MY_IDE:一个将Delphi的组件面板转变为多层并能自动隐藏的组件

//Add MultiLinePalette function by luyear 20021101
//Add the function to forbid Autohide function by luyear 20021102
unit My_IDE;

interface

uses
  Windows, Messages, SysUtils, Classes, Controls, Forms, ComCtrls;

type
  TAutoHider = class(TObject)
  protected
    procedure DelphiOnMessage(var Msg: TMsg; var Handled: Boolean);
    procedure MyDockDrop(Sender: TObject; Source: TDragDockObject; X, Y: Integer);
    procedure MyDestroy(Sender: TObject);
  public
    OldDockDrop: TDockDropEvent;
    OldDestroy: TNotifyEvent;

    Delphi: TApplication;
    Bar_Top: TForm;
    Bar_Left: TForm;
    ObjInspector: TForm;
    DockHost: TForm;

    Bar_Top_Rect: TRect;
    Bar_Left_Rect: TRect;

    F_AtTop: Boolean;
    F_AtLeft: Boolean;

    procedure Init_Bar_Left;
    procedure Bar_Left_Visible(val: Boolean);
    procedure Bar_Top_Visible(Value: Boolean);
  end;
 
  TMultiLinePalette = class  //︽摸
  public
    procedure ResizeComponentPalette(Sender : TObject);
  end;

var
  AutoHider: TAutoHider;
  MultiLinePalette : TMultiLinePalette; //︽跑秖
 
implementation

{︽}
procedure TMultiLinePalette.ResizeComponentPalette(Sender : TObject);
var
AHeight : integer;
begin
with (Sender as TTabControl) do begin
AHeight := Height + DisplayRect.Top - DisplayRect.Bottom + 29;
Constraints.MinHeight := AHeight;
Parent.Constraints.MaxHeight := AHeight;
end;
end; {ResizeMultiLineComponentPalette}

procedure SetMultiLineComponentPalette(MultiLine : boolean);
var
AppBuilder : TForm;
TabControl : TTabControl;
begin
AppBuilder := TForm(Application.FindComponent('AppBuilder'));
if (AppBuilder <> nil) then begin
TabControl := TTabControl(AppBuilder.FindComponent('TabControl'));
if (TabControl <> nil) then begin
TabControl.MultiLine := MultiLine;
if MultiLine then
TabControl.OnResize := MultiLinePalette.ResizeComponentPalette
else
TabControl.OnResize := nil;
end;
end;
end; {SetMultiLineComponentPalette}


{ TAutoHide }

procedure Restore_Bar_Left;
begin
  AutoHider.ObjInspector.OnDockDrop := nil;

  if AutoHider.DockHost <> nil then
  begin
    AutoHider.DockHost.OnDestroy := nil;
  end;
  AutoHider.Bar_Left.BoundsRect := AutoHider.Bar_Left_Rect;
end;

procedure Restore_Bar_Top;
begin
  AutoHider.Bar_Top.BoundsRect := AutoHider.Bar_Top_Rect;
end;

procedure InitAutoHider(Value: Boolean);
begin
  if Value then
  begin
    AutoHider.Delphi  := Application;
    AutoHider.Bar_Top := TForm(Application.FindComponent('AppBuilder'));
    if AutoHider.Bar_Top <> nil then
    begin
      AutoHider.Bar_Top_Rect := AutoHider.Bar_Top.BoundsRect;

      AutoHider.ObjInspector  := AutoHider.Bar_Top.FindComponent('PropertyInspector')
        as TForm;
      AutoHider.Bar_Left_Rect := AutoHider.ObjInspector.BoundsRect;

      AutoHider.OldDockDrop := AutoHider.ObjInspector.OnDockDrop;
      AutoHider.ObjInspector.OnDockDrop := AutoHider.MyDockDrop;

      AutoHider.DockHost := nil;
      AutoHider.Init_Bar_Left;

      AutoHider.F_AtTop          := True;
      AutoHider.F_AtLeft         := True;
      AutoHider.Delphi.OnMessage := AutoHider.DelphiOnMessage;
    end;
  end
  else
  begin
    Restore_Bar_Left;
    Restore_Bar_Top;
  end;
