Did somework on the generic dialogs,
[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 wxString line;
51 for (size_t pos = 0; pos < message.Len(); pos++)
52 {
53 if (message[pos] == _T('\n'))
54 {
55 if (!line.IsEmpty())
56 {
57 wxStaticText *s1 = new wxStaticText( this, -1, line );
58 box->Add( s1 );
59 line = _T("");
60 }
61 }
62 else
63 {
64 line += message[pos];
65 }
66 }
67
68 // remaining text behind last '\n'
69 if (!line.IsEmpty())
70 {
71 wxStaticText *s2 = new wxStaticText( this, -1, line );
72 box->Add( s2 );
73 }
74
75 return box;
76 }
77
78 wxSizer *wxDialogBase::CreateButtonSizer( long flags )
79 {
80 wxBoxSizer *box = new wxBoxSizer( wxHORIZONTAL );
81
82 #if defined(__WXMSW__) || defined(__WXMAC__)
83 int margin = 6;
84 #else
85 int margin = 10;
86 #endif
87
88 wxButton *ok = (wxButton *) NULL;
89 wxButton *cancel = (wxButton *) NULL;
90 wxButton *yes = (wxButton *) NULL;
91 wxButton *no = (wxButton *) NULL;
92
93 if (flags & wxYES_NO)
94 {
95 yes = new wxButton( this, wxID_YES, _("Yes") );
96 box->Add( yes, 0, wxLEFT|wxRIGHT, margin );
97 no = new wxButton( this, wxID_NO, _("No") );
98 box->Add( no, 0, wxLEFT|wxRIGHT, margin );
99 } else
100 if (flags & wxYES)
101 {
102 yes = new wxButton( this, wxID_YES, _("Yes") );
103 box->Add( yes, 0, wxLEFT|wxRIGHT, margin );
104 } else
105 if (flags & wxNO)
106 {
107 no = new wxButton( this, wxID_NO, _("No") );
108 box->Add( no, 0, wxLEFT|wxRIGHT, margin );
109 }
110
111 if (flags & wxOK)
112 {
113 ok = new wxButton( this, wxID_OK, _("OK") );
114 box->Add( ok, 0, wxLEFT|wxRIGHT, margin );
115 }
116
117 if (flags & wxFORWARD)
118 box->Add( new wxButton( this, wxID_FORWARD, _("Forward") ), 0, wxLEFT|wxRIGHT, margin );
119
120 if (flags & wxBACKWARD)
121 box->Add( new wxButton( this, wxID_BACKWARD, _("Backward") ), 0, wxLEFT|wxRIGHT, margin );
122
123 if (flags & wxSETUP)
124 box->Add( new wxButton( this, wxID_SETUP, _("Setup") ), 0, wxLEFT|wxRIGHT, margin );
125
126 if (flags & wxMORE)
127 box->Add( new wxButton( this, wxID_MORE, _("More...") ), 0, wxLEFT|wxRIGHT, margin );
128
129 if (flags & wxHELP)
130 box->Add( new wxButton( this, wxID_HELP, _("Help") ), 0, wxLEFT|wxRIGHT, margin );
131
132 if (flags & wxCANCEL)
133 {
134 cancel = new wxButton( this, wxID_CANCEL, _("Cancel") );
135 box->Add( cancel, 0, wxLEFT|wxRIGHT, margin );
136 }
137
138 if ((flags & wxNO_DEFAULT) == 0)
139 {
140 if (ok)
141 {
142 ok->SetDefault();
143 ok->SetFocus();
144 }
145 else if (yes)
146 {
147 yes->SetDefault();
148 yes->SetFocus();
149 }
150 }
151
152 return box;
153 }
154