Debian Codegraph @

wxcrafter/controls/colour_picker_wrapper.cpp

raw
1 #include "colour_picker_wrapper.h"
2 #include "allocator_mgr.h"
3 #include "color_property.h"
4 #include "wxgui_defs.h"
5 #include "wxgui_helpers.h"
6 #include "xmlutils.h"
7 #include <wx/clrpicker.h>
8 #include <wx/msgdlg.h>
9
10 ColourPickerWrapper::ColourPickerWrapper()
11 : wxcWidget(ID_WXCOLORPICKER)
12 {
13
14 PREPEND_STYLE(wxCLRP_DEFAULT_STYLE, true);
15 PREPEND_STYLE(wxCLRP_USE_TEXTCTRL, false);
16 PREPEND_STYLE(wxCLRP_SHOW_LABEL, false);
17
18 SetPropertyString(_("Common Settings"), "wxColourPickerCtrl");
19 AddProperty(new ColorProperty(PROP_VALUE, wxT("<Default>"), _("Colour")));
20 RegisterEvent(wxT("wxEVT_COMMAND_COLOURPICKER_CHANGED"), wxT("wxColourPickerEvent"),
21 _("The user changed the colour selected in the control either using the button or using text "
22 "control\n(see wxCLRP_USE_TEXTCTRL; note that in this case the event is fired only if the user's "
23 "input is valid, i.e. recognizable)."));
24
25 m_namePattern = wxT("m_colourPicker");
26 SetName(GenerateName());
27 }
28
29 ColourPickerWrapper::~ColourPickerWrapper() {}
30
31 wxcWidget* ColourPickerWrapper::Clone() const { return new ColourPickerWrapper(); }
32
33 wxString ColourPickerWrapper::CppCtorCode() const
34 {
35 wxString code;
36 wxString color = wxCrafter::ColourToCpp(PropertyString(PROP_VALUE));
37 if(color.IsEmpty()) { color << wxT("*wxBLACK"); }
38
39 code << GetName() << wxT(" = new ") << GetRealClassName() << wxT("(") << GetWindowParent() << wxT(", ")
40 << WindowID() << wxT(", ") << color << wxT(", ") << wxT("wxDefaultPosition, ") << SizeAsString() << wxT(", ")
41 << StyleFlags(wxT("wxCLRP_DEFAULT_STYLE")) << wxT(");\n");
42
43 code << CPPCommonAttributes();
44 return code;
45 }
46
47 void ColourPickerWrapper::GetIncludeFile(wxArrayString& headers) const
48 {
49 headers.Add(wxT("#include <wx/clrpicker.h>"));
50 }
51
52 wxString ColourPickerWrapper::GetWxClassName() const { return wxT("wxColourPickerCtrl"); }
53
54 void ColourPickerWrapper::ToXRC(wxString& text, XRC_TYPE type) const
55 {
56 wxString s;
57 wxString value = PropertyString(PROP_VALUE);
58 wxColour col(value);
59
60 s << XRCPrefix() << XRCStyle() << XRCSize();
61
62 if(value != wxT("<Default>")) { s << wxT("<value>") << wxCrafter::GetColourForXRC(value) << wxT("</value>"); }
63
64 s << XRCCommonAttributes() << XRCSuffix();
65
66 text << s;
67 }
68
69 void ColourPickerWrapper::LoadPropertiesFromXRC(const wxXmlNode* node)
70 {
71 // First call the base-class for the standard things
72 wxcWidget::LoadPropertiesFromXRC(node);
73
74 wxXmlNode* propertynode = XmlUtils::FindFirstByTagName(node, wxT("value"));
75 if(propertynode) { SetPropertyString(PROP_VALUE, propertynode->GetNodeContent()); }
76 }
77
78 void ColourPickerWrapper::LoadPropertiesFromwxSmith(const wxXmlNode* node)
79 {
80 // First call the base-class for the standard things
81 wxcWidget::LoadPropertiesFromwxSmith(node);
82
83 wxXmlNode* propertynode = XmlUtils::FindFirstByTagName(node, wxT("colour"));
84 if(propertynode) { SetPropertyString(PROP_VALUE, propertynode->GetNodeContent()); }
85 }
86
87 void ColourPickerWrapper::LoadPropertiesFromwxFB(const wxXmlNode* node)
88 {
89 // First call the base-class for the standard things
90 wxcWidget::LoadPropertiesFromwxFB(node);
91
92 wxXmlNode* propertynode = XmlUtils::FindNodeByName(node, "property", "colour");
93 if(propertynode) { SetPropertyString(PROP_VALUE, propertynode->GetNodeContent()); }
94 }