wxRTC now properly honours margin size

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
This commit is contained in:
Julian Smart
2009-01-21 12:06:21 +00:00
parent 3e84eb5fa2
commit e9f1000463
3 changed files with 60 additions and 6 deletions

View File

@@ -38,6 +38,8 @@ class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextStyleDefinition;
#define wxRE_READONLY 0x0010 #define wxRE_READONLY 0x0010
#define wxRE_MULTILINE 0x0020 #define wxRE_MULTILINE 0x0020
#define wxRE_CENTRE_CARET 0x8000
#define wxRE_CENTER_CARET wxRE_CENTRE_CARET
/* Flags /* Flags
*/ */

View File

@@ -159,6 +159,16 @@ public:
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} @library{wxrichtext}
@category{richtext} @category{richtext}
@appearance{richtextctrl.png} @appearance{richtextctrl.png}

View File

@@ -206,6 +206,9 @@ bool wxRichTextCtrl::Create( wxWindow* parent, wxWindowID id, const wxString& va
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) if (style & wxTE_READONLY)
SetEditable(false); SetEditable(false);
@@ -365,7 +368,18 @@ void wxRichTextCtrl::OnPaint(wxPaintEvent& WXUNUSED(event))
SetupScrollbars(); SetupScrollbars();
} }
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 wxRICHTEXT_USE_OWN_CARET
if (GetCaret()->IsVisible()) if (GetCaret()->IsVisible())
{ {
@@ -1231,6 +1245,27 @@ bool wxRichTextCtrl::ScrollIntoView(long position, int keyCode)
bool scrolled = false; bool scrolled = false;
wxSize clientSize = GetClientSize(); 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 // Going down
if (keyCode == WXK_DOWN || keyCode == WXK_NUMPAD_DOWN || if (keyCode == WXK_DOWN || keyCode == WXK_NUMPAD_DOWN ||
@@ -1255,11 +1290,11 @@ bool wxRichTextCtrl::ScrollIntoView(long position, int keyCode)
scrolled = true; scrolled = true;
} }
} }
else if (rect.y < startY) else if (rect.y < (startY + GetBuffer().GetTopMargin()))
{ {
// Make it scroll so this item is at the top // Make it scroll so this item is at the top
// of the window // of the window
int y = rect.y ; int y = rect.y - GetBuffer().GetTopMargin();
int yUnits = (int) (0.5 + ((float) y)/(float) ppuY); int yUnits = (int) (0.5 + ((float) y)/(float) ppuY);
if (startYUnits != yUnits) if (startYUnits != yUnits)
@@ -1275,11 +1310,11 @@ bool wxRichTextCtrl::ScrollIntoView(long position, int keyCode)
keyCode == WXK_HOME || keyCode == WXK_NUMPAD_HOME || keyCode == WXK_HOME || keyCode == WXK_NUMPAD_HOME ||
keyCode == WXK_PAGEUP || keyCode == WXK_NUMPAD_PAGEUP ) keyCode == WXK_PAGEUP || keyCode == WXK_NUMPAD_PAGEUP )
{ {
if (rect.y < startY) if (rect.y < (startY + GetBuffer().GetBottomMargin()))
{ {
// Make it scroll so this item is at the top // Make it scroll so this item is at the top
// of the window // of the window
int y = rect.y ; int y = rect.y - GetBuffer().GetTopMargin();
int yUnits = (int) (0.5 + ((float) y)/(float) ppuY); int yUnits = (int) (0.5 + ((float) y)/(float) ppuY);
if (startYUnits != yUnits) if (startYUnits != yUnits)
@@ -1333,8 +1368,9 @@ bool wxRichTextCtrl::IsPositionVisible(long pos) const
wxRect rect = line->GetRect(); wxRect rect = line->GetRect();
wxSize clientSize = GetClientSize(); 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)
@@ -1982,7 +2018,7 @@ void wxRichTextCtrl::SetupScrollbars(bool atTop)
int pixelsPerUnit = 5; int pixelsPerUnit = 5;
wxSize clientSize = GetClientSize(); wxSize clientSize = GetClientSize();
int maxHeight = GetBuffer().GetCachedSize().y; int maxHeight = GetBuffer().GetCachedSize().y + GetBuffer().GetTopMargin();
// Round up so we have at least maxHeight pixels // Round up so we have at least maxHeight pixels
int unitsY = (int) (((float)maxHeight/(float)pixelsPerUnit) + 0.5); int unitsY = (int) (((float)maxHeight/(float)pixelsPerUnit) + 0.5);
@@ -2883,6 +2919,12 @@ void wxRichTextCtrl::PositionCaret()
GetCaret()->Hide(); GetCaret()->Hide();
if (GetCaret()->GetSize() != newSz) if (GetCaret()->GetSize() != newSz)
GetCaret()->SetSize(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()->Move(pt);
GetCaret()->Show(); GetCaret()->Show();
} }