]> git.saurik.com Git - wxWidgets.git/blame - src/common/dlgcmn.cpp
fixes for harmless mingw32 warnings
[wxWidgets.git] / src / common / dlgcmn.cpp
CommitLineData
e37feda2
VZ
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
65571936 9// Licence: wxWindows licence
e37feda2
VZ
10/////////////////////////////////////////////////////////////////////////////
11
12// ============================================================================
13// declarations
14// ============================================================================
15
16// ----------------------------------------------------------------------------
17// headers
18// ----------------------------------------------------------------------------
19
14f355c2 20#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
1b68e0b5 21 #pragma implementation "dialogbase.h"
e37feda2
VZ
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
f6bcfd97 32 #include "wx/button.h"
e37feda2
VZ
33 #include "wx/dialog.h"
34 #include "wx/dcclient.h"
9f3a38fc 35 #include "wx/intl.h"
e37feda2 36 #include "wx/settings.h"
9f3a38fc 37 #include "wx/stattext.h"
92afa2b1 38 #include "wx/sizer.h"
f6bcfd97 39 #include "wx/button.h"
7d9f12f3 40 #include "wx/containr.h"
e37feda2
VZ
41#endif
42
92afa2b1
RR
43//--------------------------------------------------------------------------
44// wxDialogBase
45//--------------------------------------------------------------------------
e37feda2 46
7d9f12f3
VS
47// FIXME - temporary hack in absence of wxtopLevelWindow, should be always used
48#ifdef wxTopLevelWindowNative
49BEGIN_EVENT_TABLE(wxDialogBase, wxTopLevelWindow)
50 WX_EVENT_TABLE_CONTROL_CONTAINER(wxDialogBase)
51END_EVENT_TABLE()
52
53WX_DELEGATE_TO_CONTROL_CONTAINER(wxDialogBase)
54#endif
55
56void wxDialogBase::Init()
57{
58 m_returnCode = 0;
e4b713a2
VZ
59
60 // the dialogs have this flag on by default to prevent the events from the
61 // dialog controls from reaching the parent frame which is usually
62 // undesirable and can lead to unexpected and hard to find bugs
63 SetExtraStyle(GetExtraStyle() | wxWS_EX_BLOCK_EVENTS);
64
7d9f12f3
VS
65#ifdef wxTopLevelWindowNative // FIXME - temporary hack, should be always used!
66 m_container.SetContainerWindow(this);
67#endif
68}
69
d7260478 70#if wxUSE_STATTEXT // && wxUSE_TEXTCTRL
1e6feb95 71
a350a488 72wxSizer *wxDialogBase::CreateTextSizer( const wxString& message )
e37feda2 73{
2b5f62a0 74 bool is_pda = (wxSystemSettings::GetScreenType() <= wxSYS_SCREEN_PDA);
68379eaf 75
2b5f62a0 76 wxString text = message;
68379eaf 77
2b5f62a0
VZ
78 // I admit that this is complete bogus, but it makes
79 // message boxes work for pda screens temporarily..
80 int max_width = -1;
81 if (is_pda)
82 {
83 max_width = wxSystemSettings::GetMetric( wxSYS_SCREEN_X ) - 25;
84 text += wxT('\n');
85 }
68379eaf
WS
86
87
92afa2b1 88 wxBoxSizer *box = new wxBoxSizer( wxVERTICAL );
b730516c 89
8a5137d7
RR
90 // get line height for empty lines
91 int y = 0;
f1df0927
VZ
92 wxFont font( GetFont() );
93 if (!font.Ok())
94 font = *wxSWISS_FONT;
2b5f62a0 95 GetTextExtent( wxT("H"), (int*)NULL, &y, (int*)NULL, (int*)NULL, &font);
b730516c 96
2b5f62a0 97 size_t last_space = 0;
92afa2b1 98 wxString line;
2b5f62a0 99 for ( size_t pos = 0; pos < text.length(); pos++ )
e37feda2 100 {
2b5f62a0 101 switch ( text[pos] )
e37feda2 102 {
2b5f62a0 103 case wxT('\n'):
a350a488
VZ
104 if (!line.IsEmpty())
105 {
68379eaf 106 wxStaticText *s = new wxStaticText( this, wxID_ANY, line );
2b5f62a0 107 box->Add( s );
a350a488
VZ
108 line = wxT("");
109 }
110 else
111 {
112 box->Add( 5, y );
113 }
114 break;
115
2b5f62a0 116 case wxT('&'):
77ffb593 117 // this is used as accel mnemonic prefix in the wxWidgets
a350a488
VZ
118 // controls but in the static messages created by
119 // CreateTextSizer() (used by wxMessageBox, for example), we
120 // don't want this special meaning, so we need to quote it
2b5f62a0 121 line += wxT('&');
a350a488
VZ
122
123 // fall through to add it normally too
124
125 default:
2b5f62a0
VZ
126 if (text[pos] == wxT(' '))
127 last_space = pos;
68379eaf 128
a350a488 129 line += message[pos];
68379eaf 130
2b5f62a0
VZ
131 if (is_pda)
132 {
133 int width = 0;
134 GetTextExtent( line, &width, (int*)NULL, (int*)NULL, (int*)NULL, &font );
68379eaf 135
2b5f62a0
VZ
136 if (width > max_width)
137 {
138 // exception if there was no previous space
139 if (last_space == 0)
140 last_space = pos;
68379eaf 141
2b5f62a0
VZ
142 int diff = pos-last_space;
143 int len = line.Len();
144 line.Remove( len-diff, diff );
68379eaf
WS
145
146 wxStaticText *s = new wxStaticText( this, wxID_ANY, line );
2b5f62a0 147 box->Add( s );
68379eaf 148
2b5f62a0
VZ
149 pos = last_space;
150 last_space = 0;
151 line = wxT("");
152 }
153 }
e37feda2
VZ
154 }
155 }
b730516c 156
92afa2b1
RR
157 // remaining text behind last '\n'
158 if (!line.IsEmpty())
e37feda2 159 {
68379eaf 160 wxStaticText *s2 = new wxStaticText( this, wxID_ANY, line );
f1df0927 161 box->Add( s2 );
e37feda2 162 }
b730516c 163
92afa2b1 164 return box;
e37feda2 165}
b730516c 166
d7260478 167#endif // wxUSE_STATTEXT // && wxUSE_TEXTCTRL
1e6feb95
VZ
168
169#if wxUSE_BUTTON
170
92afa2b1 171wxSizer *wxDialogBase::CreateButtonSizer( long flags )
e37feda2 172{
2b5f62a0 173 bool is_pda = (wxSystemSettings::GetScreenType() <= wxSYS_SCREEN_PDA);
68379eaf
WS
174
175 // If we have a PDA screen, put yes/no button over
2b5f62a0 176 // all other buttons, otherwise on the left side.
999836aa 177 wxBoxSizer *box = is_pda ? new wxBoxSizer( wxVERTICAL ) : new wxBoxSizer( wxHORIZONTAL );
68379eaf 178
2b5f62a0 179 wxBoxSizer *inner_yes_no = NULL;
68379eaf 180
2b5f62a0
VZ
181 // Only create sizer containing yes/no
182 // if it is actually required
183 if ( (flags & wxYES_NO) != 0 )
184 {
185 inner_yes_no = new wxBoxSizer( wxHORIZONTAL );
186 box->Add( inner_yes_no, 0, wxBOTTOM, 10 );
187 }
68379eaf 188
2b5f62a0
VZ
189 wxBoxSizer *inner_rest = new wxBoxSizer( wxHORIZONTAL );
190 box->Add( inner_rest, 0, 0, 0 );
e37feda2 191
92afa2b1 192#if defined(__WXMSW__) || defined(__WXMAC__)
f1df0927 193 static const int margin = 6;
92afa2b1 194#else
f1df0927 195 static const int margin = 10;
92afa2b1 196#endif
e37feda2 197
92afa2b1 198 wxButton *ok = (wxButton *) NULL;
92afa2b1
RR
199 wxButton *yes = (wxButton *) NULL;
200 wxButton *no = (wxButton *) NULL;
9c884972 201
b5b49e42
VZ
202 // always show an OK button, unless we have both YES and NO
203 if ( (flags & wxYES_NO) != wxYES_NO )
204 flags |= wxOK;
b730516c 205
b730516c 206 if (flags & wxYES)
92afa2b1 207 {
5f7bcb48
VS
208 yes = new wxButton(this, wxID_YES, wxEmptyString,
209 wxDefaultPosition, wxDefaultSize, wxCLIP_SIBLINGS);
84fb430b 210 inner_yes_no->Add( yes, 0, wxLEFT|wxRIGHT, margin );
b5b49e42 211 }
b730516c 212 if (flags & wxNO)
92afa2b1 213 {
5f7bcb48
VS
214 no = new wxButton(this, wxID_NO, wxEmptyString,
215 wxDefaultPosition, wxDefaultSize, wxCLIP_SIBLINGS);
84fb430b 216 inner_yes_no->Add( no, 0, wxLEFT|wxRIGHT, margin );
e37feda2 217 }
92afa2b1 218
b730516c 219 if (flags & wxOK)
e37feda2 220 {
5f7bcb48
VS
221 ok = new wxButton(this, wxID_OK, wxEmptyString,
222 wxDefaultPosition, wxDefaultSize, wxCLIP_SIBLINGS);
84fb430b 223 inner_rest->Add( ok, 0, wxLEFT|wxRIGHT, margin );
e37feda2
VZ
224 }
225
b730516c 226 if (flags & wxFORWARD)
5f7bcb48
VS
227 inner_rest->Add(new wxButton(this, wxID_FORWARD, wxEmptyString,
228 wxDefaultPosition, wxDefaultSize,
c50e42a1
VS
229 wxCLIP_SIBLINGS),
230 0, wxLEFT|wxRIGHT, margin);
e37feda2 231
b730516c 232 if (flags & wxBACKWARD)
5f7bcb48
VS
233 inner_rest->Add(new wxButton(this, wxID_BACKWARD, wxEmptyString,
234 wxDefaultPosition, wxDefaultSize,
c50e42a1
VS
235 wxCLIP_SIBLINGS),
236 0, wxLEFT|wxRIGHT, margin);
e37feda2 237
b730516c 238 if (flags & wxSETUP)
84fb430b 239 inner_rest->Add( new wxButton( this, wxID_SETUP, _("Setup"),wxDefaultPosition,wxDefaultSize,wxCLIP_SIBLINGS ), 0, wxLEFT|wxRIGHT, margin );
e37feda2 240
b730516c 241 if (flags & wxMORE)
84fb430b 242 inner_rest->Add( new wxButton( this, wxID_MORE, _("More..."),wxDefaultPosition,wxDefaultSize,wxCLIP_SIBLINGS ), 0, wxLEFT|wxRIGHT, margin );
e37feda2 243
92afa2b1 244 if (flags & wxHELP)
5f7bcb48
VS
245 inner_rest->Add(new wxButton(this, wxID_HELP, wxEmptyString,
246 wxDefaultPosition, wxDefaultSize,
c50e42a1
VS
247 wxCLIP_SIBLINGS),
248 0, wxLEFT|wxRIGHT, margin);
e37feda2 249
b730516c 250 if (flags & wxCANCEL)
e37feda2 251 {
5f7bcb48
VS
252 wxButton *cancel = new wxButton(this, wxID_CANCEL, wxEmptyString,
253 wxDefaultPosition, wxDefaultSize,
c50e42a1 254 wxCLIP_SIBLINGS);
84fb430b 255 inner_rest->Add( cancel, 0, wxLEFT|wxRIGHT, margin );
e37feda2
VZ
256 }
257
b5b49e42 258 // choose the default button
b730516c
RD
259 if (flags & wxNO_DEFAULT)
260 {
261 if (no)
262 {
263 no->SetDefault();
264 no->SetFocus();
265 }
266 }
267 else
92afa2b1
RR
268 {
269 if (ok)
270 {
271 ok->SetDefault();
272 ok->SetFocus();
273 }
274 else if (yes)
275 {
276 yes->SetDefault();
277 yes->SetFocus();
278 }
279 }
b730516c 280
92afa2b1 281 return box;
e37feda2
VZ
282}
283
1e6feb95 284#endif // wxUSE_BUTTON