Jacek Caban : wineps.drv: Export DrvDeviceCapabilities.

Alexandre Julliard julliard at winehq.org
Mon Sep 13 16:12:33 CDT 2021


Module: wine
Branch: master
Commit: a8c4020029af1d61c76a94c13431d228ea321bda
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=a8c4020029af1d61c76a94c13431d228ea321bda

Author: Jacek Caban <jacek at codeweavers.com>
Date:   Mon Sep 13 13:48:30 2021 +0200

wineps.drv: Export DrvDeviceCapabilities.

Allows wineps.drv to act as printer configuration interface DLL.

Signed-off-by: Jacek Caban <jacek at codeweavers.com>
Signed-off-by: Huw Davies <huw at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/wineps.drv/driver.c        | 101 +++++++++++++++++++++++++++++-----------
 dlls/wineps.drv/wineps.drv.spec |   3 ++
 include/ddk/winddiui.h          |   1 +
 3 files changed, 78 insertions(+), 27 deletions(-)

diff --git a/dlls/wineps.drv/driver.c b/dlls/wineps.drv/driver.c
index 27e1c6e03c8..c4dcd405c26 100644
--- a/dlls/wineps.drv/driver.c
+++ b/dlls/wineps.drv/driver.c
@@ -29,6 +29,7 @@
 
 #include "wine/debug.h"
 #include "psdrv.h"
+#include "ddk/winddiui.h"
 
 #include "winuser.h"
 #include "wine/wingdi16.h"
@@ -612,40 +613,87 @@ INT CDECL PSDRV_ExtDeviceMode(LPSTR lpszDriver, HWND hwnd, LPDEVMODEA lpdmOutput
  * Returns
  *      Result depends on the setting of fwCapability.  -1 indicates failure.
  */
-DWORD CDECL PSDRV_DeviceCapabilities(LPSTR lpszDriver, LPCSTR lpszDevice, LPCSTR lpszPort,
-                                     WORD fwCapability, LPSTR lpszOutput, LPDEVMODEA lpDevMode)
+DWORD CDECL PSDRV_DeviceCapabilities(char *driver, const char *device, const char *port,
+                                     WORD capability, char *output, DEVMODEA *devmodeA)
+{
+    WCHAR *device_name = NULL;
+    DEVMODEW *devmode = NULL;
+    DWORD ret, len;
+
+    len = MultiByteToWideChar(CP_ACP, 0, device, -1, NULL, 0);
+    if (len) {
+        device_name = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
+        MultiByteToWideChar(CP_ACP, 0, device, -1, device_name, len);
+    }
+
+    if (devmodeA) devmode = GdiConvertToDevmodeW( devmodeA );
+
+    if (output && (capability == DC_BINNAMES ||
+                   capability == DC_FILEDEPENDENCIES ||
+                   capability == DC_PAPERNAMES)) {
+        /* These need A -> W translation */
+        unsigned int size = 0, i;
+        WCHAR *outputW;
+
+        ret = DrvDeviceCapabilities(NULL, device_name, capability, NULL, devmode);
+        if (ret == -1) return ret;
+
+        switch (capability) {
+        case DC_BINNAMES:
+            size = 24;
+            break;
+        case DC_PAPERNAMES:
+        case DC_FILEDEPENDENCIES:
+            size = 64;
+            break;
+        }
+        outputW = HeapAlloc(GetProcessHeap(), 0, size * ret * sizeof(WCHAR));
+        ret = DrvDeviceCapabilities(NULL, device_name, capability, outputW, devmode);
+        for (i = 0; i < ret; i++)
+            WideCharToMultiByte(CP_ACP, 0, outputW + (i * size), -1,
+                                output + (i * size), size, NULL, NULL);
+        HeapFree(GetProcessHeap(), 0, outputW);
+    } else {
+        ret = DrvDeviceCapabilities(NULL, device_name, capability, output, devmode);
+    }
+    HeapFree(GetProcessHeap(), 0, device_name);
+    HeapFree(GetProcessHeap(), 0, devmode);
+    return ret;
+}
+
+/******************************************************************************
+ *           DrvDeviceCapabilities    (wineps.drv.@)
+ */
+DWORD WINAPI DrvDeviceCapabilities(HANDLE printer, WCHAR *device_name, WORD capability,
+                                   void *output, DEVMODEW *devmode)
 {
   PRINTERINFO *pi;
   DEVMODEW *lpdm;
   DWORD ret;
-  pi = PSDRV_FindPrinterInfoA(lpszDevice);
 
-  TRACE("%s %s %s, %u, %p, %p\n", debugstr_a(lpszDriver), debugstr_a(lpszDevice),
-        debugstr_a(lpszPort), fwCapability, lpszOutput, lpDevMode);
+  TRACE("%s %u, %p, %p\n", debugstr_w(device_name), capability, output, devmode);
 
-  if (!pi) {
-      ERR("no printer info for %s %s, return 0!\n",
-          debugstr_a(lpszDriver), debugstr_a(lpszDevice));
+  if (!(pi = PSDRV_FindPrinterInfo(device_name))) {
+      ERR("no printer info for %s, return 0!\n", debugstr_w(device_name));
       return 0;
   }
 
   lpdm = &pi->Devmode->dmPublic;
-  if (lpDevMode) lpdm = GdiConvertToDevmodeW( lpDevMode );
+  if (devmode) lpdm = devmode;
 
-  switch(fwCapability) {
+  switch(capability) {
 
   case DC_PAPERS:
     {
       PAGESIZE *ps;
-      WORD *wp = (WORD *)lpszOutput;
+      WORD *wp = output;
       int i = 0;
 
       LIST_FOR_EACH_ENTRY(ps, &pi->ppd->PageSizes, PAGESIZE, entry)
       {
         TRACE("DC_PAPERS: %u\n", ps->WinPage);
         i++;
-	if(lpszOutput != NULL)
-	  *wp++ = ps->WinPage;
+        if (output != NULL) *wp++ = ps->WinPage;
       }
       ret = i;
       break;
@@ -654,14 +702,14 @@ DWORD CDECL PSDRV_DeviceCapabilities(LPSTR lpszDriver, LPCSTR lpszDevice, LPCSTR
   case DC_PAPERSIZE:
     {
       PAGESIZE *ps;
-      POINT16 *pt = (POINT16 *)lpszOutput;
+      POINT16 *pt = output;
       int i = 0;
 
       LIST_FOR_EACH_ENTRY(ps, &pi->ppd->PageSizes, PAGESIZE, entry)
       {
         TRACE("DC_PAPERSIZE: %f x %f\n", ps->PaperDimension->x, ps->PaperDimension->y);
         i++;
-	if(lpszOutput != NULL) {
+        if (output != NULL) {
           pt->x = paper_size_from_points( ps->PaperDimension->x );
           pt->y = paper_size_from_points( ps->PaperDimension->y );
 	  pt++;
@@ -674,15 +722,15 @@ DWORD CDECL PSDRV_DeviceCapabilities(LPSTR lpszDriver, LPCSTR lpszDevice, LPCSTR
   case DC_PAPERNAMES:
     {
       PAGESIZE *ps;
-      char *cp = lpszOutput;
+      WCHAR *cp = output;
       int i = 0;
 
       LIST_FOR_EACH_ENTRY(ps, &pi->ppd->PageSizes, PAGESIZE, entry)
       {
         TRACE("DC_PAPERNAMES: %s\n", debugstr_a(ps->FullName));
         i++;
-	if(lpszOutput != NULL) {
-	  lstrcpynA(cp, ps->FullName, 64);
+        if (output != NULL) {
+          MultiByteToWideChar(CP_ACP, 0, ps->FullName, -1, cp, 64);
 	  cp += 64;
 	}
       }
@@ -697,13 +745,13 @@ DWORD CDECL PSDRV_DeviceCapabilities(LPSTR lpszDriver, LPCSTR lpszDevice, LPCSTR
   case DC_BINS:
     {
       INPUTSLOT *slot;
-      WORD *wp = (WORD *)lpszOutput;
+      WORD *wp = output;
       int i = 0;
 
       LIST_FOR_EACH_ENTRY( slot, &pi->ppd->InputSlots, INPUTSLOT, entry )
       {
           i++;
-          if (lpszOutput != NULL)
+          if (output != NULL)
               *wp++ = slot->WinBin;
       }
       ret = i;
@@ -713,15 +761,15 @@ DWORD CDECL PSDRV_DeviceCapabilities(LPSTR lpszDriver, LPCSTR lpszDevice, LPCSTR
   case DC_BINNAMES:
     {
       INPUTSLOT *slot;
-      char *cp = lpszOutput;
+      WCHAR *cp = output;
       int i = 0;
 
       LIST_FOR_EACH_ENTRY( slot, &pi->ppd->InputSlots, INPUTSLOT, entry )
       {
           i++;
-          if (lpszOutput != NULL)
+          if (output != NULL)
           {
-              lstrcpynA( cp, slot->FullName, 24 );
+              MultiByteToWideChar(CP_ACP, 0, slot->FullName, -1, cp, 24);
               cp += 24;
           }
       }
@@ -737,13 +785,13 @@ DWORD CDECL PSDRV_DeviceCapabilities(LPSTR lpszDriver, LPCSTR lpszDevice, LPCSTR
   case DC_ENUMRESOLUTIONS:
     {
         RESOLUTION *res;
-        LONG *lp = (LONG *)lpszOutput;
+        LONG *lp = output;
         int i = 0;
 
         LIST_FOR_EACH_ENTRY(res, &pi->ppd->Resolutions, RESOLUTION, entry)
         {
             i++;
-            if (lpszOutput != NULL)
+            if (output != NULL)
             {
                 lp[0] = res->resx;
                 lp[1] = res->resy;
@@ -936,11 +984,10 @@ DWORD CDECL PSDRV_DeviceCapabilities(LPSTR lpszDriver, LPCSTR lpszDevice, LPCSTR
     break;
 
   default:
-    FIXME("Unsupported capability %d\n", fwCapability);
+    FIXME("Unsupported capability %d\n", capability);
     ret = -1;
   }
 
-  if (lpDevMode) HeapFree( GetProcessHeap(), 0, lpdm );
   return ret;
 }
 
diff --git a/dlls/wineps.drv/wineps.drv.spec b/dlls/wineps.drv/wineps.drv.spec
index 176b9ac2f4b..6cd7e680350 100644
--- a/dlls/wineps.drv/wineps.drv.spec
+++ b/dlls/wineps.drv/wineps.drv.spec
@@ -1 +1,4 @@
 @ cdecl wine_get_gdi_driver(long) PSDRV_get_gdi_driver
+
+# Printer driver config exports
+@ stdcall DrvDeviceCapabilities(ptr wstr long ptr ptr)
diff --git a/include/ddk/winddiui.h b/include/ddk/winddiui.h
index 7c6e775b588..b5d0c707d81 100644
--- a/include/ddk/winddiui.h
+++ b/include/ddk/winddiui.h
@@ -40,6 +40,7 @@ extern "C" {
 
 #define PRINTER_EVENT_FLAG_NO_UI 1
 
+DWORD WINAPI DrvDeviceCapabilities(HANDLE, WCHAR *, WORD, void *, DEVMODEW *);
 BOOL WINAPI DrvDriverEvent(DWORD, DWORD, LPBYTE, LPARAM);
 BOOL WINAPI DrvPrinterEvent(LPWSTR, INT, DWORD, LPARAM);
 




More information about the wine-cvs mailing list