Solaris Common Desktop Environment: Programmer's Guide

Chapter 7 Common Desktop Environment Motif Widgets

The Common Desktop Environment provides Motif 2.1 libraries (with bug fixes) and enhancements. In addition, the Common Desktop Environment provides four custom widgets you can use to provide certain OPEN LOOKTM and Microsoft® Windows functionality. This chapter describes these Motif custom widgets.

The widget library, libDtWidget, contains four widgets that combine or enhance functionality of existing Motif 2.1 widgets:

These widgets provide common functionality across all Common Desktop Environment applications. None of these widgets support subclassing.

The Custom Widgets library depends directly on the following libraries:

Menu Button Widget (DtMenuButton)

Use the DtMenuButton widget to provide menu-cascading functionality outside of a menu pane.

DtMenuButton widget is a command widget that complements the menu cascading functionality of an XmCascadeButton widget. As a complement to XmCascadeButton widget, it can only be instantiated outside a MenuBar, Pulldown, or Popup (use XmCascadeButton widget inside a MenuPane.) Figure 7-1 shows examples of a DtMenuButton widget.

Figure 7-1 Examples of menu button widget (DtMenuButton)

Graphic

Library and Header Files

The DtMenuButton widget is in the libDtWidget library. The header file is Dt/MenuButton.h.

Demo Program

A demo containing an example of the DtMenuButton widget is in /usr/dt/examples/dtwidget/controls.c.

Convenience Functions

DtCreateMenuButton() is a convenience function that creates a Common Desktop Environment widget.

DtMenuButton widget is a subclass of XmLabel class. Visually, DtMenuButton widget has a label string and a menu glyph. The menu glyph always appears on the right end of the widget and, by default, is a downward pointing arrow.

DtMenuButton widget has an implicitly created submenu attached to it. The submenu is a pop-up menu and has this DtMenuButton widget as its parent. The name of the implicitly created submenu is obtained by prefixing submenu_ to the name of this DtMenuButton widget. You can obtain the widget ID of the submenu by setting an XtGetValues on DtNsubMenuId resource of this DtMenuButton widget. The implicitly created submenu must not be destroyed by the user of this widget.

The submenu can be popped up by pressing the menu post button (see XmNmenuPost resource of XmRowColumn) anywhere on the DtMenuButton widget or by pressing the Motif Cancel key (usually Escape).

Classes

DtMenuButtonWidget inherits behavior and resources from Core, XmPrimitive, and XmLabel classes.

The class pointer is dtMenuButtonWidgetClass.

The class name is DtMenuButtonWidget.

DtMenuButtonWidget does not support subclassing.

Resources

DtMenuButtonWidget provides the following resources. Table 7-1 shows the class, type, default, and access for these resources.

See the DtMenuButtonWidget(3X) man page for more information.

The codes in the access column show if you can:

Table 7-1 DtMenuButtonWidget Resources

Name 

Class 

Type 

Default 

Access 

DtNcascadingCallback

DtCCallback

XtCallbackList

NULL

C

DtNcascadePixmap

DtCPixmap

Pixmap

XmUNSPECIFIED_PIXMAP

CSG

DtNsubMenuId

DtCMenuWidget

Widget

NULL

SG

Callback Structures

The callback structure follows and is described in Table 7-2 .

typedef struct {
 	int 	reason;
 	XEvent	*event;
} XmAnyCallbackStruct;
Table 7-2 DtMenuButtonWidget Callback Structures

Structure 

Description 

reason

Returns reason why the callback was invoked. 

event

Points to the XEvent that triggered the callback or NULL if the callback was not triggered by an XEvent.

Example of DtMenuButton Widget

The following example shows how to create and use a DtMenuButton widget. You can find this code as part of the controls.c demo in the /usr/dt/examples/dtwidget directory.

/*
  * Example code for DtMenuButton
  */  

#include Dt/DtMenuButton.h  

/* MenuButton custom glyph */  

