class MASKING_DLL_DECLSPEC Dialog

The dialog manager class.

Inheritance:

Dialog - Widget - Rect


Public Methods

[more] Dialog()
The default constructor.
[more]bool Add(Widget &obj)
Adds the widget to the dialog if it's not already added.
[more]void Remove(Widget &obj, bool del=false)
Removes the widget from the dialog.
[more]void DialogMessage(int msg, int c=0)
Broadcasts a message with one optional parameter to all the widgets in the dialog.
[more]void SetSkin(Skin* skin)
Changes the skin of the dialog and all its child widgets
[more]BITMAP* GetCanvas(Point &offset)
Returns the drawing canvas of the dialog.
[more]BITMAP* GetCanvas(Widget* obj)
Returns the canvas for widget *obj.
[more]ScreenUpdate* GetDriver() const
Returns a pointer to the dialog's screen update driver object.
[more]Mouse* GetMouse() const
Returns a pointer to the dialog's mouse object
[more]void SetMouse(Mouse* m)
Changes the mouse system driver.
[more]Point GetOffset() const
Returns the offset of the dialog relative to it's parent.
[more]virtual void HandleEvent(Widget &obj, int msg, int arg1=0, int arg2=0)
The main event handler function.
[more]Dialog* Root()
Returns the root of the dialog hierarchy (the top level dialog)
[more]Dialog* RootWindow()
Returns the root window of the dialog hierarchy (the top level window) or the root dialog if this dialog isn't part of a window
[more]virtual void Close()
Requests the dialog to be closed.
[more]bool HasFocus()
Checks whether the dialog has input focus.
[more]void Hide()
[more]void Unhide()
[more]void Enable()
[more]void Disable()
[more]void Redraw()
[more]void Redraw(const MAS::Rect &region)
These functions do the same thing as the same functions in the Widget base class.
[more]virtual void GiveFocusTo(Widget* w)
[more]virtual void TakeFocusFrom(Widget* w)
[more]virtual void MoveFocus(Widget* src, Widget* dest)
Functions for moving input focus.
[more]virtual void GiveMouseTo(Widget* w)
[more]virtual void TakeMouseFrom(Widget* w)
[more]virtual void MoveMouse(Widget* src, Widget* dest)
Like the corresponding focus functions.
[more]void MoveFocusTo(Widget* obj)
Tries to move the input focus to the passed object.
[more]Widget* GetFocusObject() const
Returns a pointer to the widget with the input focus
[more]Widget* GetMouseObject() const
Returns a pointer to the widget with the mouse
[more]void BringToTop(Widget &w)
Floats the widget to the top of the dialog.
[more]void SetTooltipObject(Tooltip* tooltipObject)
Registers a user defined tooltip object.
[more]virtual Widget* Execute(Widget* focus = NULL)
The main loop of the dialog manager.
[more]virtual Widget* Popup(Dialog* parent = NULL, int x = MAXINT, int y = MAXINT, Widget* focus = NULL)
[more]virtual Widget* Popup(Dialog* parent, const MAS::Point &pos, Widget* focus = NULL)
Pops up a window.
[more]virtual void Centre()
Centres the dialog on the screen

Public Members

[more]enum ActionType
Determines what kind of action the dialog manager should perform on the active dialog at any time but most notably when the mouse is clicked.
[more] Checks whether the dialog has the mouse.

Protected Fields

[more]static ScreenUpdate* driver
The global system screen update driver
[more]static Mouse* mouse
The global system mouse object
[more]std::vector<Widget *> widgets
The array of the dialog's child widgets
[more]std::vector<Widget *> deletedWidgets
The array of the dialog's child widgets that are scheduled for removal and deletion
[more]Widget* focusObject
A pointer to the widget that has input focus
[more]Widget* mouseObject
A pointer to the widget the mouse is currently on top of
[more]static MouseState mouseState
Holds the current state of the mouse
[more]bool joyOn
True when a joystick button has been pressed.
[more]bool escapeExits
Set to false to prevent the dialog from being closed with escape.
[more]bool arrowKeysMoveFocus
Set to false to prevent input focuse from being changed with the arrow keys.
[more]bool tabKeyMovesFocus
Set to false to turn off moving focus with the tab key.
[more]bool close
This variable is set to true when the dialog is about to be closed
[more]Tooltip defaultTooltipObject
A pointer to the tooltip widget used to display tooltips
[more]Tooltip* tooltipObject
The default tooltip object used when the user doesn't set their own
[more]Size minSize
The minimum size of the dialog.
[more]ActionType action
The currently selected dialog action

