Next Previous Up Top Contents Index

MotifEnv

Motif Dialog Patterns

The following figure shows the patterns constituting the MotifEnv dialog patterns. Patterns from XtEnv are shaded gray, and other MotifEnv patterns are shaded light-gray.

The following is a brief presentation of the different patterns:

Examples using Motif Dialog Patterns

The following example completes the MainWindow example shown earlier, by adding the menu bar, and creating a MessageDialog to pop up when the help button in the menu bar is activated.

mainwindow.bet, continued

mbar: @MenuBar
  (# fileButton: @CascadeButton
       (# init::< 
            (# do 'File' -> labelString; 'F' -> mnemonic #)
       #);
     fileMenu: @PullDownMenu
       (# quit: @PushButtonGadget
            (# init::<
                 (# 
                 do 'Quit' -> labelString;
                    'Q' -> mnemonic;
                    'Ctrl<Key>q' -> accelerator;
                    'Ctrl+q' -> acceleratorText;
                 #);
               activateCallBack::< (# do stop #);
            #);
          init::< (# do quit.init #);
       #);
     helpButton: @CascadeButton
       (* The button in the MenuBar that activates the HelpBox *)
       (# helpBox: @MessageDialog
            (* The dialog that displays the help message *)
            (# init::<
                 (#
                 do 'This "help" should be extended!'
                       -> messageString;
                    'Help' -> dialogTitle;
                    unManageCancel; unManageHelp;
                 #);
            #);
          activateCallback::< (# do helpBox.manageChild #);
          init::< 
            (# 
            do 'Help' -> labelString; 'H' -> mnemonic;
               helpBox.init 
            #);
       #);
     init::< 
       (# 
       do fileButton.init;  fileMenu.init; 
          fileMenu -> fileButton.subMenuId;
          helpButton.init;
          helpButton -> menuHelpWidget;
       #);
  #);

The example shows how to create the MenuBar and File menu for the MainWindow. Except for the use of mnemonics and accellerators, this has been explained in the section on Menus earlier in the manual. A mnemonic is a "keyboard equivalent", which can be used to invoke menus and menu items, when the menus are posted. Accelerators can be used to invoke menu items even when the menu containing the item is not posted.

The help dialog is invoked from a CascadeButton called helpButton in the MenuBar. Two special things happen in the init virtual of the MessageDialog:

  1. The dialogTitle resource is set to the text "Help". This is because some window managers decorate the dialogs with title bar etc. The dialogTitle resource determines what will appear in the title bar in that case.
  2. A MessageDialog by default contains three buttons: an OK button, a Cancel button, and a Help button. The Cancel and Help buttons do not make much sence within a help dialog, so these are removed using the unmanageCancel and unmanageHelp patterns. This is the easiest way to make a dialog with just an OK button, since, unfortunately, Motif does not include such a dialog.
The windows below show how the help dialog looks, when popped up from the mainwindow application.

The following example shows how to use the FileSelectionBox pattern to invoke a standard file specification dialog:

filedialog.bet

ORIGIN '~beta/Xt/motifenv';
INCLUDE '~beta/Xt/motif/fileselectionbox';
INCLUDE '~beta/Xt/motif/rowcolumn';
INCLUDE '~beta/Xt/motif/pushbutton';

-- PROGRAM: descriptor --
MotifEnv
(# 
   buttons: @RowColumn
     (# fs: @FileSelectionDialog
          (# init::< (# do 'Enter File' -> dialogTitle #);
             OkCallback::< 
               (# do dirSpec->putline; fs.unManageChild #);
             CancelCallback::< 
               (# do 'Cancel'->putline; fs.unManageChild #);
             HelpCallback::< 
               (# do 'Sorry, no help available'->putline #);
          #);
        getfile: @PushButton
          (# activateCallBack::< (# do fs.manageChild #)#);
        quit: @PushButton
          (# activateCallBack::< (# do stop #)#);
        init::< 
          (# 
          do fs.init; getfile.init; quit.init; 
          #);
     #);
do buttons.init;
#)

The main RowColumn contains two PushButtons:

The FileSelectionBox is popped up using the manageChild attribute. The dialog looks like this:

Three callbacks are further bound in the FileSelectionDialog: When OK is pushed, the file name selected is printed out. This is obtained using the dirSpec resource. Then the dialog is popped down using the unmanageChild attributes. If Cancel is pushed, "Cancel" is printed, and the dialog is popped down. If Help is pushed, a small disclaimer is printed out. This could easily be changed to pop up a real help dialog as in the previous example. The Filter button is used to apply the regular expression in the topmost text entry field to the list of files displayed in the dialog.


X Libraries - Reference Manual
© Mjølner Informatics

Next Previous Up Top Contents Index