]> git.saurik.com Git - wxWidgets.git/blob - src/xrc/xh_radbx.cpp
wxGTK1 : wx/private/eventloopsourcesmanager.h was missing in evtloop.cpp
[wxWidgets.git] / src / xrc / xh_radbx.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/xrc/xh_radbx.cpp
3 // Purpose: XRC resource for wxRadioBox
4 // Author: Bob Mitchell
5 // Created: 2000/03/21
6 // Copyright: (c) 2000 Bob Mitchell and Verant Interactive
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
9
10 // For compilers that support precompilation, includes "wx.h".
11 #include "wx/wxprec.h"
12
13 #ifdef __BORLANDC__
14 #pragma hdrstop
15 #endif
16
17 #if wxUSE_XRC && wxUSE_RADIOBOX
18
19 #include "wx/xrc/xh_radbx.h"
20
21 #ifndef WX_PRECOMP
22 #include "wx/intl.h"
23 #include "wx/radiobox.h"
24 #endif
25
26 #include "wx/xml/xml.h"
27
28 IMPLEMENT_DYNAMIC_CLASS(wxRadioBoxXmlHandler, wxXmlResourceHandler)
29
30 wxRadioBoxXmlHandler::wxRadioBoxXmlHandler()
31 : wxXmlResourceHandler(), m_insideBox(false)
32 {
33 XRC_ADD_STYLE(wxRA_SPECIFY_COLS);
34 XRC_ADD_STYLE(wxRA_HORIZONTAL);
35 XRC_ADD_STYLE(wxRA_SPECIFY_ROWS);
36 XRC_ADD_STYLE(wxRA_VERTICAL);
37 AddWindowStyles();
38 }
39
40 wxObject *wxRadioBoxXmlHandler::DoCreateResource()
41 {
42 if ( m_class == wxT("wxRadioBox"))
43 {
44 // find the selection
45 long selection = GetLong( wxT("selection"), -1 );
46
47 // need to build the list of strings from children
48 m_insideBox = true;
49 CreateChildrenPrivately( NULL, GetParamNode(wxT("content")));
50
51 XRC_MAKE_INSTANCE(control, wxRadioBox)
52
53 control->Create(m_parentAsWindow,
54 GetID(),
55 GetText(wxT("label")),
56 GetPosition(), GetSize(),
57 m_labels,
58 GetLong(wxT("dimension"), 1),
59 GetStyle(),
60 wxDefaultValidator,
61 GetName());
62
63 if (selection != -1)
64 control->SetSelection(selection);
65
66 SetupWindow(control);
67
68 const unsigned count = m_labels.size();
69 for( unsigned i = 0; i < count; i++ )
70 {
71 #if wxUSE_TOOLTIPS
72 if ( !m_tooltips[i].empty() )
73 control->SetItemToolTip(i, m_tooltips[i]);
74 #endif // wxUSE_TOOLTIPS
75 #if wxUSE_HELP
76 if ( m_helptextSpecified[i] )
77 control->SetItemHelpText(i, m_helptexts[i]);
78 #endif // wxUSE_HELP
79
80 if ( !m_isShown[i] )
81 control->Show(i, false);
82 if ( !m_isEnabled[i] )
83 control->Enable(i, false);
84 }
85
86
87 // forget information about the items of this radiobox, we should start
88 // afresh for the next one
89 m_labels.clear();
90
91 #if wxUSE_TOOLTIPS
92 m_tooltips.clear();
93 #endif // wxUSE_TOOLTIPS
94
95 #if wxUSE_HELP
96 m_helptexts.clear();
97 m_helptextSpecified.clear();
98 #endif // wxUSE_HELP
99
100 m_isShown.clear();
101 m_isEnabled.clear();
102
103 return control;
104 }
105 else // inside the radiobox element
106 {
107 // we handle handle <item>Label</item> constructs here, and the item
108 // tag can have tooltip, helptext, enabled and hidden attributes
109
110 wxString label = GetNodeContent(m_node);
111
112 wxString tooltip;
113 m_node->GetAttribute(wxT("tooltip"), &tooltip);
114
115 wxString helptext;
116 bool hasHelptext = m_node->GetAttribute(wxT("helptext"), &helptext);
117
118 if (m_resource->GetFlags() & wxXRC_USE_LOCALE)
119 {
120 label = wxGetTranslation(label, m_resource->GetDomain());
121 if ( !tooltip.empty() )
122 tooltip = wxGetTranslation(tooltip, m_resource->GetDomain());
123 if ( hasHelptext )
124 helptext = wxGetTranslation(helptext, m_resource->GetDomain());
125 }
126
127 m_labels.push_back(label);
128 #if wxUSE_TOOLTIPS
129 m_tooltips.push_back(tooltip);
130 #endif // wxUSE_TOOLTIPS
131 #if wxUSE_HELP
132 m_helptexts.push_back(helptext);
133 m_helptextSpecified.push_back(hasHelptext);
134 #endif // wxUSE_HELP
135 m_isEnabled.push_back(GetBoolAttr("enabled", 1));
136 m_isShown.push_back(!GetBoolAttr("hidden", 0));
137
138 return NULL;
139 }
140
141 }
142
143 bool wxRadioBoxXmlHandler::CanHandle(wxXmlNode *node)
144 {
145 return (IsOfClass(node, wxT("wxRadioBox")) ||
146 (m_insideBox && node->GetName() == wxT("item")));
147 }
148
149 #endif // wxUSE_XRC && wxUSE_RADIOBOX