## The XsMotifWindow Class

The XsMDICanvas requires that all documents be a subclass of XsMDIWindow or a subclass of a class derived from it. By itself XsMDIWindow does not define any appearance or behavior for the documents. However, XsMotifWindow, derived from XsMDIWindow, defines a MWM-like look-and-feel to a document.

Documents in your application should be derived from XsMotifWindow. This class provides the look-and-feel of Motif window and supports the interaction with the XsMDICanvas. It is up to the application to define the contents of each document.

Constructor and Destructor:

The XsMotifWindow constructor accepts one argument:

  XsMotifWindow (const char *name)

The name parameter specifies the name of the document and is used as the widget name for the underlying implementation. The name parameter is also used as the default title and icon-name for the document.

Note: The XsMotifWindow constructor does not create any widgets. Rather it only initializes internal variables. The widgets are not created until the document is added to the canvas. The XsMDICanvas calls the member-function XsMotifWindow::_buildClientArea() when it needs to create the document widgets.

The XsMotifWindow destructor destroys the document widgets (if they have been created) and frees its internal storage. It is up to the application to free all documents. The XsMDICanvas will not destroy the documents for you.

Document Utilities:

Although rarely called from the application, the XsMotifWindow supports a number of utility functions to manipulate the document.

  virtual void raise ( )
  virtual void lower ( )
  virtual void minimize ( )
  virtual void maximize ( )
  virtual void restore ( )
  virtual void close ( )

The close member-function does not destroy the document, it simply hides it from view. You can restore a closed document with XsMotifWindow::show().

The following member-functions are used to change/query the appearance of the document:

  void setTitle (const char *name)
  const char *title ( ) const
  void setIconName (const char *name)
  const char *iconName ( ) const
  void setPixmap (Pixmap pixmap)
  Pixmap pixmap ( ) const
  Widget icon ( ) const
  Boolean minimized ( ) const
  Boolean maximized ( ) const
  virtual void setPosition (Position x, Position y)
  virtual void setSize (Dimension width, Dimension height)

The setPixmap member-function accepts a pixmap which the document then uses as the decoration on the icon. Because the document does not make a copy of the pixmap, it is important that the application not free the pixmap until all documents that reference it are deleted. The document does, however, make a local copy of the title or icon-name string passed to it, so the application is free to do whatever it wants to the passed-in string. The icon member-function returns the widget that is used to implement the icon.

Creating Window Subclasses:

The application must derive its documents from XsMotifWindow in order to define the contents of the document. The XsMDICanvas calls the protected member-function _buildClientArea when it creates the document. Each class derived from XsMotifWindow must override this pure-virtual member-function.

The member-function _buildClientArea is called with a single argument:

  virtual void _buildClientArea (Widget parent)

The parent argument should be used as the parent of the contents of the document. This widget is an unmanaged XmForm widget, and all of the standard resources and constrains apply to it. The XsMDICanvas is responsible for managing the parent widget at the appropriate time.

As an example, consider the following:

    // _buildClientArea (called to create document contents)

    void MyDocument::_buildClientArea (Widget parent)
    {
       assert (parent != 0);

    // Create a main window with some dummy menus

       Widget mainW = XtVaCreateWidget ("mainWin", xmMainWindowWidgetClass, parent,
          XmNtopAttachment, XmATTACH_FORM, XmNbottomAttachment, XmATTACH_FORM,
          XmNleftAttachment, XmATTACH_FORM, XmNrightAttachment, XmATTACH_FORM,
          NULL);
       ...

       XtManageChild (mainW);
    }

In this case, an XmMainWindow is created as the child of the parent widget. The XmMainWindow is then attached to the 4 sides of the parent form. Note also that the main window is managed before returning from the function.

Resources:

The XsMotifWindow supports the following resources:

       Name              Class             Type           Default
    ------------------------------------------------------------------------------
       borderSize        BorderSize        Dimension      6
       buttonSize        ButtonSize        Dimension      23
       title             Title             String         dynamic
       titleFont         TitleFont         String         -*-helvetica-bold-o-normal-*-14-*-*-*-*-*-iso8859-1
       iconSize          IconSize          Dimension      70
       iconName          IconName          String         dynamic
       iconFont          IconFont          String         *-helvetica-bold-r-normal-*-12-*-*-*-*-*-iso8859-1
       XmNiconX          XmCIconX          Position       dynamic
       XmNiconY          XmCIconY          Position       dynamic
       saveUnder         SaveUnder         Boolean        True
       restoreString     RestoreString     String         "Restore"
       moveString        MoveString        String         "Move"
       sizeString        SizeString        String         "Size"
       minimizeString    MinimizeString    String         "Minimize"
       maximizeString    MaximizeString    String         "Maximize"
       raiseString       RaiseString       String         "Raise"
       lowerString       LowerString       String         "Lower"
       closeString       CloseString       String         "Close"
       menuFont          MenuFont          String         -*-helvetica-bold-o-normal-*-14-*-*-*-*-*-iso8859-1
       showBorder        ShowBorder        Boolean        True
       showResize        ShowResize        Boolean        True
       showTitle         ShowTitle         Boolean        True
       showMenu          ShowMenu          Boolean        True
       showMinimize      ShowMinimize      Boolean        True
       showMaximize      ShowMaximize      Boolean        True
       lowerOnIconify    LowerOnIconify    Boolean        False
       XmNminWidth       XmCMinWidth       Dimension      dynamic
       XmNmaxWidth       XmCMaxWidth       Dimension      dynamic
       XmNminHeight      XmCMinHeight      Dimension      dynamic
       XmNmaxHeight      XmCMaxHeight      Dimension      dynamic

  borderSize
    Size of the window border.
  buttonSize
    Size of the window buttons.
  title
    Title of the window. The default is the name of the window instance.
  titleFont
    Font used to draw the window title.
  iconSize
    Size of the icon representation.
  iconName
    String used on the title. If unspecified, the window title is used.
  iconFont
    Font used to draw the icon-name.
  XmNiconX
    X-position of the icon. The default location is the top-left corner of the window when it is iconified.
  XmNiconY
    Y-position of the icon. The default location is the top-left corner of the window when it is iconified.
  saveUnder
    Enables/Disables save-unders for the menu.
  restoreString
    String used as the "restore" menu item.
  moveString
    String used as the "move" menu item.
  sizeString
    String used as the "size" menu item.
  minimizeString
    String used as the "minimize" menu item.
  maximizeString
    String used as the "maximize" menu item.
  raiseString
    String used as the "raise" menu item.
  lowerString
    String used as the the "lower" menu item.
  closeString
    String used as the "close" menu item.
  menuFont
    Font used to draw the menu strings.
  showBorder
    Enables/Disables the window border. If the border is disabled, the resize-handles are automatically disabled.
  showResize
    Enables/Disables the window resize handles.
  showTitle
    Enables/Disables the window title. If the title is disabled, all of the window buttons are automatically disabled.
  showMenu
    Enables/Disables the window menu button.
  showMinimize
    Enables/Disables the window minimize button.
  showMaximize
    Enables/Disables the window maximize button.
  lowerOnIconify
    Automatically lower windows when iconified.
  XmNminWidth
    Minimium window width. The default is about four times the size of the window button.
  XmNmaxWidth
    Maximum window width. The default is not to constrain the maximum size.
  XmNminHeight
    Minimum window height. The default is about four times the size of the window button.
  XmNmaxHeight
    Maximum window height. The default is not to constrain the maximum size.

XsMotifWindow Implementation:

As a convenience to those who wish to modify the XsMotifWindow code, here is a diagram of the internal class structure: