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