]> git.saurik.com Git - wxWidgets.git/blob - src/common/dlgcmn.cpp
reverted the fix for Unicode compilation with VC++ as it breaks other ports (and...
[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 license
10 /////////////////////////////////////////////////////////////////////////////
11
12 // ============================================================================
13 // declarations
14 // ============================================================================
15
16 // ----------------------------------------------------------------------------
17 // headers
18 // ----------------------------------------------------------------------------
19
20 #ifdef __GNUG__
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 //--------------------------------------------------------------------------
45 // wxDialogBase
46 //--------------------------------------------------------------------------
47
48 // FIXME - temporary hack in absence of wxtopLevelWindow, should be always used
49 #ifdef wxTopLevelWindowNative
50 BEGIN_EVENT_TABLE(wxDialogBase, wxTopLevelWindow)
51 WX_EVENT_TABLE_CONTROL_CONTAINER(wxDialogBase)
52 END_EVENT_TABLE()
53
54 WX_DELEGATE_TO_CONTROL_CONTAINER(wxDialogBase)
55 #endif
56
57 void wxDialogBase::Init()
58 {
59 m_returnCode = 0;
60 #ifdef wxTopLevelWindowNative // FIXME - temporary hack, should be always used!
61 m_container.SetContainerWindow(this);
62 #endif
63 }
64
65 #if wxUSE_STATTEXT && wxUSE_TEXTCTRL
66
67 wxSizer *wxDialogBase::CreateTextSizer( const wxString &message )
68 {
69 wxBoxSizer *box = new wxBoxSizer( wxVERTICAL );
70
71 // get line height for empty lines
72 int y = 0;
73 wxFont font( GetFont() );
74 if (!font.Ok())
75 font = *wxSWISS_FONT;
76 GetTextExtent(_T("H"), (int*)NULL, &y, (int*)NULL, (int*)NULL, &font);
77
78 wxString line;
79 for (size_t pos = 0; pos < message.Len(); pos++)
80 {
81 if (message[pos] == wxT('\n'))
82 {
83 if (!line.IsEmpty())
84 {
85 wxStaticText *s1 = new wxStaticText( this, -1, line );
86 box->Add( s1 );
87 line = wxT("");
88 }
89 else
90 {
91 box->Add( 5, y );
92 }
93 }
94 else
95 {
96 line += message[pos];
97 }
98 }
99
100 // remaining text behind last '\n'
101 if (!line.IsEmpty())
102 {
103 wxStaticText *s2 = new wxStaticText( this, -1, line );
104 box->Add( s2 );
105 }
106
107 return box;
108 }
109
110 #endif // wxUSE_STATTEXT && wxUSE_TEXTCTRL
111
112 #if wxUSE_BUTTON
113
114 wxSizer *wxDialogBase::CreateButtonSizer( long flags )
115 {
116 wxBoxSizer *box = new wxBoxSizer( wxHORIZONTAL );
117
118 #if defined(__WXMSW__) || defined(__WXMAC__)
119 static const int margin = 6;
120 #else
121 static const int margin = 10;
122 #endif
123
124 wxButton *ok = (wxButton *) NULL;
125 wxButton *cancel = (wxButton *) NULL;
126 wxButton *yes = (wxButton *) NULL;
127 wxButton *no = (wxButton *) NULL;
128
129 // always show an OK button, unless only YES_NO is given
130 if ((flags & wxYES_NO) == 0) flags = flags | wxOK;
131
132 if (flags & wxYES_NO)
133 {
134 yes = new wxButton( this, wxID_YES, _("Yes"),wxDefaultPosition,wxDefaultSize,wxCLIP_SIBLINGS );
135 box->Add( yes, 0, wxLEFT|wxRIGHT, margin );
136 no = new wxButton( this, wxID_NO, _("No") ,wxDefaultPosition,wxDefaultSize,wxCLIP_SIBLINGS);
137 box->Add( no, 0, wxLEFT|wxRIGHT, margin );
138 } else
139 if (flags & wxYES)
140 {
141 yes = new wxButton( this, wxID_YES, _("Yes"),wxDefaultPosition,wxDefaultSize,wxCLIP_SIBLINGS );
142 box->Add( yes, 0, wxLEFT|wxRIGHT, margin );
143 } else
144 if (flags & wxNO)
145 {
146 no = new wxButton( this, wxID_NO, _("No"),wxDefaultPosition,wxDefaultSize,wxCLIP_SIBLINGS );
147 box->Add( no, 0, wxLEFT|wxRIGHT, margin );
148 }
149
150 if (flags & wxOK)
151 {
152 ok = new wxButton( this, wxID_OK, _("OK"),wxDefaultPosition,wxDefaultSize,wxCLIP_SIBLINGS );
153 box->Add( ok, 0, wxLEFT|wxRIGHT, margin );
154 }
155
156 if (flags & wxFORWARD)
157 box->Add( new wxButton( this, wxID_FORWARD, _("Forward"),wxDefaultPosition,wxDefaultSize,wxCLIP_SIBLINGS ), 0, wxLEFT|wxRIGHT, margin );
158
159 if (flags & wxBACKWARD)
160 box->Add( new wxButton( this, wxID_BACKWARD, _("Backward"),wxDefaultPosition,wxDefaultSize,wxCLIP_SIBLINGS ), 0, wxLEFT|wxRIGHT, margin );
161
162 if (flags & wxSETUP)
163 box->Add( new wxButton( this, wxID_SETUP, _("Setup"),wxDefaultPosition,wxDefaultSize,wxCLIP_SIBLINGS ), 0, wxLEFT|wxRIGHT, margin );
164
165 if (flags & wxMORE)
166 box->Add( new wxButton( this, wxID_MORE, _("More..."),wxDefaultPosition,wxDefaultSize,wxCLIP_SIBLINGS ), 0, wxLEFT|wxRIGHT, margin );
167
168 if (flags & wxHELP)
169 box->Add( new wxButton( this, wxID_HELP, _("Help"),wxDefaultPosition,wxDefaultSize,wxCLIP_SIBLINGS ), 0, wxLEFT|wxRIGHT, margin );
170
171 if (flags & wxCANCEL)
172 {
173 cancel = new wxButton( this, wxID_CANCEL, _("Cancel"),wxDefaultPosition,wxDefaultSize,wxCLIP_SIBLINGS );
174 box->Add( cancel, 0, wxLEFT|wxRIGHT, margin );
175 }
176
177 if (flags & wxNO_DEFAULT)
178 {
179 if (no)
180 {
181 no->SetDefault();
182 no->SetFocus();
183 }
184 }
185 else
186 {
187 if (ok)
188 {
189 ok->SetDefault();
190 ok->SetFocus();
191 }
192 else if (yes)
193 {
194 yes->SetDefault();
195 yes->SetFocus();
196 }
197 }
198
199 return box;
200 }
201
202 #endif // wxUSE_BUTTON