]> git.saurik.com Git - wxWidgets.git/blob - src/xrc/xh_odcombo.cpp
Added style wxTE_PROCESS_ENTER for wxOwnerDrawnComboBox
[wxWidgets.git] / src / xrc / xh_odcombo.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/xrc/xh_odcombo.cpp
3 // Purpose: XRC resource for wxRadioBox
4 // Author: Alex Bligh - Based on src/xrc/xh_combo.cpp
5 // Created: 2006/06/19
6 // RCS-ID: $Id$
7 // Copyright: (c) 2006 Alex Bligh
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_ODCOMBOBOX
19
20 #include "wx/xrc/xh_odcombo.h"
21
22 #ifndef WX_PRECOMP
23 #include "wx/intl.h"
24 #endif
25
26 #include "wx/odcombo.h"
27
28 IMPLEMENT_DYNAMIC_CLASS(wxOwnerDrawnComboBoxXmlHandler, wxXmlResourceHandler)
29
30 wxOwnerDrawnComboBoxXmlHandler::wxOwnerDrawnComboBoxXmlHandler()
31 :wxXmlResourceHandler()
32 ,m_insideBox(false)
33 {
34 XRC_ADD_STYLE(wxCB_SIMPLE);
35 XRC_ADD_STYLE(wxCB_SORT);
36 XRC_ADD_STYLE(wxCB_READONLY);
37 XRC_ADD_STYLE(wxCB_DROPDOWN);
38 XRC_ADD_STYLE(wxODCB_STD_CONTROL_PAINT);
39 XRC_ADD_STYLE(wxODCB_DCLICK_CYCLES);
40 XRC_ADD_STYLE(wxTE_PROCESS_ENTER);
41 AddWindowStyles();
42 }
43
44 wxObject *wxOwnerDrawnComboBoxXmlHandler::DoCreateResource()
45 {
46 if( m_class == wxT("wxOwnerDrawnComboBox"))
47 {
48 // find the selection
49 long selection = GetLong( wxT("selection"), -1 );
50
51 // need to build the list of strings from children
52 m_insideBox = true;
53 CreateChildrenPrivately(NULL, GetParamNode(wxT("content")));
54 wxString *strings = (wxString *) NULL;
55 if (strList.GetCount() > 0)
56 {
57 strings = new wxString[strList.GetCount()];
58 int count = strList.GetCount();
59 for (int i = 0; i < count; i++)
60 strings[i]=strList[i];
61 }
62
63 XRC_MAKE_INSTANCE(control, wxOwnerDrawnComboBox)
64
65 control->Create(m_parentAsWindow,
66 GetID(),
67 GetText(wxT("value")),
68 GetPosition(), GetSize(),
69 strList.GetCount(),
70 strings,
71 GetStyle(),
72 wxDefaultValidator,
73 GetName());
74
75 wxSize ButtonSize=GetSize(wxT("buttonsize"));
76
77 if (ButtonSize != wxDefaultSize)
78 control->SetButtonPosition(ButtonSize.GetWidth(), ButtonSize.GetHeight());
79
80 if (selection != -1)
81 control->SetSelection(selection);
82
83 SetupWindow(control);
84
85 if (strings != NULL)
86 delete[] strings;
87 strList.Clear(); // dump the strings
88
89 return control;
90 }
91 else
92 {
93 // on the inside now.
94 // handle <item>Label</item>
95
96 // add to the list
97 wxString str = GetNodeContent(m_node);
98 if (m_resource->GetFlags() & wxXRC_USE_LOCALE)
99 str = wxGetTranslation(str);
100 strList.Add(str);
101
102 return NULL;
103 }
104 }
105
106 bool wxOwnerDrawnComboBoxXmlHandler::CanHandle(wxXmlNode *node)
107 {
108 // Avoid GCC bug - this fails on certain GCC 3.x builds for an unknown reason
109 // return (IsOfClass(node, wxT("wxOwnerDrawnComboBox")) ||
110 // (m_insideBox && node->GetName() == wxT("item")));
111
112 bool fOurClass = node->GetPropVal(wxT("class"), wxEmptyString) == wxT("wxOwnerDrawnComboBox");
113 return (fOurClass ||
114 (m_insideBox && node->GetName() == wxT("item")));
115
116 }
117
118 #endif // wxUSE_XRC && wxUSE_ODCOMBOBOX