unit U_FloatPanel;

interface

uses
  Windows, U_LNG, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, USCS_Main, U_Common, U_Main, Buttons, ExtCtrls, ImgList,
  StdCtrls, siComp, siLngLnk,
  DrawEngine, PCTypesUtils, DrawObjects, PCDrawBox, PCDrawing, PowerCad;

type
  TF_FloatPanel = class(TForm)
    Panel1: TPanel;
    SpeedButton2: TSpeedButton;
    SpeedButton1: TSpeedButton;
    BtnTmp2: TSpeedButton;
    BtnTmp1: TSpeedButton;
    Timer1: TTimer;
    Timer2: TTimer;
    Label1: TLabel;
    Label6: TLabel;
    ALabel1: TLabel;
    ALabel2: TLabel;
    ALabel3: TLabel;
    ALabel4: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Label7: TLabel;
    Label8: TLabel;
    Label9: TLabel;
    Label10: TLabel;
    Label11: TLabel;
    SpeedButton3: TSpeedButton;
    lng_Forms: TsiLangLinked;
    procedure SpeedButton1Click(Sender: TObject);
    procedure SpeedButton2Click(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
    procedure Timer2Timer(Sender: TObject);
    procedure Label1MouseLeave(Sender: TObject);
    procedure Label1MouseEnter(Sender: TObject);
    procedure FormHide(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure ALabel1Click(Sender: TObject);
    procedure SpeedButton3Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

  procedure ShowFloatPanel(OnlyResize: boolean = False);
  procedure HideFloatPanel;
  procedure ResizeFloatPanel;

var
  F_FloatPanel: TF_FloatPanel;

implementation
Uses U_Constants;

{$R *.dfm}

procedure ShowFloatPanel(OnlyResize: boolean = False);
var
  Point1: TPoint;
begin
  {$if Defined(ES_GRAPH_SC)}

  {$else}
    if F_FloatPanel = nil then
      Application.CreateForm(TF_FloatPanel, F_FloatPanel);
    if F_ProjMan <> nil then
    begin
      F_FloatPanel.SpeedButton1.Flat := True;
      F_FloatPanel.SpeedButton2.Flat := True;
      F_FloatPanel.SpeedButton3.Flat := True;
      Point1.X := F_ProjMan.Left;
      Point1.Y := -12;
      ClientToScreen(F_ProjMan.Handle, Point1);
      F_FloatPanel.Top := Point1.Y;
      F_FloatPanel.Left := Point1.X;
      F_FloatPanel.Height := F_ProjMan.Height + 12;
      if Not OnlyResize then
        F_FloatPanel.Width := 250;
      F_FloatPanel.Visible := True;
      if Not OnlyResize then
        F_FloatPanel.Timer1.Enabled := True;
      if Not OnlyResize then
        FSCS_Main.FloatPanel1.Checked := True;
    end;
  {$ifend}  
end;

procedure ResizeFloatPanel;
begin
  {$if Defined(ES_GRAPH_SC)}

  {$else}
    try
      if assigned(F_FloatPanel) then
      begin
        if F_FloatPanel.Visible then
        begin
          ShowFloatPanel(True);
        end;
      end;
    except
    end;
  {$ifend}  
end;

procedure HideFloatPanel;
begin
  if F_FloatPanel <> nil then
  begin
    F_FloatPanel.Visible := False;
  end;
end;

procedure TF_FloatPanel.SpeedButton1Click(Sender: TObject);
begin
  HideFloatPanel;
end;

procedure TF_FloatPanel.SpeedButton2Click(Sender: TObject);
begin
  if SpeedButton2.Tag = 1 then
  begin
    SpeedButton2.Glyph := BtnTmp2.Glyph;
    SpeedButton2.Tag := 0;
  end
  else
  begin
    SpeedButton2.Glyph := BtnTmp1.Glyph;
    SpeedButton2.Tag := 1;
  end;
end;

procedure TF_FloatPanel.Timer1Timer(Sender: TObject);
begin
  Timer1.Enabled := False;
  if F_FloatPanel.Visible then
  begin
    if SpeedButton2.Tag = 0 then
      Timer2.Enabled := True;
  end;
end;

procedure TF_FloatPanel.Timer2Timer(Sender: TObject);
begin
  if F_FloatPanel.Width > 15 then
    F_FloatPanel.Width := F_FloatPanel.Width - 20
  else
  begin
    Timer2.Enabled := False;
    F_FloatPanel.Width := 4;
  end;
end;

procedure TF_FloatPanel.Label1MouseLeave(Sender: TObject);
begin
  if TLabel(Sender).Tag <> 0 then
    TLabel(Sender).Font.Style := TLabel(Sender).Font.Style - [fsUnderline];
  Timer1.Enabled := True;
end;

procedure TF_FloatPanel.Label1MouseEnter(Sender: TObject);
begin
  if TLabel(Sender).Tag <> 0 then
  begin
    {$IF Defined(SCS_PE) or Defined(SCS_SPA)}
    if (TLabel(Sender).Tag <> 5) and (TLabel(Sender).Tag <> 7) and (TLabel(Sender).Tag <> 8) then
    begin
      TLabel(Sender).Font.Style := TLabel(Sender).Font.Style + [fsUnderline];
      TLabel(Sender).Cursor := crHandPoint;
    end
    else
      TLabel(Sender).Cursor := crArrow;
    {$ELSE}
    TLabel(Sender).Font.Style := TLabel(Sender).Font.Style + [fsUnderline];
    {$IFEND}
  end;  
  ShowFloatPanel;
  Timer1.Enabled := False;
end;

procedure TF_FloatPanel.FormHide(Sender: TObject);
begin
  FSCS_Main.FloatPanel1.Checked := False;
end;

procedure TF_FloatPanel.FormShow(Sender: TObject);
begin
  FSCS_Main.FloatPanel1.Checked := False;
end;

procedure TF_FloatPanel.ALabel1Click(Sender: TObject);
begin
  case TLabel(Sender).Tag of
    1: FSCS_Main.aNew.Execute;
    2: FSCS_Main.aListProperties.Execute;
    3: begin
         SendMessage(FSCS_Main.Handle, WM_ACTIVATE, MakewParam(WA_ACTIVE, 0), 0);
         SendMessage(FSCS_Main.Handle, WM_SETFOCUS, 0, 0);
         FSCS_Main.aToolWallRect.Execute;
         SetCursorPos(500, 500);
       end;
    4: begin
         SendMessage(FSCS_Main.Handle, WM_ACTIVATE, MakewParam(WA_ACTIVE, 0), 0);
         SendMessage(FSCS_Main.Handle, WM_SETFOCUS, 0, 0);
         FSCS_Main.aToolSCSHDimLine.Execute;
         SetCursorPos(500, 500);
       end;
    6: begin
         SendMessage(FSCS_Main.Handle, WM_ACTIVATE, MakewParam(WA_ACTIVE, 0), 0);
         SendMessage(FSCS_Main.Handle, WM_SETFOCUS, 0, 0);
         FSCS_Main.aToolOrthoLine.Execute;
         SetCursorPos(500, 500);
       end;
    9: begin
         FSCS_Main.aMasterAutoTrace.Execute;
       end;
    10: begin
         FSCS_Main.aMasterCableChannel.Execute;
       end;
    11: begin
         if F_ProjMan <> nil then
           try
             F_ProjMan.Act_SetCableCanalConnectors.Execute;
           except
           end;
       end;
    12: begin
          FSCS_Main.aCreateProjectPlan.Execute;
       end;
    13: begin
          FSCS_Main.aRepWizard.Execute;
        end;
    5:  begin
          {$IF NOT Defined(SCS_PE) AND NOT Defined(SCS_SPA)}
          Application.HelpCommand(HELP_CONTEXT, 53000);
          {$IFEND}
        end;
    7:  begin
          {$IF NOT Defined(SCS_PE) AND NOT Defined(SCS_SPA)}
          Application.HelpCommand(HELP_CONTEXT, 35000);
          {$IFEND}
        end;
    8:  begin
          {$IF NOT Defined(SCS_PE) AND NOT Defined(SCS_SPA)}
          Application.HelpCommand(HELP_CONTEXT, 74007);
          {$IFEND}
        end;

  end;
end;

procedure TF_FloatPanel.SpeedButton3Click(Sender: TObject);
begin
  Timer1.Enabled := False;
  Timer2.Enabled := True;
end;

end.
