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