7a9c20d8974f89566d4e7a5e10e38654edc36860
[reactos.git] / reactos / lib / msi / dialog.c
1 /*
2 * Implementation of the Microsoft Installer (msi.dll)
3 *
4 * Copyright 2005 Mike McCormack for CodeWeavers
5 *
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.
10 *
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.
15 *
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
19 */
20
21 #define COBJMACROS
22
23 #include <stdarg.h>
24
25 #include "windef.h"
26 #include "winbase.h"
27 #include "winuser.h"
28 #include "winnls.h"
29 #include "wingdi.h"
30 #include "msi.h"
31 #include "msipriv.h"
32 #include "msidefs.h"
33 #include "ocidl.h"
34 #include "olectl.h"
35 #include "richedit.h"
36 #include "commctrl.h"
37
38 #include "wine/debug.h"
39 #include "wine/unicode.h"
40
41 #include "action.h"
42
43 WINE_DEFAULT_DEBUG_CHANNEL(msi);
44
45
46 struct msi_control_tag;
47 typedef struct msi_control_tag msi_control;
48 typedef UINT (*msi_handler)( msi_dialog *, msi_control *, WPARAM );
49
50 struct msi_control_tag
51 {
52 struct list entry;
53 HWND hwnd;
54 msi_handler handler;
55 LPWSTR property;
56 LPWSTR value;
57 HBITMAP hBitmap;
58 HICON hIcon;
59 LPWSTR tabnext;
60 HMODULE hDll;
61 WCHAR name[1];
62 };
63
64 typedef struct msi_font_tag
65 {
66 struct msi_font_tag *next;
67 HFONT hfont;
68 WCHAR name[1];
69 } msi_font;
70
71 struct msi_dialog_tag
72 {
73 MSIPACKAGE *package;
74 msi_dialog_event_handler event_handler;
75 BOOL finished;
76 INT scale;
77 DWORD attributes;
78 HWND hwnd;
79 LPWSTR default_font;
80 msi_font *font_list;
81 struct list controls;
82 HWND hWndFocus;
83 WCHAR name[1];
84 };
85
86 typedef UINT (*msi_dialog_control_func)( msi_dialog *dialog, MSIRECORD *rec );
87 struct control_handler
88 {
89 LPCWSTR control_type;
90 msi_dialog_control_func func;
91 };
92
93 typedef struct
94 {
95 msi_dialog* dialog;
96 msi_control *parent;
97 DWORD attributes;
98 } radio_button_group_descr;
99
100 const WCHAR szMsiDialogClass[] = {
101 'M','s','i','D','i','a','l','o','g','C','l','o','s','e','C','l','a','s','s',0
102 };
103 const WCHAR szMsiHiddenWindow[] = {
104 'M','s','i','H','i','d','d','e','n','W','i','n','d','o','w',0 };
105 const static WCHAR szStatic[] = { 'S','t','a','t','i','c',0 };
106 const static WCHAR szButton[] = { 'B','U','T','T','O','N', 0 };
107 const static WCHAR szButtonData[] = { 'M','S','I','D','A','T','A',0 };
108 static const WCHAR szText[] = { 'T','e','x','t',0 };
109 static const WCHAR szPushButton[] = { 'P','u','s','h','B','u','t','t','o','n',0 };
110 static const WCHAR szLine[] = { 'L','i','n','e',0 };
111 static const WCHAR szBitmap[] = { 'B','i','t','m','a','p',0 };
112 static const WCHAR szCheckBox[] = { 'C','h','e','c','k','B','o','x',0 };
113 static const WCHAR szScrollableText[] = {
114 'S','c','r','o','l','l','a','b','l','e','T','e','x','t',0 };
115 static const WCHAR szComboBox[] = { 'C','o','m','b','o','B','o','x',0 };
116 static const WCHAR szEdit[] = { 'E','d','i','t',0 };
117 static const WCHAR szMaskedEdit[] = { 'M','a','s','k','e','d','E','d','i','t',0 };
118 static const WCHAR szPathEdit[] = { 'P','a','t','h','E','d','i','t',0 };
119 static const WCHAR szProgressBar[] = {
120 'P','r','o','g','r','e','s','s','B','a','r',0 };
121 static const WCHAR szRadioButtonGroup[] = {
122 'R','a','d','i','o','B','u','t','t','o','n','G','r','o','u','p',0 };
123 static const WCHAR szIcon[] = { 'I','c','o','n',0 };
124
125 static UINT msi_dialog_checkbox_handler( msi_dialog *, msi_control *, WPARAM );
126 static void msi_dialog_checkbox_sync_state( msi_dialog *, msi_control * );
127 static UINT msi_dialog_button_handler( msi_dialog *, msi_control *, WPARAM );
128 static UINT msi_dialog_edit_handler( msi_dialog *, msi_control *, WPARAM );
129 static UINT msi_dialog_radiogroup_handler( msi_dialog *, msi_control *, WPARAM param );
130 static UINT msi_dialog_evaluate_control_conditions( msi_dialog *dialog );
131 static LRESULT WINAPI MSIRadioGroup_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
132
133
134 /* dialog sequencing */
135
136 #define WM_MSI_DIALOG_CREATE (WM_USER+0x100)
137 #define WM_MSI_DIALOG_DESTROY (WM_USER+0x101)
138
139 static DWORD uiThreadId;
140 static HWND hMsiHiddenWindow;
141
142 static INT msi_dialog_scale_unit( msi_dialog *dialog, INT val )
143 {
144 return (dialog->scale * val + 5) / 10;
145 }
146
147 static msi_control *msi_dialog_find_control( msi_dialog *dialog, LPCWSTR name )
148 {
149 msi_control *control;
150
151 if( !name )
152 return NULL;
153 LIST_FOR_EACH_ENTRY( control, &dialog->controls, msi_control, entry )
154 if( !strcmpW( control->name, name ) ) /* FIXME: case sensitive? */
155 return control;
156 return NULL;
157 }
158
159 static msi_control *msi_dialog_find_control_by_hwnd( msi_dialog *dialog, HWND hwnd )
160 {
161 msi_control *control;
162
163 LIST_FOR_EACH_ENTRY( control, &dialog->controls, msi_control, entry )
164 if( hwnd == control->hwnd )
165 return control;
166 return NULL;
167 }
168
169 static LPWSTR msi_get_deformatted_field( MSIPACKAGE *package, MSIRECORD *rec, int field )
170 {
171 LPCWSTR str = MSI_RecordGetString( rec, field );
172 LPWSTR ret = NULL;
173
174 if (str)
175 deformat_string( package, str, &ret );
176 return ret;
177 }
178
179 /*
180 * msi_dialog_get_style
181 *
182 * Extract the {\style} string from the front of the text to display and
183 * update the pointer.
184 */
185 static LPWSTR msi_dialog_get_style( LPCWSTR p, LPCWSTR *rest )
186 {
187 LPWSTR ret = NULL;
188 LPCWSTR q, i;
189 DWORD len;
190
191 *rest = p;
192 if( !p )
193 return ret;
194 if( *p++ != '{' )
195 return ret;
196 q = strchrW( p, '}' );
197 if( !q )
198 return ret;
199 if( *p == '\\' || *p == '&' )
200 p++;
201
202 /* little bit of sanity checking to stop us getting confused with RTF */
203 for( i=p; i<q; i++ )
204 if( *i == '}' || *i == '\\' )
205 return ret;
206
207 *rest = ++q;
208 len = q - p;
209
210 ret = msi_alloc( len*sizeof(WCHAR) );
211 if( !ret )
212 return ret;
213 memcpy( ret, p, len*sizeof(WCHAR) );
214 ret[len-1] = 0;
215 return ret;
216 }
217
218 static UINT msi_dialog_add_font( MSIRECORD *rec, LPVOID param )
219 {
220 msi_dialog *dialog = param;
221 msi_font *font;
222 LPCWSTR face, name;
223 LOGFONTW lf;
224 INT style;
225 HDC hdc;
226
227 /* create a font and add it to the list */
228 name = MSI_RecordGetString( rec, 1 );
229 font = msi_alloc( sizeof *font + strlenW( name )*sizeof (WCHAR) );
230 strcpyW( font->name, name );
231 font->next = dialog->font_list;
232 dialog->font_list = font;
233
234 memset( &lf, 0, sizeof lf );
235 face = MSI_RecordGetString( rec, 2 );
236 lf.lfHeight = MSI_RecordGetInteger( rec, 3 );
237 style = MSI_RecordGetInteger( rec, 5 );
238 if( style & msidbTextStyleStyleBitsBold )
239 lf.lfWeight = FW_BOLD;
240 if( style & msidbTextStyleStyleBitsItalic )
241 lf.lfItalic = TRUE;
242 if( style & msidbTextStyleStyleBitsUnderline )
243 lf.lfUnderline = TRUE;
244 if( style & msidbTextStyleStyleBitsStrike )
245 lf.lfStrikeOut = TRUE;
246 lstrcpynW( lf.lfFaceName, face, LF_FACESIZE );
247
248 /* adjust the height */
249 hdc = GetDC( dialog->hwnd );
250 if (hdc)
251 {
252 lf.lfHeight = -MulDiv(lf.lfHeight, GetDeviceCaps(hdc, LOGPIXELSY), 72);
253 ReleaseDC( dialog->hwnd, hdc );
254 }
255
256 font->hfont = CreateFontIndirectW( &lf );
257
258 TRACE("Adding font style %s\n", debugstr_w(font->name) );
259
260 return ERROR_SUCCESS;
261 }
262
263 static msi_font *msi_dialog_find_font( msi_dialog *dialog, LPCWSTR name )
264 {
265 msi_font *font;
266
267 for( font = dialog->font_list; font; font = font->next )
268 if( !strcmpW( font->name, name ) ) /* FIXME: case sensitive? */
269 break;
270
271 return font;
272 }
273
274 static UINT msi_dialog_set_font( msi_dialog *dialog, HWND hwnd, LPCWSTR name )
275 {
276 msi_font *font;
277
278 font = msi_dialog_find_font( dialog, name );
279 if( font )
280 SendMessageW( hwnd, WM_SETFONT, (WPARAM) font->hfont, TRUE );
281 else
282 ERR("No font entry for %s\n", debugstr_w(name));
283 return ERROR_SUCCESS;
284 }
285
286 static UINT msi_dialog_build_font_list( msi_dialog *dialog )
287 {
288 static const WCHAR query[] = {
289 'S','E','L','E','C','T',' ','*',' ',
290 'F','R','O','M',' ','`','T','e','x','t','S','t','y','l','e','`',' ',0
291 };
292 UINT r;
293 MSIQUERY *view = NULL;
294
295 TRACE("dialog %p\n", dialog );
296
297 r = MSI_OpenQuery( dialog->package->db, &view, query );
298 if( r != ERROR_SUCCESS )
299 return r;
300
301 r = MSI_IterateRecords( view, NULL, msi_dialog_add_font, dialog );
302 msiobj_release( &view->hdr );
303
304 return r;
305 }
306
307 static msi_control *msi_dialog_create_window( msi_dialog *dialog,
308 MSIRECORD *rec, LPCWSTR szCls, LPCWSTR name, LPCWSTR text,
309 DWORD style, HWND parent )
310 {
311 DWORD x, y, width, height;
312 LPWSTR font = NULL, title_font = NULL;
313 LPCWSTR title = NULL;
314 msi_control *control;
315
316 style |= WS_CHILD;
317
318 control = msi_alloc( sizeof *control + strlenW(name)*sizeof(WCHAR) );
319 strcpyW( control->name, name );
320 list_add_head( &dialog->controls, &control->entry );
321 control->handler = NULL;
322 control->property = NULL;
323 control->value = NULL;
324 control->hBitmap = NULL;
325 control->hIcon = NULL;
326 control->hDll = NULL;
327 control->tabnext = strdupW( MSI_RecordGetString( rec, 11) );
328
329 x = MSI_RecordGetInteger( rec, 4 );
330 y = MSI_RecordGetInteger( rec, 5 );
331 width = MSI_RecordGetInteger( rec, 6 );
332 height = MSI_RecordGetInteger( rec, 7 );
333
334 x = msi_dialog_scale_unit( dialog, x );
335 y = msi_dialog_scale_unit( dialog, y );
336 width = msi_dialog_scale_unit( dialog, width );
337 height = msi_dialog_scale_unit( dialog, height );
338
339 if( text )
340 {
341 deformat_string( dialog->package, text, &title_font );
342 font = msi_dialog_get_style( title_font, &title );
343 }
344
345 control->hwnd = CreateWindowW( szCls, title, style,
346 x, y, width, height, parent, NULL, NULL, NULL );
347
348 TRACE("Dialog %s control %s hwnd %p\n",
349 debugstr_w(dialog->name), debugstr_w(text), control->hwnd );
350
351 msi_dialog_set_font( dialog, control->hwnd,
352 font ? font : dialog->default_font );
353
354 msi_free( title_font );
355 msi_free( font );
356
357 return control;
358 }
359
360 static MSIRECORD *msi_get_binary_record( MSIDATABASE *db, LPCWSTR name )
361 {
362 const static WCHAR query[] = {
363 's','e','l','e','c','t',' ','*',' ',
364 'f','r','o','m',' ','B','i','n','a','r','y',' ',
365 'w','h','e','r','e',' ',
366 '`','N','a','m','e','`',' ','=',' ','\'','%','s','\'',0
367 };
368
369 return MSI_QueryGetRecord( db, query, name );
370 }
371
372 static LPWSTR msi_create_tmp_path(void)
373 {
374 WCHAR tmp[MAX_PATH];
375 LPWSTR path = NULL;
376 static const WCHAR prefix[] = { 'm','s','i',0 };
377 DWORD len, r;
378
379 r = GetTempPathW( MAX_PATH, tmp );
380 if( !r )
381 return path;
382 len = lstrlenW( tmp ) + 20;
383 path = msi_alloc( len * sizeof (WCHAR) );
384 if( path )
385 {
386 r = GetTempFileNameW( tmp, prefix, 0, path );
387 if (!r)
388 {
389 msi_free( path );
390 path = NULL;
391 }
392 }
393 return path;
394 }
395
396
397 static HANDLE msi_load_image( MSIDATABASE *db, LPCWSTR name, UINT type,
398 UINT cx, UINT cy, UINT flags )
399 {
400 MSIRECORD *rec = NULL;
401 HANDLE himage = NULL;
402 LPWSTR tmp;
403 UINT r;
404
405 TRACE("%p %s %u %u %08x\n", db, debugstr_w(name), cx, cy, flags);
406
407 tmp = msi_create_tmp_path();
408 if( !tmp )
409 return himage;
410
411 rec = msi_get_binary_record( db, name );
412 if( rec )
413 {
414 r = MSI_RecordStreamToFile( rec, 2, tmp );
415 if( r == ERROR_SUCCESS )
416 {
417 himage = LoadImageW( 0, tmp, type, cx, cy, flags );
418 DeleteFileW( tmp );
419 }
420 msiobj_release( &rec->hdr );
421 }
422
423 msi_free( tmp );
424 return himage;
425 }
426
427 static HICON msi_load_icon( MSIDATABASE *db, LPCWSTR text, UINT attributes )
428 {
429 DWORD cx = 0, cy = 0, flags;
430
431 flags = LR_LOADFROMFILE | LR_DEFAULTSIZE;
432 if( attributes & msidbControlAttributesFixedSize )
433 {
434 flags &= ~LR_DEFAULTSIZE;
435 if( attributes & msidbControlAttributesIconSize16 )
436 {
437 cx += 16;
438 cy += 16;
439 }
440 if( attributes & msidbControlAttributesIconSize32 )
441 {
442 cx += 32;
443 cy += 32;
444 }
445 /* msidbControlAttributesIconSize48 handled by above logic */
446 }
447 return msi_load_image( db, text, IMAGE_ICON, cx, cy, flags );
448 }
449
450
451 /* called from the Control Event subscription code */
452 void msi_dialog_handle_event( msi_dialog* dialog, LPCWSTR control,
453 LPCWSTR attribute, MSIRECORD *rec )
454 {
455 msi_control* ctrl;
456 LPCWSTR text;
457
458 ctrl = msi_dialog_find_control( dialog, control );
459 if (!ctrl)
460 return;
461 if( lstrcmpW(attribute, szText) )
462 {
463 ERR("Attribute %s\n", debugstr_w(attribute));
464 return;
465 }
466 text = MSI_RecordGetString( rec , 1 );
467 SetWindowTextW( ctrl->hwnd, text );
468 msi_dialog_check_messages( NULL );
469 }
470
471 static void msi_dialog_map_events(msi_dialog* dialog, LPCWSTR control)
472 {
473 static WCHAR Query[] = {
474 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
475 '`','E','v','e','n','t','M','a','p','p','i','n','g','`',' ',
476 'W','H','E','R','E',' ',
477 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',' ',
478 'A','N','D',' ',
479 '`','C','o','n','t','r','o','l','_','`',' ','=',' ','\'','%','s','\'',0
480 };
481 MSIRECORD *row;
482 LPCWSTR event, attribute;
483
484 row = MSI_QueryGetRecord( dialog->package->db, Query, dialog->name, control );
485 if (!row)
486 return;
487
488 event = MSI_RecordGetString( row, 3 );
489 attribute = MSI_RecordGetString( row, 4 );
490 ControlEvent_SubscribeToEvent( dialog->package, event, control, attribute );
491 msiobj_release( &row->hdr );
492 }
493
494 /* everything except radio buttons */
495 static msi_control *msi_dialog_add_control( msi_dialog *dialog,
496 MSIRECORD *rec, LPCWSTR szCls, DWORD style )
497 {
498 DWORD attributes;
499 LPCWSTR text, name;
500
501 name = MSI_RecordGetString( rec, 2 );
502 attributes = MSI_RecordGetInteger( rec, 8 );
503 text = MSI_RecordGetString( rec, 10 );
504 if( attributes & msidbControlAttributesVisible )
505 style |= WS_VISIBLE;
506 if( ~attributes & msidbControlAttributesEnabled )
507 style |= WS_DISABLED;
508
509 msi_dialog_map_events(dialog, name);
510
511 return msi_dialog_create_window( dialog, rec, szCls, name, text,
512 style, dialog->hwnd );
513 }
514
515 struct msi_text_info
516 {
517 WNDPROC oldproc;
518 DWORD attributes;
519 };
520
521 /*
522 * we don't erase our own background,
523 * so we have to make sure that the parent window redraws first
524 */
525 static void msi_text_on_settext( HWND hWnd )
526 {
527 HWND hParent;
528 RECT rc;
529
530 hParent = GetParent( hWnd );
531 GetWindowRect( hWnd, &rc );
532 MapWindowPoints( NULL, hParent, (LPPOINT) &rc, 2 );
533 InvalidateRect( hParent, &rc, TRUE );
534 }
535
536 static LRESULT WINAPI
537 MSIText_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
538 {
539 struct msi_text_info *info;
540 LRESULT r = 0;
541
542 TRACE("%p %04x %08x %08lx\n", hWnd, msg, wParam, lParam);
543
544 info = GetPropW(hWnd, szButtonData);
545
546 if( msg == WM_CTLCOLORSTATIC &&
547 ( info->attributes & msidbControlAttributesTransparent ) )
548 {
549 SetBkMode( (HDC)wParam, TRANSPARENT );
550 return (LRESULT) GetStockObject(NULL_BRUSH);
551 }
552
553 r = CallWindowProcW(info->oldproc, hWnd, msg, wParam, lParam);
554
555 switch( msg )
556 {
557 case WM_SETTEXT:
558 msi_text_on_settext( hWnd );
559 break;
560 case WM_NCDESTROY:
561 msi_free( info );
562 RemovePropW( hWnd, szButtonData );
563 break;
564 }
565
566 return r;
567 }
568
569 static UINT msi_dialog_text_control( msi_dialog *dialog, MSIRECORD *rec )
570 {
571 msi_control *control;
572 struct msi_text_info *info;
573
574 TRACE("%p %p\n", dialog, rec);
575
576 control = msi_dialog_add_control( dialog, rec, szStatic, SS_LEFT | WS_GROUP );
577 if( !control )
578 return ERROR_FUNCTION_FAILED;
579
580 info = msi_alloc( sizeof *info );
581 if( !info )
582 return ERROR_SUCCESS;
583
584 info->attributes = MSI_RecordGetInteger( rec, 8 );
585 if( info->attributes & msidbControlAttributesTransparent )
586 SetWindowLongPtrW( control->hwnd, GWL_EXSTYLE, WS_EX_TRANSPARENT );
587
588 info->oldproc = (WNDPROC) SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
589 (LONG_PTR)MSIText_WndProc );
590 SetPropW( control->hwnd, szButtonData, info );
591
592 return ERROR_SUCCESS;
593 }
594
595 static UINT msi_dialog_button_control( msi_dialog *dialog, MSIRECORD *rec )
596 {
597 msi_control *control;
598 UINT attributes, style;
599 LPWSTR text;
600
601 TRACE("%p %p\n", dialog, rec);
602
603 style = WS_TABSTOP;
604 attributes = MSI_RecordGetInteger( rec, 8 );
605 if( attributes & msidbControlAttributesIcon )
606 style |= BS_ICON;
607
608 control = msi_dialog_add_control( dialog, rec, szButton, style );
609 if( !control )
610 return ERROR_FUNCTION_FAILED;
611
612 control->handler = msi_dialog_button_handler;
613
614 /* set the icon */
615 text = msi_get_deformatted_field( dialog->package, rec, 10 );
616 control->hIcon = msi_load_icon( dialog->package->db, text, attributes );
617 if( attributes & msidbControlAttributesIcon )
618 SendMessageW( control->hwnd, BM_SETIMAGE, IMAGE_ICON, (LPARAM) control->hIcon );
619 msi_free( text );
620
621 return ERROR_SUCCESS;
622 }
623
624 static LPWSTR msi_get_checkbox_value( msi_dialog *dialog, LPCWSTR prop )
625 {
626 const static WCHAR query[] = {
627 'S','E','L','E','C','T',' ','*',' ',
628 'F','R','O','M',' ','`','C','h','e','c','k','B','o','x',' ','`',
629 'W','H','E','R','E',' ',
630 '`','P','r','o','p','e','r','t','y','`',' ','=',' ',
631 '\'','%','s','\'',0
632 };
633 MSIRECORD *rec = NULL;
634 LPWSTR ret = NULL;
635
636 /* find if there is a value associated with the checkbox */
637 rec = MSI_QueryGetRecord( dialog->package->db, query, prop );
638 if (!rec)
639 return ret;
640
641 ret = msi_get_deformatted_field( dialog->package, rec, 2 );
642 if( ret && !ret[0] )
643 {
644 msi_free( ret );
645 ret = NULL;
646 }
647 msiobj_release( &rec->hdr );
648 if (ret)
649 return ret;
650
651 ret = msi_dup_property( dialog->package, prop );
652 if( ret && !ret[0] )
653 {
654 msi_free( ret );
655 ret = NULL;
656 }
657
658 return ret;
659 }
660
661 static UINT msi_dialog_checkbox_control( msi_dialog *dialog, MSIRECORD *rec )
662 {
663 msi_control *control;
664 LPCWSTR prop;
665
666 TRACE("%p %p\n", dialog, rec);
667
668 control = msi_dialog_add_control( dialog, rec, szButton,
669 BS_CHECKBOX | BS_MULTILINE | WS_TABSTOP );
670 control->handler = msi_dialog_checkbox_handler;
671 prop = MSI_RecordGetString( rec, 9 );
672 if( prop )
673 {
674 control->property = strdupW( prop );
675 control->value = msi_get_checkbox_value( dialog, prop );
676 TRACE("control %s value %s\n", debugstr_w(control->property),
677 debugstr_w(control->value));
678 }
679 msi_dialog_checkbox_sync_state( dialog, control );
680
681 return ERROR_SUCCESS;
682 }
683
684 static UINT msi_dialog_line_control( msi_dialog *dialog, MSIRECORD *rec )
685 {
686 TRACE("%p %p\n", dialog, rec);
687
688 msi_dialog_add_control( dialog, rec, szStatic, SS_ETCHEDHORZ | SS_SUNKEN );
689 return ERROR_SUCCESS;
690 }
691
692 struct msi_streamin_info
693 {
694 LPSTR string;
695 DWORD offset;
696 DWORD length;
697 };
698
699 static DWORD CALLBACK
700 msi_richedit_stream_in( DWORD_PTR arg, LPBYTE buffer, LONG count, LONG *pcb )
701 {
702 struct msi_streamin_info *info = (struct msi_streamin_info*) arg;
703
704 if( (count + info->offset) > info->length )
705 count = info->length - info->offset;
706 memcpy( buffer, &info->string[ info->offset ], count );
707 *pcb = count;
708 info->offset += count;
709
710 TRACE("%ld/%ld\n", info->offset, info->length);
711
712 return 0;
713 }
714
715 static UINT msi_dialog_scrolltext_control( msi_dialog *dialog, MSIRECORD *rec )
716 {
717 const static WCHAR szRichEdit20W[] = {
718 'R','i','c','h','E','d','i','t','2','0','W',0
719 };
720 struct msi_streamin_info info;
721 msi_control *control;
722 LPCWSTR text;
723 EDITSTREAM es;
724 DWORD style;
725 HMODULE hRichedit;
726
727 hRichedit = LoadLibraryA("riched20");
728
729 style = WS_BORDER | ES_MULTILINE | WS_VSCROLL |
730 ES_READONLY | ES_AUTOVSCROLL | WS_TABSTOP;
731 control = msi_dialog_add_control( dialog, rec, szRichEdit20W, style );
732 if (!control)
733 return ERROR_FUNCTION_FAILED;
734
735 control->hDll = hRichedit;
736
737 text = MSI_RecordGetString( rec, 10 );
738 info.string = strdupWtoA( text );
739 info.offset = 0;
740 info.length = lstrlenA( info.string ) + 1;
741
742 es.dwCookie = (DWORD_PTR) &info;
743 es.dwError = 0;
744 es.pfnCallback = msi_richedit_stream_in;
745
746 SendMessageW( control->hwnd, EM_STREAMIN, SF_RTF, (LPARAM) &es );
747
748 msi_free( info.string );
749
750 return ERROR_SUCCESS;
751 }
752
753 static UINT msi_dialog_bitmap_control( msi_dialog *dialog, MSIRECORD *rec )
754 {
755 UINT cx, cy, flags, style, attributes;
756 msi_control *control;
757 LPWSTR text;
758
759 flags = LR_LOADFROMFILE;
760 style = SS_BITMAP | SS_LEFT | WS_GROUP;
761
762 attributes = MSI_RecordGetInteger( rec, 8 );
763 if( attributes & msidbControlAttributesFixedSize )
764 {
765 flags |= LR_DEFAULTSIZE;
766 style |= SS_CENTERIMAGE;
767 }
768
769 control = msi_dialog_add_control( dialog, rec, szStatic, style );
770 cx = MSI_RecordGetInteger( rec, 6 );
771 cy = MSI_RecordGetInteger( rec, 7 );
772 cx = msi_dialog_scale_unit( dialog, cx );
773 cy = msi_dialog_scale_unit( dialog, cy );
774
775 text = msi_get_deformatted_field( dialog->package, rec, 10 );
776 control->hBitmap = msi_load_image( dialog->package->db, text,
777 IMAGE_BITMAP, cx, cy, flags );
778 if( control->hBitmap )
779 SendMessageW( control->hwnd, STM_SETIMAGE,
780 IMAGE_BITMAP, (LPARAM) control->hBitmap );
781 else
782 ERR("Failed to load bitmap %s\n", debugstr_w(text));
783
784 msi_free( text );
785
786 return ERROR_SUCCESS;
787 }
788
789 static UINT msi_dialog_icon_control( msi_dialog *dialog, MSIRECORD *rec )
790 {
791 msi_control *control;
792 DWORD attributes;
793 LPWSTR text;
794
795 TRACE("\n");
796
797 control = msi_dialog_add_control( dialog, rec, szStatic,
798 SS_ICON | SS_CENTERIMAGE | WS_GROUP );
799
800 attributes = MSI_RecordGetInteger( rec, 8 );
801 text = msi_get_deformatted_field( dialog->package, rec, 10 );
802 control->hIcon = msi_load_icon( dialog->package->db, text, attributes );
803 if( control->hIcon )
804 SendMessageW( control->hwnd, STM_SETICON, (WPARAM) control->hIcon, 0 );
805 else
806 ERR("Failed to load bitmap %s\n", debugstr_w(text));
807 msi_free( text );
808 return ERROR_SUCCESS;
809 }
810
811 static UINT msi_dialog_combo_control( msi_dialog *dialog, MSIRECORD *rec )
812 {
813 static const WCHAR szCombo[] = { 'C','O','M','B','O','B','O','X',0 };
814
815 msi_dialog_add_control( dialog, rec, szCombo,
816 SS_BITMAP | SS_LEFT | SS_CENTERIMAGE );
817 return ERROR_SUCCESS;
818 }
819
820 static UINT msi_dialog_edit_control( msi_dialog *dialog, MSIRECORD *rec )
821 {
822 msi_control *control;
823 LPCWSTR prop;
824 LPWSTR val;
825
826 control = msi_dialog_add_control( dialog, rec, szEdit,
827 WS_BORDER | WS_TABSTOP );
828 control->handler = msi_dialog_edit_handler;
829 prop = MSI_RecordGetString( rec, 9 );
830 if( prop )
831 control->property = strdupW( prop );
832 val = msi_dup_property( dialog->package, control->property );
833 SetWindowTextW( control->hwnd, val );
834 msi_free( val );
835 return ERROR_SUCCESS;
836 }
837
838 /******************** Masked Edit ********************************************/
839
840 #define MASK_MAX_GROUPS 10
841
842 struct msi_mask_group
843 {
844 UINT len;
845 UINT ofs;
846 WCHAR type;
847 HWND hwnd;
848 };
849
850 struct msi_maskedit_info
851 {
852 msi_dialog *dialog;
853 WNDPROC oldproc;
854 HWND hwnd;
855 LPWSTR prop;
856 UINT num_chars;
857 UINT num_groups;
858 struct msi_mask_group group[MASK_MAX_GROUPS];
859 };
860
861 static void msi_mask_control_change( struct msi_maskedit_info *info )
862 {
863 LPWSTR val;
864 UINT i, n, r;
865
866 val = msi_alloc( (info->num_chars+1)*sizeof(WCHAR) );
867 for( i=0, n=0; i<info->num_groups; i++ )
868 {
869 if( (info->group[i].len + n) > info->num_chars )
870 {
871 ERR("can't fit control %d text into template\n",i);
872 break;
873 }
874 r = GetWindowTextW( info->group[i].hwnd, &val[n], info->group[i].len+1 );
875 if( r != info->group[i].len )
876 break;
877 n += r;
878 }
879
880 TRACE("%d/%d controls were good\n", i, info->num_groups);
881
882 if( i == info->num_groups )
883 {
884 TRACE("Set property %s to %s\n",
885 debugstr_w(info->prop), debugstr_w(val) );
886 CharUpperBuffW( val, info->num_chars );
887 MSI_SetPropertyW( info->dialog->package, info->prop, val );
888 msi_dialog_evaluate_control_conditions( info->dialog );
889 }
890 msi_free( val );
891 }
892
893 /* now move to the next control if necessary */
894 static VOID msi_mask_next_control( struct msi_maskedit_info *info, HWND hWnd )
895 {
896 HWND hWndNext;
897 UINT len, i;
898
899 for( i=0; i<info->num_groups; i++ )
900 if( info->group[i].hwnd == hWnd )
901 break;
902
903 /* don't move from the last control */
904 if( i >= (info->num_groups-1) )
905 return;
906
907 len = SendMessageW( hWnd, WM_GETTEXTLENGTH, 0, 0 );
908 if( len < info->group[i].len )
909 return;
910
911 hWndNext = GetNextDlgTabItem( GetParent( hWnd ), hWnd, FALSE );
912 SetFocus( hWndNext );
913 }
914
915 static LRESULT WINAPI
916 MSIMaskedEdit_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
917 {
918 struct msi_maskedit_info *info;
919 HRESULT r;
920
921 TRACE("%p %04x %08x %08lx\n", hWnd, msg, wParam, lParam);
922
923 info = GetPropW(hWnd, szButtonData);
924
925 r = CallWindowProcW(info->oldproc, hWnd, msg, wParam, lParam);
926
927 switch( msg )
928 {
929 case WM_COMMAND:
930 if (HIWORD(wParam) == EN_CHANGE)
931 {
932 msi_mask_control_change( info );
933 msi_mask_next_control( info, (HWND) lParam );
934 }
935 break;
936 case WM_NCDESTROY:
937 msi_free( info->prop );
938 msi_free( info );
939 RemovePropW( hWnd, szButtonData );
940 break;
941 }
942
943 return r;
944 }
945
946 /* fish the various bits of the property out and put them in the control */
947 static void
948 msi_maskedit_set_text( struct msi_maskedit_info *info, LPCWSTR text )
949 {
950 LPCWSTR p;
951 UINT i;
952
953 p = text;
954 for( i = 0; i < info->num_groups; i++ )
955 {
956 if( info->group[i].len < lstrlenW( p ) )
957 {
958 LPWSTR chunk = strdupW( p );
959 chunk[ info->group[i].len ] = 0;
960 SetWindowTextW( info->group[i].hwnd, chunk );
961 msi_free( chunk );
962 }
963 else
964 {
965 SetWindowTextW( info->group[i].hwnd, p );
966 break;
967 }
968 p += info->group[i].len;
969 }
970 }
971
972 static struct msi_maskedit_info * msi_dialog_parse_groups( LPCWSTR mask )
973 {
974 struct msi_maskedit_info * info = NULL;
975 int i = 0, n = 0, total = 0;
976 LPCWSTR p;
977
978 TRACE("masked control, template %s\n", debugstr_w(mask));
979
980 if( !mask )
981 return info;
982
983 p = strchrW(mask, '<');
984 if( !p )
985 return info;
986
987 info = msi_alloc_zero( sizeof *info );
988 if( !info )
989 return info;
990
991 p++;
992 for( i=0; i<MASK_MAX_GROUPS; i++ )
993 {
994 while (*p=='-')
995 {
996 total++;
997 p++;
998 }
999
1000 /* stop at the end of the string */
1001 if( p[0] == 0 || p[0] == '>' )
1002 break;
1003
1004 /* count the number of the same identifier */
1005 for( n=0; p[n] == p[0]; n++ )
1006 ;
1007 info->group[i].ofs = total;
1008 info->group[i].type = p[0];
1009 if( p[n] == '=' )
1010 {
1011 n++;
1012 total++; /* an extra not part of the group */
1013 }
1014 info->group[i].len = n;
1015 total += n;
1016 p += n;
1017 }
1018
1019 TRACE("%d characters in %d groups\n", total, i );
1020 if( i == MASK_MAX_GROUPS )
1021 ERR("too many groups in PIDTemplate %s\n", debugstr_w(mask));
1022
1023 info->num_chars = total;
1024 info->num_groups = i;
1025
1026 return info;
1027 }
1028
1029 static void
1030 msi_maskedit_create_children( struct msi_maskedit_info *info, LPCWSTR font )
1031 {
1032 DWORD width, height, style, wx, ww;
1033 RECT rect;
1034 HWND hwnd;
1035 UINT i;
1036
1037 style = WS_CHILD | WS_BORDER | WS_VISIBLE | WS_TABSTOP;
1038
1039 GetClientRect( info->hwnd, &rect );
1040
1041 width = rect.right - rect.left;
1042 height = rect.bottom - rect.top;
1043
1044 for( i = 0; i < info->num_groups; i++ )
1045 {
1046 wx = (info->group[i].ofs * width) / info->num_chars;
1047 ww = (info->group[i].len * width) / info->num_chars;
1048
1049 hwnd = CreateWindowW( szEdit, NULL, style, wx, 0, ww, height,
1050 info->hwnd, NULL, NULL, NULL );
1051 if( !hwnd )
1052 {
1053 ERR("failed to create mask edit sub window\n");
1054 break;
1055 }
1056
1057 SendMessageW( hwnd, EM_LIMITTEXT, info->group[i].len, 0 );
1058
1059 msi_dialog_set_font( info->dialog, hwnd,
1060 font?font:info->dialog->default_font );
1061 info->group[i].hwnd = hwnd;
1062 }
1063 }
1064
1065 /* office 2003 uses "73931<````=````=````=````=`````>@@@@@" */
1066 static UINT msi_dialog_maskedit_control( msi_dialog *dialog, MSIRECORD *rec )
1067 {
1068 LPWSTR font_mask, val = NULL, font;
1069 struct msi_maskedit_info *info = NULL;
1070 UINT ret = ERROR_SUCCESS;
1071 msi_control *control;
1072 LPCWSTR prop, mask;
1073
1074 TRACE("\n");
1075
1076 font_mask = msi_get_deformatted_field( dialog->package, rec, 10 );
1077 font = msi_dialog_get_style( font_mask, &mask );
1078 if( !mask )
1079 {
1080 ERR("mask template is empty\n");
1081 goto end;
1082 }
1083
1084 info = msi_dialog_parse_groups( mask );
1085 if( !info )
1086 {
1087 ERR("template %s is invalid\n", debugstr_w(mask));
1088 goto end;
1089 }
1090
1091 info->dialog = dialog;
1092
1093 control = msi_dialog_add_control( dialog, rec, szStatic,
1094 SS_OWNERDRAW | WS_GROUP | WS_VISIBLE );
1095 if( !control )
1096 {
1097 ERR("Failed to create maskedit container\n");
1098 ret = ERROR_FUNCTION_FAILED;
1099 goto end;
1100 }
1101 SetWindowLongPtrW( control->hwnd, GWL_EXSTYLE, WS_EX_CONTROLPARENT );
1102
1103 info->hwnd = control->hwnd;
1104
1105 /* subclass the static control */
1106 info->oldproc = (WNDPROC) SetWindowLongPtrW( info->hwnd, GWLP_WNDPROC,
1107 (LONG_PTR)MSIMaskedEdit_WndProc );
1108 SetPropW( control->hwnd, szButtonData, info );
1109
1110 prop = MSI_RecordGetString( rec, 9 );
1111 if( prop )
1112 info->prop = strdupW( prop );
1113
1114 msi_maskedit_create_children( info, font );
1115
1116 if( prop )
1117 {
1118 val = msi_dup_property( dialog->package, prop );
1119 if( val )
1120 {
1121 msi_maskedit_set_text( info, val );
1122 msi_free( val );
1123 }
1124 }
1125
1126 end:
1127 if( ret != ERROR_SUCCESS )
1128 msi_free( info );
1129 msi_free( font_mask );
1130 msi_free( font );
1131 return ret;
1132 }
1133
1134 /******************** Progress Bar *****************************************/
1135
1136 static UINT msi_dialog_progress_bar( msi_dialog *dialog, MSIRECORD *rec )
1137 {
1138 msi_dialog_add_control( dialog, rec, PROGRESS_CLASSW, WS_VISIBLE );
1139 return ERROR_SUCCESS;
1140 }
1141
1142 /******************** Path Edit ********************************************/
1143
1144 static UINT msi_dialog_pathedit_control( msi_dialog *dialog, MSIRECORD *rec )
1145 {
1146 FIXME("not implemented properly\n");
1147 return msi_dialog_edit_control( dialog, rec );
1148 }
1149
1150 /* radio buttons are a bit different from normal controls */
1151 static UINT msi_dialog_create_radiobutton( MSIRECORD *rec, LPVOID param )
1152 {
1153 radio_button_group_descr *group = (radio_button_group_descr *)param;
1154 msi_dialog *dialog = group->dialog;
1155 msi_control *control;
1156 LPCWSTR prop, text, name;
1157 DWORD style, attributes = group->attributes;
1158
1159 style = WS_CHILD | BS_AUTORADIOBUTTON | BS_MULTILINE | WS_TABSTOP;
1160 name = MSI_RecordGetString( rec, 3 );
1161 text = MSI_RecordGetString( rec, 8 );
1162 if( attributes & 1 )
1163 style |= WS_VISIBLE;
1164 if( ~attributes & 2 )
1165 style |= WS_DISABLED;
1166
1167 control = msi_dialog_create_window( dialog, rec, szButton, name, text,
1168 style, group->parent->hwnd );
1169 if (!control)
1170 return ERROR_FUNCTION_FAILED;
1171 control->handler = msi_dialog_radiogroup_handler;
1172
1173 prop = MSI_RecordGetString( rec, 1 );
1174 if( prop )
1175 control->property = strdupW( prop );
1176
1177 return ERROR_SUCCESS;
1178 }
1179
1180 static UINT msi_dialog_radiogroup_control( msi_dialog *dialog, MSIRECORD *rec )
1181 {
1182 static const WCHAR query[] = {
1183 'S','E','L','E','C','T',' ','*',' ',
1184 'F','R','O','M',' ','R','a','d','i','o','B','u','t','t','o','n',' ',
1185 'W','H','E','R','E',' ',
1186 '`','P','r','o','p','e','r','t','y','`',' ','=',' ','\'','%','s','\'',0};
1187 UINT r;
1188 LPCWSTR prop;
1189 msi_control *control;
1190 MSIQUERY *view = NULL;
1191 radio_button_group_descr group;
1192 MSIPACKAGE *package = dialog->package;
1193 WNDPROC oldproc;
1194
1195 prop = MSI_RecordGetString( rec, 9 );
1196
1197 TRACE("%p %p %s\n", dialog, rec, debugstr_w( prop ));
1198
1199 /* Create parent group box to hold radio buttons */
1200 control = msi_dialog_add_control( dialog, rec, szButton, BS_OWNERDRAW|WS_GROUP );
1201 if( !control )
1202 return ERROR_FUNCTION_FAILED;
1203
1204 oldproc = (WNDPROC) SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
1205 (LONG_PTR)MSIRadioGroup_WndProc );
1206 SetPropW(control->hwnd, szButtonData, oldproc);
1207 SetWindowLongPtrW( control->hwnd, GWL_EXSTYLE, WS_EX_CONTROLPARENT );
1208
1209 if( prop )
1210 control->property = strdupW( prop );
1211
1212 /* query the Radio Button table for all control in this group */
1213 r = MSI_OpenQuery( package->db, &view, query, prop );
1214 if( r != ERROR_SUCCESS )
1215 {
1216 ERR("query failed for dialog %s radio group %s\n",
1217 debugstr_w(dialog->name), debugstr_w(prop));
1218 return ERROR_INVALID_PARAMETER;
1219 }
1220
1221 group.dialog = dialog;
1222 group.parent = control;
1223 group.attributes = MSI_RecordGetInteger( rec, 8 );
1224
1225 r = MSI_IterateRecords( view, 0, msi_dialog_create_radiobutton, &group );
1226 msiobj_release( &view->hdr );
1227
1228 return r;
1229 }
1230
1231 struct control_handler msi_dialog_handler[] =
1232 {
1233 { szText, msi_dialog_text_control },
1234 { szPushButton, msi_dialog_button_control },
1235 { szLine, msi_dialog_line_control },
1236 { szBitmap, msi_dialog_bitmap_control },
1237 { szCheckBox, msi_dialog_checkbox_control },
1238 { szScrollableText, msi_dialog_scrolltext_control },
1239 { szComboBox, msi_dialog_combo_control },
1240 { szEdit, msi_dialog_edit_control },
1241 { szMaskedEdit, msi_dialog_maskedit_control },
1242 { szPathEdit, msi_dialog_pathedit_control },
1243 { szProgressBar, msi_dialog_progress_bar },
1244 { szRadioButtonGroup, msi_dialog_radiogroup_control },
1245 { szIcon, msi_dialog_icon_control },
1246 };
1247
1248 #define NUM_CONTROL_TYPES (sizeof msi_dialog_handler/sizeof msi_dialog_handler[0])
1249
1250 static UINT msi_dialog_create_controls( MSIRECORD *rec, LPVOID param )
1251 {
1252 msi_dialog *dialog = param;
1253 LPCWSTR control_type;
1254 UINT i;
1255
1256 /* find and call the function that can create this type of control */
1257 control_type = MSI_RecordGetString( rec, 3 );
1258 for( i=0; i<NUM_CONTROL_TYPES; i++ )
1259 if (!strcmpiW( msi_dialog_handler[i].control_type, control_type ))
1260 break;
1261 if( i != NUM_CONTROL_TYPES )
1262 msi_dialog_handler[i].func( dialog, rec );
1263 else
1264 ERR("no handler for element type %s\n", debugstr_w(control_type));
1265
1266 return ERROR_SUCCESS;
1267 }
1268
1269 static UINT msi_dialog_fill_controls( msi_dialog *dialog )
1270 {
1271 static const WCHAR query[] = {
1272 'S','E','L','E','C','T',' ','*',' ',
1273 'F','R','O','M',' ','C','o','n','t','r','o','l',' ',
1274 'W','H','E','R','E',' ',
1275 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',0};
1276 UINT r;
1277 MSIQUERY *view = NULL;
1278 MSIPACKAGE *package = dialog->package;
1279
1280 TRACE("%p %s\n", dialog, debugstr_w(dialog->name) );
1281
1282 /* query the Control table for all the elements of the control */
1283 r = MSI_OpenQuery( package->db, &view, query, dialog->name );
1284 if( r != ERROR_SUCCESS )
1285 {
1286 ERR("query failed for dialog %s\n", debugstr_w(dialog->name));
1287 return ERROR_INVALID_PARAMETER;
1288 }
1289
1290 r = MSI_IterateRecords( view, 0, msi_dialog_create_controls, dialog );
1291 msiobj_release( &view->hdr );
1292
1293 return r;
1294 }
1295
1296 static UINT msi_dialog_set_control_condition( MSIRECORD *rec, LPVOID param )
1297 {
1298 static const WCHAR szHide[] = { 'H','i','d','e',0 };
1299 static const WCHAR szShow[] = { 'S','h','o','w',0 };
1300 static const WCHAR szDisable[] = { 'D','i','s','a','b','l','e',0 };
1301 static const WCHAR szEnable[] = { 'E','n','a','b','l','e',0 };
1302 msi_dialog *dialog = param;
1303 msi_control *control;
1304 LPCWSTR name, action, condition;
1305 UINT r;
1306
1307 name = MSI_RecordGetString( rec, 2 );
1308 action = MSI_RecordGetString( rec, 3 );
1309 condition = MSI_RecordGetString( rec, 4 );
1310 r = MSI_EvaluateConditionW( dialog->package, condition );
1311 control = msi_dialog_find_control( dialog, name );
1312 if( r && control )
1313 {
1314 TRACE("%s control %s\n", debugstr_w(action), debugstr_w(name));
1315
1316 /* FIXME: case sensitive? */
1317 if(!lstrcmpW(action, szHide))
1318 ShowWindow(control->hwnd, SW_HIDE);
1319 else if(!strcmpW(action, szShow))
1320 ShowWindow(control->hwnd, SW_SHOW);
1321 else if(!strcmpW(action, szDisable))
1322 EnableWindow(control->hwnd, FALSE);
1323 else if(!strcmpW(action, szEnable))
1324 EnableWindow(control->hwnd, TRUE);
1325 else
1326 FIXME("Unhandled action %s\n", debugstr_w(action));
1327 }
1328
1329 return ERROR_SUCCESS;
1330 }
1331
1332 static UINT msi_dialog_evaluate_control_conditions( msi_dialog *dialog )
1333 {
1334 static const WCHAR query[] = {
1335 'S','E','L','E','C','T',' ','*',' ',
1336 'F','R','O','M',' ',
1337 'C','o','n','t','r','o','l','C','o','n','d','i','t','i','o','n',' ',
1338 'W','H','E','R','E',' ',
1339 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',0
1340 };
1341 UINT r;
1342 MSIQUERY *view = NULL;
1343 MSIPACKAGE *package = dialog->package;
1344
1345 TRACE("%p %s\n", dialog, debugstr_w(dialog->name) );
1346
1347 /* query the Control table for all the elements of the control */
1348 r = MSI_OpenQuery( package->db, &view, query, dialog->name );
1349 if( r != ERROR_SUCCESS )
1350 {
1351 ERR("query failed for dialog %s\n", debugstr_w(dialog->name));
1352 return ERROR_INVALID_PARAMETER;
1353 }
1354
1355 r = MSI_IterateRecords( view, 0, msi_dialog_set_control_condition, dialog );
1356 msiobj_release( &view->hdr );
1357
1358 return r;
1359 }
1360
1361 /* figure out the height of 10 point MS Sans Serif */
1362 static INT msi_dialog_get_sans_serif_height( HWND hwnd )
1363 {
1364 static const WCHAR szSansSerif[] = {
1365 'M','S',' ','S','a','n','s',' ','S','e','r','i','f',0 };
1366 LOGFONTW lf;
1367 TEXTMETRICW tm;
1368 BOOL r;
1369 LONG height = 0;
1370 HFONT hFont, hOldFont;
1371 HDC hdc;
1372
1373 hdc = GetDC( hwnd );
1374 if (hdc)
1375 {
1376 memset( &lf, 0, sizeof lf );
1377 lf.lfHeight = MulDiv(10, GetDeviceCaps(hdc, LOGPIXELSY), 72);
1378 strcpyW( lf.lfFaceName, szSansSerif );
1379 hFont = CreateFontIndirectW(&lf);
1380 if (hFont)
1381 {
1382 hOldFont = SelectObject( hdc, hFont );
1383 r = GetTextMetricsW( hdc, &tm );
1384 if (r)
1385 height = tm.tmHeight;
1386 SelectObject( hdc, hOldFont );
1387 DeleteObject( hFont );
1388 }
1389 ReleaseDC( hwnd, hdc );
1390 }
1391 return height;
1392 }
1393
1394 /* fetch the associated record from the Dialog table */
1395 static MSIRECORD *msi_get_dialog_record( msi_dialog *dialog )
1396 {
1397 static const WCHAR query[] = {
1398 'S','E','L','E','C','T',' ','*',' ',
1399 'F','R','O','M',' ','D','i','a','l','o','g',' ',
1400 'W','H','E','R','E',' ',
1401 '`','D','i','a','l','o','g','`',' ','=',' ','\'','%','s','\'',0};
1402 MSIPACKAGE *package = dialog->package;
1403 MSIRECORD *rec = NULL;
1404
1405 TRACE("%p %s\n", dialog, debugstr_w(dialog->name) );
1406
1407 rec = MSI_QueryGetRecord( package->db, query, dialog->name );
1408 if( !rec )
1409 ERR("query failed for dialog %s\n", debugstr_w(dialog->name));
1410
1411 return rec;
1412 }
1413
1414 static void msi_dialog_adjust_dialog_size( msi_dialog *dialog, LPSIZE sz )
1415 {
1416 RECT rect;
1417 LONG style;
1418
1419 /* turn the client size into the window rectangle */
1420 rect.left = 0;
1421 rect.top = 0;
1422 rect.right = msi_dialog_scale_unit( dialog, sz->cx );
1423 rect.bottom = msi_dialog_scale_unit( dialog, sz->cy );
1424 style = GetWindowLongPtrW( dialog->hwnd, GWL_STYLE );
1425 AdjustWindowRect( &rect, style, FALSE );
1426 sz->cx = rect.right - rect.left;
1427 sz->cy = rect.bottom - rect.top;
1428 }
1429
1430 static BOOL msi_control_set_next( msi_control *control, msi_control *next )
1431 {
1432 return SetWindowPos( next->hwnd, control->hwnd, 0, 0, 0, 0,
1433 SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOREDRAW |
1434 SWP_NOREPOSITION | SWP_NOSENDCHANGING | SWP_NOSIZE );
1435 }
1436
1437 static UINT msi_dialog_set_tab_order( msi_dialog *dialog )
1438 {
1439 msi_control *control, *tab_next;
1440
1441 LIST_FOR_EACH_ENTRY( control, &dialog->controls, msi_control, entry )
1442 {
1443 tab_next = msi_dialog_find_control( dialog, control->tabnext );
1444 if( !tab_next )
1445 continue;
1446 msi_control_set_next( control, tab_next );
1447 }
1448
1449 return ERROR_SUCCESS;
1450 }
1451
1452 static void msi_dialog_set_first_control( msi_dialog* dialog, LPCWSTR name )
1453 {
1454 msi_control *control;
1455
1456 control = msi_dialog_find_control( dialog, name );
1457 if( control )
1458 dialog->hWndFocus = control->hwnd;
1459 else
1460 dialog->hWndFocus = NULL;
1461 }
1462
1463 static LRESULT msi_dialog_oncreate( HWND hwnd, LPCREATESTRUCTW cs )
1464 {
1465 static const WCHAR df[] = {
1466 'D','e','f','a','u','l','t','U','I','F','o','n','t',0 };
1467 msi_dialog *dialog = (msi_dialog*) cs->lpCreateParams;
1468 MSIRECORD *rec = NULL;
1469 LPWSTR title = NULL;
1470 SIZE size;
1471
1472 TRACE("%p %p\n", dialog, dialog->package);
1473
1474 dialog->hwnd = hwnd;
1475 SetWindowLongPtrW( hwnd, GWLP_USERDATA, (LONG_PTR) dialog );
1476
1477 rec = msi_get_dialog_record( dialog );
1478 if( !rec )
1479 {
1480 TRACE("No record found for dialog %s\n", debugstr_w(dialog->name));
1481 return -1;
1482 }
1483
1484 dialog->scale = msi_dialog_get_sans_serif_height(dialog->hwnd);
1485
1486 size.cx = MSI_RecordGetInteger( rec, 4 );
1487 size.cy = MSI_RecordGetInteger( rec, 5 );
1488 msi_dialog_adjust_dialog_size( dialog, &size );
1489
1490 dialog->attributes = MSI_RecordGetInteger( rec, 6 );
1491
1492 dialog->default_font = msi_dup_property( dialog->package, df );
1493
1494 title = msi_get_deformatted_field( dialog->package, rec, 7 );
1495 SetWindowTextW( hwnd, title );
1496 msi_free( title );
1497
1498 SetWindowPos( hwnd, 0, 0, 0, size.cx, size.cy,
1499 SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOREDRAW );
1500
1501
1502 msi_dialog_build_font_list( dialog );
1503 msi_dialog_fill_controls( dialog );
1504 msi_dialog_evaluate_control_conditions( dialog );
1505 msi_dialog_set_tab_order( dialog );
1506 msi_dialog_set_first_control( dialog, MSI_RecordGetString( rec, 8 ) );
1507 msiobj_release( &rec->hdr );
1508
1509 return 0;
1510 }
1511
1512 static UINT msi_dialog_send_event( msi_dialog *dialog, LPCWSTR event, LPCWSTR arg )
1513 {
1514 LPWSTR event_fmt = NULL, arg_fmt = NULL;
1515
1516 TRACE("Sending control event %s %s\n", debugstr_w(event), debugstr_w(arg));
1517
1518 deformat_string( dialog->package, event, &event_fmt );
1519 deformat_string( dialog->package, arg, &arg_fmt );
1520
1521 dialog->event_handler( dialog->package, event_fmt, arg_fmt, dialog );
1522
1523 msi_free( event_fmt );
1524 msi_free( arg_fmt );
1525
1526 return ERROR_SUCCESS;
1527 }
1528
1529 static UINT msi_dialog_set_property( msi_dialog *dialog, LPCWSTR event, LPCWSTR arg )
1530 {
1531 static const WCHAR szNullArg[] = { '{','}',0 };
1532 LPWSTR p, prop, arg_fmt = NULL;
1533 UINT len;
1534
1535 len = strlenW(event);
1536 prop = msi_alloc( len*sizeof(WCHAR));
1537 strcpyW( prop, &event[1] );
1538 p = strchrW( prop, ']' );
1539 if( p && p[1] == 0 )
1540 {
1541 *p = 0;
1542 if( strcmpW( szNullArg, arg ) )
1543 deformat_string( dialog->package, arg, &arg_fmt );
1544 MSI_SetPropertyW( dialog->package, prop, arg_fmt );
1545 msi_free( arg_fmt );
1546 }
1547 else
1548 ERR("Badly formatted property string - what happens?\n");
1549 msi_free( prop );
1550 return ERROR_SUCCESS;
1551 }
1552
1553 static UINT msi_dialog_control_event( MSIRECORD *rec, LPVOID param )
1554 {
1555 msi_dialog *dialog = param;
1556 LPCWSTR condition, event, arg;
1557 UINT r;
1558
1559 condition = MSI_RecordGetString( rec, 5 );
1560 r = MSI_EvaluateConditionW( dialog->package, condition );
1561 if( r )
1562 {
1563 event = MSI_RecordGetString( rec, 3 );
1564 arg = MSI_RecordGetString( rec, 4 );
1565 if( event[0] == '[' )
1566 msi_dialog_set_property( dialog, event, arg );
1567 else
1568 msi_dialog_send_event( dialog, event, arg );
1569 }
1570
1571 return ERROR_SUCCESS;
1572 }
1573
1574 static UINT msi_dialog_button_handler( msi_dialog *dialog,
1575 msi_control *control, WPARAM param )
1576 {
1577 static const WCHAR query[] = {
1578 'S','E','L','E','C','T',' ','*',' ',
1579 'F','R','O','M',' ','C','o','n','t','r','o','l','E','v','e','n','t',' ',
1580 'W','H','E','R','E',' ',
1581 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',' ',
1582 'A','N','D',' ',
1583 '`','C','o','n','t','r','o','l','_','`',' ','=',' ','\'','%','s','\'',' ',
1584 'O','R','D','E','R',' ','B','Y',' ','`','O','r','d','e','r','i','n','g','`',0
1585 };
1586 MSIQUERY *view = NULL;
1587 UINT r;
1588
1589 if( HIWORD(param) != BN_CLICKED )
1590 return ERROR_SUCCESS;
1591
1592 r = MSI_OpenQuery( dialog->package->db, &view, query,
1593 dialog->name, control->name );
1594 if( r != ERROR_SUCCESS )
1595 {
1596 ERR("query failed\n");
1597 return 0;
1598 }
1599
1600 r = MSI_IterateRecords( view, 0, msi_dialog_control_event, dialog );
1601 msiobj_release( &view->hdr );
1602
1603 return r;
1604 }
1605
1606 static UINT msi_dialog_get_checkbox_state( msi_dialog *dialog,
1607 msi_control *control )
1608 {
1609 WCHAR state[2] = { 0 };
1610 DWORD sz = 2;
1611
1612 MSI_GetPropertyW( dialog->package, control->property, state, &sz );
1613 return state[0] ? 1 : 0;
1614 }
1615
1616 static void msi_dialog_set_checkbox_state( msi_dialog *dialog,
1617 msi_control *control, UINT state )
1618 {
1619 static const WCHAR szState[] = { '1', 0 };
1620 LPCWSTR val;
1621
1622 /* if uncheck then the property is set to NULL */
1623 if (!state)
1624 {
1625 MSI_SetPropertyW( dialog->package, control->property, NULL );
1626 return;
1627 }
1628
1629 /* check for a custom state */
1630 if (control->value && control->value[0])
1631 val = control->value;
1632 else
1633 val = szState;
1634
1635 MSI_SetPropertyW( dialog->package, control->property, val );
1636 }
1637
1638 static void msi_dialog_checkbox_sync_state( msi_dialog *dialog,
1639 msi_control *control )
1640 {
1641 UINT state;
1642
1643 state = msi_dialog_get_checkbox_state( dialog, control );
1644 SendMessageW( control->hwnd, BM_SETCHECK,
1645 state ? BST_CHECKED : BST_UNCHECKED, 0 );
1646 }
1647
1648 static UINT msi_dialog_checkbox_handler( msi_dialog *dialog,
1649 msi_control *control, WPARAM param )
1650 {
1651 UINT state;
1652
1653 if( HIWORD(param) != BN_CLICKED )
1654 return ERROR_SUCCESS;
1655
1656 TRACE("clicked checkbox %s, set %s\n", debugstr_w(control->name),
1657 debugstr_w(control->property));
1658
1659 state = msi_dialog_get_checkbox_state( dialog, control );
1660 state = state ? 0 : 1;
1661 msi_dialog_set_checkbox_state( dialog, control, state );
1662 msi_dialog_checkbox_sync_state( dialog, control );
1663
1664 return msi_dialog_button_handler( dialog, control, param );
1665 }
1666
1667 static UINT msi_dialog_edit_handler( msi_dialog *dialog,
1668 msi_control *control, WPARAM param )
1669 {
1670 UINT sz, r;
1671 LPWSTR buf;
1672
1673 if( HIWORD(param) != EN_CHANGE )
1674 return ERROR_SUCCESS;
1675
1676 TRACE("edit %s contents changed, set %s\n", debugstr_w(control->name),
1677 debugstr_w(control->property));
1678
1679 sz = 0x20;
1680 buf = msi_alloc( sz*sizeof(WCHAR) );
1681 while( buf )
1682 {
1683 r = GetWindowTextW( control->hwnd, buf, sz );
1684 if( r < (sz-1) )
1685 break;
1686 sz *= 2;
1687 buf = msi_realloc( buf, sz*sizeof(WCHAR) );
1688 }
1689
1690 MSI_SetPropertyW( dialog->package, control->property, buf );
1691
1692 msi_free( buf );
1693
1694 return ERROR_SUCCESS;
1695 }
1696
1697 static UINT msi_dialog_radiogroup_handler( msi_dialog *dialog,
1698 msi_control *control, WPARAM param )
1699 {
1700 if( HIWORD(param) != BN_CLICKED )
1701 return ERROR_SUCCESS;
1702
1703 TRACE("clicked radio button %s, set %s\n", debugstr_w(control->name),
1704 debugstr_w(control->property));
1705
1706 MSI_SetPropertyW( dialog->package, control->property, control->name );
1707
1708 return msi_dialog_button_handler( dialog, control, param );
1709 }
1710
1711 static LRESULT msi_dialog_oncommand( msi_dialog *dialog, WPARAM param, HWND hwnd )
1712 {
1713 msi_control *control;
1714
1715 TRACE("%p %p %08x\n", dialog, hwnd, param);
1716
1717 control = msi_dialog_find_control_by_hwnd( dialog, hwnd );
1718 if( control )
1719 {
1720 if( control->handler )
1721 {
1722 control->handler( dialog, control, param );
1723 msi_dialog_evaluate_control_conditions( dialog );
1724 }
1725 }
1726 else
1727 ERR("button click from nowhere\n");
1728 return 0;
1729 }
1730
1731 static void msi_dialog_setfocus( msi_dialog *dialog )
1732 {
1733 HWND hwnd = dialog->hWndFocus;
1734
1735 hwnd = GetNextDlgTabItem( dialog->hwnd, hwnd, TRUE);
1736 hwnd = GetNextDlgTabItem( dialog->hwnd, hwnd, FALSE);
1737 SetFocus( hwnd );
1738 dialog->hWndFocus = hwnd;
1739 }
1740
1741 static LRESULT WINAPI MSIDialog_WndProc( HWND hwnd, UINT msg,
1742 WPARAM wParam, LPARAM lParam )
1743 {
1744 msi_dialog *dialog = (LPVOID) GetWindowLongPtrW( hwnd, GWLP_USERDATA );
1745
1746 TRACE("0x%04x\n", msg);
1747
1748 switch (msg)
1749 {
1750 case WM_CREATE:
1751 return msi_dialog_oncreate( hwnd, (LPCREATESTRUCTW)lParam );
1752
1753 case WM_COMMAND:
1754 return msi_dialog_oncommand( dialog, wParam, (HWND)lParam );
1755
1756 case WM_ACTIVATE:
1757 if( LOWORD(wParam) == WA_INACTIVE )
1758 dialog->hWndFocus = GetFocus();
1759 else
1760 msi_dialog_setfocus( dialog );
1761 return 0;
1762
1763 case WM_SETFOCUS:
1764 msi_dialog_setfocus( dialog );
1765 return 0;
1766
1767 /* bounce back to our subclassed static control */
1768 case WM_CTLCOLORSTATIC:
1769 return SendMessageW( (HWND) lParam, WM_CTLCOLORSTATIC, wParam, lParam );
1770
1771 case WM_DESTROY:
1772 dialog->hwnd = NULL;
1773 return 0;
1774 }
1775 return DefWindowProcW(hwnd, msg, wParam, lParam);
1776 }
1777
1778 static LRESULT WINAPI MSIRadioGroup_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
1779 {
1780 WNDPROC oldproc = (WNDPROC) GetPropW(hWnd, szButtonData);
1781
1782 TRACE("hWnd %p msg %04x wParam 0x%08x lParam 0x%08lx\n", hWnd, msg, wParam, lParam);
1783
1784 if (msg == WM_COMMAND) /* Forward notifications to dialog */
1785 SendMessageW(GetParent(hWnd), msg, wParam, lParam);
1786
1787 return CallWindowProcW(oldproc, hWnd, msg, wParam, lParam);
1788 }
1789
1790 static LRESULT WINAPI MSIHiddenWindowProc( HWND hwnd, UINT msg,
1791 WPARAM wParam, LPARAM lParam )
1792 {
1793 msi_dialog *dialog = (msi_dialog*) lParam;
1794
1795 TRACE("%d %p\n", msg, dialog);
1796
1797 switch (msg)
1798 {
1799 case WM_MSI_DIALOG_CREATE:
1800 return msi_dialog_run_message_loop( dialog );
1801 case WM_MSI_DIALOG_DESTROY:
1802 msi_dialog_destroy( dialog );
1803 return 0;
1804 }
1805 return DefWindowProcW( hwnd, msg, wParam, lParam );
1806 }
1807
1808 /* functions that interface to other modules within MSI */
1809
1810 msi_dialog *msi_dialog_create( MSIPACKAGE* package, LPCWSTR szDialogName,
1811 msi_dialog_event_handler event_handler )
1812 {
1813 MSIRECORD *rec = NULL;
1814 msi_dialog *dialog;
1815
1816 TRACE("%p %s\n", package, debugstr_w(szDialogName));
1817
1818 /* allocate the structure for the dialog to use */
1819 dialog = msi_alloc_zero( sizeof *dialog + sizeof(WCHAR)*strlenW(szDialogName) );
1820 if( !dialog )
1821 return NULL;
1822 strcpyW( dialog->name, szDialogName );
1823 msiobj_addref( &package->hdr );
1824 dialog->package = package;
1825 dialog->event_handler = event_handler;
1826 dialog->finished = 0;
1827 list_init( &dialog->controls );
1828
1829 /* verify that the dialog exists */
1830 rec = msi_get_dialog_record( dialog );
1831 if( !rec )
1832 {
1833 msiobj_release( &package->hdr );
1834 msi_free( dialog );
1835 return NULL;
1836 }
1837 dialog->attributes = MSI_RecordGetInteger( rec, 6 );
1838 msiobj_release( &rec->hdr );
1839
1840 return dialog;
1841 }
1842
1843 static void msi_process_pending_messages( HWND hdlg )
1844 {
1845 MSG msg;
1846
1847 while( PeekMessageW( &msg, 0, 0, 0, PM_REMOVE ) )
1848 {
1849 if( hdlg && IsDialogMessageW( hdlg, &msg ))
1850 continue;
1851 TranslateMessage( &msg );
1852 DispatchMessageW( &msg );
1853 }
1854 }
1855
1856 void msi_dialog_end_dialog( msi_dialog *dialog )
1857 {
1858 TRACE("%p\n", dialog);
1859 dialog->finished = 1;
1860 PostMessageW(dialog->hwnd, WM_NULL, 0, 0);
1861 }
1862
1863 void msi_dialog_check_messages( HANDLE handle )
1864 {
1865 DWORD r;
1866
1867 /* in threads other than the UI thread, block */
1868 if( uiThreadId != GetCurrentThreadId() )
1869 {
1870 if( handle )
1871 WaitForSingleObject( handle, INFINITE );
1872 return;
1873 }
1874
1875 /* there's two choices for the UI thread */
1876 while (1)
1877 {
1878 msi_process_pending_messages( NULL );
1879
1880 if( !handle )
1881 break;
1882
1883 /*
1884 * block here until somebody creates a new dialog or
1885 * the handle we're waiting on becomes ready
1886 */
1887 r = MsgWaitForMultipleObjects( 1, &handle, 0, INFINITE, QS_ALLINPUT );
1888 if( r == WAIT_OBJECT_0 )
1889 break;
1890 }
1891 }
1892
1893 UINT msi_dialog_run_message_loop( msi_dialog *dialog )
1894 {
1895 HWND hwnd;
1896
1897 if( !(dialog->attributes & msidbDialogAttributesVisible) )
1898 return ERROR_SUCCESS;
1899
1900 if( uiThreadId != GetCurrentThreadId() )
1901 return SendMessageW( hMsiHiddenWindow, WM_MSI_DIALOG_CREATE, 0, (LPARAM) dialog );
1902
1903 /* create the dialog window, don't show it yet */
1904 hwnd = CreateWindowW( szMsiDialogClass, dialog->name, WS_OVERLAPPEDWINDOW,
1905 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
1906 NULL, NULL, NULL, dialog );
1907 if( !hwnd )
1908 {
1909 ERR("Failed to create dialog %s\n", debugstr_w( dialog->name ));
1910 return ERROR_FUNCTION_FAILED;
1911 }
1912
1913 ShowWindow( hwnd, SW_SHOW );
1914 /* UpdateWindow( hwnd ); - and causes the transparent static controls not to paint */
1915
1916 if( dialog->attributes & msidbDialogAttributesModal )
1917 {
1918 while( !dialog->finished )
1919 {
1920 MsgWaitForMultipleObjects( 0, NULL, 0, INFINITE, QS_ALLEVENTS );
1921 msi_process_pending_messages( dialog->hwnd );
1922 }
1923 }
1924 else
1925 return ERROR_IO_PENDING;
1926
1927 return ERROR_SUCCESS;
1928 }
1929
1930 void msi_dialog_do_preview( msi_dialog *dialog )
1931 {
1932 TRACE("\n");
1933 dialog->attributes |= msidbDialogAttributesVisible;
1934 dialog->attributes &= ~msidbDialogAttributesModal;
1935 msi_dialog_run_message_loop( dialog );
1936 }
1937
1938 void msi_dialog_destroy( msi_dialog *dialog )
1939 {
1940 if( uiThreadId != GetCurrentThreadId() )
1941 {
1942 SendMessageW( hMsiHiddenWindow, WM_MSI_DIALOG_DESTROY, 0, (LPARAM) dialog );
1943 return;
1944 }
1945
1946 if( dialog->hwnd )
1947 ShowWindow( dialog->hwnd, SW_HIDE );
1948
1949 if( dialog->hwnd )
1950 DestroyWindow( dialog->hwnd );
1951
1952 /* destroy the list of controls */
1953 while( !list_empty( &dialog->controls ) )
1954 {
1955 msi_control *t = LIST_ENTRY( list_head( &dialog->controls ),
1956 msi_control, entry );
1957 list_remove( &t->entry );
1958 /* leave dialog->hwnd - destroying parent destroys child windows */
1959 msi_free( t->property );
1960 msi_free( t->value );
1961 if( t->hBitmap )
1962 DeleteObject( t->hBitmap );
1963 if( t->hIcon )
1964 DestroyIcon( t->hIcon );
1965 msi_free( t->tabnext );
1966 msi_free( t );
1967 if (t->hDll)
1968 FreeLibrary( t->hDll );
1969 }
1970
1971 /* destroy the list of fonts */
1972 while( dialog->font_list )
1973 {
1974 msi_font *t = dialog->font_list;
1975 dialog->font_list = t->next;
1976 DeleteObject( t->hfont );
1977 msi_free( t );
1978 }
1979 msi_free( dialog->default_font );
1980
1981 msiobj_release( &dialog->package->hdr );
1982 dialog->package = NULL;
1983 msi_free( dialog );
1984 }
1985
1986 BOOL msi_dialog_register_class( void )
1987 {
1988 WNDCLASSW cls;
1989
1990 ZeroMemory( &cls, sizeof cls );
1991 cls.lpfnWndProc = MSIDialog_WndProc;
1992 cls.hInstance = NULL;
1993 cls.hIcon = LoadIconW(0, (LPWSTR)IDI_APPLICATION);
1994 cls.hCursor = LoadCursorW(0, (LPWSTR)IDC_ARROW);
1995 cls.hbrBackground = (HBRUSH)(COLOR_3DFACE + 1);
1996 cls.lpszMenuName = NULL;
1997 cls.lpszClassName = szMsiDialogClass;
1998
1999 if( !RegisterClassW( &cls ) )
2000 return FALSE;
2001
2002 cls.lpfnWndProc = MSIHiddenWindowProc;
2003 cls.lpszClassName = szMsiHiddenWindow;
2004
2005 if( !RegisterClassW( &cls ) )
2006 return FALSE;
2007
2008 uiThreadId = GetCurrentThreadId();
2009
2010 hMsiHiddenWindow = CreateWindowW( szMsiHiddenWindow, NULL, WS_OVERLAPPED,
2011 0, 0, 100, 100, NULL, NULL, NULL, NULL );
2012 if( !hMsiHiddenWindow )
2013 return FALSE;
2014
2015 return TRUE;
2016 }
2017
2018 void msi_dialog_unregister_class( void )
2019 {
2020 DestroyWindow( hMsiHiddenWindow );
2021 UnregisterClassW( szMsiDialogClass, NULL );
2022 uiThreadId = 0;
2023 }