(************************************************************************
*    This File is Part of the AHM Triton Tools                          *
*    for Borland Delphi and C++ Builder.                                *
*************************************************************************
* Copyright © 1995-1999 Alexander H. Mehlhorn (AHM) and Tritontools.com *
* All Rights reserved.                                                  *
*                                                                       *
*    For more Information contact us at                                 *
*    E-Mail : support@tritontools.com                                   *
*    URL : http://www.tritontools.com                                   *
*                                                                       *
*    AHM is copyright by Alexander H. Mehlhorn                          *
*    All Parts of this Collection were developed,                       *
*    designed and implemented by AHM                                    *
*                                                                       *
*    Under no Circumstances may you distribute this file                *
*    in this or any other format. This File is supplied                 *
*    as Evaluation of Source only. No Delphi Components may be developed*
*    using extracts or subsets of this code without expressed permission*
*    by AHM.                                                            *
*                                                                       *
*************************************************************************)
unit AHMTTipTrickDlg;

interface
{$I AHM.INC}
uses
  SysUtils, Windows, Messages, Classes,
  Forms, Dialogs, Graphics,AHMDialogClass,AHMDialogConst,
  Controls, Buttons, ComCtrls, StdCtrls, ExtCtrls;

type
  TAHMTipTricks = class;
  TAHMOnNewTip = procedure(Sender : TObject;TipNo : Integer) of Object;
  TAHMCheckBoxInfo = class(TPersistent)
  private
    fvisible : boolean;
    fenabled : Boolean;
    fchecked : Boolean;
    fcaption : String;
  protected
  public
    constructor Create;
    destructor Destroy; override;
  published
    Property Visible:Boolean read fvisible write fvisible default True;
    Property Enabled:Boolean read fenabled write FEnabled default True;
    Property Checked:Boolean read fchecked write FChecked default True;
    Property Caption:String read fcaption write FCaption;
  end;
  TAHMTipTricks = class(TAHMDialogComponent)
  private
     FSetupCheckbox : TAHMCheckBoxInfo;
     fColor : TColor;
     fAlignment : TAlignment;
     FCustomButton1,FCustomButton2,FOkButton,FNextButton : TAHMButtonDetails;
     fTips : TStrings;
     FOnCheck,FOnCustom1,FOnCustom2,FOnOk,FOnNExt : TNotifyEvent;
     FDidyouKnow : string;
     FFont : TFont;
     fcaps : String;
    FTipGlyph: TBitmap;
    FCurrentTip: Integer;
    FOnNewTip: TAHMOnNewTip;
     procedure SetFont(Value : TFont);
     procedure SetAlignment(Value : TAlignment);
     procedure setTips(value : TStrings);
     procedure SetColor(Value : TColor);
     procedure SetTipGlyph(const Value: TBitmap);
     procedure Custom1Change(Sender : TObject);
     procedure Custom2Change(Sender : TObject);
     procedure OkChange(Sender : TObject);
     procedure NextChange(Sender : TObject);
  protected
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
    Function Execute : Boolean; override;
    Function CloseTips : Boolean;
    Property CurrentTip : Integer read FCurrentTip;
    Function NextTip : Boolean;
  published
     Property SetupCheckbox : TAHMCheckBoxInfo read FSetupCheckbox write FSetupCheckbox;
     Property Custom1BitBtn : TAHMButtonDetails read FCustomButton1 write FCustomButton1;
     Property Custom2BitBtn : TAHMButtonDetails read FCustomButton2 write FCustomButton2;
     Property TipGlyph : TBitmap read FTipGlyph write SetTipGlyph;
     Property TipAlign : TAlignment read fAlignment write SetAlignment default taCenter;
     Property Color : TColor read fColor write SetColor default clwhite;
     Property OkBitBtn : TAHMButtonDetails read FOkButton write FOkButton;
     Property NextTipBitBtn : TAHMButtonDetails read FNextButton write FNextButton;
     Property Tips : TStrings  read fTips write SetTips;
     Property OnCustom1 : TNotifyEvent read FOnCustom1 write FOnCustom1;
     Property OnCustom2 : TNotifyEvent read FOnCustom2 write FOnCustom2;
     Property OnOk : TNotifyEvent read FOnOk write FOnOk;
     Property OnNewTip : TAHMOnNewTip read FOnNewTip write FOnNewTip;
     Property OnNext : TNotifyEvent read FOnNext write FOnNext;
     Property OnCheckClick : TNotifyevent read FOnCheck write FOnCheck;
     Property TipDlgCaption : String read fcaps write fcaps;
     Property DidYouKnow : String read FDidYouKnow write FDidYouKnow;
     Property Fonts : TFont read FFont write SetFont;
  end;


