]> git.saurik.com Git - wxWidgets.git/blob - src/xrc/xh_odcombo.cpp
Fix VC6 compilation after r73880.
[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 #include "wx/textctrl.h"
25 #endif
26
27 #include "wx/odcombo.h"
28
29 #include "wx/xml/xml.h"
30
31 IMPLEMENT_DYNAMIC_CLASS(wxOwnerDrawnComboBoxXmlHandler, wxXmlResourceHandler)
32
33 wxOwnerDrawnComboBoxXmlHandler::wxOwnerDrawnComboBoxXmlHandler()
34 :wxXmlResourceHandler()
35 ,m_insideBox(false)
36 {
37 XRC_ADD_STYLE(wxCB_SIMPLE);
38 XRC_ADD_STYLE(wxCB_SORT);
39 XRC_ADD_STYLE(wxCB_READONLY);
40 XRC_ADD_STYLE(wxCB_DROPDOWN);
41 XRC_ADD_STYLE(wxODCB_STD_CONTROL_PAINT);
42 XRC_ADD_STYLE(wxODCB_DCLICK_CYCLES);
43 XRC_ADD_STYLE(wxTE_PROCESS_ENTER);
44 AddWindowStyles();
45 }
46
47 wxObject *wxOwnerDrawnComboBoxXmlHandler::DoCreateResource()
48 {
49 if( m_class == wxT("wxOwnerDrawnComboBox"))
50 {
51 // find the selection
52 long selection = GetLong( wxT("selection"), -1 );
53
54 // need to build the list of strings from children
55 m_insideBox = true;
56 CreateChildrenPrivately(NULL, GetParamNode(wxT("content")));
57
58 XRC_MAKE_INSTANCE(control, wxOwnerDrawnComboBox)
59
60 control->Create(m_parentAsWindow,
61 GetID(),
62 GetText(wxT("value")),
63 GetPosition(), GetSize(),
64 strList,
65 GetStyle(),
66 wxDefaultValidator,
67 GetName());
68
69 wxSize sizeBtn=GetSize(wxT("buttonsize"));
70
71 if (sizeBtn != wxDefaultSize)
72 control->SetButtonPosition(sizeBtn.GetWidth(), sizeBtn.GetHeight());
73
74 if (selection != -1)
75 control->SetSelection(selection);
76
77 SetupWindow(control);
78
79 strList.Clear(); // dump the strings
80
81 return control;
82 }
83 else
84 {
85 // on the inside now.
86 // handle <item>Label</item>
87
88 // add to the list
89 wxString str = GetNodeContent(m_node);
90 if (m_resource->GetFlags() & wxXRC_USE_LOCALE)
91 str = wxGetTranslation(str, m_resource->GetDomain());
92 strList.Add(str);
93
94 return NULL;
95 }
96 }
97
98 bool wxOwnerDrawnComboBoxXmlHandler::CanHandle(wxXmlNode *node)
99 {
100 #if wxCHECK_VERSION(2,7,0)
101
102 return (IsOfClass(node, wxT("wxOwnerDrawnComboBox")) ||
103 (m_insideBox && node->GetName() == wxT("item")));
104
105 #else
106
107 // Avoid GCC bug - this fails on certain GCC 3.3 and 3.4 builds for an unknown reason
108 // it is believed to be related to the fact IsOfClass is inline, and node->GetAttribute
109 // gets passed an invalid "this" pointer. On 2.7, the function is out of line, so the
110 // above should work fine. This code is left in here so this file can easily be used
111 // in a version backported to 2.6. All we are doing here is expanding the macro
112
113 bool fOurClass = node->GetAttribute(wxT("class"), wxEmptyString) == wxT("wxOwnerDrawnComboBox");
114 return (fOurClass ||
115 (m_insideBox && node->GetName() == wxT("item")));
116 #endif
117 }
118
119 #endif // wxUSE_XRC && wxUSE_ODCOMBOBOX