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