]> git.saurik.com Git - wxWidgets.git/blob - src/common/dlgcmn.cpp
minor clean up
[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 #endif
41
42 //--------------------------------------------------------------------------
43 // wxDialogBase
44 //--------------------------------------------------------------------------
45
46 #if wxUSE_STATTEXT && wxUSE_TEXTCTRL
47
48 wxSizer *wxDialogBase::CreateTextSizer( const wxString &message )
49 {
50 wxBoxSizer *box = new wxBoxSizer( wxVERTICAL );
51
52 // get line height for empty lines
53 int y = 0;
54 wxFont font( GetFont() );
55 if (!font.Ok())
56 font = *wxSWISS_FONT;
57 GetTextExtent(_T("H"), (int*)NULL, &y, (int*)NULL, (int*)NULL, &font);
58
59 wxString line;
60 for (size_t pos = 0; pos < message.Len(); pos++)
61 {
62 if (message[pos] == wxT('\n'))
63 {
64 if (!line.IsEmpty())
65 {
66 wxStaticText *s1 = new wxStaticText( this, -1, line );
67 box->Add( s1 );
68 line = wxT("");
69 }
70 else
71 {
72 box->Add( 5, y );
73 }
74 }
75 else
76 {
77 line += message[pos];
78 }
79 }
80
81 // remaining text behind last '\n'
82 if (!line.IsEmpty())
83 {
84 wxStaticText *s2 = new wxStaticText( this, -1, line );
85 box->Add( s2 );
86 }
87
88 return box;
89 }
90
91 #endif // wxUSE_STATTEXT && wxUSE_TEXTCTRL
92
93 #if wxUSE_BUTTON
94
95 wxSizer *wxDialogBase::CreateButtonSizer( long flags )
96 {
97 wxBoxSizer *box = new wxBoxSizer( wxHORIZONTAL );
98
99 #if defined(__WXMSW__) || defined(__WXMAC__)
100 static const int margin = 6;
101 #else
102 static const int margin = 10;
103 #endif
104
105 wxButton *ok = (wxButton *) NULL;
106 wxButton *cancel = (wxButton *) NULL;
107 wxButton *yes = (wxButton *) NULL;
108 wxButton *no = (wxButton *) NULL;
109
110 // always show an OK button, unless only YES_NO is given
111 if ((flags & wxYES_NO) == 0) flags = flags | wxOK;
112
113 if (flags & wxYES_NO)
114 {
115 yes = new wxButton( this, wxID_YES, _("Yes"),wxDefaultPosition,wxDefaultSize,wxCLIP_SIBLINGS );
116 box->Add( yes, 0, wxLEFT|wxRIGHT, margin );
117 no = new wxButton( this, wxID_NO, _("No") ,wxDefaultPosition,wxDefaultSize,wxCLIP_SIBLINGS);
118 box->Add( no, 0, wxLEFT|wxRIGHT, margin );
119 } else
120 if (flags & wxYES)
121 {
122 yes = new wxButton( this, wxID_YES, _("Yes"),wxDefaultPosition,wxDefaultSize,wxCLIP_SIBLINGS );
123 box->Add( yes, 0, wxLEFT|wxRIGHT, margin );
124 } else
125 if (flags & wxNO)
126 {
127 no = new wxButton( this, wxID_NO, _("No"),wxDefaultPosition,wxDefaultSize,wxCLIP_SIBLINGS );
128 box->Add( no, 0, wxLEFT|wxRIGHT, margin );
129 }
130
131 if (flags & wxOK)
132 {
133 ok = new wxButton( this, wxID_OK, _("OK"),wxDefaultPosition,wxDefaultSize,wxCLIP_SIBLINGS );
134 box->Add( ok, 0, wxLEFT|wxRIGHT, margin );
135 }
136
137 if (flags & wxFORWARD)
138 box->Add( new wxButton( this, wxID_FORWARD, _("Forward"),wxDefaultPosition,wxDefaultSize,wxCLIP_SIBLINGS ), 0, wxLEFT|wxRIGHT, margin );
139
140 if (flags & wxBACKWARD)
141 box->Add( new wxButton( this, wxID_BACKWARD, _("Backward"),wxDefaultPosition,wxDefaultSize,wxCLIP_SIBLINGS ), 0, wxLEFT|wxRIGHT, margin );
142
143 if (flags & wxSETUP)
144 box->Add( new wxButton( this, wxID_SETUP, _("Setup"),wxDefaultPosition,wxDefaultSize,wxCLIP_SIBLINGS ), 0, wxLEFT|wxRIGHT, margin );
145
146 if (flags & wxMORE)
147 box->Add( new wxButton( this, wxID_MORE, _("More..."),wxDefaultPosition,wxDefaultSize,wxCLIP_SIBLINGS ), 0, wxLEFT|wxRIGHT, margin );
148
149 if (flags & wxHELP)
150 box->Add( new wxButton( this, wxID_HELP, _("Help"),wxDefaultPosition,wxDefaultSize,wxCLIP_SIBLINGS ), 0, wxLEFT|wxRIGHT, margin );
151
152 if (flags & wxCANCEL)
153 {
154 cancel = new wxButton( this, wxID_CANCEL, _("Cancel"),wxDefaultPosition,wxDefaultSize,wxCLIP_SIBLINGS );
155 box->Add( cancel, 0, wxLEFT|wxRIGHT, margin );
156 }
157
158 if (flags & wxNO_DEFAULT)
159 {
160 if (no)
161 {
162 no->SetDefault();
163 no->SetFocus();
164 }
165 }
166 else
167 {
168 if (ok)
169 {
170 ok->SetDefault();
171 ok->SetFocus();
172 }
173 else if (yes)
174 {
175 yes->SetDefault();
176 yes->SetFocus();
177 }
178 }
179
180 return box;
181 }
182
183 #endif // wxUSE_BUTTON