msi: Unload riched20 after its window is destroyed.
[wine/multimedia.git] / dlls / msi / dialog.c
blobd0bf75bd9ec591cbef351ad8fe3acccf1302c447
1 /*
2 * Implementation of the Microsoft Installer (msi.dll)
4 * Copyright 2005 Mike McCormack for CodeWeavers
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #define COBJMACROS
22 #define NONAMELESSUNION
23 #define NONAMELESSSTRUCT
25 #include <stdarg.h>
27 #include "windef.h"
28 #include "winbase.h"
29 #include "winuser.h"
30 #include "winnls.h"
31 #include "wingdi.h"
32 #include "msi.h"
33 #include "msipriv.h"
34 #include "msidefs.h"
35 #include "ocidl.h"
36 #include "olectl.h"
37 #include "richedit.h"
38 #include "commctrl.h"
40 #include "wine/debug.h"
41 #include "wine/unicode.h"
43 #include "action.h"
45 WINE_DEFAULT_DEBUG_CHANNEL(msi);
48 struct msi_control_tag;
49 typedef struct msi_control_tag msi_control;
50 typedef UINT (*msi_handler)( msi_dialog *, msi_control *, WPARAM );
52 struct msi_control_tag
54 struct list entry;
55 HWND hwnd;
56 msi_handler handler;
57 LPWSTR property;
58 LPWSTR value;
59 HBITMAP hBitmap;
60 HICON hIcon;
61 LPWSTR tabnext;
62 HMODULE hDll;
63 WCHAR name[1];
66 typedef struct msi_font_tag
68 struct msi_font_tag *next;
69 HFONT hfont;
70 WCHAR name[1];
71 } msi_font;
73 struct msi_dialog_tag
75 MSIPACKAGE *package;
76 msi_dialog_event_handler event_handler;
77 BOOL finished;
78 INT scale;
79 DWORD attributes;
80 HWND hwnd;
81 LPWSTR default_font;
82 msi_font *font_list;
83 struct list controls;
84 HWND hWndFocus;
85 LPWSTR control_default;
86 LPWSTR control_cancel;
87 WCHAR name[1];
90 typedef UINT (*msi_dialog_control_func)( msi_dialog *dialog, MSIRECORD *rec );
91 struct control_handler
93 LPCWSTR control_type;
94 msi_dialog_control_func func;
97 typedef struct
99 msi_dialog* dialog;
100 msi_control *parent;
101 DWORD attributes;
102 } radio_button_group_descr;
104 const WCHAR szMsiDialogClass[] = {
105 'M','s','i','D','i','a','l','o','g','C','l','o','s','e','C','l','a','s','s',0
107 const WCHAR szMsiHiddenWindow[] = {
108 'M','s','i','H','i','d','d','e','n','W','i','n','d','o','w',0 };
109 static const WCHAR szStatic[] = { 'S','t','a','t','i','c',0 };
110 static const WCHAR szButton[] = { 'B','U','T','T','O','N', 0 };
111 static const WCHAR szButtonData[] = { 'M','S','I','D','A','T','A',0 };
112 static const WCHAR szText[] = { 'T','e','x','t',0 };
113 static const WCHAR szPushButton[] = { 'P','u','s','h','B','u','t','t','o','n',0 };
114 static const WCHAR szLine[] = { 'L','i','n','e',0 };
115 static const WCHAR szBitmap[] = { 'B','i','t','m','a','p',0 };
116 static const WCHAR szCheckBox[] = { 'C','h','e','c','k','B','o','x',0 };
117 static const WCHAR szScrollableText[] = {
118 'S','c','r','o','l','l','a','b','l','e','T','e','x','t',0 };
119 static const WCHAR szComboBox[] = { 'C','o','m','b','o','B','o','x',0 };
120 static const WCHAR szEdit[] = { 'E','d','i','t',0 };
121 static const WCHAR szMaskedEdit[] = { 'M','a','s','k','e','d','E','d','i','t',0 };
122 static const WCHAR szPathEdit[] = { 'P','a','t','h','E','d','i','t',0 };
123 static const WCHAR szProgressBar[] = {
124 'P','r','o','g','r','e','s','s','B','a','r',0 };
125 static const WCHAR szRadioButtonGroup[] = {
126 'R','a','d','i','o','B','u','t','t','o','n','G','r','o','u','p',0 };
127 static const WCHAR szIcon[] = { 'I','c','o','n',0 };
128 static const WCHAR szSelectionTree[] = {
129 'S','e','l','e','c','t','i','o','n','T','r','e','e',0 };
131 static UINT msi_dialog_checkbox_handler( msi_dialog *, msi_control *, WPARAM );
132 static void msi_dialog_checkbox_sync_state( msi_dialog *, msi_control * );
133 static UINT msi_dialog_button_handler( msi_dialog *, msi_control *, WPARAM );
134 static UINT msi_dialog_edit_handler( msi_dialog *, msi_control *, WPARAM );
135 static UINT msi_dialog_radiogroup_handler( msi_dialog *, msi_control *, WPARAM param );
136 static UINT msi_dialog_evaluate_control_conditions( msi_dialog *dialog );
137 static LRESULT WINAPI MSIRadioGroup_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
140 /* dialog sequencing */
142 #define WM_MSI_DIALOG_CREATE (WM_USER+0x100)
143 #define WM_MSI_DIALOG_DESTROY (WM_USER+0x101)
145 static DWORD uiThreadId;
146 static HWND hMsiHiddenWindow;
148 static INT msi_dialog_scale_unit( msi_dialog *dialog, INT val )
150 return (dialog->scale * val + 5) / 10;
153 static msi_control *msi_dialog_find_control( msi_dialog *dialog, LPCWSTR name )
155 msi_control *control;
157 if( !name )
158 return NULL;
159 LIST_FOR_EACH_ENTRY( control, &dialog->controls, msi_control, entry )
160 if( !strcmpW( control->name, name ) ) /* FIXME: case sensitive? */
161 return control;
162 return NULL;
165 static msi_control *msi_dialog_find_control_by_hwnd( msi_dialog *dialog, HWND hwnd )
167 msi_control *control;
169 LIST_FOR_EACH_ENTRY( control, &dialog->controls, msi_control, entry )
170 if( hwnd == control->hwnd )
171 return control;
172 return NULL;
175 static LPWSTR msi_get_deformatted_field( MSIPACKAGE *package, MSIRECORD *rec, int field )
177 LPCWSTR str = MSI_RecordGetString( rec, field );
178 LPWSTR ret = NULL;
180 if (str)
181 deformat_string( package, str, &ret );
182 return ret;
186 * msi_dialog_get_style
188 * Extract the {\style} string from the front of the text to display and
189 * update the pointer.
191 static LPWSTR msi_dialog_get_style( LPCWSTR p, LPCWSTR *rest )
193 LPWSTR ret = NULL;
194 LPCWSTR q, i;
195 DWORD len;
197 *rest = p;
198 if( !p )
199 return ret;
200 if( *p++ != '{' )
201 return ret;
202 q = strchrW( p, '}' );
203 if( !q )
204 return ret;
205 if( *p == '\\' || *p == '&' )
206 p++;
208 /* little bit of sanity checking to stop us getting confused with RTF */
209 for( i=p; i<q; i++ )
210 if( *i == '}' || *i == '\\' )
211 return ret;
213 *rest = ++q;
214 len = q - p;
216 ret = msi_alloc( len*sizeof(WCHAR) );
217 if( !ret )
218 return ret;
219 memcpy( ret, p, len*sizeof(WCHAR) );
220 ret[len-1] = 0;
221 return ret;
224 static UINT msi_dialog_add_font( MSIRECORD *rec, LPVOID param )
226 msi_dialog *dialog = param;
227 msi_font *font;
228 LPCWSTR face, name;
229 LOGFONTW lf;
230 INT style;
231 HDC hdc;
233 /* create a font and add it to the list */
234 name = MSI_RecordGetString( rec, 1 );
235 font = msi_alloc( sizeof *font + strlenW( name )*sizeof (WCHAR) );
236 strcpyW( font->name, name );
237 font->next = dialog->font_list;
238 dialog->font_list = font;
240 memset( &lf, 0, sizeof lf );
241 face = MSI_RecordGetString( rec, 2 );
242 lf.lfHeight = MSI_RecordGetInteger( rec, 3 );
243 style = MSI_RecordGetInteger( rec, 5 );
244 if( style & msidbTextStyleStyleBitsBold )
245 lf.lfWeight = FW_BOLD;
246 if( style & msidbTextStyleStyleBitsItalic )
247 lf.lfItalic = TRUE;
248 if( style & msidbTextStyleStyleBitsUnderline )
249 lf.lfUnderline = TRUE;
250 if( style & msidbTextStyleStyleBitsStrike )
251 lf.lfStrikeOut = TRUE;
252 lstrcpynW( lf.lfFaceName, face, LF_FACESIZE );
254 /* adjust the height */
255 hdc = GetDC( dialog->hwnd );
256 if (hdc)
258 lf.lfHeight = -MulDiv(lf.lfHeight, GetDeviceCaps(hdc, LOGPIXELSY), 72);
259 ReleaseDC( dialog->hwnd, hdc );
262 font->hfont = CreateFontIndirectW( &lf );
264 TRACE("Adding font style %s\n", debugstr_w(font->name) );
266 return ERROR_SUCCESS;
269 static msi_font *msi_dialog_find_font( msi_dialog *dialog, LPCWSTR name )
271 msi_font *font;
273 for( font = dialog->font_list; font; font = font->next )
274 if( !strcmpW( font->name, name ) ) /* FIXME: case sensitive? */
275 break;
277 return font;
280 static UINT msi_dialog_set_font( msi_dialog *dialog, HWND hwnd, LPCWSTR name )
282 msi_font *font;
284 font = msi_dialog_find_font( dialog, name );
285 if( font )
286 SendMessageW( hwnd, WM_SETFONT, (WPARAM) font->hfont, TRUE );
287 else
288 ERR("No font entry for %s\n", debugstr_w(name));
289 return ERROR_SUCCESS;
292 static UINT msi_dialog_build_font_list( msi_dialog *dialog )
294 static const WCHAR query[] = {
295 'S','E','L','E','C','T',' ','*',' ',
296 'F','R','O','M',' ','`','T','e','x','t','S','t','y','l','e','`',' ',0
298 UINT r;
299 MSIQUERY *view = NULL;
301 TRACE("dialog %p\n", dialog );
303 r = MSI_OpenQuery( dialog->package->db, &view, query );
304 if( r != ERROR_SUCCESS )
305 return r;
307 r = MSI_IterateRecords( view, NULL, msi_dialog_add_font, dialog );
308 msiobj_release( &view->hdr );
310 return r;
313 static msi_control *msi_dialog_create_window( msi_dialog *dialog,
314 MSIRECORD *rec, LPCWSTR szCls, LPCWSTR name, LPCWSTR text,
315 DWORD style, HWND parent )
317 DWORD x, y, width, height;
318 LPWSTR font = NULL, title_font = NULL;
319 LPCWSTR title = NULL;
320 msi_control *control;
322 style |= WS_CHILD;
324 control = msi_alloc( sizeof *control + strlenW(name)*sizeof(WCHAR) );
325 strcpyW( control->name, name );
326 list_add_head( &dialog->controls, &control->entry );
327 control->handler = NULL;
328 control->property = NULL;
329 control->value = NULL;
330 control->hBitmap = NULL;
331 control->hIcon = NULL;
332 control->hDll = NULL;
333 control->tabnext = strdupW( MSI_RecordGetString( rec, 11) );
335 x = MSI_RecordGetInteger( rec, 4 );
336 y = MSI_RecordGetInteger( rec, 5 );
337 width = MSI_RecordGetInteger( rec, 6 );
338 height = MSI_RecordGetInteger( rec, 7 );
340 x = msi_dialog_scale_unit( dialog, x );
341 y = msi_dialog_scale_unit( dialog, y );
342 width = msi_dialog_scale_unit( dialog, width );
343 height = msi_dialog_scale_unit( dialog, height );
345 if( text )
347 deformat_string( dialog->package, text, &title_font );
348 font = msi_dialog_get_style( title_font, &title );
351 control->hwnd = CreateWindowW( szCls, title, style,
352 x, y, width, height, parent, NULL, NULL, NULL );
354 TRACE("Dialog %s control %s hwnd %p\n",
355 debugstr_w(dialog->name), debugstr_w(text), control->hwnd );
357 msi_dialog_set_font( dialog, control->hwnd,
358 font ? font : dialog->default_font );
360 msi_free( title_font );
361 msi_free( font );
363 return control;
366 static MSIRECORD *msi_get_binary_record( MSIDATABASE *db, LPCWSTR name )
368 static const WCHAR query[] = {
369 's','e','l','e','c','t',' ','*',' ',
370 'f','r','o','m',' ','B','i','n','a','r','y',' ',
371 'w','h','e','r','e',' ',
372 '`','N','a','m','e','`',' ','=',' ','\'','%','s','\'',0
375 return MSI_QueryGetRecord( db, query, name );
378 static LPWSTR msi_create_tmp_path(void)
380 WCHAR tmp[MAX_PATH];
381 LPWSTR path = NULL;
382 static const WCHAR prefix[] = { 'm','s','i',0 };
383 DWORD len, r;
385 r = GetTempPathW( MAX_PATH, tmp );
386 if( !r )
387 return path;
388 len = lstrlenW( tmp ) + 20;
389 path = msi_alloc( len * sizeof (WCHAR) );
390 if( path )
392 r = GetTempFileNameW( tmp, prefix, 0, path );
393 if (!r)
395 msi_free( path );
396 path = NULL;
399 return path;
403 static HANDLE msi_load_image( MSIDATABASE *db, LPCWSTR name, UINT type,
404 UINT cx, UINT cy, UINT flags )
406 MSIRECORD *rec = NULL;
407 HANDLE himage = NULL;
408 LPWSTR tmp;
409 UINT r;
411 TRACE("%p %s %u %u %08x\n", db, debugstr_w(name), cx, cy, flags);
413 tmp = msi_create_tmp_path();
414 if( !tmp )
415 return himage;
417 rec = msi_get_binary_record( db, name );
418 if( rec )
420 r = MSI_RecordStreamToFile( rec, 2, tmp );
421 if( r == ERROR_SUCCESS )
423 himage = LoadImageW( 0, tmp, type, cx, cy, flags );
424 DeleteFileW( tmp );
426 msiobj_release( &rec->hdr );
429 msi_free( tmp );
430 return himage;
433 static HICON msi_load_icon( MSIDATABASE *db, LPCWSTR text, UINT attributes )
435 DWORD cx = 0, cy = 0, flags;
437 flags = LR_LOADFROMFILE | LR_DEFAULTSIZE;
438 if( attributes & msidbControlAttributesFixedSize )
440 flags &= ~LR_DEFAULTSIZE;
441 if( attributes & msidbControlAttributesIconSize16 )
443 cx += 16;
444 cy += 16;
446 if( attributes & msidbControlAttributesIconSize32 )
448 cx += 32;
449 cy += 32;
451 /* msidbControlAttributesIconSize48 handled by above logic */
453 return msi_load_image( db, text, IMAGE_ICON, cx, cy, flags );
457 /* called from the Control Event subscription code */
458 void msi_dialog_handle_event( msi_dialog* dialog, LPCWSTR control,
459 LPCWSTR attribute, MSIRECORD *rec )
461 msi_control* ctrl;
462 LPCWSTR text;
464 ctrl = msi_dialog_find_control( dialog, control );
465 if (!ctrl)
466 return;
467 if( lstrcmpW(attribute, szText) )
469 ERR("Attribute %s\n", debugstr_w(attribute));
470 return;
472 text = MSI_RecordGetString( rec , 1 );
473 SetWindowTextW( ctrl->hwnd, text );
474 msi_dialog_check_messages( NULL );
477 static void msi_dialog_map_events(msi_dialog* dialog, LPCWSTR control)
479 static WCHAR Query[] = {
480 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
481 '`','E','v','e','n','t','M','a','p','p','i','n','g','`',' ',
482 'W','H','E','R','E',' ',
483 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',' ',
484 'A','N','D',' ',
485 '`','C','o','n','t','r','o','l','_','`',' ','=',' ','\'','%','s','\'',0
487 MSIRECORD *row;
488 LPCWSTR event, attribute;
490 row = MSI_QueryGetRecord( dialog->package->db, Query, dialog->name, control );
491 if (!row)
492 return;
494 event = MSI_RecordGetString( row, 3 );
495 attribute = MSI_RecordGetString( row, 4 );
496 ControlEvent_SubscribeToEvent( dialog->package, event, control, attribute );
497 msiobj_release( &row->hdr );
500 /* everything except radio buttons */
501 static msi_control *msi_dialog_add_control( msi_dialog *dialog,
502 MSIRECORD *rec, LPCWSTR szCls, DWORD style )
504 DWORD attributes;
505 LPCWSTR text, name;
507 name = MSI_RecordGetString( rec, 2 );
508 attributes = MSI_RecordGetInteger( rec, 8 );
509 text = MSI_RecordGetString( rec, 10 );
510 if( attributes & msidbControlAttributesVisible )
511 style |= WS_VISIBLE;
512 if( ~attributes & msidbControlAttributesEnabled )
513 style |= WS_DISABLED;
515 msi_dialog_map_events(dialog, name);
517 return msi_dialog_create_window( dialog, rec, szCls, name, text,
518 style, dialog->hwnd );
521 struct msi_text_info
523 WNDPROC oldproc;
524 DWORD attributes;
528 * we don't erase our own background,
529 * so we have to make sure that the parent window redraws first
531 static void msi_text_on_settext( HWND hWnd )
533 HWND hParent;
534 RECT rc;
536 hParent = GetParent( hWnd );
537 GetWindowRect( hWnd, &rc );
538 MapWindowPoints( NULL, hParent, (LPPOINT) &rc, 2 );
539 InvalidateRect( hParent, &rc, TRUE );
542 static LRESULT WINAPI
543 MSIText_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
545 struct msi_text_info *info;
546 LRESULT r = 0;
548 TRACE("%p %04x %08x %08lx\n", hWnd, msg, wParam, lParam);
550 info = GetPropW(hWnd, szButtonData);
552 if( msg == WM_CTLCOLORSTATIC &&
553 ( info->attributes & msidbControlAttributesTransparent ) )
555 SetBkMode( (HDC)wParam, TRANSPARENT );
556 return (LRESULT) GetStockObject(NULL_BRUSH);
559 r = CallWindowProcW(info->oldproc, hWnd, msg, wParam, lParam);
561 switch( msg )
563 case WM_SETTEXT:
564 msi_text_on_settext( hWnd );
565 break;
566 case WM_NCDESTROY:
567 msi_free( info );
568 RemovePropW( hWnd, szButtonData );
569 break;
572 return r;
575 static UINT msi_dialog_text_control( msi_dialog *dialog, MSIRECORD *rec )
577 msi_control *control;
578 struct msi_text_info *info;
580 TRACE("%p %p\n", dialog, rec);
582 control = msi_dialog_add_control( dialog, rec, szStatic, SS_LEFT | WS_GROUP );
583 if( !control )
584 return ERROR_FUNCTION_FAILED;
586 info = msi_alloc( sizeof *info );
587 if( !info )
588 return ERROR_SUCCESS;
590 info->attributes = MSI_RecordGetInteger( rec, 8 );
591 if( info->attributes & msidbControlAttributesTransparent )
592 SetWindowLongPtrW( control->hwnd, GWL_EXSTYLE, WS_EX_TRANSPARENT );
594 info->oldproc = (WNDPROC) SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
595 (LONG_PTR)MSIText_WndProc );
596 SetPropW( control->hwnd, szButtonData, info );
598 return ERROR_SUCCESS;
601 static UINT msi_dialog_button_control( msi_dialog *dialog, MSIRECORD *rec )
603 msi_control *control;
604 UINT attributes, style;
605 LPWSTR text;
607 TRACE("%p %p\n", dialog, rec);
609 style = WS_TABSTOP;
610 attributes = MSI_RecordGetInteger( rec, 8 );
611 if( attributes & msidbControlAttributesIcon )
612 style |= BS_ICON;
614 control = msi_dialog_add_control( dialog, rec, szButton, style );
615 if( !control )
616 return ERROR_FUNCTION_FAILED;
618 control->handler = msi_dialog_button_handler;
620 /* set the icon */
621 text = msi_get_deformatted_field( dialog->package, rec, 10 );
622 control->hIcon = msi_load_icon( dialog->package->db, text, attributes );
623 if( attributes & msidbControlAttributesIcon )
624 SendMessageW( control->hwnd, BM_SETIMAGE, IMAGE_ICON, (LPARAM) control->hIcon );
625 msi_free( text );
627 return ERROR_SUCCESS;
630 static LPWSTR msi_get_checkbox_value( msi_dialog *dialog, LPCWSTR prop )
632 static const WCHAR query[] = {
633 'S','E','L','E','C','T',' ','*',' ',
634 'F','R','O','M',' ','`','C','h','e','c','k','B','o','x',' ','`',
635 'W','H','E','R','E',' ',
636 '`','P','r','o','p','e','r','t','y','`',' ','=',' ',
637 '\'','%','s','\'',0
639 MSIRECORD *rec = NULL;
640 LPWSTR ret = NULL;
642 /* find if there is a value associated with the checkbox */
643 rec = MSI_QueryGetRecord( dialog->package->db, query, prop );
644 if (!rec)
645 return ret;
647 ret = msi_get_deformatted_field( dialog->package, rec, 2 );
648 if( ret && !ret[0] )
650 msi_free( ret );
651 ret = NULL;
653 msiobj_release( &rec->hdr );
654 if (ret)
655 return ret;
657 ret = msi_dup_property( dialog->package, prop );
658 if( ret && !ret[0] )
660 msi_free( ret );
661 ret = NULL;
664 return ret;
667 static UINT msi_dialog_checkbox_control( msi_dialog *dialog, MSIRECORD *rec )
669 msi_control *control;
670 LPCWSTR prop;
672 TRACE("%p %p\n", dialog, rec);
674 control = msi_dialog_add_control( dialog, rec, szButton,
675 BS_CHECKBOX | BS_MULTILINE | WS_TABSTOP );
676 control->handler = msi_dialog_checkbox_handler;
677 prop = MSI_RecordGetString( rec, 9 );
678 if( prop )
680 control->property = strdupW( prop );
681 control->value = msi_get_checkbox_value( dialog, prop );
682 TRACE("control %s value %s\n", debugstr_w(control->property),
683 debugstr_w(control->value));
685 msi_dialog_checkbox_sync_state( dialog, control );
687 return ERROR_SUCCESS;
690 static UINT msi_dialog_line_control( msi_dialog *dialog, MSIRECORD *rec )
692 TRACE("%p %p\n", dialog, rec);
694 msi_dialog_add_control( dialog, rec, szStatic, SS_ETCHEDHORZ | SS_SUNKEN );
695 return ERROR_SUCCESS;
698 /******************** Scroll Text ********************************************/
700 struct msi_scrolltext_info
702 msi_dialog *dialog;
703 msi_control *control;
704 WNDPROC oldproc;
707 static LRESULT WINAPI
708 MSIScrollText_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
710 struct msi_scrolltext_info *info;
711 HRESULT r;
713 TRACE("%p %04x %08x %08lx\n", hWnd, msg, wParam, lParam);
715 info = GetPropW( hWnd, szButtonData );
717 r = CallWindowProcW( info->oldproc, hWnd, msg, wParam, lParam );
719 switch( msg )
721 case WM_NCDESTROY:
722 msi_free( info );
723 RemovePropW( hWnd, szButtonData );
724 break;
725 case WM_PAINT:
726 /* native MSI sets a wait cursor here */
727 msi_dialog_button_handler( info->dialog, info->control, BN_CLICKED );
728 break;
730 return r;
733 struct msi_streamin_info
735 LPSTR string;
736 DWORD offset;
737 DWORD length;
740 static DWORD CALLBACK
741 msi_richedit_stream_in( DWORD_PTR arg, LPBYTE buffer, LONG count, LONG *pcb )
743 struct msi_streamin_info *info = (struct msi_streamin_info*) arg;
745 if( (count + info->offset) > info->length )
746 count = info->length - info->offset;
747 memcpy( buffer, &info->string[ info->offset ], count );
748 *pcb = count;
749 info->offset += count;
751 TRACE("%ld/%ld\n", info->offset, info->length);
753 return 0;
756 static void msi_scrolltext_add_text( msi_control *control, LPCWSTR text )
758 struct msi_streamin_info info;
759 EDITSTREAM es;
761 info.string = strdupWtoA( text );
762 info.offset = 0;
763 info.length = lstrlenA( info.string ) + 1;
765 es.dwCookie = (DWORD_PTR) &info;
766 es.dwError = 0;
767 es.pfnCallback = msi_richedit_stream_in;
769 SendMessageW( control->hwnd, EM_STREAMIN, SF_RTF, (LPARAM) &es );
771 msi_free( info.string );
774 static UINT msi_dialog_scrolltext_control( msi_dialog *dialog, MSIRECORD *rec )
776 static const WCHAR szRichEdit20W[] = {
777 'R','i','c','h','E','d','i','t','2','0','W',0
779 struct msi_scrolltext_info *info;
780 msi_control *control;
781 HMODULE hRichedit;
782 DWORD style;
784 info = msi_alloc( sizeof *info );
785 if (!info)
786 return ERROR_FUNCTION_FAILED;
788 hRichedit = LoadLibraryA("riched20");
790 style = WS_BORDER | ES_MULTILINE | WS_VSCROLL |
791 ES_READONLY | ES_AUTOVSCROLL | WS_TABSTOP;
792 control = msi_dialog_add_control( dialog, rec, szRichEdit20W, style );
793 if (!control)
795 FreeLibrary( hRichedit );
796 msi_free( info );
797 return ERROR_FUNCTION_FAILED;
800 control->hDll = hRichedit;
802 info->dialog = dialog;
803 info->control = control;
805 /* subclass the static control */
806 info->oldproc = (WNDPROC) SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
807 (LONG_PTR)MSIScrollText_WndProc );
808 SetPropW( control->hwnd, szButtonData, info );
810 /* add the text into the richedit */
811 msi_scrolltext_add_text( control, MSI_RecordGetString( rec, 10 ) );
813 return ERROR_SUCCESS;
816 static HBITMAP msi_load_picture( MSIDATABASE *db, LPCWSTR name,
817 INT cx, INT cy, DWORD flags )
819 HBITMAP hOleBitmap = 0, hBitmap = 0, hOldSrcBitmap, hOldDestBitmap;
820 MSIRECORD *rec = NULL;
821 IStream *stm = NULL;
822 IPicture *pic = NULL;
823 HDC srcdc, destdc;
824 BITMAP bm;
825 UINT r;
827 rec = msi_get_binary_record( db, name );
828 if( !rec )
829 goto end;
831 r = MSI_RecordGetIStream( rec, 2, &stm );
832 msiobj_release( &rec->hdr );
833 if( r != ERROR_SUCCESS )
834 goto end;
836 r = OleLoadPicture( stm, 0, TRUE, &IID_IPicture, (LPVOID*) &pic );
837 IStream_Release( stm );
838 if( FAILED( r ) )
840 ERR("failed to load picture\n");
841 goto end;
844 r = IPicture_get_Handle( pic, (OLE_HANDLE*) &hOleBitmap );
845 if( FAILED( r ) )
847 ERR("failed to get bitmap handle\n");
848 goto end;
851 /* make the bitmap the desired size */
852 r = GetObjectW( hOleBitmap, sizeof bm, &bm );
853 if (r != sizeof bm )
855 ERR("failed to get bitmap size\n");
856 goto end;
859 if (flags & LR_DEFAULTSIZE)
861 cx = bm.bmWidth;
862 cy = bm.bmHeight;
865 srcdc = CreateCompatibleDC( NULL );
866 hOldSrcBitmap = SelectObject( srcdc, hOleBitmap );
867 destdc = CreateCompatibleDC( NULL );
868 hBitmap = CreateCompatibleBitmap( srcdc, cx, cy );
869 hOldDestBitmap = SelectObject( destdc, hBitmap );
870 StretchBlt( destdc, 0, 0, cx, cy,
871 srcdc, 0, 0, bm.bmWidth, bm.bmHeight, SRCCOPY);
872 SelectObject( srcdc, hOldSrcBitmap );
873 SelectObject( destdc, hOldDestBitmap );
874 DeleteDC( srcdc );
875 DeleteDC( destdc );
877 end:
878 if ( pic )
879 IPicture_Release( pic );
880 return hBitmap;
883 static UINT msi_dialog_bitmap_control( msi_dialog *dialog, MSIRECORD *rec )
885 UINT cx, cy, flags, style, attributes;
886 msi_control *control;
887 LPWSTR text;
889 flags = LR_LOADFROMFILE;
890 style = SS_BITMAP | SS_LEFT | WS_GROUP;
892 attributes = MSI_RecordGetInteger( rec, 8 );
893 if( attributes & msidbControlAttributesFixedSize )
895 flags |= LR_DEFAULTSIZE;
896 style |= SS_CENTERIMAGE;
899 control = msi_dialog_add_control( dialog, rec, szStatic, style );
900 cx = MSI_RecordGetInteger( rec, 6 );
901 cy = MSI_RecordGetInteger( rec, 7 );
902 cx = msi_dialog_scale_unit( dialog, cx );
903 cy = msi_dialog_scale_unit( dialog, cy );
905 text = msi_get_deformatted_field( dialog->package, rec, 10 );
906 control->hBitmap = msi_load_picture( dialog->package->db, text, cx, cy, flags );
907 if( control->hBitmap )
908 SendMessageW( control->hwnd, STM_SETIMAGE,
909 IMAGE_BITMAP, (LPARAM) control->hBitmap );
910 else
911 ERR("Failed to load bitmap %s\n", debugstr_w(text));
913 msi_free( text );
915 return ERROR_SUCCESS;
918 static UINT msi_dialog_icon_control( msi_dialog *dialog, MSIRECORD *rec )
920 msi_control *control;
921 DWORD attributes;
922 LPWSTR text;
924 TRACE("\n");
926 control = msi_dialog_add_control( dialog, rec, szStatic,
927 SS_ICON | SS_CENTERIMAGE | WS_GROUP );
929 attributes = MSI_RecordGetInteger( rec, 8 );
930 text = msi_get_deformatted_field( dialog->package, rec, 10 );
931 control->hIcon = msi_load_icon( dialog->package->db, text, attributes );
932 if( control->hIcon )
933 SendMessageW( control->hwnd, STM_SETICON, (WPARAM) control->hIcon, 0 );
934 else
935 ERR("Failed to load bitmap %s\n", debugstr_w(text));
936 msi_free( text );
937 return ERROR_SUCCESS;
940 static UINT msi_dialog_combo_control( msi_dialog *dialog, MSIRECORD *rec )
942 static const WCHAR szCombo[] = { 'C','O','M','B','O','B','O','X',0 };
944 msi_dialog_add_control( dialog, rec, szCombo,
945 SS_BITMAP | SS_LEFT | SS_CENTERIMAGE );
946 return ERROR_SUCCESS;
949 static UINT msi_dialog_edit_control( msi_dialog *dialog, MSIRECORD *rec )
951 msi_control *control;
952 LPCWSTR prop;
953 LPWSTR val;
955 control = msi_dialog_add_control( dialog, rec, szEdit,
956 WS_BORDER | WS_TABSTOP );
957 control->handler = msi_dialog_edit_handler;
958 prop = MSI_RecordGetString( rec, 9 );
959 if( prop )
960 control->property = strdupW( prop );
961 val = msi_dup_property( dialog->package, control->property );
962 SetWindowTextW( control->hwnd, val );
963 msi_free( val );
964 return ERROR_SUCCESS;
967 /******************** Masked Edit ********************************************/
969 #define MASK_MAX_GROUPS 10
971 struct msi_mask_group
973 UINT len;
974 UINT ofs;
975 WCHAR type;
976 HWND hwnd;
979 struct msi_maskedit_info
981 msi_dialog *dialog;
982 WNDPROC oldproc;
983 HWND hwnd;
984 LPWSTR prop;
985 UINT num_chars;
986 UINT num_groups;
987 struct msi_mask_group group[MASK_MAX_GROUPS];
990 static BOOL msi_mask_editable( WCHAR type )
992 switch (type)
994 case '%':
995 case '#':
996 case '&':
997 case '`':
998 case '?':
999 case '^':
1000 return TRUE;
1002 return FALSE;
1005 static void msi_mask_control_change( struct msi_maskedit_info *info )
1007 LPWSTR val;
1008 UINT i, n, r;
1010 val = msi_alloc( (info->num_chars+1)*sizeof(WCHAR) );
1011 for( i=0, n=0; i<info->num_groups; i++ )
1013 if( (info->group[i].len + n) > info->num_chars )
1015 ERR("can't fit control %d text into template\n",i);
1016 break;
1018 if (!msi_mask_editable(info->group[i].type))
1020 for(r=0; r<info->group[i].len; r++)
1021 val[n+r] = info->group[i].type;
1022 val[n+r] = 0;
1024 else
1026 r = GetWindowTextW( info->group[i].hwnd, &val[n], info->group[i].len+1 );
1027 if( r != info->group[i].len )
1028 break;
1030 n += r;
1033 TRACE("%d/%d controls were good\n", i, info->num_groups);
1035 if( i == info->num_groups )
1037 TRACE("Set property %s to %s\n",
1038 debugstr_w(info->prop), debugstr_w(val) );
1039 CharUpperBuffW( val, info->num_chars );
1040 MSI_SetPropertyW( info->dialog->package, info->prop, val );
1041 msi_dialog_evaluate_control_conditions( info->dialog );
1043 msi_free( val );
1046 /* now move to the next control if necessary */
1047 static VOID msi_mask_next_control( struct msi_maskedit_info *info, HWND hWnd )
1049 HWND hWndNext;
1050 UINT len, i;
1052 for( i=0; i<info->num_groups; i++ )
1053 if( info->group[i].hwnd == hWnd )
1054 break;
1056 /* don't move from the last control */
1057 if( i >= (info->num_groups-1) )
1058 return;
1060 len = SendMessageW( hWnd, WM_GETTEXTLENGTH, 0, 0 );
1061 if( len < info->group[i].len )
1062 return;
1064 hWndNext = GetNextDlgTabItem( GetParent( hWnd ), hWnd, FALSE );
1065 SetFocus( hWndNext );
1068 static LRESULT WINAPI
1069 MSIMaskedEdit_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
1071 struct msi_maskedit_info *info;
1072 HRESULT r;
1074 TRACE("%p %04x %08x %08lx\n", hWnd, msg, wParam, lParam);
1076 info = GetPropW(hWnd, szButtonData);
1078 r = CallWindowProcW(info->oldproc, hWnd, msg, wParam, lParam);
1080 switch( msg )
1082 case WM_COMMAND:
1083 if (HIWORD(wParam) == EN_CHANGE)
1085 msi_mask_control_change( info );
1086 msi_mask_next_control( info, (HWND) lParam );
1088 break;
1089 case WM_NCDESTROY:
1090 msi_free( info->prop );
1091 msi_free( info );
1092 RemovePropW( hWnd, szButtonData );
1093 break;
1096 return r;
1099 /* fish the various bits of the property out and put them in the control */
1100 static void
1101 msi_maskedit_set_text( struct msi_maskedit_info *info, LPCWSTR text )
1103 LPCWSTR p;
1104 UINT i;
1106 p = text;
1107 for( i = 0; i < info->num_groups; i++ )
1109 if( info->group[i].len < lstrlenW( p ) )
1111 LPWSTR chunk = strdupW( p );
1112 chunk[ info->group[i].len ] = 0;
1113 SetWindowTextW( info->group[i].hwnd, chunk );
1114 msi_free( chunk );
1116 else
1118 SetWindowTextW( info->group[i].hwnd, p );
1119 break;
1121 p += info->group[i].len;
1125 static struct msi_maskedit_info * msi_dialog_parse_groups( LPCWSTR mask )
1127 struct msi_maskedit_info * info = NULL;
1128 int i = 0, n = 0, total = 0;
1129 LPCWSTR p;
1131 TRACE("masked control, template %s\n", debugstr_w(mask));
1133 if( !mask )
1134 return info;
1136 info = msi_alloc_zero( sizeof *info );
1137 if( !info )
1138 return info;
1140 p = strchrW(mask, '<');
1141 if( p )
1142 p++;
1143 else
1144 p = mask;
1146 for( i=0; i<MASK_MAX_GROUPS; i++ )
1148 /* stop at the end of the string */
1149 if( p[0] == 0 || p[0] == '>' )
1150 break;
1152 /* count the number of the same identifier */
1153 for( n=0; p[n] == p[0]; n++ )
1155 info->group[i].ofs = total;
1156 info->group[i].type = p[0];
1157 if( p[n] == '=' )
1159 n++;
1160 total++; /* an extra not part of the group */
1162 info->group[i].len = n;
1163 total += n;
1164 p += n;
1167 TRACE("%d characters in %d groups\n", total, i );
1168 if( i == MASK_MAX_GROUPS )
1169 ERR("too many groups in PIDTemplate %s\n", debugstr_w(mask));
1171 info->num_chars = total;
1172 info->num_groups = i;
1174 return info;
1177 static void
1178 msi_maskedit_create_children( struct msi_maskedit_info *info, LPCWSTR font )
1180 DWORD width, height, style, wx, ww;
1181 RECT rect;
1182 HWND hwnd;
1183 UINT i;
1185 style = WS_CHILD | WS_BORDER | WS_VISIBLE | WS_TABSTOP | ES_AUTOHSCROLL;
1187 GetClientRect( info->hwnd, &rect );
1189 width = rect.right - rect.left;
1190 height = rect.bottom - rect.top;
1192 for( i = 0; i < info->num_groups; i++ )
1194 if (!msi_mask_editable( info->group[i].type ))
1195 continue;
1196 wx = (info->group[i].ofs * width) / info->num_chars;
1197 ww = (info->group[i].len * width) / info->num_chars;
1199 hwnd = CreateWindowW( szEdit, NULL, style, wx, 0, ww, height,
1200 info->hwnd, NULL, NULL, NULL );
1201 if( !hwnd )
1203 ERR("failed to create mask edit sub window\n");
1204 break;
1207 SendMessageW( hwnd, EM_LIMITTEXT, info->group[i].len, 0 );
1209 msi_dialog_set_font( info->dialog, hwnd,
1210 font?font:info->dialog->default_font );
1211 info->group[i].hwnd = hwnd;
1216 * office 2003 uses "73931<````=````=````=````=`````>@@@@@"
1217 * delphi 7 uses "<????-??????-??????-????>" and "<???-???>"
1218 * filemaker pro 7 uses "<^^^^=^^^^=^^^^=^^^^=^^^^=^^^^=^^^^^>"
1220 static UINT msi_dialog_maskedit_control( msi_dialog *dialog, MSIRECORD *rec )
1222 LPWSTR font_mask, val = NULL, font;
1223 struct msi_maskedit_info *info = NULL;
1224 UINT ret = ERROR_SUCCESS;
1225 msi_control *control;
1226 LPCWSTR prop, mask;
1228 TRACE("\n");
1230 font_mask = msi_get_deformatted_field( dialog->package, rec, 10 );
1231 font = msi_dialog_get_style( font_mask, &mask );
1232 if( !mask )
1234 ERR("mask template is empty\n");
1235 goto end;
1238 info = msi_dialog_parse_groups( mask );
1239 if( !info )
1241 ERR("template %s is invalid\n", debugstr_w(mask));
1242 goto end;
1245 info->dialog = dialog;
1247 control = msi_dialog_add_control( dialog, rec, szStatic,
1248 SS_OWNERDRAW | WS_GROUP | WS_VISIBLE );
1249 if( !control )
1251 ERR("Failed to create maskedit container\n");
1252 ret = ERROR_FUNCTION_FAILED;
1253 goto end;
1255 SetWindowLongPtrW( control->hwnd, GWL_EXSTYLE, WS_EX_CONTROLPARENT );
1257 info->hwnd = control->hwnd;
1259 /* subclass the static control */
1260 info->oldproc = (WNDPROC) SetWindowLongPtrW( info->hwnd, GWLP_WNDPROC,
1261 (LONG_PTR)MSIMaskedEdit_WndProc );
1262 SetPropW( control->hwnd, szButtonData, info );
1264 prop = MSI_RecordGetString( rec, 9 );
1265 if( prop )
1266 info->prop = strdupW( prop );
1268 msi_maskedit_create_children( info, font );
1270 if( prop )
1272 val = msi_dup_property( dialog->package, prop );
1273 if( val )
1275 msi_maskedit_set_text( info, val );
1276 msi_free( val );
1280 end:
1281 if( ret != ERROR_SUCCESS )
1282 msi_free( info );
1283 msi_free( font_mask );
1284 msi_free( font );
1285 return ret;
1288 /******************** Progress Bar *****************************************/
1290 static UINT msi_dialog_progress_bar( msi_dialog *dialog, MSIRECORD *rec )
1292 msi_dialog_add_control( dialog, rec, PROGRESS_CLASSW, WS_VISIBLE );
1293 return ERROR_SUCCESS;
1296 /******************** Path Edit ********************************************/
1298 static UINT msi_dialog_pathedit_control( msi_dialog *dialog, MSIRECORD *rec )
1300 FIXME("not implemented properly\n");
1301 return msi_dialog_edit_control( dialog, rec );
1304 /* radio buttons are a bit different from normal controls */
1305 static UINT msi_dialog_create_radiobutton( MSIRECORD *rec, LPVOID param )
1307 radio_button_group_descr *group = (radio_button_group_descr *)param;
1308 msi_dialog *dialog = group->dialog;
1309 msi_control *control;
1310 LPCWSTR prop, text, name;
1311 DWORD style, attributes = group->attributes;
1313 style = WS_CHILD | BS_AUTORADIOBUTTON | BS_MULTILINE | WS_TABSTOP;
1314 name = MSI_RecordGetString( rec, 3 );
1315 text = MSI_RecordGetString( rec, 8 );
1316 if( attributes & 1 )
1317 style |= WS_VISIBLE;
1318 if( ~attributes & 2 )
1319 style |= WS_DISABLED;
1321 control = msi_dialog_create_window( dialog, rec, szButton, name, text,
1322 style, group->parent->hwnd );
1323 if (!control)
1324 return ERROR_FUNCTION_FAILED;
1325 control->handler = msi_dialog_radiogroup_handler;
1327 prop = MSI_RecordGetString( rec, 1 );
1328 if( prop )
1329 control->property = strdupW( prop );
1331 return ERROR_SUCCESS;
1334 static UINT msi_dialog_radiogroup_control( msi_dialog *dialog, MSIRECORD *rec )
1336 static const WCHAR query[] = {
1337 'S','E','L','E','C','T',' ','*',' ',
1338 'F','R','O','M',' ','R','a','d','i','o','B','u','t','t','o','n',' ',
1339 'W','H','E','R','E',' ',
1340 '`','P','r','o','p','e','r','t','y','`',' ','=',' ','\'','%','s','\'',0};
1341 UINT r;
1342 LPCWSTR prop;
1343 msi_control *control;
1344 MSIQUERY *view = NULL;
1345 radio_button_group_descr group;
1346 MSIPACKAGE *package = dialog->package;
1347 WNDPROC oldproc;
1349 prop = MSI_RecordGetString( rec, 9 );
1351 TRACE("%p %p %s\n", dialog, rec, debugstr_w( prop ));
1353 /* Create parent group box to hold radio buttons */
1354 control = msi_dialog_add_control( dialog, rec, szButton, BS_OWNERDRAW|WS_GROUP );
1355 if( !control )
1356 return ERROR_FUNCTION_FAILED;
1358 oldproc = (WNDPROC) SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
1359 (LONG_PTR)MSIRadioGroup_WndProc );
1360 SetPropW(control->hwnd, szButtonData, oldproc);
1361 SetWindowLongPtrW( control->hwnd, GWL_EXSTYLE, WS_EX_CONTROLPARENT );
1363 if( prop )
1364 control->property = strdupW( prop );
1366 /* query the Radio Button table for all control in this group */
1367 r = MSI_OpenQuery( package->db, &view, query, prop );
1368 if( r != ERROR_SUCCESS )
1370 ERR("query failed for dialog %s radio group %s\n",
1371 debugstr_w(dialog->name), debugstr_w(prop));
1372 return ERROR_INVALID_PARAMETER;
1375 group.dialog = dialog;
1376 group.parent = control;
1377 group.attributes = MSI_RecordGetInteger( rec, 8 );
1379 r = MSI_IterateRecords( view, 0, msi_dialog_create_radiobutton, &group );
1380 msiobj_release( &view->hdr );
1382 return r;
1385 /******************** Selection Tree ***************************************/
1387 static void
1388 msi_dialog_tv_add_child_features( MSIPACKAGE *package, HWND hwnd,
1389 LPCWSTR parent, HTREEITEM hParent )
1391 MSIFEATURE *feature;
1392 TVINSERTSTRUCTW tvis;
1393 HTREEITEM hitem;
1395 LIST_FOR_EACH_ENTRY( feature, &package->features, MSIFEATURE, entry )
1397 if ( lstrcmpW( parent, feature->Feature_Parent ) )
1398 continue;
1400 if ( !feature->Title )
1401 continue;
1403 memset( &tvis, 0, sizeof tvis );
1404 tvis.hParent = hParent;
1405 tvis.hInsertAfter = TVI_SORT;
1406 if (feature->Title)
1408 tvis.u.item.mask = TVIF_TEXT;
1409 tvis.u.item.pszText = feature->Title;
1411 tvis.u.item.lParam = (LPARAM) feature;
1412 hitem = (HTREEITEM) SendMessageW( hwnd, TVM_INSERTITEMW, 0, (LPARAM) &tvis );
1413 if (!hitem)
1414 continue;
1416 msi_dialog_tv_add_child_features( package, hwnd,
1417 feature->Feature, hitem );
1421 static UINT msi_dialog_selection_tree( msi_dialog *dialog, MSIRECORD *rec )
1423 msi_control *control;
1424 LPCWSTR prop;
1425 LPWSTR val;
1426 MSIPACKAGE *package = dialog->package;
1428 prop = MSI_RecordGetString( rec, 9 );
1429 val = msi_dup_property( package, prop );
1430 control = msi_dialog_add_control( dialog, rec, WC_TREEVIEWW,
1431 TVS_HASBUTTONS | WS_GROUP | WS_VSCROLL );
1432 if (!control)
1433 return ERROR_FUNCTION_FAILED;
1435 msi_dialog_tv_add_child_features( package, control->hwnd, NULL, NULL );
1437 msi_free( val );
1439 return ERROR_SUCCESS;
1442 struct control_handler msi_dialog_handler[] =
1444 { szText, msi_dialog_text_control },
1445 { szPushButton, msi_dialog_button_control },
1446 { szLine, msi_dialog_line_control },
1447 { szBitmap, msi_dialog_bitmap_control },
1448 { szCheckBox, msi_dialog_checkbox_control },
1449 { szScrollableText, msi_dialog_scrolltext_control },
1450 { szComboBox, msi_dialog_combo_control },
1451 { szEdit, msi_dialog_edit_control },
1452 { szMaskedEdit, msi_dialog_maskedit_control },
1453 { szPathEdit, msi_dialog_pathedit_control },
1454 { szProgressBar, msi_dialog_progress_bar },
1455 { szRadioButtonGroup, msi_dialog_radiogroup_control },
1456 { szIcon, msi_dialog_icon_control },
1457 { szSelectionTree, msi_dialog_selection_tree },
1460 #define NUM_CONTROL_TYPES (sizeof msi_dialog_handler/sizeof msi_dialog_handler[0])
1462 static UINT msi_dialog_create_controls( MSIRECORD *rec, LPVOID param )
1464 msi_dialog *dialog = param;
1465 LPCWSTR control_type;
1466 UINT i;
1468 /* find and call the function that can create this type of control */
1469 control_type = MSI_RecordGetString( rec, 3 );
1470 for( i=0; i<NUM_CONTROL_TYPES; i++ )
1471 if (!strcmpiW( msi_dialog_handler[i].control_type, control_type ))
1472 break;
1473 if( i != NUM_CONTROL_TYPES )
1474 msi_dialog_handler[i].func( dialog, rec );
1475 else
1476 ERR("no handler for element type %s\n", debugstr_w(control_type));
1478 return ERROR_SUCCESS;
1481 static UINT msi_dialog_fill_controls( msi_dialog *dialog )
1483 static const WCHAR query[] = {
1484 'S','E','L','E','C','T',' ','*',' ',
1485 'F','R','O','M',' ','C','o','n','t','r','o','l',' ',
1486 'W','H','E','R','E',' ',
1487 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',0};
1488 UINT r;
1489 MSIQUERY *view = NULL;
1490 MSIPACKAGE *package = dialog->package;
1492 TRACE("%p %s\n", dialog, debugstr_w(dialog->name) );
1494 /* query the Control table for all the elements of the control */
1495 r = MSI_OpenQuery( package->db, &view, query, dialog->name );
1496 if( r != ERROR_SUCCESS )
1498 ERR("query failed for dialog %s\n", debugstr_w(dialog->name));
1499 return ERROR_INVALID_PARAMETER;
1502 r = MSI_IterateRecords( view, 0, msi_dialog_create_controls, dialog );
1503 msiobj_release( &view->hdr );
1505 return r;
1508 static UINT msi_dialog_set_control_condition( MSIRECORD *rec, LPVOID param )
1510 static const WCHAR szHide[] = { 'H','i','d','e',0 };
1511 static const WCHAR szShow[] = { 'S','h','o','w',0 };
1512 static const WCHAR szDisable[] = { 'D','i','s','a','b','l','e',0 };
1513 static const WCHAR szEnable[] = { 'E','n','a','b','l','e',0 };
1514 msi_dialog *dialog = param;
1515 msi_control *control;
1516 LPCWSTR name, action, condition;
1517 UINT r;
1519 name = MSI_RecordGetString( rec, 2 );
1520 action = MSI_RecordGetString( rec, 3 );
1521 condition = MSI_RecordGetString( rec, 4 );
1522 r = MSI_EvaluateConditionW( dialog->package, condition );
1523 control = msi_dialog_find_control( dialog, name );
1524 if( r == MSICONDITION_TRUE && control )
1526 TRACE("%s control %s\n", debugstr_w(action), debugstr_w(name));
1528 /* FIXME: case sensitive? */
1529 if(!lstrcmpW(action, szHide))
1530 ShowWindow(control->hwnd, SW_HIDE);
1531 else if(!strcmpW(action, szShow))
1532 ShowWindow(control->hwnd, SW_SHOW);
1533 else if(!strcmpW(action, szDisable))
1534 EnableWindow(control->hwnd, FALSE);
1535 else if(!strcmpW(action, szEnable))
1536 EnableWindow(control->hwnd, TRUE);
1537 else
1538 FIXME("Unhandled action %s\n", debugstr_w(action));
1541 return ERROR_SUCCESS;
1544 static UINT msi_dialog_evaluate_control_conditions( msi_dialog *dialog )
1546 static const WCHAR query[] = {
1547 'S','E','L','E','C','T',' ','*',' ',
1548 'F','R','O','M',' ',
1549 'C','o','n','t','r','o','l','C','o','n','d','i','t','i','o','n',' ',
1550 'W','H','E','R','E',' ',
1551 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',0
1553 UINT r;
1554 MSIQUERY *view = NULL;
1555 MSIPACKAGE *package = dialog->package;
1557 TRACE("%p %s\n", dialog, debugstr_w(dialog->name) );
1559 /* query the Control table for all the elements of the control */
1560 r = MSI_OpenQuery( package->db, &view, query, dialog->name );
1561 if( r != ERROR_SUCCESS )
1563 ERR("query failed for dialog %s\n", debugstr_w(dialog->name));
1564 return ERROR_INVALID_PARAMETER;
1567 r = MSI_IterateRecords( view, 0, msi_dialog_set_control_condition, dialog );
1568 msiobj_release( &view->hdr );
1570 return r;
1573 UINT msi_dialog_reset( msi_dialog *dialog )
1575 /* FIXME: should restore the original values of any properties we changed */
1576 return msi_dialog_evaluate_control_conditions( dialog );
1579 /* figure out the height of 10 point MS Sans Serif */
1580 static INT msi_dialog_get_sans_serif_height( HWND hwnd )
1582 static const WCHAR szSansSerif[] = {
1583 'M','S',' ','S','a','n','s',' ','S','e','r','i','f',0 };
1584 LOGFONTW lf;
1585 TEXTMETRICW tm;
1586 BOOL r;
1587 LONG height = 0;
1588 HFONT hFont, hOldFont;
1589 HDC hdc;
1591 hdc = GetDC( hwnd );
1592 if (hdc)
1594 memset( &lf, 0, sizeof lf );
1595 lf.lfHeight = MulDiv(10, GetDeviceCaps(hdc, LOGPIXELSY), 72);
1596 strcpyW( lf.lfFaceName, szSansSerif );
1597 hFont = CreateFontIndirectW(&lf);
1598 if (hFont)
1600 hOldFont = SelectObject( hdc, hFont );
1601 r = GetTextMetricsW( hdc, &tm );
1602 if (r)
1603 height = tm.tmHeight;
1604 SelectObject( hdc, hOldFont );
1605 DeleteObject( hFont );
1607 ReleaseDC( hwnd, hdc );
1609 return height;
1612 /* fetch the associated record from the Dialog table */
1613 static MSIRECORD *msi_get_dialog_record( msi_dialog *dialog )
1615 static const WCHAR query[] = {
1616 'S','E','L','E','C','T',' ','*',' ',
1617 'F','R','O','M',' ','D','i','a','l','o','g',' ',
1618 'W','H','E','R','E',' ',
1619 '`','D','i','a','l','o','g','`',' ','=',' ','\'','%','s','\'',0};
1620 MSIPACKAGE *package = dialog->package;
1621 MSIRECORD *rec = NULL;
1623 TRACE("%p %s\n", dialog, debugstr_w(dialog->name) );
1625 rec = MSI_QueryGetRecord( package->db, query, dialog->name );
1626 if( !rec )
1627 ERR("query failed for dialog %s\n", debugstr_w(dialog->name));
1629 return rec;
1632 static void msi_dialog_adjust_dialog_size( msi_dialog *dialog, LPSIZE sz )
1634 RECT rect;
1635 LONG style;
1637 /* turn the client size into the window rectangle */
1638 rect.left = 0;
1639 rect.top = 0;
1640 rect.right = msi_dialog_scale_unit( dialog, sz->cx );
1641 rect.bottom = msi_dialog_scale_unit( dialog, sz->cy );
1642 style = GetWindowLongPtrW( dialog->hwnd, GWL_STYLE );
1643 AdjustWindowRect( &rect, style, FALSE );
1644 sz->cx = rect.right - rect.left;
1645 sz->cy = rect.bottom - rect.top;
1648 static BOOL msi_control_set_next( msi_control *control, msi_control *next )
1650 return SetWindowPos( next->hwnd, control->hwnd, 0, 0, 0, 0,
1651 SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOREDRAW |
1652 SWP_NOREPOSITION | SWP_NOSENDCHANGING | SWP_NOSIZE );
1655 static UINT msi_dialog_set_tab_order( msi_dialog *dialog )
1657 msi_control *control, *tab_next;
1659 LIST_FOR_EACH_ENTRY( control, &dialog->controls, msi_control, entry )
1661 tab_next = msi_dialog_find_control( dialog, control->tabnext );
1662 if( !tab_next )
1663 continue;
1664 msi_control_set_next( control, tab_next );
1667 return ERROR_SUCCESS;
1670 static void msi_dialog_set_first_control( msi_dialog* dialog, LPCWSTR name )
1672 msi_control *control;
1674 control = msi_dialog_find_control( dialog, name );
1675 if( control )
1676 dialog->hWndFocus = control->hwnd;
1677 else
1678 dialog->hWndFocus = NULL;
1681 static LRESULT msi_dialog_oncreate( HWND hwnd, LPCREATESTRUCTW cs )
1683 static const WCHAR df[] = {
1684 'D','e','f','a','u','l','t','U','I','F','o','n','t',0 };
1685 static const WCHAR dfv[] = {
1686 'M','S',' ','S','h','e','l','l',' ','D','l','g',0 };
1687 msi_dialog *dialog = (msi_dialog*) cs->lpCreateParams;
1688 MSIRECORD *rec = NULL;
1689 LPWSTR title = NULL;
1690 SIZE size;
1692 TRACE("%p %p\n", dialog, dialog->package);
1694 dialog->hwnd = hwnd;
1695 SetWindowLongPtrW( hwnd, GWLP_USERDATA, (LONG_PTR) dialog );
1697 rec = msi_get_dialog_record( dialog );
1698 if( !rec )
1700 TRACE("No record found for dialog %s\n", debugstr_w(dialog->name));
1701 return -1;
1704 dialog->scale = msi_dialog_get_sans_serif_height(dialog->hwnd);
1706 size.cx = MSI_RecordGetInteger( rec, 4 );
1707 size.cy = MSI_RecordGetInteger( rec, 5 );
1708 msi_dialog_adjust_dialog_size( dialog, &size );
1710 dialog->attributes = MSI_RecordGetInteger( rec, 6 );
1712 dialog->default_font = msi_dup_property( dialog->package, df );
1713 if (!dialog->default_font)
1715 dialog->default_font = strdupW(dfv);
1716 if (!dialog->default_font) return -1;
1719 title = msi_get_deformatted_field( dialog->package, rec, 7 );
1720 SetWindowTextW( hwnd, title );
1721 msi_free( title );
1723 SetWindowPos( hwnd, 0, 0, 0, size.cx, size.cy,
1724 SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOREDRAW );
1727 msi_dialog_build_font_list( dialog );
1728 msi_dialog_fill_controls( dialog );
1729 msi_dialog_evaluate_control_conditions( dialog );
1730 msi_dialog_set_tab_order( dialog );
1731 msi_dialog_set_first_control( dialog, MSI_RecordGetString( rec, 8 ) );
1732 msiobj_release( &rec->hdr );
1734 return 0;
1737 static UINT msi_dialog_send_event( msi_dialog *dialog, LPCWSTR event, LPCWSTR arg )
1739 LPWSTR event_fmt = NULL, arg_fmt = NULL;
1741 TRACE("Sending control event %s %s\n", debugstr_w(event), debugstr_w(arg));
1743 deformat_string( dialog->package, event, &event_fmt );
1744 deformat_string( dialog->package, arg, &arg_fmt );
1746 dialog->event_handler( dialog->package, event_fmt, arg_fmt, dialog );
1748 msi_free( event_fmt );
1749 msi_free( arg_fmt );
1751 return ERROR_SUCCESS;
1754 static UINT msi_dialog_set_property( msi_dialog *dialog, LPCWSTR event, LPCWSTR arg )
1756 static const WCHAR szNullArg[] = { '{','}',0 };
1757 LPWSTR p, prop, arg_fmt = NULL;
1758 UINT len;
1760 len = strlenW(event);
1761 prop = msi_alloc( len*sizeof(WCHAR));
1762 strcpyW( prop, &event[1] );
1763 p = strchrW( prop, ']' );
1764 if( p && p[1] == 0 )
1766 *p = 0;
1767 if( strcmpW( szNullArg, arg ) )
1768 deformat_string( dialog->package, arg, &arg_fmt );
1769 MSI_SetPropertyW( dialog->package, prop, arg_fmt );
1770 msi_free( arg_fmt );
1772 else
1773 ERR("Badly formatted property string - what happens?\n");
1774 msi_free( prop );
1775 return ERROR_SUCCESS;
1778 static UINT msi_dialog_control_event( MSIRECORD *rec, LPVOID param )
1780 msi_dialog *dialog = param;
1781 LPCWSTR condition, event, arg;
1782 UINT r;
1784 condition = MSI_RecordGetString( rec, 5 );
1785 r = MSI_EvaluateConditionW( dialog->package, condition );
1786 if( r == MSICONDITION_TRUE )
1788 event = MSI_RecordGetString( rec, 3 );
1789 arg = MSI_RecordGetString( rec, 4 );
1790 if( event[0] == '[' )
1791 msi_dialog_set_property( dialog, event, arg );
1792 else
1793 msi_dialog_send_event( dialog, event, arg );
1796 return ERROR_SUCCESS;
1799 static UINT msi_dialog_button_handler( msi_dialog *dialog,
1800 msi_control *control, WPARAM param )
1802 static const WCHAR query[] = {
1803 'S','E','L','E','C','T',' ','*',' ',
1804 'F','R','O','M',' ','C','o','n','t','r','o','l','E','v','e','n','t',' ',
1805 'W','H','E','R','E',' ',
1806 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',' ',
1807 'A','N','D',' ',
1808 '`','C','o','n','t','r','o','l','_','`',' ','=',' ','\'','%','s','\'',' ',
1809 'O','R','D','E','R',' ','B','Y',' ','`','O','r','d','e','r','i','n','g','`',0
1811 MSIQUERY *view = NULL;
1812 UINT r;
1814 if( HIWORD(param) != BN_CLICKED )
1815 return ERROR_SUCCESS;
1817 r = MSI_OpenQuery( dialog->package->db, &view, query,
1818 dialog->name, control->name );
1819 if( r != ERROR_SUCCESS )
1821 ERR("query failed\n");
1822 return 0;
1825 r = MSI_IterateRecords( view, 0, msi_dialog_control_event, dialog );
1826 msiobj_release( &view->hdr );
1828 return r;
1831 static UINT msi_dialog_get_checkbox_state( msi_dialog *dialog,
1832 msi_control *control )
1834 WCHAR state[2] = { 0 };
1835 DWORD sz = 2;
1837 MSI_GetPropertyW( dialog->package, control->property, state, &sz );
1838 return state[0] ? 1 : 0;
1841 static void msi_dialog_set_checkbox_state( msi_dialog *dialog,
1842 msi_control *control, UINT state )
1844 static const WCHAR szState[] = { '1', 0 };
1845 LPCWSTR val;
1847 /* if uncheck then the property is set to NULL */
1848 if (!state)
1850 MSI_SetPropertyW( dialog->package, control->property, NULL );
1851 return;
1854 /* check for a custom state */
1855 if (control->value && control->value[0])
1856 val = control->value;
1857 else
1858 val = szState;
1860 MSI_SetPropertyW( dialog->package, control->property, val );
1863 static void msi_dialog_checkbox_sync_state( msi_dialog *dialog,
1864 msi_control *control )
1866 UINT state;
1868 state = msi_dialog_get_checkbox_state( dialog, control );
1869 SendMessageW( control->hwnd, BM_SETCHECK,
1870 state ? BST_CHECKED : BST_UNCHECKED, 0 );
1873 static UINT msi_dialog_checkbox_handler( msi_dialog *dialog,
1874 msi_control *control, WPARAM param )
1876 UINT state;
1878 if( HIWORD(param) != BN_CLICKED )
1879 return ERROR_SUCCESS;
1881 TRACE("clicked checkbox %s, set %s\n", debugstr_w(control->name),
1882 debugstr_w(control->property));
1884 state = msi_dialog_get_checkbox_state( dialog, control );
1885 state = state ? 0 : 1;
1886 msi_dialog_set_checkbox_state( dialog, control, state );
1887 msi_dialog_checkbox_sync_state( dialog, control );
1889 return msi_dialog_button_handler( dialog, control, param );
1892 static UINT msi_dialog_edit_handler( msi_dialog *dialog,
1893 msi_control *control, WPARAM param )
1895 UINT sz, r;
1896 LPWSTR buf;
1898 if( HIWORD(param) != EN_CHANGE )
1899 return ERROR_SUCCESS;
1901 TRACE("edit %s contents changed, set %s\n", debugstr_w(control->name),
1902 debugstr_w(control->property));
1904 sz = 0x20;
1905 buf = msi_alloc( sz*sizeof(WCHAR) );
1906 while( buf )
1908 r = GetWindowTextW( control->hwnd, buf, sz );
1909 if( r < (sz-1) )
1910 break;
1911 sz *= 2;
1912 buf = msi_realloc( buf, sz*sizeof(WCHAR) );
1915 MSI_SetPropertyW( dialog->package, control->property, buf );
1917 msi_free( buf );
1919 return ERROR_SUCCESS;
1922 static UINT msi_dialog_radiogroup_handler( msi_dialog *dialog,
1923 msi_control *control, WPARAM param )
1925 if( HIWORD(param) != BN_CLICKED )
1926 return ERROR_SUCCESS;
1928 TRACE("clicked radio button %s, set %s\n", debugstr_w(control->name),
1929 debugstr_w(control->property));
1931 MSI_SetPropertyW( dialog->package, control->property, control->name );
1933 return msi_dialog_button_handler( dialog, control, param );
1936 static LRESULT msi_dialog_oncommand( msi_dialog *dialog, WPARAM param, HWND hwnd )
1938 msi_control *control = NULL;
1940 TRACE("%p %p %08x\n", dialog, hwnd, param);
1942 switch (param)
1944 case 1: /* enter */
1945 control = msi_dialog_find_control( dialog, dialog->control_default );
1946 break;
1947 case 2: /* escape */
1948 control = msi_dialog_find_control( dialog, dialog->control_cancel );
1949 break;
1950 default:
1951 control = msi_dialog_find_control_by_hwnd( dialog, hwnd );
1954 if( control )
1956 if( control->handler )
1958 control->handler( dialog, control, param );
1959 msi_dialog_evaluate_control_conditions( dialog );
1962 else
1963 ERR("button click from nowhere %p %d %p\n", dialog, param, hwnd);
1964 return 0;
1967 static void msi_dialog_setfocus( msi_dialog *dialog )
1969 HWND hwnd = dialog->hWndFocus;
1971 hwnd = GetNextDlgTabItem( dialog->hwnd, hwnd, TRUE);
1972 hwnd = GetNextDlgTabItem( dialog->hwnd, hwnd, FALSE);
1973 SetFocus( hwnd );
1974 dialog->hWndFocus = hwnd;
1977 static LRESULT WINAPI MSIDialog_WndProc( HWND hwnd, UINT msg,
1978 WPARAM wParam, LPARAM lParam )
1980 msi_dialog *dialog = (LPVOID) GetWindowLongPtrW( hwnd, GWLP_USERDATA );
1982 TRACE("0x%04x\n", msg);
1984 switch (msg)
1986 case WM_CREATE:
1987 return msi_dialog_oncreate( hwnd, (LPCREATESTRUCTW)lParam );
1989 case WM_COMMAND:
1990 return msi_dialog_oncommand( dialog, wParam, (HWND)lParam );
1992 case WM_ACTIVATE:
1993 if( LOWORD(wParam) == WA_INACTIVE )
1994 dialog->hWndFocus = GetFocus();
1995 else
1996 msi_dialog_setfocus( dialog );
1997 return 0;
1999 case WM_SETFOCUS:
2000 msi_dialog_setfocus( dialog );
2001 return 0;
2003 /* bounce back to our subclassed static control */
2004 case WM_CTLCOLORSTATIC:
2005 return SendMessageW( (HWND) lParam, WM_CTLCOLORSTATIC, wParam, lParam );
2007 case WM_DESTROY:
2008 dialog->hwnd = NULL;
2009 return 0;
2011 return DefWindowProcW(hwnd, msg, wParam, lParam);
2014 static BOOL CALLBACK msi_radioground_child_enum( HWND hWnd, LPARAM lParam )
2016 EnableWindow( hWnd, lParam );
2017 return TRUE;
2020 static LRESULT WINAPI MSIRadioGroup_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
2022 WNDPROC oldproc = (WNDPROC) GetPropW(hWnd, szButtonData);
2023 LRESULT r;
2025 TRACE("hWnd %p msg %04x wParam 0x%08x lParam 0x%08lx\n", hWnd, msg, wParam, lParam);
2027 if (msg == WM_COMMAND) /* Forward notifications to dialog */
2028 SendMessageW(GetParent(hWnd), msg, wParam, lParam);
2030 r = CallWindowProcW(oldproc, hWnd, msg, wParam, lParam);
2032 /* make sure the radio buttons show as disabled if the parent is disabled */
2033 if (msg == WM_ENABLE)
2034 EnumChildWindows( hWnd, msi_radioground_child_enum, wParam );
2036 return r;
2039 static LRESULT WINAPI MSIHiddenWindowProc( HWND hwnd, UINT msg,
2040 WPARAM wParam, LPARAM lParam )
2042 msi_dialog *dialog = (msi_dialog*) lParam;
2044 TRACE("%d %p\n", msg, dialog);
2046 switch (msg)
2048 case WM_MSI_DIALOG_CREATE:
2049 return msi_dialog_run_message_loop( dialog );
2050 case WM_MSI_DIALOG_DESTROY:
2051 msi_dialog_destroy( dialog );
2052 return 0;
2054 return DefWindowProcW( hwnd, msg, wParam, lParam );
2057 /* functions that interface to other modules within MSI */
2059 msi_dialog *msi_dialog_create( MSIPACKAGE* package, LPCWSTR szDialogName,
2060 msi_dialog_event_handler event_handler )
2062 MSIRECORD *rec = NULL;
2063 msi_dialog *dialog;
2065 TRACE("%p %s\n", package, debugstr_w(szDialogName));
2067 /* allocate the structure for the dialog to use */
2068 dialog = msi_alloc_zero( sizeof *dialog + sizeof(WCHAR)*strlenW(szDialogName) );
2069 if( !dialog )
2070 return NULL;
2071 strcpyW( dialog->name, szDialogName );
2072 msiobj_addref( &package->hdr );
2073 dialog->package = package;
2074 dialog->event_handler = event_handler;
2075 dialog->finished = 0;
2076 list_init( &dialog->controls );
2078 /* verify that the dialog exists */
2079 rec = msi_get_dialog_record( dialog );
2080 if( !rec )
2082 msiobj_release( &package->hdr );
2083 msi_free( dialog );
2084 return NULL;
2086 dialog->attributes = MSI_RecordGetInteger( rec, 6 );
2087 dialog->control_default = strdupW( MSI_RecordGetString( rec, 9 ) );
2088 dialog->control_cancel = strdupW( MSI_RecordGetString( rec, 10 ) );
2089 msiobj_release( &rec->hdr );
2091 return dialog;
2094 static void msi_process_pending_messages( HWND hdlg )
2096 MSG msg;
2098 while( PeekMessageW( &msg, 0, 0, 0, PM_REMOVE ) )
2100 if( hdlg && IsDialogMessageW( hdlg, &msg ))
2101 continue;
2102 TranslateMessage( &msg );
2103 DispatchMessageW( &msg );
2107 void msi_dialog_end_dialog( msi_dialog *dialog )
2109 TRACE("%p\n", dialog);
2110 dialog->finished = 1;
2111 PostMessageW(dialog->hwnd, WM_NULL, 0, 0);
2114 void msi_dialog_check_messages( HANDLE handle )
2116 DWORD r;
2118 /* in threads other than the UI thread, block */
2119 if( uiThreadId != GetCurrentThreadId() )
2121 if( handle )
2122 WaitForSingleObject( handle, INFINITE );
2123 return;
2126 /* there's two choices for the UI thread */
2127 while (1)
2129 msi_process_pending_messages( NULL );
2131 if( !handle )
2132 break;
2135 * block here until somebody creates a new dialog or
2136 * the handle we're waiting on becomes ready
2138 r = MsgWaitForMultipleObjects( 1, &handle, 0, INFINITE, QS_ALLINPUT );
2139 if( r == WAIT_OBJECT_0 )
2140 break;
2144 UINT msi_dialog_run_message_loop( msi_dialog *dialog )
2146 HWND hwnd;
2148 if( !(dialog->attributes & msidbDialogAttributesVisible) )
2149 return ERROR_SUCCESS;
2151 if( uiThreadId != GetCurrentThreadId() )
2152 return SendMessageW( hMsiHiddenWindow, WM_MSI_DIALOG_CREATE, 0, (LPARAM) dialog );
2154 /* create the dialog window, don't show it yet */
2155 hwnd = CreateWindowW( szMsiDialogClass, dialog->name, WS_OVERLAPPEDWINDOW,
2156 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
2157 NULL, NULL, NULL, dialog );
2158 if( !hwnd )
2160 ERR("Failed to create dialog %s\n", debugstr_w( dialog->name ));
2161 return ERROR_FUNCTION_FAILED;
2164 ShowWindow( hwnd, SW_SHOW );
2165 /* UpdateWindow( hwnd ); - and causes the transparent static controls not to paint */
2167 if( dialog->attributes & msidbDialogAttributesModal )
2169 while( !dialog->finished )
2171 MsgWaitForMultipleObjects( 0, NULL, 0, INFINITE, QS_ALLEVENTS );
2172 msi_process_pending_messages( dialog->hwnd );
2175 else
2176 return ERROR_IO_PENDING;
2178 return ERROR_SUCCESS;
2181 void msi_dialog_do_preview( msi_dialog *dialog )
2183 TRACE("\n");
2184 dialog->attributes |= msidbDialogAttributesVisible;
2185 dialog->attributes &= ~msidbDialogAttributesModal;
2186 msi_dialog_run_message_loop( dialog );
2189 void msi_dialog_destroy( msi_dialog *dialog )
2191 if( uiThreadId != GetCurrentThreadId() )
2193 SendMessageW( hMsiHiddenWindow, WM_MSI_DIALOG_DESTROY, 0, (LPARAM) dialog );
2194 return;
2197 if( dialog->hwnd )
2198 ShowWindow( dialog->hwnd, SW_HIDE );
2200 if( dialog->hwnd )
2201 DestroyWindow( dialog->hwnd );
2203 /* destroy the list of controls */
2204 while( !list_empty( &dialog->controls ) )
2206 msi_control *t = LIST_ENTRY( list_head( &dialog->controls ),
2207 msi_control, entry );
2208 list_remove( &t->entry );
2209 /* leave dialog->hwnd - destroying parent destroys child windows */
2210 msi_free( t->property );
2211 msi_free( t->value );
2212 if( t->hBitmap )
2213 DeleteObject( t->hBitmap );
2214 if( t->hIcon )
2215 DestroyIcon( t->hIcon );
2216 msi_free( t->tabnext );
2217 msi_free( t );
2218 if (t->hDll)
2219 FreeLibrary( t->hDll );
2222 /* destroy the list of fonts */
2223 while( dialog->font_list )
2225 msi_font *t = dialog->font_list;
2226 dialog->font_list = t->next;
2227 DeleteObject( t->hfont );
2228 msi_free( t );
2230 msi_free( dialog->default_font );
2232 msi_free( dialog->control_default );
2233 msi_free( dialog->control_cancel );
2234 msiobj_release( &dialog->package->hdr );
2235 dialog->package = NULL;
2236 msi_free( dialog );
2239 BOOL msi_dialog_register_class( void )
2241 WNDCLASSW cls;
2243 ZeroMemory( &cls, sizeof cls );
2244 cls.lpfnWndProc = MSIDialog_WndProc;
2245 cls.hInstance = NULL;
2246 cls.hIcon = LoadIconW(0, (LPWSTR)IDI_APPLICATION);
2247 cls.hCursor = LoadCursorW(0, (LPWSTR)IDC_ARROW);
2248 cls.hbrBackground = (HBRUSH)(COLOR_3DFACE + 1);
2249 cls.lpszMenuName = NULL;
2250 cls.lpszClassName = szMsiDialogClass;
2252 if( !RegisterClassW( &cls ) )
2253 return FALSE;
2255 cls.lpfnWndProc = MSIHiddenWindowProc;
2256 cls.lpszClassName = szMsiHiddenWindow;
2258 if( !RegisterClassW( &cls ) )
2259 return FALSE;
2261 uiThreadId = GetCurrentThreadId();
2263 hMsiHiddenWindow = CreateWindowW( szMsiHiddenWindow, NULL, WS_OVERLAPPED,
2264 0, 0, 100, 100, NULL, NULL, NULL, NULL );
2265 if( !hMsiHiddenWindow )
2266 return FALSE;
2268 return TRUE;
2271 void msi_dialog_unregister_class( void )
2273 DestroyWindow( hMsiHiddenWindow );
2274 hMsiHiddenWindow = NULL;
2275 UnregisterClassW( szMsiDialogClass, NULL );
2276 UnregisterClassW( szMsiHiddenWindow, NULL );
2277 uiThreadId = 0;