[PATCH] winspool: Implement AddFormA/W for level 1 forms
Marcel Partap
mpartap at gmx.net
Sat Apr 12 14:30:28 CDT 2008
---
dlls/winspool.drv/info.c | 111 ++++++++++++++++++++++++++++++++++++++++++++--
1 files changed, 107 insertions(+), 4 deletions(-)
diff --git a/dlls/winspool.drv/info.c b/dlls/winspool.drv/info.c
index 6d50a6d..23be2d2 100644
--- a/dlls/winspool.drv/info.c
+++ b/dlls/winspool.drv/info.c
@@ -168,6 +168,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','\\',
@@ -2768,20 +2774,117 @@ 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;
+ opened_printer_t *printer;
+ FORM_INFO_1W formW;
+ DWORD len;
+
+ TRACE("(%p, %d, %p)\n", hPrinter, Level, pForm);
+
+ if (Level != 1) {
+ SetLastError(ERROR_INVALID_LEVEL);
+ return FALSE;
+ }
+ printer = get_opened_printer(hPrinter);
+ if (!printer) {
+ SetLastError(ERROR_INVALID_HANDLE);
+ return FALSE;
+ }
+ if (!pForm) {
+ SetLastError(ERROR_INVALID_PARAMETER);
+ return FALSE;
+ }
+
+ memcpy(&formW, 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);
+ return FALSE;
+ }
+ formW.pName = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
+ MultiByteToWideChar(CP_ACP, 0, ((PFORM_INFO_1A)pForm)->pName, -1, formW.pName, len);
+ return AddFormW(hPrinter, Level, (LPBYTE)&formW);
}
/*****************************************************************************
* 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
+ *
+ * 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 endafw;
+ }
+ printer = get_opened_printer(hPrinter);
+ if (!printer) {
+ SetLastError(ERROR_INVALID_HANDLE);
+ goto endafw;
+ }
+ if (!pForm) {
+ SetLastError(ERROR_INVALID_PARAMETER);
+ goto endafw;
+ }
+ pfi = (PFORM_INFO_1W)pForm;
+ if (strlenW(pfi->pName) <= 0) {
+ SetLastError(ERROR_INVALID_FORM_NAME);
+ goto endafw;
+ }
+ if (pfi->Size.cx <= 0 || pfi->Size.cx <= 0 ||
+ pfi->ImageableArea.right <= 0 || pfi->ImageableArea.bottom <= 0) {
+ SetLastError(ERROR_INVALID_FORM_SIZE);
+ goto endafw;
+ }
+
+ if (RegCreateKeyW(HKEY_LOCAL_MACHINE, FormsW, &hformskey) != ERROR_SUCCESS) {
+ ERR("could not create reg key %s\n", debugstr_w(FormsW));
+ goto endafw;
+ }
+ if (RegQueryValueExW(hformskey, pfi->pName, 0, NULL, NULL, &size) == ERROR_SUCCESS && size > 0) {
+ SetLastError(ERROR_FILE_EXISTS);
+ goto endafw;
+ }
+ 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;
+ RegCloseKey(hformskey);
+
+endafw:
+ TRACE("returning %d with %d (0x%08x)\n", res, GetLastError(), GetLastError());
+ return res;
}
/*****************************************************************************
--
1.5.4.5
--------------020000090607010500090503--
More information about the wine-patches
mailing list