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
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 list_add_head( &dialog->fonts, &font->entry );
315 font->color = MSI_RecordGetInteger( rec, 4 );
317 memset( &lf, 0, sizeof lf );
318 face = MSI_RecordGetString( rec, 2 );
319 lf.lfHeight = MSI_RecordGetInteger( rec, 3 );
320 style = MSI_RecordGetInteger( rec, 5 );
321 if( style & msidbTextStyleStyleBitsBold )
322 lf.lfWeight = FW_BOLD;
323 if( style & msidbTextStyleStyleBitsItalic )
325 if( style & msidbTextStyleStyleBitsUnderline )
326 lf.lfUnderline = TRUE;
327 if( style & msidbTextStyleStyleBitsStrike )
328 lf.lfStrikeOut = TRUE;
329 lstrcpynW( lf.lfFaceName, face, LF_FACESIZE );
331 /* adjust the height */
332 hdc = GetDC( dialog->hwnd );
335 lf.lfHeight = -MulDiv(lf.lfHeight, GetDeviceCaps(hdc, LOGPIXELSY), 72);
336 ReleaseDC( dialog->hwnd, hdc );
339 font->hfont = CreateFontIndirectW( &lf );
341 TRACE("Adding font style %s\n", debugstr_w(font->name) );
343 return ERROR_SUCCESS;
346 static msi_font *msi_dialog_find_font( msi_dialog *dialog, LPCWSTR name )
348 msi_font *font = NULL;
350 LIST_FOR_EACH_ENTRY( font, &dialog->fonts, msi_font, entry )
351 if( !strcmpW( font->name, name ) ) /* FIXME: case sensitive? */
357 static UINT msi_dialog_set_font( msi_dialog *dialog, HWND hwnd, LPCWSTR name )
361 font = msi_dialog_find_font( dialog, name );
363 SendMessageW( hwnd, WM_SETFONT, (WPARAM) font->hfont, TRUE );
365 ERR("No font entry for %s\n", debugstr_w(name));
366 return ERROR_SUCCESS;
369 static UINT msi_dialog_build_font_list( msi_dialog *dialog )
371 static const WCHAR query[] = {
372 'S','E','L','E','C','T',' ','*',' ',
373 'F','R','O','M',' ','`','T','e','x','t','S','t','y','l','e','`',' ',0
376 MSIQUERY *view = NULL;
378 TRACE("dialog %p\n", dialog );
380 r = MSI_OpenQuery( dialog->package->db, &view, query );
381 if( r != ERROR_SUCCESS )
384 r = MSI_IterateRecords( view, NULL, msi_dialog_add_font, dialog );
385 msiobj_release( &view->hdr );
390 static void msi_destroy_control( msi_control *t )
392 list_remove( &t->entry );
393 /* leave dialog->hwnd - destroying parent destroys child windows */
394 msi_free( t->property );
395 msi_free( t->value );
397 DeleteObject( t->hBitmap );
399 DestroyIcon( t->hIcon );
400 msi_free( t->tabnext );
403 FreeLibrary( t->hDll );
407 static msi_control *msi_dialog_create_window( msi_dialog *dialog,
408 MSIRECORD *rec, DWORD exstyle, LPCWSTR szCls, LPCWSTR name, LPCWSTR text,
409 DWORD style, HWND parent )
411 DWORD x, y, width, height;
412 LPWSTR font = NULL, title_font = NULL;
413 LPCWSTR title = NULL;
414 msi_control *control;
418 control = msi_alloc( sizeof *control + strlenW(name)*sizeof(WCHAR) );
422 strcpyW( control->name, name );
423 list_add_tail( &dialog->controls, &control->entry );
424 control->handler = NULL;
425 control->update = NULL;
426 control->property = NULL;
427 control->value = NULL;
428 control->hBitmap = NULL;
429 control->hIcon = NULL;
430 control->hDll = NULL;
431 control->tabnext = strdupW( MSI_RecordGetString( rec, 11) );
432 control->type = strdupW( MSI_RecordGetString( rec, 3 ) );
433 control->progress_current = 0;
434 control->progress_max = 100;
436 x = MSI_RecordGetInteger( rec, 4 );
437 y = MSI_RecordGetInteger( rec, 5 );
438 width = MSI_RecordGetInteger( rec, 6 );
439 height = MSI_RecordGetInteger( rec, 7 );
441 x = msi_dialog_scale_unit( dialog, x );
442 y = msi_dialog_scale_unit( dialog, y );
443 width = msi_dialog_scale_unit( dialog, width );
444 height = msi_dialog_scale_unit( dialog, height );
448 deformat_string( dialog->package, text, &title_font );
449 font = msi_dialog_get_style( title_font, &title );
452 control->hwnd = CreateWindowExW( exstyle, szCls, title, style,
453 x, y, width, height, parent, NULL, NULL, NULL );
455 TRACE("Dialog %s control %s hwnd %p\n",
456 debugstr_w(dialog->name), debugstr_w(text), control->hwnd );
458 msi_dialog_set_font( dialog, control->hwnd,
459 font ? font : dialog->default_font );
461 msi_free( title_font );
467 static LPWSTR msi_dialog_get_uitext( msi_dialog *dialog, LPCWSTR key )
472 static const WCHAR query[] = {
473 's','e','l','e','c','t',' ','*',' ',
474 'f','r','o','m',' ','`','U','I','T','e','x','t','`',' ',
475 'w','h','e','r','e',' ','`','K','e','y','`',' ','=',' ','\'','%','s','\'',0
478 rec = MSI_QueryGetRecord( dialog->package->db, query, key );
479 if (!rec) return NULL;
480 text = strdupW( MSI_RecordGetString( rec, 2 ) );
481 msiobj_release( &rec->hdr );
485 static MSIRECORD *msi_get_binary_record( MSIDATABASE *db, LPCWSTR name )
487 static const WCHAR query[] = {
488 's','e','l','e','c','t',' ','*',' ',
489 'f','r','o','m',' ','B','i','n','a','r','y',' ',
490 'w','h','e','r','e',' ',
491 '`','N','a','m','e','`',' ','=',' ','\'','%','s','\'',0
494 return MSI_QueryGetRecord( db, query, name );
497 static LPWSTR msi_create_tmp_path(void)
503 r = GetTempPathW( MAX_PATH, tmp );
506 len = lstrlenW( tmp ) + 20;
507 path = msi_alloc( len * sizeof (WCHAR) );
510 r = GetTempFileNameW( tmp, szMsi, 0, path );
521 static HANDLE msi_load_image( MSIDATABASE *db, LPCWSTR name, UINT type,
522 UINT cx, UINT cy, UINT flags )
524 MSIRECORD *rec = NULL;
525 HANDLE himage = NULL;
529 TRACE("%p %s %u %u %08x\n", db, debugstr_w(name), cx, cy, flags);
531 tmp = msi_create_tmp_path();
535 rec = msi_get_binary_record( db, name );
538 r = MSI_RecordStreamToFile( rec, 2, tmp );
539 if( r == ERROR_SUCCESS )
541 himage = LoadImageW( 0, tmp, type, cx, cy, flags );
543 msiobj_release( &rec->hdr );
551 static HICON msi_load_icon( MSIDATABASE *db, LPCWSTR text, UINT attributes )
553 DWORD cx = 0, cy = 0, flags;
555 flags = LR_LOADFROMFILE | LR_DEFAULTSIZE;
556 if( attributes & msidbControlAttributesFixedSize )
558 flags &= ~LR_DEFAULTSIZE;
559 if( attributes & msidbControlAttributesIconSize16 )
564 if( attributes & msidbControlAttributesIconSize32 )
569 /* msidbControlAttributesIconSize48 handled by above logic */
571 return msi_load_image( db, text, IMAGE_ICON, cx, cy, flags );
574 static void msi_dialog_update_controls( msi_dialog *dialog, LPCWSTR property )
576 msi_control *control;
578 LIST_FOR_EACH_ENTRY( control, &dialog->controls, msi_control, entry )
580 if ( control->property && !strcmpW( control->property, property ) && control->update )
581 control->update( dialog, control );
585 static void msi_dialog_set_property( MSIPACKAGE *package, LPCWSTR property, LPCWSTR value )
587 UINT r = msi_set_property( package->db, property, value );
588 if (r == ERROR_SUCCESS && !strcmpW( property, cszSourceDir ))
589 msi_reset_folders( package, TRUE );
592 /* called from the Control Event subscription code */
593 void msi_dialog_handle_event( msi_dialog* dialog, LPCWSTR control,
594 LPCWSTR attribute, MSIRECORD *rec )
597 LPCWSTR font_text, text = NULL;
600 ctrl = msi_dialog_find_control( dialog, control );
603 if( !strcmpW( attribute, szText ) )
605 font_text = MSI_RecordGetString( rec , 1 );
606 font = msi_dialog_get_style( font_text, &text );
607 if (!text) text = szEmpty;
608 SetWindowTextW( ctrl->hwnd, text );
610 msi_dialog_check_messages( NULL );
612 else if( !strcmpW( attribute, szProgress ) )
616 func = MSI_RecordGetInteger( rec , 1 );
617 val = MSI_RecordGetInteger( rec , 2 );
619 TRACE("progress: func %u, val %u\n", func, val);
624 ctrl->progress_max = val;
625 ctrl->progress_current = 0;
626 SendMessageW(ctrl->hwnd, PBM_SETRANGE, 0, MAKELPARAM(0,100));
627 SendMessageW(ctrl->hwnd, PBM_SETPOS, 0, 0);
629 case 1: /* FIXME: not sure what this is supposed to do */
632 ctrl->progress_current += val;
633 if (ctrl->progress_current > ctrl->progress_max)
634 ctrl->progress_current = ctrl->progress_max;
635 SendMessageW(ctrl->hwnd, PBM_SETPOS, MulDiv(100, ctrl->progress_current, ctrl->progress_max), 0);
638 FIXME("Unknown progress message %u\n", func);
642 else if ( !strcmpW( attribute, szProperty ) )
644 MSIFEATURE *feature = msi_seltree_get_selected_feature( ctrl );
645 msi_dialog_set_property( dialog->package, ctrl->property, feature->Directory );
647 else if ( !strcmpW( attribute, szSelectionPath ) )
649 LPWSTR prop = msi_dialog_dup_property( dialog, ctrl->property, TRUE );
652 path = msi_dup_property( dialog->package->db, prop );
653 SetWindowTextW( ctrl->hwnd, path );
659 FIXME("Attribute %s not being set\n", debugstr_w(attribute));
664 static void msi_dialog_map_events(msi_dialog* dialog, LPCWSTR control)
666 static const WCHAR Query[] = {
667 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
668 '`','E','v','e','n','t','M','a','p','p','i','n','g','`',' ',
669 'W','H','E','R','E',' ',
670 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',' ',
672 '`','C','o','n','t','r','o','l','_','`',' ','=',' ','\'','%','s','\'',0
675 LPCWSTR event, attribute;
677 row = MSI_QueryGetRecord( dialog->package->db, Query, dialog->name, control );
681 event = MSI_RecordGetString( row, 3 );
682 attribute = MSI_RecordGetString( row, 4 );
683 ControlEvent_SubscribeToEvent( dialog->package, dialog, event, control, attribute );
684 msiobj_release( &row->hdr );
687 /* everything except radio buttons */
688 static msi_control *msi_dialog_add_control( msi_dialog *dialog,
689 MSIRECORD *rec, LPCWSTR szCls, DWORD style )
695 name = MSI_RecordGetString( rec, 2 );
696 attributes = MSI_RecordGetInteger( rec, 8 );
697 text = MSI_RecordGetString( rec, 10 );
699 TRACE("%s, %s, %08x, %s, %08x\n", debugstr_w(szCls), debugstr_w(name),
700 attributes, debugstr_w(text), style);
702 if( attributes & msidbControlAttributesVisible )
704 if( ~attributes & msidbControlAttributesEnabled )
705 style |= WS_DISABLED;
706 if( attributes & msidbControlAttributesSunken )
707 exstyle |= WS_EX_CLIENTEDGE;
709 msi_dialog_map_events(dialog, name);
711 return msi_dialog_create_window( dialog, rec, exstyle, szCls, name,
712 text, style, dialog->hwnd );
723 * we don't erase our own background,
724 * so we have to make sure that the parent window redraws first
726 static void msi_text_on_settext( HWND hWnd )
731 hParent = GetParent( hWnd );
732 GetWindowRect( hWnd, &rc );
733 MapWindowPoints( NULL, hParent, (LPPOINT) &rc, 2 );
734 InvalidateRect( hParent, &rc, TRUE );
737 static LRESULT WINAPI
738 MSIText_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
740 struct msi_text_info *info;
743 TRACE("%p %04x %08lx %08lx\n", hWnd, msg, wParam, lParam);
745 info = GetPropW(hWnd, szButtonData);
747 if( msg == WM_CTLCOLORSTATIC &&
748 ( info->attributes & msidbControlAttributesTransparent ) )
750 SetBkMode( (HDC)wParam, TRANSPARENT );
751 return (LRESULT) GetStockObject(NULL_BRUSH);
754 r = CallWindowProcW(info->oldproc, hWnd, msg, wParam, lParam);
756 SetTextColor( (HDC)wParam, info->font->color );
761 msi_text_on_settext( hWnd );
765 RemovePropW( hWnd, szButtonData );
772 static UINT msi_dialog_text_control( msi_dialog *dialog, MSIRECORD *rec )
774 msi_control *control;
775 struct msi_text_info *info;
776 LPCWSTR text, ptr, prop, control_name;
779 TRACE("%p %p\n", dialog, rec);
781 control = msi_dialog_add_control( dialog, rec, szStatic, SS_LEFT | WS_GROUP );
783 return ERROR_FUNCTION_FAILED;
785 info = msi_alloc( sizeof *info );
787 return ERROR_SUCCESS;
789 control_name = MSI_RecordGetString( rec, 2 );
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 );
1013 return DLGC_WANTARROWS;
1016 RemovePropW( hWnd, szButtonData );
1019 /* native MSI sets a wait cursor here */
1020 msi_dialog_button_handler( info->dialog, info->control, BN_CLICKED );
1026 struct msi_streamin_info
1033 static DWORD CALLBACK
1034 msi_richedit_stream_in( DWORD_PTR arg, LPBYTE buffer, LONG count, LONG *pcb )
1036 struct msi_streamin_info *info = (struct msi_streamin_info*) arg;
1038 if( (count + info->offset) > info->length )
1039 count = info->length - info->offset;
1040 memcpy( buffer, &info->string[ info->offset ], count );
1042 info->offset += count;
1044 TRACE("%d/%d\n", info->offset, info->length);
1049 static void msi_scrolltext_add_text( msi_control *control, LPCWSTR text )
1051 struct msi_streamin_info info;
1054 info.string = strdupWtoA( text );
1056 info.length = lstrlenA( info.string ) + 1;
1058 es.dwCookie = (DWORD_PTR) &info;
1060 es.pfnCallback = msi_richedit_stream_in;
1062 SendMessageW( control->hwnd, EM_STREAMIN, SF_RTF, (LPARAM) &es );
1064 msi_free( info.string );
1067 static UINT msi_dialog_scrolltext_control( msi_dialog *dialog, MSIRECORD *rec )
1069 static const WCHAR szRichEdit20W[] = {
1070 'R','i','c','h','E','d','i','t','2','0','W',0
1072 struct msi_scrolltext_info *info;
1073 msi_control *control;
1078 info = msi_alloc( sizeof *info );
1080 return ERROR_FUNCTION_FAILED;
1082 hRichedit = LoadLibraryA("riched20");
1084 style = WS_BORDER | ES_MULTILINE | WS_VSCROLL |
1085 ES_READONLY | ES_AUTOVSCROLL | WS_TABSTOP;
1086 control = msi_dialog_add_control( dialog, rec, szRichEdit20W, style );
1089 FreeLibrary( hRichedit );
1091 return ERROR_FUNCTION_FAILED;
1094 control->hDll = hRichedit;
1096 info->dialog = dialog;
1097 info->control = control;
1099 /* subclass the static control */
1100 info->oldproc = (WNDPROC) SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
1101 (LONG_PTR)MSIScrollText_WndProc );
1102 SetPropW( control->hwnd, szButtonData, info );
1104 /* add the text into the richedit */
1105 text = MSI_RecordGetString( rec, 10 );
1107 msi_scrolltext_add_text( control, text );
1109 return ERROR_SUCCESS;
1112 static HBITMAP msi_load_picture( MSIDATABASE *db, LPCWSTR name,
1113 INT cx, INT cy, DWORD flags )
1115 HBITMAP hOleBitmap = 0, hBitmap = 0, hOldSrcBitmap, hOldDestBitmap;
1116 MSIRECORD *rec = NULL;
1117 IStream *stm = NULL;
1118 IPicture *pic = NULL;
1123 rec = msi_get_binary_record( db, name );
1127 r = MSI_RecordGetIStream( rec, 2, &stm );
1128 msiobj_release( &rec->hdr );
1129 if( r != ERROR_SUCCESS )
1132 r = OleLoadPicture( stm, 0, TRUE, &IID_IPicture, (LPVOID*) &pic );
1133 IStream_Release( stm );
1136 ERR("failed to load picture\n");
1140 r = IPicture_get_Handle( pic, (OLE_HANDLE*) &hOleBitmap );
1143 ERR("failed to get bitmap handle\n");
1147 /* make the bitmap the desired size */
1148 r = GetObjectW( hOleBitmap, sizeof bm, &bm );
1149 if (r != sizeof bm )
1151 ERR("failed to get bitmap size\n");
1155 if (flags & LR_DEFAULTSIZE)
1161 srcdc = CreateCompatibleDC( NULL );
1162 hOldSrcBitmap = SelectObject( srcdc, hOleBitmap );
1163 destdc = CreateCompatibleDC( NULL );
1164 hBitmap = CreateCompatibleBitmap( srcdc, cx, cy );
1165 hOldDestBitmap = SelectObject( destdc, hBitmap );
1166 StretchBlt( destdc, 0, 0, cx, cy,
1167 srcdc, 0, 0, bm.bmWidth, bm.bmHeight, SRCCOPY);
1168 SelectObject( srcdc, hOldSrcBitmap );
1169 SelectObject( destdc, hOldDestBitmap );
1175 IPicture_Release( pic );
1179 static UINT msi_dialog_bitmap_control( msi_dialog *dialog, MSIRECORD *rec )
1181 UINT cx, cy, flags, style, attributes;
1182 msi_control *control;
1185 flags = LR_LOADFROMFILE;
1186 style = SS_BITMAP | SS_LEFT | WS_GROUP;
1188 attributes = MSI_RecordGetInteger( rec, 8 );
1189 if( attributes & msidbControlAttributesFixedSize )
1191 flags |= LR_DEFAULTSIZE;
1192 style |= SS_CENTERIMAGE;
1195 control = msi_dialog_add_control( dialog, rec, szStatic, style );
1196 cx = MSI_RecordGetInteger( rec, 6 );
1197 cy = MSI_RecordGetInteger( rec, 7 );
1198 cx = msi_dialog_scale_unit( dialog, cx );
1199 cy = msi_dialog_scale_unit( dialog, cy );
1201 name = msi_get_binary_name( dialog->package, rec );
1202 control->hBitmap = msi_load_picture( dialog->package->db, name, cx, cy, flags );
1203 if( control->hBitmap )
1204 SendMessageW( control->hwnd, STM_SETIMAGE,
1205 IMAGE_BITMAP, (LPARAM) control->hBitmap );
1207 ERR("Failed to load bitmap %s\n", debugstr_w(name));
1211 return ERROR_SUCCESS;
1214 static UINT msi_dialog_icon_control( msi_dialog *dialog, MSIRECORD *rec )
1216 msi_control *control;
1222 control = msi_dialog_add_control( dialog, rec, szStatic,
1223 SS_ICON | SS_CENTERIMAGE | WS_GROUP );
1225 attributes = MSI_RecordGetInteger( rec, 8 );
1226 name = msi_get_binary_name( dialog->package, rec );
1227 control->hIcon = msi_load_icon( dialog->package->db, name, attributes );
1228 if( control->hIcon )
1229 SendMessageW( control->hwnd, STM_SETICON, (WPARAM) control->hIcon, 0 );
1231 ERR("Failed to load bitmap %s\n", debugstr_w(name));
1233 return ERROR_SUCCESS;
1236 /******************** Combo Box ***************************************/
1238 struct msi_combobox_info
1248 static LRESULT WINAPI MSIComboBox_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
1250 struct msi_combobox_info *info;
1254 TRACE("%p %04x %08lx %08lx\n", hWnd, msg, wParam, lParam);
1256 info = GetPropW( hWnd, szButtonData );
1260 r = CallWindowProcW( info->oldproc, hWnd, msg, wParam, lParam );
1265 for (j = 0; j < info->num_items; j++)
1266 msi_free( info->items[j] );
1267 msi_free( info->items );
1269 RemovePropW( hWnd, szButtonData );
1276 static UINT msi_combobox_add_item( MSIRECORD *rec, LPVOID param )
1278 struct msi_combobox_info *info = param;
1279 LPCWSTR value, text;
1282 value = MSI_RecordGetString( rec, 3 );
1283 text = MSI_RecordGetString( rec, 4 );
1285 info->items[info->addpos_items] = strdupW( value );
1287 pos = SendMessageW( info->hwnd, CB_ADDSTRING, 0, (LPARAM)text );
1288 SendMessageW( info->hwnd, CB_SETITEMDATA, pos, (LPARAM)info->items[info->addpos_items] );
1289 info->addpos_items++;
1291 return ERROR_SUCCESS;
1294 static UINT msi_combobox_add_items( struct msi_combobox_info *info, LPCWSTR property )
1297 MSIQUERY *view = NULL;
1300 static const WCHAR query[] = {
1301 'S','E','L','E','C','T',' ','*',' ',
1302 'F','R','O','M',' ','`','C','o','m','b','o','B','o','x','`',' ',
1303 'W','H','E','R','E',' ',
1304 '`','P','r','o','p','e','r','t','y','`',' ','=',' ','\'','%','s','\'',' ',
1305 'O','R','D','E','R',' ','B','Y',' ','`','O','r','d','e','r','`',0
1308 r = MSI_OpenQuery( info->dialog->package->db, &view, query, property );
1309 if (r != ERROR_SUCCESS)
1312 /* just get the number of records */
1314 r = MSI_IterateRecords( view, &count, NULL, NULL );
1316 info->num_items = count;
1317 info->items = msi_alloc( sizeof(*info->items) * count );
1319 r = MSI_IterateRecords( view, NULL, msi_combobox_add_item, info );
1320 msiobj_release( &view->hdr );
1325 static UINT msi_dialog_combobox_handler( msi_dialog *dialog,
1326 msi_control *control, WPARAM param )
1328 struct msi_combobox_info *info;
1332 if (HIWORD(param) != CBN_SELCHANGE && HIWORD(param) != CBN_EDITCHANGE)
1333 return ERROR_SUCCESS;
1335 info = GetPropW( control->hwnd, szButtonData );
1336 index = SendMessageW( control->hwnd, CB_GETCURSEL, 0, 0 );
1337 if (index == CB_ERR)
1338 value = msi_get_window_text( control->hwnd );
1340 value = (LPWSTR) SendMessageW( control->hwnd, CB_GETITEMDATA, index, 0 );
1342 msi_dialog_set_property( info->dialog->package, control->property, value );
1343 msi_dialog_evaluate_control_conditions( info->dialog );
1345 if (index == CB_ERR)
1348 return ERROR_SUCCESS;
1351 static void msi_dialog_combobox_update( msi_dialog *dialog,
1352 msi_control *control )
1354 struct msi_combobox_info *info;
1358 info = GetPropW( control->hwnd, szButtonData );
1360 value = msi_dup_property( dialog->package->db, control->property );
1363 SendMessageW( control->hwnd, CB_SETCURSEL, -1, 0 );
1367 for (j = 0; j < info->num_items; j++)
1369 tmp = (LPWSTR) SendMessageW( control->hwnd, CB_GETITEMDATA, j, 0 );
1370 if (!strcmpW( value, tmp ))
1374 if (j < info->num_items)
1376 SendMessageW( control->hwnd, CB_SETCURSEL, j, 0 );
1380 SendMessageW( control->hwnd, CB_SETCURSEL, -1, 0 );
1381 SetWindowTextW( control->hwnd, value );
1387 static UINT msi_dialog_combo_control( msi_dialog *dialog, MSIRECORD *rec )
1389 struct msi_combobox_info *info;
1390 msi_control *control;
1391 DWORD attributes, style;
1394 info = msi_alloc( sizeof *info );
1396 return ERROR_FUNCTION_FAILED;
1398 style = CBS_AUTOHSCROLL | WS_TABSTOP | WS_GROUP | WS_CHILD;
1399 attributes = MSI_RecordGetInteger( rec, 8 );
1400 if ( ~attributes & msidbControlAttributesSorted)
1402 if ( attributes & msidbControlAttributesComboList)
1403 style |= CBS_DROPDOWNLIST;
1405 style |= CBS_DROPDOWN;
1407 control = msi_dialog_add_control( dialog, rec, WC_COMBOBOXW, style );
1411 return ERROR_FUNCTION_FAILED;
1414 control->handler = msi_dialog_combobox_handler;
1415 control->update = msi_dialog_combobox_update;
1417 prop = MSI_RecordGetString( rec, 9 );
1418 control->property = msi_dialog_dup_property( dialog, prop, FALSE );
1421 info->dialog = dialog;
1422 info->hwnd = control->hwnd;
1424 info->addpos_items = 0;
1425 info->oldproc = (WNDPROC)SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
1426 (LONG_PTR)MSIComboBox_WndProc );
1427 SetPropW( control->hwnd, szButtonData, info );
1429 if (control->property)
1430 msi_combobox_add_items( info, control->property );
1432 msi_dialog_combobox_update( dialog, control );
1434 return ERROR_SUCCESS;
1437 /* length of 2^32 + 1 */
1438 #define MAX_NUM_DIGITS 11
1440 static UINT msi_dialog_edit_control( msi_dialog *dialog, MSIRECORD *rec )
1442 msi_control *control;
1444 LPWSTR val, begin, end;
1445 WCHAR num[MAX_NUM_DIGITS];
1448 control = msi_dialog_add_control( dialog, rec, szEdit,
1449 WS_BORDER | WS_TABSTOP | ES_AUTOHSCROLL );
1450 control->handler = msi_dialog_edit_handler;
1452 text = MSI_RecordGetString( rec, 10 );
1455 begin = strchrW( text, '{' );
1456 end = strchrW( text, '}' );
1458 if ( begin && end && end > begin &&
1459 begin[0] >= '0' && begin[0] <= '9' &&
1460 end - begin < MAX_NUM_DIGITS)
1462 lstrcpynW( num, begin + 1, end - begin );
1463 limit = atolW( num );
1465 SendMessageW( control->hwnd, EM_SETLIMITTEXT, limit, 0 );
1469 prop = MSI_RecordGetString( rec, 9 );
1471 control->property = strdupW( prop );
1473 val = msi_dup_property( dialog->package->db, control->property );
1474 SetWindowTextW( control->hwnd, val );
1476 return ERROR_SUCCESS;
1479 /******************** Masked Edit ********************************************/
1481 #define MASK_MAX_GROUPS 20
1483 struct msi_mask_group
1491 struct msi_maskedit_info
1499 struct msi_mask_group group[MASK_MAX_GROUPS];
1502 static BOOL msi_mask_editable( WCHAR type )
1517 static void msi_mask_control_change( struct msi_maskedit_info *info )
1522 val = msi_alloc( (info->num_chars+1)*sizeof(WCHAR) );
1523 for( i=0, n=0; i<info->num_groups; i++ )
1525 if( (info->group[i].len + n) > info->num_chars )
1527 ERR("can't fit control %d text into template\n",i);
1530 if (!msi_mask_editable(info->group[i].type))
1532 for(r=0; r<info->group[i].len; r++)
1533 val[n+r] = info->group[i].type;
1538 r = GetWindowTextW( info->group[i].hwnd, &val[n], info->group[i].len+1 );
1539 if( r != info->group[i].len )
1545 TRACE("%d/%d controls were good\n", i, info->num_groups);
1547 if( i == info->num_groups )
1549 TRACE("Set property %s to %s\n", debugstr_w(info->prop), debugstr_w(val));
1550 CharUpperBuffW( val, info->num_chars );
1551 msi_dialog_set_property( info->dialog->package, info->prop, val );
1552 msi_dialog_evaluate_control_conditions( info->dialog );
1557 /* now move to the next control if necessary */
1558 static VOID msi_mask_next_control( struct msi_maskedit_info *info, HWND hWnd )
1563 for( i=0; i<info->num_groups; i++ )
1564 if( info->group[i].hwnd == hWnd )
1567 /* don't move from the last control */
1568 if( i >= (info->num_groups-1) )
1571 len = SendMessageW( hWnd, WM_GETTEXTLENGTH, 0, 0 );
1572 if( len < info->group[i].len )
1575 hWndNext = GetNextDlgTabItem( GetParent( hWnd ), hWnd, FALSE );
1576 SetFocus( hWndNext );
1579 static LRESULT WINAPI
1580 MSIMaskedEdit_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
1582 struct msi_maskedit_info *info;
1585 TRACE("%p %04x %08lx %08lx\n", hWnd, msg, wParam, lParam);
1587 info = GetPropW(hWnd, szButtonData);
1589 r = CallWindowProcW(info->oldproc, hWnd, msg, wParam, lParam);
1594 if (HIWORD(wParam) == EN_CHANGE)
1596 msi_mask_control_change( info );
1597 msi_mask_next_control( info, (HWND) lParam );
1601 msi_free( info->prop );
1603 RemovePropW( hWnd, szButtonData );
1610 /* fish the various bits of the property out and put them in the control */
1612 msi_maskedit_set_text( struct msi_maskedit_info *info, LPCWSTR text )
1618 for( i = 0; i < info->num_groups; i++ )
1620 if( info->group[i].len < strlenW( p ) )
1622 LPWSTR chunk = strdupW( p );
1623 chunk[ info->group[i].len ] = 0;
1624 SetWindowTextW( info->group[i].hwnd, chunk );
1629 SetWindowTextW( info->group[i].hwnd, p );
1632 p += info->group[i].len;
1636 static struct msi_maskedit_info * msi_dialog_parse_groups( LPCWSTR mask )
1638 struct msi_maskedit_info * info = NULL;
1639 int i = 0, n = 0, total = 0;
1642 TRACE("masked control, template %s\n", debugstr_w(mask));
1647 info = msi_alloc_zero( sizeof *info );
1651 p = strchrW(mask, '<');
1657 for( i=0; i<MASK_MAX_GROUPS; i++ )
1659 /* stop at the end of the string */
1660 if( p[0] == 0 || p[0] == '>' )
1663 /* count the number of the same identifier */
1664 for( n=0; p[n] == p[0]; n++ )
1666 info->group[i].ofs = total;
1667 info->group[i].type = p[0];
1671 total++; /* an extra not part of the group */
1673 info->group[i].len = n;
1678 TRACE("%d characters in %d groups\n", total, i );
1679 if( i == MASK_MAX_GROUPS )
1680 ERR("too many groups in PIDTemplate %s\n", debugstr_w(mask));
1682 info->num_chars = total;
1683 info->num_groups = i;
1689 msi_maskedit_create_children( struct msi_maskedit_info *info, LPCWSTR font )
1691 DWORD width, height, style, wx, ww;
1696 style = WS_CHILD | WS_BORDER | WS_VISIBLE | WS_TABSTOP | ES_AUTOHSCROLL;
1698 GetClientRect( info->hwnd, &rect );
1700 width = rect.right - rect.left;
1701 height = rect.bottom - rect.top;
1703 for( i = 0; i < info->num_groups; i++ )
1705 if (!msi_mask_editable( info->group[i].type ))
1707 wx = (info->group[i].ofs * width) / info->num_chars;
1708 ww = (info->group[i].len * width) / info->num_chars;
1710 hwnd = CreateWindowW( szEdit, NULL, style, wx, 0, ww, height,
1711 info->hwnd, NULL, NULL, NULL );
1714 ERR("failed to create mask edit sub window\n");
1718 SendMessageW( hwnd, EM_LIMITTEXT, info->group[i].len, 0 );
1720 msi_dialog_set_font( info->dialog, hwnd,
1721 font?font:info->dialog->default_font );
1722 info->group[i].hwnd = hwnd;
1727 * office 2003 uses "73931<````=````=````=````=`````>@@@@@"
1728 * delphi 7 uses "<????-??????-??????-????>" and "<???-???>"
1729 * filemaker pro 7 uses "<^^^^=^^^^=^^^^=^^^^=^^^^=^^^^=^^^^^>"
1731 static UINT msi_dialog_maskedit_control( msi_dialog *dialog, MSIRECORD *rec )
1733 LPWSTR font_mask, val = NULL, font;
1734 struct msi_maskedit_info *info = NULL;
1735 UINT ret = ERROR_SUCCESS;
1736 msi_control *control;
1741 font_mask = msi_get_deformatted_field( dialog->package, rec, 10 );
1742 font = msi_dialog_get_style( font_mask, &mask );
1745 WARN("mask template is empty\n");
1749 info = msi_dialog_parse_groups( mask );
1752 ERR("template %s is invalid\n", debugstr_w(mask));
1756 info->dialog = dialog;
1758 control = msi_dialog_add_control( dialog, rec, szStatic,
1759 SS_OWNERDRAW | WS_GROUP | WS_VISIBLE );
1762 ERR("Failed to create maskedit container\n");
1763 ret = ERROR_FUNCTION_FAILED;
1766 SetWindowLongPtrW( control->hwnd, GWL_EXSTYLE, WS_EX_CONTROLPARENT );
1768 info->hwnd = control->hwnd;
1770 /* subclass the static control */
1771 info->oldproc = (WNDPROC) SetWindowLongPtrW( info->hwnd, GWLP_WNDPROC,
1772 (LONG_PTR)MSIMaskedEdit_WndProc );
1773 SetPropW( control->hwnd, szButtonData, info );
1775 prop = MSI_RecordGetString( rec, 9 );
1777 info->prop = strdupW( prop );
1779 msi_maskedit_create_children( info, font );
1783 val = msi_dup_property( dialog->package->db, prop );
1786 msi_maskedit_set_text( info, val );
1792 if( ret != ERROR_SUCCESS )
1794 msi_free( font_mask );
1799 /******************** Progress Bar *****************************************/
1801 static UINT msi_dialog_progress_bar( msi_dialog *dialog, MSIRECORD *rec )
1803 msi_control *control;
1804 DWORD attributes, style;
1807 attributes = MSI_RecordGetInteger( rec, 8 );
1808 if( !(attributes & msidbControlAttributesProgress95) )
1809 style |= PBS_SMOOTH;
1811 control = msi_dialog_add_control( dialog, rec, PROGRESS_CLASSW, style );
1813 return ERROR_FUNCTION_FAILED;
1815 ControlEvent_SubscribeToEvent( dialog->package, dialog,
1816 szSetProgress, control->name, szProgress );
1817 return ERROR_SUCCESS;
1820 /******************** Path Edit ********************************************/
1822 struct msi_pathedit_info
1825 msi_control *control;
1829 static LPWSTR msi_get_window_text( HWND hwnd )
1835 buf = msi_alloc( sz*sizeof(WCHAR) );
1838 r = GetWindowTextW( hwnd, buf, sz );
1842 buf = msi_realloc( buf, sz*sizeof(WCHAR) );
1848 static void msi_dialog_update_pathedit( msi_dialog *dialog, msi_control *control )
1853 if (!control && !(control = msi_dialog_find_control_by_type( dialog, szPathEdit )))
1856 indirect = control->attributes & msidbControlAttributesIndirect;
1857 prop = msi_dialog_dup_property( dialog, control->property, indirect );
1858 path = msi_dialog_dup_property( dialog, prop, TRUE );
1860 SetWindowTextW( control->hwnd, path );
1861 SendMessageW( control->hwnd, EM_SETSEL, 0, -1 );
1867 /* FIXME: test when this should fail */
1868 static BOOL msi_dialog_verify_path( LPWSTR path )
1870 if ( !lstrlenW( path ) )
1873 if ( PathIsRelativeW( path ) )
1879 /* returns TRUE if the path is valid, FALSE otherwise */
1880 static BOOL msi_dialog_onkillfocus( msi_dialog *dialog, msi_control *control )
1886 indirect = control->attributes & msidbControlAttributesIndirect;
1887 prop = msi_dialog_dup_property( dialog, control->property, indirect );
1889 buf = msi_get_window_text( control->hwnd );
1891 if ( !msi_dialog_verify_path( buf ) )
1893 /* FIXME: display an error message box */
1894 ERR("Invalid path %s\n", debugstr_w( buf ));
1896 SetFocus( control->hwnd );
1901 msi_dialog_set_property( dialog->package, prop, buf );
1904 msi_dialog_update_pathedit( dialog, control );
1906 TRACE("edit %s contents changed, set %s\n", debugstr_w(control->name),
1915 static LRESULT WINAPI MSIPathEdit_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
1917 struct msi_pathedit_info *info = GetPropW(hWnd, szButtonData);
1920 TRACE("%p %04x %08lx %08lx\n", hWnd, msg, wParam, lParam);
1922 if ( msg == WM_KILLFOCUS )
1924 /* if the path is invalid, don't handle this message */
1925 if ( !msi_dialog_onkillfocus( info->dialog, info->control ) )
1929 r = CallWindowProcW(info->oldproc, hWnd, msg, wParam, lParam);
1931 if ( msg == WM_NCDESTROY )
1934 RemovePropW( hWnd, szButtonData );
1940 static UINT msi_dialog_pathedit_control( msi_dialog *dialog, MSIRECORD *rec )
1942 struct msi_pathedit_info *info;
1943 msi_control *control;
1946 info = msi_alloc( sizeof *info );
1948 return ERROR_FUNCTION_FAILED;
1950 control = msi_dialog_add_control( dialog, rec, szEdit,
1951 WS_BORDER | WS_TABSTOP );
1952 control->attributes = MSI_RecordGetInteger( rec, 8 );
1953 prop = MSI_RecordGetString( rec, 9 );
1954 control->property = msi_dialog_dup_property( dialog, prop, FALSE );
1956 info->dialog = dialog;
1957 info->control = control;
1958 info->oldproc = (WNDPROC) SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
1959 (LONG_PTR)MSIPathEdit_WndProc );
1960 SetPropW( control->hwnd, szButtonData, info );
1962 msi_dialog_update_pathedit( dialog, control );
1964 return ERROR_SUCCESS;
1967 /* radio buttons are a bit different from normal controls */
1968 static UINT msi_dialog_create_radiobutton( MSIRECORD *rec, LPVOID param )
1970 radio_button_group_descr *group = param;
1971 msi_dialog *dialog = group->dialog;
1972 msi_control *control;
1973 LPCWSTR prop, text, name;
1974 DWORD style, attributes = group->attributes;
1976 style = WS_CHILD | BS_AUTORADIOBUTTON | BS_MULTILINE | WS_TABSTOP;
1977 name = MSI_RecordGetString( rec, 3 );
1978 text = MSI_RecordGetString( rec, 8 );
1979 if( attributes & msidbControlAttributesVisible )
1980 style |= WS_VISIBLE;
1981 if( ~attributes & msidbControlAttributesEnabled )
1982 style |= WS_DISABLED;
1984 control = msi_dialog_create_window( dialog, rec, 0, szButton, name, text,
1985 style, group->parent->hwnd );
1987 return ERROR_FUNCTION_FAILED;
1988 control->handler = msi_dialog_radiogroup_handler;
1990 if (group->propval && !strcmpW( control->name, group->propval ))
1991 SendMessageW(control->hwnd, BM_SETCHECK, BST_CHECKED, 0);
1993 prop = MSI_RecordGetString( rec, 1 );
1995 control->property = strdupW( prop );
1997 return ERROR_SUCCESS;
2000 static UINT msi_dialog_radiogroup_control( msi_dialog *dialog, MSIRECORD *rec )
2002 static const WCHAR query[] = {
2003 'S','E','L','E','C','T',' ','*',' ',
2004 'F','R','O','M',' ','R','a','d','i','o','B','u','t','t','o','n',' ',
2005 'W','H','E','R','E',' ',
2006 '`','P','r','o','p','e','r','t','y','`',' ','=',' ','\'','%','s','\'',0};
2009 msi_control *control;
2010 MSIQUERY *view = NULL;
2011 radio_button_group_descr group;
2012 MSIPACKAGE *package = dialog->package;
2014 DWORD attr, style = WS_GROUP;
2016 prop = MSI_RecordGetString( rec, 9 );
2018 TRACE("%p %p %s\n", dialog, rec, debugstr_w( prop ));
2020 attr = MSI_RecordGetInteger( rec, 8 );
2021 if (attr & msidbControlAttributesHasBorder)
2022 style |= BS_GROUPBOX;
2024 style |= BS_OWNERDRAW;
2026 /* Create parent group box to hold radio buttons */
2027 control = msi_dialog_add_control( dialog, rec, szButton, style );
2029 return ERROR_FUNCTION_FAILED;
2031 oldproc = (WNDPROC) SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
2032 (LONG_PTR)MSIRadioGroup_WndProc );
2033 SetPropW(control->hwnd, szButtonData, oldproc);
2034 SetWindowLongPtrW( control->hwnd, GWL_EXSTYLE, WS_EX_CONTROLPARENT );
2037 control->property = strdupW( prop );
2039 /* query the Radio Button table for all control in this group */
2040 r = MSI_OpenQuery( package->db, &view, query, prop );
2041 if( r != ERROR_SUCCESS )
2043 ERR("query failed for dialog %s radio group %s\n",
2044 debugstr_w(dialog->name), debugstr_w(prop));
2045 return ERROR_INVALID_PARAMETER;
2048 group.dialog = dialog;
2049 group.parent = control;
2050 group.attributes = MSI_RecordGetInteger( rec, 8 );
2051 group.propval = msi_dup_property( dialog->package->db, control->property );
2053 r = MSI_IterateRecords( view, 0, msi_dialog_create_radiobutton, &group );
2054 msiobj_release( &view->hdr );
2055 msi_free( group.propval );
2060 /******************** Selection Tree ***************************************/
2062 struct msi_selection_tree_info
2071 msi_seltree_sync_item_state( HWND hwnd, MSIFEATURE *feature, HTREEITEM hItem )
2074 DWORD index = feature->Action;
2076 TRACE("Feature %s -> %d %d %d\n", debugstr_w(feature->Title),
2077 feature->Installed, feature->Action, feature->ActionRequest);
2079 if (index == INSTALLSTATE_UNKNOWN)
2080 index = INSTALLSTATE_ABSENT;
2082 tvi.mask = TVIF_STATE;
2084 tvi.state = INDEXTOSTATEIMAGEMASK( index );
2085 tvi.stateMask = TVIS_STATEIMAGEMASK;
2087 SendMessageW( hwnd, TVM_SETITEMW, 0, (LPARAM) &tvi );
2091 msi_seltree_popup_menu( HWND hwnd, INT x, INT y )
2096 /* create a menu to display */
2097 hMenu = CreatePopupMenu();
2099 /* FIXME: load strings from resources */
2100 AppendMenuA( hMenu, MF_ENABLED, INSTALLSTATE_LOCAL, "Install feature locally");
2101 AppendMenuA( hMenu, MF_ENABLED, USER_INSTALLSTATE_ALL, "Install entire feature");
2102 AppendMenuA( hMenu, MF_ENABLED, INSTALLSTATE_ADVERTISED, "Install on demand");
2103 AppendMenuA( hMenu, MF_ENABLED, INSTALLSTATE_ABSENT, "Don't install");
2104 r = TrackPopupMenu( hMenu, TPM_LEFTALIGN | TPM_TOPALIGN | TPM_RETURNCMD,
2105 x, y, 0, hwnd, NULL );
2106 DestroyMenu( hMenu );
2111 msi_seltree_feature_from_item( HWND hwnd, HTREEITEM hItem )
2115 /* get the feature from the item */
2116 memset( &tvi, 0, sizeof tvi );
2118 tvi.mask = TVIF_PARAM | TVIF_HANDLE;
2119 SendMessageW( hwnd, TVM_GETITEMW, 0, (LPARAM) &tvi );
2121 return (MSIFEATURE*) tvi.lParam;
2125 msi_seltree_update_feature_installstate( HWND hwnd, HTREEITEM hItem,
2126 MSIPACKAGE *package, MSIFEATURE *feature, INSTALLSTATE state )
2128 msi_feature_set_state( package, feature, state );
2129 msi_seltree_sync_item_state( hwnd, feature, hItem );
2130 ACTION_UpdateComponentStates( package, feature );
2134 msi_seltree_update_siblings_and_children_installstate( HWND hwnd, HTREEITEM curr,
2135 MSIPACKAGE *package, INSTALLSTATE state)
2137 /* update all siblings */
2140 MSIFEATURE *feature;
2143 feature = msi_seltree_feature_from_item( hwnd, curr );
2144 msi_seltree_update_feature_installstate( hwnd, curr, package, feature, state );
2146 /* update this sibling's children */
2147 child = (HTREEITEM)SendMessageW( hwnd, TVM_GETNEXTITEM, (WPARAM)TVGN_CHILD, (LPARAM)curr );
2149 msi_seltree_update_siblings_and_children_installstate( hwnd, child,
2152 while ((curr = (HTREEITEM)SendMessageW( hwnd, TVM_GETNEXTITEM, (WPARAM)TVGN_NEXT, (LPARAM)curr )));
2156 msi_seltree_menu( HWND hwnd, HTREEITEM hItem )
2158 struct msi_selection_tree_info *info;
2159 MSIFEATURE *feature;
2160 MSIPACKAGE *package;
2168 info = GetPropW(hwnd, szButtonData);
2169 package = info->dialog->package;
2171 feature = msi_seltree_feature_from_item( hwnd, hItem );
2174 ERR("item %p feature was NULL\n", hItem);
2178 /* get the item's rectangle to put the menu just below it */
2180 SendMessageW( hwnd, TVM_GETITEMRECT, 0, (LPARAM) &u.rc );
2181 MapWindowPoints( hwnd, NULL, u.pt, 2 );
2183 r = msi_seltree_popup_menu( hwnd, u.rc.left, u.rc.top );
2187 case USER_INSTALLSTATE_ALL:
2188 r = INSTALLSTATE_LOCAL;
2190 case INSTALLSTATE_ADVERTISED:
2191 case INSTALLSTATE_ABSENT:
2194 child = (HTREEITEM)SendMessageW( hwnd, TVM_GETNEXTITEM, (WPARAM)TVGN_CHILD, (LPARAM)hItem );
2196 msi_seltree_update_siblings_and_children_installstate( hwnd, child, package, r );
2199 case INSTALLSTATE_LOCAL:
2200 msi_seltree_update_feature_installstate( hwnd, hItem, package, feature, r );
2207 static MSIFEATURE *msi_seltree_get_selected_feature( msi_control *control )
2209 struct msi_selection_tree_info *info = GetPropW(control->hwnd, szButtonData);
2210 return msi_seltree_feature_from_item( control->hwnd, info->selected );
2213 static LRESULT WINAPI
2214 MSISelectionTree_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
2216 struct msi_selection_tree_info *info;
2217 TVHITTESTINFO tvhti;
2220 TRACE("%p %04x %08lx %08lx\n", hWnd, msg, wParam, lParam);
2222 info = GetPropW(hWnd, szButtonData);
2226 case WM_LBUTTONDOWN:
2227 tvhti.pt.x = (short)LOWORD( lParam );
2228 tvhti.pt.y = (short)HIWORD( lParam );
2231 r = CallWindowProcW(info->oldproc, hWnd, TVM_HITTEST, 0, (LPARAM) &tvhti );
2232 if (tvhti.flags & TVHT_ONITEMSTATEICON)
2233 return msi_seltree_menu( hWnd, tvhti.hItem );
2237 r = CallWindowProcW(info->oldproc, hWnd, msg, wParam, lParam);
2243 RemovePropW( hWnd, szButtonData );
2250 msi_seltree_add_child_features( MSIPACKAGE *package, HWND hwnd,
2251 LPCWSTR parent, HTREEITEM hParent )
2253 struct msi_selection_tree_info *info = GetPropW( hwnd, szButtonData );
2254 MSIFEATURE *feature;
2255 TVINSERTSTRUCTW tvis;
2256 HTREEITEM hitem, hfirst = NULL;
2258 LIST_FOR_EACH_ENTRY( feature, &package->features, MSIFEATURE, entry )
2260 if ( parent && feature->Feature_Parent && strcmpW( parent, feature->Feature_Parent ))
2262 else if ( parent && !feature->Feature_Parent )
2264 else if ( !parent && feature->Feature_Parent )
2267 if ( !feature->Title )
2270 if ( !feature->Display )
2273 memset( &tvis, 0, sizeof tvis );
2274 tvis.hParent = hParent;
2275 tvis.hInsertAfter = TVI_LAST;
2276 tvis.u.item.mask = TVIF_TEXT | TVIF_PARAM;
2277 tvis.u.item.pszText = feature->Title;
2278 tvis.u.item.lParam = (LPARAM) feature;
2280 hitem = (HTREEITEM) SendMessageW( hwnd, TVM_INSERTITEMW, 0, (LPARAM) &tvis );
2287 msi_seltree_sync_item_state( hwnd, feature, hitem );
2288 msi_seltree_add_child_features( package, hwnd,
2289 feature->Feature, hitem );
2291 /* the node is expanded if Display is odd */
2292 if ( feature->Display % 2 != 0 )
2293 SendMessageW( hwnd, TVM_EXPAND, TVE_EXPAND, (LPARAM) hitem );
2296 /* select the first item */
2297 SendMessageW( hwnd, TVM_SELECTITEM, TVGN_CARET | TVGN_DROPHILITE, (LPARAM) hfirst );
2298 info->selected = hfirst;
2301 static void msi_seltree_create_imagelist( HWND hwnd )
2303 const int bm_width = 32, bm_height = 16, bm_count = 3;
2304 const int bm_resource = 0x1001;
2309 himl = ImageList_Create( bm_width, bm_height, FALSE, 4, 0 );
2312 ERR("failed to create image list\n");
2316 for (i=0; i<bm_count; i++)
2318 hbmp = LoadBitmapW( msi_hInstance, MAKEINTRESOURCEW(i+bm_resource) );
2321 ERR("failed to load bitmap %d\n", i);
2326 * Add a dummy bitmap at offset zero because the treeview
2327 * can't use it as a state mask (zero means no user state).
2330 ImageList_Add( himl, hbmp, NULL );
2332 ImageList_Add( himl, hbmp, NULL );
2335 SendMessageW( hwnd, TVM_SETIMAGELIST, TVSIL_STATE, (LPARAM)himl );
2338 static UINT msi_dialog_seltree_handler( msi_dialog *dialog,
2339 msi_control *control, WPARAM param )
2341 struct msi_selection_tree_info *info = GetPropW( control->hwnd, szButtonData );
2342 LPNMTREEVIEWW tv = (LPNMTREEVIEWW)param;
2343 MSIRECORD *row, *rec;
2345 MSIFEATURE *feature;
2346 LPCWSTR dir, title = NULL;
2347 UINT r = ERROR_SUCCESS;
2349 static const WCHAR select[] = {
2350 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2351 '`','F','e','a','t','u','r','e','`',' ','W','H','E','R','E',' ',
2352 '`','T','i','t','l','e','`',' ','=',' ','\'','%','s','\'',0
2355 if (tv->hdr.code != TVN_SELCHANGINGW)
2356 return ERROR_SUCCESS;
2358 info->selected = tv->itemNew.hItem;
2360 if (!(tv->itemNew.mask & TVIF_TEXT))
2362 feature = msi_seltree_feature_from_item( control->hwnd, tv->itemNew.hItem );
2364 title = feature->Title;
2367 title = tv->itemNew.pszText;
2369 row = MSI_QueryGetRecord( dialog->package->db, select, title );
2371 return ERROR_FUNCTION_FAILED;
2373 rec = MSI_CreateRecord( 1 );
2375 MSI_RecordSetStringW( rec, 1, MSI_RecordGetString( row, 4 ) );
2376 ControlEvent_FireSubscribedEvent( dialog->package, szSelectionDescription, rec );
2378 dir = MSI_RecordGetString( row, 7 );
2381 folder = get_loaded_folder( dialog->package, dir );
2384 r = ERROR_FUNCTION_FAILED;
2387 MSI_RecordSetStringW( rec, 1, folder->ResolvedTarget );
2390 MSI_RecordSetStringW( rec, 1, NULL );
2392 ControlEvent_FireSubscribedEvent( dialog->package, szSelectionPath, rec );
2395 msiobj_release(&row->hdr);
2396 msiobj_release(&rec->hdr);
2401 static UINT msi_dialog_selection_tree( msi_dialog *dialog, MSIRECORD *rec )
2403 msi_control *control;
2404 LPCWSTR prop, control_name;
2405 MSIPACKAGE *package = dialog->package;
2407 struct msi_selection_tree_info *info;
2409 info = msi_alloc( sizeof *info );
2411 return ERROR_FUNCTION_FAILED;
2413 /* create the treeview control */
2414 style = TVS_HASLINES | TVS_HASBUTTONS | TVS_LINESATROOT;
2415 style |= WS_GROUP | WS_VSCROLL;
2416 control = msi_dialog_add_control( dialog, rec, WC_TREEVIEWW, style );
2420 return ERROR_FUNCTION_FAILED;
2423 control->handler = msi_dialog_seltree_handler;
2424 control_name = MSI_RecordGetString( rec, 2 );
2425 control->attributes = MSI_RecordGetInteger( rec, 8 );
2426 prop = MSI_RecordGetString( rec, 9 );
2427 control->property = msi_dialog_dup_property( dialog, prop, FALSE );
2430 info->dialog = dialog;
2431 info->hwnd = control->hwnd;
2432 info->oldproc = (WNDPROC) SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
2433 (LONG_PTR)MSISelectionTree_WndProc );
2434 SetPropW( control->hwnd, szButtonData, info );
2436 ControlEvent_SubscribeToEvent( dialog->package, dialog,
2437 szSelectionPath, control_name, szProperty );
2440 msi_seltree_create_imagelist( control->hwnd );
2441 msi_seltree_add_child_features( package, control->hwnd, NULL, NULL );
2443 return ERROR_SUCCESS;
2446 /******************** Group Box ***************************************/
2448 static UINT msi_dialog_group_box( msi_dialog *dialog, MSIRECORD *rec )
2450 msi_control *control;
2453 style = BS_GROUPBOX | WS_CHILD | WS_GROUP;
2454 control = msi_dialog_add_control( dialog, rec, WC_BUTTONW, style );
2456 return ERROR_FUNCTION_FAILED;
2458 return ERROR_SUCCESS;
2461 /******************** List Box ***************************************/
2463 struct msi_listbox_info
2473 static LRESULT WINAPI MSIListBox_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
2475 struct msi_listbox_info *info;
2479 TRACE("%p %04x %08lx %08lx\n", hWnd, msg, wParam, lParam);
2481 info = GetPropW( hWnd, szButtonData );
2485 r = CallWindowProcW( info->oldproc, hWnd, msg, wParam, lParam );
2490 for (j = 0; j < info->num_items; j++)
2491 msi_free( info->items[j] );
2492 msi_free( info->items );
2494 RemovePropW( hWnd, szButtonData );
2501 static UINT msi_listbox_add_item( MSIRECORD *rec, LPVOID param )
2503 struct msi_listbox_info *info = param;
2504 LPCWSTR value, text;
2507 value = MSI_RecordGetString( rec, 3 );
2508 text = MSI_RecordGetString( rec, 4 );
2510 info->items[info->addpos_items] = strdupW( value );
2512 pos = SendMessageW( info->hwnd, LB_ADDSTRING, 0, (LPARAM)text );
2513 SendMessageW( info->hwnd, LB_SETITEMDATA, pos, (LPARAM)info->items[info->addpos_items] );
2514 info->addpos_items++;
2515 return ERROR_SUCCESS;
2518 static UINT msi_listbox_add_items( struct msi_listbox_info *info, LPCWSTR property )
2521 MSIQUERY *view = NULL;
2524 static const WCHAR query[] = {
2525 'S','E','L','E','C','T',' ','*',' ',
2526 'F','R','O','M',' ','`','L','i','s','t','B','o','x','`',' ',
2527 'W','H','E','R','E',' ',
2528 '`','P','r','o','p','e','r','t','y','`',' ','=',' ','\'','%','s','\'',' ',
2529 'O','R','D','E','R',' ','B','Y',' ','`','O','r','d','e','r','`',0
2532 r = MSI_OpenQuery( info->dialog->package->db, &view, query, property );
2533 if ( r != ERROR_SUCCESS )
2536 /* just get the number of records */
2538 r = MSI_IterateRecords( view, &count, NULL, NULL );
2540 info->num_items = count;
2541 info->items = msi_alloc( sizeof(*info->items) * count );
2543 r = MSI_IterateRecords( view, NULL, msi_listbox_add_item, info );
2544 msiobj_release( &view->hdr );
2549 static UINT msi_dialog_listbox_handler( msi_dialog *dialog,
2550 msi_control *control, WPARAM param )
2552 struct msi_listbox_info *info;
2556 if( HIWORD(param) != LBN_SELCHANGE )
2557 return ERROR_SUCCESS;
2559 info = GetPropW( control->hwnd, szButtonData );
2560 index = SendMessageW( control->hwnd, LB_GETCURSEL, 0, 0 );
2561 value = (LPCWSTR) SendMessageW( control->hwnd, LB_GETITEMDATA, index, 0 );
2563 msi_dialog_set_property( info->dialog->package, control->property, value );
2564 msi_dialog_evaluate_control_conditions( info->dialog );
2566 return ERROR_SUCCESS;
2569 static UINT msi_dialog_list_box( msi_dialog *dialog, MSIRECORD *rec )
2571 struct msi_listbox_info *info;
2572 msi_control *control;
2573 DWORD attributes, style;
2576 info = msi_alloc( sizeof *info );
2578 return ERROR_FUNCTION_FAILED;
2580 style = WS_TABSTOP | WS_GROUP | WS_CHILD | LBS_NOTIFY | WS_VSCROLL | WS_BORDER;
2581 attributes = MSI_RecordGetInteger( rec, 8 );
2582 if (~attributes & msidbControlAttributesSorted)
2585 control = msi_dialog_add_control( dialog, rec, WC_LISTBOXW, style );
2589 return ERROR_FUNCTION_FAILED;
2592 control->handler = msi_dialog_listbox_handler;
2594 prop = MSI_RecordGetString( rec, 9 );
2595 control->property = msi_dialog_dup_property( dialog, prop, FALSE );
2598 info->dialog = dialog;
2599 info->hwnd = control->hwnd;
2601 info->addpos_items = 0;
2602 info->oldproc = (WNDPROC)SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
2603 (LONG_PTR)MSIListBox_WndProc );
2604 SetPropW( control->hwnd, szButtonData, info );
2606 if ( control->property )
2607 msi_listbox_add_items( info, control->property );
2609 return ERROR_SUCCESS;
2612 /******************** Directory Combo ***************************************/
2614 static void msi_dialog_update_directory_combo( msi_dialog *dialog, msi_control *control )
2619 if (!control && !(control = msi_dialog_find_control_by_type( dialog, szDirectoryCombo )))
2622 indirect = control->attributes & msidbControlAttributesIndirect;
2623 prop = msi_dialog_dup_property( dialog, control->property, indirect );
2624 path = msi_dialog_dup_property( dialog, prop, TRUE );
2626 PathStripPathW( path );
2627 PathRemoveBackslashW( path );
2629 SendMessageW( control->hwnd, CB_INSERTSTRING, 0, (LPARAM)path );
2630 SendMessageW( control->hwnd, CB_SETCURSEL, 0, 0 );
2636 static UINT msi_dialog_directory_combo( msi_dialog *dialog, MSIRECORD *rec )
2638 msi_control *control;
2642 /* FIXME: use CBS_OWNERDRAWFIXED and add owner draw code */
2643 style = CBS_DROPDOWNLIST | CBS_HASSTRINGS | WS_CHILD |
2644 WS_GROUP | WS_TABSTOP | WS_VSCROLL;
2645 control = msi_dialog_add_control( dialog, rec, WC_COMBOBOXW, style );
2647 return ERROR_FUNCTION_FAILED;
2649 control->attributes = MSI_RecordGetInteger( rec, 8 );
2650 prop = MSI_RecordGetString( rec, 9 );
2651 control->property = msi_dialog_dup_property( dialog, prop, FALSE );
2653 msi_dialog_update_directory_combo( dialog, control );
2655 return ERROR_SUCCESS;
2658 /******************** Directory List ***************************************/
2660 static void msi_dialog_update_directory_list( msi_dialog *dialog, msi_control *control )
2662 WCHAR dir_spec[MAX_PATH];
2663 WIN32_FIND_DATAW wfd;
2669 static const WCHAR asterisk[] = {'*',0};
2671 if (!control && !(control = msi_dialog_find_control_by_type( dialog, szDirectoryList )))
2674 /* clear the list-view */
2675 SendMessageW( control->hwnd, LVM_DELETEALLITEMS, 0, 0 );
2677 indirect = control->attributes & msidbControlAttributesIndirect;
2678 prop = msi_dialog_dup_property( dialog, control->property, indirect );
2679 path = msi_dialog_dup_property( dialog, prop, TRUE );
2681 lstrcpyW( dir_spec, path );
2682 lstrcatW( dir_spec, asterisk );
2684 file = FindFirstFileW( dir_spec, &wfd );
2685 if ( file == INVALID_HANDLE_VALUE )
2690 if ( wfd.dwFileAttributes != FILE_ATTRIBUTE_DIRECTORY )
2693 if ( !strcmpW( wfd.cFileName, szDot ) || !strcmpW( wfd.cFileName, szDotDot ) )
2696 item.mask = LVIF_TEXT;
2697 item.cchTextMax = MAX_PATH;
2700 item.pszText = wfd.cFileName;
2702 SendMessageW( control->hwnd, LVM_INSERTITEMW, 0, (LPARAM)&item );
2703 } while ( FindNextFileW( file, &wfd ) );
2710 UINT msi_dialog_directorylist_up( msi_dialog *dialog )
2712 msi_control *control;
2713 LPWSTR prop, path, ptr;
2716 control = msi_dialog_find_control_by_type( dialog, szDirectoryList );
2717 indirect = control->attributes & msidbControlAttributesIndirect;
2718 prop = msi_dialog_dup_property( dialog, control->property, indirect );
2719 path = msi_dialog_dup_property( dialog, prop, TRUE );
2721 /* strip off the last directory */
2722 ptr = PathFindFileNameW( path );
2723 if (ptr != path) *(ptr - 1) = '\0';
2724 PathAddBackslashW( path );
2726 msi_dialog_set_property( dialog->package, prop, path );
2728 msi_dialog_update_directory_list( dialog, NULL );
2729 msi_dialog_update_directory_combo( dialog, NULL );
2730 msi_dialog_update_pathedit( dialog, NULL );
2735 return ERROR_SUCCESS;
2738 static UINT msi_dialog_dirlist_handler( msi_dialog *dialog,
2739 msi_control *control, WPARAM param )
2741 LPNMHDR nmhdr = (LPNMHDR)param;
2742 WCHAR new_path[MAX_PATH];
2743 WCHAR text[MAX_PATH];
2749 if (nmhdr->code != LVN_ITEMACTIVATE)
2750 return ERROR_SUCCESS;
2752 index = SendMessageW( control->hwnd, LVM_GETNEXTITEM, -1, LVNI_SELECTED );
2755 ERR("No list-view item selected!\n");
2756 return ERROR_FUNCTION_FAILED;
2760 item.pszText = text;
2761 item.cchTextMax = MAX_PATH;
2762 SendMessageW( control->hwnd, LVM_GETITEMTEXTW, index, (LPARAM)&item );
2764 indirect = control->attributes & msidbControlAttributesIndirect;
2765 prop = msi_dialog_dup_property( dialog, control->property, indirect );
2766 path = msi_dialog_dup_property( dialog, prop, TRUE );
2768 lstrcpyW( new_path, path );
2769 lstrcatW( new_path, text );
2770 lstrcatW( new_path, szBackSlash );
2772 msi_dialog_set_property( dialog->package, prop, new_path );
2774 msi_dialog_update_directory_list( dialog, NULL );
2775 msi_dialog_update_directory_combo( dialog, NULL );
2776 msi_dialog_update_pathedit( dialog, NULL );
2780 return ERROR_SUCCESS;
2783 static UINT msi_dialog_directory_list( msi_dialog *dialog, MSIRECORD *rec )
2785 msi_control *control;
2789 style = LVS_LIST | WS_VSCROLL | LVS_SHAREIMAGELISTS |
2790 LVS_AUTOARRANGE | LVS_SINGLESEL | WS_BORDER |
2791 LVS_SORTASCENDING | WS_CHILD | WS_GROUP | WS_TABSTOP;
2792 control = msi_dialog_add_control( dialog, rec, WC_LISTVIEWW, style );
2794 return ERROR_FUNCTION_FAILED;
2796 control->attributes = MSI_RecordGetInteger( rec, 8 );
2797 control->handler = msi_dialog_dirlist_handler;
2798 prop = MSI_RecordGetString( rec, 9 );
2799 control->property = msi_dialog_dup_property( dialog, prop, FALSE );
2801 /* double click to activate an item in the list */
2802 SendMessageW( control->hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE,
2803 0, LVS_EX_TWOCLICKACTIVATE );
2805 msi_dialog_update_directory_list( dialog, control );
2807 return ERROR_SUCCESS;
2810 /******************** VolumeCost List ***************************************/
2812 static BOOL str_is_number( LPCWSTR str )
2816 for (i = 0; i < lstrlenW( str ); i++)
2817 if (!isdigitW(str[i]))
2823 static const WCHAR column_keys[][80] =
2825 {'V','o','l','u','m','e','C','o','s','t','V','o','l','u','m','e',0},
2826 {'V','o','l','u','m','e','C','o','s','t','S','i','z','e',0},
2827 {'V','o','l','u','m','e','C','o','s','t','A','v','a','i','l','a','b','l','e',0},
2828 {'V','o','l','u','m','e','C','o','s','t','R','e','q','u','i','r','e','d',0},
2829 {'V','o','l','u','m','e','C','o','s','t','D','i','f','f','e','r','e','n','c','e',0}
2832 static void msi_dialog_vcl_add_columns( msi_dialog *dialog, msi_control *control, MSIRECORD *rec )
2834 LPCWSTR text = MSI_RecordGetString( rec, 10 );
2835 LPCWSTR begin = text, end;
2840 static const WCHAR negative[] = {'-',0};
2844 while ((begin = strchrW( begin, '{' )) && count < 5)
2846 if (!(end = strchrW( begin, '}' )))
2849 num = msi_alloc( (end-begin+1)*sizeof(WCHAR) );
2853 lstrcpynW( num, begin + 1, end - begin );
2854 begin += end - begin + 1;
2856 /* empty braces or '0' hides the column */
2857 if ( !num[0] || !strcmpW( num, szZero ) )
2864 /* the width must be a positive number
2865 * if a width is invalid, all remaining columns are hidden
2867 if ( !strncmpW( num, negative, 1 ) || !str_is_number( num ) ) {
2872 ZeroMemory( &lvc, sizeof(lvc) );
2873 lvc.mask = LVCF_TEXT | LVCF_WIDTH | LVCF_SUBITEM;
2874 lvc.cx = atolW( num );
2875 lvc.pszText = msi_dialog_get_uitext( dialog, column_keys[count] );
2877 SendMessageW( control->hwnd, LVM_INSERTCOLUMNW, count++, (LPARAM)&lvc );
2878 msi_free( lvc.pszText );
2883 static LONGLONG msi_vcl_get_cost( msi_dialog *dialog )
2885 MSIFEATURE *feature;
2887 LONGLONG total_cost = 0;
2889 LIST_FOR_EACH_ENTRY( feature, &dialog->package->features, MSIFEATURE, entry )
2891 if (ERROR_SUCCESS == (MSI_GetFeatureCost(dialog->package, feature,
2892 MSICOSTTREE_SELFONLY, INSTALLSTATE_LOCAL, &each_cost)))
2894 /* each_cost is in 512-byte units */
2895 total_cost += each_cost * 512;
2897 if (ERROR_SUCCESS == (MSI_GetFeatureCost(dialog->package, feature,
2898 MSICOSTTREE_SELFONLY, INSTALLSTATE_ABSENT, &each_cost)))
2900 /* each_cost is in 512-byte units */
2901 total_cost -= each_cost * 512;
2907 static void msi_dialog_vcl_add_drives( msi_dialog *dialog, msi_control *control )
2909 ULARGE_INTEGER total, free;
2910 LONGLONG difference, cost;
2911 WCHAR size_text[MAX_PATH];
2912 WCHAR cost_text[MAX_PATH];
2918 cost = msi_vcl_get_cost(dialog);
2919 StrFormatByteSizeW(cost, cost_text, MAX_PATH);
2921 size = GetLogicalDriveStringsW( 0, NULL );
2922 if ( !size ) return;
2924 drives = msi_alloc( (size + 1) * sizeof(WCHAR) );
2925 if ( !drives ) return;
2927 GetLogicalDriveStringsW( size, drives );
2932 lvitem.mask = LVIF_TEXT;
2934 lvitem.iSubItem = 0;
2935 lvitem.pszText = ptr;
2936 lvitem.cchTextMax = lstrlenW(ptr) + 1;
2937 SendMessageW( control->hwnd, LVM_INSERTITEMW, 0, (LPARAM)&lvitem );
2939 GetDiskFreeSpaceExW(ptr, &free, &total, NULL);
2940 difference = free.QuadPart - cost;
2942 StrFormatByteSizeW(total.QuadPart, size_text, MAX_PATH);
2943 lvitem.iSubItem = 1;
2944 lvitem.pszText = size_text;
2945 lvitem.cchTextMax = lstrlenW(size_text) + 1;
2946 SendMessageW( control->hwnd, LVM_SETITEMW, 0, (LPARAM)&lvitem );
2948 StrFormatByteSizeW(free.QuadPart, size_text, MAX_PATH);
2949 lvitem.iSubItem = 2;
2950 lvitem.pszText = size_text;
2951 lvitem.cchTextMax = lstrlenW(size_text) + 1;
2952 SendMessageW( control->hwnd, LVM_SETITEMW, 0, (LPARAM)&lvitem );
2954 lvitem.iSubItem = 3;
2955 lvitem.pszText = cost_text;
2956 lvitem.cchTextMax = lstrlenW(cost_text) + 1;
2957 SendMessageW( control->hwnd, LVM_SETITEMW, 0, (LPARAM)&lvitem );
2959 StrFormatByteSizeW(difference, size_text, MAX_PATH);
2960 lvitem.iSubItem = 4;
2961 lvitem.pszText = size_text;
2962 lvitem.cchTextMax = lstrlenW(size_text) + 1;
2963 SendMessageW( control->hwnd, LVM_SETITEMW, 0, (LPARAM)&lvitem );
2965 ptr += lstrlenW(ptr) + 1;
2972 static UINT msi_dialog_volumecost_list( msi_dialog *dialog, MSIRECORD *rec )
2974 msi_control *control;
2977 style = LVS_REPORT | WS_VSCROLL | WS_HSCROLL | LVS_SHAREIMAGELISTS |
2978 LVS_AUTOARRANGE | LVS_SINGLESEL | WS_BORDER |
2979 WS_CHILD | WS_TABSTOP | WS_GROUP;
2980 control = msi_dialog_add_control( dialog, rec, WC_LISTVIEWW, style );
2982 return ERROR_FUNCTION_FAILED;
2984 msi_dialog_vcl_add_columns( dialog, control, rec );
2985 msi_dialog_vcl_add_drives( dialog, control );
2987 return ERROR_SUCCESS;
2990 /******************** VolumeSelect Combo ***************************************/
2992 static UINT msi_dialog_volsel_handler( msi_dialog *dialog,
2993 msi_control *control, WPARAM param )
2995 WCHAR text[MAX_PATH];
3000 if (HIWORD(param) != CBN_SELCHANGE)
3001 return ERROR_SUCCESS;
3003 index = SendMessageW( control->hwnd, CB_GETCURSEL, 0, 0 );
3004 if ( index == CB_ERR )
3006 ERR("No ComboBox item selected!\n");
3007 return ERROR_FUNCTION_FAILED;
3010 SendMessageW( control->hwnd, CB_GETLBTEXT, index, (LPARAM)text );
3012 indirect = control->attributes & msidbControlAttributesIndirect;
3013 prop = msi_dialog_dup_property( dialog, control->property, indirect );
3015 msi_dialog_set_property( dialog->package, prop, text );
3018 return ERROR_SUCCESS;
3021 static void msi_dialog_vsc_add_drives( msi_dialog *dialog, msi_control *control )
3026 size = GetLogicalDriveStringsW( 0, NULL );
3027 if ( !size ) return;
3029 drives = msi_alloc( (size + 1) * sizeof(WCHAR) );
3030 if ( !drives ) return;
3032 GetLogicalDriveStringsW( size, drives );
3037 SendMessageW( control->hwnd, CB_ADDSTRING, 0, (LPARAM)ptr );
3038 ptr += lstrlenW(ptr) + 1;
3044 static UINT msi_dialog_volumeselect_combo( msi_dialog *dialog, MSIRECORD *rec )
3046 msi_control *control;
3050 /* FIXME: CBS_OWNERDRAWFIXED */
3051 style = WS_CHILD | WS_VISIBLE | WS_GROUP | WS_TABSTOP |
3052 CBS_DROPDOWNLIST | CBS_SORT | CBS_HASSTRINGS |
3053 WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_RIGHTSCROLLBAR;
3054 control = msi_dialog_add_control( dialog, rec, WC_COMBOBOXW, style );
3056 return ERROR_FUNCTION_FAILED;
3058 control->attributes = MSI_RecordGetInteger( rec, 8 );
3059 control->handler = msi_dialog_volsel_handler;
3060 prop = MSI_RecordGetString( rec, 9 );
3061 control->property = msi_dialog_dup_property( dialog, prop, FALSE );
3063 msi_dialog_vsc_add_drives( dialog, control );
3065 return ERROR_SUCCESS;
3068 static const struct control_handler msi_dialog_handler[] =
3070 { szText, msi_dialog_text_control },
3071 { szPushButton, msi_dialog_button_control },
3072 { szLine, msi_dialog_line_control },
3073 { szBitmap, msi_dialog_bitmap_control },
3074 { szCheckBox, msi_dialog_checkbox_control },
3075 { szScrollableText, msi_dialog_scrolltext_control },
3076 { szComboBox, msi_dialog_combo_control },
3077 { szEdit, msi_dialog_edit_control },
3078 { szMaskedEdit, msi_dialog_maskedit_control },
3079 { szPathEdit, msi_dialog_pathedit_control },
3080 { szProgressBar, msi_dialog_progress_bar },
3081 { szRadioButtonGroup, msi_dialog_radiogroup_control },
3082 { szIcon, msi_dialog_icon_control },
3083 { szSelectionTree, msi_dialog_selection_tree },
3084 { szGroupBox, msi_dialog_group_box },
3085 { szListBox, msi_dialog_list_box },
3086 { szDirectoryCombo, msi_dialog_directory_combo },
3087 { szDirectoryList, msi_dialog_directory_list },
3088 { szVolumeCostList, msi_dialog_volumecost_list },
3089 { szVolumeSelectCombo, msi_dialog_volumeselect_combo },
3092 #define NUM_CONTROL_TYPES (sizeof msi_dialog_handler/sizeof msi_dialog_handler[0])
3094 static UINT msi_dialog_create_controls( MSIRECORD *rec, LPVOID param )
3096 msi_dialog *dialog = param;
3097 LPCWSTR control_type;
3100 /* find and call the function that can create this type of control */
3101 control_type = MSI_RecordGetString( rec, 3 );
3102 for( i=0; i<NUM_CONTROL_TYPES; i++ )
3103 if (!strcmpiW( msi_dialog_handler[i].control_type, control_type ))
3105 if( i != NUM_CONTROL_TYPES )
3106 msi_dialog_handler[i].func( dialog, rec );
3108 ERR("no handler for element type %s\n", debugstr_w(control_type));
3110 return ERROR_SUCCESS;
3113 static UINT msi_dialog_fill_controls( msi_dialog *dialog )
3115 static const WCHAR query[] = {
3116 'S','E','L','E','C','T',' ','*',' ',
3117 'F','R','O','M',' ','C','o','n','t','r','o','l',' ',
3118 'W','H','E','R','E',' ',
3119 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',0};
3121 MSIQUERY *view = NULL;
3122 MSIPACKAGE *package = dialog->package;
3124 TRACE("%p %s\n", dialog, debugstr_w(dialog->name) );
3126 /* query the Control table for all the elements of the control */
3127 r = MSI_OpenQuery( package->db, &view, query, dialog->name );
3128 if( r != ERROR_SUCCESS )
3130 ERR("query failed for dialog %s\n", debugstr_w(dialog->name));
3131 return ERROR_INVALID_PARAMETER;
3134 r = MSI_IterateRecords( view, 0, msi_dialog_create_controls, dialog );
3135 msiobj_release( &view->hdr );
3140 static UINT msi_dialog_set_control_condition( MSIRECORD *rec, LPVOID param )
3142 static const WCHAR szHide[] = { 'H','i','d','e',0 };
3143 static const WCHAR szShow[] = { 'S','h','o','w',0 };
3144 static const WCHAR szDisable[] = { 'D','i','s','a','b','l','e',0 };
3145 static const WCHAR szEnable[] = { 'E','n','a','b','l','e',0 };
3146 static const WCHAR szDefault[] = { 'D','e','f','a','u','l','t',0 };
3147 msi_dialog *dialog = param;
3148 msi_control *control;
3149 LPCWSTR name, action, condition;
3152 name = MSI_RecordGetString( rec, 2 );
3153 action = MSI_RecordGetString( rec, 3 );
3154 condition = MSI_RecordGetString( rec, 4 );
3155 r = MSI_EvaluateConditionW( dialog->package, condition );
3156 control = msi_dialog_find_control( dialog, name );
3157 if( r == MSICONDITION_TRUE && control )
3159 TRACE("%s control %s\n", debugstr_w(action), debugstr_w(name));
3161 /* FIXME: case sensitive? */
3162 if (!strcmpW( action, szHide ))
3163 ShowWindow(control->hwnd, SW_HIDE);
3164 else if (!strcmpW( action, szShow ))
3165 ShowWindow(control->hwnd, SW_SHOW);
3166 else if (!strcmpW( action, szDisable ))
3167 EnableWindow(control->hwnd, FALSE);
3168 else if (!strcmpW( action, szEnable ))
3169 EnableWindow(control->hwnd, TRUE);
3170 else if (!strcmpW( action, szDefault ))
3171 SetFocus(control->hwnd);
3173 FIXME("Unhandled action %s\n", debugstr_w(action));
3176 return ERROR_SUCCESS;
3179 static UINT msi_dialog_evaluate_control_conditions( msi_dialog *dialog )
3181 static const WCHAR query[] = {
3182 'S','E','L','E','C','T',' ','*',' ',
3183 'F','R','O','M',' ',
3184 'C','o','n','t','r','o','l','C','o','n','d','i','t','i','o','n',' ',
3185 'W','H','E','R','E',' ',
3186 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',0
3189 MSIQUERY *view = NULL;
3190 MSIPACKAGE *package = dialog->package;
3192 TRACE("%p %s\n", dialog, debugstr_w(dialog->name) );
3194 /* query the Control table for all the elements of the control */
3195 r = MSI_OpenQuery( package->db, &view, query, dialog->name );
3196 if( r != ERROR_SUCCESS )
3197 return ERROR_SUCCESS;
3199 r = MSI_IterateRecords( view, 0, msi_dialog_set_control_condition, dialog );
3200 msiobj_release( &view->hdr );
3205 UINT msi_dialog_reset( msi_dialog *dialog )
3207 /* FIXME: should restore the original values of any properties we changed */
3208 return msi_dialog_evaluate_control_conditions( dialog );
3211 /* figure out the height of 10 point MS Sans Serif */
3212 static INT msi_dialog_get_sans_serif_height( HWND hwnd )
3214 static const WCHAR szSansSerif[] = {
3215 'M','S',' ','S','a','n','s',' ','S','e','r','i','f',0 };
3220 HFONT hFont, hOldFont;
3223 hdc = GetDC( hwnd );
3226 memset( &lf, 0, sizeof lf );
3227 lf.lfHeight = MulDiv(12, GetDeviceCaps(hdc, LOGPIXELSY), 72);
3228 strcpyW( lf.lfFaceName, szSansSerif );
3229 hFont = CreateFontIndirectW(&lf);
3232 hOldFont = SelectObject( hdc, hFont );
3233 r = GetTextMetricsW( hdc, &tm );
3235 height = tm.tmHeight;
3236 SelectObject( hdc, hOldFont );
3237 DeleteObject( hFont );
3239 ReleaseDC( hwnd, hdc );
3244 /* fetch the associated record from the Dialog table */
3245 static MSIRECORD *msi_get_dialog_record( msi_dialog *dialog )
3247 static const WCHAR query[] = {
3248 'S','E','L','E','C','T',' ','*',' ',
3249 'F','R','O','M',' ','D','i','a','l','o','g',' ',
3250 'W','H','E','R','E',' ',
3251 '`','D','i','a','l','o','g','`',' ','=',' ','\'','%','s','\'',0};
3252 MSIPACKAGE *package = dialog->package;
3253 MSIRECORD *rec = NULL;
3255 TRACE("%p %s\n", dialog, debugstr_w(dialog->name) );
3257 rec = MSI_QueryGetRecord( package->db, query, dialog->name );
3259 WARN("query failed for dialog %s\n", debugstr_w(dialog->name));
3264 static void msi_dialog_adjust_dialog_pos( msi_dialog *dialog, MSIRECORD *rec, LPRECT pos )
3266 static const WCHAR szScreenX[] = {'S','c','r','e','e','n','X',0};
3267 static const WCHAR szScreenY[] = {'S','c','r','e','e','n','Y',0};
3274 center.x = MSI_RecordGetInteger( rec, 2 );
3275 center.y = MSI_RecordGetInteger( rec, 3 );
3277 sz.cx = MSI_RecordGetInteger( rec, 4 );
3278 sz.cy = MSI_RecordGetInteger( rec, 5 );
3280 sz.cx = msi_dialog_scale_unit( dialog, sz.cx );
3281 sz.cy = msi_dialog_scale_unit( dialog, sz.cy );
3283 xres = msi_get_property_int( dialog->package->db, szScreenX, 0 );
3284 yres = msi_get_property_int( dialog->package->db, szScreenY, 0 );
3286 center.x = MulDiv( center.x, xres, 100 );
3287 center.y = MulDiv( center.y, yres, 100 );
3289 /* turn the client pos into the window rectangle */
3290 if (dialog->package->center_x && dialog->package->center_y)
3292 pos->left = dialog->package->center_x - sz.cx / 2.0;
3293 pos->right = pos->left + sz.cx;
3294 pos->top = dialog->package->center_y - sz.cy / 2.0;
3295 pos->bottom = pos->top + sz.cy;
3299 pos->left = center.x - sz.cx/2;
3300 pos->right = pos->left + sz.cx;
3301 pos->top = center.y - sz.cy/2;
3302 pos->bottom = pos->top + sz.cy;
3304 /* save the center */
3305 dialog->package->center_x = center.x;
3306 dialog->package->center_y = center.y;
3309 dialog->size.cx = sz.cx;
3310 dialog->size.cy = sz.cy;
3312 TRACE("%u %u %u %u\n", pos->left, pos->top, pos->right, pos->bottom);
3314 style = GetWindowLongPtrW( dialog->hwnd, GWL_STYLE );
3315 AdjustWindowRect( pos, style, FALSE );
3318 static void msi_dialog_set_tab_order( msi_dialog *dialog, LPCWSTR first )
3320 struct list tab_chain;
3321 msi_control *control;
3322 HWND prev = HWND_TOP;
3324 list_init( &tab_chain );
3325 if (!(control = msi_dialog_find_control( dialog, first ))) return;
3327 dialog->hWndFocus = control->hwnd;
3330 list_remove( &control->entry );
3331 list_add_tail( &tab_chain, &control->entry );
3332 if (!control->tabnext) break;
3333 control = msi_dialog_find_control( dialog, control->tabnext );
3336 LIST_FOR_EACH_ENTRY( control, &tab_chain, msi_control, entry )
3338 SetWindowPos( control->hwnd, prev, 0, 0, 0, 0,
3339 SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOREDRAW |
3340 SWP_NOREPOSITION | SWP_NOSENDCHANGING | SWP_NOSIZE );
3341 prev = control->hwnd;
3344 /* put them back on the main list */
3345 list_move_head( &dialog->controls, &tab_chain );
3348 static LRESULT msi_dialog_oncreate( HWND hwnd, LPCREATESTRUCTW cs )
3350 static const WCHAR df[] = {
3351 'D','e','f','a','u','l','t','U','I','F','o','n','t',0 };
3352 static const WCHAR dfv[] = {
3353 'M','S',' ','S','h','e','l','l',' ','D','l','g',0 };
3354 msi_dialog *dialog = cs->lpCreateParams;
3355 MSIRECORD *rec = NULL;
3356 LPWSTR title = NULL;
3359 TRACE("%p %p\n", dialog, dialog->package);
3361 dialog->hwnd = hwnd;
3362 SetWindowLongPtrW( hwnd, GWLP_USERDATA, (LONG_PTR) dialog );
3364 rec = msi_get_dialog_record( dialog );
3367 TRACE("No record found for dialog %s\n", debugstr_w(dialog->name));
3371 dialog->scale = msi_dialog_get_sans_serif_height(dialog->hwnd);
3373 msi_dialog_adjust_dialog_pos( dialog, rec, &pos );
3375 dialog->attributes = MSI_RecordGetInteger( rec, 6 );
3377 dialog->default_font = msi_dup_property( dialog->package->db, df );
3378 if (!dialog->default_font)
3380 dialog->default_font = strdupW(dfv);
3381 if (!dialog->default_font) return -1;
3384 title = msi_get_deformatted_field( dialog->package, rec, 7 );
3385 SetWindowTextW( hwnd, title );
3388 SetWindowPos( hwnd, 0, pos.left, pos.top,
3389 pos.right - pos.left, pos.bottom - pos.top,
3390 SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOREDRAW );
3392 msi_dialog_build_font_list( dialog );
3393 msi_dialog_fill_controls( dialog );
3394 msi_dialog_evaluate_control_conditions( dialog );
3395 msi_dialog_set_tab_order( dialog, MSI_RecordGetString( rec, 8 ) );
3396 msiobj_release( &rec->hdr );
3401 static UINT msi_dialog_send_event( msi_dialog *dialog, LPCWSTR event, LPCWSTR arg )
3403 LPWSTR event_fmt = NULL, arg_fmt = NULL;
3405 TRACE("Sending control event %s %s\n", debugstr_w(event), debugstr_w(arg));
3407 deformat_string( dialog->package, event, &event_fmt );
3408 deformat_string( dialog->package, arg, &arg_fmt );
3410 dialog->event_handler( dialog->package, event_fmt, arg_fmt, dialog );
3412 msi_free( event_fmt );
3413 msi_free( arg_fmt );
3415 return ERROR_SUCCESS;
3418 static UINT msi_dialog_set_property_event( msi_dialog *dialog, LPCWSTR event, LPCWSTR arg )
3420 static const WCHAR szNullArg[] = { '{','}',0 };
3421 LPWSTR p, prop, arg_fmt = NULL;
3424 len = strlenW(event);
3425 prop = msi_alloc( len*sizeof(WCHAR));
3426 strcpyW( prop, &event[1] );
3427 p = strchrW( prop, ']' );
3428 if( p && (p[1] == 0 || p[1] == ' ') )
3431 if( strcmpW( szNullArg, arg ) )
3432 deformat_string( dialog->package, arg, &arg_fmt );
3433 msi_dialog_set_property( dialog->package, prop, arg_fmt );
3434 msi_dialog_update_controls( dialog, prop );
3435 msi_free( arg_fmt );
3438 ERR("Badly formatted property string - what happens?\n");
3440 return ERROR_SUCCESS;
3443 static UINT msi_dialog_control_event( MSIRECORD *rec, LPVOID param )
3445 msi_dialog *dialog = param;
3446 LPCWSTR condition, event, arg;
3449 condition = MSI_RecordGetString( rec, 5 );
3450 r = MSI_EvaluateConditionW( dialog->package, condition );
3451 if( r == MSICONDITION_TRUE || r == MSICONDITION_NONE )
3453 event = MSI_RecordGetString( rec, 3 );
3454 arg = MSI_RecordGetString( rec, 4 );
3455 if( event[0] == '[' )
3456 msi_dialog_set_property_event( dialog, event, arg );
3458 msi_dialog_send_event( dialog, event, arg );
3461 return ERROR_SUCCESS;
3470 static UINT add_rec_to_list( MSIRECORD *rec, LPVOID param )
3472 struct rec_list *add_rec;
3473 struct list *records = param;
3475 msiobj_addref( &rec->hdr );
3477 add_rec = msi_alloc( sizeof( *add_rec ) );
3480 msiobj_release( &rec->hdr );
3481 return ERROR_OUTOFMEMORY;
3485 list_add_tail( records, &add_rec->entry );
3486 return ERROR_SUCCESS;
3489 static inline void remove_rec_from_list( struct rec_list *rec_entry )
3491 msiobj_release( &rec_entry->rec->hdr );
3492 list_remove( &rec_entry->entry );
3493 msi_free( rec_entry );
3496 static UINT msi_dialog_button_handler( msi_dialog *dialog,
3497 msi_control *control, WPARAM param )
3499 static const WCHAR query[] = {
3500 'S','E','L','E','C','T',' ','*',' ',
3501 'F','R','O','M',' ','C','o','n','t','r','o','l','E','v','e','n','t',' ',
3502 'W','H','E','R','E',' ',
3503 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',' ',
3505 '`','C','o','n','t','r','o','l','_','`',' ','=',' ','\'','%','s','\'',' ',
3506 'O','R','D','E','R',' ','B','Y',' ','`','O','r','d','e','r','i','n','g','`',0
3508 MSIQUERY *view = NULL;
3509 struct rec_list *rec_entry, *next;
3513 if( HIWORD(param) != BN_CLICKED )
3514 return ERROR_SUCCESS;
3516 list_init( &events );
3518 r = MSI_OpenQuery( dialog->package->db, &view, query,
3519 dialog->name, control->name );
3520 if( r != ERROR_SUCCESS )
3522 ERR("query failed\n");
3526 r = MSI_IterateRecords( view, 0, add_rec_to_list, &events );
3527 msiobj_release( &view->hdr );
3528 if (r != ERROR_SUCCESS)
3531 /* handle all SetProperty events first */
3532 LIST_FOR_EACH_ENTRY_SAFE( rec_entry, next, &events, struct rec_list, entry )
3534 LPCWSTR event = MSI_RecordGetString( rec_entry->rec, 3 );
3536 if ( event[0] != '[' )
3539 r = msi_dialog_control_event( rec_entry->rec, dialog );
3540 remove_rec_from_list( rec_entry );
3542 if ( r != ERROR_SUCCESS )
3546 /* handle all other events */
3547 LIST_FOR_EACH_ENTRY_SAFE( rec_entry, next, &events, struct rec_list, entry )
3549 r = msi_dialog_control_event( rec_entry->rec, dialog );
3550 remove_rec_from_list( rec_entry );
3552 if ( r != ERROR_SUCCESS )
3557 LIST_FOR_EACH_ENTRY_SAFE( rec_entry, next, &events, struct rec_list, entry )
3559 remove_rec_from_list( rec_entry );
3565 static UINT msi_dialog_get_checkbox_state( msi_dialog *dialog,
3566 msi_control *control )
3568 WCHAR state[2] = { 0 };
3571 msi_get_property( dialog->package->db, control->property, state, &sz );
3572 return state[0] ? 1 : 0;
3575 static void msi_dialog_set_checkbox_state( msi_dialog *dialog,
3576 msi_control *control, UINT state )
3578 static const WCHAR szState[] = { '1', 0 };
3581 /* if uncheck then the property is set to NULL */
3584 msi_dialog_set_property( dialog->package, control->property, NULL );
3588 /* check for a custom state */
3589 if (control->value && control->value[0])
3590 val = control->value;
3594 msi_dialog_set_property( dialog->package, control->property, val );
3597 static void msi_dialog_checkbox_sync_state( msi_dialog *dialog,
3598 msi_control *control )
3602 state = msi_dialog_get_checkbox_state( dialog, control );
3603 SendMessageW( control->hwnd, BM_SETCHECK,
3604 state ? BST_CHECKED : BST_UNCHECKED, 0 );
3607 static UINT msi_dialog_checkbox_handler( msi_dialog *dialog,
3608 msi_control *control, WPARAM param )
3612 if( HIWORD(param) != BN_CLICKED )
3613 return ERROR_SUCCESS;
3615 TRACE("clicked checkbox %s, set %s\n", debugstr_w(control->name),
3616 debugstr_w(control->property));
3618 state = msi_dialog_get_checkbox_state( dialog, control );
3619 state = state ? 0 : 1;
3620 msi_dialog_set_checkbox_state( dialog, control, state );
3621 msi_dialog_checkbox_sync_state( dialog, control );
3623 return msi_dialog_button_handler( dialog, control, param );
3626 static UINT msi_dialog_edit_handler( msi_dialog *dialog,
3627 msi_control *control, WPARAM param )
3631 if( HIWORD(param) != EN_CHANGE )
3632 return ERROR_SUCCESS;
3634 TRACE("edit %s contents changed, set %s\n", debugstr_w(control->name),
3635 debugstr_w(control->property));
3637 buf = msi_get_window_text( control->hwnd );
3638 msi_dialog_set_property( dialog->package, control->property, buf );
3641 return ERROR_SUCCESS;
3644 static UINT msi_dialog_radiogroup_handler( msi_dialog *dialog,
3645 msi_control *control, WPARAM param )
3647 if( HIWORD(param) != BN_CLICKED )
3648 return ERROR_SUCCESS;
3650 TRACE("clicked radio button %s, set %s\n", debugstr_w(control->name),
3651 debugstr_w(control->property));
3653 msi_dialog_set_property( dialog->package, control->property, control->name );
3655 return msi_dialog_button_handler( dialog, control, param );
3658 static LRESULT msi_dialog_oncommand( msi_dialog *dialog, WPARAM param, HWND hwnd )
3660 msi_control *control = NULL;
3662 TRACE("%p %p %08lx\n", dialog, hwnd, param);
3667 control = msi_dialog_find_control( dialog, dialog->control_default );
3669 case 2: /* escape */
3670 control = msi_dialog_find_control( dialog, dialog->control_cancel );
3673 control = msi_dialog_find_control_by_hwnd( dialog, hwnd );
3678 if( control->handler )
3680 control->handler( dialog, control, param );
3681 msi_dialog_evaluate_control_conditions( dialog );
3688 static LRESULT msi_dialog_onnotify( msi_dialog *dialog, LPARAM param )
3690 LPNMHDR nmhdr = (LPNMHDR) param;
3691 msi_control *control = msi_dialog_find_control_by_hwnd( dialog, nmhdr->hwndFrom );
3693 TRACE("%p %p\n", dialog, nmhdr->hwndFrom);
3695 if ( control && control->handler )
3696 control->handler( dialog, control, param );
3701 static void msi_dialog_setfocus( msi_dialog *dialog )
3703 HWND hwnd = dialog->hWndFocus;
3705 hwnd = GetNextDlgTabItem( dialog->hwnd, hwnd, TRUE);
3706 hwnd = GetNextDlgTabItem( dialog->hwnd, hwnd, FALSE);
3708 dialog->hWndFocus = hwnd;
3711 static LRESULT WINAPI MSIDialog_WndProc( HWND hwnd, UINT msg,
3712 WPARAM wParam, LPARAM lParam )
3714 msi_dialog *dialog = (LPVOID) GetWindowLongPtrW( hwnd, GWLP_USERDATA );
3716 TRACE("0x%04x\n", msg);
3721 dialog->package->center_x = LOWORD(lParam) + dialog->size.cx / 2.0;
3722 dialog->package->center_y = HIWORD(lParam) + dialog->size.cy / 2.0;
3726 return msi_dialog_oncreate( hwnd, (LPCREATESTRUCTW)lParam );
3729 return msi_dialog_oncommand( dialog, wParam, (HWND)lParam );
3732 if( LOWORD(wParam) == WA_INACTIVE )
3733 dialog->hWndFocus = GetFocus();
3735 msi_dialog_setfocus( dialog );
3739 msi_dialog_setfocus( dialog );
3742 /* bounce back to our subclassed static control */
3743 case WM_CTLCOLORSTATIC:
3744 return SendMessageW( (HWND) lParam, WM_CTLCOLORSTATIC, wParam, lParam );
3747 dialog->hwnd = NULL;
3750 return msi_dialog_onnotify( dialog, lParam );
3752 return DefWindowProcW(hwnd, msg, wParam, lParam);
3755 static BOOL CALLBACK msi_radioground_child_enum( HWND hWnd, LPARAM lParam )
3757 EnableWindow( hWnd, lParam );
3761 static LRESULT WINAPI MSIRadioGroup_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
3763 WNDPROC oldproc = (WNDPROC) GetPropW(hWnd, szButtonData);
3766 TRACE("hWnd %p msg %04x wParam 0x%08lx lParam 0x%08lx\n", hWnd, msg, wParam, lParam);
3768 if (msg == WM_COMMAND) /* Forward notifications to dialog */
3769 SendMessageW(GetParent(hWnd), msg, wParam, lParam);
3771 r = CallWindowProcW(oldproc, hWnd, msg, wParam, lParam);
3773 /* make sure the radio buttons show as disabled if the parent is disabled */
3774 if (msg == WM_ENABLE)
3775 EnumChildWindows( hWnd, msi_radioground_child_enum, wParam );
3780 static LRESULT WINAPI MSIHiddenWindowProc( HWND hwnd, UINT msg,
3781 WPARAM wParam, LPARAM lParam )
3783 msi_dialog *dialog = (msi_dialog*) lParam;
3785 TRACE("%d %p\n", msg, dialog);
3789 case WM_MSI_DIALOG_CREATE:
3790 return msi_dialog_run_message_loop( dialog );
3791 case WM_MSI_DIALOG_DESTROY:
3792 msi_dialog_destroy( dialog );
3795 return DefWindowProcW( hwnd, msg, wParam, lParam );
3798 static BOOL msi_dialog_register_class( void )
3802 ZeroMemory( &cls, sizeof cls );
3803 cls.lpfnWndProc = MSIDialog_WndProc;
3804 cls.hInstance = NULL;
3805 cls.hIcon = LoadIconW(0, (LPWSTR)IDI_APPLICATION);
3806 cls.hCursor = LoadCursorW(0, (LPWSTR)IDC_ARROW);
3807 cls.hbrBackground = (HBRUSH)(COLOR_3DFACE + 1);
3808 cls.lpszMenuName = NULL;
3809 cls.lpszClassName = szMsiDialogClass;
3811 if( !RegisterClassW( &cls ) )
3814 cls.lpfnWndProc = MSIHiddenWindowProc;
3815 cls.lpszClassName = szMsiHiddenWindow;
3817 if( !RegisterClassW( &cls ) )
3820 uiThreadId = GetCurrentThreadId();
3822 hMsiHiddenWindow = CreateWindowW( szMsiHiddenWindow, NULL, WS_OVERLAPPED,
3823 0, 0, 100, 100, NULL, NULL, NULL, NULL );
3824 if( !hMsiHiddenWindow )
3830 /* functions that interface to other modules within MSI */
3832 msi_dialog *msi_dialog_create( MSIPACKAGE* package,
3833 LPCWSTR szDialogName, msi_dialog *parent,
3834 msi_dialog_event_handler event_handler )
3836 MSIRECORD *rec = NULL;
3839 TRACE("%p %s\n", package, debugstr_w(szDialogName));
3841 if (!hMsiHiddenWindow)
3842 msi_dialog_register_class();
3844 /* allocate the structure for the dialog to use */
3845 dialog = msi_alloc_zero( sizeof *dialog + sizeof(WCHAR)*strlenW(szDialogName) );
3848 strcpyW( dialog->name, szDialogName );
3849 dialog->parent = parent;
3850 msiobj_addref( &package->hdr );
3851 dialog->package = package;
3852 dialog->event_handler = event_handler;
3853 dialog->finished = 0;
3854 list_init( &dialog->controls );
3855 list_init( &dialog->fonts );
3857 /* verify that the dialog exists */
3858 rec = msi_get_dialog_record( dialog );
3861 msiobj_release( &package->hdr );
3865 dialog->attributes = MSI_RecordGetInteger( rec, 6 );
3866 dialog->control_default = strdupW( MSI_RecordGetString( rec, 9 ) );
3867 dialog->control_cancel = strdupW( MSI_RecordGetString( rec, 10 ) );
3868 msiobj_release( &rec->hdr );
3873 static void msi_process_pending_messages( HWND hdlg )
3877 while( PeekMessageW( &msg, 0, 0, 0, PM_REMOVE ) )
3879 if( hdlg && IsDialogMessageW( hdlg, &msg ))
3881 TranslateMessage( &msg );
3882 DispatchMessageW( &msg );
3886 void msi_dialog_end_dialog( msi_dialog *dialog )
3888 TRACE("%p\n", dialog);
3889 dialog->finished = 1;
3890 PostMessageW(dialog->hwnd, WM_NULL, 0, 0);
3893 void msi_dialog_check_messages( HANDLE handle )
3897 /* in threads other than the UI thread, block */
3898 if( uiThreadId != GetCurrentThreadId() )
3901 WaitForSingleObject( handle, INFINITE );
3905 /* there's two choices for the UI thread */
3908 msi_process_pending_messages( NULL );
3914 * block here until somebody creates a new dialog or
3915 * the handle we're waiting on becomes ready
3917 r = MsgWaitForMultipleObjects( 1, &handle, 0, INFINITE, QS_ALLINPUT );
3918 if( r == WAIT_OBJECT_0 )
3923 UINT msi_dialog_run_message_loop( msi_dialog *dialog )
3928 if( uiThreadId != GetCurrentThreadId() )
3929 return SendMessageW( hMsiHiddenWindow, WM_MSI_DIALOG_CREATE, 0, (LPARAM) dialog );
3931 /* create the dialog window, don't show it yet */
3932 style = WS_OVERLAPPED;
3933 if( dialog->attributes & msidbDialogAttributesVisible )
3934 style |= WS_VISIBLE;
3936 hwnd = CreateWindowW( szMsiDialogClass, dialog->name, style,
3937 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
3938 NULL, NULL, NULL, dialog );
3941 ERR("Failed to create dialog %s\n", debugstr_w( dialog->name ));
3942 return ERROR_FUNCTION_FAILED;
3945 ShowWindow( hwnd, SW_SHOW );
3946 /* UpdateWindow( hwnd ); - and causes the transparent static controls not to paint */
3948 if( dialog->attributes & msidbDialogAttributesModal )
3950 while( !dialog->finished )
3952 MsgWaitForMultipleObjects( 0, NULL, 0, INFINITE, QS_ALLINPUT );
3953 msi_process_pending_messages( dialog->hwnd );
3957 return ERROR_IO_PENDING;
3959 return ERROR_SUCCESS;
3962 void msi_dialog_do_preview( msi_dialog *dialog )
3965 dialog->attributes |= msidbDialogAttributesVisible;
3966 dialog->attributes &= ~msidbDialogAttributesModal;
3967 msi_dialog_run_message_loop( dialog );
3970 void msi_dialog_destroy( msi_dialog *dialog )
3972 msi_font *font, *next;
3974 if( uiThreadId != GetCurrentThreadId() )
3976 SendMessageW( hMsiHiddenWindow, WM_MSI_DIALOG_DESTROY, 0, (LPARAM) dialog );
3981 ShowWindow( dialog->hwnd, SW_HIDE );
3984 DestroyWindow( dialog->hwnd );
3986 /* unsubscribe events */
3987 ControlEvent_CleanupDialogSubscriptions(dialog->package, dialog->name);
3989 /* destroy the list of controls */
3990 while( !list_empty( &dialog->controls ) )
3994 t = LIST_ENTRY( list_head( &dialog->controls ),
3995 msi_control, entry );
3996 msi_destroy_control( t );
3999 /* destroy the list of fonts */
4000 LIST_FOR_EACH_ENTRY_SAFE( font, next, &dialog->fonts, msi_font, entry )
4002 list_remove( &font->entry );
4003 DeleteObject( font->hfont );
4006 msi_free( dialog->default_font );
4008 msi_free( dialog->control_default );
4009 msi_free( dialog->control_cancel );
4010 msiobj_release( &dialog->package->hdr );
4011 dialog->package = NULL;
4015 void msi_dialog_unregister_class( void )
4017 DestroyWindow( hMsiHiddenWindow );
4018 hMsiHiddenWindow = NULL;
4019 UnregisterClassW( szMsiDialogClass, NULL );
4020 UnregisterClassW( szMsiHiddenWindow, NULL );
4024 static UINT error_dialog_handler(MSIPACKAGE *package, LPCWSTR event,
4025 LPCWSTR argument, msi_dialog* dialog)
4027 static const WCHAR end_dialog[] = {'E','n','d','D','i','a','l','o','g',0};
4028 static const WCHAR error_abort[] = {'E','r','r','o','r','A','b','o','r','t',0};
4029 static const WCHAR error_cancel[] = {'E','r','r','o','r','C','a','n','c','e','l',0};
4030 static const WCHAR error_no[] = {'E','r','r','o','r','N','o',0};
4031 static const WCHAR result_prop[] = {
4032 'M','S','I','E','r','r','o','r','D','i','a','l','o','g','R','e','s','u','l','t',0
4035 if ( strcmpW( event, end_dialog ) )
4036 return ERROR_SUCCESS;
4038 if ( !strcmpW( argument, error_abort ) || !strcmpW( argument, error_cancel ) ||
4039 !strcmpW( argument, error_no ) )
4041 msi_set_property( package->db, result_prop, error_abort );
4044 ControlEvent_CleanupSubscriptions(package);
4045 msi_dialog_end_dialog( dialog );
4047 return ERROR_SUCCESS;
4050 static UINT msi_error_dialog_set_error( MSIPACKAGE *package, LPWSTR error_dialog, LPWSTR error )
4054 static const WCHAR update[] =
4055 {'U','P','D','A','T','E',' ','`','C','o','n','t','r','o','l','`',' ',
4056 'S','E','T',' ','`','T','e','x','t','`',' ','=',' ','\'','%','s','\'',' ',
4057 'W','H','E','R','E', ' ','`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',' ',
4058 'A','N','D',' ','`','C','o','n','t','r','o','l','`',' ','=',' ',
4059 '\'','E','r','r','o','r','T','e','x','t','\'',0};
4061 row = MSI_QueryGetRecord( package->db, update, error, error_dialog );
4063 return ERROR_FUNCTION_FAILED;
4065 msiobj_release(&row->hdr);
4066 return ERROR_SUCCESS;
4069 UINT msi_spawn_error_dialog( MSIPACKAGE *package, LPWSTR error_dialog, LPWSTR error )
4072 WCHAR result[MAX_PATH];
4073 UINT r = ERROR_SUCCESS;
4074 DWORD size = MAX_PATH;
4077 static const WCHAR pn_prop[] = {'P','r','o','d','u','c','t','N','a','m','e',0};
4078 static const WCHAR title_fmt[] = {'%','s',' ','W','a','r','n','i','n','g',0};
4079 static const WCHAR error_abort[] = {'E','r','r','o','r','A','b','o','r','t',0};
4080 static const WCHAR result_prop[] = {
4081 'M','S','I','E','r','r','o','r','D','i','a','l','o','g','R','e','s','u','l','t',0
4084 if ( (msi_get_property_int( package->db, szUILevel, 0 ) & INSTALLUILEVEL_MASK) == INSTALLUILEVEL_NONE )
4085 return ERROR_SUCCESS;
4087 if ( !error_dialog )
4089 LPWSTR product_name = msi_dup_property( package->db, pn_prop );
4090 WCHAR title[MAX_PATH];
4092 sprintfW( title, title_fmt, product_name );
4093 res = MessageBoxW( NULL, error, title, MB_OKCANCEL | MB_ICONWARNING );
4095 msi_free( product_name );
4098 return ERROR_SUCCESS;
4100 return ERROR_FUNCTION_FAILED;
4103 r = msi_error_dialog_set_error( package, error_dialog, error );
4104 if ( r != ERROR_SUCCESS )
4107 dialog = msi_dialog_create( package, error_dialog, package->dialog,
4108 error_dialog_handler );
4110 return ERROR_FUNCTION_FAILED;
4112 dialog->finished = FALSE;
4113 r = msi_dialog_run_message_loop( dialog );
4114 if ( r != ERROR_SUCCESS )
4117 r = msi_get_property( package->db, result_prop, result, &size );
4118 if ( r != ERROR_SUCCESS)
4121 if ( !strcmpW( result, error_abort ) )
4122 r = ERROR_FUNCTION_FAILED;
4125 msi_dialog_destroy( dialog );