unit SRVHint;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  SRVToolBar, SclRView, TFSRVHint, SRVSkinManager;

type
  TSRVHint = class(TComponent)
  private
    { Private declarations }
    FOnClick : TNotifyEvent;
    FOnClickTopButton : TSRVClickButtonEvent;
    FOnClickBottomButton : TSRVClickButtonEvent;
    FSkinManager : TSRVSkinManager;
    FSkinSchemeIndex : Integer;
  protected
    { Protected declarations }
    FMenuHButtons: TSRVButtonCollection;
    FMenuVButtons: TSRVButtonCollection;
    FMenuHorizontal: TSRVPropertyTBH;
    FMenuVertical: TSRVPropertyTBV;
    FShowDelay : Integer;
    FText : String;
    FSRVHint1 : TFSRVHint1;

    function  GetStickForm : Boolean;
    function  GetShowInMousePos : Boolean;
    function  GetWidth : Integer;
    function  GetHeight : Integer;
    function  GetHintLeft : Integer;
    function  GetHintTop : Integer;
    function  GetCloseDelay : Integer;
    function  GetFromMouseDeltaX : Integer;
    function  GetFromMouseDeltaY : Integer;
    function  GetCaption : String;
    function  GetVisibleCaption : Boolean;
    function  GetCanResize : Boolean;
    function  GetCanMove : Boolean;
    function  GetCanActiveHint : Boolean;
    function  GetHintBounds : TRect;
    function  GetAllwaysShow : Boolean;

    procedure SetMenuHButtons(const Value: TSRVButtonCollection);
    procedure SetMenuVButtons(const Value: TSRVButtonCollection);
    procedure SetMenuHorizontal(const Value: TSRVPropertyTBH);
    procedure SetMenuVertical(const Value: TSRVPropertyTBV);
    procedure SetStickForm(const Value: Boolean);
    procedure SetShowInMousePos(const Value: Boolean);
    procedure SetWidth(const Value: Integer);
    procedure SetHeight(const Value: Integer);
    procedure SetHintLeft(const Value: Integer);
    procedure SetHintTop(const Value: Integer);
    procedure SetCloseDelay(const Value: Integer);
    procedure SetFromMouseDeltaX(const Value: Integer);
    procedure SetFromMouseDeltaY(const Value: Integer);
    procedure SetCaption(const Value: String);
    procedure SetText(const Value: String);
    procedure SetVisibleCaption(const Value: Boolean);
    procedure SetCanResize(const Value: Boolean);
    procedure SetCanMove(const Value: Boolean);
    procedure SetCanActiveHint(const Value: Boolean);
    procedure SetHintBounds(const Value : TRect);
    procedure SetAllwaysShow(const Value : Boolean);
    procedure SetSkinManager(Value : TSRVSkinManager);
    procedure SetSkinSchemeIndex(Value : Integer);

    procedure ResizeHint;
  public
    { Public declarations }
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;

    procedure SetBounds(ARect : TRect);
    procedure ShowHintWithDelay(Delay : Integer);
    procedure HideHintWithDelay(Delay : Integer);
    procedure ShowHint;
    procedure HideHint;
    function  IsShowHint : Boolean;
    function  IsFocused : Boolean;
    function  InMouse : Boolean;
    procedure Lock;
    procedure Unlock;

    property  HintBounds : TRect read GetHintBounds write SetHintBounds;
  published
    { Published declarations }
    property SkinManager : TSRVSkinManager read FSkinManager write SetSkinManager;
    property SkinSchemeIndex : Integer read FSkinSchemeIndex write SetSkinSchemeIndex default 0;
    property MenuHButtons: TSRVButtonCollection read FMenuHButtons write
      SetMenuHButtons;
    property MenuVButtons: TSRVButtonCollection read FMenuVButtons write
      SetMenuVButtons;
    property MenuHorizontal: TSRVPropertyTBH read FMenuHorizontal write
      SetMenuHorizontal;
    property MenuVertical: TSRVPropertyTBV read FMenuVertical write
      SetMenuVertical;
    property ShowInMousePos : Boolean read GetShowInMousePos write
      SetShowInMousePos default False;
    property AllwaysShow : Boolean read GetAllwaysShow write
      SetAllwaysShow default False;
    property StickForm : Boolean read GetStickForm write SetStickForm
      default False;
    property Width : Integer read GetWidth write SetWidth default 320;
    property Height : Integer read GetHeight write SetHeight default 200;
    property HintLeft : Integer read GetHintLeft write SetHintLeft default 0;
    property HintTop : Integer read GetHintTop write SetHintTop default 0;
    property ShowDelay : Integer read FShowDelay write FShowDelay default 0;
    property CloseDelay : Integer read GetCloseDelay write SetCloseDelay
      default 3000;
    property FromMouseDeltaX : Integer read GetFromMouseDeltaX write
      SetFromMouseDeltaX default 0;
    property FromMouseDeltaY : Integer read GetFromMouseDeltaY write
      SetFromMouseDeltaY default 0;
    property Caption : String read GetCaption write SetCaption;
    property Text : String read FText write SetText;
    property VisibleCaption : Boolean read GetVisibleCaption write
      SetVisibleCaption default True;
    property CanResize : Boolean read GetCanResize write
      SetCanResize default False;
    property CanMove : Boolean read GetCanMove write
      SetCanMove default False;
    property CanActiveHint : Boolean read GetCanActiveHint write
      SetCanActiveHint default False;
    property Tag;
    property OnClick : TNotifyEvent read FOnClick write FOnClick;
    property OnClickTopButton : TSRVClickButtonEvent read FOnClickTopButton write FOnClickTopButton;
    property OnClickBottomButton : TSRVClickButtonEvent read FOnClickBottomButton write FOnClickBottomButton;
  end;

