X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/99257cbe01d32c8bd2e8393ba4ce6a71e5953c7e..c08ee0349dd4ed6d62f734fe576e47c7027e2b9e:/src/richtext/richtextctrl.cpp diff --git a/src/richtext/richtextctrl.cpp b/src/richtext/richtextctrl.cpp index f09732ccd2..b3cef4837e 100644 --- a/src/richtext/richtextctrl.cpp +++ b/src/richtext/richtextctrl.cpp @@ -13,7 +13,7 @@ #include "wx/wxprec.h" #ifdef __BORLANDC__ - #pragma hdrstop + #pragma hdrstop #endif #if wxUSE_RICHTEXT @@ -21,16 +21,20 @@ #include "wx/richtext/richtextctrl.h" #ifndef WX_PRECOMP - #include "wx/wx.h" + #include "wx/wx.h" + #include "wx/settings.h" #endif #include "wx/textfile.h" #include "wx/ffile.h" -#include "wx/settings.h" #include "wx/filename.h" #include "wx/dcbuffer.h" #include "wx/arrimpl.cpp" +// DLL options compatibility check: +#include "wx/app.h" +WX_CHECK_BUILD_OPTIONS("wxRichTextCtrl") + DEFINE_EVENT_TYPE(wxEVT_COMMAND_RICHTEXT_ITEM_SELECTED) DEFINE_EVENT_TYPE(wxEVT_COMMAND_RICHTEXT_ITEM_DESELECTED) DEFINE_EVENT_TYPE(wxEVT_COMMAND_RICHTEXT_LEFT_CLICK) @@ -102,17 +106,17 @@ wxRichTextCtrl::wxRichTextCtrl() Init(); } -wxRichTextCtrl::wxRichTextCtrl( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style) +wxRichTextCtrl::wxRichTextCtrl( wxWindow* parent, wxWindowID id, const wxString& value, const wxPoint& pos, const wxSize& size, long style) #if wxRICHTEXT_DERIVES_FROM_TEXTCTRLBASE : wxScrollHelper(this) #endif { Init(); - Create(parent, id, pos, size, style); + Create(parent, id, value, pos, size, style); } /// Creation -bool wxRichTextCtrl::Create( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style) +bool wxRichTextCtrl::Create( wxWindow* parent, wxWindowID id, const wxString& value, const wxPoint& pos, const wxSize& size, long style) { #if wxRICHTEXT_DERIVES_FROM_TEXTCTRLBASE if (!wxTextCtrlBase::Create(parent, id, pos, size, style|wxFULL_REPAINT_ON_RESIZE @@ -151,6 +155,9 @@ bool wxRichTextCtrl::Create( wxWindow* parent, wxWindowID id, const wxPoint& pos RecreateBuffer(size); SetCursor(wxCursor(wxCURSOR_IBEAM)); + + if (!value.IsEmpty()) + SetValue(value); return true; } @@ -205,6 +212,8 @@ void wxRichTextCtrl::Clear() m_caretAtLineStart = false; m_selectionRange.SetRange(-2, -2); + SetScrollbars(0, 0, 0, 0, 0, 0); + if (m_freezeCount == 0) { SetupScrollbars(); @@ -702,16 +711,16 @@ bool wxRichTextCtrl::ScrollIntoView(long position, int keyCode) int ppuX, ppuY; GetScrollPixelsPerUnit(& ppuX, & ppuY); - int startX, startY; - GetViewStart(& startX, & startY); - startX = 0; - startY = startY * ppuY; + int startXUnits, startYUnits; + GetViewStart(& startXUnits, & startYUnits); + int startY = startYUnits * ppuY; int sx = 0, sy = 0; GetVirtualSize(& sx, & sy); - sx = 0; + int sxUnits = 0; + int syUnits = 0; if (ppuY != 0) - sy = sy/ppuY; + syUnits = sy/ppuY; wxRect rect = line->GetRect(); @@ -727,11 +736,15 @@ bool wxRichTextCtrl::ScrollIntoView(long position, int keyCode) // Make it scroll so this item is at the bottom // of the window int y = rect.y - (clientSize.y - rect.height); - y = (int) (0.5 + y/ppuY); + int yUnits = (int) (0.5 + ((float) y)/(float) ppuY); + + // If we're still off the screen, scroll another line down + if ((rect.y + rect.height) > (clientSize.y + (yUnits*ppuY))) + yUnits ++; - if (startY != y) + if (startYUnits != yUnits) { - SetScrollbars(ppuX, ppuY, sx, sy, 0, y); + SetScrollbars(ppuX, ppuY, sxUnits, syUnits, 0, yUnits); scrolled = true; } } @@ -740,11 +753,11 @@ bool wxRichTextCtrl::ScrollIntoView(long position, int keyCode) // Make it scroll so this item is at the top // of the window int y = rect.y ; - y = (int) (0.5 + y/ppuY); + int yUnits = (int) (0.5 + ((float) y)/(float) ppuY); - if (startY != y) + if (startYUnits != yUnits) { - SetScrollbars(ppuX, ppuY, sx, sy, 0, y); + SetScrollbars(ppuX, ppuY, sxUnits, syUnits, 0, yUnits); scrolled = true; } } @@ -757,11 +770,11 @@ bool wxRichTextCtrl::ScrollIntoView(long position, int keyCode) // Make it scroll so this item is at the top // of the window int y = rect.y ; - y = (int) (0.5 + y/ppuY); + int yUnits = (int) (0.5 + ((float) y)/(float) ppuY); - if (startY != y) + if (startYUnits != yUnits) { - SetScrollbars(ppuX, ppuY, sx, sy, 0, y); + SetScrollbars(ppuX, ppuY, sxUnits, syUnits, 0, yUnits); scrolled = true; } } @@ -770,11 +783,15 @@ bool wxRichTextCtrl::ScrollIntoView(long position, int keyCode) // Make it scroll so this item is at the bottom // of the window int y = rect.y - (clientSize.y - rect.height); - y = (int) (0.5 + y/ppuY); + int yUnits = (int) (0.5 + ((float) y)/(float) ppuY); - if (startY != y) + // If we're still off the screen, scroll another line down + if ((rect.y + rect.height) > (clientSize.y + (yUnits*ppuY))) + yUnits ++; + + if (startYUnits != yUnits) { - SetScrollbars(ppuX, ppuY, sx, sy, 0, y); + SetScrollbars(ppuX, ppuY, sxUnits, syUnits, 0, yUnits); scrolled = true; } } @@ -1432,19 +1449,20 @@ void wxRichTextCtrl::SetupScrollbars(bool atTop) // TODO: reimplement scrolling so we scroll by line, not by fixed number // of pixels. See e.g. wxVScrolledWindow for ideas. - int pixelsPerUnit = 5; // 10; + int pixelsPerUnit = 5; wxSize clientSize = GetClientSize(); int maxHeight = GetBuffer().GetCachedSize().y; - int unitsY = maxHeight/pixelsPerUnit; + // Round up so we have at least maxHeight pixels + int unitsY = (int) (((float)maxHeight/(float)pixelsPerUnit) + 0.5); int startX = 0, startY = 0; if (!atTop) GetViewStart(& startX, & startY); int maxPositionX = 0; // wxMax(sz.x - clientSize.x, 0); - int maxPositionY = (wxMax(maxHeight - clientSize.y, 0))/pixelsPerUnit; + int maxPositionY = (int) ((((float)(wxMax((unitsY*pixelsPerUnit) - clientSize.y, 0)))/((float)pixelsPerUnit)) + 0.5); // Move to previous scroll position if // possible @@ -1627,8 +1645,12 @@ wxRichTextCtrl::HitTest(const wxPoint& pt, { wxClientDC dc((wxRichTextCtrl*) this); ((wxRichTextCtrl*)this)->PrepareDC(dc); + + // Buffer uses logical position (relative to start of buffer) + // so convert + wxPoint pt2 = GetLogicalPoint(pt); - int hit = ((wxRichTextCtrl*)this)->GetBuffer().HitTest(dc, pt, *pos); + int hit = ((wxRichTextCtrl*)this)->GetBuffer().HitTest(dc, pt2, *pos); switch ( hit ) { @@ -2017,10 +2039,10 @@ bool wxRichTextCtrl::CanRedo() const } // ---------------------------------------------------------------------------- -// implemenation details +// implementation details // ---------------------------------------------------------------------------- -void wxRichTextCtrl::Command(wxCommandEvent & event) +void wxRichTextCtrl::Command(wxCommandEvent& event) { SetValue(event.GetString()); GetEventHandler()->ProcessEvent(event); @@ -2173,6 +2195,11 @@ bool wxRichTextCtrl::SetStyle(long start, long end, const wxTextAttrEx& style) return GetBuffer().SetStyle(wxRichTextRange(start, end), style); } +bool wxRichTextCtrl::SetStyle(long start, long end, const wxTextAttr& style) +{ + return GetBuffer().SetStyle(wxRichTextRange(start, end), wxTextAttrEx(style)); +} + bool wxRichTextCtrl::SetStyle(const wxRichTextRange& range, const wxRichTextAttr& style) { return GetBuffer().SetStyle(range, style); @@ -2183,11 +2210,33 @@ bool wxRichTextCtrl::SetDefaultStyle(const wxTextAttrEx& style) return GetBuffer().SetDefaultStyle(style); } +bool wxRichTextCtrl::SetDefaultStyle(const wxTextAttr& style) +{ + return GetBuffer().SetDefaultStyle(wxTextAttrEx(style)); +} + const wxTextAttrEx& wxRichTextCtrl::GetDefaultStyleEx() const { return GetBuffer().GetDefaultStyle(); } +const wxTextAttr& wxRichTextCtrl::GetDefaultStyle() const +{ + return GetBuffer().GetDefaultStyle(); +} + +bool wxRichTextCtrl::GetStyle(long position, wxTextAttr& style) const +{ + wxTextAttrEx attr; + if (GetBuffer().GetStyle(position, attr)) + { + style = attr; + return true; + } + else + return false; +} + bool wxRichTextCtrl::GetStyle(long position, wxTextAttrEx& style) const { return GetBuffer().GetStyle(position, style);