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