]> git.saurik.com Git - wxWidgets.git/blob - contrib/src/xml/xh_combo.cpp
added xmlres format docs (uncomplete)
[wxWidgets.git] / contrib / src / xml / xh_combo.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: xh_combo.cpp
3 // Purpose: XML resource for wxRadioBox
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_combo.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_combo.h"
23 #include "wx/combobox.h"
24
25 #if wxUSE_COMBOBOX
26
27 wxComboBoxXmlHandler::wxComboBoxXmlHandler()
28 : wxXmlResourceHandler() , m_InsideBox(FALSE)
29 {
30 ADD_STYLE(wxCB_SIMPLE);
31 ADD_STYLE(wxCB_SORT);
32 ADD_STYLE(wxCB_READONLY);
33 ADD_STYLE(wxCB_DROPDOWN);
34 }
35
36 wxObject *wxComboBoxXmlHandler::DoCreateResource()
37 {
38 if( m_Node->GetName() == _T("combobox"))
39 {
40 // find the selection
41 long selection = GetLong( _T("selection"), -1 );
42
43 // need to build the list of strings from children
44 m_InsideBox = TRUE;
45 CreateChildren( NULL, TRUE /* only this handler */);
46 wxString *strings = (wxString *) NULL;
47 if( strList.GetCount() > 0 )
48 {
49 strings = new wxString[strList.GetCount()];
50 int count = strList.GetCount();
51 for( int i = 0; i < count; i++ )
52 strings[i]=strList[i];
53 }
54
55
56 wxComboBox *control = new wxComboBox(m_ParentAsWindow,
57 GetID(),
58 GetText(_T("value")),
59 GetPosition(), GetSize(),
60 strList.GetCount(),
61 strings,
62 GetStyle(),
63 wxDefaultValidator,
64 GetName()
65 );
66
67 if( selection != -1 )
68 control->SetSelection( selection );
69
70 SetupWindow(control);
71
72 if( strings != NULL )
73 delete [] strings;
74 strList.Clear(); // dump the strings
75
76 return control;
77 }
78 else
79 {
80 // on the inside now.
81 // handle <item>Label</item>
82
83 // add to the list
84 strList.Add( GetNodeContent(m_Node) );
85
86 return NULL;
87 }
88
89 }
90
91
92
93 bool wxComboBoxXmlHandler::CanHandle(wxXmlNode *node)
94 {
95 return( node->GetName() == _T("combobox") ||
96 ( m_InsideBox &&
97 node->GetName() == _T("item" ))
98 );
99 }
100
101 #endif