implementation

uses Math;

{-----------------------------------------------------------------------}
constructor TSRVHint.Create(AOwner: TComponent);
begin
  inherited;
    FSRVHint1 := TFSRVHint1.Create(nil);
    FSRVHint1.Name := '';

    FShowDelay := 0;
    FText := '';
    FSRVHint1.Caption := Name;
    Text := Name;
    FSRVHint1.SetBounds(0, 0, 320, 200);
    FSRVHint1.ShowInMousePos := False;
    FSRVHint1.HintDelay := 3000;
    FSRVHint1.DeltaX := 0;
    FSRVHint1.DeltaY := 0;
    FSRVHint1.IsStickForm := False;
    FSRVHint1.lblCaption.Caption := '';
    FSRVHint1.HintOwner := Self;
    FSRVHint1.CanResize := False;
    FSRVHint1.CanMove := False;
    FSRVHint1.AllwaysShow := False;
    FSRVHint1.CanActiveHint := False;
    FSRVHint1.CanActiveHint := False;
    SetRectEmpty(FSRVHint1.HintBounds);

    FMenuHButtons := TSRVButtonCollection.Create(TSRVToolButton, FSRVHint1.MenuToolBarTop);
    FMenuVButtons := TSRVButtonCollection.Create(TSRVToolButton, FSRVHint1.MenuToolBarBottom);

    FMenuHorizontal := TSRVPropertyTBH.Create(FSRVHint1.MenuToolBarTop);
    FMenuHorizontal.Buttons := FMenuHButtons;
    FMenuVertical := TSRVPropertyTBV.Create(FSRVHint1.MenuToolBarBottom);
    FMenuVertical.Buttons := FMenuVButtons;

    FSRVHint1.MenuToolBarTop.Align := alRight;
    FSRVHint1.MenuToolBarBottom.Align := alLeft;
end;

{-----------------------------------------------------------------------}
destructor TSRVHint.Destroy;
begin
    FMenuVButtons.Free;
    FMenuHButtons.Free;

    FMenuHorizontal.Free;
    FMenuHorizontal := nil;
    FMenuVertical.Free;
    FMenuVertical := nil;

    FSRVHint1.Free;
  inherited;
end;

{-----------------------------------------------------------------------}
procedure TSRVHint.SetBounds(ARect : TRect);
begin
  with ARect do
    FSRVHint1.SetBounds(Left, Top, Right - Left, Bottom - Top);
end;

{-----------------------------------------------------------------------}
procedure TSRVHint.ShowHintWithDelay(Delay : Integer);
begin
  ResizeHint;
  FSRVHint1.ShowHintWithDelay(Delay);
end;

{-----------------------------------------------------------------------}
procedure TSRVHint.HideHintWithDelay(Delay : Integer);
begin
  FSRVHint1.HintDelay := Delay;
  FSRVHint1.RunTimerCloseHint;
end;

{-----------------------------------------------------------------------}
procedure TSRVHint.ShowHint;
begin
  ResizeHint;
  FSRVHint1.ShowHintWithDelay(FShowDelay);
end;

