]>
Commit | Line | Data |
---|---|---|
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 | |
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; | |
9ceeecb9 JS |
59 | m_affirmativeId = wxID_OK; |
60 | ||
e4b713a2 VZ |
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 | ||
7d9f12f3 VS |
66 | #ifdef wxTopLevelWindowNative // FIXME - temporary hack, should be always used! |
67 | m_container.SetContainerWindow(this); | |
68 | #endif | |
69 | } | |
70 | ||
d7260478 | 71 | #if wxUSE_STATTEXT // && wxUSE_TEXTCTRL |
1e6feb95 | 72 | |
a350a488 | 73 | wxSizer *wxDialogBase::CreateTextSizer( const wxString& message ) |
e37feda2 | 74 | { |
2b5f62a0 | 75 | bool is_pda = (wxSystemSettings::GetScreenType() <= wxSYS_SCREEN_PDA); |
68379eaf | 76 | |
2b5f62a0 | 77 | wxString text = message; |
68379eaf | 78 | |
2b5f62a0 VZ |
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 | } | |
68379eaf WS |
87 | |
88 | ||
92afa2b1 | 89 | wxBoxSizer *box = new wxBoxSizer( wxVERTICAL ); |
b730516c | 90 | |
8a5137d7 RR |
91 | // get line height for empty lines |
92 | int y = 0; | |
f1df0927 VZ |
93 | wxFont font( GetFont() ); |
94 | if (!font.Ok()) | |
95 | font = *wxSWISS_FONT; | |
2b5f62a0 | 96 | GetTextExtent( wxT("H"), (int*)NULL, &y, (int*)NULL, (int*)NULL, &font); |
b730516c | 97 | |
2b5f62a0 | 98 | size_t last_space = 0; |
92afa2b1 | 99 | wxString line; |
2b5f62a0 | 100 | for ( size_t pos = 0; pos < text.length(); pos++ ) |
e37feda2 | 101 | { |
2b5f62a0 | 102 | switch ( text[pos] ) |
e37feda2 | 103 | { |
2b5f62a0 | 104 | case wxT('\n'): |
52069700 | 105 | if (!line.empty()) |
a350a488 | 106 | { |
68379eaf | 107 | wxStaticText *s = new wxStaticText( this, wxID_ANY, line ); |
2b5f62a0 | 108 | box->Add( s ); |
b494c48b | 109 | line = wxEmptyString; |
a350a488 VZ |
110 | } |
111 | else | |
112 | { | |
113 | box->Add( 5, y ); | |
114 | } | |
115 | break; | |
116 | ||
2b5f62a0 | 117 | case wxT('&'): |
77ffb593 | 118 | // this is used as accel mnemonic prefix in the wxWidgets |
a350a488 VZ |
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 | |
2b5f62a0 | 122 | line += wxT('&'); |
a350a488 VZ |
123 | |
124 | // fall through to add it normally too | |
125 | ||
126 | default: | |
2b5f62a0 VZ |
127 | if (text[pos] == wxT(' ')) |
128 | last_space = pos; | |
68379eaf | 129 | |
a350a488 | 130 | line += message[pos]; |
68379eaf | 131 | |
2b5f62a0 VZ |
132 | if (is_pda) |
133 | { | |
134 | int width = 0; | |
135 | GetTextExtent( line, &width, (int*)NULL, (int*)NULL, (int*)NULL, &font ); | |
68379eaf | 136 | |
2b5f62a0 VZ |
137 | if (width > max_width) |
138 | { | |
139 | // exception if there was no previous space | |
140 | if (last_space == 0) | |
141 | last_space = pos; | |
68379eaf | 142 | |
2b5f62a0 VZ |
143 | int diff = pos-last_space; |
144 | int len = line.Len(); | |
145 | line.Remove( len-diff, diff ); | |
68379eaf WS |
146 | |
147 | wxStaticText *s = new wxStaticText( this, wxID_ANY, line ); | |
2b5f62a0 | 148 | box->Add( s ); |
68379eaf | 149 | |
2b5f62a0 VZ |
150 | pos = last_space; |
151 | last_space = 0; | |
b494c48b | 152 | line = wxEmptyString; |
2b5f62a0 VZ |
153 | } |
154 | } | |
e37feda2 VZ |
155 | } |
156 | } | |
b730516c | 157 | |
92afa2b1 | 158 | // remaining text behind last '\n' |
52069700 | 159 | if (!line.empty()) |
e37feda2 | 160 | { |
68379eaf | 161 | wxStaticText *s2 = new wxStaticText( this, wxID_ANY, line ); |
f1df0927 | 162 | box->Add( s2 ); |
e37feda2 | 163 | } |
b730516c | 164 | |
92afa2b1 | 165 | return box; |
e37feda2 | 166 | } |
b730516c | 167 | |
d7260478 | 168 | #endif // wxUSE_STATTEXT // && wxUSE_TEXTCTRL |
1e6feb95 VZ |
169 | |
170 | #if wxUSE_BUTTON | |
171 | ||
92afa2b1 | 172 | wxSizer *wxDialogBase::CreateButtonSizer( long flags ) |
e37feda2 | 173 | { |
acf2ac37 RR |
174 | return CreateStdDialogButtonSizer( flags ); |
175 | } | |
68379eaf | 176 | |
acf2ac37 RR |
177 | wxStdDialogButtonSizer *wxDialogBase::CreateStdDialogButtonSizer( long flags ) |
178 | { | |
179 | wxStdDialogButtonSizer *sizer = new wxStdDialogButtonSizer(); | |
180 | wxButton *ok = NULL; | |
acf2ac37 RR |
181 | wxButton *yes = NULL; |
182 | wxButton *no = NULL; | |
52069700 | 183 | |
acf2ac37 | 184 | if (flags & wxOK){ |
331c1816 | 185 | ok = new wxButton(this, wxID_OK); |
52069700 | 186 | sizer->AddButton(ok); |
2b5f62a0 | 187 | } |
52069700 | 188 | |
acf2ac37 | 189 | if (flags & wxCANCEL){ |
331c1816 | 190 | wxButton *cancel = new wxButton(this, wxID_CANCEL); |
52069700 | 191 | sizer->AddButton(cancel); |
b5b49e42 | 192 | } |
52069700 | 193 | |
acf2ac37 | 194 | if (flags & wxYES){ |
331c1816 | 195 | yes = new wxButton(this, wxID_YES); |
52069700 | 196 | sizer->AddButton(yes); |
e37feda2 | 197 | } |
52069700 | 198 | |
acf2ac37 | 199 | if (flags & wxNO){ |
331c1816 | 200 | no = new wxButton(this, wxID_NO); |
52069700 | 201 | sizer->AddButton(no); |
e37feda2 | 202 | } |
52069700 | 203 | |
acf2ac37 | 204 | if (flags & wxHELP){ |
331c1816 | 205 | wxButton *help = new wxButton(this, wxID_HELP); |
52069700 | 206 | sizer->AddButton(help); |
e37feda2 | 207 | } |
52069700 | 208 | |
718903fe | 209 | sizer->Realize(); |
52069700 | 210 | |
b730516c RD |
211 | if (flags & wxNO_DEFAULT) |
212 | { | |
213 | if (no) | |
214 | { | |
215 | no->SetDefault(); | |
216 | no->SetFocus(); | |
217 | } | |
218 | } | |
219 | else | |
92afa2b1 RR |
220 | { |
221 | if (ok) | |
222 | { | |
223 | ok->SetDefault(); | |
224 | ok->SetFocus(); | |
225 | } | |
226 | else if (yes) | |
227 | { | |
228 | yes->SetDefault(); | |
229 | yes->SetFocus(); | |
230 | } | |
231 | } | |
9ceeecb9 JS |
232 | |
233 | if (flags & wxOK) | |
234 | SetAffirmativeId(wxID_OK); | |
235 | else if (flags & wxYES) | |
236 | SetAffirmativeId(wxID_YES); | |
b730516c | 237 | |
acf2ac37 | 238 | return sizer; |
e37feda2 VZ |
239 | } |
240 | ||
acf2ac37 | 241 | |
1e6feb95 | 242 | #endif // wxUSE_BUTTON |