1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/common/textcmn.cpp
3 // Purpose: implementation of platform-independent functions of wxTextCtrl
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 13.07.99
7 // Copyright: (c) wxWidgets team
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
10
11 // ============================================================================
12 // declarations
13 // ============================================================================
14
15 // for compilers that support precompilation, includes "wx.h".
16 #include "wx/wxprec.h"
17
18 #ifdef __BORLANDC__
19 #pragma hdrstop
20 #endif
21
22 #ifndef WX_PRECOMP
23 #include "wx/event.h"
24 #endif // WX_PRECOMP
25
26 #if wxUSE_TEXTCTRL
27
28 #include "wx/textctrl.h"
29
30 #ifndef WX_PRECOMP
31 #include "wx/intl.h"
32 #include "wx/log.h"
33 #endif // WX_PRECOMP
34
35 #include "wx/ffile.h"
36
37 extern WXDLLEXPORT_DATA(const char) wxTextCtrlNameStr[] = "text";
38
39 // ----------------------------------------------------------------------------
40 // macros
41 // ----------------------------------------------------------------------------
42
43 // we don't have any objects of type wxTextCtrlBase in the program, only
44 // wxTextCtrl, so this cast is safe
45 #define TEXTCTRL(ptr) ((wxTextCtrl *)(ptr))
46
47 // ============================================================================
48 // implementation
49 // ============================================================================
50
51 // ----------------------------------------------------------------------------
52 // XTI
53 // ----------------------------------------------------------------------------
54
55 wxDEFINE_FLAGS( wxTextCtrlStyle )
56 wxBEGIN_FLAGS( wxTextCtrlStyle )
57 // new style border flags, we put them first to
58 // use them for streaming out
59 wxFLAGS_MEMBER(wxBORDER_SIMPLE)
60 wxFLAGS_MEMBER(wxBORDER_SUNKEN)
61 wxFLAGS_MEMBER(wxBORDER_DOUBLE)
62 wxFLAGS_MEMBER(wxBORDER_RAISED)
63 wxFLAGS_MEMBER(wxBORDER_STATIC)
64 wxFLAGS_MEMBER(wxBORDER_NONE)
65
66 // old style border flags
67 wxFLAGS_MEMBER(wxSIMPLE_BORDER)
68 wxFLAGS_MEMBER(wxSUNKEN_BORDER)
69 wxFLAGS_MEMBER(wxDOUBLE_BORDER)
70 wxFLAGS_MEMBER(wxRAISED_BORDER)
71 wxFLAGS_MEMBER(wxSTATIC_BORDER)
72 wxFLAGS_MEMBER(wxBORDER)
73
74 // standard window styles
75 wxFLAGS_MEMBER(wxTAB_TRAVERSAL)
76 wxFLAGS_MEMBER(wxCLIP_CHILDREN)
77 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW)
78 wxFLAGS_MEMBER(wxWANTS_CHARS)
79 wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE)
80 wxFLAGS_MEMBER(wxALWAYS_SHOW_SB )
81 wxFLAGS_MEMBER(wxVSCROLL)
82 wxFLAGS_MEMBER(wxHSCROLL)
83
84 wxFLAGS_MEMBER(wxTE_PROCESS_ENTER)
85 wxFLAGS_MEMBER(wxTE_PROCESS_TAB)
86 wxFLAGS_MEMBER(wxTE_MULTILINE)
87 wxFLAGS_MEMBER(wxTE_PASSWORD)
88 wxFLAGS_MEMBER(wxTE_READONLY)
89 wxFLAGS_MEMBER(wxHSCROLL)
90 wxFLAGS_MEMBER(wxTE_RICH)
91 wxFLAGS_MEMBER(wxTE_RICH2)
92 wxFLAGS_MEMBER(wxTE_AUTO_URL)
93 wxFLAGS_MEMBER(wxTE_NOHIDESEL)
94 wxFLAGS_MEMBER(wxTE_LEFT)
95 wxFLAGS_MEMBER(wxTE_CENTRE)
96 wxFLAGS_MEMBER(wxTE_RIGHT)
97 wxFLAGS_MEMBER(wxTE_DONTWRAP)
98 wxFLAGS_MEMBER(wxTE_CHARWRAP)
99 wxFLAGS_MEMBER(wxTE_WORDWRAP)
100 wxEND_FLAGS( wxTextCtrlStyle )
101
102 wxIMPLEMENT_DYNAMIC_CLASS_XTI(wxTextCtrl, wxControl, "wx/textctrl.h")
103
104 wxBEGIN_PROPERTIES_TABLE(wxTextCtrl)
105 wxEVENT_PROPERTY( TextUpdated, wxEVT_TEXT, wxCommandEvent )
106 wxEVENT_PROPERTY( TextEnter, wxEVT_TEXT_ENTER, wxCommandEvent )
107
108 wxPROPERTY( Font, wxFont, SetFont, GetFont , wxEMPTY_PARAMETER_VALUE, \
109 0 /*flags*/, wxT("Helpstring"), wxT("group") )
110 wxPROPERTY( Value, wxString, SetValue, GetValue, wxString(), \
111 0 /*flags*/, wxT("Helpstring"), wxT("group"))
112
113 wxPROPERTY_FLAGS( WindowStyle, wxTextCtrlStyle, long, SetWindowStyleFlag, \
114 GetWindowStyleFlag, wxEMPTY_PARAMETER_VALUE, 0 /*flags*/, \
115 wxT("Helpstring"), wxT("group")) // style
116 wxEND_PROPERTIES_TABLE()
117
118 wxEMPTY_HANDLERS_TABLE(wxTextCtrl)
119
120 wxCONSTRUCTOR_6( wxTextCtrl, wxWindow*, Parent, wxWindowID, Id, \
121 wxString, Value, wxPoint, Position, wxSize, Size, \
122 long, WindowStyle)
123
124
125 IMPLEMENT_DYNAMIC_CLASS(wxTextUrlEvent, wxCommandEvent)
126
127 wxDEFINE_EVENT( wxEVT_TEXT, wxCommandEvent );
128 wxDEFINE_EVENT( wxEVT_TEXT_ENTER, wxCommandEvent );
129 wxDEFINE_EVENT( wxEVT_TEXT_URL, wxTextUrlEvent );
130 wxDEFINE_EVENT( wxEVT_TEXT_MAXLEN, wxCommandEvent );
131
IMPLEMENT_ABSTRACT_CLASS(wxTextCtrlBase,wxControl)132 IMPLEMENT_ABSTRACT_CLASS(wxTextCtrlBase, wxControl)
133
134 // ============================================================================
135 // wxTextAttr implementation
136 // ============================================================================
137
138 wxTextAttr::wxTextAttr(const wxColour& colText,
139 const wxColour& colBack,
140 const wxFont& font,
141 wxTextAttrAlignment alignment): m_textAlignment(alignment), m_colText(colText), m_colBack(colBack)
142 {
143 Init();
144
145 if (m_colText.IsOk()) m_flags |= wxTEXT_ATTR_TEXT_COLOUR;
146 if (m_colBack.IsOk()) m_flags |= wxTEXT_ATTR_BACKGROUND_COLOUR;
147 if (alignment != wxTEXT_ALIGNMENT_DEFAULT)
148 m_flags |= wxTEXT_ATTR_ALIGNMENT;
149
150 GetFontAttributes(font);
151 }
152
153 // Initialisation
Init()154 void wxTextAttr::Init()
155 {
156 m_textAlignment = wxTEXT_ALIGNMENT_DEFAULT;
157 m_flags = 0;
158 m_leftIndent = 0;
159 m_leftSubIndent = 0;
160 m_rightIndent = 0;
161
162 m_fontSize = 12;
163 m_fontStyle = wxFONTSTYLE_NORMAL;
164 m_fontWeight = wxFONTWEIGHT_NORMAL;
165 m_fontUnderlined = false;
166 m_fontStrikethrough = false;
167 m_fontEncoding = wxFONTENCODING_DEFAULT;
168 m_fontFamily = wxFONTFAMILY_DEFAULT;
169
170 m_paragraphSpacingAfter = 0;
171 m_paragraphSpacingBefore = 0;
172 m_lineSpacing = 0;
173 m_bulletStyle = wxTEXT_ATTR_BULLET_STYLE_NONE;
174 m_textEffects = wxTEXT_ATTR_EFFECT_NONE;
175 m_textEffectFlags = wxTEXT_ATTR_EFFECT_NONE;
176 m_outlineLevel = 0;
177 m_bulletNumber = 0;
178 }
179
180 // Copy
Copy(const wxTextAttr & attr)181 void wxTextAttr::Copy(const wxTextAttr& attr)
182 {
183 m_colText = attr.m_colText;
184 m_colBack = attr.m_colBack;
185 m_textAlignment = attr.m_textAlignment;
186 m_leftIndent = attr.m_leftIndent;
187 m_leftSubIndent = attr.m_leftSubIndent;
188 m_rightIndent = attr.m_rightIndent;
189 m_tabs = attr.m_tabs;
190 m_flags = attr.m_flags;
191
192 m_fontSize = attr.m_fontSize;
193 m_fontStyle = attr.m_fontStyle;
194 m_fontWeight = attr.m_fontWeight;
195 m_fontUnderlined = attr.m_fontUnderlined;
196 m_fontStrikethrough = attr.m_fontStrikethrough;
197 m_fontFaceName = attr.m_fontFaceName;
198 m_fontEncoding = attr.m_fontEncoding;
199 m_fontFamily = attr.m_fontFamily;
200 m_textEffects = attr.m_textEffects;
201 m_textEffectFlags = attr.m_textEffectFlags;
202
203 m_paragraphSpacingAfter = attr.m_paragraphSpacingAfter;
204 m_paragraphSpacingBefore = attr.m_paragraphSpacingBefore;
205 m_lineSpacing = attr.m_lineSpacing;
206 m_characterStyleName = attr.m_characterStyleName;
207 m_paragraphStyleName = attr.m_paragraphStyleName;
208 m_listStyleName = attr.m_listStyleName;
209 m_bulletStyle = attr.m_bulletStyle;
210 m_bulletNumber = attr.m_bulletNumber;
211 m_bulletText = attr.m_bulletText;
212 m_bulletFont = attr.m_bulletFont;
213 m_bulletName = attr.m_bulletName;
214 m_outlineLevel = attr.m_outlineLevel;
215
216 m_urlTarget = attr.m_urlTarget;
217 }
218
219 // operators
operator =(const wxTextAttr & attr)220 void wxTextAttr::operator= (const wxTextAttr& attr)
221 {
222 Copy(attr);
223 }
224
225 // Equality test
operator ==(const wxTextAttr & attr) const226 bool wxTextAttr::operator== (const wxTextAttr& attr) const
227 {
228 return GetFlags() == attr.GetFlags() &&
229
230 (!HasTextColour() || (GetTextColour() == attr.GetTextColour())) &&
231 (!HasBackgroundColour() || (GetBackgroundColour() == attr.GetBackgroundColour())) &&
232
233 (!HasAlignment() || (GetAlignment() == attr.GetAlignment())) &&
234 (!HasLeftIndent() || (GetLeftIndent() == attr.GetLeftIndent() &&
235 GetLeftSubIndent() == attr.GetLeftSubIndent())) &&
236 (!HasRightIndent() || (GetRightIndent() == attr.GetRightIndent())) &&
237 (!HasTabs() || (TabsEq(GetTabs(), attr.GetTabs()))) &&
238
239 (!HasParagraphSpacingAfter() || (GetParagraphSpacingAfter() == attr.GetParagraphSpacingAfter())) &&
240 (!HasParagraphSpacingBefore() || (GetParagraphSpacingBefore() == attr.GetParagraphSpacingBefore())) &&
241 (!HasLineSpacing() || (GetLineSpacing() == attr.GetLineSpacing())) &&
242 (!HasCharacterStyleName() || (GetCharacterStyleName() == attr.GetCharacterStyleName())) &&
243 (!HasParagraphStyleName() || (GetParagraphStyleName() == attr.GetParagraphStyleName())) &&
244 (!HasListStyleName() || (GetListStyleName() == attr.GetListStyleName())) &&
245
246 (!HasBulletStyle() || (GetBulletStyle() == attr.GetBulletStyle())) &&
247 (!HasBulletText() || (GetBulletText() == attr.GetBulletText())) &&
248 (!HasBulletNumber() || (GetBulletNumber() == attr.GetBulletNumber())) &&
249 (GetBulletFont() == attr.GetBulletFont()) &&
250 (!HasBulletName() || (GetBulletName() == attr.GetBulletName())) &&
251
252 (!HasTextEffects() || (GetTextEffects() == attr.GetTextEffects() &&
253 GetTextEffectFlags() == attr.GetTextEffectFlags())) &&
254
255 (!HasOutlineLevel() || (GetOutlineLevel() == attr.GetOutlineLevel())) &&
256
257 (!HasFontSize() || (GetFontSize() == attr.GetFontSize())) &&
258 (!HasFontItalic() || (GetFontStyle() == attr.GetFontStyle())) &&
259 (!HasFontWeight() || (GetFontWeight() == attr.GetFontWeight())) &&
260 (!HasFontUnderlined() || (GetFontUnderlined() == attr.GetFontUnderlined())) &&
261 (!HasFontStrikethrough() || (GetFontStrikethrough() == attr.GetFontStrikethrough())) &&
262 (!HasFontFaceName() || (GetFontFaceName() == attr.GetFontFaceName())) &&
263 (!HasFontEncoding() || (GetFontEncoding() == attr.GetFontEncoding())) &&
264 (!HasFontFamily() || (GetFontFamily() == attr.GetFontFamily())) &&
265
266 (!HasURL() || (GetURL() == attr.GetURL()));
267 }
268
269 // Partial equality test. Only returns false if an attribute doesn't match.
EqPartial(const wxTextAttr & attr,bool weakTest) const270 bool wxTextAttr::EqPartial(const wxTextAttr& attr, bool weakTest) const
271 {
272 int flags = attr.GetFlags();
273
274 if (!weakTest &&
275 ((!HasTextColour() && attr.HasTextColour()) ||
276 (!HasBackgroundColour() && attr.HasBackgroundColour()) ||
277 (!HasFontFaceName() && attr.HasFontFaceName()) ||
278 (!HasFontSize() && attr.HasFontSize()) ||
279 (!HasFontWeight() && attr.HasFontWeight()) ||
280 (!HasFontItalic() && attr.HasFontItalic()) ||
281 (!HasFontUnderlined() && attr.HasFontUnderlined()) ||
282 (!HasFontStrikethrough() && attr.HasFontStrikethrough()) ||
283 (!HasFontEncoding() && attr.HasFontEncoding()) ||
284 (!HasFontFamily() && attr.HasFontFamily()) ||
285 (!HasURL() && attr.HasURL()) ||
286 (!HasAlignment() && attr.HasAlignment()) ||
287 (!HasLeftIndent() && attr.HasLeftIndent()) ||
288 (!HasParagraphSpacingAfter() && attr.HasParagraphSpacingAfter()) ||
289 (!HasParagraphSpacingBefore() && attr.HasParagraphSpacingBefore()) ||
290 (!HasLineSpacing() && attr.HasLineSpacing()) ||
291 (!HasCharacterStyleName() && attr.HasCharacterStyleName()) ||
292 (!HasParagraphStyleName() && attr.HasParagraphStyleName()) ||
293 (!HasListStyleName() && attr.HasListStyleName()) ||
294 (!HasBulletStyle() && attr.HasBulletStyle()) ||
295 (!HasBulletNumber() && attr.HasBulletNumber()) ||
296 (!HasBulletText() && attr.HasBulletText()) ||
297 (!HasBulletName() && attr.HasBulletName()) ||
298 (!HasTabs() && attr.HasTabs()) ||
299 (!HasTextEffects() && attr.HasTextEffects()) ||
300 (!HasOutlineLevel() && attr.HasOutlineLevel())))
301 {
302 return false;
303 }
304
305 if (HasTextColour() && attr.HasTextColour() && GetTextColour() != attr.GetTextColour())
306 return false;
307
308 if (HasBackgroundColour() && attr.HasBackgroundColour() && GetBackgroundColour() != attr.GetBackgroundColour())
309 return false;
310
311 if (HasFontFaceName() && attr.HasFontFaceName() && GetFontFaceName() != attr.GetFontFaceName())
312 return false;
313
314 // This checks whether the two objects have the same font size dimension (px versus pt)
315 if (HasFontSize() && attr.HasFontSize() && (flags & wxTEXT_ATTR_FONT) != (GetFlags() & wxTEXT_ATTR_FONT))
316 return false;
317
318 if (HasFontPointSize() && attr.HasFontPointSize() && GetFontSize() != attr.GetFontSize())
319 return false;
320
321 if (HasFontPixelSize() && attr.HasFontPixelSize() && GetFontSize() != attr.GetFontSize())
322 return false;
323
324 if (HasFontWeight() && attr.HasFontWeight() && GetFontWeight() != attr.GetFontWeight())
325 return false;
326
327 if (HasFontItalic() && attr.HasFontItalic() && GetFontStyle() != attr.GetFontStyle())
328 return false;
329
330 if (HasFontUnderlined() && attr.HasFontUnderlined() && GetFontUnderlined() != attr.GetFontUnderlined())
331 return false;
332
333 if (HasFontStrikethrough() && attr.HasFontStrikethrough() && GetFontStrikethrough() != attr.GetFontStrikethrough())
334 return false;
335
336 if (HasFontEncoding() && attr.HasFontEncoding() && GetFontEncoding() != attr.GetFontEncoding())
337 return false;
338
339 if (HasFontFamily() && attr.HasFontFamily() && GetFontFamily() != attr.GetFontFamily())
340 return false;
341
342 if (HasURL() && attr.HasURL() && GetURL() != attr.GetURL())
343 return false;
344
345 if (HasAlignment() && attr.HasAlignment() && GetAlignment() != attr.GetAlignment())
346 return false;
347
348 if (HasLeftIndent() && attr.HasLeftIndent() &&
349 ((GetLeftIndent() != attr.GetLeftIndent()) || (GetLeftSubIndent() != attr.GetLeftSubIndent())))
350 return false;
351
352 if (HasRightIndent() && attr.HasRightIndent() && (GetRightIndent() != attr.GetRightIndent()))
353 return false;
354
355 if (HasParagraphSpacingAfter() && attr.HasParagraphSpacingAfter() &&
356 (GetParagraphSpacingAfter() != attr.GetParagraphSpacingAfter()))
357 return false;
358
359 if (HasParagraphSpacingBefore() && attr.HasParagraphSpacingBefore() &&
360 (GetParagraphSpacingBefore() != attr.GetParagraphSpacingBefore()))
361 return false;
362
363 if (HasLineSpacing() && attr.HasLineSpacing() && (GetLineSpacing() != attr.GetLineSpacing()))
364 return false;
365
366 if (HasCharacterStyleName() && attr.HasCharacterStyleName() && (GetCharacterStyleName() != attr.GetCharacterStyleName()))
367 return false;
368
369 if (HasParagraphStyleName() && attr.HasParagraphStyleName() && (GetParagraphStyleName() != attr.GetParagraphStyleName()))
370 return false;
371
372 if (HasListStyleName() && attr.HasListStyleName() && (GetListStyleName() != attr.GetListStyleName()))
373 return false;
374
375 if (HasBulletStyle() && attr.HasBulletStyle() && (GetBulletStyle() != attr.GetBulletStyle()))
376 return false;
377
378 if (HasBulletNumber() && attr.HasBulletNumber() && (GetBulletNumber() != attr.GetBulletNumber()))
379 return false;
380
381 if (HasBulletText() && attr.HasBulletText() &&
382 (GetBulletText() != attr.GetBulletText()) &&
383 (GetBulletFont() != attr.GetBulletFont()))
384 return false;
385
386 if (HasBulletName() && attr.HasBulletName() && (GetBulletName() != attr.GetBulletName()))
387 return false;
388
389 if (HasTabs() && attr.HasTabs() && !TabsEq(GetTabs(), attr.GetTabs()))
390 return false;
391
392 if ((HasPageBreak() != attr.HasPageBreak()))
393 return false;
394
395 if (HasTextEffects() && attr.HasTextEffects())
396 {
397 if (!BitlistsEqPartial(GetTextEffects(), attr.GetTextEffects(), GetTextEffectFlags()))
398 return false;
399 }
400
401 if (HasOutlineLevel() && attr.HasOutlineLevel() && (GetOutlineLevel() != attr.GetOutlineLevel()))
402 return false;
403
404 return true;
405 }
406
407 // Create font from font attributes.
GetFont() const408 wxFont wxTextAttr::GetFont() const
409 {
410 if ( !HasFont() )
411 return wxNullFont;
412
413 int fontSize = 10;
414 if (HasFontSize())
415 fontSize = GetFontSize();
416
417 wxFontStyle fontStyle = wxFONTSTYLE_NORMAL;
418 if (HasFontItalic())
419 fontStyle = GetFontStyle();
420
421 wxFontWeight fontWeight = wxFONTWEIGHT_NORMAL;
422 if (HasFontWeight())
423 fontWeight = GetFontWeight();
424
425 bool underlined = false;
426 if (HasFontUnderlined())
427 underlined = GetFontUnderlined();
428
429 bool strikethrough = false;
430 if (HasFontStrikethrough())
431 strikethrough = GetFontStrikethrough();
432
433 wxString fontFaceName;
434 if (HasFontFaceName())
435 fontFaceName = GetFontFaceName();
436
437 wxFontEncoding encoding = wxFONTENCODING_DEFAULT;
438 if (HasFontEncoding())
439 encoding = GetFontEncoding();
440
441 wxFontFamily fontFamily = wxFONTFAMILY_DEFAULT;
442 if (HasFontFamily())
443 fontFamily = GetFontFamily();
444
445 if (HasFontPixelSize())
446 {
447 wxFont font(wxSize(0, fontSize), fontFamily, fontStyle, fontWeight, underlined, fontFaceName, encoding);
448 if (strikethrough)
449 font.SetStrikethrough(true);
450 return font;
451 }
452 else
453 {
454 wxFont font(fontSize, fontFamily, fontStyle, fontWeight, underlined, fontFaceName, encoding);
455 if (strikethrough)
456 font.SetStrikethrough(true);
457 return font;
458 }
459 }
460
461 // Get attributes from font.
GetFontAttributes(const wxFont & font,int flags)462 bool wxTextAttr::GetFontAttributes(const wxFont& font, int flags)
463 {
464 if (!font.IsOk())
465 return false;
466
467 // If we pass both pixel and point size attributes, this is an indication
468 // to choose the most appropriate units.
469 if ((flags & wxTEXT_ATTR_FONT) == wxTEXT_ATTR_FONT)
470 {
471 if (font.IsUsingSizeInPixels())
472 {
473 m_fontSize = font.GetPixelSize().y;
474 flags &= ~wxTEXT_ATTR_FONT_POINT_SIZE;
475 }
476 else
477 {
478 m_fontSize = font.GetPointSize();
479 flags &= ~wxTEXT_ATTR_FONT_PIXEL_SIZE;
480 }
481 }
482 else if (flags & wxTEXT_ATTR_FONT_POINT_SIZE)
483 {
484 m_fontSize = font.GetPointSize();
485 flags &= ~wxTEXT_ATTR_FONT_PIXEL_SIZE;
486 }
487 else if (flags & wxTEXT_ATTR_FONT_PIXEL_SIZE)
488 {
489 m_fontSize = font.GetPixelSize().y;
490 }
491
492 if (flags & wxTEXT_ATTR_FONT_ITALIC)
493 m_fontStyle = font.GetStyle();
494
495 if (flags & wxTEXT_ATTR_FONT_WEIGHT)
496 m_fontWeight = font.GetWeight();
497
498 if (flags & wxTEXT_ATTR_FONT_UNDERLINE)
499 m_fontUnderlined = font.GetUnderlined();
500
501 if (flags & wxTEXT_ATTR_FONT_STRIKETHROUGH)
502 m_fontStrikethrough = font.GetStrikethrough();
503
504 if (flags & wxTEXT_ATTR_FONT_FACE)
505 m_fontFaceName = font.GetFaceName();
506
507 if (flags & wxTEXT_ATTR_FONT_ENCODING)
508 m_fontEncoding = font.GetEncoding();
509
510 if (flags & wxTEXT_ATTR_FONT_FAMILY)
511 {
512 // wxFont might not know its family, avoid setting m_fontFamily to an
513 // invalid value and rather pretend that we don't have any font family
514 // information at all in this case
515 const wxFontFamily fontFamily = font.GetFamily();
516 if ( fontFamily == wxFONTFAMILY_UNKNOWN )
517 flags &= ~wxTEXT_ATTR_FONT_FAMILY;
518 else
519 m_fontFamily = fontFamily;
520 }
521
522 m_flags |= flags;
523
524 return true;
525 }
526
527 // Resets bits in destination so new attributes aren't merged with mutually exclusive ones
wxResetIncompatibleBits(const int mask,const int srcFlags,int & destFlags,int & destBits)528 static bool wxResetIncompatibleBits(const int mask, const int srcFlags, int& destFlags, int& destBits)
529 {
530 if ((srcFlags & mask) && (destFlags & mask))
531 {
532 destBits &= ~mask;
533 destFlags &= ~mask;
534 }
535
536 return true;
537 }
538
Apply(const wxTextAttr & style,const wxTextAttr * compareWith)539 bool wxTextAttr::Apply(const wxTextAttr& style, const wxTextAttr* compareWith)
540 {
541 wxTextAttr& destStyle = (*this);
542
543 if (style.HasFontWeight())
544 {
545 if (!(compareWith && compareWith->HasFontWeight() && compareWith->GetFontWeight() == style.GetFontWeight()))
546 destStyle.SetFontWeight(style.GetFontWeight());
547 }
548
549 if (style.HasFontPointSize())
550 {
551 if (!(compareWith && compareWith->HasFontPointSize() && compareWith->GetFontSize() == style.GetFontSize()))
552 destStyle.SetFontPointSize(style.GetFontSize());
553 }
554 else if (style.HasFontPixelSize())
555 {
556 if (!(compareWith && compareWith->HasFontPixelSize() && compareWith->GetFontSize() == style.GetFontSize()))
557 destStyle.SetFontPixelSize(style.GetFontSize());
558 }
559
560 if (style.HasFontItalic())
561 {
562 if (!(compareWith && compareWith->HasFontItalic() && compareWith->GetFontStyle() == style.GetFontStyle()))
563 destStyle.SetFontStyle(style.GetFontStyle());
564 }
565
566 if (style.HasFontUnderlined())
567 {
568 if (!(compareWith && compareWith->HasFontUnderlined() && compareWith->GetFontUnderlined() == style.GetFontUnderlined()))
569 destStyle.SetFontUnderlined(style.GetFontUnderlined());
570 }
571
572 if (style.HasFontStrikethrough())
573 {
574 if (!(compareWith && compareWith->HasFontStrikethrough() && compareWith->GetFontStrikethrough() == style.GetFontStrikethrough()))
575 destStyle.SetFontStrikethrough(style.GetFontStrikethrough());
576 }
577
578 if (style.HasFontFaceName())
579 {
580 if (!(compareWith && compareWith->HasFontFaceName() && compareWith->GetFontFaceName() == style.GetFontFaceName()))
581 destStyle.SetFontFaceName(style.GetFontFaceName());
582 }
583
584 if (style.HasFontEncoding())
585 {
586 if (!(compareWith && compareWith->HasFontEncoding() && compareWith->GetFontEncoding() == style.GetFontEncoding()))
587 destStyle.SetFontEncoding(style.GetFontEncoding());
588 }
589
590 if (style.HasFontFamily())
591 {
592 if (!(compareWith && compareWith->HasFontFamily() && compareWith->GetFontFamily() == style.GetFontFamily()))
593 destStyle.SetFontFamily(style.GetFontFamily());
594 }
595
596 if (style.GetTextColour().IsOk() && style.HasTextColour())
597 {
598 if (!(compareWith && compareWith->HasTextColour() && compareWith->GetTextColour() == style.GetTextColour()))
599 destStyle.SetTextColour(style.GetTextColour());
600 }
601
602 if (style.GetBackgroundColour().IsOk() && style.HasBackgroundColour())
603 {
604 if (!(compareWith && compareWith->HasBackgroundColour() && compareWith->GetBackgroundColour() == style.GetBackgroundColour()))
605 destStyle.SetBackgroundColour(style.GetBackgroundColour());
606 }
607
608 if (style.HasAlignment())
609 {
610 if (!(compareWith && compareWith->HasAlignment() && compareWith->GetAlignment() == style.GetAlignment()))
611 destStyle.SetAlignment(style.GetAlignment());
612 }
613
614 if (style.HasTabs())
615 {
616 if (!(compareWith && compareWith->HasTabs() && TabsEq(compareWith->GetTabs(), style.GetTabs())))
617 destStyle.SetTabs(style.GetTabs());
618 }
619
620 if (style.HasLeftIndent())
621 {
622 if (!(compareWith && compareWith->HasLeftIndent() && compareWith->GetLeftIndent() == style.GetLeftIndent()
623 && compareWith->GetLeftSubIndent() == style.GetLeftSubIndent()))
624 destStyle.SetLeftIndent(style.GetLeftIndent(), style.GetLeftSubIndent());
625 }
626
627 if (style.HasRightIndent())
628 {
629 if (!(compareWith && compareWith->HasRightIndent() && compareWith->GetRightIndent() == style.GetRightIndent()))
630 destStyle.SetRightIndent(style.GetRightIndent());
631 }
632
633 if (style.HasParagraphSpacingAfter())
634 {
635 if (!(compareWith && compareWith->HasParagraphSpacingAfter() && compareWith->GetParagraphSpacingAfter() == style.GetParagraphSpacingAfter()))
636 destStyle.SetParagraphSpacingAfter(style.GetParagraphSpacingAfter());
637 }
638
639 if (style.HasParagraphSpacingBefore())
640 {
641 if (!(compareWith && compareWith->HasParagraphSpacingBefore() && compareWith->GetParagraphSpacingBefore() == style.GetParagraphSpacingBefore()))
642 destStyle.SetParagraphSpacingBefore(style.GetParagraphSpacingBefore());
643 }
644
645 if (style.HasLineSpacing())
646 {
647 if (!(compareWith && compareWith->HasLineSpacing() && compareWith->GetLineSpacing() == style.GetLineSpacing()))
648 destStyle.SetLineSpacing(style.GetLineSpacing());
649 }
650
651 if (style.HasCharacterStyleName())
652 {
653 if (!(compareWith && compareWith->HasCharacterStyleName() && compareWith->GetCharacterStyleName() == style.GetCharacterStyleName()))
654 destStyle.SetCharacterStyleName(style.GetCharacterStyleName());
655 }
656
657 if (style.HasParagraphStyleName())
658 {
659 if (!(compareWith && compareWith->HasParagraphStyleName() && compareWith->GetParagraphStyleName() == style.GetParagraphStyleName()))
660 destStyle.SetParagraphStyleName(style.GetParagraphStyleName());
661 }
662
663 if (style.HasListStyleName())
664 {
665 if (!(compareWith && compareWith->HasListStyleName() && compareWith->GetListStyleName() == style.GetListStyleName()))
666 destStyle.SetListStyleName(style.GetListStyleName());
667 }
668
669 if (style.HasBulletStyle())
670 {
671 if (!(compareWith && compareWith->HasBulletStyle() && compareWith->GetBulletStyle() == style.GetBulletStyle()))
672 destStyle.SetBulletStyle(style.GetBulletStyle());
673 }
674
675 if (style.HasBulletText())
676 {
677 if (!(compareWith && compareWith->HasBulletText() && compareWith->GetBulletText() == style.GetBulletText()))
678 {
679 destStyle.SetBulletText(style.GetBulletText());
680 destStyle.SetBulletFont(style.GetBulletFont());
681 }
682 }
683
684 if (style.HasBulletNumber())
685 {
686 if (!(compareWith && compareWith->HasBulletNumber() && compareWith->GetBulletNumber() == style.GetBulletNumber()))
687 destStyle.SetBulletNumber(style.GetBulletNumber());
688 }
689
690 if (style.HasBulletName())
691 {
692 if (!(compareWith && compareWith->HasBulletName() && compareWith->GetBulletName() == style.GetBulletName()))
693 destStyle.SetBulletName(style.GetBulletName());
694 }
695
696 if (style.HasURL())
697 {
698 if (!(compareWith && compareWith->HasURL() && compareWith->GetURL() == style.GetURL()))
699 destStyle.SetURL(style.GetURL());
700 }
701
702 if (style.HasPageBreak())
703 {
704 if (!(compareWith && compareWith->HasPageBreak()))
705 destStyle.SetPageBreak();
706 }
707
708 if (style.HasTextEffects())
709 {
710 if (!(compareWith && compareWith->HasTextEffects() && compareWith->GetTextEffects() == style.GetTextEffects()))
711 {
712 int destBits = destStyle.GetTextEffects();
713 int destFlags = destStyle.GetTextEffectFlags();
714
715 int srcBits = style.GetTextEffects();
716 int srcFlags = style.GetTextEffectFlags();
717
718 // Reset incompatible bits in the destination
719 wxResetIncompatibleBits((wxTEXT_ATTR_EFFECT_SUPERSCRIPT|wxTEXT_ATTR_EFFECT_SUBSCRIPT), srcFlags, destFlags, destBits);
720 wxResetIncompatibleBits((wxTEXT_ATTR_EFFECT_CAPITALS|wxTEXT_ATTR_EFFECT_SMALL_CAPITALS), srcFlags, destFlags, destBits);
721 wxResetIncompatibleBits((wxTEXT_ATTR_EFFECT_STRIKETHROUGH|wxTEXT_ATTR_EFFECT_DOUBLE_STRIKETHROUGH), srcFlags, destFlags, destBits);
722
723 CombineBitlists(destBits, srcBits, destFlags, srcFlags);
724
725 destStyle.SetTextEffects(destBits);
726 destStyle.SetTextEffectFlags(destFlags);
727 }
728 }
729
730 if (style.HasOutlineLevel())
731 {
732 if (!(compareWith && compareWith->HasOutlineLevel() && compareWith->GetOutlineLevel() == style.GetOutlineLevel()))
733 destStyle.SetOutlineLevel(style.GetOutlineLevel());
734 }
735
736 return true;
737 }
738
739 /* static */
Combine(const wxTextAttr & attr,const wxTextAttr & attrDef,const wxTextCtrlBase * text)740 wxTextAttr wxTextAttr::Combine(const wxTextAttr& attr,
741 const wxTextAttr& attrDef,
742 const wxTextCtrlBase *text)
743 {
744 wxFont font;
745 if (attr.HasFont())
746 font = attr.GetFont();
747
748 if ( !font.IsOk() )
749 {
750 if (attrDef.HasFont())
751 font = attrDef.GetFont();
752
753 if ( text && !font.IsOk() )
754 font = text->GetFont();
755 }
756
757 wxColour colFg = attr.GetTextColour();
758 if ( !colFg.IsOk() )
759 {
760 colFg = attrDef.GetTextColour();
761
762 if ( text && !colFg.IsOk() )
763 colFg = text->GetForegroundColour();
764 }
765
766 wxColour colBg = attr.GetBackgroundColour();
767 if ( !colBg.IsOk() )
768 {
769 colBg = attrDef.GetBackgroundColour();
770
771 if ( text && !colBg.IsOk() )
772 colBg = text->GetBackgroundColour();
773 }
774
775 wxTextAttr newAttr(colFg, colBg, font);
776
777 if (attr.HasAlignment())
778 newAttr.SetAlignment(attr.GetAlignment());
779 else if (attrDef.HasAlignment())
780 newAttr.SetAlignment(attrDef.GetAlignment());
781
782 if (attr.HasTabs())
783 newAttr.SetTabs(attr.GetTabs());
784 else if (attrDef.HasTabs())
785 newAttr.SetTabs(attrDef.GetTabs());
786
787 if (attr.HasLeftIndent())
788 newAttr.SetLeftIndent(attr.GetLeftIndent(), attr.GetLeftSubIndent());
789 else if (attrDef.HasLeftIndent())
790 newAttr.SetLeftIndent(attrDef.GetLeftIndent(), attr.GetLeftSubIndent());
791
792 if (attr.HasRightIndent())
793 newAttr.SetRightIndent(attr.GetRightIndent());
794 else if (attrDef.HasRightIndent())
795 newAttr.SetRightIndent(attrDef.GetRightIndent());
796
797 return newAttr;
798 }
799
800 /// Compare tabs
TabsEq(const wxArrayInt & tabs1,const wxArrayInt & tabs2)801 bool wxTextAttr::TabsEq(const wxArrayInt& tabs1, const wxArrayInt& tabs2)
802 {
803 if (tabs1.GetCount() != tabs2.GetCount())
804 return false;
805
806 size_t i;
807 for (i = 0; i < tabs1.GetCount(); i++)
808 {
809 if (tabs1[i] != tabs2[i])
810 return false;
811 }
812 return true;
813 }
814
815 // Remove attributes
RemoveStyle(wxTextAttr & destStyle,const wxTextAttr & style)816 bool wxTextAttr::RemoveStyle(wxTextAttr& destStyle, const wxTextAttr& style)
817 {
818 int flags = style.GetFlags();
819 int destFlags = destStyle.GetFlags();
820
821 // We must treat text effects specially, since we must remove only some.
822 if (style.HasTextEffects() && (style.GetTextEffectFlags() != 0))
823 {
824 int newTextEffectFlags = destStyle.GetTextEffectFlags() & ~style.GetTextEffectFlags();
825 int newTextEffects = destStyle.GetTextEffects() & ~style.GetTextEffectFlags();
826 destStyle.SetTextEffects(newTextEffects);
827 destStyle.SetTextEffectFlags(newTextEffectFlags);
828
829 // Don't remove wxTEXT_ATTR_EFFECTS unless the resulting flags are zero
830 if (newTextEffectFlags != 0)
831 flags &= ~wxTEXT_ATTR_EFFECTS;
832 }
833
834 destStyle.SetFlags(destFlags & ~flags);
835
836 return true;
837 }
838
839 /// Combine two bitlists, specifying the bits of interest with separate flags.
CombineBitlists(int & valueA,int valueB,int & flagsA,int flagsB)840 bool wxTextAttr::CombineBitlists(int& valueA, int valueB, int& flagsA, int flagsB)
841 {
842 // We want to apply B's bits to A, taking into account each's flags which indicate which bits
843 // are to be taken into account. A zero in B's bits should reset that bit in A but only if B's flags
844 // indicate it.
845
846 // First, reset the 0 bits from B. We make a mask so we're only dealing with B's zero
847 // bits at this point, ignoring any 1 bits in B or 0 bits in B that are not relevant.
848 int valueA2 = ~(~valueB & flagsB) & valueA;
849
850 // Now combine the 1 bits.
851 int valueA3 = (valueB & flagsB) | valueA2;
852
853 valueA = valueA3;
854 flagsA = (flagsA | flagsB);
855
856 return true;
857 }
858
859 /// Compare two bitlists
BitlistsEqPartial(int valueA,int valueB,int flags)860 bool wxTextAttr::BitlistsEqPartial(int valueA, int valueB, int flags)
861 {
862 int relevantBitsA = valueA & flags;
863 int relevantBitsB = valueB & flags;
864 return relevantBitsA == relevantBitsB;
865 }
866
867 /// Split into paragraph and character styles
SplitParaCharStyles(const wxTextAttr & style,wxTextAttr & parStyle,wxTextAttr & charStyle)868 bool wxTextAttr::SplitParaCharStyles(const wxTextAttr& style, wxTextAttr& parStyle, wxTextAttr& charStyle)
869 {
870 wxTextAttr defaultCharStyle1(style);
871 wxTextAttr defaultParaStyle1(style);
872 defaultCharStyle1.SetFlags(defaultCharStyle1.GetFlags()&wxTEXT_ATTR_CHARACTER);
873 defaultParaStyle1.SetFlags(defaultParaStyle1.GetFlags()&wxTEXT_ATTR_PARAGRAPH);
874
875 charStyle.Apply(defaultCharStyle1);
876 parStyle.Apply(defaultParaStyle1);
877
878 return true;
879 }
880
881 // apply styling to text range
SetStyle(long WXUNUSED (start),long WXUNUSED (end),const wxTextAttr & WXUNUSED (style))882 bool wxTextCtrlBase::SetStyle(long WXUNUSED(start), long WXUNUSED(end),
883 const wxTextAttr& WXUNUSED(style))
884 {
885 // to be implemented in derived classes
886 return false;
887 }
888
889 // get the styling at the given position
GetStyle(long WXUNUSED (position),wxTextAttr & WXUNUSED (style))890 bool wxTextCtrlBase::GetStyle(long WXUNUSED(position), wxTextAttr& WXUNUSED(style))
891 {
892 // to be implemented in derived classes
893 return false;
894 }
895
896 // change default text attributes
SetDefaultStyle(const wxTextAttr & style)897 bool wxTextCtrlBase::SetDefaultStyle(const wxTextAttr& style)
898 {
899 // keep the old attributes if the new style doesn't specify them unless the
900 // new style is empty - then reset m_defaultStyle (as there is no other way
901 // to do it)
902 if ( style.IsDefault() )
903 m_defaultStyle = style;
904 else
905 m_defaultStyle = wxTextAttr::Combine(style, m_defaultStyle, this);
906
907 return true;
908 }
909
910 // ----------------------------------------------------------------------------
911 // file IO functions
912 // ----------------------------------------------------------------------------
913
DoLoadFile(const wxString & filename,int WXUNUSED (fileType))914 bool wxTextAreaBase::DoLoadFile(const wxString& filename, int WXUNUSED(fileType))
915 {
916 #if wxUSE_FFILE
917 wxFFile file(filename);
918 if ( file.IsOpened() )
919 {
920 wxString text;
921 if ( file.ReadAll(&text) )
922 {
923 SetValue(text);
924
925 DiscardEdits();
926 m_filename = filename;
927
928 return true;
929 }
930 }
931 #else
932 (void)filename; // avoid compiler warning about unreferenced parameter
933 #endif // wxUSE_FFILE
934
935 wxLogError(_("File couldn't be loaded."));
936
937 return false;
938 }
939
DoSaveFile(const wxString & filename,int WXUNUSED (fileType))940 bool wxTextAreaBase::DoSaveFile(const wxString& filename, int WXUNUSED(fileType))
941 {
942 #if wxUSE_FFILE
943 wxFFile file(filename, wxT("w"));
944 if ( file.IsOpened() && file.Write(GetValue()) )
945 {
946 // if it worked, save for future calls
947 m_filename = filename;
948
949 // it's not modified any longer
950 DiscardEdits();
951
952 return true;
953 }
954 #else
955 (void)filename; // avoid compiler warning about unreferenced parameter
956 #endif // wxUSE_FFILE
957
958 return false;
959 }
960
SaveFile(const wxString & filename,int fileType)961 bool wxTextAreaBase::SaveFile(const wxString& filename, int fileType)
962 {
963 wxString filenameToUse = filename.empty() ? m_filename : filename;
964 if ( filenameToUse.empty() )
965 {
966 // what kind of message to give? is it an error or a program bug?
967 wxLogDebug(wxT("Can't save textctrl to file without filename."));
968
969 return false;
970 }
971
972 return DoSaveFile(filenameToUse, fileType);
973 }
974
975 // ----------------------------------------------------------------------------
976 // stream-like insertion operator
977 // ----------------------------------------------------------------------------
978
operator <<(const wxString & s)979 wxTextCtrl& wxTextCtrlBase::operator<<(const wxString& s)
980 {
981 AppendText(s);
982 return *TEXTCTRL(this);
983 }
984
operator <<(double d)985 wxTextCtrl& wxTextCtrlBase::operator<<(double d)
986 {
987 return *this << wxString::Format("%.2f", d);
988 }
989
operator <<(int i)990 wxTextCtrl& wxTextCtrlBase::operator<<(int i)
991 {
992 return *this << wxString::Format("%d", i);
993 }
994
operator <<(long l)995 wxTextCtrl& wxTextCtrlBase::operator<<(long l)
996 {
997 return *this << wxString::Format("%ld", l);
998 }
999
1000 // ----------------------------------------------------------------------------
1001 // streambuf methods implementation
1002 // ----------------------------------------------------------------------------
1003
1004 #if wxHAS_TEXT_WINDOW_STREAM
1005
overflow(int c)1006 int wxTextCtrlBase::overflow(int c)
1007 {
1008 AppendText((wxChar)c);
1009
1010 // return something different from EOF
1011 return 0;
1012 }
1013
1014 #endif // wxHAS_TEXT_WINDOW_STREAM
1015
1016 // ----------------------------------------------------------------------------
1017 // emulating key presses
1018 // ----------------------------------------------------------------------------
1019
EmulateKeyPress(const wxKeyEvent & event)1020 bool wxTextCtrlBase::EmulateKeyPress(const wxKeyEvent& event)
1021 {
1022 bool handled = false;
1023 // we have a native implementation for Win32 and so don't need this one
1024 #ifndef __WIN32__
1025 wxChar ch = 0;
1026 int keycode = event.GetKeyCode();
1027
1028 long from, to;
1029 GetSelection(&from,&to);
1030 long insert = GetInsertionPoint();
1031 long last = GetLastPosition();
1032
1033 // catch arrow left and right
1034
1035 switch ( keycode )
1036 {
1037 case WXK_LEFT:
1038 if ( event.ShiftDown() )
1039 SetSelection( (from > 0 ? from - 1 : 0) , to );
1040 else
1041 {
1042 if ( from != to )
1043 insert = from;
1044 else if ( insert > 0 )
1045 insert -= 1;
1046 SetInsertionPoint( insert );
1047 }
1048 handled = true;
1049 break;
1050 case WXK_RIGHT:
1051 if ( event.ShiftDown() )
1052 SetSelection( from, (to < last ? to + 1 : last) );
1053 else
1054 {
1055 if ( from != to )
1056 insert = to;
1057 else if ( insert < last )
1058 insert += 1;
1059 SetInsertionPoint( insert );
1060 }
1061 handled = true;
1062 break;
1063 case WXK_NUMPAD0:
1064 case WXK_NUMPAD1:
1065 case WXK_NUMPAD2:
1066 case WXK_NUMPAD3:
1067 case WXK_NUMPAD4:
1068 case WXK_NUMPAD5:
1069 case WXK_NUMPAD6:
1070 case WXK_NUMPAD7:
1071 case WXK_NUMPAD8:
1072 case WXK_NUMPAD9:
1073 ch = (wxChar)(wxT('0') + keycode - WXK_NUMPAD0);
1074 break;
1075
1076 case WXK_MULTIPLY:
1077 case WXK_NUMPAD_MULTIPLY:
1078 ch = wxT('*');
1079 break;
1080
1081 case WXK_ADD:
1082 case WXK_NUMPAD_ADD:
1083 ch = wxT('+');
1084 break;
1085
1086 case WXK_SUBTRACT:
1087 case WXK_NUMPAD_SUBTRACT:
1088 ch = wxT('-');
1089 break;
1090
1091 case WXK_DECIMAL:
1092 case WXK_NUMPAD_DECIMAL:
1093 ch = wxT('.');
1094 break;
1095
1096 case WXK_DIVIDE:
1097 case WXK_NUMPAD_DIVIDE:
1098 ch = wxT('/');
1099 break;
1100
1101 case WXK_DELETE:
1102 case WXK_NUMPAD_DELETE:
1103 // delete the character at cursor
1104 {
1105 const long pos = GetInsertionPoint();
1106 if ( pos < GetLastPosition() )
1107 Remove(pos, pos + 1);
1108 handled = true;
1109 }
1110 break;
1111
1112 case WXK_BACK:
1113 // delete the character before the cursor
1114 {
1115 const long pos = GetInsertionPoint();
1116 if ( pos > 0 )
1117 Remove(pos - 1, pos);
1118 handled = true;
1119 }
1120 break;
1121
1122 default:
1123 #if wxUSE_UNICODE
1124 if ( event.GetUnicodeKey() )
1125 {
1126 ch = event.GetUnicodeKey();
1127 }
1128 else
1129 #endif
1130 if ( keycode < 256 && keycode >= 0 && wxIsprint(keycode) )
1131 {
1132 // FIXME this is not going to work for non letters...
1133 if ( !event.ShiftDown() )
1134 {
1135 keycode = wxTolower(keycode);
1136 }
1137
1138 ch = (wxChar)keycode;
1139 }
1140 else
1141 {
1142 ch = wxT('\0');
1143 }
1144 }
1145
1146 if ( ch )
1147 {
1148 WriteText(ch);
1149
1150 handled = true;
1151 }
1152 #else // __WIN32__
1153 wxUnusedVar(event);
1154 #endif // !__WIN32__/__WIN32__
1155
1156 return handled;
1157 }
1158
1159 // ----------------------------------------------------------------------------
1160 // Other miscellaneous stuff
1161 // ----------------------------------------------------------------------------
1162
SetHint(const wxString & hint)1163 bool wxTextCtrlBase::SetHint(const wxString& hint)
1164 {
1165 wxCHECK_MSG( IsSingleLine(), false,
1166 wxS("Hints can only be set for single line text controls") );
1167
1168 return wxTextEntry::SetHint(hint);
1169 }
1170
1171 // do the window-specific processing after processing the update event
DoUpdateWindowUI(wxUpdateUIEvent & event)1172 void wxTextCtrlBase::DoUpdateWindowUI(wxUpdateUIEvent& event)
1173 {
1174 // call inherited, but skip the wxControl's version, and call directly the
1175 // wxWindow's one instead, because the only reason why we are overriding this
1176 // function is that we want to use SetValue() instead of wxControl::SetLabel()
1177 wxWindowBase::DoUpdateWindowUI(event);
1178
1179 // update text
1180 if ( event.GetSetText() )
1181 {
1182 if ( event.GetText() != GetValue() )
1183 SetValue(event.GetText());
1184 }
1185 }
1186
1187 // ----------------------------------------------------------------------------
1188 // hit testing
1189 // ----------------------------------------------------------------------------
1190
1191 wxTextCtrlHitTestResult
HitTest(const wxPoint & pt,wxTextCoord * x,wxTextCoord * y) const1192 wxTextAreaBase::HitTest(const wxPoint& pt, wxTextCoord *x, wxTextCoord *y) const
1193 {
1194 // implement in terms of the other overload as the native ports typically
1195 // can get the position and not (x, y) pair directly (although wxUniv
1196 // directly gets x and y -- and so overrides this method as well)
1197 long pos;
1198 wxTextCtrlHitTestResult rc = HitTest(pt, &pos);
1199
1200 if ( rc != wxTE_HT_UNKNOWN )
1201 {
1202 PositionToXY(pos, x, y);
1203 }
1204
1205 return rc;
1206 }
1207
1208 wxTextCtrlHitTestResult
HitTest(const wxPoint & WXUNUSED (pt),long * WXUNUSED (pos)) const1209 wxTextAreaBase::HitTest(const wxPoint& WXUNUSED(pt), long * WXUNUSED(pos)) const
1210 {
1211 // not implemented
1212 return wxTE_HT_UNKNOWN;
1213 }
1214
PositionToCoords(long pos) const1215 wxPoint wxTextAreaBase::PositionToCoords(long pos) const
1216 {
1217 wxCHECK_MSG( IsValidPosition(pos), wxDefaultPosition,
1218 wxS("Position argument out of range.") );
1219
1220 return DoPositionToCoords(pos);
1221 }
1222
DoPositionToCoords(long WXUNUSED (pos)) const1223 wxPoint wxTextAreaBase::DoPositionToCoords(long WXUNUSED(pos)) const
1224 {
1225 return wxDefaultPosition;
1226 }
1227
1228 #else // !wxUSE_TEXTCTRL
1229
1230 // define this one even if !wxUSE_TEXTCTRL because it is also used by other
1231 // controls (wxComboBox and wxSpinCtrl)
1232
1233 wxDEFINE_EVENT( wxEVT_TEXT, wxCommandEvent );
1234
1235 #endif // wxUSE_TEXTCTRL/!wxUSE_TEXTCTRL
1236