implementation

type
  TTipDialog = class(TForm)
  private
    Panel1: TPanel;
    Panel2: TPanel;
    BitBtn1: TBitBtn;
    BitBtn2: TBitBtn;
    BitBtn3: TBitBtn;
    BitBtn4: TBitBtn;
    CheckBox1: TCheckBox;
    Label1: TLabel;
    StatusBar1: TStatusBar;
    procedure BitBtn1Click(Sender: TObject);
    procedure BitBtn4Click(Sender: TObject);
    procedure BitBtn2Click(Sender: TObject);
    procedure BitBtn3Click(Sender: TObject);
    procedure CheckBox1Click(Sender: TObject);
  public
    FAHMTipTricks : TAHMTipTricks;
    Procedure SetupForm;
  end;


procedure TTipDialog.SetupForm;
begin
  Left := 262;
  Top := 185;
  Caption:=FAHMTipTricks.fcaps;
  BorderIcons := [biSystemMenu];
  BorderStyle := bsDialog;
  ClientHeight := 251;
  ClientWidth := 371;
  Color := clBtnFace;
  Position := poScreenCenter;
  Panel1:= TPanel.Create(Self);
  with Panel1 do
  begin
    Parent:=Self;
    Left := 0;
    Top := 0;
    Width := 371;
    Height := 232;
    Align := alClient;
    BevelOuter := bvLowered;
    TabOrder := 0;
    with TBevel.Create(Self) do
    begin
      Parent:=Panel1;
      Left := 8;
      Top := 8;
      Width := 257;
      Height := 201;
      Shape := bsFrame;
    end;
    Panel2:= TPanel.Create(Self);
    with Panel2 do
    begin
      Parent:=Panel1;
      Left := 16;
      Top := 16;
      Width := 241;
      Height := 185;
      BevelInner := bvLowered;
      Panel2.Color:=FAHMTipTricks.FColor;
      TabOrder := 0;
      Label1:=TLabel.Create(Self);
      with Label1 do
      begin
        Parent:=Panel2;
        Left := 2;
        Top := 43;
        Width := 237;
        Height := 140;
        Align := alClient;
        WordWrap:=true;
        Alignment:=FAHMTipTricks.falignment;
        AutoSize:=False;
        Transparent := True;
      end;
      with TImage.Create(Self) do
      begin
        Parent:=Panel2;
        Left := 2;
        Top := 2;
        Width := 237;
        Height := 41;
        Align := alTop;
        Picture.Bitmap:=FAHMTipTricks.FTipGlyph;
        Transparent:=True;
      end;
      with TLabel.Create(Self) do
      begin
        Parent:=Panel2;
        Left := 56;
        Top := 18;
        Width := 96;
        Height := 14;
        Alignment := taCenter;
        Caption := FAHMTipTricks.FDidYouKnow;
        Transparent := True;
      end;
    end;
    BitBtn1:= TBitBtn.Create(Self);
    with BitBtn1 do
    begin
      Parent:=Panel1;
      Left := 272;
      Top := 8;
      Width := 89;
      Height := 27;
      Caption := FAHMTipTricks.FOkButton.Caption;
      Hint := FAHMTipTricks.FOkButton.Hint;
      Visible := FAHMTipTricks.FOkButton.Visible;
      Glyph:=FAHMTipTricks.FOkButton.Glyph;
      Enabled := FAHMTipTricks.FOkButton.Enabled;
      ShowHint := FAHMTipTricks.FOkButton.ShowHint;
      TabOrder := 1;
      OnClick := BitBtn1Click;
    end;
    Self.ActiveControl := BitBtn1;
    BitBtn2:= TBitBtn.Create(Self);
    with Bitbtn2 do
    begin
      Parent:=Panel1;
      Left := 272;
      Top := 40;
      Width := 89;
      Height := 27;
      Caption := FAHMTipTricks.FNextButton.Caption;
      Hint := FAHMTipTricks.FNextButton.Hint;
      Visible := FAHMTipTricks.FNextButton.Visible;
      Glyph:=FAHMTipTricks.FNextButton.Glyph;
      Enabled := FAHMTipTricks.FNextButton.Enabled;
      ShowHint := FAHMTipTricks.FNextButton.ShowHint;
      TabOrder := 2;
      OnClick := BitBtn4Click;
    end;
    BitBtn3:= TBitBtn.Create(Self);
    with BitBtn3 do
    begin
      Parent:=Panel1;
      Left := 272;
      Top := 72;
      Width := 89;
      Height := 27;
      Caption := FAHMTipTricks.FCustomButton1.Caption;
      Hint := FAHMTipTricks.FCustomButton1.Hint;
      Visible := FAHMTipTricks.FCustomButton1.Visible;
      Glyph:=FAHMTipTricks.FCustomButton1.Glyph;
      Enabled := FAHMTipTricks.FCustomButton1.Enabled;
      ShowHint := FAHMTipTricks.FCustomButton1.ShowHint;
      TabOrder := 3;
      OnClick := BitBtn2Click;
    end;
    BitBtn4:= TBitBtn.Create(Self);
    with Bitbtn4 do
    begin
      Parent:=Panel1;
      Left := 272;
      Top := 104;
      Width := 89;
      Height := 27;
      Caption := FAHMTipTricks.FCustomButton2.Caption;
      Hint := FAHMTipTricks.FCustomButton2.Hint;
      Visible := FAHMTipTricks.FCustomButton2.Visible;
      Glyph:=FAHMTipTricks.FCustomButton2.Glyph;
      Enabled := FAHMTipTricks.FCustomButton2.Enabled;
      ShowHint := FAHMTipTricks.FCustomButton2.ShowHint;
      TabOrder := 4;
      OnClick := BitBtn3Click;
    end;
    CheckBox1:= TCheckBox.Create(Self);
    with Checkbox1 do
    begin
      Parent:=Panel1;
      Left := 8;
      Top := 210;
      Width := 249;
      Height := 17;
      Caption := FAHMTipTricks.FSetupCheckbox.Caption;
      Checked := FAHMTipTricks.FSetupCheckbox.Checked;
      Visible := FAHMTipTricks.FSetupCheckbox.Visible;
      Enabled := FAHMTipTricks.FSetupCheckbox.Enabled;
      TabOrder := 5;
      OnClick := CheckBox1Click;
    end;
  end;
  StatusBar1:= TStatusBar.Create(Self);
  with Statusbar1 do
  begin
    Parent:=Self;
    Left := 0;
    Top := 232;
    Width := 371;
    Height := 19;
    ParentShowHint := False;
    ShowHint := False;
    SimplePanel := True;
  end;
