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

📄 rvruler.pas

📁 richviewaction 1.58 需要richview 1.9.46
💻 PAS
📖 第 1 页 / 共 3 页
字号:
      TopMargin := M * FRichViewEdit.TopMargin;
      BottomMargin := M * FRichViewEdit.BottomMargin;
      PageHeight := M * FRichViewEdit.RVData.DocumentHeight;
    end;
  finally
    FUpdating := False;
  end;
end;
{------------------------------------------------------------------------------}
procedure TRVRuler.DoTableColumnChanged;
var
  BaseTW: Integer;
  C, TW, CW: Integer;
  Data: Integer;
  M: Extended;
  ItemNo: Integer;
  OldBW: Integer;
  RVTableInplaceEdit: TRVTableInplaceEdit;
  RVEditor: TCustomRichViewEdit;
  RVItem: TCustomRVItemInfo;
  RVTable: TRVTableItemInfo;
begin
  inherited;
  if not Assigned(FRichViewEdit) or FUpdating or (RulerType <> rtHorizontal) then
    Exit;

  if TableEditor.Active and (TableEditor.DraggedDelta <> 0) then
  begin
    M := MultiPixels;
    if FRichViewEdit.GetCurrentItemEx(TRVTableItemInfo, RVEditor, RVItem) then
    begin
      RVTable := TRVTableItemInfo(RVItem);
      ItemNo := RVEditor.GetItemNo(RVTable);
      RVEditor.BeginItemModify(ItemNo, Data);
      RVEditor.BeginUndoGroup(rvutModifyItem);
      RVEditor.SetUndoGroupMode(True);
      try
        TW := Round(M * TableEditor.TableWidth) + 2 * RVTable.BorderWidth;
        OldBW := RVTable.BestWidth;
        if OldBW < 0 then
        begin
          if TRVTableInplaceEdit(FRichViewEdit.InplaceEditor).InplaceEditor <> nil then
          begin
            // Get the cell width of the table one level down.
            RVTableInplaceEdit := TRVTableInplaceEdit(FRichViewEdit.InplaceEditor);
            while TRVTableInplaceEdit(RVTableInplaceEdit.InplaceEditor).InplaceEditor <> nil do
              RVTableInplaceEdit := TRVTableInplaceEdit(RVTableInplaceEdit.InplaceEditor);
            BaseTW := RVTableInplaceEdit.FCell.Width;
          end
          else
            BaseTW := FRichViewEdit.RVData.TextWidth;
          RVTable.BestWidth := Pred(-100 * TW div BaseTW)
        end
        else
          RVTable.BestWidth := TW;
        with TableEditor do
        begin
          C := DraggedColumn;
          CW := Round(M * (Cells[C].DragBoundary + DraggedDelta +
            CellBorderWidth + CellHSpacing / 2));
          RVTable.ResizeCol(C, CW, DraggedWithShift);
        end;
        RVEditor.Change;
        // In case the table had a BestWidth of zero it needs to be restored
        // to enable RichView itself to be able to resize it.
        if OldBW = 0 then
        begin
          RVTable.BestWidth := 0;
          RVEditor.Change;
        end;
      finally
        RVEditor.SetUndoGroupMode(False);
      end;
      RVEditor.EndItemModify(ItemNo, Data);
    end;
  end;
  UpdateTableEditor;
end;
{------------------------------------------------------------------------------}
procedure TRVRuler.DoTableRowChanged;
var
  R, RH: Integer;
  M: Extended;
  RVEditor: TCustomRichViewEdit;
  RVItem: TCustomRVItemInfo;
  RVTable: TRVTableItemInfo;
begin
  inherited;
  if not Assigned(FRichViewEdit) or FUpdating or (RulerType <> rtVertical) then
    Exit;

  if TableEditor.Active and (TableEditor.DraggedDelta <> 0) then
  begin
    M := MultiPixels;
    if FRichViewEdit.GetCurrentItemEx(TRVTableItemInfo, RVEditor, RVItem) then
    begin
      RVTable := TRVTableItemInfo(RVItem);
      with TableEditor do
      begin
        R := DraggedRow;
        RH := Round(M * (Rows[R].RowHeight + CellBorderWidth + CellVSpacing / 2));
        RVTable.ResizeRow(R, RH);
      end;
    end;
  end;
  UpdateTableEditor;
