Printers, fix printer dialgos titles (win), modified patch from Boguslaw Brandys, issue #14186

git-svn-id: trunk@41082 -
This commit is contained in:
jesus 2013-05-09 05:47:33 +00:00
parent ae587f01ff
commit 5e53bcfafa

View File

@ -1,40 +1,69 @@
{%MainUnit ../printersdlgs.pp} {%MainUnit ../printersdlgs.pp}
function PrintHookProc(hdlg: HWND; uiMsg: UINT; wParam: WPARAM; lParam: LPARAM): UINT_PTR; stdcall; // update from win32wsdialogs.pp
procedure Reposition(ADialogWnd: Handle);
var
Left, Top: Integer;
ABounds, DialogRect: TRect;
begin
// Btw, setting width and height of dialog doesnot reposition child controls :(
// So no way to set another height and width at least here
// update from win32wsdialogs.pp if (GetParent(ADialogWnd) = Widgetset.AppHandle) then
procedure Reposition(ADialogWnd: Handle);
var
Left, Top: Integer;
ABounds, DialogRect: TRect;
begin begin
// Btw, setting width and height of dialog doesnot reposition child controls :( if Screen.ActiveCustomForm <> nil then
// So no way to set another height and width at least here ABounds := Screen.ActiveCustomForm.Monitor.BoundsRect
if (GetParent(ADialogWnd) = Widgetset.AppHandle) then
begin
if Screen.ActiveCustomForm <> nil then
ABounds := Screen.ActiveCustomForm.Monitor.BoundsRect
else
if Application.MainForm <> nil then
ABounds := Application.MainForm.Monitor.BoundsRect
else
ABounds := Screen.PrimaryMonitor.BoundsRect;
end
else else
ABounds := Screen.MonitorFromWindow(GetParent(ADialogWnd)).BoundsRect; if Application.MainForm <> nil then
GetWindowRect(ADialogWnd, DialogRect); ABounds := Application.MainForm.Monitor.BoundsRect
Left := (ABounds.Right - DialogRect.Right + DialogRect.Left) div 2; else
Top := (ABounds.Bottom - DialogRect.Bottom + DialogRect.Top) div 2; ABounds := Screen.PrimaryMonitor.BoundsRect;
SetWindowPos(ADialogWnd, HWND_TOP, Left, Top, 0, 0, SWP_NOSIZE); end
end; else
ABounds := Screen.MonitorFromWindow(GetParent(ADialogWnd)).BoundsRect;
GetWindowRect(ADialogWnd, DialogRect);
Left := (ABounds.Right - DialogRect.Right + DialogRect.Left) div 2;
Top := (ABounds.Bottom - DialogRect.Bottom + DialogRect.Top) div 2;
SetWindowPos(ADialogWnd, HWND_TOP, Left, Top, 0, 0, SWP_NOSIZE);
end;
function PrintHookProc(hdlg: HWND; uiMsg: UINT; wParam: WPARAM; lParam: LPARAM): UINT_PTR; stdcall;
var
lpp: PtagPD;
begin begin
if uiMsg = WM_INITDIALOG then if uiMsg = WM_INITDIALOG then
begin
lpp := PtagPD(lParam);
if (lParam<>0) and (lpp^.lCustData<>0) then
{$IFDEF USEUNICODE}
SetWindowTextW(hdlg, pwidechar(lpp^.lCustData));
{$ELSE}
SetWindowText(hdlg,pChar(lpp^.lCustData));
{$ENDIF}
Reposition(hdlg); Reposition(hdlg);
end;
Result := 0; Result := 0;
end; end;
function PageSetupHookProc(hdlg: HWND; uiMsg: UINT; wParam: WPARAM; lParam: LPARAM): PtrUInt; stdcall;
var
lpp : PtagPSD;
begin
if uiMsg = WM_INITDIALOG then
begin
lpp := PtagPSD(lParam);
if (lParam<>0) and (lpp^.lCustData<>0) then
{$IFDEF USEUNICODE}
SetWindowTextW(hdlg, pwidechar(lpp^.lCustData));
{$ELSE}
SetWindowText(hdlg,pChar(lpp^.lCustData));
{$ENDIF}
Reposition(hdlg);
end;
Result := 0;
end;
{ TPageSetupDialog } { TPageSetupDialog }
function TPageSetupDialog.Execute: Boolean; function TPageSetupDialog.Execute: Boolean;
@ -60,7 +89,15 @@ begin
begin begin
lStructSize := SizeOf(lpp); lStructSize := SizeOf(lpp);
hInstance := System.HInstance; hInstance := System.HInstance;
lpfnPageSetupHook := @PrintHookProc; lpfnPageSetupHook := @PageSetupHookProc;
if Title<>'' then
{$IFDEF USEUNICODE}
lCustData := LPARAM(pWideChar(UTF8Decode(Title)))
{$ELSE}
lCustData := LPARAM(pChar(Utf8ToAnsi(Title)))
{$ENDIF}
else
lCustData := 0;
Flags := PSD_MARGINS or PSD_ENABLEPAGESETUPHOOK; Flags := PSD_MARGINS or PSD_ENABLEPAGESETUPHOOK;
hWndOwner := Widgetset.AppHandle; hWndOwner := Widgetset.AppHandle;
rtMargin := fMargins; rtMargin := fMargins;
@ -152,6 +189,14 @@ begin
lStructSize := SizeOf(lpp); lStructSize := SizeOf(lpp);
hInstance := System.HInstance; hInstance := System.HInstance;
lpfnSetupHook := @PrintHookProc; lpfnSetupHook := @PrintHookProc;
if Title<>'' then
{$IFDEF USEUNICODE}
lCustData := LPARAM(pWideChar(UTF8Decode(Title)))
{$ELSE}
lCustData := LPARAM(pChar(Utf8ToAnsi(Title)))
{$ENDIF}
else
lCustData := 0;
Flags := PD_PRINTSETUP or PD_RETURNDC or PD_ENABLESETUPHOOK; Flags := PD_PRINTSETUP or PD_RETURNDC or PD_ENABLESETUPHOOK;
hWndOwner := Widgetset.AppHandle; hWndOwner := Widgetset.AppHandle;
PDev := TPrinterDevice(Printer.Printers.Objects[Printer.PrinterIndex]); PDev := TPrinterDevice(Printer.Printers.Objects[Printer.PrinterIndex]);
@ -240,6 +285,14 @@ begin
hInstance := System.HInstance; hInstance := System.HInstance;
lpfnPrintHook := @PrintHookProc; lpfnPrintHook := @PrintHookProc;
lpfnSetupHook := @PrintHookProc; lpfnSetupHook := @PrintHookProc;
if Title<>'' then
{$IFDEF USEUNICODE}
lCustData := LPARAM(pWideChar(UTF8Decode(Title)))
{$ELSE}
lCustData := LPARAM(pChar(Utf8ToAnsi(Title)))
{$ENDIF}
else
lCustData := 0;
Flags := PD_ENABLEPRINTHOOK or PD_ENABLESETUPHOOK; Flags := PD_ENABLEPRINTHOOK or PD_ENABLESETUPHOOK;
if not Printer.RawMode then if not Printer.RawMode then
Flags := Flags or PD_RETURNDC; Flags := Flags or PD_RETURNDC;