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"
47 WINE_DEFAULT_DEBUG_CHANNEL(msi);
50 extern HINSTANCE msi_hInstance;
52 struct msi_control_tag;
53 typedef struct msi_control_tag msi_control;
54 typedef UINT (*msi_handler)( msi_dialog *, msi_control *, WPARAM );
56 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 szRadioButtonGroup[] = {
139 'R','a','d','i','o','B','u','t','t','o','n','G','r','o','u','p',0 };
140 static const WCHAR szIcon[] = { 'I','c','o','n',0 };
141 static const WCHAR szSelectionTree[] = {
142 'S','e','l','e','c','t','i','o','n','T','r','e','e',0 };
143 static const WCHAR szGroupBox[] = { 'G','r','o','u','p','B','o','x',0 };
144 static const WCHAR szListBox[] = { 'L','i','s','t','B','o','x',0 };
145 static const WCHAR szDirectoryCombo[] = { 'D','i','r','e','c','t','o','r','y','C','o','m','b','o',0 };
146 static const WCHAR szDirectoryList[] = { 'D','i','r','e','c','t','o','r','y','L','i','s','t',0 };
147 static const WCHAR szVolumeCostList[] = { 'V','o','l','u','m','e','C','o','s','t','L','i','s','t',0 };
148 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};
149 static const WCHAR szSelectionPath[] = {'S','e','l','e','c','t','i','o','n','P','a','t','h',0};
150 static const WCHAR szProperty[] = {'P','r','o','p','e','r','t','y',0};
152 static UINT msi_dialog_checkbox_handler( msi_dialog *, msi_control *, WPARAM );
153 static void msi_dialog_checkbox_sync_state( msi_dialog *, msi_control * );
154 static UINT msi_dialog_button_handler( msi_dialog *, msi_control *, WPARAM );
155 static UINT msi_dialog_edit_handler( msi_dialog *, msi_control *, WPARAM );
156 static UINT msi_dialog_radiogroup_handler( msi_dialog *, msi_control *, WPARAM param );
157 static UINT msi_dialog_evaluate_control_conditions( msi_dialog *dialog );
158 static LRESULT WINAPI MSIRadioGroup_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
159 static MSIFEATURE *msi_seltree_get_selected_feature( msi_control *control );
161 /* dialog sequencing */
163 #define WM_MSI_DIALOG_CREATE (WM_USER+0x100)
164 #define WM_MSI_DIALOG_DESTROY (WM_USER+0x101)
166 static DWORD uiThreadId;
167 static HWND hMsiHiddenWindow;
169 static INT msi_dialog_scale_unit( msi_dialog *dialog, INT val )
171 return (dialog->scale * val + 5) / 10;
174 static msi_control *msi_dialog_find_control( msi_dialog *dialog, LPCWSTR name )
176 msi_control *control;
180 LIST_FOR_EACH_ENTRY( control, &dialog->controls, msi_control, entry )
181 if( !strcmpW( control->name, name ) ) /* FIXME: case sensitive? */
186 static msi_control *msi_dialog_find_control_by_type( msi_dialog *dialog, LPCWSTR type )
188 msi_control *control;
192 LIST_FOR_EACH_ENTRY( control, &dialog->controls, msi_control, entry )
193 if( !strcmpW( control->type, type ) ) /* FIXME: case sensitive? */
198 static msi_control *msi_dialog_find_control_by_hwnd( msi_dialog *dialog, HWND hwnd )
200 msi_control *control;
202 LIST_FOR_EACH_ENTRY( control, &dialog->controls, msi_control, entry )
203 if( hwnd == control->hwnd )
208 static LPWSTR msi_get_deformatted_field( MSIPACKAGE *package, MSIRECORD *rec, int field )
210 LPCWSTR str = MSI_RecordGetString( rec, field );
214 deformat_string( package, str, &ret );
218 static LPWSTR msi_dialog_dup_property( msi_dialog *dialog, LPCWSTR property, BOOL indirect )
226 prop = msi_dup_property( dialog->package, property );
229 prop = strdupW( property );
234 msi_dialog *msi_dialog_get_parent( msi_dialog *dialog )
236 return dialog->parent;
239 LPWSTR msi_dialog_get_name( msi_dialog *dialog )
245 * msi_dialog_get_style
247 * Extract the {\style} string from the front of the text to display and
248 * update the pointer. Only the last style in a list is applied.
250 static LPWSTR msi_dialog_get_style( LPCWSTR p, LPCWSTR *rest )
261 while ((first = strchrW( p, '{' )) && (q = strchrW( first + 1, '}' )))
264 if( *p == '\\' || *p == '&' )
267 /* little bit of sanity checking to stop us getting confused with RTF */
269 if( *i == '}' || *i == '\\' )
279 ret = msi_alloc( len*sizeof(WCHAR) );
282 memcpy( ret, p, len*sizeof(WCHAR) );
287 static UINT msi_dialog_add_font( MSIRECORD *rec, LPVOID param )
289 msi_dialog *dialog = param;
296 /* create a font and add it to the list */
297 name = MSI_RecordGetString( rec, 1 );
298 font = msi_alloc( sizeof *font + strlenW( name )*sizeof (WCHAR) );
299 strcpyW( font->name, name );
300 font->next = dialog->font_list;
301 dialog->font_list = font;
303 font->color = MSI_RecordGetInteger( rec, 4 );
305 memset( &lf, 0, sizeof lf );
306 face = MSI_RecordGetString( rec, 2 );
307 lf.lfHeight = MSI_RecordGetInteger( rec, 3 );
308 style = MSI_RecordGetInteger( rec, 5 );
309 if( style & msidbTextStyleStyleBitsBold )
310 lf.lfWeight = FW_BOLD;
311 if( style & msidbTextStyleStyleBitsItalic )
313 if( style & msidbTextStyleStyleBitsUnderline )
314 lf.lfUnderline = TRUE;
315 if( style & msidbTextStyleStyleBitsStrike )
316 lf.lfStrikeOut = TRUE;
317 lstrcpynW( lf.lfFaceName, face, LF_FACESIZE );
319 /* adjust the height */
320 hdc = GetDC( dialog->hwnd );
323 lf.lfHeight = -MulDiv(lf.lfHeight, GetDeviceCaps(hdc, LOGPIXELSY), 72);
324 ReleaseDC( dialog->hwnd, hdc );
327 font->hfont = CreateFontIndirectW( &lf );
329 TRACE("Adding font style %s\n", debugstr_w(font->name) );
331 return ERROR_SUCCESS;
334 static msi_font *msi_dialog_find_font( msi_dialog *dialog, LPCWSTR name )
338 for( font = dialog->font_list; font; font = font->next )
339 if( !strcmpW( font->name, name ) ) /* FIXME: case sensitive? */
345 static UINT msi_dialog_set_font( msi_dialog *dialog, HWND hwnd, LPCWSTR name )
349 font = msi_dialog_find_font( dialog, name );
351 SendMessageW( hwnd, WM_SETFONT, (WPARAM) font->hfont, TRUE );
353 ERR("No font entry for %s\n", debugstr_w(name));
354 return ERROR_SUCCESS;
357 static UINT msi_dialog_build_font_list( msi_dialog *dialog )
359 static const WCHAR query[] = {
360 'S','E','L','E','C','T',' ','*',' ',
361 'F','R','O','M',' ','`','T','e','x','t','S','t','y','l','e','`',' ',0
364 MSIQUERY *view = NULL;
366 TRACE("dialog %p\n", dialog );
368 r = MSI_OpenQuery( dialog->package->db, &view, query );
369 if( r != ERROR_SUCCESS )
372 r = MSI_IterateRecords( view, NULL, msi_dialog_add_font, dialog );
373 msiobj_release( &view->hdr );
378 static msi_control *msi_dialog_create_window( msi_dialog *dialog,
379 MSIRECORD *rec, DWORD exstyle, LPCWSTR szCls, LPCWSTR name, LPCWSTR text,
380 DWORD style, HWND parent )
382 DWORD x, y, width, height;
383 LPWSTR font = NULL, title_font = NULL;
384 LPCWSTR title = NULL;
385 msi_control *control;
389 control = msi_alloc( sizeof *control + strlenW(name)*sizeof(WCHAR) );
390 strcpyW( control->name, name );
391 list_add_head( &dialog->controls, &control->entry );
392 control->handler = NULL;
393 control->property = NULL;
394 control->value = NULL;
395 control->hBitmap = NULL;
396 control->hIcon = NULL;
397 control->hDll = NULL;
398 control->tabnext = strdupW( MSI_RecordGetString( rec, 11) );
399 control->type = strdupW( MSI_RecordGetString( rec, 3 ) );
400 control->progress_current = 0;
401 control->progress_max = 100;
403 x = MSI_RecordGetInteger( rec, 4 );
404 y = MSI_RecordGetInteger( rec, 5 );
405 width = MSI_RecordGetInteger( rec, 6 );
406 height = MSI_RecordGetInteger( rec, 7 );
408 x = msi_dialog_scale_unit( dialog, x );
409 y = msi_dialog_scale_unit( dialog, y );
410 width = msi_dialog_scale_unit( dialog, width );
411 height = msi_dialog_scale_unit( dialog, height );
415 deformat_string( dialog->package, text, &title_font );
416 font = msi_dialog_get_style( title_font, &title );
419 control->hwnd = CreateWindowExW( exstyle, szCls, title, style,
420 x, y, width, height, parent, NULL, NULL, NULL );
422 TRACE("Dialog %s control %s hwnd %p\n",
423 debugstr_w(dialog->name), debugstr_w(text), control->hwnd );
425 msi_dialog_set_font( dialog, control->hwnd,
426 font ? font : dialog->default_font );
428 msi_free( title_font );
434 static LPWSTR msi_dialog_get_uitext( msi_dialog *dialog, LPCWSTR key )
439 static const WCHAR query[] = {
440 's','e','l','e','c','t',' ','*',' ',
441 'f','r','o','m',' ','`','U','I','T','e','x','t','`',' ',
442 'w','h','e','r','e',' ','`','K','e','y','`',' ','=',' ','\'','%','s','\'',0
445 rec = MSI_QueryGetRecord( dialog->package->db, query, key );
446 if (!rec) return NULL;
447 text = strdupW( MSI_RecordGetString( rec, 2 ) );
448 msiobj_release( &rec->hdr );
452 static MSIRECORD *msi_get_binary_record( MSIDATABASE *db, LPCWSTR name )
454 static const WCHAR query[] = {
455 's','e','l','e','c','t',' ','*',' ',
456 'f','r','o','m',' ','B','i','n','a','r','y',' ',
457 'w','h','e','r','e',' ',
458 '`','N','a','m','e','`',' ','=',' ','\'','%','s','\'',0
461 return MSI_QueryGetRecord( db, query, name );
464 static LPWSTR msi_create_tmp_path(void)
468 static const WCHAR prefix[] = { 'm','s','i',0 };
471 r = GetTempPathW( MAX_PATH, tmp );
474 len = lstrlenW( tmp ) + 20;
475 path = msi_alloc( len * sizeof (WCHAR) );
478 r = GetTempFileNameW( tmp, prefix, 0, path );
489 static HANDLE msi_load_image( MSIDATABASE *db, LPCWSTR name, UINT type,
490 UINT cx, UINT cy, UINT flags )
492 MSIRECORD *rec = NULL;
493 HANDLE himage = NULL;
497 TRACE("%p %s %u %u %08x\n", db, debugstr_w(name), cx, cy, flags);
499 tmp = msi_create_tmp_path();
503 rec = msi_get_binary_record( db, name );
506 r = MSI_RecordStreamToFile( rec, 2, tmp );
507 if( r == ERROR_SUCCESS )
509 himage = LoadImageW( 0, tmp, type, cx, cy, flags );
512 msiobj_release( &rec->hdr );
519 static HICON msi_load_icon( MSIDATABASE *db, LPCWSTR text, UINT attributes )
521 DWORD cx = 0, cy = 0, flags;
523 flags = LR_LOADFROMFILE | LR_DEFAULTSIZE;
524 if( attributes & msidbControlAttributesFixedSize )
526 flags &= ~LR_DEFAULTSIZE;
527 if( attributes & msidbControlAttributesIconSize16 )
532 if( attributes & msidbControlAttributesIconSize32 )
537 /* msidbControlAttributesIconSize48 handled by above logic */
539 return msi_load_image( db, text, IMAGE_ICON, cx, cy, flags );
543 /* called from the Control Event subscription code */
544 void msi_dialog_handle_event( msi_dialog* dialog, LPCWSTR control,
545 LPCWSTR attribute, MSIRECORD *rec )
548 LPCWSTR font_text, text = NULL;
551 static const WCHAR empty[] = {0};
553 ctrl = msi_dialog_find_control( dialog, control );
556 if( !lstrcmpW(attribute, szText) )
558 font_text = MSI_RecordGetString( rec , 1 );
559 font = msi_dialog_get_style( font_text, &text );
560 if (!text) text = empty;
561 SetWindowTextW( ctrl->hwnd, text );
563 msi_dialog_check_messages( NULL );
565 else if( !lstrcmpW(attribute, szProgress) )
569 func = MSI_RecordGetInteger( rec , 1 );
570 val = MSI_RecordGetInteger( rec , 2 );
575 ctrl->progress_max = val;
576 ctrl->progress_current = 0;
577 SendMessageW(ctrl->hwnd, PBM_SETRANGE, 0, MAKELPARAM(0,100));
578 SendMessageW(ctrl->hwnd, PBM_SETPOS, 0, 0);
580 case 1: /* FIXME: not sure what this is supposed to do */
583 ctrl->progress_current += val;
584 SendMessageW(ctrl->hwnd, PBM_SETPOS, 100*(ctrl->progress_current/ctrl->progress_max), 0);
587 ERR("Unknown progress message %d\n", func);
591 else if ( !lstrcmpW(attribute, szProperty) )
593 MSIFEATURE *feature = msi_seltree_get_selected_feature( ctrl );
594 MSI_SetPropertyW( dialog->package, ctrl->property, feature->Directory );
598 FIXME("Attribute %s not being set\n", debugstr_w(attribute));
603 static void msi_dialog_map_events(msi_dialog* dialog, LPCWSTR control)
605 static const WCHAR Query[] = {
606 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
607 '`','E','v','e','n','t','M','a','p','p','i','n','g','`',' ',
608 'W','H','E','R','E',' ',
609 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',' ',
611 '`','C','o','n','t','r','o','l','_','`',' ','=',' ','\'','%','s','\'',0
614 LPCWSTR event, attribute;
616 row = MSI_QueryGetRecord( dialog->package->db, Query, dialog->name, control );
620 event = MSI_RecordGetString( row, 3 );
621 attribute = MSI_RecordGetString( row, 4 );
622 ControlEvent_SubscribeToEvent( dialog->package, dialog, event, control, attribute );
623 msiobj_release( &row->hdr );
626 /* everything except radio buttons */
627 static msi_control *msi_dialog_add_control( msi_dialog *dialog,
628 MSIRECORD *rec, LPCWSTR szCls, DWORD style )
634 name = MSI_RecordGetString( rec, 2 );
635 attributes = MSI_RecordGetInteger( rec, 8 );
636 text = MSI_RecordGetString( rec, 10 );
637 if( attributes & msidbControlAttributesVisible )
639 if( ~attributes & msidbControlAttributesEnabled )
640 style |= WS_DISABLED;
641 if( attributes & msidbControlAttributesSunken )
642 exstyle |= WS_EX_CLIENTEDGE;
644 msi_dialog_map_events(dialog, name);
646 return msi_dialog_create_window( dialog, rec, exstyle, szCls, name,
647 text, style, dialog->hwnd );
658 * we don't erase our own background,
659 * so we have to make sure that the parent window redraws first
661 static void msi_text_on_settext( HWND hWnd )
666 hParent = GetParent( hWnd );
667 GetWindowRect( hWnd, &rc );
668 MapWindowPoints( NULL, hParent, (LPPOINT) &rc, 2 );
669 InvalidateRect( hParent, &rc, TRUE );
672 static LRESULT WINAPI
673 MSIText_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
675 struct msi_text_info *info;
678 TRACE("%p %04x %08x %08lx\n", hWnd, msg, wParam, lParam);
680 info = GetPropW(hWnd, szButtonData);
683 SetTextColor( (HDC)wParam, info->font->color );
685 if( msg == WM_CTLCOLORSTATIC &&
686 ( info->attributes & msidbControlAttributesTransparent ) )
688 SetBkMode( (HDC)wParam, TRANSPARENT );
689 return (LRESULT) GetStockObject(NULL_BRUSH);
692 r = CallWindowProcW(info->oldproc, hWnd, msg, wParam, lParam);
697 msi_text_on_settext( hWnd );
701 RemovePropW( hWnd, szButtonData );
708 static UINT msi_dialog_text_control( msi_dialog *dialog, MSIRECORD *rec )
710 msi_control *control;
711 struct msi_text_info *info;
715 TRACE("%p %p\n", dialog, rec);
717 control = msi_dialog_add_control( dialog, rec, szStatic, SS_LEFT | WS_GROUP );
719 return ERROR_FUNCTION_FAILED;
721 info = msi_alloc( sizeof *info );
723 return ERROR_SUCCESS;
725 text = MSI_RecordGetString( rec, 10 );
726 font_name = msi_dialog_get_style( text, &ptr );
727 info->font = ( font_name ) ? msi_dialog_find_font( dialog, font_name ) : NULL;
728 msi_free( font_name );
730 info->attributes = MSI_RecordGetInteger( rec, 8 );
731 if( info->attributes & msidbControlAttributesTransparent )
732 SetWindowLongPtrW( control->hwnd, GWL_EXSTYLE, WS_EX_TRANSPARENT );
734 info->oldproc = (WNDPROC) SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
735 (LONG_PTR)MSIText_WndProc );
736 SetPropW( control->hwnd, szButtonData, info );
738 return ERROR_SUCCESS;
741 static UINT msi_dialog_button_control( msi_dialog *dialog, MSIRECORD *rec )
743 msi_control *control;
744 UINT attributes, style;
747 TRACE("%p %p\n", dialog, rec);
750 attributes = MSI_RecordGetInteger( rec, 8 );
751 if( attributes & msidbControlAttributesIcon )
754 control = msi_dialog_add_control( dialog, rec, szButton, style );
756 return ERROR_FUNCTION_FAILED;
758 control->handler = msi_dialog_button_handler;
761 text = msi_get_deformatted_field( dialog->package, rec, 10 );
762 control->hIcon = msi_load_icon( dialog->package->db, text, attributes );
763 if( attributes & msidbControlAttributesIcon )
764 SendMessageW( control->hwnd, BM_SETIMAGE, IMAGE_ICON, (LPARAM) control->hIcon );
767 return ERROR_SUCCESS;
770 static LPWSTR msi_get_checkbox_value( msi_dialog *dialog, LPCWSTR prop )
772 static const WCHAR query[] = {
773 'S','E','L','E','C','T',' ','*',' ',
774 'F','R','O','M',' ','`','C','h','e','c','k','B','o','x',' ','`',
775 'W','H','E','R','E',' ',
776 '`','P','r','o','p','e','r','t','y','`',' ','=',' ',
779 MSIRECORD *rec = NULL;
782 /* find if there is a value associated with the checkbox */
783 rec = MSI_QueryGetRecord( dialog->package->db, query, prop );
787 ret = msi_get_deformatted_field( dialog->package, rec, 2 );
793 msiobj_release( &rec->hdr );
797 ret = msi_dup_property( dialog->package, prop );
807 static UINT msi_dialog_checkbox_control( msi_dialog *dialog, MSIRECORD *rec )
809 msi_control *control;
812 TRACE("%p %p\n", dialog, rec);
814 control = msi_dialog_add_control( dialog, rec, szButton,
815 BS_CHECKBOX | BS_MULTILINE | WS_TABSTOP );
816 control->handler = msi_dialog_checkbox_handler;
817 prop = MSI_RecordGetString( rec, 9 );
820 control->property = strdupW( prop );
821 control->value = msi_get_checkbox_value( dialog, prop );
822 TRACE("control %s value %s\n", debugstr_w(control->property),
823 debugstr_w(control->value));
825 msi_dialog_checkbox_sync_state( dialog, control );
827 return ERROR_SUCCESS;
830 static UINT msi_dialog_line_control( msi_dialog *dialog, MSIRECORD *rec )
832 TRACE("%p %p\n", dialog, rec);
834 /* line is exactly 2 units in height */
835 MSI_RecordSetInteger( rec, 7, 2 );
837 msi_dialog_add_control( dialog, rec, szStatic, SS_ETCHEDHORZ | SS_SUNKEN );
838 return ERROR_SUCCESS;
841 /******************** Scroll Text ********************************************/
843 struct msi_scrolltext_info
846 msi_control *control;
850 static LRESULT WINAPI
851 MSIScrollText_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
853 struct msi_scrolltext_info *info;
856 TRACE("%p %04x %08x %08lx\n", hWnd, msg, wParam, lParam);
858 info = GetPropW( hWnd, szButtonData );
860 r = CallWindowProcW( info->oldproc, hWnd, msg, wParam, lParam );
866 RemovePropW( hWnd, szButtonData );
869 /* native MSI sets a wait cursor here */
870 msi_dialog_button_handler( info->dialog, info->control, BN_CLICKED );
876 struct msi_streamin_info
883 static DWORD CALLBACK
884 msi_richedit_stream_in( DWORD_PTR arg, LPBYTE buffer, LONG count, LONG *pcb )
886 struct msi_streamin_info *info = (struct msi_streamin_info*) arg;
888 if( (count + info->offset) > info->length )
889 count = info->length - info->offset;
890 memcpy( buffer, &info->string[ info->offset ], count );
892 info->offset += count;
894 TRACE("%d/%d\n", info->offset, info->length);
899 static void msi_scrolltext_add_text( msi_control *control, LPCWSTR text )
901 struct msi_streamin_info info;
904 info.string = strdupWtoA( text );
906 info.length = lstrlenA( info.string ) + 1;
908 es.dwCookie = (DWORD_PTR) &info;
910 es.pfnCallback = msi_richedit_stream_in;
912 SendMessageW( control->hwnd, EM_STREAMIN, SF_RTF, (LPARAM) &es );
914 msi_free( info.string );
917 static UINT msi_dialog_scrolltext_control( msi_dialog *dialog, MSIRECORD *rec )
919 static const WCHAR szRichEdit20W[] = {
920 'R','i','c','h','E','d','i','t','2','0','W',0
922 struct msi_scrolltext_info *info;
923 msi_control *control;
927 info = msi_alloc( sizeof *info );
929 return ERROR_FUNCTION_FAILED;
931 hRichedit = LoadLibraryA("riched20");
933 style = WS_BORDER | ES_MULTILINE | WS_VSCROLL |
934 ES_READONLY | ES_AUTOVSCROLL | WS_TABSTOP;
935 control = msi_dialog_add_control( dialog, rec, szRichEdit20W, style );
938 FreeLibrary( hRichedit );
940 return ERROR_FUNCTION_FAILED;
943 control->hDll = hRichedit;
945 info->dialog = dialog;
946 info->control = control;
948 /* subclass the static control */
949 info->oldproc = (WNDPROC) SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
950 (LONG_PTR)MSIScrollText_WndProc );
951 SetPropW( control->hwnd, szButtonData, info );
953 /* add the text into the richedit */
954 msi_scrolltext_add_text( control, MSI_RecordGetString( rec, 10 ) );
956 return ERROR_SUCCESS;
959 static HBITMAP msi_load_picture( MSIDATABASE *db, LPCWSTR name,
960 INT cx, INT cy, DWORD flags )
962 HBITMAP hOleBitmap = 0, hBitmap = 0, hOldSrcBitmap, hOldDestBitmap;
963 MSIRECORD *rec = NULL;
965 IPicture *pic = NULL;
970 rec = msi_get_binary_record( db, name );
974 r = MSI_RecordGetIStream( rec, 2, &stm );
975 msiobj_release( &rec->hdr );
976 if( r != ERROR_SUCCESS )
979 r = OleLoadPicture( stm, 0, TRUE, &IID_IPicture, (LPVOID*) &pic );
980 IStream_Release( stm );
983 ERR("failed to load picture\n");
987 r = IPicture_get_Handle( pic, (OLE_HANDLE*) &hOleBitmap );
990 ERR("failed to get bitmap handle\n");
994 /* make the bitmap the desired size */
995 r = GetObjectW( hOleBitmap, sizeof bm, &bm );
998 ERR("failed to get bitmap size\n");
1002 if (flags & LR_DEFAULTSIZE)
1008 srcdc = CreateCompatibleDC( NULL );
1009 hOldSrcBitmap = SelectObject( srcdc, hOleBitmap );
1010 destdc = CreateCompatibleDC( NULL );
1011 hBitmap = CreateCompatibleBitmap( srcdc, cx, cy );
1012 hOldDestBitmap = SelectObject( destdc, hBitmap );
1013 StretchBlt( destdc, 0, 0, cx, cy,
1014 srcdc, 0, 0, bm.bmWidth, bm.bmHeight, SRCCOPY);
1015 SelectObject( srcdc, hOldSrcBitmap );
1016 SelectObject( destdc, hOldDestBitmap );
1022 IPicture_Release( pic );
1026 static UINT msi_dialog_bitmap_control( msi_dialog *dialog, MSIRECORD *rec )
1028 UINT cx, cy, flags, style, attributes;
1029 msi_control *control;
1032 flags = LR_LOADFROMFILE;
1033 style = SS_BITMAP | SS_LEFT | WS_GROUP;
1035 attributes = MSI_RecordGetInteger( rec, 8 );
1036 if( attributes & msidbControlAttributesFixedSize )
1038 flags |= LR_DEFAULTSIZE;
1039 style |= SS_CENTERIMAGE;
1042 control = msi_dialog_add_control( dialog, rec, szStatic, style );
1043 cx = MSI_RecordGetInteger( rec, 6 );
1044 cy = MSI_RecordGetInteger( rec, 7 );
1045 cx = msi_dialog_scale_unit( dialog, cx );
1046 cy = msi_dialog_scale_unit( dialog, cy );
1048 text = msi_get_deformatted_field( dialog->package, rec, 10 );
1049 control->hBitmap = msi_load_picture( dialog->package->db, text, cx, cy, flags );
1050 if( control->hBitmap )
1051 SendMessageW( control->hwnd, STM_SETIMAGE,
1052 IMAGE_BITMAP, (LPARAM) control->hBitmap );
1054 ERR("Failed to load bitmap %s\n", debugstr_w(text));
1058 return ERROR_SUCCESS;
1061 static UINT msi_dialog_icon_control( msi_dialog *dialog, MSIRECORD *rec )
1063 msi_control *control;
1069 control = msi_dialog_add_control( dialog, rec, szStatic,
1070 SS_ICON | SS_CENTERIMAGE | WS_GROUP );
1072 attributes = MSI_RecordGetInteger( rec, 8 );
1073 text = msi_get_deformatted_field( dialog->package, rec, 10 );
1074 control->hIcon = msi_load_icon( dialog->package->db, text, attributes );
1075 if( control->hIcon )
1076 SendMessageW( control->hwnd, STM_SETICON, (WPARAM) control->hIcon, 0 );
1078 ERR("Failed to load bitmap %s\n", debugstr_w(text));
1080 return ERROR_SUCCESS;
1083 static UINT msi_dialog_combo_control( msi_dialog *dialog, MSIRECORD *rec )
1085 static const WCHAR szCombo[] = { 'C','O','M','B','O','B','O','X',0 };
1087 msi_dialog_add_control( dialog, rec, szCombo,
1088 SS_BITMAP | SS_LEFT | SS_CENTERIMAGE );
1089 return ERROR_SUCCESS;
1092 static UINT msi_dialog_edit_control( msi_dialog *dialog, MSIRECORD *rec )
1094 msi_control *control;
1098 control = msi_dialog_add_control( dialog, rec, szEdit,
1099 WS_BORDER | WS_TABSTOP );
1100 control->handler = msi_dialog_edit_handler;
1101 prop = MSI_RecordGetString( rec, 9 );
1103 control->property = strdupW( prop );
1104 val = msi_dup_property( dialog->package, control->property );
1105 SetWindowTextW( control->hwnd, val );
1107 return ERROR_SUCCESS;
1110 /******************** Masked Edit ********************************************/
1112 #define MASK_MAX_GROUPS 20
1114 struct msi_mask_group
1122 struct msi_maskedit_info
1130 struct msi_mask_group group[MASK_MAX_GROUPS];
1133 static BOOL msi_mask_editable( WCHAR type )
1148 static void msi_mask_control_change( struct msi_maskedit_info *info )
1153 val = msi_alloc( (info->num_chars+1)*sizeof(WCHAR) );
1154 for( i=0, n=0; i<info->num_groups; i++ )
1156 if( (info->group[i].len + n) > info->num_chars )
1158 ERR("can't fit control %d text into template\n",i);
1161 if (!msi_mask_editable(info->group[i].type))
1163 for(r=0; r<info->group[i].len; r++)
1164 val[n+r] = info->group[i].type;
1169 r = GetWindowTextW( info->group[i].hwnd, &val[n], info->group[i].len+1 );
1170 if( r != info->group[i].len )
1176 TRACE("%d/%d controls were good\n", i, info->num_groups);
1178 if( i == info->num_groups )
1180 TRACE("Set property %s to %s\n",
1181 debugstr_w(info->prop), debugstr_w(val) );
1182 CharUpperBuffW( val, info->num_chars );
1183 MSI_SetPropertyW( info->dialog->package, info->prop, val );
1184 msi_dialog_evaluate_control_conditions( info->dialog );
1189 /* now move to the next control if necessary */
1190 static VOID msi_mask_next_control( struct msi_maskedit_info *info, HWND hWnd )
1195 for( i=0; i<info->num_groups; i++ )
1196 if( info->group[i].hwnd == hWnd )
1199 /* don't move from the last control */
1200 if( i >= (info->num_groups-1) )
1203 len = SendMessageW( hWnd, WM_GETTEXTLENGTH, 0, 0 );
1204 if( len < info->group[i].len )
1207 hWndNext = GetNextDlgTabItem( GetParent( hWnd ), hWnd, FALSE );
1208 SetFocus( hWndNext );
1211 static LRESULT WINAPI
1212 MSIMaskedEdit_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
1214 struct msi_maskedit_info *info;
1217 TRACE("%p %04x %08x %08lx\n", hWnd, msg, wParam, lParam);
1219 info = GetPropW(hWnd, szButtonData);
1221 r = CallWindowProcW(info->oldproc, hWnd, msg, wParam, lParam);
1226 if (HIWORD(wParam) == EN_CHANGE)
1228 msi_mask_control_change( info );
1229 msi_mask_next_control( info, (HWND) lParam );
1233 msi_free( info->prop );
1235 RemovePropW( hWnd, szButtonData );
1242 /* fish the various bits of the property out and put them in the control */
1244 msi_maskedit_set_text( struct msi_maskedit_info *info, LPCWSTR text )
1250 for( i = 0; i < info->num_groups; i++ )
1252 if( info->group[i].len < lstrlenW( p ) )
1254 LPWSTR chunk = strdupW( p );
1255 chunk[ info->group[i].len ] = 0;
1256 SetWindowTextW( info->group[i].hwnd, chunk );
1261 SetWindowTextW( info->group[i].hwnd, p );
1264 p += info->group[i].len;
1268 static struct msi_maskedit_info * msi_dialog_parse_groups( LPCWSTR mask )
1270 struct msi_maskedit_info * info = NULL;
1271 int i = 0, n = 0, total = 0;
1274 TRACE("masked control, template %s\n", debugstr_w(mask));
1279 info = msi_alloc_zero( sizeof *info );
1283 p = strchrW(mask, '<');
1289 for( i=0; i<MASK_MAX_GROUPS; i++ )
1291 /* stop at the end of the string */
1292 if( p[0] == 0 || p[0] == '>' )
1295 /* count the number of the same identifier */
1296 for( n=0; p[n] == p[0]; n++ )
1298 info->group[i].ofs = total;
1299 info->group[i].type = p[0];
1303 total++; /* an extra not part of the group */
1305 info->group[i].len = n;
1310 TRACE("%d characters in %d groups\n", total, i );
1311 if( i == MASK_MAX_GROUPS )
1312 ERR("too many groups in PIDTemplate %s\n", debugstr_w(mask));
1314 info->num_chars = total;
1315 info->num_groups = i;
1321 msi_maskedit_create_children( struct msi_maskedit_info *info, LPCWSTR font )
1323 DWORD width, height, style, wx, ww;
1328 style = WS_CHILD | WS_BORDER | WS_VISIBLE | WS_TABSTOP | ES_AUTOHSCROLL;
1330 GetClientRect( info->hwnd, &rect );
1332 width = rect.right - rect.left;
1333 height = rect.bottom - rect.top;
1335 for( i = 0; i < info->num_groups; i++ )
1337 if (!msi_mask_editable( info->group[i].type ))
1339 wx = (info->group[i].ofs * width) / info->num_chars;
1340 ww = (info->group[i].len * width) / info->num_chars;
1342 hwnd = CreateWindowW( szEdit, NULL, style, wx, 0, ww, height,
1343 info->hwnd, NULL, NULL, NULL );
1346 ERR("failed to create mask edit sub window\n");
1350 SendMessageW( hwnd, EM_LIMITTEXT, info->group[i].len, 0 );
1352 msi_dialog_set_font( info->dialog, hwnd,
1353 font?font:info->dialog->default_font );
1354 info->group[i].hwnd = hwnd;
1359 * office 2003 uses "73931<````=````=````=````=`````>@@@@@"
1360 * delphi 7 uses "<????-??????-??????-????>" and "<???-???>"
1361 * filemaker pro 7 uses "<^^^^=^^^^=^^^^=^^^^=^^^^=^^^^=^^^^^>"
1363 static UINT msi_dialog_maskedit_control( msi_dialog *dialog, MSIRECORD *rec )
1365 LPWSTR font_mask, val = NULL, font;
1366 struct msi_maskedit_info *info = NULL;
1367 UINT ret = ERROR_SUCCESS;
1368 msi_control *control;
1373 font_mask = msi_get_deformatted_field( dialog->package, rec, 10 );
1374 font = msi_dialog_get_style( font_mask, &mask );
1377 ERR("mask template is empty\n");
1381 info = msi_dialog_parse_groups( mask );
1384 ERR("template %s is invalid\n", debugstr_w(mask));
1388 info->dialog = dialog;
1390 control = msi_dialog_add_control( dialog, rec, szStatic,
1391 SS_OWNERDRAW | WS_GROUP | WS_VISIBLE );
1394 ERR("Failed to create maskedit container\n");
1395 ret = ERROR_FUNCTION_FAILED;
1398 SetWindowLongPtrW( control->hwnd, GWL_EXSTYLE, WS_EX_CONTROLPARENT );
1400 info->hwnd = control->hwnd;
1402 /* subclass the static control */
1403 info->oldproc = (WNDPROC) SetWindowLongPtrW( info->hwnd, GWLP_WNDPROC,
1404 (LONG_PTR)MSIMaskedEdit_WndProc );
1405 SetPropW( control->hwnd, szButtonData, info );
1407 prop = MSI_RecordGetString( rec, 9 );
1409 info->prop = strdupW( prop );
1411 msi_maskedit_create_children( info, font );
1415 val = msi_dup_property( dialog->package, prop );
1418 msi_maskedit_set_text( info, val );
1424 if( ret != ERROR_SUCCESS )
1426 msi_free( font_mask );
1431 /******************** Progress Bar *****************************************/
1433 static UINT msi_dialog_progress_bar( msi_dialog *dialog, MSIRECORD *rec )
1435 msi_dialog_add_control( dialog, rec, PROGRESS_CLASSW, WS_VISIBLE );
1436 return ERROR_SUCCESS;
1439 /******************** Path Edit ********************************************/
1441 struct msi_pathedit_info
1444 msi_control *control;
1448 static LPWSTR msi_get_window_text( HWND hwnd )
1454 buf = msi_alloc( sz*sizeof(WCHAR) );
1457 r = GetWindowTextW( hwnd, buf, sz );
1461 buf = msi_realloc( buf, sz*sizeof(WCHAR) );
1467 static void msi_dialog_update_pathedit( msi_dialog *dialog, msi_control *control )
1472 if (!control && !(control = msi_dialog_find_control_by_type( dialog, szPathEdit )))
1475 indirect = control->attributes & msidbControlAttributesIndirect;
1476 prop = msi_dialog_dup_property( dialog, control->property, indirect );
1477 path = msi_dialog_dup_property( dialog, prop, TRUE );
1479 SetWindowTextW( control->hwnd, path );
1480 SendMessageW( control->hwnd, EM_SETSEL, 0, -1 );
1486 /* FIXME: test when this should fail */
1487 static BOOL msi_dialog_verify_path( LPWSTR path )
1489 if ( !lstrlenW( path ) )
1492 if ( PathIsRelativeW( path ) )
1498 /* returns TRUE if the path is valid, FALSE otherwise */
1499 static BOOL msi_dialog_onkillfocus( msi_dialog *dialog, msi_control *control )
1505 indirect = control->attributes & msidbControlAttributesIndirect;
1506 prop = msi_dialog_dup_property( dialog, control->property, indirect );
1508 buf = msi_get_window_text( control->hwnd );
1510 if ( !msi_dialog_verify_path( buf ) )
1512 /* FIXME: display an error message box */
1513 ERR("Invalid path %s\n", debugstr_w( buf ));
1515 SetFocus( control->hwnd );
1520 MSI_SetPropertyW( dialog->package, prop, buf );
1523 msi_dialog_update_pathedit( dialog, control );
1525 TRACE("edit %s contents changed, set %s\n", debugstr_w(control->name),
1534 static LRESULT WINAPI MSIPathEdit_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
1536 struct msi_pathedit_info *info = GetPropW(hWnd, szButtonData);
1539 TRACE("%p %04x %08x %08lx\n", hWnd, msg, wParam, lParam);
1541 if ( msg == WM_KILLFOCUS )
1543 /* if the path is invalid, don't handle this message */
1544 if ( !msi_dialog_onkillfocus( info->dialog, info->control ) )
1548 r = CallWindowProcW(info->oldproc, hWnd, msg, wParam, lParam);
1550 if ( msg == WM_NCDESTROY )
1553 RemovePropW( hWnd, szButtonData );
1559 static UINT msi_dialog_pathedit_control( msi_dialog *dialog, MSIRECORD *rec )
1561 struct msi_pathedit_info *info;
1562 msi_control *control;
1565 info = msi_alloc( sizeof *info );
1567 return ERROR_FUNCTION_FAILED;
1569 control = msi_dialog_add_control( dialog, rec, szEdit,
1570 WS_BORDER | WS_TABSTOP );
1571 control->attributes = MSI_RecordGetInteger( rec, 8 );
1572 prop = MSI_RecordGetString( rec, 9 );
1573 control->property = msi_dialog_dup_property( dialog, prop, FALSE );
1575 info->dialog = dialog;
1576 info->control = control;
1577 info->oldproc = (WNDPROC) SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
1578 (LONG_PTR)MSIPathEdit_WndProc );
1579 SetPropW( control->hwnd, szButtonData, info );
1581 msi_dialog_update_pathedit( dialog, control );
1583 return ERROR_SUCCESS;
1586 /* radio buttons are a bit different from normal controls */
1587 static UINT msi_dialog_create_radiobutton( MSIRECORD *rec, LPVOID param )
1589 radio_button_group_descr *group = (radio_button_group_descr *)param;
1590 msi_dialog *dialog = group->dialog;
1591 msi_control *control;
1592 LPCWSTR prop, text, name;
1593 DWORD style, attributes = group->attributes;
1595 style = WS_CHILD | BS_AUTORADIOBUTTON | BS_MULTILINE | WS_TABSTOP;
1596 name = MSI_RecordGetString( rec, 3 );
1597 text = MSI_RecordGetString( rec, 8 );
1598 if( attributes & 1 )
1599 style |= WS_VISIBLE;
1600 if( ~attributes & 2 )
1601 style |= WS_DISABLED;
1603 control = msi_dialog_create_window( dialog, rec, 0, szButton, name, text,
1604 style, group->parent->hwnd );
1606 return ERROR_FUNCTION_FAILED;
1607 control->handler = msi_dialog_radiogroup_handler;
1609 if (!lstrcmpW(control->name, group->propval))
1610 SendMessageW(control->hwnd, BM_SETCHECK, BST_CHECKED, 0);
1612 prop = MSI_RecordGetString( rec, 1 );
1614 control->property = strdupW( prop );
1616 return ERROR_SUCCESS;
1619 static UINT msi_dialog_radiogroup_control( msi_dialog *dialog, MSIRECORD *rec )
1621 static const WCHAR query[] = {
1622 'S','E','L','E','C','T',' ','*',' ',
1623 'F','R','O','M',' ','R','a','d','i','o','B','u','t','t','o','n',' ',
1624 'W','H','E','R','E',' ',
1625 '`','P','r','o','p','e','r','t','y','`',' ','=',' ','\'','%','s','\'',0};
1628 msi_control *control;
1629 MSIQUERY *view = NULL;
1630 radio_button_group_descr group;
1631 MSIPACKAGE *package = dialog->package;
1634 prop = MSI_RecordGetString( rec, 9 );
1636 TRACE("%p %p %s\n", dialog, rec, debugstr_w( prop ));
1638 /* Create parent group box to hold radio buttons */
1639 control = msi_dialog_add_control( dialog, rec, szButton, BS_OWNERDRAW|WS_GROUP );
1641 return ERROR_FUNCTION_FAILED;
1643 oldproc = (WNDPROC) SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
1644 (LONG_PTR)MSIRadioGroup_WndProc );
1645 SetPropW(control->hwnd, szButtonData, oldproc);
1646 SetWindowLongPtrW( control->hwnd, GWL_EXSTYLE, WS_EX_CONTROLPARENT );
1649 control->property = strdupW( prop );
1651 /* query the Radio Button table for all control in this group */
1652 r = MSI_OpenQuery( package->db, &view, query, prop );
1653 if( r != ERROR_SUCCESS )
1655 ERR("query failed for dialog %s radio group %s\n",
1656 debugstr_w(dialog->name), debugstr_w(prop));
1657 return ERROR_INVALID_PARAMETER;
1660 group.dialog = dialog;
1661 group.parent = control;
1662 group.attributes = MSI_RecordGetInteger( rec, 8 );
1663 group.propval = msi_dup_property( dialog->package, control->property );
1665 r = MSI_IterateRecords( view, 0, msi_dialog_create_radiobutton, &group );
1666 msiobj_release( &view->hdr );
1667 msi_free( group.propval );
1672 /******************** Selection Tree ***************************************/
1674 struct msi_selection_tree_info
1683 msi_seltree_sync_item_state( HWND hwnd, MSIFEATURE *feature, HTREEITEM hItem )
1686 DWORD index = feature->Action;
1688 TRACE("Feature %s -> %d %d %d\n", debugstr_w(feature->Title),
1689 feature->Installed, feature->Action, feature->ActionRequest);
1691 if (index == INSTALLSTATE_UNKNOWN)
1692 index = INSTALLSTATE_ABSENT;
1694 tvi.mask = TVIF_STATE;
1696 tvi.state = INDEXTOSTATEIMAGEMASK( index );
1697 tvi.stateMask = TVIS_STATEIMAGEMASK;
1699 SendMessageW( hwnd, TVM_SETITEMW, 0, (LPARAM) &tvi );
1703 msi_seltree_popup_menu( HWND hwnd, INT x, INT y )
1708 /* create a menu to display */
1709 hMenu = CreatePopupMenu();
1711 /* FIXME: load strings from resources */
1712 AppendMenuA( hMenu, MF_ENABLED, INSTALLSTATE_LOCAL, "Install feature locally");
1713 AppendMenuA( hMenu, MF_GRAYED, 0x1000, "Install entire feature");
1714 AppendMenuA( hMenu, MF_ENABLED, INSTALLSTATE_ADVERTISED, "Install on demand");
1715 AppendMenuA( hMenu, MF_ENABLED, INSTALLSTATE_ABSENT, "Don't install");
1716 r = TrackPopupMenu( hMenu, TPM_LEFTALIGN | TPM_TOPALIGN | TPM_RETURNCMD,
1717 x, y, 0, hwnd, NULL );
1718 DestroyMenu( hMenu );
1723 msi_seltree_feature_from_item( HWND hwnd, HTREEITEM hItem )
1727 /* get the feature from the item */
1728 memset( &tvi, 0, sizeof tvi );
1730 tvi.mask = TVIF_PARAM | TVIF_HANDLE;
1731 SendMessageW( hwnd, TVM_GETITEMW, 0, (LPARAM) &tvi );
1733 return (MSIFEATURE*) tvi.lParam;
1737 msi_seltree_menu( HWND hwnd, HTREEITEM hItem )
1739 struct msi_selection_tree_info *info;
1740 MSIFEATURE *feature;
1741 MSIPACKAGE *package;
1749 info = GetPropW(hwnd, szButtonData);
1750 package = info->dialog->package;
1752 feature = msi_seltree_feature_from_item( hwnd, hItem );
1755 ERR("item %p feature was NULL\n", hItem);
1759 /* get the item's rectangle to put the menu just below it */
1761 SendMessageW( hwnd, TVM_GETITEMRECT, 0, (LPARAM) &u.rc );
1762 MapWindowPoints( hwnd, NULL, u.pt, 2 );
1764 r = msi_seltree_popup_menu( hwnd, u.rc.left, u.rc.top );
1768 case INSTALLSTATE_LOCAL:
1769 case INSTALLSTATE_ADVERTISED:
1770 case INSTALLSTATE_ABSENT:
1771 feature->ActionRequest = r;
1772 feature->Action = r;
1775 FIXME("select feature and all children\n");
1779 msi_seltree_sync_item_state( hwnd, feature, hItem );
1780 ACTION_UpdateComponentStates( package, feature->Feature );
1785 static MSIFEATURE *msi_seltree_get_selected_feature( msi_control *control )
1787 struct msi_selection_tree_info *info = GetPropW(control->hwnd, szButtonData);
1788 return msi_seltree_feature_from_item( control->hwnd, info->selected );
1791 static LRESULT WINAPI
1792 MSISelectionTree_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
1794 struct msi_selection_tree_info *info;
1795 TVHITTESTINFO tvhti;
1798 TRACE("%p %04x %08x %08lx\n", hWnd, msg, wParam, lParam);
1800 info = GetPropW(hWnd, szButtonData);
1804 case WM_LBUTTONDOWN:
1805 tvhti.pt.x = LOWORD( lParam );
1806 tvhti.pt.y = HIWORD( lParam );
1809 r = CallWindowProcW(info->oldproc, hWnd, TVM_HITTEST, 0, (LPARAM) &tvhti );
1810 if (tvhti.flags & TVHT_ONITEMSTATEICON)
1811 return msi_seltree_menu( hWnd, tvhti.hItem );
1815 r = CallWindowProcW(info->oldproc, hWnd, msg, wParam, lParam);
1821 RemovePropW( hWnd, szButtonData );
1828 msi_seltree_add_child_features( MSIPACKAGE *package, HWND hwnd,
1829 LPCWSTR parent, HTREEITEM hParent )
1831 struct msi_selection_tree_info *info = GetPropW( hwnd, szButtonData );
1832 MSIFEATURE *feature;
1833 TVINSERTSTRUCTW tvis;
1834 HTREEITEM hitem, hfirst = NULL;
1836 LIST_FOR_EACH_ENTRY( feature, &package->features, MSIFEATURE, entry )
1838 if ( lstrcmpW( parent, feature->Feature_Parent ) )
1841 if ( !feature->Title )
1844 if ( !feature->Display )
1847 memset( &tvis, 0, sizeof tvis );
1848 tvis.hParent = hParent;
1849 tvis.hInsertAfter = TVI_LAST;
1850 tvis.u.item.mask = TVIF_TEXT | TVIF_PARAM;
1851 tvis.u.item.pszText = feature->Title;
1852 tvis.u.item.lParam = (LPARAM) feature;
1854 hitem = (HTREEITEM) SendMessageW( hwnd, TVM_INSERTITEMW, 0, (LPARAM) &tvis );
1861 msi_seltree_sync_item_state( hwnd, feature, hitem );
1862 msi_seltree_add_child_features( package, hwnd,
1863 feature->Feature, hitem );
1865 /* the node is expanded if Display is odd */
1866 if ( feature->Display % 2 != 0 )
1867 SendMessageW( hwnd, TVM_EXPAND, TVE_EXPAND, (LPARAM) hitem );
1870 /* select the first item */
1871 SendMessageW( hwnd, TVM_SELECTITEM, TVGN_CARET | TVGN_DROPHILITE, (LPARAM) hfirst );
1872 info->selected = hfirst;
1875 static void msi_seltree_create_imagelist( HWND hwnd )
1877 const int bm_width = 32, bm_height = 16, bm_count = 3;
1878 const int bm_resource = 0x1001;
1883 himl = ImageList_Create( bm_width, bm_height, FALSE, 4, 0 );
1886 ERR("failed to create image list\n");
1890 for (i=0; i<bm_count; i++)
1892 hbmp = LoadBitmapW( msi_hInstance, MAKEINTRESOURCEW(i+bm_resource) );
1895 ERR("failed to load bitmap %d\n", i);
1900 * Add a dummy bitmap at offset zero because the treeview
1901 * can't use it as a state mask (zero means no user state).
1904 ImageList_Add( himl, hbmp, NULL );
1906 ImageList_Add( himl, hbmp, NULL );
1909 SendMessageW( hwnd, TVM_SETIMAGELIST, TVSIL_STATE, (LPARAM)himl );
1912 static UINT msi_dialog_seltree_handler( msi_dialog *dialog,
1913 msi_control *control, WPARAM param )
1915 struct msi_selection_tree_info *info = GetPropW( control->hwnd, szButtonData );
1916 LPNMTREEVIEWW tv = (LPNMTREEVIEWW)param;
1917 MSIRECORD *row, *rec;
1920 UINT r = ERROR_SUCCESS;
1922 static const WCHAR select[] = {
1923 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
1924 '`','F','e','a','t','u','r','e','`',' ','W','H','E','R','E',' ',
1925 '`','T','i','t','l','e','`',' ','=',' ','\'','%','s','\'',0
1928 if (tv->hdr.code != TVN_SELCHANGINGW)
1929 return ERROR_SUCCESS;
1931 info->selected = tv->itemNew.hItem;
1933 row = MSI_QueryGetRecord( dialog->package->db, select, tv->itemNew.pszText );
1935 return ERROR_FUNCTION_FAILED;
1937 rec = MSI_CreateRecord( 1 );
1939 MSI_RecordSetStringW( rec, 1, MSI_RecordGetString( row, 4 ) );
1940 ControlEvent_FireSubscribedEvent( dialog->package, szSelectionDescription, rec );
1942 dir = MSI_RecordGetString( row, 7 );
1943 folder = get_loaded_folder( dialog->package, dir );
1946 r = ERROR_FUNCTION_FAILED;
1950 MSI_RecordSetStringW( rec, 1, folder->ResolvedTarget );
1951 ControlEvent_FireSubscribedEvent( dialog->package, szSelectionPath, rec );
1954 msiobj_release(&row->hdr);
1955 msiobj_release(&rec->hdr);
1960 static UINT msi_dialog_selection_tree( msi_dialog *dialog, MSIRECORD *rec )
1962 msi_control *control;
1964 MSIPACKAGE *package = dialog->package;
1966 struct msi_selection_tree_info *info;
1968 info = msi_alloc( sizeof *info );
1970 return ERROR_FUNCTION_FAILED;
1972 /* create the treeview control */
1973 style = TVS_HASLINES | TVS_HASBUTTONS | TVS_LINESATROOT;
1974 style |= WS_GROUP | WS_VSCROLL;
1975 control = msi_dialog_add_control( dialog, rec, WC_TREEVIEWW, style );
1979 return ERROR_FUNCTION_FAILED;
1982 control->handler = msi_dialog_seltree_handler;
1983 control->attributes = MSI_RecordGetInteger( rec, 8 );
1984 prop = MSI_RecordGetString( rec, 9 );
1985 control->property = msi_dialog_dup_property( dialog, prop, FALSE );
1988 info->dialog = dialog;
1989 info->hwnd = control->hwnd;
1990 info->oldproc = (WNDPROC) SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
1991 (LONG_PTR)MSISelectionTree_WndProc );
1992 SetPropW( control->hwnd, szButtonData, info );
1994 ControlEvent_SubscribeToEvent( dialog->package, dialog,
1995 szSelectionPath, control->name, szProperty );
1998 msi_seltree_create_imagelist( control->hwnd );
1999 msi_seltree_add_child_features( package, control->hwnd, NULL, NULL );
2001 return ERROR_SUCCESS;
2004 /******************** Group Box ***************************************/
2006 static UINT msi_dialog_group_box( msi_dialog *dialog, MSIRECORD *rec )
2008 msi_control *control;
2011 style = BS_GROUPBOX | WS_CHILD | WS_GROUP;
2012 control = msi_dialog_add_control( dialog, rec, WC_BUTTONW, style );
2014 return ERROR_FUNCTION_FAILED;
2016 return ERROR_SUCCESS;
2019 /******************** List Box ***************************************/
2021 struct msi_listbox_item
2027 struct msi_listbox_info
2033 struct msi_listbox_item *items;
2036 static LRESULT WINAPI MSIListBox_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
2038 struct msi_listbox_info *info;
2042 TRACE("%p %04x %08x %08lx\n", hWnd, msg, wParam, lParam);
2044 info = GetPropW( hWnd, szButtonData );
2048 r = CallWindowProcW( info->oldproc, hWnd, msg, wParam, lParam );
2053 for (j = 0; j < info->num_items; j++)
2055 msi_free( info->items[j].property );
2056 msi_free( info->items[j].value );
2058 msi_free( info->items );
2060 RemovePropW( hWnd, szButtonData );
2067 static UINT msi_listbox_add_item( MSIRECORD *rec, LPVOID param )
2069 struct msi_listbox_info *info = param;
2070 struct msi_listbox_item *item;
2071 LPCWSTR property, value, text;
2072 static int index = 0;
2074 item = &info->items[index++];
2075 property = MSI_RecordGetString( rec, 1 );
2076 value = MSI_RecordGetString( rec, 3 );
2077 text = MSI_RecordGetString( rec, 4 );
2079 item->property = strdupW( property );
2080 item->value = strdupW( value );
2082 SendMessageW( info->hwnd, LB_ADDSTRING, 0, (LPARAM)text );
2084 return ERROR_SUCCESS;
2087 static UINT msi_listbox_add_items( struct msi_listbox_info *info )
2090 MSIQUERY *view = NULL;
2093 static const WCHAR query[] = {
2094 'S','E','L','E','C','T',' ','*',' ',
2095 'F','R','O','M',' ','`','L','i','s','t','B','o','x','`',' ',
2096 'O','R','D','E','R',' ','B','Y',' ','`','O','r','d','e','r','`',0
2099 r = MSI_OpenQuery( info->dialog->package->db, &view, query );
2100 if ( r != ERROR_SUCCESS )
2103 /* just get the number of records */
2104 r = MSI_IterateRecords( view, &count, NULL, NULL );
2106 info->num_items = count;
2107 info->items = msi_alloc( sizeof(*info->items) * count );
2109 r = MSI_IterateRecords( view, NULL, msi_listbox_add_item, info );
2110 msiobj_release( &view->hdr );
2115 static UINT msi_dialog_listbox_handler( msi_dialog *dialog,
2116 msi_control *control, WPARAM param )
2118 struct msi_listbox_info *info;
2121 if( HIWORD(param) != LBN_SELCHANGE )
2122 return ERROR_SUCCESS;
2124 info = GetPropW( control->hwnd, szButtonData );
2125 index = SendMessageW( control->hwnd, LB_GETCURSEL, 0, 0 );
2127 MSI_SetPropertyW( info->dialog->package,
2128 info->items[index].property, info->items[index].value );
2129 msi_dialog_evaluate_control_conditions( info->dialog );
2131 return ERROR_SUCCESS;
2134 static UINT msi_dialog_list_box( msi_dialog *dialog, MSIRECORD *rec )
2136 struct msi_listbox_info *info;
2137 msi_control *control;
2140 info = msi_alloc( sizeof *info );
2142 return ERROR_FUNCTION_FAILED;
2144 style = WS_TABSTOP | WS_GROUP | WS_CHILD | LBS_STANDARD;
2145 control = msi_dialog_add_control( dialog, rec, WC_LISTBOXW, style );
2147 return ERROR_FUNCTION_FAILED;
2149 control->handler = msi_dialog_listbox_handler;
2152 info->dialog = dialog;
2153 info->hwnd = control->hwnd;
2155 info->oldproc = (WNDPROC)SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
2156 (LONG_PTR)MSIListBox_WndProc );
2157 SetPropW( control->hwnd, szButtonData, info );
2159 msi_listbox_add_items( info );
2161 return ERROR_SUCCESS;
2164 /******************** Directory Combo ***************************************/
2166 static void msi_dialog_update_directory_combo( msi_dialog *dialog, msi_control *control )
2171 if (!control && !(control = msi_dialog_find_control_by_type( dialog, szDirectoryCombo )))
2174 indirect = control->attributes & msidbControlAttributesIndirect;
2175 prop = msi_dialog_dup_property( dialog, control->property, indirect );
2176 path = msi_dialog_dup_property( dialog, prop, TRUE );
2178 PathStripPathW( path );
2179 PathRemoveBackslashW( path );
2181 SendMessageW( control->hwnd, CB_INSERTSTRING, 0, (LPARAM)path );
2182 SendMessageW( control->hwnd, CB_SETCURSEL, 0, 0 );
2188 static UINT msi_dialog_directory_combo( msi_dialog *dialog, MSIRECORD *rec )
2190 msi_control *control;
2194 /* FIXME: use CBS_OWNERDRAWFIXED and add owner draw code */
2195 style = CBS_DROPDOWNLIST | CBS_HASSTRINGS | WS_CHILD |
2196 WS_GROUP | WS_TABSTOP | WS_VSCROLL;
2197 control = msi_dialog_add_control( dialog, rec, WC_COMBOBOXW, style );
2199 return ERROR_FUNCTION_FAILED;
2201 control->attributes = MSI_RecordGetInteger( rec, 8 );
2202 prop = MSI_RecordGetString( rec, 9 );
2203 control->property = msi_dialog_dup_property( dialog, prop, FALSE );
2205 msi_dialog_update_directory_combo( dialog, control );
2207 return ERROR_SUCCESS;
2210 /******************** Directory List ***************************************/
2212 static void msi_dialog_update_directory_list( msi_dialog *dialog, msi_control *control )
2214 WCHAR dir_spec[MAX_PATH];
2215 WIN32_FIND_DATAW wfd;
2221 static const WCHAR asterisk[] = {'*',0};
2222 static const WCHAR dot[] = {'.',0};
2223 static const WCHAR dotdot[] = {'.','.',0};
2225 if (!control && !(control = msi_dialog_find_control_by_type( dialog, szDirectoryList )))
2228 /* clear the list-view */
2229 SendMessageW( control->hwnd, LVM_DELETEALLITEMS, 0, 0 );
2231 indirect = control->attributes & msidbControlAttributesIndirect;
2232 prop = msi_dialog_dup_property( dialog, control->property, indirect );
2233 path = msi_dialog_dup_property( dialog, prop, TRUE );
2235 lstrcpyW( dir_spec, path );
2236 lstrcatW( dir_spec, asterisk );
2238 file = FindFirstFileW( dir_spec, &wfd );
2239 if ( file == INVALID_HANDLE_VALUE )
2244 if ( wfd.dwFileAttributes != FILE_ATTRIBUTE_DIRECTORY )
2247 if ( !lstrcmpW( wfd.cFileName, dot ) || !lstrcmpW( wfd.cFileName, dotdot ) )
2250 item.mask = LVIF_TEXT;
2251 item.cchTextMax = MAX_PATH;
2254 item.pszText = wfd.cFileName;
2256 SendMessageW( control->hwnd, LVM_INSERTITEMW, 0, (LPARAM)&item );
2257 } while ( FindNextFileW( file, &wfd ) );
2264 UINT msi_dialog_directorylist_up( msi_dialog *dialog )
2266 msi_control *control;
2267 LPWSTR prop, path, ptr;
2270 control = msi_dialog_find_control_by_type( dialog, szDirectoryList );
2271 indirect = control->attributes & msidbControlAttributesIndirect;
2272 prop = msi_dialog_dup_property( dialog, control->property, indirect );
2273 path = msi_dialog_dup_property( dialog, prop, TRUE );
2275 /* strip off the last directory */
2276 ptr = PathFindFileNameW( path );
2277 if (ptr != path) *(ptr - 1) = '\0';
2278 PathAddBackslashW( path );
2280 MSI_SetPropertyW( dialog->package, prop, path );
2282 msi_dialog_update_directory_list( dialog, NULL );
2283 msi_dialog_update_directory_combo( dialog, NULL );
2284 msi_dialog_update_pathedit( dialog, NULL );
2289 return ERROR_SUCCESS;
2292 static UINT msi_dialog_dirlist_handler( msi_dialog *dialog,
2293 msi_control *control, WPARAM param )
2295 LPNMHDR nmhdr = (LPNMHDR)param;
2296 WCHAR new_path[MAX_PATH];
2297 WCHAR text[MAX_PATH];
2303 static const WCHAR backslash[] = {'\\',0};
2305 if (nmhdr->code != LVN_ITEMACTIVATE)
2306 return ERROR_SUCCESS;
2308 index = SendMessageW( control->hwnd, LVM_GETNEXTITEM, -1, LVNI_SELECTED );
2311 ERR("No list-view item selected!\n");
2312 return ERROR_FUNCTION_FAILED;
2316 item.pszText = text;
2317 item.cchTextMax = MAX_PATH;
2318 SendMessageW( control->hwnd, LVM_GETITEMTEXTW, index, (LPARAM)&item );
2320 indirect = control->attributes & msidbControlAttributesIndirect;
2321 prop = msi_dialog_dup_property( dialog, control->property, indirect );
2322 path = msi_dialog_dup_property( dialog, prop, TRUE );
2324 lstrcpyW( new_path, path );
2325 lstrcatW( new_path, text );
2326 lstrcatW( new_path, backslash );
2328 MSI_SetPropertyW( dialog->package, prop, new_path );
2330 msi_dialog_update_directory_list( dialog, NULL );
2331 msi_dialog_update_directory_combo( dialog, NULL );
2332 msi_dialog_update_pathedit( dialog, NULL );
2336 return ERROR_SUCCESS;
2339 static UINT msi_dialog_directory_list( msi_dialog *dialog, MSIRECORD *rec )
2341 msi_control *control;
2345 style = LVS_LIST | WS_VSCROLL | LVS_SHAREIMAGELISTS |
2346 LVS_AUTOARRANGE | LVS_SINGLESEL | WS_BORDER |
2347 LVS_SORTASCENDING | WS_CHILD | WS_GROUP | WS_TABSTOP;
2348 control = msi_dialog_add_control( dialog, rec, WC_LISTVIEWW, style );
2350 return ERROR_FUNCTION_FAILED;
2352 control->attributes = MSI_RecordGetInteger( rec, 8 );
2353 control->handler = msi_dialog_dirlist_handler;
2354 prop = MSI_RecordGetString( rec, 9 );
2355 control->property = msi_dialog_dup_property( dialog, prop, FALSE );
2357 /* double click to activate an item in the list */
2358 SendMessageW( control->hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE,
2359 0, LVS_EX_TWOCLICKACTIVATE );
2361 msi_dialog_update_directory_list( dialog, control );
2363 return ERROR_SUCCESS;
2366 /******************** VolumeCost List ***************************************/
2368 static BOOL str_is_number( LPCWSTR str )
2372 for (i = 0; i < lstrlenW( str ); i++)
2373 if (!isdigitW(str[i]))
2379 WCHAR column_keys[][80] =
2381 {'V','o','l','u','m','e','C','o','s','t','V','o','l','u','m','e',0},
2382 {'V','o','l','u','m','e','C','o','s','t','S','i','z','e',0},
2383 {'V','o','l','u','m','e','C','o','s','t','A','v','a','i','l','a','b','l','e',0},
2384 {'V','o','l','u','m','e','C','o','s','t','R','e','q','u','i','r','e','d',0},
2385 {'V','o','l','u','m','e','C','o','s','t','D','i','f','f','e','r','e','n','c','e',0}
2388 static void msi_dialog_vcl_add_columns( msi_dialog *dialog, msi_control *control, MSIRECORD *rec )
2390 LPCWSTR text = MSI_RecordGetString( rec, 10 );
2391 LPCWSTR begin = text, end;
2396 static const WCHAR zero[] = {'0',0};
2397 static const WCHAR negative[] = {'-',0};
2399 while ((begin = strchrW( begin, '{' )) && count < 5)
2401 if (!(end = strchrW( begin, '}' )))
2404 lstrcpynW( num, begin + 1, end - begin );
2405 begin += end - begin + 1;
2407 /* empty braces or '0' hides the column */
2408 if ( !num[0] || !lstrcmpW( num, zero ) )
2414 /* the width must be a positive number
2415 * if a width is invalid, all remaining columns are hidden
2417 if ( !strncmpW( num, negative, 1 ) || !str_is_number( num ) )
2420 ZeroMemory( &lvc, sizeof(lvc) );
2421 lvc.mask = LVCF_TEXT | LVCF_WIDTH | LVCF_SUBITEM;
2422 lvc.cx = atolW( num );
2423 lvc.pszText = msi_dialog_get_uitext( dialog, column_keys[count] );
2425 SendMessageW( control->hwnd, LVM_INSERTCOLUMNW, count++, (LPARAM)&lvc );
2426 msi_free( lvc.pszText );
2430 static void msi_dialog_vcl_add_drives( msi_dialog *dialog, msi_control *control )
2432 ULARGE_INTEGER total, free;
2433 WCHAR size_text[MAX_PATH];
2439 size = GetLogicalDriveStringsW( 0, NULL );
2440 if ( !size ) return;
2442 drives = msi_alloc( (size + 1) * sizeof(WCHAR) );
2443 if ( !drives ) return;
2445 GetLogicalDriveStringsW( size, drives );
2450 lvitem.mask = LVIF_TEXT;
2452 lvitem.iSubItem = 0;
2453 lvitem.pszText = ptr;
2454 lvitem.cchTextMax = lstrlenW(ptr) + 1;
2455 SendMessageW( control->hwnd, LVM_INSERTITEMW, 0, (LPARAM)&lvitem );
2457 GetDiskFreeSpaceExW(ptr, &free, &total, NULL);
2459 StrFormatByteSizeW(total.QuadPart, size_text, MAX_PATH);
2460 lvitem.iSubItem = 1;
2461 lvitem.pszText = size_text;
2462 lvitem.cchTextMax = lstrlenW(size_text) + 1;
2463 SendMessageW( control->hwnd, LVM_SETITEMW, 0, (LPARAM)&lvitem );
2465 StrFormatByteSizeW(free.QuadPart, size_text, MAX_PATH);
2466 lvitem.iSubItem = 2;
2467 lvitem.pszText = size_text;
2468 lvitem.cchTextMax = lstrlenW(size_text) + 1;
2469 SendMessageW( control->hwnd, LVM_SETITEMW, 0, (LPARAM)&lvitem );
2471 ptr += lstrlenW(ptr) + 1;
2478 static UINT msi_dialog_volumecost_list( msi_dialog *dialog, MSIRECORD *rec )
2480 msi_control *control;
2483 style = LVS_REPORT | WS_VSCROLL | WS_HSCROLL | LVS_SHAREIMAGELISTS |
2484 LVS_AUTOARRANGE | LVS_SINGLESEL | WS_BORDER |
2485 WS_CHILD | WS_TABSTOP | WS_GROUP;
2486 control = msi_dialog_add_control( dialog, rec, WC_LISTVIEWW, style );
2488 return ERROR_FUNCTION_FAILED;
2490 msi_dialog_vcl_add_columns( dialog, control, rec );
2491 msi_dialog_vcl_add_drives( dialog, control );
2493 return ERROR_SUCCESS;
2496 static const struct control_handler msi_dialog_handler[] =
2498 { szText, msi_dialog_text_control },
2499 { szPushButton, msi_dialog_button_control },
2500 { szLine, msi_dialog_line_control },
2501 { szBitmap, msi_dialog_bitmap_control },
2502 { szCheckBox, msi_dialog_checkbox_control },
2503 { szScrollableText, msi_dialog_scrolltext_control },
2504 { szComboBox, msi_dialog_combo_control },
2505 { szEdit, msi_dialog_edit_control },
2506 { szMaskedEdit, msi_dialog_maskedit_control },
2507 { szPathEdit, msi_dialog_pathedit_control },
2508 { szProgressBar, msi_dialog_progress_bar },
2509 { szRadioButtonGroup, msi_dialog_radiogroup_control },
2510 { szIcon, msi_dialog_icon_control },
2511 { szSelectionTree, msi_dialog_selection_tree },
2512 { szGroupBox, msi_dialog_group_box },
2513 { szListBox, msi_dialog_list_box },
2514 { szDirectoryCombo, msi_dialog_directory_combo },
2515 { szDirectoryList, msi_dialog_directory_list },
2516 { szVolumeCostList, msi_dialog_volumecost_list },
2519 #define NUM_CONTROL_TYPES (sizeof msi_dialog_handler/sizeof msi_dialog_handler[0])
2521 static UINT msi_dialog_create_controls( MSIRECORD *rec, LPVOID param )
2523 msi_dialog *dialog = param;
2524 LPCWSTR control_type;
2527 /* find and call the function that can create this type of control */
2528 control_type = MSI_RecordGetString( rec, 3 );
2529 for( i=0; i<NUM_CONTROL_TYPES; i++ )
2530 if (!strcmpiW( msi_dialog_handler[i].control_type, control_type ))
2532 if( i != NUM_CONTROL_TYPES )
2533 msi_dialog_handler[i].func( dialog, rec );
2535 ERR("no handler for element type %s\n", debugstr_w(control_type));
2537 return ERROR_SUCCESS;
2540 static UINT msi_dialog_fill_controls( msi_dialog *dialog )
2542 static const WCHAR query[] = {
2543 'S','E','L','E','C','T',' ','*',' ',
2544 'F','R','O','M',' ','C','o','n','t','r','o','l',' ',
2545 'W','H','E','R','E',' ',
2546 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',0};
2548 MSIQUERY *view = NULL;
2549 MSIPACKAGE *package = dialog->package;
2551 TRACE("%p %s\n", dialog, debugstr_w(dialog->name) );
2553 /* query the Control table for all the elements of the control */
2554 r = MSI_OpenQuery( package->db, &view, query, dialog->name );
2555 if( r != ERROR_SUCCESS )
2557 ERR("query failed for dialog %s\n", debugstr_w(dialog->name));
2558 return ERROR_INVALID_PARAMETER;
2561 r = MSI_IterateRecords( view, 0, msi_dialog_create_controls, dialog );
2562 msiobj_release( &view->hdr );
2567 static UINT msi_dialog_set_control_condition( MSIRECORD *rec, LPVOID param )
2569 static const WCHAR szHide[] = { 'H','i','d','e',0 };
2570 static const WCHAR szShow[] = { 'S','h','o','w',0 };
2571 static const WCHAR szDisable[] = { 'D','i','s','a','b','l','e',0 };
2572 static const WCHAR szEnable[] = { 'E','n','a','b','l','e',0 };
2573 msi_dialog *dialog = param;
2574 msi_control *control;
2575 LPCWSTR name, action, condition;
2578 name = MSI_RecordGetString( rec, 2 );
2579 action = MSI_RecordGetString( rec, 3 );
2580 condition = MSI_RecordGetString( rec, 4 );
2581 r = MSI_EvaluateConditionW( dialog->package, condition );
2582 control = msi_dialog_find_control( dialog, name );
2583 if( r == MSICONDITION_TRUE && control )
2585 TRACE("%s control %s\n", debugstr_w(action), debugstr_w(name));
2587 /* FIXME: case sensitive? */
2588 if(!lstrcmpW(action, szHide))
2589 ShowWindow(control->hwnd, SW_HIDE);
2590 else if(!strcmpW(action, szShow))
2591 ShowWindow(control->hwnd, SW_SHOW);
2592 else if(!strcmpW(action, szDisable))
2593 EnableWindow(control->hwnd, FALSE);
2594 else if(!strcmpW(action, szEnable))
2595 EnableWindow(control->hwnd, TRUE);
2597 FIXME("Unhandled action %s\n", debugstr_w(action));
2600 return ERROR_SUCCESS;
2603 static UINT msi_dialog_evaluate_control_conditions( msi_dialog *dialog )
2605 static const WCHAR query[] = {
2606 'S','E','L','E','C','T',' ','*',' ',
2607 'F','R','O','M',' ',
2608 'C','o','n','t','r','o','l','C','o','n','d','i','t','i','o','n',' ',
2609 'W','H','E','R','E',' ',
2610 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',0
2613 MSIQUERY *view = NULL;
2614 MSIPACKAGE *package = dialog->package;
2616 TRACE("%p %s\n", dialog, debugstr_w(dialog->name) );
2618 /* query the Control table for all the elements of the control */
2619 r = MSI_OpenQuery( package->db, &view, query, dialog->name );
2620 if( r != ERROR_SUCCESS )
2621 return ERROR_SUCCESS;
2623 r = MSI_IterateRecords( view, 0, msi_dialog_set_control_condition, dialog );
2624 msiobj_release( &view->hdr );
2629 UINT msi_dialog_reset( msi_dialog *dialog )
2631 /* FIXME: should restore the original values of any properties we changed */
2632 return msi_dialog_evaluate_control_conditions( dialog );
2635 /* figure out the height of 10 point MS Sans Serif */
2636 static INT msi_dialog_get_sans_serif_height( HWND hwnd )
2638 static const WCHAR szSansSerif[] = {
2639 'M','S',' ','S','a','n','s',' ','S','e','r','i','f',0 };
2644 HFONT hFont, hOldFont;
2647 hdc = GetDC( hwnd );
2650 memset( &lf, 0, sizeof lf );
2651 lf.lfHeight = MulDiv(10, GetDeviceCaps(hdc, LOGPIXELSY), 72);
2652 strcpyW( lf.lfFaceName, szSansSerif );
2653 hFont = CreateFontIndirectW(&lf);
2656 hOldFont = SelectObject( hdc, hFont );
2657 r = GetTextMetricsW( hdc, &tm );
2659 height = tm.tmHeight;
2660 SelectObject( hdc, hOldFont );
2661 DeleteObject( hFont );
2663 ReleaseDC( hwnd, hdc );
2668 /* fetch the associated record from the Dialog table */
2669 static MSIRECORD *msi_get_dialog_record( msi_dialog *dialog )
2671 static const WCHAR query[] = {
2672 'S','E','L','E','C','T',' ','*',' ',
2673 'F','R','O','M',' ','D','i','a','l','o','g',' ',
2674 'W','H','E','R','E',' ',
2675 '`','D','i','a','l','o','g','`',' ','=',' ','\'','%','s','\'',0};
2676 MSIPACKAGE *package = dialog->package;
2677 MSIRECORD *rec = NULL;
2679 TRACE("%p %s\n", dialog, debugstr_w(dialog->name) );
2681 rec = MSI_QueryGetRecord( package->db, query, dialog->name );
2683 ERR("query failed for dialog %s\n", debugstr_w(dialog->name));
2688 static void msi_dialog_adjust_dialog_pos( msi_dialog *dialog, MSIRECORD *rec, LPRECT pos )
2690 static const WCHAR szScreenX[] = {'S','c','r','e','e','n','X',0};
2691 static const WCHAR szScreenY[] = {'S','c','r','e','e','n','Y',0};
2698 center.x = MSI_RecordGetInteger( rec, 2 );
2699 center.y = MSI_RecordGetInteger( rec, 3 );
2701 sz.cx = MSI_RecordGetInteger( rec, 4 );
2702 sz.cy = MSI_RecordGetInteger( rec, 5 );
2704 sz.cx = msi_dialog_scale_unit( dialog, sz.cx );
2705 sz.cy = msi_dialog_scale_unit( dialog, sz.cy );
2707 xres = msi_get_property_int( dialog->package, szScreenX, 0 );
2708 yres = msi_get_property_int( dialog->package, szScreenY, 0 );
2710 center.x = MulDiv( center.x, xres, 100 );
2711 center.y = MulDiv( center.y, yres, 100 );
2713 /* turn the client pos into the window rectangle */
2714 if (dialog->package->center_x && dialog->package->center_y)
2716 pos->left = dialog->package->center_x - sz.cx / 2.0;
2717 pos->right = pos->left + sz.cx;
2718 pos->top = dialog->package->center_y - sz.cy / 2.0;
2719 pos->bottom = pos->top + sz.cy;
2723 pos->left = center.x - sz.cx/2;
2724 pos->right = pos->left + sz.cx;
2725 pos->top = center.y - sz.cy/2;
2726 pos->bottom = pos->top + sz.cy;
2728 /* save the center */
2729 dialog->package->center_x = center.x;
2730 dialog->package->center_y = center.y;
2733 dialog->size.cx = sz.cx;
2734 dialog->size.cy = sz.cy;
2736 TRACE("%u %u %u %u\n", pos->left, pos->top, pos->right, pos->bottom);
2738 style = GetWindowLongPtrW( dialog->hwnd, GWL_STYLE );
2739 AdjustWindowRect( pos, style, FALSE );
2742 static BOOL msi_control_set_next( msi_control *control, msi_control *next )
2744 return SetWindowPos( next->hwnd, control->hwnd, 0, 0, 0, 0,
2745 SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOREDRAW |
2746 SWP_NOREPOSITION | SWP_NOSENDCHANGING | SWP_NOSIZE );
2749 static UINT msi_dialog_set_tab_order( msi_dialog *dialog )
2751 msi_control *control, *tab_next;
2753 LIST_FOR_EACH_ENTRY( control, &dialog->controls, msi_control, entry )
2755 tab_next = msi_dialog_find_control( dialog, control->tabnext );
2758 msi_control_set_next( control, tab_next );
2761 return ERROR_SUCCESS;
2764 static void msi_dialog_set_first_control( msi_dialog* dialog, LPCWSTR name )
2766 msi_control *control;
2768 control = msi_dialog_find_control( dialog, name );
2770 dialog->hWndFocus = control->hwnd;
2772 dialog->hWndFocus = NULL;
2775 static LRESULT msi_dialog_oncreate( HWND hwnd, LPCREATESTRUCTW cs )
2777 static const WCHAR df[] = {
2778 'D','e','f','a','u','l','t','U','I','F','o','n','t',0 };
2779 static const WCHAR dfv[] = {
2780 'M','S',' ','S','h','e','l','l',' ','D','l','g',0 };
2781 msi_dialog *dialog = (msi_dialog*) cs->lpCreateParams;
2782 MSIRECORD *rec = NULL;
2783 LPWSTR title = NULL;
2786 TRACE("%p %p\n", dialog, dialog->package);
2788 dialog->hwnd = hwnd;
2789 SetWindowLongPtrW( hwnd, GWLP_USERDATA, (LONG_PTR) dialog );
2791 rec = msi_get_dialog_record( dialog );
2794 TRACE("No record found for dialog %s\n", debugstr_w(dialog->name));
2798 dialog->scale = msi_dialog_get_sans_serif_height(dialog->hwnd);
2800 msi_dialog_adjust_dialog_pos( dialog, rec, &pos );
2802 dialog->attributes = MSI_RecordGetInteger( rec, 6 );
2804 dialog->default_font = msi_dup_property( dialog->package, df );
2805 if (!dialog->default_font)
2807 dialog->default_font = strdupW(dfv);
2808 if (!dialog->default_font) return -1;
2811 title = msi_get_deformatted_field( dialog->package, rec, 7 );
2812 SetWindowTextW( hwnd, title );
2815 SetWindowPos( hwnd, 0, pos.left, pos.top,
2816 pos.right - pos.left, pos.bottom - pos.top,
2817 SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOREDRAW );
2819 msi_dialog_build_font_list( dialog );
2820 msi_dialog_fill_controls( dialog );
2821 msi_dialog_evaluate_control_conditions( dialog );
2822 msi_dialog_set_tab_order( dialog );
2823 msi_dialog_set_first_control( dialog, MSI_RecordGetString( rec, 8 ) );
2824 msiobj_release( &rec->hdr );
2829 static UINT msi_dialog_send_event( msi_dialog *dialog, LPCWSTR event, LPCWSTR arg )
2831 LPWSTR event_fmt = NULL, arg_fmt = NULL;
2833 TRACE("Sending control event %s %s\n", debugstr_w(event), debugstr_w(arg));
2835 deformat_string( dialog->package, event, &event_fmt );
2836 deformat_string( dialog->package, arg, &arg_fmt );
2838 dialog->event_handler( dialog->package, event_fmt, arg_fmt, dialog );
2840 msi_free( event_fmt );
2841 msi_free( arg_fmt );
2843 return ERROR_SUCCESS;
2846 static UINT msi_dialog_set_property( msi_dialog *dialog, LPCWSTR event, LPCWSTR arg )
2848 static const WCHAR szNullArg[] = { '{','}',0 };
2849 LPWSTR p, prop, arg_fmt = NULL;
2852 len = strlenW(event);
2853 prop = msi_alloc( len*sizeof(WCHAR));
2854 strcpyW( prop, &event[1] );
2855 p = strchrW( prop, ']' );
2856 if( p && p[1] == 0 )
2859 if( strcmpW( szNullArg, arg ) )
2860 deformat_string( dialog->package, arg, &arg_fmt );
2861 MSI_SetPropertyW( dialog->package, prop, arg_fmt );
2862 msi_free( arg_fmt );
2865 ERR("Badly formatted property string - what happens?\n");
2867 return ERROR_SUCCESS;
2870 static UINT msi_dialog_control_event( MSIRECORD *rec, LPVOID param )
2872 msi_dialog *dialog = param;
2873 LPCWSTR condition, event, arg;
2876 condition = MSI_RecordGetString( rec, 5 );
2877 r = MSI_EvaluateConditionW( dialog->package, condition );
2878 if( r == MSICONDITION_TRUE || r == MSICONDITION_NONE )
2880 event = MSI_RecordGetString( rec, 3 );
2881 arg = MSI_RecordGetString( rec, 4 );
2882 if( event[0] == '[' )
2883 msi_dialog_set_property( dialog, event, arg );
2885 msi_dialog_send_event( dialog, event, arg );
2888 return ERROR_SUCCESS;
2891 static UINT msi_dialog_button_handler( msi_dialog *dialog,
2892 msi_control *control, WPARAM param )
2894 static const WCHAR query[] = {
2895 'S','E','L','E','C','T',' ','*',' ',
2896 'F','R','O','M',' ','C','o','n','t','r','o','l','E','v','e','n','t',' ',
2897 'W','H','E','R','E',' ',
2898 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',' ',
2900 '`','C','o','n','t','r','o','l','_','`',' ','=',' ','\'','%','s','\'',' ',
2901 'O','R','D','E','R',' ','B','Y',' ','`','O','r','d','e','r','i','n','g','`',0
2903 MSIQUERY *view = NULL;
2906 if( HIWORD(param) != BN_CLICKED )
2907 return ERROR_SUCCESS;
2909 r = MSI_OpenQuery( dialog->package->db, &view, query,
2910 dialog->name, control->name );
2911 if( r != ERROR_SUCCESS )
2913 ERR("query failed\n");
2917 r = MSI_ReverseIterateRecords( view, 0, msi_dialog_control_event, dialog );
2918 msiobj_release( &view->hdr );
2923 static UINT msi_dialog_get_checkbox_state( msi_dialog *dialog,
2924 msi_control *control )
2926 WCHAR state[2] = { 0 };
2929 MSI_GetPropertyW( dialog->package, control->property, state, &sz );
2930 return state[0] ? 1 : 0;
2933 static void msi_dialog_set_checkbox_state( msi_dialog *dialog,
2934 msi_control *control, UINT state )
2936 static const WCHAR szState[] = { '1', 0 };
2939 /* if uncheck then the property is set to NULL */
2942 MSI_SetPropertyW( dialog->package, control->property, NULL );
2946 /* check for a custom state */
2947 if (control->value && control->value[0])
2948 val = control->value;
2952 MSI_SetPropertyW( dialog->package, control->property, val );
2955 static void msi_dialog_checkbox_sync_state( msi_dialog *dialog,
2956 msi_control *control )
2960 state = msi_dialog_get_checkbox_state( dialog, control );
2961 SendMessageW( control->hwnd, BM_SETCHECK,
2962 state ? BST_CHECKED : BST_UNCHECKED, 0 );
2965 static UINT msi_dialog_checkbox_handler( msi_dialog *dialog,
2966 msi_control *control, WPARAM param )
2970 if( HIWORD(param) != BN_CLICKED )
2971 return ERROR_SUCCESS;
2973 TRACE("clicked checkbox %s, set %s\n", debugstr_w(control->name),
2974 debugstr_w(control->property));
2976 state = msi_dialog_get_checkbox_state( dialog, control );
2977 state = state ? 0 : 1;
2978 msi_dialog_set_checkbox_state( dialog, control, state );
2979 msi_dialog_checkbox_sync_state( dialog, control );
2981 return msi_dialog_button_handler( dialog, control, param );
2984 static UINT msi_dialog_edit_handler( msi_dialog *dialog,
2985 msi_control *control, WPARAM param )
2989 if( HIWORD(param) != EN_CHANGE )
2990 return ERROR_SUCCESS;
2992 TRACE("edit %s contents changed, set %s\n", debugstr_w(control->name),
2993 debugstr_w(control->property));
2995 buf = msi_get_window_text( control->hwnd );
2996 MSI_SetPropertyW( dialog->package, control->property, buf );
3000 return ERROR_SUCCESS;
3003 static UINT msi_dialog_radiogroup_handler( msi_dialog *dialog,
3004 msi_control *control, WPARAM param )
3006 if( HIWORD(param) != BN_CLICKED )
3007 return ERROR_SUCCESS;
3009 TRACE("clicked radio button %s, set %s\n", debugstr_w(control->name),
3010 debugstr_w(control->property));
3012 MSI_SetPropertyW( dialog->package, control->property, control->name );
3014 return msi_dialog_button_handler( dialog, control, param );
3017 static LRESULT msi_dialog_oncommand( msi_dialog *dialog, WPARAM param, HWND hwnd )
3019 msi_control *control = NULL;
3021 TRACE("%p %p %08x\n", dialog, hwnd, param);
3026 control = msi_dialog_find_control( dialog, dialog->control_default );
3028 case 2: /* escape */
3029 control = msi_dialog_find_control( dialog, dialog->control_cancel );
3032 control = msi_dialog_find_control_by_hwnd( dialog, hwnd );
3037 if( control->handler )
3039 control->handler( dialog, control, param );
3040 msi_dialog_evaluate_control_conditions( dialog );
3044 ERR("button click from nowhere %p %d %p\n", dialog, param, hwnd);
3048 static LRESULT msi_dialog_onnotify( msi_dialog *dialog, LPARAM param )
3050 LPNMHDR nmhdr = (LPNMHDR) param;
3051 msi_control *control = msi_dialog_find_control_by_hwnd( dialog, nmhdr->hwndFrom );
3053 TRACE("%p %p\n", dialog, nmhdr->hwndFrom);
3055 if ( control && control->handler )
3056 control->handler( dialog, control, param );
3061 static void msi_dialog_setfocus( msi_dialog *dialog )
3063 HWND hwnd = dialog->hWndFocus;
3065 hwnd = GetNextDlgTabItem( dialog->hwnd, hwnd, TRUE);
3066 hwnd = GetNextDlgTabItem( dialog->hwnd, hwnd, FALSE);
3068 dialog->hWndFocus = hwnd;
3071 static LRESULT WINAPI MSIDialog_WndProc( HWND hwnd, UINT msg,
3072 WPARAM wParam, LPARAM lParam )
3074 msi_dialog *dialog = (LPVOID) GetWindowLongPtrW( hwnd, GWLP_USERDATA );
3076 TRACE("0x%04x\n", msg);
3081 dialog->package->center_x = LOWORD(lParam) + dialog->size.cx / 2.0;
3082 dialog->package->center_y = HIWORD(lParam) + dialog->size.cy / 2.0;
3086 return msi_dialog_oncreate( hwnd, (LPCREATESTRUCTW)lParam );
3089 return msi_dialog_oncommand( dialog, wParam, (HWND)lParam );
3092 if( LOWORD(wParam) == WA_INACTIVE )
3093 dialog->hWndFocus = GetFocus();
3095 msi_dialog_setfocus( dialog );
3099 msi_dialog_setfocus( dialog );
3102 /* bounce back to our subclassed static control */
3103 case WM_CTLCOLORSTATIC:
3104 return SendMessageW( (HWND) lParam, WM_CTLCOLORSTATIC, wParam, lParam );
3107 dialog->hwnd = NULL;
3110 return msi_dialog_onnotify( dialog, lParam );
3112 return DefWindowProcW(hwnd, msg, wParam, lParam);
3115 static BOOL CALLBACK msi_radioground_child_enum( HWND hWnd, LPARAM lParam )
3117 EnableWindow( hWnd, lParam );
3121 static LRESULT WINAPI MSIRadioGroup_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
3123 WNDPROC oldproc = (WNDPROC) GetPropW(hWnd, szButtonData);
3126 TRACE("hWnd %p msg %04x wParam 0x%08x lParam 0x%08lx\n", hWnd, msg, wParam, lParam);
3128 if (msg == WM_COMMAND) /* Forward notifications to dialog */
3129 SendMessageW(GetParent(hWnd), msg, wParam, lParam);
3131 r = CallWindowProcW(oldproc, hWnd, msg, wParam, lParam);
3133 /* make sure the radio buttons show as disabled if the parent is disabled */
3134 if (msg == WM_ENABLE)
3135 EnumChildWindows( hWnd, msi_radioground_child_enum, wParam );
3140 static LRESULT WINAPI MSIHiddenWindowProc( HWND hwnd, UINT msg,
3141 WPARAM wParam, LPARAM lParam )
3143 msi_dialog *dialog = (msi_dialog*) lParam;
3145 TRACE("%d %p\n", msg, dialog);
3149 case WM_MSI_DIALOG_CREATE:
3150 return msi_dialog_run_message_loop( dialog );
3151 case WM_MSI_DIALOG_DESTROY:
3152 msi_dialog_destroy( dialog );
3155 return DefWindowProcW( hwnd, msg, wParam, lParam );
3158 /* functions that interface to other modules within MSI */
3160 msi_dialog *msi_dialog_create( MSIPACKAGE* package,
3161 LPCWSTR szDialogName, msi_dialog *parent,
3162 msi_dialog_event_handler event_handler )
3164 MSIRECORD *rec = NULL;
3167 TRACE("%p %s\n", package, debugstr_w(szDialogName));
3169 /* allocate the structure for the dialog to use */
3170 dialog = msi_alloc_zero( sizeof *dialog + sizeof(WCHAR)*strlenW(szDialogName) );
3173 strcpyW( dialog->name, szDialogName );
3174 dialog->parent = parent;
3175 msiobj_addref( &package->hdr );
3176 dialog->package = package;
3177 dialog->event_handler = event_handler;
3178 dialog->finished = 0;
3179 list_init( &dialog->controls );
3181 /* verify that the dialog exists */
3182 rec = msi_get_dialog_record( dialog );
3185 msiobj_release( &package->hdr );
3189 dialog->attributes = MSI_RecordGetInteger( rec, 6 );
3190 dialog->control_default = strdupW( MSI_RecordGetString( rec, 9 ) );
3191 dialog->control_cancel = strdupW( MSI_RecordGetString( rec, 10 ) );
3192 msiobj_release( &rec->hdr );
3197 static void msi_process_pending_messages( HWND hdlg )
3201 while( PeekMessageW( &msg, 0, 0, 0, PM_REMOVE ) )
3203 if( hdlg && IsDialogMessageW( hdlg, &msg ))
3205 TranslateMessage( &msg );
3206 DispatchMessageW( &msg );
3210 void msi_dialog_end_dialog( msi_dialog *dialog )
3212 TRACE("%p\n", dialog);
3213 dialog->finished = 1;
3214 PostMessageW(dialog->hwnd, WM_NULL, 0, 0);
3217 void msi_dialog_check_messages( HANDLE handle )
3221 /* in threads other than the UI thread, block */
3222 if( uiThreadId != GetCurrentThreadId() )
3225 WaitForSingleObject( handle, INFINITE );
3229 /* there's two choices for the UI thread */
3232 msi_process_pending_messages( NULL );
3238 * block here until somebody creates a new dialog or
3239 * the handle we're waiting on becomes ready
3241 r = MsgWaitForMultipleObjects( 1, &handle, 0, INFINITE, QS_ALLINPUT );
3242 if( r == WAIT_OBJECT_0 )
3247 UINT msi_dialog_run_message_loop( msi_dialog *dialog )
3252 if( uiThreadId != GetCurrentThreadId() )
3253 return SendMessageW( hMsiHiddenWindow, WM_MSI_DIALOG_CREATE, 0, (LPARAM) dialog );
3255 /* create the dialog window, don't show it yet */
3256 style = WS_OVERLAPPED;
3257 if( dialog->attributes & msidbDialogAttributesVisible )
3258 style |= WS_VISIBLE;
3260 hwnd = CreateWindowW( szMsiDialogClass, dialog->name, style,
3261 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
3262 NULL, NULL, NULL, dialog );
3265 ERR("Failed to create dialog %s\n", debugstr_w( dialog->name ));
3266 return ERROR_FUNCTION_FAILED;
3269 ShowWindow( hwnd, SW_SHOW );
3270 /* UpdateWindow( hwnd ); - and causes the transparent static controls not to paint */
3272 if( dialog->attributes & msidbDialogAttributesModal )
3274 while( !dialog->finished )
3276 MsgWaitForMultipleObjects( 0, NULL, 0, INFINITE, QS_ALLINPUT );
3277 msi_process_pending_messages( dialog->hwnd );
3281 return ERROR_IO_PENDING;
3283 return ERROR_SUCCESS;
3286 void msi_dialog_do_preview( msi_dialog *dialog )
3289 dialog->attributes |= msidbDialogAttributesVisible;
3290 dialog->attributes &= ~msidbDialogAttributesModal;
3291 msi_dialog_run_message_loop( dialog );
3294 void msi_dialog_destroy( msi_dialog *dialog )
3296 if( uiThreadId != GetCurrentThreadId() )
3298 SendMessageW( hMsiHiddenWindow, WM_MSI_DIALOG_DESTROY, 0, (LPARAM) dialog );
3303 ShowWindow( dialog->hwnd, SW_HIDE );
3306 DestroyWindow( dialog->hwnd );
3308 /* destroy the list of controls */
3309 while( !list_empty( &dialog->controls ) )
3311 msi_control *t = LIST_ENTRY( list_head( &dialog->controls ),
3312 msi_control, entry );
3313 list_remove( &t->entry );
3314 /* leave dialog->hwnd - destroying parent destroys child windows */
3315 msi_free( t->property );
3316 msi_free( t->value );
3318 DeleteObject( t->hBitmap );
3320 DestroyIcon( t->hIcon );
3321 msi_free( t->tabnext );
3322 msi_free( t->type );
3325 FreeLibrary( t->hDll );
3328 /* destroy the list of fonts */
3329 while( dialog->font_list )
3331 msi_font *t = dialog->font_list;
3332 dialog->font_list = t->next;
3333 DeleteObject( t->hfont );
3336 msi_free( dialog->default_font );
3338 msi_free( dialog->control_default );
3339 msi_free( dialog->control_cancel );
3340 msiobj_release( &dialog->package->hdr );
3341 dialog->package = NULL;
3345 BOOL msi_dialog_register_class( void )
3349 ZeroMemory( &cls, sizeof cls );
3350 cls.lpfnWndProc = MSIDialog_WndProc;
3351 cls.hInstance = NULL;
3352 cls.hIcon = LoadIconW(0, (LPWSTR)IDI_APPLICATION);
3353 cls.hCursor = LoadCursorW(0, (LPWSTR)IDC_ARROW);
3354 cls.hbrBackground = (HBRUSH)(COLOR_3DFACE + 1);
3355 cls.lpszMenuName = NULL;
3356 cls.lpszClassName = szMsiDialogClass;
3358 if( !RegisterClassW( &cls ) )
3361 cls.lpfnWndProc = MSIHiddenWindowProc;
3362 cls.lpszClassName = szMsiHiddenWindow;
3364 if( !RegisterClassW( &cls ) )
3367 uiThreadId = GetCurrentThreadId();
3369 hMsiHiddenWindow = CreateWindowW( szMsiHiddenWindow, NULL, WS_OVERLAPPED,
3370 0, 0, 100, 100, NULL, NULL, NULL, NULL );
3371 if( !hMsiHiddenWindow )
3377 void msi_dialog_unregister_class( void )
3379 DestroyWindow( hMsiHiddenWindow );
3380 hMsiHiddenWindow = NULL;
3381 UnregisterClassW( szMsiDialogClass, NULL );
3382 UnregisterClassW( szMsiHiddenWindow, NULL );