Added wxRE_CENTRE_CARET style to centre the caret line vertically
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@58257
c3d73ce0-8a6f-49c7-b76d-
6d57e0e08775
#define wxRE_READONLY 0x0010
#define wxRE_MULTILINE 0x0020
#define wxRE_READONLY 0x0010
#define wxRE_MULTILINE 0x0020
+#define wxRE_CENTRE_CARET 0x8000
+#define wxRE_CENTER_CARET wxRE_CENTRE_CARET
For more information, see the @ref overview_richtextctrl.
For more information, see the @ref overview_richtextctrl.
+ @beginStyleTable
+ @style{wxRE_CENTRE_CARET}
+ The control will try to keep the caret line centred vertically while editing.
+ wxRE_CENTER_CARET is a synonym for this style.
+ @style{wxRE_MULTILINE}
+ The control will be multiline (mandatory).
+ @style{wxRE_READONLY}
+ The control will not be editable.
+ @endStyleTable
+
@library{wxrichtext}
@category{richtext}
@appearance{richtextctrl.png}
@library{wxrichtext}
@category{richtext}
@appearance{richtextctrl.png}
SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT));
}
SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT));
}
+ // No physical scrolling, so we can preserve margins
+ EnableScrolling(false, false);
+
if (style & wxTE_READONLY)
SetEditable(false);
if (style & wxTE_READONLY)
SetEditable(false);
+ wxRect clipRect(availableSpace);
+ clipRect.x += GetBuffer().GetLeftMargin();
+ clipRect.y += GetBuffer().GetTopMargin();
+ clipRect.width -= (GetBuffer().GetLeftMargin() + GetBuffer().GetRightMargin());
+ clipRect.height -= (GetBuffer().GetTopMargin() + GetBuffer().GetBottomMargin());
+ clipRect.SetPosition(GetLogicalPoint(clipRect.GetPosition()));
+ dc.SetClippingRegion(clipRect);
+
GetBuffer().Draw(dc, GetBuffer().GetRange(), GetInternalSelectionRange(), drawingArea, 0 /* descent */, 0 /* flags */);
GetBuffer().Draw(dc, GetBuffer().GetRange(), GetInternalSelectionRange(), drawingArea, 0 /* descent */, 0 /* flags */);
+
+ dc.DestroyClippingRegion();
+
#if wxRICHTEXT_USE_OWN_CARET
if (GetCaret()->IsVisible())
{
#if wxRICHTEXT_USE_OWN_CARET
if (GetCaret()->IsVisible())
{
bool scrolled = false;
wxSize clientSize = GetClientSize();
bool scrolled = false;
wxSize clientSize = GetClientSize();
+ clientSize.y -= GetBuffer().GetBottomMargin();
+
+ if (GetWindowStyle() & wxRE_CENTRE_CARET)
+ {
+ int y = rect.y - GetClientSize().y/2;
+ int yUnits = (int) (0.5 + ((float) y)/(float) ppuY);
+ if (y >= 0 && (y + clientSize.y) < GetBuffer().GetCachedSize().y)
+ {
+ if (startYUnits != yUnits)
+ {
+ SetScrollbars(ppuX, ppuY, sxUnits, syUnits, 0, yUnits);
+ scrolled = true;
+ }
+#if !wxRICHTEXT_USE_OWN_CARET
+ if (scrolled)
+#endif
+ PositionCaret();
+
+ return scrolled;
+ }
+ }
// Going down
if (keyCode == WXK_DOWN || keyCode == WXK_NUMPAD_DOWN ||
// Going down
if (keyCode == WXK_DOWN || keyCode == WXK_NUMPAD_DOWN ||
- else if (rect.y < startY)
+ else if (rect.y < (startY + GetBuffer().GetTopMargin()))
{
// Make it scroll so this item is at the top
// of the window
{
// Make it scroll so this item is at the top
// of the window
+ int y = rect.y - GetBuffer().GetTopMargin();
int yUnits = (int) (0.5 + ((float) y)/(float) ppuY);
if (startYUnits != yUnits)
int yUnits = (int) (0.5 + ((float) y)/(float) ppuY);
if (startYUnits != yUnits)
keyCode == WXK_HOME || keyCode == WXK_NUMPAD_HOME ||
keyCode == WXK_PAGEUP || keyCode == WXK_NUMPAD_PAGEUP )
{
keyCode == WXK_HOME || keyCode == WXK_NUMPAD_HOME ||
keyCode == WXK_PAGEUP || keyCode == WXK_NUMPAD_PAGEUP )
{
+ if (rect.y < (startY + GetBuffer().GetBottomMargin()))
{
// Make it scroll so this item is at the top
// of the window
{
// Make it scroll so this item is at the top
// of the window
+ int y = rect.y - GetBuffer().GetTopMargin();
int yUnits = (int) (0.5 + ((float) y)/(float) ppuY);
if (startYUnits != yUnits)
int yUnits = (int) (0.5 + ((float) y)/(float) ppuY);
if (startYUnits != yUnits)
wxRect rect = line->GetRect();
wxSize clientSize = GetClientSize();
wxRect rect = line->GetRect();
wxSize clientSize = GetClientSize();
+ clientSize.y -= GetBuffer().GetBottomMargin();
- return (rect.GetBottom() > startY) && (rect.GetTop() < (startY + clientSize.y));
+ return (rect.GetBottom() > (startY + GetBuffer().GetTopMargin())) && (rect.GetTop() < (startY + clientSize.y));
}
void wxRichTextCtrl::SetCaretPosition(long position, bool showAtLineStart)
}
void wxRichTextCtrl::SetCaretPosition(long position, bool showAtLineStart)
int pixelsPerUnit = 5;
wxSize clientSize = GetClientSize();
int pixelsPerUnit = 5;
wxSize clientSize = GetClientSize();
- int maxHeight = GetBuffer().GetCachedSize().y;
+ int maxHeight = GetBuffer().GetCachedSize().y + GetBuffer().GetTopMargin();
// Round up so we have at least maxHeight pixels
int unitsY = (int) (((float)maxHeight/(float)pixelsPerUnit) + 0.5);
// Round up so we have at least maxHeight pixels
int unitsY = (int) (((float)maxHeight/(float)pixelsPerUnit) + 0.5);
GetCaret()->Hide();
if (GetCaret()->GetSize() != newSz)
GetCaret()->SetSize(newSz);
GetCaret()->Hide();
if (GetCaret()->GetSize() != newSz)
GetCaret()->SetSize(newSz);
+
+ int halfSize = newSz.y/2;
+ // If the caret is beyond the margin, hide it by moving it out of the way
+ if (((pt.y + halfSize) < GetBuffer().GetTopMargin()) || ((pt.y + halfSize) > (GetClientSize().y - GetBuffer().GetBottomMargin())))
+ pt.y = -200;
+
GetCaret()->Move(pt);
GetCaret()->Show();
}
GetCaret()->Move(pt);
GetCaret()->Show();
}