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.
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 progressGroup
= va_arg (ap
, int);
98 progressMax
= va_arg (ap
, int);
104 guiProgress (va_list ap
)
109 progressGroup
= va_arg (ap
, int);
110 progressMax
= max
= va_arg (ap
, int);
113 progressScale
= (double)0xffff / max
;
116 else progressScale
= 1;
117 pb
= GetDlgItem (dialog
, IDC_PB0
+ progressGroup
* 2);
118 SendMessage (pb
, PBM_SETRANGE
, 0, MAKELPARAM (0, max
));
119 SendMessage (pb
, PBM_SETSTEP
, (WPARAM
)1, 0);
123 /* report (R_STEP, fmt, ...) */
125 textStep (va_list ap
)
127 char *str
= vstrmake (NULL
, ap
);
131 fprintf (stderr
, " (%d of %d)\n", progressCurr
, progressMax
);
139 const int pgID
= IDC_ST0
+ progressGroup
* 2;
140 char *str
= vstrmake (NULL
, ap
);
143 SetDlgItemText (dialog
, pgID
, str
);
144 SendDlgItemMessage (dialog
, pgID
+1, PBM_SETPOS
,
145 (WPARAM
)(progressScale
* progressCurr
), 0);
150 /* report (R_DELTA, inc, fmt, ...) */
152 textDelta (va_list ap
)
154 const int inc
= va_arg (ap
, int);
155 char *str
= vstrmake (NULL
, ap
);
159 fprintf (stderr
, " (%d of %d)\n", progressCurr
, progressMax
);
165 guiDelta (va_list ap
)
167 const int inc
= va_arg (ap
, int);
168 const int pgID
= IDC_ST0
+ progressGroup
* 2;
169 char *str
= vstrmake (NULL
, ap
);
172 SetDlgItemText (dialog
, pgID
, str
);
173 SendDlgItemMessage (dialog
, pgID
+1, PBM_SETPOS
,
174 (WPARAM
)(progressScale
* progressCurr
), 0);
179 /* report (R_DIR, fmt, ...) */
183 char *str
= vstrmake (NULL
, ap
);
185 fputs ("Temporary directory: ", stderr
);
187 fputc ('\n', stderr
);
195 char *str
= vstrmake (NULL
, ap
);
197 SetDlgItemText (dialog
, IDC_DIR
, str
);
202 /* report (R_OUT, fmt, ...) */
206 char *str
= vstrmake (NULL
, ap
);
208 fputs ("Log file: ", stderr
);
210 fputc ('\n', stderr
);
218 char *str
= vstrmake (NULL
, ap
);
220 SetDlgItemText (dialog
, IDC_OUT
, str
);
225 /* report (R_WARNING, fmt, ...) */
227 textWarning (va_list ap
)
229 fputs ("Warning: ", stderr
);
235 guiWarning (va_list ap
)
237 char *str
= vstrmake (NULL
, ap
);
239 MessageBox (dialog
, str
, "Warning", MB_ICONWARNING
| MB_OK
);
244 /* report (R_ERROR, fmt, ...) */
246 textError (va_list ap
)
248 fputs ("Error: ", stderr
);
254 guiError (va_list ap
)
256 char *str
= vstrmake (NULL
, ap
);
258 MessageBox (dialog
, str
, "Error", MB_ICONERROR
| MB_OK
);
263 /* report (R_FATAL, fmt, ...) */
265 textFatal (va_list ap
)
272 guiFatal (va_list ap
)
278 /* report (R_ASK, type, fmt, ...) */
282 int uType
= va_arg (ap
, int);
283 int ret
= MBdefault (uType
);
284 char *str
= vstrmake (NULL
, ap
);
286 fprintf (stderr
, "Question of type %d: %s\n"
287 "Returning default: %d\n", uType
, str
, ret
);
295 int uType
= va_arg (ap
, int);
296 char *str
= vstrmake (NULL
, ap
);
297 int ret
= MessageBox (dialog
, str
, "Question",
298 MB_ICONQUESTION
| uType
);
304 /* Quiet functions */
320 return MBdefault (va_arg (ap
, int));
324 AboutProc (HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
328 switch (LOWORD (wParam
)) {
330 EndDialog (hwnd
, IDCANCEL
);
338 DlgProc (HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
342 SendMessage (hwnd
, WM_SETICON
, ICON_SMALL
,
343 (LPARAM
)LoadIcon (GetModuleHandle (NULL
),
344 MAKEINTRESOURCE (IDI_WINE
)));
345 SendMessage (hwnd
, WM_SETICON
, ICON_BIG
,
346 (LPARAM
)LoadIcon (GetModuleHandle (NULL
),
347 MAKEINTRESOURCE (IDI_WINE
)));
349 if (!SetEvent (initEvent
)) {
350 report (R_STATUS
, "Can't signal main thread: %d",
359 switch (LOWORD (wParam
)) {
361 DialogBox (GetModuleHandle (NULL
),
362 MAKEINTRESOURCE (IDD_ABOUT
), hwnd
, AboutProc
);
365 report (R_WARNING
, "Not implemented");
377 InitCommonControls ();
378 ret
= DialogBox (GetModuleHandle (NULL
),
379 MAKEINTRESOURCE (IDD_STATUS
),
383 report (R_WARNING
, "Invalid parent handle");
386 report (R_WARNING
, "DialogBox failed: %d",
392 report (R_STATUS
, "Dialog exited: %d", ret
);
398 report (enum report_type t
, ...)
400 typedef int r_fun_t (va_list);
404 static r_fun_t
* const text_funcs
[] =
405 {textStatus
, textProgress
, textStep
, textDelta
,
407 textWarning
, textError
, textFatal
, textAsk
};
408 static r_fun_t
* const GUI_funcs
[] =
409 {guiStatus
, guiProgress
, guiStep
, guiDelta
,
411 guiWarning
, guiError
, guiFatal
, guiAsk
};
412 static r_fun_t
* const quiet_funcs
[] =
413 {qNoOp
, qNoOp
, qNoOp
, qNoOp
,
415 qNoOp
, qNoOp
, qFatal
, qAsk
};
416 static r_fun_t
* const * funcs
= NULL
;
434 initEvent
= CreateEvent (NULL
, FALSE
, FALSE
, NULL
);
436 report (R_STATUS
, "Can't create event object: %d",
439 DlgThread
= CreateThread (NULL
, 0, DlgThreadProc
,
440 NULL
, 0, &DlgThreadID
);
442 report (R_STATUS
, "Can't create GUI thread: %d",
445 DWORD ret
= WaitForSingleObject (initEvent
, INFINITE
);
451 report (R_STATUS
, "GUI creation timed out");
454 report (R_STATUS
, "Wait for GUI failed: %d",
458 report (R_STATUS
, "Wait returned %d",
467 if (t
< sizeof text_funcs
/ sizeof text_funcs
[0] &&
468 t
< sizeof GUI_funcs
/ sizeof GUI_funcs
[0] &&
469 t
>= 0) ret
= funcs
[t
](ap
);
470 else report (R_WARNING
, "unimplemented report type: %d", t
);