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

📄 frxdesgnworkspace1.pas

📁 报表源码 FastReport 3 is new generation of the report generators components. It consists of report engin
💻 PAS
📖 第 1 页 / 共 2 页
字号:
            FLastMousePointY:= Y;
        end;
    end;
  end
  else if FTool = dtZoom then
    Cursor:= crZoom
  else if FTool = dtText then
    Cursor:= crIBeam
  else if FTool = dtFormat then
    Cursor:= crFormat;

  if not FMouseDown and (FMode = dmSelect) and
    ((FMode1 = dmNone) or (FMode1 = dmMoveGuide)) and not FListBox.Visible then
  begin
    if FPage is TfrxReportPage then
    begin
      for i:= 0 to HGuides.Count-1 do
      begin
        e:= frxStrToFloat(HGuides[i]);
        if (Y / Scale > e-5) and (Y / Scale < e+5) then
        begin
          FMode1:= dmMoveGuide;
          Cursor:= crVSplit;
          FGuide:= i;
        end;
      end;

      for i:= 0 to VGuides.Count-1 do
      begin
        e:= frxStrToFloat(VGuides[i]);
        if (X / Scale > e-5) and (X / Scale < e+5) then
        begin
          FMode1:= dmMoveGuide;
          Cursor:= crHSplit;
          FGuide:= i;
        end;
      end;
    end;

    if FMode1 = dmNone then
    begin
      cOver:= nil;
      for i:= FObjects.Count-1 downto 0 do
      begin
        c:= FObjects[i];
        if (c is TfrxMemoView) and Contain(c) and
           (c.Parent is TfrxDataBand) and
           (TfrxDataBand(c.Parent).Dataset<>nil) and
           (TfrxDataBand(c.Parent).Dataset.FieldsCount > 0) then
        begin
          ds:= TfrxDataBand(c.Parent).Dataset;
          if ds<>nil then
            cOver:= c;
          break;
        end;
      end;

      if FMemo<>cOver then
      begin
        FMemo:= TfrxMemoView(cOver);
        Repaint;
      end;
    end;
  end;

// moving the guideline
  if FMouseDown and (FMode1 = dmMoveGuide) then
  begin
    if Cursor = crHSplit then
    begin
      e:= frxStrToFloat(VGuides[FGuide]);
      kx:= X / Scale-FLastMousePointX;
      ky:= 0;

      if not (GridAlign and not GridCheck) then
      begin
        FModifyFlag:= True;
        e:= Round((e+kx) * 100000000) / 100000000;
        FLastMousePointX:= FLastMousePointX+kx;
      end;

      VGuides[FGuide]:= FloatToStr(e);
    end
    else
    begin
      e:= frxStrToFloat(HGuides[FGuide]);
      kx:= 0;
      ky:= Y / Scale-FLastMousePointY;

      if not (GridAlign and not GridCheck) then
      begin
        FModifyFlag:= True;
        e:= Round((e+ky) * 100000000) / 100000000;
        FLastMousePointY:= FLastMousePointY+ky;
      end;

      HGuides[FGuide]:= FloatToStr(e);
    end;

    Repaint;
  end;
end;

procedure TDesignerWorkspace.MouseUp(Button:TMouseButton;
  Shift:TShiftState; X, Y:Integer);
var
  i:Integer;
  e:Extended;
  c:TfrxComponent;

  function Contain(c:TfrxComponent):Boolean;
  begin
    with FSelectionRect do
      Result:= not ((c.Left > Right / FScale) or
                     (c.Left+c.Width < Left / FScale) or
                     (c.AbsTop > Bottom / FScale) or
                     (c.AbsTop+c.Height < Top / FScale));
  end;

  procedure CopyFormat(MemoFrom, MemoTo:TfrxMemoView);
  begin
    MemoTo.Color:= MemoFrom.Color;
    MemoTo.Font:= MemoFrom.Font;
    MemoTo.Frame.Assign(MemoFrom.Frame);
    MemoTo.BrushStyle:= MemoFrom.BrushStyle;
    MemoTo.HAlign:= MemoFrom.HAlign;
    MemoTo.VAlign:= MemoFrom.VAlign;
  end;