#define menu_glyph_width 16 
#define menu_glyph_height 16 
static unsigned char menu_glyph_bits[] = {
 	0xe0, 0x03, 0x98, 0x0f, 0x84, 0x1f, 0x82, 0x3f, 0x82, 0x3f, 0x81,
 	0x7f, 0x81, 0x7f, 0xff, 0x7f, 0xff, 0x40, 0xff, 0x40, 0xfe, 0x20, 0xfe,
 	0x20, 0xfc, 0x10, 0xf8, 0x0c, 0xe0, 0x03, 0x00, 0x00};

static void CreateMenuButtons(Widget parent) {
     Widget menuButton, submenu, titleLabel, button;
     Pixmap cascadePixmap;
     Pixel fg, bg;
     Cardinal depth;
     XmString labelString;
     Arg args[20];
     int i, n;

      /* Create title label */

     labelString = XmStringCreateLocalized("MenuButton Widget");
     n = 0;
     XtSetArg(args[n], XmNlabelString, labelString); n++;
     titleLabel = XmCreateLabel(parent, "title", args, n);
     XtManageChild(titleLabel);
     XmStringFree(labelString);

     /*
      * Create a MenuButton.
      * Add push buttons to the built-in popup menu.
      */

     labelString = XmStringCreateLocalized("Action"); n = 0;
     XtSetArg(args[n], XmNlabelString, labelString); n++;
     menuButton = DtCreateMenuButton(parent, "menuButton1", args, n);
     XtManageChild(menuButton);
     XmStringFree(labelString);
     XtVaGetValues(menuButton, DtNsubMenuId, &submenu, NULL);
     button = XmCreatePushButton(submenu, "Push", NULL, 0);
     XtManageChild(button);
     button = XmCreatePushButton(submenu, "Pull", NULL, 0);
     XtManageChild(button);
     button = XmCreatePushButton(submenu, "Turn", NULL, 0);
     XtManageChild(button);

     /*
      * Create a MenuButton.
      * Replace the built-in popup menu with a tear-off menu.
      * Add a custom pixmap in the colors of the MenuButton.
      */

     labelString = XmStringCreateLocalized("Movement");
     n = 0;
     XtSetArg(args[n], XmNlabelString, labelString); n++;
  	  menuButton = DtCreateMenuButton(parent, "menuButton1", args, n);
     XtManageChild(menuButton);
     XmStringFree(labelString);

     /* Create a tear-off menu */

     n = 0;
     XtSetArg(args[0], XmNtearOffModel, XmTEAR_OFF_ENABLED); n++;
     submenu = XmCreatePopupMenu(menuButton, "submenu", args, n);
     button = XmCreatePushButton(submenu, "Run", NULL, 0);
     XtManageChild(button);
     button = XmCreatePushButton(submenu, "Jump", NULL, 0);
     XtManageChild(button);
     button = XmCreatePushButton(submenu, "Stop", NULL, 0);
     XtManageChild(button);

     XtVaSetValues(menuButton, DtNsubMenuId, submenu, NULL);

     /* Create a pixmap using the menu button's colors and depth */

     XtVaGetValues(menuButton,
 			XmNforeground, &fg,
 			XmNbackground, &bg,
 			XmNdepth, &depth,
 			NULL);

     cascadePixmap = XCreatePixmapFromBitmapData(XtDisplay
 	  (menuButton),DefaultRootWindow(XtDisplay
 	  (menuButton)),
 	  (char*)menu_glyph_bits,
 	  menu_glyph_width, menu_glyph_height,
     fg, bg, depth);
     XtVaSetValues(menuButton, DtNcascadePixmap, cascadePixmap,
 	  NULL); 
}

Text Editor Widget (DtEditor)

The Common Desktop Environment text editing system consists of two components:

Although the OSF/Motif text widget also provides a programmatic interface, applications that use the system-wide uniform editor should use the DtEditor(3) widget. The Common Desktop Environment Text Editor and Mailer use the editor widget. Use this widget in the following circumstances:

  1. You want the functionality, such as spell checking, undo, and find/change, that is provided by the DtEditor(3) widget.

  2. You do not want to write the code so that users may read and write data to and from a file.

  3. Your program does not need to examine every character typed or every cursor movement made by a user.

