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