]> git.saurik.com Git - wxWidgets.git/blame - src/xrc/xh_radbx.cpp
improve best size calculation; notably account for wxDP_ALLOWNONE
[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
VZ
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
78d14f80 59 {
d64ad2c7 60 strings = NULL;
78d14f80
VS
61 }
62
544fee32 63 XRC_MAKE_INSTANCE(control, wxRadioBox)
f2588180
VS
64
65 control->Create(m_parentAsWindow,
66 GetID(),
67 GetText(wxT("label")),
68 GetPosition(), GetSize(),
d64ad2c7 69 labels.size(),
f2588180
VS
70 strings,
71 GetLong(wxT("dimension"), 1),
72 GetStyle(),
73 wxDefaultValidator,
74 GetName());
78d14f80 75
d64ad2c7
VZ
76 delete[] strings;
77
544fee32
VS
78 if (selection != -1)
79 control->SetSelection(selection);
78d14f80
VS
80
81 SetupWindow(control);
82
d64ad2c7
VZ
83 const unsigned count = labels.size();
84 for( unsigned i = 0; i < count; i++ )
85 {
dc26eeb3 86#if wxUSE_TOOLTIPS
d64ad2c7
VZ
87 if ( !tooltips[i].empty() )
88 control->SetItemToolTip(i, tooltips[i]);
7577ac4b 89#endif // wxUSE_TOOLTIPS
dc26eeb3
VZ
90#if wxUSE_HELP
91 if ( helptextSpecified[i] )
92 control->SetItemHelpText(i, helptexts[i]);
93#endif // wxUSE_HELP
94 }
d64ad2c7
VZ
95
96 labels.clear(); // dump the strings
dc26eeb3 97
d64ad2c7 98 tooltips.clear(); // dump the tooltips
78d14f80 99
dc26eeb3
VZ
100 helptexts.clear(); // dump the helptexts
101 helptextSpecified.clear();
102
78d14f80
VS
103 return control;
104 }
d64ad2c7 105 else // inside the radiobox element
78d14f80 106 {
dc26eeb3 107 // we handle handle <item tooltip="..." helptext="...">Label</item> constructs here
78d14f80 108
74c107ba 109 wxString str = 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 {
d4a724d4 119 str = wxGetTranslation(str, 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
126 labels.push_back(str);
127 tooltips.push_back(tooltip);
dc26eeb3
VZ
128 helptexts.push_back(helptext);
129 helptextSpecified.push_back(hasHelptext);
78d14f80
VS
130
131 return NULL;
132 }
133
134}
135
78d14f80
VS
136bool wxRadioBoxXmlHandler::CanHandle(wxXmlNode *node)
137{
138 return (IsOfClass(node, wxT("wxRadioBox")) ||
544fee32 139 (m_insideBox && node->GetName() == wxT("item")));
78d14f80
VS
140}
141
a1e4ec87 142#endif // wxUSE_XRC && wxUSE_RADIOBOX