#include <commdlg.h>
#endif
-// ----------------------------------------------------------------------------
-// constants
-// ----------------------------------------------------------------------------
-
-// default dialog pos and size
-
-#define wxDIALOG_DEFAULT_X 300
-#define wxDIALOG_DEFAULT_Y 300
-
-#define wxDIALOG_DEFAULT_WIDTH 500
-#define wxDIALOG_DEFAULT_HEIGHT 500
-
// ----------------------------------------------------------------------------
// wxWin macros
// ----------------------------------------------------------------------------
wxFLAGS_MEMBER(wxCLIP_CHILDREN)
// dialog styles
- wxFLAGS_MEMBER(wxDIALOG_MODAL)
- wxFLAGS_MEMBER(wxDIALOG_MODELESS)
- wxFLAGS_MEMBER(wxNO_3D)
wxFLAGS_MEMBER(wxWS_EX_VALIDATE_RECURSIVELY)
wxFLAGS_MEMBER(wxSTAY_ON_TOP)
wxFLAGS_MEMBER(wxCAPTION)
IMPLEMENT_DYNAMIC_CLASS_XTI(wxDialog, wxTopLevelWindow,"wx/dialog.h")
wxBEGIN_PROPERTIES_TABLE(wxDialog)
- wxPROPERTY( Title,wxString, SetTitle, GetTitle, wxString() , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
- wxPROPERTY_FLAGS( WindowStyle , wxDialogStyle , long , SetWindowStyleFlag , GetWindowStyleFlag , , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
+ wxPROPERTY( Title, wxString, SetTitle, GetTitle, wxString() , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
+ wxPROPERTY_FLAGS( WindowStyle , wxDialogStyle , long , SetWindowStyleFlag , GetWindowStyleFlag , EMPTY_MACROVALUE , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
wxEND_PROPERTIES_TABLE()
wxBEGIN_HANDLERS_TABLE(wxDialog)
EVT_BUTTON(wxID_APPLY, wxDialog::OnApply)
EVT_BUTTON(wxID_CANCEL, wxDialog::OnCancel)
- EVT_CHAR_HOOK(wxDialog::OnCharHook)
-
EVT_SYS_COLOUR_CHANGED(wxDialog::OnSysColourChanged)
EVT_CLOSE(wxDialog::OnCloseWindow)
m_isShown = FALSE;
m_modalData = NULL;
m_endModalCalled = FALSE;
-
- SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE));
}
bool wxDialog::Create(wxWindow *parent,
long style,
const wxString& name)
{
- Init();
-
SetExtraStyle(GetExtraStyle() | wxTOPLEVEL_EX_DIALOG);
// save focus before doing anything which can potentially change it
if ( !wxTopLevelWindow::Create(parent, id, title, pos, size, style, name) )
return FALSE;
- if (!m_hasFont)
+
+ if ( !m_hasFont )
SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT));
+ SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE));
+
return TRUE;
}
-void wxDialog::SetModal(bool flag)
+// deprecated ctor
+wxDialog::wxDialog(wxWindow *parent,
+ const wxString& title,
+ bool WXUNUSED(modal),
+ int x,
+ int y,
+ int w,
+ int h,
+ long style,
+ const wxString& name)
{
- if ( flag )
- {
- m_windowStyle |= wxDIALOG_MODAL;
+ Init();
- wxModelessWindows.DeleteObject(this);
- }
- else
- {
- m_windowStyle &= ~wxDIALOG_MODAL;
+ Create(parent, -1, title, wxPoint(x, y), wxSize(w, h), style, name);
+}
- wxModelessWindows.Append(this);
- }
+void wxDialog::SetModal(bool WXUNUSED(flag))
+{
+ // nothing to do, obsolete method
}
wxDialog::~wxDialog()
Show(FALSE);
}
-// ----------------------------------------------------------------------------
-// kbd handling
-// ----------------------------------------------------------------------------
-
-// By default, pressing escape cancels the dialog
-void wxDialog::OnCharHook(wxKeyEvent& event)
-{
- if (GetHWND())
- {
- // "Esc" works as an accelerator for the "Cancel" button, but it
- // shouldn't close the dialog which doesn't have any cancel button
- if ( (event.m_keyCode == WXK_ESCAPE) && FindWindow(wxID_CANCEL) )
- {
- wxCommandEvent cancelEvent(wxEVT_COMMAND_BUTTON_CLICKED, wxID_CANCEL);
- cancelEvent.SetEventObject( this );
- GetEventHandler()->ProcessEvent(cancelEvent);
-
- // ensure that there is another message for this window so the
- // ShowModal loop will exit and won't get stuck in GetMessage().
- ::PostMessage(GetHwnd(), WM_NULL, 0, 0);
-
- return;
- }
- }
-
- // We didn't process this event.
- event.Skip();
-}
-
// ----------------------------------------------------------------------------
// showing the dialogs
// ----------------------------------------------------------------------------
-bool wxDialog::IsModal() const
-{
- return (GetWindowStyleFlag() & wxDIALOG_MODAL) != 0;
-}
-
bool wxDialog::IsModalShowing() const
{
- return m_modalData != NULL;
+ return IsModal();
}
wxWindow *wxDialog::FindSuitableParent() const
return parent;
}
-void wxDialog::DoShowModal()
-{
- wxCHECK_RET( !IsModalShowing(), _T("DoShowModal() called twice") );
- wxCHECK_RET( IsModal(), _T("can't DoShowModal() modeless dialog") );
-
- wxWindow *parent = GetParent();
-
- wxWindow* oldFocus = m_oldFocus;
-
- // We have to remember the HWND because we need to check
- // the HWND still exists (oldFocus can be garbage when the dialog
- // exits, if it has been destroyed)
- HWND hwndOldFocus = 0;
- if (oldFocus)
- hwndOldFocus = (HWND) oldFocus->GetHWND();
-
- // remember where the focus was
- if ( !oldFocus )
- {
- oldFocus = parent;
- if ( parent )
- hwndOldFocus = GetHwndOf(parent);
- }
-
- // enter the modal loop
- {
- wxDialogModalDataTiedPtr modalData(&m_modalData,
- new wxDialogModalData(this));
- modalData->RunLoop();
- }
-
- // and restore focus
- // Note that this code MUST NOT access the dialog object's data
- // in case the object has been deleted (which will be the case
- // for a modal dialog that has been destroyed before calling EndModal).
- if ( oldFocus && (oldFocus != this) && ::IsWindow(hwndOldFocus))
- {
- // This is likely to prove that the object still exists
- if (wxFindWinFromHandle((WXHWND) hwndOldFocus) == oldFocus)
- oldFocus->SetFocus();
- }
-}
-
bool wxDialog::Show(bool show)
{
if ( !show && m_modalData )
InitDialog();
}
- // EndModal may have been called from InitDialog handler,
- // which would cause an infinite loop if we didn't take it
- // into account
- if ( show && IsModal() && !m_endModalCalled )
- {
- // modal dialog needs a parent window, so try to find one
- if ( !GetParent() )
- {
- m_parent = FindSuitableParent();
- }
-
- DoShowModal();
- }
-
return TRUE;
}
::SetForegroundWindow(GetHwnd());
}
-// a special version for Show(TRUE) for modal dialogs which returns return code
+// show dialog modally
int wxDialog::ShowModal()
{
+ wxASSERT_MSG( !IsModal(), _T("wxDialog::ShowModal() reentered?") );
+
m_endModalCalled = FALSE;
- if ( !IsModal() )
+
+ Show();
+
+ // EndModal may have been called from InitDialog handler (called from
+ // inside Show()), which would cause an infinite loop if we didn't take it
+ // into account
+ if ( !m_endModalCalled )
{
- SetModal(TRUE);
- }
+ // modal dialog needs a parent window, so try to find one
+ wxWindow *parent = GetParent();
+ if ( !parent )
+ {
+ parent = FindSuitableParent();
+ }
+
+ // remember where the focus was
+ wxWindow *oldFocus = m_oldFocus;
+ if ( !oldFocus )
+ {
+ // VZ: do we really want to do this?
+ oldFocus = parent;
+ }
+
+ // We have to remember the HWND because we need to check
+ // the HWND still exists (oldFocus can be garbage when the dialog
+ // exits, if it has been destroyed)
+ HWND hwndOldFocus = oldFocus ? GetHwndOf(oldFocus) : NULL;
- Show(TRUE);
+
+ // enter and run the modal loop
+ {
+ wxDialogModalDataTiedPtr modalData(&m_modalData,
+ new wxDialogModalData(this));
+ modalData->RunLoop();
+ }
+
+
+ // and restore focus
+ // Note that this code MUST NOT access the dialog object's data
+ // in case the object has been deleted (which will be the case
+ // for a modal dialog that has been destroyed before calling EndModal).
+ if ( oldFocus && (oldFocus != this) && ::IsWindow(hwndOldFocus))
+ {
+ // This is likely to prove that the object still exists
+ if (wxFindWinFromHandle((WXHWND) hwndOldFocus) == oldFocus)
+ oldFocus->SetFocus();
+ }
+ }
return GetReturnCode();
}
-// NB: this function (surprizingly) may be called for both modal and modeless
-// dialogs and should work for both of them
void wxDialog::EndModal(int retCode)
{
+ wxASSERT_MSG( IsModal(), _T("EndModal() called for non modal dialog") );
+
m_endModalCalled = TRUE;
SetReturnCode(retCode);
// dialog window proc
// ---------------------------------------------------------------------------
-long wxDialog::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam)
+WXLRESULT wxDialog::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam)
{
- long rc = 0;
+ WXLRESULT rc = 0;
bool processed = FALSE;
switch ( message )
{
+#ifdef __WXWINCE__
+ // react to pressing the OK button in the title
+ case WM_COMMAND:
+ if (LOWORD(wParam) == IDOK)
+ {
+ wxButton *btn = wxDynamicCast(FindWindow(wxID_CANCEL), wxButton);
+ if ( btn && btn->IsEnabled() )
+ {
+ // if we do have a cancel button, do press it
+ btn->MSWCommand(BN_CLICKED, 0 /* unused */);
+ processed = TRUE;
+ break;
+ }
+ }
+ break;
+#endif
case WM_CLOSE:
// if we can't close, tell the system that we processed the
// message - otherwise it would close us
// we want to override the busy cursor for modal dialogs:
// typically, wxBeginBusyCursor() is called and then a modal dialog
// is shown, but the modal dialog shouldn't have hourglass cursor
- if ( IsModalShowing() && wxIsBusy() )
+ if ( IsModal() && wxIsBusy() )
{
// set our cursor for all windows (but see below)
wxCursor cursor = m_cursor;