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

📄 rvtable.pas

📁 richview1.7 full.source
💻 PAS
📖 第 1 页 / 共 5 页
字号:
unit RVTable;
interface

{$I RV_Defs.inc}

uses Windows, SysUtils, Classes, Graphics, Controls, Forms,
     RVClasses, RVItem, RVDataList, CRVData, CRVFData, RVStyle, RVFuncs,
     RVRVData, RVERVData,
     DLines,
     {$IFNDEF RVDONOTUSELISTS}
     RVMarker,
     {$ENDIF}
     RVScroll,RichView, RVEdit, RVFMisc, PtblRV, PtRVData, TypInfo, RVUni, RVUndo,
     RVStr;

{.$DEFINE RVDEBUGTABLE}

{$IFNDEF RICHVIEWCBDEF3}
{$O-}
{$ENDIF}


const
  rvsTable = -60;

  {$R RVTable.res}
  crRVSelectRow = 104;
  crRVSelectCol = 105;

type
  TRVCellHAlign   = (rvcLeft, rvcCenter, rvcRight);
  TRVCellVAlign   = (rvcTop,  rvcMiddle, rvcBottom, rvcVDefault);

  TRVTableOption = (rvtoEditing, rvtoRowSizing, rvtoColSizing,
                    rvtoRowSelect, rvtoColSelect, rvtoRTFSaveCellPixelBestWidth,
                    rvtoRTFAllowAutofit,
                    rvtoHideGridLines, rvtoOverlappingCorners, rvtoCellBelowBorders);
  TRVTableOptions = set of TRVTableOption;

  TRVTablePrintOption = (rvtoHalftoneBorders, rvtoRowsSplit, rvtoWhiteBackground);
  TRVTablePrintOptions = set of TRVTablePrintOption;

const
  RVTABLEDEFAULTOPTIONS = [rvtoEditing, rvtoRowSizing, rvtoColSizing,
                           rvtoRowSelect, rvtoColSelect];
  RVTABLEDEFAULTPRINTOPTIONS = [rvtoHalftoneBorders,rvtoRowsSplit];
type

  TRVTableBorderStyle = (rvtbRaised, rvtbLowered, rvtbColor, rvtbRaisedColor, rvtbLoweredColor);


  TRVHTMLLength = type Integer; // > 0 - pixels
                                // = 0 - undefined
                                // < 0 - percents

  TRVTableRow = class;
  TRVTableRows = class;
  TRVTableItemInfo = class;

  TRVCellEditingEvent = procedure (Sender: TRVTableItemInfo;
                                   Row, Col : Integer;
                                   Automatic: Boolean;
                                   var AllowEdit: Boolean) of object;

  TRVTableCellData = class (TRVItemFormattedData)
    private
      FColor: TColor;
      FVAlign: TRVCellVAlign;
      FBestWidth: TRVHTMLLength;
      FBestHeight: Integer;
      FRowSpan: Integer;
      FColSpan: Integer;
      FLeft, FTop, FWidth, FHeight: Integer;
      FVisibleBorders: TRVBooleanRect;
      //FReservedRVData: TCustomRVData;
      FChosenRVData: TCustomRVFormattedData;
      FChosenItem: TCustomRVItemInfo;
      ContainerUndoItem: TRVUndoInfo;
      FBorderColor: TColor;
      FBorderLightColor: TColor;
      procedure SetBestHeight(const Value: Integer);
      procedure SetBestWidth(const Value: TRVHTMLLength);
      procedure SetVisibleBorders(const Value: TRVBooleanRect);
      function CanClear: Boolean;
      procedure SetColor(const Value: TColor);
    protected
      procedure DefineProperties(Filer: TFiler); override;
      procedure AssignSizeFrom(Cell:TRVTableCellData);
      function GetRealVAlign: TRVCellVAlign;
      function GetExtraVOffs: Integer;
      function SupportsPageBreaks: Boolean; override;
      function GetOptions: TRVOptions; override;
      procedure ResetSubCoords; override;
    public
      { methods for internal processing }
      procedure GetParentInfo(var ParentItemNo: Integer; var Location: TRVStoreSubRVData); override;
      function GetTable: TRVTableItemInfo;      
      procedure AssignAttributesFrom(Cell:TRVTableCellData; IncludeSize: Boolean;
                                     DivColSpan, DivRowSpan: Integer);      
      procedure Deselect(NewPartiallySelected: TCustomRVItemInfo; MakeEvent: Boolean); override;
      function GetEditor: TWinControl; override;
      procedure GetOrigin(var ALeft, ATop: Integer); override;
      procedure GetOriginEx(var ALeft, ATop: Integer); override;
      function GetWidth: Integer; override;
      function GetHeight: Integer; override;
      function GetColor: TColor; override;
      function GetHOffs: Integer; override;
      function GetVOffs: Integer; override;
      function GetAreaWidth: Integer; override;
      procedure AssignChosenRVData(RVData: TCustomRVFormattedData; Item: TCustomRVItemInfo); override;
      procedure UnassignChosenRVData(RVData: TCustomRVData); override;
      function GetChosenRVData: TCustomRVData; override;
      function GetChosenItem: TCustomRVItemInfo; override;
      procedure MovingToUndoList(AContainerUndoItem: TRVUndoInfo);
      procedure MovingFromUndoList;
      function GetCellHeight: Integer;
