]> git.saurik.com Git - wxWidgets.git/blob - src/generic/propdlg.cpp
Rewritten wxList docs
[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 parent = GetParentForModalDialog(parent);
66
67 if (!wxDialog::Create(parent, id, title, pos, sz, style|wxCLIP_CHILDREN, name))
68 return false;
69
70 wxBoxSizer *topSizer = new wxBoxSizer( wxVERTICAL );
71 SetSizer(topSizer);
72
73 // This gives more space around the edges
74 m_innerSizer = new wxBoxSizer( wxVERTICAL );
75
76 #if defined(__SMARTPHONE__) || defined(__POCKETPC__)
77 m_sheetOuterBorder = 0;
78 #endif
79 topSizer->Add(m_innerSizer, 1, wxGROW|wxALL, m_sheetOuterBorder);
80
81 m_bookCtrl = CreateBookCtrl();
82 AddBookCtrl(m_innerSizer);
83
84 return true;
85 }
86
87 void wxPropertySheetDialog::Init()
88 {
89 m_sheetStyle = wxPROPSHEET_DEFAULT;
90 m_innerSizer = NULL;
91 m_bookCtrl = NULL;
92 m_sheetOuterBorder = 2;
93 m_sheetInnerBorder = 5;
94 }
95
96 // Layout the dialog, to be called after pages have been created
97 void wxPropertySheetDialog::LayoutDialog(int centreFlags)
98 {
99 #if !defined(__SMARTPHONE__) && !defined(__POCKETPC__)
100 GetSizer()->Fit(this);
101 GetSizer()->SetSizeHints(this);
102 if (centreFlags)
103 Centre(centreFlags);
104 #else
105 wxUnusedVar(centreFlags);
106 #endif
107 #if defined(__SMARTPHONE__)
108 if (m_bookCtrl)
109 m_bookCtrl->SetFocus();
110 #endif
111 }
112
113 // Creates the buttons, if any
114 void wxPropertySheetDialog::CreateButtons(int flags)
115 {
116 #ifdef __POCKETPC__
117 // keep system option status
118 const wxChar *optionName = wxT("wince.dialog.real-ok-cancel");
119 const int status = wxSystemOptions::GetOptionInt(optionName);
120 wxSystemOptions::SetOption(optionName,0);
121 #endif
122
123 wxSizer *buttonSizer = CreateButtonSizer( flags & ButtonSizerFlags );
124 if( buttonSizer )
125 {
126 m_innerSizer->Add( buttonSizer, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxTOP|wxBOTTOM|wxLEFT|wxRIGHT, 2);
127 m_innerSizer->AddSpacer(2);
128 }
129
130 #ifdef __POCKETPC__
131 // restore system option
132 wxSystemOptions::SetOption(optionName,status);
133 #endif
134 }
135
136 // Creates the book control
137 wxBookCtrlBase* wxPropertySheetDialog::CreateBookCtrl()
138 {
139 int style = wxCLIP_CHILDREN | wxBK_DEFAULT;
140
141 wxBookCtrlBase* bookCtrl = NULL;
142
143 #if wxUSE_NOTEBOOK
144 if (GetSheetStyle() & wxPROPSHEET_NOTEBOOK)
145 bookCtrl = new wxNotebook(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, style );
146 #endif
147 #if wxUSE_CHOICEBOOK
148 if (GetSheetStyle() & wxPROPSHEET_CHOICEBOOK)
149 bookCtrl = new wxChoicebook(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, style );
150 #endif
151 #if wxUSE_TOOLBOOK
152 #if defined(__WXMAC__) && wxUSE_TOOLBAR && wxUSE_BMPBUTTON
153 if (GetSheetStyle() & wxPROPSHEET_BUTTONTOOLBOOK)
154 bookCtrl = new wxToolbook(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, style|wxBK_BUTTONBAR );
155 else
156 #endif
157 if ((GetSheetStyle() & wxPROPSHEET_TOOLBOOK) || (GetSheetStyle() & wxPROPSHEET_BUTTONTOOLBOOK))
158 bookCtrl = new wxToolbook(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, style );
159 #endif
160 #if wxUSE_LISTBOOK
161 if (GetSheetStyle() & wxPROPSHEET_LISTBOOK)
162 bookCtrl = new wxListbook(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, style );
163 #endif
164 #if wxUSE_TREEBOOK
165 if (GetSheetStyle() & wxPROPSHEET_TREEBOOK)
166 bookCtrl = new wxTreebook(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, style );
167 #endif
168 if (!bookCtrl)
169 bookCtrl = new wxBookCtrl(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, style );
170
171 if (GetSheetStyle() & wxPROPSHEET_SHRINKTOFIT)
172 bookCtrl->SetFitToCurrentPage(true);
173
174 return bookCtrl;
175 }
176
177 // Adds the book control to the inner sizer.
178 void wxPropertySheetDialog::AddBookCtrl(wxSizer* sizer)
179 {
180 #if defined(__POCKETPC__) && wxUSE_NOTEBOOK
181 // The book control has to be sized larger than the dialog because of a border bug
182 // in WinCE
183 int borderSize = -2;
184 sizer->Add( m_bookCtrl, 1, wxGROW|wxALIGN_CENTER_VERTICAL|wxLEFT|wxTOP|wxRIGHT, borderSize );
185 #else
186 sizer->Add( m_bookCtrl, 1, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, m_sheetInnerBorder );
187 #endif
188 }
189
190 void wxPropertySheetDialog::OnActivate(wxActivateEvent& event)
191 {
192 #if defined(__SMARTPHONE__)
193 // Attempt to focus the choice control: not yet working, but might
194 // be a step in the right direction. OnActivate overrides the default
195 // handler in toplevel.cpp that sets the focus for the first child of
196 // of the dialog (the choicebook).
197 if (event.GetActive())
198 {
199 wxChoicebook* choiceBook = wxDynamicCast(GetBookCtrl(), wxChoicebook);
200 if (choiceBook)
201 choiceBook->SetFocus();
202 }
203 else
204 #endif
205 event.Skip();
206 }
207
208 // Resize dialog if necessary
209 void wxPropertySheetDialog::OnIdle(wxIdleEvent& event)
210 {
211 event.Skip();
212
213 if ((GetSheetStyle() & wxPROPSHEET_SHRINKTOFIT) && GetBookCtrl())
214 {
215 int sel = GetBookCtrl()->GetSelection();
216 if (sel != -1 && sel != m_selectedPage)
217 {
218 GetBookCtrl()->InvalidateBestSize();
219 InvalidateBestSize();
220 SetSizeHints(-1, -1, -1, -1);
221
222 m_selectedPage = sel;
223 LayoutDialog(0);
224 }
225 }
226 }
227
228 #endif // wxUSE_BOOKCTRL