]>
Commit | Line | Data |
---|---|---|
3c9287bb | 1 | ///////////////////////////////////////////////////////////////////////////// |
2ddb4d13 | 2 | // Name: src/generic/propdlg.cpp |
3c9287bb JS |
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 | ||
3c9287bb JS |
12 | // For compilers that support precompilation, includes "wx.h". |
13 | #include "wx/wxprec.h" | |
14 | ||
15 | #ifdef __BORLANDC__ | |
93763ad5 | 16 | #pragma hdrstop |
3c9287bb JS |
17 | #endif |
18 | ||
532d575b WS |
19 | #if wxUSE_BOOKCTRL |
20 | ||
3c9287bb JS |
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 | ||
3be8026d | 29 | #include "wx/bookctrl.h" |
cc8bc5aa JS |
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 | |
6334d903 JS |
43 | #if wxUSE_TREEBOOK |
44 | #include "wx/treebook.h" | |
45 | #endif | |
cc8bc5aa | 46 | |
3c9287bb | 47 | #include "wx/generic/propdlg.h" |
897b24cf | 48 | #include "wx/sysopt.h" |
3c9287bb JS |
49 | |
50 | //----------------------------------------------------------------------------- | |
51 | // wxPropertySheetDialog | |
52 | //----------------------------------------------------------------------------- | |
53 | ||
54 | IMPLEMENT_DYNAMIC_CLASS(wxPropertySheetDialog, wxDialog) | |
55 | ||
c9ab63f4 JS |
56 | BEGIN_EVENT_TABLE(wxPropertySheetDialog, wxDialog) |
57 | EVT_ACTIVATE(wxPropertySheetDialog::OnActivate) | |
cc8bc5aa | 58 | EVT_IDLE(wxPropertySheetDialog::OnIdle) |
c9ab63f4 JS |
59 | END_EVENT_TABLE() |
60 | ||
532d575b | 61 | bool wxPropertySheetDialog::Create(wxWindow* parent, wxWindowID id, const wxString& title, |
3c9287bb JS |
62 | const wxPoint& pos, const wxSize& sz, long style, |
63 | const wxString& name) | |
64 | { | |
ac5f5c9e | 65 | if (!wxDialog::Create(parent, id, title, pos, sz, style|wxCLIP_CHILDREN, name)) |
3c9287bb | 66 | return false; |
532d575b | 67 | |
3c9287bb JS |
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 | ||
0906c58d | 74 | #if defined(__SMARTPHONE__) || defined(__POCKETPC__) |
1a1190b2 | 75 | m_sheetOuterBorder = 0; |
3c9287bb | 76 | #endif |
1a1190b2 | 77 | topSizer->Add(m_innerSizer, 1, wxGROW|wxALL, m_sheetOuterBorder); |
3c9287bb JS |
78 | |
79 | m_bookCtrl = CreateBookCtrl(); | |
80 | AddBookCtrl(m_innerSizer); | |
81 | ||
82 | return true; | |
83 | } | |
84 | ||
85 | void wxPropertySheetDialog::Init() | |
86 | { | |
cc8bc5aa | 87 | m_sheetStyle = wxPROPSHEET_DEFAULT; |
3c9287bb JS |
88 | m_innerSizer = NULL; |
89 | m_bookCtrl = NULL; | |
1a1190b2 JS |
90 | m_sheetOuterBorder = 2; |
91 | m_sheetInnerBorder = 5; | |
3c9287bb JS |
92 | } |
93 | ||
94 | // Layout the dialog, to be called after pages have been created | |
cc8bc5aa | 95 | void wxPropertySheetDialog::LayoutDialog(int centreFlags) |
3c9287bb | 96 | { |
0906c58d | 97 | #if !defined(__SMARTPHONE__) && !defined(__POCKETPC__) |
3c9287bb | 98 | GetSizer()->Fit(this); |
95ba86d7 | 99 | GetSizer()->SetSizeHints(this); |
cc8bc5aa JS |
100 | if (centreFlags) |
101 | Centre(centreFlags); | |
b9a958e6 WS |
102 | #else |
103 | wxUnusedVar(centreFlags); | |
3c9287bb | 104 | #endif |
c9ab63f4 JS |
105 | #if defined(__SMARTPHONE__) |
106 | if (m_bookCtrl) | |
107 | m_bookCtrl->SetFocus(); | |
108 | #endif | |
3c9287bb JS |
109 | } |
110 | ||
111 | // Creates the buttons, if any | |
112 | void wxPropertySheetDialog::CreateButtons(int flags) | |
113 | { | |
897b24cf WS |
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->GetChildren().GetCount() > 0 ) | |
123 | { | |
124 | m_innerSizer->Add( buttonSizer, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxTOP|wxBOTTOM|wxLEFT|wxRIGHT, 2); | |
125 | m_innerSizer->AddSpacer(2); | |
126 | } | |
127 | else | |
128 | { | |
129 | delete buttonSizer; | |
130 | } | |
131 | ||
132 | #ifdef __POCKETPC__ | |
133 | // restore system option | |
134 | wxSystemOptions::SetOption(optionName,status); | |
3c9287bb JS |
135 | #endif |
136 | } | |
137 | ||
138 | // Creates the book control | |
139 | wxBookCtrlBase* wxPropertySheetDialog::CreateBookCtrl() | |
140 | { | |
895cc205 | 141 | int style = wxCLIP_CHILDREN | wxBK_DEFAULT; |
cc8bc5aa JS |
142 | |
143 | wxBookCtrlBase* bookCtrl = NULL; | |
93763ad5 | 144 | |
cc8bc5aa JS |
145 | #if wxUSE_NOTEBOOK |
146 | if (GetSheetStyle() & wxPROPSHEET_NOTEBOOK) | |
147 | bookCtrl = new wxNotebook(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, style ); | |
148 | #endif | |
149 | #if wxUSE_CHOICEBOOK | |
150 | if (GetSheetStyle() & wxPROPSHEET_CHOICEBOOK) | |
151 | bookCtrl = new wxChoicebook(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, style ); | |
152 | #endif | |
153 | #if wxUSE_TOOLBOOK | |
b887dc7b | 154 | #if defined(__WXMAC__) && wxUSE_TOOLBAR && wxUSE_BMPBUTTON |
64d3ed17 JS |
155 | if (GetSheetStyle() & wxPROPSHEET_BUTTONTOOLBOOK) |
156 | bookCtrl = new wxToolbook(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, style|wxBK_BUTTONBAR ); | |
157 | else | |
158 | #endif | |
159 | if ((GetSheetStyle() & wxPROPSHEET_TOOLBOOK) || (GetSheetStyle() & wxPROPSHEET_BUTTONTOOLBOOK)) | |
cc8bc5aa JS |
160 | bookCtrl = new wxToolbook(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, style ); |
161 | #endif | |
162 | #if wxUSE_LISTBOOK | |
163 | if (GetSheetStyle() & wxPROPSHEET_LISTBOOK) | |
164 | bookCtrl = new wxListbook(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, style ); | |
6334d903 JS |
165 | #endif |
166 | #if wxUSE_TREEBOOK | |
167 | if (GetSheetStyle() & wxPROPSHEET_TREEBOOK) | |
168 | bookCtrl = new wxTreebook(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, style ); | |
cc8bc5aa JS |
169 | #endif |
170 | if (!bookCtrl) | |
171 | bookCtrl = new wxBookCtrl(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, style ); | |
93763ad5 | 172 | |
cc8bc5aa | 173 | if (GetSheetStyle() & wxPROPSHEET_SHRINKTOFIT) |
da817fa6 | 174 | bookCtrl->SetFitToCurrentPage(true); |
93763ad5 | 175 | |
cc8bc5aa | 176 | return bookCtrl; |
3c9287bb JS |
177 | } |
178 | ||
179 | // Adds the book control to the inner sizer. | |
180 | void wxPropertySheetDialog::AddBookCtrl(wxSizer* sizer) | |
181 | { | |
3be8026d | 182 | #if defined(__POCKETPC__) && wxUSE_NOTEBOOK |
3c9287bb JS |
183 | // The book control has to be sized larger than the dialog because of a border bug |
184 | // in WinCE | |
0906c58d JS |
185 | int borderSize = -2; |
186 | sizer->Add( m_bookCtrl, 1, wxGROW|wxALIGN_CENTER_VERTICAL|wxLEFT|wxTOP|wxRIGHT, borderSize ); | |
3c9287bb | 187 | #else |
1a1190b2 | 188 | sizer->Add( m_bookCtrl, 1, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, m_sheetInnerBorder ); |
3c9287bb JS |
189 | #endif |
190 | } | |
191 | ||
c9ab63f4 JS |
192 | void wxPropertySheetDialog::OnActivate(wxActivateEvent& event) |
193 | { | |
194 | #if defined(__SMARTPHONE__) | |
195 | // Attempt to focus the choice control: not yet working, but might | |
196 | // be a step in the right direction. OnActivate overrides the default | |
197 | // handler in toplevel.cpp that sets the focus for the first child of | |
198 | // of the dialog (the choicebook). | |
199 | if (event.GetActive()) | |
200 | { | |
532d575b | 201 | wxChoicebook* choiceBook = wxDynamicCast(GetBookCtrl(), wxChoicebook); |
c9ab63f4 JS |
202 | if (choiceBook) |
203 | choiceBook->SetFocus(); | |
204 | } | |
205 | else | |
206 | #endif | |
207 | event.Skip(); | |
208 | } | |
209 | ||
cc8bc5aa JS |
210 | // Resize dialog if necessary |
211 | void wxPropertySheetDialog::OnIdle(wxIdleEvent& event) | |
212 | { | |
213 | event.Skip(); | |
93763ad5 | 214 | |
cc8bc5aa JS |
215 | if ((GetSheetStyle() & wxPROPSHEET_SHRINKTOFIT) && GetBookCtrl()) |
216 | { | |
217 | int sel = GetBookCtrl()->GetSelection(); | |
218 | if (sel != -1 && sel != m_selectedPage) | |
219 | { | |
220 | GetBookCtrl()->InvalidateBestSize(); | |
221 | InvalidateBestSize(); | |
222 | SetSizeHints(-1, -1, -1, -1); | |
223 | ||
224 | m_selectedPage = sel; | |
225 | LayoutDialog(0); | |
226 | } | |
227 | } | |
228 | } | |
229 | ||
532d575b | 230 | #endif // wxUSE_BOOKCTRL |