aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorNeil Hodgson <nyamatongwe@gmail.com>2014-07-15 12:04:54 +1000
committerNeil Hodgson <nyamatongwe@gmail.com>2014-07-15 12:04:54 +1000
commitbaf2d31068737bf24102cee6a7fed33e0d00d1f3 (patch)
treef814f1a39637d7711ab0ce709fef0b2468fbb270 /src
parent7b7865ca3062d57ebe990468a9275180f0d60569 (diff)
downloadscintilla-mirror-baf2d31068737bf24102cee6a7fed33e0d00d1f3.tar.gz
Implement separate timers for each type of periodic activity and turn them on and off
as required. This saves power as there are fewer wake ups. A tolerance value is provided so that platforms that support coalescing timers, Windows 8+ and OS X 10.9+, can use them. The previous global 100 millisecond timer may still be used by non-core platforms.
Diffstat (limited to 'src')
-rw-r--r--src/Editor.cxx124
-rw-r--r--src/Editor.h8
2 files changed, 126 insertions, 6 deletions
diff --git a/src/Editor.cxx b/src/Editor.cxx
index a23683698..361e82803 100644
--- a/src/Editor.cxx
+++ b/src/Editor.cxx
@@ -1311,16 +1311,26 @@ void Editor::ShowCaretAtCurrentPosition() {
if (hasFocus) {
caret.active = true;
caret.on = true;
- SetTicking(true);
+ if (FineTickerAvailable()) {
+ FineTickerCancel(tickCaret);
+ if (caret.period > 0)
+ FineTickerStart(tickCaret, caret.period, caret.period/10);
+ } else {
+ SetTicking(true);
+ }
} else {
caret.active = false;
caret.on = false;
+ if (FineTickerAvailable()) {
+ FineTickerCancel(tickCaret);
+ }
}
InvalidateCaret();
}
void Editor::DropCaret() {
caret.active = false;
+ FineTickerCancel(tickCaret);
InvalidateCaret();
}
@@ -1328,6 +1338,11 @@ void Editor::CaretSetPeriod(int period) {
if (caret.period != period) {
caret.period = period;
caret.on = true;
+ if (FineTickerAvailable()) {
+ FineTickerCancel(tickCaret);
+ if ((caret.active) && (caret.period > 0))
+ FineTickerStart(tickCaret, caret.period, caret.period/10);
+ }
InvalidateCaret();
}
}
@@ -1659,6 +1674,15 @@ void Editor::Paint(Surface *surfaceWindow, PRectangle rcArea) {
view.PaintText(surfaceWindow, rcArea, rcClient, *this, vs);
+ if (horizontalScrollBarVisible && trackLineWidth && (view.lineWidthMaxSeen > scrollWidth)) {
+ if (FineTickerAvailable()) {
+ scrollWidth = view.lineWidthMaxSeen;
+ if (!FineTickerRunning(tickWiden)) {
+ FineTickerStart(tickWiden, 50, 5);
+ }
+ }
+ }
+
NotifyPainted();
}
@@ -3809,7 +3833,13 @@ void Editor::SetDragPosition(SelectionPosition newPos) {
}
if (!(posDrag == newPos)) {
caret.on = true;
- SetTicking(true);
+ if (FineTickerAvailable()) {
+ FineTickerCancel(tickCaret);
+ if ((caret.active) && (caret.period > 0) && (newPos.Position() < 0))
+ FineTickerStart(tickCaret, caret.period, caret.period/10);
+ } else {
+ SetTicking(true);
+ }
InvalidateCaret();
posDrag = newPos;
InvalidateCaret();
@@ -4033,6 +4063,12 @@ void Editor::DwellEnd(bool mouseMoved) {
dwelling = false;
NotifyDwelling(ptMouseLast, dwelling);
}
+ if (FineTickerAvailable()) {
+ FineTickerCancel(tickDwell);
+ if (mouseMoved && (dwellDelay < SC_TIME_FOREVER)) {
+ //FineTickerStart(tickDwell, dwellDelay, dwellDelay/10);
+ }
+ }
}
void Editor::MouseLeave() {
@@ -4080,6 +4116,9 @@ void Editor::ButtonDownWithModifiers(Point pt, unsigned int curTime, int modifie
if (((curTime - lastClickTime) < Platform::DoubleClickTime()) && Close(pt, lastClick)) {
//Platform::DebugPrintf("Double click %d %d = %d\n", curTime, lastClickTime, curTime - lastClickTime);
SetMouseCapture(true);
+ if (FineTickerAvailable()) {
+ FineTickerStart(tickScroll, 100, 10);
+ }
if (!ctrl || !multipleSelection || (selectionType != selChar && selectionType != selWord))
SetEmptySelection(newPos.Position());
bool doubleClick = false;
@@ -4176,6 +4215,9 @@ void Editor::ButtonDownWithModifiers(Point pt, unsigned int curTime, int modifie
SetDragPosition(SelectionPosition(invalidPosition));
SetMouseCapture(true);
+ if (FineTickerAvailable()) {
+ FineTickerStart(tickScroll, 100, 10);
+ }
} else {
if (PointIsHotspot(pt)) {
NotifyHotSpotClicked(newCharPos.Position(), modifiers);
@@ -4188,6 +4230,9 @@ void Editor::ButtonDownWithModifiers(Point pt, unsigned int curTime, int modifie
inDragDrop = ddNone;
}
SetMouseCapture(true);
+ if (FineTickerAvailable()) {
+ FineTickerStart(tickScroll, 100, 10);
+ }
if (inDragDrop != ddInitial) {
SetDragPosition(SelectionPosition(invalidPosition));
if (!shift) {
@@ -4281,6 +4326,9 @@ void Editor::ButtonMoveWithModifiers(Point pt, int modifiers) {
if (inDragDrop == ddInitial) {
if (DragThreshold(ptMouseLast, pt)) {
SetMouseCapture(false);
+ if (FineTickerAvailable()) {
+ FineTickerCancel(tickScroll);
+ }
SetDragPosition(movePos);
CopySelectionRange(&drag);
StartDrag();
@@ -4289,6 +4337,12 @@ void Editor::ButtonMoveWithModifiers(Point pt, int modifiers) {
}
ptMouseLast = pt;
+ PRectangle rcClient = GetClientRectangle();
+ Point ptOrigin = GetVisibleOriginInMain();
+ rcClient.Move(0, -ptOrigin.y);
+ if (FineTickerAvailable() && (dwellDelay < SC_TIME_FOREVER) && rcClient.Contains(pt)) {
+ FineTickerStart(tickDwell, dwellDelay, dwellDelay/10);
+ }
//Platform::DebugPrintf("Move %d %d\n", pt.x, pt.y);
if (HaveMouseCapture()) {
@@ -4340,9 +4394,6 @@ void Editor::ButtonMoveWithModifiers(Point pt, int modifiers) {
}
// Autoscroll
- PRectangle rcClient = GetClientRectangle();
- Point ptOrigin = GetVisibleOriginInMain();
- rcClient.Move(0, -ptOrigin.y);
int lineMove = DisplayFromPosition(movePos.Position());
if (pt.y > rcClient.bottom) {
ScrollTo(lineMove - LinesOnScreen() + 1);
@@ -4414,6 +4465,9 @@ void Editor::ButtonUp(Point pt, unsigned int curTime, bool ctrl) {
}
ptMouseLast = pt;
SetMouseCapture(false);
+ if (FineTickerAvailable()) {
+ FineTickerCancel(tickScroll);
+ }
NotifyIndicatorClick(false, newPos.Position(), 0);
if (inDragDrop == ddDragging) {
SelectionPosition selStart = SelectionStart();
@@ -4530,6 +4584,66 @@ bool Editor::Idle() {
return !idleDone;
}
+void Editor::SetTicking(bool) {
+ // SetTicking is deprecated. In the past it was pure virtual and was overridden in each
+ // derived platform class but fine grained timers should now be implemented.
+ // Either way, execution should not arrive here so assert failure.
+ assert(false);
+}
+
+void Editor::TickFor(TickReason reason) {
+ switch (reason) {
+ case tickCaret:
+ caret.on = !caret.on;
+ if (caret.active) {
+ InvalidateCaret();
+ }
+ break;
+ case tickScroll:
+ // Auto scroll
+ ButtonMove(ptMouseLast);
+ break;
+ case tickWiden:
+ SetScrollBars();
+ FineTickerCancel(tickWiden);
+ break;
+ case tickDwell:
+ if ((!HaveMouseCapture()) &&
+ (ptMouseLast.y >= 0)) {
+ dwelling = true;
+ NotifyDwelling(ptMouseLast, dwelling);
+ }
+ FineTickerCancel(tickDwell);
+ break;
+ default:
+ // tickPlatform handled by subclass
+ break;
+ }
+}
+
+bool Editor::FineTickerAvailable() {
+ return false;
+}
+
+// FineTickerStart is be overridden by subclasses that support fine ticking so
+// this method should never be called.
+bool Editor::FineTickerRunning(TickReason) {
+ assert(false);
+ return false;
+}
+
+// FineTickerStart is be overridden by subclasses that support fine ticking so
+// this method should never be called.
+void Editor::FineTickerStart(TickReason, int, int) {
+ assert(false);
+}
+
+// FineTickerCancel is be overridden by subclasses that support fine ticking so
+// this method should never be called.
+void Editor::FineTickerCancel(TickReason) {
+ assert(false);
+}
+
void Editor::SetFocusState(bool focusState) {
hasFocus = focusState;
NotifyFocus(hasFocus);
diff --git a/src/Editor.h b/src/Editor.h
index 53da90906..d80292a0a 100644
--- a/src/Editor.h
+++ b/src/Editor.h
@@ -500,7 +500,13 @@ protected: // ScintillaBase subclass needs access to much of Editor
void Tick();
bool Idle();
- virtual void SetTicking(bool on) = 0;
+ virtual void SetTicking(bool on);
+ enum TickReason { tickCaret, tickScroll, tickWiden, tickDwell, tickPlatform };
+ virtual void TickFor(TickReason reason);
+ virtual bool FineTickerAvailable();
+ virtual bool FineTickerRunning(TickReason reason);
+ virtual void FineTickerStart(TickReason reason, int millis, int tolerance);
+ virtual void FineTickerCancel(TickReason reason);
virtual bool SetIdle(bool) { return false; }
virtual void SetMouseCapture(bool on) = 0;
virtual bool HaveMouseCapture() = 0;