end;
{------------------------------------------------------------------------------}
procedure TRVRuler.UpdateTableEditor;
var
  FI, LI: Extended;
  R, C, L, T, X, Y: Integer;
  Row, Col: Integer;
  ListEditorWasActive: Boolean;
  MainRow, MainCol: Integer;
  H: Integer;
  M: Extended;
  ParaNo: Integer;
  ParaStyles: TParaInfos;
  RVCell: TRVTableCellData;
  RVCellLast: TRVTableCellData;
  RVEditor: TCustomRichViewEdit;
  RVItem: TCustomRVItemInfo;
  RVTable: TRVTableItemInfo;
  W: Extended;
begin
  if not Assigned(FRichViewEdit) then
    Exit;

  FUpdating := True;
  try
    M := 1 / MultiPixels;
    ListEditorWasActive := ListEditor.Active;

    TableEditor.Active := FRichViewEdit.InplaceEditor <> nil;
    if TableEditor.Active then
    begin
      TableEditor.Cells.Clear;
      TableEditor.Rows.Clear;
      if FRichViewEdit.GetCurrentItemEx(TRVTableItemInfo, RVEditor, RVItem) then
      begin
        RVTable := TRVTableItemInfo(RVItem);
        if RVTable.GetEditedCell(Row, Col) <> nil then
        begin
          TableEditor.CellIndex       := Col;
          TableEditor.RowIndex        := Row;
          TableEditor.BorderHSpacing  := M * RVTable.BorderHSpacing;
          TableEditor.BorderVSpacing  := M * RVTable.BorderVSpacing;
          TableEditor.BorderWidth     := M * RVTable.BorderWidth;
          TableEditor.CellBorderWidth := M * RVTable.CellBorderWidth;
          TableEditor.CellHSpacing    := M * RVTable.CellHSpacing;
          TableEditor.CellVSpacing    := M * RVTable.CellVSpacing;
          TableEditor.CellHPadding    := M * RVTable.CellHPadding;
          TableEditor.CellVPadding    := M * RVTable.CellVPadding;

          if RulerType = rtHorizontal then
          begin
            // Setup columns
            RVCellLast := nil;
            for C := 0 to RVTable.Rows[Row].Count - 1 do
            begin
              RVCell := RVTable.Cells[Row, C];
              if RVCell <> nil then
              begin
                TableEditor.Cells.Add.CellWidth := M * RVCell.Width;
                RVCellLast := RVCell;
              end
              else
              begin
                RVCell := RVTable.Rows.GetMainCell(Row, C, MainRow, MainCol);
                if RVCellLast <> RVCell then
                begin
                  TableEditor.Cells.Add.CellWidth := M * RVCell.Width;
                  RVCellLast := RVCell;
                end
                else
                  TableEditor.Cells.Add.CellWidth := -1;
              end;
            end;

            // Setup Drag boundaries
            TableEditor.UseDragBoundaries := True;
            for C := 0 to RVTable.Rows[0].Count - 1 do
              if TableEditor.Cells[C].DragBoundary <= 0 then
                for R := 0 to RVTable.Rows.Count - 1 do
                  if (RVTable.Cells[R, C] <> nil) and (RVTable.Cells[R, C].ColSpan = 1) then
                  begin
                    TableEditor.Cells[C].DragBoundary := M * RVTable.Cells[R, C].Width;
                    Break;
                  end;
            for C := 0 to RVTable.Rows[0].Count - 1 do
              if TableEditor.Cells[C].DragBoundary = -1 then
                for R := 0 to RVTable.Rows.Count - 1 do
                  if (RVTable.Cells[R, C] = nil) then
                  begin
                    W := M * RVTable.Rows.GetMainCell(R, C, MainRow, MainCol).Width;
                    with TableEditor do
                    begin
                      for MainCol := MainCol to C - 1 do
                        W := W - Cells[MainCol].DragBoundary - 2 * CellBorderWidth -
                          CellHSpacing;
                      Cells[C].DragBoundary := W;
                    end;
                    Break;
                  end;

            // Setup column indents
            ParaStyles := FRichViewEdit.Style.ParaStyles;
            ParaNo := FRichViewEdit.CurParaStyleNo;
            if GetListIndents(FI, LI) then
            begin
              TableEditor.FirstIndent := FI;
              TableEditor.LeftIndent  := LI;
              if UseRTL then
                TableEditor.RightIndent := M * ParaStyles[ParaNo].LeftIndent
              else
                TableEditor.RightIndent := M * ParaStyles[ParaNo].RightIndent;
            end
            else
            begin
              if UseRTL then
              begin
                TableEditor.FirstIndent :=
                  M * (ParaStyles[ParaNo].RightIndent + ParaStyles[ParaNo].FirstIndent);
                TableEditor.LeftIndent := M * -ParaStyles[ParaNo].FirstIndent;
                TableEditor.RightIndent := M * ParaStyles[ParaNo].LeftIndent;
              end
              else
              begin
                TableEditor.FirstIndent :=
                  M * (ParaStyles[ParaNo].LeftIndent + ParaStyles[ParaNo].FirstIndent);
                TableEditor.LeftIndent := M * -ParaStyles[ParaNo].FirstIndent;
                TableEditor.RightIndent := M * ParaStyles[ParaNo].RightIndent;
              end;
            end;

            // Setup table position
            if RVEditor.GetItemCoords(RVTable.GetMyItemNo, L, T) then
            begin
              RVEditor.RVData.GetOriginEx(X, Y);
              Inc(L, X);
            end
            else
              L := 0;
            if TableEditor.TablePosition = tpFromMargin then
              L := L - FRichViewEdit.LeftMargin;
            TableEditor.TableLeft := M * (L + RVTable.BorderWidth);
            TableEditor.TableWidth := M * (RVTable.Width - 2 * RVTable.BorderWidth);
          end
          else
          begin // Vertical ruler
            // Setup rows
            for R := 0 to RVTable.Rows.Count - 1 do
            begin
              H := MAXINT;
              for C := 0 to RVTable.Rows[R].Count - 1 do
              begin
                RVCell := RVTable.Cells[R, C];
                if RVCell <> nil then
                  H := Min(H, RVCell.Height);
              end;
              if H <> MAXINT then
                TableEditor.Rows.Add.RowHeight := M * H;
            end;

            // Setup table position
            if RVEditor.GetItemCoords(RVTable.GetMyItemNo, L, T) then
            begin
              RVEditor.RVData.GetOriginEx(X, Y);
              Inc(T, Y);
            end
            else
              T := 0;
            if TableEditor.TablePosition = tpFromMargin then
              T := T - FRichViewEdit.TopMargin;
            TableEditor.TableTop := M * (T + RVTable.BorderWidth);
            TableEditor.TableHeight := M * (RVTable.Height - 2 * RVTable.BorderWidth);
          end;
        end
        else
          TableEditor.Active := False;
      end
      else
        TableEditor.Active := False;
    end;
  finally
    FUpdating := False;
  end;

  if ListEditorWasActive and not ListEditor.Active then
    UpdateRulerIndents;
