dcmain.pas.svn-base

来自「TFormDesigner allows you move and resize」· SVN-BASE 代码 · 共 2,066 行 · 第 1/5 页

SVN-BASE
2,066
字号
              ktSize: GrowRect(R,0,-1);
            end;
          VK_DOWN:
            case KeyType of
              ktSelect: Control:=FindNextControl(True);
              ktMove: OffsetRect(R,0,1);
              ktFastMove: OffsetRect(R,0,FGridStep);
              ktSize: GrowRect(R,0,1);
            end;
        end;
        if (KeyType<>ktSelect) and Assigned(ParentForm) then
        begin
          if not EqualRect(BoundsRect,R) then
          begin
            BoundsRect:=R;
            DoAfterDrag(SelectedControls[i]);
          end;
        end
        else Break;
      end;
    Update;
  end;

  function SelectableParent(AControl: TControl): TControl;
  begin
    if Assigned(AControl) then
    begin
      Result:=AControl.Parent;
      while Assigned(Result) and
        (Result<>ParentForm) and
        not IsSelectableControl(Result) and
        not (caLocked in ComponentAttributes(Result)) do Result:=Result.Parent;
      if Result=ParentForm then Result:=nil;
    end
    else Result:=nil;
  end;

begin
  MessageProcessor:=False;
  ProcessProtected(ParentForm);
  E:=False;
  if Assigned(FOnBeforeMessage) then FOnBeforeMessage(Self,Sender,Message,E);
  if not E then
  begin
    with Message do
      case Msg of
        WM_ACTIVATE: LeaveMouseAction;
        WM_CTLCOLORMSGBOX..WM_CTLCOLORSTATIC,WM_SIZE,WM_MOVE:
          if (SelectedControlCount=1) and (FMouseAction=maNone) then Update;
        WM_PAINT: PostMessage(ParentForm.Handle,WM_DRAWMULTISELECT,0,0);
        WM_DRAWMULTISELECT:
          if SelectedControlCount>1 then
            for i:=0 to Pred(SelectedControlCount) do DrawMultiSelect(SelectedControls[i]);
        WM_RBUTTONDOWN,WM_RBUTTONDBLCLK:
        begin
          ISender:=GetNonTransparent(GetFormOwned(Sender));
          if IsSelectable(ISender) then
            if Assigned(ISender) and (ISender<>ParentForm) then
            begin
              if IsSelectedControl(ISender) then SelectControl(ISender)
              else Control:=ISender;
              MessageProcessor:=True;
            end
            else DeselectAllControls;
          ShowGrabs;
        end;
        WM_RBUTTONUP:
        begin
          GetCursorPos(NewDrag);
          ISender:=GetNonTransparent(GetFormOwned(Sender));
          if Assigned(ISender) and (ISender<>ParentForm) then
            if not (caDefaultMenu in ComponentAttributes(ISender)) then
            begin
              if Assigned(FPopupMenu) then
                with NewDrag do FPopupMenu.Popup(X,Y);
              MessageProcessor:=True;
            end
            else
              if Assigned(ISender) then
                with TPopupControl(ISender),NewDrag do
                  if Assigned(PopupMenu) then
                    PopupMenu.Popup(X,Y);
        end;
        WM_LBUTTONDOWN:
        begin
          FActiveHandle:=FindHandle(Sender);
          ISender:=GetNonTransparent(GetFormOwned(Sender));
          if (ISender<>ParentForm) and not IsPressed(VK_CONTROL) then
          begin
            if (caEditable in ComponentAttributes(ISender)) or (FActiveHandle<>gpNone) then
            begin
              HideGrabs;
              if FActiveHandle=gpNone then
              begin
                if IsPressed(VK_SHIFT) then
                  if IsSelectedControl(ISender) and (SelectedControlCount>1) then DeselectControl(ISender)
                  else SelectControl(ISender)
                else
                begin
                  if (SelectedControlCount<2) or not IsSelectedControl(ISender) then Control:=ISender;
                  i:=0;
                  MS:=SelectedControlCount>1;
                  while i<SelectedControlCount do
                  begin
                    if MS then E:=not (caLocked in ComponentAttributes(SelectedControls[i]))
                    else E:=True;
                    if E then DoBeforeDrag(SelectedControls[i],E);
                    if not E then
                    begin
                      if not DeselectControl(SelectedControls[i]) then Inc(i);
                    end
                    else Inc(i);
                  end;
                end;
              end
              else
              begin
                E:=True;
                DoBeforeDrag(Control,E);
                if not E then DeselectControl(Control);
              end;
              if Assigned(Control) and not IsPressed(VK_SHIFT) then
              begin
                if (SelectedControlCount<>1) or not (caLocked in ComponentAttributes(Control)) then
                begin
                  if FActiveHandle=gpNone then CheckParent(ISender);
                  Application.ProcessMessages;
                  if Assigned(Control.Parent) then
                  begin
                    with Control.Parent,R do
                    begin
                      R:=ClientRect;
                      TopLeft:=ClientToScreen(TopLeft);
                      BottomRight:=ClientToScreen(BottomRight);
                    end;
                    ClipCursor(@R);
                  end;
                  GetCursorPos(FDragPoint);
                  FDragRect:=Control.BoundsRect;
                  DrawDragRects;
                  FMouseAction:=maDragging;
                end;
              end;
            end;
          end
          else
          begin
            DeselectAllControls;
            with FSelectRect do
            begin
              GetCursorPos(TopLeft);
              BottomRight:=TopLeft;
            end;
            if not (ISender is TWinControl) then ISender:=ISender.Parent;
            FSelect:=TWinControl(ISender);
            while Assigned(FSelect) and
              not (csAcceptsControls in FSelect.ControlStyle) do
              FSelect:=FSelect.Parent;
            if not Assigned(FSelect) then FSelect:=ParentForm;
            with FSelect,R do
            begin
              R:=ClientRect;
              TopLeft:=ClientToScreen(TopLeft);
              BottomRight:=ClientToScreen(BottomRight);
            end;
            ClipCursor(@R);
            DrawSelectRect;
            FMouseAction:=maSelecting;
          end;
          if not (ISender is TWinControl) then ISender:=ISender.Parent;
          SetCapture(TWinControl(ISender).Handle);
          MessageProcessor:=True;
        end;
        WM_LBUTTONDBLCLK:
        begin
          DoDblClick(Control);
          MessageProcessor:=True;
        end;
        WM_MOUSEMOVE:
        begin
          if not IsPressed(VK_LBUTTON) then LeaveMouseAction
          else
            case FMouseAction of
              maDragging:
              begin
                if Assigned(Control) then
                begin
                  GetCursorPos(NewDrag);
                  with NewDrag do
                  begin
                    X:=X-FDragPoint.X;
                    Y:=Y-FDragPoint.Y;
                    if (FActiveHandle=gpNone) and
                      FSnapToGrid and not IsPressed(VK_MENU) then
                    begin
                      X:=Round(X/FGridStep)*FGridStep;
                      Y:=Round(Y/FGridStep)*FGridStep;
                    end;
                  end;
                  if Assigned(Control) then R:=Control.BoundsRect;
                  with NewDrag do
                    case FActiveHandle of
                      gpNone: OffsetRect(R,X,Y);
                    else
                      with R do
                      begin
                        case FActiveHandle of
                          gpLeftTop:
                          begin
                            Left:=Left+X;
                            Top:=Top+Y;
                          end;
                          gpLeftMiddle: Left:=Left+X;
                          gpLeftBottom:
                          begin
                            Left:=Left+X;
                            Bottom:=Bottom+Y;
                          end;
                          gpMiddleTop: Top:=Top+Y;
                          gpMiddleBottom: Bottom:=Bottom+Y;
                          gpRightTop:
                          begin
                            Right:=Right+X;
                            Top:=Top+Y;
                          end;
                          gpRightMiddle: Right:=Right+X;
                          gpRightBottom:
                          begin
                            Right:=Right+X;
                            Bottom:=Bottom+Y;
                          end;
                        end;
                        if FSnapToGrid and not IsPressed(VK_MENU) then
                        begin
                          if FActiveHandle in [gpLeftTop,gpLeftMiddle,gpLeftBottom] then
                            Left:=Left div FGridStep * FGridStep;
                          if FActiveHandle in [gpLeftTop,gpMiddleTop,gpRightTop] then
                            Top:=Top div FGridStep * FGridStep;
                          if FActiveHandle in [gpRightTop,gpRightMiddle,gpRightBottom] then
                            Right:=Succ(Right div FGridStep * FGridStep);
                          if FActiveHandle in [gpLeftBottom,gpMiddleBottom,gpRightBottom] then
                            Bottom:=Succ(Bottom div FGridStep * FGridStep);
                        end;
                      end;
                    end;
                  if not EqualRect(R,FDragRect) then
                  begin
                    HideHint;
                    DrawDragRects;
                    FDragRect:=R;
                    DrawDragRects;
                    with FDragRect do
                      if FActiveHandle<>gpNone then Self.ShowHint(Format('%d x %d',[Abs(Right-Left),Abs(Bottom-Top)]),hmSize)
                      else
                      begin
                        NewDrag:=GetControlsOrigin;
                        with NewDrag do
                        begin
                          Inc(X,FDragRect.Left-Control.Left);
                          Inc(Y,FDragRect.Top-Control.Top);
                          Self.ShowHint(Format('%d, %d',[X,Y]),hmMove);
                        end;
                      end;
                  end;
                end;
              end;
            maSelecting:
            begin
              DrawSelectRect;
              GetCursorPos(FSelectRect.BottomRight);
              DrawSelectRect;
            end;
          end;
          MessageProcessor:=True;
        end;
        WM_LBUTTONUP:
        begin
          ReleaseCapture;
          ClipCursor(nil);
          HideHint;
          case FMouseAction of
            maDragging:
            begin
              DrawDragRects;
              if SelectedControlCount>1 then
              begin
                NewDrag.X:=FDragRect.Left-Control.Left;
                NewDrag.Y:=FDragRect.Top-Control.Top;
                for i:=0 to Pred(SelectedControlCount) do
                begin
                  R:=SelectedControls[i].BoundsRect;
                  OffsetRect(R,NewDrag.X,NewDrag.Y);
                  SelectedControls[i].BoundsRect:=R;
                  DoAfterDrag(SelectedControls[i]);
                end;
              end
              else
              begin
                FDragRect:=NormalizeRect(FDragRect);
                if Assigned(Control) then
                begin
                  if not EqualRect(FDragRect,Control.BoundsRect) then
                  begin
                    Control.BoundsRect:=FDragRect;
                    Update;
                    DoAfterDrag(Control);
                  end;
                  FDragRect:=Control.BoundsRect;
                end;
              end;
            end;
            maSelecting:
            begin
              DrawSelectRect;
              if Assigned(FSelect) then
              begin
                with FSelect do
                begin
                  FSelectRect:=NormalizeRect(FSelectRect);
                  with FSelectRect do
                  begin
                    TopLeft:=ScreenToClient(TopLeft);
                    BottomRight:=ScreenToClient(BottomRight);
                  end;
                  for i:=0 to Pred(ControlCount) do
                    if IsSelectableControl(Controls[i]) then
                    begin
                      IntersectRect(R,FSelectRect,Controls[i].BoundsRect);
                      if not IsRectEmpty(R) then SelectControl(Controls[i]);
                    end;
                end;
              end;
            end;
          end;
          ShowGrabs;
          Update;
          FMouseAction:=maNone;
          FActiveHandle:=gpNone;
          MessageProcessor:=True;
        end;
        WM_KEYDOWN:
        begin
          case wParam of
            VK_ESCAPE:
              if FMouseAction<>maNone then LeaveMouseAction
              else Control:=SelectableParent(Control);
            VK_TAB: Control:=FindNextControl(not IsPressed(VK_SHIFT));
            VK_RIGHT,VK_LEFT,VK_UP,VK_DOWN: ProcessKey(wParam);
            VK_INSERT:
              if IsPressed(VK_CONTROL) then CopyToClipboard
              else
                if IsPressed(VK_SHIFT) then PasteFromClipboard;
            VK_DELETE:
              if IsPressed(VK_SHIFT) then CutToClipboard
              else Delete;
            Ord('C'): if IsPressed(VK_CONTROL) then CopyToClipboard;
            Ord('X'): if IsPressed(VK_CONTROL) then CutToClipboard;
            Ord('V'): if IsPressed(VK_CONTROL) then PasteFromClipboard;
          end;
          MessageProcessor:=True;
        end;
        WM_SETCURSOR:
          if not IsPressed(VK_LBUTTON) then
            with Screen do
            begin
              if Sender=ParentForm then Cursor:=crDefault
              else
              begin
                if (caDefaultCursor in ComponentAttributes(Sender)) or (caProtected in ComponentAttributes(Sender)) then
                  SetCursor(Cursors[crArrow])
                else
                  if IsGrabHandle(Sender) and not (caLocked in ComponentAttributes(Control)) then
                    SetCursor(Cursors[Sender.Cursor])
                  else
                    if Cursor=crArrow then Cursor:=crDefault
                    else SetCursor(Cursors[crArrow]);
                MessageProcessor:=True;
              end;
            end
          else MessageProcessor:=True;
        $140..354:
        begin
          MessageProcessor:=True;
          Result:=1;
        end;
        WM_COMMAND: if LParam=0 then MessageProcessor:=True;
      end;
    if Assigned(FOnAfterMessage) then FOnAfterMessage(Self,Sender,Message,Result);
  end
  else MessageProcessor:=True;
end;

procedure TCustomDesignerComponent.NotificationProcessor(AComponent: TComponent; Operation: TOperation);
begin
  if not (csDestroying in ComponentState) and (Operation=opRemove) then
  begin
    Deselect(AComponent);
    if Assigned(FindComponentContainer(AComponent)) then
    begin
      with FindComponentContainer(AComponent) do
        if not (csDestroying in ComponentState) then Free;
    end
    else
      if (AComponent is TComponentContainer) and not FInternalDestroy then
        with TComponentContainer(AComponent).Component do
          if not (csDestroying in ComponentState) then Free;
  end;
end;

func

⌨️ 快捷键说明

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