Added wxPropertySheetDialog for implementing settings dialogs
[wxWidgets.git] / src / generic / propdlg.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: 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 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
13 #pragma implementation "propdlg.h"
14 #endif
15
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
18
19 #ifdef __BORLANDC__
20 #pragma hdrstop
21 #endif
22
23 #include "wx/defs.h"
24
25 #ifndef WX_PRECOMP
26 #include "wx/button.h"
27 #include "wx/sizer.h"
28 #include "wx/intl.h"
29 #include "wx/log.h"
30 #include "wx/msgdlg.h"
31 #endif
32
33 #include "wx/notebook.h"
34 #include "wx/generic/propdlg.h"
35
36 //-----------------------------------------------------------------------------
37 // wxPropertySheetDialog
38 //-----------------------------------------------------------------------------
39
40 IMPLEMENT_DYNAMIC_CLASS(wxPropertySheetDialog, wxDialog)
41
42 bool wxPropertySheetDialog::Create(wxWindow* parent, wxWindowID id, const wxString& title,
43 const wxPoint& pos, const wxSize& sz, long style,
44 const wxString& name)
45 {
46 if (!wxDialog::Create(parent, id, title, pos, sz, style, name))
47 return false;
48
49 wxBoxSizer *topSizer = new wxBoxSizer( wxVERTICAL );
50 SetSizer(topSizer);
51
52 // This gives more space around the edges
53 m_innerSizer = new wxBoxSizer( wxVERTICAL );
54
55 int extraSpace = 5;
56 #ifdef __WXWINCE__
57 extraSpace=0;
58 #endif
59 topSizer->Add(m_innerSizer, 1, wxGROW|wxALL, extraSpace);
60
61 m_bookCtrl = CreateBookCtrl();
62 AddBookCtrl(m_innerSizer);
63
64 return true;
65 }
66
67 void wxPropertySheetDialog::Init()
68 {
69 m_innerSizer = NULL;
70 m_bookCtrl = NULL;
71 }
72
73 // Layout the dialog, to be called after pages have been created
74 void wxPropertySheetDialog::LayoutDialog()
75 {
76 #ifndef __WXWINCE__
77 GetSizer()->Fit(this);
78 Centre(wxBOTH);
79 #endif
80 }
81
82 // Creates the buttons, if any
83 void wxPropertySheetDialog::CreateButtons(int flags)
84 {
85 #ifndef __WXWINCE__
86 wxSizer* sizer = CreateButtonSizer(flags);
87 m_innerSizer->Add( sizer, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxTOP|wxBOTTOM, 5);
88 #endif
89 }
90
91 // Creates the book control
92 wxBookCtrlBase* wxPropertySheetDialog::CreateBookCtrl()
93 {
94 int style = 0;
95 #ifdef __WXWINCE__
96 style |= wxNB_BOTTOM|wxNB_FLAT;
97 #endif
98 return new wxNotebook(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, style );
99 }
100
101 // Adds the book control to the inner sizer.
102 void wxPropertySheetDialog::AddBookCtrl(wxSizer* sizer)
103 {
104 #ifdef __WXWINCE__
105 // The book control has to be sized larger than the dialog because of a border bug
106 // in WinCE
107 sizer->Add( m_bookCtrl, 1, wxGROW|wxALIGN_CENTER_VERTICAL|wxLEFT|wxTOP|wxRIGHT, -3 );
108 #else
109 sizer->Add( m_bookCtrl, 1, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5 );
110 #endif
111 }
112