]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/xrc/xh_radbx.cpp
remove superfluous assert
[wxWidgets.git] / src / xrc / xh_radbx.cpp
... / ...
CommitLineData
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
27IMPLEMENT_DYNAMIC_CLASS(wxRadioBoxXmlHandler, wxXmlResourceHandler)
28
29wxRadioBoxXmlHandler::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
39wxObject *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 const unsigned count = labels.size();
84 for( unsigned i = 0; i < count; i++ )
85 {
86#if wxUSE_TOOLTIPS
87 if ( !tooltips[i].empty() )
88 control->SetItemToolTip(i, tooltips[i]);
89#endif // wxUSE_TOOLTIPS
90#if wxUSE_HELP
91 if ( helptextSpecified[i] )
92 control->SetItemHelpText(i, helptexts[i]);
93#endif // wxUSE_HELP
94 }
95
96 labels.clear(); // dump the strings
97
98 tooltips.clear(); // dump the tooltips
99
100 helptexts.clear(); // dump the helptexts
101 helptextSpecified.clear();
102
103 return control;
104 }
105 else // inside the radiobox element
106 {
107 // we handle handle <item tooltip="..." helptext="...">Label</item> constructs here
108
109 wxString str = GetNodeContent(m_node);
110
111 wxString tooltip;
112 m_node->GetPropVal(wxT("tooltip"), &tooltip);
113
114 wxString helptext;
115 bool hasHelptext = m_node->GetPropVal(wxT("helptext"), &helptext);
116
117 if (m_resource->GetFlags() & wxXRC_USE_LOCALE)
118 {
119 str = wxGetTranslation(str, 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 labels.push_back(str);
127 tooltips.push_back(tooltip);
128 helptexts.push_back(helptext);
129 helptextSpecified.push_back(hasHelptext);
130
131 return NULL;
132 }
133
134}
135
136bool wxRadioBoxXmlHandler::CanHandle(wxXmlNode *node)
137{
138 return (IsOfClass(node, wxT("wxRadioBox")) ||
139 (m_insideBox && node->GetName() == wxT("item")));
140}
141
142#endif // wxUSE_XRC && wxUSE_RADIOBOX