{-----------------------------------------------------------------------}
procedure TSRVHint.HideHint;
begin
  FSRVHint1.HideHintWindow;
end;

{-----------------------------------------------------------------------}
function  TSRVHint.IsShowHint : Boolean;
begin
  Result := FSRVHint1.IsShowHint;
end;

{-----------------------------------------------------------------------}
function  TSRVHint.IsFocused : Boolean;
begin
  Result := IsShowHint and FSRVHint1.Focused;
end;

{-----------------------------------------------------------------------}
function  TSRVHint.InMouse : Boolean;
begin
  Result := FSRVHint1.InMouse;
end;

{-----------------------------------------------------------------------}
procedure TSRVHint.Lock;
begin
  FSRVHint1.Lock;
end;

{-----------------------------------------------------------------------}
procedure TSRVHint.Unlock;
begin
  FSRVHint1.Unlock;
end;

{-----------------------------------------------------------------------}
procedure TSRVHint.SetMenuHButtons(const Value: TSRVButtonCollection);
begin
  FMenuHButtons.Assign(Value);
  FSRVHint1.Repaint;
end;

{-----------------------------------------------------------------------}
procedure TSRVHint.SetMenuVButtons(const Value: TSRVButtonCollection);
begin
  FMenuVButtons.Assign(Value);
  FSRVHint1.Repaint;
end;

{-----------------------------------------------------------------------}
procedure TSRVHint.SetMenuHorizontal(const Value: TSRVPropertyTBH);
begin
  FMenuHorizontal.Assign(Value);
  FSRVHint1.Repaint;
end;

{-----------------------------------------------------------------------}
procedure TSRVHint.SetMenuVertical(const Value: TSRVPropertyTBV);
begin
  FMenuVertical.Assign(Value);
  FSRVHint1.Repaint;
end;

{-----------------------------------------------------------------------}
procedure TSRVHint.SetStickForm(const Value: Boolean);
begin
  FSRVHint1.IsStickForm := Value;
end;

{-----------------------------------------------------------------------}
procedure TSRVHint.SetShowInMousePos(const Value: Boolean);
begin
  FSRVHint1.ShowInMousePos := Value;
end;

{-----------------------------------------------------------------------}
procedure TSRVHint.SetAllwaysShow(const Value: Boolean);
begin
  FSRVHint1.AllwaysShow := Value;
end;

{-----------------------------------------------------------------------}
procedure TSRVHint.SetSkinManager(Value : TSRVSkinManager);
begin
  If Value <> FSkinManager then begin
    FSkinManager := Value;
    FSRVHint1.Repaint;
  end;
end;

{-----------------------------------------------------------------------}
procedure TSRVHint.SetSkinSchemeIndex(Value : Integer);
begin
  If FSkinSchemeIndex <> Value then begin
    FSkinSchemeIndex := Value;
    FSRVHint1.Repaint;
  end;
end;

{-----------------------------------------------------------------------}
procedure TSRVHint.SetWidth(const Value: Integer);
begin
  FSRVHint1.Width := Value;
end;

{-----------------------------------------------------------------------}
procedure TSRVHint.SetHeight(const Value: Integer);
begin
  FSRVHint1.Height := Value;
end;

{-----------------------------------------------------------------------}
procedure TSRVHint.SetHintLeft(const Value: Integer);
begin
  FSRVHint1.Left := Value;
end;

{-----------------------------------------------------------------------}
procedure TSRVHint.SetHintTop(const Value: Integer);
begin
  FSRVHint1.Top := Value;
end;

{-----------------------------------------------------------------------}
procedure TSRVHint.SetCloseDelay(const Value: Integer);
begin
  FSRVHint1.HintDelay := Value;
end;

{-----------------------------------------------------------------------}
procedure TSRVHint.SetFromMouseDeltaX(const Value: Integer);
begin
  FSRVHint1.DeltaX := Value;
end;

{-----------------------------------------------------------------------}
procedure TSRVHint.SetFromMouseDeltaY(const Value: Integer);
begin
  FSRVHint1.DeltaY := Value;
end;

{-----------------------------------------------------------------------}
procedure TSRVHint.SetCaption(const Value: String);
begin
  FSRVHint1.lblCaption.Caption := Value;
end;

{-----------------------------------------------------------------------}
procedure TSRVHint.SetText(const Value: String);
begin
  FSRVHint1.RichView1.Clear;
  FSRVHint1.RichView1.Add(Value, 0);
  FSRVHint1.RichView1.Format;
  FText := Value;
