Debian Codegraph @

wxcrafter/controls/text_ctrl_wrapper.cpp

raw
1 #include "text_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/textctrl.h>
7
8 TextCtrlWrapper::TextCtrlWrapper()
9 : wxcWidget(ID_WXTEXTCTRL)
10 {
11 PREPEND_STYLE(wxTE_AUTO_URL, false);
12 PREPEND_STYLE(wxTE_CENTRE, false);
13 PREPEND_STYLE(wxTE_CHARWRAP, false);
14 PREPEND_STYLE(wxTE_DONTWRAP, false);
15 PREPEND_STYLE(wxTE_LEFT, false);
16 PREPEND_STYLE(wxTE_MULTILINE, false);
17 PREPEND_STYLE(wxTE_NOHIDESEL, false);
18 PREPEND_STYLE(wxTE_NO_VSCROLL, false);
19 PREPEND_STYLE(wxTE_PASSWORD, false);
20 PREPEND_STYLE(wxTE_PROCESS_ENTER, false);
21 PREPEND_STYLE(wxTE_PROCESS_TAB, false);
22 PREPEND_STYLE(wxTE_READONLY, false);
23 PREPEND_STYLE(wxTE_RICH, false);
24 PREPEND_STYLE(wxTE_RICH2, false);
25 PREPEND_STYLE(wxTE_RIGHT, false);
26 PREPEND_STYLE(wxTE_WORDWRAP, false);
27
28 RegisterEventCommand(wxT("wxEVT_COMMAND_TEXT_UPDATED"),
29 _("Respond to a wxEVT_COMMAND_TEXT_UPDATED event, generated when the text changes.\nNotice "
30 "that this event will be sent when the text controls contents changes\n - whether this is "
31 "due to user input or comes from the program itself\n(for example, if SetValue() is "
32 "called); see ChangeValue() for a function which does not send this event."));
33 RegisterEventCommand(wxT("wxEVT_COMMAND_TEXT_ENTER"),
34 _("Respond to a wxEVT_COMMAND_TEXT_ENTER event, generated when enter is pressed in a text "
35 "control\n(which must have wxTE_PROCESS_ENTER style for this event to be generated)."));
36 RegisterEventCommand(wxT("wxEVT_COMMAND_TEXT_MAXLEN"),
37 _("User tried to enter more text into the control than the limit set by SetMaxLength."));
38 RegisterEventCommand(wxT("wxEVT_COMMAND_TEXT_URL"),
39 _("A mouse event occurred over an URL in the text control (wxMSW and wxGTK2 only)"));
40
41 SetPropertyString(_("Common Settings"), "wxTextCtrl");
42 AddProperty(new StringProperty(PROP_VALUE, wxT(""), _("Default text control value")));
43 AddProperty(new StringProperty(PROP_HINT, "", _("Sets a hint shown in an empty unfocused text control")));
44 AddProperty(new StringProperty(PROP_MAXLENGTH, wxT("0"),
45 _("The maximum length of user entered text. Only for single-line wxTextCtrls.")));
46 #if wxUSE_SPELLCHECK
47 AddProperty(new BoolProperty(PROP_SPELLCHECK, false,
48 _("Enable spell checking using the operating system provided text proofing tools. "
49 "This function is only available on OSX, Windows 8 (or newer), and GTK3 (or newer).")));
50 #endif // wxUSE_SPELLCHECK
51 AddProperty(new BoolProperty(
52 PROP_AUTO_COMPLETE_DIRS, false,
53 _("Enable auto-completion of the text using the file system directories. Notice that currently this function "
54 "is only implemented in wxMSW port and does nothing under the other platforms.")));
55 AddProperty(new BoolProperty(PROP_AUTO_COMPLETE_FILES, false,
56 _("Enable auto-completion of the text typed in a single-line text control using all "
57 "valid file system path. Notice that currently this function is only implemented in "
58 "wxMSW port and does nothing under the other platforms.")));
59 m_namePattern = wxT("m_textCtrl");
60 SetName(GenerateName());
61 }
62
63 TextCtrlWrapper::~TextCtrlWrapper() {}
64
65 void TextCtrlWrapper::GetIncludeFile(wxArrayString& headers) const { headers.Add(wxT("#include <wx/textctrl.h>")); }
66
67 wxString TextCtrlWrapper::GetWxClassName() const { return wxT("wxTextCtrl"); }
68
69 wxString TextCtrlWrapper::CppCtorCode() const
70 {
71 wxString code;
72 code << CPPStandardWxCtorWithValue(wxT("0"));
73
74 if(!HasStyle(wxTE_MULTILINE)) {
75
76 // Only supported for wx30 and later
77 code << wxCrafter::WX30_BLOCK_START();
78 code << GetName() << "->SetHint(" << wxCrafter::UNDERSCORE(PropertyString(PROP_HINT)) << ");\n";
79 code << wxCrafter::WXVER_CHECK_BLOCK_END();
80 }
81
82 #if wxUSE_SPELLCHECK
83 if(IsPropertyChecked(PROP_SPELLCHECK)) {
84 code << "\n#if wxUSE_SPELLCHECK\n";
85 code << GetName() << "->EnableProofCheck();\n";
86 code << "#endif\n";
87 }
88 #endif // wxUSE_SPELLCHECK
89
90 if(IsPropertyChecked(PROP_AUTO_COMPLETE_DIRS)) {
91 code << GetName() << "->AutoCompleteDirectories();\n";
92
93 } else if(IsPropertyChecked(PROP_AUTO_COMPLETE_FILES)) {
94 code << GetName() << "->AutoCompleteFileNames();\n";
95 }
96 return code;
97 }
98
99 void TextCtrlWrapper::ToXRC(wxString& text, XRC_TYPE type) const
100 {
101 // Filter out maxlen if the textctrl is multiline (otherwise wx2.9 asserts); similarly hint
102 wxString maxlen, hint;
103
104 if(!HasStyle(wxTE_MULTILINE)) {
105 if(wxCrafter::ToNumber(PropertyString(PROP_MAXLENGTH), -1) > 0) {
106 maxlen = "<maxlength>" + PropertyString(PROP_MAXLENGTH) << "</maxlength>";
107 }
108 if(!PropertyString(PROP_HINT).empty()) {
109 hint = "<hint>" + wxCrafter::CDATA(PropertyString(PROP_HINT)) << "</hint>";
110 }
111 }
112
113 text << XRCPrefix() << XRCStyle() << XRCSize() << XRCCommonAttributes() << XRCValue() << maxlen << hint
114 << XRCSuffix();
115 }
116
117 void TextCtrlWrapper::LoadPropertiesFromXRC(const wxXmlNode* node)
118 {
119 // First call the base-class for the standard things
120 wxcWidget::LoadPropertiesFromXRC(node);
121
122 wxXmlNode* propertynode = XmlUtils::FindFirstByTagName(node, wxT("value"));
123 if(propertynode) { SetPropertyString(PROP_VALUE, propertynode->GetNodeContent()); }
124
125 propertynode = XmlUtils::FindFirstByTagName(node, wxT("maxlength"));
126 if(propertynode) { SetPropertyString(PROP_MAXLENGTH, propertynode->GetNodeContent()); }
127 }
128
129 void TextCtrlWrapper::LoadPropertiesFromwxSmith(const wxXmlNode* node)
130 {
131 // First call the base-class for the standard things
132 wxcWidget::LoadPropertiesFromwxSmith(node);
133
134 wxXmlNode* propertynode = XmlUtils::FindFirstByTagName(node, wxT("value"));
135 if(propertynode) { SetPropertyString(PROP_VALUE, propertynode->GetNodeContent()); }
136
137 propertynode = XmlUtils::FindFirstByTagName(node, wxT("maxlength"));
138 if(propertynode) { SetPropertyString(PROP_MAXLENGTH, propertynode->GetNodeContent()); }
139 }
140
141 void TextCtrlWrapper::LoadPropertiesFromwxFB(const wxXmlNode* node)
142 {
143 // First call the base-class for the standard things
144 wxcWidget::LoadPropertiesFromwxFB(node);
145
146 wxXmlNode* propertynode = XmlUtils::FindNodeByName(node, "property", "value");
147 if(propertynode) { SetPropertyString(PROP_VALUE, propertynode->GetNodeContent()); }
148
149 propertynode = XmlUtils::FindNodeByName(node, "property", "maxlength");
150 if(propertynode) { SetPropertyString(PROP_MAXLENGTH, propertynode->GetNodeContent()); }
151 }
152
153 wxcWidget* TextCtrlWrapper::Clone() const { return new TextCtrlWrapper(); }