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->db, property );
242 prop = strdupW( property );
247 msi_dialog *msi_dialog_get_parent( msi_dialog *dialog )
249 return dialog->parent;
252 LPWSTR msi_dialog_get_name( msi_dialog *dialog )
258 * msi_dialog_get_style
260 * Extract the {\style} string from the front of the text to display and
261 * update the pointer. Only the last style in a list is applied.
263 static LPWSTR msi_dialog_get_style( LPCWSTR p, LPCWSTR *rest )
274 while ((first = strchrW( p, '{' )) && (q = strchrW( first + 1, '}' )))
277 if( *p != '\\' && *p != '&' )
280 /* little bit of sanity checking to stop us getting confused with RTF */
281 for( i=++p; i<q; i++ )
282 if( *i == '}' || *i == '\\' )
292 ret = msi_alloc( len*sizeof(WCHAR) );
295 memcpy( ret, p, len*sizeof(WCHAR) );
300 static UINT msi_dialog_add_font( MSIRECORD *rec, LPVOID param )
302 msi_dialog *dialog = param;
309 /* create a font and add it to the list */
310 name = MSI_RecordGetString( rec, 1 );
311 font = msi_alloc( sizeof *font + strlenW( name )*sizeof (WCHAR) );
312 strcpyW( font->name, name );
313 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 static void msi_dialog_set_property( MSIPACKAGE *package, LPCWSTR property, LPCWSTR value )
588 UINT r = msi_set_property( package->db, property, value );
589 if (r == ERROR_SUCCESS && !strcmpW( property, cszSourceDir ))
590 msi_reset_folders( package, TRUE );
593 /* called from the Control Event subscription code */
594 void msi_dialog_handle_event( msi_dialog* dialog, LPCWSTR control,
595 LPCWSTR attribute, MSIRECORD *rec )
598 LPCWSTR font_text, text = NULL;
601 ctrl = msi_dialog_find_control( dialog, control );
604 if( !lstrcmpW(attribute, szText) )
606 font_text = MSI_RecordGetString( rec , 1 );
607 font = msi_dialog_get_style( font_text, &text );
608 if (!text) text = szEmpty;
609 SetWindowTextW( ctrl->hwnd, text );
611 msi_dialog_check_messages( NULL );
613 else if( !lstrcmpW(attribute, szProgress) )
617 func = MSI_RecordGetInteger( rec , 1 );
618 val = MSI_RecordGetInteger( rec , 2 );
620 TRACE("progress: func %u, val %u\n", func, val);
625 ctrl->progress_max = val;
626 ctrl->progress_current = 0;
627 SendMessageW(ctrl->hwnd, PBM_SETRANGE, 0, MAKELPARAM(0,100));
628 SendMessageW(ctrl->hwnd, PBM_SETPOS, 0, 0);
630 case 1: /* FIXME: not sure what this is supposed to do */
633 ctrl->progress_current += val;
634 if (ctrl->progress_current > ctrl->progress_max)
635 ctrl->progress_current = ctrl->progress_max;
636 SendMessageW(ctrl->hwnd, PBM_SETPOS, MulDiv(100, ctrl->progress_current, ctrl->progress_max), 0);
639 FIXME("Unknown progress message %u\n", func);
643 else if ( !lstrcmpW(attribute, szProperty) )
645 MSIFEATURE *feature = msi_seltree_get_selected_feature( ctrl );
646 msi_dialog_set_property( dialog->package, ctrl->property, feature->Directory );
648 else if ( !lstrcmpW(attribute, szSelectionPath) )
650 LPWSTR prop = msi_dialog_dup_property( dialog, ctrl->property, TRUE );
653 path = msi_dup_property( dialog->package->db, prop );
654 SetWindowTextW( ctrl->hwnd, path );
660 FIXME("Attribute %s not being set\n", debugstr_w(attribute));
665 static void msi_dialog_map_events(msi_dialog* dialog, LPCWSTR control)
667 static const WCHAR Query[] = {
668 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
669 '`','E','v','e','n','t','M','a','p','p','i','n','g','`',' ',
670 'W','H','E','R','E',' ',
671 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',' ',
673 '`','C','o','n','t','r','o','l','_','`',' ','=',' ','\'','%','s','\'',0
676 LPCWSTR event, attribute;
678 row = MSI_QueryGetRecord( dialog->package->db, Query, dialog->name, control );
682 event = MSI_RecordGetString( row, 3 );
683 attribute = MSI_RecordGetString( row, 4 );
684 ControlEvent_SubscribeToEvent( dialog->package, dialog, event, control, attribute );
685 msiobj_release( &row->hdr );
688 /* everything except radio buttons */
689 static msi_control *msi_dialog_add_control( msi_dialog *dialog,
690 MSIRECORD *rec, LPCWSTR szCls, DWORD style )
696 name = MSI_RecordGetString( rec, 2 );
697 attributes = MSI_RecordGetInteger( rec, 8 );
698 text = MSI_RecordGetString( rec, 10 );
700 TRACE("%s, %s, %08x, %s, %08x\n", debugstr_w(szCls), debugstr_w(name),
701 attributes, debugstr_w(text), style);
703 if( attributes & msidbControlAttributesVisible )
705 if( ~attributes & msidbControlAttributesEnabled )
706 style |= WS_DISABLED;
707 if( attributes & msidbControlAttributesSunken )
708 exstyle |= WS_EX_CLIENTEDGE;
710 msi_dialog_map_events(dialog, name);
712 return msi_dialog_create_window( dialog, rec, exstyle, szCls, name,
713 text, style, dialog->hwnd );
724 * we don't erase our own background,
725 * so we have to make sure that the parent window redraws first
727 static void msi_text_on_settext( HWND hWnd )
732 hParent = GetParent( hWnd );
733 GetWindowRect( hWnd, &rc );
734 MapWindowPoints( NULL, hParent, (LPPOINT) &rc, 2 );
735 InvalidateRect( hParent, &rc, TRUE );
738 static LRESULT WINAPI
739 MSIText_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
741 struct msi_text_info *info;
744 TRACE("%p %04x %08lx %08lx\n", hWnd, msg, wParam, lParam);
746 info = GetPropW(hWnd, szButtonData);
748 if( msg == WM_CTLCOLORSTATIC &&
749 ( info->attributes & msidbControlAttributesTransparent ) )
751 SetBkMode( (HDC)wParam, TRANSPARENT );
752 return (LRESULT) GetStockObject(NULL_BRUSH);
755 r = CallWindowProcW(info->oldproc, hWnd, msg, wParam, lParam);
757 SetTextColor( (HDC)wParam, info->font->color );
762 msi_text_on_settext( hWnd );
766 RemovePropW( hWnd, szButtonData );
773 static UINT msi_dialog_text_control( msi_dialog *dialog, MSIRECORD *rec )
775 msi_control *control;
776 struct msi_text_info *info;
777 LPCWSTR text, ptr, prop;
780 TRACE("%p %p\n", dialog, rec);
782 control = msi_dialog_add_control( dialog, rec, szStatic, SS_LEFT | WS_GROUP );
784 return ERROR_FUNCTION_FAILED;
786 info = msi_alloc( sizeof *info );
788 return ERROR_SUCCESS;
790 control->attributes = MSI_RecordGetInteger( rec, 8 );
791 prop = MSI_RecordGetString( rec, 9 );
792 control->property = msi_dialog_dup_property( dialog, prop, FALSE );
794 text = MSI_RecordGetString( rec, 10 );
795 font_name = msi_dialog_get_style( text, &ptr );
796 info->font = ( font_name ) ? msi_dialog_find_font( dialog, font_name ) : NULL;
797 msi_free( font_name );
799 info->attributes = MSI_RecordGetInteger( rec, 8 );
800 if( info->attributes & msidbControlAttributesTransparent )
801 SetWindowLongPtrW( control->hwnd, GWL_EXSTYLE, WS_EX_TRANSPARENT );
803 info->oldproc = (WNDPROC) SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
804 (LONG_PTR)MSIText_WndProc );
805 SetPropW( control->hwnd, szButtonData, info );
807 ControlEvent_SubscribeToEvent( dialog->package, dialog,
808 szSelectionPath, control->name, szSelectionPath );
810 return ERROR_SUCCESS;
813 /* strip any leading text style label from text field */
814 static WCHAR *msi_get_binary_name( MSIPACKAGE *package, MSIRECORD *rec )
818 text = msi_get_deformatted_field( package, rec, 10 );
823 while (*p && *p != '{') p++;
824 if (!*p++) return text;
826 while (*p && *p != '}') p++;
827 if (!*p++) return text;
834 static UINT msi_dialog_button_control( msi_dialog *dialog, MSIRECORD *rec )
836 msi_control *control;
837 UINT attributes, style;
839 TRACE("%p %p\n", dialog, rec);
842 attributes = MSI_RecordGetInteger( rec, 8 );
843 if( attributes & msidbControlAttributesIcon )
846 control = msi_dialog_add_control( dialog, rec, szButton, style );
848 return ERROR_FUNCTION_FAILED;
850 control->handler = msi_dialog_button_handler;
852 if (attributes & msidbControlAttributesIcon)
855 LPWSTR name = msi_get_binary_name( dialog->package, rec );
856 control->hIcon = msi_load_icon( dialog->package->db, name, attributes );
859 SendMessageW( control->hwnd, BM_SETIMAGE, IMAGE_ICON, (LPARAM) control->hIcon );
862 ERR("Failed to load icon %s\n", debugstr_w(name));
866 return ERROR_SUCCESS;
869 static LPWSTR msi_get_checkbox_value( msi_dialog *dialog, LPCWSTR prop )
871 static const WCHAR query[] = {
872 'S','E','L','E','C','T',' ','*',' ',
873 'F','R','O','M',' ','`','C','h','e','c','k','B','o','x','`',' ',
874 'W','H','E','R','E',' ',
875 '`','P','r','o','p','e','r','t','y','`',' ','=',' ',
878 MSIRECORD *rec = NULL;
881 /* find if there is a value associated with the checkbox */
882 rec = MSI_QueryGetRecord( dialog->package->db, query, prop );
886 ret = msi_get_deformatted_field( dialog->package, rec, 2 );
892 msiobj_release( &rec->hdr );
896 ret = msi_dup_property( dialog->package->db, prop );
906 static UINT msi_dialog_checkbox_control( msi_dialog *dialog, MSIRECORD *rec )
908 msi_control *control;
911 TRACE("%p %p\n", dialog, rec);
913 control = msi_dialog_add_control( dialog, rec, szButton,
914 BS_CHECKBOX | BS_MULTILINE | WS_TABSTOP );
915 control->handler = msi_dialog_checkbox_handler;
916 control->update = msi_dialog_checkbox_sync_state;
917 prop = MSI_RecordGetString( rec, 9 );
920 control->property = strdupW( prop );
921 control->value = msi_get_checkbox_value( dialog, prop );
922 TRACE("control %s value %s\n", debugstr_w(control->property),
923 debugstr_w(control->value));
925 msi_dialog_checkbox_sync_state( dialog, control );
927 return ERROR_SUCCESS;
930 static UINT msi_dialog_line_control( msi_dialog *dialog, MSIRECORD *rec )
934 DWORD style, exstyle = 0;
935 DWORD x, y, width, height;
936 msi_control *control;
938 TRACE("%p %p\n", dialog, rec);
940 style = WS_CHILD | SS_ETCHEDHORZ | SS_SUNKEN;
942 name = MSI_RecordGetString( rec, 2 );
943 attributes = MSI_RecordGetInteger( rec, 8 );
945 if( attributes & msidbControlAttributesVisible )
947 if( ~attributes & msidbControlAttributesEnabled )
948 style |= WS_DISABLED;
949 if( attributes & msidbControlAttributesSunken )
950 exstyle |= WS_EX_CLIENTEDGE;
952 msi_dialog_map_events(dialog, name);
954 control = msi_alloc( sizeof(*control) + strlenW(name) * sizeof(WCHAR) );
956 return ERROR_OUTOFMEMORY;
958 strcpyW( control->name, name );
959 list_add_head( &dialog->controls, &control->entry );
960 control->handler = NULL;
961 control->property = NULL;
962 control->value = NULL;
963 control->hBitmap = NULL;
964 control->hIcon = NULL;
965 control->hDll = NULL;
966 control->tabnext = strdupW( MSI_RecordGetString( rec, 11) );
967 control->type = strdupW( MSI_RecordGetString( rec, 3 ) );
968 control->progress_current = 0;
969 control->progress_max = 100;
971 x = MSI_RecordGetInteger( rec, 4 );
972 y = MSI_RecordGetInteger( rec, 5 );
973 width = MSI_RecordGetInteger( rec, 6 );
975 x = msi_dialog_scale_unit( dialog, x );
976 y = msi_dialog_scale_unit( dialog, y );
977 width = msi_dialog_scale_unit( dialog, width );
978 height = 2; /* line is exactly 2 units in height */
980 control->hwnd = CreateWindowExW( exstyle, szStatic, NULL, style,
981 x, y, width, height, dialog->hwnd, NULL, NULL, NULL );
983 TRACE("Dialog %s control %s hwnd %p\n",
984 debugstr_w(dialog->name), debugstr_w(name), control->hwnd );
986 return ERROR_SUCCESS;
989 /******************** Scroll Text ********************************************/
991 struct msi_scrolltext_info
994 msi_control *control;
998 static LRESULT WINAPI
999 MSIScrollText_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
1001 struct msi_scrolltext_info *info;
1004 TRACE("%p %04x %08lx %08lx\n", hWnd, msg, wParam, lParam);
1006 info = GetPropW( hWnd, szButtonData );
1008 r = CallWindowProcW( info->oldproc, hWnd, msg, wParam, lParam );
1014 RemovePropW( hWnd, szButtonData );
1017 /* native MSI sets a wait cursor here */
1018 msi_dialog_button_handler( info->dialog, info->control, BN_CLICKED );
1024 struct msi_streamin_info
1031 static DWORD CALLBACK
1032 msi_richedit_stream_in( DWORD_PTR arg, LPBYTE buffer, LONG count, LONG *pcb )
1034 struct msi_streamin_info *info = (struct msi_streamin_info*) arg;
1036 if( (count + info->offset) > info->length )
1037 count = info->length - info->offset;
1038 memcpy( buffer, &info->string[ info->offset ], count );
1040 info->offset += count;
1042 TRACE("%d/%d\n", info->offset, info->length);
1047 static void msi_scrolltext_add_text( msi_control *control, LPCWSTR text )
1049 struct msi_streamin_info info;
1052 info.string = strdupWtoA( text );
1054 info.length = lstrlenA( info.string ) + 1;
1056 es.dwCookie = (DWORD_PTR) &info;
1058 es.pfnCallback = msi_richedit_stream_in;
1060 SendMessageW( control->hwnd, EM_STREAMIN, SF_RTF, (LPARAM) &es );
1062 msi_free( info.string );
1065 static UINT msi_dialog_scrolltext_control( msi_dialog *dialog, MSIRECORD *rec )
1067 static const WCHAR szRichEdit20W[] = {
1068 'R','i','c','h','E','d','i','t','2','0','W',0
1070 struct msi_scrolltext_info *info;
1071 msi_control *control;
1076 info = msi_alloc( sizeof *info );
1078 return ERROR_FUNCTION_FAILED;
1080 hRichedit = LoadLibraryA("riched20");
1082 style = WS_BORDER | ES_MULTILINE | WS_VSCROLL |
1083 ES_READONLY | ES_AUTOVSCROLL | WS_TABSTOP;
1084 control = msi_dialog_add_control( dialog, rec, szRichEdit20W, style );
1087 FreeLibrary( hRichedit );
1089 return ERROR_FUNCTION_FAILED;
1092 control->hDll = hRichedit;
1094 info->dialog = dialog;
1095 info->control = control;
1097 /* subclass the static control */
1098 info->oldproc = (WNDPROC) SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
1099 (LONG_PTR)MSIScrollText_WndProc );
1100 SetPropW( control->hwnd, szButtonData, info );
1102 /* add the text into the richedit */
1103 text = MSI_RecordGetString( rec, 10 );
1105 msi_scrolltext_add_text( control, text );
1107 return ERROR_SUCCESS;
1110 static HBITMAP msi_load_picture( MSIDATABASE *db, LPCWSTR name,
1111 INT cx, INT cy, DWORD flags )
1113 HBITMAP hOleBitmap = 0, hBitmap = 0, hOldSrcBitmap, hOldDestBitmap;
1114 MSIRECORD *rec = NULL;
1115 IStream *stm = NULL;
1116 IPicture *pic = NULL;
1121 rec = msi_get_binary_record( db, name );
1125 r = MSI_RecordGetIStream( rec, 2, &stm );
1126 msiobj_release( &rec->hdr );
1127 if( r != ERROR_SUCCESS )
1130 r = OleLoadPicture( stm, 0, TRUE, &IID_IPicture, (LPVOID*) &pic );
1131 IStream_Release( stm );
1134 ERR("failed to load picture\n");
1138 r = IPicture_get_Handle( pic, (OLE_HANDLE*) &hOleBitmap );
1141 ERR("failed to get bitmap handle\n");
1145 /* make the bitmap the desired size */
1146 r = GetObjectW( hOleBitmap, sizeof bm, &bm );
1147 if (r != sizeof bm )
1149 ERR("failed to get bitmap size\n");
1153 if (flags & LR_DEFAULTSIZE)
1159 srcdc = CreateCompatibleDC( NULL );
1160 hOldSrcBitmap = SelectObject( srcdc, hOleBitmap );
1161 destdc = CreateCompatibleDC( NULL );
1162 hBitmap = CreateCompatibleBitmap( srcdc, cx, cy );
1163 hOldDestBitmap = SelectObject( destdc, hBitmap );
1164 StretchBlt( destdc, 0, 0, cx, cy,
1165 srcdc, 0, 0, bm.bmWidth, bm.bmHeight, SRCCOPY);
1166 SelectObject( srcdc, hOldSrcBitmap );
1167 SelectObject( destdc, hOldDestBitmap );
1173 IPicture_Release( pic );
1177 static UINT msi_dialog_bitmap_control( msi_dialog *dialog, MSIRECORD *rec )
1179 UINT cx, cy, flags, style, attributes;
1180 msi_control *control;
1183 flags = LR_LOADFROMFILE;
1184 style = SS_BITMAP | SS_LEFT | WS_GROUP;
1186 attributes = MSI_RecordGetInteger( rec, 8 );
1187 if( attributes & msidbControlAttributesFixedSize )
1189 flags |= LR_DEFAULTSIZE;
1190 style |= SS_CENTERIMAGE;
1193 control = msi_dialog_add_control( dialog, rec, szStatic, style );
1194 cx = MSI_RecordGetInteger( rec, 6 );
1195 cy = MSI_RecordGetInteger( rec, 7 );
1196 cx = msi_dialog_scale_unit( dialog, cx );
1197 cy = msi_dialog_scale_unit( dialog, cy );
1199 name = msi_get_binary_name( dialog->package, rec );
1200 control->hBitmap = msi_load_picture( dialog->package->db, name, cx, cy, flags );
1201 if( control->hBitmap )
1202 SendMessageW( control->hwnd, STM_SETIMAGE,
1203 IMAGE_BITMAP, (LPARAM) control->hBitmap );
1205 ERR("Failed to load bitmap %s\n", debugstr_w(name));
1209 return ERROR_SUCCESS;
1212 static UINT msi_dialog_icon_control( msi_dialog *dialog, MSIRECORD *rec )
1214 msi_control *control;
1220 control = msi_dialog_add_control( dialog, rec, szStatic,
1221 SS_ICON | SS_CENTERIMAGE | WS_GROUP );
1223 attributes = MSI_RecordGetInteger( rec, 8 );
1224 name = msi_get_binary_name( dialog->package, rec );
1225 control->hIcon = msi_load_icon( dialog->package->db, name, attributes );
1226 if( control->hIcon )
1227 SendMessageW( control->hwnd, STM_SETICON, (WPARAM) control->hIcon, 0 );
1229 ERR("Failed to load bitmap %s\n", debugstr_w(name));
1231 return ERROR_SUCCESS;
1234 /******************** Combo Box ***************************************/
1236 struct msi_combobox_info
1246 static LRESULT WINAPI MSIComboBox_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
1248 struct msi_combobox_info *info;
1252 TRACE("%p %04x %08lx %08lx\n", hWnd, msg, wParam, lParam);
1254 info = GetPropW( hWnd, szButtonData );
1258 r = CallWindowProcW( info->oldproc, hWnd, msg, wParam, lParam );
1263 for (j = 0; j < info->num_items; j++)
1264 msi_free( info->items[j] );
1265 msi_free( info->items );
1267 RemovePropW( hWnd, szButtonData );
1274 static UINT msi_combobox_add_item( MSIRECORD *rec, LPVOID param )
1276 struct msi_combobox_info *info = param;
1277 LPCWSTR value, text;
1280 value = MSI_RecordGetString( rec, 3 );
1281 text = MSI_RecordGetString( rec, 4 );
1283 info->items[info->addpos_items] = strdupW( value );
1285 pos = SendMessageW( info->hwnd, CB_ADDSTRING, 0, (LPARAM)text );
1286 SendMessageW( info->hwnd, CB_SETITEMDATA, pos, (LPARAM)info->items[info->addpos_items] );
1287 info->addpos_items++;
1289 return ERROR_SUCCESS;
1292 static UINT msi_combobox_add_items( struct msi_combobox_info *info, LPCWSTR property )
1295 MSIQUERY *view = NULL;
1298 static const WCHAR query[] = {
1299 'S','E','L','E','C','T',' ','*',' ',
1300 'F','R','O','M',' ','`','C','o','m','b','o','B','o','x','`',' ',
1301 'W','H','E','R','E',' ',
1302 '`','P','r','o','p','e','r','t','y','`',' ','=',' ','\'','%','s','\'',' ',
1303 'O','R','D','E','R',' ','B','Y',' ','`','O','r','d','e','r','`',0
1306 r = MSI_OpenQuery( info->dialog->package->db, &view, query, property );
1307 if (r != ERROR_SUCCESS)
1310 /* just get the number of records */
1312 r = MSI_IterateRecords( view, &count, NULL, NULL );
1314 info->num_items = count;
1315 info->items = msi_alloc( sizeof(*info->items) * count );
1317 r = MSI_IterateRecords( view, NULL, msi_combobox_add_item, info );
1318 msiobj_release( &view->hdr );
1323 static UINT msi_dialog_combobox_handler( msi_dialog *dialog,
1324 msi_control *control, WPARAM param )
1326 struct msi_combobox_info *info;
1330 if (HIWORD(param) != CBN_SELCHANGE && HIWORD(param) != CBN_EDITCHANGE)
1331 return ERROR_SUCCESS;
1333 info = GetPropW( control->hwnd, szButtonData );
1334 index = SendMessageW( control->hwnd, CB_GETCURSEL, 0, 0 );
1335 if (index == CB_ERR)
1336 value = msi_get_window_text( control->hwnd );
1338 value = (LPWSTR) SendMessageW( control->hwnd, CB_GETITEMDATA, index, 0 );
1340 msi_dialog_set_property( info->dialog->package, control->property, value );
1341 msi_dialog_evaluate_control_conditions( info->dialog );
1343 if (index == CB_ERR)
1346 return ERROR_SUCCESS;
1349 static void msi_dialog_combobox_update( msi_dialog *dialog,
1350 msi_control *control )
1352 struct msi_combobox_info *info;
1356 info = GetPropW( control->hwnd, szButtonData );
1358 value = msi_dup_property( dialog->package->db, control->property );
1361 SendMessageW( control->hwnd, CB_SETCURSEL, -1, 0 );
1365 for (j = 0; j < info->num_items; j++)
1367 tmp = (LPWSTR) SendMessageW( control->hwnd, CB_GETITEMDATA, j, 0 );
1368 if (!lstrcmpW( value, tmp ))
1372 if (j < info->num_items)
1374 SendMessageW( control->hwnd, CB_SETCURSEL, j, 0 );
1378 SendMessageW( control->hwnd, CB_SETCURSEL, -1, 0 );
1379 SetWindowTextW( control->hwnd, value );
1385 static UINT msi_dialog_combo_control( msi_dialog *dialog, MSIRECORD *rec )
1387 struct msi_combobox_info *info;
1388 msi_control *control;
1389 DWORD attributes, style;
1392 info = msi_alloc( sizeof *info );
1394 return ERROR_FUNCTION_FAILED;
1396 style = CBS_AUTOHSCROLL | WS_TABSTOP | WS_GROUP | WS_CHILD;
1397 attributes = MSI_RecordGetInteger( rec, 8 );
1398 if ( ~attributes & msidbControlAttributesSorted)
1400 if ( attributes & msidbControlAttributesComboList)
1401 style |= CBS_DROPDOWNLIST;
1403 style |= CBS_DROPDOWN;
1405 control = msi_dialog_add_control( dialog, rec, WC_COMBOBOXW, style );
1409 return ERROR_FUNCTION_FAILED;
1412 control->handler = msi_dialog_combobox_handler;
1413 control->update = msi_dialog_combobox_update;
1415 prop = MSI_RecordGetString( rec, 9 );
1416 control->property = msi_dialog_dup_property( dialog, prop, FALSE );
1419 info->dialog = dialog;
1420 info->hwnd = control->hwnd;
1422 info->addpos_items = 0;
1423 info->oldproc = (WNDPROC)SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
1424 (LONG_PTR)MSIComboBox_WndProc );
1425 SetPropW( control->hwnd, szButtonData, info );
1427 if (control->property)
1428 msi_combobox_add_items( info, control->property );
1430 msi_dialog_combobox_update( dialog, control );
1432 return ERROR_SUCCESS;
1435 /* length of 2^32 + 1 */
1436 #define MAX_NUM_DIGITS 11
1438 static UINT msi_dialog_edit_control( msi_dialog *dialog, MSIRECORD *rec )
1440 msi_control *control;
1442 LPWSTR val, begin, end;
1443 WCHAR num[MAX_NUM_DIGITS];
1446 control = msi_dialog_add_control( dialog, rec, szEdit,
1447 WS_BORDER | WS_TABSTOP | ES_AUTOHSCROLL );
1448 control->handler = msi_dialog_edit_handler;
1450 text = MSI_RecordGetString( rec, 10 );
1453 begin = strchrW( text, '{' );
1454 end = strchrW( text, '}' );
1456 if ( begin && end && end > begin &&
1457 begin[0] >= '0' && begin[0] <= '9' &&
1458 end - begin < MAX_NUM_DIGITS)
1460 lstrcpynW( num, begin + 1, end - begin );
1461 limit = atolW( num );
1463 SendMessageW( control->hwnd, EM_SETLIMITTEXT, limit, 0 );
1467 prop = MSI_RecordGetString( rec, 9 );
1469 control->property = strdupW( prop );
1471 val = msi_dup_property( dialog->package->db, control->property );
1472 SetWindowTextW( control->hwnd, val );
1474 return ERROR_SUCCESS;
1477 /******************** Masked Edit ********************************************/
1479 #define MASK_MAX_GROUPS 20
1481 struct msi_mask_group
1489 struct msi_maskedit_info
1497 struct msi_mask_group group[MASK_MAX_GROUPS];
1500 static BOOL msi_mask_editable( WCHAR type )
1515 static void msi_mask_control_change( struct msi_maskedit_info *info )
1520 val = msi_alloc( (info->num_chars+1)*sizeof(WCHAR) );
1521 for( i=0, n=0; i<info->num_groups; i++ )
1523 if( (info->group[i].len + n) > info->num_chars )
1525 ERR("can't fit control %d text into template\n",i);
1528 if (!msi_mask_editable(info->group[i].type))
1530 for(r=0; r<info->group[i].len; r++)
1531 val[n+r] = info->group[i].type;
1536 r = GetWindowTextW( info->group[i].hwnd, &val[n], info->group[i].len+1 );
1537 if( r != info->group[i].len )
1543 TRACE("%d/%d controls were good\n", i, info->num_groups);
1545 if( i == info->num_groups )
1547 TRACE("Set property %s to %s\n", debugstr_w(info->prop), debugstr_w(val));
1548 CharUpperBuffW( val, info->num_chars );
1549 msi_dialog_set_property( info->dialog->package, info->prop, val );
1550 msi_dialog_evaluate_control_conditions( info->dialog );
1555 /* now move to the next control if necessary */
1556 static VOID msi_mask_next_control( struct msi_maskedit_info *info, HWND hWnd )
1561 for( i=0; i<info->num_groups; i++ )
1562 if( info->group[i].hwnd == hWnd )
1565 /* don't move from the last control */
1566 if( i >= (info->num_groups-1) )
1569 len = SendMessageW( hWnd, WM_GETTEXTLENGTH, 0, 0 );
1570 if( len < info->group[i].len )
1573 hWndNext = GetNextDlgTabItem( GetParent( hWnd ), hWnd, FALSE );
1574 SetFocus( hWndNext );
1577 static LRESULT WINAPI
1578 MSIMaskedEdit_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
1580 struct msi_maskedit_info *info;
1583 TRACE("%p %04x %08lx %08lx\n", hWnd, msg, wParam, lParam);
1585 info = GetPropW(hWnd, szButtonData);
1587 r = CallWindowProcW(info->oldproc, hWnd, msg, wParam, lParam);
1592 if (HIWORD(wParam) == EN_CHANGE)
1594 msi_mask_control_change( info );
1595 msi_mask_next_control( info, (HWND) lParam );
1599 msi_free( info->prop );
1601 RemovePropW( hWnd, szButtonData );
1608 /* fish the various bits of the property out and put them in the control */
1610 msi_maskedit_set_text( struct msi_maskedit_info *info, LPCWSTR text )
1616 for( i = 0; i < info->num_groups; i++ )
1618 if( info->group[i].len < strlenW( p ) )
1620 LPWSTR chunk = strdupW( p );
1621 chunk[ info->group[i].len ] = 0;
1622 SetWindowTextW( info->group[i].hwnd, chunk );
1627 SetWindowTextW( info->group[i].hwnd, p );
1630 p += info->group[i].len;
1634 static struct msi_maskedit_info * msi_dialog_parse_groups( LPCWSTR mask )
1636 struct msi_maskedit_info * info = NULL;
1637 int i = 0, n = 0, total = 0;
1640 TRACE("masked control, template %s\n", debugstr_w(mask));
1645 info = msi_alloc_zero( sizeof *info );
1649 p = strchrW(mask, '<');
1655 for( i=0; i<MASK_MAX_GROUPS; i++ )
1657 /* stop at the end of the string */
1658 if( p[0] == 0 || p[0] == '>' )
1661 /* count the number of the same identifier */
1662 for( n=0; p[n] == p[0]; n++ )
1664 info->group[i].ofs = total;
1665 info->group[i].type = p[0];
1669 total++; /* an extra not part of the group */
1671 info->group[i].len = n;
1676 TRACE("%d characters in %d groups\n", total, i );
1677 if( i == MASK_MAX_GROUPS )
1678 ERR("too many groups in PIDTemplate %s\n", debugstr_w(mask));
1680 info->num_chars = total;
1681 info->num_groups = i;
1687 msi_maskedit_create_children( struct msi_maskedit_info *info, LPCWSTR font )
1689 DWORD width, height, style, wx, ww;
1694 style = WS_CHILD | WS_BORDER | WS_VISIBLE | WS_TABSTOP | ES_AUTOHSCROLL;
1696 GetClientRect( info->hwnd, &rect );
1698 width = rect.right - rect.left;
1699 height = rect.bottom - rect.top;
1701 for( i = 0; i < info->num_groups; i++ )
1703 if (!msi_mask_editable( info->group[i].type ))
1705 wx = (info->group[i].ofs * width) / info->num_chars;
1706 ww = (info->group[i].len * width) / info->num_chars;
1708 hwnd = CreateWindowW( szEdit, NULL, style, wx, 0, ww, height,
1709 info->hwnd, NULL, NULL, NULL );
1712 ERR("failed to create mask edit sub window\n");
1716 SendMessageW( hwnd, EM_LIMITTEXT, info->group[i].len, 0 );
1718 msi_dialog_set_font( info->dialog, hwnd,
1719 font?font:info->dialog->default_font );
1720 info->group[i].hwnd = hwnd;
1725 * office 2003 uses "73931<````=````=````=````=`````>@@@@@"
1726 * delphi 7 uses "<????-??????-??????-????>" and "<???-???>"
1727 * filemaker pro 7 uses "<^^^^=^^^^=^^^^=^^^^=^^^^=^^^^=^^^^^>"
1729 static UINT msi_dialog_maskedit_control( msi_dialog *dialog, MSIRECORD *rec )
1731 LPWSTR font_mask, val = NULL, font;
1732 struct msi_maskedit_info *info = NULL;
1733 UINT ret = ERROR_SUCCESS;
1734 msi_control *control;
1739 font_mask = msi_get_deformatted_field( dialog->package, rec, 10 );
1740 font = msi_dialog_get_style( font_mask, &mask );
1743 ERR("mask template is empty\n");
1747 info = msi_dialog_parse_groups( mask );
1750 ERR("template %s is invalid\n", debugstr_w(mask));
1754 info->dialog = dialog;
1756 control = msi_dialog_add_control( dialog, rec, szStatic,
1757 SS_OWNERDRAW | WS_GROUP | WS_VISIBLE );
1760 ERR("Failed to create maskedit container\n");
1761 ret = ERROR_FUNCTION_FAILED;
1764 SetWindowLongPtrW( control->hwnd, GWL_EXSTYLE, WS_EX_CONTROLPARENT );
1766 info->hwnd = control->hwnd;
1768 /* subclass the static control */
1769 info->oldproc = (WNDPROC) SetWindowLongPtrW( info->hwnd, GWLP_WNDPROC,
1770 (LONG_PTR)MSIMaskedEdit_WndProc );
1771 SetPropW( control->hwnd, szButtonData, info );
1773 prop = MSI_RecordGetString( rec, 9 );
1775 info->prop = strdupW( prop );
1777 msi_maskedit_create_children( info, font );
1781 val = msi_dup_property( dialog->package->db, prop );
1784 msi_maskedit_set_text( info, val );
1790 if( ret != ERROR_SUCCESS )
1792 msi_free( font_mask );
1797 /******************** Progress Bar *****************************************/
1799 static UINT msi_dialog_progress_bar( msi_dialog *dialog, MSIRECORD *rec )
1801 msi_control *control;
1802 DWORD attributes, style;
1805 attributes = MSI_RecordGetInteger( rec, 8 );
1806 if( !(attributes & msidbControlAttributesProgress95) )
1807 style |= PBS_SMOOTH;
1809 control = msi_dialog_add_control( dialog, rec, PROGRESS_CLASSW, style );
1811 return ERROR_FUNCTION_FAILED;
1813 ControlEvent_SubscribeToEvent( dialog->package, dialog,
1814 szSetProgress, control->name, szProgress );
1815 return ERROR_SUCCESS;
1818 /******************** Path Edit ********************************************/
1820 struct msi_pathedit_info
1823 msi_control *control;
1827 static LPWSTR msi_get_window_text( HWND hwnd )
1833 buf = msi_alloc( sz*sizeof(WCHAR) );
1836 r = GetWindowTextW( hwnd, buf, sz );
1840 buf = msi_realloc( buf, sz*sizeof(WCHAR) );
1846 static void msi_dialog_update_pathedit( msi_dialog *dialog, msi_control *control )
1851 if (!control && !(control = msi_dialog_find_control_by_type( dialog, szPathEdit )))
1854 indirect = control->attributes & msidbControlAttributesIndirect;
1855 prop = msi_dialog_dup_property( dialog, control->property, indirect );
1856 path = msi_dialog_dup_property( dialog, prop, TRUE );
1858 SetWindowTextW( control->hwnd, path );
1859 SendMessageW( control->hwnd, EM_SETSEL, 0, -1 );
1865 /* FIXME: test when this should fail */
1866 static BOOL msi_dialog_verify_path( LPWSTR path )
1868 if ( !lstrlenW( path ) )
1871 if ( PathIsRelativeW( path ) )
1877 /* returns TRUE if the path is valid, FALSE otherwise */
1878 static BOOL msi_dialog_onkillfocus( msi_dialog *dialog, msi_control *control )
1884 indirect = control->attributes & msidbControlAttributesIndirect;
1885 prop = msi_dialog_dup_property( dialog, control->property, indirect );
1887 buf = msi_get_window_text( control->hwnd );
1889 if ( !msi_dialog_verify_path( buf ) )
1891 /* FIXME: display an error message box */
1892 ERR("Invalid path %s\n", debugstr_w( buf ));
1894 SetFocus( control->hwnd );
1899 msi_dialog_set_property( dialog->package, prop, buf );
1902 msi_dialog_update_pathedit( dialog, control );
1904 TRACE("edit %s contents changed, set %s\n", debugstr_w(control->name),
1913 static LRESULT WINAPI MSIPathEdit_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
1915 struct msi_pathedit_info *info = GetPropW(hWnd, szButtonData);
1918 TRACE("%p %04x %08lx %08lx\n", hWnd, msg, wParam, lParam);
1920 if ( msg == WM_KILLFOCUS )
1922 /* if the path is invalid, don't handle this message */
1923 if ( !msi_dialog_onkillfocus( info->dialog, info->control ) )
1927 r = CallWindowProcW(info->oldproc, hWnd, msg, wParam, lParam);
1929 if ( msg == WM_NCDESTROY )
1932 RemovePropW( hWnd, szButtonData );
1938 static UINT msi_dialog_pathedit_control( msi_dialog *dialog, MSIRECORD *rec )
1940 struct msi_pathedit_info *info;
1941 msi_control *control;
1944 info = msi_alloc( sizeof *info );
1946 return ERROR_FUNCTION_FAILED;
1948 control = msi_dialog_add_control( dialog, rec, szEdit,
1949 WS_BORDER | WS_TABSTOP );
1950 control->attributes = MSI_RecordGetInteger( rec, 8 );
1951 prop = MSI_RecordGetString( rec, 9 );
1952 control->property = msi_dialog_dup_property( dialog, prop, FALSE );
1954 info->dialog = dialog;
1955 info->control = control;
1956 info->oldproc = (WNDPROC) SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
1957 (LONG_PTR)MSIPathEdit_WndProc );
1958 SetPropW( control->hwnd, szButtonData, info );
1960 msi_dialog_update_pathedit( dialog, control );
1962 return ERROR_SUCCESS;
1965 /* radio buttons are a bit different from normal controls */
1966 static UINT msi_dialog_create_radiobutton( MSIRECORD *rec, LPVOID param )
1968 radio_button_group_descr *group = param;
1969 msi_dialog *dialog = group->dialog;
1970 msi_control *control;
1971 LPCWSTR prop, text, name;
1972 DWORD style, attributes = group->attributes;
1974 style = WS_CHILD | BS_AUTORADIOBUTTON | BS_MULTILINE | WS_TABSTOP;
1975 name = MSI_RecordGetString( rec, 3 );
1976 text = MSI_RecordGetString( rec, 8 );
1977 if( attributes & msidbControlAttributesVisible )
1978 style |= WS_VISIBLE;
1979 if( ~attributes & msidbControlAttributesEnabled )
1980 style |= WS_DISABLED;
1982 control = msi_dialog_create_window( dialog, rec, 0, szButton, name, text,
1983 style, group->parent->hwnd );
1985 return ERROR_FUNCTION_FAILED;
1986 control->handler = msi_dialog_radiogroup_handler;
1988 if (!lstrcmpW(control->name, group->propval))
1989 SendMessageW(control->hwnd, BM_SETCHECK, BST_CHECKED, 0);
1991 prop = MSI_RecordGetString( rec, 1 );
1993 control->property = strdupW( prop );
1995 return ERROR_SUCCESS;
1998 static UINT msi_dialog_radiogroup_control( msi_dialog *dialog, MSIRECORD *rec )
2000 static const WCHAR query[] = {
2001 'S','E','L','E','C','T',' ','*',' ',
2002 'F','R','O','M',' ','R','a','d','i','o','B','u','t','t','o','n',' ',
2003 'W','H','E','R','E',' ',
2004 '`','P','r','o','p','e','r','t','y','`',' ','=',' ','\'','%','s','\'',0};
2007 msi_control *control;
2008 MSIQUERY *view = NULL;
2009 radio_button_group_descr group;
2010 MSIPACKAGE *package = dialog->package;
2012 DWORD attr, style = WS_GROUP;
2014 prop = MSI_RecordGetString( rec, 9 );
2016 TRACE("%p %p %s\n", dialog, rec, debugstr_w( prop ));
2018 attr = MSI_RecordGetInteger( rec, 8 );
2019 if (attr & msidbControlAttributesHasBorder)
2020 style |= BS_GROUPBOX;
2022 style |= BS_OWNERDRAW;
2024 /* Create parent group box to hold radio buttons */
2025 control = msi_dialog_add_control( dialog, rec, szButton, style );
2027 return ERROR_FUNCTION_FAILED;
2029 oldproc = (WNDPROC) SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
2030 (LONG_PTR)MSIRadioGroup_WndProc );
2031 SetPropW(control->hwnd, szButtonData, oldproc);
2032 SetWindowLongPtrW( control->hwnd, GWL_EXSTYLE, WS_EX_CONTROLPARENT );
2035 control->property = strdupW( prop );
2037 /* query the Radio Button table for all control in this group */
2038 r = MSI_OpenQuery( package->db, &view, query, prop );
2039 if( r != ERROR_SUCCESS )
2041 ERR("query failed for dialog %s radio group %s\n",
2042 debugstr_w(dialog->name), debugstr_w(prop));
2043 return ERROR_INVALID_PARAMETER;
2046 group.dialog = dialog;
2047 group.parent = control;
2048 group.attributes = MSI_RecordGetInteger( rec, 8 );
2049 group.propval = msi_dup_property( dialog->package->db, control->property );
2051 r = MSI_IterateRecords( view, 0, msi_dialog_create_radiobutton, &group );
2052 msiobj_release( &view->hdr );
2053 msi_free( group.propval );
2058 /******************** Selection Tree ***************************************/
2060 struct msi_selection_tree_info
2069 msi_seltree_sync_item_state( HWND hwnd, MSIFEATURE *feature, HTREEITEM hItem )
2072 DWORD index = feature->Action;
2074 TRACE("Feature %s -> %d %d %d\n", debugstr_w(feature->Title),
2075 feature->Installed, feature->Action, feature->ActionRequest);
2077 if (index == INSTALLSTATE_UNKNOWN)
2078 index = INSTALLSTATE_ABSENT;
2080 tvi.mask = TVIF_STATE;
2082 tvi.state = INDEXTOSTATEIMAGEMASK( index );
2083 tvi.stateMask = TVIS_STATEIMAGEMASK;
2085 SendMessageW( hwnd, TVM_SETITEMW, 0, (LPARAM) &tvi );
2089 msi_seltree_popup_menu( HWND hwnd, INT x, INT y )
2094 /* create a menu to display */
2095 hMenu = CreatePopupMenu();
2097 /* FIXME: load strings from resources */
2098 AppendMenuA( hMenu, MF_ENABLED, INSTALLSTATE_LOCAL, "Install feature locally");
2099 AppendMenuA( hMenu, MF_ENABLED, USER_INSTALLSTATE_ALL, "Install entire feature");
2100 AppendMenuA( hMenu, MF_ENABLED, INSTALLSTATE_ADVERTISED, "Install on demand");
2101 AppendMenuA( hMenu, MF_ENABLED, INSTALLSTATE_ABSENT, "Don't install");
2102 r = TrackPopupMenu( hMenu, TPM_LEFTALIGN | TPM_TOPALIGN | TPM_RETURNCMD,
2103 x, y, 0, hwnd, NULL );
2104 DestroyMenu( hMenu );
2109 msi_seltree_feature_from_item( HWND hwnd, HTREEITEM hItem )
2113 /* get the feature from the item */
2114 memset( &tvi, 0, sizeof tvi );
2116 tvi.mask = TVIF_PARAM | TVIF_HANDLE;
2117 SendMessageW( hwnd, TVM_GETITEMW, 0, (LPARAM) &tvi );
2119 return (MSIFEATURE*) tvi.lParam;
2123 msi_seltree_update_feature_installstate( HWND hwnd, HTREEITEM hItem,
2124 MSIPACKAGE *package, MSIFEATURE *feature, INSTALLSTATE state )
2126 msi_feature_set_state( package, feature, state );
2127 msi_seltree_sync_item_state( hwnd, feature, hItem );
2128 ACTION_UpdateComponentStates( package, feature->Feature );
2132 msi_seltree_update_siblings_and_children_installstate( HWND hwnd, HTREEITEM curr,
2133 MSIPACKAGE *package, INSTALLSTATE state)
2135 /* update all siblings */
2138 MSIFEATURE *feature;
2141 feature = msi_seltree_feature_from_item( hwnd, curr );
2142 msi_seltree_update_feature_installstate( hwnd, curr, package, feature, state );
2144 /* update this sibling's children */
2145 child = (HTREEITEM)SendMessageW( hwnd, TVM_GETNEXTITEM, (WPARAM)TVGN_CHILD, (LPARAM)curr );
2147 msi_seltree_update_siblings_and_children_installstate( hwnd, child,
2150 while ((curr = (HTREEITEM)SendMessageW( hwnd, TVM_GETNEXTITEM, (WPARAM)TVGN_NEXT, (LPARAM)curr )));
2154 msi_seltree_menu( HWND hwnd, HTREEITEM hItem )
2156 struct msi_selection_tree_info *info;
2157 MSIFEATURE *feature;
2158 MSIPACKAGE *package;
2166 info = GetPropW(hwnd, szButtonData);
2167 package = info->dialog->package;
2169 feature = msi_seltree_feature_from_item( hwnd, hItem );
2172 ERR("item %p feature was NULL\n", hItem);
2176 /* get the item's rectangle to put the menu just below it */
2178 SendMessageW( hwnd, TVM_GETITEMRECT, 0, (LPARAM) &u.rc );
2179 MapWindowPoints( hwnd, NULL, u.pt, 2 );
2181 r = msi_seltree_popup_menu( hwnd, u.rc.left, u.rc.top );
2185 case USER_INSTALLSTATE_ALL:
2186 r = INSTALLSTATE_LOCAL;
2188 case INSTALLSTATE_ADVERTISED:
2189 case INSTALLSTATE_ABSENT:
2192 child = (HTREEITEM)SendMessageW( hwnd, TVM_GETNEXTITEM, (WPARAM)TVGN_CHILD, (LPARAM)hItem );
2194 msi_seltree_update_siblings_and_children_installstate( hwnd, child, package, r );
2197 case INSTALLSTATE_LOCAL:
2198 msi_seltree_update_feature_installstate( hwnd, hItem, package, feature, r );
2205 static MSIFEATURE *msi_seltree_get_selected_feature( msi_control *control )
2207 struct msi_selection_tree_info *info = GetPropW(control->hwnd, szButtonData);
2208 return msi_seltree_feature_from_item( control->hwnd, info->selected );
2211 static LRESULT WINAPI
2212 MSISelectionTree_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
2214 struct msi_selection_tree_info *info;
2215 TVHITTESTINFO tvhti;
2218 TRACE("%p %04x %08lx %08lx\n", hWnd, msg, wParam, lParam);
2220 info = GetPropW(hWnd, szButtonData);
2224 case WM_LBUTTONDOWN:
2225 tvhti.pt.x = (short)LOWORD( lParam );
2226 tvhti.pt.y = (short)HIWORD( lParam );
2229 r = CallWindowProcW(info->oldproc, hWnd, TVM_HITTEST, 0, (LPARAM) &tvhti );
2230 if (tvhti.flags & TVHT_ONITEMSTATEICON)
2231 return msi_seltree_menu( hWnd, tvhti.hItem );
2235 r = CallWindowProcW(info->oldproc, hWnd, msg, wParam, lParam);
2241 RemovePropW( hWnd, szButtonData );
2248 msi_seltree_add_child_features( MSIPACKAGE *package, HWND hwnd,
2249 LPCWSTR parent, HTREEITEM hParent )
2251 struct msi_selection_tree_info *info = GetPropW( hwnd, szButtonData );
2252 MSIFEATURE *feature;
2253 TVINSERTSTRUCTW tvis;
2254 HTREEITEM hitem, hfirst = NULL;
2256 LIST_FOR_EACH_ENTRY( feature, &package->features, MSIFEATURE, entry )
2258 if ( lstrcmpW( parent, feature->Feature_Parent ) )
2261 if ( !feature->Title )
2264 if ( !feature->Display )
2267 memset( &tvis, 0, sizeof tvis );
2268 tvis.hParent = hParent;
2269 tvis.hInsertAfter = TVI_LAST;
2270 tvis.u.item.mask = TVIF_TEXT | TVIF_PARAM;
2271 tvis.u.item.pszText = feature->Title;
2272 tvis.u.item.lParam = (LPARAM) feature;
2274 hitem = (HTREEITEM) SendMessageW( hwnd, TVM_INSERTITEMW, 0, (LPARAM) &tvis );
2281 msi_seltree_sync_item_state( hwnd, feature, hitem );
2282 msi_seltree_add_child_features( package, hwnd,
2283 feature->Feature, hitem );
2285 /* the node is expanded if Display is odd */
2286 if ( feature->Display % 2 != 0 )
2287 SendMessageW( hwnd, TVM_EXPAND, TVE_EXPAND, (LPARAM) hitem );
2290 /* select the first item */
2291 SendMessageW( hwnd, TVM_SELECTITEM, TVGN_CARET | TVGN_DROPHILITE, (LPARAM) hfirst );
2292 info->selected = hfirst;
2295 static void msi_seltree_create_imagelist( HWND hwnd )
2297 const int bm_width = 32, bm_height = 16, bm_count = 3;
2298 const int bm_resource = 0x1001;
2303 himl = ImageList_Create( bm_width, bm_height, FALSE, 4, 0 );
2306 ERR("failed to create image list\n");
2310 for (i=0; i<bm_count; i++)
2312 hbmp = LoadBitmapW( msi_hInstance, MAKEINTRESOURCEW(i+bm_resource) );
2315 ERR("failed to load bitmap %d\n", i);
2320 * Add a dummy bitmap at offset zero because the treeview
2321 * can't use it as a state mask (zero means no user state).
2324 ImageList_Add( himl, hbmp, NULL );
2326 ImageList_Add( himl, hbmp, NULL );
2329 SendMessageW( hwnd, TVM_SETIMAGELIST, TVSIL_STATE, (LPARAM)himl );
2332 static UINT msi_dialog_seltree_handler( msi_dialog *dialog,
2333 msi_control *control, WPARAM param )
2335 struct msi_selection_tree_info *info = GetPropW( control->hwnd, szButtonData );
2336 LPNMTREEVIEWW tv = (LPNMTREEVIEWW)param;
2337 MSIRECORD *row, *rec;
2339 MSIFEATURE *feature;
2340 LPCWSTR dir, title = NULL;
2341 UINT r = ERROR_SUCCESS;
2343 static const WCHAR select[] = {
2344 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2345 '`','F','e','a','t','u','r','e','`',' ','W','H','E','R','E',' ',
2346 '`','T','i','t','l','e','`',' ','=',' ','\'','%','s','\'',0
2349 if (tv->hdr.code != TVN_SELCHANGINGW)
2350 return ERROR_SUCCESS;
2352 info->selected = tv->itemNew.hItem;
2354 if (!(tv->itemNew.mask & TVIF_TEXT))
2356 feature = msi_seltree_feature_from_item( control->hwnd, tv->itemNew.hItem );
2358 title = feature->Title;
2361 title = tv->itemNew.pszText;
2363 row = MSI_QueryGetRecord( dialog->package->db, select, title );
2365 return ERROR_FUNCTION_FAILED;
2367 rec = MSI_CreateRecord( 1 );
2369 MSI_RecordSetStringW( rec, 1, MSI_RecordGetString( row, 4 ) );
2370 ControlEvent_FireSubscribedEvent( dialog->package, szSelectionDescription, rec );
2372 dir = MSI_RecordGetString( row, 7 );
2373 folder = get_loaded_folder( dialog->package, dir );
2376 r = ERROR_FUNCTION_FAILED;
2380 MSI_RecordSetStringW( rec, 1, folder->ResolvedTarget );
2381 ControlEvent_FireSubscribedEvent( dialog->package, szSelectionPath, rec );
2384 msiobj_release(&row->hdr);
2385 msiobj_release(&rec->hdr);
2390 static UINT msi_dialog_selection_tree( msi_dialog *dialog, MSIRECORD *rec )
2392 msi_control *control;
2394 MSIPACKAGE *package = dialog->package;
2396 struct msi_selection_tree_info *info;
2398 info = msi_alloc( sizeof *info );
2400 return ERROR_FUNCTION_FAILED;
2402 /* create the treeview control */
2403 style = TVS_HASLINES | TVS_HASBUTTONS | TVS_LINESATROOT;
2404 style |= WS_GROUP | WS_VSCROLL;
2405 control = msi_dialog_add_control( dialog, rec, WC_TREEVIEWW, style );
2409 return ERROR_FUNCTION_FAILED;
2412 control->handler = msi_dialog_seltree_handler;
2413 control->attributes = MSI_RecordGetInteger( rec, 8 );
2414 prop = MSI_RecordGetString( rec, 9 );
2415 control->property = msi_dialog_dup_property( dialog, prop, FALSE );
2418 info->dialog = dialog;
2419 info->hwnd = control->hwnd;
2420 info->oldproc = (WNDPROC) SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
2421 (LONG_PTR)MSISelectionTree_WndProc );
2422 SetPropW( control->hwnd, szButtonData, info );
2424 ControlEvent_SubscribeToEvent( dialog->package, dialog,
2425 szSelectionPath, control->name, szProperty );
2428 msi_seltree_create_imagelist( control->hwnd );
2429 msi_seltree_add_child_features( package, control->hwnd, NULL, NULL );
2431 return ERROR_SUCCESS;
2434 /******************** Group Box ***************************************/
2436 static UINT msi_dialog_group_box( msi_dialog *dialog, MSIRECORD *rec )
2438 msi_control *control;
2441 style = BS_GROUPBOX | WS_CHILD | WS_GROUP;
2442 control = msi_dialog_add_control( dialog, rec, WC_BUTTONW, style );
2444 return ERROR_FUNCTION_FAILED;
2446 return ERROR_SUCCESS;
2449 /******************** List Box ***************************************/
2451 struct msi_listbox_info
2461 static LRESULT WINAPI MSIListBox_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
2463 struct msi_listbox_info *info;
2467 TRACE("%p %04x %08lx %08lx\n", hWnd, msg, wParam, lParam);
2469 info = GetPropW( hWnd, szButtonData );
2473 r = CallWindowProcW( info->oldproc, hWnd, msg, wParam, lParam );
2478 for (j = 0; j < info->num_items; j++)
2479 msi_free( info->items[j] );
2480 msi_free( info->items );
2482 RemovePropW( hWnd, szButtonData );
2489 static UINT msi_listbox_add_item( MSIRECORD *rec, LPVOID param )
2491 struct msi_listbox_info *info = param;
2492 LPCWSTR value, text;
2495 value = MSI_RecordGetString( rec, 3 );
2496 text = MSI_RecordGetString( rec, 4 );
2498 info->items[info->addpos_items] = strdupW( value );
2500 pos = SendMessageW( info->hwnd, LB_ADDSTRING, 0, (LPARAM)text );
2501 SendMessageW( info->hwnd, LB_SETITEMDATA, pos, (LPARAM)info->items[info->addpos_items] );
2502 info->addpos_items++;
2503 return ERROR_SUCCESS;
2506 static UINT msi_listbox_add_items( struct msi_listbox_info *info, LPCWSTR property )
2509 MSIQUERY *view = NULL;
2512 static const WCHAR query[] = {
2513 'S','E','L','E','C','T',' ','*',' ',
2514 'F','R','O','M',' ','`','L','i','s','t','B','o','x','`',' ',
2515 'W','H','E','R','E',' ',
2516 '`','P','r','o','p','e','r','t','y','`',' ','=',' ','\'','%','s','\'',' ',
2517 'O','R','D','E','R',' ','B','Y',' ','`','O','r','d','e','r','`',0
2520 r = MSI_OpenQuery( info->dialog->package->db, &view, query, property );
2521 if ( r != ERROR_SUCCESS )
2524 /* just get the number of records */
2526 r = MSI_IterateRecords( view, &count, NULL, NULL );
2528 info->num_items = count;
2529 info->items = msi_alloc( sizeof(*info->items) * count );
2531 r = MSI_IterateRecords( view, NULL, msi_listbox_add_item, info );
2532 msiobj_release( &view->hdr );
2537 static UINT msi_dialog_listbox_handler( msi_dialog *dialog,
2538 msi_control *control, WPARAM param )
2540 struct msi_listbox_info *info;
2544 if( HIWORD(param) != LBN_SELCHANGE )
2545 return ERROR_SUCCESS;
2547 info = GetPropW( control->hwnd, szButtonData );
2548 index = SendMessageW( control->hwnd, LB_GETCURSEL, 0, 0 );
2549 value = (LPCWSTR) SendMessageW( control->hwnd, LB_GETITEMDATA, index, 0 );
2551 msi_dialog_set_property( info->dialog->package, control->property, value );
2552 msi_dialog_evaluate_control_conditions( info->dialog );
2554 return ERROR_SUCCESS;
2557 static UINT msi_dialog_list_box( msi_dialog *dialog, MSIRECORD *rec )
2559 struct msi_listbox_info *info;
2560 msi_control *control;
2561 DWORD attributes, style;
2564 info = msi_alloc( sizeof *info );
2566 return ERROR_FUNCTION_FAILED;
2568 style = WS_TABSTOP | WS_GROUP | WS_CHILD | LBS_NOTIFY | WS_VSCROLL | WS_BORDER;
2569 attributes = MSI_RecordGetInteger( rec, 8 );
2570 if (~attributes & msidbControlAttributesSorted)
2573 control = msi_dialog_add_control( dialog, rec, WC_LISTBOXW, style );
2577 return ERROR_FUNCTION_FAILED;
2580 control->handler = msi_dialog_listbox_handler;
2582 prop = MSI_RecordGetString( rec, 9 );
2583 control->property = msi_dialog_dup_property( dialog, prop, FALSE );
2586 info->dialog = dialog;
2587 info->hwnd = control->hwnd;
2589 info->addpos_items = 0;
2590 info->oldproc = (WNDPROC)SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
2591 (LONG_PTR)MSIListBox_WndProc );
2592 SetPropW( control->hwnd, szButtonData, info );
2594 if ( control->property )
2595 msi_listbox_add_items( info, control->property );
2597 return ERROR_SUCCESS;
2600 /******************** Directory Combo ***************************************/
2602 static void msi_dialog_update_directory_combo( msi_dialog *dialog, msi_control *control )
2607 if (!control && !(control = msi_dialog_find_control_by_type( dialog, szDirectoryCombo )))
2610 indirect = control->attributes & msidbControlAttributesIndirect;
2611 prop = msi_dialog_dup_property( dialog, control->property, indirect );
2612 path = msi_dialog_dup_property( dialog, prop, TRUE );
2614 PathStripPathW( path );
2615 PathRemoveBackslashW( path );
2617 SendMessageW( control->hwnd, CB_INSERTSTRING, 0, (LPARAM)path );
2618 SendMessageW( control->hwnd, CB_SETCURSEL, 0, 0 );
2624 static UINT msi_dialog_directory_combo( msi_dialog *dialog, MSIRECORD *rec )
2626 msi_control *control;
2630 /* FIXME: use CBS_OWNERDRAWFIXED and add owner draw code */
2631 style = CBS_DROPDOWNLIST | CBS_HASSTRINGS | WS_CHILD |
2632 WS_GROUP | WS_TABSTOP | WS_VSCROLL;
2633 control = msi_dialog_add_control( dialog, rec, WC_COMBOBOXW, style );
2635 return ERROR_FUNCTION_FAILED;
2637 control->attributes = MSI_RecordGetInteger( rec, 8 );
2638 prop = MSI_RecordGetString( rec, 9 );
2639 control->property = msi_dialog_dup_property( dialog, prop, FALSE );
2641 msi_dialog_update_directory_combo( dialog, control );
2643 return ERROR_SUCCESS;
2646 /******************** Directory List ***************************************/
2648 static void msi_dialog_update_directory_list( msi_dialog *dialog, msi_control *control )
2650 WCHAR dir_spec[MAX_PATH];
2651 WIN32_FIND_DATAW wfd;
2657 static const WCHAR asterisk[] = {'*',0};
2659 if (!control && !(control = msi_dialog_find_control_by_type( dialog, szDirectoryList )))
2662 /* clear the list-view */
2663 SendMessageW( control->hwnd, LVM_DELETEALLITEMS, 0, 0 );
2665 indirect = control->attributes & msidbControlAttributesIndirect;
2666 prop = msi_dialog_dup_property( dialog, control->property, indirect );
2667 path = msi_dialog_dup_property( dialog, prop, TRUE );
2669 lstrcpyW( dir_spec, path );
2670 lstrcatW( dir_spec, asterisk );
2672 file = FindFirstFileW( dir_spec, &wfd );
2673 if ( file == INVALID_HANDLE_VALUE )
2678 if ( wfd.dwFileAttributes != FILE_ATTRIBUTE_DIRECTORY )
2681 if ( !lstrcmpW( wfd.cFileName, szDot ) || !lstrcmpW( wfd.cFileName, szDotDot ) )
2684 item.mask = LVIF_TEXT;
2685 item.cchTextMax = MAX_PATH;
2688 item.pszText = wfd.cFileName;
2690 SendMessageW( control->hwnd, LVM_INSERTITEMW, 0, (LPARAM)&item );
2691 } while ( FindNextFileW( file, &wfd ) );
2698 UINT msi_dialog_directorylist_up( msi_dialog *dialog )
2700 msi_control *control;
2701 LPWSTR prop, path, ptr;
2704 control = msi_dialog_find_control_by_type( dialog, szDirectoryList );
2705 indirect = control->attributes & msidbControlAttributesIndirect;
2706 prop = msi_dialog_dup_property( dialog, control->property, indirect );
2707 path = msi_dialog_dup_property( dialog, prop, TRUE );
2709 /* strip off the last directory */
2710 ptr = PathFindFileNameW( path );
2711 if (ptr != path) *(ptr - 1) = '\0';
2712 PathAddBackslashW( path );
2714 msi_dialog_set_property( dialog->package, prop, path );
2716 msi_dialog_update_directory_list( dialog, NULL );
2717 msi_dialog_update_directory_combo( dialog, NULL );
2718 msi_dialog_update_pathedit( dialog, NULL );
2723 return ERROR_SUCCESS;
2726 static UINT msi_dialog_dirlist_handler( msi_dialog *dialog,
2727 msi_control *control, WPARAM param )
2729 LPNMHDR nmhdr = (LPNMHDR)param;
2730 WCHAR new_path[MAX_PATH];
2731 WCHAR text[MAX_PATH];
2737 if (nmhdr->code != LVN_ITEMACTIVATE)
2738 return ERROR_SUCCESS;
2740 index = SendMessageW( control->hwnd, LVM_GETNEXTITEM, -1, LVNI_SELECTED );
2743 ERR("No list-view item selected!\n");
2744 return ERROR_FUNCTION_FAILED;
2748 item.pszText = text;
2749 item.cchTextMax = MAX_PATH;
2750 SendMessageW( control->hwnd, LVM_GETITEMTEXTW, index, (LPARAM)&item );
2752 indirect = control->attributes & msidbControlAttributesIndirect;
2753 prop = msi_dialog_dup_property( dialog, control->property, indirect );
2754 path = msi_dialog_dup_property( dialog, prop, TRUE );
2756 lstrcpyW( new_path, path );
2757 lstrcatW( new_path, text );
2758 lstrcatW( new_path, szBackSlash );
2760 msi_dialog_set_property( dialog->package, prop, new_path );
2762 msi_dialog_update_directory_list( dialog, NULL );
2763 msi_dialog_update_directory_combo( dialog, NULL );
2764 msi_dialog_update_pathedit( dialog, NULL );
2768 return ERROR_SUCCESS;
2771 static UINT msi_dialog_directory_list( msi_dialog *dialog, MSIRECORD *rec )
2773 msi_control *control;
2777 style = LVS_LIST | WS_VSCROLL | LVS_SHAREIMAGELISTS |
2778 LVS_AUTOARRANGE | LVS_SINGLESEL | WS_BORDER |
2779 LVS_SORTASCENDING | WS_CHILD | WS_GROUP | WS_TABSTOP;
2780 control = msi_dialog_add_control( dialog, rec, WC_LISTVIEWW, style );
2782 return ERROR_FUNCTION_FAILED;
2784 control->attributes = MSI_RecordGetInteger( rec, 8 );
2785 control->handler = msi_dialog_dirlist_handler;
2786 prop = MSI_RecordGetString( rec, 9 );
2787 control->property = msi_dialog_dup_property( dialog, prop, FALSE );
2789 /* double click to activate an item in the list */
2790 SendMessageW( control->hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE,
2791 0, LVS_EX_TWOCLICKACTIVATE );
2793 msi_dialog_update_directory_list( dialog, control );
2795 return ERROR_SUCCESS;
2798 /******************** VolumeCost List ***************************************/
2800 static BOOL str_is_number( LPCWSTR str )
2804 for (i = 0; i < lstrlenW( str ); i++)
2805 if (!isdigitW(str[i]))
2811 static const WCHAR column_keys[][80] =
2813 {'V','o','l','u','m','e','C','o','s','t','V','o','l','u','m','e',0},
2814 {'V','o','l','u','m','e','C','o','s','t','S','i','z','e',0},
2815 {'V','o','l','u','m','e','C','o','s','t','A','v','a','i','l','a','b','l','e',0},
2816 {'V','o','l','u','m','e','C','o','s','t','R','e','q','u','i','r','e','d',0},
2817 {'V','o','l','u','m','e','C','o','s','t','D','i','f','f','e','r','e','n','c','e',0}
2820 static void msi_dialog_vcl_add_columns( msi_dialog *dialog, msi_control *control, MSIRECORD *rec )
2822 LPCWSTR text = MSI_RecordGetString( rec, 10 );
2823 LPCWSTR begin = text, end;
2828 static const WCHAR negative[] = {'-',0};
2832 while ((begin = strchrW( begin, '{' )) && count < 5)
2834 if (!(end = strchrW( begin, '}' )))
2837 num = msi_alloc( (end-begin+1)*sizeof(WCHAR) );
2841 lstrcpynW( num, begin + 1, end - begin );
2842 begin += end - begin + 1;
2844 /* empty braces or '0' hides the column */
2845 if ( !num[0] || !lstrcmpW( num, szZero ) )
2852 /* the width must be a positive number
2853 * if a width is invalid, all remaining columns are hidden
2855 if ( !strncmpW( num, negative, 1 ) || !str_is_number( num ) ) {
2860 ZeroMemory( &lvc, sizeof(lvc) );
2861 lvc.mask = LVCF_TEXT | LVCF_WIDTH | LVCF_SUBITEM;
2862 lvc.cx = atolW( num );
2863 lvc.pszText = msi_dialog_get_uitext( dialog, column_keys[count] );
2865 SendMessageW( control->hwnd, LVM_INSERTCOLUMNW, count++, (LPARAM)&lvc );
2866 msi_free( lvc.pszText );
2871 static LONGLONG msi_vcl_get_cost( msi_dialog *dialog )
2873 MSIFEATURE *feature;
2875 LONGLONG total_cost = 0;
2877 LIST_FOR_EACH_ENTRY( feature, &dialog->package->features, MSIFEATURE, entry )
2879 if (ERROR_SUCCESS == (MSI_GetFeatureCost(dialog->package, feature,
2880 MSICOSTTREE_SELFONLY, INSTALLSTATE_LOCAL, &each_cost)))
2882 /* each_cost is in 512-byte units */
2883 total_cost += each_cost * 512;
2885 if (ERROR_SUCCESS == (MSI_GetFeatureCost(dialog->package, feature,
2886 MSICOSTTREE_SELFONLY, INSTALLSTATE_ABSENT, &each_cost)))
2888 /* each_cost is in 512-byte units */
2889 total_cost -= each_cost * 512;
2895 static void msi_dialog_vcl_add_drives( msi_dialog *dialog, msi_control *control )
2897 ULARGE_INTEGER total, free;
2898 LONGLONG difference, cost;
2899 WCHAR size_text[MAX_PATH];
2900 WCHAR cost_text[MAX_PATH];
2906 cost = msi_vcl_get_cost(dialog);
2907 StrFormatByteSizeW(cost, cost_text, MAX_PATH);
2909 size = GetLogicalDriveStringsW( 0, NULL );
2910 if ( !size ) return;
2912 drives = msi_alloc( (size + 1) * sizeof(WCHAR) );
2913 if ( !drives ) return;
2915 GetLogicalDriveStringsW( size, drives );
2920 lvitem.mask = LVIF_TEXT;
2922 lvitem.iSubItem = 0;
2923 lvitem.pszText = ptr;
2924 lvitem.cchTextMax = lstrlenW(ptr) + 1;
2925 SendMessageW( control->hwnd, LVM_INSERTITEMW, 0, (LPARAM)&lvitem );
2927 GetDiskFreeSpaceExW(ptr, &free, &total, NULL);
2928 difference = free.QuadPart - cost;
2930 StrFormatByteSizeW(total.QuadPart, size_text, MAX_PATH);
2931 lvitem.iSubItem = 1;
2932 lvitem.pszText = size_text;
2933 lvitem.cchTextMax = lstrlenW(size_text) + 1;
2934 SendMessageW( control->hwnd, LVM_SETITEMW, 0, (LPARAM)&lvitem );
2936 StrFormatByteSizeW(free.QuadPart, size_text, MAX_PATH);
2937 lvitem.iSubItem = 2;
2938 lvitem.pszText = size_text;
2939 lvitem.cchTextMax = lstrlenW(size_text) + 1;
2940 SendMessageW( control->hwnd, LVM_SETITEMW, 0, (LPARAM)&lvitem );
2942 lvitem.iSubItem = 3;
2943 lvitem.pszText = cost_text;
2944 lvitem.cchTextMax = lstrlenW(cost_text) + 1;
2945 SendMessageW( control->hwnd, LVM_SETITEMW, 0, (LPARAM)&lvitem );
2947 StrFormatByteSizeW(difference, size_text, MAX_PATH);
2948 lvitem.iSubItem = 4;
2949 lvitem.pszText = size_text;
2950 lvitem.cchTextMax = lstrlenW(size_text) + 1;
2951 SendMessageW( control->hwnd, LVM_SETITEMW, 0, (LPARAM)&lvitem );
2953 ptr += lstrlenW(ptr) + 1;
2960 static UINT msi_dialog_volumecost_list( msi_dialog *dialog, MSIRECORD *rec )
2962 msi_control *control;
2965 style = LVS_REPORT | WS_VSCROLL | WS_HSCROLL | LVS_SHAREIMAGELISTS |
2966 LVS_AUTOARRANGE | LVS_SINGLESEL | WS_BORDER |
2967 WS_CHILD | WS_TABSTOP | WS_GROUP;
2968 control = msi_dialog_add_control( dialog, rec, WC_LISTVIEWW, style );
2970 return ERROR_FUNCTION_FAILED;
2972 msi_dialog_vcl_add_columns( dialog, control, rec );
2973 msi_dialog_vcl_add_drives( dialog, control );
2975 return ERROR_SUCCESS;
2978 /******************** VolumeSelect Combo ***************************************/
2980 static UINT msi_dialog_volsel_handler( msi_dialog *dialog,
2981 msi_control *control, WPARAM param )
2983 WCHAR text[MAX_PATH];
2988 if (HIWORD(param) != CBN_SELCHANGE)
2989 return ERROR_SUCCESS;
2991 index = SendMessageW( control->hwnd, CB_GETCURSEL, 0, 0 );
2992 if ( index == CB_ERR )
2994 ERR("No ComboBox item selected!\n");
2995 return ERROR_FUNCTION_FAILED;
2998 SendMessageW( control->hwnd, CB_GETLBTEXT, index, (LPARAM)text );
3000 indirect = control->attributes & msidbControlAttributesIndirect;
3001 prop = msi_dialog_dup_property( dialog, control->property, indirect );
3003 msi_dialog_set_property( dialog->package, prop, text );
3006 return ERROR_SUCCESS;
3009 static void msi_dialog_vsc_add_drives( msi_dialog *dialog, msi_control *control )
3014 size = GetLogicalDriveStringsW( 0, NULL );
3015 if ( !size ) return;
3017 drives = msi_alloc( (size + 1) * sizeof(WCHAR) );
3018 if ( !drives ) return;
3020 GetLogicalDriveStringsW( size, drives );
3025 SendMessageW( control->hwnd, CB_ADDSTRING, 0, (LPARAM)ptr );
3026 ptr += lstrlenW(ptr) + 1;
3032 static UINT msi_dialog_volumeselect_combo( msi_dialog *dialog, MSIRECORD *rec )
3034 msi_control *control;
3038 /* FIXME: CBS_OWNERDRAWFIXED */
3039 style = WS_CHILD | WS_VISIBLE | WS_GROUP | WS_TABSTOP |
3040 CBS_DROPDOWNLIST | CBS_SORT | CBS_HASSTRINGS |
3041 WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_RIGHTSCROLLBAR;
3042 control = msi_dialog_add_control( dialog, rec, WC_COMBOBOXW, style );
3044 return ERROR_FUNCTION_FAILED;
3046 control->attributes = MSI_RecordGetInteger( rec, 8 );
3047 control->handler = msi_dialog_volsel_handler;
3048 prop = MSI_RecordGetString( rec, 9 );
3049 control->property = msi_dialog_dup_property( dialog, prop, FALSE );
3051 msi_dialog_vsc_add_drives( dialog, control );
3053 return ERROR_SUCCESS;
3056 static const struct control_handler msi_dialog_handler[] =
3058 { szText, msi_dialog_text_control },
3059 { szPushButton, msi_dialog_button_control },
3060 { szLine, msi_dialog_line_control },
3061 { szBitmap, msi_dialog_bitmap_control },
3062 { szCheckBox, msi_dialog_checkbox_control },
3063 { szScrollableText, msi_dialog_scrolltext_control },
3064 { szComboBox, msi_dialog_combo_control },
3065 { szEdit, msi_dialog_edit_control },
3066 { szMaskedEdit, msi_dialog_maskedit_control },
3067 { szPathEdit, msi_dialog_pathedit_control },
3068 { szProgressBar, msi_dialog_progress_bar },
3069 { szRadioButtonGroup, msi_dialog_radiogroup_control },
3070 { szIcon, msi_dialog_icon_control },
3071 { szSelectionTree, msi_dialog_selection_tree },
3072 { szGroupBox, msi_dialog_group_box },
3073 { szListBox, msi_dialog_list_box },
3074 { szDirectoryCombo, msi_dialog_directory_combo },
3075 { szDirectoryList, msi_dialog_directory_list },
3076 { szVolumeCostList, msi_dialog_volumecost_list },
3077 { szVolumeSelectCombo, msi_dialog_volumeselect_combo },
3080 #define NUM_CONTROL_TYPES (sizeof msi_dialog_handler/sizeof msi_dialog_handler[0])
3082 static UINT msi_dialog_create_controls( MSIRECORD *rec, LPVOID param )
3084 msi_dialog *dialog = param;
3085 LPCWSTR control_type;
3088 /* find and call the function that can create this type of control */
3089 control_type = MSI_RecordGetString( rec, 3 );
3090 for( i=0; i<NUM_CONTROL_TYPES; i++ )
3091 if (!strcmpiW( msi_dialog_handler[i].control_type, control_type ))
3093 if( i != NUM_CONTROL_TYPES )
3094 msi_dialog_handler[i].func( dialog, rec );
3096 ERR("no handler for element type %s\n", debugstr_w(control_type));
3098 return ERROR_SUCCESS;
3101 static UINT msi_dialog_fill_controls( msi_dialog *dialog )
3103 static const WCHAR query[] = {
3104 'S','E','L','E','C','T',' ','*',' ',
3105 'F','R','O','M',' ','C','o','n','t','r','o','l',' ',
3106 'W','H','E','R','E',' ',
3107 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',0};
3109 MSIQUERY *view = NULL;
3110 MSIPACKAGE *package = dialog->package;
3112 TRACE("%p %s\n", dialog, debugstr_w(dialog->name) );
3114 /* query the Control table for all the elements of the control */
3115 r = MSI_OpenQuery( package->db, &view, query, dialog->name );
3116 if( r != ERROR_SUCCESS )
3118 ERR("query failed for dialog %s\n", debugstr_w(dialog->name));
3119 return ERROR_INVALID_PARAMETER;
3122 r = MSI_IterateRecords( view, 0, msi_dialog_create_controls, dialog );
3123 msiobj_release( &view->hdr );
3128 static UINT msi_dialog_set_control_condition( MSIRECORD *rec, LPVOID param )
3130 static const WCHAR szHide[] = { 'H','i','d','e',0 };
3131 static const WCHAR szShow[] = { 'S','h','o','w',0 };
3132 static const WCHAR szDisable[] = { 'D','i','s','a','b','l','e',0 };
3133 static const WCHAR szEnable[] = { 'E','n','a','b','l','e',0 };
3134 static const WCHAR szDefault[] = { 'D','e','f','a','u','l','t',0 };
3135 msi_dialog *dialog = param;
3136 msi_control *control;
3137 LPCWSTR name, action, condition;
3140 name = MSI_RecordGetString( rec, 2 );
3141 action = MSI_RecordGetString( rec, 3 );
3142 condition = MSI_RecordGetString( rec, 4 );
3143 r = MSI_EvaluateConditionW( dialog->package, condition );
3144 control = msi_dialog_find_control( dialog, name );
3145 if( r == MSICONDITION_TRUE && control )
3147 TRACE("%s control %s\n", debugstr_w(action), debugstr_w(name));
3149 /* FIXME: case sensitive? */
3150 if(!lstrcmpW(action, szHide))
3151 ShowWindow(control->hwnd, SW_HIDE);
3152 else if(!strcmpW(action, szShow))
3153 ShowWindow(control->hwnd, SW_SHOW);
3154 else if(!strcmpW(action, szDisable))
3155 EnableWindow(control->hwnd, FALSE);
3156 else if(!strcmpW(action, szEnable))
3157 EnableWindow(control->hwnd, TRUE);
3158 else if(!strcmpW(action, szDefault))
3159 SetFocus(control->hwnd);
3161 FIXME("Unhandled action %s\n", debugstr_w(action));
3164 return ERROR_SUCCESS;
3167 static UINT msi_dialog_evaluate_control_conditions( msi_dialog *dialog )
3169 static const WCHAR query[] = {
3170 'S','E','L','E','C','T',' ','*',' ',
3171 'F','R','O','M',' ',
3172 'C','o','n','t','r','o','l','C','o','n','d','i','t','i','o','n',' ',
3173 'W','H','E','R','E',' ',
3174 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',0
3177 MSIQUERY *view = NULL;
3178 MSIPACKAGE *package = dialog->package;
3180 TRACE("%p %s\n", dialog, debugstr_w(dialog->name) );
3182 /* query the Control table for all the elements of the control */
3183 r = MSI_OpenQuery( package->db, &view, query, dialog->name );
3184 if( r != ERROR_SUCCESS )
3185 return ERROR_SUCCESS;
3187 r = MSI_IterateRecords( view, 0, msi_dialog_set_control_condition, dialog );
3188 msiobj_release( &view->hdr );
3193 UINT msi_dialog_reset( msi_dialog *dialog )
3195 /* FIXME: should restore the original values of any properties we changed */
3196 return msi_dialog_evaluate_control_conditions( dialog );
3199 /* figure out the height of 10 point MS Sans Serif */
3200 static INT msi_dialog_get_sans_serif_height( HWND hwnd )
3202 static const WCHAR szSansSerif[] = {
3203 'M','S',' ','S','a','n','s',' ','S','e','r','i','f',0 };
3208 HFONT hFont, hOldFont;
3211 hdc = GetDC( hwnd );
3214 memset( &lf, 0, sizeof lf );
3215 lf.lfHeight = MulDiv(12, GetDeviceCaps(hdc, LOGPIXELSY), 72);
3216 strcpyW( lf.lfFaceName, szSansSerif );
3217 hFont = CreateFontIndirectW(&lf);
3220 hOldFont = SelectObject( hdc, hFont );
3221 r = GetTextMetricsW( hdc, &tm );
3223 height = tm.tmHeight;
3224 SelectObject( hdc, hOldFont );
3225 DeleteObject( hFont );
3227 ReleaseDC( hwnd, hdc );
3232 /* fetch the associated record from the Dialog table */
3233 static MSIRECORD *msi_get_dialog_record( msi_dialog *dialog )
3235 static const WCHAR query[] = {
3236 'S','E','L','E','C','T',' ','*',' ',
3237 'F','R','O','M',' ','D','i','a','l','o','g',' ',
3238 'W','H','E','R','E',' ',
3239 '`','D','i','a','l','o','g','`',' ','=',' ','\'','%','s','\'',0};
3240 MSIPACKAGE *package = dialog->package;
3241 MSIRECORD *rec = NULL;
3243 TRACE("%p %s\n", dialog, debugstr_w(dialog->name) );
3245 rec = MSI_QueryGetRecord( package->db, query, dialog->name );
3247 WARN("query failed for dialog %s\n", debugstr_w(dialog->name));
3252 static void msi_dialog_adjust_dialog_pos( msi_dialog *dialog, MSIRECORD *rec, LPRECT pos )
3254 static const WCHAR szScreenX[] = {'S','c','r','e','e','n','X',0};
3255 static const WCHAR szScreenY[] = {'S','c','r','e','e','n','Y',0};
3262 center.x = MSI_RecordGetInteger( rec, 2 );
3263 center.y = MSI_RecordGetInteger( rec, 3 );
3265 sz.cx = MSI_RecordGetInteger( rec, 4 );
3266 sz.cy = MSI_RecordGetInteger( rec, 5 );
3268 sz.cx = msi_dialog_scale_unit( dialog, sz.cx );
3269 sz.cy = msi_dialog_scale_unit( dialog, sz.cy );
3271 xres = msi_get_property_int( dialog->package->db, szScreenX, 0 );
3272 yres = msi_get_property_int( dialog->package->db, szScreenY, 0 );
3274 center.x = MulDiv( center.x, xres, 100 );
3275 center.y = MulDiv( center.y, yres, 100 );
3277 /* turn the client pos into the window rectangle */
3278 if (dialog->package->center_x && dialog->package->center_y)
3280 pos->left = dialog->package->center_x - sz.cx / 2.0;
3281 pos->right = pos->left + sz.cx;
3282 pos->top = dialog->package->center_y - sz.cy / 2.0;
3283 pos->bottom = pos->top + sz.cy;
3287 pos->left = center.x - sz.cx/2;
3288 pos->right = pos->left + sz.cx;
3289 pos->top = center.y - sz.cy/2;
3290 pos->bottom = pos->top + sz.cy;
3292 /* save the center */
3293 dialog->package->center_x = center.x;
3294 dialog->package->center_y = center.y;
3297 dialog->size.cx = sz.cx;
3298 dialog->size.cy = sz.cy;
3300 TRACE("%u %u %u %u\n", pos->left, pos->top, pos->right, pos->bottom);
3302 style = GetWindowLongPtrW( dialog->hwnd, GWL_STYLE );
3303 AdjustWindowRect( pos, style, FALSE );
3306 static void msi_dialog_set_tab_order( msi_dialog *dialog, LPCWSTR first )
3308 struct list tab_chain;
3309 msi_control *control;
3310 HWND prev = HWND_TOP;
3312 list_init( &tab_chain );
3313 if (!(control = msi_dialog_find_control( dialog, first ))) return;
3315 dialog->hWndFocus = control->hwnd;
3318 list_remove( &control->entry );
3319 list_add_tail( &tab_chain, &control->entry );
3320 if (!control->tabnext) break;
3321 control = msi_dialog_find_control( dialog, control->tabnext );
3324 LIST_FOR_EACH_ENTRY( control, &tab_chain, msi_control, entry )
3326 SetWindowPos( control->hwnd, prev, 0, 0, 0, 0,
3327 SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOREDRAW |
3328 SWP_NOREPOSITION | SWP_NOSENDCHANGING | SWP_NOSIZE );
3329 prev = control->hwnd;
3332 /* put them back on the main list */
3333 list_move_head( &dialog->controls, &tab_chain );
3336 static LRESULT msi_dialog_oncreate( HWND hwnd, LPCREATESTRUCTW cs )
3338 static const WCHAR df[] = {
3339 'D','e','f','a','u','l','t','U','I','F','o','n','t',0 };
3340 static const WCHAR dfv[] = {
3341 'M','S',' ','S','h','e','l','l',' ','D','l','g',0 };
3342 msi_dialog *dialog = cs->lpCreateParams;
3343 MSIRECORD *rec = NULL;
3344 LPWSTR title = NULL;
3347 TRACE("%p %p\n", dialog, dialog->package);
3349 dialog->hwnd = hwnd;
3350 SetWindowLongPtrW( hwnd, GWLP_USERDATA, (LONG_PTR) dialog );
3352 rec = msi_get_dialog_record( dialog );
3355 TRACE("No record found for dialog %s\n", debugstr_w(dialog->name));
3359 dialog->scale = msi_dialog_get_sans_serif_height(dialog->hwnd);
3361 msi_dialog_adjust_dialog_pos( dialog, rec, &pos );
3363 dialog->attributes = MSI_RecordGetInteger( rec, 6 );
3365 dialog->default_font = msi_dup_property( dialog->package->db, df );
3366 if (!dialog->default_font)
3368 dialog->default_font = strdupW(dfv);
3369 if (!dialog->default_font) return -1;
3372 title = msi_get_deformatted_field( dialog->package, rec, 7 );
3373 SetWindowTextW( hwnd, title );
3376 SetWindowPos( hwnd, 0, pos.left, pos.top,
3377 pos.right - pos.left, pos.bottom - pos.top,
3378 SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOREDRAW );
3380 msi_dialog_build_font_list( dialog );
3381 msi_dialog_fill_controls( dialog );
3382 msi_dialog_evaluate_control_conditions( dialog );
3383 msi_dialog_set_tab_order( dialog, MSI_RecordGetString( rec, 8 ) );
3384 msiobj_release( &rec->hdr );
3389 static UINT msi_dialog_send_event( msi_dialog *dialog, LPCWSTR event, LPCWSTR arg )
3391 LPWSTR event_fmt = NULL, arg_fmt = NULL;
3393 TRACE("Sending control event %s %s\n", debugstr_w(event), debugstr_w(arg));
3395 deformat_string( dialog->package, event, &event_fmt );
3396 deformat_string( dialog->package, arg, &arg_fmt );
3398 dialog->event_handler( dialog->package, event_fmt, arg_fmt, dialog );
3400 msi_free( event_fmt );
3401 msi_free( arg_fmt );
3403 return ERROR_SUCCESS;
3406 static UINT msi_dialog_set_property_event( msi_dialog *dialog, LPCWSTR event, LPCWSTR arg )
3408 static const WCHAR szNullArg[] = { '{','}',0 };
3409 LPWSTR p, prop, arg_fmt = NULL;
3412 len = strlenW(event);
3413 prop = msi_alloc( len*sizeof(WCHAR));
3414 strcpyW( prop, &event[1] );
3415 p = strchrW( prop, ']' );
3416 if( p && (p[1] == 0 || p[1] == ' ') )
3419 if( strcmpW( szNullArg, arg ) )
3420 deformat_string( dialog->package, arg, &arg_fmt );
3421 msi_dialog_set_property( dialog->package, prop, arg_fmt );
3422 msi_dialog_update_controls( dialog, prop );
3423 msi_free( arg_fmt );
3426 ERR("Badly formatted property string - what happens?\n");
3428 return ERROR_SUCCESS;
3431 static UINT msi_dialog_control_event( MSIRECORD *rec, LPVOID param )
3433 msi_dialog *dialog = param;
3434 LPCWSTR condition, event, arg;
3437 condition = MSI_RecordGetString( rec, 5 );
3438 r = MSI_EvaluateConditionW( dialog->package, condition );
3439 if( r == MSICONDITION_TRUE || r == MSICONDITION_NONE )
3441 event = MSI_RecordGetString( rec, 3 );
3442 arg = MSI_RecordGetString( rec, 4 );
3443 if( event[0] == '[' )
3444 msi_dialog_set_property_event( dialog, event, arg );
3446 msi_dialog_send_event( dialog, event, arg );
3449 return ERROR_SUCCESS;
3458 static UINT add_rec_to_list( MSIRECORD *rec, LPVOID param )
3460 struct rec_list *add_rec;
3461 struct list *records = param;
3463 msiobj_addref( &rec->hdr );
3465 add_rec = msi_alloc( sizeof( *add_rec ) );
3468 msiobj_release( &rec->hdr );
3469 return ERROR_OUTOFMEMORY;
3473 list_add_tail( records, &add_rec->entry );
3474 return ERROR_SUCCESS;
3477 static inline void remove_rec_from_list( struct rec_list *rec_entry )
3479 msiobj_release( &rec_entry->rec->hdr );
3480 list_remove( &rec_entry->entry );
3481 msi_free( rec_entry );
3484 static UINT msi_dialog_button_handler( msi_dialog *dialog,
3485 msi_control *control, WPARAM param )
3487 static const WCHAR query[] = {
3488 'S','E','L','E','C','T',' ','*',' ',
3489 'F','R','O','M',' ','C','o','n','t','r','o','l','E','v','e','n','t',' ',
3490 'W','H','E','R','E',' ',
3491 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',' ',
3493 '`','C','o','n','t','r','o','l','_','`',' ','=',' ','\'','%','s','\'',' ',
3494 'O','R','D','E','R',' ','B','Y',' ','`','O','r','d','e','r','i','n','g','`',0
3496 MSIQUERY *view = NULL;
3497 struct rec_list *rec_entry, *next;
3501 if( HIWORD(param) != BN_CLICKED )
3502 return ERROR_SUCCESS;
3504 list_init( &events );
3506 r = MSI_OpenQuery( dialog->package->db, &view, query,
3507 dialog->name, control->name );
3508 if( r != ERROR_SUCCESS )
3510 ERR("query failed\n");
3514 r = MSI_IterateRecords( view, 0, add_rec_to_list, &events );
3515 msiobj_release( &view->hdr );
3516 if (r != ERROR_SUCCESS)
3519 /* handle all SetProperty events first */
3520 LIST_FOR_EACH_ENTRY_SAFE( rec_entry, next, &events, struct rec_list, entry )
3522 LPCWSTR event = MSI_RecordGetString( rec_entry->rec, 3 );
3524 if ( event[0] != '[' )
3527 r = msi_dialog_control_event( rec_entry->rec, dialog );
3528 remove_rec_from_list( rec_entry );
3530 if ( r != ERROR_SUCCESS )
3534 /* handle all other events */
3535 LIST_FOR_EACH_ENTRY_SAFE( rec_entry, next, &events, struct rec_list, entry )
3537 r = msi_dialog_control_event( rec_entry->rec, dialog );
3538 remove_rec_from_list( rec_entry );
3540 if ( r != ERROR_SUCCESS )
3545 LIST_FOR_EACH_ENTRY_SAFE( rec_entry, next, &events, struct rec_list, entry )
3547 remove_rec_from_list( rec_entry );
3553 static UINT msi_dialog_get_checkbox_state( msi_dialog *dialog,
3554 msi_control *control )
3556 WCHAR state[2] = { 0 };
3559 msi_get_property( dialog->package->db, control->property, state, &sz );
3560 return state[0] ? 1 : 0;
3563 static void msi_dialog_set_checkbox_state( msi_dialog *dialog,
3564 msi_control *control, UINT state )
3566 static const WCHAR szState[] = { '1', 0 };
3569 /* if uncheck then the property is set to NULL */
3572 msi_dialog_set_property( dialog->package, control->property, NULL );
3576 /* check for a custom state */
3577 if (control->value && control->value[0])
3578 val = control->value;
3582 msi_dialog_set_property( dialog->package, control->property, val );
3585 static void msi_dialog_checkbox_sync_state( msi_dialog *dialog,
3586 msi_control *control )
3590 state = msi_dialog_get_checkbox_state( dialog, control );
3591 SendMessageW( control->hwnd, BM_SETCHECK,
3592 state ? BST_CHECKED : BST_UNCHECKED, 0 );
3595 static UINT msi_dialog_checkbox_handler( msi_dialog *dialog,
3596 msi_control *control, WPARAM param )
3600 if( HIWORD(param) != BN_CLICKED )
3601 return ERROR_SUCCESS;
3603 TRACE("clicked checkbox %s, set %s\n", debugstr_w(control->name),
3604 debugstr_w(control->property));
3606 state = msi_dialog_get_checkbox_state( dialog, control );
3607 state = state ? 0 : 1;
3608 msi_dialog_set_checkbox_state( dialog, control, state );
3609 msi_dialog_checkbox_sync_state( dialog, control );
3611 return msi_dialog_button_handler( dialog, control, param );
3614 static UINT msi_dialog_edit_handler( msi_dialog *dialog,
3615 msi_control *control, WPARAM param )
3619 if( HIWORD(param) != EN_CHANGE )
3620 return ERROR_SUCCESS;
3622 TRACE("edit %s contents changed, set %s\n", debugstr_w(control->name),
3623 debugstr_w(control->property));
3625 buf = msi_get_window_text( control->hwnd );
3626 msi_dialog_set_property( dialog->package, control->property, buf );
3629 return ERROR_SUCCESS;
3632 static UINT msi_dialog_radiogroup_handler( msi_dialog *dialog,
3633 msi_control *control, WPARAM param )
3635 if( HIWORD(param) != BN_CLICKED )
3636 return ERROR_SUCCESS;
3638 TRACE("clicked radio button %s, set %s\n", debugstr_w(control->name),
3639 debugstr_w(control->property));
3641 msi_dialog_set_property( dialog->package, control->property, control->name );
3643 return msi_dialog_button_handler( dialog, control, param );
3646 static LRESULT msi_dialog_oncommand( msi_dialog *dialog, WPARAM param, HWND hwnd )
3648 msi_control *control = NULL;
3650 TRACE("%p %p %08lx\n", dialog, hwnd, param);
3655 control = msi_dialog_find_control( dialog, dialog->control_default );
3657 case 2: /* escape */
3658 control = msi_dialog_find_control( dialog, dialog->control_cancel );
3661 control = msi_dialog_find_control_by_hwnd( dialog, hwnd );
3666 if( control->handler )
3668 control->handler( dialog, control, param );
3669 msi_dialog_evaluate_control_conditions( dialog );
3676 static LRESULT msi_dialog_onnotify( msi_dialog *dialog, LPARAM param )
3678 LPNMHDR nmhdr = (LPNMHDR) param;
3679 msi_control *control = msi_dialog_find_control_by_hwnd( dialog, nmhdr->hwndFrom );
3681 TRACE("%p %p\n", dialog, nmhdr->hwndFrom);
3683 if ( control && control->handler )
3684 control->handler( dialog, control, param );
3689 static void msi_dialog_setfocus( msi_dialog *dialog )
3691 HWND hwnd = dialog->hWndFocus;
3693 hwnd = GetNextDlgTabItem( dialog->hwnd, hwnd, TRUE);
3694 hwnd = GetNextDlgTabItem( dialog->hwnd, hwnd, FALSE);
3696 dialog->hWndFocus = hwnd;
3699 static LRESULT WINAPI MSIDialog_WndProc( HWND hwnd, UINT msg,
3700 WPARAM wParam, LPARAM lParam )
3702 msi_dialog *dialog = (LPVOID) GetWindowLongPtrW( hwnd, GWLP_USERDATA );
3704 TRACE("0x%04x\n", msg);
3709 dialog->package->center_x = LOWORD(lParam) + dialog->size.cx / 2.0;
3710 dialog->package->center_y = HIWORD(lParam) + dialog->size.cy / 2.0;
3714 return msi_dialog_oncreate( hwnd, (LPCREATESTRUCTW)lParam );
3717 return msi_dialog_oncommand( dialog, wParam, (HWND)lParam );
3720 if( LOWORD(wParam) == WA_INACTIVE )
3721 dialog->hWndFocus = GetFocus();
3723 msi_dialog_setfocus( dialog );
3727 msi_dialog_setfocus( dialog );
3730 /* bounce back to our subclassed static control */
3731 case WM_CTLCOLORSTATIC:
3732 return SendMessageW( (HWND) lParam, WM_CTLCOLORSTATIC, wParam, lParam );
3735 dialog->hwnd = NULL;
3738 return msi_dialog_onnotify( dialog, lParam );
3740 return DefWindowProcW(hwnd, msg, wParam, lParam);
3743 static BOOL CALLBACK msi_radioground_child_enum( HWND hWnd, LPARAM lParam )
3745 EnableWindow( hWnd, lParam );
3749 static LRESULT WINAPI MSIRadioGroup_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
3751 WNDPROC oldproc = (WNDPROC) GetPropW(hWnd, szButtonData);
3754 TRACE("hWnd %p msg %04x wParam 0x%08lx lParam 0x%08lx\n", hWnd, msg, wParam, lParam);
3756 if (msg == WM_COMMAND) /* Forward notifications to dialog */
3757 SendMessageW(GetParent(hWnd), msg, wParam, lParam);
3759 r = CallWindowProcW(oldproc, hWnd, msg, wParam, lParam);
3761 /* make sure the radio buttons show as disabled if the parent is disabled */
3762 if (msg == WM_ENABLE)
3763 EnumChildWindows( hWnd, msi_radioground_child_enum, wParam );
3768 static LRESULT WINAPI MSIHiddenWindowProc( HWND hwnd, UINT msg,
3769 WPARAM wParam, LPARAM lParam )
3771 msi_dialog *dialog = (msi_dialog*) lParam;
3773 TRACE("%d %p\n", msg, dialog);
3777 case WM_MSI_DIALOG_CREATE:
3778 return msi_dialog_run_message_loop( dialog );
3779 case WM_MSI_DIALOG_DESTROY:
3780 msi_dialog_destroy( dialog );
3783 return DefWindowProcW( hwnd, msg, wParam, lParam );
3786 static BOOL msi_dialog_register_class( void )
3790 ZeroMemory( &cls, sizeof cls );
3791 cls.lpfnWndProc = MSIDialog_WndProc;
3792 cls.hInstance = NULL;
3793 cls.hIcon = LoadIconW(0, (LPWSTR)IDI_APPLICATION);
3794 cls.hCursor = LoadCursorW(0, (LPWSTR)IDC_ARROW);
3795 cls.hbrBackground = (HBRUSH)(COLOR_3DFACE + 1);
3796 cls.lpszMenuName = NULL;
3797 cls.lpszClassName = szMsiDialogClass;
3799 if( !RegisterClassW( &cls ) )
3802 cls.lpfnWndProc = MSIHiddenWindowProc;
3803 cls.lpszClassName = szMsiHiddenWindow;
3805 if( !RegisterClassW( &cls ) )
3808 uiThreadId = GetCurrentThreadId();
3810 hMsiHiddenWindow = CreateWindowW( szMsiHiddenWindow, NULL, WS_OVERLAPPED,
3811 0, 0, 100, 100, NULL, NULL, NULL, NULL );
3812 if( !hMsiHiddenWindow )
3818 /* functions that interface to other modules within MSI */
3820 msi_dialog *msi_dialog_create( MSIPACKAGE* package,
3821 LPCWSTR szDialogName, msi_dialog *parent,
3822 msi_dialog_event_handler event_handler )
3824 MSIRECORD *rec = NULL;
3827 TRACE("%p %s\n", package, debugstr_w(szDialogName));
3829 if (!hMsiHiddenWindow)
3830 msi_dialog_register_class();
3832 /* allocate the structure for the dialog to use */
3833 dialog = msi_alloc_zero( sizeof *dialog + sizeof(WCHAR)*strlenW(szDialogName) );
3836 strcpyW( dialog->name, szDialogName );
3837 dialog->parent = parent;
3838 msiobj_addref( &package->hdr );
3839 dialog->package = package;
3840 dialog->event_handler = event_handler;
3841 dialog->finished = 0;
3842 list_init( &dialog->controls );
3844 /* verify that the dialog exists */
3845 rec = msi_get_dialog_record( dialog );
3848 msiobj_release( &package->hdr );
3852 dialog->attributes = MSI_RecordGetInteger( rec, 6 );
3853 dialog->control_default = strdupW( MSI_RecordGetString( rec, 9 ) );
3854 dialog->control_cancel = strdupW( MSI_RecordGetString( rec, 10 ) );
3855 msiobj_release( &rec->hdr );
3860 static void msi_process_pending_messages( HWND hdlg )
3864 while( PeekMessageW( &msg, 0, 0, 0, PM_REMOVE ) )
3866 if( hdlg && IsDialogMessageW( hdlg, &msg ))
3868 TranslateMessage( &msg );
3869 DispatchMessageW( &msg );
3873 void msi_dialog_end_dialog( msi_dialog *dialog )
3875 TRACE("%p\n", dialog);
3876 dialog->finished = 1;
3877 PostMessageW(dialog->hwnd, WM_NULL, 0, 0);
3880 void msi_dialog_check_messages( HANDLE handle )
3884 /* in threads other than the UI thread, block */
3885 if( uiThreadId != GetCurrentThreadId() )
3888 WaitForSingleObject( handle, INFINITE );
3892 /* there's two choices for the UI thread */
3895 msi_process_pending_messages( NULL );
3901 * block here until somebody creates a new dialog or
3902 * the handle we're waiting on becomes ready
3904 r = MsgWaitForMultipleObjects( 1, &handle, 0, INFINITE, QS_ALLINPUT );
3905 if( r == WAIT_OBJECT_0 )
3910 UINT msi_dialog_run_message_loop( msi_dialog *dialog )
3915 if( uiThreadId != GetCurrentThreadId() )
3916 return SendMessageW( hMsiHiddenWindow, WM_MSI_DIALOG_CREATE, 0, (LPARAM) dialog );
3918 /* create the dialog window, don't show it yet */
3919 style = WS_OVERLAPPED;
3920 if( dialog->attributes & msidbDialogAttributesVisible )
3921 style |= WS_VISIBLE;
3923 hwnd = CreateWindowW( szMsiDialogClass, dialog->name, style,
3924 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
3925 NULL, NULL, NULL, dialog );
3928 ERR("Failed to create dialog %s\n", debugstr_w( dialog->name ));
3929 return ERROR_FUNCTION_FAILED;
3932 ShowWindow( hwnd, SW_SHOW );
3933 /* UpdateWindow( hwnd ); - and causes the transparent static controls not to paint */
3935 if( dialog->attributes & msidbDialogAttributesModal )
3937 while( !dialog->finished )
3939 MsgWaitForMultipleObjects( 0, NULL, 0, INFINITE, QS_ALLINPUT );
3940 msi_process_pending_messages( dialog->hwnd );
3944 return ERROR_IO_PENDING;
3946 return ERROR_SUCCESS;
3949 void msi_dialog_do_preview( msi_dialog *dialog )
3952 dialog->attributes |= msidbDialogAttributesVisible;
3953 dialog->attributes &= ~msidbDialogAttributesModal;
3954 msi_dialog_run_message_loop( dialog );
3957 void msi_dialog_destroy( msi_dialog *dialog )
3959 if( uiThreadId != GetCurrentThreadId() )
3961 SendMessageW( hMsiHiddenWindow, WM_MSI_DIALOG_DESTROY, 0, (LPARAM) dialog );
3966 ShowWindow( dialog->hwnd, SW_HIDE );
3969 DestroyWindow( dialog->hwnd );
3971 /* unsubscribe events */
3972 ControlEvent_CleanupDialogSubscriptions(dialog->package, dialog->name);
3974 /* destroy the list of controls */
3975 while( !list_empty( &dialog->controls ) )
3979 t = LIST_ENTRY( list_head( &dialog->controls ),
3980 msi_control, entry );
3981 msi_destroy_control( t );
3984 /* destroy the list of fonts */
3985 while( dialog->font_list )
3987 msi_font *t = dialog->font_list;
3988 dialog->font_list = t->next;
3989 DeleteObject( t->hfont );
3992 msi_free( dialog->default_font );
3994 msi_free( dialog->control_default );
3995 msi_free( dialog->control_cancel );
3996 msiobj_release( &dialog->package->hdr );
3997 dialog->package = NULL;
4001 void msi_dialog_unregister_class( void )
4003 DestroyWindow( hMsiHiddenWindow );
4004 hMsiHiddenWindow = NULL;
4005 UnregisterClassW( szMsiDialogClass, NULL );
4006 UnregisterClassW( szMsiHiddenWindow, NULL );
4010 static UINT error_dialog_handler(MSIPACKAGE *package, LPCWSTR event,
4011 LPCWSTR argument, msi_dialog* dialog)
4013 static const WCHAR end_dialog[] = {'E','n','d','D','i','a','l','o','g',0};
4014 static const WCHAR error_abort[] = {'E','r','r','o','r','A','b','o','r','t',0};
4015 static const WCHAR error_cancel[] = {'E','r','r','o','r','C','a','n','c','e','l',0};
4016 static const WCHAR error_no[] = {'E','r','r','o','r','N','o',0};
4017 static const WCHAR result_prop[] = {
4018 'M','S','I','E','r','r','o','r','D','i','a','l','o','g','R','e','s','u','l','t',0
4021 if ( lstrcmpW( event, end_dialog ) )
4022 return ERROR_SUCCESS;
4024 if ( !lstrcmpW( argument, error_abort ) || !lstrcmpW( argument, error_cancel ) ||
4025 !lstrcmpW( argument, error_no ) )
4027 msi_set_property( package->db, result_prop, error_abort );
4030 ControlEvent_CleanupSubscriptions(package);
4031 msi_dialog_end_dialog( dialog );
4033 return ERROR_SUCCESS;
4036 static UINT msi_error_dialog_set_error( MSIPACKAGE *package, LPWSTR error_dialog, LPWSTR error )
4040 static const WCHAR update[] =
4041 {'U','P','D','A','T','E',' ','`','C','o','n','t','r','o','l','`',' ',
4042 'S','E','T',' ','`','T','e','x','t','`',' ','=',' ','\'','%','s','\'',' ',
4043 'W','H','E','R','E', ' ','`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',' ',
4044 'A','N','D',' ','`','C','o','n','t','r','o','l','`',' ','=',' ',
4045 '\'','E','r','r','o','r','T','e','x','t','\'',0};
4047 row = MSI_QueryGetRecord( package->db, update, error, error_dialog );
4049 return ERROR_FUNCTION_FAILED;
4051 msiobj_release(&row->hdr);
4052 return ERROR_SUCCESS;
4055 UINT msi_spawn_error_dialog( MSIPACKAGE *package, LPWSTR error_dialog, LPWSTR error )
4058 WCHAR result[MAX_PATH];
4059 UINT r = ERROR_SUCCESS;
4060 DWORD size = MAX_PATH;
4063 static const WCHAR pn_prop[] = {'P','r','o','d','u','c','t','N','a','m','e',0};
4064 static const WCHAR title_fmt[] = {'%','s',' ','W','a','r','n','i','n','g',0};
4065 static const WCHAR error_abort[] = {'E','r','r','o','r','A','b','o','r','t',0};
4066 static const WCHAR result_prop[] = {
4067 'M','S','I','E','r','r','o','r','D','i','a','l','o','g','R','e','s','u','l','t',0
4070 if ( (msi_get_property_int( package->db, szUILevel, 0 ) & INSTALLUILEVEL_MASK) == INSTALLUILEVEL_NONE )
4071 return ERROR_SUCCESS;
4073 if ( !error_dialog )
4075 LPWSTR product_name = msi_dup_property( package->db, pn_prop );
4076 WCHAR title[MAX_PATH];
4078 sprintfW( title, title_fmt, product_name );
4079 res = MessageBoxW( NULL, error, title, MB_OKCANCEL | MB_ICONWARNING );
4081 msi_free( product_name );
4084 return ERROR_SUCCESS;
4086 return ERROR_FUNCTION_FAILED;
4089 r = msi_error_dialog_set_error( package, error_dialog, error );
4090 if ( r != ERROR_SUCCESS )
4093 dialog = msi_dialog_create( package, error_dialog, package->dialog,
4094 error_dialog_handler );
4096 return ERROR_FUNCTION_FAILED;
4098 dialog->finished = FALSE;
4099 r = msi_dialog_run_message_loop( dialog );
4100 if ( r != ERROR_SUCCESS )
4103 r = msi_get_property( package->db, result_prop, result, &size );
4104 if ( r != ERROR_SUCCESS)
4107 if ( !lstrcmpW( result, error_abort ) )
4108 r = ERROR_FUNCTION_FAILED;
4111 msi_dialog_destroy( dialog );