Protected Methods

[more]virtual ActionType GetAction()
Returns the action the dialog manager should do on the dialog depending on the mouse position.
[more]void SelectAction(ActionType action)
Switches the current dialog's action to the action passed as the parameter of the function and changes the mouse cursor if required.
[more]virtual void UpdateSize()
Called whenever the dialog is moved or resized.
[more]void RedrawForeground(MAS::Widget* dirtyWidget, bool fromTheTop=false)
Helper function for redrawing all the widgets in the current dialog that are on top of the passed widget.
[more]void RedrawSiblings(MAS::Dialog* dlg, MAS::Widget* dirtyWidget)
Helper function for redrawing everything that is on top of dirtyWidget but is in dialogs that are siblings of the passed dialog
[more]void CheckForRedraw()
Checks if any widget needs to be redrawn.
[more]void CheckGeometry()
Checks if any widget has been moved or resized.
[more]void CheckForSkinChange()
Checks if any widget's skin has changed and send MSG_INITSKIN if it has
[more]virtual void HandleMouseInput()
Handles mouse moves and detects mouse clicks and sends appropriate mouse messages
[more]virtual void HandleKeyboardInput()
Hanldes keyboard and joystick input.
[more]virtual bool CheckKeyboardShortcuts(int cAscii, int cScan)
Checks if a widget in the dialog has the passed keyboard shortcut and sends it the MSG_KEY message.
[more]virtual bool SendKeyboardMessages(int cAscii, int cScan)
Sends keyboard messages corresponding to the passed ASCII code and scan code.
[more]virtual Widget* FindMouseObject()
Finds the widget the mouse is currently on top of
[more]virtual void MoveFocus(int dir)
Moves input focus using a direction variable that was generated with the keyboard.
[more]virtual void FillObjectList(std::vector<MAS_OBJ_LIST* > &objList, int (*cmp)(const MAS::Widget* , const MAS::Widget* ), MAS::Widget* focusObject, int &c)
Fills the given list with objects that can potentially be tabbed to.
[more]virtual void SetMouseCursor(int i)
Changes the mouse cursor to the cursor with the index i in the skin's cursor array
[more]bool AlreadyAdded(const Widget &w)
Tests whether the widget w is already in the dialog's widget array or not
[more]virtual void SelectDriver()
Select an update driver according to the settings in the Settings class
[more]Error CreateUpdateDriver(ScreenUpdate* driver)
Creates the selected update driver.


Documentation

The dialog manager class. Dialogs in MASkinG are nothing but widgets that can contain other widgets. You should always have one main dialog to which you can add widgets and other dialogs. Normally you should derive your own dialog class from Dialog and implement some of the virtual functions that define the apearance and behaviour of your dialog. In almost all cases you will need to implement the HandleEvent() and MsgInitSkin().

The most common practice to create dialogs is to define widgets as data members of their parent dialog and add them to the dialog in the constructor. The widgets may of course also be added and removed dynamically. Once the dialog is constructed it can be executed with the Execute() function.

The dialog class should also be used as a baseclass for all compound widgets, that is widgets that are made by combining several other more low level widgets.

ostatic ScreenUpdate* driver
The global system screen update driver

ostatic Mouse* mouse
The global system mouse object

ostd::vector<Widget *> widgets
The array of the dialog's child widgets

ostd::vector<Widget *> deletedWidgets
The array of the dialog's child widgets that are scheduled for removal and deletion

oWidget* focusObject
A pointer to the widget that has input focus

oWidget* mouseObject
A pointer to the widget the mouse is currently on top of

ostatic MouseState mouseState
Holds the current state of the mouse

obool joyOn
True when a joystick button has been pressed. This is used to prevent the joystick from being too "responsive".

obool escapeExits
Set to false to prevent the dialog from being closed with escape. Default is true.

obool arrowKeysMoveFocus
Set to false to prevent input focuse from being changed with the arrow keys. Default is true.

obool tabKeyMovesFocus
Set to false to turn off moving focus with the tab key. Default is true.

obool close
This variable is set to true when the dialog is about to be closed

oTooltip defaultTooltipObject
A pointer to the tooltip widget used to display tooltips

oTooltip* tooltipObject
The default tooltip object used when the user doesn't set their own