This section describes the text editor widget, DtEditor(3).

The Editor Widget library provides support for creating and editing text files. It enables applications running in the desktop environment to have a consistent method of editing text data. The DtEditor(3) widget consists of a scrolled edit window for text, an optional status line, and dialogs for finding and changing text, spell checking, and specifying formatting options. The text editor widget includes a set of convenience functions for programmatically controlling the widget.

Library and Header Files

The DtEditor widget is in the libDtWidget library. The header file is Dt/Editor.h.

Demo Program

A demo containing an example of the DtEditor widget is in /usr/dt/examples/dtwidget/editor.c.

Classes

Widget subclassing is not supported for the DtEditor widget class.

DtEditor inherits behavior and resources from Core, Composite, Constraints, XmManager, and XmForm classes.

The class name for the editor widget is DtEditorWidget.

The class pointer is dtEditorWidgetClass.

Convenience Functions

The DtEditor convenience functions are described in the following tables.

Life Cycle Functions

The DtEditor life cycle functions are described in Table 7-3 .

Table 7-3 DtEditor Life Cycle Functions

Function 

Description 

DtCreateEditor

Creates a new instance of a DtEditorwidget and its children.

DtEditorReset

Restores a DtEditor widget to its initial state.

Input/Output Functions

The DtEditor input/output functions are described in Table 7-4 .

Table 7-4 DtEditor Input/Output Functions

Function 

Description 

DtEditorAppend

Appends content data to the end of an editor widget. 

DtEditorAppendFromFile

Appends the contents of a file to the end of an editor widget. 

DtEditorGetContents

Retrieves the entire contents of an editor widget. 

DtEditorInsert

Inserts content data at the current insert position. 

DtEditorInsertFromFile

Inserts the contents of a file at the current insert position. 

DtEditorReplace 

Replaces a portion of text with the supplied data. 

DtEditorReplaceFromFile 

Replaces a portion of text with the contents of a file. 

DtEditorSaveContentsToFile

Saves the entire contents to a file. 

DtEditorSetContents

Loads content data into an editor widget, replacing the entire contents of the widget. 

DtEditorSetContentsFromFile

Loads the contents of a file into an editor widget, replacing the entire contents of the widget. 

Selection Functions

The DtEditor selection functions are described in Table 7-5 .

Table 7-5 DtEditor Selection Functions

Function 

Description 

DtEditorClearSelection

Replaces the currently selected contents with blanks. 

DtEditorCopyToClipboard

Copies the currently selected contents to the clipboard. 

DtEditorCutToClipboard

Removes the currently selected contents, placing then on the clipboard. 

DtEditorDeleteSelection

Removes the currently selected contents. 

DtEditorDeselect

Deselects any selected contents. 

DtEditorPasteFromClipboard

Pastes the contents of the clipboard into an editor widget, replacing any currently selected contents. 

DtEditorSelectAll

Selects the entire contents of an editor widget. 

Format Functions

The DtEditor format functions are described inTable 7-6 .

Table 7-6 DtEditor Format Functions

Function 

Description 

DtEditorFormat

Formats all or part of the contents of an editor widget. 

DtEditorInvokeFormatDialog

Displays the format dialog box that enables the user to specify format settings for margins and justification style and to perform formatting operations. 

Find and Change Functions

The DtEditor find and change functions are described in Table 7-7 .

Table 7-7 DtEditArea Find and Change Functions

Function 

Description 

DtEditorChange

Changes one or all occurrences of a string. 

DtEditorFind

Finds the next occurrence of a string. 

DtEditorInvokeFindChangeDialog

Displays the dialog box that enables the user to search for, and optionally change, a string. 

DtEditorInvokeSpellDialog

Displays a dialog box with a list of misspelled words in the current contents. 

Auxiliary Functions

The DtEditor auxiliary functions are described in Table 7-8 .

Table 7-8 DtEditor Auxiliary Functions

