GetBlockAttr method

Applies to
TWPRTFEnginePaint

Declaration
function GetBlockAttr(var DifferentSettings: TWPBlockAttribute; IgnoredValue: Boolean = FALSE): Boolean;

Description
This procedure fills a record with information about the text which is currently selected. This information is retrieved mainly from the "Cursor.SelectedText" interface. This makes the implementation of this procedure a good example for the use of the TWPSelectedTextAttrInterface.
function TWPRTFEnginePaint.GetBlockAttr(
  var DifferentSettings: TWPBlockAttribute;
  IgnoredValue: Boolean = FALSE): Boolean;
var d: Integer; s: Single; sel: TWPSelectionContents;
begin
  with Cursor do
  begin
    if not IsSelected then
      Result := FALSE
    else
    begin
      Result := TRUE;
      if not SelectedTextAttr.GetStyles(DifferentSettings.UnionStyle) then
        DifferentSettings.UnionStyle := [];
      DifferentSettings.FontDiffers := not SelectedTextAttr.GetFont(d);
      DifferentSettings.SizeDiffers := not SelectedTextAttr.GetFontSize(s);
      DifferentSettings.ColorDiffers := not SelectedTextAttr.GetColorNr(d);
      DifferentSettings.BKColorDiffers := not SelectedTextAttr.GetBGColorNr(d);
      DifferentSettings.AlignDiffers := not SelectedTextAttr.AGet(
        WPAT_Alignment, d);
      DifferentSettings.IndentfirstDiffers := not SelectedTextAttr.AGet(
        WPAT_IndentFirst, d);
      DifferentSettings.IndentleftDiffers := not SelectedTextAttr.AGet(
        WPAT_IndentLeft, d);
      DifferentSettings.IndentrightDiffers := not SelectedTextAttr.AGet(
        WPAT_IndentRight, d);
      DifferentSettings.SpacebeforeDiffers := not SelectedTextAttr.AGet(
        WPAT_SpaceBefore, d);
      DifferentSettings.SpaceafterDiffers := not SelectedTextAttr.AGet(
        WPAT_SpaceAfter, d);
      DifferentSettings.SpacebetweenDiffers := not SelectedTextAttr.AGet(
        WPAT_SpaceBetween, d);
      DifferentSettings.ParcolorDiffers := not SelectedTextAttr.AGet(
        WPAT_FGColor, d);
      DifferentSettings.ParshadingDiffers := not SelectedTextAttr.AGet(
        WPAT_ShadingValue, d);
      DifferentSettings.ParstyleDiffers := not SelectedTextAttr.AGetBaseStyle(d);
      DifferentSettings.ParIDDiffers := not SelectedTextAttr.AGet(
        WPAT_ParID, d);
      DifferentSettings.ParBorderDiffers := not SelectedTextAttr.AGet(
        WPAT_BorderFlags, d);

      sel := SelectionContents;
      DifferentSettings.ParInTableDiffers :=
        (wpSelStandardText in sel) and
        (wpSelTableCells in sel);
      Result := TRUE;
    end;
  end;
end;


This procedure as been included to improve the compatibility with WPTools 4. The second parameter is ignored.

The procedure is used in the method 'FontSelect' which shows a font selection dialog:
function TWPCustomRichText.FontSelect : Boolean;
var
  FontDialog1: TFontDialog;
  BlockAttr: TWPBlockAttribute;
begin
  Result := FALSE;
  if Changing then
  begin
    FontDialog1 := nil;
    try
      FontDialog1 := TFontDialog.Create(Self);
      if Printer.Printers.Count > 0 then
        FontDialog1.Device := fdPrinter;
      if Memo.Selected then
      begin
        Memo.GetBlockAttr(BlockAttr, TRUE);
        // Also assigns the asttributes to 'Attr'
        if BlockAttr.FontDiffers then
          FontDialog1.Options := FontDialog1.Options + [fdNoFaceSel];
        if BlockAttr.SizeDiffers then
          FontDialog1.Options := FontDialog1.Options + [fdNoSizeSel];
      end;
      FontDialog1.Font.Assign(UpdateFontValues);
      if FontDialog1.Execute then
      begin
        ApplyFont(FontDialog1.Font);
        Changed;
        Result := TRUE;
      end;
    finally
      FontDialog1.Free;
    end;
    Changed;
  end;
end;


Copyright (C) by WPCUBED GmbH - Munich
http://www.wpcubed.com