Added XRC handler for wxPropertySheetDialog (Sander Berents)
[wxWidgets.git] / src / xrc / xh_propdlg.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/xrc/xh_propdlg.cpp
3 // Purpose: XRC resource handler for wxPropertySheetDialog
4 // Author: Sander Berents
5 // Created: 2007/07/12
6 // RCS-ID: $Id$
7 // Copyright: (c) 2007 Sander Berents
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
10
11 // For compilers that support precompilation, includes "wx.h".
12 #include "wx/wxprec.h"
13
14 #ifdef __BORLANDC__
15 #pragma hdrstop
16 #endif
17
18 #if wxUSE_XRC && wxUSE_BOOKCTRL
19
20 #include "wx/xrc/xh_propdlg.h"
21
22 #ifndef WX_PRECOMP
23 #include "wx/log.h"
24 #include "wx/sizer.h"
25 #endif
26
27 #include "wx/bookctrl.h"
28 #include "wx/propdlg.h"
29
30 IMPLEMENT_DYNAMIC_CLASS(wxPropertySheetDialogXmlHandler, wxXmlResourceHandler)
31
32 wxPropertySheetDialogXmlHandler::wxPropertySheetDialogXmlHandler()
33 :wxXmlResourceHandler(),
34 m_isInside(false),
35 m_dialog(NULL)
36 {
37 XRC_ADD_STYLE(wxSTAY_ON_TOP);
38 XRC_ADD_STYLE(wxCAPTION);
39 XRC_ADD_STYLE(wxDEFAULT_DIALOG_STYLE);
40 XRC_ADD_STYLE(wxSYSTEM_MENU);
41 XRC_ADD_STYLE(wxRESIZE_BORDER);
42 XRC_ADD_STYLE(wxCLOSE_BOX);
43 XRC_ADD_STYLE(wxDIALOG_NO_PARENT);
44
45 XRC_ADD_STYLE(wxTAB_TRAVERSAL);
46 XRC_ADD_STYLE(wxWS_EX_VALIDATE_RECURSIVELY);
47 XRC_ADD_STYLE(wxDIALOG_EX_METAL);
48 XRC_ADD_STYLE(wxMAXIMIZE_BOX);
49 XRC_ADD_STYLE(wxMINIMIZE_BOX);
50 XRC_ADD_STYLE(wxFRAME_SHAPED);
51 XRC_ADD_STYLE(wxDIALOG_EX_CONTEXTHELP);
52
53 AddWindowStyles();
54 }
55
56 wxObject *wxPropertySheetDialogXmlHandler::DoCreateResource()
57 {
58 if (m_class == wxT("propertysheetpage"))
59 {
60 wxXmlNode *n = GetParamNode(wxT("object"));
61
62 if (!n) n = GetParamNode(wxT("object_ref"));
63
64 if (n)
65 {
66 wxBookCtrlBase *bookctrl = m_dialog->GetBookCtrl();
67 bool old_ins = m_isInside;
68 m_isInside = false;
69 wxObject *item = CreateResFromNode(n, bookctrl, NULL);
70 m_isInside = old_ins;
71 wxWindow *wnd = wxDynamicCast(item, wxWindow);
72
73 if (wnd)
74 {
75 bookctrl->AddPage(wnd, GetText(wxT("label")), GetBool(wxT("selected")));
76 if (HasParam(wxT("bitmap")))
77 {
78 wxBitmap bmp = GetBitmap(wxT("bitmap"), wxART_OTHER);
79 wxImageList *imgList = bookctrl->GetImageList();
80 if (imgList == NULL)
81 {
82 imgList = new wxImageList(bmp.GetWidth(), bmp.GetHeight());
83 bookctrl->AssignImageList(imgList);
84 }
85 int imgIndex = imgList->Add(bmp);
86 bookctrl->SetPageImage(bookctrl->GetPageCount()-1, imgIndex);
87 }
88 }
89 else
90 wxLogError(wxT("Error in resource."));
91 return wnd;
92 }
93 else
94 {
95 wxLogError(wxT("Error in resource: no control within wxPropertySheetDialog's <page> tag."));
96 return NULL;
97 }
98 }
99
100 else
101 {
102 XRC_MAKE_INSTANCE(dlg, wxPropertySheetDialog)
103
104 dlg->Create(m_parentAsWindow,
105 GetID(),
106 GetText(wxT("title")),
107 GetPosition(),
108 GetSize(),
109 GetStyle(),
110 GetName());
111
112 if (HasParam(wxT("icon"))) dlg->SetIcon(GetIcon(wxT("icon"), wxART_FRAME_ICON));
113
114 SetupWindow(dlg);
115
116 wxPropertySheetDialog *old_par = m_dialog;
117 m_dialog = dlg;
118 bool old_ins = m_isInside;
119 m_isInside = true;
120 CreateChildren(m_dialog, true/*only this handler*/);
121 m_isInside = old_ins;
122 m_dialog = old_par;
123
124 if (GetBool(wxT("centered"), false)) dlg->Centre();
125 wxString buttons = GetText(wxT("buttons"));
126 if (!buttons.IsEmpty())
127 {
128 int flags = 0;
129 if (buttons.Find(wxT("wxOK")) != wxNOT_FOUND) flags |= wxOK;
130 if (buttons.Find(wxT("wxCANCEL")) != wxNOT_FOUND) flags |= wxCANCEL;
131 if (buttons.Find(wxT("wxYES")) != wxNOT_FOUND) flags |= wxYES;
132 if (buttons.Find(wxT("wxNO")) != wxNOT_FOUND) flags |= wxNO;
133 if (buttons.Find(wxT("wxHELP")) != wxNOT_FOUND) flags |= wxHELP;
134 if (buttons.Find(wxT("wxNO_DEFAULT")) != wxNOT_FOUND) flags |= wxNO_DEFAULT;
135 dlg->CreateButtons(flags);
136 }
137
138 return dlg;
139 }
140 }
141
142 bool wxPropertySheetDialogXmlHandler::CanHandle(wxXmlNode *node)
143 {
144 return ((!m_isInside && IsOfClass(node, wxT("wxPropertySheetDialog"))) ||
145 (m_isInside && IsOfClass(node, wxT("propertysheetpage"))));
146 }
147
148 #endif // wxUSE_XRC && wxUSE_BOOKCTRL