]> git.saurik.com Git - wxWidgets.git/blob - src/xrc/xh_htmllbox.cpp
don't overwrite the existing local file if we failed to open it but it does exist
[wxWidgets.git] / src / xrc / xh_htmllbox.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: xh_simplehtmllbox.cpp
3 // Purpose: XML resource handler for wxSimpleHtmlListBox
4 // Author: Francesco Montorsi
5 // Created: 2006/10/21
6 // RCS-ID: $Id$
7 // Copyright: (c) 2006 Francesco Montorsi
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_HTML
19
20 #include "wx/xrc/xh_htmllbox.h"
21
22 #include "wx/htmllbox.h"
23 #include "wx/filesys.h"
24
25 IMPLEMENT_DYNAMIC_CLASS(wxSimpleHtmlListBoxXmlHandler, wxXmlResourceHandler)
26
27 wxSimpleHtmlListBoxXmlHandler::wxSimpleHtmlListBoxXmlHandler()
28 : wxXmlResourceHandler(), m_insideBox(false)
29 {
30 XRC_ADD_STYLE(wxHLB_DEFAULT_STYLE);
31 XRC_ADD_STYLE(wxHLB_MULTIPLE);
32 AddWindowStyles();
33 }
34
35 wxObject *wxSimpleHtmlListBoxXmlHandler::DoCreateResource()
36 {
37 if ( m_class == wxT("wxSimpleHtmlListBox"))
38 {
39 // find the selection
40 long selection = GetLong(wxT("selection"), -1);
41
42 // need to build the list of strings from children
43 m_insideBox = true;
44 CreateChildrenPrivately(NULL, GetParamNode(wxT("content")));
45 m_insideBox = false;
46
47 XRC_MAKE_INSTANCE(control, wxSimpleHtmlListBox)
48
49 control->Create(m_parentAsWindow,
50 GetID(),
51 GetPosition(), GetSize(),
52 strList,
53 GetStyle(_T("style"), wxHLB_DEFAULT_STYLE),
54 wxDefaultValidator,
55 GetName());
56
57 if (selection != -1)
58 control->SetSelection(selection);
59
60 SetupWindow(control);
61 strList.Clear(); // dump the strings
62
63 return control;
64 }
65 else
66 {
67 // on the inside now.
68 // handle <item>Label</item>
69
70 // add to the list
71 wxString str = GetNodeContent(m_node);
72 if (m_resource->GetFlags() & wxXRC_USE_LOCALE)
73 str = wxGetTranslation(str, m_resource->GetDomain());
74 strList.Add(str);
75
76 return NULL;
77 }
78 }
79
80 bool wxSimpleHtmlListBoxXmlHandler::CanHandle(wxXmlNode *node)
81 {
82 return (IsOfClass(node, wxT("wxSimpleHtmlListBox")) ||
83 (m_insideBox && node->GetName() == wxT("item")));
84 }
85
86 #endif // wxUSE_XRC && wxUSE_HTML