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

📄 rvervdata.pas

📁 richview1.7 full.source
💻 PAS
📖 第 1 页 / 共 5 页
字号:
          inc(InsertPoint);
          inc(ItemsAdded);
        end;
        {$ENDIF}
      end;
      end
    else begin  // inserting after nontext
      ItemParaNo := -1;
      InsertPoint := dli.ItemNo+1;
      if GetItem(dli.ItemNo).GetBoolValue(rvbpFullWidth) then
        info.SameAsPrev := False;
    end;
  end;
  {.............................................................}
  // Replacing an empty line with new item
  // Exception: If inserting a full-line item in bulleted paragraph,
  // we do not replace empty string, but add new item after,
  // so result will look like:
  // {bullet} {old empty string}
  // {new full-line item} { old non-text item } { rest of paragraph }
  // Special case: if inserting marker, it deletes empty string and
  // replaces a marker before it (if exists)
  function IS_ReplaceEmptyText(CharPos: TRVCharPos;
                                dli: TRVDrawLineInfo;
                                var ItemParaNo: Integer;
                                var InsertPoint: Integer;
                                var ItemsAdded: Integer;
                                var FullReformat: Boolean): Boolean;
  var curitem: TCustomRVItemInfo;
      FR: Boolean;
      {$IFNDEF RVDONOTUSELISTS}
      PrevMarkerItemNo: Integer;
      {$ENDIF}
  begin
    Result := False;
    if IsSticking(dli.ItemNo-1) or
       IsSticking(dli.ItemNo) then begin
      info.Free;
      info := nil;
      exit;
    end;
    {$IFNDEF RVDONOTUSELISTS}
    if info.GetBoolValue(rvbpFullWidth) and
      (dli.ItemNo>0) and (GetItemStyle(dli.ItemNo-1)=rvsListMarker) then
      InsertPoint := dli.ItemNo+1
    else
    {$ENDIF}
    begin
      curitem := GetItem(dli.ItemNo);
      {$IFNDEF RVDONOTUSELISTS}
      if (info.StyleNo=rvsListMarker) and (TRVMarkerItemInfo(info).ListNo>=0) and
         GetRVStyle.ListStyles[TRVMarkerItemInfo(info).ListNo].HasNumbering then begin
        if dli.ItemNo=rvsListMarker then
          PrevMarkerItemNo := dli.ItemNo
        else begin
          PrevMarkerItemNo := dli.ItemNo-1;
          if PrevMarkerItemNo>=0 then begin
            PrevMarkerItemNo := GetFirstParaItem(PrevMarkerItemNo);
            if (GetItemStyle(PrevMarkerItemNo)<>rvsListMarker) then
              PrevMarkerItemNo := -1;
          end;
        end;
        if (PrevMarkerItemNo>=0) and (TRVMarkerItemInfo(GetItem(PrevMarkerItemNo)).ListNo>=0) and
          GetRVStyle.ListStyles[TRVMarkerItemInfo(GetItem(PrevMarkerItemNo)).ListNo].IsSimpleEqual(
            GetRVStyle.ListStyles[TRVMarkerItemInfo(info).ListNo], True) then begin
          NewListNo := TRVMarkerItemInfo(GetItem(PrevMarkerItemNo)).ListNo;
          TRVMarkerItemInfo(info).ListNo := NewListNo;
        end;
      end;
      {$ENDIF}
      if not curitem.SameAsPrev then begin
        info.SameAsPrev := False;
        {$IFNDEF RVDONOTUSELISTS}
        if info.StyleNo<>rvsListMarker then
        {$ENDIF}
          info.BR := curitem.BR;
      end;
      if info.BR then
        ItemParaNo := -1;
      if curitem.PageBreakBefore then
        info.ItemOptions := info.ItemOptions+[rvioPageBreakBefore];
      Do_DeleteItem(dli.ItemNo, FR);
      FullReformat := FullReformat or FR;
      InsertPoint := dli.ItemNo;
      dec(ItemsAdded);
      info.ParaNo := FCurParaStyleNo;
      {$IFNDEF RVDONOTUSELISTS}
      if (info.StyleNo=rvsListMarker) and (InsertPoint>0) and
         (GetItemStyle(InsertPoint-1)=rvsListMarker) then begin
        dec(InsertPoint);
        Do_DeleteItem(InsertPoint, FR);
        FullReformat := FullReformat or FR;
        dec(ItemsAdded);
      end;
      {$ENDIF}
    end;
    Result := True;
  end;
  {.............................................................}
  // Inserting in text (before, after, or between)
  // Special case: a full-line item is never inserted before the first text
  // item in bulleted paragraph. In this case, it splits this text item into
  // two parts, one of them is empty:
  // {bullet} {empty string (added) }
  // {new full-line item} { string } { rest of paragraph }
  // Another special case: marker can be inserted only in place of empty line,
  // not here
  function IS_InsertInText(CharPos: TRVCharPos;
                           dli: TRVDrawLineInfo;
                           var ItemParaNo: Integer;
                           var InsertPoint: Integer;
                           var ItemsAdded: Integer;
                           var FullReformat: Boolean): Boolean;
  var s2: String;
      newsubstr: TCustomRVItemInfo;
      FR: Boolean;
  begin
    {$IFNDEF RVDONOTUSELISTS}
    if info.StyleNo=rvsListMarker then begin
      Result := True;
      info.Free;
      info := nil;
      exit;
    end;
    {$ENDIF}
    Result := False;
    if (dli.Offs+CharPos.Offset-1<=1)
       {$IFNDEF RVDONOTUSELISTS}
       and not (info.GetBoolValue(rvbpFullWidth) and (dli.ItemNo>0) and (GetItemStyle(dli.ItemNo-1)=rvsListMarker))
       {$ENDIF} then begin // inserting before text
      InsertPoint := dli.ItemNo;
      if IsSticking(InsertPoint-1) then begin
        info.Free;
        info := nil;
        exit;
      end;
      if not info.GetBoolValue(rvbpFullWidth) and  not GetItem(InsertPoint).SameAsPrev then begin
        info.SameAsPrev := False;
        info.BR := GetItem(InsertPoint).BR;
        if info.BR then
          ItemParaNo := -1;
        Do_NewLine(InsertPoint, True, -1, FR);
        FullReformat := FullReformat or FR;
        end
      else
        ItemParaNo := -1;
      AdjustTag(GetItem(InsertPoint));
      end
    else if dli.Offs+CharPos.Offset-1>ItemLength(dli.ItemNo) then begin // inserting after text
      ItemParaNo := -1;
      InsertPoint := dli.ItemNo+1;
      if IsSticking(InsertPoint-1) then begin
        info.Free;
        info := nil;
        exit;
      end;
      AdjustTag(GetItem(InsertPoint-1));
      end
    else begin // inserting in text
      if IsProtected(dli.ItemNo, rvprModifyProtect) then begin
        info.Free;
        info := nil;
        exit;
      end;
      ItemParaNo := -1;
      inc(ItemsAdded);
      InsertPoint := dli.ItemNo+1;
      s2 := RVU_Copy(Items[dli.ItemNo], dli.Offs+CharPos.Offset-1,
                           RVU_Length(Items[dli.ItemNo], GetItemOptions(dli.ItemNo)),
                           GetItemOptions(dli.ItemNo));
      Do_DeleteSubstring(dli.ItemNo, dli.Offs+CharPos.Offset-1, -1);
      newsubstr := RV_CreateTextCopy(TRVTextItemInfo(GetItem(dli.ItemNo)), Self);
      newsubstr.SameAsPrev := True;
      Do_InsertItem(InsertPoint,s2,newsubstr,False, FR);
      AdjustTag(GetItem(InsertPoint));
      FullReformat := FullReformat or FR;
    end;
    Result := True;
  end;
  {.............................................................}
