[ Previous | Next | Contents | Glossary | Home | Search ]
Motif 2.1 Programmer's Guide



Container

Container is a manager that accepts only widgets of class XmIconGadget or its subclasses as children. Applications use the IconGadget to display information in graphic and/or text form. Applications can use the Container to view the IconGadgets in different formats, to select, and to manipulate the IconGadgets.

Container has several layout options for displaying its IconGadget children. An application can use Container's XmOUTLINE layout to convey hierarchical relationships between the information or objects represented by the children; for example, an organization chart or the taxonomy of a particular genus of plant. Container's XmDETAIL layout allows the application to display additional information with each child lined up in vertical columns. Options within Container's SPATIAL layout can be used by applications to display children in a grid-like configuration as in an icon-box for a window manager. Or it can display them in specific locations; for example, a Container application could display IconGadgets that represent workstations in a computer lab so that each IconGadget's position in the Container corresponds to its location on the lab floor.

When Container's SPATIAL layout is used, users can drag and drop IconGadgets within the Container to reposition them. An application where this might be useful is a chessboard, or an application to select planting locations within a garden plot.

Container supports the same four modes of selection as the List widget. The XmNselectionPolicy resource controls the selection mode. Applications using Container can allow users to select only one or more than one IconGadget child at a time. Container invokes callbacks associated with the XmNselectionCallback resource whenever a user action causes a change to the set of selected items. Container also invokes callbacks associated with the XmNdefaultActionCallback whenever a user performs an activate action on an IconGadget child. Using these callbacks, an application using Container can respond to user actions, as in the example below.

This example program uses IconGadgets to represent workers in a fictional organization. The code could be the front end to an office telephone system. It uses Container's XmOUTLINE layout to arrange the information so that it corresponds to an organization chart. The XmNselectionPolicy is set to XmBROWSE_SELECT so that only one selection can be made at a time. If this application were to support an electronic mailing system, the application could use Container's XmEXTENDED or XmMULTIPLE selection policy to allow multiple IconGadgets to be selected at once.

void
MakeACall(Widget        w,
          XtPointer     client_data,
          XtPointer     call_data)
{
 /* Ring that person's phone when selected. */
  printf("Ring!\n");
}
 
 
void
CreateContainer(Widget parent_of_container)
{
 Widget  container1;
 Widget  president, vice_president, dir_of_sales, dir_of_rnd,
dir_of_mfr;
 
   container1 = XtVaCreateWidget("Container",
                        xmContainerWidgetClass, parent_of_container,
                        XmNlayoutType, XmOUTLINE,
                        XmNselectionPolicy, XmBROWSE_SELECT,
                        XmNautomaticSelection, XmNO_AUTO_SELECT,
                        XmNentryViewType, XmSMALL_ICON,
                        NULL);
   XtAddCallback(container1, XmNselectionCallback, MakeACall,
                 (XtPointer)NULL);
 
   president = XtVaCreateManagedWidget("President",
                        xmIconGadgetClass, container1,
                        XmNoutlineState, XmEXPANDED,
                        NULL);
   vice_president = XtVaCreateManagedWidget("Vice-President",
                        xmIconGadgetClass, container1,
                        XmNentryParent, president,
                        XmNoutlineState, XmEXPANDED,
                        NULL);
   dir_of_sales = XtVaCreateManagedWidget("Director of Sales",
                        xmIconGadgetClass, container1,
                        XmNentryParent, vice_president,
                        NULL);
   dir_of_rnd = XtVaCreateManagedWidget("Director of R&D",
                        xmIconGadgetClass, container1,
                        XmNentryParent, vice_president,
                        NULL);
   dir_of_mfr = XtVaCreateManagedWidget("Director of Manufacturing",
                        xmIconGadgetClass, container1,
                        XmNentryParent, vice_president,
                        NULL);
   XtManageChild(container1);
}

The preceding example appears online in directory demos/doc/programGuide/ch08/Container.

This example could be expanded to use other Container features. Container's XmDETAIL view could be used to give additional information about each of the workers like "job responsibilities" and "internal mail address." The application could use Container's XmNdefaultActionCallback to enable users to edit this same information. And, assuming the fictional workers weren't located on separate floors or separate sites, the application could support a switch to an XmSPATIAL view that has the office floorplan as the Container's background pixmap and positions each IconGadget according to the corresponding worker's office location.


[ Previous | Next | Contents | Glossary | Home | Search ]