]> git.saurik.com Git - wxWidgets.git/blame - src/xrc/xh_propdlg.cpp
Change wxNotebook selection before sending page changed event in wxMSW.
[wxWidgets.git] / src / xrc / xh_propdlg.cpp
CommitLineData
f8efd2df
VZ
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 #include "wx/frame.h"
26#endif
27
28#include "wx/bookctrl.h"
29#include "wx/propdlg.h"
30#include "wx/imaglist.h"
31
32IMPLEMENT_DYNAMIC_CLASS(wxPropertySheetDialogXmlHandler, wxXmlResourceHandler)
33
34wxPropertySheetDialogXmlHandler::wxPropertySheetDialogXmlHandler()
35 :wxXmlResourceHandler(),
36 m_isInside(false),
37 m_dialog(NULL)
38{
39 XRC_ADD_STYLE(wxSTAY_ON_TOP);
40 XRC_ADD_STYLE(wxCAPTION);
41 XRC_ADD_STYLE(wxDEFAULT_DIALOG_STYLE);
42 XRC_ADD_STYLE(wxSYSTEM_MENU);
43 XRC_ADD_STYLE(wxRESIZE_BORDER);
44 XRC_ADD_STYLE(wxCLOSE_BOX);
45 XRC_ADD_STYLE(wxDIALOG_NO_PARENT);
46
47 XRC_ADD_STYLE(wxTAB_TRAVERSAL);
48 XRC_ADD_STYLE(wxWS_EX_VALIDATE_RECURSIVELY);
49 XRC_ADD_STYLE(wxDIALOG_EX_METAL);
50 XRC_ADD_STYLE(wxMAXIMIZE_BOX);
51 XRC_ADD_STYLE(wxMINIMIZE_BOX);
52 XRC_ADD_STYLE(wxFRAME_SHAPED);
53 XRC_ADD_STYLE(wxDIALOG_EX_CONTEXTHELP);
54
55 AddWindowStyles();
56}
57
58wxObject *wxPropertySheetDialogXmlHandler::DoCreateResource()
59{
60 if (m_class == wxT("propertysheetpage"))
61 {
62 wxXmlNode *n = GetParamNode(wxT("object"));
63
64 if (!n) n = GetParamNode(wxT("object_ref"));
65
66 if (n)
67 {
68 wxBookCtrlBase *bookctrl = m_dialog->GetBookCtrl();
69 bool old_ins = m_isInside;
70 m_isInside = false;
71 wxObject *item = CreateResFromNode(n, bookctrl, NULL);
72 m_isInside = old_ins;
73 wxWindow *wnd = wxDynamicCast(item, wxWindow);
74
75 if (wnd)
76 {
77 bookctrl->AddPage(wnd, GetText(wxT("label")), GetBool(wxT("selected")));
78 if (HasParam(wxT("bitmap")))
79 {
80 wxBitmap bmp = GetBitmap(wxT("bitmap"), wxART_OTHER);
81 wxImageList *imgList = bookctrl->GetImageList();
82 if (imgList == NULL)
83 {
84 imgList = new wxImageList(bmp.GetWidth(), bmp.GetHeight());
85 bookctrl->AssignImageList(imgList);
86 }
87 int imgIndex = imgList->Add(bmp);
88 bookctrl->SetPageImage(bookctrl->GetPageCount()-1, imgIndex);
89 }
90 }
91 else
819559b2
VS
92 {
93 ReportError(n, "propertysheetpage child must be a window");
94 }
f8efd2df
VZ
95 return wnd;
96 }
97 else
98 {
819559b2 99 ReportError("propertysheetpage must have a window child");
f8efd2df
VZ
100 return NULL;
101 }
102 }
103
104 else
105 {
106 XRC_MAKE_INSTANCE(dlg, wxPropertySheetDialog)
107
108 dlg->Create(m_parentAsWindow,
109 GetID(),
110 GetText(wxT("title")),
111 GetPosition(),
112 GetSize(),
113 GetStyle(),
114 GetName());
115
1c60f644
VS
116 if (HasParam(wxT("icon")))
117 dlg->SetIcons(GetIconBundle(wxT("icon"), wxART_FRAME_ICON));
f8efd2df
VZ
118
119 SetupWindow(dlg);
120
121 wxPropertySheetDialog *old_par = m_dialog;
122 m_dialog = dlg;
123 bool old_ins = m_isInside;
124 m_isInside = true;
125 CreateChildren(m_dialog, true/*only this handler*/);
126 m_isInside = old_ins;
127 m_dialog = old_par;
128
129 if (GetBool(wxT("centered"), false)) dlg->Centre();
130 wxString buttons = GetText(wxT("buttons"));
131 if (!buttons.IsEmpty())
132 {
133 int flags = 0;
134 if (buttons.Find(wxT("wxOK")) != wxNOT_FOUND) flags |= wxOK;
135 if (buttons.Find(wxT("wxCANCEL")) != wxNOT_FOUND) flags |= wxCANCEL;
136 if (buttons.Find(wxT("wxYES")) != wxNOT_FOUND) flags |= wxYES;
137 if (buttons.Find(wxT("wxNO")) != wxNOT_FOUND) flags |= wxNO;
138 if (buttons.Find(wxT("wxHELP")) != wxNOT_FOUND) flags |= wxHELP;
139 if (buttons.Find(wxT("wxNO_DEFAULT")) != wxNOT_FOUND) flags |= wxNO_DEFAULT;
140 dlg->CreateButtons(flags);
141 }
142
143 return dlg;
144 }
145}
146
147bool wxPropertySheetDialogXmlHandler::CanHandle(wxXmlNode *node)
148{
149 return ((!m_isInside && IsOfClass(node, wxT("wxPropertySheetDialog"))) ||
150 (m_isInside && IsOfClass(node, wxT("propertysheetpage"))));
151}
152
153#endif // wxUSE_XRC && wxUSE_BOOKCTRL