]> git.saurik.com Git - wxWidgets.git/blob - src/common/dlgcmn.cpp
wxButton::GetDefaultSize() fix
[wxWidgets.git] / src / common / dlgcmn.cpp
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/intl.h"
37 #include "wx/settings.h"
38 #include "wx/stattext.h"
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 #if defined(__VISAGECPP__)
71 // have two versions of this in wxWindowDC tp avoid function hiding
72 // since there are two of these in wxDCBase, and in turn in wxDC.
73 // VA cannot resolve this so:
74 dc.GetTextExtent(curLine, &width, &height, NULL, NULL, NULL, FALSE);
75 #else
76 dc.GetTextExtent(curLine, &width, &height);
77 #endif
78 if ( width > widthTextMax )
79 widthTextMax = width;
80 if ( height > heightTextMax )
81 heightTextMax = height;
82
83 lines->Add(curLine);
84
85 if ( !*pc )
86 {
87 // the end of string
88 break;
89 }
90
91 curLine.Empty();
92 }
93 else
94 {
95 curLine += *pc;
96 }
97 }
98
99 return wxSize(widthTextMax, heightTextMax);
100 }
101
102 long wxDialogBase::CreateTextMessage(const wxArrayString& lines,
103 const wxPoint& posText,
104 const wxSize& sizeText)
105 {
106 wxStaticText *text;
107 int y = posText.y;
108 size_t nLineCount = lines.GetCount();
109 for ( size_t nLine = 0; nLine < nLineCount; nLine++ )
110 {
111 text = new wxStaticText(this, -1, lines[nLine],
112 wxPoint(posText.x, y),
113 sizeText);
114 y += sizeText.GetHeight();
115 }
116
117 return y;
118 }
119
120 wxSize wxDialogBase::GetStandardButtonSize(bool hasCancel)
121 {
122 #if 0
123 int wButton = 0;
124 GetTextExtent(_("OK"), &wButton, NULL);
125
126 if ( hasCancel )
127 {
128 int width;
129 GetTextExtent(_("Cancel"), &width, NULL);
130 if ( width > wButton )
131 wButton = width;
132 }
133
134 if ( wButton < 75 )
135 {
136 // the minimal acceptable width
137 wButton = 75;
138 }
139 else
140 {
141 // the width of the button is not just the width of the label...
142 wButton += 2*LAYOUT_X_MARGIN;
143 }
144
145 // a nice looking proportion
146 int hButton = (wButton * 23) / 75;
147
148 return wxSize(wButton, hButton);
149 #else
150 return wxButton::GetDefaultSize();
151 #endif
152 }
153
154 void wxDialogBase::CreateStandardButtons(long wDialog,
155 long y,
156 long wButton,
157 long hButton,
158 bool hasCancel)
159 {
160 // NB: create [Ok] first to get the right tab order
161 wxButton *ok = (wxButton *) NULL;
162 wxButton *cancel = (wxButton *) NULL;
163
164 long x = wDialog / 2;
165 if ( hasCancel )
166 x -= MARGIN_BETWEEN_BUTTONS / 2 + wButton;
167 else
168 x -= wButton / 2;
169
170 ok = new wxButton( this, wxID_OK, _("OK"),
171 wxPoint(x, y),
172 wxSize(wButton, hButton) );
173
174 if ( hasCancel )
175 {
176 x += MARGIN_BETWEEN_BUTTONS + wButton;
177 cancel = new wxButton( this, wxID_CANCEL, _("Cancel"),
178 wxPoint(x, y),
179 wxSize(wButton, hButton) );
180 }
181
182 ok->SetDefault();
183 ok->SetFocus();
184 }
185
186 long wxDialogBase::GetStandardTextHeight()
187 {
188 return (3*GetCharHeight()) / 2;
189 }