]> git.saurik.com Git - wxWidgets.git/blob - src/common/dlgcmn.cpp
Initialize m_privData before doign the assignment
[wxWidgets.git] / src / common / dlgcmn.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: common/dlgcmn.cpp
3 // Purpose: common (to all ports) wxDialog functions
4 // Author: Vadim Zeitlin
5 // Modified by:
6 // Created: 28.06.99
7 // RCS-ID: $Id$
8 // Copyright: (c) Vadim Zeitlin
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 // ============================================================================
13 // declarations
14 // ============================================================================
15
16 // ----------------------------------------------------------------------------
17 // headers
18 // ----------------------------------------------------------------------------
19
20 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
21 #pragma implementation "dialogbase.h"
22 #endif
23
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
26
27 #ifdef __BORLANDC__
28 #pragma hdrstop
29 #endif
30
31 #ifndef WX_PRECOMP
32 #include "wx/button.h"
33 #include "wx/dialog.h"
34 #include "wx/dcclient.h"
35 #include "wx/intl.h"
36 #include "wx/settings.h"
37 #include "wx/stattext.h"
38 #include "wx/sizer.h"
39 #include "wx/button.h"
40 #include "wx/containr.h"
41 #endif
42
43 //--------------------------------------------------------------------------
44 // wxDialogBase
45 //--------------------------------------------------------------------------
46
47 // FIXME - temporary hack in absence of wxtopLevelWindow, should be always used
48 #ifdef wxTopLevelWindowNative
49 BEGIN_EVENT_TABLE(wxDialogBase, wxTopLevelWindow)
50 WX_EVENT_TABLE_CONTROL_CONTAINER(wxDialogBase)
51 END_EVENT_TABLE()
52
53 WX_DELEGATE_TO_CONTROL_CONTAINER(wxDialogBase)
54 #endif
55
56 void wxDialogBase::Init()
57 {
58 m_returnCode = 0;
59 m_affirmativeId = wxID_OK;
60
61 // the dialogs have this flag on by default to prevent the events from the
62 // dialog controls from reaching the parent frame which is usually
63 // undesirable and can lead to unexpected and hard to find bugs
64 SetExtraStyle(GetExtraStyle() | wxWS_EX_BLOCK_EVENTS);
65
66 #ifdef wxTopLevelWindowNative // FIXME - temporary hack, should be always used!
67 m_container.SetContainerWindow(this);
68 #endif
69 }
70
71 #if wxUSE_STATTEXT // && wxUSE_TEXTCTRL
72
73 wxSizer *wxDialogBase::CreateTextSizer( const wxString& message )
74 {
75 bool is_pda = (wxSystemSettings::GetScreenType() <= wxSYS_SCREEN_PDA);
76
77 wxString text = message;
78
79 // I admit that this is complete bogus, but it makes
80 // message boxes work for pda screens temporarily..
81 int max_width = -1;
82 if (is_pda)
83 {
84 max_width = wxSystemSettings::GetMetric( wxSYS_SCREEN_X ) - 25;
85 text += wxT('\n');
86 }
87
88
89 wxBoxSizer *box = new wxBoxSizer( wxVERTICAL );
90
91 // get line height for empty lines
92 int y = 0;
93 wxFont font( GetFont() );
94 if (!font.Ok())
95 font = *wxSWISS_FONT;
96 GetTextExtent( wxT("H"), (int*)NULL, &y, (int*)NULL, (int*)NULL, &font);
97
98 size_t last_space = 0;
99 wxString line;
100 for ( size_t pos = 0; pos < text.length(); pos++ )
101 {
102 switch ( text[pos] )
103 {
104 case wxT('\n'):
105 if (!line.empty())
106 {
107 wxStaticText *s = new wxStaticText( this, wxID_ANY, line );
108 box->Add( s );
109 line = wxEmptyString;
110 }
111 else
112 {
113 box->Add( 5, y );
114 }
115 break;
116
117 case wxT('&'):
118 // this is used as accel mnemonic prefix in the wxWidgets
119 // controls but in the static messages created by
120 // CreateTextSizer() (used by wxMessageBox, for example), we
121 // don't want this special meaning, so we need to quote it
122 line += wxT('&');
123
124 // fall through to add it normally too
125
126 default:
127 if (text[pos] == wxT(' '))
128 last_space = pos;
129
130 line += message[pos];
131
132 if (is_pda)
133 {
134 int width = 0;
135 GetTextExtent( line, &width, (int*)NULL, (int*)NULL, (int*)NULL, &font );
136
137 if (width > max_width)
138 {
139 // exception if there was no previous space
140 if (last_space == 0)
141 last_space = pos;
142
143 int diff = pos-last_space;
144 int len = line.Len();
145 line.Remove( len-diff, diff );
146
147 wxStaticText *s = new wxStaticText( this, wxID_ANY, line );
148 box->Add( s );
149
150 pos = last_space;
151 last_space = 0;
152 line = wxEmptyString;
153 }
154 }
155 }
156 }
157
158 // remaining text behind last '\n'
159 if (!line.empty())
160 {
161 wxStaticText *s2 = new wxStaticText( this, wxID_ANY, line );
162 box->Add( s2 );
163 }
164
165 return box;
166 }
167
168 #endif // wxUSE_STATTEXT // && wxUSE_TEXTCTRL
169
170 #if wxUSE_BUTTON
171
172 wxSizer *wxDialogBase::CreateButtonSizer( long flags )
173 {
174 #ifdef __SMARTPHONE__
175 wxDialog* dialog = (wxDialog*) this;
176 if (flags & wxOK){
177 dialog->SetLeftMenu(wxID_OK);
178 }
179
180 if (flags & wxCANCEL){
181 dialog->SetRightMenu(wxID_CANCEL);
182 }
183
184 if (flags & wxYES){
185 dialog->SetLeftMenu(wxID_YES);
186 }
187
188 if (flags & wxNO){
189 dialog->SetLeftMenu(wxID_NO);
190 }
191 wxBoxSizer* sizer = new wxBoxSizer(wxHORIZONTAL);
192 return sizer;
193 #else
194 return CreateStdDialogButtonSizer( flags );
195 #endif
196 }
197
198 wxStdDialogButtonSizer *wxDialogBase::CreateStdDialogButtonSizer( long flags )
199 {
200 wxStdDialogButtonSizer *sizer = new wxStdDialogButtonSizer();
201 wxButton *ok = NULL;
202 wxButton *yes = NULL;
203 wxButton *no = NULL;
204
205 if (flags & wxOK){
206 ok = new wxButton(this, wxID_OK);
207 sizer->AddButton(ok);
208 }
209
210 if (flags & wxCANCEL){
211 wxButton *cancel = new wxButton(this, wxID_CANCEL);
212 sizer->AddButton(cancel);
213 }
214
215 if (flags & wxYES){
216 yes = new wxButton(this, wxID_YES);
217 sizer->AddButton(yes);
218 }
219
220 if (flags & wxNO){
221 no = new wxButton(this, wxID_NO);
222 sizer->AddButton(no);
223 }
224
225 if (flags & wxHELP){
226 wxButton *help = new wxButton(this, wxID_HELP);
227 sizer->AddButton(help);
228 }
229
230 sizer->Realize();
231
232 if (flags & wxNO_DEFAULT)
233 {
234 if (no)
235 {
236 no->SetDefault();
237 no->SetFocus();
238 }
239 }
240 else
241 {
242 if (ok)
243 {
244 ok->SetDefault();
245 ok->SetFocus();
246 }
247 else if (yes)
248 {
249 yes->SetDefault();
250 yes->SetFocus();
251 }
252 }
253
254 if (flags & wxOK)
255 SetAffirmativeId(wxID_OK);
256 else if (flags & wxYES)
257 SetAffirmativeId(wxID_YES);
258
259 return sizer;
260 }
261
262
263 #endif // wxUSE_BUTTON