rm_dsgform.pas

来自「胜天进销存源码,国产优秀的进销存」· PAS 代码 · 共 2,142 行 · 第 1/5 页

PAS
2,142
字号
      end;
    end;
  end;

  procedure _CheckWidthHeight(t: TRMView; aCursor1, aCursor2: TRMCursorType);
  begin
    if (t.spWidth_Designer < 0) or (t.spHeight_Designer < 0) then
    begin
      NormalizeCoord(t);
      FCursorType := aCursor1;
    end
    else
      FCursorType := aCursor2;
  end;

  function _isSplitting: Boolean;
    { 检查是不是两个选择了两个水平相连的对象,是的话,可以同时改变两个对象的width }
  var
    i, j: Integer;
  begin
    Result := False;
    if not FMouseButtonDown and (FDesignerForm.SelNum > 1) and (FMode = mdSelect) then
    begin
      for i := 0 to FDesignerForm.PageObjects.Count - 1 do
      begin
        t := FDesignerForm.PageObjects[i];
        if (not t.IsBand) and t.Selected then
        begin
          if (x >= t.spLeft_Designer) and (x <= t.spRight_Designer) and (y >= t.spTop_Designer) and (y <= t.spBottom_Designer) then
          begin
            for j := 0 to FDesignerForm.PageObjects.Count - 1 do
            begin
              t1 := FDesignerForm.PageObjects[j];
              if t1.IsBand or (t1 = t) or (not t1.Selected) then Continue;
              if (t.spLeft_Designer = t1.spRight_Designer) and (x >= t.spLeft_Designer) and (x <= t.spLeft_Designer + 2) then // 水平相邻,可以同时改变width
              begin
                Cursor := crHSplit;
                with FDesignerForm.FSplitInfo do
                begin
                  SplRect := Rect(x, t.spTop_Designer, x, t.spTop_Designer + t.spHeight_Designer);
                  if t.spLeft_Designer = t1.spLeft_Designer + t1.spWidth_Designer then
                  begin
                    SplX := t.spLeft_Designer;
                    View1 := t1;
                    View2 := t;
                  end
                  else
                  begin
                    SplX := t1.spLeft_Designer;
                    View1 := t;
                    View2 := t1;
                  end;
                  SplRect.Left := SplX;
                  SplRect.Right := SplX;
                end;
              end;
            end;
          end;
        end;
      end;
    end;

    // splitting
    if (Cursor = crHSplit) and FMouseButtonDown and RM_SelectedManyObject and (FMode = mdSelect) then
    begin
      Result := True;
      kx := x - FLastX;
      ky := 0;
      if (not FDesignerForm.GridAlign) or GridCheck then
      begin
        with FDesignerForm.FSplitInfo do
        begin
          DrawHSplitter(SplRect);
          SplRect := Rect(SplRect.Left + kx, SplRect.Top, SplRect.Right + kx, SplRect.Bottom);
          DrawHSplitter(SplRect);
        end;
        FLastX := x - ((x - FLastX) - kx);
      end;
    end;
  end;

  procedure _SetMaxResizeHeight(aBand: TRMView; var ky: Integer);
  var
    i, lidx: Integer;
    t: TRMView;
  begin
    if ky >= 0 then Exit;
    for i := 0 to FDesignerForm.PageObjects.Count - 1 do
    begin
      t := FDesignerForm.PageObjects[i];
      if (not t.IsBand) and (t.spTop_Designer >= aBand.spTop_Designer) and (t.spBottom_Designer <= aBand.spBottom_Designer) then
      begin
        lidx := aBand.spBottom_Designer - t.spBottom_Designer;
        if lidx < -ky then
          ky := -lidx;
      end;
    end;
    if - ky > aBand.spHeight_Designer then ky := -aBand.spHeight_Designer;
  end;

  procedure _GetDefaultSize(var aKx, aKy: Integer);
  var
    lIndex: Integer;
  begin
    if FDesignerForm.Page is TRMDialogPage then
    begin
      lIndex := FDesignerForm.ToolbarComponent.SelectedObjIndex;
      if lIndex >= rmgtAddIn then
        RMAddIns(lIndex - rmgtAddIn).ClassRef.DefaultSize(aKx, aKy);
    end
    else
      FDesignerForm.GetDefaultSize(kx, ky);
  end;
  