var dli: TRVDrawLineInfo;
    FR: Boolean;
    ItemParaNo: Integer;
    ItemNo1, ItemNo2: Integer;
begin
  NewListNo := -1;
  FullReformat := False;
  Result := True;
  ItemsAdded := 1;
  ItemParaNo := info.ParaNo;
  if ItemParaNo>=GetRVStyle.ParaStyles.Count then
    ItemParaNo := -1;
  if (DrawItems.Count<>0) and not info.GetBoolValue(rvbpFullWidth)
     {$IFNDEF RVDONOTUSELISTS}
     and (info.StyleNo<>rvsListMarker)
     {$ENDIF}
   then begin
    info.SameAsPrev := True;
    info.ParaNo := GetItemPara(DrawItems[CaretDrawItemNo].ItemNo);
    end
  else begin
    info.SameAsPrev := False;
    info.ParaNo := FCurParaStyleNo;
  end;
  if IsParaProtected(info.ParaNo,rvpaoReadOnly) then begin
    info.Free;
    info := nil;
    Result := False;
    exit;
  end;
  dli := DrawItems[CharEnds.Items[CaretOffs].DrawItemNo];
  if GetItemStyle(dli.ItemNo)<0 then
    IS_InsertNearNonText(CharEnds.Items[CaretOffs], dli, ItemParaNo, InsertPoint, ItemsAdded, FullReformat)
  else if (Items[dli.ItemNo]='') then
    Result := IS_ReplaceEmptyText(CharEnds.Items[CaretOffs], dli, ItemParaNo, InsertPoint, ItemsAdded, FullReformat)
  else
    Result := IS_InsertInText(CharEnds.Items[CaretOffs], dli, ItemParaNo, InsertPoint, ItemsAdded, FullReformat);
  if not Result or (info=nil) then
    exit;
  if info.GetBoolValue(rvbpFullWidth) then begin
    if InsertPoint<>Items.Count then begin
       Do_NewLine(InsertPoint, False, -1, FR);
       FullReformat := FullReformat or FR;
       Do_BR(InsertPoint, False, FR);
       FullReformat := FullReformat or FR;
    end;
    if info.StyleNo=rvsBreak then
      info.ParaNo := 0;
  end;
  FullReformat := FullReformat or FR;  
  Do_InsertItem(InsertPoint, s, info, False, FR);
  if (ItemParaNo>=0) and (ItemParaNo<>info.ParaNo) and (info.StyleNo<>rvsBreak) then begin
    ExpandToPara(InsertPoint, InsertPoint, ItemNo1, ItemNo2);
    Do_Para(ItemNo1, ItemNo2, ItemParaNo, FR);
    FullReformat := FullReformat or FR;
  end;
