bent@ragged.dartmouth.edu (12/03/88)
I have a Label widget I'm using as a graphics canvas, and I'd like to know its size (in order to scale the drawing appropriately). I've given it translations for <Configure> and <Expose> events. It works perfectly when you resize the application window from the window manager. However, I'd like to get a <Configure> event before the very first <Expose> event the way raw Xlib programs do, and I can't figure out how. What should I do? I've checked the Label's event mask at various times. After creating it with XtCreateManagedWidget (with the new translations in the arg list), only the ExposureMask is on. Not until after XtRealizeWidget(toplevel) is the StructureNotifyMask on. Nitty-gritty: the Label is in a Form, which is in a VPaned in a Shell. Environment is X11R3 with Athena Widgets and XToolkit on a Sun3/50. Please reply directly -- I'm not a news reader. Thanks in advance, - Sam Bent ( bent@ragged.dartmouth.edu )
swick@ATHENA.MIT.EDU (Ralph R. Swick) (12/05/88)
Date: 2 Dec 88 21:09:13 GMT From: dartvax!ragged.dartmouth.edu!bent@bu-cs.bu.edu I have a Label widget I'm using as a graphics canvas, ... I'd like to get a <Configure> event before the very first <Expose> event the way raw Xlib programs do, ??? ConfigureNotify events are generated only when the server actually changes the size of a window in response to a ConfigureWindow request from some client. There is no guarantee that the first Exposure event will be preceeded by a ConfigureNotify for _any_ program. I've checked the Label's event mask at various times. After creating it with XtCreateManagedWidget (with the new translations in the arg list), only the ExposureMask is on. Not until after XtRealizeWidget(toplevel) is the StructureNotifyMask on. Since the window doesn't actually exist until the widget is realized, the R3 Xt implementation does lazy evaluation of the translation table event mask. This is a bug, as the spec doesn't say that XtBuildEventMask may return a bad value for an unrealized widget. However, this won't change your problem, which is a more conceptual one (or architectural, depending on your P.O.V. :-). By design, the initial geometry of all widgets is established _before_ any windows are created (modulo any changes imposed by user interaction via the window manger). Thus, any initial size changes to children are not accomplished by ConfigureWindow requests (and corresponding ConfigureNotify events). The proper way to keep track of size changes is to attach to the widget Resize method. This is guaranteed to work both before and after the widget is realized and doesn't require the server to generate extra events. Since the resize method is owned by the widget class, you may need to write your own widget subclass (see 'X Toolkit Athena Widgets', section 3.12) to export the resize method as an instance callback. As a quick hack, you could use a translation for <Map> in the Label widget as a hook to know when the window has actually been created and then retrieve the initial size.