XTkSharedCellImpl.mesa
Copyright Ó 1993 by Xerox Corporation. All rights reserved.
Created by Christian Jacobi, February 22, 1993
Christian Jacobi, July 2, 1993 4:54 pm PDT
DIRECTORY
SharedCell, SharedCellBackdoor, Rope, XTk, XTkLabels, XTkSharedCell;
XTkSharedCellImpl: CEDAR MONITOR
IMPORTS SharedCell, SharedCellBackdoor, XTk, XTkLabels
EXPORTS XTkSharedCell ~
BEGIN
Notifier: TYPE = SharedCellBackdoor.Notifier;
Text widgets
The special implementation for Text widgets works without the memory allocation made for Generic widgets.
TextCellNotifier: Notifier = {
w: XTk.Widget ~ NARROW[notifierData];
text: Rope.ROPE ¬ NIL;
WITH value SELECT FROM
r: Rope.ROPE => text ¬ r;
ENDCASE => IF value#NIL THEN RETURN;
XTkLabels.SetText[w, text];
};
TextDestructNotified: XTk.WidgetNotifyProc = {
cell: SharedCell.Cell ~ SharedCell.NarrowCell[registerData];
SharedCellBackdoor.UnRegisterNotifier[cell, TextCellNotifier, widget];
};
BindText: PUBLIC PROC [cell: SharedCell.Cell, textWidget: XTk.Widget] = {
IF cell=NIL OR textWidget=NIL THEN ERROR;
XTk.RegisterNotifier[textWidget, XTk.postWidgetDestructionKey, TextDestructNotified, cell];
IF textWidget.state<dead THEN
SharedCellBackdoor.RegisterNotifier[cell, TextCellNotifier, textWidget];
IF textWidget.state=dead THEN
SharedCellBackdoor.UnRegisterNotifier[cell, TextCellNotifier, textWidget];
WITH SharedCell.GetContents[cell] SELECT FROM
r: Rope.ROPE => XTkLabels.SetText[textWidget, r, delayed];
ENDCASE => {};
};
Generic widgets
Binding: TYPE = RECORD [
widget: XTk.Widget,
cell: SharedCell.Cell,
notifyProc: XTk.WidgetNotifyProc,
registerData: REF
];
CellNotifier: Notifier = {
b: REF Binding ~ NARROW[notifierData];
w: XTk.Widget ~ b.widget;
IF w#NIL THEN b.notifyProc[w, b.registerData, value];
};
DestructNotified: XTk.WidgetNotifyProc = {
Unregister[NARROW[registerData]];
};
Unregister: PROC [b: REF Binding] = {
cell: SharedCell.Cell ¬ b.cell;
IF cell#NIL THEN SharedCellBackdoor.UnRegisterNotifier[cell, CellNotifier, b];
b.cell ¬ NIL; b.widget ¬ NIL; b.registerData ¬ NIL;
};
Bind: PUBLIC PROC [cell: SharedCell.Cell, widget: XTk.Widget, notifyProc: XTk.WidgetNotifyProc, registerData: REF, initialCall: BOOL] = {
b: REF Binding ~ NEW[Binding ¬ [cell: cell, widget: widget, registerData: registerData]];
IF cell=NIL OR widget=NIL OR notifyProc=NIL THEN ERROR;
XTk.RegisterNotifier[widget, XTk.postWidgetDestructionKey, DestructNotified, b];
IF widget.state<dead THEN
SharedCellBackdoor.RegisterNotifier[cell, CellNotifier, b];
IF widget.state=dead THEN Unregister[b];
IF initialCall THEN
notifyProc[widget, registerData, SharedCell.GetContents[cell]]
};
END.