]>
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" |
e37feda2 VZ |
39 | #endif |
40 | ||
41 | // ---------------------------------------------------------------------------- | |
42 | // constants | |
43 | // ---------------------------------------------------------------------------- | |
44 | ||
45 | const long wxDialogBase::LAYOUT_X_MARGIN = 5; | |
46 | const long wxDialogBase::LAYOUT_Y_MARGIN = 5; | |
47 | ||
48 | const long wxDialogBase::MARGIN_BETWEEN_BUTTONS = 3*LAYOUT_X_MARGIN; | |
49 | ||
50 | // ============================================================================ | |
51 | // implementation | |
52 | // ============================================================================ | |
53 | ||
54 | // ---------------------------------------------------------------------------- | |
55 | // dialog layout functions | |
56 | // ---------------------------------------------------------------------------- | |
57 | ||
58 | wxSize wxDialogBase::SplitTextMessage(const wxString& message, | |
59 | wxArrayString *lines) | |
60 | { | |
61 | wxClientDC dc(this); | |
62 | dc.SetFont(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT)); | |
63 | ||
64 | wxString curLine; | |
65 | long height, width, heightTextMax = 0, widthTextMax = 0; | |
66 | for ( const wxChar *pc = message; ; pc++ ) | |
67 | { | |
68 | if ( *pc == _T('\n') || !*pc ) | |
69 | { | |
70 | dc.GetTextExtent(curLine, &width, &height); | |
71 | if ( width > widthTextMax ) | |
72 | widthTextMax = width; | |
73 | if ( height > heightTextMax ) | |
74 | heightTextMax = height; | |
75 | ||
76 | lines->Add(curLine); | |
77 | ||
78 | if ( !*pc ) | |
79 | { | |
80 | // the end of string | |
81 | break; | |
82 | } | |
83 | ||
84 | curLine.Empty(); | |
85 | } | |
86 | else | |
87 | { | |
88 | curLine += *pc; | |
89 | } | |
90 | } | |
91 | ||
92 | return wxSize(widthTextMax, heightTextMax); | |
93 | } | |
94 | ||
95 | long wxDialogBase::CreateTextMessage(const wxArrayString& lines, | |
96 | const wxPoint& posText, | |
97 | const wxSize& sizeText) | |
98 | { | |
99 | wxStaticText *text; | |
100 | int y = posText.y; | |
101 | size_t nLineCount = lines.GetCount(); | |
102 | for ( size_t nLine = 0; nLine < nLineCount; nLine++ ) | |
103 | { | |
104 | text = new wxStaticText(this, -1, lines[nLine], | |
105 | wxPoint(posText.x, y), | |
106 | sizeText); | |
107 | y += sizeText.GetHeight(); | |
108 | } | |
109 | ||
110 | return y; | |
111 | } | |
112 | ||
113 | wxSize wxDialogBase::GetStandardButtonSize(bool hasCancel) | |
114 | { | |
115 | int wButton = 0; | |
116 | GetTextExtent(_("OK"), &wButton, NULL); | |
117 | ||
118 | if ( hasCancel ) | |
119 | { | |
120 | int width; | |
121 | GetTextExtent(_("Cancel"), &width, NULL); | |
122 | if ( width > wButton ) | |
123 | wButton = width; | |
124 | } | |
125 | ||
126 | if ( wButton < 75 ) | |
127 | { | |
128 | // the minimal acceptable width | |
129 | wButton = 75; | |
130 | } | |
131 | else | |
132 | { | |
133 | // the width of the button is not just the width of the label... | |
134 | wButton += 2*LAYOUT_X_MARGIN; | |
135 | } | |
136 | ||
137 | // a nice looking proportion | |
138 | int hButton = (wButton * 23) / 75; | |
139 | ||
140 | return wxSize(wButton, hButton); | |
141 | } | |
142 | ||
143 | void wxDialogBase::CreateStandardButtons(long wDialog, | |
144 | long y, | |
145 | long wButton, | |
146 | long hButton, | |
147 | bool hasCancel) | |
148 | { | |
149 | // NB: create [Ok] first to get the right tab order | |
150 | wxButton *ok = (wxButton *) NULL; | |
151 | wxButton *cancel = (wxButton *) NULL; | |
152 | ||
153 | long x = wDialog / 2; | |
154 | if ( hasCancel ) | |
155 | x -= MARGIN_BETWEEN_BUTTONS / 2 + wButton; | |
156 | else | |
157 | x -= wButton / 2; | |
158 | ||
159 | ok = new wxButton( this, wxID_OK, _("OK"), | |
160 | wxPoint(x, y), | |
161 | wxSize(wButton, hButton) ); | |
162 | ||
163 | if ( hasCancel ) | |
164 | { | |
165 | x += MARGIN_BETWEEN_BUTTONS + wButton; | |
166 | cancel = new wxButton( this, wxID_CANCEL, _("Cancel"), | |
167 | wxPoint(x, y), | |
168 | wxSize(wButton, hButton) ); | |
169 | } | |
170 | ||
171 | ok->SetDefault(); | |
172 | ok->SetFocus(); | |
173 | } | |
174 | ||
175 | long wxDialogBase::GetStandardTextHeight() | |
176 | { | |
177 | return (3*GetCharHeight()) / 2; | |
178 | } |