mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-05-30 09:02:48 +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
|
||||
cDefaultPageSetupDialogOptions = [psoMargins];
|
||||
cDefaultPageSetupMargin = 0;
|
||||
cDefaultPageSetupMinMargin = 400; //400: in mm it's 4mm, in inches it's ~10mm
|
||||
|
||||
type
|
||||
{ TPageSetupDialog }
|
||||
@ -67,6 +69,10 @@ type
|
||||
FMarginTop: integer;
|
||||
FMarginRight: integer;
|
||||
FMarginBottom: integer;
|
||||
FMinMarginLeft: integer;
|
||||
FMinMarginTop: integer;
|
||||
FMinMarginRight: integer;
|
||||
FMinMarginBottom: integer;
|
||||
FUnits: TPageMeasureUnits;
|
||||
FOptions: TPageSetupDialogOptions;
|
||||
protected
|
||||
@ -76,10 +82,14 @@ type
|
||||
published
|
||||
property PageWidth: integer read FPageWidth write FPageWidth default 0;
|
||||
property PageHeight: integer read FPageHeight write FPageHeight default 0;
|
||||
property MarginLeft: integer read FMarginLeft write FMarginLeft default 0;
|
||||
property MarginTop: integer read FMarginTop write FMarginTop default 0;
|
||||
property MarginRight: integer read FMarginRight write FMarginRight default 0;
|
||||
property MarginBottom: integer read FMarginBottom write FMarginBottom default 0;
|
||||
property MarginLeft: integer read FMarginLeft write FMarginLeft default cDefaultPageSetupMargin;
|
||||
property MarginTop: integer read FMarginTop write FMarginTop default cDefaultPageSetupMargin;
|
||||
property MarginRight: integer read FMarginRight write FMarginRight default cDefaultPageSetupMargin;
|
||||
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 Units: TPageMeasureUnits read FUnits write FUnits default pmDefault;
|
||||
end;
|
||||
@ -182,10 +192,14 @@ begin
|
||||
inherited Create(TheOwner);
|
||||
FPageWidth:= 0;
|
||||
FPageHeight:= 0;
|
||||
FMarginLeft:= 0;
|
||||
FMarginTop:= 0;
|
||||
FMarginRight:= 0;
|
||||
FMarginBottom:= 0;
|
||||
FMarginLeft:= cDefaultPageSetupMargin;
|
||||
FMarginTop:= cDefaultPageSetupMargin;
|
||||
FMarginRight:= cDefaultPageSetupMargin;
|
||||
FMarginBottom:= cDefaultPageSetupMargin;
|
||||
FMinMarginLeft:= cDefaultPageSetupMinMargin;
|
||||
FMinMarginTop:= cDefaultPageSetupMinMargin;
|
||||
FMinMarginRight:= cDefaultPageSetupMinMargin;
|
||||
FMinMarginBottom:= cDefaultPageSetupMinMargin;
|
||||
FOptions:= cDefaultPageSetupDialogOptions;
|
||||
FUnits:= pmDefault;
|
||||
end;
|
||||
|
@ -89,6 +89,13 @@ var
|
||||
begin
|
||||
Dlg:= TDlgPageSetup.Create(nil);
|
||||
try
|
||||
Dlg.SetControls(
|
||||
not (psoDisablePagePainting in Options),
|
||||
not (psoDisableMargins in Options),
|
||||
not (psoDisablePaper in Options),
|
||||
not (psoDisableOrientation in Options)
|
||||
);
|
||||
|
||||
if Title<>'' then
|
||||
Dlg.Caption:= Title
|
||||
else
|
||||
@ -99,7 +106,7 @@ begin
|
||||
Dlg.frmPageSetup.UnitInches:= true;
|
||||
with Dlg.frmPageSetup.gpMargins do
|
||||
Caption:= Caption+' (inches)';
|
||||
NDigits:= 3;
|
||||
NDigits:= 2;
|
||||
// according to MSDN, WinAPI margin rect needs values in 1/1000 of inches,
|
||||
// or in 1/100 on mm.
|
||||
// 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.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;
|
||||
if Result then
|
||||
begin
|
||||
|
@ -5,6 +5,7 @@ object framePageSetup: TframePageSetup
|
||||
Width = 448
|
||||
ClientHeight = 435
|
||||
ClientWidth = 448
|
||||
LCLVersion = '1.9.0.0'
|
||||
TabOrder = 0
|
||||
DesignLeft = 350
|
||||
DesignTop = 92
|
||||
|
@ -21,14 +21,6 @@ uses
|
||||
OsPrinters, CupsLCL;
|
||||
|
||||
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 = class(TFrame)
|
||||
@ -68,10 +60,14 @@ type
|
||||
FHeightTallest: Integer;
|
||||
FHardMargins: TRect;
|
||||
FFactorX, FFactorY, FZoom: Double;
|
||||
FOptions: TPageSetupOptions;
|
||||
EnablePreview: boolean;
|
||||
EnableMargins: boolean;
|
||||
EnablePapers: boolean;
|
||||
EnableOrientation: boolean;
|
||||
public
|
||||
UnitInches: boolean;
|
||||
procedure Initialize(AMode: TPageSetupMode);
|
||||
procedure Initialize(AEnablePreview, AEnableMargins, AEnablePapers,
|
||||
AEnableOrientation: boolean);
|
||||
procedure UpdatePageSize;
|
||||
end;
|
||||
|
||||
@ -109,13 +105,9 @@ procedure TframePageSetup.pbPreviewPaint(Sender: TObject);
|
||||
end;
|
||||
end;
|
||||
var
|
||||
R: TRect;
|
||||
NToInches: double;
|
||||
begin
|
||||
|
||||
if Sender=nil then ;
|
||||
|
||||
if not (psoMargins in FOptions) then
|
||||
if not EnablePreview then
|
||||
exit;
|
||||
|
||||
if UnitInches then
|
||||
@ -125,19 +117,18 @@ begin
|
||||
|
||||
with pbPreview do
|
||||
begin
|
||||
|
||||
// page frame
|
||||
R := Rect(0,0,Width,Height);
|
||||
Canvas.Pen.Color := clBlack;
|
||||
Canvas.Brush.Color:=clWhite;
|
||||
Canvas.Rectangle(R);
|
||||
Canvas.Brush.Color := clWhite;
|
||||
Canvas.Rectangle(0, 0, Width, Height);
|
||||
|
||||
// hard margins
|
||||
Canvas.Pen.Color := clHighlight;
|
||||
DrawMargin(0, Round(txtLeft.Value * NToInches * Printer.XDPI * FFactorX * FZoom) ); //FHardMargins.Left
|
||||
DrawMargin(1, Round(txtTop.Value * NToInches * Printer.YDPI * FFactorY * FZoom) );
|
||||
DrawMargin(2, Round(txtRight.Value * NToInches * Printer.XDPI * FFactorX * FZoom) );
|
||||
DrawMargin(3, Round(txtBottom.Value * NToInches * Printer.YDPI * FFactorY * FZoom) );
|
||||
if EnableMargins then
|
||||
begin
|
||||
Canvas.Pen.Color := clHighlight;
|
||||
DrawMargin(0, Round(txtLeft.Value * NToInches * Printer.XDPI * FFactorX * FZoom) ); //FHardMargins.Left
|
||||
DrawMargin(1, Round(txtTop.Value * NToInches * Printer.YDPI * FFactorY * FZoom) );
|
||||
DrawMargin(2, Round(txtRight.Value * NToInches * Printer.XDPI * FFactorX * FZoom) );
|
||||
DrawMargin(3, Round(txtBottom.Value * NToInches * Printer.YDPI * FFactorY * FZoom) );
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
@ -172,7 +163,7 @@ procedure TframePageSetup.panPreviewResize(Sender: TObject);
|
||||
var
|
||||
TallH: Integer;
|
||||
begin
|
||||
if not (psoMargins in FOptions) then
|
||||
if not EnablePreview then
|
||||
exit;
|
||||
|
||||
TallH := Round(FheightTallest * FFactorY);
|
||||
@ -214,7 +205,7 @@ end;
|
||||
|
||||
procedure TframePageSetup.UpdatePageSize;
|
||||
begin
|
||||
if not (psoMargins in FOptions) then
|
||||
if not EnablePreview then
|
||||
exit;
|
||||
|
||||
with Printer.PaperSize.PaperRect.PhysicalRect do
|
||||
@ -241,22 +232,21 @@ begin
|
||||
{$ENDIF}
|
||||
end;
|
||||
|
||||
procedure TframePageSetup.Initialize(AMode: TPageSetupMode);
|
||||
procedure TframePageSetup.Initialize(AEnablePreview, AEnableMargins, AEnablePapers,
|
||||
AEnableOrientation: boolean);
|
||||
var
|
||||
i,j:Integer;
|
||||
R: TPaperRect;
|
||||
begin
|
||||
case AMode of
|
||||
psmMargins:
|
||||
FOptions := [psoMargins];
|
||||
psmPapers:
|
||||
FOptions := [psoPapers,psoOrientation];
|
||||
else
|
||||
FOptions := [psoMargins,psoPapers,psoOrientation];
|
||||
end;
|
||||
EnablePreview:= AEnablePreview;
|
||||
EnableMargins:= AEnableMargins;
|
||||
EnablePapers:= AEnablePapers;
|
||||
EnableOrientation:= AEnableOrientation;
|
||||
|
||||
if [psoMargins,psoPapers]*FOptions<>[] then
|
||||
gpPaper.Enabled := EnablePapers;
|
||||
if EnablePapers then
|
||||
begin
|
||||
SetupCupsCombo(cbSource, nil, 'InputSlot');
|
||||
SetupCupsCombo(cbPaper, nil, 'PageSize');
|
||||
if (cbPaper.Items.Count=0) then
|
||||
begin
|
||||
@ -267,13 +257,8 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
if psoPapers in FOptions then
|
||||
SetupCupsCOmbo(cbSource, nil, 'InputSlot')
|
||||
else
|
||||
gpPaper.Visible := false;
|
||||
|
||||
//TODO: support reverse variants too?
|
||||
gpOrientation.Visible := (psoOrientation in FOptions);
|
||||
gpOrientation.Enabled := EnableOrientation;
|
||||
case Printer.Orientation of
|
||||
poPortrait,poReversePortrait:
|
||||
radPortrait.Checked := true;
|
||||
@ -281,7 +266,10 @@ begin
|
||||
radLandscape.Checked := true;
|
||||
end;
|
||||
|
||||
if psoMargins in FOptions then
|
||||
gpMargins.Enabled := EnableMargins;
|
||||
panPreview.Visible:= EnablePreview;
|
||||
|
||||
if EnablePreview then
|
||||
begin
|
||||
// assume 100 pix = 8.5 inch (IOW, letter size width = 100 pixels)
|
||||
with ScreenInfo do
|
||||
@ -319,24 +307,7 @@ begin
|
||||
// zoom factor
|
||||
FZoom := 1.0;
|
||||
UpdatePageSize;
|
||||
|
||||
end else
|
||||
begin
|
||||
panPreview.Visible:=false;
|
||||
gpMargins.Visible:=false;
|
||||
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.
|
||||
|
@ -7,7 +7,6 @@ object dlgPageSetup: TdlgPageSetup
|
||||
Caption = 'dlgPageSetup'
|
||||
ClientHeight = 449
|
||||
ClientWidth = 446
|
||||
OnCreate = FormCreate
|
||||
Position = poScreenCenter
|
||||
LCLVersion = '1.9.0.0'
|
||||
inline frmPageSetup: TframePageSetup
|
||||
@ -49,6 +48,7 @@ object dlgPageSetup: TdlgPageSetup
|
||||
end
|
||||
end
|
||||
inherited panPreview: TPanel
|
||||
AnchorSideTop.Control = nil
|
||||
Height = 197
|
||||
Width = 446
|
||||
ClientHeight = 197
|
||||
|
@ -28,11 +28,11 @@ type
|
||||
btnOk: TButton;
|
||||
frmPageSetup: TframePageSetup;
|
||||
PanelButtons: TPanel;
|
||||
procedure FormCreate(Sender: TObject);
|
||||
private
|
||||
|
||||
public
|
||||
|
||||
procedure SetControls(AEnablePreview, AEnableMargins, AEnablePapers,
|
||||
AEnableOrientation: boolean);
|
||||
end;
|
||||
|
||||
var
|
||||
@ -44,9 +44,10 @@ implementation
|
||||
|
||||
{ TDlgPageSetup }
|
||||
|
||||
procedure TDlgPageSetup.FormCreate(Sender: TObject);
|
||||
procedure TDlgPageSetup.SetControls(AEnablePreview, AEnableMargins, AEnablePapers,
|
||||
AEnableOrientation: boolean);
|
||||
begin
|
||||
frmPageSetup.Initialize(psmFull);
|
||||
frmPageSetup.Initialize(AEnablePreview, AEnableMargins, AEnablePapers, AEnableOrientation);
|
||||
end;
|
||||
|
||||
end.
|
||||
|
Loading…
Reference in New Issue
Block a user