msxml3: Properly escape character data in text nodes.
[wine/multimedia.git] / dlls / printui / printui.c
blob7a2b466d4111dc637b86d3a178522b40e17ee67e
1 /*
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
21 #include <stdarg.h>
23 #define COBJMACROS
24 #define NONAMELESSUNION
26 #include "windef.h"
27 #include "winbase.h"
28 #include "wingdi.h"
29 #include "winuser.h"
30 #include "winreg.h"
31 #include "winver.h"
32 #include "winnls.h"
33 #include "shellapi.h"
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)
61 LPWSTR ptr;
63 ptr = cx->pNextCharW;
64 if (ptr && ptr[0]) {
65 cx->pNextCharW = NULL;
66 return ptr;
69 /* Get the next Parameter, when available */
70 if (cx->next_arg < cx->argc) {
71 ptr = cx->argv[cx->next_arg];
72 cx->next_arg++;
73 cx->pNextCharW = NULL;
74 return ptr;
76 return 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)
91 WCHAR c;
93 /* Try the next WCHAR in the actual Parameter */
94 if (cx->pNextCharW) {
95 c = *cx->pNextCharW;
96 if (c) {
97 cx->pNextCharW++;
98 return c;
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];
107 cx->next_arg++;
110 if (cx->pNextCharW) {
111 c = *cx->pNextCharW;
112 if (c) {
113 cx->pNextCharW++;
115 else
117 /* We reached the end of the Parameter */
118 cx->pNextCharW = NULL;
120 return c;
122 return '\0';
125 /* ################################ */
126 static BOOL parse_rundll(context_t * cx)
128 LPWSTR ptr;
129 DWORD index;
130 WCHAR txtW[2];
131 WCHAR c;
134 c = get_next_wchar(cx, TRUE);
135 txtW[1] = '\0';
137 while (c)
140 while ( (c == ' ') || (c == '\t'))
142 c = get_next_wchar(cx, TRUE);
144 txtW[0] = c;
146 if (c == '@') {
147 /* read commands from a File */
148 ptr = get_next_wstr(cx);
149 FIXME("redir not supported: %s\n", debugstr_w(ptr));
150 return FALSE;
152 else if (c == '/') {
153 c = get_next_wchar(cx, FALSE);
154 while ( c )
156 txtW[0] = c;
157 ptr = strchrW(optionsW, c);
158 if (ptr) {
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]));
162 c = 0;
164 else
166 ptr = strchrW(flagsW, c);
167 if (ptr) {
168 index = ptr - flagsW;
169 cx->flags[index] = TRUE;
170 TRACE("flag: %s\n", debugstr_w(txtW));
172 else
174 cx->command = c;
175 cx->subcommand = '\0';
176 TRACE(" cmd: %s\n", debugstr_w(txtW));
179 /* help has priority over all commands */
180 if (c == '?') {
181 return TRUE;
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') ){
189 cx->subcommand = c;
190 txtW[0] = c;
191 TRACE(" sub: %s\n", debugstr_w(txtW));
192 c = get_next_wchar(cx, FALSE);
196 c = get_next_wchar(cx, TRUE);
199 else
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 */
205 cx->pNextCharW--;
206 TRACE("%d extra Parameter, starting with %s\n", 1 + (cx->argc - cx->next_arg), debugstr_w(cx->pNextCharW));
207 return TRUE;
209 FIXME("0x%x: %s is unknown\n", c, debugstr_wn(&c, 1));
210 return FALSE;
214 return TRUE;
217 /*****************************************************
218 * DllMain
220 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
222 TRACE("(%p, %d, %p)\n",hinstDLL, fdwReason, lpvReserved);
224 switch(fdwReason)
226 case DLL_WINE_PREATTACH:
227 return FALSE; /* prefer native version */
229 case DLL_PROCESS_ATTACH:
230 PRINTUI_hInstance = hinstDLL;
231 DisableThreadLibraryCalls( hinstDLL );
232 break;
234 return TRUE;
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)
245 context_t cx;
246 BOOL res = FALSE;
248 TRACE("(%p, %p, %s, 0x%x)\n", hWnd, hInst, debugstr_w(pCommand), nCmdShow);
250 memset(&cx, 0, sizeof(context_t));
251 cx.hWnd = hWnd;
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) {
263 switch (cx.command)
266 default:
268 WCHAR txtW[3];
269 txtW[0] = cx.command;
270 txtW[1] = cx.subcommand;
271 txtW[2] = '\0';
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");
281 GlobalFree(cx.argv);