26.1.1 The Main Application Window
The main application window for the editor consists of a MainWindow widget that contains a MenuBar, the
text−editing area, TextFields for entering search and replace text, and a message area. the source code shows the UIL
module that describes this interface.
! editor.uil − editor application main user interface definition
module editor
include file 'procedures.uih';
include file 'identifiers.uih';
object menubar : imported XmMenuBar;
object main_window : XmMainWindow {
controls {
XmMenuBar menubar;
XmForm form;
};
};
object form : XmForm {
controls {
XmRowColumn search_panel;
XmTextField text_output;
XmScrolledText text_edit;
};
};
list attachments : arguments {
XmNtopAttachment = XmATTACH_FORM;
XmNbottomAttachment = XmATTACH_FORM;
XmNleftAttachment = XmATTACH_FORM;
XmNrightAttachment = XmATTACH_FORM;
};
object search_panel : exported XmRowColumn {
controls {
search_prompt : XmLabel gadget {
arguments {
XmNlabelString = "Search Pattern:";
};
};
search_text : XmTextField {
callbacks {
MrmNcreateCallback = procedure register_widget (w_search_text);
};
};
replace_prompt : XmLabel gadget {
arguments {
XmNlabelString = " Replace Pattern:";
};
};
replace_text : XmTextField {
callbacks {
MrmNcreateCallback = procedure register_widget (w_replace_text);
};
};
};
26 Building an Application With UIL26.1.1 The Main Application Window
700
arguments {
XmNorientation = XmHORIZONTAL;
XmNpacking = XmPACK_TIGHT;
arguments attachments;
XmNbottomAttachment = XmATTACH_NONE;
};
};
object text_edit : XmScrolledText {
arguments {
XmNrows = 10;
XmNcolumns = 80;
XmNeditMode = XmMULTI_LINE_EDIT;
arguments attachments;
XmNtopAttachment = XmATTACH_WIDGET;
XmNtopWidget = search_panel;
XmNbottomAttachment = XmATTACH_WIDGET;
XmNbottomWidget = text_output;
};
callbacks {
MrmNcreateCallback = procedure register_widget (w_text_edit);
};
};
object text_output : XmTextField {
arguments {
XmNeditable = false;
XmNcursorPositionVisible = false;
XmNshadowThickness = 0;
arguments attachments;
XmNtopAttachment = XmATTACH_NONE;
};
callbacks {
MrmNcreateCallback = procedure register_widget (w_text_output);
};
};
end module;
The module begins by including two files: procedures.uih and identifiers.uih. The procedures.uih file contains the
callback declarations for the interface. The file also defines some arguments for the callback routines. This file is
shown in the source code
! procedures.uih − declarations of editor callbacks and their arguments
procedure
register_widget (any);
procedure
file_cb (integer);
file_select_cb (integer);
value
FILE_OPEN : 0;
FILE_SAVE : 1;
FILE_EXIT : 2;
procedure
edit_cb (integer);
26 Building an Application With UIL26.1.1 The Main Application Window
701
value
EDIT_CUT : 0;
EDIT_COPY : 1;
EDIT_PASTE : 2;
EDIT_CLEAR : 3;
procedure
search_cb (integer);
value
SEARCH_FIND_NEXT : 0;
SEARCH_SHOW_ALL : 1;
SEARCH_REPLACE : 2;
SEARCH_CLEAR : 3;
procedure
popdown_cb();
The callback routines for the menu items and the FileSelectionDialog take integer arguments. The file defines the
possible argument values for each of the callback routines. These values correspond to enumeration values in the
application code; they indicate which action the callback should perform when it is invoked. We could write a
separate procedure for each callback, but instead we use a single callback for each menu because the actions are
similar. The callbacks that use these definitions are in the menubar.uil and dialogs.uil modules described later in this
chapter.
The identifiers.uih file contains the declarations for several global widget variables. These variables are set in the UIL
module by MrmNcreateCallback. This file is listed in the source code
! identifiers.uih − declarations of application defined data
identifier
w_search_text;
w_replace_text;
w_text_edit;
w_text_output;
After the include directives at the top of editor.uil, the module declares the MenuBar, because it is used in this module
but defined in another. You must declare a widget that is defined in another module before you can use it. The
declaration of the MainWindow portion of the interface comes next. The MainWindow is at the top of the hierarchy; it
manages the MenuBar and a Form. The Form is the work area. It contains the other main sections of the window,
which are a RowColumn that contains the search and replace TextFields, the ScrolledText editing area, and the
TextField message area.
We specify the Form attachments using the attachments list, which specifies an attachment for each side of a
widget. In the individual widget definitions, we override the necessary attachments to arrange the components
properly. Since UIL allows forward references, we should be able to list the three children in the Form's controls
subsection in the same order that they appear in the user interface. However, forward references may not always work
correctly in early releases of Motif 1.2 due to an Mrm bug. To work around this problem we need to specify the
children in a particular order. If one child is attached to another, the child that specifies the attachment should be listed
after the widget to which it is attached. For example, in the editor.uil module, the text_edit contains attachments
to both of its siblings, so we list it after the other two widgets in the controls subsection of the form. The actual
widget definitions can occur in any order in the UIL module.
In addition to the Form attachments, each widget definition contains other resource settings that are necessary for the
interface. The search_panel RowColumn contains two Labels and two TextField widgets. Since the definitions of
26 Building an Application With UIL26.1.1 The Main Application Window
702
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.