TIP #169 Version 1.2: Add Slave Text Widgets

This is not necessarily the current version of this TIP.


TIP:169
Title:Add Slave Text Widgets
Version:$Revision: 1.2 $
Author:Brian Griffin <bgriffin at model dot com>
State:Draft
Type:Project
Tcl-Version:8.5
Vote:Pending
Created:Wednesday, 28 January 2004

Abstract

This TIP proposes adding a method to the text widget that will create peer text widgets, allowing two or more text widgets to share the same text, tags, and marks.

Rationale

One of the features offered by many text editors is the ability to split the view of text being edited. Currently editors based on the Tk text widget are required to create multiple widgets, duplicating all insert, delete, etc., operations on both widgets. The current text widget already separates the data from the widget rendering and it would be a simple task to allow two (or more) widgets to share this data.

Proposed Change

The proposed implementation splits the widget structure into two pieces, sharable data and widget specific rendering parts. The text tree, tags, marks, images, and undo stack would be placed in a reference counted, shared section, while the tkwin, fonts, colors, bindings, etc., would remain with the widget. A method (peer create) is added that will create a new widget that will share the data with it's "parent." The shared data also contains a list of peers which is used to propagate widget updates when the data changes.

set widget [text .text]
set slave [$widget peer create .slave]

Once a peer is created it has all the rights and privileges of the creating parent. There is no restriction on the peer's window pathname. The creating parent may also be destroyed without affecting the peer; only when the last window (peer or parent) is destroyed will the data be deleted.

Bindings are not shared, but remain with the widget. This includes tag bindings.

In keeping with Tcl's introspection nature, a "peer names" method is added that will return a list of peer widgets. (should this list include itself?)

Reference Implementation

A reference implementation based on Tcl 8.4.5 can be found at ftp://ftp.model.com/pub/tcl/textpeer845.tgz This archive contains modified tkText*.[ch] files that implement the [$w peer create] and [$w peer names] methods described above.

Copyright

This document has been placed in the public domain.


Powered by TclThis is not necessarily the current version of this TIP.

TIP AutoGenerator - written by Donal K. Fellows