X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/efb2c52f8c506008a5e374d82f3e13b55702dce3..9d5507f7a2701395e1d5c121bd877bb9066ee6ea:/src/richtext/richtextctrl.cpp?ds=inline diff --git a/src/richtext/richtextctrl.cpp b/src/richtext/richtextctrl.cpp index 901901e56d..62acf0a2fa 100644 --- a/src/richtext/richtextctrl.cpp +++ b/src/richtext/richtextctrl.cpp @@ -76,6 +76,7 @@ BEGIN_EVENT_TABLE( wxRichTextCtrl, wxControl ) EVT_KILL_FOCUS(wxRichTextCtrl::OnKillFocus) EVT_MOUSE_CAPTURE_LOST(wxRichTextCtrl::OnCaptureLost) EVT_CONTEXT_MENU(wxRichTextCtrl::OnContextMenu) + EVT_SYS_COLOUR_CHANGED(wxRichTextCtrl::OnSysColourChanged) EVT_MENU(wxID_UNDO, wxRichTextCtrl::OnUndo) EVT_UPDATE_UI(wxID_UNDO, wxRichTextCtrl::OnUpdateUndo) @@ -129,9 +130,9 @@ wxRichTextCtrl::wxRichTextCtrl(wxWindow* parent, bool wxRichTextCtrl::Create( wxWindow* parent, wxWindowID id, const wxString& value, const wxPoint& pos, const wxSize& size, long style, const wxValidator& validator, const wxString& name) { - if (!wxTextCtrlBase::Create(parent, id, pos, size, - style|wxFULL_REPAINT_ON_RESIZE, - validator, name)) + if (!wxControl::Create(parent, id, pos, size, + style|wxFULL_REPAINT_ON_RESIZE, + validator, name)) return false; if (!GetFont().Ok()) @@ -141,7 +142,7 @@ bool wxRichTextCtrl::Create( wxWindow* parent, wxWindowID id, const wxString& va GetBuffer().Reset(); GetBuffer().SetRichTextCtrl(this); - + SetCaret(new wxCaret(this, wxRICHTEXT_DEFAULT_CARET_WIDTH, 16)); GetCaret()->Show(); @@ -149,10 +150,9 @@ bool wxRichTextCtrl::Create( wxWindow* parent, wxWindowID id, const wxString& va SetEditable(false); // The base attributes must all have default values - wxTextAttrEx attributes; + wxTextAttr attributes; attributes.SetFont(GetFont()); - attributes.SetTextColour(*wxBLACK); - attributes.SetBackgroundColour(*wxWHITE); + attributes.SetTextColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT)); attributes.SetAlignment(wxTEXT_ALIGNMENT_LEFT); attributes.SetLineSpacing(10); attributes.SetParagraphSpacingAfter(10); @@ -164,10 +164,10 @@ bool wxRichTextCtrl::Create( wxWindow* parent, wxWindowID id, const wxString& va // The default attributes will be merged with base attributes, so // can be empty to begin with - wxTextAttrEx defaultAttributes; + wxTextAttr defaultAttributes; SetDefaultStyle(defaultAttributes); - SetBackgroundColour(*wxWHITE); + SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW)); SetBackgroundStyle(wxBG_STYLE_CUSTOM); // Tell the sizers to use the given or best size @@ -194,7 +194,7 @@ bool wxRichTextCtrl::Create( wxWindow* parent, wxWindowID id, const wxString& va wxRichTextCtrl::~wxRichTextCtrl() { GetBuffer().RemoveEventHandler(this); - + delete m_contextMenu; } @@ -230,7 +230,10 @@ void wxRichTextCtrl::Thaw() if (m_freezeCount == 0) { - SetupScrollbars(); + if (GetBuffer().GetDirty()) + LayoutContent(); + else + SetupScrollbars(); Refresh(false); } } @@ -245,14 +248,13 @@ void wxRichTextCtrl::Clear() m_caretAtLineStart = false; m_selectionRange.SetRange(-2, -2); - SetScrollbars(0, 0, 0, 0, 0, 0); - if (m_freezeCount == 0) { - SetupScrollbars(); + LayoutContent(); Refresh(false); } - SendTextUpdatedEvent(); + + wxTextCtrl::SendTextUpdatedEvent(this); } /// Painting @@ -328,7 +330,7 @@ void wxRichTextCtrl::OnKillFocus(wxFocusEvent& WXUNUSED(event)) void wxRichTextCtrl::OnCaptureLost(wxMouseCaptureLostEvent& WXUNUSED(event)) { - m_dragging = false; + m_dragging = false; } /// Left-click @@ -390,33 +392,42 @@ void wxRichTextCtrl::OnLeftUp(wxMouseEvent& event) long position = 0; wxPoint logicalPt = event.GetLogicalPosition(dc); int hit = GetBuffer().HitTest(dc, logicalPt, position); - + if (hit != wxRICHTEXT_HITTEST_NONE) { - wxTextAttrEx attr; - if (GetStyle(position, attr)) + wxRichTextEvent cmdEvent( + wxEVT_COMMAND_RICHTEXT_LEFT_CLICK, + GetId()); + cmdEvent.SetEventObject(this); + cmdEvent.SetPosition(m_caretPosition+1); + + if (!GetEventHandler()->ProcessEvent(cmdEvent)) { - if (attr.HasFlag(wxTEXT_ATTR_URL)) + wxTextAttr attr; + if (GetStyle(position, attr)) { - wxString urlTarget = attr.GetURL(); - if (!urlTarget.IsEmpty()) + if (attr.HasFlag(wxTEXT_ATTR_URL)) { - wxMouseEvent mouseEvent(event); - - long startPos = 0, endPos = 0; - wxRichTextObject* obj = GetBuffer().GetLeafObjectAtPosition(position); - if (obj) + wxString urlTarget = attr.GetURL(); + if (!urlTarget.IsEmpty()) { - startPos = obj->GetRange().GetStart(); - endPos = obj->GetRange().GetEnd(); - } - - wxTextUrlEvent urlEvent(GetId(), mouseEvent, startPos, endPos); - InitCommandEvent(urlEvent); - - urlEvent.SetString(urlTarget); - - GetEventHandler()->ProcessEvent(urlEvent); + wxMouseEvent mouseEvent(event); + + long startPos = 0, endPos = 0; + wxRichTextObject* obj = GetBuffer().GetLeafObjectAtPosition(position); + if (obj) + { + startPos = obj->GetRange().GetStart(); + endPos = obj->GetRange().GetEnd(); + } + + wxTextUrlEvent urlEvent(GetId(), mouseEvent, startPos, endPos); + InitCommandEvent(urlEvent); + + urlEvent.SetString(urlTarget); + + GetEventHandler()->ProcessEvent(urlEvent); + } } } } @@ -434,13 +445,13 @@ void wxRichTextCtrl::OnMoveMouse(wxMouseEvent& event) long position = 0; wxPoint logicalPt = event.GetLogicalPosition(dc); int hit = GetBuffer().HitTest(dc, logicalPt, position); - + // See if we need to change the cursor - + { if (hit != wxRICHTEXT_HITTEST_NONE && !(hit & wxRICHTEXT_HITTEST_OUTSIDE)) { - wxTextAttrEx attr; + wxTextAttr attr; if (GetStyle(position, attr)) { if (attr.HasFlag(wxTEXT_ATTR_URL)) @@ -499,20 +510,43 @@ void wxRichTextCtrl::OnMoveMouse(wxMouseEvent& event) void wxRichTextCtrl::OnRightClick(wxMouseEvent& event) { SetFocus(); - event.Skip(); + + wxRichTextEvent cmdEvent( + wxEVT_COMMAND_RICHTEXT_RIGHT_CLICK, + GetId()); + cmdEvent.SetEventObject(this); + cmdEvent.SetPosition(m_caretPosition+1); + + if (!GetEventHandler()->ProcessEvent(cmdEvent)) + event.Skip(); } /// Left-double-click -void wxRichTextCtrl::OnLeftDClick(wxMouseEvent& event) +void wxRichTextCtrl::OnLeftDClick(wxMouseEvent& WXUNUSED(event)) { - SelectWord(GetCaretPosition()+1); - event.Skip(); + wxRichTextEvent cmdEvent( + wxEVT_COMMAND_RICHTEXT_LEFT_DCLICK, + GetId()); + cmdEvent.SetEventObject(this); + cmdEvent.SetPosition(m_caretPosition+1); + + if (!GetEventHandler()->ProcessEvent(cmdEvent)) + { + SelectWord(GetCaretPosition()+1); + } } /// Middle-click void wxRichTextCtrl::OnMiddleClick(wxMouseEvent& event) { - event.Skip(); + wxRichTextEvent cmdEvent( + wxEVT_COMMAND_RICHTEXT_MIDDLE_CLICK, + GetId()); + cmdEvent.SetEventObject(this); + cmdEvent.SetPosition(m_caretPosition+1); + + if (!GetEventHandler()->ProcessEvent(cmdEvent)) + event.Skip(); } /// Key press @@ -590,7 +624,7 @@ void wxRichTextCtrl::OnChar(wxKeyEvent& event) // Generate conventional event wxCommandEvent textEvent(wxEVT_COMMAND_TEXT_ENTER, GetId()); InitCommandEvent(textEvent); - + GetEventHandler()->ProcessEvent(textEvent); } Update(); @@ -598,7 +632,7 @@ void wxRichTextCtrl::OnChar(wxKeyEvent& event) else if (event.GetKeyCode() == WXK_BACK) { BeginBatchUndo(_("Delete Text")); - + // Submit range in character positions, which are greater than caret positions, // so subtract 1 for deleted character and add 1 for conversion to character position. if (m_caretPosition > -1 && !HasSelection()) @@ -670,7 +704,6 @@ void wxRichTextCtrl::OnChar(wxKeyEvent& event) switch ( keycode ) { case WXK_ESCAPE: - // case WXK_SPACE: case WXK_DELETE: case WXK_START: case WXK_LBUTTON: @@ -764,6 +797,7 @@ void wxRichTextCtrl::OnChar(wxKeyEvent& event) case WXK_NUMPAD_SEPARATOR: case WXK_NUMPAD_SUBTRACT: case WXK_NUMPAD_DECIMAL: + case WXK_WINDOWS_LEFT: { event.Skip(); return; @@ -782,9 +816,13 @@ void wxRichTextCtrl::OnChar(wxKeyEvent& event) GetId()); cmdEvent.SetEventObject(this); cmdEvent.SetFlags(flags); +#if wxUSE_UNICODE + cmdEvent.SetCharacter(event.GetUnicodeKey()); +#else cmdEvent.SetCharacter((wxChar) keycode); +#endif cmdEvent.SetPosition(m_caretPosition+1); - + if (keycode == wxT('\t')) { // See if we need to promote or demote the selection or paragraph at the cursor @@ -814,14 +852,18 @@ void wxRichTextCtrl::OnChar(wxKeyEvent& event) long newPos = m_caretPosition; DeleteSelectedContent(& newPos); +#if wxUSE_UNICODE + wxString str = event.GetUnicodeKey(); +#else wxString str = (wxChar) event.GetKeyCode(); +#endif GetBuffer().InsertTextWithUndo(newPos+1, str, this, 0); EndBatchUndo(); SetDefaultStyleToCursorStyle(); ScrollIntoView(m_caretPosition, WXK_RIGHT); - + GetEventHandler()->ProcessEvent(cmdEvent); Update(); @@ -1009,7 +1051,7 @@ bool wxRichTextCtrl::ScrollIntoView(long position, int keyCode) // Going down if (keyCode == WXK_DOWN || keyCode == WXK_NUMPAD_DOWN || - keyCode == WXK_RIGHT || keyCode == WXK_NUMPAD_DOWN || + keyCode == WXK_RIGHT || keyCode == WXK_NUMPAD_RIGHT || keyCode == WXK_END || keyCode == WXK_NUMPAD_END || keyCode == WXK_PAGEDOWN || keyCode == WXK_NUMPAD_PAGEDOWN) { @@ -1102,17 +1144,10 @@ bool wxRichTextCtrl::IsPositionVisible(long pos) const startX = 0; startY = startY * ppuY; - int sx = 0, sy = 0; - GetVirtualSize(& sx, & sy); - sx = 0; - if (ppuY != 0) - sy = sy/ppuY; - wxRect rect = line->GetRect(); - wxSize clientSize = GetClientSize(); - return !(((rect.y + rect.height) > (clientSize.y + startY)) || rect.y < startY); + return (rect.GetBottom() > startY) && (rect.GetTop() < (startY + clientSize.y)); } void wxRichTextCtrl::SetCaretPosition(long position, bool showAtLineStart) @@ -1556,6 +1591,11 @@ bool wxRichTextCtrl::PageDown(int noPages, int flags) return false; } +static bool wxRichTextCtrlIsWhitespace(const wxString& str) +{ + return str == wxT(" ") || str == wxT("\t"); +} + // Finds the caret position for the next word long wxRichTextCtrl::FindNextWordPosition(int direction) const { @@ -1570,7 +1610,12 @@ long wxRichTextCtrl::FindNextWordPosition(int direction) const { // i is in character, not caret positions wxString text = GetBuffer().GetTextForRange(wxRichTextRange(i, i)); - if (text != wxT(" ") && !text.empty()) + wxRichTextLine* line = GetBuffer().GetLineAtPosition(i, false); + if (line && (i == line->GetAbsoluteRange().GetEnd())) + { + break; + } + else if (!wxRichTextCtrlIsWhitespace(text) && !text.empty()) i += direction; else { @@ -1581,9 +1626,13 @@ long wxRichTextCtrl::FindNextWordPosition(int direction) const { // i is in character, not caret positions wxString text = GetBuffer().GetTextForRange(wxRichTextRange(i, i)); + wxRichTextLine* line = GetBuffer().GetLineAtPosition(i, false); + if (line && (i == line->GetAbsoluteRange().GetEnd())) + return wxMax(-1, i); + if (text.empty()) // End of paragraph, or maybe an image return wxMax(-1, i - 1); - else if (text == wxT(" ") || text.empty()) + else if (wxRichTextCtrlIsWhitespace(text) || text.empty()) i += direction; else { @@ -1604,9 +1653,11 @@ long wxRichTextCtrl::FindNextWordPosition(int direction) const { // i is in character, not caret positions wxString text = GetBuffer().GetTextForRange(wxRichTextRange(i, i)); - if (text.empty()) // End of paragraph, or maybe an image + wxRichTextLine* line = GetBuffer().GetLineAtPosition(i, false); + + if (text.empty() || (line && (i == line->GetAbsoluteRange().GetStart()))) // End of paragraph, or maybe an image break; - else if (text == wxT(" ") || text.empty()) + else if (wxRichTextCtrlIsWhitespace(text) || text.empty()) i += direction; else break; @@ -1616,7 +1667,11 @@ long wxRichTextCtrl::FindNextWordPosition(int direction) const { // i is in character, not caret positions wxString text = GetBuffer().GetTextForRange(wxRichTextRange(i, i)); - if (text != wxT(" ") /* && !text.empty() */) + wxRichTextLine* line = GetBuffer().GetLineAtPosition(i, false); + if (line && line->GetAbsoluteRange().GetStart() == i) + return i-1; + + if (!wxRichTextCtrlIsWhitespace(text) /* && !text.empty() */) i += direction; else { @@ -1820,7 +1875,7 @@ bool wxRichTextCtrl::DoLoadFile(const wxString& filename, int fileType) PositionCaret(); SetupScrollbars(true); Refresh(false); - SendTextUpdatedEvent(); + wxTextCtrl::SendTextUpdatedEvent(this); if (success) return true; @@ -1981,10 +2036,8 @@ wxRichTextCtrl::HitTest(const wxPoint& pt, return wxTE_HT_BEFORE; else if ((hit & wxRICHTEXT_HITTEST_AFTER) && (hit & wxRICHTEXT_HITTEST_OUTSIDE)) return wxTE_HT_BEYOND; - else if (hit & wxRICHTEXT_HITTEST_BEFORE|wxRICHTEXT_HITTEST_AFTER) + else if (hit & (wxRICHTEXT_HITTEST_BEFORE|wxRICHTEXT_HITTEST_AFTER)) return wxTE_HT_ON_TEXT; - else - return wxTE_HT_UNKNOWN; return wxTE_HT_UNKNOWN; } @@ -2008,30 +2061,21 @@ void wxRichTextCtrl::DoSetValue(const wxString& value, int flags) { Clear(); - // if the text is long enough, it's faster to just set it instead of first - // comparing it with the old one (chances are that it will be different - // anyhow, this comparison is there to avoid flicker for small single-line - // edit controls mostly) - if ( (value.length() > 0x400) || (value != GetValue()) ) + if (!value.IsEmpty()) { + // Remove empty paragraph + GetBuffer().Clear(); DoWriteText(value); // for compatibility, don't move the cursor when doing SetValue() SetInsertionPoint(0); } - else // same text + else { - if ( flags & SetValue_SendEvent ) - { - // still send an event for consistency - SendTextUpdatedEvent(); - } + // still send an event for consistency + if (flags & SetValue_SendEvent) + wxTextCtrl::SendTextUpdatedEvent(this); } - - // we should reset the modified flag even if the value didn't really change - - // mark the control as being not dirty - we changed its text, not the - // user DiscardEdits(); } @@ -2047,7 +2091,7 @@ void wxRichTextCtrl::DoWriteText(const wxString& value, int flags) GetBuffer().InsertTextWithUndo(m_caretPosition+1, valueUnix, this, wxRICHTEXT_INSERT_WITH_PREVIOUS_PARAGRAPH_STYLE); if ( flags & SetValue_SendEvent ) - SendTextUpdatedEvent(); + wxTextCtrl::SendTextUpdatedEvent(this); } void wxRichTextCtrl::AppendText(const wxString& text) @@ -2480,8 +2524,14 @@ void wxRichTextCtrl::OnUpdateSelectAll(wxUpdateUIEvent& event) event.Enable(GetLastPosition() > 0); } -void wxRichTextCtrl::OnContextMenu(wxContextMenuEvent& WXUNUSED(event)) +void wxRichTextCtrl::OnContextMenu(wxContextMenuEvent& event) { + if (event.GetEventObject() != this) + { + event.Skip(); + return; + } + if (!m_contextMenu) { m_contextMenu = new wxMenu; @@ -2499,17 +2549,12 @@ void wxRichTextCtrl::OnContextMenu(wxContextMenuEvent& WXUNUSED(event)) return; } -bool wxRichTextCtrl::SetStyle(long start, long end, const wxTextAttrEx& style) -{ - return GetBuffer().SetStyle(wxRichTextRange(start, end-1), style); -} - bool wxRichTextCtrl::SetStyle(long start, long end, const wxTextAttr& style) { - return GetBuffer().SetStyle(wxRichTextRange(start, end-1), wxTextAttrEx(style)); + return GetBuffer().SetStyle(wxRichTextRange(start, end-1), wxTextAttr(style)); } -bool wxRichTextCtrl::SetStyle(const wxRichTextRange& range, const wxRichTextAttr& style) +bool wxRichTextCtrl::SetStyle(const wxRichTextRange& range, const wxTextAttr& style) { return GetBuffer().SetStyle(range.ToInternal(), style); } @@ -2517,34 +2562,15 @@ bool wxRichTextCtrl::SetStyle(const wxRichTextRange& range, const wxRichTextAttr // extended style setting operation with flags including: // wxRICHTEXT_SETSTYLE_WITH_UNDO, wxRICHTEXT_SETSTYLE_OPTIMIZE, wxRICHTEXT_SETSTYLE_PARAGRAPHS_ONLY. // see richtextbuffer.h for more details. -bool wxRichTextCtrl::SetStyleEx(long start, long end, const wxTextAttrEx& style, int flags) -{ - return GetBuffer().SetStyle(wxRichTextRange(start, end-1), style, flags); -} -bool wxRichTextCtrl::SetStyleEx(const wxRichTextRange& range, const wxTextAttrEx& style, int flags) +bool wxRichTextCtrl::SetStyleEx(const wxRichTextRange& range, const wxTextAttr& style, int flags) { return GetBuffer().SetStyle(range.ToInternal(), style, flags); } -bool wxRichTextCtrl::SetStyleEx(const wxRichTextRange& range, const wxRichTextAttr& style, int flags) -{ - return GetBuffer().SetStyle(range.ToInternal(), style, flags); -} - -bool wxRichTextCtrl::SetDefaultStyle(const wxTextAttrEx& style) -{ - return GetBuffer().SetDefaultStyle(style); -} - bool wxRichTextCtrl::SetDefaultStyle(const wxTextAttr& style) { - return GetBuffer().SetDefaultStyle(wxTextAttrEx(style)); -} - -const wxTextAttrEx& wxRichTextCtrl::GetDefaultStyleEx() const -{ - return GetBuffer().GetDefaultStyle(); + return GetBuffer().SetDefaultStyle(wxTextAttr(style)); } const wxTextAttr& wxRichTextCtrl::GetDefaultStyle() const @@ -2553,65 +2579,18 @@ const wxTextAttr& wxRichTextCtrl::GetDefaultStyle() const } bool wxRichTextCtrl::GetStyle(long position, wxTextAttr& style) -{ - wxTextAttrEx attr(style); - if (GetBuffer().GetStyle(position, attr)) - { - style = attr; - return true; - } - else - return false; -} - -bool wxRichTextCtrl::GetStyle(long position, wxTextAttrEx& style) -{ - return GetBuffer().GetStyle(position, style); -} - -bool wxRichTextCtrl::GetStyle(long position, wxRichTextAttr& style) { return GetBuffer().GetStyle(position, style); } // get the common set of styles for the range -bool wxRichTextCtrl::GetStyleForRange(const wxRichTextRange& range, wxRichTextAttr& style) -{ - wxTextAttrEx styleEx; - if (GetBuffer().GetStyleForRange(range.ToInternal(), styleEx)) - { - style = styleEx; - return true; - } - else - return false; -} - -bool wxRichTextCtrl::GetStyleForRange(const wxRichTextRange& range, wxTextAttrEx& style) +bool wxRichTextCtrl::GetStyleForRange(const wxRichTextRange& range, wxTextAttr& style) { return GetBuffer().GetStyleForRange(range.ToInternal(), style); } /// Get the content (uncombined) attributes for this position. - bool wxRichTextCtrl::GetUncombinedStyle(long position, wxTextAttr& style) -{ - wxTextAttrEx attr(style); - if (GetBuffer().GetUncombinedStyle(position, attr)) - { - style = attr; - return true; - } - else - return false; -} - -bool wxRichTextCtrl::GetUncombinedStyle(long position, wxTextAttrEx& style) -{ - return GetBuffer().GetUncombinedStyle(position, style); -} - -bool wxRichTextCtrl::GetUncombinedStyle(long position, wxRichTextAttr& style) { return GetBuffer().GetUncombinedStyle(position, style); } @@ -2621,7 +2600,7 @@ bool wxRichTextCtrl::SetFont(const wxFont& font) { wxControl::SetFont(font); - wxTextAttrEx attr = GetBuffer().GetAttributes(); + wxTextAttr attr = GetBuffer().GetAttributes(); attr.SetFont(font); GetBuffer().SetBasicStyle(attr); @@ -2660,12 +2639,13 @@ void wxRichTextCtrl::PositionCaret() wxRect caretRect; if (GetCaretPositionForIndex(GetCaretPosition(), caretRect)) { - wxPoint originalPt = caretRect.GetPosition(); - wxPoint pt = GetPhysicalPoint(originalPt); - if (GetCaret()->GetPosition() != pt) + wxPoint newPt = caretRect.GetPosition(); + wxSize newSz = caretRect.GetSize(); + wxPoint pt = GetPhysicalPoint(newPt); + if (GetCaret()->GetPosition() != pt || GetCaret()->GetSize() != newSz) { GetCaret()->Move(pt); - GetCaret()->SetSize(caretRect.GetSize()); + GetCaret()->SetSize(newSz); } } } @@ -2683,6 +2663,10 @@ bool wxRichTextCtrl::GetCaretPositionForIndex(long position, wxRect& rect) if (GetBuffer().FindPosition(dc, position, pt, & height, m_caretAtLineStart)) { + // Caret height can't be zero + if (height == 0) + height = dc.GetCharHeight(); + rect = wxRect(pt, wxSize(wxRICHTEXT_DEFAULT_CARET_WIDTH, height)); return true; } @@ -2771,7 +2755,7 @@ bool wxRichTextCtrl::IsSelectionBold() { if (HasSelection()) { - wxRichTextAttr attr; + wxTextAttr attr; wxRichTextRange range = GetSelectionRange(); attr.SetFlags(wxTEXT_ATTR_FONT_WEIGHT); attr.SetFontWeight(wxBOLD); @@ -2782,7 +2766,7 @@ bool wxRichTextCtrl::IsSelectionBold() { // If no selection, then we need to combine current style with default style // to see what the effect would be if we started typing. - wxRichTextAttr attr; + wxTextAttr attr; attr.SetFlags(wxTEXT_ATTR_FONT_WEIGHT); long pos = GetAdjustedCaretPosition(GetCaretPosition()); @@ -2802,7 +2786,7 @@ bool wxRichTextCtrl::IsSelectionItalics() if (HasSelection()) { wxRichTextRange range = GetSelectionRange(); - wxRichTextAttr attr; + wxTextAttr attr; attr.SetFlags(wxTEXT_ATTR_FONT_ITALIC); attr.SetFontStyle(wxITALIC); @@ -2812,7 +2796,7 @@ bool wxRichTextCtrl::IsSelectionItalics() { // If no selection, then we need to combine current style with default style // to see what the effect would be if we started typing. - wxRichTextAttr attr; + wxTextAttr attr; attr.SetFlags(wxTEXT_ATTR_FONT_ITALIC); long pos = GetAdjustedCaretPosition(GetCaretPosition()); @@ -2832,7 +2816,7 @@ bool wxRichTextCtrl::IsSelectionUnderlined() if (HasSelection()) { wxRichTextRange range = GetSelectionRange(); - wxRichTextAttr attr; + wxTextAttr attr; attr.SetFlags(wxTEXT_ATTR_FONT_UNDERLINE); attr.SetFontUnderlined(true); @@ -2842,7 +2826,7 @@ bool wxRichTextCtrl::IsSelectionUnderlined() { // If no selection, then we need to combine current style with default style // to see what the effect would be if we started typing. - wxRichTextAttr attr; + wxTextAttr attr; attr.SetFlags(wxTEXT_ATTR_FONT_UNDERLINE); long pos = GetAdjustedCaretPosition(GetCaretPosition()); @@ -2859,7 +2843,7 @@ bool wxRichTextCtrl::IsSelectionUnderlined() /// Apply bold to the selection bool wxRichTextCtrl::ApplyBoldToSelection() { - wxRichTextAttr attr; + wxTextAttr attr; attr.SetFlags(wxTEXT_ATTR_FONT_WEIGHT); attr.SetFontWeight(IsSelectionBold() ? wxNORMAL : wxBOLD); @@ -2873,7 +2857,7 @@ bool wxRichTextCtrl::ApplyBoldToSelection() /// Apply italic to the selection bool wxRichTextCtrl::ApplyItalicToSelection() { - wxRichTextAttr attr; + wxTextAttr attr; attr.SetFlags(wxTEXT_ATTR_FONT_ITALIC); attr.SetFontStyle(IsSelectionItalics() ? wxNORMAL : wxITALIC); @@ -2887,7 +2871,7 @@ bool wxRichTextCtrl::ApplyItalicToSelection() /// Apply underline to the selection bool wxRichTextCtrl::ApplyUnderlineToSelection() { - wxRichTextAttr attr; + wxTextAttr attr; attr.SetFlags(wxTEXT_ATTR_FONT_UNDERLINE); attr.SetFontUnderlined(!IsSelectionUnderlined()); @@ -2907,7 +2891,7 @@ bool wxRichTextCtrl::IsSelectionAligned(wxTextAttrAlignment alignment) else range = wxRichTextRange(GetCaretPosition()+1, GetCaretPosition()+2); - wxRichTextAttr attr; + wxTextAttr attr; attr.SetAlignment(alignment); return HasParagraphAttributes(range, attr); @@ -2916,7 +2900,7 @@ bool wxRichTextCtrl::IsSelectionAligned(wxTextAttrAlignment alignment) /// Apply alignment to the selection bool wxRichTextCtrl::ApplyAlignmentToSelection(wxTextAttrAlignment alignment) { - wxRichTextAttr attr; + wxTextAttr attr; attr.SetAlignment(alignment); if (HasSelection()) return SetStyle(GetSelectionRange(), attr); @@ -2934,7 +2918,7 @@ bool wxRichTextCtrl::ApplyStyle(wxRichTextStyleDefinition* def) { // Flags are defined within each definition, so only certain // attributes are applied. - wxRichTextAttr attr(GetStyleSheet() ? def->GetStyleMergedWithBase(GetStyleSheet()) : def->GetStyle()); + wxTextAttr attr(GetStyleSheet() ? def->GetStyleMergedWithBase(GetStyleSheet()) : def->GetStyle()); int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO|wxRICHTEXT_SETSTYLE_OPTIMIZE; @@ -2998,7 +2982,7 @@ bool wxRichTextCtrl::ApplyStyleSheet(wxRichTextStyleSheet* styleSheet) /// Sets the default style to the style under the cursor bool wxRichTextCtrl::SetDefaultStyleToCursorStyle() { - wxTextAttrEx attr; + wxTextAttr attr; attr.SetFlags(wxTEXT_ATTR_CHARACTER); // If at the start of a paragraph, use the next position. @@ -3129,5 +3113,17 @@ void wxRichTextCtrl::ClearAvailableFontNames() sm_availableFontNames.Clear(); } +void wxRichTextCtrl::OnSysColourChanged(wxSysColourChangedEvent& WXUNUSED(event)) +{ + //wxLogDebug(wxT("wxRichTextCtrl::OnSysColourChanged")); + + wxTextAttrEx basicStyle = GetBasicStyle(); + basicStyle.SetTextColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT)); + SetBasicStyle(basicStyle); + SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW)); + + Refresh(); +} + #endif // wxUSE_RICHTEXT