]> git.saurik.com Git - wxWidgets.git/blob - src/generic/msgdlgg.cpp
use WX_DEFINE_ARRAY_INT for an array of ints (bug 1536482)
[wxWidgets.git] / src / generic / msgdlgg.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/generic/msgdlgg.cpp
3 // Purpose: wxGenericMessageDialog
4 // Author: Julian Smart, Robert Roebling
5 // Modified by:
6 // Created: 04/01/98
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart and Robert Roebling
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
14
15 #ifdef __BORLANDC__
16 #pragma hdrstop
17 #endif
18
19 #if wxUSE_MSGDLG && (!defined(__WXGTK20__) || defined(__WXUNIVERSAL__) || defined(__WXGPE__))
20
21 #ifndef WX_PRECOMP
22 #include "wx/utils.h"
23 #include "wx/dialog.h"
24 #include "wx/button.h"
25 #include "wx/stattext.h"
26 #include "wx/statbmp.h"
27 #include "wx/layout.h"
28 #include "wx/intl.h"
29 #include "wx/icon.h"
30 #include "wx/sizer.h"
31 #include "wx/app.h"
32 #include "wx/settings.h"
33 #endif
34
35 #include <stdio.h>
36 #include <string.h>
37
38 #define __WX_COMPILING_MSGDLGG_CPP__ 1
39 #include "wx/msgdlg.h"
40 #include "wx/artprov.h"
41
42 #if wxUSE_STATLINE
43 #include "wx/statline.h"
44 #endif
45
46 // ----------------------------------------------------------------------------
47 // icons
48 // ----------------------------------------------------------------------------
49
50 BEGIN_EVENT_TABLE(wxGenericMessageDialog, wxDialog)
51 EVT_BUTTON(wxID_YES, wxGenericMessageDialog::OnYes)
52 EVT_BUTTON(wxID_NO, wxGenericMessageDialog::OnNo)
53 EVT_BUTTON(wxID_CANCEL, wxGenericMessageDialog::OnCancel)
54 END_EVENT_TABLE()
55
56 IMPLEMENT_CLASS(wxGenericMessageDialog, wxDialog)
57
58 wxGenericMessageDialog::wxGenericMessageDialog( wxWindow *parent,
59 const wxString& message,
60 const wxString& caption,
61 long style,
62 const wxPoint& pos)
63 : wxDialog( parent, wxID_ANY, caption, pos, wxDefaultSize, wxDEFAULT_DIALOG_STYLE )
64 {
65 SetMessageDialogStyle(style);
66
67 bool is_pda = (wxSystemSettings::GetScreenType() <= wxSYS_SCREEN_PDA);
68
69 wxBoxSizer *topsizer = new wxBoxSizer( wxVERTICAL );
70
71 wxBoxSizer *icon_text = new wxBoxSizer( wxHORIZONTAL );
72
73 #if wxUSE_STATBMP
74 // 1) icon
75 if (style & wxICON_MASK)
76 {
77 wxBitmap bitmap;
78 switch ( style & wxICON_MASK )
79 {
80 default:
81 wxFAIL_MSG(_T("incorrect log style"));
82 // fall through
83
84 case wxICON_ERROR:
85 bitmap = wxArtProvider::GetIcon(wxART_ERROR, wxART_MESSAGE_BOX);
86 break;
87
88 case wxICON_INFORMATION:
89 bitmap = wxArtProvider::GetIcon(wxART_INFORMATION, wxART_MESSAGE_BOX);
90 break;
91
92 case wxICON_WARNING:
93 bitmap = wxArtProvider::GetIcon(wxART_WARNING, wxART_MESSAGE_BOX);
94 break;
95
96 case wxICON_QUESTION:
97 bitmap = wxArtProvider::GetIcon(wxART_QUESTION, wxART_MESSAGE_BOX);
98 break;
99 }
100 wxStaticBitmap *icon = new wxStaticBitmap(this, wxID_ANY, bitmap);
101 if (is_pda)
102 topsizer->Add( icon, 0, wxTOP|wxLEFT|wxRIGHT | wxALIGN_LEFT, 10 );
103 else
104 icon_text->Add( icon, 0, wxCENTER );
105 }
106 #endif // wxUSE_STATBMP
107
108 #if wxUSE_STATTEXT
109 // 2) text
110 icon_text->Add( CreateTextSizer( message ), 0, wxALIGN_CENTER | wxLEFT, 10 );
111
112 topsizer->Add( icon_text, 1, wxCENTER | wxLEFT|wxRIGHT|wxTOP, 10 );
113 #endif // wxUSE_STATTEXT
114
115 // 3) buttons
116 int center_flag = wxEXPAND;
117 if (style & wxYES_NO)
118 center_flag = wxALIGN_CENTRE;
119 wxSizer *sizerBtn = CreateSeparatedButtonSizer(style & ButtonSizerFlags);
120 if ( sizerBtn )
121 topsizer->Add(sizerBtn, 0, center_flag | wxALL, 10 );
122
123 SetAutoLayout( true );
124 SetSizer( topsizer );
125
126 topsizer->SetSizeHints( this );
127 topsizer->Fit( this );
128 wxSize size( GetSize() );
129 if (size.x < size.y*3/2)
130 {
131 size.x = size.y*3/2;
132 SetSize( size );
133 }
134
135 Centre( wxBOTH | wxCENTER_FRAME);
136 }
137
138 void wxGenericMessageDialog::OnYes(wxCommandEvent& WXUNUSED(event))
139 {
140 EndModal( wxID_YES );
141 }
142
143 void wxGenericMessageDialog::OnNo(wxCommandEvent& WXUNUSED(event))
144 {
145 EndModal( wxID_NO );
146 }
147
148 void wxGenericMessageDialog::OnCancel(wxCommandEvent& WXUNUSED(event))
149 {
150 // Allow cancellation via ESC/Close button except if
151 // only YES and NO are specified.
152 const long style = GetMessageDialogStyle();
153 if ( (style & wxYES_NO) != wxYES_NO || (style & wxCANCEL) )
154 {
155 EndModal( wxID_CANCEL );
156 }
157 }
158
159 #endif // wxUSE_MSGDLG && !defined(__WXGTK20__)