]> git.saurik.com Git - wxWidgets.git/blob - src/generic/propdlg.cpp
Added wxToolbook class
[wxWidgets.git] / src / generic / propdlg.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/generic/propdlg.cpp
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
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
14
15 #ifdef __BORLANDC__
16 #pragma hdrstop
17 #endif
18
19 #include "wx/defs.h"
20
21 #if wxUSE_BOOKCTRL
22
23 #ifndef WX_PRECOMP
24 #include "wx/button.h"
25 #include "wx/sizer.h"
26 #include "wx/intl.h"
27 #include "wx/log.h"
28 #include "wx/msgdlg.h"
29 #endif
30
31 #include "wx/bookctrl.h"
32 #include "wx/generic/propdlg.h"
33 #include "wx/sysopt.h"
34
35 //-----------------------------------------------------------------------------
36 // wxPropertySheetDialog
37 //-----------------------------------------------------------------------------
38
39 IMPLEMENT_DYNAMIC_CLASS(wxPropertySheetDialog, wxDialog)
40
41 BEGIN_EVENT_TABLE(wxPropertySheetDialog, wxDialog)
42 EVT_ACTIVATE(wxPropertySheetDialog::OnActivate)
43 END_EVENT_TABLE()
44
45 bool wxPropertySheetDialog::Create(wxWindow* parent, wxWindowID id, const wxString& title,
46 const wxPoint& pos, const wxSize& sz, long style,
47 const wxString& name)
48 {
49 if (!wxDialog::Create(parent, id, title, pos, sz, style|wxCLIP_CHILDREN, name))
50 return false;
51
52 wxBoxSizer *topSizer = new wxBoxSizer( wxVERTICAL );
53 SetSizer(topSizer);
54
55 // This gives more space around the edges
56 m_innerSizer = new wxBoxSizer( wxVERTICAL );
57
58 int extraSpace = 2;
59 #if defined(__SMARTPHONE__) || defined(__POCKETPC__)
60 extraSpace=0;
61 #endif
62 topSizer->Add(m_innerSizer, 1, wxGROW|wxALL, extraSpace);
63
64 m_bookCtrl = CreateBookCtrl();
65 AddBookCtrl(m_innerSizer);
66
67 return true;
68 }
69
70 void wxPropertySheetDialog::Init()
71 {
72 m_innerSizer = NULL;
73 m_bookCtrl = NULL;
74 }
75
76 // Layout the dialog, to be called after pages have been created
77 void wxPropertySheetDialog::LayoutDialog()
78 {
79 #if !defined(__SMARTPHONE__) && !defined(__POCKETPC__)
80 GetSizer()->Fit(this);
81 GetSizer()->SetSizeHints(this);
82 Centre(wxBOTH);
83 #endif
84 #if defined(__SMARTPHONE__)
85 if (m_bookCtrl)
86 m_bookCtrl->SetFocus();
87 #endif
88 }
89
90 // Creates the buttons, if any
91 void wxPropertySheetDialog::CreateButtons(int flags)
92 {
93 #ifdef __POCKETPC__
94 // keep system option status
95 const wxChar *optionName = wxT("wince.dialog.real-ok-cancel");
96 const int status = wxSystemOptions::GetOptionInt(optionName);
97 wxSystemOptions::SetOption(optionName,0);
98 #endif
99
100 wxSizer *buttonSizer = CreateButtonSizer( flags & ButtonSizerFlags );
101 if(buttonSizer->GetChildren().GetCount() > 0 )
102 {
103 m_innerSizer->Add( buttonSizer, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxTOP|wxBOTTOM|wxLEFT|wxRIGHT, 2);
104 m_innerSizer->AddSpacer(2);
105 }
106 else
107 {
108 delete buttonSizer;
109 }
110
111 #ifdef __POCKETPC__
112 // restore system option
113 wxSystemOptions::SetOption(optionName,status);
114 #endif
115 }
116
117 // Creates the book control
118 wxBookCtrlBase* wxPropertySheetDialog::CreateBookCtrl()
119 {
120 int style = wxCLIP_CHILDREN;
121 #if defined(__POCKETPC__) && wxUSE_NOTEBOOK
122 style |= wxBK_BOTTOM|wxNB_FLAT;
123 #else
124 style |= wxBK_DEFAULT;
125 #endif
126 return new wxBookCtrl(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, style );
127 }
128
129 // Adds the book control to the inner sizer.
130 void wxPropertySheetDialog::AddBookCtrl(wxSizer* sizer)
131 {
132 #if defined(__POCKETPC__) && wxUSE_NOTEBOOK
133 // The book control has to be sized larger than the dialog because of a border bug
134 // in WinCE
135 int borderSize = -2;
136 sizer->Add( m_bookCtrl, 1, wxGROW|wxALIGN_CENTER_VERTICAL|wxLEFT|wxTOP|wxRIGHT, borderSize );
137 #else
138 sizer->Add( m_bookCtrl, 1, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5 );
139 #endif
140 }
141
142 void wxPropertySheetDialog::OnActivate(wxActivateEvent& event)
143 {
144 #if defined(__SMARTPHONE__)
145 // Attempt to focus the choice control: not yet working, but might
146 // be a step in the right direction. OnActivate overrides the default
147 // handler in toplevel.cpp that sets the focus for the first child of
148 // of the dialog (the choicebook).
149 if (event.GetActive())
150 {
151 wxChoicebook* choiceBook = wxDynamicCast(GetBookCtrl(), wxChoicebook);
152 if (choiceBook)
153 choiceBook->SetFocus();
154 }
155 else
156 #endif
157 event.Skip();
158 }
159
160 #endif // wxUSE_BOOKCTRL