1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/generic/propdlg.cpp
3 // Purpose: wxPropertySheetDialog
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
22 #include "wx/button.h"
26 #include "wx/msgdlg.h"
29 #include "wx/bookctrl.h"
32 #include "wx/notebook.h"
35 #include "wx/choicebk.h"
38 #include "wx/toolbook.h"
41 #include "wx/listbook.h"
44 #include "wx/treebook.h"
47 #include "wx/generic/propdlg.h"
48 #include "wx/sysopt.h"
50 //-----------------------------------------------------------------------------
51 // wxPropertySheetDialog
52 //-----------------------------------------------------------------------------
54 IMPLEMENT_DYNAMIC_CLASS(wxPropertySheetDialog
, wxDialog
)
56 BEGIN_EVENT_TABLE(wxPropertySheetDialog
, wxDialog
)
57 EVT_ACTIVATE(wxPropertySheetDialog::OnActivate
)
58 EVT_IDLE(wxPropertySheetDialog::OnIdle
)
61 bool wxPropertySheetDialog::Create(wxWindow
* parent
, wxWindowID id
, const wxString
& title
,
62 const wxPoint
& pos
, const wxSize
& sz
, long style
,
65 if (!wxDialog::Create(parent
, id
, title
, pos
, sz
, style
|wxCLIP_CHILDREN
, name
))
68 wxBoxSizer
*topSizer
= new wxBoxSizer( wxVERTICAL
);
71 // This gives more space around the edges
72 m_innerSizer
= new wxBoxSizer( wxVERTICAL
);
74 #if defined(__SMARTPHONE__) || defined(__POCKETPC__)
75 m_sheetOuterBorder
= 0;
77 topSizer
->Add(m_innerSizer
, 1, wxGROW
|wxALL
, m_sheetOuterBorder
);
79 m_bookCtrl
= CreateBookCtrl();
80 AddBookCtrl(m_innerSizer
);
85 void wxPropertySheetDialog::Init()
87 m_sheetStyle
= wxPROPSHEET_DEFAULT
;
90 m_sheetOuterBorder
= 2;
91 m_sheetInnerBorder
= 5;
94 // Layout the dialog, to be called after pages have been created
95 void wxPropertySheetDialog::LayoutDialog(int centreFlags
)
97 #if !defined(__SMARTPHONE__) && !defined(__POCKETPC__)
98 GetSizer()->Fit(this);
99 GetSizer()->SetSizeHints(this);
103 wxUnusedVar(centreFlags
);
105 #if defined(__SMARTPHONE__)
107 m_bookCtrl
->SetFocus();
111 // Creates the buttons, if any
112 void wxPropertySheetDialog::CreateButtons(int flags
)
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);
121 wxSizer
*buttonSizer
= CreateButtonSizer( flags
& ButtonSizerFlags
);
122 if(buttonSizer
->GetChildren().GetCount() > 0 )
124 m_innerSizer
->Add( buttonSizer
, 0, wxGROW
|wxALIGN_CENTER_VERTICAL
|wxTOP
|wxBOTTOM
|wxLEFT
|wxRIGHT
, 2);
125 m_innerSizer
->AddSpacer(2);
133 // restore system option
134 wxSystemOptions::SetOption(optionName
,status
);
138 // Creates the book control
139 wxBookCtrlBase
* wxPropertySheetDialog::CreateBookCtrl()
141 int style
= wxCLIP_CHILDREN
| wxBK_DEFAULT
;
143 wxBookCtrlBase
* bookCtrl
= NULL
;
146 if (GetSheetStyle() & wxPROPSHEET_NOTEBOOK
)
147 bookCtrl
= new wxNotebook(this, wxID_ANY
, wxDefaultPosition
, wxDefaultSize
, style
);
150 if (GetSheetStyle() & wxPROPSHEET_CHOICEBOOK
)
151 bookCtrl
= new wxChoicebook(this, wxID_ANY
, wxDefaultPosition
, wxDefaultSize
, style
);
154 #if defined(__WXMAC__) && wxUSE_TOOLBAR && wxUSE_BMPBUTTON
155 if (GetSheetStyle() & wxPROPSHEET_BUTTONTOOLBOOK
)
156 bookCtrl
= new wxToolbook(this, wxID_ANY
, wxDefaultPosition
, wxDefaultSize
, style
|wxBK_BUTTONBAR
);
159 if ((GetSheetStyle() & wxPROPSHEET_TOOLBOOK
) || (GetSheetStyle() & wxPROPSHEET_BUTTONTOOLBOOK
))
160 bookCtrl
= new wxToolbook(this, wxID_ANY
, wxDefaultPosition
, wxDefaultSize
, style
);
163 if (GetSheetStyle() & wxPROPSHEET_LISTBOOK
)
164 bookCtrl
= new wxListbook(this, wxID_ANY
, wxDefaultPosition
, wxDefaultSize
, style
);
167 if (GetSheetStyle() & wxPROPSHEET_TREEBOOK
)
168 bookCtrl
= new wxTreebook(this, wxID_ANY
, wxDefaultPosition
, wxDefaultSize
, style
);
171 bookCtrl
= new wxBookCtrl(this, wxID_ANY
, wxDefaultPosition
, wxDefaultSize
, style
);
173 if (GetSheetStyle() & wxPROPSHEET_SHRINKTOFIT
)
174 bookCtrl
->SetFitToCurrentPage(true);
179 // Adds the book control to the inner sizer.
180 void wxPropertySheetDialog::AddBookCtrl(wxSizer
* sizer
)
182 #if defined(__POCKETPC__) && wxUSE_NOTEBOOK
183 // The book control has to be sized larger than the dialog because of a border bug
186 sizer
->Add( m_bookCtrl
, 1, wxGROW
|wxALIGN_CENTER_VERTICAL
|wxLEFT
|wxTOP
|wxRIGHT
, borderSize
);
188 sizer
->Add( m_bookCtrl
, 1, wxGROW
|wxALIGN_CENTER_VERTICAL
|wxALL
, m_sheetInnerBorder
);
192 void wxPropertySheetDialog::OnActivate(wxActivateEvent
& event
)
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())
201 wxChoicebook
* choiceBook
= wxDynamicCast(GetBookCtrl(), wxChoicebook
);
203 choiceBook
->SetFocus();
210 // Resize dialog if necessary
211 void wxPropertySheetDialog::OnIdle(wxIdleEvent
& event
)
215 if ((GetSheetStyle() & wxPROPSHEET_SHRINKTOFIT
) && GetBookCtrl())
217 int sel
= GetBookCtrl()->GetSelection();
218 if (sel
!= -1 && sel
!= m_selectedPage
)
220 GetBookCtrl()->InvalidateBestSize();
221 InvalidateBestSize();
222 SetSizeHints(-1, -1, -1, -1);
224 m_selectedPage
= sel
;
230 #endif // wxUSE_BOOKCTRL