1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/common/textcmn.cpp
3 // Purpose: implementation of platform-independent functions of wxTextCtrl
4 // Author: Julian Smart
8 // Copyright: (c) wxWidgets team
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // for compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
29 #include "wx/textctrl.h"
38 extern WXDLLEXPORT_DATA(const char) wxTextCtrlNameStr
[] = "text";
40 // ----------------------------------------------------------------------------
42 // ----------------------------------------------------------------------------
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))
48 // ============================================================================
50 // ============================================================================
52 // ----------------------------------------------------------------------------
54 // ----------------------------------------------------------------------------
56 wxDEFINE_FLAGS( wxTextCtrlStyle
)
57 wxBEGIN_FLAGS( wxTextCtrlStyle
)
58 // new style border flags, we put them first to
59 // use them for streaming out
60 wxFLAGS_MEMBER(wxBORDER_SIMPLE
)
61 wxFLAGS_MEMBER(wxBORDER_SUNKEN
)
62 wxFLAGS_MEMBER(wxBORDER_DOUBLE
)
63 wxFLAGS_MEMBER(wxBORDER_RAISED
)
64 wxFLAGS_MEMBER(wxBORDER_STATIC
)
65 wxFLAGS_MEMBER(wxBORDER_NONE
)
67 // old style border flags
68 wxFLAGS_MEMBER(wxSIMPLE_BORDER
)
69 wxFLAGS_MEMBER(wxSUNKEN_BORDER
)
70 wxFLAGS_MEMBER(wxDOUBLE_BORDER
)
71 wxFLAGS_MEMBER(wxRAISED_BORDER
)
72 wxFLAGS_MEMBER(wxSTATIC_BORDER
)
73 wxFLAGS_MEMBER(wxBORDER
)
75 // standard window styles
76 wxFLAGS_MEMBER(wxTAB_TRAVERSAL
)
77 wxFLAGS_MEMBER(wxCLIP_CHILDREN
)
78 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW
)
79 wxFLAGS_MEMBER(wxWANTS_CHARS
)
80 wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE
)
81 wxFLAGS_MEMBER(wxALWAYS_SHOW_SB
)
82 wxFLAGS_MEMBER(wxVSCROLL
)
83 wxFLAGS_MEMBER(wxHSCROLL
)
85 wxFLAGS_MEMBER(wxTE_PROCESS_ENTER
)
86 wxFLAGS_MEMBER(wxTE_PROCESS_TAB
)
87 wxFLAGS_MEMBER(wxTE_MULTILINE
)
88 wxFLAGS_MEMBER(wxTE_PASSWORD
)
89 wxFLAGS_MEMBER(wxTE_READONLY
)
90 wxFLAGS_MEMBER(wxHSCROLL
)
91 wxFLAGS_MEMBER(wxTE_RICH
)
92 wxFLAGS_MEMBER(wxTE_RICH2
)
93 wxFLAGS_MEMBER(wxTE_AUTO_URL
)
94 wxFLAGS_MEMBER(wxTE_NOHIDESEL
)
95 wxFLAGS_MEMBER(wxTE_LEFT
)
96 wxFLAGS_MEMBER(wxTE_CENTRE
)
97 wxFLAGS_MEMBER(wxTE_RIGHT
)
98 wxFLAGS_MEMBER(wxTE_DONTWRAP
)
99 wxFLAGS_MEMBER(wxTE_CHARWRAP
)
100 wxFLAGS_MEMBER(wxTE_WORDWRAP
)
101 wxEND_FLAGS( wxTextCtrlStyle
)
103 wxIMPLEMENT_DYNAMIC_CLASS_XTI(wxTextCtrl
, wxControl
, "wx/textctrl.h")
105 wxBEGIN_PROPERTIES_TABLE(wxTextCtrl
)
106 wxEVENT_PROPERTY( TextUpdated
, wxEVT_COMMAND_TEXT_UPDATED
, wxCommandEvent
)
107 wxEVENT_PROPERTY( TextEnter
, wxEVT_COMMAND_TEXT_ENTER
, wxCommandEvent
)
109 wxPROPERTY( Font
, wxFont
, SetFont
, GetFont
, wxEMPTY_PARAMETER_VALUE
, \
110 0 /*flags*/, wxT("Helpstring"), wxT("group") )
111 wxPROPERTY( Value
, wxString
, SetValue
, GetValue
, wxString(), \
112 0 /*flags*/, wxT("Helpstring"), wxT("group"))
114 wxPROPERTY_FLAGS( WindowStyle
, wxTextCtrlStyle
, long, SetWindowStyleFlag
, \
115 GetWindowStyleFlag
, wxEMPTY_PARAMETER_VALUE
, 0 /*flags*/, \
116 wxT("Helpstring"), wxT("group")) // style
117 wxEND_PROPERTIES_TABLE()
119 wxEMPTY_HANDLERS_TABLE(wxTextCtrl
)
121 wxCONSTRUCTOR_6( wxTextCtrl
, wxWindow
*, Parent
, wxWindowID
, Id
, \
122 wxString
, Value
, wxPoint
, Position
, wxSize
, Size
, \
126 IMPLEMENT_DYNAMIC_CLASS(wxTextUrlEvent
, wxCommandEvent
)
128 wxDEFINE_EVENT( wxEVT_COMMAND_TEXT_UPDATED
, wxCommandEvent
);
129 wxDEFINE_EVENT( wxEVT_COMMAND_TEXT_ENTER
, wxCommandEvent
);
130 wxDEFINE_EVENT( wxEVT_COMMAND_TEXT_URL
, wxTextUrlEvent
);
131 wxDEFINE_EVENT( wxEVT_COMMAND_TEXT_MAXLEN
, wxCommandEvent
);
133 IMPLEMENT_ABSTRACT_CLASS(wxTextCtrlBase
, wxControl
)
135 // ============================================================================
136 // wxTextAttr implementation
137 // ============================================================================
139 wxTextAttr::wxTextAttr(const wxColour
& colText
,
140 const wxColour
& colBack
,
142 wxTextAttrAlignment alignment
): m_textAlignment(alignment
), m_colText(colText
), m_colBack(colBack
)
146 if (m_colText
.IsOk()) m_flags
|= wxTEXT_ATTR_TEXT_COLOUR
;
147 if (m_colBack
.IsOk()) m_flags
|= wxTEXT_ATTR_BACKGROUND_COLOUR
;
148 if (alignment
!= wxTEXT_ALIGNMENT_DEFAULT
)
149 m_flags
|= wxTEXT_ATTR_ALIGNMENT
;
151 GetFontAttributes(font
);
155 void wxTextAttr::Init()
157 m_textAlignment
= wxTEXT_ALIGNMENT_DEFAULT
;
164 m_fontStyle
= wxFONTSTYLE_NORMAL
;
165 m_fontWeight
= wxFONTWEIGHT_NORMAL
;
166 m_fontUnderlined
= false;
167 m_fontStrikethrough
= false;
168 m_fontEncoding
= wxFONTENCODING_DEFAULT
;
169 m_fontFamily
= wxFONTFAMILY_DEFAULT
;
171 m_paragraphSpacingAfter
= 0;
172 m_paragraphSpacingBefore
= 0;
174 m_bulletStyle
= wxTEXT_ATTR_BULLET_STYLE_NONE
;
175 m_textEffects
= wxTEXT_ATTR_EFFECT_NONE
;
176 m_textEffectFlags
= wxTEXT_ATTR_EFFECT_NONE
;
182 void wxTextAttr::Copy(const wxTextAttr
& attr
)
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
;
193 m_fontSize
= attr
.m_fontSize
;
194 m_fontStyle
= attr
.m_fontStyle
;
195 m_fontWeight
= attr
.m_fontWeight
;
196 m_fontUnderlined
= attr
.m_fontUnderlined
;
197 m_fontStrikethrough
= attr
.m_fontStrikethrough
;
198 m_fontFaceName
= attr
.m_fontFaceName
;
199 m_fontEncoding
= attr
.m_fontEncoding
;
200 m_fontFamily
= attr
.m_fontFamily
;
201 m_textEffects
= attr
.m_textEffects
;
202 m_textEffectFlags
= attr
.m_textEffectFlags
;
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
;
217 m_urlTarget
= attr
.m_urlTarget
;
221 void wxTextAttr::operator= (const wxTextAttr
& attr
)
227 bool wxTextAttr::operator== (const wxTextAttr
& attr
) const
229 return GetFlags() == attr
.GetFlags() &&
231 GetTextColour() == attr
.GetTextColour() &&
232 GetBackgroundColour() == attr
.GetBackgroundColour() &&
234 GetAlignment() == attr
.GetAlignment() &&
235 GetLeftIndent() == attr
.GetLeftIndent() &&
236 GetLeftSubIndent() == attr
.GetLeftSubIndent() &&
237 GetRightIndent() == attr
.GetRightIndent() &&
238 TabsEq(GetTabs(), attr
.GetTabs()) &&
240 GetParagraphSpacingAfter() == attr
.GetParagraphSpacingAfter() &&
241 GetParagraphSpacingBefore() == attr
.GetParagraphSpacingBefore() &&
242 GetLineSpacing() == attr
.GetLineSpacing() &&
243 GetCharacterStyleName() == attr
.GetCharacterStyleName() &&
244 GetParagraphStyleName() == attr
.GetParagraphStyleName() &&
245 GetListStyleName() == attr
.GetListStyleName() &&
247 GetBulletStyle() == attr
.GetBulletStyle() &&
248 GetBulletText() == attr
.GetBulletText() &&
249 GetBulletNumber() == attr
.GetBulletNumber() &&
250 GetBulletFont() == attr
.GetBulletFont() &&
251 GetBulletName() == attr
.GetBulletName() &&
253 GetTextEffects() == attr
.GetTextEffects() &&
254 GetTextEffectFlags() == attr
.GetTextEffectFlags() &&
256 GetOutlineLevel() == attr
.GetOutlineLevel() &&
258 GetFontSize() == attr
.GetFontSize() &&
259 GetFontStyle() == attr
.GetFontStyle() &&
260 GetFontWeight() == attr
.GetFontWeight() &&
261 GetFontUnderlined() == attr
.GetFontUnderlined() &&
262 GetFontFaceName() == attr
.GetFontFaceName() &&
263 GetFontEncoding() == attr
.GetFontEncoding() &&
264 GetFontFamily() == attr
.GetFontFamily() &&
266 GetURL() == attr
.GetURL();
269 // Partial equality test. Only returns false if an attribute doesn't match.
270 bool wxTextAttr::EqPartial(const wxTextAttr
& attr
) const
272 int flags
= attr
.GetFlags();
274 if ((flags
& wxTEXT_ATTR_TEXT_COLOUR
) && GetTextColour() != attr
.GetTextColour())
277 if ((flags
& wxTEXT_ATTR_BACKGROUND_COLOUR
) && GetBackgroundColour() != attr
.GetBackgroundColour())
280 if ((flags
& wxTEXT_ATTR_FONT_FACE
) &&
281 GetFontFaceName() != attr
.GetFontFaceName())
284 if ((flags
& wxTEXT_ATTR_FONT_SIZE
) &&
285 GetFontSize() != attr
.GetFontSize())
288 if ((flags
& wxTEXT_ATTR_FONT_WEIGHT
) &&
289 GetFontWeight() != attr
.GetFontWeight())
292 if ((flags
& wxTEXT_ATTR_FONT_ITALIC
) &&
293 GetFontStyle() != attr
.GetFontStyle())
296 if ((flags
& wxTEXT_ATTR_FONT_UNDERLINE
) &&
297 GetFontUnderlined() != attr
.GetFontUnderlined())
300 if ((flags
& wxTEXT_ATTR_FONT_ENCODING
) &&
301 GetFontEncoding() != attr
.GetFontEncoding())
304 if ((flags
& wxTEXT_ATTR_FONT_FAMILY
) &&
305 GetFontFamily() != attr
.GetFontFamily())
308 if ((flags
& wxTEXT_ATTR_URL
) && GetURL() != attr
.GetURL())
311 if ((flags
& wxTEXT_ATTR_ALIGNMENT
) && GetAlignment() != attr
.GetAlignment())
314 if ((flags
& wxTEXT_ATTR_LEFT_INDENT
) &&
315 ((GetLeftIndent() != attr
.GetLeftIndent()) || (GetLeftSubIndent() != attr
.GetLeftSubIndent())))
318 if ((flags
& wxTEXT_ATTR_RIGHT_INDENT
) &&
319 (GetRightIndent() != attr
.GetRightIndent()))
322 if ((flags
& wxTEXT_ATTR_PARA_SPACING_AFTER
) &&
323 (GetParagraphSpacingAfter() != attr
.GetParagraphSpacingAfter()))
326 if ((flags
& wxTEXT_ATTR_PARA_SPACING_BEFORE
) &&
327 (GetParagraphSpacingBefore() != attr
.GetParagraphSpacingBefore()))
330 if ((flags
& wxTEXT_ATTR_LINE_SPACING
) &&
331 (GetLineSpacing() != attr
.GetLineSpacing()))
334 if ((flags
& wxTEXT_ATTR_CHARACTER_STYLE_NAME
) &&
335 (GetCharacterStyleName() != attr
.GetCharacterStyleName()))
338 if ((flags
& wxTEXT_ATTR_PARAGRAPH_STYLE_NAME
) &&
339 (GetParagraphStyleName() != attr
.GetParagraphStyleName()))
342 if ((flags
& wxTEXT_ATTR_LIST_STYLE_NAME
) &&
343 (GetListStyleName() != attr
.GetListStyleName()))
346 if ((flags
& wxTEXT_ATTR_BULLET_STYLE
) &&
347 (GetBulletStyle() != attr
.GetBulletStyle()))
350 if ((flags
& wxTEXT_ATTR_BULLET_NUMBER
) &&
351 (GetBulletNumber() != attr
.GetBulletNumber()))
354 if ((flags
& wxTEXT_ATTR_BULLET_TEXT
) &&
355 (GetBulletText() != attr
.GetBulletText()) &&
356 (GetBulletFont() != attr
.GetBulletFont()))
359 if ((flags
& wxTEXT_ATTR_BULLET_NAME
) &&
360 (GetBulletName() != attr
.GetBulletName()))
363 if ((flags
& wxTEXT_ATTR_TABS
) &&
364 !TabsEq(GetTabs(), attr
.GetTabs()))
367 if ((flags
& wxTEXT_ATTR_PAGE_BREAK
) &&
368 (HasPageBreak() != attr
.HasPageBreak()))
371 if (flags
& wxTEXT_ATTR_EFFECTS
)
373 if (HasTextEffects() != attr
.HasTextEffects())
375 if (!BitlistsEqPartial(GetTextEffects(), attr
.GetTextEffects(), attr
.GetTextEffectFlags()))
379 if ((flags
& wxTEXT_ATTR_OUTLINE_LEVEL
) &&
380 (GetOutlineLevel() != attr
.GetOutlineLevel()))
386 // Create font from font attributes.
387 wxFont
wxTextAttr::GetFont() const
394 fontSize
= GetFontSize();
396 int fontStyle
= wxNORMAL
;
398 fontStyle
= GetFontStyle();
400 int fontWeight
= wxNORMAL
;
402 fontWeight
= GetFontWeight();
404 bool underlined
= false;
405 if (HasFontUnderlined())
406 underlined
= GetFontUnderlined();
408 bool strikethrough
= false;
409 if ( HasFontStrikethrough() )
410 strikethrough
= GetFontStrikethrough();
412 wxString fontFaceName
;
413 if (HasFontFaceName())
414 fontFaceName
= GetFontFaceName();
416 wxFontEncoding encoding
= wxFONTENCODING_DEFAULT
;
417 if (HasFontEncoding())
418 encoding
= GetFontEncoding();
420 wxFontFamily fontFamily
= wxFONTFAMILY_DEFAULT
;
422 fontFamily
= GetFontFamily();
424 wxFont
font(fontSize
, fontFamily
, fontStyle
, fontWeight
, underlined
, fontFaceName
, encoding
);
426 font
.SetStrikethrough( true );
430 // Get attributes from font.
431 bool wxTextAttr::GetFontAttributes(const wxFont
& font
, int flags
)
436 if (flags
& wxTEXT_ATTR_FONT_SIZE
)
437 m_fontSize
= font
.GetPointSize();
439 if (flags
& wxTEXT_ATTR_FONT_ITALIC
)
440 m_fontStyle
= font
.GetStyle();
442 if (flags
& wxTEXT_ATTR_FONT_WEIGHT
)
443 m_fontWeight
= font
.GetWeight();
445 if (flags
& wxTEXT_ATTR_FONT_UNDERLINE
)
446 m_fontUnderlined
= font
.GetUnderlined();
448 if (flags
& wxTEXT_ATTR_FONT_STRIKETHROUGH
)
449 m_fontStrikethrough
= font
.GetStrikethrough();
451 if (flags
& wxTEXT_ATTR_FONT_FACE
)
452 m_fontFaceName
= font
.GetFaceName();
454 if (flags
& wxTEXT_ATTR_FONT_ENCODING
)
455 m_fontEncoding
= font
.GetEncoding();
457 if (flags
& wxTEXT_ATTR_FONT_FAMILY
)
459 // wxFont might not know its family, avoid setting m_fontFamily to an
460 // invalid value and rather pretend that we don't have any font family
461 // information at all in this case
462 const wxFontFamily fontFamily
= font
.GetFamily();
463 if ( fontFamily
== wxFONTFAMILY_UNKNOWN
)
464 flags
&= ~wxTEXT_ATTR_FONT_FAMILY
;
466 m_fontFamily
= fontFamily
;
474 // Resets bits in destination so new attributes aren't merged with mutually exclusive ones
475 static bool wxResetIncompatibleBits(const int mask
, const int srcFlags
, int& destFlags
, int& destBits
)
477 if ((srcFlags
& mask
) && (destFlags
& mask
))
486 bool wxTextAttr::Apply(const wxTextAttr
& style
, const wxTextAttr
* compareWith
)
488 wxTextAttr
& destStyle
= (*this);
490 if (style
.HasFontWeight())
492 if (!(compareWith
&& compareWith
->HasFontWeight() && compareWith
->GetFontWeight() == style
.GetFontWeight()))
493 destStyle
.SetFontWeight(style
.GetFontWeight());
496 if (style
.HasFontSize())
498 if (!(compareWith
&& compareWith
->HasFontSize() && compareWith
->GetFontSize() == style
.GetFontSize()))
499 destStyle
.SetFontSize(style
.GetFontSize());
502 if (style
.HasFontItalic())
504 if (!(compareWith
&& compareWith
->HasFontItalic() && compareWith
->GetFontStyle() == style
.GetFontStyle()))
505 destStyle
.SetFontStyle(style
.GetFontStyle());
508 if (style
.HasFontUnderlined())
510 if (!(compareWith
&& compareWith
->HasFontUnderlined() && compareWith
->GetFontUnderlined() == style
.GetFontUnderlined()))
511 destStyle
.SetFontUnderlined(style
.GetFontUnderlined());
514 if (style
.HasFontStrikethrough())
516 if (!(compareWith
&& compareWith
->HasFontStrikethrough() && compareWith
->GetFontStrikethrough() == style
.GetFontStrikethrough()))
517 destStyle
.SetFontStrikethrough(style
.GetFontStrikethrough());
520 if (style
.HasFontFaceName())
522 if (!(compareWith
&& compareWith
->HasFontFaceName() && compareWith
->GetFontFaceName() == style
.GetFontFaceName()))
523 destStyle
.SetFontFaceName(style
.GetFontFaceName());
526 if (style
.HasFontEncoding())
528 if (!(compareWith
&& compareWith
->HasFontEncoding() && compareWith
->GetFontEncoding() == style
.GetFontEncoding()))
529 destStyle
.SetFontEncoding(style
.GetFontEncoding());
532 if (style
.HasFontFamily())
534 if (!(compareWith
&& compareWith
->HasFontFamily() && compareWith
->GetFontFamily() == style
.GetFontFamily()))
535 destStyle
.SetFontFamily(style
.GetFontFamily());
538 if (style
.GetTextColour().IsOk() && style
.HasTextColour())
540 if (!(compareWith
&& compareWith
->HasTextColour() && compareWith
->GetTextColour() == style
.GetTextColour()))
541 destStyle
.SetTextColour(style
.GetTextColour());
544 if (style
.GetBackgroundColour().IsOk() && style
.HasBackgroundColour())
546 if (!(compareWith
&& compareWith
->HasBackgroundColour() && compareWith
->GetBackgroundColour() == style
.GetBackgroundColour()))
547 destStyle
.SetBackgroundColour(style
.GetBackgroundColour());
550 if (style
.HasAlignment())
552 if (!(compareWith
&& compareWith
->HasAlignment() && compareWith
->GetAlignment() == style
.GetAlignment()))
553 destStyle
.SetAlignment(style
.GetAlignment());
558 if (!(compareWith
&& compareWith
->HasTabs() && TabsEq(compareWith
->GetTabs(), style
.GetTabs())))
559 destStyle
.SetTabs(style
.GetTabs());
562 if (style
.HasLeftIndent())
564 if (!(compareWith
&& compareWith
->HasLeftIndent() && compareWith
->GetLeftIndent() == style
.GetLeftIndent()
565 && compareWith
->GetLeftSubIndent() == style
.GetLeftSubIndent()))
566 destStyle
.SetLeftIndent(style
.GetLeftIndent(), style
.GetLeftSubIndent());
569 if (style
.HasRightIndent())
571 if (!(compareWith
&& compareWith
->HasRightIndent() && compareWith
->GetRightIndent() == style
.GetRightIndent()))
572 destStyle
.SetRightIndent(style
.GetRightIndent());
575 if (style
.HasParagraphSpacingAfter())
577 if (!(compareWith
&& compareWith
->HasParagraphSpacingAfter() && compareWith
->GetParagraphSpacingAfter() == style
.GetParagraphSpacingAfter()))
578 destStyle
.SetParagraphSpacingAfter(style
.GetParagraphSpacingAfter());
581 if (style
.HasParagraphSpacingBefore())
583 if (!(compareWith
&& compareWith
->HasParagraphSpacingBefore() && compareWith
->GetParagraphSpacingBefore() == style
.GetParagraphSpacingBefore()))
584 destStyle
.SetParagraphSpacingBefore(style
.GetParagraphSpacingBefore());
587 if (style
.HasLineSpacing())
589 if (!(compareWith
&& compareWith
->HasLineSpacing() && compareWith
->GetLineSpacing() == style
.GetLineSpacing()))
590 destStyle
.SetLineSpacing(style
.GetLineSpacing());
593 if (style
.HasCharacterStyleName())
595 if (!(compareWith
&& compareWith
->HasCharacterStyleName() && compareWith
->GetCharacterStyleName() == style
.GetCharacterStyleName()))
596 destStyle
.SetCharacterStyleName(style
.GetCharacterStyleName());
599 if (style
.HasParagraphStyleName())
601 if (!(compareWith
&& compareWith
->HasParagraphStyleName() && compareWith
->GetParagraphStyleName() == style
.GetParagraphStyleName()))
602 destStyle
.SetParagraphStyleName(style
.GetParagraphStyleName());
605 if (style
.HasListStyleName())
607 if (!(compareWith
&& compareWith
->HasListStyleName() && compareWith
->GetListStyleName() == style
.GetListStyleName()))
608 destStyle
.SetListStyleName(style
.GetListStyleName());
611 if (style
.HasBulletStyle())
613 if (!(compareWith
&& compareWith
->HasBulletStyle() && compareWith
->GetBulletStyle() == style
.GetBulletStyle()))
614 destStyle
.SetBulletStyle(style
.GetBulletStyle());
617 if (style
.HasBulletText())
619 if (!(compareWith
&& compareWith
->HasBulletText() && compareWith
->GetBulletText() == style
.GetBulletText()))
621 destStyle
.SetBulletText(style
.GetBulletText());
622 destStyle
.SetBulletFont(style
.GetBulletFont());
626 if (style
.HasBulletNumber())
628 if (!(compareWith
&& compareWith
->HasBulletNumber() && compareWith
->GetBulletNumber() == style
.GetBulletNumber()))
629 destStyle
.SetBulletNumber(style
.GetBulletNumber());
632 if (style
.HasBulletName())
634 if (!(compareWith
&& compareWith
->HasBulletName() && compareWith
->GetBulletName() == style
.GetBulletName()))
635 destStyle
.SetBulletName(style
.GetBulletName());
640 if (!(compareWith
&& compareWith
->HasURL() && compareWith
->GetURL() == style
.GetURL()))
641 destStyle
.SetURL(style
.GetURL());
644 if (style
.HasPageBreak())
646 if (!(compareWith
&& compareWith
->HasPageBreak()))
647 destStyle
.SetPageBreak();
650 if (style
.HasTextEffects())
652 if (!(compareWith
&& compareWith
->HasTextEffects() && compareWith
->GetTextEffects() == style
.GetTextEffects()))
654 int destBits
= destStyle
.GetTextEffects();
655 int destFlags
= destStyle
.GetTextEffectFlags();
657 int srcBits
= style
.GetTextEffects();
658 int srcFlags
= style
.GetTextEffectFlags();
660 // Reset incompatible bits in the destination
661 wxResetIncompatibleBits((wxTEXT_ATTR_EFFECT_SUPERSCRIPT
|wxTEXT_ATTR_EFFECT_SUBSCRIPT
), srcFlags
, destFlags
, destBits
);
662 wxResetIncompatibleBits((wxTEXT_ATTR_EFFECT_CAPITALS
|wxTEXT_ATTR_EFFECT_SMALL_CAPITALS
), srcFlags
, destFlags
, destBits
);
663 wxResetIncompatibleBits((wxTEXT_ATTR_EFFECT_STRIKETHROUGH
|wxTEXT_ATTR_EFFECT_DOUBLE_STRIKETHROUGH
), srcFlags
, destFlags
, destBits
);
665 CombineBitlists(destBits
, srcBits
, destFlags
, srcFlags
);
667 destStyle
.SetTextEffects(destBits
);
668 destStyle
.SetTextEffectFlags(destFlags
);
672 if (style
.HasOutlineLevel())
674 if (!(compareWith
&& compareWith
->HasOutlineLevel() && compareWith
->GetOutlineLevel() == style
.GetOutlineLevel()))
675 destStyle
.SetOutlineLevel(style
.GetOutlineLevel());
682 wxTextAttr
wxTextAttr::Combine(const wxTextAttr
& attr
,
683 const wxTextAttr
& attrDef
,
684 const wxTextCtrlBase
*text
)
688 font
= attr
.GetFont();
692 if (attrDef
.HasFont())
693 font
= attrDef
.GetFont();
695 if ( text
&& !font
.IsOk() )
696 font
= text
->GetFont();
699 wxColour colFg
= attr
.GetTextColour();
702 colFg
= attrDef
.GetTextColour();
704 if ( text
&& !colFg
.IsOk() )
705 colFg
= text
->GetForegroundColour();
708 wxColour colBg
= attr
.GetBackgroundColour();
711 colBg
= attrDef
.GetBackgroundColour();
713 if ( text
&& !colBg
.IsOk() )
714 colBg
= text
->GetBackgroundColour();
717 wxTextAttr
newAttr(colFg
, colBg
, font
);
719 if (attr
.HasAlignment())
720 newAttr
.SetAlignment(attr
.GetAlignment());
721 else if (attrDef
.HasAlignment())
722 newAttr
.SetAlignment(attrDef
.GetAlignment());
725 newAttr
.SetTabs(attr
.GetTabs());
726 else if (attrDef
.HasTabs())
727 newAttr
.SetTabs(attrDef
.GetTabs());
729 if (attr
.HasLeftIndent())
730 newAttr
.SetLeftIndent(attr
.GetLeftIndent(), attr
.GetLeftSubIndent());
731 else if (attrDef
.HasLeftIndent())
732 newAttr
.SetLeftIndent(attrDef
.GetLeftIndent(), attr
.GetLeftSubIndent());
734 if (attr
.HasRightIndent())
735 newAttr
.SetRightIndent(attr
.GetRightIndent());
736 else if (attrDef
.HasRightIndent())
737 newAttr
.SetRightIndent(attrDef
.GetRightIndent());
743 bool wxTextAttr::TabsEq(const wxArrayInt
& tabs1
, const wxArrayInt
& tabs2
)
745 if (tabs1
.GetCount() != tabs2
.GetCount())
749 for (i
= 0; i
< tabs1
.GetCount(); i
++)
751 if (tabs1
[i
] != tabs2
[i
])
758 bool wxTextAttr::RemoveStyle(wxTextAttr
& destStyle
, const wxTextAttr
& style
)
760 int flags
= style
.GetFlags();
761 int destFlags
= destStyle
.GetFlags();
763 destStyle
.SetFlags(destFlags
& ~flags
);
768 /// Combine two bitlists, specifying the bits of interest with separate flags.
769 bool wxTextAttr::CombineBitlists(int& valueA
, int valueB
, int& flagsA
, int flagsB
)
771 // We want to apply B's bits to A, taking into account each's flags which indicate which bits
772 // are to be taken into account. A zero in B's bits should reset that bit in A but only if B's flags
775 // First, reset the 0 bits from B. We make a mask so we're only dealing with B's zero
776 // bits at this point, ignoring any 1 bits in B or 0 bits in B that are not relevant.
777 int valueA2
= ~(~valueB
& flagsB
) & valueA
;
779 // Now combine the 1 bits.
780 int valueA3
= (valueB
& flagsB
) | valueA2
;
783 flagsA
= (flagsA
| flagsB
);
788 /// Compare two bitlists
789 bool wxTextAttr::BitlistsEqPartial(int valueA
, int valueB
, int flags
)
791 int relevantBitsA
= valueA
& flags
;
792 int relevantBitsB
= valueB
& flags
;
793 return relevantBitsA
== relevantBitsB
;
796 /// Split into paragraph and character styles
797 bool wxTextAttr::SplitParaCharStyles(const wxTextAttr
& style
, wxTextAttr
& parStyle
, wxTextAttr
& charStyle
)
799 wxTextAttr
defaultCharStyle1(style
);
800 wxTextAttr
defaultParaStyle1(style
);
801 defaultCharStyle1
.SetFlags(defaultCharStyle1
.GetFlags()&wxTEXT_ATTR_CHARACTER
);
802 defaultParaStyle1
.SetFlags(defaultParaStyle1
.GetFlags()&wxTEXT_ATTR_PARAGRAPH
);
804 charStyle
.Apply(defaultCharStyle1
);
805 parStyle
.Apply(defaultParaStyle1
);
810 // apply styling to text range
811 bool wxTextCtrlBase::SetStyle(long WXUNUSED(start
), long WXUNUSED(end
),
812 const wxTextAttr
& WXUNUSED(style
))
814 // to be implemented in derived classes
818 // get the styling at the given position
819 bool wxTextCtrlBase::GetStyle(long WXUNUSED(position
), wxTextAttr
& WXUNUSED(style
))
821 // to be implemented in derived classes
825 // change default text attributes
826 bool wxTextCtrlBase::SetDefaultStyle(const wxTextAttr
& style
)
828 // keep the old attributes if the new style doesn't specify them unless the
829 // new style is empty - then reset m_defaultStyle (as there is no other way
831 if ( style
.IsDefault() )
832 m_defaultStyle
= style
;
834 m_defaultStyle
= wxTextAttr::Combine(style
, m_defaultStyle
, this);
839 // ----------------------------------------------------------------------------
841 // ----------------------------------------------------------------------------
843 bool wxTextAreaBase::DoLoadFile(const wxString
& filename
, int WXUNUSED(fileType
))
846 wxFFile
file(filename
);
847 if ( file
.IsOpened() )
850 if ( file
.ReadAll(&text
) )
857 #endif // wxUSE_FFILE
862 bool wxTextCtrlBase::DoLoadFile(const wxString
& filename
, int fileType
)
864 if ( wxTextAreaBase::DoLoadFile(filename
, fileType
) )
867 m_filename
= filename
;
870 wxLogError(_("File couldn't be loaded."));
874 bool wxTextAreaBase::DoSaveFile(const wxString
& filename
, int WXUNUSED(fileType
))
877 wxFFile
file(filename
, wxT("w"));
878 return file
.IsOpened() && file
.Write(GetValue(), *wxConvCurrent
);
881 #endif // wxUSE_FFILE
884 bool wxTextAreaBase::SaveFile(const wxString
& filename
, int fileType
)
886 wxString filenameToUse
= filename
.empty() ? m_filename
: filename
;
887 if ( filenameToUse
.empty() )
889 // what kind of message to give? is it an error or a program bug?
890 wxLogDebug(wxT("Can't save textctrl to file without filename."));
895 return DoSaveFile(filenameToUse
, fileType
);
898 bool wxTextCtrlBase::DoSaveFile(const wxString
& filename
, int fileType
)
900 if ( wxTextAreaBase::DoSaveFile(filename
, fileType
) )
902 // if it worked, save for future calls
903 m_filename
= filename
;
905 // it's not modified any longer
913 // ----------------------------------------------------------------------------
914 // stream-like insertion operator
915 // ----------------------------------------------------------------------------
917 wxTextCtrl
& wxTextCtrlBase::operator<<(const wxString
& s
)
920 return *TEXTCTRL(this);
923 wxTextCtrl
& wxTextCtrlBase::operator<<(double d
)
925 return *this << wxString::Format("%.2f", d
);
928 wxTextCtrl
& wxTextCtrlBase::operator<<(int i
)
930 return *this << wxString::Format("%d", i
);
933 wxTextCtrl
& wxTextCtrlBase::operator<<(long l
)
935 return *this << wxString::Format("%ld", l
);
938 // ----------------------------------------------------------------------------
939 // streambuf methods implementation
940 // ----------------------------------------------------------------------------
942 #if wxHAS_TEXT_WINDOW_STREAM
944 int wxTextCtrlBase::overflow(int c
)
946 AppendText((wxChar
)c
);
948 // return something different from EOF
952 #endif // wxHAS_TEXT_WINDOW_STREAM
954 // ----------------------------------------------------------------------------
955 // emulating key presses
956 // ----------------------------------------------------------------------------
958 bool wxTextCtrlBase::EmulateKeyPress(const wxKeyEvent
& event
)
960 bool handled
= false;
961 // we have a native implementation for Win32 and so don't need this one
964 int keycode
= event
.GetKeyCode();
967 GetSelection(&from
,&to
);
968 long insert
= GetInsertionPoint();
969 long last
= GetLastPosition();
971 // catch arrow left and right
976 if ( event
.ShiftDown() )
977 SetSelection( (from
> 0 ? from
- 1 : 0) , to
);
982 else if ( insert
> 0 )
984 SetInsertionPoint( insert
);
989 if ( event
.ShiftDown() )
990 SetSelection( from
, (to
< last
? to
+ 1 : last
) );
995 else if ( insert
< last
)
997 SetInsertionPoint( insert
);
1011 ch
= (wxChar
)(wxT('0') + keycode
- WXK_NUMPAD0
);
1015 case WXK_NUMPAD_MULTIPLY
:
1020 case WXK_NUMPAD_ADD
:
1025 case WXK_NUMPAD_SUBTRACT
:
1030 case WXK_NUMPAD_DECIMAL
:
1035 case WXK_NUMPAD_DIVIDE
:
1040 case WXK_NUMPAD_DELETE
:
1041 // delete the character at cursor
1043 const long pos
= GetInsertionPoint();
1044 if ( pos
< GetLastPosition() )
1045 Remove(pos
, pos
+ 1);
1051 // delete the character before the cursor
1053 const long pos
= GetInsertionPoint();
1055 Remove(pos
- 1, pos
);
1062 if ( event
.GetUnicodeKey() )
1064 ch
= event
.GetUnicodeKey();
1068 if ( keycode
< 256 && keycode
>= 0 && wxIsprint(keycode
) )
1070 // FIXME this is not going to work for non letters...
1071 if ( !event
.ShiftDown() )
1073 keycode
= wxTolower(keycode
);
1076 ch
= (wxChar
)keycode
;
1092 #endif // !__WIN32__/__WIN32__
1097 // do the window-specific processing after processing the update event
1098 void wxTextCtrlBase::DoUpdateWindowUI(wxUpdateUIEvent
& event
)
1100 // call inherited, but skip the wxControl's version, and call directly the
1101 // wxWindow's one instead, because the only reason why we are overriding this
1102 // function is that we want to use SetValue() instead of wxControl::SetLabel()
1103 wxWindowBase::DoUpdateWindowUI(event
);
1106 if ( event
.GetSetText() )
1108 if ( event
.GetText() != GetValue() )
1109 SetValue(event
.GetText());
1113 // ----------------------------------------------------------------------------
1115 // ----------------------------------------------------------------------------
1117 wxTextCtrlHitTestResult
1118 wxTextAreaBase::HitTest(const wxPoint
& pt
, wxTextCoord
*x
, wxTextCoord
*y
) const
1120 // implement in terms of the other overload as the native ports typically
1121 // can get the position and not (x, y) pair directly (although wxUniv
1122 // directly gets x and y -- and so overrides this method as well)
1124 wxTextCtrlHitTestResult rc
= HitTest(pt
, &pos
);
1126 if ( rc
!= wxTE_HT_UNKNOWN
)
1128 PositionToXY(pos
, x
, y
);
1134 wxTextCtrlHitTestResult
1135 wxTextAreaBase::HitTest(const wxPoint
& WXUNUSED(pt
), long * WXUNUSED(pos
)) const
1138 return wxTE_HT_UNKNOWN
;
1141 wxPoint
wxTextAreaBase::PositionToCoords(long pos
) const
1143 wxCHECK_MSG( IsValidPosition(pos
), wxDefaultPosition
,
1144 wxS("Position argument out of range.") );
1146 return DoPositionToCoords(pos
);
1149 wxPoint
wxTextAreaBase::DoPositionToCoords(long WXUNUSED(pos
)) const
1151 return wxDefaultPosition
;
1154 #else // !wxUSE_TEXTCTRL
1156 // define this one even if !wxUSE_TEXTCTRL because it is also used by other
1157 // controls (wxComboBox and wxSpinCtrl)
1159 wxDEFINE_EVENT( wxEVT_COMMAND_TEXT_UPDATED
, wxCommandEvent
);
1161 #endif // wxUSE_TEXTCTRL/!wxUSE_TEXTCTRL