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