]> git.saurik.com Git - wxWidgets.git/blame - src/xrc/xh_radbx.cpp
new file added
[wxWidgets.git] / src / xrc / xh_radbx.cpp
CommitLineData
78d14f80 1/////////////////////////////////////////////////////////////////////////////
88a7a4e1 2// Name: src/xrc/xh_radbx.cpp
b5d6954b 3// Purpose: XRC resource for wxRadioBox
78d14f80
VS
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/////////////////////////////////////////////////////////////////////////////
f80ea77b 10
78d14f80
VS
11// For compilers that support precompilation, includes "wx.h".
12#include "wx/wxprec.h"
13
14#ifdef __BORLANDC__
15 #pragma hdrstop
16#endif
17
621be1ec 18#if wxUSE_XRC && wxUSE_RADIOBOX
a1e4ec87 19
78d14f80 20#include "wx/xrc/xh_radbx.h"
88a7a4e1
WS
21
22#ifndef WX_PRECOMP
23 #include "wx/intl.h"
cc11cc69 24 #include "wx/radiobox.h"
88a7a4e1
WS
25#endif
26
854e189f
VS
27IMPLEMENT_DYNAMIC_CLASS(wxRadioBoxXmlHandler, wxXmlResourceHandler)
28
f80ea77b
WS
29wxRadioBoxXmlHandler::wxRadioBoxXmlHandler()
30: wxXmlResourceHandler(), m_insideBox(false)
78d14f80 31{
544fee32
VS
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);
78d14f80
VS
36 AddWindowStyles();
37}
38
39wxObject *wxRadioBoxXmlHandler::DoCreateResource()
f80ea77b 40{
d64ad2c7 41 if ( m_class == wxT("wxRadioBox"))
78d14f80
VS
42 {
43 // find the selection
44 long selection = GetLong( wxT("selection"), -1 );
45
46 // need to build the list of strings from children
f80ea77b 47 m_insideBox = true;
78d14f80 48 CreateChildrenPrivately( NULL, GetParamNode(wxT("content")));
d64ad2c7 49
544fee32 50 XRC_MAKE_INSTANCE(control, wxRadioBox)
f2588180
VS
51
52 control->Create(m_parentAsWindow,
53 GetID(),
54 GetText(wxT("label")),
55 GetPosition(), GetSize(),
8758875e 56 m_labels,
f2588180
VS
57 GetLong(wxT("dimension"), 1),
58 GetStyle(),
59 wxDefaultValidator,
60 GetName());
78d14f80 61
544fee32
VS
62 if (selection != -1)
63 control->SetSelection(selection);
78d14f80
VS
64
65 SetupWindow(control);
66
8758875e 67 const unsigned count = m_labels.size();
d64ad2c7
VZ
68 for( unsigned i = 0; i < count; i++ )
69 {
dc26eeb3 70#if wxUSE_TOOLTIPS
8758875e
VZ
71 if ( !m_tooltips[i].empty() )
72 control->SetItemToolTip(i, m_tooltips[i]);
7577ac4b 73#endif // wxUSE_TOOLTIPS
dc26eeb3 74#if wxUSE_HELP
8758875e
VZ
75 if ( m_helptextSpecified[i] )
76 control->SetItemHelpText(i, m_helptexts[i]);
dc26eeb3 77#endif // wxUSE_HELP
8758875e
VZ
78
79 if ( !m_isShown[i] )
80 control->Show(i, false);
81 if ( !m_isEnabled[i] )
82 control->Enable(i, false);
dc26eeb3 83 }
d64ad2c7 84
dc26eeb3 85
8758875e
VZ
86 // forget information about the items of this radiobox, we should start
87 // afresh for the next one
88 m_labels.clear();
78d14f80 89
8758875e
VZ
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();
dc26eeb3 101
78d14f80
VS
102 return control;
103 }
d64ad2c7 104 else // inside the radiobox element
78d14f80 105 {
8758875e
VZ
106 // we handle handle <item>Label</item> constructs here, and the item
107 // tag can have tooltip, helptext, enabled and hidden attributes
78d14f80 108
8758875e 109 wxString label = GetNodeContent(m_node);
dc26eeb3 110
d64ad2c7 111 wxString tooltip;
288b6107 112 m_node->GetAttribute(wxT("tooltip"), &tooltip);
d64ad2c7 113
dc26eeb3 114 wxString helptext;
288b6107 115 bool hasHelptext = m_node->GetAttribute(wxT("helptext"), &helptext);
dc26eeb3 116
74c107ba 117 if (m_resource->GetFlags() & wxXRC_USE_LOCALE)
d64ad2c7 118 {
8758875e 119 label = wxGetTranslation(label, m_resource->GetDomain());
d64ad2c7 120 if ( !tooltip.empty() )
d4a724d4 121 tooltip = wxGetTranslation(tooltip, m_resource->GetDomain());
dc26eeb3 122 if ( hasHelptext )
d4a724d4 123 helptext = wxGetTranslation(helptext, m_resource->GetDomain());
d64ad2c7
VZ
124 }
125
8758875e
VZ
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));
78d14f80
VS
136
137 return NULL;
138 }
139
140}
141
78d14f80
VS
142bool wxRadioBoxXmlHandler::CanHandle(wxXmlNode *node)
143{
144 return (IsOfClass(node, wxT("wxRadioBox")) ||
544fee32 145 (m_insideBox && node->GetName() == wxT("item")));
78d14f80
VS
146}
147
a1e4ec87 148#endif // wxUSE_XRC && wxUSE_RADIOBOX