2 * Implementation of the Printer User Interface Dialogs
4 * Copyright 2006-2007 Detlef Riekenberg
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #define NONAMELESSUNION
35 #include "wine/unicode.h"
36 #include "wine/debug.h"
37 #include "printui_private.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(printui);
41 static HINSTANCE PRINTUI_hInstance = NULL;
43 /* ################################# */
45 /* Must be in order with OPT_* */
46 static const WCHAR optionsW[OPT_MAX+1]={'a','b','c','f','h','j','l','m','n','t','r','v',0};
48 /* Must be in order with FLAG_* */
49 static const WCHAR flagsW[FLAG_MAX+1]={'q','w','y','z','Z',0};
52 /* ################################
53 * get_next_wstr() [Internal]
55 * Get the next WSTR, when available
59 static LPWSTR get_next_wstr(context_t * cx)
65 cx->pNextCharW = NULL;
69 /* Get the next Parameter, when available */
70 if (cx->next_arg < cx->argc) {
71 ptr = cx->argv[cx->next_arg];
73 cx->pNextCharW = NULL;
80 /* ################################
81 * get_next_wchar() [Internal]
83 * Get the next WCHAR from the Commandline or from the File (@ Filename)
85 * ToDo: Support Parameter from a File ( "@Filename" )
89 static WCHAR get_next_wchar(context_t * cx, BOOL use_next_parameter)
93 /* Try the next WCHAR in the actual Parameter */
100 /* We reached the end of the Parameter */
101 cx->pNextCharW = NULL;
104 /* Get the next Parameter, when available and allowed */
105 if ((cx->pNextCharW == NULL) && (cx->next_arg < cx->argc) && (use_next_parameter)) {
106 cx->pNextCharW = cx->argv[cx->next_arg];
110 if (cx->pNextCharW) {
117 /* We reached the end of the Parameter */
118 cx->pNextCharW = NULL;
125 /* ################################ */
126 static BOOL parse_rundll(context_t * cx)
134 c = get_next_wchar(cx, TRUE);
140 while ( (c == ' ') || (c == '\t'))
142 c = get_next_wchar(cx, TRUE);
147 /* read commands from a File */
148 ptr = get_next_wstr(cx);
149 FIXME("redir not supported: %s\n", debugstr_w(ptr));
153 c = get_next_wchar(cx, FALSE);
157 ptr = strchrW(optionsW, c);
159 index = ptr - optionsW;
160 cx->options[index] = get_next_wstr(cx);
161 TRACE(" opt: %s %s\n", debugstr_w(txtW), debugstr_w(cx->options[index]));
166 ptr = strchrW(flagsW, c);
168 index = ptr - flagsW;
169 cx->flags[index] = TRUE;
170 TRACE("flag: %s\n", debugstr_w(txtW));
175 cx->subcommand = '\0';
176 TRACE(" cmd: %s\n", debugstr_w(txtW));
179 /* help has priority over all commands */
184 c = get_next_wchar(cx, FALSE);
186 /* Some commands use two wchar */
187 if ((cx->command == 'd') || (cx->command == 'g') || (cx->command == 'i') ||
188 (cx->command == 'S') || (cx->command == 'X') ){
191 TRACE(" sub: %s\n", debugstr_w(txtW));
192 c = get_next_wchar(cx, FALSE);
196 c = get_next_wchar(cx, TRUE);
201 /* The commands 'S' and 'X' have additional Parameter */
202 if ((cx->command == 'S') || (cx->command == 'X')) {
204 /* the actual WCHAR is the start from the extra Parameter */
206 TRACE("%d extra Parameter, starting with %s\n", 1 + (cx->argc - cx->next_arg), debugstr_w(cx->pNextCharW));
209 FIXME("0x%x: %s is unknown\n", c, debugstr_wn(&c, 1));
217 /*****************************************************
220 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
222 TRACE("(%p, %d, %p)\n",hinstDLL, fdwReason, lpvReserved);
226 case DLL_WINE_PREATTACH:
227 return FALSE; /* prefer native version */
229 case DLL_PROCESS_ATTACH:
230 PRINTUI_hInstance = hinstDLL;
231 DisableThreadLibraryCalls( hinstDLL );
238 /*****************************************************
239 * PrintUIEntryW [printui.@]
240 * Commandline-Interface for using printui.dll with rundll32.exe
243 void WINAPI PrintUIEntryW(HWND hWnd, HINSTANCE hInst, LPCWSTR pCommand, DWORD nCmdShow)
248 TRACE("(%p, %p, %s, 0x%x)\n", hWnd, hInst, debugstr_w(pCommand), nCmdShow);
250 memset(&cx, 0, sizeof(context_t));
252 cx.nCmdShow = nCmdShow;
254 if ((pCommand) && (pCommand[0])) {
255 /* result is allocated with GlobalAlloc() */
256 cx.argv = CommandLineToArgvW(pCommand, &cx.argc);
257 TRACE("got %d args at %p\n", cx.argc, cx.argv);
259 res = parse_rundll(&cx);
262 if (res && cx.command) {
269 txtW[0] = cx.command;
270 txtW[1] = cx.subcommand;
272 FIXME("command not implemented: %s\n", debugstr_w(txtW));
277 if ((res == FALSE) || (cx.command == '\0')) {
278 FIXME("dialog: Printer / The operation was not successful\n");