]> git.saurik.com Git - wxWidgets.git/blame - src/common/textcmn.cpp
Improve horizontal scrolling in wxRibbonControl.
[wxWidgets.git] / src / common / textcmn.cpp
CommitLineData
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
f313deaa
PC
38extern WXDLLEXPORT_DATA(const char) wxTextCtrlNameStr[] = "text";
39
a1b82138
VZ
40// ----------------------------------------------------------------------------
41// macros
42// ----------------------------------------------------------------------------
43
44// we don't have any objects of type wxTextCtrlBase in the program, only
45// wxTextCtrl, so this cast is safe
46#define TEXTCTRL(ptr) ((wxTextCtrl *)(ptr))
47
48// ============================================================================
49// implementation
50// ============================================================================
51
28953245
SC
52// ----------------------------------------------------------------------------
53// XTI
54// ----------------------------------------------------------------------------
55
56wxDEFINE_FLAGS( wxTextCtrlStyle )
57wxBEGIN_FLAGS( wxTextCtrlStyle )
58// new style border flags, we put them first to
59// use them for streaming out
60wxFLAGS_MEMBER(wxBORDER_SIMPLE)
61wxFLAGS_MEMBER(wxBORDER_SUNKEN)
62wxFLAGS_MEMBER(wxBORDER_DOUBLE)
63wxFLAGS_MEMBER(wxBORDER_RAISED)
64wxFLAGS_MEMBER(wxBORDER_STATIC)
65wxFLAGS_MEMBER(wxBORDER_NONE)
66
67// old style border flags
68wxFLAGS_MEMBER(wxSIMPLE_BORDER)
69wxFLAGS_MEMBER(wxSUNKEN_BORDER)
70wxFLAGS_MEMBER(wxDOUBLE_BORDER)
71wxFLAGS_MEMBER(wxRAISED_BORDER)
72wxFLAGS_MEMBER(wxSTATIC_BORDER)
73wxFLAGS_MEMBER(wxBORDER)
74
75// standard window styles
76wxFLAGS_MEMBER(wxTAB_TRAVERSAL)
77wxFLAGS_MEMBER(wxCLIP_CHILDREN)
78wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW)
79wxFLAGS_MEMBER(wxWANTS_CHARS)
80wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE)
81wxFLAGS_MEMBER(wxALWAYS_SHOW_SB )
82wxFLAGS_MEMBER(wxVSCROLL)
83wxFLAGS_MEMBER(wxHSCROLL)
84
85wxFLAGS_MEMBER(wxTE_PROCESS_ENTER)
86wxFLAGS_MEMBER(wxTE_PROCESS_TAB)
87wxFLAGS_MEMBER(wxTE_MULTILINE)
88wxFLAGS_MEMBER(wxTE_PASSWORD)
89wxFLAGS_MEMBER(wxTE_READONLY)
90wxFLAGS_MEMBER(wxHSCROLL)
91wxFLAGS_MEMBER(wxTE_RICH)
92wxFLAGS_MEMBER(wxTE_RICH2)
93wxFLAGS_MEMBER(wxTE_AUTO_URL)
94wxFLAGS_MEMBER(wxTE_NOHIDESEL)
95wxFLAGS_MEMBER(wxTE_LEFT)
96wxFLAGS_MEMBER(wxTE_CENTRE)
97wxFLAGS_MEMBER(wxTE_RIGHT)
98wxFLAGS_MEMBER(wxTE_DONTWRAP)
99wxFLAGS_MEMBER(wxTE_CHARWRAP)
100wxFLAGS_MEMBER(wxTE_WORDWRAP)
101wxEND_FLAGS( wxTextCtrlStyle )
102
103wxIMPLEMENT_DYNAMIC_CLASS_XTI(wxTextCtrl, wxControl, "wx/textctrl.h")
104
105wxBEGIN_PROPERTIES_TABLE(wxTextCtrl)
ce7fe42e
VZ
106wxEVENT_PROPERTY( TextUpdated, wxEVT_TEXT, wxCommandEvent )
107wxEVENT_PROPERTY( TextEnter, wxEVT_TEXT_ENTER, wxCommandEvent )
28953245
SC
108
109wxPROPERTY( Font, wxFont, SetFont, GetFont , wxEMPTY_PARAMETER_VALUE, \
110 0 /*flags*/, wxT("Helpstring"), wxT("group") )
111wxPROPERTY( Value, wxString, SetValue, GetValue, wxString(), \
112 0 /*flags*/, wxT("Helpstring"), wxT("group"))
113
114wxPROPERTY_FLAGS( WindowStyle, wxTextCtrlStyle, long, SetWindowStyleFlag, \
115 GetWindowStyleFlag, wxEMPTY_PARAMETER_VALUE, 0 /*flags*/, \
116 wxT("Helpstring"), wxT("group")) // style
117wxEND_PROPERTIES_TABLE()
118
119wxEMPTY_HANDLERS_TABLE(wxTextCtrl)
120
121wxCONSTRUCTOR_6( wxTextCtrl, wxWindow*, Parent, wxWindowID, Id, \
122 wxString, Value, wxPoint, Position, wxSize, Size, \
123 long, WindowStyle)
124
125
c57e3339
VZ
126IMPLEMENT_DYNAMIC_CLASS(wxTextUrlEvent, wxCommandEvent)
127
ce7fe42e
VZ
128wxDEFINE_EVENT( wxEVT_TEXT, wxCommandEvent );
129wxDEFINE_EVENT( wxEVT_TEXT_ENTER, wxCommandEvent );
130wxDEFINE_EVENT( wxEVT_TEXT_URL, wxTextUrlEvent );
131wxDEFINE_EVENT( wxEVT_TEXT_MAXLEN, wxCommandEvent );
c57e3339 132
9d112688
JS
133IMPLEMENT_ABSTRACT_CLASS(wxTextCtrlBase, wxControl)
134
44cc96a8
JS
135// ============================================================================
136// wxTextAttr implementation
137// ============================================================================
4bc1afd5 138
e00a5d3c
JS
139wxTextAttr::wxTextAttr(const wxColour& colText,
140 const wxColour& colBack,
141 const wxFont& font,
44cc96a8 142 wxTextAttrAlignment alignment): m_textAlignment(alignment), m_colText(colText), m_colBack(colBack)
e00a5d3c 143{
44cc96a8
JS
144 Init();
145
a1b806b9
DS
146 if (m_colText.IsOk()) m_flags |= wxTEXT_ATTR_TEXT_COLOUR;
147 if (m_colBack.IsOk()) m_flags |= wxTEXT_ATTR_BACKGROUND_COLOUR;
e00a5d3c
JS
148 if (alignment != wxTEXT_ALIGNMENT_DEFAULT)
149 m_flags |= wxTEXT_ATTR_ALIGNMENT;
44cc96a8
JS
150
151 GetFontAttributes(font);
e00a5d3c
JS
152}
153
44cc96a8 154// Initialisation
e00a5d3c
JS
155void wxTextAttr::Init()
156{
157 m_textAlignment = wxTEXT_ALIGNMENT_DEFAULT;
158 m_flags = 0;
159 m_leftIndent = 0;
89b67477 160 m_leftSubIndent = 0;
e00a5d3c 161 m_rightIndent = 0;
44cc96a8
JS
162
163 m_fontSize = 12;
7d76fbd5
FM
164 m_fontStyle = wxFONTSTYLE_NORMAL;
165 m_fontWeight = wxFONTWEIGHT_NORMAL;
44cc96a8 166 m_fontUnderlined = false;
6e43a69f 167 m_fontStrikethrough = false;
44cc96a8 168 m_fontEncoding = wxFONTENCODING_DEFAULT;
9c4cb611 169 m_fontFamily = wxFONTFAMILY_DEFAULT;
44cc96a8
JS
170
171 m_paragraphSpacingAfter = 0;
172 m_paragraphSpacingBefore = 0;
173 m_lineSpacing = 0;
174 m_bulletStyle = wxTEXT_ATTR_BULLET_STYLE_NONE;
175 m_textEffects = wxTEXT_ATTR_EFFECT_NONE;
176 m_textEffectFlags = wxTEXT_ATTR_EFFECT_NONE;
177 m_outlineLevel = 0;
178 m_bulletNumber = 0;
179}
180
181// Copy
182void wxTextAttr::Copy(const wxTextAttr& attr)
183{
184 m_colText = attr.m_colText;
185 m_colBack = attr.m_colBack;
186 m_textAlignment = attr.m_textAlignment;
187 m_leftIndent = attr.m_leftIndent;
188 m_leftSubIndent = attr.m_leftSubIndent;
189 m_rightIndent = attr.m_rightIndent;
190 m_tabs = attr.m_tabs;
191 m_flags = attr.m_flags;
192
193 m_fontSize = attr.m_fontSize;
194 m_fontStyle = attr.m_fontStyle;
195 m_fontWeight = attr.m_fontWeight;
196 m_fontUnderlined = attr.m_fontUnderlined;
6e43a69f 197 m_fontStrikethrough = attr.m_fontStrikethrough;
44cc96a8
JS
198 m_fontFaceName = attr.m_fontFaceName;
199 m_fontEncoding = attr.m_fontEncoding;
9c4cb611 200 m_fontFamily = attr.m_fontFamily;
44cc96a8
JS
201 m_textEffects = attr.m_textEffects;
202 m_textEffectFlags = attr.m_textEffectFlags;
203
204 m_paragraphSpacingAfter = attr.m_paragraphSpacingAfter;
205 m_paragraphSpacingBefore = attr.m_paragraphSpacingBefore;
206 m_lineSpacing = attr.m_lineSpacing;
207 m_characterStyleName = attr.m_characterStyleName;
208 m_paragraphStyleName = attr.m_paragraphStyleName;
209 m_listStyleName = attr.m_listStyleName;
210 m_bulletStyle = attr.m_bulletStyle;
211 m_bulletNumber = attr.m_bulletNumber;
212 m_bulletText = attr.m_bulletText;
213 m_bulletFont = attr.m_bulletFont;
214 m_bulletName = attr.m_bulletName;
215 m_outlineLevel = attr.m_outlineLevel;
216
217 m_urlTarget = attr.m_urlTarget;
218}
219
220// operators
221void wxTextAttr::operator= (const wxTextAttr& attr)
222{
223 Copy(attr);
224}
225
226// Equality test
227bool wxTextAttr::operator== (const wxTextAttr& attr) const
228{
229 return GetFlags() == attr.GetFlags() &&
230
231 GetTextColour() == attr.GetTextColour() &&
232 GetBackgroundColour() == attr.GetBackgroundColour() &&
233
234 GetAlignment() == attr.GetAlignment() &&
235 GetLeftIndent() == attr.GetLeftIndent() &&
236 GetLeftSubIndent() == attr.GetLeftSubIndent() &&
237 GetRightIndent() == attr.GetRightIndent() &&
238 TabsEq(GetTabs(), attr.GetTabs()) &&
239
240 GetParagraphSpacingAfter() == attr.GetParagraphSpacingAfter() &&
241 GetParagraphSpacingBefore() == attr.GetParagraphSpacingBefore() &&
242 GetLineSpacing() == attr.GetLineSpacing() &&
243 GetCharacterStyleName() == attr.GetCharacterStyleName() &&
244 GetParagraphStyleName() == attr.GetParagraphStyleName() &&
245 GetListStyleName() == attr.GetListStyleName() &&
246
247 GetBulletStyle() == attr.GetBulletStyle() &&
248 GetBulletText() == attr.GetBulletText() &&
249 GetBulletNumber() == attr.GetBulletNumber() &&
250 GetBulletFont() == attr.GetBulletFont() &&
251 GetBulletName() == attr.GetBulletName() &&
252
253 GetTextEffects() == attr.GetTextEffects() &&
254 GetTextEffectFlags() == attr.GetTextEffectFlags() &&
255
256 GetOutlineLevel() == attr.GetOutlineLevel() &&
257
258 GetFontSize() == attr.GetFontSize() &&
259 GetFontStyle() == attr.GetFontStyle() &&
260 GetFontWeight() == attr.GetFontWeight() &&
261 GetFontUnderlined() == attr.GetFontUnderlined() &&
262 GetFontFaceName() == attr.GetFontFaceName() &&
263 GetFontEncoding() == attr.GetFontEncoding() &&
9c4cb611 264 GetFontFamily() == attr.GetFontFamily() &&
44cc96a8
JS
265
266 GetURL() == attr.GetURL();
267}
268
24777478 269// Partial equality test. Only returns false if an attribute doesn't match.
32423dd8 270bool wxTextAttr::EqPartial(const wxTextAttr& attr, bool weakTest) const
44cc96a8 271{
24777478 272 int flags = attr.GetFlags();
32423dd8
JS
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())
44cc96a8
JS
312 return false;
313
32423dd8
JS
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))
44cc96a8
JS
316 return false;
317
32423dd8 318 if (HasFontPointSize() && attr.HasFontPointSize() && GetFontSize() != attr.GetFontSize())
44cc96a8
JS
319 return false;
320
32423dd8 321 if (HasFontPixelSize() && attr.HasFontPixelSize() && GetFontSize() != attr.GetFontSize())
44cc96a8
JS
322 return false;
323
32423dd8 324 if (HasFontWeight() && attr.HasFontWeight() && GetFontWeight() != attr.GetFontWeight())
44cc96a8
JS
325 return false;
326
32423dd8 327 if (HasFontItalic() && attr.HasFontItalic() && GetFontStyle() != attr.GetFontStyle())
44cc96a8
JS
328 return false;
329
32423dd8 330 if (HasFontUnderlined() && attr.HasFontUnderlined() && GetFontUnderlined() != attr.GetFontUnderlined())
44cc96a8
JS
331 return false;
332
32423dd8 333 if (HasFontStrikethrough() && attr.HasFontStrikethrough() && GetFontStrikethrough() != attr.GetFontStrikethrough())
44cc96a8
JS
334 return false;
335
32423dd8 336 if (HasFontEncoding() && attr.HasFontEncoding() && GetFontEncoding() != attr.GetFontEncoding())
9c4cb611
JS
337 return false;
338
32423dd8 339 if (HasFontFamily() && attr.HasFontFamily() && GetFontFamily() != attr.GetFontFamily())
44cc96a8
JS
340 return false;
341
32423dd8 342 if (HasURL() && attr.HasURL() && GetURL() != attr.GetURL())
44cc96a8
JS
343 return false;
344
32423dd8
JS
345 if (HasAlignment() && attr.HasAlignment() && GetAlignment() != attr.GetAlignment())
346 return false;
347
348 if (HasLeftIndent() && attr.HasLeftIndent() &&
44cc96a8
JS
349 ((GetLeftIndent() != attr.GetLeftIndent()) || (GetLeftSubIndent() != attr.GetLeftSubIndent())))
350 return false;
351
32423dd8 352 if (HasRightIndent() && attr.HasRightIndent() && (GetRightIndent() != attr.GetRightIndent()))
44cc96a8
JS
353 return false;
354
32423dd8 355 if (HasParagraphSpacingAfter() && attr.HasParagraphSpacingAfter() &&
44cc96a8
JS
356 (GetParagraphSpacingAfter() != attr.GetParagraphSpacingAfter()))
357 return false;
358
32423dd8 359 if (HasParagraphSpacingBefore() && attr.HasParagraphSpacingBefore() &&
44cc96a8
JS
360 (GetParagraphSpacingBefore() != attr.GetParagraphSpacingBefore()))
361 return false;
362
32423dd8 363 if (HasLineSpacing() && attr.HasLineSpacing() && (GetLineSpacing() != attr.GetLineSpacing()))
44cc96a8
JS
364 return false;
365
32423dd8 366 if (HasCharacterStyleName() && attr.HasCharacterStyleName() && (GetCharacterStyleName() != attr.GetCharacterStyleName()))
44cc96a8
JS
367 return false;
368
32423dd8 369 if (HasParagraphStyleName() && attr.HasParagraphStyleName() && (GetParagraphStyleName() != attr.GetParagraphStyleName()))
44cc96a8
JS
370 return false;
371
32423dd8 372 if (HasListStyleName() && attr.HasListStyleName() && (GetListStyleName() != attr.GetListStyleName()))
44cc96a8
JS
373 return false;
374
32423dd8 375 if (HasBulletStyle() && attr.HasBulletStyle() && (GetBulletStyle() != attr.GetBulletStyle()))
44cc96a8
JS
376 return false;
377
32423dd8 378 if (HasBulletNumber() && attr.HasBulletNumber() && (GetBulletNumber() != attr.GetBulletNumber()))
44cc96a8
JS
379 return false;
380
32423dd8 381 if (HasBulletText() && attr.HasBulletText() &&
44cc96a8
JS
382 (GetBulletText() != attr.GetBulletText()) &&
383 (GetBulletFont() != attr.GetBulletFont()))
384 return false;
385
32423dd8 386 if (HasBulletName() && attr.HasBulletName() && (GetBulletName() != attr.GetBulletName()))
44cc96a8
JS
387 return false;
388
32423dd8 389 if (HasTabs() && attr.HasTabs() && !TabsEq(GetTabs(), attr.GetTabs()))
44cc96a8
JS
390 return false;
391
32423dd8 392 if ((HasPageBreak() != attr.HasPageBreak()))
44cc96a8
JS
393 return false;
394
32423dd8 395 if (HasTextEffects() && attr.HasTextEffects())
44cc96a8 396 {
44cc96a8
JS
397 if (!BitlistsEqPartial(GetTextEffects(), attr.GetTextEffects(), attr.GetTextEffectFlags()))
398 return false;
399 }
400
32423dd8 401 if (HasOutlineLevel() && attr.HasOutlineLevel() && (GetOutlineLevel() != attr.GetOutlineLevel()))
44cc96a8
JS
402 return false;
403
404 return true;
405}
406
407// Create font from font attributes.
1fee6e25 408wxFont wxTextAttr::GetFont() const
44cc96a8 409{
1fee6e25
VZ
410 if ( !HasFont() )
411 return wxNullFont;
412
44cc96a8
JS
413 int fontSize = 10;
414 if (HasFontSize())
415 fontSize = GetFontSize();
416
32423dd8 417 wxFontStyle fontStyle = wxFONTSTYLE_NORMAL;
44cc96a8
JS
418 if (HasFontItalic())
419 fontStyle = GetFontStyle();
420
32423dd8 421 wxFontWeight fontWeight = wxFONTWEIGHT_NORMAL;
44cc96a8
JS
422 if (HasFontWeight())
423 fontWeight = GetFontWeight();
424
425 bool underlined = false;
426 if (HasFontUnderlined())
427 underlined = GetFontUnderlined();
428
c7a49742 429 bool strikethrough = false;
32423dd8 430 if (HasFontStrikethrough())
c7a49742
VZ
431 strikethrough = GetFontStrikethrough();
432
44cc96a8
JS
433 wxString fontFaceName;
434 if (HasFontFaceName())
435 fontFaceName = GetFontFaceName();
436
437 wxFontEncoding encoding = wxFONTENCODING_DEFAULT;
438 if (HasFontEncoding())
439 encoding = GetFontEncoding();
440
aa926768 441 wxFontFamily fontFamily = wxFONTFAMILY_DEFAULT;
9c4cb611
JS
442 if (HasFontFamily())
443 fontFamily = GetFontFamily();
444
32423dd8
JS
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 }
44cc96a8
JS
459}
460
461// Get attributes from font.
462bool wxTextAttr::GetFontAttributes(const wxFont& font, int flags)
463{
a1b806b9 464 if (!font.IsOk())
44cc96a8
JS
465 return false;
466
32423dd8
JS
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 {
44cc96a8 484 m_fontSize = font.GetPointSize();
32423dd8
JS
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 }
44cc96a8
JS
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
c7a49742
VZ
501 if (flags & wxTEXT_ATTR_FONT_STRIKETHROUGH)
502 m_fontStrikethrough = font.GetStrikethrough();
503
44cc96a8
JS
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
9c4cb611 510 if (flags & wxTEXT_ATTR_FONT_FAMILY)
aa926768
VZ
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 }
9c4cb611 521
c4076626
JS
522 m_flags |= flags;
523
44cc96a8
JS
524 return true;
525}
526
d1e5be0e
JS
527// Resets bits in destination so new attributes aren't merged with mutually exclusive ones
528static 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
44cc96a8
JS
539bool 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
32423dd8
JS
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())
44cc96a8 555 {
32423dd8
JS
556 if (!(compareWith && compareWith->HasFontPixelSize() && compareWith->GetFontSize() == style.GetFontSize()))
557 destStyle.SetFontPixelSize(style.GetFontSize());
44cc96a8
JS
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
c7a49742
VZ
572 if (style.HasFontStrikethrough())
573 {
574 if (!(compareWith && compareWith->HasFontStrikethrough() && compareWith->GetFontStrikethrough() == style.GetFontStrikethrough()))
575 destStyle.SetFontStrikethrough(style.GetFontStrikethrough());
576 }
577
44cc96a8
JS
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
9c4cb611
JS
590 if (style.HasFontFamily())
591 {
592 if (!(compareWith && compareWith->HasFontFamily() && compareWith->GetFontFamily() == style.GetFontFamily()))
593 destStyle.SetFontFamily(style.GetFontFamily());
594 }
595
a1b806b9 596 if (style.GetTextColour().IsOk() && style.HasTextColour())
44cc96a8
JS
597 {
598 if (!(compareWith && compareWith->HasTextColour() && compareWith->GetTextColour() == style.GetTextColour()))
599 destStyle.SetTextColour(style.GetTextColour());
600 }
601
a1b806b9 602 if (style.GetBackgroundColour().IsOk() && style.HasBackgroundColour())
44cc96a8
JS
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
d1e5be0e
JS
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
44cc96a8
JS
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;
e00a5d3c
JS
737}
738
eda40bfc
VZ
739/* static */
740wxTextAttr wxTextAttr::Combine(const wxTextAttr& attr,
741 const wxTextAttr& attrDef,
742 const wxTextCtrlBase *text)
743{
7c3c990e
JS
744 wxFont font;
745 if (attr.HasFont())
746 font = attr.GetFont();
747
a1b806b9 748 if ( !font.IsOk() )
eda40bfc 749 {
7c3c990e
JS
750 if (attrDef.HasFont())
751 font = attrDef.GetFont();
eda40bfc 752
a1b806b9 753 if ( text && !font.IsOk() )
eda40bfc
VZ
754 font = text->GetFont();
755 }
756
757 wxColour colFg = attr.GetTextColour();
a1b806b9 758 if ( !colFg.IsOk() )
eda40bfc
VZ
759 {
760 colFg = attrDef.GetTextColour();
761
a1b806b9 762 if ( text && !colFg.IsOk() )
eda40bfc
VZ
763 colFg = text->GetForegroundColour();
764 }
765
766 wxColour colBg = attr.GetBackgroundColour();
a1b806b9 767 if ( !colBg.IsOk() )
eda40bfc
VZ
768 {
769 colBg = attrDef.GetBackgroundColour();
770
a1b806b9 771 if ( text && !colBg.IsOk() )
eda40bfc
VZ
772 colBg = text->GetBackgroundColour();
773 }
774
e00a5d3c 775 wxTextAttr newAttr(colFg, colBg, font);
cb719f2e 776
e00a5d3c
JS
777 if (attr.HasAlignment())
778 newAttr.SetAlignment(attr.GetAlignment());
779 else if (attrDef.HasAlignment())
780 newAttr.SetAlignment(attrDef.GetAlignment());
cb719f2e 781
e00a5d3c
JS
782 if (attr.HasTabs())
783 newAttr.SetTabs(attr.GetTabs());
784 else if (attrDef.HasTabs())
785 newAttr.SetTabs(attrDef.GetTabs());
cb719f2e 786
e00a5d3c 787 if (attr.HasLeftIndent())
89b67477 788 newAttr.SetLeftIndent(attr.GetLeftIndent(), attr.GetLeftSubIndent());
e00a5d3c 789 else if (attrDef.HasLeftIndent())
89b67477 790 newAttr.SetLeftIndent(attrDef.GetLeftIndent(), attr.GetLeftSubIndent());
cb719f2e 791
e00a5d3c
JS
792 if (attr.HasRightIndent())
793 newAttr.SetRightIndent(attr.GetRightIndent());
794 else if (attrDef.HasRightIndent())
cb719f2e
WS
795 newAttr.SetRightIndent(attrDef.GetRightIndent());
796
e00a5d3c 797 return newAttr;
eda40bfc
VZ
798}
799
44cc96a8
JS
800/// Compare tabs
801bool wxTextAttr::TabsEq(const wxArrayInt& tabs1, const wxArrayInt& tabs2)
e00a5d3c 802{
44cc96a8
JS
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
816bool wxTextAttr::RemoveStyle(wxTextAttr& destStyle, const wxTextAttr& style)
817{
818 int flags = style.GetFlags();
819 int destFlags = destStyle.GetFlags();
820
821 destStyle.SetFlags(destFlags & ~flags);
822
823 return true;
824}
825
826/// Combine two bitlists, specifying the bits of interest with separate flags.
827bool wxTextAttr::CombineBitlists(int& valueA, int valueB, int& flagsA, int flagsB)
828{
829 // We want to apply B's bits to A, taking into account each's flags which indicate which bits
830 // are to be taken into account. A zero in B's bits should reset that bit in A but only if B's flags
831 // indicate it.
832
833 // First, reset the 0 bits from B. We make a mask so we're only dealing with B's zero
834 // bits at this point, ignoring any 1 bits in B or 0 bits in B that are not relevant.
835 int valueA2 = ~(~valueB & flagsB) & valueA;
836
837 // Now combine the 1 bits.
838 int valueA3 = (valueB & flagsB) | valueA2;
839
840 valueA = valueA3;
841 flagsA = (flagsA | flagsB);
842
843 return true;
844}
845
846/// Compare two bitlists
847bool wxTextAttr::BitlistsEqPartial(int valueA, int valueB, int flags)
848{
849 int relevantBitsA = valueA & flags;
850 int relevantBitsB = valueB & flags;
54c730a9 851 return relevantBitsA == relevantBitsB;
e00a5d3c
JS
852}
853
44cc96a8
JS
854/// Split into paragraph and character styles
855bool wxTextAttr::SplitParaCharStyles(const wxTextAttr& style, wxTextAttr& parStyle, wxTextAttr& charStyle)
856{
857 wxTextAttr defaultCharStyle1(style);
858 wxTextAttr defaultParaStyle1(style);
859 defaultCharStyle1.SetFlags(defaultCharStyle1.GetFlags()&wxTEXT_ATTR_CHARACTER);
860 defaultParaStyle1.SetFlags(defaultParaStyle1.GetFlags()&wxTEXT_ATTR_PARAGRAPH);
861
862 charStyle.Apply(defaultCharStyle1);
863 parStyle.Apply(defaultParaStyle1);
864
865 return true;
866}
e00a5d3c 867
4bc1afd5
VZ
868// apply styling to text range
869bool wxTextCtrlBase::SetStyle(long WXUNUSED(start), long WXUNUSED(end),
870 const wxTextAttr& WXUNUSED(style))
871{
0ec1179b 872 // to be implemented in derived classes
cb719f2e 873 return false;
4bc1afd5
VZ
874}
875
e00a5d3c
JS
876// get the styling at the given position
877bool wxTextCtrlBase::GetStyle(long WXUNUSED(position), wxTextAttr& WXUNUSED(style))
878{
0ec1179b 879 // to be implemented in derived classes
cb719f2e 880 return false;
e00a5d3c
JS
881}
882
4bc1afd5 883// change default text attributes
eda40bfc 884bool wxTextCtrlBase::SetDefaultStyle(const wxTextAttr& style)
4bc1afd5 885{
c598f225
VZ
886 // keep the old attributes if the new style doesn't specify them unless the
887 // new style is empty - then reset m_defaultStyle (as there is no other way
888 // to do it)
889 if ( style.IsDefault() )
890 m_defaultStyle = style;
891 else
892 m_defaultStyle = wxTextAttr::Combine(style, m_defaultStyle, this);
eda40bfc 893
cb719f2e 894 return true;
4bc1afd5
VZ
895}
896
a1b82138
VZ
897// ----------------------------------------------------------------------------
898// file IO functions
899// ----------------------------------------------------------------------------
900
3396739d 901bool wxTextAreaBase::DoLoadFile(const wxString& filename, int WXUNUSED(fileType))
a1b82138 902{
1e6feb95 903#if wxUSE_FFILE
a1b82138
VZ
904 wxFFile file(filename);
905 if ( file.IsOpened() )
906 {
907 wxString text;
908 if ( file.ReadAll(&text) )
909 {
3396739d 910 SetValue(text);
a1b82138 911
90761420
VZ
912 DiscardEdits();
913 m_filename = filename;
914
cb719f2e 915 return true;
a1b82138
VZ
916 }
917 }
3396739d
VZ
918#endif // wxUSE_FFILE
919
90761420
VZ
920 wxLogError(_("File couldn't be loaded."));
921
3396739d
VZ
922 return false;
923}
a1b82138 924
90761420 925bool wxTextAreaBase::DoSaveFile(const wxString& filename, int WXUNUSED(fileType))
3396739d 926{
90761420
VZ
927#if wxUSE_FFILE
928 wxFFile file(filename, wxT("w"));
929 if ( file.IsOpened() && file.Write(GetValue(), *wxConvCurrent) )
3396739d 930 {
90761420 931 // if it worked, save for future calls
3396739d 932 m_filename = filename;
90761420
VZ
933
934 // it's not modified any longer
935 DiscardEdits();
936
3396739d
VZ
937 return true;
938 }
90761420 939#endif // wxUSE_FFILE
a1b82138 940
cb719f2e 941 return false;
a1b82138
VZ
942}
943
0ec1179b 944bool wxTextAreaBase::SaveFile(const wxString& filename, int fileType)
a1b82138 945{
7d8268a1 946 wxString filenameToUse = filename.empty() ? m_filename : filename;
64dcc269 947 if ( filenameToUse.empty() )
a1b82138
VZ
948 {
949 // what kind of message to give? is it an error or a program bug?
223d09f6 950 wxLogDebug(wxT("Can't save textctrl to file without filename."));
a1b82138 951
cb719f2e 952 return false;
a1b82138
VZ
953 }
954
3306aec1
JS
955 return DoSaveFile(filenameToUse, fileType);
956}
957
a1b82138
VZ
958// ----------------------------------------------------------------------------
959// stream-like insertion operator
960// ----------------------------------------------------------------------------
961
962wxTextCtrl& wxTextCtrlBase::operator<<(const wxString& s)
963{
964 AppendText(s);
965 return *TEXTCTRL(this);
966}
967
a1b82138
VZ
968wxTextCtrl& wxTextCtrlBase::operator<<(double d)
969{
9e50ed28 970 return *this << wxString::Format("%.2f", d);
a1b82138
VZ
971}
972
973wxTextCtrl& wxTextCtrlBase::operator<<(int i)
974{
9e50ed28 975 return *this << wxString::Format("%d", i);
a1b82138
VZ
976}
977
9e50ed28 978wxTextCtrl& wxTextCtrlBase::operator<<(long l)
a1b82138 979{
9e50ed28 980 return *this << wxString::Format("%ld", l);
a1b82138
VZ
981}
982
983// ----------------------------------------------------------------------------
984// streambuf methods implementation
985// ----------------------------------------------------------------------------
986
15cdc341 987#if wxHAS_TEXT_WINDOW_STREAM
a1b82138 988
d73e6791 989int wxTextCtrlBase::overflow(int c)
a1b82138 990{
d73e6791 991 AppendText((wxChar)c);
a1b82138 992
d73e6791 993 // return something different from EOF
a1b82138
VZ
994 return 0;
995}
996
15cdc341 997#endif // wxHAS_TEXT_WINDOW_STREAM
a1b82138 998
94af7d45
VZ
999// ----------------------------------------------------------------------------
1000// emulating key presses
1001// ----------------------------------------------------------------------------
1002
1003bool wxTextCtrlBase::EmulateKeyPress(const wxKeyEvent& event)
1004{
8680646d 1005 bool handled = false;
0ec1179b
VZ
1006 // we have a native implementation for Win32 and so don't need this one
1007#ifndef __WIN32__
02a48e3b 1008 wxChar ch = 0;
94af7d45 1009 int keycode = event.GetKeyCode();
32423dd8 1010
8680646d
SC
1011 long from, to;
1012 GetSelection(&from,&to);
1013 long insert = GetInsertionPoint();
1014 long last = GetLastPosition();
32423dd8
JS
1015
1016 // catch arrow left and right
1017
94af7d45
VZ
1018 switch ( keycode )
1019 {
8680646d
SC
1020 case WXK_LEFT:
1021 if ( event.ShiftDown() )
1022 SetSelection( (from > 0 ? from - 1 : 0) , to );
1023 else
1024 {
1025 if ( from != to )
1026 insert = from;
1027 else if ( insert > 0 )
1028 insert -= 1;
1029 SetInsertionPoint( insert );
1030 }
1031 handled = true;
1032 break;
1033 case WXK_RIGHT:
1034 if ( event.ShiftDown() )
1035 SetSelection( from, (to < last ? to + 1 : last) );
1036 else
1037 {
1038 if ( from != to )
1039 insert = to;
1040 else if ( insert < last )
1041 insert += 1;
1042 SetInsertionPoint( insert );
1043 }
1044 handled = true;
1045 break;
94af7d45
VZ
1046 case WXK_NUMPAD0:
1047 case WXK_NUMPAD1:
1048 case WXK_NUMPAD2:
1049 case WXK_NUMPAD3:
1050 case WXK_NUMPAD4:
1051 case WXK_NUMPAD5:
1052 case WXK_NUMPAD6:
1053 case WXK_NUMPAD7:
1054 case WXK_NUMPAD8:
1055 case WXK_NUMPAD9:
9a83f860 1056 ch = (wxChar)(wxT('0') + keycode - WXK_NUMPAD0);
94af7d45
VZ
1057 break;
1058
1059 case WXK_MULTIPLY:
1060 case WXK_NUMPAD_MULTIPLY:
9a83f860 1061 ch = wxT('*');
94af7d45
VZ
1062 break;
1063
1064 case WXK_ADD:
1065 case WXK_NUMPAD_ADD:
9a83f860 1066 ch = wxT('+');
94af7d45
VZ
1067 break;
1068
1069 case WXK_SUBTRACT:
1070 case WXK_NUMPAD_SUBTRACT:
9a83f860 1071 ch = wxT('-');
94af7d45
VZ
1072 break;
1073
1074 case WXK_DECIMAL:
1075 case WXK_NUMPAD_DECIMAL:
9a83f860 1076 ch = wxT('.');
94af7d45
VZ
1077 break;
1078
1079 case WXK_DIVIDE:
1080 case WXK_NUMPAD_DIVIDE:
9a83f860 1081 ch = wxT('/');
94af7d45
VZ
1082 break;
1083
cd916794
VZ
1084 case WXK_DELETE:
1085 case WXK_NUMPAD_DELETE:
1086 // delete the character at cursor
1087 {
7d8268a1
WS
1088 const long pos = GetInsertionPoint();
1089 if ( pos < GetLastPosition() )
cd916794 1090 Remove(pos, pos + 1);
8680646d 1091 handled = true;
cd916794
VZ
1092 }
1093 break;
1094
1095 case WXK_BACK:
1096 // delete the character before the cursor
1097 {
1098 const long pos = GetInsertionPoint();
1099 if ( pos > 0 )
1100 Remove(pos - 1, pos);
8680646d 1101 handled = true;
cd916794
VZ
1102 }
1103 break;
1104
94af7d45 1105 default:
c4d25c01
VS
1106#if wxUSE_UNICODE
1107 if ( event.GetUnicodeKey() )
1108 {
1109 ch = event.GetUnicodeKey();
1110 }
1111 else
1112#endif
401eb3de 1113 if ( keycode < 256 && keycode >= 0 && wxIsprint(keycode) )
94af7d45
VZ
1114 {
1115 // FIXME this is not going to work for non letters...
1116 if ( !event.ShiftDown() )
1117 {
401eb3de 1118 keycode = wxTolower(keycode);
94af7d45
VZ
1119 }
1120
1121 ch = (wxChar)keycode;
1122 }
1123 else
1124 {
9a83f860 1125 ch = wxT('\0');
94af7d45
VZ
1126 }
1127 }
1128
1129 if ( ch )
1130 {
1131 WriteText(ch);
1132
8680646d 1133 handled = true;
94af7d45 1134 }
c8fe7fda
VZ
1135#else // __WIN32__
1136 wxUnusedVar(event);
1137#endif // !__WIN32__/__WIN32__
94af7d45 1138
8680646d 1139 return handled;
18414479
VZ
1140}
1141
7dd65e5a
VZ
1142// ----------------------------------------------------------------------------
1143// Other miscellaneous stuff
1144// ----------------------------------------------------------------------------
1145
1146bool wxTextCtrlBase::SetHint(const wxString& hint)
1147{
1148 wxCHECK_MSG( IsSingleLine(), false,
1149 wxS("Hints can only be set for single line text controls") );
1150
1151 return wxTextEntry::SetHint(hint);
1152}
1153
e39af974
JS
1154// do the window-specific processing after processing the update event
1155void wxTextCtrlBase::DoUpdateWindowUI(wxUpdateUIEvent& event)
1156{
a3a4105d
VZ
1157 // call inherited, but skip the wxControl's version, and call directly the
1158 // wxWindow's one instead, because the only reason why we are overriding this
1159 // function is that we want to use SetValue() instead of wxControl::SetLabel()
1160 wxWindowBase::DoUpdateWindowUI(event);
cb719f2e 1161
a3a4105d 1162 // update text
e39af974
JS
1163 if ( event.GetSetText() )
1164 {
1165 if ( event.GetText() != GetValue() )
1166 SetValue(event.GetText());
cb719f2e 1167 }
e39af974
JS
1168}
1169
efe66bbc
VZ
1170// ----------------------------------------------------------------------------
1171// hit testing
1172// ----------------------------------------------------------------------------
1173
692c9b86 1174wxTextCtrlHitTestResult
0ec1179b 1175wxTextAreaBase::HitTest(const wxPoint& pt, wxTextCoord *x, wxTextCoord *y) const
692c9b86
VZ
1176{
1177 // implement in terms of the other overload as the native ports typically
1178 // can get the position and not (x, y) pair directly (although wxUniv
1179 // directly gets x and y -- and so overrides this method as well)
1180 long pos;
1181 wxTextCtrlHitTestResult rc = HitTest(pt, &pos);
1182
1183 if ( rc != wxTE_HT_UNKNOWN )
1184 {
1185 PositionToXY(pos, x, y);
1186 }
1187
1188 return rc;
1189}
1190
efe66bbc 1191wxTextCtrlHitTestResult
0ec1179b 1192wxTextAreaBase::HitTest(const wxPoint& WXUNUSED(pt), long * WXUNUSED(pos)) const
efe66bbc
VZ
1193{
1194 // not implemented
1195 return wxTE_HT_UNKNOWN;
1196}
e39af974 1197
6ce83213
VZ
1198wxPoint wxTextAreaBase::PositionToCoords(long pos) const
1199{
1200 wxCHECK_MSG( IsValidPosition(pos), wxDefaultPosition,
1201 wxS("Position argument out of range.") );
1202
1203 return DoPositionToCoords(pos);
1204}
1205
1206wxPoint wxTextAreaBase::DoPositionToCoords(long WXUNUSED(pos)) const
1207{
1208 return wxDefaultPosition;
1209}
1210
ad0bae85
VZ
1211#else // !wxUSE_TEXTCTRL
1212
1213// define this one even if !wxUSE_TEXTCTRL because it is also used by other
1214// controls (wxComboBox and wxSpinCtrl)
ad0bae85 1215
ce7fe42e 1216wxDEFINE_EVENT( wxEVT_TEXT, wxCommandEvent );
ad0bae85
VZ
1217
1218#endif // wxUSE_TEXTCTRL/!wxUSE_TEXTCTRL