]> git.saurik.com Git - wxWidgets.git/blame - src/msw/msgdlg.cpp
don't crash on zero length string in DoDrawRotatedText
[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
2bda0e17
KB
12// For compilers that support precompilation, includes "wx.h".
13#include "wx/wxprec.h"
14
15#ifdef __BORLANDC__
7520f3da 16 #pragma hdrstop
2bda0e17
KB
17#endif
18
19#ifndef WX_PRECOMP
35bc781e 20 #include "wx/app.h"
0d7ea902
VZ
21 #include "wx/utils.h"
22 #include "wx/dialog.h"
23 #include "wx/msgdlg.h"
2bda0e17
KB
24#endif
25
26#include "wx/msw/private.h"
27
676d6550
JS
28// For MB_TASKMODAL
29#ifdef __WXWINCE__
30#include "wx/msw/wince/missing.h"
31#endif
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
KB
40{
41 m_caption = caption;
42 m_message = message;
2bda0e17 43 m_parent = parent;
e5b50758 44 SetMessageDialogStyle(style);
2bda0e17
KB
45}
46
0d7ea902 47int wxMessageDialog::ShowModal()
2bda0e17 48{
a543e3ce 49 if ( !wxTheApp->GetTopWindow() )
0d7ea902
VZ
50 {
51 // when the message box is shown from wxApp::OnInit() (i.e. before the
52 // message loop is entered), this must be done or the next message box
53 // will never be shown - just try putting 2 calls to wxMessageBox() in
54 // OnInit() to see it
55 while ( wxTheApp->Pending() )
56 wxTheApp->Dispatch();
57 }
93c95e18 58
b8505921 59 // use the top level window as parent if none specified
a543e3ce
VZ
60 if ( !m_parent )
61 m_parent = FindSuitableParent();
62 HWND hWnd = m_parent ? GetHwndOf(m_parent) : NULL;
b8505921
VZ
63
64 // translate wx style in MSW
0d7ea902 65 unsigned int msStyle = MB_OK;
e5b50758
WS
66 const long wxStyle = GetMessageDialogStyle();
67 if (wxStyle & wxYES_NO)
0d7ea902 68 {
3180bc0e 69#if !(defined(__SMARTPHONE__) && defined(__WXWINCE__))
e5b50758 70 if (wxStyle & wxCANCEL)
0d7ea902
VZ
71 msStyle = MB_YESNOCANCEL;
72 else
3180bc0e 73#endif // !(__SMARTPHONE__ && __WXWINCE__)
0d7ea902 74 msStyle = MB_YESNO;
93c95e18 75
e5b50758 76 if (wxStyle & wxNO_DEFAULT)
0d7ea902
VZ
77 msStyle |= MB_DEFBUTTON2;
78 }
79
e5b50758 80 if (wxStyle & wxOK)
0d7ea902 81 {
e5b50758 82 if (wxStyle & wxCANCEL)
0d7ea902
VZ
83 msStyle = MB_OKCANCEL;
84 else
85 msStyle = MB_OK;
86 }
e5b50758 87 if (wxStyle & wxICON_EXCLAMATION)
0d7ea902 88 msStyle |= MB_ICONEXCLAMATION;
e5b50758 89 else if (wxStyle & wxICON_HAND)
0d7ea902 90 msStyle |= MB_ICONHAND;
e5b50758 91 else if (wxStyle & wxICON_INFORMATION)
0d7ea902 92 msStyle |= MB_ICONINFORMATION;
e5b50758 93 else if (wxStyle & wxICON_QUESTION)
0d7ea902 94 msStyle |= MB_ICONQUESTION;
2bda0e17 95
e5b50758 96 if ( wxStyle & wxSTAY_ON_TOP )
a7fd7c78
VZ
97 msStyle |= MB_TOPMOST;
98
0d7ea902
VZ
99 if (hWnd)
100 msStyle |= MB_APPLMODAL;
101 else
102 msStyle |= MB_TASKMODAL;
93c95e18 103
b8505921
VZ
104 // do show the dialog
105 int msAns = MessageBox(hWnd, m_message.c_str(), m_caption.c_str(), msStyle);
106 int ans;
0d7ea902
VZ
107 switch (msAns)
108 {
b8505921
VZ
109 default:
110 wxFAIL_MSG(_T("unexpected ::MessageBox() return code"));
111 // fall through
112
0d7ea902
VZ
113 case IDCANCEL:
114 ans = wxID_CANCEL;
115 break;
116 case IDOK:
117 ans = wxID_OK;
118 break;
119 case IDYES:
120 ans = wxID_YES;
121 break;
122 case IDNO:
123 ans = wxID_NO;
124 break;
125 }
126 return ans;
2bda0e17 127}