begin
  if FDisableUpdate then Exit;
  FSimulateMove:= False;

  if FTool = dtZoom then
  begin
    FMode1:= dmNone;
    NormalizeRect(FSelectionRect);

    with FSelectionRect do
      if (Right-Left > 5) and (Bottom-Top > 5) then
      begin
        e:= Scale;

        if (Right-Left) / (Parent.ClientWidth-16) <
           (Bottom-Top) / (Parent.ClientHeight-16) then
          FDesigner.Scale:= (Parent.ClientHeight-16) / (Bottom-Top) * Scale else
          FDesigner.Scale:= (Parent.ClientWidth-16) / (Right-Left) * Scale;

        if Parent is TScrollingWinControl then
          with TScrollingWinControl(Parent) do
          begin
            HorzScrollBar.Position:= Round((FSelectionRect.Left / e+
              TfrxReportPage(FDesigner.Page).LeftMargin * fr01cm) * Scale);
            VertScrollBar.Position:= Round((FSelectionRect.Top / e+
              TfrxReportPage(FDesigner.Page).TopMargin * fr01cm) * Scale);
          end;
      end
      else
      begin
        e:= Scale;
        if Button = mbLeft then
        begin
          if FDesigner.Scale >= 1 then
            FDesigner.Scale:= FDesigner.Scale+1
          else
            FDesigner.Scale:= FDesigner.Scale+0.25
        end
        else
        begin
          if FDesigner.Scale >= 2 then
            FDesigner.Scale:= FDesigner.Scale-1
          else if FDesigner.Scale > 0.4 then
            FDesigner.Scale:= FDesigner.Scale-0.25
        end;
        if Parent is TScrollingWinControl then
          with TScrollingWinControl(Parent) do
          begin
            HorzScrollBar.Position:= Round((FSelectionRect.Left / e+
              TfrxReportPage(FDesigner.Page).LeftMargin * fr01cm) * Scale-
              ClientWidth / 2);
            VertScrollBar.Position:= Round((FSelectionRect.Top / e+
              TfrxReportPage(FDesigner.Page).TopMargin * fr01cm) * Scale-
              ClientHeight / 2);
          end;
      end;
  end

  else if (FTool = dtText) and FMouseDown then
  begin
    FMode1:= dmNone;
    FMouseDown:= False;
    NormalizeRect(FSelectionRect);

    if FInplaceObject<>nil then
      TInplaceMemo(FInplaceMemo).EditDone;

    FInplaceObject:= nil;

    with FSelectionRect do
      if (Right-Left < 5) or (Bottom-Top < 5) then
      begin
        for i:= 0 to FObjects.Count-1 do
        begin
          c:= FObjects[i];
          if (c is TfrxCustomMemoView) and Contain(c) then
            FInplaceObject:= TfrxMemoView(c);
        end;
      end
      else
      begin
        if GridAlign then
        begin
          Left:= Trunc(Left / GridX) * GridX;
          Right:= Trunc(Right / GridX) * GridX;
          Top:= Trunc(Top / GridY) * GridY;
          Bottom:= Trunc(Bottom / GridY) * GridY;
        end;

        FInsertion.Left:= Left / FScale;
        FInsertion.Top:= Top / FScale;
        FInsertion.Width:= (Right-Left) / FScale;
        FInsertion.Height:= (Bottom-Top) / FScale;
        if Page is TfrxDMPPage then
          FInsertion.ComponentClass:= TfrxDMPMemoView else
          FInsertion.ComponentClass:= TfrxMemoView;

        if Assigned(FOnInsert) then
          FOnInsert(Self);
        AdjustBands;

        if TObject(FSelectedObjects[0]) is TfrxCustomMemoView then
          FInplaceObject:= FSelectedObjects[0];
      end;

    if FInplaceObject<>nil then
    begin
      FSelectedObjects.Clear;
      FSelectedObjects.Add(FInplaceObject);
      SelectionChanged;
      TInplaceMemo(FInplaceMemo).Edit(FInplaceObject);
    end;

    Exit;
  end
  else if FTool = dtFormat then
  begin
    FSelectionRect:= frxRect(X, Y, X+1, Y+1);
    for i:= FObjects.Count-1 downto 0 do
    begin
      c:= FObjects[i];
      if (c is TfrxMemoView) and Contain(c) and not
         (rfDontModify in c.Restrictions) and (c<>FSelectedObjects[0]) then
      begin
        CopyFormat(TfrxMemoView(FSelectedObjects[0]), TfrxMemoView(c));
        FModifyFlag:= True;
        break;
      end;
    end;
  end;

  if FMode1 = dmMoveGuide then
  begin
    if Cursor = crHSplit then
    begin
      e:= frxStrToFloat(VGuides[FGuide]);
      if (e < 3) or (e > (Width / Scale)-3) then
        VGuides.Delete(FGuide);
    end
    else
    begin
      e:= frxStrToFloat(HGuides[FGuide]);
      if (e < 3) or (e > (Height / Scale)-3) then
        HGuides.Delete(FGuide);
    end;

    Repaint;
  end;

  inherited;
end;

procedure TDesignerWorkspace.DblClick;
begin
  if FTool = dtSelect then
    inherited;
end;

