Debian Codegraph @

src/plugins/contrib/wxSmithSTC/wxsRichTextCtrl.cpp

raw
1 /*
2 * This file is part of wxSmith plugin for Code::Blocks Studio
3 * Copyright (C) 2006-2007 Bartlomiej Swiecki
4 *
5 * wxSmith is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * wxSmith is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with wxSmith. If not, see <http://www.gnu.org/licenses/>.
17 *
18 */
19
20 #include "wxsRichTextCtrl.h"
21
22 //------------------------------------------------------------------------------
23
24 namespace
25 {
26
27 // Loading images from xpm files
28
29 #include "RTF16.xpm"
30 #include "RTF32.xpm"
31
32 wxsRegisterItem<wxsRichTextCtrl> Reg(
33 _T("wxRichTextCtrl"), // Class name
34 wxsTWidget, // Item type
35 _T("wxWindows"), // License
36 _T("Ron Collins"), // Author
37 _T("[email protected]"), // Author's email
38 _T(""), // Item's homepage
39 _T("Styled Text"), // Category in palette
40 80, // Priority in palette
41 _T("RTF"), // Base part of names for new items
42 wxsCPP, // List of coding languages supported by this item
43 1, 0, // Version
44 wxBitmap(RTF32_xpm), // 32x32 bitmap
45 wxBitmap(RTF16_xpm), // 16x16 bitmap
46 false); // We do not allow this item inside XRC files
47
48
49 WXS_ST_BEGIN(wxsRichTextCtrlStyles,_T("wxRE_MULTILINE|wxRAISED_BORDER|wxWANTS_CHARS"))
50 WXS_ST_CATEGORY("wxRichTextCtrl")
51 WXS_ST(wxRE_READONLY )
52 WXS_ST(wxRE_MULTILINE )
53 WXS_ST(wxRE_CENTER_CARET )
54 WXS_ST_DEFAULTS()
55 WXS_ST_END()
56
57 WXS_EV_BEGIN(wxsRichTextCtrlEvents)
58 WXS_EVI(EVT_RICHTEXT_CHARACTER, wxEVT_COMMAND_RICHTEXT_CHARACTER, wxRichTextEvent, EvCharacter)
59 WXS_EVI(EVT_RICHTEXT_DELETE, wxEVT_COMMAND_RICHTEXT_DELETE, wxRichTextEvent, EvDelete)
60 WXS_EVI(EVT_RICHTEXT_RETURN, wxEVT_COMMAND_RICHTEXT_RETURN, wxRichTextEvent, EvReturn)
61 WXS_EVI(EVT_RICHTEXT_STYLE_CHANGED, wxEVT_COMMAND_RICHTEXT_STYLE_CHANGED, wxRichTextEvent, EvStyleChanged)
62 WXS_EVI(EVT_RICHTEXT_STYLESHEET_CHANGED, wxEVT_COMMAND_RICHTEXT_STYLESHEET_CHANGING, wxRichTextEvent, EvStylesheetChanging)
63 WXS_EVI(EVT_RICHTEXT_STYLESHEET_REPLACING, wxEVT_COMMAND_RICHTEXT_STYLESHEET_REPLACING, wxRichTextEvent, EvStylesheetReplacing)
64 WXS_EVI(EVT_RICHTEXT_STYLESHEET_REPLACED, wxEVT_COMMAND_RICHTEXT_STYLESHEET_REPLACED, wxRichTextEvent, EvStylesheetReplaced)
65 WXS_EVI(EVT_RICHTEXT_CONTENT_INSERTED, wxEVT_COMMAND_RICHTEXT_CONTENT_INSERTED, wxRichTextEvent, EvContentInserted)
66 WXS_EVI(EVT_RICHTEXT_CONTENT_DELETED, wxEVT_COMMAND_RICHTEXT_CONTENT_DELETED, wxRichTextEvent, EvContentDeleted)
67 WXS_EVI(EVT_RICHTEXT_BUFFER_RESET, wxEVT_COMMAND_RICHTEXT_BUFFER_RESET, wxRichTextEvent, EvBufferReset)
68
69 WXS_EVI(EVT_TEXT_ENTER, wxEVT_COMMAND_TEXT_ENTER, wxCommandEvent, EvTextEnter)
70 WXS_EVI(EVT_TEXT, wxEVT_COMMAND_TEXT_UPDATED, wxCommandEvent, EvTextUpdated)
71 WXS_EVI(EVT_TEXT_URL, wxEVT_COMMAND_TEXT_URL, wxTextUrlEvent, EvTextURL)
72
73 WXS_EV_DEFAULTS()
74 WXS_EV_END()
75 }
76
77 //------------------------------------------------------------------------------
78
79 wxsRichTextCtrl::wxsRichTextCtrl(wxsItemResData* Data):
80 wxsWidget(
81 Data,
82 &Reg.Info,
83 wxsRichTextCtrlEvents,
84 wxsRichTextCtrlStyles)
85 {
86 mSize.Set(32, 32);
87 mText.Clear();
88 mVirtualSize.IsDefault = true;
89
90 }
91
92 //------------------------------------------------------------------------------
93
94 void wxsRichTextCtrl::OnBuildCreatingCode() {
95 wxString vname;
96 wxString aname;
97 wxString ss, tt;
98 wxsBaseProperties *bp;
99 wxColour fg;
100
101 // valid language?
102
103 if (GetLanguage() != wxsCPP) wxsCodeMarks::Unknown(_T("wxsRichTextCtrl::OnBuildCreatingCode"),GetLanguage());
104
105 // who we are
106
107 vname = GetVarName();
108 aname = vname + _T("_Attr");
109
110 // include files
111
112 AddHeader(_("<wx/richtext/richtextctrl.h>"), GetInfo().ClassName, 0);
113
114 // make our own size specifier with our default values
115
116 mSize.SetDefaults(wxSize(32, 32));
117 ss.Printf(_T("wxSize(%d, %d)"), mSize.GetWidth(), mSize.GetHeight());
118
119 // create the panel
120
121 Codef(_T("%C(%W, %I, wxEmptyString, %P, %s, %T, wxDefaultValidator, %N);\n"), ss.c_str());
122
123
124 // text color via an attribute record
125
126 bp = GetBaseProps();
127 fg = bp->m_Fg.GetColour();
128
129 if (fg.Ok()) {
130 Codef(_T("wxRichTextAttr %s;\n"), aname.c_str());
131 Codef(_T("%s.SetTextColour(wxColour(%d, %d, %d));\n"), aname.c_str(), fg.Red(), fg.Green(), fg.Blue());
132 Codef(_T("%s.SetFlags(wxTEXT_ATTR_TEXT_COLOUR);\n"), aname.c_str());
133 Codef(_T("%s->SetBasicStyle(%s);\n"), vname.c_str(), aname.c_str());
134 };
135
136 // other declarations
137
138 BuildSetupWindowCode();
139
140 // a virtual size
141
142 if (! mVirtualSize.IsDefault) {
143 ss = mVirtualSize.GetSizeCode(GetCoderContext());
144 Codef(_T("%ASetVirtualSize(%s);\n"), ss.c_str());
145 };
146
147
148 // initial text
149
150 for(size_t i=0; i<mText.GetCount(); i++) {
151 ss = mText.Item(i);
152 ss += _T("\n");
153 Codef(_T("%AAppendText(%t);\n"), ss.c_str());
154 };
155 }
156
157 //------------------------------------------------------------------------------
158
159 wxObject* wxsRichTextCtrl::OnBuildPreview(wxWindow* Parent, long Flags) {
160 wxRichTextCtrl *rtf;
161 wxRichTextAttr attr;
162 wxsBaseProperties *bp;
163 wxColour fg;
164 wxString ss;
165 wxSize zz;
166
167 // the default size of this widget is microscopic
168 // use this to make a reasonable default size
169
170 mSize = Size(Parent);
171 mSize.SetDefaults(wxSize(32, 32));
172
173 // make the basic widget
174
175 rtf = new wxRichTextCtrl(Parent, GetId(), wxEmptyString, Pos(Parent), mSize, Style(), wxDefaultValidator);
176
177 // text color
178
179 bp = GetBaseProps();
180 fg = bp->m_Fg.GetColour();
181
182 if (fg.Ok()) {
183 attr.SetTextColour(fg);
184 attr.SetFlags(wxTEXT_ATTR_TEXT_COLOUR);
185 rtf->SetBasicStyle(attr);
186 };
187
188 // the rest of the attributtes
189
190 SetupWindow(rtf, Flags);
191
192 // a virtual size
193
194 if (! mVirtualSize.IsDefault) {
195 zz = mVirtualSize.GetSize(Parent);
196 rtf->SetVirtualSize(zz);
197 };
198
199 // add in initial text
200
201 for(size_t i=0; i<mText.GetCount(); i++) {
202 ss = mText.Item(i);
203 ss += _T("\n");
204 rtf->AppendText(ss);
205 };
206
207 // done
208
209 return rtf;
210 }
211
212 //------------------------------------------------------------------------------
213
214 void wxsRichTextCtrl::OnEnumWidgetProperties(long Flags) {
215
216 // initial text contents
217
218 WXS_ARRAYSTRING(wxsRichTextCtrl, mText, _("Text"), _("mText"), _("text"));
219 WXS_SIZE( wxsRichTextCtrl, mVirtualSize, _T("Default Virtual Size?"), _T("Virtual Width"), _T("Virtual Height"), _T("Use Dialog Units?"), _T("mVirtualSize"));
220
221 };
222
223
224