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
41 #include "wine/debug.h"
44 #include "msiserver.h"
47 WINE_DEFAULT_DEBUG_CHANNEL(msi
);
49 extern HINSTANCE msi_hInstance
;
55 UINT (*handler
)( msi_dialog
*, struct control
*, WPARAM
);
56 void (*update
)( msi_dialog
*, struct control
* );
61 HIMAGELIST hImageList
;
65 float progress_current
;
67 BOOL progress_backwards
;
84 UINT (*event_handler
)( msi_dialog
*, const WCHAR
*, const WCHAR
* );
94 LPWSTR control_default
;
95 LPWSTR control_cancel
;
96 UINT (*pending_event
)( msi_dialog
*, const WCHAR
* );
97 LPWSTR pending_argument
;
111 struct control_handler
113 LPCWSTR control_type
;
114 UINT (*func
)( msi_dialog
*dialog
, MSIRECORD
*rec
);
117 struct radio_button_group_descr
120 struct control
*parent
;
124 /* dialog sequencing */
126 #define WM_MSI_DIALOG_CREATE (WM_USER+0x100)
127 #define WM_MSI_DIALOG_DESTROY (WM_USER+0x101)
129 #define USER_INSTALLSTATE_ALL 0x1000
131 static DWORD uiThreadId
;
132 static HWND hMsiHiddenWindow
;
134 static WCHAR
*get_window_text( HWND hwnd
)
137 WCHAR
*buf
, *new_buf
;
140 buf
= malloc( sz
* sizeof(WCHAR
) );
143 r
= GetWindowTextW( hwnd
, buf
, sz
);
147 new_buf
= realloc( buf
, sz
* sizeof(WCHAR
) );
156 static INT
dialog_scale_unit( msi_dialog
*dialog
, INT val
)
158 return MulDiv( val
, dialog
->scale
, 12 );
161 static struct control
*dialog_find_control( msi_dialog
*dialog
, const WCHAR
*name
)
163 struct control
*control
;
169 LIST_FOR_EACH_ENTRY( control
, &dialog
->controls
, struct control
, entry
)
170 if( !wcscmp( control
->name
, name
) ) /* FIXME: case sensitive? */
175 static struct control
*dialog_find_control_by_type( msi_dialog
*dialog
, const WCHAR
*type
)
177 struct control
*control
;
183 LIST_FOR_EACH_ENTRY( control
, &dialog
->controls
, struct control
, entry
)
184 if( !wcscmp( control
->type
, type
) ) /* FIXME: case sensitive? */
189 static struct control
*dialog_find_control_by_hwnd( msi_dialog
*dialog
, HWND hwnd
)
191 struct control
*control
;
195 LIST_FOR_EACH_ENTRY( control
, &dialog
->controls
, struct control
, entry
)
196 if( hwnd
== control
->hwnd
)
201 static WCHAR
*get_deformatted_field( MSIPACKAGE
*package
, MSIRECORD
*rec
, int field
)
203 LPCWSTR str
= MSI_RecordGetString( rec
, field
);
207 deformat_string( package
, str
, &ret
);
211 static WCHAR
*dialog_dup_property( msi_dialog
*dialog
, const WCHAR
*property
, BOOL indirect
)
219 prop
= msi_dup_property( dialog
->package
->db
, property
);
222 prop
= wcsdup( property
);
230 * Extract the {\style} string from the front of the text to display and
231 * update the pointer. Only the last style in a list is applied.
233 static WCHAR
*dialog_get_style( const WCHAR
*p
, const WCHAR
**rest
)
244 while ((first
= wcschr( p
, '{' )) && (q
= wcschr( first
+ 1, '}' )))
247 if( *p
!= '\\' && *p
!= '&' )
250 /* little bit of sanity checking to stop us getting confused with RTF */
251 for( i
=++p
; i
<q
; i
++ )
252 if( *i
== '}' || *i
== '\\' )
262 ret
= malloc( len
* sizeof(WCHAR
) );
265 memcpy( ret
, p
, len
*sizeof(WCHAR
) );
270 static UINT
dialog_add_font( MSIRECORD
*rec
, void *param
)
272 msi_dialog
*dialog
= param
;
279 /* create a font and add it to the list */
280 name
= MSI_RecordGetString( rec
, 1 );
281 font
= malloc( offsetof( struct font
, name
[wcslen( name
) + 1] ) );
282 lstrcpyW( font
->name
, name
);
283 list_add_head( &dialog
->fonts
, &font
->entry
);
285 font
->color
= MSI_RecordGetInteger( rec
, 4 );
287 memset( &lf
, 0, sizeof lf
);
288 face
= MSI_RecordGetString( rec
, 2 );
289 lf
.lfHeight
= MSI_RecordGetInteger( rec
, 3 );
290 style
= MSI_RecordGetInteger( rec
, 5 );
291 if( style
& msidbTextStyleStyleBitsBold
)
292 lf
.lfWeight
= FW_BOLD
;
293 if( style
& msidbTextStyleStyleBitsItalic
)
295 if( style
& msidbTextStyleStyleBitsUnderline
)
296 lf
.lfUnderline
= TRUE
;
297 if( style
& msidbTextStyleStyleBitsStrike
)
298 lf
.lfStrikeOut
= TRUE
;
299 lstrcpynW( lf
.lfFaceName
, face
, LF_FACESIZE
);
301 /* adjust the height */
302 hdc
= GetDC( dialog
->hwnd
);
305 lf
.lfHeight
= -MulDiv(lf
.lfHeight
, GetDeviceCaps(hdc
, LOGPIXELSY
), 72);
306 ReleaseDC( dialog
->hwnd
, hdc
);
309 font
->hfont
= CreateFontIndirectW( &lf
);
311 TRACE("Adding font style %s\n", debugstr_w(font
->name
) );
313 return ERROR_SUCCESS
;
316 static struct font
*dialog_find_font( msi_dialog
*dialog
, const WCHAR
*name
)
318 struct font
*font
= NULL
;
320 LIST_FOR_EACH_ENTRY( font
, &dialog
->fonts
, struct font
, entry
)
321 if( !wcscmp( font
->name
, name
) ) /* FIXME: case sensitive? */
327 static UINT
dialog_set_font( msi_dialog
*dialog
, HWND hwnd
, const WCHAR
*name
)
331 font
= dialog_find_font( dialog
, name
);
333 SendMessageW( hwnd
, WM_SETFONT
, (WPARAM
) font
->hfont
, TRUE
);
335 ERR("No font entry for %s\n", debugstr_w(name
));
336 return ERROR_SUCCESS
;
339 static UINT
dialog_build_font_list( msi_dialog
*dialog
)
344 TRACE("dialog %p\n", dialog
);
346 r
= MSI_OpenQuery( dialog
->package
->db
, &view
, L
"SELECT * FROM `TextStyle`" );
347 if( r
!= ERROR_SUCCESS
)
350 r
= MSI_IterateRecords( view
, NULL
, dialog_add_font
, dialog
);
351 msiobj_release( &view
->hdr
);
355 static void destroy_control( struct control
*t
)
357 list_remove( &t
->entry
);
358 /* leave dialog->hwnd - destroying parent destroys child windows */
362 DeleteObject( t
->hBitmap
);
364 DestroyIcon( t
->hIcon
);
366 ImageList_Destroy( t
->hImageList
);
370 FreeLibrary( t
->hDll
);
374 static struct control
*dialog_create_window( msi_dialog
*dialog
, MSIRECORD
*rec
, DWORD exstyle
,
375 const WCHAR
*szCls
, const WCHAR
*name
, const WCHAR
*text
,
376 DWORD style
, HWND parent
)
378 DWORD x
, y
, width
, height
;
379 LPWSTR font
= NULL
, title_font
= NULL
;
380 LPCWSTR title
= NULL
;
381 struct control
*control
;
385 control
= malloc( offsetof( struct control
, name
[wcslen( name
) + 1] ) );
389 lstrcpyW( control
->name
, name
);
390 list_add_tail( &dialog
->controls
, &control
->entry
);
391 control
->handler
= NULL
;
392 control
->update
= NULL
;
393 control
->property
= NULL
;
394 control
->value
= NULL
;
395 control
->hBitmap
= NULL
;
396 control
->hIcon
= NULL
;
397 control
->hImageList
= NULL
;
398 control
->hDll
= NULL
;
399 control
->tabnext
= wcsdup( MSI_RecordGetString( rec
, 11 ) );
400 control
->type
= wcsdup( MSI_RecordGetString( rec
, 3 ) );
401 control
->progress_current
= 0;
402 control
->progress_max
= 100;
403 control
->progress_backwards
= FALSE
;
405 x
= MSI_RecordGetInteger( rec
, 4 );
406 y
= MSI_RecordGetInteger( rec
, 5 );
407 width
= MSI_RecordGetInteger( rec
, 6 );
408 height
= MSI_RecordGetInteger( rec
, 7 );
410 x
= dialog_scale_unit( dialog
, x
);
411 y
= dialog_scale_unit( dialog
, y
);
412 width
= dialog_scale_unit( dialog
, width
);
413 height
= dialog_scale_unit( dialog
, height
);
417 deformat_string( dialog
->package
, text
, &title_font
);
418 font
= dialog_get_style( title_font
, &title
);
421 if (!wcsicmp( MSI_RecordGetString( rec
, 3 ), L
"Line" ))
422 height
= 2; /* line is exactly 2 units in height */
424 control
->hwnd
= CreateWindowExW( exstyle
, szCls
, title
, style
,
425 x
, y
, width
, height
, parent
, NULL
, NULL
, NULL
);
427 TRACE("Dialog %s control %s hwnd %p\n",
428 debugstr_w(dialog
->name
), debugstr_w(text
), control
->hwnd
);
430 dialog_set_font( dialog
, control
->hwnd
, font
? font
: dialog
->default_font
);
438 static WCHAR
*dialog_get_uitext( msi_dialog
*dialog
, const WCHAR
*key
)
443 rec
= MSI_QueryGetRecord( dialog
->package
->db
, L
"SELECT * FROM `UIText` WHERE `Key` = '%s'", key
);
444 if (!rec
) return NULL
;
445 text
= wcsdup( MSI_RecordGetString( rec
, 2 ) );
446 msiobj_release( &rec
->hdr
);
450 static HANDLE
load_image( MSIDATABASE
*db
, const WCHAR
*name
, UINT type
, UINT cx
, UINT cy
, UINT flags
)
453 HANDLE himage
= NULL
;
457 TRACE("%p %s %u %u %08x\n", db
, debugstr_w(name
), cx
, cy
, flags
);
459 if (!(tmp
= msi_create_temp_file( db
))) return NULL
;
461 rec
= MSI_QueryGetRecord( db
, L
"SELECT * FROM `Binary` WHERE `Name` = '%s'", name
);
464 r
= MSI_RecordStreamToFile( rec
, 2, tmp
);
465 if( r
== ERROR_SUCCESS
)
467 himage
= LoadImageW( 0, tmp
, type
, cx
, cy
, flags
);
469 msiobj_release( &rec
->hdr
);
477 static HICON
load_icon( MSIDATABASE
*db
, const WCHAR
*text
, UINT attributes
)
479 DWORD cx
= 0, cy
= 0, flags
;
481 flags
= LR_LOADFROMFILE
| LR_DEFAULTSIZE
;
482 if( attributes
& msidbControlAttributesFixedSize
)
484 flags
&= ~LR_DEFAULTSIZE
;
485 if( attributes
& msidbControlAttributesIconSize16
)
490 if( attributes
& msidbControlAttributesIconSize32
)
495 /* msidbControlAttributesIconSize48 handled by above logic */
497 return load_image( db
, text
, IMAGE_ICON
, cx
, cy
, flags
);
500 static void dialog_update_controls( msi_dialog
*dialog
, const WCHAR
*property
)
502 struct control
*control
;
504 LIST_FOR_EACH_ENTRY( control
, &dialog
->controls
, struct control
, entry
)
506 if ( control
->property
&& !wcscmp( control
->property
, property
) && control
->update
)
507 control
->update( dialog
, control
);
511 static void dialog_update_all_controls( msi_dialog
*dialog
)
513 struct control
*control
;
515 LIST_FOR_EACH_ENTRY( control
, &dialog
->controls
, struct control
, entry
)
517 if ( control
->property
&& control
->update
)
518 control
->update( dialog
, control
);
522 static void dialog_set_property( MSIPACKAGE
*package
, const WCHAR
*property
, const WCHAR
*value
)
524 UINT r
= msi_set_property( package
->db
, property
, value
, -1 );
525 if (r
== ERROR_SUCCESS
&& !wcscmp( property
, L
"SourceDir" ))
526 msi_reset_source_folders( package
);
529 static MSIFEATURE
*seltree_feature_from_item( HWND hwnd
, HTREEITEM hItem
)
533 /* get the feature from the item */
534 memset( &tvi
, 0, sizeof tvi
);
536 tvi
.mask
= TVIF_PARAM
| TVIF_HANDLE
;
537 SendMessageW( hwnd
, TVM_GETITEMW
, 0, (LPARAM
)&tvi
);
538 return (MSIFEATURE
*)tvi
.lParam
;
541 struct msi_selection_tree_info
549 static MSIFEATURE
*seltree_get_selected_feature( struct control
*control
)
551 struct msi_selection_tree_info
*info
= GetPropW( control
->hwnd
, L
"MSIDATA" );
552 return seltree_feature_from_item( control
->hwnd
, info
->selected
);
555 static void dialog_handle_event( msi_dialog
*dialog
, const WCHAR
*control
, const WCHAR
*attribute
, MSIRECORD
*rec
)
557 struct control
* ctrl
;
559 ctrl
= dialog_find_control( dialog
, control
);
562 if( !wcscmp( attribute
, L
"Text" ) )
564 const WCHAR
*font_text
, *text
= NULL
;
565 WCHAR
*font
, *text_fmt
= NULL
;
567 font_text
= MSI_RecordGetString( rec
, 1 );
568 font
= dialog_get_style( font_text
, &text
);
569 deformat_string( dialog
->package
, text
, &text_fmt
);
570 if (text_fmt
) text
= text_fmt
;
573 SetWindowTextW( ctrl
->hwnd
, text
);
577 msi_dialog_check_messages( NULL
);
579 else if( !wcscmp( attribute
, L
"Progress" ) )
581 DWORD func
, val1
, val2
, units
;
583 func
= MSI_RecordGetInteger( rec
, 1 );
584 val1
= MSI_RecordGetInteger( rec
, 2 );
585 val2
= MSI_RecordGetInteger( rec
, 3 );
587 TRACE( "progress: func %lu val1 %lu val2 %lu\n", func
, val1
, val2
);
593 SendMessageW( ctrl
->hwnd
, PBM_SETRANGE
, 0, MAKELPARAM(0,100) );
596 ctrl
->progress_max
= units
? units
: 100;
597 ctrl
->progress_current
= units
;
598 ctrl
->progress_backwards
= TRUE
;
599 SendMessageW( ctrl
->hwnd
, PBM_SETPOS
, 100, 0 );
603 ctrl
->progress_max
= units
? units
: 100;
604 ctrl
->progress_current
= 0;
605 ctrl
->progress_backwards
= FALSE
;
606 SendMessageW( ctrl
->hwnd
, PBM_SETPOS
, 0, 0 );
609 case 1: /* action data increment */
610 if (val2
) dialog
->package
->action_progress_increment
= val1
;
611 else dialog
->package
->action_progress_increment
= 0;
614 if (ctrl
->progress_backwards
)
616 if (units
>= ctrl
->progress_current
) ctrl
->progress_current
-= units
;
617 else ctrl
->progress_current
= 0;
621 if (ctrl
->progress_current
+ units
< ctrl
->progress_max
) ctrl
->progress_current
+= units
;
622 else ctrl
->progress_current
= ctrl
->progress_max
;
624 SendMessageW( ctrl
->hwnd
, PBM_SETPOS
, MulDiv(100, ctrl
->progress_current
, ctrl
->progress_max
), 0 );
627 ctrl
->progress_max
+= units
;
630 FIXME( "unknown progress message %lu\n", func
);
634 else if ( !wcscmp( attribute
, L
"Property" ) )
636 MSIFEATURE
*feature
= seltree_get_selected_feature( ctrl
);
637 if (feature
) dialog_set_property( dialog
->package
, ctrl
->property
, feature
->Directory
);
639 else if ( !wcscmp( attribute
, L
"SelectionPath" ) )
641 BOOL indirect
= ctrl
->attributes
& msidbControlAttributesIndirect
;
642 WCHAR
*path
= dialog_dup_property( dialog
, ctrl
->property
, indirect
);
644 SetWindowTextW( ctrl
->hwnd
, path
);
649 FIXME("Attribute %s not being set\n", debugstr_w(attribute
));
654 static void event_subscribe( msi_dialog
*dialog
, const WCHAR
*event
, const WCHAR
*control
, const WCHAR
*attribute
)
656 struct subscriber
*sub
;
658 TRACE("dialog %s event %s control %s attribute %s\n", debugstr_w(dialog
->name
), debugstr_w(event
),
659 debugstr_w(control
), debugstr_w(attribute
));
661 LIST_FOR_EACH_ENTRY( sub
, &dialog
->package
->subscriptions
, struct subscriber
, entry
)
663 if (sub
->dialog
== dialog
&&
664 !wcsicmp( sub
->event
, event
) &&
665 !wcsicmp( sub
->control
, control
) &&
666 !wcsicmp( sub
->attribute
, attribute
))
668 TRACE("already subscribed\n");
672 if (!(sub
= malloc( sizeof(*sub
) ))) return;
673 sub
->dialog
= dialog
;
674 sub
->event
= wcsdup( event
);
675 sub
->control
= wcsdup( control
);
676 sub
->attribute
= wcsdup( attribute
);
677 list_add_tail( &dialog
->package
->subscriptions
, &sub
->entry
);
680 struct dialog_control
683 const WCHAR
*control
;
686 static UINT
map_event( MSIRECORD
*row
, void *param
)
688 struct dialog_control
*dc
= param
;
689 const WCHAR
*event
= MSI_RecordGetString( row
, 3 );
690 const WCHAR
*attribute
= MSI_RecordGetString( row
, 4 );
692 event_subscribe( dc
->dialog
, event
, dc
->control
, attribute
);
693 return ERROR_SUCCESS
;
696 static void dialog_map_events( msi_dialog
*dialog
, const WCHAR
*control
)
699 struct dialog_control dialog_control
=
705 if (!MSI_OpenQuery( dialog
->package
->db
, &view
,
706 L
"SELECT * FROM `EventMapping` WHERE `Dialog_` = '%s' AND `Control_` = '%s'",
707 dialog
->name
, control
))
709 MSI_IterateRecords( view
, NULL
, map_event
, &dialog_control
);
710 msiobj_release( &view
->hdr
);
714 /* everything except radio buttons */
715 static struct control
*dialog_add_control( msi_dialog
*dialog
, MSIRECORD
*rec
, const WCHAR
*szCls
, DWORD style
)
718 const WCHAR
*text
= NULL
, *name
, *control_type
;
721 name
= MSI_RecordGetString( rec
, 2 );
722 control_type
= MSI_RecordGetString( rec
, 3 );
723 attributes
= MSI_RecordGetInteger( rec
, 8 );
724 if (wcscmp( control_type
, L
"ScrollableText" )) text
= MSI_RecordGetString( rec
, 10 );
726 TRACE( "%s, %s, %#lx, %s, %#lx\n", debugstr_w(szCls
), debugstr_w(name
), attributes
, debugstr_w(text
), style
);
728 if( attributes
& msidbControlAttributesVisible
)
730 if( ~attributes
& msidbControlAttributesEnabled
)
731 style
|= WS_DISABLED
;
732 if( attributes
& msidbControlAttributesSunken
)
733 exstyle
|= WS_EX_CLIENTEDGE
;
735 dialog_map_events( dialog
, name
);
737 return dialog_create_window( dialog
, rec
, exstyle
, szCls
, name
, text
, style
, dialog
->hwnd
);
748 * we don't erase our own background,
749 * so we have to make sure that the parent window redraws first
751 static void text_on_settext( HWND hWnd
)
756 hParent
= GetParent( hWnd
);
757 GetWindowRect( hWnd
, &rc
);
758 MapWindowPoints( NULL
, hParent
, (LPPOINT
) &rc
, 2 );
759 InvalidateRect( hParent
, &rc
, TRUE
);
762 static LRESULT WINAPI
MSIText_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
764 struct msi_text_info
*info
;
767 TRACE( "%p %04x %#Ix %#Ix\n", hWnd
, msg
, wParam
, lParam
);
769 info
= GetPropW(hWnd
, L
"MSIDATA");
771 if( msg
== WM_CTLCOLORSTATIC
&&
772 ( info
->attributes
& msidbControlAttributesTransparent
) )
774 SetBkMode( (HDC
)wParam
, TRANSPARENT
);
775 return (LRESULT
) GetStockObject(NULL_BRUSH
);
778 r
= CallWindowProcW(info
->oldproc
, hWnd
, msg
, wParam
, lParam
);
780 SetTextColor( (HDC
)wParam
, info
->font
->color
);
785 text_on_settext( hWnd
);
789 RemovePropW( hWnd
, L
"MSIDATA" );
796 static UINT
dialog_text_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
798 struct control
*control
;
799 struct msi_text_info
*info
;
800 LPCWSTR text
, ptr
, prop
, control_name
;
803 TRACE("%p %p\n", dialog
, rec
);
805 control
= dialog_add_control( dialog
, rec
, L
"Static", SS_LEFT
| WS_GROUP
);
807 return ERROR_FUNCTION_FAILED
;
809 info
= malloc( sizeof *info
);
811 return ERROR_SUCCESS
;
813 control_name
= MSI_RecordGetString( rec
, 2 );
814 control
->attributes
= MSI_RecordGetInteger( rec
, 8 );
815 prop
= MSI_RecordGetString( rec
, 9 );
816 control
->property
= dialog_dup_property( dialog
, prop
, FALSE
);
818 text
= MSI_RecordGetString( rec
, 10 );
819 font_name
= dialog_get_style( text
, &ptr
);
820 info
->font
= ( font_name
) ? dialog_find_font( dialog
, font_name
) : NULL
;
823 info
->attributes
= MSI_RecordGetInteger( rec
, 8 );
824 if( info
->attributes
& msidbControlAttributesTransparent
)
825 SetWindowLongPtrW( control
->hwnd
, GWL_EXSTYLE
, WS_EX_TRANSPARENT
);
827 info
->oldproc
= (WNDPROC
) SetWindowLongPtrW( control
->hwnd
, GWLP_WNDPROC
,
828 (LONG_PTR
)MSIText_WndProc
);
829 SetPropW( control
->hwnd
, L
"MSIDATA", info
);
831 event_subscribe( dialog
, L
"SelectionPath", control_name
, L
"SelectionPath" );
832 return ERROR_SUCCESS
;
835 /* strip any leading text style label from text field */
836 static WCHAR
*get_binary_name( MSIPACKAGE
*package
, MSIRECORD
*rec
)
840 text
= get_deformatted_field( package
, rec
, 10 );
845 while (*p
&& *p
!= '{') p
++;
846 if (!*p
++) return text
;
848 while (*p
&& *p
!= '}') p
++;
849 if (!*p
++) return text
;
856 static UINT
dialog_set_property_event( msi_dialog
*dialog
, const WCHAR
*event
, const WCHAR
*arg
)
858 LPWSTR p
, prop
, arg_fmt
= NULL
;
861 len
= lstrlenW( event
);
862 prop
= malloc( len
* sizeof(WCHAR
) );
863 lstrcpyW( prop
, &event
[1] );
864 p
= wcschr( prop
, ']' );
865 if (p
&& (p
[1] == 0 || p
[1] == ' '))
868 if (wcscmp( L
"{}", arg
)) deformat_string( dialog
->package
, arg
, &arg_fmt
);
869 dialog_set_property( dialog
->package
, prop
, arg_fmt
);
870 dialog_update_controls( dialog
, prop
);
873 else ERR("Badly formatted property string - what happens?\n");
875 return ERROR_SUCCESS
;
878 static UINT
dialog_send_event( msi_dialog
*dialog
, const WCHAR
*event
, const WCHAR
*arg
)
880 LPWSTR event_fmt
= NULL
, arg_fmt
= NULL
;
882 TRACE("Sending control event %s %s\n", debugstr_w(event
), debugstr_w(arg
));
884 deformat_string( dialog
->package
, event
, &event_fmt
);
885 deformat_string( dialog
->package
, arg
, &arg_fmt
);
887 dialog
->event_handler( dialog
, event_fmt
, arg_fmt
);
892 return ERROR_SUCCESS
;
895 static UINT
dialog_control_event( MSIRECORD
*rec
, void *param
)
897 msi_dialog
*dialog
= param
;
898 LPCWSTR condition
, event
, arg
;
901 condition
= MSI_RecordGetString( rec
, 5 );
902 r
= MSI_EvaluateConditionW( dialog
->package
, condition
);
903 if (r
== MSICONDITION_TRUE
|| r
== MSICONDITION_NONE
)
905 event
= MSI_RecordGetString( rec
, 3 );
906 arg
= MSI_RecordGetString( rec
, 4 );
908 dialog_set_property_event( dialog
, event
, arg
);
910 dialog_send_event( dialog
, event
, arg
);
912 return ERROR_SUCCESS
;
915 static UINT
dialog_button_handler( msi_dialog
*dialog
, struct control
*control
, WPARAM param
)
920 if (HIWORD(param
) != BN_CLICKED
)
921 return ERROR_SUCCESS
;
923 r
= MSI_OpenQuery( dialog
->package
->db
, &view
,
924 L
"SELECT * FROM `ControlEvent` WHERE `Dialog_` = '%s' AND `Control_` = '%s' ORDER BY `Ordering`",
925 dialog
->name
, control
->name
);
926 if (r
!= ERROR_SUCCESS
)
928 ERR("query failed\n");
929 return ERROR_SUCCESS
;
931 r
= MSI_IterateRecords( view
, 0, dialog_control_event
, dialog
);
932 msiobj_release( &view
->hdr
);
934 /* dialog control events must be processed last regardless of ordering */
935 if (dialog
->pending_event
)
937 r
= dialog
->pending_event( dialog
, dialog
->pending_argument
);
939 free( dialog
->pending_argument
);
940 dialog
->pending_event
= NULL
;
941 dialog
->pending_argument
= NULL
;
946 static HBITMAP
load_picture( MSIDATABASE
*db
, const WCHAR
*name
, INT cx
, INT cy
, DWORD flags
)
948 HBITMAP hOleBitmap
= 0, hBitmap
= 0, hOldSrcBitmap
, hOldDestBitmap
;
949 MSIRECORD
*rec
= NULL
;
951 IPicture
*pic
= NULL
;
956 rec
= MSI_QueryGetRecord( db
, L
"SELECT * FROM `Binary` WHERE `Name` = '%s'", name
);
960 r
= MSI_RecordGetIStream( rec
, 2, &stm
);
961 msiobj_release( &rec
->hdr
);
962 if (r
!= ERROR_SUCCESS
)
965 r
= OleLoadPicture( stm
, 0, TRUE
, &IID_IPicture
, (void **)&pic
);
966 IStream_Release( stm
);
969 ERR("failed to load picture\n");
973 r
= IPicture_get_Handle( pic
, (OLE_HANDLE
*)&hOleBitmap
);
976 ERR("failed to get bitmap handle\n");
980 /* make the bitmap the desired size */
981 r
= GetObjectW( hOleBitmap
, sizeof(bm
), &bm
);
984 ERR("failed to get bitmap size\n");
988 if (flags
& LR_DEFAULTSIZE
)
994 srcdc
= CreateCompatibleDC( NULL
);
995 hOldSrcBitmap
= SelectObject( srcdc
, hOleBitmap
);
996 destdc
= CreateCompatibleDC( NULL
);
997 hBitmap
= CreateCompatibleBitmap( srcdc
, cx
, cy
);
998 hOldDestBitmap
= SelectObject( destdc
, hBitmap
);
999 StretchBlt( destdc
, 0, 0, cx
, cy
, srcdc
, 0, 0, bm
.bmWidth
, bm
.bmHeight
, SRCCOPY
);
1000 SelectObject( srcdc
, hOldSrcBitmap
);
1001 SelectObject( destdc
, hOldDestBitmap
);
1006 if (pic
) IPicture_Release( pic
);
1010 static UINT
dialog_button_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1012 struct control
*control
;
1013 UINT attributes
, style
, cx
= 0, cy
= 0, flags
= 0;
1016 TRACE("%p %p\n", dialog
, rec
);
1019 attributes
= MSI_RecordGetInteger( rec
, 8 );
1020 if (attributes
& msidbControlAttributesIcon
) style
|= BS_ICON
;
1021 else if (attributes
& msidbControlAttributesBitmap
)
1024 if (attributes
& msidbControlAttributesFixedSize
) flags
|= LR_DEFAULTSIZE
;
1027 cx
= dialog_scale_unit( dialog
, MSI_RecordGetInteger(rec
, 6) );
1028 cy
= dialog_scale_unit( dialog
, MSI_RecordGetInteger(rec
, 7) );
1032 control
= dialog_add_control( dialog
, rec
, L
"BUTTON", style
);
1034 return ERROR_FUNCTION_FAILED
;
1036 control
->handler
= dialog_button_handler
;
1038 if (attributes
& msidbControlAttributesIcon
)
1040 name
= get_binary_name( dialog
->package
, rec
);
1041 control
->hIcon
= load_icon( dialog
->package
->db
, name
, attributes
);
1044 SendMessageW( control
->hwnd
, BM_SETIMAGE
, IMAGE_ICON
, (LPARAM
) control
->hIcon
);
1046 else ERR("Failed to load icon %s\n", debugstr_w(name
));
1048 else if (attributes
& msidbControlAttributesBitmap
)
1050 name
= get_binary_name( dialog
->package
, rec
);
1051 control
->hBitmap
= load_picture( dialog
->package
->db
, name
, cx
, cy
, flags
);
1052 if (control
->hBitmap
)
1054 SendMessageW( control
->hwnd
, BM_SETIMAGE
, IMAGE_BITMAP
, (LPARAM
) control
->hBitmap
);
1056 else ERR("Failed to load bitmap %s\n", debugstr_w(name
));
1060 return ERROR_SUCCESS
;
1063 static WCHAR
*get_checkbox_value( msi_dialog
*dialog
, const WCHAR
*prop
)
1065 MSIRECORD
*rec
= NULL
;
1068 /* find if there is a value associated with the checkbox */
1069 rec
= MSI_QueryGetRecord( dialog
->package
->db
, L
"SELECT * FROM `CheckBox` WHERE `Property` = '%s'", prop
);
1073 ret
= get_deformatted_field( dialog
->package
, rec
, 2 );
1074 if( ret
&& !ret
[0] )
1079 msiobj_release( &rec
->hdr
);
1083 ret
= msi_dup_property( dialog
->package
->db
, prop
);
1084 if( ret
&& !ret
[0] )
1093 static UINT
dialog_get_checkbox_state( msi_dialog
*dialog
, struct control
*control
)
1095 WCHAR state
[2] = {0};
1098 msi_get_property( dialog
->package
->db
, control
->property
, state
, &sz
);
1099 return state
[0] ? 1 : 0;
1102 static void dialog_set_checkbox_state( msi_dialog
*dialog
, struct control
*control
, UINT state
)
1106 /* if uncheck then the property is set to NULL */
1109 dialog_set_property( dialog
->package
, control
->property
, NULL
);
1113 /* check for a custom state */
1114 if (control
->value
&& control
->value
[0])
1115 val
= control
->value
;
1119 dialog_set_property( dialog
->package
, control
->property
, val
);
1122 static void dialog_checkbox_sync_state( msi_dialog
*dialog
, struct control
*control
)
1124 UINT state
= dialog_get_checkbox_state( dialog
, control
);
1125 SendMessageW( control
->hwnd
, BM_SETCHECK
, state
? BST_CHECKED
: BST_UNCHECKED
, 0 );
1128 static UINT
dialog_checkbox_handler( msi_dialog
*dialog
, struct control
*control
, WPARAM param
)
1132 if (HIWORD(param
) != BN_CLICKED
)
1133 return ERROR_SUCCESS
;
1135 TRACE("clicked checkbox %s, set %s\n", debugstr_w(control
->name
), debugstr_w(control
->property
));
1137 state
= dialog_get_checkbox_state( dialog
, control
);
1138 state
= state
? 0 : 1;
1139 dialog_set_checkbox_state( dialog
, control
, state
);
1140 dialog_checkbox_sync_state( dialog
, control
);
1142 return dialog_button_handler( dialog
, control
, param
);
1145 static UINT
dialog_checkbox_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1147 struct control
*control
;
1150 TRACE("%p %p\n", dialog
, rec
);
1152 control
= dialog_add_control( dialog
, rec
, L
"BUTTON", BS_CHECKBOX
| BS_MULTILINE
| WS_TABSTOP
);
1153 control
->handler
= dialog_checkbox_handler
;
1154 control
->update
= dialog_checkbox_sync_state
;
1155 prop
= MSI_RecordGetString( rec
, 9 );
1158 control
->property
= wcsdup( prop
);
1159 control
->value
= get_checkbox_value( dialog
, prop
);
1160 TRACE("control %s value %s\n", debugstr_w(control
->property
), debugstr_w(control
->value
));
1162 dialog_checkbox_sync_state( dialog
, control
);
1163 return ERROR_SUCCESS
;
1166 static UINT
dialog_line_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1168 if (!dialog_add_control( dialog
, rec
, L
"Static", SS_ETCHEDHORZ
| SS_SUNKEN
))
1169 return ERROR_FUNCTION_FAILED
;
1171 return ERROR_SUCCESS
;
1174 /******************** Scroll Text ********************************************/
1176 struct msi_scrolltext_info
1179 struct control
*control
;
1183 static LRESULT WINAPI
MSIScrollText_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1185 struct msi_scrolltext_info
*info
;
1188 TRACE( "%p %04x %#Ix %#Ix\n", hWnd
, msg
, wParam
, lParam
);
1190 info
= GetPropW( hWnd
, L
"MSIDATA" );
1192 r
= CallWindowProcW( info
->oldproc
, hWnd
, msg
, wParam
, lParam
);
1197 return DLGC_WANTARROWS
;
1200 RemovePropW( hWnd
, L
"MSIDATA" );
1203 /* native MSI sets a wait cursor here */
1204 dialog_button_handler( info
->dialog
, info
->control
, BN_CLICKED
);
1210 struct msi_streamin_info
1217 static DWORD CALLBACK
richedit_stream_in( DWORD_PTR arg
, BYTE
*buffer
, LONG count
, LONG
*pcb
)
1219 struct msi_streamin_info
*info
= (struct msi_streamin_info
*) arg
;
1221 if( (count
+ info
->offset
) > info
->length
)
1222 count
= info
->length
- info
->offset
;
1223 memcpy( buffer
, &info
->string
[ info
->offset
], count
);
1225 info
->offset
+= count
;
1227 TRACE( "%lu/%lu\n", info
->offset
, info
->length
);
1232 static void scrolltext_add_text( struct control
*control
, const WCHAR
*text
)
1234 struct msi_streamin_info info
;
1237 info
.string
= strdupWtoA( text
);
1239 info
.length
= lstrlenA( info
.string
) + 1;
1241 es
.dwCookie
= (DWORD_PTR
) &info
;
1243 es
.pfnCallback
= richedit_stream_in
;
1245 SendMessageW( control
->hwnd
, EM_STREAMIN
, SF_RTF
, (LPARAM
) &es
);
1247 free( info
.string
);
1250 static UINT
dialog_scrolltext_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1252 struct msi_scrolltext_info
*info
;
1253 struct control
*control
;
1258 info
= malloc( sizeof *info
);
1260 return ERROR_FUNCTION_FAILED
;
1262 hRichedit
= LoadLibraryA("riched20");
1264 style
= WS_BORDER
| ES_MULTILINE
| WS_VSCROLL
|
1265 ES_READONLY
| ES_AUTOVSCROLL
| WS_TABSTOP
;
1266 control
= dialog_add_control( dialog
, rec
, L
"RichEdit20W", style
);
1269 FreeLibrary( hRichedit
);
1271 return ERROR_FUNCTION_FAILED
;
1274 control
->hDll
= hRichedit
;
1276 info
->dialog
= dialog
;
1277 info
->control
= control
;
1279 /* subclass the static control */
1280 info
->oldproc
= (WNDPROC
) SetWindowLongPtrW( control
->hwnd
, GWLP_WNDPROC
,
1281 (LONG_PTR
)MSIScrollText_WndProc
);
1282 SetPropW( control
->hwnd
, L
"MSIDATA", info
);
1284 /* add the text into the richedit */
1285 text
= MSI_RecordGetString( rec
, 10 );
1287 scrolltext_add_text( control
, text
);
1289 return ERROR_SUCCESS
;
1293 static UINT
dialog_bitmap_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1295 UINT cx
, cy
, flags
, style
, attributes
;
1296 struct control
*control
;
1299 flags
= LR_LOADFROMFILE
;
1300 style
= SS_BITMAP
| SS_LEFT
| WS_GROUP
;
1302 attributes
= MSI_RecordGetInteger( rec
, 8 );
1303 if( attributes
& msidbControlAttributesFixedSize
)
1305 flags
|= LR_DEFAULTSIZE
;
1306 style
|= SS_CENTERIMAGE
;
1309 control
= dialog_add_control( dialog
, rec
, L
"Static", style
);
1310 cx
= MSI_RecordGetInteger( rec
, 6 );
1311 cy
= MSI_RecordGetInteger( rec
, 7 );
1312 cx
= dialog_scale_unit( dialog
, cx
);
1313 cy
= dialog_scale_unit( dialog
, cy
);
1315 name
= get_binary_name( dialog
->package
, rec
);
1316 control
->hBitmap
= load_picture( dialog
->package
->db
, name
, cx
, cy
, flags
);
1317 if( control
->hBitmap
)
1318 SendMessageW( control
->hwnd
, STM_SETIMAGE
,
1319 IMAGE_BITMAP
, (LPARAM
) control
->hBitmap
);
1321 ERR("Failed to load bitmap %s\n", debugstr_w(name
));
1325 return ERROR_SUCCESS
;
1328 static UINT
dialog_icon_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1330 struct control
*control
;
1336 control
= dialog_add_control( dialog
, rec
, L
"Static", SS_ICON
| SS_CENTERIMAGE
| WS_GROUP
);
1338 attributes
= MSI_RecordGetInteger( rec
, 8 );
1339 name
= get_binary_name( dialog
->package
, rec
);
1340 control
->hIcon
= load_icon( dialog
->package
->db
, name
, attributes
);
1341 if( control
->hIcon
)
1342 SendMessageW( control
->hwnd
, STM_SETICON
, (WPARAM
) control
->hIcon
, 0 );
1344 ERR("Failed to load bitmap %s\n", debugstr_w(name
));
1346 return ERROR_SUCCESS
;
1349 /******************** Combo Box ***************************************/
1351 struct msi_combobox_info
1361 static LRESULT WINAPI
MSIComboBox_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1363 struct msi_combobox_info
*info
;
1367 TRACE( "%p %04x %#Ix %#Ix\n", hWnd
, msg
, wParam
, lParam
);
1369 info
= GetPropW( hWnd
, L
"MSIDATA" );
1373 r
= CallWindowProcW( info
->oldproc
, hWnd
, msg
, wParam
, lParam
);
1378 for (j
= 0; j
< info
->num_items
; j
++)
1379 free( info
->items
[j
] );
1380 free( info
->items
);
1382 RemovePropW( hWnd
, L
"MSIDATA" );
1389 static UINT
combobox_add_item( MSIRECORD
*rec
, void *param
)
1391 struct msi_combobox_info
*info
= param
;
1392 LPCWSTR value
, text
;
1395 value
= MSI_RecordGetString( rec
, 3 );
1396 text
= MSI_RecordGetString( rec
, 4 );
1398 info
->items
[info
->addpos_items
] = wcsdup( value
);
1400 pos
= SendMessageW( info
->hwnd
, CB_ADDSTRING
, 0, (LPARAM
)text
);
1401 SendMessageW( info
->hwnd
, CB_SETITEMDATA
, pos
, (LPARAM
)info
->items
[info
->addpos_items
] );
1402 info
->addpos_items
++;
1404 return ERROR_SUCCESS
;
1407 static UINT
combobox_add_items( struct msi_combobox_info
*info
, const WCHAR
*property
)
1413 r
= MSI_OpenQuery( info
->dialog
->package
->db
, &view
,
1414 L
"SELECT * FROM `ComboBox` WHERE `Property` = '%s' ORDER BY `Order`", property
);
1415 if (r
!= ERROR_SUCCESS
)
1418 /* just get the number of records */
1420 r
= MSI_IterateRecords( view
, &count
, NULL
, NULL
);
1421 if (r
!= ERROR_SUCCESS
)
1423 msiobj_release( &view
->hdr
);
1426 info
->num_items
= count
;
1427 info
->items
= malloc( sizeof(*info
->items
) * count
);
1429 r
= MSI_IterateRecords( view
, NULL
, combobox_add_item
, info
);
1430 msiobj_release( &view
->hdr
);
1434 static UINT
dialog_set_control_condition( MSIRECORD
*rec
, void *param
)
1436 msi_dialog
*dialog
= param
;
1437 struct control
*control
;
1438 LPCWSTR name
, action
, condition
;
1441 name
= MSI_RecordGetString( rec
, 2 );
1442 action
= MSI_RecordGetString( rec
, 3 );
1443 condition
= MSI_RecordGetString( rec
, 4 );
1444 r
= MSI_EvaluateConditionW( dialog
->package
, condition
);
1445 control
= dialog_find_control( dialog
, name
);
1446 if (r
== MSICONDITION_TRUE
&& control
)
1448 TRACE("%s control %s\n", debugstr_w(action
), debugstr_w(name
));
1450 /* FIXME: case sensitive? */
1451 if (!wcscmp( action
, L
"Hide" ))
1452 ShowWindow(control
->hwnd
, SW_HIDE
);
1453 else if (!wcscmp( action
, L
"Show" ))
1454 ShowWindow(control
->hwnd
, SW_SHOW
);
1455 else if (!wcscmp( action
, L
"Disable" ))
1456 EnableWindow(control
->hwnd
, FALSE
);
1457 else if (!wcscmp( action
, L
"Enable" ))
1458 EnableWindow(control
->hwnd
, TRUE
);
1459 else if (!wcscmp( action
, L
"Default" ))
1460 SetFocus(control
->hwnd
);
1462 FIXME("Unhandled action %s\n", debugstr_w(action
));
1464 return ERROR_SUCCESS
;
1467 static UINT
dialog_evaluate_control_conditions( msi_dialog
*dialog
)
1471 MSIPACKAGE
*package
= dialog
->package
;
1473 TRACE("%p %s\n", dialog
, debugstr_w(dialog
->name
));
1475 /* query the Control table for all the elements of the control */
1476 r
= MSI_OpenQuery( package
->db
, &view
, L
"SELECT * FROM `ControlCondition` WHERE `Dialog_` = '%s'", dialog
->name
);
1477 if (r
!= ERROR_SUCCESS
)
1478 return ERROR_SUCCESS
;
1480 r
= MSI_IterateRecords( view
, 0, dialog_set_control_condition
, dialog
);
1481 msiobj_release( &view
->hdr
);
1485 static UINT
dialog_combobox_handler( msi_dialog
*dialog
, struct control
*control
, WPARAM param
)
1487 struct msi_combobox_info
*info
;
1491 if (HIWORD(param
) != CBN_SELCHANGE
&& HIWORD(param
) != CBN_EDITCHANGE
)
1492 return ERROR_SUCCESS
;
1494 info
= GetPropW( control
->hwnd
, L
"MSIDATA" );
1495 index
= SendMessageW( control
->hwnd
, CB_GETCURSEL
, 0, 0 );
1496 if (index
== CB_ERR
)
1497 value
= get_window_text( control
->hwnd
);
1499 value
= (LPWSTR
) SendMessageW( control
->hwnd
, CB_GETITEMDATA
, index
, 0 );
1501 dialog_set_property( info
->dialog
->package
, control
->property
, value
);
1502 dialog_evaluate_control_conditions( info
->dialog
);
1504 if (index
== CB_ERR
)
1507 return ERROR_SUCCESS
;
1510 static void dialog_combobox_update( msi_dialog
*dialog
, struct control
*control
)
1512 struct msi_combobox_info
*info
;
1516 info
= GetPropW( control
->hwnd
, L
"MSIDATA" );
1518 value
= msi_dup_property( dialog
->package
->db
, control
->property
);
1521 SendMessageW( control
->hwnd
, CB_SETCURSEL
, -1, 0 );
1525 for (j
= 0; j
< info
->num_items
; j
++)
1527 tmp
= (LPWSTR
) SendMessageW( control
->hwnd
, CB_GETITEMDATA
, j
, 0 );
1528 if (!wcscmp( value
, tmp
))
1532 if (j
< info
->num_items
)
1534 SendMessageW( control
->hwnd
, CB_SETCURSEL
, j
, 0 );
1538 SendMessageW( control
->hwnd
, CB_SETCURSEL
, -1, 0 );
1539 SetWindowTextW( control
->hwnd
, value
);
1545 static UINT
dialog_combo_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1547 struct msi_combobox_info
*info
;
1548 struct control
*control
;
1549 DWORD attributes
, style
;
1552 info
= malloc( sizeof *info
);
1554 return ERROR_FUNCTION_FAILED
;
1556 style
= CBS_AUTOHSCROLL
| WS_TABSTOP
| WS_GROUP
| WS_CHILD
;
1557 attributes
= MSI_RecordGetInteger( rec
, 8 );
1558 if ( ~attributes
& msidbControlAttributesSorted
)
1560 if ( attributes
& msidbControlAttributesComboList
)
1561 style
|= CBS_DROPDOWNLIST
;
1563 style
|= CBS_DROPDOWN
;
1565 control
= dialog_add_control( dialog
, rec
, WC_COMBOBOXW
, style
);
1569 return ERROR_FUNCTION_FAILED
;
1572 control
->handler
= dialog_combobox_handler
;
1573 control
->update
= dialog_combobox_update
;
1575 prop
= MSI_RecordGetString( rec
, 9 );
1576 control
->property
= dialog_dup_property( dialog
, prop
, FALSE
);
1579 info
->dialog
= dialog
;
1580 info
->hwnd
= control
->hwnd
;
1582 info
->addpos_items
= 0;
1583 info
->oldproc
= (WNDPROC
)SetWindowLongPtrW( control
->hwnd
, GWLP_WNDPROC
,
1584 (LONG_PTR
)MSIComboBox_WndProc
);
1585 SetPropW( control
->hwnd
, L
"MSIDATA", info
);
1587 if (control
->property
)
1588 combobox_add_items( info
, control
->property
);
1590 dialog_combobox_update( dialog
, control
);
1592 return ERROR_SUCCESS
;
1595 static UINT
dialog_edit_handler( msi_dialog
*dialog
, struct control
*control
, WPARAM param
)
1599 if (HIWORD(param
) != EN_CHANGE
)
1600 return ERROR_SUCCESS
;
1602 TRACE("edit %s contents changed, set %s\n", debugstr_w(control
->name
), debugstr_w(control
->property
));
1604 buf
= get_window_text( control
->hwnd
);
1605 dialog_set_property( dialog
->package
, control
->property
, buf
);
1608 return ERROR_SUCCESS
;
1611 /* length of 2^32 + 1 */
1612 #define MAX_NUM_DIGITS 11
1614 static UINT
dialog_edit_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1616 struct control
*control
;
1618 LPWSTR val
, begin
, end
;
1619 WCHAR num
[MAX_NUM_DIGITS
];
1622 control
= dialog_add_control( dialog
, rec
, L
"Edit", WS_BORDER
| WS_TABSTOP
| ES_AUTOHSCROLL
);
1623 control
->handler
= dialog_edit_handler
;
1625 text
= MSI_RecordGetString( rec
, 10 );
1628 begin
= wcschr( text
, '{' );
1629 end
= wcschr( text
, '}' );
1631 if ( begin
&& end
&& end
> begin
&&
1632 begin
[0] >= '0' && begin
[0] <= '9' &&
1633 end
- begin
< MAX_NUM_DIGITS
)
1635 lstrcpynW( num
, begin
+ 1, end
- begin
);
1636 limit
= wcstol( num
, NULL
, 10 );
1638 SendMessageW( control
->hwnd
, EM_SETLIMITTEXT
, limit
, 0 );
1642 prop
= MSI_RecordGetString( rec
, 9 );
1644 control
->property
= wcsdup( prop
);
1646 val
= msi_dup_property( dialog
->package
->db
, control
->property
);
1647 SetWindowTextW( control
->hwnd
, val
);
1649 return ERROR_SUCCESS
;
1652 /******************** Masked Edit ********************************************/
1654 #define MASK_MAX_GROUPS 20
1656 struct msi_mask_group
1664 struct msi_maskedit_info
1672 struct msi_mask_group group
[MASK_MAX_GROUPS
];
1675 static BOOL
mask_editable( WCHAR type
)
1690 static void mask_control_change( struct msi_maskedit_info
*info
)
1695 val
= malloc( (info
->num_chars
+ 1) * sizeof(WCHAR
) );
1696 for( i
=0, n
=0; i
<info
->num_groups
; i
++ )
1698 if (info
->group
[i
].len
== ~0u)
1700 UINT len
= SendMessageW( info
->group
[i
].hwnd
, WM_GETTEXTLENGTH
, 0, 0 );
1701 val
= realloc( val
, (len
+ 1) * sizeof(WCHAR
) );
1702 GetWindowTextW( info
->group
[i
].hwnd
, val
, len
+ 1 );
1706 if (info
->group
[i
].len
+ n
> info
->num_chars
)
1708 ERR("can't fit control %d text into template\n",i
);
1711 if (!mask_editable(info
->group
[i
].type
))
1713 for(r
=0; r
<info
->group
[i
].len
; r
++)
1714 val
[n
+r
] = info
->group
[i
].type
;
1719 r
= GetWindowTextW( info
->group
[i
].hwnd
, &val
[n
], info
->group
[i
].len
+1 );
1720 if( r
!= info
->group
[i
].len
)
1727 TRACE("%d/%d controls were good\n", i
, info
->num_groups
);
1729 if( i
== info
->num_groups
)
1731 TRACE("Set property %s to %s\n", debugstr_w(info
->prop
), debugstr_w(val
));
1732 dialog_set_property( info
->dialog
->package
, info
->prop
, val
);
1733 dialog_evaluate_control_conditions( info
->dialog
);
1738 /* now move to the next control if necessary */
1739 static void mask_next_control( struct msi_maskedit_info
*info
, HWND hWnd
)
1744 for( i
=0; i
<info
->num_groups
; i
++ )
1745 if( info
->group
[i
].hwnd
== hWnd
)
1748 /* don't move from the last control */
1749 if( i
>= (info
->num_groups
-1) )
1752 len
= SendMessageW( hWnd
, WM_GETTEXTLENGTH
, 0, 0 );
1753 if( len
< info
->group
[i
].len
)
1756 hWndNext
= GetNextDlgTabItem( GetParent( hWnd
), hWnd
, FALSE
);
1757 SetFocus( hWndNext
);
1760 static LRESULT WINAPI
MSIMaskedEdit_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1762 struct msi_maskedit_info
*info
;
1765 TRACE("%p %04x %#Ix %#Ix\n", hWnd
, msg
, wParam
, lParam
);
1767 info
= GetPropW(hWnd
, L
"MSIDATA");
1769 r
= CallWindowProcW(info
->oldproc
, hWnd
, msg
, wParam
, lParam
);
1774 if (HIWORD(wParam
) == EN_CHANGE
)
1776 mask_control_change( info
);
1777 mask_next_control( info
, (HWND
) lParam
);
1783 RemovePropW( hWnd
, L
"MSIDATA" );
1790 /* fish the various bits of the property out and put them in the control */
1791 static void maskedit_set_text( struct msi_maskedit_info
*info
, const WCHAR
*text
)
1797 for( i
= 0; i
< info
->num_groups
; i
++ )
1799 if( info
->group
[i
].len
< lstrlenW( p
) )
1801 WCHAR
*chunk
= wcsdup( p
);
1802 chunk
[ info
->group
[i
].len
] = 0;
1803 SetWindowTextW( info
->group
[i
].hwnd
, chunk
);
1808 SetWindowTextW( info
->group
[i
].hwnd
, p
);
1811 p
+= info
->group
[i
].len
;
1815 static struct msi_maskedit_info
*dialog_parse_groups( const WCHAR
*mask
)
1817 struct msi_maskedit_info
*info
;
1818 int i
= 0, n
= 0, total
= 0;
1821 TRACE("masked control, template %s\n", debugstr_w(mask
));
1826 info
= calloc( 1, sizeof *info
);
1830 p
= wcschr(mask
, '<');
1836 for( i
=0; i
<MASK_MAX_GROUPS
; i
++ )
1838 /* stop at the end of the string */
1839 if( p
[0] == 0 || p
[0] == '>' )
1843 /* create a group for the empty mask */
1844 info
->group
[0].type
= '&';
1845 info
->group
[0].len
= ~0u;
1851 /* count the number of the same identifier */
1852 for( n
=0; p
[n
] == p
[0]; n
++ )
1854 info
->group
[i
].ofs
= total
;
1855 info
->group
[i
].type
= p
[0];
1859 total
++; /* an extra not part of the group */
1861 info
->group
[i
].len
= n
;
1866 TRACE("%d characters in %d groups\n", total
, i
);
1867 if( i
== MASK_MAX_GROUPS
)
1868 ERR("too many groups in PIDTemplate %s\n", debugstr_w(mask
));
1870 info
->num_chars
= total
;
1871 info
->num_groups
= i
;
1876 static void maskedit_create_children( struct msi_maskedit_info
*info
, const WCHAR
*font
)
1878 DWORD width
, height
, style
, wx
, ww
;
1883 style
= WS_CHILD
| WS_BORDER
| WS_VISIBLE
| WS_TABSTOP
| ES_AUTOHSCROLL
;
1885 GetClientRect( info
->hwnd
, &rect
);
1887 width
= rect
.right
- rect
.left
;
1888 height
= rect
.bottom
- rect
.top
;
1890 for( i
= 0; i
< info
->num_groups
; i
++ )
1892 if (!mask_editable( info
->group
[i
].type
))
1894 if (info
->num_chars
)
1896 wx
= (info
->group
[i
].ofs
* width
) / info
->num_chars
;
1897 ww
= (info
->group
[i
].len
* width
) / info
->num_chars
;
1904 hwnd
= CreateWindowW( L
"Edit", NULL
, style
, wx
, 0, ww
, height
,
1905 info
->hwnd
, NULL
, NULL
, NULL
);
1908 ERR("failed to create mask edit sub window\n");
1912 SendMessageW( hwnd
, EM_LIMITTEXT
, info
->group
[i
].len
, 0 );
1914 dialog_set_font( info
->dialog
, hwnd
, font
?font
:info
->dialog
->default_font
);
1915 info
->group
[i
].hwnd
= hwnd
;
1920 * office 2003 uses "73931<````=````=````=````=`````>@@@@@"
1921 * delphi 7 uses "<????-??????-??????-????>" and "<???-???>"
1922 * filemaker pro 7 uses "<^^^^=^^^^=^^^^=^^^^=^^^^=^^^^=^^^^^>"
1924 static UINT
dialog_maskedit_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1926 LPWSTR font_mask
, val
= NULL
, font
;
1927 struct msi_maskedit_info
*info
= NULL
;
1928 UINT ret
= ERROR_SUCCESS
;
1929 struct control
*control
;
1934 font_mask
= get_deformatted_field( dialog
->package
, rec
, 10 );
1935 font
= dialog_get_style( font_mask
, &mask
);
1938 WARN("mask template is empty\n");
1942 info
= dialog_parse_groups( mask
);
1945 ERR("template %s is invalid\n", debugstr_w(mask
));
1949 info
->dialog
= dialog
;
1951 control
= dialog_add_control( dialog
, rec
, L
"Static", SS_OWNERDRAW
| WS_GROUP
| WS_VISIBLE
);
1954 ERR("Failed to create maskedit container\n");
1955 ret
= ERROR_FUNCTION_FAILED
;
1958 SetWindowLongPtrW( control
->hwnd
, GWL_EXSTYLE
, WS_EX_CONTROLPARENT
);
1960 info
->hwnd
= control
->hwnd
;
1962 /* subclass the static control */
1963 info
->oldproc
= (WNDPROC
) SetWindowLongPtrW( info
->hwnd
, GWLP_WNDPROC
,
1964 (LONG_PTR
)MSIMaskedEdit_WndProc
);
1965 SetPropW( control
->hwnd
, L
"MSIDATA", info
);
1967 prop
= MSI_RecordGetString( rec
, 9 );
1969 info
->prop
= wcsdup( prop
);
1971 maskedit_create_children( info
, font
);
1975 val
= msi_dup_property( dialog
->package
->db
, prop
);
1978 maskedit_set_text( info
, val
);
1984 if( ret
!= ERROR_SUCCESS
)
1991 /******************** Progress Bar *****************************************/
1993 static UINT
dialog_progress_bar( msi_dialog
*dialog
, MSIRECORD
*rec
)
1995 struct control
*control
;
1996 DWORD attributes
, style
;
1999 attributes
= MSI_RecordGetInteger( rec
, 8 );
2000 if( !(attributes
& msidbControlAttributesProgress95
) )
2001 style
|= PBS_SMOOTH
;
2003 control
= dialog_add_control( dialog
, rec
, PROGRESS_CLASSW
, style
);
2005 return ERROR_FUNCTION_FAILED
;
2007 event_subscribe( dialog
, L
"SetProgress", control
->name
, L
"Progress" );
2008 return ERROR_SUCCESS
;
2011 /******************** Path Edit ********************************************/
2013 struct msi_pathedit_info
2016 struct control
*control
;
2020 static WCHAR
*get_path_property( msi_dialog
*dialog
, struct control
*control
)
2023 BOOL indirect
= control
->attributes
& msidbControlAttributesIndirect
;
2024 if (!(prop
= dialog_dup_property( dialog
, control
->property
, indirect
))) return NULL
;
2025 path
= dialog_dup_property( dialog
, prop
, TRUE
);
2030 static void dialog_update_pathedit( msi_dialog
*dialog
, struct control
*control
)
2034 if (!control
&& !(control
= dialog_find_control_by_type( dialog
, L
"PathEdit" )))
2037 if (!(path
= get_path_property( dialog
, control
))) return;
2038 SetWindowTextW( control
->hwnd
, path
);
2039 SendMessageW( control
->hwnd
, EM_SETSEL
, 0, -1 );
2043 /* FIXME: test when this should fail */
2044 static BOOL
dialog_verify_path( const WCHAR
*path
)
2049 if ( PathIsRelativeW( path
) )
2055 /* returns TRUE if the path is valid, FALSE otherwise */
2056 static BOOL
dialog_onkillfocus( msi_dialog
*dialog
, struct control
*control
)
2062 indirect
= control
->attributes
& msidbControlAttributesIndirect
;
2063 prop
= dialog_dup_property( dialog
, control
->property
, indirect
);
2065 buf
= get_window_text( control
->hwnd
);
2067 if ( !dialog_verify_path( buf
) )
2069 /* FIXME: display an error message box */
2070 ERR("Invalid path %s\n", debugstr_w( buf
));
2072 SetFocus( control
->hwnd
);
2077 dialog_set_property( dialog
->package
, prop
, buf
);
2080 dialog_update_pathedit( dialog
, control
);
2082 TRACE("edit %s contents changed, set %s\n", debugstr_w(control
->name
),
2091 static LRESULT WINAPI
MSIPathEdit_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
2093 struct msi_pathedit_info
*info
= GetPropW(hWnd
, L
"MSIDATA");
2096 TRACE("%p %04x %#Ix %#Ix\n", hWnd
, msg
, wParam
, lParam
);
2098 if ( msg
== WM_KILLFOCUS
)
2100 /* if the path is invalid, don't handle this message */
2101 if ( !dialog_onkillfocus( info
->dialog
, info
->control
) )
2105 r
= CallWindowProcW(info
->oldproc
, hWnd
, msg
, wParam
, lParam
);
2107 if ( msg
== WM_NCDESTROY
)
2110 RemovePropW( hWnd
, L
"MSIDATA" );
2116 static UINT
dialog_pathedit_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
2118 struct msi_pathedit_info
*info
;
2119 struct control
*control
;
2122 info
= malloc( sizeof *info
);
2124 return ERROR_FUNCTION_FAILED
;
2126 control
= dialog_add_control( dialog
, rec
, L
"Edit", WS_BORDER
| WS_TABSTOP
);
2127 control
->attributes
= MSI_RecordGetInteger( rec
, 8 );
2128 prop
= MSI_RecordGetString( rec
, 9 );
2129 control
->property
= dialog_dup_property( dialog
, prop
, FALSE
);
2130 control
->update
= dialog_update_pathedit
;
2132 info
->dialog
= dialog
;
2133 info
->control
= control
;
2134 info
->oldproc
= (WNDPROC
) SetWindowLongPtrW( control
->hwnd
, GWLP_WNDPROC
,
2135 (LONG_PTR
)MSIPathEdit_WndProc
);
2136 SetPropW( control
->hwnd
, L
"MSIDATA", info
);
2138 dialog_update_pathedit( dialog
, control
);
2140 return ERROR_SUCCESS
;
2143 static UINT
dialog_radiogroup_handler( msi_dialog
*dialog
, struct control
*control
, WPARAM param
)
2145 if (HIWORD(param
) != BN_CLICKED
)
2146 return ERROR_SUCCESS
;
2148 TRACE("clicked radio button %s, set %s\n", debugstr_w(control
->name
), debugstr_w(control
->property
));
2150 dialog_set_property( dialog
->package
, control
->property
, control
->name
);
2152 return dialog_button_handler( dialog
, control
, param
);
2155 /* radio buttons are a bit different from normal controls */
2156 static UINT
dialog_create_radiobutton( MSIRECORD
*rec
, void *param
)
2158 struct radio_button_group_descr
*group
= param
;
2159 msi_dialog
*dialog
= group
->dialog
;
2160 struct control
*control
;
2161 LPCWSTR prop
, text
, name
;
2162 DWORD style
= WS_CHILD
| WS_VISIBLE
| WS_TABSTOP
| BS_AUTORADIOBUTTON
| BS_MULTILINE
;
2164 name
= MSI_RecordGetString( rec
, 3 );
2165 text
= MSI_RecordGetString( rec
, 8 );
2167 control
= dialog_create_window( dialog
, rec
, 0, L
"BUTTON", name
, text
, style
,
2168 group
->parent
->hwnd
);
2170 return ERROR_FUNCTION_FAILED
;
2171 control
->handler
= dialog_radiogroup_handler
;
2173 if (group
->propval
&& !wcscmp( control
->name
, group
->propval
))
2174 SendMessageW(control
->hwnd
, BM_SETCHECK
, BST_CHECKED
, 0);
2176 prop
= MSI_RecordGetString( rec
, 1 );
2178 control
->property
= wcsdup( prop
);
2180 return ERROR_SUCCESS
;
2183 static BOOL CALLBACK
radioground_child_enum( HWND hWnd
, LPARAM lParam
)
2185 EnableWindow( hWnd
, lParam
);
2189 static LRESULT WINAPI
MSIRadioGroup_WndProc( HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
2191 WNDPROC oldproc
= (WNDPROC
)GetPropW( hWnd
, L
"MSIDATA" );
2194 TRACE( "hWnd %p msg %04x wParam %#Ix lParam %#Ix\n", hWnd
, msg
, wParam
, lParam
);
2196 if (msg
== WM_COMMAND
) /* Forward notifications to dialog */
2197 SendMessageW( GetParent( hWnd
), msg
, wParam
, lParam
);
2199 r
= CallWindowProcW( oldproc
, hWnd
, msg
, wParam
, lParam
);
2201 /* make sure the radio buttons show as disabled if the parent is disabled */
2202 if (msg
== WM_ENABLE
)
2203 EnumChildWindows( hWnd
, radioground_child_enum
, wParam
);
2208 static UINT
dialog_radiogroup_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
2212 struct control
*control
;
2214 struct radio_button_group_descr group
;
2215 MSIPACKAGE
*package
= dialog
->package
;
2217 DWORD attr
, style
= WS_GROUP
;
2219 prop
= MSI_RecordGetString( rec
, 9 );
2221 TRACE("%p %p %s\n", dialog
, rec
, debugstr_w( prop
));
2223 attr
= MSI_RecordGetInteger( rec
, 8 );
2224 if (attr
& msidbControlAttributesVisible
)
2225 style
|= WS_VISIBLE
;
2226 if (~attr
& msidbControlAttributesEnabled
)
2227 style
|= WS_DISABLED
;
2228 if (attr
& msidbControlAttributesHasBorder
)
2229 style
|= BS_GROUPBOX
;
2231 style
|= BS_OWNERDRAW
;
2233 /* Create parent group box to hold radio buttons */
2234 control
= dialog_add_control( dialog
, rec
, L
"BUTTON", style
);
2236 return ERROR_FUNCTION_FAILED
;
2238 oldproc
= (WNDPROC
) SetWindowLongPtrW( control
->hwnd
, GWLP_WNDPROC
,
2239 (LONG_PTR
)MSIRadioGroup_WndProc
);
2240 SetPropW(control
->hwnd
, L
"MSIDATA", oldproc
);
2241 SetWindowLongPtrW( control
->hwnd
, GWL_EXSTYLE
, WS_EX_CONTROLPARENT
);
2244 control
->property
= wcsdup( prop
);
2246 /* query the Radio Button table for all control in this group */
2247 r
= MSI_OpenQuery( package
->db
, &view
, L
"SELECT * FROM `RadioButton` WHERE `Property` = '%s'", prop
);
2248 if( r
!= ERROR_SUCCESS
)
2250 ERR("query failed for dialog %s radio group %s\n",
2251 debugstr_w(dialog
->name
), debugstr_w(prop
));
2252 return ERROR_INVALID_PARAMETER
;
2255 group
.dialog
= dialog
;
2256 group
.parent
= control
;
2257 group
.propval
= msi_dup_property( dialog
->package
->db
, control
->property
);
2259 r
= MSI_IterateRecords( view
, 0, dialog_create_radiobutton
, &group
);
2260 msiobj_release( &view
->hdr
);
2261 free( group
.propval
);
2265 static void seltree_sync_item_state( HWND hwnd
, MSIFEATURE
*feature
, HTREEITEM hItem
)
2268 DWORD index
= feature
->ActionRequest
;
2270 TRACE("Feature %s -> %d %d %d\n", debugstr_w(feature
->Title
),
2271 feature
->Installed
, feature
->Action
, feature
->ActionRequest
);
2273 if (index
== INSTALLSTATE_UNKNOWN
)
2274 index
= INSTALLSTATE_ABSENT
;
2276 tvi
.mask
= TVIF_STATE
;
2278 tvi
.state
= INDEXTOSTATEIMAGEMASK( index
);
2279 tvi
.stateMask
= TVIS_STATEIMAGEMASK
;
2281 SendMessageW( hwnd
, TVM_SETITEMW
, 0, (LPARAM
) &tvi
);
2284 static UINT
seltree_popup_menu( HWND hwnd
, INT x
, INT y
)
2289 /* create a menu to display */
2290 hMenu
= CreatePopupMenu();
2292 /* FIXME: load strings from resources */
2293 AppendMenuA( hMenu
, MF_ENABLED
, INSTALLSTATE_LOCAL
, "Install feature locally");
2294 AppendMenuA( hMenu
, MF_ENABLED
, USER_INSTALLSTATE_ALL
, "Install entire feature");
2295 AppendMenuA( hMenu
, MF_ENABLED
, INSTALLSTATE_ADVERTISED
, "Install on demand");
2296 AppendMenuA( hMenu
, MF_ENABLED
, INSTALLSTATE_ABSENT
, "Don't install");
2297 r
= TrackPopupMenu( hMenu
, TPM_LEFTALIGN
| TPM_TOPALIGN
| TPM_RETURNCMD
,
2298 x
, y
, 0, hwnd
, NULL
);
2299 DestroyMenu( hMenu
);
2303 static void seltree_update_feature_installstate( HWND hwnd
, HTREEITEM hItem
, MSIPACKAGE
*package
,
2304 MSIFEATURE
*feature
, INSTALLSTATE state
)
2306 feature
->ActionRequest
= state
;
2307 seltree_sync_item_state( hwnd
, feature
, hItem
);
2308 ACTION_UpdateComponentStates( package
, feature
);
2311 static void seltree_update_siblings_and_children_installstate( HWND hwnd
, HTREEITEM curr
, MSIPACKAGE
*package
,
2312 INSTALLSTATE state
)
2314 /* update all siblings */
2317 MSIFEATURE
*feature
;
2320 feature
= seltree_feature_from_item( hwnd
, curr
);
2321 seltree_update_feature_installstate( hwnd
, curr
, package
, feature
, state
);
2323 /* update this sibling's children */
2324 child
= (HTREEITEM
)SendMessageW( hwnd
, TVM_GETNEXTITEM
, (WPARAM
)TVGN_CHILD
, (LPARAM
)curr
);
2326 seltree_update_siblings_and_children_installstate( hwnd
, child
, package
, state
);
2328 while ((curr
= (HTREEITEM
)SendMessageW( hwnd
, TVM_GETNEXTITEM
, (WPARAM
)TVGN_NEXT
, (LPARAM
)curr
)));
2331 static LRESULT
seltree_menu( HWND hwnd
, HTREEITEM hItem
)
2333 struct msi_selection_tree_info
*info
;
2334 MSIFEATURE
*feature
;
2335 MSIPACKAGE
*package
;
2343 info
= GetPropW(hwnd
, L
"MSIDATA");
2344 package
= info
->dialog
->package
;
2346 feature
= seltree_feature_from_item( hwnd
, hItem
);
2349 ERR("item %p feature was NULL\n", hItem
);
2353 /* get the item's rectangle to put the menu just below it */
2355 SendMessageW( hwnd
, TVM_GETITEMRECT
, 0, (LPARAM
) &u
.rc
);
2356 MapWindowPoints( hwnd
, NULL
, u
.pt
, 2 );
2358 r
= seltree_popup_menu( hwnd
, u
.rc
.left
, u
.rc
.top
);
2362 case USER_INSTALLSTATE_ALL
:
2363 r
= INSTALLSTATE_LOCAL
;
2365 case INSTALLSTATE_ADVERTISED
:
2366 case INSTALLSTATE_ABSENT
:
2369 child
= (HTREEITEM
)SendMessageW( hwnd
, TVM_GETNEXTITEM
, (WPARAM
)TVGN_CHILD
, (LPARAM
)hItem
);
2371 seltree_update_siblings_and_children_installstate( hwnd
, child
, package
, r
);
2374 case INSTALLSTATE_LOCAL
:
2375 seltree_update_feature_installstate( hwnd
, hItem
, package
, feature
, r
);
2382 static LRESULT WINAPI
MSISelectionTree_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
2384 struct msi_selection_tree_info
*info
;
2385 TVHITTESTINFO tvhti
;
2388 TRACE("%p %04x %#Ix %#Ix\n", hWnd
, msg
, wParam
, lParam
);
2390 info
= GetPropW(hWnd
, L
"MSIDATA");
2394 case WM_LBUTTONDOWN
:
2395 tvhti
.pt
.x
= (short)LOWORD( lParam
);
2396 tvhti
.pt
.y
= (short)HIWORD( lParam
);
2399 CallWindowProcW(info
->oldproc
, hWnd
, TVM_HITTEST
, 0, (LPARAM
) &tvhti
);
2400 if (tvhti
.flags
& TVHT_ONITEMSTATEICON
)
2401 return seltree_menu( hWnd
, tvhti
.hItem
);
2404 r
= CallWindowProcW(info
->oldproc
, hWnd
, msg
, wParam
, lParam
);
2410 RemovePropW( hWnd
, L
"MSIDATA" );
2416 static void seltree_add_child_features( MSIPACKAGE
*package
, HWND hwnd
, const WCHAR
*parent
, HTREEITEM hParent
)
2418 struct msi_selection_tree_info
*info
= GetPropW( hwnd
, L
"MSIDATA" );
2419 MSIFEATURE
*feature
;
2420 TVINSERTSTRUCTW tvis
;
2421 HTREEITEM hitem
, hfirst
= NULL
;
2423 LIST_FOR_EACH_ENTRY( feature
, &package
->features
, MSIFEATURE
, entry
)
2425 if ( parent
&& feature
->Feature_Parent
&& wcscmp( parent
, feature
->Feature_Parent
))
2427 else if ( parent
&& !feature
->Feature_Parent
)
2429 else if ( !parent
&& feature
->Feature_Parent
)
2432 if ( !feature
->Title
)
2435 if ( !feature
->Display
)
2438 memset( &tvis
, 0, sizeof tvis
);
2439 tvis
.hParent
= hParent
;
2440 tvis
.hInsertAfter
= TVI_LAST
;
2441 tvis
.item
.mask
= TVIF_TEXT
| TVIF_PARAM
;
2442 tvis
.item
.pszText
= feature
->Title
;
2443 tvis
.item
.lParam
= (LPARAM
) feature
;
2445 hitem
= (HTREEITEM
) SendMessageW( hwnd
, TVM_INSERTITEMW
, 0, (LPARAM
) &tvis
);
2452 seltree_sync_item_state( hwnd
, feature
, hitem
);
2453 seltree_add_child_features( package
, hwnd
,
2454 feature
->Feature
, hitem
);
2456 /* the node is expanded if Display is odd */
2457 if ( feature
->Display
% 2 != 0 )
2458 SendMessageW( hwnd
, TVM_EXPAND
, TVE_EXPAND
, (LPARAM
) hitem
);
2461 /* select the first item */
2462 SendMessageW( hwnd
, TVM_SELECTITEM
, TVGN_CARET
| TVGN_DROPHILITE
, (LPARAM
) hfirst
);
2463 info
->selected
= hfirst
;
2466 static void seltree_create_imagelist( HWND hwnd
)
2468 const int bm_width
= 32, bm_height
= 16, bm_count
= 3;
2469 const int bm_resource
= 0x1001;
2474 himl
= ImageList_Create( bm_width
, bm_height
, FALSE
, 4, 0 );
2477 ERR("failed to create image list\n");
2481 for (i
=0; i
<bm_count
; i
++)
2483 hbmp
= LoadBitmapW( msi_hInstance
, MAKEINTRESOURCEW(i
+bm_resource
) );
2486 ERR("failed to load bitmap %d\n", i
);
2491 * Add a dummy bitmap at offset zero because the treeview
2492 * can't use it as a state mask (zero means no user state).
2495 ImageList_Add( himl
, hbmp
, NULL
);
2497 ImageList_Add( himl
, hbmp
, NULL
);
2500 SendMessageW( hwnd
, TVM_SETIMAGELIST
, TVSIL_STATE
, (LPARAM
)himl
);
2503 static UINT
dialog_seltree_handler( msi_dialog
*dialog
, struct control
*control
, WPARAM param
)
2505 struct msi_selection_tree_info
*info
= GetPropW( control
->hwnd
, L
"MSIDATA" );
2506 LPNMTREEVIEWW tv
= (LPNMTREEVIEWW
)param
;
2507 MSIRECORD
*row
, *rec
;
2509 MSIFEATURE
*feature
;
2510 LPCWSTR dir
, title
= NULL
;
2511 UINT r
= ERROR_SUCCESS
;
2513 if (tv
->hdr
.code
!= TVN_SELCHANGINGW
)
2514 return ERROR_SUCCESS
;
2516 info
->selected
= tv
->itemNew
.hItem
;
2518 if (!(tv
->itemNew
.mask
& TVIF_TEXT
))
2520 feature
= seltree_feature_from_item( control
->hwnd
, tv
->itemNew
.hItem
);
2522 title
= feature
->Title
;
2525 title
= tv
->itemNew
.pszText
;
2527 row
= MSI_QueryGetRecord( dialog
->package
->db
, L
"SELECT * FROM `Feature` WHERE `Title` = '%s'", title
);
2529 return ERROR_FUNCTION_FAILED
;
2531 rec
= MSI_CreateRecord( 1 );
2533 MSI_RecordSetStringW( rec
, 1, MSI_RecordGetString( row
, 4 ) );
2534 msi_event_fire( dialog
->package
, L
"SelectionDescription", rec
);
2536 dir
= MSI_RecordGetString( row
, 7 );
2539 folder
= msi_get_loaded_folder( dialog
->package
, dir
);
2542 r
= ERROR_FUNCTION_FAILED
;
2545 MSI_RecordSetStringW( rec
, 1, folder
->ResolvedTarget
);
2548 MSI_RecordSetStringW( rec
, 1, NULL
);
2550 msi_event_fire( dialog
->package
, L
"SelectionPath", rec
);
2553 msiobj_release(&row
->hdr
);
2554 msiobj_release(&rec
->hdr
);
2559 static UINT
dialog_selection_tree( msi_dialog
*dialog
, MSIRECORD
*rec
)
2561 struct control
*control
;
2562 LPCWSTR prop
, control_name
;
2563 MSIPACKAGE
*package
= dialog
->package
;
2565 struct msi_selection_tree_info
*info
;
2567 info
= malloc( sizeof *info
);
2569 return ERROR_FUNCTION_FAILED
;
2571 /* create the treeview control */
2572 style
= TVS_HASLINES
| TVS_HASBUTTONS
| TVS_LINESATROOT
;
2573 style
|= WS_GROUP
| WS_VSCROLL
| WS_TABSTOP
;
2574 control
= dialog_add_control( dialog
, rec
, WC_TREEVIEWW
, style
);
2578 return ERROR_FUNCTION_FAILED
;
2581 control
->handler
= dialog_seltree_handler
;
2582 control_name
= MSI_RecordGetString( rec
, 2 );
2583 control
->attributes
= MSI_RecordGetInteger( rec
, 8 );
2584 prop
= MSI_RecordGetString( rec
, 9 );
2585 control
->property
= dialog_dup_property( dialog
, prop
, FALSE
);
2588 info
->dialog
= dialog
;
2589 info
->hwnd
= control
->hwnd
;
2590 info
->oldproc
= (WNDPROC
) SetWindowLongPtrW( control
->hwnd
, GWLP_WNDPROC
,
2591 (LONG_PTR
)MSISelectionTree_WndProc
);
2592 SetPropW( control
->hwnd
, L
"MSIDATA", info
);
2594 event_subscribe( dialog
, L
"SelectionPath", control_name
, L
"Property" );
2597 seltree_create_imagelist( control
->hwnd
);
2598 seltree_add_child_features( package
, control
->hwnd
, NULL
, NULL
);
2600 return ERROR_SUCCESS
;
2603 /******************** Group Box ***************************************/
2605 static UINT
dialog_group_box( msi_dialog
*dialog
, MSIRECORD
*rec
)
2607 struct control
*control
;
2610 style
= BS_GROUPBOX
| WS_CHILD
| WS_GROUP
;
2611 control
= dialog_add_control( dialog
, rec
, WC_BUTTONW
, style
);
2613 return ERROR_FUNCTION_FAILED
;
2615 return ERROR_SUCCESS
;
2618 /******************** List Box ***************************************/
2620 struct msi_listbox_info
2630 static LRESULT WINAPI
MSIListBox_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
2632 struct msi_listbox_info
*info
;
2636 TRACE("%p %04x %#Ix %#Ix\n", hWnd
, msg
, wParam
, lParam
);
2638 info
= GetPropW( hWnd
, L
"MSIDATA" );
2642 r
= CallWindowProcW( info
->oldproc
, hWnd
, msg
, wParam
, lParam
);
2647 for (j
= 0; j
< info
->num_items
; j
++)
2648 free( info
->items
[j
] );
2649 free( info
->items
);
2651 RemovePropW( hWnd
, L
"MSIDATA" );
2658 static UINT
listbox_add_item( MSIRECORD
*rec
, void *param
)
2660 struct msi_listbox_info
*info
= param
;
2661 LPCWSTR value
, text
;
2664 value
= MSI_RecordGetString( rec
, 3 );
2665 text
= MSI_RecordGetString( rec
, 4 );
2667 info
->items
[info
->addpos_items
] = wcsdup( value
);
2669 pos
= SendMessageW( info
->hwnd
, LB_ADDSTRING
, 0, (LPARAM
)text
);
2670 SendMessageW( info
->hwnd
, LB_SETITEMDATA
, pos
, (LPARAM
)info
->items
[info
->addpos_items
] );
2671 info
->addpos_items
++;
2672 return ERROR_SUCCESS
;
2675 static UINT
listbox_add_items( struct msi_listbox_info
*info
, const WCHAR
*property
)
2681 r
= MSI_OpenQuery( info
->dialog
->package
->db
, &view
,
2682 L
"SELECT * FROM `ListBox` WHERE `Property` = '%s' ORDER BY `Order`", property
);
2683 if ( r
!= ERROR_SUCCESS
)
2686 /* just get the number of records */
2688 r
= MSI_IterateRecords( view
, &count
, NULL
, NULL
);
2689 if (r
!= ERROR_SUCCESS
)
2691 msiobj_release( &view
->hdr
);
2694 info
->num_items
= count
;
2695 info
->items
= malloc( sizeof(*info
->items
) * count
);
2697 r
= MSI_IterateRecords( view
, NULL
, listbox_add_item
, info
);
2698 msiobj_release( &view
->hdr
);
2702 static UINT
dialog_listbox_handler( msi_dialog
*dialog
, struct control
*control
, WPARAM param
)
2704 struct msi_listbox_info
*info
;
2708 if( HIWORD(param
) != LBN_SELCHANGE
)
2709 return ERROR_SUCCESS
;
2711 info
= GetPropW( control
->hwnd
, L
"MSIDATA" );
2712 index
= SendMessageW( control
->hwnd
, LB_GETCURSEL
, 0, 0 );
2713 value
= (LPCWSTR
) SendMessageW( control
->hwnd
, LB_GETITEMDATA
, index
, 0 );
2715 dialog_set_property( info
->dialog
->package
, control
->property
, value
);
2716 dialog_evaluate_control_conditions( info
->dialog
);
2718 return ERROR_SUCCESS
;
2721 static UINT
dialog_list_box( msi_dialog
*dialog
, MSIRECORD
*rec
)
2723 struct msi_listbox_info
*info
;
2724 struct control
*control
;
2725 DWORD attributes
, style
;
2728 info
= malloc( sizeof *info
);
2730 return ERROR_FUNCTION_FAILED
;
2732 style
= WS_TABSTOP
| WS_GROUP
| WS_CHILD
| LBS_NOTIFY
| WS_VSCROLL
| WS_BORDER
;
2733 attributes
= MSI_RecordGetInteger( rec
, 8 );
2734 if (~attributes
& msidbControlAttributesSorted
)
2737 control
= dialog_add_control( dialog
, rec
, WC_LISTBOXW
, style
);
2741 return ERROR_FUNCTION_FAILED
;
2744 control
->handler
= dialog_listbox_handler
;
2746 prop
= MSI_RecordGetString( rec
, 9 );
2747 control
->property
= dialog_dup_property( dialog
, prop
, FALSE
);
2750 info
->dialog
= dialog
;
2751 info
->hwnd
= control
->hwnd
;
2753 info
->addpos_items
= 0;
2754 info
->oldproc
= (WNDPROC
)SetWindowLongPtrW( control
->hwnd
, GWLP_WNDPROC
,
2755 (LONG_PTR
)MSIListBox_WndProc
);
2756 SetPropW( control
->hwnd
, L
"MSIDATA", info
);
2758 if ( control
->property
)
2759 listbox_add_items( info
, control
->property
);
2761 return ERROR_SUCCESS
;
2764 /******************** Directory Combo ***************************************/
2766 static void dialog_update_directory_combo( msi_dialog
*dialog
, struct control
*control
)
2770 if (!control
&& !(control
= dialog_find_control_by_type( dialog
, L
"DirectoryCombo" )))
2773 if (!(path
= get_path_property( dialog
, control
))) return;
2774 PathStripPathW( path
);
2775 PathRemoveBackslashW( path
);
2777 SendMessageW( control
->hwnd
, CB_INSERTSTRING
, 0, (LPARAM
)path
);
2778 SendMessageW( control
->hwnd
, CB_SETCURSEL
, 0, 0 );
2783 static UINT
dialog_directory_combo( msi_dialog
*dialog
, MSIRECORD
*rec
)
2785 struct control
*control
;
2789 /* FIXME: use CBS_OWNERDRAWFIXED and add owner draw code */
2790 style
= CBS_DROPDOWNLIST
| CBS_HASSTRINGS
| WS_CHILD
|
2791 WS_GROUP
| WS_TABSTOP
| WS_VSCROLL
;
2792 control
= dialog_add_control( dialog
, rec
, WC_COMBOBOXW
, style
);
2794 return ERROR_FUNCTION_FAILED
;
2796 control
->attributes
= MSI_RecordGetInteger( rec
, 8 );
2797 prop
= MSI_RecordGetString( rec
, 9 );
2798 control
->property
= dialog_dup_property( dialog
, prop
, FALSE
);
2800 dialog_update_directory_combo( dialog
, control
);
2802 return ERROR_SUCCESS
;
2805 /******************** Directory List ***************************************/
2807 static void dialog_update_directory_list( msi_dialog
*dialog
, struct control
*control
)
2809 WCHAR dir_spec
[MAX_PATH
], *path
;
2810 WIN32_FIND_DATAW wfd
;
2814 if (!control
&& !(control
= dialog_find_control_by_type( dialog
, L
"DirectoryList" )))
2817 /* clear the list-view */
2818 SendMessageW( control
->hwnd
, LVM_DELETEALLITEMS
, 0, 0 );
2820 if (!(path
= get_path_property( dialog
, control
))) return;
2821 lstrcpyW( dir_spec
, path
);
2822 lstrcatW( dir_spec
, L
"*" );
2824 file
= FindFirstFileW( dir_spec
, &wfd
);
2825 if (file
== INVALID_HANDLE_VALUE
)
2833 if ( wfd
.dwFileAttributes
!= FILE_ATTRIBUTE_DIRECTORY
)
2836 if ( !wcscmp( wfd
.cFileName
, L
"." ) || !wcscmp( wfd
.cFileName
, L
".." ) )
2839 item
.mask
= LVIF_TEXT
;
2840 item
.cchTextMax
= MAX_PATH
;
2843 item
.pszText
= wfd
.cFileName
;
2845 SendMessageW( control
->hwnd
, LVM_INSERTITEMW
, 0, (LPARAM
)&item
);
2846 } while ( FindNextFileW( file
, &wfd
) );
2852 static UINT
dialog_directorylist_up( msi_dialog
*dialog
)
2854 struct control
*control
;
2855 LPWSTR prop
, path
, ptr
;
2858 control
= dialog_find_control_by_type( dialog
, L
"DirectoryList" );
2859 indirect
= control
->attributes
& msidbControlAttributesIndirect
;
2860 prop
= dialog_dup_property( dialog
, control
->property
, indirect
);
2861 path
= dialog_dup_property( dialog
, prop
, TRUE
);
2863 /* strip off the last directory */
2864 ptr
= PathFindFileNameW( path
);
2865 if (ptr
!= path
) *(ptr
- 1) = '\0';
2866 PathAddBackslashW( path
);
2868 dialog_set_property( dialog
->package
, prop
, path
);
2870 dialog_update_directory_list( dialog
, NULL
);
2871 dialog_update_directory_combo( dialog
, NULL
);
2872 dialog_update_pathedit( dialog
, NULL
);
2877 return ERROR_SUCCESS
;
2880 static WCHAR
*get_unique_folder_name( const WCHAR
*root
, int *ret_len
)
2882 WCHAR newfolder
[MAX_PATH
], *path
, *ptr
;
2885 len
= LoadStringW( msi_hInstance
, IDS_NEWFOLDER
, newfolder
, ARRAY_SIZE(newfolder
) );
2886 len
+= lstrlenW(root
) + 1;
2887 if (!(path
= malloc( (len
+ 4) * sizeof(WCHAR
) ))) return NULL
;
2888 lstrcpyW( path
, root
);
2889 lstrcatW( path
, newfolder
);
2893 if (GetFileAttributesW( path
) == INVALID_FILE_ATTRIBUTES
) break;
2899 swprintf( path
, len
+ 4, L
"%s%s %u", root
, newfolder
, count
++ );
2902 ptr
= wcsrchr( path
, '\\' ) + 1;
2903 *ret_len
= lstrlenW(ptr
);
2904 memmove( path
, ptr
, *ret_len
* sizeof(WCHAR
) );
2908 static UINT
dialog_directorylist_new( msi_dialog
*dialog
)
2910 struct control
*control
;
2915 control
= dialog_find_control_by_type( dialog
, L
"DirectoryList" );
2917 if (!(path
= get_path_property( dialog
, control
))) return ERROR_OUTOFMEMORY
;
2919 item
.mask
= LVIF_TEXT
;
2922 item
.pszText
= get_unique_folder_name( path
, &item
.cchTextMax
);
2924 index
= SendMessageW( control
->hwnd
, LVM_INSERTITEMW
, 0, (LPARAM
)&item
);
2925 SendMessageW( control
->hwnd
, LVM_ENSUREVISIBLE
, index
, 0 );
2926 SendMessageW( control
->hwnd
, LVM_EDITLABELW
, index
, -1 );
2929 free( item
.pszText
);
2930 return ERROR_SUCCESS
;
2933 static UINT
dialog_dirlist_handler( msi_dialog
*dialog
, struct control
*control
, WPARAM param
)
2935 NMHDR
*nmhdr
= (NMHDR
*)param
;
2936 WCHAR text
[MAX_PATH
], *new_path
, *path
, *prop
;
2939 switch (nmhdr
->code
)
2941 case LVN_ENDLABELEDITW
:
2943 NMLVDISPINFOW
*info
= (NMLVDISPINFOW
*)param
;
2944 if (!info
->item
.pszText
) return ERROR_SUCCESS
;
2945 lstrcpynW( text
, info
->item
.pszText
, ARRAY_SIZE(text
) );
2946 text
[ARRAY_SIZE(text
) - 1] = 0;
2949 case LVN_ITEMACTIVATE
:
2952 int index
= SendMessageW( control
->hwnd
, LVM_GETNEXTITEM
, -1, LVNI_SELECTED
);
2955 ERR("no list-view item selected\n");
2956 return ERROR_FUNCTION_FAILED
;
2960 item
.pszText
= text
;
2961 item
.cchTextMax
= MAX_PATH
;
2962 SendMessageW( control
->hwnd
, LVM_GETITEMTEXTW
, index
, (LPARAM
)&item
);
2963 text
[ARRAY_SIZE(text
) - 1] = 0;
2967 return ERROR_SUCCESS
;
2970 indirect
= control
->attributes
& msidbControlAttributesIndirect
;
2971 prop
= dialog_dup_property( dialog
, control
->property
, indirect
);
2972 path
= dialog_dup_property( dialog
, prop
, TRUE
);
2974 if (!(new_path
= malloc( (wcslen(path
) + wcslen(text
) + 2) * sizeof(WCHAR
) )))
2978 return ERROR_OUTOFMEMORY
;
2980 lstrcpyW( new_path
, path
);
2981 lstrcatW( new_path
, text
);
2982 if (nmhdr
->code
== LVN_ENDLABELEDITW
) CreateDirectoryW( new_path
, NULL
);
2983 lstrcatW( new_path
, L
"\\" );
2985 dialog_set_property( dialog
->package
, prop
, new_path
);
2987 dialog_update_directory_list( dialog
, NULL
);
2988 dialog_update_directory_combo( dialog
, NULL
);
2989 dialog_update_pathedit( dialog
, NULL
);
2995 return ERROR_SUCCESS
;
2998 static UINT
dialog_directory_list( msi_dialog
*dialog
, MSIRECORD
*rec
)
3000 struct control
*control
;
3004 style
= LVS_LIST
| WS_VSCROLL
| LVS_SHAREIMAGELISTS
| LVS_EDITLABELS
|
3005 LVS_AUTOARRANGE
| LVS_SINGLESEL
| WS_BORDER
|
3006 LVS_SORTASCENDING
| WS_CHILD
| WS_GROUP
| WS_TABSTOP
;
3007 control
= dialog_add_control( dialog
, rec
, WC_LISTVIEWW
, style
);
3009 return ERROR_FUNCTION_FAILED
;
3011 control
->attributes
= MSI_RecordGetInteger( rec
, 8 );
3012 control
->handler
= dialog_dirlist_handler
;
3013 prop
= MSI_RecordGetString( rec
, 9 );
3014 control
->property
= dialog_dup_property( dialog
, prop
, FALSE
);
3016 /* double click to activate an item in the list */
3017 SendMessageW( control
->hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
,
3018 0, LVS_EX_TWOCLICKACTIVATE
);
3020 dialog_update_directory_list( dialog
, control
);
3022 return ERROR_SUCCESS
;
3025 /******************** VolumeCost List ***************************************/
3027 static BOOL
str_is_number( LPCWSTR str
)
3031 for (i
= 0; i
< lstrlenW( str
); i
++)
3032 if (!iswdigit(str
[i
]))
3038 static const WCHAR column_keys
[][80] =
3040 L
"VolumeCostVolume",
3042 L
"VolumeCostAvailable",
3043 L
"VolumeCostRequired",
3044 L
"VolumeCostDifference",
3047 static void dialog_vcl_add_columns( msi_dialog
*dialog
, struct control
*control
, MSIRECORD
*rec
)
3049 LPCWSTR text
= MSI_RecordGetString( rec
, 10 );
3050 LPCWSTR begin
= text
, end
;
3057 while ((begin
= wcschr( begin
, '{' )) && count
< 5)
3059 if (!(end
= wcschr( begin
, '}' )))
3062 num
= malloc( (end
- begin
+ 1) * sizeof(WCHAR
) );
3066 lstrcpynW( num
, begin
+ 1, end
- begin
);
3067 begin
+= end
- begin
+ 1;
3069 /* empty braces or '0' hides the column */
3070 if ( !num
[0] || !wcscmp( num
, L
"0" ) )
3077 /* the width must be a positive number
3078 * if a width is invalid, all remaining columns are hidden
3080 if ( !wcsncmp( num
, L
"-", 1 ) || !str_is_number( num
) ) {
3085 ZeroMemory( &lvc
, sizeof(lvc
) );
3086 lvc
.mask
= LVCF_TEXT
| LVCF_WIDTH
| LVCF_SUBITEM
;
3087 lvc
.cx
= wcstol( num
, NULL
, 10 );
3088 lvc
.pszText
= dialog_get_uitext( dialog
, column_keys
[count
] );
3090 SendMessageW( control
->hwnd
, LVM_INSERTCOLUMNW
, count
++, (LPARAM
)&lvc
);
3091 free( lvc
.pszText
);
3096 static LONGLONG
vcl_get_cost( msi_dialog
*dialog
)
3098 MSIFEATURE
*feature
;
3100 LONGLONG total_cost
= 0;
3102 LIST_FOR_EACH_ENTRY( feature
, &dialog
->package
->features
, MSIFEATURE
, entry
)
3104 if (ERROR_SUCCESS
== (MSI_GetFeatureCost(dialog
->package
, feature
,
3105 MSICOSTTREE_SELFONLY
, INSTALLSTATE_LOCAL
, &each_cost
)))
3107 /* each_cost is in 512-byte units */
3108 total_cost
+= each_cost
* 512;
3110 if (ERROR_SUCCESS
== (MSI_GetFeatureCost(dialog
->package
, feature
,
3111 MSICOSTTREE_SELFONLY
, INSTALLSTATE_ABSENT
, &each_cost
)))
3113 /* each_cost is in 512-byte units */
3114 total_cost
-= each_cost
* 512;
3120 static void dialog_vcl_add_drives( msi_dialog
*dialog
, struct control
*control
)
3122 ULARGE_INTEGER total
, unused
;
3123 LONGLONG difference
, cost
;
3124 WCHAR size_text
[MAX_PATH
];
3125 WCHAR cost_text
[MAX_PATH
];
3131 cost
= vcl_get_cost(dialog
);
3132 StrFormatByteSizeW(cost
, cost_text
, MAX_PATH
);
3134 size
= GetLogicalDriveStringsW( 0, NULL
);
3135 if ( !size
) return;
3137 drives
= malloc( (size
+ 1) * sizeof(WCHAR
) );
3138 if ( !drives
) return;
3140 GetLogicalDriveStringsW( size
, drives
);
3145 if (GetVolumeInformationW(ptr
, NULL
, 0, NULL
, 0, &flags
, NULL
, 0) &&
3146 flags
& FILE_READ_ONLY_VOLUME
)
3148 ptr
+= lstrlenW(ptr
) + 1;
3152 lvitem
.mask
= LVIF_TEXT
;
3154 lvitem
.iSubItem
= 0;
3155 lvitem
.pszText
= ptr
;
3156 lvitem
.cchTextMax
= lstrlenW(ptr
) + 1;
3157 SendMessageW( control
->hwnd
, LVM_INSERTITEMW
, 0, (LPARAM
)&lvitem
);
3159 GetDiskFreeSpaceExW(ptr
, &unused
, &total
, NULL
);
3160 difference
= unused
.QuadPart
- cost
;
3162 StrFormatByteSizeW(total
.QuadPart
, size_text
, MAX_PATH
);
3163 lvitem
.iSubItem
= 1;
3164 lvitem
.pszText
= size_text
;
3165 lvitem
.cchTextMax
= lstrlenW(size_text
) + 1;
3166 SendMessageW( control
->hwnd
, LVM_SETITEMW
, 0, (LPARAM
)&lvitem
);
3168 StrFormatByteSizeW(unused
.QuadPart
, size_text
, MAX_PATH
);
3169 lvitem
.iSubItem
= 2;
3170 lvitem
.pszText
= size_text
;
3171 lvitem
.cchTextMax
= lstrlenW(size_text
) + 1;
3172 SendMessageW( control
->hwnd
, LVM_SETITEMW
, 0, (LPARAM
)&lvitem
);
3174 lvitem
.iSubItem
= 3;
3175 lvitem
.pszText
= cost_text
;
3176 lvitem
.cchTextMax
= lstrlenW(cost_text
) + 1;
3177 SendMessageW( control
->hwnd
, LVM_SETITEMW
, 0, (LPARAM
)&lvitem
);
3179 StrFormatByteSizeW(difference
, size_text
, MAX_PATH
);
3180 lvitem
.iSubItem
= 4;
3181 lvitem
.pszText
= size_text
;
3182 lvitem
.cchTextMax
= lstrlenW(size_text
) + 1;
3183 SendMessageW( control
->hwnd
, LVM_SETITEMW
, 0, (LPARAM
)&lvitem
);
3185 ptr
+= lstrlenW(ptr
) + 1;
3192 static UINT
dialog_volumecost_list( msi_dialog
*dialog
, MSIRECORD
*rec
)
3194 struct control
*control
;
3197 style
= LVS_REPORT
| WS_VSCROLL
| WS_HSCROLL
| LVS_SHAREIMAGELISTS
|
3198 LVS_AUTOARRANGE
| LVS_SINGLESEL
| WS_BORDER
|
3199 WS_CHILD
| WS_TABSTOP
| WS_GROUP
;
3200 control
= dialog_add_control( dialog
, rec
, WC_LISTVIEWW
, style
);
3202 return ERROR_FUNCTION_FAILED
;
3204 dialog_vcl_add_columns( dialog
, control
, rec
);
3205 dialog_vcl_add_drives( dialog
, control
);
3207 return ERROR_SUCCESS
;
3210 /******************** VolumeSelect Combo ***************************************/
3212 static UINT
dialog_volsel_handler( msi_dialog
*dialog
, struct control
*control
, WPARAM param
)
3214 WCHAR text
[MAX_PATH
];
3219 if (HIWORD(param
) != CBN_SELCHANGE
)
3220 return ERROR_SUCCESS
;
3222 index
= SendMessageW( control
->hwnd
, CB_GETCURSEL
, 0, 0 );
3223 if ( index
== CB_ERR
)
3225 ERR("No ComboBox item selected!\n");
3226 return ERROR_FUNCTION_FAILED
;
3229 SendMessageW( control
->hwnd
, CB_GETLBTEXT
, index
, (LPARAM
)text
);
3231 indirect
= control
->attributes
& msidbControlAttributesIndirect
;
3232 prop
= dialog_dup_property( dialog
, control
->property
, indirect
);
3234 dialog_set_property( dialog
->package
, prop
, text
);
3237 return ERROR_SUCCESS
;
3240 static void dialog_vsc_add_drives( msi_dialog
*dialog
, struct control
*control
)
3245 size
= GetLogicalDriveStringsW( 0, NULL
);
3246 if ( !size
) return;
3248 drives
= malloc( (size
+ 1) * sizeof(WCHAR
) );
3249 if ( !drives
) return;
3251 GetLogicalDriveStringsW( size
, drives
);
3256 SendMessageW( control
->hwnd
, CB_ADDSTRING
, 0, (LPARAM
)ptr
);
3257 ptr
+= lstrlenW(ptr
) + 1;
3263 static UINT
dialog_volumeselect_combo( msi_dialog
*dialog
, MSIRECORD
*rec
)
3265 struct control
*control
;
3269 /* FIXME: CBS_OWNERDRAWFIXED */
3270 style
= WS_CHILD
| WS_VISIBLE
| WS_GROUP
| WS_TABSTOP
|
3271 CBS_DROPDOWNLIST
| CBS_SORT
| CBS_HASSTRINGS
|
3272 WS_EX_LEFT
| WS_EX_LTRREADING
| WS_EX_RIGHTSCROLLBAR
;
3273 control
= dialog_add_control( dialog
, rec
, WC_COMBOBOXW
, style
);
3275 return ERROR_FUNCTION_FAILED
;
3277 control
->attributes
= MSI_RecordGetInteger( rec
, 8 );
3278 control
->handler
= dialog_volsel_handler
;
3279 prop
= MSI_RecordGetString( rec
, 9 );
3280 control
->property
= dialog_dup_property( dialog
, prop
, FALSE
);
3282 dialog_vsc_add_drives( dialog
, control
);
3284 return ERROR_SUCCESS
;
3287 static UINT
dialog_hyperlink_handler( msi_dialog
*dialog
, struct control
*control
, WPARAM param
)
3289 int len
, len_href
= ARRAY_SIZE( L
"href" ) - 1;
3294 item
.mask
= LIF_ITEMINDEX
| LIF_URL
;
3298 SendMessageW( control
->hwnd
, LM_GETITEM
, 0, (LPARAM
)&item
);
3301 while (*p
&& *p
!= '<') p
++;
3302 if (!*p
++) return ERROR_SUCCESS
;
3303 if (towupper( *p
++ ) != 'A' || !iswspace( *p
++ )) return ERROR_SUCCESS
;
3304 while (*p
&& iswspace( *p
)) p
++;
3306 len
= lstrlenW( p
);
3307 if (len
> len_href
&& !wcsnicmp( p
, L
"href", len_href
))
3310 while (*p
&& iswspace( *p
)) p
++;
3311 if (!*p
|| *p
++ != '=') return ERROR_SUCCESS
;
3312 while (*p
&& iswspace( *p
)) p
++;
3314 if (*p
== '\"' || *p
== '\'') quote
= *p
++;
3318 while (*q
&& *q
!= quote
) q
++;
3319 if (*q
!= quote
) return ERROR_SUCCESS
;
3323 while (*q
&& *q
!= '>' && !iswspace( *q
)) q
++;
3324 if (!*q
) return ERROR_SUCCESS
;
3326 item
.szUrl
[q
- item
.szUrl
] = 0;
3327 ShellExecuteW( NULL
, L
"open", p
, NULL
, NULL
, SW_SHOWNORMAL
);
3329 return ERROR_SUCCESS
;
3332 static UINT
dialog_hyperlink( msi_dialog
*dialog
, MSIRECORD
*rec
)
3334 struct control
*control
;
3335 DWORD style
= WS_CHILD
| WS_TABSTOP
| WS_GROUP
;
3336 const WCHAR
*text
= MSI_RecordGetString( rec
, 10 );
3337 int len
= lstrlenW( text
);
3340 control
= dialog_add_control( dialog
, rec
, WC_LINK
, style
);
3342 return ERROR_FUNCTION_FAILED
;
3344 control
->attributes
= MSI_RecordGetInteger( rec
, 8 );
3345 control
->handler
= dialog_hyperlink_handler
;
3347 item
.mask
= LIF_ITEMINDEX
| LIF_STATE
| LIF_URL
;
3349 item
.state
= LIS_ENABLED
;
3350 item
.stateMask
= LIS_ENABLED
;
3351 if (len
< L_MAX_URL_LENGTH
) lstrcpyW( item
.szUrl
, text
);
3352 else item
.szUrl
[0] = 0;
3354 SendMessageW( control
->hwnd
, LM_SETITEM
, 0, (LPARAM
)&item
);
3356 return ERROR_SUCCESS
;
3359 /******************** ListView *****************************************/
3361 struct listview_param
3364 struct control
*control
;
3367 static UINT
dialog_listview_handler( msi_dialog
*dialog
, struct control
*control
, WPARAM param
)
3369 NMHDR
*nmhdr
= (NMHDR
*)param
;
3371 FIXME("code %#x (%d)\n", nmhdr
->code
, nmhdr
->code
);
3373 return ERROR_SUCCESS
;
3376 static UINT
listview_add_item( MSIRECORD
*rec
, void *param
)
3378 struct listview_param
*lv_param
= (struct listview_param
*)param
;
3379 LPCWSTR text
, binary
;
3383 text
= MSI_RecordGetString( rec
, 4 );
3384 binary
= MSI_RecordGetString( rec
, 5 );
3385 hIcon
= load_icon( lv_param
->dialog
->package
->db
, binary
, 0 );
3387 TRACE("Adding: text %s, binary %s, icon %p\n", debugstr_w(text
), debugstr_w(binary
), hIcon
);
3389 memset( &item
, 0, sizeof(item
) );
3390 item
.mask
= LVIF_TEXT
| LVIF_IMAGE
;
3391 deformat_string( lv_param
->dialog
->package
, text
, &item
.pszText
);
3392 item
.iImage
= ImageList_AddIcon( lv_param
->control
->hImageList
, hIcon
);
3393 item
.iItem
= item
.iImage
;
3394 SendMessageW( lv_param
->control
->hwnd
, LVM_INSERTITEMW
, 0, (LPARAM
)&item
);
3396 DestroyIcon( hIcon
);
3398 return ERROR_SUCCESS
;
3401 static UINT
listview_add_items( msi_dialog
*dialog
, struct control
*control
)
3404 struct listview_param lv_param
= { dialog
, control
};
3406 if (MSI_OpenQuery( dialog
->package
->db
, &view
, L
"SELECT * FROM `ListView` WHERE `Property` = '%s' ORDER BY `Order`",
3407 control
->property
) == ERROR_SUCCESS
)
3409 MSI_IterateRecords( view
, NULL
, listview_add_item
, &lv_param
);
3410 msiobj_release( &view
->hdr
);
3413 return ERROR_SUCCESS
;
3416 static UINT
dialog_listview( msi_dialog
*dialog
, MSIRECORD
*rec
)
3418 struct control
*control
;
3420 DWORD style
, attributes
;
3424 style
= LVS_REPORT
| LVS_NOCOLUMNHEADER
| LVS_SHAREIMAGELISTS
| LVS_SINGLESEL
|
3425 LVS_SHOWSELALWAYS
| WS_VSCROLL
| WS_HSCROLL
| WS_BORDER
| WS_TABSTOP
| WS_CHILD
;
3426 attributes
= MSI_RecordGetInteger( rec
, 8 );
3427 if ( ~attributes
& msidbControlAttributesSorted
)
3428 style
|= LVS_SORTASCENDING
;
3429 control
= dialog_add_control( dialog
, rec
, WC_LISTVIEWW
, style
);
3431 return ERROR_FUNCTION_FAILED
;
3433 prop
= MSI_RecordGetString( rec
, 9 );
3434 control
->property
= dialog_dup_property( dialog
, prop
, FALSE
);
3436 control
->hImageList
= ImageList_Create( 16, 16, ILC_COLOR32
, 0, 1);
3437 SendMessageW( control
->hwnd
, LVM_SETIMAGELIST
, LVSIL_SMALL
, (LPARAM
)control
->hImageList
);
3439 col
.mask
= LVCF_FMT
| LVCF_WIDTH
;
3440 col
.fmt
= LVCFMT_LEFT
;
3442 SendMessageW( control
->hwnd
, LVM_INSERTCOLUMNW
, 0, (LPARAM
)&col
);
3444 GetClientRect( control
->hwnd
, &rc
);
3445 col
.cx
= rc
.right
- 16;
3446 SendMessageW( control
->hwnd
, LVM_INSERTCOLUMNW
, 0, (LPARAM
)&col
);
3448 if (control
->property
)
3449 listview_add_items( dialog
, control
);
3451 control
->handler
= dialog_listview_handler
;
3453 return ERROR_SUCCESS
;
3456 static const struct control_handler msi_dialog_handler
[] =
3458 { L
"Text", dialog_text_control
},
3459 { L
"PushButton", dialog_button_control
},
3460 { L
"Line", dialog_line_control
},
3461 { L
"Bitmap", dialog_bitmap_control
},
3462 { L
"CheckBox", dialog_checkbox_control
},
3463 { L
"ScrollableText", dialog_scrolltext_control
},
3464 { L
"ComboBox", dialog_combo_control
},
3465 { L
"Edit", dialog_edit_control
},
3466 { L
"MaskedEdit", dialog_maskedit_control
},
3467 { L
"PathEdit", dialog_pathedit_control
},
3468 { L
"ProgressBar", dialog_progress_bar
},
3469 { L
"RadioButtonGroup", dialog_radiogroup_control
},
3470 { L
"Icon", dialog_icon_control
},
3471 { L
"SelectionTree", dialog_selection_tree
},
3472 { L
"GroupBox", dialog_group_box
},
3473 { L
"ListBox", dialog_list_box
},
3474 { L
"DirectoryCombo", dialog_directory_combo
},
3475 { L
"DirectoryList", dialog_directory_list
},
3476 { L
"VolumeCostList", dialog_volumecost_list
},
3477 { L
"VolumeSelectCombo", dialog_volumeselect_combo
},
3478 { L
"HyperLink", dialog_hyperlink
},
3479 { L
"ListView", dialog_listview
}
3482 static UINT
dialog_create_controls( MSIRECORD
*rec
, void *param
)
3484 msi_dialog
*dialog
= param
;
3485 LPCWSTR control_type
;
3488 /* find and call the function that can create this type of control */
3489 control_type
= MSI_RecordGetString( rec
, 3 );
3490 for( i
= 0; i
< ARRAY_SIZE( msi_dialog_handler
); i
++ )
3491 if (!wcsicmp( msi_dialog_handler
[i
].control_type
, control_type
))
3493 if( i
!= ARRAY_SIZE( msi_dialog_handler
))
3494 msi_dialog_handler
[i
].func( dialog
, rec
);
3496 ERR("no handler for element type %s\n", debugstr_w(control_type
));
3498 return ERROR_SUCCESS
;
3501 static UINT
dialog_fill_controls( msi_dialog
*dialog
)
3505 MSIPACKAGE
*package
= dialog
->package
;
3507 TRACE("%p %s\n", dialog
, debugstr_w(dialog
->name
) );
3509 /* query the Control table for all the elements of the control */
3510 r
= MSI_OpenQuery( package
->db
, &view
, L
"SELECT * FROM `Control` WHERE `Dialog_` = '%s'", dialog
->name
);
3511 if( r
!= ERROR_SUCCESS
)
3513 ERR("query failed for dialog %s\n", debugstr_w(dialog
->name
));
3514 return ERROR_INVALID_PARAMETER
;
3517 r
= MSI_IterateRecords( view
, 0, dialog_create_controls
, dialog
);
3518 msiobj_release( &view
->hdr
);
3522 static UINT
dialog_reset( msi_dialog
*dialog
)
3524 /* FIXME: should restore the original values of any properties we changed */
3525 return dialog_evaluate_control_conditions( dialog
);
3528 /* figure out the height of 10 point MS Sans Serif */
3529 static INT
dialog_get_sans_serif_height( HWND hwnd
)
3535 HFONT hFont
, hOldFont
;
3538 hdc
= GetDC( hwnd
);
3541 memset( &lf
, 0, sizeof lf
);
3542 lf
.lfHeight
= MulDiv(12, GetDeviceCaps(hdc
, LOGPIXELSY
), 72);
3543 lstrcpyW( lf
.lfFaceName
, L
"MS Sans Serif" );
3544 hFont
= CreateFontIndirectW(&lf
);
3547 hOldFont
= SelectObject( hdc
, hFont
);
3548 r
= GetTextMetricsW( hdc
, &tm
);
3550 height
= tm
.tmHeight
;
3551 SelectObject( hdc
, hOldFont
);
3552 DeleteObject( hFont
);
3554 ReleaseDC( hwnd
, hdc
);
3559 /* fetch the associated record from the Dialog table */
3560 static MSIRECORD
*get_dialog_record( msi_dialog
*dialog
)
3562 MSIPACKAGE
*package
= dialog
->package
;
3563 MSIRECORD
*rec
= NULL
;
3565 TRACE("%p %s\n", dialog
, debugstr_w(dialog
->name
) );
3567 rec
= MSI_QueryGetRecord( package
->db
, L
"SELECT * FROM `Dialog` WHERE `Dialog` = '%s'", dialog
->name
);
3569 WARN("query failed for dialog %s\n", debugstr_w(dialog
->name
));
3574 static void dialog_adjust_dialog_pos( msi_dialog
*dialog
, MSIRECORD
*rec
, RECT
*pos
)
3581 center
.x
= MSI_RecordGetInteger( rec
, 2 );
3582 center
.y
= MSI_RecordGetInteger( rec
, 3 );
3584 sz
.cx
= MSI_RecordGetInteger( rec
, 4 );
3585 sz
.cy
= MSI_RecordGetInteger( rec
, 5 );
3587 sz
.cx
= dialog_scale_unit( dialog
, sz
.cx
);
3588 sz
.cy
= dialog_scale_unit( dialog
, sz
.cy
);
3590 xres
= msi_get_property_int( dialog
->package
->db
, L
"ScreenX", 0 );
3591 yres
= msi_get_property_int( dialog
->package
->db
, L
"ScreenY", 0 );
3593 center
.x
= MulDiv( center
.x
, xres
, 100 );
3594 center
.y
= MulDiv( center
.y
, yres
, 100 );
3596 /* turn the client pos into the window rectangle */
3597 if (dialog
->package
->center_x
&& dialog
->package
->center_y
)
3599 pos
->left
= dialog
->package
->center_x
- sz
.cx
/ 2.0;
3600 pos
->right
= pos
->left
+ sz
.cx
;
3601 pos
->top
= dialog
->package
->center_y
- sz
.cy
/ 2.0;
3602 pos
->bottom
= pos
->top
+ sz
.cy
;
3606 pos
->left
= center
.x
- sz
.cx
/2;
3607 pos
->right
= pos
->left
+ sz
.cx
;
3608 pos
->top
= center
.y
- sz
.cy
/2;
3609 pos
->bottom
= pos
->top
+ sz
.cy
;
3611 /* save the center */
3612 dialog
->package
->center_x
= center
.x
;
3613 dialog
->package
->center_y
= center
.y
;
3616 dialog
->size
.cx
= sz
.cx
;
3617 dialog
->size
.cy
= sz
.cy
;
3619 TRACE("%s\n", wine_dbgstr_rect(pos
));
3621 style
= GetWindowLongPtrW( dialog
->hwnd
, GWL_STYLE
);
3622 AdjustWindowRect( pos
, style
, FALSE
);
3625 static void dialog_set_tab_order( msi_dialog
*dialog
, const WCHAR
*first
)
3627 struct list tab_chain
;
3628 struct control
*control
;
3629 HWND prev
= HWND_TOP
;
3631 list_init( &tab_chain
);
3632 if (!(control
= dialog_find_control( dialog
, first
))) return;
3634 dialog
->hWndFocus
= control
->hwnd
;
3637 list_remove( &control
->entry
);
3638 list_add_tail( &tab_chain
, &control
->entry
);
3639 if (!control
->tabnext
) break;
3640 control
= dialog_find_control( dialog
, control
->tabnext
);
3643 LIST_FOR_EACH_ENTRY( control
, &tab_chain
, struct control
, entry
)
3645 SetWindowPos( control
->hwnd
, prev
, 0, 0, 0, 0,
3646 SWP_NOMOVE
| SWP_NOOWNERZORDER
| SWP_NOREDRAW
|
3647 SWP_NOREPOSITION
| SWP_NOSENDCHANGING
| SWP_NOSIZE
);
3648 prev
= control
->hwnd
;
3651 /* put them back on the main list */
3652 list_move_head( &dialog
->controls
, &tab_chain
);
3655 static LRESULT
dialog_oncreate( HWND hwnd
, CREATESTRUCTW
*cs
)
3657 msi_dialog
*dialog
= cs
->lpCreateParams
;
3658 MSIRECORD
*rec
= NULL
;
3659 LPWSTR title
= NULL
;
3662 TRACE("%p %p\n", dialog
, dialog
->package
);
3664 dialog
->hwnd
= hwnd
;
3665 SetWindowLongPtrW( hwnd
, GWLP_USERDATA
, (LONG_PTR
) dialog
);
3667 rec
= get_dialog_record( dialog
);
3670 TRACE("No record found for dialog %s\n", debugstr_w(dialog
->name
));
3674 dialog
->scale
= dialog_get_sans_serif_height(dialog
->hwnd
);
3676 dialog_adjust_dialog_pos( dialog
, rec
, &pos
);
3678 dialog
->attributes
= MSI_RecordGetInteger( rec
, 6 );
3680 dialog
->default_font
= msi_dup_property( dialog
->package
->db
, L
"DefaultUIFont" );
3681 if (!dialog
->default_font
)
3683 dialog
->default_font
= wcsdup( L
"MS Shell Dlg" );
3684 if (!dialog
->default_font
)
3686 msiobj_release( &rec
->hdr
);
3691 title
= get_deformatted_field( dialog
->package
, rec
, 7 );
3692 SetWindowTextW( hwnd
, title
);
3695 SetWindowPos( hwnd
, 0, pos
.left
, pos
.top
,
3696 pos
.right
- pos
.left
, pos
.bottom
- pos
.top
,
3697 SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_NOREDRAW
);
3699 dialog_build_font_list( dialog
);
3700 dialog_fill_controls( dialog
);
3701 dialog_evaluate_control_conditions( dialog
);
3702 dialog_set_tab_order( dialog
, MSI_RecordGetString( rec
, 8 ) );
3703 msiobj_release( &rec
->hdr
);
3708 static LRESULT
dialog_oncommand( msi_dialog
*dialog
, WPARAM param
, HWND hwnd
)
3710 struct control
*control
= NULL
;
3712 TRACE( "%p, %#Ix, %p\n", dialog
, param
, hwnd
);
3717 control
= dialog_find_control( dialog
, dialog
->control_default
);
3719 case 2: /* escape */
3720 control
= dialog_find_control( dialog
, dialog
->control_cancel
);
3723 control
= dialog_find_control_by_hwnd( dialog
, hwnd
);
3728 if( control
->handler
)
3730 control
->handler( dialog
, control
, param
);
3731 dialog_evaluate_control_conditions( dialog
);
3738 static LRESULT
dialog_onnotify( msi_dialog
*dialog
, LPARAM param
)
3740 LPNMHDR nmhdr
= (LPNMHDR
) param
;
3741 struct control
*control
= dialog_find_control_by_hwnd( dialog
, nmhdr
->hwndFrom
);
3743 TRACE("%p %p\n", dialog
, nmhdr
->hwndFrom
);
3745 if ( control
&& control
->handler
)
3746 control
->handler( dialog
, control
, param
);
3751 static void dialog_setfocus( msi_dialog
*dialog
)
3753 HWND hwnd
= dialog
->hWndFocus
;
3755 hwnd
= GetNextDlgTabItem( dialog
->hwnd
, hwnd
, TRUE
);
3756 hwnd
= GetNextDlgTabItem( dialog
->hwnd
, hwnd
, FALSE
);
3758 dialog
->hWndFocus
= hwnd
;
3761 static LRESULT WINAPI
MSIDialog_WndProc( HWND hwnd
, UINT msg
,
3762 WPARAM wParam
, LPARAM lParam
)
3764 msi_dialog
*dialog
= (LPVOID
) GetWindowLongPtrW( hwnd
, GWLP_USERDATA
);
3766 TRACE("0x%04x\n", msg
);
3771 dialog
->package
->center_x
= LOWORD(lParam
) + dialog
->size
.cx
/ 2.0;
3772 dialog
->package
->center_y
= HIWORD(lParam
) + dialog
->size
.cy
/ 2.0;
3776 return dialog_oncreate( hwnd
, (LPCREATESTRUCTW
)lParam
);
3779 return dialog_oncommand( dialog
, wParam
, (HWND
)lParam
);
3782 /* Simulate escape press */
3783 return dialog_oncommand(dialog
, 2, NULL
);
3786 if( LOWORD(wParam
) == WA_INACTIVE
)
3787 dialog
->hWndFocus
= GetFocus();
3789 dialog_setfocus( dialog
);
3793 dialog_setfocus( dialog
);
3796 /* bounce back to our subclassed static control */
3797 case WM_CTLCOLORSTATIC
:
3798 return SendMessageW( (HWND
) lParam
, WM_CTLCOLORSTATIC
, wParam
, lParam
);
3801 dialog
->hwnd
= NULL
;
3804 return dialog_onnotify( dialog
, lParam
);
3806 return DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
3809 static void process_pending_messages( HWND hdlg
)
3813 while (PeekMessageW( &msg
, 0, 0, 0, PM_REMOVE
))
3815 if (hdlg
&& IsDialogMessageW( hdlg
, &msg
)) continue;
3816 TranslateMessage( &msg
);
3817 DispatchMessageW( &msg
);
3821 static UINT
dialog_run_message_loop( msi_dialog
*dialog
)
3826 if( uiThreadId
!= GetCurrentThreadId() )
3827 return SendMessageW( hMsiHiddenWindow
, WM_MSI_DIALOG_CREATE
, 0, (LPARAM
) dialog
);
3829 /* create the dialog window, don't show it yet */
3830 style
= WS_OVERLAPPED
| WS_SYSMENU
;
3831 if( dialog
->attributes
& msidbDialogAttributesVisible
)
3832 style
|= WS_VISIBLE
;
3834 if (dialog
->parent
== NULL
&& (dialog
->attributes
& msidbDialogAttributesMinimize
))
3835 style
|= WS_MINIMIZEBOX
;
3837 parent
= dialog
->parent
? dialog
->parent
->hwnd
: 0;
3839 hwnd
= CreateWindowW( L
"MsiDialogCloseClass", dialog
->name
, style
,
3840 CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
,
3841 parent
, NULL
, NULL
, dialog
);
3844 ERR("Failed to create dialog %s\n", debugstr_w( dialog
->name
));
3845 return ERROR_FUNCTION_FAILED
;
3848 ShowWindow( hwnd
, SW_SHOW
);
3849 /* UpdateWindow( hwnd ); - and causes the transparent static controls not to paint */
3851 if( dialog
->attributes
& msidbDialogAttributesModal
)
3853 while( !dialog
->finished
)
3855 MsgWaitForMultipleObjects( 0, NULL
, 0, INFINITE
, QS_ALLINPUT
);
3856 process_pending_messages( dialog
->hwnd
);
3860 return ERROR_IO_PENDING
;
3862 return ERROR_SUCCESS
;
3865 static LRESULT WINAPI
MSIHiddenWindowProc( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
3867 msi_dialog
*dialog
= (msi_dialog
*) lParam
;
3869 TRACE("%d %p\n", msg
, dialog
);
3873 case WM_MSI_DIALOG_CREATE
:
3874 return dialog_run_message_loop( dialog
);
3875 case WM_MSI_DIALOG_DESTROY
:
3876 msi_dialog_destroy( dialog
);
3879 return DefWindowProcW( hwnd
, msg
, wParam
, lParam
);
3882 static BOOL
dialog_register_class( void )
3886 ZeroMemory( &cls
, sizeof cls
);
3887 cls
.lpfnWndProc
= MSIDialog_WndProc
;
3888 cls
.hInstance
= NULL
;
3889 cls
.hIcon
= LoadIconW(0, (LPWSTR
)IDI_APPLICATION
);
3890 cls
.hCursor
= LoadCursorW(0, (LPWSTR
)IDC_ARROW
);
3891 cls
.hbrBackground
= (HBRUSH
)(COLOR_3DFACE
+ 1);
3892 cls
.lpszMenuName
= NULL
;
3893 cls
.lpszClassName
= L
"MsiDialogCloseClass";
3895 if( !RegisterClassW( &cls
) )
3898 cls
.lpfnWndProc
= MSIHiddenWindowProc
;
3899 cls
.lpszClassName
= L
"MsiHiddenWindow";
3901 if( !RegisterClassW( &cls
) )
3904 uiThreadId
= GetCurrentThreadId();
3906 hMsiHiddenWindow
= CreateWindowW( L
"MsiHiddenWindow", NULL
, WS_OVERLAPPED
,
3907 0, 0, 100, 100, NULL
, NULL
, NULL
, NULL
);
3908 if( !hMsiHiddenWindow
)
3914 static msi_dialog
*dialog_create( MSIPACKAGE
*package
, const WCHAR
*name
, msi_dialog
*parent
,
3915 UINT (*event_handler
)(msi_dialog
*, const WCHAR
*, const WCHAR
*) )
3917 MSIRECORD
*rec
= NULL
;
3920 TRACE("%s\n", debugstr_w(name
));
3922 if (!hMsiHiddenWindow
) dialog_register_class();
3924 /* allocate the structure for the dialog to use */
3925 dialog
= calloc( 1, offsetof( msi_dialog
, name
[wcslen( name
) + 1] ) );
3928 lstrcpyW( dialog
->name
, name
);
3929 dialog
->parent
= parent
;
3930 dialog
->package
= package
;
3931 dialog
->event_handler
= event_handler
;
3932 dialog
->finished
= 0;
3933 list_init( &dialog
->controls
);
3934 list_init( &dialog
->fonts
);
3936 /* verify that the dialog exists */
3937 rec
= get_dialog_record( dialog
);
3943 dialog
->attributes
= MSI_RecordGetInteger( rec
, 6 );
3944 dialog
->control_default
= wcsdup( MSI_RecordGetString( rec
, 9 ) );
3945 dialog
->control_cancel
= wcsdup( MSI_RecordGetString( rec
, 10 ) );
3946 msiobj_release( &rec
->hdr
);
3948 rec
= MSI_CreateRecord(2);
3951 msi_dialog_destroy(dialog
);
3954 MSI_RecordSetStringW(rec
, 1, name
);
3955 MSI_RecordSetStringW(rec
, 2, L
"Dialog created");
3956 MSI_ProcessMessage(package
, INSTALLMESSAGE_ACTIONSTART
, rec
);
3957 msiobj_release(&rec
->hdr
);
3962 static void dialog_end_dialog( msi_dialog
*dialog
)
3964 TRACE("%p\n", dialog
);
3965 dialog
->finished
= 1;
3966 PostMessageW(dialog
->hwnd
, WM_NULL
, 0, 0);
3969 void msi_dialog_check_messages( HANDLE handle
)
3973 /* in threads other than the UI thread, block */
3974 if( uiThreadId
!= GetCurrentThreadId() )
3976 if (!handle
) return;
3977 while (MsgWaitForMultipleObjectsEx( 1, &handle
, INFINITE
, QS_ALLINPUT
, 0 ) == WAIT_OBJECT_0
+ 1)
3980 while (PeekMessageW( &msg
, NULL
, 0, 0, PM_REMOVE
))
3982 TranslateMessage( &msg
);
3983 DispatchMessageW( &msg
);
3989 /* there are two choices for the UI thread */
3992 process_pending_messages( NULL
);
3998 * block here until somebody creates a new dialog or
3999 * the handle we're waiting on becomes ready
4001 r
= MsgWaitForMultipleObjects( 1, &handle
, 0, INFINITE
, QS_ALLINPUT
);
4002 if( r
== WAIT_OBJECT_0
)
4007 static void dialog_do_preview( msi_dialog
*dialog
)
4010 dialog
->attributes
|= msidbDialogAttributesVisible
;
4011 dialog
->attributes
&= ~msidbDialogAttributesModal
;
4012 dialog_run_message_loop( dialog
);
4015 static void free_subscriber( struct subscriber
*sub
)
4018 free( sub
->control
);
4019 free( sub
->attribute
);
4023 static void event_cleanup_subscriptions( MSIPACKAGE
*package
, const WCHAR
*dialog
)
4025 struct list
*item
, *next
;
4027 LIST_FOR_EACH_SAFE( item
, next
, &package
->subscriptions
)
4029 struct subscriber
*sub
= LIST_ENTRY( item
, struct subscriber
, entry
);
4031 if (wcscmp( sub
->dialog
->name
, dialog
)) continue;
4032 list_remove( &sub
->entry
);
4033 free_subscriber( sub
);
4037 void msi_dialog_destroy( msi_dialog
*dialog
)
4039 struct font
*font
, *next
;
4041 if( uiThreadId
!= GetCurrentThreadId() )
4043 SendMessageW( hMsiHiddenWindow
, WM_MSI_DIALOG_DESTROY
, 0, (LPARAM
) dialog
);
4049 ShowWindow( dialog
->hwnd
, SW_HIDE
);
4050 DestroyWindow( dialog
->hwnd
);
4053 /* unsubscribe events */
4054 event_cleanup_subscriptions( dialog
->package
, dialog
->name
);
4056 /* destroy the list of controls */
4057 while( !list_empty( &dialog
->controls
) )
4061 t
= LIST_ENTRY( list_head( &dialog
->controls
), struct control
, entry
);
4062 destroy_control( t
);
4065 /* destroy the list of fonts */
4066 LIST_FOR_EACH_ENTRY_SAFE( font
, next
, &dialog
->fonts
, struct font
, entry
)
4068 list_remove( &font
->entry
);
4069 DeleteObject( font
->hfont
);
4072 free( dialog
->default_font
);
4074 free( dialog
->control_default
);
4075 free( dialog
->control_cancel
);
4076 dialog
->package
= NULL
;
4080 void msi_dialog_unregister_class( void )
4082 DestroyWindow( hMsiHiddenWindow
);
4083 hMsiHiddenWindow
= NULL
;
4084 UnregisterClassW( L
"MsiDialogCloseClass", NULL
);
4085 UnregisterClassW( L
"MsiHiddenWindow", NULL
);
4089 void msi_event_cleanup_all_subscriptions( MSIPACKAGE
*package
)
4091 struct list
*item
, *next
;
4093 LIST_FOR_EACH_SAFE( item
, next
, &package
->subscriptions
)
4095 struct subscriber
*sub
= LIST_ENTRY( item
, struct subscriber
, entry
);
4096 list_remove( &sub
->entry
);
4097 free_subscriber( sub
);
4101 static void MSI_ClosePreview( MSIOBJECTHDR
*arg
)
4103 MSIPREVIEW
*preview
= (MSIPREVIEW
*)arg
;
4104 msiobj_release( &preview
->package
->hdr
);
4107 static MSIPREVIEW
*MSI_EnableUIPreview( MSIDATABASE
*db
)
4109 MSIPREVIEW
*preview
= NULL
;
4110 MSIPACKAGE
*package
;
4112 package
= MSI_CreatePackage( db
);
4115 preview
= alloc_msiobject( MSIHANDLETYPE_PREVIEW
, sizeof(MSIPREVIEW
), MSI_ClosePreview
);
4118 preview
->package
= package
;
4119 msiobj_addref( &package
->hdr
);
4121 msiobj_release( &package
->hdr
);
4126 UINT WINAPI
MsiEnableUIPreview( MSIHANDLE hdb
, MSIHANDLE
*phPreview
)
4129 MSIPREVIEW
*preview
;
4130 UINT r
= ERROR_FUNCTION_FAILED
;
4132 TRACE( "%lu %p\n", hdb
, phPreview
);
4134 if (!(db
= msihandle2msiinfo(hdb
, MSIHANDLETYPE_DATABASE
)))
4135 return ERROR_INVALID_HANDLE
;
4137 preview
= MSI_EnableUIPreview( db
);
4140 *phPreview
= alloc_msihandle( &preview
->hdr
);
4141 msiobj_release( &preview
->hdr
);
4144 r
= ERROR_NOT_ENOUGH_MEMORY
;
4146 msiobj_release( &db
->hdr
);
4150 static UINT
preview_event_handler( msi_dialog
*dialog
, const WCHAR
*event
, const WCHAR
*argument
)
4152 MESSAGE("Preview dialog event '%s' (arg='%s')\n", debugstr_w(event
), debugstr_w(argument
));
4153 return ERROR_SUCCESS
;
4156 static UINT
MSI_PreviewDialogW( MSIPREVIEW
*preview
, LPCWSTR szDialogName
)
4158 msi_dialog
*dialog
= NULL
;
4159 UINT r
= ERROR_SUCCESS
;
4161 if (preview
->dialog
)
4162 msi_dialog_destroy( preview
->dialog
);
4164 /* an empty name means we should just destroy the current preview dialog */
4167 dialog
= dialog_create( preview
->package
, szDialogName
, NULL
, preview_event_handler
);
4169 dialog_do_preview( dialog
);
4171 r
= ERROR_FUNCTION_FAILED
;
4173 preview
->dialog
= dialog
;
4177 UINT WINAPI
MsiPreviewDialogW( MSIHANDLE hPreview
, LPCWSTR szDialogName
)
4179 MSIPREVIEW
*preview
;
4182 TRACE( "%lu %s\n", hPreview
, debugstr_w(szDialogName
) );
4184 preview
= msihandle2msiinfo( hPreview
, MSIHANDLETYPE_PREVIEW
);
4186 return ERROR_INVALID_HANDLE
;
4188 r
= MSI_PreviewDialogW( preview
, szDialogName
);
4189 msiobj_release( &preview
->hdr
);
4193 UINT WINAPI
MsiPreviewDialogA( MSIHANDLE hPreview
, LPCSTR szDialogName
)
4198 TRACE( "%lu %s\n", hPreview
, debugstr_a(szDialogName
) );
4202 strW
= strdupAtoW( szDialogName
);
4204 return ERROR_OUTOFMEMORY
;
4206 r
= MsiPreviewDialogW( hPreview
, strW
);
4211 UINT WINAPI
MsiPreviewBillboardW( MSIHANDLE hPreview
, const WCHAR
*szControlName
, const WCHAR
*szBillboard
)
4213 FIXME( "%lu %s %s\n", hPreview
, debugstr_w(szControlName
), debugstr_w(szBillboard
) );
4214 return ERROR_CALL_NOT_IMPLEMENTED
;
4217 UINT WINAPI
MsiPreviewBillboardA( MSIHANDLE hPreview
, const char *szControlName
, const char *szBillboard
)
4219 FIXME( "%lu %s %s\n", hPreview
, debugstr_a(szControlName
), debugstr_a(szBillboard
) );
4220 return ERROR_CALL_NOT_IMPLEMENTED
;
4223 struct control_event
4226 UINT (*handler
)( msi_dialog
*, const WCHAR
* );
4229 static UINT
dialog_event_handler( msi_dialog
*, const WCHAR
*, const WCHAR
* );
4231 /* create a dialog box and run it if it's modal */
4232 static INT
event_do_dialog( MSIPACKAGE
*package
, const WCHAR
*name
, msi_dialog
*parent
, BOOL destroy_modeless
)
4238 /* create a new dialog */
4239 dialog
= dialog_create( package
, name
, parent
, dialog_event_handler
);
4242 /* kill the current modeless dialog */
4243 if (destroy_modeless
&& package
->dialog
)
4245 msi_dialog_destroy( package
->dialog
);
4246 package
->dialog
= NULL
;
4249 /* modeless dialogs return an error message */
4250 r
= dialog_run_message_loop( dialog
);
4251 if (r
== ERROR_SUCCESS
)
4253 retval
= dialog
->retval
;
4254 msi_dialog_destroy( dialog
);
4259 package
->dialog
= dialog
;
4266 /* end a modal dialog box */
4267 static UINT
event_end_dialog( msi_dialog
*dialog
, const WCHAR
*argument
)
4269 if (!wcscmp( argument
, L
"Exit" ))
4270 dialog
->retval
= IDCANCEL
;
4271 else if (!wcscmp( argument
, L
"Retry" ))
4272 dialog
->retval
= IDRETRY
;
4273 else if (!wcscmp( argument
, L
"Ignore" ))
4274 dialog
->retval
= IDOK
;
4275 else if (!wcscmp( argument
, L
"Return" ))
4279 ERR("Unknown argument string %s\n", debugstr_w(argument
));
4280 dialog
->retval
= IDABORT
;
4282 event_cleanup_subscriptions( dialog
->package
, dialog
->name
);
4283 dialog_end_dialog( dialog
);
4284 return ERROR_SUCCESS
;
4287 static UINT
pending_event_end_dialog( msi_dialog
*dialog
, const WCHAR
*argument
)
4289 dialog
->pending_event
= event_end_dialog
;
4290 free( dialog
->pending_argument
);
4291 dialog
->pending_argument
= wcsdup( argument
);
4292 return ERROR_SUCCESS
;
4295 /* transition from one modal dialog to another modal dialog */
4296 static UINT
event_new_dialog( msi_dialog
*dialog
, const WCHAR
*argument
)
4298 /* store the name of the next dialog, and signal this one to end */
4299 dialog
->package
->next_dialog
= wcsdup( argument
);
4300 msi_event_cleanup_all_subscriptions( dialog
->package
);
4301 dialog_end_dialog( dialog
);
4302 return ERROR_SUCCESS
;
4305 static UINT
pending_event_new_dialog( msi_dialog
*dialog
, const WCHAR
*argument
)
4307 dialog
->pending_event
= event_new_dialog
;
4308 free( dialog
->pending_argument
);
4309 dialog
->pending_argument
= wcsdup( argument
);
4310 return ERROR_SUCCESS
;
4313 /* create a new child dialog of an existing modal dialog */
4314 static UINT
event_spawn_dialog( msi_dialog
*dialog
, const WCHAR
*argument
)
4317 /* don't destroy a modeless dialogs that might be our parent */
4318 r
= event_do_dialog( dialog
->package
, argument
, dialog
, FALSE
);
4322 dialog_end_dialog( dialog
);
4325 dialog_update_all_controls(dialog
);
4327 return ERROR_SUCCESS
;
4330 static UINT
pending_event_spawn_dialog( msi_dialog
*dialog
, const WCHAR
*argument
)
4332 dialog
->pending_event
= event_spawn_dialog
;
4333 free( dialog
->pending_argument
);
4334 dialog
->pending_argument
= wcsdup( argument
);
4335 return ERROR_SUCCESS
;
4338 /* creates a dialog that remains up for a period of time based on a condition */
4339 static UINT
event_spawn_wait_dialog( msi_dialog
*dialog
, const WCHAR
*argument
)
4341 FIXME("doing nothing\n");
4342 return ERROR_SUCCESS
;
4345 static UINT
event_do_action( msi_dialog
*dialog
, const WCHAR
*argument
)
4347 ACTION_PerformAction(dialog
->package
, argument
);
4348 return ERROR_SUCCESS
;
4351 static UINT
event_add_local( msi_dialog
*dialog
, const WCHAR
*argument
)
4353 MSIFEATURE
*feature
;
4355 LIST_FOR_EACH_ENTRY( feature
, &dialog
->package
->features
, MSIFEATURE
, entry
)
4357 if (!wcscmp( argument
, feature
->Feature
) || !wcscmp( argument
, L
"ALL" ))
4359 if (feature
->ActionRequest
!= INSTALLSTATE_LOCAL
)
4360 msi_set_property( dialog
->package
->db
, L
"Preselected", L
"1", -1 );
4361 MSI_SetFeatureStateW( dialog
->package
, feature
->Feature
, INSTALLSTATE_LOCAL
);
4364 return ERROR_SUCCESS
;
4367 static UINT
event_remove( msi_dialog
*dialog
, const WCHAR
*argument
)
4369 MSIFEATURE
*feature
;
4371 LIST_FOR_EACH_ENTRY( feature
, &dialog
->package
->features
, MSIFEATURE
, entry
)
4373 if (!wcscmp( argument
, feature
->Feature
) || !wcscmp( argument
, L
"ALL" ))
4375 if (feature
->ActionRequest
!= INSTALLSTATE_ABSENT
)
4376 msi_set_property( dialog
->package
->db
, L
"Preselected", L
"1", -1 );
4377 MSI_SetFeatureStateW( dialog
->package
, feature
->Feature
, INSTALLSTATE_ABSENT
);
4380 return ERROR_SUCCESS
;
4383 static UINT
event_add_source( msi_dialog
*dialog
, const WCHAR
*argument
)
4385 MSIFEATURE
*feature
;
4387 LIST_FOR_EACH_ENTRY( feature
, &dialog
->package
->features
, MSIFEATURE
, entry
)
4389 if (!wcscmp( argument
, feature
->Feature
) || !wcscmp( argument
, L
"ALL" ))
4391 if (feature
->ActionRequest
!= INSTALLSTATE_SOURCE
)
4392 msi_set_property( dialog
->package
->db
, L
"Preselected", L
"1", -1 );
4393 MSI_SetFeatureStateW( dialog
->package
, feature
->Feature
, INSTALLSTATE_SOURCE
);
4396 return ERROR_SUCCESS
;
4399 void msi_event_fire( MSIPACKAGE
*package
, const WCHAR
*event
, MSIRECORD
*rec
)
4401 struct subscriber
*sub
;
4403 TRACE("firing event %s\n", debugstr_w(event
));
4405 LIST_FOR_EACH_ENTRY( sub
, &package
->subscriptions
, struct subscriber
, entry
)
4407 if (wcsicmp( sub
->event
, event
)) continue;
4408 dialog_handle_event( sub
->dialog
, sub
->control
, sub
->attribute
, rec
);
4412 static UINT
event_set_target_path( msi_dialog
*dialog
, const WCHAR
*argument
)
4414 WCHAR
*path
= msi_dup_property( dialog
->package
->db
, argument
);
4415 MSIRECORD
*rec
= MSI_CreateRecord( 1 );
4416 UINT r
= ERROR_SUCCESS
;
4418 MSI_RecordSetStringW( rec
, 1, path
);
4419 msi_event_fire( dialog
->package
, L
"SelectionPath", rec
);
4422 /* failure to set the path halts the executing of control events */
4423 r
= MSI_SetTargetPathW( dialog
->package
, argument
, path
);
4426 msiobj_release( &rec
->hdr
);
4430 static UINT
event_reset( msi_dialog
*dialog
, const WCHAR
*argument
)
4432 dialog_reset( dialog
);
4433 return ERROR_SUCCESS
;
4436 INT
ACTION_ShowDialog( MSIPACKAGE
*package
, const WCHAR
*dialog
)
4441 if (!TABLE_Exists(package
->db
, L
"Dialog")) return 0;
4443 row
= MSI_CreateRecord(0);
4444 if (!row
) return -1;
4445 MSI_RecordSetStringW(row
, 0, dialog
);
4446 rc
= MSI_ProcessMessage(package
, INSTALLMESSAGE_SHOWDIALOG
, row
);
4447 msiobj_release(&row
->hdr
);
4449 if (rc
== -2) rc
= 0;
4453 MSIRECORD
*row
= MSI_CreateRecord(2);
4454 if (!row
) return -1;
4455 MSI_RecordSetInteger(row
, 1, 2726);
4456 MSI_RecordSetStringW(row
, 2, dialog
);
4457 MSI_ProcessMessage(package
, INSTALLMESSAGE_INFO
, row
);
4459 msiobj_release(&row
->hdr
);
4464 INT
ACTION_DialogBox( MSIPACKAGE
*package
, const WCHAR
*dialog
)
4468 if (package
->next_dialog
) ERR("Already got next dialog... ignoring it\n");
4469 package
->next_dialog
= NULL
;
4471 /* Dialogs are chained through NewDialog, which sets the next_dialog member.
4472 * We fall out of the loop if we reach a modeless dialog, which immediately
4473 * returns IDOK, or an EndDialog event, which returns the value corresponding
4476 r
= event_do_dialog( package
, dialog
, NULL
, TRUE
);
4477 while (package
->next_dialog
)
4479 WCHAR
*name
= package
->next_dialog
;
4481 package
->next_dialog
= NULL
;
4482 r
= event_do_dialog( package
, name
, NULL
, TRUE
);
4488 static UINT
event_set_install_level( msi_dialog
*dialog
, const WCHAR
*argument
)
4490 int level
= wcstol( argument
, NULL
, 10 );
4492 TRACE("setting install level to %d\n", level
);
4493 return MSI_SetInstallLevel( dialog
->package
, level
);
4496 static UINT
event_directory_list_up( msi_dialog
*dialog
, const WCHAR
*argument
)
4498 return dialog_directorylist_up( dialog
);
4501 static UINT
event_directory_list_new( msi_dialog
*dialog
, const WCHAR
*argument
)
4503 return dialog_directorylist_new( dialog
);
4506 static UINT
event_reinstall_mode( msi_dialog
*dialog
, const WCHAR
*argument
)
4508 return msi_set_property( dialog
->package
->db
, L
"REINSTALLMODE", argument
, -1 );
4511 static UINT
event_reinstall( msi_dialog
*dialog
, const WCHAR
*argument
)
4513 return msi_set_property( dialog
->package
->db
, L
"REINSTALL", argument
, -1 );
4516 static UINT
event_validate_product_id( msi_dialog
*dialog
, const WCHAR
*argument
)
4518 return msi_validate_product_id( dialog
->package
);
4521 static const struct control_event control_events
[] =
4523 { L
"EndDialog", pending_event_end_dialog
},
4524 { L
"NewDialog", pending_event_new_dialog
},
4525 { L
"SpawnDialog", pending_event_spawn_dialog
},
4526 { L
"SpawnWaitDialog", event_spawn_wait_dialog
},
4527 { L
"DoAction", event_do_action
},
4528 { L
"AddLocal", event_add_local
},
4529 { L
"Remove", event_remove
},
4530 { L
"AddSource", event_add_source
},
4531 { L
"SetTargetPath", event_set_target_path
},
4532 { L
"Reset", event_reset
},
4533 { L
"SetInstallLevel", event_set_install_level
},
4534 { L
"DirectoryListUp", event_directory_list_up
},
4535 { L
"DirectoryListNew", event_directory_list_new
},
4536 { L
"SelectionBrowse", event_spawn_dialog
},
4537 { L
"ReinstallMode", event_reinstall_mode
},
4538 { L
"Reinstall", event_reinstall
},
4539 { L
"ValidateProductID", event_validate_product_id
},
4543 static UINT
dialog_event_handler( msi_dialog
*dialog
, const WCHAR
*event
, const WCHAR
*argument
)
4547 TRACE("handling event %s\n", debugstr_w(event
));
4549 if (!event
) return ERROR_SUCCESS
;
4551 for (i
= 0; control_events
[i
].event
; i
++)
4553 if (!wcscmp( control_events
[i
].event
, event
))
4554 return control_events
[i
].handler( dialog
, argument
);
4556 FIXME("unhandled event %s arg(%s)\n", debugstr_w(event
), debugstr_w(argument
));
4557 return ERROR_SUCCESS
;