Merged revision(s) 43544 #767b677d3b, 43553-43554 #07ebd480ca-#07ebd480ca from trunk:

Printers (Windows): do not use a compiler directive to enable printing on Win9x systems (introduced in r39125 #de4e10c615).
Use at runtime detection to decide wether to call Ansi or Wide Windows API's and separate the used
structures into Ansi and Wide variants.
(Hiding Win9x functionality behind a compiler directive is inconsistent with current LCL behaviour)
Resolves issue #0025315.
........
Components, printers: fixed compilation with FPC > 2.6.2
........
Components, printers: Fix wrong compiler directive for compiler version detection in r43553 #07ebd480ca
........

git-svn-id: branches/fixes_1_2@43588 -
This commit is contained in:
maxim 2013-12-24 22:11:53 +00:00
parent f4a0392b5c
commit 993cbc5ae8
4 changed files with 659 additions and 459 deletions

File diff suppressed because it is too large Load Diff

View File

@ -22,6 +22,9 @@
uses
Classes, SysUtils,Printers,LCLType,{Forms,}Windows;//,dialogs;
const
UseUnicode: Boolean = True; //Determined at runtime
Type
THandleType = (htNone, htIC, htDC);

View File

@ -35,11 +35,10 @@ begin
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}
if UseUnicode then
SetWindowTextW(hdlg, pwidechar(lpp^.lCustData))
else
SetWindowText(hdlg,pChar(lpp^.lCustData));
Reposition(hdlg);
end;
Result := 0;
@ -53,11 +52,10 @@ begin
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}
if UseUnicode then
SetWindowTextW(hdlg, pwidechar(lpp^.lCustData))
else
SetWindowText(hdlg,pChar(lpp^.lCustData));
Reposition(hdlg);
end;
Result := 0;
@ -72,13 +70,11 @@ var
PDev : TPrinterDevice;
DeviceMode : THandle;
DevNames : PDevNames;
{$IFDEF USEUNICODE}
DevMode : PDeviceModeW;
St : PWidechar;
{$ELSE}
DevMode : PDeviceMode;
St : PChar;
{$ENDIF}
DevModeW : PDeviceModeW;
StW : PWidechar;
DevModeA : PDeviceMode;
StA : PChar;
BoolRes: BOOL;
begin
Result := False;
if not Assigned(Printer) then Exit;
@ -91,11 +87,12 @@ begin
hInstance := System.HInstance;
lpfnPageSetupHook := @PageSetupHookProc;
if Title<>'' then
{$IFDEF USEUNICODE}
lCustData := LPARAM(pWideChar(UTF8Decode(Title)))
{$ELSE}
lCustData := LPARAM(pChar(Utf8ToAnsi(Title)))
{$ENDIF}
begin
if UseUnicode then
lCustData := LPARAM(pWideChar(UTF8Decode(Title)))
else
lCustData := LPARAM(pChar(Utf8ToAnsi(Title)))
end
else
lCustData := 0;
Flags := PSD_MARGINS or PSD_ENABLEPAGESETUPHOOK;
@ -105,31 +102,40 @@ begin
// Pdev.DevMode has the required size, just copy to the global memory
DeviceMode := GLobalAlloc(GHND, PDev.DevModeSize);
try
DevMode := {$IFDEF USEUNICODE}PDeviceModeW{$ELSE}PDeviceMode{$ENDIF}(GlobalLock(DeviceMode));
if UseUnicode then
DevModeW := PDeviceModeW(GlobalLock(DeviceMode))
else
DevModeA := PDeviceModeA(GlobalLock(DeviceMode));
try
CopyMemory(DevMode, PDev.DevMode, Pdev.DevModeSize);
if UseUnicode then
CopyMemory(DevModeW, PDev.DevModeW, Pdev.DevModeSize)
else
CopyMemory(DevModeA, PDev.DevModeA, Pdev.DevModeSize);
finally
GlobalUnlock(DeviceMode);
end;
hDevMode := DeviceMode;
{$IFDEF USEUNICODE}
if PageSetupDlgW(@Lpp) then
{$ELSE}
if PageSetupDlg(@Lpp) then
{$ENDIF}
if UseUnicode then
BoolRes := PageSetupDlgW(@Lpp)
else
BoolRes := PageSetupDlg(@Lpp);
if BoolRes then
begin
St := '';
if UseUnicode then StW := '' else StA := '';
if Lpp.HdevNames <> 0 then
begin
DevNames := PDevNames(GlobalLock(lpp.hDevNames));
try
{$IFDEF USEUNICODE}
St := PWidechar(DEVNames) + DevNames^.wDeviceOffset;
Printer.SetPrinter(UTF8Encode(widestring(st)));
{$ELSE}
St := PChar(DevNames) + DevNames^.wDeviceOffset;
Printer.SetPrinter(St);
{$ENDIF}
if UseUnicode then
begin
StW := PWidechar(DEVNames) + DevNames^.wDeviceOffset;
Printer.SetPrinter(UTF8Encode(widestring(StW)));
end
else
begin
StA := PChar(DevNames) + DevNames^.wDeviceOffset;
Printer.SetPrinter(StA);
end
finally
GlobalUnlock(lpp.hDevNames);
GlobalFree(lpp.hDevNames);
@ -145,11 +151,17 @@ begin
if lpp.hDevMode <> 0 then
begin
DevMode := {$IFDEF USEUNICODE}PDeviceModeW{$ELSE}PDeviceMode{$ENDIF}(GlobalLock(lpp.hDevMode));
if UseUnicode then
DevModeW := PDeviceModeW(GlobalLock(lpp.hDevMode))
else
DevModeA := PDeviceModeA(GlobalLock(lpp.hDevMode));
try
//Set the properties for the selected printer
PDev := TPrinterDevice(Printer.Printers.Objects[Printer.PrinterIndex]);
CopyMemory(PDev.DevMode, DevMode, PDev.DevModeSize);
if UseUnicode then
CopyMemory(PDev.DevModeW, DevModeW, PDev.DevModeSize)
else
CopyMemory(PDev.DevModeA, DevModeA, PDev.DevModeSize);
finally
GlobalUnlock(lpp.hDevMode);
end;
@ -171,13 +183,11 @@ var
PDev : TPrinterDevice;
DeviceMode : THandle;
DevNames : PDevNames;
{$IFDEF USEUNICODE}
DevMode : PDeviceModeW;
St : PWidechar;
{$ELSE}
DevMode : PDeviceMode;
St : PChar;
{$ENDIF}
DevModeW : PDeviceModeW;
StW : PWidechar;
DevModeA : PDeviceMode;
StA : PChar;
BoolRes: BOOL;
begin
Result:=False;
if not Assigned(Printer) then Exit;
@ -190,11 +200,10 @@ begin
hInstance := System.HInstance;
lpfnSetupHook := @PrintHookProc;
if Title<>'' then
{$IFDEF USEUNICODE}
lCustData := LPARAM(pWideChar(UTF8Decode(Title)))
{$ELSE}
lCustData := LPARAM(pChar(Utf8ToAnsi(Title)))
{$ENDIF}
if UseUnicode then
lCustData := LPARAM(pWideChar(UTF8Decode(Title)))
else
lCustData := LPARAM(pChar(Utf8ToAnsi(Title)))
else
lCustData := 0;
Flags := PD_PRINTSETUP or PD_RETURNDC or PD_ENABLESETUPHOOK;
@ -203,32 +212,41 @@ begin
// Pdev.DevMode has the required size, just copy to the global memory
DeviceMode := GlobalAlloc(GHND, PDev.DevModeSize);
try
DevMode := {$IFDEF USEUNICODE}PDeviceModeW{$ELSE}PDeviceMode{$ENDIF}(GlobalLock(DeviceMode));
if UseUnicode then
DevModeW := PDeviceModeW(GlobalLock(DeviceMode))
else
DevModeA := PDeviceModeA(GlobalLock(DeviceMode));
try
CopyMemory(DevMode, Pdev.DevMode, Pdev.DevModeSize);
if useUnicode then
CopyMemory(DevModeW, Pdev.DevModeW, Pdev.DevModeSize)
else
CopyMemory(DevModeA, Pdev.DevModeA, Pdev.DevModeSize);
finally
GlobalUnlock(DeviceMode);
end;
hDevMode := DeviceMode;
{$IFDEF USEUNICODE}
if PrintDlgW(@lpp) then
{$ELSE}
if PrintDlg(@lpp) then
{$ENDIF}
if UseUnicode then
BoolRes := PrintDlgW(@lpp)
else
BoolRes := PrintDlg(@lpp);
if BoolRes then
begin
St := '';
if UseUnicode then StW := '' else StA := '';
//Change Selected printer
if lpp.hDevNames <> 0 then
begin
DevNames := PDevNames(GlobalLock(lpp.hDevNames));
try
{$IFDEF USEUNICODE}
St := PWidechar(DevNames) + DevNames^.wDeviceOffset;
Printer.SetPrinter(UTF8Encode(widestring(st)));
{$ELSE}
St := PChar(DevNames) + DevNames^.wDeviceOffset;
Printer.SetPrinter(St);
{$ENDIF}
if UseUnicode then
begin
StW := PWidechar(DevNames) + DevNames^.wDeviceOffset;
Printer.SetPrinter(UTF8Encode(widestring(StW)));
end
else
begin
StA := PChar(DevNames) + DevNames^.wDeviceOffset;
Printer.SetPrinter(StA);
end;
finally
GlobalUnlock(lpp.hDevNames);
GlobalFree(lpp.hDevNames);
@ -239,11 +257,17 @@ begin
if lpp.hDevMode <> 0 then
begin
DevMode := {$IFDEF USEUNICODE}PDeviceModeW{$ELSE}PDeviceMode{$ENDIF}(GlobalLock(lpp.hDevMode));
if UseUnicode then
DevModeW := PDeviceModeW(GlobalLock(lpp.hDevMode))
else
DevModeA := PDeviceMode(GlobalLock(lpp.hDevMode));
try
//Set the properties for the selected printer
PDev := TPrinterDevice(Printer.Printers.Objects[Printer.PrinterIndex]);
CopyMemory(PDev.DevMode, DevMode, PDev.DevModeSize);
if UseUnicode then
CopyMemory(PDev.DevModeW, DevModeW, PDev.DevModeSize)
else
CopyMemory(PDev.DevModeA, DevModeA, PDev.DevModeSize);
TWinPrinter(Printer).Handle := hDC;
finally
GlobalUnlock(lpp.hDevMode);
@ -266,13 +290,12 @@ var
PDev : TPrinterDevice;
DeviceMode : THandle;
DevNames : PDevNames;
{$IFDEF USEUNICODE}
DevMode : PDeviceModeW;
St : PWidechar;
{$ELSE}
DevMode : PDeviceMode;
St : PChar;
{$ENDIF}
DevModeW : PDeviceModeW;
StW : PWidechar;
DevModeA : PDeviceModeA;
StA : PChar;
BoolRes: BOOL;
Index: Integer;
begin
Result := False;
if not Assigned(Printer) then Exit;
@ -286,11 +309,12 @@ begin
lpfnPrintHook := @PrintHookProc;
lpfnSetupHook := @PrintHookProc;
if Title<>'' then
{$IFDEF USEUNICODE}
lCustData := LPARAM(pWideChar(UTF8Decode(Title)))
{$ELSE}
lCustData := LPARAM(pChar(Utf8ToAnsi(Title)))
{$ENDIF}
begin
if UseUnicode then
lCustData := LPARAM(pWideChar(UTF8Decode(Title)))
else
lCustData := LPARAM(pChar(Utf8ToAnsi(Title)));
end
else
lCustData := 0;
Flags := PD_ENABLEPRINTHOOK or PD_ENABLESETUPHOOK;
@ -316,9 +340,15 @@ begin
// Pdev.DevMode has the required size, just copy to the global memory
DeviceMode := GlobalAlloc(GHND, PDEV.DevModeSize);
try
DevMode := {$IFDEF USEUNICODE}PDeviceModeW{$ELSE}PDeviceMode{$ENDIF}(GlobalLock(DeviceMode));
if UseUnicode then
DevModeW := PDeviceModeW(GlobalLock(DeviceMode))
else
DevModeA := PDeviceModeA(GlobalLock(DeviceMode));
try
CopyMemory(DevMode, PDev.DevMode, PDev.DevModeSize);
if UseUnicode then
CopyMemory(DevModeW, PDev.DevModeW, PDev.DevModeSize)
else
CopyMemory(DevModeA, PDev.DevModeA, PDev.DevModeSize);
finally
GlobalUnlock(DeviceMode);
end;
@ -329,26 +359,32 @@ begin
nToPage := Word(ToPage);
nMinPage := Word(MinPage);
nMaxPage := Word(MaxPage);
DevMode^.dmCopies := nCopies;
{$IFDEF USEUNICODE}
if PrintDlgW(@lpp) then
{$ELSE}
if PrintDlg(@lpp) then
{$ENDIF}
if UseUnicode then
DevModeW^.dmCopies := nCopies
else
DevModeA^.dmCopies := nCopies;
if UseUnicode then
BoolRes := PrintDlgW(@lpp)
else
BoolRes := PrintDlg(@lpp);
if BoolRes then
begin
St:='';
if UseUnicode then StW := '' else StA:='';
//Change Selected printer
if lpp.hDevNames <> 0 then
begin
DevNames := PDevNames(GlobalLock(lpp.hDevNames));
try
{$IFDEF USEUNICODE}
St := PWidechar(DevNames) + DevNames^.wDeviceOffset;
Printer.SetPrinter(UTF8Encode(widestring(st)));
{$ELSE}
St := PChar(DevNames) + DevNames^.wDeviceOffset;
Printer.SetPrinter(St);
{$ENDIF}
if UseUnicode then
begin
StW := PWidechar(DevNames) + DevNames^.wDeviceOffset;
Printer.SetPrinter(UTF8Encode(widestring(stW)));
end
else
begin
StA := PChar(DevNames) + DevNames^.wDeviceOffset;
Printer.SetPrinter(StA);
end;
finally
GlobalUnlock(lpp.hDevNames);
GlobalFree(lpp.hDevNames);
@ -360,19 +396,45 @@ begin
// printer might have changed, check if new printer
// support extended device modes
PDev:=TPrinterDevice(Printer.Printers.Objects[Printer.PrinterIndex]);
if (lpp.hDevMode<>0) and (Pdev.DevMode<>nil) then
if (lpp.hDevMode<>0) and ( (UseUnicode and (Pdev.DevModeW<>nil)) or
((not UseUnicode) and (Pdev.DevModeA<>nil)))then
begin
DevMode:={$IFDEF USEUNICODE}PDeviceModeW{$ELSE}PDeviceMode{$ENDIF}(GlobalLock(lpp.hDevMode));
if UseUnicode then
DevModeW := PDeviceModeW(GlobalLock(lpp.hDevMode))
else
DevModeA := PDeviceModeA(GlobalLock(lpp.hDevMode));
try
CopyMemory(PDev.DevMode,DevMode,PDev.DevModeSize);
if Printer.PaperSize.SupportedPapers.IndexOfObject(TObject(ptrint(DevMode^.dmPaperSize))) <> -1
then
PDev.DevMode^.dmPaperSize := DevMode^.dmPaperSize
if UseUnicode then
CopyMemory(PDev.DevModeW,DevModeW,PDev.DevModeSize)
else
PDev.DevMode^.dmPaperSize := PDev.DefaultPaper;
CopyMemory(PDev.DevModeA,DevModeA,PDev.DevModeSize);
if UseUnicode then
Index := Printer.PaperSize.SupportedPapers.IndexOfObject(TObject(ptrint(DevModeW^.dmPaperSize)))
else
Index := Printer.PaperSize.SupportedPapers.IndexOfObject(TObject(ptrint(DevModeA^.dmPaperSize)));
if Index <> -1 then
begin
if UseUnicode then
PDev.DevModeW^.dmPaperSize := DevModeW^.dmPaperSize
else
PDev.DevModeA^.dmPaperSize := DevModeA^.dmPaperSize
end
else
begin
if Useunicode then
PDev.DevModeW^.dmPaperSize := PDev.DefaultPaper
else
PDev.DevModeA^.dmPaperSize := PDev.DefaultPaper
end;
if nCopies=1 then
Copies := DevMode^.dmCopies
begin
if UseUnicode then
Copies := DevModeW^.dmCopies
else
Copies := DevModeA^.dmCopies
end
else
Copies := nCopies;
Printer.Copies := Copies;

