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 wxString fontFaceName
;
407 if (HasFontFaceName())
408 fontFaceName
= GetFontFaceName();
410 wxFontEncoding encoding
= wxFONTENCODING_DEFAULT
;
411 if (HasFontEncoding())
412 encoding
= GetFontEncoding();
414 wxFontFamily fontFamily
= wxFONTFAMILY_DEFAULT
;
416 fontFamily
= GetFontFamily();
418 wxFont
font(fontSize
, fontFamily
, fontStyle
, fontWeight
, underlined
, fontFaceName
, encoding
);
422 // Get attributes from font.
423 bool wxTextAttr::GetFontAttributes(const wxFont
& font
, int flags
)
428 if (flags
& wxTEXT_ATTR_FONT_SIZE
)
429 m_fontSize
= font
.GetPointSize();
431 if (flags
& wxTEXT_ATTR_FONT_ITALIC
)
432 m_fontStyle
= font
.GetStyle();
434 if (flags
& wxTEXT_ATTR_FONT_WEIGHT
)
435 m_fontWeight
= font
.GetWeight();
437 if (flags
& wxTEXT_ATTR_FONT_UNDERLINE
)
438 m_fontUnderlined
= font
.GetUnderlined();
440 if (flags
& wxTEXT_ATTR_FONT_FACE
)
441 m_fontFaceName
= font
.GetFaceName();
443 if (flags
& wxTEXT_ATTR_FONT_ENCODING
)
444 m_fontEncoding
= font
.GetEncoding();
446 if (flags
& wxTEXT_ATTR_FONT_FAMILY
)
448 // wxFont might not know its family, avoid setting m_fontFamily to an
449 // invalid value and rather pretend that we don't have any font family
450 // information at all in this case
451 const wxFontFamily fontFamily
= font
.GetFamily();
452 if ( fontFamily
== wxFONTFAMILY_UNKNOWN
)
453 flags
&= ~wxTEXT_ATTR_FONT_FAMILY
;
455 m_fontFamily
= fontFamily
;
463 // Resets bits in destination so new attributes aren't merged with mutually exclusive ones
464 static bool wxResetIncompatibleBits(const int mask
, const int srcFlags
, int& destFlags
, int& destBits
)
466 if ((srcFlags
& mask
) && (destFlags
& mask
))
475 bool wxTextAttr::Apply(const wxTextAttr
& style
, const wxTextAttr
* compareWith
)
477 wxTextAttr
& destStyle
= (*this);
479 if (style
.HasFontWeight())
481 if (!(compareWith
&& compareWith
->HasFontWeight() && compareWith
->GetFontWeight() == style
.GetFontWeight()))
482 destStyle
.SetFontWeight(style
.GetFontWeight());
485 if (style
.HasFontSize())
487 if (!(compareWith
&& compareWith
->HasFontSize() && compareWith
->GetFontSize() == style
.GetFontSize()))
488 destStyle
.SetFontSize(style
.GetFontSize());
491 if (style
.HasFontItalic())
493 if (!(compareWith
&& compareWith
->HasFontItalic() && compareWith
->GetFontStyle() == style
.GetFontStyle()))
494 destStyle
.SetFontStyle(style
.GetFontStyle());
497 if (style
.HasFontUnderlined())
499 if (!(compareWith
&& compareWith
->HasFontUnderlined() && compareWith
->GetFontUnderlined() == style
.GetFontUnderlined()))
500 destStyle
.SetFontUnderlined(style
.GetFontUnderlined());
503 if (style
.HasFontFaceName())
505 if (!(compareWith
&& compareWith
->HasFontFaceName() && compareWith
->GetFontFaceName() == style
.GetFontFaceName()))
506 destStyle
.SetFontFaceName(style
.GetFontFaceName());
509 if (style
.HasFontEncoding())
511 if (!(compareWith
&& compareWith
->HasFontEncoding() && compareWith
->GetFontEncoding() == style
.GetFontEncoding()))
512 destStyle
.SetFontEncoding(style
.GetFontEncoding());
515 if (style
.HasFontFamily())
517 if (!(compareWith
&& compareWith
->HasFontFamily() && compareWith
->GetFontFamily() == style
.GetFontFamily()))
518 destStyle
.SetFontFamily(style
.GetFontFamily());
521 if (style
.GetTextColour().IsOk() && style
.HasTextColour())
523 if (!(compareWith
&& compareWith
->HasTextColour() && compareWith
->GetTextColour() == style
.GetTextColour()))
524 destStyle
.SetTextColour(style
.GetTextColour());
527 if (style
.GetBackgroundColour().IsOk() && style
.HasBackgroundColour())
529 if (!(compareWith
&& compareWith
->HasBackgroundColour() && compareWith
->GetBackgroundColour() == style
.GetBackgroundColour()))
530 destStyle
.SetBackgroundColour(style
.GetBackgroundColour());
533 if (style
.HasAlignment())
535 if (!(compareWith
&& compareWith
->HasAlignment() && compareWith
->GetAlignment() == style
.GetAlignment()))
536 destStyle
.SetAlignment(style
.GetAlignment());
541 if (!(compareWith
&& compareWith
->HasTabs() && TabsEq(compareWith
->GetTabs(), style
.GetTabs())))
542 destStyle
.SetTabs(style
.GetTabs());
545 if (style
.HasLeftIndent())
547 if (!(compareWith
&& compareWith
->HasLeftIndent() && compareWith
->GetLeftIndent() == style
.GetLeftIndent()
548 && compareWith
->GetLeftSubIndent() == style
.GetLeftSubIndent()))
549 destStyle
.SetLeftIndent(style
.GetLeftIndent(), style
.GetLeftSubIndent());
552 if (style
.HasRightIndent())
554 if (!(compareWith
&& compareWith
->HasRightIndent() && compareWith
->GetRightIndent() == style
.GetRightIndent()))
555 destStyle
.SetRightIndent(style
.GetRightIndent());
558 if (style
.HasParagraphSpacingAfter())
560 if (!(compareWith
&& compareWith
->HasParagraphSpacingAfter() && compareWith
->GetParagraphSpacingAfter() == style
.GetParagraphSpacingAfter()))
561 destStyle
.SetParagraphSpacingAfter(style
.GetParagraphSpacingAfter());
564 if (style
.HasParagraphSpacingBefore())
566 if (!(compareWith
&& compareWith
->HasParagraphSpacingBefore() && compareWith
->GetParagraphSpacingBefore() == style
.GetParagraphSpacingBefore()))
567 destStyle
.SetParagraphSpacingBefore(style
.GetParagraphSpacingBefore());
570 if (style
.HasLineSpacing())
572 if (!(compareWith
&& compareWith
->HasLineSpacing() && compareWith
->GetLineSpacing() == style
.GetLineSpacing()))
573 destStyle
.SetLineSpacing(style
.GetLineSpacing());
576 if (style
.HasCharacterStyleName())
578 if (!(compareWith
&& compareWith
->HasCharacterStyleName() && compareWith
->GetCharacterStyleName() == style
.GetCharacterStyleName()))
579 destStyle
.SetCharacterStyleName(style
.GetCharacterStyleName());
582 if (style
.HasParagraphStyleName())
584 if (!(compareWith
&& compareWith
->HasParagraphStyleName() && compareWith
->GetParagraphStyleName() == style
.GetParagraphStyleName()))
585 destStyle
.SetParagraphStyleName(style
.GetParagraphStyleName());
588 if (style
.HasListStyleName())
590 if (!(compareWith
&& compareWith
->HasListStyleName() && compareWith
->GetListStyleName() == style
.GetListStyleName()))
591 destStyle
.SetListStyleName(style
.GetListStyleName());
594 if (style
.HasBulletStyle())
596 if (!(compareWith
&& compareWith
->HasBulletStyle() && compareWith
->GetBulletStyle() == style
.GetBulletStyle()))
597 destStyle
.SetBulletStyle(style
.GetBulletStyle());
600 if (style
.HasBulletText())
602 if (!(compareWith
&& compareWith
->HasBulletText() && compareWith
->GetBulletText() == style
.GetBulletText()))
604 destStyle
.SetBulletText(style
.GetBulletText());
605 destStyle
.SetBulletFont(style
.GetBulletFont());
609 if (style
.HasBulletNumber())
611 if (!(compareWith
&& compareWith
->HasBulletNumber() && compareWith
->GetBulletNumber() == style
.GetBulletNumber()))
612 destStyle
.SetBulletNumber(style
.GetBulletNumber());
615 if (style
.HasBulletName())
617 if (!(compareWith
&& compareWith
->HasBulletName() && compareWith
->GetBulletName() == style
.GetBulletName()))
618 destStyle
.SetBulletName(style
.GetBulletName());
623 if (!(compareWith
&& compareWith
->HasURL() && compareWith
->GetURL() == style
.GetURL()))
624 destStyle
.SetURL(style
.GetURL());
627 if (style
.HasPageBreak())
629 if (!(compareWith
&& compareWith
->HasPageBreak()))
630 destStyle
.SetPageBreak();
633 if (style
.HasTextEffects())
635 if (!(compareWith
&& compareWith
->HasTextEffects() && compareWith
->GetTextEffects() == style
.GetTextEffects()))
637 int destBits
= destStyle
.GetTextEffects();
638 int destFlags
= destStyle
.GetTextEffectFlags();
640 int srcBits
= style
.GetTextEffects();
641 int srcFlags
= style
.GetTextEffectFlags();
643 // Reset incompatible bits in the destination
644 wxResetIncompatibleBits((wxTEXT_ATTR_EFFECT_SUPERSCRIPT
|wxTEXT_ATTR_EFFECT_SUBSCRIPT
), srcFlags
, destFlags
, destBits
);
645 wxResetIncompatibleBits((wxTEXT_ATTR_EFFECT_CAPITALS
|wxTEXT_ATTR_EFFECT_SMALL_CAPITALS
), srcFlags
, destFlags
, destBits
);
646 wxResetIncompatibleBits((wxTEXT_ATTR_EFFECT_STRIKETHROUGH
|wxTEXT_ATTR_EFFECT_DOUBLE_STRIKETHROUGH
), srcFlags
, destFlags
, destBits
);
648 CombineBitlists(destBits
, srcBits
, destFlags
, srcFlags
);
650 destStyle
.SetTextEffects(destBits
);
651 destStyle
.SetTextEffectFlags(destFlags
);
655 if (style
.HasOutlineLevel())
657 if (!(compareWith
&& compareWith
->HasOutlineLevel() && compareWith
->GetOutlineLevel() == style
.GetOutlineLevel()))
658 destStyle
.SetOutlineLevel(style
.GetOutlineLevel());
665 wxTextAttr
wxTextAttr::Combine(const wxTextAttr
& attr
,
666 const wxTextAttr
& attrDef
,
667 const wxTextCtrlBase
*text
)
671 font
= attr
.GetFont();
675 if (attrDef
.HasFont())
676 font
= attrDef
.GetFont();
678 if ( text
&& !font
.IsOk() )
679 font
= text
->GetFont();
682 wxColour colFg
= attr
.GetTextColour();
685 colFg
= attrDef
.GetTextColour();
687 if ( text
&& !colFg
.IsOk() )
688 colFg
= text
->GetForegroundColour();
691 wxColour colBg
= attr
.GetBackgroundColour();
694 colBg
= attrDef
.GetBackgroundColour();
696 if ( text
&& !colBg
.IsOk() )
697 colBg
= text
->GetBackgroundColour();
700 wxTextAttr
newAttr(colFg
, colBg
, font
);
702 if (attr
.HasAlignment())
703 newAttr
.SetAlignment(attr
.GetAlignment());
704 else if (attrDef
.HasAlignment())
705 newAttr
.SetAlignment(attrDef
.GetAlignment());
708 newAttr
.SetTabs(attr
.GetTabs());
709 else if (attrDef
.HasTabs())
710 newAttr
.SetTabs(attrDef
.GetTabs());
712 if (attr
.HasLeftIndent())
713 newAttr
.SetLeftIndent(attr
.GetLeftIndent(), attr
.GetLeftSubIndent());
714 else if (attrDef
.HasLeftIndent())
715 newAttr
.SetLeftIndent(attrDef
.GetLeftIndent(), attr
.GetLeftSubIndent());
717 if (attr
.HasRightIndent())
718 newAttr
.SetRightIndent(attr
.GetRightIndent());
719 else if (attrDef
.HasRightIndent())
720 newAttr
.SetRightIndent(attrDef
.GetRightIndent());
726 bool wxTextAttr::TabsEq(const wxArrayInt
& tabs1
, const wxArrayInt
& tabs2
)
728 if (tabs1
.GetCount() != tabs2
.GetCount())
732 for (i
= 0; i
< tabs1
.GetCount(); i
++)
734 if (tabs1
[i
] != tabs2
[i
])
741 bool wxTextAttr::RemoveStyle(wxTextAttr
& destStyle
, const wxTextAttr
& style
)
743 int flags
= style
.GetFlags();
744 int destFlags
= destStyle
.GetFlags();
746 destStyle
.SetFlags(destFlags
& ~flags
);
751 /// Combine two bitlists, specifying the bits of interest with separate flags.
752 bool wxTextAttr::CombineBitlists(int& valueA
, int valueB
, int& flagsA
, int flagsB
)
754 // We want to apply B's bits to A, taking into account each's flags which indicate which bits
755 // are to be taken into account. A zero in B's bits should reset that bit in A but only if B's flags
758 // First, reset the 0 bits from B. We make a mask so we're only dealing with B's zero
759 // bits at this point, ignoring any 1 bits in B or 0 bits in B that are not relevant.
760 int valueA2
= ~(~valueB
& flagsB
) & valueA
;
762 // Now combine the 1 bits.
763 int valueA3
= (valueB
& flagsB
) | valueA2
;
766 flagsA
= (flagsA
| flagsB
);
771 /// Compare two bitlists
772 bool wxTextAttr::BitlistsEqPartial(int valueA
, int valueB
, int flags
)
774 int relevantBitsA
= valueA
& flags
;
775 int relevantBitsB
= valueB
& flags
;
776 return (relevantBitsA
!= relevantBitsB
);
779 /// Split into paragraph and character styles
780 bool wxTextAttr::SplitParaCharStyles(const wxTextAttr
& style
, wxTextAttr
& parStyle
, wxTextAttr
& charStyle
)
782 wxTextAttr
defaultCharStyle1(style
);
783 wxTextAttr
defaultParaStyle1(style
);
784 defaultCharStyle1
.SetFlags(defaultCharStyle1
.GetFlags()&wxTEXT_ATTR_CHARACTER
);
785 defaultParaStyle1
.SetFlags(defaultParaStyle1
.GetFlags()&wxTEXT_ATTR_PARAGRAPH
);
787 charStyle
.Apply(defaultCharStyle1
);
788 parStyle
.Apply(defaultParaStyle1
);
793 // apply styling to text range
794 bool wxTextCtrlBase::SetStyle(long WXUNUSED(start
), long WXUNUSED(end
),
795 const wxTextAttr
& WXUNUSED(style
))
797 // to be implemented in derived classes
801 // get the styling at the given position
802 bool wxTextCtrlBase::GetStyle(long WXUNUSED(position
), wxTextAttr
& WXUNUSED(style
))
804 // to be implemented in derived classes
808 // change default text attributes
809 bool wxTextCtrlBase::SetDefaultStyle(const wxTextAttr
& style
)
811 // keep the old attributes if the new style doesn't specify them unless the
812 // new style is empty - then reset m_defaultStyle (as there is no other way
814 if ( style
.IsDefault() )
815 m_defaultStyle
= style
;
817 m_defaultStyle
= wxTextAttr::Combine(style
, m_defaultStyle
, this);
822 // ----------------------------------------------------------------------------
824 // ----------------------------------------------------------------------------
826 bool wxTextAreaBase::DoLoadFile(const wxString
& filename
, int WXUNUSED(fileType
))
829 wxFFile
file(filename
);
830 if ( file
.IsOpened() )
833 if ( file
.ReadAll(&text
) )
840 #endif // wxUSE_FFILE
845 bool wxTextCtrlBase::DoLoadFile(const wxString
& filename
, int fileType
)
847 if ( wxTextAreaBase::DoLoadFile(filename
, fileType
) )
850 m_filename
= filename
;
853 wxLogError(_("File couldn't be loaded."));
857 bool wxTextAreaBase::DoSaveFile(const wxString
& filename
, int WXUNUSED(fileType
))
860 wxFFile
file(filename
, wxT("w"));
861 return file
.IsOpened() && file
.Write(GetValue(), *wxConvCurrent
);
864 #endif // wxUSE_FFILE
867 bool wxTextAreaBase::SaveFile(const wxString
& filename
, int fileType
)
869 wxString filenameToUse
= filename
.empty() ? m_filename
: filename
;
870 if ( filenameToUse
.empty() )
872 // what kind of message to give? is it an error or a program bug?
873 wxLogDebug(wxT("Can't save textctrl to file without filename."));
878 return DoSaveFile(filenameToUse
, fileType
);
881 bool wxTextCtrlBase::DoSaveFile(const wxString
& filename
, int fileType
)
883 if ( wxTextAreaBase::DoSaveFile(filename
, fileType
) )
885 // if it worked, save for future calls
886 m_filename
= filename
;
888 // it's not modified any longer
896 // ----------------------------------------------------------------------------
897 // stream-like insertion operator
898 // ----------------------------------------------------------------------------
900 wxTextCtrl
& wxTextCtrlBase::operator<<(const wxString
& s
)
903 return *TEXTCTRL(this);
906 wxTextCtrl
& wxTextCtrlBase::operator<<(double d
)
908 return *this << wxString::Format("%.2f", d
);
911 wxTextCtrl
& wxTextCtrlBase::operator<<(int i
)
913 return *this << wxString::Format("%d", i
);
916 wxTextCtrl
& wxTextCtrlBase::operator<<(long l
)
918 return *this << wxString::Format("%ld", l
);
921 // ----------------------------------------------------------------------------
922 // streambuf methods implementation
923 // ----------------------------------------------------------------------------
925 #if wxHAS_TEXT_WINDOW_STREAM
927 int wxTextCtrlBase::overflow(int c
)
929 AppendText((wxChar
)c
);
931 // return something different from EOF
935 #endif // wxHAS_TEXT_WINDOW_STREAM
937 // ----------------------------------------------------------------------------
938 // emulating key presses
939 // ----------------------------------------------------------------------------
941 bool wxTextCtrlBase::EmulateKeyPress(const wxKeyEvent
& event
)
943 // we have a native implementation for Win32 and so don't need this one
946 int keycode
= event
.GetKeyCode();
959 ch
= (wxChar
)(wxT('0') + keycode
- WXK_NUMPAD0
);
963 case WXK_NUMPAD_MULTIPLY
:
973 case WXK_NUMPAD_SUBTRACT
:
978 case WXK_NUMPAD_DECIMAL
:
983 case WXK_NUMPAD_DIVIDE
:
988 case WXK_NUMPAD_DELETE
:
989 // delete the character at cursor
991 const long pos
= GetInsertionPoint();
992 if ( pos
< GetLastPosition() )
993 Remove(pos
, pos
+ 1);
998 // delete the character before the cursor
1000 const long pos
= GetInsertionPoint();
1002 Remove(pos
- 1, pos
);
1008 if ( event
.GetUnicodeKey() )
1010 ch
= event
.GetUnicodeKey();
1014 if ( keycode
< 256 && keycode
>= 0 && wxIsprint(keycode
) )
1016 // FIXME this is not going to work for non letters...
1017 if ( !event
.ShiftDown() )
1019 keycode
= wxTolower(keycode
);
1022 ch
= (wxChar
)keycode
;
1038 #endif // !__WIN32__/__WIN32__
1043 // do the window-specific processing after processing the update event
1044 void wxTextCtrlBase::DoUpdateWindowUI(wxUpdateUIEvent
& event
)
1046 // call inherited, but skip the wxControl's version, and call directly the
1047 // wxWindow's one instead, because the only reason why we are overriding this
1048 // function is that we want to use SetValue() instead of wxControl::SetLabel()
1049 wxWindowBase::DoUpdateWindowUI(event
);
1052 if ( event
.GetSetText() )
1054 if ( event
.GetText() != GetValue() )
1055 SetValue(event
.GetText());
1059 // ----------------------------------------------------------------------------
1061 // ----------------------------------------------------------------------------
1063 wxTextCtrlHitTestResult
1064 wxTextAreaBase::HitTest(const wxPoint
& pt
, wxTextCoord
*x
, wxTextCoord
*y
) const
1066 // implement in terms of the other overload as the native ports typically
1067 // can get the position and not (x, y) pair directly (although wxUniv
1068 // directly gets x and y -- and so overrides this method as well)
1070 wxTextCtrlHitTestResult rc
= HitTest(pt
, &pos
);
1072 if ( rc
!= wxTE_HT_UNKNOWN
)
1074 PositionToXY(pos
, x
, y
);
1080 wxTextCtrlHitTestResult
1081 wxTextAreaBase::HitTest(const wxPoint
& WXUNUSED(pt
), long * WXUNUSED(pos
)) const
1084 return wxTE_HT_UNKNOWN
;
1087 wxPoint
wxTextAreaBase::PositionToCoords(long pos
) const
1089 wxCHECK_MSG( IsValidPosition(pos
), wxDefaultPosition
,
1090 wxS("Position argument out of range.") );
1092 return DoPositionToCoords(pos
);
1095 wxPoint
wxTextAreaBase::DoPositionToCoords(long WXUNUSED(pos
)) const
1097 return wxDefaultPosition
;
1100 #else // !wxUSE_TEXTCTRL
1102 // define this one even if !wxUSE_TEXTCTRL because it is also used by other
1103 // controls (wxComboBox and wxSpinCtrl)
1105 wxDEFINE_EVENT( wxEVT_COMMAND_TEXT_UPDATED
, wxCommandEvent
);
1107 #endif // wxUSE_TEXTCTRL/!wxUSE_TEXTCTRL