]> git.saurik.com Git - wxWidgets.git/blob - src/xrc/xh_radbx.cpp
edbbbf6a492d4cf39d397bd9ff5e4bb2e1ccb5c6
[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 wxString *strings;
51 if ( !labels.empty() )
52 {
53 strings = new wxString[labels.size()];
54 const unsigned count = labels.size();
55 for( unsigned i = 0; i < count; i++ )
56 strings[i] = labels[i];
57 }
58 else
59 {
60 strings = NULL;
61 }
62
63 XRC_MAKE_INSTANCE(control, wxRadioBox)
64
65 control->Create(m_parentAsWindow,
66 GetID(),
67 GetText(wxT("label")),
68 GetPosition(), GetSize(),
69 labels.size(),
70 strings,
71 GetLong(wxT("dimension"), 1),
72 GetStyle(),
73 wxDefaultValidator,
74 GetName());
75
76 delete[] strings;
77
78 if (selection != -1)
79 control->SetSelection(selection);
80
81 SetupWindow(control);
82
83 #if wxUSE_TOOLTIPS
84 const unsigned count = labels.size();
85 for( unsigned i = 0; i < count; i++ )
86 {
87 if ( !tooltips[i].empty() )
88 control->SetItemToolTip(i, tooltips[i]);
89 }
90 #endif // wxUSE_TOOLTIPS
91
92 labels.clear(); // dump the strings
93 tooltips.clear(); // dump the tooltips
94
95 return control;
96 }
97 else // inside the radiobox element
98 {
99 // we handle <item tooltip="...">Label</item> constructs here
100
101 wxString str = GetNodeContent(m_node);
102 wxString tooltip;
103 m_node->GetPropVal(wxT("tooltip"), &tooltip);
104
105 if (m_resource->GetFlags() & wxXRC_USE_LOCALE)
106 {
107 str = wxGetTranslation(str);
108 if ( !tooltip.empty() )
109 tooltip = wxGetTranslation(tooltip);
110 }
111
112 labels.push_back(str);
113 tooltips.push_back(tooltip);
114
115 return NULL;
116 }
117
118 }
119
120 bool wxRadioBoxXmlHandler::CanHandle(wxXmlNode *node)
121 {
122 return (IsOfClass(node, wxT("wxRadioBox")) ||
123 (m_insideBox && node->GetName() == wxT("item")));
124 }
125
126 #endif // wxUSE_XRC && wxUSE_RADIOBOX