[Example] Is plain text

Demos, code samples. Only questions related to the existing topics are allowed here.
Post Reply
Sergey Tkachenko
Site Admin
Posts: 17554
Joined: Sat Aug 27, 2005 10:28 am
Contact:

[Example] Is plain text

Post by Sergey Tkachenko »

This function returns True if the TRichView control contains only a plain text.

Code: Select all

function IsPlainText(rv: TCustomRichView): Boolean;
var
  i, StyleNo, StyleNo2, ParaNo: Integer;
  s: TRVUnicodeString;
begin
  // if empty, then returning True
  if rv.ItemCount = 0 then
  begin
    Result := True;
    exit;
  end;
  Result := False;
  // checking for a background bitmap  
  if (rv.BackgroundStyle<>bsNoBitmap) and not rv.BackgroundBitmap.Empty then
    exit;
  // finding the starting text and paragraph styles
  StyleNo := rv.GetItemStyle(0);
  if StyleNo = rvsTab then
    StyleNo := TRVTabItemInfo(rv.GetItem(0)).TextStyleNo;
  if StyleNo < 0 then
    exit;
  ParaNo := rv.GetItemPara(0);
  for i := 0 to rv.ItemCount - 1 do
  begin
    // checking paragraph
    if rv.GetItemPara(i) <> ParaNo then
      exit;
    // checking checkpoints, tags, tooltips
    if (rv.GetItemCheckpoint(i) <> nil) or (rv.GetItemTag(i) <> '') then
      exit;
    rv.GetItemExtraStrProperty(i, rvespHint, s);
    if s <> '' then
      exit;
    // checking text style
    StyleNo2 := rv.GetItemStyle(i);
    if StyleNo2 = rvsTab then
      StyleNo2 := TRVTabItemInfo(rv.GetItem(i)).TextStyleNo;
    if StyleNo <> StyleNo2 then
      exit;
  end;
  Result := True;
end;
"Plain text" is defined as a text formatted with the same text and paragraph attributes, no non-text objects, without special text properties (tags, hints, checkpoints), no background image.

This function does not check text and paragraph attributes themselves (even if they have colored background and borders).
Post Reply