Skip to content

Commit

Permalink
Add Scintilla FineTicker methods to wxSTC
Browse files Browse the repository at this point in the history
Starting with version 3.5, Scintilla implemented a newer method for
handling timers and used this method in its Windows, GTK+, Cocoa, and Qt
ports. This patch attempts to bring the timer handling for wxSTC in line
with those other ports.

Closes #17949.
  • Loading branch information
New Pagodi authored and a-wi committed Sep 17, 2017
1 parent 6c01707 commit 33ad806
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 27 deletions.
1 change: 1 addition & 0 deletions docs/changes.txt
Expand Up @@ -155,6 +155,7 @@ All (GUI):
- Never restore size smaller than the best one in wxPersistentTLW.
- Fix escaping/unescaping characters in wxLongStringProperty in wxPG (mikek).
- Ensure that navigation order reflects layout of wxStdDialogButtonSizer.
- Add Scintilla FineTicker methods to wxSTC (NewPagodi).

wxGTK:

Expand Down
67 changes: 43 additions & 24 deletions src/stc/ScintillaWX.cpp
Expand Up @@ -56,16 +56,18 @@

class wxSTCTimer : public wxTimer {
public:
wxSTCTimer(ScintillaWX* swx) {
wxSTCTimer(ScintillaWX* swx, ScintillaWX::TickReason reason) {
m_swx = swx;
m_reason = reason;
}

void Notify() wxOVERRIDE {
m_swx->DoTick();
m_swx->TickFor(m_reason);
}

private:
ScintillaWX* m_swx;
ScintillaWX::TickReason m_reason;
};


Expand Down Expand Up @@ -263,10 +265,19 @@ ScintillaWX::ScintillaWX(wxStyledTextCtrl* win) {
#endif
#endif // wxHAVE_STC_RECT_FORMAT

//A timer is needed for each member of TickReason enum except tickPlatform
timers[tickCaret] = new wxSTCTimer(this,tickCaret);
timers[tickScroll] = new wxSTCTimer(this,tickScroll);
timers[tickWiden] = new wxSTCTimer(this,tickWiden);
timers[tickDwell] = new wxSTCTimer(this,tickDwell);
}


ScintillaWX::~ScintillaWX() {
for ( TimersHash::iterator i=timers.begin(); i!=timers.end(); ++i ) {
delete i->second;
}
timers.clear();
Finalise();
}

Expand Down Expand Up @@ -306,7 +317,6 @@ void ScintillaWX::Initialise() {

void ScintillaWX::Finalise() {
ScintillaBase::Finalise();
SetTicking(false);
SetIdle(false);
DestroySystemCaret();
}
Expand Down Expand Up @@ -357,25 +367,6 @@ bool ScintillaWX::SetIdle(bool on) {
}


void ScintillaWX::SetTicking(bool on) {
wxSTCTimer* steTimer;
if (timer.ticking != on) {
timer.ticking = on;
if (timer.ticking) {
steTimer = new wxSTCTimer(this);
steTimer->Start(timer.tickSize);
timer.tickerID = steTimer;
} else {
steTimer = (wxSTCTimer*)timer.tickerID;
steTimer->Stop();
delete steTimer;
timer.tickerID = 0;
}
}
timer.ticksToWait = caret.period;
}


void ScintillaWX::SetMouseCapture(bool on) {
if (mouseDownCaptures) {
if (on && !capturedMouse)
Expand Down Expand Up @@ -741,6 +732,36 @@ bool ScintillaWX::DestroySystemCaret() {
#endif
}

bool ScintillaWX::FineTickerAvailable() {
return true;
}

bool ScintillaWX::FineTickerRunning(TickReason reason) {
bool running = false;
TimersHash::iterator i = timers.find(reason);
wxASSERT_MSG( i != timers.end(), "At least one TickReason is missing a timer.");
if ( i != timers.end() ) {
running = i->second->IsRunning();
}
return running;
}

void ScintillaWX::FineTickerStart(TickReason reason, int millis,
int WXUNUSED(tolerance)) {
TimersHash::iterator i = timers.find(reason);
wxASSERT_MSG( i != timers.end(), "At least one TickReason is missing a timer." );
if ( i != timers.end() ) {
i->second->Start(millis);
}
}

void ScintillaWX::FineTickerCancel(TickReason reason) {
TimersHash::iterator i = timers.find(reason);
wxASSERT_MSG( i != timers.end(), "At least one TickReason is missing a timer." );
if ( i != timers.end() ) {
i->second->Stop();
}
}

//----------------------------------------------------------------------

Expand Down Expand Up @@ -971,7 +992,6 @@ void ScintillaWX::DoLoseFocus(){
SetFocusState(false);
focusEvent = false;
DestroySystemCaret();
SetTicking(false);
}

void ScintillaWX::DoGainFocus(){
Expand All @@ -980,7 +1000,6 @@ void ScintillaWX::DoGainFocus(){
focusEvent = false;
DestroySystemCaret();
CreateSystemCaret();
SetTicking(true);
}

void ScintillaWX::DoSysColourChange() {
Expand Down
12 changes: 9 additions & 3 deletions src/stc/ScintillaWX.h
Expand Up @@ -86,7 +86,7 @@
class WXDLLIMPEXP_FWD_CORE wxDC;
class WXDLLIMPEXP_FWD_STC wxStyledTextCtrl; // forward
class ScintillaWX;

class wxSTCTimer;

//----------------------------------------------------------------------
// Helper classes
Expand Down Expand Up @@ -121,7 +121,6 @@ class ScintillaWX : public ScintillaBase {
virtual void Finalise() wxOVERRIDE;
virtual void StartDrag() wxOVERRIDE;
virtual bool SetIdle(bool on) wxOVERRIDE;
virtual void SetTicking(bool on) wxOVERRIDE;
virtual void SetMouseCapture(bool on) wxOVERRIDE;
virtual bool HaveMouseCapture() wxOVERRIDE;
virtual void ScrollText(int linesToMove) wxOVERRIDE;
Expand Down Expand Up @@ -149,6 +148,10 @@ class ScintillaWX : public ScintillaBase {
virtual void CancelModes() wxOVERRIDE;

virtual void UpdateSystemCaret() wxOVERRIDE;
virtual bool FineTickerAvailable() wxOVERRIDE;
virtual bool FineTickerRunning(TickReason reason) wxOVERRIDE;
virtual void FineTickerStart(TickReason reason, int millis, int tolerance) wxOVERRIDE;
virtual void FineTickerCancel(TickReason reason) wxOVERRIDE;

// Event delegates
void DoPaint(wxDC* dc, wxRect rect);
Expand All @@ -168,7 +171,6 @@ class ScintillaWX : public ScintillaBase {
bool ctrlDown, bool isPageScroll);
void DoAddChar(int key);
int DoKeyDown(const wxKeyEvent& event, bool* consumed);
void DoTick() { Tick(); }
void DoOnIdle(wxIdleEvent& evt);

#if wxUSE_DRAG_AND_DROP
Expand Down Expand Up @@ -199,6 +201,9 @@ class ScintillaWX : public ScintillaBase {
bool focusEvent;
wxStyledTextCtrl* stc;

WX_DECLARE_HASH_MAP(TickReason, wxSTCTimer*, wxIntegerHash, wxIntegerEqual, TimersHash);
TimersHash timers;

#if wxUSE_DRAG_AND_DROP
wxSTCDropTarget* dropTarget;
wxDragResult dragResult;
Expand Down Expand Up @@ -227,6 +232,7 @@ class ScintillaWX : public ScintillaBase {
#endif

friend class wxSTCCallTip;
friend class wxSTCTimer; // To get access to TickReason declaration
};

//----------------------------------------------------------------------
Expand Down

0 comments on commit 33ad806

Please sign in to comment.