]>
Commit | Line | Data |
---|---|---|
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 |
27 | IMPLEMENT_DYNAMIC_CLASS(wxRadioBoxXmlHandler, wxXmlResourceHandler) |
28 | ||
f80ea77b WS |
29 | wxRadioBoxXmlHandler::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 | ||
39 | wxObject *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 | ||
7577ac4b | 83 | #if wxUSE_TOOLTIPS |
d64ad2c7 VZ |
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 | } | |
7577ac4b | 90 | #endif // wxUSE_TOOLTIPS |
d64ad2c7 VZ |
91 | |
92 | labels.clear(); // dump the strings | |
93 | tooltips.clear(); // dump the tooltips | |
78d14f80 VS |
94 | |
95 | return control; | |
96 | } | |
d64ad2c7 | 97 | else // inside the radiobox element |
78d14f80 | 98 | { |
d64ad2c7 | 99 | // we handle <item tooltip="...">Label</item> constructs here |
78d14f80 | 100 | |
74c107ba | 101 | wxString str = GetNodeContent(m_node); |
d64ad2c7 VZ |
102 | wxString tooltip; |
103 | m_node->GetPropVal(wxT("tooltip"), &tooltip); | |
104 | ||
74c107ba | 105 | if (m_resource->GetFlags() & wxXRC_USE_LOCALE) |
d64ad2c7 | 106 | { |
74c107ba | 107 | str = wxGetTranslation(str); |
d64ad2c7 VZ |
108 | if ( !tooltip.empty() ) |
109 | tooltip = wxGetTranslation(tooltip); | |
110 | } | |
111 | ||
112 | labels.push_back(str); | |
113 | tooltips.push_back(tooltip); | |
78d14f80 VS |
114 | |
115 | return NULL; | |
116 | } | |
117 | ||
118 | } | |
119 | ||
78d14f80 VS |
120 | bool wxRadioBoxXmlHandler::CanHandle(wxXmlNode *node) |
121 | { | |
122 | return (IsOfClass(node, wxT("wxRadioBox")) || | |
544fee32 | 123 | (m_insideBox && node->GetName() == wxT("item"))); |
78d14f80 VS |
124 | } |
125 | ||
a1e4ec87 | 126 | #endif // wxUSE_XRC && wxUSE_RADIOBOX |