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