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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
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.
47 renderString (va_list ap
)
49 const char *fmt
= va_arg (ap
, char*);
50 static char buffer
[128];
52 vsnprintf (buffer
, sizeof buffer
, fmt
, ap
);
59 static const int matrix
[][4] = {{IDOK
, 0, 0, 0},
60 {IDOK
, IDCANCEL
, 0, 0},
61 {IDABORT
, IDRETRY
, IDIGNORE
, 0},
62 {IDYES
, IDNO
, IDCANCEL
, 0},
64 {IDRETRY
, IDCANCEL
, 0, 0}};
65 int type
= uType
& MB_TYPEMASK
;
66 int def
= (uType
& MB_DEFMASK
) / MB_DEFBUTTON2
;
68 return matrix
[type
][def
];
71 /* report (R_STATUS, fmt, ...) */
73 textStatus (va_list ap
)
75 char *str
= vstrmake (NULL
, ap
);
84 guiStatus (va_list ap
)
87 char *str
= vstrmake (&len
, ap
);
89 if (len
> 128) str
[129] = 0;
90 SetDlgItemText (dialog
, IDC_SB
, str
);
95 /* report (R_PROGRESS, barnum, steps) */
97 textProgress (va_list ap
)
99 progressGroup
= va_arg (ap
, int);
100 progressMax
= va_arg (ap
, int);
106 guiProgress (va_list ap
)
111 progressGroup
= va_arg (ap
, int);
112 progressMax
= max
= va_arg (ap
, int);
115 progressScale
= (double)0xffff / max
;
118 else progressScale
= 1;
119 pb
= GetDlgItem (dialog
, IDC_PB0
+ progressGroup
* 2);
120 SendMessage (pb
, PBM_SETRANGE
, 0, MAKELPARAM (0, max
));
121 SendMessage (pb
, PBM_SETSTEP
, (WPARAM
)1, 0);
125 /* report (R_STEP, fmt, ...) */
127 textStep (va_list ap
)
129 char *str
= vstrmake (NULL
, ap
);
133 fprintf (stderr
, " (%d of %d)\n", progressCurr
, progressMax
);
141 const int pgID
= IDC_ST0
+ progressGroup
* 2;
142 char *str
= vstrmake (NULL
, ap
);
145 SetDlgItemText (dialog
, pgID
, str
);
146 SendDlgItemMessage (dialog
, pgID
+1, PBM_SETPOS
,
147 (WPARAM
)(progressScale
* progressCurr
), 0);
152 /* report (R_DELTA, inc, fmt, ...) */
154 textDelta (va_list ap
)
156 const int inc
= va_arg (ap
, int);
157 char *str
= vstrmake (NULL
, ap
);
161 fprintf (stderr
, " (%d of %d)\n", progressCurr
, progressMax
);
167 guiDelta (va_list ap
)
169 const int inc
= va_arg (ap
, int);
170 const int pgID
= IDC_ST0
+ progressGroup
* 2;
171 char *str
= vstrmake (NULL
, ap
);
174 SetDlgItemText (dialog
, pgID
, str
);
175 SendDlgItemMessage (dialog
, pgID
+1, PBM_SETPOS
,
176 (WPARAM
)(progressScale
* progressCurr
), 0);
185 fputs ("Tag: ", stderr
);
187 fputc ('\n', stderr
);
194 SetDlgItemText (dialog
, IDC_TAG
, tag
);
198 /* report (R_DIR, fmt, ...) */
202 char *str
= vstrmake (NULL
, ap
);
204 fputs ("Temporary directory: ", stderr
);
206 fputc ('\n', stderr
);
214 char *str
= vstrmake (NULL
, ap
);
216 SetDlgItemText (dialog
, IDC_DIR
, str
);
221 /* report (R_OUT, fmt, ...) */
225 char *str
= vstrmake (NULL
, ap
);
227 fputs ("Log file: ", stderr
);
229 fputc ('\n', stderr
);
237 char *str
= vstrmake (NULL
, ap
);
239 SetDlgItemText (dialog
, IDC_OUT
, str
);
244 /* report (R_WARNING, fmt, ...) */
246 textWarning (va_list ap
)
248 fputs ("Warning: ", stderr
);
254 guiWarning (va_list ap
)
256 char *str
= vstrmake (NULL
, ap
);
258 MessageBox (dialog
, str
, "Warning", MB_ICONWARNING
| MB_OK
);
263 /* report (R_ERROR, fmt, ...) */
265 textError (va_list ap
)
267 fputs ("Error: ", stderr
);
273 guiError (va_list ap
)
275 char *str
= vstrmake (NULL
, ap
);
277 MessageBox (dialog
, str
, "Error", MB_ICONERROR
| MB_OK
);
282 /* report (R_FATAL, fmt, ...) */
284 textFatal (va_list ap
)
291 guiFatal (va_list ap
)
297 /* report (R_ASK, type, fmt, ...) */
301 int uType
= va_arg (ap
, int);
302 int ret
= MBdefault (uType
);
303 char *str
= vstrmake (NULL
, ap
);
305 fprintf (stderr
, "Question of type %d: %s\n"
306 "Returning default: %d\n", uType
, str
, ret
);
314 int uType
= va_arg (ap
, int);
315 char *str
= vstrmake (NULL
, ap
);
316 int ret
= MessageBox (dialog
, str
, "Question",
317 MB_ICONQUESTION
| uType
);
324 EditTagProc (HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
328 if (wParam
== 8) break; /* backspace is OK */
329 if (GetWindowTextLengthA (hwnd
) == MAXTAGLEN
||
330 !goodtagchar (wParam
)) return TRUE
;
333 return CallWindowProcA (DefEditProc
, hwnd
, msg
, wParam
, lParam
);
337 AskTagProc (HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
343 DefEditProc
= (WNDPROC
)SetWindowLongPtr
344 (GetDlgItem (hwnd
, IDC_TAG
), GWLP_WNDPROC
, (LONG_PTR
)EditTagProc
);
347 switch (LOWORD (wParam
)) {
349 len
= GetWindowTextLengthA (GetDlgItem (hwnd
, IDC_TAG
));
350 tag
= xmalloc (len
+1);
351 GetDlgItemTextA (hwnd
, IDC_TAG
, tag
, len
+1);
352 EndDialog (hwnd
, IDOK
);
355 EndDialog (hwnd
, IDABORT
);
365 return DialogBox (GetModuleHandle (NULL
),
366 MAKEINTRESOURCE (IDD_TAG
),
370 /* Quiet functions */
386 return MBdefault (va_arg (ap
, int));
390 AboutProc (HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
394 switch (LOWORD (wParam
)) {
396 EndDialog (hwnd
, IDCANCEL
);
404 DlgProc (HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
408 SendMessage (hwnd
, WM_SETICON
, ICON_SMALL
,
409 (LPARAM
)LoadIcon (GetModuleHandle (NULL
),
410 MAKEINTRESOURCE (IDI_WINE
)));
411 SendMessage (hwnd
, WM_SETICON
, ICON_BIG
,
412 (LPARAM
)LoadIcon (GetModuleHandle (NULL
),
413 MAKEINTRESOURCE (IDI_WINE
)));
415 if (!SetEvent (initEvent
)) {
416 report (R_STATUS
, "Can't signal main thread: %d",
425 switch (LOWORD (wParam
)) {
427 DialogBox (GetModuleHandle (NULL
),
428 MAKEINTRESOURCE (IDD_ABOUT
), hwnd
, AboutProc
);
431 report (R_WARNING
, "Not implemented");
443 InitCommonControls ();
444 ret
= DialogBox (GetModuleHandle (NULL
),
445 MAKEINTRESOURCE (IDD_STATUS
),
449 report (R_WARNING
, "Invalid parent handle");
452 report (R_WARNING
, "DialogBox failed: %d",
458 report (R_STATUS
, "Dialog exited: %d", ret
);
464 report (enum report_type t
, ...)
466 typedef int r_fun_t (va_list);
470 static r_fun_t
* const text_funcs
[] =
471 {textStatus
, textProgress
, textStep
, textDelta
,
472 textTag
, textDir
, textOut
,
473 textWarning
, textError
, textFatal
, textAsk
};
474 static r_fun_t
* const GUI_funcs
[] =
475 {guiStatus
, guiProgress
, guiStep
, guiDelta
,
476 guiTag
, guiDir
, guiOut
,
477 guiWarning
, guiError
, guiFatal
, guiAsk
};
478 static r_fun_t
* const quiet_funcs
[] =
479 {qNoOp
, qNoOp
, qNoOp
, qNoOp
,
481 qNoOp
, qNoOp
, qFatal
, qAsk
};
482 static r_fun_t
* const * funcs
= NULL
;
500 initEvent
= CreateEvent (NULL
, FALSE
, FALSE
, NULL
);
502 report (R_STATUS
, "Can't create event object: %d",
505 DlgThread
= CreateThread (NULL
, 0, DlgThreadProc
,
506 NULL
, 0, &DlgThreadID
);
508 report (R_STATUS
, "Can't create GUI thread: %d",
511 DWORD ret
= WaitForSingleObject (initEvent
, INFINITE
);
517 report (R_STATUS
, "GUI creation timed out");
520 report (R_STATUS
, "Wait for GUI failed: %d",
524 report (R_STATUS
, "Wait returned %d",
533 if (t
< sizeof text_funcs
/ sizeof text_funcs
[0] &&
534 t
< sizeof GUI_funcs
/ sizeof GUI_funcs
[0]) ret
= funcs
[t
](ap
);
535 else report (R_WARNING
, "unimplemented report type: %d", t
);