lcl: carbon: clean up

git-svn-id: trunk@38553 -
This commit is contained in:
mattias 2012-09-07 09:25:37 +00:00
parent cbec8ef585
commit 23d713f7b5
6 changed files with 28 additions and 8 deletions

View File

@ -1,5 +1,5 @@
aarreupdatelist aarreupdatelist
This tool is under construction. This tool is under construction.
It's goal is to scan a directory and gather information of all lpk files. The goal is to scan a directory and gather information of all lpk files.

View File

@ -15,6 +15,7 @@ begin
Result.Y := 0; Result.Y := 0;
if Printer = nil then Exit; if Printer = nil then Exit;
R:=CleanPMRect;
if OSError(PMGetAdjustedPaperRect((Printer as TCarbonPrinter).PageFormat, R), if OSError(PMGetAdjustedPaperRect((Printer as TCarbonPrinter).PageFormat, R),
Self, 'GetSize', 'PMGetUnadjustedPaperRect') then Exit; Self, 'GetSize', 'PMGetUnadjustedPaperRect') then Exit;
@ -80,6 +81,7 @@ begin
try try
if I < 0 then if I < 0 then
begin begin
Result:=nil;
if OSError(PMCreatePageFormat(Result), Self, SName, 'PMCreatePageFormat') then if OSError(PMCreatePageFormat(Result), Self, SName, 'PMCreatePageFormat') then
raise EPrinter.Create('Error initializing printing for Carbon: Unable to create page format!'); raise EPrinter.Create('Error initializing printing for Carbon: Unable to create page format!');
@ -117,6 +119,7 @@ end;
function TCarbonPrinter.GetCurrentPrinter: PMPrinter; function TCarbonPrinter.GetCurrentPrinter: PMPrinter;
begin begin
Result:=nil;
OSError(PMSessionGetCurrentPrinter(PrintSession, Result), Self, 'GetCurrentPrinter', 'PMSessionGetCurrentPrinter'); OSError(PMSessionGetCurrentPrinter(PrintSession, Result), Self, 'GetCurrentPrinter', 'PMSessionGetCurrentPrinter');
end; end;
@ -168,6 +171,7 @@ var
I, C: CFIndex; I, C: CFIndex;
pa: CFArrayRef; pa: CFArrayRef;
begin begin
pa:=nil;
if OSError(PMServerCreatePrinterList(kPMServerLocal, pa), if OSError(PMServerCreatePrinterList(kPMServerLocal, pa),
Self, 'DoEnumPrinters', 'PMServerCreatePrinterList') then Exit; Self, 'DoEnumPrinters', 'PMServerCreatePrinterList') then Exit;
@ -232,6 +236,7 @@ begin
for I := 0 to C - 1 do for I := 0 to C - 1 do
begin begin
P := CFArrayGetValueAtIndex(FPaperArray, I); P := CFArrayGetValueAtIndex(FPaperArray, I);
CFString:=nil;
if OSError(PMPaperGetName(P, CFString), Self, SName, 'PMPaperGetName') then Continue; if OSError(PMPaperGetName(P, CFString), Self, SName, 'PMPaperGetName') then Continue;
PaperName := CFStringToStr(CFString); PaperName := CFStringToStr(CFString);
//MacOSX 10.4 returns wrong paper name in case of US Letter. //MacOSX 10.4 returns wrong paper name in case of US Letter.
@ -389,8 +394,10 @@ const
SName = 'DoGetPaperName'; SName = 'DoGetPaperName';
begin begin
Result := ''; Result := '';
P:=nil;
if OSError(PMGetPageFormatPaper(PageFormat, P), Self, SName, 'PMGetPageFormatPaper') then Exit; if OSError(PMGetPageFormatPaper(PageFormat, P), Self, SName, 'PMGetPageFormatPaper') then Exit;
CFString:=nil;
if OSError(PMPaperGetName(P, CFString), Self, SName, 'PMPaperGetName') then Exit; if OSError(PMPaperGetName(P, CFString), Self, SName, 'PMPaperGetName') then Exit;
Result := CFStringToStr(CFString); Result := CFStringToStr(CFString);
@ -440,18 +447,22 @@ begin
T := CreatePageFormat(AName); T := CreatePageFormat(AName);
try try
// copy scale // copy scale
S:=0.0;
OSError(PMGetScale(PageFormat, S), Self, SName, 'PMGetScale'); OSError(PMGetScale(PageFormat, S), Self, SName, 'PMGetScale');
OSError(PMSetScale(T, S), Self, SName, 'PMSetScale'); OSError(PMSetScale(T, S), Self, SName, 'PMSetScale');
// copy orientation // copy orientation
O:=CleanPMOrientation;
OSError(PMGetOrientation(PageFormat, O), Self, SName, 'PMGetOrientation'); OSError(PMGetOrientation(PageFormat, O), Self, SName, 'PMGetOrientation');
OSError(PMSetOrientation(T, O, False), Self, SName, 'PMSetOrientation'); OSError(PMSetOrientation(T, O, False), Self, SName, 'PMSetOrientation');
// update // update
OSError(PMSessionValidatePageFormat(PrintSession, T, nil), OSError(PMSessionValidatePageFormat(PrintSession, T, nil),
Self, SName, 'PMSessionValidatePageFormat'); Self, SName, 'PMSessionValidatePageFormat');
PaperRect:=CleanPMRect;
OSError(PMGetAdjustedPaperRect(T, PaperRect), Self, SName, 'PMGetAdjustedPaperRect'); OSError(PMGetAdjustedPaperRect(T, PaperRect), Self, SName, 'PMGetAdjustedPaperRect');
PageRect:=CleanPMRect;
OSError(PMGetAdjustedPageRect(T, PageRect), Self, SName, 'PMGetAdjustedPageRect'); OSError(PMGetAdjustedPageRect(T, PageRect), Self, SName, 'PMGetAdjustedPageRect');
finally finally
PMRelease(PMObject(T)); PMRelease(PMObject(T));
@ -502,6 +513,7 @@ var
C: UInt32; C: UInt32;
begin begin
Result := inherited DoGetCopies; Result := inherited DoGetCopies;
C:=0;
if OSError(PMGetCopies(PrintSettings, C), Self, 'DoGetCopies', 'PMGetCopies') then Exit; if OSError(PMGetCopies(PrintSettings, C), Self, 'DoGetCopies', 'PMGetCopies') then Exit;
Result := C; Result := C;
end; end;
@ -519,6 +531,7 @@ var
O: PMOrientation; O: PMOrientation;
begin begin
Result := inherited DoGetOrientation; Result := inherited DoGetOrientation;
O:=CleanPMOrientation;
if OSError(PMGetOrientation(PageFormat, O), Self, 'DoGetOrientation', 'PMGetOrientation') then Exit; if OSError(PMGetOrientation(PageFormat, O), Self, 'DoGetOrientation', 'PMGetOrientation') then Exit;
case O of case O of
@ -551,6 +564,7 @@ var
IsRemote: Boolean; IsRemote: Boolean;
begin begin
Result := ptLocal; Result := ptLocal;
IsRemote:=false;
OSError(PMPrinterIsRemote(GetCurrentPrinter,IsRemote), Self, 'GetPrinterType', 'PMPrinterIsRemote'); OSError(PMPrinterIsRemote(GetCurrentPrinter,IsRemote), Self, 'GetPrinterType', 'PMPrinterIsRemote');
if IsRemote then Result := ptNetwork if IsRemote then Result := ptNetwork
end; end;
@ -561,7 +575,8 @@ var
State: PMPrinterState; State: PMPrinterState;
begin begin
Result := psNoDefine; Result := psNoDefine;
State:=0;
if OSError(PMPrinterGetState(GetCurrentPrinter, State), Self, 'DoGetPrinterState', 'PMPrinterGetState') then Exit; if OSError(PMPrinterGetState(GetCurrentPrinter, State), Self, 'DoGetPrinterState', 'PMPrinterGetState') then Exit;
case State of case State of