end;

{-----------------------------------------------------------------------}
procedure TSRVHint.SetVisibleCaption(const Value: Boolean);
begin
  FSRVHint1.lblCaption.Visible := Value;
  ResizeHint;
end;

{-----------------------------------------------------------------------}
procedure TSRVHint.SetCanResize(const Value: Boolean);
begin
  FSRVHint1.CanResize := Value;
end;

{-----------------------------------------------------------------------}
procedure TSRVHint.SetCanMove(const Value: Boolean);
begin
  FSRVHint1.CanMove := Value;
end;

{-----------------------------------------------------------------------}
procedure TSRVHint.SetCanActiveHint(const Value: Boolean);
begin
  FSRVHint1.CanActiveHint := Value;
end;

{-----------------------------------------------------------------------}
procedure TSRVHint.SetHintBounds(const Value : TRect);
begin
  FSRVHint1.HintBounds := Value;
end;

{-----------------------------------------------------------------------}
function  TSRVHint.GetHintBounds : TRect;
begin
  Result := FSRVHint1.HintBounds;
end;

{-----------------------------------------------------------------------}
function  TSRVHint.GetStickForm : Boolean;
begin
  Result := FSRVHint1.IsStickForm;
end;

{-----------------------------------------------------------------------}
function  TSRVHint.GetShowInMousePos : Boolean;
begin
  Result := FSRVHint1.ShowInMousePos;
end;

{-----------------------------------------------------------------------}
function  TSRVHint.GetAllwaysShow : Boolean;
begin
  Result := FSRVHint1.AllwaysShow;
end;

{-----------------------------------------------------------------------}
function  TSRVHint.GetWidth : Integer;
begin
  Result := FSRVHint1.Width;
end;

{-----------------------------------------------------------------------}
function  TSRVHint.GetHeight : Integer;
begin
  Result := FSRVHint1.Height;
end;

{-----------------------------------------------------------------------}
function  TSRVHint.GetHintLeft : Integer;
begin
  Result := FSRVHint1.Left;
end;

{-----------------------------------------------------------------------}
function  TSRVHint.GetHintTop : Integer;
begin
  Result := FSRVHint1.Top;
end;

{-----------------------------------------------------------------------}
function  TSRVHint.GetCloseDelay : Integer;
begin
  Result := FSRVHint1.HintDelay;
end;

{-----------------------------------------------------------------------}
function  TSRVHint.GetFromMouseDeltaX : Integer;
begin
  Result := FSRVHint1.DeltaX;
end;

{-----------------------------------------------------------------------}
function  TSRVHint.GetFromMouseDeltaY : Integer;
begin
  Result := FSRVHint1.DeltaY;
end;

{-----------------------------------------------------------------------}
function  TSRVHint.GetCaption : String;
begin
  Result := FSRVHint1.lblCaption.Caption;
end;

{-----------------------------------------------------------------------}
function  TSRVHint.GetVisibleCaption : Boolean;
begin
  Result := FSRVHint1.lblCaption.Visible;
end;

{-----------------------------------------------------------------------}
function  TSRVHint.GetCanResize : Boolean;
begin
  Result := FSRVHint1.CanResize;
end;

{-----------------------------------------------------------------------}
function  TSRVHint.GetCanMove : Boolean;
begin
  Result := FSRVHint1.CanMove;
end;

{-----------------------------------------------------------------------}
function  TSRVHint.GetCanActiveHint : Boolean;
begin
  Result := FSRVHint1.CanActiveHint;
end;

{-----------------------------------------------------------------------}
procedure TSRVHint.ResizeHint;
var
     ALeft, ATop, ARight, ABottom : Integer;
begin
  with FSRVHint1 do begin
    pnlCaption.Visible := lblCaption.Visible or FMenuHorizontal.Visible;
    ALeft := pnlCaption.Left;
    ARight := pnlCaption.BoundsRect.Right;
    If pnlCaption.Visible then
      ATop := pnlCaption.BoundsRect.Bottom
    else
      ATop := lnTop.BoundsRect.Bottom;

    pnlBottom.Visible := FMenuVertical.Visible;
    If pnlBottom.Visible then
      ABottom := pnlBottom.Top
    else
      ABottom := lnBottom.Top;
    RichView1.SetBounds(ALeft, ATop, ARight, ABottom);
  end;
end;

{-----------------------------------------------------------------------}

end.
