]> git.saurik.com Git - wxWidgets.git/blob - src/xrc/xh_statbar.cpp
Use flat generic status bar by default and add wxSB_SUNKEN.
[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(wxSTB_SIZEGRIP);
35 XRC_ADD_STYLE(wxSTB_SHOW_TIPS);
36 XRC_ADD_STYLE(wxSTB_ELLIPSIZE_START);
37 XRC_ADD_STYLE(wxSTB_ELLIPSIZE_MIDDLE);
38 XRC_ADD_STYLE(wxSTB_ELLIPSIZE_END);
39 XRC_ADD_STYLE(wxSTB_DEFAULT_STYLE);
40
41 // compat style name:
42 XRC_ADD_STYLE(wxST_SIZEGRIP);
43
44 AddWindowStyles();
45 }
46
47 wxObject *wxStatusBarXmlHandler::DoCreateResource()
48 {
49 XRC_MAKE_INSTANCE(statbar, wxStatusBar)
50
51 statbar->Create(m_parentAsWindow,
52 GetID(),
53 GetStyle(),
54 GetName());
55
56 int fields = GetLong(wxT("fields"), 1);
57 wxString widths = GetParamValue(wxT("widths"));
58 wxString styles = GetParamValue(wxT("styles"));
59
60 if (fields > 1 && !widths.IsEmpty())
61 {
62 int *width = new int[fields];
63
64 for (int i = 0; i < fields; ++i)
65 {
66 width[i] = wxAtoi(widths.BeforeFirst(wxT(',')));
67 if(widths.Find(wxT(',')))
68 widths.Remove(0, widths.Find(wxT(',')) + 1);
69 }
70 statbar->SetFieldsCount(fields, width);
71 delete[] width;
72 }
73 else
74 statbar->SetFieldsCount(fields);
75
76 if (!styles.empty())
77 {
78 int *style = new int[fields];
79 for (int i = 0; i < fields; ++i)
80 {
81 style[i] = wxSB_NORMAL;
82
83 wxString first = styles.BeforeFirst(wxT(','));
84 if (first == wxT("wxSB_NORMAL"))
85 style[i] = wxSB_NORMAL;
86 else if (first == wxT("wxSB_FLAT"))
87 style[i] = wxSB_FLAT;
88 else if (first == wxT("wxSB_RAISED"))
89 style[i] = wxSB_RAISED;
90 else if (first == wxT("wxSB_SUNKEN"))
91 style[i] = wxSB_SUNKEN;
92 else if (!first.empty())
93 {
94 ReportParamError
95 (
96 "styles",
97 wxString::Format
98 (
99 "unknown status bar field style \"%s\"",
100 first
101 )
102 );
103 }
104
105 if(styles.Find(wxT(',')))
106 styles.Remove(0, styles.Find(wxT(',')) + 1);
107 }
108 statbar->SetStatusStyles(fields, style);
109 delete [] style;
110 }
111
112 CreateChildren(statbar);
113
114 if (m_parentAsWindow)
115 {
116 wxFrame *parentFrame = wxDynamicCast(m_parent, wxFrame);
117 if (parentFrame)
118 parentFrame->SetStatusBar(statbar);
119 }
120
121 return statbar;
122 }
123
124 bool wxStatusBarXmlHandler::CanHandle(wxXmlNode *node)
125 {
126 return IsOfClass(node, wxT("wxStatusBar"));
127 }
128
129 #endif // wxUSE_XRC && wxUSE_STATUSBAR