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
|
{%MainUnit ../printersdlgs.pp}
{ TPageSetupDialog }
function TPageSetupDialog.DoExecute: Boolean;
var
PgDlg: QPageSetupDialogH;
Str: WideString;
{$IFDEF HASX11}
AWND: HWND;
{$ENDIF}
begin
Result := False;
if not Assigned(Printer) then Exit;
if Printer.Printers.Count <= 0 then Exit;
PgDlg := QPageSetupDialog_create(QtDefaultPrinter.Handle, nil);
if Title <> '' then
Str := UTF8Decode(Title)
else
Str := UTF8Decode(DefaultTitle);
QWidget_setWindowTitle(PgDlg, @Str);
try
Result := QPageSetupDialog_exec(PgDlg) = Ord(QDialogAccepted);
finally
QPageSetupDialog_destroy(PgDlg);
end;
{$IFDEF HASX11}
if (QtWidgetSet.WindowManagerName = 'xfwm4') and (QApplication_activeModalWidget() <> nil) then
begin
AWND := HwndFromWidgetH(QApplication_activeModalWidget());
if (AWND <> 0) and (X11GetActivewindow <> TQtWidget(AWND).Widget) then
X11Raise(QWidget_winID(TQtWidget(AWND).Widget));
end;
{$ENDIF}
end;
{ TPrinterSetupDialog }
function TPrinterSetupDialog.DoExecute: Boolean;
var
PgDlg: QPageSetupDialogH;
Str: WideString;
{$IFDEF HASX11}
AWND: HWND;
{$ENDIF}
begin
Result := False;
if not Assigned(Printer) then Exit;
if Printer.Printers.Count <= 0 then Exit;
{There's no special dialog for printer setup under Qt,
so we'll use QPageSetupDialog here.}
PgDlg := QPageSetupDialog_create(QtDefaultPrinter.Handle, nil);
if Title <> '' then
Str := UTF8Decode(Title)
else
Str := UTF8Decode(DefaultTitle);
QWidget_setWindowTitle(PgDlg, @Str);
try
Result := QPageSetupDialog_exec(PgDlg) = Ord(QDialogAccepted);
finally
QPageSetupDialog_destroy(PgDlg);
end;
{$IFDEF HASX11}
if (QtWidgetSet.WindowManagerName = 'xfwm4') and (QApplication_activeModalWidget() <> nil) then
begin
AWND := HwndFromWidgetH(QApplication_activeModalWidget());
if (AWND <> 0) and (X11GetActivewindow <> TQtWidget(AWND).Widget) then
X11Raise(QWidget_winID(TQtWidget(AWND).Widget));
end;
{$ENDIF}
end;
{ TPrintDialog }
function TPrintDialog.DoExecute: Boolean;
var
QtPrnDlg: QPrintDialogH;
PrnOptions: QAbstractPrintDialogPrintDialogOptions;
Str: WideString;
S: String;
{$IFDEF HASX11}
AWND: HWND;
{$ENDIF}
begin
Result := False;
if not Assigned(Printer) then Exit;
if Printer.Printers.Count <= 0 then Exit;
QtPrnDlg := QPrintDialog_create(QtDefaultPrinter.Handle, nil);
try
if Title <> '' then
Str := UTF8Decode(Title)
else
Str := UTF8Decode(DefaultTitle);
QWidget_setWindowTitle(QtPrnDlg, @Str);
if (Width > 0) and (Height > 0) then
QWidget_setBaseSize(QtPrnDlg, Width, Height);
{By default, full page printing is disabled. In this case, the origin of
the QPrinter's coordinate system coincides with the top-left corner
of the printable area. If full page printing is enabled, the origin of
the QPrinter's coordinate system coincides with the top-left corner of
the paper itself. In this case, the device metrics will report the
exact same dimensions as indicated by PageSize. It may not be
possible to print on the entire physical page because of the printer's
margins, so the application must account for the margins itself.
We can set this property from QtLCL OsPrinters too.
QtDefaultPrinter.FullPage := True;
THIS IS FIXED IN Qt-4.4, so PageRect returns correct dimensions !}
QAbstractPrintDialog_setMinMax(QtPrnDlg, MinPage, MaxPage);
QAbstractPrintDialog_setFromTo(QtPrnDlg, FromPage, ToPage);
PrnOptions := QAbstractPrintDialogPrintCollateCopies
or QAbstractPrintDialogPrintShowPageSize;
if (poPrintToFile in Options) then
PrnOptions := PrnOptions or QAbstractPrintDialogPrintToFile;
if (poSelection in Options) then
PrnOptions := PrnOptions or QAbstractPrintDialogPrintSelection;
if (poPageNums) in Options then
PrnOptions := PrnOptions or QAbstractPrintDialogPrintPageRange;
{this function does not have effect on Darwin}
QAbstractPrintDialog_setEnabledOptions(QtPrnDlg, PrnOptions);
QtDefaultPrinter.numCopies := Copies;
if PrintToFile then
QtDefaultPrinter.OutputFormat := QPrinterPdfFormat;
Result := QPrintDialog_exec(QtPrnDlg) = Ord(QDialogAccepted);
if Result then
begin
S := UTF16ToUTF8(QtDefaultPrinter.PrinterName);
if Printer.Printers.IndexOf(S) <> -1 then
Printer.SetPrinter(S);
Collate := QtDefaultPrinter.Collate;
MinPage := QAbstractPrintDialog_minPage(QtPrnDlg);
MaxPage := QAbstractPrintDialog_maxPage(QtPrnDlg);
FromPage := QtDefaultPrinter.fromPage;
ToPage := QtDefaultPrinter.toPage;
PrintToFile := QtDefaultPrinter.OutputFormat <> QPrinterNativeFormat;
Copies := QtDefaultPrinter.numCopies;
case QtDefaultPrinter.PrintRange of
QPrinterAllPages: PrintRange := prAllPages;
QPrinterSelection: PrintRange := prSelection;
QPrinterPageRange: PrintRange := prPageNums;
else
PrintRange := prCurrentPage;
end;
end;
finally
QPrintDialog_destroy(QtPrnDlg);
end;
{$IFDEF HASX11}
if (QtWidgetSet.WindowManagerName = 'xfwm4') and (QApplication_activeModalWidget() <> nil) then
begin
AWND := HwndFromWidgetH(QApplication_activeModalWidget());
if (AWND <> 0) and (X11GetActivewindow <> TQtWidget(AWND).Widget) then
X11Raise(QWidget_winID(TQtWidget(AWND).Widget));
end;
{$ENDIF}
end;
|