]> git.saurik.com Git - wxWidgets.git/blob - src/xrc/xh_statbar.cpp
move parsing helpers, too (part of r59656)
[wxWidgets.git] / src / xrc / xh_statbar.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/xrc/xh_statbar.cpp
3 // Purpose: XRC resource for wxStatusBar
4 // Author: Brian Ravnsgaard Riis
5 // Created: 2004/01/21
6 // RCS-ID: $Id$
7 // Copyright: (c) 2004 Brian Ravnsgaard Riis
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_STATUSBAR
19
20 #include "wx/xrc/xh_statbar.h"
21
22 #ifndef WX_PRECOMP
23 #include "wx/string.h"
24 #include "wx/log.h"
25 #include "wx/frame.h"
26 #include "wx/statusbr.h"
27 #endif
28
29 IMPLEMENT_DYNAMIC_CLASS(wxStatusBarXmlHandler, wxXmlResourceHandler)
30
31 wxStatusBarXmlHandler::wxStatusBarXmlHandler()
32 :wxXmlResourceHandler()
33 {
34 XRC_ADD_STYLE(wxST_SIZEGRIP);
35 AddWindowStyles();
36 }
37
38 wxObject *wxStatusBarXmlHandler::DoCreateResource()
39 {
40 XRC_MAKE_INSTANCE(statbar, wxStatusBar)
41
42 statbar->Create(m_parentAsWindow,
43 GetID(),
44 GetStyle(),
45 GetName());
46
47 int fields = GetLong(wxT("fields"), 1);
48 wxString widths = GetParamValue(wxT("widths"));
49 wxString styles = GetParamValue(wxT("styles"));
50
51 if (fields > 1 && !widths.IsEmpty())
52 {
53 int *width = new int[fields];
54
55 for (int i = 0; i < fields; ++i)
56 {
57 width[i] = wxAtoi(widths.BeforeFirst(wxT(',')));
58 if(widths.Find(wxT(',')))
59 widths.Remove(0, widths.Find(wxT(',')) + 1);
60 }
61 statbar->SetFieldsCount(fields, width);
62 delete[] width;
63 }
64 else
65 statbar->SetFieldsCount(fields);
66
67 if (!styles.empty())
68 {
69 int *style = new int[fields];
70 for (int i = 0; i < fields; ++i)
71 {
72 style[i] = wxSB_NORMAL;
73
74 wxString first = styles.BeforeFirst(wxT(','));
75 if (first == wxT("wxSB_NORMAL"))
76 style[i] = wxSB_NORMAL;
77 else if (first == wxT("wxSB_FLAT"))
78 style[i] = wxSB_FLAT;
79 else if (first == wxT("wxSB_RAISED"))
80 style[i] = wxSB_RAISED;
81 else if (!first.empty())
82 {
83 ReportParamError
84 (
85 "styles",
86 wxString::Format
87 (
88 "unknown status bar field style \"%s\"",
89 first
90 )
91 );
92 }
93
94 if(styles.Find(wxT(',')))
95 styles.Remove(0, styles.Find(wxT(',')) + 1);
96 }
97 statbar->SetStatusStyles(fields, style);
98 delete [] style;
99 }
100
101 CreateChildren(statbar);
102
103 if (m_parentAsWindow)
104 {
105 wxFrame *parentFrame = wxDynamicCast(m_parent, wxFrame);
106 if (parentFrame)
107 parentFrame->SetStatusBar(statbar);
108 }
109
110 return statbar;
111 }
112
113 bool wxStatusBarXmlHandler::CanHandle(wxXmlNode *node)
114 {
115 return IsOfClass(node, wxT("wxStatusBar"));
116 }
117
118 #endif // wxUSE_XRC && wxUSE_STATUSBAR