]> git.saurik.com Git - wxWidgets.git/blob - src/common/dlgcmn.cpp
implemented better paths handling: dir1/../dir2/file is replaced by dir2/file
[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 #ifdef __GNUG__
21 #pragma implementation "dialogbase.h"
22 #endif
23
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
26
27 #ifdef __BORLANDC__
28 #pragma hdrstop
29 #endif
30
31 #ifndef WX_PRECOMP
32 #include "wx/dialog.h"
33 #include "wx/dcclient.h"
34 #include "wx/intl.h"
35 #include "wx/settings.h"
36 #include "wx/stattext.h"
37 #include "wx/sizer.h"
38 #endif
39
40 //--------------------------------------------------------------------------
41 // wxDialogBase
42 //--------------------------------------------------------------------------
43
44 wxSizer *wxDialogBase::CreateTextSizer( const wxString &message )
45 {
46 wxBoxSizer *box = new wxBoxSizer( wxVERTICAL );
47
48 // get line height for empty lines
49 int y = 0;
50 wxFont font( GetFont() );
51 if (!font.Ok())
52 font = *wxSWISS_FONT;
53 GetTextExtent(_T("H"), (int*)NULL, &y, (int*)NULL, (int*)NULL, &font);
54
55 wxString line;
56 for (size_t pos = 0; pos < message.Len(); pos++)
57 {
58 if (message[pos] == wxT('\n'))
59 {
60 if (!line.IsEmpty())
61 {
62 wxStaticText *s1 = new wxStaticText( this, -1, line );
63 box->Add( s1 );
64 line = wxT("");
65 }
66 else
67 {
68 box->Add( 5, y );
69 }
70 }
71 else
72 {
73 line += message[pos];
74 }
75 }
76
77 // remaining text behind last '\n'
78 if (!line.IsEmpty())
79 {
80 wxStaticText *s2 = new wxStaticText( this, -1, line );
81 box->Add( s2 );
82 }
83
84 return box;
85 }
86
87 wxSizer *wxDialogBase::CreateButtonSizer( long flags )
88 {
89 wxBoxSizer *box = new wxBoxSizer( wxHORIZONTAL );
90
91 #if defined(__WXMSW__) || defined(__WXMAC__)
92 static const int margin = 6;
93 #else
94 static const int margin = 10;
95 #endif
96
97 wxButton *ok = (wxButton *) NULL;
98 wxButton *cancel = (wxButton *) NULL;
99 wxButton *yes = (wxButton *) NULL;
100 wxButton *no = (wxButton *) NULL;
101
102 // always show an OK button, unless only YES_NO is given
103 if ((flags & wxYES_NO) == 0) flags = flags | wxOK;
104
105 if (flags & wxYES_NO)
106 {
107 yes = new wxButton( this, wxID_YES, _("Yes") );
108 box->Add( yes, 0, wxLEFT|wxRIGHT, margin );
109 no = new wxButton( this, wxID_NO, _("No") );
110 box->Add( no, 0, wxLEFT|wxRIGHT, margin );
111 } else
112 if (flags & wxYES)
113 {
114 yes = new wxButton( this, wxID_YES, _("Yes") );
115 box->Add( yes, 0, wxLEFT|wxRIGHT, margin );
116 } else
117 if (flags & wxNO)
118 {
119 no = new wxButton( this, wxID_NO, _("No") );
120 box->Add( no, 0, wxLEFT|wxRIGHT, margin );
121 }
122
123 if (flags & wxOK)
124 {
125 ok = new wxButton( this, wxID_OK, _("OK") );
126 box->Add( ok, 0, wxLEFT|wxRIGHT, margin );
127 }
128
129 if (flags & wxFORWARD)
130 box->Add( new wxButton( this, wxID_FORWARD, _("Forward") ), 0, wxLEFT|wxRIGHT, margin );
131
132 if (flags & wxBACKWARD)
133 box->Add( new wxButton( this, wxID_BACKWARD, _("Backward") ), 0, wxLEFT|wxRIGHT, margin );
134
135 if (flags & wxSETUP)
136 box->Add( new wxButton( this, wxID_SETUP, _("Setup") ), 0, wxLEFT|wxRIGHT, margin );
137
138 if (flags & wxMORE)
139 box->Add( new wxButton( this, wxID_MORE, _("More...") ), 0, wxLEFT|wxRIGHT, margin );
140
141 if (flags & wxHELP)
142 box->Add( new wxButton( this, wxID_HELP, _("Help") ), 0, wxLEFT|wxRIGHT, margin );
143
144 if (flags & wxCANCEL)
145 {
146 cancel = new wxButton( this, wxID_CANCEL, _("Cancel") );
147 box->Add( cancel, 0, wxLEFT|wxRIGHT, margin );
148 }
149
150 if (flags & wxNO_DEFAULT)
151 {
152 if (no)
153 {
154 no->SetDefault();
155 no->SetFocus();
156 }
157 }
158 else
159 {
160 if (ok)
161 {
162 ok->SetDefault();
163 ok->SetFocus();
164 }
165 else if (yes)
166 {
167 yes->SetDefault();
168 yes->SetFocus();
169 }
170 }
171
172 return box;
173 }
174