]>
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 | ||
20 | #if 0 | |
21 | #ifdef __GNUG__ | |
22 | #pragma implementation | |
23 | #endif | |
24 | #endif | |
25 | ||
26 | // For compilers that support precompilation, includes "wx.h". | |
27 | #include "wx/wxprec.h" | |
28 | ||
29 | #ifdef __BORLANDC__ | |
30 | #pragma hdrstop | |
31 | #endif | |
32 | ||
33 | #ifndef WX_PRECOMP | |
34 | #include "wx/dialog.h" | |
35 | #include "wx/dcclient.h" | |
9f3a38fc | 36 | #include "wx/intl.h" |
e37feda2 | 37 | #include "wx/settings.h" |
9f3a38fc | 38 | #include "wx/stattext.h" |
92afa2b1 | 39 | #include "wx/sizer.h" |
e37feda2 VZ |
40 | #endif |
41 | ||
92afa2b1 RR |
42 | //-------------------------------------------------------------------------- |
43 | // wxDialogBase | |
44 | //-------------------------------------------------------------------------- | |
e37feda2 | 45 | |
92afa2b1 | 46 | wxSizer *wxDialogBase::CreateTextSizer( const wxString &message ) |
e37feda2 | 47 | { |
92afa2b1 | 48 | wxBoxSizer *box = new wxBoxSizer( wxVERTICAL ); |
b730516c | 49 | |
8a5137d7 RR |
50 | // get line height for empty lines |
51 | int y = 0; | |
52 | wxFont new_font( GetFont() ); | |
53 | if (!new_font.Ok()) new_font = *wxSWISS_FONT; | |
54 | GetTextExtent( "H", (int*)NULL, &y, (int*)NULL, (int*)NULL, &new_font ); | |
b730516c | 55 | |
92afa2b1 RR |
56 | wxString line; |
57 | for (size_t pos = 0; pos < message.Len(); pos++) | |
e37feda2 | 58 | { |
92afa2b1 | 59 | if (message[pos] == _T('\n')) |
e37feda2 | 60 | { |
92afa2b1 | 61 | if (!line.IsEmpty()) |
e37feda2 | 62 | { |
92afa2b1 RR |
63 | wxStaticText *s1 = new wxStaticText( this, -1, line ); |
64 | box->Add( s1 ); | |
65 | line = _T(""); | |
e37feda2 | 66 | } |
8a5137d7 RR |
67 | else |
68 | { | |
69 | box->Add( 5, y ); | |
70 | } | |
e37feda2 VZ |
71 | } |
72 | else | |
73 | { | |
92afa2b1 | 74 | line += message[pos]; |
e37feda2 VZ |
75 | } |
76 | } | |
b730516c | 77 | |
92afa2b1 RR |
78 | // remaining text behind last '\n' |
79 | if (!line.IsEmpty()) | |
e37feda2 | 80 | { |
92afa2b1 RR |
81 | wxStaticText *s2 = new wxStaticText( this, -1, line ); |
82 | box->Add( s2 ); | |
e37feda2 | 83 | } |
b730516c | 84 | |
92afa2b1 | 85 | return box; |
e37feda2 | 86 | } |
b730516c | 87 | |
92afa2b1 | 88 | wxSizer *wxDialogBase::CreateButtonSizer( long flags ) |
e37feda2 | 89 | { |
92afa2b1 | 90 | wxBoxSizer *box = new wxBoxSizer( wxHORIZONTAL ); |
e37feda2 | 91 | |
92afa2b1 RR |
92 | #if defined(__WXMSW__) || defined(__WXMAC__) |
93 | int margin = 6; | |
94 | #else | |
95 | int margin = 10; | |
96 | #endif | |
e37feda2 | 97 | |
92afa2b1 RR |
98 | wxButton *ok = (wxButton *) NULL; |
99 | wxButton *cancel = (wxButton *) NULL; | |
100 | wxButton *yes = (wxButton *) NULL; | |
101 | wxButton *no = (wxButton *) NULL; | |
9c884972 RR |
102 | |
103 | // always show an OK button, unless only YES_NO is given | |
104 | if ((flags & wxYES_NO) == 0) flags = flags | wxOK; | |
b730516c RD |
105 | |
106 | if (flags & wxYES_NO) | |
e37feda2 | 107 | { |
92afa2b1 RR |
108 | yes = new wxButton( this, wxID_YES, _("Yes") ); |
109 | box->Add( yes, 0, wxLEFT|wxRIGHT, margin ); | |
110 | no = new wxButton( this, wxID_NO, _("No") ); | |
111 | box->Add( no, 0, wxLEFT|wxRIGHT, margin ); | |
b730516c RD |
112 | } else |
113 | if (flags & wxYES) | |
92afa2b1 RR |
114 | { |
115 | yes = new wxButton( this, wxID_YES, _("Yes") ); | |
116 | box->Add( yes, 0, wxLEFT|wxRIGHT, margin ); | |
b730516c RD |
117 | } else |
118 | if (flags & wxNO) | |
92afa2b1 RR |
119 | { |
120 | no = new wxButton( this, wxID_NO, _("No") ); | |
121 | box->Add( no, 0, wxLEFT|wxRIGHT, margin ); | |
e37feda2 | 122 | } |
92afa2b1 | 123 | |
b730516c | 124 | if (flags & wxOK) |
e37feda2 | 125 | { |
92afa2b1 RR |
126 | ok = new wxButton( this, wxID_OK, _("OK") ); |
127 | box->Add( ok, 0, wxLEFT|wxRIGHT, margin ); | |
e37feda2 VZ |
128 | } |
129 | ||
b730516c RD |
130 | if (flags & wxFORWARD) |
131 | box->Add( new wxButton( this, wxID_FORWARD, _("Forward") ), 0, wxLEFT|wxRIGHT, margin ); | |
e37feda2 | 132 | |
b730516c | 133 | if (flags & wxBACKWARD) |
92afa2b1 | 134 | box->Add( new wxButton( this, wxID_BACKWARD, _("Backward") ), 0, wxLEFT|wxRIGHT, margin ); |
e37feda2 | 135 | |
b730516c | 136 | if (flags & wxSETUP) |
92afa2b1 | 137 | box->Add( new wxButton( this, wxID_SETUP, _("Setup") ), 0, wxLEFT|wxRIGHT, margin ); |
e37feda2 | 138 | |
b730516c | 139 | if (flags & wxMORE) |
92afa2b1 | 140 | box->Add( new wxButton( this, wxID_MORE, _("More...") ), 0, wxLEFT|wxRIGHT, margin ); |
e37feda2 | 141 | |
92afa2b1 RR |
142 | if (flags & wxHELP) |
143 | box->Add( new wxButton( this, wxID_HELP, _("Help") ), 0, wxLEFT|wxRIGHT, margin ); | |
e37feda2 | 144 | |
b730516c | 145 | if (flags & wxCANCEL) |
e37feda2 | 146 | { |
92afa2b1 RR |
147 | cancel = new wxButton( this, wxID_CANCEL, _("Cancel") ); |
148 | box->Add( cancel, 0, wxLEFT|wxRIGHT, margin ); | |
e37feda2 VZ |
149 | } |
150 | ||
b730516c RD |
151 | if (flags & wxNO_DEFAULT) |
152 | { | |
153 | if (no) | |
154 | { | |
155 | no->SetDefault(); | |
156 | no->SetFocus(); | |
157 | } | |
158 | } | |
159 | else | |
92afa2b1 RR |
160 | { |
161 | if (ok) | |
162 | { | |
163 | ok->SetDefault(); | |
164 | ok->SetFocus(); | |
165 | } | |
166 | else if (yes) | |
167 | { | |
168 | yes->SetDefault(); | |
169 | yes->SetFocus(); | |
170 | } | |
171 | } | |
b730516c | 172 | |
92afa2b1 | 173 | return box; |
e37feda2 VZ |
174 | } |
175 |