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 if ( !feature->Display )
1614 memset( &tvis, 0, sizeof tvis );
1615 tvis.hParent = hParent;
1616 tvis.hInsertAfter = TVI_LAST;
1617 tvis.u.item.mask = TVIF_TEXT | TVIF_PARAM;
1618 tvis.u.item.pszText = feature->Title;
1619 tvis.u.item.lParam = (LPARAM) feature;
1621 hitem = (HTREEITEM) SendMessageW( hwnd, TVM_INSERTITEMW, 0, (LPARAM) &tvis );
1625 msi_seltree_sync_item_state( hwnd, feature, hitem );
1626 msi_seltree_add_child_features( package, hwnd,
1627 feature->Feature, hitem );
1629 /* the node is expanded if Display is odd */
1630 if ( feature->Display % 2 != 0 )
1631 SendMessageW( hwnd, TVM_EXPAND, TVE_EXPAND, (LPARAM) hitem );
1635 static void msi_seltree_create_imagelist( HWND hwnd )
1637 const int bm_width = 32, bm_height = 16, bm_count = 3;
1638 const int bm_resource = 0x1001;
1643 himl = ImageList_Create( bm_width, bm_height, FALSE, 4, 0 );
1646 ERR("failed to create image list\n");
1650 for (i=0; i<bm_count; i++)
1652 hbmp = LoadBitmapW( msi_hInstance, MAKEINTRESOURCEW(i+bm_resource) );
1655 ERR("failed to load bitmap %d\n", i);
1660 * Add a dummy bitmap at offset zero because the treeview
1661 * can't use it as a state mask (zero means no user state).
1664 ImageList_Add( himl, hbmp, NULL );
1666 ImageList_Add( himl, hbmp, NULL );
1669 SendMessageW( hwnd, TVM_SETIMAGELIST, TVSIL_STATE, (LPARAM)himl );
1672 static UINT msi_dialog_selection_tree( msi_dialog *dialog, MSIRECORD *rec )
1674 msi_control *control;
1676 MSIPACKAGE *package = dialog->package;
1678 struct msi_selection_tree_info *info;
1680 info = msi_alloc( sizeof *info );
1682 return ERROR_FUNCTION_FAILED;
1684 /* create the treeview control */
1685 prop = MSI_RecordGetString( rec, 9 );
1686 style = TVS_HASLINES | TVS_HASBUTTONS | TVS_LINESATROOT;
1687 style |= WS_GROUP | WS_VSCROLL;
1688 control = msi_dialog_add_control( dialog, rec, WC_TREEVIEWW, style );
1692 return ERROR_FUNCTION_FAILED;
1696 info->dialog = dialog;
1697 info->hwnd = control->hwnd;
1698 info->oldproc = (WNDPROC) SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
1699 (LONG_PTR)MSISelectionTree_WndProc );
1700 SetPropW( control->hwnd, szButtonData, info );
1703 msi_seltree_create_imagelist( control->hwnd );
1704 msi_seltree_add_child_features( package, control->hwnd, NULL, NULL );
1706 return ERROR_SUCCESS;
1709 /******************** Group Box ***************************************/
1711 static UINT msi_dialog_group_box( msi_dialog *dialog, MSIRECORD *rec )
1713 msi_control *control;
1716 style = BS_GROUPBOX | WS_CHILD | WS_GROUP;
1717 control = msi_dialog_add_control( dialog, rec, WC_BUTTONW, style );
1719 return ERROR_FUNCTION_FAILED;
1721 return ERROR_SUCCESS;
1724 /******************** List Box ***************************************/
1726 struct msi_listbox_item
1732 struct msi_listbox_info
1738 struct msi_listbox_item *items;
1741 static LRESULT WINAPI MSIListBox_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
1743 struct msi_listbox_info *info;
1747 TRACE("%p %04x %08x %08lx\n", hWnd, msg, wParam, lParam);
1749 info = GetPropW( hWnd, szButtonData );
1753 r = CallWindowProcW( info->oldproc, hWnd, msg, wParam, lParam );
1758 for (j = 0; j < info->num_items; j++)
1760 msi_free( info->items[j].property );
1761 msi_free( info->items[j].value );
1763 msi_free( info->items );
1765 RemovePropW( hWnd, szButtonData );
1772 static UINT msi_listbox_add_item( MSIRECORD *rec, LPVOID param )
1774 struct msi_listbox_info *info = param;
1775 struct msi_listbox_item *item;
1776 LPCWSTR property, value, text;
1777 static int index = 0;
1779 item = &info->items[index++];
1780 property = MSI_RecordGetString( rec, 1 );
1781 value = MSI_RecordGetString( rec, 3 );
1782 text = MSI_RecordGetString( rec, 4 );
1784 item->property = strdupW( property );
1785 item->value = strdupW( value );
1787 SendMessageW( info->hwnd, LB_ADDSTRING, 0, (LPARAM)text );
1789 return ERROR_SUCCESS;
1792 static UINT msi_listbox_add_items( struct msi_listbox_info *info )
1795 MSIQUERY *view = NULL;
1798 static const WCHAR query[] = {
1799 'S','E','L','E','C','T',' ','*',' ',
1800 'F','R','O','M',' ','`','L','i','s','t','B','o','x','`',' ',
1801 'O','R','D','E','R',' ','B','Y',' ','`','O','r','d','e','r','`',0
1804 r = MSI_OpenQuery( info->dialog->package->db, &view, query );
1805 if ( r != ERROR_SUCCESS )
1808 /* just get the number of records */
1809 r = MSI_IterateRecords( view, &count, NULL, NULL );
1811 info->num_items = count;
1812 info->items = msi_alloc( sizeof(*info->items) * count );
1814 r = MSI_IterateRecords( view, NULL, msi_listbox_add_item, info );
1815 msiobj_release( &view->hdr );
1820 static UINT msi_dialog_listbox_handler( msi_dialog *dialog,
1821 msi_control *control, WPARAM param )
1823 struct msi_listbox_info *info;
1826 if( HIWORD(param) != LBN_SELCHANGE )
1827 return ERROR_SUCCESS;
1829 info = GetPropW( control->hwnd, szButtonData );
1830 index = SendMessageW( control->hwnd, LB_GETCURSEL, 0, 0 );
1832 MSI_SetPropertyW( info->dialog->package,
1833 info->items[index].property, info->items[index].value );
1834 msi_dialog_evaluate_control_conditions( info->dialog );
1836 return ERROR_SUCCESS;
1839 static UINT msi_dialog_list_box( msi_dialog *dialog, MSIRECORD *rec )
1841 struct msi_listbox_info *info;
1842 msi_control *control;
1845 info = msi_alloc( sizeof *info );
1847 return ERROR_FUNCTION_FAILED;
1849 style = WS_TABSTOP | WS_GROUP | WS_CHILD | LBS_STANDARD;
1850 control = msi_dialog_add_control( dialog, rec, WC_LISTBOXW, style );
1852 return ERROR_FUNCTION_FAILED;
1854 control->handler = msi_dialog_listbox_handler;
1857 info->dialog = dialog;
1858 info->hwnd = control->hwnd;
1860 info->oldproc = (WNDPROC)SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
1861 (LONG_PTR)MSIListBox_WndProc );
1862 SetPropW( control->hwnd, szButtonData, info );
1864 msi_listbox_add_items( info );
1866 return ERROR_SUCCESS;
1869 static const struct control_handler msi_dialog_handler[] =
1871 { szText, msi_dialog_text_control },
1872 { szPushButton, msi_dialog_button_control },
1873 { szLine, msi_dialog_line_control },
1874 { szBitmap, msi_dialog_bitmap_control },
1875 { szCheckBox, msi_dialog_checkbox_control },
1876 { szScrollableText, msi_dialog_scrolltext_control },
1877 { szComboBox, msi_dialog_combo_control },
1878 { szEdit, msi_dialog_edit_control },
1879 { szMaskedEdit, msi_dialog_maskedit_control },
1880 { szPathEdit, msi_dialog_pathedit_control },
1881 { szProgressBar, msi_dialog_progress_bar },
1882 { szRadioButtonGroup, msi_dialog_radiogroup_control },
1883 { szIcon, msi_dialog_icon_control },
1884 { szSelectionTree, msi_dialog_selection_tree },
1885 { szGroupBox, msi_dialog_group_box },
1886 { szListBox, msi_dialog_list_box },
1889 #define NUM_CONTROL_TYPES (sizeof msi_dialog_handler/sizeof msi_dialog_handler[0])
1891 static UINT msi_dialog_create_controls( MSIRECORD *rec, LPVOID param )
1893 msi_dialog *dialog = param;
1894 LPCWSTR control_type;
1897 /* find and call the function that can create this type of control */
1898 control_type = MSI_RecordGetString( rec, 3 );
1899 for( i=0; i<NUM_CONTROL_TYPES; i++ )
1900 if (!strcmpiW( msi_dialog_handler[i].control_type, control_type ))
1902 if( i != NUM_CONTROL_TYPES )
1903 msi_dialog_handler[i].func( dialog, rec );
1905 ERR("no handler for element type %s\n", debugstr_w(control_type));
1907 return ERROR_SUCCESS;
1910 static UINT msi_dialog_fill_controls( msi_dialog *dialog )
1912 static const WCHAR query[] = {
1913 'S','E','L','E','C','T',' ','*',' ',
1914 'F','R','O','M',' ','C','o','n','t','r','o','l',' ',
1915 'W','H','E','R','E',' ',
1916 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',0};
1918 MSIQUERY *view = NULL;
1919 MSIPACKAGE *package = dialog->package;
1921 TRACE("%p %s\n", dialog, debugstr_w(dialog->name) );
1923 /* query the Control table for all the elements of the control */
1924 r = MSI_OpenQuery( package->db, &view, query, dialog->name );
1925 if( r != ERROR_SUCCESS )
1927 ERR("query failed for dialog %s\n", debugstr_w(dialog->name));
1928 return ERROR_INVALID_PARAMETER;
1931 r = MSI_IterateRecords( view, 0, msi_dialog_create_controls, dialog );
1932 msiobj_release( &view->hdr );
1937 static UINT msi_dialog_set_control_condition( MSIRECORD *rec, LPVOID param )
1939 static const WCHAR szHide[] = { 'H','i','d','e',0 };
1940 static const WCHAR szShow[] = { 'S','h','o','w',0 };
1941 static const WCHAR szDisable[] = { 'D','i','s','a','b','l','e',0 };
1942 static const WCHAR szEnable[] = { 'E','n','a','b','l','e',0 };
1943 msi_dialog *dialog = param;
1944 msi_control *control;
1945 LPCWSTR name, action, condition;
1948 name = MSI_RecordGetString( rec, 2 );
1949 action = MSI_RecordGetString( rec, 3 );
1950 condition = MSI_RecordGetString( rec, 4 );
1951 r = MSI_EvaluateConditionW( dialog->package, condition );
1952 control = msi_dialog_find_control( dialog, name );
1953 if( r == MSICONDITION_TRUE && control )
1955 TRACE("%s control %s\n", debugstr_w(action), debugstr_w(name));
1957 /* FIXME: case sensitive? */
1958 if(!lstrcmpW(action, szHide))
1959 ShowWindow(control->hwnd, SW_HIDE);
1960 else if(!strcmpW(action, szShow))
1961 ShowWindow(control->hwnd, SW_SHOW);
1962 else if(!strcmpW(action, szDisable))
1963 EnableWindow(control->hwnd, FALSE);
1964 else if(!strcmpW(action, szEnable))
1965 EnableWindow(control->hwnd, TRUE);
1967 FIXME("Unhandled action %s\n", debugstr_w(action));
1970 return ERROR_SUCCESS;
1973 static UINT msi_dialog_evaluate_control_conditions( msi_dialog *dialog )
1975 static const WCHAR query[] = {
1976 'S','E','L','E','C','T',' ','*',' ',
1977 'F','R','O','M',' ',
1978 'C','o','n','t','r','o','l','C','o','n','d','i','t','i','o','n',' ',
1979 'W','H','E','R','E',' ',
1980 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',0
1983 MSIQUERY *view = NULL;
1984 MSIPACKAGE *package = dialog->package;
1986 TRACE("%p %s\n", dialog, debugstr_w(dialog->name) );
1988 /* query the Control table for all the elements of the control */
1989 r = MSI_OpenQuery( package->db, &view, query, dialog->name );
1990 if( r != ERROR_SUCCESS )
1992 ERR("query failed for dialog %s\n", debugstr_w(dialog->name));
1993 return ERROR_INVALID_PARAMETER;
1996 r = MSI_IterateRecords( view, 0, msi_dialog_set_control_condition, dialog );
1997 msiobj_release( &view->hdr );
2002 UINT msi_dialog_reset( msi_dialog *dialog )
2004 /* FIXME: should restore the original values of any properties we changed */
2005 return msi_dialog_evaluate_control_conditions( dialog );
2008 /* figure out the height of 10 point MS Sans Serif */
2009 static INT msi_dialog_get_sans_serif_height( HWND hwnd )
2011 static const WCHAR szSansSerif[] = {
2012 'M','S',' ','S','a','n','s',' ','S','e','r','i','f',0 };
2017 HFONT hFont, hOldFont;
2020 hdc = GetDC( hwnd );
2023 memset( &lf, 0, sizeof lf );
2024 lf.lfHeight = MulDiv(10, GetDeviceCaps(hdc, LOGPIXELSY), 72);
2025 strcpyW( lf.lfFaceName, szSansSerif );
2026 hFont = CreateFontIndirectW(&lf);
2029 hOldFont = SelectObject( hdc, hFont );
2030 r = GetTextMetricsW( hdc, &tm );
2032 height = tm.tmHeight;
2033 SelectObject( hdc, hOldFont );
2034 DeleteObject( hFont );
2036 ReleaseDC( hwnd, hdc );
2041 /* fetch the associated record from the Dialog table */
2042 static MSIRECORD *msi_get_dialog_record( msi_dialog *dialog )
2044 static const WCHAR query[] = {
2045 'S','E','L','E','C','T',' ','*',' ',
2046 'F','R','O','M',' ','D','i','a','l','o','g',' ',
2047 'W','H','E','R','E',' ',
2048 '`','D','i','a','l','o','g','`',' ','=',' ','\'','%','s','\'',0};
2049 MSIPACKAGE *package = dialog->package;
2050 MSIRECORD *rec = NULL;
2052 TRACE("%p %s\n", dialog, debugstr_w(dialog->name) );
2054 rec = MSI_QueryGetRecord( package->db, query, dialog->name );
2056 ERR("query failed for dialog %s\n", debugstr_w(dialog->name));
2061 static void msi_dialog_adjust_dialog_size( msi_dialog *dialog, LPSIZE sz )
2066 /* turn the client size into the window rectangle */
2069 rect.right = msi_dialog_scale_unit( dialog, sz->cx );
2070 rect.bottom = msi_dialog_scale_unit( dialog, sz->cy );
2071 style = GetWindowLongPtrW( dialog->hwnd, GWL_STYLE );
2072 AdjustWindowRect( &rect, style, FALSE );
2073 sz->cx = rect.right - rect.left;
2074 sz->cy = rect.bottom - rect.top;
2077 static BOOL msi_control_set_next( msi_control *control, msi_control *next )
2079 return SetWindowPos( next->hwnd, control->hwnd, 0, 0, 0, 0,
2080 SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOREDRAW |
2081 SWP_NOREPOSITION | SWP_NOSENDCHANGING | SWP_NOSIZE );
2084 static UINT msi_dialog_set_tab_order( msi_dialog *dialog )
2086 msi_control *control, *tab_next;
2088 LIST_FOR_EACH_ENTRY( control, &dialog->controls, msi_control, entry )
2090 tab_next = msi_dialog_find_control( dialog, control->tabnext );
2093 msi_control_set_next( control, tab_next );
2096 return ERROR_SUCCESS;
2099 static void msi_dialog_set_first_control( msi_dialog* dialog, LPCWSTR name )
2101 msi_control *control;
2103 control = msi_dialog_find_control( dialog, name );
2105 dialog->hWndFocus = control->hwnd;
2107 dialog->hWndFocus = NULL;
2110 static LRESULT msi_dialog_oncreate( HWND hwnd, LPCREATESTRUCTW cs )
2112 static const WCHAR df[] = {
2113 'D','e','f','a','u','l','t','U','I','F','o','n','t',0 };
2114 static const WCHAR dfv[] = {
2115 'M','S',' ','S','h','e','l','l',' ','D','l','g',0 };
2116 msi_dialog *dialog = (msi_dialog*) cs->lpCreateParams;
2117 MSIRECORD *rec = NULL;
2118 LPWSTR title = NULL;
2121 TRACE("%p %p\n", dialog, dialog->package);
2123 dialog->hwnd = hwnd;
2124 SetWindowLongPtrW( hwnd, GWLP_USERDATA, (LONG_PTR) dialog );
2126 rec = msi_get_dialog_record( dialog );
2129 TRACE("No record found for dialog %s\n", debugstr_w(dialog->name));
2133 dialog->scale = msi_dialog_get_sans_serif_height(dialog->hwnd);
2135 size.cx = MSI_RecordGetInteger( rec, 4 );
2136 size.cy = MSI_RecordGetInteger( rec, 5 );
2137 msi_dialog_adjust_dialog_size( dialog, &size );
2139 dialog->attributes = MSI_RecordGetInteger( rec, 6 );
2141 dialog->default_font = msi_dup_property( dialog->package, df );
2142 if (!dialog->default_font)
2144 dialog->default_font = strdupW(dfv);
2145 if (!dialog->default_font) return -1;
2148 title = msi_get_deformatted_field( dialog->package, rec, 7 );
2149 SetWindowTextW( hwnd, title );
2152 SetWindowPos( hwnd, 0, 0, 0, size.cx, size.cy,
2153 SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOREDRAW );
2155 msi_dialog_build_font_list( dialog );
2156 msi_dialog_fill_controls( dialog );
2157 msi_dialog_evaluate_control_conditions( dialog );
2158 msi_dialog_set_tab_order( dialog );
2159 msi_dialog_set_first_control( dialog, MSI_RecordGetString( rec, 8 ) );
2160 msiobj_release( &rec->hdr );
2165 static UINT msi_dialog_send_event( msi_dialog *dialog, LPCWSTR event, LPCWSTR arg )
2167 LPWSTR event_fmt = NULL, arg_fmt = NULL;
2169 TRACE("Sending control event %s %s\n", debugstr_w(event), debugstr_w(arg));
2171 deformat_string( dialog->package, event, &event_fmt );
2172 deformat_string( dialog->package, arg, &arg_fmt );
2174 dialog->event_handler( dialog->package, event_fmt, arg_fmt, dialog );
2176 msi_free( event_fmt );
2177 msi_free( arg_fmt );
2179 return ERROR_SUCCESS;
2182 static UINT msi_dialog_set_property( msi_dialog *dialog, LPCWSTR event, LPCWSTR arg )
2184 static const WCHAR szNullArg[] = { '{','}',0 };
2185 LPWSTR p, prop, arg_fmt = NULL;
2188 len = strlenW(event);
2189 prop = msi_alloc( len*sizeof(WCHAR));
2190 strcpyW( prop, &event[1] );
2191 p = strchrW( prop, ']' );
2192 if( p && p[1] == 0 )
2195 if( strcmpW( szNullArg, arg ) )
2196 deformat_string( dialog->package, arg, &arg_fmt );
2197 MSI_SetPropertyW( dialog->package, prop, arg_fmt );
2198 msi_free( arg_fmt );
2201 ERR("Badly formatted property string - what happens?\n");
2203 return ERROR_SUCCESS;
2206 static UINT msi_dialog_control_event( MSIRECORD *rec, LPVOID param )
2208 msi_dialog *dialog = param;
2209 LPCWSTR condition, event, arg;
2212 condition = MSI_RecordGetString( rec, 5 );
2213 r = MSI_EvaluateConditionW( dialog->package, condition );
2214 if( r == MSICONDITION_TRUE || r == MSICONDITION_NONE )
2216 event = MSI_RecordGetString( rec, 3 );
2217 arg = MSI_RecordGetString( rec, 4 );
2218 if( event[0] == '[' )
2219 msi_dialog_set_property( dialog, event, arg );
2221 msi_dialog_send_event( dialog, event, arg );
2224 return ERROR_SUCCESS;
2227 static UINT msi_dialog_button_handler( msi_dialog *dialog,
2228 msi_control *control, WPARAM param )
2230 static const WCHAR query[] = {
2231 'S','E','L','E','C','T',' ','*',' ',
2232 'F','R','O','M',' ','C','o','n','t','r','o','l','E','v','e','n','t',' ',
2233 'W','H','E','R','E',' ',
2234 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',' ',
2236 '`','C','o','n','t','r','o','l','_','`',' ','=',' ','\'','%','s','\'',' ',
2237 'O','R','D','E','R',' ','B','Y',' ','`','O','r','d','e','r','i','n','g','`',0
2239 MSIQUERY *view = NULL;
2242 if( HIWORD(param) != BN_CLICKED )
2243 return ERROR_SUCCESS;
2245 r = MSI_OpenQuery( dialog->package->db, &view, query,
2246 dialog->name, control->name );
2247 if( r != ERROR_SUCCESS )
2249 ERR("query failed\n");
2253 r = MSI_IterateRecords( view, 0, msi_dialog_control_event, dialog );
2254 msiobj_release( &view->hdr );
2259 static UINT msi_dialog_get_checkbox_state( msi_dialog *dialog,
2260 msi_control *control )
2262 WCHAR state[2] = { 0 };
2265 MSI_GetPropertyW( dialog->package, control->property, state, &sz );
2266 return state[0] ? 1 : 0;
2269 static void msi_dialog_set_checkbox_state( msi_dialog *dialog,
2270 msi_control *control, UINT state )
2272 static const WCHAR szState[] = { '1', 0 };
2275 /* if uncheck then the property is set to NULL */
2278 MSI_SetPropertyW( dialog->package, control->property, NULL );
2282 /* check for a custom state */
2283 if (control->value && control->value[0])
2284 val = control->value;
2288 MSI_SetPropertyW( dialog->package, control->property, val );
2291 static void msi_dialog_checkbox_sync_state( msi_dialog *dialog,
2292 msi_control *control )
2296 state = msi_dialog_get_checkbox_state( dialog, control );
2297 SendMessageW( control->hwnd, BM_SETCHECK,
2298 state ? BST_CHECKED : BST_UNCHECKED, 0 );
2301 static UINT msi_dialog_checkbox_handler( msi_dialog *dialog,
2302 msi_control *control, WPARAM param )
2306 if( HIWORD(param) != BN_CLICKED )
2307 return ERROR_SUCCESS;
2309 TRACE("clicked checkbox %s, set %s\n", debugstr_w(control->name),
2310 debugstr_w(control->property));
2312 state = msi_dialog_get_checkbox_state( dialog, control );
2313 state = state ? 0 : 1;
2314 msi_dialog_set_checkbox_state( dialog, control, state );
2315 msi_dialog_checkbox_sync_state( dialog, control );
2317 return msi_dialog_button_handler( dialog, control, param );
2320 static UINT msi_dialog_edit_handler( msi_dialog *dialog,
2321 msi_control *control, WPARAM param )
2326 if( HIWORD(param) != EN_CHANGE )
2327 return ERROR_SUCCESS;
2329 TRACE("edit %s contents changed, set %s\n", debugstr_w(control->name),
2330 debugstr_w(control->property));
2333 buf = msi_alloc( sz*sizeof(WCHAR) );
2336 r = GetWindowTextW( control->hwnd, buf, sz );
2340 buf = msi_realloc( buf, sz*sizeof(WCHAR) );
2343 MSI_SetPropertyW( dialog->package, control->property, buf );
2347 return ERROR_SUCCESS;
2350 static UINT msi_dialog_radiogroup_handler( msi_dialog *dialog,
2351 msi_control *control, WPARAM param )
2353 if( HIWORD(param) != BN_CLICKED )
2354 return ERROR_SUCCESS;
2356 TRACE("clicked radio button %s, set %s\n", debugstr_w(control->name),
2357 debugstr_w(control->property));
2359 MSI_SetPropertyW( dialog->package, control->property, control->name );
2361 return msi_dialog_button_handler( dialog, control, param );
2364 static LRESULT msi_dialog_oncommand( msi_dialog *dialog, WPARAM param, HWND hwnd )
2366 msi_control *control = NULL;
2368 TRACE("%p %p %08x\n", dialog, hwnd, param);
2373 control = msi_dialog_find_control( dialog, dialog->control_default );
2375 case 2: /* escape */
2376 control = msi_dialog_find_control( dialog, dialog->control_cancel );
2379 control = msi_dialog_find_control_by_hwnd( dialog, hwnd );
2384 if( control->handler )
2386 control->handler( dialog, control, param );
2387 msi_dialog_evaluate_control_conditions( dialog );
2391 ERR("button click from nowhere %p %d %p\n", dialog, param, hwnd);
2395 static void msi_dialog_setfocus( msi_dialog *dialog )
2397 HWND hwnd = dialog->hWndFocus;
2399 hwnd = GetNextDlgTabItem( dialog->hwnd, hwnd, TRUE);
2400 hwnd = GetNextDlgTabItem( dialog->hwnd, hwnd, FALSE);
2402 dialog->hWndFocus = hwnd;
2405 static LRESULT WINAPI MSIDialog_WndProc( HWND hwnd, UINT msg,
2406 WPARAM wParam, LPARAM lParam )
2408 msi_dialog *dialog = (LPVOID) GetWindowLongPtrW( hwnd, GWLP_USERDATA );
2410 TRACE("0x%04x\n", msg);
2415 return msi_dialog_oncreate( hwnd, (LPCREATESTRUCTW)lParam );
2418 return msi_dialog_oncommand( dialog, wParam, (HWND)lParam );
2421 if( LOWORD(wParam) == WA_INACTIVE )
2422 dialog->hWndFocus = GetFocus();
2424 msi_dialog_setfocus( dialog );
2428 msi_dialog_setfocus( dialog );
2431 /* bounce back to our subclassed static control */
2432 case WM_CTLCOLORSTATIC:
2433 return SendMessageW( (HWND) lParam, WM_CTLCOLORSTATIC, wParam, lParam );
2436 dialog->hwnd = NULL;
2439 return DefWindowProcW(hwnd, msg, wParam, lParam);
2442 static BOOL CALLBACK msi_radioground_child_enum( HWND hWnd, LPARAM lParam )
2444 EnableWindow( hWnd, lParam );
2448 static LRESULT WINAPI MSIRadioGroup_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
2450 WNDPROC oldproc = (WNDPROC) GetPropW(hWnd, szButtonData);
2453 TRACE("hWnd %p msg %04x wParam 0x%08x lParam 0x%08lx\n", hWnd, msg, wParam, lParam);
2455 if (msg == WM_COMMAND) /* Forward notifications to dialog */
2456 SendMessageW(GetParent(hWnd), msg, wParam, lParam);
2458 r = CallWindowProcW(oldproc, hWnd, msg, wParam, lParam);
2460 /* make sure the radio buttons show as disabled if the parent is disabled */
2461 if (msg == WM_ENABLE)
2462 EnumChildWindows( hWnd, msi_radioground_child_enum, wParam );
2467 static LRESULT WINAPI MSIHiddenWindowProc( HWND hwnd, UINT msg,
2468 WPARAM wParam, LPARAM lParam )
2470 msi_dialog *dialog = (msi_dialog*) lParam;
2472 TRACE("%d %p\n", msg, dialog);
2476 case WM_MSI_DIALOG_CREATE:
2477 return msi_dialog_run_message_loop( dialog );
2478 case WM_MSI_DIALOG_DESTROY:
2479 msi_dialog_destroy( dialog );
2482 return DefWindowProcW( hwnd, msg, wParam, lParam );
2485 /* functions that interface to other modules within MSI */
2487 msi_dialog *msi_dialog_create( MSIPACKAGE* package, LPCWSTR szDialogName,
2488 msi_dialog_event_handler event_handler )
2490 MSIRECORD *rec = NULL;
2493 TRACE("%p %s\n", package, debugstr_w(szDialogName));
2495 /* allocate the structure for the dialog to use */
2496 dialog = msi_alloc_zero( sizeof *dialog + sizeof(WCHAR)*strlenW(szDialogName) );
2499 strcpyW( dialog->name, szDialogName );
2500 msiobj_addref( &package->hdr );
2501 dialog->package = package;
2502 dialog->event_handler = event_handler;
2503 dialog->finished = 0;
2504 list_init( &dialog->controls );
2506 /* verify that the dialog exists */
2507 rec = msi_get_dialog_record( dialog );
2510 msiobj_release( &package->hdr );
2514 dialog->attributes = MSI_RecordGetInteger( rec, 6 );
2515 dialog->control_default = strdupW( MSI_RecordGetString( rec, 9 ) );
2516 dialog->control_cancel = strdupW( MSI_RecordGetString( rec, 10 ) );
2517 msiobj_release( &rec->hdr );
2522 static void msi_process_pending_messages( HWND hdlg )
2526 while( PeekMessageW( &msg, 0, 0, 0, PM_REMOVE ) )
2528 if( hdlg && IsDialogMessageW( hdlg, &msg ))
2530 TranslateMessage( &msg );
2531 DispatchMessageW( &msg );
2535 void msi_dialog_end_dialog( msi_dialog *dialog )
2537 TRACE("%p\n", dialog);
2538 dialog->finished = 1;
2539 PostMessageW(dialog->hwnd, WM_NULL, 0, 0);
2542 void msi_dialog_check_messages( HANDLE handle )
2546 /* in threads other than the UI thread, block */
2547 if( uiThreadId != GetCurrentThreadId() )
2550 WaitForSingleObject( handle, INFINITE );
2554 /* there's two choices for the UI thread */
2557 msi_process_pending_messages( NULL );
2563 * block here until somebody creates a new dialog or
2564 * the handle we're waiting on becomes ready
2566 r = MsgWaitForMultipleObjects( 1, &handle, 0, INFINITE, QS_ALLINPUT );
2567 if( r == WAIT_OBJECT_0 )
2572 UINT msi_dialog_run_message_loop( msi_dialog *dialog )
2577 if( uiThreadId != GetCurrentThreadId() )
2578 return SendMessageW( hMsiHiddenWindow, WM_MSI_DIALOG_CREATE, 0, (LPARAM) dialog );
2580 /* create the dialog window, don't show it yet */
2581 style = WS_OVERLAPPED;
2582 if( dialog->attributes & msidbDialogAttributesVisible )
2583 style |= WS_VISIBLE;
2585 hwnd = CreateWindowW( szMsiDialogClass, dialog->name, style,
2586 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
2587 NULL, NULL, NULL, dialog );
2590 ERR("Failed to create dialog %s\n", debugstr_w( dialog->name ));
2591 return ERROR_FUNCTION_FAILED;
2594 ShowWindow( hwnd, SW_SHOW );
2595 /* UpdateWindow( hwnd ); - and causes the transparent static controls not to paint */
2597 if( dialog->attributes & msidbDialogAttributesModal )
2599 while( !dialog->finished )
2601 MsgWaitForMultipleObjects( 0, NULL, 0, INFINITE, QS_ALLEVENTS );
2602 msi_process_pending_messages( dialog->hwnd );
2606 return ERROR_IO_PENDING;
2608 return ERROR_SUCCESS;
2611 void msi_dialog_do_preview( msi_dialog *dialog )
2614 dialog->attributes |= msidbDialogAttributesVisible;
2615 dialog->attributes &= ~msidbDialogAttributesModal;
2616 msi_dialog_run_message_loop( dialog );
2619 void msi_dialog_destroy( msi_dialog *dialog )
2621 if( uiThreadId != GetCurrentThreadId() )
2623 SendMessageW( hMsiHiddenWindow, WM_MSI_DIALOG_DESTROY, 0, (LPARAM) dialog );
2628 ShowWindow( dialog->hwnd, SW_HIDE );
2631 DestroyWindow( dialog->hwnd );
2633 /* destroy the list of controls */
2634 while( !list_empty( &dialog->controls ) )
2636 msi_control *t = LIST_ENTRY( list_head( &dialog->controls ),
2637 msi_control, entry );
2638 list_remove( &t->entry );
2639 /* leave dialog->hwnd - destroying parent destroys child windows */
2640 msi_free( t->property );
2641 msi_free( t->value );
2643 DeleteObject( t->hBitmap );
2645 DestroyIcon( t->hIcon );
2646 msi_free( t->tabnext );
2649 FreeLibrary( t->hDll );
2652 /* destroy the list of fonts */
2653 while( dialog->font_list )
2655 msi_font *t = dialog->font_list;
2656 dialog->font_list = t->next;
2657 DeleteObject( t->hfont );
2660 msi_free( dialog->default_font );
2662 msi_free( dialog->control_default );
2663 msi_free( dialog->control_cancel );
2664 msiobj_release( &dialog->package->hdr );
2665 dialog->package = NULL;
2669 BOOL msi_dialog_register_class( void )
2673 ZeroMemory( &cls, sizeof cls );
2674 cls.lpfnWndProc = MSIDialog_WndProc;
2675 cls.hInstance = NULL;
2676 cls.hIcon = LoadIconW(0, (LPWSTR)IDI_APPLICATION);
2677 cls.hCursor = LoadCursorW(0, (LPWSTR)IDC_ARROW);
2678 cls.hbrBackground = (HBRUSH)(COLOR_3DFACE + 1);
2679 cls.lpszMenuName = NULL;
2680 cls.lpszClassName = szMsiDialogClass;
2682 if( !RegisterClassW( &cls ) )
2685 cls.lpfnWndProc = MSIHiddenWindowProc;
2686 cls.lpszClassName = szMsiHiddenWindow;
2688 if( !RegisterClassW( &cls ) )
2691 uiThreadId = GetCurrentThreadId();
2693 hMsiHiddenWindow = CreateWindowW( szMsiHiddenWindow, NULL, WS_OVERLAPPED,
2694 0, 0, 100, 100, NULL, NULL, NULL, NULL );
2695 if( !hMsiHiddenWindow )
2701 void msi_dialog_unregister_class( void )
2703 DestroyWindow( hMsiHiddenWindow );
2704 hMsiHiddenWindow = NULL;
2705 UnregisterClassW( szMsiDialogClass, NULL );
2706 UnregisterClassW( szMsiHiddenWindow, NULL );