4 * Copyright 2004 Ferenc Wagner
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
27 /* Event object to signal successful window creation to main thread.
35 /* Progress data for the text* functions and for scaling.
37 unsigned int progressMax, progressCurr;
40 /* Progress group counter for the gui* functions.
45 renderString (va_list ap)
47 const char *fmt = va_arg (ap, char*);
48 static char buffer[128];
50 vsnprintf (buffer, sizeof buffer, fmt, ap);
57 static const int matrix[][4] = {{IDOK, 0, 0, 0},
58 {IDOK, IDCANCEL, 0, 0},
59 {IDABORT, IDRETRY, IDIGNORE, 0},
60 {IDYES, IDNO, IDCANCEL, 0},
62 {IDRETRY, IDCANCEL, 0, 0}};
63 int type = uType & MB_TYPEMASK;
64 int def = (uType & MB_DEFMASK) / MB_DEFBUTTON2;
66 return matrix[type][def];
69 /* report (R_STATUS, fmt, ...) */
71 textStatus (va_list ap)
73 char *str = vstrmake (NULL, ap);
82 guiStatus (va_list ap)
85 char *str = vstrmake (&len, ap);
87 if (len > 128) str[129] = 0;
88 SetDlgItemText (dialog, IDC_SB, str);
93 /* report (R_PROGRESS, barnum, steps) */
95 textProgress (va_list ap)
97 progressMax = va_arg (ap, int);
103 guiProgress (va_list ap)
108 progressGroup = va_arg (ap, int);
109 progressMax = max = va_arg (ap, int);
112 progressScale = (double)0xffff / max;
115 else progressScale = 1;
116 pb = GetDlgItem (dialog, IDC_PB0 + progressGroup * 2);
117 SendMessage (pb, PBM_SETRANGE, 0, MAKELPARAM (0, max));
118 SendMessage (pb, PBM_SETSTEP, (WPARAM)1, 0);
122 /* report (R_STEP, fmt, ...) */
124 textStep (va_list ap)
126 char *str = vstrmake (NULL, ap);
130 fprintf (stderr, " (%d of %d)\n", progressCurr, progressMax);
138 const int pgID = IDC_ST0 + progressGroup * 2;
139 char *str = vstrmake (NULL, ap);
142 SetDlgItemText (dialog, pgID, str);
143 SendDlgItemMessage (dialog, pgID+1, PBM_SETPOS,
144 (WPARAM)(progressScale * progressCurr), 0);
149 /* report (R_DELTA, inc, fmt, ...) */
151 textDelta (va_list ap)
153 const int inc = va_arg (ap, int);
154 char *str = vstrmake (NULL, ap);
158 fprintf (stderr, " (%d of %d)\n", progressCurr, progressMax);
164 guiDelta (va_list ap)
166 const int inc = va_arg (ap, int);
167 const int pgID = IDC_ST0 + progressGroup * 2;
168 char *str = vstrmake (NULL, ap);
171 SetDlgItemText (dialog, pgID, str);
172 SendDlgItemMessage (dialog, pgID+1, PBM_SETPOS,
173 (WPARAM)(progressScale * progressCurr), 0);
178 /* report (R_DIR, fmt, ...) */
182 char *str = vstrmake (NULL, ap);
184 fputs ("Temporary directory: ", stderr);
186 fputc ('\n', stderr);
194 char *str = vstrmake (NULL, ap);
196 SetDlgItemText (dialog, IDC_DIR, str);
201 /* report (R_OUT, fmt, ...) */
205 char *str = vstrmake (NULL, ap);
207 fputs ("Log file: ", stderr);
209 fputc ('\n', stderr);
217 char *str = vstrmake (NULL, ap);
219 SetDlgItemText (dialog, IDC_OUT, str);
224 /* report (R_WARNING, fmt, ...) */
226 textWarning (va_list ap)
228 fputs ("Warning: ", stderr);
234 guiWarning (va_list ap)
236 char *str = vstrmake (NULL, ap);
238 MessageBox (dialog, str, "Warning", MB_ICONWARNING | MB_OK);
243 /* report (R_ERROR, fmt, ...) */
245 textError (va_list ap)
247 fputs ("Error: ", stderr);
253 guiError (va_list ap)
255 char *str = vstrmake (NULL, ap);
257 MessageBox (dialog, str, "Error", MB_ICONERROR | MB_OK);
262 /* report (R_FATAL, fmt, ...) */
264 textFatal (va_list ap)
271 guiFatal (va_list ap)
277 /* report (R_ASK, type, fmt, ...) */
281 int uType = va_arg (ap, int);
282 int ret = MBdefault (uType);
283 char *str = vstrmake (NULL, ap);
285 fprintf (stderr, "Question of type %d: %s\n"
286 "Returning default: %d\n", uType, str, ret);
294 int uType = va_arg (ap, int);
295 char *str = vstrmake (NULL, ap);
296 int ret = MessageBox (dialog, str, "Question",
297 MB_ICONQUESTION | uType);
303 /* Quiet functions */
319 return MBdefault (va_arg (ap, int));
323 AboutProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
327 switch (LOWORD (wParam)) {
329 EndDialog (hwnd, IDCANCEL);
337 DlgProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
341 SendMessage (hwnd, WM_SETICON, ICON_SMALL,
342 (LPARAM)LoadIcon (GetModuleHandle (NULL),
343 MAKEINTRESOURCE (IDI_WINE)));
344 SendMessage (hwnd, WM_SETICON, ICON_BIG,
345 (LPARAM)LoadIcon (GetModuleHandle (NULL),
346 MAKEINTRESOURCE (IDI_WINE)));
348 if (!SetEvent (initEvent)) {
349 report (R_STATUS, "Can't signal main thread: %d",
358 switch (LOWORD (wParam)) {
360 DialogBox (GetModuleHandle (NULL),
361 MAKEINTRESOURCE (IDD_ABOUT), hwnd, AboutProc);
364 report (R_WARNING, "Not implemented");
376 InitCommonControls ();
377 ret = DialogBox (GetModuleHandle (NULL),
378 MAKEINTRESOURCE (IDD_STATUS),
382 report (R_WARNING, "Invalid parent handle");
385 report (R_WARNING, "DialogBox failed: %d",
391 report (R_STATUS, "Dialog exited: %d", ret);
397 report (enum report_type t, ...)
399 typedef int r_fun_t (va_list);
403 static r_fun_t * const text_funcs[] =
404 {textStatus, textProgress, textStep, textDelta,
405 textDir, textOut, textFatal, textWarning, textAsk};
406 static r_fun_t * const GUI_funcs[] =
407 {guiStatus, guiProgress, guiStep, guiDelta,
408 guiDir, guiOut, guiFatal, guiWarning, guiAsk};
409 static r_fun_t * const quiet_funcs[] =
410 {qNoOp, qNoOp, qNoOp, qNoOp,
411 qNoOp, qNoOp, qFatal, qNoOp, qAsk};
412 static r_fun_t * const * funcs = NULL;
430 initEvent = CreateEvent (NULL, FALSE, FALSE, NULL);
432 report (R_STATUS, "Can't create event object: %d",
435 DlgThread = CreateThread (NULL, 0, DlgThreadProc,
436 NULL, 0, &DlgThreadID);
438 report (R_STATUS, "Can't create GUI thread: %d",
441 DWORD ret = WaitForSingleObject (initEvent, INFINITE);
447 report (R_STATUS, "GUI creation timed out");
450 report (R_STATUS, "Wait for GUI failed: %d",
454 report (R_STATUS, "Wait returned %d",
463 if (t < sizeof text_funcs / sizeof text_funcs[0] &&
464 t < sizeof GUI_funcs / sizeof GUI_funcs[0] &&
465 t >= 0) ret = funcs[t](ap);
466 else report (R_WARNING, "unimplemented report type: %d", t);