CRVFData.pas
上传用户:daoqigc
上传日期:2021-04-20
资源大小:2795k
文件大小:263k
- DocumentWidth := max(
- GetWidth-(sad.LeftMargin+sad.RightMargin),
- CalculateMinDocWidthPlus(@sad, Canvas)
- );
- DevMinTextWidth := MulDiv(GetMinTextWidth, sad.ppixDevice, sad.ppixScreen);
- DevMaxTextWidth := MulDiv(GetMaxTextWidth, sad.ppixDevice, sad.ppixScreen);
- if DocumentWidth<DevMinTextWidth then DocumentWidth := DevMinTextWidth;
- if rvoClientTextWidth in Options then begin { widths of pictures and maxtextwidth are ignored }
- TextWidth := GetWidth-(sad.LeftMargin+sad.RightMargin);
- if TextWidth<DevMinTextWidth then TextWidth := DevMinTextWidth;
- end
- else begin
- if (DocumentWidth > DevMaxTextWidth{-(sad.LeftMargin+sad.RightMargin)}) and (GetMaxTextWidth>0) then
- TextWidth := DevMaxTextWidth//-(sad.LeftMargin+sad.RightMargin)
- else
- TextWidth := DocumentWidth;
- end;
- if not (OnlyResized and (TextWidth=OldTextWidth) and (DocumentWidth=OldDocumentWidth)) or ForceFormat then begin
- if OnlyTail then begin
- StartLine := LastItemFormatted+1;
- Params.baseline := DocumentHeight-GetBottomMargin;
- if LastItemFormatted>=0 then
- dec(Params.baseline,
- RV_XToDevice(GetRVStyle.ParaStyles[GetItemPara(LastItemFormatted)].SpaceAfter, sad));
- end
- else begin
- StartLine := 0;
- Params.baseline := GetTopMargin;
- ClearTemporal;
- end;
- Params.x:=0;
- Params.prevdesc :=0;
- Params.LastDrawItem := DrawItems.Count;
- Params.DontFSL := True;
- Params.LineWidth := -1;
- Params.FirstIndent := 0;
- RVStyle := GetRVStyle;
- CreateFontInfoCache(Canvas);
- Params.FontInfoCache := GetFontInfoCache(Canvas, Self);
- Params.FormatCanvas := Canvas;
- Params.FormatCanvasHandle := Canvas.Handle;
- for i:=StartLine to Items.Count-1 do
- with TCustomRVItemInfo(Items.Objects[i]) do begin
- if not SameAsPrev and not BR then
- Params.FirstParaItemNo := i;
- if StyleNo>=0 then
- if RVStyle.ParaStyles[ParaNo].Alignment = rvaJustify then
- FormatWords(i, Canvas, sad, Params)
- else
- FormatLine(
- RV_ReturnProcessedString(Items[i],
- RVStyle.TextStyles[GetActualStyleNo(RVStyle)], False,
- rvoShowSpecialCharacters in Options, False),
- Items[i], 0,
- {$IFNDEF RVDONOTUSEUNICODE}
- RVU_Length(Items[i], ItemOptions),
- {$ELSE}
- Length(Items[i]),
- {$ENDIF}
- i, Canvas, sad, Params)
- else
- FormatLine('', '', 0, Length(Items[i]), i, Canvas, sad, Params)
- end;
- UpdateLastTab(Params);
- FinishScreenLine(sad, Params.LineWidth+Params.FirstIndent, Params.LastDrawItem,
- not (rvstLastParaAborted in State), ExtraSpaceBelowLine, Params.DontFSL,
- Params.FormatCanvas);
- DestroyFontInfoCache(Params.FontInfoCache);
- DocumentHeight := Params.baseline+Params.prevdesc+GetBottomMargin+ExtraSpaceBelowLine;
- if Items.Count>0 then
- inc(DocumentHeight,
- MulDiv(GetRVStyle.ParaStyles[GetItemPara(Items.Count-1)].SpaceAfter,
- sad.ppiyDevice, sad.ppiyScreen));
- AdjustVScrollUnits;
- AdjustJumpsCoords;
- end
- else;
- // AdjustChildrenCoords;
- cw := GetWidth;
- ch := GetHeight;
- AlreadyFormatted := True;
- SetDocumentAreaSize(DocumentWidth+GetLeftMargin+GetRightMargin, DocumentHeight, True);
- AlreadyFormatted := False;
- if (cw<>GetWidth) or (ch<>GetHeight) then begin
- //EndFormatting;
- //ScrollTo(OldY);
- EndFormatting;
- Format_(OnlyResized, ForceFormat, False, depth+1, Canvas, False,
- NoCaching, Reformatting);
- StartFormatting;
- end;
- if (depth=0) then begin
- if OnlyResized and not NoScroll then begin
- FV := FindDrawItemByItem(FV);
- if FV<>-1 then
- ScrollTo(DrawItems[FV].Top+DeltaFV,False)
- else
- ScrollTo(0,False);
- end;
- AdjustChildrenCoords;
- if OnlyTail then begin
- if rvoScrollToEnd in Options then
- ScrollTo(DocumentHeight,False)
- else
- ScrollTo(FV,False);
- // AdjustChildrenCoords;
- end;
- if OnlyResized then
- RestoreSelBounds(StartNo, EndNo, StartOffs, EndOffs);
- end;
- finally
- if (depth=0) then begin
- EndFormatting;
- LastItemFormatted := Items.Count-1;
- Formatted(0,Items.Count-1, False); // <- wrong for FormatTail
- end;
- end;
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRVFormattedData.GetSelBounds(var StartNo, EndNo,
- StartOffs, EndOffs: Integer; Normalize: Boolean);
- begin
- if not Normalize or (FSelStartNo <= FSelEndNo) then begin
- StartNo := FSelStartNo;
- EndNo := FSelEndNo;
- if not Normalize or not ((StartNo=EndNo) and (FSelStartOffs>FSelEndOffs)) then begin
- StartOffs := FSelStartOffs;
- EndOffs := FSelEndOffs;
- end
- else begin
- StartOffs := FSelEndOffs;
- EndOffs := FSelStartOffs;
- end;
- end
- else begin
- StartNo := FSelEndNo;
- EndNo := FSelStartNo;
- StartOffs := FSelEndOffs;
- EndOffs := FSelStartOffs;
- end;
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRVFormattedData.GetScreenLineBounds(DrawItemNo: Integer;
- var First, Last: Integer);
- begin
- First := DrawItemNo;
- while (First>0) and not DrawItems[First].FromNewLine do
- dec(First);
- Last := DrawItemNo+1;
- while (Last<DrawItems.Count) and not DrawItems[Last].FromNewLine do
- inc(Last);
- dec(Last);
- end;
- {------------------------------------------------------------------------------}
- var SortDrawItems: TRVDrawLines;
- function CompareCoords(Item1, Item2: Pointer): Integer;
- begin
- Result := SortDrawItems[Integer(Item1)].Left-SortDrawItems[Integer(Item2)].Left;
- end;
- procedure TCustomRVFormattedData.FindDrawItemForSel(X,Y: Integer;
- var No, Offs: Integer;
- Strict: Boolean);
- var
- styleno,i, a,b,mid, midtop, midbottom, midleft, midright, beginline, endline,
- min, minsign, cur: Integer;
- firstinline,lastinline, delta: Integer;
- dli: TRVDrawLineInfo;
- arr: PRVIntegerArray;
- Canvas: TCanvas;
- s: String;
- BiDiMode:TRVBiDiMode;
- order, revorder: TRVIntegerList;
- begin
- Canvas := GetCanvas;
- No := -1;
- Offs := -1;
- if DrawItems.Count = 0 then
- exit;
- dli := DrawItems[0];
- if (dli.Top+dli.Height>Y) then
- mid := 0
- else begin
- a := 1;
- b := DrawItems.Count-1;
- while (b-a)>1 do begin
- mid := (a+b) div 2;
- if (DrawItems[mid].Top<=Y) then
- a := mid
- else
- b := mid;
- end;
- mid := a;
- if DrawItems[b].Top<=Y then mid := b;
- end;
- GetScreenLineBounds(mid, beginline, endline);
- if endline<>DrawItems.Count-1 then begin
- // may be the next line is better?
- b := endline+2;
- while b<DrawItems.Count do begin
- if DrawItems[b].FromNewLine then break;
- inc(b);
- end;
- dec(b);
- a := mid;
- for i := endline+1 to b do
- if DrawItems[i].Top<=Y then begin
- a := i;
- break;
- end;
- if a<>mid then begin
- beginline := endline+1;
- endline := b;
- end;
- end;
- // calculating line bounds (in pixels)
- midtop := DrawItems[mid].Top;
- midbottom := midtop + DrawItems[mid].Height;
- midleft := DrawItems[mid].Left;
- midright := midleft+DrawItems[mid].Width;
- for i:= beginline to endline do begin
- dli := DrawItems[i];
- if dli.Top < midtop then midtop := dli.Top;
- if dli.Top + dli.Height > midbottom then midbottom := dli.Top + dli.Height;
- if dli.Left < midleft then midleft := dli.Left;
- if dli.Left + dli.Width > midright then midright := dli.Left + dli.Width;
- end;
- BiDiMode := GetParaBiDiMode(GetItemPara(DrawItems[beginline].ItemNo));
- if BiDiMode<>rvbdUnspecified then begin
- order := TRVIntegerList.Create;
- for i:= beginline to endline do
- order.Add(i);
- SortDrawItems := DrawItems;
- TList(order).Sort(CompareCoords);
- SortDrawItems := nil;
- revorder := TRVIntegerList.CreateEx(endline-beginline+1,0);
- for i:= beginline to endline do
- revorder[order[i-beginline]-beginline] := i;
- end
- else begin
- order := nil;
- revorder := nil;
- end;
- if BiDiMode=rvbdRightToLeft then begin
- firstinline := endline;
- lastinline := beginline;
- delta := -1;
- end
- else begin
- firstinline := beginline;
- lastinline := endline;
- delta := +1;
- end;
- for i:= beginline to endline do begin
- dli := DrawItems[i];
- if (
- (Strict and (dli.Left<=X) and (dli.Left+dli.Width>X) and (Y>=dli.Top) and (Y<=dli.Top+dli.Height))
- or
- (not Strict and (order=nil) and
- (
- ((dli.Left<=X) and ((i=lastinline) or (DrawItems[i+delta].Left>X)))
- or
- ((i=firstinline) and (X<dli.Left))
- )
- )
- or
- (not Strict and (order<>nil) and
- (
- ((dli.Left<=X) and ((revorder[i-beginline]=endline) or (DrawItems[order[revorder[i-beginline]-beginline+1]].Left>X)))
- or
- ((revorder[i-beginline]=beginline) and (X<dli.Left))
- )
- )
- )
- then begin
- styleno := GetItemStyle(dli.ItemNo);
- No := i;
- Offs := 0;
- if styleno>=0 then begin
- GetRVStyle.ApplyStyle(Canvas, StyleNo, GetParaBiDiMode(GetItemPara(dli.ItemNo)), True);
- s := DrawItems.GetString(i,Items);
- s := RV_ReturnProcessedString(s, GetRVStyle.TextStyles[StyleNo],
- IsDrawItemLastOnWrappedLine(i), rvoShowSpecialCharacters in Options, False);
- if Length(s)>0 then begin
- GetMem(arr, (dli.Length+2)*sizeof(Integer));
- try
- if (GetItemBiDiMode(dli.ItemNo)<>rvbdUnspecified) and
- RVU_GetTextCaretPos(Canvas, s, arr, GetItemOptions(dli.ItemNo),
- dli.Width{$IFNDEF RVDONOTUSEJUSTIFY}-dli.SpaceBefore{$ENDIF}) then begin
- min := Abs(X-arr[0]-dli.Left{$IFNDEF RVDONOTUSEJUSTIFY}-dli.SpaceBefore{$ENDIF});
- offs := 0;
- for a := 0 to dli.Length do
- if Abs(X-arr[a]-dli.Left{$IFNDEF RVDONOTUSEJUSTIFY}-dli.SpaceBefore{$ENDIF})<min then begin
- Offs := a;
- min := Abs(X-arr[a]-dli.Left{$IFNDEF RVDONOTUSEJUSTIFY}-dli.SpaceBefore{$ENDIF});
- end;
- if (Offs<Length(s)) and (Offs>0)and (NextCharStr(s, dli.ItemNo, Offs)>Offs+1) then
- Offs := NextCharStr(s, dli.ItemNo, Offs)-1;
- end
- else begin
- RVU_GetTextExtentExPoint(Canvas, s,
- dli.Width*10, b, arr,
- TCustomRVItemInfo(Items.Objects[dli.ItemNo]).ItemOptions);
- minsign := X-dli.Left;
- min := Abs(minsign);
- offs := 0;
- for a := 1 to b do begin
- cur := X-arr[a-1]-dli.Left{$IFNDEF RVDONOTUSEJUSTIFY}-dli.SpaceBefore{$ENDIF};
- if (abs(cur)<min) or
- ((abs(cur)=min) and
- (((cur<0) and (BiDiMode=rvbdRightToLeft)) or
- ((cur>=0) and (BiDiMode<>rvbdRightToLeft)))) then begin
- Offs := a;
- minsign := cur;
- min := Abs(minsign);
- end;
- end;
- if (Offs<Length(s)) and (Offs>0)and (NextCharStr(s, dli.ItemNo, Offs)>Offs+1) then
- Offs := NextCharStr(s, dli.ItemNo, Offs)-1;
- end;
- inc(Offs);
- if Offs>DrawItems[i].Length+1 then
- Offs := DrawItems[i].Length+1;
- if (Offs < 1) and (DrawItems[i].Length>0) then
- Offs := 1;
- finally
- FreeMem(arr);
- end;
- end
- else begin
- Offs := 1;
- end;
- end
- else begin
- Offs := (1-delta) div 2;
- if X > dli.Left + dli.Width div 2 then begin
- {State := State + [rvstClickedBeyondItem];}
- Offs := (1+delta) div 2;
- end;
- end;
- end;
- end;
- order.Free;
- revorder.Free;
- {$IFNDEF RVDONOTUSELISTS}
- if (No>=0) and not Strict then begin
- if GetDrawItemStyle(No)=rvsListMarker then begin
- inc(No);
- Offs := GetOffsBeforeDrawItem(No);
- end;
- end;
- {$ENDIF}
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRVFormattedData.RestoreSelBounds(StartNo, EndNo,
- StartOffs, EndOffs: Integer);
- begin
- Item2DrawItem(StartNo, StartOffs, {->} FSelStartNo, FSelStartOffs);
- Item2DrawItem(EndNo, EndOffs, {->} FSelEndNo, FSelEndOffs);
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRVFormattedData.StoreSelBounds(var StartNo, EndNo,
- StartOffs, EndOffs: Integer; Normalize: Boolean);
- var SelStartNo, SelEndNo, SelStartOffs, SelEndOffs: Integer;
- begin
- GetSelBounds(SelStartNo, SelEndNo, SelStartOffs, SelEndOffs, Normalize);
- DrawItem2Item(SelStartNo,SelStartOffs, {->} StartNo,StartOffs);
- DrawItem2Item(SelEndNo, SelEndOffs, {->} EndNo, EndOffs);
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRVFormattedData.DrawItem2Item(DrawItemNo, DrawItemOffs: Integer;
- var ItemNo, ItemOffs: Integer);
- var dli: TRVDrawLineInfo;
- begin
- ItemNo := -1;
- if DrawItemNo = -1 then exit;
- dli := DrawItems[DrawItemNo];
- if GetItemStyle(dli.ItemNo)>=0 then
- ItemOffs := DrawItemOffs + dli.Offs-1
- else
- ItemOffs := DrawItemOffs;
- ItemNo := dli.ItemNo;
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRVFormattedData.Item2DrawItem(ItemNo, ItemOffs: Integer;
- var DrawItemNo, DrawItemOffs: Integer);
- var item: TCustomRVItemInfo;
- i: Integer;
- begin
- DrawItemNo := -1;
- if ItemNo = -1 then
- exit;
- item := TCustomRVItemInfo(Items.Objects[ItemNo]);
- DrawItemNo := item.DrawItemNo;
- if item.StyleNo<0 then begin
- DrawItemOffs := ItemOffs-DrawItems[DrawItemNo].Offs;
- exit;
- end;
- DrawItemOffs := ItemOffs-DrawItems[DrawItemNo].Offs+1;
- for i := DrawItemNo+1 to DrawItems.Count-1 do begin
- if (DrawItems[i].ItemNo<>ItemNo) or
- ((DrawItems[i].Offs>=ItemOffs) and not (DrawItems[i-1].Offs+DrawItems[i-1].Length<ItemOffs)) then begin
- DrawItemNo := i-1;
- DrawItemOffs := ItemOffs-DrawItems[DrawItemNo].Offs+1;
- if (GetDrawItemStyle(DrawItemNo)>=0) and
- (DrawItemOffs>DrawItems[DrawItemNo].Length+DrawItems[DrawItemNo].Offs) then begin
- DrawItemNo := i;
- // changed: Jun 29 2004
- if DrawItems[DrawItemNo].Offs<=GetOffsBeforeDrawItem(DrawItemNo) then begin
- DrawItemNo := i;
- DrawItemOffs := DrawItems[DrawItemNo].Offs;
- end
- else begin
- DrawItemNo := i-1;
- DrawItemOffs := GetOffsAfterDrawItem(DrawItemNo);
- end;
- end;
- break;
- end;
- if i=DrawItems.Count-1 then begin
- DrawItemNo := i;
- DrawItemOffs := ItemOffs-DrawItems[DrawItemNo].Offs+1;
- end;
- end;
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRVFormattedData.Item2FirstDrawItem(ItemNo: Integer;
- var DrawItemNo: Integer);
- begin
- DrawItemNo := -1;
- if ItemNo = -1 then
- exit;
- DrawItemNo := TCustomRVItemInfo(Items.Objects[ItemNo]).DrawItemNo;
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRVFormattedData.Item2LastDrawItem(ItemNo: Integer; var DrawItemNo: Integer);
- begin
- DrawItemNo := -1;
- if ItemNo = -1 then
- exit;
- Item2DrawItem(ItemNo, GetOffsAfterItem(ItemNo), DrawItemNo, ItemNo);
- end;
- {------------------------------------------------------------------------------}
- function TCustomRVFormattedData.GetDrawItemNo(BoundLine, Option: Integer): Integer;
- var
- a,b,mid: Integer;
- begin
- if DrawItems.Count = 0 then begin
- Result := 0;
- exit;
- end;
- if DrawItems[0].Top>=BoundLine then begin
- Result := 0;
- exit;
- end;
- if (Option=gdinLastVisible) and (DrawItems[DrawItems.Count-1].Top<BoundLine) then begin
- Result := DrawItems.Count-1;
- exit;
- end;
- a := 1;
- b := DrawItems.Count-1;
- mid := a;
- if Option = gdinLastCompleteVisible then begin
- {
- while (b-a)>1 do begin
- mid := (a+b) div 2;
- if (TRVDrawLineInfo(DrawItems.Objects[mid]).Top+TRVDrawLineInfo(DrawItems.Objects[mid]).Height>BoundLine) then
- b := mid
- else
- a := mid;
- end;
- if mid>= DrawItems.Count then mid := DrawItems.Count-1;
- while (mid>0) and (TRVDrawLineInfo(DrawItems.Objects[mid]).Top+TRVDrawLineInfo(DrawItems.Objects[mid]).Height>BoundLine) do dec(mid);
- if (mid>0) then dec(mid);
- while (mid>0) and not TRVDrawLineInfo(DrawItems.Objects[mid]).FromNewLine do dec(mid);
- if (mid>0) then dec(mid);
- end
- }
- end
- else begin
- while (b-a)>1 do begin
- mid := (a+b) div 2;
- if (DrawItems[mid].Top>=BoundLine) then begin
- if (DrawItems[mid-1].Top<BoundLine) then break;
- b := mid;
- end
- else
- a := mid;
- end;
- if mid>= DrawItems.Count then mid := DrawItems.Count-1;
- if Option = gdinFirstVisible then begin
- while (mid>0) and not DrawItems[mid].FromNewLine do dec(mid);
- if (mid>0) then dec(mid);
- while (mid>0) and not DrawItems[mid].FromNewLine do dec(mid);
- if (mid>0) then dec(mid);
- end
- else
- while DrawItems[mid].Top<BoundLine do inc(mid);
- end;
- Result := mid;
- end;
- {------------------------------------------------------------------------------}
- // Calculating minimal possible width for paragraph sections containing
- // items in the given range.
- // This is a maximum of min widths of all paragraph sections
- // Works both for normal and no-wrap paragraphs
- function TCustomRVFormattedData.CalculateParaSectionsMinWidth(StartItemNo,
- EndItemNo: Integer; var FirstParaItemNo: Integer; sad: PRVScreenAndDevice;
- Canvas: TCanvas): Integer;
- var i,w: Integer;
- begin
- ExpandToParaSection(StartItemNo, EndItemNo, StartItemNo, EndItemNo);
- Result := 0;
- for i := StartItemNo to EndItemNo do begin
- if IsParaStart(i) then
- FirstParaItemNo := i;
- if IsFromNewLine(i) then begin
- w := CalculateParaSectionMinWidth(i, FirstParaItemNo, sad, Canvas);
- if w>Result then
- Result := w;
- end;
- end;
- end;
- {------------------------------------------------------------------------------}
- function TCustomRVFormattedData.CalculateParaSectionsMinWidthDef(StartItemNo,
- EndItemNo: Integer): Integer;
- var FirstParaItemNo: Integer;
- begin
- FirstParaItemNo := -1;
- Result := CalculateParaSectionsMinWidth(StartItemNo, EndItemNo, FirstParaItemNo, nil, nil);
- end;
- {------------------------------------------------------------------------------}
- // Calculating total indents for the paragraph section
- function TCustomRVFormattedData.CalculatePureParaSectionWidth(ItemNo: Integer;
- var FirstParaItemNo: Integer; sad: PRVScreenAndDevice; Canvas: TCanvas): Integer;
- begin
- ItemNo := GetFirstParaSectionItem(ItemNo);
- Result := GetMaxIndent(ItemNo, FirstParaItemNo);
- if (sad<>nil) then
- Result := MulDiv(Result, sad.ppixDevice, sad.ppixScreen);
- end;
- {------------------------------------------------------------------------------}
- // Calculates minimal possible width for paragraph section containing
- // StartItemNo-th item.
- // Works both for normal paragraphs (calls CalculateMinItemsWidthPlus)
- // and for no-wrap paragraphs (calculates sum of widths of all items)
- function TCustomRVFormattedData.CalculateParaSectionMinWidth(StartItemNo: Integer;
- var FirstParaItemNo: Integer; sad: PRVScreenAndDevice;
- Canvas: TCanvas): Integer;
- var i, EndItemNo: Integer;
- item: TCustomRVItemInfo;
- RVStyle: TRVStyle;
- {$IFNDEF RVDONOTUSEUNICODE}
- sz: TSize;
- {$ENDIF}
- begin
- item := GetItem(StartItemNo);
- if Canvas=nil then
- Canvas := GetCanvas;
- ExpandToParaSection(StartItemNo, StartItemNo, StartItemNo, EndItemNo);
- if not (rvpaoNoWrap in GetRVStyle.ParaStyles[item.ParaNo].Options) then begin
- Result := CalculateMinItemsWidthPlus(StartItemNo, EndItemNo, FirstParaItemNo, sad, Canvas);
- exit;
- end;
- RVStyle := GetRVStyle;
- Result := CalculatePureParaSectionWidth(StartItemNo, FirstParaItemNo, sad, Canvas);
- for i := StartItemNo to EndItemNo do begin
- item := GetItem(i);
- if item.StyleNo>=0 then
- with RVStyle.TextStyles[GetActualStyle(item)] do begin
- Apply(Canvas, GetParaBiDiMode(item.ParaNo), rvflCanUseCustomPPI in Flags);
- {$IFNDEF RVDONOTUSEUNICODE}
- if Unicode then begin
- RVU_GetTextExtentPoint32W(Canvas, Pointer(Items[i]), Length(Items[i]) div 2, sz);
- inc(Result, sz.cx);
- end
- else
- {$ENDIF}
- inc(Result, Canvas.TextWidth(Items[i]));
- end
- else
- inc(Result, item.GetMinWidth(sad, Canvas,Self));
- end;
- end;
- {------------------------------------------------------------------------------}
- function TCustomRVFormattedData.CalculateParaSectionMinWidthDef(StartItemNo: Integer): Integer;
- var FirstParaItemNo: Integer;
- begin
- FirstParaItemNo := -1;
- Result := CalculateParaSectionMinWidth(StartItemNo, FirstParaItemNo,nil,nil);
- end;
- {------------------------------------------------------------------------------}
- // Calculates a minimal possible width for the given range of items in
- // normal (i.e. wrappable) paragraphs
- // This is a maximum of individual widths of items in this range.
- function TCustomRVFormattedData.CalculateMinItemsWidthPlus(StartItemNo, EndItemNo: Integer;
- var FirstParaItemNo: Integer; sad: PRVScreenAndDevice;
- Canvas: TCanvas): Integer;
- var i,w, pspw: Integer;
- begin
- Result := 0;
- if StartItemNo>EndItemNo then
- exit;
- pspw := CalculatePureParaSectionWidth(StartItemNo, FirstParaItemNo, sad, Canvas);
- for i := StartItemNo to EndItemNo do begin
- if IsParaStart(i) then
- FirstParaItemNo := i;
- if IsFromNewLine(i) and (i<>StartItemNo) then
- pspw := CalculatePureParaSectionWidth(i, FirstParaItemNo, sad, Canvas);
- w := pspw+CalculateMinItemWidthPlus_WithoutPSWidth(i, sad, Canvas);
- if w>Result then
- Result := w;
- end;
- end;
- {------------------------------------------------------------------------------}
- // Calculates a minimal possible width for the given item in
- // normal (i.e. wrappable) paragraphs
- // If this is an item preceded by a marker, this function returns
- // a sum of min widths of this item and marker.
- function TCustomRVFormattedData.CalculateMinItemWidthPlus_WithoutPSWidth(ItemNo: Integer;
- sad: PRVScreenAndDevice;
- Canvas: TCanvas): Integer;
- var item: TCustomRVItemInfo;
- begin
- item := GetItem(ItemNo);
- Result := item.GetMinWidth(sad, Canvas, Self);
- {$IFNDEF RVDONOTUSELISTS}
- if item.SameAsPrev and (ItemNo>0) then begin
- item := GetItem(ItemNo-1);
- if item.StyleNo=rvsListMarker then
- inc(Result, item.GetMinWidth(sad, Canvas, Self));
- end;
- {$ENDIF}
- end;
- {------------------------------------------------------------------------------}
- // Calculates a minimal possible width for the paragraph section containing
- // the given item (both for wrappable and no-wrap paragraphs)
- function TCustomRVFormattedData.CalculateMinItemWidthPlusEx(ItemNo: Integer): Integer;
- var FirstParaItemNo: Integer;
- begin
- FirstParaItemNo := -1;
- Result := CalculateParaSectionMinWidth(ItemNo, FirstParaItemNo, nil, GetCanvas);
- end;
- {------------------------------------------------------------------------------}
- // Calculates a minimal possible width for the given range of items
- // (both for wrappable and no-wrap paragraphs)
- function TCustomRVFormattedData.CalculateMinItemsWidthPlusEx(StartItemNo,
- EndItemNo: Integer): Integer;
- var item: TCustomRVItemInfo;
- dummy, sno, eno,w: Integer;
- FirstParaItemNo: Integer;
- begin
- if StartItemNo>EndItemNo then begin
- Result := 0;
- exit;
- end;
- FirstParaItemNo := -1;
- item := GetItem(StartItemNo);
- ExpandToParaSection(StartItemNo, StartItemNo, dummy,eno);
- if rvpaoNoWrap in GetRVStyle.ParaStyles[item.ParaNo].Options then
- Result := CalculateParaSectionMinWidthDef(StartItemNo)
- else begin
- if eno>EndItemNo then
- eno := EndItemNo;
- Result := CalculateMinItemsWidthPlus(StartItemNo, eno, FirstParaItemNo, nil, GetCanvas);
- end;
- if eno>=EndItemNo then
- exit;
- ExpandToParaSection(EndItemNo, EndItemNo, sno, dummy);
- item := GetItem(EndItemNo);
- if rvpaoNoWrap in GetRVStyle.ParaStyles[item.ParaNo].Options then
- w := CalculateParaSectionMinWidth(EndItemNo, FirstParaItemNo, nil,GetCanvas)
- else begin
- if sno<StartItemNo then
- eno := StartItemNo;
- w := CalculateMinItemsWidthPlus(sno, EndItemNo, FirstParaItemNo, nil,GetCanvas);
- end;
- if w>Result then
- Result := w;
- if sno<=eno then
- exit;
- w := CalculateParaSectionsMinWidth(eno, sno, FirstParaItemNo, nil,nil);
- if w>Result then
- Result := w;
- end;
- {------------------------------------------------------------------------------}
- // Calculates the minimal possible width for the whole document
- function TCustomRVFormattedData.CalculateMinDocWidthPlus(sad: PRVScreenAndDevice;
- Canvas: TCanvas): Integer;
- var FirstParaItemNo: Integer;
- begin
- if (sad<>nil) and (sad.ppixScreen=sad.ppixDevice) and
- (sad.ppiyScreen=sad.ppiyDevice) then
- sad := nil;
- FirstParaItemNo := 0;
- Result := CalculateParaSectionsMinWidth(0, Items.Count-1, FirstParaItemNo, sad, Canvas);
- end;
- {------------------------------------------------------------------------------}
- function TCustomRVFormattedData.CalculateMinWidthAfterInsert(
- item: TCustomRVItemInfo; InsertItemNo: Integer): Integer;
- begin
- Result := item.GetMinWidth(nil,nil,Self);
- if rvpaoNoWrap in GetRVStyle.ParaStyles[GetItemPara(InsertItemNo)].Options then
- inc(Result,CalculateParaSectionMinWidthDef(InsertItemNo));
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRVFormattedData.AdjustJumpsCoords;
- var i,x,y: Integer;
- jumpinfo: TRVJumpInfo;
- begin
- for i:= 0 to Jumps.Count-1 do begin
- jumpinfo := TRVJumpInfo(Jumps[i]);
- jumpinfo.RVData.GetOrigin(x,y);
- dec(y, GetRVDataExtraVOffs);
- jumpinfo.l := x+jumpinfo.RVData.DrawItems[jumpinfo.DrawItemNo].Left;
- jumpinfo.t := y+jumpinfo.RVData.DrawItems[jumpinfo.DrawItemNo].Top;
- end;
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRVFormattedData.AdjustChildrenCoords;
- var i: Integer;
- ditem: TRVDrawLineInfo;
- item : TCustomRVItemInfo;
- begin
- if (rvflShareContents in Flags) or (GetParentControl.ControlCount=0) or
- (rvstDoNotMoveChildren in State) then exit;
- for i:=0 to DrawItems.Count-1 do begin
- ditem := DrawItems[i];
- item := GetItem(ditem.ItemNo);
- if item.StyleNo<0 then begin
- TRVNonTextItemInfo(item).AdjustInserted(ditem.Left-GetZHOffs, ditem.Top-GetZVOffs, True);
- end;
- end;
- {$IFNDEF RVDONOTUSESMARTPOPUP}
- TCustomRVFormattedData(GetAbsoluteRootData).AdjustSpecialControlsCoords(Self);
- {$ENDIF}
- end;
- {------------------------------------------------------------------------------}
- function TCustomRVFormattedData.FindDrawItemByItem(ItemNo: Integer): Integer;
- var i: Integer;
- begin
- Result := -1;
- if ItemNo = -1 then exit;
- for i :=0 to DrawItems.Count-1 do
- if DrawItems[i].ItemNo = ItemNo then begin
- Result := i;
- exit;
- end;
- //Assert(Result<>-1, 'Can''t FindDrawLineByLine');
- end;
- {------------------------------------------------------------------------------}
- function TCustomRVFormattedData.FindDrawItemAtPos(X,Y: Integer): Integer;
- var
- i, a,b,mid, midtop: Integer;
- dli: TRVDrawLineInfo;
- begin
- if DrawItems.Count = 0 then begin
- Result := -1;
- exit;
- end;
- dli := DrawItems[0];
- if (dli.Top<=Y) and (dli.Top+dli.Height>Y) and
- (dli.Left<=X) and (dli.Left+dli.Width>X) then begin
- Result := 0;
- exit;
- end;
- if DrawItems.Count = 1 then begin
- Result := -1;
- exit;
- end;
- a := 1;
- b := DrawItems.Count-1;
- while (b-a)>1 do begin
- mid := (a+b) div 2;
- if (DrawItems[mid].Top<=Y) then
- a := mid
- else
- b := mid;
- end;
- mid := a;
- midtop := DrawItems[mid].Top;
- while (mid>=1) and
- (DrawItems[mid-1].Top+
- DrawItems[mid-1].Height>midtop) do dec(mid);
- for i:=1 to 2 do begin
- if mid = DrawItems.Count then break;
- midtop := DrawItems[mid].Top+
- DrawItems[mid].Height-1;
- while (mid<DrawItems.Count) do begin
- dli := DrawItems[mid];
- if (dli.Top>midtop) then break;
- if (dli.Top<=Y) and (dli.Top+dli.Height>Y) and
- (dli.Left<=X) and (dli.Left+dli.Width>X) then begin
- Result := mid;
- exit;
- end;
- inc(mid);
- end;
- end;
- Result := -1;
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRVFormattedData.InvalidateDrawItem(DrawItemNo, Spacing: Integer);
- var R: TRect;
- //X, Y: Integer;
- begin
- //GetOrigin(X, Y);
- ResetSubCoords;
- with DrawItems[DrawItemNo] do
- R := Bounds(Left, Top, Width, Height);
- InflateRect(R, Spacing, Spacing);
- OffsetRect(R, {X}-GetHOffs, {Y}-GetVOffs);
- //if (R.Bottom>0) and (R.Top<TCustomRVFormattedData(GetRootData).GetHeight) then
- InvalidateRect(R);
- end;
- {------------------------------------------------------------------------------}
- function TCustomRVFormattedData.GetFirstVisible(TopLine: Integer): Integer;
- begin
- Result := GetDrawItemNo(TopLine,gdinFirstVisible);
- end;
- {------------------------------------------------------------------------------}
- function TCustomRVFormattedData.GetFirstItemVisible: Integer;
- var v: Integer;
- begin
- v := GetDrawItemNo(GetVOffs, gdinFirstVisible);
- if v>=DrawItems.Count then
- v := DrawItems.Count-1;
- if v<0 then
- Result := -1
- else
- Result := DrawItems[v].ItemNo;
- end;
- {------------------------------------------------------------------------------}
- function TCustomRVFormattedData.GetLastItemVisible: Integer;
- var v: Integer;
- begin
- v := GetDrawItemNo(GetVOffs+GetHeight, gdinLastVisible);
- if v>=DrawItems.Count then
- v := DrawItems.Count-1;
- if v<0 then
- Result := -1
- else
- Result := DrawItems[v].ItemNo;
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRVFormattedData.DrawBackground(Canvas: TCanvas; r: TRect);
- var X, Y: Integer;
- begin
- GetOrigin(X, Y);
- GetBackground.Draw(Canvas, r, GetHOffs+X, GetVOffs+Y, 0, 0, GetWidth, GetHeight,
- GetColor, False);
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRVFormattedData.PaintTo(Canvas: TCanvas; AClipRect: TRect);
- var i,no, yshift, xshift, fullwidth, selwidth, ditemselstart, ditemselend: Integer;
- dli:TRVDrawLineInfo;
- li: TCustomRVItemInfo;
- HoverNow, res: Boolean;
- s : String;
- StartNo, EndNo, StartOffs, EndOffs: Integer;
- LastDrawnStyle: Integer;
- RVStyle: TRVStyle;
- BiDiMode: TRVBiDiMode;
- DefaultTextDrawState: TRVTextDrawStates;
- DefaultDrawState: TRVItemDrawStates;
- FirstDLine, LastDLine: Integer;
- LineTopY, LineBottomY: Integer;
- ShowSpecialCharacters: Boolean;
- {.......................................................}
- function GetSelDrawState: TRVTextDrawStates;
- begin
- Result := [rvtsSelected];
- if HoverNow then
- Include(Result, rvtsHover);
- end;
- {.......................................................}
- procedure DrawText(X,Y,W, Offs, DItemNo: Integer; const s: String;
- IsStart, IsEnd, Selected, SBAdded: Boolean);
- // in : dli, Canvas, xshift, yshift, hovernow, no
- {$IFNDEF RVDONOTUSEJUSTIFY}
- var SpaceBefore: Integer;
- {$ENDIF}
- var DrawState: TRVTextDrawStates;
- s2: String;
- begin
- {
- if s='' then begin
- Canvas.Pen.Color := clBlue;
- Canvas.Pen.Style := psSolid;
- Canvas.Ellipse(x-10-xshift,y-10-yshift,x+10-xshift,y+10-yshift);
- end;
- }
- DrawState := DefaultTextDrawState;
- if Selected then Include(DrawState, rvtsSelected);
- if HoverNow then
- Include(DrawState, rvtsHover);
- if Assigned(RVStyle.OnDrawStyleText) then begin
- if IsStart then begin
- Include(DrawState, rvtsDrawItemStart);
- if dli.Offs=1 then
- Include(DrawState, rvtsItemStart);
- end;
- if IsEnd then begin
- Include(DrawState, rvtsDrawItemEnd);
- if dli.Offs+dli.Length-1=ItemLength(dli.ItemNo) then
- Include(DrawState, rvtsItemEnd);
- end;
- end;
- RVStyle.ApplyStyleColor(Canvas, No, DrawState, False, rvcmColor);
- {$IFNDEF RVDONOTUSEJUSTIFY}
- if IsStart then begin
- SpaceBefore := dli.SpaceBefore;
- if not SBAdded then
- inc(W,SpaceBefore);
- end
- else begin
- SpaceBefore := 0;
- inc(X, dli.SpaceBefore);
- if SBAdded then
- dec(W,dli.SpaceBefore);
- end;
- {$ENDIF}
- s2 := s;
- if ShowSpecialCharacters then begin
- Include(DrawState, rvtsSpecialCharacters);
- if RichViewShowGhostSpaces and IsEnd and
- IsSpaceBetweenDrawItems(DItemNo) and
- (not Selected or
- (rvstCompletelySelected in State) or
- not (DItemNo=EndNo)) then begin
- {$IFNDEF RVDONOTUSEUNICODE}
- if rvioUnicode in li.ItemOptions then
- s2 := s2+' '#0
- else
- {$ENDIF}
- s2 := s2+' ';
- end;
- end;
- if Selected and (RVStyle.SelectionStyle=rvssLines) and (W>0) then
- Canvas.FillRect(Rect(X-xshift-1, LineTopY-yshift, X-xshift+W+1, LineBottomY-yshift));
- RVStyle.DrawStyleText(s2, Canvas, dli.ItemNo, Offs+dli.Offs-1, No, Self,
- {$IFNDEF RVDONOTUSEJUSTIFY}SpaceBefore,{$ELSE}0,{$ENDIF}
- X-xshift, Y-yshift, W, dli.Height, DrawState, False, False,
- rvcmColor, BiDiMode);
- end;
- {.......................................................}
- function GetLineTopY(DrawItemNo: Integer): Integer;
- var i: Integer;
- begin
- Result := DrawItems[DrawItemNo].Top;
- for i := DrawItemNo downto 0 do begin
- if DrawItems[i].Top<Result then
- Result := DrawItems[i].Top;
- if DrawItems[i].FromNewLine then
- break;
- end;
- for i := DrawItemNo+1 to DrawItems.Count-1 do begin
- if DrawItems[i].FromNewLine then
- break;
- if DrawItems[i].Top<Result then
- Result := DrawItems[i].Top;
- end;
- end;
- {.......................................................}
- procedure DrawSoftPageBreaks;
- var FirstPB, i,DItemNo, Offs, Y: Integer;
- dli: TRVDrawLineInfo;
- PBInfo: TRVSoftPageBreakInfo;
- begin
- FirstPB := -1;
- dli := DrawItems[FirstDLine];
- for i := 0 to FSoftPageBreaks.Count-1 do
- if TRVSoftPageBreakInfo(FSoftPageBreaks.Items[i]).ItemNo>=dli.ItemNo then begin
- FirstPB := i;
- break;
- end;
- if FirstPB<0 then
- exit;
- for i := FirstPB to FSoftPageBreaks.Count-1 do begin
- PBInfo := TRVSoftPageBreakInfo(FSoftPageBreaks.Items[i]);
- Item2DrawItem(PBInfo.ItemNo, PBInfo.Offset, DItemNo, Offs);
- if DItemNo>LastDLine then
- exit;
- if (DItemNo=0) and (PBInfo.ExtraData<0) then
- continue;
- if PBInfo.ExtraData>=0 then
- Y := DrawItems[DItemNo].Top+GetItem(PBInfo.ItemNo).GetSoftPageBreakDY(PBInfo.ExtraData)
- else
- Y := GetLineTopY(DItemNo);
- RVStyle.DrawPageBreak(Canvas, Y-yshift-1, xshift, rvpbSoftPageBreak, GetParentControl);
- end;
- end;
- {.......................................................}
- procedure GetLineVerticalBounds(FirstDrawItemNo: Integer;
- var LineTopY, LineBottomY: Integer);
- var i, LastDrawItemNo: Integer;
- ditem: TRVDrawLineInfo;
- begin
- ditem := DrawItems[FirstDrawItemNo];
- LineTopY := ditem.Top;
- LineBottomY := LineTopY+ditem.Height+ditem.ExtraSpaceBelow;
- if (FirstDrawItemNo+1>=DrawItems.Count) or
- DrawItems[FirstDrawItemNo+1].FromNewLine then
- LastDrawItemNo := FirstDrawItemNo
- else begin
- LastDrawItemNo := DrawItems.Count-1;
- for i := FirstDrawItemNo+1 to DrawItems.Count-1 do begin
- ditem := DrawItems[i];
- if ditem.FromNewLine then begin
- LastDrawItemNo := i-1;
- break;
- end;
- if LineTopY>ditem.Top then
- LineTopY := ditem.Top;
- if LineBottomY<ditem.Top+ditem.Height+ditem.ExtraSpaceBelow then
- LineBottomY := ditem.Top+ditem.Height+ditem.ExtraSpaceBelow;
- end;
- end;
- if IsDrawItemParaStart(FirstDrawItemNo) then
- dec(LineTopY, RVStyle.ParaStyles[GetItemPara(
- DrawItems[FirstDrawItemNo].ItemNo)].SpaceBefore);
- if IsDrawItemParaEnd(LastDrawItemNo) then
- inc(LineBottomY, RVStyle.ParaStyles[GetItemPara(
- DrawItems[FirstDrawItemNo].ItemNo)].SpaceAfter);
- end;
- {.......................................................}
- function UseLineSelection(ditem: TRVDrawLineInfo): Boolean;
- begin
- Result := (FSelStartNo>=0) and (RVStyle.SelectionStyle=rvssLines) and
- (GetItemBiDiMode(ditem.ItemNo)=rvbdUnspecified);
- end;
- {.......................................................}
- procedure DrawParaMarkAfter(DrawItemNo: Integer);
- var BiDiMode: TRVBiDiMode;
- Left: Integer;
- s: String;
- sz: TSize;
- ditem: TRVDrawLineInfo;
- begin
- if (DrawItemNo+1<DrawItems.Count) and
- ((DrawItems[DrawItemNo].ItemNo=DrawItems[DrawItemNo+1].ItemNo) or
- not IsFromNewLine(DrawItems[DrawItemNo+1].ItemNo)) then
- exit;
- ditem := DrawItems[DrawItemNo];
- if LastDrawnStyle<0 then
- LastDrawnStyle := 0;
- BiDiMode := GetParaBiDiMode(GetItemPara(ditem.ItemNo));
- RVStyle.ApplyStyle(Canvas, LastDrawnStyle, BiDiMode, True);
- RVStyle.ApplyStyleColor(Canvas, LastDrawnStyle, [], False, rvcmColor);
- if {$IFDEF RICHVIEWCBDEF3}(Canvas.Font.Charset=SYMBOL_CHARSET) or{$ENDIF}
- (AnsiCompareText(Canvas.Font.Name, RVFONT_SYMBOL)=0) or
- (AnsiCompareText(Canvas.Font.Name, RVFONT_WINGDINGS)=0) then begin
- LastDrawnStyle := -1;
- Canvas.Font.Name := 'Arial';
- {$IFDEF RICHVIEWCBDEF3}
- Canvas.Font.CHARSET := DEFAULT_CHARSET;
- {$ENDIF}
- end;
- if (DrawItemNo+1=DrawItems.Count) or IsParaStart(DrawItems[DrawItemNo+1].ItemNo) then
- s := #$B6
- else begin
- {$IFDEF RICHVIEWCBDEF3}
- Canvas.Font.Charset := SYMBOL_CHARSET;
- {$ENDIF}
- Canvas.Font.Name := RVFONT_SYMBOL;
- s := #$BF;
- {
- Canvas.Font.Name := RVFONT_WINGDINGS;
- s := #$C3;
- }
- LastDrawnStyle := -1;
- end;
- GetTextExtentPoint32(Canvas.Handle, PChar(s), 1, sz);
- if BiDiMode<>rvbdRightToLeft then
- Left := ditem.Left+ditem.Width
- else
- Left := ditem.Left-sz.cx;
- Canvas.TextOut(Left-xshift, ditem.Top+ditem.Height-yshift-sz.cy, s);
- end;
- {.......................................................}
- {$IFNDEF RVDONOTUSELIVESPELL}
- procedure GetSubItemRect(DItemNo, StartOffs, EndOffs: Integer;
- ditem: TRVDrawLineInfo; var r: TRect);
- var s: String;
- res: Boolean;
- begin
- dec(StartOffs, ditem.Offs-1);
- if StartOffs<1 then
- StartOffs := 1;
- dec(EndOffs, ditem.Offs-1);
- if EndOffs>ditem.Length then
- EndOffs := ditem.Length;
- s := DrawItems.GetString(DItemNo,Items);
- if BiDiMode<>rvbdUnspecified then begin
- s := RV_ReturnProcessedString(s, RVStyle.TextStyles[No],
- (StartOffs>=GetOffsAfterDrawItem(DItemNo)) and IsDrawItemLastOnWrappedLine(DItemNo),
- rvoShowSpecialCharacters in Options, True);
- res := RVU_GetTextRangeCoords(Canvas, s, StartOffs, EndOffs-StartOffs+1,
- GetItemOptions(ditem.ItemNo), ditem.Width, r.Left, r.Right);
- end
- else
- res := False;
- if not res then begin
- if StartOffs>1 then begin
- s := DrawItems.GetSubString(DItemNo, Items, 1, StartOffs-1);
- s := RV_ReturnProcessedString(s, RVStyle.TextStyles[No], False,
- rvoShowSpecialCharacters in Options, True);
- r.Left := RVU_TextWidth(s, Canvas, GetItemOptions(ditem.ItemNo));
- end
- else
- r.Left := 0;
- s := DrawItems.GetSubString(DItemNo, Items, StartOffs, EndOffs-StartOffs+1);
- s := RV_ReturnProcessedString(s, RVStyle.TextStyles[No],
- (EndOffs+1>=GetOffsAfterDrawItem(DItemNo)) and IsDrawItemLastOnWrappedLine(DItemNo),
- rvoShowSpecialCharacters in Options, True);
- r.Right := r.Left+ RVU_TextWidth(s, Canvas, GetItemOptions(ditem.ItemNo));
- end;
- r.Top := 0;
- r.Bottom := ditem.Height;
- {$IFNDEF RVDONOTUSEJUSTIFY}
- OffsetRect(r, ditem.SpaceBefore, 0);
- {$ENDIF}
- end;
- procedure DrawWordPainters;
- var i,j, Offs1, Offs2: Integer;
- List: TRVWordPainterList;
- ditem: TRVDrawLineInfo;
- r: TRect;
- begin
- for i := FirstDLine to LastDLine do
- if GetItem(DrawItems[i].ItemNo).WordPaintList<>nil then begin
- ditem := DrawItems[i];
- No := GetActualStyle(GetItem(ditem.ItemNo));
- if No<>LastDrawnStyle then begin
- LastDrawnStyle := No;
- RVStyle.ApplyStyle(Canvas, No, GetParaBiDiMode(GetItemPara(ditem.ItemNo)), True);
- end;
- BiDiMode := GetParaBiDiMode(GetItemPara(ditem.ItemNo));
- List := GetItem(ditem.ItemNo).WordPaintList;
- for j := 0 to List.Count-1 do begin
- Offs1 := List[j].StartOffs;
- Offs2 := Offs1+List[j].Length;
- if (ditem.Offs>Offs2) or (ditem.Offs+ditem.Length<Offs1) then
- continue;
- GetSubItemRect(i, Offs1, Offs2-1, ditem, r);
- OffsetRect(r, ditem.Left-xshift, ditem.Top-yshift);
- List[j].Draw(Canvas, ditem, Self, r, j);
- end;
- end;
- end;
- {$ENDIF}
- {.......................................................}
- var
- AParaNo, MaxTextWidth: Integer;
- BelowBottom: Boolean;
- BRect, BRect1: TRect;
- DrawState: TRVItemDrawStates;
- TextDrawState: TRVTextDrawStates;
- ShiftedClipRect: TRect;
- begin
- RVStyle := GetRVStyle;
- GetSelBounds(StartNo, EndNo, StartOffs, EndOffs, True);
- ShiftedClipRect := AClipRect;
- yshift := GetZVOffs;
- xshift := GetZHOffs;
- OffsetRect(ShiftedClipRect,xshift,yshift);
- inc(yshift, AClipRect.Top);
- inc(xshift, AClipRect.Left);
- OffsetRect(AClipRect,-AClipRect.Left,-AClipRect.Top);
- Canvas.Brush.Style := bsClear;
- LastDrawnStyle := -1;
- BiDiMode := rvbdUnspecified;
- DefaultTextDrawState := [];
- DefaultDrawState := [];
- ShowSpecialCharacters := rvoShowSpecialCharacters in GetOptions;
- if TRVScroller(GetParentControl).FocusedEx then begin
- Include(DefaultTextDrawState, rvtsControlFocused);
- Include(DefaultDrawState, rvidsControlFocused);
- end;
- {
- if GetMaxTextWidth<>0 then begin
- Canvas.Pen.Color := clBtnFace;
- Canvas.MoveTo(GetLeftMargin+GetMaxTextWidth-xshift, AClipRect.Top);
- Canvas.LineTo(GetLeftMargin+GetMaxTextWidth-xshift, AClipRect.Bottom);
- end;
- }
- // drawing paragraph backgrounds and frames...
- FirstDLine := GetFirstVisible(ShiftedClipRect.Top);
- LastDLine := DrawItems.Count-1;
- BelowBottom := False;
- i := FirstDLine;
- while (i>0) and
- ((DrawItems[i].ItemNo=DrawItems[i-1].ItemNo) or
- not GetItem(DrawItems[i].ItemNo).CanBeBorderStart) do
- dec(i);
- MaxTextWidth := GetMaxTextWidth;
- while i<DrawItems.Count do begin
- dli := DrawItems[i];
- if BelowBottom and dli.FromNewLine then begin
- if LastDLine>i then
- LastDLine := i;
- break;
- end;
- if GetItem(dli.ItemNo).CanBeBorderStart and
- (GetItem(dli.ItemNo).StyleNo<>rvsBreak) and
- (
- (RVStyle.ParaStyles[GetItemPara(dli.ItemNo)].Border.Style<>rvbNone) or
- (RVStyle.ParaStyles[GetItemPara(dli.ItemNo)].Background.Color<>clNone) or
- Assigned(RVStyle.OnDrawParaBack)
- ) then begin
- AParaNo := GetItemPara(dli.ItemNo);
- with RVStyle.ParaStyles[AParaNo] do begin
- BRect.Left := GetLeftMargin+LeftIndent;
- if FirstIndent<0 then
- inc(BRect.Left, FirstIndent);
- if rvoClientTextWidth in Self.Options then
- BRect.Right := GetWidth-(GetRightMargin+RightIndent)
- else if MaxTextWidth>0 then
- BRect.Right := GetLeftMargin+MaxTextWidth-RightIndent
- else
- BRect.Right := GetAreaWidth-(GetRightMargin+RightIndent);
- if dli.Left+dli.Width>BRect.Right then
- BRect.Right := dli.Left+dli.Width;
- end;
- BRect.Top := dli.Top;
- BRect.Bottom := dli.Top+dli.Height+dli.ExtraSpaceBelow;
- inc(i);
- while (i<DrawItems.Count) and
- ((DrawItems[i].ItemNo=DrawItems[i-1].ItemNo) or
- not GetItem(DrawItems[i].ItemNo).CanBeBorderStart) do begin
- dli := DrawItems[i];
- if dli.Top<BRect.Top then
- BRect.Top := dli.Top;
- if dli.Top+dli.Height+dli.ExtraSpaceBelow>BRect.Bottom then
- BRect.Bottom := dli.Top+dli.Height+dli.ExtraSpaceBelow;
- if dli.Left+dli.Width>BRect.Right then
- BRect.Right := dli.Left+dli.Width;
- if BelowBottom and dli.FromNewLine and (LastDLine>i) then
- LastDLine := i;
- if (dli.Top>ShiftedClipRect.Bottom) and (GetMaxTextWidth=0) then
- BelowBottom := True;
- inc(i);
- end;
- OffsetRect(BRect, -xshift, -yshift);
- BRect1 := BRect;
- RVStyle.ParaStyles[AParaNo].Background.PrepareDraw(BRect1);
- RVStyle.ItemNo := DrawItems[i-1].ItemNo;
- RVStyle.RVData := Self;
- RVStyle.DrawParaBack(Canvas, AParaNo, BRect1, False, rvcmColor);
- RVStyle.ParaStyles[AParaNo].Border.Draw(BRect, Canvas);
- end
- else
- inc(i);
- if dli.Top>ShiftedClipRect.Bottom then
- BelowBottom := True;
- end;
- // drawing items...
- if Assigned(RVStyle.OnDrawTextBack) then
- for i:= FirstDLine to LastDLine do begin
- dli := DrawItems[i];
- with GetItem(dli.ItemNo) do
- if StyleNo>=0 then begin
- TextDrawState := [];
- if RVStyle.TextStyles[GetActualStyleNo(RVStyle)].Jump and
- (rvstDrawHover in State) and
- (LastJumpMovedAbove<>-1) and (JumpID = LastJumpMovedAbove) then
- Include(TextDrawState, rvtsHover);
- RVStyle.DrawTextBack(Canvas, dli.ItemNo, GetActualStyleNo(RVStyle),
- Self, dli.Left-xshift, dli.Top-yshift, dli.Width, dli.Height,
- TextDrawState);
- end;
- end;
- // drawing soft page breaks
- if (FSoftPageBreaks<>nil) and (rvoShowPageBreaks in Options) then
- DrawSoftPageBreaks;
- LineTopY := 0;
- LineBottomY := 0;
- for i:= FirstDLine to LastDLine do begin
- dli := DrawItems[i];
- if dli.FromNewLine and UseLineSelection(dli) then
- GetLineVerticalBounds(i, LineTopY, LineBottomY);
- li := GetItem(dli.ItemNo);
- no := GetActualStyle(li);
- if (rvioPageBreakBefore in li.ItemOptions) and
- (rvoShowPageBreaks in Options) and
- ((i=0) or (DrawItems[i-1].ItemNo<>dli.ItemNo))
- then begin
- RVStyle.DrawPageBreak(Canvas, GetLineTopY(i)-yshift-1, xshift, rvpbPageBreak, GetParentControl);
- LastDrawnStyle := -1;
- end;
- if (li.Checkpoint<>nil) and (rvoShowCheckpoints in Options) and
- ((i=0) or (DrawItems[i-1].ItemNo<>dli.ItemNo)) then begin
- RVStyle.DrawCheckpoint(Canvas, dli.Left-xshift, dli.Top-yshift,
- 0, GetParentControl.Width,
- Self, dli.ItemNo, xshift, li.Checkpoint.RaiseEvent,
- GetParentControl);
- LastDrawnStyle := -1;
- end;
- if no>=0 then begin { text }
- if No<>LastDrawnStyle then begin
- LastDrawnStyle := No;
- RVStyle.ApplyStyle(Canvas, No, GetParaBiDiMode(li.ParaNo), True);
- end;
- BiDiMode := GetItemBiDiMode(dli.ItemNo);
- HoverNow := RVStyle.TextStyles[no].Jump and (rvstDrawHover in State) and
- (LastJumpMovedAbove<>-1) and (li.JumpID = LastJumpMovedAbove);
- if ((StartNo>i) or (EndNo<i)) and
- not (rvstCompletelySelected in State) then begin {not selected}
- DrawText(dli.Left, dli.Top, dli.Width, 1, i,
- RV_ReturnProcessedString(DrawItems.GetString(i,Items),
- RVStyle.TextStyles[No], IsDrawItemLastOnWrappedLine(i),
- ShowSpecialCharacters, True),
- True, True, False,True);
- end
- else if (rvstCompletelySelected in State) or
- (((StartNo<i) or ((StartNo=i) and (StartOffs<=1))) and {selected completely}
- (((EndNo>i)) or ((EndNo=i) and (EndOffs>DrawItems[i].Length)))) then begin
- DrawText(dli.Left, dli.Top, dli.Width, 1, i,
- RV_ReturnProcessedString(DrawItems.GetString(i,Items),
- RVStyle.TextStyles[No], IsDrawItemLastOnWrappedLine(i),
- ShowSpecialCharacters, True),
- True, True, True, True);
- end
- else begin { selected partially }
- DrawText(dli.Left, dli.Top, dli.Width, 1, i,
- RV_ReturnProcessedString(DrawItems.GetString(i,Items),
- RVStyle.TextStyles[No], IsDrawItemLastOnWrappedLine(i),
- ShowSpecialCharacters, True),
- True, True, False,True);
- if (i<>StartNo) or (StartOffs<=1) then
- ditemselstart := 1
- else
- ditemselstart := StartOffs;
- if (i<>EndNo) or (EndOffs>dli.Length) then
- ditemselend := dli.Length
- else
- ditemselend := EndOffs-1;
- if ditemselend<ditemselstart then begin
- if ShowSpecialCharacters and (rvscParagraph in RVVisibleSpecialCharacters) then
- DrawParaMarkAfter(i);
- continue;
- end;
- s := DrawItems.GetString(i,Items);
- if BiDiMode<>rvbdUnspecified then begin
- s := RV_ReturnProcessedString(s, RVStyle.TextStyles[No],
- (ditemselend>=GetOffsAfterDrawItem(i)) and IsDrawItemLastOnWrappedLine(i),
- ShowSpecialCharacters, True);
- RVStyle.ApplyStyleColor(Canvas, no, GetSelDrawState, False, rvcmColor);
- res := RVU_DrawSelectedTextEx(dli.Left{$IFNDEF RVDONOTUSEJUSTIFY}+dli.SpaceBefore{$ENDIF}-xshift,
- dli.Top-yshift, dli.Width{$IFNDEF RVDONOTUSEJUSTIFY}-dli.SpaceBefore{$ENDIF},
- dli.Height, s, Canvas, ditemselstart, ditemselend, li.ItemOptions,
- BiDiMode);
- end
- else
- res := False;
- if not res then begin
- if ditemselstart>1 then begin
- s := DrawItems.GetSubString(i, Items, 1, ditemselstart-1);
- s := RV_ReturnProcessedString(s, RVStyle.TextStyles[No], False,
- ShowSpecialCharacters, True);
- fullwidth := RVU_TextWidth(s, Canvas, li.ItemOptions);
- end
- else
- fullwidth := 0;
- s := DrawItems.GetSubString(i, Items, ditemselstart, ditemselend-ditemselstart+1);
- s := RV_ReturnProcessedString(s, RVStyle.TextStyles[No],
- (ditemselend+1>=GetOffsAfterDrawItem(i)) and IsDrawItemLastOnWrappedLine(i),
- ShowSpecialCharacters, True);
- if Assigned(RVStyle.OnDrawStyleText) or
- (RVStyle.SelectionStyle=rvssLines) then begin
- selwidth := RVU_TextWidth(s, Canvas, li.ItemOptions);
- end
- else
- selwidth := 0;
- DrawText(dli.Left+fullwidth, dli.Top, selwidth, ditemselstart, i,
- s, ditemselstart<=1, ditemselend>=dli.Length, True, False);
- end;
- end;
- if ShowSpecialCharacters and (rvscParagraph in RVVisibleSpecialCharacters) then
- DrawParaMarkAfter(i);
- continue;
- end;
- DrawState := DefaultDrawState;
- if ((StartNo<=i) and (EndNo>=i) and
- not ((EndNo=i) and (EndOffs=0)) and
- not ((StartNo=i) and (StartOffs=1))) or
- (rvstCompletelySelected in State) then
- Include(DrawState,rvidsSelected);
- if (rvstDrawHover in State) and
- (LastJumpMovedAbove<>-1) and (li.JumpID = LastJumpMovedAbove) and
- li.GetBoolValueEx(rvbpJump, RVStyle) then
- Include(DrawState, rvidsHover);
- if GetParaBiDiMode(GetItemPara(dli.ItemNo))=rvbdRightToLeft then
- Include(DrawState, rvidsRTL);
- if ShowSpecialCharacters then
- Include(DrawState, rvidsShowSpecialCharacters);
- if (li = FActiveItem) then
- Include(DrawState, rvidsCurrent);
- if (rvflCanUseCustomPPI in Flags) then
- Include(DrawState, rvidsCanUseCustomPPI);
- if not li.GetBoolValue(rvbpFullWidth) then begin
- // controls, pictures, bullets, hotspots, etc.
- if (rvidsSelected in DrawState) and UseLineSelection(dli)
- {$IFNDEF RVDONOTUSELISTS} and (li.StyleNo<>rvsListMarker) {$ENDIF}
- then begin
- if rvidsControlFocused in DefaultDrawState then
- Canvas.Brush.Color := RVStyle.SelColor
- else
- Canvas.Brush.Color := RVStyle.InactiveSelColor;
- if Canvas.Brush.Color<>clNone then begin
- Canvas.Brush.Style := bsSolid;
- Canvas.FillRect(Rect(dli.Left-xshift, LineTopY-yshift,
- dli.Left-xshift+dli.Width, LineBottomY-yshift));
- end;
- Canvas.Brush.Style := bsClear;
- end;
- li.Paint(dli.Left-xshift, dli.Top-yshift, Canvas, DrawState, RVStyle, dli)
- end
- else begin
- // breaks, tables
- if rvoClientTextWidth in Options then
- fullwidth := GetWidth
- else begin
- fullwidth := GetAreaWidth;
- if (GetMaxTextWidth>0) and (GetMaxTextWidth+GetLeftMargin+GetRightMargin<fullwidth) then
- fullwidth := GetMaxTextWidth+GetLeftMargin+GetRightMargin;
- end;
- li.PaintFullWidth(dli.Left-xshift, fullwidth-GetRightMargin-xshift,
- dli.Top-yshift, Canvas, DrawState, RVStyle, AClipRect, dli);
- end;
- if ShowSpecialCharacters and (rvscParagraph in RVVisibleSpecialCharacters) then
- DrawParaMarkAfter(i);
- if li.GetBoolValue(rvbpDrawingChangesFont) then
- LastDrawnStyle := -1;
- end;
- {$IFNDEF RVDONOTUSELIVESPELL}
- DrawWordPainters;
- {$ENDIF}
- if (NotAddedCP<>nil) and (rvoShowCheckpoints in Options) then
- RVStyle.DrawCheckpoint(Canvas, -1, DocumentHeight-yshift,
- 0, GetParentControl.Width,
- Self, -1, xshift, NotAddedCP.RaiseEvent, GetParentControl);
- PostPaintTo(Canvas, xshift, yshift, FirstDLine, LastDLine);
- {$IFDEF RVWATERMARK}
- if rvflRoot in Flags then begin
- Canvas.Brush.Style := bsClear;
- Canvas.Font.Name := 'Arial';
- Canvas.Font.Size := 8;
- Canvas.Font.Style := [];
- Canvas.Font.Color := clRed;
- Canvas.TextOut(-xshift+GetWidth-80, -yshift, 'unregistered');
- end;
- {$ENDIF}
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRVFormattedData.GetItemBackground(ItemNo: Integer; r: TRect;
- MakeImageRect: Boolean;
- var Color: TColor; var bmp: TBitmap; var UseBitmap: Boolean);
- var item: TRVRectItemInfo;
- ditem: TRVDrawLineInfo;
- begin
- UseBitmap := False;
- Color := GetRVStyle.ParaStyles[GetItemPara(ItemNo)].Background.Color;
- if Color<>clNone then
- exit;
- Color := GetColor;
- if (GetBackground=nil) or (GetBackground.Style=bsNoBitmap) then
- exit;
- if bmp=nil then
- bmp := TBitmap.Create;
- item := TRVRectItemInfo(GetItem(ItemNo));
- if (item.DrawItemNo<0) or (item.DrawItemNo>=DrawItems.Count) then
- exit;
- UseBitmap := True;
- ditem := DrawItems[item.DrawItemNo];
- if MakeImageRect then
- r := Bounds(ditem.Left+item.GetBorderWidth, ditem.Top+item.GetBorderHeight,
- item.GetImageWidth(nil), item.GetImageHeight(nil));
- bmp.Width := r.Right-r.Left;
- bmp.Height := r.Bottom-r.Top;
- bmp.Canvas.Brush.Style := bsSolid;
- bmp.Canvas.Brush.Color := Color;
- bmp.Canvas.FillRect(Rect(0,0,bmp.Width,bmp.Height));
- OffsetRect(r, -GetHOffs, -GetVOffs);
- DrawBackground(bmp.Canvas, r);
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRVFormattedData.PostPaintTo(Canvas: TCanvas;
- HOffs, VOffs, FirstDrawItemNo, LastDrawItemNo: Integer);
- begin
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRVFormattedData.MouseLeave;
- var id: Integer;
- begin
- if not (rvflUseJumps in Flags) then
- exit;
- if LastRVDataMovedAbove<>nil then
- id := LastRVDataMovedAbove.LastJumpMovedAbove
- else
- id := -1;
- ClearLastJump;
- if id<>-1 then
- InvalidateJumpRect(id);
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRVFormattedData.InvalidateJumpRect(id: Integer);
- var rec: TRect;
- i : Integer;
- begin
- if GetRVStyle.FullRedraw then
- Invalidate
- else begin
- for i:=0 to Jumps.Count -1 do
- if id = TRVJumpInfo(Jumps[i]).id then
- with TRVJumpInfo(Jumps[i]) do begin
- rec := Bounds(l-GetZHOffs-5, t-GetZVOffs-5, w+10, h+10);
- InvalidateRect(rec);
- end;
- end;
- GetParentControl.Update;
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRVFormattedData.Invalidate;
- begin
- if GetParentControl<>nil then
- GetParentControl.Invalidate;
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRVFormattedData.Refresh;
- begin
- if GetParentControl<>nil then
- GetParentControl.Refresh;
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRVFormattedData.UpdateView;
- begin
- if GetParentControl<>nil then
- GetParentControl.Update;
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRVFormattedData.InvalidateRect(const r: TRect);
- begin
- if (GetParentControl<>nil) and GetParentControl.HandleAllocated then
- Windows.InvalidateRect(GetParentControl.Handle, @r, False);
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRVFormattedData.SearchHotItem(X,Y,HOffs,VOffs: Integer);
- begin
- if FCaptureMouseItem<>nil then
- exit;
- inc(X, HOffs);
- inc(Y, VOffs);
- if (LastDIMovedAbove<>-1) then
- if (LastDIMovedAbove>=DrawItems.Count) then
- LastDIMovedAbove := -1
- else
- with DrawItems[LastDIMovedAbove] do
- if not RV_PointInRect(X,Y, Left,Top,Width,Height) then
- LastDIMovedAbove := -1;
- if LastDIMovedAbove=-1 then
- LastDIMovedAbove := FindDrawItemAtPos(X,Y);
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRVFormattedData.MouseMove(Shift: TShiftState; X, Y: Integer);
- var JumpFound: Boolean;
- VOffs, HOffs: Integer;
- //SelRect: TRect;
- {...................................................}
- procedure DisplayRVDataHint;
- var s,s2: String;
- pt: TPoint;
- begin
- if rvoShowItemHints in GetOptions then begin
- s2 := GetAbsoluteRootData.GetParentControl.Hint;
- s := GetItemHint(Self, -1, '');
- GetAbsoluteRootData.GetParentControl.Hint := s;
- if s='' then
- Application.CancelHint
- else if (s<>s2) then begin
- GetCursorPos(pt);
- {$IFDEF RICHVIEWDEF5}
- Application.ActivateHint(pt);
- {$ENDIF}
- end;
- end;
- end;
- {...................................................}
- function MouseMoveHotItem(HOffs,VOffs: Integer): Boolean;
- {$IFNDEF RVDONOTUSEDRAGDROP}
- var DItemNo, DItemOffs: Integer;
- {$ENDIF}
- begin
- SearchHotItem(X,Y,HOffs,VOffs);
- if (LastDIMovedAbove<>-1) then
- with DrawItems[LastDIMovedAbove] do begin
- Result := GetItem(ItemNo).MouseMove(Shift,
- X-(Left-GetZHOffs),Y-(Top-GetZVOffs), ItemNo, Self);
- {$IFNDEF RVDONOTUSEDRAGDROP}
- if not Result and not (ssShift in Shift) and CanStartDragging then begin
- FindDrawItemForSel(X+HOffs, Y+VOffs, DItemNo, DItemOffs, True);
- if (DItemNo>=0) and DItem_InsideSelection(DItemNo, DItemOffs) then begin
- SetCursor(crArrow);
- Result := True;
- end;
- end;
- {$ENDIF}
- end
- else begin
- DisplayRVDataHint;
- Result := False;
- end;
- end;
- {...................................................}
- procedure ChangeSelection;
- var xs,ys,VPos,HPos,Width,Height: Integer;
- begin
- HPos := GetZHOffs;
- VPos := GetZVOffs;
- if rvstMakingSelection in State then begin
- ys := y;
- if not (rvflMouseXYAlwaysCorrect in Flags) then begin
- Height := GetHeight;
- ZoomInt(Height);
- if ys<0 then
- ys := 0
- else if ys>Height then
- ys := Height;
- end;
- xs := x;
- if not (rvflMouseXYAlwaysCorrect in Flags) then begin
- Width := GetWidth;
- ZoomInt(Width);
- if xs<0 then
- xs := 0
- else if xs>Width then
- xs := Width;
- end;
- if rvstLineSelection in State then begin
- if AdjustLineSelection(xs+HPos, ys+VPos) then begin
- ExpandSelectionToLines(False);
- DoOnSelection(False);
- Refresh;
- end;
- end
- else if AdjustSelectionByMode(xs+HPos, ys+VPos) then begin
- DoOnSelection(True);
- //if LastSelectionRect.Left=-1 then
- Refresh
- //else begin
- // SelRect := GetClientSelectionRect;
- // UnionRect(LastSelectionRect,LastSelectionRect,SelRect);
- // InvalidateRect(LastSelectionRect);
- // LastSelectionRect := SelRect;
- //end;
- end;
- end;
- end;
- {...................................................}
- function HighlightJump: Boolean;
- var i,HPos, VPos: Integer;
- item: TCustomRVItemInfo;
- begin
- HPos := GetZHOffs;
- VPos := GetZVOffs;
- for i:=0 to jumps.Count-1 do
- with TRVJumpInfo(Jumps[i]) do
- if RV_PointInRect(X ,Y, l-HPos, t-VPos, w, h) then begin
- Result := True;
- SetCursor(TRVJumpInfo(Jumps[i]).Cursor);
- if (LastRVDataMovedAbove=nil) or (LastRVDataMovedAbove.LastJumpMovedAbove<>id) then
- DoRVMouseMove(id+FirstJumpNo);
- if (LastRVDataMovedAbove<>nil) and (rvstDrawHover in LastRVDataMovedAbove.State) and
- (LastRVDataMovedAbove.LastJumpMovedAbove<>id) then begin
- LastRVDataMovedAbove.State := LastRVDataMovedAbove.State - [rvstDrawHover];
- InvalidateJumpRect(LastRVDataMovedAbove.LastJumpMovedAbove);
- end;
- RVData.LastJumpMovedAbove := id;
- item := RVData.GetItem(RVData.DrawItems[DrawItemNo].ItemNo);
- item.MouseMove(Shift, X-(RVData.DrawItems[DrawItemNo].Left-HPos),
- Y-(RVData.DrawItems[DrawItemNo].Top-VPos),
- RVData.DrawItems[DrawItemNo].ItemNo, RVData);
- LastRVDataMovedAbove := RVData;
- if not (rvstDrawHover in RVData.State) then begin
- if not item.GetBoolValueEx(rvbpHotColdJump,GetRVStyle) then
- exit;
- RVData.State := RVData.State + [rvstDrawHover];
- InvalidateJumpRect(RVData.LastJumpMovedAbove);
- end;
- exit;
- end;
- Result := False;
- end;
- {...................................................}
- begin
- if GetRVStyle=nil then exit;
- if (rvstMakingSelection in State) and not (ssLeft in Shift) then begin
- State := State-[rvstMakingSelection];
- FSelectingInfo.Free;
- FSelectingInfo := nil;
- //MouseUp(mbLeft, Shift, X, Y);
- end;
- HOffs := GetZHOffs;
- VOffs := GetZVOffs;
- ZoomInt(X);
- ZoomInt(Y);
- ClearXorDrawing;
- if FCaptureMouseItem=nil then begin
- ChangeSelection;
- if (GetRVStyle.LineSelectCursor<>crNone) and not (rvstMakingSelection in State) and
- (GetBiDiMode<>rvbdRightToLeft) and
- (X+HOffs<GetLeftMargin) and (rvoAllowSelection in Options) then
- SetCursor(GetRVStyle.LineSelectCursor)
- else begin
- if rvflUseJumps in Flags then begin
- JumpFound := HighlightJump;
- if not JumpFound then begin
- if (LastRVDataMovedAbove<>nil) then begin
- LastRVDataMovedAbove.State := LastRVDataMovedAbove.State - [rvstDrawHover];
- InvalidateJumpRect(LastRVDataMovedAbove.LastJumpMovedAbove);
- LastRVDataMovedAbove.LastJumpMovedAbove := -1;
- LastRVDataMovedAbove := nil;
- DoRVMouseMove(-1);
- end;
- if not MouseMoveHotItem(HOffs,VOffs) then
- SetCursor(GetNormalCursor);
- end
- end
- else
- if not MouseMoveHotItem(HOffs,VOffs) then
- SetCursor(GetNormalCursor);
- end;
- end
- else
- if not MouseMoveHotItem(HOffs,VOffs) then
- SetCursor(GetNormalCursor);
- XorDrawingEx(X,Y);
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRVFormattedData.MouseDown(Button: TMouseButton; Shift: TShiftState;
- X, Y: Integer);
- var i,StyleNo, ItemNo, Dummy, HOffs, VOffs: Integer;
- ClickedWord: String;
- RVData: TCustomRVFormattedData;
- begin
- {$IFNDEF RVDONOTUSELIVESPELL}
- LiveSpellingCheckCurrentItem;
- {$ENDIF}
- HOffs := GetZHOffs;
- VOffs := GetZVOffs;
- ZoomInt(X);
- ZoomInt(Y);
- begin
- SearchHotItem(X,Y, HOffs,VOffs);
- FClickedDrawItemNo := LastDIMovedAbove;
- if LastDIMovedAbove<>-1 then begin
- ItemNo := DrawItems[LastDIMovedAbove].ItemNo;
- if (FPartialSelectedItem<>GetItem(ItemNo)) and
- (GetChosenItem<>GetItem(ItemNo)) then begin
- DeselectPartiallySelectedItem(nil);
- if not (ssDouble in Shift) then
- Windows.SetFocus(GetParentControl.Handle);
- end;
- if LastDIMovedAbove<>-1 then
- with DrawItems[LastDIMovedAbove] do begin
- if (GetInplaceEditor<>nil) and
- not GetItem(ItemNo).OwnsInplaceEditor(GetInplaceEditor) then begin
- DestroyInplaceEditor;
- if not (ssDouble in Shift) then
- Windows.SetFocus(GetParentControl.Handle);
- end;
- GetItem(ItemNo).MouseDown(Button, Shift, X-(Left-HOffs),Y-(Top-VOffs),
- ItemNo, Self);
- end;
- end
- else begin
- ItemNo := -1;
- DestroyInplaceEditor;
- if not (ssDouble in Shift) then
- Windows.SetFocus(GetParentControl.Handle);
- end;
- if (GetInplaceEditor=nil) and IsAssignedRVMouseDown then
- DoRVMouseDown(Button, Shift, ItemNo, X, Y);
- if (GetInplaceEditor=nil) and (Button=mbLeft) then begin
- LastJumpDowned := -1;
- for i:=0 to Jumps.Count-1 do
- with TRVJumpInfo(Jumps[i]) do
- if (X>=l-HOffs) and (X<=l+w-HOffs) and
- (Y>=t-VOffs) and (Y<=t+h-VOffs) then begin
- LastJumpDowned := id;
- break;
- end;
- end;
- if (FCaptureMouseItem<>nil) or (GetInplaceEditor<>nil) then begin
- if LastDIMovedAbove<>-1 then begin
- FSelStartNo := LastDIMovedAbove;
- FSelEndNo := LastDIMovedAbove;
- FSelStartOffs := 1;
- FSelEndOffs := 1;
- DoOnSelection(True);
- end;
- exit;
- end;
- end;
- if (Button = mbLeft) and not (rvstIgnoreNextMouseDown in State) and not
- (rvstStartingDragDrop in GetAbsoluteRootData.State) then begin
- if (rvoSingleClick in Options) and IsAssignedRVDblClick and
- FindWordAt(Clickedword, X, Y, StyleNo, ItemNo, Dummy, RVData) then
- DoRVDblClick(ClickedWord, StyleNo);
- if (rvoAllowSelection in Options) and (ssLeft in Shift) then begin
- State := State - [rvstLineSelection];
- DeselectPartiallySelectedItem(nil);
- GetSelStart(FSelStartNo,FSelStartOffs);
- FindDrawItemForSel(X+HOffs, Y+VOffs, ItemNo, Dummy, False);
- {$IFNDEF RVDONOTUSEDRAGDROP}
- if not (ssShift in Shift) and (X+HOffs>=GetLeftMargin) and
- not (rvstDragDropCursorNotMoved in GetAbsoluteRootData.State) and
- DItem_InsideSelection(ItemNo, Dummy) and CanStartDragging then begin
- GetAbsoluteRootData.State := GetAbsoluteRootData.State+[rvstStartingDragDrop];
- PostMessage(GetAbsoluteRootData.GetParentControl.Handle, WM_RVDRAGDROP, 0, 0);
- end
- else
- {$ENDIF}
- begin
- FSelEndNo := ItemNo;
- FSelEndOffs := Dummy;
- if not (ssShift in Shift) or (FSelStartNo=-1) then begin
- FSelStartNo := FSelEndNo;
- FSelStartOffs := FSelEndOffs;
- end;
- if (FSelEndNo<>-1) then begin
- State := State + [rvstMakingSelection];
- FSelectingInfo.Free;
- FSelectingInfo := nil;
- if (GetRVStyle.LineSelectCursor<>crNone) and (GetBiDiMode<>rvbdRightToLeft) and
- (X+HOffs<GetLeftMargin) and
- not (ssShift in Shift) then begin
- State := State + [rvstLineSelection];
- ExpandSelectionToLines(True);
- end
- else begin
- if (GetRVStyle.SelectionMode in [rvsmWord, rvsmParagraph]) then begin
- FSelectingInfo := TRVSelectingInfo.Create;
- FSelectingInfo.DrawItemSOffs := FSelStartOffs;
- FSelectingInfo.DrawItemEOffs := FSelStartOffs;
- FSelectingInfo.DrawItemSNo := FSelStartNo;
- if GetRVStyle.SelectionMode = rvsmParagraph then begin
- FSelectingInfo.InitE(rvsesParaMode);
- if ssShift in Shift then
- AdjustSelectionByMode(X+HOffs, Y+VOffs);
- end
- else begin
- if InsideWord(FSelStartNo, FSelStartOffs) then begin
- GetWordBounds(FSelStartNo, FSelStartOffs,
- FSelectingInfo.DrawItemSWordOffs1, FSelectingInfo.DrawItemSWordOffs2);;
- FSelectingInfo.InitE(rvsesInWord)
- end
- else
- FSelectingInfo.InitE(rvsesFreeMode);
- end;
- end;
- end;
- end
- else
- State := State - [rvstMakingSelection];
- DoOnSelection(True);
- Invalidate;
- end;
- //LastSelectionRect := GetClientSelectionRect;
- end;
- end;
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRVFormattedData.MouseUp(Button: TMouseButton; Shift: TShiftState;
- X, Y: Integer);
- var i, StyleNo, no, xs, ys: Integer;
- clickedword: String;
- p: TPoint;
- DoNotJump: Boolean;
- ItemNo, ItemOffs, Dummy: Integer;
- ASelStartNo, ASelEndNo, ASelStartOffs, ASelEndOffs: Integer;
- HOffs, VOffs, Width, Height: Integer;
- RVData: TCustomRVFormattedData;
- begin
- HOffs := GetZHOffs;
- VOffs := GetZVOffs;
- Height := GetHeight;
- Width := GetWidth;
- ZoomInt(X);
- ZoomInt(Y);
- ZoomInt(Width);
- ZoomInt(Height);
- DoNotJump := SelectionExists(True, True);
- {$IFDEF RVMUDESELECT}
- if rvstMidSelClicked in State then begin
- State := State - [rvstMidSelClicked];
- Deselect(nil, True);
- Invalidate;
- end;
- {$ENDIF}
- if FCaptureMouseItem=nil then begin
- State := State - [rvstIgnoreNextMouseDown];
- if (rvstMakingSelection in State) and (Button = mbLeft) then begin
- ys := y;
- if not (rvflMouseXYAlwaysCorrect in Flags) then
- if ys<0 then
- ys := 0
- else if ys>Height then
- ys := Height;
- xs := x;
- if not (rvflMouseXYAlwaysCorrect in Flags) then
- if xs<0 then
- xs := 0
- else if xs>Width then
- xs := Width;
- if rvstLineSelection in State then
- AdjustLineSelection(xs+HOffs, ys+VOffs)
- else
- AdjustSelectionByMode(xs+HOffs, ys+VOffs);
- State := State - [rvstMakingSelection, rvstLineSelection];
- FSelectingInfo.Free;
- FSelectingInfo := nil;
- SearchHotItem(X,Y, HOffs,VOffs);
- AdjustMouseUpSelection;
- DoOnSelection(True);
- Invalidate;
- DoSelect;
- end;
- if (rvoRClickDeselects in Options) and (Button = mbRight) then begin
- GetSelBounds(ASelStartNo, ASelEndNo, ASelStartOffs, ASelEndOffs, True);
- FindDrawItemForSel(X+HOffs, Y+VOffs, ItemNo, ItemOffs, False);
- if (ItemNo<>-1) and
- (((ItemNo<ASelStartNo) or ((ItemNo=ASelStartNo) and (ItemOffs<ASelStartOffs))) or
- ((ItemNo>ASelEndNo) or ((ItemNo=ASelEndNo) and (ItemOffs>ASelEndOffs)))) then begin
- FSelStartNo := ItemNo;
- FSelStartOffs := ItemOffs;
- FSelEndNo := ItemNo;
- FSelEndOffs := ItemOffs;
- DoOnSelection(True);
- Refresh;
- DoSelect;
- end;
- end;
- end;
- SearchHotItem(X,Y, HOffs,VOffs);
- if LastDIMovedAbove<>-1 then begin
- ItemNo := DrawItems[LastDIMovedAbove].ItemNo;
- with DrawItems[LastDIMovedAbove] do
- GetItem(ItemNo).MouseUp(Button, Shift, X-(Left-HOffs),Y-(Top-VOffs),
- ItemNo, Self);
- end
- else
- ItemNo := -1;
- if FCaptureMouseItem<>nil then exit;
- if not DoNotJump and
- (Button in [mbLeft, mbRight]) and
- (ItemNo<>-1) and
- GetItem(ItemNo).GetBoolValueEx(rvbpAllowsFocus, GetRVStyle) and
- (GetRootData is TRVControlData) and
- (TRVControlData(GetRootData).TabNavigation<>rvtnNone)
- then begin
- AdjustFocus(ItemNo, Self, ItemNo);
- GetItem(ItemNo).Focusing;
- end;
- if IsAssignedRVMouseUp then
- DoRVMouseUp(Button, Shift, ItemNo, X, Y);
- if (Button = mbRight) and IsAssignedRVRightClick and
- FindWordAt(ClickedWord, X,Y, StyleNo,no, Dummy, RVData) then begin
- p := ClientToScreen(Point(X,Y));
- DoRVRightClick(ClickedWord, StyleNo, p.X, p.Y);
- end;
- if Button <> mbLeft then exit;
- if (LastJumpDowned=-1) or not IsAssignedJump or DoNotJump then
- exit;
- for i:=0 to Jumps.Count-1 do
- with TRVJumpInfo(Jumps[i]) do
- if (LastJumpDowned=id) and
- (X>=l-HOffs) and (X<=l+w-HOffs) and
- (Y>=t-VOffs) and (Y<=t+h-VOffs) then begin
- LastJumpDowned:=-1;
- DoJump(id+FirstJumpNo);
- exit;
- end;
- LastJumpDowned:=-1;
- FClickedDrawItemNo :=-1;
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRVFormattedData.DblClick;
- var
- StyleNo, ItemNo, Offs: Integer;
- ClickedWord: String;
- p: TPoint;
- RVData: TCustomRVFormattedData;
- begin
- if (not (rvoSingleClick in Options) and IsAssignedRVDblClick) or
- (rvoDblClickSelectsWord in Options) then begin
- GetCursorPos(p);
- p := ScreenToClient(p);
- //ZoomInt(p.X);
- //ZoomInt(p.Y);
- if (rvoDblClickSelectsWord in Options) and (rvoAllowSelection in Options) then begin
- if FindWordAt(ClickedWord, p.X, p.Y, StyleNo, ItemNo, Offs, RVData) then begin
- if StyleNo>=0 then
- RVData.SetSelectionBounds(ItemNo, Offs, ItemNo,
- Offs+RVU_Length(clickedword,RVData.GetItemOptions(ItemNo)))
- else
- RVData.SetSelectionBounds(ItemNo, 0, ItemNo, 1);
- RVData.State := RVData.State + [rvstIgnoreNextMouseDown];
- RVData.State := RVData.State - [rvstMakingSelection];
- Invalidate;
- State := State - [rvstMakingSelection];
- DoRVDblClick(ClickedWord, StyleNo);
- State := State + [rvstIgnoreNextMouseDown];
- end;
- exit;
- end;
- if IsAssignedRVDblClick and
- FindWordAt(ClickedWord, p.X, p.Y, StyleNo, ItemNo, Offs, RVData) then
- DoRVDblClick(ClickedWord, StyleNo);
- end;
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRVFormattedData.DeleteItems(FirstItemNo, Count: Integer);
- begin
- Deselect(nil, True);
- inherited DeleteItems(FirstItemNo, Count);
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRVFormattedData.DeleteParas(FirstItemNo, LastItemNo: Integer);
- var FirstItemNo2, LastItemNo2,
- FirstDItemNo, LastDItemNo, tmp: Integer;
- begin
- ExpandToPara(FirstItemNo, LastItemNo, FirstItemNo, LastItemNo);
- FirstItemNo2 := FirstItemNo;
- LastItemNo2 := LastItemNo;
- if FirstItemNo2>0 then
- dec(FirstItemNo2);
- if LastItemNo2<Items.Count-1 then
- inc(LastItemNo2);
- ExpandToPara(FirstItemNo2, LastItemNo2, FirstItemNo2, LastItemNo2);
- Item2FirstDrawItem(FirstItemNo2, FirstDItemNo);
- Item2FirstDrawItem(LastItemNo2, LastDItemNo);
- DeleteItems(FirstItemNo, LastItemNo-FirstItemNo+1);
- FormatParasExact(FirstDItemNo,LastDItemNo, - (LastItemNo-FirstItemNo+1), False);
- ClearJumps;
- tmp := 0;
- BuildJumpsCoords(tmp, jumps);
- end;
- {------------------------------------------------------------------------------}
- function TCustomRVFormattedData.SelectionExists(AllowReset: Boolean;UsePartialSelected: Boolean): Boolean;
- var StartNo, EndNo, StartOffs, EndOffs: Integer;
- begin
- {$IFNDEF RVDONOTUSEINPLACE}
- if (GetChosenRVData<>nil) then begin
- Result := TCustomRVFormattedData(GetChosenRVData).SelectionExists(AllowReset, UsePartialSelected);
- exit;
- end;
- {$ENDIF}
- if rvstMakingSelection in State then
- AllowReset := False;
- if UsePartialSelected and
- (FPartialSelectedItem<>nil) and
- FPartialSelectedItem.PartiallySelected then begin
- Result := True;
- exit;
- end;
- GetSelBounds(StartNo, EndNo, StartOffs, EndOffs, True);
- if (StartNo <> -1) and (StartNo=EndNo) and (StartOffs=EndOffs) then begin
- if AllowReset then
- Deselect(FPartialSelectedItem, True);
- Result := False;
- exit;
- end;
- Result := (StartNo<>-1) and (EndNo<>-1);
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRVFormattedData.SetCursor(Cursor: TCursor);
- begin
- GetParentControl.Cursor := Cursor;
- end;
- {------------------------------------------------------------------------------}
- function TCustomRVFormattedData.ClientToScreen(const p: TPoint): TPoint;
- begin
- Result := GetParentControl.ClientToScreen(p);
- end;
- {------------------------------------------------------------------------------}
- function TCustomRVFormattedData.ScreenToClient(const p: TPoint): TPoint;
- begin
- Result := GetParentControl.ScreenToClient(p);
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRVFormattedData.GetSelStart(var DINo, DIOffs: Integer);
- begin
- SelectionExists(True, False);
- DINo := FSelStartNo;
- DIOffs := FSelStartOffs;
- end;
- {------------------------------------------------------------------------------}
- function TCustomRVFormattedData.GetSelectedImage: TGraphic;
- var StartNo, EndNo, StartOffs, EndOffs,Index: Integer;
- begin
- {$IFNDEF RVDONOTUSEINPLACE}
- if (GetChosenRVData<>nil) then begin
- Result := TCustomRVFormattedData(GetChosenRVData).GetSelectedImage;
- exit;
- end;
- {$ENDIF}
- Result := nil;
- StoreSelBounds(StartNo, EndNo, StartOffs, EndOffs, True);
- if (StartNo=-1) then exit;
- case EndNo-StartNo of
- 0:
- begin
- if (StartOffs>0) or (EndOffs<1) then exit;
- Index := StartNo;
- end;
- 1:
- begin
- if StartOffs>GetOffsBeforeItem(StartNo) then begin
- if StartOffs<GetOffsAfterItem(StartNo) then exit;
- if EndOffs<GetOffsAfterItem(EndNo) then exit;
- Index := StartNo+1
- end
- else if EndOffs<GetOffsAfterItem(EndNo) then begin
- if EndOffs>GetOffsBeforeItem(EndNo) then exit;
- if StartOffs>GetOffsBeforeItem(StartNo) then exit;
- Index := StartNo
- end
- else
- exit;
- end;
- 2:
- begin
- if StartOffs<GetOffsAfterItem(StartNo) then exit;
- if EndOffs>GetOffsBeforeItem(EndNo) then exit;
- Index := StartNo+1;
- end;
- else
- exit;
- end;
- Result := TCustomRVItemInfo(Items.Objects[Index]).AsImage;
- end;
- {------------------------------------------------------------------------------}
- function TCustomRVFormattedData.GetSelText(Unicode: Boolean): String;
- var Stream: TMemoryStream;
- begin
- {$IFNDEF RVDONOTUSEINPLACE}
- if (GetChosenRVData<>nil) then begin
- Result := TCustomRVFormattedData(GetChosenRVData).GetSelText(Unicode);
- exit;
- end;
- {$ENDIF}
- if not SelectionExists(False, True) then begin
- Result := '';
- exit;
- end;
- Stream := TMemoryStream.Create;
- try
- if SaveTextToStream('', Stream, 80, True, True, Unicode, False) then begin
- SetLength(Result, Stream.Size);
- Stream.Position := 0;
- Stream.ReadBuffer(PChar(Result)^, Stream.Size);
- end
- else
- Result := '';
- finally
- Stream.Free;
- end;
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRVFormattedData.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);
- with DrawItems[FSelStartNo] do
- ShowRectangle(Left,Top,Width,Height);
- Invalidate;
- DoOnSelection(True);
- DoSelect;
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRVFormattedData.SrchStart(Down: Boolean; var strt, offs: Integer);
- var sl,so: Integer;
- begin
- if SelectionExists(True, False) then begin
- StoreSelBounds(sl, strt, so, offs, False);
- end
- else begin
- if Down then begin
- strt := GetFirstItemVisible;
- offs := GetOffsBeforeItem(0);
- end
- else begin
- strt := GetLastItemVisible;
- offs := GetOffsAfterItem(strt)+1;
- end;
- end;
- if strt<0 then strt := 0;
- end;
- {------------------------------------------------------------------------------}
- function TCustomRVFormattedData.SearchText(Down, MatchCase, WholeWord: Boolean; s:String):Boolean;
- {....................................................}
- function FwdPos(const substr, astr: String): Integer;
- var offs,r,roffs: Integer;
- str: String;
- begin
- str := astr;
- Result := 0;
- offs := 0;
- r := Pos(substr, str);
- if WholeWord then begin
- while r <> 0 do begin
- roffs := offs+r;
- if ((roffs = 1) or ((roffs > 1) and IsDelimiter(astr, roffs-1, []))) and
- (((roffs+Length(substr)) > Length(astr)) or
- (((roffs+Length(substr))<= Length(astr)) and IsDelimiter(astr, roffs+Length(substr),[])))
- then begin
- Result := roffs;
- exit;
- end;
- str := System.Copy(str,r+Length(substr),Length(str));
- inc(offs, r+Length(substr)-1);
- r := Pos(substr, str);
- end;
- end
- else
- Result := r;
- end;
- {....................................................}
- function RevPos(substr, str: String): Integer;
- var offs,r: Integer;
- begin
- Result := 0;
- offs := 0;
- while Length(str)<>0 do begin
- r := FwdPos(Substr, str);
- if r=0 then exit;
- Result := offs + r;
- str := System.Copy(str,r+Length(substr),Length(str));
- inc(offs, r+Length(substr)-1);
- end;
- end;
- {....................................................}
- function SearchInItem(item: TCustomRVItemInfo; StoreSub: TRVStoreSubRVData;
- SubRVData: TCustomRVFormattedData): Boolean;
- var SubPos: TRVSubRVDataPos;
- begin
- if Down then
- SubPos := rvdNext
- else
- SubPos := rvdPrev;
- Result := TCustomRVFormattedData(SubRVData.GetRVData).SearchText(Down, MatchCase, WholeWord, s);
- if not Result then
- repeat
- SubRVData := TCustomRVFormattedData(item.GetSubRVData(StoreSub,SubPos));
- if SubRVData=nil then
- break;
- Result := TCustomRVFormattedData(SubRVData.GetRVData).SearchText(Down, MatchCase, WholeWord, s);
- until Result;
- if Result then
- item.ChooseSubRVData(StoreSub);
- StoreSub.Free;
- end;
- {....................................................}
- procedure UpdateUnicodePos(const editorstring, soughtstring: String;
- ItemOptions: TRVItemOptions;
- var Offs, Len: Integer);
- {$IFNDEF RVDONOTUSEUNICODE}
- var s: String;
- {$ENDIF}
- begin
- {$IFNDEF RVDONOTUSEUNICODE}
- if not (rvioUnicode in ItemOptions) then
- exit;
- s := RVU_AnsiToUnicode(GetDefaultCodePage, soughtstring);
- Len := Length(s) div 2;
- s := System.Copy(editorstring, 1, Offs-1);
- s := RVU_AnsiToUnicode(GetDefaultCodePage, s);
- Offs := Length(s) div 2+1;
- {$ENDIF}
- end;
- {....................................................}
- var strt, offs, len, i, so: Integer;
- s2: String;
- ItemOptions: TRVItemOptions;
- item: TCustomRVItemInfo;
- StoreSub: TRVStoreSubRVData;
- SubPos: TRVSubRVDataPos;
- SubRVData: TCustomRVFormattedData;
- begin
- Result := False;
- if not MatchCase then
- s := AnsiUpperCase(s);
- if s='' then exit;
- if Items.Count=0 then exit;
- StoreSub := nil;
- item := GetChosenItem;
- if item=nil then
- item := PartialSelectedItem;
- if item<>nil then begin
- if Down then
- SubPos := rvdChosenDown
- else
- SubPos := rvdChosenUp;
- SubRVData := TCustomRVFormattedData(item.GetSubRVData(StoreSub, SubPos));
- if SubRVData<>nil then begin
- Result := SearchInItem(item, StoreSub, SubRVData);