Printers, Added default list of papers in case there are no printers, fixes to cups dialogs

git-svn-id: trunk@23779 -
This commit is contained in:
jesus 2010-02-24 21:21:37 +00:00
parent 84db565553
commit dc2a5b26a1
7 changed files with 239 additions and 225 deletions

View File

@ -32,6 +32,9 @@ begin
combo.Tag:=-1;
combo.Enabled:=false;
if THackCUPSPrinter(Printer).CupsPPD=nil then
exit;
if Option=nil then
begin
if OptionStr='' then

View File

@ -48,8 +48,6 @@ end;
destructor TCUPSPrinter.destroy;
begin
SetLength(FPapers, 0);
if assigned(fRawModeStream) then
fRawModeStream.Free;
@ -185,83 +183,6 @@ begin
end;
end;
// adds a list of known papers
procedure TCUPSPrinter.CreatePapers;
procedure add(AnIndex:Integer; aname:string; aPhysRect,aWrkRect:TRect);
begin
with fPapers[AnIndex] do begin
PaperName := aName;
PhysicalRect := aPhysRect;
WorkRect := aWrkRect;
WinCode:= 0;
end;
end;
function PRRect(const ALeft,ATop,ARight,ABottom: Integer): TRect;
begin
Result.Left := ALeft;
Result.Top := ATop;
Result.Right := round(ARight * Printer.XDPI / 72);
Result.Bottom := round(ABottom * Printer.XDPI / 72);
end;
begin
SetLength(fPapers, 3);
add(0, 'Letter', PRRect(0, 0, 612, 792 ), PRRect(0, 0, 612, 792 ));
add(1, 'A4', PRRect(0, 0, 595, 892 ), PRRect(0, 0, 595, 892 ));
add(2, 'Legal', PRRect(0, 0, 612, 1008), PRRect(0, 0, 612, 1008));
end;
function TCUPSPrinter.IndexOfPaper(aPaperName: string): integer;
var
i: Integer;
begin
result := -1;
for i:=0 to Length(fPapers)-1 do
if CompareText(fPapers[i].PaperName, aPapername)=0 then begin
result := i;
break;
end;
end;
function TCUPSPrinter.InternalGetDefPaperName: string;
begin
if Length(Fpapers)=0 then
CreatePapers;
result := fPapers[0].PaperName;
end;
function TCUPSPrinter.InternalGetCurPaperName: string;
begin
if Length(fPapers)=0 then
CreatePapers;
result := fPapers[fCurrentPaper].PaperName;
end;
procedure TCUPSPrinter.InternalGetPaperRect(aPaperName:string;
var PaperRect:TPaperRect);
var
i: LongInt;
begin
if Length(fPapers)=0 then
CreatePapers;
i := IndexOfPaper(aPaperName);
if i<0 then
i := FCurrentPaper;
with fPapers[i] do
if orientation in [poPortrait, poReversePortrait] then begin
PaperRect.PhysicalRect := PhysicalRect;
PaperRect.WorkRect := WorkRect;
end else begin
PaperRect.PhysicalRect.Right := PhysicalRect.Bottom;
PaperRect.Physicalrect.Bottom := PhysicalRect.Right;
PaperRect.WorkRect.Left := WorkRect.Top;
PaperRect.WorkRect.Top := PhysicalRect.Right-WorkRect.Right;
PaperRect.WorkRect.Right := WorkRect.Bottom;
PaperRect.WorkRect.Bottom := PhysicalRect.Right-Workrect.Left;
end;
end;
function TCUPSPrinter.CupsPapersListValid: boolean;
var
Lst: TStringlist;
@ -884,6 +805,10 @@ Var i,Num : Integer;
P : Pcups_dest_t;
begin
inherited DoEnumPrinters(Lst);
{$IFDEF NOPRINTERS}
Lst.Clear;
Exit;
{$ENDIF}
if not CUPSLibInstalled then Exit;
Num:=cupsGetDests(@fcupsPrinters);
@ -902,8 +827,6 @@ begin
end;
procedure TCUPSPrinter.DoEnumPapers(Lst: TStrings);
var
i: Integer;
begin
//DebugLn(['TCUPSPrinter.DoEnumPapers ',dbgsName(Self)]);
inherited DoEnumPapers(Lst);
@ -911,15 +834,6 @@ begin
GetEnumAttributeString('media-supported',Lst);
fCupsPapersCount := lst.Count;
if FCupsPapersCount=0 then begin
// printer doesn't support attribute media-supported, return
// our printer list
if Length(FPapers)=0 then
CreatePapers;
for i:=0 to Length(fPapers)-1 do
lst.Add(fPapers[i].PaperName);
fCurrentPaper := 0;
end;
end;
function TCUPSPrinter.DoSetPrinter(aName: string): Integer;
@ -1065,7 +979,7 @@ begin
if not (cpsDefaultPaperNameValid in FStates) then begin
fCachedGetDefaultPaperName:=inherited DoGetDefaultPaperName;
if not CupsPapersListValid then
FCachedGetDefaultPaperName:=InternalGetDefPaperName
FCachedGetDefaultPaperName:=PaperSize.DefaultPaperName
else begin
fCachedGetDefaultPaperName:=
GetAttributeString('media-default',fCachedGetDefaultPaperName);
@ -1083,7 +997,7 @@ begin
// paper is not yet retrieved for first time
// first try to see if there is a list of papers available
if not CupsPapersListValid then
fCachedPaperName := InternalGetCurPaperName
FCachedPaperName := PaperSize.PaperName
else begin
fCachedPaperName := cupsGetOption('PageSize');
{$IFDEF UseCache}
@ -1095,8 +1009,6 @@ begin
end;
procedure TCUPSPrinter.DoSetPaperName(aName: string);
var
i: Integer;
begin
{$IFDEF UseCache}
if aName=DoGetPaperName then exit;
@ -1104,11 +1016,9 @@ begin
{$ENDIF}
inherited DoSetPaperName(aName);
if FCupsPapersCount<=0 then begin
i := IndexOfPaper(aName);
if i>=0 then
fCurrentPaper := i;
end else
if FCupsPapersCount<=0 then
PaperSize.PaperName:=AName
else
cupsAddOption('PageSize',aName)
end;
@ -1224,8 +1134,7 @@ begin
end;
if P=nil then begin
// FCachePaperRect couldn't be determined, use our internal list
InternalGetPaperRect(aName, FCachePaperRect);
FCachePaperRect := PaperSize.PaperRectOf[AName];
fCachePaperRectResult:=1
end;

