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
;
107 } radio_button_group_descr
;
109 static const WCHAR szMsiDialogClass
[] = { 'M','s','i','D','i','a','l','o','g','C','l','o','s','e','C','l','a','s','s',0 };
110 static const WCHAR szMsiHiddenWindow
[] = { 'M','s','i','H','i','d','d','e','n','W','i','n','d','o','w',0 };
111 static const WCHAR szStatic
[] = { 'S','t','a','t','i','c',0 };
112 static const WCHAR szButton
[] = { 'B','U','T','T','O','N', 0 };
113 static const WCHAR szButtonData
[] = { 'M','S','I','D','A','T','A',0 };
114 static const WCHAR szProgress
[] = { 'P','r','o','g','r','e','s','s',0 };
115 static const WCHAR szText
[] = { 'T','e','x','t',0 };
116 static const WCHAR szPushButton
[] = { 'P','u','s','h','B','u','t','t','o','n',0 };
117 static const WCHAR szLine
[] = { 'L','i','n','e',0 };
118 static const WCHAR szBitmap
[] = { 'B','i','t','m','a','p',0 };
119 static const WCHAR szCheckBox
[] = { 'C','h','e','c','k','B','o','x',0 };
120 static const WCHAR szScrollableText
[] = { 'S','c','r','o','l','l','a','b','l','e','T','e','x','t',0 };
121 static const WCHAR szComboBox
[] = { 'C','o','m','b','o','B','o','x',0 };
122 static const WCHAR szEdit
[] = { 'E','d','i','t',0 };
123 static const WCHAR szMaskedEdit
[] = { 'M','a','s','k','e','d','E','d','i','t',0 };
124 static const WCHAR szPathEdit
[] = { 'P','a','t','h','E','d','i','t',0 };
125 static const WCHAR szProgressBar
[] = { 'P','r','o','g','r','e','s','s','B','a','r',0 };
126 static const WCHAR szSetProgress
[] = { 'S','e','t','P','r','o','g','r','e','s','s',0 };
127 static const WCHAR szRadioButtonGroup
[] = { 'R','a','d','i','o','B','u','t','t','o','n','G','r','o','u','p',0 };
128 static const WCHAR szIcon
[] = { 'I','c','o','n',0 };
129 static const WCHAR szSelectionTree
[] = { 'S','e','l','e','c','t','i','o','n','T','r','e','e',0 };
130 static const WCHAR szGroupBox
[] = { 'G','r','o','u','p','B','o','x',0 };
131 static const WCHAR szListBox
[] = { 'L','i','s','t','B','o','x',0 };
132 static const WCHAR szDirectoryCombo
[] = { 'D','i','r','e','c','t','o','r','y','C','o','m','b','o',0 };
133 static const WCHAR szDirectoryList
[] = { 'D','i','r','e','c','t','o','r','y','L','i','s','t',0 };
134 static const WCHAR szVolumeCostList
[] = { 'V','o','l','u','m','e','C','o','s','t','L','i','s','t',0 };
135 static const WCHAR szVolumeSelectCombo
[] = { 'V','o','l','u','m','e','S','e','l','e','c','t','C','o','m','b','o',0 };
136 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};
137 static const WCHAR szSelectionPath
[] = {'S','e','l','e','c','t','i','o','n','P','a','t','h',0};
138 static const WCHAR szProperty
[] = {'P','r','o','p','e','r','t','y',0};
139 static const WCHAR szHyperLink
[] = {'H','y','p','e','r','L','i','n','k',0};
141 /* dialog sequencing */
143 #define WM_MSI_DIALOG_CREATE (WM_USER+0x100)
144 #define WM_MSI_DIALOG_DESTROY (WM_USER+0x101)
146 #define USER_INSTALLSTATE_ALL 0x1000
148 static DWORD uiThreadId
;
149 static HWND hMsiHiddenWindow
;
151 static LPWSTR
msi_get_window_text( HWND hwnd
)
157 buf
= msi_alloc( sz
*sizeof(WCHAR
) );
160 r
= GetWindowTextW( hwnd
, buf
, sz
);
164 buf
= msi_realloc( buf
, sz
*sizeof(WCHAR
) );
170 static INT
msi_dialog_scale_unit( msi_dialog
*dialog
, INT val
)
172 return MulDiv( val
, dialog
->scale
, 12 );
175 static msi_control
*msi_dialog_find_control( msi_dialog
*dialog
, LPCWSTR name
)
177 msi_control
*control
;
183 LIST_FOR_EACH_ENTRY( control
, &dialog
->controls
, msi_control
, entry
)
184 if( !strcmpW( control
->name
, name
) ) /* FIXME: case sensitive? */
189 static msi_control
*msi_dialog_find_control_by_type( msi_dialog
*dialog
, LPCWSTR type
)
191 msi_control
*control
;
197 LIST_FOR_EACH_ENTRY( control
, &dialog
->controls
, msi_control
, entry
)
198 if( !strcmpW( control
->type
, type
) ) /* FIXME: case sensitive? */
203 static msi_control
*msi_dialog_find_control_by_hwnd( msi_dialog
*dialog
, HWND hwnd
)
205 msi_control
*control
;
209 LIST_FOR_EACH_ENTRY( control
, &dialog
->controls
, msi_control
, entry
)
210 if( hwnd
== control
->hwnd
)
215 static LPWSTR
msi_get_deformatted_field( MSIPACKAGE
*package
, MSIRECORD
*rec
, int field
)
217 LPCWSTR str
= MSI_RecordGetString( rec
, field
);
221 deformat_string( package
, str
, &ret
);
225 static LPWSTR
msi_dialog_dup_property( msi_dialog
*dialog
, LPCWSTR property
, BOOL indirect
)
233 prop
= msi_dup_property( dialog
->package
->db
, property
);
236 prop
= strdupW( property
);
242 * msi_dialog_get_style
244 * Extract the {\style} string from the front of the text to display and
245 * update the pointer. Only the last style in a list is applied.
247 static LPWSTR
msi_dialog_get_style( LPCWSTR p
, LPCWSTR
*rest
)
258 while ((first
= strchrW( p
, '{' )) && (q
= strchrW( first
+ 1, '}' )))
261 if( *p
!= '\\' && *p
!= '&' )
264 /* little bit of sanity checking to stop us getting confused with RTF */
265 for( i
=++p
; i
<q
; i
++ )
266 if( *i
== '}' || *i
== '\\' )
276 ret
= msi_alloc( len
*sizeof(WCHAR
) );
279 memcpy( ret
, p
, len
*sizeof(WCHAR
) );
284 static UINT
msi_dialog_add_font( MSIRECORD
*rec
, LPVOID param
)
286 msi_dialog
*dialog
= param
;
293 /* create a font and add it to the list */
294 name
= MSI_RecordGetString( rec
, 1 );
295 font
= msi_alloc( FIELD_OFFSET( msi_font
, name
[strlenW( name
) + 1] ));
296 strcpyW( font
->name
, name
);
297 list_add_head( &dialog
->fonts
, &font
->entry
);
299 font
->color
= MSI_RecordGetInteger( rec
, 4 );
301 memset( &lf
, 0, sizeof lf
);
302 face
= MSI_RecordGetString( rec
, 2 );
303 lf
.lfHeight
= MSI_RecordGetInteger( rec
, 3 );
304 style
= MSI_RecordGetInteger( rec
, 5 );
305 if( style
& msidbTextStyleStyleBitsBold
)
306 lf
.lfWeight
= FW_BOLD
;
307 if( style
& msidbTextStyleStyleBitsItalic
)
309 if( style
& msidbTextStyleStyleBitsUnderline
)
310 lf
.lfUnderline
= TRUE
;
311 if( style
& msidbTextStyleStyleBitsStrike
)
312 lf
.lfStrikeOut
= TRUE
;
313 lstrcpynW( lf
.lfFaceName
, face
, LF_FACESIZE
);
315 /* adjust the height */
316 hdc
= GetDC( dialog
->hwnd
);
319 lf
.lfHeight
= -MulDiv(lf
.lfHeight
, GetDeviceCaps(hdc
, LOGPIXELSY
), 72);
320 ReleaseDC( dialog
->hwnd
, hdc
);
323 font
->hfont
= CreateFontIndirectW( &lf
);
325 TRACE("Adding font style %s\n", debugstr_w(font
->name
) );
327 return ERROR_SUCCESS
;
330 static msi_font
*msi_dialog_find_font( msi_dialog
*dialog
, LPCWSTR name
)
332 msi_font
*font
= NULL
;
334 LIST_FOR_EACH_ENTRY( font
, &dialog
->fonts
, msi_font
, entry
)
335 if( !strcmpW( font
->name
, name
) ) /* FIXME: case sensitive? */
341 static UINT
msi_dialog_set_font( msi_dialog
*dialog
, HWND hwnd
, LPCWSTR name
)
345 font
= msi_dialog_find_font( dialog
, name
);
347 SendMessageW( hwnd
, WM_SETFONT
, (WPARAM
) font
->hfont
, TRUE
);
349 ERR("No font entry for %s\n", debugstr_w(name
));
350 return ERROR_SUCCESS
;
353 static UINT
msi_dialog_build_font_list( msi_dialog
*dialog
)
355 static const WCHAR query
[] = {
356 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
357 '`','T','e','x','t','S','t','y','l','e','`',0};
361 TRACE("dialog %p\n", dialog
);
363 r
= MSI_OpenQuery( dialog
->package
->db
, &view
, query
);
364 if( r
!= ERROR_SUCCESS
)
367 r
= MSI_IterateRecords( view
, NULL
, msi_dialog_add_font
, dialog
);
368 msiobj_release( &view
->hdr
);
372 static void msi_destroy_control( msi_control
*t
)
374 list_remove( &t
->entry
);
375 /* leave dialog->hwnd - destroying parent destroys child windows */
376 msi_free( t
->property
);
377 msi_free( t
->value
);
379 DeleteObject( t
->hBitmap
);
381 DestroyIcon( t
->hIcon
);
382 msi_free( t
->tabnext
);
385 FreeLibrary( t
->hDll
);
389 static msi_control
*dialog_create_window( msi_dialog
*dialog
, MSIRECORD
*rec
, DWORD exstyle
,
390 const WCHAR
*szCls
, const WCHAR
*name
, const WCHAR
*text
,
391 DWORD style
, HWND parent
)
393 DWORD x
, y
, width
, height
;
394 LPWSTR font
= NULL
, title_font
= NULL
;
395 LPCWSTR title
= NULL
;
396 msi_control
*control
;
400 control
= msi_alloc( FIELD_OFFSET( msi_control
, name
[strlenW( name
) + 1] ));
404 strcpyW( control
->name
, name
);
405 list_add_tail( &dialog
->controls
, &control
->entry
);
406 control
->handler
= NULL
;
407 control
->update
= NULL
;
408 control
->property
= NULL
;
409 control
->value
= NULL
;
410 control
->hBitmap
= NULL
;
411 control
->hIcon
= NULL
;
412 control
->hDll
= NULL
;
413 control
->tabnext
= strdupW( MSI_RecordGetString( rec
, 11) );
414 control
->type
= strdupW( MSI_RecordGetString( rec
, 3 ) );
415 control
->progress_current
= 0;
416 control
->progress_max
= 100;
417 control
->progress_backwards
= FALSE
;
419 x
= MSI_RecordGetInteger( rec
, 4 );
420 y
= MSI_RecordGetInteger( rec
, 5 );
421 width
= MSI_RecordGetInteger( rec
, 6 );
422 height
= MSI_RecordGetInteger( rec
, 7 );
424 x
= msi_dialog_scale_unit( dialog
, x
);
425 y
= msi_dialog_scale_unit( dialog
, y
);
426 width
= msi_dialog_scale_unit( dialog
, width
);
427 height
= msi_dialog_scale_unit( dialog
, height
);
431 deformat_string( dialog
->package
, text
, &title_font
);
432 font
= msi_dialog_get_style( title_font
, &title
);
435 control
->hwnd
= CreateWindowExW( exstyle
, szCls
, title
, style
,
436 x
, y
, width
, height
, parent
, NULL
, NULL
, NULL
);
438 TRACE("Dialog %s control %s hwnd %p\n",
439 debugstr_w(dialog
->name
), debugstr_w(text
), control
->hwnd
);
441 msi_dialog_set_font( dialog
, control
->hwnd
,
442 font
? font
: dialog
->default_font
);
444 msi_free( title_font
);
450 static LPWSTR
msi_dialog_get_uitext( msi_dialog
*dialog
, LPCWSTR key
)
455 static const WCHAR query
[] = {
456 's','e','l','e','c','t',' ','*',' ',
457 'f','r','o','m',' ','`','U','I','T','e','x','t','`',' ',
458 'w','h','e','r','e',' ','`','K','e','y','`',' ','=',' ','\'','%','s','\'',0
461 rec
= MSI_QueryGetRecord( dialog
->package
->db
, query
, key
);
462 if (!rec
) return NULL
;
463 text
= strdupW( MSI_RecordGetString( rec
, 2 ) );
464 msiobj_release( &rec
->hdr
);
468 static MSIRECORD
*msi_get_binary_record( MSIDATABASE
*db
, LPCWSTR name
)
470 static const WCHAR query
[] = {
471 's','e','l','e','c','t',' ','*',' ',
472 'f','r','o','m',' ','B','i','n','a','r','y',' ',
473 'w','h','e','r','e',' ',
474 '`','N','a','m','e','`',' ','=',' ','\'','%','s','\'',0
477 return MSI_QueryGetRecord( db
, query
, name
);
480 static LPWSTR
msi_create_tmp_path(void)
486 r
= GetTempPathW( MAX_PATH
, tmp
);
489 len
= lstrlenW( tmp
) + 20;
490 path
= msi_alloc( len
* sizeof (WCHAR
) );
493 r
= GetTempFileNameW( tmp
, szMsi
, 0, path
);
503 static HANDLE
msi_load_image( MSIDATABASE
*db
, LPCWSTR name
, UINT type
,
504 UINT cx
, UINT cy
, UINT flags
)
506 MSIRECORD
*rec
= NULL
;
507 HANDLE himage
= NULL
;
511 TRACE("%p %s %u %u %08x\n", db
, debugstr_w(name
), cx
, cy
, flags
);
513 tmp
= msi_create_tmp_path();
517 rec
= msi_get_binary_record( db
, name
);
520 r
= MSI_RecordStreamToFile( rec
, 2, tmp
);
521 if( r
== ERROR_SUCCESS
)
523 himage
= LoadImageW( 0, tmp
, type
, cx
, cy
, flags
);
525 msiobj_release( &rec
->hdr
);
533 static HICON
msi_load_icon( MSIDATABASE
*db
, LPCWSTR text
, UINT attributes
)
535 DWORD cx
= 0, cy
= 0, flags
;
537 flags
= LR_LOADFROMFILE
| LR_DEFAULTSIZE
;
538 if( attributes
& msidbControlAttributesFixedSize
)
540 flags
&= ~LR_DEFAULTSIZE
;
541 if( attributes
& msidbControlAttributesIconSize16
)
546 if( attributes
& msidbControlAttributesIconSize32
)
551 /* msidbControlAttributesIconSize48 handled by above logic */
553 return msi_load_image( db
, text
, IMAGE_ICON
, cx
, cy
, flags
);
556 static void msi_dialog_update_controls( msi_dialog
*dialog
, LPCWSTR property
)
558 msi_control
*control
;
560 LIST_FOR_EACH_ENTRY( control
, &dialog
->controls
, msi_control
, entry
)
562 if ( control
->property
&& !strcmpW( control
->property
, property
) && control
->update
)
563 control
->update( dialog
, control
);
567 static void msi_dialog_set_property( MSIPACKAGE
*package
, LPCWSTR property
, LPCWSTR value
)
569 UINT r
= msi_set_property( package
->db
, property
, value
, -1 );
570 if (r
== ERROR_SUCCESS
&& !strcmpW( property
, szSourceDir
))
571 msi_reset_folders( package
, TRUE
);
574 static MSIFEATURE
*msi_seltree_feature_from_item( HWND hwnd
, HTREEITEM hItem
)
578 /* get the feature from the item */
579 memset( &tvi
, 0, sizeof tvi
);
581 tvi
.mask
= TVIF_PARAM
| TVIF_HANDLE
;
582 SendMessageW( hwnd
, TVM_GETITEMW
, 0, (LPARAM
)&tvi
);
583 return (MSIFEATURE
*)tvi
.lParam
;
586 struct msi_selection_tree_info
594 static MSIFEATURE
*msi_seltree_get_selected_feature( msi_control
*control
)
596 struct msi_selection_tree_info
*info
= GetPropW( control
->hwnd
, szButtonData
);
597 return msi_seltree_feature_from_item( control
->hwnd
, info
->selected
);
600 static void dialog_handle_event( msi_dialog
*dialog
, const WCHAR
*control
,
601 const WCHAR
*attribute
, MSIRECORD
*rec
)
605 ctrl
= msi_dialog_find_control( dialog
, control
);
608 if( !strcmpW( attribute
, szText
) )
610 const WCHAR
*font_text
, *text
= NULL
;
611 WCHAR
*font
, *text_fmt
= NULL
;
613 font_text
= MSI_RecordGetString( rec
, 1 );
614 font
= msi_dialog_get_style( font_text
, &text
);
615 deformat_string( dialog
->package
, text
, &text_fmt
);
616 if (text_fmt
) text
= text_fmt
;
619 SetWindowTextW( ctrl
->hwnd
, text
);
622 msi_free( text_fmt
);
623 msi_dialog_check_messages( NULL
);
625 else if( !strcmpW( attribute
, szProgress
) )
627 DWORD func
, val1
, val2
, units
;
629 func
= MSI_RecordGetInteger( rec
, 1 );
630 val1
= MSI_RecordGetInteger( rec
, 2 );
631 val2
= MSI_RecordGetInteger( rec
, 3 );
633 TRACE("progress: func %u val1 %u val2 %u\n", func
, val1
, val2
);
639 SendMessageW( ctrl
->hwnd
, PBM_SETRANGE
, 0, MAKELPARAM(0,100) );
642 ctrl
->progress_max
= units
? units
: 100;
643 ctrl
->progress_current
= units
;
644 ctrl
->progress_backwards
= TRUE
;
645 SendMessageW( ctrl
->hwnd
, PBM_SETPOS
, 100, 0 );
649 ctrl
->progress_max
= units
? units
: 100;
650 ctrl
->progress_current
= 0;
651 ctrl
->progress_backwards
= FALSE
;
652 SendMessageW( ctrl
->hwnd
, PBM_SETPOS
, 0, 0 );
655 case 1: /* action data increment */
656 if (val2
) dialog
->package
->action_progress_increment
= val1
;
657 else dialog
->package
->action_progress_increment
= 0;
660 if (ctrl
->progress_backwards
)
662 if (units
>= ctrl
->progress_current
) ctrl
->progress_current
-= units
;
663 else ctrl
->progress_current
= 0;
667 if (ctrl
->progress_current
+ units
< ctrl
->progress_max
) ctrl
->progress_current
+= units
;
668 else ctrl
->progress_current
= ctrl
->progress_max
;
670 SendMessageW( ctrl
->hwnd
, PBM_SETPOS
, MulDiv(100, ctrl
->progress_current
, ctrl
->progress_max
), 0 );
673 ctrl
->progress_max
+= units
;
676 FIXME("Unknown progress message %u\n", func
);
680 else if ( !strcmpW( attribute
, szProperty
) )
682 MSIFEATURE
*feature
= msi_seltree_get_selected_feature( ctrl
);
683 if (feature
) msi_dialog_set_property( dialog
->package
, ctrl
->property
, feature
->Directory
);
685 else if ( !strcmpW( attribute
, szSelectionPath
) )
687 BOOL indirect
= ctrl
->attributes
& msidbControlAttributesIndirect
;
688 LPWSTR path
= msi_dialog_dup_property( dialog
, ctrl
->property
, indirect
);
690 SetWindowTextW( ctrl
->hwnd
, path
);
695 FIXME("Attribute %s not being set\n", debugstr_w(attribute
));
700 static void event_subscribe( msi_dialog
*dialog
, const WCHAR
*event
, const WCHAR
*control
, const WCHAR
*attribute
)
702 struct subscriber
*sub
;
704 TRACE("event %s control %s attribute %s\n", debugstr_w(event
), debugstr_w(control
), debugstr_w(attribute
));
706 LIST_FOR_EACH_ENTRY( sub
, &dialog
->package
->subscriptions
, struct subscriber
, entry
)
708 if (!strcmpiW( sub
->event
, event
) &&
709 !strcmpiW( sub
->control
, control
) &&
710 !strcmpiW( sub
->attribute
, attribute
))
712 TRACE("already subscribed\n");
716 if (!(sub
= msi_alloc( sizeof(*sub
) ))) return;
717 sub
->dialog
= dialog
;
718 sub
->event
= strdupW( event
);
719 sub
->control
= strdupW( control
);
720 sub
->attribute
= strdupW( attribute
);
721 list_add_tail( &dialog
->package
->subscriptions
, &sub
->entry
);
724 struct dialog_control
727 const WCHAR
*control
;
730 static UINT
map_event( MSIRECORD
*row
, void *param
)
732 struct dialog_control
*dc
= param
;
733 const WCHAR
*event
= MSI_RecordGetString( row
, 3 );
734 const WCHAR
*attribute
= MSI_RecordGetString( row
, 4 );
736 event_subscribe( dc
->dialog
, event
, dc
->control
, attribute
);
737 return ERROR_SUCCESS
;
740 static void dialog_map_events( msi_dialog
*dialog
, const WCHAR
*control
)
742 static const WCHAR queryW
[] =
743 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
744 '`','E','v','e','n','t','M','a','p','p','i','n','g','`',' ',
745 'W','H','E','R','E',' ','`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',' ',
746 'A','N','D',' ','`','C','o','n','t','r','o','l','_','`',' ','=',' ','\'','%','s','\'',0};
748 struct dialog_control dialog_control
=
754 if (!MSI_OpenQuery( dialog
->package
->db
, &view
, queryW
, dialog
->name
, control
))
756 MSI_IterateRecords( view
, NULL
, map_event
, &dialog_control
);
757 msiobj_release( &view
->hdr
);
761 /* everything except radio buttons */
762 static msi_control
*msi_dialog_add_control( msi_dialog
*dialog
,
763 MSIRECORD
*rec
, LPCWSTR szCls
, DWORD style
)
766 const WCHAR
*text
= NULL
, *name
, *control_type
;
769 name
= MSI_RecordGetString( rec
, 2 );
770 control_type
= MSI_RecordGetString( rec
, 3 );
771 attributes
= MSI_RecordGetInteger( rec
, 8 );
772 if (strcmpW( control_type
, szScrollableText
)) text
= MSI_RecordGetString( rec
, 10 );
774 TRACE("%s, %s, %08x, %s, %08x\n", debugstr_w(szCls
), debugstr_w(name
),
775 attributes
, debugstr_w(text
), style
);
777 if( attributes
& msidbControlAttributesVisible
)
779 if( ~attributes
& msidbControlAttributesEnabled
)
780 style
|= WS_DISABLED
;
781 if( attributes
& msidbControlAttributesSunken
)
782 exstyle
|= WS_EX_CLIENTEDGE
;
784 dialog_map_events( dialog
, name
);
786 return dialog_create_window( dialog
, rec
, exstyle
, szCls
, name
, text
, style
, dialog
->hwnd
);
797 * we don't erase our own background,
798 * so we have to make sure that the parent window redraws first
800 static void msi_text_on_settext( HWND hWnd
)
805 hParent
= GetParent( hWnd
);
806 GetWindowRect( hWnd
, &rc
);
807 MapWindowPoints( NULL
, hParent
, (LPPOINT
) &rc
, 2 );
808 InvalidateRect( hParent
, &rc
, TRUE
);
811 static LRESULT WINAPI
812 MSIText_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
814 struct msi_text_info
*info
;
817 TRACE("%p %04x %08lx %08lx\n", hWnd
, msg
, wParam
, lParam
);
819 info
= GetPropW(hWnd
, szButtonData
);
821 if( msg
== WM_CTLCOLORSTATIC
&&
822 ( info
->attributes
& msidbControlAttributesTransparent
) )
824 SetBkMode( (HDC
)wParam
, TRANSPARENT
);
825 return (LRESULT
) GetStockObject(NULL_BRUSH
);
828 r
= CallWindowProcW(info
->oldproc
, hWnd
, msg
, wParam
, lParam
);
830 SetTextColor( (HDC
)wParam
, info
->font
->color
);
835 msi_text_on_settext( hWnd
);
839 RemovePropW( hWnd
, szButtonData
);
846 static UINT
msi_dialog_text_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
848 msi_control
*control
;
849 struct msi_text_info
*info
;
850 LPCWSTR text
, ptr
, prop
, control_name
;
853 TRACE("%p %p\n", dialog
, rec
);
855 control
= msi_dialog_add_control( dialog
, rec
, szStatic
, SS_LEFT
| WS_GROUP
);
857 return ERROR_FUNCTION_FAILED
;
859 info
= msi_alloc( sizeof *info
);
861 return ERROR_SUCCESS
;
863 control_name
= MSI_RecordGetString( rec
, 2 );
864 control
->attributes
= MSI_RecordGetInteger( rec
, 8 );
865 prop
= MSI_RecordGetString( rec
, 9 );
866 control
->property
= msi_dialog_dup_property( dialog
, prop
, FALSE
);
868 text
= MSI_RecordGetString( rec
, 10 );
869 font_name
= msi_dialog_get_style( text
, &ptr
);
870 info
->font
= ( font_name
) ? msi_dialog_find_font( dialog
, font_name
) : NULL
;
871 msi_free( font_name
);
873 info
->attributes
= MSI_RecordGetInteger( rec
, 8 );
874 if( info
->attributes
& msidbControlAttributesTransparent
)
875 SetWindowLongPtrW( control
->hwnd
, GWL_EXSTYLE
, WS_EX_TRANSPARENT
);
877 info
->oldproc
= (WNDPROC
) SetWindowLongPtrW( control
->hwnd
, GWLP_WNDPROC
,
878 (LONG_PTR
)MSIText_WndProc
);
879 SetPropW( control
->hwnd
, szButtonData
, info
);
881 event_subscribe( dialog
, szSelectionPath
, control_name
, szSelectionPath
);
882 return ERROR_SUCCESS
;
885 /* strip any leading text style label from text field */
886 static WCHAR
*msi_get_binary_name( MSIPACKAGE
*package
, MSIRECORD
*rec
)
890 text
= msi_get_deformatted_field( package
, rec
, 10 );
895 while (*p
&& *p
!= '{') p
++;
896 if (!*p
++) return text
;
898 while (*p
&& *p
!= '}') p
++;
899 if (!*p
++) return text
;
906 static UINT
msi_dialog_set_property_event( msi_dialog
*dialog
, LPCWSTR event
, LPCWSTR arg
)
908 static const WCHAR szNullArg
[] = {'{','}',0};
909 LPWSTR p
, prop
, arg_fmt
= NULL
;
912 len
= strlenW( event
);
913 prop
= msi_alloc( len
* sizeof(WCHAR
) );
914 strcpyW( prop
, &event
[1] );
915 p
= strchrW( prop
, ']' );
916 if (p
&& (p
[1] == 0 || p
[1] == ' '))
919 if (strcmpW( szNullArg
, arg
))
920 deformat_string( dialog
->package
, arg
, &arg_fmt
);
921 msi_dialog_set_property( dialog
->package
, prop
, arg_fmt
);
922 msi_dialog_update_controls( dialog
, prop
);
925 else ERR("Badly formatted property string - what happens?\n");
927 return ERROR_SUCCESS
;
930 static UINT
msi_dialog_send_event( msi_dialog
*dialog
, LPCWSTR event
, LPCWSTR arg
)
932 LPWSTR event_fmt
= NULL
, arg_fmt
= NULL
;
934 TRACE("Sending control event %s %s\n", debugstr_w(event
), debugstr_w(arg
));
936 deformat_string( dialog
->package
, event
, &event_fmt
);
937 deformat_string( dialog
->package
, arg
, &arg_fmt
);
939 dialog
->event_handler( dialog
, event_fmt
, arg_fmt
);
941 msi_free( event_fmt
);
944 return ERROR_SUCCESS
;
947 static UINT
msi_dialog_control_event( MSIRECORD
*rec
, LPVOID param
)
949 msi_dialog
*dialog
= param
;
950 LPCWSTR condition
, event
, arg
;
953 condition
= MSI_RecordGetString( rec
, 5 );
954 r
= MSI_EvaluateConditionW( dialog
->package
, condition
);
955 if (r
== MSICONDITION_TRUE
|| r
== MSICONDITION_NONE
)
957 event
= MSI_RecordGetString( rec
, 3 );
958 arg
= MSI_RecordGetString( rec
, 4 );
960 msi_dialog_set_property_event( dialog
, event
, arg
);
962 msi_dialog_send_event( dialog
, event
, arg
);
964 return ERROR_SUCCESS
;
967 static UINT
msi_dialog_button_handler( msi_dialog
*dialog
, msi_control
*control
, WPARAM param
)
969 static const WCHAR query
[] = {
970 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
971 'C','o','n','t','r','o','l','E','v','e','n','t',' ','W','H','E','R','E',' ',
972 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',' ','A','N','D',' ',
973 '`','C','o','n','t','r','o','l','_','`',' ','=',' ','\'','%','s','\'',' ',
974 'O','R','D','E','R',' ','B','Y',' ','`','O','r','d','e','r','i','n','g','`',0};
978 if (HIWORD(param
) != BN_CLICKED
)
979 return ERROR_SUCCESS
;
981 r
= MSI_OpenQuery( dialog
->package
->db
, &view
, query
, dialog
->name
, control
->name
);
982 if (r
!= ERROR_SUCCESS
)
984 ERR("query failed\n");
985 return ERROR_SUCCESS
;
987 r
= MSI_IterateRecords( view
, 0, msi_dialog_control_event
, dialog
);
988 msiobj_release( &view
->hdr
);
992 static UINT
msi_dialog_button_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
994 msi_control
*control
;
995 UINT attributes
, style
;
997 TRACE("%p %p\n", dialog
, rec
);
1000 attributes
= MSI_RecordGetInteger( rec
, 8 );
1001 if( attributes
& msidbControlAttributesIcon
)
1004 control
= msi_dialog_add_control( dialog
, rec
, szButton
, style
);
1006 return ERROR_FUNCTION_FAILED
;
1008 control
->handler
= msi_dialog_button_handler
;
1010 if (attributes
& msidbControlAttributesIcon
)
1013 LPWSTR name
= msi_get_binary_name( dialog
->package
, rec
);
1014 control
->hIcon
= msi_load_icon( dialog
->package
->db
, name
, attributes
);
1017 SendMessageW( control
->hwnd
, BM_SETIMAGE
, IMAGE_ICON
, (LPARAM
) control
->hIcon
);
1020 ERR("Failed to load icon %s\n", debugstr_w(name
));
1024 return ERROR_SUCCESS
;
1027 static LPWSTR
msi_get_checkbox_value( msi_dialog
*dialog
, LPCWSTR prop
)
1029 static const WCHAR query
[] = {
1030 'S','E','L','E','C','T',' ','*',' ',
1031 'F','R','O','M',' ','`','C','h','e','c','k','B','o','x','`',' ',
1032 'W','H','E','R','E',' ',
1033 '`','P','r','o','p','e','r','t','y','`',' ','=',' ',
1036 MSIRECORD
*rec
= NULL
;
1039 /* find if there is a value associated with the checkbox */
1040 rec
= MSI_QueryGetRecord( dialog
->package
->db
, query
, prop
);
1044 ret
= msi_get_deformatted_field( dialog
->package
, rec
, 2 );
1045 if( ret
&& !ret
[0] )
1050 msiobj_release( &rec
->hdr
);
1054 ret
= msi_dup_property( dialog
->package
->db
, prop
);
1055 if( ret
&& !ret
[0] )
1064 static UINT
msi_dialog_get_checkbox_state( msi_dialog
*dialog
, msi_control
*control
)
1066 WCHAR state
[2] = {0};
1069 msi_get_property( dialog
->package
->db
, control
->property
, state
, &sz
);
1070 return state
[0] ? 1 : 0;
1073 static void msi_dialog_set_checkbox_state( msi_dialog
*dialog
, msi_control
*control
, UINT state
)
1075 static const WCHAR szState
[] = {'1',0};
1078 /* if uncheck then the property is set to NULL */
1081 msi_dialog_set_property( dialog
->package
, control
->property
, NULL
);
1085 /* check for a custom state */
1086 if (control
->value
&& control
->value
[0])
1087 val
= control
->value
;
1091 msi_dialog_set_property( dialog
->package
, control
->property
, val
);
1094 static void msi_dialog_checkbox_sync_state( msi_dialog
*dialog
, msi_control
*control
)
1096 UINT state
= msi_dialog_get_checkbox_state( dialog
, control
);
1097 SendMessageW( control
->hwnd
, BM_SETCHECK
, state
? BST_CHECKED
: BST_UNCHECKED
, 0 );
1100 static UINT
msi_dialog_checkbox_handler( msi_dialog
*dialog
, msi_control
*control
, WPARAM param
)
1104 if (HIWORD(param
) != BN_CLICKED
)
1105 return ERROR_SUCCESS
;
1107 TRACE("clicked checkbox %s, set %s\n", debugstr_w(control
->name
), debugstr_w(control
->property
));
1109 state
= msi_dialog_get_checkbox_state( dialog
, control
);
1110 state
= state
? 0 : 1;
1111 msi_dialog_set_checkbox_state( dialog
, control
, state
);
1112 msi_dialog_checkbox_sync_state( dialog
, control
);
1114 return msi_dialog_button_handler( dialog
, control
, param
);
1117 static UINT
msi_dialog_checkbox_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1119 msi_control
*control
;
1122 TRACE("%p %p\n", dialog
, rec
);
1124 control
= msi_dialog_add_control( dialog
, rec
, szButton
, BS_CHECKBOX
| BS_MULTILINE
| WS_TABSTOP
);
1125 control
->handler
= msi_dialog_checkbox_handler
;
1126 control
->update
= msi_dialog_checkbox_sync_state
;
1127 prop
= MSI_RecordGetString( rec
, 9 );
1130 control
->property
= strdupW( prop
);
1131 control
->value
= msi_get_checkbox_value( dialog
, prop
);
1132 TRACE("control %s value %s\n", debugstr_w(control
->property
), debugstr_w(control
->value
));
1134 msi_dialog_checkbox_sync_state( dialog
, control
);
1135 return ERROR_SUCCESS
;
1138 static UINT
msi_dialog_line_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1142 DWORD style
, exstyle
= 0;
1143 DWORD x
, y
, width
, height
;
1144 msi_control
*control
;
1146 TRACE("%p %p\n", dialog
, rec
);
1148 style
= WS_CHILD
| SS_ETCHEDHORZ
| SS_SUNKEN
;
1150 name
= MSI_RecordGetString( rec
, 2 );
1151 attributes
= MSI_RecordGetInteger( rec
, 8 );
1153 if( attributes
& msidbControlAttributesVisible
)
1154 style
|= WS_VISIBLE
;
1155 if( ~attributes
& msidbControlAttributesEnabled
)
1156 style
|= WS_DISABLED
;
1157 if( attributes
& msidbControlAttributesSunken
)
1158 exstyle
|= WS_EX_CLIENTEDGE
;
1160 dialog_map_events( dialog
, name
);
1162 control
= msi_alloc( FIELD_OFFSET(msi_control
, name
[strlenW( name
) + 1] ));
1164 return ERROR_OUTOFMEMORY
;
1166 strcpyW( control
->name
, name
);
1167 list_add_head( &dialog
->controls
, &control
->entry
);
1168 control
->handler
= NULL
;
1169 control
->property
= NULL
;
1170 control
->value
= NULL
;
1171 control
->hBitmap
= NULL
;
1172 control
->hIcon
= NULL
;
1173 control
->hDll
= NULL
;
1174 control
->tabnext
= strdupW( MSI_RecordGetString( rec
, 11) );
1175 control
->type
= strdupW( MSI_RecordGetString( rec
, 3 ) );
1176 control
->progress_current
= 0;
1177 control
->progress_max
= 100;
1178 control
->progress_backwards
= FALSE
;
1180 x
= MSI_RecordGetInteger( rec
, 4 );
1181 y
= MSI_RecordGetInteger( rec
, 5 );
1182 width
= MSI_RecordGetInteger( rec
, 6 );
1184 x
= msi_dialog_scale_unit( dialog
, x
);
1185 y
= msi_dialog_scale_unit( dialog
, y
);
1186 width
= msi_dialog_scale_unit( dialog
, width
);
1187 height
= 2; /* line is exactly 2 units in height */
1189 control
->hwnd
= CreateWindowExW( exstyle
, szStatic
, NULL
, style
,
1190 x
, y
, width
, height
, dialog
->hwnd
, NULL
, NULL
, NULL
);
1192 TRACE("Dialog %s control %s hwnd %p\n",
1193 debugstr_w(dialog
->name
), debugstr_w(name
), control
->hwnd
);
1195 return ERROR_SUCCESS
;
1198 /******************** Scroll Text ********************************************/
1200 struct msi_scrolltext_info
1203 msi_control
*control
;
1207 static LRESULT WINAPI
1208 MSIScrollText_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1210 struct msi_scrolltext_info
*info
;
1213 TRACE("%p %04x %08lx %08lx\n", hWnd
, msg
, wParam
, lParam
);
1215 info
= GetPropW( hWnd
, szButtonData
);
1217 r
= CallWindowProcW( info
->oldproc
, hWnd
, msg
, wParam
, lParam
);
1222 return DLGC_WANTARROWS
;
1225 RemovePropW( hWnd
, szButtonData
);
1228 /* native MSI sets a wait cursor here */
1229 msi_dialog_button_handler( info
->dialog
, info
->control
, BN_CLICKED
);
1235 struct msi_streamin_info
1242 static DWORD CALLBACK
1243 msi_richedit_stream_in( DWORD_PTR arg
, LPBYTE buffer
, LONG count
, LONG
*pcb
)
1245 struct msi_streamin_info
*info
= (struct msi_streamin_info
*) arg
;
1247 if( (count
+ info
->offset
) > info
->length
)
1248 count
= info
->length
- info
->offset
;
1249 memcpy( buffer
, &info
->string
[ info
->offset
], count
);
1251 info
->offset
+= count
;
1253 TRACE("%d/%d\n", info
->offset
, info
->length
);
1258 static void msi_scrolltext_add_text( msi_control
*control
, LPCWSTR text
)
1260 struct msi_streamin_info info
;
1263 info
.string
= strdupWtoA( text
);
1265 info
.length
= lstrlenA( info
.string
) + 1;
1267 es
.dwCookie
= (DWORD_PTR
) &info
;
1269 es
.pfnCallback
= msi_richedit_stream_in
;
1271 SendMessageW( control
->hwnd
, EM_STREAMIN
, SF_RTF
, (LPARAM
) &es
);
1273 msi_free( info
.string
);
1276 static UINT
msi_dialog_scrolltext_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1278 static const WCHAR szRichEdit20W
[] = {'R','i','c','h','E','d','i','t','2','0','W',0};
1279 struct msi_scrolltext_info
*info
;
1280 msi_control
*control
;
1285 info
= msi_alloc( sizeof *info
);
1287 return ERROR_FUNCTION_FAILED
;
1289 hRichedit
= LoadLibraryA("riched20");
1291 style
= WS_BORDER
| ES_MULTILINE
| WS_VSCROLL
|
1292 ES_READONLY
| ES_AUTOVSCROLL
| WS_TABSTOP
;
1293 control
= msi_dialog_add_control( dialog
, rec
, szRichEdit20W
, style
);
1296 FreeLibrary( hRichedit
);
1298 return ERROR_FUNCTION_FAILED
;
1301 control
->hDll
= hRichedit
;
1303 info
->dialog
= dialog
;
1304 info
->control
= control
;
1306 /* subclass the static control */
1307 info
->oldproc
= (WNDPROC
) SetWindowLongPtrW( control
->hwnd
, GWLP_WNDPROC
,
1308 (LONG_PTR
)MSIScrollText_WndProc
);
1309 SetPropW( control
->hwnd
, szButtonData
, info
);
1311 /* add the text into the richedit */
1312 text
= MSI_RecordGetString( rec
, 10 );
1314 msi_scrolltext_add_text( control
, text
);
1316 return ERROR_SUCCESS
;
1319 static HBITMAP
msi_load_picture( MSIDATABASE
*db
, LPCWSTR name
,
1320 INT cx
, INT cy
, DWORD flags
)
1322 HBITMAP hOleBitmap
= 0, hBitmap
= 0, hOldSrcBitmap
, hOldDestBitmap
;
1323 MSIRECORD
*rec
= NULL
;
1324 IStream
*stm
= NULL
;
1325 IPicture
*pic
= NULL
;
1330 rec
= msi_get_binary_record( db
, name
);
1334 r
= MSI_RecordGetIStream( rec
, 2, &stm
);
1335 msiobj_release( &rec
->hdr
);
1336 if( r
!= ERROR_SUCCESS
)
1339 r
= OleLoadPicture( stm
, 0, TRUE
, &IID_IPicture
, (LPVOID
*) &pic
);
1340 IStream_Release( stm
);
1343 ERR("failed to load picture\n");
1347 r
= IPicture_get_Handle( pic
, (OLE_HANDLE
*) &hOleBitmap
);
1350 ERR("failed to get bitmap handle\n");
1354 /* make the bitmap the desired size */
1355 r
= GetObjectW( hOleBitmap
, sizeof bm
, &bm
);
1356 if (r
!= sizeof bm
)
1358 ERR("failed to get bitmap size\n");
1362 if (flags
& LR_DEFAULTSIZE
)
1368 srcdc
= CreateCompatibleDC( NULL
);
1369 hOldSrcBitmap
= SelectObject( srcdc
, hOleBitmap
);
1370 destdc
= CreateCompatibleDC( NULL
);
1371 hBitmap
= CreateCompatibleBitmap( srcdc
, cx
, cy
);
1372 hOldDestBitmap
= SelectObject( destdc
, hBitmap
);
1373 StretchBlt( destdc
, 0, 0, cx
, cy
,
1374 srcdc
, 0, 0, bm
.bmWidth
, bm
.bmHeight
, SRCCOPY
);
1375 SelectObject( srcdc
, hOldSrcBitmap
);
1376 SelectObject( destdc
, hOldDestBitmap
);
1382 IPicture_Release( pic
);
1386 static UINT
msi_dialog_bitmap_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1388 UINT cx
, cy
, flags
, style
, attributes
;
1389 msi_control
*control
;
1392 flags
= LR_LOADFROMFILE
;
1393 style
= SS_BITMAP
| SS_LEFT
| WS_GROUP
;
1395 attributes
= MSI_RecordGetInteger( rec
, 8 );
1396 if( attributes
& msidbControlAttributesFixedSize
)
1398 flags
|= LR_DEFAULTSIZE
;
1399 style
|= SS_CENTERIMAGE
;
1402 control
= msi_dialog_add_control( dialog
, rec
, szStatic
, style
);
1403 cx
= MSI_RecordGetInteger( rec
, 6 );
1404 cy
= MSI_RecordGetInteger( rec
, 7 );
1405 cx
= msi_dialog_scale_unit( dialog
, cx
);
1406 cy
= msi_dialog_scale_unit( dialog
, cy
);
1408 name
= msi_get_binary_name( dialog
->package
, rec
);
1409 control
->hBitmap
= msi_load_picture( dialog
->package
->db
, name
, cx
, cy
, flags
);
1410 if( control
->hBitmap
)
1411 SendMessageW( control
->hwnd
, STM_SETIMAGE
,
1412 IMAGE_BITMAP
, (LPARAM
) control
->hBitmap
);
1414 ERR("Failed to load bitmap %s\n", debugstr_w(name
));
1418 return ERROR_SUCCESS
;
1421 static UINT
msi_dialog_icon_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1423 msi_control
*control
;
1429 control
= msi_dialog_add_control( dialog
, rec
, szStatic
,
1430 SS_ICON
| SS_CENTERIMAGE
| WS_GROUP
);
1432 attributes
= MSI_RecordGetInteger( rec
, 8 );
1433 name
= msi_get_binary_name( dialog
->package
, rec
);
1434 control
->hIcon
= msi_load_icon( dialog
->package
->db
, name
, attributes
);
1435 if( control
->hIcon
)
1436 SendMessageW( control
->hwnd
, STM_SETICON
, (WPARAM
) control
->hIcon
, 0 );
1438 ERR("Failed to load bitmap %s\n", debugstr_w(name
));
1440 return ERROR_SUCCESS
;
1443 /******************** Combo Box ***************************************/
1445 struct msi_combobox_info
1455 static LRESULT WINAPI
MSIComboBox_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1457 struct msi_combobox_info
*info
;
1461 TRACE("%p %04x %08lx %08lx\n", hWnd
, msg
, wParam
, lParam
);
1463 info
= GetPropW( hWnd
, szButtonData
);
1467 r
= CallWindowProcW( info
->oldproc
, hWnd
, msg
, wParam
, lParam
);
1472 for (j
= 0; j
< info
->num_items
; j
++)
1473 msi_free( info
->items
[j
] );
1474 msi_free( info
->items
);
1476 RemovePropW( hWnd
, szButtonData
);
1483 static UINT
msi_combobox_add_item( MSIRECORD
*rec
, LPVOID param
)
1485 struct msi_combobox_info
*info
= param
;
1486 LPCWSTR value
, text
;
1489 value
= MSI_RecordGetString( rec
, 3 );
1490 text
= MSI_RecordGetString( rec
, 4 );
1492 info
->items
[info
->addpos_items
] = strdupW( value
);
1494 pos
= SendMessageW( info
->hwnd
, CB_ADDSTRING
, 0, (LPARAM
)text
);
1495 SendMessageW( info
->hwnd
, CB_SETITEMDATA
, pos
, (LPARAM
)info
->items
[info
->addpos_items
] );
1496 info
->addpos_items
++;
1498 return ERROR_SUCCESS
;
1501 static UINT
msi_combobox_add_items( struct msi_combobox_info
*info
, LPCWSTR property
)
1503 static const WCHAR query
[] = {
1504 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
1505 '`','C','o','m','b','o','B','o','x','`',' ','W','H','E','R','E',' ',
1506 '`','P','r','o','p','e','r','t','y','`',' ','=',' ','\'','%','s','\'',' ',
1507 'O','R','D','E','R',' ','B','Y',' ','`','O','r','d','e','r','`',0};
1512 r
= MSI_OpenQuery( info
->dialog
->package
->db
, &view
, query
, property
);
1513 if (r
!= ERROR_SUCCESS
)
1516 /* just get the number of records */
1518 r
= MSI_IterateRecords( view
, &count
, NULL
, NULL
);
1519 if (r
!= ERROR_SUCCESS
)
1521 msiobj_release( &view
->hdr
);
1524 info
->num_items
= count
;
1525 info
->items
= msi_alloc( sizeof(*info
->items
) * count
);
1527 r
= MSI_IterateRecords( view
, NULL
, msi_combobox_add_item
, info
);
1528 msiobj_release( &view
->hdr
);
1532 static UINT
msi_dialog_set_control_condition( MSIRECORD
*rec
, LPVOID param
)
1534 static const WCHAR szHide
[] = {'H','i','d','e',0};
1535 static const WCHAR szShow
[] = {'S','h','o','w',0};
1536 static const WCHAR szDisable
[] = {'D','i','s','a','b','l','e',0};
1537 static const WCHAR szEnable
[] = {'E','n','a','b','l','e',0};
1538 static const WCHAR szDefault
[] = {'D','e','f','a','u','l','t',0};
1539 msi_dialog
*dialog
= param
;
1540 msi_control
*control
;
1541 LPCWSTR name
, action
, condition
;
1544 name
= MSI_RecordGetString( rec
, 2 );
1545 action
= MSI_RecordGetString( rec
, 3 );
1546 condition
= MSI_RecordGetString( rec
, 4 );
1547 r
= MSI_EvaluateConditionW( dialog
->package
, condition
);
1548 control
= msi_dialog_find_control( dialog
, name
);
1549 if (r
== MSICONDITION_TRUE
&& control
)
1551 TRACE("%s control %s\n", debugstr_w(action
), debugstr_w(name
));
1553 /* FIXME: case sensitive? */
1554 if (!strcmpW( action
, szHide
))
1555 ShowWindow(control
->hwnd
, SW_HIDE
);
1556 else if (!strcmpW( action
, szShow
))
1557 ShowWindow(control
->hwnd
, SW_SHOW
);
1558 else if (!strcmpW( action
, szDisable
))
1559 EnableWindow(control
->hwnd
, FALSE
);
1560 else if (!strcmpW( action
, szEnable
))
1561 EnableWindow(control
->hwnd
, TRUE
);
1562 else if (!strcmpW( action
, szDefault
))
1563 SetFocus(control
->hwnd
);
1565 FIXME("Unhandled action %s\n", debugstr_w(action
));
1567 return ERROR_SUCCESS
;
1570 static UINT
msi_dialog_evaluate_control_conditions( msi_dialog
*dialog
)
1572 static const WCHAR query
[] = {
1573 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
1574 'C','o','n','t','r','o','l','C','o','n','d','i','t','i','o','n',' ',
1575 'W','H','E','R','E',' ','`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',0};
1578 MSIPACKAGE
*package
= dialog
->package
;
1580 TRACE("%p %s\n", dialog
, debugstr_w(dialog
->name
));
1582 /* query the Control table for all the elements of the control */
1583 r
= MSI_OpenQuery( package
->db
, &view
, query
, dialog
->name
);
1584 if (r
!= ERROR_SUCCESS
)
1585 return ERROR_SUCCESS
;
1587 r
= MSI_IterateRecords( view
, 0, msi_dialog_set_control_condition
, dialog
);
1588 msiobj_release( &view
->hdr
);
1592 static UINT
msi_dialog_combobox_handler( msi_dialog
*dialog
, msi_control
*control
, WPARAM param
)
1594 struct msi_combobox_info
*info
;
1598 if (HIWORD(param
) != CBN_SELCHANGE
&& HIWORD(param
) != CBN_EDITCHANGE
)
1599 return ERROR_SUCCESS
;
1601 info
= GetPropW( control
->hwnd
, szButtonData
);
1602 index
= SendMessageW( control
->hwnd
, CB_GETCURSEL
, 0, 0 );
1603 if (index
== CB_ERR
)
1604 value
= msi_get_window_text( control
->hwnd
);
1606 value
= (LPWSTR
) SendMessageW( control
->hwnd
, CB_GETITEMDATA
, index
, 0 );
1608 msi_dialog_set_property( info
->dialog
->package
, control
->property
, value
);
1609 msi_dialog_evaluate_control_conditions( info
->dialog
);
1611 if (index
== CB_ERR
)
1614 return ERROR_SUCCESS
;
1617 static void msi_dialog_combobox_update( msi_dialog
*dialog
, msi_control
*control
)
1619 struct msi_combobox_info
*info
;
1623 info
= GetPropW( control
->hwnd
, szButtonData
);
1625 value
= msi_dup_property( dialog
->package
->db
, control
->property
);
1628 SendMessageW( control
->hwnd
, CB_SETCURSEL
, -1, 0 );
1632 for (j
= 0; j
< info
->num_items
; j
++)
1634 tmp
= (LPWSTR
) SendMessageW( control
->hwnd
, CB_GETITEMDATA
, j
, 0 );
1635 if (!strcmpW( value
, tmp
))
1639 if (j
< info
->num_items
)
1641 SendMessageW( control
->hwnd
, CB_SETCURSEL
, j
, 0 );
1645 SendMessageW( control
->hwnd
, CB_SETCURSEL
, -1, 0 );
1646 SetWindowTextW( control
->hwnd
, value
);
1652 static UINT
msi_dialog_combo_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1654 struct msi_combobox_info
*info
;
1655 msi_control
*control
;
1656 DWORD attributes
, style
;
1659 info
= msi_alloc( sizeof *info
);
1661 return ERROR_FUNCTION_FAILED
;
1663 style
= CBS_AUTOHSCROLL
| WS_TABSTOP
| WS_GROUP
| WS_CHILD
;
1664 attributes
= MSI_RecordGetInteger( rec
, 8 );
1665 if ( ~attributes
& msidbControlAttributesSorted
)
1667 if ( attributes
& msidbControlAttributesComboList
)
1668 style
|= CBS_DROPDOWNLIST
;
1670 style
|= CBS_DROPDOWN
;
1672 control
= msi_dialog_add_control( dialog
, rec
, WC_COMBOBOXW
, style
);
1676 return ERROR_FUNCTION_FAILED
;
1679 control
->handler
= msi_dialog_combobox_handler
;
1680 control
->update
= msi_dialog_combobox_update
;
1682 prop
= MSI_RecordGetString( rec
, 9 );
1683 control
->property
= msi_dialog_dup_property( dialog
, prop
, FALSE
);
1686 info
->dialog
= dialog
;
1687 info
->hwnd
= control
->hwnd
;
1689 info
->addpos_items
= 0;
1690 info
->oldproc
= (WNDPROC
)SetWindowLongPtrW( control
->hwnd
, GWLP_WNDPROC
,
1691 (LONG_PTR
)MSIComboBox_WndProc
);
1692 SetPropW( control
->hwnd
, szButtonData
, info
);
1694 if (control
->property
)
1695 msi_combobox_add_items( info
, control
->property
);
1697 msi_dialog_combobox_update( dialog
, control
);
1699 return ERROR_SUCCESS
;
1702 static UINT
msi_dialog_edit_handler( msi_dialog
*dialog
, msi_control
*control
, WPARAM param
)
1706 if (HIWORD(param
) != EN_CHANGE
)
1707 return ERROR_SUCCESS
;
1709 TRACE("edit %s contents changed, set %s\n", debugstr_w(control
->name
), debugstr_w(control
->property
));
1711 buf
= msi_get_window_text( control
->hwnd
);
1712 msi_dialog_set_property( dialog
->package
, control
->property
, buf
);
1715 return ERROR_SUCCESS
;
1718 /* length of 2^32 + 1 */
1719 #define MAX_NUM_DIGITS 11
1721 static UINT
msi_dialog_edit_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1723 msi_control
*control
;
1725 LPWSTR val
, begin
, end
;
1726 WCHAR num
[MAX_NUM_DIGITS
];
1729 control
= msi_dialog_add_control( dialog
, rec
, szEdit
,
1730 WS_BORDER
| WS_TABSTOP
| ES_AUTOHSCROLL
);
1731 control
->handler
= msi_dialog_edit_handler
;
1733 text
= MSI_RecordGetString( rec
, 10 );
1736 begin
= strchrW( text
, '{' );
1737 end
= strchrW( text
, '}' );
1739 if ( begin
&& end
&& end
> begin
&&
1740 begin
[0] >= '0' && begin
[0] <= '9' &&
1741 end
- begin
< MAX_NUM_DIGITS
)
1743 lstrcpynW( num
, begin
+ 1, end
- begin
);
1744 limit
= atolW( num
);
1746 SendMessageW( control
->hwnd
, EM_SETLIMITTEXT
, limit
, 0 );
1750 prop
= MSI_RecordGetString( rec
, 9 );
1752 control
->property
= strdupW( prop
);
1754 val
= msi_dup_property( dialog
->package
->db
, control
->property
);
1755 SetWindowTextW( control
->hwnd
, val
);
1757 return ERROR_SUCCESS
;
1760 /******************** Masked Edit ********************************************/
1762 #define MASK_MAX_GROUPS 20
1764 struct msi_mask_group
1772 struct msi_maskedit_info
1780 struct msi_mask_group group
[MASK_MAX_GROUPS
];
1783 static BOOL
msi_mask_editable( WCHAR type
)
1798 static void msi_mask_control_change( struct msi_maskedit_info
*info
)
1803 val
= msi_alloc( (info
->num_chars
+1)*sizeof(WCHAR
) );
1804 for( i
=0, n
=0; i
<info
->num_groups
; i
++ )
1806 if (info
->group
[i
].len
== ~0u)
1808 UINT len
= SendMessageW( info
->group
[i
].hwnd
, WM_GETTEXTLENGTH
, 0, 0 );
1809 val
= msi_realloc( val
, (len
+ 1) * sizeof(WCHAR
) );
1810 GetWindowTextW( info
->group
[i
].hwnd
, val
, len
+ 1 );
1814 if (info
->group
[i
].len
+ n
> info
->num_chars
)
1816 ERR("can't fit control %d text into template\n",i
);
1819 if (!msi_mask_editable(info
->group
[i
].type
))
1821 for(r
=0; r
<info
->group
[i
].len
; r
++)
1822 val
[n
+r
] = info
->group
[i
].type
;
1827 r
= GetWindowTextW( info
->group
[i
].hwnd
, &val
[n
], info
->group
[i
].len
+1 );
1828 if( r
!= info
->group
[i
].len
)
1835 TRACE("%d/%d controls were good\n", i
, info
->num_groups
);
1837 if( i
== info
->num_groups
)
1839 TRACE("Set property %s to %s\n", debugstr_w(info
->prop
), debugstr_w(val
));
1840 msi_dialog_set_property( info
->dialog
->package
, info
->prop
, val
);
1841 msi_dialog_evaluate_control_conditions( info
->dialog
);
1846 /* now move to the next control if necessary */
1847 static VOID
msi_mask_next_control( struct msi_maskedit_info
*info
, HWND hWnd
)
1852 for( i
=0; i
<info
->num_groups
; i
++ )
1853 if( info
->group
[i
].hwnd
== hWnd
)
1856 /* don't move from the last control */
1857 if( i
>= (info
->num_groups
-1) )
1860 len
= SendMessageW( hWnd
, WM_GETTEXTLENGTH
, 0, 0 );
1861 if( len
< info
->group
[i
].len
)
1864 hWndNext
= GetNextDlgTabItem( GetParent( hWnd
), hWnd
, FALSE
);
1865 SetFocus( hWndNext
);
1868 static LRESULT WINAPI
1869 MSIMaskedEdit_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1871 struct msi_maskedit_info
*info
;
1874 TRACE("%p %04x %08lx %08lx\n", hWnd
, msg
, wParam
, lParam
);
1876 info
= GetPropW(hWnd
, szButtonData
);
1878 r
= CallWindowProcW(info
->oldproc
, hWnd
, msg
, wParam
, lParam
);
1883 if (HIWORD(wParam
) == EN_CHANGE
)
1885 msi_mask_control_change( info
);
1886 msi_mask_next_control( info
, (HWND
) lParam
);
1890 msi_free( info
->prop
);
1892 RemovePropW( hWnd
, szButtonData
);
1899 /* fish the various bits of the property out and put them in the control */
1901 msi_maskedit_set_text( struct msi_maskedit_info
*info
, LPCWSTR text
)
1907 for( i
= 0; i
< info
->num_groups
; i
++ )
1909 if( info
->group
[i
].len
< strlenW( p
) )
1911 LPWSTR chunk
= strdupW( p
);
1912 chunk
[ info
->group
[i
].len
] = 0;
1913 SetWindowTextW( info
->group
[i
].hwnd
, chunk
);
1918 SetWindowTextW( info
->group
[i
].hwnd
, p
);
1921 p
+= info
->group
[i
].len
;
1925 static struct msi_maskedit_info
* msi_dialog_parse_groups( LPCWSTR mask
)
1927 struct msi_maskedit_info
*info
;
1928 int i
= 0, n
= 0, total
= 0;
1931 TRACE("masked control, template %s\n", debugstr_w(mask
));
1936 info
= msi_alloc_zero( sizeof *info
);
1940 p
= strchrW(mask
, '<');
1946 for( i
=0; i
<MASK_MAX_GROUPS
; i
++ )
1948 /* stop at the end of the string */
1949 if( p
[0] == 0 || p
[0] == '>' )
1953 /* create a group for the empty mask */
1954 info
->group
[0].type
= '&';
1955 info
->group
[0].len
= ~0u;
1961 /* count the number of the same identifier */
1962 for( n
=0; p
[n
] == p
[0]; n
++ )
1964 info
->group
[i
].ofs
= total
;
1965 info
->group
[i
].type
= p
[0];
1969 total
++; /* an extra not part of the group */
1971 info
->group
[i
].len
= n
;
1976 TRACE("%d characters in %d groups\n", total
, i
);
1977 if( i
== MASK_MAX_GROUPS
)
1978 ERR("too many groups in PIDTemplate %s\n", debugstr_w(mask
));
1980 info
->num_chars
= total
;
1981 info
->num_groups
= i
;
1987 msi_maskedit_create_children( struct msi_maskedit_info
*info
, LPCWSTR font
)
1989 DWORD width
, height
, style
, wx
, ww
;
1994 style
= WS_CHILD
| WS_BORDER
| WS_VISIBLE
| WS_TABSTOP
| ES_AUTOHSCROLL
;
1996 GetClientRect( info
->hwnd
, &rect
);
1998 width
= rect
.right
- rect
.left
;
1999 height
= rect
.bottom
- rect
.top
;
2001 for( i
= 0; i
< info
->num_groups
; i
++ )
2003 if (!msi_mask_editable( info
->group
[i
].type
))
2005 if (info
->num_chars
)
2007 wx
= (info
->group
[i
].ofs
* width
) / info
->num_chars
;
2008 ww
= (info
->group
[i
].len
* width
) / info
->num_chars
;
2015 hwnd
= CreateWindowW( szEdit
, NULL
, style
, wx
, 0, ww
, height
,
2016 info
->hwnd
, NULL
, NULL
, NULL
);
2019 ERR("failed to create mask edit sub window\n");
2023 SendMessageW( hwnd
, EM_LIMITTEXT
, info
->group
[i
].len
, 0 );
2025 msi_dialog_set_font( info
->dialog
, hwnd
,
2026 font
?font
:info
->dialog
->default_font
);
2027 info
->group
[i
].hwnd
= hwnd
;
2032 * office 2003 uses "73931<````=````=````=````=`````>@@@@@"
2033 * delphi 7 uses "<????-??????-??????-????>" and "<???-???>"
2034 * filemaker pro 7 uses "<^^^^=^^^^=^^^^=^^^^=^^^^=^^^^=^^^^^>"
2036 static UINT
msi_dialog_maskedit_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
2038 LPWSTR font_mask
, val
= NULL
, font
;
2039 struct msi_maskedit_info
*info
= NULL
;
2040 UINT ret
= ERROR_SUCCESS
;
2041 msi_control
*control
;
2046 font_mask
= msi_get_deformatted_field( dialog
->package
, rec
, 10 );
2047 font
= msi_dialog_get_style( font_mask
, &mask
);
2050 WARN("mask template is empty\n");
2054 info
= msi_dialog_parse_groups( mask
);
2057 ERR("template %s is invalid\n", debugstr_w(mask
));
2061 info
->dialog
= dialog
;
2063 control
= msi_dialog_add_control( dialog
, rec
, szStatic
,
2064 SS_OWNERDRAW
| WS_GROUP
| WS_VISIBLE
);
2067 ERR("Failed to create maskedit container\n");
2068 ret
= ERROR_FUNCTION_FAILED
;
2071 SetWindowLongPtrW( control
->hwnd
, GWL_EXSTYLE
, WS_EX_CONTROLPARENT
);
2073 info
->hwnd
= control
->hwnd
;
2075 /* subclass the static control */
2076 info
->oldproc
= (WNDPROC
) SetWindowLongPtrW( info
->hwnd
, GWLP_WNDPROC
,
2077 (LONG_PTR
)MSIMaskedEdit_WndProc
);
2078 SetPropW( control
->hwnd
, szButtonData
, info
);
2080 prop
= MSI_RecordGetString( rec
, 9 );
2082 info
->prop
= strdupW( prop
);
2084 msi_maskedit_create_children( info
, font
);
2088 val
= msi_dup_property( dialog
->package
->db
, prop
);
2091 msi_maskedit_set_text( info
, val
);
2097 if( ret
!= ERROR_SUCCESS
)
2099 msi_free( font_mask
);
2104 /******************** Progress Bar *****************************************/
2106 static UINT
msi_dialog_progress_bar( msi_dialog
*dialog
, MSIRECORD
*rec
)
2108 msi_control
*control
;
2109 DWORD attributes
, style
;
2112 attributes
= MSI_RecordGetInteger( rec
, 8 );
2113 if( !(attributes
& msidbControlAttributesProgress95
) )
2114 style
|= PBS_SMOOTH
;
2116 control
= msi_dialog_add_control( dialog
, rec
, PROGRESS_CLASSW
, style
);
2118 return ERROR_FUNCTION_FAILED
;
2120 event_subscribe( dialog
, szSetProgress
, control
->name
, szProgress
);
2121 return ERROR_SUCCESS
;
2124 /******************** Path Edit ********************************************/
2126 struct msi_pathedit_info
2129 msi_control
*control
;
2133 static void msi_dialog_update_pathedit( msi_dialog
*dialog
, msi_control
*control
)
2138 if (!control
&& !(control
= msi_dialog_find_control_by_type( dialog
, szPathEdit
)))
2141 indirect
= control
->attributes
& msidbControlAttributesIndirect
;
2142 prop
= msi_dialog_dup_property( dialog
, control
->property
, indirect
);
2143 path
= msi_dialog_dup_property( dialog
, prop
, TRUE
);
2145 SetWindowTextW( control
->hwnd
, path
);
2146 SendMessageW( control
->hwnd
, EM_SETSEL
, 0, -1 );
2152 /* FIXME: test when this should fail */
2153 static BOOL
msi_dialog_verify_path( LPWSTR path
)
2155 if ( !lstrlenW( path
) )
2158 if ( PathIsRelativeW( path
) )
2164 /* returns TRUE if the path is valid, FALSE otherwise */
2165 static BOOL
msi_dialog_onkillfocus( msi_dialog
*dialog
, msi_control
*control
)
2171 indirect
= control
->attributes
& msidbControlAttributesIndirect
;
2172 prop
= msi_dialog_dup_property( dialog
, control
->property
, indirect
);
2174 buf
= msi_get_window_text( control
->hwnd
);
2176 if ( !msi_dialog_verify_path( buf
) )
2178 /* FIXME: display an error message box */
2179 ERR("Invalid path %s\n", debugstr_w( buf
));
2181 SetFocus( control
->hwnd
);
2186 msi_dialog_set_property( dialog
->package
, prop
, buf
);
2189 msi_dialog_update_pathedit( dialog
, control
);
2191 TRACE("edit %s contents changed, set %s\n", debugstr_w(control
->name
),
2200 static LRESULT WINAPI
MSIPathEdit_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
2202 struct msi_pathedit_info
*info
= GetPropW(hWnd
, szButtonData
);
2205 TRACE("%p %04x %08lx %08lx\n", hWnd
, msg
, wParam
, lParam
);
2207 if ( msg
== WM_KILLFOCUS
)
2209 /* if the path is invalid, don't handle this message */
2210 if ( !msi_dialog_onkillfocus( info
->dialog
, info
->control
) )
2214 r
= CallWindowProcW(info
->oldproc
, hWnd
, msg
, wParam
, lParam
);
2216 if ( msg
== WM_NCDESTROY
)
2219 RemovePropW( hWnd
, szButtonData
);
2225 static UINT
msi_dialog_pathedit_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
2227 struct msi_pathedit_info
*info
;
2228 msi_control
*control
;
2231 info
= msi_alloc( sizeof *info
);
2233 return ERROR_FUNCTION_FAILED
;
2235 control
= msi_dialog_add_control( dialog
, rec
, szEdit
,
2236 WS_BORDER
| WS_TABSTOP
);
2237 control
->attributes
= MSI_RecordGetInteger( rec
, 8 );
2238 prop
= MSI_RecordGetString( rec
, 9 );
2239 control
->property
= msi_dialog_dup_property( dialog
, prop
, FALSE
);
2241 info
->dialog
= dialog
;
2242 info
->control
= control
;
2243 info
->oldproc
= (WNDPROC
) SetWindowLongPtrW( control
->hwnd
, GWLP_WNDPROC
,
2244 (LONG_PTR
)MSIPathEdit_WndProc
);
2245 SetPropW( control
->hwnd
, szButtonData
, info
);
2247 msi_dialog_update_pathedit( dialog
, control
);
2249 return ERROR_SUCCESS
;
2252 static UINT
msi_dialog_radiogroup_handler( msi_dialog
*dialog
, msi_control
*control
, WPARAM param
)
2254 if (HIWORD(param
) != BN_CLICKED
)
2255 return ERROR_SUCCESS
;
2257 TRACE("clicked radio button %s, set %s\n", debugstr_w(control
->name
), debugstr_w(control
->property
));
2259 msi_dialog_set_property( dialog
->package
, control
->property
, control
->name
);
2261 return msi_dialog_button_handler( dialog
, control
, param
);
2264 /* radio buttons are a bit different from normal controls */
2265 static UINT
msi_dialog_create_radiobutton( MSIRECORD
*rec
, LPVOID param
)
2267 radio_button_group_descr
*group
= param
;
2268 msi_dialog
*dialog
= group
->dialog
;
2269 msi_control
*control
;
2270 LPCWSTR prop
, text
, name
;
2271 DWORD style
, attributes
= group
->attributes
;
2273 style
= WS_CHILD
| BS_AUTORADIOBUTTON
| BS_MULTILINE
| WS_TABSTOP
;
2274 name
= MSI_RecordGetString( rec
, 3 );
2275 text
= MSI_RecordGetString( rec
, 8 );
2276 if( attributes
& msidbControlAttributesVisible
)
2277 style
|= WS_VISIBLE
;
2278 if( ~attributes
& msidbControlAttributesEnabled
)
2279 style
|= WS_DISABLED
;
2281 control
= dialog_create_window( dialog
, rec
, 0, szButton
, name
, text
, style
,
2282 group
->parent
->hwnd
);
2284 return ERROR_FUNCTION_FAILED
;
2285 control
->handler
= msi_dialog_radiogroup_handler
;
2287 if (group
->propval
&& !strcmpW( control
->name
, group
->propval
))
2288 SendMessageW(control
->hwnd
, BM_SETCHECK
, BST_CHECKED
, 0);
2290 prop
= MSI_RecordGetString( rec
, 1 );
2292 control
->property
= strdupW( prop
);
2294 return ERROR_SUCCESS
;
2297 static BOOL CALLBACK
msi_radioground_child_enum( HWND hWnd
, LPARAM lParam
)
2299 EnableWindow( hWnd
, lParam
);
2303 static LRESULT WINAPI
MSIRadioGroup_WndProc( HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
2305 WNDPROC oldproc
= (WNDPROC
)GetPropW( hWnd
, szButtonData
);
2308 TRACE("hWnd %p msg %04x wParam 0x%08lx lParam 0x%08lx\n", hWnd
, msg
, wParam
, lParam
);
2310 if (msg
== WM_COMMAND
) /* Forward notifications to dialog */
2311 SendMessageW( GetParent( hWnd
), msg
, wParam
, lParam
);
2313 r
= CallWindowProcW( oldproc
, hWnd
, msg
, wParam
, lParam
);
2315 /* make sure the radio buttons show as disabled if the parent is disabled */
2316 if (msg
== WM_ENABLE
)
2317 EnumChildWindows( hWnd
, msi_radioground_child_enum
, wParam
);
2322 static UINT
msi_dialog_radiogroup_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
2324 static const WCHAR query
[] = {
2325 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2326 'R','a','d','i','o','B','u','t','t','o','n',' ','W','H','E','R','E',' ',
2327 '`','P','r','o','p','e','r','t','y','`',' ','=',' ','\'','%','s','\'',0};
2330 msi_control
*control
;
2332 radio_button_group_descr group
;
2333 MSIPACKAGE
*package
= dialog
->package
;
2335 DWORD attr
, style
= WS_GROUP
;
2337 prop
= MSI_RecordGetString( rec
, 9 );
2339 TRACE("%p %p %s\n", dialog
, rec
, debugstr_w( prop
));
2341 attr
= MSI_RecordGetInteger( rec
, 8 );
2342 if (attr
& msidbControlAttributesHasBorder
)
2343 style
|= BS_GROUPBOX
;
2345 style
|= BS_OWNERDRAW
;
2347 /* Create parent group box to hold radio buttons */
2348 control
= msi_dialog_add_control( dialog
, rec
, szButton
, style
);
2350 return ERROR_FUNCTION_FAILED
;
2352 oldproc
= (WNDPROC
) SetWindowLongPtrW( control
->hwnd
, GWLP_WNDPROC
,
2353 (LONG_PTR
)MSIRadioGroup_WndProc
);
2354 SetPropW(control
->hwnd
, szButtonData
, oldproc
);
2355 SetWindowLongPtrW( control
->hwnd
, GWL_EXSTYLE
, WS_EX_CONTROLPARENT
);
2358 control
->property
= strdupW( prop
);
2360 /* query the Radio Button table for all control in this group */
2361 r
= MSI_OpenQuery( package
->db
, &view
, query
, prop
);
2362 if( r
!= ERROR_SUCCESS
)
2364 ERR("query failed for dialog %s radio group %s\n",
2365 debugstr_w(dialog
->name
), debugstr_w(prop
));
2366 return ERROR_INVALID_PARAMETER
;
2369 group
.dialog
= dialog
;
2370 group
.parent
= control
;
2371 group
.attributes
= MSI_RecordGetInteger( rec
, 8 );
2372 group
.propval
= msi_dup_property( dialog
->package
->db
, control
->property
);
2374 r
= MSI_IterateRecords( view
, 0, msi_dialog_create_radiobutton
, &group
);
2375 msiobj_release( &view
->hdr
);
2376 msi_free( group
.propval
);
2381 msi_seltree_sync_item_state( HWND hwnd
, MSIFEATURE
*feature
, HTREEITEM hItem
)
2384 DWORD index
= feature
->ActionRequest
;
2386 TRACE("Feature %s -> %d %d %d\n", debugstr_w(feature
->Title
),
2387 feature
->Installed
, feature
->Action
, feature
->ActionRequest
);
2389 if (index
== INSTALLSTATE_UNKNOWN
)
2390 index
= INSTALLSTATE_ABSENT
;
2392 tvi
.mask
= TVIF_STATE
;
2394 tvi
.state
= INDEXTOSTATEIMAGEMASK( index
);
2395 tvi
.stateMask
= TVIS_STATEIMAGEMASK
;
2397 SendMessageW( hwnd
, TVM_SETITEMW
, 0, (LPARAM
) &tvi
);
2401 msi_seltree_popup_menu( HWND hwnd
, INT x
, INT y
)
2406 /* create a menu to display */
2407 hMenu
= CreatePopupMenu();
2409 /* FIXME: load strings from resources */
2410 AppendMenuA( hMenu
, MF_ENABLED
, INSTALLSTATE_LOCAL
, "Install feature locally");
2411 AppendMenuA( hMenu
, MF_ENABLED
, USER_INSTALLSTATE_ALL
, "Install entire feature");
2412 AppendMenuA( hMenu
, MF_ENABLED
, INSTALLSTATE_ADVERTISED
, "Install on demand");
2413 AppendMenuA( hMenu
, MF_ENABLED
, INSTALLSTATE_ABSENT
, "Don't install");
2414 r
= TrackPopupMenu( hMenu
, TPM_LEFTALIGN
| TPM_TOPALIGN
| TPM_RETURNCMD
,
2415 x
, y
, 0, hwnd
, NULL
);
2416 DestroyMenu( hMenu
);
2421 msi_seltree_update_feature_installstate( HWND hwnd
, HTREEITEM hItem
,
2422 MSIPACKAGE
*package
, MSIFEATURE
*feature
, INSTALLSTATE state
)
2424 feature
->ActionRequest
= state
;
2425 msi_seltree_sync_item_state( hwnd
, feature
, hItem
);
2426 ACTION_UpdateComponentStates( package
, feature
);
2430 msi_seltree_update_siblings_and_children_installstate( HWND hwnd
, HTREEITEM curr
,
2431 MSIPACKAGE
*package
, INSTALLSTATE state
)
2433 /* update all siblings */
2436 MSIFEATURE
*feature
;
2439 feature
= msi_seltree_feature_from_item( hwnd
, curr
);
2440 msi_seltree_update_feature_installstate( hwnd
, curr
, package
, feature
, state
);
2442 /* update this sibling's children */
2443 child
= (HTREEITEM
)SendMessageW( hwnd
, TVM_GETNEXTITEM
, (WPARAM
)TVGN_CHILD
, (LPARAM
)curr
);
2445 msi_seltree_update_siblings_and_children_installstate( hwnd
, child
,
2448 while ((curr
= (HTREEITEM
)SendMessageW( hwnd
, TVM_GETNEXTITEM
, (WPARAM
)TVGN_NEXT
, (LPARAM
)curr
)));
2452 msi_seltree_menu( HWND hwnd
, HTREEITEM hItem
)
2454 struct msi_selection_tree_info
*info
;
2455 MSIFEATURE
*feature
;
2456 MSIPACKAGE
*package
;
2464 info
= GetPropW(hwnd
, szButtonData
);
2465 package
= info
->dialog
->package
;
2467 feature
= msi_seltree_feature_from_item( hwnd
, hItem
);
2470 ERR("item %p feature was NULL\n", hItem
);
2474 /* get the item's rectangle to put the menu just below it */
2476 SendMessageW( hwnd
, TVM_GETITEMRECT
, 0, (LPARAM
) &u
.rc
);
2477 MapWindowPoints( hwnd
, NULL
, u
.pt
, 2 );
2479 r
= msi_seltree_popup_menu( hwnd
, u
.rc
.left
, u
.rc
.top
);
2483 case USER_INSTALLSTATE_ALL
:
2484 r
= INSTALLSTATE_LOCAL
;
2486 case INSTALLSTATE_ADVERTISED
:
2487 case INSTALLSTATE_ABSENT
:
2490 child
= (HTREEITEM
)SendMessageW( hwnd
, TVM_GETNEXTITEM
, (WPARAM
)TVGN_CHILD
, (LPARAM
)hItem
);
2492 msi_seltree_update_siblings_and_children_installstate( hwnd
, child
, package
, r
);
2495 case INSTALLSTATE_LOCAL
:
2496 msi_seltree_update_feature_installstate( hwnd
, hItem
, package
, feature
, r
);
2503 static LRESULT WINAPI
2504 MSISelectionTree_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
2506 struct msi_selection_tree_info
*info
;
2507 TVHITTESTINFO tvhti
;
2510 TRACE("%p %04x %08lx %08lx\n", hWnd
, msg
, wParam
, lParam
);
2512 info
= GetPropW(hWnd
, szButtonData
);
2516 case WM_LBUTTONDOWN
:
2517 tvhti
.pt
.x
= (short)LOWORD( lParam
);
2518 tvhti
.pt
.y
= (short)HIWORD( lParam
);
2521 CallWindowProcW(info
->oldproc
, hWnd
, TVM_HITTEST
, 0, (LPARAM
) &tvhti
);
2522 if (tvhti
.flags
& TVHT_ONITEMSTATEICON
)
2523 return msi_seltree_menu( hWnd
, tvhti
.hItem
);
2526 r
= CallWindowProcW(info
->oldproc
, hWnd
, msg
, wParam
, lParam
);
2532 RemovePropW( hWnd
, szButtonData
);
2539 msi_seltree_add_child_features( MSIPACKAGE
*package
, HWND hwnd
,
2540 LPCWSTR parent
, HTREEITEM hParent
)
2542 struct msi_selection_tree_info
*info
= GetPropW( hwnd
, szButtonData
);
2543 MSIFEATURE
*feature
;
2544 TVINSERTSTRUCTW tvis
;
2545 HTREEITEM hitem
, hfirst
= NULL
;
2547 LIST_FOR_EACH_ENTRY( feature
, &package
->features
, MSIFEATURE
, entry
)
2549 if ( parent
&& feature
->Feature_Parent
&& strcmpW( parent
, feature
->Feature_Parent
))
2551 else if ( parent
&& !feature
->Feature_Parent
)
2553 else if ( !parent
&& feature
->Feature_Parent
)
2556 if ( !feature
->Title
)
2559 if ( !feature
->Display
)
2562 memset( &tvis
, 0, sizeof tvis
);
2563 tvis
.hParent
= hParent
;
2564 tvis
.hInsertAfter
= TVI_LAST
;
2565 tvis
.u
.item
.mask
= TVIF_TEXT
| TVIF_PARAM
;
2566 tvis
.u
.item
.pszText
= feature
->Title
;
2567 tvis
.u
.item
.lParam
= (LPARAM
) feature
;
2569 hitem
= (HTREEITEM
) SendMessageW( hwnd
, TVM_INSERTITEMW
, 0, (LPARAM
) &tvis
);
2576 msi_seltree_sync_item_state( hwnd
, feature
, hitem
);
2577 msi_seltree_add_child_features( package
, hwnd
,
2578 feature
->Feature
, hitem
);
2580 /* the node is expanded if Display is odd */
2581 if ( feature
->Display
% 2 != 0 )
2582 SendMessageW( hwnd
, TVM_EXPAND
, TVE_EXPAND
, (LPARAM
) hitem
);
2585 /* select the first item */
2586 SendMessageW( hwnd
, TVM_SELECTITEM
, TVGN_CARET
| TVGN_DROPHILITE
, (LPARAM
) hfirst
);
2587 info
->selected
= hfirst
;
2590 static void msi_seltree_create_imagelist( HWND hwnd
)
2592 const int bm_width
= 32, bm_height
= 16, bm_count
= 3;
2593 const int bm_resource
= 0x1001;
2598 himl
= ImageList_Create( bm_width
, bm_height
, FALSE
, 4, 0 );
2601 ERR("failed to create image list\n");
2605 for (i
=0; i
<bm_count
; i
++)
2607 hbmp
= LoadBitmapW( msi_hInstance
, MAKEINTRESOURCEW(i
+bm_resource
) );
2610 ERR("failed to load bitmap %d\n", i
);
2615 * Add a dummy bitmap at offset zero because the treeview
2616 * can't use it as a state mask (zero means no user state).
2619 ImageList_Add( himl
, hbmp
, NULL
);
2621 ImageList_Add( himl
, hbmp
, NULL
);
2624 SendMessageW( hwnd
, TVM_SETIMAGELIST
, TVSIL_STATE
, (LPARAM
)himl
);
2627 static UINT
msi_dialog_seltree_handler( msi_dialog
*dialog
,
2628 msi_control
*control
, WPARAM param
)
2630 struct msi_selection_tree_info
*info
= GetPropW( control
->hwnd
, szButtonData
);
2631 LPNMTREEVIEWW tv
= (LPNMTREEVIEWW
)param
;
2632 MSIRECORD
*row
, *rec
;
2634 MSIFEATURE
*feature
;
2635 LPCWSTR dir
, title
= NULL
;
2636 UINT r
= ERROR_SUCCESS
;
2638 static const WCHAR select
[] = {
2639 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2640 '`','F','e','a','t','u','r','e','`',' ','W','H','E','R','E',' ',
2641 '`','T','i','t','l','e','`',' ','=',' ','\'','%','s','\'',0
2644 if (tv
->hdr
.code
!= TVN_SELCHANGINGW
)
2645 return ERROR_SUCCESS
;
2647 info
->selected
= tv
->itemNew
.hItem
;
2649 if (!(tv
->itemNew
.mask
& TVIF_TEXT
))
2651 feature
= msi_seltree_feature_from_item( control
->hwnd
, tv
->itemNew
.hItem
);
2653 title
= feature
->Title
;
2656 title
= tv
->itemNew
.pszText
;
2658 row
= MSI_QueryGetRecord( dialog
->package
->db
, select
, title
);
2660 return ERROR_FUNCTION_FAILED
;
2662 rec
= MSI_CreateRecord( 1 );
2664 MSI_RecordSetStringW( rec
, 1, MSI_RecordGetString( row
, 4 ) );
2665 msi_event_fire( dialog
->package
, szSelectionDescription
, rec
);
2667 dir
= MSI_RecordGetString( row
, 7 );
2670 folder
= msi_get_loaded_folder( dialog
->package
, dir
);
2673 r
= ERROR_FUNCTION_FAILED
;
2676 MSI_RecordSetStringW( rec
, 1, folder
->ResolvedTarget
);
2679 MSI_RecordSetStringW( rec
, 1, NULL
);
2681 msi_event_fire( dialog
->package
, szSelectionPath
, rec
);
2684 msiobj_release(&row
->hdr
);
2685 msiobj_release(&rec
->hdr
);
2690 static UINT
msi_dialog_selection_tree( msi_dialog
*dialog
, MSIRECORD
*rec
)
2692 msi_control
*control
;
2693 LPCWSTR prop
, control_name
;
2694 MSIPACKAGE
*package
= dialog
->package
;
2696 struct msi_selection_tree_info
*info
;
2698 info
= msi_alloc( sizeof *info
);
2700 return ERROR_FUNCTION_FAILED
;
2702 /* create the treeview control */
2703 style
= TVS_HASLINES
| TVS_HASBUTTONS
| TVS_LINESATROOT
;
2704 style
|= WS_GROUP
| WS_VSCROLL
;
2705 control
= msi_dialog_add_control( dialog
, rec
, WC_TREEVIEWW
, style
);
2709 return ERROR_FUNCTION_FAILED
;
2712 control
->handler
= msi_dialog_seltree_handler
;
2713 control_name
= MSI_RecordGetString( rec
, 2 );
2714 control
->attributes
= MSI_RecordGetInteger( rec
, 8 );
2715 prop
= MSI_RecordGetString( rec
, 9 );
2716 control
->property
= msi_dialog_dup_property( dialog
, prop
, FALSE
);
2719 info
->dialog
= dialog
;
2720 info
->hwnd
= control
->hwnd
;
2721 info
->oldproc
= (WNDPROC
) SetWindowLongPtrW( control
->hwnd
, GWLP_WNDPROC
,
2722 (LONG_PTR
)MSISelectionTree_WndProc
);
2723 SetPropW( control
->hwnd
, szButtonData
, info
);
2725 event_subscribe( dialog
, szSelectionPath
, control_name
, szProperty
);
2728 msi_seltree_create_imagelist( control
->hwnd
);
2729 msi_seltree_add_child_features( package
, control
->hwnd
, NULL
, NULL
);
2731 return ERROR_SUCCESS
;
2734 /******************** Group Box ***************************************/
2736 static UINT
msi_dialog_group_box( msi_dialog
*dialog
, MSIRECORD
*rec
)
2738 msi_control
*control
;
2741 style
= BS_GROUPBOX
| WS_CHILD
| WS_GROUP
;
2742 control
= msi_dialog_add_control( dialog
, rec
, WC_BUTTONW
, style
);
2744 return ERROR_FUNCTION_FAILED
;
2746 return ERROR_SUCCESS
;
2749 /******************** List Box ***************************************/
2751 struct msi_listbox_info
2761 static LRESULT WINAPI
MSIListBox_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
2763 struct msi_listbox_info
*info
;
2767 TRACE("%p %04x %08lx %08lx\n", hWnd
, msg
, wParam
, lParam
);
2769 info
= GetPropW( hWnd
, szButtonData
);
2773 r
= CallWindowProcW( info
->oldproc
, hWnd
, msg
, wParam
, lParam
);
2778 for (j
= 0; j
< info
->num_items
; j
++)
2779 msi_free( info
->items
[j
] );
2780 msi_free( info
->items
);
2782 RemovePropW( hWnd
, szButtonData
);
2789 static UINT
msi_listbox_add_item( MSIRECORD
*rec
, LPVOID param
)
2791 struct msi_listbox_info
*info
= param
;
2792 LPCWSTR value
, text
;
2795 value
= MSI_RecordGetString( rec
, 3 );
2796 text
= MSI_RecordGetString( rec
, 4 );
2798 info
->items
[info
->addpos_items
] = strdupW( value
);
2800 pos
= SendMessageW( info
->hwnd
, LB_ADDSTRING
, 0, (LPARAM
)text
);
2801 SendMessageW( info
->hwnd
, LB_SETITEMDATA
, pos
, (LPARAM
)info
->items
[info
->addpos_items
] );
2802 info
->addpos_items
++;
2803 return ERROR_SUCCESS
;
2806 static UINT
msi_listbox_add_items( struct msi_listbox_info
*info
, LPCWSTR property
)
2808 static const WCHAR query
[] = {
2809 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2810 '`','L','i','s','t','B','o','x','`',' ','W','H','E','R','E',' ',
2811 '`','P','r','o','p','e','r','t','y','`',' ','=',' ','\'','%','s','\'',' ',
2812 'O','R','D','E','R',' ','B','Y',' ','`','O','r','d','e','r','`',0};
2817 r
= MSI_OpenQuery( info
->dialog
->package
->db
, &view
, query
, property
);
2818 if ( r
!= ERROR_SUCCESS
)
2821 /* just get the number of records */
2823 r
= MSI_IterateRecords( view
, &count
, NULL
, NULL
);
2824 if (r
!= ERROR_SUCCESS
)
2826 msiobj_release( &view
->hdr
);
2829 info
->num_items
= count
;
2830 info
->items
= msi_alloc( sizeof(*info
->items
) * count
);
2832 r
= MSI_IterateRecords( view
, NULL
, msi_listbox_add_item
, info
);
2833 msiobj_release( &view
->hdr
);
2837 static UINT
msi_dialog_listbox_handler( msi_dialog
*dialog
,
2838 msi_control
*control
, WPARAM param
)
2840 struct msi_listbox_info
*info
;
2844 if( HIWORD(param
) != LBN_SELCHANGE
)
2845 return ERROR_SUCCESS
;
2847 info
= GetPropW( control
->hwnd
, szButtonData
);
2848 index
= SendMessageW( control
->hwnd
, LB_GETCURSEL
, 0, 0 );
2849 value
= (LPCWSTR
) SendMessageW( control
->hwnd
, LB_GETITEMDATA
, index
, 0 );
2851 msi_dialog_set_property( info
->dialog
->package
, control
->property
, value
);
2852 msi_dialog_evaluate_control_conditions( info
->dialog
);
2854 return ERROR_SUCCESS
;
2857 static UINT
msi_dialog_list_box( msi_dialog
*dialog
, MSIRECORD
*rec
)
2859 struct msi_listbox_info
*info
;
2860 msi_control
*control
;
2861 DWORD attributes
, style
;
2864 info
= msi_alloc( sizeof *info
);
2866 return ERROR_FUNCTION_FAILED
;
2868 style
= WS_TABSTOP
| WS_GROUP
| WS_CHILD
| LBS_NOTIFY
| WS_VSCROLL
| WS_BORDER
;
2869 attributes
= MSI_RecordGetInteger( rec
, 8 );
2870 if (~attributes
& msidbControlAttributesSorted
)
2873 control
= msi_dialog_add_control( dialog
, rec
, WC_LISTBOXW
, style
);
2877 return ERROR_FUNCTION_FAILED
;
2880 control
->handler
= msi_dialog_listbox_handler
;
2882 prop
= MSI_RecordGetString( rec
, 9 );
2883 control
->property
= msi_dialog_dup_property( dialog
, prop
, FALSE
);
2886 info
->dialog
= dialog
;
2887 info
->hwnd
= control
->hwnd
;
2889 info
->addpos_items
= 0;
2890 info
->oldproc
= (WNDPROC
)SetWindowLongPtrW( control
->hwnd
, GWLP_WNDPROC
,
2891 (LONG_PTR
)MSIListBox_WndProc
);
2892 SetPropW( control
->hwnd
, szButtonData
, info
);
2894 if ( control
->property
)
2895 msi_listbox_add_items( info
, control
->property
);
2897 return ERROR_SUCCESS
;
2900 /******************** Directory Combo ***************************************/
2902 static void msi_dialog_update_directory_combo( msi_dialog
*dialog
, msi_control
*control
)
2907 if (!control
&& !(control
= msi_dialog_find_control_by_type( dialog
, szDirectoryCombo
)))
2910 indirect
= control
->attributes
& msidbControlAttributesIndirect
;
2911 prop
= msi_dialog_dup_property( dialog
, control
->property
, indirect
);
2912 path
= msi_dialog_dup_property( dialog
, prop
, TRUE
);
2914 PathStripPathW( path
);
2915 PathRemoveBackslashW( path
);
2917 SendMessageW( control
->hwnd
, CB_INSERTSTRING
, 0, (LPARAM
)path
);
2918 SendMessageW( control
->hwnd
, CB_SETCURSEL
, 0, 0 );
2924 static UINT
msi_dialog_directory_combo( msi_dialog
*dialog
, MSIRECORD
*rec
)
2926 msi_control
*control
;
2930 /* FIXME: use CBS_OWNERDRAWFIXED and add owner draw code */
2931 style
= CBS_DROPDOWNLIST
| CBS_HASSTRINGS
| WS_CHILD
|
2932 WS_GROUP
| WS_TABSTOP
| WS_VSCROLL
;
2933 control
= msi_dialog_add_control( dialog
, rec
, WC_COMBOBOXW
, style
);
2935 return ERROR_FUNCTION_FAILED
;
2937 control
->attributes
= MSI_RecordGetInteger( rec
, 8 );
2938 prop
= MSI_RecordGetString( rec
, 9 );
2939 control
->property
= msi_dialog_dup_property( dialog
, prop
, FALSE
);
2941 msi_dialog_update_directory_combo( dialog
, control
);
2943 return ERROR_SUCCESS
;
2946 /******************** Directory List ***************************************/
2948 static void msi_dialog_update_directory_list( msi_dialog
*dialog
, msi_control
*control
)
2950 WCHAR dir_spec
[MAX_PATH
];
2951 WIN32_FIND_DATAW wfd
;
2957 static const WCHAR asterisk
[] = {'*',0};
2959 if (!control
&& !(control
= msi_dialog_find_control_by_type( dialog
, szDirectoryList
)))
2962 /* clear the list-view */
2963 SendMessageW( control
->hwnd
, LVM_DELETEALLITEMS
, 0, 0 );
2965 indirect
= control
->attributes
& msidbControlAttributesIndirect
;
2966 prop
= msi_dialog_dup_property( dialog
, control
->property
, indirect
);
2967 path
= msi_dialog_dup_property( dialog
, prop
, TRUE
);
2969 lstrcpyW( dir_spec
, path
);
2970 lstrcatW( dir_spec
, asterisk
);
2972 file
= FindFirstFileW( dir_spec
, &wfd
);
2973 if ( file
== INVALID_HANDLE_VALUE
)
2978 if ( wfd
.dwFileAttributes
!= FILE_ATTRIBUTE_DIRECTORY
)
2981 if ( !strcmpW( wfd
.cFileName
, szDot
) || !strcmpW( wfd
.cFileName
, szDotDot
) )
2984 item
.mask
= LVIF_TEXT
;
2985 item
.cchTextMax
= MAX_PATH
;
2988 item
.pszText
= wfd
.cFileName
;
2990 SendMessageW( control
->hwnd
, LVM_INSERTITEMW
, 0, (LPARAM
)&item
);
2991 } while ( FindNextFileW( file
, &wfd
) );
2998 static UINT
msi_dialog_directorylist_up( msi_dialog
*dialog
)
3000 msi_control
*control
;
3001 LPWSTR prop
, path
, ptr
;
3004 control
= msi_dialog_find_control_by_type( dialog
, szDirectoryList
);
3005 indirect
= control
->attributes
& msidbControlAttributesIndirect
;
3006 prop
= msi_dialog_dup_property( dialog
, control
->property
, indirect
);
3007 path
= msi_dialog_dup_property( dialog
, prop
, TRUE
);
3009 /* strip off the last directory */
3010 ptr
= PathFindFileNameW( path
);
3011 if (ptr
!= path
) *(ptr
- 1) = '\0';
3012 PathAddBackslashW( path
);
3014 msi_dialog_set_property( dialog
->package
, prop
, path
);
3016 msi_dialog_update_directory_list( dialog
, NULL
);
3017 msi_dialog_update_directory_combo( dialog
, NULL
);
3018 msi_dialog_update_pathedit( dialog
, NULL
);
3023 return ERROR_SUCCESS
;
3026 static UINT
msi_dialog_dirlist_handler( msi_dialog
*dialog
,
3027 msi_control
*control
, WPARAM param
)
3029 LPNMHDR nmhdr
= (LPNMHDR
)param
;
3030 WCHAR new_path
[MAX_PATH
];
3031 WCHAR text
[MAX_PATH
];
3037 if (nmhdr
->code
!= LVN_ITEMACTIVATE
)
3038 return ERROR_SUCCESS
;
3040 index
= SendMessageW( control
->hwnd
, LVM_GETNEXTITEM
, -1, LVNI_SELECTED
);
3043 ERR("No list-view item selected!\n");
3044 return ERROR_FUNCTION_FAILED
;
3048 item
.pszText
= text
;
3049 item
.cchTextMax
= MAX_PATH
;
3050 SendMessageW( control
->hwnd
, LVM_GETITEMTEXTW
, index
, (LPARAM
)&item
);
3052 indirect
= control
->attributes
& msidbControlAttributesIndirect
;
3053 prop
= msi_dialog_dup_property( dialog
, control
->property
, indirect
);
3054 path
= msi_dialog_dup_property( dialog
, prop
, TRUE
);
3056 lstrcpyW( new_path
, path
);
3057 lstrcatW( new_path
, text
);
3058 lstrcatW( new_path
, szBackSlash
);
3060 msi_dialog_set_property( dialog
->package
, prop
, new_path
);
3062 msi_dialog_update_directory_list( dialog
, NULL
);
3063 msi_dialog_update_directory_combo( dialog
, NULL
);
3064 msi_dialog_update_pathedit( dialog
, NULL
);
3068 return ERROR_SUCCESS
;
3071 static UINT
msi_dialog_directory_list( msi_dialog
*dialog
, MSIRECORD
*rec
)
3073 msi_control
*control
;
3077 style
= LVS_LIST
| WS_VSCROLL
| LVS_SHAREIMAGELISTS
|
3078 LVS_AUTOARRANGE
| LVS_SINGLESEL
| WS_BORDER
|
3079 LVS_SORTASCENDING
| WS_CHILD
| WS_GROUP
| WS_TABSTOP
;
3080 control
= msi_dialog_add_control( dialog
, rec
, WC_LISTVIEWW
, style
);
3082 return ERROR_FUNCTION_FAILED
;
3084 control
->attributes
= MSI_RecordGetInteger( rec
, 8 );
3085 control
->handler
= msi_dialog_dirlist_handler
;
3086 prop
= MSI_RecordGetString( rec
, 9 );
3087 control
->property
= msi_dialog_dup_property( dialog
, prop
, FALSE
);
3089 /* double click to activate an item in the list */
3090 SendMessageW( control
->hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
,
3091 0, LVS_EX_TWOCLICKACTIVATE
);
3093 msi_dialog_update_directory_list( dialog
, control
);
3095 return ERROR_SUCCESS
;
3098 /******************** VolumeCost List ***************************************/
3100 static BOOL
str_is_number( LPCWSTR str
)
3104 for (i
= 0; i
< lstrlenW( str
); i
++)
3105 if (!isdigitW(str
[i
]))
3111 static const WCHAR column_keys
[][80] =
3113 {'V','o','l','u','m','e','C','o','s','t','V','o','l','u','m','e',0},
3114 {'V','o','l','u','m','e','C','o','s','t','S','i','z','e',0},
3115 {'V','o','l','u','m','e','C','o','s','t','A','v','a','i','l','a','b','l','e',0},
3116 {'V','o','l','u','m','e','C','o','s','t','R','e','q','u','i','r','e','d',0},
3117 {'V','o','l','u','m','e','C','o','s','t','D','i','f','f','e','r','e','n','c','e',0}
3120 static void msi_dialog_vcl_add_columns( msi_dialog
*dialog
, msi_control
*control
, MSIRECORD
*rec
)
3122 LPCWSTR text
= MSI_RecordGetString( rec
, 10 );
3123 LPCWSTR begin
= text
, end
;
3128 static const WCHAR negative
[] = {'-',0};
3132 while ((begin
= strchrW( begin
, '{' )) && count
< 5)
3134 if (!(end
= strchrW( begin
, '}' )))
3137 num
= msi_alloc( (end
-begin
+1)*sizeof(WCHAR
) );
3141 lstrcpynW( num
, begin
+ 1, end
- begin
);
3142 begin
+= end
- begin
+ 1;
3144 /* empty braces or '0' hides the column */
3145 if ( !num
[0] || !strcmpW( num
, szZero
) )
3152 /* the width must be a positive number
3153 * if a width is invalid, all remaining columns are hidden
3155 if ( !strncmpW( num
, negative
, 1 ) || !str_is_number( num
) ) {
3160 ZeroMemory( &lvc
, sizeof(lvc
) );
3161 lvc
.mask
= LVCF_TEXT
| LVCF_WIDTH
| LVCF_SUBITEM
;
3162 lvc
.cx
= atolW( num
);
3163 lvc
.pszText
= msi_dialog_get_uitext( dialog
, column_keys
[count
] );
3165 SendMessageW( control
->hwnd
, LVM_INSERTCOLUMNW
, count
++, (LPARAM
)&lvc
);
3166 msi_free( lvc
.pszText
);
3171 static LONGLONG
msi_vcl_get_cost( msi_dialog
*dialog
)
3173 MSIFEATURE
*feature
;
3175 LONGLONG total_cost
= 0;
3177 LIST_FOR_EACH_ENTRY( feature
, &dialog
->package
->features
, MSIFEATURE
, entry
)
3179 if (ERROR_SUCCESS
== (MSI_GetFeatureCost(dialog
->package
, feature
,
3180 MSICOSTTREE_SELFONLY
, INSTALLSTATE_LOCAL
, &each_cost
)))
3182 /* each_cost is in 512-byte units */
3183 total_cost
+= each_cost
* 512;
3185 if (ERROR_SUCCESS
== (MSI_GetFeatureCost(dialog
->package
, feature
,
3186 MSICOSTTREE_SELFONLY
, INSTALLSTATE_ABSENT
, &each_cost
)))
3188 /* each_cost is in 512-byte units */
3189 total_cost
-= each_cost
* 512;
3195 static void msi_dialog_vcl_add_drives( msi_dialog
*dialog
, msi_control
*control
)
3197 ULARGE_INTEGER total
, free
;
3198 LONGLONG difference
, cost
;
3199 WCHAR size_text
[MAX_PATH
];
3200 WCHAR cost_text
[MAX_PATH
];
3206 cost
= msi_vcl_get_cost(dialog
);
3207 StrFormatByteSizeW(cost
, cost_text
, MAX_PATH
);
3209 size
= GetLogicalDriveStringsW( 0, NULL
);
3210 if ( !size
) return;
3212 drives
= msi_alloc( (size
+ 1) * sizeof(WCHAR
) );
3213 if ( !drives
) return;
3215 GetLogicalDriveStringsW( size
, drives
);
3220 lvitem
.mask
= LVIF_TEXT
;
3222 lvitem
.iSubItem
= 0;
3223 lvitem
.pszText
= ptr
;
3224 lvitem
.cchTextMax
= lstrlenW(ptr
) + 1;
3225 SendMessageW( control
->hwnd
, LVM_INSERTITEMW
, 0, (LPARAM
)&lvitem
);
3227 GetDiskFreeSpaceExW(ptr
, &free
, &total
, NULL
);
3228 difference
= free
.QuadPart
- cost
;
3230 StrFormatByteSizeW(total
.QuadPart
, size_text
, MAX_PATH
);
3231 lvitem
.iSubItem
= 1;
3232 lvitem
.pszText
= size_text
;
3233 lvitem
.cchTextMax
= lstrlenW(size_text
) + 1;
3234 SendMessageW( control
->hwnd
, LVM_SETITEMW
, 0, (LPARAM
)&lvitem
);
3236 StrFormatByteSizeW(free
.QuadPart
, size_text
, MAX_PATH
);
3237 lvitem
.iSubItem
= 2;
3238 lvitem
.pszText
= size_text
;
3239 lvitem
.cchTextMax
= lstrlenW(size_text
) + 1;
3240 SendMessageW( control
->hwnd
, LVM_SETITEMW
, 0, (LPARAM
)&lvitem
);
3242 lvitem
.iSubItem
= 3;
3243 lvitem
.pszText
= cost_text
;
3244 lvitem
.cchTextMax
= lstrlenW(cost_text
) + 1;
3245 SendMessageW( control
->hwnd
, LVM_SETITEMW
, 0, (LPARAM
)&lvitem
);
3247 StrFormatByteSizeW(difference
, size_text
, MAX_PATH
);
3248 lvitem
.iSubItem
= 4;
3249 lvitem
.pszText
= size_text
;
3250 lvitem
.cchTextMax
= lstrlenW(size_text
) + 1;
3251 SendMessageW( control
->hwnd
, LVM_SETITEMW
, 0, (LPARAM
)&lvitem
);
3253 ptr
+= lstrlenW(ptr
) + 1;
3260 static UINT
msi_dialog_volumecost_list( msi_dialog
*dialog
, MSIRECORD
*rec
)
3262 msi_control
*control
;
3265 style
= LVS_REPORT
| WS_VSCROLL
| WS_HSCROLL
| LVS_SHAREIMAGELISTS
|
3266 LVS_AUTOARRANGE
| LVS_SINGLESEL
| WS_BORDER
|
3267 WS_CHILD
| WS_TABSTOP
| WS_GROUP
;
3268 control
= msi_dialog_add_control( dialog
, rec
, WC_LISTVIEWW
, style
);
3270 return ERROR_FUNCTION_FAILED
;
3272 msi_dialog_vcl_add_columns( dialog
, control
, rec
);
3273 msi_dialog_vcl_add_drives( dialog
, control
);
3275 return ERROR_SUCCESS
;
3278 /******************** VolumeSelect Combo ***************************************/
3280 static UINT
msi_dialog_volsel_handler( msi_dialog
*dialog
,
3281 msi_control
*control
, WPARAM param
)
3283 WCHAR text
[MAX_PATH
];
3288 if (HIWORD(param
) != CBN_SELCHANGE
)
3289 return ERROR_SUCCESS
;
3291 index
= SendMessageW( control
->hwnd
, CB_GETCURSEL
, 0, 0 );
3292 if ( index
== CB_ERR
)
3294 ERR("No ComboBox item selected!\n");
3295 return ERROR_FUNCTION_FAILED
;
3298 SendMessageW( control
->hwnd
, CB_GETLBTEXT
, index
, (LPARAM
)text
);
3300 indirect
= control
->attributes
& msidbControlAttributesIndirect
;
3301 prop
= msi_dialog_dup_property( dialog
, control
->property
, indirect
);
3303 msi_dialog_set_property( dialog
->package
, prop
, text
);
3306 return ERROR_SUCCESS
;
3309 static void msi_dialog_vsc_add_drives( msi_dialog
*dialog
, msi_control
*control
)
3314 size
= GetLogicalDriveStringsW( 0, NULL
);
3315 if ( !size
) return;
3317 drives
= msi_alloc( (size
+ 1) * sizeof(WCHAR
) );
3318 if ( !drives
) return;
3320 GetLogicalDriveStringsW( size
, drives
);
3325 SendMessageW( control
->hwnd
, CB_ADDSTRING
, 0, (LPARAM
)ptr
);
3326 ptr
+= lstrlenW(ptr
) + 1;
3332 static UINT
msi_dialog_volumeselect_combo( msi_dialog
*dialog
, MSIRECORD
*rec
)
3334 msi_control
*control
;
3338 /* FIXME: CBS_OWNERDRAWFIXED */
3339 style
= WS_CHILD
| WS_VISIBLE
| WS_GROUP
| WS_TABSTOP
|
3340 CBS_DROPDOWNLIST
| CBS_SORT
| CBS_HASSTRINGS
|
3341 WS_EX_LEFT
| WS_EX_LTRREADING
| WS_EX_RIGHTSCROLLBAR
;
3342 control
= msi_dialog_add_control( dialog
, rec
, WC_COMBOBOXW
, style
);
3344 return ERROR_FUNCTION_FAILED
;
3346 control
->attributes
= MSI_RecordGetInteger( rec
, 8 );
3347 control
->handler
= msi_dialog_volsel_handler
;
3348 prop
= MSI_RecordGetString( rec
, 9 );
3349 control
->property
= msi_dialog_dup_property( dialog
, prop
, FALSE
);
3351 msi_dialog_vsc_add_drives( dialog
, control
);
3353 return ERROR_SUCCESS
;
3356 static UINT
msi_dialog_hyperlink_handler( msi_dialog
*dialog
, msi_control
*control
, WPARAM param
)
3358 static const WCHAR hrefW
[] = {'h','r','e','f'};
3359 static const WCHAR openW
[] = {'o','p','e','n',0};
3360 int len
, len_href
= sizeof(hrefW
) / sizeof(hrefW
[0]);
3365 item
.mask
= LIF_ITEMINDEX
| LIF_URL
;
3369 SendMessageW( control
->hwnd
, LM_GETITEM
, 0, (LPARAM
)&item
);
3372 while (*p
&& *p
!= '<') p
++;
3373 if (!*p
++) return ERROR_SUCCESS
;
3374 if (toupperW( *p
++ ) != 'A' || !isspaceW( *p
++ )) return ERROR_SUCCESS
;
3375 while (*p
&& isspaceW( *p
)) p
++;
3378 if (len
> len_href
&& !memicmpW( p
, hrefW
, len_href
))
3381 while (*p
&& isspaceW( *p
)) p
++;
3382 if (!*p
|| *p
++ != '=') return ERROR_SUCCESS
;
3383 while (*p
&& isspaceW( *p
)) p
++;
3385 if (*p
== '\"' || *p
== '\'') quote
= *p
++;
3389 while (*q
&& *q
!= quote
) q
++;
3390 if (*q
!= quote
) return ERROR_SUCCESS
;
3394 while (*q
&& *q
!= '>' && !isspaceW( *q
)) q
++;
3395 if (!*q
) return ERROR_SUCCESS
;
3397 item
.szUrl
[q
- item
.szUrl
] = 0;
3398 ShellExecuteW( NULL
, openW
, p
, NULL
, NULL
, SW_SHOWNORMAL
);
3400 return ERROR_SUCCESS
;
3403 static UINT
msi_dialog_hyperlink( msi_dialog
*dialog
, MSIRECORD
*rec
)
3405 msi_control
*control
;
3406 DWORD style
= WS_CHILD
| WS_TABSTOP
| WS_GROUP
;
3407 const WCHAR
*text
= MSI_RecordGetString( rec
, 10 );
3408 int len
= strlenW( text
);
3411 control
= msi_dialog_add_control( dialog
, rec
, WC_LINK
, style
);
3413 return ERROR_FUNCTION_FAILED
;
3415 control
->attributes
= MSI_RecordGetInteger( rec
, 8 );
3416 control
->handler
= msi_dialog_hyperlink_handler
;
3418 item
.mask
= LIF_ITEMINDEX
| LIF_STATE
| LIF_URL
;
3420 item
.state
= LIS_ENABLED
;
3421 item
.stateMask
= LIS_ENABLED
;
3422 if (len
< L_MAX_URL_LENGTH
) strcpyW( item
.szUrl
, text
);
3423 else item
.szUrl
[0] = 0;
3425 SendMessageW( control
->hwnd
, LM_SETITEM
, 0, (LPARAM
)&item
);
3427 return ERROR_SUCCESS
;
3430 static const struct control_handler msi_dialog_handler
[] =
3432 { szText
, msi_dialog_text_control
},
3433 { szPushButton
, msi_dialog_button_control
},
3434 { szLine
, msi_dialog_line_control
},
3435 { szBitmap
, msi_dialog_bitmap_control
},
3436 { szCheckBox
, msi_dialog_checkbox_control
},
3437 { szScrollableText
, msi_dialog_scrolltext_control
},
3438 { szComboBox
, msi_dialog_combo_control
},
3439 { szEdit
, msi_dialog_edit_control
},
3440 { szMaskedEdit
, msi_dialog_maskedit_control
},
3441 { szPathEdit
, msi_dialog_pathedit_control
},
3442 { szProgressBar
, msi_dialog_progress_bar
},
3443 { szRadioButtonGroup
, msi_dialog_radiogroup_control
},
3444 { szIcon
, msi_dialog_icon_control
},
3445 { szSelectionTree
, msi_dialog_selection_tree
},
3446 { szGroupBox
, msi_dialog_group_box
},
3447 { szListBox
, msi_dialog_list_box
},
3448 { szDirectoryCombo
, msi_dialog_directory_combo
},
3449 { szDirectoryList
, msi_dialog_directory_list
},
3450 { szVolumeCostList
, msi_dialog_volumecost_list
},
3451 { szVolumeSelectCombo
, msi_dialog_volumeselect_combo
},
3452 { szHyperLink
, msi_dialog_hyperlink
}
3455 #define NUM_CONTROL_TYPES (sizeof msi_dialog_handler/sizeof msi_dialog_handler[0])
3457 static UINT
msi_dialog_create_controls( MSIRECORD
*rec
, LPVOID param
)
3459 msi_dialog
*dialog
= param
;
3460 LPCWSTR control_type
;
3463 /* find and call the function that can create this type of control */
3464 control_type
= MSI_RecordGetString( rec
, 3 );
3465 for( i
=0; i
<NUM_CONTROL_TYPES
; i
++ )
3466 if (!strcmpiW( msi_dialog_handler
[i
].control_type
, control_type
))
3468 if( i
!= NUM_CONTROL_TYPES
)
3469 msi_dialog_handler
[i
].func( dialog
, rec
);
3471 ERR("no handler for element type %s\n", debugstr_w(control_type
));
3473 return ERROR_SUCCESS
;
3476 static UINT
msi_dialog_fill_controls( msi_dialog
*dialog
)
3478 static const WCHAR query
[] = {
3479 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
3480 'C','o','n','t','r','o','l',' ','W','H','E','R','E',' ',
3481 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',0};
3484 MSIPACKAGE
*package
= dialog
->package
;
3486 TRACE("%p %s\n", dialog
, debugstr_w(dialog
->name
) );
3488 /* query the Control table for all the elements of the control */
3489 r
= MSI_OpenQuery( package
->db
, &view
, query
, dialog
->name
);
3490 if( r
!= ERROR_SUCCESS
)
3492 ERR("query failed for dialog %s\n", debugstr_w(dialog
->name
));
3493 return ERROR_INVALID_PARAMETER
;
3496 r
= MSI_IterateRecords( view
, 0, msi_dialog_create_controls
, dialog
);
3497 msiobj_release( &view
->hdr
);
3501 static UINT
msi_dialog_reset( msi_dialog
*dialog
)
3503 /* FIXME: should restore the original values of any properties we changed */
3504 return msi_dialog_evaluate_control_conditions( dialog
);
3507 /* figure out the height of 10 point MS Sans Serif */
3508 static INT
msi_dialog_get_sans_serif_height( HWND hwnd
)
3510 static const WCHAR szSansSerif
[] = {
3511 'M','S',' ','S','a','n','s',' ','S','e','r','i','f',0 };
3516 HFONT hFont
, hOldFont
;
3519 hdc
= GetDC( hwnd
);
3522 memset( &lf
, 0, sizeof lf
);
3523 lf
.lfHeight
= MulDiv(12, GetDeviceCaps(hdc
, LOGPIXELSY
), 72);
3524 strcpyW( lf
.lfFaceName
, szSansSerif
);
3525 hFont
= CreateFontIndirectW(&lf
);
3528 hOldFont
= SelectObject( hdc
, hFont
);
3529 r
= GetTextMetricsW( hdc
, &tm
);
3531 height
= tm
.tmHeight
;
3532 SelectObject( hdc
, hOldFont
);
3533 DeleteObject( hFont
);
3535 ReleaseDC( hwnd
, hdc
);
3540 /* fetch the associated record from the Dialog table */
3541 static MSIRECORD
*msi_get_dialog_record( msi_dialog
*dialog
)
3543 static const WCHAR query
[] = {
3544 'S','E','L','E','C','T',' ','*',' ',
3545 'F','R','O','M',' ','D','i','a','l','o','g',' ',
3546 'W','H','E','R','E',' ',
3547 '`','D','i','a','l','o','g','`',' ','=',' ','\'','%','s','\'',0};
3548 MSIPACKAGE
*package
= dialog
->package
;
3549 MSIRECORD
*rec
= NULL
;
3551 TRACE("%p %s\n", dialog
, debugstr_w(dialog
->name
) );
3553 rec
= MSI_QueryGetRecord( package
->db
, query
, dialog
->name
);
3555 WARN("query failed for dialog %s\n", debugstr_w(dialog
->name
));
3560 static void msi_dialog_adjust_dialog_pos( msi_dialog
*dialog
, MSIRECORD
*rec
, LPRECT pos
)
3562 static const WCHAR szScreenX
[] = {'S','c','r','e','e','n','X',0};
3563 static const WCHAR szScreenY
[] = {'S','c','r','e','e','n','Y',0};
3570 center
.x
= MSI_RecordGetInteger( rec
, 2 );
3571 center
.y
= MSI_RecordGetInteger( rec
, 3 );
3573 sz
.cx
= MSI_RecordGetInteger( rec
, 4 );
3574 sz
.cy
= MSI_RecordGetInteger( rec
, 5 );
3576 sz
.cx
= msi_dialog_scale_unit( dialog
, sz
.cx
);
3577 sz
.cy
= msi_dialog_scale_unit( dialog
, sz
.cy
);
3579 xres
= msi_get_property_int( dialog
->package
->db
, szScreenX
, 0 );
3580 yres
= msi_get_property_int( dialog
->package
->db
, szScreenY
, 0 );
3582 center
.x
= MulDiv( center
.x
, xres
, 100 );
3583 center
.y
= MulDiv( center
.y
, yres
, 100 );
3585 /* turn the client pos into the window rectangle */
3586 if (dialog
->package
->center_x
&& dialog
->package
->center_y
)
3588 pos
->left
= dialog
->package
->center_x
- sz
.cx
/ 2.0;
3589 pos
->right
= pos
->left
+ sz
.cx
;
3590 pos
->top
= dialog
->package
->center_y
- sz
.cy
/ 2.0;
3591 pos
->bottom
= pos
->top
+ sz
.cy
;
3595 pos
->left
= center
.x
- sz
.cx
/2;
3596 pos
->right
= pos
->left
+ sz
.cx
;
3597 pos
->top
= center
.y
- sz
.cy
/2;
3598 pos
->bottom
= pos
->top
+ sz
.cy
;
3600 /* save the center */
3601 dialog
->package
->center_x
= center
.x
;
3602 dialog
->package
->center_y
= center
.y
;
3605 dialog
->size
.cx
= sz
.cx
;
3606 dialog
->size
.cy
= sz
.cy
;
3608 TRACE("%u %u %u %u\n", pos
->left
, pos
->top
, pos
->right
, pos
->bottom
);
3610 style
= GetWindowLongPtrW( dialog
->hwnd
, GWL_STYLE
);
3611 AdjustWindowRect( pos
, style
, FALSE
);
3614 static void msi_dialog_set_tab_order( msi_dialog
*dialog
, LPCWSTR first
)
3616 struct list tab_chain
;
3617 msi_control
*control
;
3618 HWND prev
= HWND_TOP
;
3620 list_init( &tab_chain
);
3621 if (!(control
= msi_dialog_find_control( dialog
, first
))) return;
3623 dialog
->hWndFocus
= control
->hwnd
;
3626 list_remove( &control
->entry
);
3627 list_add_tail( &tab_chain
, &control
->entry
);
3628 if (!control
->tabnext
) break;
3629 control
= msi_dialog_find_control( dialog
, control
->tabnext
);
3632 LIST_FOR_EACH_ENTRY( control
, &tab_chain
, msi_control
, entry
)
3634 SetWindowPos( control
->hwnd
, prev
, 0, 0, 0, 0,
3635 SWP_NOMOVE
| SWP_NOOWNERZORDER
| SWP_NOREDRAW
|
3636 SWP_NOREPOSITION
| SWP_NOSENDCHANGING
| SWP_NOSIZE
);
3637 prev
= control
->hwnd
;
3640 /* put them back on the main list */
3641 list_move_head( &dialog
->controls
, &tab_chain
);
3644 static LRESULT
msi_dialog_oncreate( HWND hwnd
, LPCREATESTRUCTW cs
)
3646 static const WCHAR df
[] = {
3647 'D','e','f','a','u','l','t','U','I','F','o','n','t',0 };
3648 static const WCHAR dfv
[] = {
3649 'M','S',' ','S','h','e','l','l',' ','D','l','g',0 };
3650 msi_dialog
*dialog
= cs
->lpCreateParams
;
3651 MSIRECORD
*rec
= NULL
;
3652 LPWSTR title
= NULL
;
3655 TRACE("%p %p\n", dialog
, dialog
->package
);
3657 dialog
->hwnd
= hwnd
;
3658 SetWindowLongPtrW( hwnd
, GWLP_USERDATA
, (LONG_PTR
) dialog
);
3660 rec
= msi_get_dialog_record( dialog
);
3663 TRACE("No record found for dialog %s\n", debugstr_w(dialog
->name
));
3667 dialog
->scale
= msi_dialog_get_sans_serif_height(dialog
->hwnd
);
3669 msi_dialog_adjust_dialog_pos( dialog
, rec
, &pos
);
3671 dialog
->attributes
= MSI_RecordGetInteger( rec
, 6 );
3673 dialog
->default_font
= msi_dup_property( dialog
->package
->db
, df
);
3674 if (!dialog
->default_font
)
3676 dialog
->default_font
= strdupW(dfv
);
3677 msiobj_release( &rec
->hdr
);
3678 if (!dialog
->default_font
) return -1;
3681 title
= msi_get_deformatted_field( dialog
->package
, rec
, 7 );
3682 SetWindowTextW( hwnd
, title
);
3685 SetWindowPos( hwnd
, 0, pos
.left
, pos
.top
,
3686 pos
.right
- pos
.left
, pos
.bottom
- pos
.top
,
3687 SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_NOREDRAW
);
3689 msi_dialog_build_font_list( dialog
);
3690 msi_dialog_fill_controls( dialog
);
3691 msi_dialog_evaluate_control_conditions( dialog
);
3692 msi_dialog_set_tab_order( dialog
, MSI_RecordGetString( rec
, 8 ) );
3693 msiobj_release( &rec
->hdr
);
3698 static LRESULT
msi_dialog_oncommand( msi_dialog
*dialog
, WPARAM param
, HWND hwnd
)
3700 msi_control
*control
= NULL
;
3702 TRACE("%p %p %08lx\n", dialog
, hwnd
, param
);
3707 control
= msi_dialog_find_control( dialog
, dialog
->control_default
);
3709 case 2: /* escape */
3710 control
= msi_dialog_find_control( dialog
, dialog
->control_cancel
);
3713 control
= msi_dialog_find_control_by_hwnd( dialog
, hwnd
);
3718 if( control
->handler
)
3720 control
->handler( dialog
, control
, param
);
3721 msi_dialog_evaluate_control_conditions( dialog
);
3728 static LRESULT
msi_dialog_onnotify( msi_dialog
*dialog
, LPARAM param
)
3730 LPNMHDR nmhdr
= (LPNMHDR
) param
;
3731 msi_control
*control
= msi_dialog_find_control_by_hwnd( dialog
, nmhdr
->hwndFrom
);
3733 TRACE("%p %p\n", dialog
, nmhdr
->hwndFrom
);
3735 if ( control
&& control
->handler
)
3736 control
->handler( dialog
, control
, param
);
3741 static void dialog_setfocus( msi_dialog
*dialog
)
3743 HWND hwnd
= dialog
->hWndFocus
;
3745 hwnd
= GetNextDlgTabItem( dialog
->hwnd
, hwnd
, TRUE
);
3746 hwnd
= GetNextDlgTabItem( dialog
->hwnd
, hwnd
, FALSE
);
3748 dialog
->hWndFocus
= hwnd
;
3751 static LRESULT WINAPI
MSIDialog_WndProc( HWND hwnd
, UINT msg
,
3752 WPARAM wParam
, LPARAM lParam
)
3754 msi_dialog
*dialog
= (LPVOID
) GetWindowLongPtrW( hwnd
, GWLP_USERDATA
);
3756 TRACE("0x%04x\n", msg
);
3761 dialog
->package
->center_x
= LOWORD(lParam
) + dialog
->size
.cx
/ 2.0;
3762 dialog
->package
->center_y
= HIWORD(lParam
) + dialog
->size
.cy
/ 2.0;
3766 return msi_dialog_oncreate( hwnd
, (LPCREATESTRUCTW
)lParam
);
3769 return msi_dialog_oncommand( dialog
, wParam
, (HWND
)lParam
);
3772 if( LOWORD(wParam
) == WA_INACTIVE
)
3773 dialog
->hWndFocus
= GetFocus();
3775 dialog_setfocus( dialog
);
3779 dialog_setfocus( dialog
);
3782 /* bounce back to our subclassed static control */
3783 case WM_CTLCOLORSTATIC
:
3784 return SendMessageW( (HWND
) lParam
, WM_CTLCOLORSTATIC
, wParam
, lParam
);
3787 dialog
->hwnd
= NULL
;
3790 return msi_dialog_onnotify( dialog
, lParam
);
3792 return DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
3795 static void process_pending_messages( HWND hdlg
)
3799 while (PeekMessageW( &msg
, 0, 0, 0, PM_REMOVE
))
3801 if (hdlg
&& IsDialogMessageW( hdlg
, &msg
)) continue;
3802 TranslateMessage( &msg
);
3803 DispatchMessageW( &msg
);
3807 static UINT
dialog_run_message_loop( msi_dialog
*dialog
)
3812 if( uiThreadId
!= GetCurrentThreadId() )
3813 return SendMessageW( hMsiHiddenWindow
, WM_MSI_DIALOG_CREATE
, 0, (LPARAM
) dialog
);
3815 /* create the dialog window, don't show it yet */
3816 style
= WS_OVERLAPPED
;
3817 if( dialog
->attributes
& msidbDialogAttributesVisible
)
3818 style
|= WS_VISIBLE
;
3820 hwnd
= CreateWindowW( szMsiDialogClass
, dialog
->name
, style
,
3821 CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
,
3822 NULL
, NULL
, NULL
, dialog
);
3825 ERR("Failed to create dialog %s\n", debugstr_w( dialog
->name
));
3826 return ERROR_FUNCTION_FAILED
;
3829 ShowWindow( hwnd
, SW_SHOW
);
3830 /* UpdateWindow( hwnd ); - and causes the transparent static controls not to paint */
3832 if( dialog
->attributes
& msidbDialogAttributesModal
)
3834 while( !dialog
->finished
)
3836 MsgWaitForMultipleObjects( 0, NULL
, 0, INFINITE
, QS_ALLINPUT
);
3837 process_pending_messages( dialog
->hwnd
);
3841 return ERROR_IO_PENDING
;
3843 return ERROR_SUCCESS
;
3846 static LRESULT WINAPI
MSIHiddenWindowProc( HWND hwnd
, UINT msg
,
3847 WPARAM wParam
, LPARAM lParam
)
3849 msi_dialog
*dialog
= (msi_dialog
*) lParam
;
3851 TRACE("%d %p\n", msg
, dialog
);
3855 case WM_MSI_DIALOG_CREATE
:
3856 return dialog_run_message_loop( dialog
);
3857 case WM_MSI_DIALOG_DESTROY
:
3858 msi_dialog_destroy( dialog
);
3861 return DefWindowProcW( hwnd
, msg
, wParam
, lParam
);
3864 static BOOL
dialog_register_class( void )
3868 ZeroMemory( &cls
, sizeof cls
);
3869 cls
.lpfnWndProc
= MSIDialog_WndProc
;
3870 cls
.hInstance
= NULL
;
3871 cls
.hIcon
= LoadIconW(0, (LPWSTR
)IDI_APPLICATION
);
3872 cls
.hCursor
= LoadCursorW(0, (LPWSTR
)IDC_ARROW
);
3873 cls
.hbrBackground
= (HBRUSH
)(COLOR_3DFACE
+ 1);
3874 cls
.lpszMenuName
= NULL
;
3875 cls
.lpszClassName
= szMsiDialogClass
;
3877 if( !RegisterClassW( &cls
) )
3880 cls
.lpfnWndProc
= MSIHiddenWindowProc
;
3881 cls
.lpszClassName
= szMsiHiddenWindow
;
3883 if( !RegisterClassW( &cls
) )
3886 uiThreadId
= GetCurrentThreadId();
3888 hMsiHiddenWindow
= CreateWindowW( szMsiHiddenWindow
, NULL
, WS_OVERLAPPED
,
3889 0, 0, 100, 100, NULL
, NULL
, NULL
, NULL
);
3890 if( !hMsiHiddenWindow
)
3896 static msi_dialog
*dialog_create( MSIPACKAGE
*package
, const WCHAR
*name
, msi_dialog
*parent
,
3897 control_event_handler event_handler
)
3899 MSIRECORD
*rec
= NULL
;
3902 TRACE("%s\n", debugstr_w(name
));
3904 if (!hMsiHiddenWindow
) dialog_register_class();
3906 /* allocate the structure for the dialog to use */
3907 dialog
= msi_alloc_zero( FIELD_OFFSET( msi_dialog
, name
[strlenW( name
) + 1] ));
3910 strcpyW( dialog
->name
, name
);
3911 dialog
->parent
= parent
;
3912 msiobj_addref( &package
->hdr
);
3913 dialog
->package
= package
;
3914 dialog
->event_handler
= event_handler
;
3915 dialog
->finished
= 0;
3916 list_init( &dialog
->controls
);
3917 list_init( &dialog
->fonts
);
3919 /* verify that the dialog exists */
3920 rec
= msi_get_dialog_record( dialog
);
3923 msiobj_release( &package
->hdr
);
3927 dialog
->attributes
= MSI_RecordGetInteger( rec
, 6 );
3928 dialog
->control_default
= strdupW( MSI_RecordGetString( rec
, 9 ) );
3929 dialog
->control_cancel
= strdupW( MSI_RecordGetString( rec
, 10 ) );
3930 msiobj_release( &rec
->hdr
);
3935 static void msi_dialog_end_dialog( msi_dialog
*dialog
)
3937 TRACE("%p\n", dialog
);
3938 dialog
->finished
= 1;
3939 PostMessageW(dialog
->hwnd
, WM_NULL
, 0, 0);
3942 void msi_dialog_check_messages( HANDLE handle
)
3946 /* in threads other than the UI thread, block */
3947 if( uiThreadId
!= GetCurrentThreadId() )
3949 if (!handle
) return;
3950 while (MsgWaitForMultipleObjectsEx( 1, &handle
, INFINITE
, QS_ALLINPUT
, 0 ) == WAIT_OBJECT_0
+ 1)
3953 while (PeekMessageW( &msg
, NULL
, 0, 0, PM_REMOVE
))
3955 TranslateMessage( &msg
);
3956 DispatchMessageW( &msg
);
3962 /* there are two choices for the UI thread */
3965 process_pending_messages( NULL
);
3971 * block here until somebody creates a new dialog or
3972 * the handle we're waiting on becomes ready
3974 r
= MsgWaitForMultipleObjects( 1, &handle
, 0, INFINITE
, QS_ALLINPUT
);
3975 if( r
== WAIT_OBJECT_0
)
3980 static void dialog_do_preview( msi_dialog
*dialog
)
3983 dialog
->attributes
|= msidbDialogAttributesVisible
;
3984 dialog
->attributes
&= ~msidbDialogAttributesModal
;
3985 dialog_run_message_loop( dialog
);
3988 static void free_subscriber( struct subscriber
*sub
)
3990 msi_free( sub
->event
);
3991 msi_free( sub
->control
);
3992 msi_free( sub
->attribute
);
3996 static void event_cleanup_subscriptions( MSIPACKAGE
*package
, const WCHAR
*dialog
)
3998 struct list
*item
, *next
;
4000 LIST_FOR_EACH_SAFE( item
, next
, &package
->subscriptions
)
4002 struct subscriber
*sub
= LIST_ENTRY( item
, struct subscriber
, entry
);
4004 if (strcmpW( sub
->dialog
->name
, dialog
)) continue;
4005 list_remove( &sub
->entry
);
4006 free_subscriber( sub
);
4010 void msi_dialog_destroy( msi_dialog
*dialog
)
4012 msi_font
*font
, *next
;
4014 if( uiThreadId
!= GetCurrentThreadId() )
4016 SendMessageW( hMsiHiddenWindow
, WM_MSI_DIALOG_DESTROY
, 0, (LPARAM
) dialog
);
4021 ShowWindow( dialog
->hwnd
, SW_HIDE
);
4024 DestroyWindow( dialog
->hwnd
);
4026 /* unsubscribe events */
4027 event_cleanup_subscriptions( dialog
->package
, dialog
->name
);
4029 /* destroy the list of controls */
4030 while( !list_empty( &dialog
->controls
) )
4034 t
= LIST_ENTRY( list_head( &dialog
->controls
),
4035 msi_control
, entry
);
4036 msi_destroy_control( t
);
4039 /* destroy the list of fonts */
4040 LIST_FOR_EACH_ENTRY_SAFE( font
, next
, &dialog
->fonts
, msi_font
, entry
)
4042 list_remove( &font
->entry
);
4043 DeleteObject( font
->hfont
);
4046 msi_free( dialog
->default_font
);
4048 msi_free( dialog
->control_default
);
4049 msi_free( dialog
->control_cancel
);
4050 msiobj_release( &dialog
->package
->hdr
);
4051 dialog
->package
= NULL
;
4055 void msi_dialog_unregister_class( void )
4057 DestroyWindow( hMsiHiddenWindow
);
4058 hMsiHiddenWindow
= NULL
;
4059 UnregisterClassW( szMsiDialogClass
, NULL
);
4060 UnregisterClassW( szMsiHiddenWindow
, NULL
);
4064 void msi_event_cleanup_all_subscriptions( MSIPACKAGE
*package
)
4066 struct list
*item
, *next
;
4068 LIST_FOR_EACH_SAFE( item
, next
, &package
->subscriptions
)
4070 struct subscriber
*sub
= LIST_ENTRY( item
, struct subscriber
, entry
);
4071 list_remove( &sub
->entry
);
4072 free_subscriber( sub
);
4076 static UINT
error_dialog_handler( msi_dialog
*dialog
, const WCHAR
*event
, const WCHAR
*argument
)
4078 static const WCHAR end_dialog
[] = {'E','n','d','D','i','a','l','o','g',0};
4079 static const WCHAR error_abort
[] = {'E','r','r','o','r','A','b','o','r','t',0};
4080 static const WCHAR error_cancel
[] = {'E','r','r','o','r','C','a','n','c','e','l',0};
4081 static const WCHAR error_no
[] = {'E','r','r','o','r','N','o',0};
4082 static const WCHAR result_prop
[] = {
4083 'M','S','I','E','r','r','o','r','D','i','a','l','o','g','R','e','s','u','l','t',0
4086 if ( strcmpW( event
, end_dialog
) )
4087 return ERROR_SUCCESS
;
4089 if ( !strcmpW( argument
, error_abort
) || !strcmpW( argument
, error_cancel
) ||
4090 !strcmpW( argument
, error_no
) )
4092 msi_set_property( dialog
->package
->db
, result_prop
, error_abort
, -1 );
4095 msi_event_cleanup_all_subscriptions( dialog
->package
);
4096 msi_dialog_end_dialog( dialog
);
4098 return ERROR_SUCCESS
;
4101 static UINT
msi_error_dialog_set_error( MSIPACKAGE
*package
, LPWSTR error_dialog
, LPWSTR error
)
4105 static const WCHAR update
[] =
4106 {'U','P','D','A','T','E',' ','`','C','o','n','t','r','o','l','`',' ',
4107 'S','E','T',' ','`','T','e','x','t','`',' ','=',' ','\'','%','s','\'',' ',
4108 'W','H','E','R','E', ' ','`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',' ',
4109 'A','N','D',' ','`','C','o','n','t','r','o','l','`',' ','=',' ',
4110 '\'','E','r','r','o','r','T','e','x','t','\'',0};
4112 row
= MSI_QueryGetRecord( package
->db
, update
, error
, error_dialog
);
4114 return ERROR_FUNCTION_FAILED
;
4116 msiobj_release(&row
->hdr
);
4117 return ERROR_SUCCESS
;
4120 UINT
msi_spawn_error_dialog( MSIPACKAGE
*package
, LPWSTR error_dialog
, LPWSTR error
)
4123 WCHAR result
[MAX_PATH
];
4124 UINT r
= ERROR_SUCCESS
;
4125 DWORD size
= MAX_PATH
;
4128 static const WCHAR pn_prop
[] = {'P','r','o','d','u','c','t','N','a','m','e',0};
4129 static const WCHAR title_fmt
[] = {'%','s',' ','W','a','r','n','i','n','g',0};
4130 static const WCHAR error_abort
[] = {'E','r','r','o','r','A','b','o','r','t',0};
4131 static const WCHAR result_prop
[] = {
4132 'M','S','I','E','r','r','o','r','D','i','a','l','o','g','R','e','s','u','l','t',0
4135 if ((package
->ui_level
& INSTALLUILEVEL_MASK
) == INSTALLUILEVEL_NONE
) return ERROR_SUCCESS
;
4137 if ( !error_dialog
)
4139 LPWSTR product_name
= msi_dup_property( package
->db
, pn_prop
);
4140 WCHAR title
[MAX_PATH
];
4142 sprintfW( title
, title_fmt
, product_name
);
4143 res
= MessageBoxW( NULL
, error
, title
, MB_OKCANCEL
| MB_ICONWARNING
);
4145 msi_free( product_name
);
4148 return ERROR_SUCCESS
;
4150 return ERROR_FUNCTION_FAILED
;
4153 r
= msi_error_dialog_set_error( package
, error_dialog
, error
);
4154 if ( r
!= ERROR_SUCCESS
)
4157 dialog
= dialog_create( package
, error_dialog
, package
->dialog
, error_dialog_handler
);
4159 return ERROR_FUNCTION_FAILED
;
4161 dialog
->finished
= FALSE
;
4162 r
= dialog_run_message_loop( dialog
);
4163 if ( r
!= ERROR_SUCCESS
)
4166 r
= msi_get_property( package
->db
, result_prop
, result
, &size
);
4167 if ( r
!= ERROR_SUCCESS
)
4170 if ( !strcmpW( result
, error_abort
) )
4171 r
= ERROR_FUNCTION_FAILED
;
4174 msi_dialog_destroy( dialog
);
4179 static void MSI_ClosePreview( MSIOBJECTHDR
*arg
)
4181 MSIPREVIEW
*preview
= (MSIPREVIEW
*)arg
;
4182 msiobj_release( &preview
->package
->hdr
);
4185 static MSIPREVIEW
*MSI_EnableUIPreview( MSIDATABASE
*db
)
4187 MSIPREVIEW
*preview
= NULL
;
4188 MSIPACKAGE
*package
;
4190 package
= MSI_CreatePackage( db
, NULL
);
4193 preview
= alloc_msiobject( MSIHANDLETYPE_PREVIEW
, sizeof(MSIPREVIEW
), MSI_ClosePreview
);
4196 preview
->package
= package
;
4197 msiobj_addref( &package
->hdr
);
4199 msiobj_release( &package
->hdr
);
4204 UINT WINAPI
MsiEnableUIPreview( MSIHANDLE hdb
, MSIHANDLE
*phPreview
)
4207 MSIPREVIEW
*preview
;
4208 UINT r
= ERROR_FUNCTION_FAILED
;
4210 TRACE("%d %p\n", hdb
, phPreview
);
4212 db
= msihandle2msiinfo( hdb
, MSIHANDLETYPE_DATABASE
);
4215 IWineMsiRemoteDatabase
*remote_database
;
4217 remote_database
= (IWineMsiRemoteDatabase
*)msi_get_remote( hdb
);
4218 if (!remote_database
)
4219 return ERROR_INVALID_HANDLE
;
4223 IWineMsiRemoteDatabase_Release( remote_database
);
4224 WARN("MsiEnableUIPreview not allowed during a custom action!\n");
4226 return ERROR_FUNCTION_FAILED
;
4228 preview
= MSI_EnableUIPreview( db
);
4231 *phPreview
= alloc_msihandle( &preview
->hdr
);
4232 msiobj_release( &preview
->hdr
);
4235 r
= ERROR_NOT_ENOUGH_MEMORY
;
4237 msiobj_release( &db
->hdr
);
4241 static UINT
preview_event_handler( msi_dialog
*dialog
, const WCHAR
*event
, const WCHAR
*argument
)
4243 MESSAGE("Preview dialog event '%s' (arg='%s')\n", debugstr_w(event
), debugstr_w(argument
));
4244 return ERROR_SUCCESS
;
4247 static UINT
MSI_PreviewDialogW( MSIPREVIEW
*preview
, LPCWSTR szDialogName
)
4249 msi_dialog
*dialog
= NULL
;
4250 UINT r
= ERROR_SUCCESS
;
4252 if (preview
->dialog
)
4253 msi_dialog_destroy( preview
->dialog
);
4255 /* an empty name means we should just destroy the current preview dialog */
4258 dialog
= dialog_create( preview
->package
, szDialogName
, NULL
, preview_event_handler
);
4260 dialog_do_preview( dialog
);
4262 r
= ERROR_FUNCTION_FAILED
;
4264 preview
->dialog
= dialog
;
4268 UINT WINAPI
MsiPreviewDialogW( MSIHANDLE hPreview
, LPCWSTR szDialogName
)
4270 MSIPREVIEW
*preview
;
4273 TRACE("%d %s\n", hPreview
, debugstr_w(szDialogName
));
4275 preview
= msihandle2msiinfo( hPreview
, MSIHANDLETYPE_PREVIEW
);
4277 return ERROR_INVALID_HANDLE
;
4279 r
= MSI_PreviewDialogW( preview
, szDialogName
);
4280 msiobj_release( &preview
->hdr
);
4284 UINT WINAPI
MsiPreviewDialogA( MSIHANDLE hPreview
, LPCSTR szDialogName
)
4289 TRACE("%d %s\n", hPreview
, debugstr_a(szDialogName
));
4293 strW
= strdupAtoW( szDialogName
);
4295 return ERROR_OUTOFMEMORY
;
4297 r
= MsiPreviewDialogW( hPreview
, strW
);
4302 UINT WINAPI
MsiPreviewBillboardW( MSIHANDLE hPreview
, LPCWSTR szControlName
, LPCWSTR szBillboard
)
4304 FIXME("%d %s %s\n", hPreview
, debugstr_w(szControlName
), debugstr_w(szBillboard
));
4305 return ERROR_CALL_NOT_IMPLEMENTED
;
4308 UINT WINAPI
MsiPreviewBillboardA( MSIHANDLE hPreview
, LPCSTR szControlName
, LPCSTR szBillboard
)
4310 FIXME("%d %s %s\n", hPreview
, debugstr_a(szControlName
), debugstr_a(szBillboard
));
4311 return ERROR_CALL_NOT_IMPLEMENTED
;
4314 typedef UINT (*event_handler
)( msi_dialog
*, const WCHAR
* );
4316 struct control_event
4319 event_handler handler
;
4322 static UINT
dialog_event_handler( msi_dialog
*, const WCHAR
*, const WCHAR
* );
4324 /* create a dialog box and run it if it's modal */
4325 static UINT
event_do_dialog( MSIPACKAGE
*package
, const WCHAR
*name
, msi_dialog
*parent
, BOOL destroy_modeless
)
4330 /* create a new dialog */
4331 dialog
= dialog_create( package
, name
, parent
, dialog_event_handler
);
4334 /* kill the current modeless dialog */
4335 if (destroy_modeless
&& package
->dialog
)
4337 msi_dialog_destroy( package
->dialog
);
4338 package
->dialog
= NULL
;
4341 /* modeless dialogs return an error message */
4342 r
= dialog_run_message_loop( dialog
);
4343 if (r
== ERROR_SUCCESS
)
4344 msi_dialog_destroy( dialog
);
4346 package
->dialog
= dialog
;
4348 else r
= ERROR_FUNCTION_FAILED
;
4352 /* end a modal dialog box */
4353 static UINT
event_end_dialog( msi_dialog
*dialog
, const WCHAR
*argument
)
4355 static const WCHAR exitW
[] = {'E','x','i','t',0};
4356 static const WCHAR retryW
[] = {'R','e','t','r','y',0};
4357 static const WCHAR ignoreW
[] = {'I','g','n','o','r','e',0};
4358 static const WCHAR returnW
[] = {'R','e','t','u','r','n',0};
4360 if (!strcmpW( argument
, exitW
))
4361 dialog
->package
->CurrentInstallState
= ERROR_INSTALL_USEREXIT
;
4362 else if (!strcmpW( argument
, retryW
))
4363 dialog
->package
->CurrentInstallState
= ERROR_INSTALL_SUSPEND
;
4364 else if (!strcmpW( argument
, ignoreW
))
4365 dialog
->package
->CurrentInstallState
= ERROR_SUCCESS
;
4366 else if (!strcmpW( argument
, returnW
))
4368 msi_dialog
*parent
= dialog
->parent
;
4369 msi_free( dialog
->package
->next_dialog
);
4370 dialog
->package
->next_dialog
= (parent
) ? strdupW( parent
->name
) : NULL
;
4371 dialog
->package
->CurrentInstallState
= ERROR_SUCCESS
;
4375 ERR("Unknown argument string %s\n", debugstr_w(argument
));
4376 dialog
->package
->CurrentInstallState
= ERROR_FUNCTION_FAILED
;
4378 event_cleanup_subscriptions( dialog
->package
, dialog
->name
);
4379 msi_dialog_end_dialog( dialog
);
4380 return ERROR_SUCCESS
;
4383 /* transition from one modal dialog to another modal dialog */
4384 static UINT
event_new_dialog( msi_dialog
*dialog
, const WCHAR
*argument
)
4386 /* store the name of the next dialog, and signal this one to end */
4387 dialog
->package
->next_dialog
= strdupW( argument
);
4388 msi_event_cleanup_all_subscriptions( dialog
->package
);
4389 msi_dialog_end_dialog( dialog
);
4390 return ERROR_SUCCESS
;
4393 /* create a new child dialog of an existing modal dialog */
4394 static UINT
event_spawn_dialog( msi_dialog
*dialog
, const WCHAR
*argument
)
4396 /* don't destroy a modeless dialogs that might be our parent */
4397 event_do_dialog( dialog
->package
, argument
, dialog
, FALSE
);
4398 if (dialog
->package
->CurrentInstallState
!= ERROR_SUCCESS
) msi_dialog_end_dialog( dialog
);
4399 return ERROR_SUCCESS
;
4402 /* creates a dialog that remains up for a period of time based on a condition */
4403 static UINT
event_spawn_wait_dialog( msi_dialog
*dialog
, const WCHAR
*argument
)
4405 FIXME("doing nothing\n");
4406 return ERROR_SUCCESS
;
4409 static UINT
event_do_action( msi_dialog
*dialog
, const WCHAR
*argument
)
4411 ACTION_PerformAction( dialog
->package
, argument
, SCRIPT_NONE
);
4412 return ERROR_SUCCESS
;
4415 static UINT
event_add_local( msi_dialog
*dialog
, const WCHAR
*argument
)
4417 MSIFEATURE
*feature
;
4419 LIST_FOR_EACH_ENTRY( feature
, &dialog
->package
->features
, MSIFEATURE
, entry
)
4421 if (!strcmpW( argument
, feature
->Feature
) || !strcmpW( argument
, szAll
))
4423 if (feature
->ActionRequest
!= INSTALLSTATE_LOCAL
)
4424 msi_set_property( dialog
->package
->db
, szPreselected
, szOne
, -1 );
4425 MSI_SetFeatureStateW( dialog
->package
, feature
->Feature
, INSTALLSTATE_LOCAL
);
4428 return ERROR_SUCCESS
;
4431 static UINT
event_remove( msi_dialog
*dialog
, const WCHAR
*argument
)
4433 MSIFEATURE
*feature
;
4435 LIST_FOR_EACH_ENTRY( feature
, &dialog
->package
->features
, MSIFEATURE
, entry
)
4437 if (!strcmpW( argument
, feature
->Feature
) || !strcmpW( argument
, szAll
))
4439 if (feature
->ActionRequest
!= INSTALLSTATE_ABSENT
)
4440 msi_set_property( dialog
->package
->db
, szPreselected
, szOne
, -1 );
4441 MSI_SetFeatureStateW( dialog
->package
, feature
->Feature
, INSTALLSTATE_ABSENT
);
4444 return ERROR_SUCCESS
;
4447 static UINT
event_add_source( msi_dialog
*dialog
, const WCHAR
*argument
)
4449 MSIFEATURE
*feature
;
4451 LIST_FOR_EACH_ENTRY( feature
, &dialog
->package
->features
, MSIFEATURE
, entry
)
4453 if (!strcmpW( argument
, feature
->Feature
) || !strcmpW( argument
, szAll
))
4455 if (feature
->ActionRequest
!= INSTALLSTATE_SOURCE
)
4456 msi_set_property( dialog
->package
->db
, szPreselected
, szOne
, -1 );
4457 MSI_SetFeatureStateW( dialog
->package
, feature
->Feature
, INSTALLSTATE_SOURCE
);
4460 return ERROR_SUCCESS
;
4463 void msi_event_fire( MSIPACKAGE
*package
, const WCHAR
*event
, MSIRECORD
*rec
)
4465 struct subscriber
*sub
;
4467 TRACE("firing event %s\n", debugstr_w(event
));
4469 LIST_FOR_EACH_ENTRY( sub
, &package
->subscriptions
, struct subscriber
, entry
)
4471 if (strcmpiW( sub
->event
, event
)) continue;
4472 dialog_handle_event( sub
->dialog
, sub
->control
, sub
->attribute
, rec
);
4476 static UINT
event_set_target_path( msi_dialog
*dialog
, const WCHAR
*argument
)
4478 WCHAR
*path
= msi_dup_property( dialog
->package
->db
, argument
);
4479 MSIRECORD
*rec
= MSI_CreateRecord( 1 );
4480 UINT r
= ERROR_SUCCESS
;
4482 MSI_RecordSetStringW( rec
, 1, path
);
4483 msi_event_fire( dialog
->package
, szSelectionPath
, rec
);
4486 /* failure to set the path halts the executing of control events */
4487 r
= MSI_SetTargetPathW( dialog
->package
, argument
, path
);
4490 msi_free( &rec
->hdr
);
4494 static UINT
event_reset( msi_dialog
*dialog
, const WCHAR
*argument
)
4496 msi_dialog_reset( dialog
);
4497 return ERROR_SUCCESS
;
4500 /* Return ERROR_SUCCESS if dialog is process and ERROR_FUNCTION_FAILED
4501 * if the given parameter is not a dialog box
4503 UINT
ACTION_DialogBox( MSIPACKAGE
*package
, const WCHAR
*dialog
)
4507 if (package
->next_dialog
) ERR("Already got next dialog... ignoring it\n");
4508 package
->next_dialog
= NULL
;
4510 /* Dialogs are chained by filling in the next_dialog member
4511 * of the package structure, then terminating the current dialog.
4512 * The code below sees the next_dialog member set, and runs the
4514 * We fall out of the loop below if we come across a modeless
4515 * dialog, as it returns ERROR_IO_PENDING when we try to run
4518 r
= event_do_dialog( package
, dialog
, NULL
, TRUE
);
4519 while (r
== ERROR_SUCCESS
&& package
->next_dialog
)
4521 WCHAR
*name
= package
->next_dialog
;
4523 package
->next_dialog
= NULL
;
4524 r
= event_do_dialog( package
, name
, NULL
, TRUE
);
4527 if (r
== ERROR_IO_PENDING
) r
= ERROR_SUCCESS
;
4531 static UINT
event_set_install_level( msi_dialog
*dialog
, const WCHAR
*argument
)
4533 int level
= atolW( argument
);
4535 TRACE("setting install level to %d\n", level
);
4536 return MSI_SetInstallLevel( dialog
->package
, level
);
4539 static UINT
event_directory_list_up( msi_dialog
*dialog
, const WCHAR
*argument
)
4541 return msi_dialog_directorylist_up( dialog
);
4544 static UINT
event_reinstall_mode( msi_dialog
*dialog
, const WCHAR
*argument
)
4546 return msi_set_property( dialog
->package
->db
, szReinstallMode
, argument
, -1 );
4549 static UINT
event_reinstall( msi_dialog
*dialog
, const WCHAR
*argument
)
4551 return msi_set_property( dialog
->package
->db
, szReinstall
, argument
, -1 );
4554 static UINT
event_validate_product_id( msi_dialog
*dialog
, const WCHAR
*argument
)
4556 return msi_validate_product_id( dialog
->package
);
4559 static const WCHAR end_dialogW
[] = {'E','n','d','D','i','a','l','o','g',0};
4560 static const WCHAR new_dialogW
[] = {'N','e','w','D','i','a','l','o','g',0};
4561 static const WCHAR spawn_dialogW
[] = {'S','p','a','w','n','D','i','a','l','o','g',0};
4562 static const WCHAR spawn_wait_dialogW
[] = {'S','p','a','w','n','W','a','i','t','D','i','a','l','o','g',0};
4563 static const WCHAR do_actionW
[] = {'D','o','A','c','t','i','o','n',0};
4564 static const WCHAR add_localW
[] = {'A','d','d','L','o','c','a','l',0};
4565 static const WCHAR removeW
[] = {'R','e','m','o','v','e',0};
4566 static const WCHAR add_sourceW
[] = {'A','d','d','S','o','u','r','c','e',0};
4567 static const WCHAR set_target_pathW
[] = {'S','e','t','T','a','r','g','e','t','P','a','t','h',0};
4568 static const WCHAR resetW
[] = {'R','e','s','e','t',0};
4569 static const WCHAR set_install_levelW
[] = {'S','e','t','I','n','s','t','a','l','l','L','e','v','e','l',0};
4570 static const WCHAR directory_list_upW
[] = {'D','i','r','e','c','t','o','r','y','L','i','s','t','U','p',0};
4571 static const WCHAR selection_browseW
[] = {'S','e','l','e','c','t','i','o','n','B','r','o','w','s','e',0};
4572 static const WCHAR reinstall_modeW
[] = {'R','e','i','n','s','t','a','l','l','M','o','d','e',0};
4573 static const WCHAR reinstallW
[] = {'R','e','i','n','s','t','a','l','l',0};
4574 static const WCHAR validate_product_idW
[] = {'V','a','l','i','d','a','t','e','P','r','o','d','u','c','t','I','D',0};
4576 static const struct control_event control_events
[] =
4578 { end_dialogW
, event_end_dialog
},
4579 { new_dialogW
, event_new_dialog
},
4580 { spawn_dialogW
, event_spawn_dialog
},
4581 { spawn_wait_dialogW
, event_spawn_wait_dialog
},
4582 { do_actionW
, event_do_action
},
4583 { add_localW
, event_add_local
},
4584 { removeW
, event_remove
},
4585 { add_sourceW
, event_add_source
},
4586 { set_target_pathW
, event_set_target_path
},
4587 { resetW
, event_reset
},
4588 { set_install_levelW
, event_set_install_level
},
4589 { directory_list_upW
, event_directory_list_up
},
4590 { selection_browseW
, event_spawn_dialog
},
4591 { reinstall_modeW
, event_reinstall_mode
},
4592 { reinstallW
, event_reinstall
},
4593 { validate_product_idW
, event_validate_product_id
},
4597 static UINT
dialog_event_handler( msi_dialog
*dialog
, const WCHAR
*event
, const WCHAR
*argument
)
4601 TRACE("handling event %s\n", debugstr_w(event
));
4603 if (!event
) return ERROR_SUCCESS
;
4605 for (i
= 0; control_events
[i
].event
; i
++)
4607 if (!strcmpW( control_events
[i
].event
, event
))
4608 return control_events
[i
].handler( dialog
, argument
);
4610 FIXME("unhandled event %s arg(%s)\n", debugstr_w(event
), debugstr_w(argument
));
4611 return ERROR_SUCCESS
;