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