RVERVData.pas
上传用户:daoqigc
上传日期:2021-04-20
资源大小:2795k
文件大小:247k
- end;
- if dli.ItemNo=Items.Count-1 then begin
- if ((StyleNo>=0) and (ItemLength(dli.ItemNo)=0)) then
- OnBackSpacePress_(False,False,False);
- exit;
- end;
- end;
- end;
- First := CharEnds.Items[0].DrawItemNo;
- Last := CharEnds.Items[CharEnds.Count-1].DrawItemNo;
- GetParaBounds(First,Last,First,Last);
- with GetItem(dli.ItemNo) do begin
- if (CaretOffs=CharEnds.Count-1) and
- ((StyleNo<0) or
- (dli.Offs+CharEnds.Items[CaretOffs].Offset-1>ItemLength(dli.ItemNo))) and
- (GetItem(dli.ItemNo+1).SameAsPrev)
- then begin { we at the end of screen line, item, but not paragraph }
- inc(CaretDrawItemNo);
- OnChangeCaretLine(0);
- CaretOffs := 0;
- OnDeletePress_(Ctrl, True);
- ChangeCaret(False,True,False,True);
- exit;
- end;
- end;
- BeginUndoSequence(rvutDelete, True);
- if (CaretOffs=CharEnds.Count-1) and
- ((GetItemStyle(dli.ItemNo)<0) or
- (dli.Offs+CharEnds.Items[CaretOffs].Offset-1>ItemLength(dli.ItemNo))) and
- not GetItem(dli.ItemNo+1).SameAsPrev then
- Del_AtTheEndOfParaSection(dli.ItemNo, First, Last)
- else
- Del_AtTheMiddle(dli, First, Last);
- end;
- {------------------------------------------------------------------------------}
- procedure TRVEditRVData.OnBackSpacePress_(Ctrl: Boolean; MultiDelete, FromNextLine: Boolean);
- {.....................................................................}
- function GetPrevP(dli: TRVDrawLineInfo; CaretOffs: Integer): Integer;
- begin
- if DrawItems[CharEnds.Items[CaretOffs-1].DrawItemNo].ItemNo<>dli.ItemNo then
- Result := 0
- else
- Result := dli.Offs+CharEnds.Items[CaretOffs-1].Offset-2;
- end;
- {.....................................................................}
- function DeleteCount(s: String; p, ItemNo: Integer): Integer;
- var ItemOptions: TRVItemOptions;
- IsSpace2, IsDelim1, IsDelim2: Boolean;
- begin
- if Ctrl then begin
- ItemOptions := GetItemOptions(ItemNo);
- Result := 1;
- for p := p-1 downto 1 do begin
- IsSpace2 := RVU_IsSpace(s, p+1, ItemOptions);
- IsDelim1 := IsDelimiter(s, p, ItemOptions);
- IsDelim2 := IsDelimiter(s, p+1, ItemOptions);
- if (IsDelim1 and not IsDelim2) or
- (not IsDelim1 and not IsSpace2 and IsDelim2) then
- break;
- inc(Result);
- end;
- end
- else if MultiDelete then
- Result := (p+1)-PrevCharStr(s,ItemNo,p+1)
- else
- Result := 1;
- end;
- {.....................................................................}
- procedure AdjustCaret(SavedCaretNo, SavedCaretOffs: Integer; ApplyPara: Boolean);
- begin
- Item2DrawItem(SavedCaretNo, SavedCaretOffs, CaretDrawItemNo, SavedCaretOffs);
- {$IFNDEF RVDONOTUSELISTS}
- AdjustMarkerCaret(True, SavedCaretOffs);
- {$ENDIF}
- OnChangeCaretLine(SavedCaretOffs-2);
- ChangeCaret(False,True,False,True);
- if ApplyPara then
- ApplyParaStyle(FCurParaStyleNo, rvscParaStyle);
- end;
- {.....................................................................}
- // Deleting current empty line
- // This function is called only if this is an empty line without marker,
- // and this line is not the first
- procedure Backspace_DeleteCurrentEmptyString(dli: TRVDrawLineInfo; First, Last: Integer);
- var SavedCaretNo, SavedCaretOffs, ItemsAdded: Integer;
- FullReformat: Boolean;
- begin
- if not TCustomRichViewEdit(RichView).BeforeChange(False) then
- exit;
- if IsProtected(dli.ItemNo, rvprDeleteProtect) or
- IsItemParaProtected(dli.ItemNo) or
- ItemHasPersistentCheckpoint(dli.ItemNo) then begin
- Beep;
- exit;
- end;
- SavedCaretNo := dli.ItemNo-1;
- SavedCaretOffs := GetOffsAfterItem(SavedCaretNo);
- Do_DeleteItem(dli.ItemNo, FullReformat);
- ItemsAdded := -1;
- {$IFNDEF RVDONOTUSELIVESPELL}
- LaterSetBackLiveSpellingTo(SavedCaretNo, 0, False);
- {$ENDIF}
- Reformat_(FullReformat, First, Last, ItemsAdded);
- AdjustCaret(SavedCaretNo, SavedCaretOffs, True);
- end;
- {.....................................................................}
- // Deleting previous empty line
- // If this line is after marker, moving current item to this marker's paragraph
- // This function is called only if caret is at the beginning of line,
- // end previous line if finished by an empty text item
- procedure Backspace_DeletePrevEmptyString(dli: TRVDrawLineInfo; First, Last: Integer);
- var SavedCaretNo, SavedCaretOffs, ItemsAdded: Integer;
- FullReformat, FR: Boolean;
- begin
- if not TCustomRichViewEdit(RichView).BeforeChange(False) then
- exit;
- if IsProtected(dli.ItemNo-1, rvprDeleteProtect) or
- IsItemParaProtected(dli.ItemNo-1) or
- IsItemParaProtected(dli.ItemNo) or
- ParaHasPersistentCheckpoint(dli.ItemNo-1) then begin
- Beep;
- exit;
- end;
- {$IFNDEF RVDONOTUSELISTS}
- if (dli.ItemNo>1) and (GetItemStyle(dli.ItemNo-2)=rvsListMarker) and
- ParaHasPersistentCheckpoint(dli.ItemNo) then begin
- Beep;
- exit;
- end;
- {$ENDIF}
- FullReformat := False;
- if not GetItem(dli.ItemNo-1).BR then begin
- Do_BR(dli.ItemNo, False, FR);
- FullReformat := FullReformat or FR;
- end;
- {$IFNDEF RVDONOTUSELISTS}
- if (dli.ItemNo>1) and (GetItemStyle(dli.ItemNo-2)=rvsListMarker) then begin
- Do_NewLine(dli.ItemNo, True, -1, FR);
- FullReformat := FullReformat or FR;
- end;
- {$ENDIF}
- SavedCaretNo := dli.ItemNo;
- SavedCaretOffs := GetOffsBeforeItem(SavedCaretNo);
- dec(SavedCaretNo);
- Do_DeleteItem(dli.ItemNo-1, FR);
- {$IFNDEF RVDONOTUSELIVESPELL}
- LaterSetBackLiveSpellingTo(dli.ItemNo-1, 0, False);
- {$ENDIF}
- FullReformat := FullReformat or FR;
- ItemsAdded := -1;
- Reformat_(FullReformat, First, Last, ItemsAdded);
- AdjustCaret(SavedCaretNo, SavedCaretOffs, False);
- end;
- {.....................................................................}
- // Concatenating two text items into one
- // This function is called only if caret is at the beginning of line,
- // and the first item in this line and the last item in previous line
- // can be combined.
- procedure Backspace_ConcateItems(dli: TRVDrawLineInfo; First, Last: Integer);
- var SavedCaretNo, SavedCaretOffs, ItemsAdded: Integer;
- begin
- if not TCustomRichViewEdit(RichView).BeforeChange(False) then
- exit;
- if IsItemParaProtected(dli.ItemNo-1) or IsItemParaProtected(dli.ItemNo) or
- IsProtected(dli.ItemNo, rvprParaStartProtect) or
- ParaHasPersistentCheckpoint(dli.ItemNo) then begin
- Beep;
- exit;
- end;
- SavedCaretOffs := ItemLength(dli.ItemNo-1)+1;
- Do_Concate(dli.ItemNo-1);
- {$IFNDEF RVDONOTUSELIVESPELL}
- LaterSetBackLiveSpellingTo(dli.ItemNo-1, SavedCaretOffs, True);
- {$ENDIF}
- ItemsAdded := -1;
- SavedCaretNo := dli.ItemNo-1;
- FormatParasExact(First, Last, ItemsAdded, False);
- AdjustCaret(SavedCaretNo, SavedCaretOffs, True);
- end;
- {.....................................................................}
- // Moving current item to the end of previous paragraph
- // This function is called only if caret is at the beginning of line
- procedure Backspace_MoveToPrev(dli: TRVDrawLineInfo; First, Last: Integer);
- var SavedCaretNo, SavedCaretOffs, ItemsAdded: Integer;
- FullReformat: Boolean;
- begin
- if not TCustomRichViewEdit(RichView).BeforeChange(False) then
- exit;
- if IsProtected(dli.ItemNo, rvprParaStartProtect) or
- IsItemParaProtected(dli.ItemNo) or IsItemParaProtected(dli.ItemNo-1) or
- ParaHasPersistentCheckpoint(dli.ItemNo) then begin
- Beep;
- exit;
- end;
- Do_NewLine(dli.ItemNo, True,-1, FullReformat);
- ItemsAdded := 0;
- SavedCaretNo := dli.ItemNo;
- SavedCaretOffs := GetOffsBeforeItem(SavedCaretNo);
- Reformat_(FullReformat, First, Last, ItemsAdded);
- AdjustCaret(SavedCaretNo, SavedCaretOffs, True);
- end;
- {.....................................................................}
- // Deleting the ItemNo-th item completely.
- // May be called for current item or previous item (marker).
- procedure Backspace_DeleteItem(ItemNo, First, Last: Integer);
- var Prev, SavedCaretNo, SavedCaretOffs, ItemsAdded, DeletedWidth: Integer;
- FullReformat, FR: Boolean;
- ASameAsPrev, ABR, APB: Boolean;
- Item: TCustomRVItemInfo;
- {$IFNDEF RVDONOTUSELISTS}
- M_FirstItemNo, M_MarkerIndex: Integer;
- M_ListNos: TRVIntegerList;
- {$ENDIF}
- {$IFNDEF RVDONOTUSELIVESPELL}
- Len: Integer;
- {$ENDIF}
- begin
- if not TCustomRichViewEdit(RichView).BeforeChange(False) then
- exit;
- if IsItemParaProtected(ItemNo) or
- IsProtected(ItemNo, rvprDeleteProtect) or
- not MovePersistentCheckpoint(ItemNo, False) then begin
- Beep;
- exit;
- end;
- FullReformat := False;
- ItemsAdded := -1;
- Prev := ItemNo-1;
- if Prev>=0 then begin
- SavedCaretNo := Prev;
- SavedCaretOffs := GetOffsAfterItem(Prev)
- end
- else begin
- SavedCaretNo := -1; { avoiding warnings}
- SavedCaretOffs := -1;
- end;
- Item := GetItem(ItemNo);
- {$IFNDEF RVDONOTUSELISTS}
- PrepareForUpdateRangeAfterMarkers(ItemNo, ItemNo, True, M_FirstItemNo, M_MarkerIndex, M_ListNos);
- {$ENDIF}
- DeletedWidth := CalculateMinItemWidthPlusEx(ItemNo);
- ASameAsPrev := Item.SameAsPrev;
- ABR := Item.BR;
- APB := Item.PageBreakBefore;
- Do_DeleteItem(ItemNo, FR);
- FullReformat := FullReformat or FR;
- {$IFNDEF RVDONOTUSELIVESPELL}
- Len := -1;
- {$ENDIF}
- if (ItemNo<Items.Count) and GetItem(ItemNo).SameAsPrev then
- if (not ASameAsPrev) or (ItemNo=0) then begin
- { move next item to the new line }
- Do_NewLine(ItemNo, False, -1, FR);
- {$IFNDEF RVDONOTUSELIVESPELL}
- LaterSetBackLiveSpellingTo(ItemNo, 0, False);
- Len := 0;
- {$ENDIF}
- FullReformat := FullReformat or FR;
- Do_BR(ItemNo, ABR, FR);
- FullReformat := FullReformat or FR;
- Do_PageBreak(ItemNo, APB);
- SavedCaretNo := ItemNo;
- SavedCaretOffs := GetOffsBeforeItem(ItemNo);
- end
- else begin
- if RV_CanConcateItems(ItemNo-1, GetItem(ItemNo-1), GetItem(ItemNo), False) then begin
- { concate items before and after deleted }
- {$IFNDEF RVDONOTUSELIVESPELL}
- Len := ItemLength(ItemNo-1);
- {$ENDIF}
- Do_Concate(ItemNo-1);
- {$IFNDEF RVDONOTUSELIVESPELL}
- LaterSetBackLiveSpellingTo(ItemNo-1, Len+1, True);
- {$ENDIF}
- dec(ItemsAdded);
- end;
- end;
- {$IFNDEF RVDONOTUSELIVESPELL}
- if Len<0 then begin
- if ItemNo>=Items.Count then
- dec(ItemNo);
- LaterSetBackLiveSpellingTo(ItemNo, 0, False);
- end;
- {$ENDIF}
- Reformat_(FullReformat or (DeletedWidth>=DocumentWidth), First, Last, ItemsAdded);
- AdjustCaret(SavedCaretNo, SavedCaretOffs, False);
- {$IFNDEF RVDONOTUSELISTS}
- if not FullReformat then
- UpdateAfterMarkers(M_FirstItemNo, M_MarkerIndex, M_ListNos, -1);
- {$ENDIF}
- end;
- {.....................................................................}
- // Actions on backspace at the beginning of line
- procedure Backspace_AtTheBeginningOfParaSection(dli: TRVDrawLineInfo; First, Last: Integer);
- begin
- if PageBreaksBeforeItems[dli.ItemNo] then begin
- if not TCustomRichViewEdit(RichView).BeforeChange(False) then
- exit;
- Do_PageBreak(dli.ItemNo, False);
- Invalidate;
- Change;
- end
- {$IFNDEF RVDONOTUSELISTS}
- else if (dli.ItemNo>0) and (GetItemStyle(dli.ItemNo-1)=rvsListMarker) then
- Backspace_DeleteItem(dli.ItemNo-1, First, Last)
- {$ENDIF}
- else if (GetItemStyle(dli.ItemNo)>=0) and (ItemLength(dli.ItemNo)=0) then
- BackSpace_DeleteCurrentEmptyString(dli, First, Last)
- else if (GetItemStyle(dli.ItemNo-1)>=0) and
- (ItemLength(dli.ItemNo-1)=0) then
- BackSpace_DeletePrevEmptyString(dli, First, Last)
- else if RV_CanConcateItems(dli.ItemNo-1, GetItem(dli.ItemNo-1), GetItem(dli.ItemNo), True) then
- BackSpace_ConcateItems(dli, First, Last)
- else
- Backspace_MoveToPrev(dli, First, Last);
- end;
- {.....................................................................}
- // Deleting the ItemNo-th item and inserting an empty text instead
- procedure Backspace_ReplaceWithEmptyText(ItemNo, First, Last: Integer);
- var SavedCaretNo, SavedCaretOffs, ItemsAdded, DeletedWidth: Integer;
- FullReformat1, FullReformat2: Boolean;
- s: String;
- TextItem, Item: TCustomRVItemInfo;
- begin
- if not TCustomRichViewEdit(RichView).BeforeChange(False) then
- exit;
- if IsItemParaProtected(ItemNo) or
- IsProtected(ItemNo, rvprDeleteProtect) then begin
- Beep;
- exit;
- end;
- Item := GetItem(ItemNo);
- TextItem := CreateTextItem(0, FCurParaStyleNo, FCurTextStyleNo, Item.SameAsPrev, Item.BR);
- if Item.Checkpoint<>nil then begin
- TextItem.Checkpoint := Item.Checkpoint.CreateCopy(rvoTagsArePChars in Options);
- Do_DeleteCP(ItemNo);
- end;
- if Item.StyleNo>=0 then
- TextItem.Tag := RV_CopyTag(Item.Tag, rvoTagsArePChars in Options);
- ItemsAdded := 0;
- SavedCaretNo := ItemNo;
- SavedCaretOffs := 1;
- DeletedWidth := CalculateMinItemWidthPlusEx(ItemNo);
- Do_DeleteItem(ItemNo, FullReformat1);
- s := '';
- Do_InsertItem(ItemNo, s, TextItem, False, FullReformat2);
- {$IFNDEF RVDONOTUSELIVESPELL}
- LaterSetBackLiveSpellingTo(ItemNo, 0, True);
- {$ENDIF}
- Reformat_(FullReformat1 or FullReformat2 or (DeletedWidth>=DocumentWidth), First, Last, ItemsAdded);
- AdjustCaret(SavedCaretNo, SavedCaretOffs, False);
- end;
- {.....................................................................}
- // Deleting characters from item (but not item itself)
- procedure Backspace_DeleteSubstring(dli: TRVDrawLineInfo; First, Last, Offset: Integer);
- var DeletedWidth, SavedCaretNo, SavedCaretOffs, CD: Integer;
- s: String;
- r: Boolean;
- begin
- Include(State, rvstKeyPress);
- try
- r := TCustomRichViewEdit(RichView).BeforeChange(False);
- finally
- Exclude(State, rvstKeyPress);
- end;
- if not r then
- exit;
- if IsProtected(dli.ItemNo, rvprModifyProtect) then begin
- Beep;
- exit;
- end;
- DeletedWidth := CalculateParaSectionMinWidthDef(dli.ItemNo);
- s := Items[dli.ItemNo];
- SavedCaretOffs := dli.Offs+Offset-2;
- CD := DeleteCount(s, SavedCaretOffs, dli.ItemNo);
- SavedCaretOffs := SavedCaretOffs-CD+1;
- Do_DeleteSubstring(dli.ItemNo, SavedCaretOffs, CD);
- {$IFNDEF RVDONOTUSELIVESPELL}
- TCustomRichView(RichView).AdjustLiveSpellingOnDelete(Self, dli.ItemNo,
- SavedCaretOffs, CD);
- {$ENDIF}
- SavedCaretNo := dli.ItemNo;
- Reformat_((DeletedWidth>=DocumentWidth), First, Last, 0);
- AdjustCaret(SavedCaretNo, SavedCaretOffs, False);
- end;
- {.....................................................................}
- // Actions on backspace when caret is not at the beginning of line
- procedure Backspace_NotAtTheBeginning(dli: TRVDrawLineInfo; First, Last, Offset: Integer);
- var StyleNo: Integer;
- begin
- StyleNo := GetItemStyle(dli.ItemNo);
- if ((StyleNo<0) and (Offset=1))
- or
- ((StyleNo>=0) and
- (ItemLength(dli.ItemNo)= DeleteCount(Items[dli.ItemNo], dli.Offs+Offset-2, dli.ItemNo))) then begin
- if (not GetItem(dli.ItemNo).SameAsPrev
- {$IFNDEF RVDONOTUSELISTS}
- or ((dli.ItemNo>0) and (GetItemStyle(dli.ItemNo-1)=rvsListMarker))
- {$ENDIF}
- )
- and
- ((dli.ItemNo>=Items.Count-1) or (not GetItem(dli.ItemNo+1).SameAsPrev)) then
- Backspace_ReplaceWithEmptyText(dli.ItemNo, First, Last)
- else
- Backspace_DeleteItem(dli.ItemNo, First, Last)
- end
- else
- Backspace_DeleteSubstring(dli, First, Last, Offset);
- end;
- {.....................................................................}
- var dli: TRVDrawLineInfo;
- First, Last, Offset: Integer;
- begin
- CaretDrawItemNo := CharEnds.Items[CaretOffs].DrawItemNo;
- dli := DrawItems[CaretDrawItemNo];
- Offset := CharEnds.Items[CaretOffs].Offset;
- if FromNextLine and (CaretDrawItemNo+1<DrawItems.Count) then begin
- // may be space was eaten?
- if DrawItems[CaretDrawItemNo].ItemNo<>DrawItems[CaretDrawItemNo+1].ItemNo then
- Offset := GetOffsAfterItem(DrawItems[CaretDrawItemNo].ItemNo)-DrawItems[CaretDrawItemNo].Offs+1
- end;
- with GetItem(dli.ItemNo) do begin
- if IsParaProtected(ParaNo,rvpaoReadOnly) then begin
- Beep;
- exit;
- end;
- if (CaretOffs=0) and
- (
- (StyleNo<0) or
- (dli.Offs+CharEnds.Items[CaretOffs].Offset-1<=1)
- ) then begin
- if (dli.ItemNo=0) then
- exit;
- if GetBoolValue(rvbpFullWidth) or
- (GetItem(dli.ItemNo-1).GetBoolValue(rvbpFullWidth) and not ((StyleNo>=0) and (ItemLength(dli.ItemNo)=0))) then begin
- OnLeftPress(False,False);
- exit;
- end;
- end;
- end;
- First := CharEnds.Items[0].DrawItemNo;
- Last := CharEnds.Items[CharEnds.Count-1].DrawItemNo;
- GetParaBounds(First,Last,First,Last);
- with GetItem(dli.ItemNo) do begin
- if (CaretOffs=0) and
- (SameAsPrev) and
- (((StyleNo<0) and (CharEnds.Items[CaretOffs].Offset=0)) or
- ((StyleNo>=0) and (dli.Offs+CharEnds.Items[CaretOffs].Offset-1<=GetOffsBeforeItem(dli.ItemNo))))
- {$IFNDEF RVDONOTUSELISTS}
- and
- not ((dli.ItemNo>0) and (GetItemStyle(dli.ItemNo-1)=rvsListMarker))
- {$ENDIF}
- then begin { we at the beginning of screen line, item, but not paragraph }
- dec(CaretDrawItemNo);
- OnChangeCaretLine(0);
- CaretOffs := CharEnds.Count-1;
- OnBackSpacePress_(Ctrl, MultiDelete, True);
- ChangeCaret(False,True,False,True);
- exit;
- end;
- end;
- BeginUndoSequence(rvutDelete, True);
- if CaretAtTheBeginningOfParaSection then
- Backspace_AtTheBeginningOfParaSection(dli, First, Last)
- else
- Backspace_NotAtTheBeginning(dli, First, Last, Offset);
- end;
- {------------------------------------------------------------------------------}
- procedure TRVEditRVData.ApplyParaStyle(ParaStyleNo: Integer;
- ConvType: TRVEStyleConversionType);
- var i, StartNo,EndNo, SelStartNo, SelEndNo : Integer;
- DIStartNo, DIEndNo, DIStartOffs, DIEndOffs: Integer;
- CIN, CIOffs, SSIN, SSIOffs, SEIN, SEIOffs: Integer;
- FullReformat: Boolean;
- ParaList: TRVIntegerList;
- Changed: Boolean;
- {..................................................................}
- function GetNewStyleNo(OldStyleNo: Integer): Integer;
- begin
- Result := OldStyleNo;
- TCustomRichViewEdit(FRichView).FCurStyleConversion(TCustomRichViewEdit(FRichView),
- OldStyleNo, OldStyleNo, ParaStyleNo, False, Result, True);
- end;
- {...................................................................}
- begin
- if FPartialSelectedItem<>nil then begin
- FPartialSelectedItem.ApplyStyleConversionToSubRVDatas(ParaStyleNo, True, ConvType);
- exit;
- end;
- if SelectionExists(True, False) then
- GetSelBounds(DIStartNo, DIEndNo, DIStartOffs, DIEndOffs, True)
- else begin
- DIStartNo := CaretDrawItemNo;
- DIEndNo := CaretDrawItemNo;
- end;
- StartNo := DrawItems[DIStartNo].ItemNo;
- EndNo := DrawItems[DIEndNo].ItemNo;
- with CharEnds.Items[CaretOffs] do begin
- CaretDrawItemNo := DrawItemNo;
- CIOffs := Offset;
- end;
- SelStartNo := StartNo;
- SelEndNo := EndNo;
- if DIStartOffs>=GetOffsAfterDrawItem(DIStartNo) then
- inc(SelStartNo);
- if DIEndOffs<=GetOffsBeforeDrawItem(DIEndNo) then
- dec(SelEndNo);
- DrawItem2Item(CaretDrawItemNo, CIOffs, CIN, CIOffs);
- StoreSelBounds(SSIN,SEIN,SSIOffs,SEIOffs, True);
- while StartNo>0 do begin
- if GetItem(StartNo).CanBeBorderStart then
- break;
- dec(StartNo)
- end;
- inc(EndNo);
- while EndNo<Items.Count do begin
- if GetItem(EndNo).CanBeBorderStart then break;
- inc(EndNo)
- end;
- dec(EndNo);
- if ConvType<>rvscParaStyle then begin
- ParaList := TRVIntegerList.Create;
- try
- ParaList.Capacity := EndNo-StartNo+1;
- for i := StartNo to EndNo do
- ParaList.Add(GetNewStyleNo(GetItemPara(i)));
- Changed := Do_ParaList(StartNo, ParaList, FullReformat);
- finally
- ParaList.Free;
- end;
- end
- else
- Changed := Do_Para(StartNo, EndNo, ParaStyleNo, FullReformat);
- for i := SelStartNo to SelEndNo do
- GetItem(i).ApplyStyleConversionToSubRVDatas(ParaStyleNo, False, ConvType);
- if Changed then begin
- Item2DrawItem(StartNo, GetOffsBeforeItem(StartNo), DIStartNo, DIStartOffs);
- Item2DrawItem(EndNo, GetOffsAfterItem(EndNo), DIEndNo, DIEndOffs);
- try
- Include(State, rvstInvalidSelection);
- if FullReformat then
- Format_(False, True, False, 0, GetCanvas, False, False, False)
- else
- FormatParas(DIStartNo, DIEndNo, 0);
- finally
- Exclude(State, rvstInvalidSelection);
- end;
- RestoreSelBounds(SSIN,SEIN,SSIOffs,SEIOffs);
- Invalidate;
- Item2DrawItem(CIN, CIOffs,CaretDrawItemNo, CaretOffs);
- OnChangeCaretLine(CaretOffs-2);
- end;
- ChangeCaret(False,True,False,True);
- Change;
- end;
- {------------------------------------------------------------------------------}
- function TRVEditRVData.OnHomePress(Ctrl: Boolean): Boolean;
- begin
- Result := Ctrl;
- if Ctrl then begin
- CaretDrawItemNo := 0;
- OnChangeCaretLine(GetOffsBeforeItem(0)-2);
- CaretOffs := 0;
- end
- else begin
- CaretOffs := 0;
- CaretDrawItemNo := CharEnds.Items[CaretOffs].DrawItemNo;
- end;
- ChangeCaret(False,True,False,False);
- end;
- {------------------------------------------------------------------------------}
- function TRVEditRVData.OnEndPress(Ctrl: Boolean): Boolean;
- begin
- Result := Ctrl;
- if Ctrl then begin
- CaretDrawItemNo := DrawItems.Count-1;
- OnChangeCaretLine(0);
- CaretOffs := CharEnds.Count-1;
- end
- else begin
- CaretOffs := CharEnds.Count-1;
- CaretDrawItemNo := CharEnds.Items[CaretOffs].DrawItemNo;
- end;
- ChangeCaret(False,True,False,False);
- end;
- {------------------------------------------------------------------------------}
- { Moving caret to the beginning of the previous paragraph.
- Used in paragraph selection mode, for arrow keys movement. }
- procedure TRVEditRVData.MoveCaretToTheBeginningOfThePrevParagraph;
- var DrawItemNo, DrawItemOffs: Integer;
- begin
- DrawItemNo := CharEnds.Items[CaretOffs].DrawItemNo;
- while (DrawItemNo>0) and not IsDrawItemParaStart(DrawItemNo) do
- dec(DrawItemNo);
- if DrawItemNo>0 then
- dec(DrawItemNo);
- while (DrawItemNo>0) and not IsDrawItemParaStart(DrawItemNo) do
- dec(DrawItemNo);
- DrawItemOffs := GetOffsBeforeDrawItem(DrawItemNo);
- CaretDrawItemNo := DrawItemNo;
- OnChangeCaretLine(DrawItemOffs-2);
- ChangeCaret(False,True,False,False);
- end;
- {------------------------------------------------------------------------------}
- { Moving caret to the end of the next paragraph.
- Used in paragraph selection mode, for arrow keys movement. }
- procedure TRVEditRVData.MoveCaretToTheEndOfTheNextParagraph;
- var DrawItemNo, DrawItemOffs: Integer;
- begin
- DrawItemNo := CharEnds.Items[CaretOffs].DrawItemNo;
- while (DrawItemNo+1<DrawItems.Count-1) and
- not IsDrawItemParaStart(DrawItemNo+1) do
- inc(DrawItemNo);
- if DrawItemNo<DrawItems.Count-1 then
- inc(DrawItemNo);
- while (DrawItemNo+1<DrawItems.Count-1) and
- not IsDrawItemParaStart(DrawItemNo+1) do
- inc(DrawItemNo);
- DrawItemOffs := GetOffsAfterDrawItem(DrawItemNo);
- CaretDrawItemNo := DrawItemNo;
- OnChangeCaretLine(DrawItemOffs-2);
- ChangeCaret(False,True,False,False);
- end;
- {------------------------------------------------------------------------------}
- function TRVEditRVData.OnLeftPress(Shift, Ctrl: Boolean): Boolean;
- var no,no2,offs: Integer;
- dli: TRVDrawLineInfo;
- li: TCustomRVItemInfo;
- // IsSpace1,
- IsSpace2, IsDelim1, IsDelim2: Boolean;
- s: String;
- begin
- Result := False;
- dli := DrawItems[CharEnds.Items[CaretOffs].DrawItemNo];
- li := GetItem(dli.ItemNo);
- offs := TRVCharPos(CharEnds.Items[CaretOffs]).Offset+dli.Offs-2;
- if Shift and (GetRVStyle.SelectionMode=rvsmParagraph) and
- IsMultiParagraphSelection then begin
- MoveCaretToTheBeginningOfThePrevParagraph;
- exit;
- end;
- if not Ctrl or (li.StyleNo<0) or (Offs<=0) then begin
- if not CaretAtTheBeginningOfLine then begin
- if Shift or Ctrl or not li.EnterItem(rvedRight,0) then
- dec(CaretOffs)
- end
- else begin
- if CaretDrawItemNo<>0 then begin
- dec(CaretDrawItemNo);
- {$IFNDEF RVDONOTUSELISTS}
- if (CaretDrawItemNo=0) and (GetItemStyle(0)=rvsListMarker) then
- Result := True;
- {$ENDIF}
- CaretOffs := GetOffsAfterDrawItem(CaretDrawItemNo);
- {$IFNDEF RVDONOTUSELISTS}
- AdjustMarkerCaret(False, CaretOffs);
- {$ENDIF}
- OnChangeCaretLine(CaretOffs-2);
- end
- else
- Result := True;
- end
- end
- else begin
- no2 := 0;
- s := Items[dli.ItemNo];
- for no := offs downto 1 do begin
- if (no2<>0) then begin
- //IsSpace1 := RVU_IsSpace(s, no, GetItemOptions(dli.ItemNo));
- IsSpace2 := RVU_IsSpace(s, no+1, GetItemOptions(dli.ItemNo));
- IsDelim1 := IsDelimiter(s, no, GetItemOptions(dli.ItemNo));
- IsDelim2 := IsDelimiter(s, no+1, GetItemOptions(dli.ItemNo));
- if (IsDelim1 and not IsDelim2) or
- (not IsDelim1 and not IsSpace2 and IsDelim2) then
- break;
- end;
- inc(no2);
- end;
- if no2<=CaretOffs then
- dec(CaretOffs, no2)
- else begin
- Item2DrawItem(dli.ItemNo, offs-no2+1, CaretDrawItemNo, CaretOffs);
- {$IFNDEF RVDONOTUSELISTS}
- AdjustMarkerCaret(False, CaretOffs);
- {$ENDIF}
- OnChangeCaretLine(CaretOffs-2);
- end;
- end;
- ChangeCaret(False,True,False,False);
- end;
- {------------------------------------------------------------------------------}
- function TRVEditRVData.OnRightPress(Shift, Ctrl: Boolean): Boolean;
- var no,no2,offs: Integer;
- dli: TRVDrawLineInfo;
- li: TCustomRVItemInfo;
- IsSpace1, IsSpace2, IsDelim1, IsDelim2: Boolean;
- s: String;
- begin
- Result := False;
- if Shift and (GetRVStyle.SelectionMode=rvsmParagraph) and
- IsMultiParagraphSelection then begin
- MoveCaretToTheEndOfTheNextParagraph;
- exit;
- end;
- if not (Ctrl) then begin
- if not CaretAtTheEndOfLine then begin
- dli := DrawItems[CharEnds.Items[CaretOffs+1].DrawItemNo];
- li := GetItem(dli.ItemNo);
- if Shift or Ctrl or not li.EnterItem(rvedLeft,0) then
- inc(CaretOffs)
- end
- else begin
- if CaretDrawItemNo<>DrawItems.Count-1 then begin
- inc(CaretDrawItemNo);
- CaretOffs := GetOffsBeforeDrawItem(CaretDrawItemNo);
- {$IFNDEF RVDONOTUSELISTS}
- AdjustMarkerCaret(True, CaretOffs);
- {$ENDIF}
- OnChangeCaretLine(CaretOffs-2);
- end
- else
- Result := True;
- end
- end
- else begin
- inc(CaretOffs);
- if CaretOffs=CharEnds.Count then
- if CaretDrawItemNo=DrawItems.Count-1 then begin
- dec(CaretOffs);
- Result := True;
- exit;
- end
- else begin
- inc(CaretDrawItemNo);
- CaretOffs := GetOffsBeforeDrawItem(CaretDrawItemNo);
- {$IFNDEF RVDONOTUSELISTS}
- AdjustMarkerCaret(True, CaretOffs);
- {$ENDIF}
- OnChangeCaretLine(CaretOffs-2);
- end;
- dli := DrawItems[CharEnds.Items[CaretOffs].DrawItemNo];
- li := GetItem(dli.ItemNo);
- if li.StyleNo>=0 then begin
- offs := TRVCharPos(CharEnds.Items[CaretOffs]).Offset+dli.Offs-1;
- no2 := 0;
- s := Items[dli.ItemNo];
- if offs>1 then begin
- for no := offs to ItemLength(dli.ItemNo) do begin
- IsSpace1 := RVU_IsSpace(s, no-1, li.ItemOptions);
- IsDelim1 := IsDelimiter(s, no-1, li.ItemOptions);
- IsSpace2 := RVU_IsSpace(s ,no, li.ItemOptions);
- IsDelim2 := IsDelimiter(s, no, li.ItemOptions);
- if (IsSpace1 and not IsSpace2) or
- (IsDelim1 and not IsDelim2) or
- (not IsDelim1 and not IsSpace2 and IsDelim2) then
- break;
- inc(no2);
- end;
- end;
- if no2+CaretOffs<CharEnds.Count then
- inc(CaretOffs, no2)
- else begin
- Item2DrawItem(dli.ItemNo, offs+no2, CaretDrawItemNo, CaretOffs);
- {$IFNDEF RVDONOTUSELISTS}
- AdjustMarkerCaret(True, CaretOffs);
- {$ENDIF}
- OnChangeCaretLine(CaretOffs-2);
- end;
- end;
- end;
- ChangeCaret(False,True,False,False);
- end;
- {------------------------------------------------------------------------------}
- function TRVEditRVData.OnUpPress(Shift,Ctrl: Boolean): Boolean;
- var offs: Integer;
- item: TCustomRVItemInfo;
- ditem : TRVDrawLineInfo;
- x, DrawItemNo: Integer;
- r: Boolean;
- begin
- DrawItemNo := CharEnds.Items[0].DrawItemNo;
- Result := DrawItemNo=0;
- if not Result then begin
- if Shift and (GetRVStyle.SelectionMode=rvsmParagraph) and
- IsMultiParagraphSelection then begin
- MoveCaretToTheBeginningOfThePrevParagraph;
- exit;
- end;
- x := CharEnds.Items[CaretOffs].X;
- dec(DrawItemNo);
- {$IFNDEF RVDONOTUSELISTS}
- if GetDrawItemStyle(DrawItemNo)=rvsListMarker then begin
- Result := DrawItemNo=0;
- if not Result then
- dec(DrawItemNo)
- else begin
- if Shift and not CaretAtTheBeginningOfLine then
- CaretOffs := 0
- else
- ScrollTo(0,True);
- exit;
- end;
- end;
- {$ENDIF}
- FindDrawItemForSel(x, DrawItems[DrawItemNo].Top+1, CaretDrawItemNo, offs, False);
- ditem := DrawItems[CaretDrawItemNo];
- r := False;
- if (x>=ditem.Left) and (x<=ditem.Left+ditem.Width) then begin
- item := GetItem(ditem.ItemNo);
- if not Shift and not Ctrl and item.EnterItem(rvedBottom, x-ditem.Left) then
- r := True;
- end;
- if not r then begin
- OnChangeCaretLine(offs-2);
- ChangeCaret(False,True,False,False);
- end;
- end
- else if Shift and not CaretAtTheBeginningOfLine then
- CaretOffs := 0
- else
- ScrollTo(0,True);
- end;
- {------------------------------------------------------------------------------}
- function TRVEditRVData.OnDownPress(Shift,Ctrl: Boolean): Boolean;
- var offs: Integer;
- item: TCustomRVItemInfo;
- ditem : TRVDrawLineInfo;
- x: Integer;
- r: Boolean;
- begin
- Result := CaretInTheLastLine;
- if not Result then begin
- if Shift and (GetRVStyle.SelectionMode=rvsmParagraph) and
- IsMultiParagraphSelection then begin
- MoveCaretToTheEndOfTheNextParagraph;
- exit;
- end;
- x := CharEnds.Items[CaretOffs].X;
- FindDrawItemForSel(x,
- DrawItems[CharEnds.Items[CharEnds.Count-1].DrawItemNo+1].Top+1,
- CaretDrawItemNo, offs, False);
- ditem := DrawItems[CaretDrawItemNo];
- r := False;
- if (x>=ditem.Left) and (x<=ditem.Left+ditem.Width) then begin
- item := GetItem(ditem.ItemNo);
- if not Shift and not Ctrl and item.EnterItem(rvedTop, x-ditem.Left) then
- r := True;
- end;
- if not r then begin
- OnChangeCaretLine(offs-2);
- ChangeCaret(False,True,False,False);
- end;
- end
- else begin
- if Shift and not CaretAtTheEndOfLine then begin
- CaretOffs := CharEnds.Count-1;
- end
- else
- ScrollTo(DocumentHeight,True);
- end;
- end;
- {------------------------------------------------------------------------------}
- function TRVEditRVData.OnPgUpPress: Boolean;
- var offs,x,y: Integer;
- NewDrawLineNo: Integer;
- begin
- Result := False;
- x := TRVCharPos(CharEnds.Items[CaretOffs]).X;
- y := GetVOffs-(GetHeight * 3 div 4);
- while y>0 do begin
- FindDrawItemForSel(x,y, NewDrawLineNo, offs, False);
- if (NewDrawLineNo<CaretDrawItemNo) then begin
- CaretDrawItemNo := NewDrawLineNo;
- OnChangeCaretLine(offs-2);
- ChangeCaret(False,True,False,False);
- exit;
- end;
- dec(y, GetHeight div 2);
- end;
- OnHomePress(True)
- end;
- {------------------------------------------------------------------------------}
- function TRVEditRVData.OnPgDownPress: Boolean;
- var offs,x,y: Integer;
- NewDrawLineNo: Integer;
- begin
- Result := False;
- x := TRVCharPos(CharEnds.Items[CaretOffs]).X;
- y := GetVOffs+(GetHeight * 3 div 4);
- while y<DocumentHeight do begin
- FindDrawItemForSel(x,y, NewDrawLineNo, offs, False);
- if (NewDrawLineNo>CaretDrawItemNo) then begin
- CaretDrawItemNo := NewDrawLineNo;
- OnChangeCaretLine(offs-2);
- ChangeCaret(False,False,False,False);
- ScrollTo(DrawItems[CaretDrawItemNo].Top,True);
- exit;
- end;
- inc(y, GetHeight div 2);
- end;
- OnEndPress(True)
- end;
- {------------------------------------------------------------------------------}
- function TRVEditRVData.BuildJumpsCoords(IgnoreReadOnly: Boolean): Integer;
- begin
- if not IgnoreReadOnly and TCustomRichViewEdit(FRichView).ReadOnly then
- exit;
- if CaptureMouseItem<>nil then exit;
- ClearJumps;
- Result := 0;
- inherited BuildJumpsCoords(Result,jumps);
- Flags := Flags + [rvflUseJumps];
- State := State - [rvstDrawHover];
- Invalidate;
- end;
- {------------------------------------------------------------------------------}
- procedure TRVEditRVData.ClearJumpsCoords;
- begin
- if TCustomRichViewEdit(FRichView).ReadOnly then
- exit;
- if CaptureMouseItem<>nil then exit;
- if rvflUseJumps in Flags then begin
- ClearJumps;
- Flags := Flags - [rvflUseJumps];
- State := State - [rvstDrawHover];
- ChangeCaret(False,False,True,False);
- Invalidate;
- end;
- end;
- {------------------------------------------------------------------------------}
- procedure TRVEditRVData.PrepareForEdit;
- begin
- if (Items.Count=0) and (GetRVStyle<>nil) then begin
- AddNL('',FCurTextStyleNo,FCurParaStyleNo);
- Format_(False, True, False, 0, GetCanvas, False, False, False);
- if DrawItems.Count=0 then exit;
- CaretDrawItemNo := 0;
- OnChangeCaretLine(1-2);
- CaretOffs := 0;
- end;
- end;
- {------------------------------------------------------------------------------}
- procedure TRVEditRVData.Format_(OnlyResized,ForceFormat,NoScroll:Boolean;
- depth: Integer; Canvas: TCanvas; OnlyTail, NoCaching, Reformatting: Boolean);
- var SavedCaretDrawItemNo, SavedCaretOffs, Offs: Integer;
- saved: Boolean;
- begin
- if rvstSkipFormatting in State then
- exit;
- PrepareForEdit;
- if AlreadyFormatted then begin
- AlreadyFormatted := False;
- exit;
- end;
- saved := (depth=0) and
- (GetRVStyle<>nil) and
- not (rvstSkipformatting in State);
- if saved and (OnlyResized or OnlyTail) then begin
- if CaretDrawItemNo<>-1 then
- with CharEnds.Items[CaretOffs] do begin
- CaretDrawItemNo := DrawItemNo;
- Offs := Offset;
- end;
- DrawItem2Item(CaretDrawItemNo, Offs, {->} SavedCaretDrawItemNo, SavedCaretOffs);
- end;
- inherited;
- if saved then begin
- if (OnlyResized or OnlyTail) then begin
- Item2DrawItem(SavedCaretDrawItemNo, SavedCaretOffs, {->} CaretDrawItemNo, Offs);
- OnChangeCaretLine(Offs-2);
- end
- else begin
- Deselect(nil, False);
- if DrawItems.Count=0 then begin
- CaretDrawItemNo := -1;
- CaretOffs := -1;
- end
- else begin
- CaretDrawItemNo := 0;
- OnChangeCaretLine(GetOffsBeforeItem(0)-2);
- CaretOffs := 0;
- end;
- end;
- CreateResizer;
- ChangeCaret(False,False, not (rvstEditorUnformatted in State),False);
- end;
- if depth=0 then
- Exclude(State, rvstEditorUnformatted);
- end;
- {------------------------------------------------------------------------------}
- procedure TRVEditRVData.ApplyStyleConversion_(UserData: Integer;
- ConvType: TRVEStyleConversionType; ApplyToWholeParas: Boolean);
- var StartNo,EndNo, StartOffs, EndOffs : Integer;
- SL, EL, SO, EO: Integer;
- DIStartNo, DIEndNo, DLStartOffs, DLEndOffs, i, ConvertedCurStyle: Integer;
- CLN, CLOffs: Integer;
- ItemsAdded, OldWidth, NewWidth: Integer;
- inverted: Boolean;
- {..................................................................}
- function GetNewStyleNo(OldStyleNo, ParaNo: Integer): Integer;
- begin
- Result := OldStyleNo;
- TCustomRichViewEdit(FRichView).FCurStyleConversion(
- TCustomRichViewEdit(FRichView), OldStyleNo, ParaNo, UserData, True, Result,
- ApplyToWholeParas);
- end;
- {...................................................................}
- function NeedClearTag(li: TCustomRVItemInfo; NewStyleNo: Integer): Boolean;
- begin
- Result :=
- (rvoClearTagOnStyleApp in TCustomRichViewEdit(FRichView).EditorOptions)
- and (li.StyleNo<>NewStyleNo);
- end;
- {...................................................................}
- procedure ClrTag(ItemNo, NewStyleNo: Integer);
- var li: TCustomRVItemInfo;
- begin
- li := GetItem(ItemNo);
- if NeedClearTag(li, NewStyleNo) then
- Do_Tag(ItemNo, 0, False);
- end;
- {...................................................................}
- procedure DoSetStyleNo(li: TCustomRVItemInfo; ItemNo, NewStyleNo: Integer);
- {$IFNDEF RVDONOTUSEUNICODE}
- var ActualNewStyleNo: Integer;
- {$ENDIF}
- begin
- {$IFNDEF RVDONOTUSEUNICODE}
- ActualNewStyleNo := GetActualStyle2(NewStyleNo,li.ParaNo);
- if GetRVStyle.TextStyles[GetActualStyle(li)].Unicode then begin
- if not GetRVStyle.TextStyles[ActualNewStyleNo].Unicode then begin
- Do_ChangeText(ItemNo, RVU_UnicodeToAnsi(GetStyleCodePage(ActualNewStyleNo), Items[ItemNo]));
- end;
- end
- else begin
- if GetRVStyle.TextStyles[NewStyleNo].Unicode then begin
- Do_ChangeText(ItemNo, RVU_AnsiToUnicode(GetStyleCodePage(GetActualStyle(li)), Items[ItemNo]));
- end;
- end;
- {$ENDIF}
- Do_StyleNo(ItemNo, NewStyleNo);
- end;
- {...................................................................}
- procedure ApplyToWhole(ItemNo: Integer);
- var NewStyleNo: Integer;
- li: TCustomRVItemInfo;
- begin
- li := GetItem(ItemNo);
- if (li.StyleNo<0) then begin
- li.ApplyStyleConversion(Self, ItemNo, UserData);
- exit;
- end;
- NewStyleNo := GetNewStyleNo(GetActualStyle(li), li.ParaNo);
- if (li.StyleNo<>NewStyleNo) then begin
- ClrTag(ItemNo, NewStyleNo);
- DoSetStyleNo(li, ItemNo, NewStyleNo);
- end;
- end;
- {...................................................................}
- function GetStr(const s: String; OldStyleNo, NewStyleNo, ParaNo: Integer): String;
- {$IFNDEF RVDONOTUSEUNICODE}
- var oldU, newU: Boolean;
- {$ENDIF}
- begin
- {$IFNDEF RVDONOTUSEUNICODE}
- oldU := GetRVStyle.TextStyles[GetActualStyle2(OldStyleNo,ParaNo)].Unicode;
- newU := GetRVStyle.TextStyles[GetActualStyle2(NewStyleNo,ParaNo)].Unicode;
- if oldU then
- if not newU then
- Result := RVU_UnicodeToAnsi(GetStyleCodePage(GetActualStyle2(NewStyleNo,ParaNo)), s)
- else
- Result := s
- else
- if newU then
- Result := RVU_AnsiToUnicode(GetStyleCodePage(GetActualStyle2(OldStyleNo,ParaNo)), s)
- else
- {$ENDIF}
- Result := s;
- end;
- {...................................................................}
- procedure ApplyToItemStart(ItemNo: Integer;
- StartOffs, EndOffs: Integer);
- var s1: String;
- tag: Integer;
- curitem, newitem: TCustomRVItemInfo;
- NewStyleNo: Integer;
- Dummy: Boolean;
- begin
- curitem := GetItem(ItemNo);
- NewStyleNo := GetNewStyleNo(GetActualStyle(curitem), curitem.ParaNo);
- if NewStyleNo=curitem.StyleNo then
- exit;
- s1 := RVU_Copy(Items[ItemNo], 1, EndOffs-1, curitem.ItemOptions);
- Do_DeleteSubstring(ItemNo, 1, EndOffs-1);
- if s1='' then
- exit;
- if NeedClearTag(curitem, NewStyleNo) then
- tag := 0
- else
- tag := RV_CopyTag(curitem.Tag, rvoTagsArePChars in Options);
- newitem := InsString(
- GetStr(s1, curitem.StyleNo, NewStyleNo, curitem.ParaNo), ItemNo, tag,
- curitem.ParaNo, NewStyleNo, curitem.SameAsPrev, curitem.BR, Dummy);
- if curitem.Checkpoint<>nil then begin
- Do_AddCP(ItemNo, curitem.Checkpoint.CreateCopy(rvoTagsArePChars in Options));
- Do_DeleteCP(ItemNo+1);
- end;
- if curitem.PageBreakBefore then begin
- newitem.PageBreakBefore := True;
- end;
- inc(ItemsAdded);
- Do_NewLine(ItemNo+1, True, -1, Dummy);
- EL := ItemNo;
- EO := GetOffsAfterItem(EL);
- end;
- {...................................................................}
- procedure ApplyToItemEnd(ItemNo, StartOffs, EndOffs: Integer);
- var s2: String;
- tag, NewStyleNo: Integer;
- curitem: TCustomRVItemInfo;
- Dummy: Boolean;
- begin
- curitem := GetItem(ItemNo);
- NewStyleNo := GetNewStyleNo(GetActualStyle(curitem), curitem.ParaNo);
- if NewStyleNo=curitem.StyleNo then
- exit;
- s2 := RVU_Copy(Items[ItemNo], StartOffs, RVU_Length(Items[ItemNo], curitem.ItemOptions), curitem.ItemOptions);
- Do_DeleteSubstring(ItemNo, StartOffs, -1);
- if s2='' then
- exit;
- if NeedClearTag(curitem, NewStyleNo) then
- tag := 0
- else
- tag := RV_CopyTag(curitem.Tag, rvoTagsArePChars in Options);
- s2 := GetStr(s2, curitem.StyleNo, NewStyleNo, curitem.ParaNo);
- InsString(s2, ItemNo+1, tag, curitem.ParaNo, NewStyleNo, True, False, Dummy);
- inc(ItemsAdded);
- SL := ItemNo;
- SO := GetOffsAfterItem(SL);
- if StartNo=EndNo then begin
- EL := ItemNo+1;
- EO := GetOffsAfterItem(EL);
- end
- else
- inc(EL);
- end;
- {...................................................................}
- procedure ApplyToItemMid(ItemNo, StartOffs, EndOffs: Integer);
- var s1, s2, s3: String;
- curitem, newitem: TCustomRVItemInfo;
- Tag, NewStyleNo: Integer;
- Dummy: Boolean;
- begin
- curitem := GetItem(ItemNo);
- NewStyleNo := GetNewStyleNo(GetActualStyle(curitem), curitem.ParaNo);
- if NewStyleNo=curitem.StyleNo then
- exit;
- s1 := RVU_Copy(Items[ItemNo], 1, StartOffs-1, curitem.ItemOptions);
- s2 := RVU_Copy(Items[ItemNo], StartOffs, EndOffs-StartOffs, curitem.ItemOptions);
- s3 := RVU_Copy(Items[ItemNo], EndOffs, RVU_Length(Items[ItemNo], curitem.ItemOptions), curitem.ItemOptions);
- if s1<>'' then begin
- Tag := RV_CopyTag(curitem.Tag, rvoTagsArePChars in Options);
- newitem := InsString2(s1, ItemNo, Tag, curitem, curitem.SameAsPrev, curitem.BR, Dummy);
- if curitem.Checkpoint<>nil then begin
- Do_AddCP(ItemNo, curitem.Checkpoint.CreateCopy(rvoTagsArePChars in Options));
- Do_DeleteCP(ItemNo+1);
- end;
- if curitem.PageBreakBefore then
- newitem.PageBreakBefore := True;
- inc(ItemsAdded);
- inc(ItemNo);
- Do_NewLine(ItemNo, True, -1, Dummy);
- end;
- if s3<>'' then begin
- tag :=RV_CopyTag(curitem.Tag, rvoTagsArePChars in Options);
- InsString2(s3, ItemNo+1, tag, curitem, True, False, Dummy);
- if (s1='') and (s2='') and (curitem.Checkpoint<>nil) then begin
- Do_AddCP(ItemNo+1, curitem.Checkpoint.CreateCopy(rvoTagsArePChars in Options));
- Do_DeleteCP(ItemNo);
- end;
- inc(ItemsAdded);
- end;
- ClrTag(ItemNo,NewStyleNo);
- Do_DeleteSubstring(ItemNo, EndOffs, -1);
- Do_DeleteSubstring(ItemNo, 1, StartOffs-1);
- DoSetStyleNo(curitem, ItemNo, NewStyleNo);
- SL := ItemNo-1;
- EL := ItemNo;
- SO := GetOffsAfterItem(SL);
- EO := GetOffsAfterItem(EL);
- end;
- {..................................................................}
- procedure ASC_Concate(StartNo, EndNo: Integer);
- var i: Integer;
- begin
- if StartNo>0 then
- dec(StartNo);
- if EndNo<Items.Count-1 then
- inc(EndNo);
- {$IFNDEF RVDONOTUSELIVESPELL}
- LaterSetBackLiveSpellingTo(StartNo, 0, True);
- {$ENDIF}
- {$IFNDEF RVDONOTUSELIVESPELL}
- GetItem(EndNo).ClearWordPainters(0);
- {$ENDIF}
- for i := EndNo downto StartNo+1 do begin
- if RV_CanConcateItems(i-1, GetItem(i-1), GetItem(i), False) then begin
- dec(ItemsAdded);
- if i<=SL then begin
- if i=SL then
- inc(SO, RVU_Length(Items[i-1], GetItemOptions(i-1)));
- dec(SL);
- end;
- if i<=EL then begin
- if i=EL then
- inc(EO, RVU_Length(Items[i-1], GetItemOptions(i-1)));
- dec(EL);
- end;
- Do_Concate(i-1);
- end;
- {$IFNDEF RVDONOTUSELIVESPELL}
- GetItem(i-1).ClearWordPainters(0);
- {$ENDIF}
- end;
- end;
- {..................................................................}
- begin
- if FPartialSelectedItem<>nil then begin
- FPartialSelectedItem.ApplyStyleConversionToSubRVDatas(UserData, True, ConvType);
- exit;
- end;
- if not (rvprDoNotAutoSwitch in
- GetRVStyle.TextStyles[GetActualCurStyleNo].Protection) then
- FPrevTextStyleNo := FCurTextStyleNo;
- ConvertedCurStyle := FCurTextStyleNo;
- TCustomRichViewEdit(FRichView).FCurStyleConversion(TCustomRichViewEdit(FRichView),
- FCurTextStyleNo, FCurParaStyleNo, UserData, False, ConvertedCurStyle,
- ApplyToWholeParas);
- if not ApplyToWholeParas and not SelectionExists(True, False) then begin
- if (GetItemStyle(GetCurItemNo)>=0) and (Items[GetCurItemNo]='') then begin
- BeginUndoSequence(rvutStyleNo, True);
- ApplyToWhole(GetCurItemNo);
- FormatParas(CaretDrawItemNo, CaretDrawItemNo, 0);
- SetCurTextStyleNo(ConvertedCurStyle);
- ChangeCaret(False,True,True,True);
- Change;
- end;
- SetCurTextStyleNo(ConvertedCurStyle);
- exit;
- end;
- BeginUndoSequence(rvutStyleNo, True);
- GetSelBounds(DIStartNo, DIEndNo, DLStartOffs, DLEndOffs, True);
- StoreSelBounds(StartNo, EndNo, StartOffs, EndOffs, True);
- OldWidth := CalculateParaSectionsMinWidthDef(StartNo, EndNo);
- StoreSelBounds(SL, EL, SO, EO, False);
- inverted := (SL<>StartNo) or (SO<>StartOffs);
- StoreSelBounds(SL, EL, SO, EO, True);
- StartNo := DrawItems[DIStartNo].ItemNo;
- EndNo := DrawItems[DIEndNo].ItemNo;
- if ApplyToWholeParas then begin
- while (StartNo>0) and not IsParaStart(StartNo) do
- dec(StartNo);
- StartOffs := GetOffsBeforeItem(StartNo);
- while (EndNo+1<ItemCount) and not IsParaStart(EndNo+1) do
- inc(EndNo);
- EndOffs := GetOffsAfterItem(EndNo);
- end;
- GetParaBounds(DIStartNo, DIEndNo,DIStartNo, DIEndNo);
- with CharEnds.Items[CaretOffs] do begin
- CaretDrawItemNo := DrawItemNo;
- CLOffs := Offset;
- end;
- DrawItem2Item(CaretDrawItemNo, CLOffs, CLN, CLOffs);
- ItemsAdded := 0;
- if StartNo=EndNo then begin // (1) one item is selected
- if (GetItemStyle(StartNo)>=0) then begin
- if (StartOffs<=GetOffsBeforeItem(StartNo)) and (EndOffs>=GetOffsAfterItem(StartNo)) then
- ApplyToWhole(StartNo)
- else if StartOffs<=GetOffsBeforeItem(StartNo) then
- ApplyToItemStart(StartNo, StartOffs, EndOffs)
- else if EndOffs>=GetOffsAfterItem(StartNo) then
- ApplyToItemEnd(StartNo, StartOffs, EndOffs)
- else
- ApplyToItemMid(StartNo, StartOffs, EndOffs);
- end
- else
- GetItem(StartNo).ApplyStyleConversion(Self, StartNo, UserData);
- end
- else begin // (2) 2 or more items are selected
- if GetItemStyle(EndNo)>=0 then begin
- if EndOffs>=GetOffsAfterItem(EndNo) then
- ApplyToWhole(EndNo)
- else
- ApplyToItemStart(EndNo, 1, EndOffs);
- end
- else
- GetItem(EndNo).ApplyStyleConversion(Self, EndNo, UserData);
- for i := EndNo-1 downto StartNo+1 do
- ApplyToWhole(i);
- if GetItemStyle(StartNo)>=0 then begin
- if StartOffs<=GetOffsBeforeItem(StartNo) then
- ApplyToWhole(StartNo)
- else
- ApplyToItemEnd(StartNo, StartOffs, GetOffsAfterItem(StartNo));
- end
- else if StartOffs<=GetOffsBeforeItem(StartNo) then
- GetItem(StartNo).ApplyStyleConversion(Self, StartNo, UserData);
- end;
- if ApplyToWholeParas then
- ASC_Concate(StartNo, EndNo)
- else
- ASC_Concate(SL, EL);
- if SL<EL then begin
- StartNo := SL;
- EndNo := EL;
- end
- else begin
- StartNo := EL;
- EndNo := SL;
- end;
- NewWidth := CalculateParaSectionsMinWidthDef(StartNo,EndNo);
- try
- Include(State, rvstInvalidSelection);
- Reformat_((OldWidth<>NewWidth) and ((OldWidth>=DocumentWidth) or (NewWidth>=DocumentWidth)),
- DIStartNo, DIEndNo, ItemsAdded);
- finally
- Exclude(State, rvstInvalidSelection);
- end;
- if not Inverted then begin
- Item2DrawItem(SL,SO, FSelStartNo, FSelStartOffs);
- Item2DrawItem(EL,EO, FSelEndNo, FSelEndOffs);
- end
- else begin
- Item2DrawItem(EL,EO, FSelStartNo, FSelStartOffs);
- Item2DrawItem(SL,SO, FSelEndNo, FSelEndOffs);
- end;
- CaretDrawItemNo := FSelEndNo;
- OnChangeCaretLine(FSelEndOffs-2);
- SetCurTextStyleNo(ConvertedCurStyle);
- ChangeCaret(False,True,True,True);
- Invalidate;
- Change;
- end;
- {------------------------------------------------------------------------------}
- function TRVEditRVData.InsertTextFromStreamW(Stream: TStream;
- AutoTag: Boolean): Boolean;
- var FullText: String;
- begin
- Result := True;
- if Stream.Size=Stream.Position then
- exit;
- SetLength(FullText, Stream.Size-Stream.Position);
- Stream.ReadBuffer(PChar(FullText)^, Length(FullText));
- try
- InsertTextW_(FullText, AutoTag, False);
- except
- Result := False;
- end;
- end;
- {------------------------------------------------------------------------------}
- function TRVEditRVData.InsertTextFromStream(Stream: TStream;
- OEM, AutoTag: Boolean): Boolean;
- var FullText: String;
- begin
- Result := True;
- if Stream.Size=Stream.Position then
- exit;
- SetLength(FullText, Stream.Size-Stream.Position);
- Stream.ReadBuffer(PChar(FullText)^, Length(FullText));
- Replace0(FullText);
- if OEM then
- OEMToAnsi(PChar(FullText),PChar(FullText));
- try
- InsertText_(FullText, AutoTag, False);
- except
- Result := False;
- end;
- end;
- {------------------------------------------------------------------------------}
- function TRVEditRVData.InsertTextFromFileW(const FileName: String; AutoTag: Boolean): Boolean;
- var Stream: TFileStream;
- begin
- Stream := TFileStream.Create(FileName, fmOpenRead);
- try
- Result := InsertTextFromStreamW(Stream, AutoTag);
- except
- Result := False;
- end;
- Stream.Free;
- end;
- {------------------------------------------------------------------------------}
- function TRVEditRVData.InsertTextFromFile(const FileName: String; OEM, AutoTag: Boolean): Boolean;
- var Stream: TFileStream;
- begin
- try
- Stream := TFileStream.Create(FileName, fmOpenRead);
- try
- Result := InsertTextFromStream(Stream, OEM, AutoTag);
- finally
- Stream.Free;
- end;
- except
- Result := False;
- end;
- end;
- {------------------------------------------------------------------------------}
- procedure TRVEditRVData.AfterAddingText(StartItemNo, EndItemNo, ItemsAdded,
- DIStartNo, DIEndNo: Integer;
- FullReformat, CaretBefore: Boolean);
- var Offs, CDIOffs: Integer;
- FR: Boolean;
- {$IFNDEF RVDONOTUSELIVESPELL}
- Len: Integer;
- {$ENDIF}
- begin
- Do_InsertItems_2(StartItemNo+1, EndItemNo-StartItemNo,
- Do_InsertItems_1(StartItemNo+1, EndItemNo-StartItemNo),
- FR);
- if FR then
- FullReformat := True;
- // concating Items
- if CaretBefore then
- Offs := 1
- else
- Offs := ItemLength(EndItemNo)+1;
- if (EndItemNo<>Items.Count-1) and
- RV_CanConcateItems(EndItemNo, GetItem(EndItemNo), GetItem(EndItemNo+1), False) then begin
- Do_Concate(EndItemNo);
- {$IFNDEF RVDONOTUSELIVESPELL}
- GetItem(EndItemNo).ClearWordPainters(0);
- {$ENDIF}
- dec(ItemsAdded);
- end;
- {$IFNDEF RVDONOTUSELIVESPELL}
- Len := 0;
- {$ENDIF}
- if (StartItemNo<>0) and
- RV_CanConcateItems(StartItemNo-1, GetItem(StartItemNo-1), GetItem(StartItemNo), False) then begin
- if CaretBefore or (StartItemNo=EndItemNo) then
- inc(Offs, ItemLength(StartItemNo-1));
- {$IFNDEF RVDONOTUSELIVESPELL}
- Len := ItemLength(StartItemNo-1);
- {$ENDIF}
- Do_Concate(StartItemNo-1);
- dec(ItemsAdded);
- dec(EndItemNo);
- dec(StartItemNo);
- {$IFNDEF RVDONOTUSELIVESPELL}
- GetItem(StartItemNo).ClearWordPainters(Len);
- {$ENDIF}
- end;
- AdjustInItemsRange(StartItemNo);
- AdjustInItemsRange(EndItemNo);
- if CalculateMinItemsWidthPlusEx(StartItemNo,EndItemNo)>DocumentWidth then
- FullReformat := True;
- // formatting
- Reformat_(FullReformat, DIStartNo,DIEndNo,ItemsAdded);
- if CaretBefore then
- Item2DrawItem(StartItemNo,Offs, CaretDrawItemNo, CDIOffs)
- else
- Item2DrawItem(EndItemNo,Offs, CaretDrawItemNo, CDIOffs);
- OnChangeCaretLine(CDIOffs-2);
- ChangeCaret(False,True,False,True);
- {$IFNDEF RVDONOTUSELISTS}
- if not FullReformat and (GetItemStyle(GetFirstParaItem(StartItemNo))=rvsListMarker) then
- UpdateRangeAfterMarkers(StartItemNo, EndItemNo);
- {$ENDIF}
- {$IFNDEF RVDONOTUSELIVESPELL}
- LaterSetBackLiveSpellingTo(StartItemNo, Len+1, True);
- {$ENDIF}
- end;
- {------------------------------------------------------------------------------}
- function TRVEditRVData.InsertItemFromTextFile(var s: String; item: TCustomRVItemInfo;
- AutoTag, BR: Boolean; var FirstIP, InsertPoint, ItemsAdded, MarkerItemNo: Integer;
- var FirstItem, PageBreak, FromNewLine, FullReformat: Boolean) : Boolean;
- var Dummy: Integer;
- {$IFNDEF RVDONOTUSELISTS}
- FR: Boolean;
- {$ENDIF}
- begin
- Result := False;
- if PageBreak then begin
- item.PageBreakBefore := True;
- PageBreak := False;
- end;
- if FirstItem then begin
- if not InsSomething(item, s, AutoTag, InsertPoint, ItemsAdded, FullReformat, Dummy) then begin
- Beep;
- exit;
- end;
- FirstIP := InsertPoint;
- {$IFNDEF RVDONOTUSELISTS}
- MarkerItemNo := GetFirstParaItem(InsertPoint);
- if GetItemStyle(MarkerItemNo)<>rvsListMarker then
- MarkerItemNo := -1;
- {$ENDIF}
- FirstItem := False;
- end
- else begin
- inc(InsertPoint);
- inc(ItemsAdded);
- {$IFNDEF RVDONOTUSELISTS}
- if FromNewLine and not BR and (MarkerItemNo>=0) then begin
- FR := False;
- ReplicateMarker(MarkerItemNo, InsertPoint, FR, False);
- FullReformat := FullReformat or FR;
- inc(InsertPoint);
- inc(ItemsAdded);
- item.SameAsPrev := True;
- end
- else
- {$ENDIF}
- begin
- item.SameAsPrev := not FromNewLine;
- if FromNewLine and BR then
- item.BR := True;
- end;
- item.Inserting(Self, s, False);
- Items.InsertObject(InsertPoint, s, item);
- item.Inserted(Self, InsertPoint);
- end;
- FromNewLine := False;
- Result := True;
- end;
- {------------------------------------------------------------------------------}
- procedure TRVEditRVData.InsertText_(const text: String; AutoTag, CaretBefore: Boolean);
- var DIStartNo, DIEndNo: Integer;
- fulltextstartptr, startptr, ptr, endptr: PChar;
- SkipIfEqual: Char;
- ItemsAdded, FirstIP,InsertPoint: Integer;
- FirstItem: Boolean;
- {$IFNDEF RVDONOTUSEUNICODE}
- ToUnicode: Boolean;
- CodePage: Cardinal;
- {$ENDIF}
- MarkerItemNo: Integer;
- FullReformat: Boolean;
- FromNewLine, ProcessPageBreaks, PageBreak, ProcessTabs: Boolean;
- {............................................................}
- function InsertTextItem: Boolean;
- var s: String;
- item: TCustomRVItemInfo;
- begin
- s := System.Copy(text, StartPtr-FullTextStartPtr+1, Ptr-StartPtr);
- if not ProcessTabs then
- s := RV_ReplaceTabsA(s, GetRVStyle.SpacesInTab);
- {$IFNDEF RVDONOTUSEUNICODE}
- if ToUnicode then
- s := RVU_AnsiToUnicode(CodePage, s);
- {$ENDIF}
- item := CreateTextItem(0, FCurParaStyleNo, FCurTextStyleNo, False, False);
- Result := InsertItemFromTextFile(s, item, AutoTag, False, FirstIP, InsertPoint,
- ItemsAdded, MarkerItemNo, FirstItem, PageBreak, FromNewLine,
- FullReformat);
- end;
- {............................................................}
- function InsertTabItem: Boolean;
- var s: String;
- item: TRVTabItemInfo;
- begin
- item := TRVTabItemInfo.Create(Self);
- item.StyleNo := rvsTab;
- item.TextStyleNo := FCurTextStyleNo;
- item.ParaNo := FCurParaStyleNo;
- Result := InsertItemFromTextFile(s, item, AutoTag, False, FirstIP, InsertPoint,
- ItemsAdded, MarkerItemNo, FirstItem, PageBreak, FromNewLine,
- FullReformat);
- end;
- {............................................................}
- begin
- if Text='' then begin
- Invalidate;
- exit;
- end;
- GetParaBounds(CaretDrawItemNo,CaretDrawItemNo,DIStartNo,DIEndNo);
- FullReformat := False;
- FirstItem := True;
- InsertPoint := -1;
- FirstIP := -1;
- ItemsAdded := 0;
- FullTextStartPtr := PChar(Text);
- StartPtr := FullTextStartPtr;
- Ptr := StartPtr;
- EndPtr := FullTextStartPtr+Length(Text);
- SkipIfEqual := #0;
- ProcessPageBreaks := SupportsPageBreaks;
- PageBreak := False;
- ProcessTabs := (GetRVStyle<>nil) and (GetRVStyle.SpacesInTab<=0);
- FromNewLine := False;
- {$IFNDEF RVDONOTUSEUNICODE}
- ToUnicode := GetRVStyle.TextStyles[GetActualCurStyleNo].Unicode;
- CodePage := GetStyleCodePage(GetActualCurStyleNo);
- {$ENDIF}
- {$IFNDEF RVDONOTUSELISTS}
- MarkerItemNo := -1;
- {$ENDIF}
- while Ptr<EndPtr do begin
- if SkipIfEqual<>#0 then begin
- if (ptr^=SkipIfEqual) then begin
- inc(StartPtr);
- inc(Ptr);
- SkipIfEqual := #0;
- continue;
- end;
- SkipIfEqual := #0;
- end;
- if ((Ptr^) in [#10, #12, #13]) or (ProcessTabs and ((Ptr^)=#9)) then begin
- if not InsertTextItem then
- exit;
- StartPtr := Ptr+1;
- end;
- case Ptr^ of
- #9: // tab
- begin
- if ProcessTabs then begin
- if not InsertTabItem then
- exit;
- FromNewLine := False;
- end;
- end;
- #12: // page break
- begin
- PageBreak := ProcessPageBreaks;
- FromNewLine := True;
- end;
- #13:
- begin
- FromNewLine := True;
- SkipIfEqual := #10;
- end;
- #10:
- begin
- FromNewLine := True;
- SkipIfEqual := #13;
- end;
- end;
- inc(ptr);
- end;
- if not InsertTextItem then
- exit;
- if InsertPoint=-1 then
- exit;
- AfterAddingText(FirstIP, InsertPoint, ItemsAdded, DIStartNo, DIEndNo,
- FullReformat, CaretBefore);
- end;
- {------------------------------------------------------------------------------}
- procedure TRVEditRVData.InsertTextTyping(text: String; Key: Char);
- var ditem: TRVDrawLineInfo;
- item: TCustomRVItemInfo;
- ItemNo, Offs, Len : Integer;
- s: String;
- Minus,SavedCaretOffs: Integer;
- {.....................................................}
- procedure DoInsert;
- begin
- if not TCustomRichViewEdit(RichView).BeforeChange(False) then
- exit;
- BeginUndoSequence(rvutInsert, True);
- InsertString(Text,FCurTextStyleNo,True,False); { inserting character in new item }
- Refresh;
- Change;
- end;
- {.....................................................}
- begin
- if (GetRVStyle=nil) or (PartialSelectedItem<>nil) or not CanDelete then begin
- Beep;
- exit;
- end;
- Len := Length(text);
- {$IFNDEF RVDONOTUSEUNICODE}
- if GetRVStyle.TextStyles[GetActualCurStyleNo].Unicode then
- Len := Length(text) div 2;
- {$ENDIF}
- CaretDrawItemNo := CharEnds.Items[CaretOffs].DrawItemNo;
- ditem := DrawItems[CaretDrawItemNo];
- Minus := 1;
- item := GetItem(ditem.ItemNo);
- if IsParaProtected(item.ParaNo,rvpaoReadOnly) then begin
- Beep;
- exit;
- end;
- Offs := CharEnds.Items[CaretOffs].Offset-1;
- if item.StyleNo<>FCurTextStyleNo then
- if (
- ((item.StyleNo<0) and (CharEnds.Items[CaretOffs].Offset=1)) or
- ((item.StyleNo>=0) and (ditem.Offs+CharEnds.Items[CaretOffs].Offset-1>ItemLength(ditem.ItemNo)))
- ) and
- (CaretDrawItemNo<>DrawItems.Count-1) then begin
- ditem := DrawItems[CaretDrawItemNo+1];
- item := GetItem(ditem.ItemNo);
- Minus := 2;
- Offs := 1;
- if (not item.SameAsPrev) or
- (item.StyleNo<>FCurTextStyleNo) then begin
- DoInsert;
- exit;
- end;
- inc(CaretOffs);
- end
- else begin
- DoInsert;
- exit;
- end;
- { inserting in existing item }
- if item.StyleNo>=0 then begin
- if (rvprConcateProtect in GetRVStyle.TextStyles[GetActualStyle(item)].Protection) or
- (
- (rvprModifyProtect in GetRVStyle.TextStyles[GetActualStyle(item)].Protection) and
- ((ditem.Offs+Offs+1-Minus <= GetOffsBeforeItem(ditem.ItemNo)) or
- (ditem.Offs+Offs+1-Minus >= GetOffsAfterItem(ditem.ItemNo)))
- )
- then begin
- if Minus=2 then
- dec(CaretOffs);
- DoInsert;
- exit;
- end;
- if rvprModifyProtect in GetRVStyle.TextStyles[GetActualStyle(item)].Protection then begin
- if Minus=2 then
- dec(CaretOffs);
- Beep;
- exit;
- end;
- end;
- SavedCaretOffs := ditem.Offs+Offs;
- ItemNo := ditem.ItemNo;
- if Len>1 then begin
- BeginUndoSequence(rvutMiscTyping, True);
- Do_InsertSubstring(ItemNo, ditem.Offs+Offs+1-Minus, text);
- {$IFNDEF RVDONOTUSELIVESPELL}
- LaterSetBackLiveSpellingTo(ItemNo, 0, True);
- {$ENDIF}
- end
- else begin
- UndoList.AddTyping(ItemNo, ditem.Offs+Offs+1-Minus, rvioUnicode in GetItemOptions(ditem.ItemNo));
- s := Items[ItemNo];
- if Length(s)=0 then
- GetItem(ItemNo).ParaNo := FCurParaStyleNo;
- RVU_Insert(Text, s, SavedCaretOffs+1-Minus, GetItemOptions(ditem.ItemNo));
- {$IFNDEF RVDONOTUSELIVESPELL}
- TCustomRichView(RichView).AdjustLiveSpellingOnKeyPress(Self.GetSourceRVData, ItemNo,
- SavedCaretOffs+1-Minus, Key);
- {$ENDIF}
- ItemAction(rviaTextModifying, GetItem(ItemNo), s, Self);
- Items[ItemNo] := s;
- end;
- if CalculateParaSectionMinWidthDef(ItemNo)>DocumentWidth then begin
- Format_(False, True, False, 0, GetCanvas, False, False, False);
- Invalidate;
- end
- else
- FormatParas(CharEnds.Items[0].DrawItemNo, CharEnds.Items[CharEnds.Count-1].DrawItemNo,0);
- Item2DrawItem(ItemNo, SavedCaretOffs+1, CaretDrawItemNo, CaretOffs);
- OnChangeCaretLine(CaretOffs-Minus-1);
- ChangeCaret(False,True,False,False);
- Change;
- end;
- {------------------------------------------------------------------------------}
- procedure TRVEditRVData.InsertTextW_(const text: String; AutoTag, CaretBefore: Boolean);
- var DIStartNo, DIEndNo: Integer;
- startptr,ptr,endptr: PWord;
- SkipIfEqual: Word;
- ItemsAdded, FirstIP,InsertPoint: Integer;
- FirstItem: Boolean;
- ANP: Boolean;
- ConvertToAnsi: Boolean;
- CodePage: Cardinal;
- FullReformat: Boolean;
- PageBreak, ProcessTabs, FromNewLine: Boolean;
- MarkerItemNo: Integer;
- {............................................................}
- function InsertTextItem: Boolean;
- var s: String;
- item: TCustomRVItemInfo;
- begin
- s := System.Copy(text, PChar(startptr)-PChar(text)+1, PChar(ptr)-PChar(startptr));
- if not ProcessTabs then
- s := RV_ReplaceTabsW(s, GetRVStyle.SpacesInTab);
- if ConvertToAnsi then
- s := RVU_UnicodeToAnsi(CodePage, s);
- item := CreateTextItem(0, FCurParaStyleNo, FCurTextStyleNo, False, False);
- Result := InsertItemFromTextFile(s, item, AutoTag, not ANP, FirstIP, InsertPoint,
- ItemsAdded, MarkerItemNo, FirstItem, PageBreak, FromNewLine,
- FullReformat);
- StartPtr := PWord(PChar(Ptr)+2);
- end;
- {............................................................}
- function InsertTabItem: Boolean;
- var s: String;
- item: TRVTabItemInfo;
- begin
- item := TRVTabItemInfo.Create(Self);
- item.StyleNo := rvsTab;
- item.TextStyleNo := FCurTextStyleNo;
- item.ParaNo := FCurParaStyleNo;
- Result := InsertItemFromTextFile(s, item, AutoTag, not ANP, FirstIP, InsertPoint,
- ItemsAdded, MarkerItemNo, FirstItem, PageBreak, FromNewLine,
- FullReformat);
- end;
- {............................................................}
- begin
- FullReformat := False;
- RVCheckUni(Length(text));
- {$IFNDEF RVDONOTUSEUNICODE}
- ConvertToAnsi := not GetRVStyle.TextStyles[GetActualCurStyleNo].Unicode;
- CodePage := GetStyleCodePage(GetActualCurStyleNo);
- {$ENDIF}
- {$IFNDEF RVDONOTUSELISTS}
- MarkerItemNo := -1;
- {$ENDIF}
- ProcessTabs := (GetRVStyle<>nil) and (GetRVStyle.SpacesInTab<=0);
- GetParaBounds(CaretDrawItemNo,CaretDrawItemNo,DIStartNo,DIEndNo);
- FirstItem := True;
- InsertPoint := -1;
- FirstIP := -1;
- ItemsAdded := 0;
- StartPtr := PWord(PChar(Text));
- EndPtr := PWord(PChar(Text)+Length(Text));
- RVU_ProcessByteOrderMark(StartPtr, Length(Text) div 2);
- Ptr := StartPtr;
- if Ptr=EndPtr then begin
- Invalidate;
- exit;
- end;
- SkipIfEqual := 0;
- ANP := True;
- PageBreak := False;
- FromNewLine := True;
- while PChar(ptr)<PChar(endptr) do begin
- if SkipIfEqual<>0 then begin
- if (ptr^=SkipIfEqual) then begin
- inc(PChar(startptr),2);
- inc(PChar(ptr),2);
- SkipIfEqual := 0;
- continue;
- end;
- SkipIfEqual := 0;
- end;
- case ptr^ of
- UNI_LineSeparator, UNI_VerticalTab:
- begin
- if not InsertTextItem then
- exit;
- ANP := False;
- FromNewLine := True;
- end;
- UNI_ParagraphSeparator:
- begin
- if not InsertTextItem then
- exit;
- ANP := True;
- FromNewLine := True;
- end;
- UNI_FF:
- begin
- if not InsertTextItem then
- exit;
- PageBreak := SupportsPageBreaks;
- FromNewLine := True;
- end;
- UNI_CR:
- begin
- if not InsertTextItem then
- exit;
- ANP := True;
- SkipIfEqual := UNI_LF;
- FromNewLine := True;
- end;
- UNI_LF:
- begin
- if not InsertTextItem then
- exit;
- ANP := True;
- SkipIfEqual := UNI_CR;
- FromNewLine := True;
- end;
- UNI_Tab:
- begin
- if ProcessTabs then begin
- if not InsertTextItem then
- exit;
- if not InsertTabItem then
- exit;
- FromNewLine := False;
- end;
- end;
- end;
- inc(PChar(ptr), 2);
- end;
- if not InsertTextItem then
- exit;
- if InsertPoint=-1 then exit;
- AfterAddingText(FirstIP, InsertPoint, ItemsAdded, DIStartNo,DIEndNo,FullReformat, CaretBefore);
- end;
- {------------------------------------------------------------------------------}
- function TRVEditRVData.InsertRVFFromStreamEd_(Stream: TStream):Boolean;
- var
- Offs,CDIOffs : Integer;
- DIStartNo, DIEndNo: Integer;
- InsertPoint, LastInserted: Integer;
- dli: TRVDrawLineInfo;
- li: TCustomRVItemInfo;
- FullFormat, FR: Boolean;
- Color : TColor;
- NonFirstItemsAdded, ItemsAdded: Integer;
- ui: TRVUndoInsertItemsInfo;
- FailedBecauseOfProtect: Boolean;
- begin
- GetParaBounds(CaretDrawItemNo,CaretDrawItemNo,DIStartNo,DIEndNo);
- with CharEnds.Items[CaretOffs] do begin
- dli := DrawItems[DrawItemNo];
- li := GetItem(dli.ItemNo);
- InsertPoint := dli.ItemNo;
- if ((li.StyleNo>=0) and (dli.Offs+Offset-1>=GetOffsAfterItem(dli.ItemNo))) or
- ((li.StyleNo<0) and (Offset=1)) then
- inc(InsertPoint);
- end;
- BeginUndoSequence(rvutInsert, True);
- ItemsAdded := Items.Count;
- Color := TCustomRichView(FRichView).Color;
- FRVFInserted := False;
- Result := InsertRVFFromStream_(Stream, InsertPoint, -1, False, False, True,
- Color, TCustomRichView(FRichView).Background, nil, NonFirstItemsAdded,
- FailedBecauseOfProtect, FullFormat);
- if Result and FailedBecauseOfProtect or not FRVFInserted then
- exit;
- if not Result then begin
- TCustomRichViewEdit(FRichView).Format;
- Invalidate;
- Beep;
- exit;
- end;
- TCustomRichView(FRichView).Color := Color;
- ItemsAdded := Items.Count - ItemsAdded;
- LastInserted := InsertPoint+NonFirstItemsAdded;
- if LastInserted>=Items.Count then
- exit;
- Offs := GetOffsAfterItem(LastInserted);
- ui := Do_InsertItems_1(InsertPoint+1, NonFirstItemsAdded);
- Do_InsertItems_2(InsertPoint+1, NonFirstItemsAdded, ui, FR);
- if InsertPoint<0 then
- InsertPoint := 0;
- FullFormat := FullFormat or FR or (CalculateMinItemsWidthPlusEx(InsertPoint,LastInserted) > DocumentWidth);
- ConcateAfterAdding(InsertPoint, LastInserted, ItemsAdded, Offs);
- // formatting
- if FullFormat then begin
- Format_(False,True, False, 0,GetCanvas,False, False, False);
- Invalidate;
- end
- else
- FormatParasExact(DIStartNo,DIEndNo,ItemsAdded, False);
- Item2DrawItem(LastInserted, Offs, CaretDrawItemNo, CDIOffs);
- OnChangeCaretLine(CDIOffs-2);
- ChangeCaret(False,True,False,True);
- {$IFNDEF RVDONOTUSELISTS}
- if not FullFormat then
- UpdateRangeAfterMarkers(InsertPoint,LastInserted);
- {$ENDIF}
- end;
- {------------------------------------------------------------------------------}
- {$IFNDEF RVDONOTUSERTFIMPORT}
- function TRVEditRVData.InsertRTFFromStreamEd_(Stream: TStream): Boolean;
- var
- Offs,CDIOffs : Integer;
- DIStartNo, DIEndNo: Integer;
- ItemsAdded, InsertPoint, LastInserted: Integer;
- dli: TRVDrawLineInfo;
- li: TCustomRVItemInfo;
- FullFormat, FR: Boolean;
- ui: TRVUndoInsertItemsInfo;
- rp: TRVRTFReaderProperties;
- begin
- if Stream.Position=Stream.Size then begin
- Result := True;
- exit;
- end;
- Result := False;
- rp := TRVRTFReaderProperties(GetRTFProperties);
- if rp=nil then
- exit;
- GetParaBounds(CaretDrawItemNo,CaretDrawItemNo,DIStartNo,DIEndNo);
- with CharEnds.Items[CaretOffs] do begin
- dli := DrawItems[DrawItemNo];
- li := GetItem(dli.ItemNo);
- InsertPoint := dli.ItemNo;
- if ((li.StyleNo>=0) and (dli.Offs+Offset-1>=GetOffsAfterItem(dli.ItemNo))) or
- ((li.StyleNo<0) and (Offset=1)) then
- inc(InsertPoint);
- end;
- BeginUndoSequence(rvutInsert, True);
- ItemsAdded := Items.Count;
- Result := rp.InsertFromStreamEd(Stream, Self, InsertPoint)=rtf_ec_OK;
- if Result and rp.FailedBecauseOfProtect or (InsertPoint<0) then
- exit;
- if not Result then begin
- TCustomRichViewEdit(FRichView).Format;
- Invalidate;
- Beep;
- exit;
- end;
- ItemsAdded := Items.Count-ItemsAdded;
- LastInserted := InsertPoint+rp.NonFirstItemsAdded;
- Offs := GetOffsAfterItem(LastInserted);
- ui := Do_InsertItems_1(InsertPoint+1, rp.NonFirstItemsAdded);
- Do_InsertItems_2(InsertPoint+1, rp.NonFirstItemsAdded, ui, FR);
- FullFormat := rp.FullReformat or FR or (CalculateMinItemsWidthPlusEx(InsertPoint,LastInserted) > DocumentWidth);
- ConcateAfterAdding(InsertPoint, LastInserted, ItemsAdded, Offs);
- // formatting
- if FullFormat then begin
- Format_(False,True,False, 0,GetCanvas,False, False, False);
- Invalidate;
- end
- else
- FormatParasExact(DIStartNo,DIEndNo,ItemsAdded, False);
- Item2DrawItem(LastInserted, Offs, CaretDrawItemNo, CDIOffs);
- OnChangeCaretLine(CDIOffs-2);
- ChangeCaret(False,True,False,True);
- {$IFNDEF RVDONOTUSELISTS}
- if not FullFormat then
- UpdateRangeAfterMarkers(InsertPoint,LastInserted);
- {$ENDIF}
- end;
- {$ENDIF}
- {------------------------------------------------------------------------------}
- {$IFNDEF RVDONOTUSERTF}
- function TRVEditRVData.SaveRTFToStream(Stream: TStream; const Path: String;
- SelectionOnly: Boolean; Level: Integer; Color: TColor;
- Background: TRVBackground; ColorList: TRVColorList;
- StyleToFont, ListOverrideOffsetsList1, ListOverrideOffsetsList2: TRVIntegerList;
- FontTable: TRVRTFFontTable; tpp: Double):Boolean;
- begin
- if rvflRootEditor in Flags then
- BuildJumpsCoords(False);
- Result := inherited SaveRTFToStream(Stream, Path, SelectionOnly, Level, Color,
- Background, ColorList, StyleToFont,
- ListOverrideOffsetsList1, ListOverrideOffsetsList2, FontTable, tpp);
- if rvflRootEditor in Flags then
- ClearJumpsCoords;
- end;
- {$ENDIF}
- {------------------------------------------------------------------------------}
- procedure TRVEditRVData.ConcateAfterAdding(var InsertPoint, LastInserted, ItemsAdded, Offs: Integer);
- var li, li2: TCustomRVItemInfo;
- i: Integer;
- atend: Boolean;
- fr: Boolean;
- {$IFNDEF RVDONOTUSELIVESPELL}
- Len: Integer;
- {$ENDIF}
- begin
- if LastInserted<>Items.Count-1 then begin
- li := GetItem(LastInserted);
- li2 := GetItem(LastInserted+1);
- if RV_CanConcateItems(LastInserted, li,li2,False) then begin
- Do_Concate(LastInserted);
- {$IFNDEF RVDONOTUSELIVESPELL}
- GetItem(LastInserted).ClearWordPainters(0);
- {$ENDIF}
- dec(ItemsAdded);
- end
- else if li.GetBoolValue(rvbpFullWidth) and li2.SameAsPrev then
- Do_NewLine(LastInserted+1,False,li2.ParaNo,fr);
- end;
- atend := True;
- for i := LastInserted downto InsertPoint+1 do begin
- li := GetItem(i-1);
- li2 := GetItem(i);
- SimpleConcateSubitems(i);
- if RV_CanConcateItems(i-1, li,li2,False) then begin
- if atend then
- inc(Offs, RVU_Length(Items[i-1], GetItemOptions(i-1)));
- Do_Concate(i-1);
- dec(ItemsAdded);
- dec(LastInserted);
- end
- else
- atend := False;
- end;
- if (InsertPoint>=0) and (InsertPoint<ItemCount) then
- SimpleConcateSubitems(InsertPoint);
- if InsertPoint<>0 then begin
- li := GetItem(InsertPoint-1);
- li2 := GetItem(InsertPoint);
- if RV_CanConcateItems(InsertPoint-1, li,li2,False) then begin
- if atend then
- inc(Offs, RVU_Length(Items[InsertPoint-1], GetItemOptions(InsertPoint-1)));
- {$IFNDEF RVDONOTUSELIVESPELL}
- Len := ItemLength(InsertPoint-1);
- {$ENDIF}
- Do_Concate(InsertPoint-1);
- {$IFNDEF RVDONOTUSELIVESPELL}
- LaterSetBackLiveSpellingTo(InsertPoint-1, Len+1, True);
- {$ENDIF}
- dec(ItemsAdded);
- dec(LastInserted);
- end
- else begin
- if (li2.StyleNo>=0) and li2.SameAsPrev and (Items[InsertPoint]='')
- {$IFNDEF RVDONOTUSELISTS}
- and (li.StyleNo<>rvsListMarker)
- {$ENDIF}
- then begin
- Do_DeleteItem(InsertPoint, fr);
- dec(ItemsAdded);
- dec(LastInserted);
- if InsertPoint=ItemCount then
- dec(InsertPoint);
- end;
- {$IFNDEF RVDONOTUSELIVESPELL}
- LaterSetBackLiveSpellingTo(InsertPoint, 0, True);
- {$ENDIF}
- end;
- end;
- end;
- {------------------------------------------------------------------------------}
- procedure TRVEditRVData.GetSelStart(var DINo, DIOffs: Integer);
- begin
- inherited GetSelStart(DINo,DIOffs);
- if (DINo=-1) and (CaretDrawItemNo<>-1) then
- with CharEnds.Items[CaretOffs] do begin
- DINo := DrawItemNo;
- DIOffs := Offset;
- end;
- end;
- {------------------------------------------------------------------------------}
- procedure TRVEditRVData.SrchSelectIt(strt, offs, len: Integer; Invert: Boolean);
- begin
- {$IFNDEF RVDONOTUSELIVESPELL}
- LiveSpellingCheckCurrentItem;
- {$ENDIF}
- DeselectPartiallySelectedItem(nil);
- if not Invert then
- RestoreSelBounds(strt,strt,offs,offs+len)
- else
- RestoreSelBounds(strt,strt,offs+len,offs);
- Invalidate;
- DoOnSelection(True);
- DoSelect;
- end;
- {------------------------------------------------------------------------------}
- procedure TRVEditRVData.SrchStart(Down: Boolean; var strt, offs: Integer);
- begin
- strt := GetCurItemNo;
- offs := GetOffsetInCurItem;
- if Down and (offs>=GetOffsAfterItem(strt)) then begin
- inc(strt);
- if strt<Items.Count then
- offs := GetOffsBeforeItem(strt);
- end
- else if not Down and (offs<=GetOffsBeforeItem(strt)) then begin
- dec(strt);
- if strt>=0 then
- offs := GetOffsAfterItem(strt);
- end;
- end;
- {------------------------------------------------------------------------------}
- function TRVEditRVData.GetCurItemNo: Integer;
- {........................................}
- function IndexOf(obj: TObject): Integer;
- begin
- if (CaretDrawItemNo>=0) and (Items.Objects[DrawItems[CaretDrawItemNo].ItemNo]=obj) then
- Result := DrawItems[CaretDrawItemNo].ItemNo
- else
- Result := Items.IndexOfObject(obj);
- end;
- {........................................}
- begin
- PrepareForEdit;
- if FPartialSelectedItem<>nil then
- Result := IndexOf(FPartialSelectedItem)
- else if GetChosenItem<>nil then
- Result := IndexOf(GetChosenItem)
- else if CaretDrawItemNo=-1 then
- Result := -1
- else
- Result := DrawItems[CaretDrawItemNo].ItemNo
- end;
- {------------------------------------------------------------------------------}
- function TRVEditRVData.GetOffsetInCurItem: Integer;
- begin
- PrepareForEdit;
- if FPartialSelectedItem<>nil then
- Result := 1
- else if CaretDrawItemNo=-1 then
- Result := -1
- else begin
- if GetDrawItemStyle(CaretDrawItemNo)>=0 then
- Result := DrawItems[CaretDrawItemNo].Offs+CharEnds.Items[CaretOffs].Offset-1
- else
- Result := CharEnds.Items[CaretOffs].Offset;
- end;
- end;
- {------------------------------------------------------------------------------}
- function TRVEditRVData.NotFormatted: Boolean;
- begin
- Result := DrawItems.Count=0;
- end;
- {------------------------------------------------------------------------------}
- procedure TRVEditRVData.StartShiftMoving;
- begin
- with CharEnds.Items[CaretOffs] do
- if not SelectionExists(True, False) then begin
- FSelStartNo := DrawItemNo;
- FSelStartOffs := Offset;
- FSelEndNo := DrawItemNo;
- FSelEndOffs := Offset;
- end;
- end;
- {------------------------------------------------------------------------------}
- procedure TRVEditRVData.EndShiftMoving;
- begin
- with CharEnds.Items[CaretOffs] do begin
- FSelEndNo := DrawItemNo;
- FSelEndOffs := Offset;
- end;
- if GetRVStyle.SelectionMode=rvsmParagraph then
- ExpandSelectionToParagraph(True);
- DoOnSelection(True);
- DoSelect;
- end;
- {------------------------------------------------------------------------------}
- procedure TRVEditRVData.InsertString(var s: String; StyleNo: Integer;
- AutoTag, CaretBefore: Boolean);
- var info: TCustomRVItemInfo;
- begin
- info := RichViewTextItemClass.Create(Self);
- {$IFNDEF RVDONOTUSEUNICODE}
- if GetRVStyle.TextStyles[GetActualStyle2(StyleNo, FCurParaStyleNo)].Unicode then
- Include(info.ItemOptions,rvioUnicode);
- {$ENDIF}
- info.StyleNo := StyleNo;
- InsertSomething(info, s, AutoTag, CaretBefore);
- end;
- {------------------------------------------------------------------------------}
- procedure TRVEditRVData.KeyPress(var Key: Char);
- var Text: String;
- begin
- if (GetRVStyle=nil) or (PartialSelectedItem<>nil) or not CanDelete then begin
- Beep;
- exit;
- end;
- {$IFNDEF RVDONOTUSEUNICODE}
- if GetRVStyle.TextStyles[GetActualCurStyleNo].Unicode then begin
- Text := RVU_KeyToUnicode(Key);
- if Length(Text)=0 then exit;
- end
- else
- {$ENDIF}
- Text := Key;
- InsertTextTyping(Text, Key);
- end;
- {------------------------------------------------------------------------------}
- procedure TRVEditRVData.CreateResizer;
- {..............................................}
- function GetResizerDrawItemNo: Integer;
- begin
- Result := GetOneSelectedItemNo;
- if (Result>=0) and (GetItemStyle(Result)<0) and
- GetItem(Result).GetBoolValue(rvbpResizable) then
- Item2FirstDrawItem(Result, Result)
- else
- Result := -1;
- end;
- {..............................................}
- var ResizerDrawItemNo: Integer;
- begin
- if rvstInvalidSelection in State then
- exit;
- FResizer.Free;
- FResizer := nil;
- if (TCustomRichViewEdit(RichView).ReadOnly and
- not (rvflDBRichViewEdit in GetAbsoluteRootData.Flags)) or
- (rvoNoImageResize in TCustomRichViewEdit(RichView).EditorOptions) then
- exit;
- ResizerDrawItemNo := GetResizerDrawItemNo;
- if (ResizerDrawItemNo>=0) and
- not IsItemParaProtected(DrawItems[ResizerDrawItemNo].ItemNo) then begin
- FResizer := TRVItemResizer.Create(DrawItems[ResizerDrawItemNo],
- GetItem(DrawItems[ResizerDrawItemNo].ItemNo), ResizerDrawItemNo);
- if GetItem(DrawItems[ResizerDrawItemNo].ItemNo).GetBoolValue(rvbpResizeHandlesOutside) then
- FResizer.Position := rvhpOutside;
- end;
- end;
- {------------------------------------------------------------------------------}
- procedure TRVEditRVData.UpdateResizer;
- begin
- if (FResizer<>nil) and
- ((FResizer.DrawItemNo>=DrawItems.Count) or
- (DrawItems[FResizer.DrawItemNo]<>FResizer.DrawItem)) then
- CreateResizer;
- end;
- {------------------------------------------------------------------------------}
- procedure TRVEditRVData.DoOnSelection(AllowScrolling: Boolean);
- begin
- TCustomRichViewEdit(FRichView).Selecting;
- {$IFNDEF RVDONOTUSELISTS}
- if (FSelEndNo>=0) and (GetDrawItemStyle(FSelEndNo)=rvsListMarker) then begin
- inc(FSelEndNo);
- FSelEndOffs := GetOffsBeforeDrawItem(FSelEndNo);
- end;
- {$ENDIF}
- if (FSelEndNo>=0) then begin
- CaretDrawItemNo := FSelEndNo;
- OnChangeCaretLine(FSelEndOffs-2);
- end;
- CreateResizer;
- {$IFDEF RVDEBUG}{$I Debugi.inc}{$ENDIF}
- ChangeCaret(False,AllowScrolling,False,False);
- {$IFNDEF RVDONOTUSEANIMATION}
- ResetAniBackground;
- {$ENDIF}
- end;
- {------------------------------------------------------------------------------}
- procedure TRVEditRVData.Reformat(FullFormat,ForceFormat,NoScroll: Boolean; ItemNo: Integer; UpdateView: Boolean);
- var ln, lo, dlo: Integer;
- curdlno,dummy: Integer;
- begin
- DrawItem2Item(CaretDrawItemNo, CharEnds.Items[CaretOffs].Offset, ln, lo);
- if FullFormat then begin
- Format_(True,ForceFormat,NoScroll, 0,GetCanvas,False, False, False);
- Invalidate;
- end
- else begin
- if ln=ItemNo then
- curdlno := CaretDrawItemNo
- else
- Item2DrawItem(ItemNo,0,curdlno,dummy);
- FormatParas(curdlno,curdlno,0);
- end;
- Item2DrawItem(ln, lo, CaretDrawItemNo, dlo);
- OnChangeCaretLine(dlo-2);
- ChangeCaret( False,UpdateView,False,UpdateView);
- end;
- {------------------------------------------------------------------------------}
- function TRVEditRVData.InsertFirstRVFItem(var Index: Integer;
- var s: String; var li: TCustomRVItemInfo; EditFlag: Boolean;
- var FullReformat: Boolean;
- var NewListNo: Integer):Boolean;
- var ItemsAdded: Integer;
- begin
- if EditFlag then begin
- Result := InsSomething(li, s, False, Index, ItemsAdded, FullReformat, NewListNo);
- FRVFInserted := True;
- if not Result then Beep;
- end
- else
- Result := (inherited InsertFirstRVFItem(Index, s, li, EditFlag, FullReformat, NewListNo));
- end;
- {------------------------------------------------------------------------------}
- procedure TRVEditRVData.AdjustControlPlacement(ItemNo: Integer);
- var dlno: Integer;
- NewWidth, NewHeight, OldWidth, OldHeight: Integer;
- begin
- CheckItemClass(ItemNo, TRVControlItemInfo);
- dlno := FindDrawItemByItem(ItemNo);
- if dlno<0 then
- exit;
- with Items.Objects[ItemNo] as TRVControlItemInfo do
- if (Control<>ResizingControl) then begin
- OldWidth := DrawItems[dlno].Width-2;
- OldHeight := DrawItems[dlno].Height-2;
- NewWidth := Control.Width;
- NewHeight := Control.Height;
- if (NewWidth<>OldWidth) or
- (NewHeight<>OldHeight) then
- DoResizeControl(ItemNo,OldWidth,OldHeight,NewWidth,NewHeight)
- else begin
- Control.Left := DrawItems[dlno].Left+1-GetHOffs;
- Control.Tag := DrawItems[dlno].Top+1-GetVOffs;
- RV_Tag2Y(Control);
- end;
- end;
- end;
- {------------------------------------------------------------------------------}
- procedure TRVEditRVData.ResizeControl(ItemNo, NewWidth, NewHeight: Integer;Reformat: Boolean);
- var OldWidth, OldHeight:Integer;
- begin
- CheckItemClass(ItemNo, TRVControlItemInfo);
- with Items.Objects[ItemNo] as TRVControlItemInfo do begin
- OldWidth := Control.Width;
- OldHeight := Control.Height;
- if (OldWidth=NewWidth) and (OldHeight=NewHeight) then exit;
- ResizingControl := Control;
- try
- Control.SetBounds(Control.Left, Control.Top, NewWidth, NewHeight);
- finally
- ResizingControl := nil;
- end;
- end;
- if Reformat then
- DoResizeControl(ItemNo,OldWidth,OldHeight,NewWidth,NewHeight);
- end;
- {------------------------------------------------------------------------------}
- procedure TRVEditRVData.DoResizeControl(ItemNo, OldWidth,OldHeight,NewWidth,NewHeight: Integer);
- var FullReformat: Boolean;
- NewFWidth, OldFWidth: Integer;
- begin
- NewFWidth := CalculateMinItemWidthPlusEx(ItemNo);
- OldFWidth := NewFWidth-NewWidth+OldWidth;
- FullReformat := (OldFWidth<>NewFWidth) and
- ((OldFWidth>=DocumentWidth) or
- (NewFWidth> DocumentWidth));
- Reformat(FullReformat,False,False,ItemNo,True);
- Invalidate;
- end;
- {------------------------------------------------------------------------------}
- procedure TRVEditRVData.SelectCurrentWord;
- var first, last, ItemNo, Offs, Len: Integer;
- ItemOptions: TRVItemOptions;
- s: String;
- begin
- PrepareForEdit;
- if GetItemStyle(GetCurItemNo)<0 then exit;
- Offs := GetOffsetInCurItem;
- ItemNo := GetCurItemNo;
- Last := Offs;
- First := Offs;
- s := Items[ItemNo];
- Len := ItemLength(ItemNo);
- ItemOptions := GetItemOptions(ItemNo);
- while (Last<=Len) do begin
- if IsDelimiter(s, Last, ItemOptions) then
- break;
- inc(Last);
- end;
- dec(First);
- while (First>0) do begin
- if IsDelimiter(s, First, ItemOptions) then begin
- inc(First);
- break;
- end;
- dec(First);
- end;
- if First=0 then
- inc(First);
- SetSelectionBounds(ItemNo, First, ItemNo, Last);
- Invalidate;
- end;
- {------------------------------------------------------------------------------}
- procedure TRVEditRVData.InsertPageBreak;
- var NeedReformat, FullReformat: Boolean;
- begin
- FullReformat := False;
- Deselect(nil, True);
- BeginUndoSequence(rvutInsertPageBreak, True);
- TCustomRichViewEdit(FRichView).SetUndoGroupMode(True);
- try
- if (GetOffsetInCurItem>GetOffsBeforeItem(GetCurItemNo)) or
- (
- GetItem(GetCurItemNo).SameAsPrev
- {$IFNDEF RVDONOTUSELISTS}
- and not ((GetCurItemNo>0) and (GetItemStyle(GetCurItemNo-1)=rvsListMarker))
- {$ENDIF}
- ) then
- OnEnterPress_(False, False);
- NeedReformat := GetItem(GetCurItemNo).BR;
- Do_BR(GetCurItemNo,False, FullReformat);
- Do_PageBreak(GetCurItemNo,True);
- finally
- TCustomRichViewEdit(FRichView).SetUndoGroupMode(False);
- end;
- if NeedReformat then
- Reformat(FullReformat, True, False, GetCurItemNo,True);
- Refresh;
- Change;
- end;
- {------------------------------------------------------------------------------}
- procedure TRVEditRVData.Change;
- begin
- ChangeEx(True);
- end;
- {------------------------------------------------------------------------------}
- procedure TRVEditRVData.ChangeEx(ClearRedo: Boolean);
- begin
- TCustomRichViewEdit(FRichView).Modified := True;
- if not (rvstDoNotClearCurTag in State) then
- ClearCurTag;
- TCustomRichViewEdit(FRichView).DoChange(ClearRedo);
- end;
- {------------------------------------------------------------------------------}
- procedure TRVEditRVData.SetCurParaStyleNo(Value: Integer);
- begin
- TCustomRichViewEdit(FRichView).CurParaStyleNo := Value;
- end;
- {------------------------------------------------------------------------------}
- procedure TRVEditRVData.SetCurTextStyleNo(Value: Integer);
- begin
- TCustomRichViewEdit(FRichView).CurTextStyleNo := Value;
- end;
- {------------------------------------------------------------------------------}
- {$IFNDEF RVDONOTUSEHTML}
- function TRVEditRVData.SaveHTMLToStreamEx(Stream: TStream;
- const Path, Title, ImagesPrefix, ExtraStyles,
- ExternalCSS, CPPrefix: String;
- Options: TRVSaveOptions; Color: TColor;
- var CurrentFileColor: TColor;
- var imgSaveNo: Integer;
- LeftMargin, TopMargin, RightMargin, BottomMargin: Integer;
- Background: TRVBackground;
- Bullets: TRVList): Boolean;
- begin
- if rvflRootEditor in Flags then
- BuildJumpsCoords(False);
- Result := inherited SaveHTMLToStreamEx(Stream, Path, Title, ImagesPrefix, ExtraStyles,
- ExternalCSS, CPPrefix,
- Options, Color, CurrentFileColor, imgSaveNo,
- LeftMargin, TopMargin, RightMargin, BottomMargin,
- Background,Bullets);
- if rvflRootEditor in Flags then
- ClearJumpsCoords;
- end;
- {------------------------------------------------------------------------------}
- function TRVEditRVData.SaveHTMLToStream(Stream: TStream;
- const Path, Title,ImagesPrefix: String;
- Options: TRVSaveOptions; Color: TColor;
- var imgSaveNo: Integer;
- LeftMargin, TopMargin, RightMargin, BottomMargin: Integer;
- Background: TRVBackground;
- Bullets: TRVList): Boolean;
- begin
- if rvflRootEditor in Flags then
- BuildJumpsCoords(False);
- Result := inherited SaveHTMLToStream(Stream, Path, Title,ImagesPrefix,
- Options, Color, imgSaveNo,
- LeftMargin, TopMargin, RightMargin, BottomMargin,
- Background,Bullets);
- if rvflRootEditor in Flags then
- ClearJumpsCoords;
- end;
- {$ENDIF}
- {------------------------------------------------------------------------------}
- function TRVEditRVData.GetIMEWinCoord: TPoint;
- begin
- with CharEnds.Items[CaretOffs] do begin
- Result.x := X-1+MoveRightTo-GetHOffs;
- Result.y := DrawItems[CaretDrawItemNo].Top-1-GetVOffs;
- end;
- end;
- {------------------------------------------------------------------------------}
- procedure TRVEditRVData.GetSelectionBoundsEx(var StartItemNo,
- StartItemOffs, EndItemNo, EndItemOffs: Integer; Normalize: Boolean);
- begin
- if SelectionExists(False,False) then
- inherited
- else begin
- StartItemNo := GetCurItemNo;
- EndItemNo := StartItemNo;
- StartItemOffs := GetOffsetInCurItem;
- EndItemOffs := StartItemOffs;
- end;
- end;
- {------------------------------------------------------------------------------}
- procedure TRVEditRVData.GetSelBounds(var StartNo, EndNo, StartOffs, EndOffs: Integer;
- Normalize: Boolean);
- begin
- if (FSelStartNo>=0) and (FSelEndNo>=0) then
- inherited
- else begin
- StartNo := CaretDrawItemNo;
- EndNo := StartNo;
- if StartNo>=0 then
- StartOffs := CharEnds.Items[CaretOffs].Offset
- else
- StartOffs := -1;
- EndOffs := StartOffs;
- end;
- end;
- {------------------------------------------------------------------------------}
- procedure TRVEditRVData.BeginItemModify(ItemNo: Integer; var ModifyData: Integer);
- begin
- ModifyData := CalculateMinItemWidthPlusEx(ItemNo);
- end;
- {------------------------------------------------------------------------------}
- procedure TRVEditRVData.EndItemModify(ItemNo, ModifyData: Integer);
- var NewW: Integer;
- FullReformat: Boolean;
- begin
- NewW := CalculateMinItemWidthPlusEx(ItemNo);
- FullReformat := (NewW<>ModifyData) and
- ((ModifyData>=DocumentWidth) or (NewW>DocumentWidth));
- Reformat(FullReformat, True, False, ItemNo, True);
- end;
- {------------------------------------------------------------------------------}
- procedure TRVEditRVData.DeselectPartiallySelectedItem(NewPartiallySelected: TCustomRVItemInfo);
- var r: Boolean;
- RVData: TCustomRVData;
- begin
- r := (FPartialSelectedItem<>nil);
- if r then begin
- RVData := Self;
- while RVData<>nil do begin
- if (rvstClearing in RVData.State) then begin
- r := False;
- break;
- end;
- RVData := RVData.GetAbsoluteParentData;
- end;
- end;
- inherited DeselectPartiallySelectedItem(NewPartiallySelected);
- if r then
- TCustomRichViewEdit(FRichView).AfterCaretMove;
- end;
- {------------------------------------------------------------------------------}
- procedure TRVEditRVData.SetPartialSelectedItem(Item: TCustomRVItemInfo);
- var r: Boolean;
- begin
- r := FPartialSelectedItem<>Item;
- inherited SetPartialSelectedItem(Item);
- if r then
- TCustomRichViewEdit(FRichView).AfterCaretMove;
- end;
- {------------------------------------------------------------------------------}
- procedure TRVEditRVData.MarkStylesInUse(Data: TRVDeleteUnusedStylesData);
- begin
- inherited MarkStylesInUse(Data);
- if FCurTextStyleNo<>-1 then begin
- FCurTextStyleNo := GetActualCurStyleNo;
- Data.UsedTextStyles[FCurTextStyleNo] := 1;
- end;
- if FCurParaStyleNo<>-1 then
- Data.UsedParaStyles[FCurParaStyleNo] := 1;
- end;
- {------------------------------------------------------------------------------}
- procedure TRVEditRVData.AfterDeleteStyles(Data: TRVDeleteUnusedStylesData);
- {$IFNDEF RVDONOTUSEINPLACE}
- var inplace: TControl;
- {$ENDIF}
- begin
- TCustomRichViewEdit(FRichView).ClearUndo;
- if FCurTextStyleNo<>-1 then
- dec(FCurTextStyleNo, Data.UsedTextStyles[FCurTextStyleNo]-1);
- if Data.UsedTextStyles[FPrevTextStyleNo]>0 then
- dec(FPrevTextStyleNo, Data.UsedTextStyles[FPrevTextStyleNo]-1)
- else
- FPrevTextStyleNo := 0;
- if FCurParaStyleNo<>-1 then
- dec(FCurParaStyleNo, Data.UsedParaStyles[FCurParaStyleNo]-1);
- {$IFNDEF RVDONOTUSEINPLACE}
- inplace := GetInplaceEditor;
- if inplace=nil then
- {$ENDIF}
- begin
- State := State + [rvstForceStyleChangeEvent];
- SetCurTextStyleNo(FCurTextStyleNo);
- State := State + [rvstForceStyleChangeEvent];
- SetCurParaStyleNo(FCurParaStyleNo);
- end;
- inherited AfterDeleteStyles(Data);
- end;
- {------------------------------------------------------------------------------}
- {$IFNDEF RVDONOTUSELISTS}
- function TRVEditRVData.ReplicateMarker(ReferenceItemNo,
- InsertItemNo: Integer; var FullReformat: Boolean;
- EditFlag: Boolean): Boolean;
- var Marker: TRVMarkerItemInfo;
- s: String;
- begin
- Result := False;
- if ReferenceItemNo<0 then
- exit;
- ReferenceItemNo := GetFirstParaItem(ReferenceItemNo);
- if GetItemStyle(ReferenceItemNo)<>rvsListMarker then
- exit;
- Marker := TRVMarkerItemInfo(RV_DuplicateItem(GetItem(ReferenceItemNo), Self,
- False));
- Marker.DeleteProtect := False;
- Marker.Reset := False;
- s := Items[ReferenceItemNo];
- if EditFlag then
- Do_InsertItem(InsertItemNo, s, Marker, False, FullReformat)
- else begin
- Marker.Inserting(Self, s, False);
- Items.InsertObject(InsertItemNo,s,Marker);
- Marker.Inserted(Self, InsertItemNo);
- AddMarkerInList(InsertItemNo);
- end;
- Result := True;
- end;
- {------------------------------------------------------------------------------}
- procedure TRVEditRVData.AdjustMarkerPos(var ItemNo, Offs: Integer;
- DefRight: Boolean);
- var Right: Boolean;
- begin
- if GetItemStyle(ItemNo)<>rvsListMarker then
- exit;
- Right := (Offs=1) or DefRight;
- if ItemNo=0 then
- Right := True;
- if Right and (ItemNo+1>=Items.Count) then
- exit;
- if Right then begin
- inc(ItemNo);
- Offs := GetOffsBeforeItem(ItemNo);
- end
- else begin
- dec(ItemNo);
- Offs := GetOffsAfterItem(ItemNo);
- end;
- end;
- {------------------------------------------------------------------------------}
- procedure TRVEditRVData.AdjustMarkerCaret(Right: Boolean; var Offs: Integer);
- begin
- if GetDrawItemStyle(CaretDrawItemNo)<>rvsListMarker then
- exit;
- if CaretDrawItemNo=0 then
- Right := True;
- if Right then begin
- inc(CaretDrawItemNo);
- Offs := GetOffsBeforeDrawItem(CaretDrawItemNo);
- end
- else begin
- dec(CaretDrawItemNo);
- Offs := GetOffsAfterDrawItem(CaretDrawItemNo);
- end;
- end;
- {$ENDIF}
- {------------------------------------------------------------------------------}
- function TRVEditRVData.CaretAtTheBeginningOfParaSection: Boolean;
- var item: TCustomRVItemInfo;
- dli: TRVDrawLineInfo;
- begin
- CaretDrawItemNo := CharEnds.Items[CaretOffs].DrawItemNo;
- dli := DrawItems[CaretDrawItemNo];
- item := GetItem(dli.ItemNo);
- if CaretOffs=0 then begin
- Result := (dli.Offs+CharEnds.Items[CaretOffs].Offset-1<=GetOffsBeforeItem(dli.ItemNo));
- if Result then
- Result := not item.SameAsPrev
- {$IFNDEF RVDONOTUSELISTS}
- or (item.SameAsPrev and (dli.ItemNo>0) and (GetItemStyle(dli.ItemNo-1)=rvsListMarker))
- {$ENDIF}
- ;
- end
- else
- Result := False;
- end;
- {------------------------------------------------------------------------------}
- function TRVEditRVData.CaretAtTheEndOfParaSection: Boolean;
- var item: TCustomRVItemInfo;
- dli: TRVDrawLineInfo;
- begin
- CaretDrawItemNo := CharEnds.Items[CaretOffs].DrawItemNo;
- dli := DrawItems[CaretDrawItemNo];
- item := GetItem(dli.ItemNo);
- Result := (CaretOffs=CharEnds.Count-1) and
- ((dli.ItemNo+1=Items.Count) or
- (not GetItem(dli.ItemNo+1).SameAsPrev)) and
- ((item.StyleNo<0) or
- (dli.Offs+CharEnds.Items[CaretOffs].Offset-1>ItemLength(dli.ItemNo))
- )
- end;
- {------------------------------------------------------------------------------}
- function TRVEditRVData.CaretInTheLastLine: Boolean;
- begin
- Result := CharEnds.Items[CharEnds.Count-1].DrawItemNo = DrawItems.Count-1;
- end;
- {------------------------------------------------------------------------------}
- function TRVEditRVData.CaretAtTheBeginningOfLine: Boolean;
- begin
- Result := CaretOffs=0;
- end;
- {------------------------------------------------------------------------------}
- function TRVEditRVData.CaretAtTheEndOfLine: Boolean;
- begin
- Result := CaretOffs=CharEnds.Count-1;
- end;
- {------------------------------------------------------------------------------}
- {$IFNDEF RVDONOTUSELISTS}
- procedure TRVEditRVData.ApplyListStyle_(AListNo, AListLevel, AStartFrom: Integer;
- AUseStartFrom, ARecursive: Boolean; Operation: TRVParaListOperation;
- var ItemsAdded, StartNo, EndNo, SelStartNo, SelEndNo: Integer;
- ListNos: TRVIntegerList; var LastVWMarkerIndex: Integer);
- var i: Integer;
- FR: Boolean;
- OldMarker, Marker: TRVMarkerItemInfo;
- OldListNo, OldLevel, OldStartFrom: Integer;
- OldUseStartFrom: Boolean;
- OldMarkerCp: TRVCPInfo;
- OldMarkerTag: Integer;
- OldMarkerDeleteProtect: Boolean;
- s: String;
- Markers: TRVMarkerList;
- {$IFNDEF RVDONOTUSELIVESPELL}
- FirstAffectedItemNo: Integer;
- {$ENDIF}
- begin
- ExpandToPara(StartNo, EndNo, StartNo, EndNo);
- ItemsAdded := 0;
- OldListNo := -1;
- OldLevel := -1;
- OldStartFrom := -1;
- OldUseStartFrom := False;
- Markers := GetMarkers(False);
- LastVWMarkerIndex := -1;
- OldMarkerCp := nil;
- OldMarkerTag := 0;
- OldMarkerDeleteProtect := False;
- {$IFNDEF RVDONOTUSELIVESPELL}
- FirstAffectedItemNo := -1;
- {$ENDIF}
- for i := EndNo downto StartNo do
- if IsParaStart(i) and not GetItem(i).GetBoolValue(rvbpFullWidth) then begin
- OldMarker := nil;
- if GetItemStyle(i)=rvsListMarker then begin
- OldListNo := TRVMarkerItemInfo(GetItem(i)).ListNo;
- if (OldListNo>=0) and (GetRVStyle.ListStyles[OldListNo].HasVariableWidth) then begin
- ListNos.AddUnique(OldListNo);
- LastVWMarkerIndex := TRVMarkerItemInfo(GetItem(i)).GetIndexInList(Markers);
- end;
- if (Operation in [rvplopLevel,rvplopChange]) then begin
- OldMarker := TRVMarkerItemInfo(GetItem(i));
- OldListNo := OldMarker.ListNo;
- OldLevel := OldMarker.Level;
- OldStartFrom := OldMarker.StartFrom;
- OldUseStartFrom := OldMarker.Reset;
- if OldMarker.Checkpoint<>nil then
- OldMarkerCp :=
- OldMarker.Checkpoint.CreateCopy(rvoTagsArePChars in Options)
- else
- OldMarkerCp := nil;
- OldMarkerTag := RV_CopyTag(OldMarker.Tag, rvoTagsArePChars in Options);
- OldMarkerDeleteProtect := OldMarker.DeleteProtect;
- end;
- if (Operation=rvplopRemove) and (i+1<Items.Count) then
- Do_NewLine(i+1, False, -1, FR);
- Do_DeleteItem(i, FR);
- {$IFNDEF RVDONOTUSELIVESPELL}
- FirstAffectedItemNo := i;
- {$ENDIF}
- dec(ItemsAdded);
- if SelStartNo>=i then
- dec(SelStartNo);
- if SelEndNo>=i then
- dec(SelEndNo);
- dec(EndNo);
- end;
- if (Operation<>rvplopRemove) then begin
- s := '';
- if (Operation = rvplopLevel) and (OldMarker<>nil) then begin
- Marker := TRVMarkerItemInfo.CreateEx(Self, OldListNo,
- OldLevel+AListLevel, OldStartFrom, OldUseStartFrom);
- if Marker.Level>=GetRVStyle.ListStyles[Marker.ListNo].Levels.Count then
- Marker.Level := GetRVStyle.ListStyles[Marker.ListNo].Levels.Count-1;
- if Marker.Level<0 then
- Marker.Level := 0;
- end
- else if Operation=rvplopChange then begin
- if AListLevel<0 then begin
- if OldMarker=nil then
- OldLevel := 0
- end
- else
- OldLevel := AListLevel;
- Marker := TRVMarkerItemInfo.CreateEx(Self, AListNo, OldLevel, AStartFrom, AUseStartFrom and (i=StartNo));
- end
- else
- Marker := nil;
- if Marker<>nil then begin
- if OldMarker<>nil then begin
- Marker.Checkpoint := OldMarkerCP;
- Marker.Tag := OldMarkerTag;
- Marker.DeleteProtect := OldMarkerDeleteProtect;
- end;
- Marker.ParaNo := GetItemPara(i);
- if SelStartNo>=i then
- inc(SelStartNo);
- if SelEndNo>=i then
- inc(SelEndNo);
- inc(EndNo);
- Do_InsertItem(i, s, marker, False, FR);
- {$IFNDEF RVDONOTUSELIVESPELL}
- FirstAffectedItemNo := i;
- {$ENDIF}
- Do_NewLine(i+1, True, Marker.ParaNo, FR);
- inc(ItemsAdded);
- end;
- end;
- end;
- {$IFNDEF RVDONOTUSELIVESPELL}
- if (FirstAffectedItemNo>=0) and (FirstAffectedItemNo<ItemCount) then
- LaterSetBackLiveSpellingTo(FirstAffectedItemNo, 0, False);
- {$ENDIF}
- end;
- {------------------------------------------------------------------------------}
- procedure TRVEditRVData.ApplyListStyle(AListNo, AListLevel, AStartFrom: Integer;
- AUseStartFrom, ARecursive: Boolean;
- Operation: TRVParaListOperation);
- var StartNo, EndNo, StartOffs, EndOffs: Integer;
- OldWidth, NewWidth, ItemsAdded: Integer;
- DIStartNo, DIEndNo: Integer;
- SL, EL, SO, EO: Integer;
- LastVWMarkerIndex: Integer;
- ListNos: TRVIntegerList;
- begin
- LastVWMarkerIndex := -1;
- ListNos := TRVIntegerList.Create;
- try
- BeginUndoSequence(rvutList, True);
- SetUndoGroupMode(True);
- try
- GetSelectionBoundsEx(StartNo, StartOffs, EndNo, EndOffs, True);
- GetSelectionBoundsEx(SL, SO, EL, EO, False);
- Item2FirstDrawItem(StartNo,DIStartNo);
- Item2FirstDrawItem(EndNo,DIEndNo);
- GetParaBounds(DIStartNo, DIEndNo,DIStartNo, DIEndNo);
- ExpandToPara(StartNo, EndNo, StartNo, EndNo);
- OldWidth := CalculateParaSectionsMinWidthDef(StartNo, EndNo);
- ApplyListStyle_(AListNo, AListLevel, AStartFrom,
- AUseStartFrom, ARecursive, Operation, ItemsAdded,StartNo, EndNo, SL, EL, ListNos, LastVWMarkerIndex);
- NewWidth := CalculateParaSectionsMinWidthDef(StartNo, EndNo);
- try
- Include(State, rvstInvalidSelection);
- Reformat_((OldWidth<>NewWidth) and ((NewWidth>DocumentWidth) or (OldWidth>=DocumentWidth)),
- DIStartNo, DIEndNo, ItemsAdded);
- finally
- Exclude(State, rvstInvalidSelection);
- end;
- Item2DrawItem(SL,SO, FSelStartNo, FSelStartOffs);
- Item2DrawItem(EL,EO, FSelEndNo, FSelEndOffs);
- CaretDrawItemNo := FSelEndNo;
- OnChangeCaretLine(FSelEndOffs-2);
- ChangeCaret(False, True, False, False);
- finally
- SetUndoGroupMode(False);
- Change;
- end;
- UpdateAfterMarkers(EndNo, LastVWMarkerIndex, ListNos, -1);
- finally
- ListNos.Free;
- end;
- GetParentControl.Invalidate;
- end;
- {------------------------------------------------------------------------------}
- procedure TRVEditRVData.UpdateAfterMarkers(FirstItemNo,
- LastMarkerIndex: Integer; ListNos: TRVIntegerList; ListNo: Integer);
- var ListNosCreated: Boolean;
- LastMarkerItemNo, StartNo, EndNo, Dummy: Integer;
- Markers : TRVMarkerList;
- begin
- if (ListNos=nil) and (ListNo<0) then
- exit;
- Markers := GetMarkers(False);
- if Markers=nil then
- exit;
- ListNosCreated := ListNos=nil;
- if ListNosCreated then
- ListNos := TRVIntegerList.CreateEx(1, ListNo);
- if (ListNos.Count>0) then begin
- LastMarkerIndex := FindLastMarkerIndex(LastMarkerIndex, ListNos);
- if LastMarkerIndex>=0 then begin
- LastMarkerItemNo := FindMarkerLocalLocationFrom(FirstItemNo+1, TRVMarkerItemInfo(Markers[LastMarkerIndex]));
- if LastMarkerItemNo>=0 then begin
- ExpandToPara(FirstItemNo+1, LastMarkerItemNo, StartNo, EndNo);
- Item2FirstDrawItem(StartNo, StartNo);
- Item2DrawItem(EndNo, GetOffsAfterItem(EndNo), EndNo, Dummy);
- Do_ReformateRange(StartNo, EndNo, False);
- FormatParasExact(StartNo, EndNo, 0, True);
- end
- else begin
- (GetAbsoluteRootData as TRichViewRVData).Format_(True, True, True, 0, nil,
- False, True, False);
- Do_ReformateRange(-1, -1, True);
- end;
- end;
- end;
- if ListNosCreated then
- ListNos.Free;
- end;
- {------------------------------------------------------------------------------}
- procedure TRVEditRVData.PrepareForUpdateRangeAfterMarkers(StartNo,
- EndNo: Integer; ForDeletion: Boolean;
- var FirstItemNo, LastMarkerIndex: Integer;
- var ListNos: TRVIntegerList);
- var i, ListNo: Integer;
- Style: TRVStyle;
- Markers : TRVMarkerList;
- begin
- ListNos := nil;
- Markers := GetMarkers(False);
- if Markers=nil then
- exit;
- if StartNo<0 then
- exit;
- AdjustInItemsRange(StartNo);
- AdjustInItemsRange(EndNo);
- ExpandToPara(StartNo, EndNo, StartNo, EndNo);
- ListNos := TRVIntegerList.Create;
- LastMarkerIndex := -1;
- Style := GetRVStyle;
- for i := StartNo to EndNo do
- if (GetItemStyle(i)=rvsListMarker) then begin
- ListNo := TRVMarkerItemInfo(GetItem(i)).ListNo;
- if (ListNo>=0) and Style.ListStyles[ListNo].HasVariableWidth then begin
- ListNos.AddUnique(ListNo);
- if not ForDeletion or (LastMarkerIndex<0) then
- LastMarkerIndex := TRVMarkerItemInfo(GetItem(i)).GetIndexInList(Markers);
- end;
- end;
- if ForDeletion and (LastMarkerIndex>=0) then
- dec(LastMarkerIndex);
- FirstItemNo := EndNo;
- end;
- {------------------------------------------------------------------------------}
- procedure TRVEditRVData.UpdateRangeAfterMarkers(StartNo, EndNo: Integer);
- var ListNos: TRVIntegerList;
- LastMarkerIndex, FirstItemNo: Integer;
- begin
- PrepareForUpdateRangeAfterMarkers(StartNo, EndNo, False, FirstItemNo, LastMarkerIndex, ListNos);
- if (ListNos<>nil) and (ListNos.Count>0) then
- UpdateAfterMarkers(FirstItemNo, LastMarkerIndex, ListNos, -1);
- ListNos.Free;
- end;
- {$ENDIF}
- {------------------------------------------------------------------------------}
- procedure TRVEditRVData.PostPaintTo(Canvas: TCanvas; XShift, YShift,
- FirstDrawItemNo, LastDrawItemNo: Integer);
- begin
- if FResizer<>nil then
- FResizer.Draw(Canvas, XShift, YShift);
- end;
- {------------------------------------------------------------------------------}
- function TRVEditRVData.GetResizeHandleAt(X, Y: Integer;
- var Index: TRVResizeHandleIndex): Boolean;
- begin
- Result := (FResizer<>nil) and FResizer.GetResizeHandleAt(X, Y, GetHOffs, GetVOffs, Index);
- end;
- {------------------------------------------------------------------------------}
- procedure TRVEditRVData.MouseMove(Shift: TShiftState; X, Y: Integer);
- var Index: TRVResizeHandleIndex;
- begin
- if (FResizer<>nil) and FResizer.Dragging then begin
- XorDrawing;
- FResizer.DragTo(Shift, X,Y, GetHOffs, GetVOffs);
- XorDrawingEx(X,Y);
- end
- else if GetResizeHandleAt(X, Y, Index) then begin
- SetCursor(FResizer.GetResizeHandleCursor(Index));
- end
- else
- inherited;
- end;
- {------------------------------------------------------------------------------}
- procedure TRVEditRVData.MouseDown(Button: TMouseButton; Shift: TShiftState;
- X, Y: Integer);
- begin
- if (FResizer<>nil) and FResizer.MouseDown(X,Y, GetHOffs, GetVOffs) then begin
- XorDrawing;
- SetCursor(crCross);
- Windows.SetCursor(Screen.Cursors[crCross]);
- end
- else
- inherited;
- end;
- {------------------------------------------------------------------------------}
- procedure TRVEditRVData.MouseUp(Button: TMouseButton; Shift: TShiftState;
- X, Y: Integer);
- var Dragging: Boolean;
- begin
- if (FResizer<>nil) and (FResizer.Dragging or FResizer.DragCancelled) then begin
- Dragging := FResizer.Dragging;
- if Dragging then
- ClearXorDrawing;
- FResizer.MouseUp(X,Y, GetHOffs, GetVOffs);
- if Dragging then begin
- SetCursor(GetNormalCursor);
- ResizeItem(FResizer.ItemNo, FResizer.Width, FResizer.Height);
- end;
- end
- else
- inherited;
- end;
- {------------------------------------------------------------------------------}
- procedure TRVEditRVData.XorDrawing;
- begin
- if (FResizer<>nil) and (FResizer.Dragging) then begin
- FResizer.XorDrawing(GetCanvas, GetHOffs, GetVOffs);
- XorImageDrawn := not XorImageDrawn;
- end
- else
- inherited;
- end;
- {------------------------------------------------------------------------------}
- function TRVEditRVData.CancelResize: Boolean;
- begin
- Result := (FResizer<>nil) and FResizer.Dragging;
- if Result then begin
- ClearXorDrawing;
- FResizer.CancelDrag;
- SetCursor(GetNormalCursor);
- Windows.SetCursor(Screen.Cursors[GetNormalCursor]);
- end;
- end;
- {------------------------------------------------------------------------------}
- procedure TRVEditRVData.AdjustMouseUpSelection;
- begin
- if (FClickedDrawItemNo=LastDIMovedAbove) and (FClickedDrawItemNo>=0) and
- (GetItem(DrawItems[FClickedDrawItemNo].ItemNo).GetBoolValue(rvbpResizable) or
- GetItem(DrawItems[FClickedDrawItemNo].ItemNo).GetBoolValue(rvbpClickSelect)) and
- not SelectionExists(False, False) then begin
- FSelStartNo := FClickedDrawItemNo;
- FSelEndNo := FClickedDrawItemNo;
- FSelStartOffs := 0;
- FSelEndOffs := 1;
- end;
- end;
- {------------------------------------------------------------------------------}
- procedure TRVEditRVData.ResizeItem(ItemNo, Width, Height: Integer);
- var item: TCustomRVItemInfo;
- edit: TCustomRichViewEdit;
- Data: Integer;
- begin
- item := GetItem(ItemNo);
- if item is TRVRectItemInfo then begin
- dec(Width, TRVRectItemInfo(item).Spacing*2);
- dec(Height, TRVRectItemInfo(item).Spacing*2);
- end;
- if Width<1 then
- Width := 1;
- if Height<1 then
- Height := 1;
- edit := TCustomRichViewEdit(RichView);
- if not edit.BeforeChange(False) then
- exit;
- BeginUndoSequence(rvutModifyItem, True);
- SetUndoGroupMode(True);
- try
- if item is TRVControlItemInfo then begin
- Do_Resize(ItemNo, Width, Height, True);
- end
- else begin
- BeginItemModify(ItemNo, Data);
- if item is TRVRectItemInfo then begin
- edit.SetItemExtraIntPropertyEd(ItemNo, rvepImageHeight, Height, False);
- edit.SetItemExtraIntPropertyEd(ItemNo, rvepImageWidth, Width, False);
- end;
- EndItemModify(ItemNo, Data);
- end;
- finally
- SetUndoGroupMode(False);
- end;
- Change;
- end;
- {------------------------------------------------------------------------------}
- function TRVEditRVData.GetActualCurStyleNo: Integer;
- begin
- Result := GetActualStyle2(FCurTextStyleNo, FCurParaStyleNo);
- end;
- {------------------------------------------------------------------------------}
- { Returns True if the ItemNo-th item has a checkpoint with "Persistent" flag }
- function TRVEditRVData.ItemHasPersistentCheckpoint(ItemNo: Integer): Boolean;
- begin
- Result := (GetItem(ItemNo).Checkpoint<>nil) and
- GetItem(ItemNo).Checkpoint.Persistent;
- end;
- {------------------------------------------------------------------------------}
- { Returns True if the paragraph containing the ItemNo-th item has a checkpoint
- with "Persistent" flag }
- function TRVEditRVData.ParaHasPersistentCheckpoint(ItemNo: Integer): Boolean;
- var i: Integer;
- begin
- Result := False;
- i := ItemNo;
- while i>=0 do begin
- Result := ItemHasPersistentCheckpoint(i);
- if Result then
- exit;
- if IsParaStart(i) then
- break;
- dec(i);
- end;
- i := ItemNo+1;
- while i<ItemCount do begin
- if IsParaStart(i) then
- break;
- Result := ItemHasPersistentCheckpoint(i);
- if Result then
- exit;
- inc(i);
- end;
- end;
- {------------------------------------------------------------------------------}
- { Moves "persistent" checkpoint from the ItemNo-th item to the adjacent item
- in the same paragraph. If possible (and not OnlyToPrev), to the next item.
- If not, to the previous one. If moving is impossible, returns False.
- If the ItemNo-th item does not have "persistent" checkpoint, returns True. }
- function TRVEditRVData.MovePersistentCheckpoint(ItemNo: Integer;
- OnlyToPrev: Boolean): Boolean;
- begin
- Result := True;
- if not ItemHasPersistentCheckpoint(ItemNo) then
- exit;
- if not OnlyToPrev and (ItemNo+1<ItemCount) and not IsParaStart(ItemNo+1) and
- not ItemHasPersistentCheckpoint(ItemNo+1) then
- Do_MoveCP(ItemNo, ItemNo+1)
- else if (ItemNo-1>=0) and not IsParaStart(ItemNo) and
- not ItemHasPersistentCheckpoint(ItemNo-1) then
- Do_MoveCP(ItemNo, ItemNo-1)
- else
- Result := False;
- end;
- {------------------------------------------------------------------------------}
- { Assigns 0 to FCurTag field. Frees memory. }
- procedure TRVEditRVData.ClearCurTag;
- begin
- if rvoTagsArePChars in Options then
- StrDispose(PChar(FCurTag));
- FCurTag := 0;
- end;
- {------------------------------------------------------------------------------}
- { Assigns new value to FCurTag field.
- If a text item is selected, and its style is a current text style,
- assigns a copy of tag of this item.
- Otherwise, assigns 0. }
- procedure TRVEditRVData.AssignCurTag;
- var ItemNo: Integer;
- begin
- ClearCurTag;
- //ItemNo := GetOneSelectedItemNo;
- ItemNo := GetCurItemNo;
- if (ItemNo>=0) and (GetItemStyle(ItemNo)=FCurTextStyleNo) then
- FCurTag := RV_CopyTag(GetItemTag(ItemNo), rvoTagsArePChars in Options);
- end;
- {------------------------------------------------------------------------------}
- { If only one item is completely selected, returns its index.
- Otherwise, returns -1. }
- function TRVEditRVData.GetOneSelectedItemNo: Integer;
- var itemno1, itemno2, itemoffs1, itemoffs2: Integer;
- begin
- Result := -1;
- if (FSelStartNo<0) or (FSelEndNo<0) then
- exit;
- GetSelectionBoundsEx(itemno1, itemoffs1, itemno2, itemoffs2, True);
- if itemoffs1>=GetOffsAfterItem(itemno1) then begin
- inc(itemno1);
- if itemno1>=Items.Count then
- exit;
- itemoffs1 := GetOffsBeforeItem(itemno1);
- end;
- if itemoffs2<=GetOffsBeforeItem(itemno2) then begin
- dec(itemno2);
- if itemno2<0 then
- exit;
- itemoffs2 := GetOffsAfterItem(itemno2);
- end;
- if (itemno1=itemno2) and (itemoffs1<=GetOffsBeforeItem(itemno1)) and
- (itemoffs2>=GetOffsAfterItem(itemno2)) then
- Result := itemno1;
- end;
- {------------------------------------------------------------------------------}
- {$IFNDEF RVDONOTUSEDRAGDROP}
- {------------------------------------------------------------------------------}
- { Drag&Drop: IDropTarget related }
- {------------------------------------------------------------------------------}
- { Returns information about drag&drop caret location.
- It is used by this RVData and all its children RVDatas (including inplace
- editors) }
- function TRVEditRVData.GetDragDropCaretInfo: TRVDragDropCaretInfo;
- begin
- if rvflRoot in Flags then
- Result := FDragDropCaretInfo
- else
- Result := TCustomRVFormattedData(GetAbsoluteRootData).GetDragDropCaretInfo;
- end;
- {------------------------------------------------------------------------------}
- { Creates FDragDropCaretInfo (if not created) and increase reference count.
- Only for root editors. }
- procedure TRVEditRVData.CreateDragDropCaretInfo;
- begin
- if rvflRoot in Flags then begin
- if FDragDropCaretInfo=nil then
- FDragDropCaretInfo := TRVDragDropCaretInfo.Create;
- inc(FDragDropCaretInfo.RefCount);
- end;
- end;
- {------------------------------------------------------------------------------}
- { Decrease reference count. If zero, frees FDragDropCaretInfo.
- Only for root editors. }
- procedure TRVEditRVData.ReleaseDragDropCaretInfo;
- begin
- if rvflRoot in Flags then
- if FDragDropCaretInfo<>nil then begin
- dec(FDragDropCaretInfo.RefCount);
- if FDragDropCaretInfo.RefCount=0 then begin
- FDragDropCaretInfo.Free;
- FDragDropCaretInfo := nil;
- end;
- end;
- end;
- {------------------------------------------------------------------------------}
- { Drag&Drop: IDropSource related }
- {------------------------------------------------------------------------------}
- { Initializing dragging. Overrides in TRichViewRVData.InitDragging.
- Returns True on success.
- Returns DropSource and OKEffect for call of DoDragDrop. }
- function TRVEditRVData.InitDragging(var DropSource: TRVDropSource;
- var OKEffect: Integer): Boolean;
- begin
- Result := inherited InitDragging(DropSource, OKEffect);
- if Result and (rvflRoot in Flags) and
- not TCustomRichViewEdit(FRichView).ReadOnly and CanDelete then
- OKEffect := OKEffect or DROPEFFECT_MOVE;
- end;
- {------------------------------------------------------------------------------}
- procedure TRVEditRVData.DoneDragging(FDeleteSelection: Boolean);
- begin
- inherited DoneDragging(FDeleteSelection);
- if FDeleteSelection then
- TCustomRichViewEdit(RichView).DeleteSelection;
- end;
- {$ENDIF}
- {------------------------------------------------------------------------------}
- procedure TRVEditRVData.DoCurrentTextStyleConversion(var StyleNo: Integer;
- ParaStyleNo, ItemNo, UserData: Integer; ToWholeParagraphs: Boolean);
- var rve: TCustomRichViewEdit;
- NewStyleNo: Integer;
- begin
- rve := TCustomRichViewEdit(RichView);
- if not Assigned(rve.FCurStyleConversion) then
- exit;
- rve.FCurStyleConversion(rve, StyleNo, ParaStyleNo, UserData, True, NewStyleNo,
- ToWholeParagraphs);
- Do_AssociatedTextStyleNo(ItemNo, NewStyleNo);
- end;
- {------------------------------------------------------------------------------}
- {$IFNDEF RVDONOTUSELIVESPELL}
- procedure TRVEditRVData.LaterSetBackLiveSpellingTo(ItemNo, Offs: Integer;
- ClearPainters: Boolean);
- begin
- if ClearPainters then
- GetItem(ItemNo).ClearWordPainters(Offs-1);
- TCustomRichView(RichView).LaterSetBackLiveSpellingTo(GetSourceRVData, ItemNo, Offs);
- end;
- procedure TRVEditRVData.LiveSpellingCheckCurrentItem;
- var rve: TCustomRichViewEdit;
- begin
- rve := TCustomRichViewEdit(RichView);
- rve.LiveSpellingCheckCurrentItem(rve.TopLevelEditor.RVData.GetSourceRVData,
- rve.TopLevelEditor.CurItemNo);
- end;
- {$ENDIF}
- end.