1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/generic/propdlg.cpp
3 // Purpose: wxPropertySheetDialog
4 // Author: Julian Smart
7 // Copyright: (c) Julian Smart
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 // For compilers that support precompilation, includes "wx.h".
12 #include "wx/wxprec.h"
21 #include "wx/button.h"
25 #include "wx/msgdlg.h"
28 #include "wx/bookctrl.h"
31 #include "wx/notebook.h"
34 #include "wx/choicebk.h"
37 #include "wx/toolbook.h"
40 #include "wx/listbook.h"
43 #include "wx/treebook.h"
46 #include "wx/generic/propdlg.h"
47 #include "wx/sysopt.h"
49 //-----------------------------------------------------------------------------
50 // wxPropertySheetDialog
51 //-----------------------------------------------------------------------------
53 IMPLEMENT_DYNAMIC_CLASS(wxPropertySheetDialog
, wxDialog
)
55 BEGIN_EVENT_TABLE(wxPropertySheetDialog
, wxDialog
)
56 EVT_ACTIVATE(wxPropertySheetDialog::OnActivate
)
57 EVT_IDLE(wxPropertySheetDialog::OnIdle
)
60 bool wxPropertySheetDialog::Create(wxWindow
* parent
, wxWindowID id
, const wxString
& title
,
61 const wxPoint
& pos
, const wxSize
& sz
, long style
,
64 parent
= GetParentForModalDialog(parent
, style
);
66 if (!wxDialog::Create(parent
, id
, title
, pos
, sz
, style
|wxCLIP_CHILDREN
, name
))
69 wxBoxSizer
*topSizer
= new wxBoxSizer( wxVERTICAL
);
72 // This gives more space around the edges
73 m_innerSizer
= new wxBoxSizer( wxVERTICAL
);
75 #if defined(__SMARTPHONE__) || defined(__POCKETPC__)
76 m_sheetOuterBorder
= 0;
78 topSizer
->Add(m_innerSizer
, 1, wxGROW
|wxALL
, m_sheetOuterBorder
);
80 m_bookCtrl
= CreateBookCtrl();
81 AddBookCtrl(m_innerSizer
);
86 void wxPropertySheetDialog::Init()
88 m_sheetStyle
= wxPROPSHEET_DEFAULT
;
91 m_sheetOuterBorder
= 2;
92 m_sheetInnerBorder
= 5;
95 // Layout the dialog, to be called after pages have been created
96 void wxPropertySheetDialog::LayoutDialog(int centreFlags
)
98 #if !defined(__SMARTPHONE__) && !defined(__POCKETPC__)
99 GetSizer()->Fit(this);
100 GetSizer()->SetSizeHints(this);
104 wxUnusedVar(centreFlags
);
106 #if defined(__SMARTPHONE__)
108 m_bookCtrl
->SetFocus();
112 // Creates the buttons, if any
113 void wxPropertySheetDialog::CreateButtons(int flags
)
116 // keep system option status
117 const wxChar
*optionName
= wxT("wince.dialog.real-ok-cancel");
118 const int status
= wxSystemOptions::GetOptionInt(optionName
);
119 wxSystemOptions::SetOption(optionName
,0);
122 wxSizer
*buttonSizer
= CreateButtonSizer(flags
);
125 m_innerSizer
->Add( buttonSizer
, 0, wxGROW
|wxALIGN_CENTER_VERTICAL
|wxTOP
|wxBOTTOM
|wxLEFT
|wxRIGHT
, 2);
126 m_innerSizer
->AddSpacer(2);
130 // restore system option
131 wxSystemOptions::SetOption(optionName
,status
);
135 // Creates the book control
136 wxBookCtrlBase
* wxPropertySheetDialog::CreateBookCtrl()
138 int style
= wxCLIP_CHILDREN
| wxBK_DEFAULT
;
140 wxBookCtrlBase
* bookCtrl
= NULL
;
143 if (GetSheetStyle() & wxPROPSHEET_NOTEBOOK
)
144 bookCtrl
= new wxNotebook(this, wxID_ANY
, wxDefaultPosition
, wxDefaultSize
, style
);
147 if (GetSheetStyle() & wxPROPSHEET_CHOICEBOOK
)
148 bookCtrl
= new wxChoicebook(this, wxID_ANY
, wxDefaultPosition
, wxDefaultSize
, style
);
151 #if defined(__WXMAC__) && wxUSE_TOOLBAR && wxUSE_BMPBUTTON
152 if (GetSheetStyle() & wxPROPSHEET_BUTTONTOOLBOOK
)
153 bookCtrl
= new wxToolbook(this, wxID_ANY
, wxDefaultPosition
, wxDefaultSize
, style
|wxTBK_BUTTONBAR
);
156 if ((GetSheetStyle() & wxPROPSHEET_TOOLBOOK
) || (GetSheetStyle() & wxPROPSHEET_BUTTONTOOLBOOK
))
157 bookCtrl
= new wxToolbook(this, wxID_ANY
, wxDefaultPosition
, wxDefaultSize
, style
);
160 if (GetSheetStyle() & wxPROPSHEET_LISTBOOK
)
161 bookCtrl
= new wxListbook(this, wxID_ANY
, wxDefaultPosition
, wxDefaultSize
, style
);
164 if (GetSheetStyle() & wxPROPSHEET_TREEBOOK
)
165 bookCtrl
= new wxTreebook(this, wxID_ANY
, wxDefaultPosition
, wxDefaultSize
, style
);
168 bookCtrl
= new wxBookCtrl(this, wxID_ANY
, wxDefaultPosition
, wxDefaultSize
, style
);
170 if (GetSheetStyle() & wxPROPSHEET_SHRINKTOFIT
)
171 bookCtrl
->SetFitToCurrentPage(true);
176 // Adds the book control to the inner sizer.
177 void wxPropertySheetDialog::AddBookCtrl(wxSizer
* sizer
)
179 #if defined(__POCKETPC__) && wxUSE_NOTEBOOK
180 // The book control has to be sized larger than the dialog because of a border bug
183 sizer
->Add( m_bookCtrl
, 1, wxGROW
|wxALIGN_CENTER_VERTICAL
|wxLEFT
|wxTOP
|wxRIGHT
, borderSize
);
185 sizer
->Add( m_bookCtrl
, 1, wxGROW
|wxALIGN_CENTER_VERTICAL
|wxALL
, m_sheetInnerBorder
);
189 void wxPropertySheetDialog::OnActivate(wxActivateEvent
& event
)
191 #if defined(__SMARTPHONE__)
192 // Attempt to focus the choice control: not yet working, but might
193 // be a step in the right direction. OnActivate overrides the default
194 // handler in toplevel.cpp that sets the focus for the first child of
195 // of the dialog (the choicebook).
196 if (event
.GetActive())
198 wxChoicebook
* choiceBook
= wxDynamicCast(GetBookCtrl(), wxChoicebook
);
200 choiceBook
->SetFocus();
207 // Resize dialog if necessary
208 void wxPropertySheetDialog::OnIdle(wxIdleEvent
& event
)
212 if ((GetSheetStyle() & wxPROPSHEET_SHRINKTOFIT
) && GetBookCtrl())
214 int sel
= GetBookCtrl()->GetSelection();
215 if (sel
!= -1 && sel
!= m_selectedPage
)
217 GetBookCtrl()->InvalidateBestSize();
218 InvalidateBestSize();
219 SetSizeHints(-1, -1, -1, -1);
221 m_selectedPage
= sel
;
227 // Override function in base
228 wxWindow
* wxPropertySheetDialog::GetContentWindow() const
230 return GetBookCtrl();
233 #endif // wxUSE_BOOKCTRL