end;

procedure TAutoHider.Bar_Top_Visible(Value: Boolean);
begin
  if Value = F_AtTop then Exit;

  if Value OR (Bar_top.windowstate=wsMaximized) then
  begin
    Bar_Top.Top := 0;
    Bar_Top.Show;
  end
  else
  begin
    Bar_Top.Top := -Bar_Top.Height + 3;
  end;

  F_AtTop := Value;
end;

procedure TAutoHider.Bar_Left_Visible(val: Boolean);
begin
  if val = F_AtLeft then Exit;

  if val OR (Bar_Left.windowstate=wsMaximized) then
  begin
    Bar_Left.Left   := 0;
    Bar_Left.Top    := 0;
    Bar_Left.Height := Screen.WorkAreaHeight;
    Bar_Left.Show;
  end
  else
  begin
    Bar_Left.Left := -Bar_Left.Width + 3;
  end;

  F_AtLeft := val;
end;

procedure TAutoHider.DelphiOnMessage(var Msg: TMsg; var Handled: Boolean);
begin
  if not Delphi.Active then Exit;
  if (Msg.message = WM_LBUTTONDOWN) then Exit;

  if (Msg.message = WM_MOUSEMOVE) or (Msg.message = WM_NCMOUSEMOVE) then
  begin
    if F_AtTop then
      if Mouse.CursorPos.Y > Bar_Top.Height + 50 then
      begin
        Bar_Top_Visible(False);
      end;
    if not F_AtTop then
      if Mouse.CursorPos.Y < 3 then
      begin
        Bar_Top_Visible(True);
      end;

    if F_AtLeft then
      if (Mouse.CursorPos.x > Bar_Left.Width + 50) and (not Bar_left.Active) then
      begin
        Bar_Left_Visible(False);
      end;
    if not F_AtLeft then
      if Mouse.CursorPos.X < 3 then
      begin
        Bar_Left_Visible(True);
      end;
  end;
end;

procedure TAutoHider.MyDestroy(Sender: TObject);
begin
  if Sender is TApplication then
  begin
    Bar_Top_Visible(False);
    Bar_Left_Visible(False);
  end
  else
  begin
    if Assigned(OldDestroy) then OldDestroy(Sender);
    DockHost := nil;
    Bar_Left := ObjInspector;
  end;
end;

procedure TAutoHider.Init_Bar_Left;
begin
  if (Delphi.FindComponent('TabDockHostForm') as TForm) <> nil then
    DockHost := Delphi.FindComponent('TabDockHostForm') as TForm
  else if (Delphi.FindComponent('JoinDockForm') as TForm) <> nil then
    DockHost := Delphi.FindComponent('JoinDockForm') as TForm;

  if DockHost <> nil then
  begin
    DockHost.Top       := 0;
    DockHost.Height    := Screen.WorkAreaHeight;
    OldDestroy         := DockHost.OnDestroy;
    DockHost.OnDestroy := MyDestroy;
    Bar_Left           := DockHost;
  end
  else
  begin
    Bar_Left := ObjInspector;
  end;
  //Add by luyear 021104
  Bar_left.Constraints.MaxWidth:=200;
  Bar_left.BorderStyle:= bsSizeAble;
end;

procedure TAutoHider.MyDockDrop(Sender: TObject; Source: TDragDockObject; X,
  Y: Integer);
begin
  if Assigned(OldDockDrop) then  OldDockDrop(Sender, Source, X, Y);
  Init_Bar_Left;
end;

initialization
  MultiLinePalette := TMultiLinePalette.Create;
  SetMultiLineComponentPalette(true);

  AutoHider := TAutoHider.Create;
  InitAutoHider(True);

finalization
  InitAutoHider(False);
  AutoHider.Delphi.OnMessage := nil;
  AutoHider.Free;
 
  SetMultiLineComponentPalette(false);
  MultiLinePalette.Free;
end.

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值