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 (dialog->scale * val + 5) / 10;
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_head( &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)
498 static const WCHAR prefix[] = { 'm','s','i',0 };
501 r = GetTempPathW( MAX_PATH, tmp );
504 len = lstrlenW( tmp ) + 20;
505 path = msi_alloc( len * sizeof (WCHAR) );
508 r = GetTempFileNameW( tmp, prefix, 0, path );
519 static HANDLE msi_load_image( MSIDATABASE *db, LPCWSTR name, UINT type,
520 UINT cx, UINT cy, UINT flags )
522 MSIRECORD *rec = NULL;
523 HANDLE himage = NULL;
527 TRACE("%p %s %u %u %08x\n", db, debugstr_w(name), cx, cy, flags);
529 tmp = msi_create_tmp_path();
533 rec = msi_get_binary_record( db, name );
536 r = MSI_RecordStreamToFile( rec, 2, tmp );
537 if( r == ERROR_SUCCESS )
539 himage = LoadImageW( 0, tmp, type, cx, cy, flags );
541 msiobj_release( &rec->hdr );
549 static HICON msi_load_icon( MSIDATABASE *db, LPCWSTR text, UINT attributes )
551 DWORD cx = 0, cy = 0, flags;
553 flags = LR_LOADFROMFILE | LR_DEFAULTSIZE;
554 if( attributes & msidbControlAttributesFixedSize )
556 flags &= ~LR_DEFAULTSIZE;
557 if( attributes & msidbControlAttributesIconSize16 )
562 if( attributes & msidbControlAttributesIconSize32 )
567 /* msidbControlAttributesIconSize48 handled by above logic */
569 return msi_load_image( db, text, IMAGE_ICON, cx, cy, flags );
572 static void msi_dialog_update_controls( msi_dialog *dialog, LPCWSTR property )
574 msi_control *control;
576 LIST_FOR_EACH_ENTRY( control, &dialog->controls, msi_control, entry )
578 if ( !lstrcmpW( control->property, property ) && control->update )
579 control->update( dialog, control );
583 /* called from the Control Event subscription code */
584 void msi_dialog_handle_event( msi_dialog* dialog, LPCWSTR control,
585 LPCWSTR attribute, MSIRECORD *rec )
588 LPCWSTR font_text, text = NULL;
591 static const WCHAR empty[] = {0};
593 ctrl = msi_dialog_find_control( dialog, control );
596 if( !lstrcmpW(attribute, szText) )
598 font_text = MSI_RecordGetString( rec , 1 );
599 font = msi_dialog_get_style( font_text, &text );
600 if (!text) text = empty;
601 SetWindowTextW( ctrl->hwnd, text );
603 msi_dialog_check_messages( NULL );
605 else if( !lstrcmpW(attribute, szProgress) )
609 func = MSI_RecordGetInteger( rec , 1 );
610 val = MSI_RecordGetInteger( rec , 2 );
615 ctrl->progress_max = val;
616 ctrl->progress_current = 0;
617 SendMessageW(ctrl->hwnd, PBM_SETRANGE, 0, MAKELPARAM(0,100));
618 SendMessageW(ctrl->hwnd, PBM_SETPOS, 0, 0);
620 case 1: /* FIXME: not sure what this is supposed to do */
623 ctrl->progress_current += val;
624 SendMessageW(ctrl->hwnd, PBM_SETPOS, 100*(ctrl->progress_current/ctrl->progress_max), 0);
627 ERR("Unknown progress message %d\n", func);
631 else if ( !lstrcmpW(attribute, szProperty) )
633 MSIFEATURE *feature = msi_seltree_get_selected_feature( ctrl );
634 MSI_SetPropertyW( dialog->package, ctrl->property, feature->Directory );
636 else if ( !lstrcmpW(attribute, szSelectionPath) )
638 LPWSTR prop = msi_dialog_dup_property( dialog, ctrl->property, TRUE );
641 path = msi_dup_property( dialog->package, prop );
642 SetWindowTextW( ctrl->hwnd, path );
648 FIXME("Attribute %s not being set\n", debugstr_w(attribute));
653 static void msi_dialog_map_events(msi_dialog* dialog, LPCWSTR control)
655 static const WCHAR Query[] = {
656 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
657 '`','E','v','e','n','t','M','a','p','p','i','n','g','`',' ',
658 'W','H','E','R','E',' ',
659 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',' ',
661 '`','C','o','n','t','r','o','l','_','`',' ','=',' ','\'','%','s','\'',0
664 LPCWSTR event, attribute;
666 row = MSI_QueryGetRecord( dialog->package->db, Query, dialog->name, control );
670 event = MSI_RecordGetString( row, 3 );
671 attribute = MSI_RecordGetString( row, 4 );
672 ControlEvent_SubscribeToEvent( dialog->package, dialog, event, control, attribute );
673 msiobj_release( &row->hdr );
676 /* everything except radio buttons */
677 static msi_control *msi_dialog_add_control( msi_dialog *dialog,
678 MSIRECORD *rec, LPCWSTR szCls, DWORD style )
684 name = MSI_RecordGetString( rec, 2 );
685 attributes = MSI_RecordGetInteger( rec, 8 );
686 text = MSI_RecordGetString( rec, 10 );
687 if( attributes & msidbControlAttributesVisible )
689 if( ~attributes & msidbControlAttributesEnabled )
690 style |= WS_DISABLED;
691 if( attributes & msidbControlAttributesSunken )
692 exstyle |= WS_EX_CLIENTEDGE;
694 msi_dialog_map_events(dialog, name);
696 return msi_dialog_create_window( dialog, rec, exstyle, szCls, name,
697 text, style, dialog->hwnd );
708 * we don't erase our own background,
709 * so we have to make sure that the parent window redraws first
711 static void msi_text_on_settext( HWND hWnd )
716 hParent = GetParent( hWnd );
717 GetWindowRect( hWnd, &rc );
718 MapWindowPoints( NULL, hParent, (LPPOINT) &rc, 2 );
719 InvalidateRect( hParent, &rc, TRUE );
722 static LRESULT WINAPI
723 MSIText_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
725 struct msi_text_info *info;
728 TRACE("%p %04x %08lx %08lx\n", hWnd, msg, wParam, lParam);
730 info = GetPropW(hWnd, szButtonData);
732 if( msg == WM_CTLCOLORSTATIC &&
733 ( info->attributes & msidbControlAttributesTransparent ) )
735 SetBkMode( (HDC)wParam, TRANSPARENT );
736 return (LRESULT) GetStockObject(NULL_BRUSH);
739 r = CallWindowProcW(info->oldproc, hWnd, msg, wParam, lParam);
741 SetTextColor( (HDC)wParam, info->font->color );
746 msi_text_on_settext( hWnd );
750 RemovePropW( hWnd, szButtonData );
757 static UINT msi_dialog_text_control( msi_dialog *dialog, MSIRECORD *rec )
759 msi_control *control;
760 struct msi_text_info *info;
761 LPCWSTR text, ptr, prop;
764 TRACE("%p %p\n", dialog, rec);
766 control = msi_dialog_add_control( dialog, rec, szStatic, SS_LEFT | WS_GROUP );
768 return ERROR_FUNCTION_FAILED;
770 info = msi_alloc( sizeof *info );
772 return ERROR_SUCCESS;
774 control->attributes = MSI_RecordGetInteger( rec, 8 );
775 prop = MSI_RecordGetString( rec, 9 );
776 control->property = msi_dialog_dup_property( dialog, prop, FALSE );
778 text = MSI_RecordGetString( rec, 10 );
779 font_name = msi_dialog_get_style( text, &ptr );
780 info->font = ( font_name ) ? msi_dialog_find_font( dialog, font_name ) : NULL;
781 msi_free( font_name );
783 info->attributes = MSI_RecordGetInteger( rec, 8 );
784 if( info->attributes & msidbControlAttributesTransparent )
785 SetWindowLongPtrW( control->hwnd, GWL_EXSTYLE, WS_EX_TRANSPARENT );
787 info->oldproc = (WNDPROC) SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
788 (LONG_PTR)MSIText_WndProc );
789 SetPropW( control->hwnd, szButtonData, info );
791 ControlEvent_SubscribeToEvent( dialog->package, dialog,
792 szSelectionPath, control->name, szSelectionPath );
794 return ERROR_SUCCESS;
797 static UINT msi_dialog_button_control( msi_dialog *dialog, MSIRECORD *rec )
799 msi_control *control;
800 UINT attributes, style;
803 TRACE("%p %p\n", dialog, rec);
806 attributes = MSI_RecordGetInteger( rec, 8 );
807 if( attributes & msidbControlAttributesIcon )
810 control = msi_dialog_add_control( dialog, rec, szButton, style );
812 return ERROR_FUNCTION_FAILED;
814 control->handler = msi_dialog_button_handler;
817 text = msi_get_deformatted_field( dialog->package, rec, 10 );
818 control->hIcon = msi_load_icon( dialog->package->db, text, attributes );
819 if( attributes & msidbControlAttributesIcon )
820 SendMessageW( control->hwnd, BM_SETIMAGE, IMAGE_ICON, (LPARAM) control->hIcon );
823 return ERROR_SUCCESS;
826 static LPWSTR msi_get_checkbox_value( msi_dialog *dialog, LPCWSTR prop )
828 static const WCHAR query[] = {
829 'S','E','L','E','C','T',' ','*',' ',
830 'F','R','O','M',' ','`','C','h','e','c','k','B','o','x','`',' ',
831 'W','H','E','R','E',' ',
832 '`','P','r','o','p','e','r','t','y','`',' ','=',' ',
835 MSIRECORD *rec = NULL;
838 /* find if there is a value associated with the checkbox */
839 rec = MSI_QueryGetRecord( dialog->package->db, query, prop );
843 ret = msi_get_deformatted_field( dialog->package, rec, 2 );
849 msiobj_release( &rec->hdr );
853 ret = msi_dup_property( dialog->package, prop );
863 static UINT msi_dialog_checkbox_control( msi_dialog *dialog, MSIRECORD *rec )
865 msi_control *control;
868 TRACE("%p %p\n", dialog, rec);
870 control = msi_dialog_add_control( dialog, rec, szButton,
871 BS_CHECKBOX | BS_MULTILINE | WS_TABSTOP );
872 control->handler = msi_dialog_checkbox_handler;
873 control->update = msi_dialog_checkbox_sync_state;
874 prop = MSI_RecordGetString( rec, 9 );
877 control->property = strdupW( prop );
878 control->value = msi_get_checkbox_value( dialog, prop );
879 TRACE("control %s value %s\n", debugstr_w(control->property),
880 debugstr_w(control->value));
882 msi_dialog_checkbox_sync_state( dialog, control );
884 return ERROR_SUCCESS;
887 static UINT msi_dialog_line_control( msi_dialog *dialog, MSIRECORD *rec )
891 DWORD style, exstyle = 0;
892 DWORD x, y, width, height;
893 msi_control *control;
895 TRACE("%p %p\n", dialog, rec);
897 style = WS_CHILD | SS_ETCHEDHORZ | SS_SUNKEN;
899 name = MSI_RecordGetString( rec, 2 );
900 attributes = MSI_RecordGetInteger( rec, 8 );
902 if( attributes & msidbControlAttributesVisible )
904 if( ~attributes & msidbControlAttributesEnabled )
905 style |= WS_DISABLED;
906 if( attributes & msidbControlAttributesSunken )
907 exstyle |= WS_EX_CLIENTEDGE;
909 msi_dialog_map_events(dialog, name);
911 control = msi_alloc( sizeof(*control) + strlenW(name) * sizeof(WCHAR) );
913 return ERROR_OUTOFMEMORY;
915 strcpyW( control->name, name );
916 list_add_head( &dialog->controls, &control->entry );
917 control->handler = NULL;
918 control->property = NULL;
919 control->value = NULL;
920 control->hBitmap = NULL;
921 control->hIcon = NULL;
922 control->hDll = NULL;
923 control->tabnext = strdupW( MSI_RecordGetString( rec, 11) );
924 control->type = strdupW( MSI_RecordGetString( rec, 3 ) );
925 control->progress_current = 0;
926 control->progress_max = 100;
928 x = MSI_RecordGetInteger( rec, 4 );
929 y = MSI_RecordGetInteger( rec, 5 );
930 width = MSI_RecordGetInteger( rec, 6 );
932 x = msi_dialog_scale_unit( dialog, x );
933 y = msi_dialog_scale_unit( dialog, y );
934 width = msi_dialog_scale_unit( dialog, width );
935 height = 2; /* line is exactly 2 units in height */
937 control->hwnd = CreateWindowExW( exstyle, szStatic, NULL, style,
938 x, y, width, height, dialog->hwnd, NULL, NULL, NULL );
940 TRACE("Dialog %s control %s hwnd %p\n",
941 debugstr_w(dialog->name), debugstr_w(name), control->hwnd );
943 return ERROR_SUCCESS;
946 /******************** Scroll Text ********************************************/
948 struct msi_scrolltext_info
951 msi_control *control;
955 static LRESULT WINAPI
956 MSIScrollText_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
958 struct msi_scrolltext_info *info;
961 TRACE("%p %04x %08lx %08lx\n", hWnd, msg, wParam, lParam);
963 info = GetPropW( hWnd, szButtonData );
965 r = CallWindowProcW( info->oldproc, hWnd, msg, wParam, lParam );
971 RemovePropW( hWnd, szButtonData );
974 /* native MSI sets a wait cursor here */
975 msi_dialog_button_handler( info->dialog, info->control, BN_CLICKED );
981 struct msi_streamin_info
988 static DWORD CALLBACK
989 msi_richedit_stream_in( DWORD_PTR arg, LPBYTE buffer, LONG count, LONG *pcb )
991 struct msi_streamin_info *info = (struct msi_streamin_info*) arg;
993 if( (count + info->offset) > info->length )
994 count = info->length - info->offset;
995 memcpy( buffer, &info->string[ info->offset ], count );
997 info->offset += count;
999 TRACE("%d/%d\n", info->offset, info->length);
1004 static void msi_scrolltext_add_text( msi_control *control, LPCWSTR text )
1006 struct msi_streamin_info info;
1009 info.string = strdupWtoA( text );
1011 info.length = lstrlenA( info.string ) + 1;
1013 es.dwCookie = (DWORD_PTR) &info;
1015 es.pfnCallback = msi_richedit_stream_in;
1017 SendMessageW( control->hwnd, EM_STREAMIN, SF_RTF, (LPARAM) &es );
1019 msi_free( info.string );
1022 static UINT msi_dialog_scrolltext_control( msi_dialog *dialog, MSIRECORD *rec )
1024 static const WCHAR szRichEdit20W[] = {
1025 'R','i','c','h','E','d','i','t','2','0','W',0
1027 struct msi_scrolltext_info *info;
1028 msi_control *control;
1033 info = msi_alloc( sizeof *info );
1035 return ERROR_FUNCTION_FAILED;
1037 hRichedit = LoadLibraryA("riched20");
1039 style = WS_BORDER | ES_MULTILINE | WS_VSCROLL |
1040 ES_READONLY | ES_AUTOVSCROLL | WS_TABSTOP;
1041 control = msi_dialog_add_control( dialog, rec, szRichEdit20W, style );
1044 FreeLibrary( hRichedit );
1046 return ERROR_FUNCTION_FAILED;
1049 control->hDll = hRichedit;
1051 info->dialog = dialog;
1052 info->control = control;
1054 /* subclass the static control */
1055 info->oldproc = (WNDPROC) SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
1056 (LONG_PTR)MSIScrollText_WndProc );
1057 SetPropW( control->hwnd, szButtonData, info );
1059 /* add the text into the richedit */
1060 text = MSI_RecordGetString( rec, 10 );
1062 msi_scrolltext_add_text( control, text );
1064 return ERROR_SUCCESS;
1067 static HBITMAP msi_load_picture( MSIDATABASE *db, LPCWSTR name,
1068 INT cx, INT cy, DWORD flags )
1070 HBITMAP hOleBitmap = 0, hBitmap = 0, hOldSrcBitmap, hOldDestBitmap;
1071 MSIRECORD *rec = NULL;
1072 IStream *stm = NULL;
1073 IPicture *pic = NULL;
1078 rec = msi_get_binary_record( db, name );
1082 r = MSI_RecordGetIStream( rec, 2, &stm );
1083 msiobj_release( &rec->hdr );
1084 if( r != ERROR_SUCCESS )
1087 r = OleLoadPicture( stm, 0, TRUE, &IID_IPicture, (LPVOID*) &pic );
1088 IStream_Release( stm );
1091 ERR("failed to load picture\n");
1095 r = IPicture_get_Handle( pic, (OLE_HANDLE*) &hOleBitmap );
1098 ERR("failed to get bitmap handle\n");
1102 /* make the bitmap the desired size */
1103 r = GetObjectW( hOleBitmap, sizeof bm, &bm );
1104 if (r != sizeof bm )
1106 ERR("failed to get bitmap size\n");
1110 if (flags & LR_DEFAULTSIZE)
1116 srcdc = CreateCompatibleDC( NULL );
1117 hOldSrcBitmap = SelectObject( srcdc, hOleBitmap );
1118 destdc = CreateCompatibleDC( NULL );
1119 hBitmap = CreateCompatibleBitmap( srcdc, cx, cy );
1120 hOldDestBitmap = SelectObject( destdc, hBitmap );
1121 StretchBlt( destdc, 0, 0, cx, cy,
1122 srcdc, 0, 0, bm.bmWidth, bm.bmHeight, SRCCOPY);
1123 SelectObject( srcdc, hOldSrcBitmap );
1124 SelectObject( destdc, hOldDestBitmap );
1130 IPicture_Release( pic );
1134 static UINT msi_dialog_bitmap_control( msi_dialog *dialog, MSIRECORD *rec )
1136 UINT cx, cy, flags, style, attributes;
1137 msi_control *control;
1140 flags = LR_LOADFROMFILE;
1141 style = SS_BITMAP | SS_LEFT | WS_GROUP;
1143 attributes = MSI_RecordGetInteger( rec, 8 );
1144 if( attributes & msidbControlAttributesFixedSize )
1146 flags |= LR_DEFAULTSIZE;
1147 style |= SS_CENTERIMAGE;
1150 control = msi_dialog_add_control( dialog, rec, szStatic, style );
1151 cx = MSI_RecordGetInteger( rec, 6 );
1152 cy = MSI_RecordGetInteger( rec, 7 );
1153 cx = msi_dialog_scale_unit( dialog, cx );
1154 cy = msi_dialog_scale_unit( dialog, cy );
1156 text = msi_get_deformatted_field( dialog->package, rec, 10 );
1157 control->hBitmap = msi_load_picture( dialog->package->db, text, cx, cy, flags );
1158 if( control->hBitmap )
1159 SendMessageW( control->hwnd, STM_SETIMAGE,
1160 IMAGE_BITMAP, (LPARAM) control->hBitmap );
1162 ERR("Failed to load bitmap %s\n", debugstr_w(text));
1166 return ERROR_SUCCESS;
1169 static UINT msi_dialog_icon_control( msi_dialog *dialog, MSIRECORD *rec )
1171 msi_control *control;
1177 control = msi_dialog_add_control( dialog, rec, szStatic,
1178 SS_ICON | SS_CENTERIMAGE | WS_GROUP );
1180 attributes = MSI_RecordGetInteger( rec, 8 );
1181 text = msi_get_deformatted_field( dialog->package, rec, 10 );
1182 control->hIcon = msi_load_icon( dialog->package->db, text, attributes );
1183 if( control->hIcon )
1184 SendMessageW( control->hwnd, STM_SETICON, (WPARAM) control->hIcon, 0 );
1186 ERR("Failed to load bitmap %s\n", debugstr_w(text));
1188 return ERROR_SUCCESS;
1191 static UINT msi_dialog_combo_control( msi_dialog *dialog, MSIRECORD *rec )
1193 static const WCHAR szCombo[] = { 'C','O','M','B','O','B','O','X',0 };
1194 DWORD attributes, style;
1196 style = CBS_AUTOHSCROLL | WS_TABSTOP | WS_GROUP | WS_CHILD;
1197 attributes = MSI_RecordGetInteger( rec, 8 );
1198 if ( ~attributes & msidbControlAttributesSorted)
1200 if ( attributes & msidbControlAttributesComboList)
1201 style |= CBS_DROPDOWNLIST;
1203 style |= CBS_DROPDOWN;
1205 msi_dialog_add_control( dialog, rec, szCombo, style );
1206 return ERROR_SUCCESS;
1209 /* length of 2^32 + 1 */
1210 #define MAX_NUM_DIGITS 11
1212 static UINT msi_dialog_edit_control( msi_dialog *dialog, MSIRECORD *rec )
1214 msi_control *control;
1216 LPWSTR val, begin, end;
1217 WCHAR num[MAX_NUM_DIGITS];
1220 control = msi_dialog_add_control( dialog, rec, szEdit,
1221 WS_BORDER | WS_TABSTOP | ES_AUTOHSCROLL );
1222 control->handler = msi_dialog_edit_handler;
1224 text = MSI_RecordGetString( rec, 10 );
1227 begin = strchrW( text, '{' );
1228 end = strchrW( text, '}' );
1230 if ( begin && end && end > begin &&
1231 begin[0] >= '0' && begin[0] <= '9' &&
1232 end - begin < MAX_NUM_DIGITS)
1234 lstrcpynW( num, begin + 1, end - begin );
1235 limit = atolW( num );
1237 SendMessageW( control->hwnd, EM_SETLIMITTEXT, limit, 0 );
1241 prop = MSI_RecordGetString( rec, 9 );
1243 control->property = strdupW( prop );
1245 val = msi_dup_property( dialog->package, control->property );
1246 SetWindowTextW( control->hwnd, val );
1248 return ERROR_SUCCESS;
1251 /******************** Masked Edit ********************************************/
1253 #define MASK_MAX_GROUPS 20
1255 struct msi_mask_group
1263 struct msi_maskedit_info
1271 struct msi_mask_group group[MASK_MAX_GROUPS];
1274 static BOOL msi_mask_editable( WCHAR type )
1289 static void msi_mask_control_change( struct msi_maskedit_info *info )
1294 val = msi_alloc( (info->num_chars+1)*sizeof(WCHAR) );
1295 for( i=0, n=0; i<info->num_groups; i++ )
1297 if( (info->group[i].len + n) > info->num_chars )
1299 ERR("can't fit control %d text into template\n",i);
1302 if (!msi_mask_editable(info->group[i].type))
1304 for(r=0; r<info->group[i].len; r++)
1305 val[n+r] = info->group[i].type;
1310 r = GetWindowTextW( info->group[i].hwnd, &val[n], info->group[i].len+1 );
1311 if( r != info->group[i].len )
1317 TRACE("%d/%d controls were good\n", i, info->num_groups);
1319 if( i == info->num_groups )
1321 TRACE("Set property %s to %s\n",
1322 debugstr_w(info->prop), debugstr_w(val) );
1323 CharUpperBuffW( val, info->num_chars );
1324 MSI_SetPropertyW( info->dialog->package, info->prop, val );
1325 msi_dialog_evaluate_control_conditions( info->dialog );
1330 /* now move to the next control if necessary */
1331 static VOID msi_mask_next_control( struct msi_maskedit_info *info, HWND hWnd )
1336 for( i=0; i<info->num_groups; i++ )
1337 if( info->group[i].hwnd == hWnd )
1340 /* don't move from the last control */
1341 if( i >= (info->num_groups-1) )
1344 len = SendMessageW( hWnd, WM_GETTEXTLENGTH, 0, 0 );
1345 if( len < info->group[i].len )
1348 hWndNext = GetNextDlgTabItem( GetParent( hWnd ), hWnd, FALSE );
1349 SetFocus( hWndNext );
1352 static LRESULT WINAPI
1353 MSIMaskedEdit_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
1355 struct msi_maskedit_info *info;
1358 TRACE("%p %04x %08lx %08lx\n", hWnd, msg, wParam, lParam);
1360 info = GetPropW(hWnd, szButtonData);
1362 r = CallWindowProcW(info->oldproc, hWnd, msg, wParam, lParam);
1367 if (HIWORD(wParam) == EN_CHANGE)
1369 msi_mask_control_change( info );
1370 msi_mask_next_control( info, (HWND) lParam );
1374 msi_free( info->prop );
1376 RemovePropW( hWnd, szButtonData );
1383 /* fish the various bits of the property out and put them in the control */
1385 msi_maskedit_set_text( struct msi_maskedit_info *info, LPCWSTR text )
1391 for( i = 0; i < info->num_groups; i++ )
1393 if( info->group[i].len < strlenW( p ) )
1395 LPWSTR chunk = strdupW( p );
1396 chunk[ info->group[i].len ] = 0;
1397 SetWindowTextW( info->group[i].hwnd, chunk );
1402 SetWindowTextW( info->group[i].hwnd, p );
1405 p += info->group[i].len;
1409 static struct msi_maskedit_info * msi_dialog_parse_groups( LPCWSTR mask )
1411 struct msi_maskedit_info * info = NULL;
1412 int i = 0, n = 0, total = 0;
1415 TRACE("masked control, template %s\n", debugstr_w(mask));
1420 info = msi_alloc_zero( sizeof *info );
1424 p = strchrW(mask, '<');
1430 for( i=0; i<MASK_MAX_GROUPS; i++ )
1432 /* stop at the end of the string */
1433 if( p[0] == 0 || p[0] == '>' )
1436 /* count the number of the same identifier */
1437 for( n=0; p[n] == p[0]; n++ )
1439 info->group[i].ofs = total;
1440 info->group[i].type = p[0];
1444 total++; /* an extra not part of the group */
1446 info->group[i].len = n;
1451 TRACE("%d characters in %d groups\n", total, i );
1452 if( i == MASK_MAX_GROUPS )
1453 ERR("too many groups in PIDTemplate %s\n", debugstr_w(mask));
1455 info->num_chars = total;
1456 info->num_groups = i;
1462 msi_maskedit_create_children( struct msi_maskedit_info *info, LPCWSTR font )
1464 DWORD width, height, style, wx, ww;
1469 style = WS_CHILD | WS_BORDER | WS_VISIBLE | WS_TABSTOP | ES_AUTOHSCROLL;
1471 GetClientRect( info->hwnd, &rect );
1473 width = rect.right - rect.left;
1474 height = rect.bottom - rect.top;
1476 for( i = 0; i < info->num_groups; i++ )
1478 if (!msi_mask_editable( info->group[i].type ))
1480 wx = (info->group[i].ofs * width) / info->num_chars;
1481 ww = (info->group[i].len * width) / info->num_chars;
1483 hwnd = CreateWindowW( szEdit, NULL, style, wx, 0, ww, height,
1484 info->hwnd, NULL, NULL, NULL );
1487 ERR("failed to create mask edit sub window\n");
1491 SendMessageW( hwnd, EM_LIMITTEXT, info->group[i].len, 0 );
1493 msi_dialog_set_font( info->dialog, hwnd,
1494 font?font:info->dialog->default_font );
1495 info->group[i].hwnd = hwnd;
1500 * office 2003 uses "73931<````=````=````=````=`````>@@@@@"
1501 * delphi 7 uses "<????-??????-??????-????>" and "<???-???>"
1502 * filemaker pro 7 uses "<^^^^=^^^^=^^^^=^^^^=^^^^=^^^^=^^^^^>"
1504 static UINT msi_dialog_maskedit_control( msi_dialog *dialog, MSIRECORD *rec )
1506 LPWSTR font_mask, val = NULL, font;
1507 struct msi_maskedit_info *info = NULL;
1508 UINT ret = ERROR_SUCCESS;
1509 msi_control *control;
1514 font_mask = msi_get_deformatted_field( dialog->package, rec, 10 );
1515 font = msi_dialog_get_style( font_mask, &mask );
1518 ERR("mask template is empty\n");
1522 info = msi_dialog_parse_groups( mask );
1525 ERR("template %s is invalid\n", debugstr_w(mask));
1529 info->dialog = dialog;
1531 control = msi_dialog_add_control( dialog, rec, szStatic,
1532 SS_OWNERDRAW | WS_GROUP | WS_VISIBLE );
1535 ERR("Failed to create maskedit container\n");
1536 ret = ERROR_FUNCTION_FAILED;
1539 SetWindowLongPtrW( control->hwnd, GWL_EXSTYLE, WS_EX_CONTROLPARENT );
1541 info->hwnd = control->hwnd;
1543 /* subclass the static control */
1544 info->oldproc = (WNDPROC) SetWindowLongPtrW( info->hwnd, GWLP_WNDPROC,
1545 (LONG_PTR)MSIMaskedEdit_WndProc );
1546 SetPropW( control->hwnd, szButtonData, info );
1548 prop = MSI_RecordGetString( rec, 9 );
1550 info->prop = strdupW( prop );
1552 msi_maskedit_create_children( info, font );
1556 val = msi_dup_property( dialog->package, prop );
1559 msi_maskedit_set_text( info, val );
1565 if( ret != ERROR_SUCCESS )
1567 msi_free( font_mask );
1572 /******************** Progress Bar *****************************************/
1574 static UINT msi_dialog_progress_bar( msi_dialog *dialog, MSIRECORD *rec )
1576 msi_control *control;
1578 control = msi_dialog_add_control( dialog, rec, PROGRESS_CLASSW, WS_VISIBLE );
1580 return ERROR_FUNCTION_FAILED;
1582 ControlEvent_SubscribeToEvent( dialog->package, dialog,
1583 szSetProgress, control->name, szProgress );
1584 return ERROR_SUCCESS;
1587 /******************** Path Edit ********************************************/
1589 struct msi_pathedit_info
1592 msi_control *control;
1596 static LPWSTR msi_get_window_text( HWND hwnd )
1602 buf = msi_alloc( sz*sizeof(WCHAR) );
1605 r = GetWindowTextW( hwnd, buf, sz );
1609 buf = msi_realloc( buf, sz*sizeof(WCHAR) );
1615 static void msi_dialog_update_pathedit( msi_dialog *dialog, msi_control *control )
1620 if (!control && !(control = msi_dialog_find_control_by_type( dialog, szPathEdit )))
1623 indirect = control->attributes & msidbControlAttributesIndirect;
1624 prop = msi_dialog_dup_property( dialog, control->property, indirect );
1625 path = msi_dialog_dup_property( dialog, prop, TRUE );
1627 SetWindowTextW( control->hwnd, path );
1628 SendMessageW( control->hwnd, EM_SETSEL, 0, -1 );
1634 /* FIXME: test when this should fail */
1635 static BOOL msi_dialog_verify_path( LPWSTR path )
1637 if ( !lstrlenW( path ) )
1640 if ( PathIsRelativeW( path ) )
1646 /* returns TRUE if the path is valid, FALSE otherwise */
1647 static BOOL msi_dialog_onkillfocus( msi_dialog *dialog, msi_control *control )
1653 indirect = control->attributes & msidbControlAttributesIndirect;
1654 prop = msi_dialog_dup_property( dialog, control->property, indirect );
1656 buf = msi_get_window_text( control->hwnd );
1658 if ( !msi_dialog_verify_path( buf ) )
1660 /* FIXME: display an error message box */
1661 ERR("Invalid path %s\n", debugstr_w( buf ));
1663 SetFocus( control->hwnd );
1668 MSI_SetPropertyW( dialog->package, prop, buf );
1671 msi_dialog_update_pathedit( dialog, control );
1673 TRACE("edit %s contents changed, set %s\n", debugstr_w(control->name),
1682 static LRESULT WINAPI MSIPathEdit_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
1684 struct msi_pathedit_info *info = GetPropW(hWnd, szButtonData);
1687 TRACE("%p %04x %08lx %08lx\n", hWnd, msg, wParam, lParam);
1689 if ( msg == WM_KILLFOCUS )
1691 /* if the path is invalid, don't handle this message */
1692 if ( !msi_dialog_onkillfocus( info->dialog, info->control ) )
1696 r = CallWindowProcW(info->oldproc, hWnd, msg, wParam, lParam);
1698 if ( msg == WM_NCDESTROY )
1701 RemovePropW( hWnd, szButtonData );
1707 static UINT msi_dialog_pathedit_control( msi_dialog *dialog, MSIRECORD *rec )
1709 struct msi_pathedit_info *info;
1710 msi_control *control;
1713 info = msi_alloc( sizeof *info );
1715 return ERROR_FUNCTION_FAILED;
1717 control = msi_dialog_add_control( dialog, rec, szEdit,
1718 WS_BORDER | WS_TABSTOP );
1719 control->attributes = MSI_RecordGetInteger( rec, 8 );
1720 prop = MSI_RecordGetString( rec, 9 );
1721 control->property = msi_dialog_dup_property( dialog, prop, FALSE );
1723 info->dialog = dialog;
1724 info->control = control;
1725 info->oldproc = (WNDPROC) SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
1726 (LONG_PTR)MSIPathEdit_WndProc );
1727 SetPropW( control->hwnd, szButtonData, info );
1729 msi_dialog_update_pathedit( dialog, control );
1731 return ERROR_SUCCESS;
1734 /* radio buttons are a bit different from normal controls */
1735 static UINT msi_dialog_create_radiobutton( MSIRECORD *rec, LPVOID param )
1737 radio_button_group_descr *group = param;
1738 msi_dialog *dialog = group->dialog;
1739 msi_control *control;
1740 LPCWSTR prop, text, name;
1741 DWORD style, attributes = group->attributes;
1743 style = WS_CHILD | BS_AUTORADIOBUTTON | BS_MULTILINE | WS_TABSTOP;
1744 name = MSI_RecordGetString( rec, 3 );
1745 text = MSI_RecordGetString( rec, 8 );
1746 if( attributes & msidbControlAttributesVisible )
1747 style |= WS_VISIBLE;
1748 if( ~attributes & msidbControlAttributesEnabled )
1749 style |= WS_DISABLED;
1751 control = msi_dialog_create_window( dialog, rec, 0, szButton, name, text,
1752 style, group->parent->hwnd );
1754 return ERROR_FUNCTION_FAILED;
1755 control->handler = msi_dialog_radiogroup_handler;
1757 if (!lstrcmpW(control->name, group->propval))
1758 SendMessageW(control->hwnd, BM_SETCHECK, BST_CHECKED, 0);
1760 prop = MSI_RecordGetString( rec, 1 );
1762 control->property = strdupW( prop );
1764 return ERROR_SUCCESS;
1767 static UINT msi_dialog_radiogroup_control( msi_dialog *dialog, MSIRECORD *rec )
1769 static const WCHAR query[] = {
1770 'S','E','L','E','C','T',' ','*',' ',
1771 'F','R','O','M',' ','R','a','d','i','o','B','u','t','t','o','n',' ',
1772 'W','H','E','R','E',' ',
1773 '`','P','r','o','p','e','r','t','y','`',' ','=',' ','\'','%','s','\'',0};
1776 msi_control *control;
1777 MSIQUERY *view = NULL;
1778 radio_button_group_descr group;
1779 MSIPACKAGE *package = dialog->package;
1781 DWORD attr, style = WS_GROUP;
1783 prop = MSI_RecordGetString( rec, 9 );
1785 TRACE("%p %p %s\n", dialog, rec, debugstr_w( prop ));
1787 attr = MSI_RecordGetInteger( rec, 8 );
1788 if (attr & msidbControlAttributesHasBorder)
1789 style |= BS_GROUPBOX;
1791 style |= BS_OWNERDRAW;
1793 /* Create parent group box to hold radio buttons */
1794 control = msi_dialog_add_control( dialog, rec, szButton, style );
1796 return ERROR_FUNCTION_FAILED;
1798 oldproc = (WNDPROC) SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
1799 (LONG_PTR)MSIRadioGroup_WndProc );
1800 SetPropW(control->hwnd, szButtonData, oldproc);
1801 SetWindowLongPtrW( control->hwnd, GWL_EXSTYLE, WS_EX_CONTROLPARENT );
1804 control->property = strdupW( prop );
1806 /* query the Radio Button table for all control in this group */
1807 r = MSI_OpenQuery( package->db, &view, query, prop );
1808 if( r != ERROR_SUCCESS )
1810 ERR("query failed for dialog %s radio group %s\n",
1811 debugstr_w(dialog->name), debugstr_w(prop));
1812 return ERROR_INVALID_PARAMETER;
1815 group.dialog = dialog;
1816 group.parent = control;
1817 group.attributes = MSI_RecordGetInteger( rec, 8 );
1818 group.propval = msi_dup_property( dialog->package, control->property );
1820 r = MSI_IterateRecords( view, 0, msi_dialog_create_radiobutton, &group );
1821 msiobj_release( &view->hdr );
1822 msi_free( group.propval );
1827 /******************** Selection Tree ***************************************/
1829 struct msi_selection_tree_info
1838 msi_seltree_sync_item_state( HWND hwnd, MSIFEATURE *feature, HTREEITEM hItem )
1841 DWORD index = feature->Action;
1843 TRACE("Feature %s -> %d %d %d\n", debugstr_w(feature->Title),
1844 feature->Installed, feature->Action, feature->ActionRequest);
1846 if (index == INSTALLSTATE_UNKNOWN)
1847 index = INSTALLSTATE_ABSENT;
1849 tvi.mask = TVIF_STATE;
1851 tvi.state = INDEXTOSTATEIMAGEMASK( index );
1852 tvi.stateMask = TVIS_STATEIMAGEMASK;
1854 SendMessageW( hwnd, TVM_SETITEMW, 0, (LPARAM) &tvi );
1858 msi_seltree_popup_menu( HWND hwnd, INT x, INT y )
1863 /* create a menu to display */
1864 hMenu = CreatePopupMenu();
1866 /* FIXME: load strings from resources */
1867 AppendMenuA( hMenu, MF_ENABLED, INSTALLSTATE_LOCAL, "Install feature locally");
1868 AppendMenuA( hMenu, MF_GRAYED, 0x1000, "Install entire feature");
1869 AppendMenuA( hMenu, MF_ENABLED, INSTALLSTATE_ADVERTISED, "Install on demand");
1870 AppendMenuA( hMenu, MF_ENABLED, INSTALLSTATE_ABSENT, "Don't install");
1871 r = TrackPopupMenu( hMenu, TPM_LEFTALIGN | TPM_TOPALIGN | TPM_RETURNCMD,
1872 x, y, 0, hwnd, NULL );
1873 DestroyMenu( hMenu );
1878 msi_seltree_feature_from_item( HWND hwnd, HTREEITEM hItem )
1882 /* get the feature from the item */
1883 memset( &tvi, 0, sizeof tvi );
1885 tvi.mask = TVIF_PARAM | TVIF_HANDLE;
1886 SendMessageW( hwnd, TVM_GETITEMW, 0, (LPARAM) &tvi );
1888 return (MSIFEATURE*) tvi.lParam;
1892 msi_seltree_menu( HWND hwnd, HTREEITEM hItem )
1894 struct msi_selection_tree_info *info;
1895 MSIFEATURE *feature;
1896 MSIPACKAGE *package;
1904 info = GetPropW(hwnd, szButtonData);
1905 package = info->dialog->package;
1907 feature = msi_seltree_feature_from_item( hwnd, hItem );
1910 ERR("item %p feature was NULL\n", hItem);
1914 /* get the item's rectangle to put the menu just below it */
1916 SendMessageW( hwnd, TVM_GETITEMRECT, 0, (LPARAM) &u.rc );
1917 MapWindowPoints( hwnd, NULL, u.pt, 2 );
1919 r = msi_seltree_popup_menu( hwnd, u.rc.left, u.rc.top );
1923 case INSTALLSTATE_LOCAL:
1924 case INSTALLSTATE_ADVERTISED:
1925 case INSTALLSTATE_ABSENT:
1926 msi_feature_set_state(package, feature, r);
1929 FIXME("select feature and all children\n");
1933 msi_seltree_sync_item_state( hwnd, feature, hItem );
1934 ACTION_UpdateComponentStates( package, feature->Feature );
1939 static MSIFEATURE *msi_seltree_get_selected_feature( msi_control *control )
1941 struct msi_selection_tree_info *info = GetPropW(control->hwnd, szButtonData);
1942 return msi_seltree_feature_from_item( control->hwnd, info->selected );
1945 static LRESULT WINAPI
1946 MSISelectionTree_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
1948 struct msi_selection_tree_info *info;
1949 TVHITTESTINFO tvhti;
1952 TRACE("%p %04x %08lx %08lx\n", hWnd, msg, wParam, lParam);
1954 info = GetPropW(hWnd, szButtonData);
1958 case WM_LBUTTONDOWN:
1959 tvhti.pt.x = (short)LOWORD( lParam );
1960 tvhti.pt.y = (short)HIWORD( lParam );
1963 r = CallWindowProcW(info->oldproc, hWnd, TVM_HITTEST, 0, (LPARAM) &tvhti );
1964 if (tvhti.flags & TVHT_ONITEMSTATEICON)
1965 return msi_seltree_menu( hWnd, tvhti.hItem );
1969 r = CallWindowProcW(info->oldproc, hWnd, msg, wParam, lParam);
1975 RemovePropW( hWnd, szButtonData );
1982 msi_seltree_add_child_features( MSIPACKAGE *package, HWND hwnd,
1983 LPCWSTR parent, HTREEITEM hParent )
1985 struct msi_selection_tree_info *info = GetPropW( hwnd, szButtonData );
1986 MSIFEATURE *feature;
1987 TVINSERTSTRUCTW tvis;
1988 HTREEITEM hitem, hfirst = NULL;
1990 LIST_FOR_EACH_ENTRY( feature, &package->features, MSIFEATURE, entry )
1992 if ( lstrcmpW( parent, feature->Feature_Parent ) )
1995 if ( !feature->Title )
1998 if ( !feature->Display )
2001 memset( &tvis, 0, sizeof tvis );
2002 tvis.hParent = hParent;
2003 tvis.hInsertAfter = TVI_LAST;
2004 tvis.u.item.mask = TVIF_TEXT | TVIF_PARAM;
2005 tvis.u.item.pszText = feature->Title;
2006 tvis.u.item.lParam = (LPARAM) feature;
2008 hitem = (HTREEITEM) SendMessageW( hwnd, TVM_INSERTITEMW, 0, (LPARAM) &tvis );
2015 msi_seltree_sync_item_state( hwnd, feature, hitem );
2016 msi_seltree_add_child_features( package, hwnd,
2017 feature->Feature, hitem );
2019 /* the node is expanded if Display is odd */
2020 if ( feature->Display % 2 != 0 )
2021 SendMessageW( hwnd, TVM_EXPAND, TVE_EXPAND, (LPARAM) hitem );
2024 /* select the first item */
2025 SendMessageW( hwnd, TVM_SELECTITEM, TVGN_CARET | TVGN_DROPHILITE, (LPARAM) hfirst );
2026 info->selected = hfirst;
2029 static void msi_seltree_create_imagelist( HWND hwnd )
2031 const int bm_width = 32, bm_height = 16, bm_count = 3;
2032 const int bm_resource = 0x1001;
2037 himl = ImageList_Create( bm_width, bm_height, FALSE, 4, 0 );
2040 ERR("failed to create image list\n");
2044 for (i=0; i<bm_count; i++)
2046 hbmp = LoadBitmapW( msi_hInstance, MAKEINTRESOURCEW(i+bm_resource) );
2049 ERR("failed to load bitmap %d\n", i);
2054 * Add a dummy bitmap at offset zero because the treeview
2055 * can't use it as a state mask (zero means no user state).
2058 ImageList_Add( himl, hbmp, NULL );
2060 ImageList_Add( himl, hbmp, NULL );
2063 SendMessageW( hwnd, TVM_SETIMAGELIST, TVSIL_STATE, (LPARAM)himl );
2066 static UINT msi_dialog_seltree_handler( msi_dialog *dialog,
2067 msi_control *control, WPARAM param )
2069 struct msi_selection_tree_info *info = GetPropW( control->hwnd, szButtonData );
2070 LPNMTREEVIEWW tv = (LPNMTREEVIEWW)param;
2071 MSIRECORD *row, *rec;
2073 MSIFEATURE *feature;
2074 LPCWSTR dir, title = NULL;
2075 UINT r = ERROR_SUCCESS;
2077 static const WCHAR select[] = {
2078 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2079 '`','F','e','a','t','u','r','e','`',' ','W','H','E','R','E',' ',
2080 '`','T','i','t','l','e','`',' ','=',' ','\'','%','s','\'',0
2083 if (tv->hdr.code != TVN_SELCHANGINGW)
2084 return ERROR_SUCCESS;
2086 info->selected = tv->itemNew.hItem;
2088 if (!(tv->itemNew.mask & TVIF_TEXT))
2090 feature = msi_seltree_feature_from_item( control->hwnd, tv->itemNew.hItem );
2092 title = feature->Title;
2095 title = tv->itemNew.pszText;
2097 row = MSI_QueryGetRecord( dialog->package->db, select, title );
2099 return ERROR_FUNCTION_FAILED;
2101 rec = MSI_CreateRecord( 1 );
2103 MSI_RecordSetStringW( rec, 1, MSI_RecordGetString( row, 4 ) );
2104 ControlEvent_FireSubscribedEvent( dialog->package, szSelectionDescription, rec );
2106 dir = MSI_RecordGetString( row, 7 );
2107 folder = get_loaded_folder( dialog->package, dir );
2110 r = ERROR_FUNCTION_FAILED;
2114 MSI_RecordSetStringW( rec, 1, folder->ResolvedTarget );
2115 ControlEvent_FireSubscribedEvent( dialog->package, szSelectionPath, rec );
2118 msiobj_release(&row->hdr);
2119 msiobj_release(&rec->hdr);
2124 static UINT msi_dialog_selection_tree( msi_dialog *dialog, MSIRECORD *rec )
2126 msi_control *control;
2128 MSIPACKAGE *package = dialog->package;
2130 struct msi_selection_tree_info *info;
2132 info = msi_alloc( sizeof *info );
2134 return ERROR_FUNCTION_FAILED;
2136 /* create the treeview control */
2137 style = TVS_HASLINES | TVS_HASBUTTONS | TVS_LINESATROOT;
2138 style |= WS_GROUP | WS_VSCROLL;
2139 control = msi_dialog_add_control( dialog, rec, WC_TREEVIEWW, style );
2143 return ERROR_FUNCTION_FAILED;
2146 control->handler = msi_dialog_seltree_handler;
2147 control->attributes = MSI_RecordGetInteger( rec, 8 );
2148 prop = MSI_RecordGetString( rec, 9 );
2149 control->property = msi_dialog_dup_property( dialog, prop, FALSE );
2152 info->dialog = dialog;
2153 info->hwnd = control->hwnd;
2154 info->oldproc = (WNDPROC) SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
2155 (LONG_PTR)MSISelectionTree_WndProc );
2156 SetPropW( control->hwnd, szButtonData, info );
2158 ControlEvent_SubscribeToEvent( dialog->package, dialog,
2159 szSelectionPath, control->name, szProperty );
2162 msi_seltree_create_imagelist( control->hwnd );
2163 msi_seltree_add_child_features( package, control->hwnd, NULL, NULL );
2165 return ERROR_SUCCESS;
2168 /******************** Group Box ***************************************/
2170 static UINT msi_dialog_group_box( msi_dialog *dialog, MSIRECORD *rec )
2172 msi_control *control;
2175 style = BS_GROUPBOX | WS_CHILD | WS_GROUP;
2176 control = msi_dialog_add_control( dialog, rec, WC_BUTTONW, style );
2178 return ERROR_FUNCTION_FAILED;
2180 return ERROR_SUCCESS;
2183 /******************** List Box ***************************************/
2185 struct msi_listbox_info
2195 static LRESULT WINAPI MSIListBox_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
2197 struct msi_listbox_info *info;
2201 TRACE("%p %04x %08lx %08lx\n", hWnd, msg, wParam, lParam);
2203 info = GetPropW( hWnd, szButtonData );
2207 r = CallWindowProcW( info->oldproc, hWnd, msg, wParam, lParam );
2212 for (j = 0; j < info->num_items; j++)
2213 msi_free( info->items[j] );
2214 msi_free( info->items );
2216 RemovePropW( hWnd, szButtonData );
2223 static UINT msi_listbox_add_item( MSIRECORD *rec, LPVOID param )
2225 struct msi_listbox_info *info = param;
2226 LPCWSTR value, text;
2229 value = MSI_RecordGetString( rec, 3 );
2230 text = MSI_RecordGetString( rec, 4 );
2232 info->items[info->addpos_items] = strdupW( value );
2234 pos = SendMessageW( info->hwnd, LB_ADDSTRING, 0, (LPARAM)text );
2235 SendMessageW( info->hwnd, LB_SETITEMDATA, pos, (LPARAM)info->items[info->addpos_items] );
2236 info->addpos_items++;
2237 return ERROR_SUCCESS;
2240 static UINT msi_listbox_add_items( struct msi_listbox_info *info, LPCWSTR property )
2243 MSIQUERY *view = NULL;
2246 static const WCHAR query[] = {
2247 'S','E','L','E','C','T',' ','*',' ',
2248 'F','R','O','M',' ','`','L','i','s','t','B','o','x','`',' ',
2249 'W','H','E','R','E',' ',
2250 '`','P','r','o','p','e','r','t','y','`',' ','=',' ','\'','%','s','\'',' ',
2251 'O','R','D','E','R',' ','B','Y',' ','`','O','r','d','e','r','`',0
2254 r = MSI_OpenQuery( info->dialog->package->db, &view, query, property );
2255 if ( r != ERROR_SUCCESS )
2258 /* just get the number of records */
2260 r = MSI_IterateRecords( view, &count, NULL, NULL );
2262 info->num_items = count;
2263 info->items = msi_alloc( sizeof(*info->items) * count );
2265 r = MSI_IterateRecords( view, NULL, msi_listbox_add_item, info );
2266 msiobj_release( &view->hdr );
2271 static UINT msi_dialog_listbox_handler( msi_dialog *dialog,
2272 msi_control *control, WPARAM param )
2274 struct msi_listbox_info *info;
2278 if( HIWORD(param) != LBN_SELCHANGE )
2279 return ERROR_SUCCESS;
2281 info = GetPropW( control->hwnd, szButtonData );
2282 index = SendMessageW( control->hwnd, LB_GETCURSEL, 0, 0 );
2283 value = (LPCWSTR) SendMessageW( control->hwnd, LB_GETITEMDATA, index, 0 );
2285 MSI_SetPropertyW( info->dialog->package,
2286 control->property, value );
2287 msi_dialog_evaluate_control_conditions( info->dialog );
2289 return ERROR_SUCCESS;
2292 static UINT msi_dialog_list_box( msi_dialog *dialog, MSIRECORD *rec )
2294 struct msi_listbox_info *info;
2295 msi_control *control;
2296 DWORD attributes, style;
2299 info = msi_alloc( sizeof *info );
2301 return ERROR_FUNCTION_FAILED;
2303 style = WS_TABSTOP | WS_GROUP | WS_CHILD | LBS_NOTIFY | WS_VSCROLL | WS_BORDER;
2304 attributes = MSI_RecordGetInteger( rec, 8 );
2305 if (~attributes & msidbControlAttributesSorted)
2308 control = msi_dialog_add_control( dialog, rec, WC_LISTBOXW, style );
2312 return ERROR_FUNCTION_FAILED;
2315 control->handler = msi_dialog_listbox_handler;
2317 prop = MSI_RecordGetString( rec, 9 );
2318 control->property = msi_dialog_dup_property( dialog, prop, FALSE );
2321 info->dialog = dialog;
2322 info->hwnd = control->hwnd;
2324 info->addpos_items = 0;
2325 info->oldproc = (WNDPROC)SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
2326 (LONG_PTR)MSIListBox_WndProc );
2327 SetPropW( control->hwnd, szButtonData, info );
2329 if ( control->property )
2330 msi_listbox_add_items( info, control->property );
2332 return ERROR_SUCCESS;
2335 /******************** Directory Combo ***************************************/
2337 static void msi_dialog_update_directory_combo( msi_dialog *dialog, msi_control *control )
2342 if (!control && !(control = msi_dialog_find_control_by_type( dialog, szDirectoryCombo )))
2345 indirect = control->attributes & msidbControlAttributesIndirect;
2346 prop = msi_dialog_dup_property( dialog, control->property, indirect );
2347 path = msi_dialog_dup_property( dialog, prop, TRUE );
2349 PathStripPathW( path );
2350 PathRemoveBackslashW( path );
2352 SendMessageW( control->hwnd, CB_INSERTSTRING, 0, (LPARAM)path );
2353 SendMessageW( control->hwnd, CB_SETCURSEL, 0, 0 );
2359 static UINT msi_dialog_directory_combo( msi_dialog *dialog, MSIRECORD *rec )
2361 msi_control *control;
2365 /* FIXME: use CBS_OWNERDRAWFIXED and add owner draw code */
2366 style = CBS_DROPDOWNLIST | CBS_HASSTRINGS | WS_CHILD |
2367 WS_GROUP | WS_TABSTOP | WS_VSCROLL;
2368 control = msi_dialog_add_control( dialog, rec, WC_COMBOBOXW, style );
2370 return ERROR_FUNCTION_FAILED;
2372 control->attributes = MSI_RecordGetInteger( rec, 8 );
2373 prop = MSI_RecordGetString( rec, 9 );
2374 control->property = msi_dialog_dup_property( dialog, prop, FALSE );
2376 msi_dialog_update_directory_combo( dialog, control );
2378 return ERROR_SUCCESS;
2381 /******************** Directory List ***************************************/
2383 static void msi_dialog_update_directory_list( msi_dialog *dialog, msi_control *control )
2385 WCHAR dir_spec[MAX_PATH];
2386 WIN32_FIND_DATAW wfd;
2392 static const WCHAR asterisk[] = {'*',0};
2393 static const WCHAR dot[] = {'.',0};
2394 static const WCHAR dotdot[] = {'.','.',0};
2396 if (!control && !(control = msi_dialog_find_control_by_type( dialog, szDirectoryList )))
2399 /* clear the list-view */
2400 SendMessageW( control->hwnd, LVM_DELETEALLITEMS, 0, 0 );
2402 indirect = control->attributes & msidbControlAttributesIndirect;
2403 prop = msi_dialog_dup_property( dialog, control->property, indirect );
2404 path = msi_dialog_dup_property( dialog, prop, TRUE );
2406 lstrcpyW( dir_spec, path );
2407 lstrcatW( dir_spec, asterisk );
2409 file = FindFirstFileW( dir_spec, &wfd );
2410 if ( file == INVALID_HANDLE_VALUE )
2415 if ( wfd.dwFileAttributes != FILE_ATTRIBUTE_DIRECTORY )
2418 if ( !lstrcmpW( wfd.cFileName, dot ) || !lstrcmpW( wfd.cFileName, dotdot ) )
2421 item.mask = LVIF_TEXT;
2422 item.cchTextMax = MAX_PATH;
2425 item.pszText = wfd.cFileName;
2427 SendMessageW( control->hwnd, LVM_INSERTITEMW, 0, (LPARAM)&item );
2428 } while ( FindNextFileW( file, &wfd ) );
2435 UINT msi_dialog_directorylist_up( msi_dialog *dialog )
2437 msi_control *control;
2438 LPWSTR prop, path, ptr;
2441 control = msi_dialog_find_control_by_type( dialog, szDirectoryList );
2442 indirect = control->attributes & msidbControlAttributesIndirect;
2443 prop = msi_dialog_dup_property( dialog, control->property, indirect );
2444 path = msi_dialog_dup_property( dialog, prop, TRUE );
2446 /* strip off the last directory */
2447 ptr = PathFindFileNameW( path );
2448 if (ptr != path) *(ptr - 1) = '\0';
2449 PathAddBackslashW( path );
2451 MSI_SetPropertyW( dialog->package, prop, path );
2453 msi_dialog_update_directory_list( dialog, NULL );
2454 msi_dialog_update_directory_combo( dialog, NULL );
2455 msi_dialog_update_pathedit( dialog, NULL );
2460 return ERROR_SUCCESS;
2463 static UINT msi_dialog_dirlist_handler( msi_dialog *dialog,
2464 msi_control *control, WPARAM param )
2466 LPNMHDR nmhdr = (LPNMHDR)param;
2467 WCHAR new_path[MAX_PATH];
2468 WCHAR text[MAX_PATH];
2474 static const WCHAR backslash[] = {'\\',0};
2476 if (nmhdr->code != LVN_ITEMACTIVATE)
2477 return ERROR_SUCCESS;
2479 index = SendMessageW( control->hwnd, LVM_GETNEXTITEM, -1, LVNI_SELECTED );
2482 ERR("No list-view item selected!\n");
2483 return ERROR_FUNCTION_FAILED;
2487 item.pszText = text;
2488 item.cchTextMax = MAX_PATH;
2489 SendMessageW( control->hwnd, LVM_GETITEMTEXTW, index, (LPARAM)&item );
2491 indirect = control->attributes & msidbControlAttributesIndirect;
2492 prop = msi_dialog_dup_property( dialog, control->property, indirect );
2493 path = msi_dialog_dup_property( dialog, prop, TRUE );
2495 lstrcpyW( new_path, path );
2496 lstrcatW( new_path, text );
2497 lstrcatW( new_path, backslash );
2499 MSI_SetPropertyW( dialog->package, prop, new_path );
2501 msi_dialog_update_directory_list( dialog, NULL );
2502 msi_dialog_update_directory_combo( dialog, NULL );
2503 msi_dialog_update_pathedit( dialog, NULL );
2507 return ERROR_SUCCESS;
2510 static UINT msi_dialog_directory_list( msi_dialog *dialog, MSIRECORD *rec )
2512 msi_control *control;
2516 style = LVS_LIST | WS_VSCROLL | LVS_SHAREIMAGELISTS |
2517 LVS_AUTOARRANGE | LVS_SINGLESEL | WS_BORDER |
2518 LVS_SORTASCENDING | WS_CHILD | WS_GROUP | WS_TABSTOP;
2519 control = msi_dialog_add_control( dialog, rec, WC_LISTVIEWW, style );
2521 return ERROR_FUNCTION_FAILED;
2523 control->attributes = MSI_RecordGetInteger( rec, 8 );
2524 control->handler = msi_dialog_dirlist_handler;
2525 prop = MSI_RecordGetString( rec, 9 );
2526 control->property = msi_dialog_dup_property( dialog, prop, FALSE );
2528 /* double click to activate an item in the list */
2529 SendMessageW( control->hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE,
2530 0, LVS_EX_TWOCLICKACTIVATE );
2532 msi_dialog_update_directory_list( dialog, control );
2534 return ERROR_SUCCESS;
2537 /******************** VolumeCost List ***************************************/
2539 static BOOL str_is_number( LPCWSTR str )
2543 for (i = 0; i < lstrlenW( str ); i++)
2544 if (!isdigitW(str[i]))
2550 static const WCHAR column_keys[][80] =
2552 {'V','o','l','u','m','e','C','o','s','t','V','o','l','u','m','e',0},
2553 {'V','o','l','u','m','e','C','o','s','t','S','i','z','e',0},
2554 {'V','o','l','u','m','e','C','o','s','t','A','v','a','i','l','a','b','l','e',0},
2555 {'V','o','l','u','m','e','C','o','s','t','R','e','q','u','i','r','e','d',0},
2556 {'V','o','l','u','m','e','C','o','s','t','D','i','f','f','e','r','e','n','c','e',0}
2559 static void msi_dialog_vcl_add_columns( msi_dialog *dialog, msi_control *control, MSIRECORD *rec )
2561 LPCWSTR text = MSI_RecordGetString( rec, 10 );
2562 LPCWSTR begin = text, end;
2567 static const WCHAR zero[] = {'0',0};
2568 static const WCHAR negative[] = {'-',0};
2572 while ((begin = strchrW( begin, '{' )) && count < 5)
2574 if (!(end = strchrW( begin, '}' )))
2577 num = msi_alloc( (end-begin+1)*sizeof(WCHAR) );
2581 lstrcpynW( num, begin + 1, end - begin );
2582 begin += end - begin + 1;
2584 /* empty braces or '0' hides the column */
2585 if ( !num[0] || !lstrcmpW( num, zero ) )
2592 /* the width must be a positive number
2593 * if a width is invalid, all remaining columns are hidden
2595 if ( !strncmpW( num, negative, 1 ) || !str_is_number( num ) ) {
2600 ZeroMemory( &lvc, sizeof(lvc) );
2601 lvc.mask = LVCF_TEXT | LVCF_WIDTH | LVCF_SUBITEM;
2602 lvc.cx = atolW( num );
2603 lvc.pszText = msi_dialog_get_uitext( dialog, column_keys[count] );
2605 SendMessageW( control->hwnd, LVM_INSERTCOLUMNW, count++, (LPARAM)&lvc );
2606 msi_free( lvc.pszText );
2611 static void msi_dialog_vcl_add_drives( msi_dialog *dialog, msi_control *control )
2613 ULARGE_INTEGER total, free;
2614 WCHAR size_text[MAX_PATH];
2620 size = GetLogicalDriveStringsW( 0, NULL );
2621 if ( !size ) return;
2623 drives = msi_alloc( (size + 1) * sizeof(WCHAR) );
2624 if ( !drives ) return;
2626 GetLogicalDriveStringsW( size, drives );
2631 lvitem.mask = LVIF_TEXT;
2633 lvitem.iSubItem = 0;
2634 lvitem.pszText = ptr;
2635 lvitem.cchTextMax = lstrlenW(ptr) + 1;
2636 SendMessageW( control->hwnd, LVM_INSERTITEMW, 0, (LPARAM)&lvitem );
2638 GetDiskFreeSpaceExW(ptr, &free, &total, NULL);
2640 StrFormatByteSizeW(total.QuadPart, size_text, MAX_PATH);
2641 lvitem.iSubItem = 1;
2642 lvitem.pszText = size_text;
2643 lvitem.cchTextMax = lstrlenW(size_text) + 1;
2644 SendMessageW( control->hwnd, LVM_SETITEMW, 0, (LPARAM)&lvitem );
2646 StrFormatByteSizeW(free.QuadPart, size_text, MAX_PATH);
2647 lvitem.iSubItem = 2;
2648 lvitem.pszText = size_text;
2649 lvitem.cchTextMax = lstrlenW(size_text) + 1;
2650 SendMessageW( control->hwnd, LVM_SETITEMW, 0, (LPARAM)&lvitem );
2652 ptr += lstrlenW(ptr) + 1;
2659 static UINT msi_dialog_volumecost_list( msi_dialog *dialog, MSIRECORD *rec )
2661 msi_control *control;
2664 style = LVS_REPORT | WS_VSCROLL | WS_HSCROLL | LVS_SHAREIMAGELISTS |
2665 LVS_AUTOARRANGE | LVS_SINGLESEL | WS_BORDER |
2666 WS_CHILD | WS_TABSTOP | WS_GROUP;
2667 control = msi_dialog_add_control( dialog, rec, WC_LISTVIEWW, style );
2669 return ERROR_FUNCTION_FAILED;
2671 msi_dialog_vcl_add_columns( dialog, control, rec );
2672 msi_dialog_vcl_add_drives( dialog, control );
2674 return ERROR_SUCCESS;
2677 /******************** VolumeSelect Combo ***************************************/
2679 static UINT msi_dialog_volsel_handler( msi_dialog *dialog,
2680 msi_control *control, WPARAM param )
2682 WCHAR text[MAX_PATH];
2687 if (HIWORD(param) != CBN_SELCHANGE)
2688 return ERROR_SUCCESS;
2690 index = SendMessageW( control->hwnd, CB_GETCURSEL, 0, 0 );
2691 if ( index == CB_ERR )
2693 ERR("No ComboBox item selected!\n");
2694 return ERROR_FUNCTION_FAILED;
2697 SendMessageW( control->hwnd, CB_GETLBTEXT, index, (LPARAM)text );
2699 indirect = control->attributes & msidbControlAttributesIndirect;
2700 prop = msi_dialog_dup_property( dialog, control->property, indirect );
2702 MSI_SetPropertyW( dialog->package, prop, text );
2705 return ERROR_SUCCESS;
2708 static void msi_dialog_vsc_add_drives( msi_dialog *dialog, msi_control *control )
2713 size = GetLogicalDriveStringsW( 0, NULL );
2714 if ( !size ) return;
2716 drives = msi_alloc( (size + 1) * sizeof(WCHAR) );
2717 if ( !drives ) return;
2719 GetLogicalDriveStringsW( size, drives );
2724 SendMessageW( control->hwnd, CB_ADDSTRING, 0, (LPARAM)ptr );
2725 ptr += lstrlenW(ptr) + 1;
2731 static UINT msi_dialog_volumeselect_combo( msi_dialog *dialog, MSIRECORD *rec )
2733 msi_control *control;
2737 /* FIXME: CBS_OWNERDRAWFIXED */
2738 style = WS_CHILD | WS_VISIBLE | WS_GROUP | WS_TABSTOP |
2739 CBS_DROPDOWNLIST | CBS_SORT | CBS_HASSTRINGS |
2740 WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_RIGHTSCROLLBAR;
2741 control = msi_dialog_add_control( dialog, rec, WC_COMBOBOXW, style );
2743 return ERROR_FUNCTION_FAILED;
2745 control->attributes = MSI_RecordGetInteger( rec, 8 );
2746 control->handler = msi_dialog_volsel_handler;
2747 prop = MSI_RecordGetString( rec, 9 );
2748 control->property = msi_dialog_dup_property( dialog, prop, FALSE );
2750 msi_dialog_vsc_add_drives( dialog, control );
2752 return ERROR_SUCCESS;
2755 static const struct control_handler msi_dialog_handler[] =
2757 { szText, msi_dialog_text_control },
2758 { szPushButton, msi_dialog_button_control },
2759 { szLine, msi_dialog_line_control },
2760 { szBitmap, msi_dialog_bitmap_control },
2761 { szCheckBox, msi_dialog_checkbox_control },
2762 { szScrollableText, msi_dialog_scrolltext_control },
2763 { szComboBox, msi_dialog_combo_control },
2764 { szEdit, msi_dialog_edit_control },
2765 { szMaskedEdit, msi_dialog_maskedit_control },
2766 { szPathEdit, msi_dialog_pathedit_control },
2767 { szProgressBar, msi_dialog_progress_bar },
2768 { szRadioButtonGroup, msi_dialog_radiogroup_control },
2769 { szIcon, msi_dialog_icon_control },
2770 { szSelectionTree, msi_dialog_selection_tree },
2771 { szGroupBox, msi_dialog_group_box },
2772 { szListBox, msi_dialog_list_box },
2773 { szDirectoryCombo, msi_dialog_directory_combo },
2774 { szDirectoryList, msi_dialog_directory_list },
2775 { szVolumeCostList, msi_dialog_volumecost_list },
2776 { szVolumeSelectCombo, msi_dialog_volumeselect_combo },
2779 #define NUM_CONTROL_TYPES (sizeof msi_dialog_handler/sizeof msi_dialog_handler[0])
2781 static UINT msi_dialog_create_controls( MSIRECORD *rec, LPVOID param )
2783 msi_dialog *dialog = param;
2784 LPCWSTR control_type;
2787 /* find and call the function that can create this type of control */
2788 control_type = MSI_RecordGetString( rec, 3 );
2789 for( i=0; i<NUM_CONTROL_TYPES; i++ )
2790 if (!strcmpiW( msi_dialog_handler[i].control_type, control_type ))
2792 if( i != NUM_CONTROL_TYPES )
2793 msi_dialog_handler[i].func( dialog, rec );
2795 ERR("no handler for element type %s\n", debugstr_w(control_type));
2797 return ERROR_SUCCESS;
2800 static UINT msi_dialog_fill_controls( msi_dialog *dialog )
2802 static const WCHAR query[] = {
2803 'S','E','L','E','C','T',' ','*',' ',
2804 'F','R','O','M',' ','C','o','n','t','r','o','l',' ',
2805 'W','H','E','R','E',' ',
2806 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',0};
2808 MSIQUERY *view = NULL;
2809 MSIPACKAGE *package = dialog->package;
2811 TRACE("%p %s\n", dialog, debugstr_w(dialog->name) );
2813 /* query the Control table for all the elements of the control */
2814 r = MSI_OpenQuery( package->db, &view, query, dialog->name );
2815 if( r != ERROR_SUCCESS )
2817 ERR("query failed for dialog %s\n", debugstr_w(dialog->name));
2818 return ERROR_INVALID_PARAMETER;
2821 r = MSI_IterateRecords( view, 0, msi_dialog_create_controls, dialog );
2822 msiobj_release( &view->hdr );
2827 static UINT msi_dialog_set_control_condition( MSIRECORD *rec, LPVOID param )
2829 static const WCHAR szHide[] = { 'H','i','d','e',0 };
2830 static const WCHAR szShow[] = { 'S','h','o','w',0 };
2831 static const WCHAR szDisable[] = { 'D','i','s','a','b','l','e',0 };
2832 static const WCHAR szEnable[] = { 'E','n','a','b','l','e',0 };
2833 static const WCHAR szDefault[] = { 'D','e','f','a','u','l','t',0 };
2834 msi_dialog *dialog = param;
2835 msi_control *control;
2836 LPCWSTR name, action, condition;
2839 name = MSI_RecordGetString( rec, 2 );
2840 action = MSI_RecordGetString( rec, 3 );
2841 condition = MSI_RecordGetString( rec, 4 );
2842 r = MSI_EvaluateConditionW( dialog->package, condition );
2843 control = msi_dialog_find_control( dialog, name );
2844 if( r == MSICONDITION_TRUE && control )
2846 TRACE("%s control %s\n", debugstr_w(action), debugstr_w(name));
2848 /* FIXME: case sensitive? */
2849 if(!lstrcmpW(action, szHide))
2850 ShowWindow(control->hwnd, SW_HIDE);
2851 else if(!strcmpW(action, szShow))
2852 ShowWindow(control->hwnd, SW_SHOW);
2853 else if(!strcmpW(action, szDisable))
2854 EnableWindow(control->hwnd, FALSE);
2855 else if(!strcmpW(action, szEnable))
2856 EnableWindow(control->hwnd, TRUE);
2857 else if(!strcmpW(action, szDefault))
2858 SetFocus(control->hwnd);
2860 FIXME("Unhandled action %s\n", debugstr_w(action));
2863 return ERROR_SUCCESS;
2866 static UINT msi_dialog_evaluate_control_conditions( msi_dialog *dialog )
2868 static const WCHAR query[] = {
2869 'S','E','L','E','C','T',' ','*',' ',
2870 'F','R','O','M',' ',
2871 'C','o','n','t','r','o','l','C','o','n','d','i','t','i','o','n',' ',
2872 'W','H','E','R','E',' ',
2873 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',0
2876 MSIQUERY *view = NULL;
2877 MSIPACKAGE *package = dialog->package;
2879 TRACE("%p %s\n", dialog, debugstr_w(dialog->name) );
2881 /* query the Control table for all the elements of the control */
2882 r = MSI_OpenQuery( package->db, &view, query, dialog->name );
2883 if( r != ERROR_SUCCESS )
2884 return ERROR_SUCCESS;
2886 r = MSI_IterateRecords( view, 0, msi_dialog_set_control_condition, dialog );
2887 msiobj_release( &view->hdr );
2892 UINT msi_dialog_reset( msi_dialog *dialog )
2894 /* FIXME: should restore the original values of any properties we changed */
2895 return msi_dialog_evaluate_control_conditions( dialog );
2898 /* figure out the height of 10 point MS Sans Serif */
2899 static INT msi_dialog_get_sans_serif_height( HWND hwnd )
2901 static const WCHAR szSansSerif[] = {
2902 'M','S',' ','S','a','n','s',' ','S','e','r','i','f',0 };
2907 HFONT hFont, hOldFont;
2910 hdc = GetDC( hwnd );
2913 memset( &lf, 0, sizeof lf );
2914 lf.lfHeight = MulDiv(10, GetDeviceCaps(hdc, LOGPIXELSY), 72);
2915 strcpyW( lf.lfFaceName, szSansSerif );
2916 hFont = CreateFontIndirectW(&lf);
2919 hOldFont = SelectObject( hdc, hFont );
2920 r = GetTextMetricsW( hdc, &tm );
2922 height = tm.tmHeight;
2923 SelectObject( hdc, hOldFont );
2924 DeleteObject( hFont );
2926 ReleaseDC( hwnd, hdc );
2931 /* fetch the associated record from the Dialog table */
2932 static MSIRECORD *msi_get_dialog_record( msi_dialog *dialog )
2934 static const WCHAR query[] = {
2935 'S','E','L','E','C','T',' ','*',' ',
2936 'F','R','O','M',' ','D','i','a','l','o','g',' ',
2937 'W','H','E','R','E',' ',
2938 '`','D','i','a','l','o','g','`',' ','=',' ','\'','%','s','\'',0};
2939 MSIPACKAGE *package = dialog->package;
2940 MSIRECORD *rec = NULL;
2942 TRACE("%p %s\n", dialog, debugstr_w(dialog->name) );
2944 rec = MSI_QueryGetRecord( package->db, query, dialog->name );
2946 WARN("query failed for dialog %s\n", debugstr_w(dialog->name));
2951 static void msi_dialog_adjust_dialog_pos( msi_dialog *dialog, MSIRECORD *rec, LPRECT pos )
2953 static const WCHAR szScreenX[] = {'S','c','r','e','e','n','X',0};
2954 static const WCHAR szScreenY[] = {'S','c','r','e','e','n','Y',0};
2961 center.x = MSI_RecordGetInteger( rec, 2 );
2962 center.y = MSI_RecordGetInteger( rec, 3 );
2964 sz.cx = MSI_RecordGetInteger( rec, 4 );
2965 sz.cy = MSI_RecordGetInteger( rec, 5 );
2967 sz.cx = msi_dialog_scale_unit( dialog, sz.cx );
2968 sz.cy = msi_dialog_scale_unit( dialog, sz.cy );
2970 xres = msi_get_property_int( dialog->package, szScreenX, 0 );
2971 yres = msi_get_property_int( dialog->package, szScreenY, 0 );
2973 center.x = MulDiv( center.x, xres, 100 );
2974 center.y = MulDiv( center.y, yres, 100 );
2976 /* turn the client pos into the window rectangle */
2977 if (dialog->package->center_x && dialog->package->center_y)
2979 pos->left = dialog->package->center_x - sz.cx / 2.0;
2980 pos->right = pos->left + sz.cx;
2981 pos->top = dialog->package->center_y - sz.cy / 2.0;
2982 pos->bottom = pos->top + sz.cy;
2986 pos->left = center.x - sz.cx/2;
2987 pos->right = pos->left + sz.cx;
2988 pos->top = center.y - sz.cy/2;
2989 pos->bottom = pos->top + sz.cy;
2991 /* save the center */
2992 dialog->package->center_x = center.x;
2993 dialog->package->center_y = center.y;
2996 dialog->size.cx = sz.cx;
2997 dialog->size.cy = sz.cy;
2999 TRACE("%u %u %u %u\n", pos->left, pos->top, pos->right, pos->bottom);
3001 style = GetWindowLongPtrW( dialog->hwnd, GWL_STYLE );
3002 AdjustWindowRect( pos, style, FALSE );
3005 static BOOL msi_control_set_next( msi_control *control, msi_control *next )
3007 return SetWindowPos( next->hwnd, control->hwnd, 0, 0, 0, 0,
3008 SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOREDRAW |
3009 SWP_NOREPOSITION | SWP_NOSENDCHANGING | SWP_NOSIZE );
3012 static UINT msi_dialog_set_tab_order( msi_dialog *dialog )
3014 msi_control *control, *tab_next;
3016 LIST_FOR_EACH_ENTRY( control, &dialog->controls, msi_control, entry )
3018 tab_next = msi_dialog_find_control( dialog, control->tabnext );
3021 msi_control_set_next( control, tab_next );
3024 return ERROR_SUCCESS;
3027 static void msi_dialog_set_first_control( msi_dialog* dialog, LPCWSTR name )
3029 msi_control *control;
3031 control = msi_dialog_find_control( dialog, name );
3033 dialog->hWndFocus = control->hwnd;
3035 dialog->hWndFocus = NULL;
3038 static LRESULT msi_dialog_oncreate( HWND hwnd, LPCREATESTRUCTW cs )
3040 static const WCHAR df[] = {
3041 'D','e','f','a','u','l','t','U','I','F','o','n','t',0 };
3042 static const WCHAR dfv[] = {
3043 'M','S',' ','S','h','e','l','l',' ','D','l','g',0 };
3044 msi_dialog *dialog = cs->lpCreateParams;
3045 MSIRECORD *rec = NULL;
3046 LPWSTR title = NULL;
3049 TRACE("%p %p\n", dialog, dialog->package);
3051 dialog->hwnd = hwnd;
3052 SetWindowLongPtrW( hwnd, GWLP_USERDATA, (LONG_PTR) dialog );
3054 rec = msi_get_dialog_record( dialog );
3057 TRACE("No record found for dialog %s\n", debugstr_w(dialog->name));
3061 dialog->scale = msi_dialog_get_sans_serif_height(dialog->hwnd);
3063 msi_dialog_adjust_dialog_pos( dialog, rec, &pos );
3065 dialog->attributes = MSI_RecordGetInteger( rec, 6 );
3067 dialog->default_font = msi_dup_property( dialog->package, df );
3068 if (!dialog->default_font)
3070 dialog->default_font = strdupW(dfv);
3071 if (!dialog->default_font) return -1;
3074 title = msi_get_deformatted_field( dialog->package, rec, 7 );
3075 SetWindowTextW( hwnd, title );
3078 SetWindowPos( hwnd, 0, pos.left, pos.top,
3079 pos.right - pos.left, pos.bottom - pos.top,
3080 SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOREDRAW );
3082 msi_dialog_build_font_list( dialog );
3083 msi_dialog_fill_controls( dialog );
3084 msi_dialog_evaluate_control_conditions( dialog );
3085 msi_dialog_set_tab_order( dialog );
3086 msi_dialog_set_first_control( dialog, MSI_RecordGetString( rec, 8 ) );
3087 msiobj_release( &rec->hdr );
3092 static UINT msi_dialog_send_event( msi_dialog *dialog, LPCWSTR event, LPCWSTR arg )
3094 LPWSTR event_fmt = NULL, arg_fmt = NULL;
3096 TRACE("Sending control event %s %s\n", debugstr_w(event), debugstr_w(arg));
3098 deformat_string( dialog->package, event, &event_fmt );
3099 deformat_string( dialog->package, arg, &arg_fmt );
3101 dialog->event_handler( dialog->package, event_fmt, arg_fmt, dialog );
3103 msi_free( event_fmt );
3104 msi_free( arg_fmt );
3106 return ERROR_SUCCESS;
3109 static UINT msi_dialog_set_property( msi_dialog *dialog, LPCWSTR event, LPCWSTR arg )
3111 static const WCHAR szNullArg[] = { '{','}',0 };
3112 LPWSTR p, prop, arg_fmt = NULL;
3115 len = strlenW(event);
3116 prop = msi_alloc( len*sizeof(WCHAR));
3117 strcpyW( prop, &event[1] );
3118 p = strchrW( prop, ']' );
3119 if( p && (p[1] == 0 || p[1] == ' ') )
3122 if( strcmpW( szNullArg, arg ) )
3123 deformat_string( dialog->package, arg, &arg_fmt );
3124 MSI_SetPropertyW( dialog->package, prop, arg_fmt );
3125 msi_dialog_update_controls( dialog, prop );
3126 msi_free( arg_fmt );
3129 ERR("Badly formatted property string - what happens?\n");
3131 return ERROR_SUCCESS;
3134 static UINT msi_dialog_control_event( MSIRECORD *rec, LPVOID param )
3136 msi_dialog *dialog = param;
3137 LPCWSTR condition, event, arg;
3140 condition = MSI_RecordGetString( rec, 5 );
3141 r = MSI_EvaluateConditionW( dialog->package, condition );
3142 if( r == MSICONDITION_TRUE || r == MSICONDITION_NONE )
3144 event = MSI_RecordGetString( rec, 3 );
3145 arg = MSI_RecordGetString( rec, 4 );
3146 if( event[0] == '[' )
3147 msi_dialog_set_property( dialog, event, arg );
3149 msi_dialog_send_event( dialog, event, arg );
3152 return ERROR_SUCCESS;
3161 static UINT add_rec_to_list( MSIRECORD *rec, LPVOID param )
3163 struct rec_list *add_rec;
3164 struct list *records = param;
3166 msiobj_addref( &rec->hdr );
3168 add_rec = msi_alloc( sizeof( *add_rec ) );
3171 msiobj_release( &rec->hdr );
3172 return ERROR_OUTOFMEMORY;
3176 list_add_tail( records, &add_rec->entry );
3177 return ERROR_SUCCESS;
3180 static inline void remove_rec_from_list( struct rec_list *rec_entry )
3182 msiobj_release( &rec_entry->rec->hdr );
3183 list_remove( &rec_entry->entry );
3184 msi_free( rec_entry );
3187 static UINT msi_dialog_button_handler( msi_dialog *dialog,
3188 msi_control *control, WPARAM param )
3190 static const WCHAR query[] = {
3191 'S','E','L','E','C','T',' ','*',' ',
3192 'F','R','O','M',' ','C','o','n','t','r','o','l','E','v','e','n','t',' ',
3193 'W','H','E','R','E',' ',
3194 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',' ',
3196 '`','C','o','n','t','r','o','l','_','`',' ','=',' ','\'','%','s','\'',' ',
3197 'O','R','D','E','R',' ','B','Y',' ','`','O','r','d','e','r','i','n','g','`',0
3199 MSIQUERY *view = NULL;
3200 struct rec_list *rec_entry, *next;
3204 if( HIWORD(param) != BN_CLICKED )
3205 return ERROR_SUCCESS;
3207 list_init( &events );
3209 r = MSI_OpenQuery( dialog->package->db, &view, query,
3210 dialog->name, control->name );
3211 if( r != ERROR_SUCCESS )
3213 ERR("query failed\n");
3217 r = MSI_IterateRecords( view, 0, add_rec_to_list, &events );
3218 msiobj_release( &view->hdr );
3219 if (r != ERROR_SUCCESS)
3222 /* handle all SetProperty events first */
3223 LIST_FOR_EACH_ENTRY_SAFE( rec_entry, next, &events, struct rec_list, entry )
3225 LPCWSTR event = MSI_RecordGetString( rec_entry->rec, 3 );
3227 if ( event[0] != '[' )
3230 r = msi_dialog_control_event( rec_entry->rec, dialog );
3231 remove_rec_from_list( rec_entry );
3233 if ( r != ERROR_SUCCESS )
3237 /* handle all other events */
3238 LIST_FOR_EACH_ENTRY_SAFE( rec_entry, next, &events, struct rec_list, entry )
3240 r = msi_dialog_control_event( rec_entry->rec, dialog );
3241 remove_rec_from_list( rec_entry );
3243 if ( r != ERROR_SUCCESS )
3248 LIST_FOR_EACH_ENTRY_SAFE( rec_entry, next, &events, struct rec_list, entry )
3250 remove_rec_from_list( rec_entry );
3256 static UINT msi_dialog_get_checkbox_state( msi_dialog *dialog,
3257 msi_control *control )
3259 WCHAR state[2] = { 0 };
3262 MSI_GetPropertyW( dialog->package, control->property, state, &sz );
3263 return state[0] ? 1 : 0;
3266 static void msi_dialog_set_checkbox_state( msi_dialog *dialog,
3267 msi_control *control, UINT state )
3269 static const WCHAR szState[] = { '1', 0 };
3272 /* if uncheck then the property is set to NULL */
3275 MSI_SetPropertyW( dialog->package, control->property, NULL );
3279 /* check for a custom state */
3280 if (control->value && control->value[0])
3281 val = control->value;
3285 MSI_SetPropertyW( dialog->package, control->property, val );
3288 static void msi_dialog_checkbox_sync_state( msi_dialog *dialog,
3289 msi_control *control )
3293 state = msi_dialog_get_checkbox_state( dialog, control );
3294 SendMessageW( control->hwnd, BM_SETCHECK,
3295 state ? BST_CHECKED : BST_UNCHECKED, 0 );
3298 static UINT msi_dialog_checkbox_handler( msi_dialog *dialog,
3299 msi_control *control, WPARAM param )
3303 if( HIWORD(param) != BN_CLICKED )
3304 return ERROR_SUCCESS;
3306 TRACE("clicked checkbox %s, set %s\n", debugstr_w(control->name),
3307 debugstr_w(control->property));
3309 state = msi_dialog_get_checkbox_state( dialog, control );
3310 state = state ? 0 : 1;
3311 msi_dialog_set_checkbox_state( dialog, control, state );
3312 msi_dialog_checkbox_sync_state( dialog, control );
3314 return msi_dialog_button_handler( dialog, control, param );
3317 static UINT msi_dialog_edit_handler( msi_dialog *dialog,
3318 msi_control *control, WPARAM param )
3322 if( HIWORD(param) != EN_CHANGE )
3323 return ERROR_SUCCESS;
3325 TRACE("edit %s contents changed, set %s\n", debugstr_w(control->name),
3326 debugstr_w(control->property));
3328 buf = msi_get_window_text( control->hwnd );
3329 MSI_SetPropertyW( dialog->package, control->property, buf );
3333 return ERROR_SUCCESS;
3336 static UINT msi_dialog_radiogroup_handler( msi_dialog *dialog,
3337 msi_control *control, WPARAM param )
3339 if( HIWORD(param) != BN_CLICKED )
3340 return ERROR_SUCCESS;
3342 TRACE("clicked radio button %s, set %s\n", debugstr_w(control->name),
3343 debugstr_w(control->property));
3345 MSI_SetPropertyW( dialog->package, control->property, control->name );
3347 return msi_dialog_button_handler( dialog, control, param );
3350 static LRESULT msi_dialog_oncommand( msi_dialog *dialog, WPARAM param, HWND hwnd )
3352 msi_control *control = NULL;
3354 TRACE("%p %p %08lx\n", dialog, hwnd, param);
3359 control = msi_dialog_find_control( dialog, dialog->control_default );
3361 case 2: /* escape */
3362 control = msi_dialog_find_control( dialog, dialog->control_cancel );
3365 control = msi_dialog_find_control_by_hwnd( dialog, hwnd );
3370 if( control->handler )
3372 control->handler( dialog, control, param );
3373 msi_dialog_evaluate_control_conditions( dialog );
3380 static LRESULT msi_dialog_onnotify( msi_dialog *dialog, LPARAM param )
3382 LPNMHDR nmhdr = (LPNMHDR) param;
3383 msi_control *control = msi_dialog_find_control_by_hwnd( dialog, nmhdr->hwndFrom );
3385 TRACE("%p %p\n", dialog, nmhdr->hwndFrom);
3387 if ( control && control->handler )
3388 control->handler( dialog, control, param );
3393 static void msi_dialog_setfocus( msi_dialog *dialog )
3395 HWND hwnd = dialog->hWndFocus;
3397 hwnd = GetNextDlgTabItem( dialog->hwnd, hwnd, TRUE);
3398 hwnd = GetNextDlgTabItem( dialog->hwnd, hwnd, FALSE);
3400 dialog->hWndFocus = hwnd;
3403 static LRESULT WINAPI MSIDialog_WndProc( HWND hwnd, UINT msg,
3404 WPARAM wParam, LPARAM lParam )
3406 msi_dialog *dialog = (LPVOID) GetWindowLongPtrW( hwnd, GWLP_USERDATA );
3408 TRACE("0x%04x\n", msg);
3413 dialog->package->center_x = LOWORD(lParam) + dialog->size.cx / 2.0;
3414 dialog->package->center_y = HIWORD(lParam) + dialog->size.cy / 2.0;
3418 return msi_dialog_oncreate( hwnd, (LPCREATESTRUCTW)lParam );
3421 return msi_dialog_oncommand( dialog, wParam, (HWND)lParam );
3424 if( LOWORD(wParam) == WA_INACTIVE )
3425 dialog->hWndFocus = GetFocus();
3427 msi_dialog_setfocus( dialog );
3431 msi_dialog_setfocus( dialog );
3434 /* bounce back to our subclassed static control */
3435 case WM_CTLCOLORSTATIC:
3436 return SendMessageW( (HWND) lParam, WM_CTLCOLORSTATIC, wParam, lParam );
3439 dialog->hwnd = NULL;
3442 return msi_dialog_onnotify( dialog, lParam );
3444 return DefWindowProcW(hwnd, msg, wParam, lParam);
3447 static BOOL CALLBACK msi_radioground_child_enum( HWND hWnd, LPARAM lParam )
3449 EnableWindow( hWnd, lParam );
3453 static LRESULT WINAPI MSIRadioGroup_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
3455 WNDPROC oldproc = (WNDPROC) GetPropW(hWnd, szButtonData);
3458 TRACE("hWnd %p msg %04x wParam 0x%08lx lParam 0x%08lx\n", hWnd, msg, wParam, lParam);
3460 if (msg == WM_COMMAND) /* Forward notifications to dialog */
3461 SendMessageW(GetParent(hWnd), msg, wParam, lParam);
3463 r = CallWindowProcW(oldproc, hWnd, msg, wParam, lParam);
3465 /* make sure the radio buttons show as disabled if the parent is disabled */
3466 if (msg == WM_ENABLE)
3467 EnumChildWindows( hWnd, msi_radioground_child_enum, wParam );
3472 static LRESULT WINAPI MSIHiddenWindowProc( HWND hwnd, UINT msg,
3473 WPARAM wParam, LPARAM lParam )
3475 msi_dialog *dialog = (msi_dialog*) lParam;
3477 TRACE("%d %p\n", msg, dialog);
3481 case WM_MSI_DIALOG_CREATE:
3482 return msi_dialog_run_message_loop( dialog );
3483 case WM_MSI_DIALOG_DESTROY:
3484 msi_dialog_destroy( dialog );
3487 return DefWindowProcW( hwnd, msg, wParam, lParam );
3490 static BOOL msi_dialog_register_class( void )
3494 ZeroMemory( &cls, sizeof cls );
3495 cls.lpfnWndProc = MSIDialog_WndProc;
3496 cls.hInstance = NULL;
3497 cls.hIcon = LoadIconW(0, (LPWSTR)IDI_APPLICATION);
3498 cls.hCursor = LoadCursorW(0, (LPWSTR)IDC_ARROW);
3499 cls.hbrBackground = (HBRUSH)(COLOR_3DFACE + 1);
3500 cls.lpszMenuName = NULL;
3501 cls.lpszClassName = szMsiDialogClass;
3503 if( !RegisterClassW( &cls ) )
3506 cls.lpfnWndProc = MSIHiddenWindowProc;
3507 cls.lpszClassName = szMsiHiddenWindow;
3509 if( !RegisterClassW( &cls ) )
3512 uiThreadId = GetCurrentThreadId();
3514 hMsiHiddenWindow = CreateWindowW( szMsiHiddenWindow, NULL, WS_OVERLAPPED,
3515 0, 0, 100, 100, NULL, NULL, NULL, NULL );
3516 if( !hMsiHiddenWindow )
3522 /* functions that interface to other modules within MSI */
3524 msi_dialog *msi_dialog_create( MSIPACKAGE* package,
3525 LPCWSTR szDialogName, msi_dialog *parent,
3526 msi_dialog_event_handler event_handler )
3528 MSIRECORD *rec = NULL;
3531 TRACE("%p %s\n", package, debugstr_w(szDialogName));
3533 if (!hMsiHiddenWindow)
3534 msi_dialog_register_class();
3536 /* allocate the structure for the dialog to use */
3537 dialog = msi_alloc_zero( sizeof *dialog + sizeof(WCHAR)*strlenW(szDialogName) );
3540 strcpyW( dialog->name, szDialogName );
3541 dialog->parent = parent;
3542 msiobj_addref( &package->hdr );
3543 dialog->package = package;
3544 dialog->event_handler = event_handler;
3545 dialog->finished = 0;
3546 list_init( &dialog->controls );
3548 /* verify that the dialog exists */
3549 rec = msi_get_dialog_record( dialog );
3552 msiobj_release( &package->hdr );
3556 dialog->attributes = MSI_RecordGetInteger( rec, 6 );
3557 dialog->control_default = strdupW( MSI_RecordGetString( rec, 9 ) );
3558 dialog->control_cancel = strdupW( MSI_RecordGetString( rec, 10 ) );
3559 msiobj_release( &rec->hdr );
3564 static void msi_process_pending_messages( HWND hdlg )
3568 while( PeekMessageW( &msg, 0, 0, 0, PM_REMOVE ) )
3570 if( hdlg && IsDialogMessageW( hdlg, &msg ))
3572 TranslateMessage( &msg );
3573 DispatchMessageW( &msg );
3577 void msi_dialog_end_dialog( msi_dialog *dialog )
3579 TRACE("%p\n", dialog);
3580 dialog->finished = 1;
3581 PostMessageW(dialog->hwnd, WM_NULL, 0, 0);
3584 void msi_dialog_check_messages( HANDLE handle )
3588 /* in threads other than the UI thread, block */
3589 if( uiThreadId != GetCurrentThreadId() )
3592 WaitForSingleObject( handle, INFINITE );
3596 /* there's two choices for the UI thread */
3599 msi_process_pending_messages( NULL );
3605 * block here until somebody creates a new dialog or
3606 * the handle we're waiting on becomes ready
3608 r = MsgWaitForMultipleObjects( 1, &handle, 0, INFINITE, QS_ALLINPUT );
3609 if( r == WAIT_OBJECT_0 )
3614 UINT msi_dialog_run_message_loop( msi_dialog *dialog )
3619 if( uiThreadId != GetCurrentThreadId() )
3620 return SendMessageW( hMsiHiddenWindow, WM_MSI_DIALOG_CREATE, 0, (LPARAM) dialog );
3622 /* create the dialog window, don't show it yet */
3623 style = WS_OVERLAPPED;
3624 if( dialog->attributes & msidbDialogAttributesVisible )
3625 style |= WS_VISIBLE;
3627 hwnd = CreateWindowW( szMsiDialogClass, dialog->name, style,
3628 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
3629 NULL, NULL, NULL, dialog );
3632 ERR("Failed to create dialog %s\n", debugstr_w( dialog->name ));
3633 return ERROR_FUNCTION_FAILED;
3636 ShowWindow( hwnd, SW_SHOW );
3637 /* UpdateWindow( hwnd ); - and causes the transparent static controls not to paint */
3639 if( dialog->attributes & msidbDialogAttributesModal )
3641 while( !dialog->finished )
3643 MsgWaitForMultipleObjects( 0, NULL, 0, INFINITE, QS_ALLINPUT );
3644 msi_process_pending_messages( dialog->hwnd );
3648 return ERROR_IO_PENDING;
3650 return ERROR_SUCCESS;
3653 void msi_dialog_do_preview( msi_dialog *dialog )
3656 dialog->attributes |= msidbDialogAttributesVisible;
3657 dialog->attributes &= ~msidbDialogAttributesModal;
3658 msi_dialog_run_message_loop( dialog );
3661 void msi_dialog_destroy( msi_dialog *dialog )
3663 if( uiThreadId != GetCurrentThreadId() )
3665 SendMessageW( hMsiHiddenWindow, WM_MSI_DIALOG_DESTROY, 0, (LPARAM) dialog );
3670 ShowWindow( dialog->hwnd, SW_HIDE );
3673 DestroyWindow( dialog->hwnd );
3675 /* unsubscribe events */
3676 ControlEvent_CleanupDialogSubscriptions(dialog->package, dialog->name);
3678 /* destroy the list of controls */
3679 while( !list_empty( &dialog->controls ) )
3683 t = LIST_ENTRY( list_head( &dialog->controls ),
3684 msi_control, entry );
3685 msi_destroy_control( t );
3688 /* destroy the list of fonts */
3689 while( dialog->font_list )
3691 msi_font *t = dialog->font_list;
3692 dialog->font_list = t->next;
3693 DeleteObject( t->hfont );
3696 msi_free( dialog->default_font );
3698 msi_free( dialog->control_default );
3699 msi_free( dialog->control_cancel );
3700 msiobj_release( &dialog->package->hdr );
3701 dialog->package = NULL;
3705 void msi_dialog_unregister_class( void )
3707 DestroyWindow( hMsiHiddenWindow );
3708 hMsiHiddenWindow = NULL;
3709 UnregisterClassW( szMsiDialogClass, NULL );
3710 UnregisterClassW( szMsiHiddenWindow, NULL );
3714 static UINT error_dialog_handler(MSIPACKAGE *package, LPCWSTR event,
3715 LPCWSTR argument, msi_dialog* dialog)
3717 static const WCHAR end_dialog[] = {'E','n','d','D','i','a','l','o','g',0};
3718 static const WCHAR error_abort[] = {'E','r','r','o','r','A','b','o','r','t',0};
3719 static const WCHAR error_cancel[] = {'E','r','r','o','r','C','a','n','c','e','l',0};
3720 static const WCHAR error_no[] = {'E','r','r','o','r','N','o',0};
3721 static const WCHAR result_prop[] = {
3722 'M','S','I','E','r','r','o','r','D','i','a','l','o','g','R','e','s','u','l','t',0
3725 if ( lstrcmpW( event, end_dialog ) )
3726 return ERROR_SUCCESS;
3728 if ( !lstrcmpW( argument, error_abort ) || !lstrcmpW( argument, error_cancel ) ||
3729 !lstrcmpW( argument, error_no ) )
3731 MSI_SetPropertyW( package, result_prop, error_abort );
3734 ControlEvent_CleanupSubscriptions(package);
3735 msi_dialog_end_dialog( dialog );
3737 return ERROR_SUCCESS;
3740 static UINT msi_error_dialog_set_error( MSIPACKAGE *package, LPWSTR error_dialog, LPWSTR error )
3744 static const WCHAR update[] =
3745 {'U','P','D','A','T','E',' ','`','C','o','n','t','r','o','l','`',' ',
3746 'S','E','T',' ','`','T','e','x','t','`',' ','=',' ','\'','%','s','\'',' ',
3747 'W','H','E','R','E', ' ','`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',' ',
3748 'A','N','D',' ','`','C','o','n','t','r','o','l','`',' ','=',' ',
3749 '\'','E','r','r','o','r','T','e','x','t','\'',0};
3751 row = MSI_QueryGetRecord( package->db, update, error, error_dialog );
3753 return ERROR_FUNCTION_FAILED;
3755 msiobj_release(&row->hdr);
3756 return ERROR_SUCCESS;
3759 UINT msi_spawn_error_dialog( MSIPACKAGE *package, LPWSTR error_dialog, LPWSTR error )
3762 WCHAR result[MAX_PATH];
3763 UINT r = ERROR_SUCCESS;
3764 DWORD size = MAX_PATH;
3767 static const WCHAR szUILevel[] = {'U','I','L','e','v','e','l',0};
3768 static const WCHAR pn_prop[] = {'P','r','o','d','u','c','t','N','a','m','e',0};
3769 static const WCHAR title_fmt[] = {'%','s',' ','W','a','r','n','i','n','g',0};
3770 static const WCHAR error_abort[] = {'E','r','r','o','r','A','b','o','r','t',0};
3771 static const WCHAR result_prop[] = {
3772 'M','S','I','E','r','r','o','r','D','i','a','l','o','g','R','e','s','u','l','t',0
3775 if ( (msi_get_property_int(package, szUILevel, 0) & INSTALLUILEVEL_MASK) == INSTALLUILEVEL_NONE )
3776 return ERROR_SUCCESS;
3778 if ( !error_dialog )
3780 LPWSTR product_name = msi_dup_property( package, pn_prop );
3781 WCHAR title[MAX_PATH];
3783 sprintfW( title, title_fmt, product_name );
3784 res = MessageBoxW( NULL, error, title, MB_OKCANCEL | MB_ICONWARNING );
3786 msi_free( product_name );
3789 return ERROR_SUCCESS;
3791 return ERROR_FUNCTION_FAILED;
3794 r = msi_error_dialog_set_error( package, error_dialog, error );
3795 if ( r != ERROR_SUCCESS )
3798 dialog = msi_dialog_create( package, error_dialog, package->dialog,
3799 error_dialog_handler );
3801 return ERROR_FUNCTION_FAILED;
3803 dialog->finished = FALSE;
3804 r = msi_dialog_run_message_loop( dialog );
3805 if ( r != ERROR_SUCCESS )
3808 r = MSI_GetPropertyW( package, result_prop, result, &size );
3809 if ( r != ERROR_SUCCESS)
3812 if ( !lstrcmpW( result, error_abort ) )
3813 r = ERROR_FUNCTION_FAILED;
3816 msi_dialog_destroy( dialog );