X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/a1b806b98241ab649c169aaa1f134df85e80fb8b..e2cb99c8567e4010a2caf77e3e8b7e4501bf3d6a:/src/stc/stc.cpp diff --git a/src/stc/stc.cpp b/src/stc/stc.cpp index b9f6da5e3e..cc580a1ff3 100644 --- a/src/stc/stc.cpp +++ b/src/stc/stc.cpp @@ -1,5 +1,5 @@ //////////////////////////////////////////////////////////////////////////// -// Name: src/stc/stc.cpp +// Name: stc.cpp // Purpose: A wxWidgets implementation of Scintilla. This class is the // one meant to be used directly by wx applications. It does not // derive directly from the Scintilla classes, but instead @@ -199,7 +199,7 @@ bool wxStyledTextCtrl::Create(wxWindow *parent, m_swx = new ScintillaWX(this); m_stopWatch.Start(); m_lastKeyDownConsumed = false; - m_lastWheelTimestamp = 0; + m_timeToBlockWheelEventsUntil = 0; m_vScrollBar = NULL; m_hScrollBar = NULL; #if wxUSE_UNICODE @@ -210,7 +210,7 @@ bool wxStyledTextCtrl::Create(wxWindow *parent, SetInitialSize(size); // Reduces flicker on GTK+/X11 - SetBackgroundStyle(wxBG_STYLE_CUSTOM); + SetBackgroundStyle(wxBG_STYLE_PAINT); // Make sure it can take the focus SetCanFocus(true); @@ -258,8 +258,8 @@ void wxStyledTextCtrl::SetHScrollBar(wxScrollBar* bar) { // Add text to the document at current position. void wxStyledTextCtrl::AddText(const wxString& text) { - wxWX2MBbuf buf = (wxWX2MBbuf)wx2stc(text); - SendMsg(2001, strlen(buf), (sptr_t)(const char*)buf); + const wxWX2MBbuf buf = wx2stc(text); + SendMsg(2001, wx2stclen(text, buf), (sptr_t)(const char*)buf); } // Add array of cells to document. @@ -1410,7 +1410,7 @@ int wxStyledTextCtrl::FindText(int minPos, int maxPos, TextToFind ft; ft.chrg.cpMin = minPos; ft.chrg.cpMax = maxPos; - wxWX2MBbuf buf = (wxWX2MBbuf)wx2stc(text); + const wxWX2MBbuf buf = wx2stc(text); ft.lpstrText = (char*)(const char*)buf; return SendMsg(2150, flags, (sptr_t)&ft); @@ -1708,8 +1708,8 @@ int wxStyledTextCtrl::GetTargetEnd() const // Returns the length of the replacement text. int wxStyledTextCtrl::ReplaceTarget(const wxString& text) { - wxWX2MBbuf buf = (wxWX2MBbuf)wx2stc(text); - return SendMsg(2194, strlen(buf), (sptr_t)(const char*)buf); + const wxWX2MBbuf buf = wx2stc(text); + return SendMsg(2194, wx2stclen(text, buf), (sptr_t)(const char*)buf); } // Replace the target text with the argument text after \d processing. @@ -1720,8 +1720,8 @@ int wxStyledTextCtrl::GetTargetEnd() const // caused by processing the \d patterns. int wxStyledTextCtrl::ReplaceTargetRE(const wxString& text) { - wxWX2MBbuf buf = (wxWX2MBbuf)wx2stc(text); - return SendMsg(2195, strlen(buf), (sptr_t)(const char*)buf); + const wxWX2MBbuf buf = wx2stc(text); + return SendMsg(2195, wx2stclen(text, buf), (sptr_t)(const char*)buf); } // Search for a counted string in the target and set the target to the found @@ -1729,8 +1729,8 @@ int wxStyledTextCtrl::GetTargetEnd() const // Returns length of range or -1 for failure in which case target is not moved. int wxStyledTextCtrl::SearchInTarget(const wxString& text) { - wxWX2MBbuf buf = (wxWX2MBbuf)wx2stc(text); - return SendMsg(2197, strlen(buf), (sptr_t)(const char*)buf); + const wxWX2MBbuf buf = wx2stc(text); + return SendMsg(2197, wx2stclen(text, buf), (sptr_t)(const char*)buf); } // Set the search flags used by SearchInTarget. @@ -1964,7 +1964,7 @@ void wxStyledTextCtrl::SetWrapVisualFlags(int wrapVisualFlags) SendMsg(2460, wrapVisualFlags, 0); } -// Retrieve the display mode of visual flags for wrapped lines. +// Retrive the display mode of visual flags for wrapped lines. int wxStyledTextCtrl::GetWrapVisualFlags() const { return SendMsg(2461, 0, 0); @@ -1976,7 +1976,7 @@ void wxStyledTextCtrl::SetWrapVisualFlagsLocation(int wrapVisualFlagsLocation) SendMsg(2462, wrapVisualFlagsLocation, 0); } -// Retrieve the location of visual flags for wrapped lines. +// Retrive the location of visual flags for wrapped lines. int wxStyledTextCtrl::GetWrapVisualFlagsLocation() const { return SendMsg(2463, 0, 0); @@ -1988,7 +1988,7 @@ void wxStyledTextCtrl::SetWrapStartIndent(int indent) SendMsg(2464, indent, 0); } -// Retrieve the start indent for wrapped lines. +// Retrive the start indent for wrapped lines. int wxStyledTextCtrl::GetWrapStartIndent() const { return SendMsg(2465, 0, 0); @@ -2085,8 +2085,8 @@ bool wxStyledTextCtrl::GetUseVerticalScrollBar() const // Append a string to the end of the document without changing the selection. void wxStyledTextCtrl::AppendText(const wxString& text) { - wxWX2MBbuf buf = (wxWX2MBbuf)wx2stc(text); - SendMsg(2282, strlen(buf), (sptr_t)(const char*)buf); + const wxWX2MBbuf buf = wx2stc(text); + SendMsg(2282, wx2stclen(text, buf), (sptr_t)(const char*)buf); } // Is drawing done in two phases with backgrounds drawn before foregrounds? @@ -4086,9 +4086,11 @@ bool wxStyledTextCtrl::GetUseAntiAliasing() { -void wxStyledTextCtrl::AddTextRaw(const char* text) +void wxStyledTextCtrl::AddTextRaw(const char* text, int length) { - SendMsg(SCI_ADDTEXT, strlen(text), (sptr_t)text); + if (length == -1) + length = strlen(text); + SendMsg(SCI_ADDTEXT, length, (sptr_t)text); } void wxStyledTextCtrl::InsertTextRaw(int pos, const char* text) @@ -4176,9 +4178,11 @@ wxCharBuffer wxStyledTextCtrl::GetTextRaw() return buf; } -void wxStyledTextCtrl::AppendTextRaw(const char* text) +void wxStyledTextCtrl::AppendTextRaw(const char* text, int length) { - SendMsg(SCI_APPENDTEXT, strlen(text), (sptr_t)text); + if (length == -1) + length = strlen(text); + SendMsg(SCI_APPENDTEXT, length, (sptr_t)text); } @@ -4264,18 +4268,24 @@ void wxStyledTextCtrl::OnContextMenu(wxContextMenuEvent& evt) { void wxStyledTextCtrl::OnMouseWheel(wxMouseEvent& evt) { - // prevent having an event queue with wheel events that cannot be processed - // reasonably fast (see ticket #9057) - if ( m_lastWheelTimestamp <= evt.GetTimestamp() ) + // Prevent having an event queue with wheel events that cannot be processed + // reasonably fast (see ticket #9057) by ignoring all of them that happen + // during the time interval corresponding to the time it took us to handle + // the last one. + // + // Notice the use of TimeInMicro() instead of Time() to avoid overflow in + // long running programs. + if ( m_timeToBlockWheelEventsUntil <= m_stopWatch.TimeInMicro() ) { - m_lastWheelTimestamp = m_stopWatch.Time(); + const wxLongLong beforeMouseWheel = m_stopWatch.TimeInMicro(); m_swx->DoMouseWheel(evt.GetWheelRotation(), evt.GetWheelDelta(), evt.GetLinesPerAction(), evt.ControlDown(), evt.IsPageScroll()); - m_lastWheelTimestamp = m_stopWatch.Time() - m_lastWheelTimestamp; - m_lastWheelTimestamp += evt.GetTimestamp(); + const wxLongLong afterMouseWheel = m_stopWatch.TimeInMicro(); + m_timeToBlockWheelEventsUntil = afterMouseWheel; + m_timeToBlockWheelEventsUntil += afterMouseWheel - beforeMouseWheel; } }