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 szHyperLink
[] = {'H','y','p','e','r','L','i','n','k',0};
160 /* dialog sequencing */
162 #define WM_MSI_DIALOG_CREATE (WM_USER+0x100)
163 #define WM_MSI_DIALOG_DESTROY (WM_USER+0x101)
165 #define USER_INSTALLSTATE_ALL 0x1000
167 static DWORD uiThreadId
;
168 static HWND hMsiHiddenWindow
;
170 static LPWSTR
msi_get_window_text( HWND hwnd
)
176 buf
= msi_alloc( sz
*sizeof(WCHAR
) );
179 r
= GetWindowTextW( hwnd
, buf
, sz
);
183 buf
= msi_realloc( buf
, sz
*sizeof(WCHAR
) );
189 static INT
msi_dialog_scale_unit( msi_dialog
*dialog
, INT val
)
191 return MulDiv( val
, dialog
->scale
, 12 );
194 static msi_control
*msi_dialog_find_control( msi_dialog
*dialog
, LPCWSTR name
)
196 msi_control
*control
;
202 LIST_FOR_EACH_ENTRY( control
, &dialog
->controls
, msi_control
, entry
)
203 if( !strcmpW( control
->name
, name
) ) /* FIXME: case sensitive? */
208 static msi_control
*msi_dialog_find_control_by_type( msi_dialog
*dialog
, LPCWSTR type
)
210 msi_control
*control
;
216 LIST_FOR_EACH_ENTRY( control
, &dialog
->controls
, msi_control
, entry
)
217 if( !strcmpW( control
->type
, type
) ) /* FIXME: case sensitive? */
222 static msi_control
*msi_dialog_find_control_by_hwnd( msi_dialog
*dialog
, HWND hwnd
)
224 msi_control
*control
;
228 LIST_FOR_EACH_ENTRY( control
, &dialog
->controls
, msi_control
, entry
)
229 if( hwnd
== control
->hwnd
)
234 static LPWSTR
msi_get_deformatted_field( MSIPACKAGE
*package
, MSIRECORD
*rec
, int field
)
236 LPCWSTR str
= MSI_RecordGetString( rec
, field
);
240 deformat_string( package
, str
, &ret
);
244 static LPWSTR
msi_dialog_dup_property( msi_dialog
*dialog
, LPCWSTR property
, BOOL indirect
)
252 prop
= msi_dup_property( dialog
->package
->db
, property
);
255 prop
= strdupW( property
);
261 * msi_dialog_get_style
263 * Extract the {\style} string from the front of the text to display and
264 * update the pointer. Only the last style in a list is applied.
266 static LPWSTR
msi_dialog_get_style( LPCWSTR p
, LPCWSTR
*rest
)
277 while ((first
= strchrW( p
, '{' )) && (q
= strchrW( first
+ 1, '}' )))
280 if( *p
!= '\\' && *p
!= '&' )
283 /* little bit of sanity checking to stop us getting confused with RTF */
284 for( i
=++p
; i
<q
; i
++ )
285 if( *i
== '}' || *i
== '\\' )
295 ret
= msi_alloc( len
*sizeof(WCHAR
) );
298 memcpy( ret
, p
, len
*sizeof(WCHAR
) );
303 static UINT
msi_dialog_add_font( MSIRECORD
*rec
, LPVOID param
)
305 msi_dialog
*dialog
= param
;
312 /* create a font and add it to the list */
313 name
= MSI_RecordGetString( rec
, 1 );
314 font
= msi_alloc( FIELD_OFFSET( msi_font
, name
[strlenW( name
) + 1] ));
315 strcpyW( font
->name
, name
);
316 list_add_head( &dialog
->fonts
, &font
->entry
);
318 font
->color
= MSI_RecordGetInteger( rec
, 4 );
320 memset( &lf
, 0, sizeof lf
);
321 face
= MSI_RecordGetString( rec
, 2 );
322 lf
.lfHeight
= MSI_RecordGetInteger( rec
, 3 );
323 style
= MSI_RecordGetInteger( rec
, 5 );
324 if( style
& msidbTextStyleStyleBitsBold
)
325 lf
.lfWeight
= FW_BOLD
;
326 if( style
& msidbTextStyleStyleBitsItalic
)
328 if( style
& msidbTextStyleStyleBitsUnderline
)
329 lf
.lfUnderline
= TRUE
;
330 if( style
& msidbTextStyleStyleBitsStrike
)
331 lf
.lfStrikeOut
= TRUE
;
332 lstrcpynW( lf
.lfFaceName
, face
, LF_FACESIZE
);
334 /* adjust the height */
335 hdc
= GetDC( dialog
->hwnd
);
338 lf
.lfHeight
= -MulDiv(lf
.lfHeight
, GetDeviceCaps(hdc
, LOGPIXELSY
), 72);
339 ReleaseDC( dialog
->hwnd
, hdc
);
342 font
->hfont
= CreateFontIndirectW( &lf
);
344 TRACE("Adding font style %s\n", debugstr_w(font
->name
) );
346 return ERROR_SUCCESS
;
349 static msi_font
*msi_dialog_find_font( msi_dialog
*dialog
, LPCWSTR name
)
351 msi_font
*font
= NULL
;
353 LIST_FOR_EACH_ENTRY( font
, &dialog
->fonts
, msi_font
, entry
)
354 if( !strcmpW( font
->name
, name
) ) /* FIXME: case sensitive? */
360 static UINT
msi_dialog_set_font( msi_dialog
*dialog
, HWND hwnd
, LPCWSTR name
)
364 font
= msi_dialog_find_font( dialog
, name
);
366 SendMessageW( hwnd
, WM_SETFONT
, (WPARAM
) font
->hfont
, TRUE
);
368 ERR("No font entry for %s\n", debugstr_w(name
));
369 return ERROR_SUCCESS
;
372 static UINT
msi_dialog_build_font_list( msi_dialog
*dialog
)
374 static const WCHAR query
[] = {
375 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
376 '`','T','e','x','t','S','t','y','l','e','`',0};
380 TRACE("dialog %p\n", dialog
);
382 r
= MSI_OpenQuery( dialog
->package
->db
, &view
, query
);
383 if( r
!= ERROR_SUCCESS
)
386 r
= MSI_IterateRecords( view
, NULL
, msi_dialog_add_font
, dialog
);
387 msiobj_release( &view
->hdr
);
391 static void msi_destroy_control( msi_control
*t
)
393 list_remove( &t
->entry
);
394 /* leave dialog->hwnd - destroying parent destroys child windows */
395 msi_free( t
->property
);
396 msi_free( t
->value
);
398 DeleteObject( t
->hBitmap
);
400 DestroyIcon( t
->hIcon
);
401 msi_free( t
->tabnext
);
404 FreeLibrary( t
->hDll
);
408 static msi_control
*dialog_create_window( msi_dialog
*dialog
, MSIRECORD
*rec
, DWORD exstyle
,
409 const WCHAR
*szCls
, const WCHAR
*name
, const WCHAR
*text
,
410 DWORD style
, HWND parent
)
412 DWORD x
, y
, width
, height
;
413 LPWSTR font
= NULL
, title_font
= NULL
;
414 LPCWSTR title
= NULL
;
415 msi_control
*control
;
419 control
= msi_alloc( FIELD_OFFSET( msi_control
, name
[strlenW( name
) + 1] ));
423 strcpyW( control
->name
, name
);
424 list_add_tail( &dialog
->controls
, &control
->entry
);
425 control
->handler
= NULL
;
426 control
->update
= NULL
;
427 control
->property
= NULL
;
428 control
->value
= NULL
;
429 control
->hBitmap
= NULL
;
430 control
->hIcon
= NULL
;
431 control
->hDll
= NULL
;
432 control
->tabnext
= strdupW( MSI_RecordGetString( rec
, 11) );
433 control
->type
= strdupW( MSI_RecordGetString( rec
, 3 ) );
434 control
->progress_current
= 0;
435 control
->progress_max
= 100;
436 control
->progress_backwards
= FALSE
;
438 x
= MSI_RecordGetInteger( rec
, 4 );
439 y
= MSI_RecordGetInteger( rec
, 5 );
440 width
= MSI_RecordGetInteger( rec
, 6 );
441 height
= MSI_RecordGetInteger( rec
, 7 );
443 x
= msi_dialog_scale_unit( dialog
, x
);
444 y
= msi_dialog_scale_unit( dialog
, y
);
445 width
= msi_dialog_scale_unit( dialog
, width
);
446 height
= msi_dialog_scale_unit( dialog
, height
);
450 deformat_string( dialog
->package
, text
, &title_font
);
451 font
= msi_dialog_get_style( title_font
, &title
);
454 control
->hwnd
= CreateWindowExW( exstyle
, szCls
, title
, style
,
455 x
, y
, width
, height
, parent
, NULL
, NULL
, NULL
);
457 TRACE("Dialog %s control %s hwnd %p\n",
458 debugstr_w(dialog
->name
), debugstr_w(text
), control
->hwnd
);
460 msi_dialog_set_font( dialog
, control
->hwnd
,
461 font
? font
: dialog
->default_font
);
463 msi_free( title_font
);
469 static LPWSTR
msi_dialog_get_uitext( msi_dialog
*dialog
, LPCWSTR key
)
474 static const WCHAR query
[] = {
475 's','e','l','e','c','t',' ','*',' ',
476 'f','r','o','m',' ','`','U','I','T','e','x','t','`',' ',
477 'w','h','e','r','e',' ','`','K','e','y','`',' ','=',' ','\'','%','s','\'',0
480 rec
= MSI_QueryGetRecord( dialog
->package
->db
, query
, key
);
481 if (!rec
) return NULL
;
482 text
= strdupW( MSI_RecordGetString( rec
, 2 ) );
483 msiobj_release( &rec
->hdr
);
487 static MSIRECORD
*msi_get_binary_record( MSIDATABASE
*db
, LPCWSTR name
)
489 static const WCHAR query
[] = {
490 's','e','l','e','c','t',' ','*',' ',
491 'f','r','o','m',' ','B','i','n','a','r','y',' ',
492 'w','h','e','r','e',' ',
493 '`','N','a','m','e','`',' ','=',' ','\'','%','s','\'',0
496 return MSI_QueryGetRecord( db
, query
, name
);
499 static LPWSTR
msi_create_tmp_path(void)
505 r
= GetTempPathW( MAX_PATH
, tmp
);
508 len
= lstrlenW( tmp
) + 20;
509 path
= msi_alloc( len
* sizeof (WCHAR
) );
512 r
= GetTempFileNameW( tmp
, szMsi
, 0, path
);
522 static HANDLE
msi_load_image( MSIDATABASE
*db
, LPCWSTR name
, UINT type
,
523 UINT cx
, UINT cy
, UINT flags
)
525 MSIRECORD
*rec
= NULL
;
526 HANDLE himage
= NULL
;
530 TRACE("%p %s %u %u %08x\n", db
, debugstr_w(name
), cx
, cy
, flags
);
532 tmp
= msi_create_tmp_path();
536 rec
= msi_get_binary_record( db
, name
);
539 r
= MSI_RecordStreamToFile( rec
, 2, tmp
);
540 if( r
== ERROR_SUCCESS
)
542 himage
= LoadImageW( 0, tmp
, type
, cx
, cy
, flags
);
544 msiobj_release( &rec
->hdr
);
552 static HICON
msi_load_icon( MSIDATABASE
*db
, LPCWSTR text
, UINT attributes
)
554 DWORD cx
= 0, cy
= 0, flags
;
556 flags
= LR_LOADFROMFILE
| LR_DEFAULTSIZE
;
557 if( attributes
& msidbControlAttributesFixedSize
)
559 flags
&= ~LR_DEFAULTSIZE
;
560 if( attributes
& msidbControlAttributesIconSize16
)
565 if( attributes
& msidbControlAttributesIconSize32
)
570 /* msidbControlAttributesIconSize48 handled by above logic */
572 return msi_load_image( db
, text
, IMAGE_ICON
, cx
, cy
, flags
);
575 static void msi_dialog_update_controls( msi_dialog
*dialog
, LPCWSTR property
)
577 msi_control
*control
;
579 LIST_FOR_EACH_ENTRY( control
, &dialog
->controls
, msi_control
, entry
)
581 if ( control
->property
&& !strcmpW( control
->property
, property
) && control
->update
)
582 control
->update( dialog
, control
);
586 static void msi_dialog_set_property( MSIPACKAGE
*package
, LPCWSTR property
, LPCWSTR value
)
588 UINT r
= msi_set_property( package
->db
, property
, value
, -1 );
589 if (r
== ERROR_SUCCESS
&& !strcmpW( property
, szSourceDir
))
590 msi_reset_folders( package
, TRUE
);
593 static MSIFEATURE
*msi_seltree_feature_from_item( HWND hwnd
, HTREEITEM hItem
)
597 /* get the feature from the item */
598 memset( &tvi
, 0, sizeof tvi
);
600 tvi
.mask
= TVIF_PARAM
| TVIF_HANDLE
;
601 SendMessageW( hwnd
, TVM_GETITEMW
, 0, (LPARAM
)&tvi
);
602 return (MSIFEATURE
*)tvi
.lParam
;
605 struct msi_selection_tree_info
613 static MSIFEATURE
*msi_seltree_get_selected_feature( msi_control
*control
)
615 struct msi_selection_tree_info
*info
= GetPropW( control
->hwnd
, szButtonData
);
616 return msi_seltree_feature_from_item( control
->hwnd
, info
->selected
);
619 static void dialog_handle_event( msi_dialog
*dialog
, const WCHAR
*control
,
620 const WCHAR
*attribute
, MSIRECORD
*rec
)
624 ctrl
= msi_dialog_find_control( dialog
, control
);
627 if( !strcmpW( attribute
, szText
) )
629 const WCHAR
*font_text
, *text
= NULL
;
630 WCHAR
*font
, *text_fmt
= NULL
;
632 font_text
= MSI_RecordGetString( rec
, 1 );
633 font
= msi_dialog_get_style( font_text
, &text
);
634 deformat_string( dialog
->package
, text
, &text_fmt
);
635 if (text_fmt
) text
= text_fmt
;
638 SetWindowTextW( ctrl
->hwnd
, text
);
641 msi_free( text_fmt
);
642 msi_dialog_check_messages( NULL
);
644 else if( !strcmpW( attribute
, szProgress
) )
646 DWORD func
, val1
, val2
, units
;
648 func
= MSI_RecordGetInteger( rec
, 1 );
649 val1
= MSI_RecordGetInteger( rec
, 2 );
650 val2
= MSI_RecordGetInteger( rec
, 3 );
652 TRACE("progress: func %u val1 %u val2 %u\n", func
, val1
, val2
);
658 SendMessageW( ctrl
->hwnd
, PBM_SETRANGE
, 0, MAKELPARAM(0,100) );
661 ctrl
->progress_max
= units
? units
: 100;
662 ctrl
->progress_current
= units
;
663 ctrl
->progress_backwards
= TRUE
;
664 SendMessageW( ctrl
->hwnd
, PBM_SETPOS
, 100, 0 );
668 ctrl
->progress_max
= units
? units
: 100;
669 ctrl
->progress_current
= 0;
670 ctrl
->progress_backwards
= FALSE
;
671 SendMessageW( ctrl
->hwnd
, PBM_SETPOS
, 0, 0 );
674 case 1: /* action data increment */
675 if (val2
) dialog
->package
->action_progress_increment
= val1
;
676 else dialog
->package
->action_progress_increment
= 0;
679 if (ctrl
->progress_backwards
)
681 if (units
>= ctrl
->progress_current
) ctrl
->progress_current
-= units
;
682 else ctrl
->progress_current
= 0;
686 if (ctrl
->progress_current
+ units
< ctrl
->progress_max
) ctrl
->progress_current
+= units
;
687 else ctrl
->progress_current
= ctrl
->progress_max
;
689 SendMessageW( ctrl
->hwnd
, PBM_SETPOS
, MulDiv(100, ctrl
->progress_current
, ctrl
->progress_max
), 0 );
692 ctrl
->progress_max
+= units
;
695 FIXME("Unknown progress message %u\n", func
);
699 else if ( !strcmpW( attribute
, szProperty
) )
701 MSIFEATURE
*feature
= msi_seltree_get_selected_feature( ctrl
);
702 if (feature
) msi_dialog_set_property( dialog
->package
, ctrl
->property
, feature
->Directory
);
704 else if ( !strcmpW( attribute
, szSelectionPath
) )
706 BOOL indirect
= ctrl
->attributes
& msidbControlAttributesIndirect
;
707 LPWSTR path
= msi_dialog_dup_property( dialog
, ctrl
->property
, indirect
);
709 SetWindowTextW( ctrl
->hwnd
, path
);
714 FIXME("Attribute %s not being set\n", debugstr_w(attribute
));
719 static void event_subscribe( msi_dialog
*dialog
, const WCHAR
*event
, const WCHAR
*control
, const WCHAR
*attribute
)
721 struct subscriber
*sub
;
723 TRACE("event %s control %s attribute %s\n", debugstr_w(event
), debugstr_w(control
), debugstr_w(attribute
));
725 LIST_FOR_EACH_ENTRY( sub
, &dialog
->package
->subscriptions
, struct subscriber
, entry
)
727 if (!strcmpiW( sub
->event
, event
) &&
728 !strcmpiW( sub
->control
, control
) &&
729 !strcmpiW( sub
->attribute
, attribute
))
731 TRACE("already subscribed\n");
735 if (!(sub
= msi_alloc( sizeof(*sub
) ))) return;
736 sub
->dialog
= dialog
;
737 sub
->event
= strdupW( event
);
738 sub
->control
= strdupW( control
);
739 sub
->attribute
= strdupW( attribute
);
740 list_add_tail( &dialog
->package
->subscriptions
, &sub
->entry
);
743 struct dialog_control
746 const WCHAR
*control
;
749 static UINT
map_event( MSIRECORD
*row
, void *param
)
751 struct dialog_control
*dc
= param
;
752 const WCHAR
*event
= MSI_RecordGetString( row
, 3 );
753 const WCHAR
*attribute
= MSI_RecordGetString( row
, 4 );
755 event_subscribe( dc
->dialog
, event
, dc
->control
, attribute
);
756 return ERROR_SUCCESS
;
759 static void dialog_map_events( msi_dialog
*dialog
, const WCHAR
*control
)
761 static const WCHAR queryW
[] =
762 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
763 '`','E','v','e','n','t','M','a','p','p','i','n','g','`',' ',
764 'W','H','E','R','E',' ','`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',' ',
765 'A','N','D',' ','`','C','o','n','t','r','o','l','_','`',' ','=',' ','\'','%','s','\'',0};
767 struct dialog_control dialog_control
=
773 if (!MSI_OpenQuery( dialog
->package
->db
, &view
, queryW
, dialog
->name
, control
))
775 MSI_IterateRecords( view
, NULL
, map_event
, &dialog_control
);
776 msiobj_release( &view
->hdr
);
780 /* everything except radio buttons */
781 static msi_control
*msi_dialog_add_control( msi_dialog
*dialog
,
782 MSIRECORD
*rec
, LPCWSTR szCls
, DWORD style
)
785 const WCHAR
*text
= NULL
, *name
, *control_type
;
788 name
= MSI_RecordGetString( rec
, 2 );
789 control_type
= MSI_RecordGetString( rec
, 3 );
790 attributes
= MSI_RecordGetInteger( rec
, 8 );
791 if (strcmpW( control_type
, szScrollableText
)) text
= MSI_RecordGetString( rec
, 10 );
793 TRACE("%s, %s, %08x, %s, %08x\n", debugstr_w(szCls
), debugstr_w(name
),
794 attributes
, debugstr_w(text
), style
);
796 if( attributes
& msidbControlAttributesVisible
)
798 if( ~attributes
& msidbControlAttributesEnabled
)
799 style
|= WS_DISABLED
;
800 if( attributes
& msidbControlAttributesSunken
)
801 exstyle
|= WS_EX_CLIENTEDGE
;
803 dialog_map_events( dialog
, name
);
805 return dialog_create_window( dialog
, rec
, exstyle
, szCls
, name
, text
, style
, dialog
->hwnd
);
816 * we don't erase our own background,
817 * so we have to make sure that the parent window redraws first
819 static void msi_text_on_settext( HWND hWnd
)
824 hParent
= GetParent( hWnd
);
825 GetWindowRect( hWnd
, &rc
);
826 MapWindowPoints( NULL
, hParent
, (LPPOINT
) &rc
, 2 );
827 InvalidateRect( hParent
, &rc
, TRUE
);
830 static LRESULT WINAPI
831 MSIText_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
833 struct msi_text_info
*info
;
836 TRACE("%p %04x %08lx %08lx\n", hWnd
, msg
, wParam
, lParam
);
838 info
= GetPropW(hWnd
, szButtonData
);
840 if( msg
== WM_CTLCOLORSTATIC
&&
841 ( info
->attributes
& msidbControlAttributesTransparent
) )
843 SetBkMode( (HDC
)wParam
, TRANSPARENT
);
844 return (LRESULT
) GetStockObject(NULL_BRUSH
);
847 r
= CallWindowProcW(info
->oldproc
, hWnd
, msg
, wParam
, lParam
);
849 SetTextColor( (HDC
)wParam
, info
->font
->color
);
854 msi_text_on_settext( hWnd
);
858 RemovePropW( hWnd
, szButtonData
);
865 static UINT
msi_dialog_text_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
867 msi_control
*control
;
868 struct msi_text_info
*info
;
869 LPCWSTR text
, ptr
, prop
, control_name
;
872 TRACE("%p %p\n", dialog
, rec
);
874 control
= msi_dialog_add_control( dialog
, rec
, szStatic
, SS_LEFT
| WS_GROUP
);
876 return ERROR_FUNCTION_FAILED
;
878 info
= msi_alloc( sizeof *info
);
880 return ERROR_SUCCESS
;
882 control_name
= MSI_RecordGetString( rec
, 2 );
883 control
->attributes
= MSI_RecordGetInteger( rec
, 8 );
884 prop
= MSI_RecordGetString( rec
, 9 );
885 control
->property
= msi_dialog_dup_property( dialog
, prop
, FALSE
);
887 text
= MSI_RecordGetString( rec
, 10 );
888 font_name
= msi_dialog_get_style( text
, &ptr
);
889 info
->font
= ( font_name
) ? msi_dialog_find_font( dialog
, font_name
) : NULL
;
890 msi_free( font_name
);
892 info
->attributes
= MSI_RecordGetInteger( rec
, 8 );
893 if( info
->attributes
& msidbControlAttributesTransparent
)
894 SetWindowLongPtrW( control
->hwnd
, GWL_EXSTYLE
, WS_EX_TRANSPARENT
);
896 info
->oldproc
= (WNDPROC
) SetWindowLongPtrW( control
->hwnd
, GWLP_WNDPROC
,
897 (LONG_PTR
)MSIText_WndProc
);
898 SetPropW( control
->hwnd
, szButtonData
, info
);
900 event_subscribe( dialog
, szSelectionPath
, control_name
, szSelectionPath
);
901 return ERROR_SUCCESS
;
904 /* strip any leading text style label from text field */
905 static WCHAR
*msi_get_binary_name( MSIPACKAGE
*package
, MSIRECORD
*rec
)
909 text
= msi_get_deformatted_field( package
, rec
, 10 );
914 while (*p
&& *p
!= '{') p
++;
915 if (!*p
++) return text
;
917 while (*p
&& *p
!= '}') p
++;
918 if (!*p
++) return text
;
925 static UINT
msi_dialog_set_property_event( msi_dialog
*dialog
, LPCWSTR event
, LPCWSTR arg
)
927 static const WCHAR szNullArg
[] = {'{','}',0};
928 LPWSTR p
, prop
, arg_fmt
= NULL
;
931 len
= strlenW( event
);
932 prop
= msi_alloc( len
* sizeof(WCHAR
) );
933 strcpyW( prop
, &event
[1] );
934 p
= strchrW( prop
, ']' );
935 if (p
&& (p
[1] == 0 || p
[1] == ' '))
938 if (strcmpW( szNullArg
, arg
))
939 deformat_string( dialog
->package
, arg
, &arg_fmt
);
940 msi_dialog_set_property( dialog
->package
, prop
, arg_fmt
);
941 msi_dialog_update_controls( dialog
, prop
);
944 else ERR("Badly formatted property string - what happens?\n");
946 return ERROR_SUCCESS
;
949 static UINT
msi_dialog_send_event( msi_dialog
*dialog
, LPCWSTR event
, LPCWSTR arg
)
951 LPWSTR event_fmt
= NULL
, arg_fmt
= NULL
;
953 TRACE("Sending control event %s %s\n", debugstr_w(event
), debugstr_w(arg
));
955 deformat_string( dialog
->package
, event
, &event_fmt
);
956 deformat_string( dialog
->package
, arg
, &arg_fmt
);
958 dialog
->event_handler( dialog
, event_fmt
, arg_fmt
);
960 msi_free( event_fmt
);
963 return ERROR_SUCCESS
;
966 static UINT
msi_dialog_control_event( MSIRECORD
*rec
, LPVOID param
)
968 msi_dialog
*dialog
= param
;
969 LPCWSTR condition
, event
, arg
;
972 condition
= MSI_RecordGetString( rec
, 5 );
973 r
= MSI_EvaluateConditionW( dialog
->package
, condition
);
974 if (r
== MSICONDITION_TRUE
|| r
== MSICONDITION_NONE
)
976 event
= MSI_RecordGetString( rec
, 3 );
977 arg
= MSI_RecordGetString( rec
, 4 );
979 msi_dialog_set_property_event( dialog
, event
, arg
);
981 msi_dialog_send_event( dialog
, event
, arg
);
983 return ERROR_SUCCESS
;
986 static UINT
msi_dialog_button_handler( msi_dialog
*dialog
, msi_control
*control
, WPARAM param
)
988 static const WCHAR query
[] = {
989 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
990 'C','o','n','t','r','o','l','E','v','e','n','t',' ','W','H','E','R','E',' ',
991 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',' ','A','N','D',' ',
992 '`','C','o','n','t','r','o','l','_','`',' ','=',' ','\'','%','s','\'',' ',
993 'O','R','D','E','R',' ','B','Y',' ','`','O','r','d','e','r','i','n','g','`',0};
997 if (HIWORD(param
) != BN_CLICKED
)
998 return ERROR_SUCCESS
;
1000 r
= MSI_OpenQuery( dialog
->package
->db
, &view
, query
, dialog
->name
, control
->name
);
1001 if (r
!= ERROR_SUCCESS
)
1003 ERR("query failed\n");
1004 return ERROR_SUCCESS
;
1006 r
= MSI_IterateRecords( view
, 0, msi_dialog_control_event
, dialog
);
1007 msiobj_release( &view
->hdr
);
1011 static UINT
msi_dialog_button_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1013 msi_control
*control
;
1014 UINT attributes
, style
;
1016 TRACE("%p %p\n", dialog
, rec
);
1019 attributes
= MSI_RecordGetInteger( rec
, 8 );
1020 if( attributes
& msidbControlAttributesIcon
)
1023 control
= msi_dialog_add_control( dialog
, rec
, szButton
, style
);
1025 return ERROR_FUNCTION_FAILED
;
1027 control
->handler
= msi_dialog_button_handler
;
1029 if (attributes
& msidbControlAttributesIcon
)
1032 LPWSTR name
= msi_get_binary_name( dialog
->package
, rec
);
1033 control
->hIcon
= msi_load_icon( dialog
->package
->db
, name
, attributes
);
1036 SendMessageW( control
->hwnd
, BM_SETIMAGE
, IMAGE_ICON
, (LPARAM
) control
->hIcon
);
1039 ERR("Failed to load icon %s\n", debugstr_w(name
));
1043 return ERROR_SUCCESS
;
1046 static LPWSTR
msi_get_checkbox_value( msi_dialog
*dialog
, LPCWSTR prop
)
1048 static const WCHAR query
[] = {
1049 'S','E','L','E','C','T',' ','*',' ',
1050 'F','R','O','M',' ','`','C','h','e','c','k','B','o','x','`',' ',
1051 'W','H','E','R','E',' ',
1052 '`','P','r','o','p','e','r','t','y','`',' ','=',' ',
1055 MSIRECORD
*rec
= NULL
;
1058 /* find if there is a value associated with the checkbox */
1059 rec
= MSI_QueryGetRecord( dialog
->package
->db
, query
, prop
);
1063 ret
= msi_get_deformatted_field( dialog
->package
, rec
, 2 );
1064 if( ret
&& !ret
[0] )
1069 msiobj_release( &rec
->hdr
);
1073 ret
= msi_dup_property( dialog
->package
->db
, prop
);
1074 if( ret
&& !ret
[0] )
1083 static UINT
msi_dialog_get_checkbox_state( msi_dialog
*dialog
, msi_control
*control
)
1085 WCHAR state
[2] = {0};
1088 msi_get_property( dialog
->package
->db
, control
->property
, state
, &sz
);
1089 return state
[0] ? 1 : 0;
1092 static void msi_dialog_set_checkbox_state( msi_dialog
*dialog
, msi_control
*control
, UINT state
)
1094 static const WCHAR szState
[] = {'1',0};
1097 /* if uncheck then the property is set to NULL */
1100 msi_dialog_set_property( dialog
->package
, control
->property
, NULL
);
1104 /* check for a custom state */
1105 if (control
->value
&& control
->value
[0])
1106 val
= control
->value
;
1110 msi_dialog_set_property( dialog
->package
, control
->property
, val
);
1113 static void msi_dialog_checkbox_sync_state( msi_dialog
*dialog
, msi_control
*control
)
1115 UINT state
= msi_dialog_get_checkbox_state( dialog
, control
);
1116 SendMessageW( control
->hwnd
, BM_SETCHECK
, state
? BST_CHECKED
: BST_UNCHECKED
, 0 );
1119 static UINT
msi_dialog_checkbox_handler( msi_dialog
*dialog
, msi_control
*control
, WPARAM param
)
1123 if (HIWORD(param
) != BN_CLICKED
)
1124 return ERROR_SUCCESS
;
1126 TRACE("clicked checkbox %s, set %s\n", debugstr_w(control
->name
), debugstr_w(control
->property
));
1128 state
= msi_dialog_get_checkbox_state( dialog
, control
);
1129 state
= state
? 0 : 1;
1130 msi_dialog_set_checkbox_state( dialog
, control
, state
);
1131 msi_dialog_checkbox_sync_state( dialog
, control
);
1133 return msi_dialog_button_handler( dialog
, control
, param
);
1136 static UINT
msi_dialog_checkbox_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1138 msi_control
*control
;
1141 TRACE("%p %p\n", dialog
, rec
);
1143 control
= msi_dialog_add_control( dialog
, rec
, szButton
, BS_CHECKBOX
| BS_MULTILINE
| WS_TABSTOP
);
1144 control
->handler
= msi_dialog_checkbox_handler
;
1145 control
->update
= msi_dialog_checkbox_sync_state
;
1146 prop
= MSI_RecordGetString( rec
, 9 );
1149 control
->property
= strdupW( prop
);
1150 control
->value
= msi_get_checkbox_value( dialog
, prop
);
1151 TRACE("control %s value %s\n", debugstr_w(control
->property
), debugstr_w(control
->value
));
1153 msi_dialog_checkbox_sync_state( dialog
, control
);
1154 return ERROR_SUCCESS
;
1157 static UINT
msi_dialog_line_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1161 DWORD style
, exstyle
= 0;
1162 DWORD x
, y
, width
, height
;
1163 msi_control
*control
;
1165 TRACE("%p %p\n", dialog
, rec
);
1167 style
= WS_CHILD
| SS_ETCHEDHORZ
| SS_SUNKEN
;
1169 name
= MSI_RecordGetString( rec
, 2 );
1170 attributes
= MSI_RecordGetInteger( rec
, 8 );
1172 if( attributes
& msidbControlAttributesVisible
)
1173 style
|= WS_VISIBLE
;
1174 if( ~attributes
& msidbControlAttributesEnabled
)
1175 style
|= WS_DISABLED
;
1176 if( attributes
& msidbControlAttributesSunken
)
1177 exstyle
|= WS_EX_CLIENTEDGE
;
1179 dialog_map_events( dialog
, name
);
1181 control
= msi_alloc( FIELD_OFFSET(msi_control
, name
[strlenW( name
) + 1] ));
1183 return ERROR_OUTOFMEMORY
;
1185 strcpyW( control
->name
, name
);
1186 list_add_head( &dialog
->controls
, &control
->entry
);
1187 control
->handler
= NULL
;
1188 control
->property
= NULL
;
1189 control
->value
= NULL
;
1190 control
->hBitmap
= NULL
;
1191 control
->hIcon
= NULL
;
1192 control
->hDll
= NULL
;
1193 control
->tabnext
= strdupW( MSI_RecordGetString( rec
, 11) );
1194 control
->type
= strdupW( MSI_RecordGetString( rec
, 3 ) );
1195 control
->progress_current
= 0;
1196 control
->progress_max
= 100;
1197 control
->progress_backwards
= FALSE
;
1199 x
= MSI_RecordGetInteger( rec
, 4 );
1200 y
= MSI_RecordGetInteger( rec
, 5 );
1201 width
= MSI_RecordGetInteger( rec
, 6 );
1203 x
= msi_dialog_scale_unit( dialog
, x
);
1204 y
= msi_dialog_scale_unit( dialog
, y
);
1205 width
= msi_dialog_scale_unit( dialog
, width
);
1206 height
= 2; /* line is exactly 2 units in height */
1208 control
->hwnd
= CreateWindowExW( exstyle
, szStatic
, NULL
, style
,
1209 x
, y
, width
, height
, dialog
->hwnd
, NULL
, NULL
, NULL
);
1211 TRACE("Dialog %s control %s hwnd %p\n",
1212 debugstr_w(dialog
->name
), debugstr_w(name
), control
->hwnd
);
1214 return ERROR_SUCCESS
;
1217 /******************** Scroll Text ********************************************/
1219 struct msi_scrolltext_info
1222 msi_control
*control
;
1226 static LRESULT WINAPI
1227 MSIScrollText_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1229 struct msi_scrolltext_info
*info
;
1232 TRACE("%p %04x %08lx %08lx\n", hWnd
, msg
, wParam
, lParam
);
1234 info
= GetPropW( hWnd
, szButtonData
);
1236 r
= CallWindowProcW( info
->oldproc
, hWnd
, msg
, wParam
, lParam
);
1241 return DLGC_WANTARROWS
;
1244 RemovePropW( hWnd
, szButtonData
);
1247 /* native MSI sets a wait cursor here */
1248 msi_dialog_button_handler( info
->dialog
, info
->control
, BN_CLICKED
);
1254 struct msi_streamin_info
1261 static DWORD CALLBACK
1262 msi_richedit_stream_in( DWORD_PTR arg
, LPBYTE buffer
, LONG count
, LONG
*pcb
)
1264 struct msi_streamin_info
*info
= (struct msi_streamin_info
*) arg
;
1266 if( (count
+ info
->offset
) > info
->length
)
1267 count
= info
->length
- info
->offset
;
1268 memcpy( buffer
, &info
->string
[ info
->offset
], count
);
1270 info
->offset
+= count
;
1272 TRACE("%d/%d\n", info
->offset
, info
->length
);
1277 static void msi_scrolltext_add_text( msi_control
*control
, LPCWSTR text
)
1279 struct msi_streamin_info info
;
1282 info
.string
= strdupWtoA( text
);
1284 info
.length
= lstrlenA( info
.string
) + 1;
1286 es
.dwCookie
= (DWORD_PTR
) &info
;
1288 es
.pfnCallback
= msi_richedit_stream_in
;
1290 SendMessageW( control
->hwnd
, EM_STREAMIN
, SF_RTF
, (LPARAM
) &es
);
1292 msi_free( info
.string
);
1295 static UINT
msi_dialog_scrolltext_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1297 static const WCHAR szRichEdit20W
[] = {'R','i','c','h','E','d','i','t','2','0','W',0};
1298 struct msi_scrolltext_info
*info
;
1299 msi_control
*control
;
1304 info
= msi_alloc( sizeof *info
);
1306 return ERROR_FUNCTION_FAILED
;
1308 hRichedit
= LoadLibraryA("riched20");
1310 style
= WS_BORDER
| ES_MULTILINE
| WS_VSCROLL
|
1311 ES_READONLY
| ES_AUTOVSCROLL
| WS_TABSTOP
;
1312 control
= msi_dialog_add_control( dialog
, rec
, szRichEdit20W
, style
);
1315 FreeLibrary( hRichedit
);
1317 return ERROR_FUNCTION_FAILED
;
1320 control
->hDll
= hRichedit
;
1322 info
->dialog
= dialog
;
1323 info
->control
= control
;
1325 /* subclass the static control */
1326 info
->oldproc
= (WNDPROC
) SetWindowLongPtrW( control
->hwnd
, GWLP_WNDPROC
,
1327 (LONG_PTR
)MSIScrollText_WndProc
);
1328 SetPropW( control
->hwnd
, szButtonData
, info
);
1330 /* add the text into the richedit */
1331 text
= MSI_RecordGetString( rec
, 10 );
1333 msi_scrolltext_add_text( control
, text
);
1335 return ERROR_SUCCESS
;
1338 static HBITMAP
msi_load_picture( MSIDATABASE
*db
, LPCWSTR name
,
1339 INT cx
, INT cy
, DWORD flags
)
1341 HBITMAP hOleBitmap
= 0, hBitmap
= 0, hOldSrcBitmap
, hOldDestBitmap
;
1342 MSIRECORD
*rec
= NULL
;
1343 IStream
*stm
= NULL
;
1344 IPicture
*pic
= NULL
;
1349 rec
= msi_get_binary_record( db
, name
);
1353 r
= MSI_RecordGetIStream( rec
, 2, &stm
);
1354 msiobj_release( &rec
->hdr
);
1355 if( r
!= ERROR_SUCCESS
)
1358 r
= OleLoadPicture( stm
, 0, TRUE
, &IID_IPicture
, (LPVOID
*) &pic
);
1359 IStream_Release( stm
);
1362 ERR("failed to load picture\n");
1366 r
= IPicture_get_Handle( pic
, (OLE_HANDLE
*) &hOleBitmap
);
1369 ERR("failed to get bitmap handle\n");
1373 /* make the bitmap the desired size */
1374 r
= GetObjectW( hOleBitmap
, sizeof bm
, &bm
);
1375 if (r
!= sizeof bm
)
1377 ERR("failed to get bitmap size\n");
1381 if (flags
& LR_DEFAULTSIZE
)
1387 srcdc
= CreateCompatibleDC( NULL
);
1388 hOldSrcBitmap
= SelectObject( srcdc
, hOleBitmap
);
1389 destdc
= CreateCompatibleDC( NULL
);
1390 hBitmap
= CreateCompatibleBitmap( srcdc
, cx
, cy
);
1391 hOldDestBitmap
= SelectObject( destdc
, hBitmap
);
1392 StretchBlt( destdc
, 0, 0, cx
, cy
,
1393 srcdc
, 0, 0, bm
.bmWidth
, bm
.bmHeight
, SRCCOPY
);
1394 SelectObject( srcdc
, hOldSrcBitmap
);
1395 SelectObject( destdc
, hOldDestBitmap
);
1401 IPicture_Release( pic
);
1405 static UINT
msi_dialog_bitmap_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1407 UINT cx
, cy
, flags
, style
, attributes
;
1408 msi_control
*control
;
1411 flags
= LR_LOADFROMFILE
;
1412 style
= SS_BITMAP
| SS_LEFT
| WS_GROUP
;
1414 attributes
= MSI_RecordGetInteger( rec
, 8 );
1415 if( attributes
& msidbControlAttributesFixedSize
)
1417 flags
|= LR_DEFAULTSIZE
;
1418 style
|= SS_CENTERIMAGE
;
1421 control
= msi_dialog_add_control( dialog
, rec
, szStatic
, style
);
1422 cx
= MSI_RecordGetInteger( rec
, 6 );
1423 cy
= MSI_RecordGetInteger( rec
, 7 );
1424 cx
= msi_dialog_scale_unit( dialog
, cx
);
1425 cy
= msi_dialog_scale_unit( dialog
, cy
);
1427 name
= msi_get_binary_name( dialog
->package
, rec
);
1428 control
->hBitmap
= msi_load_picture( dialog
->package
->db
, name
, cx
, cy
, flags
);
1429 if( control
->hBitmap
)
1430 SendMessageW( control
->hwnd
, STM_SETIMAGE
,
1431 IMAGE_BITMAP
, (LPARAM
) control
->hBitmap
);
1433 ERR("Failed to load bitmap %s\n", debugstr_w(name
));
1437 return ERROR_SUCCESS
;
1440 static UINT
msi_dialog_icon_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1442 msi_control
*control
;
1448 control
= msi_dialog_add_control( dialog
, rec
, szStatic
,
1449 SS_ICON
| SS_CENTERIMAGE
| WS_GROUP
);
1451 attributes
= MSI_RecordGetInteger( rec
, 8 );
1452 name
= msi_get_binary_name( dialog
->package
, rec
);
1453 control
->hIcon
= msi_load_icon( dialog
->package
->db
, name
, attributes
);
1454 if( control
->hIcon
)
1455 SendMessageW( control
->hwnd
, STM_SETICON
, (WPARAM
) control
->hIcon
, 0 );
1457 ERR("Failed to load bitmap %s\n", debugstr_w(name
));
1459 return ERROR_SUCCESS
;
1462 /******************** Combo Box ***************************************/
1464 struct msi_combobox_info
1474 static LRESULT WINAPI
MSIComboBox_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1476 struct msi_combobox_info
*info
;
1480 TRACE("%p %04x %08lx %08lx\n", hWnd
, msg
, wParam
, lParam
);
1482 info
= GetPropW( hWnd
, szButtonData
);
1486 r
= CallWindowProcW( info
->oldproc
, hWnd
, msg
, wParam
, lParam
);
1491 for (j
= 0; j
< info
->num_items
; j
++)
1492 msi_free( info
->items
[j
] );
1493 msi_free( info
->items
);
1495 RemovePropW( hWnd
, szButtonData
);
1502 static UINT
msi_combobox_add_item( MSIRECORD
*rec
, LPVOID param
)
1504 struct msi_combobox_info
*info
= param
;
1505 LPCWSTR value
, text
;
1508 value
= MSI_RecordGetString( rec
, 3 );
1509 text
= MSI_RecordGetString( rec
, 4 );
1511 info
->items
[info
->addpos_items
] = strdupW( value
);
1513 pos
= SendMessageW( info
->hwnd
, CB_ADDSTRING
, 0, (LPARAM
)text
);
1514 SendMessageW( info
->hwnd
, CB_SETITEMDATA
, pos
, (LPARAM
)info
->items
[info
->addpos_items
] );
1515 info
->addpos_items
++;
1517 return ERROR_SUCCESS
;
1520 static UINT
msi_combobox_add_items( struct msi_combobox_info
*info
, LPCWSTR property
)
1522 static const WCHAR query
[] = {
1523 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
1524 '`','C','o','m','b','o','B','o','x','`',' ','W','H','E','R','E',' ',
1525 '`','P','r','o','p','e','r','t','y','`',' ','=',' ','\'','%','s','\'',' ',
1526 'O','R','D','E','R',' ','B','Y',' ','`','O','r','d','e','r','`',0};
1531 r
= MSI_OpenQuery( info
->dialog
->package
->db
, &view
, query
, property
);
1532 if (r
!= ERROR_SUCCESS
)
1535 /* just get the number of records */
1537 r
= MSI_IterateRecords( view
, &count
, NULL
, NULL
);
1538 if (r
!= ERROR_SUCCESS
)
1540 msiobj_release( &view
->hdr
);
1543 info
->num_items
= count
;
1544 info
->items
= msi_alloc( sizeof(*info
->items
) * count
);
1546 r
= MSI_IterateRecords( view
, NULL
, msi_combobox_add_item
, info
);
1547 msiobj_release( &view
->hdr
);
1551 static UINT
msi_dialog_set_control_condition( MSIRECORD
*rec
, LPVOID param
)
1553 static const WCHAR szHide
[] = {'H','i','d','e',0};
1554 static const WCHAR szShow
[] = {'S','h','o','w',0};
1555 static const WCHAR szDisable
[] = {'D','i','s','a','b','l','e',0};
1556 static const WCHAR szEnable
[] = {'E','n','a','b','l','e',0};
1557 static const WCHAR szDefault
[] = {'D','e','f','a','u','l','t',0};
1558 msi_dialog
*dialog
= param
;
1559 msi_control
*control
;
1560 LPCWSTR name
, action
, condition
;
1563 name
= MSI_RecordGetString( rec
, 2 );
1564 action
= MSI_RecordGetString( rec
, 3 );
1565 condition
= MSI_RecordGetString( rec
, 4 );
1566 r
= MSI_EvaluateConditionW( dialog
->package
, condition
);
1567 control
= msi_dialog_find_control( dialog
, name
);
1568 if (r
== MSICONDITION_TRUE
&& control
)
1570 TRACE("%s control %s\n", debugstr_w(action
), debugstr_w(name
));
1572 /* FIXME: case sensitive? */
1573 if (!strcmpW( action
, szHide
))
1574 ShowWindow(control
->hwnd
, SW_HIDE
);
1575 else if (!strcmpW( action
, szShow
))
1576 ShowWindow(control
->hwnd
, SW_SHOW
);
1577 else if (!strcmpW( action
, szDisable
))
1578 EnableWindow(control
->hwnd
, FALSE
);
1579 else if (!strcmpW( action
, szEnable
))
1580 EnableWindow(control
->hwnd
, TRUE
);
1581 else if (!strcmpW( action
, szDefault
))
1582 SetFocus(control
->hwnd
);
1584 FIXME("Unhandled action %s\n", debugstr_w(action
));
1586 return ERROR_SUCCESS
;
1589 static UINT
msi_dialog_evaluate_control_conditions( msi_dialog
*dialog
)
1591 static const WCHAR query
[] = {
1592 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
1593 'C','o','n','t','r','o','l','C','o','n','d','i','t','i','o','n',' ',
1594 'W','H','E','R','E',' ','`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',0};
1597 MSIPACKAGE
*package
= dialog
->package
;
1599 TRACE("%p %s\n", dialog
, debugstr_w(dialog
->name
));
1601 /* query the Control table for all the elements of the control */
1602 r
= MSI_OpenQuery( package
->db
, &view
, query
, dialog
->name
);
1603 if (r
!= ERROR_SUCCESS
)
1604 return ERROR_SUCCESS
;
1606 r
= MSI_IterateRecords( view
, 0, msi_dialog_set_control_condition
, dialog
);
1607 msiobj_release( &view
->hdr
);
1611 static UINT
msi_dialog_combobox_handler( msi_dialog
*dialog
, msi_control
*control
, WPARAM param
)
1613 struct msi_combobox_info
*info
;
1617 if (HIWORD(param
) != CBN_SELCHANGE
&& HIWORD(param
) != CBN_EDITCHANGE
)
1618 return ERROR_SUCCESS
;
1620 info
= GetPropW( control
->hwnd
, szButtonData
);
1621 index
= SendMessageW( control
->hwnd
, CB_GETCURSEL
, 0, 0 );
1622 if (index
== CB_ERR
)
1623 value
= msi_get_window_text( control
->hwnd
);
1625 value
= (LPWSTR
) SendMessageW( control
->hwnd
, CB_GETITEMDATA
, index
, 0 );
1627 msi_dialog_set_property( info
->dialog
->package
, control
->property
, value
);
1628 msi_dialog_evaluate_control_conditions( info
->dialog
);
1630 if (index
== CB_ERR
)
1633 return ERROR_SUCCESS
;
1636 static void msi_dialog_combobox_update( msi_dialog
*dialog
, msi_control
*control
)
1638 struct msi_combobox_info
*info
;
1642 info
= GetPropW( control
->hwnd
, szButtonData
);
1644 value
= msi_dup_property( dialog
->package
->db
, control
->property
);
1647 SendMessageW( control
->hwnd
, CB_SETCURSEL
, -1, 0 );
1651 for (j
= 0; j
< info
->num_items
; j
++)
1653 tmp
= (LPWSTR
) SendMessageW( control
->hwnd
, CB_GETITEMDATA
, j
, 0 );
1654 if (!strcmpW( value
, tmp
))
1658 if (j
< info
->num_items
)
1660 SendMessageW( control
->hwnd
, CB_SETCURSEL
, j
, 0 );
1664 SendMessageW( control
->hwnd
, CB_SETCURSEL
, -1, 0 );
1665 SetWindowTextW( control
->hwnd
, value
);
1671 static UINT
msi_dialog_combo_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1673 struct msi_combobox_info
*info
;
1674 msi_control
*control
;
1675 DWORD attributes
, style
;
1678 info
= msi_alloc( sizeof *info
);
1680 return ERROR_FUNCTION_FAILED
;
1682 style
= CBS_AUTOHSCROLL
| WS_TABSTOP
| WS_GROUP
| WS_CHILD
;
1683 attributes
= MSI_RecordGetInteger( rec
, 8 );
1684 if ( ~attributes
& msidbControlAttributesSorted
)
1686 if ( attributes
& msidbControlAttributesComboList
)
1687 style
|= CBS_DROPDOWNLIST
;
1689 style
|= CBS_DROPDOWN
;
1691 control
= msi_dialog_add_control( dialog
, rec
, WC_COMBOBOXW
, style
);
1695 return ERROR_FUNCTION_FAILED
;
1698 control
->handler
= msi_dialog_combobox_handler
;
1699 control
->update
= msi_dialog_combobox_update
;
1701 prop
= MSI_RecordGetString( rec
, 9 );
1702 control
->property
= msi_dialog_dup_property( dialog
, prop
, FALSE
);
1705 info
->dialog
= dialog
;
1706 info
->hwnd
= control
->hwnd
;
1708 info
->addpos_items
= 0;
1709 info
->oldproc
= (WNDPROC
)SetWindowLongPtrW( control
->hwnd
, GWLP_WNDPROC
,
1710 (LONG_PTR
)MSIComboBox_WndProc
);
1711 SetPropW( control
->hwnd
, szButtonData
, info
);
1713 if (control
->property
)
1714 msi_combobox_add_items( info
, control
->property
);
1716 msi_dialog_combobox_update( dialog
, control
);
1718 return ERROR_SUCCESS
;
1721 static UINT
msi_dialog_edit_handler( msi_dialog
*dialog
, msi_control
*control
, WPARAM param
)
1725 if (HIWORD(param
) != EN_CHANGE
)
1726 return ERROR_SUCCESS
;
1728 TRACE("edit %s contents changed, set %s\n", debugstr_w(control
->name
), debugstr_w(control
->property
));
1730 buf
= msi_get_window_text( control
->hwnd
);
1731 msi_dialog_set_property( dialog
->package
, control
->property
, buf
);
1734 return ERROR_SUCCESS
;
1737 /* length of 2^32 + 1 */
1738 #define MAX_NUM_DIGITS 11
1740 static UINT
msi_dialog_edit_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1742 msi_control
*control
;
1744 LPWSTR val
, begin
, end
;
1745 WCHAR num
[MAX_NUM_DIGITS
];
1748 control
= msi_dialog_add_control( dialog
, rec
, szEdit
,
1749 WS_BORDER
| WS_TABSTOP
| ES_AUTOHSCROLL
);
1750 control
->handler
= msi_dialog_edit_handler
;
1752 text
= MSI_RecordGetString( rec
, 10 );
1755 begin
= strchrW( text
, '{' );
1756 end
= strchrW( text
, '}' );
1758 if ( begin
&& end
&& end
> begin
&&
1759 begin
[0] >= '0' && begin
[0] <= '9' &&
1760 end
- begin
< MAX_NUM_DIGITS
)
1762 lstrcpynW( num
, begin
+ 1, end
- begin
);
1763 limit
= atolW( num
);
1765 SendMessageW( control
->hwnd
, EM_SETLIMITTEXT
, limit
, 0 );
1769 prop
= MSI_RecordGetString( rec
, 9 );
1771 control
->property
= strdupW( prop
);
1773 val
= msi_dup_property( dialog
->package
->db
, control
->property
);
1774 SetWindowTextW( control
->hwnd
, val
);
1776 return ERROR_SUCCESS
;
1779 /******************** Masked Edit ********************************************/
1781 #define MASK_MAX_GROUPS 20
1783 struct msi_mask_group
1791 struct msi_maskedit_info
1799 struct msi_mask_group group
[MASK_MAX_GROUPS
];
1802 static BOOL
msi_mask_editable( WCHAR type
)
1817 static void msi_mask_control_change( struct msi_maskedit_info
*info
)
1822 val
= msi_alloc( (info
->num_chars
+1)*sizeof(WCHAR
) );
1823 for( i
=0, n
=0; i
<info
->num_groups
; i
++ )
1825 if (info
->group
[i
].len
== ~0u)
1827 UINT len
= SendMessageW( info
->group
[i
].hwnd
, WM_GETTEXTLENGTH
, 0, 0 );
1828 val
= msi_realloc( val
, (len
+ 1) * sizeof(WCHAR
) );
1829 GetWindowTextW( info
->group
[i
].hwnd
, val
, len
+ 1 );
1833 if (info
->group
[i
].len
+ n
> info
->num_chars
)
1835 ERR("can't fit control %d text into template\n",i
);
1838 if (!msi_mask_editable(info
->group
[i
].type
))
1840 for(r
=0; r
<info
->group
[i
].len
; r
++)
1841 val
[n
+r
] = info
->group
[i
].type
;
1846 r
= GetWindowTextW( info
->group
[i
].hwnd
, &val
[n
], info
->group
[i
].len
+1 );
1847 if( r
!= info
->group
[i
].len
)
1854 TRACE("%d/%d controls were good\n", i
, info
->num_groups
);
1856 if( i
== info
->num_groups
)
1858 TRACE("Set property %s to %s\n", debugstr_w(info
->prop
), debugstr_w(val
));
1859 msi_dialog_set_property( info
->dialog
->package
, info
->prop
, val
);
1860 msi_dialog_evaluate_control_conditions( info
->dialog
);
1865 /* now move to the next control if necessary */
1866 static VOID
msi_mask_next_control( struct msi_maskedit_info
*info
, HWND hWnd
)
1871 for( i
=0; i
<info
->num_groups
; i
++ )
1872 if( info
->group
[i
].hwnd
== hWnd
)
1875 /* don't move from the last control */
1876 if( i
>= (info
->num_groups
-1) )
1879 len
= SendMessageW( hWnd
, WM_GETTEXTLENGTH
, 0, 0 );
1880 if( len
< info
->group
[i
].len
)
1883 hWndNext
= GetNextDlgTabItem( GetParent( hWnd
), hWnd
, FALSE
);
1884 SetFocus( hWndNext
);
1887 static LRESULT WINAPI
1888 MSIMaskedEdit_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1890 struct msi_maskedit_info
*info
;
1893 TRACE("%p %04x %08lx %08lx\n", hWnd
, msg
, wParam
, lParam
);
1895 info
= GetPropW(hWnd
, szButtonData
);
1897 r
= CallWindowProcW(info
->oldproc
, hWnd
, msg
, wParam
, lParam
);
1902 if (HIWORD(wParam
) == EN_CHANGE
)
1904 msi_mask_control_change( info
);
1905 msi_mask_next_control( info
, (HWND
) lParam
);
1909 msi_free( info
->prop
);
1911 RemovePropW( hWnd
, szButtonData
);
1918 /* fish the various bits of the property out and put them in the control */
1920 msi_maskedit_set_text( struct msi_maskedit_info
*info
, LPCWSTR text
)
1926 for( i
= 0; i
< info
->num_groups
; i
++ )
1928 if( info
->group
[i
].len
< strlenW( p
) )
1930 LPWSTR chunk
= strdupW( p
);
1931 chunk
[ info
->group
[i
].len
] = 0;
1932 SetWindowTextW( info
->group
[i
].hwnd
, chunk
);
1937 SetWindowTextW( info
->group
[i
].hwnd
, p
);
1940 p
+= info
->group
[i
].len
;
1944 static struct msi_maskedit_info
* msi_dialog_parse_groups( LPCWSTR mask
)
1946 struct msi_maskedit_info
*info
;
1947 int i
= 0, n
= 0, total
= 0;
1950 TRACE("masked control, template %s\n", debugstr_w(mask
));
1955 info
= msi_alloc_zero( sizeof *info
);
1959 p
= strchrW(mask
, '<');
1965 for( i
=0; i
<MASK_MAX_GROUPS
; i
++ )
1967 /* stop at the end of the string */
1968 if( p
[0] == 0 || p
[0] == '>' )
1972 /* create a group for the empty mask */
1973 info
->group
[0].type
= '&';
1974 info
->group
[0].len
= ~0u;
1980 /* count the number of the same identifier */
1981 for( n
=0; p
[n
] == p
[0]; n
++ )
1983 info
->group
[i
].ofs
= total
;
1984 info
->group
[i
].type
= p
[0];
1988 total
++; /* an extra not part of the group */
1990 info
->group
[i
].len
= n
;
1995 TRACE("%d characters in %d groups\n", total
, i
);
1996 if( i
== MASK_MAX_GROUPS
)
1997 ERR("too many groups in PIDTemplate %s\n", debugstr_w(mask
));
1999 info
->num_chars
= total
;
2000 info
->num_groups
= i
;
2006 msi_maskedit_create_children( struct msi_maskedit_info
*info
, LPCWSTR font
)
2008 DWORD width
, height
, style
, wx
, ww
;
2013 style
= WS_CHILD
| WS_BORDER
| WS_VISIBLE
| WS_TABSTOP
| ES_AUTOHSCROLL
;
2015 GetClientRect( info
->hwnd
, &rect
);
2017 width
= rect
.right
- rect
.left
;
2018 height
= rect
.bottom
- rect
.top
;
2020 for( i
= 0; i
< info
->num_groups
; i
++ )
2022 if (!msi_mask_editable( info
->group
[i
].type
))
2024 if (info
->num_chars
)
2026 wx
= (info
->group
[i
].ofs
* width
) / info
->num_chars
;
2027 ww
= (info
->group
[i
].len
* width
) / info
->num_chars
;
2034 hwnd
= CreateWindowW( szEdit
, NULL
, style
, wx
, 0, ww
, height
,
2035 info
->hwnd
, NULL
, NULL
, NULL
);
2038 ERR("failed to create mask edit sub window\n");
2042 SendMessageW( hwnd
, EM_LIMITTEXT
, info
->group
[i
].len
, 0 );
2044 msi_dialog_set_font( info
->dialog
, hwnd
,
2045 font
?font
:info
->dialog
->default_font
);
2046 info
->group
[i
].hwnd
= hwnd
;
2051 * office 2003 uses "73931<````=````=````=````=`````>@@@@@"
2052 * delphi 7 uses "<????-??????-??????-????>" and "<???-???>"
2053 * filemaker pro 7 uses "<^^^^=^^^^=^^^^=^^^^=^^^^=^^^^=^^^^^>"
2055 static UINT
msi_dialog_maskedit_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
2057 LPWSTR font_mask
, val
= NULL
, font
;
2058 struct msi_maskedit_info
*info
= NULL
;
2059 UINT ret
= ERROR_SUCCESS
;
2060 msi_control
*control
;
2065 font_mask
= msi_get_deformatted_field( dialog
->package
, rec
, 10 );
2066 font
= msi_dialog_get_style( font_mask
, &mask
);
2069 WARN("mask template is empty\n");
2073 info
= msi_dialog_parse_groups( mask
);
2076 ERR("template %s is invalid\n", debugstr_w(mask
));
2080 info
->dialog
= dialog
;
2082 control
= msi_dialog_add_control( dialog
, rec
, szStatic
,
2083 SS_OWNERDRAW
| WS_GROUP
| WS_VISIBLE
);
2086 ERR("Failed to create maskedit container\n");
2087 ret
= ERROR_FUNCTION_FAILED
;
2090 SetWindowLongPtrW( control
->hwnd
, GWL_EXSTYLE
, WS_EX_CONTROLPARENT
);
2092 info
->hwnd
= control
->hwnd
;
2094 /* subclass the static control */
2095 info
->oldproc
= (WNDPROC
) SetWindowLongPtrW( info
->hwnd
, GWLP_WNDPROC
,
2096 (LONG_PTR
)MSIMaskedEdit_WndProc
);
2097 SetPropW( control
->hwnd
, szButtonData
, info
);
2099 prop
= MSI_RecordGetString( rec
, 9 );
2101 info
->prop
= strdupW( prop
);
2103 msi_maskedit_create_children( info
, font
);
2107 val
= msi_dup_property( dialog
->package
->db
, prop
);
2110 msi_maskedit_set_text( info
, val
);
2116 if( ret
!= ERROR_SUCCESS
)
2118 msi_free( font_mask
);
2123 /******************** Progress Bar *****************************************/
2125 static UINT
msi_dialog_progress_bar( msi_dialog
*dialog
, MSIRECORD
*rec
)
2127 msi_control
*control
;
2128 DWORD attributes
, style
;
2131 attributes
= MSI_RecordGetInteger( rec
, 8 );
2132 if( !(attributes
& msidbControlAttributesProgress95
) )
2133 style
|= PBS_SMOOTH
;
2135 control
= msi_dialog_add_control( dialog
, rec
, PROGRESS_CLASSW
, style
);
2137 return ERROR_FUNCTION_FAILED
;
2139 event_subscribe( dialog
, szSetProgress
, control
->name
, szProgress
);
2140 return ERROR_SUCCESS
;
2143 /******************** Path Edit ********************************************/
2145 struct msi_pathedit_info
2148 msi_control
*control
;
2152 static void msi_dialog_update_pathedit( msi_dialog
*dialog
, msi_control
*control
)
2157 if (!control
&& !(control
= msi_dialog_find_control_by_type( dialog
, szPathEdit
)))
2160 indirect
= control
->attributes
& msidbControlAttributesIndirect
;
2161 prop
= msi_dialog_dup_property( dialog
, control
->property
, indirect
);
2162 path
= msi_dialog_dup_property( dialog
, prop
, TRUE
);
2164 SetWindowTextW( control
->hwnd
, path
);
2165 SendMessageW( control
->hwnd
, EM_SETSEL
, 0, -1 );
2171 /* FIXME: test when this should fail */
2172 static BOOL
msi_dialog_verify_path( LPWSTR path
)
2177 if ( PathIsRelativeW( path
) )
2183 /* returns TRUE if the path is valid, FALSE otherwise */
2184 static BOOL
msi_dialog_onkillfocus( msi_dialog
*dialog
, msi_control
*control
)
2190 indirect
= control
->attributes
& msidbControlAttributesIndirect
;
2191 prop
= msi_dialog_dup_property( dialog
, control
->property
, indirect
);
2193 buf
= msi_get_window_text( control
->hwnd
);
2195 if ( !msi_dialog_verify_path( buf
) )
2197 /* FIXME: display an error message box */
2198 ERR("Invalid path %s\n", debugstr_w( buf
));
2200 SetFocus( control
->hwnd
);
2205 msi_dialog_set_property( dialog
->package
, prop
, buf
);
2208 msi_dialog_update_pathedit( dialog
, control
);
2210 TRACE("edit %s contents changed, set %s\n", debugstr_w(control
->name
),
2219 static LRESULT WINAPI
MSIPathEdit_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
2221 struct msi_pathedit_info
*info
= GetPropW(hWnd
, szButtonData
);
2224 TRACE("%p %04x %08lx %08lx\n", hWnd
, msg
, wParam
, lParam
);
2226 if ( msg
== WM_KILLFOCUS
)
2228 /* if the path is invalid, don't handle this message */
2229 if ( !msi_dialog_onkillfocus( info
->dialog
, info
->control
) )
2233 r
= CallWindowProcW(info
->oldproc
, hWnd
, msg
, wParam
, lParam
);
2235 if ( msg
== WM_NCDESTROY
)
2238 RemovePropW( hWnd
, szButtonData
);
2244 static UINT
msi_dialog_pathedit_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
2246 struct msi_pathedit_info
*info
;
2247 msi_control
*control
;
2250 info
= msi_alloc( sizeof *info
);
2252 return ERROR_FUNCTION_FAILED
;
2254 control
= msi_dialog_add_control( dialog
, rec
, szEdit
,
2255 WS_BORDER
| WS_TABSTOP
);
2256 control
->attributes
= MSI_RecordGetInteger( rec
, 8 );
2257 prop
= MSI_RecordGetString( rec
, 9 );
2258 control
->property
= msi_dialog_dup_property( dialog
, prop
, FALSE
);
2260 info
->dialog
= dialog
;
2261 info
->control
= control
;
2262 info
->oldproc
= (WNDPROC
) SetWindowLongPtrW( control
->hwnd
, GWLP_WNDPROC
,
2263 (LONG_PTR
)MSIPathEdit_WndProc
);
2264 SetPropW( control
->hwnd
, szButtonData
, info
);
2266 msi_dialog_update_pathedit( dialog
, control
);
2268 return ERROR_SUCCESS
;
2271 static UINT
msi_dialog_radiogroup_handler( msi_dialog
*dialog
, msi_control
*control
, WPARAM param
)
2273 if (HIWORD(param
) != BN_CLICKED
)
2274 return ERROR_SUCCESS
;
2276 TRACE("clicked radio button %s, set %s\n", debugstr_w(control
->name
), debugstr_w(control
->property
));
2278 msi_dialog_set_property( dialog
->package
, control
->property
, control
->name
);
2280 return msi_dialog_button_handler( dialog
, control
, param
);
2283 /* radio buttons are a bit different from normal controls */
2284 static UINT
msi_dialog_create_radiobutton( MSIRECORD
*rec
, LPVOID param
)
2286 radio_button_group_descr
*group
= param
;
2287 msi_dialog
*dialog
= group
->dialog
;
2288 msi_control
*control
;
2289 LPCWSTR prop
, text
, name
;
2290 DWORD style
, attributes
= group
->attributes
;
2292 style
= WS_CHILD
| BS_AUTORADIOBUTTON
| BS_MULTILINE
| WS_TABSTOP
;
2293 name
= MSI_RecordGetString( rec
, 3 );
2294 text
= MSI_RecordGetString( rec
, 8 );
2295 if( attributes
& msidbControlAttributesVisible
)
2296 style
|= WS_VISIBLE
;
2297 if( ~attributes
& msidbControlAttributesEnabled
)
2298 style
|= WS_DISABLED
;
2300 control
= dialog_create_window( dialog
, rec
, 0, szButton
, name
, text
, style
,
2301 group
->parent
->hwnd
);
2303 return ERROR_FUNCTION_FAILED
;
2304 control
->handler
= msi_dialog_radiogroup_handler
;
2306 if (group
->propval
&& !strcmpW( control
->name
, group
->propval
))
2307 SendMessageW(control
->hwnd
, BM_SETCHECK
, BST_CHECKED
, 0);
2309 prop
= MSI_RecordGetString( rec
, 1 );
2311 control
->property
= strdupW( prop
);
2313 return ERROR_SUCCESS
;
2316 static BOOL CALLBACK
msi_radioground_child_enum( HWND hWnd
, LPARAM lParam
)
2318 EnableWindow( hWnd
, lParam
);
2322 static LRESULT WINAPI
MSIRadioGroup_WndProc( HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
2324 WNDPROC oldproc
= (WNDPROC
)GetPropW( hWnd
, szButtonData
);
2327 TRACE("hWnd %p msg %04x wParam 0x%08lx lParam 0x%08lx\n", hWnd
, msg
, wParam
, lParam
);
2329 if (msg
== WM_COMMAND
) /* Forward notifications to dialog */
2330 SendMessageW( GetParent( hWnd
), msg
, wParam
, lParam
);
2332 r
= CallWindowProcW( oldproc
, hWnd
, msg
, wParam
, lParam
);
2334 /* make sure the radio buttons show as disabled if the parent is disabled */
2335 if (msg
== WM_ENABLE
)
2336 EnumChildWindows( hWnd
, msi_radioground_child_enum
, wParam
);
2341 static UINT
msi_dialog_radiogroup_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
2343 static const WCHAR query
[] = {
2344 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2345 'R','a','d','i','o','B','u','t','t','o','n',' ','W','H','E','R','E',' ',
2346 '`','P','r','o','p','e','r','t','y','`',' ','=',' ','\'','%','s','\'',0};
2349 msi_control
*control
;
2351 radio_button_group_descr group
;
2352 MSIPACKAGE
*package
= dialog
->package
;
2354 DWORD attr
, style
= WS_GROUP
;
2356 prop
= MSI_RecordGetString( rec
, 9 );
2358 TRACE("%p %p %s\n", dialog
, rec
, debugstr_w( prop
));
2360 attr
= MSI_RecordGetInteger( rec
, 8 );
2361 if (attr
& msidbControlAttributesHasBorder
)
2362 style
|= BS_GROUPBOX
;
2364 style
|= BS_OWNERDRAW
;
2366 /* Create parent group box to hold radio buttons */
2367 control
= msi_dialog_add_control( dialog
, rec
, szButton
, style
);
2369 return ERROR_FUNCTION_FAILED
;
2371 oldproc
= (WNDPROC
) SetWindowLongPtrW( control
->hwnd
, GWLP_WNDPROC
,
2372 (LONG_PTR
)MSIRadioGroup_WndProc
);
2373 SetPropW(control
->hwnd
, szButtonData
, oldproc
);
2374 SetWindowLongPtrW( control
->hwnd
, GWL_EXSTYLE
, WS_EX_CONTROLPARENT
);
2377 control
->property
= strdupW( prop
);
2379 /* query the Radio Button table for all control in this group */
2380 r
= MSI_OpenQuery( package
->db
, &view
, query
, prop
);
2381 if( r
!= ERROR_SUCCESS
)
2383 ERR("query failed for dialog %s radio group %s\n",
2384 debugstr_w(dialog
->name
), debugstr_w(prop
));
2385 return ERROR_INVALID_PARAMETER
;
2388 group
.dialog
= dialog
;
2389 group
.parent
= control
;
2390 group
.attributes
= MSI_RecordGetInteger( rec
, 8 );
2391 group
.propval
= msi_dup_property( dialog
->package
->db
, control
->property
);
2393 r
= MSI_IterateRecords( view
, 0, msi_dialog_create_radiobutton
, &group
);
2394 msiobj_release( &view
->hdr
);
2395 msi_free( group
.propval
);
2400 msi_seltree_sync_item_state( HWND hwnd
, MSIFEATURE
*feature
, HTREEITEM hItem
)
2403 DWORD index
= feature
->ActionRequest
;
2405 TRACE("Feature %s -> %d %d %d\n", debugstr_w(feature
->Title
),
2406 feature
->Installed
, feature
->Action
, feature
->ActionRequest
);
2408 if (index
== INSTALLSTATE_UNKNOWN
)
2409 index
= INSTALLSTATE_ABSENT
;
2411 tvi
.mask
= TVIF_STATE
;
2413 tvi
.state
= INDEXTOSTATEIMAGEMASK( index
);
2414 tvi
.stateMask
= TVIS_STATEIMAGEMASK
;
2416 SendMessageW( hwnd
, TVM_SETITEMW
, 0, (LPARAM
) &tvi
);
2420 msi_seltree_popup_menu( HWND hwnd
, INT x
, INT y
)
2425 /* create a menu to display */
2426 hMenu
= CreatePopupMenu();
2428 /* FIXME: load strings from resources */
2429 AppendMenuA( hMenu
, MF_ENABLED
, INSTALLSTATE_LOCAL
, "Install feature locally");
2430 AppendMenuA( hMenu
, MF_ENABLED
, USER_INSTALLSTATE_ALL
, "Install entire feature");
2431 AppendMenuA( hMenu
, MF_ENABLED
, INSTALLSTATE_ADVERTISED
, "Install on demand");
2432 AppendMenuA( hMenu
, MF_ENABLED
, INSTALLSTATE_ABSENT
, "Don't install");
2433 r
= TrackPopupMenu( hMenu
, TPM_LEFTALIGN
| TPM_TOPALIGN
| TPM_RETURNCMD
,
2434 x
, y
, 0, hwnd
, NULL
);
2435 DestroyMenu( hMenu
);
2440 msi_seltree_update_feature_installstate( HWND hwnd
, HTREEITEM hItem
,
2441 MSIPACKAGE
*package
, MSIFEATURE
*feature
, INSTALLSTATE state
)
2443 feature
->ActionRequest
= state
;
2444 msi_seltree_sync_item_state( hwnd
, feature
, hItem
);
2445 ACTION_UpdateComponentStates( package
, feature
);
2449 msi_seltree_update_siblings_and_children_installstate( HWND hwnd
, HTREEITEM curr
,
2450 MSIPACKAGE
*package
, INSTALLSTATE state
)
2452 /* update all siblings */
2455 MSIFEATURE
*feature
;
2458 feature
= msi_seltree_feature_from_item( hwnd
, curr
);
2459 msi_seltree_update_feature_installstate( hwnd
, curr
, package
, feature
, state
);
2461 /* update this sibling's children */
2462 child
= (HTREEITEM
)SendMessageW( hwnd
, TVM_GETNEXTITEM
, (WPARAM
)TVGN_CHILD
, (LPARAM
)curr
);
2464 msi_seltree_update_siblings_and_children_installstate( hwnd
, child
,
2467 while ((curr
= (HTREEITEM
)SendMessageW( hwnd
, TVM_GETNEXTITEM
, (WPARAM
)TVGN_NEXT
, (LPARAM
)curr
)));
2471 msi_seltree_menu( HWND hwnd
, HTREEITEM hItem
)
2473 struct msi_selection_tree_info
*info
;
2474 MSIFEATURE
*feature
;
2475 MSIPACKAGE
*package
;
2483 info
= GetPropW(hwnd
, szButtonData
);
2484 package
= info
->dialog
->package
;
2486 feature
= msi_seltree_feature_from_item( hwnd
, hItem
);
2489 ERR("item %p feature was NULL\n", hItem
);
2493 /* get the item's rectangle to put the menu just below it */
2495 SendMessageW( hwnd
, TVM_GETITEMRECT
, 0, (LPARAM
) &u
.rc
);
2496 MapWindowPoints( hwnd
, NULL
, u
.pt
, 2 );
2498 r
= msi_seltree_popup_menu( hwnd
, u
.rc
.left
, u
.rc
.top
);
2502 case USER_INSTALLSTATE_ALL
:
2503 r
= INSTALLSTATE_LOCAL
;
2505 case INSTALLSTATE_ADVERTISED
:
2506 case INSTALLSTATE_ABSENT
:
2509 child
= (HTREEITEM
)SendMessageW( hwnd
, TVM_GETNEXTITEM
, (WPARAM
)TVGN_CHILD
, (LPARAM
)hItem
);
2511 msi_seltree_update_siblings_and_children_installstate( hwnd
, child
, package
, r
);
2514 case INSTALLSTATE_LOCAL
:
2515 msi_seltree_update_feature_installstate( hwnd
, hItem
, package
, feature
, r
);
2522 static LRESULT WINAPI
2523 MSISelectionTree_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
2525 struct msi_selection_tree_info
*info
;
2526 TVHITTESTINFO tvhti
;
2529 TRACE("%p %04x %08lx %08lx\n", hWnd
, msg
, wParam
, lParam
);
2531 info
= GetPropW(hWnd
, szButtonData
);
2535 case WM_LBUTTONDOWN
:
2536 tvhti
.pt
.x
= (short)LOWORD( lParam
);
2537 tvhti
.pt
.y
= (short)HIWORD( lParam
);
2540 CallWindowProcW(info
->oldproc
, hWnd
, TVM_HITTEST
, 0, (LPARAM
) &tvhti
);
2541 if (tvhti
.flags
& TVHT_ONITEMSTATEICON
)
2542 return msi_seltree_menu( hWnd
, tvhti
.hItem
);
2545 r
= CallWindowProcW(info
->oldproc
, hWnd
, msg
, wParam
, lParam
);
2551 RemovePropW( hWnd
, szButtonData
);
2558 msi_seltree_add_child_features( MSIPACKAGE
*package
, HWND hwnd
,
2559 LPCWSTR parent
, HTREEITEM hParent
)
2561 struct msi_selection_tree_info
*info
= GetPropW( hwnd
, szButtonData
);
2562 MSIFEATURE
*feature
;
2563 TVINSERTSTRUCTW tvis
;
2564 HTREEITEM hitem
, hfirst
= NULL
;
2566 LIST_FOR_EACH_ENTRY( feature
, &package
->features
, MSIFEATURE
, entry
)
2568 if ( parent
&& feature
->Feature_Parent
&& strcmpW( parent
, feature
->Feature_Parent
))
2570 else if ( parent
&& !feature
->Feature_Parent
)
2572 else if ( !parent
&& feature
->Feature_Parent
)
2575 if ( !feature
->Title
)
2578 if ( !feature
->Display
)
2581 memset( &tvis
, 0, sizeof tvis
);
2582 tvis
.hParent
= hParent
;
2583 tvis
.hInsertAfter
= TVI_LAST
;
2584 tvis
.u
.item
.mask
= TVIF_TEXT
| TVIF_PARAM
;
2585 tvis
.u
.item
.pszText
= feature
->Title
;
2586 tvis
.u
.item
.lParam
= (LPARAM
) feature
;
2588 hitem
= (HTREEITEM
) SendMessageW( hwnd
, TVM_INSERTITEMW
, 0, (LPARAM
) &tvis
);
2595 msi_seltree_sync_item_state( hwnd
, feature
, hitem
);
2596 msi_seltree_add_child_features( package
, hwnd
,
2597 feature
->Feature
, hitem
);
2599 /* the node is expanded if Display is odd */
2600 if ( feature
->Display
% 2 != 0 )
2601 SendMessageW( hwnd
, TVM_EXPAND
, TVE_EXPAND
, (LPARAM
) hitem
);
2604 /* select the first item */
2605 SendMessageW( hwnd
, TVM_SELECTITEM
, TVGN_CARET
| TVGN_DROPHILITE
, (LPARAM
) hfirst
);
2606 info
->selected
= hfirst
;
2609 static void msi_seltree_create_imagelist( HWND hwnd
)
2611 const int bm_width
= 32, bm_height
= 16, bm_count
= 3;
2612 const int bm_resource
= 0x1001;
2617 himl
= ImageList_Create( bm_width
, bm_height
, FALSE
, 4, 0 );
2620 ERR("failed to create image list\n");
2624 for (i
=0; i
<bm_count
; i
++)
2626 hbmp
= LoadBitmapW( msi_hInstance
, MAKEINTRESOURCEW(i
+bm_resource
) );
2629 ERR("failed to load bitmap %d\n", i
);
2634 * Add a dummy bitmap at offset zero because the treeview
2635 * can't use it as a state mask (zero means no user state).
2638 ImageList_Add( himl
, hbmp
, NULL
);
2640 ImageList_Add( himl
, hbmp
, NULL
);
2643 SendMessageW( hwnd
, TVM_SETIMAGELIST
, TVSIL_STATE
, (LPARAM
)himl
);
2646 static UINT
msi_dialog_seltree_handler( msi_dialog
*dialog
,
2647 msi_control
*control
, WPARAM param
)
2649 struct msi_selection_tree_info
*info
= GetPropW( control
->hwnd
, szButtonData
);
2650 LPNMTREEVIEWW tv
= (LPNMTREEVIEWW
)param
;
2651 MSIRECORD
*row
, *rec
;
2653 MSIFEATURE
*feature
;
2654 LPCWSTR dir
, title
= NULL
;
2655 UINT r
= ERROR_SUCCESS
;
2657 static const WCHAR select
[] = {
2658 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2659 '`','F','e','a','t','u','r','e','`',' ','W','H','E','R','E',' ',
2660 '`','T','i','t','l','e','`',' ','=',' ','\'','%','s','\'',0
2663 if (tv
->hdr
.code
!= TVN_SELCHANGINGW
)
2664 return ERROR_SUCCESS
;
2666 info
->selected
= tv
->itemNew
.hItem
;
2668 if (!(tv
->itemNew
.mask
& TVIF_TEXT
))
2670 feature
= msi_seltree_feature_from_item( control
->hwnd
, tv
->itemNew
.hItem
);
2672 title
= feature
->Title
;
2675 title
= tv
->itemNew
.pszText
;
2677 row
= MSI_QueryGetRecord( dialog
->package
->db
, select
, title
);
2679 return ERROR_FUNCTION_FAILED
;
2681 rec
= MSI_CreateRecord( 1 );
2683 MSI_RecordSetStringW( rec
, 1, MSI_RecordGetString( row
, 4 ) );
2684 msi_event_fire( dialog
->package
, szSelectionDescription
, rec
);
2686 dir
= MSI_RecordGetString( row
, 7 );
2689 folder
= msi_get_loaded_folder( dialog
->package
, dir
);
2692 r
= ERROR_FUNCTION_FAILED
;
2695 MSI_RecordSetStringW( rec
, 1, folder
->ResolvedTarget
);
2698 MSI_RecordSetStringW( rec
, 1, NULL
);
2700 msi_event_fire( dialog
->package
, szSelectionPath
, rec
);
2703 msiobj_release(&row
->hdr
);
2704 msiobj_release(&rec
->hdr
);
2709 static UINT
msi_dialog_selection_tree( msi_dialog
*dialog
, MSIRECORD
*rec
)
2711 msi_control
*control
;
2712 LPCWSTR prop
, control_name
;
2713 MSIPACKAGE
*package
= dialog
->package
;
2715 struct msi_selection_tree_info
*info
;
2717 info
= msi_alloc( sizeof *info
);
2719 return ERROR_FUNCTION_FAILED
;
2721 /* create the treeview control */
2722 style
= TVS_HASLINES
| TVS_HASBUTTONS
| TVS_LINESATROOT
;
2723 style
|= WS_GROUP
| WS_VSCROLL
;
2724 control
= msi_dialog_add_control( dialog
, rec
, WC_TREEVIEWW
, style
);
2728 return ERROR_FUNCTION_FAILED
;
2731 control
->handler
= msi_dialog_seltree_handler
;
2732 control_name
= MSI_RecordGetString( rec
, 2 );
2733 control
->attributes
= MSI_RecordGetInteger( rec
, 8 );
2734 prop
= MSI_RecordGetString( rec
, 9 );
2735 control
->property
= msi_dialog_dup_property( dialog
, prop
, FALSE
);
2738 info
->dialog
= dialog
;
2739 info
->hwnd
= control
->hwnd
;
2740 info
->oldproc
= (WNDPROC
) SetWindowLongPtrW( control
->hwnd
, GWLP_WNDPROC
,
2741 (LONG_PTR
)MSISelectionTree_WndProc
);
2742 SetPropW( control
->hwnd
, szButtonData
, info
);
2744 event_subscribe( dialog
, szSelectionPath
, control_name
, szProperty
);
2747 msi_seltree_create_imagelist( control
->hwnd
);
2748 msi_seltree_add_child_features( package
, control
->hwnd
, NULL
, NULL
);
2750 return ERROR_SUCCESS
;
2753 /******************** Group Box ***************************************/
2755 static UINT
msi_dialog_group_box( msi_dialog
*dialog
, MSIRECORD
*rec
)
2757 msi_control
*control
;
2760 style
= BS_GROUPBOX
| WS_CHILD
| WS_GROUP
;
2761 control
= msi_dialog_add_control( dialog
, rec
, WC_BUTTONW
, style
);
2763 return ERROR_FUNCTION_FAILED
;
2765 return ERROR_SUCCESS
;
2768 /******************** List Box ***************************************/
2770 struct msi_listbox_info
2780 static LRESULT WINAPI
MSIListBox_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
2782 struct msi_listbox_info
*info
;
2786 TRACE("%p %04x %08lx %08lx\n", hWnd
, msg
, wParam
, lParam
);
2788 info
= GetPropW( hWnd
, szButtonData
);
2792 r
= CallWindowProcW( info
->oldproc
, hWnd
, msg
, wParam
, lParam
);
2797 for (j
= 0; j
< info
->num_items
; j
++)
2798 msi_free( info
->items
[j
] );
2799 msi_free( info
->items
);
2801 RemovePropW( hWnd
, szButtonData
);
2808 static UINT
msi_listbox_add_item( MSIRECORD
*rec
, LPVOID param
)
2810 struct msi_listbox_info
*info
= param
;
2811 LPCWSTR value
, text
;
2814 value
= MSI_RecordGetString( rec
, 3 );
2815 text
= MSI_RecordGetString( rec
, 4 );
2817 info
->items
[info
->addpos_items
] = strdupW( value
);
2819 pos
= SendMessageW( info
->hwnd
, LB_ADDSTRING
, 0, (LPARAM
)text
);
2820 SendMessageW( info
->hwnd
, LB_SETITEMDATA
, pos
, (LPARAM
)info
->items
[info
->addpos_items
] );
2821 info
->addpos_items
++;
2822 return ERROR_SUCCESS
;
2825 static UINT
msi_listbox_add_items( struct msi_listbox_info
*info
, LPCWSTR property
)
2827 static const WCHAR query
[] = {
2828 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2829 '`','L','i','s','t','B','o','x','`',' ','W','H','E','R','E',' ',
2830 '`','P','r','o','p','e','r','t','y','`',' ','=',' ','\'','%','s','\'',' ',
2831 'O','R','D','E','R',' ','B','Y',' ','`','O','r','d','e','r','`',0};
2836 r
= MSI_OpenQuery( info
->dialog
->package
->db
, &view
, query
, property
);
2837 if ( r
!= ERROR_SUCCESS
)
2840 /* just get the number of records */
2842 r
= MSI_IterateRecords( view
, &count
, NULL
, NULL
);
2843 if (r
!= ERROR_SUCCESS
)
2845 msiobj_release( &view
->hdr
);
2848 info
->num_items
= count
;
2849 info
->items
= msi_alloc( sizeof(*info
->items
) * count
);
2851 r
= MSI_IterateRecords( view
, NULL
, msi_listbox_add_item
, info
);
2852 msiobj_release( &view
->hdr
);
2856 static UINT
msi_dialog_listbox_handler( msi_dialog
*dialog
,
2857 msi_control
*control
, WPARAM param
)
2859 struct msi_listbox_info
*info
;
2863 if( HIWORD(param
) != LBN_SELCHANGE
)
2864 return ERROR_SUCCESS
;
2866 info
= GetPropW( control
->hwnd
, szButtonData
);
2867 index
= SendMessageW( control
->hwnd
, LB_GETCURSEL
, 0, 0 );
2868 value
= (LPCWSTR
) SendMessageW( control
->hwnd
, LB_GETITEMDATA
, index
, 0 );
2870 msi_dialog_set_property( info
->dialog
->package
, control
->property
, value
);
2871 msi_dialog_evaluate_control_conditions( info
->dialog
);
2873 return ERROR_SUCCESS
;
2876 static UINT
msi_dialog_list_box( msi_dialog
*dialog
, MSIRECORD
*rec
)
2878 struct msi_listbox_info
*info
;
2879 msi_control
*control
;
2880 DWORD attributes
, style
;
2883 info
= msi_alloc( sizeof *info
);
2885 return ERROR_FUNCTION_FAILED
;
2887 style
= WS_TABSTOP
| WS_GROUP
| WS_CHILD
| LBS_NOTIFY
| WS_VSCROLL
| WS_BORDER
;
2888 attributes
= MSI_RecordGetInteger( rec
, 8 );
2889 if (~attributes
& msidbControlAttributesSorted
)
2892 control
= msi_dialog_add_control( dialog
, rec
, WC_LISTBOXW
, style
);
2896 return ERROR_FUNCTION_FAILED
;
2899 control
->handler
= msi_dialog_listbox_handler
;
2901 prop
= MSI_RecordGetString( rec
, 9 );
2902 control
->property
= msi_dialog_dup_property( dialog
, prop
, FALSE
);
2905 info
->dialog
= dialog
;
2906 info
->hwnd
= control
->hwnd
;
2908 info
->addpos_items
= 0;
2909 info
->oldproc
= (WNDPROC
)SetWindowLongPtrW( control
->hwnd
, GWLP_WNDPROC
,
2910 (LONG_PTR
)MSIListBox_WndProc
);
2911 SetPropW( control
->hwnd
, szButtonData
, info
);
2913 if ( control
->property
)
2914 msi_listbox_add_items( info
, control
->property
);
2916 return ERROR_SUCCESS
;
2919 /******************** Directory Combo ***************************************/
2921 static void msi_dialog_update_directory_combo( msi_dialog
*dialog
, msi_control
*control
)
2926 if (!control
&& !(control
= msi_dialog_find_control_by_type( dialog
, szDirectoryCombo
)))
2929 indirect
= control
->attributes
& msidbControlAttributesIndirect
;
2930 prop
= msi_dialog_dup_property( dialog
, control
->property
, indirect
);
2931 path
= msi_dialog_dup_property( dialog
, prop
, TRUE
);
2933 PathStripPathW( path
);
2934 PathRemoveBackslashW( path
);
2936 SendMessageW( control
->hwnd
, CB_INSERTSTRING
, 0, (LPARAM
)path
);
2937 SendMessageW( control
->hwnd
, CB_SETCURSEL
, 0, 0 );
2943 static UINT
msi_dialog_directory_combo( msi_dialog
*dialog
, MSIRECORD
*rec
)
2945 msi_control
*control
;
2949 /* FIXME: use CBS_OWNERDRAWFIXED and add owner draw code */
2950 style
= CBS_DROPDOWNLIST
| CBS_HASSTRINGS
| WS_CHILD
|
2951 WS_GROUP
| WS_TABSTOP
| WS_VSCROLL
;
2952 control
= msi_dialog_add_control( dialog
, rec
, WC_COMBOBOXW
, style
);
2954 return ERROR_FUNCTION_FAILED
;
2956 control
->attributes
= MSI_RecordGetInteger( rec
, 8 );
2957 prop
= MSI_RecordGetString( rec
, 9 );
2958 control
->property
= msi_dialog_dup_property( dialog
, prop
, FALSE
);
2960 msi_dialog_update_directory_combo( dialog
, control
);
2962 return ERROR_SUCCESS
;
2965 /******************** Directory List ***************************************/
2967 static void msi_dialog_update_directory_list( msi_dialog
*dialog
, msi_control
*control
)
2969 WCHAR dir_spec
[MAX_PATH
];
2970 WIN32_FIND_DATAW wfd
;
2976 static const WCHAR asterisk
[] = {'*',0};
2978 if (!control
&& !(control
= msi_dialog_find_control_by_type( dialog
, szDirectoryList
)))
2981 /* clear the list-view */
2982 SendMessageW( control
->hwnd
, LVM_DELETEALLITEMS
, 0, 0 );
2984 indirect
= control
->attributes
& msidbControlAttributesIndirect
;
2985 prop
= msi_dialog_dup_property( dialog
, control
->property
, indirect
);
2986 path
= msi_dialog_dup_property( dialog
, prop
, TRUE
);
2988 lstrcpyW( dir_spec
, path
);
2989 lstrcatW( dir_spec
, asterisk
);
2991 file
= FindFirstFileW( dir_spec
, &wfd
);
2992 if ( file
== INVALID_HANDLE_VALUE
)
2997 if ( wfd
.dwFileAttributes
!= FILE_ATTRIBUTE_DIRECTORY
)
3000 if ( !strcmpW( wfd
.cFileName
, szDot
) || !strcmpW( wfd
.cFileName
, szDotDot
) )
3003 item
.mask
= LVIF_TEXT
;
3004 item
.cchTextMax
= MAX_PATH
;
3007 item
.pszText
= wfd
.cFileName
;
3009 SendMessageW( control
->hwnd
, LVM_INSERTITEMW
, 0, (LPARAM
)&item
);
3010 } while ( FindNextFileW( file
, &wfd
) );
3017 static UINT
msi_dialog_directorylist_up( msi_dialog
*dialog
)
3019 msi_control
*control
;
3020 LPWSTR prop
, path
, ptr
;
3023 control
= msi_dialog_find_control_by_type( dialog
, szDirectoryList
);
3024 indirect
= control
->attributes
& msidbControlAttributesIndirect
;
3025 prop
= msi_dialog_dup_property( dialog
, control
->property
, indirect
);
3026 path
= msi_dialog_dup_property( dialog
, prop
, TRUE
);
3028 /* strip off the last directory */
3029 ptr
= PathFindFileNameW( path
);
3030 if (ptr
!= path
) *(ptr
- 1) = '\0';
3031 PathAddBackslashW( path
);
3033 msi_dialog_set_property( dialog
->package
, prop
, path
);
3035 msi_dialog_update_directory_list( dialog
, NULL
);
3036 msi_dialog_update_directory_combo( dialog
, NULL
);
3037 msi_dialog_update_pathedit( dialog
, NULL
);
3042 return ERROR_SUCCESS
;
3045 static UINT
msi_dialog_dirlist_handler( msi_dialog
*dialog
,
3046 msi_control
*control
, WPARAM param
)
3048 LPNMHDR nmhdr
= (LPNMHDR
)param
;
3049 WCHAR new_path
[MAX_PATH
];
3050 WCHAR text
[MAX_PATH
];
3056 if (nmhdr
->code
!= LVN_ITEMACTIVATE
)
3057 return ERROR_SUCCESS
;
3059 index
= SendMessageW( control
->hwnd
, LVM_GETNEXTITEM
, -1, LVNI_SELECTED
);
3062 ERR("No list-view item selected!\n");
3063 return ERROR_FUNCTION_FAILED
;
3067 item
.pszText
= text
;
3068 item
.cchTextMax
= MAX_PATH
;
3069 SendMessageW( control
->hwnd
, LVM_GETITEMTEXTW
, index
, (LPARAM
)&item
);
3071 indirect
= control
->attributes
& msidbControlAttributesIndirect
;
3072 prop
= msi_dialog_dup_property( dialog
, control
->property
, indirect
);
3073 path
= msi_dialog_dup_property( dialog
, prop
, TRUE
);
3075 lstrcpyW( new_path
, path
);
3076 lstrcatW( new_path
, text
);
3077 lstrcatW( new_path
, szBackSlash
);
3079 msi_dialog_set_property( dialog
->package
, prop
, new_path
);
3081 msi_dialog_update_directory_list( dialog
, NULL
);
3082 msi_dialog_update_directory_combo( dialog
, NULL
);
3083 msi_dialog_update_pathedit( dialog
, NULL
);
3087 return ERROR_SUCCESS
;
3090 static UINT
msi_dialog_directory_list( msi_dialog
*dialog
, MSIRECORD
*rec
)
3092 msi_control
*control
;
3096 style
= LVS_LIST
| WS_VSCROLL
| LVS_SHAREIMAGELISTS
|
3097 LVS_AUTOARRANGE
| LVS_SINGLESEL
| WS_BORDER
|
3098 LVS_SORTASCENDING
| WS_CHILD
| WS_GROUP
| WS_TABSTOP
;
3099 control
= msi_dialog_add_control( dialog
, rec
, WC_LISTVIEWW
, style
);
3101 return ERROR_FUNCTION_FAILED
;
3103 control
->attributes
= MSI_RecordGetInteger( rec
, 8 );
3104 control
->handler
= msi_dialog_dirlist_handler
;
3105 prop
= MSI_RecordGetString( rec
, 9 );
3106 control
->property
= msi_dialog_dup_property( dialog
, prop
, FALSE
);
3108 /* double click to activate an item in the list */
3109 SendMessageW( control
->hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
,
3110 0, LVS_EX_TWOCLICKACTIVATE
);
3112 msi_dialog_update_directory_list( dialog
, control
);
3114 return ERROR_SUCCESS
;
3117 /******************** VolumeCost List ***************************************/
3119 static BOOL
str_is_number( LPCWSTR str
)
3123 for (i
= 0; i
< lstrlenW( str
); i
++)
3124 if (!isdigitW(str
[i
]))
3130 static const WCHAR column_keys
[][80] =
3132 {'V','o','l','u','m','e','C','o','s','t','V','o','l','u','m','e',0},
3133 {'V','o','l','u','m','e','C','o','s','t','S','i','z','e',0},
3134 {'V','o','l','u','m','e','C','o','s','t','A','v','a','i','l','a','b','l','e',0},
3135 {'V','o','l','u','m','e','C','o','s','t','R','e','q','u','i','r','e','d',0},
3136 {'V','o','l','u','m','e','C','o','s','t','D','i','f','f','e','r','e','n','c','e',0}
3139 static void msi_dialog_vcl_add_columns( msi_dialog
*dialog
, msi_control
*control
, MSIRECORD
*rec
)
3141 LPCWSTR text
= MSI_RecordGetString( rec
, 10 );
3142 LPCWSTR begin
= text
, end
;
3147 static const WCHAR negative
[] = {'-',0};
3151 while ((begin
= strchrW( begin
, '{' )) && count
< 5)
3153 if (!(end
= strchrW( begin
, '}' )))
3156 num
= msi_alloc( (end
-begin
+1)*sizeof(WCHAR
) );
3160 lstrcpynW( num
, begin
+ 1, end
- begin
);
3161 begin
+= end
- begin
+ 1;
3163 /* empty braces or '0' hides the column */
3164 if ( !num
[0] || !strcmpW( num
, szZero
) )
3171 /* the width must be a positive number
3172 * if a width is invalid, all remaining columns are hidden
3174 if ( !strncmpW( num
, negative
, 1 ) || !str_is_number( num
) ) {
3179 ZeroMemory( &lvc
, sizeof(lvc
) );
3180 lvc
.mask
= LVCF_TEXT
| LVCF_WIDTH
| LVCF_SUBITEM
;
3181 lvc
.cx
= atolW( num
);
3182 lvc
.pszText
= msi_dialog_get_uitext( dialog
, column_keys
[count
] );
3184 SendMessageW( control
->hwnd
, LVM_INSERTCOLUMNW
, count
++, (LPARAM
)&lvc
);
3185 msi_free( lvc
.pszText
);
3190 static LONGLONG
msi_vcl_get_cost( msi_dialog
*dialog
)
3192 MSIFEATURE
*feature
;
3194 LONGLONG total_cost
= 0;
3196 LIST_FOR_EACH_ENTRY( feature
, &dialog
->package
->features
, MSIFEATURE
, entry
)
3198 if (ERROR_SUCCESS
== (MSI_GetFeatureCost(dialog
->package
, feature
,
3199 MSICOSTTREE_SELFONLY
, INSTALLSTATE_LOCAL
, &each_cost
)))
3201 /* each_cost is in 512-byte units */
3202 total_cost
+= each_cost
* 512;
3204 if (ERROR_SUCCESS
== (MSI_GetFeatureCost(dialog
->package
, feature
,
3205 MSICOSTTREE_SELFONLY
, INSTALLSTATE_ABSENT
, &each_cost
)))
3207 /* each_cost is in 512-byte units */
3208 total_cost
-= each_cost
* 512;
3214 static void msi_dialog_vcl_add_drives( msi_dialog
*dialog
, msi_control
*control
)
3216 ULARGE_INTEGER total
, free
;
3217 LONGLONG difference
, cost
;
3218 WCHAR size_text
[MAX_PATH
];
3219 WCHAR cost_text
[MAX_PATH
];
3225 cost
= msi_vcl_get_cost(dialog
);
3226 StrFormatByteSizeW(cost
, cost_text
, MAX_PATH
);
3228 size
= GetLogicalDriveStringsW( 0, NULL
);
3229 if ( !size
) return;
3231 drives
= msi_alloc( (size
+ 1) * sizeof(WCHAR
) );
3232 if ( !drives
) return;
3234 GetLogicalDriveStringsW( size
, drives
);
3239 lvitem
.mask
= LVIF_TEXT
;
3241 lvitem
.iSubItem
= 0;
3242 lvitem
.pszText
= ptr
;
3243 lvitem
.cchTextMax
= lstrlenW(ptr
) + 1;
3244 SendMessageW( control
->hwnd
, LVM_INSERTITEMW
, 0, (LPARAM
)&lvitem
);
3246 GetDiskFreeSpaceExW(ptr
, &free
, &total
, NULL
);
3247 difference
= free
.QuadPart
- cost
;
3249 StrFormatByteSizeW(total
.QuadPart
, size_text
, MAX_PATH
);
3250 lvitem
.iSubItem
= 1;
3251 lvitem
.pszText
= size_text
;
3252 lvitem
.cchTextMax
= lstrlenW(size_text
) + 1;
3253 SendMessageW( control
->hwnd
, LVM_SETITEMW
, 0, (LPARAM
)&lvitem
);
3255 StrFormatByteSizeW(free
.QuadPart
, size_text
, MAX_PATH
);
3256 lvitem
.iSubItem
= 2;
3257 lvitem
.pszText
= size_text
;
3258 lvitem
.cchTextMax
= lstrlenW(size_text
) + 1;
3259 SendMessageW( control
->hwnd
, LVM_SETITEMW
, 0, (LPARAM
)&lvitem
);
3261 lvitem
.iSubItem
= 3;
3262 lvitem
.pszText
= cost_text
;
3263 lvitem
.cchTextMax
= lstrlenW(cost_text
) + 1;
3264 SendMessageW( control
->hwnd
, LVM_SETITEMW
, 0, (LPARAM
)&lvitem
);
3266 StrFormatByteSizeW(difference
, size_text
, MAX_PATH
);
3267 lvitem
.iSubItem
= 4;
3268 lvitem
.pszText
= size_text
;
3269 lvitem
.cchTextMax
= lstrlenW(size_text
) + 1;
3270 SendMessageW( control
->hwnd
, LVM_SETITEMW
, 0, (LPARAM
)&lvitem
);
3272 ptr
+= lstrlenW(ptr
) + 1;
3279 static UINT
msi_dialog_volumecost_list( msi_dialog
*dialog
, MSIRECORD
*rec
)
3281 msi_control
*control
;
3284 style
= LVS_REPORT
| WS_VSCROLL
| WS_HSCROLL
| LVS_SHAREIMAGELISTS
|
3285 LVS_AUTOARRANGE
| LVS_SINGLESEL
| WS_BORDER
|
3286 WS_CHILD
| WS_TABSTOP
| WS_GROUP
;
3287 control
= msi_dialog_add_control( dialog
, rec
, WC_LISTVIEWW
, style
);
3289 return ERROR_FUNCTION_FAILED
;
3291 msi_dialog_vcl_add_columns( dialog
, control
, rec
);
3292 msi_dialog_vcl_add_drives( dialog
, control
);
3294 return ERROR_SUCCESS
;
3297 /******************** VolumeSelect Combo ***************************************/
3299 static UINT
msi_dialog_volsel_handler( msi_dialog
*dialog
,
3300 msi_control
*control
, WPARAM param
)
3302 WCHAR text
[MAX_PATH
];
3307 if (HIWORD(param
) != CBN_SELCHANGE
)
3308 return ERROR_SUCCESS
;
3310 index
= SendMessageW( control
->hwnd
, CB_GETCURSEL
, 0, 0 );
3311 if ( index
== CB_ERR
)
3313 ERR("No ComboBox item selected!\n");
3314 return ERROR_FUNCTION_FAILED
;
3317 SendMessageW( control
->hwnd
, CB_GETLBTEXT
, index
, (LPARAM
)text
);
3319 indirect
= control
->attributes
& msidbControlAttributesIndirect
;
3320 prop
= msi_dialog_dup_property( dialog
, control
->property
, indirect
);
3322 msi_dialog_set_property( dialog
->package
, prop
, text
);
3325 return ERROR_SUCCESS
;
3328 static void msi_dialog_vsc_add_drives( msi_dialog
*dialog
, msi_control
*control
)
3333 size
= GetLogicalDriveStringsW( 0, NULL
);
3334 if ( !size
) return;
3336 drives
= msi_alloc( (size
+ 1) * sizeof(WCHAR
) );
3337 if ( !drives
) return;
3339 GetLogicalDriveStringsW( size
, drives
);
3344 SendMessageW( control
->hwnd
, CB_ADDSTRING
, 0, (LPARAM
)ptr
);
3345 ptr
+= lstrlenW(ptr
) + 1;
3351 static UINT
msi_dialog_volumeselect_combo( msi_dialog
*dialog
, MSIRECORD
*rec
)
3353 msi_control
*control
;
3357 /* FIXME: CBS_OWNERDRAWFIXED */
3358 style
= WS_CHILD
| WS_VISIBLE
| WS_GROUP
| WS_TABSTOP
|
3359 CBS_DROPDOWNLIST
| CBS_SORT
| CBS_HASSTRINGS
|
3360 WS_EX_LEFT
| WS_EX_LTRREADING
| WS_EX_RIGHTSCROLLBAR
;
3361 control
= msi_dialog_add_control( dialog
, rec
, WC_COMBOBOXW
, style
);
3363 return ERROR_FUNCTION_FAILED
;
3365 control
->attributes
= MSI_RecordGetInteger( rec
, 8 );
3366 control
->handler
= msi_dialog_volsel_handler
;
3367 prop
= MSI_RecordGetString( rec
, 9 );
3368 control
->property
= msi_dialog_dup_property( dialog
, prop
, FALSE
);
3370 msi_dialog_vsc_add_drives( dialog
, control
);
3372 return ERROR_SUCCESS
;
3375 static UINT
msi_dialog_hyperlink_handler( msi_dialog
*dialog
, msi_control
*control
, WPARAM param
)
3377 static const WCHAR hrefW
[] = {'h','r','e','f'};
3378 static const WCHAR openW
[] = {'o','p','e','n',0};
3379 int len
, len_href
= sizeof(hrefW
) / sizeof(hrefW
[0]);
3384 item
.mask
= LIF_ITEMINDEX
| LIF_URL
;
3388 SendMessageW( control
->hwnd
, LM_GETITEM
, 0, (LPARAM
)&item
);
3391 while (*p
&& *p
!= '<') p
++;
3392 if (!*p
++) return ERROR_SUCCESS
;
3393 if (toupperW( *p
++ ) != 'A' || !isspaceW( *p
++ )) return ERROR_SUCCESS
;
3394 while (*p
&& isspaceW( *p
)) p
++;
3397 if (len
> len_href
&& !memicmpW( p
, hrefW
, len_href
))
3400 while (*p
&& isspaceW( *p
)) p
++;
3401 if (!*p
|| *p
++ != '=') return ERROR_SUCCESS
;
3402 while (*p
&& isspaceW( *p
)) p
++;
3404 if (*p
== '\"' || *p
== '\'') quote
= *p
++;
3408 while (*q
&& *q
!= quote
) q
++;
3409 if (*q
!= quote
) return ERROR_SUCCESS
;
3413 while (*q
&& *q
!= '>' && !isspaceW( *q
)) q
++;
3414 if (!*q
) return ERROR_SUCCESS
;
3416 item
.szUrl
[q
- item
.szUrl
] = 0;
3417 ShellExecuteW( NULL
, openW
, p
, NULL
, NULL
, SW_SHOWNORMAL
);
3419 return ERROR_SUCCESS
;
3422 static UINT
msi_dialog_hyperlink( msi_dialog
*dialog
, MSIRECORD
*rec
)
3424 msi_control
*control
;
3425 DWORD style
= WS_CHILD
| WS_TABSTOP
| WS_GROUP
;
3426 const WCHAR
*text
= MSI_RecordGetString( rec
, 10 );
3427 int len
= strlenW( text
);
3430 control
= msi_dialog_add_control( dialog
, rec
, WC_LINK
, style
);
3432 return ERROR_FUNCTION_FAILED
;
3434 control
->attributes
= MSI_RecordGetInteger( rec
, 8 );
3435 control
->handler
= msi_dialog_hyperlink_handler
;
3437 item
.mask
= LIF_ITEMINDEX
| LIF_STATE
| LIF_URL
;
3439 item
.state
= LIS_ENABLED
;
3440 item
.stateMask
= LIS_ENABLED
;
3441 if (len
< L_MAX_URL_LENGTH
) strcpyW( item
.szUrl
, text
);
3442 else item
.szUrl
[0] = 0;
3444 SendMessageW( control
->hwnd
, LM_SETITEM
, 0, (LPARAM
)&item
);
3446 return ERROR_SUCCESS
;
3449 static const struct control_handler msi_dialog_handler
[] =
3451 { szText
, msi_dialog_text_control
},
3452 { szPushButton
, msi_dialog_button_control
},
3453 { szLine
, msi_dialog_line_control
},
3454 { szBitmap
, msi_dialog_bitmap_control
},
3455 { szCheckBox
, msi_dialog_checkbox_control
},
3456 { szScrollableText
, msi_dialog_scrolltext_control
},
3457 { szComboBox
, msi_dialog_combo_control
},
3458 { szEdit
, msi_dialog_edit_control
},
3459 { szMaskedEdit
, msi_dialog_maskedit_control
},
3460 { szPathEdit
, msi_dialog_pathedit_control
},
3461 { szProgressBar
, msi_dialog_progress_bar
},
3462 { szRadioButtonGroup
, msi_dialog_radiogroup_control
},
3463 { szIcon
, msi_dialog_icon_control
},
3464 { szSelectionTree
, msi_dialog_selection_tree
},
3465 { szGroupBox
, msi_dialog_group_box
},
3466 { szListBox
, msi_dialog_list_box
},
3467 { szDirectoryCombo
, msi_dialog_directory_combo
},
3468 { szDirectoryList
, msi_dialog_directory_list
},
3469 { szVolumeCostList
, msi_dialog_volumecost_list
},
3470 { szVolumeSelectCombo
, msi_dialog_volumeselect_combo
},
3471 { szHyperLink
, msi_dialog_hyperlink
}
3474 #define NUM_CONTROL_TYPES (sizeof msi_dialog_handler/sizeof msi_dialog_handler[0])
3476 static UINT
msi_dialog_create_controls( MSIRECORD
*rec
, LPVOID param
)
3478 msi_dialog
*dialog
= param
;
3479 LPCWSTR control_type
;
3482 /* find and call the function that can create this type of control */
3483 control_type
= MSI_RecordGetString( rec
, 3 );
3484 for( i
=0; i
<NUM_CONTROL_TYPES
; i
++ )
3485 if (!strcmpiW( msi_dialog_handler
[i
].control_type
, control_type
))
3487 if( i
!= NUM_CONTROL_TYPES
)
3488 msi_dialog_handler
[i
].func( dialog
, rec
);
3490 ERR("no handler for element type %s\n", debugstr_w(control_type
));
3492 return ERROR_SUCCESS
;
3495 static UINT
msi_dialog_fill_controls( msi_dialog
*dialog
)
3497 static const WCHAR query
[] = {
3498 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
3499 'C','o','n','t','r','o','l',' ','W','H','E','R','E',' ',
3500 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',0};
3503 MSIPACKAGE
*package
= dialog
->package
;
3505 TRACE("%p %s\n", dialog
, debugstr_w(dialog
->name
) );
3507 /* query the Control table for all the elements of the control */
3508 r
= MSI_OpenQuery( package
->db
, &view
, query
, dialog
->name
);
3509 if( r
!= ERROR_SUCCESS
)
3511 ERR("query failed for dialog %s\n", debugstr_w(dialog
->name
));
3512 return ERROR_INVALID_PARAMETER
;
3515 r
= MSI_IterateRecords( view
, 0, msi_dialog_create_controls
, dialog
);
3516 msiobj_release( &view
->hdr
);
3520 static UINT
msi_dialog_reset( msi_dialog
*dialog
)
3522 /* FIXME: should restore the original values of any properties we changed */
3523 return msi_dialog_evaluate_control_conditions( dialog
);
3526 /* figure out the height of 10 point MS Sans Serif */
3527 static INT
msi_dialog_get_sans_serif_height( HWND hwnd
)
3529 static const WCHAR szSansSerif
[] = {
3530 'M','S',' ','S','a','n','s',' ','S','e','r','i','f',0 };
3535 HFONT hFont
, hOldFont
;
3538 hdc
= GetDC( hwnd
);
3541 memset( &lf
, 0, sizeof lf
);
3542 lf
.lfHeight
= MulDiv(12, GetDeviceCaps(hdc
, LOGPIXELSY
), 72);
3543 strcpyW( lf
.lfFaceName
, szSansSerif
);
3544 hFont
= CreateFontIndirectW(&lf
);
3547 hOldFont
= SelectObject( hdc
, hFont
);
3548 r
= GetTextMetricsW( hdc
, &tm
);
3550 height
= tm
.tmHeight
;
3551 SelectObject( hdc
, hOldFont
);
3552 DeleteObject( hFont
);
3554 ReleaseDC( hwnd
, hdc
);
3559 /* fetch the associated record from the Dialog table */
3560 static MSIRECORD
*msi_get_dialog_record( msi_dialog
*dialog
)
3562 static const WCHAR query
[] = {
3563 'S','E','L','E','C','T',' ','*',' ',
3564 'F','R','O','M',' ','D','i','a','l','o','g',' ',
3565 'W','H','E','R','E',' ',
3566 '`','D','i','a','l','o','g','`',' ','=',' ','\'','%','s','\'',0};
3567 MSIPACKAGE
*package
= dialog
->package
;
3568 MSIRECORD
*rec
= NULL
;
3570 TRACE("%p %s\n", dialog
, debugstr_w(dialog
->name
) );
3572 rec
= MSI_QueryGetRecord( package
->db
, query
, dialog
->name
);
3574 WARN("query failed for dialog %s\n", debugstr_w(dialog
->name
));
3579 static void msi_dialog_adjust_dialog_pos( msi_dialog
*dialog
, MSIRECORD
*rec
, LPRECT pos
)
3581 static const WCHAR szScreenX
[] = {'S','c','r','e','e','n','X',0};
3582 static const WCHAR szScreenY
[] = {'S','c','r','e','e','n','Y',0};
3589 center
.x
= MSI_RecordGetInteger( rec
, 2 );
3590 center
.y
= MSI_RecordGetInteger( rec
, 3 );
3592 sz
.cx
= MSI_RecordGetInteger( rec
, 4 );
3593 sz
.cy
= MSI_RecordGetInteger( rec
, 5 );
3595 sz
.cx
= msi_dialog_scale_unit( dialog
, sz
.cx
);
3596 sz
.cy
= msi_dialog_scale_unit( dialog
, sz
.cy
);
3598 xres
= msi_get_property_int( dialog
->package
->db
, szScreenX
, 0 );
3599 yres
= msi_get_property_int( dialog
->package
->db
, szScreenY
, 0 );
3601 center
.x
= MulDiv( center
.x
, xres
, 100 );
3602 center
.y
= MulDiv( center
.y
, yres
, 100 );
3604 /* turn the client pos into the window rectangle */
3605 if (dialog
->package
->center_x
&& dialog
->package
->center_y
)
3607 pos
->left
= dialog
->package
->center_x
- sz
.cx
/ 2.0;
3608 pos
->right
= pos
->left
+ sz
.cx
;
3609 pos
->top
= dialog
->package
->center_y
- sz
.cy
/ 2.0;
3610 pos
->bottom
= pos
->top
+ sz
.cy
;
3614 pos
->left
= center
.x
- sz
.cx
/2;
3615 pos
->right
= pos
->left
+ sz
.cx
;
3616 pos
->top
= center
.y
- sz
.cy
/2;
3617 pos
->bottom
= pos
->top
+ sz
.cy
;
3619 /* save the center */
3620 dialog
->package
->center_x
= center
.x
;
3621 dialog
->package
->center_y
= center
.y
;
3624 dialog
->size
.cx
= sz
.cx
;
3625 dialog
->size
.cy
= sz
.cy
;
3627 TRACE("%u %u %u %u\n", pos
->left
, pos
->top
, pos
->right
, pos
->bottom
);
3629 style
= GetWindowLongPtrW( dialog
->hwnd
, GWL_STYLE
);
3630 AdjustWindowRect( pos
, style
, FALSE
);
3633 static void msi_dialog_set_tab_order( msi_dialog
*dialog
, LPCWSTR first
)
3635 struct list tab_chain
;
3636 msi_control
*control
;
3637 HWND prev
= HWND_TOP
;
3639 list_init( &tab_chain
);
3640 if (!(control
= msi_dialog_find_control( dialog
, first
))) return;
3642 dialog
->hWndFocus
= control
->hwnd
;
3645 list_remove( &control
->entry
);
3646 list_add_tail( &tab_chain
, &control
->entry
);
3647 if (!control
->tabnext
) break;
3648 control
= msi_dialog_find_control( dialog
, control
->tabnext
);
3651 LIST_FOR_EACH_ENTRY( control
, &tab_chain
, msi_control
, entry
)
3653 SetWindowPos( control
->hwnd
, prev
, 0, 0, 0, 0,
3654 SWP_NOMOVE
| SWP_NOOWNERZORDER
| SWP_NOREDRAW
|
3655 SWP_NOREPOSITION
| SWP_NOSENDCHANGING
| SWP_NOSIZE
);
3656 prev
= control
->hwnd
;
3659 /* put them back on the main list */
3660 list_move_head( &dialog
->controls
, &tab_chain
);
3663 static LRESULT
msi_dialog_oncreate( HWND hwnd
, LPCREATESTRUCTW cs
)
3665 static const WCHAR df
[] = {
3666 'D','e','f','a','u','l','t','U','I','F','o','n','t',0 };
3667 static const WCHAR dfv
[] = {
3668 'M','S',' ','S','h','e','l','l',' ','D','l','g',0 };
3669 msi_dialog
*dialog
= cs
->lpCreateParams
;
3670 MSIRECORD
*rec
= NULL
;
3671 LPWSTR title
= NULL
;
3674 TRACE("%p %p\n", dialog
, dialog
->package
);
3676 dialog
->hwnd
= hwnd
;
3677 SetWindowLongPtrW( hwnd
, GWLP_USERDATA
, (LONG_PTR
) dialog
);
3679 rec
= msi_get_dialog_record( dialog
);
3682 TRACE("No record found for dialog %s\n", debugstr_w(dialog
->name
));
3686 dialog
->scale
= msi_dialog_get_sans_serif_height(dialog
->hwnd
);
3688 msi_dialog_adjust_dialog_pos( dialog
, rec
, &pos
);
3690 dialog
->attributes
= MSI_RecordGetInteger( rec
, 6 );
3692 dialog
->default_font
= msi_dup_property( dialog
->package
->db
, df
);
3693 if (!dialog
->default_font
)
3695 dialog
->default_font
= strdupW(dfv
);
3696 msiobj_release( &rec
->hdr
);
3697 if (!dialog
->default_font
) return -1;
3700 title
= msi_get_deformatted_field( dialog
->package
, rec
, 7 );
3701 SetWindowTextW( hwnd
, title
);
3704 SetWindowPos( hwnd
, 0, pos
.left
, pos
.top
,
3705 pos
.right
- pos
.left
, pos
.bottom
- pos
.top
,
3706 SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_NOREDRAW
);
3708 msi_dialog_build_font_list( dialog
);
3709 msi_dialog_fill_controls( dialog
);
3710 msi_dialog_evaluate_control_conditions( dialog
);
3711 msi_dialog_set_tab_order( dialog
, MSI_RecordGetString( rec
, 8 ) );
3712 msiobj_release( &rec
->hdr
);
3717 static LRESULT
msi_dialog_oncommand( msi_dialog
*dialog
, WPARAM param
, HWND hwnd
)
3719 msi_control
*control
= NULL
;
3721 TRACE("%p %p %08lx\n", dialog
, hwnd
, param
);
3726 control
= msi_dialog_find_control( dialog
, dialog
->control_default
);
3728 case 2: /* escape */
3729 control
= msi_dialog_find_control( dialog
, dialog
->control_cancel
);
3732 control
= msi_dialog_find_control_by_hwnd( dialog
, hwnd
);
3737 if( control
->handler
)
3739 control
->handler( dialog
, control
, param
);
3740 msi_dialog_evaluate_control_conditions( dialog
);
3747 static LRESULT
msi_dialog_onnotify( msi_dialog
*dialog
, LPARAM param
)
3749 LPNMHDR nmhdr
= (LPNMHDR
) param
;
3750 msi_control
*control
= msi_dialog_find_control_by_hwnd( dialog
, nmhdr
->hwndFrom
);
3752 TRACE("%p %p\n", dialog
, nmhdr
->hwndFrom
);
3754 if ( control
&& control
->handler
)
3755 control
->handler( dialog
, control
, param
);
3760 static void dialog_setfocus( msi_dialog
*dialog
)
3762 HWND hwnd
= dialog
->hWndFocus
;
3764 hwnd
= GetNextDlgTabItem( dialog
->hwnd
, hwnd
, TRUE
);
3765 hwnd
= GetNextDlgTabItem( dialog
->hwnd
, hwnd
, FALSE
);
3767 dialog
->hWndFocus
= hwnd
;
3770 static LRESULT WINAPI
MSIDialog_WndProc( HWND hwnd
, UINT msg
,
3771 WPARAM wParam
, LPARAM lParam
)
3773 msi_dialog
*dialog
= (LPVOID
) GetWindowLongPtrW( hwnd
, GWLP_USERDATA
);
3775 TRACE("0x%04x\n", msg
);
3780 dialog
->package
->center_x
= LOWORD(lParam
) + dialog
->size
.cx
/ 2.0;
3781 dialog
->package
->center_y
= HIWORD(lParam
) + dialog
->size
.cy
/ 2.0;
3785 return msi_dialog_oncreate( hwnd
, (LPCREATESTRUCTW
)lParam
);
3788 return msi_dialog_oncommand( dialog
, wParam
, (HWND
)lParam
);
3791 if( LOWORD(wParam
) == WA_INACTIVE
)
3792 dialog
->hWndFocus
= GetFocus();
3794 dialog_setfocus( dialog
);
3798 dialog_setfocus( dialog
);
3801 /* bounce back to our subclassed static control */
3802 case WM_CTLCOLORSTATIC
:
3803 return SendMessageW( (HWND
) lParam
, WM_CTLCOLORSTATIC
, wParam
, lParam
);
3806 dialog
->hwnd
= NULL
;
3809 return msi_dialog_onnotify( dialog
, lParam
);
3811 return DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
3814 static void process_pending_messages( HWND hdlg
)
3818 while (PeekMessageW( &msg
, 0, 0, 0, PM_REMOVE
))
3820 if (hdlg
&& IsDialogMessageW( hdlg
, &msg
)) continue;
3821 TranslateMessage( &msg
);
3822 DispatchMessageW( &msg
);
3826 static UINT
dialog_run_message_loop( msi_dialog
*dialog
)
3831 if( uiThreadId
!= GetCurrentThreadId() )
3832 return SendMessageW( hMsiHiddenWindow
, WM_MSI_DIALOG_CREATE
, 0, (LPARAM
) dialog
);
3834 /* create the dialog window, don't show it yet */
3835 style
= WS_OVERLAPPED
;
3836 if( dialog
->attributes
& msidbDialogAttributesVisible
)
3837 style
|= WS_VISIBLE
;
3839 hwnd
= CreateWindowW( szMsiDialogClass
, dialog
->name
, style
,
3840 CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
,
3841 NULL
, NULL
, NULL
, dialog
);
3844 ERR("Failed to create dialog %s\n", debugstr_w( dialog
->name
));
3845 return ERROR_FUNCTION_FAILED
;
3848 ShowWindow( hwnd
, SW_SHOW
);
3849 /* UpdateWindow( hwnd ); - and causes the transparent static controls not to paint */
3851 if( dialog
->attributes
& msidbDialogAttributesModal
)
3853 while( !dialog
->finished
)
3855 MsgWaitForMultipleObjects( 0, NULL
, 0, INFINITE
, QS_ALLINPUT
);
3856 process_pending_messages( dialog
->hwnd
);
3860 return ERROR_IO_PENDING
;
3862 return ERROR_SUCCESS
;
3865 static LRESULT WINAPI
MSIHiddenWindowProc( HWND hwnd
, UINT msg
,
3866 WPARAM wParam
, LPARAM lParam
)
3868 msi_dialog
*dialog
= (msi_dialog
*) lParam
;
3870 TRACE("%d %p\n", msg
, dialog
);
3874 case WM_MSI_DIALOG_CREATE
:
3875 return dialog_run_message_loop( dialog
);
3876 case WM_MSI_DIALOG_DESTROY
:
3877 msi_dialog_destroy( dialog
);
3880 return DefWindowProcW( hwnd
, msg
, wParam
, lParam
);
3883 static BOOL
dialog_register_class( void )
3887 ZeroMemory( &cls
, sizeof cls
);
3888 cls
.lpfnWndProc
= MSIDialog_WndProc
;
3889 cls
.hInstance
= NULL
;
3890 cls
.hIcon
= LoadIconW(0, (LPWSTR
)IDI_APPLICATION
);
3891 cls
.hCursor
= LoadCursorW(0, (LPWSTR
)IDC_ARROW
);
3892 cls
.hbrBackground
= (HBRUSH
)(COLOR_3DFACE
+ 1);
3893 cls
.lpszMenuName
= NULL
;
3894 cls
.lpszClassName
= szMsiDialogClass
;
3896 if( !RegisterClassW( &cls
) )
3899 cls
.lpfnWndProc
= MSIHiddenWindowProc
;
3900 cls
.lpszClassName
= szMsiHiddenWindow
;
3902 if( !RegisterClassW( &cls
) )
3905 uiThreadId
= GetCurrentThreadId();
3907 hMsiHiddenWindow
= CreateWindowW( szMsiHiddenWindow
, NULL
, WS_OVERLAPPED
,
3908 0, 0, 100, 100, NULL
, NULL
, NULL
, NULL
);
3909 if( !hMsiHiddenWindow
)
3915 static msi_dialog
*dialog_create( MSIPACKAGE
*package
, const WCHAR
*name
, msi_dialog
*parent
,
3916 control_event_handler event_handler
)
3918 MSIRECORD
*rec
= NULL
;
3921 TRACE("%s\n", debugstr_w(name
));
3923 if (!hMsiHiddenWindow
) dialog_register_class();
3925 /* allocate the structure for the dialog to use */
3926 dialog
= msi_alloc_zero( FIELD_OFFSET( msi_dialog
, name
[strlenW( name
) + 1] ));
3929 strcpyW( dialog
->name
, name
);
3930 dialog
->parent
= parent
;
3931 msiobj_addref( &package
->hdr
);
3932 dialog
->package
= package
;
3933 dialog
->event_handler
= event_handler
;
3934 dialog
->finished
= 0;
3935 list_init( &dialog
->controls
);
3936 list_init( &dialog
->fonts
);
3938 /* verify that the dialog exists */
3939 rec
= msi_get_dialog_record( dialog
);
3942 msiobj_release( &package
->hdr
);
3946 dialog
->attributes
= MSI_RecordGetInteger( rec
, 6 );
3947 dialog
->control_default
= strdupW( MSI_RecordGetString( rec
, 9 ) );
3948 dialog
->control_cancel
= strdupW( MSI_RecordGetString( rec
, 10 ) );
3949 msiobj_release( &rec
->hdr
);
3954 static void msi_dialog_end_dialog( msi_dialog
*dialog
)
3956 TRACE("%p\n", dialog
);
3957 dialog
->finished
= 1;
3958 PostMessageW(dialog
->hwnd
, WM_NULL
, 0, 0);
3961 void msi_dialog_check_messages( HANDLE handle
)
3965 /* in threads other than the UI thread, block */
3966 if( uiThreadId
!= GetCurrentThreadId() )
3968 if (!handle
) return;
3969 while (MsgWaitForMultipleObjectsEx( 1, &handle
, INFINITE
, QS_ALLINPUT
, 0 ) == WAIT_OBJECT_0
+ 1)
3972 while (PeekMessageW( &msg
, NULL
, 0, 0, PM_REMOVE
))
3974 TranslateMessage( &msg
);
3975 DispatchMessageW( &msg
);
3981 /* there are two choices for the UI thread */
3984 process_pending_messages( NULL
);
3990 * block here until somebody creates a new dialog or
3991 * the handle we're waiting on becomes ready
3993 r
= MsgWaitForMultipleObjects( 1, &handle
, 0, INFINITE
, QS_ALLINPUT
);
3994 if( r
== WAIT_OBJECT_0
)
3999 static void dialog_do_preview( msi_dialog
*dialog
)
4002 dialog
->attributes
|= msidbDialogAttributesVisible
;
4003 dialog
->attributes
&= ~msidbDialogAttributesModal
;
4004 dialog_run_message_loop( dialog
);
4007 static void free_subscriber( struct subscriber
*sub
)
4009 msi_free( sub
->event
);
4010 msi_free( sub
->control
);
4011 msi_free( sub
->attribute
);
4015 static void event_cleanup_subscriptions( MSIPACKAGE
*package
, const WCHAR
*dialog
)
4017 struct list
*item
, *next
;
4019 LIST_FOR_EACH_SAFE( item
, next
, &package
->subscriptions
)
4021 struct subscriber
*sub
= LIST_ENTRY( item
, struct subscriber
, entry
);
4023 if (strcmpW( sub
->dialog
->name
, dialog
)) continue;
4024 list_remove( &sub
->entry
);
4025 free_subscriber( sub
);
4029 void msi_dialog_destroy( msi_dialog
*dialog
)
4031 msi_font
*font
, *next
;
4033 if( uiThreadId
!= GetCurrentThreadId() )
4035 SendMessageW( hMsiHiddenWindow
, WM_MSI_DIALOG_DESTROY
, 0, (LPARAM
) dialog
);
4040 ShowWindow( dialog
->hwnd
, SW_HIDE
);
4043 DestroyWindow( dialog
->hwnd
);
4045 /* unsubscribe events */
4046 event_cleanup_subscriptions( dialog
->package
, dialog
->name
);
4048 /* destroy the list of controls */
4049 while( !list_empty( &dialog
->controls
) )
4053 t
= LIST_ENTRY( list_head( &dialog
->controls
),
4054 msi_control
, entry
);
4055 msi_destroy_control( t
);
4058 /* destroy the list of fonts */
4059 LIST_FOR_EACH_ENTRY_SAFE( font
, next
, &dialog
->fonts
, msi_font
, entry
)
4061 list_remove( &font
->entry
);
4062 DeleteObject( font
->hfont
);
4065 msi_free( dialog
->default_font
);
4067 msi_free( dialog
->control_default
);
4068 msi_free( dialog
->control_cancel
);
4069 msiobj_release( &dialog
->package
->hdr
);
4070 dialog
->package
= NULL
;
4074 void msi_dialog_unregister_class( void )
4076 DestroyWindow( hMsiHiddenWindow
);
4077 hMsiHiddenWindow
= NULL
;
4078 UnregisterClassW( szMsiDialogClass
, NULL
);
4079 UnregisterClassW( szMsiHiddenWindow
, NULL
);
4083 void msi_event_cleanup_all_subscriptions( MSIPACKAGE
*package
)
4085 struct list
*item
, *next
;
4087 LIST_FOR_EACH_SAFE( item
, next
, &package
->subscriptions
)
4089 struct subscriber
*sub
= LIST_ENTRY( item
, struct subscriber
, entry
);
4090 list_remove( &sub
->entry
);
4091 free_subscriber( sub
);
4095 static UINT
error_dialog_handler( msi_dialog
*dialog
, const WCHAR
*event
, const WCHAR
*argument
)
4097 static const WCHAR end_dialog
[] = {'E','n','d','D','i','a','l','o','g',0};
4098 static const WCHAR error_abort
[] = {'E','r','r','o','r','A','b','o','r','t',0};
4099 static const WCHAR error_cancel
[] = {'E','r','r','o','r','C','a','n','c','e','l',0};
4100 static const WCHAR error_no
[] = {'E','r','r','o','r','N','o',0};
4101 static const WCHAR result_prop
[] = {
4102 'M','S','I','E','r','r','o','r','D','i','a','l','o','g','R','e','s','u','l','t',0
4105 if ( strcmpW( event
, end_dialog
) )
4106 return ERROR_SUCCESS
;
4108 if ( !strcmpW( argument
, error_abort
) || !strcmpW( argument
, error_cancel
) ||
4109 !strcmpW( argument
, error_no
) )
4111 msi_set_property( dialog
->package
->db
, result_prop
, error_abort
, -1 );
4114 msi_event_cleanup_all_subscriptions( dialog
->package
);
4115 msi_dialog_end_dialog( dialog
);
4117 return ERROR_SUCCESS
;
4120 static UINT
msi_error_dialog_set_error( MSIPACKAGE
*package
, LPWSTR error_dialog
, LPWSTR error
)
4124 static const WCHAR update
[] =
4125 {'U','P','D','A','T','E',' ','`','C','o','n','t','r','o','l','`',' ',
4126 'S','E','T',' ','`','T','e','x','t','`',' ','=',' ','\'','%','s','\'',' ',
4127 'W','H','E','R','E', ' ','`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',' ',
4128 'A','N','D',' ','`','C','o','n','t','r','o','l','`',' ','=',' ',
4129 '\'','E','r','r','o','r','T','e','x','t','\'',0};
4131 row
= MSI_QueryGetRecord( package
->db
, update
, error
, error_dialog
);
4133 return ERROR_FUNCTION_FAILED
;
4135 msiobj_release(&row
->hdr
);
4136 return ERROR_SUCCESS
;
4139 UINT
msi_spawn_error_dialog( MSIPACKAGE
*package
, LPWSTR error_dialog
, LPWSTR error
)
4142 WCHAR result
[MAX_PATH
];
4143 UINT r
= ERROR_SUCCESS
;
4144 DWORD size
= MAX_PATH
;
4147 static const WCHAR pn_prop
[] = {'P','r','o','d','u','c','t','N','a','m','e',0};
4148 static const WCHAR title_fmt
[] = {'%','s',' ','W','a','r','n','i','n','g',0};
4149 static const WCHAR error_abort
[] = {'E','r','r','o','r','A','b','o','r','t',0};
4150 static const WCHAR result_prop
[] = {
4151 'M','S','I','E','r','r','o','r','D','i','a','l','o','g','R','e','s','u','l','t',0
4154 if ((package
->ui_level
& INSTALLUILEVEL_MASK
) == INSTALLUILEVEL_NONE
) return ERROR_SUCCESS
;
4156 if ( !error_dialog
)
4158 LPWSTR product_name
= msi_dup_property( package
->db
, pn_prop
);
4159 WCHAR title
[MAX_PATH
];
4161 sprintfW( title
, title_fmt
, product_name
);
4162 res
= MessageBoxW( NULL
, error
, title
, MB_OKCANCEL
| MB_ICONWARNING
);
4164 msi_free( product_name
);
4167 return ERROR_SUCCESS
;
4169 return ERROR_FUNCTION_FAILED
;
4172 r
= msi_error_dialog_set_error( package
, error_dialog
, error
);
4173 if ( r
!= ERROR_SUCCESS
)
4176 dialog
= dialog_create( package
, error_dialog
, package
->dialog
, error_dialog_handler
);
4178 return ERROR_FUNCTION_FAILED
;
4180 dialog
->finished
= FALSE
;
4181 r
= dialog_run_message_loop( dialog
);
4182 if ( r
!= ERROR_SUCCESS
)
4185 r
= msi_get_property( package
->db
, result_prop
, result
, &size
);
4186 if ( r
!= ERROR_SUCCESS
)
4189 if ( !strcmpW( result
, error_abort
) )
4190 r
= ERROR_FUNCTION_FAILED
;
4193 msi_dialog_destroy( dialog
);
4198 static void MSI_ClosePreview( MSIOBJECTHDR
*arg
)
4200 MSIPREVIEW
*preview
= (MSIPREVIEW
*)arg
;
4201 msiobj_release( &preview
->package
->hdr
);
4204 static MSIPREVIEW
*MSI_EnableUIPreview( MSIDATABASE
*db
)
4206 MSIPREVIEW
*preview
= NULL
;
4207 MSIPACKAGE
*package
;
4209 package
= MSI_CreatePackage( db
, NULL
);
4212 preview
= alloc_msiobject( MSIHANDLETYPE_PREVIEW
, sizeof(MSIPREVIEW
), MSI_ClosePreview
);
4215 preview
->package
= package
;
4216 msiobj_addref( &package
->hdr
);
4218 msiobj_release( &package
->hdr
);
4223 UINT WINAPI
MsiEnableUIPreview( MSIHANDLE hdb
, MSIHANDLE
*phPreview
)
4226 MSIPREVIEW
*preview
;
4227 UINT r
= ERROR_FUNCTION_FAILED
;
4229 TRACE("%d %p\n", hdb
, phPreview
);
4231 db
= msihandle2msiinfo( hdb
, MSIHANDLETYPE_DATABASE
);
4234 IWineMsiRemoteDatabase
*remote_database
;
4236 remote_database
= (IWineMsiRemoteDatabase
*)msi_get_remote( hdb
);
4237 if (!remote_database
)
4238 return ERROR_INVALID_HANDLE
;
4242 IWineMsiRemoteDatabase_Release( remote_database
);
4243 WARN("MsiEnableUIPreview not allowed during a custom action!\n");
4245 return ERROR_FUNCTION_FAILED
;
4247 preview
= MSI_EnableUIPreview( db
);
4250 *phPreview
= alloc_msihandle( &preview
->hdr
);
4251 msiobj_release( &preview
->hdr
);
4254 r
= ERROR_NOT_ENOUGH_MEMORY
;
4256 msiobj_release( &db
->hdr
);
4260 static UINT
preview_event_handler( msi_dialog
*dialog
, const WCHAR
*event
, const WCHAR
*argument
)
4262 MESSAGE("Preview dialog event '%s' (arg='%s')\n", debugstr_w(event
), debugstr_w(argument
));
4263 return ERROR_SUCCESS
;
4266 static UINT
MSI_PreviewDialogW( MSIPREVIEW
*preview
, LPCWSTR szDialogName
)
4268 msi_dialog
*dialog
= NULL
;
4269 UINT r
= ERROR_SUCCESS
;
4271 if (preview
->dialog
)
4272 msi_dialog_destroy( preview
->dialog
);
4274 /* an empty name means we should just destroy the current preview dialog */
4277 dialog
= dialog_create( preview
->package
, szDialogName
, NULL
, preview_event_handler
);
4279 dialog_do_preview( dialog
);
4281 r
= ERROR_FUNCTION_FAILED
;
4283 preview
->dialog
= dialog
;
4287 UINT WINAPI
MsiPreviewDialogW( MSIHANDLE hPreview
, LPCWSTR szDialogName
)
4289 MSIPREVIEW
*preview
;
4292 TRACE("%d %s\n", hPreview
, debugstr_w(szDialogName
));
4294 preview
= msihandle2msiinfo( hPreview
, MSIHANDLETYPE_PREVIEW
);
4296 return ERROR_INVALID_HANDLE
;
4298 r
= MSI_PreviewDialogW( preview
, szDialogName
);
4299 msiobj_release( &preview
->hdr
);
4303 UINT WINAPI
MsiPreviewDialogA( MSIHANDLE hPreview
, LPCSTR szDialogName
)
4308 TRACE("%d %s\n", hPreview
, debugstr_a(szDialogName
));
4312 strW
= strdupAtoW( szDialogName
);
4314 return ERROR_OUTOFMEMORY
;
4316 r
= MsiPreviewDialogW( hPreview
, strW
);
4321 UINT WINAPI
MsiPreviewBillboardW( MSIHANDLE hPreview
, LPCWSTR szControlName
, LPCWSTR szBillboard
)
4323 FIXME("%d %s %s\n", hPreview
, debugstr_w(szControlName
), debugstr_w(szBillboard
));
4324 return ERROR_CALL_NOT_IMPLEMENTED
;
4327 UINT WINAPI
MsiPreviewBillboardA( MSIHANDLE hPreview
, LPCSTR szControlName
, LPCSTR szBillboard
)
4329 FIXME("%d %s %s\n", hPreview
, debugstr_a(szControlName
), debugstr_a(szBillboard
));
4330 return ERROR_CALL_NOT_IMPLEMENTED
;
4333 typedef UINT (*event_handler
)( msi_dialog
*, const WCHAR
* );
4335 struct control_event
4338 event_handler handler
;
4341 static UINT
dialog_event_handler( msi_dialog
*, const WCHAR
*, const WCHAR
* );
4343 /* create a dialog box and run it if it's modal */
4344 static UINT
event_do_dialog( MSIPACKAGE
*package
, const WCHAR
*name
, msi_dialog
*parent
, BOOL destroy_modeless
)
4349 /* create a new dialog */
4350 dialog
= dialog_create( package
, name
, parent
, dialog_event_handler
);
4353 /* kill the current modeless dialog */
4354 if (destroy_modeless
&& package
->dialog
)
4356 msi_dialog_destroy( package
->dialog
);
4357 package
->dialog
= NULL
;
4360 /* modeless dialogs return an error message */
4361 r
= dialog_run_message_loop( dialog
);
4362 if (r
== ERROR_SUCCESS
)
4363 msi_dialog_destroy( dialog
);
4365 package
->dialog
= dialog
;
4367 else r
= ERROR_FUNCTION_FAILED
;
4371 /* end a modal dialog box */
4372 static UINT
event_end_dialog( msi_dialog
*dialog
, const WCHAR
*argument
)
4374 static const WCHAR exitW
[] = {'E','x','i','t',0};
4375 static const WCHAR retryW
[] = {'R','e','t','r','y',0};
4376 static const WCHAR ignoreW
[] = {'I','g','n','o','r','e',0};
4377 static const WCHAR returnW
[] = {'R','e','t','u','r','n',0};
4379 if (!strcmpW( argument
, exitW
))
4380 dialog
->package
->CurrentInstallState
= ERROR_INSTALL_USEREXIT
;
4381 else if (!strcmpW( argument
, retryW
))
4382 dialog
->package
->CurrentInstallState
= ERROR_INSTALL_SUSPEND
;
4383 else if (!strcmpW( argument
, ignoreW
))
4384 dialog
->package
->CurrentInstallState
= ERROR_SUCCESS
;
4385 else if (!strcmpW( argument
, returnW
))
4387 msi_dialog
*parent
= dialog
->parent
;
4388 msi_free( dialog
->package
->next_dialog
);
4389 dialog
->package
->next_dialog
= (parent
) ? strdupW( parent
->name
) : NULL
;
4390 dialog
->package
->CurrentInstallState
= ERROR_SUCCESS
;
4394 ERR("Unknown argument string %s\n", debugstr_w(argument
));
4395 dialog
->package
->CurrentInstallState
= ERROR_FUNCTION_FAILED
;
4397 event_cleanup_subscriptions( dialog
->package
, dialog
->name
);
4398 msi_dialog_end_dialog( dialog
);
4399 return ERROR_SUCCESS
;
4402 /* transition from one modal dialog to another modal dialog */
4403 static UINT
event_new_dialog( msi_dialog
*dialog
, const WCHAR
*argument
)
4405 /* store the name of the next dialog, and signal this one to end */
4406 dialog
->package
->next_dialog
= strdupW( argument
);
4407 msi_event_cleanup_all_subscriptions( dialog
->package
);
4408 msi_dialog_end_dialog( dialog
);
4409 return ERROR_SUCCESS
;
4412 /* create a new child dialog of an existing modal dialog */
4413 static UINT
event_spawn_dialog( msi_dialog
*dialog
, const WCHAR
*argument
)
4415 /* don't destroy a modeless dialogs that might be our parent */
4416 event_do_dialog( dialog
->package
, argument
, dialog
, FALSE
);
4417 if (dialog
->package
->CurrentInstallState
!= ERROR_SUCCESS
) msi_dialog_end_dialog( dialog
);
4418 return ERROR_SUCCESS
;
4421 /* creates a dialog that remains up for a period of time based on a condition */
4422 static UINT
event_spawn_wait_dialog( msi_dialog
*dialog
, const WCHAR
*argument
)
4424 FIXME("doing nothing\n");
4425 return ERROR_SUCCESS
;
4428 static UINT
event_do_action( msi_dialog
*dialog
, const WCHAR
*argument
)
4430 ACTION_PerformAction( dialog
->package
, argument
, SCRIPT_NONE
);
4431 return ERROR_SUCCESS
;
4434 static UINT
event_add_local( msi_dialog
*dialog
, const WCHAR
*argument
)
4436 MSIFEATURE
*feature
;
4438 LIST_FOR_EACH_ENTRY( feature
, &dialog
->package
->features
, MSIFEATURE
, entry
)
4440 if (!strcmpW( argument
, feature
->Feature
) || !strcmpW( argument
, szAll
))
4442 if (feature
->ActionRequest
!= INSTALLSTATE_LOCAL
)
4443 msi_set_property( dialog
->package
->db
, szPreselected
, szOne
, -1 );
4444 MSI_SetFeatureStateW( dialog
->package
, feature
->Feature
, INSTALLSTATE_LOCAL
);
4447 return ERROR_SUCCESS
;
4450 static UINT
event_remove( msi_dialog
*dialog
, const WCHAR
*argument
)
4452 MSIFEATURE
*feature
;
4454 LIST_FOR_EACH_ENTRY( feature
, &dialog
->package
->features
, MSIFEATURE
, entry
)
4456 if (!strcmpW( argument
, feature
->Feature
) || !strcmpW( argument
, szAll
))
4458 if (feature
->ActionRequest
!= INSTALLSTATE_ABSENT
)
4459 msi_set_property( dialog
->package
->db
, szPreselected
, szOne
, -1 );
4460 MSI_SetFeatureStateW( dialog
->package
, feature
->Feature
, INSTALLSTATE_ABSENT
);
4463 return ERROR_SUCCESS
;
4466 static UINT
event_add_source( msi_dialog
*dialog
, const WCHAR
*argument
)
4468 MSIFEATURE
*feature
;
4470 LIST_FOR_EACH_ENTRY( feature
, &dialog
->package
->features
, MSIFEATURE
, entry
)
4472 if (!strcmpW( argument
, feature
->Feature
) || !strcmpW( argument
, szAll
))
4474 if (feature
->ActionRequest
!= INSTALLSTATE_SOURCE
)
4475 msi_set_property( dialog
->package
->db
, szPreselected
, szOne
, -1 );
4476 MSI_SetFeatureStateW( dialog
->package
, feature
->Feature
, INSTALLSTATE_SOURCE
);
4479 return ERROR_SUCCESS
;
4482 void msi_event_fire( MSIPACKAGE
*package
, const WCHAR
*event
, MSIRECORD
*rec
)
4484 struct subscriber
*sub
;
4486 TRACE("firing event %s\n", debugstr_w(event
));
4488 LIST_FOR_EACH_ENTRY( sub
, &package
->subscriptions
, struct subscriber
, entry
)
4490 if (strcmpiW( sub
->event
, event
)) continue;
4491 dialog_handle_event( sub
->dialog
, sub
->control
, sub
->attribute
, rec
);
4495 static UINT
event_set_target_path( msi_dialog
*dialog
, const WCHAR
*argument
)
4497 WCHAR
*path
= msi_dup_property( dialog
->package
->db
, argument
);
4498 MSIRECORD
*rec
= MSI_CreateRecord( 1 );
4499 UINT r
= ERROR_SUCCESS
;
4501 MSI_RecordSetStringW( rec
, 1, path
);
4502 msi_event_fire( dialog
->package
, szSelectionPath
, rec
);
4505 /* failure to set the path halts the executing of control events */
4506 r
= MSI_SetTargetPathW( dialog
->package
, argument
, path
);
4509 msi_free( &rec
->hdr
);
4513 static UINT
event_reset( msi_dialog
*dialog
, const WCHAR
*argument
)
4515 msi_dialog_reset( dialog
);
4516 return ERROR_SUCCESS
;
4519 /* Return ERROR_SUCCESS if dialog is process and ERROR_FUNCTION_FAILED
4520 * if the given parameter is not a dialog box
4522 UINT
ACTION_DialogBox( MSIPACKAGE
*package
, const WCHAR
*dialog
)
4526 if (package
->next_dialog
) ERR("Already got next dialog... ignoring it\n");
4527 package
->next_dialog
= NULL
;
4529 /* Dialogs are chained by filling in the next_dialog member
4530 * of the package structure, then terminating the current dialog.
4531 * The code below sees the next_dialog member set, and runs the
4533 * We fall out of the loop below if we come across a modeless
4534 * dialog, as it returns ERROR_IO_PENDING when we try to run
4537 r
= event_do_dialog( package
, dialog
, NULL
, TRUE
);
4538 while (r
== ERROR_SUCCESS
&& package
->next_dialog
)
4540 WCHAR
*name
= package
->next_dialog
;
4542 package
->next_dialog
= NULL
;
4543 r
= event_do_dialog( package
, name
, NULL
, TRUE
);
4546 if (r
== ERROR_IO_PENDING
) r
= ERROR_SUCCESS
;
4550 static UINT
event_set_install_level( msi_dialog
*dialog
, const WCHAR
*argument
)
4552 int level
= atolW( argument
);
4554 TRACE("setting install level to %d\n", level
);
4555 return MSI_SetInstallLevel( dialog
->package
, level
);
4558 static UINT
event_directory_list_up( msi_dialog
*dialog
, const WCHAR
*argument
)
4560 return msi_dialog_directorylist_up( dialog
);
4563 static UINT
event_reinstall_mode( msi_dialog
*dialog
, const WCHAR
*argument
)
4565 return msi_set_property( dialog
->package
->db
, szReinstallMode
, argument
, -1 );
4568 static UINT
event_reinstall( msi_dialog
*dialog
, const WCHAR
*argument
)
4570 return msi_set_property( dialog
->package
->db
, szReinstall
, argument
, -1 );
4573 static UINT
event_validate_product_id( msi_dialog
*dialog
, const WCHAR
*argument
)
4575 return msi_validate_product_id( dialog
->package
);
4578 static const WCHAR end_dialogW
[] = {'E','n','d','D','i','a','l','o','g',0};
4579 static const WCHAR new_dialogW
[] = {'N','e','w','D','i','a','l','o','g',0};
4580 static const WCHAR spawn_dialogW
[] = {'S','p','a','w','n','D','i','a','l','o','g',0};
4581 static const WCHAR spawn_wait_dialogW
[] = {'S','p','a','w','n','W','a','i','t','D','i','a','l','o','g',0};
4582 static const WCHAR do_actionW
[] = {'D','o','A','c','t','i','o','n',0};
4583 static const WCHAR add_localW
[] = {'A','d','d','L','o','c','a','l',0};
4584 static const WCHAR removeW
[] = {'R','e','m','o','v','e',0};
4585 static const WCHAR add_sourceW
[] = {'A','d','d','S','o','u','r','c','e',0};
4586 static const WCHAR set_target_pathW
[] = {'S','e','t','T','a','r','g','e','t','P','a','t','h',0};
4587 static const WCHAR resetW
[] = {'R','e','s','e','t',0};
4588 static const WCHAR set_install_levelW
[] = {'S','e','t','I','n','s','t','a','l','l','L','e','v','e','l',0};
4589 static const WCHAR directory_list_upW
[] = {'D','i','r','e','c','t','o','r','y','L','i','s','t','U','p',0};
4590 static const WCHAR selection_browseW
[] = {'S','e','l','e','c','t','i','o','n','B','r','o','w','s','e',0};
4591 static const WCHAR reinstall_modeW
[] = {'R','e','i','n','s','t','a','l','l','M','o','d','e',0};
4592 static const WCHAR reinstallW
[] = {'R','e','i','n','s','t','a','l','l',0};
4593 static const WCHAR validate_product_idW
[] = {'V','a','l','i','d','a','t','e','P','r','o','d','u','c','t','I','D',0};
4595 static const struct control_event control_events
[] =
4597 { end_dialogW
, event_end_dialog
},
4598 { new_dialogW
, event_new_dialog
},
4599 { spawn_dialogW
, event_spawn_dialog
},
4600 { spawn_wait_dialogW
, event_spawn_wait_dialog
},
4601 { do_actionW
, event_do_action
},
4602 { add_localW
, event_add_local
},
4603 { removeW
, event_remove
},
4604 { add_sourceW
, event_add_source
},
4605 { set_target_pathW
, event_set_target_path
},
4606 { resetW
, event_reset
},
4607 { set_install_levelW
, event_set_install_level
},
4608 { directory_list_upW
, event_directory_list_up
},
4609 { selection_browseW
, event_spawn_dialog
},
4610 { reinstall_modeW
, event_reinstall_mode
},
4611 { reinstallW
, event_reinstall
},
4612 { validate_product_idW
, event_validate_product_id
},
4616 static UINT
dialog_event_handler( msi_dialog
*dialog
, const WCHAR
*event
, const WCHAR
*argument
)
4620 TRACE("handling event %s\n", debugstr_w(event
));
4622 if (!event
) return ERROR_SUCCESS
;
4624 for (i
= 0; control_events
[i
].event
; i
++)
4626 if (!strcmpW( control_events
[i
].event
, event
))
4627 return control_events
[i
].handler( dialog
, argument
);
4629 FIXME("unhandled event %s arg(%s)\n", debugstr_w(event
), debugstr_w(argument
));
4630 return ERROR_SUCCESS
;