diff --git a/docs/changes.txt b/docs/changes.txt index 831b7b0c17..bea540b67d 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -73,6 +73,8 @@ All (GUI): with BEGIN_EVENT_TABLE_TEMPLATEn() macros - Added double-buffering to wxVListBox and fixed a scrolling issue. - Added wxToolbook (uses a wxToolBar to control pages). +- Added SetSheetStyle to wxPropertySheetDialog and allowed it to + behave like a Mac OS X settings dialog. wxMSW: diff --git a/docs/latex/wx/propdlg.tex b/docs/latex/wx/propdlg.tex index a7e3c42800..83b9f421f3 100644 --- a/docs/latex/wx/propdlg.tex +++ b/docs/latex/wx/propdlg.tex @@ -1,8 +1,9 @@ \section{\class{wxPropertySheetDialog}}\label{wxpropertysheetdialog} This class represents a property sheet dialog: a tabbed dialog -for showing settings. It is optimized to show with flat tabs -on PocketPC devices. +for showing settings. It is optimized to show flat tabs +on PocketPC devices, and can be customized to use different +controllers instead of the default notebook style. To use this class, call \helpref{wxPropertySheetDialog::Create}{wxpropertysheetdialogcreate} from your own Create function. Then call \helpref{CreateButtons}{wxpropertysheetdialogcreatebuttons}, and create pages, adding them to the book control. @@ -29,6 +30,11 @@ bool MyPropertySheetDialog::Create(...) If necessary, override CreateBookCtrl and AddBookCtrl to create and add a different kind of book control. You would then need to use two-step construction for the dialog. +Or, change the style of book control by calling \helpref{SetSheetStyle}{wxpropertysheetdialogsetsheetstyle} +before calling Create. + +The dialogs sample shows this class being used with notebook and toolbook controllers (for +Windows-style and Mac-style settings dialogs). \wxheading{Derived from} @@ -77,8 +83,9 @@ Call this from your own Create function, before adding buttons and pages. \func{virtual wxBookCtrlBase*}{CreateBookCtrl}{\void} -Override this if you wish to create a different kind of book control; by default, a wxNotebook -is created. +Override this if you wish to create a different kind of book control; by default, the value +passed to \helpref{SetSheetStyle}{wxpropertysheetdialogsetsheetstyle} is used to determine the control. +The default behaviour is to create a notebook except on Smartphone, where a choicebook is used. \membersection{wxPropertySheetDialog::CreateButtons}\label{wxpropertysheetdialogcreatebuttons} @@ -99,9 +106,16 @@ Returns the book control that will contain your settings pages. Returns the inner sizer that contains the book control and button sizer. +\membersection{wxPropertySheetDialog::GetSheetStyle}\label{wxpropertysheetdialoggetsheetstyle} + +\constfunc{long}{GetSheetStyle}{\void} + +Returns the sheet style. See \helpref{SetSheetStyle}{wxpropertysheetdialogsetsheetstyle} for +permissable values. + \membersection{wxPropertySheetDialog::LayoutDialog}\label{wxpropertysheetdialoglayoutdialog} -\func{void}{LayoutDialog}{\void} +\func{void}{LayoutDialog}{\param{int}{ centreFlags=wxBOTH}} Call this to lay out the dialog. On PocketPC, this does nothing, since the dialog will be shown full-screen, and the layout will be done when the dialog receives a size event. @@ -118,3 +132,22 @@ Sets the book control used for the dialog. You will normally not need to use thi Sets the inner sizer that contains the book control and button sizer. You will normally not need to use this. +\membersection{wxPropertySheetDialog::SetSheetStyle}\label{wxpropertysheetdialogsetsheetstyle} + +\func{void}{SetSheetStyle}{\param{long}{ style}} + +You can customize the look and feel of the dialog by setting the sheet style. It is +a bit list of the following values: + +\twocolwidtha{5cm} +\begin{twocollist}\itemsep=0pt +\twocolitem{wxPROPSHEET\_DEFAULT}{Uses the default look and feel for the controller window, +normally a notebook except on Smartphone where a choice control is used.} +\twocolitem{wxPROPSHEET\_NOTEBOOK}{Uses a notebook for the controller window.} +\twocolitem{wxPROPSHEET\_TOOLBOOK}{Uses a toolbook for the controller window.} +\twocolitem{wxPROPSHEET\_CHOICEBOOK}{Uses a choicebook for the controller window.} +\twocolitem{wxPROPSHEET\_LISTBOOK}{Uses a listbook for the controller window.} +\twocolitem{wxPROPSHEET\_SHRINKTOFIT}{Shrinks the dialog window to fit the currently selected page (common behaviour for +property sheets on Mac OS X).} +\end{twocollist} + diff --git a/include/wx/generic/propdlg.h b/include/wx/generic/propdlg.h index 8d168f32d5..6ecb9ec47c 100644 --- a/include/wx/generic/propdlg.h +++ b/include/wx/generic/propdlg.h @@ -48,6 +48,24 @@ class WXDLLEXPORT wxBookCtrlBase; // kind of book control. //----------------------------------------------------------------------------- +// Use the platform default +#define wxPROPSHEET_DEFAULT 0x0001 + +// Use a notebook +#define wxPROPSHEET_NOTEBOOK 0x0002 + +// Use a toolbook +#define wxPROPSHEET_TOOLBOOK 0x0004 + +// Use a choicebook +#define wxPROPSHEET_CHOICEBOOK 0x0008 + +// Use a listbook +#define wxPROPSHEET_LISTBOOK 0x0010 + +// Shrink dialog to fit current page +#define wxPROPSHEET_SHRINKTOFIT 0x0100 + class WXDLLIMPEXP_ADV wxPropertySheetDialog : public wxDialog { public: @@ -81,13 +99,17 @@ public: void SetInnerSize(wxSizer* sizer) { m_innerSizer = sizer; } wxSizer* GetInnerSizer() const { return m_innerSizer ; } + // Set and get the book style + void SetSheetStyle(long sheetStyle) { m_sheetStyle = sheetStyle; } + long GetSheetStyle() const { return m_sheetStyle ; } + /// Operations // Creates the buttons (none on PocketPC) virtual void CreateButtons(int flags = wxOK|wxCANCEL); // Lay out the dialog, to be called after pages have been created - virtual void LayoutDialog(); + virtual void LayoutDialog(int centreFlags = wxBOTH); /// Implementation @@ -101,12 +123,17 @@ public: // Set the focus void OnActivate(wxActivateEvent& event); + // Resize dialog if necessary + void OnIdle(wxIdleEvent& event); + private: void Init(); protected: wxBookCtrlBase* m_bookCtrl; wxSizer* m_innerSizer; // sizer for extra space + long m_sheetStyle; + int m_selectedPage; DECLARE_DYNAMIC_CLASS(wxPropertySheetDialog) DECLARE_EVENT_TABLE() diff --git a/samples/dialogs/dialogs.cpp b/samples/dialogs/dialogs.cpp index 9c4f7eba68..05fc07b510 100644 --- a/samples/dialogs/dialogs.cpp +++ b/samples/dialogs/dialogs.cpp @@ -25,6 +25,7 @@ #include "wx/datetime.h" #include "wx/image.h" #include "wx/bookctrl.h" +#include "wx/artprov.h" #if wxUSE_COLOURDLG #include "wx/colordlg.h" @@ -191,6 +192,7 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame) #if USE_SETTINGS_DIALOG EVT_MENU(DIALOGS_PROPERTY_SHEET, MyFrame::OnPropertySheet) + EVT_MENU(DIALOGS_PROPERTY_SHEET_TOOLBOOK, MyFrame::OnPropertySheetToolBook) #endif EVT_MENU(DIALOGS_REQUEST, MyFrame::OnRequestUserAttention) @@ -358,6 +360,7 @@ bool MyApp::OnInit() #if USE_SETTINGS_DIALOG file_menu->Append(DIALOGS_PROPERTY_SHEET, _T("&Property Sheet Dialog\tCtrl-P")); + file_menu->Append(DIALOGS_PROPERTY_SHEET_TOOLBOOK, _T("Property Sheet Dialog using &ToolBook")); #endif file_menu->Append(DIALOGS_REQUEST, _T("&Request user attention\tCtrl-R")); @@ -973,6 +976,12 @@ void MyFrame::OnPropertySheet(wxCommandEvent& WXUNUSED(event)) SettingsDialog dialog(this); dialog.ShowModal(); } + +void MyFrame::OnPropertySheetToolBook(wxCommandEvent& WXUNUSED(event)) +{ + SettingsDialog dialog(this, true); + dialog.ShowModal(); +} #endif // USE_SETTINGS_DIALOG void MyFrame::OnRequestUserAttention(wxCommandEvent& WXUNUSED(event)) @@ -1371,33 +1380,67 @@ IMPLEMENT_CLASS(SettingsDialog, wxPropertySheetDialog) BEGIN_EVENT_TABLE(SettingsDialog, wxPropertySheetDialog) END_EVENT_TABLE() -SettingsDialog::SettingsDialog(wxWindow* win) +SettingsDialog::SettingsDialog(wxWindow* win, bool useToolBook) { SetExtraStyle(wxDIALOG_EX_CONTEXTHELP|wxWS_EX_VALIDATE_RECURSIVELY); + int tabImage1 = -1; + int tabImage2 = -1; + + if (useToolBook) + { + tabImage1 = 0; + tabImage2 = 1; + SetSheetStyle(wxPROPSHEET_TOOLBOOK|wxPROPSHEET_SHRINKTOFIT); + + // create a dummy image list with a few icons + const wxSize imageSize(32, 32); + + m_imageList = new wxImageList(imageSize.GetWidth(), imageSize.GetHeight()); + m_imageList-> + Add(wxArtProvider::GetIcon(wxART_INFORMATION, wxART_OTHER, imageSize)); + m_imageList-> + Add(wxArtProvider::GetIcon(wxART_QUESTION, wxART_OTHER, imageSize)); + m_imageList-> + Add(wxArtProvider::GetIcon(wxART_WARNING, wxART_OTHER, imageSize)); + m_imageList-> + Add(wxArtProvider::GetIcon(wxART_ERROR, wxART_OTHER, imageSize)); + } + else + m_imageList = NULL; + Create(win, wxID_ANY, _("Preferences"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE #ifndef __WXWINCE__ |wxRESIZE_BORDER #endif ); - CreateButtons(wxOK|wxCANCEL + + // If using a toolbook, also follow Mac style and don't create buttons + if (!useToolBook) + CreateButtons(wxOK|wxCANCEL #ifndef __POCKETPC__ - |wxHELP + |wxHELP #endif ); wxBookCtrlBase* notebook = GetBookCtrl(); + notebook->SetImageList(m_imageList); wxPanel* generalSettings = CreateGeneralSettingsPage(notebook); wxPanel* aestheticSettings = CreateAestheticSettingsPage(notebook); - notebook->AddPage(generalSettings, _("General")); - notebook->AddPage(aestheticSettings, _("Aesthetics")); + notebook->AddPage(generalSettings, _("General"), true, tabImage1); + notebook->AddPage(aestheticSettings, _("Aesthetics"), false, tabImage2); LayoutDialog(); } +SettingsDialog::~SettingsDialog() +{ + delete m_imageList; +} + wxPanel* SettingsDialog::CreateGeneralSettingsPage(wxWindow* parent) { wxPanel* panel = new wxPanel(parent, wxID_ANY); diff --git a/samples/dialogs/dialogs.h b/samples/dialogs/dialogs.h index 79e8c49d69..0e76bc1230 100644 --- a/samples/dialogs/dialogs.h +++ b/samples/dialogs/dialogs.h @@ -142,7 +142,8 @@ class SettingsDialog: public wxPropertySheetDialog { DECLARE_CLASS(SettingsDialog) public: - SettingsDialog(wxWindow* parent); + SettingsDialog(wxWindow* parent, bool useToolBook = false); + ~SettingsDialog(); wxPanel* CreateGeneralSettingsPage(wxWindow* parent); wxPanel* CreateAestheticSettingsPage(wxWindow* parent); @@ -160,6 +161,8 @@ protected: ID_FONT_SIZE }; + wxImageList* m_imageList; + DECLARE_EVENT_TABLE() }; @@ -253,6 +256,7 @@ public: #endif // USE_FONTDLG_GENERIC void OnPropertySheet(wxCommandEvent& event); + void OnPropertySheetToolBook(wxCommandEvent& event); void OnRequestUserAttention(wxCommandEvent& event); void OnExit(wxCommandEvent& event); @@ -322,7 +326,8 @@ enum DIALOGS_FIND, DIALOGS_REPLACE, DIALOGS_REQUEST, - DIALOGS_PROPERTY_SHEET + DIALOGS_PROPERTY_SHEET, + DIALOGS_PROPERTY_SHEET_TOOLBOOK }; #endif diff --git a/src/generic/propdlg.cpp b/src/generic/propdlg.cpp index cc1fbc59c7..d82f8b889c 100644 --- a/src/generic/propdlg.cpp +++ b/src/generic/propdlg.cpp @@ -29,6 +29,20 @@ #endif #include "wx/bookctrl.h" + +#if wxUSE_NOTEBOOK +#include "wx/notebook.h" +#endif +#if wxUSE_CHOICEBOOK +#include "wx/choicebk.h" +#endif +#if wxUSE_TOOLBOOK +#include "wx/toolbook.h" +#endif +#if wxUSE_LISTBOOK +#include "wx/listbook.h" +#endif + #include "wx/generic/propdlg.h" #include "wx/sysopt.h" @@ -40,6 +54,7 @@ IMPLEMENT_DYNAMIC_CLASS(wxPropertySheetDialog, wxDialog) BEGIN_EVENT_TABLE(wxPropertySheetDialog, wxDialog) EVT_ACTIVATE(wxPropertySheetDialog::OnActivate) + EVT_IDLE(wxPropertySheetDialog::OnIdle) END_EVENT_TABLE() bool wxPropertySheetDialog::Create(wxWindow* parent, wxWindowID id, const wxString& title, @@ -69,17 +84,19 @@ bool wxPropertySheetDialog::Create(wxWindow* parent, wxWindowID id, const wxStri void wxPropertySheetDialog::Init() { + m_sheetStyle = wxPROPSHEET_DEFAULT; m_innerSizer = NULL; m_bookCtrl = NULL; } // Layout the dialog, to be called after pages have been created -void wxPropertySheetDialog::LayoutDialog() +void wxPropertySheetDialog::LayoutDialog(int centreFlags) { #if !defined(__SMARTPHONE__) && !defined(__POCKETPC__) GetSizer()->Fit(this); GetSizer()->SetSizeHints(this); - Centre(wxBOTH); + if (centreFlags) + Centre(centreFlags); #endif #if defined(__SMARTPHONE__) if (m_bookCtrl) @@ -123,7 +140,32 @@ wxBookCtrlBase* wxPropertySheetDialog::CreateBookCtrl() #else style |= wxBK_DEFAULT; #endif - return new wxBookCtrl(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, style ); + + wxBookCtrlBase* bookCtrl = NULL; + +#if wxUSE_NOTEBOOK + if (GetSheetStyle() & wxPROPSHEET_NOTEBOOK) + bookCtrl = new wxNotebook(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, style ); +#endif +#if wxUSE_CHOICEBOOK + if (GetSheetStyle() & wxPROPSHEET_CHOICEBOOK) + bookCtrl = new wxChoicebook(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, style ); +#endif +#if wxUSE_TOOLBOOK + if (GetSheetStyle() & wxPROPSHEET_TOOLBOOK) + bookCtrl = new wxToolbook(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, style ); +#endif +#if wxUSE_LISTBOOK + if (GetSheetStyle() & wxPROPSHEET_LISTBOOK) + bookCtrl = new wxListbook(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, style ); +#endif + if (!bookCtrl) + bookCtrl = new wxBookCtrl(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, style ); + + if (GetSheetStyle() & wxPROPSHEET_SHRINKTOFIT) + bookCtrl->SetShrinkMode(true); + + return bookCtrl; } // Adds the book control to the inner sizer. @@ -157,4 +199,25 @@ void wxPropertySheetDialog::OnActivate(wxActivateEvent& event) event.Skip(); } +// Resize dialog if necessary +void wxPropertySheetDialog::OnIdle(wxIdleEvent& event) +{ + event.Skip(); + + if ((GetSheetStyle() & wxPROPSHEET_SHRINKTOFIT) && GetBookCtrl()) + { + int sel = GetBookCtrl()->GetSelection(); + if (sel != -1 && sel != m_selectedPage) + { + GetBookCtrl()->InvalidateBestSize(); + InvalidateBestSize(); + SetSizeHints(-1, -1, -1, -1); + + m_selectedPage = sel; + LayoutDialog(0); + } + } +} + #endif // wxUSE_BOOKCTRL +