]> git.saurik.com Git - wxWidgets.git/blame - src/xrc/xh_choic.cpp
fixed array tests compilation and a bug in obj array test
[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"
24
25wxChoiceXmlHandler::wxChoiceXmlHandler()
26: wxXmlResourceHandler() , m_insideBox(FALSE)
27{
544fee32 28 XRC_ADD_STYLE(wxCB_SORT);
78d14f80
VS
29 AddWindowStyles();
30}
31
32wxObject *wxChoiceXmlHandler::DoCreateResource()
33{
34 if( m_class == wxT("wxChoice"))
35 {
36 // find the selection
544fee32 37 long selection = GetLong(wxT("selection"), -1);
78d14f80
VS
38
39 // need to build the list of strings from children
40 m_insideBox = TRUE;
544fee32 41 CreateChildrenPrivately(NULL, GetParamNode(wxT("content")));
78d14f80 42 wxString *strings = (wxString *) NULL;
544fee32 43 if (strList.GetCount() > 0)
78d14f80
VS
44 {
45 strings = new wxString[strList.GetCount()];
46 int count = strList.GetCount();
544fee32 47 for (int i = 0; i < count; i++)
78d14f80
VS
48 strings[i]=strList[i];
49 }
50
544fee32 51 XRC_MAKE_INSTANCE(control, wxChoice)
f2588180
VS
52
53 control->Create(m_parentAsWindow,
54 GetID(),
55 GetPosition(), GetSize(),
56 strList.GetCount(),
57 strings,
58 GetStyle(),
59 wxDefaultValidator,
60 GetName());
78d14f80 61
544fee32
VS
62 if (selection != -1)
63 control->SetSelection(selection);
78d14f80
VS
64
65 SetupWindow(control);
66
544fee32
VS
67 if (strings != NULL)
68 delete[] strings;
78d14f80
VS
69 strList.Clear(); // dump the strings
70
71 return control;
72 }
73 else
74 {
75 // on the inside now.
76 // handle <item>Label</item>
77
78 // add to the list
544fee32 79 strList.Add(GetNodeContent(m_node));
78d14f80
VS
80
81 return NULL;
82 }
78d14f80
VS
83}
84
78d14f80
VS
85bool wxChoiceXmlHandler::CanHandle(wxXmlNode *node)
86{
87 return (IsOfClass(node, wxT("wxChoice")) ||
544fee32 88 (m_insideBox && node->GetName() == wxT("item")));
78d14f80 89}