MDIGadget()

Syntax

Result = MDIGadget(#Gadget, x, y, Width, Height, SubMenu, MenuItem [, Flags])
Description
Creates a client area, in which child windows can be displayed. These child windows are fully movable and sizable by the user in this area. If #PB_Any is used as '#Gadget' parameter, the new gadget identifier will be returned as 'Result'.

An MDIGadget() is always connected to a window Menu (see CreateMenu()). Therefore a MDIGadget() can only be put on a window that has a menu attached to it. The gadget will give the user the opportunity to select the child windows through one of the windows submenus. In the 'SubMenu' parameter, you have to specify the submenu index (created with MenuTitle()) where these items will be attached to (the first submenu has the index 0). The Gadget will add a seperator at the end of this menu, and then add one item for each currently displayed child window.

The gadget will require a set of Menu item identifiers (see the 'MenuID' parameter of MenuItem()) to add these menuitems. In the 'MenuItem' parameter of MDIGadget() you have to specify the lowest number that the gadget can use for that purpose. It will use numbers above that, when new child windows are added, so you need to reserve at least as much numbers as you plan to add items. It is recommended to use a number above all menu identifiers of your program, to make sure there is never a collision.

Additional notes:
Because of the connection with the window menu, there can only be one MDIGadget() on a window, however you can put another one in a second window if you wish. You can only put this gadget directly on a window, you can NOT put it inside a ContainerGadget(), SplitterGadget() or PanelGadget().
As the whole point of this gadget is to dynamically display data, it is recommended to use the #PB_Any feature to populate a child window with gadgets.

The child windows of these gadget are numbered from 0 to the number of windows, just like in any other gadget. You must be aware, that if you add a new window inbetween the numbers of the allready open windows, that all numbers of those windows after the one you inserted will be increased by one. The same applies to removing windows. The best way to manage data for each mdi window is with a LinkedList, because the same rules apply there. (When you add an item inbetween, the index of those above gets increased.)

The following values can be used in the 'Flags' parameter:
  #PB_MDI_AutoSize       : The gadget will automatically resize itself to fit the parent window.
                           If you have no other gadgets on the window, this is a helpfull option.
  #PB_MDI_BorderLess     : There will be no border drawn around the client area.
  #PB_MDI_NoScrollBars   : When the user drags a childwindow outside of the displayed area, there will be no scrollbars.
The MDIGadget() returns the following values through EventType() in case of an event:
  #PB_EventType_Focus    : The active child window has changed. Use GetGadgetState() to find out which.
  #PB_EventType_CloseItem: The user has clicked the close button at the active window. Also use 
                           GetGadgetState() to get it's number.
  #PB_EventType_SizeItem : A child window has been resized. As this doesn't need to be the active one, 
                           use GetGadgetAttribute() with #PB_MDI_SizedItem to find out which.
                           use GetGadgetItemAttribute() to get the new size of the child window.
You can add a 'mini help' to this gadget by using GadgetToolTip().

The following commands can be used to manage the gadget contents:

- CountGadgetItems() : Return the number of child windows.
- AddGadgetItem() : Add a new child window to the gadget.
- RemoveGadgetItem() : Close a child window.
- ClearGadgetItemList() : Close all child windows.
- GetGadgetItemText() : Get the title of a child window.
- SetGadgetItemText() : Set the title of a child window.
- GetGadgetState() : Get the currently focused child window.
- SetGadgetState() : Set the currently focused window, or arrange the child windows. (see GetGadgetState() for more info.)
- GetGadgetItemState() : Check if a child window is maximized, minimized, normal or hidden.
- SetGadgetItemState() : Set the state of a child window (maximized, minimized, hidden).
- GetGadgetItemAttribute() : Get the width or height of a child window.
- SetGadgetItemAttribute() : Set the width or height of a child window.
- GetGadgetAttribute() : Use with #PB_MDI_SizedItem to find out which childwindow has been resized.

Example:
  If OpenWindow(0,0,0,400,300,#PB_Window_SystemMenu|#PB_Window_ScreenCentered|#PB_Window_SizeGadget|#PB_Window_MaximizeGadget,"MDIGadget")
    If CreateGadgetList(WindowID(0)) And CreateMenu(0, WindowID(0))
      MenuTitle("Menu index 0")
      MenuTitle("MDI windows menu")
        MenuItem(0, "self created item")
        MenuItem(1, "self created item")
        
      MDIGadget(0, 0, 0, 0, 0, 1, 2, #PB_MDI_AutoSize)
        AddGadgetItem(0, -1, "child window")
          ; add gadgets here...
      CloseGadgetList()
    EndIf
    Repeat : Until WaitWindowEvent()=#PB_Event_CloseWindow
  EndIf

Supported OS

Windows, Linux, MacOS X

<- ListViewGadget() - Gadget Index - OpenGadgetList() ->