home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 September / Chip_2001-09_cd1.bin / zkuste / delphi / kolekce / d56 / RMCTL.ZIP / rmAppEvents.pas < prev    next >
Pascal/Delphi Source File  |  2001-06-22  |  7KB  |  241 lines

  1. {================================================================================
  2. Copyright (C) 1997-2001 Mills Enterprise
  3.  
  4. Unit     : rmAppEvents
  5. Purpose  : Originally a fix for D5 bug but is now usefull for other versions
  6.            of Delphi.
  7. Date     : 01-15-2000
  8. Author   : Ryan J. Mills
  9. Version  : 1.80
  10. ================================================================================}
  11.  
  12. unit rmAppEvents;
  13.  
  14. interface
  15.  
  16. {$I CompilerDefines.INC}
  17.  
  18. uses Windows, Messages, SysUtils, Classes, Forms, ActnList;
  19.  
  20. type
  21.   TrmCustomApplicationEvents = class(TComponent)
  22.   private
  23.     FOnActionExecute: TActionEvent;
  24.     FOnActionUpdate: TActionEvent;
  25.     FOnException: TExceptionEvent;
  26.     FOnMessage: TMessageEvent;
  27.     FOnHelp: THelpEvent;
  28.     FOnHint: TNotifyEvent;
  29.     FOnIdle: TIdleEvent;
  30.     FOnDeactivate: TNotifyEvent;
  31.     FOnActivate: TNotifyEvent;
  32.     FOnMinimize: TNotifyEvent;
  33.     FOnRestore: TNotifyEvent;
  34.     FOnShortCut: TShortCutEvent;
  35.     FOnShowHint: TShowHintEvent;
  36.     procedure DoActionExecute(Action: TBasicAction; var Handled: Boolean);
  37.     procedure DoActionUpdate(Action: TBasicAction; var Handled: Boolean);
  38.     procedure DoActivate(Sender: TObject);
  39.     procedure DoDeactivate(Sender: TObject);
  40.     procedure DoException(Sender: TObject; E: Exception);
  41.     procedure DoIdle(Sender: TObject; var Done: Boolean);
  42.     function DoHelp(Command: Word; Data: Longint; var CallHelp: Boolean): Boolean;
  43.     procedure DoHint(Sender: TObject);
  44.     procedure DoMessage(var Msg: TMsg; var Handled: Boolean);
  45.     procedure DoMinimize(Sender: TObject);
  46.     procedure DoRestore(Sender: TObject);
  47.     procedure DoShowHint(var HintStr: string; var CanShow: Boolean;
  48.       var HintInfo: THintInfo);
  49.     procedure DoShortcut(var Msg: TWMKey; var Handled: Boolean);
  50.   protected
  51.     property OnActionExecute: TActionEvent read FOnActionExecute write FOnActionExecute;
  52.     property OnActionUpdate: TActionEvent read FOnActionUpdate write FOnActionUpdate;
  53.     property OnActivate: TNotifyEvent read FOnActivate write FOnActivate;
  54.     property OnDeactivate: TNotifyEvent read FOnDeactivate write FOnDeactivate;
  55.     property OnException: TExceptionEvent read FOnException write FOnException;
  56.     property OnIdle: TIdleEvent read FOnIdle write FOnIdle;
  57.     property OnHelp: THelpEvent read FOnHelp write FOnHelp;
  58.     property OnHint: TNotifyEvent read FOnHint write FOnHint;
  59.     property OnMessage: TMessageEvent read FOnMessage write FOnMessage;
  60.     property OnMinimize: TNotifyEvent read FOnMinimize write FOnMinimize;
  61.     property OnRestore: TNotifyEvent read FOnRestore write FOnRestore;
  62.     property OnShowHint: TShowHintEvent read FOnShowHint write FOnShowHint;
  63.     property OnShortCut: TShortCutEvent read FOnShortCut write FOnShortCut;
  64.   public
  65.     constructor Create(AOwner: TComponent); override;
  66.     destructor Destroy; override;
  67.   end;
  68.  
  69.   TrmApplicationEvents = class(TrmCustomApplicationEvents)
  70.   published
  71.     property OnActionExecute;
  72.     property OnActionUpdate;
  73.     property OnActivate;
  74.     property OnDeactivate;
  75.     property OnException;
  76.     property OnIdle;
  77.     property OnHelp;
  78.     property OnHint;
  79.     property OnMessage;
  80.     property OnMinimize;
  81.     property OnRestore;
  82.     property OnShowHint;
  83.     property OnShortCut;
  84.   end;
  85.  
  86. implementation
  87.  
  88. uses Contnrs, Consts, StdActns;
  89.  
  90. { TrmCustomApplicationEvents }
  91.  
  92. constructor TrmCustomApplicationEvents.Create(AOwner: TComponent);
  93. begin
  94.   inherited Create(AOwner);
  95.  
  96.   if csdesigning in componentstate then
  97.      exit;
  98.  
  99.   with Application do
  100.   begin
  101.     OnActionExecute := DoActionExecute;
  102.     OnActionUpdate := DoActionUpdate;
  103.     OnActivate := DoActivate;
  104.     OnDeactivate := DoDeactivate;
  105.     OnException := DoException;
  106.     OnHelp := DoHelp;
  107.     OnHint := DoHint;
  108.     OnIdle := DoIdle;
  109.     OnMessage := DoMessage;
  110.     OnMinimize := DoMinimize;
  111.     OnRestore := DoRestore;
  112.     OnShowHint := DoShowHint;
  113.     OnShortCut := DoShortcut;
  114.   end;
  115.  
  116. end;
  117.  
  118. destructor TrmCustomApplicationEvents.Destroy;
  119. begin
  120.   with Application do
  121.   begin
  122.     OnActionExecute := nil;
  123.     OnActionUpdate := nil;
  124.     OnActivate := nil;
  125.     OnDeactivate := nil;
  126.     OnException := nil;
  127.     OnHelp := nil;
  128.     OnHint := nil;
  129.     OnIdle := nil;
  130.     OnMessage := nil;
  131.     OnMinimize := nil;
  132.     OnRestore := nil;
  133.     OnShowHint := nil;
  134.     OnShortCut := nil;
  135.   end;
  136.  
  137.   inherited;
  138. end;
  139.  
  140. procedure TrmCustomApplicationEvents.DoActionExecute(Action: TBasicAction;
  141.   var Handled: Boolean);
  142. begin
  143.   if Assigned(FOnActionExecute) then
  144.      FOnActionExecute(Action, Handled);
  145. end;
  146.  
  147. procedure TrmCustomApplicationEvents.DoActionUpdate(Action: TBasicAction;
  148.   var Handled: Boolean);
  149. begin
  150.   if Assigned(FOnActionUpdate) then
  151.      FOnActionUpdate(Action, Handled);
  152. end;
  153.  
  154. procedure TrmCustomApplicationEvents.DoActivate(Sender: TObject);
  155. begin
  156.   if Assigned(FOnActivate) then
  157.      FOnActivate(Sender);
  158. end;
  159.  
  160. procedure TrmCustomApplicationEvents.DoDeactivate(Sender: TObject);
  161. begin
  162.   if Assigned(FOnDeactivate) then FOnDeactivate(Sender);
  163. end;
  164.  
  165. procedure TrmCustomApplicationEvents.DoException(Sender: TObject;
  166.   E: Exception);
  167. begin
  168.   if Assigned(FOnException) then
  169.      FOnException(Sender, E)
  170.   else
  171.      Application.ShowException(E);
  172. end;
  173.  
  174. function TrmCustomApplicationEvents.DoHelp(Command: Word; Data: Integer;
  175.   var CallHelp: Boolean): Boolean;
  176. begin
  177.   if Assigned(FOnHelp) then
  178.     Result := FOnHelp(Command, Data, CallHelp)
  179.   else
  180.     Result := False;  
  181. end;
  182.  
  183. procedure TrmCustomApplicationEvents.DoHint(Sender: TObject);
  184. begin
  185.   if Assigned(FOnHint) then
  186.      FOnHint(Sender)
  187. {$IFDEF D4_OR_HIGHER}
  188.   else
  189.   { Fire THintAction to anyone interested }
  190.   with THintAction.Create(Self) do
  191.   begin
  192.     Hint := Application.hint;
  193.     try
  194.       Execute;
  195.     finally
  196.       Free;
  197.     end;
  198.   end;
  199. {$ENDIF}
  200. end;
  201.  
  202. procedure TrmCustomApplicationEvents.DoIdle(Sender: TObject; var Done: Boolean);
  203. begin
  204.   if Assigned(FOnIdle) then
  205.      FOnIdle(Sender, Done);
  206. end;
  207.  
  208. procedure TrmCustomApplicationEvents.DoMessage(var Msg: TMsg; var Handled: Boolean);
  209. begin
  210.   if Assigned(FOnMessage) then
  211.      FOnMessage(Msg, Handled);
  212. end;
  213.  
  214. procedure TrmCustomApplicationEvents.DoMinimize(Sender: TObject);
  215. begin
  216.   if Assigned(FOnMinimize) then
  217.      FOnMinimize(Sender);
  218. end;
  219.  
  220. procedure TrmCustomApplicationEvents.DoRestore(Sender: TObject);
  221. begin
  222.   if Assigned(FOnRestore) then
  223.      FOnRestore(Sender);
  224. end;
  225.  
  226. procedure TrmCustomApplicationEvents.DoShortcut(var Msg: TWMKey;
  227.   var Handled: Boolean);
  228. begin
  229.   if Assigned(FOnShortcut) then
  230.      FOnShortcut(Msg, Handled);
  231. end;
  232.  
  233. procedure TrmCustomApplicationEvents.DoShowHint(var HintStr: string;
  234.   var CanShow: Boolean; var HintInfo: THintInfo);
  235. begin
  236.   if Assigned(FOnShowHint) then
  237.      FOnShowHint(HintStr, CanShow, HintInfo);
  238. end;
  239.  
  240. end.
  241.