Function 

Description 

DtEditorCheckForUnsavedChanges

Reports whether the contents of an editor widget have been altered since the last time they were retrieved or saved. 

DtEditorDisableRedisplay 

Prevents redisplay of an editor widget even though its visual attributes have changed. 

DtEditorEnableRedisplay 

Forces the visual update of an editor widget. 

DtEditorGetInsertPosition

Returns the insertion cursor position of the editor widget. 

DtEditorGetLastPosition

Returns the position of the last character in the edit window. 

DtEditorGetMessageTextFieldID

Retrieves the widget ID of the text field widget used to display application messages. 

DtEditorGetSizeHints

Retrieves sizing information from an editor widget. 

DtEditorGoToLine

Moves the insertion cursor to the specified line. 

DtEditorSetInsertionPosition

Sets the position of the insertion cursor. 

DtEditorTraverseToEditor

Sets keyboard traversal to the edit window of an editor widget. 

DtEditorUndoEdit

Undoes the last edit made by a user. 

Resources

The DtEditor widget provides the following set of resources.

The status line also includes a Motif XmTextField(3X) widget for displaying messages supplied by an application. This field is a convenient place for an application to display status and feedback about the document being edited. The ID of the text field is retrieved using DtEditorGetMessageTextFieldID(3). A message is displayed by setting the XmNvalue or XmNvalueWcs resource of this widget. If the text field is not needed, you can unmanage it by calling XtUnmanageWidget(3X) with its ID.

Table 7-9 lists the class, type, default, and access for each resource. You can also set the resource values for the inherited classes to set attributes for this widget. To reference a resource by name or class in an .Xdefaults file, remove the DtN or DtC prefix and use the remaining letters. To specify one of the defined values for a resource in an .Xdefaults file, remove the Dt prefix and use the remaining letters (in either lowercase or uppercase, but include any underscores between words).

The codes in the access column show if you can:

See the DtEditor(3) man page for more information.

Table 7-9 DtEditor Resources

Name 

Class 

Type 

Default 

Access 

DtNautoShowCursorPosition

DtCAutoShowCursorPosition

Boolean

True

CSG

DtNblinkRate

DtCBlinkRate

int

500

CSG

DtNbuttonFontList 

DtCFontList 

XmFontList 

Dynamic 

CSG 

DtNcolumns

DtCColumns

XmNcolumns

Dynamic

CSG

DtNcursorPosition

DtCCursorPosition

XmTextPosition

0

CSG

DtNcursorPositionVisible

DtCCursorPositionVisible

Boolean

True

CSG

DtNdialogTitle

DtCDialogTitle

XmString

NULL

CSG

DtNeditable

DtCEditable

Boolean

True

CSG

DtNlabelFontList 

DtCFontList 

XmFontList 

Dynamic 

CSG 

DtNmaxLength

DtCMaxLength

int

Largest integer

CSG

DtNoverstrike

DtCOverstrike

Boolean

False

CSG

DtNrows

DtCRows

XmNrows

Dynamic

CSG

DtNscrollHorizontal

DtCScroll

Boolean

True

CG

DtNscrollLeftSide

DtCScrollSide

Boolean

Dynamic

CG

DtNscrollTopSide

DtCScrollSide

Boolean

False

CG

DtNscrollVertical

DtCScroll

Boolean

True

CG

DtNshowStatusLine

DtCShowStatusLine

Boolean

False

CSG

DtNspellFilter

DtCspellFilter

char *

Spell

CSG

DtNtextBackground

DtCBackground

Pixel

Dynamic

CSG

DtNtextDeselectCallback

DtCCallback

XtCallbackList

NULL

C

DtNtextFontList 

DtCFontList 

XmFontList 

Dynamic 

CSG 

DtNtextForeground

DtCForeground

Pixel

Dynamic

CSG

DtNtextTranslations 

DtCTranslations 

XtTranslations 

NULL 

CS 

DtNtextSelectCallback

DtCCallback

XtCallbackList

NULL

C

