////////////////////////////////////////////////////////////////////////////
-// 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
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
SetInitialSize(size);
// Reduces flicker on GTK+/X11
- SetBackgroundStyle(wxBG_STYLE_CUSTOM);
+ SetBackgroundStyle(wxBG_STYLE_PAINT);
// Make sure it can take the focus
SetCanFocus(true);
// 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.
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);
// 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.
// 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
// 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.
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);
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);
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);
// 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?
-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)
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);
}
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;
}
}