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
7 // Copyright: (c) 2006 Alex Bligh
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 // For compilers that support precompilation, includes "wx.h".
12 #include "wx/wxprec.h"
18 #if wxUSE_XRC && wxUSE_ODCOMBOBOX
20 #include "wx/xrc/xh_odcombo.h"
24 #include "wx/textctrl.h"
27 #include "wx/odcombo.h"
29 IMPLEMENT_DYNAMIC_CLASS(wxOwnerDrawnComboBoxXmlHandler
, wxXmlResourceHandler
)
31 wxOwnerDrawnComboBoxXmlHandler::wxOwnerDrawnComboBoxXmlHandler()
32 :wxXmlResourceHandler()
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(wxODCB_STD_CONTROL_PAINT
);
40 XRC_ADD_STYLE(wxODCB_DCLICK_CYCLES
);
41 XRC_ADD_STYLE(wxTE_PROCESS_ENTER
);
45 wxObject
*wxOwnerDrawnComboBoxXmlHandler::DoCreateResource()
47 if( m_class
== wxT("wxOwnerDrawnComboBox"))
50 long selection
= GetLong( wxT("selection"), -1 );
52 // need to build the list of strings from children
54 CreateChildrenPrivately(NULL
, GetParamNode(wxT("content")));
55 wxString
*strings
= (wxString
*) NULL
;
56 if (strList
.GetCount() > 0)
58 strings
= new wxString
[strList
.GetCount()];
59 int count
= strList
.GetCount();
60 for (int i
= 0; i
< count
; i
++)
61 strings
[i
]=strList
[i
];
64 XRC_MAKE_INSTANCE(control
, wxOwnerDrawnComboBox
)
66 control
->Create(m_parentAsWindow
,
68 GetText(wxT("value")),
69 GetPosition(), GetSize(),
76 wxSize ButtonSize
=GetSize(wxT("buttonsize"));
78 if (ButtonSize
!= wxDefaultSize
)
79 control
->SetButtonPosition(ButtonSize
.GetWidth(), ButtonSize
.GetHeight());
82 control
->SetSelection(selection
);
88 strList
.Clear(); // dump the strings
95 // handle <item>Label</item>
98 wxString str
= GetNodeContent(m_node
);
99 if (m_resource
->GetFlags() & wxXRC_USE_LOCALE
)
100 str
= wxGetTranslation(str
, m_resource
->GetDomain());
107 bool wxOwnerDrawnComboBoxXmlHandler::CanHandle(wxXmlNode
*node
)
109 #if wxCHECK_VERSION(2,7,0)
111 return (IsOfClass(node
, wxT("wxOwnerDrawnComboBox")) ||
112 (m_insideBox
&& node
->GetName() == wxT("item")));
116 // Avoid GCC bug - this fails on certain GCC 3.3 and 3.4 builds for an unknown reason
117 // it is believed to be related to the fact IsOfClass is inline, and node->GetPropVal
118 // gets passed an invalid "this" pointer. On 2.7, the function is out of line, so the
119 // above should work fine. This code is left in here so this file can easily be used
120 // in a version backported to 2.6. All we are doing here is expanding the macro
122 bool fOurClass
= node
->GetPropVal(wxT("class"), wxEmptyString
) == wxT("wxOwnerDrawnComboBox");
124 (m_insideBox
&& node
->GetName() == wxT("item")));
128 #endif // wxUSE_XRC && wxUSE_ODCOMBOBOX