View File

@ -67,14 +67,7 @@ type
cpsResolutionValid
);
TCUPSPrinterStates = set of TCUPSPrinterState;
TPaperItem = record
PaperName: string[40];
PhysicalRect: TRect;
WorkRect: TRect;
WinCode: Integer;
end;
{ TCUPSPrinter }
TCUPSPrinter = Class(TPrinter)
@ -103,14 +96,7 @@ type
procedure DoCupsConnect;
private
fPapers: array of TPaperItem;
fCupsPapersCount: Integer;
fCurrentPaper: Integer;
procedure CreatePapers;
function IndexOfPaper(aPaperName: string): integer;
function InternalGetDefPaperName: string;
function InternalGetCurPaperName: string;
procedure InternalGetPaperRect(aPaperName:string; var PaperRect:TPaperRect);
function CupsPapersListValid: boolean;
function InternalGetResolution(ForX: boolean): Integer;
{$IFDEF DebugCUPS}

View File

@ -3,37 +3,37 @@ object framePageSetup: TframePageSetup
Height = 435
Top = 0
Width = 403
ClientHeight = 431
ClientWidth = 399
ClientHeight = 435
ClientWidth = 403
TabOrder = 0
DesignLeft = 427
DesignTop = 126
DesignLeft = 388
DesignTop = 96
object panSetup: TPanel
Left = 0
Height = 211
Top = 220
Width = 399
Top = 224
Width = 403
Align = alBottom
BevelOuter = bvNone
ClientHeight = 211
ClientWidth = 399
ClientWidth = 403
TabOrder = 0
object gpPaper: TGroupBox
Left = 6
Height = 98
Top = 6
Width = 387
Width = 391
Align = alTop
BorderSpacing.Around = 6
Caption = 'Paper'
ClientHeight = 81
ClientWidth = 383
ClientWidth = 387
TabOrder = 0
object lblPaper: TLabel
Left = 14
Height = 16
Top = 11
Width = 41
Width = 39
Caption = 'Paper:'
ParentColor = False
end
@ -41,7 +41,7 @@ object framePageSetup: TframePageSetup
Left = 14
Height = 16
Top = 51
Width = 49
Width = 46
Caption = 'Source:'
ParentColor = False
end
@ -49,11 +49,9 @@ object framePageSetup: TframePageSetup
Left = 78
Height = 29
Top = 3
Width = 298
Width = 302
Anchors = [akTop, akLeft, akRight]
AutoComplete = False
ItemHeight = 0
ItemWidth = 0
OnChange = cbPaperChange
Style = csDropDownList
TabOrder = 0
@ -62,11 +60,9 @@ object framePageSetup: TframePageSetup
Left = 78
Height = 29
Top = 43
Width = 298
Width = 302
Anchors = [akTop, akLeft, akRight]
AutoComplete = False
ItemHeight = 0
ItemWidth = 0
Style = csDropDownList
TabOrder = 1
end
@ -84,9 +80,9 @@ object framePageSetup: TframePageSetup
TabOrder = 1
object radPortrait: TRadioButton
Left = 14
Height = 22
Height = 21
Top = 14
Width = 71
Width = 65
Caption = 'Portrait'
Checked = True
OnClick = radPortraitClick
@ -95,9 +91,9 @@ object framePageSetup: TframePageSetup
end
object radLandscape: TRadioButton
Left = 14
Height = 22
Height = 21
Top = 44
Width = 92
Width = 86
Caption = 'Landscape'
OnClick = radPortraitClick
TabOrder = 1
@ -108,19 +104,19 @@ object framePageSetup: TframePageSetup
Left = 132
Height = 95
Top = 110
Width = 261
Width = 265
Align = alClient
BorderSpacing.Around = 6
Caption = 'Margins'
ClientHeight = 78
ClientWidth = 257
ClientWidth = 261
TabOrder = 2
object panMargins: TPanel
AnchorSideLeft.Control = gpMargins
AnchorSideLeft.Side = asrCenter
AnchorSideTop.Control = gpMargins
AnchorSideTop.Side = asrCenter
Left = 4
Left = 6
Height = 72
Top = 3
Width = 249
@ -132,7 +128,7 @@ object framePageSetup: TframePageSetup
Left = 127
Height = 16
Top = 50
Width = 50
Width = 47
Caption = 'Bottom:'
ParentColor = False
end
@ -140,7 +136,7 @@ object framePageSetup: TframePageSetup
Left = 6
Height = 16
Top = 48
Width = 26
Width = 25
Caption = 'Top:'
ParentColor = False
end
@ -148,7 +144,7 @@ object framePageSetup: TframePageSetup
Left = 127
Height = 16
Top = 14
Width = 37
Width = 35
Caption = 'Right:'
ParentColor = False
end
@ -156,34 +152,34 @@ object framePageSetup: TframePageSetup
Left = 6
Height = 16
Top = 14
Width = 28
Width = 26
Caption = 'Left:'
ParentColor = False
end
object txtBottom: TEdit
Left = 183
Height = 23
Height = 25
Top = 43
Width = 64
TabOrder = 0
end
object txtTop: TEdit
Left = 40
Height = 23
Height = 25
Top = 43
Width = 56
TabOrder = 1
end
object txtRight: TEdit
Left = 183
Height = 23
Height = 25
Top = 7
Width = 64
TabOrder = 2
end
object txtLeft: TEdit
Left = 40
Height = 23
Height = 25
Top = 7
Width = 56
TabOrder = 3
@ -194,13 +190,13 @@ object framePageSetup: TframePageSetup
object panPreview: TPanel
AnchorSideTop.Control = panSetup
Left = 0
Height = 220
Height = 224
Top = 0
Width = 399
Width = 403
Align = alClient
BevelOuter = bvNone
ClientHeight = 220
ClientWidth = 399
ClientHeight = 224
ClientWidth = 403
Constraints.MinHeight = 142
TabOrder = 1
OnMouseDown = pbPreviewMouseDown
@ -210,9 +206,9 @@ object framePageSetup: TframePageSetup
AnchorSideLeft.Side = asrCenter
AnchorSideTop.Control = panPreview
AnchorSideTop.Side = asrCenter
Left = 149
Left = 151
Height = 130
Top = 45
Top = 47
Width = 100
OnMouseDown = pbPreviewMouseDown
OnMouseWheelDown = pbPreviewMouseWheelDown

