]> git.saurik.com Git - wxWidgets.git/blob - contrib/src/xml/xh_choic.cpp
removed loading from in-memory document (illicit idea)
[wxWidgets.git] / contrib / src / xml / xh_choic.cpp
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
25 wxChoiceXmlHandler::wxChoiceXmlHandler()
26 : wxXmlResourceHandler() , m_InsideBox(FALSE)
27 {
28 ADD_STYLE(wxCB_SORT);
29 AddWindowStyles();
30 }
31
32 wxObject *wxChoiceXmlHandler::DoCreateResource()
33 {
34 if( m_Node->GetName() == _T("choice"))
35 {
36 // find the selection
37 long selection = GetLong( _T("selection"), -1 );
38
39 // need to build the list of strings from children
40 m_InsideBox = TRUE;
41 CreateChildren( NULL, TRUE /* only this handler */,
42 GetParamNode(_T("content")));
43 wxString *strings = (wxString *) NULL;
44 if( strList.GetCount() > 0 )
45 {
46 strings = new wxString[strList.GetCount()];
47 int count = strList.GetCount();
48 for( int i = 0; i < count; i++ )
49 strings[i]=strList[i];
50 }
51
52
53 wxChoice *control = new wxChoice(m_ParentAsWindow,
54 GetID(),
55 GetPosition(), GetSize(),
56 strList.GetCount(),
57 strings,
58 GetStyle(),
59 wxDefaultValidator,
60 GetName()
61 );
62
63 if( selection != -1 )
64 control->SetSelection( selection );
65
66 SetupWindow(control);
67
68 if( strings != NULL )
69 delete [] strings;
70 strList.Clear(); // dump the strings
71
72 return control;
73 }
74 else
75 {
76 // on the inside now.
77 // handle <item>Label</item>
78
79 // add to the list
80 strList.Add( GetNodeContent(m_Node) );
81
82 return NULL;
83 }
84
85 }
86
87
88
89 bool wxChoiceXmlHandler::CanHandle(wxXmlNode *node)
90 {
91 return( node->GetName() == _T("choice") ||
92 ( m_InsideBox &&
93 node->GetName() == _T("item" ))
94 );
95 }
96
97