EVT_PAINT(wxRichTextCtrl::OnPaint)
EVT_ERASE_BACKGROUND(wxRichTextCtrl::OnEraseBackground)
EVT_IDLE(wxRichTextCtrl::OnIdle)
+ EVT_SCROLLWIN(wxRichTextCtrl::OnScroll)
EVT_LEFT_DOWN(wxRichTextCtrl::OnLeftClick)
EVT_MOTION(wxRichTextCtrl::OnMoveMouse)
EVT_LEFT_UP(wxRichTextCtrl::OnLeftUp)
// Create a buffer
RecreateBuffer(size);
- wxCaret* caret = new wxCaret(this, wxRICHTEXT_DEFAULT_CARET_WIDTH, 16);
- SetCaret(caret);
- caret->Show();
- PositionCaret();
-
SetCursor(wxCursor(wxCURSOR_IBEAM));
return true;
/// Painting
void wxRichTextCtrl::OnPaint(wxPaintEvent& WXUNUSED(event))
{
- wxBufferedPaintDC dc(this, m_bufferBitmap);
-
- PrepareDC(dc);
-
- if (m_freezeCount > 0)
- return;
-
- dc.SetFont(GetFont());
-
- // Paint the background
- PaintBackground(dc);
+ if (GetCaret())
+ GetCaret()->Hide();
- wxRegion dirtyRegion = GetUpdateRegion();
-
- wxRect drawingArea(GetLogicalPoint(wxPoint(0, 0)), GetClientSize());
- wxRect availableSpace(GetClientSize());
- if (GetBuffer().GetDirty())
{
- GetBuffer().Layout(dc, availableSpace, wxRICHTEXT_FIXED_WIDTH|wxRICHTEXT_VARIABLE_HEIGHT);
- GetBuffer().SetDirty(false);
- SetupScrollbars();
+ wxBufferedPaintDC dc(this, m_bufferBitmap);
+ //wxLogDebug(wxT("OnPaint"));
+
+ PrepareDC(dc);
+
+ if (m_freezeCount > 0)
+ return;
+
+ dc.SetFont(GetFont());
+
+ // Paint the background
+ PaintBackground(dc);
+
+ wxRegion dirtyRegion = GetUpdateRegion();
+
+ wxRect drawingArea(GetLogicalPoint(wxPoint(0, 0)), GetClientSize());
+ wxRect availableSpace(GetClientSize());
+ if (GetBuffer().GetDirty())
+ {
+ GetBuffer().Layout(dc, availableSpace, wxRICHTEXT_FIXED_WIDTH|wxRICHTEXT_VARIABLE_HEIGHT);
+ GetBuffer().SetDirty(false);
+ SetupScrollbars();
+ }
+
+ GetBuffer().Draw(dc, GetBuffer().GetRange(), GetSelectionRange(), drawingArea, 0 /* descent */, 0 /* flags */);
}
- PositionCaret();
- GetBuffer().Draw(dc, GetBuffer().GetRange(), GetSelectionRange(), drawingArea, 0 /* descent */, 0 /* flags */);
+ if (GetCaret())
+ GetCaret()->Show();
+
+ PositionCaret();
}
// Empty implementation, to prevent flicker
void wxRichTextCtrl::OnSetFocus(wxFocusEvent& WXUNUSED(event))
{
+ wxCaret* caret = new wxCaret(this, wxRICHTEXT_DEFAULT_CARET_WIDTH, 16);
+ SetCaret(caret);
+ caret->Show();
+ PositionCaret();
+
if (!IsFrozen())
Refresh();
}
void wxRichTextCtrl::OnKillFocus(wxFocusEvent& WXUNUSED(event))
{
+ SetCaret(NULL);
+
if (!IsFrozen())
Refresh();
}
SetDefaultStyleToCursorStyle();
}
- // Only refresh if something changed
- Thaw(success);
+ Thaw(false);
return success;
}
// Make it scroll so this item is at the bottom
// of the window
int y = rect.y - (clientSize.y - rect.height);
- SetScrollbars(ppuX, ppuY, sx, sy, 0, (int) (0.5 + y/ppuY));
+ y = (int) (0.5 + y/ppuY);
+
+ if (startY != y)
+ {
+ SetScrollbars(ppuX, ppuY, sx, sy, 0, y);
+ scrolled = true;
+ }
}
else if (rect.y < startY)
{
// Make it scroll so this item is at the top
// of the window
int y = rect.y ;
- SetScrollbars(ppuX, ppuY, sx, sy, 0, (int) (0.5 + y/ppuY));
+ y = (int) (0.5 + y/ppuY);
+
+ if (startY != y)
+ {
+ SetScrollbars(ppuX, ppuY, sx, sy, 0, y);
+ scrolled = true;
+ }
}
- scrolled = true;
}
// Going up
else if (keyCode == WXK_UP || keyCode == WXK_LEFT || keyCode == WXK_HOME || keyCode == WXK_PRIOR || keyCode == WXK_PAGEUP)
// Make it scroll so this item is at the top
// of the window
int y = rect.y ;
- SetScrollbars(ppuX, ppuY, sx, sy, 0, (int) (0.5 + y/ppuY));
+ y = (int) (0.5 + y/ppuY);
+
+ if (startY != y)
+ {
+ SetScrollbars(ppuX, ppuY, sx, sy, 0, y);
+ scrolled = true;
+ }
}
else if ((rect.y + rect.height) > (clientSize.y + startY))
{
// Make it scroll so this item is at the bottom
// of the window
int y = rect.y - (clientSize.y - rect.height);
- SetScrollbars(ppuX, ppuY, sx, sy, 0, (int) (0.5 + y/ppuY));
+ y = (int) (0.5 + y/ppuY);
+
+ if (startY != y)
+ {
+ SetScrollbars(ppuX, ppuY, sx, sy, 0, y);
+ scrolled = true;
+ }
}
- scrolled = true;
}
PositionCaret();
PositionCaret();
SetDefaultStyleToCursorStyle();
- if (!IsFrozen())
- Refresh(); // TODO: optimize so that if we didn't change the selection, we don't refresh
+ if (extendSel)
+ Refresh();
return true;
}
else
PositionCaret();
SetDefaultStyleToCursorStyle();
- if (!IsFrozen())
+ if (extendSel)
Refresh();
return true;
}
/// Move up
bool wxRichTextCtrl::MoveDown(int noLines, int flags)
{
+ if (!GetCaret())
+ return false;
+
long lineNumber = GetBuffer().GetVisibleLineNumber(m_caretPosition, true, m_caretAtLineStart);
wxPoint pt = GetCaret()->GetPosition();
long newLine = lineNumber + noLines;
long newSelEnd = newPos;
- if (!ExtendSelection(m_caretPosition, newSelEnd, flags))
+ bool extendSel = ExtendSelection(m_caretPosition, newSelEnd, flags);
+ if (!extendSel)
SelectNone();
SetCaretPosition(newPos, caretLineStart);
PositionCaret();
SetDefaultStyleToCursorStyle();
- if (!IsFrozen())
+ if (extendSel)
Refresh();
return true;
}
if (para)
{
long newPos = para->GetRange().GetEnd() - 1;
- if (!ExtendSelection(m_caretPosition, newPos, flags))
+ bool extendSel = ExtendSelection(m_caretPosition, newPos, flags);
+ if (!extendSel)
SelectNone();
SetCaretPosition(newPos);
PositionCaret();
SetDefaultStyleToCursorStyle();
- if (!IsFrozen())
+ if (extendSel)
Refresh();
return true;
}
if (para)
{
long newPos = para->GetRange().GetStart() - 1;
- if (!ExtendSelection(m_caretPosition, newPos, flags))
+ bool extendSel = ExtendSelection(m_caretPosition, newPos, flags);
+ if (!extendSel)
SelectNone();
SetCaretPosition(newPos);
PositionCaret();
SetDefaultStyleToCursorStyle();
- if (!IsFrozen())
+ if (extendSel)
Refresh();
return true;
}
{
wxRichTextRange lineRange = line->GetAbsoluteRange();
long newPos = lineRange.GetEnd();
- if (!ExtendSelection(m_caretPosition, newPos, flags))
+ bool extendSel = ExtendSelection(m_caretPosition, newPos, flags);
+ if (!extendSel)
SelectNone();
SetCaretPosition(newPos);
PositionCaret();
SetDefaultStyleToCursorStyle();
- if (!IsFrozen())
+ if (extendSel)
Refresh();
return true;
}
wxRichTextRange lineRange = line->GetAbsoluteRange();
long newPos = lineRange.GetStart()-1;
- if (!ExtendSelection(m_caretPosition, newPos, flags))
+ bool extendSel = ExtendSelection(m_caretPosition, newPos, flags);
+ if (!extendSel)
SelectNone();
wxRichTextParagraph* para = GetBuffer().GetParagraphForLine(line);
PositionCaret();
SetDefaultStyleToCursorStyle();
- if (!IsFrozen())
+ if (extendSel)
Refresh();
return true;
}
{
if (m_caretPosition != -1)
{
- if (!ExtendSelection(m_caretPosition, -1, flags))
+ bool extendSel = ExtendSelection(m_caretPosition, -1, flags);
+ if (!extendSel)
SelectNone();
SetCaretPosition(-1);
PositionCaret();
SetDefaultStyleToCursorStyle();
- if (!IsFrozen())
+ if (extendSel)
Refresh();
return true;
}
if (m_caretPosition != endPos)
{
- if (!ExtendSelection(m_caretPosition, endPos, flags))
+ bool extendSel = ExtendSelection(m_caretPosition, endPos, flags);
+ if (!extendSel)
SelectNone();
SetCaretPosition(endPos);
PositionCaret();
SetDefaultStyleToCursorStyle();
- if (!IsFrozen())
+ if (extendSel)
Refresh();
return true;
}
{
wxRichTextParagraph* para = GetBuffer().GetParagraphForLine(newLine);
- if (!ExtendSelection(m_caretPosition, pos, flags))
+ bool extendSel = ExtendSelection(m_caretPosition, pos, flags);
+ if (!extendSel)
SelectNone();
SetCaretPosition(pos, para->GetRange().GetStart() != lineRange.GetStart());
PositionCaret();
SetDefaultStyleToCursorStyle();
- if (!IsFrozen())
+ if (extendSel)
Refresh();
return true;
}
{
wxRichTextParagraph* para = GetBuffer().GetParagraphAtPosition(pos, true);
- if (!ExtendSelection(m_caretPosition, pos, flags))
+ bool extendSel = ExtendSelection(m_caretPosition, pos, flags);
+ if (!extendSel)
SelectNone();
SetCaretPosition(pos, para->GetRange().GetStart() != pos);
PositionCaret();
SetDefaultStyleToCursorStyle();
- if (!IsFrozen())
+ if (extendSel)
Refresh();
return true;
}
{
wxRichTextParagraph* para = GetBuffer().GetParagraphAtPosition(pos, true);
- if (!ExtendSelection(m_caretPosition, pos, flags))
+ bool extendSel = ExtendSelection(m_caretPosition, pos, flags);
+ if (!extendSel)
SelectNone();
SetCaretPosition(pos, para->GetRange().GetStart() != pos);
PositionCaret();
SetDefaultStyleToCursorStyle();
- if (!IsFrozen())
+ if (extendSel)
Refresh();
return true;
}
event.Skip();
}
+/// Scrolling
+void wxRichTextCtrl::OnScroll(wxScrollWinEvent& event)
+{
+ // Not used
+ event.Skip();
+}
+
/// Set up scrollbars, e.g. after a resize
void wxRichTextCtrl::SetupScrollbars(bool atTop)
{
/// Select none
void wxRichTextCtrl::SelectNone()
{
- SetSelection(-2, -2);
+ if (!(GetSelectionRange() == wxRichTextRange(-2, -2)))
+ SetSelection(-2, -2);
m_selectionAnchor = -2;
}
{
m_selectionAnchor = from;
m_selectionRange.SetRange(from, to);
- if (!IsFrozen())
- Refresh();
+ Refresh();
PositionCaret();
}
/// Position the caret
void wxRichTextCtrl::PositionCaret()
{
+ if (!GetCaret())
+ return;
+
+ //wxLogDebug(wxT("PositionCaret"));
+
wxRect caretRect;
if (GetCaretPositionForIndex(GetCaretPosition(), caretRect))
{
wxPoint originalPt = caretRect.GetPosition();
wxPoint pt = GetPhysicalPoint(originalPt);
-
- GetCaret()->Move(pt);
- GetCaret()->SetSize(caretRect.GetSize());
+ if (GetCaret()->GetPosition() != pt)
+ {
+ GetCaret()->Move(pt);
+ GetCaret()->SetSize(caretRect.GetSize());
+ }
}
}