]> git.saurik.com Git - wxWidgets.git/blob - src/xrc/xh_statbar.cpp
non-PCH build fix (according to Tinderbox).
[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
82 if (!first.empty())
83 wxLogError(wxT("Error in resource, unknown statusbar field style: ") + first);
84 if(styles.Find(wxT(',')))
85 styles.Remove(0, styles.Find(wxT(',')) + 1);
86 }
87 statbar->SetStatusStyles(fields, style);
88 delete [] style;
89 }
90
91 if (m_parentAsWindow)
92 {
93 wxFrame *parentFrame = wxDynamicCast(m_parent, wxFrame);
94 if (parentFrame)
95 parentFrame->SetStatusBar(statbar);
96 }
97
98 return statbar;
99 }
100
101 bool wxStatusBarXmlHandler::CanHandle(wxXmlNode *node)
102 {
103 return IsOfClass(node, wxT("wxStatusBar"));
104 }
105
106 #endif // wxUSE_XRC && wxUSE_STATUSBAR