added support for radiobox items tooltips in XRC
[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 #endif
25
26 #include "wx/radiobox.h"
27
28 IMPLEMENT_DYNAMIC_CLASS(wxRadioBoxXmlHandler, wxXmlResourceHandler)
29
30 wxRadioBoxXmlHandler::wxRadioBoxXmlHandler()
31 : wxXmlResourceHandler(), m_insideBox(false)
32 {
33 XRC_ADD_STYLE(wxRA_SPECIFY_COLS);
34 XRC_ADD_STYLE(wxRA_HORIZONTAL);
35 XRC_ADD_STYLE(wxRA_SPECIFY_ROWS);
36 XRC_ADD_STYLE(wxRA_VERTICAL);
37 AddWindowStyles();
38 }
39
40 wxObject *wxRadioBoxXmlHandler::DoCreateResource()
41 {
42 if ( m_class == wxT("wxRadioBox"))
43 {
44 // find the selection
45 long selection = GetLong( wxT("selection"), -1 );
46
47 // need to build the list of strings from children
48 m_insideBox = true;
49 CreateChildrenPrivately( NULL, GetParamNode(wxT("content")));
50
51 wxString *strings;
52 if ( !labels.empty() )
53 {
54 strings = new wxString[labels.size()];
55 const unsigned count = labels.size();
56 for( unsigned i = 0; i < count; i++ )
57 strings[i] = labels[i];
58 }
59 else
60 {
61 strings = NULL;
62 }
63
64 XRC_MAKE_INSTANCE(control, wxRadioBox)
65
66 control->Create(m_parentAsWindow,
67 GetID(),
68 GetText(wxT("label")),
69 GetPosition(), GetSize(),
70 labels.size(),
71 strings,
72 GetLong(wxT("dimension"), 1),
73 GetStyle(),
74 wxDefaultValidator,
75 GetName());
76
77 delete[] strings;
78
79 if (selection != -1)
80 control->SetSelection(selection);
81
82 SetupWindow(control);
83
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
91 labels.clear(); // dump the strings
92 tooltips.clear(); // dump the tooltips
93
94 return control;
95 }
96 else // inside the radiobox element
97 {
98 // we handle <item tooltip="...">Label</item> constructs here
99
100 wxString str = GetNodeContent(m_node);
101 wxString tooltip;
102 m_node->GetPropVal(wxT("tooltip"), &tooltip);
103
104 if (m_resource->GetFlags() & wxXRC_USE_LOCALE)
105 {
106 str = wxGetTranslation(str);
107 if ( !tooltip.empty() )
108 tooltip = wxGetTranslation(tooltip);
109 }
110
111 labels.push_back(str);
112 tooltips.push_back(tooltip);
113
114 return NULL;
115 }
116
117 }
118
119 bool wxRadioBoxXmlHandler::CanHandle(wxXmlNode *node)
120 {
121 return (IsOfClass(node, wxT("wxRadioBox")) ||
122 (m_insideBox && node->GetName() == wxT("item")));
123 }
124
125 #endif // wxUSE_XRC && wxUSE_RADIOBOX