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