wxBaseDialog

A common base class for dialog boxes.  The wxBaseDialog class provides a common look and feel to all classes derived from it.  This allows a consistent UI across the entire application and even across different OS platforms.  By default, wxBaseDialog provides a black background, with bitmapped title and text, and a resizable, custom-drawn frame.  Default OK and Cancel button are also provided, though they may be hidden or altered by derived classes.  There are also virtual functions available for derived classes to do their own specialized handling on OK, Cancel, and Size events.  Derived classes may also do their own customized painting and window sizing, if desired.

Derived From

wxDialog (see http://www.wxwindows.org/manuals/2.4.2/wx109.htm)

Project

UICore

Include

BaseDialog.h

Summary
A common base class for dialog boxes.
The wxBaseDialog constructor.
Prevents users from resizing the dialog.
Allows derived classes to handle the OK event.
Allows derived classes to handle the Cancel event.
Allows derived classes to handle the Size event.
The OK button.
The Cancel button.
The wxWidgets event table declaration.
Sizing and movement flags.
Draws a sizing rectangle in the desktop window.
Calculates what stretch mode should be set when the user starts dragging the edge of the dialog to resize the dialog.
Calculates the new rectangle size for the window based on the current stretch mode and the amount of mouse movement that has occurred.
Calculates the best available size for the window, preventing it from being sized too small, if it has constraints.
Sets the window cursor correctly based on the given stretch/move mode.
Allows custom painting.
On Win32, sets the curved window region.
Handles the OK button being clicked.
Handles the Cancel button being clicked.
Paints the window.
Erases the window.
Resizes the window.
Handles the left mouse down event.
Handles the left mouse up event.
Handles the mouse moving.
The memory bitmap for the window.
The title bar bitmap.
The title text for the dialog window.
The current stretch/move mode.
The origin point for window movement.
The origin point for calculating mouse delta values.
The last drawn sizing/movement rectangle.
Whether the window is resizable.

Protected

Summary
The wxBaseDialog constructor.
Prevents users from resizing the dialog.
Allows derived classes to handle the OK event.
Allows derived classes to handle the Cancel event.
Allows derived classes to handle the Size event.
The OK button.
The Cancel button.
The wxWidgets event table declaration.

Constructors

wxBaseDialog

wxBaseDialog(wxWindow *parent,
ISizerPtr sizer,
const wxString &label)

The wxBaseDialog constructor.  Creates the dialog and then calls the CreateSizers function of the given ISizer pointer, which creates the specific layout for that dialog window.

Parameters

parentThe parent window of the dialog.
sizerThe ISizer that will create the dialog layout.  Must not be NULL.
labelThe caption of the dialog.

Destructor

~wxBaseDialog

virtual ~wxBaseDialog()

Functions

DisableResize

void DisableResize()

Prevents users from resizing the dialog.  Useful for dialogs that must be pixel-specific in size.

Virtual Functions

Ok

virtual void Ok()

Allows derived classes to handle the OK event.  Called when the user clicks on the OK button.  The default implementation ends the dialog with a wxID_OK return code.

Cancel

virtual void Cancel()

Allows derived classes to handle the Cancel event.  Called when the user clicks on the Cancel button.  The default implementation ends the dialog with a wxID_CANCEL return code.

Size

virtual void Size(wxSizeEvent &event)

Allows derived classes to handle the Size event.  Called when the dialog window is resized.  The default implementation resizes the drawing bitmap and the bitmapped title bar.

Parameters

eventThe size event.

Variables

mpOK

wxClearButton *mpOK

The OK button.  See wxClearButton.

mpCancel

wxClearButton *mpCancel

The Cancel button.  See wxClearButton.

DECLARE_EVENT_TABLE

The wxWidgets event table declaration.

Private

Summary
Sizing and movement flags.
Draws a sizing rectangle in the desktop window.
Calculates what stretch mode should be set when the user starts dragging the edge of the dialog to resize the dialog.
Calculates the new rectangle size for the window based on the current stretch mode and the amount of mouse movement that has occurred.
Calculates the best available size for the window, preventing it from being sized too small, if it has constraints.
Sets the window cursor correctly based on the given stretch/move mode.
Allows custom painting.
On Win32, sets the curved window region.
Handles the OK button being clicked.
Handles the Cancel button being clicked.
Paints the window.
Erases the window.
Resizes the window.
Handles the left mouse down event.
Handles the left mouse up event.
Handles the mouse moving.
The memory bitmap for the window.
The title bar bitmap.
The title text for the dialog window.
The current stretch/move mode.
The origin point for window movement.
The origin point for calculating mouse delta values.
The last drawn sizing/movement rectangle.
Whether the window is resizable.

Enumerations

Mode

Sizing and movement flags.  Used when the window is being resized by a user or moved on the screen to properly interpret the mouse events and adjust the window in response.  Flags are: ModeNone, ModeMove, ModeStretchN, ModeStretchS, ModeStretchE, ModeStretchW, ModeStretchNE, ModeStretchSW, ModeStretchNW, ModeStretchSE.

Functions

DrawSizingRect

void DrawSizingRect(const wxRect &rect)

Draws a sizing rectangle in the desktop window.  Uses a wxScreenDC and the wxINVERT draw type to allow sizing to leave no visual artifacts behind.

Parameters

rectThe sizing rectangle to draw.

FindStretchEntry

Mode FindStretchEntry(const wxPoint &point)

Calculates what stretch mode should be set when the user starts dragging the edge of the dialog to resize the dialog.

Parameters

pointThe point at which the drag is occurring.

Returns

The stretch mode for resizing the window.

GetStretchRect

void GetStretchRect(const wxPoint &delta,
wxRect &rect)

Calculates the new rectangle size for the window based on the current stretch mode and the amount of mouse movement that has occurred.

Parameters

deltaThe amount of mouse movement that has occurred.
rectThe rectangle to store the new window size.

CalcStretchSize

void CalcStretchSize(const wxPoint &delta,
wxSize &size,
wxPoint &overflow)

Calculates the best available size for the window, preventing it from being sized too small, if it has constraints.

Parameters

deltaThe amount of mouse movement that has occurred.
sizeThe size of the window after stretching.
overflowAny amount the desired size is different from the actual possible size.

SetDialogCursor

void SetDialogCursor(Mode mode)

Sets the window cursor correctly based on the given stretch/move mode.

Parameters

modeThe mode to set the cursor with.

Virtual Functions

Paint

virtual void Paint(wxMemoryDC &dc)

Allows custom painting.  Derived classes can override Paint to customize drawing.  The default implementation draw a black background with a bitmapped title bar and curved outline edges.

Parameters

dcThe memory device context to draw to.

SetRegion

virtual void SetRegion()

On Win32, sets the curved window region.  Derived classes can override SetRegion to customize their shape on Win32.  The default implementation uses SetWindowRgn to create a window with curved edges.

Event Message Handling

OnOk

void OnOk(wxCommandEvent &event)

Handles the OK button being clicked.  Immediately calls the Ok function.

Parameters

eventThe button click event.

OnCancel

void OnCancel(wxCommandEvent &event)

Handles the Cancel button being clicked.  Immediately calls the Cancel function.

Parameters

eventThe button click event.

OnPaint

void OnPaint(wxPaintEvent &event)

Paints the window.  Selects the memory bitmap into the device context and then calls the Paint function.

Parameters

eventThe paint event.

OnBackground

void OnBackground(wxEraseEvent &event)

Erases the window.  Necessary in order to prevent flickering when redrawing the window.

Parameters

eventThe erase event.

OnSize

void OnSize(wxSizeEvent &event)

Resizes the window.

Parameters

eventThe size event.

OnLeftDown

void OnLeftDown(wxMouseEvent &event)

Handles the left mouse down event.  Performs a test to see if the dialog is about to be moved or resized.

Parameters

eventThe mouse event.

OnLeftUp

void OnLeftUp(wxMouseEvent &event)

Handles the left mouse up event.  Cleans up any window sizing or movement that was occurring.

Parameters

eventThe mouse event.

OnMouseMove

void OnMouseMove(wxMouseEvent &event)

Handles the mouse moving.  Sizes or moves the window if the appropriate mode is engaged.

Parameters

eventThe mouse event.

Variables

mMemBitmap

wxBitmap mMemBitmap

The memory bitmap for the window.  Prevents flickering by having the entire scene drawn into the memory bitmap via the Paint function and then blitting the bitmap in one pass to the screen in OnPaint.

mTitleBitmap

wxBitmap mTitleBitmap

The title bar bitmap.  Grows or shrinks in width as the dialog window grows or shrinks.

mLabel

wxString mLabel

The title text for the dialog window.  Drawn on top of the title bitmap during painting.

mMode

Mode mMode

The current stretch/move mode.

mMoveOrigin

wxPoint mMoveOrigin

The origin point for window movement.  Used as the anchor location to determine where the window should be moved to based on to the user’s mouse movements.

mMouseOrigin

wxPoint mMouseOrigin

The origin point for calculating mouse delta values.  Set when the user causes a left mouse down event and used as the origin point for calculating how far the user has moved the mouse.  Applied to both window streching and window movement.

mLastRect

wxRect mLastRect

The last drawn sizing/movement rectangle.  Allows for old rectangles to be reinverted as new sizing/movement rectanagles are drawn, which prevents display artifacts.

mResizable

bool mResizable

Whether the window is resizable.  True if resizable, false if not.

wxBaseDialog(wxWindow *parent,
ISizerPtr sizer,
const wxString &label)
The wxBaseDialog constructor.
virtual ~wxBaseDialog()
void DisableResize()
Prevents users from resizing the dialog.
virtual void Ok()
Allows derived classes to handle the OK event.
virtual void Cancel()
Allows derived classes to handle the Cancel event.
virtual void Size(wxSizeEvent &event)
Allows derived classes to handle the Size event.
wxClearButton *mpOK
The OK button.
wxClearButton *mpCancel
The Cancel button.
void DrawSizingRect(const wxRect &rect)
Draws a sizing rectangle in the desktop window.
Mode FindStretchEntry(const wxPoint &point)
Calculates what stretch mode should be set when the user starts dragging the edge of the dialog to resize the dialog.
void GetStretchRect(const wxPoint &delta,
wxRect &rect)
Calculates the new rectangle size for the window based on the current stretch mode and the amount of mouse movement that has occurred.
void CalcStretchSize(const wxPoint &delta,
wxSize &size,
wxPoint &overflow)
Calculates the best available size for the window, preventing it from being sized too small, if it has constraints.
void SetDialogCursor(Mode mode)
Sets the window cursor correctly based on the given stretch/move mode.
virtual void Paint(wxMemoryDC &dc)
Allows custom painting.
virtual void SetRegion()
On Win32, sets the curved window region.
void OnOk(wxCommandEvent &event)
Handles the OK button being clicked.
void OnCancel(wxCommandEvent &event)
Handles the Cancel button being clicked.
void OnPaint(wxPaintEvent &event)
Paints the window.
void OnBackground(wxEraseEvent &event)
Erases the window.
void OnSize(wxSizeEvent &event)
Resizes the window.
void OnLeftDown(wxMouseEvent &event)
Handles the left mouse down event.
void OnLeftUp(wxMouseEvent &event)
Handles the left mouse up event.
void OnMouseMove(wxMouseEvent &event)
Handles the mouse moving.
wxBitmap mMemBitmap
The memory bitmap for the window.
wxBitmap mTitleBitmap
The title bar bitmap.
wxString mLabel
The title text for the dialog window.
Mode mMode
The current stretch/move mode.
wxPoint mMoveOrigin
The origin point for window movement.
wxPoint mMouseOrigin
The origin point for calculating mouse delta values.
wxRect mLastRect
The last drawn sizing/movement rectangle.
bool mResizable
Whether the window is resizable.
UICore provides a set of common UI controls that promote a constant look and feel across all aspects of the UI.
An interface for sizing dialog windows.
A completely custom-drawn bitmapped button.