// Created: 01/02/97
// RCS-ID: $Id$
// Copyright: (c) Julian Smart and Markus Holzem
-// Licence: wxWindows licence
+// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#endif
#include "wx/msw/private.h"
+#include "wx/log.h"
-#if USE_COMMON_DIALOGS
+#if wxUSE_COMMON_DIALOGS
#include <commdlg.h>
#endif
// 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_BUTTON(wxID_OK, wxDialog::OnOK)
- 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)
-END_EVENT_TABLE()
-
+ 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)
+ EVT_CHAR_HOOK(wxDialog::OnCharHook)
+ EVT_SYS_COLOUR_CHANGED(wxDialog::OnSysColourChanged)
+ EVT_CLOSE(wxDialog::OnCloseWindow)
+ END_EVENT_TABLE()
#endif
-long wxDialog::MSWDefWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam)
-{
- return ::CallWindowProc(CASTWNDPROC (FARPROC) m_oldWndProc, (HWND) GetHWND(), (UINT) nMsg, (WPARAM) wParam, (LPARAM) lParam);
-}
-
-bool wxDialog::MSWProcessMessage(WXMSG* pMsg)
-{
- return (::IsDialogMessage((HWND) GetHWND(), (MSG*)pMsg) != 0);
-}
-
bool wxDialog::MSWOnClose(void)
{
return Close();
m_modalShowing = FALSE;
SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE));
- SetDefaultBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE));
}
-bool wxDialog::Create(wxWindow *parent, const wxWindowID id,
- const wxString& title,
- const wxPoint& pos,
- const wxSize& size,
- const long style,
- const wxString& name)
+bool wxDialog::Create(wxWindow *parent, wxWindowID id,
+ const wxString& title,
+ const wxPoint& pos,
+ const wxSize& size,
+ long style,
+ const wxString& name)
{
- SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE));
- SetDefaultBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE));
- SetName(name);
-
- if (!parent)
- wxTopLevelWindows.Append(this);
+ SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE));
+ SetName(name);
+
+ if (!parent)
+ wxTopLevelWindows.Append(this);
-// windowFont = wxTheFontList->FindOrCreateFont(11, wxSWISS, wxNORMAL, wxNORMAL);
+ // windowFont = wxTheFontList->FindOrCreateFont(11, wxSWISS, wxNORMAL, wxNORMAL);
- if (parent) parent->AddChild(this);
+ if (parent) parent->AddChild(this);
- if ( id == -1 )
- m_windowId = (int)NewControlId();
- else
- m_windowId = id;
-
- int x = pos.x;
- int y = pos.y;
- int width = size.x;
- int height = size.y;
-
- if (x < 0) x = wxDIALOG_DEFAULT_X;
- if (y < 0) y = wxDIALOG_DEFAULT_Y;
-
- m_windowStyle = style;
-
- m_isShown = FALSE;
- m_modalShowing = FALSE;
-
- if (width < 0)
- width = 500;
- if (height < 0)
- height = 500;
+ if ( id == -1 )
+ m_windowId = (int)NewControlId();
+ else
+ m_windowId = id;
+
+ int x = pos.x;
+ int y = pos.y;
+ int width = size.x;
+ int height = size.y;
+
+ if (x < 0) x = wxDIALOG_DEFAULT_X;
+ if (y < 0) y = wxDIALOG_DEFAULT_Y;
+
+ m_windowStyle = style;
+
+ m_isShown = FALSE;
+ m_modalShowing = FALSE;
+
+ if (width < 0)
+ width = 500;
+ if (height < 0)
+ height = 500;
+
+ WXDWORD extendedStyle = MakeExtendedStyle(m_windowStyle);
+ if (m_windowStyle & wxSTAY_ON_TOP)
+ extendedStyle |= WS_EX_TOPMOST;
+
+ // Allows creation of dialogs with & without captions under MSWindows,
+ // resizeable or not (but a resizeable dialog always has caption -
+ // otherwise it would look too strange)
+ const char *dlg;
+ if ( style & wxTHICK_FRAME )
+ dlg = "wxResizeableDialog";
+ else if ( style & wxCAPTION )
+ dlg = "wxCaptionDialog";
+ else
+ dlg = "wxNoCaptionDialog";
+ MSWCreate(m_windowId, parent, NULL, this, NULL,
+ x, y, width, height,
+ 0, // style is not used if we have dlg template
+ dlg,
+ extendedStyle);
- WXDWORD extendedStyle = MakeExtendedStyle(m_windowStyle);
- if (m_windowStyle & wxSTAY_ON_TOP)
- extendedStyle |= WS_EX_TOPMOST;
+ HWND hwnd = (HWND)GetHWND();
- // 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);
- }
- else{
- MSWCreate(m_windowId, (wxWindow *)parent, NULL, this, NULL, x, y, width, height, 0, "wxNoCaptionDialog",
- extendedStyle);
- }
+ if ( !hwnd )
+ {
+ wxLogError(_("Failed to created dialog."));
- SubclassWin(GetHWND());
+ return FALSE;
+ }
- SetWindowText((HWND) GetHWND(), (const char *)title);
- SetFont(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT));
+ SubclassWin(GetHWND());
+
+ SetWindowText(hwnd, title);
+ SetFont(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT));
- return TRUE;
+ return TRUE;
}
-void wxDialog::SetModal(const bool flag)
+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)
{
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.
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)
wxWindow::Fit();
}
-void wxDialog::Iconize(const bool WXUNUSED(iconize))
+void wxDialog::Iconize(bool WXUNUSED(iconize))
{
// Windows dialog boxes can't be iconized
}
return FALSE;
}
-void wxDialog::SetSize(const int x, const int y, const int width, const int height, const int WXUNUSED(sizeFlags))
-{
- wxWindow::SetSize(x, y, width, height);
-}
-
-void wxDialog::SetClientSize(const int width, const int height)
+void wxDialog::DoSetClientSize(int width, int height)
{
HWND hWnd = (HWND) GetHWND();
RECT rect;
- GetClientRect(hWnd, &rect);
+ ::GetClientRect(hWnd, &rect);
RECT rect2;
GetWindowRect(hWnd, &rect2);
int actual_height = rect2.bottom - rect2.top - rect.bottom + height;
MoveWindow(hWnd, rect2.left, rect2.top, actual_width, actual_height, TRUE);
-#if WXWIN_COMPATIBILITY
- GetEventHandler()->OldOnSize(actual_width, actual_height);
-#else
+
wxSizeEvent event(wxSize(actual_width, actual_height), m_windowId);
- event.eventObject = this;
+ event.SetEventObject( this );
GetEventHandler()->ProcessEvent(event);
-#endif
}
void wxDialog::GetPosition(int *x, int *y) const
return m_isShown;
}
-bool wxDialog::Show(const bool show)
+bool wxDialog::Show(bool show)
{
m_isShown = show;
if (!modal) {
if (show) {
if (!wxModelessWindows.Member(this))
- wxModelessWindows.Append(this);
+ wxModelessWindows.Append(this);
} else
wxModelessWindows.DeleteObject(this);
}
{
if (show)
{
- wxList DisabledWindows;
+ m_hwndOldFocus = (WXHWND)::GetFocus();
+
if (m_modalShowing)
{
BringWindowToTop((HWND) GetHWND());
::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();
}
// 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 ( !wxTheApp->ProcessMessage((WXMSG *)&msg) )
{
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!!!
- // 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)
{
}
}
// 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);
+ wxWindow* win = (wxWindow*) node->Data();
+ if (wxModalDialogs.Member(win) || wxModelessWindows.Member(win))
+ {
+ HWND hWnd = (HWND) win->GetHWND();
+ if (::IsWindow(hWnd))
+ ::EnableWindow(hWnd,TRUE);
+ }
node=node->Next();
}
}
- else
+ else // !show
{
+ ::SetFocus((HWND)m_hwndOldFocus);
+
wxModalDialogs.DeleteObject(this);
wxNode *last = wxModalDialogs.Last();
m_modalShowing = FALSE;
}
}
- else
+ else // !modal
{
if (show)
{
return wxString(wxBuffer);
}
-void wxDialog::Centre(const int direction)
+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);
// Replacement for Show(TRUE) for modal dialogs - returns return code
int wxDialog::ShowModal(void)
{
- 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(const WXHDC pDC, const WXHWND pWnd, const WXUINT nCtlColor,
- WXUINT message, WXWPARAM wParam, WXLPARAM lParam)
+WXHBRUSH wxDialog::OnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor,
+ WXUINT message, WXWPARAM wParam, WXLPARAM lParam)
{
-#if CTL3D
+#if wxUSE_CTL3D
HBRUSH hbrush = Ctl3dCtlColorEx(message, wParam, lParam);
return (WXHBRUSH) hbrush;
#else
// 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)
else
{
SetReturnCode(wxID_CANCEL);
- this->Show(FALSE);
+ this->Show(FALSE);
}
}
-bool wxDialog::OnClose(void)
+void wxDialog::OnCloseWindow(wxCloseEvent& event)
{
- // Behaviour changed in 2.0: we'll send a Cancel message by default,
+ // We'll send a Cancel message by default,
// which may close the dialog.
- // Check for looping if the Cancel event handler calls Close()
+ // Check for looping if the Cancel event handler calls Close().
+
+ // Note that if a cancel button and handler aren't present in the dialog,
+ // nothing will happen when you close the dialog via the window manager, or
+ // via Close().
+ // We wouldn't want to destroy the dialog by default, since the dialog may have been
+ // created on the stack.
+ // However, this does mean that calling dialog->Close() won't delete the dialog
+ // unless the handler for wxID_CANCEL does so. So use Destroy() if you want to be
+ // sure to destroy the dialog.
+ // The default OnCancel (above) simply ends a modal dialog, and hides a modeless dialog.
static wxList closing;
-
+
if ( closing.Member(this) )
- return FALSE;
-
+ return;
+
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); // This may close the dialog
closing.DeleteObject(this);
-
- return FALSE;
-}
-
-void wxDialog::OnCloseWindow(wxCloseEvent& event)
-{
- // Compatibility
- if ( GetEventHandler()->OnClose() || event.GetForce())
- {
- this->Destroy();
- }
}
// Destroy the window (delayed, if a managed window)
return TRUE;
}
+void wxDialog::OnSize(wxSizeEvent& WXUNUSED(event))
+{
+ // if we're using constraints - do use them
+ #if wxUSE_CONSTRAINTS
+ if ( GetAutoLayout() ) {
+ Layout();
+ }
+ #endif
+}
+
void wxDialog::OnSysColourChanged(wxSysColourChangedEvent& event)
{
-#if CTL3D
+#if wxUSE_CTL3D
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);
-}
-
+}
\ No newline at end of file