1/////////////////////////////////////////////////////////////////////////////
2// Name:        src/xrc/xh_choic.cpp
3// Purpose:     XRC resource for wxChoice
4// Author:      Bob Mitchell
5// Created:     2000/03/21
6// RCS-ID:      $Id: xh_choic.cpp 42258 2006-10-22 22:12:32Z VZ $
7// Copyright:   (c) 2000 Bob Mitchell and Verant Interactive
8// Licence:     wxWindows licence
9/////////////////////////////////////////////////////////////////////////////
10
11// For compilers that support precompilation, includes "wx.h".
12#include "wx/wxprec.h"
13
14#ifdef __BORLANDC__
15    #pragma hdrstop
16#endif
17
18#if wxUSE_XRC && wxUSE_CHOICE
19
20#include "wx/xrc/xh_choic.h"
21
22#ifndef WX_PRECOMP
23    #include "wx/intl.h"
24    #include "wx/choice.h"
25#endif
26
27IMPLEMENT_DYNAMIC_CLASS(wxChoiceXmlHandler, wxXmlResourceHandler)
28
29wxChoiceXmlHandler::wxChoiceXmlHandler()
30: wxXmlResourceHandler() , m_insideBox(false)
31{
32    XRC_ADD_STYLE(wxCB_SORT);
33    AddWindowStyles();
34}
35
36wxObject *wxChoiceXmlHandler::DoCreateResource()
37{
38    if( m_class == wxT("wxChoice"))
39    {
40        // find the selection
41        long selection = GetLong(wxT("selection"), -1);
42
43        // need to build the list of strings from children
44        m_insideBox = true;
45        CreateChildrenPrivately(NULL, GetParamNode(wxT("content")));
46
47        XRC_MAKE_INSTANCE(control, wxChoice)
48
49        control->Create(m_parentAsWindow,
50                        GetID(),
51                        GetPosition(), GetSize(),
52                        strList,
53                        GetStyle(),
54                        wxDefaultValidator,
55                        GetName());
56
57        if (selection != -1)
58            control->SetSelection(selection);
59
60        SetupWindow(control);
61
62        strList.Clear();    // dump the strings
63
64        return control;
65    }
66    else
67    {
68        // on the inside now.
69        // handle <item>Label</item>
70
71        // add to the list
72        wxString str = GetNodeContent(m_node);
73        if (m_resource->GetFlags() & wxXRC_USE_LOCALE)
74            str = wxGetTranslation(str, m_resource->GetDomain());
75        strList.Add(str);
76
77        return NULL;
78    }
79}
80
81bool wxChoiceXmlHandler::CanHandle(wxXmlNode *node)
82{
83    return (IsOfClass(node, wxT("wxChoice")) ||
84           (m_insideBox && node->GetName() == wxT("item")));
85}
86
87#endif // wxUSE_XRC && wxUSE_CHOICE
88