******************* DUIM-Frames Library ******************* .. current-library:: duim .. current-module:: duim-frames Overview ======== The DUIM-Frames library contains interfaces that define a wide variety of frames for use in your GUI applications, as well as the necessary functions, generic functions, and macros for creating and manipulating them. The library contains a single module, *duim-frames*, from which all the interfaces described in this chapter are exposed. `DUIM-Frames Module`_ contains complete reference entries for each exposed interface. Frames are the basic components used to display DUIM objects on-screen. An instance of type :class:`` is an object representing some state in a user application, plus the sheets in its interface. Frames control the overall appearance of the entire window, allowing you to distinguish, for example, between a normal window and a dialog box, or allowing you to specify modal or modeless dialog boxes, and might include such things as a menu bar, a tool bar, and a status bar. Frames exist on windows and contain sheets, which can be instances of :class:`` or :class:``, or any of their subclasses, and an event loop. The event loop associated with a frame is represented by an instance of a subclass of :class:``. An overview of these subclasses is provided in `Subclasses of \`_. The class hierarchy for DUIM-Frames =================================== This section presents an overview of the available classes of frame, frame event, and command-related classes, and describes the class hierarchy present. The class and its subclasses ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ The base class for all DUIM frames is the :class:`` class, which is itself a subclass of :drm:``. In addition, there are a number of classes related to commands that are subclasses of :drm:``, together with a number of classes related to events that occur in frames. - :drm:`` - :class:`` - :class:`` - See :ref:`gadgets-subclasses-of-page` - :class:`` - See `Subclasses of \`_ - :class:`` - :class:`` - See `Subclasses of \`_ - :class:`` - :class:`` - :class:`` - :class:`` The :class:`` class represents the base class for all types of frame. An introduction to the subclasses available is given in `Subclasses of \`_. The :class:`` class represents the base class for all events that can occur. Although this class and the :class:`` subclass are exposed by the DUIM-Sheets library, the subclasses of :class:`` itself are exposed by the DUIM-Frames library. See `Subclasses of \`_ for an introduction to these subclasses. See the :doc:`DUIM-Sheets Library `, for a complete description of the DUIM-Sheets library. The remaining four classes exposed by the DUIM-Frames library relate to commands and their use in application menus. :class:`` This class is used to create the most basic type of command. A command is an operation that can be invoked as a callback from a menu item, a button, or other suitable interface control. :class:`` This class is used to define commands whose effects can be reversed. Typically, the user chooses the command *Edit > Undo* to reverse the effects of a command of this class. :class:`` The :class:`` class is used to define the complete menu structure of an application frame, from the menu bar and menus to the menu items on each menu. :class:`` This class represents a menu item on a menu defined in a command table. Subclasses of ^^^^^^^^^^^^^^^^^^^^^ A number of subclasses of :class:`` are provided to allow you to create a variety of common types of frame. - :class:`` - :class:`` - :class:`` - :class:`` - :class:`` :class:`` This class is the most common sort of frame and is used to create a standard window in an application. :class:`` This class is used to create dialog boxes for use in an application. :class:`` This class is used to create property sheets for use in an application. Property sheets are a special type of dialog box which make use of tab controls to display several pages of information within the same dialog. :class:`` This class is used to create wizards for use in an application. Wizards are a special type of multi-page dialog in which the user is guided through a series of sequential steps, filling out any information requested and using *Next* and *Back* buttons to navigate to the next or previous steps in the process. Subclasses of ^^^^^^^^^^^^^^^^^^^^^^^^^^^ The :class:`` class provides a number of subclasses that describe various events that can occur in frames. - :class:`` - :class:`` - :class:`` - :class:`` - :class:`` - :class:`` - :class:`` - :class:`` The name of each of these subclasses accurately reflects the type of event that they are used to represent. The classes :class:`` and :class:`` represent a frame being created or destroyed. The classes :class:`` and :class:`` represent the events that occur when a frame is displayed on the computer screen or removed from it. The class :class:`` represents the act of exiting a frame, and the class :class:`` represents the event where a frame has been successfully exited. In addition, the class :class:`` has a subclass :class:``. This is reserved for the special case where the frame that has been exited is actually the parent frame for the whole application, in which case the whole application is exited, together with any other frames that may have been spawned as a result of using the application. .. note:: The classes :class:`` and :class:`` are distinct from the classes :class:`` and :class:``. A frame is not necessarily mapped as soon as it is created, and any frame can be unmapped from the screen without actually destroying it (for example, a frame may be iconized). .. _frames-subclasses-of-page: Subclasses of ^^^^^^^^^^^^^^^^^^^^ Although the :class:`` class is itself a subclass of :class:``, and is exposed by the DUIM-Gadgets library, two of its subclasses are exposed by the DUIM-Frames library: :class:`` and :class:``. See :ref:`gadgets-subclasses-of-page` for an introduction to these classes. DUIM-Commands Library ===================== All commands-related interfaces are now defined directly in the Commands library. However, these same interfaces are imported to and re-exported from DUIM-Frames, so they can be used in almost the same way as for Harlequin Dylan 1.0. You should continue to look for commands-related documentation in this chapter. A consequence of the introduction of the Commands library is that a slight change in syntax is required in the definition of commands in command tables. In Harlequin Dylan 1.0, two approaches could be taken when specifying a command in a table. For example, a menu item could be specified by either of the following: .. code-block:: dylan menu-item "My Command" = make(, function: my-command), menu-item "My Command" = my-command, Beginning with Harlequin Dylan 1.1, only the last of these may be used. This may require you to change some of your code. DUIM-Frames Module ================== This section contains a complete reference of all the interfaces that are exported from the *duim-frames* module. .. method:: = :specializer: Returns true if the specified commands are the same. :signature: = *command1* *command2* => *equal?* :param command1: An instance of type :class:``. :param command2: An instance of type :class:``. :value equal?: An instance of type :drm:``. :description: Returns true if *command1* and *command2* are the same. .. generic-function:: add-command Adds a command to the specified command table. :signature: add-command *command-table* *command* #key *name* *menu image* *accelerator* *mnemonic* *error?* => () :param command-table: An instance of type :class:``. :param command: An instance of type ``type-union(, )``. :param #key name: An instance of type ``false-or()``. :param #key menu: An instance of type ``false-or()``. :param #key image: An instance of type ``false-or()``. :param #key accelerator: An instance of type ``false-or()``. :param #key mnemonic: An instance of type ``false-or()``. :param #key error?: An instance of type :drm:``. Default value: ``#t``. :description: You can supply a keyboard accelerator or a mnemonic using the *accelerator* and *mnemonic* arguments respectively. Adds *command* to *command-table*. The argument *name* is the command-line name for the command. - When *name* is ``#f``, the command is not available via command-line interactions. - When *name* is a string, that string is the command-line name for the command. For the purposes of command-line name lookup, the character case of *name* is ignored. The argument *menu* is a menu for *command*. - When *menu* is ``#f``, *command* is not available via menus. - When *menu* is a string, the string is used as the menu name. - When *menu* is ``#t`` and *name* is a string, then *name* is used as the menu name. - When *menu* is ``#t`` and *name* is not a string, a menu name is automatically generated. - When *menu* is a list of the form ``(string, menu-options)``, *string* is the menu name and *menu-options* consists of a list of keyword-value pairs. Each keyword-value pair is itself a list. The valid keywords are ``after:``, ``documentation:``, and ``text-style:``, which are interpreted as for :gf:`add-command-table-menu-item`. You can supply an image that will appear on the menu next to the command name using the *image* argument. When supplying an image, bear in mind the size of the menu: you should only supply a small icon-sized image for a menu command. There may also be other interface guidelines that you wish to follow when using images in menu items. The value for *accelerator* is either keyboard gesture or ``#f``. When it is a gesture, this gesture represents the keystroke accelerator for the command; otherwise the command is not available via keystroke accelerators. Similarly, if mnemonic is supplied, this gesture is used as a mnemonic for the command. If *command* is already present in the command table and *error?* is ``#t``, an error is signalled. When *command* is already present in the command table and *error?* is ``#f``, then the old command-line name, menu, and keystroke accelerator are removed from the command table before creating the new one. :seealso: - :gf:`remove-command` .. generic-function:: add-command-table-menu-item Adds a menu item to the specified command table. :signature: add-command-table-menu-item *command-table* *string* *type* *value* #key *documentation* *after* *accelerator* *mnemonic* *text-style* *error?* *items* *label-key* *value-key* *test* *callback* => *menu-item* :param command-table: An instance of type :class:``. :param string: An instance of type ``false-or()``. :param type: An instance of type ``one-of(#"command", #"function", #"menu", #"divider")``. :param value: An instance of type :drm:``. :param #key documentation: An instance of type :drm:``. :param #key after: An instance of type ``one-of(#"start", #"end", #"sort")``, or an instance of :drm:``. Default value: ``#"end"``. :param #key accelerator: An instance of type ``false-or()``. :param #key mnemonic: An instance of type ``false-or()``. :param #key text-style: An instance of type :class:``. :param #key error?: An instance of type :drm:``. Default value: ``#t``. :param #key items: An instance of type ``limited(, of: )``. :param #key label-key: An instance of type :drm:``. :param #key value-key: An instance of type :drm:``. :param #key test: An instance of type :drm:``. :param #key callback: An instance of type :drm:``. :value menu-item: An instance of type :class:``. :description: Adds a command menu item to the menu in *command-table*. The *string* argument is the name of the command menu item; its character case is ignored. The *type* of the item is either ``#"command"``, ``#"function"``, ``#"menu"``, or ``#"divider"``. When *type* is ``#"command"``, *value* must be one of the following: - A command (a list consisting of a command name followed by a list of the arguments for the command). - A command name. In this case, *value* behaves as though a command with no arguments was supplied. When all the required arguments for the command are supplied, clicking on an item in the menu invokes the command immediately. Otherwise, the user is prompted for the remaining required arguments. When *type* is ``#"function"``, *value* must be a function having indefinite extent that, when called, returns a command. The function is called with two arguments: - The gesture used to select the item (either a keyboard or button press event). - A "numeric argument". When *type* is ``#"menu"``, this indicates that a sub-menu is required, and *value* must be another command table or the name of another command table. When *type* is ``#"divider"``, some sort of a dividing line is displayed in the menu at that point. If *string* is supplied, it will be drawn as the divider instead of a line. If the look and feel provided by the underlying window system has no corresponding concept, ``#"divider"`` items may be ignored. When *type* is ``#"divider"``, *value* is ignored. The argument *documentation* specifies a documentation string, This can be used to provide the user with some online documentation for the menu item. Documentation strings are often displayed in a status bar at the bottom of an application; highlighting the menu item using the mouse pointer displays the documentation string in the status bar. The *text-style* argument, if supplied, represents text style. This specifies the font family, style, and weight with which to display the menu item in the menu. For most menu items, you should just use the default text style (that is, the one that the user chooses for all applications). However, in certain cases, some variation is allowed. The *text-style* argument is of most use in context sensitive pop-up menus, which often have a default menu item. This is usually the command that is invoked by pressing the RETURN key on the current selection: for example, in a list of files, the default command usually opens the selected file in the application associated with it. In Windows 95, the default command is displayed using a bold font, to differentiate it from other commands in the menu, and you should use the text-style argument to specify this. When altering the text style of a menu item, you should always try to stick to any relevant interface guidelines. The *items* argument is used to specify the gadgets that are to be supplied to the command table as menu items. You can supply either push boxes, check boxes, or radio boxes. The *after* argument denotes where in the menu the new item is to be added. It must be one of the following: - ``#"start"`` Adds the new item to the beginning of the menu. - ``#"end"`` Adds the new item to the end of the menu. A string naming an existing entry - Adds the new item after that entry. - ``#"sort"`` Insert the item in such as way as to maintain the menu in alphabetical order. If *mnemonic* is supplied, the item is added to the keyboard mnemonic table for the command table. The value of *mnemonic* must be a keyboard gesture name. When *mnemonic* is supplied and *type* is ``#"command"`` or ``#"function"``, typing a key on the keyboard that matches the mnemonic invokes the command specified by *value*. When *type* is ``#"menu"``, the command is read from the submenu indicated by *value* in a window system specific manner. This usually means that the submenu itself is displayed, allowing the user to see the available options at that point. When *accelerator* is supplied, typing a key sequence on the keyboard that matches the accelerator invokes the command specified by *value*, no matter what *type* is. If the item named by *string* is already present in the command table and *error?* is ``#t``, then an error is signalled. When the item is already present in the command table and *error?* is ``#f``, the old item is removed from the menu before adding the new item. Note that the character case of *string* is ignored when searching the command table. :seealso: - :class:`` - :gf:`remove-command-table-menu-item` .. class:: :sealed: :instantiable: The class of events signalled when an application exits. :superclasses: :class:`` :description: The class of events signalled when an application exits. An instance of this class is distributed when your application is exited, for instance by choosing *File > Exit* from its main menu bar. :seealso: - :gf:`exit-frame` - :class:`` .. generic-function:: apply-in-frame Applies the specified function to the given arguments in the main thread of the frame. :signature: apply-in-frame *frame function arg* #rest *args* => () :param frame: An instance of type :class:``. :param function: An instance of type :drm:``. :param arg: An instance of type :drm:``. :param #rest args: Instances of type :drm:``. :description: Applies *function* to the given arguments in the main thread of *frame*. You must supply at least one argument (*arg*), though you can optionally supply as many additional arguments as you like. :seealso: - :gf:`call-in-frame` .. generic-function:: call-in-frame Calls the specified function with the given arguments in the main thread of the frame. :signature: call-in-frame *frame function* #rest *args* => () :param frame: An instance of type :class:``. :param function: An instance of type :drm:``. :param #rest args: Instances of type :drm:``. :description: Calls *function* with the given arguments in the main thread of *frame*. :seealso: - :gf:`apply-in-frame` .. generic-function:: cancel-dialog Cancels the specified dialog. :signature: cancel-dialog *dialog* #key *destroy?* => () :param dialog: An instance of type :class:``. :param destroy?: An instance of type :drm:``. Default value: ``#t``. :description: Cancels *dialog* and removes it from the screen. Any changes that the user has made to information displayed in the dialog is discarded. If *destroy?* is ``#t`` then the dialog is unmapped from the screen. This is the default callback used for the cancel button in a dialog. :example: The following example defines a button, ``*no-button*``, that calls :gf:`cancel-dialog` as its activate-callback. This button is then used in a dialog that simply replaces the standard cancel button for the newly defined dialog. Note that the example assumes the existence of a similar ``*yes-button*`` to replace the exit button. .. code-block:: dylan define variable *no-button* = make(, label: "No", activate-callback: cancel-dialog, max-width: $fill); define variable *dialog* = make(, exit-button?: #f, cancel-button?: #f, layout: vertically () make(