]>
Commit | Line | Data |
---|---|---|
582f07c2 WS |
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 | |
582f07c2 WS |
6 | // Copyright: (c) 2006 Alex Bligh |
7 | // Licence: wxWindows licence | |
8 | ///////////////////////////////////////////////////////////////////////////// | |
9 | ||
10 | // For compilers that support precompilation, includes "wx.h". | |
11 | #include "wx/wxprec.h" | |
12 | ||
13 | #ifdef __BORLANDC__ | |
14 | #pragma hdrstop | |
15 | #endif | |
16 | ||
17 | #if wxUSE_XRC && wxUSE_ODCOMBOBOX | |
18 | ||
19 | #include "wx/xrc/xh_odcombo.h" | |
20 | ||
21 | #ifndef WX_PRECOMP | |
22 | #include "wx/intl.h" | |
8fdc4ac7 | 23 | #include "wx/textctrl.h" |
582f07c2 WS |
24 | #endif |
25 | ||
26 | #include "wx/odcombo.h" | |
27 | ||
df27f1dc VZ |
28 | #include "wx/xml/xml.h" |
29 | ||
582f07c2 WS |
30 | IMPLEMENT_DYNAMIC_CLASS(wxOwnerDrawnComboBoxXmlHandler, wxXmlResourceHandler) |
31 | ||
32 | wxOwnerDrawnComboBoxXmlHandler::wxOwnerDrawnComboBoxXmlHandler() | |
33 | :wxXmlResourceHandler() | |
34 | ,m_insideBox(false) | |
35 | { | |
36 | XRC_ADD_STYLE(wxCB_SIMPLE); | |
37 | XRC_ADD_STYLE(wxCB_SORT); | |
38 | XRC_ADD_STYLE(wxCB_READONLY); | |
39 | XRC_ADD_STYLE(wxCB_DROPDOWN); | |
40 | XRC_ADD_STYLE(wxODCB_STD_CONTROL_PAINT); | |
41 | XRC_ADD_STYLE(wxODCB_DCLICK_CYCLES); | |
205515af | 42 | XRC_ADD_STYLE(wxTE_PROCESS_ENTER); |
582f07c2 WS |
43 | AddWindowStyles(); |
44 | } | |
45 | ||
46 | wxObject *wxOwnerDrawnComboBoxXmlHandler::DoCreateResource() | |
47 | { | |
48 | if( m_class == wxT("wxOwnerDrawnComboBox")) | |
49 | { | |
50 | // find the selection | |
51 | long selection = GetLong( wxT("selection"), -1 ); | |
52 | ||
53 | // need to build the list of strings from children | |
54 | m_insideBox = true; | |
55 | CreateChildrenPrivately(NULL, GetParamNode(wxT("content"))); | |
582f07c2 WS |
56 | |
57 | XRC_MAKE_INSTANCE(control, wxOwnerDrawnComboBox) | |
58 | ||
59 | control->Create(m_parentAsWindow, | |
60 | GetID(), | |
61 | GetText(wxT("value")), | |
62 | GetPosition(), GetSize(), | |
187d8152 | 63 | strList, |
582f07c2 WS |
64 | GetStyle(), |
65 | wxDefaultValidator, | |
66 | GetName()); | |
67 | ||
187d8152 | 68 | wxSize sizeBtn=GetSize(wxT("buttonsize")); |
582f07c2 | 69 | |
187d8152 VZ |
70 | if (sizeBtn != wxDefaultSize) |
71 | control->SetButtonPosition(sizeBtn.GetWidth(), sizeBtn.GetHeight()); | |
582f07c2 WS |
72 | |
73 | if (selection != -1) | |
74 | control->SetSelection(selection); | |
75 | ||
76 | SetupWindow(control); | |
77 | ||
582f07c2 WS |
78 | strList.Clear(); // dump the strings |
79 | ||
80 | return control; | |
81 | } | |
82 | else | |
83 | { | |
84 | // on the inside now. | |
85 | // handle <item>Label</item> | |
86 | ||
87 | // add to the list | |
88 | wxString str = GetNodeContent(m_node); | |
89 | if (m_resource->GetFlags() & wxXRC_USE_LOCALE) | |
d4a724d4 | 90 | str = wxGetTranslation(str, m_resource->GetDomain()); |
582f07c2 WS |
91 | strList.Add(str); |
92 | ||
93 | return NULL; | |
94 | } | |
95 | } | |
96 | ||
97 | bool wxOwnerDrawnComboBoxXmlHandler::CanHandle(wxXmlNode *node) | |
98 | { | |
728e18f6 | 99 | #if wxCHECK_VERSION(2,7,0) |
9366ec4e AB |
100 | |
101 | return (IsOfClass(node, wxT("wxOwnerDrawnComboBox")) || | |
102 | (m_insideBox && node->GetName() == wxT("item"))); | |
103 | ||
104 | #else | |
105 | ||
106 | // Avoid GCC bug - this fails on certain GCC 3.3 and 3.4 builds for an unknown reason | |
288b6107 | 107 | // it is believed to be related to the fact IsOfClass is inline, and node->GetAttribute |
9366ec4e AB |
108 | // gets passed an invalid "this" pointer. On 2.7, the function is out of line, so the |
109 | // above should work fine. This code is left in here so this file can easily be used | |
110 | // in a version backported to 2.6. All we are doing here is expanding the macro | |
582f07c2 | 111 | |
288b6107 | 112 | bool fOurClass = node->GetAttribute(wxT("class"), wxEmptyString) == wxT("wxOwnerDrawnComboBox"); |
582f07c2 WS |
113 | return (fOurClass || |
114 | (m_insideBox && node->GetName() == wxT("item"))); | |
9366ec4e | 115 | #endif |
582f07c2 WS |
116 | } |
117 | ||
118 | #endif // wxUSE_XRC && wxUSE_ODCOMBOBOX |