]> git.saurik.com Git - wxWidgets.git/blob - src/xrc/xh_editlbox.cpp
Remove all lines containing cvs/svn "$Id$" keyword.
[wxWidgets.git] / src / xrc / xh_editlbox.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/xrc/xh_editlbox.cpp
3 // Purpose: implementation of wxEditableListBox XRC handler
4 // Author: Vadim Zeitlin
5 // Created: 2009-06-04
6 // Copyright: (c) 2009 Vadim Zeitlin <vadim@wxwidgets.org>
7 // Licence: wxWindows licence
8 ///////////////////////////////////////////////////////////////////////////////
9
10 // ============================================================================
11 // declarations
12 // ============================================================================
13
14 // ----------------------------------------------------------------------------
15 // headers
16 // ----------------------------------------------------------------------------
17
18 // for compilers that support precompilation, includes "wx.h".
19 #include "wx/wxprec.h"
20
21 #ifdef __BORLANDC__
22 #pragma hdrstop
23 #endif
24
25 #if wxUSE_XRC && wxUSE_EDITABLELISTBOX
26
27 #ifndef WX_PRECOMP
28 #include "wx/intl.h"
29 #endif // WX_PRECOMP
30
31 #include "wx/editlbox.h"
32 #include "wx/xrc/xh_editlbox.h"
33
34 #include "wx/xml/xml.h"
35
36 // ----------------------------------------------------------------------------
37 // constants
38 // ----------------------------------------------------------------------------
39
40 namespace
41 {
42
43 const char * const EDITLBOX_CLASS_NAME = "wxEditableListBox";
44 const char * const EDITLBOX_ITEM_NAME = "item";
45
46 } // anonymous namespace
47
48 // ============================================================================
49 // implementation
50 // ============================================================================
51
52 IMPLEMENT_DYNAMIC_CLASS(wxEditableListBoxXmlHandler, wxXmlResourceHandler)
53
54 wxEditableListBoxXmlHandler::wxEditableListBoxXmlHandler()
55 {
56 m_insideBox = false;
57
58 XRC_ADD_STYLE(wxEL_ALLOW_NEW);
59 XRC_ADD_STYLE(wxEL_ALLOW_EDIT);
60 XRC_ADD_STYLE(wxEL_ALLOW_DELETE);
61 XRC_ADD_STYLE(wxEL_NO_REORDER);
62
63 AddWindowStyles();
64 }
65
66 wxObject *wxEditableListBoxXmlHandler::DoCreateResource()
67 {
68 if ( m_class == EDITLBOX_CLASS_NAME )
69 {
70 // create the control itself
71 XRC_MAKE_INSTANCE(control, wxEditableListBox)
72
73 control->Create
74 (
75 m_parentAsWindow,
76 GetID(),
77 GetText("label"),
78 GetPosition(),
79 GetSize(),
80 GetStyle(),
81 GetName()
82 );
83
84 SetupWindow(control);
85
86 // if any items are given, add them to the control
87 wxXmlNode * const contents = GetParamNode("content");
88 if ( contents )
89 {
90 m_insideBox = true;
91 CreateChildrenPrivately(NULL, contents);
92 m_insideBox = false;
93
94 control->SetStrings(m_items);
95 m_items.clear();
96 }
97
98 return control;
99 }
100 else if ( m_insideBox && m_node->GetName() == EDITLBOX_ITEM_NAME )
101 {
102 wxString str = GetNodeContent(m_node);
103 if ( m_resource->GetFlags() & wxXRC_USE_LOCALE )
104 str = wxGetTranslation(str, m_resource->GetDomain());
105 m_items.push_back(str);
106
107 return NULL;
108 }
109 else
110 {
111 ReportError("Unexpected node inside wxEditableListBox");
112 return NULL;
113 }
114 }
115
116 bool wxEditableListBoxXmlHandler::CanHandle(wxXmlNode *node)
117 {
118 return IsOfClass(node, EDITLBOX_CLASS_NAME) ||
119 (m_insideBox && node->GetName() == EDITLBOX_ITEM_NAME);
120 }
121
122
123 #endif // wxUSE_XRC && wxUSE_EDITABLELISTBOX