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
42 #include "wine/debug.h"
45 #include "msiserver.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
* );
57 typedef UINT (*event_handler
)( msi_dialog
*, const WCHAR
* );
59 struct msi_control_tag
69 HIMAGELIST hImageList
;
73 float progress_current
;
75 BOOL progress_backwards
;
80 typedef struct msi_font_tag
92 control_event_handler event_handler
;
100 struct list controls
;
102 LPWSTR control_default
;
103 LPWSTR control_cancel
;
104 event_handler pending_event
;
105 LPWSTR pending_argument
;
119 typedef UINT (*msi_dialog_control_func
)( msi_dialog
*dialog
, MSIRECORD
*rec
);
120 struct control_handler
122 LPCWSTR control_type
;
123 msi_dialog_control_func func
;
131 } radio_button_group_descr
;
133 /* dialog sequencing */
135 #define WM_MSI_DIALOG_CREATE (WM_USER+0x100)
136 #define WM_MSI_DIALOG_DESTROY (WM_USER+0x101)
138 #define USER_INSTALLSTATE_ALL 0x1000
140 static DWORD uiThreadId
;
141 static HWND hMsiHiddenWindow
;
143 static LPWSTR
msi_get_window_text( HWND hwnd
)
149 buf
= msi_alloc( sz
*sizeof(WCHAR
) );
152 r
= GetWindowTextW( hwnd
, buf
, sz
);
156 buf
= msi_realloc( buf
, sz
*sizeof(WCHAR
) );
162 static INT
msi_dialog_scale_unit( msi_dialog
*dialog
, INT val
)
164 return MulDiv( val
, dialog
->scale
, 12 );
167 static msi_control
*msi_dialog_find_control( msi_dialog
*dialog
, LPCWSTR name
)
169 msi_control
*control
;
175 LIST_FOR_EACH_ENTRY( control
, &dialog
->controls
, msi_control
, entry
)
176 if( !wcscmp( control
->name
, name
) ) /* FIXME: case sensitive? */
181 static msi_control
*msi_dialog_find_control_by_type( msi_dialog
*dialog
, LPCWSTR type
)
183 msi_control
*control
;
189 LIST_FOR_EACH_ENTRY( control
, &dialog
->controls
, msi_control
, entry
)
190 if( !wcscmp( control
->type
, type
) ) /* FIXME: case sensitive? */
195 static msi_control
*msi_dialog_find_control_by_hwnd( msi_dialog
*dialog
, HWND hwnd
)
197 msi_control
*control
;
201 LIST_FOR_EACH_ENTRY( control
, &dialog
->controls
, msi_control
, entry
)
202 if( hwnd
== control
->hwnd
)
207 static LPWSTR
msi_get_deformatted_field( MSIPACKAGE
*package
, MSIRECORD
*rec
, int field
)
209 LPCWSTR str
= MSI_RecordGetString( rec
, field
);
213 deformat_string( package
, str
, &ret
);
217 static LPWSTR
msi_dialog_dup_property( msi_dialog
*dialog
, LPCWSTR property
, BOOL indirect
)
225 prop
= msi_dup_property( dialog
->package
->db
, property
);
228 prop
= strdupW( property
);
234 * msi_dialog_get_style
236 * Extract the {\style} string from the front of the text to display and
237 * update the pointer. Only the last style in a list is applied.
239 static LPWSTR
msi_dialog_get_style( LPCWSTR p
, LPCWSTR
*rest
)
250 while ((first
= wcschr( p
, '{' )) && (q
= wcschr( first
+ 1, '}' )))
253 if( *p
!= '\\' && *p
!= '&' )
256 /* little bit of sanity checking to stop us getting confused with RTF */
257 for( i
=++p
; i
<q
; i
++ )
258 if( *i
== '}' || *i
== '\\' )
268 ret
= msi_alloc( len
*sizeof(WCHAR
) );
271 memcpy( ret
, p
, len
*sizeof(WCHAR
) );
276 static UINT
msi_dialog_add_font( MSIRECORD
*rec
, LPVOID param
)
278 msi_dialog
*dialog
= param
;
285 /* create a font and add it to the list */
286 name
= MSI_RecordGetString( rec
, 1 );
287 font
= msi_alloc( FIELD_OFFSET( msi_font
, name
[lstrlenW( name
) + 1] ));
288 lstrcpyW( font
->name
, name
);
289 list_add_head( &dialog
->fonts
, &font
->entry
);
291 font
->color
= MSI_RecordGetInteger( rec
, 4 );
293 memset( &lf
, 0, sizeof lf
);
294 face
= MSI_RecordGetString( rec
, 2 );
295 lf
.lfHeight
= MSI_RecordGetInteger( rec
, 3 );
296 style
= MSI_RecordGetInteger( rec
, 5 );
297 if( style
& msidbTextStyleStyleBitsBold
)
298 lf
.lfWeight
= FW_BOLD
;
299 if( style
& msidbTextStyleStyleBitsItalic
)
301 if( style
& msidbTextStyleStyleBitsUnderline
)
302 lf
.lfUnderline
= TRUE
;
303 if( style
& msidbTextStyleStyleBitsStrike
)
304 lf
.lfStrikeOut
= TRUE
;
305 lstrcpynW( lf
.lfFaceName
, face
, LF_FACESIZE
);
307 /* adjust the height */
308 hdc
= GetDC( dialog
->hwnd
);
311 lf
.lfHeight
= -MulDiv(lf
.lfHeight
, GetDeviceCaps(hdc
, LOGPIXELSY
), 72);
312 ReleaseDC( dialog
->hwnd
, hdc
);
315 font
->hfont
= CreateFontIndirectW( &lf
);
317 TRACE("Adding font style %s\n", debugstr_w(font
->name
) );
319 return ERROR_SUCCESS
;
322 static msi_font
*msi_dialog_find_font( msi_dialog
*dialog
, LPCWSTR name
)
324 msi_font
*font
= NULL
;
326 LIST_FOR_EACH_ENTRY( font
, &dialog
->fonts
, msi_font
, entry
)
327 if( !wcscmp( font
->name
, name
) ) /* FIXME: case sensitive? */
333 static UINT
msi_dialog_set_font( msi_dialog
*dialog
, HWND hwnd
, LPCWSTR name
)
337 font
= msi_dialog_find_font( dialog
, name
);
339 SendMessageW( hwnd
, WM_SETFONT
, (WPARAM
) font
->hfont
, TRUE
);
341 ERR("No font entry for %s\n", debugstr_w(name
));
342 return ERROR_SUCCESS
;
345 static UINT
msi_dialog_build_font_list( msi_dialog
*dialog
)
350 TRACE("dialog %p\n", dialog
);
352 r
= MSI_OpenQuery( dialog
->package
->db
, &view
, L
"SELECT * FROM `TextStyle`" );
353 if( r
!= ERROR_SUCCESS
)
356 r
= MSI_IterateRecords( view
, NULL
, msi_dialog_add_font
, dialog
);
357 msiobj_release( &view
->hdr
);
361 static void msi_destroy_control( msi_control
*t
)
363 list_remove( &t
->entry
);
364 /* leave dialog->hwnd - destroying parent destroys child windows */
365 msi_free( t
->property
);
366 msi_free( t
->value
);
368 DeleteObject( t
->hBitmap
);
370 DestroyIcon( t
->hIcon
);
372 ImageList_Destroy( t
->hImageList
);
373 msi_free( t
->tabnext
);
376 FreeLibrary( t
->hDll
);
380 static msi_control
*dialog_create_window( msi_dialog
*dialog
, MSIRECORD
*rec
, DWORD exstyle
,
381 const WCHAR
*szCls
, const WCHAR
*name
, const WCHAR
*text
,
382 DWORD style
, HWND parent
)
384 DWORD x
, y
, width
, height
;
385 LPWSTR font
= NULL
, title_font
= NULL
;
386 LPCWSTR title
= NULL
;
387 msi_control
*control
;
391 control
= msi_alloc( FIELD_OFFSET( msi_control
, name
[lstrlenW( name
) + 1] ));
395 lstrcpyW( control
->name
, name
);
396 list_add_tail( &dialog
->controls
, &control
->entry
);
397 control
->handler
= NULL
;
398 control
->update
= NULL
;
399 control
->property
= NULL
;
400 control
->value
= NULL
;
401 control
->hBitmap
= NULL
;
402 control
->hIcon
= NULL
;
403 control
->hImageList
= NULL
;
404 control
->hDll
= NULL
;
405 control
->tabnext
= strdupW( MSI_RecordGetString( rec
, 11) );
406 control
->type
= strdupW( MSI_RecordGetString( rec
, 3 ) );
407 control
->progress_current
= 0;
408 control
->progress_max
= 100;
409 control
->progress_backwards
= FALSE
;
411 x
= MSI_RecordGetInteger( rec
, 4 );
412 y
= MSI_RecordGetInteger( rec
, 5 );
413 width
= MSI_RecordGetInteger( rec
, 6 );
414 height
= MSI_RecordGetInteger( rec
, 7 );
416 x
= msi_dialog_scale_unit( dialog
, x
);
417 y
= msi_dialog_scale_unit( dialog
, y
);
418 width
= msi_dialog_scale_unit( dialog
, width
);
419 height
= msi_dialog_scale_unit( dialog
, height
);
423 deformat_string( dialog
->package
, text
, &title_font
);
424 font
= msi_dialog_get_style( title_font
, &title
);
427 control
->hwnd
= CreateWindowExW( exstyle
, szCls
, title
, style
,
428 x
, y
, width
, height
, parent
, NULL
, NULL
, NULL
);
430 TRACE("Dialog %s control %s hwnd %p\n",
431 debugstr_w(dialog
->name
), debugstr_w(text
), control
->hwnd
);
433 msi_dialog_set_font( dialog
, control
->hwnd
,
434 font
? font
: dialog
->default_font
);
436 msi_free( title_font
);
442 static LPWSTR
msi_dialog_get_uitext( msi_dialog
*dialog
, LPCWSTR key
)
447 rec
= MSI_QueryGetRecord( dialog
->package
->db
, L
"SELECT * FROM `UIText` WHERE `Key` = '%s'", key
);
448 if (!rec
) return NULL
;
449 text
= strdupW( MSI_RecordGetString( rec
, 2 ) );
450 msiobj_release( &rec
->hdr
);
454 static HANDLE
msi_load_image( MSIDATABASE
*db
, LPCWSTR name
, UINT type
,
455 UINT cx
, UINT cy
, UINT flags
)
458 HANDLE himage
= NULL
;
462 TRACE("%p %s %u %u %08x\n", db
, debugstr_w(name
), cx
, cy
, flags
);
464 if (!(tmp
= msi_create_temp_file( db
))) return NULL
;
466 rec
= MSI_QueryGetRecord( db
, L
"SELECT * FROM `Binary` WHERE `Name` = '%s'", name
);
469 r
= MSI_RecordStreamToFile( rec
, 2, tmp
);
470 if( r
== ERROR_SUCCESS
)
472 himage
= LoadImageW( 0, tmp
, type
, cx
, cy
, flags
);
474 msiobj_release( &rec
->hdr
);
482 static HICON
msi_load_icon( MSIDATABASE
*db
, LPCWSTR text
, UINT attributes
)
484 DWORD cx
= 0, cy
= 0, flags
;
486 flags
= LR_LOADFROMFILE
| LR_DEFAULTSIZE
;
487 if( attributes
& msidbControlAttributesFixedSize
)
489 flags
&= ~LR_DEFAULTSIZE
;
490 if( attributes
& msidbControlAttributesIconSize16
)
495 if( attributes
& msidbControlAttributesIconSize32
)
500 /* msidbControlAttributesIconSize48 handled by above logic */
502 return msi_load_image( db
, text
, IMAGE_ICON
, cx
, cy
, flags
);
505 static void msi_dialog_update_controls( msi_dialog
*dialog
, LPCWSTR property
)
507 msi_control
*control
;
509 LIST_FOR_EACH_ENTRY( control
, &dialog
->controls
, msi_control
, entry
)
511 if ( control
->property
&& !wcscmp( control
->property
, property
) && control
->update
)
512 control
->update( dialog
, control
);
516 static void msi_dialog_update_all_controls( msi_dialog
*dialog
)
518 msi_control
*control
;
520 LIST_FOR_EACH_ENTRY( control
, &dialog
->controls
, msi_control
, entry
)
522 if ( control
->property
&& control
->update
)
523 control
->update( dialog
, control
);
527 static void msi_dialog_set_property( MSIPACKAGE
*package
, LPCWSTR property
, LPCWSTR value
)
529 UINT r
= msi_set_property( package
->db
, property
, value
, -1 );
530 if (r
== ERROR_SUCCESS
&& !wcscmp( property
, L
"SourceDir" ))
531 msi_reset_source_folders( package
);
534 static MSIFEATURE
*msi_seltree_feature_from_item( HWND hwnd
, HTREEITEM hItem
)
538 /* get the feature from the item */
539 memset( &tvi
, 0, sizeof tvi
);
541 tvi
.mask
= TVIF_PARAM
| TVIF_HANDLE
;
542 SendMessageW( hwnd
, TVM_GETITEMW
, 0, (LPARAM
)&tvi
);
543 return (MSIFEATURE
*)tvi
.lParam
;
546 struct msi_selection_tree_info
554 static MSIFEATURE
*msi_seltree_get_selected_feature( msi_control
*control
)
556 struct msi_selection_tree_info
*info
= GetPropW( control
->hwnd
, L
"MSIDATA" );
557 return msi_seltree_feature_from_item( control
->hwnd
, info
->selected
);
560 static void dialog_handle_event( msi_dialog
*dialog
, const WCHAR
*control
,
561 const WCHAR
*attribute
, MSIRECORD
*rec
)
565 ctrl
= msi_dialog_find_control( dialog
, control
);
568 if( !wcscmp( attribute
, L
"Text" ) )
570 const WCHAR
*font_text
, *text
= NULL
;
571 WCHAR
*font
, *text_fmt
= NULL
;
573 font_text
= MSI_RecordGetString( rec
, 1 );
574 font
= msi_dialog_get_style( font_text
, &text
);
575 deformat_string( dialog
->package
, text
, &text_fmt
);
576 if (text_fmt
) text
= text_fmt
;
579 SetWindowTextW( ctrl
->hwnd
, text
);
582 msi_free( text_fmt
);
583 msi_dialog_check_messages( NULL
);
585 else if( !wcscmp( attribute
, L
"Progress" ) )
587 DWORD func
, val1
, val2
, units
;
589 func
= MSI_RecordGetInteger( rec
, 1 );
590 val1
= MSI_RecordGetInteger( rec
, 2 );
591 val2
= MSI_RecordGetInteger( rec
, 3 );
593 TRACE("progress: func %u val1 %u val2 %u\n", func
, val1
, val2
);
599 SendMessageW( ctrl
->hwnd
, PBM_SETRANGE
, 0, MAKELPARAM(0,100) );
602 ctrl
->progress_max
= units
? units
: 100;
603 ctrl
->progress_current
= units
;
604 ctrl
->progress_backwards
= TRUE
;
605 SendMessageW( ctrl
->hwnd
, PBM_SETPOS
, 100, 0 );
609 ctrl
->progress_max
= units
? units
: 100;
610 ctrl
->progress_current
= 0;
611 ctrl
->progress_backwards
= FALSE
;
612 SendMessageW( ctrl
->hwnd
, PBM_SETPOS
, 0, 0 );
615 case 1: /* action data increment */
616 if (val2
) dialog
->package
->action_progress_increment
= val1
;
617 else dialog
->package
->action_progress_increment
= 0;
620 if (ctrl
->progress_backwards
)
622 if (units
>= ctrl
->progress_current
) ctrl
->progress_current
-= units
;
623 else ctrl
->progress_current
= 0;
627 if (ctrl
->progress_current
+ units
< ctrl
->progress_max
) ctrl
->progress_current
+= units
;
628 else ctrl
->progress_current
= ctrl
->progress_max
;
630 SendMessageW( ctrl
->hwnd
, PBM_SETPOS
, MulDiv(100, ctrl
->progress_current
, ctrl
->progress_max
), 0 );
633 ctrl
->progress_max
+= units
;
636 FIXME("Unknown progress message %u\n", func
);
640 else if ( !wcscmp( attribute
, L
"Property" ) )
642 MSIFEATURE
*feature
= msi_seltree_get_selected_feature( ctrl
);
643 if (feature
) msi_dialog_set_property( dialog
->package
, ctrl
->property
, feature
->Directory
);
645 else if ( !wcscmp( attribute
, L
"SelectionPath" ) )
647 BOOL indirect
= ctrl
->attributes
& msidbControlAttributesIndirect
;
648 LPWSTR path
= msi_dialog_dup_property( dialog
, ctrl
->property
, indirect
);
650 SetWindowTextW( ctrl
->hwnd
, path
);
655 FIXME("Attribute %s not being set\n", debugstr_w(attribute
));
660 static void event_subscribe( msi_dialog
*dialog
, const WCHAR
*event
, const WCHAR
*control
, const WCHAR
*attribute
)
662 struct subscriber
*sub
;
664 TRACE("dialog %s event %s control %s attribute %s\n", debugstr_w(dialog
->name
), debugstr_w(event
),
665 debugstr_w(control
), debugstr_w(attribute
));
667 LIST_FOR_EACH_ENTRY( sub
, &dialog
->package
->subscriptions
, struct subscriber
, entry
)
669 if (sub
->dialog
== dialog
&&
670 !wcsicmp( sub
->event
, event
) &&
671 !wcsicmp( sub
->control
, control
) &&
672 !wcsicmp( sub
->attribute
, attribute
))
674 TRACE("already subscribed\n");
678 if (!(sub
= msi_alloc( sizeof(*sub
) ))) return;
679 sub
->dialog
= dialog
;
680 sub
->event
= strdupW( event
);
681 sub
->control
= strdupW( control
);
682 sub
->attribute
= strdupW( attribute
);
683 list_add_tail( &dialog
->package
->subscriptions
, &sub
->entry
);
686 struct dialog_control
689 const WCHAR
*control
;
692 static UINT
map_event( MSIRECORD
*row
, void *param
)
694 struct dialog_control
*dc
= param
;
695 const WCHAR
*event
= MSI_RecordGetString( row
, 3 );
696 const WCHAR
*attribute
= MSI_RecordGetString( row
, 4 );
698 event_subscribe( dc
->dialog
, event
, dc
->control
, attribute
);
699 return ERROR_SUCCESS
;
702 static void dialog_map_events( msi_dialog
*dialog
, const WCHAR
*control
)
705 struct dialog_control dialog_control
=
711 if (!MSI_OpenQuery( dialog
->package
->db
, &view
,
712 L
"SELECT * FROM `EventMapping` WHERE `Dialog_` = '%s' AND `Control_` = '%s'",
713 dialog
->name
, control
))
715 MSI_IterateRecords( view
, NULL
, map_event
, &dialog_control
);
716 msiobj_release( &view
->hdr
);
720 /* everything except radio buttons */
721 static msi_control
*msi_dialog_add_control( msi_dialog
*dialog
,
722 MSIRECORD
*rec
, LPCWSTR szCls
, DWORD style
)
725 const WCHAR
*text
= NULL
, *name
, *control_type
;
728 name
= MSI_RecordGetString( rec
, 2 );
729 control_type
= MSI_RecordGetString( rec
, 3 );
730 attributes
= MSI_RecordGetInteger( rec
, 8 );
731 if (wcscmp( control_type
, L
"ScrollableText" )) text
= MSI_RecordGetString( rec
, 10 );
733 TRACE("%s, %s, %08x, %s, %08x\n", debugstr_w(szCls
), debugstr_w(name
),
734 attributes
, debugstr_w(text
), style
);
736 if( attributes
& msidbControlAttributesVisible
)
738 if( ~attributes
& msidbControlAttributesEnabled
)
739 style
|= WS_DISABLED
;
740 if( attributes
& msidbControlAttributesSunken
)
741 exstyle
|= WS_EX_CLIENTEDGE
;
743 dialog_map_events( dialog
, name
);
745 return dialog_create_window( dialog
, rec
, exstyle
, szCls
, name
, text
, style
, dialog
->hwnd
);
756 * we don't erase our own background,
757 * so we have to make sure that the parent window redraws first
759 static void msi_text_on_settext( HWND hWnd
)
764 hParent
= GetParent( hWnd
);
765 GetWindowRect( hWnd
, &rc
);
766 MapWindowPoints( NULL
, hParent
, (LPPOINT
) &rc
, 2 );
767 InvalidateRect( hParent
, &rc
, TRUE
);
770 static LRESULT WINAPI
771 MSIText_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
773 struct msi_text_info
*info
;
776 TRACE("%p %04x %08lx %08lx\n", hWnd
, msg
, wParam
, lParam
);
778 info
= GetPropW(hWnd
, L
"MSIDATA");
780 if( msg
== WM_CTLCOLORSTATIC
&&
781 ( info
->attributes
& msidbControlAttributesTransparent
) )
783 SetBkMode( (HDC
)wParam
, TRANSPARENT
);
784 return (LRESULT
) GetStockObject(NULL_BRUSH
);
787 r
= CallWindowProcW(info
->oldproc
, hWnd
, msg
, wParam
, lParam
);
789 SetTextColor( (HDC
)wParam
, info
->font
->color
);
794 msi_text_on_settext( hWnd
);
798 RemovePropW( hWnd
, L
"MSIDATA" );
805 static UINT
msi_dialog_text_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
807 msi_control
*control
;
808 struct msi_text_info
*info
;
809 LPCWSTR text
, ptr
, prop
, control_name
;
812 TRACE("%p %p\n", dialog
, rec
);
814 control
= msi_dialog_add_control( dialog
, rec
, L
"Static", SS_LEFT
| WS_GROUP
);
816 return ERROR_FUNCTION_FAILED
;
818 info
= msi_alloc( sizeof *info
);
820 return ERROR_SUCCESS
;
822 control_name
= MSI_RecordGetString( rec
, 2 );
823 control
->attributes
= MSI_RecordGetInteger( rec
, 8 );
824 prop
= MSI_RecordGetString( rec
, 9 );
825 control
->property
= msi_dialog_dup_property( dialog
, prop
, FALSE
);
827 text
= MSI_RecordGetString( rec
, 10 );
828 font_name
= msi_dialog_get_style( text
, &ptr
);
829 info
->font
= ( font_name
) ? msi_dialog_find_font( dialog
, font_name
) : NULL
;
830 msi_free( font_name
);
832 info
->attributes
= MSI_RecordGetInteger( rec
, 8 );
833 if( info
->attributes
& msidbControlAttributesTransparent
)
834 SetWindowLongPtrW( control
->hwnd
, GWL_EXSTYLE
, WS_EX_TRANSPARENT
);
836 info
->oldproc
= (WNDPROC
) SetWindowLongPtrW( control
->hwnd
, GWLP_WNDPROC
,
837 (LONG_PTR
)MSIText_WndProc
);
838 SetPropW( control
->hwnd
, L
"MSIDATA", info
);
840 event_subscribe( dialog
, L
"SelectionPath", control_name
, L
"SelectionPath" );
841 return ERROR_SUCCESS
;
844 /* strip any leading text style label from text field */
845 static WCHAR
*msi_get_binary_name( MSIPACKAGE
*package
, MSIRECORD
*rec
)
849 text
= msi_get_deformatted_field( package
, rec
, 10 );
854 while (*p
&& *p
!= '{') p
++;
855 if (!*p
++) return text
;
857 while (*p
&& *p
!= '}') p
++;
858 if (!*p
++) return text
;
865 static UINT
msi_dialog_set_property_event( msi_dialog
*dialog
, LPCWSTR event
, LPCWSTR arg
)
867 LPWSTR p
, prop
, arg_fmt
= NULL
;
870 len
= lstrlenW( event
);
871 prop
= msi_alloc( len
* sizeof(WCHAR
) );
872 lstrcpyW( prop
, &event
[1] );
873 p
= wcschr( prop
, ']' );
874 if (p
&& (p
[1] == 0 || p
[1] == ' '))
877 if (wcscmp( L
"{}", arg
)) deformat_string( dialog
->package
, arg
, &arg_fmt
);
878 msi_dialog_set_property( dialog
->package
, prop
, arg_fmt
);
879 msi_dialog_update_controls( dialog
, prop
);
882 else ERR("Badly formatted property string - what happens?\n");
884 return ERROR_SUCCESS
;
887 static UINT
msi_dialog_send_event( msi_dialog
*dialog
, LPCWSTR event
, LPCWSTR arg
)
889 LPWSTR event_fmt
= NULL
, arg_fmt
= NULL
;
891 TRACE("Sending control event %s %s\n", debugstr_w(event
), debugstr_w(arg
));
893 deformat_string( dialog
->package
, event
, &event_fmt
);
894 deformat_string( dialog
->package
, arg
, &arg_fmt
);
896 dialog
->event_handler( dialog
, event_fmt
, arg_fmt
);
898 msi_free( event_fmt
);
901 return ERROR_SUCCESS
;
904 static UINT
msi_dialog_control_event( MSIRECORD
*rec
, LPVOID param
)
906 msi_dialog
*dialog
= param
;
907 LPCWSTR condition
, event
, arg
;
910 condition
= MSI_RecordGetString( rec
, 5 );
911 r
= MSI_EvaluateConditionW( dialog
->package
, condition
);
912 if (r
== MSICONDITION_TRUE
|| r
== MSICONDITION_NONE
)
914 event
= MSI_RecordGetString( rec
, 3 );
915 arg
= MSI_RecordGetString( rec
, 4 );
917 msi_dialog_set_property_event( dialog
, event
, arg
);
919 msi_dialog_send_event( dialog
, event
, arg
);
921 return ERROR_SUCCESS
;
924 static UINT
msi_dialog_button_handler( msi_dialog
*dialog
, msi_control
*control
, WPARAM param
)
929 if (HIWORD(param
) != BN_CLICKED
)
930 return ERROR_SUCCESS
;
932 r
= MSI_OpenQuery( dialog
->package
->db
, &view
,
933 L
"SELECT * FROM `ControlEvent` WHERE `Dialog_` = '%s' AND `Control_` = '%s' ORDER BY `Ordering`",
934 dialog
->name
, control
->name
);
935 if (r
!= ERROR_SUCCESS
)
937 ERR("query failed\n");
938 return ERROR_SUCCESS
;
940 r
= MSI_IterateRecords( view
, 0, msi_dialog_control_event
, dialog
);
941 msiobj_release( &view
->hdr
);
943 /* dialog control events must be processed last regardless of ordering */
944 if (dialog
->pending_event
)
946 r
= dialog
->pending_event( dialog
, dialog
->pending_argument
);
948 msi_free( dialog
->pending_argument
);
949 dialog
->pending_event
= NULL
;
950 dialog
->pending_argument
= NULL
;
955 static HBITMAP
msi_load_picture( MSIDATABASE
*db
, const WCHAR
*name
, INT cx
, INT cy
, DWORD flags
)
957 HBITMAP hOleBitmap
= 0, hBitmap
= 0, hOldSrcBitmap
, hOldDestBitmap
;
958 MSIRECORD
*rec
= NULL
;
960 IPicture
*pic
= NULL
;
965 rec
= MSI_QueryGetRecord( db
, L
"SELECT * FROM `Binary` WHERE `Name` = '%s'", name
);
969 r
= MSI_RecordGetIStream( rec
, 2, &stm
);
970 msiobj_release( &rec
->hdr
);
971 if (r
!= ERROR_SUCCESS
)
974 r
= OleLoadPicture( stm
, 0, TRUE
, &IID_IPicture
, (void **)&pic
);
975 IStream_Release( stm
);
978 ERR("failed to load picture\n");
982 r
= IPicture_get_Handle( pic
, (OLE_HANDLE
*)&hOleBitmap
);
985 ERR("failed to get bitmap handle\n");
989 /* make the bitmap the desired size */
990 r
= GetObjectW( hOleBitmap
, sizeof(bm
), &bm
);
993 ERR("failed to get bitmap size\n");
997 if (flags
& LR_DEFAULTSIZE
)
1003 srcdc
= CreateCompatibleDC( NULL
);
1004 hOldSrcBitmap
= SelectObject( srcdc
, hOleBitmap
);
1005 destdc
= CreateCompatibleDC( NULL
);
1006 hBitmap
= CreateCompatibleBitmap( srcdc
, cx
, cy
);
1007 hOldDestBitmap
= SelectObject( destdc
, hBitmap
);
1008 StretchBlt( destdc
, 0, 0, cx
, cy
, srcdc
, 0, 0, bm
.bmWidth
, bm
.bmHeight
, SRCCOPY
);
1009 SelectObject( srcdc
, hOldSrcBitmap
);
1010 SelectObject( destdc
, hOldDestBitmap
);
1015 if (pic
) IPicture_Release( pic
);
1019 static UINT
msi_dialog_button_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1021 msi_control
*control
;
1022 UINT attributes
, style
, cx
= 0, cy
= 0, flags
= 0;
1025 TRACE("%p %p\n", dialog
, rec
);
1028 attributes
= MSI_RecordGetInteger( rec
, 8 );
1029 if (attributes
& msidbControlAttributesIcon
) style
|= BS_ICON
;
1030 else if (attributes
& msidbControlAttributesBitmap
)
1033 if (attributes
& msidbControlAttributesFixedSize
) flags
|= LR_DEFAULTSIZE
;
1036 cx
= msi_dialog_scale_unit( dialog
, MSI_RecordGetInteger(rec
, 6) );
1037 cy
= msi_dialog_scale_unit( dialog
, MSI_RecordGetInteger(rec
, 7) );
1041 control
= msi_dialog_add_control( dialog
, rec
, L
"BUTTON", style
);
1043 return ERROR_FUNCTION_FAILED
;
1045 control
->handler
= msi_dialog_button_handler
;
1047 if (attributes
& msidbControlAttributesIcon
)
1049 name
= msi_get_binary_name( dialog
->package
, rec
);
1050 control
->hIcon
= msi_load_icon( dialog
->package
->db
, name
, attributes
);
1053 SendMessageW( control
->hwnd
, BM_SETIMAGE
, IMAGE_ICON
, (LPARAM
) control
->hIcon
);
1055 else ERR("Failed to load icon %s\n", debugstr_w(name
));
1057 else if (attributes
& msidbControlAttributesBitmap
)
1059 name
= msi_get_binary_name( dialog
->package
, rec
);
1060 control
->hBitmap
= msi_load_picture( dialog
->package
->db
, name
, cx
, cy
, flags
);
1061 if (control
->hBitmap
)
1063 SendMessageW( control
->hwnd
, BM_SETIMAGE
, IMAGE_BITMAP
, (LPARAM
) control
->hBitmap
);
1065 else ERR("Failed to load bitmap %s\n", debugstr_w(name
));
1069 return ERROR_SUCCESS
;
1072 static LPWSTR
msi_get_checkbox_value( msi_dialog
*dialog
, LPCWSTR prop
)
1074 MSIRECORD
*rec
= NULL
;
1077 /* find if there is a value associated with the checkbox */
1078 rec
= MSI_QueryGetRecord( dialog
->package
->db
, L
"SELECT * FROM `CheckBox` WHERE `Property` = '%s'", prop
);
1082 ret
= msi_get_deformatted_field( dialog
->package
, rec
, 2 );
1083 if( ret
&& !ret
[0] )
1088 msiobj_release( &rec
->hdr
);
1092 ret
= msi_dup_property( dialog
->package
->db
, prop
);
1093 if( ret
&& !ret
[0] )
1102 static UINT
msi_dialog_get_checkbox_state( msi_dialog
*dialog
, msi_control
*control
)
1104 WCHAR state
[2] = {0};
1107 msi_get_property( dialog
->package
->db
, control
->property
, state
, &sz
);
1108 return state
[0] ? 1 : 0;
1111 static void msi_dialog_set_checkbox_state( msi_dialog
*dialog
, msi_control
*control
, UINT state
)
1115 /* if uncheck then the property is set to NULL */
1118 msi_dialog_set_property( dialog
->package
, control
->property
, NULL
);
1122 /* check for a custom state */
1123 if (control
->value
&& control
->value
[0])
1124 val
= control
->value
;
1128 msi_dialog_set_property( dialog
->package
, control
->property
, val
);
1131 static void msi_dialog_checkbox_sync_state( msi_dialog
*dialog
, msi_control
*control
)
1133 UINT state
= msi_dialog_get_checkbox_state( dialog
, control
);
1134 SendMessageW( control
->hwnd
, BM_SETCHECK
, state
? BST_CHECKED
: BST_UNCHECKED
, 0 );
1137 static UINT
msi_dialog_checkbox_handler( msi_dialog
*dialog
, msi_control
*control
, WPARAM param
)
1141 if (HIWORD(param
) != BN_CLICKED
)
1142 return ERROR_SUCCESS
;
1144 TRACE("clicked checkbox %s, set %s\n", debugstr_w(control
->name
), debugstr_w(control
->property
));
1146 state
= msi_dialog_get_checkbox_state( dialog
, control
);
1147 state
= state
? 0 : 1;
1148 msi_dialog_set_checkbox_state( dialog
, control
, state
);
1149 msi_dialog_checkbox_sync_state( dialog
, control
);
1151 return msi_dialog_button_handler( dialog
, control
, param
);
1154 static UINT
msi_dialog_checkbox_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1156 msi_control
*control
;
1159 TRACE("%p %p\n", dialog
, rec
);
1161 control
= msi_dialog_add_control( dialog
, rec
, L
"BUTTON", BS_CHECKBOX
| BS_MULTILINE
| WS_TABSTOP
);
1162 control
->handler
= msi_dialog_checkbox_handler
;
1163 control
->update
= msi_dialog_checkbox_sync_state
;
1164 prop
= MSI_RecordGetString( rec
, 9 );
1167 control
->property
= strdupW( prop
);
1168 control
->value
= msi_get_checkbox_value( dialog
, prop
);
1169 TRACE("control %s value %s\n", debugstr_w(control
->property
), debugstr_w(control
->value
));
1171 msi_dialog_checkbox_sync_state( dialog
, control
);
1172 return ERROR_SUCCESS
;
1175 static UINT
msi_dialog_line_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1179 DWORD style
, exstyle
= 0;
1180 DWORD x
, y
, width
, height
;
1181 msi_control
*control
;
1183 TRACE("%p %p\n", dialog
, rec
);
1185 style
= WS_CHILD
| SS_ETCHEDHORZ
| SS_SUNKEN
;
1187 name
= MSI_RecordGetString( rec
, 2 );
1188 attributes
= MSI_RecordGetInteger( rec
, 8 );
1190 if( attributes
& msidbControlAttributesVisible
)
1191 style
|= WS_VISIBLE
;
1192 if( ~attributes
& msidbControlAttributesEnabled
)
1193 style
|= WS_DISABLED
;
1194 if( attributes
& msidbControlAttributesSunken
)
1195 exstyle
|= WS_EX_CLIENTEDGE
;
1197 dialog_map_events( dialog
, name
);
1199 control
= msi_alloc( FIELD_OFFSET(msi_control
, name
[lstrlenW( name
) + 1] ));
1201 return ERROR_OUTOFMEMORY
;
1203 lstrcpyW( control
->name
, name
);
1204 list_add_head( &dialog
->controls
, &control
->entry
);
1205 control
->handler
= NULL
;
1206 control
->property
= NULL
;
1207 control
->value
= NULL
;
1208 control
->hBitmap
= NULL
;
1209 control
->hIcon
= NULL
;
1210 control
->hDll
= NULL
;
1211 control
->tabnext
= strdupW( MSI_RecordGetString( rec
, 11) );
1212 control
->type
= strdupW( MSI_RecordGetString( rec
, 3 ) );
1213 control
->progress_current
= 0;
1214 control
->progress_max
= 100;
1215 control
->progress_backwards
= FALSE
;
1217 x
= MSI_RecordGetInteger( rec
, 4 );
1218 y
= MSI_RecordGetInteger( rec
, 5 );
1219 width
= MSI_RecordGetInteger( rec
, 6 );
1221 x
= msi_dialog_scale_unit( dialog
, x
);
1222 y
= msi_dialog_scale_unit( dialog
, y
);
1223 width
= msi_dialog_scale_unit( dialog
, width
);
1224 height
= 2; /* line is exactly 2 units in height */
1226 control
->hwnd
= CreateWindowExW( exstyle
, L
"Static", NULL
, style
,
1227 x
, y
, width
, height
, dialog
->hwnd
, NULL
, NULL
, NULL
);
1229 TRACE("Dialog %s control %s hwnd %p\n",
1230 debugstr_w(dialog
->name
), debugstr_w(name
), control
->hwnd
);
1232 return ERROR_SUCCESS
;
1235 /******************** Scroll Text ********************************************/
1237 struct msi_scrolltext_info
1240 msi_control
*control
;
1244 static LRESULT WINAPI
1245 MSIScrollText_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1247 struct msi_scrolltext_info
*info
;
1250 TRACE("%p %04x %08lx %08lx\n", hWnd
, msg
, wParam
, lParam
);
1252 info
= GetPropW( hWnd
, L
"MSIDATA" );
1254 r
= CallWindowProcW( info
->oldproc
, hWnd
, msg
, wParam
, lParam
);
1259 return DLGC_WANTARROWS
;
1262 RemovePropW( hWnd
, L
"MSIDATA" );
1265 /* native MSI sets a wait cursor here */
1266 msi_dialog_button_handler( info
->dialog
, info
->control
, BN_CLICKED
);
1272 struct msi_streamin_info
1279 static DWORD CALLBACK
1280 msi_richedit_stream_in( DWORD_PTR arg
, LPBYTE buffer
, LONG count
, LONG
*pcb
)
1282 struct msi_streamin_info
*info
= (struct msi_streamin_info
*) arg
;
1284 if( (count
+ info
->offset
) > info
->length
)
1285 count
= info
->length
- info
->offset
;
1286 memcpy( buffer
, &info
->string
[ info
->offset
], count
);
1288 info
->offset
+= count
;
1290 TRACE("%d/%d\n", info
->offset
, info
->length
);
1295 static void msi_scrolltext_add_text( msi_control
*control
, LPCWSTR text
)
1297 struct msi_streamin_info info
;
1300 info
.string
= strdupWtoA( text
);
1302 info
.length
= lstrlenA( info
.string
) + 1;
1304 es
.dwCookie
= (DWORD_PTR
) &info
;
1306 es
.pfnCallback
= msi_richedit_stream_in
;
1308 SendMessageW( control
->hwnd
, EM_STREAMIN
, SF_RTF
, (LPARAM
) &es
);
1310 msi_free( info
.string
);
1313 static UINT
msi_dialog_scrolltext_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1315 struct msi_scrolltext_info
*info
;
1316 msi_control
*control
;
1321 info
= msi_alloc( sizeof *info
);
1323 return ERROR_FUNCTION_FAILED
;
1325 hRichedit
= LoadLibraryA("riched20");
1327 style
= WS_BORDER
| ES_MULTILINE
| WS_VSCROLL
|
1328 ES_READONLY
| ES_AUTOVSCROLL
| WS_TABSTOP
;
1329 control
= msi_dialog_add_control( dialog
, rec
, L
"RichEdit20W", style
);
1332 FreeLibrary( hRichedit
);
1334 return ERROR_FUNCTION_FAILED
;
1337 control
->hDll
= hRichedit
;
1339 info
->dialog
= dialog
;
1340 info
->control
= control
;
1342 /* subclass the static control */
1343 info
->oldproc
= (WNDPROC
) SetWindowLongPtrW( control
->hwnd
, GWLP_WNDPROC
,
1344 (LONG_PTR
)MSIScrollText_WndProc
);
1345 SetPropW( control
->hwnd
, L
"MSIDATA", info
);
1347 /* add the text into the richedit */
1348 text
= MSI_RecordGetString( rec
, 10 );
1350 msi_scrolltext_add_text( control
, text
);
1352 return ERROR_SUCCESS
;
1356 static UINT
msi_dialog_bitmap_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1358 UINT cx
, cy
, flags
, style
, attributes
;
1359 msi_control
*control
;
1362 flags
= LR_LOADFROMFILE
;
1363 style
= SS_BITMAP
| SS_LEFT
| WS_GROUP
;
1365 attributes
= MSI_RecordGetInteger( rec
, 8 );
1366 if( attributes
& msidbControlAttributesFixedSize
)
1368 flags
|= LR_DEFAULTSIZE
;
1369 style
|= SS_CENTERIMAGE
;
1372 control
= msi_dialog_add_control( dialog
, rec
, L
"Static", style
);
1373 cx
= MSI_RecordGetInteger( rec
, 6 );
1374 cy
= MSI_RecordGetInteger( rec
, 7 );
1375 cx
= msi_dialog_scale_unit( dialog
, cx
);
1376 cy
= msi_dialog_scale_unit( dialog
, cy
);
1378 name
= msi_get_binary_name( dialog
->package
, rec
);
1379 control
->hBitmap
= msi_load_picture( dialog
->package
->db
, name
, cx
, cy
, flags
);
1380 if( control
->hBitmap
)
1381 SendMessageW( control
->hwnd
, STM_SETIMAGE
,
1382 IMAGE_BITMAP
, (LPARAM
) control
->hBitmap
);
1384 ERR("Failed to load bitmap %s\n", debugstr_w(name
));
1388 return ERROR_SUCCESS
;
1391 static UINT
msi_dialog_icon_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1393 msi_control
*control
;
1399 control
= msi_dialog_add_control( dialog
, rec
, L
"Static",
1400 SS_ICON
| SS_CENTERIMAGE
| WS_GROUP
);
1402 attributes
= MSI_RecordGetInteger( rec
, 8 );
1403 name
= msi_get_binary_name( dialog
->package
, rec
);
1404 control
->hIcon
= msi_load_icon( dialog
->package
->db
, name
, attributes
);
1405 if( control
->hIcon
)
1406 SendMessageW( control
->hwnd
, STM_SETICON
, (WPARAM
) control
->hIcon
, 0 );
1408 ERR("Failed to load bitmap %s\n", debugstr_w(name
));
1410 return ERROR_SUCCESS
;
1413 /******************** Combo Box ***************************************/
1415 struct msi_combobox_info
1425 static LRESULT WINAPI
MSIComboBox_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1427 struct msi_combobox_info
*info
;
1431 TRACE("%p %04x %08lx %08lx\n", hWnd
, msg
, wParam
, lParam
);
1433 info
= GetPropW( hWnd
, L
"MSIDATA" );
1437 r
= CallWindowProcW( info
->oldproc
, hWnd
, msg
, wParam
, lParam
);
1442 for (j
= 0; j
< info
->num_items
; j
++)
1443 msi_free( info
->items
[j
] );
1444 msi_free( info
->items
);
1446 RemovePropW( hWnd
, L
"MSIDATA" );
1453 static UINT
msi_combobox_add_item( MSIRECORD
*rec
, LPVOID param
)
1455 struct msi_combobox_info
*info
= param
;
1456 LPCWSTR value
, text
;
1459 value
= MSI_RecordGetString( rec
, 3 );
1460 text
= MSI_RecordGetString( rec
, 4 );
1462 info
->items
[info
->addpos_items
] = strdupW( value
);
1464 pos
= SendMessageW( info
->hwnd
, CB_ADDSTRING
, 0, (LPARAM
)text
);
1465 SendMessageW( info
->hwnd
, CB_SETITEMDATA
, pos
, (LPARAM
)info
->items
[info
->addpos_items
] );
1466 info
->addpos_items
++;
1468 return ERROR_SUCCESS
;
1471 static UINT
msi_combobox_add_items( struct msi_combobox_info
*info
, LPCWSTR property
)
1477 r
= MSI_OpenQuery( info
->dialog
->package
->db
, &view
,
1478 L
"SELECT * FROM `ComboBox` WHERE `Property` = '%s' ORDER BY `Order`", property
);
1479 if (r
!= ERROR_SUCCESS
)
1482 /* just get the number of records */
1484 r
= MSI_IterateRecords( view
, &count
, NULL
, NULL
);
1485 if (r
!= ERROR_SUCCESS
)
1487 msiobj_release( &view
->hdr
);
1490 info
->num_items
= count
;
1491 info
->items
= msi_alloc( sizeof(*info
->items
) * count
);
1493 r
= MSI_IterateRecords( view
, NULL
, msi_combobox_add_item
, info
);
1494 msiobj_release( &view
->hdr
);
1498 static UINT
msi_dialog_set_control_condition( MSIRECORD
*rec
, LPVOID param
)
1500 msi_dialog
*dialog
= param
;
1501 msi_control
*control
;
1502 LPCWSTR name
, action
, condition
;
1505 name
= MSI_RecordGetString( rec
, 2 );
1506 action
= MSI_RecordGetString( rec
, 3 );
1507 condition
= MSI_RecordGetString( rec
, 4 );
1508 r
= MSI_EvaluateConditionW( dialog
->package
, condition
);
1509 control
= msi_dialog_find_control( dialog
, name
);
1510 if (r
== MSICONDITION_TRUE
&& control
)
1512 TRACE("%s control %s\n", debugstr_w(action
), debugstr_w(name
));
1514 /* FIXME: case sensitive? */
1515 if (!wcscmp( action
, L
"Hide" ))
1516 ShowWindow(control
->hwnd
, SW_HIDE
);
1517 else if (!wcscmp( action
, L
"Show" ))
1518 ShowWindow(control
->hwnd
, SW_SHOW
);
1519 else if (!wcscmp( action
, L
"Disable" ))
1520 EnableWindow(control
->hwnd
, FALSE
);
1521 else if (!wcscmp( action
, L
"Enable" ))
1522 EnableWindow(control
->hwnd
, TRUE
);
1523 else if (!wcscmp( action
, L
"Default" ))
1524 SetFocus(control
->hwnd
);
1526 FIXME("Unhandled action %s\n", debugstr_w(action
));
1528 return ERROR_SUCCESS
;
1531 static UINT
msi_dialog_evaluate_control_conditions( msi_dialog
*dialog
)
1535 MSIPACKAGE
*package
= dialog
->package
;
1537 TRACE("%p %s\n", dialog
, debugstr_w(dialog
->name
));
1539 /* query the Control table for all the elements of the control */
1540 r
= MSI_OpenQuery( package
->db
, &view
, L
"SELECT * FROM `ControlCondition` WHERE `Dialog_` = '%s'", dialog
->name
);
1541 if (r
!= ERROR_SUCCESS
)
1542 return ERROR_SUCCESS
;
1544 r
= MSI_IterateRecords( view
, 0, msi_dialog_set_control_condition
, dialog
);
1545 msiobj_release( &view
->hdr
);
1549 static UINT
msi_dialog_combobox_handler( msi_dialog
*dialog
, msi_control
*control
, WPARAM param
)
1551 struct msi_combobox_info
*info
;
1555 if (HIWORD(param
) != CBN_SELCHANGE
&& HIWORD(param
) != CBN_EDITCHANGE
)
1556 return ERROR_SUCCESS
;
1558 info
= GetPropW( control
->hwnd
, L
"MSIDATA" );
1559 index
= SendMessageW( control
->hwnd
, CB_GETCURSEL
, 0, 0 );
1560 if (index
== CB_ERR
)
1561 value
= msi_get_window_text( control
->hwnd
);
1563 value
= (LPWSTR
) SendMessageW( control
->hwnd
, CB_GETITEMDATA
, index
, 0 );
1565 msi_dialog_set_property( info
->dialog
->package
, control
->property
, value
);
1566 msi_dialog_evaluate_control_conditions( info
->dialog
);
1568 if (index
== CB_ERR
)
1571 return ERROR_SUCCESS
;
1574 static void msi_dialog_combobox_update( msi_dialog
*dialog
, msi_control
*control
)
1576 struct msi_combobox_info
*info
;
1580 info
= GetPropW( control
->hwnd
, L
"MSIDATA" );
1582 value
= msi_dup_property( dialog
->package
->db
, control
->property
);
1585 SendMessageW( control
->hwnd
, CB_SETCURSEL
, -1, 0 );
1589 for (j
= 0; j
< info
->num_items
; j
++)
1591 tmp
= (LPWSTR
) SendMessageW( control
->hwnd
, CB_GETITEMDATA
, j
, 0 );
1592 if (!wcscmp( value
, tmp
))
1596 if (j
< info
->num_items
)
1598 SendMessageW( control
->hwnd
, CB_SETCURSEL
, j
, 0 );
1602 SendMessageW( control
->hwnd
, CB_SETCURSEL
, -1, 0 );
1603 SetWindowTextW( control
->hwnd
, value
);
1609 static UINT
msi_dialog_combo_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1611 struct msi_combobox_info
*info
;
1612 msi_control
*control
;
1613 DWORD attributes
, style
;
1616 info
= msi_alloc( sizeof *info
);
1618 return ERROR_FUNCTION_FAILED
;
1620 style
= CBS_AUTOHSCROLL
| WS_TABSTOP
| WS_GROUP
| WS_CHILD
;
1621 attributes
= MSI_RecordGetInteger( rec
, 8 );
1622 if ( ~attributes
& msidbControlAttributesSorted
)
1624 if ( attributes
& msidbControlAttributesComboList
)
1625 style
|= CBS_DROPDOWNLIST
;
1627 style
|= CBS_DROPDOWN
;
1629 control
= msi_dialog_add_control( dialog
, rec
, WC_COMBOBOXW
, style
);
1633 return ERROR_FUNCTION_FAILED
;
1636 control
->handler
= msi_dialog_combobox_handler
;
1637 control
->update
= msi_dialog_combobox_update
;
1639 prop
= MSI_RecordGetString( rec
, 9 );
1640 control
->property
= msi_dialog_dup_property( dialog
, prop
, FALSE
);
1643 info
->dialog
= dialog
;
1644 info
->hwnd
= control
->hwnd
;
1646 info
->addpos_items
= 0;
1647 info
->oldproc
= (WNDPROC
)SetWindowLongPtrW( control
->hwnd
, GWLP_WNDPROC
,
1648 (LONG_PTR
)MSIComboBox_WndProc
);
1649 SetPropW( control
->hwnd
, L
"MSIDATA", info
);
1651 if (control
->property
)
1652 msi_combobox_add_items( info
, control
->property
);
1654 msi_dialog_combobox_update( dialog
, control
);
1656 return ERROR_SUCCESS
;
1659 static UINT
msi_dialog_edit_handler( msi_dialog
*dialog
, msi_control
*control
, WPARAM param
)
1663 if (HIWORD(param
) != EN_CHANGE
)
1664 return ERROR_SUCCESS
;
1666 TRACE("edit %s contents changed, set %s\n", debugstr_w(control
->name
), debugstr_w(control
->property
));
1668 buf
= msi_get_window_text( control
->hwnd
);
1669 msi_dialog_set_property( dialog
->package
, control
->property
, buf
);
1672 return ERROR_SUCCESS
;
1675 /* length of 2^32 + 1 */
1676 #define MAX_NUM_DIGITS 11
1678 static UINT
msi_dialog_edit_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1680 msi_control
*control
;
1682 LPWSTR val
, begin
, end
;
1683 WCHAR num
[MAX_NUM_DIGITS
];
1686 control
= msi_dialog_add_control( dialog
, rec
, L
"Edit",
1687 WS_BORDER
| WS_TABSTOP
| ES_AUTOHSCROLL
);
1688 control
->handler
= msi_dialog_edit_handler
;
1690 text
= MSI_RecordGetString( rec
, 10 );
1693 begin
= wcschr( text
, '{' );
1694 end
= wcschr( text
, '}' );
1696 if ( begin
&& end
&& end
> begin
&&
1697 begin
[0] >= '0' && begin
[0] <= '9' &&
1698 end
- begin
< MAX_NUM_DIGITS
)
1700 lstrcpynW( num
, begin
+ 1, end
- begin
);
1701 limit
= wcstol( num
, NULL
, 10 );
1703 SendMessageW( control
->hwnd
, EM_SETLIMITTEXT
, limit
, 0 );
1707 prop
= MSI_RecordGetString( rec
, 9 );
1709 control
->property
= strdupW( prop
);
1711 val
= msi_dup_property( dialog
->package
->db
, control
->property
);
1712 SetWindowTextW( control
->hwnd
, val
);
1714 return ERROR_SUCCESS
;
1717 /******************** Masked Edit ********************************************/
1719 #define MASK_MAX_GROUPS 20
1721 struct msi_mask_group
1729 struct msi_maskedit_info
1737 struct msi_mask_group group
[MASK_MAX_GROUPS
];
1740 static BOOL
msi_mask_editable( WCHAR type
)
1755 static void msi_mask_control_change( struct msi_maskedit_info
*info
)
1760 val
= msi_alloc( (info
->num_chars
+1)*sizeof(WCHAR
) );
1761 for( i
=0, n
=0; i
<info
->num_groups
; i
++ )
1763 if (info
->group
[i
].len
== ~0u)
1765 UINT len
= SendMessageW( info
->group
[i
].hwnd
, WM_GETTEXTLENGTH
, 0, 0 );
1766 val
= msi_realloc( val
, (len
+ 1) * sizeof(WCHAR
) );
1767 GetWindowTextW( info
->group
[i
].hwnd
, val
, len
+ 1 );
1771 if (info
->group
[i
].len
+ n
> info
->num_chars
)
1773 ERR("can't fit control %d text into template\n",i
);
1776 if (!msi_mask_editable(info
->group
[i
].type
))
1778 for(r
=0; r
<info
->group
[i
].len
; r
++)
1779 val
[n
+r
] = info
->group
[i
].type
;
1784 r
= GetWindowTextW( info
->group
[i
].hwnd
, &val
[n
], info
->group
[i
].len
+1 );
1785 if( r
!= info
->group
[i
].len
)
1792 TRACE("%d/%d controls were good\n", i
, info
->num_groups
);
1794 if( i
== info
->num_groups
)
1796 TRACE("Set property %s to %s\n", debugstr_w(info
->prop
), debugstr_w(val
));
1797 msi_dialog_set_property( info
->dialog
->package
, info
->prop
, val
);
1798 msi_dialog_evaluate_control_conditions( info
->dialog
);
1803 /* now move to the next control if necessary */
1804 static VOID
msi_mask_next_control( struct msi_maskedit_info
*info
, HWND hWnd
)
1809 for( i
=0; i
<info
->num_groups
; i
++ )
1810 if( info
->group
[i
].hwnd
== hWnd
)
1813 /* don't move from the last control */
1814 if( i
>= (info
->num_groups
-1) )
1817 len
= SendMessageW( hWnd
, WM_GETTEXTLENGTH
, 0, 0 );
1818 if( len
< info
->group
[i
].len
)
1821 hWndNext
= GetNextDlgTabItem( GetParent( hWnd
), hWnd
, FALSE
);
1822 SetFocus( hWndNext
);
1825 static LRESULT WINAPI
1826 MSIMaskedEdit_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1828 struct msi_maskedit_info
*info
;
1831 TRACE("%p %04x %08lx %08lx\n", hWnd
, msg
, wParam
, lParam
);
1833 info
= GetPropW(hWnd
, L
"MSIDATA");
1835 r
= CallWindowProcW(info
->oldproc
, hWnd
, msg
, wParam
, lParam
);
1840 if (HIWORD(wParam
) == EN_CHANGE
)
1842 msi_mask_control_change( info
);
1843 msi_mask_next_control( info
, (HWND
) lParam
);
1847 msi_free( info
->prop
);
1849 RemovePropW( hWnd
, L
"MSIDATA" );
1856 /* fish the various bits of the property out and put them in the control */
1858 msi_maskedit_set_text( struct msi_maskedit_info
*info
, LPCWSTR text
)
1864 for( i
= 0; i
< info
->num_groups
; i
++ )
1866 if( info
->group
[i
].len
< lstrlenW( p
) )
1868 LPWSTR chunk
= strdupW( p
);
1869 chunk
[ info
->group
[i
].len
] = 0;
1870 SetWindowTextW( info
->group
[i
].hwnd
, chunk
);
1875 SetWindowTextW( info
->group
[i
].hwnd
, p
);
1878 p
+= info
->group
[i
].len
;
1882 static struct msi_maskedit_info
* msi_dialog_parse_groups( LPCWSTR mask
)
1884 struct msi_maskedit_info
*info
;
1885 int i
= 0, n
= 0, total
= 0;
1888 TRACE("masked control, template %s\n", debugstr_w(mask
));
1893 info
= msi_alloc_zero( sizeof *info
);
1897 p
= wcschr(mask
, '<');
1903 for( i
=0; i
<MASK_MAX_GROUPS
; i
++ )
1905 /* stop at the end of the string */
1906 if( p
[0] == 0 || p
[0] == '>' )
1910 /* create a group for the empty mask */
1911 info
->group
[0].type
= '&';
1912 info
->group
[0].len
= ~0u;
1918 /* count the number of the same identifier */
1919 for( n
=0; p
[n
] == p
[0]; n
++ )
1921 info
->group
[i
].ofs
= total
;
1922 info
->group
[i
].type
= p
[0];
1926 total
++; /* an extra not part of the group */
1928 info
->group
[i
].len
= n
;
1933 TRACE("%d characters in %d groups\n", total
, i
);
1934 if( i
== MASK_MAX_GROUPS
)
1935 ERR("too many groups in PIDTemplate %s\n", debugstr_w(mask
));
1937 info
->num_chars
= total
;
1938 info
->num_groups
= i
;
1944 msi_maskedit_create_children( struct msi_maskedit_info
*info
, LPCWSTR font
)
1946 DWORD width
, height
, style
, wx
, ww
;
1951 style
= WS_CHILD
| WS_BORDER
| WS_VISIBLE
| WS_TABSTOP
| ES_AUTOHSCROLL
;
1953 GetClientRect( info
->hwnd
, &rect
);
1955 width
= rect
.right
- rect
.left
;
1956 height
= rect
.bottom
- rect
.top
;
1958 for( i
= 0; i
< info
->num_groups
; i
++ )
1960 if (!msi_mask_editable( info
->group
[i
].type
))
1962 if (info
->num_chars
)
1964 wx
= (info
->group
[i
].ofs
* width
) / info
->num_chars
;
1965 ww
= (info
->group
[i
].len
* width
) / info
->num_chars
;
1972 hwnd
= CreateWindowW( L
"Edit", NULL
, style
, wx
, 0, ww
, height
,
1973 info
->hwnd
, NULL
, NULL
, NULL
);
1976 ERR("failed to create mask edit sub window\n");
1980 SendMessageW( hwnd
, EM_LIMITTEXT
, info
->group
[i
].len
, 0 );
1982 msi_dialog_set_font( info
->dialog
, hwnd
,
1983 font
?font
:info
->dialog
->default_font
);
1984 info
->group
[i
].hwnd
= hwnd
;
1989 * office 2003 uses "73931<````=````=````=````=`````>@@@@@"
1990 * delphi 7 uses "<????-??????-??????-????>" and "<???-???>"
1991 * filemaker pro 7 uses "<^^^^=^^^^=^^^^=^^^^=^^^^=^^^^=^^^^^>"
1993 static UINT
msi_dialog_maskedit_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1995 LPWSTR font_mask
, val
= NULL
, font
;
1996 struct msi_maskedit_info
*info
= NULL
;
1997 UINT ret
= ERROR_SUCCESS
;
1998 msi_control
*control
;
2003 font_mask
= msi_get_deformatted_field( dialog
->package
, rec
, 10 );
2004 font
= msi_dialog_get_style( font_mask
, &mask
);
2007 WARN("mask template is empty\n");
2011 info
= msi_dialog_parse_groups( mask
);
2014 ERR("template %s is invalid\n", debugstr_w(mask
));
2018 info
->dialog
= dialog
;
2020 control
= msi_dialog_add_control( dialog
, rec
, L
"Static",
2021 SS_OWNERDRAW
| WS_GROUP
| WS_VISIBLE
);
2024 ERR("Failed to create maskedit container\n");
2025 ret
= ERROR_FUNCTION_FAILED
;
2028 SetWindowLongPtrW( control
->hwnd
, GWL_EXSTYLE
, WS_EX_CONTROLPARENT
);
2030 info
->hwnd
= control
->hwnd
;
2032 /* subclass the static control */
2033 info
->oldproc
= (WNDPROC
) SetWindowLongPtrW( info
->hwnd
, GWLP_WNDPROC
,
2034 (LONG_PTR
)MSIMaskedEdit_WndProc
);
2035 SetPropW( control
->hwnd
, L
"MSIDATA", info
);
2037 prop
= MSI_RecordGetString( rec
, 9 );
2039 info
->prop
= strdupW( prop
);
2041 msi_maskedit_create_children( info
, font
);
2045 val
= msi_dup_property( dialog
->package
->db
, prop
);
2048 msi_maskedit_set_text( info
, val
);
2054 if( ret
!= ERROR_SUCCESS
)
2056 msi_free( font_mask
);
2061 /******************** Progress Bar *****************************************/
2063 static UINT
msi_dialog_progress_bar( msi_dialog
*dialog
, MSIRECORD
*rec
)
2065 msi_control
*control
;
2066 DWORD attributes
, style
;
2069 attributes
= MSI_RecordGetInteger( rec
, 8 );
2070 if( !(attributes
& msidbControlAttributesProgress95
) )
2071 style
|= PBS_SMOOTH
;
2073 control
= msi_dialog_add_control( dialog
, rec
, PROGRESS_CLASSW
, style
);
2075 return ERROR_FUNCTION_FAILED
;
2077 event_subscribe( dialog
, L
"SetProgress", control
->name
, L
"Progress" );
2078 return ERROR_SUCCESS
;
2081 /******************** Path Edit ********************************************/
2083 struct msi_pathedit_info
2086 msi_control
*control
;
2090 static WCHAR
*get_path_property( msi_dialog
*dialog
, msi_control
*control
)
2093 BOOL indirect
= control
->attributes
& msidbControlAttributesIndirect
;
2094 if (!(prop
= msi_dialog_dup_property( dialog
, control
->property
, indirect
))) return NULL
;
2095 path
= msi_dialog_dup_property( dialog
, prop
, TRUE
);
2100 static void msi_dialog_update_pathedit( msi_dialog
*dialog
, msi_control
*control
)
2104 if (!control
&& !(control
= msi_dialog_find_control_by_type( dialog
, L
"PathEdit" )))
2107 if (!(path
= get_path_property( dialog
, control
))) return;
2108 SetWindowTextW( control
->hwnd
, path
);
2109 SendMessageW( control
->hwnd
, EM_SETSEL
, 0, -1 );
2113 /* FIXME: test when this should fail */
2114 static BOOL
msi_dialog_verify_path( LPWSTR path
)
2119 if ( PathIsRelativeW( path
) )
2125 /* returns TRUE if the path is valid, FALSE otherwise */
2126 static BOOL
msi_dialog_onkillfocus( msi_dialog
*dialog
, msi_control
*control
)
2132 indirect
= control
->attributes
& msidbControlAttributesIndirect
;
2133 prop
= msi_dialog_dup_property( dialog
, control
->property
, indirect
);
2135 buf
= msi_get_window_text( control
->hwnd
);
2137 if ( !msi_dialog_verify_path( buf
) )
2139 /* FIXME: display an error message box */
2140 ERR("Invalid path %s\n", debugstr_w( buf
));
2142 SetFocus( control
->hwnd
);
2147 msi_dialog_set_property( dialog
->package
, prop
, buf
);
2150 msi_dialog_update_pathedit( dialog
, control
);
2152 TRACE("edit %s contents changed, set %s\n", debugstr_w(control
->name
),
2161 static LRESULT WINAPI
MSIPathEdit_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
2163 struct msi_pathedit_info
*info
= GetPropW(hWnd
, L
"MSIDATA");
2166 TRACE("%p %04x %08lx %08lx\n", hWnd
, msg
, wParam
, lParam
);
2168 if ( msg
== WM_KILLFOCUS
)
2170 /* if the path is invalid, don't handle this message */
2171 if ( !msi_dialog_onkillfocus( info
->dialog
, info
->control
) )
2175 r
= CallWindowProcW(info
->oldproc
, hWnd
, msg
, wParam
, lParam
);
2177 if ( msg
== WM_NCDESTROY
)
2180 RemovePropW( hWnd
, L
"MSIDATA" );
2186 static UINT
msi_dialog_pathedit_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
2188 struct msi_pathedit_info
*info
;
2189 msi_control
*control
;
2192 info
= msi_alloc( sizeof *info
);
2194 return ERROR_FUNCTION_FAILED
;
2196 control
= msi_dialog_add_control( dialog
, rec
, L
"Edit",
2197 WS_BORDER
| WS_TABSTOP
);
2198 control
->attributes
= MSI_RecordGetInteger( rec
, 8 );
2199 prop
= MSI_RecordGetString( rec
, 9 );
2200 control
->property
= msi_dialog_dup_property( dialog
, prop
, FALSE
);
2201 control
->update
= msi_dialog_update_pathedit
;
2203 info
->dialog
= dialog
;
2204 info
->control
= control
;
2205 info
->oldproc
= (WNDPROC
) SetWindowLongPtrW( control
->hwnd
, GWLP_WNDPROC
,
2206 (LONG_PTR
)MSIPathEdit_WndProc
);
2207 SetPropW( control
->hwnd
, L
"MSIDATA", info
);
2209 msi_dialog_update_pathedit( dialog
, control
);
2211 return ERROR_SUCCESS
;
2214 static UINT
msi_dialog_radiogroup_handler( msi_dialog
*dialog
, msi_control
*control
, WPARAM param
)
2216 if (HIWORD(param
) != BN_CLICKED
)
2217 return ERROR_SUCCESS
;
2219 TRACE("clicked radio button %s, set %s\n", debugstr_w(control
->name
), debugstr_w(control
->property
));
2221 msi_dialog_set_property( dialog
->package
, control
->property
, control
->name
);
2223 return msi_dialog_button_handler( dialog
, control
, param
);
2226 /* radio buttons are a bit different from normal controls */
2227 static UINT
msi_dialog_create_radiobutton( MSIRECORD
*rec
, LPVOID param
)
2229 radio_button_group_descr
*group
= param
;
2230 msi_dialog
*dialog
= group
->dialog
;
2231 msi_control
*control
;
2232 LPCWSTR prop
, text
, name
;
2233 DWORD style
= WS_CHILD
| WS_VISIBLE
| WS_TABSTOP
| BS_AUTORADIOBUTTON
| BS_MULTILINE
;
2235 name
= MSI_RecordGetString( rec
, 3 );
2236 text
= MSI_RecordGetString( rec
, 8 );
2238 control
= dialog_create_window( dialog
, rec
, 0, L
"BUTTON", name
, text
, style
,
2239 group
->parent
->hwnd
);
2241 return ERROR_FUNCTION_FAILED
;
2242 control
->handler
= msi_dialog_radiogroup_handler
;
2244 if (group
->propval
&& !wcscmp( control
->name
, group
->propval
))
2245 SendMessageW(control
->hwnd
, BM_SETCHECK
, BST_CHECKED
, 0);
2247 prop
= MSI_RecordGetString( rec
, 1 );
2249 control
->property
= strdupW( prop
);
2251 return ERROR_SUCCESS
;
2254 static BOOL CALLBACK
msi_radioground_child_enum( HWND hWnd
, LPARAM lParam
)
2256 EnableWindow( hWnd
, lParam
);
2260 static LRESULT WINAPI
MSIRadioGroup_WndProc( HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
2262 WNDPROC oldproc
= (WNDPROC
)GetPropW( hWnd
, L
"MSIDATA" );
2265 TRACE("hWnd %p msg %04x wParam 0x%08lx lParam 0x%08lx\n", hWnd
, msg
, wParam
, lParam
);
2267 if (msg
== WM_COMMAND
) /* Forward notifications to dialog */
2268 SendMessageW( GetParent( hWnd
), msg
, wParam
, lParam
);
2270 r
= CallWindowProcW( oldproc
, hWnd
, msg
, wParam
, lParam
);
2272 /* make sure the radio buttons show as disabled if the parent is disabled */
2273 if (msg
== WM_ENABLE
)
2274 EnumChildWindows( hWnd
, msi_radioground_child_enum
, wParam
);
2279 static UINT
msi_dialog_radiogroup_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
2283 msi_control
*control
;
2285 radio_button_group_descr group
;
2286 MSIPACKAGE
*package
= dialog
->package
;
2288 DWORD attr
, style
= WS_GROUP
;
2290 prop
= MSI_RecordGetString( rec
, 9 );
2292 TRACE("%p %p %s\n", dialog
, rec
, debugstr_w( prop
));
2294 attr
= MSI_RecordGetInteger( rec
, 8 );
2295 if (attr
& msidbControlAttributesVisible
)
2296 style
|= WS_VISIBLE
;
2297 if (~attr
& msidbControlAttributesEnabled
)
2298 style
|= WS_DISABLED
;
2299 if (attr
& msidbControlAttributesHasBorder
)
2300 style
|= BS_GROUPBOX
;
2302 style
|= BS_OWNERDRAW
;
2304 /* Create parent group box to hold radio buttons */
2305 control
= msi_dialog_add_control( dialog
, rec
, L
"BUTTON", style
);
2307 return ERROR_FUNCTION_FAILED
;
2309 oldproc
= (WNDPROC
) SetWindowLongPtrW( control
->hwnd
, GWLP_WNDPROC
,
2310 (LONG_PTR
)MSIRadioGroup_WndProc
);
2311 SetPropW(control
->hwnd
, L
"MSIDATA", oldproc
);
2312 SetWindowLongPtrW( control
->hwnd
, GWL_EXSTYLE
, WS_EX_CONTROLPARENT
);
2315 control
->property
= strdupW( prop
);
2317 /* query the Radio Button table for all control in this group */
2318 r
= MSI_OpenQuery( package
->db
, &view
, L
"SELECT * FROM `RadioButton` WHERE `Property` = '%s'", prop
);
2319 if( r
!= ERROR_SUCCESS
)
2321 ERR("query failed for dialog %s radio group %s\n",
2322 debugstr_w(dialog
->name
), debugstr_w(prop
));
2323 return ERROR_INVALID_PARAMETER
;
2326 group
.dialog
= dialog
;
2327 group
.parent
= control
;
2328 group
.propval
= msi_dup_property( dialog
->package
->db
, control
->property
);
2330 r
= MSI_IterateRecords( view
, 0, msi_dialog_create_radiobutton
, &group
);
2331 msiobj_release( &view
->hdr
);
2332 msi_free( group
.propval
);
2337 msi_seltree_sync_item_state( HWND hwnd
, MSIFEATURE
*feature
, HTREEITEM hItem
)
2340 DWORD index
= feature
->ActionRequest
;
2342 TRACE("Feature %s -> %d %d %d\n", debugstr_w(feature
->Title
),
2343 feature
->Installed
, feature
->Action
, feature
->ActionRequest
);
2345 if (index
== INSTALLSTATE_UNKNOWN
)
2346 index
= INSTALLSTATE_ABSENT
;
2348 tvi
.mask
= TVIF_STATE
;
2350 tvi
.state
= INDEXTOSTATEIMAGEMASK( index
);
2351 tvi
.stateMask
= TVIS_STATEIMAGEMASK
;
2353 SendMessageW( hwnd
, TVM_SETITEMW
, 0, (LPARAM
) &tvi
);
2357 msi_seltree_popup_menu( HWND hwnd
, INT x
, INT y
)
2362 /* create a menu to display */
2363 hMenu
= CreatePopupMenu();
2365 /* FIXME: load strings from resources */
2366 AppendMenuA( hMenu
, MF_ENABLED
, INSTALLSTATE_LOCAL
, "Install feature locally");
2367 AppendMenuA( hMenu
, MF_ENABLED
, USER_INSTALLSTATE_ALL
, "Install entire feature");
2368 AppendMenuA( hMenu
, MF_ENABLED
, INSTALLSTATE_ADVERTISED
, "Install on demand");
2369 AppendMenuA( hMenu
, MF_ENABLED
, INSTALLSTATE_ABSENT
, "Don't install");
2370 r
= TrackPopupMenu( hMenu
, TPM_LEFTALIGN
| TPM_TOPALIGN
| TPM_RETURNCMD
,
2371 x
, y
, 0, hwnd
, NULL
);
2372 DestroyMenu( hMenu
);
2377 msi_seltree_update_feature_installstate( HWND hwnd
, HTREEITEM hItem
,
2378 MSIPACKAGE
*package
, MSIFEATURE
*feature
, INSTALLSTATE state
)
2380 feature
->ActionRequest
= state
;
2381 msi_seltree_sync_item_state( hwnd
, feature
, hItem
);
2382 ACTION_UpdateComponentStates( package
, feature
);
2386 msi_seltree_update_siblings_and_children_installstate( HWND hwnd
, HTREEITEM curr
,
2387 MSIPACKAGE
*package
, INSTALLSTATE state
)
2389 /* update all siblings */
2392 MSIFEATURE
*feature
;
2395 feature
= msi_seltree_feature_from_item( hwnd
, curr
);
2396 msi_seltree_update_feature_installstate( hwnd
, curr
, package
, feature
, state
);
2398 /* update this sibling's children */
2399 child
= (HTREEITEM
)SendMessageW( hwnd
, TVM_GETNEXTITEM
, (WPARAM
)TVGN_CHILD
, (LPARAM
)curr
);
2401 msi_seltree_update_siblings_and_children_installstate( hwnd
, child
,
2404 while ((curr
= (HTREEITEM
)SendMessageW( hwnd
, TVM_GETNEXTITEM
, (WPARAM
)TVGN_NEXT
, (LPARAM
)curr
)));
2408 msi_seltree_menu( HWND hwnd
, HTREEITEM hItem
)
2410 struct msi_selection_tree_info
*info
;
2411 MSIFEATURE
*feature
;
2412 MSIPACKAGE
*package
;
2420 info
= GetPropW(hwnd
, L
"MSIDATA");
2421 package
= info
->dialog
->package
;
2423 feature
= msi_seltree_feature_from_item( hwnd
, hItem
);
2426 ERR("item %p feature was NULL\n", hItem
);
2430 /* get the item's rectangle to put the menu just below it */
2432 SendMessageW( hwnd
, TVM_GETITEMRECT
, 0, (LPARAM
) &u
.rc
);
2433 MapWindowPoints( hwnd
, NULL
, u
.pt
, 2 );
2435 r
= msi_seltree_popup_menu( hwnd
, u
.rc
.left
, u
.rc
.top
);
2439 case USER_INSTALLSTATE_ALL
:
2440 r
= INSTALLSTATE_LOCAL
;
2442 case INSTALLSTATE_ADVERTISED
:
2443 case INSTALLSTATE_ABSENT
:
2446 child
= (HTREEITEM
)SendMessageW( hwnd
, TVM_GETNEXTITEM
, (WPARAM
)TVGN_CHILD
, (LPARAM
)hItem
);
2448 msi_seltree_update_siblings_and_children_installstate( hwnd
, child
, package
, r
);
2451 case INSTALLSTATE_LOCAL
:
2452 msi_seltree_update_feature_installstate( hwnd
, hItem
, package
, feature
, r
);
2459 static LRESULT WINAPI
2460 MSISelectionTree_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
2462 struct msi_selection_tree_info
*info
;
2463 TVHITTESTINFO tvhti
;
2466 TRACE("%p %04x %08lx %08lx\n", hWnd
, msg
, wParam
, lParam
);
2468 info
= GetPropW(hWnd
, L
"MSIDATA");
2472 case WM_LBUTTONDOWN
:
2473 tvhti
.pt
.x
= (short)LOWORD( lParam
);
2474 tvhti
.pt
.y
= (short)HIWORD( lParam
);
2477 CallWindowProcW(info
->oldproc
, hWnd
, TVM_HITTEST
, 0, (LPARAM
) &tvhti
);
2478 if (tvhti
.flags
& TVHT_ONITEMSTATEICON
)
2479 return msi_seltree_menu( hWnd
, tvhti
.hItem
);
2482 r
= CallWindowProcW(info
->oldproc
, hWnd
, msg
, wParam
, lParam
);
2488 RemovePropW( hWnd
, L
"MSIDATA" );
2495 msi_seltree_add_child_features( MSIPACKAGE
*package
, HWND hwnd
,
2496 LPCWSTR parent
, HTREEITEM hParent
)
2498 struct msi_selection_tree_info
*info
= GetPropW( hwnd
, L
"MSIDATA" );
2499 MSIFEATURE
*feature
;
2500 TVINSERTSTRUCTW tvis
;
2501 HTREEITEM hitem
, hfirst
= NULL
;
2503 LIST_FOR_EACH_ENTRY( feature
, &package
->features
, MSIFEATURE
, entry
)
2505 if ( parent
&& feature
->Feature_Parent
&& wcscmp( parent
, feature
->Feature_Parent
))
2507 else if ( parent
&& !feature
->Feature_Parent
)
2509 else if ( !parent
&& feature
->Feature_Parent
)
2512 if ( !feature
->Title
)
2515 if ( !feature
->Display
)
2518 memset( &tvis
, 0, sizeof tvis
);
2519 tvis
.hParent
= hParent
;
2520 tvis
.hInsertAfter
= TVI_LAST
;
2521 tvis
.u
.item
.mask
= TVIF_TEXT
| TVIF_PARAM
;
2522 tvis
.u
.item
.pszText
= feature
->Title
;
2523 tvis
.u
.item
.lParam
= (LPARAM
) feature
;
2525 hitem
= (HTREEITEM
) SendMessageW( hwnd
, TVM_INSERTITEMW
, 0, (LPARAM
) &tvis
);
2532 msi_seltree_sync_item_state( hwnd
, feature
, hitem
);
2533 msi_seltree_add_child_features( package
, hwnd
,
2534 feature
->Feature
, hitem
);
2536 /* the node is expanded if Display is odd */
2537 if ( feature
->Display
% 2 != 0 )
2538 SendMessageW( hwnd
, TVM_EXPAND
, TVE_EXPAND
, (LPARAM
) hitem
);
2541 /* select the first item */
2542 SendMessageW( hwnd
, TVM_SELECTITEM
, TVGN_CARET
| TVGN_DROPHILITE
, (LPARAM
) hfirst
);
2543 info
->selected
= hfirst
;
2546 static void msi_seltree_create_imagelist( HWND hwnd
)
2548 const int bm_width
= 32, bm_height
= 16, bm_count
= 3;
2549 const int bm_resource
= 0x1001;
2554 himl
= ImageList_Create( bm_width
, bm_height
, FALSE
, 4, 0 );
2557 ERR("failed to create image list\n");
2561 for (i
=0; i
<bm_count
; i
++)
2563 hbmp
= LoadBitmapW( msi_hInstance
, MAKEINTRESOURCEW(i
+bm_resource
) );
2566 ERR("failed to load bitmap %d\n", i
);
2571 * Add a dummy bitmap at offset zero because the treeview
2572 * can't use it as a state mask (zero means no user state).
2575 ImageList_Add( himl
, hbmp
, NULL
);
2577 ImageList_Add( himl
, hbmp
, NULL
);
2580 SendMessageW( hwnd
, TVM_SETIMAGELIST
, TVSIL_STATE
, (LPARAM
)himl
);
2583 static UINT
msi_dialog_seltree_handler( msi_dialog
*dialog
,
2584 msi_control
*control
, WPARAM param
)
2586 struct msi_selection_tree_info
*info
= GetPropW( control
->hwnd
, L
"MSIDATA" );
2587 LPNMTREEVIEWW tv
= (LPNMTREEVIEWW
)param
;
2588 MSIRECORD
*row
, *rec
;
2590 MSIFEATURE
*feature
;
2591 LPCWSTR dir
, title
= NULL
;
2592 UINT r
= ERROR_SUCCESS
;
2594 if (tv
->hdr
.code
!= TVN_SELCHANGINGW
)
2595 return ERROR_SUCCESS
;
2597 info
->selected
= tv
->itemNew
.hItem
;
2599 if (!(tv
->itemNew
.mask
& TVIF_TEXT
))
2601 feature
= msi_seltree_feature_from_item( control
->hwnd
, tv
->itemNew
.hItem
);
2603 title
= feature
->Title
;
2606 title
= tv
->itemNew
.pszText
;
2608 row
= MSI_QueryGetRecord( dialog
->package
->db
, L
"SELECT * FROM `Feature` WHERE `Title` = '%s'", title
);
2610 return ERROR_FUNCTION_FAILED
;
2612 rec
= MSI_CreateRecord( 1 );
2614 MSI_RecordSetStringW( rec
, 1, MSI_RecordGetString( row
, 4 ) );
2615 msi_event_fire( dialog
->package
, L
"SelectionDescription", rec
);
2617 dir
= MSI_RecordGetString( row
, 7 );
2620 folder
= msi_get_loaded_folder( dialog
->package
, dir
);
2623 r
= ERROR_FUNCTION_FAILED
;
2626 MSI_RecordSetStringW( rec
, 1, folder
->ResolvedTarget
);
2629 MSI_RecordSetStringW( rec
, 1, NULL
);
2631 msi_event_fire( dialog
->package
, L
"SelectionPath", rec
);
2634 msiobj_release(&row
->hdr
);
2635 msiobj_release(&rec
->hdr
);
2640 static UINT
msi_dialog_selection_tree( msi_dialog
*dialog
, MSIRECORD
*rec
)
2642 msi_control
*control
;
2643 LPCWSTR prop
, control_name
;
2644 MSIPACKAGE
*package
= dialog
->package
;
2646 struct msi_selection_tree_info
*info
;
2648 info
= msi_alloc( sizeof *info
);
2650 return ERROR_FUNCTION_FAILED
;
2652 /* create the treeview control */
2653 style
= TVS_HASLINES
| TVS_HASBUTTONS
| TVS_LINESATROOT
;
2654 style
|= WS_GROUP
| WS_VSCROLL
| WS_TABSTOP
;
2655 control
= msi_dialog_add_control( dialog
, rec
, WC_TREEVIEWW
, style
);
2659 return ERROR_FUNCTION_FAILED
;
2662 control
->handler
= msi_dialog_seltree_handler
;
2663 control_name
= MSI_RecordGetString( rec
, 2 );
2664 control
->attributes
= MSI_RecordGetInteger( rec
, 8 );
2665 prop
= MSI_RecordGetString( rec
, 9 );
2666 control
->property
= msi_dialog_dup_property( dialog
, prop
, FALSE
);
2669 info
->dialog
= dialog
;
2670 info
->hwnd
= control
->hwnd
;
2671 info
->oldproc
= (WNDPROC
) SetWindowLongPtrW( control
->hwnd
, GWLP_WNDPROC
,
2672 (LONG_PTR
)MSISelectionTree_WndProc
);
2673 SetPropW( control
->hwnd
, L
"MSIDATA", info
);
2675 event_subscribe( dialog
, L
"SelectionPath", control_name
, L
"Property" );
2678 msi_seltree_create_imagelist( control
->hwnd
);
2679 msi_seltree_add_child_features( package
, control
->hwnd
, NULL
, NULL
);
2681 return ERROR_SUCCESS
;
2684 /******************** Group Box ***************************************/
2686 static UINT
msi_dialog_group_box( msi_dialog
*dialog
, MSIRECORD
*rec
)
2688 msi_control
*control
;
2691 style
= BS_GROUPBOX
| WS_CHILD
| WS_GROUP
;
2692 control
= msi_dialog_add_control( dialog
, rec
, WC_BUTTONW
, style
);
2694 return ERROR_FUNCTION_FAILED
;
2696 return ERROR_SUCCESS
;
2699 /******************** List Box ***************************************/
2701 struct msi_listbox_info
2711 static LRESULT WINAPI
MSIListBox_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
2713 struct msi_listbox_info
*info
;
2717 TRACE("%p %04x %08lx %08lx\n", hWnd
, msg
, wParam
, lParam
);
2719 info
= GetPropW( hWnd
, L
"MSIDATA" );
2723 r
= CallWindowProcW( info
->oldproc
, hWnd
, msg
, wParam
, lParam
);
2728 for (j
= 0; j
< info
->num_items
; j
++)
2729 msi_free( info
->items
[j
] );
2730 msi_free( info
->items
);
2732 RemovePropW( hWnd
, L
"MSIDATA" );
2739 static UINT
msi_listbox_add_item( MSIRECORD
*rec
, LPVOID param
)
2741 struct msi_listbox_info
*info
= param
;
2742 LPCWSTR value
, text
;
2745 value
= MSI_RecordGetString( rec
, 3 );
2746 text
= MSI_RecordGetString( rec
, 4 );
2748 info
->items
[info
->addpos_items
] = strdupW( value
);
2750 pos
= SendMessageW( info
->hwnd
, LB_ADDSTRING
, 0, (LPARAM
)text
);
2751 SendMessageW( info
->hwnd
, LB_SETITEMDATA
, pos
, (LPARAM
)info
->items
[info
->addpos_items
] );
2752 info
->addpos_items
++;
2753 return ERROR_SUCCESS
;
2756 static UINT
msi_listbox_add_items( struct msi_listbox_info
*info
, LPCWSTR property
)
2762 r
= MSI_OpenQuery( info
->dialog
->package
->db
, &view
,
2763 L
"SELECT * FROM `ListBox` WHERE `Property` = '%s' ORDER BY `Order`", property
);
2764 if ( r
!= ERROR_SUCCESS
)
2767 /* just get the number of records */
2769 r
= MSI_IterateRecords( view
, &count
, NULL
, NULL
);
2770 if (r
!= ERROR_SUCCESS
)
2772 msiobj_release( &view
->hdr
);
2775 info
->num_items
= count
;
2776 info
->items
= msi_alloc( sizeof(*info
->items
) * count
);
2778 r
= MSI_IterateRecords( view
, NULL
, msi_listbox_add_item
, info
);
2779 msiobj_release( &view
->hdr
);
2783 static UINT
msi_dialog_listbox_handler( msi_dialog
*dialog
,
2784 msi_control
*control
, WPARAM param
)
2786 struct msi_listbox_info
*info
;
2790 if( HIWORD(param
) != LBN_SELCHANGE
)
2791 return ERROR_SUCCESS
;
2793 info
= GetPropW( control
->hwnd
, L
"MSIDATA" );
2794 index
= SendMessageW( control
->hwnd
, LB_GETCURSEL
, 0, 0 );
2795 value
= (LPCWSTR
) SendMessageW( control
->hwnd
, LB_GETITEMDATA
, index
, 0 );
2797 msi_dialog_set_property( info
->dialog
->package
, control
->property
, value
);
2798 msi_dialog_evaluate_control_conditions( info
->dialog
);
2800 return ERROR_SUCCESS
;
2803 static UINT
msi_dialog_list_box( msi_dialog
*dialog
, MSIRECORD
*rec
)
2805 struct msi_listbox_info
*info
;
2806 msi_control
*control
;
2807 DWORD attributes
, style
;
2810 info
= msi_alloc( sizeof *info
);
2812 return ERROR_FUNCTION_FAILED
;
2814 style
= WS_TABSTOP
| WS_GROUP
| WS_CHILD
| LBS_NOTIFY
| WS_VSCROLL
| WS_BORDER
;
2815 attributes
= MSI_RecordGetInteger( rec
, 8 );
2816 if (~attributes
& msidbControlAttributesSorted
)
2819 control
= msi_dialog_add_control( dialog
, rec
, WC_LISTBOXW
, style
);
2823 return ERROR_FUNCTION_FAILED
;
2826 control
->handler
= msi_dialog_listbox_handler
;
2828 prop
= MSI_RecordGetString( rec
, 9 );
2829 control
->property
= msi_dialog_dup_property( dialog
, prop
, FALSE
);
2832 info
->dialog
= dialog
;
2833 info
->hwnd
= control
->hwnd
;
2835 info
->addpos_items
= 0;
2836 info
->oldproc
= (WNDPROC
)SetWindowLongPtrW( control
->hwnd
, GWLP_WNDPROC
,
2837 (LONG_PTR
)MSIListBox_WndProc
);
2838 SetPropW( control
->hwnd
, L
"MSIDATA", info
);
2840 if ( control
->property
)
2841 msi_listbox_add_items( info
, control
->property
);
2843 return ERROR_SUCCESS
;
2846 /******************** Directory Combo ***************************************/
2848 static void msi_dialog_update_directory_combo( msi_dialog
*dialog
, msi_control
*control
)
2852 if (!control
&& !(control
= msi_dialog_find_control_by_type( dialog
, L
"DirectoryCombo" )))
2855 if (!(path
= get_path_property( dialog
, control
))) return;
2856 PathStripPathW( path
);
2857 PathRemoveBackslashW( path
);
2859 SendMessageW( control
->hwnd
, CB_INSERTSTRING
, 0, (LPARAM
)path
);
2860 SendMessageW( control
->hwnd
, CB_SETCURSEL
, 0, 0 );
2865 static UINT
msi_dialog_directory_combo( msi_dialog
*dialog
, MSIRECORD
*rec
)
2867 msi_control
*control
;
2871 /* FIXME: use CBS_OWNERDRAWFIXED and add owner draw code */
2872 style
= CBS_DROPDOWNLIST
| CBS_HASSTRINGS
| WS_CHILD
|
2873 WS_GROUP
| WS_TABSTOP
| WS_VSCROLL
;
2874 control
= msi_dialog_add_control( dialog
, rec
, WC_COMBOBOXW
, style
);
2876 return ERROR_FUNCTION_FAILED
;
2878 control
->attributes
= MSI_RecordGetInteger( rec
, 8 );
2879 prop
= MSI_RecordGetString( rec
, 9 );
2880 control
->property
= msi_dialog_dup_property( dialog
, prop
, FALSE
);
2882 msi_dialog_update_directory_combo( dialog
, control
);
2884 return ERROR_SUCCESS
;
2887 /******************** Directory List ***************************************/
2889 static void msi_dialog_update_directory_list( msi_dialog
*dialog
, msi_control
*control
)
2891 WCHAR dir_spec
[MAX_PATH
], *path
;
2892 WIN32_FIND_DATAW wfd
;
2896 if (!control
&& !(control
= msi_dialog_find_control_by_type( dialog
, L
"DirectoryList" )))
2899 /* clear the list-view */
2900 SendMessageW( control
->hwnd
, LVM_DELETEALLITEMS
, 0, 0 );
2902 if (!(path
= get_path_property( dialog
, control
))) return;
2903 lstrcpyW( dir_spec
, path
);
2904 lstrcatW( dir_spec
, L
"*" );
2906 file
= FindFirstFileW( dir_spec
, &wfd
);
2907 if (file
== INVALID_HANDLE_VALUE
)
2915 if ( wfd
.dwFileAttributes
!= FILE_ATTRIBUTE_DIRECTORY
)
2918 if ( !wcscmp( wfd
.cFileName
, L
"." ) || !wcscmp( wfd
.cFileName
, L
".." ) )
2921 item
.mask
= LVIF_TEXT
;
2922 item
.cchTextMax
= MAX_PATH
;
2925 item
.pszText
= wfd
.cFileName
;
2927 SendMessageW( control
->hwnd
, LVM_INSERTITEMW
, 0, (LPARAM
)&item
);
2928 } while ( FindNextFileW( file
, &wfd
) );
2934 static UINT
msi_dialog_directorylist_up( msi_dialog
*dialog
)
2936 msi_control
*control
;
2937 LPWSTR prop
, path
, ptr
;
2940 control
= msi_dialog_find_control_by_type( dialog
, L
"DirectoryList" );
2941 indirect
= control
->attributes
& msidbControlAttributesIndirect
;
2942 prop
= msi_dialog_dup_property( dialog
, control
->property
, indirect
);
2943 path
= msi_dialog_dup_property( dialog
, prop
, TRUE
);
2945 /* strip off the last directory */
2946 ptr
= PathFindFileNameW( path
);
2947 if (ptr
!= path
) *(ptr
- 1) = '\0';
2948 PathAddBackslashW( path
);
2950 msi_dialog_set_property( dialog
->package
, prop
, path
);
2952 msi_dialog_update_directory_list( dialog
, NULL
);
2953 msi_dialog_update_directory_combo( dialog
, NULL
);
2954 msi_dialog_update_pathedit( dialog
, NULL
);
2959 return ERROR_SUCCESS
;
2962 static WCHAR
*get_unique_folder_name( const WCHAR
*root
, int *ret_len
)
2964 WCHAR newfolder
[MAX_PATH
], *path
, *ptr
;
2967 len
= LoadStringW( msi_hInstance
, IDS_NEWFOLDER
, newfolder
, ARRAY_SIZE(newfolder
) );
2968 len
+= lstrlenW(root
) + 1;
2969 if (!(path
= msi_alloc( (len
+ 4) * sizeof(WCHAR
) ))) return NULL
;
2970 lstrcpyW( path
, root
);
2971 lstrcatW( path
, newfolder
);
2975 if (GetFileAttributesW( path
) == INVALID_FILE_ATTRIBUTES
) break;
2981 swprintf( path
, len
+ 4, L
"%s%s %u", root
, newfolder
, count
++ );
2984 ptr
= wcsrchr( path
, '\\' ) + 1;
2985 *ret_len
= lstrlenW(ptr
);
2986 memmove( path
, ptr
, *ret_len
* sizeof(WCHAR
) );
2990 static UINT
msi_dialog_directorylist_new( msi_dialog
*dialog
)
2992 msi_control
*control
;
2997 control
= msi_dialog_find_control_by_type( dialog
, L
"DirectoryList" );
2999 if (!(path
= get_path_property( dialog
, control
))) return ERROR_OUTOFMEMORY
;
3001 item
.mask
= LVIF_TEXT
;
3004 item
.pszText
= get_unique_folder_name( path
, &item
.cchTextMax
);
3006 index
= SendMessageW( control
->hwnd
, LVM_INSERTITEMW
, 0, (LPARAM
)&item
);
3007 SendMessageW( control
->hwnd
, LVM_ENSUREVISIBLE
, index
, 0 );
3008 SendMessageW( control
->hwnd
, LVM_EDITLABELW
, index
, -1 );
3011 msi_free( item
.pszText
);
3012 return ERROR_SUCCESS
;
3015 static UINT
msi_dialog_dirlist_handler( msi_dialog
*dialog
, msi_control
*control
, WPARAM param
)
3017 NMHDR
*nmhdr
= (NMHDR
*)param
;
3018 WCHAR text
[MAX_PATH
], *new_path
, *path
, *prop
;
3021 switch (nmhdr
->code
)
3023 case LVN_ENDLABELEDITW
:
3025 NMLVDISPINFOW
*info
= (NMLVDISPINFOW
*)param
;
3026 if (!info
->item
.pszText
) return ERROR_SUCCESS
;
3027 lstrcpynW( text
, info
->item
.pszText
, ARRAY_SIZE(text
) );
3028 text
[ARRAY_SIZE(text
) - 1] = 0;
3031 case LVN_ITEMACTIVATE
:
3034 int index
= SendMessageW( control
->hwnd
, LVM_GETNEXTITEM
, -1, LVNI_SELECTED
);
3037 ERR("no list-view item selected\n");
3038 return ERROR_FUNCTION_FAILED
;
3042 item
.pszText
= text
;
3043 item
.cchTextMax
= MAX_PATH
;
3044 SendMessageW( control
->hwnd
, LVM_GETITEMTEXTW
, index
, (LPARAM
)&item
);
3045 text
[ARRAY_SIZE(text
) - 1] = 0;
3049 return ERROR_SUCCESS
;
3052 indirect
= control
->attributes
& msidbControlAttributesIndirect
;
3053 prop
= msi_dialog_dup_property( dialog
, control
->property
, indirect
);
3054 path
= msi_dialog_dup_property( dialog
, prop
, TRUE
);
3056 if (!(new_path
= msi_alloc( (lstrlenW(path
) + lstrlenW(text
) + 2) * sizeof(WCHAR
) )))
3060 return ERROR_OUTOFMEMORY
;
3062 lstrcpyW( new_path
, path
);
3063 lstrcatW( new_path
, text
);
3064 if (nmhdr
->code
== LVN_ENDLABELEDITW
) CreateDirectoryW( new_path
, NULL
);
3065 lstrcatW( new_path
, L
"\\" );
3067 msi_dialog_set_property( dialog
->package
, prop
, new_path
);
3069 msi_dialog_update_directory_list( dialog
, NULL
);
3070 msi_dialog_update_directory_combo( dialog
, NULL
);
3071 msi_dialog_update_pathedit( dialog
, NULL
);
3075 msi_free( new_path
);
3077 return ERROR_SUCCESS
;
3080 static UINT
msi_dialog_directory_list( msi_dialog
*dialog
, MSIRECORD
*rec
)
3082 msi_control
*control
;
3086 style
= LVS_LIST
| WS_VSCROLL
| LVS_SHAREIMAGELISTS
| LVS_EDITLABELS
|
3087 LVS_AUTOARRANGE
| LVS_SINGLESEL
| WS_BORDER
|
3088 LVS_SORTASCENDING
| WS_CHILD
| WS_GROUP
| WS_TABSTOP
;
3089 control
= msi_dialog_add_control( dialog
, rec
, WC_LISTVIEWW
, style
);
3091 return ERROR_FUNCTION_FAILED
;
3093 control
->attributes
= MSI_RecordGetInteger( rec
, 8 );
3094 control
->handler
= msi_dialog_dirlist_handler
;
3095 prop
= MSI_RecordGetString( rec
, 9 );
3096 control
->property
= msi_dialog_dup_property( dialog
, prop
, FALSE
);
3098 /* double click to activate an item in the list */
3099 SendMessageW( control
->hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
,
3100 0, LVS_EX_TWOCLICKACTIVATE
);
3102 msi_dialog_update_directory_list( dialog
, control
);
3104 return ERROR_SUCCESS
;
3107 /******************** VolumeCost List ***************************************/
3109 static BOOL
str_is_number( LPCWSTR str
)
3113 for (i
= 0; i
< lstrlenW( str
); i
++)
3114 if (!iswdigit(str
[i
]))
3120 static const WCHAR column_keys
[][80] =
3122 L
"VolumeCostVolume",
3124 L
"VolumeCostAvailable",
3125 L
"VolumeCostRequired",
3126 L
"VolumeCostDifference",
3129 static void msi_dialog_vcl_add_columns( msi_dialog
*dialog
, msi_control
*control
, MSIRECORD
*rec
)
3131 LPCWSTR text
= MSI_RecordGetString( rec
, 10 );
3132 LPCWSTR begin
= text
, end
;
3139 while ((begin
= wcschr( begin
, '{' )) && count
< 5)
3141 if (!(end
= wcschr( begin
, '}' )))
3144 num
= msi_alloc( (end
-begin
+1)*sizeof(WCHAR
) );
3148 lstrcpynW( num
, begin
+ 1, end
- begin
);
3149 begin
+= end
- begin
+ 1;
3151 /* empty braces or '0' hides the column */
3152 if ( !num
[0] || !wcscmp( num
, L
"0" ) )
3159 /* the width must be a positive number
3160 * if a width is invalid, all remaining columns are hidden
3162 if ( !wcsncmp( num
, L
"-", 1 ) || !str_is_number( num
) ) {
3167 ZeroMemory( &lvc
, sizeof(lvc
) );
3168 lvc
.mask
= LVCF_TEXT
| LVCF_WIDTH
| LVCF_SUBITEM
;
3169 lvc
.cx
= wcstol( num
, NULL
, 10 );
3170 lvc
.pszText
= msi_dialog_get_uitext( dialog
, column_keys
[count
] );
3172 SendMessageW( control
->hwnd
, LVM_INSERTCOLUMNW
, count
++, (LPARAM
)&lvc
);
3173 msi_free( lvc
.pszText
);
3178 static LONGLONG
msi_vcl_get_cost( msi_dialog
*dialog
)
3180 MSIFEATURE
*feature
;
3182 LONGLONG total_cost
= 0;
3184 LIST_FOR_EACH_ENTRY( feature
, &dialog
->package
->features
, MSIFEATURE
, entry
)
3186 if (ERROR_SUCCESS
== (MSI_GetFeatureCost(dialog
->package
, feature
,
3187 MSICOSTTREE_SELFONLY
, INSTALLSTATE_LOCAL
, &each_cost
)))
3189 /* each_cost is in 512-byte units */
3190 total_cost
+= each_cost
* 512;
3192 if (ERROR_SUCCESS
== (MSI_GetFeatureCost(dialog
->package
, feature
,
3193 MSICOSTTREE_SELFONLY
, INSTALLSTATE_ABSENT
, &each_cost
)))
3195 /* each_cost is in 512-byte units */
3196 total_cost
-= each_cost
* 512;
3202 static void msi_dialog_vcl_add_drives( msi_dialog
*dialog
, msi_control
*control
)
3204 ULARGE_INTEGER total
, free
;
3205 LONGLONG difference
, cost
;
3206 WCHAR size_text
[MAX_PATH
];
3207 WCHAR cost_text
[MAX_PATH
];
3213 cost
= msi_vcl_get_cost(dialog
);
3214 StrFormatByteSizeW(cost
, cost_text
, MAX_PATH
);
3216 size
= GetLogicalDriveStringsW( 0, NULL
);
3217 if ( !size
) return;
3219 drives
= msi_alloc( (size
+ 1) * sizeof(WCHAR
) );
3220 if ( !drives
) return;
3222 GetLogicalDriveStringsW( size
, drives
);
3227 if (GetVolumeInformationW(ptr
, NULL
, 0, NULL
, 0, &flags
, NULL
, 0) &&
3228 flags
& FILE_READ_ONLY_VOLUME
)
3230 ptr
+= lstrlenW(ptr
) + 1;
3234 lvitem
.mask
= LVIF_TEXT
;
3236 lvitem
.iSubItem
= 0;
3237 lvitem
.pszText
= ptr
;
3238 lvitem
.cchTextMax
= lstrlenW(ptr
) + 1;
3239 SendMessageW( control
->hwnd
, LVM_INSERTITEMW
, 0, (LPARAM
)&lvitem
);
3241 GetDiskFreeSpaceExW(ptr
, &free
, &total
, NULL
);
3242 difference
= free
.QuadPart
- cost
;
3244 StrFormatByteSizeW(total
.QuadPart
, size_text
, MAX_PATH
);
3245 lvitem
.iSubItem
= 1;
3246 lvitem
.pszText
= size_text
;
3247 lvitem
.cchTextMax
= lstrlenW(size_text
) + 1;
3248 SendMessageW( control
->hwnd
, LVM_SETITEMW
, 0, (LPARAM
)&lvitem
);
3250 StrFormatByteSizeW(free
.QuadPart
, size_text
, MAX_PATH
);
3251 lvitem
.iSubItem
= 2;
3252 lvitem
.pszText
= size_text
;
3253 lvitem
.cchTextMax
= lstrlenW(size_text
) + 1;
3254 SendMessageW( control
->hwnd
, LVM_SETITEMW
, 0, (LPARAM
)&lvitem
);
3256 lvitem
.iSubItem
= 3;
3257 lvitem
.pszText
= cost_text
;
3258 lvitem
.cchTextMax
= lstrlenW(cost_text
) + 1;
3259 SendMessageW( control
->hwnd
, LVM_SETITEMW
, 0, (LPARAM
)&lvitem
);
3261 StrFormatByteSizeW(difference
, size_text
, MAX_PATH
);
3262 lvitem
.iSubItem
= 4;
3263 lvitem
.pszText
= size_text
;
3264 lvitem
.cchTextMax
= lstrlenW(size_text
) + 1;
3265 SendMessageW( control
->hwnd
, LVM_SETITEMW
, 0, (LPARAM
)&lvitem
);
3267 ptr
+= lstrlenW(ptr
) + 1;
3274 static UINT
msi_dialog_volumecost_list( msi_dialog
*dialog
, MSIRECORD
*rec
)
3276 msi_control
*control
;
3279 style
= LVS_REPORT
| WS_VSCROLL
| WS_HSCROLL
| LVS_SHAREIMAGELISTS
|
3280 LVS_AUTOARRANGE
| LVS_SINGLESEL
| WS_BORDER
|
3281 WS_CHILD
| WS_TABSTOP
| WS_GROUP
;
3282 control
= msi_dialog_add_control( dialog
, rec
, WC_LISTVIEWW
, style
);
3284 return ERROR_FUNCTION_FAILED
;
3286 msi_dialog_vcl_add_columns( dialog
, control
, rec
);
3287 msi_dialog_vcl_add_drives( dialog
, control
);
3289 return ERROR_SUCCESS
;
3292 /******************** VolumeSelect Combo ***************************************/
3294 static UINT
msi_dialog_volsel_handler( msi_dialog
*dialog
,
3295 msi_control
*control
, WPARAM param
)
3297 WCHAR text
[MAX_PATH
];
3302 if (HIWORD(param
) != CBN_SELCHANGE
)
3303 return ERROR_SUCCESS
;
3305 index
= SendMessageW( control
->hwnd
, CB_GETCURSEL
, 0, 0 );
3306 if ( index
== CB_ERR
)
3308 ERR("No ComboBox item selected!\n");
3309 return ERROR_FUNCTION_FAILED
;
3312 SendMessageW( control
->hwnd
, CB_GETLBTEXT
, index
, (LPARAM
)text
);
3314 indirect
= control
->attributes
& msidbControlAttributesIndirect
;
3315 prop
= msi_dialog_dup_property( dialog
, control
->property
, indirect
);
3317 msi_dialog_set_property( dialog
->package
, prop
, text
);
3320 return ERROR_SUCCESS
;
3323 static void msi_dialog_vsc_add_drives( msi_dialog
*dialog
, msi_control
*control
)
3328 size
= GetLogicalDriveStringsW( 0, NULL
);
3329 if ( !size
) return;
3331 drives
= msi_alloc( (size
+ 1) * sizeof(WCHAR
) );
3332 if ( !drives
) return;
3334 GetLogicalDriveStringsW( size
, drives
);
3339 SendMessageW( control
->hwnd
, CB_ADDSTRING
, 0, (LPARAM
)ptr
);
3340 ptr
+= lstrlenW(ptr
) + 1;
3346 static UINT
msi_dialog_volumeselect_combo( msi_dialog
*dialog
, MSIRECORD
*rec
)
3348 msi_control
*control
;
3352 /* FIXME: CBS_OWNERDRAWFIXED */
3353 style
= WS_CHILD
| WS_VISIBLE
| WS_GROUP
| WS_TABSTOP
|
3354 CBS_DROPDOWNLIST
| CBS_SORT
| CBS_HASSTRINGS
|
3355 WS_EX_LEFT
| WS_EX_LTRREADING
| WS_EX_RIGHTSCROLLBAR
;
3356 control
= msi_dialog_add_control( dialog
, rec
, WC_COMBOBOXW
, style
);
3358 return ERROR_FUNCTION_FAILED
;
3360 control
->attributes
= MSI_RecordGetInteger( rec
, 8 );
3361 control
->handler
= msi_dialog_volsel_handler
;
3362 prop
= MSI_RecordGetString( rec
, 9 );
3363 control
->property
= msi_dialog_dup_property( dialog
, prop
, FALSE
);
3365 msi_dialog_vsc_add_drives( dialog
, control
);
3367 return ERROR_SUCCESS
;
3370 static UINT
msi_dialog_hyperlink_handler( msi_dialog
*dialog
, msi_control
*control
, WPARAM param
)
3372 int len
, len_href
= ARRAY_SIZE( L
"href" ) - 1;
3377 item
.mask
= LIF_ITEMINDEX
| LIF_URL
;
3381 SendMessageW( control
->hwnd
, LM_GETITEM
, 0, (LPARAM
)&item
);
3384 while (*p
&& *p
!= '<') p
++;
3385 if (!*p
++) return ERROR_SUCCESS
;
3386 if (towupper( *p
++ ) != 'A' || !iswspace( *p
++ )) return ERROR_SUCCESS
;
3387 while (*p
&& iswspace( *p
)) p
++;
3389 len
= lstrlenW( p
);
3390 if (len
> len_href
&& !wcsnicmp( p
, L
"href", len_href
))
3393 while (*p
&& iswspace( *p
)) p
++;
3394 if (!*p
|| *p
++ != '=') return ERROR_SUCCESS
;
3395 while (*p
&& iswspace( *p
)) p
++;
3397 if (*p
== '\"' || *p
== '\'') quote
= *p
++;
3401 while (*q
&& *q
!= quote
) q
++;
3402 if (*q
!= quote
) return ERROR_SUCCESS
;
3406 while (*q
&& *q
!= '>' && !iswspace( *q
)) q
++;
3407 if (!*q
) return ERROR_SUCCESS
;
3409 item
.szUrl
[q
- item
.szUrl
] = 0;
3410 ShellExecuteW( NULL
, L
"open", p
, NULL
, NULL
, SW_SHOWNORMAL
);
3412 return ERROR_SUCCESS
;
3415 static UINT
msi_dialog_hyperlink( msi_dialog
*dialog
, MSIRECORD
*rec
)
3417 msi_control
*control
;
3418 DWORD style
= WS_CHILD
| WS_TABSTOP
| WS_GROUP
;
3419 const WCHAR
*text
= MSI_RecordGetString( rec
, 10 );
3420 int len
= lstrlenW( text
);
3423 control
= msi_dialog_add_control( dialog
, rec
, WC_LINK
, style
);
3425 return ERROR_FUNCTION_FAILED
;
3427 control
->attributes
= MSI_RecordGetInteger( rec
, 8 );
3428 control
->handler
= msi_dialog_hyperlink_handler
;
3430 item
.mask
= LIF_ITEMINDEX
| LIF_STATE
| LIF_URL
;
3432 item
.state
= LIS_ENABLED
;
3433 item
.stateMask
= LIS_ENABLED
;
3434 if (len
< L_MAX_URL_LENGTH
) lstrcpyW( item
.szUrl
, text
);
3435 else item
.szUrl
[0] = 0;
3437 SendMessageW( control
->hwnd
, LM_SETITEM
, 0, (LPARAM
)&item
);
3439 return ERROR_SUCCESS
;
3442 /******************** ListView *****************************************/
3444 struct listview_param
3447 msi_control
*control
;
3450 static UINT
msi_dialog_listview_handler( msi_dialog
*dialog
, msi_control
*control
, WPARAM param
)
3452 NMHDR
*nmhdr
= (NMHDR
*)param
;
3454 FIXME("code %#x (%d)\n", nmhdr
->code
, nmhdr
->code
);
3456 return ERROR_SUCCESS
;
3459 static UINT
msi_listview_add_item( MSIRECORD
*rec
, LPVOID param
)
3461 struct listview_param
*lv_param
= (struct listview_param
*)param
;
3462 LPCWSTR text
, binary
;
3466 text
= MSI_RecordGetString( rec
, 4 );
3467 binary
= MSI_RecordGetString( rec
, 5 );
3468 hIcon
= msi_load_icon( lv_param
->dialog
->package
->db
, binary
, 0 );
3470 TRACE("Adding: text %s, binary %s, icon %p\n", debugstr_w(text
), debugstr_w(binary
), hIcon
);
3472 memset( &item
, 0, sizeof(item
) );
3473 item
.mask
= LVIF_TEXT
| LVIF_IMAGE
;
3474 deformat_string( lv_param
->dialog
->package
, text
, &item
.pszText
);
3475 item
.iImage
= ImageList_AddIcon( lv_param
->control
->hImageList
, hIcon
);
3476 item
.iItem
= item
.iImage
;
3477 SendMessageW( lv_param
->control
->hwnd
, LVM_INSERTITEMW
, 0, (LPARAM
)&item
);
3479 DestroyIcon( hIcon
);
3481 return ERROR_SUCCESS
;
3484 static UINT
msi_listview_add_items( msi_dialog
*dialog
, msi_control
*control
)
3487 struct listview_param lv_param
= { dialog
, control
};
3489 if (MSI_OpenQuery( dialog
->package
->db
, &view
, L
"SELECT * FROM `ListView` WHERE `Property` = '%s' ORDER BY `Order`",
3490 control
->property
) == ERROR_SUCCESS
)
3492 MSI_IterateRecords( view
, NULL
, msi_listview_add_item
, &lv_param
);
3493 msiobj_release( &view
->hdr
);
3496 return ERROR_SUCCESS
;
3499 static UINT
msi_dialog_listview( msi_dialog
*dialog
, MSIRECORD
*rec
)
3501 msi_control
*control
;
3503 DWORD style
, attributes
;
3507 style
= LVS_REPORT
| LVS_NOCOLUMNHEADER
| LVS_SHAREIMAGELISTS
| LVS_SINGLESEL
|
3508 LVS_SHOWSELALWAYS
| WS_VSCROLL
| WS_HSCROLL
| WS_BORDER
| WS_TABSTOP
| WS_CHILD
;
3509 attributes
= MSI_RecordGetInteger( rec
, 8 );
3510 if ( ~attributes
& msidbControlAttributesSorted
)
3511 style
|= LVS_SORTASCENDING
;
3512 control
= msi_dialog_add_control( dialog
, rec
, WC_LISTVIEWW
, style
);
3514 return ERROR_FUNCTION_FAILED
;
3516 prop
= MSI_RecordGetString( rec
, 9 );
3517 control
->property
= msi_dialog_dup_property( dialog
, prop
, FALSE
);
3519 control
->hImageList
= ImageList_Create( 16, 16, ILC_COLOR32
, 0, 1);
3520 SendMessageW( control
->hwnd
, LVM_SETIMAGELIST
, LVSIL_SMALL
, (LPARAM
)control
->hImageList
);
3522 col
.mask
= LVCF_FMT
| LVCF_WIDTH
;
3523 col
.fmt
= LVCFMT_LEFT
;
3525 SendMessageW( control
->hwnd
, LVM_INSERTCOLUMNW
, 0, (LPARAM
)&col
);
3527 GetClientRect( control
->hwnd
, &rc
);
3528 col
.cx
= rc
.right
- 16;
3529 SendMessageW( control
->hwnd
, LVM_INSERTCOLUMNW
, 0, (LPARAM
)&col
);
3531 if (control
->property
)
3532 msi_listview_add_items( dialog
, control
);
3534 control
->handler
= msi_dialog_listview_handler
;
3536 return ERROR_SUCCESS
;
3539 static const struct control_handler msi_dialog_handler
[] =
3541 { L
"Text", msi_dialog_text_control
},
3542 { L
"PushButton", msi_dialog_button_control
},
3543 { L
"Line", msi_dialog_line_control
},
3544 { L
"Bitmap", msi_dialog_bitmap_control
},
3545 { L
"CheckBox", msi_dialog_checkbox_control
},
3546 { L
"ScrollableText", msi_dialog_scrolltext_control
},
3547 { L
"ComboBox", msi_dialog_combo_control
},
3548 { L
"Edit", msi_dialog_edit_control
},
3549 { L
"MaskedEdit", msi_dialog_maskedit_control
},
3550 { L
"PathEdit", msi_dialog_pathedit_control
},
3551 { L
"ProgressBar", msi_dialog_progress_bar
},
3552 { L
"RadioButtonGroup", msi_dialog_radiogroup_control
},
3553 { L
"Icon", msi_dialog_icon_control
},
3554 { L
"SelectionTree", msi_dialog_selection_tree
},
3555 { L
"GroupBox", msi_dialog_group_box
},
3556 { L
"ListBox", msi_dialog_list_box
},
3557 { L
"DirectoryCombo", msi_dialog_directory_combo
},
3558 { L
"DirectoryList", msi_dialog_directory_list
},
3559 { L
"VolumeCostList", msi_dialog_volumecost_list
},
3560 { L
"VolumeSelectCombo", msi_dialog_volumeselect_combo
},
3561 { L
"HyperLink", msi_dialog_hyperlink
},
3562 { L
"ListView", msi_dialog_listview
}
3565 static UINT
msi_dialog_create_controls( MSIRECORD
*rec
, LPVOID param
)
3567 msi_dialog
*dialog
= param
;
3568 LPCWSTR control_type
;
3571 /* find and call the function that can create this type of control */
3572 control_type
= MSI_RecordGetString( rec
, 3 );
3573 for( i
= 0; i
< ARRAY_SIZE( msi_dialog_handler
); i
++ )
3574 if (!wcsicmp( msi_dialog_handler
[i
].control_type
, control_type
))
3576 if( i
!= ARRAY_SIZE( msi_dialog_handler
))
3577 msi_dialog_handler
[i
].func( dialog
, rec
);
3579 ERR("no handler for element type %s\n", debugstr_w(control_type
));
3581 return ERROR_SUCCESS
;
3584 static UINT
msi_dialog_fill_controls( msi_dialog
*dialog
)
3588 MSIPACKAGE
*package
= dialog
->package
;
3590 TRACE("%p %s\n", dialog
, debugstr_w(dialog
->name
) );
3592 /* query the Control table for all the elements of the control */
3593 r
= MSI_OpenQuery( package
->db
, &view
, L
"SELECT * FROM `Control` WHERE `Dialog_` = '%s'", dialog
->name
);
3594 if( r
!= ERROR_SUCCESS
)
3596 ERR("query failed for dialog %s\n", debugstr_w(dialog
->name
));
3597 return ERROR_INVALID_PARAMETER
;
3600 r
= MSI_IterateRecords( view
, 0, msi_dialog_create_controls
, dialog
);
3601 msiobj_release( &view
->hdr
);
3605 static UINT
msi_dialog_reset( msi_dialog
*dialog
)
3607 /* FIXME: should restore the original values of any properties we changed */
3608 return msi_dialog_evaluate_control_conditions( dialog
);
3611 /* figure out the height of 10 point MS Sans Serif */
3612 static INT
msi_dialog_get_sans_serif_height( HWND hwnd
)
3618 HFONT hFont
, hOldFont
;
3621 hdc
= GetDC( hwnd
);
3624 memset( &lf
, 0, sizeof lf
);
3625 lf
.lfHeight
= MulDiv(12, GetDeviceCaps(hdc
, LOGPIXELSY
), 72);
3626 lstrcpyW( lf
.lfFaceName
, L
"MS Sans Serif" );
3627 hFont
= CreateFontIndirectW(&lf
);
3630 hOldFont
= SelectObject( hdc
, hFont
);
3631 r
= GetTextMetricsW( hdc
, &tm
);
3633 height
= tm
.tmHeight
;
3634 SelectObject( hdc
, hOldFont
);
3635 DeleteObject( hFont
);
3637 ReleaseDC( hwnd
, hdc
);
3642 /* fetch the associated record from the Dialog table */
3643 static MSIRECORD
*msi_get_dialog_record( msi_dialog
*dialog
)
3645 MSIPACKAGE
*package
= dialog
->package
;
3646 MSIRECORD
*rec
= NULL
;
3648 TRACE("%p %s\n", dialog
, debugstr_w(dialog
->name
) );
3650 rec
= MSI_QueryGetRecord( package
->db
, L
"SELECT * FROM `Dialog` WHERE `Dialog` = '%s'", dialog
->name
);
3652 WARN("query failed for dialog %s\n", debugstr_w(dialog
->name
));
3657 static void msi_dialog_adjust_dialog_pos( msi_dialog
*dialog
, MSIRECORD
*rec
, LPRECT pos
)
3664 center
.x
= MSI_RecordGetInteger( rec
, 2 );
3665 center
.y
= MSI_RecordGetInteger( rec
, 3 );
3667 sz
.cx
= MSI_RecordGetInteger( rec
, 4 );
3668 sz
.cy
= MSI_RecordGetInteger( rec
, 5 );
3670 sz
.cx
= msi_dialog_scale_unit( dialog
, sz
.cx
);
3671 sz
.cy
= msi_dialog_scale_unit( dialog
, sz
.cy
);
3673 xres
= msi_get_property_int( dialog
->package
->db
, L
"ScreenX", 0 );
3674 yres
= msi_get_property_int( dialog
->package
->db
, L
"ScreenY", 0 );
3676 center
.x
= MulDiv( center
.x
, xres
, 100 );
3677 center
.y
= MulDiv( center
.y
, yres
, 100 );
3679 /* turn the client pos into the window rectangle */
3680 if (dialog
->package
->center_x
&& dialog
->package
->center_y
)
3682 pos
->left
= dialog
->package
->center_x
- sz
.cx
/ 2.0;
3683 pos
->right
= pos
->left
+ sz
.cx
;
3684 pos
->top
= dialog
->package
->center_y
- sz
.cy
/ 2.0;
3685 pos
->bottom
= pos
->top
+ sz
.cy
;
3689 pos
->left
= center
.x
- sz
.cx
/2;
3690 pos
->right
= pos
->left
+ sz
.cx
;
3691 pos
->top
= center
.y
- sz
.cy
/2;
3692 pos
->bottom
= pos
->top
+ sz
.cy
;
3694 /* save the center */
3695 dialog
->package
->center_x
= center
.x
;
3696 dialog
->package
->center_y
= center
.y
;
3699 dialog
->size
.cx
= sz
.cx
;
3700 dialog
->size
.cy
= sz
.cy
;
3702 TRACE("%s\n", wine_dbgstr_rect(pos
));
3704 style
= GetWindowLongPtrW( dialog
->hwnd
, GWL_STYLE
);
3705 AdjustWindowRect( pos
, style
, FALSE
);
3708 static void msi_dialog_set_tab_order( msi_dialog
*dialog
, LPCWSTR first
)
3710 struct list tab_chain
;
3711 msi_control
*control
;
3712 HWND prev
= HWND_TOP
;
3714 list_init( &tab_chain
);
3715 if (!(control
= msi_dialog_find_control( dialog
, first
))) return;
3717 dialog
->hWndFocus
= control
->hwnd
;
3720 list_remove( &control
->entry
);
3721 list_add_tail( &tab_chain
, &control
->entry
);
3722 if (!control
->tabnext
) break;
3723 control
= msi_dialog_find_control( dialog
, control
->tabnext
);
3726 LIST_FOR_EACH_ENTRY( control
, &tab_chain
, msi_control
, entry
)
3728 SetWindowPos( control
->hwnd
, prev
, 0, 0, 0, 0,
3729 SWP_NOMOVE
| SWP_NOOWNERZORDER
| SWP_NOREDRAW
|
3730 SWP_NOREPOSITION
| SWP_NOSENDCHANGING
| SWP_NOSIZE
);
3731 prev
= control
->hwnd
;
3734 /* put them back on the main list */
3735 list_move_head( &dialog
->controls
, &tab_chain
);
3738 static LRESULT
msi_dialog_oncreate( HWND hwnd
, LPCREATESTRUCTW cs
)
3740 msi_dialog
*dialog
= cs
->lpCreateParams
;
3741 MSIRECORD
*rec
= NULL
;
3742 LPWSTR title
= NULL
;
3745 TRACE("%p %p\n", dialog
, dialog
->package
);
3747 dialog
->hwnd
= hwnd
;
3748 SetWindowLongPtrW( hwnd
, GWLP_USERDATA
, (LONG_PTR
) dialog
);
3750 rec
= msi_get_dialog_record( dialog
);
3753 TRACE("No record found for dialog %s\n", debugstr_w(dialog
->name
));
3757 dialog
->scale
= msi_dialog_get_sans_serif_height(dialog
->hwnd
);
3759 msi_dialog_adjust_dialog_pos( dialog
, rec
, &pos
);
3761 dialog
->attributes
= MSI_RecordGetInteger( rec
, 6 );
3763 dialog
->default_font
= msi_dup_property( dialog
->package
->db
, L
"DefaultUIFont" );
3764 if (!dialog
->default_font
)
3766 dialog
->default_font
= strdupW( L
"MS Shell Dlg" );
3767 if (!dialog
->default_font
)
3769 msiobj_release( &rec
->hdr
);
3774 title
= msi_get_deformatted_field( dialog
->package
, rec
, 7 );
3775 SetWindowTextW( hwnd
, title
);
3778 SetWindowPos( hwnd
, 0, pos
.left
, pos
.top
,
3779 pos
.right
- pos
.left
, pos
.bottom
- pos
.top
,
3780 SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_NOREDRAW
);
3782 msi_dialog_build_font_list( dialog
);
3783 msi_dialog_fill_controls( dialog
);
3784 msi_dialog_evaluate_control_conditions( dialog
);
3785 msi_dialog_set_tab_order( dialog
, MSI_RecordGetString( rec
, 8 ) );
3786 msiobj_release( &rec
->hdr
);
3791 static LRESULT
msi_dialog_oncommand( msi_dialog
*dialog
, WPARAM param
, HWND hwnd
)
3793 msi_control
*control
= NULL
;
3795 TRACE("%p %p %08lx\n", dialog
, hwnd
, param
);
3800 control
= msi_dialog_find_control( dialog
, dialog
->control_default
);
3802 case 2: /* escape */
3803 control
= msi_dialog_find_control( dialog
, dialog
->control_cancel
);
3806 control
= msi_dialog_find_control_by_hwnd( dialog
, hwnd
);
3811 if( control
->handler
)
3813 control
->handler( dialog
, control
, param
);
3814 msi_dialog_evaluate_control_conditions( dialog
);
3821 static LRESULT
msi_dialog_onnotify( msi_dialog
*dialog
, LPARAM param
)
3823 LPNMHDR nmhdr
= (LPNMHDR
) param
;
3824 msi_control
*control
= msi_dialog_find_control_by_hwnd( dialog
, nmhdr
->hwndFrom
);
3826 TRACE("%p %p\n", dialog
, nmhdr
->hwndFrom
);
3828 if ( control
&& control
->handler
)
3829 control
->handler( dialog
, control
, param
);
3834 static void dialog_setfocus( msi_dialog
*dialog
)
3836 HWND hwnd
= dialog
->hWndFocus
;
3838 hwnd
= GetNextDlgTabItem( dialog
->hwnd
, hwnd
, TRUE
);
3839 hwnd
= GetNextDlgTabItem( dialog
->hwnd
, hwnd
, FALSE
);
3841 dialog
->hWndFocus
= hwnd
;
3844 static LRESULT WINAPI
MSIDialog_WndProc( HWND hwnd
, UINT msg
,
3845 WPARAM wParam
, LPARAM lParam
)
3847 msi_dialog
*dialog
= (LPVOID
) GetWindowLongPtrW( hwnd
, GWLP_USERDATA
);
3849 TRACE("0x%04x\n", msg
);
3854 dialog
->package
->center_x
= LOWORD(lParam
) + dialog
->size
.cx
/ 2.0;
3855 dialog
->package
->center_y
= HIWORD(lParam
) + dialog
->size
.cy
/ 2.0;
3859 return msi_dialog_oncreate( hwnd
, (LPCREATESTRUCTW
)lParam
);
3862 return msi_dialog_oncommand( dialog
, wParam
, (HWND
)lParam
);
3865 /* Simulate escape press */
3866 return msi_dialog_oncommand(dialog
, 2, NULL
);
3869 if( LOWORD(wParam
) == WA_INACTIVE
)
3870 dialog
->hWndFocus
= GetFocus();
3872 dialog_setfocus( dialog
);
3876 dialog_setfocus( dialog
);
3879 /* bounce back to our subclassed static control */
3880 case WM_CTLCOLORSTATIC
:
3881 return SendMessageW( (HWND
) lParam
, WM_CTLCOLORSTATIC
, wParam
, lParam
);
3884 dialog
->hwnd
= NULL
;
3887 return msi_dialog_onnotify( dialog
, lParam
);
3889 return DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
3892 static void process_pending_messages( HWND hdlg
)
3896 while (PeekMessageW( &msg
, 0, 0, 0, PM_REMOVE
))
3898 if (hdlg
&& IsDialogMessageW( hdlg
, &msg
)) continue;
3899 TranslateMessage( &msg
);
3900 DispatchMessageW( &msg
);
3904 static UINT
dialog_run_message_loop( msi_dialog
*dialog
)
3909 if( uiThreadId
!= GetCurrentThreadId() )
3910 return SendMessageW( hMsiHiddenWindow
, WM_MSI_DIALOG_CREATE
, 0, (LPARAM
) dialog
);
3912 /* create the dialog window, don't show it yet */
3913 style
= WS_OVERLAPPED
| WS_SYSMENU
;
3914 if( dialog
->attributes
& msidbDialogAttributesVisible
)
3915 style
|= WS_VISIBLE
;
3917 if (dialog
->parent
== NULL
&& (dialog
->attributes
& msidbDialogAttributesMinimize
))
3918 style
|= WS_MINIMIZEBOX
;
3920 hwnd
= CreateWindowW( L
"MsiDialogCloseClass", dialog
->name
, style
,
3921 CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
,
3922 NULL
, NULL
, NULL
, dialog
);
3925 ERR("Failed to create dialog %s\n", debugstr_w( dialog
->name
));
3926 return ERROR_FUNCTION_FAILED
;
3929 ShowWindow( hwnd
, SW_SHOW
);
3930 /* UpdateWindow( hwnd ); - and causes the transparent static controls not to paint */
3932 if( dialog
->attributes
& msidbDialogAttributesModal
)
3934 while( !dialog
->finished
)
3936 MsgWaitForMultipleObjects( 0, NULL
, 0, INFINITE
, QS_ALLINPUT
);
3937 process_pending_messages( dialog
->hwnd
);
3941 return ERROR_IO_PENDING
;
3943 return ERROR_SUCCESS
;
3946 static LRESULT WINAPI
MSIHiddenWindowProc( HWND hwnd
, UINT msg
,
3947 WPARAM wParam
, LPARAM lParam
)
3949 msi_dialog
*dialog
= (msi_dialog
*) lParam
;
3951 TRACE("%d %p\n", msg
, dialog
);
3955 case WM_MSI_DIALOG_CREATE
:
3956 return dialog_run_message_loop( dialog
);
3957 case WM_MSI_DIALOG_DESTROY
:
3958 msi_dialog_destroy( dialog
);
3961 return DefWindowProcW( hwnd
, msg
, wParam
, lParam
);
3964 static BOOL
dialog_register_class( void )
3968 ZeroMemory( &cls
, sizeof cls
);
3969 cls
.lpfnWndProc
= MSIDialog_WndProc
;
3970 cls
.hInstance
= NULL
;
3971 cls
.hIcon
= LoadIconW(0, (LPWSTR
)IDI_APPLICATION
);
3972 cls
.hCursor
= LoadCursorW(0, (LPWSTR
)IDC_ARROW
);
3973 cls
.hbrBackground
= (HBRUSH
)(COLOR_3DFACE
+ 1);
3974 cls
.lpszMenuName
= NULL
;
3975 cls
.lpszClassName
= L
"MsiDialogCloseClass";
3977 if( !RegisterClassW( &cls
) )
3980 cls
.lpfnWndProc
= MSIHiddenWindowProc
;
3981 cls
.lpszClassName
= L
"MsiHiddenWindow";
3983 if( !RegisterClassW( &cls
) )
3986 uiThreadId
= GetCurrentThreadId();
3988 hMsiHiddenWindow
= CreateWindowW( L
"MsiHiddenWindow", NULL
, WS_OVERLAPPED
,
3989 0, 0, 100, 100, NULL
, NULL
, NULL
, NULL
);
3990 if( !hMsiHiddenWindow
)
3996 static msi_dialog
*dialog_create( MSIPACKAGE
*package
, const WCHAR
*name
, msi_dialog
*parent
,
3997 control_event_handler event_handler
)
3999 MSIRECORD
*rec
= NULL
;
4002 TRACE("%s\n", debugstr_w(name
));
4004 if (!hMsiHiddenWindow
) dialog_register_class();
4006 /* allocate the structure for the dialog to use */
4007 dialog
= msi_alloc_zero( FIELD_OFFSET( msi_dialog
, name
[lstrlenW( name
) + 1] ));
4010 lstrcpyW( dialog
->name
, name
);
4011 dialog
->parent
= parent
;
4012 dialog
->package
= package
;
4013 dialog
->event_handler
= event_handler
;
4014 dialog
->finished
= 0;
4015 list_init( &dialog
->controls
);
4016 list_init( &dialog
->fonts
);
4018 /* verify that the dialog exists */
4019 rec
= msi_get_dialog_record( dialog
);
4025 dialog
->attributes
= MSI_RecordGetInteger( rec
, 6 );
4026 dialog
->control_default
= strdupW( MSI_RecordGetString( rec
, 9 ) );
4027 dialog
->control_cancel
= strdupW( MSI_RecordGetString( rec
, 10 ) );
4028 msiobj_release( &rec
->hdr
);
4030 rec
= MSI_CreateRecord(2);
4033 msi_dialog_destroy(dialog
);
4036 MSI_RecordSetStringW(rec
, 1, name
);
4037 MSI_RecordSetStringW(rec
, 2, L
"Dialog created");
4038 MSI_ProcessMessage(package
, INSTALLMESSAGE_ACTIONSTART
, rec
);
4039 msiobj_release(&rec
->hdr
);
4044 static void msi_dialog_end_dialog( msi_dialog
*dialog
)
4046 TRACE("%p\n", dialog
);
4047 dialog
->finished
= 1;
4048 PostMessageW(dialog
->hwnd
, WM_NULL
, 0, 0);
4051 void msi_dialog_check_messages( HANDLE handle
)
4055 /* in threads other than the UI thread, block */
4056 if( uiThreadId
!= GetCurrentThreadId() )
4058 if (!handle
) return;
4059 while (MsgWaitForMultipleObjectsEx( 1, &handle
, INFINITE
, QS_ALLINPUT
, 0 ) == WAIT_OBJECT_0
+ 1)
4062 while (PeekMessageW( &msg
, NULL
, 0, 0, PM_REMOVE
))
4064 TranslateMessage( &msg
);
4065 DispatchMessageW( &msg
);
4071 /* there are two choices for the UI thread */
4074 process_pending_messages( NULL
);
4080 * block here until somebody creates a new dialog or
4081 * the handle we're waiting on becomes ready
4083 r
= MsgWaitForMultipleObjects( 1, &handle
, 0, INFINITE
, QS_ALLINPUT
);
4084 if( r
== WAIT_OBJECT_0
)
4089 static void dialog_do_preview( msi_dialog
*dialog
)
4092 dialog
->attributes
|= msidbDialogAttributesVisible
;
4093 dialog
->attributes
&= ~msidbDialogAttributesModal
;
4094 dialog_run_message_loop( dialog
);
4097 static void free_subscriber( struct subscriber
*sub
)
4099 msi_free( sub
->event
);
4100 msi_free( sub
->control
);
4101 msi_free( sub
->attribute
);
4105 static void event_cleanup_subscriptions( MSIPACKAGE
*package
, const WCHAR
*dialog
)
4107 struct list
*item
, *next
;
4109 LIST_FOR_EACH_SAFE( item
, next
, &package
->subscriptions
)
4111 struct subscriber
*sub
= LIST_ENTRY( item
, struct subscriber
, entry
);
4113 if (wcscmp( sub
->dialog
->name
, dialog
)) continue;
4114 list_remove( &sub
->entry
);
4115 free_subscriber( sub
);
4119 void msi_dialog_destroy( msi_dialog
*dialog
)
4121 msi_font
*font
, *next
;
4123 if( uiThreadId
!= GetCurrentThreadId() )
4125 SendMessageW( hMsiHiddenWindow
, WM_MSI_DIALOG_DESTROY
, 0, (LPARAM
) dialog
);
4131 ShowWindow( dialog
->hwnd
, SW_HIDE
);
4132 DestroyWindow( dialog
->hwnd
);
4135 /* unsubscribe events */
4136 event_cleanup_subscriptions( dialog
->package
, dialog
->name
);
4138 /* destroy the list of controls */
4139 while( !list_empty( &dialog
->controls
) )
4143 t
= LIST_ENTRY( list_head( &dialog
->controls
),
4144 msi_control
, entry
);
4145 msi_destroy_control( t
);
4148 /* destroy the list of fonts */
4149 LIST_FOR_EACH_ENTRY_SAFE( font
, next
, &dialog
->fonts
, msi_font
, entry
)
4151 list_remove( &font
->entry
);
4152 DeleteObject( font
->hfont
);
4155 msi_free( dialog
->default_font
);
4157 msi_free( dialog
->control_default
);
4158 msi_free( dialog
->control_cancel
);
4159 dialog
->package
= NULL
;
4163 void msi_dialog_unregister_class( void )
4165 DestroyWindow( hMsiHiddenWindow
);
4166 hMsiHiddenWindow
= NULL
;
4167 UnregisterClassW( L
"MsiDialogCloseClass", NULL
);
4168 UnregisterClassW( L
"MsiHiddenWindow", NULL
);
4172 void msi_event_cleanup_all_subscriptions( MSIPACKAGE
*package
)
4174 struct list
*item
, *next
;
4176 LIST_FOR_EACH_SAFE( item
, next
, &package
->subscriptions
)
4178 struct subscriber
*sub
= LIST_ENTRY( item
, struct subscriber
, entry
);
4179 list_remove( &sub
->entry
);
4180 free_subscriber( sub
);
4184 static void MSI_ClosePreview( MSIOBJECTHDR
*arg
)
4186 MSIPREVIEW
*preview
= (MSIPREVIEW
*)arg
;
4187 msiobj_release( &preview
->package
->hdr
);
4190 static MSIPREVIEW
*MSI_EnableUIPreview( MSIDATABASE
*db
)
4192 MSIPREVIEW
*preview
= NULL
;
4193 MSIPACKAGE
*package
;
4195 package
= MSI_CreatePackage( db
);
4198 preview
= alloc_msiobject( MSIHANDLETYPE_PREVIEW
, sizeof(MSIPREVIEW
), MSI_ClosePreview
);
4201 preview
->package
= package
;
4202 msiobj_addref( &package
->hdr
);
4204 msiobj_release( &package
->hdr
);
4209 UINT WINAPI
MsiEnableUIPreview( MSIHANDLE hdb
, MSIHANDLE
*phPreview
)
4212 MSIPREVIEW
*preview
;
4213 UINT r
= ERROR_FUNCTION_FAILED
;
4215 TRACE("%d %p\n", hdb
, phPreview
);
4217 if (!(db
= msihandle2msiinfo(hdb
, MSIHANDLETYPE_DATABASE
)))
4218 return ERROR_INVALID_HANDLE
;
4220 preview
= MSI_EnableUIPreview( db
);
4223 *phPreview
= alloc_msihandle( &preview
->hdr
);
4224 msiobj_release( &preview
->hdr
);
4227 r
= ERROR_NOT_ENOUGH_MEMORY
;
4229 msiobj_release( &db
->hdr
);
4233 static UINT
preview_event_handler( msi_dialog
*dialog
, const WCHAR
*event
, const WCHAR
*argument
)
4235 MESSAGE("Preview dialog event '%s' (arg='%s')\n", debugstr_w(event
), debugstr_w(argument
));
4236 return ERROR_SUCCESS
;
4239 static UINT
MSI_PreviewDialogW( MSIPREVIEW
*preview
, LPCWSTR szDialogName
)
4241 msi_dialog
*dialog
= NULL
;
4242 UINT r
= ERROR_SUCCESS
;
4244 if (preview
->dialog
)
4245 msi_dialog_destroy( preview
->dialog
);
4247 /* an empty name means we should just destroy the current preview dialog */
4250 dialog
= dialog_create( preview
->package
, szDialogName
, NULL
, preview_event_handler
);
4252 dialog_do_preview( dialog
);
4254 r
= ERROR_FUNCTION_FAILED
;
4256 preview
->dialog
= dialog
;
4260 UINT WINAPI
MsiPreviewDialogW( MSIHANDLE hPreview
, LPCWSTR szDialogName
)
4262 MSIPREVIEW
*preview
;
4265 TRACE("%d %s\n", hPreview
, debugstr_w(szDialogName
));
4267 preview
= msihandle2msiinfo( hPreview
, MSIHANDLETYPE_PREVIEW
);
4269 return ERROR_INVALID_HANDLE
;
4271 r
= MSI_PreviewDialogW( preview
, szDialogName
);
4272 msiobj_release( &preview
->hdr
);
4276 UINT WINAPI
MsiPreviewDialogA( MSIHANDLE hPreview
, LPCSTR szDialogName
)
4281 TRACE("%d %s\n", hPreview
, debugstr_a(szDialogName
));
4285 strW
= strdupAtoW( szDialogName
);
4287 return ERROR_OUTOFMEMORY
;
4289 r
= MsiPreviewDialogW( hPreview
, strW
);
4294 UINT WINAPI
MsiPreviewBillboardW( MSIHANDLE hPreview
, LPCWSTR szControlName
, LPCWSTR szBillboard
)
4296 FIXME("%d %s %s\n", hPreview
, debugstr_w(szControlName
), debugstr_w(szBillboard
));
4297 return ERROR_CALL_NOT_IMPLEMENTED
;
4300 UINT WINAPI
MsiPreviewBillboardA( MSIHANDLE hPreview
, LPCSTR szControlName
, LPCSTR szBillboard
)
4302 FIXME("%d %s %s\n", hPreview
, debugstr_a(szControlName
), debugstr_a(szBillboard
));
4303 return ERROR_CALL_NOT_IMPLEMENTED
;
4306 struct control_event
4309 event_handler handler
;
4312 static UINT
dialog_event_handler( msi_dialog
*, const WCHAR
*, const WCHAR
* );
4314 /* create a dialog box and run it if it's modal */
4315 static INT
event_do_dialog( MSIPACKAGE
*package
, const WCHAR
*name
, msi_dialog
*parent
, BOOL destroy_modeless
)
4321 /* create a new dialog */
4322 dialog
= dialog_create( package
, name
, parent
, dialog_event_handler
);
4325 /* kill the current modeless dialog */
4326 if (destroy_modeless
&& package
->dialog
)
4328 msi_dialog_destroy( package
->dialog
);
4329 package
->dialog
= NULL
;
4332 /* modeless dialogs return an error message */
4333 r
= dialog_run_message_loop( dialog
);
4334 if (r
== ERROR_SUCCESS
)
4336 retval
= dialog
->retval
;
4337 msi_dialog_destroy( dialog
);
4342 package
->dialog
= dialog
;
4349 /* end a modal dialog box */
4350 static UINT
event_end_dialog( msi_dialog
*dialog
, const WCHAR
*argument
)
4352 if (!wcscmp( argument
, L
"Exit" ))
4353 dialog
->retval
= IDCANCEL
;
4354 else if (!wcscmp( argument
, L
"Retry" ))
4355 dialog
->retval
= IDRETRY
;
4356 else if (!wcscmp( argument
, L
"Ignore" ))
4357 dialog
->retval
= IDOK
;
4358 else if (!wcscmp( argument
, L
"Return" ))
4362 ERR("Unknown argument string %s\n", debugstr_w(argument
));
4363 dialog
->retval
= IDABORT
;
4365 event_cleanup_subscriptions( dialog
->package
, dialog
->name
);
4366 msi_dialog_end_dialog( dialog
);
4367 return ERROR_SUCCESS
;
4370 static UINT
pending_event_end_dialog( msi_dialog
*dialog
, const WCHAR
*argument
)
4372 dialog
->pending_event
= event_end_dialog
;
4373 msi_free( dialog
->pending_argument
);
4374 dialog
->pending_argument
= strdupW( argument
);
4375 return ERROR_SUCCESS
;
4378 /* transition from one modal dialog to another modal dialog */
4379 static UINT
event_new_dialog( msi_dialog
*dialog
, const WCHAR
*argument
)
4381 /* store the name of the next dialog, and signal this one to end */
4382 dialog
->package
->next_dialog
= strdupW( argument
);
4383 msi_event_cleanup_all_subscriptions( dialog
->package
);
4384 msi_dialog_end_dialog( dialog
);
4385 return ERROR_SUCCESS
;
4388 static UINT
pending_event_new_dialog( msi_dialog
*dialog
, const WCHAR
*argument
)
4390 dialog
->pending_event
= event_new_dialog
;
4391 msi_free( dialog
->pending_argument
);
4392 dialog
->pending_argument
= strdupW( argument
);
4393 return ERROR_SUCCESS
;
4396 /* create a new child dialog of an existing modal dialog */
4397 static UINT
event_spawn_dialog( msi_dialog
*dialog
, const WCHAR
*argument
)
4400 /* don't destroy a modeless dialogs that might be our parent */
4401 r
= event_do_dialog( dialog
->package
, argument
, dialog
, FALSE
);
4405 msi_dialog_end_dialog( dialog
);
4408 msi_dialog_update_all_controls(dialog
);
4410 return ERROR_SUCCESS
;
4413 static UINT
pending_event_spawn_dialog( msi_dialog
*dialog
, const WCHAR
*argument
)
4415 dialog
->pending_event
= event_spawn_dialog
;
4416 msi_free( dialog
->pending_argument
);
4417 dialog
->pending_argument
= strdupW( argument
);
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
);
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 (!wcscmp( argument
, feature
->Feature
) || !wcscmp( argument
, L
"ALL" ))
4442 if (feature
->ActionRequest
!= INSTALLSTATE_LOCAL
)
4443 msi_set_property( dialog
->package
->db
, L
"Preselected", L
"1", -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 (!wcscmp( argument
, feature
->Feature
) || !wcscmp( argument
, L
"ALL" ))
4458 if (feature
->ActionRequest
!= INSTALLSTATE_ABSENT
)
4459 msi_set_property( dialog
->package
->db
, L
"Preselected", L
"1", -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 (!wcscmp( argument
, feature
->Feature
) || !wcscmp( argument
, L
"ALL" ))
4474 if (feature
->ActionRequest
!= INSTALLSTATE_SOURCE
)
4475 msi_set_property( dialog
->package
->db
, L
"Preselected", L
"1", -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 (wcsicmp( 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
, L
"SelectionPath", 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 INT
ACTION_ShowDialog( MSIPACKAGE
*package
, const WCHAR
*dialog
)
4524 if (!TABLE_Exists(package
->db
, L
"Dialog")) return 0;
4526 row
= MSI_CreateRecord(0);
4527 if (!row
) return -1;
4528 MSI_RecordSetStringW(row
, 0, dialog
);
4529 rc
= MSI_ProcessMessage(package
, INSTALLMESSAGE_SHOWDIALOG
, row
);
4530 msiobj_release(&row
->hdr
);
4532 if (rc
== -2) rc
= 0;
4536 MSIRECORD
*row
= MSI_CreateRecord(2);
4537 if (!row
) return -1;
4538 MSI_RecordSetInteger(row
, 1, 2726);
4539 MSI_RecordSetStringW(row
, 2, dialog
);
4540 MSI_ProcessMessage(package
, INSTALLMESSAGE_INFO
, row
);
4542 msiobj_release(&row
->hdr
);
4547 INT
ACTION_DialogBox( MSIPACKAGE
*package
, const WCHAR
*dialog
)
4551 if (package
->next_dialog
) ERR("Already got next dialog... ignoring it\n");
4552 package
->next_dialog
= NULL
;
4554 /* Dialogs are chained through NewDialog, which sets the next_dialog member.
4555 * We fall out of the loop if we reach a modeless dialog, which immediately
4556 * returns IDOK, or an EndDialog event, which returns the value corresponding
4559 r
= event_do_dialog( package
, dialog
, NULL
, TRUE
);
4560 while (package
->next_dialog
)
4562 WCHAR
*name
= package
->next_dialog
;
4564 package
->next_dialog
= NULL
;
4565 r
= event_do_dialog( package
, name
, NULL
, TRUE
);
4571 static UINT
event_set_install_level( msi_dialog
*dialog
, const WCHAR
*argument
)
4573 int level
= wcstol( argument
, NULL
, 10 );
4575 TRACE("setting install level to %d\n", level
);
4576 return MSI_SetInstallLevel( dialog
->package
, level
);
4579 static UINT
event_directory_list_up( msi_dialog
*dialog
, const WCHAR
*argument
)
4581 return msi_dialog_directorylist_up( dialog
);
4584 static UINT
event_directory_list_new( msi_dialog
*dialog
, const WCHAR
*argument
)
4586 return msi_dialog_directorylist_new( dialog
);
4589 static UINT
event_reinstall_mode( msi_dialog
*dialog
, const WCHAR
*argument
)
4591 return msi_set_property( dialog
->package
->db
, L
"REINSTALLMODE", argument
, -1 );
4594 static UINT
event_reinstall( msi_dialog
*dialog
, const WCHAR
*argument
)
4596 return msi_set_property( dialog
->package
->db
, L
"REINSTALL", argument
, -1 );
4599 static UINT
event_validate_product_id( msi_dialog
*dialog
, const WCHAR
*argument
)
4601 return msi_validate_product_id( dialog
->package
);
4604 static const struct control_event control_events
[] =
4606 { L
"EndDialog", pending_event_end_dialog
},
4607 { L
"NewDialog", pending_event_new_dialog
},
4608 { L
"SpawnDialog", pending_event_spawn_dialog
},
4609 { L
"SpawnWaitDialog", event_spawn_wait_dialog
},
4610 { L
"DoAction", event_do_action
},
4611 { L
"AddLocal", event_add_local
},
4612 { L
"Remove", event_remove
},
4613 { L
"AddSource", event_add_source
},
4614 { L
"SetTargetPath", event_set_target_path
},
4615 { L
"Reset", event_reset
},
4616 { L
"SetInstallLevel", event_set_install_level
},
4617 { L
"DirectoryListUp", event_directory_list_up
},
4618 { L
"DirectoryListNew", event_directory_list_new
},
4619 { L
"SelectionBrowse", event_spawn_dialog
},
4620 { L
"ReinstallMode", event_reinstall_mode
},
4621 { L
"Reinstall", event_reinstall
},
4622 { L
"ValidateProductID", event_validate_product_id
},
4626 static UINT
dialog_event_handler( msi_dialog
*dialog
, const WCHAR
*event
, const WCHAR
*argument
)
4630 TRACE("handling event %s\n", debugstr_w(event
));
4632 if (!event
) return ERROR_SUCCESS
;
4634 for (i
= 0; control_events
[i
].event
; i
++)
4636 if (!wcscmp( control_events
[i
].event
, event
))
4637 return control_events
[i
].handler( dialog
, argument
);
4639 FIXME("unhandled event %s arg(%s)\n", debugstr_w(event
), debugstr_w(argument
));
4640 return ERROR_SUCCESS
;