end;

constructor TAHMCheckBoxInfo.Create;
begin
  fvisible :=true;
  fenabled :=true;
  fchecked := true;
  inherited Create;
  FCaption :=ahmrcdlgshowtipsatstart;
end;

destructor TAHMCheckBoxInfo.Destroy;
begin
  inherited Destroy;
end;

constructor TAHMTipTricks.Create(AOwner: TComponent);
begin
  FSetupCheckbox := TAHMCheckBoxInfo.Create;
  FCustomButton1 := TAHMButtonDetails.Create(self);
  FCustomButton2 := TAHMButtonDetails.Create(self);
  FOkButton := TAHMButtonDetails.Create(self);
  FNextButton := TAHMButtonDetails.Create(self);
  FCustomButton1.OnChange:=Custom1Change;
  FCustomButton2.OnChange:=Custom2Change;
  FOkButton.OnChange:=OkChange;
  FNextButton.OnChange:=NextChange;
  FOkButton.caption:=ahmrcdlgok;
  FNextButton.caption:=ahmrcdlgnexttip;
  fTips:=TStringList.create;
  FDidYouKnow:=ahmrcdlgdidyouknow;
  FFont := TFont.Create;
  FFont.size := 8;
  fcolor:=clwhite;
  falignment:=taCenter;
  inherited Create(AOwner);
  FTipGlyph:=Tbitmap.Create;
  FCurrentTip:=-1;
end;

destructor TAHMTipTricks.Destroy;
begin
  FTipGlyph.Free;
  FSetupCheckbox.free;
  FCustomButton1.free;
  FCustomButton2.free;
  FOkButton.free;
  FNextButton.free;
  fTips.free;
  FFont.free;
  inherited Destroy;
end;

procedure TAHMTipTricks.SetTips(value : Tstrings);
begin
  fTips.assign(value);
end;


procedure TAHMTipTricks.SetFont(value : TFont);
begin
  FFont.assign(value);
end;

procedure TAHMTipTricks.SetAlignment(Value : TAlignment);
begin
  falignment:=Value;
end;

procedure TAHMTipTricks.SetColor(Value : TColor);
begin
  fcolor:=Value;
end;

Var TipsDialog : TTipDialog=nil;

