]>
Commit | Line | Data |
---|---|---|
a1b82138 | 1 | /////////////////////////////////////////////////////////////////////////////// |
d5da0ce7 | 2 | // Name: src/common/textcmn.cpp |
a1b82138 VZ |
3 | // Purpose: implementation of platform-independent functions of wxTextCtrl |
4 | // Author: Julian Smart | |
5 | // Modified by: | |
6 | // Created: 13.07.99 | |
7 | // RCS-ID: $Id$ | |
77ffb593 | 8 | // Copyright: (c) wxWidgets team |
65571936 | 9 | // Licence: wxWindows licence |
a1b82138 VZ |
10 | /////////////////////////////////////////////////////////////////////////////// |
11 | ||
12 | // ============================================================================ | |
13 | // declarations | |
14 | // ============================================================================ | |
1e6feb95 | 15 | |
a1b82138 VZ |
16 | // for compilers that support precompilation, includes "wx.h". |
17 | #include "wx/wxprec.h" | |
18 | ||
19 | #ifdef __BORLANDC__ | |
20 | #pragma hdrstop | |
21 | #endif | |
22 | ||
d5da0ce7 WS |
23 | #ifndef WX_PRECOMP |
24 | #include "wx/event.h" | |
25 | #endif // WX_PRECOMP | |
26 | ||
1e6feb95 VZ |
27 | #if wxUSE_TEXTCTRL |
28 | ||
d5da0ce7 WS |
29 | #include "wx/textctrl.h" |
30 | ||
a1b82138 | 31 | #ifndef WX_PRECOMP |
0efe5ba7 VZ |
32 | #include "wx/intl.h" |
33 | #include "wx/log.h" | |
a1b82138 VZ |
34 | #endif // WX_PRECOMP |
35 | ||
36 | #include "wx/ffile.h" | |
37 | ||
38 | // ---------------------------------------------------------------------------- | |
39 | // macros | |
40 | // ---------------------------------------------------------------------------- | |
41 | ||
42 | // we don't have any objects of type wxTextCtrlBase in the program, only | |
43 | // wxTextCtrl, so this cast is safe | |
44 | #define TEXTCTRL(ptr) ((wxTextCtrl *)(ptr)) | |
45 | ||
46 | // ============================================================================ | |
47 | // implementation | |
48 | // ============================================================================ | |
49 | ||
c57e3339 VZ |
50 | IMPLEMENT_DYNAMIC_CLASS(wxTextUrlEvent, wxCommandEvent) |
51 | ||
9b11752c VZ |
52 | wxDEFINE_EVENT( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEvent ); |
53 | wxDEFINE_EVENT( wxEVT_COMMAND_TEXT_ENTER, wxCommandEvent ); | |
54 | wxDEFINE_EVENT( wxEVT_COMMAND_TEXT_URL, wxTextUrlEvent ); | |
55 | wxDEFINE_EVENT( wxEVT_COMMAND_TEXT_MAXLEN, wxCommandEvent ); | |
c57e3339 | 56 | |
9d112688 JS |
57 | IMPLEMENT_ABSTRACT_CLASS(wxTextCtrlBase, wxControl) |
58 | ||
44cc96a8 JS |
59 | // ============================================================================ |
60 | // wxTextAttr implementation | |
61 | // ============================================================================ | |
4bc1afd5 | 62 | |
e00a5d3c JS |
63 | wxTextAttr::wxTextAttr(const wxColour& colText, |
64 | const wxColour& colBack, | |
65 | const wxFont& font, | |
44cc96a8 | 66 | wxTextAttrAlignment alignment): m_textAlignment(alignment), m_colText(colText), m_colBack(colBack) |
e00a5d3c | 67 | { |
44cc96a8 JS |
68 | Init(); |
69 | ||
e00a5d3c JS |
70 | if (m_colText.Ok()) m_flags |= wxTEXT_ATTR_TEXT_COLOUR; |
71 | if (m_colBack.Ok()) m_flags |= wxTEXT_ATTR_BACKGROUND_COLOUR; | |
e00a5d3c JS |
72 | if (alignment != wxTEXT_ALIGNMENT_DEFAULT) |
73 | m_flags |= wxTEXT_ATTR_ALIGNMENT; | |
44cc96a8 JS |
74 | |
75 | GetFontAttributes(font); | |
e00a5d3c JS |
76 | } |
77 | ||
44cc96a8 | 78 | // Initialisation |
e00a5d3c JS |
79 | void wxTextAttr::Init() |
80 | { | |
81 | m_textAlignment = wxTEXT_ALIGNMENT_DEFAULT; | |
82 | m_flags = 0; | |
83 | m_leftIndent = 0; | |
89b67477 | 84 | m_leftSubIndent = 0; |
e00a5d3c | 85 | m_rightIndent = 0; |
44cc96a8 JS |
86 | |
87 | m_fontSize = 12; | |
7d76fbd5 FM |
88 | m_fontStyle = wxFONTSTYLE_NORMAL; |
89 | m_fontWeight = wxFONTWEIGHT_NORMAL; | |
44cc96a8 JS |
90 | m_fontUnderlined = false; |
91 | m_fontEncoding = wxFONTENCODING_DEFAULT; | |
9c4cb611 | 92 | m_fontFamily = wxFONTFAMILY_DEFAULT; |
44cc96a8 JS |
93 | |
94 | m_paragraphSpacingAfter = 0; | |
95 | m_paragraphSpacingBefore = 0; | |
96 | m_lineSpacing = 0; | |
97 | m_bulletStyle = wxTEXT_ATTR_BULLET_STYLE_NONE; | |
98 | m_textEffects = wxTEXT_ATTR_EFFECT_NONE; | |
99 | m_textEffectFlags = wxTEXT_ATTR_EFFECT_NONE; | |
100 | m_outlineLevel = 0; | |
101 | m_bulletNumber = 0; | |
102 | } | |
103 | ||
104 | // Copy | |
105 | void wxTextAttr::Copy(const wxTextAttr& attr) | |
106 | { | |
107 | m_colText = attr.m_colText; | |
108 | m_colBack = attr.m_colBack; | |
109 | m_textAlignment = attr.m_textAlignment; | |
110 | m_leftIndent = attr.m_leftIndent; | |
111 | m_leftSubIndent = attr.m_leftSubIndent; | |
112 | m_rightIndent = attr.m_rightIndent; | |
113 | m_tabs = attr.m_tabs; | |
114 | m_flags = attr.m_flags; | |
115 | ||
116 | m_fontSize = attr.m_fontSize; | |
117 | m_fontStyle = attr.m_fontStyle; | |
118 | m_fontWeight = attr.m_fontWeight; | |
119 | m_fontUnderlined = attr.m_fontUnderlined; | |
120 | m_fontFaceName = attr.m_fontFaceName; | |
121 | m_fontEncoding = attr.m_fontEncoding; | |
9c4cb611 | 122 | m_fontFamily = attr.m_fontFamily; |
44cc96a8 JS |
123 | m_textEffects = attr.m_textEffects; |
124 | m_textEffectFlags = attr.m_textEffectFlags; | |
125 | ||
126 | m_paragraphSpacingAfter = attr.m_paragraphSpacingAfter; | |
127 | m_paragraphSpacingBefore = attr.m_paragraphSpacingBefore; | |
128 | m_lineSpacing = attr.m_lineSpacing; | |
129 | m_characterStyleName = attr.m_characterStyleName; | |
130 | m_paragraphStyleName = attr.m_paragraphStyleName; | |
131 | m_listStyleName = attr.m_listStyleName; | |
132 | m_bulletStyle = attr.m_bulletStyle; | |
133 | m_bulletNumber = attr.m_bulletNumber; | |
134 | m_bulletText = attr.m_bulletText; | |
135 | m_bulletFont = attr.m_bulletFont; | |
136 | m_bulletName = attr.m_bulletName; | |
137 | m_outlineLevel = attr.m_outlineLevel; | |
138 | ||
139 | m_urlTarget = attr.m_urlTarget; | |
140 | } | |
141 | ||
142 | // operators | |
143 | void wxTextAttr::operator= (const wxTextAttr& attr) | |
144 | { | |
145 | Copy(attr); | |
146 | } | |
147 | ||
148 | // Equality test | |
149 | bool wxTextAttr::operator== (const wxTextAttr& attr) const | |
150 | { | |
151 | return GetFlags() == attr.GetFlags() && | |
152 | ||
153 | GetTextColour() == attr.GetTextColour() && | |
154 | GetBackgroundColour() == attr.GetBackgroundColour() && | |
155 | ||
156 | GetAlignment() == attr.GetAlignment() && | |
157 | GetLeftIndent() == attr.GetLeftIndent() && | |
158 | GetLeftSubIndent() == attr.GetLeftSubIndent() && | |
159 | GetRightIndent() == attr.GetRightIndent() && | |
160 | TabsEq(GetTabs(), attr.GetTabs()) && | |
161 | ||
162 | GetParagraphSpacingAfter() == attr.GetParagraphSpacingAfter() && | |
163 | GetParagraphSpacingBefore() == attr.GetParagraphSpacingBefore() && | |
164 | GetLineSpacing() == attr.GetLineSpacing() && | |
165 | GetCharacterStyleName() == attr.GetCharacterStyleName() && | |
166 | GetParagraphStyleName() == attr.GetParagraphStyleName() && | |
167 | GetListStyleName() == attr.GetListStyleName() && | |
168 | ||
169 | GetBulletStyle() == attr.GetBulletStyle() && | |
170 | GetBulletText() == attr.GetBulletText() && | |
171 | GetBulletNumber() == attr.GetBulletNumber() && | |
172 | GetBulletFont() == attr.GetBulletFont() && | |
173 | GetBulletName() == attr.GetBulletName() && | |
174 | ||
175 | GetTextEffects() == attr.GetTextEffects() && | |
176 | GetTextEffectFlags() == attr.GetTextEffectFlags() && | |
177 | ||
178 | GetOutlineLevel() == attr.GetOutlineLevel() && | |
179 | ||
180 | GetFontSize() == attr.GetFontSize() && | |
181 | GetFontStyle() == attr.GetFontStyle() && | |
182 | GetFontWeight() == attr.GetFontWeight() && | |
183 | GetFontUnderlined() == attr.GetFontUnderlined() && | |
184 | GetFontFaceName() == attr.GetFontFaceName() && | |
185 | GetFontEncoding() == attr.GetFontEncoding() && | |
9c4cb611 | 186 | GetFontFamily() == attr.GetFontFamily() && |
44cc96a8 JS |
187 | |
188 | GetURL() == attr.GetURL(); | |
189 | } | |
190 | ||
191 | // Partial equality test taking flags into account | |
192 | bool wxTextAttr::EqPartial(const wxTextAttr& attr, int flags) const | |
193 | { | |
194 | if ((flags & wxTEXT_ATTR_TEXT_COLOUR) && GetTextColour() != attr.GetTextColour()) | |
195 | return false; | |
196 | ||
197 | if ((flags & wxTEXT_ATTR_BACKGROUND_COLOUR) && GetBackgroundColour() != attr.GetBackgroundColour()) | |
198 | return false; | |
199 | ||
200 | if ((flags & wxTEXT_ATTR_FONT_FACE) && | |
201 | GetFontFaceName() != attr.GetFontFaceName()) | |
202 | return false; | |
203 | ||
204 | if ((flags & wxTEXT_ATTR_FONT_SIZE) && | |
205 | GetFontSize() != attr.GetFontSize()) | |
206 | return false; | |
207 | ||
208 | if ((flags & wxTEXT_ATTR_FONT_WEIGHT) && | |
209 | GetFontWeight() != attr.GetFontWeight()) | |
210 | return false; | |
211 | ||
212 | if ((flags & wxTEXT_ATTR_FONT_ITALIC) && | |
213 | GetFontStyle() != attr.GetFontStyle()) | |
214 | return false; | |
215 | ||
216 | if ((flags & wxTEXT_ATTR_FONT_UNDERLINE) && | |
217 | GetFontUnderlined() != attr.GetFontUnderlined()) | |
218 | return false; | |
219 | ||
220 | if ((flags & wxTEXT_ATTR_FONT_ENCODING) && | |
221 | GetFontEncoding() != attr.GetFontEncoding()) | |
222 | return false; | |
223 | ||
9c4cb611 JS |
224 | if ((flags & wxTEXT_ATTR_FONT_FAMILY) && |
225 | GetFontFamily() != attr.GetFontFamily()) | |
226 | return false; | |
227 | ||
44cc96a8 JS |
228 | if ((flags & wxTEXT_ATTR_URL) && GetURL() != attr.GetURL()) |
229 | return false; | |
230 | ||
231 | if ((flags & wxTEXT_ATTR_ALIGNMENT) && GetAlignment() != attr.GetAlignment()) | |
232 | return false; | |
233 | ||
234 | if ((flags & wxTEXT_ATTR_LEFT_INDENT) && | |
235 | ((GetLeftIndent() != attr.GetLeftIndent()) || (GetLeftSubIndent() != attr.GetLeftSubIndent()))) | |
236 | return false; | |
237 | ||
238 | if ((flags & wxTEXT_ATTR_RIGHT_INDENT) && | |
239 | (GetRightIndent() != attr.GetRightIndent())) | |
240 | return false; | |
241 | ||
242 | if ((flags & wxTEXT_ATTR_PARA_SPACING_AFTER) && | |
243 | (GetParagraphSpacingAfter() != attr.GetParagraphSpacingAfter())) | |
244 | return false; | |
245 | ||
246 | if ((flags & wxTEXT_ATTR_PARA_SPACING_BEFORE) && | |
247 | (GetParagraphSpacingBefore() != attr.GetParagraphSpacingBefore())) | |
248 | return false; | |
249 | ||
250 | if ((flags & wxTEXT_ATTR_LINE_SPACING) && | |
251 | (GetLineSpacing() != attr.GetLineSpacing())) | |
252 | return false; | |
253 | ||
254 | if ((flags & wxTEXT_ATTR_CHARACTER_STYLE_NAME) && | |
255 | (GetCharacterStyleName() != attr.GetCharacterStyleName())) | |
256 | return false; | |
257 | ||
258 | if ((flags & wxTEXT_ATTR_PARAGRAPH_STYLE_NAME) && | |
259 | (GetParagraphStyleName() != attr.GetParagraphStyleName())) | |
260 | return false; | |
261 | ||
262 | if ((flags & wxTEXT_ATTR_LIST_STYLE_NAME) && | |
263 | (GetListStyleName() != attr.GetListStyleName())) | |
264 | return false; | |
265 | ||
266 | if ((flags & wxTEXT_ATTR_BULLET_STYLE) && | |
267 | (GetBulletStyle() != attr.GetBulletStyle())) | |
268 | return false; | |
269 | ||
270 | if ((flags & wxTEXT_ATTR_BULLET_NUMBER) && | |
271 | (GetBulletNumber() != attr.GetBulletNumber())) | |
272 | return false; | |
273 | ||
274 | if ((flags & wxTEXT_ATTR_BULLET_TEXT) && | |
275 | (GetBulletText() != attr.GetBulletText()) && | |
276 | (GetBulletFont() != attr.GetBulletFont())) | |
277 | return false; | |
278 | ||
279 | if ((flags & wxTEXT_ATTR_BULLET_NAME) && | |
280 | (GetBulletName() != attr.GetBulletName())) | |
281 | return false; | |
282 | ||
283 | if ((flags & wxTEXT_ATTR_TABS) && | |
284 | !TabsEq(GetTabs(), attr.GetTabs())) | |
285 | return false; | |
286 | ||
287 | if ((flags & wxTEXT_ATTR_PAGE_BREAK) && | |
288 | (HasPageBreak() != attr.HasPageBreak())) | |
289 | return false; | |
290 | ||
291 | if (flags & wxTEXT_ATTR_EFFECTS) | |
292 | { | |
293 | if (HasTextEffects() != attr.HasTextEffects()) | |
294 | return false; | |
295 | if (!BitlistsEqPartial(GetTextEffects(), attr.GetTextEffects(), attr.GetTextEffectFlags())) | |
296 | return false; | |
297 | } | |
298 | ||
299 | if ((flags & wxTEXT_ATTR_OUTLINE_LEVEL) && | |
300 | (GetOutlineLevel() != attr.GetOutlineLevel())) | |
301 | return false; | |
302 | ||
303 | return true; | |
304 | } | |
305 | ||
306 | // Create font from font attributes. | |
1fee6e25 | 307 | wxFont wxTextAttr::GetFont() const |
44cc96a8 | 308 | { |
1fee6e25 VZ |
309 | if ( !HasFont() ) |
310 | return wxNullFont; | |
311 | ||
44cc96a8 JS |
312 | int fontSize = 10; |
313 | if (HasFontSize()) | |
314 | fontSize = GetFontSize(); | |
315 | ||
316 | int fontStyle = wxNORMAL; | |
317 | if (HasFontItalic()) | |
318 | fontStyle = GetFontStyle(); | |
319 | ||
320 | int fontWeight = wxNORMAL; | |
321 | if (HasFontWeight()) | |
322 | fontWeight = GetFontWeight(); | |
323 | ||
324 | bool underlined = false; | |
325 | if (HasFontUnderlined()) | |
326 | underlined = GetFontUnderlined(); | |
327 | ||
328 | wxString fontFaceName; | |
329 | if (HasFontFaceName()) | |
330 | fontFaceName = GetFontFaceName(); | |
331 | ||
332 | wxFontEncoding encoding = wxFONTENCODING_DEFAULT; | |
333 | if (HasFontEncoding()) | |
334 | encoding = GetFontEncoding(); | |
335 | ||
9c4cb611 JS |
336 | int fontFamily = wxFONTFAMILY_DEFAULT; |
337 | if (HasFontFamily()) | |
338 | fontFamily = GetFontFamily(); | |
339 | ||
340 | wxFont font(fontSize, fontFamily, fontStyle, fontWeight, underlined, fontFaceName, encoding); | |
44cc96a8 JS |
341 | return font; |
342 | } | |
343 | ||
344 | // Get attributes from font. | |
345 | bool wxTextAttr::GetFontAttributes(const wxFont& font, int flags) | |
346 | { | |
347 | if (!font.Ok()) | |
348 | return false; | |
349 | ||
350 | if (flags & wxTEXT_ATTR_FONT_SIZE) | |
351 | m_fontSize = font.GetPointSize(); | |
352 | ||
353 | if (flags & wxTEXT_ATTR_FONT_ITALIC) | |
354 | m_fontStyle = font.GetStyle(); | |
355 | ||
356 | if (flags & wxTEXT_ATTR_FONT_WEIGHT) | |
357 | m_fontWeight = font.GetWeight(); | |
358 | ||
359 | if (flags & wxTEXT_ATTR_FONT_UNDERLINE) | |
360 | m_fontUnderlined = font.GetUnderlined(); | |
361 | ||
362 | if (flags & wxTEXT_ATTR_FONT_FACE) | |
363 | m_fontFaceName = font.GetFaceName(); | |
364 | ||
365 | if (flags & wxTEXT_ATTR_FONT_ENCODING) | |
366 | m_fontEncoding = font.GetEncoding(); | |
367 | ||
9c4cb611 JS |
368 | if (flags & wxTEXT_ATTR_FONT_FAMILY) |
369 | m_fontFamily = font.GetFamily(); | |
370 | ||
c4076626 JS |
371 | m_flags |= flags; |
372 | ||
44cc96a8 JS |
373 | return true; |
374 | } | |
375 | ||
d1e5be0e JS |
376 | // Resets bits in destination so new attributes aren't merged with mutually exclusive ones |
377 | static bool wxResetIncompatibleBits(const int mask, const int srcFlags, int& destFlags, int& destBits) | |
378 | { | |
379 | if ((srcFlags & mask) && (destFlags & mask)) | |
380 | { | |
381 | destBits &= ~mask; | |
382 | destFlags &= ~mask; | |
383 | } | |
384 | ||
385 | return true; | |
386 | } | |
387 | ||
44cc96a8 JS |
388 | bool wxTextAttr::Apply(const wxTextAttr& style, const wxTextAttr* compareWith) |
389 | { | |
390 | wxTextAttr& destStyle = (*this); | |
391 | ||
392 | if (style.HasFontWeight()) | |
393 | { | |
394 | if (!(compareWith && compareWith->HasFontWeight() && compareWith->GetFontWeight() == style.GetFontWeight())) | |
395 | destStyle.SetFontWeight(style.GetFontWeight()); | |
396 | } | |
397 | ||
398 | if (style.HasFontSize()) | |
399 | { | |
400 | if (!(compareWith && compareWith->HasFontSize() && compareWith->GetFontSize() == style.GetFontSize())) | |
401 | destStyle.SetFontSize(style.GetFontSize()); | |
402 | } | |
403 | ||
404 | if (style.HasFontItalic()) | |
405 | { | |
406 | if (!(compareWith && compareWith->HasFontItalic() && compareWith->GetFontStyle() == style.GetFontStyle())) | |
407 | destStyle.SetFontStyle(style.GetFontStyle()); | |
408 | } | |
409 | ||
410 | if (style.HasFontUnderlined()) | |
411 | { | |
412 | if (!(compareWith && compareWith->HasFontUnderlined() && compareWith->GetFontUnderlined() == style.GetFontUnderlined())) | |
413 | destStyle.SetFontUnderlined(style.GetFontUnderlined()); | |
414 | } | |
415 | ||
416 | if (style.HasFontFaceName()) | |
417 | { | |
418 | if (!(compareWith && compareWith->HasFontFaceName() && compareWith->GetFontFaceName() == style.GetFontFaceName())) | |
419 | destStyle.SetFontFaceName(style.GetFontFaceName()); | |
420 | } | |
421 | ||
422 | if (style.HasFontEncoding()) | |
423 | { | |
424 | if (!(compareWith && compareWith->HasFontEncoding() && compareWith->GetFontEncoding() == style.GetFontEncoding())) | |
425 | destStyle.SetFontEncoding(style.GetFontEncoding()); | |
426 | } | |
427 | ||
9c4cb611 JS |
428 | if (style.HasFontFamily()) |
429 | { | |
430 | if (!(compareWith && compareWith->HasFontFamily() && compareWith->GetFontFamily() == style.GetFontFamily())) | |
431 | destStyle.SetFontFamily(style.GetFontFamily()); | |
432 | } | |
433 | ||
44cc96a8 JS |
434 | if (style.GetTextColour().Ok() && style.HasTextColour()) |
435 | { | |
436 | if (!(compareWith && compareWith->HasTextColour() && compareWith->GetTextColour() == style.GetTextColour())) | |
437 | destStyle.SetTextColour(style.GetTextColour()); | |
438 | } | |
439 | ||
440 | if (style.GetBackgroundColour().Ok() && style.HasBackgroundColour()) | |
441 | { | |
442 | if (!(compareWith && compareWith->HasBackgroundColour() && compareWith->GetBackgroundColour() == style.GetBackgroundColour())) | |
443 | destStyle.SetBackgroundColour(style.GetBackgroundColour()); | |
444 | } | |
445 | ||
446 | if (style.HasAlignment()) | |
447 | { | |
448 | if (!(compareWith && compareWith->HasAlignment() && compareWith->GetAlignment() == style.GetAlignment())) | |
449 | destStyle.SetAlignment(style.GetAlignment()); | |
450 | } | |
451 | ||
452 | if (style.HasTabs()) | |
453 | { | |
454 | if (!(compareWith && compareWith->HasTabs() && TabsEq(compareWith->GetTabs(), style.GetTabs()))) | |
455 | destStyle.SetTabs(style.GetTabs()); | |
456 | } | |
457 | ||
458 | if (style.HasLeftIndent()) | |
459 | { | |
460 | if (!(compareWith && compareWith->HasLeftIndent() && compareWith->GetLeftIndent() == style.GetLeftIndent() | |
461 | && compareWith->GetLeftSubIndent() == style.GetLeftSubIndent())) | |
462 | destStyle.SetLeftIndent(style.GetLeftIndent(), style.GetLeftSubIndent()); | |
463 | } | |
464 | ||
465 | if (style.HasRightIndent()) | |
466 | { | |
467 | if (!(compareWith && compareWith->HasRightIndent() && compareWith->GetRightIndent() == style.GetRightIndent())) | |
468 | destStyle.SetRightIndent(style.GetRightIndent()); | |
469 | } | |
470 | ||
471 | if (style.HasParagraphSpacingAfter()) | |
472 | { | |
473 | if (!(compareWith && compareWith->HasParagraphSpacingAfter() && compareWith->GetParagraphSpacingAfter() == style.GetParagraphSpacingAfter())) | |
474 | destStyle.SetParagraphSpacingAfter(style.GetParagraphSpacingAfter()); | |
475 | } | |
476 | ||
477 | if (style.HasParagraphSpacingBefore()) | |
478 | { | |
479 | if (!(compareWith && compareWith->HasParagraphSpacingBefore() && compareWith->GetParagraphSpacingBefore() == style.GetParagraphSpacingBefore())) | |
480 | destStyle.SetParagraphSpacingBefore(style.GetParagraphSpacingBefore()); | |
481 | } | |
482 | ||
483 | if (style.HasLineSpacing()) | |
484 | { | |
485 | if (!(compareWith && compareWith->HasLineSpacing() && compareWith->GetLineSpacing() == style.GetLineSpacing())) | |
486 | destStyle.SetLineSpacing(style.GetLineSpacing()); | |
487 | } | |
488 | ||
489 | if (style.HasCharacterStyleName()) | |
490 | { | |
491 | if (!(compareWith && compareWith->HasCharacterStyleName() && compareWith->GetCharacterStyleName() == style.GetCharacterStyleName())) | |
492 | destStyle.SetCharacterStyleName(style.GetCharacterStyleName()); | |
493 | } | |
494 | ||
495 | if (style.HasParagraphStyleName()) | |
496 | { | |
497 | if (!(compareWith && compareWith->HasParagraphStyleName() && compareWith->GetParagraphStyleName() == style.GetParagraphStyleName())) | |
498 | destStyle.SetParagraphStyleName(style.GetParagraphStyleName()); | |
499 | } | |
500 | ||
501 | if (style.HasListStyleName()) | |
502 | { | |
503 | if (!(compareWith && compareWith->HasListStyleName() && compareWith->GetListStyleName() == style.GetListStyleName())) | |
504 | destStyle.SetListStyleName(style.GetListStyleName()); | |
505 | } | |
506 | ||
507 | if (style.HasBulletStyle()) | |
508 | { | |
509 | if (!(compareWith && compareWith->HasBulletStyle() && compareWith->GetBulletStyle() == style.GetBulletStyle())) | |
510 | destStyle.SetBulletStyle(style.GetBulletStyle()); | |
511 | } | |
512 | ||
513 | if (style.HasBulletText()) | |
514 | { | |
515 | if (!(compareWith && compareWith->HasBulletText() && compareWith->GetBulletText() == style.GetBulletText())) | |
516 | { | |
517 | destStyle.SetBulletText(style.GetBulletText()); | |
518 | destStyle.SetBulletFont(style.GetBulletFont()); | |
519 | } | |
520 | } | |
521 | ||
522 | if (style.HasBulletNumber()) | |
523 | { | |
524 | if (!(compareWith && compareWith->HasBulletNumber() && compareWith->GetBulletNumber() == style.GetBulletNumber())) | |
525 | destStyle.SetBulletNumber(style.GetBulletNumber()); | |
526 | } | |
527 | ||
528 | if (style.HasBulletName()) | |
529 | { | |
530 | if (!(compareWith && compareWith->HasBulletName() && compareWith->GetBulletName() == style.GetBulletName())) | |
531 | destStyle.SetBulletName(style.GetBulletName()); | |
532 | } | |
533 | ||
534 | if (style.HasURL()) | |
535 | { | |
536 | if (!(compareWith && compareWith->HasURL() && compareWith->GetURL() == style.GetURL())) | |
537 | destStyle.SetURL(style.GetURL()); | |
538 | } | |
539 | ||
540 | if (style.HasPageBreak()) | |
541 | { | |
542 | if (!(compareWith && compareWith->HasPageBreak())) | |
543 | destStyle.SetPageBreak(); | |
544 | } | |
545 | ||
546 | if (style.HasTextEffects()) | |
547 | { | |
548 | if (!(compareWith && compareWith->HasTextEffects() && compareWith->GetTextEffects() == style.GetTextEffects())) | |
549 | { | |
550 | int destBits = destStyle.GetTextEffects(); | |
551 | int destFlags = destStyle.GetTextEffectFlags(); | |
552 | ||
553 | int srcBits = style.GetTextEffects(); | |
554 | int srcFlags = style.GetTextEffectFlags(); | |
555 | ||
d1e5be0e JS |
556 | // Reset incompatible bits in the destination |
557 | wxResetIncompatibleBits((wxTEXT_ATTR_EFFECT_SUPERSCRIPT|wxTEXT_ATTR_EFFECT_SUBSCRIPT), srcFlags, destFlags, destBits); | |
558 | wxResetIncompatibleBits((wxTEXT_ATTR_EFFECT_CAPITALS|wxTEXT_ATTR_EFFECT_SMALL_CAPITALS), srcFlags, destFlags, destBits); | |
559 | wxResetIncompatibleBits((wxTEXT_ATTR_EFFECT_STRIKETHROUGH|wxTEXT_ATTR_EFFECT_DOUBLE_STRIKETHROUGH), srcFlags, destFlags, destBits); | |
560 | ||
44cc96a8 JS |
561 | CombineBitlists(destBits, srcBits, destFlags, srcFlags); |
562 | ||
563 | destStyle.SetTextEffects(destBits); | |
564 | destStyle.SetTextEffectFlags(destFlags); | |
565 | } | |
566 | } | |
567 | ||
568 | if (style.HasOutlineLevel()) | |
569 | { | |
570 | if (!(compareWith && compareWith->HasOutlineLevel() && compareWith->GetOutlineLevel() == style.GetOutlineLevel())) | |
571 | destStyle.SetOutlineLevel(style.GetOutlineLevel()); | |
572 | } | |
573 | ||
574 | return true; | |
e00a5d3c JS |
575 | } |
576 | ||
eda40bfc VZ |
577 | /* static */ |
578 | wxTextAttr wxTextAttr::Combine(const wxTextAttr& attr, | |
579 | const wxTextAttr& attrDef, | |
580 | const wxTextCtrlBase *text) | |
581 | { | |
7c3c990e JS |
582 | wxFont font; |
583 | if (attr.HasFont()) | |
584 | font = attr.GetFont(); | |
585 | ||
eda40bfc VZ |
586 | if ( !font.Ok() ) |
587 | { | |
7c3c990e JS |
588 | if (attrDef.HasFont()) |
589 | font = attrDef.GetFont(); | |
eda40bfc VZ |
590 | |
591 | if ( text && !font.Ok() ) | |
592 | font = text->GetFont(); | |
593 | } | |
594 | ||
595 | wxColour colFg = attr.GetTextColour(); | |
596 | if ( !colFg.Ok() ) | |
597 | { | |
598 | colFg = attrDef.GetTextColour(); | |
599 | ||
600 | if ( text && !colFg.Ok() ) | |
601 | colFg = text->GetForegroundColour(); | |
602 | } | |
603 | ||
604 | wxColour colBg = attr.GetBackgroundColour(); | |
605 | if ( !colBg.Ok() ) | |
606 | { | |
607 | colBg = attrDef.GetBackgroundColour(); | |
608 | ||
609 | if ( text && !colBg.Ok() ) | |
610 | colBg = text->GetBackgroundColour(); | |
611 | } | |
612 | ||
e00a5d3c | 613 | wxTextAttr newAttr(colFg, colBg, font); |
cb719f2e | 614 | |
e00a5d3c JS |
615 | if (attr.HasAlignment()) |
616 | newAttr.SetAlignment(attr.GetAlignment()); | |
617 | else if (attrDef.HasAlignment()) | |
618 | newAttr.SetAlignment(attrDef.GetAlignment()); | |
cb719f2e | 619 | |
e00a5d3c JS |
620 | if (attr.HasTabs()) |
621 | newAttr.SetTabs(attr.GetTabs()); | |
622 | else if (attrDef.HasTabs()) | |
623 | newAttr.SetTabs(attrDef.GetTabs()); | |
cb719f2e | 624 | |
e00a5d3c | 625 | if (attr.HasLeftIndent()) |
89b67477 | 626 | newAttr.SetLeftIndent(attr.GetLeftIndent(), attr.GetLeftSubIndent()); |
e00a5d3c | 627 | else if (attrDef.HasLeftIndent()) |
89b67477 | 628 | newAttr.SetLeftIndent(attrDef.GetLeftIndent(), attr.GetLeftSubIndent()); |
cb719f2e | 629 | |
e00a5d3c JS |
630 | if (attr.HasRightIndent()) |
631 | newAttr.SetRightIndent(attr.GetRightIndent()); | |
632 | else if (attrDef.HasRightIndent()) | |
cb719f2e WS |
633 | newAttr.SetRightIndent(attrDef.GetRightIndent()); |
634 | ||
e00a5d3c | 635 | return newAttr; |
eda40bfc VZ |
636 | } |
637 | ||
44cc96a8 JS |
638 | /// Compare tabs |
639 | bool wxTextAttr::TabsEq(const wxArrayInt& tabs1, const wxArrayInt& tabs2) | |
e00a5d3c | 640 | { |
44cc96a8 JS |
641 | if (tabs1.GetCount() != tabs2.GetCount()) |
642 | return false; | |
643 | ||
644 | size_t i; | |
645 | for (i = 0; i < tabs1.GetCount(); i++) | |
646 | { | |
647 | if (tabs1[i] != tabs2[i]) | |
648 | return false; | |
649 | } | |
650 | return true; | |
651 | } | |
652 | ||
653 | // Remove attributes | |
654 | bool wxTextAttr::RemoveStyle(wxTextAttr& destStyle, const wxTextAttr& style) | |
655 | { | |
656 | int flags = style.GetFlags(); | |
657 | int destFlags = destStyle.GetFlags(); | |
658 | ||
659 | destStyle.SetFlags(destFlags & ~flags); | |
660 | ||
661 | return true; | |
662 | } | |
663 | ||
664 | /// Combine two bitlists, specifying the bits of interest with separate flags. | |
665 | bool wxTextAttr::CombineBitlists(int& valueA, int valueB, int& flagsA, int flagsB) | |
666 | { | |
667 | // We want to apply B's bits to A, taking into account each's flags which indicate which bits | |
668 | // are to be taken into account. A zero in B's bits should reset that bit in A but only if B's flags | |
669 | // indicate it. | |
670 | ||
671 | // First, reset the 0 bits from B. We make a mask so we're only dealing with B's zero | |
672 | // bits at this point, ignoring any 1 bits in B or 0 bits in B that are not relevant. | |
673 | int valueA2 = ~(~valueB & flagsB) & valueA; | |
674 | ||
675 | // Now combine the 1 bits. | |
676 | int valueA3 = (valueB & flagsB) | valueA2; | |
677 | ||
678 | valueA = valueA3; | |
679 | flagsA = (flagsA | flagsB); | |
680 | ||
681 | return true; | |
682 | } | |
683 | ||
684 | /// Compare two bitlists | |
685 | bool wxTextAttr::BitlistsEqPartial(int valueA, int valueB, int flags) | |
686 | { | |
687 | int relevantBitsA = valueA & flags; | |
688 | int relevantBitsB = valueB & flags; | |
689 | return (relevantBitsA != relevantBitsB); | |
e00a5d3c JS |
690 | } |
691 | ||
44cc96a8 JS |
692 | /// Split into paragraph and character styles |
693 | bool wxTextAttr::SplitParaCharStyles(const wxTextAttr& style, wxTextAttr& parStyle, wxTextAttr& charStyle) | |
694 | { | |
695 | wxTextAttr defaultCharStyle1(style); | |
696 | wxTextAttr defaultParaStyle1(style); | |
697 | defaultCharStyle1.SetFlags(defaultCharStyle1.GetFlags()&wxTEXT_ATTR_CHARACTER); | |
698 | defaultParaStyle1.SetFlags(defaultParaStyle1.GetFlags()&wxTEXT_ATTR_PARAGRAPH); | |
699 | ||
700 | charStyle.Apply(defaultCharStyle1); | |
701 | parStyle.Apply(defaultParaStyle1); | |
702 | ||
703 | return true; | |
704 | } | |
e00a5d3c | 705 | |
4bc1afd5 VZ |
706 | // apply styling to text range |
707 | bool wxTextCtrlBase::SetStyle(long WXUNUSED(start), long WXUNUSED(end), | |
708 | const wxTextAttr& WXUNUSED(style)) | |
709 | { | |
0ec1179b | 710 | // to be implemented in derived classes |
cb719f2e | 711 | return false; |
4bc1afd5 VZ |
712 | } |
713 | ||
e00a5d3c JS |
714 | // get the styling at the given position |
715 | bool wxTextCtrlBase::GetStyle(long WXUNUSED(position), wxTextAttr& WXUNUSED(style)) | |
716 | { | |
0ec1179b | 717 | // to be implemented in derived classes |
cb719f2e | 718 | return false; |
e00a5d3c JS |
719 | } |
720 | ||
4bc1afd5 | 721 | // change default text attributes |
eda40bfc | 722 | bool wxTextCtrlBase::SetDefaultStyle(const wxTextAttr& style) |
4bc1afd5 | 723 | { |
c598f225 VZ |
724 | // keep the old attributes if the new style doesn't specify them unless the |
725 | // new style is empty - then reset m_defaultStyle (as there is no other way | |
726 | // to do it) | |
727 | if ( style.IsDefault() ) | |
728 | m_defaultStyle = style; | |
729 | else | |
730 | m_defaultStyle = wxTextAttr::Combine(style, m_defaultStyle, this); | |
eda40bfc | 731 | |
cb719f2e | 732 | return true; |
4bc1afd5 VZ |
733 | } |
734 | ||
a1b82138 VZ |
735 | // ---------------------------------------------------------------------------- |
736 | // file IO functions | |
737 | // ---------------------------------------------------------------------------- | |
738 | ||
3396739d | 739 | bool wxTextAreaBase::DoLoadFile(const wxString& filename, int WXUNUSED(fileType)) |
a1b82138 | 740 | { |
1e6feb95 | 741 | #if wxUSE_FFILE |
a1b82138 VZ |
742 | wxFFile file(filename); |
743 | if ( file.IsOpened() ) | |
744 | { | |
745 | wxString text; | |
746 | if ( file.ReadAll(&text) ) | |
747 | { | |
3396739d | 748 | SetValue(text); |
a1b82138 | 749 | |
cb719f2e | 750 | return true; |
a1b82138 VZ |
751 | } |
752 | } | |
3396739d VZ |
753 | #endif // wxUSE_FFILE |
754 | ||
755 | return false; | |
756 | } | |
a1b82138 | 757 | |
3396739d VZ |
758 | bool wxTextCtrlBase::DoLoadFile(const wxString& filename, int fileType) |
759 | { | |
760 | if ( wxTextAreaBase::DoLoadFile(filename, fileType) ) | |
761 | { | |
762 | DiscardEdits(); | |
763 | m_filename = filename; | |
764 | return true; | |
765 | } | |
a1b82138 | 766 | wxLogError(_("File couldn't be loaded.")); |
3396739d VZ |
767 | return false; |
768 | } | |
a1b82138 | 769 | |
3396739d VZ |
770 | bool wxTextAreaBase::DoSaveFile(const wxString& filename, int WXUNUSED(fileType)) |
771 | { | |
772 | #if wxUSE_FFILE | |
773 | wxFFile file(filename, wxT("w")); | |
774 | return file.IsOpened() && file.Write(GetValue(), *wxConvCurrent); | |
775 | #else | |
cb719f2e | 776 | return false; |
3396739d | 777 | #endif // wxUSE_FFILE |
a1b82138 VZ |
778 | } |
779 | ||
0ec1179b | 780 | bool wxTextAreaBase::SaveFile(const wxString& filename, int fileType) |
a1b82138 | 781 | { |
7d8268a1 | 782 | wxString filenameToUse = filename.empty() ? m_filename : filename; |
64dcc269 | 783 | if ( filenameToUse.empty() ) |
a1b82138 VZ |
784 | { |
785 | // what kind of message to give? is it an error or a program bug? | |
223d09f6 | 786 | wxLogDebug(wxT("Can't save textctrl to file without filename.")); |
a1b82138 | 787 | |
cb719f2e | 788 | return false; |
a1b82138 VZ |
789 | } |
790 | ||
3306aec1 JS |
791 | return DoSaveFile(filenameToUse, fileType); |
792 | } | |
793 | ||
3396739d | 794 | bool wxTextCtrlBase::DoSaveFile(const wxString& filename, int fileType) |
3306aec1 | 795 | { |
3396739d | 796 | if ( wxTextAreaBase::DoSaveFile(filename, fileType) ) |
a1b82138 | 797 | { |
3306aec1 JS |
798 | // if it worked, save for future calls |
799 | m_filename = filename; | |
ee2ec18e | 800 | |
a1b82138 VZ |
801 | // it's not modified any longer |
802 | DiscardEdits(); | |
803 | ||
cb719f2e | 804 | return true; |
a1b82138 | 805 | } |
cb719f2e | 806 | return false; |
a1b82138 VZ |
807 | } |
808 | ||
809 | // ---------------------------------------------------------------------------- | |
810 | // stream-like insertion operator | |
811 | // ---------------------------------------------------------------------------- | |
812 | ||
813 | wxTextCtrl& wxTextCtrlBase::operator<<(const wxString& s) | |
814 | { | |
815 | AppendText(s); | |
816 | return *TEXTCTRL(this); | |
817 | } | |
818 | ||
a1b82138 VZ |
819 | wxTextCtrl& wxTextCtrlBase::operator<<(double d) |
820 | { | |
9e50ed28 | 821 | return *this << wxString::Format("%.2f", d); |
a1b82138 VZ |
822 | } |
823 | ||
824 | wxTextCtrl& wxTextCtrlBase::operator<<(int i) | |
825 | { | |
9e50ed28 | 826 | return *this << wxString::Format("%d", i); |
a1b82138 VZ |
827 | } |
828 | ||
9e50ed28 | 829 | wxTextCtrl& wxTextCtrlBase::operator<<(long l) |
a1b82138 | 830 | { |
9e50ed28 | 831 | return *this << wxString::Format("%ld", l); |
a1b82138 VZ |
832 | } |
833 | ||
834 | // ---------------------------------------------------------------------------- | |
835 | // streambuf methods implementation | |
836 | // ---------------------------------------------------------------------------- | |
837 | ||
15cdc341 | 838 | #if wxHAS_TEXT_WINDOW_STREAM |
a1b82138 | 839 | |
d73e6791 | 840 | int wxTextCtrlBase::overflow(int c) |
a1b82138 | 841 | { |
d73e6791 | 842 | AppendText((wxChar)c); |
a1b82138 | 843 | |
d73e6791 | 844 | // return something different from EOF |
a1b82138 VZ |
845 | return 0; |
846 | } | |
847 | ||
15cdc341 | 848 | #endif // wxHAS_TEXT_WINDOW_STREAM |
a1b82138 | 849 | |
94af7d45 VZ |
850 | // ---------------------------------------------------------------------------- |
851 | // emulating key presses | |
852 | // ---------------------------------------------------------------------------- | |
853 | ||
854 | bool wxTextCtrlBase::EmulateKeyPress(const wxKeyEvent& event) | |
855 | { | |
0ec1179b VZ |
856 | // we have a native implementation for Win32 and so don't need this one |
857 | #ifndef __WIN32__ | |
02a48e3b | 858 | wxChar ch = 0; |
94af7d45 VZ |
859 | int keycode = event.GetKeyCode(); |
860 | switch ( keycode ) | |
861 | { | |
862 | case WXK_NUMPAD0: | |
863 | case WXK_NUMPAD1: | |
864 | case WXK_NUMPAD2: | |
865 | case WXK_NUMPAD3: | |
866 | case WXK_NUMPAD4: | |
867 | case WXK_NUMPAD5: | |
868 | case WXK_NUMPAD6: | |
869 | case WXK_NUMPAD7: | |
870 | case WXK_NUMPAD8: | |
871 | case WXK_NUMPAD9: | |
9a83f860 | 872 | ch = (wxChar)(wxT('0') + keycode - WXK_NUMPAD0); |
94af7d45 VZ |
873 | break; |
874 | ||
875 | case WXK_MULTIPLY: | |
876 | case WXK_NUMPAD_MULTIPLY: | |
9a83f860 | 877 | ch = wxT('*'); |
94af7d45 VZ |
878 | break; |
879 | ||
880 | case WXK_ADD: | |
881 | case WXK_NUMPAD_ADD: | |
9a83f860 | 882 | ch = wxT('+'); |
94af7d45 VZ |
883 | break; |
884 | ||
885 | case WXK_SUBTRACT: | |
886 | case WXK_NUMPAD_SUBTRACT: | |
9a83f860 | 887 | ch = wxT('-'); |
94af7d45 VZ |
888 | break; |
889 | ||
890 | case WXK_DECIMAL: | |
891 | case WXK_NUMPAD_DECIMAL: | |
9a83f860 | 892 | ch = wxT('.'); |
94af7d45 VZ |
893 | break; |
894 | ||
895 | case WXK_DIVIDE: | |
896 | case WXK_NUMPAD_DIVIDE: | |
9a83f860 | 897 | ch = wxT('/'); |
94af7d45 VZ |
898 | break; |
899 | ||
cd916794 VZ |
900 | case WXK_DELETE: |
901 | case WXK_NUMPAD_DELETE: | |
902 | // delete the character at cursor | |
903 | { | |
7d8268a1 WS |
904 | const long pos = GetInsertionPoint(); |
905 | if ( pos < GetLastPosition() ) | |
cd916794 VZ |
906 | Remove(pos, pos + 1); |
907 | } | |
908 | break; | |
909 | ||
910 | case WXK_BACK: | |
911 | // delete the character before the cursor | |
912 | { | |
913 | const long pos = GetInsertionPoint(); | |
914 | if ( pos > 0 ) | |
915 | Remove(pos - 1, pos); | |
916 | } | |
917 | break; | |
918 | ||
94af7d45 | 919 | default: |
c4d25c01 VS |
920 | #if wxUSE_UNICODE |
921 | if ( event.GetUnicodeKey() ) | |
922 | { | |
923 | ch = event.GetUnicodeKey(); | |
924 | } | |
925 | else | |
926 | #endif | |
401eb3de | 927 | if ( keycode < 256 && keycode >= 0 && wxIsprint(keycode) ) |
94af7d45 VZ |
928 | { |
929 | // FIXME this is not going to work for non letters... | |
930 | if ( !event.ShiftDown() ) | |
931 | { | |
401eb3de | 932 | keycode = wxTolower(keycode); |
94af7d45 VZ |
933 | } |
934 | ||
935 | ch = (wxChar)keycode; | |
936 | } | |
937 | else | |
938 | { | |
9a83f860 | 939 | ch = wxT('\0'); |
94af7d45 VZ |
940 | } |
941 | } | |
942 | ||
943 | if ( ch ) | |
944 | { | |
945 | WriteText(ch); | |
946 | ||
cb719f2e | 947 | return true; |
94af7d45 | 948 | } |
c8fe7fda VZ |
949 | #else // __WIN32__ |
950 | wxUnusedVar(event); | |
951 | #endif // !__WIN32__/__WIN32__ | |
94af7d45 | 952 | |
0ec1179b | 953 | return false; |
18414479 VZ |
954 | } |
955 | ||
e39af974 JS |
956 | // do the window-specific processing after processing the update event |
957 | void wxTextCtrlBase::DoUpdateWindowUI(wxUpdateUIEvent& event) | |
958 | { | |
a3a4105d VZ |
959 | // call inherited, but skip the wxControl's version, and call directly the |
960 | // wxWindow's one instead, because the only reason why we are overriding this | |
961 | // function is that we want to use SetValue() instead of wxControl::SetLabel() | |
962 | wxWindowBase::DoUpdateWindowUI(event); | |
cb719f2e | 963 | |
a3a4105d | 964 | // update text |
e39af974 JS |
965 | if ( event.GetSetText() ) |
966 | { | |
967 | if ( event.GetText() != GetValue() ) | |
968 | SetValue(event.GetText()); | |
cb719f2e | 969 | } |
e39af974 JS |
970 | } |
971 | ||
efe66bbc VZ |
972 | // ---------------------------------------------------------------------------- |
973 | // hit testing | |
974 | // ---------------------------------------------------------------------------- | |
975 | ||
692c9b86 | 976 | wxTextCtrlHitTestResult |
0ec1179b | 977 | wxTextAreaBase::HitTest(const wxPoint& pt, wxTextCoord *x, wxTextCoord *y) const |
692c9b86 VZ |
978 | { |
979 | // implement in terms of the other overload as the native ports typically | |
980 | // can get the position and not (x, y) pair directly (although wxUniv | |
981 | // directly gets x and y -- and so overrides this method as well) | |
982 | long pos; | |
983 | wxTextCtrlHitTestResult rc = HitTest(pt, &pos); | |
984 | ||
985 | if ( rc != wxTE_HT_UNKNOWN ) | |
986 | { | |
987 | PositionToXY(pos, x, y); | |
988 | } | |
989 | ||
990 | return rc; | |
991 | } | |
992 | ||
efe66bbc | 993 | wxTextCtrlHitTestResult |
0ec1179b | 994 | wxTextAreaBase::HitTest(const wxPoint& WXUNUSED(pt), long * WXUNUSED(pos)) const |
efe66bbc VZ |
995 | { |
996 | // not implemented | |
997 | return wxTE_HT_UNKNOWN; | |
998 | } | |
e39af974 | 999 | |
ee2ec18e VZ |
1000 | // ---------------------------------------------------------------------------- |
1001 | // events | |
1002 | // ---------------------------------------------------------------------------- | |
1003 | ||
0ec1179b | 1004 | /* static */ |
fa2f57be | 1005 | bool wxTextCtrlBase::SendTextUpdatedEvent(wxWindow *win) |
ee2ec18e | 1006 | { |
0ec1179b | 1007 | wxCommandEvent event(wxEVT_COMMAND_TEXT_UPDATED, win->GetId()); |
ee2ec18e VZ |
1008 | |
1009 | // do not do this as it could be very inefficient if the text control | |
1010 | // contains a lot of text and we're not using ref-counted wxString | |
1011 | // implementation -- instead, event.GetString() will query the control for | |
1012 | // its current text if needed | |
0ec1179b | 1013 | //event.SetString(win->GetValue()); |
ee2ec18e | 1014 | |
0ec1179b | 1015 | event.SetEventObject(win); |
fa2f57be | 1016 | return win->GetEventHandler()->ProcessEvent(event); |
ee2ec18e VZ |
1017 | } |
1018 | ||
ad0bae85 VZ |
1019 | #else // !wxUSE_TEXTCTRL |
1020 | ||
1021 | // define this one even if !wxUSE_TEXTCTRL because it is also used by other | |
1022 | // controls (wxComboBox and wxSpinCtrl) | |
ad0bae85 | 1023 | |
9b11752c | 1024 | wxDEFINE_EVENT( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEvent ); |
ad0bae85 VZ |
1025 | |
1026 | #endif // wxUSE_TEXTCTRL/!wxUSE_TEXTCTRL |