Skip to content

Commit

Permalink
continue FPC/LCL compatibility work
Browse files Browse the repository at this point in the history
- but not yet finished because there is a lot of low-level Delphi specific code :(
  • Loading branch information
Arnaud Bouchez committed Oct 24, 2022
1 parent 023740d commit 37f3205
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/mormot.commit.inc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
'2.0.4228'
'2.0.4229'
2 changes: 1 addition & 1 deletion src/ui/mormot.ui.core.pas
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ procedure TextRectUtf8(const Rect: TRect; Canvas: TCanvas; X, Y: integer;
procedure TextRectString(const Rect: TRect; Canvas: TCanvas; X, Y: integer;
const Text: string; Align: TAlignment = taLeftJustify; NoControlChar: boolean = false);

/// alternative to the VCL Canvas.TextFlas property
/// alternative to the VCL Canvas.TextFlas property for text output
function TextFlags(Canvas: TCanvas): integer;

{$ifdef OSWINDOWS}
Expand Down
70 changes: 60 additions & 10 deletions src/ui/mormot.ui.report.pas
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
- TRenderPages Prototype - unfinished
Forked and heavily patched from TPages component (c) 2003 Angus Johnson
Note: not yet compatible with FPC due to a lot of Windowsims and VCLisms
*****************************************************************************
*)
Expand All @@ -20,12 +21,18 @@ interface

{$I ..\mormot.defines.inc}

{$ifdef OSPOSIX}
{$if defined(OSPOSIX) or defined(FPC)}

// do-nothing-unit on non Windows system
// do-nothing-unit on non Delphi + Windows system
// = not yet compatible with FPC/LCL due to a lot of Windowsims and VCLisms :(
procedure Register;

implementation

procedure Register;
begin
end;

{$else}

{.$define MOUSE_CLICK_PERFORM_ZOOM} // old not user-friendly behavior
Expand Down Expand Up @@ -1432,6 +1439,19 @@ function ConvertNegsToParentheses(const ValStr: SynUnicode): SynUnicode;
result := result + ')';
end;

{$ifdef FPC}
// some WinSpool redefinitions to match Delphi signature
function EnumPrinters(Flags: DWORD; Name: PChar; Level: DWORD;
pPrinterEnum: Pointer; cbBuf: DWORD; var pcbNeeded, pcReturned: DWORD): BOOL; stdcall;
external 'winspool.drv' name 'EnumPrintersA';
function OpenPrinter(pPrinterName: PChar; var phPrinter: THandle;
pDefault: PPrinterDefaults): BOOL; stdcall;
external 'winspool.drv' name 'EnumPrintersA';
function GetPrinterDriver(hPrinter: THandle; pEnvironment: PChar; Level: DWORD;
pDriverInfo: Pointer; cbBuf: DWORD; var pcbNeeded: DWORD): BOOL; stdcall;
external 'winspool.drv' name 'EnumPrintersA';
{$endif FPC}

function PrinterDriverExists: boolean;
var
Flags, Count, NumInfo: dword;
Expand Down Expand Up @@ -1518,7 +1538,7 @@ function GetDefaultPrinterName: string;
MoveFast(p^, pointer(result)^, p2 - p);
end;

function GetDriverForPrinter(Device: PChar; Driver: PChar): boolean;
function GetDriverForPrinter(Device, Driver: PChar): boolean;
var
PrintHandle: THandle;
DriverInfo2: PDriverInfo2;
Expand All @@ -1529,22 +1549,42 @@ function GetDriverForPrinter(Device: PChar; Driver: PChar): boolean;
if not OpenPrinter(Device, PrintHandle, nil) then
exit;
try
getmem(DriverInfo2, 1024);
Getmem(DriverInfo2, 1024);
try
if GetPrinterDriver(PrintHandle, nil, 2, DriverInfo2, 1024, cnt) then
if GetPrinterDriver(
PrintHandle, nil, 2, DriverInfo2, 1024, cnt) then
begin
DriverPath := changefileext(extractfilename(DriverInfo2.pDriverPath), '');
strpcopy(Driver, DriverPath);
result := true;
end;
finally
freemem(DriverInfo2);
Freemem(DriverInfo2);
end;
finally
ClosePrinter(PrintHandle);
end;
end;

{$ifdef FPC}

procedure SetCurrentPrinterAsDefault;
begin
// not implemented yet
end;

function CurrentPrinterName: string;
begin
result := Printer.PrinterName;
end;

function CurrentPrinterPaperSize: string;
begin
result := Printer.PaperSize.PaperName;
end;

{$else}

procedure SetCurrentPrinterAsDefault;
var
Device, Driver, Port: array[byte] of char;
Expand Down Expand Up @@ -1634,6 +1674,8 @@ function CurrentPrinterPaperSize: string;
end;
end;

{$endif FPC}

function GetNextItemW(var P: PWideChar): SynUnicode;
var
S: PWideChar;
Expand Down Expand Up @@ -1758,7 +1800,13 @@ procedure TrimLine(Canvas: TCanvas; var ls: SynUnicode; out rs: SynUnicode;
end;


procedure PrintBitmap(Canvas: TCanvas; DestRect: TRect; Bitmap: TBitmap);
{$ifdef FPC}
procedure PrintBitmap(Canvas: TCanvas; const DestRect: TRect; Bitmap: TBitmap);
begin
Canvas.StretchDraw(DestRect.Rect, Bitmap);
end;
{$else}
procedure PrintBitmap(Canvas: TCanvas; const DestRect: TRect; Bitmap: TBitmap);
var
BitmapHeader: pBitmapInfo;
BitmapImage: pointer;
Expand Down Expand Up @@ -1786,7 +1834,7 @@ procedure PrintBitmap(Canvas: TCanvas; DestRect: TRect; Bitmap: TBitmap);
FreeMem(BitmapImage)
end;
end;

{$endif FPC}

// This DrawArrow() function is based on code downloaded from
// http://www.efg2.com/Lab/Library/Delphi/Graphics/Algorithms.htm
Expand Down Expand Up @@ -3769,7 +3817,9 @@ procedure TGdiPages.DrawGraphic(graph: TGraphic; bLeft, bWidth: integer;
R: TRect;
H: integer;
begin
if (self = nil) or (graph = nil) or graph.Empty then
if (self = nil) or
(graph = nil) or
graph.Empty then
exit; // avoid GPF
// compute position and draw bitmap
if bLeft = maxInt then
Expand Down Expand Up @@ -6110,7 +6160,7 @@ procedure TRenderBox.Plain;

{$endif RENDERPAGES}

{$endif OSPOSIX}
{$ifend OSPOSIX+FPC}

end.

0 comments on commit 37f3205

Please sign in to comment.