]> git.saurik.com Git - wxWidgets.git/blame - contrib/src/xml/xh_choic.cpp
1) some cleanup in wxHtmlWindow, moved private structures out of headers
[wxWidgets.git] / contrib / src / xml / xh_choic.cpp
CommitLineData
56d2f750
VS
1/////////////////////////////////////////////////////////////////////////////
2// Name: xh_choic.cpp
3// Purpose: XML resource for wxChoice
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/xml/xh_choic.h"
23#include "wx/choice.h"
24
25wxChoiceXmlHandler::wxChoiceXmlHandler()
26: wxXmlResourceHandler() , m_InsideBox(FALSE)
27{
28 ADD_STYLE(wxCB_SORT);
09dc1241 29 AddWindowStyles();
56d2f750
VS
30}
31
32wxObject *wxChoiceXmlHandler::DoCreateResource()
33{
a559d708 34 if( m_Class == wxT("wxChoice"))
56d2f750
VS
35 {
36 // find the selection
a559d708 37 long selection = GetLong( wxT("selection"), -1 );
56d2f750
VS
38
39 // need to build the list of strings from children
40 m_InsideBox = TRUE;
a559d708 41 CreateChildrenPrivately( NULL, GetParamNode(wxT("content")));
56d2f750
VS
42 wxString *strings = (wxString *) NULL;
43 if( strList.GetCount() > 0 )
44 {
45 strings = new wxString[strList.GetCount()];
46 int count = strList.GetCount();
47 for( int i = 0; i < count; i++ )
48 strings[i]=strList[i];
49 }
50
51
52 wxChoice *control = new wxChoice(m_ParentAsWindow,
53 GetID(),
54 GetPosition(), GetSize(),
55 strList.GetCount(),
56 strings,
57 GetStyle(),
58 wxDefaultValidator,
59 GetName()
60 );
61
62 if( selection != -1 )
63 control->SetSelection( selection );
64
65 SetupWindow(control);
66
67 if( strings != NULL )
68 delete [] strings;
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
79 strList.Add( GetNodeContent(m_Node) );
80
81 return NULL;
82 }
83
84}
85
86
87
88bool wxChoiceXmlHandler::CanHandle(wxXmlNode *node)
89{
a559d708
VS
90 return (IsOfClass(node, wxT("wxChoice")) ||
91 (m_InsideBox && node->GetName() == wxT("item"))
e066e256 92 );
56d2f750
VS
93}
94
95