]> git.saurik.com Git - wxWidgets.git/blob - src/xrc/xh_statbar.cpp
minor cleanup - reformatting
[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 #endif
25
26 #include "wx/frame.h"
27 #include "wx/log.h"
28
29 #include "wx/statusbr.h"
30
31 IMPLEMENT_DYNAMIC_CLASS(wxStatusBarXmlHandler, wxXmlResourceHandler)
32
33 wxStatusBarXmlHandler::wxStatusBarXmlHandler() :
34 wxXmlResourceHandler()
35 {
36 XRC_ADD_STYLE(wxST_SIZEGRIP);
37 AddWindowStyles();
38 }
39
40 wxObject *wxStatusBarXmlHandler::DoCreateResource()
41 {
42 XRC_MAKE_INSTANCE(statbar, wxStatusBar)
43
44 statbar->Create(m_parentAsWindow,
45 GetID(),
46 GetStyle(),
47 GetName());
48
49 int fields = GetLong(wxT("fields"), 1);
50 wxString widths = GetParamValue(wxT("widths"));
51 wxString styles = GetParamValue(wxT("styles"));
52
53 if (fields > 1 && !widths.IsEmpty())
54 {
55 int *width = new int[fields];
56
57 for (int i = 0; i < fields; ++i)
58 {
59 width[i] = wxAtoi(widths.BeforeFirst(wxT(',')));
60 if(widths.Find(wxT(',')))
61 widths.Remove(0, widths.Find(wxT(',')) + 1);
62 }
63 statbar->SetFieldsCount(fields, width);
64 delete[] width;
65 }
66 else
67 statbar->SetFieldsCount(fields);
68
69 if (!styles.empty())
70 {
71 int *style = new int[fields];
72 for (int i = 0; i < fields; ++i)
73 {
74 style[i] = wxSB_NORMAL;
75
76 wxString first = styles.BeforeFirst(wxT(','));
77 if (first == wxT("wxSB_NORMAL"))
78 style[i] = wxSB_NORMAL;
79 else if (first == wxT("wxSB_FLAT"))
80 style[i] = wxSB_FLAT;
81 else if (first == wxT("wxSB_RAISED"))
82 style[i] = wxSB_RAISED;
83
84 if (!first.empty())
85 wxLogError(wxT("Error in resource, unknown statusbar field style: ") + first);
86 if(styles.Find(wxT(',')))
87 styles.Remove(0, styles.Find(wxT(',')) + 1);
88 }
89 statbar->SetStatusStyles(fields, style);
90 delete [] style;
91 }
92
93 if (m_parentAsWindow)
94 {
95 wxFrame *parentFrame = wxDynamicCast(m_parent, wxFrame);
96 if (parentFrame)
97 parentFrame->SetStatusBar(statbar);
98 }
99
100 return statbar;
101 }
102
103 bool wxStatusBarXmlHandler::CanHandle(wxXmlNode *node)
104 {
105 return IsOfClass(node, wxT("wxStatusBar"));
106 }
107
108 #endif // wxUSE_XRC && wxUSE_STATUSBAR