end;
{------------------------------------------------------------------------------}
function TRVRuler.GetListIndents(var FI, LI: Extended): Boolean;
var
  FirstParaItemNo: Integer;
  ListLevel: Integer;
  ListNo: Integer;
  M: Extended;
  RVEditor: TCustomRichViewEdit;
  RVListLevel: TRVListLevel;
  StartFrom: Integer;
  UseStartFrom: Boolean;
begin
  Result := False;
  RVEditor := FRichViewEdit.TopLevelEditor;

  FirstParaItemNo := RVEditor.CurItemNo;
  if FirstParaItemNo < 0 then // document is cleared
    Exit;
  while not RVEditor.IsParaStart(FirstParaItemNo) do
    Dec(FirstParaItemNo);

  if RVEditor.GetItemStyle(FirstParaItemNo) = rvsListMarker then
  begin
    Result := True;
    RVEditor.GetListMarkerInfo(FirstParaItemNo,
      ListNo, ListLevel, StartFrom, UseStartFrom);
    RVListLevel := TRVMarkerItemInfo(RVEditor.GetItem(FirstParaItemNo)).GetLevelInfo(RVEditor.Style);
    if RVListLevel = nil then
    begin
      Result := False;
      Exit;
    end;
    M := 1 / MultiPixels;
    FI := M * (RVListLevel.LeftIndent + RVListLevel.FirstIndent);
    LI := M * -RVListLevel.FirstIndent;
    ListEditor.ListLevel := ListLevel;
  end;
  ListEditor.Active := Result;
end;
{------------------------------------------------------------------------------}
procedure TRVRuler.UpdateListEditor;
var
  FI, LI: Extended;
  ListEditorWasActive: Boolean;
begin
  if not Assigned(FRichViewEdit) or (RulerType <> rtHorizontal) then
    Exit;

  FUpdating := True;
  try
    ListEditorWasActive := ListEditor.Active;
    if GetListIndents(FI, LI) then
    begin
      if TableEditor.Active then
      begin
        TableEditor.FirstIndent := FI;
        TableEditor.LeftIndent  := LI;
      end
      else
      begin
        FirstIndent := FI;
        LeftIndent  := LI;
      end;
    end;
  finally
    FUpdating := False;
  end;

  if ListEditorWasActive and not ListEditor.Active then
    UpdateRulerIndents;
end;

end.

⌨️ 快捷键说明

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