]> git.saurik.com Git - wxWidgets.git/blame - src/xrc/xh_choic.cpp
mention ShouldInheritColours() change
[wxWidgets.git] / src / xrc / xh_choic.cpp
CommitLineData
78d14f80
VS
1/////////////////////////////////////////////////////////////////////////////
2// Name: 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/////////////////////////////////////////////////////////////////////////////
10
11#ifdef __GNUG__
12#pragma implementation "xh_choic.h"
13#endif
14
15// For compilers that support precompilation, includes "wx.h".
16#include "wx/wxprec.h"
17
18#ifdef __BORLANDC__
19 #pragma hdrstop
20#endif
21
22#include "wx/xrc/xh_choic.h"
23#include "wx/choice.h"
02df3799 24#include "wx/intl.h"
78d14f80 25
854e189f
VS
26IMPLEMENT_DYNAMIC_CLASS(wxChoiceXmlHandler, wxXmlResourceHandler)
27
78d14f80
VS
28wxChoiceXmlHandler::wxChoiceXmlHandler()
29: wxXmlResourceHandler() , m_insideBox(FALSE)
30{
544fee32 31 XRC_ADD_STYLE(wxCB_SORT);
78d14f80
VS
32 AddWindowStyles();
33}
34
35wxObject *wxChoiceXmlHandler::DoCreateResource()
36{
37 if( m_class == wxT("wxChoice"))
38 {
39 // find the selection
544fee32 40 long selection = GetLong(wxT("selection"), -1);
78d14f80
VS
41
42 // need to build the list of strings from children
43 m_insideBox = TRUE;
544fee32 44 CreateChildrenPrivately(NULL, GetParamNode(wxT("content")));
78d14f80 45 wxString *strings = (wxString *) NULL;
544fee32 46 if (strList.GetCount() > 0)
78d14f80
VS
47 {
48 strings = new wxString[strList.GetCount()];
49 int count = strList.GetCount();
544fee32 50 for (int i = 0; i < count; i++)
78d14f80
VS
51 strings[i]=strList[i];
52 }
53
544fee32 54 XRC_MAKE_INSTANCE(control, wxChoice)
f2588180
VS
55
56 control->Create(m_parentAsWindow,
57 GetID(),
58 GetPosition(), GetSize(),
59 strList.GetCount(),
60 strings,
61 GetStyle(),
62 wxDefaultValidator,
63 GetName());
78d14f80 64
544fee32
VS
65 if (selection != -1)
66 control->SetSelection(selection);
78d14f80
VS
67
68 SetupWindow(control);
69
544fee32
VS
70 if (strings != NULL)
71 delete[] strings;
78d14f80
VS
72 strList.Clear(); // dump the strings
73
74 return control;
75 }
76 else
77 {
78 // on the inside now.
79 // handle <item>Label</item>
80
81 // add to the list
74c107ba
VS
82 wxString str = GetNodeContent(m_node);
83 if (m_resource->GetFlags() & wxXRC_USE_LOCALE)
84 str = wxGetTranslation(str);
85 strList.Add(str);
78d14f80
VS
86
87 return NULL;
88 }
78d14f80
VS
89}
90
78d14f80
VS
91bool wxChoiceXmlHandler::CanHandle(wxXmlNode *node)
92{
93 return (IsOfClass(node, wxT("wxChoice")) ||
544fee32 94 (m_insideBox && node->GetName() == wxT("item")));
78d14f80 95}