mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-06-20 01:08:22 +02:00
Printers: Set margins etc. for Unix PageSetup dialog. Issue #33427, patch from AlexeyT.
git-svn-id: trunk@57528 -
This commit is contained in:
parent
75314f3319
commit
e092279c61
@ -55,6 +55,8 @@ type
|
|||||||
|
|
||||||
const
|
const
|
||||||
cDefaultPageSetupDialogOptions = [psoMargins];
|
cDefaultPageSetupDialogOptions = [psoMargins];
|
||||||
|
cDefaultPageSetupMargin = 0;
|
||||||
|
cDefaultPageSetupMinMargin = 400; //400: in mm it's 4mm, in inches it's ~10mm
|
||||||
|
|
||||||
type
|
type
|
||||||
{ TPageSetupDialog }
|
{ TPageSetupDialog }
|
||||||
@ -67,6 +69,10 @@ type
|
|||||||
FMarginTop: integer;
|
FMarginTop: integer;
|
||||||
FMarginRight: integer;
|
FMarginRight: integer;
|
||||||
FMarginBottom: integer;
|
FMarginBottom: integer;
|
||||||
|
FMinMarginLeft: integer;
|
||||||
|
FMinMarginTop: integer;
|
||||||
|
FMinMarginRight: integer;
|
||||||
|
FMinMarginBottom: integer;
|
||||||
FUnits: TPageMeasureUnits;
|
FUnits: TPageMeasureUnits;
|
||||||
FOptions: TPageSetupDialogOptions;
|
FOptions: TPageSetupDialogOptions;
|
||||||
protected
|
protected
|
||||||
@ -76,10 +82,14 @@ type
|
|||||||
published
|
published
|
||||||
property PageWidth: integer read FPageWidth write FPageWidth default 0;
|
property PageWidth: integer read FPageWidth write FPageWidth default 0;
|
||||||
property PageHeight: integer read FPageHeight write FPageHeight default 0;
|
property PageHeight: integer read FPageHeight write FPageHeight default 0;
|
||||||
property MarginLeft: integer read FMarginLeft write FMarginLeft default 0;
|
property MarginLeft: integer read FMarginLeft write FMarginLeft default cDefaultPageSetupMargin;
|
||||||
property MarginTop: integer read FMarginTop write FMarginTop default 0;
|
property MarginTop: integer read FMarginTop write FMarginTop default cDefaultPageSetupMargin;
|
||||||
property MarginRight: integer read FMarginRight write FMarginRight default 0;
|
property MarginRight: integer read FMarginRight write FMarginRight default cDefaultPageSetupMargin;
|
||||||
property MarginBottom: integer read FMarginBottom write FMarginBottom default 0;
|
property MarginBottom: integer read FMarginBottom write FMarginBottom default cDefaultPageSetupMargin;
|
||||||
|
property MinMarginLeft: integer read FMinMarginLeft write FMinMarginLeft default cDefaultPageSetupMinMargin;
|
||||||
|
property MinMarginTop: integer read FMinMarginTop write FMinMarginTop default cDefaultPageSetupMinMargin;
|
||||||
|
property MinMarginRight: integer read FMinMarginRight write FMinMarginRight default cDefaultPageSetupMinMargin;
|
||||||
|
property MinMarginBottom: integer read FMinMarginBottom write FMinMarginBottom default cDefaultPageSetupMinMargin;
|
||||||
property Options: TPageSetupDialogOptions read FOptions write FOptions default cDefaultPageSetupDialogOptions;
|
property Options: TPageSetupDialogOptions read FOptions write FOptions default cDefaultPageSetupDialogOptions;
|
||||||
property Units: TPageMeasureUnits read FUnits write FUnits default pmDefault;
|
property Units: TPageMeasureUnits read FUnits write FUnits default pmDefault;
|
||||||
end;
|
end;
|
||||||
@ -182,10 +192,14 @@ begin
|
|||||||
inherited Create(TheOwner);
|
inherited Create(TheOwner);
|
||||||
FPageWidth:= 0;
|
FPageWidth:= 0;
|
||||||
FPageHeight:= 0;
|
FPageHeight:= 0;
|
||||||
FMarginLeft:= 0;
|
FMarginLeft:= cDefaultPageSetupMargin;
|
||||||
FMarginTop:= 0;
|
FMarginTop:= cDefaultPageSetupMargin;
|
||||||
FMarginRight:= 0;
|
FMarginRight:= cDefaultPageSetupMargin;
|
||||||
FMarginBottom:= 0;
|
FMarginBottom:= cDefaultPageSetupMargin;
|
||||||
|
FMinMarginLeft:= cDefaultPageSetupMinMargin;
|
||||||
|
FMinMarginTop:= cDefaultPageSetupMinMargin;
|
||||||
|
FMinMarginRight:= cDefaultPageSetupMinMargin;
|
||||||
|
FMinMarginBottom:= cDefaultPageSetupMinMargin;
|
||||||
FOptions:= cDefaultPageSetupDialogOptions;
|
FOptions:= cDefaultPageSetupDialogOptions;
|
||||||
FUnits:= pmDefault;
|
FUnits:= pmDefault;
|
||||||
end;
|
end;
|
||||||
|
@ -89,6 +89,13 @@ var
|
|||||||
begin
|
begin
|
||||||
Dlg:= TDlgPageSetup.Create(nil);
|
Dlg:= TDlgPageSetup.Create(nil);
|
||||||
try
|
try
|
||||||
|
Dlg.SetControls(
|
||||||
|
not (psoDisablePagePainting in Options),
|
||||||
|
not (psoDisableMargins in Options),
|
||||||
|
not (psoDisablePaper in Options),
|
||||||
|
not (psoDisableOrientation in Options)
|
||||||
|
);
|
||||||
|
|
||||||
if Title<>'' then
|
if Title<>'' then
|
||||||
Dlg.Caption:= Title
|
Dlg.Caption:= Title
|
||||||
else
|
else
|
||||||
@ -99,7 +106,7 @@ begin
|
|||||||
Dlg.frmPageSetup.UnitInches:= true;
|
Dlg.frmPageSetup.UnitInches:= true;
|
||||||
with Dlg.frmPageSetup.gpMargins do
|
with Dlg.frmPageSetup.gpMargins do
|
||||||
Caption:= Caption+' (inches)';
|
Caption:= Caption+' (inches)';
|
||||||
NDigits:= 3;
|
NDigits:= 2;
|
||||||
// according to MSDN, WinAPI margin rect needs values in 1/1000 of inches,
|
// according to MSDN, WinAPI margin rect needs values in 1/1000 of inches,
|
||||||
// or in 1/100 on mm.
|
// or in 1/100 on mm.
|
||||||
// https://msdn.microsoft.com/en-us/library/windows/desktop/ms646842(v=vs.85).aspx
|
// https://msdn.microsoft.com/en-us/library/windows/desktop/ms646842(v=vs.85).aspx
|
||||||
@ -125,6 +132,11 @@ begin
|
|||||||
Dlg.frmPageSetup.txtRight.Value:= FMarginRight/NScale;
|
Dlg.frmPageSetup.txtRight.Value:= FMarginRight/NScale;
|
||||||
Dlg.frmPageSetup.txtBottom.Value:= FMarginBottom/NScale;
|
Dlg.frmPageSetup.txtBottom.Value:= FMarginBottom/NScale;
|
||||||
|
|
||||||
|
Dlg.frmPageSetup.txtLeft.MinValue:= FMinMarginLeft/NScale;
|
||||||
|
Dlg.frmPageSetup.txtTop.MinValue:= FMinMarginTop/NScale;
|
||||||
|
Dlg.frmPageSetup.txtRight.MinValue:= FMinMarginRight/NScale;
|
||||||
|
Dlg.frmPageSetup.txtBottom.MinValue:= FMinMarginBottom/NScale;
|
||||||
|
|
||||||
Result:= Dlg.ShowModal=mrOk;
|
Result:= Dlg.ShowModal=mrOk;
|
||||||
if Result then
|
if Result then
|
||||||
begin
|
begin
|
||||||
|
@ -5,6 +5,7 @@ object framePageSetup: TframePageSetup
|
|||||||
Width = 448
|
Width = 448
|
||||||
ClientHeight = 435
|
ClientHeight = 435
|
||||||
ClientWidth = 448
|
ClientWidth = 448
|
||||||
|
LCLVersion = '1.9.0.0'
|
||||||
TabOrder = 0
|
TabOrder = 0
|
||||||
DesignLeft = 350
|
DesignLeft = 350
|
||||||
DesignTop = 92
|
DesignTop = 92
|
||||||
|
@ -21,14 +21,6 @@ uses
|
|||||||
OsPrinters, CupsLCL;
|
OsPrinters, CupsLCL;
|
||||||
|
|
||||||
type
|
type
|
||||||
TPageSetupMode = (psmFull, psmPapers, psmMargins);
|
|
||||||
TPageSetupOption = (
|
|
||||||
psoMargins, // margins and preview are visible
|
|
||||||
psoPapers, // papers group visible
|
|
||||||
psoOrientation // orientation group visible
|
|
||||||
);
|
|
||||||
TPageSetupOptions = set of TPageSetupOption;
|
|
||||||
|
|
||||||
{ TframePageSetup }
|
{ TframePageSetup }
|
||||||
|
|
||||||
TframePageSetup = class(TFrame)
|
TframePageSetup = class(TFrame)
|
||||||
@ -68,10 +60,14 @@ type
|
|||||||
FHeightTallest: Integer;
|
FHeightTallest: Integer;
|
||||||
FHardMargins: TRect;
|
FHardMargins: TRect;
|
||||||
FFactorX, FFactorY, FZoom: Double;
|
FFactorX, FFactorY, FZoom: Double;
|
||||||
FOptions: TPageSetupOptions;
|
EnablePreview: boolean;
|
||||||
|
EnableMargins: boolean;
|
||||||
|
EnablePapers: boolean;
|
||||||
|
EnableOrientation: boolean;
|
||||||
public
|
public
|
||||||
UnitInches: boolean;
|
UnitInches: boolean;
|
||||||
procedure Initialize(AMode: TPageSetupMode);
|
procedure Initialize(AEnablePreview, AEnableMargins, AEnablePapers,
|
||||||
|
AEnableOrientation: boolean);
|
||||||
procedure UpdatePageSize;
|
procedure UpdatePageSize;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -109,13 +105,9 @@ procedure TframePageSetup.pbPreviewPaint(Sender: TObject);
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
var
|
var
|
||||||
R: TRect;
|
|
||||||
NToInches: double;
|
NToInches: double;
|
||||||
begin
|
begin
|
||||||
|
if not EnablePreview then
|
||||||
if Sender=nil then ;
|
|
||||||
|
|
||||||
if not (psoMargins in FOptions) then
|
|
||||||
exit;
|
exit;
|
||||||
|
|
||||||
if UnitInches then
|
if UnitInches then
|
||||||
@ -125,14 +117,12 @@ begin
|
|||||||
|
|
||||||
with pbPreview do
|
with pbPreview do
|
||||||
begin
|
begin
|
||||||
|
|
||||||
// page frame
|
|
||||||
R := Rect(0,0,Width,Height);
|
|
||||||
Canvas.Pen.Color := clBlack;
|
Canvas.Pen.Color := clBlack;
|
||||||
Canvas.Brush.Color := clWhite;
|
Canvas.Brush.Color := clWhite;
|
||||||
Canvas.Rectangle(R);
|
Canvas.Rectangle(0, 0, Width, Height);
|
||||||
|
|
||||||
// hard margins
|
if EnableMargins then
|
||||||
|
begin
|
||||||
Canvas.Pen.Color := clHighlight;
|
Canvas.Pen.Color := clHighlight;
|
||||||
DrawMargin(0, Round(txtLeft.Value * NToInches * Printer.XDPI * FFactorX * FZoom) ); //FHardMargins.Left
|
DrawMargin(0, Round(txtLeft.Value * NToInches * Printer.XDPI * FFactorX * FZoom) ); //FHardMargins.Left
|
||||||
DrawMargin(1, Round(txtTop.Value * NToInches * Printer.YDPI * FFactorY * FZoom) );
|
DrawMargin(1, Round(txtTop.Value * NToInches * Printer.YDPI * FFactorY * FZoom) );
|
||||||
@ -140,6 +130,7 @@ begin
|
|||||||
DrawMargin(3, Round(txtBottom.Value * NToInches * Printer.YDPI * FFactorY * FZoom) );
|
DrawMargin(3, Round(txtBottom.Value * NToInches * Printer.YDPI * FFactorY * FZoom) );
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TframePageSetup.radPortraitClick(Sender: TObject);
|
procedure TframePageSetup.radPortraitClick(Sender: TObject);
|
||||||
begin
|
begin
|
||||||
@ -172,7 +163,7 @@ procedure TframePageSetup.panPreviewResize(Sender: TObject);
|
|||||||
var
|
var
|
||||||
TallH: Integer;
|
TallH: Integer;
|
||||||
begin
|
begin
|
||||||
if not (psoMargins in FOptions) then
|
if not EnablePreview then
|
||||||
exit;
|
exit;
|
||||||
|
|
||||||
TallH := Round(FheightTallest * FFactorY);
|
TallH := Round(FheightTallest * FFactorY);
|
||||||
@ -214,7 +205,7 @@ end;
|
|||||||
|
|
||||||
procedure TframePageSetup.UpdatePageSize;
|
procedure TframePageSetup.UpdatePageSize;
|
||||||
begin
|
begin
|
||||||
if not (psoMargins in FOptions) then
|
if not EnablePreview then
|
||||||
exit;
|
exit;
|
||||||
|
|
||||||
with Printer.PaperSize.PaperRect.PhysicalRect do
|
with Printer.PaperSize.PaperRect.PhysicalRect do
|
||||||
@ -241,22 +232,21 @@ begin
|
|||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TframePageSetup.Initialize(AMode: TPageSetupMode);
|
procedure TframePageSetup.Initialize(AEnablePreview, AEnableMargins, AEnablePapers,
|
||||||
|
AEnableOrientation: boolean);
|
||||||
var
|
var
|
||||||
i,j:Integer;
|
i,j:Integer;
|
||||||
R: TPaperRect;
|
R: TPaperRect;
|
||||||
begin
|
begin
|
||||||
case AMode of
|
EnablePreview:= AEnablePreview;
|
||||||
psmMargins:
|
EnableMargins:= AEnableMargins;
|
||||||
FOptions := [psoMargins];
|
EnablePapers:= AEnablePapers;
|
||||||
psmPapers:
|
EnableOrientation:= AEnableOrientation;
|
||||||
FOptions := [psoPapers,psoOrientation];
|
|
||||||
else
|
|
||||||
FOptions := [psoMargins,psoPapers,psoOrientation];
|
|
||||||
end;
|
|
||||||
|
|
||||||
if [psoMargins,psoPapers]*FOptions<>[] then
|
gpPaper.Enabled := EnablePapers;
|
||||||
|
if EnablePapers then
|
||||||
begin
|
begin
|
||||||
|
SetupCupsCombo(cbSource, nil, 'InputSlot');
|
||||||
SetupCupsCombo(cbPaper, nil, 'PageSize');
|
SetupCupsCombo(cbPaper, nil, 'PageSize');
|
||||||
if (cbPaper.Items.Count=0) then
|
if (cbPaper.Items.Count=0) then
|
||||||
begin
|
begin
|
||||||
@ -267,13 +257,8 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
if psoPapers in FOptions then
|
|
||||||
SetupCupsCOmbo(cbSource, nil, 'InputSlot')
|
|
||||||
else
|
|
||||||
gpPaper.Visible := false;
|
|
||||||
|
|
||||||
//TODO: support reverse variants too?
|
//TODO: support reverse variants too?
|
||||||
gpOrientation.Visible := (psoOrientation in FOptions);
|
gpOrientation.Enabled := EnableOrientation;
|
||||||
case Printer.Orientation of
|
case Printer.Orientation of
|
||||||
poPortrait,poReversePortrait:
|
poPortrait,poReversePortrait:
|
||||||
radPortrait.Checked := true;
|
radPortrait.Checked := true;
|
||||||
@ -281,7 +266,10 @@ begin
|
|||||||
radLandscape.Checked := true;
|
radLandscape.Checked := true;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
if psoMargins in FOptions then
|
gpMargins.Enabled := EnableMargins;
|
||||||
|
panPreview.Visible:= EnablePreview;
|
||||||
|
|
||||||
|
if EnablePreview then
|
||||||
begin
|
begin
|
||||||
// assume 100 pix = 8.5 inch (IOW, letter size width = 100 pixels)
|
// assume 100 pix = 8.5 inch (IOW, letter size width = 100 pixels)
|
||||||
with ScreenInfo do
|
with ScreenInfo do
|
||||||
@ -319,24 +307,7 @@ begin
|
|||||||
// zoom factor
|
// zoom factor
|
||||||
FZoom := 1.0;
|
FZoom := 1.0;
|
||||||
UpdatePageSize;
|
UpdatePageSize;
|
||||||
|
|
||||||
end else
|
|
||||||
begin
|
|
||||||
panPreview.Visible:=false;
|
|
||||||
gpMargins.Visible:=false;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
if AMode=psmPapers then
|
|
||||||
begin
|
|
||||||
gpOrientation.Anchors:=[akTop,akRight,akBottom];
|
|
||||||
gpOrientation.Align:=alRight;
|
|
||||||
gpPaper.Anchors:=[akTop,akLeft];
|
|
||||||
gpPaper.Align:=alClient;
|
|
||||||
PanSetup.Align:=alClient;
|
|
||||||
end else
|
|
||||||
if AMode=psmMargins then
|
|
||||||
PanSetup.Height:=gpMargins.Height+C_BOTHSPACES;
|
|
||||||
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
end.
|
end.
|
||||||
|
@ -7,7 +7,6 @@ object dlgPageSetup: TdlgPageSetup
|
|||||||
Caption = 'dlgPageSetup'
|
Caption = 'dlgPageSetup'
|
||||||
ClientHeight = 449
|
ClientHeight = 449
|
||||||
ClientWidth = 446
|
ClientWidth = 446
|
||||||
OnCreate = FormCreate
|
|
||||||
Position = poScreenCenter
|
Position = poScreenCenter
|
||||||
LCLVersion = '1.9.0.0'
|
LCLVersion = '1.9.0.0'
|
||||||
inline frmPageSetup: TframePageSetup
|
inline frmPageSetup: TframePageSetup
|
||||||
@ -49,6 +48,7 @@ object dlgPageSetup: TdlgPageSetup
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
inherited panPreview: TPanel
|
inherited panPreview: TPanel
|
||||||
|
AnchorSideTop.Control = nil
|
||||||
Height = 197
|
Height = 197
|
||||||
Width = 446
|
Width = 446
|
||||||
ClientHeight = 197
|
ClientHeight = 197
|
||||||
|
@ -28,11 +28,11 @@ type
|
|||||||
btnOk: TButton;
|
btnOk: TButton;
|
||||||
frmPageSetup: TframePageSetup;
|
frmPageSetup: TframePageSetup;
|
||||||
PanelButtons: TPanel;
|
PanelButtons: TPanel;
|
||||||
procedure FormCreate(Sender: TObject);
|
|
||||||
private
|
private
|
||||||
|
|
||||||
public
|
public
|
||||||
|
procedure SetControls(AEnablePreview, AEnableMargins, AEnablePapers,
|
||||||
|
AEnableOrientation: boolean);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
var
|
var
|
||||||
@ -44,9 +44,10 @@ implementation
|
|||||||
|
|
||||||
{ TDlgPageSetup }
|
{ TDlgPageSetup }
|
||||||
|
|
||||||
procedure TDlgPageSetup.FormCreate(Sender: TObject);
|
procedure TDlgPageSetup.SetControls(AEnablePreview, AEnableMargins, AEnablePapers,
|
||||||
|
AEnableOrientation: boolean);
|
||||||
begin
|
begin
|
||||||
frmPageSetup.Initialize(psmFull);
|
frmPageSetup.Initialize(AEnablePreview, AEnableMargins, AEnablePapers, AEnableOrientation);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
end.
|
end.
|
||||||
|
Loading…
Reference in New Issue
Block a user