⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dockwin.cpp

📁 C++Builder程序员编程手记《配书光盘》
💻 CPP
字号:
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "dockwin.h"
#include "Main.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TDockableForm *DockableForm;
//---------------------------------------------------------------------------
__fastcall TDockableForm::TDockableForm(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TDockableForm::FormClose(TObject *Sender,
      TCloseAction &Action)
{
  if (dynamic_cast<TPanel*>(HostDockSite) != NULL)
    MainWin->ShowPanel(static_cast<TPanel*>(HostDockSite), false, NULL);

  Action = caHide;
}
//---------------------------------------------------------------------------

void __fastcall TDockableForm::FormDockOver(TObject *Sender,
      TDragDockObject *Source, int X, int Y, TDragState State,
      bool &Accept)
{
  TRect ARect;

  Accept = (dynamic_cast<TDockableForm*>(Source->Control) != NULL);

  // Draw dock preview depending on where the cursor is relative to our client area
  if (Accept && (ComputerDockAlign(ARect, Point(X, Y)) != alNone))
    Source->DockRect = ARect;  
}
//---------------------------------------------------------------------------


TAlign TDockableForm::ComputerDockAlign(TRect & DockRect, const TPoint & MousePos)
{
  Windows::TRect  DockTopRect,
                  DockLeftRect,
                  DockBottomRect,
                  DockRightRect,
                  DockCenterRect;

  Windows::TPoint TopLeft,
                  BottomRight;

  TAlign Result = alNone;

  // Divide form up into docking "Zones"
  TopLeft = Windows::TPoint(0, 0);
  BottomRight = Windows::TPoint(ClientWidth / 5, ClientHeight);
  DockLeftRect = Windows::TRect(TopLeft, BottomRight);

  TopLeft = Windows::TPoint(ClientWidth / 5, 0);
  BottomRight = Windows::TPoint(ClientWidth / 5 * 4, ClientHeight / 5);
  DockTopRect = Windows::TRect(TopLeft, BottomRight);

  TopLeft = Windows::TPoint(ClientWidth / 5 * 4, 0);
  BottomRight = Windows::TPoint(ClientWidth, ClientHeight);
  DockRightRect = Windows::TRect(TopLeft, BottomRight);

  TopLeft = Windows::TPoint(ClientWidth / 5, ClientHeight / 5 * 4);
  BottomRight = Windows::TPoint(ClientWidth / 5 * 4, ClientHeight);
  DockBottomRect = Windows::TRect(TopLeft, BottomRight);

  TopLeft = Windows::TPoint(ClientWidth / 5, ClientHeight / 5);
  BottomRight = Windows::TPoint(ClientWidth / 5 * 4, ClientHeight / 5 * 4);
  DockCenterRect = Windows::TRect(TopLeft, BottomRight);

  // Find out where the mouse cursor is,
  // to decide where to draw dock preview.
  if (PtInRect(&DockLeftRect, MousePos))
  {
    Result = alLeft;
    DockRect = DockLeftRect;
    DockRect.Right = ClientWidth / 2;
  }
  else
    if (PtInRect(&DockTopRect, MousePos))
    {
      Result = alTop;
      DockRect = DockTopRect;
      DockRect.Left = 0;
      DockRect.Right = ClientWidth;
      DockRect.Bottom = ClientHeight / 2;
    }
    else
      if (PtInRect(&DockRightRect, MousePos))
      {
        Result = alRight;
        DockRect = DockRightRect;
        DockRect.Left = ClientWidth / 2;
      }
      else
        if (PtInRect(&DockBottomRect, MousePos))
        {
          Result = alBottom;
          DockRect = DockBottomRect;
          DockRect.Left = 0;
          DockRect.Right = ClientWidth;
          DockRect.Top = ClientHeight / 2;
        }
        else
          if (PtInRect(&DockCenterRect, MousePos))
          {
            Result = alClient;
            DockRect = DockCenterRect;
          }

  if (Result != alNone)
  {
    // DockRect is in screen coordinates.
    TopLeft = ClientToScreen(Windows::TPoint(DockRect.Left, DockRect.Top));
    BottomRight = ClientToScreen(Windows::TPoint(DockRect.Right, DockRect.Bottom));

    DockRect = TRect(TopLeft, BottomRight);
  }
  return Result;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -