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