Debian Codegraph @

wxcrafter/controls/file_picker_ctrl_wrapper.cpp

raw
1 #include "file_picker_ctrl_wrapper.h"
2 #include "allocator_mgr.h"
3 #include "wxgui_defs.h"
4 #include "wxgui_helpers.h"
5 #include "xmlutils.h"
6 #include <wx/filepicker.h>
7
8 FilePickerCtrlWrapper::FilePickerCtrlWrapper()
9 : wxcWidget(ID_WXFILEPICKER)
10 {
11 SetPropertyString(_("Common Settings"), "wxFilePickerCtrl");
12 AddProperty(new StringProperty(PROP_VALUE, wxT(""), _("Default value")));
13 AddProperty(new StringProperty(PROP_MESSAGE, _("Select a file"), _("Message to show to the user")));
14 AddProperty(new StringProperty(PROP_WILDCARD, wxT("*"), _("Wildcard")));
15
16 PREPEND_STYLE(wxFLP_OPEN, false);
17 PREPEND_STYLE(wxFLP_SAVE, false);
18 PREPEND_STYLE(wxFLP_OVERWRITE_PROMPT, false);
19 PREPEND_STYLE(wxFLP_FILE_MUST_EXIST, false);
20 PREPEND_STYLE(wxFLP_CHANGE_DIR, false);
21 PREPEND_STYLE(wxFLP_SMALL, true);
22
23 PREPEND_STYLE(wxFLP_USE_TEXTCTRL, false);
24 PREPEND_STYLE(wxFLP_DEFAULT_STYLE, true);
25
26 RegisterEvent(wxT("wxEVT_COMMAND_FILEPICKER_CHANGED"), wxT("wxFileDirPickerEvent"),
27 _("The user changed the file selected in the control either using the button or using text "
28 "control\n(see wxFLP_USE_TEXTCTRL; note that in this case the event is fired\nonly if the user's "
29 "input is valid, e.g. an existing file path if wxFLP_FILE_MUST_EXIST was given)."));
30 m_namePattern = wxT("m_filePicker");
31 SetName(GenerateName());
32 }
33
34 FilePickerCtrlWrapper::~FilePickerCtrlWrapper() {}
35
36 wxcWidget* FilePickerCtrlWrapper::Clone() const { return new FilePickerCtrlWrapper(); }
37
38 wxString FilePickerCtrlWrapper::CppCtorCode() const
39 {
40 // wxFilePickerCtrl(wxWindow *parent, wxWindowID id, const wxString& path = wxEmptyString, const wxString& message =
41 // "Select a file", const wxString& wildcard = "*.*", const wxPoint& pos = wxDefaultPosition, const wxSize& size =
42 // wxDefaultSize, long style = wxFLP_DEFAULT_STYLE, const wxValidator& validator = wxDefaultValidator, const
43 // wxString& name = "filepickerctrl")
44 wxString cpp;
45 cpp << GetName() << wxT(" = new ") << GetRealClassName() << wxT("(") << GetWindowParent() << wxT(", ") << WindowID()
46 << wxT(", ") << wxT("wxEmptyString, ") << wxCrafter::UNDERSCORE(PropertyString(PROP_MESSAGE)) << wxT(", ")
47 << wxCrafter::WXT(PropertyString(PROP_WILDCARD)) << wxT(", ") << wxT("wxDefaultPosition, ") << SizeAsString()
48 << wxT(", ") << StyleFlags(wxT("wxFLP_DEFAULT_STYLE")) << wxT(");\n");
49 cpp << CPPCommonAttributes();
50 return cpp;
51 }
52
53 void FilePickerCtrlWrapper::GetIncludeFile(wxArrayString& headers) const
54 {
55 headers.Add(wxT("#include <wx/filepicker.h>"));
56 }
57
58 wxString FilePickerCtrlWrapper::GetWxClassName() const { return wxT("wxFilePickerCtrl"); }
59
60 void FilePickerCtrlWrapper::ToXRC(wxString& text, XRC_TYPE type) const
61 {
62 text << XRCPrefix() << XRCStyle() << XRCCommonAttributes() << XRCSize() << wxT("<message>")
63 << wxCrafter::XMLEncode(PropertyString(PROP_MESSAGE)) << wxT("</message>") << wxT("<wildcard>")
64 << wxCrafter::XMLEncode(PropertyString(PROP_WILDCARD)) << wxT("</wildcard>") << wxT("<value>")
65 << wxCrafter::XMLEncode(PropertyString(PROP_VALUE)) << wxT("</value>") << XRCSuffix();
66 }
67
68 void FilePickerCtrlWrapper::LoadPropertiesFromXRC(const wxXmlNode* node)
69 {
70 // First call the base-class for the standard things
71 wxcWidget::LoadPropertiesFromXRC(node);
72
73 wxXmlNode* propertynode = XmlUtils::FindFirstByTagName(node, wxT("value"));
74 if(propertynode) { SetPropertyString(PROP_VALUE, propertynode->GetNodeContent()); }
75
76 propertynode = XmlUtils::FindFirstByTagName(node, "message");
77 if(propertynode) { SetPropertyString(PROP_MESSAGE, propertynode->GetNodeContent()); }
78
79 propertynode = XmlUtils::FindFirstByTagName(node, "wildcard");
80 if(propertynode) { SetPropertyString(PROP_WILDCARD, propertynode->GetNodeContent()); }
81 }
82
83 void FilePickerCtrlWrapper::LoadPropertiesFromwxSmith(const wxXmlNode* node)
84 {
85 // First call the base-class for the standard things
86 wxcWidget::LoadPropertiesFromwxSmith(node);
87
88 wxXmlNode* propertynode = XmlUtils::FindFirstByTagName(node, wxT("path"));
89 if(propertynode) { SetPropertyString(PROP_VALUE, propertynode->GetNodeContent()); }
90
91 propertynode = XmlUtils::FindFirstByTagName(node, "message");
92 if(propertynode) { SetPropertyString(PROP_MESSAGE, propertynode->GetNodeContent()); }
93
94 propertynode = XmlUtils::FindFirstByTagName(node, "wildcard");
95 if(propertynode) { SetPropertyString(PROP_WILDCARD, propertynode->GetNodeContent()); }
96 }
97
98 void FilePickerCtrlWrapper::LoadPropertiesFromwxFB(const wxXmlNode* node)
99 {
100 // First call the base-class for the standard things
101 wxcWidget::LoadPropertiesFromwxFB(node);
102
103 wxXmlNode* propertynode = XmlUtils::FindNodeByName(node, "property", "value");
104 if(propertynode) { SetPropertyString(PROP_VALUE, propertynode->GetNodeContent()); }
105
106 propertynode = XmlUtils::FindNodeByName(node, "property", "message");
107 if(propertynode) { SetPropertyString(PROP_MESSAGE, propertynode->GetNodeContent()); }
108
109 propertynode = XmlUtils::FindNodeByName(node, "property", "wildcard");
110 if(propertynode) { SetPropertyString(PROP_WILDCARD, propertynode->GetNodeContent()); }
111 }