Function TAHMTipTricks.Execute : Boolean;
begin
  result:=False;
  if not(FSetupCheckbox.FChecked) then exit;
  TipsDialog :=TTipDialog.CreateNew(Application);
  with TipsDialog do
  try
    FAHMTipTricks:=Self;
    SetupForm;
    Font:=FFont;
    BitBtn4Click(Self);
    inherited Execute;
    showmodal;
    result:=true;
  finally
    Free;
  end;
  TipsDialog:=nil;
end;

procedure TTipDialog.BitBtn1Click(Sender: TObject);
begin
  if assigned(FAHMTipTricks.FOnOk) then FAHMTipTricks.FOnOk(self);
  close;
end;

procedure TTipDialog.BitBtn4Click(Sender: TObject);
var i : integer;
    s: string;
begin
  Randomize;
  if assigned(FAHMTipTricks.FOnNext) then FAHMTipTricks.FOnNext(self);
  if FAHMTipTricks.FTips.count>0 then
  begin
    repeat I:=Random(FAHMTipTricks.FTips.count) until I<>FAHMTipTricks.FCurrentTip;
    FAHMTipTricks.FCurrentTip:=I;
    S:=FAHMTipTricks.FTips[i];
    Label1.caption:=s;
    if Assigned(FAHMtipTricks.FOnNewTip) then FAHMTipTricks.FOnNewTip(Self,I);
  end else label1.caption:=ahmrcdlgnomoretipsfound;
end;

procedure TTipDialog.BitBtn2Click(Sender: TObject);
begin
  if assigned(FAHMTipTricks.FOnCustom1) then FAHMTipTricks.FOnCustom1(self);
end;

procedure TTipDialog.BitBtn3Click(Sender: TObject);
begin
  if assigned(FAHMTipTricks.FOnCustom2) then FAHMTipTricks.FOnCustom2(self);
end;

procedure TTipDialog.CheckBox1Click(Sender: TObject);
begin
  FAHMTipTricks.FSetupCheckbox.Checked:=Checkbox1.checked;
  if assigned(FAHMTipTricks.FOnCheck) then FAHMTipTricks.FOnCheck(self);
end;

procedure TAHMTipTricks.SetTipGlyph(const Value: TBitmap);
begin
  FTipGlyph.assign(Value);
end;

function TAHMTipTricks.CloseTips: Boolean;
begin
  if TipsDialog<>nil then
  begin
    TipsDialog.ModalResult:=mrOk;
    Result:=True;
  end else result:=False;
end;

procedure TAHMTipTricks.Custom1Change(Sender: TObject);
begin
  if TipsDialog<>nil then
   with TipsDialog.BitBtn3 do
   begin
     Caption := FCustomButton1.Caption;
     Hint := FCustomButton1.Hint;
     Visible :=FCustomButton1.Visible;
     Glyph:=FCustomButton1.Glyph;
     Enabled := FCustomButton1.Enabled;
     ShowHint := FCustomButton1.ShowHint;
   end;
end;

procedure TAHMTipTricks.Custom2Change(Sender: TObject);
begin
  if TipsDialog<>nil then
  with TipsDialog.Bitbtn4 do
  begin
    Caption := FCustomButton2.Caption;
    Hint := FCustomButton2.Hint;
    Visible := FCustomButton2.Visible;
    Glyph:=FCustomButton2.Glyph;
    Enabled := FCustomButton2.Enabled;
    ShowHint := FCustomButton2.ShowHint;
  end;
end;

procedure TAHMTipTricks.NextChange(Sender: TObject);
begin
  if TipsDialog<>nil then
  with TipsDialog.BitBtn2 do
  begin
    Caption := FNextButton.Caption;
    Hint := FNextButton.Hint;
    Visible := FNextButton.Visible;
    Glyph:=FNextButton.Glyph;
    Enabled := FNextButton.Enabled;
    ShowHint := FNextButton.ShowHint;
  end;
end;

procedure TAHMTipTricks.OkChange(Sender: TObject);
begin
  if TipsDialog<>nil then
  with TipsDialog.Bitbtn1 do
  begin
    Caption := FOkButton.Caption;
    Hint := FOkButton.Hint;
    Visible := FOkButton.Visible;
    Glyph:= FOkButton.Glyph;
    Enabled := FOkButton.Enabled;
    ShowHint := FOkButton.ShowHint;
  end;
end;

function TAHMTipTricks.NextTip: Boolean;
begin
  if TipsDialog<>nil then
  begin
    TipsDialog.BitBtn4Click(Self);
    Result:=True;
  end else result:=False;

end;

end.
