WPCubed Product Support

Request for new event- BeforeLeaveRTFDataBlock

Can we have a new BeforeLeaveRTFDataBlock event in TWPCustomRtfEdit. This would be implemented as follows:

TWPAllowEvent = procedure(Sender: TWPCustomRtfEdit;
  var Allow: Boolean) of object;

FBeforeLeaveRTFDataBlock: TWPAllowEvent;

function TWPCustomRtfEdit.DontAllowLeaveRTFDataBlock: Boolean;
var allow: Boolean;
begin
  allow := TRUE;
  if assigned(FBeforeLeaveRTFDataBlock) then
    FBeforeLeaveRTFDataBlock(Self, allow)
  if allow = FALSE then
  begin
    Result := TRUE;
    exit;
  end;
  if (wpDisableEditOfNonBodyDataBlocks in EditOptionsEx)
    or (LayoutMode = wplayLayout) then
    with FMemo.Cursor do
    begin
      if (RTFData = nil) or (RTFData.Kind <> wpIsBody) then
        Result := FALSE
      else Result := TRUE;
    end else Result := FALSE;
end;

This will allow us to lock users into data blocks under program control. In particular, our application will have two distinct edit modes - Body Mode and Header/Footer Mode. Currently we can lock the user into the body using the wpDisableEditOfNonBodyDataBlocks option, but there is no way of locking them out of the body when they are in our Header/Footer Mode. Introducing our proposed event will be much more flexible than creating another EditOptionsEx value such as wpDisableEditOfBodyDataBlocks

#1 ♥ 0
4.6k Views 2 users read 2 min

Actually my implementation is no good as I need to know the destination data block. So please consider the following solution which works for me - Modify WPRTEPaint as follows (new or modified lines marked with {*}):

  1. add new data type for the event
...type  TWPRTFEnginePaint = class;  TWPLeaveRTFDataBlockEvent = procedure(Sender: TWPRTFEnginePaint;    FromBlock, ToBlock: TWPRTFDataBlock; var Allowed: Boolean) of object; {*}
  1. Create the event property
TWPRTFEnginePaint = class(TWPRTFEngineBasis)...    FOverridePageCount, FOverridePageOffset: Integer;    FBeforeLeaveRTFDataBlock: TWPLeaveRTFDataBlockEvent; {*}    procedure SetUseANSITextAttr(x: Boolean);...    property OnGetPageGapText: TWPOnGetPageGapText read _OnGetPageGapText write _OnGetPageGapText;    property BeforeLeaveRTFDataBlock: TWPLeaveRTFDataBlockEvent read FBeforeLeaveRTFDataBlock write FBeforeLeaveRTFDataBlock; {*}  end;
  1. Now implement in MoveCursor function
function TWPRTFEnginePaint.MoveCursor(PaintPageNr: Integer; X, Y: Integer; DontLeaveDataBlock: Boolean = FALSE): Boolean;
var aRTFData, newblock: TWPRTFDataBlock;
...
  Allowed: Boolean; {*}
begin
...
      RepaintIt := (par.RTFData <> Cursor.RTFData);

      Allowed := TRUE; {*}
      if RepaintIt then
        if assigned(FBeforeLeaveRTFDataBlock) then {*}
          FBeforeLeaveRTFDataBlock(self, Cursor.RTFData, par.RTFData, Allowed);  {*}

      if not Allowed or (DontLeaveDataBlock and RepaintIt and (Cursor.RTFData <> nil)) then exit; {*}
...

I hope you will be able to include these changes in your next release.

#3 ♥ 0
support

thanks for the suggestion,
OnLeaveRTFDataBlock will be in V5.20.7

Julian

#4 ♥ 0
This category is archived. No new posts are possible.