Debian Codegraph @

wxcrafter/controls/hyper_link_ctrl_wrapper.cpp

raw
1 #include "hyper_link_ctrl_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/hyperlink.h>
8
9 HyperLinkCtrlWrapper::HyperLinkCtrlWrapper()
10 : wxcWidget(ID_WXHYPERLINK)
11 {
12 PREPEND_STYLE_FALSE(wxHL_ALIGN_LEFT);
13 PREPEND_STYLE_FALSE(wxHL_ALIGN_RIGHT);
14 PREPEND_STYLE_FALSE(wxHL_ALIGN_CENTRE);
15 PREPEND_STYLE_FALSE(wxHL_CONTEXTMENU);
16 PREPEND_STYLE_TRUE(wxHL_DEFAULT_STYLE);
17
18 RegisterEvent(wxT("wxEVT_COMMAND_HYPERLINK"), wxT("wxHyperlinkEvent"),
19 _("The hyperlink was (left) clicked. If this event is not handled in user's code (or it's skipped; "
20 "see wxEvent::Skip)\nthen a call to wxLaunchDefaultBrowser is done with the hyperlink's URL."));
21
22 SetPropertyString(_("Common Settings"), "wxHyperLinkCtrl");
23 AddProperty(new StringProperty(PROP_LABEL, wxT("codelite IDE"), _("The label of the hyperlink")));
24 AddProperty(
25 new StringProperty(PROP_URL, wxT("http://www.codelite.org"), _("The URL associated with the given label")));
26 AddProperty(
27 new ColorProperty(PROP_NORMAL_COLOR, wxT("#0000FF"),
28 _("Sets the colour used to print the label when the link has never been clicked "
29 "before\n(i.e. the link has not been visited) and the mouse is not over the control.")));
30 AddProperty(new ColorProperty(PROP_VISITED_COLOR, wxT("#FF0000"),
31 _("Sets the colour used to print the label when the mouse is not over the control "
32 "and the link has already been clicked before\n(i.e. the link has been visited)")));
33 AddProperty(new ColorProperty(
34 PROP_HOVER_COLOR, wxT("#0000FF"),
35 _("Sets the colour used to print the label of the hyperlink when the mouse is over the control")));
36
37 m_namePattern = wxT("m_hyperLink");
38 SetName(GenerateName());
39 }
40
41 HyperLinkCtrlWrapper::~HyperLinkCtrlWrapper() {}
42
43 wxcWidget* HyperLinkCtrlWrapper::Clone() const { return new HyperLinkCtrlWrapper(); }
44
45 wxString HyperLinkCtrlWrapper::CppCtorCode() const
46 {
47 wxString code;
48 code << GetName() << wxT(" = new ") << GetRealClassName() << wxT("(") << GetWindowParent() << wxT(", ")
49 << WindowID() << wxT(", ") << wxCrafter::UNDERSCORE(PropertyString(PROP_LABEL)) << wxT(", ")
50 << wxCrafter::WXT(PropertyString(PROP_URL)) << wxT(", ") << wxT("wxDefaultPosition, ") << SizeAsString()
51 << wxT(", ") << StyleFlags(wxT("wxHL_DEFAULT_STYLE")) << wxT(");\n");
52
53 code << CPPCommonAttributes();
54 wxString color;
55 color = wxCrafter::ColourToCpp(PropertyString(PROP_NORMAL_COLOR));
56 if(color.IsEmpty() == false) { code << GetName() << wxT("->SetNormalColour(") << color << wxT(");\n"); }
57
58 color = wxCrafter::ColourToCpp(PropertyString(PROP_HOVER_COLOR));
59 if(color.IsEmpty() == false) { code << GetName() << wxT("->SetHoverColour(") << color << wxT(");\n"); }
60
61 color = wxCrafter::ColourToCpp(PropertyString(PROP_VISITED_COLOR));
62 if(color.IsEmpty() == false) { code << GetName() << wxT("->SetVisitedColour(") << color << wxT(");\n"); }
63 return code;
64 }
65
66 void HyperLinkCtrlWrapper::GetIncludeFile(wxArrayString& headers) const
67 {
68 headers.Add(wxT("#include <wx/hyperlink.h>"));
69 }
70
71 wxString HyperLinkCtrlWrapper::GetWxClassName() const { return wxT("wxHyperlinkCtrl"); }
72
73 void HyperLinkCtrlWrapper::ToXRC(wxString& text, XRC_TYPE type) const
74 {
75 text << XRCPrefix() << XRCCommonAttributes() << XRCStyle() << XRCSize() << XRCLabel() << wxT("<url>")
76 << wxCrafter::XMLEncode(PropertyString(PROP_URL)) << wxT("</url>") << XRCSuffix();
77 }
78
79 void HyperLinkCtrlWrapper::LoadPropertiesFromXRC(const wxXmlNode* node)
80 {
81 wxcWidget::LoadPropertiesFromXRC(node); // Baseclass stuff first
82
83 wxXmlNode* propertynode = XmlUtils::FindFirstByTagName(node, wxT("url"));
84 if(propertynode) { SetPropertyString(PROP_URL, propertynode->GetNodeContent()); }
85 // XRC doesn't seem to do the other properties
86 }
87
88 void HyperLinkCtrlWrapper::LoadPropertiesFromwxSmith(const wxXmlNode* node)
89 {
90 wxcWidget::LoadPropertiesFromwxSmith(node); // Baseclass stuff first
91
92 wxXmlNode* propertynode = XmlUtils::FindFirstByTagName(node, wxT("url"));
93 if(propertynode) { SetPropertyString(PROP_URL, propertynode->GetNodeContent()); }
94
95 propertynode = XmlUtils::FindFirstByTagName(node, wxT("normal_color"));
96 if(propertynode) { SetPropertyString(PROP_NORMAL_COLOR, propertynode->GetNodeContent()); }
97
98 propertynode = XmlUtils::FindFirstByTagName(node, wxT("hover_color"));
99 if(propertynode) { SetPropertyString(PROP_HOVER_COLOR, propertynode->GetNodeContent()); }
100
101 propertynode = XmlUtils::FindFirstByTagName(node, wxT("visited_color"));
102 if(propertynode) { SetPropertyString(PROP_VISITED_COLOR, propertynode->GetNodeContent()); }
103 }
104
105 void HyperLinkCtrlWrapper::LoadPropertiesFromwxFB(const wxXmlNode* node)
106 {
107 // First call the base-class for the standard things
108 wxcWidget::LoadPropertiesFromwxFB(node);
109
110 wxXmlNode* propertynode = XmlUtils::FindNodeByName(node, "property", "url");
111 if(propertynode) { SetPropertyString(PROP_URL, propertynode->GetNodeContent()); }
112
113 propertynode = XmlUtils::FindNodeByName(node, "property", "hover_color");
114 if(propertynode) {
115 wxString col = wxCrafter::ValueToColourString(propertynode->GetNodeContent());
116 if(!col.empty()) { SetPropertyString(PROP_HOVER_COLOR, col); }
117 }
118
119 propertynode = XmlUtils::FindNodeByName(node, "property", "normal_color");
120 if(propertynode) {
121 wxString col = wxCrafter::ValueToColourString(propertynode->GetNodeContent());
122 if(!col.empty()) { SetPropertyString(PROP_NORMAL_COLOR, col); }
123 }
124
125 propertynode = XmlUtils::FindNodeByName(node, "property", "visited_color");
126 if(propertynode) {
127 wxString col = wxCrafter::ValueToColourString(propertynode->GetNodeContent());
128 if(!col.empty()) { SetPropertyString(PROP_VISITED_COLOR, col); }
129 }
130 }