WxDialog

From WxWiki

Jump to: navigation, search

As the docs describe, a modal dialog blocks program flow and user input on other windows until it is dismissed, whereas a modeless dialog behaves more like a frame in that program flow continues, and input on other windows is still possible.

If you want to block other windows without creating a dialog using the wxWindowDisabler class.

Contents

[edit] Preventing the parent frame from being raised when a modeless dialog is raised

Normally, when a modeless dialog is activated, its parent frame is raised. If you don't want that, you might just want to create the dialog with 'NULL' as its parent.

[edit] wxWindow::CaptureMouse

Also, you can use wxWindow::CaptureMouse to direct all input to a single dialog like modal dialogs.

[edit] Gotchas

[edit] No OnShow() in wxGTK

There is no OnShow event on wxGTK as of wx2.3.3.

As a workaround, consider using the EVT_PAINT instead.

[edit] Style parameter

Passing wxFRAME_DEFAULT_STYLE (instead of wxDIALOG_DEFAULT_STYLE) to a wxDialog works like a charm: you get a sizeable, closable, min/max-able Dialog; however, if you don't implement OnClose(), it won't close when the 'X' is clicked. --aZhnaZg 6/1/03 2.4.0

[edit] Change TAB order dynamically

The simplest way to manage TAB order dynamically is handle EVT_CHAR_HOOK event.

BEGIN_EVENT_TABLE(AnyDialog, wxDialog)
	EVT_CHAR_HOOK (AnyDialog::OnCharHook)
END_EVENT_TABLE()
 
void AnyDialog::OnCharHook (wxKeyEvent& event)
{
	wxWindow *win = FindFocus ();
	if (win == NULL) {
		event.Skip ();
		return;
		}
	if (event.GetKeyCode () == WXK_TAB) {
		bool backward = event.ShiftDown ();
		switch (win->GetId ()) {
			case SOME_CONTROL_ID:
				if (backward)
					FindWindow (CONTROL_BEFORE_THIS)->SetFocus ();
				else
					FindWindow (CONTROL_AFTER_THIS)->SetFocus ();			
				return;
			}
		}
	event.Skip ();
}

[edit] Crash upon closing the application or dialog

Don't use Close() with a wxDialog, use Destroy instead.

[edit] Disabled Close Button

If you forget to specify wxCLOSE_BOX, the dialog will not have a functional close button ('X'). wxCLOSE_BOX is included in wxDEFAULT_DIALOG_STYLE.

Personal tools