X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/567da5c600dc5bc6f3e5df18129f7125b433d83f..eeccd5d94ce6b11f36af95db4ac528a2e2e0c4c5:/src/msw/dialog.cpp diff --git a/src/msw/dialog.cpp b/src/msw/dialog.cpp index 83d0548920..d5f08d2412 100644 --- a/src/msw/dialog.cpp +++ b/src/msw/dialog.cpp @@ -30,7 +30,7 @@ #include "wx/msw/private.h" -#if USE_COMMON_DIALOGS +#if wxUSE_COMMON_DIALOGS #include #endif @@ -41,12 +41,13 @@ // for modal dialogs wxList wxModalDialogs; wxList wxModelessWindows; // Frames and modeless dialogs -extern wxList wxPendingDelete; +extern wxList WXDLLEXPORT wxPendingDelete; #if !USE_SHARED_LIBRARY 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) @@ -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) @@ -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(); @@ -311,7 +305,6 @@ bool wxDialog::Show(bool show) { m_hwndOldFocus = (WXHWND)::GetFocus(); - wxList DisabledWindows; if (m_modalShowing) { BringWindowToTop((HWND) GetHWND()); @@ -327,6 +320,13 @@ 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) { @@ -334,7 +334,7 @@ bool wxDialog::Show(bool show) if (::IsWindowEnabled((HWND) win->GetHWND())) { ::EnableWindow((HWND) win->GetHWND(), FALSE); - DisabledWindows.Append(win); + disabledWindows.Append(win); } node = node->Next(); } @@ -361,6 +361,10 @@ bool wxDialog::Show(bool show) TranslateMessage(&msg); DispatchMessage(&msg); } + + // If we get crashes (as per George Tasker's message) with nested modal dialogs, + // we should try removing the m_modalShowing test + 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!!! @@ -373,12 +377,15 @@ 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(); - HWND hWnd = (HWND) win->GetHWND(); - if (::IsWindow(hWnd) && (wxModalDialogs.Member(win) || wxModelessWindows.Member(win) )) - ::EnableWindow(hWnd,TRUE); + if (wxModalDialogs.Member(win) || wxModelessWindows.Member(win)) + { + HWND hWnd = (HWND) win->GetHWND(); + if (::IsWindow(hWnd)) + ::EnableWindow(hWnd,TRUE); + } node=node->Next(); } } @@ -464,27 +471,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); @@ -531,8 +530,8 @@ void wxDialog::OnOK(wxCommandEvent& event) EndModal(wxID_OK); else { - SetReturnCode(wxID_OK); - this->Show(FALSE); + SetReturnCode(wxID_OK); + this->Show(FALSE); } } } @@ -557,7 +556,7 @@ void wxDialog::OnCancel(wxCommandEvent& event) 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() @@ -568,13 +567,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) @@ -584,6 +593,8 @@ void wxDialog::OnCloseWindow(wxCloseEvent& event) { this->Destroy(); } + else + event.Veto(TRUE); } // Destroy the window (delayed, if a managed window) @@ -600,7 +611,6 @@ void wxDialog::OnSysColourChanged(wxSysColourChangedEvent& event) Ctl3dColorChange(); #else SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE)); - SetDefaultBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE)); Refresh(); #endif }