]> git.saurik.com Git - wxWidgets.git/blame - src/generic/propdlg.cpp
Work around missing mode_t definition with ICC.
[wxWidgets.git] / src / generic / propdlg.cpp
CommitLineData
3c9287bb 1/////////////////////////////////////////////////////////////////////////////
2ddb4d13 2// Name: src/generic/propdlg.cpp
3c9287bb
JS
3// Purpose: wxPropertySheetDialog
4// Author: Julian Smart
5// Modified by:
6// Created: 2005-03-12
3c9287bb
JS
7// Copyright: (c) Julian Smart
8// Licence: wxWindows licence
9/////////////////////////////////////////////////////////////////////////////
10
3c9287bb
JS
11// For compilers that support precompilation, includes "wx.h".
12#include "wx/wxprec.h"
13
14#ifdef __BORLANDC__
93763ad5 15 #pragma hdrstop
3c9287bb
JS
16#endif
17
532d575b
WS
18#if wxUSE_BOOKCTRL
19
3c9287bb
JS
20#ifndef WX_PRECOMP
21 #include "wx/button.h"
22 #include "wx/sizer.h"
23 #include "wx/intl.h"
24 #include "wx/log.h"
25 #include "wx/msgdlg.h"
26#endif
27
3be8026d 28#include "wx/bookctrl.h"
cc8bc5aa
JS
29
30#if wxUSE_NOTEBOOK
31#include "wx/notebook.h"
32#endif
33#if wxUSE_CHOICEBOOK
34#include "wx/choicebk.h"
35#endif
36#if wxUSE_TOOLBOOK
37#include "wx/toolbook.h"
38#endif
39#if wxUSE_LISTBOOK
40#include "wx/listbook.h"
41#endif
6334d903
JS
42#if wxUSE_TREEBOOK
43#include "wx/treebook.h"
44#endif
cc8bc5aa 45
3c9287bb 46#include "wx/generic/propdlg.h"
897b24cf 47#include "wx/sysopt.h"
3c9287bb
JS
48
49//-----------------------------------------------------------------------------
50// wxPropertySheetDialog
51//-----------------------------------------------------------------------------
52
53IMPLEMENT_DYNAMIC_CLASS(wxPropertySheetDialog, wxDialog)
54
c9ab63f4
JS
55BEGIN_EVENT_TABLE(wxPropertySheetDialog, wxDialog)
56 EVT_ACTIVATE(wxPropertySheetDialog::OnActivate)
cc8bc5aa 57 EVT_IDLE(wxPropertySheetDialog::OnIdle)
c9ab63f4
JS
58END_EVENT_TABLE()
59
532d575b 60bool wxPropertySheetDialog::Create(wxWindow* parent, wxWindowID id, const wxString& title,
3c9287bb
JS
61 const wxPoint& pos, const wxSize& sz, long style,
62 const wxString& name)
63{
cdc48273 64 parent = GetParentForModalDialog(parent, style);
2229243b 65
ac5f5c9e 66 if (!wxDialog::Create(parent, id, title, pos, sz, style|wxCLIP_CHILDREN, name))
3c9287bb 67 return false;
532d575b 68
3c9287bb
JS
69 wxBoxSizer *topSizer = new wxBoxSizer( wxVERTICAL );
70 SetSizer(topSizer);
71
72 // This gives more space around the edges
73 m_innerSizer = new wxBoxSizer( wxVERTICAL );
74
0906c58d 75#if defined(__SMARTPHONE__) || defined(__POCKETPC__)
1a1190b2 76 m_sheetOuterBorder = 0;
3c9287bb 77#endif
1a1190b2 78 topSizer->Add(m_innerSizer, 1, wxGROW|wxALL, m_sheetOuterBorder);
3c9287bb
JS
79
80 m_bookCtrl = CreateBookCtrl();
81 AddBookCtrl(m_innerSizer);
82
83 return true;
84}
85
86void wxPropertySheetDialog::Init()
87{
cc8bc5aa 88 m_sheetStyle = wxPROPSHEET_DEFAULT;
3c9287bb
JS
89 m_innerSizer = NULL;
90 m_bookCtrl = NULL;
1a1190b2
JS
91 m_sheetOuterBorder = 2;
92 m_sheetInnerBorder = 5;
3c9287bb
JS
93}
94
95// Layout the dialog, to be called after pages have been created
cc8bc5aa 96void wxPropertySheetDialog::LayoutDialog(int centreFlags)
3c9287bb 97{
0906c58d 98#if !defined(__SMARTPHONE__) && !defined(__POCKETPC__)
3c9287bb 99 GetSizer()->Fit(this);
95ba86d7 100 GetSizer()->SetSizeHints(this);
cc8bc5aa
JS
101 if (centreFlags)
102 Centre(centreFlags);
b9a958e6
WS
103#else
104 wxUnusedVar(centreFlags);
3c9287bb 105#endif
c9ab63f4
JS
106#if defined(__SMARTPHONE__)
107 if (m_bookCtrl)
108 m_bookCtrl->SetFocus();
109#endif
3c9287bb
JS
110}
111
112// Creates the buttons, if any
113void wxPropertySheetDialog::CreateButtons(int flags)
114{
897b24cf
WS
115#ifdef __POCKETPC__
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);
120#endif
121
12a124dd 122 wxSizer *buttonSizer = CreateButtonSizer(flags);
bd9f3519 123 if( buttonSizer )
897b24cf
WS
124 {
125 m_innerSizer->Add( buttonSizer, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxTOP|wxBOTTOM|wxLEFT|wxRIGHT, 2);
126 m_innerSizer->AddSpacer(2);
127 }
897b24cf
WS
128
129#ifdef __POCKETPC__
130 // restore system option
131 wxSystemOptions::SetOption(optionName,status);
3c9287bb
JS
132#endif
133}
134
135// Creates the book control
136wxBookCtrlBase* wxPropertySheetDialog::CreateBookCtrl()
137{
895cc205 138 int style = wxCLIP_CHILDREN | wxBK_DEFAULT;
cc8bc5aa
JS
139
140 wxBookCtrlBase* bookCtrl = NULL;
93763ad5 141
cc8bc5aa
JS
142#if wxUSE_NOTEBOOK
143 if (GetSheetStyle() & wxPROPSHEET_NOTEBOOK)
144 bookCtrl = new wxNotebook(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, style );
145#endif
146#if wxUSE_CHOICEBOOK
147 if (GetSheetStyle() & wxPROPSHEET_CHOICEBOOK)
148 bookCtrl = new wxChoicebook(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, style );
149#endif
150#if wxUSE_TOOLBOOK
b887dc7b 151#if defined(__WXMAC__) && wxUSE_TOOLBAR && wxUSE_BMPBUTTON
64d3ed17 152 if (GetSheetStyle() & wxPROPSHEET_BUTTONTOOLBOOK)
e3507dd8 153 bookCtrl = new wxToolbook(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, style|wxTBK_BUTTONBAR );
64d3ed17
JS
154 else
155#endif
156 if ((GetSheetStyle() & wxPROPSHEET_TOOLBOOK) || (GetSheetStyle() & wxPROPSHEET_BUTTONTOOLBOOK))
cc8bc5aa
JS
157 bookCtrl = new wxToolbook(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, style );
158#endif
159#if wxUSE_LISTBOOK
160 if (GetSheetStyle() & wxPROPSHEET_LISTBOOK)
161 bookCtrl = new wxListbook(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, style );
6334d903
JS
162#endif
163#if wxUSE_TREEBOOK
164 if (GetSheetStyle() & wxPROPSHEET_TREEBOOK)
165 bookCtrl = new wxTreebook(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, style );
cc8bc5aa
JS
166#endif
167 if (!bookCtrl)
168 bookCtrl = new wxBookCtrl(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, style );
93763ad5 169
cc8bc5aa 170 if (GetSheetStyle() & wxPROPSHEET_SHRINKTOFIT)
da817fa6 171 bookCtrl->SetFitToCurrentPage(true);
93763ad5 172
cc8bc5aa 173 return bookCtrl;
3c9287bb
JS
174}
175
176// Adds the book control to the inner sizer.
177void wxPropertySheetDialog::AddBookCtrl(wxSizer* sizer)
178{
3be8026d 179#if defined(__POCKETPC__) && wxUSE_NOTEBOOK
3c9287bb
JS
180 // The book control has to be sized larger than the dialog because of a border bug
181 // in WinCE
0906c58d
JS
182 int borderSize = -2;
183 sizer->Add( m_bookCtrl, 1, wxGROW|wxALIGN_CENTER_VERTICAL|wxLEFT|wxTOP|wxRIGHT, borderSize );
3c9287bb 184#else
1a1190b2 185 sizer->Add( m_bookCtrl, 1, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, m_sheetInnerBorder );
3c9287bb
JS
186#endif
187}
188
c9ab63f4
JS
189void wxPropertySheetDialog::OnActivate(wxActivateEvent& event)
190{
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())
197 {
532d575b 198 wxChoicebook* choiceBook = wxDynamicCast(GetBookCtrl(), wxChoicebook);
c9ab63f4
JS
199 if (choiceBook)
200 choiceBook->SetFocus();
201 }
202 else
203#endif
204 event.Skip();
205}
206
cc8bc5aa
JS
207// Resize dialog if necessary
208void wxPropertySheetDialog::OnIdle(wxIdleEvent& event)
209{
210 event.Skip();
93763ad5 211
cc8bc5aa
JS
212 if ((GetSheetStyle() & wxPROPSHEET_SHRINKTOFIT) && GetBookCtrl())
213 {
214 int sel = GetBookCtrl()->GetSelection();
215 if (sel != -1 && sel != m_selectedPage)
216 {
217 GetBookCtrl()->InvalidateBestSize();
218 InvalidateBestSize();
219 SetSizeHints(-1, -1, -1, -1);
220
221 m_selectedPage = sel;
222 LayoutDialog(0);
223 }
224 }
225}
226
3aa8e4ea
JS
227// Override function in base
228wxWindow* wxPropertySheetDialog::GetContentWindow() const
229{
230 return GetBookCtrl();
231}
232
532d575b 233#endif // wxUSE_BOOKCTRL