TESTING -- override pthreads to fix gstreamer v5
[wine/multimedia.git] / dlls / printui / printui.c
blob32e7b52e3d13f16881a81416214b46d26c97d4df
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
25 #include "windef.h"
26 #include "winbase.h"
27 #include "wingdi.h"
28 #include "winuser.h"
29 #include "winreg.h"
30 #include "winver.h"
31 #include "winnls.h"
32 #include "shellapi.h"
34 #include "wine/unicode.h"
35 #include "wine/debug.h"
36 #include "printui_private.h"
38 WINE_DEFAULT_DEBUG_CHANNEL(printui);
40 /* ################################# */
42 /* Must be in order with OPT_* */
43 static const WCHAR optionsW[OPT_MAX+1]={'a','b','c','f','h','j','l','m','n','t','r','v',0};
45 /* Must be in order with FLAG_* */
46 static const WCHAR flagsW[FLAG_MAX+1]={'q','w','y','z','Z',0};
49 /* ################################
50 * get_next_wstr() [Internal]
52 * Get the next WSTR, when available
56 static LPWSTR get_next_wstr(context_t * cx)
58 LPWSTR ptr;
60 ptr = cx->pNextCharW;
61 if (ptr && ptr[0]) {
62 cx->pNextCharW = NULL;
63 return ptr;
66 /* Get the next Parameter, when available */
67 if (cx->next_arg < cx->argc) {
68 ptr = cx->argv[cx->next_arg];
69 cx->next_arg++;
70 cx->pNextCharW = NULL;
71 return ptr;
73 return NULL;
77 /* ################################
78 * get_next_wchar() [Internal]
80 * Get the next WCHAR from the Commandline or from the File (@ Filename)
82 * ToDo: Support Parameter from a File ( "@Filename" )
86 static WCHAR get_next_wchar(context_t * cx, BOOL use_next_parameter)
88 WCHAR c;
90 /* Try the next WCHAR in the actual Parameter */
91 if (cx->pNextCharW) {
92 c = *cx->pNextCharW;
93 if (c) {
94 cx->pNextCharW++;
95 return c;
97 /* We reached the end of the Parameter */
98 cx->pNextCharW = NULL;
101 /* Get the next Parameter, when available and allowed */
102 if ((cx->pNextCharW == NULL) && (cx->next_arg < cx->argc) && (use_next_parameter)) {
103 cx->pNextCharW = cx->argv[cx->next_arg];
104 cx->next_arg++;
107 if (cx->pNextCharW) {
108 c = *cx->pNextCharW;
109 if (c) {
110 cx->pNextCharW++;
112 else
114 /* We reached the end of the Parameter */
115 cx->pNextCharW = NULL;
117 return c;
119 return '\0';
122 /* ################################ */
123 static BOOL parse_rundll(context_t * cx)
125 LPWSTR ptr;
126 DWORD index;
127 WCHAR txtW[2];
128 WCHAR c;
131 c = get_next_wchar(cx, TRUE);
132 txtW[1] = '\0';
134 while (c)
137 while ( (c == ' ') || (c == '\t'))
139 c = get_next_wchar(cx, TRUE);
141 txtW[0] = c;
143 if (c == '@') {
144 /* read commands from a File */
145 ptr = get_next_wstr(cx);
146 FIXME("redir not supported: %s\n", debugstr_w(ptr));
147 return FALSE;
149 else if (c == '/') {
150 c = get_next_wchar(cx, FALSE);
151 while ( c )
153 txtW[0] = c;
154 ptr = strchrW(optionsW, c);
155 if (ptr) {
156 index = ptr - optionsW;
157 cx->options[index] = get_next_wstr(cx);
158 TRACE(" opt: %s %s\n", debugstr_w(txtW), debugstr_w(cx->options[index]));
159 c = 0;
161 else
163 ptr = strchrW(flagsW, c);
164 if (ptr) {
165 index = ptr - flagsW;
166 cx->flags[index] = TRUE;
167 TRACE("flag: %s\n", debugstr_w(txtW));
169 else
171 cx->command = c;
172 cx->subcommand = '\0';
173 TRACE(" cmd: %s\n", debugstr_w(txtW));
176 /* help has priority over all commands */
177 if (c == '?') {
178 return TRUE;
181 c = get_next_wchar(cx, FALSE);
183 /* Some commands use two wchar */
184 if ((cx->command == 'd') || (cx->command == 'g') || (cx->command == 'i') ||
185 (cx->command == 'S') || (cx->command == 'X') ){
186 cx->subcommand = c;
187 txtW[0] = c;
188 TRACE(" sub: %s\n", debugstr_w(txtW));
189 c = get_next_wchar(cx, FALSE);
193 c = get_next_wchar(cx, TRUE);
196 else
198 /* The commands 'S' and 'X' have additional Parameter */
199 if ((cx->command == 'S') || (cx->command == 'X')) {
201 /* the actual WCHAR is the start from the extra Parameter */
202 cx->pNextCharW--;
203 TRACE("%d extra Parameter, starting with %s\n", 1 + (cx->argc - cx->next_arg), debugstr_w(cx->pNextCharW));
204 return TRUE;
206 FIXME("0x%x: %s is unknown\n", c, debugstr_wn(&c, 1));
207 return FALSE;
211 return TRUE;
214 /*****************************************************
215 * DllMain
217 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
219 TRACE("(%p, %d, %p)\n",hinstDLL, fdwReason, lpvReserved);
221 switch(fdwReason)
223 case DLL_WINE_PREATTACH:
224 return FALSE; /* prefer native version */
226 case DLL_PROCESS_ATTACH:
227 DisableThreadLibraryCalls( hinstDLL );
228 break;
230 return TRUE;
234 /*****************************************************
235 * PrintUIEntryW [printui.@]
236 * Commandline-Interface for using printui.dll with rundll32.exe
239 void WINAPI PrintUIEntryW(HWND hWnd, HINSTANCE hInst, LPCWSTR pCommand, DWORD nCmdShow)
241 context_t cx;
242 BOOL res = FALSE;
244 TRACE("(%p, %p, %s, 0x%x)\n", hWnd, hInst, debugstr_w(pCommand), nCmdShow);
246 memset(&cx, 0, sizeof(context_t));
247 cx.hWnd = hWnd;
248 cx.nCmdShow = nCmdShow;
250 if ((pCommand) && (pCommand[0])) {
251 /* result is allocated with GlobalAlloc() */
252 cx.argv = CommandLineToArgvW(pCommand, &cx.argc);
253 TRACE("got %d args at %p\n", cx.argc, cx.argv);
255 res = parse_rundll(&cx);
258 if (res && cx.command) {
259 switch (cx.command)
262 default:
264 WCHAR txtW[3];
265 txtW[0] = cx.command;
266 txtW[1] = cx.subcommand;
267 txtW[2] = '\0';
268 FIXME("command not implemented: %s\n", debugstr_w(txtW));
273 if ((res == FALSE) || (cx.command == '\0')) {
274 FIXME("dialog: Printer / The operation was not successful\n");
277 GlobalFree(cx.argv);