WidgetWrap

Section: X Version 11 (3X)
Updated:
Index Return to Main Contents
 

NAME

WidgetCreate, WidgetSet, WidgetGet - programmer's convenience routines  

SYNTAX

WidgetCreate(name, class, parent, varargs)

      char *name;

      WidgetClass class;

      Widget parent;

WidgetSet(widget, varargs)

      Widget *widget;

WidgetGet(widget, varargs)

      Widget *widget;

char * GenericWidgetName(buf)

      char *buf;  

ARGUMENTS

buf
Buffer to place new widget name.
class
The class of the widget to be created.
name
The name of the widget when created.
parent
The parent of the widget to be created.
widget
The widget to set or get attributes.
 

DESCRIPTION

The purpose of these functions is to allow the programmer to create widgets and set and get widget attributes via a variable argument list style of function call. This eliminates the need for many local variables and bothersome XtSetArg() calls and so forth. An example of usage:

Widget foo;

foo = WidgetCreate("foo", labelWidgetClass, toplevel,
XtNlabel,           "Widget",
XtNforeground,      WhitePixelOfScreen(XtScreen(toplevel)),
XtNbackground,      BlackPixelOfScreen(XtScreen(toplevel)),
XtNborderWidth,     1,
NULL);

As you can see, the list must be NULL terminated. You may pass up to to MAXARGS argument pairs (which is defined in WidgetWrap.h). There are special args available to the Create/Get/Set functions that are available:

XtNmanaged    pass "False" to create a non-managed widget. XtNargList    takes two parameters.

The XtNargList makes it possible to pass attributes to the Create/Get/Set calls that are probably common to many widgets to be created or reset.

static Arg args[] = {
XtNforeground,   black,
XtNbackground,   white,
XtNwidth,        20,
XtNheight,       10,

};
foo = WidgetCreate(NULL, widgetClass, toplevel, XtNargList, args, XtNumber(args), NULL);

There are two other XtN's that the widgetwrap code provides. You can create toplevel application shell widgets and popup shells as well as other widget types by passing these parameters:


   XtNpopupShell     pass "True" to create a PopupShellWidget.
   XtNapplicShell     pass "True" to create an applicationShellWidget

These obsolete the need for XtCreatePopupShell() and XtCreateApplicationShell() Note that for both of these, the "parent" parameter is ignored for the WidgetCreate() call (you may pass anything, but the parent parameter remains there for consistency).

Most large applications will create huge numbers of widgets which the programmer has to think up unique names for all of them. What's more, typically, as noted by the examples above, the names are constant strings which takes up memory, disk spaces, etc... So, if WidgetCreate() gets NULL as the name of the widget, then a widget name will be created automatically by calling GenericWidgetName() since most of the time, user's don't care what the name of a widget is, this capability is available.  

DIAGNOSTICS

WidgetCreate() will return NULL if a widget cannot be created. It uses the routines (and is a front end for) XtCreateWidget(), XtCreateManagedWidget(), XtCreatePopupShell(), and XtCreateApplicationShell().  

BUGS

The number of parameters is limited to a constant size defined in the public include file WidgetWrap.h but should be set to a reasonable size. If the number of parameters exceeds that size, a warning will be printed. If the calling function is WidgetSet() or WidgetGet(), the warning is advisory only and the runtime code is not effected. However, if the number of arguments are exceeded for WidgetCreate() calls, then the widget is not created and NULL is returned.


 

Index

NAME
SYNTAX
ARGUMENTS
DESCRIPTION
DIAGNOSTICS
BUGS

This document was created by man2html, using the manual pages.
Time: 06:09:42 GMT, December 12, 2024