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