end;
{------------------------------------------------------------------------------}
function TRVEditRVData.InsertSomething(info: TCustomRVItemInfo; var s: String;
                                       AutoTag, CaretBefore: Boolean): Boolean;
var
  InsertPoint, Dummy : Integer;
  Offs, ItemsAdded: Integer;
  FullReformat : Boolean;
begin
  if info.StyleNo<>rvsBreak then
    info.ParaNo := FCurParaStyleNo;
  if (FPartialSelectedItem<>nil) or
     not InsSomething(info, s, AutoTag, InsertPoint, ItemsAdded, FullReformat, Dummy) then begin
    Beep;
    Result := False;
    exit;
  end;
  if info=nil then begin
    // only possible if info was a marker, and it was not inserted, but this is
    // not error
    Result := True;
    exit;
  end;
  if (FullReformat or (CalculateMinItemWidthPlusEx(InsertPoint)>DocumentWidth)) and
     (DocumentWidth<>CalculateMinDocWidthPlus(nil,nil)) then begin
    Format_(False,True,False,0,GetCanvas,False,False);
    Invalidate;
    ChangeCaret(False,True,True,False);
    end
  else
    FormatParas(CharEnds.Items[0].DrawItemNo, CharEnds.Items[CharEnds.Count-1].DrawItemNo,ItemsAdded);
  if CaretBefore then
    if info.StyleNo<0 then
      Offs := 0
    else
      Offs := 1
  else
    if info.StyleNo<0 then
      Offs := 1
    else
      Offs := RVU_Length(S, GetItemOptions(InsertPoint))+1;
  Item2DrawItem(InsertPoint, Offs, {->} CaretDrawItemNo, Offs);
  OnChangeCaretLine(Offs-2);
  ChangeCaret(False, True, False, False);
  Result := True;
