]> git.saurik.com Git - wxWidgets.git/blame - src/msw/msgdlg.cpp
applying OSAF patch for "toolbar selection not correct on Mac after calling Realize...
[wxWidgets.git] / src / msw / msgdlg.cpp
CommitLineData
2bda0e17 1/////////////////////////////////////////////////////////////////////////////
e5b50758 2// Name: src/msw/msgdlg.cpp
2bda0e17
KB
3// Purpose: wxMessageDialog
4// Author: Julian Smart
5// Modified by:
6// Created: 04/01/98
7// RCS-ID: $Id$
6c9a19aa 8// Copyright: (c) Julian Smart
65571936 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
676d6550
JS
33// For MB_TASKMODAL
34#ifdef __WXWINCE__
35#include "wx/msw/wince/missing.h"
36#endif
37
2bda0e17 38IMPLEMENT_CLASS(wxMessageDialog, wxDialog)
2bda0e17 39
0d7ea902
VZ
40wxMessageDialog::wxMessageDialog(wxWindow *parent,
41 const wxString& message,
42 const wxString& caption,
43 long style,
44 const wxPoint& WXUNUSED(pos))
2bda0e17
KB
45{
46 m_caption = caption;
47 m_message = message;
2bda0e17 48 m_parent = parent;
e5b50758 49 SetMessageDialogStyle(style);
2bda0e17
KB
50}
51
0d7ea902 52int wxMessageDialog::ShowModal()
2bda0e17 53{
a543e3ce 54 if ( !wxTheApp->GetTopWindow() )
0d7ea902
VZ
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 }
93c95e18 63
b8505921 64 // use the top level window as parent if none specified
a543e3ce
VZ
65 if ( !m_parent )
66 m_parent = FindSuitableParent();
67 HWND hWnd = m_parent ? GetHwndOf(m_parent) : NULL;
b8505921
VZ
68
69 // translate wx style in MSW
0d7ea902 70 unsigned int msStyle = MB_OK;
e5b50758
WS
71 const long wxStyle = GetMessageDialogStyle();
72 if (wxStyle & wxYES_NO)
0d7ea902 73 {
3180bc0e 74#if !(defined(__SMARTPHONE__) && defined(__WXWINCE__))
e5b50758 75 if (wxStyle & wxCANCEL)
0d7ea902
VZ
76 msStyle = MB_YESNOCANCEL;
77 else
3180bc0e 78#endif // !(__SMARTPHONE__ && __WXWINCE__)
0d7ea902 79 msStyle = MB_YESNO;
93c95e18 80
e5b50758 81 if (wxStyle & wxNO_DEFAULT)
0d7ea902
VZ
82 msStyle |= MB_DEFBUTTON2;
83 }
84
e5b50758 85 if (wxStyle & wxOK)
0d7ea902 86 {
e5b50758 87 if (wxStyle & wxCANCEL)
0d7ea902
VZ
88 msStyle = MB_OKCANCEL;
89 else
90 msStyle = MB_OK;
91 }
e5b50758 92 if (wxStyle & wxICON_EXCLAMATION)
0d7ea902 93 msStyle |= MB_ICONEXCLAMATION;
e5b50758 94 else if (wxStyle & wxICON_HAND)
0d7ea902 95 msStyle |= MB_ICONHAND;
e5b50758 96 else if (wxStyle & wxICON_INFORMATION)
0d7ea902 97 msStyle |= MB_ICONINFORMATION;
e5b50758 98 else if (wxStyle & wxICON_QUESTION)
0d7ea902 99 msStyle |= MB_ICONQUESTION;
2bda0e17 100
e5b50758 101 if ( wxStyle & wxSTAY_ON_TOP )
a7fd7c78
VZ
102 msStyle |= MB_TOPMOST;
103
0d7ea902
VZ
104 if (hWnd)
105 msStyle |= MB_APPLMODAL;
106 else
107 msStyle |= MB_TASKMODAL;
93c95e18 108
b8505921
VZ
109 // do show the dialog
110 int msAns = MessageBox(hWnd, m_message.c_str(), m_caption.c_str(), msStyle);
111 int ans;
0d7ea902
VZ
112 switch (msAns)
113 {
b8505921
VZ
114 default:
115 wxFAIL_MSG(_T("unexpected ::MessageBox() return code"));
116 // fall through
117
0d7ea902
VZ
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;
2bda0e17
KB
132}
133