]>
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 | |
43 | ||
3c9287bb | 44 | #include "wx/generic/propdlg.h" |
897b24cf | 45 | #include "wx/sysopt.h" |
3c9287bb JS |
46 | |
47 | //----------------------------------------------------------------------------- | |
48 | // wxPropertySheetDialog | |
49 | //----------------------------------------------------------------------------- | |
50 | ||
51 | IMPLEMENT_DYNAMIC_CLASS(wxPropertySheetDialog, wxDialog) | |
52 | ||
c9ab63f4 JS |
53 | BEGIN_EVENT_TABLE(wxPropertySheetDialog, wxDialog) |
54 | EVT_ACTIVATE(wxPropertySheetDialog::OnActivate) | |
cc8bc5aa | 55 | EVT_IDLE(wxPropertySheetDialog::OnIdle) |
c9ab63f4 JS |
56 | END_EVENT_TABLE() |
57 | ||
532d575b | 58 | bool wxPropertySheetDialog::Create(wxWindow* parent, wxWindowID id, const wxString& title, |
3c9287bb JS |
59 | const wxPoint& pos, const wxSize& sz, long style, |
60 | const wxString& name) | |
61 | { | |
ac5f5c9e | 62 | if (!wxDialog::Create(parent, id, title, pos, sz, style|wxCLIP_CHILDREN, name)) |
3c9287bb | 63 | return false; |
532d575b | 64 | |
3c9287bb JS |
65 | wxBoxSizer *topSizer = new wxBoxSizer( wxVERTICAL ); |
66 | SetSizer(topSizer); | |
67 | ||
68 | // This gives more space around the edges | |
69 | m_innerSizer = new wxBoxSizer( wxVERTICAL ); | |
70 | ||
0906c58d | 71 | #if defined(__SMARTPHONE__) || defined(__POCKETPC__) |
1a1190b2 | 72 | m_sheetOuterBorder = 0; |
3c9287bb | 73 | #endif |
1a1190b2 | 74 | topSizer->Add(m_innerSizer, 1, wxGROW|wxALL, m_sheetOuterBorder); |
3c9287bb JS |
75 | |
76 | m_bookCtrl = CreateBookCtrl(); | |
77 | AddBookCtrl(m_innerSizer); | |
78 | ||
79 | return true; | |
80 | } | |
81 | ||
82 | void wxPropertySheetDialog::Init() | |
83 | { | |
cc8bc5aa | 84 | m_sheetStyle = wxPROPSHEET_DEFAULT; |
3c9287bb JS |
85 | m_innerSizer = NULL; |
86 | m_bookCtrl = NULL; | |
1a1190b2 JS |
87 | m_sheetOuterBorder = 2; |
88 | m_sheetInnerBorder = 5; | |
3c9287bb JS |
89 | } |
90 | ||
91 | // Layout the dialog, to be called after pages have been created | |
cc8bc5aa | 92 | void wxPropertySheetDialog::LayoutDialog(int centreFlags) |
3c9287bb | 93 | { |
0906c58d | 94 | #if !defined(__SMARTPHONE__) && !defined(__POCKETPC__) |
3c9287bb | 95 | GetSizer()->Fit(this); |
95ba86d7 | 96 | GetSizer()->SetSizeHints(this); |
cc8bc5aa JS |
97 | if (centreFlags) |
98 | Centre(centreFlags); | |
b9a958e6 WS |
99 | #else |
100 | wxUnusedVar(centreFlags); | |
3c9287bb | 101 | #endif |
c9ab63f4 JS |
102 | #if defined(__SMARTPHONE__) |
103 | if (m_bookCtrl) | |
104 | m_bookCtrl->SetFocus(); | |
105 | #endif | |
3c9287bb JS |
106 | } |
107 | ||
108 | // Creates the buttons, if any | |
109 | void wxPropertySheetDialog::CreateButtons(int flags) | |
110 | { | |
897b24cf WS |
111 | #ifdef __POCKETPC__ |
112 | // keep system option status | |
113 | const wxChar *optionName = wxT("wince.dialog.real-ok-cancel"); | |
114 | const int status = wxSystemOptions::GetOptionInt(optionName); | |
115 | wxSystemOptions::SetOption(optionName,0); | |
116 | #endif | |
117 | ||
118 | wxSizer *buttonSizer = CreateButtonSizer( flags & ButtonSizerFlags ); | |
119 | if(buttonSizer->GetChildren().GetCount() > 0 ) | |
120 | { | |
121 | m_innerSizer->Add( buttonSizer, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxTOP|wxBOTTOM|wxLEFT|wxRIGHT, 2); | |
122 | m_innerSizer->AddSpacer(2); | |
123 | } | |
124 | else | |
125 | { | |
126 | delete buttonSizer; | |
127 | } | |
128 | ||
129 | #ifdef __POCKETPC__ | |
130 | // restore system option | |
131 | wxSystemOptions::SetOption(optionName,status); | |
3c9287bb JS |
132 | #endif |
133 | } | |
134 | ||
135 | // Creates the book control | |
136 | wxBookCtrlBase* wxPropertySheetDialog::CreateBookCtrl() | |
137 | { | |
ac5f5c9e | 138 | int style = wxCLIP_CHILDREN; |
3be8026d | 139 | #if defined(__POCKETPC__) && wxUSE_NOTEBOOK |
2ddb4d13 | 140 | style |= wxBK_BOTTOM|wxNB_FLAT; |
3be8026d | 141 | #else |
2ddb4d13 | 142 | style |= wxBK_DEFAULT; |
3c9287bb | 143 | #endif |
cc8bc5aa JS |
144 | |
145 | wxBookCtrlBase* bookCtrl = NULL; | |
93763ad5 | 146 | |
cc8bc5aa JS |
147 | #if wxUSE_NOTEBOOK |
148 | if (GetSheetStyle() & wxPROPSHEET_NOTEBOOK) | |
149 | bookCtrl = new wxNotebook(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, style ); | |
150 | #endif | |
151 | #if wxUSE_CHOICEBOOK | |
152 | if (GetSheetStyle() & wxPROPSHEET_CHOICEBOOK) | |
153 | bookCtrl = new wxChoicebook(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, style ); | |
154 | #endif | |
155 | #if wxUSE_TOOLBOOK | |
b887dc7b | 156 | #if defined(__WXMAC__) && wxUSE_TOOLBAR && wxUSE_BMPBUTTON |
64d3ed17 JS |
157 | if (GetSheetStyle() & wxPROPSHEET_BUTTONTOOLBOOK) |
158 | bookCtrl = new wxToolbook(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, style|wxBK_BUTTONBAR ); | |
159 | else | |
160 | #endif | |
161 | if ((GetSheetStyle() & wxPROPSHEET_TOOLBOOK) || (GetSheetStyle() & wxPROPSHEET_BUTTONTOOLBOOK)) | |
cc8bc5aa JS |
162 | bookCtrl = new wxToolbook(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, style ); |
163 | #endif | |
164 | #if wxUSE_LISTBOOK | |
165 | if (GetSheetStyle() & wxPROPSHEET_LISTBOOK) | |
166 | bookCtrl = new wxListbook(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, style ); | |
167 | #endif | |
168 | if (!bookCtrl) | |
169 | bookCtrl = new wxBookCtrl(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, style ); | |
93763ad5 | 170 | |
cc8bc5aa | 171 | if (GetSheetStyle() & wxPROPSHEET_SHRINKTOFIT) |
da817fa6 | 172 | bookCtrl->SetFitToCurrentPage(true); |
93763ad5 | 173 | |
cc8bc5aa | 174 | return bookCtrl; |
3c9287bb JS |
175 | } |
176 | ||
177 | // Adds the book control to the inner sizer. | |
178 | void wxPropertySheetDialog::AddBookCtrl(wxSizer* sizer) | |
179 | { | |
3be8026d | 180 | #if defined(__POCKETPC__) && wxUSE_NOTEBOOK |
3c9287bb JS |
181 | // The book control has to be sized larger than the dialog because of a border bug |
182 | // in WinCE | |
0906c58d JS |
183 | int borderSize = -2; |
184 | sizer->Add( m_bookCtrl, 1, wxGROW|wxALIGN_CENTER_VERTICAL|wxLEFT|wxTOP|wxRIGHT, borderSize ); | |
3c9287bb | 185 | #else |
1a1190b2 | 186 | sizer->Add( m_bookCtrl, 1, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, m_sheetInnerBorder ); |
3c9287bb JS |
187 | #endif |
188 | } | |
189 | ||
c9ab63f4 JS |
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 | { | |
532d575b | 199 | wxChoicebook* choiceBook = wxDynamicCast(GetBookCtrl(), wxChoicebook); |
c9ab63f4 JS |
200 | if (choiceBook) |
201 | choiceBook->SetFocus(); | |
202 | } | |
203 | else | |
204 | #endif | |
205 | event.Skip(); | |
206 | } | |
207 | ||
cc8bc5aa JS |
208 | // Resize dialog if necessary |
209 | void wxPropertySheetDialog::OnIdle(wxIdleEvent& event) | |
210 | { | |
211 | event.Skip(); | |
93763ad5 | 212 | |
cc8bc5aa JS |
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 | ||
532d575b | 228 | #endif // wxUSE_BOOKCTRL |