2 * Implementation of the Microsoft Installer (msi.dll)
4 * Copyright 2005 Mike McCormack for CodeWeavers
5 * Copyright 2005 Aric Stewart for CodeWeavers
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
28 WINE_DEFAULT_DEBUG_CHANNEL(msi
);
30 extern HINSTANCE msi_hInstance
;
32 struct msi_control_tag
;
33 typedef struct msi_control_tag msi_control
;
34 typedef UINT (*msi_handler
)( msi_dialog
*, msi_control
*, WPARAM
);
35 typedef void (*msi_update
)( msi_dialog
*, msi_control
* );
36 typedef UINT (*control_event_handler
)( msi_dialog
*, const WCHAR
*, const WCHAR
* );
38 struct msi_control_tag
51 float progress_current
;
53 BOOL progress_backwards
;
58 typedef struct msi_font_tag
70 control_event_handler event_handler
;
80 LPWSTR control_default
;
81 LPWSTR control_cancel
;
94 typedef UINT (*msi_dialog_control_func
)( msi_dialog
*dialog
, MSIRECORD
*rec
);
95 struct control_handler
98 msi_dialog_control_func func
;
106 } radio_button_group_descr
;
108 static const WCHAR szMsiDialogClass
[] = { 'M','s','i','D','i','a','l','o','g','C','l','o','s','e','C','l','a','s','s',0 };
109 static const WCHAR szMsiHiddenWindow
[] = { 'M','s','i','H','i','d','d','e','n','W','i','n','d','o','w',0 };
110 static const WCHAR szStatic
[] = { 'S','t','a','t','i','c',0 };
111 static const WCHAR szButton
[] = { 'B','U','T','T','O','N', 0 };
112 static const WCHAR szButtonData
[] = { 'M','S','I','D','A','T','A',0 };
113 static const WCHAR szProgress
[] = { 'P','r','o','g','r','e','s','s',0 };
114 static const WCHAR szText
[] = { 'T','e','x','t',0 };
115 static const WCHAR szPushButton
[] = { 'P','u','s','h','B','u','t','t','o','n',0 };
116 static const WCHAR szLine
[] = { 'L','i','n','e',0 };
117 static const WCHAR szBitmap
[] = { 'B','i','t','m','a','p',0 };
118 static const WCHAR szCheckBox
[] = { 'C','h','e','c','k','B','o','x',0 };
119 static const WCHAR szScrollableText
[] = { 'S','c','r','o','l','l','a','b','l','e','T','e','x','t',0 };
120 static const WCHAR szComboBox
[] = { 'C','o','m','b','o','B','o','x',0 };
121 static const WCHAR szEdit
[] = { 'E','d','i','t',0 };
122 static const WCHAR szMaskedEdit
[] = { 'M','a','s','k','e','d','E','d','i','t',0 };
123 static const WCHAR szPathEdit
[] = { 'P','a','t','h','E','d','i','t',0 };
124 static const WCHAR szProgressBar
[] = { 'P','r','o','g','r','e','s','s','B','a','r',0 };
125 static const WCHAR szSetProgress
[] = { 'S','e','t','P','r','o','g','r','e','s','s',0 };
126 static const WCHAR szRadioButtonGroup
[] = { 'R','a','d','i','o','B','u','t','t','o','n','G','r','o','u','p',0 };
127 static const WCHAR szIcon
[] = { 'I','c','o','n',0 };
128 static const WCHAR szSelectionTree
[] = { 'S','e','l','e','c','t','i','o','n','T','r','e','e',0 };
129 static const WCHAR szGroupBox
[] = { 'G','r','o','u','p','B','o','x',0 };
130 static const WCHAR szListBox
[] = { 'L','i','s','t','B','o','x',0 };
131 static const WCHAR szDirectoryCombo
[] = { 'D','i','r','e','c','t','o','r','y','C','o','m','b','o',0 };
132 static const WCHAR szDirectoryList
[] = { 'D','i','r','e','c','t','o','r','y','L','i','s','t',0 };
133 static const WCHAR szVolumeCostList
[] = { 'V','o','l','u','m','e','C','o','s','t','L','i','s','t',0 };
134 static const WCHAR szVolumeSelectCombo
[] = { 'V','o','l','u','m','e','S','e','l','e','c','t','C','o','m','b','o',0 };
135 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};
136 static const WCHAR szSelectionPath
[] = {'S','e','l','e','c','t','i','o','n','P','a','t','h',0};
137 static const WCHAR szHyperLink
[] = {'H','y','p','e','r','L','i','n','k',0};
139 /* dialog sequencing */
141 #define WM_MSI_DIALOG_CREATE (WM_USER+0x100)
142 #define WM_MSI_DIALOG_DESTROY (WM_USER+0x101)
144 #define USER_INSTALLSTATE_ALL 0x1000
146 static DWORD uiThreadId
;
147 static HWND hMsiHiddenWindow
;
149 static LPWSTR
msi_get_window_text( HWND hwnd
)
155 buf
= msi_alloc( sz
*sizeof(WCHAR
) );
158 r
= GetWindowTextW( hwnd
, buf
, sz
);
162 buf
= msi_realloc( buf
, sz
*sizeof(WCHAR
) );
168 static INT
msi_dialog_scale_unit( msi_dialog
*dialog
, INT val
)
170 return MulDiv( val
, dialog
->scale
, 12 );
173 static msi_control
*msi_dialog_find_control( msi_dialog
*dialog
, LPCWSTR name
)
175 msi_control
*control
;
181 LIST_FOR_EACH_ENTRY( control
, &dialog
->controls
, msi_control
, entry
)
182 if( !strcmpW( control
->name
, name
) ) /* FIXME: case sensitive? */
187 static msi_control
*msi_dialog_find_control_by_type( msi_dialog
*dialog
, LPCWSTR type
)
189 msi_control
*control
;
195 LIST_FOR_EACH_ENTRY( control
, &dialog
->controls
, msi_control
, entry
)
196 if( !strcmpW( control
->type
, type
) ) /* FIXME: case sensitive? */
201 static msi_control
*msi_dialog_find_control_by_hwnd( msi_dialog
*dialog
, HWND hwnd
)
203 msi_control
*control
;
207 LIST_FOR_EACH_ENTRY( control
, &dialog
->controls
, msi_control
, entry
)
208 if( hwnd
== control
->hwnd
)
213 static LPWSTR
msi_get_deformatted_field( MSIPACKAGE
*package
, MSIRECORD
*rec
, int field
)
215 LPCWSTR str
= MSI_RecordGetString( rec
, field
);
219 deformat_string( package
, str
, &ret
);
223 static LPWSTR
msi_dialog_dup_property( msi_dialog
*dialog
, LPCWSTR property
, BOOL indirect
)
231 prop
= msi_dup_property( dialog
->package
->db
, property
);
234 prop
= strdupW( property
);
240 * msi_dialog_get_style
242 * Extract the {\style} string from the front of the text to display and
243 * update the pointer. Only the last style in a list is applied.
245 static LPWSTR
msi_dialog_get_style( LPCWSTR p
, LPCWSTR
*rest
)
256 while ((first
= strchrW( p
, '{' )) && (q
= strchrW( first
+ 1, '}' )))
259 if( *p
!= '\\' && *p
!= '&' )
262 /* little bit of sanity checking to stop us getting confused with RTF */
263 for( i
=++p
; i
<q
; i
++ )
264 if( *i
== '}' || *i
== '\\' )
274 ret
= msi_alloc( len
*sizeof(WCHAR
) );
277 memcpy( ret
, p
, len
*sizeof(WCHAR
) );
282 static UINT
msi_dialog_add_font( MSIRECORD
*rec
, LPVOID param
)
284 msi_dialog
*dialog
= param
;
291 /* create a font and add it to the list */
292 name
= MSI_RecordGetString( rec
, 1 );
293 font
= msi_alloc( FIELD_OFFSET( msi_font
, name
[strlenW( name
) + 1] ));
294 strcpyW( font
->name
, name
);
295 list_add_head( &dialog
->fonts
, &font
->entry
);
297 font
->color
= MSI_RecordGetInteger( rec
, 4 );
299 memset( &lf
, 0, sizeof lf
);
300 face
= MSI_RecordGetString( rec
, 2 );
301 lf
.lfHeight
= MSI_RecordGetInteger( rec
, 3 );
302 style
= MSI_RecordGetInteger( rec
, 5 );
303 if( style
& msidbTextStyleStyleBitsBold
)
304 lf
.lfWeight
= FW_BOLD
;
305 if( style
& msidbTextStyleStyleBitsItalic
)
307 if( style
& msidbTextStyleStyleBitsUnderline
)
308 lf
.lfUnderline
= TRUE
;
309 if( style
& msidbTextStyleStyleBitsStrike
)
310 lf
.lfStrikeOut
= TRUE
;
311 lstrcpynW( lf
.lfFaceName
, face
, LF_FACESIZE
);
313 /* adjust the height */
314 hdc
= GetDC( dialog
->hwnd
);
317 lf
.lfHeight
= -MulDiv(lf
.lfHeight
, GetDeviceCaps(hdc
, LOGPIXELSY
), 72);
318 ReleaseDC( dialog
->hwnd
, hdc
);
321 font
->hfont
= CreateFontIndirectW( &lf
);
323 TRACE("Adding font style %s\n", debugstr_w(font
->name
) );
325 return ERROR_SUCCESS
;
328 static msi_font
*msi_dialog_find_font( msi_dialog
*dialog
, LPCWSTR name
)
330 msi_font
*font
= NULL
;
332 LIST_FOR_EACH_ENTRY( font
, &dialog
->fonts
, msi_font
, entry
)
333 if( !strcmpW( font
->name
, name
) ) /* FIXME: case sensitive? */
339 static UINT
msi_dialog_set_font( msi_dialog
*dialog
, HWND hwnd
, LPCWSTR name
)
343 font
= msi_dialog_find_font( dialog
, name
);
345 SendMessageW( hwnd
, WM_SETFONT
, (WPARAM
) font
->hfont
, TRUE
);
347 ERR("No font entry for %s\n", debugstr_w(name
));
348 return ERROR_SUCCESS
;
351 static UINT
msi_dialog_build_font_list( msi_dialog
*dialog
)
353 static const WCHAR query
[] = {
354 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
355 '`','T','e','x','t','S','t','y','l','e','`',0};
359 TRACE("dialog %p\n", dialog
);
361 r
= MSI_OpenQuery( dialog
->package
->db
, &view
, query
);
362 if( r
!= ERROR_SUCCESS
)
365 r
= MSI_IterateRecords( view
, NULL
, msi_dialog_add_font
, dialog
);
366 msiobj_release( &view
->hdr
);
370 static void msi_destroy_control( msi_control
*t
)
372 list_remove( &t
->entry
);
373 /* leave dialog->hwnd - destroying parent destroys child windows */
374 msi_free( t
->property
);
375 msi_free( t
->value
);
377 DeleteObject( t
->hBitmap
);
379 DestroyIcon( t
->hIcon
);
380 msi_free( t
->tabnext
);
383 FreeLibrary( t
->hDll
);
387 static msi_control
*dialog_create_window( msi_dialog
*dialog
, MSIRECORD
*rec
, DWORD exstyle
,
388 const WCHAR
*szCls
, const WCHAR
*name
, const WCHAR
*text
,
389 DWORD style
, HWND parent
)
391 DWORD x
, y
, width
, height
;
392 LPWSTR font
= NULL
, title_font
= NULL
;
393 LPCWSTR title
= NULL
;
394 msi_control
*control
;
398 control
= msi_alloc( FIELD_OFFSET( msi_control
, name
[strlenW( name
) + 1] ));
402 strcpyW( control
->name
, name
);
403 list_add_tail( &dialog
->controls
, &control
->entry
);
404 control
->handler
= NULL
;
405 control
->update
= NULL
;
406 control
->property
= NULL
;
407 control
->value
= NULL
;
408 control
->hBitmap
= NULL
;
409 control
->hIcon
= NULL
;
410 control
->hDll
= NULL
;
411 control
->tabnext
= strdupW( MSI_RecordGetString( rec
, 11) );
412 control
->type
= strdupW( MSI_RecordGetString( rec
, 3 ) );
413 control
->progress_current
= 0;
414 control
->progress_max
= 100;
415 control
->progress_backwards
= FALSE
;
417 x
= MSI_RecordGetInteger( rec
, 4 );
418 y
= MSI_RecordGetInteger( rec
, 5 );
419 width
= MSI_RecordGetInteger( rec
, 6 );
420 height
= MSI_RecordGetInteger( rec
, 7 );
422 x
= msi_dialog_scale_unit( dialog
, x
);
423 y
= msi_dialog_scale_unit( dialog
, y
);
424 width
= msi_dialog_scale_unit( dialog
, width
);
425 height
= msi_dialog_scale_unit( dialog
, height
);
429 deformat_string( dialog
->package
, text
, &title_font
);
430 font
= msi_dialog_get_style( title_font
, &title
);
433 control
->hwnd
= CreateWindowExW( exstyle
, szCls
, title
, style
,
434 x
, y
, width
, height
, parent
, NULL
, NULL
, NULL
);
436 TRACE("Dialog %s control %s hwnd %p\n",
437 debugstr_w(dialog
->name
), debugstr_w(text
), control
->hwnd
);
439 msi_dialog_set_font( dialog
, control
->hwnd
,
440 font
? font
: dialog
->default_font
);
442 msi_free( title_font
);
448 static LPWSTR
msi_dialog_get_uitext( msi_dialog
*dialog
, LPCWSTR key
)
453 static const WCHAR query
[] = {
454 's','e','l','e','c','t',' ','*',' ',
455 'f','r','o','m',' ','`','U','I','T','e','x','t','`',' ',
456 'w','h','e','r','e',' ','`','K','e','y','`',' ','=',' ','\'','%','s','\'',0
459 rec
= MSI_QueryGetRecord( dialog
->package
->db
, query
, key
);
460 if (!rec
) return NULL
;
461 text
= strdupW( MSI_RecordGetString( rec
, 2 ) );
462 msiobj_release( &rec
->hdr
);
466 static MSIRECORD
*msi_get_binary_record( MSIDATABASE
*db
, LPCWSTR name
)
468 static const WCHAR query
[] = {
469 's','e','l','e','c','t',' ','*',' ',
470 'f','r','o','m',' ','B','i','n','a','r','y',' ',
471 'w','h','e','r','e',' ',
472 '`','N','a','m','e','`',' ','=',' ','\'','%','s','\'',0
475 return MSI_QueryGetRecord( db
, query
, name
);
478 static HANDLE
msi_load_image( MSIDATABASE
*db
, LPCWSTR name
, UINT type
,
479 UINT cx
, UINT cy
, UINT flags
)
482 HANDLE himage
= NULL
;
486 TRACE("%p %s %u %u %08x\n", db
, debugstr_w(name
), cx
, cy
, flags
);
488 if (!(tmp
= msi_create_temp_file( db
))) return NULL
;
490 rec
= msi_get_binary_record( db
, name
);
493 r
= MSI_RecordStreamToFile( rec
, 2, tmp
);
494 if( r
== ERROR_SUCCESS
)
496 himage
= LoadImageW( 0, tmp
, type
, cx
, cy
, flags
);
498 msiobj_release( &rec
->hdr
);
506 static HICON
msi_load_icon( MSIDATABASE
*db
, LPCWSTR text
, UINT attributes
)
508 DWORD cx
= 0, cy
= 0, flags
;
510 flags
= LR_LOADFROMFILE
| LR_DEFAULTSIZE
;
511 if( attributes
& msidbControlAttributesFixedSize
)
513 flags
&= ~LR_DEFAULTSIZE
;
514 if( attributes
& msidbControlAttributesIconSize16
)
519 if( attributes
& msidbControlAttributesIconSize32
)
524 /* msidbControlAttributesIconSize48 handled by above logic */
526 return msi_load_image( db
, text
, IMAGE_ICON
, cx
, cy
, flags
);
529 static void msi_dialog_update_controls( msi_dialog
*dialog
, LPCWSTR property
)
531 msi_control
*control
;
533 LIST_FOR_EACH_ENTRY( control
, &dialog
->controls
, msi_control
, entry
)
535 if ( control
->property
&& !strcmpW( control
->property
, property
) && control
->update
)
536 control
->update( dialog
, control
);
540 static void msi_dialog_set_property( MSIPACKAGE
*package
, LPCWSTR property
, LPCWSTR value
)
542 UINT r
= msi_set_property( package
->db
, property
, value
, -1 );
543 if (r
== ERROR_SUCCESS
&& !strcmpW( property
, szSourceDir
))
544 msi_reset_folders( package
, TRUE
);
547 static MSIFEATURE
*msi_seltree_feature_from_item( HWND hwnd
, HTREEITEM hItem
)
551 /* get the feature from the item */
552 memset( &tvi
, 0, sizeof tvi
);
554 tvi
.mask
= TVIF_PARAM
| TVIF_HANDLE
;
555 SendMessageW( hwnd
, TVM_GETITEMW
, 0, (LPARAM
)&tvi
);
556 return (MSIFEATURE
*)tvi
.lParam
;
559 struct msi_selection_tree_info
567 static MSIFEATURE
*msi_seltree_get_selected_feature( msi_control
*control
)
569 struct msi_selection_tree_info
*info
= GetPropW( control
->hwnd
, szButtonData
);
570 return msi_seltree_feature_from_item( control
->hwnd
, info
->selected
);
573 static void dialog_handle_event( msi_dialog
*dialog
, const WCHAR
*control
,
574 const WCHAR
*attribute
, MSIRECORD
*rec
)
578 ctrl
= msi_dialog_find_control( dialog
, control
);
581 if( !strcmpW( attribute
, szText
) )
583 const WCHAR
*font_text
, *text
= NULL
;
584 WCHAR
*font
, *text_fmt
= NULL
;
586 font_text
= MSI_RecordGetString( rec
, 1 );
587 font
= msi_dialog_get_style( font_text
, &text
);
588 deformat_string( dialog
->package
, text
, &text_fmt
);
589 if (text_fmt
) text
= text_fmt
;
592 SetWindowTextW( ctrl
->hwnd
, text
);
595 msi_free( text_fmt
);
596 msi_dialog_check_messages( NULL
);
598 else if( !strcmpW( attribute
, szProgress
) )
600 DWORD func
, val1
, val2
, units
;
602 func
= MSI_RecordGetInteger( rec
, 1 );
603 val1
= MSI_RecordGetInteger( rec
, 2 );
604 val2
= MSI_RecordGetInteger( rec
, 3 );
606 TRACE("progress: func %u val1 %u val2 %u\n", func
, val1
, val2
);
612 SendMessageW( ctrl
->hwnd
, PBM_SETRANGE
, 0, MAKELPARAM(0,100) );
615 ctrl
->progress_max
= units
? units
: 100;
616 ctrl
->progress_current
= units
;
617 ctrl
->progress_backwards
= TRUE
;
618 SendMessageW( ctrl
->hwnd
, PBM_SETPOS
, 100, 0 );
622 ctrl
->progress_max
= units
? units
: 100;
623 ctrl
->progress_current
= 0;
624 ctrl
->progress_backwards
= FALSE
;
625 SendMessageW( ctrl
->hwnd
, PBM_SETPOS
, 0, 0 );
628 case 1: /* action data increment */
629 if (val2
) dialog
->package
->action_progress_increment
= val1
;
630 else dialog
->package
->action_progress_increment
= 0;
633 if (ctrl
->progress_backwards
)
635 if (units
>= ctrl
->progress_current
) ctrl
->progress_current
-= units
;
636 else ctrl
->progress_current
= 0;
640 if (ctrl
->progress_current
+ units
< ctrl
->progress_max
) ctrl
->progress_current
+= units
;
641 else ctrl
->progress_current
= ctrl
->progress_max
;
643 SendMessageW( ctrl
->hwnd
, PBM_SETPOS
, MulDiv(100, ctrl
->progress_current
, ctrl
->progress_max
), 0 );
646 ctrl
->progress_max
+= units
;
649 FIXME("Unknown progress message %u\n", func
);
653 else if ( !strcmpW( attribute
, szProperty
) )
655 MSIFEATURE
*feature
= msi_seltree_get_selected_feature( ctrl
);
656 if (feature
) msi_dialog_set_property( dialog
->package
, ctrl
->property
, feature
->Directory
);
658 else if ( !strcmpW( attribute
, szSelectionPath
) )
660 BOOL indirect
= ctrl
->attributes
& msidbControlAttributesIndirect
;
661 LPWSTR path
= msi_dialog_dup_property( dialog
, ctrl
->property
, indirect
);
663 SetWindowTextW( ctrl
->hwnd
, path
);
668 FIXME("Attribute %s not being set\n", debugstr_w(attribute
));
673 static void event_subscribe( msi_dialog
*dialog
, const WCHAR
*event
, const WCHAR
*control
, const WCHAR
*attribute
)
675 struct subscriber
*sub
;
677 TRACE("event %s control %s attribute %s\n", debugstr_w(event
), debugstr_w(control
), debugstr_w(attribute
));
679 LIST_FOR_EACH_ENTRY( sub
, &dialog
->package
->subscriptions
, struct subscriber
, entry
)
681 if (!strcmpiW( sub
->event
, event
) &&
682 !strcmpiW( sub
->control
, control
) &&
683 !strcmpiW( sub
->attribute
, attribute
))
685 TRACE("already subscribed\n");
689 if (!(sub
= msi_alloc( sizeof(*sub
) ))) return;
690 sub
->dialog
= dialog
;
691 sub
->event
= strdupW( event
);
692 sub
->control
= strdupW( control
);
693 sub
->attribute
= strdupW( attribute
);
694 list_add_tail( &dialog
->package
->subscriptions
, &sub
->entry
);
697 struct dialog_control
700 const WCHAR
*control
;
703 static UINT
map_event( MSIRECORD
*row
, void *param
)
705 struct dialog_control
*dc
= param
;
706 const WCHAR
*event
= MSI_RecordGetString( row
, 3 );
707 const WCHAR
*attribute
= MSI_RecordGetString( row
, 4 );
709 event_subscribe( dc
->dialog
, event
, dc
->control
, attribute
);
710 return ERROR_SUCCESS
;
713 static void dialog_map_events( msi_dialog
*dialog
, const WCHAR
*control
)
715 static const WCHAR queryW
[] =
716 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
717 '`','E','v','e','n','t','M','a','p','p','i','n','g','`',' ',
718 'W','H','E','R','E',' ','`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',' ',
719 'A','N','D',' ','`','C','o','n','t','r','o','l','_','`',' ','=',' ','\'','%','s','\'',0};
721 struct dialog_control dialog_control
=
727 if (!MSI_OpenQuery( dialog
->package
->db
, &view
, queryW
, dialog
->name
, control
))
729 MSI_IterateRecords( view
, NULL
, map_event
, &dialog_control
);
730 msiobj_release( &view
->hdr
);
734 /* everything except radio buttons */
735 static msi_control
*msi_dialog_add_control( msi_dialog
*dialog
,
736 MSIRECORD
*rec
, LPCWSTR szCls
, DWORD style
)
739 const WCHAR
*text
= NULL
, *name
, *control_type
;
742 name
= MSI_RecordGetString( rec
, 2 );
743 control_type
= MSI_RecordGetString( rec
, 3 );
744 attributes
= MSI_RecordGetInteger( rec
, 8 );
745 if (strcmpW( control_type
, szScrollableText
)) text
= MSI_RecordGetString( rec
, 10 );
747 TRACE("%s, %s, %08x, %s, %08x\n", debugstr_w(szCls
), debugstr_w(name
),
748 attributes
, debugstr_w(text
), style
);
750 if( attributes
& msidbControlAttributesVisible
)
752 if( ~attributes
& msidbControlAttributesEnabled
)
753 style
|= WS_DISABLED
;
754 if( attributes
& msidbControlAttributesSunken
)
755 exstyle
|= WS_EX_CLIENTEDGE
;
757 dialog_map_events( dialog
, name
);
759 return dialog_create_window( dialog
, rec
, exstyle
, szCls
, name
, text
, style
, dialog
->hwnd
);
770 * we don't erase our own background,
771 * so we have to make sure that the parent window redraws first
773 static void msi_text_on_settext( HWND hWnd
)
778 hParent
= GetParent( hWnd
);
779 GetWindowRect( hWnd
, &rc
);
780 MapWindowPoints( NULL
, hParent
, (LPPOINT
) &rc
, 2 );
781 InvalidateRect( hParent
, &rc
, TRUE
);
784 static LRESULT WINAPI
785 MSIText_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
787 struct msi_text_info
*info
;
790 TRACE("%p %04x %08lx %08lx\n", hWnd
, msg
, wParam
, lParam
);
792 info
= GetPropW(hWnd
, szButtonData
);
794 if( msg
== WM_CTLCOLORSTATIC
&&
795 ( info
->attributes
& msidbControlAttributesTransparent
) )
797 SetBkMode( (HDC
)wParam
, TRANSPARENT
);
798 return (LRESULT
) GetStockObject(NULL_BRUSH
);
801 r
= CallWindowProcW(info
->oldproc
, hWnd
, msg
, wParam
, lParam
);
803 SetTextColor( (HDC
)wParam
, info
->font
->color
);
808 msi_text_on_settext( hWnd
);
812 RemovePropW( hWnd
, szButtonData
);
819 static UINT
msi_dialog_text_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
821 msi_control
*control
;
822 struct msi_text_info
*info
;
823 LPCWSTR text
, ptr
, prop
, control_name
;
826 TRACE("%p %p\n", dialog
, rec
);
828 control
= msi_dialog_add_control( dialog
, rec
, szStatic
, SS_LEFT
| WS_GROUP
);
830 return ERROR_FUNCTION_FAILED
;
832 info
= msi_alloc( sizeof *info
);
834 return ERROR_SUCCESS
;
836 control_name
= MSI_RecordGetString( rec
, 2 );
837 control
->attributes
= MSI_RecordGetInteger( rec
, 8 );
838 prop
= MSI_RecordGetString( rec
, 9 );
839 control
->property
= msi_dialog_dup_property( dialog
, prop
, FALSE
);
841 text
= MSI_RecordGetString( rec
, 10 );
842 font_name
= msi_dialog_get_style( text
, &ptr
);
843 info
->font
= ( font_name
) ? msi_dialog_find_font( dialog
, font_name
) : NULL
;
844 msi_free( font_name
);
846 info
->attributes
= MSI_RecordGetInteger( rec
, 8 );
847 if( info
->attributes
& msidbControlAttributesTransparent
)
848 SetWindowLongPtrW( control
->hwnd
, GWL_EXSTYLE
, WS_EX_TRANSPARENT
);
850 info
->oldproc
= (WNDPROC
) SetWindowLongPtrW( control
->hwnd
, GWLP_WNDPROC
,
851 (LONG_PTR
)MSIText_WndProc
);
852 SetPropW( control
->hwnd
, szButtonData
, info
);
854 event_subscribe( dialog
, szSelectionPath
, control_name
, szSelectionPath
);
855 return ERROR_SUCCESS
;
858 /* strip any leading text style label from text field */
859 static WCHAR
*msi_get_binary_name( MSIPACKAGE
*package
, MSIRECORD
*rec
)
863 text
= msi_get_deformatted_field( package
, rec
, 10 );
868 while (*p
&& *p
!= '{') p
++;
869 if (!*p
++) return text
;
871 while (*p
&& *p
!= '}') p
++;
872 if (!*p
++) return text
;
879 static UINT
msi_dialog_set_property_event( msi_dialog
*dialog
, LPCWSTR event
, LPCWSTR arg
)
881 static const WCHAR szNullArg
[] = {'{','}',0};
882 LPWSTR p
, prop
, arg_fmt
= NULL
;
885 len
= strlenW( event
);
886 prop
= msi_alloc( len
* sizeof(WCHAR
) );
887 strcpyW( prop
, &event
[1] );
888 p
= strchrW( prop
, ']' );
889 if (p
&& (p
[1] == 0 || p
[1] == ' '))
892 if (strcmpW( szNullArg
, arg
))
893 deformat_string( dialog
->package
, arg
, &arg_fmt
);
894 msi_dialog_set_property( dialog
->package
, prop
, arg_fmt
);
895 msi_dialog_update_controls( dialog
, prop
);
898 else ERR("Badly formatted property string - what happens?\n");
900 return ERROR_SUCCESS
;
903 static UINT
msi_dialog_send_event( msi_dialog
*dialog
, LPCWSTR event
, LPCWSTR arg
)
905 LPWSTR event_fmt
= NULL
, arg_fmt
= NULL
;
907 TRACE("Sending control event %s %s\n", debugstr_w(event
), debugstr_w(arg
));
909 deformat_string( dialog
->package
, event
, &event_fmt
);
910 deformat_string( dialog
->package
, arg
, &arg_fmt
);
912 dialog
->event_handler( dialog
, event_fmt
, arg_fmt
);
914 msi_free( event_fmt
);
917 return ERROR_SUCCESS
;
920 static UINT
msi_dialog_control_event( MSIRECORD
*rec
, LPVOID param
)
922 msi_dialog
*dialog
= param
;
923 LPCWSTR condition
, event
, arg
;
926 condition
= MSI_RecordGetString( rec
, 5 );
927 r
= MSI_EvaluateConditionW( dialog
->package
, condition
);
928 if (r
== MSICONDITION_TRUE
|| r
== MSICONDITION_NONE
)
930 event
= MSI_RecordGetString( rec
, 3 );
931 arg
= MSI_RecordGetString( rec
, 4 );
933 msi_dialog_set_property_event( dialog
, event
, arg
);
935 msi_dialog_send_event( dialog
, event
, arg
);
937 return ERROR_SUCCESS
;
940 static UINT
msi_dialog_button_handler( msi_dialog
*dialog
, msi_control
*control
, WPARAM param
)
942 static const WCHAR query
[] = {
943 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
944 'C','o','n','t','r','o','l','E','v','e','n','t',' ','W','H','E','R','E',' ',
945 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',' ','A','N','D',' ',
946 '`','C','o','n','t','r','o','l','_','`',' ','=',' ','\'','%','s','\'',' ',
947 'O','R','D','E','R',' ','B','Y',' ','`','O','r','d','e','r','i','n','g','`',0};
951 if (HIWORD(param
) != BN_CLICKED
)
952 return ERROR_SUCCESS
;
954 r
= MSI_OpenQuery( dialog
->package
->db
, &view
, query
, dialog
->name
, control
->name
);
955 if (r
!= ERROR_SUCCESS
)
957 ERR("query failed\n");
958 return ERROR_SUCCESS
;
960 r
= MSI_IterateRecords( view
, 0, msi_dialog_control_event
, dialog
);
961 msiobj_release( &view
->hdr
);
965 static UINT
msi_dialog_button_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
967 msi_control
*control
;
968 UINT attributes
, style
;
970 TRACE("%p %p\n", dialog
, rec
);
973 attributes
= MSI_RecordGetInteger( rec
, 8 );
974 if( attributes
& msidbControlAttributesIcon
)
977 control
= msi_dialog_add_control( dialog
, rec
, szButton
, style
);
979 return ERROR_FUNCTION_FAILED
;
981 control
->handler
= msi_dialog_button_handler
;
983 if (attributes
& msidbControlAttributesIcon
)
986 LPWSTR name
= msi_get_binary_name( dialog
->package
, rec
);
987 control
->hIcon
= msi_load_icon( dialog
->package
->db
, name
, attributes
);
990 SendMessageW( control
->hwnd
, BM_SETIMAGE
, IMAGE_ICON
, (LPARAM
) control
->hIcon
);
993 ERR("Failed to load icon %s\n", debugstr_w(name
));
997 return ERROR_SUCCESS
;
1000 static LPWSTR
msi_get_checkbox_value( msi_dialog
*dialog
, LPCWSTR prop
)
1002 static const WCHAR query
[] = {
1003 'S','E','L','E','C','T',' ','*',' ',
1004 'F','R','O','M',' ','`','C','h','e','c','k','B','o','x','`',' ',
1005 'W','H','E','R','E',' ',
1006 '`','P','r','o','p','e','r','t','y','`',' ','=',' ',
1009 MSIRECORD
*rec
= NULL
;
1012 /* find if there is a value associated with the checkbox */
1013 rec
= MSI_QueryGetRecord( dialog
->package
->db
, query
, prop
);
1017 ret
= msi_get_deformatted_field( dialog
->package
, rec
, 2 );
1018 if( ret
&& !ret
[0] )
1023 msiobj_release( &rec
->hdr
);
1027 ret
= msi_dup_property( dialog
->package
->db
, prop
);
1028 if( ret
&& !ret
[0] )
1037 static UINT
msi_dialog_get_checkbox_state( msi_dialog
*dialog
, msi_control
*control
)
1039 WCHAR state
[2] = {0};
1042 msi_get_property( dialog
->package
->db
, control
->property
, state
, &sz
);
1043 return state
[0] ? 1 : 0;
1046 static void msi_dialog_set_checkbox_state( msi_dialog
*dialog
, msi_control
*control
, UINT state
)
1048 static const WCHAR szState
[] = {'1',0};
1051 /* if uncheck then the property is set to NULL */
1054 msi_dialog_set_property( dialog
->package
, control
->property
, NULL
);
1058 /* check for a custom state */
1059 if (control
->value
&& control
->value
[0])
1060 val
= control
->value
;
1064 msi_dialog_set_property( dialog
->package
, control
->property
, val
);
1067 static void msi_dialog_checkbox_sync_state( msi_dialog
*dialog
, msi_control
*control
)
1069 UINT state
= msi_dialog_get_checkbox_state( dialog
, control
);
1070 SendMessageW( control
->hwnd
, BM_SETCHECK
, state
? BST_CHECKED
: BST_UNCHECKED
, 0 );
1073 static UINT
msi_dialog_checkbox_handler( msi_dialog
*dialog
, msi_control
*control
, WPARAM param
)
1077 if (HIWORD(param
) != BN_CLICKED
)
1078 return ERROR_SUCCESS
;
1080 TRACE("clicked checkbox %s, set %s\n", debugstr_w(control
->name
), debugstr_w(control
->property
));
1082 state
= msi_dialog_get_checkbox_state( dialog
, control
);
1083 state
= state
? 0 : 1;
1084 msi_dialog_set_checkbox_state( dialog
, control
, state
);
1085 msi_dialog_checkbox_sync_state( dialog
, control
);
1087 return msi_dialog_button_handler( dialog
, control
, param
);
1090 static UINT
msi_dialog_checkbox_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1092 msi_control
*control
;
1095 TRACE("%p %p\n", dialog
, rec
);
1097 control
= msi_dialog_add_control( dialog
, rec
, szButton
, BS_CHECKBOX
| BS_MULTILINE
| WS_TABSTOP
);
1098 control
->handler
= msi_dialog_checkbox_handler
;
1099 control
->update
= msi_dialog_checkbox_sync_state
;
1100 prop
= MSI_RecordGetString( rec
, 9 );
1103 control
->property
= strdupW( prop
);
1104 control
->value
= msi_get_checkbox_value( dialog
, prop
);
1105 TRACE("control %s value %s\n", debugstr_w(control
->property
), debugstr_w(control
->value
));
1107 msi_dialog_checkbox_sync_state( dialog
, control
);
1108 return ERROR_SUCCESS
;
1111 static UINT
msi_dialog_line_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1115 DWORD style
, exstyle
= 0;
1116 DWORD x
, y
, width
, height
;
1117 msi_control
*control
;
1119 TRACE("%p %p\n", dialog
, rec
);
1121 style
= WS_CHILD
| SS_ETCHEDHORZ
| SS_SUNKEN
;
1123 name
= MSI_RecordGetString( rec
, 2 );
1124 attributes
= MSI_RecordGetInteger( rec
, 8 );
1126 if( attributes
& msidbControlAttributesVisible
)
1127 style
|= WS_VISIBLE
;
1128 if( ~attributes
& msidbControlAttributesEnabled
)
1129 style
|= WS_DISABLED
;
1130 if( attributes
& msidbControlAttributesSunken
)
1131 exstyle
|= WS_EX_CLIENTEDGE
;
1133 dialog_map_events( dialog
, name
);
1135 control
= msi_alloc( FIELD_OFFSET(msi_control
, name
[strlenW( name
) + 1] ));
1137 return ERROR_OUTOFMEMORY
;
1139 strcpyW( control
->name
, name
);
1140 list_add_head( &dialog
->controls
, &control
->entry
);
1141 control
->handler
= NULL
;
1142 control
->property
= NULL
;
1143 control
->value
= NULL
;
1144 control
->hBitmap
= NULL
;
1145 control
->hIcon
= NULL
;
1146 control
->hDll
= NULL
;
1147 control
->tabnext
= strdupW( MSI_RecordGetString( rec
, 11) );
1148 control
->type
= strdupW( MSI_RecordGetString( rec
, 3 ) );
1149 control
->progress_current
= 0;
1150 control
->progress_max
= 100;
1151 control
->progress_backwards
= FALSE
;
1153 x
= MSI_RecordGetInteger( rec
, 4 );
1154 y
= MSI_RecordGetInteger( rec
, 5 );
1155 width
= MSI_RecordGetInteger( rec
, 6 );
1157 x
= msi_dialog_scale_unit( dialog
, x
);
1158 y
= msi_dialog_scale_unit( dialog
, y
);
1159 width
= msi_dialog_scale_unit( dialog
, width
);
1160 height
= 2; /* line is exactly 2 units in height */
1162 control
->hwnd
= CreateWindowExW( exstyle
, szStatic
, NULL
, style
,
1163 x
, y
, width
, height
, dialog
->hwnd
, NULL
, NULL
, NULL
);
1165 TRACE("Dialog %s control %s hwnd %p\n",
1166 debugstr_w(dialog
->name
), debugstr_w(name
), control
->hwnd
);
1168 return ERROR_SUCCESS
;
1171 /******************** Scroll Text ********************************************/
1173 struct msi_scrolltext_info
1176 msi_control
*control
;
1180 static LRESULT WINAPI
1181 MSIScrollText_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1183 struct msi_scrolltext_info
*info
;
1186 TRACE("%p %04x %08lx %08lx\n", hWnd
, msg
, wParam
, lParam
);
1188 info
= GetPropW( hWnd
, szButtonData
);
1190 r
= CallWindowProcW( info
->oldproc
, hWnd
, msg
, wParam
, lParam
);
1195 return DLGC_WANTARROWS
;
1198 RemovePropW( hWnd
, szButtonData
);
1201 /* native MSI sets a wait cursor here */
1202 msi_dialog_button_handler( info
->dialog
, info
->control
, BN_CLICKED
);
1208 struct msi_streamin_info
1215 static DWORD CALLBACK
1216 msi_richedit_stream_in( DWORD_PTR arg
, LPBYTE buffer
, LONG count
, LONG
*pcb
)
1218 struct msi_streamin_info
*info
= (struct msi_streamin_info
*) arg
;
1220 if( (count
+ info
->offset
) > info
->length
)
1221 count
= info
->length
- info
->offset
;
1222 memcpy( buffer
, &info
->string
[ info
->offset
], count
);
1224 info
->offset
+= count
;
1226 TRACE("%d/%d\n", info
->offset
, info
->length
);
1231 static void msi_scrolltext_add_text( msi_control
*control
, LPCWSTR text
)
1233 struct msi_streamin_info info
;
1236 info
.string
= strdupWtoA( text
);
1238 info
.length
= lstrlenA( info
.string
) + 1;
1240 es
.dwCookie
= (DWORD_PTR
) &info
;
1242 es
.pfnCallback
= msi_richedit_stream_in
;
1244 SendMessageW( control
->hwnd
, EM_STREAMIN
, SF_RTF
, (LPARAM
) &es
);
1246 msi_free( info
.string
);
1249 static UINT
msi_dialog_scrolltext_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1251 static const WCHAR szRichEdit20W
[] = {'R','i','c','h','E','d','i','t','2','0','W',0};
1252 struct msi_scrolltext_info
*info
;
1253 msi_control
*control
;
1258 info
= msi_alloc( sizeof *info
);
1260 return ERROR_FUNCTION_FAILED
;
1262 hRichedit
= LoadLibraryA("riched20");
1264 style
= WS_BORDER
| ES_MULTILINE
| WS_VSCROLL
|
1265 ES_READONLY
| ES_AUTOVSCROLL
| WS_TABSTOP
;
1266 control
= msi_dialog_add_control( dialog
, rec
, szRichEdit20W
, style
);
1269 FreeLibrary( hRichedit
);
1271 return ERROR_FUNCTION_FAILED
;
1274 control
->hDll
= hRichedit
;
1276 info
->dialog
= dialog
;
1277 info
->control
= control
;
1279 /* subclass the static control */
1280 info
->oldproc
= (WNDPROC
) SetWindowLongPtrW( control
->hwnd
, GWLP_WNDPROC
,
1281 (LONG_PTR
)MSIScrollText_WndProc
);
1282 SetPropW( control
->hwnd
, szButtonData
, info
);
1284 /* add the text into the richedit */
1285 text
= MSI_RecordGetString( rec
, 10 );
1287 msi_scrolltext_add_text( control
, text
);
1289 return ERROR_SUCCESS
;
1292 static HBITMAP
msi_load_picture( MSIDATABASE
*db
, LPCWSTR name
,
1293 INT cx
, INT cy
, DWORD flags
)
1295 HBITMAP hOleBitmap
= 0, hBitmap
= 0, hOldSrcBitmap
, hOldDestBitmap
;
1296 MSIRECORD
*rec
= NULL
;
1297 IStream
*stm
= NULL
;
1298 IPicture
*pic
= NULL
;
1303 rec
= msi_get_binary_record( db
, name
);
1307 r
= MSI_RecordGetIStream( rec
, 2, &stm
);
1308 msiobj_release( &rec
->hdr
);
1309 if( r
!= ERROR_SUCCESS
)
1312 r
= OleLoadPicture( stm
, 0, TRUE
, &IID_IPicture
, (LPVOID
*) &pic
);
1313 IStream_Release( stm
);
1316 ERR("failed to load picture\n");
1320 r
= IPicture_get_Handle( pic
, (OLE_HANDLE
*) &hOleBitmap
);
1323 ERR("failed to get bitmap handle\n");
1327 /* make the bitmap the desired size */
1328 r
= GetObjectW( hOleBitmap
, sizeof bm
, &bm
);
1329 if (r
!= sizeof bm
)
1331 ERR("failed to get bitmap size\n");
1335 if (flags
& LR_DEFAULTSIZE
)
1341 srcdc
= CreateCompatibleDC( NULL
);
1342 hOldSrcBitmap
= SelectObject( srcdc
, hOleBitmap
);
1343 destdc
= CreateCompatibleDC( NULL
);
1344 hBitmap
= CreateCompatibleBitmap( srcdc
, cx
, cy
);
1345 hOldDestBitmap
= SelectObject( destdc
, hBitmap
);
1346 StretchBlt( destdc
, 0, 0, cx
, cy
,
1347 srcdc
, 0, 0, bm
.bmWidth
, bm
.bmHeight
, SRCCOPY
);
1348 SelectObject( srcdc
, hOldSrcBitmap
);
1349 SelectObject( destdc
, hOldDestBitmap
);
1355 IPicture_Release( pic
);
1359 static UINT
msi_dialog_bitmap_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1361 UINT cx
, cy
, flags
, style
, attributes
;
1362 msi_control
*control
;
1365 flags
= LR_LOADFROMFILE
;
1366 style
= SS_BITMAP
| SS_LEFT
| WS_GROUP
;
1368 attributes
= MSI_RecordGetInteger( rec
, 8 );
1369 if( attributes
& msidbControlAttributesFixedSize
)
1371 flags
|= LR_DEFAULTSIZE
;
1372 style
|= SS_CENTERIMAGE
;
1375 control
= msi_dialog_add_control( dialog
, rec
, szStatic
, style
);
1376 cx
= MSI_RecordGetInteger( rec
, 6 );
1377 cy
= MSI_RecordGetInteger( rec
, 7 );
1378 cx
= msi_dialog_scale_unit( dialog
, cx
);
1379 cy
= msi_dialog_scale_unit( dialog
, cy
);
1381 name
= msi_get_binary_name( dialog
->package
, rec
);
1382 control
->hBitmap
= msi_load_picture( dialog
->package
->db
, name
, cx
, cy
, flags
);
1383 if( control
->hBitmap
)
1384 SendMessageW( control
->hwnd
, STM_SETIMAGE
,
1385 IMAGE_BITMAP
, (LPARAM
) control
->hBitmap
);
1387 ERR("Failed to load bitmap %s\n", debugstr_w(name
));
1391 return ERROR_SUCCESS
;
1394 static UINT
msi_dialog_icon_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1396 msi_control
*control
;
1402 control
= msi_dialog_add_control( dialog
, rec
, szStatic
,
1403 SS_ICON
| SS_CENTERIMAGE
| WS_GROUP
);
1405 attributes
= MSI_RecordGetInteger( rec
, 8 );
1406 name
= msi_get_binary_name( dialog
->package
, rec
);
1407 control
->hIcon
= msi_load_icon( dialog
->package
->db
, name
, attributes
);
1408 if( control
->hIcon
)
1409 SendMessageW( control
->hwnd
, STM_SETICON
, (WPARAM
) control
->hIcon
, 0 );
1411 ERR("Failed to load bitmap %s\n", debugstr_w(name
));
1413 return ERROR_SUCCESS
;
1416 /******************** Combo Box ***************************************/
1418 struct msi_combobox_info
1428 static LRESULT WINAPI
MSIComboBox_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1430 struct msi_combobox_info
*info
;
1434 TRACE("%p %04x %08lx %08lx\n", hWnd
, msg
, wParam
, lParam
);
1436 info
= GetPropW( hWnd
, szButtonData
);
1440 r
= CallWindowProcW( info
->oldproc
, hWnd
, msg
, wParam
, lParam
);
1445 for (j
= 0; j
< info
->num_items
; j
++)
1446 msi_free( info
->items
[j
] );
1447 msi_free( info
->items
);
1449 RemovePropW( hWnd
, szButtonData
);
1456 static UINT
msi_combobox_add_item( MSIRECORD
*rec
, LPVOID param
)
1458 struct msi_combobox_info
*info
= param
;
1459 LPCWSTR value
, text
;
1462 value
= MSI_RecordGetString( rec
, 3 );
1463 text
= MSI_RecordGetString( rec
, 4 );
1465 info
->items
[info
->addpos_items
] = strdupW( value
);
1467 pos
= SendMessageW( info
->hwnd
, CB_ADDSTRING
, 0, (LPARAM
)text
);
1468 SendMessageW( info
->hwnd
, CB_SETITEMDATA
, pos
, (LPARAM
)info
->items
[info
->addpos_items
] );
1469 info
->addpos_items
++;
1471 return ERROR_SUCCESS
;
1474 static UINT
msi_combobox_add_items( struct msi_combobox_info
*info
, LPCWSTR property
)
1476 static const WCHAR query
[] = {
1477 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
1478 '`','C','o','m','b','o','B','o','x','`',' ','W','H','E','R','E',' ',
1479 '`','P','r','o','p','e','r','t','y','`',' ','=',' ','\'','%','s','\'',' ',
1480 'O','R','D','E','R',' ','B','Y',' ','`','O','r','d','e','r','`',0};
1485 r
= MSI_OpenQuery( info
->dialog
->package
->db
, &view
, query
, property
);
1486 if (r
!= ERROR_SUCCESS
)
1489 /* just get the number of records */
1491 r
= MSI_IterateRecords( view
, &count
, NULL
, NULL
);
1492 if (r
!= ERROR_SUCCESS
)
1494 msiobj_release( &view
->hdr
);
1497 info
->num_items
= count
;
1498 info
->items
= msi_alloc( sizeof(*info
->items
) * count
);
1500 r
= MSI_IterateRecords( view
, NULL
, msi_combobox_add_item
, info
);
1501 msiobj_release( &view
->hdr
);
1505 static UINT
msi_dialog_set_control_condition( MSIRECORD
*rec
, LPVOID param
)
1507 static const WCHAR szHide
[] = {'H','i','d','e',0};
1508 static const WCHAR szShow
[] = {'S','h','o','w',0};
1509 static const WCHAR szDisable
[] = {'D','i','s','a','b','l','e',0};
1510 static const WCHAR szEnable
[] = {'E','n','a','b','l','e',0};
1511 static const WCHAR szDefault
[] = {'D','e','f','a','u','l','t',0};
1512 msi_dialog
*dialog
= param
;
1513 msi_control
*control
;
1514 LPCWSTR name
, action
, condition
;
1517 name
= MSI_RecordGetString( rec
, 2 );
1518 action
= MSI_RecordGetString( rec
, 3 );
1519 condition
= MSI_RecordGetString( rec
, 4 );
1520 r
= MSI_EvaluateConditionW( dialog
->package
, condition
);
1521 control
= msi_dialog_find_control( dialog
, name
);
1522 if (r
== MSICONDITION_TRUE
&& control
)
1524 TRACE("%s control %s\n", debugstr_w(action
), debugstr_w(name
));
1526 /* FIXME: case sensitive? */
1527 if (!strcmpW( action
, szHide
))
1528 ShowWindow(control
->hwnd
, SW_HIDE
);
1529 else if (!strcmpW( action
, szShow
))
1530 ShowWindow(control
->hwnd
, SW_SHOW
);
1531 else if (!strcmpW( action
, szDisable
))
1532 EnableWindow(control
->hwnd
, FALSE
);
1533 else if (!strcmpW( action
, szEnable
))
1534 EnableWindow(control
->hwnd
, TRUE
);
1535 else if (!strcmpW( action
, szDefault
))
1536 SetFocus(control
->hwnd
);
1538 FIXME("Unhandled action %s\n", debugstr_w(action
));
1540 return ERROR_SUCCESS
;
1543 static UINT
msi_dialog_evaluate_control_conditions( msi_dialog
*dialog
)
1545 static const WCHAR query
[] = {
1546 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
1547 'C','o','n','t','r','o','l','C','o','n','d','i','t','i','o','n',' ',
1548 'W','H','E','R','E',' ','`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',0};
1551 MSIPACKAGE
*package
= dialog
->package
;
1553 TRACE("%p %s\n", dialog
, debugstr_w(dialog
->name
));
1555 /* query the Control table for all the elements of the control */
1556 r
= MSI_OpenQuery( package
->db
, &view
, query
, dialog
->name
);
1557 if (r
!= ERROR_SUCCESS
)
1558 return ERROR_SUCCESS
;
1560 r
= MSI_IterateRecords( view
, 0, msi_dialog_set_control_condition
, dialog
);
1561 msiobj_release( &view
->hdr
);
1565 static UINT
msi_dialog_combobox_handler( msi_dialog
*dialog
, msi_control
*control
, WPARAM param
)
1567 struct msi_combobox_info
*info
;
1571 if (HIWORD(param
) != CBN_SELCHANGE
&& HIWORD(param
) != CBN_EDITCHANGE
)
1572 return ERROR_SUCCESS
;
1574 info
= GetPropW( control
->hwnd
, szButtonData
);
1575 index
= SendMessageW( control
->hwnd
, CB_GETCURSEL
, 0, 0 );
1576 if (index
== CB_ERR
)
1577 value
= msi_get_window_text( control
->hwnd
);
1579 value
= (LPWSTR
) SendMessageW( control
->hwnd
, CB_GETITEMDATA
, index
, 0 );
1581 msi_dialog_set_property( info
->dialog
->package
, control
->property
, value
);
1582 msi_dialog_evaluate_control_conditions( info
->dialog
);
1584 if (index
== CB_ERR
)
1587 return ERROR_SUCCESS
;
1590 static void msi_dialog_combobox_update( msi_dialog
*dialog
, msi_control
*control
)
1592 struct msi_combobox_info
*info
;
1596 info
= GetPropW( control
->hwnd
, szButtonData
);
1598 value
= msi_dup_property( dialog
->package
->db
, control
->property
);
1601 SendMessageW( control
->hwnd
, CB_SETCURSEL
, -1, 0 );
1605 for (j
= 0; j
< info
->num_items
; j
++)
1607 tmp
= (LPWSTR
) SendMessageW( control
->hwnd
, CB_GETITEMDATA
, j
, 0 );
1608 if (!strcmpW( value
, tmp
))
1612 if (j
< info
->num_items
)
1614 SendMessageW( control
->hwnd
, CB_SETCURSEL
, j
, 0 );
1618 SendMessageW( control
->hwnd
, CB_SETCURSEL
, -1, 0 );
1619 SetWindowTextW( control
->hwnd
, value
);
1625 static UINT
msi_dialog_combo_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1627 struct msi_combobox_info
*info
;
1628 msi_control
*control
;
1629 DWORD attributes
, style
;
1632 info
= msi_alloc( sizeof *info
);
1634 return ERROR_FUNCTION_FAILED
;
1636 style
= CBS_AUTOHSCROLL
| WS_TABSTOP
| WS_GROUP
| WS_CHILD
;
1637 attributes
= MSI_RecordGetInteger( rec
, 8 );
1638 if ( ~attributes
& msidbControlAttributesSorted
)
1640 if ( attributes
& msidbControlAttributesComboList
)
1641 style
|= CBS_DROPDOWNLIST
;
1643 style
|= CBS_DROPDOWN
;
1645 control
= msi_dialog_add_control( dialog
, rec
, WC_COMBOBOXW
, style
);
1649 return ERROR_FUNCTION_FAILED
;
1652 control
->handler
= msi_dialog_combobox_handler
;
1653 control
->update
= msi_dialog_combobox_update
;
1655 prop
= MSI_RecordGetString( rec
, 9 );
1656 control
->property
= msi_dialog_dup_property( dialog
, prop
, FALSE
);
1659 info
->dialog
= dialog
;
1660 info
->hwnd
= control
->hwnd
;
1662 info
->addpos_items
= 0;
1663 info
->oldproc
= (WNDPROC
)SetWindowLongPtrW( control
->hwnd
, GWLP_WNDPROC
,
1664 (LONG_PTR
)MSIComboBox_WndProc
);
1665 SetPropW( control
->hwnd
, szButtonData
, info
);
1667 if (control
->property
)
1668 msi_combobox_add_items( info
, control
->property
);
1670 msi_dialog_combobox_update( dialog
, control
);
1672 return ERROR_SUCCESS
;
1675 static UINT
msi_dialog_edit_handler( msi_dialog
*dialog
, msi_control
*control
, WPARAM param
)
1679 if (HIWORD(param
) != EN_CHANGE
)
1680 return ERROR_SUCCESS
;
1682 TRACE("edit %s contents changed, set %s\n", debugstr_w(control
->name
), debugstr_w(control
->property
));
1684 buf
= msi_get_window_text( control
->hwnd
);
1685 msi_dialog_set_property( dialog
->package
, control
->property
, buf
);
1688 return ERROR_SUCCESS
;
1691 /* length of 2^32 + 1 */
1692 #define MAX_NUM_DIGITS 11
1694 static UINT
msi_dialog_edit_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1696 msi_control
*control
;
1698 LPWSTR val
, begin
, end
;
1699 WCHAR num
[MAX_NUM_DIGITS
];
1702 control
= msi_dialog_add_control( dialog
, rec
, szEdit
,
1703 WS_BORDER
| WS_TABSTOP
| ES_AUTOHSCROLL
);
1704 control
->handler
= msi_dialog_edit_handler
;
1706 text
= MSI_RecordGetString( rec
, 10 );
1709 begin
= strchrW( text
, '{' );
1710 end
= strchrW( text
, '}' );
1712 if ( begin
&& end
&& end
> begin
&&
1713 begin
[0] >= '0' && begin
[0] <= '9' &&
1714 end
- begin
< MAX_NUM_DIGITS
)
1716 lstrcpynW( num
, begin
+ 1, end
- begin
);
1717 limit
= atolW( num
);
1719 SendMessageW( control
->hwnd
, EM_SETLIMITTEXT
, limit
, 0 );
1723 prop
= MSI_RecordGetString( rec
, 9 );
1725 control
->property
= strdupW( prop
);
1727 val
= msi_dup_property( dialog
->package
->db
, control
->property
);
1728 SetWindowTextW( control
->hwnd
, val
);
1730 return ERROR_SUCCESS
;
1733 /******************** Masked Edit ********************************************/
1735 #define MASK_MAX_GROUPS 20
1737 struct msi_mask_group
1745 struct msi_maskedit_info
1753 struct msi_mask_group group
[MASK_MAX_GROUPS
];
1756 static BOOL
msi_mask_editable( WCHAR type
)
1771 static void msi_mask_control_change( struct msi_maskedit_info
*info
)
1776 val
= msi_alloc( (info
->num_chars
+1)*sizeof(WCHAR
) );
1777 for( i
=0, n
=0; i
<info
->num_groups
; i
++ )
1779 if (info
->group
[i
].len
== ~0u)
1781 UINT len
= SendMessageW( info
->group
[i
].hwnd
, WM_GETTEXTLENGTH
, 0, 0 );
1782 val
= msi_realloc( val
, (len
+ 1) * sizeof(WCHAR
) );
1783 GetWindowTextW( info
->group
[i
].hwnd
, val
, len
+ 1 );
1787 if (info
->group
[i
].len
+ n
> info
->num_chars
)
1789 ERR("can't fit control %d text into template\n",i
);
1792 if (!msi_mask_editable(info
->group
[i
].type
))
1794 for(r
=0; r
<info
->group
[i
].len
; r
++)
1795 val
[n
+r
] = info
->group
[i
].type
;
1800 r
= GetWindowTextW( info
->group
[i
].hwnd
, &val
[n
], info
->group
[i
].len
+1 );
1801 if( r
!= info
->group
[i
].len
)
1808 TRACE("%d/%d controls were good\n", i
, info
->num_groups
);
1810 if( i
== info
->num_groups
)
1812 TRACE("Set property %s to %s\n", debugstr_w(info
->prop
), debugstr_w(val
));
1813 msi_dialog_set_property( info
->dialog
->package
, info
->prop
, val
);
1814 msi_dialog_evaluate_control_conditions( info
->dialog
);
1819 /* now move to the next control if necessary */
1820 static VOID
msi_mask_next_control( struct msi_maskedit_info
*info
, HWND hWnd
)
1825 for( i
=0; i
<info
->num_groups
; i
++ )
1826 if( info
->group
[i
].hwnd
== hWnd
)
1829 /* don't move from the last control */
1830 if( i
>= (info
->num_groups
-1) )
1833 len
= SendMessageW( hWnd
, WM_GETTEXTLENGTH
, 0, 0 );
1834 if( len
< info
->group
[i
].len
)
1837 hWndNext
= GetNextDlgTabItem( GetParent( hWnd
), hWnd
, FALSE
);
1838 SetFocus( hWndNext
);
1841 static LRESULT WINAPI
1842 MSIMaskedEdit_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1844 struct msi_maskedit_info
*info
;
1847 TRACE("%p %04x %08lx %08lx\n", hWnd
, msg
, wParam
, lParam
);
1849 info
= GetPropW(hWnd
, szButtonData
);
1851 r
= CallWindowProcW(info
->oldproc
, hWnd
, msg
, wParam
, lParam
);
1856 if (HIWORD(wParam
) == EN_CHANGE
)
1858 msi_mask_control_change( info
);
1859 msi_mask_next_control( info
, (HWND
) lParam
);
1863 msi_free( info
->prop
);
1865 RemovePropW( hWnd
, szButtonData
);
1872 /* fish the various bits of the property out and put them in the control */
1874 msi_maskedit_set_text( struct msi_maskedit_info
*info
, LPCWSTR text
)
1880 for( i
= 0; i
< info
->num_groups
; i
++ )
1882 if( info
->group
[i
].len
< strlenW( p
) )
1884 LPWSTR chunk
= strdupW( p
);
1885 chunk
[ info
->group
[i
].len
] = 0;
1886 SetWindowTextW( info
->group
[i
].hwnd
, chunk
);
1891 SetWindowTextW( info
->group
[i
].hwnd
, p
);
1894 p
+= info
->group
[i
].len
;
1898 static struct msi_maskedit_info
* msi_dialog_parse_groups( LPCWSTR mask
)
1900 struct msi_maskedit_info
*info
;
1901 int i
= 0, n
= 0, total
= 0;
1904 TRACE("masked control, template %s\n", debugstr_w(mask
));
1909 info
= msi_alloc_zero( sizeof *info
);
1913 p
= strchrW(mask
, '<');
1919 for( i
=0; i
<MASK_MAX_GROUPS
; i
++ )
1921 /* stop at the end of the string */
1922 if( p
[0] == 0 || p
[0] == '>' )
1926 /* create a group for the empty mask */
1927 info
->group
[0].type
= '&';
1928 info
->group
[0].len
= ~0u;
1934 /* count the number of the same identifier */
1935 for( n
=0; p
[n
] == p
[0]; n
++ )
1937 info
->group
[i
].ofs
= total
;
1938 info
->group
[i
].type
= p
[0];
1942 total
++; /* an extra not part of the group */
1944 info
->group
[i
].len
= n
;
1949 TRACE("%d characters in %d groups\n", total
, i
);
1950 if( i
== MASK_MAX_GROUPS
)
1951 ERR("too many groups in PIDTemplate %s\n", debugstr_w(mask
));
1953 info
->num_chars
= total
;
1954 info
->num_groups
= i
;
1960 msi_maskedit_create_children( struct msi_maskedit_info
*info
, LPCWSTR font
)
1962 DWORD width
, height
, style
, wx
, ww
;
1967 style
= WS_CHILD
| WS_BORDER
| WS_VISIBLE
| WS_TABSTOP
| ES_AUTOHSCROLL
;
1969 GetClientRect( info
->hwnd
, &rect
);
1971 width
= rect
.right
- rect
.left
;
1972 height
= rect
.bottom
- rect
.top
;
1974 for( i
= 0; i
< info
->num_groups
; i
++ )
1976 if (!msi_mask_editable( info
->group
[i
].type
))
1978 if (info
->num_chars
)
1980 wx
= (info
->group
[i
].ofs
* width
) / info
->num_chars
;
1981 ww
= (info
->group
[i
].len
* width
) / info
->num_chars
;
1988 hwnd
= CreateWindowW( szEdit
, NULL
, style
, wx
, 0, ww
, height
,
1989 info
->hwnd
, NULL
, NULL
, NULL
);
1992 ERR("failed to create mask edit sub window\n");
1996 SendMessageW( hwnd
, EM_LIMITTEXT
, info
->group
[i
].len
, 0 );
1998 msi_dialog_set_font( info
->dialog
, hwnd
,
1999 font
?font
:info
->dialog
->default_font
);
2000 info
->group
[i
].hwnd
= hwnd
;
2005 * office 2003 uses "73931<````=````=````=````=`````>@@@@@"
2006 * delphi 7 uses "<????-??????-??????-????>" and "<???-???>"
2007 * filemaker pro 7 uses "<^^^^=^^^^=^^^^=^^^^=^^^^=^^^^=^^^^^>"
2009 static UINT
msi_dialog_maskedit_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
2011 LPWSTR font_mask
, val
= NULL
, font
;
2012 struct msi_maskedit_info
*info
= NULL
;
2013 UINT ret
= ERROR_SUCCESS
;
2014 msi_control
*control
;
2019 font_mask
= msi_get_deformatted_field( dialog
->package
, rec
, 10 );
2020 font
= msi_dialog_get_style( font_mask
, &mask
);
2023 WARN("mask template is empty\n");
2027 info
= msi_dialog_parse_groups( mask
);
2030 ERR("template %s is invalid\n", debugstr_w(mask
));
2034 info
->dialog
= dialog
;
2036 control
= msi_dialog_add_control( dialog
, rec
, szStatic
,
2037 SS_OWNERDRAW
| WS_GROUP
| WS_VISIBLE
);
2040 ERR("Failed to create maskedit container\n");
2041 ret
= ERROR_FUNCTION_FAILED
;
2044 SetWindowLongPtrW( control
->hwnd
, GWL_EXSTYLE
, WS_EX_CONTROLPARENT
);
2046 info
->hwnd
= control
->hwnd
;
2048 /* subclass the static control */
2049 info
->oldproc
= (WNDPROC
) SetWindowLongPtrW( info
->hwnd
, GWLP_WNDPROC
,
2050 (LONG_PTR
)MSIMaskedEdit_WndProc
);
2051 SetPropW( control
->hwnd
, szButtonData
, info
);
2053 prop
= MSI_RecordGetString( rec
, 9 );
2055 info
->prop
= strdupW( prop
);
2057 msi_maskedit_create_children( info
, font
);
2061 val
= msi_dup_property( dialog
->package
->db
, prop
);
2064 msi_maskedit_set_text( info
, val
);
2070 if( ret
!= ERROR_SUCCESS
)
2072 msi_free( font_mask
);
2077 /******************** Progress Bar *****************************************/
2079 static UINT
msi_dialog_progress_bar( msi_dialog
*dialog
, MSIRECORD
*rec
)
2081 msi_control
*control
;
2082 DWORD attributes
, style
;
2085 attributes
= MSI_RecordGetInteger( rec
, 8 );
2086 if( !(attributes
& msidbControlAttributesProgress95
) )
2087 style
|= PBS_SMOOTH
;
2089 control
= msi_dialog_add_control( dialog
, rec
, PROGRESS_CLASSW
, style
);
2091 return ERROR_FUNCTION_FAILED
;
2093 event_subscribe( dialog
, szSetProgress
, control
->name
, szProgress
);
2094 return ERROR_SUCCESS
;
2097 /******************** Path Edit ********************************************/
2099 struct msi_pathedit_info
2102 msi_control
*control
;
2106 static void msi_dialog_update_pathedit( msi_dialog
*dialog
, msi_control
*control
)
2111 if (!control
&& !(control
= msi_dialog_find_control_by_type( dialog
, szPathEdit
)))
2114 indirect
= control
->attributes
& msidbControlAttributesIndirect
;
2115 prop
= msi_dialog_dup_property( dialog
, control
->property
, indirect
);
2116 path
= msi_dialog_dup_property( dialog
, prop
, TRUE
);
2118 SetWindowTextW( control
->hwnd
, path
);
2119 SendMessageW( control
->hwnd
, EM_SETSEL
, 0, -1 );
2125 /* FIXME: test when this should fail */
2126 static BOOL
msi_dialog_verify_path( LPWSTR path
)
2131 if ( PathIsRelativeW( path
) )
2137 /* returns TRUE if the path is valid, FALSE otherwise */
2138 static BOOL
msi_dialog_onkillfocus( msi_dialog
*dialog
, msi_control
*control
)
2144 indirect
= control
->attributes
& msidbControlAttributesIndirect
;
2145 prop
= msi_dialog_dup_property( dialog
, control
->property
, indirect
);
2147 buf
= msi_get_window_text( control
->hwnd
);
2149 if ( !msi_dialog_verify_path( buf
) )
2151 /* FIXME: display an error message box */
2152 ERR("Invalid path %s\n", debugstr_w( buf
));
2154 SetFocus( control
->hwnd
);
2159 msi_dialog_set_property( dialog
->package
, prop
, buf
);
2162 msi_dialog_update_pathedit( dialog
, control
);
2164 TRACE("edit %s contents changed, set %s\n", debugstr_w(control
->name
),
2173 static LRESULT WINAPI
MSIPathEdit_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
2175 struct msi_pathedit_info
*info
= GetPropW(hWnd
, szButtonData
);
2178 TRACE("%p %04x %08lx %08lx\n", hWnd
, msg
, wParam
, lParam
);
2180 if ( msg
== WM_KILLFOCUS
)
2182 /* if the path is invalid, don't handle this message */
2183 if ( !msi_dialog_onkillfocus( info
->dialog
, info
->control
) )
2187 r
= CallWindowProcW(info
->oldproc
, hWnd
, msg
, wParam
, lParam
);
2189 if ( msg
== WM_NCDESTROY
)
2192 RemovePropW( hWnd
, szButtonData
);
2198 static UINT
msi_dialog_pathedit_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
2200 struct msi_pathedit_info
*info
;
2201 msi_control
*control
;
2204 info
= msi_alloc( sizeof *info
);
2206 return ERROR_FUNCTION_FAILED
;
2208 control
= msi_dialog_add_control( dialog
, rec
, szEdit
,
2209 WS_BORDER
| WS_TABSTOP
);
2210 control
->attributes
= MSI_RecordGetInteger( rec
, 8 );
2211 prop
= MSI_RecordGetString( rec
, 9 );
2212 control
->property
= msi_dialog_dup_property( dialog
, prop
, FALSE
);
2214 info
->dialog
= dialog
;
2215 info
->control
= control
;
2216 info
->oldproc
= (WNDPROC
) SetWindowLongPtrW( control
->hwnd
, GWLP_WNDPROC
,
2217 (LONG_PTR
)MSIPathEdit_WndProc
);
2218 SetPropW( control
->hwnd
, szButtonData
, info
);
2220 msi_dialog_update_pathedit( dialog
, control
);
2222 return ERROR_SUCCESS
;
2225 static UINT
msi_dialog_radiogroup_handler( msi_dialog
*dialog
, msi_control
*control
, WPARAM param
)
2227 if (HIWORD(param
) != BN_CLICKED
)
2228 return ERROR_SUCCESS
;
2230 TRACE("clicked radio button %s, set %s\n", debugstr_w(control
->name
), debugstr_w(control
->property
));
2232 msi_dialog_set_property( dialog
->package
, control
->property
, control
->name
);
2234 return msi_dialog_button_handler( dialog
, control
, param
);
2237 /* radio buttons are a bit different from normal controls */
2238 static UINT
msi_dialog_create_radiobutton( MSIRECORD
*rec
, LPVOID param
)
2240 radio_button_group_descr
*group
= param
;
2241 msi_dialog
*dialog
= group
->dialog
;
2242 msi_control
*control
;
2243 LPCWSTR prop
, text
, name
;
2244 DWORD style
= WS_CHILD
| WS_VISIBLE
| WS_TABSTOP
| BS_AUTORADIOBUTTON
| BS_MULTILINE
;
2246 name
= MSI_RecordGetString( rec
, 3 );
2247 text
= MSI_RecordGetString( rec
, 8 );
2249 control
= dialog_create_window( dialog
, rec
, 0, szButton
, name
, text
, style
,
2250 group
->parent
->hwnd
);
2252 return ERROR_FUNCTION_FAILED
;
2253 control
->handler
= msi_dialog_radiogroup_handler
;
2255 if (group
->propval
&& !strcmpW( control
->name
, group
->propval
))
2256 SendMessageW(control
->hwnd
, BM_SETCHECK
, BST_CHECKED
, 0);
2258 prop
= MSI_RecordGetString( rec
, 1 );
2260 control
->property
= strdupW( prop
);
2262 return ERROR_SUCCESS
;
2265 static BOOL CALLBACK
msi_radioground_child_enum( HWND hWnd
, LPARAM lParam
)
2267 EnableWindow( hWnd
, lParam
);
2271 static LRESULT WINAPI
MSIRadioGroup_WndProc( HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
2273 WNDPROC oldproc
= (WNDPROC
)GetPropW( hWnd
, szButtonData
);
2276 TRACE("hWnd %p msg %04x wParam 0x%08lx lParam 0x%08lx\n", hWnd
, msg
, wParam
, lParam
);
2278 if (msg
== WM_COMMAND
) /* Forward notifications to dialog */
2279 SendMessageW( GetParent( hWnd
), msg
, wParam
, lParam
);
2281 r
= CallWindowProcW( oldproc
, hWnd
, msg
, wParam
, lParam
);
2283 /* make sure the radio buttons show as disabled if the parent is disabled */
2284 if (msg
== WM_ENABLE
)
2285 EnumChildWindows( hWnd
, msi_radioground_child_enum
, wParam
);
2290 static UINT
msi_dialog_radiogroup_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
2292 static const WCHAR query
[] = {
2293 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2294 'R','a','d','i','o','B','u','t','t','o','n',' ','W','H','E','R','E',' ',
2295 '`','P','r','o','p','e','r','t','y','`',' ','=',' ','\'','%','s','\'',0};
2298 msi_control
*control
;
2300 radio_button_group_descr group
;
2301 MSIPACKAGE
*package
= dialog
->package
;
2303 DWORD attr
, style
= WS_GROUP
;
2305 prop
= MSI_RecordGetString( rec
, 9 );
2307 TRACE("%p %p %s\n", dialog
, rec
, debugstr_w( prop
));
2309 attr
= MSI_RecordGetInteger( rec
, 8 );
2310 if (attr
& msidbControlAttributesVisible
)
2311 style
|= WS_VISIBLE
;
2312 if (~attr
& msidbControlAttributesEnabled
)
2313 style
|= WS_DISABLED
;
2314 if (attr
& msidbControlAttributesHasBorder
)
2315 style
|= BS_GROUPBOX
;
2317 style
|= BS_OWNERDRAW
;
2319 /* Create parent group box to hold radio buttons */
2320 control
= msi_dialog_add_control( dialog
, rec
, szButton
, style
);
2322 return ERROR_FUNCTION_FAILED
;
2324 oldproc
= (WNDPROC
) SetWindowLongPtrW( control
->hwnd
, GWLP_WNDPROC
,
2325 (LONG_PTR
)MSIRadioGroup_WndProc
);
2326 SetPropW(control
->hwnd
, szButtonData
, oldproc
);
2327 SetWindowLongPtrW( control
->hwnd
, GWL_EXSTYLE
, WS_EX_CONTROLPARENT
);
2330 control
->property
= strdupW( prop
);
2332 /* query the Radio Button table for all control in this group */
2333 r
= MSI_OpenQuery( package
->db
, &view
, query
, prop
);
2334 if( r
!= ERROR_SUCCESS
)
2336 ERR("query failed for dialog %s radio group %s\n",
2337 debugstr_w(dialog
->name
), debugstr_w(prop
));
2338 return ERROR_INVALID_PARAMETER
;
2341 group
.dialog
= dialog
;
2342 group
.parent
= control
;
2343 group
.propval
= msi_dup_property( dialog
->package
->db
, control
->property
);
2345 r
= MSI_IterateRecords( view
, 0, msi_dialog_create_radiobutton
, &group
);
2346 msiobj_release( &view
->hdr
);
2347 msi_free( group
.propval
);
2352 msi_seltree_sync_item_state( HWND hwnd
, MSIFEATURE
*feature
, HTREEITEM hItem
)
2355 DWORD index
= feature
->ActionRequest
;
2357 TRACE("Feature %s -> %d %d %d\n", debugstr_w(feature
->Title
),
2358 feature
->Installed
, feature
->Action
, feature
->ActionRequest
);
2360 if (index
== INSTALLSTATE_UNKNOWN
)
2361 index
= INSTALLSTATE_ABSENT
;
2363 tvi
.mask
= TVIF_STATE
;
2365 tvi
.state
= INDEXTOSTATEIMAGEMASK( index
);
2366 tvi
.stateMask
= TVIS_STATEIMAGEMASK
;
2368 SendMessageW( hwnd
, TVM_SETITEMW
, 0, (LPARAM
) &tvi
);
2372 msi_seltree_popup_menu( HWND hwnd
, INT x
, INT y
)
2377 /* create a menu to display */
2378 hMenu
= CreatePopupMenu();
2380 /* FIXME: load strings from resources */
2381 AppendMenuA( hMenu
, MF_ENABLED
, INSTALLSTATE_LOCAL
, "Install feature locally");
2382 AppendMenuA( hMenu
, MF_ENABLED
, USER_INSTALLSTATE_ALL
, "Install entire feature");
2383 AppendMenuA( hMenu
, MF_ENABLED
, INSTALLSTATE_ADVERTISED
, "Install on demand");
2384 AppendMenuA( hMenu
, MF_ENABLED
, INSTALLSTATE_ABSENT
, "Don't install");
2385 r
= TrackPopupMenu( hMenu
, TPM_LEFTALIGN
| TPM_TOPALIGN
| TPM_RETURNCMD
,
2386 x
, y
, 0, hwnd
, NULL
);
2387 DestroyMenu( hMenu
);
2392 msi_seltree_update_feature_installstate( HWND hwnd
, HTREEITEM hItem
,
2393 MSIPACKAGE
*package
, MSIFEATURE
*feature
, INSTALLSTATE state
)
2395 feature
->ActionRequest
= state
;
2396 msi_seltree_sync_item_state( hwnd
, feature
, hItem
);
2397 ACTION_UpdateComponentStates( package
, feature
);
2401 msi_seltree_update_siblings_and_children_installstate( HWND hwnd
, HTREEITEM curr
,
2402 MSIPACKAGE
*package
, INSTALLSTATE state
)
2404 /* update all siblings */
2407 MSIFEATURE
*feature
;
2410 feature
= msi_seltree_feature_from_item( hwnd
, curr
);
2411 msi_seltree_update_feature_installstate( hwnd
, curr
, package
, feature
, state
);
2413 /* update this sibling's children */
2414 child
= (HTREEITEM
)SendMessageW( hwnd
, TVM_GETNEXTITEM
, (WPARAM
)TVGN_CHILD
, (LPARAM
)curr
);
2416 msi_seltree_update_siblings_and_children_installstate( hwnd
, child
,
2419 while ((curr
= (HTREEITEM
)SendMessageW( hwnd
, TVM_GETNEXTITEM
, (WPARAM
)TVGN_NEXT
, (LPARAM
)curr
)));
2423 msi_seltree_menu( HWND hwnd
, HTREEITEM hItem
)
2425 struct msi_selection_tree_info
*info
;
2426 MSIFEATURE
*feature
;
2427 MSIPACKAGE
*package
;
2435 info
= GetPropW(hwnd
, szButtonData
);
2436 package
= info
->dialog
->package
;
2438 feature
= msi_seltree_feature_from_item( hwnd
, hItem
);
2441 ERR("item %p feature was NULL\n", hItem
);
2445 /* get the item's rectangle to put the menu just below it */
2447 SendMessageW( hwnd
, TVM_GETITEMRECT
, 0, (LPARAM
) &u
.rc
);
2448 MapWindowPoints( hwnd
, NULL
, u
.pt
, 2 );
2450 r
= msi_seltree_popup_menu( hwnd
, u
.rc
.left
, u
.rc
.top
);
2454 case USER_INSTALLSTATE_ALL
:
2455 r
= INSTALLSTATE_LOCAL
;
2457 case INSTALLSTATE_ADVERTISED
:
2458 case INSTALLSTATE_ABSENT
:
2461 child
= (HTREEITEM
)SendMessageW( hwnd
, TVM_GETNEXTITEM
, (WPARAM
)TVGN_CHILD
, (LPARAM
)hItem
);
2463 msi_seltree_update_siblings_and_children_installstate( hwnd
, child
, package
, r
);
2466 case INSTALLSTATE_LOCAL
:
2467 msi_seltree_update_feature_installstate( hwnd
, hItem
, package
, feature
, r
);
2474 static LRESULT WINAPI
2475 MSISelectionTree_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
2477 struct msi_selection_tree_info
*info
;
2478 TVHITTESTINFO tvhti
;
2481 TRACE("%p %04x %08lx %08lx\n", hWnd
, msg
, wParam
, lParam
);
2483 info
= GetPropW(hWnd
, szButtonData
);
2487 case WM_LBUTTONDOWN
:
2488 tvhti
.pt
.x
= (short)LOWORD( lParam
);
2489 tvhti
.pt
.y
= (short)HIWORD( lParam
);
2492 CallWindowProcW(info
->oldproc
, hWnd
, TVM_HITTEST
, 0, (LPARAM
) &tvhti
);
2493 if (tvhti
.flags
& TVHT_ONITEMSTATEICON
)
2494 return msi_seltree_menu( hWnd
, tvhti
.hItem
);
2497 r
= CallWindowProcW(info
->oldproc
, hWnd
, msg
, wParam
, lParam
);
2503 RemovePropW( hWnd
, szButtonData
);
2510 msi_seltree_add_child_features( MSIPACKAGE
*package
, HWND hwnd
,
2511 LPCWSTR parent
, HTREEITEM hParent
)
2513 struct msi_selection_tree_info
*info
= GetPropW( hwnd
, szButtonData
);
2514 MSIFEATURE
*feature
;
2515 TVINSERTSTRUCTW tvis
;
2516 HTREEITEM hitem
, hfirst
= NULL
;
2518 LIST_FOR_EACH_ENTRY( feature
, &package
->features
, MSIFEATURE
, entry
)
2520 if ( parent
&& feature
->Feature_Parent
&& strcmpW( parent
, feature
->Feature_Parent
))
2522 else if ( parent
&& !feature
->Feature_Parent
)
2524 else if ( !parent
&& feature
->Feature_Parent
)
2527 if ( !feature
->Title
)
2530 if ( !feature
->Display
)
2533 memset( &tvis
, 0, sizeof tvis
);
2534 tvis
.hParent
= hParent
;
2535 tvis
.hInsertAfter
= TVI_LAST
;
2536 tvis
.u
.item
.mask
= TVIF_TEXT
| TVIF_PARAM
;
2537 tvis
.u
.item
.pszText
= feature
->Title
;
2538 tvis
.u
.item
.lParam
= (LPARAM
) feature
;
2540 hitem
= (HTREEITEM
) SendMessageW( hwnd
, TVM_INSERTITEMW
, 0, (LPARAM
) &tvis
);
2547 msi_seltree_sync_item_state( hwnd
, feature
, hitem
);
2548 msi_seltree_add_child_features( package
, hwnd
,
2549 feature
->Feature
, hitem
);
2551 /* the node is expanded if Display is odd */
2552 if ( feature
->Display
% 2 != 0 )
2553 SendMessageW( hwnd
, TVM_EXPAND
, TVE_EXPAND
, (LPARAM
) hitem
);
2556 /* select the first item */
2557 SendMessageW( hwnd
, TVM_SELECTITEM
, TVGN_CARET
| TVGN_DROPHILITE
, (LPARAM
) hfirst
);
2558 info
->selected
= hfirst
;
2561 static void msi_seltree_create_imagelist( HWND hwnd
)
2563 const int bm_width
= 32, bm_height
= 16, bm_count
= 3;
2564 const int bm_resource
= 0x1001;
2569 himl
= ImageList_Create( bm_width
, bm_height
, FALSE
, 4, 0 );
2572 ERR("failed to create image list\n");
2576 for (i
=0; i
<bm_count
; i
++)
2578 hbmp
= LoadBitmapW( msi_hInstance
, MAKEINTRESOURCEW(i
+bm_resource
) );
2581 ERR("failed to load bitmap %d\n", i
);
2586 * Add a dummy bitmap at offset zero because the treeview
2587 * can't use it as a state mask (zero means no user state).
2590 ImageList_Add( himl
, hbmp
, NULL
);
2592 ImageList_Add( himl
, hbmp
, NULL
);
2595 SendMessageW( hwnd
, TVM_SETIMAGELIST
, TVSIL_STATE
, (LPARAM
)himl
);
2598 static UINT
msi_dialog_seltree_handler( msi_dialog
*dialog
,
2599 msi_control
*control
, WPARAM param
)
2601 struct msi_selection_tree_info
*info
= GetPropW( control
->hwnd
, szButtonData
);
2602 LPNMTREEVIEWW tv
= (LPNMTREEVIEWW
)param
;
2603 MSIRECORD
*row
, *rec
;
2605 MSIFEATURE
*feature
;
2606 LPCWSTR dir
, title
= NULL
;
2607 UINT r
= ERROR_SUCCESS
;
2609 static const WCHAR select
[] = {
2610 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2611 '`','F','e','a','t','u','r','e','`',' ','W','H','E','R','E',' ',
2612 '`','T','i','t','l','e','`',' ','=',' ','\'','%','s','\'',0
2615 if (tv
->hdr
.code
!= TVN_SELCHANGINGW
)
2616 return ERROR_SUCCESS
;
2618 info
->selected
= tv
->itemNew
.hItem
;
2620 if (!(tv
->itemNew
.mask
& TVIF_TEXT
))
2622 feature
= msi_seltree_feature_from_item( control
->hwnd
, tv
->itemNew
.hItem
);
2624 title
= feature
->Title
;
2627 title
= tv
->itemNew
.pszText
;
2629 row
= MSI_QueryGetRecord( dialog
->package
->db
, select
, title
);
2631 return ERROR_FUNCTION_FAILED
;
2633 rec
= MSI_CreateRecord( 1 );
2635 MSI_RecordSetStringW( rec
, 1, MSI_RecordGetString( row
, 4 ) );
2636 msi_event_fire( dialog
->package
, szSelectionDescription
, rec
);
2638 dir
= MSI_RecordGetString( row
, 7 );
2641 folder
= msi_get_loaded_folder( dialog
->package
, dir
);
2644 r
= ERROR_FUNCTION_FAILED
;
2647 MSI_RecordSetStringW( rec
, 1, folder
->ResolvedTarget
);
2650 MSI_RecordSetStringW( rec
, 1, NULL
);
2652 msi_event_fire( dialog
->package
, szSelectionPath
, rec
);
2655 msiobj_release(&row
->hdr
);
2656 msiobj_release(&rec
->hdr
);
2661 static UINT
msi_dialog_selection_tree( msi_dialog
*dialog
, MSIRECORD
*rec
)
2663 msi_control
*control
;
2664 LPCWSTR prop
, control_name
;
2665 MSIPACKAGE
*package
= dialog
->package
;
2667 struct msi_selection_tree_info
*info
;
2669 info
= msi_alloc( sizeof *info
);
2671 return ERROR_FUNCTION_FAILED
;
2673 /* create the treeview control */
2674 style
= TVS_HASLINES
| TVS_HASBUTTONS
| TVS_LINESATROOT
;
2675 style
|= WS_GROUP
| WS_VSCROLL
| WS_TABSTOP
;
2676 control
= msi_dialog_add_control( dialog
, rec
, WC_TREEVIEWW
, style
);
2680 return ERROR_FUNCTION_FAILED
;
2683 control
->handler
= msi_dialog_seltree_handler
;
2684 control_name
= MSI_RecordGetString( rec
, 2 );
2685 control
->attributes
= MSI_RecordGetInteger( rec
, 8 );
2686 prop
= MSI_RecordGetString( rec
, 9 );
2687 control
->property
= msi_dialog_dup_property( dialog
, prop
, FALSE
);
2690 info
->dialog
= dialog
;
2691 info
->hwnd
= control
->hwnd
;
2692 info
->oldproc
= (WNDPROC
) SetWindowLongPtrW( control
->hwnd
, GWLP_WNDPROC
,
2693 (LONG_PTR
)MSISelectionTree_WndProc
);
2694 SetPropW( control
->hwnd
, szButtonData
, info
);
2696 event_subscribe( dialog
, szSelectionPath
, control_name
, szProperty
);
2699 msi_seltree_create_imagelist( control
->hwnd
);
2700 msi_seltree_add_child_features( package
, control
->hwnd
, NULL
, NULL
);
2702 return ERROR_SUCCESS
;
2705 /******************** Group Box ***************************************/
2707 static UINT
msi_dialog_group_box( msi_dialog
*dialog
, MSIRECORD
*rec
)
2709 msi_control
*control
;
2712 style
= BS_GROUPBOX
| WS_CHILD
| WS_GROUP
;
2713 control
= msi_dialog_add_control( dialog
, rec
, WC_BUTTONW
, style
);
2715 return ERROR_FUNCTION_FAILED
;
2717 return ERROR_SUCCESS
;
2720 /******************** List Box ***************************************/
2722 struct msi_listbox_info
2732 static LRESULT WINAPI
MSIListBox_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
2734 struct msi_listbox_info
*info
;
2738 TRACE("%p %04x %08lx %08lx\n", hWnd
, msg
, wParam
, lParam
);
2740 info
= GetPropW( hWnd
, szButtonData
);
2744 r
= CallWindowProcW( info
->oldproc
, hWnd
, msg
, wParam
, lParam
);
2749 for (j
= 0; j
< info
->num_items
; j
++)
2750 msi_free( info
->items
[j
] );
2751 msi_free( info
->items
);
2753 RemovePropW( hWnd
, szButtonData
);
2760 static UINT
msi_listbox_add_item( MSIRECORD
*rec
, LPVOID param
)
2762 struct msi_listbox_info
*info
= param
;
2763 LPCWSTR value
, text
;
2766 value
= MSI_RecordGetString( rec
, 3 );
2767 text
= MSI_RecordGetString( rec
, 4 );
2769 info
->items
[info
->addpos_items
] = strdupW( value
);
2771 pos
= SendMessageW( info
->hwnd
, LB_ADDSTRING
, 0, (LPARAM
)text
);
2772 SendMessageW( info
->hwnd
, LB_SETITEMDATA
, pos
, (LPARAM
)info
->items
[info
->addpos_items
] );
2773 info
->addpos_items
++;
2774 return ERROR_SUCCESS
;
2777 static UINT
msi_listbox_add_items( struct msi_listbox_info
*info
, LPCWSTR property
)
2779 static const WCHAR query
[] = {
2780 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2781 '`','L','i','s','t','B','o','x','`',' ','W','H','E','R','E',' ',
2782 '`','P','r','o','p','e','r','t','y','`',' ','=',' ','\'','%','s','\'',' ',
2783 'O','R','D','E','R',' ','B','Y',' ','`','O','r','d','e','r','`',0};
2788 r
= MSI_OpenQuery( info
->dialog
->package
->db
, &view
, query
, property
);
2789 if ( r
!= ERROR_SUCCESS
)
2792 /* just get the number of records */
2794 r
= MSI_IterateRecords( view
, &count
, NULL
, NULL
);
2795 if (r
!= ERROR_SUCCESS
)
2797 msiobj_release( &view
->hdr
);
2800 info
->num_items
= count
;
2801 info
->items
= msi_alloc( sizeof(*info
->items
) * count
);
2803 r
= MSI_IterateRecords( view
, NULL
, msi_listbox_add_item
, info
);
2804 msiobj_release( &view
->hdr
);
2808 static UINT
msi_dialog_listbox_handler( msi_dialog
*dialog
,
2809 msi_control
*control
, WPARAM param
)
2811 struct msi_listbox_info
*info
;
2815 if( HIWORD(param
) != LBN_SELCHANGE
)
2816 return ERROR_SUCCESS
;
2818 info
= GetPropW( control
->hwnd
, szButtonData
);
2819 index
= SendMessageW( control
->hwnd
, LB_GETCURSEL
, 0, 0 );
2820 value
= (LPCWSTR
) SendMessageW( control
->hwnd
, LB_GETITEMDATA
, index
, 0 );
2822 msi_dialog_set_property( info
->dialog
->package
, control
->property
, value
);
2823 msi_dialog_evaluate_control_conditions( info
->dialog
);
2825 return ERROR_SUCCESS
;
2828 static UINT
msi_dialog_list_box( msi_dialog
*dialog
, MSIRECORD
*rec
)
2830 struct msi_listbox_info
*info
;
2831 msi_control
*control
;
2832 DWORD attributes
, style
;
2835 info
= msi_alloc( sizeof *info
);
2837 return ERROR_FUNCTION_FAILED
;
2839 style
= WS_TABSTOP
| WS_GROUP
| WS_CHILD
| LBS_NOTIFY
| WS_VSCROLL
| WS_BORDER
;
2840 attributes
= MSI_RecordGetInteger( rec
, 8 );
2841 if (~attributes
& msidbControlAttributesSorted
)
2844 control
= msi_dialog_add_control( dialog
, rec
, WC_LISTBOXW
, style
);
2848 return ERROR_FUNCTION_FAILED
;
2851 control
->handler
= msi_dialog_listbox_handler
;
2853 prop
= MSI_RecordGetString( rec
, 9 );
2854 control
->property
= msi_dialog_dup_property( dialog
, prop
, FALSE
);
2857 info
->dialog
= dialog
;
2858 info
->hwnd
= control
->hwnd
;
2860 info
->addpos_items
= 0;
2861 info
->oldproc
= (WNDPROC
)SetWindowLongPtrW( control
->hwnd
, GWLP_WNDPROC
,
2862 (LONG_PTR
)MSIListBox_WndProc
);
2863 SetPropW( control
->hwnd
, szButtonData
, info
);
2865 if ( control
->property
)
2866 msi_listbox_add_items( info
, control
->property
);
2868 return ERROR_SUCCESS
;
2871 /******************** Directory Combo ***************************************/
2873 static void msi_dialog_update_directory_combo( msi_dialog
*dialog
, msi_control
*control
)
2878 if (!control
&& !(control
= msi_dialog_find_control_by_type( dialog
, szDirectoryCombo
)))
2881 indirect
= control
->attributes
& msidbControlAttributesIndirect
;
2882 prop
= msi_dialog_dup_property( dialog
, control
->property
, indirect
);
2883 path
= msi_dialog_dup_property( dialog
, prop
, TRUE
);
2885 PathStripPathW( path
);
2886 PathRemoveBackslashW( path
);
2888 SendMessageW( control
->hwnd
, CB_INSERTSTRING
, 0, (LPARAM
)path
);
2889 SendMessageW( control
->hwnd
, CB_SETCURSEL
, 0, 0 );
2895 static UINT
msi_dialog_directory_combo( msi_dialog
*dialog
, MSIRECORD
*rec
)
2897 msi_control
*control
;
2901 /* FIXME: use CBS_OWNERDRAWFIXED and add owner draw code */
2902 style
= CBS_DROPDOWNLIST
| CBS_HASSTRINGS
| WS_CHILD
|
2903 WS_GROUP
| WS_TABSTOP
| WS_VSCROLL
;
2904 control
= msi_dialog_add_control( dialog
, rec
, WC_COMBOBOXW
, style
);
2906 return ERROR_FUNCTION_FAILED
;
2908 control
->attributes
= MSI_RecordGetInteger( rec
, 8 );
2909 prop
= MSI_RecordGetString( rec
, 9 );
2910 control
->property
= msi_dialog_dup_property( dialog
, prop
, FALSE
);
2912 msi_dialog_update_directory_combo( dialog
, control
);
2914 return ERROR_SUCCESS
;
2917 /******************** Directory List ***************************************/
2919 static void msi_dialog_update_directory_list( msi_dialog
*dialog
, msi_control
*control
)
2921 WCHAR dir_spec
[MAX_PATH
];
2922 WIN32_FIND_DATAW wfd
;
2928 static const WCHAR asterisk
[] = {'*',0};
2930 if (!control
&& !(control
= msi_dialog_find_control_by_type( dialog
, szDirectoryList
)))
2933 /* clear the list-view */
2934 SendMessageW( control
->hwnd
, LVM_DELETEALLITEMS
, 0, 0 );
2936 indirect
= control
->attributes
& msidbControlAttributesIndirect
;
2937 prop
= msi_dialog_dup_property( dialog
, control
->property
, indirect
);
2938 path
= msi_dialog_dup_property( dialog
, prop
, TRUE
);
2940 lstrcpyW( dir_spec
, path
);
2941 lstrcatW( dir_spec
, asterisk
);
2943 file
= FindFirstFileW( dir_spec
, &wfd
);
2944 if ( file
== INVALID_HANDLE_VALUE
)
2949 if ( wfd
.dwFileAttributes
!= FILE_ATTRIBUTE_DIRECTORY
)
2952 if ( !strcmpW( wfd
.cFileName
, szDot
) || !strcmpW( wfd
.cFileName
, szDotDot
) )
2955 item
.mask
= LVIF_TEXT
;
2956 item
.cchTextMax
= MAX_PATH
;
2959 item
.pszText
= wfd
.cFileName
;
2961 SendMessageW( control
->hwnd
, LVM_INSERTITEMW
, 0, (LPARAM
)&item
);
2962 } while ( FindNextFileW( file
, &wfd
) );
2969 static UINT
msi_dialog_directorylist_up( msi_dialog
*dialog
)
2971 msi_control
*control
;
2972 LPWSTR prop
, path
, ptr
;
2975 control
= msi_dialog_find_control_by_type( dialog
, szDirectoryList
);
2976 indirect
= control
->attributes
& msidbControlAttributesIndirect
;
2977 prop
= msi_dialog_dup_property( dialog
, control
->property
, indirect
);
2978 path
= msi_dialog_dup_property( dialog
, prop
, TRUE
);
2980 /* strip off the last directory */
2981 ptr
= PathFindFileNameW( path
);
2982 if (ptr
!= path
) *(ptr
- 1) = '\0';
2983 PathAddBackslashW( path
);
2985 msi_dialog_set_property( dialog
->package
, prop
, path
);
2987 msi_dialog_update_directory_list( dialog
, NULL
);
2988 msi_dialog_update_directory_combo( dialog
, NULL
);
2989 msi_dialog_update_pathedit( dialog
, NULL
);
2994 return ERROR_SUCCESS
;
2997 static UINT
msi_dialog_dirlist_handler( msi_dialog
*dialog
,
2998 msi_control
*control
, WPARAM param
)
3000 LPNMHDR nmhdr
= (LPNMHDR
)param
;
3001 WCHAR new_path
[MAX_PATH
];
3002 WCHAR text
[MAX_PATH
];
3008 if (nmhdr
->code
!= LVN_ITEMACTIVATE
)
3009 return ERROR_SUCCESS
;
3011 index
= SendMessageW( control
->hwnd
, LVM_GETNEXTITEM
, -1, LVNI_SELECTED
);
3014 ERR("No list-view item selected!\n");
3015 return ERROR_FUNCTION_FAILED
;
3019 item
.pszText
= text
;
3020 item
.cchTextMax
= MAX_PATH
;
3021 SendMessageW( control
->hwnd
, LVM_GETITEMTEXTW
, index
, (LPARAM
)&item
);
3023 indirect
= control
->attributes
& msidbControlAttributesIndirect
;
3024 prop
= msi_dialog_dup_property( dialog
, control
->property
, indirect
);
3025 path
= msi_dialog_dup_property( dialog
, prop
, TRUE
);
3027 lstrcpyW( new_path
, path
);
3028 lstrcatW( new_path
, text
);
3029 lstrcatW( new_path
, szBackSlash
);
3031 msi_dialog_set_property( dialog
->package
, prop
, new_path
);
3033 msi_dialog_update_directory_list( dialog
, NULL
);
3034 msi_dialog_update_directory_combo( dialog
, NULL
);
3035 msi_dialog_update_pathedit( dialog
, NULL
);
3039 return ERROR_SUCCESS
;
3042 static UINT
msi_dialog_directory_list( msi_dialog
*dialog
, MSIRECORD
*rec
)
3044 msi_control
*control
;
3048 style
= LVS_LIST
| WS_VSCROLL
| LVS_SHAREIMAGELISTS
|
3049 LVS_AUTOARRANGE
| LVS_SINGLESEL
| WS_BORDER
|
3050 LVS_SORTASCENDING
| WS_CHILD
| WS_GROUP
| WS_TABSTOP
;
3051 control
= msi_dialog_add_control( dialog
, rec
, WC_LISTVIEWW
, style
);
3053 return ERROR_FUNCTION_FAILED
;
3055 control
->attributes
= MSI_RecordGetInteger( rec
, 8 );
3056 control
->handler
= msi_dialog_dirlist_handler
;
3057 prop
= MSI_RecordGetString( rec
, 9 );
3058 control
->property
= msi_dialog_dup_property( dialog
, prop
, FALSE
);
3060 /* double click to activate an item in the list */
3061 SendMessageW( control
->hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
,
3062 0, LVS_EX_TWOCLICKACTIVATE
);
3064 msi_dialog_update_directory_list( dialog
, control
);
3066 return ERROR_SUCCESS
;
3069 /******************** VolumeCost List ***************************************/
3071 static BOOL
str_is_number( LPCWSTR str
)
3075 for (i
= 0; i
< lstrlenW( str
); i
++)
3076 if (!isdigitW(str
[i
]))
3082 static const WCHAR column_keys
[][80] =
3084 {'V','o','l','u','m','e','C','o','s','t','V','o','l','u','m','e',0},
3085 {'V','o','l','u','m','e','C','o','s','t','S','i','z','e',0},
3086 {'V','o','l','u','m','e','C','o','s','t','A','v','a','i','l','a','b','l','e',0},
3087 {'V','o','l','u','m','e','C','o','s','t','R','e','q','u','i','r','e','d',0},
3088 {'V','o','l','u','m','e','C','o','s','t','D','i','f','f','e','r','e','n','c','e',0}
3091 static void msi_dialog_vcl_add_columns( msi_dialog
*dialog
, msi_control
*control
, MSIRECORD
*rec
)
3093 LPCWSTR text
= MSI_RecordGetString( rec
, 10 );
3094 LPCWSTR begin
= text
, end
;
3099 static const WCHAR negative
[] = {'-',0};
3103 while ((begin
= strchrW( begin
, '{' )) && count
< 5)
3105 if (!(end
= strchrW( begin
, '}' )))
3108 num
= msi_alloc( (end
-begin
+1)*sizeof(WCHAR
) );
3112 lstrcpynW( num
, begin
+ 1, end
- begin
);
3113 begin
+= end
- begin
+ 1;
3115 /* empty braces or '0' hides the column */
3116 if ( !num
[0] || !strcmpW( num
, szZero
) )
3123 /* the width must be a positive number
3124 * if a width is invalid, all remaining columns are hidden
3126 if ( !strncmpW( num
, negative
, 1 ) || !str_is_number( num
) ) {
3131 ZeroMemory( &lvc
, sizeof(lvc
) );
3132 lvc
.mask
= LVCF_TEXT
| LVCF_WIDTH
| LVCF_SUBITEM
;
3133 lvc
.cx
= atolW( num
);
3134 lvc
.pszText
= msi_dialog_get_uitext( dialog
, column_keys
[count
] );
3136 SendMessageW( control
->hwnd
, LVM_INSERTCOLUMNW
, count
++, (LPARAM
)&lvc
);
3137 msi_free( lvc
.pszText
);
3142 static LONGLONG
msi_vcl_get_cost( msi_dialog
*dialog
)
3144 MSIFEATURE
*feature
;
3146 LONGLONG total_cost
= 0;
3148 LIST_FOR_EACH_ENTRY( feature
, &dialog
->package
->features
, MSIFEATURE
, entry
)
3150 if (ERROR_SUCCESS
== (MSI_GetFeatureCost(dialog
->package
, feature
,
3151 MSICOSTTREE_SELFONLY
, INSTALLSTATE_LOCAL
, &each_cost
)))
3153 /* each_cost is in 512-byte units */
3154 total_cost
+= each_cost
* 512;
3156 if (ERROR_SUCCESS
== (MSI_GetFeatureCost(dialog
->package
, feature
,
3157 MSICOSTTREE_SELFONLY
, INSTALLSTATE_ABSENT
, &each_cost
)))
3159 /* each_cost is in 512-byte units */
3160 total_cost
-= each_cost
* 512;
3166 static void msi_dialog_vcl_add_drives( msi_dialog
*dialog
, msi_control
*control
)
3168 ULARGE_INTEGER total
, free
;
3169 LONGLONG difference
, cost
;
3170 WCHAR size_text
[MAX_PATH
];
3171 WCHAR cost_text
[MAX_PATH
];
3177 cost
= msi_vcl_get_cost(dialog
);
3178 StrFormatByteSizeW(cost
, cost_text
, MAX_PATH
);
3180 size
= GetLogicalDriveStringsW( 0, NULL
);
3181 if ( !size
) return;
3183 drives
= msi_alloc( (size
+ 1) * sizeof(WCHAR
) );
3184 if ( !drives
) return;
3186 GetLogicalDriveStringsW( size
, drives
);
3191 lvitem
.mask
= LVIF_TEXT
;
3193 lvitem
.iSubItem
= 0;
3194 lvitem
.pszText
= ptr
;
3195 lvitem
.cchTextMax
= lstrlenW(ptr
) + 1;
3196 SendMessageW( control
->hwnd
, LVM_INSERTITEMW
, 0, (LPARAM
)&lvitem
);
3198 GetDiskFreeSpaceExW(ptr
, &free
, &total
, NULL
);
3199 difference
= free
.QuadPart
- cost
;
3201 StrFormatByteSizeW(total
.QuadPart
, size_text
, MAX_PATH
);
3202 lvitem
.iSubItem
= 1;
3203 lvitem
.pszText
= size_text
;
3204 lvitem
.cchTextMax
= lstrlenW(size_text
) + 1;
3205 SendMessageW( control
->hwnd
, LVM_SETITEMW
, 0, (LPARAM
)&lvitem
);
3207 StrFormatByteSizeW(free
.QuadPart
, size_text
, MAX_PATH
);
3208 lvitem
.iSubItem
= 2;
3209 lvitem
.pszText
= size_text
;
3210 lvitem
.cchTextMax
= lstrlenW(size_text
) + 1;
3211 SendMessageW( control
->hwnd
, LVM_SETITEMW
, 0, (LPARAM
)&lvitem
);
3213 lvitem
.iSubItem
= 3;
3214 lvitem
.pszText
= cost_text
;
3215 lvitem
.cchTextMax
= lstrlenW(cost_text
) + 1;
3216 SendMessageW( control
->hwnd
, LVM_SETITEMW
, 0, (LPARAM
)&lvitem
);
3218 StrFormatByteSizeW(difference
, size_text
, MAX_PATH
);
3219 lvitem
.iSubItem
= 4;
3220 lvitem
.pszText
= size_text
;
3221 lvitem
.cchTextMax
= lstrlenW(size_text
) + 1;
3222 SendMessageW( control
->hwnd
, LVM_SETITEMW
, 0, (LPARAM
)&lvitem
);
3224 ptr
+= lstrlenW(ptr
) + 1;
3231 static UINT
msi_dialog_volumecost_list( msi_dialog
*dialog
, MSIRECORD
*rec
)
3233 msi_control
*control
;
3236 style
= LVS_REPORT
| WS_VSCROLL
| WS_HSCROLL
| LVS_SHAREIMAGELISTS
|
3237 LVS_AUTOARRANGE
| LVS_SINGLESEL
| WS_BORDER
|
3238 WS_CHILD
| WS_TABSTOP
| WS_GROUP
;
3239 control
= msi_dialog_add_control( dialog
, rec
, WC_LISTVIEWW
, style
);
3241 return ERROR_FUNCTION_FAILED
;
3243 msi_dialog_vcl_add_columns( dialog
, control
, rec
);
3244 msi_dialog_vcl_add_drives( dialog
, control
);
3246 return ERROR_SUCCESS
;
3249 /******************** VolumeSelect Combo ***************************************/
3251 static UINT
msi_dialog_volsel_handler( msi_dialog
*dialog
,
3252 msi_control
*control
, WPARAM param
)
3254 WCHAR text
[MAX_PATH
];
3259 if (HIWORD(param
) != CBN_SELCHANGE
)
3260 return ERROR_SUCCESS
;
3262 index
= SendMessageW( control
->hwnd
, CB_GETCURSEL
, 0, 0 );
3263 if ( index
== CB_ERR
)
3265 ERR("No ComboBox item selected!\n");
3266 return ERROR_FUNCTION_FAILED
;
3269 SendMessageW( control
->hwnd
, CB_GETLBTEXT
, index
, (LPARAM
)text
);
3271 indirect
= control
->attributes
& msidbControlAttributesIndirect
;
3272 prop
= msi_dialog_dup_property( dialog
, control
->property
, indirect
);
3274 msi_dialog_set_property( dialog
->package
, prop
, text
);
3277 return ERROR_SUCCESS
;
3280 static void msi_dialog_vsc_add_drives( msi_dialog
*dialog
, msi_control
*control
)
3285 size
= GetLogicalDriveStringsW( 0, NULL
);
3286 if ( !size
) return;
3288 drives
= msi_alloc( (size
+ 1) * sizeof(WCHAR
) );
3289 if ( !drives
) return;
3291 GetLogicalDriveStringsW( size
, drives
);
3296 SendMessageW( control
->hwnd
, CB_ADDSTRING
, 0, (LPARAM
)ptr
);
3297 ptr
+= lstrlenW(ptr
) + 1;
3303 static UINT
msi_dialog_volumeselect_combo( msi_dialog
*dialog
, MSIRECORD
*rec
)
3305 msi_control
*control
;
3309 /* FIXME: CBS_OWNERDRAWFIXED */
3310 style
= WS_CHILD
| WS_VISIBLE
| WS_GROUP
| WS_TABSTOP
|
3311 CBS_DROPDOWNLIST
| CBS_SORT
| CBS_HASSTRINGS
|
3312 WS_EX_LEFT
| WS_EX_LTRREADING
| WS_EX_RIGHTSCROLLBAR
;
3313 control
= msi_dialog_add_control( dialog
, rec
, WC_COMBOBOXW
, style
);
3315 return ERROR_FUNCTION_FAILED
;
3317 control
->attributes
= MSI_RecordGetInteger( rec
, 8 );
3318 control
->handler
= msi_dialog_volsel_handler
;
3319 prop
= MSI_RecordGetString( rec
, 9 );
3320 control
->property
= msi_dialog_dup_property( dialog
, prop
, FALSE
);
3322 msi_dialog_vsc_add_drives( dialog
, control
);
3324 return ERROR_SUCCESS
;
3327 static UINT
msi_dialog_hyperlink_handler( msi_dialog
*dialog
, msi_control
*control
, WPARAM param
)
3329 static const WCHAR hrefW
[] = {'h','r','e','f'};
3330 static const WCHAR openW
[] = {'o','p','e','n',0};
3331 int len
, len_href
= sizeof(hrefW
) / sizeof(hrefW
[0]);
3336 item
.mask
= LIF_ITEMINDEX
| LIF_URL
;
3340 SendMessageW( control
->hwnd
, LM_GETITEM
, 0, (LPARAM
)&item
);
3343 while (*p
&& *p
!= '<') p
++;
3344 if (!*p
++) return ERROR_SUCCESS
;
3345 if (toupperW( *p
++ ) != 'A' || !isspaceW( *p
++ )) return ERROR_SUCCESS
;
3346 while (*p
&& isspaceW( *p
)) p
++;
3349 if (len
> len_href
&& !memicmpW( p
, hrefW
, len_href
))
3352 while (*p
&& isspaceW( *p
)) p
++;
3353 if (!*p
|| *p
++ != '=') return ERROR_SUCCESS
;
3354 while (*p
&& isspaceW( *p
)) p
++;
3356 if (*p
== '\"' || *p
== '\'') quote
= *p
++;
3360 while (*q
&& *q
!= quote
) q
++;
3361 if (*q
!= quote
) return ERROR_SUCCESS
;
3365 while (*q
&& *q
!= '>' && !isspaceW( *q
)) q
++;
3366 if (!*q
) return ERROR_SUCCESS
;
3368 item
.szUrl
[q
- item
.szUrl
] = 0;
3369 ShellExecuteW( NULL
, openW
, p
, NULL
, NULL
, SW_SHOWNORMAL
);
3371 return ERROR_SUCCESS
;
3374 static UINT
msi_dialog_hyperlink( msi_dialog
*dialog
, MSIRECORD
*rec
)
3376 msi_control
*control
;
3377 DWORD style
= WS_CHILD
| WS_TABSTOP
| WS_GROUP
;
3378 const WCHAR
*text
= MSI_RecordGetString( rec
, 10 );
3379 int len
= strlenW( text
);
3382 control
= msi_dialog_add_control( dialog
, rec
, WC_LINK
, style
);
3384 return ERROR_FUNCTION_FAILED
;
3386 control
->attributes
= MSI_RecordGetInteger( rec
, 8 );
3387 control
->handler
= msi_dialog_hyperlink_handler
;
3389 item
.mask
= LIF_ITEMINDEX
| LIF_STATE
| LIF_URL
;
3391 item
.state
= LIS_ENABLED
;
3392 item
.stateMask
= LIS_ENABLED
;
3393 if (len
< L_MAX_URL_LENGTH
) strcpyW( item
.szUrl
, text
);
3394 else item
.szUrl
[0] = 0;
3396 SendMessageW( control
->hwnd
, LM_SETITEM
, 0, (LPARAM
)&item
);
3398 return ERROR_SUCCESS
;
3401 static const struct control_handler msi_dialog_handler
[] =
3403 { szText
, msi_dialog_text_control
},
3404 { szPushButton
, msi_dialog_button_control
},
3405 { szLine
, msi_dialog_line_control
},
3406 { szBitmap
, msi_dialog_bitmap_control
},
3407 { szCheckBox
, msi_dialog_checkbox_control
},
3408 { szScrollableText
, msi_dialog_scrolltext_control
},
3409 { szComboBox
, msi_dialog_combo_control
},
3410 { szEdit
, msi_dialog_edit_control
},
3411 { szMaskedEdit
, msi_dialog_maskedit_control
},
3412 { szPathEdit
, msi_dialog_pathedit_control
},
3413 { szProgressBar
, msi_dialog_progress_bar
},
3414 { szRadioButtonGroup
, msi_dialog_radiogroup_control
},
3415 { szIcon
, msi_dialog_icon_control
},
3416 { szSelectionTree
, msi_dialog_selection_tree
},
3417 { szGroupBox
, msi_dialog_group_box
},
3418 { szListBox
, msi_dialog_list_box
},
3419 { szDirectoryCombo
, msi_dialog_directory_combo
},
3420 { szDirectoryList
, msi_dialog_directory_list
},
3421 { szVolumeCostList
, msi_dialog_volumecost_list
},
3422 { szVolumeSelectCombo
, msi_dialog_volumeselect_combo
},
3423 { szHyperLink
, msi_dialog_hyperlink
}
3426 #define NUM_CONTROL_TYPES (sizeof msi_dialog_handler/sizeof msi_dialog_handler[0])
3428 static UINT
msi_dialog_create_controls( MSIRECORD
*rec
, LPVOID param
)
3430 msi_dialog
*dialog
= param
;
3431 LPCWSTR control_type
;
3434 /* find and call the function that can create this type of control */
3435 control_type
= MSI_RecordGetString( rec
, 3 );
3436 for( i
=0; i
<NUM_CONTROL_TYPES
; i
++ )
3437 if (!strcmpiW( msi_dialog_handler
[i
].control_type
, control_type
))
3439 if( i
!= NUM_CONTROL_TYPES
)
3440 msi_dialog_handler
[i
].func( dialog
, rec
);
3442 ERR("no handler for element type %s\n", debugstr_w(control_type
));
3444 return ERROR_SUCCESS
;
3447 static UINT
msi_dialog_fill_controls( msi_dialog
*dialog
)
3449 static const WCHAR query
[] = {
3450 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
3451 'C','o','n','t','r','o','l',' ','W','H','E','R','E',' ',
3452 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',0};
3455 MSIPACKAGE
*package
= dialog
->package
;
3457 TRACE("%p %s\n", dialog
, debugstr_w(dialog
->name
) );
3459 /* query the Control table for all the elements of the control */
3460 r
= MSI_OpenQuery( package
->db
, &view
, query
, dialog
->name
);
3461 if( r
!= ERROR_SUCCESS
)
3463 ERR("query failed for dialog %s\n", debugstr_w(dialog
->name
));
3464 return ERROR_INVALID_PARAMETER
;
3467 r
= MSI_IterateRecords( view
, 0, msi_dialog_create_controls
, dialog
);
3468 msiobj_release( &view
->hdr
);
3472 static UINT
msi_dialog_reset( msi_dialog
*dialog
)
3474 /* FIXME: should restore the original values of any properties we changed */
3475 return msi_dialog_evaluate_control_conditions( dialog
);
3478 /* figure out the height of 10 point MS Sans Serif */
3479 static INT
msi_dialog_get_sans_serif_height( HWND hwnd
)
3481 static const WCHAR szSansSerif
[] = {
3482 'M','S',' ','S','a','n','s',' ','S','e','r','i','f',0 };
3487 HFONT hFont
, hOldFont
;
3490 hdc
= GetDC( hwnd
);
3493 memset( &lf
, 0, sizeof lf
);
3494 lf
.lfHeight
= MulDiv(12, GetDeviceCaps(hdc
, LOGPIXELSY
), 72);
3495 strcpyW( lf
.lfFaceName
, szSansSerif
);
3496 hFont
= CreateFontIndirectW(&lf
);
3499 hOldFont
= SelectObject( hdc
, hFont
);
3500 r
= GetTextMetricsW( hdc
, &tm
);
3502 height
= tm
.tmHeight
;
3503 SelectObject( hdc
, hOldFont
);
3504 DeleteObject( hFont
);
3506 ReleaseDC( hwnd
, hdc
);
3511 /* fetch the associated record from the Dialog table */
3512 static MSIRECORD
*msi_get_dialog_record( msi_dialog
*dialog
)
3514 static const WCHAR query
[] = {
3515 'S','E','L','E','C','T',' ','*',' ',
3516 'F','R','O','M',' ','D','i','a','l','o','g',' ',
3517 'W','H','E','R','E',' ',
3518 '`','D','i','a','l','o','g','`',' ','=',' ','\'','%','s','\'',0};
3519 MSIPACKAGE
*package
= dialog
->package
;
3520 MSIRECORD
*rec
= NULL
;
3522 TRACE("%p %s\n", dialog
, debugstr_w(dialog
->name
) );
3524 rec
= MSI_QueryGetRecord( package
->db
, query
, dialog
->name
);
3526 WARN("query failed for dialog %s\n", debugstr_w(dialog
->name
));
3531 static void msi_dialog_adjust_dialog_pos( msi_dialog
*dialog
, MSIRECORD
*rec
, LPRECT pos
)
3533 static const WCHAR szScreenX
[] = {'S','c','r','e','e','n','X',0};
3534 static const WCHAR szScreenY
[] = {'S','c','r','e','e','n','Y',0};
3541 center
.x
= MSI_RecordGetInteger( rec
, 2 );
3542 center
.y
= MSI_RecordGetInteger( rec
, 3 );
3544 sz
.cx
= MSI_RecordGetInteger( rec
, 4 );
3545 sz
.cy
= MSI_RecordGetInteger( rec
, 5 );
3547 sz
.cx
= msi_dialog_scale_unit( dialog
, sz
.cx
);
3548 sz
.cy
= msi_dialog_scale_unit( dialog
, sz
.cy
);
3550 xres
= msi_get_property_int( dialog
->package
->db
, szScreenX
, 0 );
3551 yres
= msi_get_property_int( dialog
->package
->db
, szScreenY
, 0 );
3553 center
.x
= MulDiv( center
.x
, xres
, 100 );
3554 center
.y
= MulDiv( center
.y
, yres
, 100 );
3556 /* turn the client pos into the window rectangle */
3557 if (dialog
->package
->center_x
&& dialog
->package
->center_y
)
3559 pos
->left
= dialog
->package
->center_x
- sz
.cx
/ 2.0;
3560 pos
->right
= pos
->left
+ sz
.cx
;
3561 pos
->top
= dialog
->package
->center_y
- sz
.cy
/ 2.0;
3562 pos
->bottom
= pos
->top
+ sz
.cy
;
3566 pos
->left
= center
.x
- sz
.cx
/2;
3567 pos
->right
= pos
->left
+ sz
.cx
;
3568 pos
->top
= center
.y
- sz
.cy
/2;
3569 pos
->bottom
= pos
->top
+ sz
.cy
;
3571 /* save the center */
3572 dialog
->package
->center_x
= center
.x
;
3573 dialog
->package
->center_y
= center
.y
;
3576 dialog
->size
.cx
= sz
.cx
;
3577 dialog
->size
.cy
= sz
.cy
;
3579 TRACE("%u %u %u %u\n", pos
->left
, pos
->top
, pos
->right
, pos
->bottom
);
3581 style
= GetWindowLongPtrW( dialog
->hwnd
, GWL_STYLE
);
3582 AdjustWindowRect( pos
, style
, FALSE
);
3585 static void msi_dialog_set_tab_order( msi_dialog
*dialog
, LPCWSTR first
)
3587 struct list tab_chain
;
3588 msi_control
*control
;
3589 HWND prev
= HWND_TOP
;
3591 list_init( &tab_chain
);
3592 if (!(control
= msi_dialog_find_control( dialog
, first
))) return;
3594 dialog
->hWndFocus
= control
->hwnd
;
3597 list_remove( &control
->entry
);
3598 list_add_tail( &tab_chain
, &control
->entry
);
3599 if (!control
->tabnext
) break;
3600 control
= msi_dialog_find_control( dialog
, control
->tabnext
);
3603 LIST_FOR_EACH_ENTRY( control
, &tab_chain
, msi_control
, entry
)
3605 SetWindowPos( control
->hwnd
, prev
, 0, 0, 0, 0,
3606 SWP_NOMOVE
| SWP_NOOWNERZORDER
| SWP_NOREDRAW
|
3607 SWP_NOREPOSITION
| SWP_NOSENDCHANGING
| SWP_NOSIZE
);
3608 prev
= control
->hwnd
;
3611 /* put them back on the main list */
3612 list_move_head( &dialog
->controls
, &tab_chain
);
3615 static LRESULT
msi_dialog_oncreate( HWND hwnd
, LPCREATESTRUCTW cs
)
3617 static const WCHAR df
[] = {
3618 'D','e','f','a','u','l','t','U','I','F','o','n','t',0 };
3619 static const WCHAR dfv
[] = {
3620 'M','S',' ','S','h','e','l','l',' ','D','l','g',0 };
3621 msi_dialog
*dialog
= cs
->lpCreateParams
;
3622 MSIRECORD
*rec
= NULL
;
3623 LPWSTR title
= NULL
;
3626 TRACE("%p %p\n", dialog
, dialog
->package
);
3628 dialog
->hwnd
= hwnd
;
3629 SetWindowLongPtrW( hwnd
, GWLP_USERDATA
, (LONG_PTR
) dialog
);
3631 rec
= msi_get_dialog_record( dialog
);
3634 TRACE("No record found for dialog %s\n", debugstr_w(dialog
->name
));
3638 dialog
->scale
= msi_dialog_get_sans_serif_height(dialog
->hwnd
);
3640 msi_dialog_adjust_dialog_pos( dialog
, rec
, &pos
);
3642 dialog
->attributes
= MSI_RecordGetInteger( rec
, 6 );
3644 dialog
->default_font
= msi_dup_property( dialog
->package
->db
, df
);
3645 if (!dialog
->default_font
)
3647 dialog
->default_font
= strdupW(dfv
);
3648 if (!dialog
->default_font
)
3650 msiobj_release( &rec
->hdr
);
3655 title
= msi_get_deformatted_field( dialog
->package
, rec
, 7 );
3656 SetWindowTextW( hwnd
, title
);
3659 SetWindowPos( hwnd
, 0, pos
.left
, pos
.top
,
3660 pos
.right
- pos
.left
, pos
.bottom
- pos
.top
,
3661 SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_NOREDRAW
);
3663 msi_dialog_build_font_list( dialog
);
3664 msi_dialog_fill_controls( dialog
);
3665 msi_dialog_evaluate_control_conditions( dialog
);
3666 msi_dialog_set_tab_order( dialog
, MSI_RecordGetString( rec
, 8 ) );
3667 msiobj_release( &rec
->hdr
);
3672 static LRESULT
msi_dialog_oncommand( msi_dialog
*dialog
, WPARAM param
, HWND hwnd
)
3674 msi_control
*control
= NULL
;
3676 TRACE("%p %p %08lx\n", dialog
, hwnd
, param
);
3681 control
= msi_dialog_find_control( dialog
, dialog
->control_default
);
3683 case 2: /* escape */
3684 control
= msi_dialog_find_control( dialog
, dialog
->control_cancel
);
3687 control
= msi_dialog_find_control_by_hwnd( dialog
, hwnd
);
3692 if( control
->handler
)
3694 control
->handler( dialog
, control
, param
);
3695 msi_dialog_evaluate_control_conditions( dialog
);
3702 static LRESULT
msi_dialog_onnotify( msi_dialog
*dialog
, LPARAM param
)
3704 LPNMHDR nmhdr
= (LPNMHDR
) param
;
3705 msi_control
*control
= msi_dialog_find_control_by_hwnd( dialog
, nmhdr
->hwndFrom
);
3707 TRACE("%p %p\n", dialog
, nmhdr
->hwndFrom
);
3709 if ( control
&& control
->handler
)
3710 control
->handler( dialog
, control
, param
);
3715 static void dialog_setfocus( msi_dialog
*dialog
)
3717 HWND hwnd
= dialog
->hWndFocus
;
3719 hwnd
= GetNextDlgTabItem( dialog
->hwnd
, hwnd
, TRUE
);
3720 hwnd
= GetNextDlgTabItem( dialog
->hwnd
, hwnd
, FALSE
);
3722 dialog
->hWndFocus
= hwnd
;
3725 static LRESULT WINAPI
MSIDialog_WndProc( HWND hwnd
, UINT msg
,
3726 WPARAM wParam
, LPARAM lParam
)
3728 msi_dialog
*dialog
= (LPVOID
) GetWindowLongPtrW( hwnd
, GWLP_USERDATA
);
3730 TRACE("0x%04x\n", msg
);
3735 dialog
->package
->center_x
= LOWORD(lParam
) + dialog
->size
.cx
/ 2.0;
3736 dialog
->package
->center_y
= HIWORD(lParam
) + dialog
->size
.cy
/ 2.0;
3740 return msi_dialog_oncreate( hwnd
, (LPCREATESTRUCTW
)lParam
);
3743 return msi_dialog_oncommand( dialog
, wParam
, (HWND
)lParam
);
3746 if( LOWORD(wParam
) == WA_INACTIVE
)
3747 dialog
->hWndFocus
= GetFocus();
3749 dialog_setfocus( dialog
);
3753 dialog_setfocus( dialog
);
3756 /* bounce back to our subclassed static control */
3757 case WM_CTLCOLORSTATIC
:
3758 return SendMessageW( (HWND
) lParam
, WM_CTLCOLORSTATIC
, wParam
, lParam
);
3761 dialog
->hwnd
= NULL
;
3764 return msi_dialog_onnotify( dialog
, lParam
);
3766 return DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
3769 static void process_pending_messages( HWND hdlg
)
3773 while (PeekMessageW( &msg
, 0, 0, 0, PM_REMOVE
))
3775 if (hdlg
&& IsDialogMessageW( hdlg
, &msg
)) continue;
3776 TranslateMessage( &msg
);
3777 DispatchMessageW( &msg
);
3781 static UINT
dialog_run_message_loop( msi_dialog
*dialog
)
3786 if( uiThreadId
!= GetCurrentThreadId() )
3787 return SendMessageW( hMsiHiddenWindow
, WM_MSI_DIALOG_CREATE
, 0, (LPARAM
) dialog
);
3789 /* create the dialog window, don't show it yet */
3790 style
= WS_OVERLAPPED
;
3791 if( dialog
->attributes
& msidbDialogAttributesVisible
)
3792 style
|= WS_VISIBLE
;
3794 hwnd
= CreateWindowW( szMsiDialogClass
, dialog
->name
, style
,
3795 CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
,
3796 NULL
, NULL
, NULL
, dialog
);
3799 ERR("Failed to create dialog %s\n", debugstr_w( dialog
->name
));
3800 return ERROR_FUNCTION_FAILED
;
3803 ShowWindow( hwnd
, SW_SHOW
);
3804 /* UpdateWindow( hwnd ); - and causes the transparent static controls not to paint */
3806 if( dialog
->attributes
& msidbDialogAttributesModal
)
3808 while( !dialog
->finished
)
3810 MsgWaitForMultipleObjects( 0, NULL
, 0, INFINITE
, QS_ALLINPUT
);
3811 process_pending_messages( dialog
->hwnd
);
3815 return ERROR_IO_PENDING
;
3817 return ERROR_SUCCESS
;
3820 static LRESULT WINAPI
MSIHiddenWindowProc( HWND hwnd
, UINT msg
,
3821 WPARAM wParam
, LPARAM lParam
)
3823 msi_dialog
*dialog
= (msi_dialog
*) lParam
;
3825 TRACE("%d %p\n", msg
, dialog
);
3829 case WM_MSI_DIALOG_CREATE
:
3830 return dialog_run_message_loop( dialog
);
3831 case WM_MSI_DIALOG_DESTROY
:
3832 msi_dialog_destroy( dialog
);
3835 return DefWindowProcW( hwnd
, msg
, wParam
, lParam
);
3838 static BOOL
dialog_register_class( void )
3842 ZeroMemory( &cls
, sizeof cls
);
3843 cls
.lpfnWndProc
= MSIDialog_WndProc
;
3844 cls
.hInstance
= NULL
;
3845 cls
.hIcon
= LoadIconW(0, (LPWSTR
)IDI_APPLICATION
);
3846 cls
.hCursor
= LoadCursorW(0, (LPWSTR
)IDC_ARROW
);
3847 cls
.hbrBackground
= (HBRUSH
)(COLOR_3DFACE
+ 1);
3848 cls
.lpszMenuName
= NULL
;
3849 cls
.lpszClassName
= szMsiDialogClass
;
3851 if( !RegisterClassW( &cls
) )
3854 cls
.lpfnWndProc
= MSIHiddenWindowProc
;
3855 cls
.lpszClassName
= szMsiHiddenWindow
;
3857 if( !RegisterClassW( &cls
) )
3860 uiThreadId
= GetCurrentThreadId();
3862 hMsiHiddenWindow
= CreateWindowW( szMsiHiddenWindow
, NULL
, WS_OVERLAPPED
,
3863 0, 0, 100, 100, NULL
, NULL
, NULL
, NULL
);
3864 if( !hMsiHiddenWindow
)
3870 static msi_dialog
*dialog_create( MSIPACKAGE
*package
, const WCHAR
*name
, msi_dialog
*parent
,
3871 control_event_handler event_handler
)
3873 MSIRECORD
*rec
= NULL
;
3876 TRACE("%s\n", debugstr_w(name
));
3878 if (!hMsiHiddenWindow
) dialog_register_class();
3880 /* allocate the structure for the dialog to use */
3881 dialog
= msi_alloc_zero( FIELD_OFFSET( msi_dialog
, name
[strlenW( name
) + 1] ));
3884 strcpyW( dialog
->name
, name
);
3885 dialog
->parent
= parent
;
3886 msiobj_addref( &package
->hdr
);
3887 dialog
->package
= package
;
3888 dialog
->event_handler
= event_handler
;
3889 dialog
->finished
= 0;
3890 list_init( &dialog
->controls
);
3891 list_init( &dialog
->fonts
);
3893 /* verify that the dialog exists */
3894 rec
= msi_get_dialog_record( dialog
);
3897 msiobj_release( &package
->hdr
);
3901 dialog
->attributes
= MSI_RecordGetInteger( rec
, 6 );
3902 dialog
->control_default
= strdupW( MSI_RecordGetString( rec
, 9 ) );
3903 dialog
->control_cancel
= strdupW( MSI_RecordGetString( rec
, 10 ) );
3904 msiobj_release( &rec
->hdr
);
3909 static void msi_dialog_end_dialog( msi_dialog
*dialog
)
3911 TRACE("%p\n", dialog
);
3912 dialog
->finished
= 1;
3913 PostMessageW(dialog
->hwnd
, WM_NULL
, 0, 0);
3916 void msi_dialog_check_messages( HANDLE handle
)
3920 /* in threads other than the UI thread, block */
3921 if( uiThreadId
!= GetCurrentThreadId() )
3923 if (!handle
) return;
3924 while (MsgWaitForMultipleObjectsEx( 1, &handle
, INFINITE
, QS_ALLINPUT
, 0 ) == WAIT_OBJECT_0
+ 1)
3927 while (PeekMessageW( &msg
, NULL
, 0, 0, PM_REMOVE
))
3929 TranslateMessage( &msg
);
3930 DispatchMessageW( &msg
);
3936 /* there are two choices for the UI thread */
3939 process_pending_messages( NULL
);
3945 * block here until somebody creates a new dialog or
3946 * the handle we're waiting on becomes ready
3948 r
= MsgWaitForMultipleObjects( 1, &handle
, 0, INFINITE
, QS_ALLINPUT
);
3949 if( r
== WAIT_OBJECT_0
)
3954 static void dialog_do_preview( msi_dialog
*dialog
)
3957 dialog
->attributes
|= msidbDialogAttributesVisible
;
3958 dialog
->attributes
&= ~msidbDialogAttributesModal
;
3959 dialog_run_message_loop( dialog
);
3962 static void free_subscriber( struct subscriber
*sub
)
3964 msi_free( sub
->event
);
3965 msi_free( sub
->control
);
3966 msi_free( sub
->attribute
);
3970 static void event_cleanup_subscriptions( MSIPACKAGE
*package
, const WCHAR
*dialog
)
3972 struct list
*item
, *next
;
3974 LIST_FOR_EACH_SAFE( item
, next
, &package
->subscriptions
)
3976 struct subscriber
*sub
= LIST_ENTRY( item
, struct subscriber
, entry
);
3978 if (strcmpW( sub
->dialog
->name
, dialog
)) continue;
3979 list_remove( &sub
->entry
);
3980 free_subscriber( sub
);
3984 void msi_dialog_destroy( msi_dialog
*dialog
)
3986 msi_font
*font
, *next
;
3988 if( uiThreadId
!= GetCurrentThreadId() )
3990 SendMessageW( hMsiHiddenWindow
, WM_MSI_DIALOG_DESTROY
, 0, (LPARAM
) dialog
);
3995 ShowWindow( dialog
->hwnd
, SW_HIDE
);
3998 DestroyWindow( dialog
->hwnd
);
4000 /* unsubscribe events */
4001 event_cleanup_subscriptions( dialog
->package
, dialog
->name
);
4003 /* destroy the list of controls */
4004 while( !list_empty( &dialog
->controls
) )
4008 t
= LIST_ENTRY( list_head( &dialog
->controls
),
4009 msi_control
, entry
);
4010 msi_destroy_control( t
);
4013 /* destroy the list of fonts */
4014 LIST_FOR_EACH_ENTRY_SAFE( font
, next
, &dialog
->fonts
, msi_font
, entry
)
4016 list_remove( &font
->entry
);
4017 DeleteObject( font
->hfont
);
4020 msi_free( dialog
->default_font
);
4022 msi_free( dialog
->control_default
);
4023 msi_free( dialog
->control_cancel
);
4024 msiobj_release( &dialog
->package
->hdr
);
4025 dialog
->package
= NULL
;
4029 void msi_dialog_unregister_class( void )
4031 DestroyWindow( hMsiHiddenWindow
);
4032 hMsiHiddenWindow
= NULL
;
4033 UnregisterClassW( szMsiDialogClass
, NULL
);
4034 UnregisterClassW( szMsiHiddenWindow
, NULL
);
4038 void msi_event_cleanup_all_subscriptions( MSIPACKAGE
*package
)
4040 struct list
*item
, *next
;
4042 LIST_FOR_EACH_SAFE( item
, next
, &package
->subscriptions
)
4044 struct subscriber
*sub
= LIST_ENTRY( item
, struct subscriber
, entry
);
4045 list_remove( &sub
->entry
);
4046 free_subscriber( sub
);
4050 static UINT
error_dialog_handler( msi_dialog
*dialog
, const WCHAR
*event
, const WCHAR
*argument
)
4052 static const WCHAR end_dialog
[] = {'E','n','d','D','i','a','l','o','g',0};
4053 static const WCHAR error_abort
[] = {'E','r','r','o','r','A','b','o','r','t',0};
4054 static const WCHAR error_cancel
[] = {'E','r','r','o','r','C','a','n','c','e','l',0};
4055 static const WCHAR error_no
[] = {'E','r','r','o','r','N','o',0};
4056 static const WCHAR result_prop
[] = {
4057 'M','S','I','E','r','r','o','r','D','i','a','l','o','g','R','e','s','u','l','t',0
4060 if ( strcmpW( event
, end_dialog
) )
4061 return ERROR_SUCCESS
;
4063 if ( !strcmpW( argument
, error_abort
) || !strcmpW( argument
, error_cancel
) ||
4064 !strcmpW( argument
, error_no
) )
4066 msi_set_property( dialog
->package
->db
, result_prop
, error_abort
, -1 );
4069 msi_event_cleanup_all_subscriptions( dialog
->package
);
4070 msi_dialog_end_dialog( dialog
);
4072 return ERROR_SUCCESS
;
4075 static UINT
msi_error_dialog_set_error( MSIPACKAGE
*package
, LPWSTR error_dialog
, LPWSTR error
)
4079 static const WCHAR update
[] =
4080 {'U','P','D','A','T','E',' ','`','C','o','n','t','r','o','l','`',' ',
4081 'S','E','T',' ','`','T','e','x','t','`',' ','=',' ','\'','%','s','\'',' ',
4082 'W','H','E','R','E', ' ','`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',' ',
4083 'A','N','D',' ','`','C','o','n','t','r','o','l','`',' ','=',' ',
4084 '\'','E','r','r','o','r','T','e','x','t','\'',0};
4086 row
= MSI_QueryGetRecord( package
->db
, update
, error
, error_dialog
);
4088 return ERROR_FUNCTION_FAILED
;
4090 msiobj_release(&row
->hdr
);
4091 return ERROR_SUCCESS
;
4094 UINT
msi_spawn_error_dialog( MSIPACKAGE
*package
, LPWSTR error_dialog
, LPWSTR error
)
4097 WCHAR result
[MAX_PATH
];
4098 UINT r
= ERROR_SUCCESS
;
4099 DWORD size
= MAX_PATH
;
4102 static const WCHAR pn_prop
[] = {'P','r','o','d','u','c','t','N','a','m','e',0};
4103 static const WCHAR title_fmt
[] = {'%','s',' ','W','a','r','n','i','n','g',0};
4104 static const WCHAR error_abort
[] = {'E','r','r','o','r','A','b','o','r','t',0};
4105 static const WCHAR result_prop
[] = {
4106 'M','S','I','E','r','r','o','r','D','i','a','l','o','g','R','e','s','u','l','t',0
4109 if ((package
->ui_level
& INSTALLUILEVEL_MASK
) == INSTALLUILEVEL_NONE
) return ERROR_SUCCESS
;
4111 if ( !error_dialog
)
4113 LPWSTR product_name
= msi_dup_property( package
->db
, pn_prop
);
4114 WCHAR title
[MAX_PATH
];
4116 sprintfW( title
, title_fmt
, product_name
);
4117 res
= MessageBoxW( NULL
, error
, title
, MB_OKCANCEL
| MB_ICONWARNING
);
4119 msi_free( product_name
);
4122 return ERROR_SUCCESS
;
4124 return ERROR_FUNCTION_FAILED
;
4127 r
= msi_error_dialog_set_error( package
, error_dialog
, error
);
4128 if ( r
!= ERROR_SUCCESS
)
4131 dialog
= dialog_create( package
, error_dialog
, package
->dialog
, error_dialog_handler
);
4133 return ERROR_FUNCTION_FAILED
;
4135 dialog
->finished
= FALSE
;
4136 r
= dialog_run_message_loop( dialog
);
4137 if ( r
!= ERROR_SUCCESS
)
4140 r
= msi_get_property( package
->db
, result_prop
, result
, &size
);
4141 if ( r
!= ERROR_SUCCESS
)
4144 if ( !strcmpW( result
, error_abort
) )
4145 r
= ERROR_FUNCTION_FAILED
;
4148 msi_dialog_destroy( dialog
);
4153 static void MSI_ClosePreview( MSIOBJECTHDR
*arg
)
4155 MSIPREVIEW
*preview
= (MSIPREVIEW
*)arg
;
4156 msiobj_release( &preview
->package
->hdr
);
4159 static MSIPREVIEW
*MSI_EnableUIPreview( MSIDATABASE
*db
)
4161 MSIPREVIEW
*preview
= NULL
;
4162 MSIPACKAGE
*package
;
4164 package
= MSI_CreatePackage( db
, NULL
);
4167 preview
= alloc_msiobject( MSIHANDLETYPE_PREVIEW
, sizeof(MSIPREVIEW
), MSI_ClosePreview
);
4170 preview
->package
= package
;
4171 msiobj_addref( &package
->hdr
);
4173 msiobj_release( &package
->hdr
);
4178 UINT WINAPI
MsiEnableUIPreview( MSIHANDLE hdb
, MSIHANDLE
*phPreview
)
4181 MSIPREVIEW
*preview
;
4182 UINT r
= ERROR_FUNCTION_FAILED
;
4184 TRACE("%d %p\n", hdb
, phPreview
);
4186 db
= msihandle2msiinfo( hdb
, MSIHANDLETYPE_DATABASE
);
4189 IWineMsiRemoteDatabase
*remote_database
;
4191 remote_database
= (IWineMsiRemoteDatabase
*)msi_get_remote( hdb
);
4192 if (!remote_database
)
4193 return ERROR_INVALID_HANDLE
;
4197 IWineMsiRemoteDatabase_Release( remote_database
);
4198 WARN("MsiEnableUIPreview not allowed during a custom action!\n");
4200 return ERROR_FUNCTION_FAILED
;
4202 preview
= MSI_EnableUIPreview( db
);
4205 *phPreview
= alloc_msihandle( &preview
->hdr
);
4206 msiobj_release( &preview
->hdr
);
4209 r
= ERROR_NOT_ENOUGH_MEMORY
;
4211 msiobj_release( &db
->hdr
);
4215 static UINT
preview_event_handler( msi_dialog
*dialog
, const WCHAR
*event
, const WCHAR
*argument
)
4217 MESSAGE("Preview dialog event '%s' (arg='%s')\n", debugstr_w(event
), debugstr_w(argument
));
4218 return ERROR_SUCCESS
;
4221 static UINT
MSI_PreviewDialogW( MSIPREVIEW
*preview
, LPCWSTR szDialogName
)
4223 msi_dialog
*dialog
= NULL
;
4224 UINT r
= ERROR_SUCCESS
;
4226 if (preview
->dialog
)
4227 msi_dialog_destroy( preview
->dialog
);
4229 /* an empty name means we should just destroy the current preview dialog */
4232 dialog
= dialog_create( preview
->package
, szDialogName
, NULL
, preview_event_handler
);
4234 dialog_do_preview( dialog
);
4236 r
= ERROR_FUNCTION_FAILED
;
4238 preview
->dialog
= dialog
;
4242 UINT WINAPI
MsiPreviewDialogW( MSIHANDLE hPreview
, LPCWSTR szDialogName
)
4244 MSIPREVIEW
*preview
;
4247 TRACE("%d %s\n", hPreview
, debugstr_w(szDialogName
));
4249 preview
= msihandle2msiinfo( hPreview
, MSIHANDLETYPE_PREVIEW
);
4251 return ERROR_INVALID_HANDLE
;
4253 r
= MSI_PreviewDialogW( preview
, szDialogName
);
4254 msiobj_release( &preview
->hdr
);
4258 UINT WINAPI
MsiPreviewDialogA( MSIHANDLE hPreview
, LPCSTR szDialogName
)
4263 TRACE("%d %s\n", hPreview
, debugstr_a(szDialogName
));
4267 strW
= strdupAtoW( szDialogName
);
4269 return ERROR_OUTOFMEMORY
;
4271 r
= MsiPreviewDialogW( hPreview
, strW
);
4276 UINT WINAPI
MsiPreviewBillboardW( MSIHANDLE hPreview
, LPCWSTR szControlName
, LPCWSTR szBillboard
)
4278 FIXME("%d %s %s\n", hPreview
, debugstr_w(szControlName
), debugstr_w(szBillboard
));
4279 return ERROR_CALL_NOT_IMPLEMENTED
;
4282 UINT WINAPI
MsiPreviewBillboardA( MSIHANDLE hPreview
, LPCSTR szControlName
, LPCSTR szBillboard
)
4284 FIXME("%d %s %s\n", hPreview
, debugstr_a(szControlName
), debugstr_a(szBillboard
));
4285 return ERROR_CALL_NOT_IMPLEMENTED
;
4288 typedef UINT (*event_handler
)( msi_dialog
*, const WCHAR
* );
4290 struct control_event
4293 event_handler handler
;
4296 static UINT
dialog_event_handler( msi_dialog
*, const WCHAR
*, const WCHAR
* );
4298 /* create a dialog box and run it if it's modal */
4299 static UINT
event_do_dialog( MSIPACKAGE
*package
, const WCHAR
*name
, msi_dialog
*parent
, BOOL destroy_modeless
)
4304 /* create a new dialog */
4305 dialog
= dialog_create( package
, name
, parent
, dialog_event_handler
);
4308 /* kill the current modeless dialog */
4309 if (destroy_modeless
&& package
->dialog
)
4311 msi_dialog_destroy( package
->dialog
);
4312 package
->dialog
= NULL
;
4315 /* modeless dialogs return an error message */
4316 r
= dialog_run_message_loop( dialog
);
4317 if (r
== ERROR_SUCCESS
)
4318 msi_dialog_destroy( dialog
);
4320 package
->dialog
= dialog
;
4322 else r
= ERROR_FUNCTION_FAILED
;
4326 /* end a modal dialog box */
4327 static UINT
event_end_dialog( msi_dialog
*dialog
, const WCHAR
*argument
)
4329 static const WCHAR exitW
[] = {'E','x','i','t',0};
4330 static const WCHAR retryW
[] = {'R','e','t','r','y',0};
4331 static const WCHAR ignoreW
[] = {'I','g','n','o','r','e',0};
4332 static const WCHAR returnW
[] = {'R','e','t','u','r','n',0};
4334 if (!strcmpW( argument
, exitW
))
4335 dialog
->package
->CurrentInstallState
= ERROR_INSTALL_USEREXIT
;
4336 else if (!strcmpW( argument
, retryW
))
4337 dialog
->package
->CurrentInstallState
= ERROR_INSTALL_SUSPEND
;
4338 else if (!strcmpW( argument
, ignoreW
))
4339 dialog
->package
->CurrentInstallState
= ERROR_SUCCESS
;
4340 else if (!strcmpW( argument
, returnW
))
4342 msi_dialog
*parent
= dialog
->parent
;
4343 msi_free( dialog
->package
->next_dialog
);
4344 dialog
->package
->next_dialog
= (parent
) ? strdupW( parent
->name
) : NULL
;
4345 dialog
->package
->CurrentInstallState
= ERROR_SUCCESS
;
4349 ERR("Unknown argument string %s\n", debugstr_w(argument
));
4350 dialog
->package
->CurrentInstallState
= ERROR_FUNCTION_FAILED
;
4352 event_cleanup_subscriptions( dialog
->package
, dialog
->name
);
4353 msi_dialog_end_dialog( dialog
);
4354 return ERROR_SUCCESS
;
4357 /* transition from one modal dialog to another modal dialog */
4358 static UINT
event_new_dialog( msi_dialog
*dialog
, const WCHAR
*argument
)
4360 /* store the name of the next dialog, and signal this one to end */
4361 dialog
->package
->next_dialog
= strdupW( argument
);
4362 msi_event_cleanup_all_subscriptions( dialog
->package
);
4363 msi_dialog_end_dialog( dialog
);
4364 return ERROR_SUCCESS
;
4367 /* create a new child dialog of an existing modal dialog */
4368 static UINT
event_spawn_dialog( msi_dialog
*dialog
, const WCHAR
*argument
)
4370 /* don't destroy a modeless dialogs that might be our parent */
4371 event_do_dialog( dialog
->package
, argument
, dialog
, FALSE
);
4372 if (dialog
->package
->CurrentInstallState
!= ERROR_SUCCESS
) msi_dialog_end_dialog( dialog
);
4373 return ERROR_SUCCESS
;
4376 /* creates a dialog that remains up for a period of time based on a condition */
4377 static UINT
event_spawn_wait_dialog( msi_dialog
*dialog
, const WCHAR
*argument
)
4379 FIXME("doing nothing\n");
4380 return ERROR_SUCCESS
;
4383 static UINT
event_do_action( msi_dialog
*dialog
, const WCHAR
*argument
)
4385 ACTION_PerformAction( dialog
->package
, argument
, SCRIPT_NONE
);
4386 return ERROR_SUCCESS
;
4389 static UINT
event_add_local( msi_dialog
*dialog
, const WCHAR
*argument
)
4391 MSIFEATURE
*feature
;
4393 LIST_FOR_EACH_ENTRY( feature
, &dialog
->package
->features
, MSIFEATURE
, entry
)
4395 if (!strcmpW( argument
, feature
->Feature
) || !strcmpW( argument
, szAll
))
4397 if (feature
->ActionRequest
!= INSTALLSTATE_LOCAL
)
4398 msi_set_property( dialog
->package
->db
, szPreselected
, szOne
, -1 );
4399 MSI_SetFeatureStateW( dialog
->package
, feature
->Feature
, INSTALLSTATE_LOCAL
);
4402 return ERROR_SUCCESS
;
4405 static UINT
event_remove( msi_dialog
*dialog
, const WCHAR
*argument
)
4407 MSIFEATURE
*feature
;
4409 LIST_FOR_EACH_ENTRY( feature
, &dialog
->package
->features
, MSIFEATURE
, entry
)
4411 if (!strcmpW( argument
, feature
->Feature
) || !strcmpW( argument
, szAll
))
4413 if (feature
->ActionRequest
!= INSTALLSTATE_ABSENT
)
4414 msi_set_property( dialog
->package
->db
, szPreselected
, szOne
, -1 );
4415 MSI_SetFeatureStateW( dialog
->package
, feature
->Feature
, INSTALLSTATE_ABSENT
);
4418 return ERROR_SUCCESS
;
4421 static UINT
event_add_source( msi_dialog
*dialog
, const WCHAR
*argument
)
4423 MSIFEATURE
*feature
;
4425 LIST_FOR_EACH_ENTRY( feature
, &dialog
->package
->features
, MSIFEATURE
, entry
)
4427 if (!strcmpW( argument
, feature
->Feature
) || !strcmpW( argument
, szAll
))
4429 if (feature
->ActionRequest
!= INSTALLSTATE_SOURCE
)
4430 msi_set_property( dialog
->package
->db
, szPreselected
, szOne
, -1 );
4431 MSI_SetFeatureStateW( dialog
->package
, feature
->Feature
, INSTALLSTATE_SOURCE
);
4434 return ERROR_SUCCESS
;
4437 void msi_event_fire( MSIPACKAGE
*package
, const WCHAR
*event
, MSIRECORD
*rec
)
4439 struct subscriber
*sub
;
4441 TRACE("firing event %s\n", debugstr_w(event
));
4443 LIST_FOR_EACH_ENTRY( sub
, &package
->subscriptions
, struct subscriber
, entry
)
4445 if (strcmpiW( sub
->event
, event
)) continue;
4446 dialog_handle_event( sub
->dialog
, sub
->control
, sub
->attribute
, rec
);
4450 static UINT
event_set_target_path( msi_dialog
*dialog
, const WCHAR
*argument
)
4452 WCHAR
*path
= msi_dup_property( dialog
->package
->db
, argument
);
4453 MSIRECORD
*rec
= MSI_CreateRecord( 1 );
4454 UINT r
= ERROR_SUCCESS
;
4456 MSI_RecordSetStringW( rec
, 1, path
);
4457 msi_event_fire( dialog
->package
, szSelectionPath
, rec
);
4460 /* failure to set the path halts the executing of control events */
4461 r
= MSI_SetTargetPathW( dialog
->package
, argument
, path
);
4464 msi_free( &rec
->hdr
);
4468 static UINT
event_reset( msi_dialog
*dialog
, const WCHAR
*argument
)
4470 msi_dialog_reset( dialog
);
4471 return ERROR_SUCCESS
;
4474 /* Return ERROR_SUCCESS if dialog is process and ERROR_FUNCTION_FAILED
4475 * if the given parameter is not a dialog box
4477 UINT
ACTION_DialogBox( MSIPACKAGE
*package
, const WCHAR
*dialog
)
4481 if (package
->next_dialog
) ERR("Already got next dialog... ignoring it\n");
4482 package
->next_dialog
= NULL
;
4484 /* Dialogs are chained by filling in the next_dialog member
4485 * of the package structure, then terminating the current dialog.
4486 * The code below sees the next_dialog member set, and runs the
4488 * We fall out of the loop below if we come across a modeless
4489 * dialog, as it returns ERROR_IO_PENDING when we try to run
4492 r
= event_do_dialog( package
, dialog
, NULL
, TRUE
);
4493 while (r
== ERROR_SUCCESS
&& package
->next_dialog
)
4495 WCHAR
*name
= package
->next_dialog
;
4497 package
->next_dialog
= NULL
;
4498 r
= event_do_dialog( package
, name
, NULL
, TRUE
);
4501 if (r
== ERROR_IO_PENDING
) r
= ERROR_SUCCESS
;
4505 static UINT
event_set_install_level( msi_dialog
*dialog
, const WCHAR
*argument
)
4507 int level
= atolW( argument
);
4509 TRACE("setting install level to %d\n", level
);
4510 return MSI_SetInstallLevel( dialog
->package
, level
);
4513 static UINT
event_directory_list_up( msi_dialog
*dialog
, const WCHAR
*argument
)
4515 return msi_dialog_directorylist_up( dialog
);
4518 static UINT
event_reinstall_mode( msi_dialog
*dialog
, const WCHAR
*argument
)
4520 return msi_set_property( dialog
->package
->db
, szReinstallMode
, argument
, -1 );
4523 static UINT
event_reinstall( msi_dialog
*dialog
, const WCHAR
*argument
)
4525 return msi_set_property( dialog
->package
->db
, szReinstall
, argument
, -1 );
4528 static UINT
event_validate_product_id( msi_dialog
*dialog
, const WCHAR
*argument
)
4530 return msi_validate_product_id( dialog
->package
);
4533 static const WCHAR end_dialogW
[] = {'E','n','d','D','i','a','l','o','g',0};
4534 static const WCHAR new_dialogW
[] = {'N','e','w','D','i','a','l','o','g',0};
4535 static const WCHAR spawn_dialogW
[] = {'S','p','a','w','n','D','i','a','l','o','g',0};
4536 static const WCHAR spawn_wait_dialogW
[] = {'S','p','a','w','n','W','a','i','t','D','i','a','l','o','g',0};
4537 static const WCHAR do_actionW
[] = {'D','o','A','c','t','i','o','n',0};
4538 static const WCHAR add_localW
[] = {'A','d','d','L','o','c','a','l',0};
4539 static const WCHAR removeW
[] = {'R','e','m','o','v','e',0};
4540 static const WCHAR add_sourceW
[] = {'A','d','d','S','o','u','r','c','e',0};
4541 static const WCHAR set_target_pathW
[] = {'S','e','t','T','a','r','g','e','t','P','a','t','h',0};
4542 static const WCHAR resetW
[] = {'R','e','s','e','t',0};
4543 static const WCHAR set_install_levelW
[] = {'S','e','t','I','n','s','t','a','l','l','L','e','v','e','l',0};
4544 static const WCHAR directory_list_upW
[] = {'D','i','r','e','c','t','o','r','y','L','i','s','t','U','p',0};
4545 static const WCHAR selection_browseW
[] = {'S','e','l','e','c','t','i','o','n','B','r','o','w','s','e',0};
4546 static const WCHAR reinstall_modeW
[] = {'R','e','i','n','s','t','a','l','l','M','o','d','e',0};
4547 static const WCHAR reinstallW
[] = {'R','e','i','n','s','t','a','l','l',0};
4548 static const WCHAR validate_product_idW
[] = {'V','a','l','i','d','a','t','e','P','r','o','d','u','c','t','I','D',0};
4550 static const struct control_event control_events
[] =
4552 { end_dialogW
, event_end_dialog
},
4553 { new_dialogW
, event_new_dialog
},
4554 { spawn_dialogW
, event_spawn_dialog
},
4555 { spawn_wait_dialogW
, event_spawn_wait_dialog
},
4556 { do_actionW
, event_do_action
},
4557 { add_localW
, event_add_local
},
4558 { removeW
, event_remove
},
4559 { add_sourceW
, event_add_source
},
4560 { set_target_pathW
, event_set_target_path
},
4561 { resetW
, event_reset
},
4562 { set_install_levelW
, event_set_install_level
},
4563 { directory_list_upW
, event_directory_list_up
},
4564 { selection_browseW
, event_spawn_dialog
},
4565 { reinstall_modeW
, event_reinstall_mode
},
4566 { reinstallW
, event_reinstall
},
4567 { validate_product_idW
, event_validate_product_id
},
4571 static UINT
dialog_event_handler( msi_dialog
*dialog
, const WCHAR
*event
, const WCHAR
*argument
)
4575 TRACE("handling event %s\n", debugstr_w(event
));
4577 if (!event
) return ERROR_SUCCESS
;
4579 for (i
= 0; control_events
[i
].event
; i
++)
4581 if (!strcmpW( control_events
[i
].event
, event
))
4582 return control_events
[i
].handler( dialog
, argument
);
4584 FIXME("unhandled event %s arg(%s)\n", debugstr_w(event
), debugstr_w(argument
));
4585 return ERROR_SUCCESS
;