]> git.saurik.com Git - wxWidgets.git/blob - src/xrc/xh_radbx.cpp
Include wx/list.h according to precompiled headers of wx/wx.h (with other minor clean...
[wxWidgets.git] / src / xrc / xh_radbx.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: 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 #include "wx/radiobox.h"
22 #include "wx/intl.h"
23
24 IMPLEMENT_DYNAMIC_CLASS(wxRadioBoxXmlHandler, wxXmlResourceHandler)
25
26 wxRadioBoxXmlHandler::wxRadioBoxXmlHandler()
27 : wxXmlResourceHandler(), m_insideBox(false)
28 {
29 XRC_ADD_STYLE(wxRA_SPECIFY_COLS);
30 XRC_ADD_STYLE(wxRA_HORIZONTAL);
31 XRC_ADD_STYLE(wxRA_SPECIFY_ROWS);
32 XRC_ADD_STYLE(wxRA_VERTICAL);
33 AddWindowStyles();
34 }
35
36 wxObject *wxRadioBoxXmlHandler::DoCreateResource()
37 {
38 if( m_class == wxT("wxRadioBox"))
39 {
40 // find the selection
41 long selection = GetLong( wxT("selection"), -1 );
42
43 // need to build the list of strings from children
44 m_insideBox = true;
45 CreateChildrenPrivately( NULL, GetParamNode(wxT("content")));
46 wxString *strings = (wxString *) NULL;
47 if( strList.GetCount() > 0 )
48 {
49 strings = new wxString[strList.GetCount()];
50 int count = strList.GetCount();
51 for( int i = 0; i < count; i++ )
52 strings[i]=strList[i];
53 }
54
55 XRC_MAKE_INSTANCE(control, wxRadioBox)
56
57 control->Create(m_parentAsWindow,
58 GetID(),
59 GetText(wxT("label")),
60 GetPosition(), GetSize(),
61 strList.GetCount(),
62 strings,
63 GetLong(wxT("dimension"), 1),
64 GetStyle(),
65 wxDefaultValidator,
66 GetName());
67
68 if (selection != -1)
69 control->SetSelection(selection);
70
71 SetupWindow(control);
72
73 if (strings != NULL)
74 delete[] strings;
75 strList.Clear(); // dump the strings
76
77 return control;
78 }
79 else
80 {
81 // on the inside now.
82 // handle <item selected="boolean">Label</item>
83
84 // add to the list
85 wxString str = GetNodeContent(m_node);
86 if (m_resource->GetFlags() & wxXRC_USE_LOCALE)
87 str = wxGetTranslation(str);
88 strList.Add(str);
89
90 return NULL;
91 }
92
93 }
94
95 bool wxRadioBoxXmlHandler::CanHandle(wxXmlNode *node)
96 {
97 return (IsOfClass(node, wxT("wxRadioBox")) ||
98 (m_insideBox && node->GetName() == wxT("item")));
99 }
100
101 #endif // wxUSE_XRC && wxUSE_RADIOBOX