]> git.saurik.com Git - wxWidgets.git/blob - src/xrc/xh_combo.cpp
finished implementation for stencil and colored patterns
[wxWidgets.git] / src / xrc / xh_combo.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: xh_combo.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_COMBOBOX
19
20 #include "wx/xrc/xh_combo.h"
21 #include "wx/combobox.h"
22 #include "wx/intl.h"
23
24 IMPLEMENT_DYNAMIC_CLASS(wxComboBoxXmlHandler, wxXmlResourceHandler)
25
26 wxComboBoxXmlHandler::wxComboBoxXmlHandler()
27 : wxXmlResourceHandler() , m_insideBox(false)
28 {
29 XRC_ADD_STYLE(wxCB_SIMPLE);
30 XRC_ADD_STYLE(wxCB_SORT);
31 XRC_ADD_STYLE(wxCB_READONLY);
32 XRC_ADD_STYLE(wxCB_DROPDOWN);
33 AddWindowStyles();
34 }
35
36 wxObject *wxComboBoxXmlHandler::DoCreateResource()
37 {
38 if( m_class == wxT("wxComboBox"))
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, wxComboBox)
56
57 control->Create(m_parentAsWindow,
58 GetID(),
59 GetText(wxT("value")),
60 GetPosition(), GetSize(),
61 strList.GetCount(),
62 strings,
63 GetStyle(),
64 wxDefaultValidator,
65 GetName());
66
67 if (selection != -1)
68 control->SetSelection(selection);
69
70 SetupWindow(control);
71
72 if (strings != NULL)
73 delete[] strings;
74 strList.Clear(); // dump the strings
75
76 return control;
77 }
78 else
79 {
80 // on the inside now.
81 // handle <item>Label</item>
82
83 // add to the list
84 wxString str = GetNodeContent(m_node);
85 if (m_resource->GetFlags() & wxXRC_USE_LOCALE)
86 str = wxGetTranslation(str);
87 strList.Add(str);
88
89 return NULL;
90 }
91 }
92
93 bool wxComboBoxXmlHandler::CanHandle(wxXmlNode *node)
94 {
95 return (IsOfClass(node, wxT("wxComboBox")) ||
96 (m_insideBox && node->GetName() == wxT("item")));
97 }
98
99 #endif // wxUSE_XRC && wxUSE_COMBOBOX