]> git.saurik.com Git - wxWidgets.git/blame - src/msw/msgdlg.cpp
Modified wxGetHomeDir to take environment variable HOME into account.
[wxWidgets.git] / src / msw / msgdlg.cpp
CommitLineData
2bda0e17
KB
1/////////////////////////////////////////////////////////////////////////////
2// Name: msgdlg.cpp
3// Purpose: wxMessageDialog
4// Author: Julian Smart
5// Modified by:
6// Created: 04/01/98
7// RCS-ID: $Id$
6c9a19aa
JS
8// Copyright: (c) Julian Smart
9// Licence: wxWindows licence
2bda0e17
KB
10/////////////////////////////////////////////////////////////////////////////
11
14f355c2 12#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
2bda0e17
KB
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
35bc781e 24 #include "wx/app.h"
0d7ea902
VZ
25 #include "wx/defs.h"
26 #include "wx/utils.h"
27 #include "wx/dialog.h"
28 #include "wx/msgdlg.h"
2bda0e17
KB
29#endif
30
31#include "wx/msw/private.h"
32
2bda0e17 33IMPLEMENT_CLASS(wxMessageDialog, wxDialog)
2bda0e17 34
0d7ea902
VZ
35wxMessageDialog::wxMessageDialog(wxWindow *parent,
36 const wxString& message,
37 const wxString& caption,
38 long style,
39 const wxPoint& WXUNUSED(pos))
2bda0e17 40{
e8e4025d
VZ
41#ifdef __WXDEBUG__
42 // check for common programming errors
43 if ( (style & wxID_OK) == wxID_OK )
44 {
45 // programmer probably confused wxID_OK with wxOK. Correct one is wxOK.
46 wxFAIL_MSG( _T("wxMessageBox: Did you mean wxOK (and not wxID_OK)?") );
47 }
48#endif // __WXDEBUG__
49
2bda0e17
KB
50 m_caption = caption;
51 m_message = message;
52 m_dialogStyle = style;
53 m_parent = parent;
54}
55
0d7ea902 56int wxMessageDialog::ShowModal()
2bda0e17 57{
a543e3ce 58 if ( !wxTheApp->GetTopWindow() )
0d7ea902
VZ
59 {
60 // when the message box is shown from wxApp::OnInit() (i.e. before the
61 // message loop is entered), this must be done or the next message box
62 // will never be shown - just try putting 2 calls to wxMessageBox() in
63 // OnInit() to see it
64 while ( wxTheApp->Pending() )
65 wxTheApp->Dispatch();
66 }
93c95e18 67
b8505921 68 // use the top level window as parent if none specified
a543e3ce
VZ
69 if ( !m_parent )
70 m_parent = FindSuitableParent();
71 HWND hWnd = m_parent ? GetHwndOf(m_parent) : NULL;
b8505921
VZ
72
73 // translate wx style in MSW
0d7ea902
VZ
74 unsigned int msStyle = MB_OK;
75 if (m_dialogStyle & wxYES_NO)
76 {
77 if (m_dialogStyle & wxCANCEL)
78 msStyle = MB_YESNOCANCEL;
79 else
80 msStyle = MB_YESNO;
93c95e18 81
0d7ea902
VZ
82 if (m_dialogStyle & wxNO_DEFAULT)
83 msStyle |= MB_DEFBUTTON2;
84 }
85
86 if (m_dialogStyle & wxOK)
87 {
88 if (m_dialogStyle & wxCANCEL)
89 msStyle = MB_OKCANCEL;
90 else
91 msStyle = MB_OK;
92 }
93 if (m_dialogStyle & wxICON_EXCLAMATION)
94 msStyle |= MB_ICONEXCLAMATION;
95 else if (m_dialogStyle & wxICON_HAND)
96 msStyle |= MB_ICONHAND;
97 else if (m_dialogStyle & wxICON_INFORMATION)
98 msStyle |= MB_ICONINFORMATION;
99 else if (m_dialogStyle & wxICON_QUESTION)
100 msStyle |= MB_ICONQUESTION;
2bda0e17 101
a7fd7c78
VZ
102 if ( m_dialogStyle & wxSTAY_ON_TOP )
103 msStyle |= MB_TOPMOST;
104
0d7ea902
VZ
105 if (hWnd)
106 msStyle |= MB_APPLMODAL;
4676948b 107#ifndef __WXWINCE__
0d7ea902
VZ
108 else
109 msStyle |= MB_TASKMODAL;
4676948b 110#endif
93c95e18 111
b8505921
VZ
112 // do show the dialog
113 int msAns = MessageBox(hWnd, m_message.c_str(), m_caption.c_str(), msStyle);
114 int ans;
0d7ea902
VZ
115 switch (msAns)
116 {
b8505921
VZ
117 default:
118 wxFAIL_MSG(_T("unexpected ::MessageBox() return code"));
119 // fall through
120
0d7ea902
VZ
121 case IDCANCEL:
122 ans = wxID_CANCEL;
123 break;
124 case IDOK:
125 ans = wxID_OK;
126 break;
127 case IDYES:
128 ans = wxID_YES;
129 break;
130 case IDNO:
131 ans = wxID_NO;
132 break;
133 }
134 return ans;
2bda0e17
KB
135}
136