]> git.saurik.com Git - wxWidgets.git/blob - src/msw/msgdlg.cpp
Hack to make wxStaticBox be repainted when inside a scrolling window
[wxWidgets.git] / src / msw / msgdlg.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/msw/msgdlg.cpp
3 // Purpose: wxMessageDialog
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 04/01/98
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
13 #pragma implementation "msgdlg.h"
14 #endif
15
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
18
19 #ifdef __BORLANDC__
20 #pragma hdrstop
21 #endif
22
23 #ifndef WX_PRECOMP
24 #include "wx/app.h"
25 #include "wx/defs.h"
26 #include "wx/utils.h"
27 #include "wx/dialog.h"
28 #include "wx/msgdlg.h"
29 #endif
30
31 #include "wx/msw/private.h"
32
33 // For MB_TASKMODAL
34 #ifdef __WXWINCE__
35 #include "wx/msw/wince/missing.h"
36 #endif
37
38 IMPLEMENT_CLASS(wxMessageDialog, wxDialog)
39
40 wxMessageDialog::wxMessageDialog(wxWindow *parent,
41 const wxString& message,
42 const wxString& caption,
43 long style,
44 const wxPoint& WXUNUSED(pos))
45 {
46 m_caption = caption;
47 m_message = message;
48 m_parent = parent;
49 SetMessageDialogStyle(style);
50 }
51
52 int wxMessageDialog::ShowModal()
53 {
54 if ( !wxTheApp->GetTopWindow() )
55 {
56 // when the message box is shown from wxApp::OnInit() (i.e. before the
57 // message loop is entered), this must be done or the next message box
58 // will never be shown - just try putting 2 calls to wxMessageBox() in
59 // OnInit() to see it
60 while ( wxTheApp->Pending() )
61 wxTheApp->Dispatch();
62 }
63
64 // use the top level window as parent if none specified
65 if ( !m_parent )
66 m_parent = FindSuitableParent();
67 HWND hWnd = m_parent ? GetHwndOf(m_parent) : NULL;
68
69 // translate wx style in MSW
70 unsigned int msStyle = MB_OK;
71 const long wxStyle = GetMessageDialogStyle();
72 if (wxStyle & wxYES_NO)
73 {
74 #if !(defined(__SMARTPHONE__) && defined(__WXWINCE__))
75 if (wxStyle & wxCANCEL)
76 msStyle = MB_YESNOCANCEL;
77 else
78 #endif // !(__SMARTPHONE__ && __WXWINCE__)
79 msStyle = MB_YESNO;
80
81 if (wxStyle & wxNO_DEFAULT)
82 msStyle |= MB_DEFBUTTON2;
83 }
84
85 if (wxStyle & wxOK)
86 {
87 if (wxStyle & wxCANCEL)
88 msStyle = MB_OKCANCEL;
89 else
90 msStyle = MB_OK;
91 }
92 if (wxStyle & wxICON_EXCLAMATION)
93 msStyle |= MB_ICONEXCLAMATION;
94 else if (wxStyle & wxICON_HAND)
95 msStyle |= MB_ICONHAND;
96 else if (wxStyle & wxICON_INFORMATION)
97 msStyle |= MB_ICONINFORMATION;
98 else if (wxStyle & wxICON_QUESTION)
99 msStyle |= MB_ICONQUESTION;
100
101 if ( wxStyle & wxSTAY_ON_TOP )
102 msStyle |= MB_TOPMOST;
103
104 if (hWnd)
105 msStyle |= MB_APPLMODAL;
106 else
107 msStyle |= MB_TASKMODAL;
108
109 // do show the dialog
110 int msAns = MessageBox(hWnd, m_message.c_str(), m_caption.c_str(), msStyle);
111 int ans;
112 switch (msAns)
113 {
114 default:
115 wxFAIL_MSG(_T("unexpected ::MessageBox() return code"));
116 // fall through
117
118 case IDCANCEL:
119 ans = wxID_CANCEL;
120 break;
121 case IDOK:
122 ans = wxID_OK;
123 break;
124 case IDYES:
125 ans = wxID_YES;
126 break;
127 case IDNO:
128 ans = wxID_NO;
129 break;
130 }
131 return ans;
132 }
133