Output of paned_win1.c
9.7.1 Pane Constraints
One problem with setting the maximum and minimum resources for a widget involves determining exactly what those
extents should be. The maximum size of 45 for the Label widgets in the source code is an arbitrary value that was
selected for demonstration purposes only. If other resources had been set on one of the Labels such that the widget
needed to be larger, the application would definitely look unbalanced. For example, an extremely high resolution
monitor might require the use of unusually large fonts in order for text to appear normal. There are two choices
available at this point. One is to specify the maximum and minimum values in a resolution−independent way and the
other is to ask the Label widget itself what height it wants to be.
Specifying resolution−independent dimensions requires you to carefully consider the type of application you are
creating. When you specify resolution−independent values, you must specify the values in either millimeters, inches,
points, or font units. The value of the XmN-unit-Type Manager resource controls the type of units that are used.
the source code demonstrates the use of resolution−independent dimensions. XtSetLanguageProc() is only
available in X11R5; there is no corresponding function in X11R4.
/* unit_types.c −−the same as paned_win1.c except that the
* Labels' minimum and maximum sizes are set to 1/4 inch and
* 1/2 inch respectively. These measurements are retained
* regardless of the pixels−per−inch resolution of the user's
* display.
*/
#include <Xm/Label.h>
#include <Xm/PanedW.h>
#include <Xm/Text.h>
main(argc, argv)
char *argv[];
{
Widget toplevel, pane;
XtAppContext app;
XtSetLanguageProc (NULL, NULL, NULL);
toplevel = XtVaAppInitialize (&app, "Demos", NULL, 0,
&argc, argv, NULL, NULL);
pane = XtVaCreateWidget ("pane",
xmPanedWindowWidgetClass, toplevel,
XmNunitType, Xm1000TH_INCHES,
NULL);
XtVaCreateManagedWidget ("Hello", xmLabelWidgetClass, pane,
XmNpaneMinimum, 250, /* quarter inch */
XmNpaneMaximum, 500, /* half inch */
NULL);
XtVaCreateManagedWidget ("text", xmTextWidgetClass, pane,
XmNrows, 5,
XmNcolumns, 80,
XmNpaneMinimum, 250,
XmNeditMode, XmMULTI_LINE_EDIT,
XmNvalue, "This is a test of the paned window widget.",
9 Manager Widgets 9.7.1 Pane Constraints
239
NULL);
XtVaCreateManagedWidget ("Goodbye", xmLabelWidgetClass, pane,
XmNpaneMinimum, 250, /* quarter inch */
XmNpaneMaximum, 500, /* half inch */
NULL);
XtManageChild (pane);
XtRealizeWidget (toplevel);
XtAppMainLoop (app);
}
The second technique that we can use is to query the Label widgets about their heights. This technique requires the
use of the Xt function XtQueryGeometry(), as shown in the source code XtSetLanguageProc() is only
available in X11R5; there is no corresponding function in X11R4.
/* paned_wind2.c −−there are two label widgets that are positioned
* above and below a Text widget. The labels' desired heights are
* queried using XtQueryGeometry() and their corresponding maximum
* and minimum sizes are set to the same value. This effectively
* prevents those panes from being resized. The Text widget has its
* minimum size set to 35 preventing it from becoming so small that
* its text cannot be read.
*/
#include <Xm/Label.h>
#include <Xm/PanedW.h>
#include <Xm/Text.h>
main(argc, argv)
char *argv[];
{
Widget toplevel, pane, label;
XtWidgetGeometry size;
XtAppContext app;
XtSetLanguageProc (NULL, NULL, NULL);
toplevel = XtVaAppInitialize (&app, "Demos", NULL, 0,
&argc, argv, NULL, NULL);
pane = XtVaCreateWidget ("pane",
xmPanedWindowWidgetClass, toplevel, NULL);
label = XtVaCreateManagedWidget ("Hello",
xmLabelWidgetClass, pane, NULL);
size.request_mode = CWHeight;
XtQueryGeometry (label, NULL, &size);
XtVaSetValues (label,
XmNpaneMaximum, size.height,
XmNpaneMinimum, size.height,
NULL);
printf ("hello's height: %d0, size.height);
XtVaCreateManagedWidget ("text", xmTextWidgetClass, pane,
XmNrows, 5,
XmNcolumns, 80,
XmNresizeWidth, False,
XmNresizeHeight, False,
XmNpaneMinimum, 35,
9 Manager Widgets 9.7.1 Pane Constraints
240
XmNeditMode, XmMULTI_LINE_EDIT,
XmNvalue, "This is a test of the paned window widget.",
NULL);
label = XtVaCreateManagedWidget ("Goodbye",
xmLabelWidgetClass, pane, NULL);
size.request_mode = CWHeight;
XtQueryGeometry (label, NULL, &size);
XtVaSetValues (label,
XmNpaneMaximum, size.height,
XmNpaneMinimum, size.height,
NULL);
printf ("goodbye's height: %d0, size.height);
XtManageChild (pane);
XtRealizeWidget (toplevel);
XtAppMainLoop (app);
}
XtQueryGeometry() asks a widget what size it would like to be. This routine takes the following form:
XtGeometryResult
XtQueryGeometry(widget, intended, preferred_return)
Widget widget;
XtWidgetGeometry *intended;
XtWidgetGeometry *preferred_return;
Since we do not want to resize the widget, we pass NULL for the intended parameter. We are not interested in the
return value of the function, since the information that we want is returned in the preferred_return parameter.
This parameter is of type XtWidgetGeometry, which is defined as follows:
typedef struct {
XtGeometryMask request_mode;
Position x, y;
Dimension width, height, border_width;
Widget sibling;
int stack_mode;
} XtWidgetGeometry;
We tell the widget what we want to know by setting the request_mode field of the size variable that we pass to
the routine. The request_mode field is checked by the query_geometry function within the called widget.
Depending on which bits that are specified, the appropriate fields are set within the returned data structure. In the
source code we set request_mode to CWHeight, which tells the Label widget's query_geometry method to
return the desired height in the height field of the data structure. If we had wanted to know the width as well, we
could have set request_mode as follows:
size.request_mode = (CWHeight | CWWidth);
In this case, the width and height fields would be filled in by the Label widget.
Once we have the Label's desired height, we can set the constraint resources XmNpaneMaximum and
XmNpaneMinimum to the height of the Label. By making these two values the same, the pane associated with the
Label cannot be resized. In most cases, the XtQueryGeometry() method can be used reliably to determine proper
values for minimum and maximum pane extents. In Motif 1.1, many of the Motif widgets do not have
query_geometry methods, so they do not return sensible values when XtQueryGeometry() is called. In Motif
9 Manager Widgets 9.7.1 Pane Constraints
241

Get Volume 6A: Motif Programming Manual now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.