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/generic/propdlg.h"
45 #include "wx/sysopt.h"
47 //-----------------------------------------------------------------------------
48 // wxPropertySheetDialog
49 //-----------------------------------------------------------------------------
51 IMPLEMENT_DYNAMIC_CLASS(wxPropertySheetDialog
, wxDialog
)
53 BEGIN_EVENT_TABLE(wxPropertySheetDialog
, wxDialog
)
54 EVT_ACTIVATE(wxPropertySheetDialog::OnActivate
)
55 EVT_IDLE(wxPropertySheetDialog::OnIdle
)
58 bool wxPropertySheetDialog::Create(wxWindow
* parent
, wxWindowID id
, const wxString
& title
,
59 const wxPoint
& pos
, const wxSize
& sz
, long style
,
62 if (!wxDialog::Create(parent
, id
, title
, pos
, sz
, style
|wxCLIP_CHILDREN
, name
))
65 wxBoxSizer
*topSizer
= new wxBoxSizer( wxVERTICAL
);
68 // This gives more space around the edges
69 m_innerSizer
= new wxBoxSizer( wxVERTICAL
);
71 #if defined(__SMARTPHONE__) || defined(__POCKETPC__)
72 m_sheetOuterBorder
= 0;
74 topSizer
->Add(m_innerSizer
, 1, wxGROW
|wxALL
, m_sheetOuterBorder
);
76 m_bookCtrl
= CreateBookCtrl();
77 AddBookCtrl(m_innerSizer
);
82 void wxPropertySheetDialog::Init()
84 m_sheetStyle
= wxPROPSHEET_DEFAULT
;
87 m_sheetOuterBorder
= 2;
88 m_sheetInnerBorder
= 5;
91 // Layout the dialog, to be called after pages have been created
92 void wxPropertySheetDialog::LayoutDialog(int centreFlags
)
94 #if !defined(__SMARTPHONE__) && !defined(__POCKETPC__)
95 GetSizer()->Fit(this);
96 GetSizer()->SetSizeHints(this);
100 wxUnusedVar(centreFlags
);
102 #if defined(__SMARTPHONE__)
104 m_bookCtrl
->SetFocus();
108 // Creates the buttons, if any
109 void wxPropertySheetDialog::CreateButtons(int flags
)
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);
118 wxSizer
*buttonSizer
= CreateButtonSizer( flags
& ButtonSizerFlags
);
119 if(buttonSizer
->GetChildren().GetCount() > 0 )
121 m_innerSizer
->Add( buttonSizer
, 0, wxGROW
|wxALIGN_CENTER_VERTICAL
|wxTOP
|wxBOTTOM
|wxLEFT
|wxRIGHT
, 2);
122 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
;
139 #if defined(__POCKETPC__) && wxUSE_NOTEBOOK
140 style
|= wxBK_BOTTOM
|wxNB_FLAT
;
142 style
|= wxBK_DEFAULT
;
145 wxBookCtrlBase
* bookCtrl
= NULL
;
148 if (GetSheetStyle() & wxPROPSHEET_NOTEBOOK
)
149 bookCtrl
= new wxNotebook(this, wxID_ANY
, wxDefaultPosition
, wxDefaultSize
, style
);
152 if (GetSheetStyle() & wxPROPSHEET_CHOICEBOOK
)
153 bookCtrl
= new wxChoicebook(this, wxID_ANY
, wxDefaultPosition
, wxDefaultSize
, style
);
156 #if defined(__WXMAC__) && wxUSE_TOOLBAR && wxUSE_BMPBUTTON
157 if (GetSheetStyle() & wxPROPSHEET_BUTTONTOOLBOOK
)
158 bookCtrl
= new wxToolbook(this, wxID_ANY
, wxDefaultPosition
, wxDefaultSize
, style
|wxBK_BUTTONBAR
);
161 if ((GetSheetStyle() & wxPROPSHEET_TOOLBOOK
) || (GetSheetStyle() & wxPROPSHEET_BUTTONTOOLBOOK
))
162 bookCtrl
= new wxToolbook(this, wxID_ANY
, wxDefaultPosition
, wxDefaultSize
, style
);
165 if (GetSheetStyle() & wxPROPSHEET_LISTBOOK
)
166 bookCtrl
= new wxListbook(this, wxID_ANY
, wxDefaultPosition
, wxDefaultSize
, style
);
169 bookCtrl
= new wxBookCtrl(this, wxID_ANY
, wxDefaultPosition
, wxDefaultSize
, style
);
171 if (GetSheetStyle() & wxPROPSHEET_SHRINKTOFIT
)
172 bookCtrl
->SetFitToCurrentPage(true);
177 // Adds the book control to the inner sizer.
178 void wxPropertySheetDialog::AddBookCtrl(wxSizer
* sizer
)
180 #if defined(__POCKETPC__) && wxUSE_NOTEBOOK
181 // The book control has to be sized larger than the dialog because of a border bug
184 sizer
->Add( m_bookCtrl
, 1, wxGROW
|wxALIGN_CENTER_VERTICAL
|wxLEFT
|wxTOP
|wxRIGHT
, borderSize
);
186 sizer
->Add( m_bookCtrl
, 1, wxGROW
|wxALIGN_CENTER_VERTICAL
|wxALL
, m_sheetInnerBorder
);
190 void wxPropertySheetDialog::OnActivate(wxActivateEvent
& event
)
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())
199 wxChoicebook
* choiceBook
= wxDynamicCast(GetBookCtrl(), wxChoicebook
);
201 choiceBook
->SetFocus();
208 // Resize dialog if necessary
209 void wxPropertySheetDialog::OnIdle(wxIdleEvent
& event
)
213 if ((GetSheetStyle() & wxPROPSHEET_SHRINKTOFIT
) && GetBookCtrl())
215 int sel
= GetBookCtrl()->GetSelection();
216 if (sel
!= -1 && sel
!= m_selectedPage
)
218 GetBookCtrl()->InvalidateBestSize();
219 InvalidateBestSize();
220 SetSizeHints(-1, -1, -1, -1);
222 m_selectedPage
= sel
;
228 #endif // wxUSE_BOOKCTRL