]> git.saurik.com Git - wxWidgets.git/blob - src/msw/msgdlg.cpp
a3f4628ae1d358e8df20e82da04620eec7661294
[wxWidgets.git] / src / msw / msgdlg.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: 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 and Markus Holzem
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifdef __GNUG__
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 <stdio.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 #include <math.h>
34 #include <stdlib.h>
35 #include <string.h>
36
37 #define wxDIALOG_DEFAULT_X 300
38 #define wxDIALOG_DEFAULT_Y 300
39
40 #if !USE_SHARED_LIBRARY
41 IMPLEMENT_CLASS(wxMessageDialog, wxDialog)
42 #endif
43
44 wxMessageDialog::wxMessageDialog(wxWindow *parent, const wxString& message, const wxString& caption,
45 long style, const wxPoint& pos)
46 {
47 m_caption = caption;
48 m_message = message;
49 m_dialogStyle = style;
50 m_parent = parent;
51 }
52
53 int wxMessageDialog::ShowModal(void)
54 {
55 HWND hWnd = 0;
56 if (m_parent) hWnd = (HWND) m_parent->GetHWND();
57 unsigned int msStyle = MB_OK;
58 if (m_dialogStyle & wxYES_NO)
59 {
60 if (m_dialogStyle & wxCANCEL)
61 msStyle = MB_YESNOCANCEL;
62 else
63 msStyle = MB_YESNO;
64 }
65 if (m_dialogStyle & wxOK)
66 {
67 if (m_dialogStyle & wxCANCEL)
68 msStyle = MB_OKCANCEL;
69 else
70 msStyle = MB_OK;
71 }
72 if (m_dialogStyle & wxICON_EXCLAMATION)
73 msStyle |= MB_ICONEXCLAMATION;
74 else if (m_dialogStyle & wxICON_HAND)
75 msStyle |= MB_ICONHAND;
76 else if (m_dialogStyle & wxICON_INFORMATION)
77 msStyle |= MB_ICONINFORMATION;
78 else if (m_dialogStyle & wxICON_QUESTION)
79 msStyle |= MB_ICONQUESTION;
80
81 if (hWnd)
82 msStyle |= MB_APPLMODAL;
83 else
84 msStyle |= MB_TASKMODAL;
85
86 int msAns = MessageBox(hWnd, (LPCSTR)(const char *)m_message, (LPCSTR)(const char *)m_caption, msStyle);
87 int ans = wxOK;
88 switch (msAns)
89 {
90 case IDCANCEL:
91 ans = wxID_CANCEL;
92 break;
93 case IDOK:
94 ans = wxID_OK;
95 break;
96 case IDYES:
97 ans = wxID_YES;
98 break;
99 case IDNO:
100 ans = wxID_NO;
101 break;
102 }
103 return ans;
104 }
105
106 /*
107 * Common dialogs
108 *
109 */
110
111 // Pop up a message box
112 int wxMessageBox(const wxString& message, const wxString& caption, const long style,
113 wxWindow *parent, const int x, const int y)
114 {
115 wxMessageDialog dialog(parent, message, caption, style);
116
117 int ans = dialog.ShowModal();
118 switch ( ans )
119 {
120 case wxID_OK:
121 return wxOK;
122 break;
123 case wxID_YES:
124 return wxYES;
125 break;
126 case wxID_NO:
127 return wxNO;
128 break;
129 default:
130 case wxID_CANCEL:
131 return wxCANCEL;
132 break;
133 }
134
135 return ans;
136 }
137
138