[PATCH] winspool: Implement AddFormA/W for level 1 forms

Marcel Partap mpartap at gmx.net
Sun Apr 27 14:51:05 CDT 2008


---
 dlls/winspool.drv/info.c |  110 ++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 106 insertions(+), 4 deletions(-)

diff --git a/dlls/winspool.drv/info.c b/dlls/winspool.drv/info.c
index f8abdf2..f06933a 100644
--- a/dlls/winspool.drv/info.c
+++ b/dlls/winspool.drv/info.c
@@ -166,6 +166,12 @@ static const WCHAR DriversW[] = { 'S','y','s','t','e','m','\\',
                                   'E','n','v','i','r','o','n','m','e','n','t','s','\\',
                                   '%','s','\\','D','r','i','v','e','r','s','%','s',0 };
 
+static const WCHAR FormsW[] = { 'S','y','s','t','e','m','\\',
+                                'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
+                                'c','o','n','t','r','o','l','\\',
+                                'P','r','i','n','t','\\',
+                                'F','o','r','m','s',0 };
+
 static const WCHAR MonitorsW[] =  { 'S','y','s','t','e','m','\\',
                                   'C','u', 'r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
                                   'C','o','n','t','r','o','l','\\',
@@ -2712,20 +2718,116 @@ end:
 
 /*****************************************************************************
  *          AddFormA  [WINSPOOL.@]
+ * See AddFormsW
  */
 BOOL WINAPI AddFormA(HANDLE hPrinter, DWORD Level, LPBYTE pForm)
 {
-    FIXME("(%p,%d,%p): stub\n", hPrinter, Level, pForm);
-    return 1;
+    PFORM_INFO_1W pFormW = NULL;
+    DWORD        len;
+    BOOL         res = FALSE;
+
+    TRACE("(%p, %d, %p)\n", hPrinter, Level, pForm);
+
+    if (pForm) {
+        pFormW = HeapAlloc(GetProcessHeap(), 0, sizeof(FORM_INFO_1W));
+        memcpy(pFormW, pForm, sizeof(FORM_INFO_1A));
+
+        /* convert form name to unicode */
+        len = MultiByteToWideChar(CP_ACP, 0, ((PFORM_INFO_1A)pForm)->pName, -1, NULL, 0);
+        if (len == 0) {
+           SetLastError(ERROR_INVALID_FORM_NAME);
+           goto afa_cleanup;
+        }
+        pFormW->pName = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
+        MultiByteToWideChar(CP_ACP, 0, ((PFORM_INFO_1A)pForm)->pName, -1, pFormW->pName, len);
+    }
+    res = AddFormW(hPrinter, Level, (LPBYTE)pFormW);
+
+afa_cleanup:
+    if (pFormW) {
+        if (pFormW->pName) HeapFree(GetProcessHeap(), 0, pFormW->pName);
+        HeapFree(GetProcessHeap(), 0, pFormW);
+    }
+
+    TRACE("returning %d with %d\n", res, GetLastError());
+    return res;
 }
 
 /*****************************************************************************
  *          AddFormW  [WINSPOOL.@]
+ *
+ * adds a print form to the system configuration
+ *
+ * PARAMS
+ *  hPrinter (I) valid printer handle
+ *  Level    (I) form info level
+ *  pForm    (I) pointer to the buffer to be added
+ *
+ * RETURNS
+ *  Success: TRUE
+ *  Failure: FALSE
+ *
+ * NOTES
+ *  fixme: no level 2 support
+ *
  */
 BOOL WINAPI AddFormW(HANDLE hPrinter, DWORD Level, LPBYTE pForm)
 {
-    FIXME("(%p,%d,%p): stub\n", hPrinter, Level, pForm);
-    return 1;
+    opened_printer_t *printer;
+    form_regentry_t   form;
+    PFORM_INFO_1W     pfi;
+    HKEY   hformskey = NULL;
+    DWORD  size = 0;
+    BOOL   res = FALSE;
+
+    TRACE("(%p, %d, %p)\n", hPrinter, Level, pForm);
+
+    if (Level != 1) {
+        if (Level == 2)
+            FIXME("level 2 not yet supported\n");
+        SetLastError(ERROR_INVALID_LEVEL);
+        goto afw_cleanup;
+    }
+    printer = get_opened_printer(hPrinter);
+    if (!printer) {
+        SetLastError(ERROR_INVALID_HANDLE);
+        goto afw_cleanup;
+    }
+    if (!pForm) {
+        SetLastError(ERROR_INVALID_PARAMETER);
+        goto afw_cleanup;
+    }
+    pfi = (PFORM_INFO_1W)pForm;
+    if (strlenW(pfi->pName) <= 0) {
+        SetLastError(ERROR_INVALID_FORM_NAME);
+        goto afw_cleanup;
+    }
+    if (pfi->Size.cx <= 0 || pfi->Size.cx <= 0 ||
+        pfi->ImageableArea.right <= 0 || pfi->ImageableArea.bottom <= 0) {
+        SetLastError(ERROR_INVALID_FORM_SIZE);
+        goto afw_cleanup;
+    }
+
+    if (RegCreateKeyW(HKEY_LOCAL_MACHINE, FormsW, &hformskey) != ERROR_SUCCESS) {
+        ERR("could not create reg key %s\n", debugstr_w(FormsW));
+        goto afw_cleanup;
+    }
+    if (RegQueryValueExW(hformskey, pfi->pName, 0, NULL, NULL, &size) == ERROR_SUCCESS && size > 0) {
+        SetLastError(ERROR_FILE_EXISTS);
+        goto afw_cleanup;
+    }
+    memcpy(&form.size, &pfi->Size, sizeof(SIZEL));
+    memcpy(&form.area, &pfi->ImageableArea, sizeof(RECTL));
+    form.formorder = 0;
+    form.flags = pfi->Flags;
+    if (RegSetValueExW(hformskey, pfi->pName, 0, REG_BINARY, (LPBYTE)&form, sizeof(form)) == ERROR_SUCCESS)
+        res = TRUE;
+
+afw_cleanup:
+    if (hformskey) RegCloseKey(hformskey);
+
+    TRACE("returning %d with %d\n", res, GetLastError());
+    return res;
 }
 
 /*****************************************************************************
-- 
1.5.5.1


--------------080708060500090004000007--



More information about the wine-patches mailing list