mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-04-18 09:29:35 +02:00
Structural work for Printing in Cocoa, now it already compiles and links but doesnt print anything
git-svn-id: trunk@47768 -
This commit is contained in:
parent
b8546196bb
commit
20a1bf3a5f
3
.gitattributes
vendored
3
.gitattributes
vendored
@ -2997,6 +2997,9 @@ components/printers/carbon/carbonprinters_h.inc svneol=native#text/pascal
|
||||
components/printers/carbon/carbonprinting.pas svneol=native#text/pascal
|
||||
components/printers/carbon/carbonprndialogs.inc svneol=native#text/pascal
|
||||
components/printers/carbon/issues.xml svneol=native#text/xml
|
||||
components/printers/cocoa/cocoaprinters.inc svneol=native#text/plain
|
||||
components/printers/cocoa/cocoaprinters_h.inc svneol=native#text/plain
|
||||
components/printers/cocoa/cocoaprndialogs.inc svneol=native#text/plain
|
||||
components/printers/design/Makefile svneol=native#text/plain
|
||||
components/printers/design/Makefile.compiled svneol=native#text/plain
|
||||
components/printers/design/Makefile.fpc svneol=native#text/plain
|
||||
|
638
components/printers/cocoa/cocoaprinters.inc
Normal file
638
components/printers/cocoa/cocoaprinters.inc
Normal file
@ -0,0 +1,638 @@
|
||||
{%MainUnit ../osprinters.pas}
|
||||
{**************************************************************
|
||||
Implementation for carbonprinter
|
||||
***************************************************************}
|
||||
Uses InterfaceBase, LCLIntf, LCLProc;
|
||||
|
||||
|
||||
{ TCocoaPrinterContext }
|
||||
|
||||
{function TCocoaPrinterContext.GetSize: TPoint;
|
||||
var
|
||||
R: PMRect;
|
||||
begin
|
||||
Result.X := 0;
|
||||
Result.Y := 0;
|
||||
|
||||
if Printer = nil then Exit;
|
||||
R:=CleanPMRect;
|
||||
if OSError(PMGetAdjustedPaperRect((Printer as TCocoaPrinter).PageFormat, R),
|
||||
Self, 'GetSize', 'PMGetUnadjustedPaperRect') then Exit;
|
||||
|
||||
Result.X := Round(R.right - R.left);
|
||||
Result.Y := Round(R.bottom - R.top);
|
||||
end;
|
||||
|
||||
procedure TCocoaPrinterContext.Release;
|
||||
begin
|
||||
// redirect drawing to dummy context when not able printing page
|
||||
CGContext := DefaultContext.CGContext;
|
||||
end;
|
||||
|
||||
procedure TCocoaPrinterContext.Reset;
|
||||
begin
|
||||
inherited Reset;
|
||||
|
||||
if CGContext <> nil then
|
||||
begin
|
||||
// flip and offset CTM from lower to upper left corner
|
||||
CGContextTranslateCTM(CGContext, 0, GetSize.Y);
|
||||
CGContextScaleCTM(CGContext, 1, -1);
|
||||
end;
|
||||
end; }
|
||||
|
||||
{ TCocoaPrinter }
|
||||
|
||||
procedure TCocoaPrinter.CreatePrintSession;
|
||||
begin
|
||||
//if OSError(PMCreateSession(FPrintSession), Self, 'GetPrintSession', 'PMCreateSession') then
|
||||
//raise EPrinter.Create('Error initializing printing for Carbon: Unable to create print session!');
|
||||
end;
|
||||
|
||||
procedure TCocoaPrinter.CreatePrintSettings;
|
||||
const
|
||||
SName = 'CreatePrintSettings';
|
||||
begin
|
||||
//if OSError(PMCreatePrintSettings(FPrintSettings), Self, SName, 'PMCreatePrintSettings') then
|
||||
//raise EPrinter.Create('Error initializing printing for Carbon: Unable to create print settings!');
|
||||
|
||||
//OSError(PMSessionDefaultPrintSettings(PrintSession, FPrintSettings), Self, SName, 'PMSessionDefaultPrintSettings');
|
||||
end;
|
||||
|
||||
function TCocoaPrinter.CreatePageFormat(APaper: String): PMPageFormat;
|
||||
var
|
||||
I: Integer;
|
||||
S: TStringList;
|
||||
const
|
||||
SName = 'CreatePageFormat';
|
||||
begin
|
||||
{ if APaper = '' then
|
||||
begin
|
||||
I := -1;
|
||||
S := nil;
|
||||
end
|
||||
else
|
||||
begin
|
||||
S := TStringList.Create;
|
||||
BeginEnumPapers(S);
|
||||
I := S.IndexOf(APaper);
|
||||
end;
|
||||
|
||||
try
|
||||
if I < 0 then
|
||||
begin
|
||||
Result:=nil;
|
||||
if OSError(PMCreatePageFormat(Result), Self, SName, 'PMCreatePageFormat') then
|
||||
raise EPrinter.Create('Error initializing printing for Carbon: Unable to create page format!');
|
||||
|
||||
OSError(PMSessionDefaultPageFormat(PrintSession, Result), Self, SName, 'PMSessionDefaultPageFormat');
|
||||
end
|
||||
else
|
||||
begin
|
||||
OSError(PMCreatePageFormatWithPMPaper(Result,
|
||||
PMPaper(CFArrayGetValueAtIndex(FPaperArray, I))),
|
||||
Self, SName, 'PMCreatePageFormatWithPMPaper');
|
||||
|
||||
end;
|
||||
finally
|
||||
if S <> nil then
|
||||
begin
|
||||
EndEnumPapers;
|
||||
S.Free;
|
||||
end;
|
||||
end; }
|
||||
end;
|
||||
|
||||
function TCocoaPrinter.ValidatePageFormat: Boolean;
|
||||
begin
|
||||
Result := False;
|
||||
//OSError(PMSessionValidatePageFormat(PrintSession, PageFormat, @Result),
|
||||
//Self, 'ValidatePageFormat', 'PMSessionValidatePageFormat');
|
||||
end;
|
||||
|
||||
function TCocoaPrinter.ValidatePrintSettings: Boolean;
|
||||
begin
|
||||
Result := False;
|
||||
//OSError(PMSessionValidatePrintSettings(PrintSession, PrintSettings, @Result),
|
||||
//Self, 'ValidatePrintSettings', 'PMSessionValidatePrintSettings');
|
||||
end;
|
||||
|
||||
function TCocoaPrinter.GetCurrentPrinterName: String;
|
||||
{var
|
||||
P: PMPrinter; }
|
||||
begin
|
||||
{ Result := '';
|
||||
P := GetCurrentPrinter;
|
||||
if P <> nil then
|
||||
Result := CFStringToStr(PMPrinterGetName(P));
|
||||
if Trim(Result) = '' then
|
||||
Result := ''; }
|
||||
end;
|
||||
|
||||
procedure TCocoaPrinter.BeginPage;
|
||||
{var
|
||||
PaperRect: PMRect; }
|
||||
begin
|
||||
{ if FBeginDocumentStatus = noErr then
|
||||
begin
|
||||
FNewPageStatus := PMSessionBeginPage(PrintSession, nil, nil);
|
||||
OSError(FNewPageStatus, Self, 'BeginPage', 'PMSessionBeginPage', '', kPMCancel);
|
||||
|
||||
// update printer context
|
||||
if OSError(PMSessionGetCGGraphicsContext(PrintSession, FPrinterContext.CGContext),
|
||||
Self, 'BeginPage', 'PMSessionGetCGGraphicsContext') then
|
||||
FPrinterContext.Release
|
||||
else
|
||||
FPrinterContext.Reset;
|
||||
|
||||
// translate the context from his paper (0,0) origin
|
||||
// to our working imageable area
|
||||
if PMGetAdjustedPaperRect(PageFormat, PaperRect{%H-})=noErr then
|
||||
CGContextTranslateCTM(FPrinterContext.CGContext, -PaperRect.left, -PaperRect.top);
|
||||
|
||||
if Assigned(Canvas) then
|
||||
Canvas.Handle := HDC(FPrinterContext);
|
||||
end; }
|
||||
end;
|
||||
|
||||
procedure TCocoaPrinter.EndPage;
|
||||
begin
|
||||
{FPrinterContext.Release;
|
||||
if Assigned(Canvas) then Canvas.Handle := 0;
|
||||
|
||||
if FBeginDocumentStatus = noErr then
|
||||
begin
|
||||
if FNewPageStatus = noErr then
|
||||
OSError(PMSessionEndPage(PrintSession), Self, 'EndPage', 'PMSessionEndPage', '', kPMCancel);
|
||||
end; }
|
||||
end;
|
||||
|
||||
procedure TCocoaPrinter.FindDefaultPrinter;
|
||||
{var
|
||||
P: PMPrinter;
|
||||
I, C: CFIndex;
|
||||
pa: CFArrayRef; }
|
||||
begin
|
||||
{pa:=nil;
|
||||
if OSError(PMServerCreatePrinterList(kPMServerLocal, pa),
|
||||
Self, 'DoEnumPrinters', 'PMServerCreatePrinterList') then Exit;
|
||||
|
||||
if not Assigned(pa) then Exit;
|
||||
|
||||
C := CFArrayGetCount(pa);
|
||||
for I := 0 to C - 1 do
|
||||
begin
|
||||
P := CFArrayGetValueAtIndex(pa, I);
|
||||
|
||||
if PMPrinterIsDefault(P) then
|
||||
begin
|
||||
FDefaultPrinter := CFStringToStr(PMPrinterGetName(P));
|
||||
Break;
|
||||
end;
|
||||
end;
|
||||
CFRelease(pa); }
|
||||
end;
|
||||
|
||||
procedure TCocoaPrinter.BeginEnumPrinters(Lst: TStrings);
|
||||
{var
|
||||
P: PMPrinter;
|
||||
I, C: CFIndex;
|
||||
NewPrinterName: String; }
|
||||
begin
|
||||
{FPrinterArray := nil;
|
||||
if OSError(PMServerCreatePrinterList(kPMServerLocal, FPrinterArray),
|
||||
Self, 'DoEnumPrinters', 'PMServerCreatePrinterList') then Exit;
|
||||
|
||||
C := CFArrayGetCount(FPrinterArray);
|
||||
for I := 0 to C - 1 do
|
||||
begin
|
||||
P := CFArrayGetValueAtIndex(FPrinterArray, I);
|
||||
NewPrinterName := CFStringToStr(PMPrinterGetName(P));
|
||||
|
||||
//DebugLn(DbgS(I) + ' ' + PrinterName);
|
||||
if NewPrinterName = FDefaultPrinter then
|
||||
Lst.InsertObject(0, NewPrinterName, TObject(I))
|
||||
else
|
||||
Lst.AddObject(NewPrinterName, TObject(I));
|
||||
end; }
|
||||
end;
|
||||
|
||||
procedure TCocoaPrinter.EndEnumPrinters;
|
||||
begin
|
||||
if FPrinterArray<>nil then
|
||||
CFRelease(FPrinterArray);
|
||||
end;
|
||||
|
||||
procedure TCocoaPrinter.BeginEnumPapers(Lst: TStrings);
|
||||
var
|
||||
{P: PMPaper; }
|
||||
I, C: CFIndex;
|
||||
CFString: CFStringRef;
|
||||
PaperName: String;
|
||||
const
|
||||
SName = 'DoEnumPapers';
|
||||
begin
|
||||
{FPaperArray := nil;
|
||||
if OSError(PMPrinterGetPaperList(GetCurrentPrinter, FPaperArray),
|
||||
Self, SName, 'PMPrinterGetPaperList') then Exit;
|
||||
FPaperArray := CFRetain(FPaperArray);
|
||||
|
||||
C := CFArrayGetCount(FPaperArray);
|
||||
for I := 0 to C - 1 do
|
||||
begin
|
||||
P := CFArrayGetValueAtIndex(FPaperArray, I);
|
||||
CFString:=nil;
|
||||
if OSError(PMPaperGetName(P, CFString), Self, SName, 'PMPaperGetName') then Continue;
|
||||
PaperName := CFStringToStr(CFString);
|
||||
//MacOSX 10.4 returns wrong paper name in case of US Letter.
|
||||
//In system we can choose US Letter, but here it returns Letter.Issue #17698
|
||||
if PaperName = 'Letter' then
|
||||
PaperName := 'US Letter'
|
||||
else
|
||||
if PaperName = 'Legal' then
|
||||
PaperName := 'US Legal';
|
||||
Lst.Add(PaperName);
|
||||
end; }
|
||||
end;
|
||||
|
||||
procedure TCocoaPrinter.EndEnumPapers;
|
||||
begin
|
||||
if FPaperArray<>nil then
|
||||
CFRelease(FPaperArray);
|
||||
end;
|
||||
|
||||
constructor TCocoaPrinter.Create;
|
||||
begin
|
||||
inherited Create;
|
||||
|
||||
CreatePrintSession;
|
||||
CreatePrintSettings;
|
||||
FPageFormat := CreatePageFormat('');
|
||||
FPrinterContext := TCocoaPrinterContext.Create;
|
||||
|
||||
FindDefaultPrinter;
|
||||
UpdatePrinter;
|
||||
//DebugLn('Current ' + GetCurrentPrinterName);
|
||||
//DebugLn('Default ' + FDefaultPrinter);
|
||||
end;
|
||||
|
||||
procedure TCocoaPrinter.DoDestroy;
|
||||
begin
|
||||
FPrinterContext.Free;
|
||||
|
||||
{if FPrintSettings <> nil then PMRelease(PMObject(FPrintSettings));
|
||||
if FPageFormat <> nil then PMRelease(PMObject(FPageFormat));
|
||||
if FPrintSession <> nil then PMRelease(PMObject(FPrintSession)); }
|
||||
|
||||
inherited DoDestroy;
|
||||
end;
|
||||
|
||||
function TCocoaPrinter.Write(const Buffer; Count: Integer;
|
||||
var Written: Integer): Boolean;
|
||||
begin
|
||||
Result := False;
|
||||
CheckRawMode(True);
|
||||
|
||||
DebugLn('TCocoaPrinter.Write Error: Raw mode is not supported for Carbon!');
|
||||
end;
|
||||
|
||||
procedure TCocoaPrinter.RawModeChanging;
|
||||
begin
|
||||
//
|
||||
end;
|
||||
|
||||
procedure TCocoaPrinter.Validate;
|
||||
var
|
||||
P: String;
|
||||
begin
|
||||
{ValidatePrintSettings;
|
||||
ValidatePageFormat;
|
||||
|
||||
// if target paper is not supported, use the default
|
||||
P := DoGetPaperName;
|
||||
if PaperSize.SupportedPapers.IndexOf(P) = -1 then
|
||||
DoSetPaperName(DoGetDefaultPaperName); }
|
||||
end;
|
||||
|
||||
procedure TCocoaPrinter.UpdatePrinter;
|
||||
{var
|
||||
s: string;
|
||||
Res: PMResolution;}
|
||||
begin
|
||||
{s := GetCurrentPrinterName;
|
||||
if trim(s) = '' then // Observed if Default printer set to "Use last printer", and no printing done
|
||||
s := '*'; // so select lcl default
|
||||
SetPrinter(s);
|
||||
// set the page format resolution
|
||||
Res := GetOutputResolution;
|
||||
PMSetResolution(PageFormat, Res);
|
||||
Validate; }
|
||||
end;
|
||||
|
||||
function TCocoaPrinter.GetOutputResolution: PMResolution;
|
||||
var
|
||||
res: OSStatus;
|
||||
begin
|
||||
{ res := PMPrinterGetOutputResolution(GetCurrentPrinter, PrintSettings, Result{%H-});
|
||||
if res<>noErr then
|
||||
begin
|
||||
Result.vRes:=72;
|
||||
Result.hRes:=72;
|
||||
end; }
|
||||
end;
|
||||
|
||||
function TCocoaPrinter.GetXDPI: Integer;
|
||||
var
|
||||
dpi: PMResolution;
|
||||
begin
|
||||
dpi := GetOutputResolution;
|
||||
result := round(dpi.hRes);
|
||||
end;
|
||||
|
||||
function TCocoaPrinter.GetYDPI: Integer;
|
||||
var
|
||||
dpi: PMResolution;
|
||||
begin
|
||||
dpi := GetOutputResolution;
|
||||
result := round(dpi.hRes);
|
||||
end;
|
||||
|
||||
procedure TCocoaPrinter.DoBeginDoc;
|
||||
begin
|
||||
inherited DoBeginDoc;
|
||||
|
||||
//DebugLn('TCocoaPrinter.DoBeginDoc ' + DbgS(Printing));
|
||||
Validate;
|
||||
|
||||
//FBeginDocumentStatus := PMSessionBeginCGDocument(PrintSession, PrintSettings, PageFormat);
|
||||
//OSError(FBeginDocumentStatus, Self, 'DoBeginDoc', 'PMSessionBeginCGDocument', '', kPMCancel);
|
||||
|
||||
FNewPageStatus := kPMCancel;
|
||||
|
||||
BeginPage;
|
||||
end;
|
||||
|
||||
procedure TCocoaPrinter.DoNewPage;
|
||||
begin
|
||||
inherited DoNewPage;
|
||||
|
||||
EndPage;
|
||||
BeginPage;
|
||||
end;
|
||||
|
||||
procedure TCocoaPrinter.DoEndDoc(aAborded: Boolean);
|
||||
begin
|
||||
inherited DoEndDoc(aAborded);
|
||||
|
||||
{ EndPage;
|
||||
if FBeginDocumentStatus = noErr then
|
||||
OSError(PMSessionEndDocument(PrintSession), Self, 'DoEndDoc', 'PMSessionEndDocument', '', kPMCancel);}
|
||||
end;
|
||||
|
||||
procedure TCocoaPrinter.DoAbort;
|
||||
begin
|
||||
inherited DoAbort;
|
||||
|
||||
//OSError(PMSessionSetError(PrintSession, kPMCancel), Self, 'DoAbort', 'PMSessionSetError');
|
||||
end;
|
||||
|
||||
//Enum all defined printers. First printer it's default
|
||||
procedure TCocoaPrinter.DoEnumPrinters(Lst: TStrings);
|
||||
begin
|
||||
BeginEnumPrinters(Lst);
|
||||
EndEnumPrinters;
|
||||
end;
|
||||
|
||||
procedure TCocoaPrinter.DoResetPrintersList;
|
||||
begin
|
||||
inherited DoResetPrintersList;
|
||||
end;
|
||||
|
||||
procedure TCocoaPrinter.DoEnumPapers(Lst: TStrings);
|
||||
begin
|
||||
BeginEnumPapers(Lst);
|
||||
EndEnumPapers;
|
||||
end;
|
||||
|
||||
function TCocoaPrinter.DoGetPaperName: string;
|
||||
{var
|
||||
P: PMPaper;
|
||||
CFString: CFStringRef;
|
||||
const
|
||||
SName = 'DoGetPaperName'; }
|
||||
begin
|
||||
{Result := '';
|
||||
|
||||
P:=nil;
|
||||
if OSError(PMGetPageFormatPaper(PageFormat, P), Self, SName, 'PMGetPageFormatPaper') then Exit;
|
||||
CFString:=nil;
|
||||
if OSError(PMPaperGetName(P, CFString), Self, SName, 'PMPaperGetName') then Exit;
|
||||
|
||||
Result := CFStringToStr(CFString); }
|
||||
end;
|
||||
|
||||
function TCocoaPrinter.DoGetDefaultPaperName: string;
|
||||
{var
|
||||
T: PMPageFormat; }
|
||||
begin
|
||||
{Result := '';
|
||||
|
||||
T := FPageFormat;
|
||||
FPageFormat := CreatePageFormat('');
|
||||
|
||||
Result := DoGetPaperName;
|
||||
if T <> nil then
|
||||
begin
|
||||
PMRelease(PMObject(FPageFormat));
|
||||
FPageFormat := T;
|
||||
end; }
|
||||
end;
|
||||
|
||||
procedure TCocoaPrinter.DoSetPaperName(AName: string);
|
||||
var
|
||||
O: TPrinterOrientation;
|
||||
begin
|
||||
{ O := DoGetOrientation;
|
||||
if FPageFormat <> nil then PMRelease(PMObject(FPageFormat));
|
||||
|
||||
FPageFormat := CreatePageFormat(AName);
|
||||
DoSetOrientation(O);
|
||||
|
||||
ValidatePageFormat; }
|
||||
end;
|
||||
|
||||
function TCocoaPrinter.DoGetPaperRect(AName: string; var APaperRc: TPaperRect): Integer;
|
||||
{var
|
||||
T: PMPageFormat;
|
||||
PaperRect, PageRect: PMRect;
|
||||
S: Double;
|
||||
O: PMOrientation;
|
||||
Res: PMResolution;
|
||||
const
|
||||
SName = 'DoGetPaperRect'; }
|
||||
begin
|
||||
{Result := -1;
|
||||
|
||||
T := CreatePageFormat(AName);
|
||||
try
|
||||
// copy scale
|
||||
S:=0.0;
|
||||
OSError(PMGetScale(PageFormat, S), Self, SName, 'PMGetScale');
|
||||
OSError(PMSetScale(T, S), Self, SName, 'PMSetScale');
|
||||
|
||||
// copy orientation
|
||||
O:=CleanPMOrientation;
|
||||
OSError(PMGetOrientation(PageFormat, O), Self, SName, 'PMGetOrientation');
|
||||
OSError(PMSetOrientation(T, O, False), Self, SName, 'PMSetOrientation');
|
||||
|
||||
// copy resolution
|
||||
Res := GetOutputResolution;
|
||||
OSError(PMSetResolution(T, Res), self, SName, 'PMSetResolution');
|
||||
|
||||
// update
|
||||
OSError(PMSessionValidatePageFormat(PrintSession, T, nil),
|
||||
Self, SName, 'PMSessionValidatePageFormat');
|
||||
|
||||
PaperRect:=CleanPMRect;
|
||||
OSError(PMGetAdjustedPaperRect(T, PaperRect), Self, SName, 'PMGetAdjustedPaperRect');
|
||||
PageRect:=CleanPMRect;
|
||||
OSError(PMGetAdjustedPageRect(T, PageRect), Self, SName, 'PMGetAdjustedPageRect');
|
||||
finally
|
||||
PMRelease(PMObject(T));
|
||||
end;
|
||||
|
||||
ValidatePageFormat;
|
||||
|
||||
APaperRc.PhysicalRect.Left := 0;
|
||||
APaperRc.PhysicalRect.Top := 0;
|
||||
APaperRc.PhysicalRect.Right := Round(PaperRect.right - PaperRect.left);
|
||||
APaperRc.PhysicalRect.Bottom := Round(PaperRect.bottom - PaperRect.top);
|
||||
|
||||
APaperRc.WorkRect.Left := Round(-PaperRect.left);
|
||||
APaperRc.WorkRect.Top := Round(-PaperRect.top);
|
||||
APaperRc.WorkRect.Right := Round(PageRect.right - PageRect.left - PaperRect.left);
|
||||
APaperRc.WorkRect.Bottom := Round(PageRect.bottom - PageRect.top - PaperRect.top);
|
||||
|
||||
Result := 1; }
|
||||
end;
|
||||
|
||||
function TCocoaPrinter.DoSetPrinter(aName: string): Integer;
|
||||
{var
|
||||
S: TStringList;
|
||||
P: PMPrinter; }
|
||||
begin
|
||||
{S := TStringList.Create;
|
||||
BeginEnumPrinters(S);
|
||||
try
|
||||
Result := S.IndexOf(AName);
|
||||
if Result >= 0 then
|
||||
begin
|
||||
//DebugLn('DoSetPrinter ' + DbgS(Result));
|
||||
//DebugLn('TCocoaPrinter.DoSetPrinter ' + AName + ' ' + DbgS(PrintSession) + ' ' + DbgS(Printers.Objects[Result]));
|
||||
P := PMPrinter(CFArrayGetValueAtIndex(FPrinterArray, Integer(S.Objects[Result])));
|
||||
PMRetain(PMObject(P));
|
||||
if OSError(PMSessionSetCurrentPMPrinter(PrintSession, P),
|
||||
Self, 'DoSetPrinter', 'PMSessionSetCurrentPMPrinter') then
|
||||
raise EPrinter.CreateFmt('The system is unable to select printer "%s"!', [AName]);
|
||||
end;
|
||||
finally
|
||||
EndEnumPrinters;
|
||||
S.Free;
|
||||
end; }
|
||||
end;
|
||||
|
||||
function TCocoaPrinter.DoGetCopies: Integer;
|
||||
var
|
||||
C: UInt32;
|
||||
begin
|
||||
{Result := inherited DoGetCopies;
|
||||
C:=0;
|
||||
if OSError(PMGetCopies(PrintSettings, C), Self, 'DoGetCopies', 'PMGetCopies') then Exit;
|
||||
Result := C; }
|
||||
end;
|
||||
|
||||
procedure TCocoaPrinter.DoSetCopies(AValue: Integer);
|
||||
begin
|
||||
{inherited DoSetCopies(AValue);
|
||||
OSError(PMSetCopies(PrintSettings, AValue, False), Self, 'DoSetCopies', 'PMSetCopies');
|
||||
|
||||
ValidatePrintSettings;}
|
||||
end;
|
||||
|
||||
function TCocoaPrinter.DoGetOrientation: TPrinterOrientation;
|
||||
{var
|
||||
O: PMOrientation; }
|
||||
begin
|
||||
{Result := inherited DoGetOrientation;
|
||||
O:=CleanPMOrientation;
|
||||
if OSError(PMGetOrientation(PageFormat, O), Self, 'DoGetOrientation', 'PMGetOrientation') then Exit;
|
||||
|
||||
case O of
|
||||
kPMPortrait: Result := poPortrait;
|
||||
kPMLandscape: Result := poLandscape;
|
||||
kPMReversePortrait: Result := poReversePortrait;
|
||||
kPMReverseLandscape: Result := poReverseLandscape;
|
||||
end; }
|
||||
end;
|
||||
|
||||
procedure TCocoaPrinter.DoSetOrientation(AValue: TPrinterOrientation);
|
||||
{var
|
||||
O: PMOrientation; }
|
||||
begin
|
||||
{inherited DoSetOrientation(aValue);
|
||||
|
||||
case AValue of
|
||||
poPortrait: O := kPMPortrait;
|
||||
poLandscape: O := kPMLandscape;
|
||||
poReversePortrait: O := kPMReversePortrait;
|
||||
poReverseLandscape: O := kPMReverseLandscape;
|
||||
end;
|
||||
|
||||
OSError(PMSetOrientation(PageFormat, O, kPMUnlocked), Self, 'DoSetOrientation', 'PMSetOrientation');
|
||||
ValidatePageFormat; }
|
||||
end;
|
||||
|
||||
function TCocoaPrinter.GetPrinterType: TPrinterType;
|
||||
var
|
||||
IsRemote: Boolean;
|
||||
begin
|
||||
{ Result := ptLocal;
|
||||
IsRemote:=false;
|
||||
OSError(PMPrinterIsRemote(GetCurrentPrinter,IsRemote), Self, 'GetPrinterType', 'PMPrinterIsRemote');
|
||||
if IsRemote then Result := ptNetwork}
|
||||
end;
|
||||
|
||||
|
||||
function TCocoaPrinter.DoGetPrinterState: TPrinterState;
|
||||
{var
|
||||
State: PMPrinterState;}
|
||||
begin
|
||||
{Result := psNoDefine;
|
||||
|
||||
State:=0;
|
||||
if OSError(PMPrinterGetState(GetCurrentPrinter, State), Self, 'DoGetPrinterState', 'PMPrinterGetState') then Exit;
|
||||
|
||||
case State of
|
||||
kPMPrinterIdle: Result := psReady;
|
||||
kPMPrinterProcessing: Result := psPrinting;
|
||||
kPMPrinterStopped: Result := psStopped;
|
||||
end;}
|
||||
end;
|
||||
|
||||
function TCocoaPrinter.GetCanPrint: Boolean;
|
||||
begin
|
||||
Result := (DoGetPrinterState <> psStopped);
|
||||
end;
|
||||
|
||||
function TCocoaPrinter.GetCanRenderCopies: Boolean;
|
||||
begin
|
||||
Result := True;
|
||||
end;
|
||||
|
||||
initialization
|
||||
|
||||
Printer := TCocoaPrinter.Create;
|
||||
|
||||
finalization
|
||||
|
||||
FreeAndNil(Printer);
|
94
components/printers/cocoa/cocoaprinters_h.inc
Normal file
94
components/printers/cocoa/cocoaprinters_h.inc
Normal file
@ -0,0 +1,94 @@
|
||||
{%MainUnit ../osprinters.pas}
|
||||
uses
|
||||
MacOSAll, CocoaAll,
|
||||
Classes, SysUtils, Printers, LCLType;
|
||||
|
||||
type
|
||||
{ TCocoaPrinterContext }
|
||||
|
||||
TCocoaPrinterContext = class(TObject)
|
||||
{protected
|
||||
function GetSize: TPoint; override;
|
||||
public
|
||||
procedure Release;
|
||||
procedure Reset; override; }
|
||||
end;
|
||||
|
||||
{ TCocoaPrinter }
|
||||
|
||||
TCocoaPrinter = class(TPrinter)
|
||||
private
|
||||
FPrintSession: PMPrintSession;
|
||||
FPrintSettings: PMPrintSettings;
|
||||
FPageFormat: PMPageFormat;
|
||||
FBeginDocumentStatus: OSStatus;
|
||||
FNewPageStatus: OSStatus;
|
||||
FPrinterContext: TCocoaPrinterContext;
|
||||
FPrinterArray: CFArrayRef;
|
||||
FPaperArray: CFArrayRef;
|
||||
FDefaultPrinter: String;
|
||||
|
||||
procedure CreatePrintSession;
|
||||
procedure CreatePrintSettings;
|
||||
function GetCurrentPrinterName: String;
|
||||
|
||||
function CreatePageFormat(APaper: String): PMPageFormat;
|
||||
|
||||
function ValidatePageFormat: Boolean;
|
||||
function ValidatePrintSettings: Boolean;
|
||||
|
||||
procedure BeginPage;
|
||||
procedure EndPage;
|
||||
|
||||
procedure FindDefaultPrinter;
|
||||
procedure BeginEnumPrinters(Lst: TStrings);
|
||||
procedure EndEnumPrinters;
|
||||
procedure BeginEnumPapers(Lst: TStrings);
|
||||
procedure EndEnumPapers;
|
||||
function GetOutputResolution: PMResolution;
|
||||
|
||||
protected
|
||||
procedure DoBeginDoc; override;
|
||||
procedure DoNewPage; override;
|
||||
procedure DoEndDoc(aAborded : Boolean); override;
|
||||
procedure DoAbort; override;
|
||||
|
||||
procedure DoEnumPrinters(Lst : TStrings); override;
|
||||
procedure DoResetPrintersList; override;
|
||||
|
||||
procedure DoEnumPapers(Lst : TStrings); override;
|
||||
function DoGetPaperName: string; override;
|
||||
function DoGetDefaultPaperName: string; override;
|
||||
procedure DoSetPaperName(aName : string); override;
|
||||
function DoGetPaperRect(aName : string; Var aPaperRc : TPaperRect) : Integer; override;
|
||||
|
||||
function DoSetPrinter(aName : string): Integer; override;
|
||||
|
||||
function DoGetCopies : Integer; override;
|
||||
procedure DoSetCopies(aValue : Integer); override;
|
||||
function DoGetOrientation: TPrinterOrientation; override;
|
||||
procedure DoSetOrientation(aValue : TPrinterOrientation); override;
|
||||
|
||||
function GetXDPI: Integer; override;
|
||||
function GetYDPI: Integer; override;
|
||||
function GetPrinterType: TPrinterType;override;
|
||||
function DoGetPrinterState: TPrinterState;override;
|
||||
function GetCanPrint: Boolean;override;
|
||||
function GetCanRenderCopies : Boolean;override;
|
||||
procedure RawModeChanging; override;
|
||||
procedure DoDestroy; override;
|
||||
public
|
||||
procedure Validate;
|
||||
procedure UpdatePrinter;
|
||||
public
|
||||
constructor Create; override;
|
||||
function Write(const {%H-}Buffer; {%H-}Count:Integer; var {%H-}Written: Integer): Boolean; override;
|
||||
// Warning not portable functions here
|
||||
property CurrentPrinterName: String read GetCurrentPrinterName;
|
||||
property PrintSession: PMPrintSession read FPrintSession;
|
||||
property PrintSettings: PMPrintSettings read FPrintSettings;
|
||||
property PageFormat: PMPageFormat read FPageFormat;
|
||||
// Warning it is a not portable property
|
||||
property Handle: TCocoaPrinterContext read FPrinterContext;
|
||||
end;
|
||||
|
118
components/printers/cocoa/cocoaprndialogs.inc
Normal file
118
components/printers/cocoa/cocoaprndialogs.inc
Normal file
@ -0,0 +1,118 @@
|
||||
{%MainUnit ../printersdlgs.pp}
|
||||
|
||||
|
||||
const
|
||||
SExecute = 'Execute';
|
||||
|
||||
{ TPageSetupDialog }
|
||||
|
||||
function TPageSetupDialog.Execute: Boolean;
|
||||
var
|
||||
CocoaPrinter: TCocoaPrinter;
|
||||
begin
|
||||
Result := False;
|
||||
// TODO: set and get paper margins, title
|
||||
|
||||
if not Assigned(Printer) then Exit;
|
||||
|
||||
CocoaPrinter := Printer as TCocoaPrinter;
|
||||
|
||||
{ if OSError(PMSessionPageSetupDialog(CarbonPrinter.PrintSession,
|
||||
CarbonPrinter.PageFormat, Result),
|
||||
Self, SExecute, 'PMSessionPageSetupDialog') then Exit;
|
||||
|
||||
if Result then CarbonPrinter.Validate; }
|
||||
end;
|
||||
|
||||
|
||||
{ TPrinterSetupDialog }
|
||||
|
||||
function TPrinterSetupDialog.Execute: Boolean;
|
||||
begin
|
||||
Result := False;
|
||||
if not Assigned(Printer) then Exit;
|
||||
if Printer.Printers.Count <= 0 then Exit;
|
||||
|
||||
raise Printers.EPrinter.Create('TPrinterSetupDialog is not supported in Cocoa!');
|
||||
end;
|
||||
|
||||
|
||||
{ TPrintDialog }
|
||||
|
||||
function TPrintDialog.Execute: Boolean;
|
||||
{var
|
||||
CarbonPrinter: TCarbonPrinter;
|
||||
DialogSettings: PMPrintSettings;
|
||||
V: UInt32;
|
||||
B: Boolean;
|
||||
PMin, PMax, PFrom, PTo: Integer; }
|
||||
begin
|
||||
{ Result := False;
|
||||
// TODO: Options, Title
|
||||
|
||||
if not Assigned(Printer) then Exit;
|
||||
|
||||
CarbonPrinter := Printer as TCarbonPrinter;
|
||||
//DebugLn('TPrintDialog.Execute ' + CarbonPrinter.CurrentPrinterName);
|
||||
|
||||
DialogSettings:=nil;
|
||||
if OSError(PMCreatePrintSettings(DialogSettings),
|
||||
Self, SExecute, 'PMCreatePrintSettings') then Exit;
|
||||
try
|
||||
if OSError(PMCopyPrintSettings(CarbonPrinter.PrintSettings, DialogSettings),
|
||||
Self, SExecute, 'PMCopyPrintSettings') then Exit;
|
||||
|
||||
OSError(PMSetCollate(DialogSettings, Collate), Self, SExecute, 'PMSetCollate');
|
||||
OSError(PMSetCopies(DialogSettings, Copies, False), Self, SExecute, 'PMSetCopies');
|
||||
|
||||
PMin := MinPage;
|
||||
PMax := Max(PMin, MaxPage);
|
||||
PFrom := Min(Max(FromPage, PMin), PMax);
|
||||
PTo := Max(PFrom, Min(ToPage, PMax));
|
||||
|
||||
OSError(PMSetPageRange(DialogSettings, PMin, PMax),
|
||||
Self, SExecute, 'PMSetPageRange');
|
||||
if PrintRange <> prAllPages then
|
||||
begin
|
||||
OSError(PMSetFirstPage(DialogSettings, PFrom, False), Self, SExecute, 'PMSetFirstPage');
|
||||
OSError(PMSetLastPage(DialogSettings, PTo, False), Self, SExecute, 'PMSetLastPage');
|
||||
end;
|
||||
|
||||
if OSError(PMSessionPrintDialog(CarbonPrinter.PrintSession, DialogSettings, CarbonPrinter.PageFormat, Result),
|
||||
Self, SExecute, 'PMSessionPrintDialog') then Exit;
|
||||
|
||||
if Result then
|
||||
begin
|
||||
B := Collate;
|
||||
OSError(PMGetCollate(DialogSettings, B), Self, SExecute, 'PMGetCollate');
|
||||
Collate := B;
|
||||
|
||||
V := Copies;
|
||||
OSError(PMGetCopies(DialogSettings, V), Self, SExecute, 'PMGetCopies');
|
||||
Copies := V;
|
||||
|
||||
OSError(PMGetLastPage(DialogSettings, V), Self, SExecute, 'PMGetLastPage');
|
||||
if V > $FFFF then
|
||||
begin
|
||||
PrintRange := prAllPages;
|
||||
FromPage := PMin;
|
||||
ToPage := PMax;
|
||||
end
|
||||
else
|
||||
begin
|
||||
PrintRange := prSelection;
|
||||
ToPage := V;
|
||||
OSError(PMGetFirstPage(DialogSettings, V), Self, SExecute, 'PMGetFirstPage');
|
||||
FromPage := V;
|
||||
end;
|
||||
|
||||
if OSError(PMCopyPrintSettings(DialogSettings, CarbonPrinter.PrintSettings),
|
||||
Self, SExecute, 'PMCopyPrintSettings') then Exit;
|
||||
|
||||
CarbonPrinter.UpdatePrinter;
|
||||
end;
|
||||
finally
|
||||
PMRelease(PMObject(DialogSettings));
|
||||
end; }
|
||||
end;
|
||||
|
@ -30,11 +30,19 @@ interface
|
||||
|
||||
|
||||
{$IFDEF UNIX}
|
||||
{$IFDEF LCLCarbon}
|
||||
{$IFNDEF NativePrint}
|
||||
{$I cupsprinters_h.inc}
|
||||
{$ELSE}
|
||||
{$I carbonprinters_h.inc}
|
||||
{$IFDEF DARWIN}
|
||||
{$IFDEF LCLCarbon}
|
||||
{$IFNDEF NativePrint}
|
||||
{$I cupsprinters_h.inc}
|
||||
{$ELSE}
|
||||
{$I carbonprinters_h.inc}
|
||||
{$ENDIF}
|
||||
{$ENDIF}
|
||||
{$IFDEF LCLCocoa}
|
||||
{$I cocoaprinters_h.inc}
|
||||
{$ENDIF}
|
||||
{$IFDEF LCLQt}
|
||||
{$I qtprinters_h.inc}
|
||||
{$ENDIF}
|
||||
{$ELSE}
|
||||
{$IFDEF LCLQt}
|
||||
@ -56,11 +64,19 @@ interface
|
||||
implementation
|
||||
|
||||
{$IFDEF UNIX}
|
||||
{$IFDEF LCLCarbon}
|
||||
{$IFNDEF NativePrint}
|
||||
{$I cupsprinters.inc}
|
||||
{$ELSE}
|
||||
{$I carbonprinters.inc}
|
||||
{$IFDEF DARWIN}
|
||||
{$IFDEF LCLCarbon}
|
||||
{$IFNDEF NativePrint}
|
||||
{$I cupsprinters.inc}
|
||||
{$ELSE}
|
||||
{$I carbonprinters.inc}
|
||||
{$ENDIF}
|
||||
{$ENDIF}
|
||||
{$IFDEF LCLCocoa}
|
||||
{$I cocoaprinters.inc}
|
||||
{$ENDIF}
|
||||
{$IFDEF LCLQt}
|
||||
{$I qtprinters.inc}
|
||||
{$ENDIF}
|
||||
{$ELSE}
|
||||
{$IFDEF LCLQt}
|
||||
|
@ -3,14 +3,15 @@
|
||||
<Package Version="4">
|
||||
<PathDelim Value="\"/>
|
||||
<Name Value="Printer4Lazarus"/>
|
||||
<Type Value="RunAndDesignTime"/>
|
||||
<AddToProjectUsesSection Value="True"/>
|
||||
<Author Value="Olivier Guilbaud"/>
|
||||
<CompilerOptions>
|
||||
<Version Value="11"/>
|
||||
<PathDelim Value="\"/>
|
||||
<SearchPaths>
|
||||
<IncludeFiles Value="unix;win32;carbon;qt"/>
|
||||
<OtherUnitFiles Value="unix;win32;carbon;qt"/>
|
||||
<IncludeFiles Value="unix;win32;carbon;qt;cocoa"/>
|
||||
<OtherUnitFiles Value="unix;win32;carbon;qt;cocoa"/>
|
||||
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)\$(LCLWidgetType)"/>
|
||||
</SearchPaths>
|
||||
<Parsing>
|
||||
@ -29,7 +30,7 @@
|
||||
<License Value="LGPL
|
||||
"/>
|
||||
<Version Minor="5"/>
|
||||
<Files Count="33">
|
||||
<Files Count="36">
|
||||
<Item1>
|
||||
<Filename Value="printersdlgs.pp"/>
|
||||
<HasRegisterProc Value="True"/>
|
||||
@ -121,60 +122,71 @@
|
||||
<UnitName Value="CarbonPrinting"/>
|
||||
</Item21>
|
||||
<Item22>
|
||||
<Filename Value="qt\qtprndialogs.inc"/>
|
||||
<Filename Value="cocoa\cocoaprinters.inc"/>
|
||||
<Type Value="Include"/>
|
||||
</Item22>
|
||||
<Item23>
|
||||
<Filename Value="qt\qtprinters_h.inc"/>
|
||||
<Filename Value="cocoa\cocoaprinters_h.inc"/>
|
||||
<Type Value="Include"/>
|
||||
</Item23>
|
||||
<Item24>
|
||||
<Filename Value="qt\qtprinters.inc"/>
|
||||
<Filename Value="cocoa\cocoaprndialogs.inc"/>
|
||||
<Type Value="Include"/>
|
||||
</Item24>
|
||||
<Item25>
|
||||
<Filename Value="carbon\issues.xml"/>
|
||||
<Type Value="Issues"/>
|
||||
<Filename Value="qt\qtprndialogs.inc"/>
|
||||
<Type Value="Include"/>
|
||||
</Item25>
|
||||
<Item26>
|
||||
<Filename Value="unix\udlgpagesetup.lfm"/>
|
||||
<Type Value="LFM"/>
|
||||
<Filename Value="qt\qtprinters_h.inc"/>
|
||||
<Type Value="Include"/>
|
||||
</Item26>
|
||||
<Item27>
|
||||
<Filename Value="qt\qtprinters.inc"/>
|
||||
<Type Value="Include"/>
|
||||
</Item27>
|
||||
<Item28>
|
||||
<Filename Value="carbon\issues.xml"/>
|
||||
<Type Value="Issues"/>
|
||||
</Item28>
|
||||
<Item29>
|
||||
<Filename Value="unix\udlgpagesetup.lfm"/>
|
||||
<Type Value="LFM"/>
|
||||
</Item29>
|
||||
<Item30>
|
||||
<Filename Value="unix\udlgpagesetup.pas"/>
|
||||
<AddToUsesPkgSection Value="False"/>
|
||||
<UnitName Value="udlgpagesetup"/>
|
||||
</Item27>
|
||||
<Item28>
|
||||
</Item30>
|
||||
<Item31>
|
||||
<Filename Value="unix\framepagesetup.lfm"/>
|
||||
<Type Value="LFM"/>
|
||||
</Item28>
|
||||
<Item29>
|
||||
</Item31>
|
||||
<Item32>
|
||||
<Filename Value="unix\framepagesetup.pas"/>
|
||||
<AddToUsesPkgSection Value="False"/>
|
||||
<UnitName Value="framePageSetup"/>
|
||||
</Item29>
|
||||
<Item30>
|
||||
</Item32>
|
||||
<Item33>
|
||||
<Filename Value="unix\frameprinterselector.lfm"/>
|
||||
<Type Value="LFM"/>
|
||||
</Item30>
|
||||
<Item31>
|
||||
</Item33>
|
||||
<Item34>
|
||||
<Filename Value="unix\frameprinterselector.pas"/>
|
||||
<AddToUsesPkgSection Value="False"/>
|
||||
<UnitName Value="frameprinterselector"/>
|
||||
</Item31>
|
||||
<Item32>
|
||||
</Item34>
|
||||
<Item35>
|
||||
<Filename Value="unix\udlgprintersetup.pas"/>
|
||||
<AddToUsesPkgSection Value="False"/>
|
||||
<UnitName Value="udlgprintersetup"/>
|
||||
</Item32>
|
||||
<Item33>
|
||||
</Item35>
|
||||
<Item36>
|
||||
<Filename Value="unix\cupslcl.pas"/>
|
||||
<AddToUsesPkgSection Value="False"/>
|
||||
<UnitName Value="cupslcl"/>
|
||||
</Item33>
|
||||
</Item36>
|
||||
</Files>
|
||||
<Type Value="RunAndDesignTime"/>
|
||||
<RequiredPkgs Count="1">
|
||||
<Item1>
|
||||
<PackageName Value="cairocanvas_pkg"/>
|
||||
|
@ -70,30 +70,33 @@ implementation
|
||||
{$R printersdlgs.res}
|
||||
|
||||
{$IFDEF UNIX}
|
||||
{$IFDEF LCLCarbon}
|
||||
{$IFNDEF NativePrint}
|
||||
|
||||
// add units as needed for carbon, for the moment use cups ones.
|
||||
uses Controls, udlgSelectPrinter, udlgPropertiesPrinter, FileUtil;
|
||||
{$I cupsprndialogs.inc}
|
||||
|
||||
{$ELSE}
|
||||
|
||||
uses
|
||||
Controls, Math, CarbonProc,
|
||||
MacOSAll,
|
||||
LCLProc;
|
||||
{$I carbonprndialogs.inc}
|
||||
|
||||
{$IFDEF DARWIN}
|
||||
{$IFDEF LCLCarbon}
|
||||
{$IFNDEF NativePrint}
|
||||
// add units as needed for carbon, for the moment use cups ones.
|
||||
uses Controls, udlgSelectPrinter, udlgPropertiesPrinter, FileUtil;
|
||||
{$I cupsprndialogs.inc}
|
||||
{$ELSE}
|
||||
uses Controls, Math, CarbonProc, MacOSAll, LCLProc;
|
||||
{$I carbonprndialogs.inc}
|
||||
{$ENDIF}
|
||||
{$ENDIF}
|
||||
{$IFDEF LCLCocoa}
|
||||
uses Controls, Math, CocoaAll, MacOSAll, LCLProc;
|
||||
{$I cocoaprndialogs.inc}
|
||||
{$ENDIF}
|
||||
{$IFDEF LCLQt}
|
||||
uses Controls, qtobjects, qt4, qtint, FileUtil;
|
||||
{$I qtprndialogs.inc}
|
||||
{$ENDIF}
|
||||
{$ELSE}
|
||||
{$IFDEF LCLQt}
|
||||
uses Controls, qtobjects, qt4, qtint, FileUtil;
|
||||
{$I qtprndialogs.inc}
|
||||
{$ELSE}
|
||||
uses Controls, udlgSelectPrinter, udlgPropertiesPrinter, udlgPageSetup, FileUtil;
|
||||
{$I cupsprndialogs.inc}
|
||||
{$ENDIF}
|
||||
uses Controls, qtobjects, qt4, qtint, FileUtil;
|
||||
{$I qtprndialogs.inc}
|
||||
{$ELSE}
|
||||
uses Controls, udlgSelectPrinter, udlgPropertiesPrinter, udlgPageSetup, FileUtil;
|
||||
{$I cupsprndialogs.inc}
|
||||
{$ENDIF}
|
||||
{$ENDIF}
|
||||
{$ENDIF}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user