begin
  FMoved := True;
  w := 2;
  if RM_FirstChange and FMouseButtonDown and not FObjectsSelecting then
  begin
    kx := x - FLastX;
    ky := y - FLastY;
    if not FDesignerForm.GridAlign or GridCheck then
    begin
      FDesignerForm.GetRegion;
      if (kx <> 0) or (ky <> 0) then
        FDesignerForm.AddUndoAction(acEdit);
    end;
  end;

  if not FMouseButtonDown then
  begin
    if FDesignerForm.ToolbarComponent.btnNoSelect.Down then
    begin
      FMode := mdSelect;
      Cursor := crDefault;
      if FDesignerForm.SelNum = 0 then
      begin
        FDesignerForm.FShowSizes := False;
        RM_OldRect := Rect(x, y, x, y);
        FDesignerForm.ShowObjMsg;
      end;
    end
    else
    begin
      FMode := mdInsert; // 选择了控件,准备增加
      if Cursor <> crCross then
      begin
        RoundCoord(x, y);
        _GetDefaultSize(kx, ky);
        //FDesignerForm.GetDefaultSize(kx, ky);
        RM_OldRect := Rect(x, y, x + kx, y + ky);
        //if FDesignerForm.Page is TRMReportPage then
          DrawFocusRect(RM_OldRect);
      end;
      Cursor := crCross;
    end;
  end;

  if (FMode = mdInsert) and (not FMouseButtonDown) then
  begin
    //if FDesignerForm.Page is TRMReportPage then
      DrawFocusRect(RM_OldRect);
    RoundCoord(x, y);
    OffsetRect(RM_OldRect, x - RM_OldRect.Left, y - RM_OldRect.Top);
    //if FDesignerForm.Page is TRMReportPage then
      DrawFocusRect(RM_OldRect);
    FDesignerForm.FShowSizes := True;
    FDesignerForm.ShowObjMsg;
    FDesignerForm.FShowSizes := False;
    Exit;
  end;

  // cursor shapes
  if not FMouseButtonDown and (FDesignerForm.SelNum = 1) and (FMode = mdSelect) then
  begin
    t := FDesignerForm.PageObjects[FDesignerForm.TopSelected];
    if Cont(t.spLeft_Designer, t.spTop_Designer, x, y) or Cont(t.spLeft_Designer + t.spWidth_Designer, t.spTop_Designer + t.spHeight_Designer, x, y) then
      Cursor := crSizeNWSE // 改变一个对象大小
    else if Cont(t.spLeft_Designer + t.spWidth_Designer, t.spTop_Designer, x, y) or Cont(t.spLeft_Designer, t.spTop_Designer + t.spHeight_Designer, x, y) then
      Cursor := crSizeNESW
    else if Cont(t.spLeft_Designer + t.spWidth_Designer div 2, t.spTop_Designer, x, y) or Cont(t.spLeft_Designer + t.spWidth_Designer div 2, t.spTop_Designer + t.spHeight_Designer, x, y) then
      Cursor := crSizeNS
    else if Cont(t.spLeft_Designer, t.spTop_Designer + t.spHeight_Designer div 2, x, y) or Cont(t.spLeft_Designer + t.spWidth_Designer, t.spTop_Designer + t.spHeight_Designer div 2, x, y) then
      Cursor := crSizeWE
    else
      Cursor := crDefault;
  end;

  // selecting a lot of objects
  if FMouseButtonDown and FObjectsSelecting then
  begin
    DrawFocusRect(RM_OldRect);
    if Cursor = crCross then
      RoundCoord(x, y);
    RM_OldRect := Rect(RM_OldRect.Left, RM_OldRect.Top, x, y);
    DrawFocusRect(RM_OldRect);
    FDesignerForm.FShowSizes := True;
    if Cursor = crCross then
      FDesignerForm.ShowObjMsg;
    FDesignerForm.FShowSizes := False;
    Exit;
  end;

  // selecting a lot of objects
  if FObjectsSelecting then // 选择Objects
  begin
    DrawFocusRect(RM_OldRect);
    RM_OldRect := Rect(RM_OldRect.Left, RM_OldRect.Top, x, y);
    DrawFocusRect(RM_OldRect);
    Exit;
  end;

  // check for multiple selected objects - right-bottom corner
  if not FMouseButtonDown and (FDesignerForm.SelNum > 1) and (FMode = mdSelect) then
  begin
    t := FDesignerForm.PageObjects[FRightBottom];
    if Cont(t.spLeft_Designer + t.spWidth_Designer, t.spTop_Designer + t.spHeight_Designer, x, y) then
      Cursor := crSizeNWSE // 可以同时改变多个对象的大小
  end;

  if _IsSplitting then
  begin
    Exit;
  end;

  // sizing several objects
  if FMouseButtonDown and RM_SelectedManyObject and (FMode = mdSelect) and (Cursor <> crDefault) then
  begin
    kx := x - FLastX;
    ky := y - FLastY;
    if FDesignerForm.GridAlign and not GridCheck then Exit;
    DrawFocusRect(RM_OldRect);
    RM_OldRect := Rect(RM_OldRect.Left, RM_OldRect.Top, RM_OldRect.Right + kx, RM_OldRect.Bottom + ky);
    DrawFocusRect(RM_OldRect);
    FLastX := x - ((x - FLastX) - kx);
    FLastY := y - ((y - FLastY) - ky);
    FDesignerForm.ShowObjMsg;
    Exit;
  end;

  // moving
  if FMouseButtonDown and (FMode = mdSelect) and (FDesignerForm.SelNum >= 1) and (Cursor = crDefault) then
  begin
    kx := x - FLastX;
    ky := y - FLastY;
    if FDesignerForm.GridAlign and not GridCheck then Exit;
    if RM_FirstBandMove and (FDesignerForm.SelNum = 1) and ((kx <> 0) or (ky <> 0)) and not (ssAlt in Shift) then
    begin
      if TRMView(FDesignerForm.PageObjects[FDesignerForm.TopSelected]).isBand then
      begin
        Bnd := FDesignerForm.PageObjects[FDesignerForm.TopSelected];
        for i := 0 to FDesignerForm.PageObjects.Count - 1 do
        begin
          t := FDesignerForm.PageObjects[i];
          if not t.IsBand then
            if (t.spLeft_Designer >= Bnd.spLeft_Designer) and (t.spLeft_Designer + t.spWidth_Designer <= Bnd.spLeft_Designer + Bnd.spWidth_Designer) and
              (t.spTop_Designer >= Bnd.spTop_Designer) and (t.spTop_Designer + t.spHeight_Designer <= Bnd.spTop_Designer + Bnd.spHeight_Designer) then
            begin
              t.Selected := True;
              Inc(FDesignerForm.SelNum);
            end;
        end;
        GetMultipleSelected;
      end;
    end;

    if (kx <> 0) or (ky <> 0) then
    begin
      RM_FirstBandMove := False;
    end;
    DrawPage(dmShape);

    for i := 0 to FDesignerForm.PageObjects.Count - 1 do
    begin
      t := FDesignerForm.PageObjects[i];
      if not t.Selected then Continue;

      if t.IsCrossBand then
      begin
        t.spLeft_Designer := t.spLeft_Designer + kx;
        if kx <> 0 then FDesignerForm.Modified := True;
      end
      else if not FDesignerForm.IsBandsSelect(liBand) then //对Band,控制其不能左右移动!
      begin
        t.spLeft_Designer := t.spLeft_Designer + kx;
        if kx <> 0 then
        begin
          FDesignerForm.Modified := True;
          FBandMoved := True;
        end;
      end;
      t.spTop_Designer := t.spTop_Designer + ky;
      if ky <> 0 then
      begin
        FDesignerForm.Modified := True;
        FBandMoved := True;
      end;
    end;
    DrawPage(dmShape);
    Inc(FLastX, kx);
    Inc(FLastY, ky);
    FDesignerForm.ShowObjMsg;
  end;

  // resizing
  if FMouseButtonDown and (FMode = mdSelect) and (FDesignerForm.SelNum = 1) and (Cursor <> crDefault) then
  begin
    kx := x - FLastX;
    ky := y - FLastY;
    if FDesignerForm.GridAlign and not GridCheck then Exit;
    DrawPage(dmShape);
    t := FDesignerForm.PageObjects[FDesignerForm.TopSelected];
    if t.IsBand then
    begin
      if TRMCustomBandView(t).BandType in [rmbtCrossHeader, rmbtCrossData, rmbtCrossFooter] then
        ky := 0
      else
      begin
        kx := 0;
        _SetMaxResizeHeight(t, ky);
      end;
    end;
    FDesignerForm.Modified := True;
    w := 3;
    if Cursor = crSizeNWSE then // 右下角,左上角
    begin
      if ((FCursorType = ct1) or Cont(t.spLeft_Designer, t.spTop_Designer, FLastX, FLastY)) and
        (FCursorType <> ct2) then
      begin
        t.spLeft_Designer := t.spLeft_Designer + kx;
        t.spWidth_Designer := t.spWidth_Designer - kx;
        t.spTop_Designer := t.spTop_Designer + ky;
        t.spHeight_Designer := t.spHeight_Designer - ky;
        _CheckWidthHeight(t, ct2, ct1);
      end
      else
      begin
        t.spWidth_Designer := t.spWidth_Designer + kx;
        t.spHeight_Designer := t.spHeight_Designer + ky;
        _CheckWidthHeight(t, ct1, ct2);
      end;
      if (ky <> 0) and t.IsBand and (not t.IsCrossBand) then
        FBandMoved := True;
    end;

    if Cursor = crSizeNESW then // 右上角,左下角
    begin
      if ((FCursorType = ct3) or Cont(t.spLeft_Designer + t.spWidth_Designer, t.spTop_Designer, FLastX, FLastY)) and
        (FCursorType <> ct4) then
      begin
        t.spTop_Designer := t.spTop_Designer + ky;
        t.spWidth_Designer := t.spWidth_Designer + kx;
        t.spHeight_Designer := t.spHeight_Designer - ky;
        _CheckWidthHeight(t, ct4, ct3);
      end
      else
      begin
        t.spLeft_Designer := t.spLeft_Designer + kx;
        t.spWidth_Designer := t.spWidth_Designer - kx;
        t.spHeight_Designer := t.spHeight_Designer + ky;
        _CheckWidthHeight(t, ct3, ct4);
      end;
      if (ky <> 0) and t.IsBand and (not t.IsCrossBand) then
        FBandMoved := True;
    end;

    if Cursor = crSizeWE then // 改变width
    begin
      if ((FCursorType = ct5) or Cont(t.spLeft_Designer, t.spTop_Designer + t.spHeight_Designer div 2, FLastX, FLastY)) and
        (FCursorType <> ct6) then
      begin
        t.spLeft_Designer := t.spLeft_Designer + kx;
        t.spWidth_Designer := t.spWidth_Designer - kx;
        _CheckWidthHeight(t, ct6, ct5);
      end
      else
      begin
        t.spWidth_Designer := t.spWidth_Designer + kx;
        _CheckWidthHeight(t, ct5, ct6);
      end;
    end;

    if Cursor = crSizeNS then // 改变Height
    begin
      if ((FCursorType = ct7) or Cont(t.spLeft_Designer + t.spWidth_Designer div 2, t.spTop_Designer, FLastX, FLastY)) and
        (FCursorType <> ct8) then
      begin
        t.spTop_Designer := t.spTop_Designer + ky;
        t.spHeight_Designer := t.spHeight_Designer - ky;
        _CheckWidthHeight(t, ct8, ct7);
      end
      else
      begin
        t.spHeight_Designer := t.spHeight_Designer + ky;
        _CheckWidthHeight(t, ct7, ct8);
      end;
    end;

    DrawPage(dmShape);
    FLastX := x - ((x - FLastX) - kx);
    FLastY := y - ((y - FLastY) - ky);
    FDesignerForm.ShowObjMsg;
  end;
end;

procedure TRMWorkSpace.CMMouseLeave(var Message: TMessage);
begin
  inherited;
  if ((FMode = mdInsert) and not FMouseButtonDown) or FDragFlag then
  begin
    //if FDesignerForm.Page is TRMReportPage then
      DrawFocusRect(RM_OldRect);
    OffsetRect(RM_OldRect, -10000, -10000);
    Exit;
  end;
end;

procedure TRMWorkSpace.OnDoubleClickEvent(Sender: TObject);
begin
  FMouseButtonDown := False;
  if FDesignerForm.SelNum = 0 then
  begin
    if FDesignerForm.Page is TRMReportPage then
    begin
      //FDesignerForm.ToolbarStandard.btnPageSetup.Click;
      FDoubleClickFlag 

⌨️ 快捷键说明

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