rm_dsgform.pas

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

PAS
2,142
字号
        f := True;
        break;
      end;
    end;
    if not f then
    begin
      FDesignerForm.UnselectAll;
      FDesignerForm.SelNum := 0;
      FDesignerForm.FirstSelected := nil;
      if Button = mbLeft then
      begin
        FObjectsSelecting := True;
        RM_OldRect := Rect(x, y, x, y);
        Exit;
      end;
    end;
    GetMultipleSelected;
    if not DontChange then FDesignerForm.SelectionChanged(True);
  end;

  if FDesignerForm.SelNum = 0 then
  begin // reset multiple selection
    FRightBottom := -1;
    RM_SelectedManyObject := False;
  end;
  FLastX := x;
  FLastY := y;
  FMoved := False;
  RM_FirstChange := True;
  RM_FirstBandMove := True;
  if Button = mbRight then
  begin
    DrawPage(dmSelection);
    FMouseButtonDown := False;
    GetCursorPos(p);
    FDesignerForm.SelectionChanged(True);
    FDesignerForm.ObjectPopupMenu.Popup(p.X, p.Y);
  end
  else
    DrawPage(dmShape);
end;

procedure TRMWorkSpace.OnMouseUpEvent(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var
  i, dx, dy: Integer;
  nx, ny, x1, x2, y1, y2: Double;
  t: TRMView;
  liNeedReDraw: Boolean;
  lObjectInserted: Boolean;

  function _GetUnusedBand: TRMBandType;
  var
    b: TRMBandType;
  begin
    Result := rmbtNone;
    for b := rmbtReportTitle to rmbtNone do
    begin
      if not FDesignerForm.RMCheckBand(b) then
      begin
        Result := b;
        Break;
      end;
    end;
    if Result = rmbtNone then
      Result := rmbtMasterData;
  end;

  procedure _AddObject(aType: Byte; aClassName: string);
  begin
    t := RMCreateObject(aType, aClassName);
    t.ParentPage := FDesignerForm.Page;
  end;

  procedure _SetControlParent;
  var
    i: Integer;
    lView: TRMView;
  begin
    if t is TRMDialogControl then
    begin
      for i := FDesignerForm.Page.Objects.Count - 2 downto 0 do
      begin
        lView := FDesignerForm.Page.Objects[i];
        if THackView(lView).IsContainer and
          (t.spLeft >= lView.spLeft) and (t.spTop >= lView.spTop) and
          (t.spLeft <= lView.spBottom) and (t.spTop <= lView.spBottom) then
        begin
          THackDialogControl(t).ParentControl := lView.Name;
          THackView(t).IsChildView := True;
          Break;
        end;
      end;
    end;
  end;

  procedure _CreateSection;
  var
    tmp: TRMBandTypesForm;
    lSubReportView: TRMView;
  begin
    tmp := TRMBandTypesForm.Create(nil);
    try
      lSubReportView := FDesignerForm.IsSubreport(FDesignerForm.CurPage);
      if (lSubReportView <> nil) and (TRMSubReportView(lSubReportView).SubReportType = rmstChild) then
        tmp.IsSubreport := True
      else
        tmp.IsSubreport := False;

      lObjectInserted := tmp.ShowModal = mrOk;
      if lObjectInserted then
      begin
        t := RMCreateBand(tmp.SelectedTyp);
        t.ParentPage := FDesignerForm.Page;
        FDesignerForm.SendBandsToDown;
      end;
    finally
      tmp.Free;
    end;
  end;

  procedure _CreateSubReport;
  var
    liPage: TRMReportPage;
  begin
    t := RMCreateObject(rmgtSubReport, '');
    t.ParentPage := FDesignerForm.Page;
    TRMSubReportView(t).SubPage := FDesignerForm.Report.Pages.Count;
    with FDesignerForm, TRMReportPage(FDesignerForm.Page) do
    begin
      liPage := TRMReportPage(Report.Pages.AddReportPage);
      liPage.ChangePaper(PageSize, PrinterInfo.PageWidth, PrinterInfo.PageHeight, PageBin, PageOrientation);
      liPage.mmMarginLeft := mmMarginLeft;
      liPage.mmMarginTop := mmMarginTop;
      liPage.mmMarginRight := mmMarginRight;
      liPage.mmMarginBottom := mmMarginBottom;
      liPage.CreateName;
    end;
    FDesignerForm.SetPageTabs;
    FDesignerForm.CurPage := FDesignerForm.CurPage;
  end;

  procedure _SetDefaultProp;
  var
    lWidth, lHeight: Integer;
    lSaveDesignerRestrictions: TRMDesignerRestrictions;
  begin
    FDesignerForm.Modified := True;
    lSaveDesignerRestrictions := FDesignerForm.DesignerRestrictions;
    FDesignerForm.DesignerRestrictions := [];
    try
      with RM_OldRect do
      begin
        if (Left = Right) or (Top = Bottom) then
        begin
          lWidth := 36;          lHeight := 36;
          if t is TRMCustomMemoView then
            FDesignerForm.GetDefaultSize(lWidth, lHeight)
          else if FDesignerForm.Page is TRMDialogPage then
            t.DefaultSize(lWidth, lHeight);

          RM_OldRect := Rect(Left, Top, Left + lWidth, Top + lHeight);
        end;
      end;

      FDesignerForm.UnselectAll;
      t.Selected := True;
      t.spLeft_Designer := RM_OldRect.Left;
      t.spTop_Designer := RM_OldRect.Top;
      if (t.spWidth_Designer = 0) and (t.spHeight_Designer = 0) then
      begin
        t.spWidth_Designer := RM_OldRect.Right - RM_OldRect.Left;
        t.spHeight_Designer := RM_OldRect.Bottom - RM_OldRect.Top;
      end;
      if t.IsBand and t.IsCrossBand then
      begin
        t.spWidth_Designer := 40;
      end;

      if t is TRMCustomMemoView then
      begin
        t.LeftFrame.Visible := RM_LastLeftFrameVisible;
        t.TopFrame.Visible := RM_LastTopFrameVisible;
        t.RightFrame.Visible := RM_LastRightFrameVisible;
        t.BottomFrame.Visible := RM_LastBottomFrameVisible;
        t.LeftFrame.mmWidth := RM_LastFrameWidth;
        t.TopFrame.mmWidth := RM_LastFrameWidth;
        t.RightFrame.mmWidth := RM_LastFrameWidth;
        t.BottomFrame.mmWidth := RM_LastFrameWidth;
        t.LeftFrame.Color := RM_LastFrameColor;
        t.TopFrame.Color := RM_LastFrameColor;
        t.RightFrame.Color := RM_LastFrameColor;
        t.BottomFrame.Color := RM_LastFrameColor;
        t.FillColor := RM_LastFillColor;
        with TRMCustomMemoView(t) do
        begin
          Font.Name := RM_LastFontName;
          Font.Size := RM_LastFontSize;
          Font.Style := RMSetFontStyle(RM_LastFontStyle);
          Font.Color := RM_LastFontColor;
          Font.Charset := RM_LastFontCharset;
          HAlign := RM_LastHAlign;
          VAlign := RM_LastVAlign;
        end;
      end;

      if t is TRMDialogControl then
      begin
        THackDialogControl(t).Font := t.ParentPage.Font;
      end;

      FDesignerForm.SelNum := 1;
      if t.IsBand then
        Draw(10000, t.GetClipRgn(rmrtExtended))
      else
      begin
        t.Draw(Canvas);
        DrawSelection(t);
      end;

      FDesignerForm.SelectionChanged(True);
    finally
      FDesignerForm.DesignerRestrictions := lSaveDesignerRestrictions;
    end;
  end;

  procedure _InsertControl;
  begin
    t := nil;
    if FDesignerForm.DesignerRestrictions * [rmdrDontCreateObj] = [] then
    begin
      if FDesignerForm.ToolbarComponent.SelectedObjIndex >= 0 then
      begin
        case FDesignerForm.ToolbarComponent.SelectedObjIndex of
          rmgtBand:
            begin
              if _GetUnusedBand <> rmbtNone then
                _CreateSection;
            end;
          rmgtSubReport:
            _CreateSubReport;
        else
          if FDesignerForm.ToolbarComponent.SelectedObjIndex >= rmgtAddIn then
            _AddObject(rmgtAddIn, RMAddIns(FDesignerForm.ToolbarComponent.SelectedObjIndex - rmgtAddIn).ClassRef.ClassName)
          else
            _AddObject(FDesignerForm.ToolbarComponent.SelectedObjIndex, '');
        end;
      end;
    end;

    if t <> nil then
    begin
      _SetDefaultProp;
      FDesignerForm.SetObjectID(t);
      FDesignerForm.AddUndoAction(acInsert);
      _SetControlParent;
    end
    else
    begin
      FMoved := False;
      FCursorType := ctNone;
      FDesignerForm.ToolbarComponent.btnNoSelect.Down := TRUE;
    end;
    if not FDesignerForm.FObjRepeat then
      FDesignerForm.ToolbarComponent.btnNoSelect.Down := True
    else
      DrawFocusRect(RM_OldRect);
  end;

begin
  if Button <> mbLeft then Exit;
  FMouseButtonDown := False;
  DrawPage(dmShape);

  //inserting a new object
  if Cursor = crCross then
  begin
    FMode := mdSelect;
//    if FDesignerForm.Page is TRMReportPage then
    begin
      DrawFocusRect(RM_OldRect);
      if (RM_OldRect.Left = RM_OldRect.Right) and
        (RM_OldRect.Top = RM_OldRect.Bottom) then
        RM_OldRect := RM_OldRect1;
    end;
    NormalizeRect(RM_OldRect);
    FObjectsSelecting := False;

    FObjectsSelecting := False;
    _InsertControl;
    Exit;
  end;

  //calculating which objects contains in frame (if user select it with mouse+Ctrl key)
  if FObjectsSelecting then
  begin
    DrawFocusRect(RM_OldRect);
    FObjectsSelecting := False;
    NormalizeRect(RM_OldRect);
    for i := 0 to FDesignerForm.PageObjects.Count - 1 do
    begin
      t := FDesignerForm.PageObjects[i];
      if t.IsBand then Continue;
      with RM_OldRect do
      begin
        if not ((t.spLeft_Designer > Right) or (t.spLeft_Designer + t.spWidth_Designer < Left) or
          (t.spTop_Designer > Bottom) or (t.spTop_Designer + t.spHeight_Designer < Top)) then
        begin
          t.Selected := True;
          Inc(FDesignerForm.SelNum);
        end;
      end;
    end;
    GetMultipleSelected;
    FDesignerForm.SelectionChanged(True);
    DrawPage(dmSelection);
    Exit;
  end;

  // splitting
  if FMoved and RM_SelectedManyObject and (Cursor = crHSplit) then //同时改变
  begin
    with FDesignerForm.FSplitInfo do
    begin
      dx := SplRect.Left - SplX;
      if (View1.spWidth_Designer + dx > 0) and (View2.spWidth_Designer - dx > 0) then
      begin
        View1.spWidth_Designer := View1.spWidth_Designer + dx;
        View2.spLeft_Designer := View2.spLeft_Designer + dx;
        View2.spWidth_Designer := View2.spWidth_Designer - dx;
        FDesignerForm.Modified := True;
      end;
    end;
    GetMultipleSelected;
    Draw(FDesignerForm.TopSelected, RM_ClipRgn);
    Exit;
  end;

  // resizing several objects
  if FMoved and RM_SelectedManyObject and (Cursor <> crDefault) then
  begin
    DrawFocusRect(RM_OldRect);
    nx := (RM_OldRect.Right - RM_OldRect.Left) / (RM_OldRect1.Right - RM_OldRect1.Left);
    ny := (RM_OldRect.Bottom - RM_OldRect.Top) / (RM_OldRect1.Bottom - RM_OldRect1.Top);
    for i := 0 to FDesignerForm.PageObjects.Count - 1 do
    begin
      t := FDesignerForm.PageObjects[i];
      if t.Selected then
      begin
        x1 := (THackView(t).OriginalRect.Left - FLeftTop.x) * nx;
        x2 := THackView(t).OriginalRect.Right * nx;
        dx := Round(x1 + x2) - (Round(x1) + Round(x2));
        t.spLeft_Designer := FLeftTop.x + Round(x1);
        t.spWidth_Designer := Round(x2) + dx;

        y1 := (THackView(t).OriginalRect.Top - FLeftTop.y) * ny;
        y2 := THackView(t).OriginalRect.Bottom * ny;
        dy := Round(y1 + y2) - (Round(y1) + Round(y2));
        t.spTop_Designer := FLeftTop.y + Round(y1);
        t.spHeight_Designer := Round(y2) + dy;
        FDesignerForm.Modified := True;
      end;
    end;
    Draw(FDesignerForm.TopSelected, RM_ClipRgn);
    Exit;
  end;

  // redrawing all FMoved or resized objects
  if not FMoved then
  begin
    FDesignerForm.SelectionChanged(True);
    DrawPage(dmSelection);
  end;
  if (FDesignerForm.SelNum >= 1) and FMoved then
  begin
    liNeedReDraw := True;
    if ((Cursor = crSizeNS) or FBandMoved) and FDesignerForm.IsBandsSelect(t) then
    begin
      if FDesignerForm.AutoChangeBandPos and FDesignerForm.Page.UpdateBandsPageRect then
      begin
        FDesignerForm.RedrawPage;
        FDesignerForm.Modified := True;
        liNeedRedraw := False;
      end;
    end;

    if FDesignerForm.SelNum > 1 then
    begin
      if liNeedRedraw then
      begin
        Draw(FDesignerForm.TopSelected, RM_ClipRgn);
        GetMultipleSelected;
        FDesignerForm.SelectionChanged(True);
      end;
    end
    else
    begin
      t := FDesignerForm.PageObjects[FDesignerForm.TopSelected];
      NormalizeCoord(t);
      if liNeedRedraw then
        Draw(FDesignerForm.TopSelected, RM_ClipRgn);
      FDesignerForm.SelectionChanged(True);
      //      FDesignerForm.ShowPosition;
    end;
  end;
  FMoved := False;
  FCursorType := ctNone;
end;

procedure TRMWorkSpace.OnMouseMoveEvent(Sender: TObject; Shift: TShiftState; X, Y: Integer);
var
  i, kx, ky, w: Integer;
  t, t1, Bnd: TRMView;
  liBand: TRMView;

  function Cont(px, py, x, y: Integer): Boolean;
  begin
    Result := (x >= px - w) and (x <= px + w + 1) and (y >= py - w) and (y <= py + w + 1);
  end;

  function GridCheck: Boolean;
  begin
    with FDesignerForm do
    begin
      Result := (kx >= GridSize) or (kx <= -GridSize) or
        (ky >= GridSize) or (ky <= -GridSize);
      if Result then
      begin
        kx := kx - kx mod GridSize;
        ky := ky - ky mod GridSize;

⌨️ 快捷键说明

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