X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/5de76427c87d8289f5c343cef16e9375056fc49f..5bd22e2636e94befad993db415b98f3c4858caa2:/src/msw/dialog.cpp diff --git a/src/msw/dialog.cpp b/src/msw/dialog.cpp index be4021a373..44919fc74c 100644 --- a/src/msw/dialog.cpp +++ b/src/msw/dialog.cpp @@ -6,7 +6,7 @@ // Created: 01/02/97 // RCS-ID: $Id$ // Copyright: (c) Julian Smart and Markus Holzem -// Licence: wxWindows licence +// Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// #ifdef __GNUG__ @@ -30,7 +30,7 @@ #include "wx/msw/private.h" -#if USE_COMMON_DIALOGS +#if wxUSE_COMMON_DIALOGS #include #endif @@ -47,6 +47,7 @@ extern wxList wxPendingDelete; IMPLEMENT_DYNAMIC_CLASS(wxDialog, wxPanel) BEGIN_EVENT_TABLE(wxDialog, wxPanel) + EVT_SIZE(wxDialog::OnSize) EVT_BUTTON(wxID_OK, wxDialog::OnOK) EVT_BUTTON(wxID_APPLY, wxDialog::OnApply) EVT_BUTTON(wxID_CANCEL, wxDialog::OnCancel) @@ -59,7 +60,7 @@ END_EVENT_TABLE() long wxDialog::MSWDefWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam) { - return ::CallWindowProc(CASTWNDPROC (FARPROC) m_oldWndProc, (HWND) GetHWND(), (UINT) nMsg, (WPARAM) wParam, (LPARAM) lParam); + return ::CallWindowProc(CASTWNDPROC m_oldWndProc, (HWND) GetHWND(), (UINT) nMsg, (WPARAM) wParam, (LPARAM) lParam); } bool wxDialog::MSWProcessMessage(WXMSG* pMsg) @@ -78,7 +79,6 @@ wxDialog::wxDialog(void) m_modalShowing = FALSE; SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE)); - SetDefaultBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE)); } bool wxDialog::Create(wxWindow *parent, wxWindowID id, @@ -89,7 +89,6 @@ bool wxDialog::Create(wxWindow *parent, wxWindowID id, const wxString& name) { SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE)); - SetDefaultBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE)); SetName(name); if (!parent) @@ -100,9 +99,9 @@ bool wxDialog::Create(wxWindow *parent, wxWindowID id, if (parent) parent->AddChild(this); if ( id == -1 ) - m_windowId = (int)NewControlId(); + m_windowId = (int)NewControlId(); else - m_windowId = id; + m_windowId = id; int x = pos.x; int y = pos.y; @@ -129,11 +128,11 @@ bool wxDialog::Create(wxWindow *parent, wxWindowID id, // Allows creation of dialogs with & without captions under MSWindows if(style & wxCAPTION){ MSWCreate(m_windowId, (wxWindow *)parent, NULL, this, NULL, x, y, width, height, 0, "wxCaptionDialog", - extendedStyle); + extendedStyle); } else{ MSWCreate(m_windowId, (wxWindow *)parent, NULL, this, NULL, x, y, width, height, 0, "wxNoCaptionDialog", - extendedStyle); + extendedStyle); } SubclassWin(GetHWND()); @@ -146,11 +145,11 @@ bool wxDialog::Create(wxWindow *parent, wxWindowID id, void wxDialog::SetModal(bool flag) { - if ( flag ) - m_windowStyle |= wxDIALOG_MODAL ; - else - if ( m_windowStyle & wxDIALOG_MODAL ) - m_windowStyle -= wxDIALOG_MODAL ; + if ( flag ) + m_windowStyle |= wxDIALOG_MODAL ; + else + if ( m_windowStyle & wxDIALOG_MODAL ) + m_windowStyle -= wxDIALOG_MODAL ; wxModelessWindows.DeleteObject(this); if (!flag) @@ -204,13 +203,13 @@ void wxDialog::OnCharHook(wxKeyEvent& event) { if (event.m_keyCode == WXK_ESCAPE) { - // Behaviour changed in 2.0: we'll send a Cancel message - // to the dialog instead of Close. - wxCommandEvent cancelEvent(wxEVT_COMMAND_BUTTON_CLICKED, wxID_CANCEL); - cancelEvent.SetEventObject( this ); - GetEventHandler()->ProcessEvent(cancelEvent); + // Behaviour changed in 2.0: we'll send a Cancel message + // to the dialog instead of Close. + wxCommandEvent cancelEvent(wxEVT_COMMAND_BUTTON_CLICKED, wxID_CANCEL); + cancelEvent.SetEventObject( this ); + GetEventHandler()->ProcessEvent(cancelEvent); - return; + return; } } // We didn't process this event. @@ -219,9 +218,9 @@ void wxDialog::OnCharHook(wxKeyEvent& event) void wxDialog::OnPaint(wxPaintEvent& event) { - // No: if you call the default procedure, it makes - // the following painting code not work. -// wxWindow::OnPaint(event); + // No: if you call the default procedure, it makes + // the following painting code not work. +// wxWindow::OnPaint(event); } void wxDialog::Fit(void) @@ -239,11 +238,6 @@ bool wxDialog::IsIconized(void) const return FALSE; } -void wxDialog::SetSize(int x, int y, int width, int height, int WXUNUSED(sizeFlags)) -{ - wxWindow::SetSize(x, y, width, height); -} - void wxDialog::SetClientSize(int width, int height) { HWND hWnd = (HWND) GetHWND(); @@ -294,7 +288,7 @@ bool wxDialog::Show(bool show) if (!modal) { if (show) { if (!wxModelessWindows.Member(this)) - wxModelessWindows.Append(this); + wxModelessWindows.Append(this); } else wxModelessWindows.DeleteObject(this); } @@ -309,7 +303,8 @@ bool wxDialog::Show(bool show) { if (show) { - wxList DisabledWindows; + m_hwndOldFocus = (WXHWND)::GetFocus(); + if (m_modalShowing) { BringWindowToTop((HWND) GetHWND()); @@ -325,15 +320,22 @@ bool wxDialog::Show(bool show) ::EnableWindow((HWND) box->GetHWND(), FALSE); node = node->Next(); } + + // if we don't do it, some window might be deleted while we have pointers + // to them in our disabledWindows list and the program will crash when it + // will try to reenable them after the modal dialog end + wxTheApp->DeletePendingObjects(); + wxList disabledWindows; + node = wxModelessWindows.First(); while (node) { wxWindow *win = (wxWindow *)node->Data(); - if (::IsWindowEnabled((HWND) win->GetHWND())) - { + if (::IsWindowEnabled((HWND) win->GetHWND())) + { ::EnableWindow((HWND) win->GetHWND(), FALSE); - DisabledWindows.Append(win); - } + disabledWindows.Append(win); + } node = node->Next(); } @@ -349,15 +351,20 @@ bool wxDialog::Show(bool show) // a message before the deletion. while (wxModalDialogs.Member(this) && m_modalShowing && GetMessage(&msg, NULL, 0, 0)) { - if (!IsDialogMessage((HWND) GetHWND(), &msg)) + if (m_acceleratorTable.Ok() && + ::TranslateAccelerator((HWND) GetHWND(), (HACCEL) m_acceleratorTable.GetHACCEL(), &msg)) + { + // Have processed the message + } + else if (!IsDialogMessage((HWND) GetHWND(), &msg)) { TranslateMessage(&msg); DispatchMessage(&msg); } if (m_modalShowing && !::PeekMessage(&msg, 0, 0, 0, PM_NOREMOVE)) - // dfgg: NB MUST test m_modalShowing again as the message loop could have triggered - // a Show(FALSE) in the mean time!!! - // Without the test, we might delete the dialog before the end of modal showing. + // dfgg: NB MUST test m_modalShowing again as the message loop could have triggered + // a Show(FALSE) in the mean time!!! + // Without the test, we might delete the dialog before the end of modal showing. { while (wxTheApp->ProcessIdle() && m_modalShowing) { @@ -366,17 +373,19 @@ bool wxDialog::Show(bool show) } } // dfgg: now must specifically re-enable all other app windows that we disabled earlier - node=DisabledWindows.First(); + node=disabledWindows.First(); while(node) { - wxWindow* win = (wxWindow*) node->Data(); + wxWindow* win = (wxWindow*) node->Data(); HWND hWnd = (HWND) win->GetHWND(); if (::IsWindow(hWnd) && (wxModalDialogs.Member(win) || wxModelessWindows.Member(win) )) ::EnableWindow(hWnd,TRUE); node=node->Next(); } } - else + else // !show { + ::SetFocus((HWND)m_hwndOldFocus); + wxModalDialogs.DeleteObject(this); wxNode *last = wxModalDialogs.Last(); @@ -416,7 +425,7 @@ bool wxDialog::Show(bool show) m_modalShowing = FALSE; } } - else + else // !modal { if (show) { @@ -455,27 +464,19 @@ void wxDialog::Centre(int direction) int x_offset,y_offset ; int display_width, display_height; int width, height, x, y; - wxFrame *frame ; - if (direction & wxCENTER_FRAME) + wxWindow *parent = GetParent(); + if ((direction & wxCENTER_FRAME) && parent) { - frame = (wxFrame*)GetParent() ; - if (frame) - { - frame->GetPosition(&x_offset,&y_offset) ; - frame->GetSize(&display_width,&display_height) ; - } + parent->GetPosition(&x_offset,&y_offset) ; + parent->GetSize(&display_width,&display_height) ; } else - frame = NULL ; - - if (frame==NULL) { wxDisplaySize(&display_width, &display_height); x_offset = 0 ; y_offset = 0 ; } - GetSize(&width, &height); GetPosition(&x, &y); @@ -490,20 +491,20 @@ void wxDialog::Centre(int direction) // Replacement for Show(TRUE) for modal dialogs - returns return code int wxDialog::ShowModal(void) { - m_windowStyle |= wxDIALOG_MODAL; - Show(TRUE); - return GetReturnCode(); + m_windowStyle |= wxDIALOG_MODAL; + Show(TRUE); + return GetReturnCode(); } void wxDialog::EndModal(int retCode) { - SetReturnCode(retCode); - Show(FALSE); + SetReturnCode(retCode); + Show(FALSE); } // Define for each class of dialog and control WXHBRUSH wxDialog::OnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor, - WXUINT message, WXWPARAM wParam, WXLPARAM lParam) + WXUINT message, WXWPARAM wParam, WXLPARAM lParam) { #if CTL3D HBRUSH hbrush = Ctl3dCtlColorEx(message, wParam, lParam); @@ -516,23 +517,23 @@ WXHBRUSH wxDialog::OnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor, // Standard buttons void wxDialog::OnOK(wxCommandEvent& event) { - if ( Validate() && TransferDataFromWindow() ) - { + if ( Validate() && TransferDataFromWindow() ) + { if ( IsModal() ) EndModal(wxID_OK); else { - SetReturnCode(wxID_OK); - this->Show(FALSE); + SetReturnCode(wxID_OK); + this->Show(FALSE); } - } + } } void wxDialog::OnApply(wxCommandEvent& event) { - if (Validate()) - TransferDataFromWindow(); - // TODO probably need to disable the Apply button until things change again + if (Validate()) + TransferDataFromWindow(); + // TODO probably need to disable the Apply button until things change again } void wxDialog::OnCancel(wxCommandEvent& event) @@ -542,13 +543,13 @@ void wxDialog::OnCancel(wxCommandEvent& event) else { SetReturnCode(wxID_CANCEL); - this->Show(FALSE); + this->Show(FALSE); } } bool wxDialog::OnClose(void) { - // Behaviour changed in 2.0: we'll send a Cancel message by default, + // Behaviour changed in 2.0: we'll send a Cancel message by default, // which may close the dialog. // Check for looping if the Cancel event handler calls Close() @@ -559,13 +560,23 @@ bool wxDialog::OnClose(void) closing.Append(this); - wxCommandEvent cancelEvent(wxEVT_COMMAND_BUTTON_CLICKED, wxID_CANCEL); - cancelEvent.SetEventObject( this ); - GetEventHandler()->ProcessEvent(cancelEvent); + wxCommandEvent cancelEvent(wxEVT_COMMAND_BUTTON_CLICKED, wxID_CANCEL); + cancelEvent.SetEventObject( this ); + GetEventHandler()->ProcessEvent(cancelEvent); closing.DeleteObject(this); - return FALSE; + return FALSE; +} + +void wxDialog::OnSize(wxSizeEvent& WXUNUSED(event)) +{ + // if we're using constraints - do use them + #if wxUSE_CONSTRAINTS + if ( GetAutoLayout() ) { + Layout(); + } + #endif } void wxDialog::OnCloseWindow(wxCloseEvent& event) @@ -575,6 +586,8 @@ void wxDialog::OnCloseWindow(wxCloseEvent& event) { this->Destroy(); } + else + event.Veto(TRUE); } // Destroy the window (delayed, if a managed window) @@ -591,13 +604,12 @@ void wxDialog::OnSysColourChanged(wxSysColourChangedEvent& event) Ctl3dColorChange(); #else SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE)); - SetDefaultBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE)); Refresh(); #endif } long wxDialog::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam) { - return wxWindow::MSWWindowProc(message, wParam, lParam); + return wxWindow::MSWWindowProc(message, wParam, lParam); }