]> git.saurik.com Git - wxWidgets.git/blame - src/generic/propdlg.cpp
provide wxGetLocalTimeMillis() (returning double) even if wxUSE_LONGLONG==0
[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
7// RCS-ID: $Id$
8// Copyright: (c) Julian Smart
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
3c9287bb
JS
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
532d575b
WS
21#if wxUSE_BOOKCTRL
22
3c9287bb
JS
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
3be8026d 31#include "wx/bookctrl.h"
cc8bc5aa
JS
32
33#if wxUSE_NOTEBOOK
34#include "wx/notebook.h"
35#endif
36#if wxUSE_CHOICEBOOK
37#include "wx/choicebk.h"
38#endif
39#if wxUSE_TOOLBOOK
40#include "wx/toolbook.h"
41#endif
42#if wxUSE_LISTBOOK
43#include "wx/listbook.h"
44#endif
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{
ac5f5c9e 64 if (!wxDialog::Create(parent, id, title, pos, sz, style|wxCLIP_CHILDREN, name))
3c9287bb 65 return false;
532d575b 66
3c9287bb
JS
67 wxBoxSizer *topSizer = new wxBoxSizer( wxVERTICAL );
68 SetSizer(topSizer);
69
70 // This gives more space around the edges
71 m_innerSizer = new wxBoxSizer( wxVERTICAL );
72
95ba86d7 73 int extraSpace = 2;
0906c58d 74#if defined(__SMARTPHONE__) || defined(__POCKETPC__)
3c9287bb
JS
75 extraSpace=0;
76#endif
77 topSizer->Add(m_innerSizer, 1, wxGROW|wxALL, extraSpace);
78
79 m_bookCtrl = CreateBookCtrl();
80 AddBookCtrl(m_innerSizer);
81
82 return true;
83}
84
85void wxPropertySheetDialog::Init()
86{
cc8bc5aa 87 m_sheetStyle = wxPROPSHEET_DEFAULT;
3c9287bb
JS
88 m_innerSizer = NULL;
89 m_bookCtrl = NULL;
90}
91
92// Layout the dialog, to be called after pages have been created
cc8bc5aa 93void wxPropertySheetDialog::LayoutDialog(int centreFlags)
3c9287bb 94{
0906c58d 95#if !defined(__SMARTPHONE__) && !defined(__POCKETPC__)
3c9287bb 96 GetSizer()->Fit(this);
95ba86d7 97 GetSizer()->SetSizeHints(this);
cc8bc5aa
JS
98 if (centreFlags)
99 Centre(centreFlags);
3c9287bb 100#endif
c9ab63f4
JS
101#if defined(__SMARTPHONE__)
102 if (m_bookCtrl)
103 m_bookCtrl->SetFocus();
6fc07dd8 104 wxUnusedVar(centreFlags);
c9ab63f4 105#endif
3c9287bb
JS
106}
107
108// Creates the buttons, if any
109void wxPropertySheetDialog::CreateButtons(int flags)
110{
897b24cf
WS
111#ifdef __POCKETPC__
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);
116#endif
117
118 wxSizer *buttonSizer = CreateButtonSizer( flags & ButtonSizerFlags );
119 if(buttonSizer->GetChildren().GetCount() > 0 )
120 {
121 m_innerSizer->Add( buttonSizer, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxTOP|wxBOTTOM|wxLEFT|wxRIGHT, 2);
122 m_innerSizer->AddSpacer(2);
123 }
124 else
125 {
126 delete buttonSizer;
127 }
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{
ac5f5c9e 138 int style = wxCLIP_CHILDREN;
3be8026d 139#if defined(__POCKETPC__) && wxUSE_NOTEBOOK
2ddb4d13 140 style |= wxBK_BOTTOM|wxNB_FLAT;
3be8026d 141#else
2ddb4d13 142 style |= wxBK_DEFAULT;
3c9287bb 143#endif
cc8bc5aa
JS
144
145 wxBookCtrlBase* bookCtrl = NULL;
146
147#if wxUSE_NOTEBOOK
148 if (GetSheetStyle() & wxPROPSHEET_NOTEBOOK)
149 bookCtrl = new wxNotebook(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, style );
150#endif
151#if wxUSE_CHOICEBOOK
152 if (GetSheetStyle() & wxPROPSHEET_CHOICEBOOK)
153 bookCtrl = new wxChoicebook(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, style );
154#endif
155#if wxUSE_TOOLBOOK
156 if (GetSheetStyle() & wxPROPSHEET_TOOLBOOK)
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 );
162#endif
163 if (!bookCtrl)
164 bookCtrl = new wxBookCtrl(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, style );
165
166 if (GetSheetStyle() & wxPROPSHEET_SHRINKTOFIT)
da817fa6 167 bookCtrl->SetFitToCurrentPage(true);
cc8bc5aa
JS
168
169 return bookCtrl;
3c9287bb
JS
170}
171
172// Adds the book control to the inner sizer.
173void wxPropertySheetDialog::AddBookCtrl(wxSizer* sizer)
174{
3be8026d 175#if defined(__POCKETPC__) && wxUSE_NOTEBOOK
3c9287bb
JS
176 // The book control has to be sized larger than the dialog because of a border bug
177 // in WinCE
0906c58d
JS
178 int borderSize = -2;
179 sizer->Add( m_bookCtrl, 1, wxGROW|wxALIGN_CENTER_VERTICAL|wxLEFT|wxTOP|wxRIGHT, borderSize );
3c9287bb
JS
180#else
181 sizer->Add( m_bookCtrl, 1, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5 );
182#endif
183}
184
c9ab63f4
JS
185void wxPropertySheetDialog::OnActivate(wxActivateEvent& event)
186{
187#if defined(__SMARTPHONE__)
188 // Attempt to focus the choice control: not yet working, but might
189 // be a step in the right direction. OnActivate overrides the default
190 // handler in toplevel.cpp that sets the focus for the first child of
191 // of the dialog (the choicebook).
192 if (event.GetActive())
193 {
532d575b 194 wxChoicebook* choiceBook = wxDynamicCast(GetBookCtrl(), wxChoicebook);
c9ab63f4
JS
195 if (choiceBook)
196 choiceBook->SetFocus();
197 }
198 else
199#endif
200 event.Skip();
201}
202
cc8bc5aa
JS
203// Resize dialog if necessary
204void wxPropertySheetDialog::OnIdle(wxIdleEvent& event)
205{
206 event.Skip();
207
208 if ((GetSheetStyle() & wxPROPSHEET_SHRINKTOFIT) && GetBookCtrl())
209 {
210 int sel = GetBookCtrl()->GetSelection();
211 if (sel != -1 && sel != m_selectedPage)
212 {
213 GetBookCtrl()->InvalidateBestSize();
214 InvalidateBestSize();
215 SetSizeHints(-1, -1, -1, -1);
216
217 m_selectedPage = sel;
218 LayoutDialog(0);
219 }
220 }
221}
222
532d575b 223#endif // wxUSE_BOOKCTRL
cc8bc5aa 224