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
23 #define NONAMELESSUNION
24 #define NONAMELESSSTRUCT
42 #include "msiserver.h"
45 #include "wine/debug.h"
46 #include "wine/unicode.h"
48 WINE_DEFAULT_DEBUG_CHANNEL(msi
);
50 extern HINSTANCE msi_hInstance
;
52 struct msi_control_tag
;
53 typedef struct msi_control_tag msi_control
;
54 typedef UINT (*msi_handler
)( msi_dialog
*, msi_control
*, WPARAM
);
55 typedef void (*msi_update
)( msi_dialog
*, msi_control
* );
56 typedef UINT (*control_event_handler
)( msi_dialog
*, const WCHAR
*, const WCHAR
* );
58 struct msi_control_tag
71 float progress_current
;
73 BOOL progress_backwards
;
78 typedef struct msi_font_tag
90 control_event_handler event_handler
;
100 LPWSTR control_default
;
101 LPWSTR control_cancel
;
114 typedef UINT (*msi_dialog_control_func
)( msi_dialog
*dialog
, MSIRECORD
*rec
);
115 struct control_handler
117 LPCWSTR control_type
;
118 msi_dialog_control_func func
;
127 } radio_button_group_descr
;
129 static const WCHAR szMsiDialogClass
[] = { 'M','s','i','D','i','a','l','o','g','C','l','o','s','e','C','l','a','s','s',0 };
130 static const WCHAR szMsiHiddenWindow
[] = { 'M','s','i','H','i','d','d','e','n','W','i','n','d','o','w',0 };
131 static const WCHAR szStatic
[] = { 'S','t','a','t','i','c',0 };
132 static const WCHAR szButton
[] = { 'B','U','T','T','O','N', 0 };
133 static const WCHAR szButtonData
[] = { 'M','S','I','D','A','T','A',0 };
134 static const WCHAR szProgress
[] = { 'P','r','o','g','r','e','s','s',0 };
135 static const WCHAR szText
[] = { 'T','e','x','t',0 };
136 static const WCHAR szPushButton
[] = { 'P','u','s','h','B','u','t','t','o','n',0 };
137 static const WCHAR szLine
[] = { 'L','i','n','e',0 };
138 static const WCHAR szBitmap
[] = { 'B','i','t','m','a','p',0 };
139 static const WCHAR szCheckBox
[] = { 'C','h','e','c','k','B','o','x',0 };
140 static const WCHAR szScrollableText
[] = { 'S','c','r','o','l','l','a','b','l','e','T','e','x','t',0 };
141 static const WCHAR szComboBox
[] = { 'C','o','m','b','o','B','o','x',0 };
142 static const WCHAR szEdit
[] = { 'E','d','i','t',0 };
143 static const WCHAR szMaskedEdit
[] = { 'M','a','s','k','e','d','E','d','i','t',0 };
144 static const WCHAR szPathEdit
[] = { 'P','a','t','h','E','d','i','t',0 };
145 static const WCHAR szProgressBar
[] = { 'P','r','o','g','r','e','s','s','B','a','r',0 };
146 static const WCHAR szSetProgress
[] = { 'S','e','t','P','r','o','g','r','e','s','s',0 };
147 static const WCHAR szRadioButtonGroup
[] = { 'R','a','d','i','o','B','u','t','t','o','n','G','r','o','u','p',0 };
148 static const WCHAR szIcon
[] = { 'I','c','o','n',0 };
149 static const WCHAR szSelectionTree
[] = { 'S','e','l','e','c','t','i','o','n','T','r','e','e',0 };
150 static const WCHAR szGroupBox
[] = { 'G','r','o','u','p','B','o','x',0 };
151 static const WCHAR szListBox
[] = { 'L','i','s','t','B','o','x',0 };
152 static const WCHAR szDirectoryCombo
[] = { 'D','i','r','e','c','t','o','r','y','C','o','m','b','o',0 };
153 static const WCHAR szDirectoryList
[] = { 'D','i','r','e','c','t','o','r','y','L','i','s','t',0 };
154 static const WCHAR szVolumeCostList
[] = { 'V','o','l','u','m','e','C','o','s','t','L','i','s','t',0 };
155 static const WCHAR szVolumeSelectCombo
[] = { 'V','o','l','u','m','e','S','e','l','e','c','t','C','o','m','b','o',0 };
156 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};
157 static const WCHAR szSelectionPath
[] = {'S','e','l','e','c','t','i','o','n','P','a','t','h',0};
158 static const WCHAR szProperty
[] = {'P','r','o','p','e','r','t','y',0};
159 static const WCHAR szHyperLink
[] = {'H','y','p','e','r','L','i','n','k',0};
161 /* dialog sequencing */
163 #define WM_MSI_DIALOG_CREATE (WM_USER+0x100)
164 #define WM_MSI_DIALOG_DESTROY (WM_USER+0x101)
166 #define USER_INSTALLSTATE_ALL 0x1000
168 static DWORD uiThreadId
;
169 static HWND hMsiHiddenWindow
;
171 static LPWSTR
msi_get_window_text( HWND hwnd
)
177 buf
= msi_alloc( sz
*sizeof(WCHAR
) );
180 r
= GetWindowTextW( hwnd
, buf
, sz
);
184 buf
= msi_realloc( buf
, sz
*sizeof(WCHAR
) );
190 static INT
msi_dialog_scale_unit( msi_dialog
*dialog
, INT val
)
192 return MulDiv( val
, dialog
->scale
, 12 );
195 static msi_control
*msi_dialog_find_control( msi_dialog
*dialog
, LPCWSTR name
)
197 msi_control
*control
;
203 LIST_FOR_EACH_ENTRY( control
, &dialog
->controls
, msi_control
, entry
)
204 if( !strcmpW( control
->name
, name
) ) /* FIXME: case sensitive? */
209 static msi_control
*msi_dialog_find_control_by_type( msi_dialog
*dialog
, LPCWSTR type
)
211 msi_control
*control
;
217 LIST_FOR_EACH_ENTRY( control
, &dialog
->controls
, msi_control
, entry
)
218 if( !strcmpW( control
->type
, type
) ) /* FIXME: case sensitive? */
223 static msi_control
*msi_dialog_find_control_by_hwnd( msi_dialog
*dialog
, HWND hwnd
)
225 msi_control
*control
;
229 LIST_FOR_EACH_ENTRY( control
, &dialog
->controls
, msi_control
, entry
)
230 if( hwnd
== control
->hwnd
)
235 static LPWSTR
msi_get_deformatted_field( MSIPACKAGE
*package
, MSIRECORD
*rec
, int field
)
237 LPCWSTR str
= MSI_RecordGetString( rec
, field
);
241 deformat_string( package
, str
, &ret
);
245 static LPWSTR
msi_dialog_dup_property( msi_dialog
*dialog
, LPCWSTR property
, BOOL indirect
)
253 prop
= msi_dup_property( dialog
->package
->db
, property
);
256 prop
= strdupW( property
);
262 * msi_dialog_get_style
264 * Extract the {\style} string from the front of the text to display and
265 * update the pointer. Only the last style in a list is applied.
267 static LPWSTR
msi_dialog_get_style( LPCWSTR p
, LPCWSTR
*rest
)
278 while ((first
= strchrW( p
, '{' )) && (q
= strchrW( first
+ 1, '}' )))
281 if( *p
!= '\\' && *p
!= '&' )
284 /* little bit of sanity checking to stop us getting confused with RTF */
285 for( i
=++p
; i
<q
; i
++ )
286 if( *i
== '}' || *i
== '\\' )
296 ret
= msi_alloc( len
*sizeof(WCHAR
) );
299 memcpy( ret
, p
, len
*sizeof(WCHAR
) );
304 static UINT
msi_dialog_add_font( MSIRECORD
*rec
, LPVOID param
)
306 msi_dialog
*dialog
= param
;
313 /* create a font and add it to the list */
314 name
= MSI_RecordGetString( rec
, 1 );
315 font
= msi_alloc( FIELD_OFFSET( msi_font
, name
[strlenW( name
) + 1] ));
316 strcpyW( font
->name
, name
);
317 list_add_head( &dialog
->fonts
, &font
->entry
);
319 font
->color
= MSI_RecordGetInteger( rec
, 4 );
321 memset( &lf
, 0, sizeof lf
);
322 face
= MSI_RecordGetString( rec
, 2 );
323 lf
.lfHeight
= MSI_RecordGetInteger( rec
, 3 );
324 style
= MSI_RecordGetInteger( rec
, 5 );
325 if( style
& msidbTextStyleStyleBitsBold
)
326 lf
.lfWeight
= FW_BOLD
;
327 if( style
& msidbTextStyleStyleBitsItalic
)
329 if( style
& msidbTextStyleStyleBitsUnderline
)
330 lf
.lfUnderline
= TRUE
;
331 if( style
& msidbTextStyleStyleBitsStrike
)
332 lf
.lfStrikeOut
= TRUE
;
333 lstrcpynW( lf
.lfFaceName
, face
, LF_FACESIZE
);
335 /* adjust the height */
336 hdc
= GetDC( dialog
->hwnd
);
339 lf
.lfHeight
= -MulDiv(lf
.lfHeight
, GetDeviceCaps(hdc
, LOGPIXELSY
), 72);
340 ReleaseDC( dialog
->hwnd
, hdc
);
343 font
->hfont
= CreateFontIndirectW( &lf
);
345 TRACE("Adding font style %s\n", debugstr_w(font
->name
) );
347 return ERROR_SUCCESS
;
350 static msi_font
*msi_dialog_find_font( msi_dialog
*dialog
, LPCWSTR name
)
352 msi_font
*font
= NULL
;
354 LIST_FOR_EACH_ENTRY( font
, &dialog
->fonts
, msi_font
, entry
)
355 if( !strcmpW( font
->name
, name
) ) /* FIXME: case sensitive? */
361 static UINT
msi_dialog_set_font( msi_dialog
*dialog
, HWND hwnd
, LPCWSTR name
)
365 font
= msi_dialog_find_font( dialog
, name
);
367 SendMessageW( hwnd
, WM_SETFONT
, (WPARAM
) font
->hfont
, TRUE
);
369 ERR("No font entry for %s\n", debugstr_w(name
));
370 return ERROR_SUCCESS
;
373 static UINT
msi_dialog_build_font_list( msi_dialog
*dialog
)
375 static const WCHAR query
[] = {
376 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
377 '`','T','e','x','t','S','t','y','l','e','`',0};
381 TRACE("dialog %p\n", dialog
);
383 r
= MSI_OpenQuery( dialog
->package
->db
, &view
, query
);
384 if( r
!= ERROR_SUCCESS
)
387 r
= MSI_IterateRecords( view
, NULL
, msi_dialog_add_font
, dialog
);
388 msiobj_release( &view
->hdr
);
392 static void msi_destroy_control( msi_control
*t
)
394 list_remove( &t
->entry
);
395 /* leave dialog->hwnd - destroying parent destroys child windows */
396 msi_free( t
->property
);
397 msi_free( t
->value
);
399 DeleteObject( t
->hBitmap
);
401 DestroyIcon( t
->hIcon
);
402 msi_free( t
->tabnext
);
405 FreeLibrary( t
->hDll
);
409 static msi_control
*dialog_create_window( msi_dialog
*dialog
, MSIRECORD
*rec
, DWORD exstyle
,
410 const WCHAR
*szCls
, const WCHAR
*name
, const WCHAR
*text
,
411 DWORD style
, HWND parent
)
413 DWORD x
, y
, width
, height
;
414 LPWSTR font
= NULL
, title_font
= NULL
;
415 LPCWSTR title
= NULL
;
416 msi_control
*control
;
420 control
= msi_alloc( FIELD_OFFSET( msi_control
, name
[strlenW( name
) + 1] ));
424 strcpyW( control
->name
, name
);
425 list_add_tail( &dialog
->controls
, &control
->entry
);
426 control
->handler
= NULL
;
427 control
->update
= NULL
;
428 control
->property
= NULL
;
429 control
->value
= NULL
;
430 control
->hBitmap
= NULL
;
431 control
->hIcon
= NULL
;
432 control
->hDll
= NULL
;
433 control
->tabnext
= strdupW( MSI_RecordGetString( rec
, 11) );
434 control
->type
= strdupW( MSI_RecordGetString( rec
, 3 ) );
435 control
->progress_current
= 0;
436 control
->progress_max
= 100;
437 control
->progress_backwards
= FALSE
;
439 x
= MSI_RecordGetInteger( rec
, 4 );
440 y
= MSI_RecordGetInteger( rec
, 5 );
441 width
= MSI_RecordGetInteger( rec
, 6 );
442 height
= MSI_RecordGetInteger( rec
, 7 );
444 x
= msi_dialog_scale_unit( dialog
, x
);
445 y
= msi_dialog_scale_unit( dialog
, y
);
446 width
= msi_dialog_scale_unit( dialog
, width
);
447 height
= msi_dialog_scale_unit( dialog
, height
);
451 deformat_string( dialog
->package
, text
, &title_font
);
452 font
= msi_dialog_get_style( title_font
, &title
);
455 control
->hwnd
= CreateWindowExW( exstyle
, szCls
, title
, style
,
456 x
, y
, width
, height
, parent
, NULL
, NULL
, NULL
);
458 TRACE("Dialog %s control %s hwnd %p\n",
459 debugstr_w(dialog
->name
), debugstr_w(text
), control
->hwnd
);
461 msi_dialog_set_font( dialog
, control
->hwnd
,
462 font
? font
: dialog
->default_font
);
464 msi_free( title_font
);
470 static LPWSTR
msi_dialog_get_uitext( msi_dialog
*dialog
, LPCWSTR key
)
475 static const WCHAR query
[] = {
476 's','e','l','e','c','t',' ','*',' ',
477 'f','r','o','m',' ','`','U','I','T','e','x','t','`',' ',
478 'w','h','e','r','e',' ','`','K','e','y','`',' ','=',' ','\'','%','s','\'',0
481 rec
= MSI_QueryGetRecord( dialog
->package
->db
, query
, key
);
482 if (!rec
) return NULL
;
483 text
= strdupW( MSI_RecordGetString( rec
, 2 ) );
484 msiobj_release( &rec
->hdr
);
488 static MSIRECORD
*msi_get_binary_record( MSIDATABASE
*db
, LPCWSTR name
)
490 static const WCHAR query
[] = {
491 's','e','l','e','c','t',' ','*',' ',
492 'f','r','o','m',' ','B','i','n','a','r','y',' ',
493 'w','h','e','r','e',' ',
494 '`','N','a','m','e','`',' ','=',' ','\'','%','s','\'',0
497 return MSI_QueryGetRecord( db
, query
, name
);
500 static LPWSTR
msi_create_tmp_path(void)
506 r
= GetTempPathW( MAX_PATH
, tmp
);
509 len
= lstrlenW( tmp
) + 20;
510 path
= msi_alloc( len
* sizeof (WCHAR
) );
513 r
= GetTempFileNameW( tmp
, szMsi
, 0, path
);
523 static HANDLE
msi_load_image( MSIDATABASE
*db
, LPCWSTR name
, UINT type
,
524 UINT cx
, UINT cy
, UINT flags
)
526 MSIRECORD
*rec
= NULL
;
527 HANDLE himage
= NULL
;
531 TRACE("%p %s %u %u %08x\n", db
, debugstr_w(name
), cx
, cy
, flags
);
533 tmp
= msi_create_tmp_path();
537 rec
= msi_get_binary_record( db
, name
);
540 r
= MSI_RecordStreamToFile( rec
, 2, tmp
);
541 if( r
== ERROR_SUCCESS
)
543 himage
= LoadImageW( 0, tmp
, type
, cx
, cy
, flags
);
545 msiobj_release( &rec
->hdr
);
553 static HICON
msi_load_icon( MSIDATABASE
*db
, LPCWSTR text
, UINT attributes
)
555 DWORD cx
= 0, cy
= 0, flags
;
557 flags
= LR_LOADFROMFILE
| LR_DEFAULTSIZE
;
558 if( attributes
& msidbControlAttributesFixedSize
)
560 flags
&= ~LR_DEFAULTSIZE
;
561 if( attributes
& msidbControlAttributesIconSize16
)
566 if( attributes
& msidbControlAttributesIconSize32
)
571 /* msidbControlAttributesIconSize48 handled by above logic */
573 return msi_load_image( db
, text
, IMAGE_ICON
, cx
, cy
, flags
);
576 static void msi_dialog_update_controls( msi_dialog
*dialog
, LPCWSTR property
)
578 msi_control
*control
;
580 LIST_FOR_EACH_ENTRY( control
, &dialog
->controls
, msi_control
, entry
)
582 if ( control
->property
&& !strcmpW( control
->property
, property
) && control
->update
)
583 control
->update( dialog
, control
);
587 static void msi_dialog_set_property( MSIPACKAGE
*package
, LPCWSTR property
, LPCWSTR value
)
589 UINT r
= msi_set_property( package
->db
, property
, value
, -1 );
590 if (r
== ERROR_SUCCESS
&& !strcmpW( property
, szSourceDir
))
591 msi_reset_folders( package
, TRUE
);
594 static MSIFEATURE
*msi_seltree_feature_from_item( HWND hwnd
, HTREEITEM hItem
)
598 /* get the feature from the item */
599 memset( &tvi
, 0, sizeof tvi
);
601 tvi
.mask
= TVIF_PARAM
| TVIF_HANDLE
;
602 SendMessageW( hwnd
, TVM_GETITEMW
, 0, (LPARAM
)&tvi
);
603 return (MSIFEATURE
*)tvi
.lParam
;
606 struct msi_selection_tree_info
614 static MSIFEATURE
*msi_seltree_get_selected_feature( msi_control
*control
)
616 struct msi_selection_tree_info
*info
= GetPropW( control
->hwnd
, szButtonData
);
617 return msi_seltree_feature_from_item( control
->hwnd
, info
->selected
);
620 static void dialog_handle_event( msi_dialog
*dialog
, const WCHAR
*control
,
621 const WCHAR
*attribute
, MSIRECORD
*rec
)
625 ctrl
= msi_dialog_find_control( dialog
, control
);
628 if( !strcmpW( attribute
, szText
) )
630 const WCHAR
*font_text
, *text
= NULL
;
631 WCHAR
*font
, *text_fmt
= NULL
;
633 font_text
= MSI_RecordGetString( rec
, 1 );
634 font
= msi_dialog_get_style( font_text
, &text
);
635 deformat_string( dialog
->package
, text
, &text_fmt
);
636 if (text_fmt
) text
= text_fmt
;
639 SetWindowTextW( ctrl
->hwnd
, text
);
642 msi_free( text_fmt
);
643 msi_dialog_check_messages( NULL
);
645 else if( !strcmpW( attribute
, szProgress
) )
647 DWORD func
, val1
, val2
, units
;
649 func
= MSI_RecordGetInteger( rec
, 1 );
650 val1
= MSI_RecordGetInteger( rec
, 2 );
651 val2
= MSI_RecordGetInteger( rec
, 3 );
653 TRACE("progress: func %u val1 %u val2 %u\n", func
, val1
, val2
);
659 SendMessageW( ctrl
->hwnd
, PBM_SETRANGE
, 0, MAKELPARAM(0,100) );
662 ctrl
->progress_max
= units
? units
: 100;
663 ctrl
->progress_current
= units
;
664 ctrl
->progress_backwards
= TRUE
;
665 SendMessageW( ctrl
->hwnd
, PBM_SETPOS
, 100, 0 );
669 ctrl
->progress_max
= units
? units
: 100;
670 ctrl
->progress_current
= 0;
671 ctrl
->progress_backwards
= FALSE
;
672 SendMessageW( ctrl
->hwnd
, PBM_SETPOS
, 0, 0 );
675 case 1: /* action data increment */
676 if (val2
) dialog
->package
->action_progress_increment
= val1
;
677 else dialog
->package
->action_progress_increment
= 0;
680 if (ctrl
->progress_backwards
)
682 if (units
>= ctrl
->progress_current
) ctrl
->progress_current
-= units
;
683 else ctrl
->progress_current
= 0;
687 if (ctrl
->progress_current
+ units
< ctrl
->progress_max
) ctrl
->progress_current
+= units
;
688 else ctrl
->progress_current
= ctrl
->progress_max
;
690 SendMessageW( ctrl
->hwnd
, PBM_SETPOS
, MulDiv(100, ctrl
->progress_current
, ctrl
->progress_max
), 0 );
693 ctrl
->progress_max
+= units
;
696 FIXME("Unknown progress message %u\n", func
);
700 else if ( !strcmpW( attribute
, szProperty
) )
702 MSIFEATURE
*feature
= msi_seltree_get_selected_feature( ctrl
);
703 if (feature
) msi_dialog_set_property( dialog
->package
, ctrl
->property
, feature
->Directory
);
705 else if ( !strcmpW( attribute
, szSelectionPath
) )
707 BOOL indirect
= ctrl
->attributes
& msidbControlAttributesIndirect
;
708 LPWSTR path
= msi_dialog_dup_property( dialog
, ctrl
->property
, indirect
);
710 SetWindowTextW( ctrl
->hwnd
, path
);
715 FIXME("Attribute %s not being set\n", debugstr_w(attribute
));
720 static void event_subscribe( msi_dialog
*dialog
, const WCHAR
*event
, const WCHAR
*control
, const WCHAR
*attribute
)
722 struct subscriber
*sub
;
724 TRACE("event %s control %s attribute %s\n", debugstr_w(event
), debugstr_w(control
), debugstr_w(attribute
));
726 LIST_FOR_EACH_ENTRY( sub
, &dialog
->package
->subscriptions
, struct subscriber
, entry
)
728 if (!strcmpiW( sub
->event
, event
) &&
729 !strcmpiW( sub
->control
, control
) &&
730 !strcmpiW( sub
->attribute
, attribute
))
732 TRACE("already subscribed\n");
736 if (!(sub
= msi_alloc( sizeof(*sub
) ))) return;
737 sub
->dialog
= dialog
;
738 sub
->event
= strdupW( event
);
739 sub
->control
= strdupW( control
);
740 sub
->attribute
= strdupW( attribute
);
741 list_add_tail( &dialog
->package
->subscriptions
, &sub
->entry
);
744 struct dialog_control
747 const WCHAR
*control
;
750 static UINT
map_event( MSIRECORD
*row
, void *param
)
752 struct dialog_control
*dc
= param
;
753 const WCHAR
*event
= MSI_RecordGetString( row
, 3 );
754 const WCHAR
*attribute
= MSI_RecordGetString( row
, 4 );
756 event_subscribe( dc
->dialog
, event
, dc
->control
, attribute
);
757 return ERROR_SUCCESS
;
760 static void dialog_map_events( msi_dialog
*dialog
, const WCHAR
*control
)
762 static const WCHAR queryW
[] =
763 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
764 '`','E','v','e','n','t','M','a','p','p','i','n','g','`',' ',
765 'W','H','E','R','E',' ','`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',' ',
766 'A','N','D',' ','`','C','o','n','t','r','o','l','_','`',' ','=',' ','\'','%','s','\'',0};
768 struct dialog_control dialog_control
=
774 if (!MSI_OpenQuery( dialog
->package
->db
, &view
, queryW
, dialog
->name
, control
))
776 MSI_IterateRecords( view
, NULL
, map_event
, &dialog_control
);
777 msiobj_release( &view
->hdr
);
781 /* everything except radio buttons */
782 static msi_control
*msi_dialog_add_control( msi_dialog
*dialog
,
783 MSIRECORD
*rec
, LPCWSTR szCls
, DWORD style
)
786 const WCHAR
*text
= NULL
, *name
, *control_type
;
789 name
= MSI_RecordGetString( rec
, 2 );
790 control_type
= MSI_RecordGetString( rec
, 3 );
791 attributes
= MSI_RecordGetInteger( rec
, 8 );
792 if (strcmpW( control_type
, szScrollableText
)) text
= MSI_RecordGetString( rec
, 10 );
794 TRACE("%s, %s, %08x, %s, %08x\n", debugstr_w(szCls
), debugstr_w(name
),
795 attributes
, debugstr_w(text
), style
);
797 if( attributes
& msidbControlAttributesVisible
)
799 if( ~attributes
& msidbControlAttributesEnabled
)
800 style
|= WS_DISABLED
;
801 if( attributes
& msidbControlAttributesSunken
)
802 exstyle
|= WS_EX_CLIENTEDGE
;
804 dialog_map_events( dialog
, name
);
806 return dialog_create_window( dialog
, rec
, exstyle
, szCls
, name
, text
, style
, dialog
->hwnd
);
817 * we don't erase our own background,
818 * so we have to make sure that the parent window redraws first
820 static void msi_text_on_settext( HWND hWnd
)
825 hParent
= GetParent( hWnd
);
826 GetWindowRect( hWnd
, &rc
);
827 MapWindowPoints( NULL
, hParent
, (LPPOINT
) &rc
, 2 );
828 InvalidateRect( hParent
, &rc
, TRUE
);
831 static LRESULT WINAPI
832 MSIText_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
834 struct msi_text_info
*info
;
837 TRACE("%p %04x %08lx %08lx\n", hWnd
, msg
, wParam
, lParam
);
839 info
= GetPropW(hWnd
, szButtonData
);
841 if( msg
== WM_CTLCOLORSTATIC
&&
842 ( info
->attributes
& msidbControlAttributesTransparent
) )
844 SetBkMode( (HDC
)wParam
, TRANSPARENT
);
845 return (LRESULT
) GetStockObject(NULL_BRUSH
);
848 r
= CallWindowProcW(info
->oldproc
, hWnd
, msg
, wParam
, lParam
);
850 SetTextColor( (HDC
)wParam
, info
->font
->color
);
855 msi_text_on_settext( hWnd
);
859 RemovePropW( hWnd
, szButtonData
);
866 static UINT
msi_dialog_text_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
868 msi_control
*control
;
869 struct msi_text_info
*info
;
870 LPCWSTR text
, ptr
, prop
, control_name
;
873 TRACE("%p %p\n", dialog
, rec
);
875 control
= msi_dialog_add_control( dialog
, rec
, szStatic
, SS_LEFT
| WS_GROUP
);
877 return ERROR_FUNCTION_FAILED
;
879 info
= msi_alloc( sizeof *info
);
881 return ERROR_SUCCESS
;
883 control_name
= MSI_RecordGetString( rec
, 2 );
884 control
->attributes
= MSI_RecordGetInteger( rec
, 8 );
885 prop
= MSI_RecordGetString( rec
, 9 );
886 control
->property
= msi_dialog_dup_property( dialog
, prop
, FALSE
);
888 text
= MSI_RecordGetString( rec
, 10 );
889 font_name
= msi_dialog_get_style( text
, &ptr
);
890 info
->font
= ( font_name
) ? msi_dialog_find_font( dialog
, font_name
) : NULL
;
891 msi_free( font_name
);
893 info
->attributes
= MSI_RecordGetInteger( rec
, 8 );
894 if( info
->attributes
& msidbControlAttributesTransparent
)
895 SetWindowLongPtrW( control
->hwnd
, GWL_EXSTYLE
, WS_EX_TRANSPARENT
);
897 info
->oldproc
= (WNDPROC
) SetWindowLongPtrW( control
->hwnd
, GWLP_WNDPROC
,
898 (LONG_PTR
)MSIText_WndProc
);
899 SetPropW( control
->hwnd
, szButtonData
, info
);
901 event_subscribe( dialog
, szSelectionPath
, control_name
, szSelectionPath
);
902 return ERROR_SUCCESS
;
905 /* strip any leading text style label from text field */
906 static WCHAR
*msi_get_binary_name( MSIPACKAGE
*package
, MSIRECORD
*rec
)
910 text
= msi_get_deformatted_field( package
, rec
, 10 );
915 while (*p
&& *p
!= '{') p
++;
916 if (!*p
++) return text
;
918 while (*p
&& *p
!= '}') p
++;
919 if (!*p
++) return text
;
926 static UINT
msi_dialog_set_property_event( msi_dialog
*dialog
, LPCWSTR event
, LPCWSTR arg
)
928 static const WCHAR szNullArg
[] = {'{','}',0};
929 LPWSTR p
, prop
, arg_fmt
= NULL
;
932 len
= strlenW( event
);
933 prop
= msi_alloc( len
* sizeof(WCHAR
) );
934 strcpyW( prop
, &event
[1] );
935 p
= strchrW( prop
, ']' );
936 if (p
&& (p
[1] == 0 || p
[1] == ' '))
939 if (strcmpW( szNullArg
, arg
))
940 deformat_string( dialog
->package
, arg
, &arg_fmt
);
941 msi_dialog_set_property( dialog
->package
, prop
, arg_fmt
);
942 msi_dialog_update_controls( dialog
, prop
);
945 else ERR("Badly formatted property string - what happens?\n");
947 return ERROR_SUCCESS
;
950 static UINT
msi_dialog_send_event( msi_dialog
*dialog
, LPCWSTR event
, LPCWSTR arg
)
952 LPWSTR event_fmt
= NULL
, arg_fmt
= NULL
;
954 TRACE("Sending control event %s %s\n", debugstr_w(event
), debugstr_w(arg
));
956 deformat_string( dialog
->package
, event
, &event_fmt
);
957 deformat_string( dialog
->package
, arg
, &arg_fmt
);
959 dialog
->event_handler( dialog
, event_fmt
, arg_fmt
);
961 msi_free( event_fmt
);
964 return ERROR_SUCCESS
;
967 static UINT
msi_dialog_control_event( MSIRECORD
*rec
, LPVOID param
)
969 msi_dialog
*dialog
= param
;
970 LPCWSTR condition
, event
, arg
;
973 condition
= MSI_RecordGetString( rec
, 5 );
974 r
= MSI_EvaluateConditionW( dialog
->package
, condition
);
975 if (r
== MSICONDITION_TRUE
|| r
== MSICONDITION_NONE
)
977 event
= MSI_RecordGetString( rec
, 3 );
978 arg
= MSI_RecordGetString( rec
, 4 );
980 msi_dialog_set_property_event( dialog
, event
, arg
);
982 msi_dialog_send_event( dialog
, event
, arg
);
984 return ERROR_SUCCESS
;
987 static UINT
msi_dialog_button_handler( msi_dialog
*dialog
, msi_control
*control
, WPARAM param
)
989 static const WCHAR query
[] = {
990 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
991 'C','o','n','t','r','o','l','E','v','e','n','t',' ','W','H','E','R','E',' ',
992 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',' ','A','N','D',' ',
993 '`','C','o','n','t','r','o','l','_','`',' ','=',' ','\'','%','s','\'',' ',
994 'O','R','D','E','R',' ','B','Y',' ','`','O','r','d','e','r','i','n','g','`',0};
998 if (HIWORD(param
) != BN_CLICKED
)
999 return ERROR_SUCCESS
;
1001 r
= MSI_OpenQuery( dialog
->package
->db
, &view
, query
, dialog
->name
, control
->name
);
1002 if (r
!= ERROR_SUCCESS
)
1004 ERR("query failed\n");
1005 return ERROR_SUCCESS
;
1007 r
= MSI_IterateRecords( view
, 0, msi_dialog_control_event
, dialog
);
1008 msiobj_release( &view
->hdr
);
1012 static UINT
msi_dialog_button_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1014 msi_control
*control
;
1015 UINT attributes
, style
;
1017 TRACE("%p %p\n", dialog
, rec
);
1020 attributes
= MSI_RecordGetInteger( rec
, 8 );
1021 if( attributes
& msidbControlAttributesIcon
)
1024 control
= msi_dialog_add_control( dialog
, rec
, szButton
, style
);
1026 return ERROR_FUNCTION_FAILED
;
1028 control
->handler
= msi_dialog_button_handler
;
1030 if (attributes
& msidbControlAttributesIcon
)
1033 LPWSTR name
= msi_get_binary_name( dialog
->package
, rec
);
1034 control
->hIcon
= msi_load_icon( dialog
->package
->db
, name
, attributes
);
1037 SendMessageW( control
->hwnd
, BM_SETIMAGE
, IMAGE_ICON
, (LPARAM
) control
->hIcon
);
1040 ERR("Failed to load icon %s\n", debugstr_w(name
));
1044 return ERROR_SUCCESS
;
1047 static LPWSTR
msi_get_checkbox_value( msi_dialog
*dialog
, LPCWSTR prop
)
1049 static const WCHAR query
[] = {
1050 'S','E','L','E','C','T',' ','*',' ',
1051 'F','R','O','M',' ','`','C','h','e','c','k','B','o','x','`',' ',
1052 'W','H','E','R','E',' ',
1053 '`','P','r','o','p','e','r','t','y','`',' ','=',' ',
1056 MSIRECORD
*rec
= NULL
;
1059 /* find if there is a value associated with the checkbox */
1060 rec
= MSI_QueryGetRecord( dialog
->package
->db
, query
, prop
);
1064 ret
= msi_get_deformatted_field( dialog
->package
, rec
, 2 );
1065 if( ret
&& !ret
[0] )
1070 msiobj_release( &rec
->hdr
);
1074 ret
= msi_dup_property( dialog
->package
->db
, prop
);
1075 if( ret
&& !ret
[0] )
1084 static UINT
msi_dialog_get_checkbox_state( msi_dialog
*dialog
, msi_control
*control
)
1086 WCHAR state
[2] = {0};
1089 msi_get_property( dialog
->package
->db
, control
->property
, state
, &sz
);
1090 return state
[0] ? 1 : 0;
1093 static void msi_dialog_set_checkbox_state( msi_dialog
*dialog
, msi_control
*control
, UINT state
)
1095 static const WCHAR szState
[] = {'1',0};
1098 /* if uncheck then the property is set to NULL */
1101 msi_dialog_set_property( dialog
->package
, control
->property
, NULL
);
1105 /* check for a custom state */
1106 if (control
->value
&& control
->value
[0])
1107 val
= control
->value
;
1111 msi_dialog_set_property( dialog
->package
, control
->property
, val
);
1114 static void msi_dialog_checkbox_sync_state( msi_dialog
*dialog
, msi_control
*control
)
1116 UINT state
= msi_dialog_get_checkbox_state( dialog
, control
);
1117 SendMessageW( control
->hwnd
, BM_SETCHECK
, state
? BST_CHECKED
: BST_UNCHECKED
, 0 );
1120 static UINT
msi_dialog_checkbox_handler( msi_dialog
*dialog
, msi_control
*control
, WPARAM param
)
1124 if (HIWORD(param
) != BN_CLICKED
)
1125 return ERROR_SUCCESS
;
1127 TRACE("clicked checkbox %s, set %s\n", debugstr_w(control
->name
), debugstr_w(control
->property
));
1129 state
= msi_dialog_get_checkbox_state( dialog
, control
);
1130 state
= state
? 0 : 1;
1131 msi_dialog_set_checkbox_state( dialog
, control
, state
);
1132 msi_dialog_checkbox_sync_state( dialog
, control
);
1134 return msi_dialog_button_handler( dialog
, control
, param
);
1137 static UINT
msi_dialog_checkbox_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1139 msi_control
*control
;
1142 TRACE("%p %p\n", dialog
, rec
);
1144 control
= msi_dialog_add_control( dialog
, rec
, szButton
, BS_CHECKBOX
| BS_MULTILINE
| WS_TABSTOP
);
1145 control
->handler
= msi_dialog_checkbox_handler
;
1146 control
->update
= msi_dialog_checkbox_sync_state
;
1147 prop
= MSI_RecordGetString( rec
, 9 );
1150 control
->property
= strdupW( prop
);
1151 control
->value
= msi_get_checkbox_value( dialog
, prop
);
1152 TRACE("control %s value %s\n", debugstr_w(control
->property
), debugstr_w(control
->value
));
1154 msi_dialog_checkbox_sync_state( dialog
, control
);
1155 return ERROR_SUCCESS
;
1158 static UINT
msi_dialog_line_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1162 DWORD style
, exstyle
= 0;
1163 DWORD x
, y
, width
, height
;
1164 msi_control
*control
;
1166 TRACE("%p %p\n", dialog
, rec
);
1168 style
= WS_CHILD
| SS_ETCHEDHORZ
| SS_SUNKEN
;
1170 name
= MSI_RecordGetString( rec
, 2 );
1171 attributes
= MSI_RecordGetInteger( rec
, 8 );
1173 if( attributes
& msidbControlAttributesVisible
)
1174 style
|= WS_VISIBLE
;
1175 if( ~attributes
& msidbControlAttributesEnabled
)
1176 style
|= WS_DISABLED
;
1177 if( attributes
& msidbControlAttributesSunken
)
1178 exstyle
|= WS_EX_CLIENTEDGE
;
1180 dialog_map_events( dialog
, name
);
1182 control
= msi_alloc( FIELD_OFFSET(msi_control
, name
[strlenW( name
) + 1] ));
1184 return ERROR_OUTOFMEMORY
;
1186 strcpyW( control
->name
, name
);
1187 list_add_head( &dialog
->controls
, &control
->entry
);
1188 control
->handler
= NULL
;
1189 control
->property
= NULL
;
1190 control
->value
= NULL
;
1191 control
->hBitmap
= NULL
;
1192 control
->hIcon
= NULL
;
1193 control
->hDll
= NULL
;
1194 control
->tabnext
= strdupW( MSI_RecordGetString( rec
, 11) );
1195 control
->type
= strdupW( MSI_RecordGetString( rec
, 3 ) );
1196 control
->progress_current
= 0;
1197 control
->progress_max
= 100;
1198 control
->progress_backwards
= FALSE
;
1200 x
= MSI_RecordGetInteger( rec
, 4 );
1201 y
= MSI_RecordGetInteger( rec
, 5 );
1202 width
= MSI_RecordGetInteger( rec
, 6 );
1204 x
= msi_dialog_scale_unit( dialog
, x
);
1205 y
= msi_dialog_scale_unit( dialog
, y
);
1206 width
= msi_dialog_scale_unit( dialog
, width
);
1207 height
= 2; /* line is exactly 2 units in height */
1209 control
->hwnd
= CreateWindowExW( exstyle
, szStatic
, NULL
, style
,
1210 x
, y
, width
, height
, dialog
->hwnd
, NULL
, NULL
, NULL
);
1212 TRACE("Dialog %s control %s hwnd %p\n",
1213 debugstr_w(dialog
->name
), debugstr_w(name
), control
->hwnd
);
1215 return ERROR_SUCCESS
;
1218 /******************** Scroll Text ********************************************/
1220 struct msi_scrolltext_info
1223 msi_control
*control
;
1227 static LRESULT WINAPI
1228 MSIScrollText_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1230 struct msi_scrolltext_info
*info
;
1233 TRACE("%p %04x %08lx %08lx\n", hWnd
, msg
, wParam
, lParam
);
1235 info
= GetPropW( hWnd
, szButtonData
);
1237 r
= CallWindowProcW( info
->oldproc
, hWnd
, msg
, wParam
, lParam
);
1242 return DLGC_WANTARROWS
;
1245 RemovePropW( hWnd
, szButtonData
);
1248 /* native MSI sets a wait cursor here */
1249 msi_dialog_button_handler( info
->dialog
, info
->control
, BN_CLICKED
);
1255 struct msi_streamin_info
1262 static DWORD CALLBACK
1263 msi_richedit_stream_in( DWORD_PTR arg
, LPBYTE buffer
, LONG count
, LONG
*pcb
)
1265 struct msi_streamin_info
*info
= (struct msi_streamin_info
*) arg
;
1267 if( (count
+ info
->offset
) > info
->length
)
1268 count
= info
->length
- info
->offset
;
1269 memcpy( buffer
, &info
->string
[ info
->offset
], count
);
1271 info
->offset
+= count
;
1273 TRACE("%d/%d\n", info
->offset
, info
->length
);
1278 static void msi_scrolltext_add_text( msi_control
*control
, LPCWSTR text
)
1280 struct msi_streamin_info info
;
1283 info
.string
= strdupWtoA( text
);
1285 info
.length
= lstrlenA( info
.string
) + 1;
1287 es
.dwCookie
= (DWORD_PTR
) &info
;
1289 es
.pfnCallback
= msi_richedit_stream_in
;
1291 SendMessageW( control
->hwnd
, EM_STREAMIN
, SF_RTF
, (LPARAM
) &es
);
1293 msi_free( info
.string
);
1296 static UINT
msi_dialog_scrolltext_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1298 static const WCHAR szRichEdit20W
[] = {'R','i','c','h','E','d','i','t','2','0','W',0};
1299 struct msi_scrolltext_info
*info
;
1300 msi_control
*control
;
1305 info
= msi_alloc( sizeof *info
);
1307 return ERROR_FUNCTION_FAILED
;
1309 hRichedit
= LoadLibraryA("riched20");
1311 style
= WS_BORDER
| ES_MULTILINE
| WS_VSCROLL
|
1312 ES_READONLY
| ES_AUTOVSCROLL
| WS_TABSTOP
;
1313 control
= msi_dialog_add_control( dialog
, rec
, szRichEdit20W
, style
);
1316 FreeLibrary( hRichedit
);
1318 return ERROR_FUNCTION_FAILED
;
1321 control
->hDll
= hRichedit
;
1323 info
->dialog
= dialog
;
1324 info
->control
= control
;
1326 /* subclass the static control */
1327 info
->oldproc
= (WNDPROC
) SetWindowLongPtrW( control
->hwnd
, GWLP_WNDPROC
,
1328 (LONG_PTR
)MSIScrollText_WndProc
);
1329 SetPropW( control
->hwnd
, szButtonData
, info
);
1331 /* add the text into the richedit */
1332 text
= MSI_RecordGetString( rec
, 10 );
1334 msi_scrolltext_add_text( control
, text
);
1336 return ERROR_SUCCESS
;
1339 static HBITMAP
msi_load_picture( MSIDATABASE
*db
, LPCWSTR name
,
1340 INT cx
, INT cy
, DWORD flags
)
1342 HBITMAP hOleBitmap
= 0, hBitmap
= 0, hOldSrcBitmap
, hOldDestBitmap
;
1343 MSIRECORD
*rec
= NULL
;
1344 IStream
*stm
= NULL
;
1345 IPicture
*pic
= NULL
;
1350 rec
= msi_get_binary_record( db
, name
);
1354 r
= MSI_RecordGetIStream( rec
, 2, &stm
);
1355 msiobj_release( &rec
->hdr
);
1356 if( r
!= ERROR_SUCCESS
)
1359 r
= OleLoadPicture( stm
, 0, TRUE
, &IID_IPicture
, (LPVOID
*) &pic
);
1360 IStream_Release( stm
);
1363 ERR("failed to load picture\n");
1367 r
= IPicture_get_Handle( pic
, (OLE_HANDLE
*) &hOleBitmap
);
1370 ERR("failed to get bitmap handle\n");
1374 /* make the bitmap the desired size */
1375 r
= GetObjectW( hOleBitmap
, sizeof bm
, &bm
);
1376 if (r
!= sizeof bm
)
1378 ERR("failed to get bitmap size\n");
1382 if (flags
& LR_DEFAULTSIZE
)
1388 srcdc
= CreateCompatibleDC( NULL
);
1389 hOldSrcBitmap
= SelectObject( srcdc
, hOleBitmap
);
1390 destdc
= CreateCompatibleDC( NULL
);
1391 hBitmap
= CreateCompatibleBitmap( srcdc
, cx
, cy
);
1392 hOldDestBitmap
= SelectObject( destdc
, hBitmap
);
1393 StretchBlt( destdc
, 0, 0, cx
, cy
,
1394 srcdc
, 0, 0, bm
.bmWidth
, bm
.bmHeight
, SRCCOPY
);
1395 SelectObject( srcdc
, hOldSrcBitmap
);
1396 SelectObject( destdc
, hOldDestBitmap
);
1402 IPicture_Release( pic
);
1406 static UINT
msi_dialog_bitmap_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1408 UINT cx
, cy
, flags
, style
, attributes
;
1409 msi_control
*control
;
1412 flags
= LR_LOADFROMFILE
;
1413 style
= SS_BITMAP
| SS_LEFT
| WS_GROUP
;
1415 attributes
= MSI_RecordGetInteger( rec
, 8 );
1416 if( attributes
& msidbControlAttributesFixedSize
)
1418 flags
|= LR_DEFAULTSIZE
;
1419 style
|= SS_CENTERIMAGE
;
1422 control
= msi_dialog_add_control( dialog
, rec
, szStatic
, style
);
1423 cx
= MSI_RecordGetInteger( rec
, 6 );
1424 cy
= MSI_RecordGetInteger( rec
, 7 );
1425 cx
= msi_dialog_scale_unit( dialog
, cx
);
1426 cy
= msi_dialog_scale_unit( dialog
, cy
);
1428 name
= msi_get_binary_name( dialog
->package
, rec
);
1429 control
->hBitmap
= msi_load_picture( dialog
->package
->db
, name
, cx
, cy
, flags
);
1430 if( control
->hBitmap
)
1431 SendMessageW( control
->hwnd
, STM_SETIMAGE
,
1432 IMAGE_BITMAP
, (LPARAM
) control
->hBitmap
);
1434 ERR("Failed to load bitmap %s\n", debugstr_w(name
));
1438 return ERROR_SUCCESS
;
1441 static UINT
msi_dialog_icon_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1443 msi_control
*control
;
1449 control
= msi_dialog_add_control( dialog
, rec
, szStatic
,
1450 SS_ICON
| SS_CENTERIMAGE
| WS_GROUP
);
1452 attributes
= MSI_RecordGetInteger( rec
, 8 );
1453 name
= msi_get_binary_name( dialog
->package
, rec
);
1454 control
->hIcon
= msi_load_icon( dialog
->package
->db
, name
, attributes
);
1455 if( control
->hIcon
)
1456 SendMessageW( control
->hwnd
, STM_SETICON
, (WPARAM
) control
->hIcon
, 0 );
1458 ERR("Failed to load bitmap %s\n", debugstr_w(name
));
1460 return ERROR_SUCCESS
;
1463 /******************** Combo Box ***************************************/
1465 struct msi_combobox_info
1475 static LRESULT WINAPI
MSIComboBox_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1477 struct msi_combobox_info
*info
;
1481 TRACE("%p %04x %08lx %08lx\n", hWnd
, msg
, wParam
, lParam
);
1483 info
= GetPropW( hWnd
, szButtonData
);
1487 r
= CallWindowProcW( info
->oldproc
, hWnd
, msg
, wParam
, lParam
);
1492 for (j
= 0; j
< info
->num_items
; j
++)
1493 msi_free( info
->items
[j
] );
1494 msi_free( info
->items
);
1496 RemovePropW( hWnd
, szButtonData
);
1503 static UINT
msi_combobox_add_item( MSIRECORD
*rec
, LPVOID param
)
1505 struct msi_combobox_info
*info
= param
;
1506 LPCWSTR value
, text
;
1509 value
= MSI_RecordGetString( rec
, 3 );
1510 text
= MSI_RecordGetString( rec
, 4 );
1512 info
->items
[info
->addpos_items
] = strdupW( value
);
1514 pos
= SendMessageW( info
->hwnd
, CB_ADDSTRING
, 0, (LPARAM
)text
);
1515 SendMessageW( info
->hwnd
, CB_SETITEMDATA
, pos
, (LPARAM
)info
->items
[info
->addpos_items
] );
1516 info
->addpos_items
++;
1518 return ERROR_SUCCESS
;
1521 static UINT
msi_combobox_add_items( struct msi_combobox_info
*info
, LPCWSTR property
)
1523 static const WCHAR query
[] = {
1524 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
1525 '`','C','o','m','b','o','B','o','x','`',' ','W','H','E','R','E',' ',
1526 '`','P','r','o','p','e','r','t','y','`',' ','=',' ','\'','%','s','\'',' ',
1527 'O','R','D','E','R',' ','B','Y',' ','`','O','r','d','e','r','`',0};
1532 r
= MSI_OpenQuery( info
->dialog
->package
->db
, &view
, query
, property
);
1533 if (r
!= ERROR_SUCCESS
)
1536 /* just get the number of records */
1538 r
= MSI_IterateRecords( view
, &count
, NULL
, NULL
);
1539 if (r
!= ERROR_SUCCESS
)
1541 msiobj_release( &view
->hdr
);
1544 info
->num_items
= count
;
1545 info
->items
= msi_alloc( sizeof(*info
->items
) * count
);
1547 r
= MSI_IterateRecords( view
, NULL
, msi_combobox_add_item
, info
);
1548 msiobj_release( &view
->hdr
);
1552 static UINT
msi_dialog_set_control_condition( MSIRECORD
*rec
, LPVOID param
)
1554 static const WCHAR szHide
[] = {'H','i','d','e',0};
1555 static const WCHAR szShow
[] = {'S','h','o','w',0};
1556 static const WCHAR szDisable
[] = {'D','i','s','a','b','l','e',0};
1557 static const WCHAR szEnable
[] = {'E','n','a','b','l','e',0};
1558 static const WCHAR szDefault
[] = {'D','e','f','a','u','l','t',0};
1559 msi_dialog
*dialog
= param
;
1560 msi_control
*control
;
1561 LPCWSTR name
, action
, condition
;
1564 name
= MSI_RecordGetString( rec
, 2 );
1565 action
= MSI_RecordGetString( rec
, 3 );
1566 condition
= MSI_RecordGetString( rec
, 4 );
1567 r
= MSI_EvaluateConditionW( dialog
->package
, condition
);
1568 control
= msi_dialog_find_control( dialog
, name
);
1569 if (r
== MSICONDITION_TRUE
&& control
)
1571 TRACE("%s control %s\n", debugstr_w(action
), debugstr_w(name
));
1573 /* FIXME: case sensitive? */
1574 if (!strcmpW( action
, szHide
))
1575 ShowWindow(control
->hwnd
, SW_HIDE
);
1576 else if (!strcmpW( action
, szShow
))
1577 ShowWindow(control
->hwnd
, SW_SHOW
);
1578 else if (!strcmpW( action
, szDisable
))
1579 EnableWindow(control
->hwnd
, FALSE
);
1580 else if (!strcmpW( action
, szEnable
))
1581 EnableWindow(control
->hwnd
, TRUE
);
1582 else if (!strcmpW( action
, szDefault
))
1583 SetFocus(control
->hwnd
);
1585 FIXME("Unhandled action %s\n", debugstr_w(action
));
1587 return ERROR_SUCCESS
;
1590 static UINT
msi_dialog_evaluate_control_conditions( msi_dialog
*dialog
)
1592 static const WCHAR query
[] = {
1593 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
1594 'C','o','n','t','r','o','l','C','o','n','d','i','t','i','o','n',' ',
1595 'W','H','E','R','E',' ','`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',0};
1598 MSIPACKAGE
*package
= dialog
->package
;
1600 TRACE("%p %s\n", dialog
, debugstr_w(dialog
->name
));
1602 /* query the Control table for all the elements of the control */
1603 r
= MSI_OpenQuery( package
->db
, &view
, query
, dialog
->name
);
1604 if (r
!= ERROR_SUCCESS
)
1605 return ERROR_SUCCESS
;
1607 r
= MSI_IterateRecords( view
, 0, msi_dialog_set_control_condition
, dialog
);
1608 msiobj_release( &view
->hdr
);
1612 static UINT
msi_dialog_combobox_handler( msi_dialog
*dialog
, msi_control
*control
, WPARAM param
)
1614 struct msi_combobox_info
*info
;
1618 if (HIWORD(param
) != CBN_SELCHANGE
&& HIWORD(param
) != CBN_EDITCHANGE
)
1619 return ERROR_SUCCESS
;
1621 info
= GetPropW( control
->hwnd
, szButtonData
);
1622 index
= SendMessageW( control
->hwnd
, CB_GETCURSEL
, 0, 0 );
1623 if (index
== CB_ERR
)
1624 value
= msi_get_window_text( control
->hwnd
);
1626 value
= (LPWSTR
) SendMessageW( control
->hwnd
, CB_GETITEMDATA
, index
, 0 );
1628 msi_dialog_set_property( info
->dialog
->package
, control
->property
, value
);
1629 msi_dialog_evaluate_control_conditions( info
->dialog
);
1631 if (index
== CB_ERR
)
1634 return ERROR_SUCCESS
;
1637 static void msi_dialog_combobox_update( msi_dialog
*dialog
, msi_control
*control
)
1639 struct msi_combobox_info
*info
;
1643 info
= GetPropW( control
->hwnd
, szButtonData
);
1645 value
= msi_dup_property( dialog
->package
->db
, control
->property
);
1648 SendMessageW( control
->hwnd
, CB_SETCURSEL
, -1, 0 );
1652 for (j
= 0; j
< info
->num_items
; j
++)
1654 tmp
= (LPWSTR
) SendMessageW( control
->hwnd
, CB_GETITEMDATA
, j
, 0 );
1655 if (!strcmpW( value
, tmp
))
1659 if (j
< info
->num_items
)
1661 SendMessageW( control
->hwnd
, CB_SETCURSEL
, j
, 0 );
1665 SendMessageW( control
->hwnd
, CB_SETCURSEL
, -1, 0 );
1666 SetWindowTextW( control
->hwnd
, value
);
1672 static UINT
msi_dialog_combo_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1674 struct msi_combobox_info
*info
;
1675 msi_control
*control
;
1676 DWORD attributes
, style
;
1679 info
= msi_alloc( sizeof *info
);
1681 return ERROR_FUNCTION_FAILED
;
1683 style
= CBS_AUTOHSCROLL
| WS_TABSTOP
| WS_GROUP
| WS_CHILD
;
1684 attributes
= MSI_RecordGetInteger( rec
, 8 );
1685 if ( ~attributes
& msidbControlAttributesSorted
)
1687 if ( attributes
& msidbControlAttributesComboList
)
1688 style
|= CBS_DROPDOWNLIST
;
1690 style
|= CBS_DROPDOWN
;
1692 control
= msi_dialog_add_control( dialog
, rec
, WC_COMBOBOXW
, style
);
1696 return ERROR_FUNCTION_FAILED
;
1699 control
->handler
= msi_dialog_combobox_handler
;
1700 control
->update
= msi_dialog_combobox_update
;
1702 prop
= MSI_RecordGetString( rec
, 9 );
1703 control
->property
= msi_dialog_dup_property( dialog
, prop
, FALSE
);
1706 info
->dialog
= dialog
;
1707 info
->hwnd
= control
->hwnd
;
1709 info
->addpos_items
= 0;
1710 info
->oldproc
= (WNDPROC
)SetWindowLongPtrW( control
->hwnd
, GWLP_WNDPROC
,
1711 (LONG_PTR
)MSIComboBox_WndProc
);
1712 SetPropW( control
->hwnd
, szButtonData
, info
);
1714 if (control
->property
)
1715 msi_combobox_add_items( info
, control
->property
);
1717 msi_dialog_combobox_update( dialog
, control
);
1719 return ERROR_SUCCESS
;
1722 static UINT
msi_dialog_edit_handler( msi_dialog
*dialog
, msi_control
*control
, WPARAM param
)
1726 if (HIWORD(param
) != EN_CHANGE
)
1727 return ERROR_SUCCESS
;
1729 TRACE("edit %s contents changed, set %s\n", debugstr_w(control
->name
), debugstr_w(control
->property
));
1731 buf
= msi_get_window_text( control
->hwnd
);
1732 msi_dialog_set_property( dialog
->package
, control
->property
, buf
);
1735 return ERROR_SUCCESS
;
1738 /* length of 2^32 + 1 */
1739 #define MAX_NUM_DIGITS 11
1741 static UINT
msi_dialog_edit_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1743 msi_control
*control
;
1745 LPWSTR val
, begin
, end
;
1746 WCHAR num
[MAX_NUM_DIGITS
];
1749 control
= msi_dialog_add_control( dialog
, rec
, szEdit
,
1750 WS_BORDER
| WS_TABSTOP
| ES_AUTOHSCROLL
);
1751 control
->handler
= msi_dialog_edit_handler
;
1753 text
= MSI_RecordGetString( rec
, 10 );
1756 begin
= strchrW( text
, '{' );
1757 end
= strchrW( text
, '}' );
1759 if ( begin
&& end
&& end
> begin
&&
1760 begin
[0] >= '0' && begin
[0] <= '9' &&
1761 end
- begin
< MAX_NUM_DIGITS
)
1763 lstrcpynW( num
, begin
+ 1, end
- begin
);
1764 limit
= atolW( num
);
1766 SendMessageW( control
->hwnd
, EM_SETLIMITTEXT
, limit
, 0 );
1770 prop
= MSI_RecordGetString( rec
, 9 );
1772 control
->property
= strdupW( prop
);
1774 val
= msi_dup_property( dialog
->package
->db
, control
->property
);
1775 SetWindowTextW( control
->hwnd
, val
);
1777 return ERROR_SUCCESS
;
1780 /******************** Masked Edit ********************************************/
1782 #define MASK_MAX_GROUPS 20
1784 struct msi_mask_group
1792 struct msi_maskedit_info
1800 struct msi_mask_group group
[MASK_MAX_GROUPS
];
1803 static BOOL
msi_mask_editable( WCHAR type
)
1818 static void msi_mask_control_change( struct msi_maskedit_info
*info
)
1823 val
= msi_alloc( (info
->num_chars
+1)*sizeof(WCHAR
) );
1824 for( i
=0, n
=0; i
<info
->num_groups
; i
++ )
1826 if (info
->group
[i
].len
== ~0u)
1828 UINT len
= SendMessageW( info
->group
[i
].hwnd
, WM_GETTEXTLENGTH
, 0, 0 );
1829 val
= msi_realloc( val
, (len
+ 1) * sizeof(WCHAR
) );
1830 GetWindowTextW( info
->group
[i
].hwnd
, val
, len
+ 1 );
1834 if (info
->group
[i
].len
+ n
> info
->num_chars
)
1836 ERR("can't fit control %d text into template\n",i
);
1839 if (!msi_mask_editable(info
->group
[i
].type
))
1841 for(r
=0; r
<info
->group
[i
].len
; r
++)
1842 val
[n
+r
] = info
->group
[i
].type
;
1847 r
= GetWindowTextW( info
->group
[i
].hwnd
, &val
[n
], info
->group
[i
].len
+1 );
1848 if( r
!= info
->group
[i
].len
)
1855 TRACE("%d/%d controls were good\n", i
, info
->num_groups
);
1857 if( i
== info
->num_groups
)
1859 TRACE("Set property %s to %s\n", debugstr_w(info
->prop
), debugstr_w(val
));
1860 msi_dialog_set_property( info
->dialog
->package
, info
->prop
, val
);
1861 msi_dialog_evaluate_control_conditions( info
->dialog
);
1866 /* now move to the next control if necessary */
1867 static VOID
msi_mask_next_control( struct msi_maskedit_info
*info
, HWND hWnd
)
1872 for( i
=0; i
<info
->num_groups
; i
++ )
1873 if( info
->group
[i
].hwnd
== hWnd
)
1876 /* don't move from the last control */
1877 if( i
>= (info
->num_groups
-1) )
1880 len
= SendMessageW( hWnd
, WM_GETTEXTLENGTH
, 0, 0 );
1881 if( len
< info
->group
[i
].len
)
1884 hWndNext
= GetNextDlgTabItem( GetParent( hWnd
), hWnd
, FALSE
);
1885 SetFocus( hWndNext
);
1888 static LRESULT WINAPI
1889 MSIMaskedEdit_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1891 struct msi_maskedit_info
*info
;
1894 TRACE("%p %04x %08lx %08lx\n", hWnd
, msg
, wParam
, lParam
);
1896 info
= GetPropW(hWnd
, szButtonData
);
1898 r
= CallWindowProcW(info
->oldproc
, hWnd
, msg
, wParam
, lParam
);
1903 if (HIWORD(wParam
) == EN_CHANGE
)
1905 msi_mask_control_change( info
);
1906 msi_mask_next_control( info
, (HWND
) lParam
);
1910 msi_free( info
->prop
);
1912 RemovePropW( hWnd
, szButtonData
);
1919 /* fish the various bits of the property out and put them in the control */
1921 msi_maskedit_set_text( struct msi_maskedit_info
*info
, LPCWSTR text
)
1927 for( i
= 0; i
< info
->num_groups
; i
++ )
1929 if( info
->group
[i
].len
< strlenW( p
) )
1931 LPWSTR chunk
= strdupW( p
);
1932 chunk
[ info
->group
[i
].len
] = 0;
1933 SetWindowTextW( info
->group
[i
].hwnd
, chunk
);
1938 SetWindowTextW( info
->group
[i
].hwnd
, p
);
1941 p
+= info
->group
[i
].len
;
1945 static struct msi_maskedit_info
* msi_dialog_parse_groups( LPCWSTR mask
)
1947 struct msi_maskedit_info
*info
;
1948 int i
= 0, n
= 0, total
= 0;
1951 TRACE("masked control, template %s\n", debugstr_w(mask
));
1956 info
= msi_alloc_zero( sizeof *info
);
1960 p
= strchrW(mask
, '<');
1966 for( i
=0; i
<MASK_MAX_GROUPS
; i
++ )
1968 /* stop at the end of the string */
1969 if( p
[0] == 0 || p
[0] == '>' )
1973 /* create a group for the empty mask */
1974 info
->group
[0].type
= '&';
1975 info
->group
[0].len
= ~0u;
1981 /* count the number of the same identifier */
1982 for( n
=0; p
[n
] == p
[0]; n
++ )
1984 info
->group
[i
].ofs
= total
;
1985 info
->group
[i
].type
= p
[0];
1989 total
++; /* an extra not part of the group */
1991 info
->group
[i
].len
= n
;
1996 TRACE("%d characters in %d groups\n", total
, i
);
1997 if( i
== MASK_MAX_GROUPS
)
1998 ERR("too many groups in PIDTemplate %s\n", debugstr_w(mask
));
2000 info
->num_chars
= total
;
2001 info
->num_groups
= i
;
2007 msi_maskedit_create_children( struct msi_maskedit_info
*info
, LPCWSTR font
)
2009 DWORD width
, height
, style
, wx
, ww
;
2014 style
= WS_CHILD
| WS_BORDER
| WS_VISIBLE
| WS_TABSTOP
| ES_AUTOHSCROLL
;
2016 GetClientRect( info
->hwnd
, &rect
);
2018 width
= rect
.right
- rect
.left
;
2019 height
= rect
.bottom
- rect
.top
;
2021 for( i
= 0; i
< info
->num_groups
; i
++ )
2023 if (!msi_mask_editable( info
->group
[i
].type
))
2025 if (info
->num_chars
)
2027 wx
= (info
->group
[i
].ofs
* width
) / info
->num_chars
;
2028 ww
= (info
->group
[i
].len
* width
) / info
->num_chars
;
2035 hwnd
= CreateWindowW( szEdit
, NULL
, style
, wx
, 0, ww
, height
,
2036 info
->hwnd
, NULL
, NULL
, NULL
);
2039 ERR("failed to create mask edit sub window\n");
2043 SendMessageW( hwnd
, EM_LIMITTEXT
, info
->group
[i
].len
, 0 );
2045 msi_dialog_set_font( info
->dialog
, hwnd
,
2046 font
?font
:info
->dialog
->default_font
);
2047 info
->group
[i
].hwnd
= hwnd
;
2052 * office 2003 uses "73931<````=````=````=````=`````>@@@@@"
2053 * delphi 7 uses "<????-??????-??????-????>" and "<???-???>"
2054 * filemaker pro 7 uses "<^^^^=^^^^=^^^^=^^^^=^^^^=^^^^=^^^^^>"
2056 static UINT
msi_dialog_maskedit_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
2058 LPWSTR font_mask
, val
= NULL
, font
;
2059 struct msi_maskedit_info
*info
= NULL
;
2060 UINT ret
= ERROR_SUCCESS
;
2061 msi_control
*control
;
2066 font_mask
= msi_get_deformatted_field( dialog
->package
, rec
, 10 );
2067 font
= msi_dialog_get_style( font_mask
, &mask
);
2070 WARN("mask template is empty\n");
2074 info
= msi_dialog_parse_groups( mask
);
2077 ERR("template %s is invalid\n", debugstr_w(mask
));
2081 info
->dialog
= dialog
;
2083 control
= msi_dialog_add_control( dialog
, rec
, szStatic
,
2084 SS_OWNERDRAW
| WS_GROUP
| WS_VISIBLE
);
2087 ERR("Failed to create maskedit container\n");
2088 ret
= ERROR_FUNCTION_FAILED
;
2091 SetWindowLongPtrW( control
->hwnd
, GWL_EXSTYLE
, WS_EX_CONTROLPARENT
);
2093 info
->hwnd
= control
->hwnd
;
2095 /* subclass the static control */
2096 info
->oldproc
= (WNDPROC
) SetWindowLongPtrW( info
->hwnd
, GWLP_WNDPROC
,
2097 (LONG_PTR
)MSIMaskedEdit_WndProc
);
2098 SetPropW( control
->hwnd
, szButtonData
, info
);
2100 prop
= MSI_RecordGetString( rec
, 9 );
2102 info
->prop
= strdupW( prop
);
2104 msi_maskedit_create_children( info
, font
);
2108 val
= msi_dup_property( dialog
->package
->db
, prop
);
2111 msi_maskedit_set_text( info
, val
);
2117 if( ret
!= ERROR_SUCCESS
)
2119 msi_free( font_mask
);
2124 /******************** Progress Bar *****************************************/
2126 static UINT
msi_dialog_progress_bar( msi_dialog
*dialog
, MSIRECORD
*rec
)
2128 msi_control
*control
;
2129 DWORD attributes
, style
;
2132 attributes
= MSI_RecordGetInteger( rec
, 8 );
2133 if( !(attributes
& msidbControlAttributesProgress95
) )
2134 style
|= PBS_SMOOTH
;
2136 control
= msi_dialog_add_control( dialog
, rec
, PROGRESS_CLASSW
, style
);
2138 return ERROR_FUNCTION_FAILED
;
2140 event_subscribe( dialog
, szSetProgress
, control
->name
, szProgress
);
2141 return ERROR_SUCCESS
;
2144 /******************** Path Edit ********************************************/
2146 struct msi_pathedit_info
2149 msi_control
*control
;
2153 static void msi_dialog_update_pathedit( msi_dialog
*dialog
, msi_control
*control
)
2158 if (!control
&& !(control
= msi_dialog_find_control_by_type( dialog
, szPathEdit
)))
2161 indirect
= control
->attributes
& msidbControlAttributesIndirect
;
2162 prop
= msi_dialog_dup_property( dialog
, control
->property
, indirect
);
2163 path
= msi_dialog_dup_property( dialog
, prop
, TRUE
);
2165 SetWindowTextW( control
->hwnd
, path
);
2166 SendMessageW( control
->hwnd
, EM_SETSEL
, 0, -1 );
2172 /* FIXME: test when this should fail */
2173 static BOOL
msi_dialog_verify_path( LPWSTR path
)
2175 if ( !lstrlenW( path
) )
2178 if ( PathIsRelativeW( path
) )
2184 /* returns TRUE if the path is valid, FALSE otherwise */
2185 static BOOL
msi_dialog_onkillfocus( msi_dialog
*dialog
, msi_control
*control
)
2191 indirect
= control
->attributes
& msidbControlAttributesIndirect
;
2192 prop
= msi_dialog_dup_property( dialog
, control
->property
, indirect
);
2194 buf
= msi_get_window_text( control
->hwnd
);
2196 if ( !msi_dialog_verify_path( buf
) )
2198 /* FIXME: display an error message box */
2199 ERR("Invalid path %s\n", debugstr_w( buf
));
2201 SetFocus( control
->hwnd
);
2206 msi_dialog_set_property( dialog
->package
, prop
, buf
);
2209 msi_dialog_update_pathedit( dialog
, control
);
2211 TRACE("edit %s contents changed, set %s\n", debugstr_w(control
->name
),
2220 static LRESULT WINAPI
MSIPathEdit_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
2222 struct msi_pathedit_info
*info
= GetPropW(hWnd
, szButtonData
);
2225 TRACE("%p %04x %08lx %08lx\n", hWnd
, msg
, wParam
, lParam
);
2227 if ( msg
== WM_KILLFOCUS
)
2229 /* if the path is invalid, don't handle this message */
2230 if ( !msi_dialog_onkillfocus( info
->dialog
, info
->control
) )
2234 r
= CallWindowProcW(info
->oldproc
, hWnd
, msg
, wParam
, lParam
);
2236 if ( msg
== WM_NCDESTROY
)
2239 RemovePropW( hWnd
, szButtonData
);
2245 static UINT
msi_dialog_pathedit_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
2247 struct msi_pathedit_info
*info
;
2248 msi_control
*control
;
2251 info
= msi_alloc( sizeof *info
);
2253 return ERROR_FUNCTION_FAILED
;
2255 control
= msi_dialog_add_control( dialog
, rec
, szEdit
,
2256 WS_BORDER
| WS_TABSTOP
);
2257 control
->attributes
= MSI_RecordGetInteger( rec
, 8 );
2258 prop
= MSI_RecordGetString( rec
, 9 );
2259 control
->property
= msi_dialog_dup_property( dialog
, prop
, FALSE
);
2261 info
->dialog
= dialog
;
2262 info
->control
= control
;
2263 info
->oldproc
= (WNDPROC
) SetWindowLongPtrW( control
->hwnd
, GWLP_WNDPROC
,
2264 (LONG_PTR
)MSIPathEdit_WndProc
);
2265 SetPropW( control
->hwnd
, szButtonData
, info
);
2267 msi_dialog_update_pathedit( dialog
, control
);
2269 return ERROR_SUCCESS
;
2272 static UINT
msi_dialog_radiogroup_handler( msi_dialog
*dialog
, msi_control
*control
, WPARAM param
)
2274 if (HIWORD(param
) != BN_CLICKED
)
2275 return ERROR_SUCCESS
;
2277 TRACE("clicked radio button %s, set %s\n", debugstr_w(control
->name
), debugstr_w(control
->property
));
2279 msi_dialog_set_property( dialog
->package
, control
->property
, control
->name
);
2281 return msi_dialog_button_handler( dialog
, control
, param
);
2284 /* radio buttons are a bit different from normal controls */
2285 static UINT
msi_dialog_create_radiobutton( MSIRECORD
*rec
, LPVOID param
)
2287 radio_button_group_descr
*group
= param
;
2288 msi_dialog
*dialog
= group
->dialog
;
2289 msi_control
*control
;
2290 LPCWSTR prop
, text
, name
;
2291 DWORD style
, attributes
= group
->attributes
;
2293 style
= WS_CHILD
| BS_AUTORADIOBUTTON
| BS_MULTILINE
| WS_TABSTOP
;
2294 name
= MSI_RecordGetString( rec
, 3 );
2295 text
= MSI_RecordGetString( rec
, 8 );
2296 if( attributes
& msidbControlAttributesVisible
)
2297 style
|= WS_VISIBLE
;
2298 if( ~attributes
& msidbControlAttributesEnabled
)
2299 style
|= WS_DISABLED
;
2301 control
= dialog_create_window( dialog
, rec
, 0, szButton
, name
, text
, style
,
2302 group
->parent
->hwnd
);
2304 return ERROR_FUNCTION_FAILED
;
2305 control
->handler
= msi_dialog_radiogroup_handler
;
2307 if (group
->propval
&& !strcmpW( control
->name
, group
->propval
))
2308 SendMessageW(control
->hwnd
, BM_SETCHECK
, BST_CHECKED
, 0);
2310 prop
= MSI_RecordGetString( rec
, 1 );
2312 control
->property
= strdupW( prop
);
2314 return ERROR_SUCCESS
;
2317 static BOOL CALLBACK
msi_radioground_child_enum( HWND hWnd
, LPARAM lParam
)
2319 EnableWindow( hWnd
, lParam
);
2323 static LRESULT WINAPI
MSIRadioGroup_WndProc( HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
2325 WNDPROC oldproc
= (WNDPROC
)GetPropW( hWnd
, szButtonData
);
2328 TRACE("hWnd %p msg %04x wParam 0x%08lx lParam 0x%08lx\n", hWnd
, msg
, wParam
, lParam
);
2330 if (msg
== WM_COMMAND
) /* Forward notifications to dialog */
2331 SendMessageW( GetParent( hWnd
), msg
, wParam
, lParam
);
2333 r
= CallWindowProcW( oldproc
, hWnd
, msg
, wParam
, lParam
);
2335 /* make sure the radio buttons show as disabled if the parent is disabled */
2336 if (msg
== WM_ENABLE
)
2337 EnumChildWindows( hWnd
, msi_radioground_child_enum
, wParam
);
2342 static UINT
msi_dialog_radiogroup_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
2344 static const WCHAR query
[] = {
2345 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2346 'R','a','d','i','o','B','u','t','t','o','n',' ','W','H','E','R','E',' ',
2347 '`','P','r','o','p','e','r','t','y','`',' ','=',' ','\'','%','s','\'',0};
2350 msi_control
*control
;
2352 radio_button_group_descr group
;
2353 MSIPACKAGE
*package
= dialog
->package
;
2355 DWORD attr
, style
= WS_GROUP
;
2357 prop
= MSI_RecordGetString( rec
, 9 );
2359 TRACE("%p %p %s\n", dialog
, rec
, debugstr_w( prop
));
2361 attr
= MSI_RecordGetInteger( rec
, 8 );
2362 if (attr
& msidbControlAttributesHasBorder
)
2363 style
|= BS_GROUPBOX
;
2365 style
|= BS_OWNERDRAW
;
2367 /* Create parent group box to hold radio buttons */
2368 control
= msi_dialog_add_control( dialog
, rec
, szButton
, style
);
2370 return ERROR_FUNCTION_FAILED
;
2372 oldproc
= (WNDPROC
) SetWindowLongPtrW( control
->hwnd
, GWLP_WNDPROC
,
2373 (LONG_PTR
)MSIRadioGroup_WndProc
);
2374 SetPropW(control
->hwnd
, szButtonData
, oldproc
);
2375 SetWindowLongPtrW( control
->hwnd
, GWL_EXSTYLE
, WS_EX_CONTROLPARENT
);
2378 control
->property
= strdupW( prop
);
2380 /* query the Radio Button table for all control in this group */
2381 r
= MSI_OpenQuery( package
->db
, &view
, query
, prop
);
2382 if( r
!= ERROR_SUCCESS
)
2384 ERR("query failed for dialog %s radio group %s\n",
2385 debugstr_w(dialog
->name
), debugstr_w(prop
));
2386 return ERROR_INVALID_PARAMETER
;
2389 group
.dialog
= dialog
;
2390 group
.parent
= control
;
2391 group
.attributes
= MSI_RecordGetInteger( rec
, 8 );
2392 group
.propval
= msi_dup_property( dialog
->package
->db
, control
->property
);
2394 r
= MSI_IterateRecords( view
, 0, msi_dialog_create_radiobutton
, &group
);
2395 msiobj_release( &view
->hdr
);
2396 msi_free( group
.propval
);
2401 msi_seltree_sync_item_state( HWND hwnd
, MSIFEATURE
*feature
, HTREEITEM hItem
)
2404 DWORD index
= feature
->ActionRequest
;
2406 TRACE("Feature %s -> %d %d %d\n", debugstr_w(feature
->Title
),
2407 feature
->Installed
, feature
->Action
, feature
->ActionRequest
);
2409 if (index
== INSTALLSTATE_UNKNOWN
)
2410 index
= INSTALLSTATE_ABSENT
;
2412 tvi
.mask
= TVIF_STATE
;
2414 tvi
.state
= INDEXTOSTATEIMAGEMASK( index
);
2415 tvi
.stateMask
= TVIS_STATEIMAGEMASK
;
2417 SendMessageW( hwnd
, TVM_SETITEMW
, 0, (LPARAM
) &tvi
);
2421 msi_seltree_popup_menu( HWND hwnd
, INT x
, INT y
)
2426 /* create a menu to display */
2427 hMenu
= CreatePopupMenu();
2429 /* FIXME: load strings from resources */
2430 AppendMenuA( hMenu
, MF_ENABLED
, INSTALLSTATE_LOCAL
, "Install feature locally");
2431 AppendMenuA( hMenu
, MF_ENABLED
, USER_INSTALLSTATE_ALL
, "Install entire feature");
2432 AppendMenuA( hMenu
, MF_ENABLED
, INSTALLSTATE_ADVERTISED
, "Install on demand");
2433 AppendMenuA( hMenu
, MF_ENABLED
, INSTALLSTATE_ABSENT
, "Don't install");
2434 r
= TrackPopupMenu( hMenu
, TPM_LEFTALIGN
| TPM_TOPALIGN
| TPM_RETURNCMD
,
2435 x
, y
, 0, hwnd
, NULL
);
2436 DestroyMenu( hMenu
);
2441 msi_seltree_update_feature_installstate( HWND hwnd
, HTREEITEM hItem
,
2442 MSIPACKAGE
*package
, MSIFEATURE
*feature
, INSTALLSTATE state
)
2444 feature
->ActionRequest
= state
;
2445 msi_seltree_sync_item_state( hwnd
, feature
, hItem
);
2446 ACTION_UpdateComponentStates( package
, feature
);
2450 msi_seltree_update_siblings_and_children_installstate( HWND hwnd
, HTREEITEM curr
,
2451 MSIPACKAGE
*package
, INSTALLSTATE state
)
2453 /* update all siblings */
2456 MSIFEATURE
*feature
;
2459 feature
= msi_seltree_feature_from_item( hwnd
, curr
);
2460 msi_seltree_update_feature_installstate( hwnd
, curr
, package
, feature
, state
);
2462 /* update this sibling's children */
2463 child
= (HTREEITEM
)SendMessageW( hwnd
, TVM_GETNEXTITEM
, (WPARAM
)TVGN_CHILD
, (LPARAM
)curr
);
2465 msi_seltree_update_siblings_and_children_installstate( hwnd
, child
,
2468 while ((curr
= (HTREEITEM
)SendMessageW( hwnd
, TVM_GETNEXTITEM
, (WPARAM
)TVGN_NEXT
, (LPARAM
)curr
)));
2472 msi_seltree_menu( HWND hwnd
, HTREEITEM hItem
)
2474 struct msi_selection_tree_info
*info
;
2475 MSIFEATURE
*feature
;
2476 MSIPACKAGE
*package
;
2484 info
= GetPropW(hwnd
, szButtonData
);
2485 package
= info
->dialog
->package
;
2487 feature
= msi_seltree_feature_from_item( hwnd
, hItem
);
2490 ERR("item %p feature was NULL\n", hItem
);
2494 /* get the item's rectangle to put the menu just below it */
2496 SendMessageW( hwnd
, TVM_GETITEMRECT
, 0, (LPARAM
) &u
.rc
);
2497 MapWindowPoints( hwnd
, NULL
, u
.pt
, 2 );
2499 r
= msi_seltree_popup_menu( hwnd
, u
.rc
.left
, u
.rc
.top
);
2503 case USER_INSTALLSTATE_ALL
:
2504 r
= INSTALLSTATE_LOCAL
;
2506 case INSTALLSTATE_ADVERTISED
:
2507 case INSTALLSTATE_ABSENT
:
2510 child
= (HTREEITEM
)SendMessageW( hwnd
, TVM_GETNEXTITEM
, (WPARAM
)TVGN_CHILD
, (LPARAM
)hItem
);
2512 msi_seltree_update_siblings_and_children_installstate( hwnd
, child
, package
, r
);
2515 case INSTALLSTATE_LOCAL
:
2516 msi_seltree_update_feature_installstate( hwnd
, hItem
, package
, feature
, r
);
2523 static LRESULT WINAPI
2524 MSISelectionTree_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
2526 struct msi_selection_tree_info
*info
;
2527 TVHITTESTINFO tvhti
;
2530 TRACE("%p %04x %08lx %08lx\n", hWnd
, msg
, wParam
, lParam
);
2532 info
= GetPropW(hWnd
, szButtonData
);
2536 case WM_LBUTTONDOWN
:
2537 tvhti
.pt
.x
= (short)LOWORD( lParam
);
2538 tvhti
.pt
.y
= (short)HIWORD( lParam
);
2541 CallWindowProcW(info
->oldproc
, hWnd
, TVM_HITTEST
, 0, (LPARAM
) &tvhti
);
2542 if (tvhti
.flags
& TVHT_ONITEMSTATEICON
)
2543 return msi_seltree_menu( hWnd
, tvhti
.hItem
);
2546 r
= CallWindowProcW(info
->oldproc
, hWnd
, msg
, wParam
, lParam
);
2552 RemovePropW( hWnd
, szButtonData
);
2559 msi_seltree_add_child_features( MSIPACKAGE
*package
, HWND hwnd
,
2560 LPCWSTR parent
, HTREEITEM hParent
)
2562 struct msi_selection_tree_info
*info
= GetPropW( hwnd
, szButtonData
);
2563 MSIFEATURE
*feature
;
2564 TVINSERTSTRUCTW tvis
;
2565 HTREEITEM hitem
, hfirst
= NULL
;
2567 LIST_FOR_EACH_ENTRY( feature
, &package
->features
, MSIFEATURE
, entry
)
2569 if ( parent
&& feature
->Feature_Parent
&& strcmpW( parent
, feature
->Feature_Parent
))
2571 else if ( parent
&& !feature
->Feature_Parent
)
2573 else if ( !parent
&& feature
->Feature_Parent
)
2576 if ( !feature
->Title
)
2579 if ( !feature
->Display
)
2582 memset( &tvis
, 0, sizeof tvis
);
2583 tvis
.hParent
= hParent
;
2584 tvis
.hInsertAfter
= TVI_LAST
;
2585 tvis
.u
.item
.mask
= TVIF_TEXT
| TVIF_PARAM
;
2586 tvis
.u
.item
.pszText
= feature
->Title
;
2587 tvis
.u
.item
.lParam
= (LPARAM
) feature
;
2589 hitem
= (HTREEITEM
) SendMessageW( hwnd
, TVM_INSERTITEMW
, 0, (LPARAM
) &tvis
);
2596 msi_seltree_sync_item_state( hwnd
, feature
, hitem
);
2597 msi_seltree_add_child_features( package
, hwnd
,
2598 feature
->Feature
, hitem
);
2600 /* the node is expanded if Display is odd */
2601 if ( feature
->Display
% 2 != 0 )
2602 SendMessageW( hwnd
, TVM_EXPAND
, TVE_EXPAND
, (LPARAM
) hitem
);
2605 /* select the first item */
2606 SendMessageW( hwnd
, TVM_SELECTITEM
, TVGN_CARET
| TVGN_DROPHILITE
, (LPARAM
) hfirst
);
2607 info
->selected
= hfirst
;
2610 static void msi_seltree_create_imagelist( HWND hwnd
)
2612 const int bm_width
= 32, bm_height
= 16, bm_count
= 3;
2613 const int bm_resource
= 0x1001;
2618 himl
= ImageList_Create( bm_width
, bm_height
, FALSE
, 4, 0 );
2621 ERR("failed to create image list\n");
2625 for (i
=0; i
<bm_count
; i
++)
2627 hbmp
= LoadBitmapW( msi_hInstance
, MAKEINTRESOURCEW(i
+bm_resource
) );
2630 ERR("failed to load bitmap %d\n", i
);
2635 * Add a dummy bitmap at offset zero because the treeview
2636 * can't use it as a state mask (zero means no user state).
2639 ImageList_Add( himl
, hbmp
, NULL
);
2641 ImageList_Add( himl
, hbmp
, NULL
);
2644 SendMessageW( hwnd
, TVM_SETIMAGELIST
, TVSIL_STATE
, (LPARAM
)himl
);
2647 static UINT
msi_dialog_seltree_handler( msi_dialog
*dialog
,
2648 msi_control
*control
, WPARAM param
)
2650 struct msi_selection_tree_info
*info
= GetPropW( control
->hwnd
, szButtonData
);
2651 LPNMTREEVIEWW tv
= (LPNMTREEVIEWW
)param
;
2652 MSIRECORD
*row
, *rec
;
2654 MSIFEATURE
*feature
;
2655 LPCWSTR dir
, title
= NULL
;
2656 UINT r
= ERROR_SUCCESS
;
2658 static const WCHAR select
[] = {
2659 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2660 '`','F','e','a','t','u','r','e','`',' ','W','H','E','R','E',' ',
2661 '`','T','i','t','l','e','`',' ','=',' ','\'','%','s','\'',0
2664 if (tv
->hdr
.code
!= TVN_SELCHANGINGW
)
2665 return ERROR_SUCCESS
;
2667 info
->selected
= tv
->itemNew
.hItem
;
2669 if (!(tv
->itemNew
.mask
& TVIF_TEXT
))
2671 feature
= msi_seltree_feature_from_item( control
->hwnd
, tv
->itemNew
.hItem
);
2673 title
= feature
->Title
;
2676 title
= tv
->itemNew
.pszText
;
2678 row
= MSI_QueryGetRecord( dialog
->package
->db
, select
, title
);
2680 return ERROR_FUNCTION_FAILED
;
2682 rec
= MSI_CreateRecord( 1 );
2684 MSI_RecordSetStringW( rec
, 1, MSI_RecordGetString( row
, 4 ) );
2685 msi_event_fire( dialog
->package
, szSelectionDescription
, rec
);
2687 dir
= MSI_RecordGetString( row
, 7 );
2690 folder
= msi_get_loaded_folder( dialog
->package
, dir
);
2693 r
= ERROR_FUNCTION_FAILED
;
2696 MSI_RecordSetStringW( rec
, 1, folder
->ResolvedTarget
);
2699 MSI_RecordSetStringW( rec
, 1, NULL
);
2701 msi_event_fire( dialog
->package
, szSelectionPath
, rec
);
2704 msiobj_release(&row
->hdr
);
2705 msiobj_release(&rec
->hdr
);
2710 static UINT
msi_dialog_selection_tree( msi_dialog
*dialog
, MSIRECORD
*rec
)
2712 msi_control
*control
;
2713 LPCWSTR prop
, control_name
;
2714 MSIPACKAGE
*package
= dialog
->package
;
2716 struct msi_selection_tree_info
*info
;
2718 info
= msi_alloc( sizeof *info
);
2720 return ERROR_FUNCTION_FAILED
;
2722 /* create the treeview control */
2723 style
= TVS_HASLINES
| TVS_HASBUTTONS
| TVS_LINESATROOT
;
2724 style
|= WS_GROUP
| WS_VSCROLL
;
2725 control
= msi_dialog_add_control( dialog
, rec
, WC_TREEVIEWW
, style
);
2729 return ERROR_FUNCTION_FAILED
;
2732 control
->handler
= msi_dialog_seltree_handler
;
2733 control_name
= MSI_RecordGetString( rec
, 2 );
2734 control
->attributes
= MSI_RecordGetInteger( rec
, 8 );
2735 prop
= MSI_RecordGetString( rec
, 9 );
2736 control
->property
= msi_dialog_dup_property( dialog
, prop
, FALSE
);
2739 info
->dialog
= dialog
;
2740 info
->hwnd
= control
->hwnd
;
2741 info
->oldproc
= (WNDPROC
) SetWindowLongPtrW( control
->hwnd
, GWLP_WNDPROC
,
2742 (LONG_PTR
)MSISelectionTree_WndProc
);
2743 SetPropW( control
->hwnd
, szButtonData
, info
);
2745 event_subscribe( dialog
, szSelectionPath
, control_name
, szProperty
);
2748 msi_seltree_create_imagelist( control
->hwnd
);
2749 msi_seltree_add_child_features( package
, control
->hwnd
, NULL
, NULL
);
2751 return ERROR_SUCCESS
;
2754 /******************** Group Box ***************************************/
2756 static UINT
msi_dialog_group_box( msi_dialog
*dialog
, MSIRECORD
*rec
)
2758 msi_control
*control
;
2761 style
= BS_GROUPBOX
| WS_CHILD
| WS_GROUP
;
2762 control
= msi_dialog_add_control( dialog
, rec
, WC_BUTTONW
, style
);
2764 return ERROR_FUNCTION_FAILED
;
2766 return ERROR_SUCCESS
;
2769 /******************** List Box ***************************************/
2771 struct msi_listbox_info
2781 static LRESULT WINAPI
MSIListBox_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
2783 struct msi_listbox_info
*info
;
2787 TRACE("%p %04x %08lx %08lx\n", hWnd
, msg
, wParam
, lParam
);
2789 info
= GetPropW( hWnd
, szButtonData
);
2793 r
= CallWindowProcW( info
->oldproc
, hWnd
, msg
, wParam
, lParam
);
2798 for (j
= 0; j
< info
->num_items
; j
++)
2799 msi_free( info
->items
[j
] );
2800 msi_free( info
->items
);
2802 RemovePropW( hWnd
, szButtonData
);
2809 static UINT
msi_listbox_add_item( MSIRECORD
*rec
, LPVOID param
)
2811 struct msi_listbox_info
*info
= param
;
2812 LPCWSTR value
, text
;
2815 value
= MSI_RecordGetString( rec
, 3 );
2816 text
= MSI_RecordGetString( rec
, 4 );
2818 info
->items
[info
->addpos_items
] = strdupW( value
);
2820 pos
= SendMessageW( info
->hwnd
, LB_ADDSTRING
, 0, (LPARAM
)text
);
2821 SendMessageW( info
->hwnd
, LB_SETITEMDATA
, pos
, (LPARAM
)info
->items
[info
->addpos_items
] );
2822 info
->addpos_items
++;
2823 return ERROR_SUCCESS
;
2826 static UINT
msi_listbox_add_items( struct msi_listbox_info
*info
, LPCWSTR property
)
2828 static const WCHAR query
[] = {
2829 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2830 '`','L','i','s','t','B','o','x','`',' ','W','H','E','R','E',' ',
2831 '`','P','r','o','p','e','r','t','y','`',' ','=',' ','\'','%','s','\'',' ',
2832 'O','R','D','E','R',' ','B','Y',' ','`','O','r','d','e','r','`',0};
2837 r
= MSI_OpenQuery( info
->dialog
->package
->db
, &view
, query
, property
);
2838 if ( r
!= ERROR_SUCCESS
)
2841 /* just get the number of records */
2843 r
= MSI_IterateRecords( view
, &count
, NULL
, NULL
);
2844 if (r
!= ERROR_SUCCESS
)
2846 msiobj_release( &view
->hdr
);
2849 info
->num_items
= count
;
2850 info
->items
= msi_alloc( sizeof(*info
->items
) * count
);
2852 r
= MSI_IterateRecords( view
, NULL
, msi_listbox_add_item
, info
);
2853 msiobj_release( &view
->hdr
);
2857 static UINT
msi_dialog_listbox_handler( msi_dialog
*dialog
,
2858 msi_control
*control
, WPARAM param
)
2860 struct msi_listbox_info
*info
;
2864 if( HIWORD(param
) != LBN_SELCHANGE
)
2865 return ERROR_SUCCESS
;
2867 info
= GetPropW( control
->hwnd
, szButtonData
);
2868 index
= SendMessageW( control
->hwnd
, LB_GETCURSEL
, 0, 0 );
2869 value
= (LPCWSTR
) SendMessageW( control
->hwnd
, LB_GETITEMDATA
, index
, 0 );
2871 msi_dialog_set_property( info
->dialog
->package
, control
->property
, value
);
2872 msi_dialog_evaluate_control_conditions( info
->dialog
);
2874 return ERROR_SUCCESS
;
2877 static UINT
msi_dialog_list_box( msi_dialog
*dialog
, MSIRECORD
*rec
)
2879 struct msi_listbox_info
*info
;
2880 msi_control
*control
;
2881 DWORD attributes
, style
;
2884 info
= msi_alloc( sizeof *info
);
2886 return ERROR_FUNCTION_FAILED
;
2888 style
= WS_TABSTOP
| WS_GROUP
| WS_CHILD
| LBS_NOTIFY
| WS_VSCROLL
| WS_BORDER
;
2889 attributes
= MSI_RecordGetInteger( rec
, 8 );
2890 if (~attributes
& msidbControlAttributesSorted
)
2893 control
= msi_dialog_add_control( dialog
, rec
, WC_LISTBOXW
, style
);
2897 return ERROR_FUNCTION_FAILED
;
2900 control
->handler
= msi_dialog_listbox_handler
;
2902 prop
= MSI_RecordGetString( rec
, 9 );
2903 control
->property
= msi_dialog_dup_property( dialog
, prop
, FALSE
);
2906 info
->dialog
= dialog
;
2907 info
->hwnd
= control
->hwnd
;
2909 info
->addpos_items
= 0;
2910 info
->oldproc
= (WNDPROC
)SetWindowLongPtrW( control
->hwnd
, GWLP_WNDPROC
,
2911 (LONG_PTR
)MSIListBox_WndProc
);
2912 SetPropW( control
->hwnd
, szButtonData
, info
);
2914 if ( control
->property
)
2915 msi_listbox_add_items( info
, control
->property
);
2917 return ERROR_SUCCESS
;
2920 /******************** Directory Combo ***************************************/
2922 static void msi_dialog_update_directory_combo( msi_dialog
*dialog
, msi_control
*control
)
2927 if (!control
&& !(control
= msi_dialog_find_control_by_type( dialog
, szDirectoryCombo
)))
2930 indirect
= control
->attributes
& msidbControlAttributesIndirect
;
2931 prop
= msi_dialog_dup_property( dialog
, control
->property
, indirect
);
2932 path
= msi_dialog_dup_property( dialog
, prop
, TRUE
);
2934 PathStripPathW( path
);
2935 PathRemoveBackslashW( path
);
2937 SendMessageW( control
->hwnd
, CB_INSERTSTRING
, 0, (LPARAM
)path
);
2938 SendMessageW( control
->hwnd
, CB_SETCURSEL
, 0, 0 );
2944 static UINT
msi_dialog_directory_combo( msi_dialog
*dialog
, MSIRECORD
*rec
)
2946 msi_control
*control
;
2950 /* FIXME: use CBS_OWNERDRAWFIXED and add owner draw code */
2951 style
= CBS_DROPDOWNLIST
| CBS_HASSTRINGS
| WS_CHILD
|
2952 WS_GROUP
| WS_TABSTOP
| WS_VSCROLL
;
2953 control
= msi_dialog_add_control( dialog
, rec
, WC_COMBOBOXW
, style
);
2955 return ERROR_FUNCTION_FAILED
;
2957 control
->attributes
= MSI_RecordGetInteger( rec
, 8 );
2958 prop
= MSI_RecordGetString( rec
, 9 );
2959 control
->property
= msi_dialog_dup_property( dialog
, prop
, FALSE
);
2961 msi_dialog_update_directory_combo( dialog
, control
);
2963 return ERROR_SUCCESS
;
2966 /******************** Directory List ***************************************/
2968 static void msi_dialog_update_directory_list( msi_dialog
*dialog
, msi_control
*control
)
2970 WCHAR dir_spec
[MAX_PATH
];
2971 WIN32_FIND_DATAW wfd
;
2977 static const WCHAR asterisk
[] = {'*',0};
2979 if (!control
&& !(control
= msi_dialog_find_control_by_type( dialog
, szDirectoryList
)))
2982 /* clear the list-view */
2983 SendMessageW( control
->hwnd
, LVM_DELETEALLITEMS
, 0, 0 );
2985 indirect
= control
->attributes
& msidbControlAttributesIndirect
;
2986 prop
= msi_dialog_dup_property( dialog
, control
->property
, indirect
);
2987 path
= msi_dialog_dup_property( dialog
, prop
, TRUE
);
2989 lstrcpyW( dir_spec
, path
);
2990 lstrcatW( dir_spec
, asterisk
);
2992 file
= FindFirstFileW( dir_spec
, &wfd
);
2993 if ( file
== INVALID_HANDLE_VALUE
)
2998 if ( wfd
.dwFileAttributes
!= FILE_ATTRIBUTE_DIRECTORY
)
3001 if ( !strcmpW( wfd
.cFileName
, szDot
) || !strcmpW( wfd
.cFileName
, szDotDot
) )
3004 item
.mask
= LVIF_TEXT
;
3005 item
.cchTextMax
= MAX_PATH
;
3008 item
.pszText
= wfd
.cFileName
;
3010 SendMessageW( control
->hwnd
, LVM_INSERTITEMW
, 0, (LPARAM
)&item
);
3011 } while ( FindNextFileW( file
, &wfd
) );
3018 static UINT
msi_dialog_directorylist_up( msi_dialog
*dialog
)
3020 msi_control
*control
;
3021 LPWSTR prop
, path
, ptr
;
3024 control
= msi_dialog_find_control_by_type( dialog
, szDirectoryList
);
3025 indirect
= control
->attributes
& msidbControlAttributesIndirect
;
3026 prop
= msi_dialog_dup_property( dialog
, control
->property
, indirect
);
3027 path
= msi_dialog_dup_property( dialog
, prop
, TRUE
);
3029 /* strip off the last directory */
3030 ptr
= PathFindFileNameW( path
);
3031 if (ptr
!= path
) *(ptr
- 1) = '\0';
3032 PathAddBackslashW( path
);
3034 msi_dialog_set_property( dialog
->package
, prop
, path
);
3036 msi_dialog_update_directory_list( dialog
, NULL
);
3037 msi_dialog_update_directory_combo( dialog
, NULL
);
3038 msi_dialog_update_pathedit( dialog
, NULL
);
3043 return ERROR_SUCCESS
;
3046 static UINT
msi_dialog_dirlist_handler( msi_dialog
*dialog
,
3047 msi_control
*control
, WPARAM param
)
3049 LPNMHDR nmhdr
= (LPNMHDR
)param
;
3050 WCHAR new_path
[MAX_PATH
];
3051 WCHAR text
[MAX_PATH
];
3057 if (nmhdr
->code
!= LVN_ITEMACTIVATE
)
3058 return ERROR_SUCCESS
;
3060 index
= SendMessageW( control
->hwnd
, LVM_GETNEXTITEM
, -1, LVNI_SELECTED
);
3063 ERR("No list-view item selected!\n");
3064 return ERROR_FUNCTION_FAILED
;
3068 item
.pszText
= text
;
3069 item
.cchTextMax
= MAX_PATH
;
3070 SendMessageW( control
->hwnd
, LVM_GETITEMTEXTW
, index
, (LPARAM
)&item
);
3072 indirect
= control
->attributes
& msidbControlAttributesIndirect
;
3073 prop
= msi_dialog_dup_property( dialog
, control
->property
, indirect
);
3074 path
= msi_dialog_dup_property( dialog
, prop
, TRUE
);
3076 lstrcpyW( new_path
, path
);
3077 lstrcatW( new_path
, text
);
3078 lstrcatW( new_path
, szBackSlash
);
3080 msi_dialog_set_property( dialog
->package
, prop
, new_path
);
3082 msi_dialog_update_directory_list( dialog
, NULL
);
3083 msi_dialog_update_directory_combo( dialog
, NULL
);
3084 msi_dialog_update_pathedit( dialog
, NULL
);
3088 return ERROR_SUCCESS
;
3091 static UINT
msi_dialog_directory_list( msi_dialog
*dialog
, MSIRECORD
*rec
)
3093 msi_control
*control
;
3097 style
= LVS_LIST
| WS_VSCROLL
| LVS_SHAREIMAGELISTS
|
3098 LVS_AUTOARRANGE
| LVS_SINGLESEL
| WS_BORDER
|
3099 LVS_SORTASCENDING
| WS_CHILD
| WS_GROUP
| WS_TABSTOP
;
3100 control
= msi_dialog_add_control( dialog
, rec
, WC_LISTVIEWW
, style
);
3102 return ERROR_FUNCTION_FAILED
;
3104 control
->attributes
= MSI_RecordGetInteger( rec
, 8 );
3105 control
->handler
= msi_dialog_dirlist_handler
;
3106 prop
= MSI_RecordGetString( rec
, 9 );
3107 control
->property
= msi_dialog_dup_property( dialog
, prop
, FALSE
);
3109 /* double click to activate an item in the list */
3110 SendMessageW( control
->hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
,
3111 0, LVS_EX_TWOCLICKACTIVATE
);
3113 msi_dialog_update_directory_list( dialog
, control
);
3115 return ERROR_SUCCESS
;
3118 /******************** VolumeCost List ***************************************/
3120 static BOOL
str_is_number( LPCWSTR str
)
3124 for (i
= 0; i
< lstrlenW( str
); i
++)
3125 if (!isdigitW(str
[i
]))
3131 static const WCHAR column_keys
[][80] =
3133 {'V','o','l','u','m','e','C','o','s','t','V','o','l','u','m','e',0},
3134 {'V','o','l','u','m','e','C','o','s','t','S','i','z','e',0},
3135 {'V','o','l','u','m','e','C','o','s','t','A','v','a','i','l','a','b','l','e',0},
3136 {'V','o','l','u','m','e','C','o','s','t','R','e','q','u','i','r','e','d',0},
3137 {'V','o','l','u','m','e','C','o','s','t','D','i','f','f','e','r','e','n','c','e',0}
3140 static void msi_dialog_vcl_add_columns( msi_dialog
*dialog
, msi_control
*control
, MSIRECORD
*rec
)
3142 LPCWSTR text
= MSI_RecordGetString( rec
, 10 );
3143 LPCWSTR begin
= text
, end
;
3148 static const WCHAR negative
[] = {'-',0};
3152 while ((begin
= strchrW( begin
, '{' )) && count
< 5)
3154 if (!(end
= strchrW( begin
, '}' )))
3157 num
= msi_alloc( (end
-begin
+1)*sizeof(WCHAR
) );
3161 lstrcpynW( num
, begin
+ 1, end
- begin
);
3162 begin
+= end
- begin
+ 1;
3164 /* empty braces or '0' hides the column */
3165 if ( !num
[0] || !strcmpW( num
, szZero
) )
3172 /* the width must be a positive number
3173 * if a width is invalid, all remaining columns are hidden
3175 if ( !strncmpW( num
, negative
, 1 ) || !str_is_number( num
) ) {
3180 ZeroMemory( &lvc
, sizeof(lvc
) );
3181 lvc
.mask
= LVCF_TEXT
| LVCF_WIDTH
| LVCF_SUBITEM
;
3182 lvc
.cx
= atolW( num
);
3183 lvc
.pszText
= msi_dialog_get_uitext( dialog
, column_keys
[count
] );
3185 SendMessageW( control
->hwnd
, LVM_INSERTCOLUMNW
, count
++, (LPARAM
)&lvc
);
3186 msi_free( lvc
.pszText
);
3191 static LONGLONG
msi_vcl_get_cost( msi_dialog
*dialog
)
3193 MSIFEATURE
*feature
;
3195 LONGLONG total_cost
= 0;
3197 LIST_FOR_EACH_ENTRY( feature
, &dialog
->package
->features
, MSIFEATURE
, entry
)
3199 if (ERROR_SUCCESS
== (MSI_GetFeatureCost(dialog
->package
, feature
,
3200 MSICOSTTREE_SELFONLY
, INSTALLSTATE_LOCAL
, &each_cost
)))
3202 /* each_cost is in 512-byte units */
3203 total_cost
+= each_cost
* 512;
3205 if (ERROR_SUCCESS
== (MSI_GetFeatureCost(dialog
->package
, feature
,
3206 MSICOSTTREE_SELFONLY
, INSTALLSTATE_ABSENT
, &each_cost
)))
3208 /* each_cost is in 512-byte units */
3209 total_cost
-= each_cost
* 512;
3215 static void msi_dialog_vcl_add_drives( msi_dialog
*dialog
, msi_control
*control
)
3217 ULARGE_INTEGER total
, free
;
3218 LONGLONG difference
, cost
;
3219 WCHAR size_text
[MAX_PATH
];
3220 WCHAR cost_text
[MAX_PATH
];
3226 cost
= msi_vcl_get_cost(dialog
);
3227 StrFormatByteSizeW(cost
, cost_text
, MAX_PATH
);
3229 size
= GetLogicalDriveStringsW( 0, NULL
);
3230 if ( !size
) return;
3232 drives
= msi_alloc( (size
+ 1) * sizeof(WCHAR
) );
3233 if ( !drives
) return;
3235 GetLogicalDriveStringsW( size
, drives
);
3240 lvitem
.mask
= LVIF_TEXT
;
3242 lvitem
.iSubItem
= 0;
3243 lvitem
.pszText
= ptr
;
3244 lvitem
.cchTextMax
= lstrlenW(ptr
) + 1;
3245 SendMessageW( control
->hwnd
, LVM_INSERTITEMW
, 0, (LPARAM
)&lvitem
);
3247 GetDiskFreeSpaceExW(ptr
, &free
, &total
, NULL
);
3248 difference
= free
.QuadPart
- cost
;
3250 StrFormatByteSizeW(total
.QuadPart
, size_text
, MAX_PATH
);
3251 lvitem
.iSubItem
= 1;
3252 lvitem
.pszText
= size_text
;
3253 lvitem
.cchTextMax
= lstrlenW(size_text
) + 1;
3254 SendMessageW( control
->hwnd
, LVM_SETITEMW
, 0, (LPARAM
)&lvitem
);
3256 StrFormatByteSizeW(free
.QuadPart
, size_text
, MAX_PATH
);
3257 lvitem
.iSubItem
= 2;
3258 lvitem
.pszText
= size_text
;
3259 lvitem
.cchTextMax
= lstrlenW(size_text
) + 1;
3260 SendMessageW( control
->hwnd
, LVM_SETITEMW
, 0, (LPARAM
)&lvitem
);
3262 lvitem
.iSubItem
= 3;
3263 lvitem
.pszText
= cost_text
;
3264 lvitem
.cchTextMax
= lstrlenW(cost_text
) + 1;
3265 SendMessageW( control
->hwnd
, LVM_SETITEMW
, 0, (LPARAM
)&lvitem
);
3267 StrFormatByteSizeW(difference
, size_text
, MAX_PATH
);
3268 lvitem
.iSubItem
= 4;
3269 lvitem
.pszText
= size_text
;
3270 lvitem
.cchTextMax
= lstrlenW(size_text
) + 1;
3271 SendMessageW( control
->hwnd
, LVM_SETITEMW
, 0, (LPARAM
)&lvitem
);
3273 ptr
+= lstrlenW(ptr
) + 1;
3280 static UINT
msi_dialog_volumecost_list( msi_dialog
*dialog
, MSIRECORD
*rec
)
3282 msi_control
*control
;
3285 style
= LVS_REPORT
| WS_VSCROLL
| WS_HSCROLL
| LVS_SHAREIMAGELISTS
|
3286 LVS_AUTOARRANGE
| LVS_SINGLESEL
| WS_BORDER
|
3287 WS_CHILD
| WS_TABSTOP
| WS_GROUP
;
3288 control
= msi_dialog_add_control( dialog
, rec
, WC_LISTVIEWW
, style
);
3290 return ERROR_FUNCTION_FAILED
;
3292 msi_dialog_vcl_add_columns( dialog
, control
, rec
);
3293 msi_dialog_vcl_add_drives( dialog
, control
);
3295 return ERROR_SUCCESS
;
3298 /******************** VolumeSelect Combo ***************************************/
3300 static UINT
msi_dialog_volsel_handler( msi_dialog
*dialog
,
3301 msi_control
*control
, WPARAM param
)
3303 WCHAR text
[MAX_PATH
];
3308 if (HIWORD(param
) != CBN_SELCHANGE
)
3309 return ERROR_SUCCESS
;
3311 index
= SendMessageW( control
->hwnd
, CB_GETCURSEL
, 0, 0 );
3312 if ( index
== CB_ERR
)
3314 ERR("No ComboBox item selected!\n");
3315 return ERROR_FUNCTION_FAILED
;
3318 SendMessageW( control
->hwnd
, CB_GETLBTEXT
, index
, (LPARAM
)text
);
3320 indirect
= control
->attributes
& msidbControlAttributesIndirect
;
3321 prop
= msi_dialog_dup_property( dialog
, control
->property
, indirect
);
3323 msi_dialog_set_property( dialog
->package
, prop
, text
);
3326 return ERROR_SUCCESS
;
3329 static void msi_dialog_vsc_add_drives( msi_dialog
*dialog
, msi_control
*control
)
3334 size
= GetLogicalDriveStringsW( 0, NULL
);
3335 if ( !size
) return;
3337 drives
= msi_alloc( (size
+ 1) * sizeof(WCHAR
) );
3338 if ( !drives
) return;
3340 GetLogicalDriveStringsW( size
, drives
);
3345 SendMessageW( control
->hwnd
, CB_ADDSTRING
, 0, (LPARAM
)ptr
);
3346 ptr
+= lstrlenW(ptr
) + 1;
3352 static UINT
msi_dialog_volumeselect_combo( msi_dialog
*dialog
, MSIRECORD
*rec
)
3354 msi_control
*control
;
3358 /* FIXME: CBS_OWNERDRAWFIXED */
3359 style
= WS_CHILD
| WS_VISIBLE
| WS_GROUP
| WS_TABSTOP
|
3360 CBS_DROPDOWNLIST
| CBS_SORT
| CBS_HASSTRINGS
|
3361 WS_EX_LEFT
| WS_EX_LTRREADING
| WS_EX_RIGHTSCROLLBAR
;
3362 control
= msi_dialog_add_control( dialog
, rec
, WC_COMBOBOXW
, style
);
3364 return ERROR_FUNCTION_FAILED
;
3366 control
->attributes
= MSI_RecordGetInteger( rec
, 8 );
3367 control
->handler
= msi_dialog_volsel_handler
;
3368 prop
= MSI_RecordGetString( rec
, 9 );
3369 control
->property
= msi_dialog_dup_property( dialog
, prop
, FALSE
);
3371 msi_dialog_vsc_add_drives( dialog
, control
);
3373 return ERROR_SUCCESS
;
3376 static UINT
msi_dialog_hyperlink_handler( msi_dialog
*dialog
, msi_control
*control
, WPARAM param
)
3378 static const WCHAR hrefW
[] = {'h','r','e','f'};
3379 static const WCHAR openW
[] = {'o','p','e','n',0};
3380 int len
, len_href
= sizeof(hrefW
) / sizeof(hrefW
[0]);
3385 item
.mask
= LIF_ITEMINDEX
| LIF_URL
;
3389 SendMessageW( control
->hwnd
, LM_GETITEM
, 0, (LPARAM
)&item
);
3392 while (*p
&& *p
!= '<') p
++;
3393 if (!*p
++) return ERROR_SUCCESS
;
3394 if (toupperW( *p
++ ) != 'A' || !isspaceW( *p
++ )) return ERROR_SUCCESS
;
3395 while (*p
&& isspaceW( *p
)) p
++;
3398 if (len
> len_href
&& !memicmpW( p
, hrefW
, len_href
))
3401 while (*p
&& isspaceW( *p
)) p
++;
3402 if (!*p
|| *p
++ != '=') return ERROR_SUCCESS
;
3403 while (*p
&& isspaceW( *p
)) p
++;
3405 if (*p
== '\"' || *p
== '\'') quote
= *p
++;
3409 while (*q
&& *q
!= quote
) q
++;
3410 if (*q
!= quote
) return ERROR_SUCCESS
;
3414 while (*q
&& *q
!= '>' && !isspaceW( *q
)) q
++;
3415 if (!*q
) return ERROR_SUCCESS
;
3417 item
.szUrl
[q
- item
.szUrl
] = 0;
3418 ShellExecuteW( NULL
, openW
, p
, NULL
, NULL
, SW_SHOWNORMAL
);
3420 return ERROR_SUCCESS
;
3423 static UINT
msi_dialog_hyperlink( msi_dialog
*dialog
, MSIRECORD
*rec
)
3425 msi_control
*control
;
3426 DWORD style
= WS_CHILD
| WS_TABSTOP
| WS_GROUP
;
3427 const WCHAR
*text
= MSI_RecordGetString( rec
, 10 );
3428 int len
= strlenW( text
);
3431 control
= msi_dialog_add_control( dialog
, rec
, WC_LINK
, style
);
3433 return ERROR_FUNCTION_FAILED
;
3435 control
->attributes
= MSI_RecordGetInteger( rec
, 8 );
3436 control
->handler
= msi_dialog_hyperlink_handler
;
3438 item
.mask
= LIF_ITEMINDEX
| LIF_STATE
| LIF_URL
;
3440 item
.state
= LIS_ENABLED
;
3441 item
.stateMask
= LIS_ENABLED
;
3442 if (len
< L_MAX_URL_LENGTH
) strcpyW( item
.szUrl
, text
);
3443 else item
.szUrl
[0] = 0;
3445 SendMessageW( control
->hwnd
, LM_SETITEM
, 0, (LPARAM
)&item
);
3447 return ERROR_SUCCESS
;
3450 static const struct control_handler msi_dialog_handler
[] =
3452 { szText
, msi_dialog_text_control
},
3453 { szPushButton
, msi_dialog_button_control
},
3454 { szLine
, msi_dialog_line_control
},
3455 { szBitmap
, msi_dialog_bitmap_control
},
3456 { szCheckBox
, msi_dialog_checkbox_control
},
3457 { szScrollableText
, msi_dialog_scrolltext_control
},
3458 { szComboBox
, msi_dialog_combo_control
},
3459 { szEdit
, msi_dialog_edit_control
},
3460 { szMaskedEdit
, msi_dialog_maskedit_control
},
3461 { szPathEdit
, msi_dialog_pathedit_control
},
3462 { szProgressBar
, msi_dialog_progress_bar
},
3463 { szRadioButtonGroup
, msi_dialog_radiogroup_control
},
3464 { szIcon
, msi_dialog_icon_control
},
3465 { szSelectionTree
, msi_dialog_selection_tree
},
3466 { szGroupBox
, msi_dialog_group_box
},
3467 { szListBox
, msi_dialog_list_box
},
3468 { szDirectoryCombo
, msi_dialog_directory_combo
},
3469 { szDirectoryList
, msi_dialog_directory_list
},
3470 { szVolumeCostList
, msi_dialog_volumecost_list
},
3471 { szVolumeSelectCombo
, msi_dialog_volumeselect_combo
},
3472 { szHyperLink
, msi_dialog_hyperlink
}
3475 #define NUM_CONTROL_TYPES (sizeof msi_dialog_handler/sizeof msi_dialog_handler[0])
3477 static UINT
msi_dialog_create_controls( MSIRECORD
*rec
, LPVOID param
)
3479 msi_dialog
*dialog
= param
;
3480 LPCWSTR control_type
;
3483 /* find and call the function that can create this type of control */
3484 control_type
= MSI_RecordGetString( rec
, 3 );
3485 for( i
=0; i
<NUM_CONTROL_TYPES
; i
++ )
3486 if (!strcmpiW( msi_dialog_handler
[i
].control_type
, control_type
))
3488 if( i
!= NUM_CONTROL_TYPES
)
3489 msi_dialog_handler
[i
].func( dialog
, rec
);
3491 ERR("no handler for element type %s\n", debugstr_w(control_type
));
3493 return ERROR_SUCCESS
;
3496 static UINT
msi_dialog_fill_controls( msi_dialog
*dialog
)
3498 static const WCHAR query
[] = {
3499 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
3500 'C','o','n','t','r','o','l',' ','W','H','E','R','E',' ',
3501 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',0};
3504 MSIPACKAGE
*package
= dialog
->package
;
3506 TRACE("%p %s\n", dialog
, debugstr_w(dialog
->name
) );
3508 /* query the Control table for all the elements of the control */
3509 r
= MSI_OpenQuery( package
->db
, &view
, query
, dialog
->name
);
3510 if( r
!= ERROR_SUCCESS
)
3512 ERR("query failed for dialog %s\n", debugstr_w(dialog
->name
));
3513 return ERROR_INVALID_PARAMETER
;
3516 r
= MSI_IterateRecords( view
, 0, msi_dialog_create_controls
, dialog
);
3517 msiobj_release( &view
->hdr
);
3521 static UINT
msi_dialog_reset( msi_dialog
*dialog
)
3523 /* FIXME: should restore the original values of any properties we changed */
3524 return msi_dialog_evaluate_control_conditions( dialog
);
3527 /* figure out the height of 10 point MS Sans Serif */
3528 static INT
msi_dialog_get_sans_serif_height( HWND hwnd
)
3530 static const WCHAR szSansSerif
[] = {
3531 'M','S',' ','S','a','n','s',' ','S','e','r','i','f',0 };
3536 HFONT hFont
, hOldFont
;
3539 hdc
= GetDC( hwnd
);
3542 memset( &lf
, 0, sizeof lf
);
3543 lf
.lfHeight
= MulDiv(12, GetDeviceCaps(hdc
, LOGPIXELSY
), 72);
3544 strcpyW( lf
.lfFaceName
, szSansSerif
);
3545 hFont
= CreateFontIndirectW(&lf
);
3548 hOldFont
= SelectObject( hdc
, hFont
);
3549 r
= GetTextMetricsW( hdc
, &tm
);
3551 height
= tm
.tmHeight
;
3552 SelectObject( hdc
, hOldFont
);
3553 DeleteObject( hFont
);
3555 ReleaseDC( hwnd
, hdc
);
3560 /* fetch the associated record from the Dialog table */
3561 static MSIRECORD
*msi_get_dialog_record( msi_dialog
*dialog
)
3563 static const WCHAR query
[] = {
3564 'S','E','L','E','C','T',' ','*',' ',
3565 'F','R','O','M',' ','D','i','a','l','o','g',' ',
3566 'W','H','E','R','E',' ',
3567 '`','D','i','a','l','o','g','`',' ','=',' ','\'','%','s','\'',0};
3568 MSIPACKAGE
*package
= dialog
->package
;
3569 MSIRECORD
*rec
= NULL
;
3571 TRACE("%p %s\n", dialog
, debugstr_w(dialog
->name
) );
3573 rec
= MSI_QueryGetRecord( package
->db
, query
, dialog
->name
);
3575 WARN("query failed for dialog %s\n", debugstr_w(dialog
->name
));
3580 static void msi_dialog_adjust_dialog_pos( msi_dialog
*dialog
, MSIRECORD
*rec
, LPRECT pos
)
3582 static const WCHAR szScreenX
[] = {'S','c','r','e','e','n','X',0};
3583 static const WCHAR szScreenY
[] = {'S','c','r','e','e','n','Y',0};
3590 center
.x
= MSI_RecordGetInteger( rec
, 2 );
3591 center
.y
= MSI_RecordGetInteger( rec
, 3 );
3593 sz
.cx
= MSI_RecordGetInteger( rec
, 4 );
3594 sz
.cy
= MSI_RecordGetInteger( rec
, 5 );
3596 sz
.cx
= msi_dialog_scale_unit( dialog
, sz
.cx
);
3597 sz
.cy
= msi_dialog_scale_unit( dialog
, sz
.cy
);
3599 xres
= msi_get_property_int( dialog
->package
->db
, szScreenX
, 0 );
3600 yres
= msi_get_property_int( dialog
->package
->db
, szScreenY
, 0 );
3602 center
.x
= MulDiv( center
.x
, xres
, 100 );
3603 center
.y
= MulDiv( center
.y
, yres
, 100 );
3605 /* turn the client pos into the window rectangle */
3606 if (dialog
->package
->center_x
&& dialog
->package
->center_y
)
3608 pos
->left
= dialog
->package
->center_x
- sz
.cx
/ 2.0;
3609 pos
->right
= pos
->left
+ sz
.cx
;
3610 pos
->top
= dialog
->package
->center_y
- sz
.cy
/ 2.0;
3611 pos
->bottom
= pos
->top
+ sz
.cy
;
3615 pos
->left
= center
.x
- sz
.cx
/2;
3616 pos
->right
= pos
->left
+ sz
.cx
;
3617 pos
->top
= center
.y
- sz
.cy
/2;
3618 pos
->bottom
= pos
->top
+ sz
.cy
;
3620 /* save the center */
3621 dialog
->package
->center_x
= center
.x
;
3622 dialog
->package
->center_y
= center
.y
;
3625 dialog
->size
.cx
= sz
.cx
;
3626 dialog
->size
.cy
= sz
.cy
;
3628 TRACE("%u %u %u %u\n", pos
->left
, pos
->top
, pos
->right
, pos
->bottom
);
3630 style
= GetWindowLongPtrW( dialog
->hwnd
, GWL_STYLE
);
3631 AdjustWindowRect( pos
, style
, FALSE
);
3634 static void msi_dialog_set_tab_order( msi_dialog
*dialog
, LPCWSTR first
)
3636 struct list tab_chain
;
3637 msi_control
*control
;
3638 HWND prev
= HWND_TOP
;
3640 list_init( &tab_chain
);
3641 if (!(control
= msi_dialog_find_control( dialog
, first
))) return;
3643 dialog
->hWndFocus
= control
->hwnd
;
3646 list_remove( &control
->entry
);
3647 list_add_tail( &tab_chain
, &control
->entry
);
3648 if (!control
->tabnext
) break;
3649 control
= msi_dialog_find_control( dialog
, control
->tabnext
);
3652 LIST_FOR_EACH_ENTRY( control
, &tab_chain
, msi_control
, entry
)
3654 SetWindowPos( control
->hwnd
, prev
, 0, 0, 0, 0,
3655 SWP_NOMOVE
| SWP_NOOWNERZORDER
| SWP_NOREDRAW
|
3656 SWP_NOREPOSITION
| SWP_NOSENDCHANGING
| SWP_NOSIZE
);
3657 prev
= control
->hwnd
;
3660 /* put them back on the main list */
3661 list_move_head( &dialog
->controls
, &tab_chain
);
3664 static LRESULT
msi_dialog_oncreate( HWND hwnd
, LPCREATESTRUCTW cs
)
3666 static const WCHAR df
[] = {
3667 'D','e','f','a','u','l','t','U','I','F','o','n','t',0 };
3668 static const WCHAR dfv
[] = {
3669 'M','S',' ','S','h','e','l','l',' ','D','l','g',0 };
3670 msi_dialog
*dialog
= cs
->lpCreateParams
;
3671 MSIRECORD
*rec
= NULL
;
3672 LPWSTR title
= NULL
;
3675 TRACE("%p %p\n", dialog
, dialog
->package
);
3677 dialog
->hwnd
= hwnd
;
3678 SetWindowLongPtrW( hwnd
, GWLP_USERDATA
, (LONG_PTR
) dialog
);
3680 rec
= msi_get_dialog_record( dialog
);
3683 TRACE("No record found for dialog %s\n", debugstr_w(dialog
->name
));
3687 dialog
->scale
= msi_dialog_get_sans_serif_height(dialog
->hwnd
);
3689 msi_dialog_adjust_dialog_pos( dialog
, rec
, &pos
);
3691 dialog
->attributes
= MSI_RecordGetInteger( rec
, 6 );
3693 dialog
->default_font
= msi_dup_property( dialog
->package
->db
, df
);
3694 if (!dialog
->default_font
)
3696 dialog
->default_font
= strdupW(dfv
);
3697 msiobj_release( &rec
->hdr
);
3698 if (!dialog
->default_font
) return -1;
3701 title
= msi_get_deformatted_field( dialog
->package
, rec
, 7 );
3702 SetWindowTextW( hwnd
, title
);
3705 SetWindowPos( hwnd
, 0, pos
.left
, pos
.top
,
3706 pos
.right
- pos
.left
, pos
.bottom
- pos
.top
,
3707 SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_NOREDRAW
);
3709 msi_dialog_build_font_list( dialog
);
3710 msi_dialog_fill_controls( dialog
);
3711 msi_dialog_evaluate_control_conditions( dialog
);
3712 msi_dialog_set_tab_order( dialog
, MSI_RecordGetString( rec
, 8 ) );
3713 msiobj_release( &rec
->hdr
);
3718 static LRESULT
msi_dialog_oncommand( msi_dialog
*dialog
, WPARAM param
, HWND hwnd
)
3720 msi_control
*control
= NULL
;
3722 TRACE("%p %p %08lx\n", dialog
, hwnd
, param
);
3727 control
= msi_dialog_find_control( dialog
, dialog
->control_default
);
3729 case 2: /* escape */
3730 control
= msi_dialog_find_control( dialog
, dialog
->control_cancel
);
3733 control
= msi_dialog_find_control_by_hwnd( dialog
, hwnd
);
3738 if( control
->handler
)
3740 control
->handler( dialog
, control
, param
);
3741 msi_dialog_evaluate_control_conditions( dialog
);
3748 static LRESULT
msi_dialog_onnotify( msi_dialog
*dialog
, LPARAM param
)
3750 LPNMHDR nmhdr
= (LPNMHDR
) param
;
3751 msi_control
*control
= msi_dialog_find_control_by_hwnd( dialog
, nmhdr
->hwndFrom
);
3753 TRACE("%p %p\n", dialog
, nmhdr
->hwndFrom
);
3755 if ( control
&& control
->handler
)
3756 control
->handler( dialog
, control
, param
);
3761 static void dialog_setfocus( msi_dialog
*dialog
)
3763 HWND hwnd
= dialog
->hWndFocus
;
3765 hwnd
= GetNextDlgTabItem( dialog
->hwnd
, hwnd
, TRUE
);
3766 hwnd
= GetNextDlgTabItem( dialog
->hwnd
, hwnd
, FALSE
);
3768 dialog
->hWndFocus
= hwnd
;
3771 static LRESULT WINAPI
MSIDialog_WndProc( HWND hwnd
, UINT msg
,
3772 WPARAM wParam
, LPARAM lParam
)
3774 msi_dialog
*dialog
= (LPVOID
) GetWindowLongPtrW( hwnd
, GWLP_USERDATA
);
3776 TRACE("0x%04x\n", msg
);
3781 dialog
->package
->center_x
= LOWORD(lParam
) + dialog
->size
.cx
/ 2.0;
3782 dialog
->package
->center_y
= HIWORD(lParam
) + dialog
->size
.cy
/ 2.0;
3786 return msi_dialog_oncreate( hwnd
, (LPCREATESTRUCTW
)lParam
);
3789 return msi_dialog_oncommand( dialog
, wParam
, (HWND
)lParam
);
3792 if( LOWORD(wParam
) == WA_INACTIVE
)
3793 dialog
->hWndFocus
= GetFocus();
3795 dialog_setfocus( dialog
);
3799 dialog_setfocus( dialog
);
3802 /* bounce back to our subclassed static control */
3803 case WM_CTLCOLORSTATIC
:
3804 return SendMessageW( (HWND
) lParam
, WM_CTLCOLORSTATIC
, wParam
, lParam
);
3807 dialog
->hwnd
= NULL
;
3810 return msi_dialog_onnotify( dialog
, lParam
);
3812 return DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
3815 static void process_pending_messages( HWND hdlg
)
3819 while (PeekMessageW( &msg
, 0, 0, 0, PM_REMOVE
))
3821 if (hdlg
&& IsDialogMessageW( hdlg
, &msg
)) continue;
3822 TranslateMessage( &msg
);
3823 DispatchMessageW( &msg
);
3827 static UINT
dialog_run_message_loop( msi_dialog
*dialog
)
3832 if( uiThreadId
!= GetCurrentThreadId() )
3833 return SendMessageW( hMsiHiddenWindow
, WM_MSI_DIALOG_CREATE
, 0, (LPARAM
) dialog
);
3835 /* create the dialog window, don't show it yet */
3836 style
= WS_OVERLAPPED
;
3837 if( dialog
->attributes
& msidbDialogAttributesVisible
)
3838 style
|= WS_VISIBLE
;
3840 hwnd
= CreateWindowW( szMsiDialogClass
, dialog
->name
, style
,
3841 CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
,
3842 NULL
, NULL
, NULL
, dialog
);
3845 ERR("Failed to create dialog %s\n", debugstr_w( dialog
->name
));
3846 return ERROR_FUNCTION_FAILED
;
3849 ShowWindow( hwnd
, SW_SHOW
);
3850 /* UpdateWindow( hwnd ); - and causes the transparent static controls not to paint */
3852 if( dialog
->attributes
& msidbDialogAttributesModal
)
3854 while( !dialog
->finished
)
3856 MsgWaitForMultipleObjects( 0, NULL
, 0, INFINITE
, QS_ALLINPUT
);
3857 process_pending_messages( dialog
->hwnd
);
3861 return ERROR_IO_PENDING
;
3863 return ERROR_SUCCESS
;
3866 static LRESULT WINAPI
MSIHiddenWindowProc( HWND hwnd
, UINT msg
,
3867 WPARAM wParam
, LPARAM lParam
)
3869 msi_dialog
*dialog
= (msi_dialog
*) lParam
;
3871 TRACE("%d %p\n", msg
, dialog
);
3875 case WM_MSI_DIALOG_CREATE
:
3876 return dialog_run_message_loop( dialog
);
3877 case WM_MSI_DIALOG_DESTROY
:
3878 msi_dialog_destroy( dialog
);
3881 return DefWindowProcW( hwnd
, msg
, wParam
, lParam
);
3884 static BOOL
dialog_register_class( void )
3888 ZeroMemory( &cls
, sizeof cls
);
3889 cls
.lpfnWndProc
= MSIDialog_WndProc
;
3890 cls
.hInstance
= NULL
;
3891 cls
.hIcon
= LoadIconW(0, (LPWSTR
)IDI_APPLICATION
);
3892 cls
.hCursor
= LoadCursorW(0, (LPWSTR
)IDC_ARROW
);
3893 cls
.hbrBackground
= (HBRUSH
)(COLOR_3DFACE
+ 1);
3894 cls
.lpszMenuName
= NULL
;
3895 cls
.lpszClassName
= szMsiDialogClass
;
3897 if( !RegisterClassW( &cls
) )
3900 cls
.lpfnWndProc
= MSIHiddenWindowProc
;
3901 cls
.lpszClassName
= szMsiHiddenWindow
;
3903 if( !RegisterClassW( &cls
) )
3906 uiThreadId
= GetCurrentThreadId();
3908 hMsiHiddenWindow
= CreateWindowW( szMsiHiddenWindow
, NULL
, WS_OVERLAPPED
,
3909 0, 0, 100, 100, NULL
, NULL
, NULL
, NULL
);
3910 if( !hMsiHiddenWindow
)
3916 static msi_dialog
*dialog_create( MSIPACKAGE
*package
, const WCHAR
*name
, msi_dialog
*parent
,
3917 control_event_handler event_handler
)
3919 MSIRECORD
*rec
= NULL
;
3922 TRACE("%s\n", debugstr_w(name
));
3924 if (!hMsiHiddenWindow
) dialog_register_class();
3926 /* allocate the structure for the dialog to use */
3927 dialog
= msi_alloc_zero( FIELD_OFFSET( msi_dialog
, name
[strlenW( name
) + 1] ));
3930 strcpyW( dialog
->name
, name
);
3931 dialog
->parent
= parent
;
3932 msiobj_addref( &package
->hdr
);
3933 dialog
->package
= package
;
3934 dialog
->event_handler
= event_handler
;
3935 dialog
->finished
= 0;
3936 list_init( &dialog
->controls
);
3937 list_init( &dialog
->fonts
);
3939 /* verify that the dialog exists */
3940 rec
= msi_get_dialog_record( dialog
);
3943 msiobj_release( &package
->hdr
);
3947 dialog
->attributes
= MSI_RecordGetInteger( rec
, 6 );
3948 dialog
->control_default
= strdupW( MSI_RecordGetString( rec
, 9 ) );
3949 dialog
->control_cancel
= strdupW( MSI_RecordGetString( rec
, 10 ) );
3950 msiobj_release( &rec
->hdr
);
3955 static void msi_dialog_end_dialog( msi_dialog
*dialog
)
3957 TRACE("%p\n", dialog
);
3958 dialog
->finished
= 1;
3959 PostMessageW(dialog
->hwnd
, WM_NULL
, 0, 0);
3962 void msi_dialog_check_messages( HANDLE handle
)
3966 /* in threads other than the UI thread, block */
3967 if( uiThreadId
!= GetCurrentThreadId() )
3969 if (!handle
) return;
3970 while (MsgWaitForMultipleObjectsEx( 1, &handle
, INFINITE
, QS_ALLINPUT
, 0 ) == WAIT_OBJECT_0
+ 1)
3973 while (PeekMessageW( &msg
, NULL
, 0, 0, PM_REMOVE
))
3975 TranslateMessage( &msg
);
3976 DispatchMessageW( &msg
);
3982 /* there are two choices for the UI thread */
3985 process_pending_messages( NULL
);
3991 * block here until somebody creates a new dialog or
3992 * the handle we're waiting on becomes ready
3994 r
= MsgWaitForMultipleObjects( 1, &handle
, 0, INFINITE
, QS_ALLINPUT
);
3995 if( r
== WAIT_OBJECT_0
)
4000 static void dialog_do_preview( msi_dialog
*dialog
)
4003 dialog
->attributes
|= msidbDialogAttributesVisible
;
4004 dialog
->attributes
&= ~msidbDialogAttributesModal
;
4005 dialog_run_message_loop( dialog
);
4008 static void free_subscriber( struct subscriber
*sub
)
4010 msi_free( sub
->event
);
4011 msi_free( sub
->control
);
4012 msi_free( sub
->attribute
);
4016 static void event_cleanup_subscriptions( MSIPACKAGE
*package
, const WCHAR
*dialog
)
4018 struct list
*item
, *next
;
4020 LIST_FOR_EACH_SAFE( item
, next
, &package
->subscriptions
)
4022 struct subscriber
*sub
= LIST_ENTRY( item
, struct subscriber
, entry
);
4024 if (strcmpW( sub
->dialog
->name
, dialog
)) continue;
4025 list_remove( &sub
->entry
);
4026 free_subscriber( sub
);
4030 void msi_dialog_destroy( msi_dialog
*dialog
)
4032 msi_font
*font
, *next
;
4034 if( uiThreadId
!= GetCurrentThreadId() )
4036 SendMessageW( hMsiHiddenWindow
, WM_MSI_DIALOG_DESTROY
, 0, (LPARAM
) dialog
);
4041 ShowWindow( dialog
->hwnd
, SW_HIDE
);
4044 DestroyWindow( dialog
->hwnd
);
4046 /* unsubscribe events */
4047 event_cleanup_subscriptions( dialog
->package
, dialog
->name
);
4049 /* destroy the list of controls */
4050 while( !list_empty( &dialog
->controls
) )
4054 t
= LIST_ENTRY( list_head( &dialog
->controls
),
4055 msi_control
, entry
);
4056 msi_destroy_control( t
);
4059 /* destroy the list of fonts */
4060 LIST_FOR_EACH_ENTRY_SAFE( font
, next
, &dialog
->fonts
, msi_font
, entry
)
4062 list_remove( &font
->entry
);
4063 DeleteObject( font
->hfont
);
4066 msi_free( dialog
->default_font
);
4068 msi_free( dialog
->control_default
);
4069 msi_free( dialog
->control_cancel
);
4070 msiobj_release( &dialog
->package
->hdr
);
4071 dialog
->package
= NULL
;
4075 void msi_dialog_unregister_class( void )
4077 DestroyWindow( hMsiHiddenWindow
);
4078 hMsiHiddenWindow
= NULL
;
4079 UnregisterClassW( szMsiDialogClass
, NULL
);
4080 UnregisterClassW( szMsiHiddenWindow
, NULL
);
4084 void msi_event_cleanup_all_subscriptions( MSIPACKAGE
*package
)
4086 struct list
*item
, *next
;
4088 LIST_FOR_EACH_SAFE( item
, next
, &package
->subscriptions
)
4090 struct subscriber
*sub
= LIST_ENTRY( item
, struct subscriber
, entry
);
4091 list_remove( &sub
->entry
);
4092 free_subscriber( sub
);
4096 static UINT
error_dialog_handler( msi_dialog
*dialog
, const WCHAR
*event
, const WCHAR
*argument
)
4098 static const WCHAR end_dialog
[] = {'E','n','d','D','i','a','l','o','g',0};
4099 static const WCHAR error_abort
[] = {'E','r','r','o','r','A','b','o','r','t',0};
4100 static const WCHAR error_cancel
[] = {'E','r','r','o','r','C','a','n','c','e','l',0};
4101 static const WCHAR error_no
[] = {'E','r','r','o','r','N','o',0};
4102 static const WCHAR result_prop
[] = {
4103 'M','S','I','E','r','r','o','r','D','i','a','l','o','g','R','e','s','u','l','t',0
4106 if ( strcmpW( event
, end_dialog
) )
4107 return ERROR_SUCCESS
;
4109 if ( !strcmpW( argument
, error_abort
) || !strcmpW( argument
, error_cancel
) ||
4110 !strcmpW( argument
, error_no
) )
4112 msi_set_property( dialog
->package
->db
, result_prop
, error_abort
, -1 );
4115 msi_event_cleanup_all_subscriptions( dialog
->package
);
4116 msi_dialog_end_dialog( dialog
);
4118 return ERROR_SUCCESS
;
4121 static UINT
msi_error_dialog_set_error( MSIPACKAGE
*package
, LPWSTR error_dialog
, LPWSTR error
)
4125 static const WCHAR update
[] =
4126 {'U','P','D','A','T','E',' ','`','C','o','n','t','r','o','l','`',' ',
4127 'S','E','T',' ','`','T','e','x','t','`',' ','=',' ','\'','%','s','\'',' ',
4128 'W','H','E','R','E', ' ','`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',' ',
4129 'A','N','D',' ','`','C','o','n','t','r','o','l','`',' ','=',' ',
4130 '\'','E','r','r','o','r','T','e','x','t','\'',0};
4132 row
= MSI_QueryGetRecord( package
->db
, update
, error
, error_dialog
);
4134 return ERROR_FUNCTION_FAILED
;
4136 msiobj_release(&row
->hdr
);
4137 return ERROR_SUCCESS
;
4140 UINT
msi_spawn_error_dialog( MSIPACKAGE
*package
, LPWSTR error_dialog
, LPWSTR error
)
4143 WCHAR result
[MAX_PATH
];
4144 UINT r
= ERROR_SUCCESS
;
4145 DWORD size
= MAX_PATH
;
4148 static const WCHAR pn_prop
[] = {'P','r','o','d','u','c','t','N','a','m','e',0};
4149 static const WCHAR title_fmt
[] = {'%','s',' ','W','a','r','n','i','n','g',0};
4150 static const WCHAR error_abort
[] = {'E','r','r','o','r','A','b','o','r','t',0};
4151 static const WCHAR result_prop
[] = {
4152 'M','S','I','E','r','r','o','r','D','i','a','l','o','g','R','e','s','u','l','t',0
4155 if ((package
->ui_level
& INSTALLUILEVEL_MASK
) == INSTALLUILEVEL_NONE
) return ERROR_SUCCESS
;
4157 if ( !error_dialog
)
4159 LPWSTR product_name
= msi_dup_property( package
->db
, pn_prop
);
4160 WCHAR title
[MAX_PATH
];
4162 sprintfW( title
, title_fmt
, product_name
);
4163 res
= MessageBoxW( NULL
, error
, title
, MB_OKCANCEL
| MB_ICONWARNING
);
4165 msi_free( product_name
);
4168 return ERROR_SUCCESS
;
4170 return ERROR_FUNCTION_FAILED
;
4173 r
= msi_error_dialog_set_error( package
, error_dialog
, error
);
4174 if ( r
!= ERROR_SUCCESS
)
4177 dialog
= dialog_create( package
, error_dialog
, package
->dialog
, error_dialog_handler
);
4179 return ERROR_FUNCTION_FAILED
;
4181 dialog
->finished
= FALSE
;
4182 r
= dialog_run_message_loop( dialog
);
4183 if ( r
!= ERROR_SUCCESS
)
4186 r
= msi_get_property( package
->db
, result_prop
, result
, &size
);
4187 if ( r
!= ERROR_SUCCESS
)
4190 if ( !strcmpW( result
, error_abort
) )
4191 r
= ERROR_FUNCTION_FAILED
;
4194 msi_dialog_destroy( dialog
);
4199 static void MSI_ClosePreview( MSIOBJECTHDR
*arg
)
4201 MSIPREVIEW
*preview
= (MSIPREVIEW
*)arg
;
4202 msiobj_release( &preview
->package
->hdr
);
4205 static MSIPREVIEW
*MSI_EnableUIPreview( MSIDATABASE
*db
)
4207 MSIPREVIEW
*preview
= NULL
;
4208 MSIPACKAGE
*package
;
4210 package
= MSI_CreatePackage( db
, NULL
);
4213 preview
= alloc_msiobject( MSIHANDLETYPE_PREVIEW
, sizeof(MSIPREVIEW
), MSI_ClosePreview
);
4216 preview
->package
= package
;
4217 msiobj_addref( &package
->hdr
);
4219 msiobj_release( &package
->hdr
);
4224 UINT WINAPI
MsiEnableUIPreview( MSIHANDLE hdb
, MSIHANDLE
*phPreview
)
4227 MSIPREVIEW
*preview
;
4228 UINT r
= ERROR_FUNCTION_FAILED
;
4230 TRACE("%d %p\n", hdb
, phPreview
);
4232 db
= msihandle2msiinfo( hdb
, MSIHANDLETYPE_DATABASE
);
4235 IWineMsiRemoteDatabase
*remote_database
;
4237 remote_database
= (IWineMsiRemoteDatabase
*)msi_get_remote( hdb
);
4238 if (!remote_database
)
4239 return ERROR_INVALID_HANDLE
;
4243 IWineMsiRemoteDatabase_Release( remote_database
);
4244 WARN("MsiEnableUIPreview not allowed during a custom action!\n");
4246 return ERROR_FUNCTION_FAILED
;
4248 preview
= MSI_EnableUIPreview( db
);
4251 *phPreview
= alloc_msihandle( &preview
->hdr
);
4252 msiobj_release( &preview
->hdr
);
4255 r
= ERROR_NOT_ENOUGH_MEMORY
;
4257 msiobj_release( &db
->hdr
);
4261 static UINT
preview_event_handler( msi_dialog
*dialog
, const WCHAR
*event
, const WCHAR
*argument
)
4263 MESSAGE("Preview dialog event '%s' (arg='%s')\n", debugstr_w(event
), debugstr_w(argument
));
4264 return ERROR_SUCCESS
;
4267 static UINT
MSI_PreviewDialogW( MSIPREVIEW
*preview
, LPCWSTR szDialogName
)
4269 msi_dialog
*dialog
= NULL
;
4270 UINT r
= ERROR_SUCCESS
;
4272 if (preview
->dialog
)
4273 msi_dialog_destroy( preview
->dialog
);
4275 /* an empty name means we should just destroy the current preview dialog */
4278 dialog
= dialog_create( preview
->package
, szDialogName
, NULL
, preview_event_handler
);
4280 dialog_do_preview( dialog
);
4282 r
= ERROR_FUNCTION_FAILED
;
4284 preview
->dialog
= dialog
;
4288 UINT WINAPI
MsiPreviewDialogW( MSIHANDLE hPreview
, LPCWSTR szDialogName
)
4290 MSIPREVIEW
*preview
;
4293 TRACE("%d %s\n", hPreview
, debugstr_w(szDialogName
));
4295 preview
= msihandle2msiinfo( hPreview
, MSIHANDLETYPE_PREVIEW
);
4297 return ERROR_INVALID_HANDLE
;
4299 r
= MSI_PreviewDialogW( preview
, szDialogName
);
4300 msiobj_release( &preview
->hdr
);
4304 UINT WINAPI
MsiPreviewDialogA( MSIHANDLE hPreview
, LPCSTR szDialogName
)
4309 TRACE("%d %s\n", hPreview
, debugstr_a(szDialogName
));
4313 strW
= strdupAtoW( szDialogName
);
4315 return ERROR_OUTOFMEMORY
;
4317 r
= MsiPreviewDialogW( hPreview
, strW
);
4322 UINT WINAPI
MsiPreviewBillboardW( MSIHANDLE hPreview
, LPCWSTR szControlName
, LPCWSTR szBillboard
)
4324 FIXME("%d %s %s\n", hPreview
, debugstr_w(szControlName
), debugstr_w(szBillboard
));
4325 return ERROR_CALL_NOT_IMPLEMENTED
;
4328 UINT WINAPI
MsiPreviewBillboardA( MSIHANDLE hPreview
, LPCSTR szControlName
, LPCSTR szBillboard
)
4330 FIXME("%d %s %s\n", hPreview
, debugstr_a(szControlName
), debugstr_a(szBillboard
));
4331 return ERROR_CALL_NOT_IMPLEMENTED
;
4334 typedef UINT (*event_handler
)( msi_dialog
*, const WCHAR
* );
4336 struct control_event
4339 event_handler handler
;
4342 static UINT
dialog_event_handler( msi_dialog
*, const WCHAR
*, const WCHAR
* );
4344 /* create a dialog box and run it if it's modal */
4345 static UINT
event_do_dialog( MSIPACKAGE
*package
, const WCHAR
*name
, msi_dialog
*parent
, BOOL destroy_modeless
)
4350 /* create a new dialog */
4351 dialog
= dialog_create( package
, name
, parent
, dialog_event_handler
);
4354 /* kill the current modeless dialog */
4355 if (destroy_modeless
&& package
->dialog
)
4357 msi_dialog_destroy( package
->dialog
);
4358 package
->dialog
= NULL
;
4361 /* modeless dialogs return an error message */
4362 r
= dialog_run_message_loop( dialog
);
4363 if (r
== ERROR_SUCCESS
)
4364 msi_dialog_destroy( dialog
);
4366 package
->dialog
= dialog
;
4368 else r
= ERROR_FUNCTION_FAILED
;
4372 /* end a modal dialog box */
4373 static UINT
event_end_dialog( msi_dialog
*dialog
, const WCHAR
*argument
)
4375 static const WCHAR exitW
[] = {'E','x','i','t',0};
4376 static const WCHAR retryW
[] = {'R','e','t','r','y',0};
4377 static const WCHAR ignoreW
[] = {'I','g','n','o','r','e',0};
4378 static const WCHAR returnW
[] = {'R','e','t','u','r','n',0};
4380 if (!strcmpW( argument
, exitW
))
4381 dialog
->package
->CurrentInstallState
= ERROR_INSTALL_USEREXIT
;
4382 else if (!strcmpW( argument
, retryW
))
4383 dialog
->package
->CurrentInstallState
= ERROR_INSTALL_SUSPEND
;
4384 else if (!strcmpW( argument
, ignoreW
))
4385 dialog
->package
->CurrentInstallState
= ERROR_SUCCESS
;
4386 else if (!strcmpW( argument
, returnW
))
4388 msi_dialog
*parent
= dialog
->parent
;
4389 msi_free( dialog
->package
->next_dialog
);
4390 dialog
->package
->next_dialog
= (parent
) ? strdupW( parent
->name
) : NULL
;
4391 dialog
->package
->CurrentInstallState
= ERROR_SUCCESS
;
4395 ERR("Unknown argument string %s\n", debugstr_w(argument
));
4396 dialog
->package
->CurrentInstallState
= ERROR_FUNCTION_FAILED
;
4398 event_cleanup_subscriptions( dialog
->package
, dialog
->name
);
4399 msi_dialog_end_dialog( dialog
);
4400 return ERROR_SUCCESS
;
4403 /* transition from one modal dialog to another modal dialog */
4404 static UINT
event_new_dialog( msi_dialog
*dialog
, const WCHAR
*argument
)
4406 /* store the name of the next dialog, and signal this one to end */
4407 dialog
->package
->next_dialog
= strdupW( argument
);
4408 msi_event_cleanup_all_subscriptions( dialog
->package
);
4409 msi_dialog_end_dialog( dialog
);
4410 return ERROR_SUCCESS
;
4413 /* create a new child dialog of an existing modal dialog */
4414 static UINT
event_spawn_dialog( msi_dialog
*dialog
, const WCHAR
*argument
)
4416 /* don't destroy a modeless dialogs that might be our parent */
4417 event_do_dialog( dialog
->package
, argument
, dialog
, FALSE
);
4418 if (dialog
->package
->CurrentInstallState
!= ERROR_SUCCESS
) msi_dialog_end_dialog( dialog
);
4419 return ERROR_SUCCESS
;
4422 /* creates a dialog that remains up for a period of time based on a condition */
4423 static UINT
event_spawn_wait_dialog( msi_dialog
*dialog
, const WCHAR
*argument
)
4425 FIXME("doing nothing\n");
4426 return ERROR_SUCCESS
;
4429 static UINT
event_do_action( msi_dialog
*dialog
, const WCHAR
*argument
)
4431 ACTION_PerformAction( dialog
->package
, argument
, SCRIPT_NONE
);
4432 return ERROR_SUCCESS
;
4435 static UINT
event_add_local( msi_dialog
*dialog
, const WCHAR
*argument
)
4437 MSIFEATURE
*feature
;
4439 LIST_FOR_EACH_ENTRY( feature
, &dialog
->package
->features
, MSIFEATURE
, entry
)
4441 if (!strcmpW( argument
, feature
->Feature
) || !strcmpW( argument
, szAll
))
4443 if (feature
->ActionRequest
!= INSTALLSTATE_LOCAL
)
4444 msi_set_property( dialog
->package
->db
, szPreselected
, szOne
, -1 );
4445 MSI_SetFeatureStateW( dialog
->package
, feature
->Feature
, INSTALLSTATE_LOCAL
);
4448 return ERROR_SUCCESS
;
4451 static UINT
event_remove( msi_dialog
*dialog
, const WCHAR
*argument
)
4453 MSIFEATURE
*feature
;
4455 LIST_FOR_EACH_ENTRY( feature
, &dialog
->package
->features
, MSIFEATURE
, entry
)
4457 if (!strcmpW( argument
, feature
->Feature
) || !strcmpW( argument
, szAll
))
4459 if (feature
->ActionRequest
!= INSTALLSTATE_ABSENT
)
4460 msi_set_property( dialog
->package
->db
, szPreselected
, szOne
, -1 );
4461 MSI_SetFeatureStateW( dialog
->package
, feature
->Feature
, INSTALLSTATE_ABSENT
);
4464 return ERROR_SUCCESS
;
4467 static UINT
event_add_source( msi_dialog
*dialog
, const WCHAR
*argument
)
4469 MSIFEATURE
*feature
;
4471 LIST_FOR_EACH_ENTRY( feature
, &dialog
->package
->features
, MSIFEATURE
, entry
)
4473 if (!strcmpW( argument
, feature
->Feature
) || !strcmpW( argument
, szAll
))
4475 if (feature
->ActionRequest
!= INSTALLSTATE_SOURCE
)
4476 msi_set_property( dialog
->package
->db
, szPreselected
, szOne
, -1 );
4477 MSI_SetFeatureStateW( dialog
->package
, feature
->Feature
, INSTALLSTATE_SOURCE
);
4480 return ERROR_SUCCESS
;
4483 void msi_event_fire( MSIPACKAGE
*package
, const WCHAR
*event
, MSIRECORD
*rec
)
4485 struct subscriber
*sub
;
4487 TRACE("firing event %s\n", debugstr_w(event
));
4489 LIST_FOR_EACH_ENTRY( sub
, &package
->subscriptions
, struct subscriber
, entry
)
4491 if (strcmpiW( sub
->event
, event
)) continue;
4492 dialog_handle_event( sub
->dialog
, sub
->control
, sub
->attribute
, rec
);
4496 static UINT
event_set_target_path( msi_dialog
*dialog
, const WCHAR
*argument
)
4498 WCHAR
*path
= msi_dup_property( dialog
->package
->db
, argument
);
4499 MSIRECORD
*rec
= MSI_CreateRecord( 1 );
4500 UINT r
= ERROR_SUCCESS
;
4502 MSI_RecordSetStringW( rec
, 1, path
);
4503 msi_event_fire( dialog
->package
, szSelectionPath
, rec
);
4506 /* failure to set the path halts the executing of control events */
4507 r
= MSI_SetTargetPathW( dialog
->package
, argument
, path
);
4510 msi_free( &rec
->hdr
);
4514 static UINT
event_reset( msi_dialog
*dialog
, const WCHAR
*argument
)
4516 msi_dialog_reset( dialog
);
4517 return ERROR_SUCCESS
;
4520 /* Return ERROR_SUCCESS if dialog is process and ERROR_FUNCTION_FAILED
4521 * if the given parameter is not a dialog box
4523 UINT
ACTION_DialogBox( MSIPACKAGE
*package
, const WCHAR
*dialog
)
4527 if (package
->next_dialog
) ERR("Already got next dialog... ignoring it\n");
4528 package
->next_dialog
= NULL
;
4530 /* Dialogs are chained by filling in the next_dialog member
4531 * of the package structure, then terminating the current dialog.
4532 * The code below sees the next_dialog member set, and runs the
4534 * We fall out of the loop below if we come across a modeless
4535 * dialog, as it returns ERROR_IO_PENDING when we try to run
4538 r
= event_do_dialog( package
, dialog
, NULL
, TRUE
);
4539 while (r
== ERROR_SUCCESS
&& package
->next_dialog
)
4541 WCHAR
*name
= package
->next_dialog
;
4543 package
->next_dialog
= NULL
;
4544 r
= event_do_dialog( package
, name
, NULL
, TRUE
);
4547 if (r
== ERROR_IO_PENDING
) r
= ERROR_SUCCESS
;
4551 static UINT
event_set_install_level( msi_dialog
*dialog
, const WCHAR
*argument
)
4553 int level
= atolW( argument
);
4555 TRACE("setting install level to %d\n", level
);
4556 return MSI_SetInstallLevel( dialog
->package
, level
);
4559 static UINT
event_directory_list_up( msi_dialog
*dialog
, const WCHAR
*argument
)
4561 return msi_dialog_directorylist_up( dialog
);
4564 static UINT
event_reinstall_mode( msi_dialog
*dialog
, const WCHAR
*argument
)
4566 return msi_set_property( dialog
->package
->db
, szReinstallMode
, argument
, -1 );
4569 static UINT
event_reinstall( msi_dialog
*dialog
, const WCHAR
*argument
)
4571 return msi_set_property( dialog
->package
->db
, szReinstall
, argument
, -1 );
4574 static UINT
event_validate_product_id( msi_dialog
*dialog
, const WCHAR
*argument
)
4576 return msi_validate_product_id( dialog
->package
);
4579 static const WCHAR end_dialogW
[] = {'E','n','d','D','i','a','l','o','g',0};
4580 static const WCHAR new_dialogW
[] = {'N','e','w','D','i','a','l','o','g',0};
4581 static const WCHAR spawn_dialogW
[] = {'S','p','a','w','n','D','i','a','l','o','g',0};
4582 static const WCHAR spawn_wait_dialogW
[] = {'S','p','a','w','n','W','a','i','t','D','i','a','l','o','g',0};
4583 static const WCHAR do_actionW
[] = {'D','o','A','c','t','i','o','n',0};
4584 static const WCHAR add_localW
[] = {'A','d','d','L','o','c','a','l',0};
4585 static const WCHAR removeW
[] = {'R','e','m','o','v','e',0};
4586 static const WCHAR add_sourceW
[] = {'A','d','d','S','o','u','r','c','e',0};
4587 static const WCHAR set_target_pathW
[] = {'S','e','t','T','a','r','g','e','t','P','a','t','h',0};
4588 static const WCHAR resetW
[] = {'R','e','s','e','t',0};
4589 static const WCHAR set_install_levelW
[] = {'S','e','t','I','n','s','t','a','l','l','L','e','v','e','l',0};
4590 static const WCHAR directory_list_upW
[] = {'D','i','r','e','c','t','o','r','y','L','i','s','t','U','p',0};
4591 static const WCHAR selection_browseW
[] = {'S','e','l','e','c','t','i','o','n','B','r','o','w','s','e',0};
4592 static const WCHAR reinstall_modeW
[] = {'R','e','i','n','s','t','a','l','l','M','o','d','e',0};
4593 static const WCHAR reinstallW
[] = {'R','e','i','n','s','t','a','l','l',0};
4594 static const WCHAR validate_product_idW
[] = {'V','a','l','i','d','a','t','e','P','r','o','d','u','c','t','I','D',0};
4596 static const struct control_event control_events
[] =
4598 { end_dialogW
, event_end_dialog
},
4599 { new_dialogW
, event_new_dialog
},
4600 { spawn_dialogW
, event_spawn_dialog
},
4601 { spawn_wait_dialogW
, event_spawn_wait_dialog
},
4602 { do_actionW
, event_do_action
},
4603 { add_localW
, event_add_local
},
4604 { removeW
, event_remove
},
4605 { add_sourceW
, event_add_source
},
4606 { set_target_pathW
, event_set_target_path
},
4607 { resetW
, event_reset
},
4608 { set_install_levelW
, event_set_install_level
},
4609 { directory_list_upW
, event_directory_list_up
},
4610 { selection_browseW
, event_spawn_dialog
},
4611 { reinstall_modeW
, event_reinstall_mode
},
4612 { reinstallW
, event_reinstall
},
4613 { validate_product_idW
, event_validate_product_id
},
4617 static UINT
dialog_event_handler( msi_dialog
*dialog
, const WCHAR
*event
, const WCHAR
*argument
)
4621 TRACE("handling event %s\n", debugstr_w(event
));
4623 if (!event
) return ERROR_SUCCESS
;
4625 for (i
= 0; control_events
[i
].event
; i
++)
4627 if (!strcmpW( control_events
[i
].event
, event
))
4628 return control_events
[i
].handler( dialog
, argument
);
4630 FIXME("unhandled event %s arg(%s)\n", debugstr_w(event
), debugstr_w(argument
));
4631 return ERROR_SUCCESS
;