LCL: TIdleTimer: added property FireOnIdle for idle functions that work in several chunks

git-svn-id: trunk@19389 -
This commit is contained in:
mattias 2009-04-12 22:57:42 +00:00
parent 39dabdaf5d
commit 8704259100
2 changed files with 22 additions and 19 deletions

View File

@ -325,7 +325,16 @@ type
end;
{ TIdleTimer }
{ TIdleTimer
For example:
Do something after 2 seconds after user input and idle.
AutoEnabled:=true;
AutoStartEvent:=[itaOnIdle]; // start the timer on first idle
AutoEndEvent:=[itaOnUserInput]; // end on any user input
If the OnTimer event works in several chunks, set FireOnIdle:=true.
The OnTimer event will then be called on idle until FireOnIdle is false.
FireOnIdle is set to false on any user input. }
TIdleTimerAutoEvent = (
itaOnIdle,
@ -334,15 +343,16 @@ type
);
TIdleTimerAutoEvents = set of TIdleTimerAutoEvent;
{ TCustomIdleTimer }
TCustomIdleTimer = class(TCustomTimer)
private
FAutoEnabled: boolean;
FAutoEndEvent: TIdleTimerAutoEvent;
FAutoStartEvent: TIdleTimerAutoEvent;
FFireOnIdle: boolean;
FHandlersConnected: boolean;
procedure UpdateHandlers;
procedure SetAutoEndEvent(const AValue: TIdleTimerAutoEvent);
procedure SetAutoStartEvent(const AValue: TIdleTimerAutoEvent);
protected
procedure SetAutoEnabled(const AValue: boolean); virtual;
procedure DoOnIdle(Sender: TObject; var Done: Boolean); virtual;
@ -354,11 +364,12 @@ type
destructor Destroy; override;
property AutoEnabled: boolean read FAutoEnabled
write SetAutoEnabled default False;
write SetAutoEnabled default False;
property AutoStartEvent: TIdleTimerAutoEvent read FAutoStartEvent
write SetAutoStartEvent default itaOnIdle;
write FAutoStartEvent default itaOnIdle;
property AutoEndEvent: TIdleTimerAutoEvent read FAutoEndEvent
write SetAutoEndEvent default itaOnUserInput;
write FAutoEndEvent default itaOnUserInput;
property FireOnIdle: boolean read FFireOnIdle write FFireOnIdle default false;
end;
TIdleTimer = class(TCustomIdleTimer)

View File

@ -36,6 +36,10 @@ begin
Enabled:=false;
if AutoStartEvent=itaOnIdle then
Enabled:=true;
if FFireOnIdle then begin
DoOnTimer;
Done:=not FFireOnIdle;
end;
end;
procedure TCustomIdleTimer.DoOnIdleEnd(Sender: TObject);
@ -50,6 +54,7 @@ end;
procedure TCustomIdleTimer.DoOnUserInput(Sender: TObject; Msg: Cardinal);
begin
FireOnIdle:=false;
if not AutoEnabled then exit;
// automatic start, stop or restart
if AutoEndEvent=itaOnUserInput then
@ -98,17 +103,4 @@ begin
end;
end;
procedure TCustomIdleTimer.SetAutoEndEvent(const AValue: TIdleTimerAutoEvent);
begin
if FAutoEndEvent=AValue then exit;
FAutoEndEvent:=AValue;
end;
procedure TCustomIdleTimer.SetAutoStartEvent(const AValue: TIdleTimerAutoEvent);
begin
if FAutoStartEvent=AValue then exit;
FAutoStartEvent:=AValue;
end;
// included by extctrls.pp