[comp.windows.x] Dynamically Replacing Widget Translations

stuart@rennet.cs.wisc.edu (Stuart Friedberg) (12/18/88)

I started to make a Toggle widget as a subclass of Command using
state-sensitive translation tables, rather than state-sensitive
actions.  I intended to compile two translation tables during
ClassInitialize, record them in the subclass's ToggleClassPart, and
install them in the widget instance's CorePart on the fly.

Then I discovered I didn't know how to completely replace a translation
table.  A CorePart TMRec is more than an XtTranslations, which is what
the translation compiler returns.

Question 1a: Am I attempting something against the spirit of X or the
             Athena Toolkit?
Question 1b: If so, what is an approach in the approved spirit to provide
             state-sensitive behavior?

Poking around the R3 Xt/TMstate.c, it seems that the common code
to XtOverrideTranslations and XtAugmentTranslations does what I
want, namely

    if (XtIsRealized(widget)) {
        XtUninstallTranslations(widget);
        ((WindowObj)widget)->win_obj.tm.translations = newTable;
        _XtBindActions(widget, &((WindowObj)widget)->win_obj.tm, 0);
        _XtInstallTranslations(widget, newTable);
    }
    else ((WindowObj)widget)->win_obj.tm.translations = newTable;

Question 2a: Is there more to it than that?
Question 2b: If not, wouldn't this be a good candidate for encapsulation
             as a new public function: _XtReplaceTranslations?

Looking back into the R2 sources, which are what I am running now,
XtUninstallTranslations doesn't exist, and _XtInstallTranslations is
never used.

Question 3a: Can Core be substituted safely for WindowObj?
Question 3b: Can the R3 code for XtUninstallTranslations be used in R2?
Question 3c: With those substitutions, will the R3 solution work in R2?
Question 3d: If not, is it all practical to attempt tm table replacement in R2?

Finally and somewhat peripherally,

Question 4a: Is the Core => Object + RectObj + WindowObj split complete?
Question 4b: Where can I find the documentation about it (purpose,
             proposed new subclasses of Object and RectObj, etc)?

Stu Friedberg  stuart@cs.wisc.edu

kit@ATHENA.MIT.EDU (Chris D. Peterson) (12/29/88)

> I started to make a Toggle widget...

If you are only interesed in a toggle widget, see my recent posting of a
toggle widget implementation.

> Then I discovered I didn't know how to completely replace a translation
> table.  A CorePart TMRec is more than an XtTranslations, which is what
> the translation compiler returns.

> Question 1a: Am I attempting something against the spirit of X or the
>             Athena Toolkit?

No, Replacing translations is fine, but should be done as described below.

Note: Replacing a translation table inside and action routine is bad business,
      and it is not clear wether or not the intrinsics even support this, 
      we are currently looking into this question.

> Question 1b: If so, what is an approach in the approved spirit to provide
>             state-sensitive behavior?

The Athena widget set implements state information by storing the information
in the widget's instance structure, this is how the command widget knows wether
or not it is set, for instance.

> Poking around the R3 Xt/TMstate.c, it seems that the common code
> to XtOverrideTranslations and XtAugmentTranslations does what I
> want, namely...

> Question 2a: Is there more to it than that?

The only "Standardized" part of the X Toolkit is the Intrinsics document, the
implementation provided by the MIT X Consortium is only a sample implementation.
Things that are internal to that should remain there, and they are not
portable to other toolkit implementations.  Copying source code, and using 
internal functions is strongly discouraged.  If you need to do this then you are
either doing something wrong, or we did something wrong.

> Question 2b: If not, wouldn't this be a good candidate for encapsulation
>             as a new public function: _XtReplaceTranslations?

This functionality can be obtained two ways, the first is to use 
XtSetValues to set the new translations table for the widget.  The other
is do use the convience routines XtUninstallTranslations(), and
XtOverrideTranslations().

> Looking back into the R2 sources, which are what I am running now,
> XtUninstallTranslations doesn't exist, and _XtInstallTranslations is
> never used.
 
If you need this functionality use R3.

> Question 3a: Can Core be substituted safely for WindowObj?

Core is a sub-class of WindowObj, and should contain all its functionality.
WindowObj is and internal Intrinsics object, and should not be used in
widgets or applications.  A good rule of thumb here is:  "If is isn't in
the intrinsics manual it is not portable".

> Question 3b: Can the R3 code for XtUninstallTranslations be used in R2?

Doubtful.

> Question 3c: With those substitutions, will the R3 solution work in R2?

Your solutions will not even work with other Xt R3 compatible implementations.

> Question 3d: If not, is it all practical to attempt tm table replacement in
> R2?

Probabally not.

						Chris D. Peterson     
						MIT X Consortium /
						Project Athena 

Net:	kit@athena.mit.edu		
Phone: (617) 253 - 1326			
USMail: MIT - Room E40-321
	77 Massachusetts Ave.		
	Cambridge, MA 02139		

kit@ATHENA.MIT.EDU (Chris D. Peterson) (12/29/88)

> I started to make a Toggle widget...

I have recently implemented a toggle widget to be included as part of the
Athena Widget Set, and for a limited time am offering a beta test version
to those of you with FTP access to expo.

File: /ftp/contrib/toggle.tar.Z  

Avaliable via anonymous ftp from:

Official name:  EXPO.LCS.MIT.EDU
Host address:   18.30.0.212

						Chris D. Peterson     
						MIT X Consortium /
						Project Athena 

Net:	kit@athena.mit.edu		
Phone: (617) 253 - 1326			
USMail: MIT - Room E40-321
	77 Massachusetts Ave.		
	Cambridge, MA 02139