X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/d2d0adc7765dfe904f0f7e97d85a2638c934a7d6..4fe0156b18e2330be391b804da341e546164b85f:/src/richtext/richtextctrl.cpp diff --git a/src/richtext/richtextctrl.cpp b/src/richtext/richtextctrl.cpp index c59cbfb851..636c494439 100644 --- a/src/richtext/richtextctrl.cpp +++ b/src/richtext/richtextctrl.cpp @@ -128,7 +128,11 @@ bool wxRichTextCtrl::Create( wxWindow* parent, wxWindowID id, const wxString& va SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT)); } + GetBuffer().Reset(); GetBuffer().SetRichTextCtrl(this); + + SetCaret(new wxCaret(this, wxRICHTEXT_DEFAULT_CARET_WIDTH, 16)); + GetCaret()->Show(); if (style & wxTE_READONLY) SetEditable(false); @@ -153,7 +157,7 @@ bool wxRichTextCtrl::Create( wxWindow* parent, wxWindowID id, const wxString& va SetBackgroundStyle(wxBG_STYLE_CUSTOM); // Tell the sizers to use the given or best size - SetBestFittingSize(size); + SetInitialSize(size); #if wxRICHTEXT_BUFFERED_PAINTING // Create a buffer @@ -220,7 +224,7 @@ void wxRichTextCtrl::Thaw() /// Clear all text void wxRichTextCtrl::Clear() { - m_buffer.Reset(); + m_buffer.ResetAndClearCommands(); m_buffer.SetDirty(true); m_caretPosition = -1; m_caretPositionForDefaultStyle = -2; @@ -240,7 +244,7 @@ void wxRichTextCtrl::Clear() /// Painting void wxRichTextCtrl::OnPaint(wxPaintEvent& WXUNUSED(event)) { - if (GetCaret()) + if (GetCaret() && GetCaret()->IsVisible()) GetCaret()->Hide(); { @@ -259,7 +263,11 @@ void wxRichTextCtrl::OnPaint(wxPaintEvent& WXUNUSED(event)) // Paint the background PaintBackground(dc); - wxRect drawingArea(GetLogicalPoint(wxPoint(0, 0)), GetClientSize()); + // wxRect drawingArea(GetLogicalPoint(wxPoint(0, 0)), GetClientSize()); + + wxRect drawingArea(GetUpdateRegion().GetBox()); + drawingArea.SetPosition(GetLogicalPoint(drawingArea.GetPosition())); + wxRect availableSpace(GetClientSize()); if (GetBuffer().GetDirty()) { @@ -271,7 +279,7 @@ void wxRichTextCtrl::OnPaint(wxPaintEvent& WXUNUSED(event)) GetBuffer().Draw(dc, GetBuffer().GetRange(), GetInternalSelectionRange(), drawingArea, 0 /* descent */, 0 /* flags */); } - if (GetCaret()) + if (GetCaret() && !GetCaret()->IsVisible()) GetCaret()->Show(); PositionCaret(); @@ -284,21 +292,24 @@ void wxRichTextCtrl::OnEraseBackground(wxEraseEvent& WXUNUSED(event)) void wxRichTextCtrl::OnSetFocus(wxFocusEvent& WXUNUSED(event)) { - wxCaret* caret = new wxCaret(this, wxRICHTEXT_DEFAULT_CARET_WIDTH, 16); - SetCaret(caret); - caret->Show(); - PositionCaret(); + if (GetCaret()) + { + if (!GetCaret()->IsVisible()) + GetCaret()->Show(); + PositionCaret(); + } - if (!IsFrozen()) - Refresh(false); + // if (!IsFrozen()) + // Refresh(false); } void wxRichTextCtrl::OnKillFocus(wxFocusEvent& WXUNUSED(event)) { - SetCaret(NULL); + if (GetCaret() && GetCaret()->IsVisible()) + GetCaret()->Hide(); - if (!IsFrozen()) - Refresh(false); + // if (!IsFrozen()) + // Refresh(false); } /// Left-click @@ -415,13 +426,11 @@ void wxRichTextCtrl::OnMoveMouse(wxMouseEvent& event) { if (attr.HasFlag(wxTEXT_ATTR_URL)) { - if (GetCursor() != m_urlCursor) - SetCursor(m_urlCursor); + SetCursor(m_urlCursor); } else if (!attr.HasFlag(wxTEXT_ATTR_URL)) { - if (GetCursor() != m_textCursor) - SetCursor(m_textCursor); + SetCursor(m_textCursor); } } } @@ -553,6 +562,7 @@ void wxRichTextCtrl::OnChar(wxKeyEvent& event) GetEventHandler()->ProcessEvent(textEvent); } + Update(); } else if (event.GetKeyCode() == WXK_BACK) { @@ -572,7 +582,6 @@ void wxRichTextCtrl::OnChar(wxKeyEvent& event) EndBatchUndo(); - // Shouldn't this be in Do()? if (GetLastPosition() == -1) { GetBuffer().Reset(); @@ -583,6 +592,7 @@ void wxRichTextCtrl::OnChar(wxKeyEvent& event) } ScrollIntoView(m_caretPosition, WXK_LEFT); + Update(); } else if (event.GetKeyCode() == WXK_DELETE) { @@ -601,7 +611,6 @@ void wxRichTextCtrl::OnChar(wxKeyEvent& event) EndBatchUndo(); - // Shouldn't this be in Do()? if (GetLastPosition() == -1) { GetBuffer().Reset(); @@ -610,6 +619,7 @@ void wxRichTextCtrl::OnChar(wxKeyEvent& event) PositionCaret(); SetDefaultStyleToCursorStyle(); } + Update(); } else { @@ -758,6 +768,7 @@ void wxRichTextCtrl::OnChar(wxKeyEvent& event) SetDefaultStyleToCursorStyle(); ScrollIntoView(m_caretPosition, WXK_RIGHT); + Update(); } } } @@ -2942,6 +2953,18 @@ long wxRichTextCtrl::GetFirstVisiblePosition() const return 0; } +/// Get the first visible point in the window +wxPoint wxRichTextCtrl::GetFirstVisiblePoint() const +{ + int ppuX, ppuY; + int startXUnits, startYUnits; + + GetScrollPixelsPerUnit(& ppuX, & ppuY); + GetViewStart(& startXUnits, & startYUnits); + + return wxPoint(startXUnits * ppuX, startYUnits * ppuY); +} + /// The adjusted caret position is the character position adjusted to take /// into account whether we're at the start of a paragraph, in which case /// style information should be taken from the next position, not current one.