| 1 |
#include "MyComboBoxXmlHandler.h" |
| 2 |
#include <wx/combobox.h> |
| 3 |
#include <wx/xml/xml.h> |
| 4 |
#include <wx/xrc/xmlres.h> |
| 5 |
|
| 6 |
MyComboBoxXmlHandler::MyComboBoxXmlHandler() |
| 7 |
: wxXmlResourceHandler() |
| 8 |
, m_insideBox(false) |
| 9 |
{ |
| 10 |
XRC_ADD_STYLE(wxCB_SIMPLE); |
| 11 |
XRC_ADD_STYLE(wxCB_SORT); |
| 12 |
XRC_ADD_STYLE(wxCB_READONLY); |
| 13 |
XRC_ADD_STYLE(wxCB_DROPDOWN); |
| 14 |
XRC_ADD_STYLE(wxTE_PROCESS_ENTER); |
| 15 |
AddWindowStyles(); |
| 16 |
} |
| 17 |
|
| 18 |
MyComboBoxXmlHandler::~MyComboBoxXmlHandler() {} |
| 19 |
|
| 20 |
wxObject* MyComboBoxXmlHandler::DoCreateResource() |
| 21 |
{ |
| 22 |
if(m_class == wxT("wxComboBox")) { |
| 23 |
// find the selection |
| 24 |
long selection = GetLong(wxT("selection"), -1); |
| 25 |
|
| 26 |
// need to build the list of strings from children |
| 27 |
m_insideBox = true; |
| 28 |
CreateChildrenPrivately(NULL, GetParamNode(wxT("content"))); |
| 29 |
|
| 30 |
XRC_MAKE_INSTANCE(control, wxComboBox) |
| 31 |
|
| 32 |
control->Create(m_parentAsWindow, GetID(), GetText(wxT("value")), GetPosition(), GetSize(), strList, GetStyle(), |
| 33 |
wxDefaultValidator, GetName()); |
| 34 |
|
| 35 |
if(selection != -1) control->SetSelection(selection); |
| 36 |
|
| 37 |
if(HasParam("hint")) { control->SetHint(GetText("hint")); } |
| 38 |
|
| 39 |
SetupWindow(control); |
| 40 |
|
| 41 |
strList.Clear(); // dump the strings |
| 42 |
|
| 43 |
return control; |
| 44 |
} else { |
| 45 |
// on the inside now. |
| 46 |
// handle <item>Label</item> |
| 47 |
|
| 48 |
// add to the list |
| 49 |
wxString str = GetNodeContent(m_node); |
| 50 |
if(m_resource->GetFlags() & wxXRC_USE_LOCALE) str = wxGetTranslation(str, m_resource->GetDomain()); |
| 51 |
strList.Add(str); |
| 52 |
|
| 53 |
return NULL; |
| 54 |
} |
| 55 |
} |
| 56 |
|
| 57 |
bool MyComboBoxXmlHandler::CanHandle(wxXmlNode* node) |
| 58 |
{ |
| 59 |
return (IsOfClass(node, wxT("wxComboBox")) || (m_insideBox && node->GetName() == wxT("item"))); |
| 60 |
} |