]> git.saurik.com Git - wxWidgets.git/blame - src/common/dlgcmn.cpp
Made changes to allow build with new mingw32/gcc-2.95
[wxWidgets.git] / src / common / dlgcmn.cpp
CommitLineData
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
45const long wxDialogBase::LAYOUT_X_MARGIN = 5;
46const long wxDialogBase::LAYOUT_Y_MARGIN = 5;
47
48const long wxDialogBase::MARGIN_BETWEEN_BUTTONS = 3*LAYOUT_X_MARGIN;
49
50// ============================================================================
51// implementation
52// ============================================================================
53
54// ----------------------------------------------------------------------------
55// dialog layout functions
56// ----------------------------------------------------------------------------
57
58wxSize 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 {
1408104d
DW
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
e37feda2 76 dc.GetTextExtent(curLine, &width, &height);
1408104d 77#endif
e37feda2
VZ
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
102long 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
120wxSize wxDialogBase::GetStandardButtonSize(bool hasCancel)
121{
122 int wButton = 0;
123 GetTextExtent(_("OK"), &wButton, NULL);
124
125 if ( hasCancel )
126 {
127 int width;
128 GetTextExtent(_("Cancel"), &width, NULL);
129 if ( width > wButton )
130 wButton = width;
131 }
132
133 if ( wButton < 75 )
134 {
135 // the minimal acceptable width
136 wButton = 75;
137 }
138 else
139 {
140 // the width of the button is not just the width of the label...
141 wButton += 2*LAYOUT_X_MARGIN;
142 }
143
144 // a nice looking proportion
145 int hButton = (wButton * 23) / 75;
146
147 return wxSize(wButton, hButton);
148}
149
150void wxDialogBase::CreateStandardButtons(long wDialog,
151 long y,
152 long wButton,
153 long hButton,
154 bool hasCancel)
155{
156 // NB: create [Ok] first to get the right tab order
157 wxButton *ok = (wxButton *) NULL;
158 wxButton *cancel = (wxButton *) NULL;
159
160 long x = wDialog / 2;
161 if ( hasCancel )
162 x -= MARGIN_BETWEEN_BUTTONS / 2 + wButton;
163 else
164 x -= wButton / 2;
165
166 ok = new wxButton( this, wxID_OK, _("OK"),
167 wxPoint(x, y),
168 wxSize(wButton, hButton) );
169
170 if ( hasCancel )
171 {
172 x += MARGIN_BETWEEN_BUTTONS + wButton;
173 cancel = new wxButton( this, wxID_CANCEL, _("Cancel"),
174 wxPoint(x, y),
175 wxSize(wButton, hButton) );
176 }
177
178 ok->SetDefault();
179 ok->SetFocus();
180}
181
182long wxDialogBase::GetStandardTextHeight()
183{
184 return (3*GetCharHeight()) / 2;
185}