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