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
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
27 /* Event object to signal successful window creation to main thread.
29 static HANDLE initEvent
;
35 /* Progress data for the text* functions and for scaling.
37 static unsigned int progressMax
, progressCurr
;
38 static double progressScale
;
40 /* Progress group counter for the gui* functions.
42 static int progressGroup
;
44 static WNDPROC DefEditProc
;
49 static const int matrix
[][4] = {{IDOK
, 0, 0, 0},
50 {IDOK
, IDCANCEL
, 0, 0},
51 {IDABORT
, IDRETRY
, IDIGNORE
, 0},
52 {IDYES
, IDNO
, IDCANCEL
, 0},
54 {IDRETRY
, IDCANCEL
, 0, 0}};
55 int type
= uType
& MB_TYPEMASK
;
56 int def
= (uType
& MB_DEFMASK
) / MB_DEFBUTTON2
;
58 return matrix
[type
][def
];
61 /* report (R_STATUS, fmt, ...) */
63 textStatus (va_list ap
)
65 char *str
= vstrmake (NULL
, ap
);
74 guiStatus (va_list ap
)
77 char *str
= vstrmake (&len
, ap
);
79 if (len
> 128) str
[129] = 0;
80 SetDlgItemTextA (dialog
, IDC_SB
, str
);
85 /* report (R_PROGRESS, barnum, steps) */
87 textProgress (va_list ap
)
89 progressGroup
= va_arg (ap
, int);
90 progressMax
= va_arg (ap
, int);
96 guiProgress (va_list ap
)
101 progressGroup
= va_arg (ap
, int);
102 progressMax
= max
= va_arg (ap
, int);
105 progressScale
= (double)0xffff / max
;
108 else progressScale
= 1;
109 pb
= GetDlgItem (dialog
, IDC_PB0
+ progressGroup
* 2);
110 SendMessageA(pb
, PBM_SETRANGE
, 0, MAKELPARAM (0, max
));
111 SendMessageA(pb
, PBM_SETSTEP
, 1, 0);
115 /* report (R_STEP, fmt, ...) */
117 textStep (va_list ap
)
119 char *str
= vstrmake (NULL
, ap
);
123 fprintf (stderr
, " (%d of %d)\n", progressCurr
, progressMax
);
131 const int pgID
= IDC_ST0
+ progressGroup
* 2;
132 char *str
= vstrmake (NULL
, ap
);
135 SetDlgItemTextA (dialog
, pgID
, str
);
136 SendDlgItemMessageA(dialog
, pgID
+1, PBM_SETPOS
,
137 progressScale
* progressCurr
, 0);
142 /* report (R_DELTA, inc, fmt, ...) */
144 textDelta (va_list ap
)
146 const int inc
= va_arg (ap
, int);
147 char *str
= vstrmake (NULL
, ap
);
151 fprintf (stderr
, " (%d of %d)\n", progressCurr
, progressMax
);
157 guiDelta (va_list ap
)
159 const int inc
= va_arg (ap
, int);
160 const int pgID
= IDC_ST0
+ progressGroup
* 2;
161 char *str
= vstrmake (NULL
, ap
);
164 SetDlgItemTextA (dialog
, pgID
, str
);
165 SendDlgItemMessageA(dialog
, pgID
+1, PBM_SETPOS
,
166 progressScale
* progressCurr
, 0);
175 fputs ("Tag: ", stderr
);
177 fputc ('\n', stderr
);
184 SetDlgItemTextA (dialog
, IDC_TAG
, tag
);
188 /* report (R_DIR, fmt, ...) */
192 char *str
= vstrmake (NULL
, ap
);
194 fputs ("Temporary directory: ", stderr
);
196 fputc ('\n', stderr
);
204 char *str
= vstrmake (NULL
, ap
);
206 SetDlgItemTextA (dialog
, IDC_DIR
, str
);
211 /* report (R_OUT, fmt, ...) */
215 char *str
= vstrmake (NULL
, ap
);
217 fputs ("Log file: ", stderr
);
219 fputc ('\n', stderr
);
227 char *str
= vstrmake (NULL
, ap
);
229 SetDlgItemTextA (dialog
, IDC_OUT
, str
);
234 /* report (R_WARNING, fmt, ...) */
236 textWarning (va_list ap
)
238 fputs ("Warning: ", stderr
);
244 guiWarning (va_list ap
)
246 char *str
= vstrmake (NULL
, ap
);
248 MessageBoxA (dialog
, str
, "Warning", MB_ICONWARNING
| MB_OK
);
253 /* report (R_ERROR, fmt, ...) */
255 textError (va_list ap
)
257 fputs ("Error: ", stderr
);
263 guiError (va_list ap
)
265 char *str
= vstrmake (NULL
, ap
);
267 MessageBoxA (dialog
, str
, "Error", MB_ICONERROR
| MB_OK
);
272 /* report (R_FATAL, fmt, ...) */
274 textFatal (va_list ap
)
282 guiFatal (va_list ap
)
289 /* report (R_ASK, type, fmt, ...) */
293 int uType
= va_arg (ap
, int);
294 int ret
= MBdefault (uType
);
295 char *str
= vstrmake (NULL
, ap
);
297 fprintf (stderr
, "Question of type %d: %s\n"
298 "Returning default: %d\n", uType
, str
, ret
);
306 int uType
= va_arg (ap
, int);
307 char *str
= vstrmake (NULL
, ap
);
308 int ret
= MessageBoxA (dialog
, str
, "Question", MB_ICONQUESTION
| uType
);
315 EditTagProc (HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
319 if (wParam
== 8) break; /* backspace is OK */
320 if (GetWindowTextLengthA (hwnd
) == MAXTAGLEN
||
321 !goodtagchar (wParam
)) return TRUE
;
324 return CallWindowProcA (DefEditProc
, hwnd
, msg
, wParam
, lParam
);
327 static INT_PTR CALLBACK
328 AskTagProc (HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
334 DefEditProc
= (WNDPROC
)SetWindowLongPtrA
335 (GetDlgItem (hwnd
, IDC_TAG
), GWLP_WNDPROC
, (LONG_PTR
)EditTagProc
);
338 switch (LOWORD (wParam
)) {
340 len
= GetWindowTextLengthA (GetDlgItem (hwnd
, IDC_TAG
));
342 report (R_WARNING
, "You must enter a tag to continue");
346 GetDlgItemTextA (hwnd
, IDC_TAG
, tag
, len
+1);
347 EndDialog (hwnd
, IDOK
);
350 EndDialog (hwnd
, IDABORT
);
360 return DialogBoxA(GetModuleHandleA(NULL
), MAKEINTRESOURCEA(IDD_TAG
), dialog
, AskTagProc
);
363 static INT_PTR CALLBACK
364 AskEmailProc (HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
371 switch (LOWORD (wParam
)) {
373 len
= GetWindowTextLengthA (GetDlgItem (hwnd
, IDC_EMAIL
));
375 report (R_WARNING
, "You must enter an email address to continue");
378 email
= xalloc(len
+1);
379 GetDlgItemTextA (hwnd
, IDC_EMAIL
, email
, len
+1);
380 EndDialog (hwnd
, IDOK
);
383 EndDialog (hwnd
, IDABORT
);
393 return DialogBoxA(GetModuleHandleA(NULL
), MAKEINTRESOURCEA(IDD_EMAIL
), dialog
, AskEmailProc
);
396 /* Quiet functions */
406 return MBdefault (va_arg (ap
, int));
409 static INT_PTR CALLBACK
410 AboutProc (HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
414 switch (LOWORD (wParam
)) {
416 EndDialog (hwnd
, IDCANCEL
);
423 static INT_PTR CALLBACK
424 DlgProc (HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
428 SendMessageA(hwnd
, WM_SETICON
, ICON_SMALL
,
429 (LPARAM
)LoadImageA( GetModuleHandleA(NULL
), MAKEINTRESOURCEA(IDI_WINE
), IMAGE_ICON
,
430 GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
),
432 SendMessageA(hwnd
, WM_SETICON
, ICON_BIG
,
433 (LPARAM
)LoadIconA( GetModuleHandleA(NULL
), MAKEINTRESOURCEA(IDI_WINE
)));
435 if (!SetEvent (initEvent
)) {
436 report (R_STATUS
, "Can't signal main thread: %d",
445 switch (LOWORD (wParam
)) {
447 DialogBoxA(GetModuleHandleA(NULL
), MAKEINTRESOURCEA(IDD_ABOUT
), hwnd
, AboutProc
);
450 report (R_STATUS
, "Aborting, please wait...");
459 DlgThreadProc (LPVOID param
)
463 InitCommonControls ();
464 ret
= DialogBoxA(GetModuleHandleA(NULL
), MAKEINTRESOURCEA(IDD_STATUS
), NULL
, DlgProc
);
467 report (R_FATAL
, "Cannot display dialog");
470 report (R_WARNING
, "DialogBox failed: %d",
476 report (R_STATUS
, "Dialog exited: %d", ret
);
481 int WINAPIV
report (enum report_type t
, ...)
483 typedef int r_fun_t (va_list);
487 static r_fun_t
* const text_funcs
[] =
488 {textStatus
, textProgress
, textStep
, textDelta
,
489 textTag
, textDir
, textOut
,
490 textWarning
, textError
, textFatal
, textAsk
};
491 static r_fun_t
* const GUI_funcs
[] =
492 {guiStatus
, guiProgress
, guiStep
, guiDelta
,
493 guiTag
, guiDir
, guiOut
,
494 guiWarning
, guiError
, guiFatal
, guiAsk
};
495 static r_fun_t
* const quiet_funcs
[] =
496 {qNoOp
, qNoOp
, qNoOp
, qNoOp
,
498 qNoOp
, textError
, textFatal
, qAsk
};
499 static r_fun_t
* const * funcs
= NULL
;
517 initEvent
= CreateEventA(NULL
, FALSE
, FALSE
, NULL
);
519 report (R_STATUS
, "Can't create event object: %d",
522 DlgThread
= CreateThread (NULL
, 0, DlgThreadProc
,
523 NULL
, 0, &DlgThreadID
);
525 report (R_STATUS
, "Can't create GUI thread: %d",
528 DWORD ret
= WaitForSingleObject (initEvent
, INFINITE
);
529 CloseHandle(DlgThread
);
535 report (R_STATUS
, "GUI creation timed out");
538 report (R_STATUS
, "Wait for GUI failed: %d",
542 report (R_STATUS
, "Wait returned %d",
551 if (t
< ARRAY_SIZE(text_funcs
)) ret
= funcs
[t
](ap
);
552 else report (R_WARNING
, "unimplemented report type: %d", t
);