end;
{------------------------------------------------------------------------------}
function TRVEditRVData.CreateTextItem(Tag, ParaStyle, FontStyle: Integer; SameAsPrev, BR: Boolean): TCustomRVItemInfo;
begin
  Result            := RichViewTextItemClass.Create(Self);
  {$IFNDEF RVDONOTUSEUNICODE}
  if GetRVStyle.TextStyles[FontStyle].Unicode then
    Include(Result.ItemOptions,rvioUnicode);
  {$ENDIF}
  Result.StyleNo    := FontStyle;
  Result.ParaNo     := ParaStyle;
  Result.SameAsPrev := SameAsPrev;
  Result.BR         := BR;
  Result.Tag        := Tag;
end;
{------------------------------------------------------------------------------}
function TRVEditRVData.CreateTextItem2(Tag: Integer; Source: TCustomRVItemInfo; SameAsPrev, BR: Boolean): TCustomRVItemInfo;
begin
  Result            := RichViewTextItemClass.Create(Self);
  Result.Assign(Source);
  Result.ItemOptions := [];
  {$IFNDEF RVDONOTUSEUNICODE}
  if GetRVStyle.TextStyles[Result.StyleNo].Unicode then
    Include(Result.ItemOptions,rvioUnicode);
  {$ENDIF}
  Result.SameAsPrev := SameAsPrev;
  Result.BR         := BR;
  Result.Tag        := Tag;
end;
{------------------------------------------------------------------------------}
function TRVEditRVData.InsString(s: String;
                                 Index, Tag: Integer;
                                 ParaStyle, FontStyle: Integer;
                                 SameAsPrev, BR: Boolean;
                                 var FullReformat: Boolean): TCustomRVItemInfo;
begin
  Result := CreateTextItem(Tag, ParaStyle, FontStyle, SameAsPrev, BR);
  Do_InsertItem(Index, s, Result, False, FullReformat);
end;
{------------------------------------------------------------------------------}
function TRVEditRVData.InsString2(s: String; Index, Tag: Integer; Source: TCustomRVItemInfo; SameAsPrev, BR: Boolean;
                                  var FullReformat: Boolean): TCustomRVItemInfo;
begin
  Result := CreateTextItem2(Tag, Source, SameAsPrev, BR);
  Do_InsertItem(Index, s, Result, False, FullReformat);
end;
{------------------------------------------------------------------------------}
function TRVEditRVData.InsEmptyString(Index, Tag, ParaStyle, FontStyle: Integer; SameAsPrev, BR: Boolean): TCustomRVItemInfo;
var FullReformat: Boolean;
begin
  Result := InsString('', Index, Tag, ParaStyle, FontStyle, SameAsPrev, BR, FullReformat);
end;
{------------------------------------------------------------------------------}
function TRVEditRVData.CanDelete: Boolean;
var i, StyleNo: Integer;
    StartNo, EndNo, StartOffs, EndOffs: Integer;
    {................................................}
    function CompletelySelected(a,b, ItemNo: Integer): Boolean;
    begin
      Result := (a<=GetOffsBeforeItem(ItemNo)) and
                (b>=GetOffsAfterItem(ItemNo));
    end;
    {...........................................

⌨️ 快捷键说明

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