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

📄 rm_dsgform.pas

📁 这是一个功能强大
💻 PAS
📖 第 1 页 / 共 5 页
字号:
    FPageEditor.FPopupMenu.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: Integer;
  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;
        FPageEditor.SendBandsToDown;
      end;
    finally
      tmp.Free;
    end;
  end;

  procedure _CreateSubReport;
  var
    lPage: TRMReportPage;
  begin
    t := RMCreateObject(rmgtSubReport, '');
    t.ParentPage := FDesignerForm.Page;
    TRMSubReportView(t).SubPage := FDesignerForm.Report.Pages.Count;
    with FDesignerForm, TRMReportPage(FDesignerForm.Page) do
    begin
      lPage := TRMReportPage(Report.Pages.AddReportPage);
      lPage.ChangePaper(PageSize, PrinterInfo.ScreenPageWidth, PrinterInfo.ScreenPageHeight, PageBin, PageOrientation);
      lPage.mmMarginLeft := mmMarginLeft;
      lPage.mmMarginTop := mmMarginTop;
      lPage.mmMarginRight := mmMarginRight;
      lPage.mmMarginBottom := mmMarginBottom;
      lPage.CreateName(True);
    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
            FPageEditor.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;

      lWidth := t.spWidth_Designer;
      lHeight := t.spHeight_Designer;
      RoundCoord(lWidth, lHeight);
      t.spWidth_Designer := lWidth;
      t.spHeight_Designer := lHeight;
      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;

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

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

    if t <> nil then
    begin
      _SetDefaultProp;
      FDesignerForm.SetObjectID(t);
      FDesignerForm.AddUndoAction(rmacInsert);
      _SetControlParent;
    end
    else
    begin
      FMoved := False;
      FCursorType := ctNone;
      FPageEditor.ToolbarComponent.btnNoSelect.Down := TRUE;
    end;
    if not FPageEditor.ObjRepeat then
      FPageEditor.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;
    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;
    FPageEditor.Editor_SelectionChanged(True);
    DrawPage(dmSelection);
    Exit;
  end;

  // splitting
  if FMoved and RM_SelectedManyObject and (Cursor = crHSplit) then //同时改变
  begin
    with 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;

  // redrawing all FMoved or resized objects
  if not FMoved then
  begin
    FPageEditor.Editor_SelectionChanged(True);
    DrawPage(dmSelection);
  end;
  if (FDesignerForm.SelNum >= 1) and FMoved then
  begin
    liNeedReDraw := True;
    if ((Cursor = crSizeNS) or FBandMoved) and FPageEditor.IsBandsSelect(t) then
    begin
    end;

    if FDesignerForm.SelNum > 1 then
    begin
      if liNeedRedraw then
      begin
        Draw(FDesignerForm.TopSelected, RM_ClipRgn);
        GetMultipleSelected;
        FPageEditor.Editor_SelectionChanged(True);
      end;
    end
    else
    begin
      t := FDesignerForm.PageObjects[FDesignerForm.TopSelected];
      NormalizeCoord(t);
      if liNeedRedraw then
        Draw(FDesignerForm.TopSelected, RM_ClipRgn);
      FPageEditor.Editor_SelectionChanged(True);
    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, lBnd: TRMView;
  liBand: TRMView;
  lRgn: HRGN;
  lFlag: Boolean;

  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;
      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 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;

⌨️ 快捷键说明

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