Hi,
ProtectedTextAttr does not chante the protected paragraphs, just the text with the afsProtected flag.
The easiest would be to apply paragraph shading to the protected paragraphs, you can assign and remove that quickly in a loop over all paragraphs.
Optionally You can also use some code to render custom backgrounds for certain paragraps, see demo CustomParDraw which uses this event handler:
procedure TWPCustDraw.WPRichText1CustomLinePaintBefore(Sender: TObject; RTFEngine: TWPRTFEngineBasis; Param: TWPVirtPagePaintParam; EndOfPageRun: Boolean);begin if Flash.Checked and (Param.Par = flashpar) then begin Param.Canvas.Brush.Style := bsSolid; Param.Canvas.Brush.Color := clYellow; Param.Canvas.FillRect(Param.Rect); end;end;procedure TWPCustDraw.WPRichText1CustomLinePaintAfter(Sender: TObject; RTFEngine: TWPRTFEngineBasis; Param: TWPVirtPagePaintParam; EndOfPageRun: Boolean);var r: TRect; par: TParagraph;begin if EndOfPageRun then // at last ... begin r := Param.UnionRect; Param.Canvas.Brush.Style := bsClear; if CreateBox.Checked and (Param.Tag=2) then begin Param.Canvas.Pen.Width := Param.Page.XPixelsPerInch div 30; Param.Canvas.Pen.Color := clBlack; InflateRect(r, Param.Page.XPixelsPerInch div 30, Param.Page.XPixelsPerInch div 30); // We need to start on next page with a box! if not Param.Par.HasText('$end') then HasOpenBox := TRUE; end else begin Param.Canvas.Pen.Width := 0; if flashmode then Param.Canvas.Pen.Color := clYellow else Param.Canvas.Pen.Color := clRed; end; Param.Canvas.Rectangle(r.Left, r.Top, r.Right, r.Bottom); end else if Param.Tag = 0 then // check each par only once! begin // This is need to for dynamic boxes to span multiple pages! if Param.PageNo=0 then HasOpenBox := FALSE; Param.Tag := 1; if HiglightNOW.Checked and not Param.Par.IsTable and Param.Par.HasText('NOW') then begin Param.CallAgainToClose := TRUE; Param.UseUntilIncludingPar := Param.Par.LastInnerChild; end else if CreateBox.Checked then begin par := Param.Par; if HasOpenBox or par.HasText('$start') then begin while (par <> nil) and not par.HasText('$end') do par := par.next; Param.Tag := 2; // we need to know that this is a dynamic box Param.UseUntilIncludingPar := par; if par <> nil then Param.CallAgainToClose := TRUE; end; end; end;end;
This is a bit complicated since it draws a frame around selected paragraphs, it would be simpler to do just shading:
procedure TWPCustDraw.WPRichText1CustomLinePaintBefore(Sender: TObject;
RTFEngine: TWPRTFEngineBasis; Param: TWPVirtPagePaintParam;
EndOfPageRun: Boolean);
begin
if Param.Par.AGetDef(WPAT_ParProtect, 0)=1 then
begin
Param.Canvas.Brush.Style := bsSolid;
Param.Canvas.Brush.Color := clGRay;
Param.Canvas.FillRect(Param.Rect);
end;
end;