]>
git.saurik.com Git - wxWidgets.git/blob - src/common/dlgcmn.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: common/dlgcmn.cpp
3 // Purpose: common (to all ports) wxDialog functions
4 // Author: Vadim Zeitlin
8 // Copyright: (c) Vadim Zeitlin
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
22 #pragma implementation
26 // For compilers that support precompilation, includes "wx.h".
27 #include "wx/wxprec.h"
34 #include "wx/dialog.h"
35 #include "wx/dcclient.h"
37 #include "wx/settings.h"
38 #include "wx/stattext.h"
41 // ----------------------------------------------------------------------------
43 // ----------------------------------------------------------------------------
45 const long wxDialogBase::LAYOUT_X_MARGIN
= 5;
46 const long wxDialogBase::LAYOUT_Y_MARGIN
= 5;
48 const long wxDialogBase::MARGIN_BETWEEN_BUTTONS
= 3*LAYOUT_X_MARGIN
;
50 // ============================================================================
52 // ============================================================================
54 // ----------------------------------------------------------------------------
55 // dialog layout functions
56 // ----------------------------------------------------------------------------
58 wxSize
wxDialogBase::SplitTextMessage(const wxString
& message
,
62 dc
.SetFont(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT
));
65 long height
, width
, heightTextMax
= 0, widthTextMax
= 0;
66 for ( const wxChar
*pc
= message
; ; pc
++ )
68 if ( *pc
== _T('\n') || !*pc
)
70 dc
.GetTextExtent(curLine
, &width
, &height
);
71 if ( width
> widthTextMax
)
73 if ( height
> heightTextMax
)
74 heightTextMax
= height
;
92 return wxSize(widthTextMax
, heightTextMax
);
95 long wxDialogBase::CreateTextMessage(const wxArrayString
& lines
,
96 const wxPoint
& posText
,
97 const wxSize
& sizeText
)
101 size_t nLineCount
= lines
.GetCount();
102 for ( size_t nLine
= 0; nLine
< nLineCount
; nLine
++ )
104 text
= new wxStaticText(this, -1, lines
[nLine
],
105 wxPoint(posText
.x
, y
),
107 y
+= sizeText
.GetHeight();
113 wxSize
wxDialogBase::GetStandardButtonSize(bool hasCancel
)
116 GetTextExtent(_("OK"), &wButton
, NULL
);
121 GetTextExtent(_("Cancel"), &width
, NULL
);
122 if ( width
> wButton
)
128 // the minimal acceptable width
133 // the width of the button is not just the width of the label...
134 wButton
+= 2*LAYOUT_X_MARGIN
;
137 // a nice looking proportion
138 int hButton
= (wButton
* 23) / 75;
140 return wxSize(wButton
, hButton
);
143 void wxDialogBase::CreateStandardButtons(long wDialog
,
149 // NB: create [Ok] first to get the right tab order
150 wxButton
*ok
= (wxButton
*) NULL
;
151 wxButton
*cancel
= (wxButton
*) NULL
;
153 long x
= wDialog
/ 2;
155 x
-= MARGIN_BETWEEN_BUTTONS
/ 2 + wButton
;
159 ok
= new wxButton( this, wxID_OK
, _("OK"),
161 wxSize(wButton
, hButton
) );
165 x
+= MARGIN_BETWEEN_BUTTONS
+ wButton
;
166 cancel
= new wxButton( this, wxID_CANCEL
, _("Cancel"),
168 wxSize(wButton
, hButton
) );
175 long wxDialogBase::GetStandardTextHeight()
177 return (3*GetCharHeight()) / 2;