]> git.saurik.com Git - wxWidgets.git/blob - src/generic/propdlg.cpp
added wxCSConv::IsOk() (patch 1637944)
[wxWidgets.git] / src / generic / propdlg.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/generic/propdlg.cpp
3 // Purpose: wxPropertySheetDialog
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 2005-03-12
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
14
15 #ifdef __BORLANDC__
16 #pragma hdrstop
17 #endif
18
19 #if wxUSE_BOOKCTRL
20
21 #ifndef WX_PRECOMP
22 #include "wx/button.h"
23 #include "wx/sizer.h"
24 #include "wx/intl.h"
25 #include "wx/log.h"
26 #include "wx/msgdlg.h"
27 #endif
28
29 #include "wx/bookctrl.h"
30
31 #if wxUSE_NOTEBOOK
32 #include "wx/notebook.h"
33 #endif
34 #if wxUSE_CHOICEBOOK
35 #include "wx/choicebk.h"
36 #endif
37 #if wxUSE_TOOLBOOK
38 #include "wx/toolbook.h"
39 #endif
40 #if wxUSE_LISTBOOK
41 #include "wx/listbook.h"
42 #endif
43 #if wxUSE_TREEBOOK
44 #include "wx/treebook.h"
45 #endif
46
47 #include "wx/generic/propdlg.h"
48 #include "wx/sysopt.h"
49
50 //-----------------------------------------------------------------------------
51 // wxPropertySheetDialog
52 //-----------------------------------------------------------------------------
53
54 IMPLEMENT_DYNAMIC_CLASS(wxPropertySheetDialog, wxDialog)
55
56 BEGIN_EVENT_TABLE(wxPropertySheetDialog, wxDialog)
57 EVT_ACTIVATE(wxPropertySheetDialog::OnActivate)
58 EVT_IDLE(wxPropertySheetDialog::OnIdle)
59 END_EVENT_TABLE()
60
61 bool wxPropertySheetDialog::Create(wxWindow* parent, wxWindowID id, const wxString& title,
62 const wxPoint& pos, const wxSize& sz, long style,
63 const wxString& name)
64 {
65 if (!wxDialog::Create(parent, id, title, pos, sz, style|wxCLIP_CHILDREN, name))
66 return false;
67
68 wxBoxSizer *topSizer = new wxBoxSizer( wxVERTICAL );
69 SetSizer(topSizer);
70
71 // This gives more space around the edges
72 m_innerSizer = new wxBoxSizer( wxVERTICAL );
73
74 #if defined(__SMARTPHONE__) || defined(__POCKETPC__)
75 m_sheetOuterBorder = 0;
76 #endif
77 topSizer->Add(m_innerSizer, 1, wxGROW|wxALL, m_sheetOuterBorder);
78
79 m_bookCtrl = CreateBookCtrl();
80 AddBookCtrl(m_innerSizer);
81
82 return true;
83 }
84
85 void wxPropertySheetDialog::Init()
86 {
87 m_sheetStyle = wxPROPSHEET_DEFAULT;
88 m_innerSizer = NULL;
89 m_bookCtrl = NULL;
90 m_sheetOuterBorder = 2;
91 m_sheetInnerBorder = 5;
92 }
93
94 // Layout the dialog, to be called after pages have been created
95 void wxPropertySheetDialog::LayoutDialog(int centreFlags)
96 {
97 #if !defined(__SMARTPHONE__) && !defined(__POCKETPC__)
98 GetSizer()->Fit(this);
99 GetSizer()->SetSizeHints(this);
100 if (centreFlags)
101 Centre(centreFlags);
102 #else
103 wxUnusedVar(centreFlags);
104 #endif
105 #if defined(__SMARTPHONE__)
106 if (m_bookCtrl)
107 m_bookCtrl->SetFocus();
108 #endif
109 }
110
111 // Creates the buttons, if any
112 void wxPropertySheetDialog::CreateButtons(int flags)
113 {
114 #ifdef __POCKETPC__
115 // keep system option status
116 const wxChar *optionName = wxT("wince.dialog.real-ok-cancel");
117 const int status = wxSystemOptions::GetOptionInt(optionName);
118 wxSystemOptions::SetOption(optionName,0);
119 #endif
120
121 wxSizer *buttonSizer = CreateButtonSizer( flags & ButtonSizerFlags );
122 if( buttonSizer )
123 {
124 m_innerSizer->Add( buttonSizer, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxTOP|wxBOTTOM|wxLEFT|wxRIGHT, 2);
125 m_innerSizer->AddSpacer(2);
126 }
127
128 #ifdef __POCKETPC__
129 // restore system option
130 wxSystemOptions::SetOption(optionName,status);
131 #endif
132 }
133
134 // Creates the book control
135 wxBookCtrlBase* wxPropertySheetDialog::CreateBookCtrl()
136 {
137 int style = wxCLIP_CHILDREN | wxBK_DEFAULT;
138
139 wxBookCtrlBase* bookCtrl = NULL;
140
141 #if wxUSE_NOTEBOOK
142 if (GetSheetStyle() & wxPROPSHEET_NOTEBOOK)
143 bookCtrl = new wxNotebook(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, style );
144 #endif
145 #if wxUSE_CHOICEBOOK
146 if (GetSheetStyle() & wxPROPSHEET_CHOICEBOOK)
147 bookCtrl = new wxChoicebook(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, style );
148 #endif
149 #if wxUSE_TOOLBOOK
150 #if defined(__WXMAC__) && wxUSE_TOOLBAR && wxUSE_BMPBUTTON
151 if (GetSheetStyle() & wxPROPSHEET_BUTTONTOOLBOOK)
152 bookCtrl = new wxToolbook(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, style|wxBK_BUTTONBAR );
153 else
154 #endif
155 if ((GetSheetStyle() & wxPROPSHEET_TOOLBOOK) || (GetSheetStyle() & wxPROPSHEET_BUTTONTOOLBOOK))
156 bookCtrl = new wxToolbook(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, style );
157 #endif
158 #if wxUSE_LISTBOOK
159 if (GetSheetStyle() & wxPROPSHEET_LISTBOOK)
160 bookCtrl = new wxListbook(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, style );
161 #endif
162 #if wxUSE_TREEBOOK
163 if (GetSheetStyle() & wxPROPSHEET_TREEBOOK)
164 bookCtrl = new wxTreebook(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, style );
165 #endif
166 if (!bookCtrl)
167 bookCtrl = new wxBookCtrl(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, style );
168
169 if (GetSheetStyle() & wxPROPSHEET_SHRINKTOFIT)
170 bookCtrl->SetFitToCurrentPage(true);
171
172 return bookCtrl;
173 }
174
175 // Adds the book control to the inner sizer.
176 void wxPropertySheetDialog::AddBookCtrl(wxSizer* sizer)
177 {
178 #if defined(__POCKETPC__) && wxUSE_NOTEBOOK
179 // The book control has to be sized larger than the dialog because of a border bug
180 // in WinCE
181 int borderSize = -2;
182 sizer->Add( m_bookCtrl, 1, wxGROW|wxALIGN_CENTER_VERTICAL|wxLEFT|wxTOP|wxRIGHT, borderSize );
183 #else
184 sizer->Add( m_bookCtrl, 1, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, m_sheetInnerBorder );
185 #endif
186 }
187
188 void wxPropertySheetDialog::OnActivate(wxActivateEvent& event)
189 {
190 #if defined(__SMARTPHONE__)
191 // Attempt to focus the choice control: not yet working, but might
192 // be a step in the right direction. OnActivate overrides the default
193 // handler in toplevel.cpp that sets the focus for the first child of
194 // of the dialog (the choicebook).
195 if (event.GetActive())
196 {
197 wxChoicebook* choiceBook = wxDynamicCast(GetBookCtrl(), wxChoicebook);
198 if (choiceBook)
199 choiceBook->SetFocus();
200 }
201 else
202 #endif
203 event.Skip();
204 }
205
206 // Resize dialog if necessary
207 void wxPropertySheetDialog::OnIdle(wxIdleEvent& event)
208 {
209 event.Skip();
210
211 if ((GetSheetStyle() & wxPROPSHEET_SHRINKTOFIT) && GetBookCtrl())
212 {
213 int sel = GetBookCtrl()->GetSelection();
214 if (sel != -1 && sel != m_selectedPage)
215 {
216 GetBookCtrl()->InvalidateBestSize();
217 InvalidateBestSize();
218 SetSizeHints(-1, -1, -1, -1);
219
220 m_selectedPage = sel;
221 LayoutDialog(0);
222 }
223 }
224 }
225
226 #endif // wxUSE_BOOKCTRL