View File

@ -88,12 +88,6 @@ type
end;
PtagPD = ^tagPD;
{$IFDEF USEUNICODE}
LPTSTR = PWidechar;
{$ELSE}
LPTSTR = PChar;
{$ENDIF}
_PRINTER_DEFAULTSA = record
pDatatype : LPSTR;
pDevMode : LPDEVMODE;
@ -118,11 +112,7 @@ type
pDriverName : LPTSTR;
pComment : LPTSTR;
pLocation : LPTSTR;
{$IFDEF USEUNICODE}
pDevMode : LPDEVMODEW;
{$ELSE}
pDevMode : LPDEVMODE;
{$ENDIF}
pSepFile : LPTSTR;
pPrintProcessor : LPTSTR;
pDatatype : LPTSTR;
@ -145,6 +135,41 @@ type
PPRINTER_INFO_2 = ^PRINTER_INFO_2;
LPPRINTER_INFO_2 = ^PRINTER_INFO_2;
_PRINTER_INFO_2W = record
pServerName : LPWSTR;
pPrinterName : LPWSTR;
pShareName : LPWSTR;
pPortName : LPWSTR;
pDriverName : LPWSTR;
pComment : LPWSTR;
pLocation : LPWSTR;
pDevMode : LPDEVMODEW;
pSepFile : LPWSTR;
pPrintProcessor : LPWSTR;
pDatatype : LPWSTR;
pParameters : LPWSTR;
pSecurityDescriptor : PSECURITY_DESCRIPTOR;
Attributes : DWORD;
Priority : DWORD;
DefaultPriority : DWORD;
StartTime : DWORD;
UntilTime : DWORD;
Status : DWORD;
cJobs : DWORD;
AveragePPM : DWORD;
end;
PRINTER_INFO_2W = _PRINTER_INFO_2W;
PPRINTER_INFO_2W = ^_PRINTER_INFO_2W;
LPPRINTER_INFO_2W = ^_PRINTER_INFO_2W;
//PRINTER_INFO_2 = PRINTER_INFO_2W;
//PPRINTER_INFO_2 = ^PRINTER_INFO_2;
//LPPRINTER_INFO_2 = ^PRINTER_INFO_2;
_PRINTER_INFO_4A = record
pPrinterName : LPSTR;
pServerName : LPSTR;
@ -158,6 +183,19 @@ type
PPRINTER_INFO_4 = ^PRINTER_INFO_4;
LPPRINTER_INFO_4 = ^PRINTER_INFO_4;
_PRINTER_INFO_4W = record
pPrinterName : LPWSTR;
pServerName : LPWSTR;
Attributes : DWORD;
end;
PRINTER_INFO_4W = _PRINTER_INFO_4W;
PPRINTER_INFO_4W = ^_PRINTER_INFO_4W;
LPPRINTER_INFO_4W = ^_PRINTER_INFO_4W;
//PRINTER_INFO_4 = PRINTER_INFO_4W;
//PPRINTER_INFO_4 = ^PRINTER_INFO_4;
//LPPRINTER_INFO_4 = ^PRINTER_INFO_4;
type
{ TPrinterDevice }
@ -170,11 +208,8 @@ type
DefaultPaper: Short;
DefaultBin: short;
{$IFDEF USEUNICODE}
DevMode: PDeviceModeW;
{$ELSE}
DevMode: PDeviceMode;
{$ENDIF}
DevModeW: PDeviceModeW;
DevModeA: PDeviceModeA;
DevModeSize: integer;
destructor Destroy; override;
end;
@ -228,7 +263,8 @@ implementation
destructor TPrinterDevice.Destroy;
begin
ReallocMem(DevMode, 0);
ReallocMem(DevModeA, 0);
ReallocMem(DevModeW, 0);
inherited Destroy;
end;