[comp.windows.x] X11 Toolkit

Chi-Ming.Yang@CIVE.RI.CMU.EDU (06/11/88)

** urgent **


    I have some questions about using the X11 Toolkit (widgets).  I am writing
an application program which will open several windows (or widgets) on the 
screen with fixed window layout, i.e. the user of this program is not 
encouraged to change the configurations of those windows.  Then, within these 
windows, some texts and graphics entities will be displayed.  


    I read the X Toolkit Intrinsics manual, but I still haven't a clear idea 
about what is the normal programming sequence of those massive functions in 
X11 (and X Toolkit).  My idea is to adopt the Text, Label, and Viewport 
widgets as the first-level (children of the toplevelshell) windows on my 
screen layout.  Then, other windows will be attached to those widgets (if 
possible) as children for displaying purpose.


    Now, after testing the Toolkit functions and associated examples in Xaw.  
I have some questions:


1. Why can't I explicitly locate the widgets I create on the screen?  Each 
time after I call the XtRealizeWidget(), I have to use the cursor (mouse) to 
locate and size the window (widget).  This is not what I need.  I just want 
the created widgets to be placed at the predetermined place on the screen.


2. For Viewport widget, I am supposed to create a child for this widget.  I 
guess I can use one ordinary window as the child.  Is that right?  Then, I can
draw texts and lines on this child window and use the scrolling capability of 
the parent widget (Viewport widget).  Is that true?


3. Please tell me how to correctly implement a pop-up menu for a widget or 
window.  Are there any higher level toolkits or functions which I can call 
directly to arrange the items and sequences in the menu?


    Your suggestions and help is very much appreciated.



Chi-ming Yang


Carnegie-Mellon University
Department of Civil Engineering

E-mail address : cy0l@andrew.cmu.edu

kit@athena.mit.edu (Chris D. Peterson) (06/13/88)

Posting it so that others may benifit, I have answered similar questions
a lot lately.

> 1. Why can't I explicitly locate the widgets I create on the screen?  Each 
> time after I call the XtRealizeWidget(), I have to use the cursor (mouse) to 
> locate and size the window (widget).  This is not what I need.  I just want 
> the created widgets to be placed at the predetermined place on the screen.

This only happens for widgets that are children of the root window, it seems
as if you are saying that your application wants to explicitly place place
a number of windows on the users display that are children of the root.  If
this is the case here are a number of observations:

1) This is very unfriendly (don't you dare tell ME where MY windows appear
   on MY display, if your application does this then I and a lot of other
   people will refuse to use it!!!).

2) This is not the job of your application, but the job of a window manager,
   you may REQUEST where you would like the windows to go, but have no 
   guarentee that that is where they will appear, or where they will remain.

3) In my experience it seems as if there are very few applications that need
   to have more than one top level widget (Child of the root window).
   Perhaps the effect you are looking for can be obtained by having one
   child of the root, and putting all the other widgets inside of it, this 
   way you can maintain their releative positions without bumping into the 
   window manager, while still allowing the user to put it into any part of
   the display he/she feels is best for them.

If you still think that you want to create multiple top level windows there
are a couple of solutions:

1) Have a system wide defaults file that specifies the geometry resource
   of each widget, as the correct location (NOTE: this is the best solution
   as it allows the user to override you if he knows what he is doing).

2) specify a geometery in the application.

3) Use the transient shell, This will allow you to put up a window in the
   location that you asked for.  It is meant for transient windows (as the
   name implies) and thus should only for things like menues, and pop ups.

4) I refer you to Chapter 8 in the Xtk Intinsics Manual.

5) DO NOT use override redirect!!!!

> 2. For Viewport widget, I am supposed to create a child for this widget.  I 
> guess I can use one ordinary window as the child.  Is that right?  Then,
> I can draw texts and lines on this child window and use the scrolling 
> capability of the parent widget (Viewport widget).  Is that true?

> I am supposed to create a child for this widget.

yep.

If you are looking for a window to use as a child the best (and easiest)
thing to do is to instanciate a core widget, this is a widget with no 
special properties, and can be used like a regular widget (don't forget to
specify the width and height).

	XtCreateWidget("foo", widgetClass, parent, NULL, 0);

Now you can draw stuff in this window, and scroll around in it using the 
parent (veiwport).  Don't forget that you have to refresh this window on
expose events yourself, as the toolkit is not doing it for you.

> 3. Please tell me how to correctly implement a pop-up menu for a widget or 
> window.  Are there any higher level toolkits or functions which I can call 
> directly to arrange the items and sequences in the menu?

Last I heard you were on your own with this one, I had to do it myself
back when I wrote Xman, the code for this client is in: 'contrib/xman'
on the X11R2 tape.  This is the only publicly avaliable Xtk example
source code in a complex appliaction that I know of other than 'xmh'
which is horrendous to read.

I hope this helps, pardon my flames.

						Chris D. Peterson     
						Project Athena     
						Systems Development

Working for but not owned by: MIT Project Athena.
Net:	kit@athena.mit.edu		
Phone: (617) 253 - 1326			
USMail: MIT - Room E40-342C		
	77 Massachusetts Ave.		
	Cambridge, MA 02139