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.
const wxColour& background) {
SendMsg(2040, markerNumber, markerSymbol);
- if (foreground.Ok())
+ if (foreground.IsOk())
MarkerSetForeground(markerNumber, foreground);
- if (background.Ok())
+ if (background.IsOk())
MarkerSetBackground(markerNumber, background);
}
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);
// Retrieve the selected text.
wxString wxStyledTextCtrl::GetSelectedText() {
- long start;
- long end;
-
- GetSelection(&start, &end);
- int len = end - start;
+ const int len = SendMsg(SCI_GETSELTEXT, 0, (sptr_t)0);
if (!len) return wxEmptyString;
wxMemoryBuffer mbuf(len+2);
// 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.
// 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)
wxCharBuffer wxStyledTextCtrl::GetSelectedTextRaw()
{
- long start;
- long end;
-
- GetSelection(&start, &end);
- int len = end - start;
- if (!len) {
- wxCharBuffer empty;
- return empty;
- }
+ // Calculate the length needed first.
+ const int len = SendMsg(SCI_GETSELTEXT, 0, (sptr_t)0);
+ // And then really get the data.
wxCharBuffer buf(len);
SendMsg(SCI_GETSELTEXT, 0, (sptr_t)buf.data());
return buf;
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;
}
}
/*static*/ wxVersionInfo wxStyledTextCtrl::GetLibraryVersionInfo()
{
- return wxVersionInfo("Scintilla", 2, 3);
+ return wxVersionInfo("Scintilla", 2, 3, 0, "Scintilla 2.03");
}
#endif // wxUSE_STC