View File

@ -81,7 +81,7 @@ type
public public
constructor Create; override; constructor Create; override;
destructor Destroy; override; destructor Destroy; override;
function Write(const Buffer; Count:Integer; var Written: Integer): Boolean; override; function Write(const {%H-}Buffer; {%H-}Count:Integer; var {%H-}Written: Integer): Boolean; override;
// Warning not portable functions here // Warning not portable functions here
property CurrentPrinterName: String read GetCurrentPrinterName; property CurrentPrinterName: String read GetCurrentPrinterName;
property PrintSession: PMPrintSession read FPrintSession; property PrintSession: PMPrintSession read FPrintSession;

View File

@ -43,7 +43,7 @@ function TPrintDialog.Execute: Boolean;
var var
CarbonPrinter: TCarbonPrinter; CarbonPrinter: TCarbonPrinter;
DialogSettings: PMPrintSettings; DialogSettings: PMPrintSettings;
U, V: UInt32; V: UInt32;
B: Boolean; B: Boolean;
PMin, PMax, PFrom, PTo: Integer; PMin, PMax, PFrom, PTo: Integer;
begin begin
@ -54,7 +54,8 @@ begin
CarbonPrinter := Printer as TCarbonPrinter; CarbonPrinter := Printer as TCarbonPrinter;
//DebugLn('TPrintDialog.Execute ' + CarbonPrinter.CurrentPrinterName); //DebugLn('TPrintDialog.Execute ' + CarbonPrinter.CurrentPrinterName);
DialogSettings:=nil;
if OSError(PMCreatePrintSettings(DialogSettings), if OSError(PMCreatePrintSettings(DialogSettings),
Self, SExecute, 'PMCreatePrintSettings') then Exit; Self, SExecute, 'PMCreatePrintSettings') then Exit;
try try

View File

@ -38,6 +38,10 @@ uses
Classes, SysUtils, Types, LCLType, LCLProc, Classes, SysUtils, Types, LCLType, LCLProc,
Controls, Forms, Graphics, Math, GraphType; Controls, Forms, Graphics, Math, GraphType;
const
CleanPMRect: PMRect = (top: 0; left: 0; bottom: 0; right: 0);
CleanPMOrientation: PMOrientation = 0;
function OSError(AResult: OSStatus; const AMethodName, ACallName: String; function OSError(AResult: OSStatus; const AMethodName, ACallName: String;
const AText: String = ''): Boolean; const AText: String = ''): Boolean;
function OSError(AResult: OSStatus; const AObject: TObject; const AMethodName, ACallName: String; function OSError(AResult: OSStatus; const AObject: TObject; const AMethodName, ACallName: String;

View File

@ -3098,7 +3098,7 @@ const
var var
ACtl: TCarbonControl; ACtl: TCarbonControl;
R, R1: CGRect; R, R1: CGRect;
RR: TRect; {%H-}RR: TRect;
begin begin
{$IFDEF VerboseWinAPI} {$IFDEF VerboseWinAPI}
DebugLn('TCarbonWidgetSet.ScrollWindowEx() HWnd=',dbgs(hWnd),' prcScroll ',prcScroll <> nil, DebugLn('TCarbonWidgetSet.ScrollWindowEx() HWnd=',dbgs(hWnd),' prcScroll ',prcScroll <> nil,