]> git.saurik.com Git - wxWidgets.git/blame - src/xrc/xh_choic.cpp
Merge in from trunk r68626 - r68683
[wxWidgets.git] / src / xrc / xh_choic.cpp
CommitLineData
78d14f80 1/////////////////////////////////////////////////////////////////////////////
88a7a4e1 2// Name: src/xrc/xh_choic.cpp
b5d6954b 3// Purpose: XRC resource for wxChoice
78d14f80
VS
4// Author: Bob Mitchell
5// Created: 2000/03/21
6// RCS-ID: $Id$
7// Copyright: (c) 2000 Bob Mitchell and Verant Interactive
8// Licence: wxWindows licence
9/////////////////////////////////////////////////////////////////////////////
f80ea77b 10
78d14f80
VS
11// For compilers that support precompilation, includes "wx.h".
12#include "wx/wxprec.h"
13
14#ifdef __BORLANDC__
15 #pragma hdrstop
16#endif
17
b36e08d0 18#if wxUSE_XRC && wxUSE_CHOICE
a1e4ec87 19
78d14f80 20#include "wx/xrc/xh_choic.h"
88a7a4e1
WS
21
22#ifndef WX_PRECOMP
23 #include "wx/intl.h"
b36e08d0 24 #include "wx/choice.h"
88a7a4e1
WS
25#endif
26
854e189f
VS
27IMPLEMENT_DYNAMIC_CLASS(wxChoiceXmlHandler, wxXmlResourceHandler)
28
f80ea77b
WS
29wxChoiceXmlHandler::wxChoiceXmlHandler()
30: wxXmlResourceHandler() , m_insideBox(false)
78d14f80 31{
544fee32 32 XRC_ADD_STYLE(wxCB_SORT);
78d14f80
VS
33 AddWindowStyles();
34}
35
36wxObject *wxChoiceXmlHandler::DoCreateResource()
f80ea77b 37{
78d14f80
VS
38 if( m_class == wxT("wxChoice"))
39 {
40 // find the selection
544fee32 41 long selection = GetLong(wxT("selection"), -1);
78d14f80
VS
42
43 // need to build the list of strings from children
f80ea77b 44 m_insideBox = true;
544fee32 45 CreateChildrenPrivately(NULL, GetParamNode(wxT("content")));
78d14f80 46
544fee32 47 XRC_MAKE_INSTANCE(control, wxChoice)
f2588180
VS
48
49 control->Create(m_parentAsWindow,
50 GetID(),
51 GetPosition(), GetSize(),
187d8152 52 strList,
f2588180
VS
53 GetStyle(),
54 wxDefaultValidator,
55 GetName());
78d14f80 56
544fee32
VS
57 if (selection != -1)
58 control->SetSelection(selection);
78d14f80
VS
59
60 SetupWindow(control);
61
f80ea77b 62 strList.Clear(); // dump the strings
78d14f80
VS
63
64 return control;
65 }
66 else
67 {
68 // on the inside now.
69 // handle <item>Label</item>
f80ea77b 70
78d14f80 71 // add to the list
74c107ba
VS
72 wxString str = GetNodeContent(m_node);
73 if (m_resource->GetFlags() & wxXRC_USE_LOCALE)
d4a724d4 74 str = wxGetTranslation(str, m_resource->GetDomain());
74c107ba 75 strList.Add(str);
78d14f80
VS
76
77 return NULL;
78 }
78d14f80
VS
79}
80
78d14f80
VS
81bool wxChoiceXmlHandler::CanHandle(wxXmlNode *node)
82{
83 return (IsOfClass(node, wxT("wxChoice")) ||
544fee32 84 (m_insideBox && node->GetName() == wxT("item")));
78d14f80 85}
a1e4ec87 86
b36e08d0 87#endif // wxUSE_XRC && wxUSE_CHOICE