2 * Implementation of the Microsoft Installer (msi.dll)
4 * Copyright 2005 Mike McCormack for CodeWeavers
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #define NONAMELESSUNION
23 #define NONAMELESSSTRUCT
42 #include "wine/debug.h"
43 #include "wine/unicode.h"
45 WINE_DEFAULT_DEBUG_CHANNEL(msi);
48 extern HINSTANCE msi_hInstance;
50 struct msi_control_tag;
51 typedef struct msi_control_tag msi_control;
52 typedef UINT (*msi_handler)( msi_dialog *, msi_control *, WPARAM );
53 typedef void (*msi_update)( msi_dialog *, msi_control * );
55 struct msi_control_tag
68 float progress_current;
74 typedef struct msi_font_tag
76 struct msi_font_tag *next;
86 msi_dialog_event_handler event_handler;
96 LPWSTR control_default;
97 LPWSTR control_cancel;
101 typedef UINT (*msi_dialog_control_func)( msi_dialog *dialog, MSIRECORD *rec );
102 struct control_handler
104 LPCWSTR control_type;
105 msi_dialog_control_func func;
114 } radio_button_group_descr;
116 static const WCHAR szMsiDialogClass[] = {
117 'M','s','i','D','i','a','l','o','g','C','l','o','s','e','C','l','a','s','s',0
119 static const WCHAR szMsiHiddenWindow[] = {
120 'M','s','i','H','i','d','d','e','n','W','i','n','d','o','w',0 };
121 static const WCHAR szStatic[] = { 'S','t','a','t','i','c',0 };
122 static const WCHAR szButton[] = { 'B','U','T','T','O','N', 0 };
123 static const WCHAR szButtonData[] = { 'M','S','I','D','A','T','A',0 };
124 static const WCHAR szProgress[] = { 'P','r','o','g','r','e','s','s',0 };
125 static const WCHAR szText[] = { 'T','e','x','t',0 };
126 static const WCHAR szPushButton[] = { 'P','u','s','h','B','u','t','t','o','n',0 };
127 static const WCHAR szLine[] = { 'L','i','n','e',0 };
128 static const WCHAR szBitmap[] = { 'B','i','t','m','a','p',0 };
129 static const WCHAR szCheckBox[] = { 'C','h','e','c','k','B','o','x',0 };
130 static const WCHAR szScrollableText[] = {
131 'S','c','r','o','l','l','a','b','l','e','T','e','x','t',0 };
132 static const WCHAR szComboBox[] = { 'C','o','m','b','o','B','o','x',0 };
133 static const WCHAR szEdit[] = { 'E','d','i','t',0 };
134 static const WCHAR szMaskedEdit[] = { 'M','a','s','k','e','d','E','d','i','t',0 };
135 static const WCHAR szPathEdit[] = { 'P','a','t','h','E','d','i','t',0 };
136 static const WCHAR szProgressBar[] = {
137 'P','r','o','g','r','e','s','s','B','a','r',0 };
138 static const WCHAR szSetProgress[] = {
139 'S','e','t','P','r','o','g','r','e','s','s',0 };
140 static const WCHAR szRadioButtonGroup[] = {
141 'R','a','d','i','o','B','u','t','t','o','n','G','r','o','u','p',0 };
142 static const WCHAR szIcon[] = { 'I','c','o','n',0 };
143 static const WCHAR szSelectionTree[] = {
144 'S','e','l','e','c','t','i','o','n','T','r','e','e',0 };
145 static const WCHAR szGroupBox[] = { 'G','r','o','u','p','B','o','x',0 };
146 static const WCHAR szListBox[] = { 'L','i','s','t','B','o','x',0 };
147 static const WCHAR szDirectoryCombo[] = { 'D','i','r','e','c','t','o','r','y','C','o','m','b','o',0 };
148 static const WCHAR szDirectoryList[] = { 'D','i','r','e','c','t','o','r','y','L','i','s','t',0 };
149 static const WCHAR szVolumeCostList[] = { 'V','o','l','u','m','e','C','o','s','t','L','i','s','t',0 };
150 static const WCHAR szVolumeSelectCombo[] = { 'V','o','l','u','m','e','S','e','l','e','c','t','C','o','m','b','o',0 };
151 static const WCHAR szSelectionDescription[] = {'S','e','l','e','c','t','i','o','n','D','e','s','c','r','i','p','t','i','o','n',0};
152 static const WCHAR szSelectionPath[] = {'S','e','l','e','c','t','i','o','n','P','a','t','h',0};
153 static const WCHAR szProperty[] = {'P','r','o','p','e','r','t','y',0};
155 static UINT msi_dialog_checkbox_handler( msi_dialog *, msi_control *, WPARAM );
156 static void msi_dialog_checkbox_sync_state( msi_dialog *, msi_control * );
157 static UINT msi_dialog_button_handler( msi_dialog *, msi_control *, WPARAM );
158 static UINT msi_dialog_edit_handler( msi_dialog *, msi_control *, WPARAM );
159 static UINT msi_dialog_radiogroup_handler( msi_dialog *, msi_control *, WPARAM );
160 static UINT msi_dialog_evaluate_control_conditions( msi_dialog *dialog );
161 static LRESULT WINAPI MSIRadioGroup_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
162 static MSIFEATURE *msi_seltree_get_selected_feature( msi_control *control );
164 /* dialog sequencing */
166 #define WM_MSI_DIALOG_CREATE (WM_USER+0x100)
167 #define WM_MSI_DIALOG_DESTROY (WM_USER+0x101)
169 static DWORD uiThreadId;
170 static HWND hMsiHiddenWindow;
172 static INT msi_dialog_scale_unit( msi_dialog *dialog, INT val )
174 return MulDiv( val, dialog->scale, 12 );
177 static msi_control *msi_dialog_find_control( msi_dialog *dialog, LPCWSTR name )
179 msi_control *control;
185 LIST_FOR_EACH_ENTRY( control, &dialog->controls, msi_control, entry )
186 if( !strcmpW( control->name, name ) ) /* FIXME: case sensitive? */
191 static msi_control *msi_dialog_find_control_by_type( msi_dialog *dialog, LPCWSTR type )
193 msi_control *control;
199 LIST_FOR_EACH_ENTRY( control, &dialog->controls, msi_control, entry )
200 if( !strcmpW( control->type, type ) ) /* FIXME: case sensitive? */
205 static msi_control *msi_dialog_find_control_by_hwnd( msi_dialog *dialog, HWND hwnd )
207 msi_control *control;
211 LIST_FOR_EACH_ENTRY( control, &dialog->controls, msi_control, entry )
212 if( hwnd == control->hwnd )
217 static LPWSTR msi_get_deformatted_field( MSIPACKAGE *package, MSIRECORD *rec, int field )
219 LPCWSTR str = MSI_RecordGetString( rec, field );
223 deformat_string( package, str, &ret );
227 static LPWSTR msi_dialog_dup_property( msi_dialog *dialog, LPCWSTR property, BOOL indirect )
235 prop = msi_dup_property( dialog->package, property );
238 prop = strdupW( property );
243 msi_dialog *msi_dialog_get_parent( msi_dialog *dialog )
245 return dialog->parent;
248 LPWSTR msi_dialog_get_name( msi_dialog *dialog )
254 * msi_dialog_get_style
256 * Extract the {\style} string from the front of the text to display and
257 * update the pointer. Only the last style in a list is applied.
259 static LPWSTR msi_dialog_get_style( LPCWSTR p, LPCWSTR *rest )
270 while ((first = strchrW( p, '{' )) && (q = strchrW( first + 1, '}' )))
273 if( *p != '\\' && *p != '&' )
276 /* little bit of sanity checking to stop us getting confused with RTF */
277 for( i=++p; i<q; i++ )
278 if( *i == '}' || *i == '\\' )
288 ret = msi_alloc( len*sizeof(WCHAR) );
291 memcpy( ret, p, len*sizeof(WCHAR) );
296 static UINT msi_dialog_add_font( MSIRECORD *rec, LPVOID param )
298 msi_dialog *dialog = param;
305 /* create a font and add it to the list */
306 name = MSI_RecordGetString( rec, 1 );
307 font = msi_alloc( sizeof *font + strlenW( name )*sizeof (WCHAR) );
308 strcpyW( font->name, name );
309 font->next = dialog->font_list;
310 dialog->font_list = font;
312 font->color = MSI_RecordGetInteger( rec, 4 );
314 memset( &lf, 0, sizeof lf );
315 face = MSI_RecordGetString( rec, 2 );
316 lf.lfHeight = MSI_RecordGetInteger( rec, 3 );
317 style = MSI_RecordGetInteger( rec, 5 );
318 if( style & msidbTextStyleStyleBitsBold )
319 lf.lfWeight = FW_BOLD;
320 if( style & msidbTextStyleStyleBitsItalic )
322 if( style & msidbTextStyleStyleBitsUnderline )
323 lf.lfUnderline = TRUE;
324 if( style & msidbTextStyleStyleBitsStrike )
325 lf.lfStrikeOut = TRUE;
326 lstrcpynW( lf.lfFaceName, face, LF_FACESIZE );
328 /* adjust the height */
329 hdc = GetDC( dialog->hwnd );
332 lf.lfHeight = -MulDiv(lf.lfHeight, GetDeviceCaps(hdc, LOGPIXELSY), 72);
333 ReleaseDC( dialog->hwnd, hdc );
336 font->hfont = CreateFontIndirectW( &lf );
338 TRACE("Adding font style %s\n", debugstr_w(font->name) );
340 return ERROR_SUCCESS;
343 static msi_font *msi_dialog_find_font( msi_dialog *dialog, LPCWSTR name )
347 for( font = dialog->font_list; font; font = font->next )
348 if( !strcmpW( font->name, name ) ) /* FIXME: case sensitive? */
354 static UINT msi_dialog_set_font( msi_dialog *dialog, HWND hwnd, LPCWSTR name )
358 font = msi_dialog_find_font( dialog, name );
360 SendMessageW( hwnd, WM_SETFONT, (WPARAM) font->hfont, TRUE );
362 ERR("No font entry for %s\n", debugstr_w(name));
363 return ERROR_SUCCESS;
366 static UINT msi_dialog_build_font_list( msi_dialog *dialog )
368 static const WCHAR query[] = {
369 'S','E','L','E','C','T',' ','*',' ',
370 'F','R','O','M',' ','`','T','e','x','t','S','t','y','l','e','`',' ',0
373 MSIQUERY *view = NULL;
375 TRACE("dialog %p\n", dialog );
377 r = MSI_OpenQuery( dialog->package->db, &view, query );
378 if( r != ERROR_SUCCESS )
381 r = MSI_IterateRecords( view, NULL, msi_dialog_add_font, dialog );
382 msiobj_release( &view->hdr );
387 static void msi_destroy_control( msi_control *t )
389 list_remove( &t->entry );
390 /* leave dialog->hwnd - destroying parent destroys child windows */
391 msi_free( t->property );
392 msi_free( t->value );
394 DeleteObject( t->hBitmap );
396 DestroyIcon( t->hIcon );
397 msi_free( t->tabnext );
400 FreeLibrary( t->hDll );
404 static msi_control *msi_dialog_create_window( msi_dialog *dialog,
405 MSIRECORD *rec, DWORD exstyle, LPCWSTR szCls, LPCWSTR name, LPCWSTR text,
406 DWORD style, HWND parent )
408 DWORD x, y, width, height;
409 LPWSTR font = NULL, title_font = NULL;
410 LPCWSTR title = NULL;
411 msi_control *control;
415 control = msi_alloc( sizeof *control + strlenW(name)*sizeof(WCHAR) );
419 strcpyW( control->name, name );
420 list_add_tail( &dialog->controls, &control->entry );
421 control->handler = NULL;
422 control->update = NULL;
423 control->property = NULL;
424 control->value = NULL;
425 control->hBitmap = NULL;
426 control->hIcon = NULL;
427 control->hDll = NULL;
428 control->tabnext = strdupW( MSI_RecordGetString( rec, 11) );
429 control->type = strdupW( MSI_RecordGetString( rec, 3 ) );
430 control->progress_current = 0;
431 control->progress_max = 100;
433 x = MSI_RecordGetInteger( rec, 4 );
434 y = MSI_RecordGetInteger( rec, 5 );
435 width = MSI_RecordGetInteger( rec, 6 );
436 height = MSI_RecordGetInteger( rec, 7 );
438 x = msi_dialog_scale_unit( dialog, x );
439 y = msi_dialog_scale_unit( dialog, y );
440 width = msi_dialog_scale_unit( dialog, width );
441 height = msi_dialog_scale_unit( dialog, height );
445 deformat_string( dialog->package, text, &title_font );
446 font = msi_dialog_get_style( title_font, &title );
449 control->hwnd = CreateWindowExW( exstyle, szCls, title, style,
450 x, y, width, height, parent, NULL, NULL, NULL );
452 TRACE("Dialog %s control %s hwnd %p\n",
453 debugstr_w(dialog->name), debugstr_w(text), control->hwnd );
455 msi_dialog_set_font( dialog, control->hwnd,
456 font ? font : dialog->default_font );
458 msi_free( title_font );
464 static LPWSTR msi_dialog_get_uitext( msi_dialog *dialog, LPCWSTR key )
469 static const WCHAR query[] = {
470 's','e','l','e','c','t',' ','*',' ',
471 'f','r','o','m',' ','`','U','I','T','e','x','t','`',' ',
472 'w','h','e','r','e',' ','`','K','e','y','`',' ','=',' ','\'','%','s','\'',0
475 rec = MSI_QueryGetRecord( dialog->package->db, query, key );
476 if (!rec) return NULL;
477 text = strdupW( MSI_RecordGetString( rec, 2 ) );
478 msiobj_release( &rec->hdr );
482 static MSIRECORD *msi_get_binary_record( MSIDATABASE *db, LPCWSTR name )
484 static const WCHAR query[] = {
485 's','e','l','e','c','t',' ','*',' ',
486 'f','r','o','m',' ','B','i','n','a','r','y',' ',
487 'w','h','e','r','e',' ',
488 '`','N','a','m','e','`',' ','=',' ','\'','%','s','\'',0
491 return MSI_QueryGetRecord( db, query, name );
494 static LPWSTR msi_create_tmp_path(void)
500 r = GetTempPathW( MAX_PATH, tmp );
503 len = lstrlenW( tmp ) + 20;
504 path = msi_alloc( len * sizeof (WCHAR) );
507 r = GetTempFileNameW( tmp, szMsi, 0, path );
518 static HANDLE msi_load_image( MSIDATABASE *db, LPCWSTR name, UINT type,
519 UINT cx, UINT cy, UINT flags )
521 MSIRECORD *rec = NULL;
522 HANDLE himage = NULL;
526 TRACE("%p %s %u %u %08x\n", db, debugstr_w(name), cx, cy, flags);
528 tmp = msi_create_tmp_path();
532 rec = msi_get_binary_record( db, name );
535 r = MSI_RecordStreamToFile( rec, 2, tmp );
536 if( r == ERROR_SUCCESS )
538 himage = LoadImageW( 0, tmp, type, cx, cy, flags );
540 msiobj_release( &rec->hdr );
548 static HICON msi_load_icon( MSIDATABASE *db, LPCWSTR text, UINT attributes )
550 DWORD cx = 0, cy = 0, flags;
552 flags = LR_LOADFROMFILE | LR_DEFAULTSIZE;
553 if( attributes & msidbControlAttributesFixedSize )
555 flags &= ~LR_DEFAULTSIZE;
556 if( attributes & msidbControlAttributesIconSize16 )
561 if( attributes & msidbControlAttributesIconSize32 )
566 /* msidbControlAttributesIconSize48 handled by above logic */
568 return msi_load_image( db, text, IMAGE_ICON, cx, cy, flags );
571 static void msi_dialog_update_controls( msi_dialog *dialog, LPCWSTR property )
573 msi_control *control;
575 LIST_FOR_EACH_ENTRY( control, &dialog->controls, msi_control, entry )
577 if ( !lstrcmpW( control->property, property ) && control->update )
578 control->update( dialog, control );
582 /* called from the Control Event subscription code */
583 void msi_dialog_handle_event( msi_dialog* dialog, LPCWSTR control,
584 LPCWSTR attribute, MSIRECORD *rec )
587 LPCWSTR font_text, text = NULL;
590 ctrl = msi_dialog_find_control( dialog, control );
593 if( !lstrcmpW(attribute, szText) )
595 font_text = MSI_RecordGetString( rec , 1 );
596 font = msi_dialog_get_style( font_text, &text );
597 if (!text) text = szEmpty;
598 SetWindowTextW( ctrl->hwnd, text );
600 msi_dialog_check_messages( NULL );
602 else if( !lstrcmpW(attribute, szProgress) )
606 func = MSI_RecordGetInteger( rec , 1 );
607 val = MSI_RecordGetInteger( rec , 2 );
609 TRACE("progress: func %u, val %u\n", func, val);
614 ctrl->progress_max = val;
615 ctrl->progress_current = 0;
616 SendMessageW(ctrl->hwnd, PBM_SETRANGE, 0, MAKELPARAM(0,100));
617 SendMessageW(ctrl->hwnd, PBM_SETPOS, 0, 0);
619 case 1: /* FIXME: not sure what this is supposed to do */
622 ctrl->progress_current += val;
623 if (ctrl->progress_current > ctrl->progress_max)
624 ctrl->progress_current = ctrl->progress_max;
625 SendMessageW(ctrl->hwnd, PBM_SETPOS, MulDiv(100, ctrl->progress_current, ctrl->progress_max), 0);
628 FIXME("Unknown progress message %u\n", func);
632 else if ( !lstrcmpW(attribute, szProperty) )
634 MSIFEATURE *feature = msi_seltree_get_selected_feature( ctrl );
635 MSI_SetPropertyW( dialog->package, ctrl->property, feature->Directory );
637 else if ( !lstrcmpW(attribute, szSelectionPath) )
639 LPWSTR prop = msi_dialog_dup_property( dialog, ctrl->property, TRUE );
642 path = msi_dup_property( dialog->package, prop );
643 SetWindowTextW( ctrl->hwnd, path );
649 FIXME("Attribute %s not being set\n", debugstr_w(attribute));
654 static void msi_dialog_map_events(msi_dialog* dialog, LPCWSTR control)
656 static const WCHAR Query[] = {
657 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
658 '`','E','v','e','n','t','M','a','p','p','i','n','g','`',' ',
659 'W','H','E','R','E',' ',
660 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',' ',
662 '`','C','o','n','t','r','o','l','_','`',' ','=',' ','\'','%','s','\'',0
665 LPCWSTR event, attribute;
667 row = MSI_QueryGetRecord( dialog->package->db, Query, dialog->name, control );
671 event = MSI_RecordGetString( row, 3 );
672 attribute = MSI_RecordGetString( row, 4 );
673 ControlEvent_SubscribeToEvent( dialog->package, dialog, event, control, attribute );
674 msiobj_release( &row->hdr );
677 /* everything except radio buttons */
678 static msi_control *msi_dialog_add_control( msi_dialog *dialog,
679 MSIRECORD *rec, LPCWSTR szCls, DWORD style )
685 name = MSI_RecordGetString( rec, 2 );
686 attributes = MSI_RecordGetInteger( rec, 8 );
687 text = MSI_RecordGetString( rec, 10 );
689 TRACE("%s, %s, %08x, %s, %08x\n", debugstr_w(szCls), debugstr_w(name),
690 attributes, debugstr_w(text), style);
692 if( attributes & msidbControlAttributesVisible )
694 if( ~attributes & msidbControlAttributesEnabled )
695 style |= WS_DISABLED;
696 if( attributes & msidbControlAttributesSunken )
697 exstyle |= WS_EX_CLIENTEDGE;
699 msi_dialog_map_events(dialog, name);
701 return msi_dialog_create_window( dialog, rec, exstyle, szCls, name,
702 text, style, dialog->hwnd );
713 * we don't erase our own background,
714 * so we have to make sure that the parent window redraws first
716 static void msi_text_on_settext( HWND hWnd )
721 hParent = GetParent( hWnd );
722 GetWindowRect( hWnd, &rc );
723 MapWindowPoints( NULL, hParent, (LPPOINT) &rc, 2 );
724 InvalidateRect( hParent, &rc, TRUE );
727 static LRESULT WINAPI
728 MSIText_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
730 struct msi_text_info *info;
733 TRACE("%p %04x %08lx %08lx\n", hWnd, msg, wParam, lParam);
735 info = GetPropW(hWnd, szButtonData);
737 if( msg == WM_CTLCOLORSTATIC &&
738 ( info->attributes & msidbControlAttributesTransparent ) )
740 SetBkMode( (HDC)wParam, TRANSPARENT );
741 return (LRESULT) GetStockObject(NULL_BRUSH);
744 r = CallWindowProcW(info->oldproc, hWnd, msg, wParam, lParam);
746 SetTextColor( (HDC)wParam, info->font->color );
751 msi_text_on_settext( hWnd );
755 RemovePropW( hWnd, szButtonData );
762 static UINT msi_dialog_text_control( msi_dialog *dialog, MSIRECORD *rec )
764 msi_control *control;
765 struct msi_text_info *info;
766 LPCWSTR text, ptr, prop;
769 TRACE("%p %p\n", dialog, rec);
771 control = msi_dialog_add_control( dialog, rec, szStatic, SS_LEFT | WS_GROUP );
773 return ERROR_FUNCTION_FAILED;
775 info = msi_alloc( sizeof *info );
777 return ERROR_SUCCESS;
779 control->attributes = MSI_RecordGetInteger( rec, 8 );
780 prop = MSI_RecordGetString( rec, 9 );
781 control->property = msi_dialog_dup_property( dialog, prop, FALSE );
783 text = MSI_RecordGetString( rec, 10 );
784 font_name = msi_dialog_get_style( text, &ptr );
785 info->font = ( font_name ) ? msi_dialog_find_font( dialog, font_name ) : NULL;
786 msi_free( font_name );
788 info->attributes = MSI_RecordGetInteger( rec, 8 );
789 if( info->attributes & msidbControlAttributesTransparent )
790 SetWindowLongPtrW( control->hwnd, GWL_EXSTYLE, WS_EX_TRANSPARENT );
792 info->oldproc = (WNDPROC) SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
793 (LONG_PTR)MSIText_WndProc );
794 SetPropW( control->hwnd, szButtonData, info );
796 ControlEvent_SubscribeToEvent( dialog->package, dialog,
797 szSelectionPath, control->name, szSelectionPath );
799 return ERROR_SUCCESS;
802 static UINT msi_dialog_button_control( msi_dialog *dialog, MSIRECORD *rec )
804 msi_control *control;
805 UINT attributes, style;
808 TRACE("%p %p\n", dialog, rec);
811 attributes = MSI_RecordGetInteger( rec, 8 );
812 if( attributes & msidbControlAttributesIcon )
815 control = msi_dialog_add_control( dialog, rec, szButton, style );
817 return ERROR_FUNCTION_FAILED;
819 control->handler = msi_dialog_button_handler;
822 text = msi_get_deformatted_field( dialog->package, rec, 10 );
823 control->hIcon = msi_load_icon( dialog->package->db, text, attributes );
824 if( attributes & msidbControlAttributesIcon )
825 SendMessageW( control->hwnd, BM_SETIMAGE, IMAGE_ICON, (LPARAM) control->hIcon );
828 return ERROR_SUCCESS;
831 static LPWSTR msi_get_checkbox_value( msi_dialog *dialog, LPCWSTR prop )
833 static const WCHAR query[] = {
834 'S','E','L','E','C','T',' ','*',' ',
835 'F','R','O','M',' ','`','C','h','e','c','k','B','o','x','`',' ',
836 'W','H','E','R','E',' ',
837 '`','P','r','o','p','e','r','t','y','`',' ','=',' ',
840 MSIRECORD *rec = NULL;
843 /* find if there is a value associated with the checkbox */
844 rec = MSI_QueryGetRecord( dialog->package->db, query, prop );
848 ret = msi_get_deformatted_field( dialog->package, rec, 2 );
854 msiobj_release( &rec->hdr );
858 ret = msi_dup_property( dialog->package, prop );
868 static UINT msi_dialog_checkbox_control( msi_dialog *dialog, MSIRECORD *rec )
870 msi_control *control;
873 TRACE("%p %p\n", dialog, rec);
875 control = msi_dialog_add_control( dialog, rec, szButton,
876 BS_CHECKBOX | BS_MULTILINE | WS_TABSTOP );
877 control->handler = msi_dialog_checkbox_handler;
878 control->update = msi_dialog_checkbox_sync_state;
879 prop = MSI_RecordGetString( rec, 9 );
882 control->property = strdupW( prop );
883 control->value = msi_get_checkbox_value( dialog, prop );
884 TRACE("control %s value %s\n", debugstr_w(control->property),
885 debugstr_w(control->value));
887 msi_dialog_checkbox_sync_state( dialog, control );
889 return ERROR_SUCCESS;
892 static UINT msi_dialog_line_control( msi_dialog *dialog, MSIRECORD *rec )
896 DWORD style, exstyle = 0;
897 DWORD x, y, width, height;
898 msi_control *control;
900 TRACE("%p %p\n", dialog, rec);
902 style = WS_CHILD | SS_ETCHEDHORZ | SS_SUNKEN;
904 name = MSI_RecordGetString( rec, 2 );
905 attributes = MSI_RecordGetInteger( rec, 8 );
907 if( attributes & msidbControlAttributesVisible )
909 if( ~attributes & msidbControlAttributesEnabled )
910 style |= WS_DISABLED;
911 if( attributes & msidbControlAttributesSunken )
912 exstyle |= WS_EX_CLIENTEDGE;
914 msi_dialog_map_events(dialog, name);
916 control = msi_alloc( sizeof(*control) + strlenW(name) * sizeof(WCHAR) );
918 return ERROR_OUTOFMEMORY;
920 strcpyW( control->name, name );
921 list_add_head( &dialog->controls, &control->entry );
922 control->handler = NULL;
923 control->property = NULL;
924 control->value = NULL;
925 control->hBitmap = NULL;
926 control->hIcon = NULL;
927 control->hDll = NULL;
928 control->tabnext = strdupW( MSI_RecordGetString( rec, 11) );
929 control->type = strdupW( MSI_RecordGetString( rec, 3 ) );
930 control->progress_current = 0;
931 control->progress_max = 100;
933 x = MSI_RecordGetInteger( rec, 4 );
934 y = MSI_RecordGetInteger( rec, 5 );
935 width = MSI_RecordGetInteger( rec, 6 );
937 x = msi_dialog_scale_unit( dialog, x );
938 y = msi_dialog_scale_unit( dialog, y );
939 width = msi_dialog_scale_unit( dialog, width );
940 height = 2; /* line is exactly 2 units in height */
942 control->hwnd = CreateWindowExW( exstyle, szStatic, NULL, style,
943 x, y, width, height, dialog->hwnd, NULL, NULL, NULL );
945 TRACE("Dialog %s control %s hwnd %p\n",
946 debugstr_w(dialog->name), debugstr_w(name), control->hwnd );
948 return ERROR_SUCCESS;
951 /******************** Scroll Text ********************************************/
953 struct msi_scrolltext_info
956 msi_control *control;
960 static LRESULT WINAPI
961 MSIScrollText_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
963 struct msi_scrolltext_info *info;
966 TRACE("%p %04x %08lx %08lx\n", hWnd, msg, wParam, lParam);
968 info = GetPropW( hWnd, szButtonData );
970 r = CallWindowProcW( info->oldproc, hWnd, msg, wParam, lParam );
976 RemovePropW( hWnd, szButtonData );
979 /* native MSI sets a wait cursor here */
980 msi_dialog_button_handler( info->dialog, info->control, BN_CLICKED );
986 struct msi_streamin_info
993 static DWORD CALLBACK
994 msi_richedit_stream_in( DWORD_PTR arg, LPBYTE buffer, LONG count, LONG *pcb )
996 struct msi_streamin_info *info = (struct msi_streamin_info*) arg;
998 if( (count + info->offset) > info->length )
999 count = info->length - info->offset;
1000 memcpy( buffer, &info->string[ info->offset ], count );
1002 info->offset += count;
1004 TRACE("%d/%d\n", info->offset, info->length);
1009 static void msi_scrolltext_add_text( msi_control *control, LPCWSTR text )
1011 struct msi_streamin_info info;
1014 info.string = strdupWtoA( text );
1016 info.length = lstrlenA( info.string ) + 1;
1018 es.dwCookie = (DWORD_PTR) &info;
1020 es.pfnCallback = msi_richedit_stream_in;
1022 SendMessageW( control->hwnd, EM_STREAMIN, SF_RTF, (LPARAM) &es );
1024 msi_free( info.string );
1027 static UINT msi_dialog_scrolltext_control( msi_dialog *dialog, MSIRECORD *rec )
1029 static const WCHAR szRichEdit20W[] = {
1030 'R','i','c','h','E','d','i','t','2','0','W',0
1032 struct msi_scrolltext_info *info;
1033 msi_control *control;
1038 info = msi_alloc( sizeof *info );
1040 return ERROR_FUNCTION_FAILED;
1042 hRichedit = LoadLibraryA("riched20");
1044 style = WS_BORDER | ES_MULTILINE | WS_VSCROLL |
1045 ES_READONLY | ES_AUTOVSCROLL | WS_TABSTOP;
1046 control = msi_dialog_add_control( dialog, rec, szRichEdit20W, style );
1049 FreeLibrary( hRichedit );
1051 return ERROR_FUNCTION_FAILED;
1054 control->hDll = hRichedit;
1056 info->dialog = dialog;
1057 info->control = control;
1059 /* subclass the static control */
1060 info->oldproc = (WNDPROC) SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
1061 (LONG_PTR)MSIScrollText_WndProc );
1062 SetPropW( control->hwnd, szButtonData, info );
1064 /* add the text into the richedit */
1065 text = MSI_RecordGetString( rec, 10 );
1067 msi_scrolltext_add_text( control, text );
1069 return ERROR_SUCCESS;
1072 static HBITMAP msi_load_picture( MSIDATABASE *db, LPCWSTR name,
1073 INT cx, INT cy, DWORD flags )
1075 HBITMAP hOleBitmap = 0, hBitmap = 0, hOldSrcBitmap, hOldDestBitmap;
1076 MSIRECORD *rec = NULL;
1077 IStream *stm = NULL;
1078 IPicture *pic = NULL;
1083 rec = msi_get_binary_record( db, name );
1087 r = MSI_RecordGetIStream( rec, 2, &stm );
1088 msiobj_release( &rec->hdr );
1089 if( r != ERROR_SUCCESS )
1092 r = OleLoadPicture( stm, 0, TRUE, &IID_IPicture, (LPVOID*) &pic );
1093 IStream_Release( stm );
1096 ERR("failed to load picture\n");
1100 r = IPicture_get_Handle( pic, (OLE_HANDLE*) &hOleBitmap );
1103 ERR("failed to get bitmap handle\n");
1107 /* make the bitmap the desired size */
1108 r = GetObjectW( hOleBitmap, sizeof bm, &bm );
1109 if (r != sizeof bm )
1111 ERR("failed to get bitmap size\n");
1115 if (flags & LR_DEFAULTSIZE)
1121 srcdc = CreateCompatibleDC( NULL );
1122 hOldSrcBitmap = SelectObject( srcdc, hOleBitmap );
1123 destdc = CreateCompatibleDC( NULL );
1124 hBitmap = CreateCompatibleBitmap( srcdc, cx, cy );
1125 hOldDestBitmap = SelectObject( destdc, hBitmap );
1126 StretchBlt( destdc, 0, 0, cx, cy,
1127 srcdc, 0, 0, bm.bmWidth, bm.bmHeight, SRCCOPY);
1128 SelectObject( srcdc, hOldSrcBitmap );
1129 SelectObject( destdc, hOldDestBitmap );
1135 IPicture_Release( pic );
1139 static UINT msi_dialog_bitmap_control( msi_dialog *dialog, MSIRECORD *rec )
1141 UINT cx, cy, flags, style, attributes;
1142 msi_control *control;
1145 flags = LR_LOADFROMFILE;
1146 style = SS_BITMAP | SS_LEFT | WS_GROUP;
1148 attributes = MSI_RecordGetInteger( rec, 8 );
1149 if( attributes & msidbControlAttributesFixedSize )
1151 flags |= LR_DEFAULTSIZE;
1152 style |= SS_CENTERIMAGE;
1155 control = msi_dialog_add_control( dialog, rec, szStatic, style );
1156 cx = MSI_RecordGetInteger( rec, 6 );
1157 cy = MSI_RecordGetInteger( rec, 7 );
1158 cx = msi_dialog_scale_unit( dialog, cx );
1159 cy = msi_dialog_scale_unit( dialog, cy );
1161 text = msi_get_deformatted_field( dialog->package, rec, 10 );
1162 control->hBitmap = msi_load_picture( dialog->package->db, text, cx, cy, flags );
1163 if( control->hBitmap )
1164 SendMessageW( control->hwnd, STM_SETIMAGE,
1165 IMAGE_BITMAP, (LPARAM) control->hBitmap );
1167 ERR("Failed to load bitmap %s\n", debugstr_w(text));
1171 return ERROR_SUCCESS;
1174 static UINT msi_dialog_icon_control( msi_dialog *dialog, MSIRECORD *rec )
1176 msi_control *control;
1182 control = msi_dialog_add_control( dialog, rec, szStatic,
1183 SS_ICON | SS_CENTERIMAGE | WS_GROUP );
1185 attributes = MSI_RecordGetInteger( rec, 8 );
1186 text = msi_get_deformatted_field( dialog->package, rec, 10 );
1187 control->hIcon = msi_load_icon( dialog->package->db, text, attributes );
1188 if( control->hIcon )
1189 SendMessageW( control->hwnd, STM_SETICON, (WPARAM) control->hIcon, 0 );
1191 ERR("Failed to load bitmap %s\n", debugstr_w(text));
1193 return ERROR_SUCCESS;
1196 static UINT msi_dialog_combo_control( msi_dialog *dialog, MSIRECORD *rec )
1198 static const WCHAR szCombo[] = { 'C','O','M','B','O','B','O','X',0 };
1199 DWORD attributes, style;
1201 style = CBS_AUTOHSCROLL | WS_TABSTOP | WS_GROUP | WS_CHILD;
1202 attributes = MSI_RecordGetInteger( rec, 8 );
1203 if ( ~attributes & msidbControlAttributesSorted)
1205 if ( attributes & msidbControlAttributesComboList)
1206 style |= CBS_DROPDOWNLIST;
1208 style |= CBS_DROPDOWN;
1210 msi_dialog_add_control( dialog, rec, szCombo, style );
1211 return ERROR_SUCCESS;
1214 /* length of 2^32 + 1 */
1215 #define MAX_NUM_DIGITS 11
1217 static UINT msi_dialog_edit_control( msi_dialog *dialog, MSIRECORD *rec )
1219 msi_control *control;
1221 LPWSTR val, begin, end;
1222 WCHAR num[MAX_NUM_DIGITS];
1225 control = msi_dialog_add_control( dialog, rec, szEdit,
1226 WS_BORDER | WS_TABSTOP | ES_AUTOHSCROLL );
1227 control->handler = msi_dialog_edit_handler;
1229 text = MSI_RecordGetString( rec, 10 );
1232 begin = strchrW( text, '{' );
1233 end = strchrW( text, '}' );
1235 if ( begin && end && end > begin &&
1236 begin[0] >= '0' && begin[0] <= '9' &&
1237 end - begin < MAX_NUM_DIGITS)
1239 lstrcpynW( num, begin + 1, end - begin );
1240 limit = atolW( num );
1242 SendMessageW( control->hwnd, EM_SETLIMITTEXT, limit, 0 );
1246 prop = MSI_RecordGetString( rec, 9 );
1248 control->property = strdupW( prop );
1250 val = msi_dup_property( dialog->package, control->property );
1251 SetWindowTextW( control->hwnd, val );
1253 return ERROR_SUCCESS;
1256 /******************** Masked Edit ********************************************/
1258 #define MASK_MAX_GROUPS 20
1260 struct msi_mask_group
1268 struct msi_maskedit_info
1276 struct msi_mask_group group[MASK_MAX_GROUPS];
1279 static BOOL msi_mask_editable( WCHAR type )
1294 static void msi_mask_control_change( struct msi_maskedit_info *info )
1299 val = msi_alloc( (info->num_chars+1)*sizeof(WCHAR) );
1300 for( i=0, n=0; i<info->num_groups; i++ )
1302 if( (info->group[i].len + n) > info->num_chars )
1304 ERR("can't fit control %d text into template\n",i);
1307 if (!msi_mask_editable(info->group[i].type))
1309 for(r=0; r<info->group[i].len; r++)
1310 val[n+r] = info->group[i].type;
1315 r = GetWindowTextW( info->group[i].hwnd, &val[n], info->group[i].len+1 );
1316 if( r != info->group[i].len )
1322 TRACE("%d/%d controls were good\n", i, info->num_groups);
1324 if( i == info->num_groups )
1326 TRACE("Set property %s to %s\n",
1327 debugstr_w(info->prop), debugstr_w(val) );
1328 CharUpperBuffW( val, info->num_chars );
1329 MSI_SetPropertyW( info->dialog->package, info->prop, val );
1330 msi_dialog_evaluate_control_conditions( info->dialog );
1335 /* now move to the next control if necessary */
1336 static VOID msi_mask_next_control( struct msi_maskedit_info *info, HWND hWnd )
1341 for( i=0; i<info->num_groups; i++ )
1342 if( info->group[i].hwnd == hWnd )
1345 /* don't move from the last control */
1346 if( i >= (info->num_groups-1) )
1349 len = SendMessageW( hWnd, WM_GETTEXTLENGTH, 0, 0 );
1350 if( len < info->group[i].len )
1353 hWndNext = GetNextDlgTabItem( GetParent( hWnd ), hWnd, FALSE );
1354 SetFocus( hWndNext );
1357 static LRESULT WINAPI
1358 MSIMaskedEdit_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
1360 struct msi_maskedit_info *info;
1363 TRACE("%p %04x %08lx %08lx\n", hWnd, msg, wParam, lParam);
1365 info = GetPropW(hWnd, szButtonData);
1367 r = CallWindowProcW(info->oldproc, hWnd, msg, wParam, lParam);
1372 if (HIWORD(wParam) == EN_CHANGE)
1374 msi_mask_control_change( info );
1375 msi_mask_next_control( info, (HWND) lParam );
1379 msi_free( info->prop );
1381 RemovePropW( hWnd, szButtonData );
1388 /* fish the various bits of the property out and put them in the control */
1390 msi_maskedit_set_text( struct msi_maskedit_info *info, LPCWSTR text )
1396 for( i = 0; i < info->num_groups; i++ )
1398 if( info->group[i].len < strlenW( p ) )
1400 LPWSTR chunk = strdupW( p );
1401 chunk[ info->group[i].len ] = 0;
1402 SetWindowTextW( info->group[i].hwnd, chunk );
1407 SetWindowTextW( info->group[i].hwnd, p );
1410 p += info->group[i].len;
1414 static struct msi_maskedit_info * msi_dialog_parse_groups( LPCWSTR mask )
1416 struct msi_maskedit_info * info = NULL;
1417 int i = 0, n = 0, total = 0;
1420 TRACE("masked control, template %s\n", debugstr_w(mask));
1425 info = msi_alloc_zero( sizeof *info );
1429 p = strchrW(mask, '<');
1435 for( i=0; i<MASK_MAX_GROUPS; i++ )
1437 /* stop at the end of the string */
1438 if( p[0] == 0 || p[0] == '>' )
1441 /* count the number of the same identifier */
1442 for( n=0; p[n] == p[0]; n++ )
1444 info->group[i].ofs = total;
1445 info->group[i].type = p[0];
1449 total++; /* an extra not part of the group */
1451 info->group[i].len = n;
1456 TRACE("%d characters in %d groups\n", total, i );
1457 if( i == MASK_MAX_GROUPS )
1458 ERR("too many groups in PIDTemplate %s\n", debugstr_w(mask));
1460 info->num_chars = total;
1461 info->num_groups = i;
1467 msi_maskedit_create_children( struct msi_maskedit_info *info, LPCWSTR font )
1469 DWORD width, height, style, wx, ww;
1474 style = WS_CHILD | WS_BORDER | WS_VISIBLE | WS_TABSTOP | ES_AUTOHSCROLL;
1476 GetClientRect( info->hwnd, &rect );
1478 width = rect.right - rect.left;
1479 height = rect.bottom - rect.top;
1481 for( i = 0; i < info->num_groups; i++ )
1483 if (!msi_mask_editable( info->group[i].type ))
1485 wx = (info->group[i].ofs * width) / info->num_chars;
1486 ww = (info->group[i].len * width) / info->num_chars;
1488 hwnd = CreateWindowW( szEdit, NULL, style, wx, 0, ww, height,
1489 info->hwnd, NULL, NULL, NULL );
1492 ERR("failed to create mask edit sub window\n");
1496 SendMessageW( hwnd, EM_LIMITTEXT, info->group[i].len, 0 );
1498 msi_dialog_set_font( info->dialog, hwnd,
1499 font?font:info->dialog->default_font );
1500 info->group[i].hwnd = hwnd;
1505 * office 2003 uses "73931<````=````=````=````=`````>@@@@@"
1506 * delphi 7 uses "<????-??????-??????-????>" and "<???-???>"
1507 * filemaker pro 7 uses "<^^^^=^^^^=^^^^=^^^^=^^^^=^^^^=^^^^^>"
1509 static UINT msi_dialog_maskedit_control( msi_dialog *dialog, MSIRECORD *rec )
1511 LPWSTR font_mask, val = NULL, font;
1512 struct msi_maskedit_info *info = NULL;
1513 UINT ret = ERROR_SUCCESS;
1514 msi_control *control;
1519 font_mask = msi_get_deformatted_field( dialog->package, rec, 10 );
1520 font = msi_dialog_get_style( font_mask, &mask );
1523 ERR("mask template is empty\n");
1527 info = msi_dialog_parse_groups( mask );
1530 ERR("template %s is invalid\n", debugstr_w(mask));
1534 info->dialog = dialog;
1536 control = msi_dialog_add_control( dialog, rec, szStatic,
1537 SS_OWNERDRAW | WS_GROUP | WS_VISIBLE );
1540 ERR("Failed to create maskedit container\n");
1541 ret = ERROR_FUNCTION_FAILED;
1544 SetWindowLongPtrW( control->hwnd, GWL_EXSTYLE, WS_EX_CONTROLPARENT );
1546 info->hwnd = control->hwnd;
1548 /* subclass the static control */
1549 info->oldproc = (WNDPROC) SetWindowLongPtrW( info->hwnd, GWLP_WNDPROC,
1550 (LONG_PTR)MSIMaskedEdit_WndProc );
1551 SetPropW( control->hwnd, szButtonData, info );
1553 prop = MSI_RecordGetString( rec, 9 );
1555 info->prop = strdupW( prop );
1557 msi_maskedit_create_children( info, font );
1561 val = msi_dup_property( dialog->package, prop );
1564 msi_maskedit_set_text( info, val );
1570 if( ret != ERROR_SUCCESS )
1572 msi_free( font_mask );
1577 /******************** Progress Bar *****************************************/
1579 static UINT msi_dialog_progress_bar( msi_dialog *dialog, MSIRECORD *rec )
1581 msi_control *control;
1582 DWORD attributes, style;
1585 attributes = MSI_RecordGetInteger( rec, 8 );
1586 if( !(attributes & msidbControlAttributesProgress95) )
1587 style |= PBS_SMOOTH;
1589 control = msi_dialog_add_control( dialog, rec, PROGRESS_CLASSW, style );
1591 return ERROR_FUNCTION_FAILED;
1593 ControlEvent_SubscribeToEvent( dialog->package, dialog,
1594 szSetProgress, control->name, szProgress );
1595 return ERROR_SUCCESS;
1598 /******************** Path Edit ********************************************/
1600 struct msi_pathedit_info
1603 msi_control *control;
1607 static LPWSTR msi_get_window_text( HWND hwnd )
1613 buf = msi_alloc( sz*sizeof(WCHAR) );
1616 r = GetWindowTextW( hwnd, buf, sz );
1620 buf = msi_realloc( buf, sz*sizeof(WCHAR) );
1626 static void msi_dialog_update_pathedit( msi_dialog *dialog, msi_control *control )
1631 if (!control && !(control = msi_dialog_find_control_by_type( dialog, szPathEdit )))
1634 indirect = control->attributes & msidbControlAttributesIndirect;
1635 prop = msi_dialog_dup_property( dialog, control->property, indirect );
1636 path = msi_dialog_dup_property( dialog, prop, TRUE );
1638 SetWindowTextW( control->hwnd, path );
1639 SendMessageW( control->hwnd, EM_SETSEL, 0, -1 );
1645 /* FIXME: test when this should fail */
1646 static BOOL msi_dialog_verify_path( LPWSTR path )
1648 if ( !lstrlenW( path ) )
1651 if ( PathIsRelativeW( path ) )
1657 /* returns TRUE if the path is valid, FALSE otherwise */
1658 static BOOL msi_dialog_onkillfocus( msi_dialog *dialog, msi_control *control )
1664 indirect = control->attributes & msidbControlAttributesIndirect;
1665 prop = msi_dialog_dup_property( dialog, control->property, indirect );
1667 buf = msi_get_window_text( control->hwnd );
1669 if ( !msi_dialog_verify_path( buf ) )
1671 /* FIXME: display an error message box */
1672 ERR("Invalid path %s\n", debugstr_w( buf ));
1674 SetFocus( control->hwnd );
1679 MSI_SetPropertyW( dialog->package, prop, buf );
1682 msi_dialog_update_pathedit( dialog, control );
1684 TRACE("edit %s contents changed, set %s\n", debugstr_w(control->name),
1693 static LRESULT WINAPI MSIPathEdit_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
1695 struct msi_pathedit_info *info = GetPropW(hWnd, szButtonData);
1698 TRACE("%p %04x %08lx %08lx\n", hWnd, msg, wParam, lParam);
1700 if ( msg == WM_KILLFOCUS )
1702 /* if the path is invalid, don't handle this message */
1703 if ( !msi_dialog_onkillfocus( info->dialog, info->control ) )
1707 r = CallWindowProcW(info->oldproc, hWnd, msg, wParam, lParam);
1709 if ( msg == WM_NCDESTROY )
1712 RemovePropW( hWnd, szButtonData );
1718 static UINT msi_dialog_pathedit_control( msi_dialog *dialog, MSIRECORD *rec )
1720 struct msi_pathedit_info *info;
1721 msi_control *control;
1724 info = msi_alloc( sizeof *info );
1726 return ERROR_FUNCTION_FAILED;
1728 control = msi_dialog_add_control( dialog, rec, szEdit,
1729 WS_BORDER | WS_TABSTOP );
1730 control->attributes = MSI_RecordGetInteger( rec, 8 );
1731 prop = MSI_RecordGetString( rec, 9 );
1732 control->property = msi_dialog_dup_property( dialog, prop, FALSE );
1734 info->dialog = dialog;
1735 info->control = control;
1736 info->oldproc = (WNDPROC) SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
1737 (LONG_PTR)MSIPathEdit_WndProc );
1738 SetPropW( control->hwnd, szButtonData, info );
1740 msi_dialog_update_pathedit( dialog, control );
1742 return ERROR_SUCCESS;
1745 /* radio buttons are a bit different from normal controls */
1746 static UINT msi_dialog_create_radiobutton( MSIRECORD *rec, LPVOID param )
1748 radio_button_group_descr *group = param;
1749 msi_dialog *dialog = group->dialog;
1750 msi_control *control;
1751 LPCWSTR prop, text, name;
1752 DWORD style, attributes = group->attributes;
1754 style = WS_CHILD | BS_AUTORADIOBUTTON | BS_MULTILINE | WS_TABSTOP;
1755 name = MSI_RecordGetString( rec, 3 );
1756 text = MSI_RecordGetString( rec, 8 );
1757 if( attributes & msidbControlAttributesVisible )
1758 style |= WS_VISIBLE;
1759 if( ~attributes & msidbControlAttributesEnabled )
1760 style |= WS_DISABLED;
1762 control = msi_dialog_create_window( dialog, rec, 0, szButton, name, text,
1763 style, group->parent->hwnd );
1765 return ERROR_FUNCTION_FAILED;
1766 control->handler = msi_dialog_radiogroup_handler;
1768 if (!lstrcmpW(control->name, group->propval))
1769 SendMessageW(control->hwnd, BM_SETCHECK, BST_CHECKED, 0);
1771 prop = MSI_RecordGetString( rec, 1 );
1773 control->property = strdupW( prop );
1775 return ERROR_SUCCESS;
1778 static UINT msi_dialog_radiogroup_control( msi_dialog *dialog, MSIRECORD *rec )
1780 static const WCHAR query[] = {
1781 'S','E','L','E','C','T',' ','*',' ',
1782 'F','R','O','M',' ','R','a','d','i','o','B','u','t','t','o','n',' ',
1783 'W','H','E','R','E',' ',
1784 '`','P','r','o','p','e','r','t','y','`',' ','=',' ','\'','%','s','\'',0};
1787 msi_control *control;
1788 MSIQUERY *view = NULL;
1789 radio_button_group_descr group;
1790 MSIPACKAGE *package = dialog->package;
1792 DWORD attr, style = WS_GROUP;
1794 prop = MSI_RecordGetString( rec, 9 );
1796 TRACE("%p %p %s\n", dialog, rec, debugstr_w( prop ));
1798 attr = MSI_RecordGetInteger( rec, 8 );
1799 if (attr & msidbControlAttributesHasBorder)
1800 style |= BS_GROUPBOX;
1802 style |= BS_OWNERDRAW;
1804 /* Create parent group box to hold radio buttons */
1805 control = msi_dialog_add_control( dialog, rec, szButton, style );
1807 return ERROR_FUNCTION_FAILED;
1809 oldproc = (WNDPROC) SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
1810 (LONG_PTR)MSIRadioGroup_WndProc );
1811 SetPropW(control->hwnd, szButtonData, oldproc);
1812 SetWindowLongPtrW( control->hwnd, GWL_EXSTYLE, WS_EX_CONTROLPARENT );
1815 control->property = strdupW( prop );
1817 /* query the Radio Button table for all control in this group */
1818 r = MSI_OpenQuery( package->db, &view, query, prop );
1819 if( r != ERROR_SUCCESS )
1821 ERR("query failed for dialog %s radio group %s\n",
1822 debugstr_w(dialog->name), debugstr_w(prop));
1823 return ERROR_INVALID_PARAMETER;
1826 group.dialog = dialog;
1827 group.parent = control;
1828 group.attributes = MSI_RecordGetInteger( rec, 8 );
1829 group.propval = msi_dup_property( dialog->package, control->property );
1831 r = MSI_IterateRecords( view, 0, msi_dialog_create_radiobutton, &group );
1832 msiobj_release( &view->hdr );
1833 msi_free( group.propval );
1838 /******************** Selection Tree ***************************************/
1840 struct msi_selection_tree_info
1849 msi_seltree_sync_item_state( HWND hwnd, MSIFEATURE *feature, HTREEITEM hItem )
1852 DWORD index = feature->Action;
1854 TRACE("Feature %s -> %d %d %d\n", debugstr_w(feature->Title),
1855 feature->Installed, feature->Action, feature->ActionRequest);
1857 if (index == INSTALLSTATE_UNKNOWN)
1858 index = INSTALLSTATE_ABSENT;
1860 tvi.mask = TVIF_STATE;
1862 tvi.state = INDEXTOSTATEIMAGEMASK( index );
1863 tvi.stateMask = TVIS_STATEIMAGEMASK;
1865 SendMessageW( hwnd, TVM_SETITEMW, 0, (LPARAM) &tvi );
1869 msi_seltree_popup_menu( HWND hwnd, INT x, INT y )
1874 /* create a menu to display */
1875 hMenu = CreatePopupMenu();
1877 /* FIXME: load strings from resources */
1878 AppendMenuA( hMenu, MF_ENABLED, INSTALLSTATE_LOCAL, "Install feature locally");
1879 AppendMenuA( hMenu, MF_GRAYED, 0x1000, "Install entire feature");
1880 AppendMenuA( hMenu, MF_ENABLED, INSTALLSTATE_ADVERTISED, "Install on demand");
1881 AppendMenuA( hMenu, MF_ENABLED, INSTALLSTATE_ABSENT, "Don't install");
1882 r = TrackPopupMenu( hMenu, TPM_LEFTALIGN | TPM_TOPALIGN | TPM_RETURNCMD,
1883 x, y, 0, hwnd, NULL );
1884 DestroyMenu( hMenu );
1889 msi_seltree_feature_from_item( HWND hwnd, HTREEITEM hItem )
1893 /* get the feature from the item */
1894 memset( &tvi, 0, sizeof tvi );
1896 tvi.mask = TVIF_PARAM | TVIF_HANDLE;
1897 SendMessageW( hwnd, TVM_GETITEMW, 0, (LPARAM) &tvi );
1899 return (MSIFEATURE*) tvi.lParam;
1903 msi_seltree_menu( HWND hwnd, HTREEITEM hItem )
1905 struct msi_selection_tree_info *info;
1906 MSIFEATURE *feature;
1907 MSIPACKAGE *package;
1915 info = GetPropW(hwnd, szButtonData);
1916 package = info->dialog->package;
1918 feature = msi_seltree_feature_from_item( hwnd, hItem );
1921 ERR("item %p feature was NULL\n", hItem);
1925 /* get the item's rectangle to put the menu just below it */
1927 SendMessageW( hwnd, TVM_GETITEMRECT, 0, (LPARAM) &u.rc );
1928 MapWindowPoints( hwnd, NULL, u.pt, 2 );
1930 r = msi_seltree_popup_menu( hwnd, u.rc.left, u.rc.top );
1934 case INSTALLSTATE_LOCAL:
1935 case INSTALLSTATE_ADVERTISED:
1936 case INSTALLSTATE_ABSENT:
1937 msi_feature_set_state(package, feature, r);
1940 FIXME("select feature and all children\n");
1944 msi_seltree_sync_item_state( hwnd, feature, hItem );
1945 ACTION_UpdateComponentStates( package, feature->Feature );
1950 static MSIFEATURE *msi_seltree_get_selected_feature( msi_control *control )
1952 struct msi_selection_tree_info *info = GetPropW(control->hwnd, szButtonData);
1953 return msi_seltree_feature_from_item( control->hwnd, info->selected );
1956 static LRESULT WINAPI
1957 MSISelectionTree_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
1959 struct msi_selection_tree_info *info;
1960 TVHITTESTINFO tvhti;
1963 TRACE("%p %04x %08lx %08lx\n", hWnd, msg, wParam, lParam);
1965 info = GetPropW(hWnd, szButtonData);
1969 case WM_LBUTTONDOWN:
1970 tvhti.pt.x = (short)LOWORD( lParam );
1971 tvhti.pt.y = (short)HIWORD( lParam );
1974 r = CallWindowProcW(info->oldproc, hWnd, TVM_HITTEST, 0, (LPARAM) &tvhti );
1975 if (tvhti.flags & TVHT_ONITEMSTATEICON)
1976 return msi_seltree_menu( hWnd, tvhti.hItem );
1980 r = CallWindowProcW(info->oldproc, hWnd, msg, wParam, lParam);
1986 RemovePropW( hWnd, szButtonData );
1993 msi_seltree_add_child_features( MSIPACKAGE *package, HWND hwnd,
1994 LPCWSTR parent, HTREEITEM hParent )
1996 struct msi_selection_tree_info *info = GetPropW( hwnd, szButtonData );
1997 MSIFEATURE *feature;
1998 TVINSERTSTRUCTW tvis;
1999 HTREEITEM hitem, hfirst = NULL;
2001 LIST_FOR_EACH_ENTRY( feature, &package->features, MSIFEATURE, entry )
2003 if ( lstrcmpW( parent, feature->Feature_Parent ) )
2006 if ( !feature->Title )
2009 if ( !feature->Display )
2012 memset( &tvis, 0, sizeof tvis );
2013 tvis.hParent = hParent;
2014 tvis.hInsertAfter = TVI_LAST;
2015 tvis.u.item.mask = TVIF_TEXT | TVIF_PARAM;
2016 tvis.u.item.pszText = feature->Title;
2017 tvis.u.item.lParam = (LPARAM) feature;
2019 hitem = (HTREEITEM) SendMessageW( hwnd, TVM_INSERTITEMW, 0, (LPARAM) &tvis );
2026 msi_seltree_sync_item_state( hwnd, feature, hitem );
2027 msi_seltree_add_child_features( package, hwnd,
2028 feature->Feature, hitem );
2030 /* the node is expanded if Display is odd */
2031 if ( feature->Display % 2 != 0 )
2032 SendMessageW( hwnd, TVM_EXPAND, TVE_EXPAND, (LPARAM) hitem );
2035 /* select the first item */
2036 SendMessageW( hwnd, TVM_SELECTITEM, TVGN_CARET | TVGN_DROPHILITE, (LPARAM) hfirst );
2037 info->selected = hfirst;
2040 static void msi_seltree_create_imagelist( HWND hwnd )
2042 const int bm_width = 32, bm_height = 16, bm_count = 3;
2043 const int bm_resource = 0x1001;
2048 himl = ImageList_Create( bm_width, bm_height, FALSE, 4, 0 );
2051 ERR("failed to create image list\n");
2055 for (i=0; i<bm_count; i++)
2057 hbmp = LoadBitmapW( msi_hInstance, MAKEINTRESOURCEW(i+bm_resource) );
2060 ERR("failed to load bitmap %d\n", i);
2065 * Add a dummy bitmap at offset zero because the treeview
2066 * can't use it as a state mask (zero means no user state).
2069 ImageList_Add( himl, hbmp, NULL );
2071 ImageList_Add( himl, hbmp, NULL );
2074 SendMessageW( hwnd, TVM_SETIMAGELIST, TVSIL_STATE, (LPARAM)himl );
2077 static UINT msi_dialog_seltree_handler( msi_dialog *dialog,
2078 msi_control *control, WPARAM param )
2080 struct msi_selection_tree_info *info = GetPropW( control->hwnd, szButtonData );
2081 LPNMTREEVIEWW tv = (LPNMTREEVIEWW)param;
2082 MSIRECORD *row, *rec;
2084 MSIFEATURE *feature;
2085 LPCWSTR dir, title = NULL;
2086 UINT r = ERROR_SUCCESS;
2088 static const WCHAR select[] = {
2089 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2090 '`','F','e','a','t','u','r','e','`',' ','W','H','E','R','E',' ',
2091 '`','T','i','t','l','e','`',' ','=',' ','\'','%','s','\'',0
2094 if (tv->hdr.code != TVN_SELCHANGINGW)
2095 return ERROR_SUCCESS;
2097 info->selected = tv->itemNew.hItem;
2099 if (!(tv->itemNew.mask & TVIF_TEXT))
2101 feature = msi_seltree_feature_from_item( control->hwnd, tv->itemNew.hItem );
2103 title = feature->Title;
2106 title = tv->itemNew.pszText;
2108 row = MSI_QueryGetRecord( dialog->package->db, select, title );
2110 return ERROR_FUNCTION_FAILED;
2112 rec = MSI_CreateRecord( 1 );
2114 MSI_RecordSetStringW( rec, 1, MSI_RecordGetString( row, 4 ) );
2115 ControlEvent_FireSubscribedEvent( dialog->package, szSelectionDescription, rec );
2117 dir = MSI_RecordGetString( row, 7 );
2118 folder = get_loaded_folder( dialog->package, dir );
2121 r = ERROR_FUNCTION_FAILED;
2125 MSI_RecordSetStringW( rec, 1, folder->ResolvedTarget );
2126 ControlEvent_FireSubscribedEvent( dialog->package, szSelectionPath, rec );
2129 msiobj_release(&row->hdr);
2130 msiobj_release(&rec->hdr);
2135 static UINT msi_dialog_selection_tree( msi_dialog *dialog, MSIRECORD *rec )
2137 msi_control *control;
2139 MSIPACKAGE *package = dialog->package;
2141 struct msi_selection_tree_info *info;
2143 info = msi_alloc( sizeof *info );
2145 return ERROR_FUNCTION_FAILED;
2147 /* create the treeview control */
2148 style = TVS_HASLINES | TVS_HASBUTTONS | TVS_LINESATROOT;
2149 style |= WS_GROUP | WS_VSCROLL;
2150 control = msi_dialog_add_control( dialog, rec, WC_TREEVIEWW, style );
2154 return ERROR_FUNCTION_FAILED;
2157 control->handler = msi_dialog_seltree_handler;
2158 control->attributes = MSI_RecordGetInteger( rec, 8 );
2159 prop = MSI_RecordGetString( rec, 9 );
2160 control->property = msi_dialog_dup_property( dialog, prop, FALSE );
2163 info->dialog = dialog;
2164 info->hwnd = control->hwnd;
2165 info->oldproc = (WNDPROC) SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
2166 (LONG_PTR)MSISelectionTree_WndProc );
2167 SetPropW( control->hwnd, szButtonData, info );
2169 ControlEvent_SubscribeToEvent( dialog->package, dialog,
2170 szSelectionPath, control->name, szProperty );
2173 msi_seltree_create_imagelist( control->hwnd );
2174 msi_seltree_add_child_features( package, control->hwnd, NULL, NULL );
2176 return ERROR_SUCCESS;
2179 /******************** Group Box ***************************************/
2181 static UINT msi_dialog_group_box( msi_dialog *dialog, MSIRECORD *rec )
2183 msi_control *control;
2186 style = BS_GROUPBOX | WS_CHILD | WS_GROUP;
2187 control = msi_dialog_add_control( dialog, rec, WC_BUTTONW, style );
2189 return ERROR_FUNCTION_FAILED;
2191 return ERROR_SUCCESS;
2194 /******************** List Box ***************************************/
2196 struct msi_listbox_info
2206 static LRESULT WINAPI MSIListBox_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
2208 struct msi_listbox_info *info;
2212 TRACE("%p %04x %08lx %08lx\n", hWnd, msg, wParam, lParam);
2214 info = GetPropW( hWnd, szButtonData );
2218 r = CallWindowProcW( info->oldproc, hWnd, msg, wParam, lParam );
2223 for (j = 0; j < info->num_items; j++)
2224 msi_free( info->items[j] );
2225 msi_free( info->items );
2227 RemovePropW( hWnd, szButtonData );
2234 static UINT msi_listbox_add_item( MSIRECORD *rec, LPVOID param )
2236 struct msi_listbox_info *info = param;
2237 LPCWSTR value, text;
2240 value = MSI_RecordGetString( rec, 3 );
2241 text = MSI_RecordGetString( rec, 4 );
2243 info->items[info->addpos_items] = strdupW( value );
2245 pos = SendMessageW( info->hwnd, LB_ADDSTRING, 0, (LPARAM)text );
2246 SendMessageW( info->hwnd, LB_SETITEMDATA, pos, (LPARAM)info->items[info->addpos_items] );
2247 info->addpos_items++;
2248 return ERROR_SUCCESS;
2251 static UINT msi_listbox_add_items( struct msi_listbox_info *info, LPCWSTR property )
2254 MSIQUERY *view = NULL;
2257 static const WCHAR query[] = {
2258 'S','E','L','E','C','T',' ','*',' ',
2259 'F','R','O','M',' ','`','L','i','s','t','B','o','x','`',' ',
2260 'W','H','E','R','E',' ',
2261 '`','P','r','o','p','e','r','t','y','`',' ','=',' ','\'','%','s','\'',' ',
2262 'O','R','D','E','R',' ','B','Y',' ','`','O','r','d','e','r','`',0
2265 r = MSI_OpenQuery( info->dialog->package->db, &view, query, property );
2266 if ( r != ERROR_SUCCESS )
2269 /* just get the number of records */
2271 r = MSI_IterateRecords( view, &count, NULL, NULL );
2273 info->num_items = count;
2274 info->items = msi_alloc( sizeof(*info->items) * count );
2276 r = MSI_IterateRecords( view, NULL, msi_listbox_add_item, info );
2277 msiobj_release( &view->hdr );
2282 static UINT msi_dialog_listbox_handler( msi_dialog *dialog,
2283 msi_control *control, WPARAM param )
2285 struct msi_listbox_info *info;
2289 if( HIWORD(param) != LBN_SELCHANGE )
2290 return ERROR_SUCCESS;
2292 info = GetPropW( control->hwnd, szButtonData );
2293 index = SendMessageW( control->hwnd, LB_GETCURSEL, 0, 0 );
2294 value = (LPCWSTR) SendMessageW( control->hwnd, LB_GETITEMDATA, index, 0 );
2296 MSI_SetPropertyW( info->dialog->package,
2297 control->property, value );
2298 msi_dialog_evaluate_control_conditions( info->dialog );
2300 return ERROR_SUCCESS;
2303 static UINT msi_dialog_list_box( msi_dialog *dialog, MSIRECORD *rec )
2305 struct msi_listbox_info *info;
2306 msi_control *control;
2307 DWORD attributes, style;
2310 info = msi_alloc( sizeof *info );
2312 return ERROR_FUNCTION_FAILED;
2314 style = WS_TABSTOP | WS_GROUP | WS_CHILD | LBS_NOTIFY | WS_VSCROLL | WS_BORDER;
2315 attributes = MSI_RecordGetInteger( rec, 8 );
2316 if (~attributes & msidbControlAttributesSorted)
2319 control = msi_dialog_add_control( dialog, rec, WC_LISTBOXW, style );
2323 return ERROR_FUNCTION_FAILED;
2326 control->handler = msi_dialog_listbox_handler;
2328 prop = MSI_RecordGetString( rec, 9 );
2329 control->property = msi_dialog_dup_property( dialog, prop, FALSE );
2332 info->dialog = dialog;
2333 info->hwnd = control->hwnd;
2335 info->addpos_items = 0;
2336 info->oldproc = (WNDPROC)SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
2337 (LONG_PTR)MSIListBox_WndProc );
2338 SetPropW( control->hwnd, szButtonData, info );
2340 if ( control->property )
2341 msi_listbox_add_items( info, control->property );
2343 return ERROR_SUCCESS;
2346 /******************** Directory Combo ***************************************/
2348 static void msi_dialog_update_directory_combo( msi_dialog *dialog, msi_control *control )
2353 if (!control && !(control = msi_dialog_find_control_by_type( dialog, szDirectoryCombo )))
2356 indirect = control->attributes & msidbControlAttributesIndirect;
2357 prop = msi_dialog_dup_property( dialog, control->property, indirect );
2358 path = msi_dialog_dup_property( dialog, prop, TRUE );
2360 PathStripPathW( path );
2361 PathRemoveBackslashW( path );
2363 SendMessageW( control->hwnd, CB_INSERTSTRING, 0, (LPARAM)path );
2364 SendMessageW( control->hwnd, CB_SETCURSEL, 0, 0 );
2370 static UINT msi_dialog_directory_combo( msi_dialog *dialog, MSIRECORD *rec )
2372 msi_control *control;
2376 /* FIXME: use CBS_OWNERDRAWFIXED and add owner draw code */
2377 style = CBS_DROPDOWNLIST | CBS_HASSTRINGS | WS_CHILD |
2378 WS_GROUP | WS_TABSTOP | WS_VSCROLL;
2379 control = msi_dialog_add_control( dialog, rec, WC_COMBOBOXW, style );
2381 return ERROR_FUNCTION_FAILED;
2383 control->attributes = MSI_RecordGetInteger( rec, 8 );
2384 prop = MSI_RecordGetString( rec, 9 );
2385 control->property = msi_dialog_dup_property( dialog, prop, FALSE );
2387 msi_dialog_update_directory_combo( dialog, control );
2389 return ERROR_SUCCESS;
2392 /******************** Directory List ***************************************/
2394 static void msi_dialog_update_directory_list( msi_dialog *dialog, msi_control *control )
2396 WCHAR dir_spec[MAX_PATH];
2397 WIN32_FIND_DATAW wfd;
2403 static const WCHAR asterisk[] = {'*',0};
2405 if (!control && !(control = msi_dialog_find_control_by_type( dialog, szDirectoryList )))
2408 /* clear the list-view */
2409 SendMessageW( control->hwnd, LVM_DELETEALLITEMS, 0, 0 );
2411 indirect = control->attributes & msidbControlAttributesIndirect;
2412 prop = msi_dialog_dup_property( dialog, control->property, indirect );
2413 path = msi_dialog_dup_property( dialog, prop, TRUE );
2415 lstrcpyW( dir_spec, path );
2416 lstrcatW( dir_spec, asterisk );
2418 file = FindFirstFileW( dir_spec, &wfd );
2419 if ( file == INVALID_HANDLE_VALUE )
2424 if ( wfd.dwFileAttributes != FILE_ATTRIBUTE_DIRECTORY )
2427 if ( !lstrcmpW( wfd.cFileName, szDot ) || !lstrcmpW( wfd.cFileName, szDotDot ) )
2430 item.mask = LVIF_TEXT;
2431 item.cchTextMax = MAX_PATH;
2434 item.pszText = wfd.cFileName;
2436 SendMessageW( control->hwnd, LVM_INSERTITEMW, 0, (LPARAM)&item );
2437 } while ( FindNextFileW( file, &wfd ) );
2444 UINT msi_dialog_directorylist_up( msi_dialog *dialog )
2446 msi_control *control;
2447 LPWSTR prop, path, ptr;
2450 control = msi_dialog_find_control_by_type( dialog, szDirectoryList );
2451 indirect = control->attributes & msidbControlAttributesIndirect;
2452 prop = msi_dialog_dup_property( dialog, control->property, indirect );
2453 path = msi_dialog_dup_property( dialog, prop, TRUE );
2455 /* strip off the last directory */
2456 ptr = PathFindFileNameW( path );
2457 if (ptr != path) *(ptr - 1) = '\0';
2458 PathAddBackslashW( path );
2460 MSI_SetPropertyW( dialog->package, prop, path );
2462 msi_dialog_update_directory_list( dialog, NULL );
2463 msi_dialog_update_directory_combo( dialog, NULL );
2464 msi_dialog_update_pathedit( dialog, NULL );
2469 return ERROR_SUCCESS;
2472 static UINT msi_dialog_dirlist_handler( msi_dialog *dialog,
2473 msi_control *control, WPARAM param )
2475 LPNMHDR nmhdr = (LPNMHDR)param;
2476 WCHAR new_path[MAX_PATH];
2477 WCHAR text[MAX_PATH];
2483 if (nmhdr->code != LVN_ITEMACTIVATE)
2484 return ERROR_SUCCESS;
2486 index = SendMessageW( control->hwnd, LVM_GETNEXTITEM, -1, LVNI_SELECTED );
2489 ERR("No list-view item selected!\n");
2490 return ERROR_FUNCTION_FAILED;
2494 item.pszText = text;
2495 item.cchTextMax = MAX_PATH;
2496 SendMessageW( control->hwnd, LVM_GETITEMTEXTW, index, (LPARAM)&item );
2498 indirect = control->attributes & msidbControlAttributesIndirect;
2499 prop = msi_dialog_dup_property( dialog, control->property, indirect );
2500 path = msi_dialog_dup_property( dialog, prop, TRUE );
2502 lstrcpyW( new_path, path );
2503 lstrcatW( new_path, text );
2504 lstrcatW( new_path, szBackSlash );
2506 MSI_SetPropertyW( dialog->package, prop, new_path );
2508 msi_dialog_update_directory_list( dialog, NULL );
2509 msi_dialog_update_directory_combo( dialog, NULL );
2510 msi_dialog_update_pathedit( dialog, NULL );
2514 return ERROR_SUCCESS;
2517 static UINT msi_dialog_directory_list( msi_dialog *dialog, MSIRECORD *rec )
2519 msi_control *control;
2523 style = LVS_LIST | WS_VSCROLL | LVS_SHAREIMAGELISTS |
2524 LVS_AUTOARRANGE | LVS_SINGLESEL | WS_BORDER |
2525 LVS_SORTASCENDING | WS_CHILD | WS_GROUP | WS_TABSTOP;
2526 control = msi_dialog_add_control( dialog, rec, WC_LISTVIEWW, style );
2528 return ERROR_FUNCTION_FAILED;
2530 control->attributes = MSI_RecordGetInteger( rec, 8 );
2531 control->handler = msi_dialog_dirlist_handler;
2532 prop = MSI_RecordGetString( rec, 9 );
2533 control->property = msi_dialog_dup_property( dialog, prop, FALSE );
2535 /* double click to activate an item in the list */
2536 SendMessageW( control->hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE,
2537 0, LVS_EX_TWOCLICKACTIVATE );
2539 msi_dialog_update_directory_list( dialog, control );
2541 return ERROR_SUCCESS;
2544 /******************** VolumeCost List ***************************************/
2546 static BOOL str_is_number( LPCWSTR str )
2550 for (i = 0; i < lstrlenW( str ); i++)
2551 if (!isdigitW(str[i]))
2557 static const WCHAR column_keys[][80] =
2559 {'V','o','l','u','m','e','C','o','s','t','V','o','l','u','m','e',0},
2560 {'V','o','l','u','m','e','C','o','s','t','S','i','z','e',0},
2561 {'V','o','l','u','m','e','C','o','s','t','A','v','a','i','l','a','b','l','e',0},
2562 {'V','o','l','u','m','e','C','o','s','t','R','e','q','u','i','r','e','d',0},
2563 {'V','o','l','u','m','e','C','o','s','t','D','i','f','f','e','r','e','n','c','e',0}
2566 static void msi_dialog_vcl_add_columns( msi_dialog *dialog, msi_control *control, MSIRECORD *rec )
2568 LPCWSTR text = MSI_RecordGetString( rec, 10 );
2569 LPCWSTR begin = text, end;
2574 static const WCHAR negative[] = {'-',0};
2578 while ((begin = strchrW( begin, '{' )) && count < 5)
2580 if (!(end = strchrW( begin, '}' )))
2583 num = msi_alloc( (end-begin+1)*sizeof(WCHAR) );
2587 lstrcpynW( num, begin + 1, end - begin );
2588 begin += end - begin + 1;
2590 /* empty braces or '0' hides the column */
2591 if ( !num[0] || !lstrcmpW( num, szZero ) )
2598 /* the width must be a positive number
2599 * if a width is invalid, all remaining columns are hidden
2601 if ( !strncmpW( num, negative, 1 ) || !str_is_number( num ) ) {
2606 ZeroMemory( &lvc, sizeof(lvc) );
2607 lvc.mask = LVCF_TEXT | LVCF_WIDTH | LVCF_SUBITEM;
2608 lvc.cx = atolW( num );
2609 lvc.pszText = msi_dialog_get_uitext( dialog, column_keys[count] );
2611 SendMessageW( control->hwnd, LVM_INSERTCOLUMNW, count++, (LPARAM)&lvc );
2612 msi_free( lvc.pszText );
2617 static LONGLONG msi_vcl_get_cost( msi_dialog *dialog )
2619 MSIFEATURE *feature;
2621 LONGLONG total_cost = 0;
2623 LIST_FOR_EACH_ENTRY( feature, &dialog->package->features, MSIFEATURE, entry )
2625 if (ERROR_SUCCESS == (MSI_GetFeatureCost(dialog->package, feature,
2626 MSICOSTTREE_SELFONLY, INSTALLSTATE_LOCAL, &each_cost)))
2628 /* each_cost is in 512-byte units */
2629 total_cost += each_cost * 512;
2631 if (ERROR_SUCCESS == (MSI_GetFeatureCost(dialog->package, feature,
2632 MSICOSTTREE_SELFONLY, INSTALLSTATE_ABSENT, &each_cost)))
2634 /* each_cost is in 512-byte units */
2635 total_cost -= each_cost * 512;
2641 static void msi_dialog_vcl_add_drives( msi_dialog *dialog, msi_control *control )
2643 ULARGE_INTEGER total, free;
2644 LONGLONG difference, cost;
2645 WCHAR size_text[MAX_PATH];
2646 WCHAR cost_text[MAX_PATH];
2652 cost = msi_vcl_get_cost(dialog);
2653 StrFormatByteSizeW(cost, cost_text, MAX_PATH);
2655 size = GetLogicalDriveStringsW( 0, NULL );
2656 if ( !size ) return;
2658 drives = msi_alloc( (size + 1) * sizeof(WCHAR) );
2659 if ( !drives ) return;
2661 GetLogicalDriveStringsW( size, drives );
2666 lvitem.mask = LVIF_TEXT;
2668 lvitem.iSubItem = 0;
2669 lvitem.pszText = ptr;
2670 lvitem.cchTextMax = lstrlenW(ptr) + 1;
2671 SendMessageW( control->hwnd, LVM_INSERTITEMW, 0, (LPARAM)&lvitem );
2673 GetDiskFreeSpaceExW(ptr, &free, &total, NULL);
2674 difference = free.QuadPart - cost;
2676 StrFormatByteSizeW(total.QuadPart, size_text, MAX_PATH);
2677 lvitem.iSubItem = 1;
2678 lvitem.pszText = size_text;
2679 lvitem.cchTextMax = lstrlenW(size_text) + 1;
2680 SendMessageW( control->hwnd, LVM_SETITEMW, 0, (LPARAM)&lvitem );
2682 StrFormatByteSizeW(free.QuadPart, size_text, MAX_PATH);
2683 lvitem.iSubItem = 2;
2684 lvitem.pszText = size_text;
2685 lvitem.cchTextMax = lstrlenW(size_text) + 1;
2686 SendMessageW( control->hwnd, LVM_SETITEMW, 0, (LPARAM)&lvitem );
2688 lvitem.iSubItem = 3;
2689 lvitem.pszText = cost_text;
2690 lvitem.cchTextMax = lstrlenW(cost_text) + 1;
2691 SendMessageW( control->hwnd, LVM_SETITEMW, 0, (LPARAM)&lvitem );
2693 StrFormatByteSizeW(difference, size_text, MAX_PATH);
2694 lvitem.iSubItem = 4;
2695 lvitem.pszText = size_text;
2696 lvitem.cchTextMax = lstrlenW(size_text) + 1;
2697 SendMessageW( control->hwnd, LVM_SETITEMW, 0, (LPARAM)&lvitem );
2699 ptr += lstrlenW(ptr) + 1;
2706 static UINT msi_dialog_volumecost_list( msi_dialog *dialog, MSIRECORD *rec )
2708 msi_control *control;
2711 style = LVS_REPORT | WS_VSCROLL | WS_HSCROLL | LVS_SHAREIMAGELISTS |
2712 LVS_AUTOARRANGE | LVS_SINGLESEL | WS_BORDER |
2713 WS_CHILD | WS_TABSTOP | WS_GROUP;
2714 control = msi_dialog_add_control( dialog, rec, WC_LISTVIEWW, style );
2716 return ERROR_FUNCTION_FAILED;
2718 msi_dialog_vcl_add_columns( dialog, control, rec );
2719 msi_dialog_vcl_add_drives( dialog, control );
2721 return ERROR_SUCCESS;
2724 /******************** VolumeSelect Combo ***************************************/
2726 static UINT msi_dialog_volsel_handler( msi_dialog *dialog,
2727 msi_control *control, WPARAM param )
2729 WCHAR text[MAX_PATH];
2734 if (HIWORD(param) != CBN_SELCHANGE)
2735 return ERROR_SUCCESS;
2737 index = SendMessageW( control->hwnd, CB_GETCURSEL, 0, 0 );
2738 if ( index == CB_ERR )
2740 ERR("No ComboBox item selected!\n");
2741 return ERROR_FUNCTION_FAILED;
2744 SendMessageW( control->hwnd, CB_GETLBTEXT, index, (LPARAM)text );
2746 indirect = control->attributes & msidbControlAttributesIndirect;
2747 prop = msi_dialog_dup_property( dialog, control->property, indirect );
2749 MSI_SetPropertyW( dialog->package, prop, text );
2752 return ERROR_SUCCESS;
2755 static void msi_dialog_vsc_add_drives( msi_dialog *dialog, msi_control *control )
2760 size = GetLogicalDriveStringsW( 0, NULL );
2761 if ( !size ) return;
2763 drives = msi_alloc( (size + 1) * sizeof(WCHAR) );
2764 if ( !drives ) return;
2766 GetLogicalDriveStringsW( size, drives );
2771 SendMessageW( control->hwnd, CB_ADDSTRING, 0, (LPARAM)ptr );
2772 ptr += lstrlenW(ptr) + 1;
2778 static UINT msi_dialog_volumeselect_combo( msi_dialog *dialog, MSIRECORD *rec )
2780 msi_control *control;
2784 /* FIXME: CBS_OWNERDRAWFIXED */
2785 style = WS_CHILD | WS_VISIBLE | WS_GROUP | WS_TABSTOP |
2786 CBS_DROPDOWNLIST | CBS_SORT | CBS_HASSTRINGS |
2787 WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_RIGHTSCROLLBAR;
2788 control = msi_dialog_add_control( dialog, rec, WC_COMBOBOXW, style );
2790 return ERROR_FUNCTION_FAILED;
2792 control->attributes = MSI_RecordGetInteger( rec, 8 );
2793 control->handler = msi_dialog_volsel_handler;
2794 prop = MSI_RecordGetString( rec, 9 );
2795 control->property = msi_dialog_dup_property( dialog, prop, FALSE );
2797 msi_dialog_vsc_add_drives( dialog, control );
2799 return ERROR_SUCCESS;
2802 static const struct control_handler msi_dialog_handler[] =
2804 { szText, msi_dialog_text_control },
2805 { szPushButton, msi_dialog_button_control },
2806 { szLine, msi_dialog_line_control },
2807 { szBitmap, msi_dialog_bitmap_control },
2808 { szCheckBox, msi_dialog_checkbox_control },
2809 { szScrollableText, msi_dialog_scrolltext_control },
2810 { szComboBox, msi_dialog_combo_control },
2811 { szEdit, msi_dialog_edit_control },
2812 { szMaskedEdit, msi_dialog_maskedit_control },
2813 { szPathEdit, msi_dialog_pathedit_control },
2814 { szProgressBar, msi_dialog_progress_bar },
2815 { szRadioButtonGroup, msi_dialog_radiogroup_control },
2816 { szIcon, msi_dialog_icon_control },
2817 { szSelectionTree, msi_dialog_selection_tree },
2818 { szGroupBox, msi_dialog_group_box },
2819 { szListBox, msi_dialog_list_box },
2820 { szDirectoryCombo, msi_dialog_directory_combo },
2821 { szDirectoryList, msi_dialog_directory_list },
2822 { szVolumeCostList, msi_dialog_volumecost_list },
2823 { szVolumeSelectCombo, msi_dialog_volumeselect_combo },
2826 #define NUM_CONTROL_TYPES (sizeof msi_dialog_handler/sizeof msi_dialog_handler[0])
2828 static UINT msi_dialog_create_controls( MSIRECORD *rec, LPVOID param )
2830 msi_dialog *dialog = param;
2831 LPCWSTR control_type;
2834 /* find and call the function that can create this type of control */
2835 control_type = MSI_RecordGetString( rec, 3 );
2836 for( i=0; i<NUM_CONTROL_TYPES; i++ )
2837 if (!strcmpiW( msi_dialog_handler[i].control_type, control_type ))
2839 if( i != NUM_CONTROL_TYPES )
2840 msi_dialog_handler[i].func( dialog, rec );
2842 ERR("no handler for element type %s\n", debugstr_w(control_type));
2844 return ERROR_SUCCESS;
2847 static UINT msi_dialog_fill_controls( msi_dialog *dialog )
2849 static const WCHAR query[] = {
2850 'S','E','L','E','C','T',' ','*',' ',
2851 'F','R','O','M',' ','C','o','n','t','r','o','l',' ',
2852 'W','H','E','R','E',' ',
2853 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',0};
2855 MSIQUERY *view = NULL;
2856 MSIPACKAGE *package = dialog->package;
2858 TRACE("%p %s\n", dialog, debugstr_w(dialog->name) );
2860 /* query the Control table for all the elements of the control */
2861 r = MSI_OpenQuery( package->db, &view, query, dialog->name );
2862 if( r != ERROR_SUCCESS )
2864 ERR("query failed for dialog %s\n", debugstr_w(dialog->name));
2865 return ERROR_INVALID_PARAMETER;
2868 r = MSI_IterateRecords( view, 0, msi_dialog_create_controls, dialog );
2869 msiobj_release( &view->hdr );
2874 static UINT msi_dialog_set_control_condition( MSIRECORD *rec, LPVOID param )
2876 static const WCHAR szHide[] = { 'H','i','d','e',0 };
2877 static const WCHAR szShow[] = { 'S','h','o','w',0 };
2878 static const WCHAR szDisable[] = { 'D','i','s','a','b','l','e',0 };
2879 static const WCHAR szEnable[] = { 'E','n','a','b','l','e',0 };
2880 static const WCHAR szDefault[] = { 'D','e','f','a','u','l','t',0 };
2881 msi_dialog *dialog = param;
2882 msi_control *control;
2883 LPCWSTR name, action, condition;
2886 name = MSI_RecordGetString( rec, 2 );
2887 action = MSI_RecordGetString( rec, 3 );
2888 condition = MSI_RecordGetString( rec, 4 );
2889 r = MSI_EvaluateConditionW( dialog->package, condition );
2890 control = msi_dialog_find_control( dialog, name );
2891 if( r == MSICONDITION_TRUE && control )
2893 TRACE("%s control %s\n", debugstr_w(action), debugstr_w(name));
2895 /* FIXME: case sensitive? */
2896 if(!lstrcmpW(action, szHide))
2897 ShowWindow(control->hwnd, SW_HIDE);
2898 else if(!strcmpW(action, szShow))
2899 ShowWindow(control->hwnd, SW_SHOW);
2900 else if(!strcmpW(action, szDisable))
2901 EnableWindow(control->hwnd, FALSE);
2902 else if(!strcmpW(action, szEnable))
2903 EnableWindow(control->hwnd, TRUE);
2904 else if(!strcmpW(action, szDefault))
2905 SetFocus(control->hwnd);
2907 FIXME("Unhandled action %s\n", debugstr_w(action));
2910 return ERROR_SUCCESS;
2913 static UINT msi_dialog_evaluate_control_conditions( msi_dialog *dialog )
2915 static const WCHAR query[] = {
2916 'S','E','L','E','C','T',' ','*',' ',
2917 'F','R','O','M',' ',
2918 'C','o','n','t','r','o','l','C','o','n','d','i','t','i','o','n',' ',
2919 'W','H','E','R','E',' ',
2920 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',0
2923 MSIQUERY *view = NULL;
2924 MSIPACKAGE *package = dialog->package;
2926 TRACE("%p %s\n", dialog, debugstr_w(dialog->name) );
2928 /* query the Control table for all the elements of the control */
2929 r = MSI_OpenQuery( package->db, &view, query, dialog->name );
2930 if( r != ERROR_SUCCESS )
2931 return ERROR_SUCCESS;
2933 r = MSI_IterateRecords( view, 0, msi_dialog_set_control_condition, dialog );
2934 msiobj_release( &view->hdr );
2939 UINT msi_dialog_reset( msi_dialog *dialog )
2941 /* FIXME: should restore the original values of any properties we changed */
2942 return msi_dialog_evaluate_control_conditions( dialog );
2945 /* figure out the height of 10 point MS Sans Serif */
2946 static INT msi_dialog_get_sans_serif_height( HWND hwnd )
2948 static const WCHAR szSansSerif[] = {
2949 'M','S',' ','S','a','n','s',' ','S','e','r','i','f',0 };
2954 HFONT hFont, hOldFont;
2957 hdc = GetDC( hwnd );
2960 memset( &lf, 0, sizeof lf );
2961 lf.lfHeight = MulDiv(12, GetDeviceCaps(hdc, LOGPIXELSY), 72);
2962 strcpyW( lf.lfFaceName, szSansSerif );
2963 hFont = CreateFontIndirectW(&lf);
2966 hOldFont = SelectObject( hdc, hFont );
2967 r = GetTextMetricsW( hdc, &tm );
2969 height = tm.tmHeight;
2970 SelectObject( hdc, hOldFont );
2971 DeleteObject( hFont );
2973 ReleaseDC( hwnd, hdc );
2978 /* fetch the associated record from the Dialog table */
2979 static MSIRECORD *msi_get_dialog_record( msi_dialog *dialog )
2981 static const WCHAR query[] = {
2982 'S','E','L','E','C','T',' ','*',' ',
2983 'F','R','O','M',' ','D','i','a','l','o','g',' ',
2984 'W','H','E','R','E',' ',
2985 '`','D','i','a','l','o','g','`',' ','=',' ','\'','%','s','\'',0};
2986 MSIPACKAGE *package = dialog->package;
2987 MSIRECORD *rec = NULL;
2989 TRACE("%p %s\n", dialog, debugstr_w(dialog->name) );
2991 rec = MSI_QueryGetRecord( package->db, query, dialog->name );
2993 WARN("query failed for dialog %s\n", debugstr_w(dialog->name));
2998 static void msi_dialog_adjust_dialog_pos( msi_dialog *dialog, MSIRECORD *rec, LPRECT pos )
3000 static const WCHAR szScreenX[] = {'S','c','r','e','e','n','X',0};
3001 static const WCHAR szScreenY[] = {'S','c','r','e','e','n','Y',0};
3008 center.x = MSI_RecordGetInteger( rec, 2 );
3009 center.y = MSI_RecordGetInteger( rec, 3 );
3011 sz.cx = MSI_RecordGetInteger( rec, 4 );
3012 sz.cy = MSI_RecordGetInteger( rec, 5 );
3014 sz.cx = msi_dialog_scale_unit( dialog, sz.cx );
3015 sz.cy = msi_dialog_scale_unit( dialog, sz.cy );
3017 xres = msi_get_property_int( dialog->package, szScreenX, 0 );
3018 yres = msi_get_property_int( dialog->package, szScreenY, 0 );
3020 center.x = MulDiv( center.x, xres, 100 );
3021 center.y = MulDiv( center.y, yres, 100 );
3023 /* turn the client pos into the window rectangle */
3024 if (dialog->package->center_x && dialog->package->center_y)
3026 pos->left = dialog->package->center_x - sz.cx / 2.0;
3027 pos->right = pos->left + sz.cx;
3028 pos->top = dialog->package->center_y - sz.cy / 2.0;
3029 pos->bottom = pos->top + sz.cy;
3033 pos->left = center.x - sz.cx/2;
3034 pos->right = pos->left + sz.cx;
3035 pos->top = center.y - sz.cy/2;
3036 pos->bottom = pos->top + sz.cy;
3038 /* save the center */
3039 dialog->package->center_x = center.x;
3040 dialog->package->center_y = center.y;
3043 dialog->size.cx = sz.cx;
3044 dialog->size.cy = sz.cy;
3046 TRACE("%u %u %u %u\n", pos->left, pos->top, pos->right, pos->bottom);
3048 style = GetWindowLongPtrW( dialog->hwnd, GWL_STYLE );
3049 AdjustWindowRect( pos, style, FALSE );
3052 static void msi_dialog_set_tab_order( msi_dialog *dialog, LPCWSTR first )
3054 struct list tab_chain;
3055 msi_control *control;
3056 HWND prev = HWND_TOP;
3058 list_init( &tab_chain );
3059 if (!(control = msi_dialog_find_control( dialog, first ))) return;
3061 dialog->hWndFocus = control->hwnd;
3064 list_remove( &control->entry );
3065 list_add_tail( &tab_chain, &control->entry );
3066 if (!control->tabnext) break;
3067 control = msi_dialog_find_control( dialog, control->tabnext );
3070 LIST_FOR_EACH_ENTRY( control, &tab_chain, msi_control, entry )
3072 SetWindowPos( control->hwnd, prev, 0, 0, 0, 0,
3073 SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOREDRAW |
3074 SWP_NOREPOSITION | SWP_NOSENDCHANGING | SWP_NOSIZE );
3075 prev = control->hwnd;
3078 /* put them back on the main list */
3079 list_move_head( &dialog->controls, &tab_chain );
3082 static LRESULT msi_dialog_oncreate( HWND hwnd, LPCREATESTRUCTW cs )
3084 static const WCHAR df[] = {
3085 'D','e','f','a','u','l','t','U','I','F','o','n','t',0 };
3086 static const WCHAR dfv[] = {
3087 'M','S',' ','S','h','e','l','l',' ','D','l','g',0 };
3088 msi_dialog *dialog = cs->lpCreateParams;
3089 MSIRECORD *rec = NULL;
3090 LPWSTR title = NULL;
3093 TRACE("%p %p\n", dialog, dialog->package);
3095 dialog->hwnd = hwnd;
3096 SetWindowLongPtrW( hwnd, GWLP_USERDATA, (LONG_PTR) dialog );
3098 rec = msi_get_dialog_record( dialog );
3101 TRACE("No record found for dialog %s\n", debugstr_w(dialog->name));
3105 dialog->scale = msi_dialog_get_sans_serif_height(dialog->hwnd);
3107 msi_dialog_adjust_dialog_pos( dialog, rec, &pos );
3109 dialog->attributes = MSI_RecordGetInteger( rec, 6 );
3111 dialog->default_font = msi_dup_property( dialog->package, df );
3112 if (!dialog->default_font)
3114 dialog->default_font = strdupW(dfv);
3115 if (!dialog->default_font) return -1;
3118 title = msi_get_deformatted_field( dialog->package, rec, 7 );
3119 SetWindowTextW( hwnd, title );
3122 SetWindowPos( hwnd, 0, pos.left, pos.top,
3123 pos.right - pos.left, pos.bottom - pos.top,
3124 SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOREDRAW );
3126 msi_dialog_build_font_list( dialog );
3127 msi_dialog_fill_controls( dialog );
3128 msi_dialog_evaluate_control_conditions( dialog );
3129 msi_dialog_set_tab_order( dialog, MSI_RecordGetString( rec, 8 ) );
3130 msiobj_release( &rec->hdr );
3135 static UINT msi_dialog_send_event( msi_dialog *dialog, LPCWSTR event, LPCWSTR arg )
3137 LPWSTR event_fmt = NULL, arg_fmt = NULL;
3139 TRACE("Sending control event %s %s\n", debugstr_w(event), debugstr_w(arg));
3141 deformat_string( dialog->package, event, &event_fmt );
3142 deformat_string( dialog->package, arg, &arg_fmt );
3144 dialog->event_handler( dialog->package, event_fmt, arg_fmt, dialog );
3146 msi_free( event_fmt );
3147 msi_free( arg_fmt );
3149 return ERROR_SUCCESS;
3152 static UINT msi_dialog_set_property( msi_dialog *dialog, LPCWSTR event, LPCWSTR arg )
3154 static const WCHAR szNullArg[] = { '{','}',0 };
3155 LPWSTR p, prop, arg_fmt = NULL;
3158 len = strlenW(event);
3159 prop = msi_alloc( len*sizeof(WCHAR));
3160 strcpyW( prop, &event[1] );
3161 p = strchrW( prop, ']' );
3162 if( p && (p[1] == 0 || p[1] == ' ') )
3165 if( strcmpW( szNullArg, arg ) )
3166 deformat_string( dialog->package, arg, &arg_fmt );
3167 MSI_SetPropertyW( dialog->package, prop, arg_fmt );
3168 msi_dialog_update_controls( dialog, prop );
3169 msi_free( arg_fmt );
3172 ERR("Badly formatted property string - what happens?\n");
3174 return ERROR_SUCCESS;
3177 static UINT msi_dialog_control_event( MSIRECORD *rec, LPVOID param )
3179 msi_dialog *dialog = param;
3180 LPCWSTR condition, event, arg;
3183 condition = MSI_RecordGetString( rec, 5 );
3184 r = MSI_EvaluateConditionW( dialog->package, condition );
3185 if( r == MSICONDITION_TRUE || r == MSICONDITION_NONE )
3187 event = MSI_RecordGetString( rec, 3 );
3188 arg = MSI_RecordGetString( rec, 4 );
3189 if( event[0] == '[' )
3190 msi_dialog_set_property( dialog, event, arg );
3192 msi_dialog_send_event( dialog, event, arg );
3195 return ERROR_SUCCESS;
3204 static UINT add_rec_to_list( MSIRECORD *rec, LPVOID param )
3206 struct rec_list *add_rec;
3207 struct list *records = param;
3209 msiobj_addref( &rec->hdr );
3211 add_rec = msi_alloc( sizeof( *add_rec ) );
3214 msiobj_release( &rec->hdr );
3215 return ERROR_OUTOFMEMORY;
3219 list_add_tail( records, &add_rec->entry );
3220 return ERROR_SUCCESS;
3223 static inline void remove_rec_from_list( struct rec_list *rec_entry )
3225 msiobj_release( &rec_entry->rec->hdr );
3226 list_remove( &rec_entry->entry );
3227 msi_free( rec_entry );
3230 static UINT msi_dialog_button_handler( msi_dialog *dialog,
3231 msi_control *control, WPARAM param )
3233 static const WCHAR query[] = {
3234 'S','E','L','E','C','T',' ','*',' ',
3235 'F','R','O','M',' ','C','o','n','t','r','o','l','E','v','e','n','t',' ',
3236 'W','H','E','R','E',' ',
3237 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',' ',
3239 '`','C','o','n','t','r','o','l','_','`',' ','=',' ','\'','%','s','\'',' ',
3240 'O','R','D','E','R',' ','B','Y',' ','`','O','r','d','e','r','i','n','g','`',0
3242 MSIQUERY *view = NULL;
3243 struct rec_list *rec_entry, *next;
3247 if( HIWORD(param) != BN_CLICKED )
3248 return ERROR_SUCCESS;
3250 list_init( &events );
3252 r = MSI_OpenQuery( dialog->package->db, &view, query,
3253 dialog->name, control->name );
3254 if( r != ERROR_SUCCESS )
3256 ERR("query failed\n");
3260 r = MSI_IterateRecords( view, 0, add_rec_to_list, &events );
3261 msiobj_release( &view->hdr );
3262 if (r != ERROR_SUCCESS)
3265 /* handle all SetProperty events first */
3266 LIST_FOR_EACH_ENTRY_SAFE( rec_entry, next, &events, struct rec_list, entry )
3268 LPCWSTR event = MSI_RecordGetString( rec_entry->rec, 3 );
3270 if ( event[0] != '[' )
3273 r = msi_dialog_control_event( rec_entry->rec, dialog );
3274 remove_rec_from_list( rec_entry );
3276 if ( r != ERROR_SUCCESS )
3280 /* handle all other events */
3281 LIST_FOR_EACH_ENTRY_SAFE( rec_entry, next, &events, struct rec_list, entry )
3283 r = msi_dialog_control_event( rec_entry->rec, dialog );
3284 remove_rec_from_list( rec_entry );
3286 if ( r != ERROR_SUCCESS )
3291 LIST_FOR_EACH_ENTRY_SAFE( rec_entry, next, &events, struct rec_list, entry )
3293 remove_rec_from_list( rec_entry );
3299 static UINT msi_dialog_get_checkbox_state( msi_dialog *dialog,
3300 msi_control *control )
3302 WCHAR state[2] = { 0 };
3305 MSI_GetPropertyW( dialog->package, control->property, state, &sz );
3306 return state[0] ? 1 : 0;
3309 static void msi_dialog_set_checkbox_state( msi_dialog *dialog,
3310 msi_control *control, UINT state )
3312 static const WCHAR szState[] = { '1', 0 };
3315 /* if uncheck then the property is set to NULL */
3318 MSI_SetPropertyW( dialog->package, control->property, NULL );
3322 /* check for a custom state */
3323 if (control->value && control->value[0])
3324 val = control->value;
3328 MSI_SetPropertyW( dialog->package, control->property, val );
3331 static void msi_dialog_checkbox_sync_state( msi_dialog *dialog,
3332 msi_control *control )
3336 state = msi_dialog_get_checkbox_state( dialog, control );
3337 SendMessageW( control->hwnd, BM_SETCHECK,
3338 state ? BST_CHECKED : BST_UNCHECKED, 0 );
3341 static UINT msi_dialog_checkbox_handler( msi_dialog *dialog,
3342 msi_control *control, WPARAM param )
3346 if( HIWORD(param) != BN_CLICKED )
3347 return ERROR_SUCCESS;
3349 TRACE("clicked checkbox %s, set %s\n", debugstr_w(control->name),
3350 debugstr_w(control->property));
3352 state = msi_dialog_get_checkbox_state( dialog, control );
3353 state = state ? 0 : 1;
3354 msi_dialog_set_checkbox_state( dialog, control, state );
3355 msi_dialog_checkbox_sync_state( dialog, control );
3357 return msi_dialog_button_handler( dialog, control, param );
3360 static UINT msi_dialog_edit_handler( msi_dialog *dialog,
3361 msi_control *control, WPARAM param )
3365 if( HIWORD(param) != EN_CHANGE )
3366 return ERROR_SUCCESS;
3368 TRACE("edit %s contents changed, set %s\n", debugstr_w(control->name),
3369 debugstr_w(control->property));
3371 buf = msi_get_window_text( control->hwnd );
3372 MSI_SetPropertyW( dialog->package, control->property, buf );
3376 return ERROR_SUCCESS;
3379 static UINT msi_dialog_radiogroup_handler( msi_dialog *dialog,
3380 msi_control *control, WPARAM param )
3382 if( HIWORD(param) != BN_CLICKED )
3383 return ERROR_SUCCESS;
3385 TRACE("clicked radio button %s, set %s\n", debugstr_w(control->name),
3386 debugstr_w(control->property));
3388 MSI_SetPropertyW( dialog->package, control->property, control->name );
3390 return msi_dialog_button_handler( dialog, control, param );
3393 static LRESULT msi_dialog_oncommand( msi_dialog *dialog, WPARAM param, HWND hwnd )
3395 msi_control *control = NULL;
3397 TRACE("%p %p %08lx\n", dialog, hwnd, param);
3402 control = msi_dialog_find_control( dialog, dialog->control_default );
3404 case 2: /* escape */
3405 control = msi_dialog_find_control( dialog, dialog->control_cancel );
3408 control = msi_dialog_find_control_by_hwnd( dialog, hwnd );
3413 if( control->handler )
3415 control->handler( dialog, control, param );
3416 msi_dialog_evaluate_control_conditions( dialog );
3423 static LRESULT msi_dialog_onnotify( msi_dialog *dialog, LPARAM param )
3425 LPNMHDR nmhdr = (LPNMHDR) param;
3426 msi_control *control = msi_dialog_find_control_by_hwnd( dialog, nmhdr->hwndFrom );
3428 TRACE("%p %p\n", dialog, nmhdr->hwndFrom);
3430 if ( control && control->handler )
3431 control->handler( dialog, control, param );
3436 static void msi_dialog_setfocus( msi_dialog *dialog )
3438 HWND hwnd = dialog->hWndFocus;
3440 hwnd = GetNextDlgTabItem( dialog->hwnd, hwnd, TRUE);
3441 hwnd = GetNextDlgTabItem( dialog->hwnd, hwnd, FALSE);
3443 dialog->hWndFocus = hwnd;
3446 static LRESULT WINAPI MSIDialog_WndProc( HWND hwnd, UINT msg,
3447 WPARAM wParam, LPARAM lParam )
3449 msi_dialog *dialog = (LPVOID) GetWindowLongPtrW( hwnd, GWLP_USERDATA );
3451 TRACE("0x%04x\n", msg);
3456 dialog->package->center_x = LOWORD(lParam) + dialog->size.cx / 2.0;
3457 dialog->package->center_y = HIWORD(lParam) + dialog->size.cy / 2.0;
3461 return msi_dialog_oncreate( hwnd, (LPCREATESTRUCTW)lParam );
3464 return msi_dialog_oncommand( dialog, wParam, (HWND)lParam );
3467 if( LOWORD(wParam) == WA_INACTIVE )
3468 dialog->hWndFocus = GetFocus();
3470 msi_dialog_setfocus( dialog );
3474 msi_dialog_setfocus( dialog );
3477 /* bounce back to our subclassed static control */
3478 case WM_CTLCOLORSTATIC:
3479 return SendMessageW( (HWND) lParam, WM_CTLCOLORSTATIC, wParam, lParam );
3482 dialog->hwnd = NULL;
3485 return msi_dialog_onnotify( dialog, lParam );
3487 return DefWindowProcW(hwnd, msg, wParam, lParam);
3490 static BOOL CALLBACK msi_radioground_child_enum( HWND hWnd, LPARAM lParam )
3492 EnableWindow( hWnd, lParam );
3496 static LRESULT WINAPI MSIRadioGroup_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
3498 WNDPROC oldproc = (WNDPROC) GetPropW(hWnd, szButtonData);
3501 TRACE("hWnd %p msg %04x wParam 0x%08lx lParam 0x%08lx\n", hWnd, msg, wParam, lParam);
3503 if (msg == WM_COMMAND) /* Forward notifications to dialog */
3504 SendMessageW(GetParent(hWnd), msg, wParam, lParam);
3506 r = CallWindowProcW(oldproc, hWnd, msg, wParam, lParam);
3508 /* make sure the radio buttons show as disabled if the parent is disabled */
3509 if (msg == WM_ENABLE)
3510 EnumChildWindows( hWnd, msi_radioground_child_enum, wParam );
3515 static LRESULT WINAPI MSIHiddenWindowProc( HWND hwnd, UINT msg,
3516 WPARAM wParam, LPARAM lParam )
3518 msi_dialog *dialog = (msi_dialog*) lParam;
3520 TRACE("%d %p\n", msg, dialog);
3524 case WM_MSI_DIALOG_CREATE:
3525 return msi_dialog_run_message_loop( dialog );
3526 case WM_MSI_DIALOG_DESTROY:
3527 msi_dialog_destroy( dialog );
3530 return DefWindowProcW( hwnd, msg, wParam, lParam );
3533 static BOOL msi_dialog_register_class( void )
3537 ZeroMemory( &cls, sizeof cls );
3538 cls.lpfnWndProc = MSIDialog_WndProc;
3539 cls.hInstance = NULL;
3540 cls.hIcon = LoadIconW(0, (LPWSTR)IDI_APPLICATION);
3541 cls.hCursor = LoadCursorW(0, (LPWSTR)IDC_ARROW);
3542 cls.hbrBackground = (HBRUSH)(COLOR_3DFACE + 1);
3543 cls.lpszMenuName = NULL;
3544 cls.lpszClassName = szMsiDialogClass;
3546 if( !RegisterClassW( &cls ) )
3549 cls.lpfnWndProc = MSIHiddenWindowProc;
3550 cls.lpszClassName = szMsiHiddenWindow;
3552 if( !RegisterClassW( &cls ) )
3555 uiThreadId = GetCurrentThreadId();
3557 hMsiHiddenWindow = CreateWindowW( szMsiHiddenWindow, NULL, WS_OVERLAPPED,
3558 0, 0, 100, 100, NULL, NULL, NULL, NULL );
3559 if( !hMsiHiddenWindow )
3565 /* functions that interface to other modules within MSI */
3567 msi_dialog *msi_dialog_create( MSIPACKAGE* package,
3568 LPCWSTR szDialogName, msi_dialog *parent,
3569 msi_dialog_event_handler event_handler )
3571 MSIRECORD *rec = NULL;
3574 TRACE("%p %s\n", package, debugstr_w(szDialogName));
3576 if (!hMsiHiddenWindow)
3577 msi_dialog_register_class();
3579 /* allocate the structure for the dialog to use */
3580 dialog = msi_alloc_zero( sizeof *dialog + sizeof(WCHAR)*strlenW(szDialogName) );
3583 strcpyW( dialog->name, szDialogName );
3584 dialog->parent = parent;
3585 msiobj_addref( &package->hdr );
3586 dialog->package = package;
3587 dialog->event_handler = event_handler;
3588 dialog->finished = 0;
3589 list_init( &dialog->controls );
3591 /* verify that the dialog exists */
3592 rec = msi_get_dialog_record( dialog );
3595 msiobj_release( &package->hdr );
3599 dialog->attributes = MSI_RecordGetInteger( rec, 6 );
3600 dialog->control_default = strdupW( MSI_RecordGetString( rec, 9 ) );
3601 dialog->control_cancel = strdupW( MSI_RecordGetString( rec, 10 ) );
3602 msiobj_release( &rec->hdr );
3607 static void msi_process_pending_messages( HWND hdlg )
3611 while( PeekMessageW( &msg, 0, 0, 0, PM_REMOVE ) )
3613 if( hdlg && IsDialogMessageW( hdlg, &msg ))
3615 TranslateMessage( &msg );
3616 DispatchMessageW( &msg );
3620 void msi_dialog_end_dialog( msi_dialog *dialog )
3622 TRACE("%p\n", dialog);
3623 dialog->finished = 1;
3624 PostMessageW(dialog->hwnd, WM_NULL, 0, 0);
3627 void msi_dialog_check_messages( HANDLE handle )
3631 /* in threads other than the UI thread, block */
3632 if( uiThreadId != GetCurrentThreadId() )
3635 WaitForSingleObject( handle, INFINITE );
3639 /* there's two choices for the UI thread */
3642 msi_process_pending_messages( NULL );
3648 * block here until somebody creates a new dialog or
3649 * the handle we're waiting on becomes ready
3651 r = MsgWaitForMultipleObjects( 1, &handle, 0, INFINITE, QS_ALLINPUT );
3652 if( r == WAIT_OBJECT_0 )
3657 UINT msi_dialog_run_message_loop( msi_dialog *dialog )
3662 if( uiThreadId != GetCurrentThreadId() )
3663 return SendMessageW( hMsiHiddenWindow, WM_MSI_DIALOG_CREATE, 0, (LPARAM) dialog );
3665 /* create the dialog window, don't show it yet */
3666 style = WS_OVERLAPPED;
3667 if( dialog->attributes & msidbDialogAttributesVisible )
3668 style |= WS_VISIBLE;
3670 hwnd = CreateWindowW( szMsiDialogClass, dialog->name, style,
3671 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
3672 NULL, NULL, NULL, dialog );
3675 ERR("Failed to create dialog %s\n", debugstr_w( dialog->name ));
3676 return ERROR_FUNCTION_FAILED;
3679 ShowWindow( hwnd, SW_SHOW );
3680 /* UpdateWindow( hwnd ); - and causes the transparent static controls not to paint */
3682 if( dialog->attributes & msidbDialogAttributesModal )
3684 while( !dialog->finished )
3686 MsgWaitForMultipleObjects( 0, NULL, 0, INFINITE, QS_ALLINPUT );
3687 msi_process_pending_messages( dialog->hwnd );
3691 return ERROR_IO_PENDING;
3693 return ERROR_SUCCESS;
3696 void msi_dialog_do_preview( msi_dialog *dialog )
3699 dialog->attributes |= msidbDialogAttributesVisible;
3700 dialog->attributes &= ~msidbDialogAttributesModal;
3701 msi_dialog_run_message_loop( dialog );
3704 void msi_dialog_destroy( msi_dialog *dialog )
3706 if( uiThreadId != GetCurrentThreadId() )
3708 SendMessageW( hMsiHiddenWindow, WM_MSI_DIALOG_DESTROY, 0, (LPARAM) dialog );
3713 ShowWindow( dialog->hwnd, SW_HIDE );
3716 DestroyWindow( dialog->hwnd );
3718 /* unsubscribe events */
3719 ControlEvent_CleanupDialogSubscriptions(dialog->package, dialog->name);
3721 /* destroy the list of controls */
3722 while( !list_empty( &dialog->controls ) )
3726 t = LIST_ENTRY( list_head( &dialog->controls ),
3727 msi_control, entry );
3728 msi_destroy_control( t );
3731 /* destroy the list of fonts */
3732 while( dialog->font_list )
3734 msi_font *t = dialog->font_list;
3735 dialog->font_list = t->next;
3736 DeleteObject( t->hfont );
3739 msi_free( dialog->default_font );
3741 msi_free( dialog->control_default );
3742 msi_free( dialog->control_cancel );
3743 msiobj_release( &dialog->package->hdr );
3744 dialog->package = NULL;
3748 void msi_dialog_unregister_class( void )
3750 DestroyWindow( hMsiHiddenWindow );
3751 hMsiHiddenWindow = NULL;
3752 UnregisterClassW( szMsiDialogClass, NULL );
3753 UnregisterClassW( szMsiHiddenWindow, NULL );
3757 static UINT error_dialog_handler(MSIPACKAGE *package, LPCWSTR event,
3758 LPCWSTR argument, msi_dialog* dialog)
3760 static const WCHAR end_dialog[] = {'E','n','d','D','i','a','l','o','g',0};
3761 static const WCHAR error_abort[] = {'E','r','r','o','r','A','b','o','r','t',0};
3762 static const WCHAR error_cancel[] = {'E','r','r','o','r','C','a','n','c','e','l',0};
3763 static const WCHAR error_no[] = {'E','r','r','o','r','N','o',0};
3764 static const WCHAR result_prop[] = {
3765 'M','S','I','E','r','r','o','r','D','i','a','l','o','g','R','e','s','u','l','t',0
3768 if ( lstrcmpW( event, end_dialog ) )
3769 return ERROR_SUCCESS;
3771 if ( !lstrcmpW( argument, error_abort ) || !lstrcmpW( argument, error_cancel ) ||
3772 !lstrcmpW( argument, error_no ) )
3774 MSI_SetPropertyW( package, result_prop, error_abort );
3777 ControlEvent_CleanupSubscriptions(package);
3778 msi_dialog_end_dialog( dialog );
3780 return ERROR_SUCCESS;
3783 static UINT msi_error_dialog_set_error( MSIPACKAGE *package, LPWSTR error_dialog, LPWSTR error )
3787 static const WCHAR update[] =
3788 {'U','P','D','A','T','E',' ','`','C','o','n','t','r','o','l','`',' ',
3789 'S','E','T',' ','`','T','e','x','t','`',' ','=',' ','\'','%','s','\'',' ',
3790 'W','H','E','R','E', ' ','`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',' ',
3791 'A','N','D',' ','`','C','o','n','t','r','o','l','`',' ','=',' ',
3792 '\'','E','r','r','o','r','T','e','x','t','\'',0};
3794 row = MSI_QueryGetRecord( package->db, update, error, error_dialog );
3796 return ERROR_FUNCTION_FAILED;
3798 msiobj_release(&row->hdr);
3799 return ERROR_SUCCESS;
3802 UINT msi_spawn_error_dialog( MSIPACKAGE *package, LPWSTR error_dialog, LPWSTR error )
3805 WCHAR result[MAX_PATH];
3806 UINT r = ERROR_SUCCESS;
3807 DWORD size = MAX_PATH;
3810 static const WCHAR pn_prop[] = {'P','r','o','d','u','c','t','N','a','m','e',0};
3811 static const WCHAR title_fmt[] = {'%','s',' ','W','a','r','n','i','n','g',0};
3812 static const WCHAR error_abort[] = {'E','r','r','o','r','A','b','o','r','t',0};
3813 static const WCHAR result_prop[] = {
3814 'M','S','I','E','r','r','o','r','D','i','a','l','o','g','R','e','s','u','l','t',0
3817 if ( (msi_get_property_int(package, szUILevel, 0) & INSTALLUILEVEL_MASK) == INSTALLUILEVEL_NONE )
3818 return ERROR_SUCCESS;
3820 if ( !error_dialog )
3822 LPWSTR product_name = msi_dup_property( package, pn_prop );
3823 WCHAR title[MAX_PATH];
3825 sprintfW( title, title_fmt, product_name );
3826 res = MessageBoxW( NULL, error, title, MB_OKCANCEL | MB_ICONWARNING );
3828 msi_free( product_name );
3831 return ERROR_SUCCESS;
3833 return ERROR_FUNCTION_FAILED;
3836 r = msi_error_dialog_set_error( package, error_dialog, error );
3837 if ( r != ERROR_SUCCESS )
3840 dialog = msi_dialog_create( package, error_dialog, package->dialog,
3841 error_dialog_handler );
3843 return ERROR_FUNCTION_FAILED;
3845 dialog->finished = FALSE;
3846 r = msi_dialog_run_message_loop( dialog );
3847 if ( r != ERROR_SUCCESS )
3850 r = MSI_GetPropertyW( package, result_prop, result, &size );
3851 if ( r != ERROR_SUCCESS)
3854 if ( !lstrcmpW( result, error_abort ) )
3855 r = ERROR_FUNCTION_FAILED;
3858 msi_dialog_destroy( dialog );