]> git.saurik.com Git - wxWidgets.git/blame_incremental - contrib/src/xrc/xh_choic.cpp
added wxWizard handler to XRC
[wxWidgets.git] / contrib / src / xrc / xh_choic.cpp
... / ...
CommitLineData
1/////////////////////////////////////////////////////////////////////////////
2// Name: xh_choic.cpp
3// Purpose: XRC 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/xrc/xh_choic.h"
23#include "wx/choice.h"
24#include "wx/intl.h"
25
26wxChoiceXmlHandler::wxChoiceXmlHandler()
27: wxXmlResourceHandler() , m_insideBox(FALSE)
28{
29 XRC_ADD_STYLE(wxCB_SORT);
30 AddWindowStyles();
31}
32
33wxObject *wxChoiceXmlHandler::DoCreateResource()
34{
35 if( m_class == wxT("wxChoice"))
36 {
37 // find the selection
38 long selection = GetLong(wxT("selection"), -1);
39
40 // need to build the list of strings from children
41 m_insideBox = TRUE;
42 CreateChildrenPrivately(NULL, GetParamNode(wxT("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 XRC_MAKE_INSTANCE(control, wxChoice)
53
54 control->Create(m_parentAsWindow,
55 GetID(),
56 GetPosition(), GetSize(),
57 strList.GetCount(),
58 strings,
59 GetStyle(),
60 wxDefaultValidator,
61 GetName());
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 wxString str = GetNodeContent(m_node);
81 if (m_resource->GetFlags() & wxXRC_USE_LOCALE)
82 str = wxGetTranslation(str);
83 strList.Add(str);
84
85 return NULL;
86 }
87}
88
89bool wxChoiceXmlHandler::CanHandle(wxXmlNode *node)
90{
91 return (IsOfClass(node, wxT("wxChoice")) ||
92 (m_insideBox && node->GetName() == wxT("item")));
93}