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
42 #include "wine/debug.h"
43 #include "wine/unicode.h"
45 WINE_DEFAULT_DEBUG_CHANNEL(msi);
47 extern HINSTANCE msi_hInstance;
49 struct msi_control_tag;
50 typedef struct msi_control_tag msi_control;
51 typedef UINT (*msi_handler)( msi_dialog *, msi_control *, WPARAM );
52 typedef void (*msi_update)( msi_dialog *, msi_control * );
54 struct msi_control_tag
67 float progress_current;
69 BOOL progress_backwards;
74 typedef struct msi_font_tag
86 msi_dialog_event_handler event_handler;
96 LPWSTR control_default;
97 LPWSTR control_cancel;
101 typedef UINT (*msi_dialog_control_func)( msi_dialog *dialog, MSIRECORD *rec );
102 struct control_handler
104 LPCWSTR control_type;
105 msi_dialog_control_func func;
114 } radio_button_group_descr;
116 static const WCHAR szMsiDialogClass[] = { 'M','s','i','D','i','a','l','o','g','C','l','o','s','e','C','l','a','s','s',0 };
117 static const WCHAR szMsiHiddenWindow[] = { 'M','s','i','H','i','d','d','e','n','W','i','n','d','o','w',0 };
118 static const WCHAR szStatic[] = { 'S','t','a','t','i','c',0 };
119 static const WCHAR szButton[] = { 'B','U','T','T','O','N', 0 };
120 static const WCHAR szButtonData[] = { 'M','S','I','D','A','T','A',0 };
121 static const WCHAR szProgress[] = { 'P','r','o','g','r','e','s','s',0 };
122 static const WCHAR szText[] = { 'T','e','x','t',0 };
123 static const WCHAR szPushButton[] = { 'P','u','s','h','B','u','t','t','o','n',0 };
124 static const WCHAR szLine[] = { 'L','i','n','e',0 };
125 static const WCHAR szBitmap[] = { 'B','i','t','m','a','p',0 };
126 static const WCHAR szCheckBox[] = { 'C','h','e','c','k','B','o','x',0 };
127 static const WCHAR szScrollableText[] = { 'S','c','r','o','l','l','a','b','l','e','T','e','x','t',0 };
128 static const WCHAR szComboBox[] = { 'C','o','m','b','o','B','o','x',0 };
129 static const WCHAR szEdit[] = { 'E','d','i','t',0 };
130 static const WCHAR szMaskedEdit[] = { 'M','a','s','k','e','d','E','d','i','t',0 };
131 static const WCHAR szPathEdit[] = { 'P','a','t','h','E','d','i','t',0 };
132 static const WCHAR szProgressBar[] = { 'P','r','o','g','r','e','s','s','B','a','r',0 };
133 static const WCHAR szSetProgress[] = { 'S','e','t','P','r','o','g','r','e','s','s',0 };
134 static const WCHAR szRadioButtonGroup[] = { 'R','a','d','i','o','B','u','t','t','o','n','G','r','o','u','p',0 };
135 static const WCHAR szIcon[] = { 'I','c','o','n',0 };
136 static const WCHAR szSelectionTree[] = { '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 };
139 static const WCHAR szDirectoryCombo[] = { 'D','i','r','e','c','t','o','r','y','C','o','m','b','o',0 };
140 static const WCHAR szDirectoryList[] = { 'D','i','r','e','c','t','o','r','y','L','i','s','t',0 };
141 static const WCHAR szVolumeCostList[] = { 'V','o','l','u','m','e','C','o','s','t','L','i','s','t',0 };
142 static const WCHAR szVolumeSelectCombo[] = { 'V','o','l','u','m','e','S','e','l','e','c','t','C','o','m','b','o',0 };
143 static const WCHAR szSelectionDescription[] = {'S','e','l','e','c','t','i','o','n','D','e','s','c','r','i','p','t','i','o','n',0};
144 static const WCHAR szSelectionPath[] = {'S','e','l','e','c','t','i','o','n','P','a','t','h',0};
145 static const WCHAR szProperty[] = {'P','r','o','p','e','r','t','y',0};
147 /* dialog sequencing */
149 #define WM_MSI_DIALOG_CREATE (WM_USER+0x100)
150 #define WM_MSI_DIALOG_DESTROY (WM_USER+0x101)
152 #define USER_INSTALLSTATE_ALL 0x1000
154 static DWORD uiThreadId;
155 static HWND hMsiHiddenWindow;
157 static LPWSTR msi_get_window_text( HWND hwnd )
163 buf = msi_alloc( sz*sizeof(WCHAR) );
166 r = GetWindowTextW( hwnd, buf, sz );
170 buf = msi_realloc( buf, sz*sizeof(WCHAR) );
176 static INT msi_dialog_scale_unit( msi_dialog *dialog, INT val )
178 return MulDiv( val, dialog->scale, 12 );
181 static msi_control *msi_dialog_find_control( msi_dialog *dialog, LPCWSTR name )
183 msi_control *control;
189 LIST_FOR_EACH_ENTRY( control, &dialog->controls, msi_control, entry )
190 if( !strcmpW( control->name, name ) ) /* FIXME: case sensitive? */
195 static msi_control *msi_dialog_find_control_by_type( msi_dialog *dialog, LPCWSTR type )
197 msi_control *control;
203 LIST_FOR_EACH_ENTRY( control, &dialog->controls, msi_control, entry )
204 if( !strcmpW( control->type, type ) ) /* FIXME: case sensitive? */
209 static msi_control *msi_dialog_find_control_by_hwnd( msi_dialog *dialog, HWND hwnd )
211 msi_control *control;
215 LIST_FOR_EACH_ENTRY( control, &dialog->controls, msi_control, entry )
216 if( hwnd == control->hwnd )
221 static LPWSTR msi_get_deformatted_field( MSIPACKAGE *package, MSIRECORD *rec, int field )
223 LPCWSTR str = MSI_RecordGetString( rec, field );
227 deformat_string( package, str, &ret );
231 static LPWSTR msi_dialog_dup_property( msi_dialog *dialog, LPCWSTR property, BOOL indirect )
239 prop = msi_dup_property( dialog->package->db, property );
242 prop = strdupW( property );
247 msi_dialog *msi_dialog_get_parent( msi_dialog *dialog )
249 return dialog->parent;
252 LPWSTR msi_dialog_get_name( msi_dialog *dialog )
258 * msi_dialog_get_style
260 * Extract the {\style} string from the front of the text to display and
261 * update the pointer. Only the last style in a list is applied.
263 static LPWSTR msi_dialog_get_style( LPCWSTR p, LPCWSTR *rest )
274 while ((first = strchrW( p, '{' )) && (q = strchrW( first + 1, '}' )))
277 if( *p != '\\' && *p != '&' )
280 /* little bit of sanity checking to stop us getting confused with RTF */
281 for( i=++p; i<q; i++ )
282 if( *i == '}' || *i == '\\' )
292 ret = msi_alloc( len*sizeof(WCHAR) );
295 memcpy( ret, p, len*sizeof(WCHAR) );
300 static UINT msi_dialog_add_font( MSIRECORD *rec, LPVOID param )
302 msi_dialog *dialog = param;
309 /* create a font and add it to the list */
310 name = MSI_RecordGetString( rec, 1 );
311 font = msi_alloc( sizeof *font + strlenW( name )*sizeof (WCHAR) );
312 strcpyW( font->name, name );
313 list_add_head( &dialog->fonts, &font->entry );
315 font->color = MSI_RecordGetInteger( rec, 4 );
317 memset( &lf, 0, sizeof lf );
318 face = MSI_RecordGetString( rec, 2 );
319 lf.lfHeight = MSI_RecordGetInteger( rec, 3 );
320 style = MSI_RecordGetInteger( rec, 5 );
321 if( style & msidbTextStyleStyleBitsBold )
322 lf.lfWeight = FW_BOLD;
323 if( style & msidbTextStyleStyleBitsItalic )
325 if( style & msidbTextStyleStyleBitsUnderline )
326 lf.lfUnderline = TRUE;
327 if( style & msidbTextStyleStyleBitsStrike )
328 lf.lfStrikeOut = TRUE;
329 lstrcpynW( lf.lfFaceName, face, LF_FACESIZE );
331 /* adjust the height */
332 hdc = GetDC( dialog->hwnd );
335 lf.lfHeight = -MulDiv(lf.lfHeight, GetDeviceCaps(hdc, LOGPIXELSY), 72);
336 ReleaseDC( dialog->hwnd, hdc );
339 font->hfont = CreateFontIndirectW( &lf );
341 TRACE("Adding font style %s\n", debugstr_w(font->name) );
343 return ERROR_SUCCESS;
346 static msi_font *msi_dialog_find_font( msi_dialog *dialog, LPCWSTR name )
348 msi_font *font = NULL;
350 LIST_FOR_EACH_ENTRY( font, &dialog->fonts, msi_font, entry )
351 if( !strcmpW( font->name, name ) ) /* FIXME: case sensitive? */
357 static UINT msi_dialog_set_font( msi_dialog *dialog, HWND hwnd, LPCWSTR name )
361 font = msi_dialog_find_font( dialog, name );
363 SendMessageW( hwnd, WM_SETFONT, (WPARAM) font->hfont, TRUE );
365 ERR("No font entry for %s\n", debugstr_w(name));
366 return ERROR_SUCCESS;
369 static UINT msi_dialog_build_font_list( msi_dialog *dialog )
371 static const WCHAR query[] = {
372 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
373 '`','T','e','x','t','S','t','y','l','e','`',0};
377 TRACE("dialog %p\n", dialog );
379 r = MSI_OpenQuery( dialog->package->db, &view, query );
380 if( r != ERROR_SUCCESS )
383 r = MSI_IterateRecords( view, NULL, msi_dialog_add_font, dialog );
384 msiobj_release( &view->hdr );
388 static void msi_destroy_control( msi_control *t )
390 list_remove( &t->entry );
391 /* leave dialog->hwnd - destroying parent destroys child windows */
392 msi_free( t->property );
393 msi_free( t->value );
395 DeleteObject( t->hBitmap );
397 DestroyIcon( t->hIcon );
398 msi_free( t->tabnext );
401 FreeLibrary( t->hDll );
405 static msi_control *msi_dialog_create_window( msi_dialog *dialog,
406 MSIRECORD *rec, DWORD exstyle, LPCWSTR szCls, LPCWSTR name, LPCWSTR text,
407 DWORD style, HWND parent )
409 DWORD x, y, width, height;
410 LPWSTR font = NULL, title_font = NULL;
411 LPCWSTR title = NULL;
412 msi_control *control;
416 control = msi_alloc( sizeof *control + strlenW(name)*sizeof(WCHAR) );
420 strcpyW( control->name, name );
421 list_add_tail( &dialog->controls, &control->entry );
422 control->handler = NULL;
423 control->update = NULL;
424 control->property = NULL;
425 control->value = NULL;
426 control->hBitmap = NULL;
427 control->hIcon = NULL;
428 control->hDll = NULL;
429 control->tabnext = strdupW( MSI_RecordGetString( rec, 11) );
430 control->type = strdupW( MSI_RecordGetString( rec, 3 ) );
431 control->progress_current = 0;
432 control->progress_max = 100;
433 control->progress_backwards = FALSE;
435 x = MSI_RecordGetInteger( rec, 4 );
436 y = MSI_RecordGetInteger( rec, 5 );
437 width = MSI_RecordGetInteger( rec, 6 );
438 height = MSI_RecordGetInteger( rec, 7 );
440 x = msi_dialog_scale_unit( dialog, x );
441 y = msi_dialog_scale_unit( dialog, y );
442 width = msi_dialog_scale_unit( dialog, width );
443 height = msi_dialog_scale_unit( dialog, height );
447 deformat_string( dialog->package, text, &title_font );
448 font = msi_dialog_get_style( title_font, &title );
451 control->hwnd = CreateWindowExW( exstyle, szCls, title, style,
452 x, y, width, height, parent, NULL, NULL, NULL );
454 TRACE("Dialog %s control %s hwnd %p\n",
455 debugstr_w(dialog->name), debugstr_w(text), control->hwnd );
457 msi_dialog_set_font( dialog, control->hwnd,
458 font ? font : dialog->default_font );
460 msi_free( title_font );
466 static LPWSTR msi_dialog_get_uitext( msi_dialog *dialog, LPCWSTR key )
471 static const WCHAR query[] = {
472 's','e','l','e','c','t',' ','*',' ',
473 'f','r','o','m',' ','`','U','I','T','e','x','t','`',' ',
474 'w','h','e','r','e',' ','`','K','e','y','`',' ','=',' ','\'','%','s','\'',0
477 rec = MSI_QueryGetRecord( dialog->package->db, query, key );
478 if (!rec) return NULL;
479 text = strdupW( MSI_RecordGetString( rec, 2 ) );
480 msiobj_release( &rec->hdr );
484 static MSIRECORD *msi_get_binary_record( MSIDATABASE *db, LPCWSTR name )
486 static const WCHAR query[] = {
487 's','e','l','e','c','t',' ','*',' ',
488 'f','r','o','m',' ','B','i','n','a','r','y',' ',
489 'w','h','e','r','e',' ',
490 '`','N','a','m','e','`',' ','=',' ','\'','%','s','\'',0
493 return MSI_QueryGetRecord( db, query, name );
496 static LPWSTR msi_create_tmp_path(void)
502 r = GetTempPathW( MAX_PATH, tmp );
505 len = lstrlenW( tmp ) + 20;
506 path = msi_alloc( len * sizeof (WCHAR) );
509 r = GetTempFileNameW( tmp, szMsi, 0, path );
519 static HANDLE msi_load_image( MSIDATABASE *db, LPCWSTR name, UINT type,
520 UINT cx, UINT cy, UINT flags )
522 MSIRECORD *rec = NULL;
523 HANDLE himage = NULL;
527 TRACE("%p %s %u %u %08x\n", db, debugstr_w(name), cx, cy, flags);
529 tmp = msi_create_tmp_path();
533 rec = msi_get_binary_record( db, name );
536 r = MSI_RecordStreamToFile( rec, 2, tmp );
537 if( r == ERROR_SUCCESS )
539 himage = LoadImageW( 0, tmp, type, cx, cy, flags );
541 msiobj_release( &rec->hdr );
549 static HICON msi_load_icon( MSIDATABASE *db, LPCWSTR text, UINT attributes )
551 DWORD cx = 0, cy = 0, flags;
553 flags = LR_LOADFROMFILE | LR_DEFAULTSIZE;
554 if( attributes & msidbControlAttributesFixedSize )
556 flags &= ~LR_DEFAULTSIZE;
557 if( attributes & msidbControlAttributesIconSize16 )
562 if( attributes & msidbControlAttributesIconSize32 )
567 /* msidbControlAttributesIconSize48 handled by above logic */
569 return msi_load_image( db, text, IMAGE_ICON, cx, cy, flags );
572 static void msi_dialog_update_controls( msi_dialog *dialog, LPCWSTR property )
574 msi_control *control;
576 LIST_FOR_EACH_ENTRY( control, &dialog->controls, msi_control, entry )
578 if ( control->property && !strcmpW( control->property, property ) && control->update )
579 control->update( dialog, control );
583 static void msi_dialog_set_property( MSIPACKAGE *package, LPCWSTR property, LPCWSTR value )
585 UINT r = msi_set_property( package->db, property, value );
586 if (r == ERROR_SUCCESS && !strcmpW( property, szSourceDir ))
587 msi_reset_folders( package, TRUE );
590 static MSIFEATURE *msi_seltree_feature_from_item( HWND hwnd, HTREEITEM hItem )
594 /* get the feature from the item */
595 memset( &tvi, 0, sizeof tvi );
597 tvi.mask = TVIF_PARAM | TVIF_HANDLE;
598 SendMessageW( hwnd, TVM_GETITEMW, 0, (LPARAM)&tvi );
599 return (MSIFEATURE *)tvi.lParam;
602 struct msi_selection_tree_info
610 static MSIFEATURE *msi_seltree_get_selected_feature( msi_control *control )
612 struct msi_selection_tree_info *info = GetPropW( control->hwnd, szButtonData );
613 return msi_seltree_feature_from_item( control->hwnd, info->selected );
616 /* called from the Control Event subscription code */
617 void msi_dialog_handle_event( msi_dialog* dialog, LPCWSTR control,
618 LPCWSTR attribute, MSIRECORD *rec )
621 LPCWSTR font_text, text = NULL;
624 ctrl = msi_dialog_find_control( dialog, control );
627 if( !strcmpW( attribute, szText ) )
629 font_text = MSI_RecordGetString( rec , 1 );
630 font = msi_dialog_get_style( font_text, &text );
631 if (!text) text = szEmpty;
632 SetWindowTextW( ctrl->hwnd, text );
634 msi_dialog_check_messages( NULL );
636 else if( !strcmpW( attribute, szProgress ) )
638 DWORD func, val1, val2, units;
640 func = MSI_RecordGetInteger( rec, 1 );
641 val1 = MSI_RecordGetInteger( rec, 2 );
642 val2 = MSI_RecordGetInteger( rec, 3 );
644 TRACE("progress: func %u val1 %u val2 %u\n", func, val1, val2);
649 SendMessageW( ctrl->hwnd, PBM_SETRANGE, 0, MAKELPARAM(0,100) );
653 ctrl->progress_max = units ? units : 100;
654 ctrl->progress_current = units;
655 ctrl->progress_backwards = TRUE;
656 SendMessageW( ctrl->hwnd, PBM_SETPOS, 100, 0 );
660 ctrl->progress_max = units ? units : 100;
661 ctrl->progress_current = 0;
662 ctrl->progress_backwards = FALSE;
663 SendMessageW( ctrl->hwnd, PBM_SETPOS, 0, 0 );
666 case 1: /* FIXME: not sure what this is supposed to do */
670 if (ctrl->progress_backwards)
672 if (units >= ctrl->progress_current) ctrl->progress_current -= units;
673 else ctrl->progress_current = 0;
677 if (ctrl->progress_current + units < ctrl->progress_max) ctrl->progress_current += units;
678 else ctrl->progress_current = ctrl->progress_max;
680 SendMessageW( ctrl->hwnd, PBM_SETPOS, MulDiv(100, ctrl->progress_current, ctrl->progress_max), 0 );
683 FIXME("Unknown progress message %u\n", func);
687 else if ( !strcmpW( attribute, szProperty ) )
689 MSIFEATURE *feature = msi_seltree_get_selected_feature( ctrl );
690 msi_dialog_set_property( dialog->package, ctrl->property, feature->Directory );
692 else if ( !strcmpW( attribute, szSelectionPath ) )
694 LPWSTR path = msi_dialog_dup_property( dialog, ctrl->property, TRUE );
696 SetWindowTextW( ctrl->hwnd, path );
701 FIXME("Attribute %s not being set\n", debugstr_w(attribute));
706 static void msi_dialog_map_events(msi_dialog* dialog, LPCWSTR control)
708 static const WCHAR Query[] = {
709 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
710 '`','E','v','e','n','t','M','a','p','p','i','n','g','`',' ',
711 'W','H','E','R','E',' ',
712 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',' ',
714 '`','C','o','n','t','r','o','l','_','`',' ','=',' ','\'','%','s','\'',0
717 LPCWSTR event, attribute;
719 row = MSI_QueryGetRecord( dialog->package->db, Query, dialog->name, control );
723 event = MSI_RecordGetString( row, 3 );
724 attribute = MSI_RecordGetString( row, 4 );
725 ControlEvent_SubscribeToEvent( dialog->package, dialog, event, control, attribute );
726 msiobj_release( &row->hdr );
729 /* everything except radio buttons */
730 static msi_control *msi_dialog_add_control( msi_dialog *dialog,
731 MSIRECORD *rec, LPCWSTR szCls, DWORD style )
737 name = MSI_RecordGetString( rec, 2 );
738 attributes = MSI_RecordGetInteger( rec, 8 );
739 text = MSI_RecordGetString( rec, 10 );
741 TRACE("%s, %s, %08x, %s, %08x\n", debugstr_w(szCls), debugstr_w(name),
742 attributes, debugstr_w(text), style);
744 if( attributes & msidbControlAttributesVisible )
746 if( ~attributes & msidbControlAttributesEnabled )
747 style |= WS_DISABLED;
748 if( attributes & msidbControlAttributesSunken )
749 exstyle |= WS_EX_CLIENTEDGE;
751 msi_dialog_map_events(dialog, name);
753 return msi_dialog_create_window( dialog, rec, exstyle, szCls, name,
754 text, style, dialog->hwnd );
765 * we don't erase our own background,
766 * so we have to make sure that the parent window redraws first
768 static void msi_text_on_settext( HWND hWnd )
773 hParent = GetParent( hWnd );
774 GetWindowRect( hWnd, &rc );
775 MapWindowPoints( NULL, hParent, (LPPOINT) &rc, 2 );
776 InvalidateRect( hParent, &rc, TRUE );
779 static LRESULT WINAPI
780 MSIText_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
782 struct msi_text_info *info;
785 TRACE("%p %04x %08lx %08lx\n", hWnd, msg, wParam, lParam);
787 info = GetPropW(hWnd, szButtonData);
789 if( msg == WM_CTLCOLORSTATIC &&
790 ( info->attributes & msidbControlAttributesTransparent ) )
792 SetBkMode( (HDC)wParam, TRANSPARENT );
793 return (LRESULT) GetStockObject(NULL_BRUSH);
796 r = CallWindowProcW(info->oldproc, hWnd, msg, wParam, lParam);
798 SetTextColor( (HDC)wParam, info->font->color );
803 msi_text_on_settext( hWnd );
807 RemovePropW( hWnd, szButtonData );
814 static UINT msi_dialog_text_control( msi_dialog *dialog, MSIRECORD *rec )
816 msi_control *control;
817 struct msi_text_info *info;
818 LPCWSTR text, ptr, prop, control_name;
821 TRACE("%p %p\n", dialog, rec);
823 control = msi_dialog_add_control( dialog, rec, szStatic, SS_LEFT | WS_GROUP );
825 return ERROR_FUNCTION_FAILED;
827 info = msi_alloc( sizeof *info );
829 return ERROR_SUCCESS;
831 control_name = MSI_RecordGetString( rec, 2 );
832 control->attributes = MSI_RecordGetInteger( rec, 8 );
833 prop = MSI_RecordGetString( rec, 9 );
834 control->property = msi_dialog_dup_property( dialog, prop, FALSE );
836 text = MSI_RecordGetString( rec, 10 );
837 font_name = msi_dialog_get_style( text, &ptr );
838 info->font = ( font_name ) ? msi_dialog_find_font( dialog, font_name ) : NULL;
839 msi_free( font_name );
841 info->attributes = MSI_RecordGetInteger( rec, 8 );
842 if( info->attributes & msidbControlAttributesTransparent )
843 SetWindowLongPtrW( control->hwnd, GWL_EXSTYLE, WS_EX_TRANSPARENT );
845 info->oldproc = (WNDPROC) SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
846 (LONG_PTR)MSIText_WndProc );
847 SetPropW( control->hwnd, szButtonData, info );
849 ControlEvent_SubscribeToEvent( dialog->package, dialog,
850 szSelectionPath, control_name, szSelectionPath );
852 return ERROR_SUCCESS;
855 /* strip any leading text style label from text field */
856 static WCHAR *msi_get_binary_name( MSIPACKAGE *package, MSIRECORD *rec )
860 text = msi_get_deformatted_field( package, rec, 10 );
865 while (*p && *p != '{') p++;
866 if (!*p++) return text;
868 while (*p && *p != '}') p++;
869 if (!*p++) return text;
876 static UINT msi_dialog_set_property_event( msi_dialog *dialog, LPCWSTR event, LPCWSTR arg )
878 static const WCHAR szNullArg[] = {'{','}',0};
879 LPWSTR p, prop, arg_fmt = NULL;
882 len = strlenW( event );
883 prop = msi_alloc( len * sizeof(WCHAR) );
884 strcpyW( prop, &event[1] );
885 p = strchrW( prop, ']' );
886 if (p && (p[1] == 0 || p[1] == ' '))
889 if (strcmpW( szNullArg, arg ))
890 deformat_string( dialog->package, arg, &arg_fmt );
891 msi_dialog_set_property( dialog->package, prop, arg_fmt );
892 msi_dialog_update_controls( dialog, prop );
895 else ERR("Badly formatted property string - what happens?\n");
897 return ERROR_SUCCESS;
900 static UINT msi_dialog_send_event( msi_dialog *dialog, LPCWSTR event, LPCWSTR arg )
902 LPWSTR event_fmt = NULL, arg_fmt = NULL;
904 TRACE("Sending control event %s %s\n", debugstr_w(event), debugstr_w(arg));
906 deformat_string( dialog->package, event, &event_fmt );
907 deformat_string( dialog->package, arg, &arg_fmt );
909 dialog->event_handler( dialog->package, event_fmt, arg_fmt, dialog );
911 msi_free( event_fmt );
914 return ERROR_SUCCESS;
917 static UINT msi_dialog_control_event( MSIRECORD *rec, LPVOID param )
919 msi_dialog *dialog = param;
920 LPCWSTR condition, event, arg;
923 condition = MSI_RecordGetString( rec, 5 );
924 r = MSI_EvaluateConditionW( dialog->package, condition );
925 if (r == MSICONDITION_TRUE || r == MSICONDITION_NONE)
927 event = MSI_RecordGetString( rec, 3 );
928 arg = MSI_RecordGetString( rec, 4 );
930 msi_dialog_set_property_event( dialog, event, arg );
932 msi_dialog_send_event( dialog, event, arg );
934 return ERROR_SUCCESS;
937 static UINT msi_dialog_button_handler( msi_dialog *dialog, msi_control *control, WPARAM param )
939 static const WCHAR query[] = {
940 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
941 'C','o','n','t','r','o','l','E','v','e','n','t',' ','W','H','E','R','E',' ',
942 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',' ','A','N','D',' ',
943 '`','C','o','n','t','r','o','l','_','`',' ','=',' ','\'','%','s','\'',' ',
944 'O','R','D','E','R',' ','B','Y',' ','`','O','r','d','e','r','i','n','g','`',0};
948 if (HIWORD(param) != BN_CLICKED)
949 return ERROR_SUCCESS;
951 r = MSI_OpenQuery( dialog->package->db, &view, query, dialog->name, control->name );
952 if (r != ERROR_SUCCESS)
954 ERR("query failed\n");
955 return ERROR_SUCCESS;
957 r = MSI_IterateRecords( view, 0, msi_dialog_control_event, dialog );
958 msiobj_release( &view->hdr );
962 static UINT msi_dialog_button_control( msi_dialog *dialog, MSIRECORD *rec )
964 msi_control *control;
965 UINT attributes, style;
967 TRACE("%p %p\n", dialog, rec);
970 attributes = MSI_RecordGetInteger( rec, 8 );
971 if( attributes & msidbControlAttributesIcon )
974 control = msi_dialog_add_control( dialog, rec, szButton, style );
976 return ERROR_FUNCTION_FAILED;
978 control->handler = msi_dialog_button_handler;
980 if (attributes & msidbControlAttributesIcon)
983 LPWSTR name = msi_get_binary_name( dialog->package, rec );
984 control->hIcon = msi_load_icon( dialog->package->db, name, attributes );
987 SendMessageW( control->hwnd, BM_SETIMAGE, IMAGE_ICON, (LPARAM) control->hIcon );
990 ERR("Failed to load icon %s\n", debugstr_w(name));
994 return ERROR_SUCCESS;
997 static LPWSTR msi_get_checkbox_value( msi_dialog *dialog, LPCWSTR prop )
999 static const WCHAR query[] = {
1000 'S','E','L','E','C','T',' ','*',' ',
1001 'F','R','O','M',' ','`','C','h','e','c','k','B','o','x','`',' ',
1002 'W','H','E','R','E',' ',
1003 '`','P','r','o','p','e','r','t','y','`',' ','=',' ',
1006 MSIRECORD *rec = NULL;
1009 /* find if there is a value associated with the checkbox */
1010 rec = MSI_QueryGetRecord( dialog->package->db, query, prop );
1014 ret = msi_get_deformatted_field( dialog->package, rec, 2 );
1015 if( ret && !ret[0] )
1020 msiobj_release( &rec->hdr );
1024 ret = msi_dup_property( dialog->package->db, prop );
1025 if( ret && !ret[0] )
1034 static UINT msi_dialog_get_checkbox_state( msi_dialog *dialog, msi_control *control )
1036 WCHAR state[2] = {0};
1039 msi_get_property( dialog->package->db, control->property, state, &sz );
1040 return state[0] ? 1 : 0;
1043 static void msi_dialog_set_checkbox_state( msi_dialog *dialog, msi_control *control, UINT state )
1045 static const WCHAR szState[] = {'1',0};
1048 /* if uncheck then the property is set to NULL */
1051 msi_dialog_set_property( dialog->package, control->property, NULL );
1055 /* check for a custom state */
1056 if (control->value && control->value[0])
1057 val = control->value;
1061 msi_dialog_set_property( dialog->package, control->property, val );
1064 static void msi_dialog_checkbox_sync_state( msi_dialog *dialog, msi_control *control )
1066 UINT state = msi_dialog_get_checkbox_state( dialog, control );
1067 SendMessageW( control->hwnd, BM_SETCHECK, state ? BST_CHECKED : BST_UNCHECKED, 0 );
1070 static UINT msi_dialog_checkbox_handler( msi_dialog *dialog, msi_control *control, WPARAM param )
1074 if (HIWORD(param) != BN_CLICKED)
1075 return ERROR_SUCCESS;
1077 TRACE("clicked checkbox %s, set %s\n", debugstr_w(control->name), debugstr_w(control->property));
1079 state = msi_dialog_get_checkbox_state( dialog, control );
1080 state = state ? 0 : 1;
1081 msi_dialog_set_checkbox_state( dialog, control, state );
1082 msi_dialog_checkbox_sync_state( dialog, control );
1084 return msi_dialog_button_handler( dialog, control, param );
1087 static UINT msi_dialog_checkbox_control( msi_dialog *dialog, MSIRECORD *rec )
1089 msi_control *control;
1092 TRACE("%p %p\n", dialog, rec);
1094 control = msi_dialog_add_control( dialog, rec, szButton, BS_CHECKBOX | BS_MULTILINE | WS_TABSTOP );
1095 control->handler = msi_dialog_checkbox_handler;
1096 control->update = msi_dialog_checkbox_sync_state;
1097 prop = MSI_RecordGetString( rec, 9 );
1100 control->property = strdupW( prop );
1101 control->value = msi_get_checkbox_value( dialog, prop );
1102 TRACE("control %s value %s\n", debugstr_w(control->property), debugstr_w(control->value));
1104 msi_dialog_checkbox_sync_state( dialog, control );
1105 return ERROR_SUCCESS;
1108 static UINT msi_dialog_line_control( msi_dialog *dialog, MSIRECORD *rec )
1112 DWORD style, exstyle = 0;
1113 DWORD x, y, width, height;
1114 msi_control *control;
1116 TRACE("%p %p\n", dialog, rec);
1118 style = WS_CHILD | SS_ETCHEDHORZ | SS_SUNKEN;
1120 name = MSI_RecordGetString( rec, 2 );
1121 attributes = MSI_RecordGetInteger( rec, 8 );
1123 if( attributes & msidbControlAttributesVisible )
1124 style |= WS_VISIBLE;
1125 if( ~attributes & msidbControlAttributesEnabled )
1126 style |= WS_DISABLED;
1127 if( attributes & msidbControlAttributesSunken )
1128 exstyle |= WS_EX_CLIENTEDGE;
1130 msi_dialog_map_events(dialog, name);
1132 control = msi_alloc( sizeof(*control) + strlenW(name) * sizeof(WCHAR) );
1134 return ERROR_OUTOFMEMORY;
1136 strcpyW( control->name, name );
1137 list_add_head( &dialog->controls, &control->entry );
1138 control->handler = NULL;
1139 control->property = NULL;
1140 control->value = NULL;
1141 control->hBitmap = NULL;
1142 control->hIcon = NULL;
1143 control->hDll = NULL;
1144 control->tabnext = strdupW( MSI_RecordGetString( rec, 11) );
1145 control->type = strdupW( MSI_RecordGetString( rec, 3 ) );
1146 control->progress_current = 0;
1147 control->progress_max = 100;
1148 control->progress_backwards = FALSE;
1150 x = MSI_RecordGetInteger( rec, 4 );
1151 y = MSI_RecordGetInteger( rec, 5 );
1152 width = MSI_RecordGetInteger( rec, 6 );
1154 x = msi_dialog_scale_unit( dialog, x );
1155 y = msi_dialog_scale_unit( dialog, y );
1156 width = msi_dialog_scale_unit( dialog, width );
1157 height = 2; /* line is exactly 2 units in height */
1159 control->hwnd = CreateWindowExW( exstyle, szStatic, NULL, style,
1160 x, y, width, height, dialog->hwnd, NULL, NULL, NULL );
1162 TRACE("Dialog %s control %s hwnd %p\n",
1163 debugstr_w(dialog->name), debugstr_w(name), control->hwnd );
1165 return ERROR_SUCCESS;
1168 /******************** Scroll Text ********************************************/
1170 struct msi_scrolltext_info
1173 msi_control *control;
1177 static LRESULT WINAPI
1178 MSIScrollText_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
1180 struct msi_scrolltext_info *info;
1183 TRACE("%p %04x %08lx %08lx\n", hWnd, msg, wParam, lParam);
1185 info = GetPropW( hWnd, szButtonData );
1187 r = CallWindowProcW( info->oldproc, hWnd, msg, wParam, lParam );
1192 return DLGC_WANTARROWS;
1195 RemovePropW( hWnd, szButtonData );
1198 /* native MSI sets a wait cursor here */
1199 msi_dialog_button_handler( info->dialog, info->control, BN_CLICKED );
1205 struct msi_streamin_info
1212 static DWORD CALLBACK
1213 msi_richedit_stream_in( DWORD_PTR arg, LPBYTE buffer, LONG count, LONG *pcb )
1215 struct msi_streamin_info *info = (struct msi_streamin_info*) arg;
1217 if( (count + info->offset) > info->length )
1218 count = info->length - info->offset;
1219 memcpy( buffer, &info->string[ info->offset ], count );
1221 info->offset += count;
1223 TRACE("%d/%d\n", info->offset, info->length);
1228 static void msi_scrolltext_add_text( msi_control *control, LPCWSTR text )
1230 struct msi_streamin_info info;
1233 info.string = strdupWtoA( text );
1235 info.length = lstrlenA( info.string ) + 1;
1237 es.dwCookie = (DWORD_PTR) &info;
1239 es.pfnCallback = msi_richedit_stream_in;
1241 SendMessageW( control->hwnd, EM_STREAMIN, SF_RTF, (LPARAM) &es );
1243 msi_free( info.string );
1246 static UINT msi_dialog_scrolltext_control( msi_dialog *dialog, MSIRECORD *rec )
1248 static const WCHAR szRichEdit20W[] = {'R','i','c','h','E','d','i','t','2','0','W',0};
1249 struct msi_scrolltext_info *info;
1250 msi_control *control;
1255 info = msi_alloc( sizeof *info );
1257 return ERROR_FUNCTION_FAILED;
1259 hRichedit = LoadLibraryA("riched20");
1261 style = WS_BORDER | ES_MULTILINE | WS_VSCROLL |
1262 ES_READONLY | ES_AUTOVSCROLL | WS_TABSTOP;
1263 control = msi_dialog_add_control( dialog, rec, szRichEdit20W, style );
1266 FreeLibrary( hRichedit );
1268 return ERROR_FUNCTION_FAILED;
1271 control->hDll = hRichedit;
1273 info->dialog = dialog;
1274 info->control = control;
1276 /* subclass the static control */
1277 info->oldproc = (WNDPROC) SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
1278 (LONG_PTR)MSIScrollText_WndProc );
1279 SetPropW( control->hwnd, szButtonData, info );
1281 /* add the text into the richedit */
1282 text = MSI_RecordGetString( rec, 10 );
1284 msi_scrolltext_add_text( control, text );
1286 return ERROR_SUCCESS;
1289 static HBITMAP msi_load_picture( MSIDATABASE *db, LPCWSTR name,
1290 INT cx, INT cy, DWORD flags )
1292 HBITMAP hOleBitmap = 0, hBitmap = 0, hOldSrcBitmap, hOldDestBitmap;
1293 MSIRECORD *rec = NULL;
1294 IStream *stm = NULL;
1295 IPicture *pic = NULL;
1300 rec = msi_get_binary_record( db, name );
1304 r = MSI_RecordGetIStream( rec, 2, &stm );
1305 msiobj_release( &rec->hdr );
1306 if( r != ERROR_SUCCESS )
1309 r = OleLoadPicture( stm, 0, TRUE, &IID_IPicture, (LPVOID*) &pic );
1310 IStream_Release( stm );
1313 ERR("failed to load picture\n");
1317 r = IPicture_get_Handle( pic, (OLE_HANDLE*) &hOleBitmap );
1320 ERR("failed to get bitmap handle\n");
1324 /* make the bitmap the desired size */
1325 r = GetObjectW( hOleBitmap, sizeof bm, &bm );
1326 if (r != sizeof bm )
1328 ERR("failed to get bitmap size\n");
1332 if (flags & LR_DEFAULTSIZE)
1338 srcdc = CreateCompatibleDC( NULL );
1339 hOldSrcBitmap = SelectObject( srcdc, hOleBitmap );
1340 destdc = CreateCompatibleDC( NULL );
1341 hBitmap = CreateCompatibleBitmap( srcdc, cx, cy );
1342 hOldDestBitmap = SelectObject( destdc, hBitmap );
1343 StretchBlt( destdc, 0, 0, cx, cy,
1344 srcdc, 0, 0, bm.bmWidth, bm.bmHeight, SRCCOPY);
1345 SelectObject( srcdc, hOldSrcBitmap );
1346 SelectObject( destdc, hOldDestBitmap );
1352 IPicture_Release( pic );
1356 static UINT msi_dialog_bitmap_control( msi_dialog *dialog, MSIRECORD *rec )
1358 UINT cx, cy, flags, style, attributes;
1359 msi_control *control;
1362 flags = LR_LOADFROMFILE;
1363 style = SS_BITMAP | SS_LEFT | WS_GROUP;
1365 attributes = MSI_RecordGetInteger( rec, 8 );
1366 if( attributes & msidbControlAttributesFixedSize )
1368 flags |= LR_DEFAULTSIZE;
1369 style |= SS_CENTERIMAGE;
1372 control = msi_dialog_add_control( dialog, rec, szStatic, style );
1373 cx = MSI_RecordGetInteger( rec, 6 );
1374 cy = MSI_RecordGetInteger( rec, 7 );
1375 cx = msi_dialog_scale_unit( dialog, cx );
1376 cy = msi_dialog_scale_unit( dialog, cy );
1378 name = msi_get_binary_name( dialog->package, rec );
1379 control->hBitmap = msi_load_picture( dialog->package->db, name, cx, cy, flags );
1380 if( control->hBitmap )
1381 SendMessageW( control->hwnd, STM_SETIMAGE,
1382 IMAGE_BITMAP, (LPARAM) control->hBitmap );
1384 ERR("Failed to load bitmap %s\n", debugstr_w(name));
1388 return ERROR_SUCCESS;
1391 static UINT msi_dialog_icon_control( msi_dialog *dialog, MSIRECORD *rec )
1393 msi_control *control;
1399 control = msi_dialog_add_control( dialog, rec, szStatic,
1400 SS_ICON | SS_CENTERIMAGE | WS_GROUP );
1402 attributes = MSI_RecordGetInteger( rec, 8 );
1403 name = msi_get_binary_name( dialog->package, rec );
1404 control->hIcon = msi_load_icon( dialog->package->db, name, attributes );
1405 if( control->hIcon )
1406 SendMessageW( control->hwnd, STM_SETICON, (WPARAM) control->hIcon, 0 );
1408 ERR("Failed to load bitmap %s\n", debugstr_w(name));
1410 return ERROR_SUCCESS;
1413 /******************** Combo Box ***************************************/
1415 struct msi_combobox_info
1425 static LRESULT WINAPI MSIComboBox_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
1427 struct msi_combobox_info *info;
1431 TRACE("%p %04x %08lx %08lx\n", hWnd, msg, wParam, lParam);
1433 info = GetPropW( hWnd, szButtonData );
1437 r = CallWindowProcW( info->oldproc, hWnd, msg, wParam, lParam );
1442 for (j = 0; j < info->num_items; j++)
1443 msi_free( info->items[j] );
1444 msi_free( info->items );
1446 RemovePropW( hWnd, szButtonData );
1453 static UINT msi_combobox_add_item( MSIRECORD *rec, LPVOID param )
1455 struct msi_combobox_info *info = param;
1456 LPCWSTR value, text;
1459 value = MSI_RecordGetString( rec, 3 );
1460 text = MSI_RecordGetString( rec, 4 );
1462 info->items[info->addpos_items] = strdupW( value );
1464 pos = SendMessageW( info->hwnd, CB_ADDSTRING, 0, (LPARAM)text );
1465 SendMessageW( info->hwnd, CB_SETITEMDATA, pos, (LPARAM)info->items[info->addpos_items] );
1466 info->addpos_items++;
1468 return ERROR_SUCCESS;
1471 static UINT msi_combobox_add_items( struct msi_combobox_info *info, LPCWSTR property )
1473 static const WCHAR query[] = {
1474 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
1475 '`','C','o','m','b','o','B','o','x','`',' ','W','H','E','R','E',' ',
1476 '`','P','r','o','p','e','r','t','y','`',' ','=',' ','\'','%','s','\'',' ',
1477 'O','R','D','E','R',' ','B','Y',' ','`','O','r','d','e','r','`',0};
1482 r = MSI_OpenQuery( info->dialog->package->db, &view, query, property );
1483 if (r != ERROR_SUCCESS)
1486 /* just get the number of records */
1488 r = MSI_IterateRecords( view, &count, NULL, NULL );
1489 if (r != ERROR_SUCCESS)
1491 msiobj_release( &view->hdr );
1494 info->num_items = count;
1495 info->items = msi_alloc( sizeof(*info->items) * count );
1497 r = MSI_IterateRecords( view, NULL, msi_combobox_add_item, info );
1498 msiobj_release( &view->hdr );
1502 static UINT msi_dialog_set_control_condition( MSIRECORD *rec, LPVOID param )
1504 static const WCHAR szHide[] = {'H','i','d','e',0};
1505 static const WCHAR szShow[] = {'S','h','o','w',0};
1506 static const WCHAR szDisable[] = {'D','i','s','a','b','l','e',0};
1507 static const WCHAR szEnable[] = {'E','n','a','b','l','e',0};
1508 static const WCHAR szDefault[] = {'D','e','f','a','u','l','t',0};
1509 msi_dialog *dialog = param;
1510 msi_control *control;
1511 LPCWSTR name, action, condition;
1514 name = MSI_RecordGetString( rec, 2 );
1515 action = MSI_RecordGetString( rec, 3 );
1516 condition = MSI_RecordGetString( rec, 4 );
1517 r = MSI_EvaluateConditionW( dialog->package, condition );
1518 control = msi_dialog_find_control( dialog, name );
1519 if (r == MSICONDITION_TRUE && control)
1521 TRACE("%s control %s\n", debugstr_w(action), debugstr_w(name));
1523 /* FIXME: case sensitive? */
1524 if (!strcmpW( action, szHide ))
1525 ShowWindow(control->hwnd, SW_HIDE);
1526 else if (!strcmpW( action, szShow ))
1527 ShowWindow(control->hwnd, SW_SHOW);
1528 else if (!strcmpW( action, szDisable ))
1529 EnableWindow(control->hwnd, FALSE);
1530 else if (!strcmpW( action, szEnable ))
1531 EnableWindow(control->hwnd, TRUE);
1532 else if (!strcmpW( action, szDefault ))
1533 SetFocus(control->hwnd);
1535 FIXME("Unhandled action %s\n", debugstr_w(action));
1537 return ERROR_SUCCESS;
1540 static UINT msi_dialog_evaluate_control_conditions( msi_dialog *dialog )
1542 static const WCHAR query[] = {
1543 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
1544 'C','o','n','t','r','o','l','C','o','n','d','i','t','i','o','n',' ',
1545 'W','H','E','R','E',' ','`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',0};
1548 MSIPACKAGE *package = dialog->package;
1550 TRACE("%p %s\n", dialog, debugstr_w(dialog->name));
1552 /* query the Control table for all the elements of the control */
1553 r = MSI_OpenQuery( package->db, &view, query, dialog->name );
1554 if (r != ERROR_SUCCESS)
1555 return ERROR_SUCCESS;
1557 r = MSI_IterateRecords( view, 0, msi_dialog_set_control_condition, dialog );
1558 msiobj_release( &view->hdr );
1562 static UINT msi_dialog_combobox_handler( msi_dialog *dialog, msi_control *control, WPARAM param )
1564 struct msi_combobox_info *info;
1568 if (HIWORD(param) != CBN_SELCHANGE && HIWORD(param) != CBN_EDITCHANGE)
1569 return ERROR_SUCCESS;
1571 info = GetPropW( control->hwnd, szButtonData );
1572 index = SendMessageW( control->hwnd, CB_GETCURSEL, 0, 0 );
1573 if (index == CB_ERR)
1574 value = msi_get_window_text( control->hwnd );
1576 value = (LPWSTR) SendMessageW( control->hwnd, CB_GETITEMDATA, index, 0 );
1578 msi_dialog_set_property( info->dialog->package, control->property, value );
1579 msi_dialog_evaluate_control_conditions( info->dialog );
1581 if (index == CB_ERR)
1584 return ERROR_SUCCESS;
1587 static void msi_dialog_combobox_update( msi_dialog *dialog, msi_control *control )
1589 struct msi_combobox_info *info;
1593 info = GetPropW( control->hwnd, szButtonData );
1595 value = msi_dup_property( dialog->package->db, control->property );
1598 SendMessageW( control->hwnd, CB_SETCURSEL, -1, 0 );
1602 for (j = 0; j < info->num_items; j++)
1604 tmp = (LPWSTR) SendMessageW( control->hwnd, CB_GETITEMDATA, j, 0 );
1605 if (!strcmpW( value, tmp ))
1609 if (j < info->num_items)
1611 SendMessageW( control->hwnd, CB_SETCURSEL, j, 0 );
1615 SendMessageW( control->hwnd, CB_SETCURSEL, -1, 0 );
1616 SetWindowTextW( control->hwnd, value );
1622 static UINT msi_dialog_combo_control( msi_dialog *dialog, MSIRECORD *rec )
1624 struct msi_combobox_info *info;
1625 msi_control *control;
1626 DWORD attributes, style;
1629 info = msi_alloc( sizeof *info );
1631 return ERROR_FUNCTION_FAILED;
1633 style = CBS_AUTOHSCROLL | WS_TABSTOP | WS_GROUP | WS_CHILD;
1634 attributes = MSI_RecordGetInteger( rec, 8 );
1635 if ( ~attributes & msidbControlAttributesSorted)
1637 if ( attributes & msidbControlAttributesComboList)
1638 style |= CBS_DROPDOWNLIST;
1640 style |= CBS_DROPDOWN;
1642 control = msi_dialog_add_control( dialog, rec, WC_COMBOBOXW, style );
1646 return ERROR_FUNCTION_FAILED;
1649 control->handler = msi_dialog_combobox_handler;
1650 control->update = msi_dialog_combobox_update;
1652 prop = MSI_RecordGetString( rec, 9 );
1653 control->property = msi_dialog_dup_property( dialog, prop, FALSE );
1656 info->dialog = dialog;
1657 info->hwnd = control->hwnd;
1659 info->addpos_items = 0;
1660 info->oldproc = (WNDPROC)SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
1661 (LONG_PTR)MSIComboBox_WndProc );
1662 SetPropW( control->hwnd, szButtonData, info );
1664 if (control->property)
1665 msi_combobox_add_items( info, control->property );
1667 msi_dialog_combobox_update( dialog, control );
1669 return ERROR_SUCCESS;
1672 static UINT msi_dialog_edit_handler( msi_dialog *dialog, msi_control *control, WPARAM param )
1676 if (HIWORD(param) != EN_CHANGE)
1677 return ERROR_SUCCESS;
1679 TRACE("edit %s contents changed, set %s\n", debugstr_w(control->name), debugstr_w(control->property));
1681 buf = msi_get_window_text( control->hwnd );
1682 msi_dialog_set_property( dialog->package, control->property, buf );
1685 return ERROR_SUCCESS;
1688 /* length of 2^32 + 1 */
1689 #define MAX_NUM_DIGITS 11
1691 static UINT msi_dialog_edit_control( msi_dialog *dialog, MSIRECORD *rec )
1693 msi_control *control;
1695 LPWSTR val, begin, end;
1696 WCHAR num[MAX_NUM_DIGITS];
1699 control = msi_dialog_add_control( dialog, rec, szEdit,
1700 WS_BORDER | WS_TABSTOP | ES_AUTOHSCROLL );
1701 control->handler = msi_dialog_edit_handler;
1703 text = MSI_RecordGetString( rec, 10 );
1706 begin = strchrW( text, '{' );
1707 end = strchrW( text, '}' );
1709 if ( begin && end && end > begin &&
1710 begin[0] >= '0' && begin[0] <= '9' &&
1711 end - begin < MAX_NUM_DIGITS)
1713 lstrcpynW( num, begin + 1, end - begin );
1714 limit = atolW( num );
1716 SendMessageW( control->hwnd, EM_SETLIMITTEXT, limit, 0 );
1720 prop = MSI_RecordGetString( rec, 9 );
1722 control->property = strdupW( prop );
1724 val = msi_dup_property( dialog->package->db, control->property );
1725 SetWindowTextW( control->hwnd, val );
1727 return ERROR_SUCCESS;
1730 /******************** Masked Edit ********************************************/
1732 #define MASK_MAX_GROUPS 20
1734 struct msi_mask_group
1742 struct msi_maskedit_info
1750 struct msi_mask_group group[MASK_MAX_GROUPS];
1753 static BOOL msi_mask_editable( WCHAR type )
1768 static void msi_mask_control_change( struct msi_maskedit_info *info )
1773 val = msi_alloc( (info->num_chars+1)*sizeof(WCHAR) );
1774 for( i=0, n=0; i<info->num_groups; i++ )
1776 if( (info->group[i].len + n) > info->num_chars )
1778 ERR("can't fit control %d text into template\n",i);
1781 if (!msi_mask_editable(info->group[i].type))
1783 for(r=0; r<info->group[i].len; r++)
1784 val[n+r] = info->group[i].type;
1789 r = GetWindowTextW( info->group[i].hwnd, &val[n], info->group[i].len+1 );
1790 if( r != info->group[i].len )
1796 TRACE("%d/%d controls were good\n", i, info->num_groups);
1798 if( i == info->num_groups )
1800 TRACE("Set property %s to %s\n", debugstr_w(info->prop), debugstr_w(val));
1801 CharUpperBuffW( val, info->num_chars );
1802 msi_dialog_set_property( info->dialog->package, info->prop, val );
1803 msi_dialog_evaluate_control_conditions( info->dialog );
1808 /* now move to the next control if necessary */
1809 static VOID msi_mask_next_control( struct msi_maskedit_info *info, HWND hWnd )
1814 for( i=0; i<info->num_groups; i++ )
1815 if( info->group[i].hwnd == hWnd )
1818 /* don't move from the last control */
1819 if( i >= (info->num_groups-1) )
1822 len = SendMessageW( hWnd, WM_GETTEXTLENGTH, 0, 0 );
1823 if( len < info->group[i].len )
1826 hWndNext = GetNextDlgTabItem( GetParent( hWnd ), hWnd, FALSE );
1827 SetFocus( hWndNext );
1830 static LRESULT WINAPI
1831 MSIMaskedEdit_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
1833 struct msi_maskedit_info *info;
1836 TRACE("%p %04x %08lx %08lx\n", hWnd, msg, wParam, lParam);
1838 info = GetPropW(hWnd, szButtonData);
1840 r = CallWindowProcW(info->oldproc, hWnd, msg, wParam, lParam);
1845 if (HIWORD(wParam) == EN_CHANGE)
1847 msi_mask_control_change( info );
1848 msi_mask_next_control( info, (HWND) lParam );
1852 msi_free( info->prop );
1854 RemovePropW( hWnd, szButtonData );
1861 /* fish the various bits of the property out and put them in the control */
1863 msi_maskedit_set_text( struct msi_maskedit_info *info, LPCWSTR text )
1869 for( i = 0; i < info->num_groups; i++ )
1871 if( info->group[i].len < strlenW( p ) )
1873 LPWSTR chunk = strdupW( p );
1874 chunk[ info->group[i].len ] = 0;
1875 SetWindowTextW( info->group[i].hwnd, chunk );
1880 SetWindowTextW( info->group[i].hwnd, p );
1883 p += info->group[i].len;
1887 static struct msi_maskedit_info * msi_dialog_parse_groups( LPCWSTR mask )
1889 struct msi_maskedit_info * info = NULL;
1890 int i = 0, n = 0, total = 0;
1893 TRACE("masked control, template %s\n", debugstr_w(mask));
1898 info = msi_alloc_zero( sizeof *info );
1902 p = strchrW(mask, '<');
1908 for( i=0; i<MASK_MAX_GROUPS; i++ )
1910 /* stop at the end of the string */
1911 if( p[0] == 0 || p[0] == '>' )
1914 /* count the number of the same identifier */
1915 for( n=0; p[n] == p[0]; n++ )
1917 info->group[i].ofs = total;
1918 info->group[i].type = p[0];
1922 total++; /* an extra not part of the group */
1924 info->group[i].len = n;
1929 TRACE("%d characters in %d groups\n", total, i );
1930 if( i == MASK_MAX_GROUPS )
1931 ERR("too many groups in PIDTemplate %s\n", debugstr_w(mask));
1933 info->num_chars = total;
1934 info->num_groups = i;
1940 msi_maskedit_create_children( struct msi_maskedit_info *info, LPCWSTR font )
1942 DWORD width, height, style, wx, ww;
1947 style = WS_CHILD | WS_BORDER | WS_VISIBLE | WS_TABSTOP | ES_AUTOHSCROLL;
1949 GetClientRect( info->hwnd, &rect );
1951 width = rect.right - rect.left;
1952 height = rect.bottom - rect.top;
1954 for( i = 0; i < info->num_groups; i++ )
1956 if (!msi_mask_editable( info->group[i].type ))
1958 wx = (info->group[i].ofs * width) / info->num_chars;
1959 ww = (info->group[i].len * width) / info->num_chars;
1961 hwnd = CreateWindowW( szEdit, NULL, style, wx, 0, ww, height,
1962 info->hwnd, NULL, NULL, NULL );
1965 ERR("failed to create mask edit sub window\n");
1969 SendMessageW( hwnd, EM_LIMITTEXT, info->group[i].len, 0 );
1971 msi_dialog_set_font( info->dialog, hwnd,
1972 font?font:info->dialog->default_font );
1973 info->group[i].hwnd = hwnd;
1978 * office 2003 uses "73931<````=````=````=````=`````>@@@@@"
1979 * delphi 7 uses "<????-??????-??????-????>" and "<???-???>"
1980 * filemaker pro 7 uses "<^^^^=^^^^=^^^^=^^^^=^^^^=^^^^=^^^^^>"
1982 static UINT msi_dialog_maskedit_control( msi_dialog *dialog, MSIRECORD *rec )
1984 LPWSTR font_mask, val = NULL, font;
1985 struct msi_maskedit_info *info = NULL;
1986 UINT ret = ERROR_SUCCESS;
1987 msi_control *control;
1992 font_mask = msi_get_deformatted_field( dialog->package, rec, 10 );
1993 font = msi_dialog_get_style( font_mask, &mask );
1996 WARN("mask template is empty\n");
2000 info = msi_dialog_parse_groups( mask );
2003 ERR("template %s is invalid\n", debugstr_w(mask));
2007 info->dialog = dialog;
2009 control = msi_dialog_add_control( dialog, rec, szStatic,
2010 SS_OWNERDRAW | WS_GROUP | WS_VISIBLE );
2013 ERR("Failed to create maskedit container\n");
2014 ret = ERROR_FUNCTION_FAILED;
2017 SetWindowLongPtrW( control->hwnd, GWL_EXSTYLE, WS_EX_CONTROLPARENT );
2019 info->hwnd = control->hwnd;
2021 /* subclass the static control */
2022 info->oldproc = (WNDPROC) SetWindowLongPtrW( info->hwnd, GWLP_WNDPROC,
2023 (LONG_PTR)MSIMaskedEdit_WndProc );
2024 SetPropW( control->hwnd, szButtonData, info );
2026 prop = MSI_RecordGetString( rec, 9 );
2028 info->prop = strdupW( prop );
2030 msi_maskedit_create_children( info, font );
2034 val = msi_dup_property( dialog->package->db, prop );
2037 msi_maskedit_set_text( info, val );
2043 if( ret != ERROR_SUCCESS )
2045 msi_free( font_mask );
2050 /******************** Progress Bar *****************************************/
2052 static UINT msi_dialog_progress_bar( msi_dialog *dialog, MSIRECORD *rec )
2054 msi_control *control;
2055 DWORD attributes, style;
2058 attributes = MSI_RecordGetInteger( rec, 8 );
2059 if( !(attributes & msidbControlAttributesProgress95) )
2060 style |= PBS_SMOOTH;
2062 control = msi_dialog_add_control( dialog, rec, PROGRESS_CLASSW, style );
2064 return ERROR_FUNCTION_FAILED;
2066 ControlEvent_SubscribeToEvent( dialog->package, dialog,
2067 szSetProgress, control->name, szProgress );
2068 return ERROR_SUCCESS;
2071 /******************** Path Edit ********************************************/
2073 struct msi_pathedit_info
2076 msi_control *control;
2080 static void msi_dialog_update_pathedit( msi_dialog *dialog, msi_control *control )
2085 if (!control && !(control = msi_dialog_find_control_by_type( dialog, szPathEdit )))
2088 indirect = control->attributes & msidbControlAttributesIndirect;
2089 prop = msi_dialog_dup_property( dialog, control->property, indirect );
2090 path = msi_dialog_dup_property( dialog, prop, TRUE );
2092 SetWindowTextW( control->hwnd, path );
2093 SendMessageW( control->hwnd, EM_SETSEL, 0, -1 );
2099 /* FIXME: test when this should fail */
2100 static BOOL msi_dialog_verify_path( LPWSTR path )
2102 if ( !lstrlenW( path ) )
2105 if ( PathIsRelativeW( path ) )
2111 /* returns TRUE if the path is valid, FALSE otherwise */
2112 static BOOL msi_dialog_onkillfocus( msi_dialog *dialog, msi_control *control )
2118 indirect = control->attributes & msidbControlAttributesIndirect;
2119 prop = msi_dialog_dup_property( dialog, control->property, indirect );
2121 buf = msi_get_window_text( control->hwnd );
2123 if ( !msi_dialog_verify_path( buf ) )
2125 /* FIXME: display an error message box */
2126 ERR("Invalid path %s\n", debugstr_w( buf ));
2128 SetFocus( control->hwnd );
2133 msi_dialog_set_property( dialog->package, prop, buf );
2136 msi_dialog_update_pathedit( dialog, control );
2138 TRACE("edit %s contents changed, set %s\n", debugstr_w(control->name),
2147 static LRESULT WINAPI MSIPathEdit_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
2149 struct msi_pathedit_info *info = GetPropW(hWnd, szButtonData);
2152 TRACE("%p %04x %08lx %08lx\n", hWnd, msg, wParam, lParam);
2154 if ( msg == WM_KILLFOCUS )
2156 /* if the path is invalid, don't handle this message */
2157 if ( !msi_dialog_onkillfocus( info->dialog, info->control ) )
2161 r = CallWindowProcW(info->oldproc, hWnd, msg, wParam, lParam);
2163 if ( msg == WM_NCDESTROY )
2166 RemovePropW( hWnd, szButtonData );
2172 static UINT msi_dialog_pathedit_control( msi_dialog *dialog, MSIRECORD *rec )
2174 struct msi_pathedit_info *info;
2175 msi_control *control;
2178 info = msi_alloc( sizeof *info );
2180 return ERROR_FUNCTION_FAILED;
2182 control = msi_dialog_add_control( dialog, rec, szEdit,
2183 WS_BORDER | WS_TABSTOP );
2184 control->attributes = MSI_RecordGetInteger( rec, 8 );
2185 prop = MSI_RecordGetString( rec, 9 );
2186 control->property = msi_dialog_dup_property( dialog, prop, FALSE );
2188 info->dialog = dialog;
2189 info->control = control;
2190 info->oldproc = (WNDPROC) SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
2191 (LONG_PTR)MSIPathEdit_WndProc );
2192 SetPropW( control->hwnd, szButtonData, info );
2194 msi_dialog_update_pathedit( dialog, control );
2196 return ERROR_SUCCESS;
2199 static UINT msi_dialog_radiogroup_handler( msi_dialog *dialog, msi_control *control, WPARAM param )
2201 if (HIWORD(param) != BN_CLICKED)
2202 return ERROR_SUCCESS;
2204 TRACE("clicked radio button %s, set %s\n", debugstr_w(control->name), debugstr_w(control->property));
2206 msi_dialog_set_property( dialog->package, control->property, control->name );
2208 return msi_dialog_button_handler( dialog, control, param );
2211 /* radio buttons are a bit different from normal controls */
2212 static UINT msi_dialog_create_radiobutton( MSIRECORD *rec, LPVOID param )
2214 radio_button_group_descr *group = param;
2215 msi_dialog *dialog = group->dialog;
2216 msi_control *control;
2217 LPCWSTR prop, text, name;
2218 DWORD style, attributes = group->attributes;
2220 style = WS_CHILD | BS_AUTORADIOBUTTON | BS_MULTILINE | WS_TABSTOP;
2221 name = MSI_RecordGetString( rec, 3 );
2222 text = MSI_RecordGetString( rec, 8 );
2223 if( attributes & msidbControlAttributesVisible )
2224 style |= WS_VISIBLE;
2225 if( ~attributes & msidbControlAttributesEnabled )
2226 style |= WS_DISABLED;
2228 control = msi_dialog_create_window( dialog, rec, 0, szButton, name, text,
2229 style, group->parent->hwnd );
2231 return ERROR_FUNCTION_FAILED;
2232 control->handler = msi_dialog_radiogroup_handler;
2234 if (group->propval && !strcmpW( control->name, group->propval ))
2235 SendMessageW(control->hwnd, BM_SETCHECK, BST_CHECKED, 0);
2237 prop = MSI_RecordGetString( rec, 1 );
2239 control->property = strdupW( prop );
2241 return ERROR_SUCCESS;
2244 static BOOL CALLBACK msi_radioground_child_enum( HWND hWnd, LPARAM lParam )
2246 EnableWindow( hWnd, lParam );
2250 static LRESULT WINAPI MSIRadioGroup_WndProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
2252 WNDPROC oldproc = (WNDPROC)GetPropW( hWnd, szButtonData );
2255 TRACE("hWnd %p msg %04x wParam 0x%08lx lParam 0x%08lx\n", hWnd, msg, wParam, lParam);
2257 if (msg == WM_COMMAND) /* Forward notifications to dialog */
2258 SendMessageW( GetParent( hWnd ), msg, wParam, lParam );
2260 r = CallWindowProcW( oldproc, hWnd, msg, wParam, lParam );
2262 /* make sure the radio buttons show as disabled if the parent is disabled */
2263 if (msg == WM_ENABLE)
2264 EnumChildWindows( hWnd, msi_radioground_child_enum, wParam );
2269 static UINT msi_dialog_radiogroup_control( msi_dialog *dialog, MSIRECORD *rec )
2271 static const WCHAR query[] = {
2272 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2273 'R','a','d','i','o','B','u','t','t','o','n',' ','W','H','E','R','E',' ',
2274 '`','P','r','o','p','e','r','t','y','`',' ','=',' ','\'','%','s','\'',0};
2277 msi_control *control;
2279 radio_button_group_descr group;
2280 MSIPACKAGE *package = dialog->package;
2282 DWORD attr, style = WS_GROUP;
2284 prop = MSI_RecordGetString( rec, 9 );
2286 TRACE("%p %p %s\n", dialog, rec, debugstr_w( prop ));
2288 attr = MSI_RecordGetInteger( rec, 8 );
2289 if (attr & msidbControlAttributesHasBorder)
2290 style |= BS_GROUPBOX;
2292 style |= BS_OWNERDRAW;
2294 /* Create parent group box to hold radio buttons */
2295 control = msi_dialog_add_control( dialog, rec, szButton, style );
2297 return ERROR_FUNCTION_FAILED;
2299 oldproc = (WNDPROC) SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
2300 (LONG_PTR)MSIRadioGroup_WndProc );
2301 SetPropW(control->hwnd, szButtonData, oldproc);
2302 SetWindowLongPtrW( control->hwnd, GWL_EXSTYLE, WS_EX_CONTROLPARENT );
2305 control->property = strdupW( prop );
2307 /* query the Radio Button table for all control in this group */
2308 r = MSI_OpenQuery( package->db, &view, query, prop );
2309 if( r != ERROR_SUCCESS )
2311 ERR("query failed for dialog %s radio group %s\n",
2312 debugstr_w(dialog->name), debugstr_w(prop));
2313 return ERROR_INVALID_PARAMETER;
2316 group.dialog = dialog;
2317 group.parent = control;
2318 group.attributes = MSI_RecordGetInteger( rec, 8 );
2319 group.propval = msi_dup_property( dialog->package->db, control->property );
2321 r = MSI_IterateRecords( view, 0, msi_dialog_create_radiobutton, &group );
2322 msiobj_release( &view->hdr );
2323 msi_free( group.propval );
2328 msi_seltree_sync_item_state( HWND hwnd, MSIFEATURE *feature, HTREEITEM hItem )
2331 DWORD index = feature->ActionRequest;
2333 TRACE("Feature %s -> %d %d %d\n", debugstr_w(feature->Title),
2334 feature->Installed, feature->Action, feature->ActionRequest);
2336 if (index == INSTALLSTATE_UNKNOWN)
2337 index = INSTALLSTATE_ABSENT;
2339 tvi.mask = TVIF_STATE;
2341 tvi.state = INDEXTOSTATEIMAGEMASK( index );
2342 tvi.stateMask = TVIS_STATEIMAGEMASK;
2344 SendMessageW( hwnd, TVM_SETITEMW, 0, (LPARAM) &tvi );
2348 msi_seltree_popup_menu( HWND hwnd, INT x, INT y )
2353 /* create a menu to display */
2354 hMenu = CreatePopupMenu();
2356 /* FIXME: load strings from resources */
2357 AppendMenuA( hMenu, MF_ENABLED, INSTALLSTATE_LOCAL, "Install feature locally");
2358 AppendMenuA( hMenu, MF_ENABLED, USER_INSTALLSTATE_ALL, "Install entire feature");
2359 AppendMenuA( hMenu, MF_ENABLED, INSTALLSTATE_ADVERTISED, "Install on demand");
2360 AppendMenuA( hMenu, MF_ENABLED, INSTALLSTATE_ABSENT, "Don't install");
2361 r = TrackPopupMenu( hMenu, TPM_LEFTALIGN | TPM_TOPALIGN | TPM_RETURNCMD,
2362 x, y, 0, hwnd, NULL );
2363 DestroyMenu( hMenu );
2368 msi_seltree_update_feature_installstate( HWND hwnd, HTREEITEM hItem,
2369 MSIPACKAGE *package, MSIFEATURE *feature, INSTALLSTATE state )
2371 feature->ActionRequest = state;
2372 msi_seltree_sync_item_state( hwnd, feature, hItem );
2373 ACTION_UpdateComponentStates( package, feature );
2377 msi_seltree_update_siblings_and_children_installstate( HWND hwnd, HTREEITEM curr,
2378 MSIPACKAGE *package, INSTALLSTATE state)
2380 /* update all siblings */
2383 MSIFEATURE *feature;
2386 feature = msi_seltree_feature_from_item( hwnd, curr );
2387 msi_seltree_update_feature_installstate( hwnd, curr, package, feature, state );
2389 /* update this sibling's children */
2390 child = (HTREEITEM)SendMessageW( hwnd, TVM_GETNEXTITEM, (WPARAM)TVGN_CHILD, (LPARAM)curr );
2392 msi_seltree_update_siblings_and_children_installstate( hwnd, child,
2395 while ((curr = (HTREEITEM)SendMessageW( hwnd, TVM_GETNEXTITEM, (WPARAM)TVGN_NEXT, (LPARAM)curr )));
2399 msi_seltree_menu( HWND hwnd, HTREEITEM hItem )
2401 struct msi_selection_tree_info *info;
2402 MSIFEATURE *feature;
2403 MSIPACKAGE *package;
2411 info = GetPropW(hwnd, szButtonData);
2412 package = info->dialog->package;
2414 feature = msi_seltree_feature_from_item( hwnd, hItem );
2417 ERR("item %p feature was NULL\n", hItem);
2421 /* get the item's rectangle to put the menu just below it */
2423 SendMessageW( hwnd, TVM_GETITEMRECT, 0, (LPARAM) &u.rc );
2424 MapWindowPoints( hwnd, NULL, u.pt, 2 );
2426 r = msi_seltree_popup_menu( hwnd, u.rc.left, u.rc.top );
2430 case USER_INSTALLSTATE_ALL:
2431 r = INSTALLSTATE_LOCAL;
2433 case INSTALLSTATE_ADVERTISED:
2434 case INSTALLSTATE_ABSENT:
2437 child = (HTREEITEM)SendMessageW( hwnd, TVM_GETNEXTITEM, (WPARAM)TVGN_CHILD, (LPARAM)hItem );
2439 msi_seltree_update_siblings_and_children_installstate( hwnd, child, package, r );
2442 case INSTALLSTATE_LOCAL:
2443 msi_seltree_update_feature_installstate( hwnd, hItem, package, feature, r );
2450 static LRESULT WINAPI
2451 MSISelectionTree_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
2453 struct msi_selection_tree_info *info;
2454 TVHITTESTINFO tvhti;
2457 TRACE("%p %04x %08lx %08lx\n", hWnd, msg, wParam, lParam);
2459 info = GetPropW(hWnd, szButtonData);
2463 case WM_LBUTTONDOWN:
2464 tvhti.pt.x = (short)LOWORD( lParam );
2465 tvhti.pt.y = (short)HIWORD( lParam );
2468 r = CallWindowProcW(info->oldproc, hWnd, TVM_HITTEST, 0, (LPARAM) &tvhti );
2469 if (tvhti.flags & TVHT_ONITEMSTATEICON)
2470 return msi_seltree_menu( hWnd, tvhti.hItem );
2474 r = CallWindowProcW(info->oldproc, hWnd, msg, wParam, lParam);
2480 RemovePropW( hWnd, szButtonData );
2487 msi_seltree_add_child_features( MSIPACKAGE *package, HWND hwnd,
2488 LPCWSTR parent, HTREEITEM hParent )
2490 struct msi_selection_tree_info *info = GetPropW( hwnd, szButtonData );
2491 MSIFEATURE *feature;
2492 TVINSERTSTRUCTW tvis;
2493 HTREEITEM hitem, hfirst = NULL;
2495 LIST_FOR_EACH_ENTRY( feature, &package->features, MSIFEATURE, entry )
2497 if ( parent && feature->Feature_Parent && strcmpW( parent, feature->Feature_Parent ))
2499 else if ( parent && !feature->Feature_Parent )
2501 else if ( !parent && feature->Feature_Parent )
2504 if ( !feature->Title )
2507 if ( !feature->Display )
2510 memset( &tvis, 0, sizeof tvis );
2511 tvis.hParent = hParent;
2512 tvis.hInsertAfter = TVI_LAST;
2513 tvis.u.item.mask = TVIF_TEXT | TVIF_PARAM;
2514 tvis.u.item.pszText = feature->Title;
2515 tvis.u.item.lParam = (LPARAM) feature;
2517 hitem = (HTREEITEM) SendMessageW( hwnd, TVM_INSERTITEMW, 0, (LPARAM) &tvis );
2524 msi_seltree_sync_item_state( hwnd, feature, hitem );
2525 msi_seltree_add_child_features( package, hwnd,
2526 feature->Feature, hitem );
2528 /* the node is expanded if Display is odd */
2529 if ( feature->Display % 2 != 0 )
2530 SendMessageW( hwnd, TVM_EXPAND, TVE_EXPAND, (LPARAM) hitem );
2533 /* select the first item */
2534 SendMessageW( hwnd, TVM_SELECTITEM, TVGN_CARET | TVGN_DROPHILITE, (LPARAM) hfirst );
2535 info->selected = hfirst;
2538 static void msi_seltree_create_imagelist( HWND hwnd )
2540 const int bm_width = 32, bm_height = 16, bm_count = 3;
2541 const int bm_resource = 0x1001;
2546 himl = ImageList_Create( bm_width, bm_height, FALSE, 4, 0 );
2549 ERR("failed to create image list\n");
2553 for (i=0; i<bm_count; i++)
2555 hbmp = LoadBitmapW( msi_hInstance, MAKEINTRESOURCEW(i+bm_resource) );
2558 ERR("failed to load bitmap %d\n", i);
2563 * Add a dummy bitmap at offset zero because the treeview
2564 * can't use it as a state mask (zero means no user state).
2567 ImageList_Add( himl, hbmp, NULL );
2569 ImageList_Add( himl, hbmp, NULL );
2572 SendMessageW( hwnd, TVM_SETIMAGELIST, TVSIL_STATE, (LPARAM)himl );
2575 static UINT msi_dialog_seltree_handler( msi_dialog *dialog,
2576 msi_control *control, WPARAM param )
2578 struct msi_selection_tree_info *info = GetPropW( control->hwnd, szButtonData );
2579 LPNMTREEVIEWW tv = (LPNMTREEVIEWW)param;
2580 MSIRECORD *row, *rec;
2582 MSIFEATURE *feature;
2583 LPCWSTR dir, title = NULL;
2584 UINT r = ERROR_SUCCESS;
2586 static const WCHAR select[] = {
2587 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2588 '`','F','e','a','t','u','r','e','`',' ','W','H','E','R','E',' ',
2589 '`','T','i','t','l','e','`',' ','=',' ','\'','%','s','\'',0
2592 if (tv->hdr.code != TVN_SELCHANGINGW)
2593 return ERROR_SUCCESS;
2595 info->selected = tv->itemNew.hItem;
2597 if (!(tv->itemNew.mask & TVIF_TEXT))
2599 feature = msi_seltree_feature_from_item( control->hwnd, tv->itemNew.hItem );
2601 title = feature->Title;
2604 title = tv->itemNew.pszText;
2606 row = MSI_QueryGetRecord( dialog->package->db, select, title );
2608 return ERROR_FUNCTION_FAILED;
2610 rec = MSI_CreateRecord( 1 );
2612 MSI_RecordSetStringW( rec, 1, MSI_RecordGetString( row, 4 ) );
2613 ControlEvent_FireSubscribedEvent( dialog->package, szSelectionDescription, rec );
2615 dir = MSI_RecordGetString( row, 7 );
2618 folder = msi_get_loaded_folder( dialog->package, dir );
2621 r = ERROR_FUNCTION_FAILED;
2624 MSI_RecordSetStringW( rec, 1, folder->ResolvedTarget );
2627 MSI_RecordSetStringW( rec, 1, NULL );
2629 ControlEvent_FireSubscribedEvent( dialog->package, szSelectionPath, rec );
2632 msiobj_release(&row->hdr);
2633 msiobj_release(&rec->hdr);
2638 static UINT msi_dialog_selection_tree( msi_dialog *dialog, MSIRECORD *rec )
2640 msi_control *control;
2641 LPCWSTR prop, control_name;
2642 MSIPACKAGE *package = dialog->package;
2644 struct msi_selection_tree_info *info;
2646 info = msi_alloc( sizeof *info );
2648 return ERROR_FUNCTION_FAILED;
2650 /* create the treeview control */
2651 style = TVS_HASLINES | TVS_HASBUTTONS | TVS_LINESATROOT;
2652 style |= WS_GROUP | WS_VSCROLL;
2653 control = msi_dialog_add_control( dialog, rec, WC_TREEVIEWW, style );
2657 return ERROR_FUNCTION_FAILED;
2660 control->handler = msi_dialog_seltree_handler;
2661 control_name = MSI_RecordGetString( rec, 2 );
2662 control->attributes = MSI_RecordGetInteger( rec, 8 );
2663 prop = MSI_RecordGetString( rec, 9 );
2664 control->property = msi_dialog_dup_property( dialog, prop, FALSE );
2667 info->dialog = dialog;
2668 info->hwnd = control->hwnd;
2669 info->oldproc = (WNDPROC) SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
2670 (LONG_PTR)MSISelectionTree_WndProc );
2671 SetPropW( control->hwnd, szButtonData, info );
2673 ControlEvent_SubscribeToEvent( dialog->package, dialog,
2674 szSelectionPath, control_name, szProperty );
2677 msi_seltree_create_imagelist( control->hwnd );
2678 msi_seltree_add_child_features( package, control->hwnd, NULL, NULL );
2680 return ERROR_SUCCESS;
2683 /******************** Group Box ***************************************/
2685 static UINT msi_dialog_group_box( msi_dialog *dialog, MSIRECORD *rec )
2687 msi_control *control;
2690 style = BS_GROUPBOX | WS_CHILD | WS_GROUP;
2691 control = msi_dialog_add_control( dialog, rec, WC_BUTTONW, style );
2693 return ERROR_FUNCTION_FAILED;
2695 return ERROR_SUCCESS;
2698 /******************** List Box ***************************************/
2700 struct msi_listbox_info
2710 static LRESULT WINAPI MSIListBox_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
2712 struct msi_listbox_info *info;
2716 TRACE("%p %04x %08lx %08lx\n", hWnd, msg, wParam, lParam);
2718 info = GetPropW( hWnd, szButtonData );
2722 r = CallWindowProcW( info->oldproc, hWnd, msg, wParam, lParam );
2727 for (j = 0; j < info->num_items; j++)
2728 msi_free( info->items[j] );
2729 msi_free( info->items );
2731 RemovePropW( hWnd, szButtonData );
2738 static UINT msi_listbox_add_item( MSIRECORD *rec, LPVOID param )
2740 struct msi_listbox_info *info = param;
2741 LPCWSTR value, text;
2744 value = MSI_RecordGetString( rec, 3 );
2745 text = MSI_RecordGetString( rec, 4 );
2747 info->items[info->addpos_items] = strdupW( value );
2749 pos = SendMessageW( info->hwnd, LB_ADDSTRING, 0, (LPARAM)text );
2750 SendMessageW( info->hwnd, LB_SETITEMDATA, pos, (LPARAM)info->items[info->addpos_items] );
2751 info->addpos_items++;
2752 return ERROR_SUCCESS;
2755 static UINT msi_listbox_add_items( struct msi_listbox_info *info, LPCWSTR property )
2757 static const WCHAR query[] = {
2758 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2759 '`','L','i','s','t','B','o','x','`',' ','W','H','E','R','E',' ',
2760 '`','P','r','o','p','e','r','t','y','`',' ','=',' ','\'','%','s','\'',' ',
2761 'O','R','D','E','R',' ','B','Y',' ','`','O','r','d','e','r','`',0};
2766 r = MSI_OpenQuery( info->dialog->package->db, &view, query, property );
2767 if ( r != ERROR_SUCCESS )
2770 /* just get the number of records */
2772 r = MSI_IterateRecords( view, &count, NULL, NULL );
2773 if (r != ERROR_SUCCESS)
2775 msiobj_release( &view->hdr );
2778 info->num_items = count;
2779 info->items = msi_alloc( sizeof(*info->items) * count );
2781 r = MSI_IterateRecords( view, NULL, msi_listbox_add_item, info );
2782 msiobj_release( &view->hdr );
2786 static UINT msi_dialog_listbox_handler( msi_dialog *dialog,
2787 msi_control *control, WPARAM param )
2789 struct msi_listbox_info *info;
2793 if( HIWORD(param) != LBN_SELCHANGE )
2794 return ERROR_SUCCESS;
2796 info = GetPropW( control->hwnd, szButtonData );
2797 index = SendMessageW( control->hwnd, LB_GETCURSEL, 0, 0 );
2798 value = (LPCWSTR) SendMessageW( control->hwnd, LB_GETITEMDATA, index, 0 );
2800 msi_dialog_set_property( info->dialog->package, control->property, value );
2801 msi_dialog_evaluate_control_conditions( info->dialog );
2803 return ERROR_SUCCESS;
2806 static UINT msi_dialog_list_box( msi_dialog *dialog, MSIRECORD *rec )
2808 struct msi_listbox_info *info;
2809 msi_control *control;
2810 DWORD attributes, style;
2813 info = msi_alloc( sizeof *info );
2815 return ERROR_FUNCTION_FAILED;
2817 style = WS_TABSTOP | WS_GROUP | WS_CHILD | LBS_NOTIFY | WS_VSCROLL | WS_BORDER;
2818 attributes = MSI_RecordGetInteger( rec, 8 );
2819 if (~attributes & msidbControlAttributesSorted)
2822 control = msi_dialog_add_control( dialog, rec, WC_LISTBOXW, style );
2826 return ERROR_FUNCTION_FAILED;
2829 control->handler = msi_dialog_listbox_handler;
2831 prop = MSI_RecordGetString( rec, 9 );
2832 control->property = msi_dialog_dup_property( dialog, prop, FALSE );
2835 info->dialog = dialog;
2836 info->hwnd = control->hwnd;
2838 info->addpos_items = 0;
2839 info->oldproc = (WNDPROC)SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
2840 (LONG_PTR)MSIListBox_WndProc );
2841 SetPropW( control->hwnd, szButtonData, info );
2843 if ( control->property )
2844 msi_listbox_add_items( info, control->property );
2846 return ERROR_SUCCESS;
2849 /******************** Directory Combo ***************************************/
2851 static void msi_dialog_update_directory_combo( msi_dialog *dialog, msi_control *control )
2856 if (!control && !(control = msi_dialog_find_control_by_type( dialog, szDirectoryCombo )))
2859 indirect = control->attributes & msidbControlAttributesIndirect;
2860 prop = msi_dialog_dup_property( dialog, control->property, indirect );
2861 path = msi_dialog_dup_property( dialog, prop, TRUE );
2863 PathStripPathW( path );
2864 PathRemoveBackslashW( path );
2866 SendMessageW( control->hwnd, CB_INSERTSTRING, 0, (LPARAM)path );
2867 SendMessageW( control->hwnd, CB_SETCURSEL, 0, 0 );
2873 static UINT msi_dialog_directory_combo( msi_dialog *dialog, MSIRECORD *rec )
2875 msi_control *control;
2879 /* FIXME: use CBS_OWNERDRAWFIXED and add owner draw code */
2880 style = CBS_DROPDOWNLIST | CBS_HASSTRINGS | WS_CHILD |
2881 WS_GROUP | WS_TABSTOP | WS_VSCROLL;
2882 control = msi_dialog_add_control( dialog, rec, WC_COMBOBOXW, style );
2884 return ERROR_FUNCTION_FAILED;
2886 control->attributes = MSI_RecordGetInteger( rec, 8 );
2887 prop = MSI_RecordGetString( rec, 9 );
2888 control->property = msi_dialog_dup_property( dialog, prop, FALSE );
2890 msi_dialog_update_directory_combo( dialog, control );
2892 return ERROR_SUCCESS;
2895 /******************** Directory List ***************************************/
2897 static void msi_dialog_update_directory_list( msi_dialog *dialog, msi_control *control )
2899 WCHAR dir_spec[MAX_PATH];
2900 WIN32_FIND_DATAW wfd;
2906 static const WCHAR asterisk[] = {'*',0};
2908 if (!control && !(control = msi_dialog_find_control_by_type( dialog, szDirectoryList )))
2911 /* clear the list-view */
2912 SendMessageW( control->hwnd, LVM_DELETEALLITEMS, 0, 0 );
2914 indirect = control->attributes & msidbControlAttributesIndirect;
2915 prop = msi_dialog_dup_property( dialog, control->property, indirect );
2916 path = msi_dialog_dup_property( dialog, prop, TRUE );
2918 lstrcpyW( dir_spec, path );
2919 lstrcatW( dir_spec, asterisk );
2921 file = FindFirstFileW( dir_spec, &wfd );
2922 if ( file == INVALID_HANDLE_VALUE )
2927 if ( wfd.dwFileAttributes != FILE_ATTRIBUTE_DIRECTORY )
2930 if ( !strcmpW( wfd.cFileName, szDot ) || !strcmpW( wfd.cFileName, szDotDot ) )
2933 item.mask = LVIF_TEXT;
2934 item.cchTextMax = MAX_PATH;
2937 item.pszText = wfd.cFileName;
2939 SendMessageW( control->hwnd, LVM_INSERTITEMW, 0, (LPARAM)&item );
2940 } while ( FindNextFileW( file, &wfd ) );
2947 UINT msi_dialog_directorylist_up( msi_dialog *dialog )
2949 msi_control *control;
2950 LPWSTR prop, path, ptr;
2953 control = msi_dialog_find_control_by_type( dialog, szDirectoryList );
2954 indirect = control->attributes & msidbControlAttributesIndirect;
2955 prop = msi_dialog_dup_property( dialog, control->property, indirect );
2956 path = msi_dialog_dup_property( dialog, prop, TRUE );
2958 /* strip off the last directory */
2959 ptr = PathFindFileNameW( path );
2960 if (ptr != path) *(ptr - 1) = '\0';
2961 PathAddBackslashW( path );
2963 msi_dialog_set_property( dialog->package, prop, path );
2965 msi_dialog_update_directory_list( dialog, NULL );
2966 msi_dialog_update_directory_combo( dialog, NULL );
2967 msi_dialog_update_pathedit( dialog, NULL );
2972 return ERROR_SUCCESS;
2975 static UINT msi_dialog_dirlist_handler( msi_dialog *dialog,
2976 msi_control *control, WPARAM param )
2978 LPNMHDR nmhdr = (LPNMHDR)param;
2979 WCHAR new_path[MAX_PATH];
2980 WCHAR text[MAX_PATH];
2986 if (nmhdr->code != LVN_ITEMACTIVATE)
2987 return ERROR_SUCCESS;
2989 index = SendMessageW( control->hwnd, LVM_GETNEXTITEM, -1, LVNI_SELECTED );
2992 ERR("No list-view item selected!\n");
2993 return ERROR_FUNCTION_FAILED;
2997 item.pszText = text;
2998 item.cchTextMax = MAX_PATH;
2999 SendMessageW( control->hwnd, LVM_GETITEMTEXTW, index, (LPARAM)&item );
3001 indirect = control->attributes & msidbControlAttributesIndirect;
3002 prop = msi_dialog_dup_property( dialog, control->property, indirect );
3003 path = msi_dialog_dup_property( dialog, prop, TRUE );
3005 lstrcpyW( new_path, path );
3006 lstrcatW( new_path, text );
3007 lstrcatW( new_path, szBackSlash );
3009 msi_dialog_set_property( dialog->package, prop, new_path );
3011 msi_dialog_update_directory_list( dialog, NULL );
3012 msi_dialog_update_directory_combo( dialog, NULL );
3013 msi_dialog_update_pathedit( dialog, NULL );
3017 return ERROR_SUCCESS;
3020 static UINT msi_dialog_directory_list( msi_dialog *dialog, MSIRECORD *rec )
3022 msi_control *control;
3026 style = LVS_LIST | WS_VSCROLL | LVS_SHAREIMAGELISTS |
3027 LVS_AUTOARRANGE | LVS_SINGLESEL | WS_BORDER |
3028 LVS_SORTASCENDING | WS_CHILD | WS_GROUP | WS_TABSTOP;
3029 control = msi_dialog_add_control( dialog, rec, WC_LISTVIEWW, style );
3031 return ERROR_FUNCTION_FAILED;
3033 control->attributes = MSI_RecordGetInteger( rec, 8 );
3034 control->handler = msi_dialog_dirlist_handler;
3035 prop = MSI_RecordGetString( rec, 9 );
3036 control->property = msi_dialog_dup_property( dialog, prop, FALSE );
3038 /* double click to activate an item in the list */
3039 SendMessageW( control->hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE,
3040 0, LVS_EX_TWOCLICKACTIVATE );
3042 msi_dialog_update_directory_list( dialog, control );
3044 return ERROR_SUCCESS;
3047 /******************** VolumeCost List ***************************************/
3049 static BOOL str_is_number( LPCWSTR str )
3053 for (i = 0; i < lstrlenW( str ); i++)
3054 if (!isdigitW(str[i]))
3060 static const WCHAR column_keys[][80] =
3062 {'V','o','l','u','m','e','C','o','s','t','V','o','l','u','m','e',0},
3063 {'V','o','l','u','m','e','C','o','s','t','S','i','z','e',0},
3064 {'V','o','l','u','m','e','C','o','s','t','A','v','a','i','l','a','b','l','e',0},
3065 {'V','o','l','u','m','e','C','o','s','t','R','e','q','u','i','r','e','d',0},
3066 {'V','o','l','u','m','e','C','o','s','t','D','i','f','f','e','r','e','n','c','e',0}
3069 static void msi_dialog_vcl_add_columns( msi_dialog *dialog, msi_control *control, MSIRECORD *rec )
3071 LPCWSTR text = MSI_RecordGetString( rec, 10 );
3072 LPCWSTR begin = text, end;
3077 static const WCHAR negative[] = {'-',0};
3081 while ((begin = strchrW( begin, '{' )) && count < 5)
3083 if (!(end = strchrW( begin, '}' )))
3086 num = msi_alloc( (end-begin+1)*sizeof(WCHAR) );
3090 lstrcpynW( num, begin + 1, end - begin );
3091 begin += end - begin + 1;
3093 /* empty braces or '0' hides the column */
3094 if ( !num[0] || !strcmpW( num, szZero ) )
3101 /* the width must be a positive number
3102 * if a width is invalid, all remaining columns are hidden
3104 if ( !strncmpW( num, negative, 1 ) || !str_is_number( num ) ) {
3109 ZeroMemory( &lvc, sizeof(lvc) );
3110 lvc.mask = LVCF_TEXT | LVCF_WIDTH | LVCF_SUBITEM;
3111 lvc.cx = atolW( num );
3112 lvc.pszText = msi_dialog_get_uitext( dialog, column_keys[count] );
3114 SendMessageW( control->hwnd, LVM_INSERTCOLUMNW, count++, (LPARAM)&lvc );
3115 msi_free( lvc.pszText );
3120 static LONGLONG msi_vcl_get_cost( msi_dialog *dialog )
3122 MSIFEATURE *feature;
3124 LONGLONG total_cost = 0;
3126 LIST_FOR_EACH_ENTRY( feature, &dialog->package->features, MSIFEATURE, entry )
3128 if (ERROR_SUCCESS == (MSI_GetFeatureCost(dialog->package, feature,
3129 MSICOSTTREE_SELFONLY, INSTALLSTATE_LOCAL, &each_cost)))
3131 /* each_cost is in 512-byte units */
3132 total_cost += each_cost * 512;
3134 if (ERROR_SUCCESS == (MSI_GetFeatureCost(dialog->package, feature,
3135 MSICOSTTREE_SELFONLY, INSTALLSTATE_ABSENT, &each_cost)))
3137 /* each_cost is in 512-byte units */
3138 total_cost -= each_cost * 512;
3144 static void msi_dialog_vcl_add_drives( msi_dialog *dialog, msi_control *control )
3146 ULARGE_INTEGER total, free;
3147 LONGLONG difference, cost;
3148 WCHAR size_text[MAX_PATH];
3149 WCHAR cost_text[MAX_PATH];
3155 cost = msi_vcl_get_cost(dialog);
3156 StrFormatByteSizeW(cost, cost_text, MAX_PATH);
3158 size = GetLogicalDriveStringsW( 0, NULL );
3159 if ( !size ) return;
3161 drives = msi_alloc( (size + 1) * sizeof(WCHAR) );
3162 if ( !drives ) return;
3164 GetLogicalDriveStringsW( size, drives );
3169 lvitem.mask = LVIF_TEXT;
3171 lvitem.iSubItem = 0;
3172 lvitem.pszText = ptr;
3173 lvitem.cchTextMax = lstrlenW(ptr) + 1;
3174 SendMessageW( control->hwnd, LVM_INSERTITEMW, 0, (LPARAM)&lvitem );
3176 GetDiskFreeSpaceExW(ptr, &free, &total, NULL);
3177 difference = free.QuadPart - cost;
3179 StrFormatByteSizeW(total.QuadPart, size_text, MAX_PATH);
3180 lvitem.iSubItem = 1;
3181 lvitem.pszText = size_text;
3182 lvitem.cchTextMax = lstrlenW(size_text) + 1;
3183 SendMessageW( control->hwnd, LVM_SETITEMW, 0, (LPARAM)&lvitem );
3185 StrFormatByteSizeW(free.QuadPart, size_text, MAX_PATH);
3186 lvitem.iSubItem = 2;
3187 lvitem.pszText = size_text;
3188 lvitem.cchTextMax = lstrlenW(size_text) + 1;
3189 SendMessageW( control->hwnd, LVM_SETITEMW, 0, (LPARAM)&lvitem );
3191 lvitem.iSubItem = 3;
3192 lvitem.pszText = cost_text;
3193 lvitem.cchTextMax = lstrlenW(cost_text) + 1;
3194 SendMessageW( control->hwnd, LVM_SETITEMW, 0, (LPARAM)&lvitem );
3196 StrFormatByteSizeW(difference, size_text, MAX_PATH);
3197 lvitem.iSubItem = 4;
3198 lvitem.pszText = size_text;
3199 lvitem.cchTextMax = lstrlenW(size_text) + 1;
3200 SendMessageW( control->hwnd, LVM_SETITEMW, 0, (LPARAM)&lvitem );
3202 ptr += lstrlenW(ptr) + 1;
3209 static UINT msi_dialog_volumecost_list( msi_dialog *dialog, MSIRECORD *rec )
3211 msi_control *control;
3214 style = LVS_REPORT | WS_VSCROLL | WS_HSCROLL | LVS_SHAREIMAGELISTS |
3215 LVS_AUTOARRANGE | LVS_SINGLESEL | WS_BORDER |
3216 WS_CHILD | WS_TABSTOP | WS_GROUP;
3217 control = msi_dialog_add_control( dialog, rec, WC_LISTVIEWW, style );
3219 return ERROR_FUNCTION_FAILED;
3221 msi_dialog_vcl_add_columns( dialog, control, rec );
3222 msi_dialog_vcl_add_drives( dialog, control );
3224 return ERROR_SUCCESS;
3227 /******************** VolumeSelect Combo ***************************************/
3229 static UINT msi_dialog_volsel_handler( msi_dialog *dialog,
3230 msi_control *control, WPARAM param )
3232 WCHAR text[MAX_PATH];
3237 if (HIWORD(param) != CBN_SELCHANGE)
3238 return ERROR_SUCCESS;
3240 index = SendMessageW( control->hwnd, CB_GETCURSEL, 0, 0 );
3241 if ( index == CB_ERR )
3243 ERR("No ComboBox item selected!\n");
3244 return ERROR_FUNCTION_FAILED;
3247 SendMessageW( control->hwnd, CB_GETLBTEXT, index, (LPARAM)text );
3249 indirect = control->attributes & msidbControlAttributesIndirect;
3250 prop = msi_dialog_dup_property( dialog, control->property, indirect );
3252 msi_dialog_set_property( dialog->package, prop, text );
3255 return ERROR_SUCCESS;
3258 static void msi_dialog_vsc_add_drives( msi_dialog *dialog, msi_control *control )
3263 size = GetLogicalDriveStringsW( 0, NULL );
3264 if ( !size ) return;
3266 drives = msi_alloc( (size + 1) * sizeof(WCHAR) );
3267 if ( !drives ) return;
3269 GetLogicalDriveStringsW( size, drives );
3274 SendMessageW( control->hwnd, CB_ADDSTRING, 0, (LPARAM)ptr );
3275 ptr += lstrlenW(ptr) + 1;
3281 static UINT msi_dialog_volumeselect_combo( msi_dialog *dialog, MSIRECORD *rec )
3283 msi_control *control;
3287 /* FIXME: CBS_OWNERDRAWFIXED */
3288 style = WS_CHILD | WS_VISIBLE | WS_GROUP | WS_TABSTOP |
3289 CBS_DROPDOWNLIST | CBS_SORT | CBS_HASSTRINGS |
3290 WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_RIGHTSCROLLBAR;
3291 control = msi_dialog_add_control( dialog, rec, WC_COMBOBOXW, style );
3293 return ERROR_FUNCTION_FAILED;
3295 control->attributes = MSI_RecordGetInteger( rec, 8 );
3296 control->handler = msi_dialog_volsel_handler;
3297 prop = MSI_RecordGetString( rec, 9 );
3298 control->property = msi_dialog_dup_property( dialog, prop, FALSE );
3300 msi_dialog_vsc_add_drives( dialog, control );
3302 return ERROR_SUCCESS;
3305 static const struct control_handler msi_dialog_handler[] =
3307 { szText, msi_dialog_text_control },
3308 { szPushButton, msi_dialog_button_control },
3309 { szLine, msi_dialog_line_control },
3310 { szBitmap, msi_dialog_bitmap_control },
3311 { szCheckBox, msi_dialog_checkbox_control },
3312 { szScrollableText, msi_dialog_scrolltext_control },
3313 { szComboBox, msi_dialog_combo_control },
3314 { szEdit, msi_dialog_edit_control },
3315 { szMaskedEdit, msi_dialog_maskedit_control },
3316 { szPathEdit, msi_dialog_pathedit_control },
3317 { szProgressBar, msi_dialog_progress_bar },
3318 { szRadioButtonGroup, msi_dialog_radiogroup_control },
3319 { szIcon, msi_dialog_icon_control },
3320 { szSelectionTree, msi_dialog_selection_tree },
3321 { szGroupBox, msi_dialog_group_box },
3322 { szListBox, msi_dialog_list_box },
3323 { szDirectoryCombo, msi_dialog_directory_combo },
3324 { szDirectoryList, msi_dialog_directory_list },
3325 { szVolumeCostList, msi_dialog_volumecost_list },
3326 { szVolumeSelectCombo, msi_dialog_volumeselect_combo },
3329 #define NUM_CONTROL_TYPES (sizeof msi_dialog_handler/sizeof msi_dialog_handler[0])
3331 static UINT msi_dialog_create_controls( MSIRECORD *rec, LPVOID param )
3333 msi_dialog *dialog = param;
3334 LPCWSTR control_type;
3337 /* find and call the function that can create this type of control */
3338 control_type = MSI_RecordGetString( rec, 3 );
3339 for( i=0; i<NUM_CONTROL_TYPES; i++ )
3340 if (!strcmpiW( msi_dialog_handler[i].control_type, control_type ))
3342 if( i != NUM_CONTROL_TYPES )
3343 msi_dialog_handler[i].func( dialog, rec );
3345 ERR("no handler for element type %s\n", debugstr_w(control_type));
3347 return ERROR_SUCCESS;
3350 static UINT msi_dialog_fill_controls( msi_dialog *dialog )
3352 static const WCHAR query[] = {
3353 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
3354 'C','o','n','t','r','o','l',' ','W','H','E','R','E',' ',
3355 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',0};
3358 MSIPACKAGE *package = dialog->package;
3360 TRACE("%p %s\n", dialog, debugstr_w(dialog->name) );
3362 /* query the Control table for all the elements of the control */
3363 r = MSI_OpenQuery( package->db, &view, query, dialog->name );
3364 if( r != ERROR_SUCCESS )
3366 ERR("query failed for dialog %s\n", debugstr_w(dialog->name));
3367 return ERROR_INVALID_PARAMETER;
3370 r = MSI_IterateRecords( view, 0, msi_dialog_create_controls, dialog );
3371 msiobj_release( &view->hdr );
3375 UINT msi_dialog_reset( msi_dialog *dialog )
3377 /* FIXME: should restore the original values of any properties we changed */
3378 return msi_dialog_evaluate_control_conditions( dialog );
3381 /* figure out the height of 10 point MS Sans Serif */
3382 static INT msi_dialog_get_sans_serif_height( HWND hwnd )
3384 static const WCHAR szSansSerif[] = {
3385 'M','S',' ','S','a','n','s',' ','S','e','r','i','f',0 };
3390 HFONT hFont, hOldFont;
3393 hdc = GetDC( hwnd );
3396 memset( &lf, 0, sizeof lf );
3397 lf.lfHeight = MulDiv(12, GetDeviceCaps(hdc, LOGPIXELSY), 72);
3398 strcpyW( lf.lfFaceName, szSansSerif );
3399 hFont = CreateFontIndirectW(&lf);
3402 hOldFont = SelectObject( hdc, hFont );
3403 r = GetTextMetricsW( hdc, &tm );
3405 height = tm.tmHeight;
3406 SelectObject( hdc, hOldFont );
3407 DeleteObject( hFont );
3409 ReleaseDC( hwnd, hdc );
3414 /* fetch the associated record from the Dialog table */
3415 static MSIRECORD *msi_get_dialog_record( msi_dialog *dialog )
3417 static const WCHAR query[] = {
3418 'S','E','L','E','C','T',' ','*',' ',
3419 'F','R','O','M',' ','D','i','a','l','o','g',' ',
3420 'W','H','E','R','E',' ',
3421 '`','D','i','a','l','o','g','`',' ','=',' ','\'','%','s','\'',0};
3422 MSIPACKAGE *package = dialog->package;
3423 MSIRECORD *rec = NULL;
3425 TRACE("%p %s\n", dialog, debugstr_w(dialog->name) );
3427 rec = MSI_QueryGetRecord( package->db, query, dialog->name );
3429 WARN("query failed for dialog %s\n", debugstr_w(dialog->name));
3434 static void msi_dialog_adjust_dialog_pos( msi_dialog *dialog, MSIRECORD *rec, LPRECT pos )
3436 static const WCHAR szScreenX[] = {'S','c','r','e','e','n','X',0};
3437 static const WCHAR szScreenY[] = {'S','c','r','e','e','n','Y',0};
3444 center.x = MSI_RecordGetInteger( rec, 2 );
3445 center.y = MSI_RecordGetInteger( rec, 3 );
3447 sz.cx = MSI_RecordGetInteger( rec, 4 );
3448 sz.cy = MSI_RecordGetInteger( rec, 5 );
3450 sz.cx = msi_dialog_scale_unit( dialog, sz.cx );
3451 sz.cy = msi_dialog_scale_unit( dialog, sz.cy );
3453 xres = msi_get_property_int( dialog->package->db, szScreenX, 0 );
3454 yres = msi_get_property_int( dialog->package->db, szScreenY, 0 );
3456 center.x = MulDiv( center.x, xres, 100 );
3457 center.y = MulDiv( center.y, yres, 100 );
3459 /* turn the client pos into the window rectangle */
3460 if (dialog->package->center_x && dialog->package->center_y)
3462 pos->left = dialog->package->center_x - sz.cx / 2.0;
3463 pos->right = pos->left + sz.cx;
3464 pos->top = dialog->package->center_y - sz.cy / 2.0;
3465 pos->bottom = pos->top + sz.cy;
3469 pos->left = center.x - sz.cx/2;
3470 pos->right = pos->left + sz.cx;
3471 pos->top = center.y - sz.cy/2;
3472 pos->bottom = pos->top + sz.cy;
3474 /* save the center */
3475 dialog->package->center_x = center.x;
3476 dialog->package->center_y = center.y;
3479 dialog->size.cx = sz.cx;
3480 dialog->size.cy = sz.cy;
3482 TRACE("%u %u %u %u\n", pos->left, pos->top, pos->right, pos->bottom);
3484 style = GetWindowLongPtrW( dialog->hwnd, GWL_STYLE );
3485 AdjustWindowRect( pos, style, FALSE );
3488 static void msi_dialog_set_tab_order( msi_dialog *dialog, LPCWSTR first )
3490 struct list tab_chain;
3491 msi_control *control;
3492 HWND prev = HWND_TOP;
3494 list_init( &tab_chain );
3495 if (!(control = msi_dialog_find_control( dialog, first ))) return;
3497 dialog->hWndFocus = control->hwnd;
3500 list_remove( &control->entry );
3501 list_add_tail( &tab_chain, &control->entry );
3502 if (!control->tabnext) break;
3503 control = msi_dialog_find_control( dialog, control->tabnext );
3506 LIST_FOR_EACH_ENTRY( control, &tab_chain, msi_control, entry )
3508 SetWindowPos( control->hwnd, prev, 0, 0, 0, 0,
3509 SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOREDRAW |
3510 SWP_NOREPOSITION | SWP_NOSENDCHANGING | SWP_NOSIZE );
3511 prev = control->hwnd;
3514 /* put them back on the main list */
3515 list_move_head( &dialog->controls, &tab_chain );
3518 static LRESULT msi_dialog_oncreate( HWND hwnd, LPCREATESTRUCTW cs )
3520 static const WCHAR df[] = {
3521 'D','e','f','a','u','l','t','U','I','F','o','n','t',0 };
3522 static const WCHAR dfv[] = {
3523 'M','S',' ','S','h','e','l','l',' ','D','l','g',0 };
3524 msi_dialog *dialog = cs->lpCreateParams;
3525 MSIRECORD *rec = NULL;
3526 LPWSTR title = NULL;
3529 TRACE("%p %p\n", dialog, dialog->package);
3531 dialog->hwnd = hwnd;
3532 SetWindowLongPtrW( hwnd, GWLP_USERDATA, (LONG_PTR) dialog );
3534 rec = msi_get_dialog_record( dialog );
3537 TRACE("No record found for dialog %s\n", debugstr_w(dialog->name));
3541 dialog->scale = msi_dialog_get_sans_serif_height(dialog->hwnd);
3543 msi_dialog_adjust_dialog_pos( dialog, rec, &pos );
3545 dialog->attributes = MSI_RecordGetInteger( rec, 6 );
3547 dialog->default_font = msi_dup_property( dialog->package->db, df );
3548 if (!dialog->default_font)
3550 dialog->default_font = strdupW(dfv);
3551 if (!dialog->default_font) return -1;
3554 title = msi_get_deformatted_field( dialog->package, rec, 7 );
3555 SetWindowTextW( hwnd, title );
3558 SetWindowPos( hwnd, 0, pos.left, pos.top,
3559 pos.right - pos.left, pos.bottom - pos.top,
3560 SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOREDRAW );
3562 msi_dialog_build_font_list( dialog );
3563 msi_dialog_fill_controls( dialog );
3564 msi_dialog_evaluate_control_conditions( dialog );
3565 msi_dialog_set_tab_order( dialog, MSI_RecordGetString( rec, 8 ) );
3566 msiobj_release( &rec->hdr );
3571 static LRESULT msi_dialog_oncommand( msi_dialog *dialog, WPARAM param, HWND hwnd )
3573 msi_control *control = NULL;
3575 TRACE("%p %p %08lx\n", dialog, hwnd, param);
3580 control = msi_dialog_find_control( dialog, dialog->control_default );
3582 case 2: /* escape */
3583 control = msi_dialog_find_control( dialog, dialog->control_cancel );
3586 control = msi_dialog_find_control_by_hwnd( dialog, hwnd );
3591 if( control->handler )
3593 control->handler( dialog, control, param );
3594 msi_dialog_evaluate_control_conditions( dialog );
3601 static LRESULT msi_dialog_onnotify( msi_dialog *dialog, LPARAM param )
3603 LPNMHDR nmhdr = (LPNMHDR) param;
3604 msi_control *control = msi_dialog_find_control_by_hwnd( dialog, nmhdr->hwndFrom );
3606 TRACE("%p %p\n", dialog, nmhdr->hwndFrom);
3608 if ( control && control->handler )
3609 control->handler( dialog, control, param );
3614 static void msi_dialog_setfocus( msi_dialog *dialog )
3616 HWND hwnd = dialog->hWndFocus;
3618 hwnd = GetNextDlgTabItem( dialog->hwnd, hwnd, TRUE);
3619 hwnd = GetNextDlgTabItem( dialog->hwnd, hwnd, FALSE);
3621 dialog->hWndFocus = hwnd;
3624 static LRESULT WINAPI MSIDialog_WndProc( HWND hwnd, UINT msg,
3625 WPARAM wParam, LPARAM lParam )
3627 msi_dialog *dialog = (LPVOID) GetWindowLongPtrW( hwnd, GWLP_USERDATA );
3629 TRACE("0x%04x\n", msg);
3634 dialog->package->center_x = LOWORD(lParam) + dialog->size.cx / 2.0;
3635 dialog->package->center_y = HIWORD(lParam) + dialog->size.cy / 2.0;
3639 return msi_dialog_oncreate( hwnd, (LPCREATESTRUCTW)lParam );
3642 return msi_dialog_oncommand( dialog, wParam, (HWND)lParam );
3645 if( LOWORD(wParam) == WA_INACTIVE )
3646 dialog->hWndFocus = GetFocus();
3648 msi_dialog_setfocus( dialog );
3652 msi_dialog_setfocus( dialog );
3655 /* bounce back to our subclassed static control */
3656 case WM_CTLCOLORSTATIC:
3657 return SendMessageW( (HWND) lParam, WM_CTLCOLORSTATIC, wParam, lParam );
3660 dialog->hwnd = NULL;
3663 return msi_dialog_onnotify( dialog, lParam );
3665 return DefWindowProcW(hwnd, msg, wParam, lParam);
3668 static LRESULT WINAPI MSIHiddenWindowProc( HWND hwnd, UINT msg,
3669 WPARAM wParam, LPARAM lParam )
3671 msi_dialog *dialog = (msi_dialog*) lParam;
3673 TRACE("%d %p\n", msg, dialog);
3677 case WM_MSI_DIALOG_CREATE:
3678 return msi_dialog_run_message_loop( dialog );
3679 case WM_MSI_DIALOG_DESTROY:
3680 msi_dialog_destroy( dialog );
3683 return DefWindowProcW( hwnd, msg, wParam, lParam );
3686 static BOOL msi_dialog_register_class( void )
3690 ZeroMemory( &cls, sizeof cls );
3691 cls.lpfnWndProc = MSIDialog_WndProc;
3692 cls.hInstance = NULL;
3693 cls.hIcon = LoadIconW(0, (LPWSTR)IDI_APPLICATION);
3694 cls.hCursor = LoadCursorW(0, (LPWSTR)IDC_ARROW);
3695 cls.hbrBackground = (HBRUSH)(COLOR_3DFACE + 1);
3696 cls.lpszMenuName = NULL;
3697 cls.lpszClassName = szMsiDialogClass;
3699 if( !RegisterClassW( &cls ) )
3702 cls.lpfnWndProc = MSIHiddenWindowProc;
3703 cls.lpszClassName = szMsiHiddenWindow;
3705 if( !RegisterClassW( &cls ) )
3708 uiThreadId = GetCurrentThreadId();
3710 hMsiHiddenWindow = CreateWindowW( szMsiHiddenWindow, NULL, WS_OVERLAPPED,
3711 0, 0, 100, 100, NULL, NULL, NULL, NULL );
3712 if( !hMsiHiddenWindow )
3718 /* functions that interface to other modules within MSI */
3720 msi_dialog *msi_dialog_create( MSIPACKAGE* package,
3721 LPCWSTR szDialogName, msi_dialog *parent,
3722 msi_dialog_event_handler event_handler )
3724 MSIRECORD *rec = NULL;
3727 TRACE("%p %s\n", package, debugstr_w(szDialogName));
3729 if (!hMsiHiddenWindow)
3730 msi_dialog_register_class();
3732 /* allocate the structure for the dialog to use */
3733 dialog = msi_alloc_zero( sizeof *dialog + sizeof(WCHAR)*strlenW(szDialogName) );
3736 strcpyW( dialog->name, szDialogName );
3737 dialog->parent = parent;
3738 msiobj_addref( &package->hdr );
3739 dialog->package = package;
3740 dialog->event_handler = event_handler;
3741 dialog->finished = 0;
3742 list_init( &dialog->controls );
3743 list_init( &dialog->fonts );
3745 /* verify that the dialog exists */
3746 rec = msi_get_dialog_record( dialog );
3749 msiobj_release( &package->hdr );
3753 dialog->attributes = MSI_RecordGetInteger( rec, 6 );
3754 dialog->control_default = strdupW( MSI_RecordGetString( rec, 9 ) );
3755 dialog->control_cancel = strdupW( MSI_RecordGetString( rec, 10 ) );
3756 msiobj_release( &rec->hdr );
3761 static void msi_process_pending_messages( HWND hdlg )
3765 while( PeekMessageW( &msg, 0, 0, 0, PM_REMOVE ) )
3767 if( hdlg && IsDialogMessageW( hdlg, &msg ))
3769 TranslateMessage( &msg );
3770 DispatchMessageW( &msg );
3774 void msi_dialog_end_dialog( msi_dialog *dialog )
3776 TRACE("%p\n", dialog);
3777 dialog->finished = 1;
3778 PostMessageW(dialog->hwnd, WM_NULL, 0, 0);
3781 void msi_dialog_check_messages( HANDLE handle )
3785 /* in threads other than the UI thread, block */
3786 if( uiThreadId != GetCurrentThreadId() )
3789 WaitForSingleObject( handle, INFINITE );
3793 /* there's two choices for the UI thread */
3796 msi_process_pending_messages( NULL );
3802 * block here until somebody creates a new dialog or
3803 * the handle we're waiting on becomes ready
3805 r = MsgWaitForMultipleObjects( 1, &handle, 0, INFINITE, QS_ALLINPUT );
3806 if( r == WAIT_OBJECT_0 )
3811 UINT msi_dialog_run_message_loop( msi_dialog *dialog )
3816 if( uiThreadId != GetCurrentThreadId() )
3817 return SendMessageW( hMsiHiddenWindow, WM_MSI_DIALOG_CREATE, 0, (LPARAM) dialog );
3819 /* create the dialog window, don't show it yet */
3820 style = WS_OVERLAPPED;
3821 if( dialog->attributes & msidbDialogAttributesVisible )
3822 style |= WS_VISIBLE;
3824 hwnd = CreateWindowW( szMsiDialogClass, dialog->name, style,
3825 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
3826 NULL, NULL, NULL, dialog );
3829 ERR("Failed to create dialog %s\n", debugstr_w( dialog->name ));
3830 return ERROR_FUNCTION_FAILED;
3833 ShowWindow( hwnd, SW_SHOW );
3834 /* UpdateWindow( hwnd ); - and causes the transparent static controls not to paint */
3836 if( dialog->attributes & msidbDialogAttributesModal )
3838 while( !dialog->finished )
3840 MsgWaitForMultipleObjects( 0, NULL, 0, INFINITE, QS_ALLINPUT );
3841 msi_process_pending_messages( dialog->hwnd );
3845 return ERROR_IO_PENDING;
3847 return ERROR_SUCCESS;
3850 void msi_dialog_do_preview( msi_dialog *dialog )
3853 dialog->attributes |= msidbDialogAttributesVisible;
3854 dialog->attributes &= ~msidbDialogAttributesModal;
3855 msi_dialog_run_message_loop( dialog );
3858 void msi_dialog_destroy( msi_dialog *dialog )
3860 msi_font *font, *next;
3862 if( uiThreadId != GetCurrentThreadId() )
3864 SendMessageW( hMsiHiddenWindow, WM_MSI_DIALOG_DESTROY, 0, (LPARAM) dialog );
3869 ShowWindow( dialog->hwnd, SW_HIDE );
3872 DestroyWindow( dialog->hwnd );
3874 /* unsubscribe events */
3875 ControlEvent_CleanupDialogSubscriptions(dialog->package, dialog->name);
3877 /* destroy the list of controls */
3878 while( !list_empty( &dialog->controls ) )
3882 t = LIST_ENTRY( list_head( &dialog->controls ),
3883 msi_control, entry );
3884 msi_destroy_control( t );
3887 /* destroy the list of fonts */
3888 LIST_FOR_EACH_ENTRY_SAFE( font, next, &dialog->fonts, msi_font, entry )
3890 list_remove( &font->entry );
3891 DeleteObject( font->hfont );
3894 msi_free( dialog->default_font );
3896 msi_free( dialog->control_default );
3897 msi_free( dialog->control_cancel );
3898 msiobj_release( &dialog->package->hdr );
3899 dialog->package = NULL;
3903 void msi_dialog_unregister_class( void )
3905 DestroyWindow( hMsiHiddenWindow );
3906 hMsiHiddenWindow = NULL;
3907 UnregisterClassW( szMsiDialogClass, NULL );
3908 UnregisterClassW( szMsiHiddenWindow, NULL );
3912 static UINT error_dialog_handler(MSIPACKAGE *package, LPCWSTR event,
3913 LPCWSTR argument, msi_dialog* dialog)
3915 static const WCHAR end_dialog[] = {'E','n','d','D','i','a','l','o','g',0};
3916 static const WCHAR error_abort[] = {'E','r','r','o','r','A','b','o','r','t',0};
3917 static const WCHAR error_cancel[] = {'E','r','r','o','r','C','a','n','c','e','l',0};
3918 static const WCHAR error_no[] = {'E','r','r','o','r','N','o',0};
3919 static const WCHAR result_prop[] = {
3920 'M','S','I','E','r','r','o','r','D','i','a','l','o','g','R','e','s','u','l','t',0
3923 if ( strcmpW( event, end_dialog ) )
3924 return ERROR_SUCCESS;
3926 if ( !strcmpW( argument, error_abort ) || !strcmpW( argument, error_cancel ) ||
3927 !strcmpW( argument, error_no ) )
3929 msi_set_property( package->db, result_prop, error_abort );
3932 ControlEvent_CleanupSubscriptions(package);
3933 msi_dialog_end_dialog( dialog );
3935 return ERROR_SUCCESS;
3938 static UINT msi_error_dialog_set_error( MSIPACKAGE *package, LPWSTR error_dialog, LPWSTR error )
3942 static const WCHAR update[] =
3943 {'U','P','D','A','T','E',' ','`','C','o','n','t','r','o','l','`',' ',
3944 'S','E','T',' ','`','T','e','x','t','`',' ','=',' ','\'','%','s','\'',' ',
3945 'W','H','E','R','E', ' ','`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',' ',
3946 'A','N','D',' ','`','C','o','n','t','r','o','l','`',' ','=',' ',
3947 '\'','E','r','r','o','r','T','e','x','t','\'',0};
3949 row = MSI_QueryGetRecord( package->db, update, error, error_dialog );
3951 return ERROR_FUNCTION_FAILED;
3953 msiobj_release(&row->hdr);
3954 return ERROR_SUCCESS;
3957 UINT msi_spawn_error_dialog( MSIPACKAGE *package, LPWSTR error_dialog, LPWSTR error )
3960 WCHAR result[MAX_PATH];
3961 UINT r = ERROR_SUCCESS;
3962 DWORD size = MAX_PATH;
3965 static const WCHAR pn_prop[] = {'P','r','o','d','u','c','t','N','a','m','e',0};
3966 static const WCHAR title_fmt[] = {'%','s',' ','W','a','r','n','i','n','g',0};
3967 static const WCHAR error_abort[] = {'E','r','r','o','r','A','b','o','r','t',0};
3968 static const WCHAR result_prop[] = {
3969 'M','S','I','E','r','r','o','r','D','i','a','l','o','g','R','e','s','u','l','t',0
3972 if ( (msi_get_property_int( package->db, szUILevel, 0 ) & INSTALLUILEVEL_MASK) == INSTALLUILEVEL_NONE )
3973 return ERROR_SUCCESS;
3975 if ( !error_dialog )
3977 LPWSTR product_name = msi_dup_property( package->db, pn_prop );
3978 WCHAR title[MAX_PATH];
3980 sprintfW( title, title_fmt, product_name );
3981 res = MessageBoxW( NULL, error, title, MB_OKCANCEL | MB_ICONWARNING );
3983 msi_free( product_name );
3986 return ERROR_SUCCESS;
3988 return ERROR_FUNCTION_FAILED;
3991 r = msi_error_dialog_set_error( package, error_dialog, error );
3992 if ( r != ERROR_SUCCESS )
3995 dialog = msi_dialog_create( package, error_dialog, package->dialog,
3996 error_dialog_handler );
3998 return ERROR_FUNCTION_FAILED;
4000 dialog->finished = FALSE;
4001 r = msi_dialog_run_message_loop( dialog );
4002 if ( r != ERROR_SUCCESS )
4005 r = msi_get_property( package->db, result_prop, result, &size );
4006 if ( r != ERROR_SUCCESS)
4009 if ( !strcmpW( result, error_abort ) )
4010 r = ERROR_FUNCTION_FAILED;
4013 msi_dialog_destroy( dialog );