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);
48 extern HINSTANCE msi_hInstance;
50 struct msi_control_tag;
51 typedef struct msi_control_tag msi_control;
52 typedef UINT (*msi_handler)( msi_dialog *, msi_control *, WPARAM );
53 typedef void (*msi_update)( msi_dialog *, msi_control * );
55 struct msi_control_tag
68 float progress_current;
74 typedef struct msi_font_tag
76 struct msi_font_tag *next;
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[] = {
117 'M','s','i','D','i','a','l','o','g','C','l','o','s','e','C','l','a','s','s',0
119 static const WCHAR szMsiHiddenWindow[] = {
120 'M','s','i','H','i','d','d','e','n','W','i','n','d','o','w',0 };
121 static const WCHAR szStatic[] = { 'S','t','a','t','i','c',0 };
122 static const WCHAR szButton[] = { 'B','U','T','T','O','N', 0 };
123 static const WCHAR szButtonData[] = { 'M','S','I','D','A','T','A',0 };
124 static const WCHAR szProgress[] = { 'P','r','o','g','r','e','s','s',0 };
125 static const WCHAR szText[] = { 'T','e','x','t',0 };
126 static const WCHAR szPushButton[] = { 'P','u','s','h','B','u','t','t','o','n',0 };
127 static const WCHAR szLine[] = { 'L','i','n','e',0 };
128 static const WCHAR szBitmap[] = { 'B','i','t','m','a','p',0 };
129 static const WCHAR szCheckBox[] = { 'C','h','e','c','k','B','o','x',0 };
130 static const WCHAR szScrollableText[] = {
131 'S','c','r','o','l','l','a','b','l','e','T','e','x','t',0 };
132 static const WCHAR szComboBox[] = { 'C','o','m','b','o','B','o','x',0 };
133 static const WCHAR szEdit[] = { 'E','d','i','t',0 };
134 static const WCHAR szMaskedEdit[] = { 'M','a','s','k','e','d','E','d','i','t',0 };
135 static const WCHAR szPathEdit[] = { 'P','a','t','h','E','d','i','t',0 };
136 static const WCHAR szProgressBar[] = {
137 'P','r','o','g','r','e','s','s','B','a','r',0 };
138 static const WCHAR szSetProgress[] = {
139 'S','e','t','P','r','o','g','r','e','s','s',0 };
140 static const WCHAR szRadioButtonGroup[] = {
141 'R','a','d','i','o','B','u','t','t','o','n','G','r','o','u','p',0 };
142 static const WCHAR szIcon[] = { 'I','c','o','n',0 };
143 static const WCHAR szSelectionTree[] = {
144 'S','e','l','e','c','t','i','o','n','T','r','e','e',0 };
145 static const WCHAR szGroupBox[] = { 'G','r','o','u','p','B','o','x',0 };
146 static const WCHAR szListBox[] = { 'L','i','s','t','B','o','x',0 };
147 static const WCHAR szDirectoryCombo[] = { 'D','i','r','e','c','t','o','r','y','C','o','m','b','o',0 };
148 static const WCHAR szDirectoryList[] = { 'D','i','r','e','c','t','o','r','y','L','i','s','t',0 };
149 static const WCHAR szVolumeCostList[] = { 'V','o','l','u','m','e','C','o','s','t','L','i','s','t',0 };
150 static const WCHAR szVolumeSelectCombo[] = { 'V','o','l','u','m','e','S','e','l','e','c','t','C','o','m','b','o',0 };
151 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};
152 static const WCHAR szSelectionPath[] = {'S','e','l','e','c','t','i','o','n','P','a','t','h',0};
153 static const WCHAR szProperty[] = {'P','r','o','p','e','r','t','y',0};
155 static UINT msi_dialog_checkbox_handler( msi_dialog *, msi_control *, WPARAM );
156 static void msi_dialog_checkbox_sync_state( msi_dialog *, msi_control * );
157 static UINT msi_dialog_button_handler( msi_dialog *, msi_control *, WPARAM );
158 static UINT msi_dialog_edit_handler( msi_dialog *, msi_control *, WPARAM );
159 static UINT msi_dialog_radiogroup_handler( msi_dialog *, msi_control *, WPARAM );
160 static UINT msi_dialog_evaluate_control_conditions( msi_dialog *dialog );
161 static LRESULT WINAPI MSIRadioGroup_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
162 static MSIFEATURE *msi_seltree_get_selected_feature( msi_control *control );
164 /* dialog sequencing */
166 #define WM_MSI_DIALOG_CREATE (WM_USER+0x100)
167 #define WM_MSI_DIALOG_DESTROY (WM_USER+0x101)
169 #define USER_INSTALLSTATE_ALL 0x1000
171 static DWORD uiThreadId;
172 static HWND hMsiHiddenWindow;
174 static LPWSTR msi_get_window_text( HWND hwnd );
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, 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 font->next = dialog->font_list;
314 dialog->font_list = font;
316 font->color = MSI_RecordGetInteger( rec, 4 );
318 memset( &lf, 0, sizeof lf );
319 face = MSI_RecordGetString( rec, 2 );
320 lf.lfHeight = MSI_RecordGetInteger( rec, 3 );
321 style = MSI_RecordGetInteger( rec, 5 );
322 if( style & msidbTextStyleStyleBitsBold )
323 lf.lfWeight = FW_BOLD;
324 if( style & msidbTextStyleStyleBitsItalic )
326 if( style & msidbTextStyleStyleBitsUnderline )
327 lf.lfUnderline = TRUE;
328 if( style & msidbTextStyleStyleBitsStrike )
329 lf.lfStrikeOut = TRUE;
330 lstrcpynW( lf.lfFaceName, face, LF_FACESIZE );
332 /* adjust the height */
333 hdc = GetDC( dialog->hwnd );
336 lf.lfHeight = -MulDiv(lf.lfHeight, GetDeviceCaps(hdc, LOGPIXELSY), 72);
337 ReleaseDC( dialog->hwnd, hdc );
340 font->hfont = CreateFontIndirectW( &lf );
342 TRACE("Adding font style %s\n", debugstr_w(font->name) );
344 return ERROR_SUCCESS;
347 static msi_font *msi_dialog_find_font( msi_dialog *dialog, LPCWSTR name )
351 for( font = dialog->font_list; font; font = font->next )
352 if( !strcmpW( font->name, name ) ) /* FIXME: case sensitive? */
358 static UINT msi_dialog_set_font( msi_dialog *dialog, HWND hwnd, LPCWSTR name )
362 font = msi_dialog_find_font( dialog, name );
364 SendMessageW( hwnd, WM_SETFONT, (WPARAM) font->hfont, TRUE );
366 ERR("No font entry for %s\n", debugstr_w(name));
367 return ERROR_SUCCESS;
370 static UINT msi_dialog_build_font_list( msi_dialog *dialog )
372 static const WCHAR query[] = {
373 'S','E','L','E','C','T',' ','*',' ',
374 'F','R','O','M',' ','`','T','e','x','t','S','t','y','l','e','`',' ',0
377 MSIQUERY *view = NULL;
379 TRACE("dialog %p\n", dialog );
381 r = MSI_OpenQuery( dialog->package->db, &view, query );
382 if( r != ERROR_SUCCESS )
385 r = MSI_IterateRecords( view, NULL, msi_dialog_add_font, dialog );
386 msiobj_release( &view->hdr );
391 static void msi_destroy_control( msi_control *t )
393 list_remove( &t->entry );
394 /* leave dialog->hwnd - destroying parent destroys child windows */
395 msi_free( t->property );
396 msi_free( t->value );
398 DeleteObject( t->hBitmap );
400 DestroyIcon( t->hIcon );
401 msi_free( t->tabnext );
404 FreeLibrary( t->hDll );
408 static msi_control *msi_dialog_create_window( msi_dialog *dialog,
409 MSIRECORD *rec, DWORD exstyle, LPCWSTR szCls, LPCWSTR name, LPCWSTR text,
410 DWORD style, HWND parent )
412 DWORD x, y, width, height;
413 LPWSTR font = NULL, title_font = NULL;
414 LPCWSTR title = NULL;
415 msi_control *control;
419 control = msi_alloc( sizeof *control + strlenW(name)*sizeof(WCHAR) );
423 strcpyW( control->name, name );
424 list_add_tail( &dialog->controls, &control->entry );
425 control->handler = NULL;
426 control->update = NULL;
427 control->property = NULL;
428 control->value = NULL;
429 control->hBitmap = NULL;
430 control->hIcon = NULL;
431 control->hDll = NULL;
432 control->tabnext = strdupW( MSI_RecordGetString( rec, 11) );
433 control->type = strdupW( MSI_RecordGetString( rec, 3 ) );
434 control->progress_current = 0;
435 control->progress_max = 100;
437 x = MSI_RecordGetInteger( rec, 4 );
438 y = MSI_RecordGetInteger( rec, 5 );
439 width = MSI_RecordGetInteger( rec, 6 );
440 height = MSI_RecordGetInteger( rec, 7 );
442 x = msi_dialog_scale_unit( dialog, x );
443 y = msi_dialog_scale_unit( dialog, y );
444 width = msi_dialog_scale_unit( dialog, width );
445 height = msi_dialog_scale_unit( dialog, height );
449 deformat_string( dialog->package, text, &title_font );
450 font = msi_dialog_get_style( title_font, &title );
453 control->hwnd = CreateWindowExW( exstyle, szCls, title, style,
454 x, y, width, height, parent, NULL, NULL, NULL );
456 TRACE("Dialog %s control %s hwnd %p\n",
457 debugstr_w(dialog->name), debugstr_w(text), control->hwnd );
459 msi_dialog_set_font( dialog, control->hwnd,
460 font ? font : dialog->default_font );
462 msi_free( title_font );
468 static LPWSTR msi_dialog_get_uitext( msi_dialog *dialog, LPCWSTR key )
473 static const WCHAR query[] = {
474 's','e','l','e','c','t',' ','*',' ',
475 'f','r','o','m',' ','`','U','I','T','e','x','t','`',' ',
476 'w','h','e','r','e',' ','`','K','e','y','`',' ','=',' ','\'','%','s','\'',0
479 rec = MSI_QueryGetRecord( dialog->package->db, query, key );
480 if (!rec) return NULL;
481 text = strdupW( MSI_RecordGetString( rec, 2 ) );
482 msiobj_release( &rec->hdr );
486 static MSIRECORD *msi_get_binary_record( MSIDATABASE *db, LPCWSTR name )
488 static const WCHAR query[] = {
489 's','e','l','e','c','t',' ','*',' ',
490 'f','r','o','m',' ','B','i','n','a','r','y',' ',
491 'w','h','e','r','e',' ',
492 '`','N','a','m','e','`',' ','=',' ','\'','%','s','\'',0
495 return MSI_QueryGetRecord( db, query, name );
498 static LPWSTR msi_create_tmp_path(void)
504 r = GetTempPathW( MAX_PATH, tmp );
507 len = lstrlenW( tmp ) + 20;
508 path = msi_alloc( len * sizeof (WCHAR) );
511 r = GetTempFileNameW( tmp, szMsi, 0, path );
522 static HANDLE msi_load_image( MSIDATABASE *db, LPCWSTR name, UINT type,
523 UINT cx, UINT cy, UINT flags )
525 MSIRECORD *rec = NULL;
526 HANDLE himage = NULL;
530 TRACE("%p %s %u %u %08x\n", db, debugstr_w(name), cx, cy, flags);
532 tmp = msi_create_tmp_path();
536 rec = msi_get_binary_record( db, name );
539 r = MSI_RecordStreamToFile( rec, 2, tmp );
540 if( r == ERROR_SUCCESS )
542 himage = LoadImageW( 0, tmp, type, cx, cy, flags );
544 msiobj_release( &rec->hdr );
552 static HICON msi_load_icon( MSIDATABASE *db, LPCWSTR text, UINT attributes )
554 DWORD cx = 0, cy = 0, flags;
556 flags = LR_LOADFROMFILE | LR_DEFAULTSIZE;
557 if( attributes & msidbControlAttributesFixedSize )
559 flags &= ~LR_DEFAULTSIZE;
560 if( attributes & msidbControlAttributesIconSize16 )
565 if( attributes & msidbControlAttributesIconSize32 )
570 /* msidbControlAttributesIconSize48 handled by above logic */
572 return msi_load_image( db, text, IMAGE_ICON, cx, cy, flags );
575 static void msi_dialog_update_controls( msi_dialog *dialog, LPCWSTR property )
577 msi_control *control;
579 LIST_FOR_EACH_ENTRY( control, &dialog->controls, msi_control, entry )
581 if ( !lstrcmpW( control->property, property ) && control->update )
582 control->update( dialog, control );
586 /* called from the Control Event subscription code */
587 void msi_dialog_handle_event( msi_dialog* dialog, LPCWSTR control,
588 LPCWSTR attribute, MSIRECORD *rec )
591 LPCWSTR font_text, text = NULL;
594 ctrl = msi_dialog_find_control( dialog, control );
597 if( !lstrcmpW(attribute, szText) )
599 font_text = MSI_RecordGetString( rec , 1 );
600 font = msi_dialog_get_style( font_text, &text );
601 if (!text) text = szEmpty;
602 SetWindowTextW( ctrl->hwnd, text );
604 msi_dialog_check_messages( NULL );
606 else if( !lstrcmpW(attribute, szProgress) )
610 func = MSI_RecordGetInteger( rec , 1 );
611 val = MSI_RecordGetInteger( rec , 2 );
613 TRACE("progress: func %u, val %u\n", func, val);
618 ctrl->progress_max = val;
619 ctrl->progress_current = 0;
620 SendMessageW(ctrl->hwnd, PBM_SETRANGE, 0, MAKELPARAM(0,100));
621 SendMessageW(ctrl->hwnd, PBM_SETPOS, 0, 0);
623 case 1: /* FIXME: not sure what this is supposed to do */
626 ctrl->progress_current += val;
627 if (ctrl->progress_current > ctrl->progress_max)
628 ctrl->progress_current = ctrl->progress_max;
629 SendMessageW(ctrl->hwnd, PBM_SETPOS, MulDiv(100, ctrl->progress_current, ctrl->progress_max), 0);
632 FIXME("Unknown progress message %u\n", func);
636 else if ( !lstrcmpW(attribute, szProperty) )
638 MSIFEATURE *feature = msi_seltree_get_selected_feature( ctrl );
639 MSI_SetPropertyW( dialog->package, ctrl->property, feature->Directory );
641 else if ( !lstrcmpW(attribute, szSelectionPath) )
643 LPWSTR prop = msi_dialog_dup_property( dialog, ctrl->property, TRUE );
646 path = msi_dup_property( dialog->package, prop );
647 SetWindowTextW( ctrl->hwnd, path );
653 FIXME("Attribute %s not being set\n", debugstr_w(attribute));
658 static void msi_dialog_map_events(msi_dialog* dialog, LPCWSTR control)
660 static const WCHAR Query[] = {
661 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
662 '`','E','v','e','n','t','M','a','p','p','i','n','g','`',' ',
663 'W','H','E','R','E',' ',
664 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',' ',
666 '`','C','o','n','t','r','o','l','_','`',' ','=',' ','\'','%','s','\'',0
669 LPCWSTR event, attribute;
671 row = MSI_QueryGetRecord( dialog->package->db, Query, dialog->name, control );
675 event = MSI_RecordGetString( row, 3 );
676 attribute = MSI_RecordGetString( row, 4 );
677 ControlEvent_SubscribeToEvent( dialog->package, dialog, event, control, attribute );
678 msiobj_release( &row->hdr );
681 /* everything except radio buttons */
682 static msi_control *msi_dialog_add_control( msi_dialog *dialog,
683 MSIRECORD *rec, LPCWSTR szCls, DWORD style )
689 name = MSI_RecordGetString( rec, 2 );
690 attributes = MSI_RecordGetInteger( rec, 8 );
691 text = MSI_RecordGetString( rec, 10 );
693 TRACE("%s, %s, %08x, %s, %08x\n", debugstr_w(szCls), debugstr_w(name),
694 attributes, debugstr_w(text), style);
696 if( attributes & msidbControlAttributesVisible )
698 if( ~attributes & msidbControlAttributesEnabled )
699 style |= WS_DISABLED;
700 if( attributes & msidbControlAttributesSunken )
701 exstyle |= WS_EX_CLIENTEDGE;
703 msi_dialog_map_events(dialog, name);
705 return msi_dialog_create_window( dialog, rec, exstyle, szCls, name,
706 text, style, dialog->hwnd );
717 * we don't erase our own background,
718 * so we have to make sure that the parent window redraws first
720 static void msi_text_on_settext( HWND hWnd )
725 hParent = GetParent( hWnd );
726 GetWindowRect( hWnd, &rc );
727 MapWindowPoints( NULL, hParent, (LPPOINT) &rc, 2 );
728 InvalidateRect( hParent, &rc, TRUE );
731 static LRESULT WINAPI
732 MSIText_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
734 struct msi_text_info *info;
737 TRACE("%p %04x %08lx %08lx\n", hWnd, msg, wParam, lParam);
739 info = GetPropW(hWnd, szButtonData);
741 if( msg == WM_CTLCOLORSTATIC &&
742 ( info->attributes & msidbControlAttributesTransparent ) )
744 SetBkMode( (HDC)wParam, TRANSPARENT );
745 return (LRESULT) GetStockObject(NULL_BRUSH);
748 r = CallWindowProcW(info->oldproc, hWnd, msg, wParam, lParam);
750 SetTextColor( (HDC)wParam, info->font->color );
755 msi_text_on_settext( hWnd );
759 RemovePropW( hWnd, szButtonData );
766 static UINT msi_dialog_text_control( msi_dialog *dialog, MSIRECORD *rec )
768 msi_control *control;
769 struct msi_text_info *info;
770 LPCWSTR text, ptr, prop;
773 TRACE("%p %p\n", dialog, rec);
775 control = msi_dialog_add_control( dialog, rec, szStatic, SS_LEFT | WS_GROUP );
777 return ERROR_FUNCTION_FAILED;
779 info = msi_alloc( sizeof *info );
781 return ERROR_SUCCESS;
783 control->attributes = MSI_RecordGetInteger( rec, 8 );
784 prop = MSI_RecordGetString( rec, 9 );
785 control->property = msi_dialog_dup_property( dialog, prop, FALSE );
787 text = MSI_RecordGetString( rec, 10 );
788 font_name = msi_dialog_get_style( text, &ptr );
789 info->font = ( font_name ) ? msi_dialog_find_font( dialog, font_name ) : NULL;
790 msi_free( font_name );
792 info->attributes = MSI_RecordGetInteger( rec, 8 );
793 if( info->attributes & msidbControlAttributesTransparent )
794 SetWindowLongPtrW( control->hwnd, GWL_EXSTYLE, WS_EX_TRANSPARENT );
796 info->oldproc = (WNDPROC) SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
797 (LONG_PTR)MSIText_WndProc );
798 SetPropW( control->hwnd, szButtonData, info );
800 ControlEvent_SubscribeToEvent( dialog->package, dialog,
801 szSelectionPath, control->name, szSelectionPath );
803 return ERROR_SUCCESS;
806 /* strip any leading text style label from text field */
807 static WCHAR *msi_get_binary_name( MSIPACKAGE *package, MSIRECORD *rec )
811 text = msi_get_deformatted_field( package, rec, 10 );
816 while (*p && *p != '{') p++;
817 if (!*p++) return text;
819 while (*p && *p != '}') p++;
820 if (!*p++) return text;
827 static UINT msi_dialog_button_control( msi_dialog *dialog, MSIRECORD *rec )
829 msi_control *control;
830 UINT attributes, style;
832 TRACE("%p %p\n", dialog, rec);
835 attributes = MSI_RecordGetInteger( rec, 8 );
836 if( attributes & msidbControlAttributesIcon )
839 control = msi_dialog_add_control( dialog, rec, szButton, style );
841 return ERROR_FUNCTION_FAILED;
843 control->handler = msi_dialog_button_handler;
845 if (attributes & msidbControlAttributesIcon)
848 LPWSTR name = msi_get_binary_name( dialog->package, rec );
849 control->hIcon = msi_load_icon( dialog->package->db, name, attributes );
852 SendMessageW( control->hwnd, BM_SETIMAGE, IMAGE_ICON, (LPARAM) control->hIcon );
855 ERR("Failed to load icon %s\n", debugstr_w(name));
859 return ERROR_SUCCESS;
862 static LPWSTR msi_get_checkbox_value( msi_dialog *dialog, LPCWSTR prop )
864 static const WCHAR query[] = {
865 'S','E','L','E','C','T',' ','*',' ',
866 'F','R','O','M',' ','`','C','h','e','c','k','B','o','x','`',' ',
867 'W','H','E','R','E',' ',
868 '`','P','r','o','p','e','r','t','y','`',' ','=',' ',
871 MSIRECORD *rec = NULL;
874 /* find if there is a value associated with the checkbox */
875 rec = MSI_QueryGetRecord( dialog->package->db, query, prop );
879 ret = msi_get_deformatted_field( dialog->package, rec, 2 );
885 msiobj_release( &rec->hdr );
889 ret = msi_dup_property( dialog->package, prop );
899 static UINT msi_dialog_checkbox_control( msi_dialog *dialog, MSIRECORD *rec )
901 msi_control *control;
904 TRACE("%p %p\n", dialog, rec);
906 control = msi_dialog_add_control( dialog, rec, szButton,
907 BS_CHECKBOX | BS_MULTILINE | WS_TABSTOP );
908 control->handler = msi_dialog_checkbox_handler;
909 control->update = msi_dialog_checkbox_sync_state;
910 prop = MSI_RecordGetString( rec, 9 );
913 control->property = strdupW( prop );
914 control->value = msi_get_checkbox_value( dialog, prop );
915 TRACE("control %s value %s\n", debugstr_w(control->property),
916 debugstr_w(control->value));
918 msi_dialog_checkbox_sync_state( dialog, control );
920 return ERROR_SUCCESS;
923 static UINT msi_dialog_line_control( msi_dialog *dialog, MSIRECORD *rec )
927 DWORD style, exstyle = 0;
928 DWORD x, y, width, height;
929 msi_control *control;
931 TRACE("%p %p\n", dialog, rec);
933 style = WS_CHILD | SS_ETCHEDHORZ | SS_SUNKEN;
935 name = MSI_RecordGetString( rec, 2 );
936 attributes = MSI_RecordGetInteger( rec, 8 );
938 if( attributes & msidbControlAttributesVisible )
940 if( ~attributes & msidbControlAttributesEnabled )
941 style |= WS_DISABLED;
942 if( attributes & msidbControlAttributesSunken )
943 exstyle |= WS_EX_CLIENTEDGE;
945 msi_dialog_map_events(dialog, name);
947 control = msi_alloc( sizeof(*control) + strlenW(name) * sizeof(WCHAR) );
949 return ERROR_OUTOFMEMORY;
951 strcpyW( control->name, name );
952 list_add_head( &dialog->controls, &control->entry );
953 control->handler = NULL;
954 control->property = NULL;
955 control->value = NULL;
956 control->hBitmap = NULL;
957 control->hIcon = NULL;
958 control->hDll = NULL;
959 control->tabnext = strdupW( MSI_RecordGetString( rec, 11) );
960 control->type = strdupW( MSI_RecordGetString( rec, 3 ) );
961 control->progress_current = 0;
962 control->progress_max = 100;
964 x = MSI_RecordGetInteger( rec, 4 );
965 y = MSI_RecordGetInteger( rec, 5 );
966 width = MSI_RecordGetInteger( rec, 6 );
968 x = msi_dialog_scale_unit( dialog, x );
969 y = msi_dialog_scale_unit( dialog, y );
970 width = msi_dialog_scale_unit( dialog, width );
971 height = 2; /* line is exactly 2 units in height */
973 control->hwnd = CreateWindowExW( exstyle, szStatic, NULL, style,
974 x, y, width, height, dialog->hwnd, NULL, NULL, NULL );
976 TRACE("Dialog %s control %s hwnd %p\n",
977 debugstr_w(dialog->name), debugstr_w(name), control->hwnd );
979 return ERROR_SUCCESS;
982 /******************** Scroll Text ********************************************/
984 struct msi_scrolltext_info
987 msi_control *control;
991 static LRESULT WINAPI
992 MSIScrollText_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
994 struct msi_scrolltext_info *info;
997 TRACE("%p %04x %08lx %08lx\n", hWnd, msg, wParam, lParam);
999 info = GetPropW( hWnd, szButtonData );
1001 r = CallWindowProcW( info->oldproc, hWnd, msg, wParam, lParam );
1007 RemovePropW( hWnd, szButtonData );
1010 /* native MSI sets a wait cursor here */
1011 msi_dialog_button_handler( info->dialog, info->control, BN_CLICKED );
1017 struct msi_streamin_info
1024 static DWORD CALLBACK
1025 msi_richedit_stream_in( DWORD_PTR arg, LPBYTE buffer, LONG count, LONG *pcb )
1027 struct msi_streamin_info *info = (struct msi_streamin_info*) arg;
1029 if( (count + info->offset) > info->length )
1030 count = info->length - info->offset;
1031 memcpy( buffer, &info->string[ info->offset ], count );
1033 info->offset += count;
1035 TRACE("%d/%d\n", info->offset, info->length);
1040 static void msi_scrolltext_add_text( msi_control *control, LPCWSTR text )
1042 struct msi_streamin_info info;
1045 info.string = strdupWtoA( text );
1047 info.length = lstrlenA( info.string ) + 1;
1049 es.dwCookie = (DWORD_PTR) &info;
1051 es.pfnCallback = msi_richedit_stream_in;
1053 SendMessageW( control->hwnd, EM_STREAMIN, SF_RTF, (LPARAM) &es );
1055 msi_free( info.string );
1058 static UINT msi_dialog_scrolltext_control( msi_dialog *dialog, MSIRECORD *rec )
1060 static const WCHAR szRichEdit20W[] = {
1061 'R','i','c','h','E','d','i','t','2','0','W',0
1063 struct msi_scrolltext_info *info;
1064 msi_control *control;
1069 info = msi_alloc( sizeof *info );
1071 return ERROR_FUNCTION_FAILED;
1073 hRichedit = LoadLibraryA("riched20");
1075 style = WS_BORDER | ES_MULTILINE | WS_VSCROLL |
1076 ES_READONLY | ES_AUTOVSCROLL | WS_TABSTOP;
1077 control = msi_dialog_add_control( dialog, rec, szRichEdit20W, style );
1080 FreeLibrary( hRichedit );
1082 return ERROR_FUNCTION_FAILED;
1085 control->hDll = hRichedit;
1087 info->dialog = dialog;
1088 info->control = control;
1090 /* subclass the static control */
1091 info->oldproc = (WNDPROC) SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
1092 (LONG_PTR)MSIScrollText_WndProc );
1093 SetPropW( control->hwnd, szButtonData, info );
1095 /* add the text into the richedit */
1096 text = MSI_RecordGetString( rec, 10 );
1098 msi_scrolltext_add_text( control, text );
1100 return ERROR_SUCCESS;
1103 static HBITMAP msi_load_picture( MSIDATABASE *db, LPCWSTR name,
1104 INT cx, INT cy, DWORD flags )
1106 HBITMAP hOleBitmap = 0, hBitmap = 0, hOldSrcBitmap, hOldDestBitmap;
1107 MSIRECORD *rec = NULL;
1108 IStream *stm = NULL;
1109 IPicture *pic = NULL;
1114 rec = msi_get_binary_record( db, name );
1118 r = MSI_RecordGetIStream( rec, 2, &stm );
1119 msiobj_release( &rec->hdr );
1120 if( r != ERROR_SUCCESS )
1123 r = OleLoadPicture( stm, 0, TRUE, &IID_IPicture, (LPVOID*) &pic );
1124 IStream_Release( stm );
1127 ERR("failed to load picture\n");
1131 r = IPicture_get_Handle( pic, (OLE_HANDLE*) &hOleBitmap );
1134 ERR("failed to get bitmap handle\n");
1138 /* make the bitmap the desired size */
1139 r = GetObjectW( hOleBitmap, sizeof bm, &bm );
1140 if (r != sizeof bm )
1142 ERR("failed to get bitmap size\n");
1146 if (flags & LR_DEFAULTSIZE)
1152 srcdc = CreateCompatibleDC( NULL );
1153 hOldSrcBitmap = SelectObject( srcdc, hOleBitmap );
1154 destdc = CreateCompatibleDC( NULL );
1155 hBitmap = CreateCompatibleBitmap( srcdc, cx, cy );
1156 hOldDestBitmap = SelectObject( destdc, hBitmap );
1157 StretchBlt( destdc, 0, 0, cx, cy,
1158 srcdc, 0, 0, bm.bmWidth, bm.bmHeight, SRCCOPY);
1159 SelectObject( srcdc, hOldSrcBitmap );
1160 SelectObject( destdc, hOldDestBitmap );
1166 IPicture_Release( pic );
1170 static UINT msi_dialog_bitmap_control( msi_dialog *dialog, MSIRECORD *rec )
1172 UINT cx, cy, flags, style, attributes;
1173 msi_control *control;
1176 flags = LR_LOADFROMFILE;
1177 style = SS_BITMAP | SS_LEFT | WS_GROUP;
1179 attributes = MSI_RecordGetInteger( rec, 8 );
1180 if( attributes & msidbControlAttributesFixedSize )
1182 flags |= LR_DEFAULTSIZE;
1183 style |= SS_CENTERIMAGE;
1186 control = msi_dialog_add_control( dialog, rec, szStatic, style );
1187 cx = MSI_RecordGetInteger( rec, 6 );
1188 cy = MSI_RecordGetInteger( rec, 7 );
1189 cx = msi_dialog_scale_unit( dialog, cx );
1190 cy = msi_dialog_scale_unit( dialog, cy );
1192 name = msi_get_binary_name( dialog->package, rec );
1193 control->hBitmap = msi_load_picture( dialog->package->db, name, cx, cy, flags );
1194 if( control->hBitmap )
1195 SendMessageW( control->hwnd, STM_SETIMAGE,
1196 IMAGE_BITMAP, (LPARAM) control->hBitmap );
1198 ERR("Failed to load bitmap %s\n", debugstr_w(name));
1202 return ERROR_SUCCESS;
1205 static UINT msi_dialog_icon_control( msi_dialog *dialog, MSIRECORD *rec )
1207 msi_control *control;
1213 control = msi_dialog_add_control( dialog, rec, szStatic,
1214 SS_ICON | SS_CENTERIMAGE | WS_GROUP );
1216 attributes = MSI_RecordGetInteger( rec, 8 );
1217 name = msi_get_binary_name( dialog->package, rec );
1218 control->hIcon = msi_load_icon( dialog->package->db, name, attributes );
1219 if( control->hIcon )
1220 SendMessageW( control->hwnd, STM_SETICON, (WPARAM) control->hIcon, 0 );
1222 ERR("Failed to load bitmap %s\n", debugstr_w(name));
1224 return ERROR_SUCCESS;
1227 /******************** Combo Box ***************************************/
1229 struct msi_combobox_info
1239 static LRESULT WINAPI MSIComboBox_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
1241 struct msi_combobox_info *info;
1245 TRACE("%p %04x %08lx %08lx\n", hWnd, msg, wParam, lParam);
1247 info = GetPropW( hWnd, szButtonData );
1251 r = CallWindowProcW( info->oldproc, hWnd, msg, wParam, lParam );
1256 for (j = 0; j < info->num_items; j++)
1257 msi_free( info->items[j] );
1258 msi_free( info->items );
1260 RemovePropW( hWnd, szButtonData );
1267 static UINT msi_combobox_add_item( MSIRECORD *rec, LPVOID param )
1269 struct msi_combobox_info *info = param;
1270 LPCWSTR value, text;
1273 value = MSI_RecordGetString( rec, 3 );
1274 text = MSI_RecordGetString( rec, 4 );
1276 info->items[info->addpos_items] = strdupW( value );
1278 pos = SendMessageW( info->hwnd, CB_ADDSTRING, 0, (LPARAM)text );
1279 SendMessageW( info->hwnd, CB_SETITEMDATA, pos, (LPARAM)info->items[info->addpos_items] );
1280 info->addpos_items++;
1282 return ERROR_SUCCESS;
1285 static UINT msi_combobox_add_items( struct msi_combobox_info *info, LPCWSTR property )
1288 MSIQUERY *view = NULL;
1291 static const WCHAR query[] = {
1292 'S','E','L','E','C','T',' ','*',' ',
1293 'F','R','O','M',' ','`','C','o','m','b','o','B','o','x','`',' ',
1294 'W','H','E','R','E',' ',
1295 '`','P','r','o','p','e','r','t','y','`',' ','=',' ','\'','%','s','\'',' ',
1296 'O','R','D','E','R',' ','B','Y',' ','`','O','r','d','e','r','`',0
1299 r = MSI_OpenQuery( info->dialog->package->db, &view, query, property );
1300 if (r != ERROR_SUCCESS)
1303 /* just get the number of records */
1305 r = MSI_IterateRecords( view, &count, NULL, NULL );
1307 info->num_items = count;
1308 info->items = msi_alloc( sizeof(*info->items) * count );
1310 r = MSI_IterateRecords( view, NULL, msi_combobox_add_item, info );
1311 msiobj_release( &view->hdr );
1316 static UINT msi_dialog_combobox_handler( msi_dialog *dialog,
1317 msi_control *control, WPARAM param )
1319 struct msi_combobox_info *info;
1323 if (HIWORD(param) != CBN_SELCHANGE && HIWORD(param) != CBN_EDITCHANGE)
1324 return ERROR_SUCCESS;
1326 info = GetPropW( control->hwnd, szButtonData );
1327 index = SendMessageW( control->hwnd, CB_GETCURSEL, 0, 0 );
1328 if (index == CB_ERR)
1329 value = msi_get_window_text( control->hwnd );
1331 value = (LPWSTR) SendMessageW( control->hwnd, CB_GETITEMDATA, index, 0 );
1333 MSI_SetPropertyW( info->dialog->package,
1334 control->property, value );
1335 msi_dialog_evaluate_control_conditions( info->dialog );
1337 if (index == CB_ERR)
1340 return ERROR_SUCCESS;
1343 static void msi_dialog_combobox_update( msi_dialog *dialog,
1344 msi_control *control )
1346 struct msi_combobox_info *info;
1350 info = GetPropW( control->hwnd, szButtonData );
1352 value = msi_dup_property( dialog->package, control->property );
1355 SendMessageW( control->hwnd, CB_SETCURSEL, -1, 0 );
1359 for (j = 0; j < info->num_items; j++)
1361 tmp = (LPWSTR) SendMessageW( control->hwnd, CB_GETITEMDATA, j, 0 );
1362 if (!lstrcmpW( value, tmp ))
1366 if (j < info->num_items)
1368 SendMessageW( control->hwnd, CB_SETCURSEL, j, 0 );
1372 SendMessageW( control->hwnd, CB_SETCURSEL, -1, 0 );
1373 SetWindowTextW( control->hwnd, value );
1379 static UINT msi_dialog_combo_control( msi_dialog *dialog, MSIRECORD *rec )
1381 struct msi_combobox_info *info;
1382 msi_control *control;
1383 DWORD attributes, style;
1386 info = msi_alloc( sizeof *info );
1388 return ERROR_FUNCTION_FAILED;
1390 style = CBS_AUTOHSCROLL | WS_TABSTOP | WS_GROUP | WS_CHILD;
1391 attributes = MSI_RecordGetInteger( rec, 8 );
1392 if ( ~attributes & msidbControlAttributesSorted)
1394 if ( attributes & msidbControlAttributesComboList)
1395 style |= CBS_DROPDOWNLIST;
1397 style |= CBS_DROPDOWN;
1399 control = msi_dialog_add_control( dialog, rec, WC_COMBOBOXW, style );
1403 return ERROR_FUNCTION_FAILED;
1406 control->handler = msi_dialog_combobox_handler;
1407 control->update = msi_dialog_combobox_update;
1409 prop = MSI_RecordGetString( rec, 9 );
1410 control->property = msi_dialog_dup_property( dialog, prop, FALSE );
1413 info->dialog = dialog;
1414 info->hwnd = control->hwnd;
1416 info->addpos_items = 0;
1417 info->oldproc = (WNDPROC)SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
1418 (LONG_PTR)MSIComboBox_WndProc );
1419 SetPropW( control->hwnd, szButtonData, info );
1421 if (control->property)
1422 msi_combobox_add_items( info, control->property );
1424 msi_dialog_combobox_update( dialog, control );
1426 return ERROR_SUCCESS;
1429 /* length of 2^32 + 1 */
1430 #define MAX_NUM_DIGITS 11
1432 static UINT msi_dialog_edit_control( msi_dialog *dialog, MSIRECORD *rec )
1434 msi_control *control;
1436 LPWSTR val, begin, end;
1437 WCHAR num[MAX_NUM_DIGITS];
1440 control = msi_dialog_add_control( dialog, rec, szEdit,
1441 WS_BORDER | WS_TABSTOP | ES_AUTOHSCROLL );
1442 control->handler = msi_dialog_edit_handler;
1444 text = MSI_RecordGetString( rec, 10 );
1447 begin = strchrW( text, '{' );
1448 end = strchrW( text, '}' );
1450 if ( begin && end && end > begin &&
1451 begin[0] >= '0' && begin[0] <= '9' &&
1452 end - begin < MAX_NUM_DIGITS)
1454 lstrcpynW( num, begin + 1, end - begin );
1455 limit = atolW( num );
1457 SendMessageW( control->hwnd, EM_SETLIMITTEXT, limit, 0 );
1461 prop = MSI_RecordGetString( rec, 9 );
1463 control->property = strdupW( prop );
1465 val = msi_dup_property( dialog->package, control->property );
1466 SetWindowTextW( control->hwnd, val );
1468 return ERROR_SUCCESS;
1471 /******************** Masked Edit ********************************************/
1473 #define MASK_MAX_GROUPS 20
1475 struct msi_mask_group
1483 struct msi_maskedit_info
1491 struct msi_mask_group group[MASK_MAX_GROUPS];
1494 static BOOL msi_mask_editable( WCHAR type )
1509 static void msi_mask_control_change( struct msi_maskedit_info *info )
1514 val = msi_alloc( (info->num_chars+1)*sizeof(WCHAR) );
1515 for( i=0, n=0; i<info->num_groups; i++ )
1517 if( (info->group[i].len + n) > info->num_chars )
1519 ERR("can't fit control %d text into template\n",i);
1522 if (!msi_mask_editable(info->group[i].type))
1524 for(r=0; r<info->group[i].len; r++)
1525 val[n+r] = info->group[i].type;
1530 r = GetWindowTextW( info->group[i].hwnd, &val[n], info->group[i].len+1 );
1531 if( r != info->group[i].len )
1537 TRACE("%d/%d controls were good\n", i, info->num_groups);
1539 if( i == info->num_groups )
1541 TRACE("Set property %s to %s\n",
1542 debugstr_w(info->prop), debugstr_w(val) );
1543 CharUpperBuffW( val, info->num_chars );
1544 MSI_SetPropertyW( info->dialog->package, info->prop, val );
1545 msi_dialog_evaluate_control_conditions( info->dialog );
1550 /* now move to the next control if necessary */
1551 static VOID msi_mask_next_control( struct msi_maskedit_info *info, HWND hWnd )
1556 for( i=0; i<info->num_groups; i++ )
1557 if( info->group[i].hwnd == hWnd )
1560 /* don't move from the last control */
1561 if( i >= (info->num_groups-1) )
1564 len = SendMessageW( hWnd, WM_GETTEXTLENGTH, 0, 0 );
1565 if( len < info->group[i].len )
1568 hWndNext = GetNextDlgTabItem( GetParent( hWnd ), hWnd, FALSE );
1569 SetFocus( hWndNext );
1572 static LRESULT WINAPI
1573 MSIMaskedEdit_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
1575 struct msi_maskedit_info *info;
1578 TRACE("%p %04x %08lx %08lx\n", hWnd, msg, wParam, lParam);
1580 info = GetPropW(hWnd, szButtonData);
1582 r = CallWindowProcW(info->oldproc, hWnd, msg, wParam, lParam);
1587 if (HIWORD(wParam) == EN_CHANGE)
1589 msi_mask_control_change( info );
1590 msi_mask_next_control( info, (HWND) lParam );
1594 msi_free( info->prop );
1596 RemovePropW( hWnd, szButtonData );
1603 /* fish the various bits of the property out and put them in the control */
1605 msi_maskedit_set_text( struct msi_maskedit_info *info, LPCWSTR text )
1611 for( i = 0; i < info->num_groups; i++ )
1613 if( info->group[i].len < strlenW( p ) )
1615 LPWSTR chunk = strdupW( p );
1616 chunk[ info->group[i].len ] = 0;
1617 SetWindowTextW( info->group[i].hwnd, chunk );
1622 SetWindowTextW( info->group[i].hwnd, p );
1625 p += info->group[i].len;
1629 static struct msi_maskedit_info * msi_dialog_parse_groups( LPCWSTR mask )
1631 struct msi_maskedit_info * info = NULL;
1632 int i = 0, n = 0, total = 0;
1635 TRACE("masked control, template %s\n", debugstr_w(mask));
1640 info = msi_alloc_zero( sizeof *info );
1644 p = strchrW(mask, '<');
1650 for( i=0; i<MASK_MAX_GROUPS; i++ )
1652 /* stop at the end of the string */
1653 if( p[0] == 0 || p[0] == '>' )
1656 /* count the number of the same identifier */
1657 for( n=0; p[n] == p[0]; n++ )
1659 info->group[i].ofs = total;
1660 info->group[i].type = p[0];
1664 total++; /* an extra not part of the group */
1666 info->group[i].len = n;
1671 TRACE("%d characters in %d groups\n", total, i );
1672 if( i == MASK_MAX_GROUPS )
1673 ERR("too many groups in PIDTemplate %s\n", debugstr_w(mask));
1675 info->num_chars = total;
1676 info->num_groups = i;
1682 msi_maskedit_create_children( struct msi_maskedit_info *info, LPCWSTR font )
1684 DWORD width, height, style, wx, ww;
1689 style = WS_CHILD | WS_BORDER | WS_VISIBLE | WS_TABSTOP | ES_AUTOHSCROLL;
1691 GetClientRect( info->hwnd, &rect );
1693 width = rect.right - rect.left;
1694 height = rect.bottom - rect.top;
1696 for( i = 0; i < info->num_groups; i++ )
1698 if (!msi_mask_editable( info->group[i].type ))
1700 wx = (info->group[i].ofs * width) / info->num_chars;
1701 ww = (info->group[i].len * width) / info->num_chars;
1703 hwnd = CreateWindowW( szEdit, NULL, style, wx, 0, ww, height,
1704 info->hwnd, NULL, NULL, NULL );
1707 ERR("failed to create mask edit sub window\n");
1711 SendMessageW( hwnd, EM_LIMITTEXT, info->group[i].len, 0 );
1713 msi_dialog_set_font( info->dialog, hwnd,
1714 font?font:info->dialog->default_font );
1715 info->group[i].hwnd = hwnd;
1720 * office 2003 uses "73931<````=````=````=````=`````>@@@@@"
1721 * delphi 7 uses "<????-??????-??????-????>" and "<???-???>"
1722 * filemaker pro 7 uses "<^^^^=^^^^=^^^^=^^^^=^^^^=^^^^=^^^^^>"
1724 static UINT msi_dialog_maskedit_control( msi_dialog *dialog, MSIRECORD *rec )
1726 LPWSTR font_mask, val = NULL, font;
1727 struct msi_maskedit_info *info = NULL;
1728 UINT ret = ERROR_SUCCESS;
1729 msi_control *control;
1734 font_mask = msi_get_deformatted_field( dialog->package, rec, 10 );
1735 font = msi_dialog_get_style( font_mask, &mask );
1738 ERR("mask template is empty\n");
1742 info = msi_dialog_parse_groups( mask );
1745 ERR("template %s is invalid\n", debugstr_w(mask));
1749 info->dialog = dialog;
1751 control = msi_dialog_add_control( dialog, rec, szStatic,
1752 SS_OWNERDRAW | WS_GROUP | WS_VISIBLE );
1755 ERR("Failed to create maskedit container\n");
1756 ret = ERROR_FUNCTION_FAILED;
1759 SetWindowLongPtrW( control->hwnd, GWL_EXSTYLE, WS_EX_CONTROLPARENT );
1761 info->hwnd = control->hwnd;
1763 /* subclass the static control */
1764 info->oldproc = (WNDPROC) SetWindowLongPtrW( info->hwnd, GWLP_WNDPROC,
1765 (LONG_PTR)MSIMaskedEdit_WndProc );
1766 SetPropW( control->hwnd, szButtonData, info );
1768 prop = MSI_RecordGetString( rec, 9 );
1770 info->prop = strdupW( prop );
1772 msi_maskedit_create_children( info, font );
1776 val = msi_dup_property( dialog->package, prop );
1779 msi_maskedit_set_text( info, val );
1785 if( ret != ERROR_SUCCESS )
1787 msi_free( font_mask );
1792 /******************** Progress Bar *****************************************/
1794 static UINT msi_dialog_progress_bar( msi_dialog *dialog, MSIRECORD *rec )
1796 msi_control *control;
1797 DWORD attributes, style;
1800 attributes = MSI_RecordGetInteger( rec, 8 );
1801 if( !(attributes & msidbControlAttributesProgress95) )
1802 style |= PBS_SMOOTH;
1804 control = msi_dialog_add_control( dialog, rec, PROGRESS_CLASSW, style );
1806 return ERROR_FUNCTION_FAILED;
1808 ControlEvent_SubscribeToEvent( dialog->package, dialog,
1809 szSetProgress, control->name, szProgress );
1810 return ERROR_SUCCESS;
1813 /******************** Path Edit ********************************************/
1815 struct msi_pathedit_info
1818 msi_control *control;
1822 static LPWSTR msi_get_window_text( HWND hwnd )
1828 buf = msi_alloc( sz*sizeof(WCHAR) );
1831 r = GetWindowTextW( hwnd, buf, sz );
1835 buf = msi_realloc( buf, sz*sizeof(WCHAR) );
1841 static void msi_dialog_update_pathedit( msi_dialog *dialog, msi_control *control )
1846 if (!control && !(control = msi_dialog_find_control_by_type( dialog, szPathEdit )))
1849 indirect = control->attributes & msidbControlAttributesIndirect;
1850 prop = msi_dialog_dup_property( dialog, control->property, indirect );
1851 path = msi_dialog_dup_property( dialog, prop, TRUE );
1853 SetWindowTextW( control->hwnd, path );
1854 SendMessageW( control->hwnd, EM_SETSEL, 0, -1 );
1860 /* FIXME: test when this should fail */
1861 static BOOL msi_dialog_verify_path( LPWSTR path )
1863 if ( !lstrlenW( path ) )
1866 if ( PathIsRelativeW( path ) )
1872 /* returns TRUE if the path is valid, FALSE otherwise */
1873 static BOOL msi_dialog_onkillfocus( msi_dialog *dialog, msi_control *control )
1879 indirect = control->attributes & msidbControlAttributesIndirect;
1880 prop = msi_dialog_dup_property( dialog, control->property, indirect );
1882 buf = msi_get_window_text( control->hwnd );
1884 if ( !msi_dialog_verify_path( buf ) )
1886 /* FIXME: display an error message box */
1887 ERR("Invalid path %s\n", debugstr_w( buf ));
1889 SetFocus( control->hwnd );
1894 MSI_SetPropertyW( dialog->package, prop, buf );
1897 msi_dialog_update_pathedit( dialog, control );
1899 TRACE("edit %s contents changed, set %s\n", debugstr_w(control->name),
1908 static LRESULT WINAPI MSIPathEdit_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
1910 struct msi_pathedit_info *info = GetPropW(hWnd, szButtonData);
1913 TRACE("%p %04x %08lx %08lx\n", hWnd, msg, wParam, lParam);
1915 if ( msg == WM_KILLFOCUS )
1917 /* if the path is invalid, don't handle this message */
1918 if ( !msi_dialog_onkillfocus( info->dialog, info->control ) )
1922 r = CallWindowProcW(info->oldproc, hWnd, msg, wParam, lParam);
1924 if ( msg == WM_NCDESTROY )
1927 RemovePropW( hWnd, szButtonData );
1933 static UINT msi_dialog_pathedit_control( msi_dialog *dialog, MSIRECORD *rec )
1935 struct msi_pathedit_info *info;
1936 msi_control *control;
1939 info = msi_alloc( sizeof *info );
1941 return ERROR_FUNCTION_FAILED;
1943 control = msi_dialog_add_control( dialog, rec, szEdit,
1944 WS_BORDER | WS_TABSTOP );
1945 control->attributes = MSI_RecordGetInteger( rec, 8 );
1946 prop = MSI_RecordGetString( rec, 9 );
1947 control->property = msi_dialog_dup_property( dialog, prop, FALSE );
1949 info->dialog = dialog;
1950 info->control = control;
1951 info->oldproc = (WNDPROC) SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
1952 (LONG_PTR)MSIPathEdit_WndProc );
1953 SetPropW( control->hwnd, szButtonData, info );
1955 msi_dialog_update_pathedit( dialog, control );
1957 return ERROR_SUCCESS;
1960 /* radio buttons are a bit different from normal controls */
1961 static UINT msi_dialog_create_radiobutton( MSIRECORD *rec, LPVOID param )
1963 radio_button_group_descr *group = param;
1964 msi_dialog *dialog = group->dialog;
1965 msi_control *control;
1966 LPCWSTR prop, text, name;
1967 DWORD style, attributes = group->attributes;
1969 style = WS_CHILD | BS_AUTORADIOBUTTON | BS_MULTILINE | WS_TABSTOP;
1970 name = MSI_RecordGetString( rec, 3 );
1971 text = MSI_RecordGetString( rec, 8 );
1972 if( attributes & msidbControlAttributesVisible )
1973 style |= WS_VISIBLE;
1974 if( ~attributes & msidbControlAttributesEnabled )
1975 style |= WS_DISABLED;
1977 control = msi_dialog_create_window( dialog, rec, 0, szButton, name, text,
1978 style, group->parent->hwnd );
1980 return ERROR_FUNCTION_FAILED;
1981 control->handler = msi_dialog_radiogroup_handler;
1983 if (!lstrcmpW(control->name, group->propval))
1984 SendMessageW(control->hwnd, BM_SETCHECK, BST_CHECKED, 0);
1986 prop = MSI_RecordGetString( rec, 1 );
1988 control->property = strdupW( prop );
1990 return ERROR_SUCCESS;
1993 static UINT msi_dialog_radiogroup_control( msi_dialog *dialog, MSIRECORD *rec )
1995 static const WCHAR query[] = {
1996 'S','E','L','E','C','T',' ','*',' ',
1997 'F','R','O','M',' ','R','a','d','i','o','B','u','t','t','o','n',' ',
1998 'W','H','E','R','E',' ',
1999 '`','P','r','o','p','e','r','t','y','`',' ','=',' ','\'','%','s','\'',0};
2002 msi_control *control;
2003 MSIQUERY *view = NULL;
2004 radio_button_group_descr group;
2005 MSIPACKAGE *package = dialog->package;
2007 DWORD attr, style = WS_GROUP;
2009 prop = MSI_RecordGetString( rec, 9 );
2011 TRACE("%p %p %s\n", dialog, rec, debugstr_w( prop ));
2013 attr = MSI_RecordGetInteger( rec, 8 );
2014 if (attr & msidbControlAttributesHasBorder)
2015 style |= BS_GROUPBOX;
2017 style |= BS_OWNERDRAW;
2019 /* Create parent group box to hold radio buttons */
2020 control = msi_dialog_add_control( dialog, rec, szButton, style );
2022 return ERROR_FUNCTION_FAILED;
2024 oldproc = (WNDPROC) SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
2025 (LONG_PTR)MSIRadioGroup_WndProc );
2026 SetPropW(control->hwnd, szButtonData, oldproc);
2027 SetWindowLongPtrW( control->hwnd, GWL_EXSTYLE, WS_EX_CONTROLPARENT );
2030 control->property = strdupW( prop );
2032 /* query the Radio Button table for all control in this group */
2033 r = MSI_OpenQuery( package->db, &view, query, prop );
2034 if( r != ERROR_SUCCESS )
2036 ERR("query failed for dialog %s radio group %s\n",
2037 debugstr_w(dialog->name), debugstr_w(prop));
2038 return ERROR_INVALID_PARAMETER;
2041 group.dialog = dialog;
2042 group.parent = control;
2043 group.attributes = MSI_RecordGetInteger( rec, 8 );
2044 group.propval = msi_dup_property( dialog->package, control->property );
2046 r = MSI_IterateRecords( view, 0, msi_dialog_create_radiobutton, &group );
2047 msiobj_release( &view->hdr );
2048 msi_free( group.propval );
2053 /******************** Selection Tree ***************************************/
2055 struct msi_selection_tree_info
2064 msi_seltree_sync_item_state( HWND hwnd, MSIFEATURE *feature, HTREEITEM hItem )
2067 DWORD index = feature->Action;
2069 TRACE("Feature %s -> %d %d %d\n", debugstr_w(feature->Title),
2070 feature->Installed, feature->Action, feature->ActionRequest);
2072 if (index == INSTALLSTATE_UNKNOWN)
2073 index = INSTALLSTATE_ABSENT;
2075 tvi.mask = TVIF_STATE;
2077 tvi.state = INDEXTOSTATEIMAGEMASK( index );
2078 tvi.stateMask = TVIS_STATEIMAGEMASK;
2080 SendMessageW( hwnd, TVM_SETITEMW, 0, (LPARAM) &tvi );
2084 msi_seltree_popup_menu( HWND hwnd, INT x, INT y )
2089 /* create a menu to display */
2090 hMenu = CreatePopupMenu();
2092 /* FIXME: load strings from resources */
2093 AppendMenuA( hMenu, MF_ENABLED, INSTALLSTATE_LOCAL, "Install feature locally");
2094 AppendMenuA( hMenu, MF_ENABLED, USER_INSTALLSTATE_ALL, "Install entire feature");
2095 AppendMenuA( hMenu, MF_ENABLED, INSTALLSTATE_ADVERTISED, "Install on demand");
2096 AppendMenuA( hMenu, MF_ENABLED, INSTALLSTATE_ABSENT, "Don't install");
2097 r = TrackPopupMenu( hMenu, TPM_LEFTALIGN | TPM_TOPALIGN | TPM_RETURNCMD,
2098 x, y, 0, hwnd, NULL );
2099 DestroyMenu( hMenu );
2104 msi_seltree_feature_from_item( HWND hwnd, HTREEITEM hItem )
2108 /* get the feature from the item */
2109 memset( &tvi, 0, sizeof tvi );
2111 tvi.mask = TVIF_PARAM | TVIF_HANDLE;
2112 SendMessageW( hwnd, TVM_GETITEMW, 0, (LPARAM) &tvi );
2114 return (MSIFEATURE*) tvi.lParam;
2118 msi_seltree_update_feature_installstate( HWND hwnd, HTREEITEM hItem,
2119 MSIPACKAGE *package, MSIFEATURE *feature, INSTALLSTATE state )
2121 msi_feature_set_state( package, feature, state );
2122 msi_seltree_sync_item_state( hwnd, feature, hItem );
2123 ACTION_UpdateComponentStates( package, feature->Feature );
2127 msi_seltree_update_siblings_and_children_installstate( HWND hwnd, HTREEITEM curr,
2128 MSIPACKAGE *package, INSTALLSTATE state)
2130 /* update all siblings */
2133 MSIFEATURE *feature;
2136 feature = msi_seltree_feature_from_item( hwnd, curr );
2137 msi_seltree_update_feature_installstate( hwnd, curr, package, feature, state );
2139 /* update this sibling's children */
2140 child = (HTREEITEM)SendMessageW( hwnd, TVM_GETNEXTITEM, (WPARAM)TVGN_CHILD, (LPARAM)curr );
2142 msi_seltree_update_siblings_and_children_installstate( hwnd, child,
2145 while ((curr = (HTREEITEM)SendMessageW( hwnd, TVM_GETNEXTITEM, (WPARAM)TVGN_NEXT, (LPARAM)curr )));
2149 msi_seltree_menu( HWND hwnd, HTREEITEM hItem )
2151 struct msi_selection_tree_info *info;
2152 MSIFEATURE *feature;
2153 MSIPACKAGE *package;
2161 info = GetPropW(hwnd, szButtonData);
2162 package = info->dialog->package;
2164 feature = msi_seltree_feature_from_item( hwnd, hItem );
2167 ERR("item %p feature was NULL\n", hItem);
2171 /* get the item's rectangle to put the menu just below it */
2173 SendMessageW( hwnd, TVM_GETITEMRECT, 0, (LPARAM) &u.rc );
2174 MapWindowPoints( hwnd, NULL, u.pt, 2 );
2176 r = msi_seltree_popup_menu( hwnd, u.rc.left, u.rc.top );
2180 case USER_INSTALLSTATE_ALL:
2181 r = INSTALLSTATE_LOCAL;
2183 case INSTALLSTATE_ADVERTISED:
2184 case INSTALLSTATE_ABSENT:
2187 child = (HTREEITEM)SendMessageW( hwnd, TVM_GETNEXTITEM, (WPARAM)TVGN_CHILD, (LPARAM)hItem );
2189 msi_seltree_update_siblings_and_children_installstate( hwnd, child, package, r );
2192 case INSTALLSTATE_LOCAL:
2193 msi_seltree_update_feature_installstate( hwnd, hItem, package, feature, r );
2200 static MSIFEATURE *msi_seltree_get_selected_feature( msi_control *control )
2202 struct msi_selection_tree_info *info = GetPropW(control->hwnd, szButtonData);
2203 return msi_seltree_feature_from_item( control->hwnd, info->selected );
2206 static LRESULT WINAPI
2207 MSISelectionTree_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
2209 struct msi_selection_tree_info *info;
2210 TVHITTESTINFO tvhti;
2213 TRACE("%p %04x %08lx %08lx\n", hWnd, msg, wParam, lParam);
2215 info = GetPropW(hWnd, szButtonData);
2219 case WM_LBUTTONDOWN:
2220 tvhti.pt.x = (short)LOWORD( lParam );
2221 tvhti.pt.y = (short)HIWORD( lParam );
2224 r = CallWindowProcW(info->oldproc, hWnd, TVM_HITTEST, 0, (LPARAM) &tvhti );
2225 if (tvhti.flags & TVHT_ONITEMSTATEICON)
2226 return msi_seltree_menu( hWnd, tvhti.hItem );
2230 r = CallWindowProcW(info->oldproc, hWnd, msg, wParam, lParam);
2236 RemovePropW( hWnd, szButtonData );
2243 msi_seltree_add_child_features( MSIPACKAGE *package, HWND hwnd,
2244 LPCWSTR parent, HTREEITEM hParent )
2246 struct msi_selection_tree_info *info = GetPropW( hwnd, szButtonData );
2247 MSIFEATURE *feature;
2248 TVINSERTSTRUCTW tvis;
2249 HTREEITEM hitem, hfirst = NULL;
2251 LIST_FOR_EACH_ENTRY( feature, &package->features, MSIFEATURE, entry )
2253 if ( lstrcmpW( parent, feature->Feature_Parent ) )
2256 if ( !feature->Title )
2259 if ( !feature->Display )
2262 memset( &tvis, 0, sizeof tvis );
2263 tvis.hParent = hParent;
2264 tvis.hInsertAfter = TVI_LAST;
2265 tvis.u.item.mask = TVIF_TEXT | TVIF_PARAM;
2266 tvis.u.item.pszText = feature->Title;
2267 tvis.u.item.lParam = (LPARAM) feature;
2269 hitem = (HTREEITEM) SendMessageW( hwnd, TVM_INSERTITEMW, 0, (LPARAM) &tvis );
2276 msi_seltree_sync_item_state( hwnd, feature, hitem );
2277 msi_seltree_add_child_features( package, hwnd,
2278 feature->Feature, hitem );
2280 /* the node is expanded if Display is odd */
2281 if ( feature->Display % 2 != 0 )
2282 SendMessageW( hwnd, TVM_EXPAND, TVE_EXPAND, (LPARAM) hitem );
2285 /* select the first item */
2286 SendMessageW( hwnd, TVM_SELECTITEM, TVGN_CARET | TVGN_DROPHILITE, (LPARAM) hfirst );
2287 info->selected = hfirst;
2290 static void msi_seltree_create_imagelist( HWND hwnd )
2292 const int bm_width = 32, bm_height = 16, bm_count = 3;
2293 const int bm_resource = 0x1001;
2298 himl = ImageList_Create( bm_width, bm_height, FALSE, 4, 0 );
2301 ERR("failed to create image list\n");
2305 for (i=0; i<bm_count; i++)
2307 hbmp = LoadBitmapW( msi_hInstance, MAKEINTRESOURCEW(i+bm_resource) );
2310 ERR("failed to load bitmap %d\n", i);
2315 * Add a dummy bitmap at offset zero because the treeview
2316 * can't use it as a state mask (zero means no user state).
2319 ImageList_Add( himl, hbmp, NULL );
2321 ImageList_Add( himl, hbmp, NULL );
2324 SendMessageW( hwnd, TVM_SETIMAGELIST, TVSIL_STATE, (LPARAM)himl );
2327 static UINT msi_dialog_seltree_handler( msi_dialog *dialog,
2328 msi_control *control, WPARAM param )
2330 struct msi_selection_tree_info *info = GetPropW( control->hwnd, szButtonData );
2331 LPNMTREEVIEWW tv = (LPNMTREEVIEWW)param;
2332 MSIRECORD *row, *rec;
2334 MSIFEATURE *feature;
2335 LPCWSTR dir, title = NULL;
2336 UINT r = ERROR_SUCCESS;
2338 static const WCHAR select[] = {
2339 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2340 '`','F','e','a','t','u','r','e','`',' ','W','H','E','R','E',' ',
2341 '`','T','i','t','l','e','`',' ','=',' ','\'','%','s','\'',0
2344 if (tv->hdr.code != TVN_SELCHANGINGW)
2345 return ERROR_SUCCESS;
2347 info->selected = tv->itemNew.hItem;
2349 if (!(tv->itemNew.mask & TVIF_TEXT))
2351 feature = msi_seltree_feature_from_item( control->hwnd, tv->itemNew.hItem );
2353 title = feature->Title;
2356 title = tv->itemNew.pszText;
2358 row = MSI_QueryGetRecord( dialog->package->db, select, title );
2360 return ERROR_FUNCTION_FAILED;
2362 rec = MSI_CreateRecord( 1 );
2364 MSI_RecordSetStringW( rec, 1, MSI_RecordGetString( row, 4 ) );
2365 ControlEvent_FireSubscribedEvent( dialog->package, szSelectionDescription, rec );
2367 dir = MSI_RecordGetString( row, 7 );
2368 folder = get_loaded_folder( dialog->package, dir );
2371 r = ERROR_FUNCTION_FAILED;
2375 MSI_RecordSetStringW( rec, 1, folder->ResolvedTarget );
2376 ControlEvent_FireSubscribedEvent( dialog->package, szSelectionPath, rec );
2379 msiobj_release(&row->hdr);
2380 msiobj_release(&rec->hdr);
2385 static UINT msi_dialog_selection_tree( msi_dialog *dialog, MSIRECORD *rec )
2387 msi_control *control;
2389 MSIPACKAGE *package = dialog->package;
2391 struct msi_selection_tree_info *info;
2393 info = msi_alloc( sizeof *info );
2395 return ERROR_FUNCTION_FAILED;
2397 /* create the treeview control */
2398 style = TVS_HASLINES | TVS_HASBUTTONS | TVS_LINESATROOT;
2399 style |= WS_GROUP | WS_VSCROLL;
2400 control = msi_dialog_add_control( dialog, rec, WC_TREEVIEWW, style );
2404 return ERROR_FUNCTION_FAILED;
2407 control->handler = msi_dialog_seltree_handler;
2408 control->attributes = MSI_RecordGetInteger( rec, 8 );
2409 prop = MSI_RecordGetString( rec, 9 );
2410 control->property = msi_dialog_dup_property( dialog, prop, FALSE );
2413 info->dialog = dialog;
2414 info->hwnd = control->hwnd;
2415 info->oldproc = (WNDPROC) SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
2416 (LONG_PTR)MSISelectionTree_WndProc );
2417 SetPropW( control->hwnd, szButtonData, info );
2419 ControlEvent_SubscribeToEvent( dialog->package, dialog,
2420 szSelectionPath, control->name, szProperty );
2423 msi_seltree_create_imagelist( control->hwnd );
2424 msi_seltree_add_child_features( package, control->hwnd, NULL, NULL );
2426 return ERROR_SUCCESS;
2429 /******************** Group Box ***************************************/
2431 static UINT msi_dialog_group_box( msi_dialog *dialog, MSIRECORD *rec )
2433 msi_control *control;
2436 style = BS_GROUPBOX | WS_CHILD | WS_GROUP;
2437 control = msi_dialog_add_control( dialog, rec, WC_BUTTONW, style );
2439 return ERROR_FUNCTION_FAILED;
2441 return ERROR_SUCCESS;
2444 /******************** List Box ***************************************/
2446 struct msi_listbox_info
2456 static LRESULT WINAPI MSIListBox_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
2458 struct msi_listbox_info *info;
2462 TRACE("%p %04x %08lx %08lx\n", hWnd, msg, wParam, lParam);
2464 info = GetPropW( hWnd, szButtonData );
2468 r = CallWindowProcW( info->oldproc, hWnd, msg, wParam, lParam );
2473 for (j = 0; j < info->num_items; j++)
2474 msi_free( info->items[j] );
2475 msi_free( info->items );
2477 RemovePropW( hWnd, szButtonData );
2484 static UINT msi_listbox_add_item( MSIRECORD *rec, LPVOID param )
2486 struct msi_listbox_info *info = param;
2487 LPCWSTR value, text;
2490 value = MSI_RecordGetString( rec, 3 );
2491 text = MSI_RecordGetString( rec, 4 );
2493 info->items[info->addpos_items] = strdupW( value );
2495 pos = SendMessageW( info->hwnd, LB_ADDSTRING, 0, (LPARAM)text );
2496 SendMessageW( info->hwnd, LB_SETITEMDATA, pos, (LPARAM)info->items[info->addpos_items] );
2497 info->addpos_items++;
2498 return ERROR_SUCCESS;
2501 static UINT msi_listbox_add_items( struct msi_listbox_info *info, LPCWSTR property )
2504 MSIQUERY *view = NULL;
2507 static const WCHAR query[] = {
2508 'S','E','L','E','C','T',' ','*',' ',
2509 'F','R','O','M',' ','`','L','i','s','t','B','o','x','`',' ',
2510 'W','H','E','R','E',' ',
2511 '`','P','r','o','p','e','r','t','y','`',' ','=',' ','\'','%','s','\'',' ',
2512 'O','R','D','E','R',' ','B','Y',' ','`','O','r','d','e','r','`',0
2515 r = MSI_OpenQuery( info->dialog->package->db, &view, query, property );
2516 if ( r != ERROR_SUCCESS )
2519 /* just get the number of records */
2521 r = MSI_IterateRecords( view, &count, NULL, NULL );
2523 info->num_items = count;
2524 info->items = msi_alloc( sizeof(*info->items) * count );
2526 r = MSI_IterateRecords( view, NULL, msi_listbox_add_item, info );
2527 msiobj_release( &view->hdr );
2532 static UINT msi_dialog_listbox_handler( msi_dialog *dialog,
2533 msi_control *control, WPARAM param )
2535 struct msi_listbox_info *info;
2539 if( HIWORD(param) != LBN_SELCHANGE )
2540 return ERROR_SUCCESS;
2542 info = GetPropW( control->hwnd, szButtonData );
2543 index = SendMessageW( control->hwnd, LB_GETCURSEL, 0, 0 );
2544 value = (LPCWSTR) SendMessageW( control->hwnd, LB_GETITEMDATA, index, 0 );
2546 MSI_SetPropertyW( info->dialog->package,
2547 control->property, value );
2548 msi_dialog_evaluate_control_conditions( info->dialog );
2550 return ERROR_SUCCESS;
2553 static UINT msi_dialog_list_box( msi_dialog *dialog, MSIRECORD *rec )
2555 struct msi_listbox_info *info;
2556 msi_control *control;
2557 DWORD attributes, style;
2560 info = msi_alloc( sizeof *info );
2562 return ERROR_FUNCTION_FAILED;
2564 style = WS_TABSTOP | WS_GROUP | WS_CHILD | LBS_NOTIFY | WS_VSCROLL | WS_BORDER;
2565 attributes = MSI_RecordGetInteger( rec, 8 );
2566 if (~attributes & msidbControlAttributesSorted)
2569 control = msi_dialog_add_control( dialog, rec, WC_LISTBOXW, style );
2573 return ERROR_FUNCTION_FAILED;
2576 control->handler = msi_dialog_listbox_handler;
2578 prop = MSI_RecordGetString( rec, 9 );
2579 control->property = msi_dialog_dup_property( dialog, prop, FALSE );
2582 info->dialog = dialog;
2583 info->hwnd = control->hwnd;
2585 info->addpos_items = 0;
2586 info->oldproc = (WNDPROC)SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
2587 (LONG_PTR)MSIListBox_WndProc );
2588 SetPropW( control->hwnd, szButtonData, info );
2590 if ( control->property )
2591 msi_listbox_add_items( info, control->property );
2593 return ERROR_SUCCESS;
2596 /******************** Directory Combo ***************************************/
2598 static void msi_dialog_update_directory_combo( msi_dialog *dialog, msi_control *control )
2603 if (!control && !(control = msi_dialog_find_control_by_type( dialog, szDirectoryCombo )))
2606 indirect = control->attributes & msidbControlAttributesIndirect;
2607 prop = msi_dialog_dup_property( dialog, control->property, indirect );
2608 path = msi_dialog_dup_property( dialog, prop, TRUE );
2610 PathStripPathW( path );
2611 PathRemoveBackslashW( path );
2613 SendMessageW( control->hwnd, CB_INSERTSTRING, 0, (LPARAM)path );
2614 SendMessageW( control->hwnd, CB_SETCURSEL, 0, 0 );
2620 static UINT msi_dialog_directory_combo( msi_dialog *dialog, MSIRECORD *rec )
2622 msi_control *control;
2626 /* FIXME: use CBS_OWNERDRAWFIXED and add owner draw code */
2627 style = CBS_DROPDOWNLIST | CBS_HASSTRINGS | WS_CHILD |
2628 WS_GROUP | WS_TABSTOP | WS_VSCROLL;
2629 control = msi_dialog_add_control( dialog, rec, WC_COMBOBOXW, style );
2631 return ERROR_FUNCTION_FAILED;
2633 control->attributes = MSI_RecordGetInteger( rec, 8 );
2634 prop = MSI_RecordGetString( rec, 9 );
2635 control->property = msi_dialog_dup_property( dialog, prop, FALSE );
2637 msi_dialog_update_directory_combo( dialog, control );
2639 return ERROR_SUCCESS;
2642 /******************** Directory List ***************************************/
2644 static void msi_dialog_update_directory_list( msi_dialog *dialog, msi_control *control )
2646 WCHAR dir_spec[MAX_PATH];
2647 WIN32_FIND_DATAW wfd;
2653 static const WCHAR asterisk[] = {'*',0};
2655 if (!control && !(control = msi_dialog_find_control_by_type( dialog, szDirectoryList )))
2658 /* clear the list-view */
2659 SendMessageW( control->hwnd, LVM_DELETEALLITEMS, 0, 0 );
2661 indirect = control->attributes & msidbControlAttributesIndirect;
2662 prop = msi_dialog_dup_property( dialog, control->property, indirect );
2663 path = msi_dialog_dup_property( dialog, prop, TRUE );
2665 lstrcpyW( dir_spec, path );
2666 lstrcatW( dir_spec, asterisk );
2668 file = FindFirstFileW( dir_spec, &wfd );
2669 if ( file == INVALID_HANDLE_VALUE )
2674 if ( wfd.dwFileAttributes != FILE_ATTRIBUTE_DIRECTORY )
2677 if ( !lstrcmpW( wfd.cFileName, szDot ) || !lstrcmpW( wfd.cFileName, szDotDot ) )
2680 item.mask = LVIF_TEXT;
2681 item.cchTextMax = MAX_PATH;
2684 item.pszText = wfd.cFileName;
2686 SendMessageW( control->hwnd, LVM_INSERTITEMW, 0, (LPARAM)&item );
2687 } while ( FindNextFileW( file, &wfd ) );
2694 UINT msi_dialog_directorylist_up( msi_dialog *dialog )
2696 msi_control *control;
2697 LPWSTR prop, path, ptr;
2700 control = msi_dialog_find_control_by_type( dialog, szDirectoryList );
2701 indirect = control->attributes & msidbControlAttributesIndirect;
2702 prop = msi_dialog_dup_property( dialog, control->property, indirect );
2703 path = msi_dialog_dup_property( dialog, prop, TRUE );
2705 /* strip off the last directory */
2706 ptr = PathFindFileNameW( path );
2707 if (ptr != path) *(ptr - 1) = '\0';
2708 PathAddBackslashW( path );
2710 MSI_SetPropertyW( dialog->package, prop, path );
2712 msi_dialog_update_directory_list( dialog, NULL );
2713 msi_dialog_update_directory_combo( dialog, NULL );
2714 msi_dialog_update_pathedit( dialog, NULL );
2719 return ERROR_SUCCESS;
2722 static UINT msi_dialog_dirlist_handler( msi_dialog *dialog,
2723 msi_control *control, WPARAM param )
2725 LPNMHDR nmhdr = (LPNMHDR)param;
2726 WCHAR new_path[MAX_PATH];
2727 WCHAR text[MAX_PATH];
2733 if (nmhdr->code != LVN_ITEMACTIVATE)
2734 return ERROR_SUCCESS;
2736 index = SendMessageW( control->hwnd, LVM_GETNEXTITEM, -1, LVNI_SELECTED );
2739 ERR("No list-view item selected!\n");
2740 return ERROR_FUNCTION_FAILED;
2744 item.pszText = text;
2745 item.cchTextMax = MAX_PATH;
2746 SendMessageW( control->hwnd, LVM_GETITEMTEXTW, index, (LPARAM)&item );
2748 indirect = control->attributes & msidbControlAttributesIndirect;
2749 prop = msi_dialog_dup_property( dialog, control->property, indirect );
2750 path = msi_dialog_dup_property( dialog, prop, TRUE );
2752 lstrcpyW( new_path, path );
2753 lstrcatW( new_path, text );
2754 lstrcatW( new_path, szBackSlash );
2756 MSI_SetPropertyW( dialog->package, prop, new_path );
2758 msi_dialog_update_directory_list( dialog, NULL );
2759 msi_dialog_update_directory_combo( dialog, NULL );
2760 msi_dialog_update_pathedit( dialog, NULL );
2764 return ERROR_SUCCESS;
2767 static UINT msi_dialog_directory_list( msi_dialog *dialog, MSIRECORD *rec )
2769 msi_control *control;
2773 style = LVS_LIST | WS_VSCROLL | LVS_SHAREIMAGELISTS |
2774 LVS_AUTOARRANGE | LVS_SINGLESEL | WS_BORDER |
2775 LVS_SORTASCENDING | WS_CHILD | WS_GROUP | WS_TABSTOP;
2776 control = msi_dialog_add_control( dialog, rec, WC_LISTVIEWW, style );
2778 return ERROR_FUNCTION_FAILED;
2780 control->attributes = MSI_RecordGetInteger( rec, 8 );
2781 control->handler = msi_dialog_dirlist_handler;
2782 prop = MSI_RecordGetString( rec, 9 );
2783 control->property = msi_dialog_dup_property( dialog, prop, FALSE );
2785 /* double click to activate an item in the list */
2786 SendMessageW( control->hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE,
2787 0, LVS_EX_TWOCLICKACTIVATE );
2789 msi_dialog_update_directory_list( dialog, control );
2791 return ERROR_SUCCESS;
2794 /******************** VolumeCost List ***************************************/
2796 static BOOL str_is_number( LPCWSTR str )
2800 for (i = 0; i < lstrlenW( str ); i++)
2801 if (!isdigitW(str[i]))
2807 static const WCHAR column_keys[][80] =
2809 {'V','o','l','u','m','e','C','o','s','t','V','o','l','u','m','e',0},
2810 {'V','o','l','u','m','e','C','o','s','t','S','i','z','e',0},
2811 {'V','o','l','u','m','e','C','o','s','t','A','v','a','i','l','a','b','l','e',0},
2812 {'V','o','l','u','m','e','C','o','s','t','R','e','q','u','i','r','e','d',0},
2813 {'V','o','l','u','m','e','C','o','s','t','D','i','f','f','e','r','e','n','c','e',0}
2816 static void msi_dialog_vcl_add_columns( msi_dialog *dialog, msi_control *control, MSIRECORD *rec )
2818 LPCWSTR text = MSI_RecordGetString( rec, 10 );
2819 LPCWSTR begin = text, end;
2824 static const WCHAR negative[] = {'-',0};
2828 while ((begin = strchrW( begin, '{' )) && count < 5)
2830 if (!(end = strchrW( begin, '}' )))
2833 num = msi_alloc( (end-begin+1)*sizeof(WCHAR) );
2837 lstrcpynW( num, begin + 1, end - begin );
2838 begin += end - begin + 1;
2840 /* empty braces or '0' hides the column */
2841 if ( !num[0] || !lstrcmpW( num, szZero ) )
2848 /* the width must be a positive number
2849 * if a width is invalid, all remaining columns are hidden
2851 if ( !strncmpW( num, negative, 1 ) || !str_is_number( num ) ) {
2856 ZeroMemory( &lvc, sizeof(lvc) );
2857 lvc.mask = LVCF_TEXT | LVCF_WIDTH | LVCF_SUBITEM;
2858 lvc.cx = atolW( num );
2859 lvc.pszText = msi_dialog_get_uitext( dialog, column_keys[count] );
2861 SendMessageW( control->hwnd, LVM_INSERTCOLUMNW, count++, (LPARAM)&lvc );
2862 msi_free( lvc.pszText );
2867 static LONGLONG msi_vcl_get_cost( msi_dialog *dialog )
2869 MSIFEATURE *feature;
2871 LONGLONG total_cost = 0;
2873 LIST_FOR_EACH_ENTRY( feature, &dialog->package->features, MSIFEATURE, entry )
2875 if (ERROR_SUCCESS == (MSI_GetFeatureCost(dialog->package, feature,
2876 MSICOSTTREE_SELFONLY, INSTALLSTATE_LOCAL, &each_cost)))
2878 /* each_cost is in 512-byte units */
2879 total_cost += each_cost * 512;
2881 if (ERROR_SUCCESS == (MSI_GetFeatureCost(dialog->package, feature,
2882 MSICOSTTREE_SELFONLY, INSTALLSTATE_ABSENT, &each_cost)))
2884 /* each_cost is in 512-byte units */
2885 total_cost -= each_cost * 512;
2891 static void msi_dialog_vcl_add_drives( msi_dialog *dialog, msi_control *control )
2893 ULARGE_INTEGER total, free;
2894 LONGLONG difference, cost;
2895 WCHAR size_text[MAX_PATH];
2896 WCHAR cost_text[MAX_PATH];
2902 cost = msi_vcl_get_cost(dialog);
2903 StrFormatByteSizeW(cost, cost_text, MAX_PATH);
2905 size = GetLogicalDriveStringsW( 0, NULL );
2906 if ( !size ) return;
2908 drives = msi_alloc( (size + 1) * sizeof(WCHAR) );
2909 if ( !drives ) return;
2911 GetLogicalDriveStringsW( size, drives );
2916 lvitem.mask = LVIF_TEXT;
2918 lvitem.iSubItem = 0;
2919 lvitem.pszText = ptr;
2920 lvitem.cchTextMax = lstrlenW(ptr) + 1;
2921 SendMessageW( control->hwnd, LVM_INSERTITEMW, 0, (LPARAM)&lvitem );
2923 GetDiskFreeSpaceExW(ptr, &free, &total, NULL);
2924 difference = free.QuadPart - cost;
2926 StrFormatByteSizeW(total.QuadPart, size_text, MAX_PATH);
2927 lvitem.iSubItem = 1;
2928 lvitem.pszText = size_text;
2929 lvitem.cchTextMax = lstrlenW(size_text) + 1;
2930 SendMessageW( control->hwnd, LVM_SETITEMW, 0, (LPARAM)&lvitem );
2932 StrFormatByteSizeW(free.QuadPart, size_text, MAX_PATH);
2933 lvitem.iSubItem = 2;
2934 lvitem.pszText = size_text;
2935 lvitem.cchTextMax = lstrlenW(size_text) + 1;
2936 SendMessageW( control->hwnd, LVM_SETITEMW, 0, (LPARAM)&lvitem );
2938 lvitem.iSubItem = 3;
2939 lvitem.pszText = cost_text;
2940 lvitem.cchTextMax = lstrlenW(cost_text) + 1;
2941 SendMessageW( control->hwnd, LVM_SETITEMW, 0, (LPARAM)&lvitem );
2943 StrFormatByteSizeW(difference, size_text, MAX_PATH);
2944 lvitem.iSubItem = 4;
2945 lvitem.pszText = size_text;
2946 lvitem.cchTextMax = lstrlenW(size_text) + 1;
2947 SendMessageW( control->hwnd, LVM_SETITEMW, 0, (LPARAM)&lvitem );
2949 ptr += lstrlenW(ptr) + 1;
2956 static UINT msi_dialog_volumecost_list( msi_dialog *dialog, MSIRECORD *rec )
2958 msi_control *control;
2961 style = LVS_REPORT | WS_VSCROLL | WS_HSCROLL | LVS_SHAREIMAGELISTS |
2962 LVS_AUTOARRANGE | LVS_SINGLESEL | WS_BORDER |
2963 WS_CHILD | WS_TABSTOP | WS_GROUP;
2964 control = msi_dialog_add_control( dialog, rec, WC_LISTVIEWW, style );
2966 return ERROR_FUNCTION_FAILED;
2968 msi_dialog_vcl_add_columns( dialog, control, rec );
2969 msi_dialog_vcl_add_drives( dialog, control );
2971 return ERROR_SUCCESS;
2974 /******************** VolumeSelect Combo ***************************************/
2976 static UINT msi_dialog_volsel_handler( msi_dialog *dialog,
2977 msi_control *control, WPARAM param )
2979 WCHAR text[MAX_PATH];
2984 if (HIWORD(param) != CBN_SELCHANGE)
2985 return ERROR_SUCCESS;
2987 index = SendMessageW( control->hwnd, CB_GETCURSEL, 0, 0 );
2988 if ( index == CB_ERR )
2990 ERR("No ComboBox item selected!\n");
2991 return ERROR_FUNCTION_FAILED;
2994 SendMessageW( control->hwnd, CB_GETLBTEXT, index, (LPARAM)text );
2996 indirect = control->attributes & msidbControlAttributesIndirect;
2997 prop = msi_dialog_dup_property( dialog, control->property, indirect );
2999 MSI_SetPropertyW( dialog->package, prop, text );
3002 return ERROR_SUCCESS;
3005 static void msi_dialog_vsc_add_drives( msi_dialog *dialog, msi_control *control )
3010 size = GetLogicalDriveStringsW( 0, NULL );
3011 if ( !size ) return;
3013 drives = msi_alloc( (size + 1) * sizeof(WCHAR) );
3014 if ( !drives ) return;
3016 GetLogicalDriveStringsW( size, drives );
3021 SendMessageW( control->hwnd, CB_ADDSTRING, 0, (LPARAM)ptr );
3022 ptr += lstrlenW(ptr) + 1;
3028 static UINT msi_dialog_volumeselect_combo( msi_dialog *dialog, MSIRECORD *rec )
3030 msi_control *control;
3034 /* FIXME: CBS_OWNERDRAWFIXED */
3035 style = WS_CHILD | WS_VISIBLE | WS_GROUP | WS_TABSTOP |
3036 CBS_DROPDOWNLIST | CBS_SORT | CBS_HASSTRINGS |
3037 WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_RIGHTSCROLLBAR;
3038 control = msi_dialog_add_control( dialog, rec, WC_COMBOBOXW, style );
3040 return ERROR_FUNCTION_FAILED;
3042 control->attributes = MSI_RecordGetInteger( rec, 8 );
3043 control->handler = msi_dialog_volsel_handler;
3044 prop = MSI_RecordGetString( rec, 9 );
3045 control->property = msi_dialog_dup_property( dialog, prop, FALSE );
3047 msi_dialog_vsc_add_drives( dialog, control );
3049 return ERROR_SUCCESS;
3052 static const struct control_handler msi_dialog_handler[] =
3054 { szText, msi_dialog_text_control },
3055 { szPushButton, msi_dialog_button_control },
3056 { szLine, msi_dialog_line_control },
3057 { szBitmap, msi_dialog_bitmap_control },
3058 { szCheckBox, msi_dialog_checkbox_control },
3059 { szScrollableText, msi_dialog_scrolltext_control },
3060 { szComboBox, msi_dialog_combo_control },
3061 { szEdit, msi_dialog_edit_control },
3062 { szMaskedEdit, msi_dialog_maskedit_control },
3063 { szPathEdit, msi_dialog_pathedit_control },
3064 { szProgressBar, msi_dialog_progress_bar },
3065 { szRadioButtonGroup, msi_dialog_radiogroup_control },
3066 { szIcon, msi_dialog_icon_control },
3067 { szSelectionTree, msi_dialog_selection_tree },
3068 { szGroupBox, msi_dialog_group_box },
3069 { szListBox, msi_dialog_list_box },
3070 { szDirectoryCombo, msi_dialog_directory_combo },
3071 { szDirectoryList, msi_dialog_directory_list },
3072 { szVolumeCostList, msi_dialog_volumecost_list },
3073 { szVolumeSelectCombo, msi_dialog_volumeselect_combo },
3076 #define NUM_CONTROL_TYPES (sizeof msi_dialog_handler/sizeof msi_dialog_handler[0])
3078 static UINT msi_dialog_create_controls( MSIRECORD *rec, LPVOID param )
3080 msi_dialog *dialog = param;
3081 LPCWSTR control_type;
3084 /* find and call the function that can create this type of control */
3085 control_type = MSI_RecordGetString( rec, 3 );
3086 for( i=0; i<NUM_CONTROL_TYPES; i++ )
3087 if (!strcmpiW( msi_dialog_handler[i].control_type, control_type ))
3089 if( i != NUM_CONTROL_TYPES )
3090 msi_dialog_handler[i].func( dialog, rec );
3092 ERR("no handler for element type %s\n", debugstr_w(control_type));
3094 return ERROR_SUCCESS;
3097 static UINT msi_dialog_fill_controls( msi_dialog *dialog )
3099 static const WCHAR query[] = {
3100 'S','E','L','E','C','T',' ','*',' ',
3101 'F','R','O','M',' ','C','o','n','t','r','o','l',' ',
3102 'W','H','E','R','E',' ',
3103 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',0};
3105 MSIQUERY *view = NULL;
3106 MSIPACKAGE *package = dialog->package;
3108 TRACE("%p %s\n", dialog, debugstr_w(dialog->name) );
3110 /* query the Control table for all the elements of the control */
3111 r = MSI_OpenQuery( package->db, &view, query, dialog->name );
3112 if( r != ERROR_SUCCESS )
3114 ERR("query failed for dialog %s\n", debugstr_w(dialog->name));
3115 return ERROR_INVALID_PARAMETER;
3118 r = MSI_IterateRecords( view, 0, msi_dialog_create_controls, dialog );
3119 msiobj_release( &view->hdr );
3124 static UINT msi_dialog_set_control_condition( MSIRECORD *rec, LPVOID param )
3126 static const WCHAR szHide[] = { 'H','i','d','e',0 };
3127 static const WCHAR szShow[] = { 'S','h','o','w',0 };
3128 static const WCHAR szDisable[] = { 'D','i','s','a','b','l','e',0 };
3129 static const WCHAR szEnable[] = { 'E','n','a','b','l','e',0 };
3130 static const WCHAR szDefault[] = { 'D','e','f','a','u','l','t',0 };
3131 msi_dialog *dialog = param;
3132 msi_control *control;
3133 LPCWSTR name, action, condition;
3136 name = MSI_RecordGetString( rec, 2 );
3137 action = MSI_RecordGetString( rec, 3 );
3138 condition = MSI_RecordGetString( rec, 4 );
3139 r = MSI_EvaluateConditionW( dialog->package, condition );
3140 control = msi_dialog_find_control( dialog, name );
3141 if( r == MSICONDITION_TRUE && control )
3143 TRACE("%s control %s\n", debugstr_w(action), debugstr_w(name));
3145 /* FIXME: case sensitive? */
3146 if(!lstrcmpW(action, szHide))
3147 ShowWindow(control->hwnd, SW_HIDE);
3148 else if(!strcmpW(action, szShow))
3149 ShowWindow(control->hwnd, SW_SHOW);
3150 else if(!strcmpW(action, szDisable))
3151 EnableWindow(control->hwnd, FALSE);
3152 else if(!strcmpW(action, szEnable))
3153 EnableWindow(control->hwnd, TRUE);
3154 else if(!strcmpW(action, szDefault))
3155 SetFocus(control->hwnd);
3157 FIXME("Unhandled action %s\n", debugstr_w(action));
3160 return ERROR_SUCCESS;
3163 static UINT msi_dialog_evaluate_control_conditions( msi_dialog *dialog )
3165 static const WCHAR query[] = {
3166 'S','E','L','E','C','T',' ','*',' ',
3167 'F','R','O','M',' ',
3168 'C','o','n','t','r','o','l','C','o','n','d','i','t','i','o','n',' ',
3169 'W','H','E','R','E',' ',
3170 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',0
3173 MSIQUERY *view = NULL;
3174 MSIPACKAGE *package = dialog->package;
3176 TRACE("%p %s\n", dialog, debugstr_w(dialog->name) );
3178 /* query the Control table for all the elements of the control */
3179 r = MSI_OpenQuery( package->db, &view, query, dialog->name );
3180 if( r != ERROR_SUCCESS )
3181 return ERROR_SUCCESS;
3183 r = MSI_IterateRecords( view, 0, msi_dialog_set_control_condition, dialog );
3184 msiobj_release( &view->hdr );
3189 UINT msi_dialog_reset( msi_dialog *dialog )
3191 /* FIXME: should restore the original values of any properties we changed */
3192 return msi_dialog_evaluate_control_conditions( dialog );
3195 /* figure out the height of 10 point MS Sans Serif */
3196 static INT msi_dialog_get_sans_serif_height( HWND hwnd )
3198 static const WCHAR szSansSerif[] = {
3199 'M','S',' ','S','a','n','s',' ','S','e','r','i','f',0 };
3204 HFONT hFont, hOldFont;
3207 hdc = GetDC( hwnd );
3210 memset( &lf, 0, sizeof lf );
3211 lf.lfHeight = MulDiv(12, GetDeviceCaps(hdc, LOGPIXELSY), 72);
3212 strcpyW( lf.lfFaceName, szSansSerif );
3213 hFont = CreateFontIndirectW(&lf);
3216 hOldFont = SelectObject( hdc, hFont );
3217 r = GetTextMetricsW( hdc, &tm );
3219 height = tm.tmHeight;
3220 SelectObject( hdc, hOldFont );
3221 DeleteObject( hFont );
3223 ReleaseDC( hwnd, hdc );
3228 /* fetch the associated record from the Dialog table */
3229 static MSIRECORD *msi_get_dialog_record( msi_dialog *dialog )
3231 static const WCHAR query[] = {
3232 'S','E','L','E','C','T',' ','*',' ',
3233 'F','R','O','M',' ','D','i','a','l','o','g',' ',
3234 'W','H','E','R','E',' ',
3235 '`','D','i','a','l','o','g','`',' ','=',' ','\'','%','s','\'',0};
3236 MSIPACKAGE *package = dialog->package;
3237 MSIRECORD *rec = NULL;
3239 TRACE("%p %s\n", dialog, debugstr_w(dialog->name) );
3241 rec = MSI_QueryGetRecord( package->db, query, dialog->name );
3243 WARN("query failed for dialog %s\n", debugstr_w(dialog->name));
3248 static void msi_dialog_adjust_dialog_pos( msi_dialog *dialog, MSIRECORD *rec, LPRECT pos )
3250 static const WCHAR szScreenX[] = {'S','c','r','e','e','n','X',0};
3251 static const WCHAR szScreenY[] = {'S','c','r','e','e','n','Y',0};
3258 center.x = MSI_RecordGetInteger( rec, 2 );
3259 center.y = MSI_RecordGetInteger( rec, 3 );
3261 sz.cx = MSI_RecordGetInteger( rec, 4 );
3262 sz.cy = MSI_RecordGetInteger( rec, 5 );
3264 sz.cx = msi_dialog_scale_unit( dialog, sz.cx );
3265 sz.cy = msi_dialog_scale_unit( dialog, sz.cy );
3267 xres = msi_get_property_int( dialog->package, szScreenX, 0 );
3268 yres = msi_get_property_int( dialog->package, szScreenY, 0 );
3270 center.x = MulDiv( center.x, xres, 100 );
3271 center.y = MulDiv( center.y, yres, 100 );
3273 /* turn the client pos into the window rectangle */
3274 if (dialog->package->center_x && dialog->package->center_y)
3276 pos->left = dialog->package->center_x - sz.cx / 2.0;
3277 pos->right = pos->left + sz.cx;
3278 pos->top = dialog->package->center_y - sz.cy / 2.0;
3279 pos->bottom = pos->top + sz.cy;
3283 pos->left = center.x - sz.cx/2;
3284 pos->right = pos->left + sz.cx;
3285 pos->top = center.y - sz.cy/2;
3286 pos->bottom = pos->top + sz.cy;
3288 /* save the center */
3289 dialog->package->center_x = center.x;
3290 dialog->package->center_y = center.y;
3293 dialog->size.cx = sz.cx;
3294 dialog->size.cy = sz.cy;
3296 TRACE("%u %u %u %u\n", pos->left, pos->top, pos->right, pos->bottom);
3298 style = GetWindowLongPtrW( dialog->hwnd, GWL_STYLE );
3299 AdjustWindowRect( pos, style, FALSE );
3302 static void msi_dialog_set_tab_order( msi_dialog *dialog, LPCWSTR first )
3304 struct list tab_chain;
3305 msi_control *control;
3306 HWND prev = HWND_TOP;
3308 list_init( &tab_chain );
3309 if (!(control = msi_dialog_find_control( dialog, first ))) return;
3311 dialog->hWndFocus = control->hwnd;
3314 list_remove( &control->entry );
3315 list_add_tail( &tab_chain, &control->entry );
3316 if (!control->tabnext) break;
3317 control = msi_dialog_find_control( dialog, control->tabnext );
3320 LIST_FOR_EACH_ENTRY( control, &tab_chain, msi_control, entry )
3322 SetWindowPos( control->hwnd, prev, 0, 0, 0, 0,
3323 SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOREDRAW |
3324 SWP_NOREPOSITION | SWP_NOSENDCHANGING | SWP_NOSIZE );
3325 prev = control->hwnd;
3328 /* put them back on the main list */
3329 list_move_head( &dialog->controls, &tab_chain );
3332 static LRESULT msi_dialog_oncreate( HWND hwnd, LPCREATESTRUCTW cs )
3334 static const WCHAR df[] = {
3335 'D','e','f','a','u','l','t','U','I','F','o','n','t',0 };
3336 static const WCHAR dfv[] = {
3337 'M','S',' ','S','h','e','l','l',' ','D','l','g',0 };
3338 msi_dialog *dialog = cs->lpCreateParams;
3339 MSIRECORD *rec = NULL;
3340 LPWSTR title = NULL;
3343 TRACE("%p %p\n", dialog, dialog->package);
3345 dialog->hwnd = hwnd;
3346 SetWindowLongPtrW( hwnd, GWLP_USERDATA, (LONG_PTR) dialog );
3348 rec = msi_get_dialog_record( dialog );
3351 TRACE("No record found for dialog %s\n", debugstr_w(dialog->name));
3355 dialog->scale = msi_dialog_get_sans_serif_height(dialog->hwnd);
3357 msi_dialog_adjust_dialog_pos( dialog, rec, &pos );
3359 dialog->attributes = MSI_RecordGetInteger( rec, 6 );
3361 dialog->default_font = msi_dup_property( dialog->package, df );
3362 if (!dialog->default_font)
3364 dialog->default_font = strdupW(dfv);
3365 if (!dialog->default_font) return -1;
3368 title = msi_get_deformatted_field( dialog->package, rec, 7 );
3369 SetWindowTextW( hwnd, title );
3372 SetWindowPos( hwnd, 0, pos.left, pos.top,
3373 pos.right - pos.left, pos.bottom - pos.top,
3374 SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOREDRAW );
3376 msi_dialog_build_font_list( dialog );
3377 msi_dialog_fill_controls( dialog );
3378 msi_dialog_evaluate_control_conditions( dialog );
3379 msi_dialog_set_tab_order( dialog, MSI_RecordGetString( rec, 8 ) );
3380 msiobj_release( &rec->hdr );
3385 static UINT msi_dialog_send_event( msi_dialog *dialog, LPCWSTR event, LPCWSTR arg )
3387 LPWSTR event_fmt = NULL, arg_fmt = NULL;
3389 TRACE("Sending control event %s %s\n", debugstr_w(event), debugstr_w(arg));
3391 deformat_string( dialog->package, event, &event_fmt );
3392 deformat_string( dialog->package, arg, &arg_fmt );
3394 dialog->event_handler( dialog->package, event_fmt, arg_fmt, dialog );
3396 msi_free( event_fmt );
3397 msi_free( arg_fmt );
3399 return ERROR_SUCCESS;
3402 static UINT msi_dialog_set_property( msi_dialog *dialog, LPCWSTR event, LPCWSTR arg )
3404 static const WCHAR szNullArg[] = { '{','}',0 };
3405 LPWSTR p, prop, arg_fmt = NULL;
3408 len = strlenW(event);
3409 prop = msi_alloc( len*sizeof(WCHAR));
3410 strcpyW( prop, &event[1] );
3411 p = strchrW( prop, ']' );
3412 if( p && (p[1] == 0 || p[1] == ' ') )
3415 if( strcmpW( szNullArg, arg ) )
3416 deformat_string( dialog->package, arg, &arg_fmt );
3417 MSI_SetPropertyW( dialog->package, prop, arg_fmt );
3418 msi_dialog_update_controls( dialog, prop );
3419 msi_free( arg_fmt );
3422 ERR("Badly formatted property string - what happens?\n");
3424 return ERROR_SUCCESS;
3427 static UINT msi_dialog_control_event( MSIRECORD *rec, LPVOID param )
3429 msi_dialog *dialog = param;
3430 LPCWSTR condition, event, arg;
3433 condition = MSI_RecordGetString( rec, 5 );
3434 r = MSI_EvaluateConditionW( dialog->package, condition );
3435 if( r == MSICONDITION_TRUE || r == MSICONDITION_NONE )
3437 event = MSI_RecordGetString( rec, 3 );
3438 arg = MSI_RecordGetString( rec, 4 );
3439 if( event[0] == '[' )
3440 msi_dialog_set_property( dialog, event, arg );
3442 msi_dialog_send_event( dialog, event, arg );
3445 return ERROR_SUCCESS;
3454 static UINT add_rec_to_list( MSIRECORD *rec, LPVOID param )
3456 struct rec_list *add_rec;
3457 struct list *records = param;
3459 msiobj_addref( &rec->hdr );
3461 add_rec = msi_alloc( sizeof( *add_rec ) );
3464 msiobj_release( &rec->hdr );
3465 return ERROR_OUTOFMEMORY;
3469 list_add_tail( records, &add_rec->entry );
3470 return ERROR_SUCCESS;
3473 static inline void remove_rec_from_list( struct rec_list *rec_entry )
3475 msiobj_release( &rec_entry->rec->hdr );
3476 list_remove( &rec_entry->entry );
3477 msi_free( rec_entry );
3480 static UINT msi_dialog_button_handler( msi_dialog *dialog,
3481 msi_control *control, WPARAM param )
3483 static const WCHAR query[] = {
3484 'S','E','L','E','C','T',' ','*',' ',
3485 'F','R','O','M',' ','C','o','n','t','r','o','l','E','v','e','n','t',' ',
3486 'W','H','E','R','E',' ',
3487 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',' ',
3489 '`','C','o','n','t','r','o','l','_','`',' ','=',' ','\'','%','s','\'',' ',
3490 'O','R','D','E','R',' ','B','Y',' ','`','O','r','d','e','r','i','n','g','`',0
3492 MSIQUERY *view = NULL;
3493 struct rec_list *rec_entry, *next;
3497 if( HIWORD(param) != BN_CLICKED )
3498 return ERROR_SUCCESS;
3500 list_init( &events );
3502 r = MSI_OpenQuery( dialog->package->db, &view, query,
3503 dialog->name, control->name );
3504 if( r != ERROR_SUCCESS )
3506 ERR("query failed\n");
3510 r = MSI_IterateRecords( view, 0, add_rec_to_list, &events );
3511 msiobj_release( &view->hdr );
3512 if (r != ERROR_SUCCESS)
3515 /* handle all SetProperty events first */
3516 LIST_FOR_EACH_ENTRY_SAFE( rec_entry, next, &events, struct rec_list, entry )
3518 LPCWSTR event = MSI_RecordGetString( rec_entry->rec, 3 );
3520 if ( event[0] != '[' )
3523 r = msi_dialog_control_event( rec_entry->rec, dialog );
3524 remove_rec_from_list( rec_entry );
3526 if ( r != ERROR_SUCCESS )
3530 /* handle all other events */
3531 LIST_FOR_EACH_ENTRY_SAFE( rec_entry, next, &events, struct rec_list, entry )
3533 r = msi_dialog_control_event( rec_entry->rec, dialog );
3534 remove_rec_from_list( rec_entry );
3536 if ( r != ERROR_SUCCESS )
3541 LIST_FOR_EACH_ENTRY_SAFE( rec_entry, next, &events, struct rec_list, entry )
3543 remove_rec_from_list( rec_entry );
3549 static UINT msi_dialog_get_checkbox_state( msi_dialog *dialog,
3550 msi_control *control )
3552 WCHAR state[2] = { 0 };
3555 MSI_GetPropertyW( dialog->package, control->property, state, &sz );
3556 return state[0] ? 1 : 0;
3559 static void msi_dialog_set_checkbox_state( msi_dialog *dialog,
3560 msi_control *control, UINT state )
3562 static const WCHAR szState[] = { '1', 0 };
3565 /* if uncheck then the property is set to NULL */
3568 MSI_SetPropertyW( dialog->package, control->property, NULL );
3572 /* check for a custom state */
3573 if (control->value && control->value[0])
3574 val = control->value;
3578 MSI_SetPropertyW( dialog->package, control->property, val );
3581 static void msi_dialog_checkbox_sync_state( msi_dialog *dialog,
3582 msi_control *control )
3586 state = msi_dialog_get_checkbox_state( dialog, control );
3587 SendMessageW( control->hwnd, BM_SETCHECK,
3588 state ? BST_CHECKED : BST_UNCHECKED, 0 );
3591 static UINT msi_dialog_checkbox_handler( msi_dialog *dialog,
3592 msi_control *control, WPARAM param )
3596 if( HIWORD(param) != BN_CLICKED )
3597 return ERROR_SUCCESS;
3599 TRACE("clicked checkbox %s, set %s\n", debugstr_w(control->name),
3600 debugstr_w(control->property));
3602 state = msi_dialog_get_checkbox_state( dialog, control );
3603 state = state ? 0 : 1;
3604 msi_dialog_set_checkbox_state( dialog, control, state );
3605 msi_dialog_checkbox_sync_state( dialog, control );
3607 return msi_dialog_button_handler( dialog, control, param );
3610 static UINT msi_dialog_edit_handler( msi_dialog *dialog,
3611 msi_control *control, WPARAM param )
3615 if( HIWORD(param) != EN_CHANGE )
3616 return ERROR_SUCCESS;
3618 TRACE("edit %s contents changed, set %s\n", debugstr_w(control->name),
3619 debugstr_w(control->property));
3621 buf = msi_get_window_text( control->hwnd );
3622 MSI_SetPropertyW( dialog->package, control->property, buf );
3626 return ERROR_SUCCESS;
3629 static UINT msi_dialog_radiogroup_handler( msi_dialog *dialog,
3630 msi_control *control, WPARAM param )
3632 if( HIWORD(param) != BN_CLICKED )
3633 return ERROR_SUCCESS;
3635 TRACE("clicked radio button %s, set %s\n", debugstr_w(control->name),
3636 debugstr_w(control->property));
3638 MSI_SetPropertyW( dialog->package, control->property, control->name );
3640 return msi_dialog_button_handler( dialog, control, param );
3643 static LRESULT msi_dialog_oncommand( msi_dialog *dialog, WPARAM param, HWND hwnd )
3645 msi_control *control = NULL;
3647 TRACE("%p %p %08lx\n", dialog, hwnd, param);
3652 control = msi_dialog_find_control( dialog, dialog->control_default );
3654 case 2: /* escape */
3655 control = msi_dialog_find_control( dialog, dialog->control_cancel );
3658 control = msi_dialog_find_control_by_hwnd( dialog, hwnd );
3663 if( control->handler )
3665 control->handler( dialog, control, param );
3666 msi_dialog_evaluate_control_conditions( dialog );
3673 static LRESULT msi_dialog_onnotify( msi_dialog *dialog, LPARAM param )
3675 LPNMHDR nmhdr = (LPNMHDR) param;
3676 msi_control *control = msi_dialog_find_control_by_hwnd( dialog, nmhdr->hwndFrom );
3678 TRACE("%p %p\n", dialog, nmhdr->hwndFrom);
3680 if ( control && control->handler )
3681 control->handler( dialog, control, param );
3686 static void msi_dialog_setfocus( msi_dialog *dialog )
3688 HWND hwnd = dialog->hWndFocus;
3690 hwnd = GetNextDlgTabItem( dialog->hwnd, hwnd, TRUE);
3691 hwnd = GetNextDlgTabItem( dialog->hwnd, hwnd, FALSE);
3693 dialog->hWndFocus = hwnd;
3696 static LRESULT WINAPI MSIDialog_WndProc( HWND hwnd, UINT msg,
3697 WPARAM wParam, LPARAM lParam )
3699 msi_dialog *dialog = (LPVOID) GetWindowLongPtrW( hwnd, GWLP_USERDATA );
3701 TRACE("0x%04x\n", msg);
3706 dialog->package->center_x = LOWORD(lParam) + dialog->size.cx / 2.0;
3707 dialog->package->center_y = HIWORD(lParam) + dialog->size.cy / 2.0;
3711 return msi_dialog_oncreate( hwnd, (LPCREATESTRUCTW)lParam );
3714 return msi_dialog_oncommand( dialog, wParam, (HWND)lParam );
3717 if( LOWORD(wParam) == WA_INACTIVE )
3718 dialog->hWndFocus = GetFocus();
3720 msi_dialog_setfocus( dialog );
3724 msi_dialog_setfocus( dialog );
3727 /* bounce back to our subclassed static control */
3728 case WM_CTLCOLORSTATIC:
3729 return SendMessageW( (HWND) lParam, WM_CTLCOLORSTATIC, wParam, lParam );
3732 dialog->hwnd = NULL;
3735 return msi_dialog_onnotify( dialog, lParam );
3737 return DefWindowProcW(hwnd, msg, wParam, lParam);
3740 static BOOL CALLBACK msi_radioground_child_enum( HWND hWnd, LPARAM lParam )
3742 EnableWindow( hWnd, lParam );
3746 static LRESULT WINAPI MSIRadioGroup_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
3748 WNDPROC oldproc = (WNDPROC) GetPropW(hWnd, szButtonData);
3751 TRACE("hWnd %p msg %04x wParam 0x%08lx lParam 0x%08lx\n", hWnd, msg, wParam, lParam);
3753 if (msg == WM_COMMAND) /* Forward notifications to dialog */
3754 SendMessageW(GetParent(hWnd), msg, wParam, lParam);
3756 r = CallWindowProcW(oldproc, hWnd, msg, wParam, lParam);
3758 /* make sure the radio buttons show as disabled if the parent is disabled */
3759 if (msg == WM_ENABLE)
3760 EnumChildWindows( hWnd, msi_radioground_child_enum, wParam );
3765 static LRESULT WINAPI MSIHiddenWindowProc( HWND hwnd, UINT msg,
3766 WPARAM wParam, LPARAM lParam )
3768 msi_dialog *dialog = (msi_dialog*) lParam;
3770 TRACE("%d %p\n", msg, dialog);
3774 case WM_MSI_DIALOG_CREATE:
3775 return msi_dialog_run_message_loop( dialog );
3776 case WM_MSI_DIALOG_DESTROY:
3777 msi_dialog_destroy( dialog );
3780 return DefWindowProcW( hwnd, msg, wParam, lParam );
3783 static BOOL msi_dialog_register_class( void )
3787 ZeroMemory( &cls, sizeof cls );
3788 cls.lpfnWndProc = MSIDialog_WndProc;
3789 cls.hInstance = NULL;
3790 cls.hIcon = LoadIconW(0, (LPWSTR)IDI_APPLICATION);
3791 cls.hCursor = LoadCursorW(0, (LPWSTR)IDC_ARROW);
3792 cls.hbrBackground = (HBRUSH)(COLOR_3DFACE + 1);
3793 cls.lpszMenuName = NULL;
3794 cls.lpszClassName = szMsiDialogClass;
3796 if( !RegisterClassW( &cls ) )
3799 cls.lpfnWndProc = MSIHiddenWindowProc;
3800 cls.lpszClassName = szMsiHiddenWindow;
3802 if( !RegisterClassW( &cls ) )
3805 uiThreadId = GetCurrentThreadId();
3807 hMsiHiddenWindow = CreateWindowW( szMsiHiddenWindow, NULL, WS_OVERLAPPED,
3808 0, 0, 100, 100, NULL, NULL, NULL, NULL );
3809 if( !hMsiHiddenWindow )
3815 /* functions that interface to other modules within MSI */
3817 msi_dialog *msi_dialog_create( MSIPACKAGE* package,
3818 LPCWSTR szDialogName, msi_dialog *parent,
3819 msi_dialog_event_handler event_handler )
3821 MSIRECORD *rec = NULL;
3824 TRACE("%p %s\n", package, debugstr_w(szDialogName));
3826 if (!hMsiHiddenWindow)
3827 msi_dialog_register_class();
3829 /* allocate the structure for the dialog to use */
3830 dialog = msi_alloc_zero( sizeof *dialog + sizeof(WCHAR)*strlenW(szDialogName) );
3833 strcpyW( dialog->name, szDialogName );
3834 dialog->parent = parent;
3835 msiobj_addref( &package->hdr );
3836 dialog->package = package;
3837 dialog->event_handler = event_handler;
3838 dialog->finished = 0;
3839 list_init( &dialog->controls );
3841 /* verify that the dialog exists */
3842 rec = msi_get_dialog_record( dialog );
3845 msiobj_release( &package->hdr );
3849 dialog->attributes = MSI_RecordGetInteger( rec, 6 );
3850 dialog->control_default = strdupW( MSI_RecordGetString( rec, 9 ) );
3851 dialog->control_cancel = strdupW( MSI_RecordGetString( rec, 10 ) );
3852 msiobj_release( &rec->hdr );
3857 static void msi_process_pending_messages( HWND hdlg )
3861 while( PeekMessageW( &msg, 0, 0, 0, PM_REMOVE ) )
3863 if( hdlg && IsDialogMessageW( hdlg, &msg ))
3865 TranslateMessage( &msg );
3866 DispatchMessageW( &msg );
3870 void msi_dialog_end_dialog( msi_dialog *dialog )
3872 TRACE("%p\n", dialog);
3873 dialog->finished = 1;
3874 PostMessageW(dialog->hwnd, WM_NULL, 0, 0);
3877 void msi_dialog_check_messages( HANDLE handle )
3881 /* in threads other than the UI thread, block */
3882 if( uiThreadId != GetCurrentThreadId() )
3885 WaitForSingleObject( handle, INFINITE );
3889 /* there's two choices for the UI thread */
3892 msi_process_pending_messages( NULL );
3898 * block here until somebody creates a new dialog or
3899 * the handle we're waiting on becomes ready
3901 r = MsgWaitForMultipleObjects( 1, &handle, 0, INFINITE, QS_ALLINPUT );
3902 if( r == WAIT_OBJECT_0 )
3907 UINT msi_dialog_run_message_loop( msi_dialog *dialog )
3912 if( uiThreadId != GetCurrentThreadId() )
3913 return SendMessageW( hMsiHiddenWindow, WM_MSI_DIALOG_CREATE, 0, (LPARAM) dialog );
3915 /* create the dialog window, don't show it yet */
3916 style = WS_OVERLAPPED;
3917 if( dialog->attributes & msidbDialogAttributesVisible )
3918 style |= WS_VISIBLE;
3920 hwnd = CreateWindowW( szMsiDialogClass, dialog->name, style,
3921 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
3922 NULL, NULL, NULL, dialog );
3925 ERR("Failed to create dialog %s\n", debugstr_w( dialog->name ));
3926 return ERROR_FUNCTION_FAILED;
3929 ShowWindow( hwnd, SW_SHOW );
3930 /* UpdateWindow( hwnd ); - and causes the transparent static controls not to paint */
3932 if( dialog->attributes & msidbDialogAttributesModal )
3934 while( !dialog->finished )
3936 MsgWaitForMultipleObjects( 0, NULL, 0, INFINITE, QS_ALLINPUT );
3937 msi_process_pending_messages( dialog->hwnd );
3941 return ERROR_IO_PENDING;
3943 return ERROR_SUCCESS;
3946 void msi_dialog_do_preview( msi_dialog *dialog )
3949 dialog->attributes |= msidbDialogAttributesVisible;
3950 dialog->attributes &= ~msidbDialogAttributesModal;
3951 msi_dialog_run_message_loop( dialog );
3954 void msi_dialog_destroy( msi_dialog *dialog )
3956 if( uiThreadId != GetCurrentThreadId() )
3958 SendMessageW( hMsiHiddenWindow, WM_MSI_DIALOG_DESTROY, 0, (LPARAM) dialog );
3963 ShowWindow( dialog->hwnd, SW_HIDE );
3966 DestroyWindow( dialog->hwnd );
3968 /* unsubscribe events */
3969 ControlEvent_CleanupDialogSubscriptions(dialog->package, dialog->name);
3971 /* destroy the list of controls */
3972 while( !list_empty( &dialog->controls ) )
3976 t = LIST_ENTRY( list_head( &dialog->controls ),
3977 msi_control, entry );
3978 msi_destroy_control( t );
3981 /* destroy the list of fonts */
3982 while( dialog->font_list )
3984 msi_font *t = dialog->font_list;
3985 dialog->font_list = t->next;
3986 DeleteObject( t->hfont );
3989 msi_free( dialog->default_font );
3991 msi_free( dialog->control_default );
3992 msi_free( dialog->control_cancel );
3993 msiobj_release( &dialog->package->hdr );
3994 dialog->package = NULL;
3998 void msi_dialog_unregister_class( void )
4000 DestroyWindow( hMsiHiddenWindow );
4001 hMsiHiddenWindow = NULL;
4002 UnregisterClassW( szMsiDialogClass, NULL );
4003 UnregisterClassW( szMsiHiddenWindow, NULL );
4007 static UINT error_dialog_handler(MSIPACKAGE *package, LPCWSTR event,
4008 LPCWSTR argument, msi_dialog* dialog)
4010 static const WCHAR end_dialog[] = {'E','n','d','D','i','a','l','o','g',0};
4011 static const WCHAR error_abort[] = {'E','r','r','o','r','A','b','o','r','t',0};
4012 static const WCHAR error_cancel[] = {'E','r','r','o','r','C','a','n','c','e','l',0};
4013 static const WCHAR error_no[] = {'E','r','r','o','r','N','o',0};
4014 static const WCHAR result_prop[] = {
4015 'M','S','I','E','r','r','o','r','D','i','a','l','o','g','R','e','s','u','l','t',0
4018 if ( lstrcmpW( event, end_dialog ) )
4019 return ERROR_SUCCESS;
4021 if ( !lstrcmpW( argument, error_abort ) || !lstrcmpW( argument, error_cancel ) ||
4022 !lstrcmpW( argument, error_no ) )
4024 MSI_SetPropertyW( package, result_prop, error_abort );
4027 ControlEvent_CleanupSubscriptions(package);
4028 msi_dialog_end_dialog( dialog );
4030 return ERROR_SUCCESS;
4033 static UINT msi_error_dialog_set_error( MSIPACKAGE *package, LPWSTR error_dialog, LPWSTR error )
4037 static const WCHAR update[] =
4038 {'U','P','D','A','T','E',' ','`','C','o','n','t','r','o','l','`',' ',
4039 'S','E','T',' ','`','T','e','x','t','`',' ','=',' ','\'','%','s','\'',' ',
4040 'W','H','E','R','E', ' ','`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',' ',
4041 'A','N','D',' ','`','C','o','n','t','r','o','l','`',' ','=',' ',
4042 '\'','E','r','r','o','r','T','e','x','t','\'',0};
4044 row = MSI_QueryGetRecord( package->db, update, error, error_dialog );
4046 return ERROR_FUNCTION_FAILED;
4048 msiobj_release(&row->hdr);
4049 return ERROR_SUCCESS;
4052 UINT msi_spawn_error_dialog( MSIPACKAGE *package, LPWSTR error_dialog, LPWSTR error )
4055 WCHAR result[MAX_PATH];
4056 UINT r = ERROR_SUCCESS;
4057 DWORD size = MAX_PATH;
4060 static const WCHAR pn_prop[] = {'P','r','o','d','u','c','t','N','a','m','e',0};
4061 static const WCHAR title_fmt[] = {'%','s',' ','W','a','r','n','i','n','g',0};
4062 static const WCHAR error_abort[] = {'E','r','r','o','r','A','b','o','r','t',0};
4063 static const WCHAR result_prop[] = {
4064 'M','S','I','E','r','r','o','r','D','i','a','l','o','g','R','e','s','u','l','t',0
4067 if ( (msi_get_property_int(package, szUILevel, 0) & INSTALLUILEVEL_MASK) == INSTALLUILEVEL_NONE )
4068 return ERROR_SUCCESS;
4070 if ( !error_dialog )
4072 LPWSTR product_name = msi_dup_property( package, pn_prop );
4073 WCHAR title[MAX_PATH];
4075 sprintfW( title, title_fmt, product_name );
4076 res = MessageBoxW( NULL, error, title, MB_OKCANCEL | MB_ICONWARNING );
4078 msi_free( product_name );
4081 return ERROR_SUCCESS;
4083 return ERROR_FUNCTION_FAILED;
4086 r = msi_error_dialog_set_error( package, error_dialog, error );
4087 if ( r != ERROR_SUCCESS )
4090 dialog = msi_dialog_create( package, error_dialog, package->dialog,
4091 error_dialog_handler );
4093 return ERROR_FUNCTION_FAILED;
4095 dialog->finished = FALSE;
4096 r = msi_dialog_run_message_loop( dialog );
4097 if ( r != ERROR_SUCCESS )
4100 r = MSI_GetPropertyW( package, result_prop, result, &size );
4101 if ( r != ERROR_SUCCESS)
4104 if ( !lstrcmpW( result, error_abort ) )
4105 r = ERROR_FUNCTION_FAILED;
4108 msi_dialog_destroy( dialog );