DtNtopCharacter

DtCTextPosition

XmTextPosition

0

CSG

DtNwordWrap

DtCWordWrap

Boolean

True

CSG

Inherited Resources

DtEditor inherits behavior and resources from the following superclasses:

Refer to the appropriate man page for more information.

Localization Resources

The following list describes a set of widget resources that are designed for localization of the DtEditor widget and its dialog boxes. Default values for these resources depend on the locale.

Table 7-10 lists the class, type, default, and access for each of the localization resources. The codes in the access column show if you can:

See the DtEditor(3) man page for more information.

Table 7-10 DtEditor Localization Resources

Name 

Class 

Type 

Default 

Access 

DtNcenterToggleLabel

DtCCenterToggleLabel

XmString

Dynamic

CSG

DtNchangeAllButtonLabel

DtCChangeAllButtonLabel

XmString

Dynamic

CSG

DtNchangeButtonLabel

DtCChangeButtonLabel

XmString

Dynamic

CSG

DtNchangeFieldLabel

DtCChangeFieldLabel

XmString

Dynamic

CSG

DtNcurrentLineLabel

DtCCurrentLineLabel

XmString

Dynamic

CSG

DtNfindButtonLabel

DtCFindButtonLabel

XmString

Dynamic

CSG

DtNfindChangeDialogTitle

DtCFindChangeDialogTitle

XmString

Dynamic

CSG

DtNfindFieldLabel

DtCFindFieldLabel

XmString

Dynamic

CSG

DtNformatAllButtonLabel

DtCFormatAllButtonLabel

XmString

Dynamic

CSG

DtNformatParagraphButtonLabel

DtCFormatParagraphButtonLabel

XmString

Dynamic

CSG

DtNformatSettingsDialogTitle

DtCFormatSettingsDialogTitle

XmString

Dynamic

CSG

DtNinformationDialogTitle

DtCInformationDialogTitle

XmString

Dynamic

CSG

DtNjustifyToggleLabel

DtCJustifyToggleLabel

XmString

Dynamic

CSG

DtNleftAlignToggleLabel

DtCLeftAlignToggleLabel

XmString

Dynamic

CSG

DtNleftMarginFieldLabel

DtCLeftMarginFieldLabel

XmString

Dynamic

CSG

DtNmisspelledListLabel

DtCMisspelledListLabel

XmString

Dynamic

CSG

DtNoverstrikeLabel

DtCOverstrikeLabel

XmString

Dynamic

CSG

DtNrightAlignToggleLabel

DtCRightAlignToggleLabel

XmString

Dynamic

CSG

DtNrightMarginFieldLabel

DtCRightMarginFieldLabel

XmString

Dynamic

CSG

DtNspellDialogTitle

DtCSpellDialogTitle

XmString

Dynamic

CSG

DtNtotalLineCountLabel

DtCTotalLineCountLabel

XmString

Dynamic

CSG

Callback Functions

The DtEditor widget supports three callback functions:

If you want to present help information about the editor widget and its dialog boxes, set the XmNhelpCallback resource and use the reason field passed as part of DtEditorHelpCallbackStruct to set the contents of the Help dialog box. A pointer to the following structure is passed to XmNHelpCallback. The callback structure and is described in Table 7-11 .

typedef struct {
		int     reason;
 	XEvent   *event;
} DtEditorHelpCallbackStruct;
Table 7-11 DtEditorHelp Callback Structure

Structure 

Description 

reason

The reason why the callback was invoked. Refer to the DtEditor(3) man page for a list of reasons.

event

A pointer to the event that invoked this callback. The value can be NULL. 

Use the DtNtextSelectCallback and DtNtextDeselectCallback resources when you want to enable and disable menu items and commands depending on whether text is selected. DtNtextSelectCallback specifies a function that is called whenever some text is selected in the edit window. DtNtextDeselectCallback specifies a function that is called whenever no text is selected within the edit window. The reasons sent by the callbacks are DtEDITOR_TEXT_SELECT and DtEDITOR_TEXT_DESELECT.