]> git.saurik.com Git - wxWidgets.git/blame - src/common/dlgcmn.cpp
wxRTTI for wxPopupWindow in wxMGL
[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
9// Licence: wxWindows license
10/////////////////////////////////////////////////////////////////////////////
11
12// ============================================================================
13// declarations
14// ============================================================================
15
16// ----------------------------------------------------------------------------
17// headers
18// ----------------------------------------------------------------------------
19
e37feda2 20#ifdef __GNUG__
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
7d9f12f3 43
92afa2b1
RR
44//--------------------------------------------------------------------------
45// wxDialogBase
46//--------------------------------------------------------------------------
e37feda2 47
7d9f12f3
VS
48// FIXME - temporary hack in absence of wxtopLevelWindow, should be always used
49#ifdef wxTopLevelWindowNative
50BEGIN_EVENT_TABLE(wxDialogBase, wxTopLevelWindow)
51 WX_EVENT_TABLE_CONTROL_CONTAINER(wxDialogBase)
52END_EVENT_TABLE()
53
54WX_DELEGATE_TO_CONTROL_CONTAINER(wxDialogBase)
55#endif
56
57void wxDialogBase::Init()
58{
59 m_returnCode = 0;
e4b713a2
VZ
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
7d9f12f3
VS
66#ifdef wxTopLevelWindowNative // FIXME - temporary hack, should be always used!
67 m_container.SetContainerWindow(this);
68#endif
69}
70
1e6feb95
VZ
71#if wxUSE_STATTEXT && wxUSE_TEXTCTRL
72
a350a488 73wxSizer *wxDialogBase::CreateTextSizer( const wxString& message )
e37feda2 74{
92afa2b1 75 wxBoxSizer *box = new wxBoxSizer( wxVERTICAL );
b730516c 76
8a5137d7
RR
77 // get line height for empty lines
78 int y = 0;
f1df0927
VZ
79 wxFont font( GetFont() );
80 if (!font.Ok())
81 font = *wxSWISS_FONT;
82 GetTextExtent(_T("H"), (int*)NULL, &y, (int*)NULL, (int*)NULL, &font);
b730516c 83
92afa2b1 84 wxString line;
a350a488 85 for ( size_t pos = 0; pos < message.length(); pos++ )
e37feda2 86 {
a350a488 87 switch ( message[pos] )
e37feda2 88 {
a350a488
VZ
89 case _T('\n'):
90 if (!line.IsEmpty())
91 {
92 wxStaticText *s1 = new wxStaticText( this, -1, line );
93 box->Add( s1 );
94 line = wxT("");
95 }
96 else
97 {
98 box->Add( 5, y );
99 }
100 break;
101
102 case _T('&'):
103 // this is used as accel mnemonic prefix in the wxWindows
104 // controls but in the static messages created by
105 // CreateTextSizer() (used by wxMessageBox, for example), we
106 // don't want this special meaning, so we need to quote it
107 line += _T('&');
108
109 // fall through to add it normally too
110
111 default:
112 line += message[pos];
e37feda2
VZ
113 }
114 }
b730516c 115
92afa2b1
RR
116 // remaining text behind last '\n'
117 if (!line.IsEmpty())
e37feda2 118 {
92afa2b1 119 wxStaticText *s2 = new wxStaticText( this, -1, line );
f1df0927 120 box->Add( s2 );
e37feda2 121 }
b730516c 122
92afa2b1 123 return box;
e37feda2 124}
b730516c 125
1e6feb95
VZ
126#endif // wxUSE_STATTEXT && wxUSE_TEXTCTRL
127
128#if wxUSE_BUTTON
129
92afa2b1 130wxSizer *wxDialogBase::CreateButtonSizer( long flags )
e37feda2 131{
92afa2b1 132 wxBoxSizer *box = new wxBoxSizer( wxHORIZONTAL );
e37feda2 133
92afa2b1 134#if defined(__WXMSW__) || defined(__WXMAC__)
f1df0927 135 static const int margin = 6;
92afa2b1 136#else
f1df0927 137 static const int margin = 10;
92afa2b1 138#endif
e37feda2 139
92afa2b1
RR
140 wxButton *ok = (wxButton *) NULL;
141 wxButton *cancel = (wxButton *) NULL;
142 wxButton *yes = (wxButton *) NULL;
143 wxButton *no = (wxButton *) NULL;
9c884972
RR
144
145 // always show an OK button, unless only YES_NO is given
146 if ((flags & wxYES_NO) == 0) flags = flags | wxOK;
b730516c
RD
147
148 if (flags & wxYES_NO)
e37feda2 149 {
b0766406 150 yes = new wxButton( this, wxID_YES, _("Yes"),wxDefaultPosition,wxDefaultSize,wxCLIP_SIBLINGS );
92afa2b1 151 box->Add( yes, 0, wxLEFT|wxRIGHT, margin );
b0766406 152 no = new wxButton( this, wxID_NO, _("No") ,wxDefaultPosition,wxDefaultSize,wxCLIP_SIBLINGS);
92afa2b1 153 box->Add( no, 0, wxLEFT|wxRIGHT, margin );
b730516c
RD
154 } else
155 if (flags & wxYES)
92afa2b1 156 {
b0766406 157 yes = new wxButton( this, wxID_YES, _("Yes"),wxDefaultPosition,wxDefaultSize,wxCLIP_SIBLINGS );
92afa2b1 158 box->Add( yes, 0, wxLEFT|wxRIGHT, margin );
b730516c
RD
159 } else
160 if (flags & wxNO)
92afa2b1 161 {
b0766406 162 no = new wxButton( this, wxID_NO, _("No"),wxDefaultPosition,wxDefaultSize,wxCLIP_SIBLINGS );
92afa2b1 163 box->Add( no, 0, wxLEFT|wxRIGHT, margin );
e37feda2 164 }
92afa2b1 165
b730516c 166 if (flags & wxOK)
e37feda2 167 {
b0766406 168 ok = new wxButton( this, wxID_OK, _("OK"),wxDefaultPosition,wxDefaultSize,wxCLIP_SIBLINGS );
92afa2b1 169 box->Add( ok, 0, wxLEFT|wxRIGHT, margin );
e37feda2
VZ
170 }
171
b730516c 172 if (flags & wxFORWARD)
b0766406 173 box->Add( new wxButton( this, wxID_FORWARD, _("Forward"),wxDefaultPosition,wxDefaultSize,wxCLIP_SIBLINGS ), 0, wxLEFT|wxRIGHT, margin );
e37feda2 174
b730516c 175 if (flags & wxBACKWARD)
b0766406 176 box->Add( new wxButton( this, wxID_BACKWARD, _("Backward"),wxDefaultPosition,wxDefaultSize,wxCLIP_SIBLINGS ), 0, wxLEFT|wxRIGHT, margin );
e37feda2 177
b730516c 178 if (flags & wxSETUP)
b0766406 179 box->Add( new wxButton( this, wxID_SETUP, _("Setup"),wxDefaultPosition,wxDefaultSize,wxCLIP_SIBLINGS ), 0, wxLEFT|wxRIGHT, margin );
e37feda2 180
b730516c 181 if (flags & wxMORE)
b0766406 182 box->Add( new wxButton( this, wxID_MORE, _("More..."),wxDefaultPosition,wxDefaultSize,wxCLIP_SIBLINGS ), 0, wxLEFT|wxRIGHT, margin );
e37feda2 183
92afa2b1 184 if (flags & wxHELP)
b0766406 185 box->Add( new wxButton( this, wxID_HELP, _("Help"),wxDefaultPosition,wxDefaultSize,wxCLIP_SIBLINGS ), 0, wxLEFT|wxRIGHT, margin );
e37feda2 186
b730516c 187 if (flags & wxCANCEL)
e37feda2 188 {
b0766406 189 cancel = new wxButton( this, wxID_CANCEL, _("Cancel"),wxDefaultPosition,wxDefaultSize,wxCLIP_SIBLINGS );
92afa2b1 190 box->Add( cancel, 0, wxLEFT|wxRIGHT, margin );
e37feda2
VZ
191 }
192
b730516c
RD
193 if (flags & wxNO_DEFAULT)
194 {
195 if (no)
196 {
197 no->SetDefault();
198 no->SetFocus();
199 }
200 }
201 else
92afa2b1
RR
202 {
203 if (ok)
204 {
205 ok->SetDefault();
206 ok->SetFocus();
207 }
208 else if (yes)
209 {
210 yes->SetDefault();
211 yes->SetFocus();
212 }
213 }
b730516c 214
92afa2b1 215 return box;
e37feda2
VZ
216}
217
1e6feb95 218#endif // wxUSE_BUTTON