View File

@ -2,58 +2,57 @@
LazarusResources.Add('TframePageSetup','FORMDATA',[
'TPF0'#15'TframePageSetup'#14'framePageSetup'#4'Left'#2#0#6'Height'#3#179#1#3
+'Top'#2#0#5'Width'#3#147#1#12'ClientHeight'#3#175#1#11'ClientWidth'#3#143#1#8
+'TabOrder'#2#0#10'DesignLeft'#3#171#1#9'DesignTop'#2'~'#0#6'TPanel'#8'panSet'
+'up'#4'Left'#2#0#6'Height'#3#211#0#3'Top'#3#220#0#5'Width'#3#143#1#5'Align'#7
+'Top'#2#0#5'Width'#3#147#1#12'ClientHeight'#3#179#1#11'ClientWidth'#3#147#1#8
+'TabOrder'#2#0#10'DesignLeft'#3#132#1#9'DesignTop'#2'`'#0#6'TPanel'#8'panSet'
+'up'#4'Left'#2#0#6'Height'#3#211#0#3'Top'#3#224#0#5'Width'#3#147#1#5'Align'#7
+#8'alBottom'#10'BevelOuter'#7#6'bvNone'#12'ClientHeight'#3#211#0#11'ClientWi'
+'dth'#3#143#1#8'TabOrder'#2#0#0#9'TGroupBox'#7'gpPaper'#4'Left'#2#6#6'Height'
+#2'b'#3'Top'#2#6#5'Width'#3#131#1#5'Align'#7#5'alTop'#20'BorderSpacing.Aroun'
+'d'#2#6#7'Caption'#6#5'Paper'#12'ClientHeight'#2'Q'#11'ClientWidth'#3''#1#8
+'dth'#3#147#1#8'TabOrder'#2#0#0#9'TGroupBox'#7'gpPaper'#4'Left'#2#6#6'Height'
+#2'b'#3'Top'#2#6#5'Width'#3#135#1#5'Align'#7#5'alTop'#20'BorderSpacing.Aroun'
+'d'#2#6#7'Caption'#6#5'Paper'#12'ClientHeight'#2'Q'#11'ClientWidth'#3#131#1#8
+'TabOrder'#2#0#0#6'TLabel'#8'lblPaper'#4'Left'#2#14#6'Height'#2#16#3'Top'#2
+#11#5'Width'#2')'#7'Caption'#6#6'Paper:'#11'ParentColor'#8#0#0#6'TLabel'#9'l'
+'blSource'#4'Left'#2#14#6'Height'#2#16#3'Top'#2'3'#5'Width'#2'1'#7'Caption'#6
+#7'Source:'#11'ParentColor'#8#0#0#9'TComboBox'#7'cbPaper'#4'Left'#2'N'#6'Hei'
+'ght'#2#29#3'Top'#2#3#5'Width'#3'*'#1#7'Anchors'#11#5'akTop'#6'akLeft'#7'akR'
+'ight'#0#12'AutoComplete'#8#10'ItemHeight'#2#0#9'ItemWidth'#2#0#8'OnChange'#7
+#13'cbPaperChange'#5'Style'#7#14'csDropDownList'#8'TabOrder'#2#0#0#0#9'TComb'
+'oBox'#8'cbSource'#4'Left'#2'N'#6'Height'#2#29#3'Top'#2'+'#5'Width'#3'*'#1#7
+'Anchors'#11#5'akTop'#6'akLeft'#7'akRight'#0#12'AutoComplete'#8#10'ItemHeigh'
+'t'#2#0#9'ItemWidth'#2#0#5'Style'#7#14'csDropDownList'#8'TabOrder'#2#1#0#0#0
+#9'TGroupBox'#13'gpOrientation'#4'Left'#2#6#6'Height'#2'_'#3'Top'#2'n'#5'Wid'
+'th'#2'x'#5'Align'#7#6'alLeft'#20'BorderSpacing.Around'#2#6#7'Caption'#6#11
+'Orientation'#12'ClientHeight'#2'N'#11'ClientWidth'#2't'#8'TabOrder'#2#1#0#12
+'TRadioButton'#11'radPortrait'#4'Left'#2#14#6'Height'#2#22#3'Top'#2#14#5'Wid'
+'th'#2'G'#7'Caption'#6#8'Portrait'#7'Checked'#9#7'OnClick'#7#16'radPortraitC'
+'lick'#5'State'#7#9'cbChecked'#8'TabOrder'#2#0#0#0#12'TRadioButton'#12'radLa'
+'ndscape'#4'Left'#2#14#6'Height'#2#22#3'Top'#2','#5'Width'#2'\'#7'Caption'#6
+#9'Landscape'#7'OnClick'#7#16'radPortraitClick'#8'TabOrder'#2#1#7'TabStop'#8
+#0#0#0#9'TGroupBox'#9'gpMargins'#4'Left'#3#132#0#6'Height'#2'_'#3'Top'#2'n'#5
+'Width'#3#5#1#5'Align'#7#8'alClient'#20'BorderSpacing.Around'#2#6#7'Caption'
+#6#7'Margins'#12'ClientHeight'#2'N'#11'ClientWidth'#3#1#1#8'TabOrder'#2#2#0#6
+'TPanel'#10'panMargins'#22'AnchorSideLeft.Control'#7#9'gpMargins'#19'AnchorS'
+'ideLeft.Side'#7#9'asrCenter'#21'AnchorSideTop.Control'#7#9'gpMargins'#18'An'
+'chorSideTop.Side'#7#9'asrCenter'#4'Left'#2#4#6'Height'#2'H'#3'Top'#2#3#5'Wi'
+'dth'#3#249#0#10'BevelOuter'#7#7'bvSpace'#12'ClientHeight'#2'H'#11'ClientWid'
+'th'#3#249#0#8'TabOrder'#2#0#0#6'TLabel'#9'lblBottom'#4'Left'#2''#6'Height'
+#2#16#3'Top'#2'2'#5'Width'#2'2'#7'Caption'#6#7'Bottom:'#11'ParentColor'#8#0#0
+#6'TLabel'#6'lblTop'#4'Left'#2#6#6'Height'#2#16#3'Top'#2'0'#5'Width'#2#26#7
+'Caption'#6#4'Top:'#11'ParentColor'#8#0#0#6'TLabel'#8'lblRight'#4'Left'#2''
+#6'Height'#2#16#3'Top'#2#14#5'Width'#2'%'#7'Caption'#6#6'Right:'#11'ParentCo'
+'lor'#8#0#0#6'TLabel'#7'lblLeft'#4'Left'#2#6#6'Height'#2#16#3'Top'#2#14#5'Wi'
+'dth'#2#28#7'Caption'#6#5'Left:'#11'ParentColor'#8#0#0#5'TEdit'#9'txtBottom'
+#4'Left'#3#183#0#6'Height'#2#23#3'Top'#2'+'#5'Width'#2'@'#8'TabOrder'#2#0#0#0
+#5'TEdit'#6'txtTop'#4'Left'#2'('#6'Height'#2#23#3'Top'#2'+'#5'Width'#2'8'#8
+'TabOrder'#2#1#0#0#5'TEdit'#8'txtRight'#4'Left'#3#183#0#6'Height'#2#23#3'Top'
+#2#7#5'Width'#2'@'#8'TabOrder'#2#2#0#0#5'TEdit'#7'txtLeft'#4'Left'#2'('#6'He'
+'ight'#2#23#3'Top'#2#7#5'Width'#2'8'#8'TabOrder'#2#3#0#0#0#0#0#6'TPanel'#10
+#11#5'Width'#2''''#7'Caption'#6#6'Paper:'#11'ParentColor'#8#0#0#6'TLabel'#9
+'lblSource'#4'Left'#2#14#6'Height'#2#16#3'Top'#2'3'#5'Width'#2'.'#7'Caption'
+#6#7'Source:'#11'ParentColor'#8#0#0#9'TComboBox'#7'cbPaper'#4'Left'#2'N'#6'H'
+'eight'#2#29#3'Top'#2#3#5'Width'#3'.'#1#7'Anchors'#11#5'akTop'#6'akLeft'#7'a'
+'kRight'#0#10'ItemHeight'#2#0#8'OnChange'#7#13'cbPaperChange'#5'Style'#7#14
+'csDropDownList'#8'TabOrder'#2#0#0#0#9'TComboBox'#8'cbSource'#4'Left'#2'N'#6
+'Height'#2#29#3'Top'#2'+'#5'Width'#3'.'#1#7'Anchors'#11#5'akTop'#6'akLeft'#7
+'akRight'#0#10'ItemHeight'#2#0#5'Style'#7#14'csDropDownList'#8'TabOrder'#2#1
+#0#0#0#9'TGroupBox'#13'gpOrientation'#4'Left'#2#6#6'Height'#2'_'#3'Top'#2'n'
+#5'Width'#2'x'#5'Align'#7#6'alLeft'#20'BorderSpacing.Around'#2#6#7'Caption'#6
+#11'Orientation'#12'ClientHeight'#2'N'#11'ClientWidth'#2't'#8'TabOrder'#2#1#0
+#12'TRadioButton'#11'radPortrait'#4'Left'#2#14#6'Height'#2#21#3'Top'#2#14#5
+'Width'#2'A'#7'Caption'#6#8'Portrait'#7'Checked'#9#7'OnClick'#7#16'radPortra'
+'itClick'#5'State'#7#9'cbChecked'#8'TabOrder'#2#0#0#0#12'TRadioButton'#12'ra'
+'dLandscape'#4'Left'#2#14#6'Height'#2#21#3'Top'#2','#5'Width'#2'V'#7'Caption'
+#6#9'Landscape'#7'OnClick'#7#16'radPortraitClick'#8'TabOrder'#2#1#7'TabStop'
+#8#0#0#0#9'TGroupBox'#9'gpMargins'#4'Left'#3#132#0#6'Height'#2'_'#3'Top'#2'n'
+#5'Width'#3#9#1#5'Align'#7#8'alClient'#20'BorderSpacing.Around'#2#6#7'Captio'
+'n'#6#7'Margins'#12'ClientHeight'#2'N'#11'ClientWidth'#3#5#1#8'TabOrder'#2#2
+#0#6'TPanel'#10'panMargins'#22'AnchorSideLeft.Control'#7#9'gpMargins'#19'Anc'
+'horSideLeft.Side'#7#9'asrCenter'#21'AnchorSideTop.Control'#7#9'gpMargins'#18
+'AnchorSideTop.Side'#7#9'asrCenter'#4'Left'#2#6#6'Height'#2'H'#3'Top'#2#3#5
+'Width'#3#249#0#10'BevelOuter'#7#7'bvSpace'#12'ClientHeight'#2'H'#11'ClientW'
+'idth'#3#249#0#8'TabOrder'#2#0#0#6'TLabel'#9'lblBottom'#4'Left'#2#127#6'Heig'
+'ht'#2#16#3'Top'#2'2'#5'Width'#2'/'#7'Caption'#6#7'Bottom:'#11'ParentColor'#8
+#0#0#6'TLabel'#6'lblTop'#4'Left'#2#6#6'Height'#2#16#3'Top'#2'0'#5'Width'#2#25
+#7'Caption'#6#4'Top:'#11'ParentColor'#8#0#0#6'TLabel'#8'lblRight'#4'Left'#2
+#127#6'Height'#2#16#3'Top'#2#14#5'Width'#2'#'#7'Caption'#6#6'Right:'#11'Pare'
+'ntColor'#8#0#0#6'TLabel'#7'lblLeft'#4'Left'#2#6#6'Height'#2#16#3'Top'#2#14#5
+'Width'#2#26#7'Caption'#6#5'Left:'#11'ParentColor'#8#0#0#5'TEdit'#9'txtBotto'
+'m'#4'Left'#3#183#0#6'Height'#2#25#3'Top'#2'+'#5'Width'#2'@'#8'TabOrder'#2#0
+#0#0#5'TEdit'#6'txtTop'#4'Left'#2'('#6'Height'#2#25#3'Top'#2'+'#5'Width'#2'8'
+#8'TabOrder'#2#1#0#0#5'TEdit'#8'txtRight'#4'Left'#3#183#0#6'Height'#2#25#3'T'
+'op'#2#7#5'Width'#2'@'#8'TabOrder'#2#2#0#0#5'TEdit'#7'txtLeft'#4'Left'#2'('#6
+'Height'#2#25#3'Top'#2#7#5'Width'#2'8'#8'TabOrder'#2#3#0#0#0#0#0#6'TPanel'#10
+'panPreview'#21'AnchorSideTop.Control'#7#8'panSetup'#4'Left'#2#0#6'Height'#3
+#220#0#3'Top'#2#0#5'Width'#3#143#1#5'Align'#7#8'alClient'#10'BevelOuter'#7#6
+'bvNone'#12'ClientHeight'#3#220#0#11'ClientWidth'#3#143#1#21'Constraints.Min'
+#224#0#3'Top'#2#0#5'Width'#3#147#1#5'Align'#7#8'alClient'#10'BevelOuter'#7#6
+'bvNone'#12'ClientHeight'#3#224#0#11'ClientWidth'#3#147#1#21'Constraints.Min'
+'Height'#3#142#0#8'TabOrder'#2#1#11'OnMouseDown'#7#18'pbPreviewMouseDown'#8
+'OnResize'#7#16'panPreviewResize'#0#9'TPaintBox'#9'pbPreview'#22'AnchorSideL'
+'eft.Control'#7#10'panPreview'#19'AnchorSideLeft.Side'#7#9'asrCenter'#21'Anc'
+'horSideTop.Control'#7#10'panPreview'#18'AnchorSideTop.Side'#7#9'asrCenter'#4
+'Left'#3#149#0#6'Height'#3#130#0#3'Top'#2'-'#5'Width'#2'd'#11'OnMouseDown'#7
+'Left'#3#151#0#6'Height'#3#130#0#3'Top'#2'/'#5'Width'#2'd'#11'OnMouseDown'#7
+#18'pbPreviewMouseDown'#16'OnMouseWheelDown'#7#23'pbPreviewMouseWheelDown'#14
+'OnMouseWheelUp'#7#21'pbPreviewMouseWheelUp'#7'OnPaint'#7#14'pbPreviewPaint'
+#0#0#0#0

View File

@ -113,8 +113,7 @@ begin
Canvas.Rectangle(R);
// hard margins
Canvas.Pen.Color := RGBToColor(255,127,127);
Canvas.Brush.Color := RGBToColor(255,127,127);
Canvas.Pen.Color := RGBToColor(255,204,204);
DrawMargin(0, FHardMargins.Left );
DrawMargin(1, FHardMargins.Top );
DrawMargin(2, FHardMargins.Right );
@ -135,7 +134,12 @@ end;
procedure TframePageSetup.cbPaperChange(Sender: TObject);
begin
Printer.PaperSize.PaperName := GetCupsComboKeyValue(cbPaper);
if Printer.PaperSize.DefaultPapers then
begin
if cbPaper.ItemIndex>=0 then
Printer.PaperSize.PaperName := cbPaper.Items[cbPaper.ItemIndex];
end else
Printer.PaperSize.PaperName := GetCupsComboKeyValue(cbPaper);
UpdatePageSize;
end;
@ -227,7 +231,16 @@ begin
end;
if [psoMargins,psoPapers]*FOptions<>[] then
begin
SetupCupsCombo(cbPaper, nil, 'PageSize');
if (cbPaper.Items.Count=0) then
begin
// no cups printer papers, use default ones
cbPaper.Items := Printer.PaperSize.SupportedPapers;
cbPaper.ItemIndex:= cbPaper.Items.IndexOf(Printer.PaperSize.PaperName);
cbPaper.Enabled:=true;
end;
end;
if psoPapers in FOptions then
SetupCupsCOmbo(cbSource, nil, 'InputSlot')
@ -255,9 +268,13 @@ begin
// find the tallest paper
FHeightTallest := 0;
j := -1;
if cbPaper.Enabled then
for i:=0 to cbPaper.Items.Count-1 do
begin
R := Printer.PaperSize.PaperRectOf[GetCupsComboKeyValue(cbPaper, i)];
if Printer.PaperSize.DefaultPapers then
R := Printer.PaperSize.PaperRectOf[cbPaper.Items[i]]
else
R := Printer.PaperSize.PaperRectOf[GetCupsComboKeyValue(cbPaper, i)];
with R.PhysicalRect do
if FHeightTallest<(Bottom-Top) then
begin

View File

@ -120,6 +120,11 @@ type
WorkRect : TRect;
end;
TPaperItem = record
PaperName: string[40];
PaperRect: TPaperRect;
end;
{ TPaperSize }
TPaperSize = Class(TObject)
@ -139,11 +144,19 @@ type
function GetSupportedPapers: TStrings;
procedure SetPaperName(const AName: string);
function PaperRectOfName(const AName: string) : TPaperRect;
protected
private
fInternalPapers : array of TPaperItem;
fDefaultPapers : boolean;
fDefaultPaperIndex : Integer;
procedure CreateInternalPapers;
procedure FillDefaultPapers;
function GetDefaultPaperRect(const AName: string; var APaperRect:TPaperRect): Integer;
function IndexOfDefaultPaper(const AName: string): Integer;
public
constructor Create(aOwner : TPrinter); overload;
destructor Destroy; override;
property DefaultPapers : boolean read fDefaultPapers;
property Width : Integer read GetPhysPaperWidth;
property Height : Integer read GetPhysPaperHeight;
property PaperName : string read GetPaperName write SetPaperName;
@ -526,9 +539,7 @@ end;
function TPrinter.GetOrientation: TPrinterOrientation;
begin
Result:=poPortrait;
if Printers.Count>0 then
Result:=DoGetOrientation;
Result:=DoGetOrientation;
end;
// Returns the height in points (pixels) of printable area
@ -608,8 +619,7 @@ end;
procedure TPrinter.SetOrientation(const AValue: TPrinterOrientation);
begin
CheckPrinting(False);
if Printers.Count>0 then
DoSetOrientation(aValue);
DoSetOrientation(aValue);
end;
//Set the selected printer
@ -645,7 +655,7 @@ end;
//If not Printer selected, Select the default printer
procedure TPrinter.SelectCurrentPrinterOrDefault;
begin
if fPrinterIndex<0 then
if (fPrinterIndex<0) and (Printers.Count>0) then
PrinterIndex:=0;
end;
@ -810,9 +820,76 @@ end;
{ TPaperSize }
procedure TPaperSize.CreateInternalPapers;
procedure add(AnIndex:Integer; aname:string; aPhysRect,aWrkRect:TRect);
begin
with fInternalPapers[AnIndex] do begin
PaperName := aName;
PaperRect.PhysicalRect := aPhysRect;
PaperRect.WorkRect := aWrkRect;
end;
end;
function PRRect(const ALeft,ATop,ARight,ABottom: Integer): TRect;
begin
Result.Left := ALeft;
Result.Top := ATop;
Result.Right := round(ARight * FOwnedPrinter.XDPI / 72);
Result.Bottom := round(ABottom * FOwnedPrinter.XDPI / 72);
end;
begin
if Length(fInternalPapers)=0 then
begin
SetLength(fInternalPapers, 3);
add(0, 'Letter', PRRect(0, 0, 612, 792 ), PRRect(0, 0, 612, 792 ));
add(1, 'A4', PRRect(0, 0, 595, 892 ), PRRect(0, 0, 595, 892 ));
add(2, 'Legal', PRRect(0, 0, 612, 1008), PRRect(0, 0, 612, 1008));
end;
end;
procedure TPaperSize.FillDefaultPapers;
var
i: Integer;
begin
FSupportedPapers.Clear;
CreateInternalPapers;
for i:=0 to Length(FInternalPapers)-1 do
FSupportedPapers.Add(FInternalPapers[i].PaperName);
FDefaultPaperIndex := 0;
FDefaultPapers := true;
end;
function TPaperSize.GetDefaultPaperName: string;
begin
Result:=fOwnedPrinter.DoGetDefaultPaperName;
if fDefaultPapers then
Result := FSupportedPapers[0]
else
Result := fOwnedPrinter.DoGetDefaultPaperName;
end;
function TPaperSize.GetDefaultPaperRect(const AName: string;
var APaperRect:TPaperRect): Integer;
begin
Result := IndexOfDefaultPaper(AName);
if Result>=0 then
with FInternalPapers[Result].PaperRect do begin
if FOwnedPrinter.Orientation in [poPortrait, poReversePortrait] then
begin
APaperRect.PhysicalRect := PhysicalRect;
APaperRect.WorkRect := WorkRect;
end else
begin
APaperRect.PhysicalRect.Left := 0;
APaperRect.PhysicalRect.Top := 0;
APaperRect.PhysicalRect.Right := PhysicalRect.Bottom;
APaperRect.Physicalrect.Bottom := PhysicalRect.Right;
APaperRect.WorkRect.Left := WorkRect.Top;
APaperRect.WorkRect.Top := PhysicalRect.Right-WorkRect.Right;
APaperRect.WorkRect.Right := WorkRect.Bottom;
APaperRect.WorkRect.Bottom := PhysicalRect.Right-Workrect.Left;
end;
end;
end;
function TPaperSize.GetPhysPaperHeight: Integer;
@ -822,7 +899,11 @@ end;
function TPaperSize.GetPaperName: string;
begin
Result:=fOwnedPrinter.DoGetPaperName;
if fDefaultPapers then
Result := SupportedPapers[FDefaultPaperIndex]
else
Result := fOwnedPrinter.DoGetPaperName;
if Result='' then
Result:=DefaultPaperName;
end;
@ -839,26 +920,48 @@ end;
function TPaperSize.GetSupportedPapers: TStrings;
begin
if (fOwnedPrinter.Printers.Count>0) and
((fSupportedPapers.Count=0)
or (fLastPrinterIndex<>fOwnedPrinter.PrinterIndex)) then
if (fSupportedPapers.Count=0) or
(fLastPrinterIndex<>fOwnedPrinter.PrinterIndex) then
begin
fOwnedPrinter.SelectCurrentPrinterOrDefault;
fSupportedPapers.Clear;
fDefaultPapers := false;
//DebugLn(['TPaperSize.GetSupportedPapers ',dbgsName(fOwnedPrinter),' ',dbgsName(Printer),' ',fOwnedPrinter=Printer]);
fOwnedPrinter.DoEnumPapers(fSupportedPapers);
if fSupportedPapers.Count=0 then
FillDefaultPapers;
fLastPrinterIndex:=fOwnedPrinter.PrinterIndex;
end;
Result:=fSupportedPapers;
end;
function TPaperSize.IndexOfDefaultPaper(const AName: string): Integer;
var
i: Integer;
begin
Result := -1;
for i:=0 to Length(fInternalPapers)-1 do
if CompareText(fInternalPapers[i].PaperName, AName)=0 then
begin
Result := i;
break;
end;
end;
procedure TPaperSize.SetPaperName(const AName: string);
begin
if SupportedPapers.IndexOf(aName)<>-1 then
begin
if aName<>PaperName then
fOwnedPrinter.DoSetPaperName(aName)
begin
if fDefaultPapers then
FDefaultPaperIndex := IndexOfDefaultPaper(AName)
else
FOwnedPrinter.DoSetPaperName(aName)
end;
end
else
raise EPrinter.Create(Format('Paper "%s" not supported !',[aName]));
@ -873,16 +976,17 @@ begin
if SupportedPapers.IndexOf(AName)<>-1 then
begin
Margins:=fOwnedPrinter.DoGetPaperRect(aName,TmpPaperRect);
if fDefaultPapers then
Margins := GetDefaultPaperRect(AName, TmpPaperRect)
else
Margins := fOwnedPrinter.DoGetPaperRect(aName,TmpPaperRect);
if Margins>=0 then
begin
Result := TmpPaperRect;
end
else raise EPrinter.Create(Format('The paper "%s" has no defined rectangle ! ',[aName]));
{end else if (AName='') and (SupportedPapers.Count=0) then begin
DebugLn(['WARNING: TPaperSize.PaperRectOfName: printer has no paper rect. Using 1000,1000']);
Result.PhysicalRect:=Rect(0,0,1000,1000);
Result.WorkRect:=Result.PhysicalRect;}
Result := TmpPaperRect
else
raise EPrinter.Create(Format('The paper "%s" has no defined rectangle ! ',[aName]));
end
else raise EPrinter.Create(Format('Paper "%s" not supported !',[aName]));
end;