]> git.saurik.com Git - wxWidgets.git/blame - src/common/dlgcmn.cpp
implemented GetProgramHandle() for Win32 and documented it
[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;
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 73wxSizer *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 172wxSizer *wxDialogBase::CreateButtonSizer( long flags )
e37feda2 173{
102c0454
JS
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
acf2ac37 194 return CreateStdDialogButtonSizer( flags );
102c0454 195#endif
acf2ac37 196}
68379eaf 197
acf2ac37
RR
198wxStdDialogButtonSizer *wxDialogBase::CreateStdDialogButtonSizer( long flags )
199{
200 wxStdDialogButtonSizer *sizer = new wxStdDialogButtonSizer();
201 wxButton *ok = NULL;
acf2ac37
RR
202 wxButton *yes = NULL;
203 wxButton *no = NULL;
52069700 204
acf2ac37 205 if (flags & wxOK){
331c1816 206 ok = new wxButton(this, wxID_OK);
52069700 207 sizer->AddButton(ok);
2b5f62a0 208 }
52069700 209
acf2ac37 210 if (flags & wxCANCEL){
331c1816 211 wxButton *cancel = new wxButton(this, wxID_CANCEL);
52069700 212 sizer->AddButton(cancel);
b5b49e42 213 }
52069700 214
acf2ac37 215 if (flags & wxYES){
331c1816 216 yes = new wxButton(this, wxID_YES);
52069700 217 sizer->AddButton(yes);
e37feda2 218 }
52069700 219
acf2ac37 220 if (flags & wxNO){
331c1816 221 no = new wxButton(this, wxID_NO);
52069700 222 sizer->AddButton(no);
e37feda2 223 }
52069700 224
acf2ac37 225 if (flags & wxHELP){
331c1816 226 wxButton *help = new wxButton(this, wxID_HELP);
52069700 227 sizer->AddButton(help);
e37feda2 228 }
52069700 229
718903fe 230 sizer->Realize();
52069700 231
b730516c
RD
232 if (flags & wxNO_DEFAULT)
233 {
234 if (no)
235 {
236 no->SetDefault();
237 no->SetFocus();
238 }
239 }
240 else
92afa2b1
RR
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 }
9ceeecb9
JS
253
254 if (flags & wxOK)
255 SetAffirmativeId(wxID_OK);
256 else if (flags & wxYES)
257 SetAffirmativeId(wxID_YES);
b730516c 258
acf2ac37 259 return sizer;
e37feda2
VZ
260}
261
acf2ac37 262
1e6feb95 263#endif // wxUSE_BUTTON