]> git.saurik.com Git - wxWidgets.git/blob - src/common/dlgcmn.cpp
Changed values passed to SetClientSize() in CreateWidgets() so that buttons are not...
[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 #include "wx/sizer.h"
40 #endif
41
42 //--------------------------------------------------------------------------
43 // wxDialogBase
44 //--------------------------------------------------------------------------
45
46 wxSizer *wxDialogBase::CreateTextSizer( const wxString &message )
47 {
48 wxBoxSizer *box = new wxBoxSizer( wxVERTICAL );
49
50 // get line height for empty lines
51 int y = 0;
52 wxFont new_font( GetFont() );
53 if (!new_font.Ok()) new_font = *wxSWISS_FONT;
54 GetTextExtent( "H", (int*)NULL, &y, (int*)NULL, (int*)NULL, &new_font );
55
56 wxString line;
57 for (size_t pos = 0; pos < message.Len(); pos++)
58 {
59 if (message[pos] == _T('\n'))
60 {
61 if (!line.IsEmpty())
62 {
63 wxStaticText *s1 = new wxStaticText( this, -1, line );
64 box->Add( s1 );
65 line = _T("");
66 }
67 else
68 {
69 box->Add( 5, y );
70 }
71 }
72 else
73 {
74 line += message[pos];
75 }
76 }
77
78 // remaining text behind last '\n'
79 if (!line.IsEmpty())
80 {
81 wxStaticText *s2 = new wxStaticText( this, -1, line );
82 box->Add( s2 );
83 }
84
85 return box;
86 }
87
88 wxSizer *wxDialogBase::CreateButtonSizer( long flags )
89 {
90 wxBoxSizer *box = new wxBoxSizer( wxHORIZONTAL );
91
92 #if defined(__WXMSW__) || defined(__WXMAC__)
93 int margin = 6;
94 #else
95 int margin = 10;
96 #endif
97
98 wxButton *ok = (wxButton *) NULL;
99 wxButton *cancel = (wxButton *) NULL;
100 wxButton *yes = (wxButton *) NULL;
101 wxButton *no = (wxButton *) NULL;
102
103 if (flags & wxYES_NO)
104 {
105 yes = new wxButton( this, wxID_YES, _("Yes") );
106 box->Add( yes, 0, wxLEFT|wxRIGHT, margin );
107 no = new wxButton( this, wxID_NO, _("No") );
108 box->Add( no, 0, wxLEFT|wxRIGHT, margin );
109 } else
110 if (flags & wxYES)
111 {
112 yes = new wxButton( this, wxID_YES, _("Yes") );
113 box->Add( yes, 0, wxLEFT|wxRIGHT, margin );
114 } else
115 if (flags & wxNO)
116 {
117 no = new wxButton( this, wxID_NO, _("No") );
118 box->Add( no, 0, wxLEFT|wxRIGHT, margin );
119 }
120
121 if (flags & wxOK)
122 {
123 ok = new wxButton( this, wxID_OK, _("OK") );
124 box->Add( ok, 0, wxLEFT|wxRIGHT, margin );
125 }
126
127 if (flags & wxFORWARD)
128 box->Add( new wxButton( this, wxID_FORWARD, _("Forward") ), 0, wxLEFT|wxRIGHT, margin );
129
130 if (flags & wxBACKWARD)
131 box->Add( new wxButton( this, wxID_BACKWARD, _("Backward") ), 0, wxLEFT|wxRIGHT, margin );
132
133 if (flags & wxSETUP)
134 box->Add( new wxButton( this, wxID_SETUP, _("Setup") ), 0, wxLEFT|wxRIGHT, margin );
135
136 if (flags & wxMORE)
137 box->Add( new wxButton( this, wxID_MORE, _("More...") ), 0, wxLEFT|wxRIGHT, margin );
138
139 if (flags & wxHELP)
140 box->Add( new wxButton( this, wxID_HELP, _("Help") ), 0, wxLEFT|wxRIGHT, margin );
141
142 if (flags & wxCANCEL)
143 {
144 cancel = new wxButton( this, wxID_CANCEL, _("Cancel") );
145 box->Add( cancel, 0, wxLEFT|wxRIGHT, margin );
146 }
147
148 if ((flags & wxNO_DEFAULT) == 0)
149 {
150 if (ok)
151 {
152 ok->SetDefault();
153 ok->SetFocus();
154 }
155 else if (yes)
156 {
157 yes->SetDefault();
158 yes->SetFocus();
159 }
160 }
161
162 return box;
163 }
164