Minor change to TPrintPreview

Please post bug reports, feature requests, or any question regarding the DELPHI AREA products here.

Minor change to TPrintPreview

Postby Seb@stieN » May 28th, 2003, 7:45 pm

For TPrintPreview accept more TCustomRichEdit (ex TwwRichEdit)

Code: Select all
function TPrintPreview.PaintRichText(const Rect: TRect;
  RichEdit: TCustomRichEdit; MaxPages: Integer; pOffset: PInteger): Integer;
var
  Range: TFormatRange;
  MaxLen, OldMap: Integer;
  SaveRect: TRect;
  SaveIndex: Integer;
  TextLenEx: TGetTextLengthEx;
begin
  Result := 0;
  FillChar(Range, SizeOf(TFormatRange), 0);
  Range.hdc := Canvas.Handle;
  Range.hdcTarget := Range.hdc;
  Range.rc.Left := ConvertUnit(Rect.Left, Units, mmTWIPS);
  Range.rc.Top := ConvertUnit(Rect.Top, Units, mmTWIPS);
  Range.rc.Right := ConvertUnit(Rect.Right, Units, mmTWIPS);
  Range.rc.Bottom := ConvertUnit(Rect.Bottom, Units, mmTWIPS);
  Range.rcPage := Range.rc;
  Range.chrg.cpMax := -1;
  if pOffset = nil then
    Range.chrg.cpMin := 0
  else
    Range.chrg.cpMin := pOffset^;
  SaveRect := Range.rc;
  //MaxLen := RichEdit.GetTextLen;
  with TextLenEx do
    begin
      flags    := GTL_DEFAULT;
      codepage := CP_ACP;
    end;
  MaxLen := SendMessage(RichEdit.Handle, EM_GETTEXTLENGTHEX, wParam(@TextLenEx), 0);
  SaveIndex := SaveDC(Range.hdc);
  OldMap := SetMapMode(Range.hdc, MM_TEXT);
  //RichEdit.Perform(EM_FORMATRANGE, 0, 0);
  SendMessage(RichEdit.Handle, EM_FORMATRANGE, 0, 0);
  try
    repeat
      if Result > 0  then
      begin
        RestoreDC(Range.hdc, SaveIndex);
        SetMapMode(Range.hdc, OldMap);
        NewPage;
        Range.hdc := Canvas.Handle;
        Range.hdcTarget := Range.hdc;
        SaveIndex := SaveDC(Range.hdc);
        SetMapMode(Range.hdc, MM_TEXT);
        Range.rc := SaveRect;
      end;
      //Range.chrg.cpMin := RichEdit.Perform(EM_FORMATRANGE, 1, Integer(@Range));
      Range.chrg.cpMin := SendMessage(RichEdit.Handle, EM_FORMATRANGE, 1, Integer(@Range));
      if Range.chrg.cpMin <> -1 then
        Inc(Result);
    until (Range.chrg.cpMin >= MaxLen) or (Range.chrg.cpMin = -1) or
          ((MaxPages > 0) and (Result >= MaxPages));
  finally
    //RichEdit.Perform(EM_FORMATRANGE, 0, 0);
    SendMessage(RichEdit.Handle, EM_FORMATRANGE, 0, 0);
    RestoreDC(Range.hdc, SaveIndex);
    SetMapMode(Range.hdc, OldMap);
    if pOffset <> nil then
      if Range.chrg.cpMin < MaxLen then
        pOffset^ := Range.chrg.cpMin
      else
        pOffset^ := -1;
  end;
end;
Seb@stieN
Active Member
Active Member
 
Posts: 10
Joined: May 28th, 2003, 7:41 pm

Postby Kambiz » May 28th, 2003, 7:53 pm

Thank you very much! :)

Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2408
Joined: March 7th, 2003, 7:10 pm


Return to DELPHI AREA Products

Who is online

Users browsing this forum: No registered users and 3 guests

cron