]> git.saurik.com Git - wxWidgets.git/blob - src/xrc/xh_combo.cpp
wxRTC: fixed guidelines overwriting adjacent cell borders; corrected capitalisation...
[wxWidgets.git] / src / xrc / xh_combo.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/xrc/xh_combo.cpp
3 // Purpose: XRC resource for wxComboBox
4 // Author: Bob Mitchell
5 // Created: 2000/03/21
6 // Copyright: (c) 2000 Bob Mitchell and Verant Interactive
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
9
10 // For compilers that support precompilation, includes "wx.h".
11 #include "wx/wxprec.h"
12
13 #ifdef __BORLANDC__
14 #pragma hdrstop
15 #endif
16
17 #if wxUSE_XRC && wxUSE_COMBOBOX
18
19 #include "wx/xrc/xh_combo.h"
20
21 #ifndef WX_PRECOMP
22 #include "wx/intl.h"
23 #include "wx/combobox.h"
24 #include "wx/textctrl.h" // for wxTE_PROCESS_ENTER
25 #endif
26
27 #include "wx/xml/xml.h"
28
29 IMPLEMENT_DYNAMIC_CLASS(wxComboBoxXmlHandler, wxXmlResourceHandler)
30
31 wxComboBoxXmlHandler::wxComboBoxXmlHandler()
32 :wxXmlResourceHandler()
33 ,m_insideBox(false)
34 {
35 XRC_ADD_STYLE(wxCB_SIMPLE);
36 XRC_ADD_STYLE(wxCB_SORT);
37 XRC_ADD_STYLE(wxCB_READONLY);
38 XRC_ADD_STYLE(wxCB_DROPDOWN);
39 XRC_ADD_STYLE(wxTE_PROCESS_ENTER);
40 AddWindowStyles();
41 }
42
43 wxObject *wxComboBoxXmlHandler::DoCreateResource()
44 {
45 if( m_class == wxT("wxComboBox"))
46 {
47 // find the selection
48 long selection = GetLong( wxT("selection"), -1 );
49
50 // need to build the list of strings from children
51 m_insideBox = true;
52 CreateChildrenPrivately(NULL, GetParamNode(wxT("content")));
53
54 XRC_MAKE_INSTANCE(control, wxComboBox)
55
56 control->Create(m_parentAsWindow,
57 GetID(),
58 GetText(wxT("value")),
59 GetPosition(), GetSize(),
60 strList,
61 GetStyle(),
62 wxDefaultValidator,
63 GetName());
64
65 if (selection != -1)
66 control->SetSelection(selection);
67
68 SetupWindow(control);
69
70 strList.Clear(); // dump the strings
71
72 return control;
73 }
74 else
75 {
76 // on the inside now.
77 // handle <item>Label</item>
78
79 // add to the list
80 wxString str = GetNodeContent(m_node);
81 if (m_resource->GetFlags() & wxXRC_USE_LOCALE)
82 str = wxGetTranslation(str, m_resource->GetDomain());
83 strList.Add(str);
84
85 return NULL;
86 }
87 }
88
89 bool wxComboBoxXmlHandler::CanHandle(wxXmlNode *node)
90 {
91 return (IsOfClass(node, wxT("wxComboBox")) ||
92 (m_insideBox && node->GetName() == wxT("item")));
93 }
94
95 #endif // wxUSE_XRC && wxUSE_COMBOBOX