procedure TDesignerWorkspace.KeyDown(var Key:Word; Shift:TShiftState);
begin
  if (Key = VK_ESCAPE) and FSimulateMove then
  begin
    Key:= VK_DELETE;
    MouseUp(mbLeft, [], 0, 0);
  end;
  inherited;
end;

procedure TDesignerWorkspace.SimulateMove;
var
  r:TfrxRect;
begin
  FMode1:= dmMove;
  r:= GetSelectionBounds;
  MouseDown(mbLeft, [], Round(r.Left / Scale)+20, Round(r.Top / Scale)+20);
  FSimulateMove:= True;
end;

procedure TDesignerWorkspace.DoLBClick(Sender:TObject);
begin
  if FMemo<>nil then
  begin
    FMemo.DataSet:= TfrxDataBand(FMemo.Parent).Dataset;
    FMemo.DataField:= FListBox.Items[FListBox.ItemIndex];
  end;
  FListBox.Hide;

  FModifyFlag:= True;
  DoModify;
end;

procedure TDesignerWorkspace.LBDrawItem(Control:TWinControl; Index:Integer;
  ARect:TRect; State:TOwnerDrawState);
begin
  with FListBox do
  begin
    Canvas.FillRect(ARect);
    frxResources.MainButtonImages.Draw(Canvas, ARect.Left, ARect.Top, 54);
    Canvas.TextOut(ARect.Left+20, ARect.Top+1, Items[Index]);
  end;
end;

procedure TDesignerWorkspace.CheckGuides(var kx, ky:Extended;
  var Result:Boolean);
var
  i:Integer;
  c:TfrxComponent;

  procedure CheckH(coord:Extended);
  var
    i:Integer;
    e:Extended;
  begin
    for i:= 0 to HGuides.Count-1 do
    begin
      e:= frxStrToFloat(HGuides[i]);
      if Abs(coord+ky-e) < 6 then
      begin
        ky:= e-coord;
        break;
      end;
    end;
  end;

  procedure CheckV(coord:Extended);
  var
    i:Integer;
    e:Extended;
  begin
    for i:= 0 to VGuides.Count-1 do
    begin
      e:= frxStrToFloat(VGuides[i]);
      if Abs(coord+kx-e) < 6 then
      begin
        kx:= e-coord;
        break;
      end;
    end;
  end;

begin
  if not (FPage is TfrxReportPage) or not FShowGuides then Exit;

  if FMouseDown and (FMode1 = dmSizeBand) then
    CheckH(FSizedBand.Top+FSizedBand.Height);

  if not FMouseDown and ((FMode1 = dmInsertObject) or (FMode1 = dmInsertLine)) then
  begin
    CheckV(FInsertion.Left);
    CheckH(FInsertion.Top);
    CheckV(FInsertion.Left+FInsertion.Width);
    CheckH(FInsertion.Top+FInsertion.Height);
  end;

  if FMouseDown and ((FMode1 = dmInsertObject) or (FMode1 = dmInsertLine)) then
  begin
    CheckV(FInsertion.Left);
    CheckH(FInsertion.Top);
  end;

  if FMouseDown and (FMode1 = dmMove) then
    for i:= 0 to SelectedCount-1 do
    begin
      c:= FSelectedObjects[i];
      CheckV(c.Left);
      CheckH(c.AbsTop);
      CheckH(c.Top);
      CheckV(c.Left+c.Width);
      CheckH(c.AbsTop+c.Height);
    end;

  if FMouseDown and (FMode1 = dmSize) then
  begin
    c:= FSelectedObjects[0];
    if FCT in [ct1, ct6, ct4] then
      CheckV(c.Left);
    if FCT in [ct1, ct7, ct3] then
      CheckH(c.AbsTop);
    if FCT in [ct3, ct5, ct2] then
      CheckV(c.Left+c.Width);
    if FCT in [ct4, ct8, ct2] then
      CheckH(c.AbsTop+c.Height);
  end;
end;

procedure TDesignerWorkspace.SetShowGuides(const Value:Boolean);
begin
  FShowGuides:= Value;
  Invalidate;
end;

function TDesignerWorkspace.GetHGuides:TStrings;
begin
  Result:= TfrxReportPage(FPage).HGuides;
end;

function TDesignerWorkspace.GetVGuides:TStrings;
begin
  Result:= TfrxReportPage(FPage).VGuides;
end;

procedure TDesignerWorkspace.SetHGuides(const Value:TStrings);
begin
  TfrxReportPage(FPage).HGuides:= Value;
end;

procedure TDesignerWorkspace.SetVGuides(const Value:TStrings);
begin
  TfrxReportPage(FPage).VGuides:= Value;
end;

procedure TDesignerWorkspace.SetTool(const Value:TfrxDesignTool);
begin
  FTool:= Value;
end;

end.

⌨️ 快捷键说明

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