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_fontEncoding
= wxFONTENCODING_DEFAULT
;
168 m_fontFamily
= wxFONTFAMILY_DEFAULT
;
170 m_paragraphSpacingAfter
= 0;
171 m_paragraphSpacingBefore
= 0;
173 m_bulletStyle
= wxTEXT_ATTR_BULLET_STYLE_NONE
;
174 m_textEffects
= wxTEXT_ATTR_EFFECT_NONE
;
175 m_textEffectFlags
= wxTEXT_ATTR_EFFECT_NONE
;
181 void wxTextAttr::Copy(const wxTextAttr
& attr
)
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
;
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_fontFaceName
= attr
.m_fontFaceName
;
197 m_fontEncoding
= attr
.m_fontEncoding
;
198 m_fontFamily
= attr
.m_fontFamily
;
199 m_textEffects
= attr
.m_textEffects
;
200 m_textEffectFlags
= attr
.m_textEffectFlags
;
202 m_paragraphSpacingAfter
= attr
.m_paragraphSpacingAfter
;
203 m_paragraphSpacingBefore
= attr
.m_paragraphSpacingBefore
;
204 m_lineSpacing
= attr
.m_lineSpacing
;
205 m_characterStyleName
= attr
.m_characterStyleName
;
206 m_paragraphStyleName
= attr
.m_paragraphStyleName
;
207 m_listStyleName
= attr
.m_listStyleName
;
208 m_bulletStyle
= attr
.m_bulletStyle
;
209 m_bulletNumber
= attr
.m_bulletNumber
;
210 m_bulletText
= attr
.m_bulletText
;
211 m_bulletFont
= attr
.m_bulletFont
;
212 m_bulletName
= attr
.m_bulletName
;
213 m_outlineLevel
= attr
.m_outlineLevel
;
215 m_urlTarget
= attr
.m_urlTarget
;
219 void wxTextAttr::operator= (const wxTextAttr
& attr
)
225 bool wxTextAttr::operator== (const wxTextAttr
& attr
) const
227 return GetFlags() == attr
.GetFlags() &&
229 GetTextColour() == attr
.GetTextColour() &&
230 GetBackgroundColour() == attr
.GetBackgroundColour() &&
232 GetAlignment() == attr
.GetAlignment() &&
233 GetLeftIndent() == attr
.GetLeftIndent() &&
234 GetLeftSubIndent() == attr
.GetLeftSubIndent() &&
235 GetRightIndent() == attr
.GetRightIndent() &&
236 TabsEq(GetTabs(), attr
.GetTabs()) &&
238 GetParagraphSpacingAfter() == attr
.GetParagraphSpacingAfter() &&
239 GetParagraphSpacingBefore() == attr
.GetParagraphSpacingBefore() &&
240 GetLineSpacing() == attr
.GetLineSpacing() &&
241 GetCharacterStyleName() == attr
.GetCharacterStyleName() &&
242 GetParagraphStyleName() == attr
.GetParagraphStyleName() &&
243 GetListStyleName() == attr
.GetListStyleName() &&
245 GetBulletStyle() == attr
.GetBulletStyle() &&
246 GetBulletText() == attr
.GetBulletText() &&
247 GetBulletNumber() == attr
.GetBulletNumber() &&
248 GetBulletFont() == attr
.GetBulletFont() &&
249 GetBulletName() == attr
.GetBulletName() &&
251 GetTextEffects() == attr
.GetTextEffects() &&
252 GetTextEffectFlags() == attr
.GetTextEffectFlags() &&
254 GetOutlineLevel() == attr
.GetOutlineLevel() &&
256 GetFontSize() == attr
.GetFontSize() &&
257 GetFontStyle() == attr
.GetFontStyle() &&
258 GetFontWeight() == attr
.GetFontWeight() &&
259 GetFontUnderlined() == attr
.GetFontUnderlined() &&
260 GetFontFaceName() == attr
.GetFontFaceName() &&
261 GetFontEncoding() == attr
.GetFontEncoding() &&
262 GetFontFamily() == attr
.GetFontFamily() &&
264 GetURL() == attr
.GetURL();
267 // Partial equality test. Only returns false if an attribute doesn't match.
268 bool wxTextAttr::EqPartial(const wxTextAttr
& attr
) const
270 int flags
= attr
.GetFlags();
272 if ((flags
& wxTEXT_ATTR_TEXT_COLOUR
) && GetTextColour() != attr
.GetTextColour())
275 if ((flags
& wxTEXT_ATTR_BACKGROUND_COLOUR
) && GetBackgroundColour() != attr
.GetBackgroundColour())
278 if ((flags
& wxTEXT_ATTR_FONT_FACE
) &&
279 GetFontFaceName() != attr
.GetFontFaceName())
282 if ((flags
& wxTEXT_ATTR_FONT_SIZE
) &&
283 GetFontSize() != attr
.GetFontSize())
286 if ((flags
& wxTEXT_ATTR_FONT_WEIGHT
) &&
287 GetFontWeight() != attr
.GetFontWeight())
290 if ((flags
& wxTEXT_ATTR_FONT_ITALIC
) &&
291 GetFontStyle() != attr
.GetFontStyle())
294 if ((flags
& wxTEXT_ATTR_FONT_UNDERLINE
) &&
295 GetFontUnderlined() != attr
.GetFontUnderlined())
298 if ((flags
& wxTEXT_ATTR_FONT_ENCODING
) &&
299 GetFontEncoding() != attr
.GetFontEncoding())
302 if ((flags
& wxTEXT_ATTR_FONT_FAMILY
) &&
303 GetFontFamily() != attr
.GetFontFamily())
306 if ((flags
& wxTEXT_ATTR_URL
) && GetURL() != attr
.GetURL())
309 if ((flags
& wxTEXT_ATTR_ALIGNMENT
) && GetAlignment() != attr
.GetAlignment())
312 if ((flags
& wxTEXT_ATTR_LEFT_INDENT
) &&
313 ((GetLeftIndent() != attr
.GetLeftIndent()) || (GetLeftSubIndent() != attr
.GetLeftSubIndent())))
316 if ((flags
& wxTEXT_ATTR_RIGHT_INDENT
) &&
317 (GetRightIndent() != attr
.GetRightIndent()))
320 if ((flags
& wxTEXT_ATTR_PARA_SPACING_AFTER
) &&
321 (GetParagraphSpacingAfter() != attr
.GetParagraphSpacingAfter()))
324 if ((flags
& wxTEXT_ATTR_PARA_SPACING_BEFORE
) &&
325 (GetParagraphSpacingBefore() != attr
.GetParagraphSpacingBefore()))
328 if ((flags
& wxTEXT_ATTR_LINE_SPACING
) &&
329 (GetLineSpacing() != attr
.GetLineSpacing()))
332 if ((flags
& wxTEXT_ATTR_CHARACTER_STYLE_NAME
) &&
333 (GetCharacterStyleName() != attr
.GetCharacterStyleName()))
336 if ((flags
& wxTEXT_ATTR_PARAGRAPH_STYLE_NAME
) &&
337 (GetParagraphStyleName() != attr
.GetParagraphStyleName()))
340 if ((flags
& wxTEXT_ATTR_LIST_STYLE_NAME
) &&
341 (GetListStyleName() != attr
.GetListStyleName()))
344 if ((flags
& wxTEXT_ATTR_BULLET_STYLE
) &&
345 (GetBulletStyle() != attr
.GetBulletStyle()))
348 if ((flags
& wxTEXT_ATTR_BULLET_NUMBER
) &&
349 (GetBulletNumber() != attr
.GetBulletNumber()))
352 if ((flags
& wxTEXT_ATTR_BULLET_TEXT
) &&
353 (GetBulletText() != attr
.GetBulletText()) &&
354 (GetBulletFont() != attr
.GetBulletFont()))
357 if ((flags
& wxTEXT_ATTR_BULLET_NAME
) &&
358 (GetBulletName() != attr
.GetBulletName()))
361 if ((flags
& wxTEXT_ATTR_TABS
) &&
362 !TabsEq(GetTabs(), attr
.GetTabs()))
365 if ((flags
& wxTEXT_ATTR_PAGE_BREAK
) &&
366 (HasPageBreak() != attr
.HasPageBreak()))
369 if (flags
& wxTEXT_ATTR_EFFECTS
)
371 if (HasTextEffects() != attr
.HasTextEffects())
373 if (!BitlistsEqPartial(GetTextEffects(), attr
.GetTextEffects(), attr
.GetTextEffectFlags()))
377 if ((flags
& wxTEXT_ATTR_OUTLINE_LEVEL
) &&
378 (GetOutlineLevel() != attr
.GetOutlineLevel()))
384 // Create font from font attributes.
385 wxFont
wxTextAttr::GetFont() const
392 fontSize
= GetFontSize();
394 int fontStyle
= wxNORMAL
;
396 fontStyle
= GetFontStyle();
398 int fontWeight
= wxNORMAL
;
400 fontWeight
= GetFontWeight();
402 bool underlined
= false;
403 if (HasFontUnderlined())
404 underlined
= GetFontUnderlined();
406 bool strikethrough
= false;
407 if ( HasFontStrikethrough() )
408 strikethrough
= GetFontStrikethrough();
410 wxString fontFaceName
;
411 if (HasFontFaceName())
412 fontFaceName
= GetFontFaceName();
414 wxFontEncoding encoding
= wxFONTENCODING_DEFAULT
;
415 if (HasFontEncoding())
416 encoding
= GetFontEncoding();
418 wxFontFamily fontFamily
= wxFONTFAMILY_DEFAULT
;
420 fontFamily
= GetFontFamily();
422 wxFont
font(fontSize
, fontFamily
, fontStyle
, fontWeight
, underlined
, fontFaceName
, encoding
);
424 font
.SetStrikethrough( true );
428 // Get attributes from font.
429 bool wxTextAttr::GetFontAttributes(const wxFont
& font
, int flags
)
434 if (flags
& wxTEXT_ATTR_FONT_SIZE
)
435 m_fontSize
= font
.GetPointSize();
437 if (flags
& wxTEXT_ATTR_FONT_ITALIC
)
438 m_fontStyle
= font
.GetStyle();
440 if (flags
& wxTEXT_ATTR_FONT_WEIGHT
)
441 m_fontWeight
= font
.GetWeight();
443 if (flags
& wxTEXT_ATTR_FONT_UNDERLINE
)
444 m_fontUnderlined
= font
.GetUnderlined();
446 if (flags
& wxTEXT_ATTR_FONT_STRIKETHROUGH
)
447 m_fontStrikethrough
= font
.GetStrikethrough();
449 if (flags
& wxTEXT_ATTR_FONT_FACE
)
450 m_fontFaceName
= font
.GetFaceName();
452 if (flags
& wxTEXT_ATTR_FONT_ENCODING
)
453 m_fontEncoding
= font
.GetEncoding();
455 if (flags
& wxTEXT_ATTR_FONT_FAMILY
)
457 // wxFont might not know its family, avoid setting m_fontFamily to an
458 // invalid value and rather pretend that we don't have any font family
459 // information at all in this case
460 const wxFontFamily fontFamily
= font
.GetFamily();
461 if ( fontFamily
== wxFONTFAMILY_UNKNOWN
)
462 flags
&= ~wxTEXT_ATTR_FONT_FAMILY
;
464 m_fontFamily
= fontFamily
;
472 // Resets bits in destination so new attributes aren't merged with mutually exclusive ones
473 static bool wxResetIncompatibleBits(const int mask
, const int srcFlags
, int& destFlags
, int& destBits
)
475 if ((srcFlags
& mask
) && (destFlags
& mask
))
484 bool wxTextAttr::Apply(const wxTextAttr
& style
, const wxTextAttr
* compareWith
)
486 wxTextAttr
& destStyle
= (*this);
488 if (style
.HasFontWeight())
490 if (!(compareWith
&& compareWith
->HasFontWeight() && compareWith
->GetFontWeight() == style
.GetFontWeight()))
491 destStyle
.SetFontWeight(style
.GetFontWeight());
494 if (style
.HasFontSize())
496 if (!(compareWith
&& compareWith
->HasFontSize() && compareWith
->GetFontSize() == style
.GetFontSize()))
497 destStyle
.SetFontSize(style
.GetFontSize());
500 if (style
.HasFontItalic())
502 if (!(compareWith
&& compareWith
->HasFontItalic() && compareWith
->GetFontStyle() == style
.GetFontStyle()))
503 destStyle
.SetFontStyle(style
.GetFontStyle());
506 if (style
.HasFontUnderlined())
508 if (!(compareWith
&& compareWith
->HasFontUnderlined() && compareWith
->GetFontUnderlined() == style
.GetFontUnderlined()))
509 destStyle
.SetFontUnderlined(style
.GetFontUnderlined());
512 if (style
.HasFontStrikethrough())
514 if (!(compareWith
&& compareWith
->HasFontStrikethrough() && compareWith
->GetFontStrikethrough() == style
.GetFontStrikethrough()))
515 destStyle
.SetFontStrikethrough(style
.GetFontStrikethrough());
518 if (style
.HasFontFaceName())
520 if (!(compareWith
&& compareWith
->HasFontFaceName() && compareWith
->GetFontFaceName() == style
.GetFontFaceName()))
521 destStyle
.SetFontFaceName(style
.GetFontFaceName());
524 if (style
.HasFontEncoding())
526 if (!(compareWith
&& compareWith
->HasFontEncoding() && compareWith
->GetFontEncoding() == style
.GetFontEncoding()))
527 destStyle
.SetFontEncoding(style
.GetFontEncoding());
530 if (style
.HasFontFamily())
532 if (!(compareWith
&& compareWith
->HasFontFamily() && compareWith
->GetFontFamily() == style
.GetFontFamily()))
533 destStyle
.SetFontFamily(style
.GetFontFamily());
536 if (style
.GetTextColour().IsOk() && style
.HasTextColour())
538 if (!(compareWith
&& compareWith
->HasTextColour() && compareWith
->GetTextColour() == style
.GetTextColour()))
539 destStyle
.SetTextColour(style
.GetTextColour());
542 if (style
.GetBackgroundColour().IsOk() && style
.HasBackgroundColour())
544 if (!(compareWith
&& compareWith
->HasBackgroundColour() && compareWith
->GetBackgroundColour() == style
.GetBackgroundColour()))
545 destStyle
.SetBackgroundColour(style
.GetBackgroundColour());
548 if (style
.HasAlignment())
550 if (!(compareWith
&& compareWith
->HasAlignment() && compareWith
->GetAlignment() == style
.GetAlignment()))
551 destStyle
.SetAlignment(style
.GetAlignment());
556 if (!(compareWith
&& compareWith
->HasTabs() && TabsEq(compareWith
->GetTabs(), style
.GetTabs())))
557 destStyle
.SetTabs(style
.GetTabs());
560 if (style
.HasLeftIndent())
562 if (!(compareWith
&& compareWith
->HasLeftIndent() && compareWith
->GetLeftIndent() == style
.GetLeftIndent()
563 && compareWith
->GetLeftSubIndent() == style
.GetLeftSubIndent()))
564 destStyle
.SetLeftIndent(style
.GetLeftIndent(), style
.GetLeftSubIndent());
567 if (style
.HasRightIndent())
569 if (!(compareWith
&& compareWith
->HasRightIndent() && compareWith
->GetRightIndent() == style
.GetRightIndent()))
570 destStyle
.SetRightIndent(style
.GetRightIndent());
573 if (style
.HasParagraphSpacingAfter())
575 if (!(compareWith
&& compareWith
->HasParagraphSpacingAfter() && compareWith
->GetParagraphSpacingAfter() == style
.GetParagraphSpacingAfter()))
576 destStyle
.SetParagraphSpacingAfter(style
.GetParagraphSpacingAfter());
579 if (style
.HasParagraphSpacingBefore())
581 if (!(compareWith
&& compareWith
->HasParagraphSpacingBefore() && compareWith
->GetParagraphSpacingBefore() == style
.GetParagraphSpacingBefore()))
582 destStyle
.SetParagraphSpacingBefore(style
.GetParagraphSpacingBefore());
585 if (style
.HasLineSpacing())
587 if (!(compareWith
&& compareWith
->HasLineSpacing() && compareWith
->GetLineSpacing() == style
.GetLineSpacing()))
588 destStyle
.SetLineSpacing(style
.GetLineSpacing());
591 if (style
.HasCharacterStyleName())
593 if (!(compareWith
&& compareWith
->HasCharacterStyleName() && compareWith
->GetCharacterStyleName() == style
.GetCharacterStyleName()))
594 destStyle
.SetCharacterStyleName(style
.GetCharacterStyleName());
597 if (style
.HasParagraphStyleName())
599 if (!(compareWith
&& compareWith
->HasParagraphStyleName() && compareWith
->GetParagraphStyleName() == style
.GetParagraphStyleName()))
600 destStyle
.SetParagraphStyleName(style
.GetParagraphStyleName());
603 if (style
.HasListStyleName())
605 if (!(compareWith
&& compareWith
->HasListStyleName() && compareWith
->GetListStyleName() == style
.GetListStyleName()))
606 destStyle
.SetListStyleName(style
.GetListStyleName());
609 if (style
.HasBulletStyle())
611 if (!(compareWith
&& compareWith
->HasBulletStyle() && compareWith
->GetBulletStyle() == style
.GetBulletStyle()))
612 destStyle
.SetBulletStyle(style
.GetBulletStyle());
615 if (style
.HasBulletText())
617 if (!(compareWith
&& compareWith
->HasBulletText() && compareWith
->GetBulletText() == style
.GetBulletText()))
619 destStyle
.SetBulletText(style
.GetBulletText());
620 destStyle
.SetBulletFont(style
.GetBulletFont());
624 if (style
.HasBulletNumber())
626 if (!(compareWith
&& compareWith
->HasBulletNumber() && compareWith
->GetBulletNumber() == style
.GetBulletNumber()))
627 destStyle
.SetBulletNumber(style
.GetBulletNumber());
630 if (style
.HasBulletName())
632 if (!(compareWith
&& compareWith
->HasBulletName() && compareWith
->GetBulletName() == style
.GetBulletName()))
633 destStyle
.SetBulletName(style
.GetBulletName());
638 if (!(compareWith
&& compareWith
->HasURL() && compareWith
->GetURL() == style
.GetURL()))
639 destStyle
.SetURL(style
.GetURL());
642 if (style
.HasPageBreak())
644 if (!(compareWith
&& compareWith
->HasPageBreak()))
645 destStyle
.SetPageBreak();
648 if (style
.HasTextEffects())
650 if (!(compareWith
&& compareWith
->HasTextEffects() && compareWith
->GetTextEffects() == style
.GetTextEffects()))
652 int destBits
= destStyle
.GetTextEffects();
653 int destFlags
= destStyle
.GetTextEffectFlags();
655 int srcBits
= style
.GetTextEffects();
656 int srcFlags
= style
.GetTextEffectFlags();
658 // Reset incompatible bits in the destination
659 wxResetIncompatibleBits((wxTEXT_ATTR_EFFECT_SUPERSCRIPT
|wxTEXT_ATTR_EFFECT_SUBSCRIPT
), srcFlags
, destFlags
, destBits
);
660 wxResetIncompatibleBits((wxTEXT_ATTR_EFFECT_CAPITALS
|wxTEXT_ATTR_EFFECT_SMALL_CAPITALS
), srcFlags
, destFlags
, destBits
);
661 wxResetIncompatibleBits((wxTEXT_ATTR_EFFECT_STRIKETHROUGH
|wxTEXT_ATTR_EFFECT_DOUBLE_STRIKETHROUGH
), srcFlags
, destFlags
, destBits
);
663 CombineBitlists(destBits
, srcBits
, destFlags
, srcFlags
);
665 destStyle
.SetTextEffects(destBits
);
666 destStyle
.SetTextEffectFlags(destFlags
);
670 if (style
.HasOutlineLevel())
672 if (!(compareWith
&& compareWith
->HasOutlineLevel() && compareWith
->GetOutlineLevel() == style
.GetOutlineLevel()))
673 destStyle
.SetOutlineLevel(style
.GetOutlineLevel());
680 wxTextAttr
wxTextAttr::Combine(const wxTextAttr
& attr
,
681 const wxTextAttr
& attrDef
,
682 const wxTextCtrlBase
*text
)
686 font
= attr
.GetFont();
690 if (attrDef
.HasFont())
691 font
= attrDef
.GetFont();
693 if ( text
&& !font
.IsOk() )
694 font
= text
->GetFont();
697 wxColour colFg
= attr
.GetTextColour();
700 colFg
= attrDef
.GetTextColour();
702 if ( text
&& !colFg
.IsOk() )
703 colFg
= text
->GetForegroundColour();
706 wxColour colBg
= attr
.GetBackgroundColour();
709 colBg
= attrDef
.GetBackgroundColour();
711 if ( text
&& !colBg
.IsOk() )
712 colBg
= text
->GetBackgroundColour();
715 wxTextAttr
newAttr(colFg
, colBg
, font
);
717 if (attr
.HasAlignment())
718 newAttr
.SetAlignment(attr
.GetAlignment());
719 else if (attrDef
.HasAlignment())
720 newAttr
.SetAlignment(attrDef
.GetAlignment());
723 newAttr
.SetTabs(attr
.GetTabs());
724 else if (attrDef
.HasTabs())
725 newAttr
.SetTabs(attrDef
.GetTabs());
727 if (attr
.HasLeftIndent())
728 newAttr
.SetLeftIndent(attr
.GetLeftIndent(), attr
.GetLeftSubIndent());
729 else if (attrDef
.HasLeftIndent())
730 newAttr
.SetLeftIndent(attrDef
.GetLeftIndent(), attr
.GetLeftSubIndent());
732 if (attr
.HasRightIndent())
733 newAttr
.SetRightIndent(attr
.GetRightIndent());
734 else if (attrDef
.HasRightIndent())
735 newAttr
.SetRightIndent(attrDef
.GetRightIndent());
741 bool wxTextAttr::TabsEq(const wxArrayInt
& tabs1
, const wxArrayInt
& tabs2
)
743 if (tabs1
.GetCount() != tabs2
.GetCount())
747 for (i
= 0; i
< tabs1
.GetCount(); i
++)
749 if (tabs1
[i
] != tabs2
[i
])
756 bool wxTextAttr::RemoveStyle(wxTextAttr
& destStyle
, const wxTextAttr
& style
)
758 int flags
= style
.GetFlags();
759 int destFlags
= destStyle
.GetFlags();
761 destStyle
.SetFlags(destFlags
& ~flags
);
766 /// Combine two bitlists, specifying the bits of interest with separate flags.
767 bool wxTextAttr::CombineBitlists(int& valueA
, int valueB
, int& flagsA
, int flagsB
)
769 // We want to apply B's bits to A, taking into account each's flags which indicate which bits
770 // are to be taken into account. A zero in B's bits should reset that bit in A but only if B's flags
773 // First, reset the 0 bits from B. We make a mask so we're only dealing with B's zero
774 // bits at this point, ignoring any 1 bits in B or 0 bits in B that are not relevant.
775 int valueA2
= ~(~valueB
& flagsB
) & valueA
;
777 // Now combine the 1 bits.
778 int valueA3
= (valueB
& flagsB
) | valueA2
;
781 flagsA
= (flagsA
| flagsB
);
786 /// Compare two bitlists
787 bool wxTextAttr::BitlistsEqPartial(int valueA
, int valueB
, int flags
)
789 int relevantBitsA
= valueA
& flags
;
790 int relevantBitsB
= valueB
& flags
;
791 return relevantBitsA
== relevantBitsB
;
794 /// Split into paragraph and character styles
795 bool wxTextAttr::SplitParaCharStyles(const wxTextAttr
& style
, wxTextAttr
& parStyle
, wxTextAttr
& charStyle
)
797 wxTextAttr
defaultCharStyle1(style
);
798 wxTextAttr
defaultParaStyle1(style
);
799 defaultCharStyle1
.SetFlags(defaultCharStyle1
.GetFlags()&wxTEXT_ATTR_CHARACTER
);
800 defaultParaStyle1
.SetFlags(defaultParaStyle1
.GetFlags()&wxTEXT_ATTR_PARAGRAPH
);
802 charStyle
.Apply(defaultCharStyle1
);
803 parStyle
.Apply(defaultParaStyle1
);
808 // apply styling to text range
809 bool wxTextCtrlBase::SetStyle(long WXUNUSED(start
), long WXUNUSED(end
),
810 const wxTextAttr
& WXUNUSED(style
))
812 // to be implemented in derived classes
816 // get the styling at the given position
817 bool wxTextCtrlBase::GetStyle(long WXUNUSED(position
), wxTextAttr
& WXUNUSED(style
))
819 // to be implemented in derived classes
823 // change default text attributes
824 bool wxTextCtrlBase::SetDefaultStyle(const wxTextAttr
& style
)
826 // keep the old attributes if the new style doesn't specify them unless the
827 // new style is empty - then reset m_defaultStyle (as there is no other way
829 if ( style
.IsDefault() )
830 m_defaultStyle
= style
;
832 m_defaultStyle
= wxTextAttr::Combine(style
, m_defaultStyle
, this);
837 // ----------------------------------------------------------------------------
839 // ----------------------------------------------------------------------------
841 bool wxTextAreaBase::DoLoadFile(const wxString
& filename
, int WXUNUSED(fileType
))
844 wxFFile
file(filename
);
845 if ( file
.IsOpened() )
848 if ( file
.ReadAll(&text
) )
855 #endif // wxUSE_FFILE
860 bool wxTextCtrlBase::DoLoadFile(const wxString
& filename
, int fileType
)
862 if ( wxTextAreaBase::DoLoadFile(filename
, fileType
) )
865 m_filename
= filename
;
868 wxLogError(_("File couldn't be loaded."));
872 bool wxTextAreaBase::DoSaveFile(const wxString
& filename
, int WXUNUSED(fileType
))
875 wxFFile
file(filename
, wxT("w"));
876 return file
.IsOpened() && file
.Write(GetValue(), *wxConvCurrent
);
879 #endif // wxUSE_FFILE
882 bool wxTextAreaBase::SaveFile(const wxString
& filename
, int fileType
)
884 wxString filenameToUse
= filename
.empty() ? m_filename
: filename
;
885 if ( filenameToUse
.empty() )
887 // what kind of message to give? is it an error or a program bug?
888 wxLogDebug(wxT("Can't save textctrl to file without filename."));
893 return DoSaveFile(filenameToUse
, fileType
);
896 bool wxTextCtrlBase::DoSaveFile(const wxString
& filename
, int fileType
)
898 if ( wxTextAreaBase::DoSaveFile(filename
, fileType
) )
900 // if it worked, save for future calls
901 m_filename
= filename
;
903 // it's not modified any longer
911 // ----------------------------------------------------------------------------
912 // stream-like insertion operator
913 // ----------------------------------------------------------------------------
915 wxTextCtrl
& wxTextCtrlBase::operator<<(const wxString
& s
)
918 return *TEXTCTRL(this);
921 wxTextCtrl
& wxTextCtrlBase::operator<<(double d
)
923 return *this << wxString::Format("%.2f", d
);
926 wxTextCtrl
& wxTextCtrlBase::operator<<(int i
)
928 return *this << wxString::Format("%d", i
);
931 wxTextCtrl
& wxTextCtrlBase::operator<<(long l
)
933 return *this << wxString::Format("%ld", l
);
936 // ----------------------------------------------------------------------------
937 // streambuf methods implementation
938 // ----------------------------------------------------------------------------
940 #if wxHAS_TEXT_WINDOW_STREAM
942 int wxTextCtrlBase::overflow(int c
)
944 AppendText((wxChar
)c
);
946 // return something different from EOF
950 #endif // wxHAS_TEXT_WINDOW_STREAM
952 // ----------------------------------------------------------------------------
953 // emulating key presses
954 // ----------------------------------------------------------------------------
956 bool wxTextCtrlBase::EmulateKeyPress(const wxKeyEvent
& event
)
958 bool handled
= false;
959 // we have a native implementation for Win32 and so don't need this one
962 int keycode
= event
.GetKeyCode();
965 GetSelection(&from
,&to
);
966 long insert
= GetInsertionPoint();
967 long last
= GetLastPosition();
969 // catch arrow left and right
974 if ( event
.ShiftDown() )
975 SetSelection( (from
> 0 ? from
- 1 : 0) , to
);
980 else if ( insert
> 0 )
982 SetInsertionPoint( insert
);
987 if ( event
.ShiftDown() )
988 SetSelection( from
, (to
< last
? to
+ 1 : last
) );
993 else if ( insert
< last
)
995 SetInsertionPoint( insert
);
1009 ch
= (wxChar
)(wxT('0') + keycode
- WXK_NUMPAD0
);
1013 case WXK_NUMPAD_MULTIPLY
:
1018 case WXK_NUMPAD_ADD
:
1023 case WXK_NUMPAD_SUBTRACT
:
1028 case WXK_NUMPAD_DECIMAL
:
1033 case WXK_NUMPAD_DIVIDE
:
1038 case WXK_NUMPAD_DELETE
:
1039 // delete the character at cursor
1041 const long pos
= GetInsertionPoint();
1042 if ( pos
< GetLastPosition() )
1043 Remove(pos
, pos
+ 1);
1049 // delete the character before the cursor
1051 const long pos
= GetInsertionPoint();
1053 Remove(pos
- 1, pos
);
1060 if ( event
.GetUnicodeKey() )
1062 ch
= event
.GetUnicodeKey();
1066 if ( keycode
< 256 && keycode
>= 0 && wxIsprint(keycode
) )
1068 // FIXME this is not going to work for non letters...
1069 if ( !event
.ShiftDown() )
1071 keycode
= wxTolower(keycode
);
1074 ch
= (wxChar
)keycode
;
1090 #endif // !__WIN32__/__WIN32__
1095 // do the window-specific processing after processing the update event
1096 void wxTextCtrlBase::DoUpdateWindowUI(wxUpdateUIEvent
& event
)
1098 // call inherited, but skip the wxControl's version, and call directly the
1099 // wxWindow's one instead, because the only reason why we are overriding this
1100 // function is that we want to use SetValue() instead of wxControl::SetLabel()
1101 wxWindowBase::DoUpdateWindowUI(event
);
1104 if ( event
.GetSetText() )
1106 if ( event
.GetText() != GetValue() )
1107 SetValue(event
.GetText());
1111 // ----------------------------------------------------------------------------
1113 // ----------------------------------------------------------------------------
1115 wxTextCtrlHitTestResult
1116 wxTextAreaBase::HitTest(const wxPoint
& pt
, wxTextCoord
*x
, wxTextCoord
*y
) const
1118 // implement in terms of the other overload as the native ports typically
1119 // can get the position and not (x, y) pair directly (although wxUniv
1120 // directly gets x and y -- and so overrides this method as well)
1122 wxTextCtrlHitTestResult rc
= HitTest(pt
, &pos
);
1124 if ( rc
!= wxTE_HT_UNKNOWN
)
1126 PositionToXY(pos
, x
, y
);
1132 wxTextCtrlHitTestResult
1133 wxTextAreaBase::HitTest(const wxPoint
& WXUNUSED(pt
), long * WXUNUSED(pos
)) const
1136 return wxTE_HT_UNKNOWN
;
1139 wxPoint
wxTextAreaBase::PositionToCoords(long pos
) const
1141 wxCHECK_MSG( IsValidPosition(pos
), wxDefaultPosition
,
1142 wxS("Position argument out of range.") );
1144 return DoPositionToCoords(pos
);
1147 wxPoint
wxTextAreaBase::DoPositionToCoords(long WXUNUSED(pos
)) const
1149 return wxDefaultPosition
;
1152 #else // !wxUSE_TEXTCTRL
1154 // define this one even if !wxUSE_TEXTCTRL because it is also used by other
1155 // controls (wxComboBox and wxSpinCtrl)
1157 wxDEFINE_EVENT( wxEVT_COMMAND_TEXT_UPDATED
, wxCommandEvent
);
1159 #endif // wxUSE_TEXTCTRL/!wxUSE_TEXTCTRL