//      function GetWidthInFixedTable(TableWidth: Integer): Integer;
      function GetMinWidth(sad: PRVScreenAndDevice; Canvas: TCanvas): Integer;
      function HasData(CheckStyles: Boolean): Boolean;
      function GetRVData: TCustomRVData; override;
      procedure DoSelect; override;
      procedure ControlAction2(ControlAction: TRVControlAction; ItemNo: Integer; var Control: TControl); override;
      procedure ItemAction(ItemAction: TRVItemAction; Item: TCustomRVItemInfo;
                               var Text: String; RVData: TCustomRVData); override;
      procedure AdjustFocus(NewFocusedItemNo: Integer; TopLevelRVData: TPersistent; TopLevelItemNo: Integer); override;
      { public methods and properties }
      constructor Create(ARow: TRVTableRow);
      destructor Destroy; override;
      {$IFNDEF RVDONOTUSELISTS}
      function GetMarkers(AllowCreate: Boolean): TRVMarkerList; override;
      {$ENDIF}      

      function Edit: TCustomRVData; override;
      property Left:Integer read FLeft;
      property Top:Integer  read FTop;
      property Height:Integer read FHeight;
      property Width:Integer read FWidth;

      property ColSpan: Integer read FColSpan;
      property RowSpan: Integer read FRowSpan;

    published
      { published properties }
      property Color: TColor                  read FColor          write SetColor      default clNone;
      property BorderColor: TColor            read FBorderColor    write FBorderColor  default clNone;
      property BorderLightColor: TColor       read FBorderLightColor write FBorderLightColor default clNone;
      property BestWidth: TRVHTMLLength       read FBestWidth      write SetBestWidth  default 0;
      property BestHeight: Integer            read FBestHeight     write SetBestHeight default 0;
      property VisibleBorders: TRVBooleanRect read FVisibleBorders write SetVisibleBorders;
      property VAlign: TRVCellVAlign          read FVAlign         write FVAlign       default rvcVDefault;
  end;

  TRVTableRow = class (TRVDataList)
    private
      FVAlign: TRVCellVAlign;
      function Get(Index: Integer): TRVTableCellData;
      procedure Put(Index: Integer; const Value: TRVTableCellData);
      procedure InsertEmpty(Index: Integer);
      procedure InsertPointer(Index: Integer; Item: TRVTableCellData);
    protected
      FRows: TRVTableRows;
      function GetParentRVData: TCustomRVData; override;
      function HasCellsInRange(Index, RangeStart, Count: Integer): Boolean;
    public
      constructor Create(nCols: Integer; ARows: TRVTableRows; MainRVData: TCustomRVData);
      function Add: TRVTableCellData;
      function Insert(Index: Integer): TRVTableCellData;
      function GetHeight: Integer;
      function GetBestHeight: Integer;
      property VAlign: TRVCellVAlign read FVAlign write FVAlign default rvcTop;
      property Items[Index: Integer]: TRVTableCellData read Get write Put; default;
  end;

  TRVTableRows = class (TRVList)
    private
      function Get(Index: Integer): TRVTableRow;
      procedure Put(Index: Integer; const Value: TRVTableRow);
      function GetMinColWidth(Col: Integer; sad: PRVScreenAndDevice;
                              Canvas: TCanvas): Integer;
      function GetPercentColWidth(Col, TableWidth: Integer): Integer;
      function IsPercentWidthColumn(Col: Integer): Boolean;
      function GetPixelColWidth(Col: Integer): Integer;
      function StartMergeCells(TopRow, LeftCol:Integer;
                               var ColSpan, RowSpan: Integer): Boolean;
    protected
      FMainRVData: TCustomRVData;
      FTable     : TRVTableItemInfo;
      function GetColCount: Integer;
      function IsEmptyRows(TopRow, LeftCol, ColSpan, RowSpan, TopRow2, RowSpan2: Integer): Boolean;
      function IsEmptyCols(TopRow, LeftCol, ColSpan, RowSpan, LeftCol2, ColSpan2: Integer): Boolean;
      function GetBestWidth(TopRow, LeftCol, ColSpan, RowSpan: Integer): Integer;
      procedure UnmergeCell(Row,Col: Integer; UnmergeRows, UnmergeCols: Boolean);
      procedure UnmergeCells(TopRow, LeftCol, ColSpan, RowSpan: Integer; UnmergeRows, UnmergeCols: Boolean);
      procedure InsertRows(Index, Count, CopyIndex: Integer; DivideHeights: Boolean);
      procedure InsertCols(Index, Count, CopyIndex: Integer; DivideWidths: Boolean);
      procedure DeleteRows(Index, Count: Integer; DecreaseHeight: Boolean);
      procedure DeleteCols(Index, Count: Integer; DecreaseWidth: Boolean);
      function SplitCellVertically(Row, Col, ColCount: Integer): Integer;
      function SplitCellsVertically(TopRow, LeftCol, ColSpan, RowSpan, ColCount: Integer):Integer;
      function SplitCellHorizontally(Row, Col, RowCount: Integer): Integer;
      function SplitCellsHorizontally(TopRow, LeftCol, ColSpan, RowSpan, RowCount: Integer):Integer;
      procedure MovingToUndoList(Row, Col, ColSpan, RowSpan: Integer; AContainerUndoItem: TRVUndoInfo);
      procedure MovingFromUndoList(Row, Col, ColSpan, RowSpan: Integer);
      procedure Do_BeforeInsertRows(ItemNo,Row,Count: Integer);
      procedure Do_InsertRows(Row,Count: Integer);
      procedure Do_UnInsertRows(Row,Count: Integer);
      procedure Do_BeforeInsertCell(ItemNo,Row,Col: Integer);
      procedure Do_BeforeSpreadOverEmptyCells(ItemNo, Row, Col, ColSpan: Integer);
      procedure Do_SpreadOverEmptyCells(Row, Col, ColSpan: Integer);
      procedure Do_UnSpreadOverEmptyCells(Row, Col, ColSpan: Integer);
      procedure Do_SetSpan(ItemNo,Row, Col, Span: Integer; IsColSpan: Boolean);
      procedure Do_BeforeFreeEmptyCells(ItemNo,Row, Col, ColSpan, RowSpan: Integer);
      procedure Do_FreeEmptyCells(Row, Col, ColSpan, RowSpan: Integer);
      procedure Do_UnFreeEmptyCells(Row, Col, ColSpan, RowSpan: Integer);
      procedure Do_BeforeInsertEmptyCells(ItemNo,Row, Col, ColCount, RowCount: Integer);
      procedure Do_InsertEmptyCells(Row, Col, ColCount, RowCount: Integer);
      procedure Do_UnInsertEmptyCells(Row, Col, ColCount, RowCount: Integer);
      procedure Do_BeforeSplitCellHorz(ItemNo,Row,Col,Row2: Integer; DecreaseHeight: Boolean);
      procedure Do_SplitCellHorz(Row,Col,Row2: Integer; DecreaseHeight: Boolean);
      procedure Do_UnSplitCellHorz(Row,Col,Row2: Integer; OldBestHeight: Integer);
      procedure Do_BeforeSplitCellVert(ItemNo,Row,Col,Col2: Integer; DecreaseWidth: Boolean);
      procedure Do_SplitCellVert(Row,Col,Col2: Integer; DecreaseWidth: Boolean);
      procedure Do_UnSplitCellVert(Row,Col,Col2: Integer; OldBestWidth: Integer);
      function Do_BeforeDeleteRows(ItemNo,Row,Count: Integer): TRVUndoInfo;
      procedure Do_DeleteRows(ItemNo,Row,Count: Integer; ui: TRVUndoInfo);
      procedure Do_UnDeleteRows(Row: Integer; RowList: TList);
      function Do_BeforeDeleteCols(ItemNo,Col,Count: Integer): TRVUndoInfo;
      procedure Do_DeleteCols(ItemNo,Col,Count: Integer;ui: TRVUndoInfo);
      procedure Do_UnDeleteCols(Col: Integer; CellList: TList);
      function Do_BeforeMergeCells(ItemNo, Row,Col, ColSpan, RowSpan: Integer): TRVUndoInfo;
      procedure Do_MergeCells(ItemNo, Row,Col, ColSpan, RowSpan: Integer;ui: TRVUndoInfo; ChangeBestWidth: Boolean);
      procedure Do_UndoMergeCells(ItemNo, Row,Col, OldColSpan, OldRowSpan: Integer;
                                  MergedItemsList: TRVList; OldBestWidth: TRVHTMLLength);
      procedure Do_BeforeUnmergeCell(ItemNo, Row,Col: Integer; UnmergeRows, UnmergeCols: Boolean);
      procedure Do_UnmergeCell(ItemNo, Row,Col: Integer; UnmergeRows, UnmergeCols: Boolean);
      procedure Do_UndoUnmergeCell(ItemNo, Row,Col: Integer;
                                   OldColSpan, OldRowSpan: Integer;
                                   OldBestWidth: TRVHTMLLength;
                                   OldBestHeight: Integer);
      function Do_BeforeClearCells(ItemNo: Integer; RowList, ColList: TRVIntegerList;
                                    var CellsList: TList): TRVUndoInfo;
      procedure Do_ClearCells(CellsList: TList; RowList, ColList: TRVIntegerList;
                              ui: TRVUndoInfo);
      procedure Do_UnClearCells(CellsList: TList; RowList, ColList: TRVIntegerList);
      procedure InsertPointer(Index: Integer; Item: TRVTableRow);
    public
      constructor Create(nRows, nCols: Integer; AMainRVData: TCustomRVData;
                         ATable: TRVTableItemInfo);
      destructor Destroy; override;
      procedure MergeCells(TopRow, LeftCol, ColSpan, RowSpan: Integer;
                           AllowMergeRC, ChangeBestWidth: Boolean);      
      function Empty: Boolean;
      function Add(nCols: Integer): TRVTableRow;
      function GetMainCell(ARow,ACol: Integer; var MRow, MCol: Integer): TRVTableCellData;
      function Insert(Index, nCols: Integer): TRVTableRow;
      procedure Reset(nRows, nCols: Integer);
      function CanMergeCells(TopRow, LeftCol, ColSpan, RowSpan: Integer;
                             AllowMergeRC: Boolean): Boolean;
      property Items[Index: Integer]: TRVTableRow read Get write Put; default;
  end;

  TRVTableInplaceParamStorage = record
    Stored: Boolean;
    StartNo, EndNo, StartOffs, EndOffs: Integer;
    Row, Col: Integer;
    PartialSelected: TCustomRVItemInfo;
  end;

  TRVTableItemFormattingInfo = class
    private
      ColWidths, RowHeights, ColStarts,RowStarts: TRVIntegerList;
      FWidth, FHeight: Integer;
      Rows : TRVList;
    public
      constructor Create(CreateRows:Boolean);
      destructor Destroy; override;
      procedure Clear;
      procedure QuickClear;
  end;

  TRVCellDirection = (rvcdLeft, rvcdUp, rvcdRight, rvcdDown,
                      rvcdDocTop, rvcdDocBottom,
                      rvcdNext, rvcdPrev);

  TRVTableDrawBorderEvent = procedure (Sender: TRVTableItemInfo;
    Canvas: TCanvas; Left,Top,Right,Bottom, Width: Integer;
    LightColor, Color, BackgroundColor: TColor;
    Style: TRVTableBorderStyle; Printing: Boolean;
    VisibleBorders: TRVBooleanRect;
    var DoDefault: Boolean) of object;

  TRVTableState = (rvtsInserted, rvtsEditMode, rvtsModified, rvtsFormatInplace,
     rvtsVerticalDraggedRule, rvtsDRChangeTableWidth,
     rvtsJustCreated, rvtsInplaceIsReformatting, rvtsSelExists);
  TRVTableStates = set of TRVTableState;

  TRVTableItemInfo = class (TRVFullLineItemInfo)
    private
      FOnCellEditing: TRVCellEditingEvent;
      FState: TRVTableStates;

⌨️ 快捷键说明

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