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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #define NONAMELESSUNION
23 #define NONAMELESSSTRUCT
40 #include "wine/debug.h"
41 #include "wine/unicode.h"
45 WINE_DEFAULT_DEBUG_CHANNEL(msi);
48 extern HINSTANCE msi_hInstance;
50 struct msi_control_tag;
51 typedef struct msi_control_tag msi_control;
52 typedef UINT (*msi_handler)( msi_dialog *, msi_control *, WPARAM );
54 struct msi_control_tag
65 float progress_current;
70 typedef struct msi_font_tag
72 struct msi_font_tag *next;
81 msi_dialog_event_handler event_handler;
90 LPWSTR control_default;
91 LPWSTR control_cancel;
95 typedef UINT (*msi_dialog_control_func)( msi_dialog *dialog, MSIRECORD *rec );
96 struct control_handler
99 msi_dialog_control_func func;
108 } radio_button_group_descr;
110 static const WCHAR szMsiDialogClass[] = {
111 'M','s','i','D','i','a','l','o','g','C','l','o','s','e','C','l','a','s','s',0
113 static const WCHAR szMsiHiddenWindow[] = {
114 'M','s','i','H','i','d','d','e','n','W','i','n','d','o','w',0 };
115 static const WCHAR szStatic[] = { 'S','t','a','t','i','c',0 };
116 static const WCHAR szButton[] = { 'B','U','T','T','O','N', 0 };
117 static const WCHAR szButtonData[] = { 'M','S','I','D','A','T','A',0 };
118 static const WCHAR szProgress[] = { 'P','r','o','g','r','e','s','s',0 };
119 static const WCHAR szText[] = { 'T','e','x','t',0 };
120 static const WCHAR szPushButton[] = { 'P','u','s','h','B','u','t','t','o','n',0 };
121 static const WCHAR szLine[] = { 'L','i','n','e',0 };
122 static const WCHAR szBitmap[] = { 'B','i','t','m','a','p',0 };
123 static const WCHAR szCheckBox[] = { 'C','h','e','c','k','B','o','x',0 };
124 static const WCHAR szScrollableText[] = {
125 'S','c','r','o','l','l','a','b','l','e','T','e','x','t',0 };
126 static const WCHAR szComboBox[] = { 'C','o','m','b','o','B','o','x',0 };
127 static const WCHAR szEdit[] = { 'E','d','i','t',0 };
128 static const WCHAR szMaskedEdit[] = { 'M','a','s','k','e','d','E','d','i','t',0 };
129 static const WCHAR szPathEdit[] = { 'P','a','t','h','E','d','i','t',0 };
130 static const WCHAR szProgressBar[] = {
131 'P','r','o','g','r','e','s','s','B','a','r',0 };
132 static const WCHAR szRadioButtonGroup[] = {
133 'R','a','d','i','o','B','u','t','t','o','n','G','r','o','u','p',0 };
134 static const WCHAR szIcon[] = { 'I','c','o','n',0 };
135 static const WCHAR szSelectionTree[] = {
136 'S','e','l','e','c','t','i','o','n','T','r','e','e',0 };
137 static const WCHAR szGroupBox[] = { 'G','r','o','u','p','B','o','x',0 };
138 static const WCHAR szListBox[] = { 'L','i','s','t','B','o','x',0 };
140 static UINT msi_dialog_checkbox_handler( msi_dialog *, msi_control *, WPARAM );
141 static void msi_dialog_checkbox_sync_state( msi_dialog *, msi_control * );
142 static UINT msi_dialog_button_handler( msi_dialog *, msi_control *, WPARAM );
143 static UINT msi_dialog_edit_handler( msi_dialog *, msi_control *, WPARAM );
144 static UINT msi_dialog_radiogroup_handler( msi_dialog *, msi_control *, WPARAM param );
145 static UINT msi_dialog_evaluate_control_conditions( msi_dialog *dialog );
146 static LRESULT WINAPI MSIRadioGroup_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
149 /* dialog sequencing */
151 #define WM_MSI_DIALOG_CREATE (WM_USER+0x100)
152 #define WM_MSI_DIALOG_DESTROY (WM_USER+0x101)
154 static DWORD uiThreadId;
155 static HWND hMsiHiddenWindow;
157 static INT msi_dialog_scale_unit( msi_dialog *dialog, INT val )
159 return (dialog->scale * val + 5) / 10;
162 static msi_control *msi_dialog_find_control( msi_dialog *dialog, LPCWSTR name )
164 msi_control *control;
168 LIST_FOR_EACH_ENTRY( control, &dialog->controls, msi_control, entry )
169 if( !strcmpW( control->name, name ) ) /* FIXME: case sensitive? */
174 static msi_control *msi_dialog_find_control_by_hwnd( msi_dialog *dialog, HWND hwnd )
176 msi_control *control;
178 LIST_FOR_EACH_ENTRY( control, &dialog->controls, msi_control, entry )
179 if( hwnd == control->hwnd )
184 static LPWSTR msi_get_deformatted_field( MSIPACKAGE *package, MSIRECORD *rec, int field )
186 LPCWSTR str = MSI_RecordGetString( rec, field );
190 deformat_string( package, str, &ret );
195 * msi_dialog_get_style
197 * Extract the {\style} string from the front of the text to display and
198 * update the pointer.
200 static LPWSTR msi_dialog_get_style( LPCWSTR p, LPCWSTR *rest )
211 q = strchrW( p, '}' );
214 if( *p == '\\' || *p == '&' )
217 /* little bit of sanity checking to stop us getting confused with RTF */
219 if( *i == '}' || *i == '\\' )
225 ret = msi_alloc( len*sizeof(WCHAR) );
228 memcpy( ret, p, len*sizeof(WCHAR) );
233 static UINT msi_dialog_add_font( MSIRECORD *rec, LPVOID param )
235 msi_dialog *dialog = param;
242 /* create a font and add it to the list */
243 name = MSI_RecordGetString( rec, 1 );
244 font = msi_alloc( sizeof *font + strlenW( name )*sizeof (WCHAR) );
245 strcpyW( font->name, name );
246 font->next = dialog->font_list;
247 dialog->font_list = font;
249 font->color = MSI_RecordGetInteger( rec, 4 );
251 memset( &lf, 0, sizeof lf );
252 face = MSI_RecordGetString( rec, 2 );
253 lf.lfHeight = MSI_RecordGetInteger( rec, 3 );
254 style = MSI_RecordGetInteger( rec, 5 );
255 if( style & msidbTextStyleStyleBitsBold )
256 lf.lfWeight = FW_BOLD;
257 if( style & msidbTextStyleStyleBitsItalic )
259 if( style & msidbTextStyleStyleBitsUnderline )
260 lf.lfUnderline = TRUE;
261 if( style & msidbTextStyleStyleBitsStrike )
262 lf.lfStrikeOut = TRUE;
263 lstrcpynW( lf.lfFaceName, face, LF_FACESIZE );
265 /* adjust the height */
266 hdc = GetDC( dialog->hwnd );
269 lf.lfHeight = -MulDiv(lf.lfHeight, GetDeviceCaps(hdc, LOGPIXELSY), 72);
270 ReleaseDC( dialog->hwnd, hdc );
273 font->hfont = CreateFontIndirectW( &lf );
275 TRACE("Adding font style %s\n", debugstr_w(font->name) );
277 return ERROR_SUCCESS;
280 static msi_font *msi_dialog_find_font( msi_dialog *dialog, LPCWSTR name )
284 for( font = dialog->font_list; font; font = font->next )
285 if( !strcmpW( font->name, name ) ) /* FIXME: case sensitive? */
291 static UINT msi_dialog_set_font( msi_dialog *dialog, HWND hwnd, LPCWSTR name )
295 font = msi_dialog_find_font( dialog, name );
297 SendMessageW( hwnd, WM_SETFONT, (WPARAM) font->hfont, TRUE );
299 ERR("No font entry for %s\n", debugstr_w(name));
300 return ERROR_SUCCESS;
303 static UINT msi_dialog_build_font_list( msi_dialog *dialog )
305 static const WCHAR query[] = {
306 'S','E','L','E','C','T',' ','*',' ',
307 'F','R','O','M',' ','`','T','e','x','t','S','t','y','l','e','`',' ',0
310 MSIQUERY *view = NULL;
312 TRACE("dialog %p\n", dialog );
314 r = MSI_OpenQuery( dialog->package->db, &view, query );
315 if( r != ERROR_SUCCESS )
318 r = MSI_IterateRecords( view, NULL, msi_dialog_add_font, dialog );
319 msiobj_release( &view->hdr );
324 static msi_control *msi_dialog_create_window( msi_dialog *dialog,
325 MSIRECORD *rec, DWORD exstyle, LPCWSTR szCls, LPCWSTR name, LPCWSTR text,
326 DWORD style, HWND parent )
328 DWORD x, y, width, height;
329 LPWSTR font = NULL, title_font = NULL;
330 LPCWSTR title = NULL;
331 msi_control *control;
335 control = msi_alloc( sizeof *control + strlenW(name)*sizeof(WCHAR) );
336 strcpyW( control->name, name );
337 list_add_head( &dialog->controls, &control->entry );
338 control->handler = NULL;
339 control->property = NULL;
340 control->value = NULL;
341 control->hBitmap = NULL;
342 control->hIcon = NULL;
343 control->hDll = NULL;
344 control->tabnext = strdupW( MSI_RecordGetString( rec, 11) );
345 control->progress_current = 0;
346 control->progress_max = 100;
348 x = MSI_RecordGetInteger( rec, 4 );
349 y = MSI_RecordGetInteger( rec, 5 );
350 width = MSI_RecordGetInteger( rec, 6 );
351 height = MSI_RecordGetInteger( rec, 7 );
353 x = msi_dialog_scale_unit( dialog, x );
354 y = msi_dialog_scale_unit( dialog, y );
355 width = msi_dialog_scale_unit( dialog, width );
356 height = msi_dialog_scale_unit( dialog, height );
360 deformat_string( dialog->package, text, &title_font );
361 font = msi_dialog_get_style( title_font, &title );
364 control->hwnd = CreateWindowExW( exstyle, szCls, title, style,
365 x, y, width, height, parent, NULL, NULL, NULL );
367 TRACE("Dialog %s control %s hwnd %p\n",
368 debugstr_w(dialog->name), debugstr_w(text), control->hwnd );
370 msi_dialog_set_font( dialog, control->hwnd,
371 font ? font : dialog->default_font );
373 msi_free( title_font );
379 static MSIRECORD *msi_get_binary_record( MSIDATABASE *db, LPCWSTR name )
381 static const WCHAR query[] = {
382 's','e','l','e','c','t',' ','*',' ',
383 'f','r','o','m',' ','B','i','n','a','r','y',' ',
384 'w','h','e','r','e',' ',
385 '`','N','a','m','e','`',' ','=',' ','\'','%','s','\'',0
388 return MSI_QueryGetRecord( db, query, name );
391 static LPWSTR msi_create_tmp_path(void)
395 static const WCHAR prefix[] = { 'm','s','i',0 };
398 r = GetTempPathW( MAX_PATH, tmp );
401 len = lstrlenW( tmp ) + 20;
402 path = msi_alloc( len * sizeof (WCHAR) );
405 r = GetTempFileNameW( tmp, prefix, 0, path );
416 static HANDLE msi_load_image( MSIDATABASE *db, LPCWSTR name, UINT type,
417 UINT cx, UINT cy, UINT flags )
419 MSIRECORD *rec = NULL;
420 HANDLE himage = NULL;
424 TRACE("%p %s %u %u %08x\n", db, debugstr_w(name), cx, cy, flags);
426 tmp = msi_create_tmp_path();
430 rec = msi_get_binary_record( db, name );
433 r = MSI_RecordStreamToFile( rec, 2, tmp );
434 if( r == ERROR_SUCCESS )
436 himage = LoadImageW( 0, tmp, type, cx, cy, flags );
439 msiobj_release( &rec->hdr );
446 static HICON msi_load_icon( MSIDATABASE *db, LPCWSTR text, UINT attributes )
448 DWORD cx = 0, cy = 0, flags;
450 flags = LR_LOADFROMFILE | LR_DEFAULTSIZE;
451 if( attributes & msidbControlAttributesFixedSize )
453 flags &= ~LR_DEFAULTSIZE;
454 if( attributes & msidbControlAttributesIconSize16 )
459 if( attributes & msidbControlAttributesIconSize32 )
464 /* msidbControlAttributesIconSize48 handled by above logic */
466 return msi_load_image( db, text, IMAGE_ICON, cx, cy, flags );
470 /* called from the Control Event subscription code */
471 void msi_dialog_handle_event( msi_dialog* dialog, LPCWSTR control,
472 LPCWSTR attribute, MSIRECORD *rec )
475 LPCWSTR font_text, text = NULL;
478 ctrl = msi_dialog_find_control( dialog, control );
481 if( !lstrcmpW(attribute, szText) )
483 font_text = MSI_RecordGetString( rec , 1 );
484 font = msi_dialog_get_style( font_text, &text );
485 SetWindowTextW( ctrl->hwnd, text );
487 msi_dialog_check_messages( NULL );
489 else if( !lstrcmpW(attribute, szProgress) )
493 func = MSI_RecordGetInteger( rec , 1 );
494 val = MSI_RecordGetInteger( rec , 2 );
499 ctrl->progress_max = val;
500 ctrl->progress_current = 0;
501 SendMessageW(ctrl->hwnd, PBM_SETRANGE, 0, MAKELPARAM(0,100));
502 SendMessageW(ctrl->hwnd, PBM_SETPOS, 0, 0);
504 case 1: /* FIXME: not sure what this is supposed to do */
507 ctrl->progress_current += val;
508 SendMessageW(ctrl->hwnd, PBM_SETPOS, 100*(ctrl->progress_current/ctrl->progress_max), 0);
511 ERR("Unknown progress message %ld\n", func);
517 FIXME("Attribute %s not being set\n", debugstr_w(attribute));
522 static void msi_dialog_map_events(msi_dialog* dialog, LPCWSTR control)
524 static const WCHAR Query[] = {
525 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
526 '`','E','v','e','n','t','M','a','p','p','i','n','g','`',' ',
527 'W','H','E','R','E',' ',
528 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',' ',
530 '`','C','o','n','t','r','o','l','_','`',' ','=',' ','\'','%','s','\'',0
533 LPCWSTR event, attribute;
535 row = MSI_QueryGetRecord( dialog->package->db, Query, dialog->name, control );
539 event = MSI_RecordGetString( row, 3 );
540 attribute = MSI_RecordGetString( row, 4 );
541 ControlEvent_SubscribeToEvent( dialog->package, event, control, attribute );
542 msiobj_release( &row->hdr );
545 /* everything except radio buttons */
546 static msi_control *msi_dialog_add_control( msi_dialog *dialog,
547 MSIRECORD *rec, LPCWSTR szCls, DWORD style )
553 name = MSI_RecordGetString( rec, 2 );
554 attributes = MSI_RecordGetInteger( rec, 8 );
555 text = MSI_RecordGetString( rec, 10 );
556 if( attributes & msidbControlAttributesVisible )
558 if( ~attributes & msidbControlAttributesEnabled )
559 style |= WS_DISABLED;
560 if( attributes & msidbControlAttributesSunken )
561 exstyle |= WS_EX_CLIENTEDGE;
563 msi_dialog_map_events(dialog, name);
565 return msi_dialog_create_window( dialog, rec, exstyle, szCls, name,
566 text, style, dialog->hwnd );
577 * we don't erase our own background,
578 * so we have to make sure that the parent window redraws first
580 static void msi_text_on_settext( HWND hWnd )
585 hParent = GetParent( hWnd );
586 GetWindowRect( hWnd, &rc );
587 MapWindowPoints( NULL, hParent, (LPPOINT) &rc, 2 );
588 InvalidateRect( hParent, &rc, TRUE );
591 static LRESULT WINAPI
592 MSIText_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
594 struct msi_text_info *info;
597 TRACE("%p %04x %08x %08lx\n", hWnd, msg, wParam, lParam);
599 info = GetPropW(hWnd, szButtonData);
602 SetTextColor( (HDC)wParam, info->font->color );
604 if( msg == WM_CTLCOLORSTATIC &&
605 ( info->attributes & msidbControlAttributesTransparent ) )
607 SetBkMode( (HDC)wParam, TRANSPARENT );
608 return (LRESULT) GetStockObject(NULL_BRUSH);
611 r = CallWindowProcW(info->oldproc, hWnd, msg, wParam, lParam);
616 msi_text_on_settext( hWnd );
620 RemovePropW( hWnd, szButtonData );
627 static UINT msi_dialog_text_control( msi_dialog *dialog, MSIRECORD *rec )
629 msi_control *control;
630 struct msi_text_info *info;
634 TRACE("%p %p\n", dialog, rec);
636 control = msi_dialog_add_control( dialog, rec, szStatic, SS_LEFT | WS_GROUP );
638 return ERROR_FUNCTION_FAILED;
640 info = msi_alloc( sizeof *info );
642 return ERROR_SUCCESS;
644 text = MSI_RecordGetString( rec, 10 );
645 font_name = msi_dialog_get_style( text, &ptr );
646 info->font = ( font_name ) ? msi_dialog_find_font( dialog, font_name ) : NULL;
647 msi_free( font_name );
649 info->attributes = MSI_RecordGetInteger( rec, 8 );
650 if( info->attributes & msidbControlAttributesTransparent )
651 SetWindowLongPtrW( control->hwnd, GWL_EXSTYLE, WS_EX_TRANSPARENT );
653 info->oldproc = (WNDPROC) SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
654 (LONG_PTR)MSIText_WndProc );
655 SetPropW( control->hwnd, szButtonData, info );
657 return ERROR_SUCCESS;
660 static UINT msi_dialog_button_control( msi_dialog *dialog, MSIRECORD *rec )
662 msi_control *control;
663 UINT attributes, style;
666 TRACE("%p %p\n", dialog, rec);
669 attributes = MSI_RecordGetInteger( rec, 8 );
670 if( attributes & msidbControlAttributesIcon )
673 control = msi_dialog_add_control( dialog, rec, szButton, style );
675 return ERROR_FUNCTION_FAILED;
677 control->handler = msi_dialog_button_handler;
680 text = msi_get_deformatted_field( dialog->package, rec, 10 );
681 control->hIcon = msi_load_icon( dialog->package->db, text, attributes );
682 if( attributes & msidbControlAttributesIcon )
683 SendMessageW( control->hwnd, BM_SETIMAGE, IMAGE_ICON, (LPARAM) control->hIcon );
686 return ERROR_SUCCESS;
689 static LPWSTR msi_get_checkbox_value( msi_dialog *dialog, LPCWSTR prop )
691 static const WCHAR query[] = {
692 'S','E','L','E','C','T',' ','*',' ',
693 'F','R','O','M',' ','`','C','h','e','c','k','B','o','x',' ','`',
694 'W','H','E','R','E',' ',
695 '`','P','r','o','p','e','r','t','y','`',' ','=',' ',
698 MSIRECORD *rec = NULL;
701 /* find if there is a value associated with the checkbox */
702 rec = MSI_QueryGetRecord( dialog->package->db, query, prop );
706 ret = msi_get_deformatted_field( dialog->package, rec, 2 );
712 msiobj_release( &rec->hdr );
716 ret = msi_dup_property( dialog->package, prop );
726 static UINT msi_dialog_checkbox_control( msi_dialog *dialog, MSIRECORD *rec )
728 msi_control *control;
731 TRACE("%p %p\n", dialog, rec);
733 control = msi_dialog_add_control( dialog, rec, szButton,
734 BS_CHECKBOX | BS_MULTILINE | WS_TABSTOP );
735 control->handler = msi_dialog_checkbox_handler;
736 prop = MSI_RecordGetString( rec, 9 );
739 control->property = strdupW( prop );
740 control->value = msi_get_checkbox_value( dialog, prop );
741 TRACE("control %s value %s\n", debugstr_w(control->property),
742 debugstr_w(control->value));
744 msi_dialog_checkbox_sync_state( dialog, control );
746 return ERROR_SUCCESS;
749 static UINT msi_dialog_line_control( msi_dialog *dialog, MSIRECORD *rec )
751 TRACE("%p %p\n", dialog, rec);
753 msi_dialog_add_control( dialog, rec, szStatic, SS_ETCHEDHORZ | SS_SUNKEN );
754 return ERROR_SUCCESS;
757 /******************** Scroll Text ********************************************/
759 struct msi_scrolltext_info
762 msi_control *control;
766 static LRESULT WINAPI
767 MSIScrollText_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
769 struct msi_scrolltext_info *info;
772 TRACE("%p %04x %08x %08lx\n", hWnd, msg, wParam, lParam);
774 info = GetPropW( hWnd, szButtonData );
776 r = CallWindowProcW( info->oldproc, hWnd, msg, wParam, lParam );
782 RemovePropW( hWnd, szButtonData );
785 /* native MSI sets a wait cursor here */
786 msi_dialog_button_handler( info->dialog, info->control, BN_CLICKED );
792 struct msi_streamin_info
799 static DWORD CALLBACK
800 msi_richedit_stream_in( DWORD_PTR arg, LPBYTE buffer, LONG count, LONG *pcb )
802 struct msi_streamin_info *info = (struct msi_streamin_info*) arg;
804 if( (count + info->offset) > info->length )
805 count = info->length - info->offset;
806 memcpy( buffer, &info->string[ info->offset ], count );
808 info->offset += count;
810 TRACE("%ld/%ld\n", info->offset, info->length);
815 static void msi_scrolltext_add_text( msi_control *control, LPCWSTR text )
817 struct msi_streamin_info info;
820 info.string = strdupWtoA( text );
822 info.length = lstrlenA( info.string ) + 1;
824 es.dwCookie = (DWORD_PTR) &info;
826 es.pfnCallback = msi_richedit_stream_in;
828 SendMessageW( control->hwnd, EM_STREAMIN, SF_RTF, (LPARAM) &es );
830 msi_free( info.string );
833 static UINT msi_dialog_scrolltext_control( msi_dialog *dialog, MSIRECORD *rec )
835 static const WCHAR szRichEdit20W[] = {
836 'R','i','c','h','E','d','i','t','2','0','W',0
838 struct msi_scrolltext_info *info;
839 msi_control *control;
843 info = msi_alloc( sizeof *info );
845 return ERROR_FUNCTION_FAILED;
847 hRichedit = LoadLibraryA("riched20");
849 style = WS_BORDER | ES_MULTILINE | WS_VSCROLL |
850 ES_READONLY | ES_AUTOVSCROLL | WS_TABSTOP;
851 control = msi_dialog_add_control( dialog, rec, szRichEdit20W, style );
854 FreeLibrary( hRichedit );
856 return ERROR_FUNCTION_FAILED;
859 control->hDll = hRichedit;
861 info->dialog = dialog;
862 info->control = control;
864 /* subclass the static control */
865 info->oldproc = (WNDPROC) SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
866 (LONG_PTR)MSIScrollText_WndProc );
867 SetPropW( control->hwnd, szButtonData, info );
869 /* add the text into the richedit */
870 msi_scrolltext_add_text( control, MSI_RecordGetString( rec, 10 ) );
872 return ERROR_SUCCESS;
875 static HBITMAP msi_load_picture( MSIDATABASE *db, LPCWSTR name,
876 INT cx, INT cy, DWORD flags )
878 HBITMAP hOleBitmap = 0, hBitmap = 0, hOldSrcBitmap, hOldDestBitmap;
879 MSIRECORD *rec = NULL;
881 IPicture *pic = NULL;
886 rec = msi_get_binary_record( db, name );
890 r = MSI_RecordGetIStream( rec, 2, &stm );
891 msiobj_release( &rec->hdr );
892 if( r != ERROR_SUCCESS )
895 r = OleLoadPicture( stm, 0, TRUE, &IID_IPicture, (LPVOID*) &pic );
896 IStream_Release( stm );
899 ERR("failed to load picture\n");
903 r = IPicture_get_Handle( pic, (OLE_HANDLE*) &hOleBitmap );
906 ERR("failed to get bitmap handle\n");
910 /* make the bitmap the desired size */
911 r = GetObjectW( hOleBitmap, sizeof bm, &bm );
914 ERR("failed to get bitmap size\n");
918 if (flags & LR_DEFAULTSIZE)
924 srcdc = CreateCompatibleDC( NULL );
925 hOldSrcBitmap = SelectObject( srcdc, hOleBitmap );
926 destdc = CreateCompatibleDC( NULL );
927 hBitmap = CreateCompatibleBitmap( srcdc, cx, cy );
928 hOldDestBitmap = SelectObject( destdc, hBitmap );
929 StretchBlt( destdc, 0, 0, cx, cy,
930 srcdc, 0, 0, bm.bmWidth, bm.bmHeight, SRCCOPY);
931 SelectObject( srcdc, hOldSrcBitmap );
932 SelectObject( destdc, hOldDestBitmap );
938 IPicture_Release( pic );
942 static UINT msi_dialog_bitmap_control( msi_dialog *dialog, MSIRECORD *rec )
944 UINT cx, cy, flags, style, attributes;
945 msi_control *control;
948 flags = LR_LOADFROMFILE;
949 style = SS_BITMAP | SS_LEFT | WS_GROUP;
951 attributes = MSI_RecordGetInteger( rec, 8 );
952 if( attributes & msidbControlAttributesFixedSize )
954 flags |= LR_DEFAULTSIZE;
955 style |= SS_CENTERIMAGE;
958 control = msi_dialog_add_control( dialog, rec, szStatic, style );
959 cx = MSI_RecordGetInteger( rec, 6 );
960 cy = MSI_RecordGetInteger( rec, 7 );
961 cx = msi_dialog_scale_unit( dialog, cx );
962 cy = msi_dialog_scale_unit( dialog, cy );
964 text = msi_get_deformatted_field( dialog->package, rec, 10 );
965 control->hBitmap = msi_load_picture( dialog->package->db, text, cx, cy, flags );
966 if( control->hBitmap )
967 SendMessageW( control->hwnd, STM_SETIMAGE,
968 IMAGE_BITMAP, (LPARAM) control->hBitmap );
970 ERR("Failed to load bitmap %s\n", debugstr_w(text));
974 return ERROR_SUCCESS;
977 static UINT msi_dialog_icon_control( msi_dialog *dialog, MSIRECORD *rec )
979 msi_control *control;
985 control = msi_dialog_add_control( dialog, rec, szStatic,
986 SS_ICON | SS_CENTERIMAGE | WS_GROUP );
988 attributes = MSI_RecordGetInteger( rec, 8 );
989 text = msi_get_deformatted_field( dialog->package, rec, 10 );
990 control->hIcon = msi_load_icon( dialog->package->db, text, attributes );
992 SendMessageW( control->hwnd, STM_SETICON, (WPARAM) control->hIcon, 0 );
994 ERR("Failed to load bitmap %s\n", debugstr_w(text));
996 return ERROR_SUCCESS;
999 static UINT msi_dialog_combo_control( msi_dialog *dialog, MSIRECORD *rec )
1001 static const WCHAR szCombo[] = { 'C','O','M','B','O','B','O','X',0 };
1003 msi_dialog_add_control( dialog, rec, szCombo,
1004 SS_BITMAP | SS_LEFT | SS_CENTERIMAGE );
1005 return ERROR_SUCCESS;
1008 static UINT msi_dialog_edit_control( msi_dialog *dialog, MSIRECORD *rec )
1010 msi_control *control;
1014 control = msi_dialog_add_control( dialog, rec, szEdit,
1015 WS_BORDER | WS_TABSTOP );
1016 control->handler = msi_dialog_edit_handler;
1017 prop = MSI_RecordGetString( rec, 9 );
1019 control->property = strdupW( prop );
1020 val = msi_dup_property( dialog->package, control->property );
1021 SetWindowTextW( control->hwnd, val );
1023 return ERROR_SUCCESS;
1026 /******************** Masked Edit ********************************************/
1028 #define MASK_MAX_GROUPS 10
1030 struct msi_mask_group
1038 struct msi_maskedit_info
1046 struct msi_mask_group group[MASK_MAX_GROUPS];
1049 static BOOL msi_mask_editable( WCHAR type )
1064 static void msi_mask_control_change( struct msi_maskedit_info *info )
1069 val = msi_alloc( (info->num_chars+1)*sizeof(WCHAR) );
1070 for( i=0, n=0; i<info->num_groups; i++ )
1072 if( (info->group[i].len + n) > info->num_chars )
1074 ERR("can't fit control %d text into template\n",i);
1077 if (!msi_mask_editable(info->group[i].type))
1079 for(r=0; r<info->group[i].len; r++)
1080 val[n+r] = info->group[i].type;
1085 r = GetWindowTextW( info->group[i].hwnd, &val[n], info->group[i].len+1 );
1086 if( r != info->group[i].len )
1092 TRACE("%d/%d controls were good\n", i, info->num_groups);
1094 if( i == info->num_groups )
1096 TRACE("Set property %s to %s\n",
1097 debugstr_w(info->prop), debugstr_w(val) );
1098 CharUpperBuffW( val, info->num_chars );
1099 MSI_SetPropertyW( info->dialog->package, info->prop, val );
1100 msi_dialog_evaluate_control_conditions( info->dialog );
1105 /* now move to the next control if necessary */
1106 static VOID msi_mask_next_control( struct msi_maskedit_info *info, HWND hWnd )
1111 for( i=0; i<info->num_groups; i++ )
1112 if( info->group[i].hwnd == hWnd )
1115 /* don't move from the last control */
1116 if( i >= (info->num_groups-1) )
1119 len = SendMessageW( hWnd, WM_GETTEXTLENGTH, 0, 0 );
1120 if( len < info->group[i].len )
1123 hWndNext = GetNextDlgTabItem( GetParent( hWnd ), hWnd, FALSE );
1124 SetFocus( hWndNext );
1127 static LRESULT WINAPI
1128 MSIMaskedEdit_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
1130 struct msi_maskedit_info *info;
1133 TRACE("%p %04x %08x %08lx\n", hWnd, msg, wParam, lParam);
1135 info = GetPropW(hWnd, szButtonData);
1137 r = CallWindowProcW(info->oldproc, hWnd, msg, wParam, lParam);
1142 if (HIWORD(wParam) == EN_CHANGE)
1144 msi_mask_control_change( info );
1145 msi_mask_next_control( info, (HWND) lParam );
1149 msi_free( info->prop );
1151 RemovePropW( hWnd, szButtonData );
1158 /* fish the various bits of the property out and put them in the control */
1160 msi_maskedit_set_text( struct msi_maskedit_info *info, LPCWSTR text )
1166 for( i = 0; i < info->num_groups; i++ )
1168 if( info->group[i].len < lstrlenW( p ) )
1170 LPWSTR chunk = strdupW( p );
1171 chunk[ info->group[i].len ] = 0;
1172 SetWindowTextW( info->group[i].hwnd, chunk );
1177 SetWindowTextW( info->group[i].hwnd, p );
1180 p += info->group[i].len;
1184 static struct msi_maskedit_info * msi_dialog_parse_groups( LPCWSTR mask )
1186 struct msi_maskedit_info * info = NULL;
1187 int i = 0, n = 0, total = 0;
1190 TRACE("masked control, template %s\n", debugstr_w(mask));
1195 info = msi_alloc_zero( sizeof *info );
1199 p = strchrW(mask, '<');
1205 for( i=0; i<MASK_MAX_GROUPS; i++ )
1207 /* stop at the end of the string */
1208 if( p[0] == 0 || p[0] == '>' )
1211 /* count the number of the same identifier */
1212 for( n=0; p[n] == p[0]; n++ )
1214 info->group[i].ofs = total;
1215 info->group[i].type = p[0];
1219 total++; /* an extra not part of the group */
1221 info->group[i].len = n;
1226 TRACE("%d characters in %d groups\n", total, i );
1227 if( i == MASK_MAX_GROUPS )
1228 ERR("too many groups in PIDTemplate %s\n", debugstr_w(mask));
1230 info->num_chars = total;
1231 info->num_groups = i;
1237 msi_maskedit_create_children( struct msi_maskedit_info *info, LPCWSTR font )
1239 DWORD width, height, style, wx, ww;
1244 style = WS_CHILD | WS_BORDER | WS_VISIBLE | WS_TABSTOP | ES_AUTOHSCROLL;
1246 GetClientRect( info->hwnd, &rect );
1248 width = rect.right - rect.left;
1249 height = rect.bottom - rect.top;
1251 for( i = 0; i < info->num_groups; i++ )
1253 if (!msi_mask_editable( info->group[i].type ))
1255 wx = (info->group[i].ofs * width) / info->num_chars;
1256 ww = (info->group[i].len * width) / info->num_chars;
1258 hwnd = CreateWindowW( szEdit, NULL, style, wx, 0, ww, height,
1259 info->hwnd, NULL, NULL, NULL );
1262 ERR("failed to create mask edit sub window\n");
1266 SendMessageW( hwnd, EM_LIMITTEXT, info->group[i].len, 0 );
1268 msi_dialog_set_font( info->dialog, hwnd,
1269 font?font:info->dialog->default_font );
1270 info->group[i].hwnd = hwnd;
1275 * office 2003 uses "73931<````=````=````=````=`````>@@@@@"
1276 * delphi 7 uses "<????-??????-??????-????>" and "<???-???>"
1277 * filemaker pro 7 uses "<^^^^=^^^^=^^^^=^^^^=^^^^=^^^^=^^^^^>"
1279 static UINT msi_dialog_maskedit_control( msi_dialog *dialog, MSIRECORD *rec )
1281 LPWSTR font_mask, val = NULL, font;
1282 struct msi_maskedit_info *info = NULL;
1283 UINT ret = ERROR_SUCCESS;
1284 msi_control *control;
1289 font_mask = msi_get_deformatted_field( dialog->package, rec, 10 );
1290 font = msi_dialog_get_style( font_mask, &mask );
1293 ERR("mask template is empty\n");
1297 info = msi_dialog_parse_groups( mask );
1300 ERR("template %s is invalid\n", debugstr_w(mask));
1304 info->dialog = dialog;
1306 control = msi_dialog_add_control( dialog, rec, szStatic,
1307 SS_OWNERDRAW | WS_GROUP | WS_VISIBLE );
1310 ERR("Failed to create maskedit container\n");
1311 ret = ERROR_FUNCTION_FAILED;
1314 SetWindowLongPtrW( control->hwnd, GWL_EXSTYLE, WS_EX_CONTROLPARENT );
1316 info->hwnd = control->hwnd;
1318 /* subclass the static control */
1319 info->oldproc = (WNDPROC) SetWindowLongPtrW( info->hwnd, GWLP_WNDPROC,
1320 (LONG_PTR)MSIMaskedEdit_WndProc );
1321 SetPropW( control->hwnd, szButtonData, info );
1323 prop = MSI_RecordGetString( rec, 9 );
1325 info->prop = strdupW( prop );
1327 msi_maskedit_create_children( info, font );
1331 val = msi_dup_property( dialog->package, prop );
1334 msi_maskedit_set_text( info, val );
1340 if( ret != ERROR_SUCCESS )
1342 msi_free( font_mask );
1347 /******************** Progress Bar *****************************************/
1349 static UINT msi_dialog_progress_bar( msi_dialog *dialog, MSIRECORD *rec )
1351 msi_dialog_add_control( dialog, rec, PROGRESS_CLASSW, WS_VISIBLE );
1352 return ERROR_SUCCESS;
1355 /******************** Path Edit ********************************************/
1357 static UINT msi_dialog_pathedit_control( msi_dialog *dialog, MSIRECORD *rec )
1359 FIXME("not implemented properly\n");
1360 return msi_dialog_edit_control( dialog, rec );
1363 /* radio buttons are a bit different from normal controls */
1364 static UINT msi_dialog_create_radiobutton( MSIRECORD *rec, LPVOID param )
1366 radio_button_group_descr *group = (radio_button_group_descr *)param;
1367 msi_dialog *dialog = group->dialog;
1368 msi_control *control;
1369 LPCWSTR prop, text, name;
1370 DWORD style, attributes = group->attributes;
1372 style = WS_CHILD | BS_AUTORADIOBUTTON | BS_MULTILINE | WS_TABSTOP;
1373 name = MSI_RecordGetString( rec, 3 );
1374 text = MSI_RecordGetString( rec, 8 );
1375 if( attributes & 1 )
1376 style |= WS_VISIBLE;
1377 if( ~attributes & 2 )
1378 style |= WS_DISABLED;
1380 control = msi_dialog_create_window( dialog, rec, 0, szButton, name, text,
1381 style, group->parent->hwnd );
1383 return ERROR_FUNCTION_FAILED;
1384 control->handler = msi_dialog_radiogroup_handler;
1386 if (!lstrcmpW(control->name, group->propval))
1387 SendMessageW(control->hwnd, BM_SETCHECK, BST_CHECKED, 0);
1389 prop = MSI_RecordGetString( rec, 1 );
1391 control->property = strdupW( prop );
1393 return ERROR_SUCCESS;
1396 static UINT msi_dialog_radiogroup_control( msi_dialog *dialog, MSIRECORD *rec )
1398 static const WCHAR query[] = {
1399 'S','E','L','E','C','T',' ','*',' ',
1400 'F','R','O','M',' ','R','a','d','i','o','B','u','t','t','o','n',' ',
1401 'W','H','E','R','E',' ',
1402 '`','P','r','o','p','e','r','t','y','`',' ','=',' ','\'','%','s','\'',0};
1405 msi_control *control;
1406 MSIQUERY *view = NULL;
1407 radio_button_group_descr group;
1408 MSIPACKAGE *package = dialog->package;
1411 prop = MSI_RecordGetString( rec, 9 );
1413 TRACE("%p %p %s\n", dialog, rec, debugstr_w( prop ));
1415 /* Create parent group box to hold radio buttons */
1416 control = msi_dialog_add_control( dialog, rec, szButton, BS_OWNERDRAW|WS_GROUP );
1418 return ERROR_FUNCTION_FAILED;
1420 oldproc = (WNDPROC) SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
1421 (LONG_PTR)MSIRadioGroup_WndProc );
1422 SetPropW(control->hwnd, szButtonData, oldproc);
1423 SetWindowLongPtrW( control->hwnd, GWL_EXSTYLE, WS_EX_CONTROLPARENT );
1426 control->property = strdupW( prop );
1428 /* query the Radio Button table for all control in this group */
1429 r = MSI_OpenQuery( package->db, &view, query, prop );
1430 if( r != ERROR_SUCCESS )
1432 ERR("query failed for dialog %s radio group %s\n",
1433 debugstr_w(dialog->name), debugstr_w(prop));
1434 return ERROR_INVALID_PARAMETER;
1437 group.dialog = dialog;
1438 group.parent = control;
1439 group.attributes = MSI_RecordGetInteger( rec, 8 );
1440 group.propval = msi_dup_property( dialog->package, control->property );
1442 r = MSI_IterateRecords( view, 0, msi_dialog_create_radiobutton, &group );
1443 msiobj_release( &view->hdr );
1444 msi_free( group.propval );
1449 /******************** Selection Tree ***************************************/
1451 struct msi_selection_tree_info
1459 msi_seltree_sync_item_state( HWND hwnd, MSIFEATURE *feature, HTREEITEM hItem )
1463 TRACE("Feature %s -> %d %d %d\n", debugstr_w(feature->Title),
1464 feature->Installed, feature->Action, feature->ActionRequest);
1466 tvi.mask = TVIF_STATE;
1468 tvi.state = INDEXTOSTATEIMAGEMASK( feature->Action );
1469 tvi.stateMask = TVIS_STATEIMAGEMASK;
1471 SendMessageW( hwnd, TVM_SETITEMW, 0, (LPARAM) &tvi );
1475 msi_seltree_popup_menu( HWND hwnd, INT x, INT y )
1480 /* create a menu to display */
1481 hMenu = CreatePopupMenu();
1483 /* FIXME: load strings from resources */
1484 AppendMenuA( hMenu, MF_ENABLED, INSTALLSTATE_LOCAL, "Install feature locally");
1485 AppendMenuA( hMenu, MF_GRAYED, 0x1000, "Install entire feature");
1486 AppendMenuA( hMenu, MF_ENABLED, INSTALLSTATE_ADVERTISED, "Install on demand");
1487 AppendMenuA( hMenu, MF_ENABLED, INSTALLSTATE_ABSENT, "Don't install");
1488 r = TrackPopupMenu( hMenu, TPM_LEFTALIGN | TPM_TOPALIGN | TPM_RETURNCMD,
1489 x, y, 0, hwnd, NULL );
1490 DestroyMenu( hMenu );
1495 msi_seltree_feature_from_item( HWND hwnd, HTREEITEM hItem )
1499 /* get the feature from the item */
1500 memset( &tvi, 0, sizeof tvi );
1502 tvi.mask = TVIF_PARAM | TVIF_HANDLE;
1503 SendMessageW( hwnd, TVM_GETITEMW, 0, (LPARAM) &tvi );
1505 return (MSIFEATURE*) tvi.lParam;
1509 msi_seltree_menu( HWND hwnd, HTREEITEM hItem )
1511 MSIFEATURE *feature;
1520 feature = msi_seltree_feature_from_item( hwnd, hItem );
1523 ERR("item %p feature was NULL\n", hItem);
1527 /* get the item's rectangle to put the menu just below it */
1529 SendMessageW( hwnd, TVM_GETITEMRECT, 0, (LPARAM) &u.rc );
1530 MapWindowPoints( hwnd, NULL, u.pt, 2 );
1532 r = msi_seltree_popup_menu( hwnd, u.rc.left, u.rc.top );
1536 case INSTALLSTATE_LOCAL:
1537 case INSTALLSTATE_ADVERTISED:
1538 case INSTALLSTATE_ABSENT:
1539 feature->ActionRequest = r;
1540 feature->Action = r;
1543 FIXME("select feature and all children\n");
1547 msi_seltree_sync_item_state( hwnd, feature, hItem );
1549 /* update the feature's components */
1550 LIST_FOR_EACH_ENTRY( cl, &feature->Components, ComponentList, entry )
1552 cl->component->Action = feature->Action;
1553 cl->component->ActionRequest = feature->ActionRequest;
1559 static LRESULT WINAPI
1560 MSISelectionTree_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
1562 struct msi_selection_tree_info *info;
1563 TVHITTESTINFO tvhti;
1566 TRACE("%p %04x %08x %08lx\n", hWnd, msg, wParam, lParam);
1568 info = GetPropW(hWnd, szButtonData);
1572 case WM_LBUTTONDOWN:
1573 tvhti.pt.x = LOWORD( lParam );
1574 tvhti.pt.y = HIWORD( lParam );
1577 r = CallWindowProcW(info->oldproc, hWnd, TVM_HITTEST, 0, (LPARAM) &tvhti );
1578 if (tvhti.flags & TVHT_ONITEMSTATEICON)
1579 return msi_seltree_menu( hWnd, tvhti.hItem );
1583 r = CallWindowProcW(info->oldproc, hWnd, msg, wParam, lParam);
1589 RemovePropW( hWnd, szButtonData );
1596 msi_seltree_add_child_features( MSIPACKAGE *package, HWND hwnd,
1597 LPCWSTR parent, HTREEITEM hParent )
1599 MSIFEATURE *feature;
1600 TVINSERTSTRUCTW tvis;
1603 LIST_FOR_EACH_ENTRY( feature, &package->features, MSIFEATURE, entry )
1605 if ( lstrcmpW( parent, feature->Feature_Parent ) )
1608 if ( !feature->Title )
1611 memset( &tvis, 0, sizeof tvis );
1612 tvis.hParent = hParent;
1613 tvis.hInsertAfter = TVI_LAST;
1614 tvis.u.item.mask = TVIF_TEXT | TVIF_PARAM;
1615 tvis.u.item.pszText = feature->Title;
1616 tvis.u.item.lParam = (LPARAM) feature;
1618 hitem = (HTREEITEM) SendMessageW( hwnd, TVM_INSERTITEMW, 0, (LPARAM) &tvis );
1622 msi_seltree_sync_item_state( hwnd, feature, hitem );
1623 msi_seltree_add_child_features( package, hwnd,
1624 feature->Feature, hitem );
1628 static void msi_seltree_create_imagelist( HWND hwnd )
1630 const int bm_width = 32, bm_height = 16, bm_count = 3;
1631 const int bm_resource = 0x1001;
1636 himl = ImageList_Create( bm_width, bm_height, FALSE, 4, 0 );
1639 ERR("failed to create image list\n");
1643 for (i=0; i<bm_count; i++)
1645 hbmp = LoadBitmapW( msi_hInstance, MAKEINTRESOURCEW(i+bm_resource) );
1648 ERR("failed to load bitmap %d\n", i);
1653 * Add a dummy bitmap at offset zero because the treeview
1654 * can't use it as a state mask (zero means no user state).
1657 ImageList_Add( himl, hbmp, NULL );
1659 ImageList_Add( himl, hbmp, NULL );
1662 SendMessageW( hwnd, TVM_SETIMAGELIST, TVSIL_STATE, (LPARAM)himl );
1665 static UINT msi_dialog_selection_tree( msi_dialog *dialog, MSIRECORD *rec )
1667 msi_control *control;
1669 MSIPACKAGE *package = dialog->package;
1671 struct msi_selection_tree_info *info;
1673 info = msi_alloc( sizeof *info );
1675 return ERROR_FUNCTION_FAILED;
1677 /* create the treeview control */
1678 prop = MSI_RecordGetString( rec, 9 );
1679 style = TVS_HASLINES | TVS_HASBUTTONS | TVS_LINESATROOT;
1680 style |= WS_GROUP | WS_VSCROLL;
1681 control = msi_dialog_add_control( dialog, rec, WC_TREEVIEWW, style );
1685 return ERROR_FUNCTION_FAILED;
1689 info->dialog = dialog;
1690 info->hwnd = control->hwnd;
1691 info->oldproc = (WNDPROC) SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
1692 (LONG_PTR)MSISelectionTree_WndProc );
1693 SetPropW( control->hwnd, szButtonData, info );
1696 msi_seltree_create_imagelist( control->hwnd );
1697 msi_seltree_add_child_features( package, control->hwnd, NULL, NULL );
1699 return ERROR_SUCCESS;
1702 /******************** Group Box ***************************************/
1704 static UINT msi_dialog_group_box( msi_dialog *dialog, MSIRECORD *rec )
1706 msi_control *control;
1709 style = BS_GROUPBOX | WS_CHILD | WS_GROUP;
1710 control = msi_dialog_add_control( dialog, rec, WC_BUTTONW, style );
1712 return ERROR_FUNCTION_FAILED;
1714 return ERROR_SUCCESS;
1717 /******************** List Box ***************************************/
1719 struct msi_listbox_item
1725 struct msi_listbox_info
1731 struct msi_listbox_item *items;
1734 static LRESULT WINAPI MSIListBox_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
1736 struct msi_listbox_info *info;
1740 TRACE("%p %04x %08x %08lx\n", hWnd, msg, wParam, lParam);
1742 info = GetPropW( hWnd, szButtonData );
1746 r = CallWindowProcW( info->oldproc, hWnd, msg, wParam, lParam );
1751 for (j = 0; j < info->num_items; j++)
1753 msi_free( info->items[j].property );
1754 msi_free( info->items[j].value );
1756 msi_free( info->items );
1758 RemovePropW( hWnd, szButtonData );
1765 static UINT msi_listbox_add_item( MSIRECORD *rec, LPVOID param )
1767 struct msi_listbox_info *info = param;
1768 struct msi_listbox_item *item;
1769 LPCWSTR property, value, text;
1770 static int index = 0;
1772 item = &info->items[index++];
1773 property = MSI_RecordGetString( rec, 1 );
1774 value = MSI_RecordGetString( rec, 3 );
1775 text = MSI_RecordGetString( rec, 4 );
1777 item->property = strdupW( property );
1778 item->value = strdupW( value );
1780 SendMessageW( info->hwnd, LB_ADDSTRING, 0, (LPARAM)text );
1782 return ERROR_SUCCESS;
1785 static UINT msi_listbox_add_items( struct msi_listbox_info *info )
1788 MSIQUERY *view = NULL;
1791 static const WCHAR query[] = {
1792 'S','E','L','E','C','T',' ','*',' ',
1793 'F','R','O','M',' ','`','L','i','s','t','B','o','x','`',' ',
1794 'O','R','D','E','R',' ','B','Y',' ','`','O','r','d','e','r','`',0
1797 r = MSI_OpenQuery( info->dialog->package->db, &view, query );
1798 if ( r != ERROR_SUCCESS )
1801 /* just get the number of records */
1802 r = MSI_IterateRecords( view, &count, NULL, NULL );
1804 info->num_items = count;
1805 info->items = msi_alloc( sizeof(*info->items) * count );
1807 r = MSI_IterateRecords( view, NULL, msi_listbox_add_item, info );
1808 msiobj_release( &view->hdr );
1813 static UINT msi_dialog_listbox_handler( msi_dialog *dialog,
1814 msi_control *control, WPARAM param )
1816 struct msi_listbox_info *info;
1819 if( HIWORD(param) != LBN_SELCHANGE )
1820 return ERROR_SUCCESS;
1822 info = GetPropW( control->hwnd, szButtonData );
1823 index = SendMessageW( control->hwnd, LB_GETCURSEL, 0, 0 );
1825 MSI_SetPropertyW( info->dialog->package,
1826 info->items[index].property, info->items[index].value );
1827 msi_dialog_evaluate_control_conditions( info->dialog );
1829 return ERROR_SUCCESS;
1832 static UINT msi_dialog_list_box( msi_dialog *dialog, MSIRECORD *rec )
1834 struct msi_listbox_info *info;
1835 msi_control *control;
1838 info = msi_alloc( sizeof *info );
1840 return ERROR_FUNCTION_FAILED;
1842 style = WS_TABSTOP | WS_GROUP | WS_CHILD | LBS_STANDARD;
1843 control = msi_dialog_add_control( dialog, rec, WC_LISTBOXW, style );
1845 return ERROR_FUNCTION_FAILED;
1847 control->handler = msi_dialog_listbox_handler;
1850 info->dialog = dialog;
1851 info->hwnd = control->hwnd;
1853 info->oldproc = (WNDPROC)SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
1854 (LONG_PTR)MSIListBox_WndProc );
1855 SetPropW( control->hwnd, szButtonData, info );
1857 msi_listbox_add_items( info );
1859 return ERROR_SUCCESS;
1862 static const struct control_handler msi_dialog_handler[] =
1864 { szText, msi_dialog_text_control },
1865 { szPushButton, msi_dialog_button_control },
1866 { szLine, msi_dialog_line_control },
1867 { szBitmap, msi_dialog_bitmap_control },
1868 { szCheckBox, msi_dialog_checkbox_control },
1869 { szScrollableText, msi_dialog_scrolltext_control },
1870 { szComboBox, msi_dialog_combo_control },
1871 { szEdit, msi_dialog_edit_control },
1872 { szMaskedEdit, msi_dialog_maskedit_control },
1873 { szPathEdit, msi_dialog_pathedit_control },
1874 { szProgressBar, msi_dialog_progress_bar },
1875 { szRadioButtonGroup, msi_dialog_radiogroup_control },
1876 { szIcon, msi_dialog_icon_control },
1877 { szSelectionTree, msi_dialog_selection_tree },
1878 { szGroupBox, msi_dialog_group_box },
1879 { szListBox, msi_dialog_list_box },
1882 #define NUM_CONTROL_TYPES (sizeof msi_dialog_handler/sizeof msi_dialog_handler[0])
1884 static UINT msi_dialog_create_controls( MSIRECORD *rec, LPVOID param )
1886 msi_dialog *dialog = param;
1887 LPCWSTR control_type;
1890 /* find and call the function that can create this type of control */
1891 control_type = MSI_RecordGetString( rec, 3 );
1892 for( i=0; i<NUM_CONTROL_TYPES; i++ )
1893 if (!strcmpiW( msi_dialog_handler[i].control_type, control_type ))
1895 if( i != NUM_CONTROL_TYPES )
1896 msi_dialog_handler[i].func( dialog, rec );
1898 ERR("no handler for element type %s\n", debugstr_w(control_type));
1900 return ERROR_SUCCESS;
1903 static UINT msi_dialog_fill_controls( msi_dialog *dialog )
1905 static const WCHAR query[] = {
1906 'S','E','L','E','C','T',' ','*',' ',
1907 'F','R','O','M',' ','C','o','n','t','r','o','l',' ',
1908 'W','H','E','R','E',' ',
1909 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',0};
1911 MSIQUERY *view = NULL;
1912 MSIPACKAGE *package = dialog->package;
1914 TRACE("%p %s\n", dialog, debugstr_w(dialog->name) );
1916 /* query the Control table for all the elements of the control */
1917 r = MSI_OpenQuery( package->db, &view, query, dialog->name );
1918 if( r != ERROR_SUCCESS )
1920 ERR("query failed for dialog %s\n", debugstr_w(dialog->name));
1921 return ERROR_INVALID_PARAMETER;
1924 r = MSI_IterateRecords( view, 0, msi_dialog_create_controls, dialog );
1925 msiobj_release( &view->hdr );
1930 static UINT msi_dialog_set_control_condition( MSIRECORD *rec, LPVOID param )
1932 static const WCHAR szHide[] = { 'H','i','d','e',0 };
1933 static const WCHAR szShow[] = { 'S','h','o','w',0 };
1934 static const WCHAR szDisable[] = { 'D','i','s','a','b','l','e',0 };
1935 static const WCHAR szEnable[] = { 'E','n','a','b','l','e',0 };
1936 msi_dialog *dialog = param;
1937 msi_control *control;
1938 LPCWSTR name, action, condition;
1941 name = MSI_RecordGetString( rec, 2 );
1942 action = MSI_RecordGetString( rec, 3 );
1943 condition = MSI_RecordGetString( rec, 4 );
1944 r = MSI_EvaluateConditionW( dialog->package, condition );
1945 control = msi_dialog_find_control( dialog, name );
1946 if( r == MSICONDITION_TRUE && control )
1948 TRACE("%s control %s\n", debugstr_w(action), debugstr_w(name));
1950 /* FIXME: case sensitive? */
1951 if(!lstrcmpW(action, szHide))
1952 ShowWindow(control->hwnd, SW_HIDE);
1953 else if(!strcmpW(action, szShow))
1954 ShowWindow(control->hwnd, SW_SHOW);
1955 else if(!strcmpW(action, szDisable))
1956 EnableWindow(control->hwnd, FALSE);
1957 else if(!strcmpW(action, szEnable))
1958 EnableWindow(control->hwnd, TRUE);
1960 FIXME("Unhandled action %s\n", debugstr_w(action));
1963 return ERROR_SUCCESS;
1966 static UINT msi_dialog_evaluate_control_conditions( msi_dialog *dialog )
1968 static const WCHAR query[] = {
1969 'S','E','L','E','C','T',' ','*',' ',
1970 'F','R','O','M',' ',
1971 'C','o','n','t','r','o','l','C','o','n','d','i','t','i','o','n',' ',
1972 'W','H','E','R','E',' ',
1973 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',0
1976 MSIQUERY *view = NULL;
1977 MSIPACKAGE *package = dialog->package;
1979 TRACE("%p %s\n", dialog, debugstr_w(dialog->name) );
1981 /* query the Control table for all the elements of the control */
1982 r = MSI_OpenQuery( package->db, &view, query, dialog->name );
1983 if( r != ERROR_SUCCESS )
1985 ERR("query failed for dialog %s\n", debugstr_w(dialog->name));
1986 return ERROR_INVALID_PARAMETER;
1989 r = MSI_IterateRecords( view, 0, msi_dialog_set_control_condition, dialog );
1990 msiobj_release( &view->hdr );
1995 UINT msi_dialog_reset( msi_dialog *dialog )
1997 /* FIXME: should restore the original values of any properties we changed */
1998 return msi_dialog_evaluate_control_conditions( dialog );
2001 /* figure out the height of 10 point MS Sans Serif */
2002 static INT msi_dialog_get_sans_serif_height( HWND hwnd )
2004 static const WCHAR szSansSerif[] = {
2005 'M','S',' ','S','a','n','s',' ','S','e','r','i','f',0 };
2010 HFONT hFont, hOldFont;
2013 hdc = GetDC( hwnd );
2016 memset( &lf, 0, sizeof lf );
2017 lf.lfHeight = MulDiv(10, GetDeviceCaps(hdc, LOGPIXELSY), 72);
2018 strcpyW( lf.lfFaceName, szSansSerif );
2019 hFont = CreateFontIndirectW(&lf);
2022 hOldFont = SelectObject( hdc, hFont );
2023 r = GetTextMetricsW( hdc, &tm );
2025 height = tm.tmHeight;
2026 SelectObject( hdc, hOldFont );
2027 DeleteObject( hFont );
2029 ReleaseDC( hwnd, hdc );
2034 /* fetch the associated record from the Dialog table */
2035 static MSIRECORD *msi_get_dialog_record( msi_dialog *dialog )
2037 static const WCHAR query[] = {
2038 'S','E','L','E','C','T',' ','*',' ',
2039 'F','R','O','M',' ','D','i','a','l','o','g',' ',
2040 'W','H','E','R','E',' ',
2041 '`','D','i','a','l','o','g','`',' ','=',' ','\'','%','s','\'',0};
2042 MSIPACKAGE *package = dialog->package;
2043 MSIRECORD *rec = NULL;
2045 TRACE("%p %s\n", dialog, debugstr_w(dialog->name) );
2047 rec = MSI_QueryGetRecord( package->db, query, dialog->name );
2049 ERR("query failed for dialog %s\n", debugstr_w(dialog->name));
2054 static void msi_dialog_adjust_dialog_size( msi_dialog *dialog, LPSIZE sz )
2059 /* turn the client size into the window rectangle */
2062 rect.right = msi_dialog_scale_unit( dialog, sz->cx );
2063 rect.bottom = msi_dialog_scale_unit( dialog, sz->cy );
2064 style = GetWindowLongPtrW( dialog->hwnd, GWL_STYLE );
2065 AdjustWindowRect( &rect, style, FALSE );
2066 sz->cx = rect.right - rect.left;
2067 sz->cy = rect.bottom - rect.top;
2070 static BOOL msi_control_set_next( msi_control *control, msi_control *next )
2072 return SetWindowPos( next->hwnd, control->hwnd, 0, 0, 0, 0,
2073 SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOREDRAW |
2074 SWP_NOREPOSITION | SWP_NOSENDCHANGING | SWP_NOSIZE );
2077 static UINT msi_dialog_set_tab_order( msi_dialog *dialog )
2079 msi_control *control, *tab_next;
2081 LIST_FOR_EACH_ENTRY( control, &dialog->controls, msi_control, entry )
2083 tab_next = msi_dialog_find_control( dialog, control->tabnext );
2086 msi_control_set_next( control, tab_next );
2089 return ERROR_SUCCESS;
2092 static void msi_dialog_set_first_control( msi_dialog* dialog, LPCWSTR name )
2094 msi_control *control;
2096 control = msi_dialog_find_control( dialog, name );
2098 dialog->hWndFocus = control->hwnd;
2100 dialog->hWndFocus = NULL;
2103 static LRESULT msi_dialog_oncreate( HWND hwnd, LPCREATESTRUCTW cs )
2105 static const WCHAR df[] = {
2106 'D','e','f','a','u','l','t','U','I','F','o','n','t',0 };
2107 static const WCHAR dfv[] = {
2108 'M','S',' ','S','h','e','l','l',' ','D','l','g',0 };
2109 msi_dialog *dialog = (msi_dialog*) cs->lpCreateParams;
2110 MSIRECORD *rec = NULL;
2111 LPWSTR title = NULL;
2114 TRACE("%p %p\n", dialog, dialog->package);
2116 dialog->hwnd = hwnd;
2117 SetWindowLongPtrW( hwnd, GWLP_USERDATA, (LONG_PTR) dialog );
2119 rec = msi_get_dialog_record( dialog );
2122 TRACE("No record found for dialog %s\n", debugstr_w(dialog->name));
2126 dialog->scale = msi_dialog_get_sans_serif_height(dialog->hwnd);
2128 size.cx = MSI_RecordGetInteger( rec, 4 );
2129 size.cy = MSI_RecordGetInteger( rec, 5 );
2130 msi_dialog_adjust_dialog_size( dialog, &size );
2132 dialog->attributes = MSI_RecordGetInteger( rec, 6 );
2134 dialog->default_font = msi_dup_property( dialog->package, df );
2135 if (!dialog->default_font)
2137 dialog->default_font = strdupW(dfv);
2138 if (!dialog->default_font) return -1;
2141 title = msi_get_deformatted_field( dialog->package, rec, 7 );
2142 SetWindowTextW( hwnd, title );
2145 SetWindowPos( hwnd, 0, 0, 0, size.cx, size.cy,
2146 SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOREDRAW );
2148 msi_dialog_build_font_list( dialog );
2149 msi_dialog_fill_controls( dialog );
2150 msi_dialog_evaluate_control_conditions( dialog );
2151 msi_dialog_set_tab_order( dialog );
2152 msi_dialog_set_first_control( dialog, MSI_RecordGetString( rec, 8 ) );
2153 msiobj_release( &rec->hdr );
2158 static UINT msi_dialog_send_event( msi_dialog *dialog, LPCWSTR event, LPCWSTR arg )
2160 LPWSTR event_fmt = NULL, arg_fmt = NULL;
2162 TRACE("Sending control event %s %s\n", debugstr_w(event), debugstr_w(arg));
2164 deformat_string( dialog->package, event, &event_fmt );
2165 deformat_string( dialog->package, arg, &arg_fmt );
2167 dialog->event_handler( dialog->package, event_fmt, arg_fmt, dialog );
2169 msi_free( event_fmt );
2170 msi_free( arg_fmt );
2172 return ERROR_SUCCESS;
2175 static UINT msi_dialog_set_property( msi_dialog *dialog, LPCWSTR event, LPCWSTR arg )
2177 static const WCHAR szNullArg[] = { '{','}',0 };
2178 LPWSTR p, prop, arg_fmt = NULL;
2181 len = strlenW(event);
2182 prop = msi_alloc( len*sizeof(WCHAR));
2183 strcpyW( prop, &event[1] );
2184 p = strchrW( prop, ']' );
2185 if( p && p[1] == 0 )
2188 if( strcmpW( szNullArg, arg ) )
2189 deformat_string( dialog->package, arg, &arg_fmt );
2190 MSI_SetPropertyW( dialog->package, prop, arg_fmt );
2191 msi_free( arg_fmt );
2194 ERR("Badly formatted property string - what happens?\n");
2196 return ERROR_SUCCESS;
2199 static UINT msi_dialog_control_event( MSIRECORD *rec, LPVOID param )
2201 msi_dialog *dialog = param;
2202 LPCWSTR condition, event, arg;
2205 condition = MSI_RecordGetString( rec, 5 );
2206 r = MSI_EvaluateConditionW( dialog->package, condition );
2207 if( r == MSICONDITION_TRUE || r == MSICONDITION_NONE )
2209 event = MSI_RecordGetString( rec, 3 );
2210 arg = MSI_RecordGetString( rec, 4 );
2211 if( event[0] == '[' )
2212 msi_dialog_set_property( dialog, event, arg );
2214 msi_dialog_send_event( dialog, event, arg );
2217 return ERROR_SUCCESS;
2220 static UINT msi_dialog_button_handler( msi_dialog *dialog,
2221 msi_control *control, WPARAM param )
2223 static const WCHAR query[] = {
2224 'S','E','L','E','C','T',' ','*',' ',
2225 'F','R','O','M',' ','C','o','n','t','r','o','l','E','v','e','n','t',' ',
2226 'W','H','E','R','E',' ',
2227 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',' ',
2229 '`','C','o','n','t','r','o','l','_','`',' ','=',' ','\'','%','s','\'',' ',
2230 'O','R','D','E','R',' ','B','Y',' ','`','O','r','d','e','r','i','n','g','`',0
2232 MSIQUERY *view = NULL;
2235 if( HIWORD(param) != BN_CLICKED )
2236 return ERROR_SUCCESS;
2238 r = MSI_OpenQuery( dialog->package->db, &view, query,
2239 dialog->name, control->name );
2240 if( r != ERROR_SUCCESS )
2242 ERR("query failed\n");
2246 r = MSI_IterateRecords( view, 0, msi_dialog_control_event, dialog );
2247 msiobj_release( &view->hdr );
2252 static UINT msi_dialog_get_checkbox_state( msi_dialog *dialog,
2253 msi_control *control )
2255 WCHAR state[2] = { 0 };
2258 MSI_GetPropertyW( dialog->package, control->property, state, &sz );
2259 return state[0] ? 1 : 0;
2262 static void msi_dialog_set_checkbox_state( msi_dialog *dialog,
2263 msi_control *control, UINT state )
2265 static const WCHAR szState[] = { '1', 0 };
2268 /* if uncheck then the property is set to NULL */
2271 MSI_SetPropertyW( dialog->package, control->property, NULL );
2275 /* check for a custom state */
2276 if (control->value && control->value[0])
2277 val = control->value;
2281 MSI_SetPropertyW( dialog->package, control->property, val );
2284 static void msi_dialog_checkbox_sync_state( msi_dialog *dialog,
2285 msi_control *control )
2289 state = msi_dialog_get_checkbox_state( dialog, control );
2290 SendMessageW( control->hwnd, BM_SETCHECK,
2291 state ? BST_CHECKED : BST_UNCHECKED, 0 );
2294 static UINT msi_dialog_checkbox_handler( msi_dialog *dialog,
2295 msi_control *control, WPARAM param )
2299 if( HIWORD(param) != BN_CLICKED )
2300 return ERROR_SUCCESS;
2302 TRACE("clicked checkbox %s, set %s\n", debugstr_w(control->name),
2303 debugstr_w(control->property));
2305 state = msi_dialog_get_checkbox_state( dialog, control );
2306 state = state ? 0 : 1;
2307 msi_dialog_set_checkbox_state( dialog, control, state );
2308 msi_dialog_checkbox_sync_state( dialog, control );
2310 return msi_dialog_button_handler( dialog, control, param );
2313 static UINT msi_dialog_edit_handler( msi_dialog *dialog,
2314 msi_control *control, WPARAM param )
2319 if( HIWORD(param) != EN_CHANGE )
2320 return ERROR_SUCCESS;
2322 TRACE("edit %s contents changed, set %s\n", debugstr_w(control->name),
2323 debugstr_w(control->property));
2326 buf = msi_alloc( sz*sizeof(WCHAR) );
2329 r = GetWindowTextW( control->hwnd, buf, sz );
2333 buf = msi_realloc( buf, sz*sizeof(WCHAR) );
2336 MSI_SetPropertyW( dialog->package, control->property, buf );
2340 return ERROR_SUCCESS;
2343 static UINT msi_dialog_radiogroup_handler( msi_dialog *dialog,
2344 msi_control *control, WPARAM param )
2346 if( HIWORD(param) != BN_CLICKED )
2347 return ERROR_SUCCESS;
2349 TRACE("clicked radio button %s, set %s\n", debugstr_w(control->name),
2350 debugstr_w(control->property));
2352 MSI_SetPropertyW( dialog->package, control->property, control->name );
2354 return msi_dialog_button_handler( dialog, control, param );
2357 static LRESULT msi_dialog_oncommand( msi_dialog *dialog, WPARAM param, HWND hwnd )
2359 msi_control *control = NULL;
2361 TRACE("%p %p %08x\n", dialog, hwnd, param);
2366 control = msi_dialog_find_control( dialog, dialog->control_default );
2368 case 2: /* escape */
2369 control = msi_dialog_find_control( dialog, dialog->control_cancel );
2372 control = msi_dialog_find_control_by_hwnd( dialog, hwnd );
2377 if( control->handler )
2379 control->handler( dialog, control, param );
2380 msi_dialog_evaluate_control_conditions( dialog );
2384 ERR("button click from nowhere %p %d %p\n", dialog, param, hwnd);
2388 static void msi_dialog_setfocus( msi_dialog *dialog )
2390 HWND hwnd = dialog->hWndFocus;
2392 hwnd = GetNextDlgTabItem( dialog->hwnd, hwnd, TRUE);
2393 hwnd = GetNextDlgTabItem( dialog->hwnd, hwnd, FALSE);
2395 dialog->hWndFocus = hwnd;
2398 static LRESULT WINAPI MSIDialog_WndProc( HWND hwnd, UINT msg,
2399 WPARAM wParam, LPARAM lParam )
2401 msi_dialog *dialog = (LPVOID) GetWindowLongPtrW( hwnd, GWLP_USERDATA );
2403 TRACE("0x%04x\n", msg);
2408 return msi_dialog_oncreate( hwnd, (LPCREATESTRUCTW)lParam );
2411 return msi_dialog_oncommand( dialog, wParam, (HWND)lParam );
2414 if( LOWORD(wParam) == WA_INACTIVE )
2415 dialog->hWndFocus = GetFocus();
2417 msi_dialog_setfocus( dialog );
2421 msi_dialog_setfocus( dialog );
2424 /* bounce back to our subclassed static control */
2425 case WM_CTLCOLORSTATIC:
2426 return SendMessageW( (HWND) lParam, WM_CTLCOLORSTATIC, wParam, lParam );
2429 dialog->hwnd = NULL;
2432 return DefWindowProcW(hwnd, msg, wParam, lParam);
2435 static BOOL CALLBACK msi_radioground_child_enum( HWND hWnd, LPARAM lParam )
2437 EnableWindow( hWnd, lParam );
2441 static LRESULT WINAPI MSIRadioGroup_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
2443 WNDPROC oldproc = (WNDPROC) GetPropW(hWnd, szButtonData);
2446 TRACE("hWnd %p msg %04x wParam 0x%08x lParam 0x%08lx\n", hWnd, msg, wParam, lParam);
2448 if (msg == WM_COMMAND) /* Forward notifications to dialog */
2449 SendMessageW(GetParent(hWnd), msg, wParam, lParam);
2451 r = CallWindowProcW(oldproc, hWnd, msg, wParam, lParam);
2453 /* make sure the radio buttons show as disabled if the parent is disabled */
2454 if (msg == WM_ENABLE)
2455 EnumChildWindows( hWnd, msi_radioground_child_enum, wParam );
2460 static LRESULT WINAPI MSIHiddenWindowProc( HWND hwnd, UINT msg,
2461 WPARAM wParam, LPARAM lParam )
2463 msi_dialog *dialog = (msi_dialog*) lParam;
2465 TRACE("%d %p\n", msg, dialog);
2469 case WM_MSI_DIALOG_CREATE:
2470 return msi_dialog_run_message_loop( dialog );
2471 case WM_MSI_DIALOG_DESTROY:
2472 msi_dialog_destroy( dialog );
2475 return DefWindowProcW( hwnd, msg, wParam, lParam );
2478 /* functions that interface to other modules within MSI */
2480 msi_dialog *msi_dialog_create( MSIPACKAGE* package, LPCWSTR szDialogName,
2481 msi_dialog_event_handler event_handler )
2483 MSIRECORD *rec = NULL;
2486 TRACE("%p %s\n", package, debugstr_w(szDialogName));
2488 /* allocate the structure for the dialog to use */
2489 dialog = msi_alloc_zero( sizeof *dialog + sizeof(WCHAR)*strlenW(szDialogName) );
2492 strcpyW( dialog->name, szDialogName );
2493 msiobj_addref( &package->hdr );
2494 dialog->package = package;
2495 dialog->event_handler = event_handler;
2496 dialog->finished = 0;
2497 list_init( &dialog->controls );
2499 /* verify that the dialog exists */
2500 rec = msi_get_dialog_record( dialog );
2503 msiobj_release( &package->hdr );
2507 dialog->attributes = MSI_RecordGetInteger( rec, 6 );
2508 dialog->control_default = strdupW( MSI_RecordGetString( rec, 9 ) );
2509 dialog->control_cancel = strdupW( MSI_RecordGetString( rec, 10 ) );
2510 msiobj_release( &rec->hdr );
2515 static void msi_process_pending_messages( HWND hdlg )
2519 while( PeekMessageW( &msg, 0, 0, 0, PM_REMOVE ) )
2521 if( hdlg && IsDialogMessageW( hdlg, &msg ))
2523 TranslateMessage( &msg );
2524 DispatchMessageW( &msg );
2528 void msi_dialog_end_dialog( msi_dialog *dialog )
2530 TRACE("%p\n", dialog);
2531 dialog->finished = 1;
2532 PostMessageW(dialog->hwnd, WM_NULL, 0, 0);
2535 void msi_dialog_check_messages( HANDLE handle )
2539 /* in threads other than the UI thread, block */
2540 if( uiThreadId != GetCurrentThreadId() )
2543 WaitForSingleObject( handle, INFINITE );
2547 /* there's two choices for the UI thread */
2550 msi_process_pending_messages( NULL );
2556 * block here until somebody creates a new dialog or
2557 * the handle we're waiting on becomes ready
2559 r = MsgWaitForMultipleObjects( 1, &handle, 0, INFINITE, QS_ALLINPUT );
2560 if( r == WAIT_OBJECT_0 )
2565 UINT msi_dialog_run_message_loop( msi_dialog *dialog )
2570 if( uiThreadId != GetCurrentThreadId() )
2571 return SendMessageW( hMsiHiddenWindow, WM_MSI_DIALOG_CREATE, 0, (LPARAM) dialog );
2573 /* create the dialog window, don't show it yet */
2574 style = WS_OVERLAPPED;
2575 if( dialog->attributes & msidbDialogAttributesVisible )
2576 style |= WS_VISIBLE;
2578 hwnd = CreateWindowW( szMsiDialogClass, dialog->name, style,
2579 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
2580 NULL, NULL, NULL, dialog );
2583 ERR("Failed to create dialog %s\n", debugstr_w( dialog->name ));
2584 return ERROR_FUNCTION_FAILED;
2587 ShowWindow( hwnd, SW_SHOW );
2588 /* UpdateWindow( hwnd ); - and causes the transparent static controls not to paint */
2590 if( dialog->attributes & msidbDialogAttributesModal )
2592 while( !dialog->finished )
2594 MsgWaitForMultipleObjects( 0, NULL, 0, INFINITE, QS_ALLEVENTS );
2595 msi_process_pending_messages( dialog->hwnd );
2599 return ERROR_IO_PENDING;
2601 return ERROR_SUCCESS;
2604 void msi_dialog_do_preview( msi_dialog *dialog )
2607 dialog->attributes |= msidbDialogAttributesVisible;
2608 dialog->attributes &= ~msidbDialogAttributesModal;
2609 msi_dialog_run_message_loop( dialog );
2612 void msi_dialog_destroy( msi_dialog *dialog )
2614 if( uiThreadId != GetCurrentThreadId() )
2616 SendMessageW( hMsiHiddenWindow, WM_MSI_DIALOG_DESTROY, 0, (LPARAM) dialog );
2621 ShowWindow( dialog->hwnd, SW_HIDE );
2624 DestroyWindow( dialog->hwnd );
2626 /* destroy the list of controls */
2627 while( !list_empty( &dialog->controls ) )
2629 msi_control *t = LIST_ENTRY( list_head( &dialog->controls ),
2630 msi_control, entry );
2631 list_remove( &t->entry );
2632 /* leave dialog->hwnd - destroying parent destroys child windows */
2633 msi_free( t->property );
2634 msi_free( t->value );
2636 DeleteObject( t->hBitmap );
2638 DestroyIcon( t->hIcon );
2639 msi_free( t->tabnext );
2642 FreeLibrary( t->hDll );
2645 /* destroy the list of fonts */
2646 while( dialog->font_list )
2648 msi_font *t = dialog->font_list;
2649 dialog->font_list = t->next;
2650 DeleteObject( t->hfont );
2653 msi_free( dialog->default_font );
2655 msi_free( dialog->control_default );
2656 msi_free( dialog->control_cancel );
2657 msiobj_release( &dialog->package->hdr );
2658 dialog->package = NULL;
2662 BOOL msi_dialog_register_class( void )
2666 ZeroMemory( &cls, sizeof cls );
2667 cls.lpfnWndProc = MSIDialog_WndProc;
2668 cls.hInstance = NULL;
2669 cls.hIcon = LoadIconW(0, (LPWSTR)IDI_APPLICATION);
2670 cls.hCursor = LoadCursorW(0, (LPWSTR)IDC_ARROW);
2671 cls.hbrBackground = (HBRUSH)(COLOR_3DFACE + 1);
2672 cls.lpszMenuName = NULL;
2673 cls.lpszClassName = szMsiDialogClass;
2675 if( !RegisterClassW( &cls ) )
2678 cls.lpfnWndProc = MSIHiddenWindowProc;
2679 cls.lpszClassName = szMsiHiddenWindow;
2681 if( !RegisterClassW( &cls ) )
2684 uiThreadId = GetCurrentThreadId();
2686 hMsiHiddenWindow = CreateWindowW( szMsiHiddenWindow, NULL, WS_OVERLAPPED,
2687 0, 0, 100, 100, NULL, NULL, NULL, NULL );
2688 if( !hMsiHiddenWindow )
2694 void msi_dialog_unregister_class( void )
2696 DestroyWindow( hMsiHiddenWindow );
2697 hMsiHiddenWindow = NULL;
2698 UnregisterClassW( szMsiDialogClass, NULL );
2699 UnregisterClassW( szMsiHiddenWindow, NULL );