oenum ActionType
Determines what kind of action the dialog manager should perform on the active dialog at any time but most notably when the mouse is clicked. The action type can be one of the following:
         NONE                  - do nothing (usually when the mouse is inside the dialog
         MOVE                  - move the dialog (usually when the mouse is on the caption bar)
         RESIZE_UP_LEFT        - resize the dialog (usually when the mouse is on the
         RESIZE_UP_RIGHT         dialog border; the actual action depend on the exact
         RESIZE_DOWN_LEFT        position on the border)
         RESIZE_DOWN_RIGHT
         RESIZE_UP
         RESIZE_DOWN
         RESIZE_LEFT
         RESIZE_RIGHT

oSize minSize
The minimum size of the dialog. This is only relevant for dialogs that are not on the top level and can be resized.

oActionType action
The currently selected dialog action

ovirtual ActionType GetAction()
Returns the action the dialog manager should do on the dialog depending on the mouse position. The default implementation returns NONE if the mouse is on top of a widget that takes input focus otherwise it returns MOVE. The window class for example overloads this function to return MOVE only if the mouse is on top of the top bar and appropriate resize actions when it is on top of a window border.

ovoid SelectAction(ActionType action)
Switches the current dialog's action to the action passed as the parameter of the function and changes the mouse cursor if required. For example if the new action is RESIZE_VERTICAL it cahnges the cursor to the vertical resize arrows.

ovirtual void UpdateSize()
Called whenever the dialog is moved or resized. You should overload this function to update the position and size of the dialog's widgets acording to the new size of the dialog. For example if you have a window with a panel you should resize the panel in this function so that it will always be inside the dialog.

ovoid RedrawForeground(MAS::Widget* dirtyWidget, bool fromTheTop=false)
Helper function for redrawing all the widgets in the current dialog that are on top of the passed widget. This function needs to be called to prevent dirty widgets from drawing themselves over widgets that are on top of them in the z-order. This isn't the fastest way, it would be faster if the dirty widget's canvas would be clipped so that only the visible parts would be updated but the widgets on top might not be rectangular and may have transparent bits in them so it's actually easier to just redraw everything. If fromTheTop is true, then all the widgets in the dialog are checked to see if they need to be redrawn, otherwise the checking starts at the dirtyWidget and goes on from there. This is needed if dirtyWidget isn't actually a member of this dialog.

ovoid RedrawSiblings(MAS::Dialog* dlg, MAS::Widget* dirtyWidget)
Helper function for redrawing everything that is on top of dirtyWidget but is in dialogs that are siblings of the passed dialog

ovoid CheckForRedraw()
Checks if any widget needs to be redrawn. Cycles through all the widgets to see if any need to be redrawn and sends MSG_DRAW messages to all that do.

ovoid CheckGeometry()
Checks if any widget has been moved or resized. Like CheckForRedraw() only this function checks if any widget has been resized or moved and sends either MSG_RESIZE, MSG_MOVE or MSG_SHAPE.

ovoid CheckForSkinChange()
Checks if any widget's skin has changed and send MSG_INITSKIN if it has

ovirtual void HandleMouseInput()
Handles mouse moves and detects mouse clicks and sends appropriate mouse messages

ovirtual void HandleKeyboardInput()
Hanldes keyboard and joystick input. It converts joystick button presses to matching keyboard presses to simulate joystick input.

ovirtual bool CheckKeyboardShortcuts(int cAscii, int cScan)
Checks if a widget in the dialog has the passed keyboard shortcut and sends it the MSG_KEY message. It returns true if a widget with the keyboard shortcut is found, otherwise it returns false. This function searches for the widget with the shortcut recursively in all child dialogs and windows too.

ovirtual bool SendKeyboardMessages(int cAscii, int cScan)
Sends keyboard messages corresponding to the passed ASCII code and scan code. It returns true if a message was actually sent and false if it wasn't. This allows the messages to be passed up and down the dialog hierarchy.

ovirtual Widget* FindMouseObject()
Finds the widget the mouse is currently on top of

ovirtual void MoveFocus(int dir)
Moves input focus using a direction variable that was generated with the keyboard. The valid values for dir are: 0 (TAB), 1 (SHIFT+TAB), 2 (right), 3 (left), 4 (down) and 5 (up).

ovirtual void FillObjectList(std::vector<MAS_OBJ_LIST* > &objList, int (*cmp)(const MAS::Widget* , const MAS::Widget* ), MAS::Widget* focusObject, int &c)
Fills the given list with objects that can potentially be tabbed to. This is an internal function for constructing a list of objects that can be tabbed to. The objList parameter is passed by reference and is the list that is being constructed, cmp is the comparison function that calculates the difference between the current widget and the reference widget, w is the reference widget (the one that currently has input focus) and c is a counter of widgets that were added to the list. Derived dialogs should not overload this function but compound widgets should, but they should leave implementation empty. Instead they should implement MsgGotfocus() and MsgLostfocus() to make sure the right subwidget is given focus when the compound is tabbed to.

ovirtual void SetMouseCursor(int i)
Changes the mouse cursor to the cursor with the index i in the skin's cursor array

obool AlreadyAdded(const Widget &w)
Tests whether the widget w is already in the dialog's widget array or not

ovirtual void SelectDriver()
Select an update driver according to the settings in the Settings class

oError CreateUpdateDriver(ScreenUpdate* driver)
Creates the selected update driver. If the requested driver is DRS and the driver doesn't work, the default driver is selected instead. If the requested driver is one of the double buffering drivers and it doesn't work the next one in line is tried and then the next one and if none work, the default one is selected. For example if you want triple buffering and it doesn't work, this function will try page flipping instead, and if that doesn't work, it will try regular double buffering.

o Dialog()
The default constructor. Doesn't do much except to initialize some varibles. In a derived dialog class you should setup the dialog's children widgets and add them to the dialog. You shouldn't however do any skin specific initialization (like setting the color of some text or something). You should do this in the MsgInitSkin() function instead.

obool Add(Widget &obj)
Adds the widget to the dialog if it's not already added. Returns true if the widget was actually added, false if it already was in the dialog.

ovoid Remove(Widget &obj, bool del=false)
Removes the widget from the dialog. After removing a widget the entire dialog is redrawn. If del is true, the widget is only scheduled for for removal and deletion and is actually removed at the first chance (i.e. at the next MSG_TICK). You have to set del to true if you create widgets dynamically in your dialog (with new) because it is illegal for you to delete a widget in HandleEvent(). You should NOT set del to true if you're removing a statically created widget!

ovoid DialogMessage(int msg, int c=0)
Broadcasts a message with one optional parameter to all the widgets in the dialog. Note that most messages are passed only to widgets that are not hidden. There are some expections though: MSG_START, MSG_END, MSG_INITSKIN and perhaps some others.

ovoid SetSkin(Skin* skin)
Changes the skin of the dialog and all its child widgets

oBITMAP* GetCanvas(Point &offset)
Returns the drawing canvas of the dialog. The offset parameter is the relative starting position of the rectangle you wish to draw to. The GetCanvas() function then turns them into absolute screen coordinates so you can safely create a subbitmap or something like that. Normally you shouldn't need to call this function because the dialog manager automatically crates a canvas for widgets that need to be redrawn.

oBITMAP* GetCanvas(Widget* obj)
Returns the canvas for widget *obj. Basically this function gets the dialog's canvas, makes a subbitmap where the widget is and returns it.

oScreenUpdate* GetDriver() const
Returns a pointer to the dialog's screen update driver object. You shouldn't need to use this except maybe for reading the name of the driver or something like that.

oMouse* GetMouse() const
Returns a pointer to the dialog's mouse object

ovoid SetMouse(Mouse* m)
Changes the mouse system driver. If you want to modify the appearance and/or bahaviour of the mouse in your program, just derive your own mouse class from Mouse, create a new instance of it and pass it to this function. The mouse driver is deleted when it's not needed anymore (i.e. when a new driver is installed or when the program ends) so you don't need to worry about deleting it.

oPoint GetOffset() const
Returns the offset of the dialog relative to it's parent. Note that the top level dialog can only be placed at the top left corner of the screen.

ovirtual void HandleEvent(Widget &obj, int msg, int arg1=0, int arg2=0)
The main event handler function. The default implementation doesn't really do much except for handling a couple of events but you should overload it in your derived dialog classes and use it to handle events. The parameters are the object that caused the event to be created, the event message (the same as the MSG_SOMETHING constants) and two optional parameters which have different meanings for different messages but are most often unused.

The most common way to write the event handler is to write a large switch statement in which you call functions that correspond to the event. Here's a small example:

      void MyDialog::HandleEvent(Widget &obj, int msg, int arg1, int arg2) {
          pass the event up the class hierarchy
         Dialog::HandleEvent(obj, msg, arg1, arg2);

handle different messages switch (msg) { case MSG_ACTIVATE: if (obj == button1) OnButton1(); else if (obj == button2) OnButton2(); else if (obj == button3) OnButton3(); break;

case MSG_RPRESS: if (obj == desktop) OnPopupMenu(); break;

case MSG_MOUSEMOVE: if (obj == desktop) OnMouseMove(Point(arg1, arg2)); break;

case MSG_SCROLL: if (object == slider1) OnChangeVolume(int arg1); break; }; }

Note that it is illegal to delete a widget in HandleEvent() or in a function called from HandleEven(). If you want to remove and delete a dynamically created widget (e.g. in response to MSG_CLOSE), call Remove(obj, true) instead.

oDialog* Root()
Returns the root of the dialog hierarchy (the top level dialog)

oDialog* RootWindow()
Returns the root window of the dialog hierarchy (the top level window) or the root dialog if this dialog isn't part of a window

ovirtual void Close()
Requests the dialog to be closed. It calls MsgClose() to determine whether the dialog should really be closed or not. Call this function when you want to close the dialog or remove it but don't popup a dialog asking the user if they really want to exit. Do that in the MsgClose() function instead.

obool HasFocus()
Checks whether the dialog has input focus. A dialog has input focus if it's D_HASFOCUS flag is set or if any of it's child widgets has input focus.

o Checks whether the dialog has the mouse.
Checks whether the dialog has the mouse. A dialog has the mouse if it's D_HASMOUSE flag is set or if any of it's child widgets has the mouse.

ovoid Hide()

ovoid Unhide()

ovoid Enable()

ovoid Disable()

ovoid Redraw()

ovoid Redraw(const MAS::Rect &region)
These functions do the same thing as the same functions in the Widget base class. The only exception is that they also propagate the messages to all dialog's child widgets. For example if you ask the dialog to redraw itself it will ask all it's widgets to redraw themselves as well.

ovirtual void GiveFocusTo(Widget* w)

ovirtual void TakeFocusFrom(Widget* w)

ovirtual void MoveFocus(Widget* src, Widget* dest)
Functions for moving input focus. GiveFocusTo() tries to give focus to the passed widget if it wants it, TakeFocusFrom() takes focus away from the widget and MoveFocus() moves the input focus by first taking it away from the src object and giving it the dest object.

ovirtual void GiveMouseTo(Widget* w)

ovirtual void TakeMouseFrom(Widget* w)

ovirtual void MoveMouse(Widget* src, Widget* dest)
Like the corresponding focus functions. Except that these don't handle input focus but the fact whether a widget has the mouse or not.

ovoid MoveFocusTo(Widget* obj)
Tries to move the input focus to the passed object. This can fail if the object you're trying to give focus to is hidden, disables or doesn't want to take focus.

oWidget* GetFocusObject() const
Returns a pointer to the widget with the input focus

oWidget* GetMouseObject() const
Returns a pointer to the widget with the mouse

ovoid BringToTop(Widget &w)
Floats the widget to the top of the dialog. It does so by first removing it from the widget array and then adding it back to the end of the array.

ovoid SetTooltipObject(Tooltip* tooltipObject)
Registers a user defined tooltip object. This is then used for displaying tooltip help bubbles. Pass NULL to reset the tooltip object to the default implementation.

ovirtual Widget* Execute(Widget* focus = NULL)
The main loop of the dialog manager. This function executes the dialog and returns a pointer to the widget that last had input focus (i.e. the widget that caused the dialog to close. The optional focus parameter should be a pointer to the widget you want to have focus when the dialog starts. Note that the dialog you execute (the top level dialog) can't be smaller than the screen and you can't place it in an arbitrary position, it has to be in the top left corner of the screen.

ovirtual Widget* Popup(Dialog* parent = NULL, int x = MAXINT, int y = MAXINT, Widget* focus = NULL)

ovirtual Widget* Popup(Dialog* parent, const MAS::Point &pos, Widget* focus = NULL)
Pops up a window. Similar to Execute() except that this function pops up the dialog at the specified position which means it will remember the background of the dialog if it's not popped up from a parent dialog. Note that if you want to popup a dialog, it needs a parent so you have to pass "this" if you call this function from a dialog's message handler. Pass NULL only when the dialog is not popped up from a parent dialog. In this case a dummy parent will be created automatically and it will remember the background of the dialog.

ovirtual void Centre()
Centres the dialog on the screen


Direct child classes:
Window
TabPanel
Splitter
Menu
GroupBox
GLDialog
CompoundWidget
Friends:
class MASKING_DLL_DECLSPEC Widget

Alphabetic index Hierarchy of classes


Back to front page   |   page generated with DOC++