Reuse wxCaret object

Add page break specification
Optimize drawing after character input


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@42734 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Julian Smart
2006-10-30 17:51:38 +00:00
parent 391bf008a7
commit ea160b2e92
5 changed files with 232 additions and 22 deletions

View File

@@ -130,6 +130,9 @@ 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();
if (style & wxTE_READONLY)
SetEditable(false);
@@ -241,7 +244,7 @@ void wxRichTextCtrl::Clear()
/// Painting
void wxRichTextCtrl::OnPaint(wxPaintEvent& WXUNUSED(event))
{
if (GetCaret())
if (GetCaret() && GetCaret()->IsVisible())
GetCaret()->Hide();
{
@@ -260,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())
{
@@ -272,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();
@@ -285,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
@@ -2945,6 +2955,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.