1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199
|
{ TPrinterSetupDialog }
function TPrinterSetupDialog.DoExecute: Boolean;
Var Dlg : Tdlgpropertiesprinter;
begin
Dlg:=TdlgPropertiesPrinter.Create(nil);
try
if (Title='') then
begin
if Printer<>nil then
Dlg.Caption := Printer.PrinterName;
end else
Dlg.Caption := Title;
Result:=(Dlg.ShowModal=mrOk);
if Result then
Dlg.InitProperties;
finally
Dlg.Free;
end;
end;
{ TPrintDialog }
function TPrintDialog.DoExecute: Boolean;
Var
Dlg : TdlgSelectPrinter;
i : Integer;
begin
Dlg:=TdlgSelectPrinter.Create(nil);
Dlg.Options := Self.Options;
Dlg.PrintRange := Self.PrintRange;
Dlg.cbCollate.Checked := Self.Collate;
Dlg.edCopies.Value := Self.Copies;
if Title<>'' then
Dlg.Caption := Title
else
Dlg.Caption := DefaultTitle;
if FromPage<1 then FromPage:=1;
if ToPage<FromPage then ToPage:=FromPage;
Dlg.edRange.Text := IntToStr(Self.FromPage) +'-'+ IntToStr(Self.ToPage);
case Dlg.PrintRange of
prAllPages: Dlg.rbAllPage.Checked := True;
prSelection: Dlg.rbSelection.Checked := True;
prPageNums: Dlg.rbRange.Checked := True;
prCurrentPage: Dlg.rbCurrentPage.Checked := True;
end;
try
Dlg.btnPreview.Visible:=False;
Result:=(Dlg.ShowModal=mrOk);
if Result then begin
// TDlgSelectPrinter will setup directoy cups printer options
// yet, TPrintDialog should return information about user choice
// modifying fields accordingly.
self.PrintRange:=dlg.PrintRange;
self.Collate := dlg.cbCollate.Checked;
self.Copies := dlg.edCopies.Value;
// Page range. This migth get really complex because it's free enty
// textbox. To fill FromPage and ToPage we will use some
// simple rules.
i := pos('-', Dlg.edRange.Text);
if i<>0 then begin
FromPage := StrToIntDef(Trim(Copy(Dlg.edRange.Text, 1, i-1)), FromPage);
ToPage := StrToIntDef(Trim(Copy(Dlg.edRange.Text, i+1, MaxInt)), ToPage);
if ToPage<FromPage then begin
i := ToPage;
ToPage := FromPage;
FromPage := i;
end;
end else begin
Self.FromPage := StrToIntDef(Trim(Dlg.edRange.Text), Self.FromPage);
Self.ToPage := Self.FromPage;
end;
end;
finally
Dlg.Free;
end;
end;
{ TPageSetupDialog }
function TPageSetupDialog.DoExecute: Boolean;
var
Dlg: TDlgPageSetup;
NDigits, NScale: integer;
NInc: double;
begin
if Printer.PrinterIndex<0 then
begin
if psoWarning in Options then
MessageDlg(Title, p4lrsNoDefaultPrinter, mtWarning, [mbOk], 0);
exit(false);
end;
// w/o SetPrinter, list of paper names is different
// (Letter / US Letter, EnvMonarch / Envelope Monarch),
// and list of sources is empty
Printer.SetPrinter(Printer.Printers[Printer.PrinterIndex]);
Dlg:= TDlgPageSetup.Create(nil);
try
if Title<>'' then
Dlg.Caption:= Title
else
Dlg.Caption:= DefaultTitle;
if FUnits=pmInches then
begin
Dlg.frmPageSetup.UnitInches:= true;
with Dlg.frmPageSetup.gpMargins do
Caption:= Caption+' '+p4lrsShortUnitsInches;
NDigits:= 2;
NInc:= 0.01;
// 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
NScale:= 1000;
end
else
begin
Dlg.frmPageSetup.UnitInches:= false;
with Dlg.frmPageSetup.gpMargins do
Caption:= Caption+' '+p4lrsShortUnitsMm;
NDigits:= 0;
NInc:= 1.0;
NScale:= 100;
end;
// after setting UnitInches
Dlg.SetControls(
not (psoDisablePagePainting in Options),
not (psoDisableMargins in Options),
not (psoDisablePaper in Options),
not (psoDisableOrientation in Options)
);
Dlg.btnPrinter.Enabled:= not (psoDisablePrinter in Options);
Dlg.frmPageSetup.txtLeft.DecimalPlaces:= NDigits;
Dlg.frmPageSetup.txtTop.DecimalPlaces:= NDigits;
Dlg.frmPageSetup.txtRight.DecimalPlaces:= NDigits;
Dlg.frmPageSetup.txtBottom.DecimalPlaces:= NDigits;
if psoMargins in Options then
begin
Dlg.frmPageSetup.txtLeft.Value:= FMarginLeft/NScale;
Dlg.frmPageSetup.txtTop.Value:= FMarginTop/NScale;
Dlg.frmPageSetup.txtRight.Value:= FMarginRight/NScale;
Dlg.frmPageSetup.txtBottom.Value:= FMarginBottom/NScale;
end
else
begin
// set margins 1 inch or 10 mm
Dlg.frmPageSetup.txtLeft.Value:= 1000/NScale;
Dlg.frmPageSetup.txtTop.Value:= 1000/NScale;
Dlg.frmPageSetup.txtRight.Value:= 1000/NScale;
Dlg.frmPageSetup.txtBottom.Value:= 1000/NScale;
end;
if psoDefaultMinMargins in Options then
begin
Dlg.frmPageSetup.SetDefaultMinMargins;
end;
if psoMinMargins in Options then
begin
Dlg.frmPageSetup.txtLeft.MinValue:= FMinMarginLeft/NScale;
Dlg.frmPageSetup.txtTop.MinValue:= FMinMarginTop/NScale;
Dlg.frmPageSetup.txtRight.MinValue:= FMinMarginRight/NScale;
Dlg.frmPageSetup.txtBottom.MinValue:= FMinMarginBottom/NScale;
end;
Dlg.frmPageSetup.txtLeft.Increment:= NInc;
Dlg.frmPageSetup.txtTop.Increment:= NInc;
Dlg.frmPageSetup.txtRight.Increment:= NInc;
Dlg.frmPageSetup.txtBottom.Increment:= NInc;
Dlg.frmPageSetup.UpdatePageSize;
Result:= Dlg.ShowModal=mrOk;
if Result then
begin
FMarginLeft:= Round(Dlg.frmPageSetup.txtLeft.Value*NScale);
FMarginTop:= Round(Dlg.frmPageSetup.txtTop.Value*NScale);
FMarginRight:= Round(Dlg.frmPageSetup.txtRight.Value*NScale);
FMarginBottom:= Round(Dlg.frmPageSetup.txtBottom.Value*NScale);
FPageWidth:= Round(Dlg.frmPageSetup.CurPageWidth*NScale);
FPageHeight:= Round(Dlg.frmPageSetup.CurPageHeight*NScale);
end;
finally
Dlg.Free;
end;
end;
|