MG: implemented hints

git-svn-id: trunk@3608 -
This commit is contained in:
lazarus 2002-11-05 20:03:42 +00:00
parent 0d0e5a2574
commit 69623c1f81
3 changed files with 72 additions and 17 deletions

View File

@ -1045,7 +1045,7 @@ begin
inherited MouseDown(Button,Shift,X,Y); inherited MouseDown(Button,Shift,X,Y);
//hide the hint //hide the hint
if FHintWindow.Visible then FHintWindow.Visible := False; FHintWindow.Visible := False;
if Button=mbLeft then begin if Button=mbLeft then begin
if Cursor=crHSplit then begin if Cursor=crHSplit then begin

View File

@ -422,6 +422,8 @@ type
property HideInterval : Integer read FHideInterval write SetHideInterval; property HideInterval : Integer read FHideInterval write SetHideInterval;
end; end;
THintWindowClass = class of THintWindow;
{ TScreen } { TScreen }
@ -458,28 +460,47 @@ type
TExceptionEvent = procedure (Sender: TObject; E: Exception) of object; TExceptionEvent = procedure (Sender: TObject; E: Exception) of object;
TIdleEvent = procedure (Sender: TObject; var Done: Boolean) of object; TIdleEvent = procedure (Sender: TObject; var Done: Boolean) of object;
TOnUserInputEvent = procedure(Sender: TObject; Msg: Cardinal) of object;
TApplicationStateType = (AppWaiting, AppIdleEndSent); TAppHintTimerType = (ahtNone, ahtShowHint, ahtHideHint, ahtReshowHint);
TApplicationState = set of TApplicationStateType; THintInfoAtMouse = record
MousePos: TPoint;
Control: TControl;
ControlHasHint: boolean;
end;
TApplicationFlag = (AppWaiting, AppIdleEndSent);
TApplicationFlags = set of TApplicationFlag;
TApplication = class(TComponent) TApplication = class(TComponent)
private private
FFlag: TApplicationFlags;
FHandle : THandle; FHandle : THandle;
FHint: string;
FHintColor: TColor;
FHintControl: TControl;
FHintHidePause: Integer;
FHintPause: Integer;
FHintShortCuts: Boolean;
FHintShortPause: Integer;
FHintTimer: TCustomTimer;
FHintTimerType: TAppHintTimerType;
FHintWindow: THintWindow;
FIcon: TIcon; FIcon: TIcon;
FList: TList; FList: TList;
FMainForm : TForm; FMainForm : TForm;
FMouseControl: TControl; FMouseControl: TControl;
FOnException: TExceptionEvent; FOnException: TExceptionEvent;
FOnHint: TNotifyEvent;
FOnIdle: TIdleEvent; FOnIdle: TIdleEvent;
FOnIdleHandler: TMethodList; FOnIdleHandler: TMethodList;
FOnIdleEnd: TNotifyEvent; FOnIdleEnd: TNotifyEvent;
FOnIdleEndHandler: TMethodList; FOnIdleEndHandler: TMethodList;
FOnUserInput: TNotifyEvent; FOnUserInput: TOnUserInputEvent;
FOnUserInputHandler: TMethodList; FOnUserInputHandler: TMethodList;
FState: TApplicationState; FShowHint: Boolean;
FTerminate : Boolean; FTerminate : Boolean;
FTitle : String; FTitle : String;
procedure wndproc(var Message : TLMessage);
procedure DoOnIdleEnd; procedure DoOnIdleEnd;
function GetExename: String; function GetExename: String;
function GetIconHandle: HICON; function GetIconHandle: HICON;
@ -487,10 +508,20 @@ type
procedure IconChanged(Sender: TObject); procedure IconChanged(Sender: TObject);
procedure Idle; procedure Idle;
procedure MouseIdle(const CurrentControl: TControl); procedure MouseIdle(const CurrentControl: TControl);
procedure SetHint(const AValue: string);
procedure SetHintColor(const AValue: TColor);
procedure SetIcon(AValue: TIcon); procedure SetIcon(AValue: TIcon);
procedure SetShowHint(const AValue: Boolean);
procedure StopHintTimer;
procedure WndProc(var AMessage : TLMessage);
protected protected
procedure NotifyIdleHandler; procedure NotifyIdleHandler;
procedure NotifyIdleEndHandler; procedure NotifyIdleEndHandler;
function IsHintMsg(var Msg: TMsg): Boolean;
procedure DoOnMouseMove; virtual;
procedure ShowHintWindow(const Info: THintInfoAtMouse);
procedure StartHintTimer(Interval: integer; TimerType: TAppHintTimerType);
procedure OnHintTimer(Sender: TObject);
public public
constructor Create(AOwner: TComponent); override; constructor Create(AOwner: TComponent); override;
destructor Destroy; override; destructor Destroy; override;
@ -501,7 +532,9 @@ type
procedure HandleException(Sender: TObject); procedure HandleException(Sender: TObject);
procedure HandleMessage; procedure HandleMessage;
function IsWaiting: boolean; function IsWaiting: boolean;
procedure HintMouseMessage(Control : TControl; var Message: TLMessage); procedure CancelHint;
procedure HideHint;
procedure HintMouseMessage(Control : TControl; var AMessage: TLMessage);
property Icon: TIcon read FIcon write SetIcon; property Icon: TIcon read FIcon write SetIcon;
procedure Initialize; procedure Initialize;
function MessageBox(Text, Caption : PChar; Flags : Longint) : Integer; function MessageBox(Text, Caption : PChar; Flags : Longint) : Integer;
@ -510,22 +543,30 @@ type
procedure Run; procedure Run;
procedure ShowException(E: Exception); procedure ShowException(E: Exception);
procedure Terminate; procedure Terminate;
procedure NotifyUserInputHandler; procedure NotifyUserInputHandler(Msg: Cardinal);
procedure AddOnIdleHandler(AnOnIdleHandler: TNotifyEvent); procedure AddOnIdleHandler(AnOnIdleHandler: TNotifyEvent);
procedure RemoveOnIdleHandler(AnOnIdleHandler: TNotifyEvent); procedure RemoveOnIdleHandler(AnOnIdleHandler: TNotifyEvent);
procedure AddOnIdleEndHandler(AnOnIdleEndHandler: TNotifyEvent); procedure AddOnIdleEndHandler(AnOnIdleEndHandler: TNotifyEvent);
procedure RemoveOnIdleEndHandler(AnOnIdleEndHandler: TNotifyEvent); procedure RemoveOnIdleEndHandler(AnOnIdleEndHandler: TNotifyEvent);
procedure AddOnUserInputHandler(AnOnUserInputHandler: TNotifyEvent); procedure AddOnUserInputHandler(AnOnUserInputHandler: TOnUserInputEvent);
procedure RemoveOnUserInputHandler(AnOnUserInputHandler: TNotifyEvent); procedure RemoveOnUserInputHandler(AnOnUserInputHandler: TOnUserInputEvent);
public public
property Exename: String read GetExeName; property Exename: String read GetExeName;
property Handle: THandle read FHandle; property Handle: THandle read FHandle;
property Terminated: Boolean read FTerminate; property Hint: string read FHint write SetHint;
property HintColor: TColor read FHintColor write SetHintColor;
property HintHidePause: Integer read FHintHidePause write FHintHidePause;
property HintPause: Integer read FHintPause write FHintPause;
property HintShortCuts: Boolean read FHintShortCuts write FHintShortCuts;
property HintShortPause: Integer read FHintShortPause write FHintShortPause;
property MainForm: TForm read FMainForm; property MainForm: TForm read FMainForm;
property Terminated: Boolean read FTerminate;
property OnException: TExceptionEvent read FOnException write FOnException; property OnException: TExceptionEvent read FOnException write FOnException;
property OnIdle: TIdleEvent read FOnIdle write FOnIdle; property OnIdle: TIdleEvent read FOnIdle write FOnIdle;
property OnIdleEnd: TNotifyEvent read FOnIdleEnd write FOnIdleEnd; property OnIdleEnd: TNotifyEvent read FOnIdleEnd write FOnIdleEnd;
property OnUserInput: TNotifyEvent read FOnUserInput write FOnUserInput; property OnHint: TNotifyEvent read FOnHint write FOnHint;
property OnUserInput: TOnUserInputEvent read FOnUserInput write FOnUserInput;
property ShowHint: Boolean read FShowHint write SetShowHint;
property Title: String read GetTitle write FTitle; property Title: String read GetTitle write FTitle;
end; end;
@ -560,6 +601,7 @@ function GetParentForm(Control:TControl): TCustomForm;
function FindRootDesigner(AComponent: TComponent): TIDesigner; function FindRootDesigner(AComponent: TComponent): TIDesigner;
function IsAccel(VK : Word; const Str : ShortString): Boolean; function IsAccel(VK : Word; const Str : ShortString): Boolean;
procedure NotifyApplicationUserInput(Msg: Cardinal);
function InitResourceComponent(Instance: TComponent; function InitResourceComponent(Instance: TComponent;
RootAncestor: TClass):Boolean; RootAncestor: TClass):Boolean;
@ -569,6 +611,7 @@ var
Application : TApplication; Application : TApplication;
Screen : TScreen; Screen : TScreen;
ExceptionObject : TExceptObject; ExceptionObject : TExceptObject;
HintWindowClass: THintWindowClass;
type type
TMessageBoxFunction = TMessageBoxFunction =
@ -578,8 +621,10 @@ var
procedure FreeInterfaceObject; procedure FreeInterfaceObject;
implementation implementation
uses uses
LResources, Math; LResources, Math;
@ -587,6 +632,17 @@ var
FocusMessages: Boolean; FocusMessages: Boolean;
FocusCount: Integer; FocusCount: Integer;
{------------------------------------------------------------------------------
procedure NotifyApplicationUserInput;
------------------------------------------------------------------------------}
procedure NotifyApplicationUserInput(Msg: Cardinal);
begin
if Application<>nil then
Application.NotifyUserInputHandler(Msg);
end;
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
procedure ExceptionOccurred(Sender : TObject; Addr,Frame : Pointer); procedure ExceptionOccurred(Sender : TObject; Addr,Frame : Pointer);
var var
@ -808,10 +864,9 @@ initialization
finalization finalization
writeln('forms.pp - finalization section'); writeln('forms.pp - finalization section');
LCLProc.OwnerFormDesignerModifiedProc:=nil; LCLProc.OwnerFormDesignerModifiedProc:=nil;
Application.Free; HintWindowClass:=THintWindow;
Application:= nil; FreeThenNil(Application);
Screen.Free; FreeThenNil(Screen);
Screen:= nil;
end. end.

View File

@ -48,7 +48,7 @@ begin
Enabled:=true; Enabled:=true;
end; end;
procedure TIdleTimer.DoOnUserInput(Sender: TObject); procedure TIdleTimer.DoOnUserInput(Sender: TObject; Msg: Cardinal);
begin begin
if not AutoEnabled then exit; if not AutoEnabled then exit;
// automatic start, stop or restart // automatic start, stop or restart