📄 jvappevent.pas
字号:
{-----------------------------------------------------------------------------
The contents of this file are subject to the Mozilla Public License
Version 1.1 (the "License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL/MPL-1.1.html
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either expressed or implied. See the License for
the specific language governing rights and limitations under the License.
The Original Code is: JvAppEvent.PAS, released on 2002-07-04.
The Initial Developers of the Original Code are: Fedor Koshevnikov, Igor Pavluk and Serge Korolev
Copyright (c) 1997, 1998 Fedor Koshevnikov, Igor Pavluk and Serge Korolev
Copyright (c) 2001,2002 SGB Software
All Rights Reserved.
Contributor(s):
Hofi
Last Modified: 2004-10-07
Changes:
2004-10-07:
* Added by Hofi
TJvAppEvents
property CancelDispatch
gives a chance to break event dispatching in a particular event handler.
You may retrieve the latest version of this file at the Project JEDI's JVCL home page,
located at http://jvcl.sourceforge.net
Known Issues:
-----------------------------------------------------------------------------}
// $Id: JvAppEvent.pas,v 1.25 2005/02/17 10:19:58 marquardt Exp $
unit JvAppEvent;
{$I jvcl.inc}
interface
uses
{$IFDEF UNITVERSIONING}
JclUnitVersioning,
{$ENDIF UNITVERSIONING}
Windows, Messages,
{$IFDEF VisualCLX}
Qt,
{$ENDIF VisualCLX}
SysUtils, Classes, Controls, Graphics, Forms, ActnList,
JvTypes, JvComponent;
const
DefHintColor = clInfoBk;
DefHintPause = 500;
DefHintShortPause = DefHintPause div 10;
DefHintHidePause = DefHintPause * 5;
{$IFDEF VisualCLX}
type
{ short names }
TUIEffect = ( General, AnimateMenu, FadeMenu, AnimateCombo, AnimateTooltip, FadeTooltip );
TUIEffects = set of TUIEffect;
{$ENDIF VisualCLX}
type
TJvAppEvents = class(TJvComponent)
private
FChained: Boolean;
FHintColor: TColor;
FHintPause: Integer;
FShowHint: Boolean;
FCanvas: TCanvas;
FUpdateFormatSettings: Boolean;
FCancelDispatch: Boolean;
FHintShortPause: Integer;
FHintHidePause: Integer;
FShowMainForm: Boolean;
FHintShortCuts: Boolean;
FMouseDragImmediate: Boolean;
FMouseDragThreshold: Integer;
FOnActionExecute: TActionEvent;
FOnActionUpdate: TActionEvent;
FOnShortCut: TShortCutEvent;
{$IFDEF VCL}
FUpdateMetricSettings: Boolean;
FBiDiMode: TBiDiMode;
FBiDiKeyboard: string;
FNonBiDiKeyboard: string;
{$ENDIF VCL}
FOnPaintIcon: TNotifyEvent;
FOnActivate: TNotifyEvent;
FOnDeactivate: TNotifyEvent;
FOnException: TExceptionEvent;
FOnIdle: TIdleEvent;
FOnHelp: THelpEvent;
FOnHint: TNotifyEvent;
{$IFDEF VCL}
FOnMessage: TMessageEvent;
{$ENDIF VCL}
{$IFDEF VisualCLX}
FOnEvent: TEventEvent;
{$ENDIF VisualCLX}
FOnMinimize: TNotifyEvent;
FOnRestore: TNotifyEvent;
FOnShowHint: TShowHintEvent;
{$IFDEF VCL}
FOnSettingsChanged: TNotifyEvent;
{$ENDIF VCL}
FOnActiveControlChange: TNotifyEvent;
FOnActiveFormChange: TNotifyEvent;
procedure UpdateAppProps;
function GetCanvas: TCanvas;
function GetHintColor: TColor;
function GetHintPause: Integer;
function GetShowHint: Boolean;
procedure SetHintColor(Value: TColor);
procedure SetHintPause(Value: Integer);
procedure SetShowHint(Value: Boolean);
function GetUpdateFormatSettings: Boolean;
procedure SetUpdateFormatSettings(Value: Boolean);
function GetHintShortPause: Integer;
function GetHintHidePause: Integer;
function GetShowMainForm: Boolean;
procedure SetHintShortPause(Value: Integer);
procedure SetHintHidePause(Value: Integer);
procedure SetShowMainForm(Value: Boolean);
function GetHintShortCuts: Boolean;
procedure SetHintShortCuts(Value: Boolean);
function GetMouseDragImmediate: Boolean;
function GetMouseDragThreshold: Integer;
procedure SetMouseDragImmediate(Value: Boolean);
procedure SetMouseDragThreshold(Value: Integer);
{$IFDEF VCL}
function GetUpdateMetricSettings: Boolean;
procedure SetUpdateMetricSettings(Value: Boolean);
function GetBiDiMode: TBiDiMode;
procedure SetBiDiMode(Value: TBiDiMode);
function GetBiDiKeyboard: string;
function GetNonBiDiKeyboard: string;
procedure SetBiDiKeyboard(const Value: string);
procedure SetNonBiDiKeyboard(const Value: string);
{$ENDIF VCL}
{$IFDEF VisualCLX}
function GetEffects: TUIEffects;
function GetHintFont: TFont;
procedure SetEffects(Value: TUIEffects);
procedure SetHintFont(Value: TFont);
{$ENDIF VisualCLX}
protected
procedure Loaded; override;
{$IFDEF VCL}
procedure PaintIcon; virtual;
procedure SettingsChanged; dynamic;
function MessageHook(var Msg: TMessage): Boolean; virtual;
{$ENDIF VCL}
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
property Canvas: TCanvas read GetCanvas; { for painting the icon }
procedure CancelDispatch;
published
property Chained: Boolean read FChained write FChained default True;
property HintColor: TColor read GetHintColor write SetHintColor default DefHintColor;
{$IFDEF VisualCLX}
property HintFont: TFont read GetHintFont write SetHintFont;
{$ENDIF VisualCLX}
property HintPause: Integer read GetHintPause write SetHintPause default DefHintPause;
property ShowHint: Boolean read GetShowHint write SetShowHint default True;
property UpdateFormatSettings: Boolean read GetUpdateFormatSettings
write SetUpdateFormatSettings default True;
property HintShortPause: Integer read GetHintShortPause write SetHintShortPause
default DefHintShortPause;
property HintHidePause: Integer read GetHintHidePause write SetHintHidePause
default DefHintHidePause;
property ShowMainForm: Boolean read GetShowMainForm write SetShowMainForm
default True;
property HintShortCuts: Boolean read GetHintShortCuts write SetHintShortCuts
default True;
{$IFDEF VisualCLX}
property Effects: TUIEffects read GetEffects write SetEffects;
{$ENDIF VisualCLX}
{$IFDEF VCL}
property UpdateMetricSettings: Boolean read GetUpdateMetricSettings
write SetUpdateMetricSettings default True;
property BiDiMode: TBiDiMode read GetBiDiMode write SetBiDiMode
default bdLeftToRight;
property BiDiKeyboard: string read GetBiDiKeyboard write SetBiDiKeyboard;
property NonBiDiKeyboard: string read GetNonBiDiKeyboard write SetNonBiDiKeyboard;
{$ENDIF VCL}
property MouseDragImmediate: Boolean read GetMouseDragImmediate
write SetMouseDragImmediate default True;
property MouseDragThreshold: Integer read GetMouseDragThreshold
write SetMouseDragThreshold default 5;
property OnActionExecute: TActionEvent read FOnActionExecute write FOnActionExecute;
property OnActionUpdate: TActionEvent read FOnActionUpdate write FOnActionUpdate;
property OnShortCut: TShortCutEvent read FOnShortCut write FOnShortCut;
property OnActivate: TNotifyEvent read FOnActivate write FOnActivate;
property OnDeactivate: TNotifyEvent read FOnDeactivate write FOnDeactivate;
property OnException: TExceptionEvent read FOnException write FOnException;
property OnIdle: TIdleEvent read FOnIdle write FOnIdle;
property OnHelp: THelpEvent read FOnHelp write FOnHelp;
property OnHint: TNotifyEvent read FOnHint write FOnHint;
property OnMinimize: TNotifyEvent read FOnMinimize write FOnMinimize;
property OnPaintIcon: TNotifyEvent read FOnPaintIcon write FOnPaintIcon;
property OnRestore: TNotifyEvent read FOnRestore write FOnRestore;
property OnShowHint: TShowHintEvent read FOnShowHint write FOnShowHint;
{$IFDEF VCL}
property OnMessage: TMessageEvent read FOnMessage write FOnMessage;
property OnSettingsChanged: TNotifyEvent read FOnSettingsChanged write FOnSettingsChanged;
{$ENDIF VCL}
property OnActiveControlChange: TNotifyEvent read FOnActiveControlChange write FOnActiveControlChange;
property OnActiveFormChange: TNotifyEvent read FOnActiveFormChange write FOnActiveFormChange;
{$IFDEF VisualCLX}
property OnEvent: TEventEvent read FOnEvent write FOnEvent;
{$ENDIF VisualCLX}
end;
{$IFDEF UNITVERSIONING}
const
UnitVersioning: TUnitVersionInfo = (
RCSfile: '$RCSfile: JvAppEvent.pas,v $';
Revision: '$Revision: 1.25 $';
Date: '$Date: 2005/02/17 10:19:58 $';
LogPath: 'JVCL\run'
);
{$ENDIF UNITVERSIONING}
implementation
type
TJvAppEventList = class(TObject)
private
FAppEvents: TList;
FHooked: Boolean;
FOnActivate: TNotifyEvent;
FOnDeactivate: TNotifyEvent;
FOnException: TExceptionEvent;
FOnIdle: TIdleEvent;
FOnHelp: THelpEvent;
FOnHint: TNotifyEvent;
{$IFDEF VCL}
FOnMessage: TMessageEvent;
{$ENDIF VCL}
{$IFDEF VisualCLX}
FOnEvent: TEventEvent;
{$ENDIF VisualCLX}
FOnMinimize: TNotifyEvent;
FOnRestore: TNotifyEvent;
FOnShowHint: TShowHintEvent;
FOnActiveControlChange: TNotifyEvent;
FOnActiveFormChange: TNotifyEvent;
FOnActionExecute: TActionEvent;
FOnActionUpdate: TActionEvent;
FOnShortCut: TShortCutEvent;
procedure AddEvents(App: TJvAppEvents);
procedure RemoveEvents(App: TJvAppEvents);
procedure ClearEvents;
protected
procedure DoActivate(Sender: TObject);
procedure DoDeactivate(Sender: TObject);
procedure DoException(Sender: TObject; E: Exception);
procedure DoIdle(Sender: TObject; var Done: Boolean);
procedure DoHint(Sender: TObject);
procedure DoMinimize(Sender: TObject);
procedure DoRestore(Sender: TObject);
{$IFDEF VCL}
function DoHelp(Command: Word; Data: Longint;
var CallHelp: Boolean): Boolean;
procedure DoMessage(var Msg: TMsg; var Handled: Boolean);
procedure DoShortCut(var Msg: TWMKey; var Handled: Boolean);
{$ENDIF VCL}
{$IFDEF VisualCLX}
function DoHelp(HelpType: THelpType; HelpContext: THelpContext;
const HelpKeyword: string; const HelpFile: string;
var Handled: Boolean): Boolean;
procedure DoShortCut(Key: Integer; Shift: TShiftState; var Handled: Boolean);
procedure DoEvent(Sender: QObjectH; Event: QEventH; var Handled: Boolean);
{$ENDIF VisualCLX}
procedure DoShowHint(var HintStr: THintString; var CanShow: Boolean;
var HintInfo: THintInfo);
procedure DoActiveControlChange(Sender: TObject);
procedure DoActiveFormChange(Sender: TObject);
procedure DoActionExecute(Action: TBasicAction; var Handled: Boolean);
procedure DoActionUpdate(Action: TBasicAction; var Handled: Boolean);
public
constructor Create;
destructor Destroy; override;
end;
//=== { TJvAppEventList } ====================================================
constructor TJvAppEventList.Create;
begin
inherited Create;
FAppEvents := TList.Create;
end;
destructor TJvAppEventList.Destroy;
begin
ClearEvents;
FAppEvents.Free;
inherited Destroy;
end;
procedure TJvAppEventList.ClearEvents;
begin
if FHooked then
begin
Application.OnActivate := nil;
Application.OnDeactivate := nil;
Application.OnException := nil;
{$IFDEF VisualCLX}
Application.OnEvent := nil;
{$ENDIF VisualCLX}
Application.OnIdle := nil;
Application.OnHelp := nil;
Application.OnHint := nil;
{$IFDEF VCL}
Application.OnMessage := nil;
{$ENDIF VCL}
Application.OnMinimize := nil;
Application.OnRestore := nil;
Application.OnShowHint := nil;
Application.OnActionExecute := nil;
Application.OnActionUpdate := nil;
Application.OnShortCut := nil;
if Screen <> nil then
begin
Screen.OnActiveControlChange := nil;
Screen.OnActiveFormChange := nil;
end;
end;
end;
procedure TJvAppEventList.AddEvents(App: TJvAppEvents);
begin
if (App <> nil) and (FAppEvents.IndexOf(App) = -1) then
begin
FAppEvents.Add(App);
if not (csDesigning in App.ComponentState) and (FAppEvents.Count = 1) then
begin
FOnActivate := Application.OnActivate;
FOnDeactivate := Application.OnDeactivate;
FOnException := Application.OnException;
FOnIdle := Application.OnIdle;
FOnHelp := Application.OnHelp;
FOnHint := Application.OnHint;
{$IFDEF VCL}
FOnMessage := Application.OnMessage;
{$ENDIF VCL}
{$IFDEF VisualCLX}
FOnEvent := Application.OnEvent;
{$ENDIF VisualCLX}
FOnMinimize := Application.OnMinimize;
FOnRestore := Application.OnRestore;
FOnShowHint := Application.OnShowHint;
FOnActionExecute := Application.OnActionExecute;
FOnActionUpdate := Application.OnActionUpdate;
FOnShortCut := Application.OnShortCut;
Application.OnActionExecute := DoActionExecute;
Application.OnActionUpdate := DoActionUpdate;
Application.OnShortCut := DoShortCut;
Application.OnActivate := DoActivate;
Application.OnDeactivate := DoDeactivate;
Application.OnException := DoException;
Application.OnIdle := DoIdle;
Application.OnHelp := DoHelp;
Application.OnHint := DoHint;
{$IFDEF VCL}
Application.OnMessage := DoMessage;
{$ENDIF VCL}
{$IFDEF VisualCLX}
Application.OnEvent := DoEvent;
{$ENDIF VisualCLX}
Application.OnMinimize := DoMinimize;
Application.OnRestore := DoRestore;
Application.OnShowHint := DoShowHint;
if Screen <> nil then
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -