Huw Davies : winspool: Move the default page size query to cups.c.

Alexandre Julliard julliard at winehq.org
Tue Oct 26 16:19:19 CDT 2021


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

Author: Huw Davies <huw at codeweavers.com>
Date:   Tue Oct 26 11:18:12 2021 +0100

winspool: Move the default page size query to cups.c.

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

---

 dlls/winspool.drv/cups.c   |  97 ++++++++++++++++++++++++++++++++++++++++
 dlls/winspool.drv/info.c   | 108 ++++++---------------------------------------
 dlls/winspool.drv/wspool.h |   7 +++
 3 files changed, 117 insertions(+), 95 deletions(-)

diff --git a/dlls/winspool.drv/cups.c b/dlls/winspool.drv/cups.c
index 2ce5f43fa8f..ae771eba46c 100644
--- a/dlls/winspool.drv/cups.c
+++ b/dlls/winspool.drv/cups.c
@@ -32,6 +32,62 @@
 #include <cups/ppd.h>
 #endif
 
+#ifdef HAVE_APPLICATIONSERVICES_APPLICATIONSERVICES_H
+#define GetCurrentProcess GetCurrentProcess_Mac
+#define GetCurrentThread GetCurrentThread_Mac
+#define LoadResource LoadResource_Mac
+#define AnimatePalette AnimatePalette_Mac
+#define EqualRgn EqualRgn_Mac
+#define FillRgn FillRgn_Mac
+#define FrameRgn FrameRgn_Mac
+#define GetPixel GetPixel_Mac
+#define InvertRgn InvertRgn_Mac
+#define LineTo LineTo_Mac
+#define OffsetRgn OffsetRgn_Mac
+#define PaintRgn PaintRgn_Mac
+#define Polygon Polygon_Mac
+#define ResizePalette ResizePalette_Mac
+#define SetRectRgn SetRectRgn_Mac
+#define EqualRect EqualRect_Mac
+#define FillRect FillRect_Mac
+#define FrameRect FrameRect_Mac
+#define GetCursor GetCursor_Mac
+#define InvertRect InvertRect_Mac
+#define OffsetRect OffsetRect_Mac
+#define PtInRect PtInRect_Mac
+#define SetCursor SetCursor_Mac
+#define SetRect SetRect_Mac
+#define ShowCursor ShowCursor_Mac
+#define UnionRect UnionRect_Mac
+#include <ApplicationServices/ApplicationServices.h>
+#undef GetCurrentProcess
+#undef GetCurrentThread
+#undef LoadResource
+#undef AnimatePalette
+#undef EqualRgn
+#undef FillRgn
+#undef FrameRgn
+#undef GetPixel
+#undef InvertRgn
+#undef LineTo
+#undef OffsetRgn
+#undef PaintRgn
+#undef Polygon
+#undef ResizePalette
+#undef SetRectRgn
+#undef EqualRect
+#undef FillRect
+#undef FrameRect
+#undef GetCursor
+#undef InvertRect
+#undef OffsetRect
+#undef PtInRect
+#undef SetCursor
+#undef SetRect
+#undef ShowCursor
+#undef UnionRect
+#endif
+
 #include "ntstatus.h"
 #define WIN32_NO_STATUS
 #include "windef.h"
@@ -341,3 +397,44 @@ NTSTATUS unix_get_ppd( void *args )
     free( unix_ppd );
     return status;
 }
+
+NTSTATUS unix_get_default_page_size( void *args )
+{
+#ifdef HAVE_APPLICATIONSERVICES_APPLICATIONSERVICES_H
+    struct get_default_page_size_params *params = args;
+    NTSTATUS status = STATUS_UNSUCCESSFUL;
+    PMPrintSession session = NULL;
+    PMPageFormat format = NULL;
+    CFStringRef paper_name;
+    PMPaper paper;
+    CFRange range;
+    int size;
+
+    if (PMCreateSession( &session )) goto end;
+    if (PMCreatePageFormat( &format )) goto end;
+    if (PMSessionDefaultPageFormat( session, format )) goto end;
+    if (PMGetPageFormatPaper( format, &paper )) goto end;
+    if (PMPaperGetPPDPaperName( paper, &paper_name )) goto end;
+
+    range.location = 0;
+    range.length = CFStringGetLength( paper_name );
+    size = (range.length + 1) * sizeof(WCHAR);
+
+    if (params->name_size >= size)
+    {
+        CFStringGetCharacters( paper_name, range, (UniChar*)params->name );
+        params->name[range.length] = 0;
+        status = STATUS_SUCCESS;
+    }
+    else
+        status = STATUS_BUFFER_OVERFLOW;
+    params->name_size = size;
+
+end:
+    if (format) PMRelease( format );
+    if (session) PMRelease( session );
+    return status;
+#else
+    return STATUS_NOT_IMPLEMENTED;
+#endif
+}
diff --git a/dlls/winspool.drv/info.c b/dlls/winspool.drv/info.c
index 5deab0083d3..a8b0a0365ae 100644
--- a/dlls/winspool.drv/info.c
+++ b/dlls/winspool.drv/info.c
@@ -48,62 +48,6 @@
 # include <cups/ppd.h>
 #endif
 
-#ifdef HAVE_APPLICATIONSERVICES_APPLICATIONSERVICES_H
-#define GetCurrentProcess GetCurrentProcess_Mac
-#define GetCurrentThread GetCurrentThread_Mac
-#define LoadResource LoadResource_Mac
-#define AnimatePalette AnimatePalette_Mac
-#define EqualRgn EqualRgn_Mac
-#define FillRgn FillRgn_Mac
-#define FrameRgn FrameRgn_Mac
-#define GetPixel GetPixel_Mac
-#define InvertRgn InvertRgn_Mac
-#define LineTo LineTo_Mac
-#define OffsetRgn OffsetRgn_Mac
-#define PaintRgn PaintRgn_Mac
-#define Polygon Polygon_Mac
-#define ResizePalette ResizePalette_Mac
-#define SetRectRgn SetRectRgn_Mac
-#define EqualRect EqualRect_Mac
-#define FillRect FillRect_Mac
-#define FrameRect FrameRect_Mac
-#define GetCursor GetCursor_Mac
-#define InvertRect InvertRect_Mac
-#define OffsetRect OffsetRect_Mac
-#define PtInRect PtInRect_Mac
-#define SetCursor SetCursor_Mac
-#define SetRect SetRect_Mac
-#define ShowCursor ShowCursor_Mac
-#define UnionRect UnionRect_Mac
-#include <ApplicationServices/ApplicationServices.h>
-#undef GetCurrentProcess
-#undef GetCurrentThread
-#undef LoadResource
-#undef AnimatePalette
-#undef EqualRgn
-#undef FillRgn
-#undef FrameRgn
-#undef GetPixel
-#undef InvertRgn
-#undef LineTo
-#undef OffsetRgn
-#undef PaintRgn
-#undef Polygon
-#undef ResizePalette
-#undef SetRectRgn
-#undef EqualRect
-#undef FillRect
-#undef FrameRect
-#undef GetCursor
-#undef InvertRect
-#undef OffsetRect
-#undef PtInRect
-#undef SetCursor
-#undef SetRect
-#undef ShowCursor
-#undef UnionRect
-#endif
-
 #define NONAMELESSSTRUCT
 #define NONAMELESSUNION
 
@@ -987,46 +931,20 @@ end:
 
 static void set_ppd_overrides( HANDLE printer )
 {
-    WCHAR *wstr = NULL;
-    int size = 0;
-#ifdef HAVE_APPLICATIONSERVICES_APPLICATIONSERVICES_H
-    OSStatus status;
-    PMPrintSession session = NULL;
-    PMPageFormat format = NULL;
-    PMPaper paper;
-    CFStringRef paper_name;
-    CFRange range;
-
-    status = PMCreateSession( &session );
-    if (status) goto end;
-
-    status = PMCreatePageFormat( &format );
-    if (status) goto end;
-
-    status = PMSessionDefaultPageFormat( session, format );
-    if (status) goto end;
-
-    status = PMGetPageFormatPaper( format, &paper );
-    if (status) goto end;
-
-    status = PMPaperGetPPDPaperName( paper, &paper_name );
-    if (status) goto end;
-
-    range.location = 0;
-    range.length = CFStringGetLength( paper_name );
-    size = (range.length + 1) * sizeof(WCHAR);
-
-    wstr = HeapAlloc( GetProcessHeap(), 0, size );
-    CFStringGetCharacters( paper_name, range, (UniChar*)wstr );
-    wstr[range.length] = 0;
-
-end:
-    if (format) PMRelease( format );
-    if (session) PMRelease( session );
-#endif
+    WCHAR buffer[256];
+    struct get_default_page_size_params params = { .name = buffer, .name_size = sizeof(buffer) };
+    NTSTATUS status;
 
-    SetPrinterDataExW( printer, PPD_Overrides, DefaultPageSize, REG_SZ, (BYTE*)wstr, size );
-    HeapFree( GetProcessHeap(), 0, wstr );
+    while (1)
+    {
+        status = UNIX_CALL( get_default_page_size, &params );
+        if (status != STATUS_BUFFER_OVERFLOW) break;
+        if (params.name != buffer) heap_free( params.name );
+        params.name = heap_alloc( params.name_size );
+        if (!params.name) break;
+    }
+    if (!status) SetPrinterDataExW( printer, PPD_Overrides, DefaultPageSize, REG_SZ, (BYTE*)params.name, params.name_size );
+    if (params.name != buffer) heap_free( params.name );
 }
 
 static BOOL update_driver( HANDLE printer )
diff --git a/dlls/winspool.drv/wspool.h b/dlls/winspool.drv/wspool.h
index e66e08bfee0..578ed39733d 100644
--- a/dlls/winspool.drv/wspool.h
+++ b/dlls/winspool.drv/wspool.h
@@ -52,6 +52,12 @@ struct enum_printers_params
     unsigned int num;
 };
 
+struct get_default_page_size_params
+{
+    WCHAR *name;
+    unsigned int name_size;
+};
+
 struct get_ppd_params
 {
     const WCHAR *printer; /* set to NULL to unlink */
@@ -62,4 +68,5 @@ struct get_ppd_params
 
 NTSTATUS unix_process_attach( void * ) DECLSPEC_HIDDEN;
 NTSTATUS unix_enum_printers( void * ) DECLSPEC_HIDDEN;
+NTSTATUS unix_get_default_page_size( void * ) DECLSPEC_HIDDEN;
 NTSTATUS unix_get_ppd( void * ) DECLSPEC_HIDDEN;




More information about the wine-cvs mailing list