-------- Original Message --------
Subject: Re: [Lazarusdev] Re: [lazarus] [Fwd: TApplication.OnEndSession]
Date: Wed, 08 Mar 2006 18:34:42 +0100
From: Bogusław Brandys <[EMAIL PROTECTED]>
To: Marc Weustink <[EMAIL PROTECTED]>
References: <[EMAIL PROTECTED]> <[EMAIL PROTECTED]>
<[EMAIL PROTECTED]> <[EMAIL PROTECTED]>
<[EMAIL PROTECTED]> <[EMAIL PROTECTED]>
<[EMAIL PROTECTED]>
Marc Weustink wrote:
Vincent Snijders wrote:
I forward his answers.
Bogusław Brandys wrote:
Vincent Snijders wrote:
Micha Nelissen wrote:
Vincent Snijders wrote:
Note: do not call any modal dialog or long processing on this event
because system timeout message and shutdown itself even if Stop
:= true.
Ok is to set Stop:=true and show non-modal dialog
Wat is your opinion about this patch? Shall I apply it?
I'm ok with the event in general, but it's strange that a modal
dialog is not allowed. Are you sure you need to stop all shutdowns,
because the user *may* choose to cancel ?
It is allowed, but it will only work if the event returns fast
enough. If just showing the dailog and waiting for a response takes
longer than a couple of seconds, windows will close anyway. Bogusław
showed a hack: return Stop:=false;
That's all true.Modal dialog is allowed but only for a few seconds.
Maybe we shoud rethink the naming, currently: Stop:= true means that
the computer won't stop, because the shutdown is canceled.
Beter have a Cancel parameter, just like the OnClose
Ok.I will fix that (Cancel instead of Stop)
Also, why aren't there two events, OnEndSession, and
OnQueryEndSession ?
For me it's not a problem - I can add OnQueryEndSession, but as I
know under Unix/Linux that will be useless (how about MacOSX also ?)
- that's why only one event.
I don't think that is a problem. IIRC even on windows you can get a
EndSession without a QueryEnd.
Marc
But on Unix/Linux OnQueryEndSession would do nothing so why adding new
event if is not multiplatform ? What's wrong with one event with
parameter TEndKind ?
Fixed patch (Cancel instead of Stop) attached.
Regards
Bogusław Brandys
Index: forms.pp
===================================================================
--- forms.pp (revision 8890)
+++ forms.pp (working copy)
@@ -799,6 +799,8 @@
{ TApplication }
+ TEndKind = (seEnd,seQueryEnd);
+ TEndSessionEvent = procedure (Kind : TEndKind;var Cancel : Boolean) of
object;
TExceptionEvent = procedure (Sender: TObject; E: Exception) of object;
TIdleEvent = procedure (Sender: TObject; var Done: Boolean) of object;
TOnUserInputEvent = procedure(Sender: TObject; Msg: Cardinal) of object;
@@ -906,6 +908,7 @@
FOnHint: TNotifyEvent;
FOnIdle: TIdleEvent;
FOnIdleEnd: TNotifyEvent;
+ FOnEndSession : TEndSessionEvent;
FOnShortcut: TShortcutEvent;
FOnShowHint: TShowHintEvent;
FOnUserInput: TOnUserInputEvent;
@@ -1016,6 +1019,7 @@
procedure RemoveAllHandlersOfObject(AnObject: TObject); virtual;
procedure DoBeforeMouseMessage(CurMouseControl: TControl);
function IsShortcut(var Message: TLMKey): boolean;
+ procedure IntfEndSession(Kind : TEndKind; var Stop : Boolean);
public
procedure DoEscapeKey(AControl: TWinControl; var Key: Word;
Shift: TShiftState);
@@ -1042,6 +1046,7 @@
property OnDeactivate: TNotifyEvent read FOnDeactivate write FOnDeactivate;
property OnIdle: TIdleEvent read FOnIdle write FOnIdle;
property OnIdleEnd: TNotifyEvent read FOnIdleEnd write FOnIdleEnd;
+ property OnEndSession: TEndSessionEvent read FOnEndSession write
FOnEndSession;
property OnHelp: THelpEvent read FOnHelp write FOnHelp;
property OnHint: TNotifyEvent read FOnHint write FOnHint;
property OnShortcut: TShortcutEvent read FOnShortcut write FOnShortcut;
@@ -1077,6 +1082,7 @@
FOnHint: TNotifyEvent;
FOnShowHint: TShowHintEvent;
FOnUserInput: TOnUserInputEvent;
+ FOnEndSession : TEndSessionEvent;
procedure SetShowMainForm(const AValue: Boolean);
protected
Procedure SetCaptureExceptions(Const AValue : boolean);
@@ -1093,6 +1099,7 @@
Procedure SetOnException(Const AValue : TExceptionEvent);
Procedure SetOnIdle(Const AValue : TIdleEvent);
Procedure SetOnIdleEnd(Const AValue : TNotifyEvent);
+ Procedure SetOnEndSession(Const AValue : TEndSessionEvent);
Procedure SetOnHelp(Const AValue : THelpEvent);
Procedure SetOnHint(Const AValue : TNotifyEvent);
Procedure SetOnShowHint(Const AValue : TShowHintEvent);
@@ -1116,6 +1123,7 @@
property OnException: TExceptionEvent read FOnException write
SetOnException;
property OnIdle: TIdleEvent read FOnIdle write SetOnIdle;
property OnIdleEnd: TNotifyEvent read FOnIdleEnd write SetOnIdleEnd;
+ property OnEndSession : TEndSessionEvent read FOnEndSession write
SetOnEndSession;
property OnHelp: THelpEvent read FOnHelp write SetOnHelp;
property OnHint: TNotifyEvent read FOnHint write SetOnHint;
property OnShowHint: TShowHintEvent read FOnShowHint write SetOnShowHint;
@@ -1226,6 +1234,7 @@
function IsAccel(VK: word; const Str: string): Boolean;
procedure NotifyApplicationUserInput(Msg: Cardinal);
+
function InitResourceComponent(Instance: TComponent;
RootAncestor: TClass):Boolean;
Index: include/application.inc
===================================================================
--- include/application.inc (revision 8890)
+++ include/application.inc (working copy)
@@ -1378,6 +1378,17 @@
end;
{------------------------------------------------------------------------------
+ procedure TApplication.IntfEndSession(Kind : TEndKind; var Stop : Boolean);
+------------------------------------------------------------------------------}
+
+procedure TApplication.IntfEndSession(Kind : TEndKind; var Stop : Boolean);
+begin
+ if Assigned(FOnEndSession) then FOnEndSession(Kind,Stop);
+end;
+
+
+
+{------------------------------------------------------------------------------
procedure TApplication.DoBeforeMouseMessage(CurMouseControl: TControl);
------------------------------------------------------------------------------}
procedure TApplication.DoBeforeMouseMessage(CurMouseControl: TControl);
Index: include/applicationproperties.inc
===================================================================
--- include/applicationproperties.inc (revision 8890)
+++ include/applicationproperties.inc (working copy)
@@ -129,6 +129,16 @@
Application.OnIdleEnd := AValue;
end;
+
+Procedure TApplicationProperties.SetOnEndSession(Const AValue :
TEndSessionEvent);
+begin
+ FOnEndSession := AValue;
+
+ If not (csDesigning in ComponentState) then
+ Application.OnEndSession := AValue;
+end;
+
+
Procedure TApplicationProperties.SetOnHelp(Const AValue : THelpEvent);
begin
FOnHelp := AValue;
@@ -196,6 +206,7 @@
FOnHint := nil;
FOnShowHint := nil;
FOnUserInput := nil;
+ FOnEndSession := nil;
end;
// included by forms.pp
Index: interfaces/win32/win32callback.inc
===================================================================
--- interfaces/win32/win32callback.inc (revision 8890)
+++ interfaces/win32/win32callback.inc (working copy)
@@ -211,7 +211,8 @@
LMMove: TLMMove; // used by WM_MOVE
LMNotify: TLMNotify; // used by WM_NOTIFY
DrawListItemStruct: TDrawListItemStruct; //used by WM_DRAWITEM
-
+ EndStop : Boolean;//use by WM_QUERYENDSESSION
+
procedure ShowHideTabPage(NotebookHandle: HWnd; Showing: boolean);
var
NoteBook: TCustomNotebook;
@@ -1638,6 +1639,31 @@
// winxp theme changed, recheck whether themes are enabled
TWin32WidgetSet(WidgetSet).UpdateThemesActive;
end;
+
+ WM_ENDSESSION:
+ Begin
+ if (Application<>nil) and (TWin32WidgetSet(WidgetSet).AppHandle=Window)
and (WParam>0) and (LParam=0) then
+ begin
+ Result := 0;
+ EndStop := false;
+ Application.IntfEndSession(seEnd,EndStop);
+ Exit;
+ end;
+ End;
+
+ WM_QUERYENDSESSION:
+ Begin
+ if (Application<>nil) and (TWin32WidgetSet(WidgetSet).AppHandle=Window)
and (LParam=0) then
+ begin
+ EndStop := false;
+ Result := 1;
+ Application.IntfEndSession(seQueryEnd,EndStop);
+ if EndStop then Result := 0;
+ Exit;
+ end;
+ End;
+
+
{$ifdef PassWin32MessagesToLCL}
else
// pass along user defined messages
@@ -1648,7 +1674,8 @@
LMessage.LParam := LParam;
WinProcess := false;
end;
-{$endif}
+
+{$endif}
End;
If WinProcess Then