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
22 #define WIN32_NO_STATUS
24 #define COM_NO_WINDOWS_H
27 #define NONAMELESSUNION
28 #define NONAMELESSSTRUCT
33 //#include "winbase.h"
35 //#include "winuser.h"
39 //#include "msidefs.h"
46 #include <msiserver.h>
49 #include <wine/debug.h>
50 #include <wine/unicode.h>
52 WINE_DEFAULT_DEBUG_CHANNEL(msi
);
54 extern HINSTANCE msi_hInstance
;
56 struct msi_control_tag
;
57 typedef struct msi_control_tag msi_control
;
58 typedef UINT (*msi_handler
)( msi_dialog
*, msi_control
*, WPARAM
);
59 typedef void (*msi_update
)( msi_dialog
*, msi_control
* );
60 typedef UINT (*control_event_handler
)( msi_dialog
*, const WCHAR
*, const WCHAR
* );
62 struct msi_control_tag
75 float progress_current
;
77 BOOL progress_backwards
;
82 typedef struct msi_font_tag
94 control_event_handler event_handler
;
102 struct list controls
;
104 LPWSTR control_default
;
105 LPWSTR control_cancel
;
118 typedef UINT (*msi_dialog_control_func
)( msi_dialog
*dialog
, MSIRECORD
*rec
);
119 struct control_handler
121 LPCWSTR control_type
;
122 msi_dialog_control_func func
;
131 } radio_button_group_descr
;
133 static const WCHAR szMsiDialogClass
[] = { 'M','s','i','D','i','a','l','o','g','C','l','o','s','e','C','l','a','s','s',0 };
134 static const WCHAR szMsiHiddenWindow
[] = { 'M','s','i','H','i','d','d','e','n','W','i','n','d','o','w',0 };
135 static const WCHAR szStatic
[] = { 'S','t','a','t','i','c',0 };
136 static const WCHAR szButton
[] = { 'B','U','T','T','O','N', 0 };
137 static const WCHAR szButtonData
[] = { 'M','S','I','D','A','T','A',0 };
138 static const WCHAR szProgress
[] = { 'P','r','o','g','r','e','s','s',0 };
139 static const WCHAR szText
[] = { 'T','e','x','t',0 };
140 static const WCHAR szPushButton
[] = { 'P','u','s','h','B','u','t','t','o','n',0 };
141 static const WCHAR szLine
[] = { 'L','i','n','e',0 };
142 static const WCHAR szBitmap
[] = { 'B','i','t','m','a','p',0 };
143 static const WCHAR szCheckBox
[] = { 'C','h','e','c','k','B','o','x',0 };
144 static const WCHAR szScrollableText
[] = { 'S','c','r','o','l','l','a','b','l','e','T','e','x','t',0 };
145 static const WCHAR szComboBox
[] = { 'C','o','m','b','o','B','o','x',0 };
146 static const WCHAR szEdit
[] = { 'E','d','i','t',0 };
147 static const WCHAR szMaskedEdit
[] = { 'M','a','s','k','e','d','E','d','i','t',0 };
148 static const WCHAR szPathEdit
[] = { 'P','a','t','h','E','d','i','t',0 };
149 static const WCHAR szProgressBar
[] = { 'P','r','o','g','r','e','s','s','B','a','r',0 };
150 static const WCHAR szSetProgress
[] = { 'S','e','t','P','r','o','g','r','e','s','s',0 };
151 static const WCHAR szRadioButtonGroup
[] = { 'R','a','d','i','o','B','u','t','t','o','n','G','r','o','u','p',0 };
152 static const WCHAR szIcon
[] = { 'I','c','o','n',0 };
153 static const WCHAR szSelectionTree
[] = { 'S','e','l','e','c','t','i','o','n','T','r','e','e',0 };
154 static const WCHAR szGroupBox
[] = { 'G','r','o','u','p','B','o','x',0 };
155 static const WCHAR szListBox
[] = { 'L','i','s','t','B','o','x',0 };
156 static const WCHAR szDirectoryCombo
[] = { 'D','i','r','e','c','t','o','r','y','C','o','m','b','o',0 };
157 static const WCHAR szDirectoryList
[] = { 'D','i','r','e','c','t','o','r','y','L','i','s','t',0 };
158 static const WCHAR szVolumeCostList
[] = { 'V','o','l','u','m','e','C','o','s','t','L','i','s','t',0 };
159 static const WCHAR szVolumeSelectCombo
[] = { 'V','o','l','u','m','e','S','e','l','e','c','t','C','o','m','b','o',0 };
160 static const WCHAR szSelectionDescription
[] = {'S','e','l','e','c','t','i','o','n','D','e','s','c','r','i','p','t','i','o','n',0};
161 static const WCHAR szSelectionPath
[] = {'S','e','l','e','c','t','i','o','n','P','a','t','h',0};
162 static const WCHAR szProperty
[] = {'P','r','o','p','e','r','t','y',0};
163 static const WCHAR szHyperLink
[] = {'H','y','p','e','r','L','i','n','k',0};
165 /* dialog sequencing */
167 #define WM_MSI_DIALOG_CREATE (WM_USER+0x100)
168 #define WM_MSI_DIALOG_DESTROY (WM_USER+0x101)
170 #define USER_INSTALLSTATE_ALL 0x1000
172 static DWORD uiThreadId
;
173 static HWND hMsiHiddenWindow
;
175 static LPWSTR
msi_get_window_text( HWND hwnd
)
181 buf
= msi_alloc( sz
*sizeof(WCHAR
) );
184 r
= GetWindowTextW( hwnd
, buf
, sz
);
188 buf
= msi_realloc( buf
, sz
*sizeof(WCHAR
) );
194 static INT
msi_dialog_scale_unit( msi_dialog
*dialog
, INT val
)
196 return MulDiv( val
, dialog
->scale
, 12 );
199 static msi_control
*msi_dialog_find_control( msi_dialog
*dialog
, LPCWSTR name
)
201 msi_control
*control
;
207 LIST_FOR_EACH_ENTRY( control
, &dialog
->controls
, msi_control
, entry
)
208 if( !strcmpW( control
->name
, name
) ) /* FIXME: case sensitive? */
213 static msi_control
*msi_dialog_find_control_by_type( msi_dialog
*dialog
, LPCWSTR type
)
215 msi_control
*control
;
221 LIST_FOR_EACH_ENTRY( control
, &dialog
->controls
, msi_control
, entry
)
222 if( !strcmpW( control
->type
, type
) ) /* FIXME: case sensitive? */
227 static msi_control
*msi_dialog_find_control_by_hwnd( msi_dialog
*dialog
, HWND hwnd
)
229 msi_control
*control
;
233 LIST_FOR_EACH_ENTRY( control
, &dialog
->controls
, msi_control
, entry
)
234 if( hwnd
== control
->hwnd
)
239 static LPWSTR
msi_get_deformatted_field( MSIPACKAGE
*package
, MSIRECORD
*rec
, int field
)
241 LPCWSTR str
= MSI_RecordGetString( rec
, field
);
245 deformat_string( package
, str
, &ret
);
249 static LPWSTR
msi_dialog_dup_property( msi_dialog
*dialog
, LPCWSTR property
, BOOL indirect
)
257 prop
= msi_dup_property( dialog
->package
->db
, property
);
260 prop
= strdupW( property
);
266 * msi_dialog_get_style
268 * Extract the {\style} string from the front of the text to display and
269 * update the pointer. Only the last style in a list is applied.
271 static LPWSTR
msi_dialog_get_style( LPCWSTR p
, LPCWSTR
*rest
)
282 while ((first
= strchrW( p
, '{' )) && (q
= strchrW( first
+ 1, '}' )))
285 if( *p
!= '\\' && *p
!= '&' )
288 /* little bit of sanity checking to stop us getting confused with RTF */
289 for( i
=++p
; i
<q
; i
++ )
290 if( *i
== '}' || *i
== '\\' )
300 ret
= msi_alloc( len
*sizeof(WCHAR
) );
303 memcpy( ret
, p
, len
*sizeof(WCHAR
) );
308 static UINT
msi_dialog_add_font( MSIRECORD
*rec
, LPVOID param
)
310 msi_dialog
*dialog
= param
;
317 /* create a font and add it to the list */
318 name
= MSI_RecordGetString( rec
, 1 );
319 font
= msi_alloc( FIELD_OFFSET( msi_font
, name
[strlenW( name
) + 1] ));
320 strcpyW( font
->name
, name
);
321 list_add_head( &dialog
->fonts
, &font
->entry
);
323 font
->color
= MSI_RecordGetInteger( rec
, 4 );
325 memset( &lf
, 0, sizeof lf
);
326 face
= MSI_RecordGetString( rec
, 2 );
327 lf
.lfHeight
= MSI_RecordGetInteger( rec
, 3 );
328 style
= MSI_RecordGetInteger( rec
, 5 );
329 if( style
& msidbTextStyleStyleBitsBold
)
330 lf
.lfWeight
= FW_BOLD
;
331 if( style
& msidbTextStyleStyleBitsItalic
)
333 if( style
& msidbTextStyleStyleBitsUnderline
)
334 lf
.lfUnderline
= TRUE
;
335 if( style
& msidbTextStyleStyleBitsStrike
)
336 lf
.lfStrikeOut
= TRUE
;
337 lstrcpynW( lf
.lfFaceName
, face
, LF_FACESIZE
);
339 /* adjust the height */
340 hdc
= GetDC( dialog
->hwnd
);
343 lf
.lfHeight
= -MulDiv(lf
.lfHeight
, GetDeviceCaps(hdc
, LOGPIXELSY
), 72);
344 ReleaseDC( dialog
->hwnd
, hdc
);
347 font
->hfont
= CreateFontIndirectW( &lf
);
349 TRACE("Adding font style %s\n", debugstr_w(font
->name
) );
351 return ERROR_SUCCESS
;
354 static msi_font
*msi_dialog_find_font( msi_dialog
*dialog
, LPCWSTR name
)
356 msi_font
*font
= NULL
;
358 LIST_FOR_EACH_ENTRY( font
, &dialog
->fonts
, msi_font
, entry
)
359 if( !strcmpW( font
->name
, name
) ) /* FIXME: case sensitive? */
365 static UINT
msi_dialog_set_font( msi_dialog
*dialog
, HWND hwnd
, LPCWSTR name
)
369 font
= msi_dialog_find_font( dialog
, name
);
371 SendMessageW( hwnd
, WM_SETFONT
, (WPARAM
) font
->hfont
, TRUE
);
373 ERR("No font entry for %s\n", debugstr_w(name
));
374 return ERROR_SUCCESS
;
377 static UINT
msi_dialog_build_font_list( msi_dialog
*dialog
)
379 static const WCHAR query
[] = {
380 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
381 '`','T','e','x','t','S','t','y','l','e','`',0};
385 TRACE("dialog %p\n", dialog
);
387 r
= MSI_OpenQuery( dialog
->package
->db
, &view
, query
);
388 if( r
!= ERROR_SUCCESS
)
391 r
= MSI_IterateRecords( view
, NULL
, msi_dialog_add_font
, dialog
);
392 msiobj_release( &view
->hdr
);
396 static void msi_destroy_control( msi_control
*t
)
398 list_remove( &t
->entry
);
399 /* leave dialog->hwnd - destroying parent destroys child windows */
400 msi_free( t
->property
);
401 msi_free( t
->value
);
403 DeleteObject( t
->hBitmap
);
405 DestroyIcon( t
->hIcon
);
406 msi_free( t
->tabnext
);
409 FreeLibrary( t
->hDll
);
413 static msi_control
*dialog_create_window( msi_dialog
*dialog
, MSIRECORD
*rec
, DWORD exstyle
,
414 const WCHAR
*szCls
, const WCHAR
*name
, const WCHAR
*text
,
415 DWORD style
, HWND parent
)
417 DWORD x
, y
, width
, height
;
418 LPWSTR font
= NULL
, title_font
= NULL
;
419 LPCWSTR title
= NULL
;
420 msi_control
*control
;
424 control
= msi_alloc( FIELD_OFFSET( msi_control
, name
[strlenW( name
) + 1] ));
428 strcpyW( control
->name
, name
);
429 list_add_tail( &dialog
->controls
, &control
->entry
);
430 control
->handler
= NULL
;
431 control
->update
= NULL
;
432 control
->property
= NULL
;
433 control
->value
= NULL
;
434 control
->hBitmap
= NULL
;
435 control
->hIcon
= NULL
;
436 control
->hDll
= NULL
;
437 control
->tabnext
= strdupW( MSI_RecordGetString( rec
, 11) );
438 control
->type
= strdupW( MSI_RecordGetString( rec
, 3 ) );
439 control
->progress_current
= 0;
440 control
->progress_max
= 100;
441 control
->progress_backwards
= FALSE
;
443 x
= MSI_RecordGetInteger( rec
, 4 );
444 y
= MSI_RecordGetInteger( rec
, 5 );
445 width
= MSI_RecordGetInteger( rec
, 6 );
446 height
= MSI_RecordGetInteger( rec
, 7 );
448 x
= msi_dialog_scale_unit( dialog
, x
);
449 y
= msi_dialog_scale_unit( dialog
, y
);
450 width
= msi_dialog_scale_unit( dialog
, width
);
451 height
= msi_dialog_scale_unit( dialog
, height
);
455 deformat_string( dialog
->package
, text
, &title_font
);
456 font
= msi_dialog_get_style( title_font
, &title
);
459 control
->hwnd
= CreateWindowExW( exstyle
, szCls
, title
, style
,
460 x
, y
, width
, height
, parent
, NULL
, NULL
, NULL
);
462 TRACE("Dialog %s control %s hwnd %p\n",
463 debugstr_w(dialog
->name
), debugstr_w(text
), control
->hwnd
);
465 msi_dialog_set_font( dialog
, control
->hwnd
,
466 font
? font
: dialog
->default_font
);
468 msi_free( title_font
);
474 static LPWSTR
msi_dialog_get_uitext( msi_dialog
*dialog
, LPCWSTR key
)
479 static const WCHAR query
[] = {
480 's','e','l','e','c','t',' ','*',' ',
481 'f','r','o','m',' ','`','U','I','T','e','x','t','`',' ',
482 'w','h','e','r','e',' ','`','K','e','y','`',' ','=',' ','\'','%','s','\'',0
485 rec
= MSI_QueryGetRecord( dialog
->package
->db
, query
, key
);
486 if (!rec
) return NULL
;
487 text
= strdupW( MSI_RecordGetString( rec
, 2 ) );
488 msiobj_release( &rec
->hdr
);
492 static MSIRECORD
*msi_get_binary_record( MSIDATABASE
*db
, LPCWSTR name
)
494 static const WCHAR query
[] = {
495 's','e','l','e','c','t',' ','*',' ',
496 'f','r','o','m',' ','B','i','n','a','r','y',' ',
497 'w','h','e','r','e',' ',
498 '`','N','a','m','e','`',' ','=',' ','\'','%','s','\'',0
501 return MSI_QueryGetRecord( db
, query
, name
);
504 static LPWSTR
msi_create_tmp_path(void)
510 r
= GetTempPathW( MAX_PATH
, tmp
);
513 len
= lstrlenW( tmp
) + 20;
514 path
= msi_alloc( len
* sizeof (WCHAR
) );
517 r
= GetTempFileNameW( tmp
, szMsi
, 0, path
);
527 static HANDLE
msi_load_image( MSIDATABASE
*db
, LPCWSTR name
, UINT type
,
528 UINT cx
, UINT cy
, UINT flags
)
530 MSIRECORD
*rec
= NULL
;
531 HANDLE himage
= NULL
;
535 TRACE("%p %s %u %u %08x\n", db
, debugstr_w(name
), cx
, cy
, flags
);
537 tmp
= msi_create_tmp_path();
541 rec
= msi_get_binary_record( db
, name
);
544 r
= MSI_RecordStreamToFile( rec
, 2, tmp
);
545 if( r
== ERROR_SUCCESS
)
547 himage
= LoadImageW( 0, tmp
, type
, cx
, cy
, flags
);
549 msiobj_release( &rec
->hdr
);
557 static HICON
msi_load_icon( MSIDATABASE
*db
, LPCWSTR text
, UINT attributes
)
559 DWORD cx
= 0, cy
= 0, flags
;
561 flags
= LR_LOADFROMFILE
| LR_DEFAULTSIZE
;
562 if( attributes
& msidbControlAttributesFixedSize
)
564 flags
&= ~LR_DEFAULTSIZE
;
565 if( attributes
& msidbControlAttributesIconSize16
)
570 if( attributes
& msidbControlAttributesIconSize32
)
575 /* msidbControlAttributesIconSize48 handled by above logic */
577 return msi_load_image( db
, text
, IMAGE_ICON
, cx
, cy
, flags
);
580 static void msi_dialog_update_controls( msi_dialog
*dialog
, LPCWSTR property
)
582 msi_control
*control
;
584 LIST_FOR_EACH_ENTRY( control
, &dialog
->controls
, msi_control
, entry
)
586 if ( control
->property
&& !strcmpW( control
->property
, property
) && control
->update
)
587 control
->update( dialog
, control
);
591 static void msi_dialog_set_property( MSIPACKAGE
*package
, LPCWSTR property
, LPCWSTR value
)
593 UINT r
= msi_set_property( package
->db
, property
, value
, -1 );
594 if (r
== ERROR_SUCCESS
&& !strcmpW( property
, szSourceDir
))
595 msi_reset_folders( package
, TRUE
);
598 static MSIFEATURE
*msi_seltree_feature_from_item( HWND hwnd
, HTREEITEM hItem
)
602 /* get the feature from the item */
603 memset( &tvi
, 0, sizeof tvi
);
605 tvi
.mask
= TVIF_PARAM
| TVIF_HANDLE
;
606 SendMessageW( hwnd
, TVM_GETITEMW
, 0, (LPARAM
)&tvi
);
607 return (MSIFEATURE
*)tvi
.lParam
;
610 struct msi_selection_tree_info
618 static MSIFEATURE
*msi_seltree_get_selected_feature( msi_control
*control
)
620 struct msi_selection_tree_info
*info
= GetPropW( control
->hwnd
, szButtonData
);
621 return msi_seltree_feature_from_item( control
->hwnd
, info
->selected
);
624 static void dialog_handle_event( msi_dialog
*dialog
, const WCHAR
*control
,
625 const WCHAR
*attribute
, MSIRECORD
*rec
)
629 ctrl
= msi_dialog_find_control( dialog
, control
);
632 if( !strcmpW( attribute
, szText
) )
634 const WCHAR
*font_text
, *text
= NULL
;
635 WCHAR
*font
, *text_fmt
= NULL
;
637 font_text
= MSI_RecordGetString( rec
, 1 );
638 font
= msi_dialog_get_style( font_text
, &text
);
639 deformat_string( dialog
->package
, text
, &text_fmt
);
640 if (text_fmt
) text
= text_fmt
;
643 SetWindowTextW( ctrl
->hwnd
, text
);
646 msi_free( text_fmt
);
647 msi_dialog_check_messages( NULL
);
649 else if( !strcmpW( attribute
, szProgress
) )
651 DWORD func
, val1
, val2
, units
;
653 func
= MSI_RecordGetInteger( rec
, 1 );
654 val1
= MSI_RecordGetInteger( rec
, 2 );
655 val2
= MSI_RecordGetInteger( rec
, 3 );
657 TRACE("progress: func %u val1 %u val2 %u\n", func
, val1
, val2
);
663 SendMessageW( ctrl
->hwnd
, PBM_SETRANGE
, 0, MAKELPARAM(0,100) );
666 ctrl
->progress_max
= units
? units
: 100;
667 ctrl
->progress_current
= units
;
668 ctrl
->progress_backwards
= TRUE
;
669 SendMessageW( ctrl
->hwnd
, PBM_SETPOS
, 100, 0 );
673 ctrl
->progress_max
= units
? units
: 100;
674 ctrl
->progress_current
= 0;
675 ctrl
->progress_backwards
= FALSE
;
676 SendMessageW( ctrl
->hwnd
, PBM_SETPOS
, 0, 0 );
679 case 1: /* action data increment */
680 if (val2
) dialog
->package
->action_progress_increment
= val1
;
681 else dialog
->package
->action_progress_increment
= 0;
684 if (ctrl
->progress_backwards
)
686 if (units
>= ctrl
->progress_current
) ctrl
->progress_current
-= units
;
687 else ctrl
->progress_current
= 0;
691 if (ctrl
->progress_current
+ units
< ctrl
->progress_max
) ctrl
->progress_current
+= units
;
692 else ctrl
->progress_current
= ctrl
->progress_max
;
694 SendMessageW( ctrl
->hwnd
, PBM_SETPOS
, MulDiv(100, ctrl
->progress_current
, ctrl
->progress_max
), 0 );
697 ctrl
->progress_max
+= units
;
700 FIXME("Unknown progress message %u\n", func
);
704 else if ( !strcmpW( attribute
, szProperty
) )
706 MSIFEATURE
*feature
= msi_seltree_get_selected_feature( ctrl
);
707 if (feature
) msi_dialog_set_property( dialog
->package
, ctrl
->property
, feature
->Directory
);
709 else if ( !strcmpW( attribute
, szSelectionPath
) )
711 BOOL indirect
= ctrl
->attributes
& msidbControlAttributesIndirect
;
712 LPWSTR path
= msi_dialog_dup_property( dialog
, ctrl
->property
, indirect
);
714 SetWindowTextW( ctrl
->hwnd
, path
);
719 FIXME("Attribute %s not being set\n", debugstr_w(attribute
));
724 static void event_subscribe( msi_dialog
*dialog
, const WCHAR
*event
, const WCHAR
*control
, const WCHAR
*attribute
)
726 struct subscriber
*sub
;
728 TRACE("event %s control %s attribute %s\n", debugstr_w(event
), debugstr_w(control
), debugstr_w(attribute
));
730 LIST_FOR_EACH_ENTRY( sub
, &dialog
->package
->subscriptions
, struct subscriber
, entry
)
732 if (!strcmpiW( sub
->event
, event
) &&
733 !strcmpiW( sub
->control
, control
) &&
734 !strcmpiW( sub
->attribute
, attribute
))
736 TRACE("already subscribed\n");
740 if (!(sub
= msi_alloc( sizeof(*sub
) ))) return;
741 sub
->dialog
= dialog
;
742 sub
->event
= strdupW( event
);
743 sub
->control
= strdupW( control
);
744 sub
->attribute
= strdupW( attribute
);
745 list_add_tail( &dialog
->package
->subscriptions
, &sub
->entry
);
748 struct dialog_control
751 const WCHAR
*control
;
754 static UINT
map_event( MSIRECORD
*row
, void *param
)
756 struct dialog_control
*dc
= param
;
757 const WCHAR
*event
= MSI_RecordGetString( row
, 3 );
758 const WCHAR
*attribute
= MSI_RecordGetString( row
, 4 );
760 event_subscribe( dc
->dialog
, event
, dc
->control
, attribute
);
761 return ERROR_SUCCESS
;
764 static void dialog_map_events( msi_dialog
*dialog
, const WCHAR
*control
)
766 static const WCHAR queryW
[] =
767 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
768 '`','E','v','e','n','t','M','a','p','p','i','n','g','`',' ',
769 'W','H','E','R','E',' ','`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',' ',
770 'A','N','D',' ','`','C','o','n','t','r','o','l','_','`',' ','=',' ','\'','%','s','\'',0};
772 struct dialog_control dialog_control
=
778 if (!MSI_OpenQuery( dialog
->package
->db
, &view
, queryW
, dialog
->name
, control
))
780 MSI_IterateRecords( view
, NULL
, map_event
, &dialog_control
);
781 msiobj_release( &view
->hdr
);
785 /* everything except radio buttons */
786 static msi_control
*msi_dialog_add_control( msi_dialog
*dialog
,
787 MSIRECORD
*rec
, LPCWSTR szCls
, DWORD style
)
793 name
= MSI_RecordGetString( rec
, 2 );
794 attributes
= MSI_RecordGetInteger( rec
, 8 );
795 text
= MSI_RecordGetString( rec
, 10 );
797 TRACE("%s, %s, %08x, %s, %08x\n", debugstr_w(szCls
), debugstr_w(name
),
798 attributes
, debugstr_w(text
), style
);
800 if( attributes
& msidbControlAttributesVisible
)
802 if( ~attributes
& msidbControlAttributesEnabled
)
803 style
|= WS_DISABLED
;
804 if( attributes
& msidbControlAttributesSunken
)
805 exstyle
|= WS_EX_CLIENTEDGE
;
807 dialog_map_events( dialog
, name
);
809 return dialog_create_window( dialog
, rec
, exstyle
, szCls
, name
, text
, style
, dialog
->hwnd
);
820 * we don't erase our own background,
821 * so we have to make sure that the parent window redraws first
823 static void msi_text_on_settext( HWND hWnd
)
828 hParent
= GetParent( hWnd
);
829 GetWindowRect( hWnd
, &rc
);
830 MapWindowPoints( NULL
, hParent
, (LPPOINT
) &rc
, 2 );
831 InvalidateRect( hParent
, &rc
, TRUE
);
834 static LRESULT WINAPI
835 MSIText_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
837 struct msi_text_info
*info
;
840 TRACE("%p %04x %08lx %08lx\n", hWnd
, msg
, wParam
, lParam
);
842 info
= GetPropW(hWnd
, szButtonData
);
844 if( msg
== WM_CTLCOLORSTATIC
&&
845 ( info
->attributes
& msidbControlAttributesTransparent
) )
847 SetBkMode( (HDC
)wParam
, TRANSPARENT
);
848 return (LRESULT
) GetStockObject(NULL_BRUSH
);
851 r
= CallWindowProcW(info
->oldproc
, hWnd
, msg
, wParam
, lParam
);
853 SetTextColor( (HDC
)wParam
, info
->font
->color
);
858 msi_text_on_settext( hWnd
);
862 RemovePropW( hWnd
, szButtonData
);
869 static UINT
msi_dialog_text_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
871 msi_control
*control
;
872 struct msi_text_info
*info
;
873 LPCWSTR text
, ptr
, prop
, control_name
;
876 TRACE("%p %p\n", dialog
, rec
);
878 control
= msi_dialog_add_control( dialog
, rec
, szStatic
, SS_LEFT
| WS_GROUP
);
880 return ERROR_FUNCTION_FAILED
;
882 info
= msi_alloc( sizeof *info
);
884 return ERROR_SUCCESS
;
886 control_name
= MSI_RecordGetString( rec
, 2 );
887 control
->attributes
= MSI_RecordGetInteger( rec
, 8 );
888 prop
= MSI_RecordGetString( rec
, 9 );
889 control
->property
= msi_dialog_dup_property( dialog
, prop
, FALSE
);
891 text
= MSI_RecordGetString( rec
, 10 );
892 font_name
= msi_dialog_get_style( text
, &ptr
);
893 info
->font
= ( font_name
) ? msi_dialog_find_font( dialog
, font_name
) : NULL
;
894 msi_free( font_name
);
896 info
->attributes
= MSI_RecordGetInteger( rec
, 8 );
897 if( info
->attributes
& msidbControlAttributesTransparent
)
898 SetWindowLongPtrW( control
->hwnd
, GWL_EXSTYLE
, WS_EX_TRANSPARENT
);
900 info
->oldproc
= (WNDPROC
) SetWindowLongPtrW( control
->hwnd
, GWLP_WNDPROC
,
901 (LONG_PTR
)MSIText_WndProc
);
902 SetPropW( control
->hwnd
, szButtonData
, info
);
904 event_subscribe( dialog
, szSelectionPath
, control_name
, szSelectionPath
);
905 return ERROR_SUCCESS
;
908 /* strip any leading text style label from text field */
909 static WCHAR
*msi_get_binary_name( MSIPACKAGE
*package
, MSIRECORD
*rec
)
913 text
= msi_get_deformatted_field( package
, rec
, 10 );
918 while (*p
&& *p
!= '{') p
++;
919 if (!*p
++) return text
;
921 while (*p
&& *p
!= '}') p
++;
922 if (!*p
++) return text
;
929 static UINT
msi_dialog_set_property_event( msi_dialog
*dialog
, LPCWSTR event
, LPCWSTR arg
)
931 static const WCHAR szNullArg
[] = {'{','}',0};
932 LPWSTR p
, prop
, arg_fmt
= NULL
;
935 len
= strlenW( event
);
936 prop
= msi_alloc( len
* sizeof(WCHAR
) );
937 strcpyW( prop
, &event
[1] );
938 p
= strchrW( prop
, ']' );
939 if (p
&& (p
[1] == 0 || p
[1] == ' '))
942 if (strcmpW( szNullArg
, arg
))
943 deformat_string( dialog
->package
, arg
, &arg_fmt
);
944 msi_dialog_set_property( dialog
->package
, prop
, arg_fmt
);
945 msi_dialog_update_controls( dialog
, prop
);
948 else ERR("Badly formatted property string - what happens?\n");
950 return ERROR_SUCCESS
;
953 static UINT
msi_dialog_send_event( msi_dialog
*dialog
, LPCWSTR event
, LPCWSTR arg
)
955 LPWSTR event_fmt
= NULL
, arg_fmt
= NULL
;
957 TRACE("Sending control event %s %s\n", debugstr_w(event
), debugstr_w(arg
));
959 deformat_string( dialog
->package
, event
, &event_fmt
);
960 deformat_string( dialog
->package
, arg
, &arg_fmt
);
962 dialog
->event_handler( dialog
, event_fmt
, arg_fmt
);
964 msi_free( event_fmt
);
967 return ERROR_SUCCESS
;
970 static UINT
msi_dialog_control_event( MSIRECORD
*rec
, LPVOID param
)
972 msi_dialog
*dialog
= param
;
973 LPCWSTR condition
, event
, arg
;
976 condition
= MSI_RecordGetString( rec
, 5 );
977 r
= MSI_EvaluateConditionW( dialog
->package
, condition
);
978 if (r
== MSICONDITION_TRUE
|| r
== MSICONDITION_NONE
)
980 event
= MSI_RecordGetString( rec
, 3 );
981 arg
= MSI_RecordGetString( rec
, 4 );
983 msi_dialog_set_property_event( dialog
, event
, arg
);
985 msi_dialog_send_event( dialog
, event
, arg
);
987 return ERROR_SUCCESS
;
990 static UINT
msi_dialog_button_handler( msi_dialog
*dialog
, msi_control
*control
, WPARAM param
)
992 static const WCHAR query
[] = {
993 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
994 'C','o','n','t','r','o','l','E','v','e','n','t',' ','W','H','E','R','E',' ',
995 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',' ','A','N','D',' ',
996 '`','C','o','n','t','r','o','l','_','`',' ','=',' ','\'','%','s','\'',' ',
997 'O','R','D','E','R',' ','B','Y',' ','`','O','r','d','e','r','i','n','g','`',0};
1001 if (HIWORD(param
) != BN_CLICKED
)
1002 return ERROR_SUCCESS
;
1004 r
= MSI_OpenQuery( dialog
->package
->db
, &view
, query
, dialog
->name
, control
->name
);
1005 if (r
!= ERROR_SUCCESS
)
1007 ERR("query failed\n");
1008 return ERROR_SUCCESS
;
1010 r
= MSI_IterateRecords( view
, 0, msi_dialog_control_event
, dialog
);
1011 msiobj_release( &view
->hdr
);
1015 static UINT
msi_dialog_button_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1017 msi_control
*control
;
1018 UINT attributes
, style
;
1020 TRACE("%p %p\n", dialog
, rec
);
1023 attributes
= MSI_RecordGetInteger( rec
, 8 );
1024 if( attributes
& msidbControlAttributesIcon
)
1027 control
= msi_dialog_add_control( dialog
, rec
, szButton
, style
);
1029 return ERROR_FUNCTION_FAILED
;
1031 control
->handler
= msi_dialog_button_handler
;
1033 if (attributes
& msidbControlAttributesIcon
)
1036 LPWSTR name
= msi_get_binary_name( dialog
->package
, rec
);
1037 control
->hIcon
= msi_load_icon( dialog
->package
->db
, name
, attributes
);
1040 SendMessageW( control
->hwnd
, BM_SETIMAGE
, IMAGE_ICON
, (LPARAM
) control
->hIcon
);
1043 ERR("Failed to load icon %s\n", debugstr_w(name
));
1047 return ERROR_SUCCESS
;
1050 static LPWSTR
msi_get_checkbox_value( msi_dialog
*dialog
, LPCWSTR prop
)
1052 static const WCHAR query
[] = {
1053 'S','E','L','E','C','T',' ','*',' ',
1054 'F','R','O','M',' ','`','C','h','e','c','k','B','o','x','`',' ',
1055 'W','H','E','R','E',' ',
1056 '`','P','r','o','p','e','r','t','y','`',' ','=',' ',
1059 MSIRECORD
*rec
= NULL
;
1062 /* find if there is a value associated with the checkbox */
1063 rec
= MSI_QueryGetRecord( dialog
->package
->db
, query
, prop
);
1067 ret
= msi_get_deformatted_field( dialog
->package
, rec
, 2 );
1068 if( ret
&& !ret
[0] )
1073 msiobj_release( &rec
->hdr
);
1077 ret
= msi_dup_property( dialog
->package
->db
, prop
);
1078 if( ret
&& !ret
[0] )
1087 static UINT
msi_dialog_get_checkbox_state( msi_dialog
*dialog
, msi_control
*control
)
1089 WCHAR state
[2] = {0};
1092 msi_get_property( dialog
->package
->db
, control
->property
, state
, &sz
);
1093 return state
[0] ? 1 : 0;
1096 static void msi_dialog_set_checkbox_state( msi_dialog
*dialog
, msi_control
*control
, UINT state
)
1098 static const WCHAR szState
[] = {'1',0};
1101 /* if uncheck then the property is set to NULL */
1104 msi_dialog_set_property( dialog
->package
, control
->property
, NULL
);
1108 /* check for a custom state */
1109 if (control
->value
&& control
->value
[0])
1110 val
= control
->value
;
1114 msi_dialog_set_property( dialog
->package
, control
->property
, val
);
1117 static void msi_dialog_checkbox_sync_state( msi_dialog
*dialog
, msi_control
*control
)
1119 UINT state
= msi_dialog_get_checkbox_state( dialog
, control
);
1120 SendMessageW( control
->hwnd
, BM_SETCHECK
, state
? BST_CHECKED
: BST_UNCHECKED
, 0 );
1123 static UINT
msi_dialog_checkbox_handler( msi_dialog
*dialog
, msi_control
*control
, WPARAM param
)
1127 if (HIWORD(param
) != BN_CLICKED
)
1128 return ERROR_SUCCESS
;
1130 TRACE("clicked checkbox %s, set %s\n", debugstr_w(control
->name
), debugstr_w(control
->property
));
1132 state
= msi_dialog_get_checkbox_state( dialog
, control
);
1133 state
= state
? 0 : 1;
1134 msi_dialog_set_checkbox_state( dialog
, control
, state
);
1135 msi_dialog_checkbox_sync_state( dialog
, control
);
1137 return msi_dialog_button_handler( dialog
, control
, param
);
1140 static UINT
msi_dialog_checkbox_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1142 msi_control
*control
;
1145 TRACE("%p %p\n", dialog
, rec
);
1147 control
= msi_dialog_add_control( dialog
, rec
, szButton
, BS_CHECKBOX
| BS_MULTILINE
| WS_TABSTOP
);
1148 control
->handler
= msi_dialog_checkbox_handler
;
1149 control
->update
= msi_dialog_checkbox_sync_state
;
1150 prop
= MSI_RecordGetString( rec
, 9 );
1153 control
->property
= strdupW( prop
);
1154 control
->value
= msi_get_checkbox_value( dialog
, prop
);
1155 TRACE("control %s value %s\n", debugstr_w(control
->property
), debugstr_w(control
->value
));
1157 msi_dialog_checkbox_sync_state( dialog
, control
);
1158 return ERROR_SUCCESS
;
1161 static UINT
msi_dialog_line_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1165 DWORD style
, exstyle
= 0;
1166 DWORD x
, y
, width
, height
;
1167 msi_control
*control
;
1169 TRACE("%p %p\n", dialog
, rec
);
1171 style
= WS_CHILD
| SS_ETCHEDHORZ
| SS_SUNKEN
;
1173 name
= MSI_RecordGetString( rec
, 2 );
1174 attributes
= MSI_RecordGetInteger( rec
, 8 );
1176 if( attributes
& msidbControlAttributesVisible
)
1177 style
|= WS_VISIBLE
;
1178 if( ~attributes
& msidbControlAttributesEnabled
)
1179 style
|= WS_DISABLED
;
1180 if( attributes
& msidbControlAttributesSunken
)
1181 exstyle
|= WS_EX_CLIENTEDGE
;
1183 dialog_map_events( dialog
, name
);
1185 control
= msi_alloc( FIELD_OFFSET(msi_control
, name
[strlenW( name
) + 1] ));
1187 return ERROR_OUTOFMEMORY
;
1189 strcpyW( control
->name
, name
);
1190 list_add_head( &dialog
->controls
, &control
->entry
);
1191 control
->handler
= NULL
;
1192 control
->property
= NULL
;
1193 control
->value
= NULL
;
1194 control
->hBitmap
= NULL
;
1195 control
->hIcon
= NULL
;
1196 control
->hDll
= NULL
;
1197 control
->tabnext
= strdupW( MSI_RecordGetString( rec
, 11) );
1198 control
->type
= strdupW( MSI_RecordGetString( rec
, 3 ) );
1199 control
->progress_current
= 0;
1200 control
->progress_max
= 100;
1201 control
->progress_backwards
= FALSE
;
1203 x
= MSI_RecordGetInteger( rec
, 4 );
1204 y
= MSI_RecordGetInteger( rec
, 5 );
1205 width
= MSI_RecordGetInteger( rec
, 6 );
1207 x
= msi_dialog_scale_unit( dialog
, x
);
1208 y
= msi_dialog_scale_unit( dialog
, y
);
1209 width
= msi_dialog_scale_unit( dialog
, width
);
1210 height
= 2; /* line is exactly 2 units in height */
1212 control
->hwnd
= CreateWindowExW( exstyle
, szStatic
, NULL
, style
,
1213 x
, y
, width
, height
, dialog
->hwnd
, NULL
, NULL
, NULL
);
1215 TRACE("Dialog %s control %s hwnd %p\n",
1216 debugstr_w(dialog
->name
), debugstr_w(name
), control
->hwnd
);
1218 return ERROR_SUCCESS
;
1221 /******************** Scroll Text ********************************************/
1223 struct msi_scrolltext_info
1226 msi_control
*control
;
1230 static LRESULT WINAPI
1231 MSIScrollText_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1233 struct msi_scrolltext_info
*info
;
1236 TRACE("%p %04x %08lx %08lx\n", hWnd
, msg
, wParam
, lParam
);
1238 info
= GetPropW( hWnd
, szButtonData
);
1240 r
= CallWindowProcW( info
->oldproc
, hWnd
, msg
, wParam
, lParam
);
1245 return DLGC_WANTARROWS
;
1248 RemovePropW( hWnd
, szButtonData
);
1251 /* native MSI sets a wait cursor here */
1252 msi_dialog_button_handler( info
->dialog
, info
->control
, BN_CLICKED
);
1258 struct msi_streamin_info
1265 static DWORD CALLBACK
1266 msi_richedit_stream_in( DWORD_PTR arg
, LPBYTE buffer
, LONG count
, LONG
*pcb
)
1268 struct msi_streamin_info
*info
= (struct msi_streamin_info
*) arg
;
1270 if( (count
+ info
->offset
) > info
->length
)
1271 count
= info
->length
- info
->offset
;
1272 memcpy( buffer
, &info
->string
[ info
->offset
], count
);
1274 info
->offset
+= count
;
1276 TRACE("%d/%d\n", info
->offset
, info
->length
);
1281 static void msi_scrolltext_add_text( msi_control
*control
, LPCWSTR text
)
1283 struct msi_streamin_info info
;
1286 info
.string
= strdupWtoA( text
);
1288 info
.length
= lstrlenA( info
.string
) + 1;
1290 es
.dwCookie
= (DWORD_PTR
) &info
;
1292 es
.pfnCallback
= msi_richedit_stream_in
;
1294 SendMessageW( control
->hwnd
, EM_STREAMIN
, SF_RTF
, (LPARAM
) &es
);
1296 msi_free( info
.string
);
1299 static UINT
msi_dialog_scrolltext_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1301 static const WCHAR szRichEdit20W
[] = {'R','i','c','h','E','d','i','t','2','0','W',0};
1302 struct msi_scrolltext_info
*info
;
1303 msi_control
*control
;
1308 info
= msi_alloc( sizeof *info
);
1310 return ERROR_FUNCTION_FAILED
;
1312 hRichedit
= LoadLibraryA("riched20");
1314 style
= WS_BORDER
| ES_MULTILINE
| WS_VSCROLL
|
1315 ES_READONLY
| ES_AUTOVSCROLL
| WS_TABSTOP
;
1316 control
= msi_dialog_add_control( dialog
, rec
, szRichEdit20W
, style
);
1319 FreeLibrary( hRichedit
);
1321 return ERROR_FUNCTION_FAILED
;
1324 control
->hDll
= hRichedit
;
1326 info
->dialog
= dialog
;
1327 info
->control
= control
;
1329 /* subclass the static control */
1330 info
->oldproc
= (WNDPROC
) SetWindowLongPtrW( control
->hwnd
, GWLP_WNDPROC
,
1331 (LONG_PTR
)MSIScrollText_WndProc
);
1332 SetPropW( control
->hwnd
, szButtonData
, info
);
1334 /* add the text into the richedit */
1335 text
= MSI_RecordGetString( rec
, 10 );
1337 msi_scrolltext_add_text( control
, text
);
1339 return ERROR_SUCCESS
;
1342 static HBITMAP
msi_load_picture( MSIDATABASE
*db
, LPCWSTR name
,
1343 INT cx
, INT cy
, DWORD flags
)
1345 HBITMAP hOleBitmap
= 0, hBitmap
= 0, hOldSrcBitmap
, hOldDestBitmap
;
1346 MSIRECORD
*rec
= NULL
;
1347 IStream
*stm
= NULL
;
1348 IPicture
*pic
= NULL
;
1353 rec
= msi_get_binary_record( db
, name
);
1357 r
= MSI_RecordGetIStream( rec
, 2, &stm
);
1358 msiobj_release( &rec
->hdr
);
1359 if( r
!= ERROR_SUCCESS
)
1362 r
= OleLoadPicture( stm
, 0, TRUE
, &IID_IPicture
, (LPVOID
*) &pic
);
1363 IStream_Release( stm
);
1366 ERR("failed to load picture\n");
1370 r
= IPicture_get_Handle( pic
, (OLE_HANDLE
*) &hOleBitmap
);
1373 ERR("failed to get bitmap handle\n");
1377 /* make the bitmap the desired size */
1378 r
= GetObjectW( hOleBitmap
, sizeof bm
, &bm
);
1379 if (r
!= sizeof bm
)
1381 ERR("failed to get bitmap size\n");
1385 if (flags
& LR_DEFAULTSIZE
)
1391 srcdc
= CreateCompatibleDC( NULL
);
1392 hOldSrcBitmap
= SelectObject( srcdc
, hOleBitmap
);
1393 destdc
= CreateCompatibleDC( NULL
);
1394 hBitmap
= CreateCompatibleBitmap( srcdc
, cx
, cy
);
1395 hOldDestBitmap
= SelectObject( destdc
, hBitmap
);
1396 StretchBlt( destdc
, 0, 0, cx
, cy
,
1397 srcdc
, 0, 0, bm
.bmWidth
, bm
.bmHeight
, SRCCOPY
);
1398 SelectObject( srcdc
, hOldSrcBitmap
);
1399 SelectObject( destdc
, hOldDestBitmap
);
1405 IPicture_Release( pic
);
1409 static UINT
msi_dialog_bitmap_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1411 UINT cx
, cy
, flags
, style
, attributes
;
1412 msi_control
*control
;
1415 flags
= LR_LOADFROMFILE
;
1416 style
= SS_BITMAP
| SS_LEFT
| WS_GROUP
;
1418 attributes
= MSI_RecordGetInteger( rec
, 8 );
1419 if( attributes
& msidbControlAttributesFixedSize
)
1421 flags
|= LR_DEFAULTSIZE
;
1422 style
|= SS_CENTERIMAGE
;
1425 control
= msi_dialog_add_control( dialog
, rec
, szStatic
, style
);
1426 cx
= MSI_RecordGetInteger( rec
, 6 );
1427 cy
= MSI_RecordGetInteger( rec
, 7 );
1428 cx
= msi_dialog_scale_unit( dialog
, cx
);
1429 cy
= msi_dialog_scale_unit( dialog
, cy
);
1431 name
= msi_get_binary_name( dialog
->package
, rec
);
1432 control
->hBitmap
= msi_load_picture( dialog
->package
->db
, name
, cx
, cy
, flags
);
1433 if( control
->hBitmap
)
1434 SendMessageW( control
->hwnd
, STM_SETIMAGE
,
1435 IMAGE_BITMAP
, (LPARAM
) control
->hBitmap
);
1437 ERR("Failed to load bitmap %s\n", debugstr_w(name
));
1441 return ERROR_SUCCESS
;
1444 static UINT
msi_dialog_icon_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1446 msi_control
*control
;
1452 control
= msi_dialog_add_control( dialog
, rec
, szStatic
,
1453 SS_ICON
| SS_CENTERIMAGE
| WS_GROUP
);
1455 attributes
= MSI_RecordGetInteger( rec
, 8 );
1456 name
= msi_get_binary_name( dialog
->package
, rec
);
1457 control
->hIcon
= msi_load_icon( dialog
->package
->db
, name
, attributes
);
1458 if( control
->hIcon
)
1459 SendMessageW( control
->hwnd
, STM_SETICON
, (WPARAM
) control
->hIcon
, 0 );
1461 ERR("Failed to load bitmap %s\n", debugstr_w(name
));
1463 return ERROR_SUCCESS
;
1466 /******************** Combo Box ***************************************/
1468 struct msi_combobox_info
1478 static LRESULT WINAPI
MSIComboBox_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1480 struct msi_combobox_info
*info
;
1484 TRACE("%p %04x %08lx %08lx\n", hWnd
, msg
, wParam
, lParam
);
1486 info
= GetPropW( hWnd
, szButtonData
);
1490 r
= CallWindowProcW( info
->oldproc
, hWnd
, msg
, wParam
, lParam
);
1495 for (j
= 0; j
< info
->num_items
; j
++)
1496 msi_free( info
->items
[j
] );
1497 msi_free( info
->items
);
1499 RemovePropW( hWnd
, szButtonData
);
1506 static UINT
msi_combobox_add_item( MSIRECORD
*rec
, LPVOID param
)
1508 struct msi_combobox_info
*info
= param
;
1509 LPCWSTR value
, text
;
1512 value
= MSI_RecordGetString( rec
, 3 );
1513 text
= MSI_RecordGetString( rec
, 4 );
1515 info
->items
[info
->addpos_items
] = strdupW( value
);
1517 pos
= SendMessageW( info
->hwnd
, CB_ADDSTRING
, 0, (LPARAM
)text
);
1518 SendMessageW( info
->hwnd
, CB_SETITEMDATA
, pos
, (LPARAM
)info
->items
[info
->addpos_items
] );
1519 info
->addpos_items
++;
1521 return ERROR_SUCCESS
;
1524 static UINT
msi_combobox_add_items( struct msi_combobox_info
*info
, LPCWSTR property
)
1526 static const WCHAR query
[] = {
1527 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
1528 '`','C','o','m','b','o','B','o','x','`',' ','W','H','E','R','E',' ',
1529 '`','P','r','o','p','e','r','t','y','`',' ','=',' ','\'','%','s','\'',' ',
1530 'O','R','D','E','R',' ','B','Y',' ','`','O','r','d','e','r','`',0};
1535 r
= MSI_OpenQuery( info
->dialog
->package
->db
, &view
, query
, property
);
1536 if (r
!= ERROR_SUCCESS
)
1539 /* just get the number of records */
1541 r
= MSI_IterateRecords( view
, &count
, NULL
, NULL
);
1542 if (r
!= ERROR_SUCCESS
)
1544 msiobj_release( &view
->hdr
);
1547 info
->num_items
= count
;
1548 info
->items
= msi_alloc( sizeof(*info
->items
) * count
);
1550 r
= MSI_IterateRecords( view
, NULL
, msi_combobox_add_item
, info
);
1551 msiobj_release( &view
->hdr
);
1555 static UINT
msi_dialog_set_control_condition( MSIRECORD
*rec
, LPVOID param
)
1557 static const WCHAR szHide
[] = {'H','i','d','e',0};
1558 static const WCHAR szShow
[] = {'S','h','o','w',0};
1559 static const WCHAR szDisable
[] = {'D','i','s','a','b','l','e',0};
1560 static const WCHAR szEnable
[] = {'E','n','a','b','l','e',0};
1561 static const WCHAR szDefault
[] = {'D','e','f','a','u','l','t',0};
1562 msi_dialog
*dialog
= param
;
1563 msi_control
*control
;
1564 LPCWSTR name
, action
, condition
;
1567 name
= MSI_RecordGetString( rec
, 2 );
1568 action
= MSI_RecordGetString( rec
, 3 );
1569 condition
= MSI_RecordGetString( rec
, 4 );
1570 r
= MSI_EvaluateConditionW( dialog
->package
, condition
);
1571 control
= msi_dialog_find_control( dialog
, name
);
1572 if (r
== MSICONDITION_TRUE
&& control
)
1574 TRACE("%s control %s\n", debugstr_w(action
), debugstr_w(name
));
1576 /* FIXME: case sensitive? */
1577 if (!strcmpW( action
, szHide
))
1578 ShowWindow(control
->hwnd
, SW_HIDE
);
1579 else if (!strcmpW( action
, szShow
))
1580 ShowWindow(control
->hwnd
, SW_SHOW
);
1581 else if (!strcmpW( action
, szDisable
))
1582 EnableWindow(control
->hwnd
, FALSE
);
1583 else if (!strcmpW( action
, szEnable
))
1584 EnableWindow(control
->hwnd
, TRUE
);
1585 else if (!strcmpW( action
, szDefault
))
1586 SetFocus(control
->hwnd
);
1588 FIXME("Unhandled action %s\n", debugstr_w(action
));
1590 return ERROR_SUCCESS
;
1593 static UINT
msi_dialog_evaluate_control_conditions( msi_dialog
*dialog
)
1595 static const WCHAR query
[] = {
1596 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
1597 'C','o','n','t','r','o','l','C','o','n','d','i','t','i','o','n',' ',
1598 'W','H','E','R','E',' ','`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',0};
1601 MSIPACKAGE
*package
= dialog
->package
;
1603 TRACE("%p %s\n", dialog
, debugstr_w(dialog
->name
));
1605 /* query the Control table for all the elements of the control */
1606 r
= MSI_OpenQuery( package
->db
, &view
, query
, dialog
->name
);
1607 if (r
!= ERROR_SUCCESS
)
1608 return ERROR_SUCCESS
;
1610 r
= MSI_IterateRecords( view
, 0, msi_dialog_set_control_condition
, dialog
);
1611 msiobj_release( &view
->hdr
);
1615 static UINT
msi_dialog_combobox_handler( msi_dialog
*dialog
, msi_control
*control
, WPARAM param
)
1617 struct msi_combobox_info
*info
;
1621 if (HIWORD(param
) != CBN_SELCHANGE
&& HIWORD(param
) != CBN_EDITCHANGE
)
1622 return ERROR_SUCCESS
;
1624 info
= GetPropW( control
->hwnd
, szButtonData
);
1625 index
= SendMessageW( control
->hwnd
, CB_GETCURSEL
, 0, 0 );
1626 if (index
== CB_ERR
)
1627 value
= msi_get_window_text( control
->hwnd
);
1629 value
= (LPWSTR
) SendMessageW( control
->hwnd
, CB_GETITEMDATA
, index
, 0 );
1631 msi_dialog_set_property( info
->dialog
->package
, control
->property
, value
);
1632 msi_dialog_evaluate_control_conditions( info
->dialog
);
1634 if (index
== CB_ERR
)
1637 return ERROR_SUCCESS
;
1640 static void msi_dialog_combobox_update( msi_dialog
*dialog
, msi_control
*control
)
1642 struct msi_combobox_info
*info
;
1646 info
= GetPropW( control
->hwnd
, szButtonData
);
1648 value
= msi_dup_property( dialog
->package
->db
, control
->property
);
1651 SendMessageW( control
->hwnd
, CB_SETCURSEL
, -1, 0 );
1655 for (j
= 0; j
< info
->num_items
; j
++)
1657 tmp
= (LPWSTR
) SendMessageW( control
->hwnd
, CB_GETITEMDATA
, j
, 0 );
1658 if (!strcmpW( value
, tmp
))
1662 if (j
< info
->num_items
)
1664 SendMessageW( control
->hwnd
, CB_SETCURSEL
, j
, 0 );
1668 SendMessageW( control
->hwnd
, CB_SETCURSEL
, -1, 0 );
1669 SetWindowTextW( control
->hwnd
, value
);
1675 static UINT
msi_dialog_combo_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1677 struct msi_combobox_info
*info
;
1678 msi_control
*control
;
1679 DWORD attributes
, style
;
1682 info
= msi_alloc( sizeof *info
);
1684 return ERROR_FUNCTION_FAILED
;
1686 style
= CBS_AUTOHSCROLL
| WS_TABSTOP
| WS_GROUP
| WS_CHILD
;
1687 attributes
= MSI_RecordGetInteger( rec
, 8 );
1688 if ( ~attributes
& msidbControlAttributesSorted
)
1690 if ( attributes
& msidbControlAttributesComboList
)
1691 style
|= CBS_DROPDOWNLIST
;
1693 style
|= CBS_DROPDOWN
;
1695 control
= msi_dialog_add_control( dialog
, rec
, WC_COMBOBOXW
, style
);
1699 return ERROR_FUNCTION_FAILED
;
1702 control
->handler
= msi_dialog_combobox_handler
;
1703 control
->update
= msi_dialog_combobox_update
;
1705 prop
= MSI_RecordGetString( rec
, 9 );
1706 control
->property
= msi_dialog_dup_property( dialog
, prop
, FALSE
);
1709 info
->dialog
= dialog
;
1710 info
->hwnd
= control
->hwnd
;
1712 info
->addpos_items
= 0;
1713 info
->oldproc
= (WNDPROC
)SetWindowLongPtrW( control
->hwnd
, GWLP_WNDPROC
,
1714 (LONG_PTR
)MSIComboBox_WndProc
);
1715 SetPropW( control
->hwnd
, szButtonData
, info
);
1717 if (control
->property
)
1718 msi_combobox_add_items( info
, control
->property
);
1720 msi_dialog_combobox_update( dialog
, control
);
1722 return ERROR_SUCCESS
;
1725 static UINT
msi_dialog_edit_handler( msi_dialog
*dialog
, msi_control
*control
, WPARAM param
)
1729 if (HIWORD(param
) != EN_CHANGE
)
1730 return ERROR_SUCCESS
;
1732 TRACE("edit %s contents changed, set %s\n", debugstr_w(control
->name
), debugstr_w(control
->property
));
1734 buf
= msi_get_window_text( control
->hwnd
);
1735 msi_dialog_set_property( dialog
->package
, control
->property
, buf
);
1738 return ERROR_SUCCESS
;
1741 /* length of 2^32 + 1 */
1742 #define MAX_NUM_DIGITS 11
1744 static UINT
msi_dialog_edit_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1746 msi_control
*control
;
1748 LPWSTR val
, begin
, end
;
1749 WCHAR num
[MAX_NUM_DIGITS
];
1752 control
= msi_dialog_add_control( dialog
, rec
, szEdit
,
1753 WS_BORDER
| WS_TABSTOP
| ES_AUTOHSCROLL
);
1754 control
->handler
= msi_dialog_edit_handler
;
1756 text
= MSI_RecordGetString( rec
, 10 );
1759 begin
= strchrW( text
, '{' );
1760 end
= strchrW( text
, '}' );
1762 if ( begin
&& end
&& end
> begin
&&
1763 begin
[0] >= '0' && begin
[0] <= '9' &&
1764 end
- begin
< MAX_NUM_DIGITS
)
1766 lstrcpynW( num
, begin
+ 1, end
- begin
);
1767 limit
= atolW( num
);
1769 SendMessageW( control
->hwnd
, EM_SETLIMITTEXT
, limit
, 0 );
1773 prop
= MSI_RecordGetString( rec
, 9 );
1775 control
->property
= strdupW( prop
);
1777 val
= msi_dup_property( dialog
->package
->db
, control
->property
);
1778 SetWindowTextW( control
->hwnd
, val
);
1780 return ERROR_SUCCESS
;
1783 /******************** Masked Edit ********************************************/
1785 #define MASK_MAX_GROUPS 20
1787 struct msi_mask_group
1795 struct msi_maskedit_info
1803 struct msi_mask_group group
[MASK_MAX_GROUPS
];
1806 static BOOL
msi_mask_editable( WCHAR type
)
1821 static void msi_mask_control_change( struct msi_maskedit_info
*info
)
1826 val
= msi_alloc( (info
->num_chars
+1)*sizeof(WCHAR
) );
1827 for( i
=0, n
=0; i
<info
->num_groups
; i
++ )
1829 if( (info
->group
[i
].len
+ n
) > info
->num_chars
)
1831 ERR("can't fit control %d text into template\n",i
);
1834 if (!msi_mask_editable(info
->group
[i
].type
))
1836 for(r
=0; r
<info
->group
[i
].len
; r
++)
1837 val
[n
+r
] = info
->group
[i
].type
;
1842 r
= GetWindowTextW( info
->group
[i
].hwnd
, &val
[n
], info
->group
[i
].len
+1 );
1843 if( r
!= info
->group
[i
].len
)
1849 TRACE("%d/%d controls were good\n", i
, info
->num_groups
);
1851 if( i
== info
->num_groups
)
1853 TRACE("Set property %s to %s\n", debugstr_w(info
->prop
), debugstr_w(val
));
1854 msi_dialog_set_property( info
->dialog
->package
, info
->prop
, val
);
1855 msi_dialog_evaluate_control_conditions( info
->dialog
);
1860 /* now move to the next control if necessary */
1861 static VOID
msi_mask_next_control( struct msi_maskedit_info
*info
, HWND hWnd
)
1866 for( i
=0; i
<info
->num_groups
; i
++ )
1867 if( info
->group
[i
].hwnd
== hWnd
)
1870 /* don't move from the last control */
1871 if( i
>= (info
->num_groups
-1) )
1874 len
= SendMessageW( hWnd
, WM_GETTEXTLENGTH
, 0, 0 );
1875 if( len
< info
->group
[i
].len
)
1878 hWndNext
= GetNextDlgTabItem( GetParent( hWnd
), hWnd
, FALSE
);
1879 SetFocus( hWndNext
);
1882 static LRESULT WINAPI
1883 MSIMaskedEdit_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1885 struct msi_maskedit_info
*info
;
1888 TRACE("%p %04x %08lx %08lx\n", hWnd
, msg
, wParam
, lParam
);
1890 info
= GetPropW(hWnd
, szButtonData
);
1892 r
= CallWindowProcW(info
->oldproc
, hWnd
, msg
, wParam
, lParam
);
1897 if (HIWORD(wParam
) == EN_CHANGE
)
1899 msi_mask_control_change( info
);
1900 msi_mask_next_control( info
, (HWND
) lParam
);
1904 msi_free( info
->prop
);
1906 RemovePropW( hWnd
, szButtonData
);
1913 /* fish the various bits of the property out and put them in the control */
1915 msi_maskedit_set_text( struct msi_maskedit_info
*info
, LPCWSTR text
)
1921 for( i
= 0; i
< info
->num_groups
; i
++ )
1923 if( info
->group
[i
].len
< strlenW( p
) )
1925 LPWSTR chunk
= strdupW( p
);
1926 chunk
[ info
->group
[i
].len
] = 0;
1927 SetWindowTextW( info
->group
[i
].hwnd
, chunk
);
1932 SetWindowTextW( info
->group
[i
].hwnd
, p
);
1935 p
+= info
->group
[i
].len
;
1939 static struct msi_maskedit_info
* msi_dialog_parse_groups( LPCWSTR mask
)
1941 struct msi_maskedit_info
* info
= NULL
;
1942 int i
= 0, n
= 0, total
= 0;
1945 TRACE("masked control, template %s\n", debugstr_w(mask
));
1950 info
= msi_alloc_zero( sizeof *info
);
1954 p
= strchrW(mask
, '<');
1960 for( i
=0; i
<MASK_MAX_GROUPS
; i
++ )
1962 /* stop at the end of the string */
1963 if( p
[0] == 0 || p
[0] == '>' )
1966 /* count the number of the same identifier */
1967 for( n
=0; p
[n
] == p
[0]; n
++ )
1969 info
->group
[i
].ofs
= total
;
1970 info
->group
[i
].type
= p
[0];
1974 total
++; /* an extra not part of the group */
1976 info
->group
[i
].len
= n
;
1981 TRACE("%d characters in %d groups\n", total
, i
);
1982 if( i
== MASK_MAX_GROUPS
)
1983 ERR("too many groups in PIDTemplate %s\n", debugstr_w(mask
));
1985 info
->num_chars
= total
;
1986 info
->num_groups
= i
;
1992 msi_maskedit_create_children( struct msi_maskedit_info
*info
, LPCWSTR font
)
1994 DWORD width
, height
, style
, wx
, ww
;
1999 style
= WS_CHILD
| WS_BORDER
| WS_VISIBLE
| WS_TABSTOP
| ES_AUTOHSCROLL
;
2001 GetClientRect( info
->hwnd
, &rect
);
2003 width
= rect
.right
- rect
.left
;
2004 height
= rect
.bottom
- rect
.top
;
2006 for( i
= 0; i
< info
->num_groups
; i
++ )
2008 if (!msi_mask_editable( info
->group
[i
].type
))
2010 wx
= (info
->group
[i
].ofs
* width
) / info
->num_chars
;
2011 ww
= (info
->group
[i
].len
* width
) / info
->num_chars
;
2013 hwnd
= CreateWindowW( szEdit
, NULL
, style
, wx
, 0, ww
, height
,
2014 info
->hwnd
, NULL
, NULL
, NULL
);
2017 ERR("failed to create mask edit sub window\n");
2021 SendMessageW( hwnd
, EM_LIMITTEXT
, info
->group
[i
].len
, 0 );
2023 msi_dialog_set_font( info
->dialog
, hwnd
,
2024 font
?font
:info
->dialog
->default_font
);
2025 info
->group
[i
].hwnd
= hwnd
;
2030 * office 2003 uses "73931<````=````=````=````=`````>@@@@@"
2031 * delphi 7 uses "<????-??????-??????-????>" and "<???-???>"
2032 * filemaker pro 7 uses "<^^^^=^^^^=^^^^=^^^^=^^^^=^^^^=^^^^^>"
2034 static UINT
msi_dialog_maskedit_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
2036 LPWSTR font_mask
, val
= NULL
, font
;
2037 struct msi_maskedit_info
*info
= NULL
;
2038 UINT ret
= ERROR_SUCCESS
;
2039 msi_control
*control
;
2044 font_mask
= msi_get_deformatted_field( dialog
->package
, rec
, 10 );
2045 font
= msi_dialog_get_style( font_mask
, &mask
);
2048 WARN("mask template is empty\n");
2052 info
= msi_dialog_parse_groups( mask
);
2055 ERR("template %s is invalid\n", debugstr_w(mask
));
2059 info
->dialog
= dialog
;
2061 control
= msi_dialog_add_control( dialog
, rec
, szStatic
,
2062 SS_OWNERDRAW
| WS_GROUP
| WS_VISIBLE
);
2065 ERR("Failed to create maskedit container\n");
2066 ret
= ERROR_FUNCTION_FAILED
;
2069 SetWindowLongPtrW( control
->hwnd
, GWL_EXSTYLE
, WS_EX_CONTROLPARENT
);
2071 info
->hwnd
= control
->hwnd
;
2073 /* subclass the static control */
2074 info
->oldproc
= (WNDPROC
) SetWindowLongPtrW( info
->hwnd
, GWLP_WNDPROC
,
2075 (LONG_PTR
)MSIMaskedEdit_WndProc
);
2076 SetPropW( control
->hwnd
, szButtonData
, info
);
2078 prop
= MSI_RecordGetString( rec
, 9 );
2080 info
->prop
= strdupW( prop
);
2082 msi_maskedit_create_children( info
, font
);
2086 val
= msi_dup_property( dialog
->package
->db
, prop
);
2089 msi_maskedit_set_text( info
, val
);
2095 if( ret
!= ERROR_SUCCESS
)
2097 msi_free( font_mask
);
2102 /******************** Progress Bar *****************************************/
2104 static UINT
msi_dialog_progress_bar( msi_dialog
*dialog
, MSIRECORD
*rec
)
2106 msi_control
*control
;
2107 DWORD attributes
, style
;
2110 attributes
= MSI_RecordGetInteger( rec
, 8 );
2111 if( !(attributes
& msidbControlAttributesProgress95
) )
2112 style
|= PBS_SMOOTH
;
2114 control
= msi_dialog_add_control( dialog
, rec
, PROGRESS_CLASSW
, style
);
2116 return ERROR_FUNCTION_FAILED
;
2118 event_subscribe( dialog
, szSetProgress
, control
->name
, szProgress
);
2119 return ERROR_SUCCESS
;
2122 /******************** Path Edit ********************************************/
2124 struct msi_pathedit_info
2127 msi_control
*control
;
2131 static void msi_dialog_update_pathedit( msi_dialog
*dialog
, msi_control
*control
)
2136 if (!control
&& !(control
= msi_dialog_find_control_by_type( dialog
, szPathEdit
)))
2139 indirect
= control
->attributes
& msidbControlAttributesIndirect
;
2140 prop
= msi_dialog_dup_property( dialog
, control
->property
, indirect
);
2141 path
= msi_dialog_dup_property( dialog
, prop
, TRUE
);
2143 SetWindowTextW( control
->hwnd
, path
);
2144 SendMessageW( control
->hwnd
, EM_SETSEL
, 0, -1 );
2150 /* FIXME: test when this should fail */
2151 static BOOL
msi_dialog_verify_path( LPWSTR path
)
2153 if ( !lstrlenW( path
) )
2156 if ( PathIsRelativeW( path
) )
2162 /* returns TRUE if the path is valid, FALSE otherwise */
2163 static BOOL
msi_dialog_onkillfocus( msi_dialog
*dialog
, msi_control
*control
)
2169 indirect
= control
->attributes
& msidbControlAttributesIndirect
;
2170 prop
= msi_dialog_dup_property( dialog
, control
->property
, indirect
);
2172 buf
= msi_get_window_text( control
->hwnd
);
2174 if ( !msi_dialog_verify_path( buf
) )
2176 /* FIXME: display an error message box */
2177 ERR("Invalid path %s\n", debugstr_w( buf
));
2179 SetFocus( control
->hwnd
);
2184 msi_dialog_set_property( dialog
->package
, prop
, buf
);
2187 msi_dialog_update_pathedit( dialog
, control
);
2189 TRACE("edit %s contents changed, set %s\n", debugstr_w(control
->name
),
2198 static LRESULT WINAPI
MSIPathEdit_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
2200 struct msi_pathedit_info
*info
= GetPropW(hWnd
, szButtonData
);
2203 TRACE("%p %04x %08lx %08lx\n", hWnd
, msg
, wParam
, lParam
);
2205 if ( msg
== WM_KILLFOCUS
)
2207 /* if the path is invalid, don't handle this message */
2208 if ( !msi_dialog_onkillfocus( info
->dialog
, info
->control
) )
2212 r
= CallWindowProcW(info
->oldproc
, hWnd
, msg
, wParam
, lParam
);
2214 if ( msg
== WM_NCDESTROY
)
2217 RemovePropW( hWnd
, szButtonData
);
2223 static UINT
msi_dialog_pathedit_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
2225 struct msi_pathedit_info
*info
;
2226 msi_control
*control
;
2229 info
= msi_alloc( sizeof *info
);
2231 return ERROR_FUNCTION_FAILED
;
2233 control
= msi_dialog_add_control( dialog
, rec
, szEdit
,
2234 WS_BORDER
| WS_TABSTOP
);
2235 control
->attributes
= MSI_RecordGetInteger( rec
, 8 );
2236 prop
= MSI_RecordGetString( rec
, 9 );
2237 control
->property
= msi_dialog_dup_property( dialog
, prop
, FALSE
);
2239 info
->dialog
= dialog
;
2240 info
->control
= control
;
2241 info
->oldproc
= (WNDPROC
) SetWindowLongPtrW( control
->hwnd
, GWLP_WNDPROC
,
2242 (LONG_PTR
)MSIPathEdit_WndProc
);
2243 SetPropW( control
->hwnd
, szButtonData
, info
);
2245 msi_dialog_update_pathedit( dialog
, control
);
2247 return ERROR_SUCCESS
;
2250 static UINT
msi_dialog_radiogroup_handler( msi_dialog
*dialog
, msi_control
*control
, WPARAM param
)
2252 if (HIWORD(param
) != BN_CLICKED
)
2253 return ERROR_SUCCESS
;
2255 TRACE("clicked radio button %s, set %s\n", debugstr_w(control
->name
), debugstr_w(control
->property
));
2257 msi_dialog_set_property( dialog
->package
, control
->property
, control
->name
);
2259 return msi_dialog_button_handler( dialog
, control
, param
);
2262 /* radio buttons are a bit different from normal controls */
2263 static UINT
msi_dialog_create_radiobutton( MSIRECORD
*rec
, LPVOID param
)
2265 radio_button_group_descr
*group
= param
;
2266 msi_dialog
*dialog
= group
->dialog
;
2267 msi_control
*control
;
2268 LPCWSTR prop
, text
, name
;
2269 DWORD style
, attributes
= group
->attributes
;
2271 style
= WS_CHILD
| BS_AUTORADIOBUTTON
| BS_MULTILINE
| WS_TABSTOP
;
2272 name
= MSI_RecordGetString( rec
, 3 );
2273 text
= MSI_RecordGetString( rec
, 8 );
2274 if( attributes
& msidbControlAttributesVisible
)
2275 style
|= WS_VISIBLE
;
2276 if( ~attributes
& msidbControlAttributesEnabled
)
2277 style
|= WS_DISABLED
;
2279 control
= dialog_create_window( dialog
, rec
, 0, szButton
, name
, text
, style
,
2280 group
->parent
->hwnd
);
2282 return ERROR_FUNCTION_FAILED
;
2283 control
->handler
= msi_dialog_radiogroup_handler
;
2285 if (group
->propval
&& !strcmpW( control
->name
, group
->propval
))
2286 SendMessageW(control
->hwnd
, BM_SETCHECK
, BST_CHECKED
, 0);
2288 prop
= MSI_RecordGetString( rec
, 1 );
2290 control
->property
= strdupW( prop
);
2292 return ERROR_SUCCESS
;
2295 static BOOL CALLBACK
msi_radioground_child_enum( HWND hWnd
, LPARAM lParam
)
2297 EnableWindow( hWnd
, lParam
);
2301 static LRESULT WINAPI
MSIRadioGroup_WndProc( HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
2303 WNDPROC oldproc
= (WNDPROC
)GetPropW( hWnd
, szButtonData
);
2306 TRACE("hWnd %p msg %04x wParam 0x%08lx lParam 0x%08lx\n", hWnd
, msg
, wParam
, lParam
);
2308 if (msg
== WM_COMMAND
) /* Forward notifications to dialog */
2309 SendMessageW( GetParent( hWnd
), msg
, wParam
, lParam
);
2311 r
= CallWindowProcW( oldproc
, hWnd
, msg
, wParam
, lParam
);
2313 /* make sure the radio buttons show as disabled if the parent is disabled */
2314 if (msg
== WM_ENABLE
)
2315 EnumChildWindows( hWnd
, msi_radioground_child_enum
, wParam
);
2320 static UINT
msi_dialog_radiogroup_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
2322 static const WCHAR query
[] = {
2323 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2324 'R','a','d','i','o','B','u','t','t','o','n',' ','W','H','E','R','E',' ',
2325 '`','P','r','o','p','e','r','t','y','`',' ','=',' ','\'','%','s','\'',0};
2328 msi_control
*control
;
2330 radio_button_group_descr group
;
2331 MSIPACKAGE
*package
= dialog
->package
;
2333 DWORD attr
, style
= WS_GROUP
;
2335 prop
= MSI_RecordGetString( rec
, 9 );
2337 TRACE("%p %p %s\n", dialog
, rec
, debugstr_w( prop
));
2339 attr
= MSI_RecordGetInteger( rec
, 8 );
2340 if (attr
& msidbControlAttributesHasBorder
)
2341 style
|= BS_GROUPBOX
;
2343 style
|= BS_OWNERDRAW
;
2345 /* Create parent group box to hold radio buttons */
2346 control
= msi_dialog_add_control( dialog
, rec
, szButton
, style
);
2348 return ERROR_FUNCTION_FAILED
;
2350 oldproc
= (WNDPROC
) SetWindowLongPtrW( control
->hwnd
, GWLP_WNDPROC
,
2351 (LONG_PTR
)MSIRadioGroup_WndProc
);
2352 SetPropW(control
->hwnd
, szButtonData
, oldproc
);
2353 SetWindowLongPtrW( control
->hwnd
, GWL_EXSTYLE
, WS_EX_CONTROLPARENT
);
2356 control
->property
= strdupW( prop
);
2358 /* query the Radio Button table for all control in this group */
2359 r
= MSI_OpenQuery( package
->db
, &view
, query
, prop
);
2360 if( r
!= ERROR_SUCCESS
)
2362 ERR("query failed for dialog %s radio group %s\n",
2363 debugstr_w(dialog
->name
), debugstr_w(prop
));
2364 return ERROR_INVALID_PARAMETER
;
2367 group
.dialog
= dialog
;
2368 group
.parent
= control
;
2369 group
.attributes
= MSI_RecordGetInteger( rec
, 8 );
2370 group
.propval
= msi_dup_property( dialog
->package
->db
, control
->property
);
2372 r
= MSI_IterateRecords( view
, 0, msi_dialog_create_radiobutton
, &group
);
2373 msiobj_release( &view
->hdr
);
2374 msi_free( group
.propval
);
2379 msi_seltree_sync_item_state( HWND hwnd
, MSIFEATURE
*feature
, HTREEITEM hItem
)
2382 DWORD index
= feature
->ActionRequest
;
2384 TRACE("Feature %s -> %d %d %d\n", debugstr_w(feature
->Title
),
2385 feature
->Installed
, feature
->Action
, feature
->ActionRequest
);
2387 if (index
== INSTALLSTATE_UNKNOWN
)
2388 index
= INSTALLSTATE_ABSENT
;
2390 tvi
.mask
= TVIF_STATE
;
2392 tvi
.state
= INDEXTOSTATEIMAGEMASK( index
);
2393 tvi
.stateMask
= TVIS_STATEIMAGEMASK
;
2395 SendMessageW( hwnd
, TVM_SETITEMW
, 0, (LPARAM
) &tvi
);
2399 msi_seltree_popup_menu( HWND hwnd
, INT x
, INT y
)
2404 /* create a menu to display */
2405 hMenu
= CreatePopupMenu();
2407 /* FIXME: load strings from resources */
2408 AppendMenuA( hMenu
, MF_ENABLED
, INSTALLSTATE_LOCAL
, "Install feature locally");
2409 AppendMenuA( hMenu
, MF_ENABLED
, USER_INSTALLSTATE_ALL
, "Install entire feature");
2410 AppendMenuA( hMenu
, MF_ENABLED
, INSTALLSTATE_ADVERTISED
, "Install on demand");
2411 AppendMenuA( hMenu
, MF_ENABLED
, INSTALLSTATE_ABSENT
, "Don't install");
2412 r
= TrackPopupMenu( hMenu
, TPM_LEFTALIGN
| TPM_TOPALIGN
| TPM_RETURNCMD
,
2413 x
, y
, 0, hwnd
, NULL
);
2414 DestroyMenu( hMenu
);
2419 msi_seltree_update_feature_installstate( HWND hwnd
, HTREEITEM hItem
,
2420 MSIPACKAGE
*package
, MSIFEATURE
*feature
, INSTALLSTATE state
)
2422 feature
->ActionRequest
= state
;
2423 msi_seltree_sync_item_state( hwnd
, feature
, hItem
);
2424 ACTION_UpdateComponentStates( package
, feature
);
2428 msi_seltree_update_siblings_and_children_installstate( HWND hwnd
, HTREEITEM curr
,
2429 MSIPACKAGE
*package
, INSTALLSTATE state
)
2431 /* update all siblings */
2434 MSIFEATURE
*feature
;
2437 feature
= msi_seltree_feature_from_item( hwnd
, curr
);
2438 msi_seltree_update_feature_installstate( hwnd
, curr
, package
, feature
, state
);
2440 /* update this sibling's children */
2441 child
= (HTREEITEM
)SendMessageW( hwnd
, TVM_GETNEXTITEM
, (WPARAM
)TVGN_CHILD
, (LPARAM
)curr
);
2443 msi_seltree_update_siblings_and_children_installstate( hwnd
, child
,
2446 while ((curr
= (HTREEITEM
)SendMessageW( hwnd
, TVM_GETNEXTITEM
, (WPARAM
)TVGN_NEXT
, (LPARAM
)curr
)));
2450 msi_seltree_menu( HWND hwnd
, HTREEITEM hItem
)
2452 struct msi_selection_tree_info
*info
;
2453 MSIFEATURE
*feature
;
2454 MSIPACKAGE
*package
;
2462 info
= GetPropW(hwnd
, szButtonData
);
2463 package
= info
->dialog
->package
;
2465 feature
= msi_seltree_feature_from_item( hwnd
, hItem
);
2468 ERR("item %p feature was NULL\n", hItem
);
2472 /* get the item's rectangle to put the menu just below it */
2474 SendMessageW( hwnd
, TVM_GETITEMRECT
, 0, (LPARAM
) &u
.rc
);
2475 MapWindowPoints( hwnd
, NULL
, u
.pt
, 2 );
2477 r
= msi_seltree_popup_menu( hwnd
, u
.rc
.left
, u
.rc
.top
);
2481 case USER_INSTALLSTATE_ALL
:
2482 r
= INSTALLSTATE_LOCAL
;
2484 case INSTALLSTATE_ADVERTISED
:
2485 case INSTALLSTATE_ABSENT
:
2488 child
= (HTREEITEM
)SendMessageW( hwnd
, TVM_GETNEXTITEM
, (WPARAM
)TVGN_CHILD
, (LPARAM
)hItem
);
2490 msi_seltree_update_siblings_and_children_installstate( hwnd
, child
, package
, r
);
2493 case INSTALLSTATE_LOCAL
:
2494 msi_seltree_update_feature_installstate( hwnd
, hItem
, package
, feature
, r
);
2501 static LRESULT WINAPI
2502 MSISelectionTree_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
2504 struct msi_selection_tree_info
*info
;
2505 TVHITTESTINFO tvhti
;
2508 TRACE("%p %04x %08lx %08lx\n", hWnd
, msg
, wParam
, lParam
);
2510 info
= GetPropW(hWnd
, szButtonData
);
2514 case WM_LBUTTONDOWN
:
2515 tvhti
.pt
.x
= (short)LOWORD( lParam
);
2516 tvhti
.pt
.y
= (short)HIWORD( lParam
);
2519 CallWindowProcW(info
->oldproc
, hWnd
, TVM_HITTEST
, 0, (LPARAM
) &tvhti
);
2520 if (tvhti
.flags
& TVHT_ONITEMSTATEICON
)
2521 return msi_seltree_menu( hWnd
, tvhti
.hItem
);
2524 r
= CallWindowProcW(info
->oldproc
, hWnd
, msg
, wParam
, lParam
);
2530 RemovePropW( hWnd
, szButtonData
);
2537 msi_seltree_add_child_features( MSIPACKAGE
*package
, HWND hwnd
,
2538 LPCWSTR parent
, HTREEITEM hParent
)
2540 struct msi_selection_tree_info
*info
= GetPropW( hwnd
, szButtonData
);
2541 MSIFEATURE
*feature
;
2542 TVINSERTSTRUCTW tvis
;
2543 HTREEITEM hitem
, hfirst
= NULL
;
2545 LIST_FOR_EACH_ENTRY( feature
, &package
->features
, MSIFEATURE
, entry
)
2547 if ( parent
&& feature
->Feature_Parent
&& strcmpW( parent
, feature
->Feature_Parent
))
2549 else if ( parent
&& !feature
->Feature_Parent
)
2551 else if ( !parent
&& feature
->Feature_Parent
)
2554 if ( !feature
->Title
)
2557 if ( !feature
->Display
)
2560 memset( &tvis
, 0, sizeof tvis
);
2561 tvis
.hParent
= hParent
;
2562 tvis
.hInsertAfter
= TVI_LAST
;
2563 tvis
.u
.item
.mask
= TVIF_TEXT
| TVIF_PARAM
;
2564 tvis
.u
.item
.pszText
= feature
->Title
;
2565 tvis
.u
.item
.lParam
= (LPARAM
) feature
;
2567 hitem
= (HTREEITEM
) SendMessageW( hwnd
, TVM_INSERTITEMW
, 0, (LPARAM
) &tvis
);
2574 msi_seltree_sync_item_state( hwnd
, feature
, hitem
);
2575 msi_seltree_add_child_features( package
, hwnd
,
2576 feature
->Feature
, hitem
);
2578 /* the node is expanded if Display is odd */
2579 if ( feature
->Display
% 2 != 0 )
2580 SendMessageW( hwnd
, TVM_EXPAND
, TVE_EXPAND
, (LPARAM
) hitem
);
2583 /* select the first item */
2584 SendMessageW( hwnd
, TVM_SELECTITEM
, TVGN_CARET
| TVGN_DROPHILITE
, (LPARAM
) hfirst
);
2585 info
->selected
= hfirst
;
2588 static void msi_seltree_create_imagelist( HWND hwnd
)
2590 const int bm_width
= 32, bm_height
= 16, bm_count
= 3;
2591 const int bm_resource
= 0x1001;
2596 himl
= ImageList_Create( bm_width
, bm_height
, FALSE
, 4, 0 );
2599 ERR("failed to create image list\n");
2603 for (i
=0; i
<bm_count
; i
++)
2605 hbmp
= LoadBitmapW( msi_hInstance
, MAKEINTRESOURCEW(i
+bm_resource
) );
2608 ERR("failed to load bitmap %d\n", i
);
2613 * Add a dummy bitmap at offset zero because the treeview
2614 * can't use it as a state mask (zero means no user state).
2617 ImageList_Add( himl
, hbmp
, NULL
);
2619 ImageList_Add( himl
, hbmp
, NULL
);
2622 SendMessageW( hwnd
, TVM_SETIMAGELIST
, TVSIL_STATE
, (LPARAM
)himl
);
2625 static UINT
msi_dialog_seltree_handler( msi_dialog
*dialog
,
2626 msi_control
*control
, WPARAM param
)
2628 struct msi_selection_tree_info
*info
= GetPropW( control
->hwnd
, szButtonData
);
2629 LPNMTREEVIEWW tv
= (LPNMTREEVIEWW
)param
;
2630 MSIRECORD
*row
, *rec
;
2632 MSIFEATURE
*feature
;
2633 LPCWSTR dir
, title
= NULL
;
2634 UINT r
= ERROR_SUCCESS
;
2636 static const WCHAR select
[] = {
2637 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2638 '`','F','e','a','t','u','r','e','`',' ','W','H','E','R','E',' ',
2639 '`','T','i','t','l','e','`',' ','=',' ','\'','%','s','\'',0
2642 if (tv
->hdr
.code
!= TVN_SELCHANGINGW
)
2643 return ERROR_SUCCESS
;
2645 info
->selected
= tv
->itemNew
.hItem
;
2647 if (!(tv
->itemNew
.mask
& TVIF_TEXT
))
2649 feature
= msi_seltree_feature_from_item( control
->hwnd
, tv
->itemNew
.hItem
);
2651 title
= feature
->Title
;
2654 title
= tv
->itemNew
.pszText
;
2656 row
= MSI_QueryGetRecord( dialog
->package
->db
, select
, title
);
2658 return ERROR_FUNCTION_FAILED
;
2660 rec
= MSI_CreateRecord( 1 );
2662 MSI_RecordSetStringW( rec
, 1, MSI_RecordGetString( row
, 4 ) );
2663 msi_event_fire( dialog
->package
, szSelectionDescription
, rec
);
2665 dir
= MSI_RecordGetString( row
, 7 );
2668 folder
= msi_get_loaded_folder( dialog
->package
, dir
);
2671 r
= ERROR_FUNCTION_FAILED
;
2674 MSI_RecordSetStringW( rec
, 1, folder
->ResolvedTarget
);
2677 MSI_RecordSetStringW( rec
, 1, NULL
);
2679 msi_event_fire( dialog
->package
, szSelectionPath
, rec
);
2682 msiobj_release(&row
->hdr
);
2683 msiobj_release(&rec
->hdr
);
2688 static UINT
msi_dialog_selection_tree( msi_dialog
*dialog
, MSIRECORD
*rec
)
2690 msi_control
*control
;
2691 LPCWSTR prop
, control_name
;
2692 MSIPACKAGE
*package
= dialog
->package
;
2694 struct msi_selection_tree_info
*info
;
2696 info
= msi_alloc( sizeof *info
);
2698 return ERROR_FUNCTION_FAILED
;
2700 /* create the treeview control */
2701 style
= TVS_HASLINES
| TVS_HASBUTTONS
| TVS_LINESATROOT
;
2702 style
|= WS_GROUP
| WS_VSCROLL
;
2703 control
= msi_dialog_add_control( dialog
, rec
, WC_TREEVIEWW
, style
);
2707 return ERROR_FUNCTION_FAILED
;
2710 control
->handler
= msi_dialog_seltree_handler
;
2711 control_name
= MSI_RecordGetString( rec
, 2 );
2712 control
->attributes
= MSI_RecordGetInteger( rec
, 8 );
2713 prop
= MSI_RecordGetString( rec
, 9 );
2714 control
->property
= msi_dialog_dup_property( dialog
, prop
, FALSE
);
2717 info
->dialog
= dialog
;
2718 info
->hwnd
= control
->hwnd
;
2719 info
->oldproc
= (WNDPROC
) SetWindowLongPtrW( control
->hwnd
, GWLP_WNDPROC
,
2720 (LONG_PTR
)MSISelectionTree_WndProc
);
2721 SetPropW( control
->hwnd
, szButtonData
, info
);
2723 event_subscribe( dialog
, szSelectionPath
, control_name
, szProperty
);
2726 msi_seltree_create_imagelist( control
->hwnd
);
2727 msi_seltree_add_child_features( package
, control
->hwnd
, NULL
, NULL
);
2729 return ERROR_SUCCESS
;
2732 /******************** Group Box ***************************************/
2734 static UINT
msi_dialog_group_box( msi_dialog
*dialog
, MSIRECORD
*rec
)
2736 msi_control
*control
;
2739 style
= BS_GROUPBOX
| WS_CHILD
| WS_GROUP
;
2740 control
= msi_dialog_add_control( dialog
, rec
, WC_BUTTONW
, style
);
2742 return ERROR_FUNCTION_FAILED
;
2744 return ERROR_SUCCESS
;
2747 /******************** List Box ***************************************/
2749 struct msi_listbox_info
2759 static LRESULT WINAPI
MSIListBox_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
2761 struct msi_listbox_info
*info
;
2765 TRACE("%p %04x %08lx %08lx\n", hWnd
, msg
, wParam
, lParam
);
2767 info
= GetPropW( hWnd
, szButtonData
);
2771 r
= CallWindowProcW( info
->oldproc
, hWnd
, msg
, wParam
, lParam
);
2776 for (j
= 0; j
< info
->num_items
; j
++)
2777 msi_free( info
->items
[j
] );
2778 msi_free( info
->items
);
2780 RemovePropW( hWnd
, szButtonData
);
2787 static UINT
msi_listbox_add_item( MSIRECORD
*rec
, LPVOID param
)
2789 struct msi_listbox_info
*info
= param
;
2790 LPCWSTR value
, text
;
2793 value
= MSI_RecordGetString( rec
, 3 );
2794 text
= MSI_RecordGetString( rec
, 4 );
2796 info
->items
[info
->addpos_items
] = strdupW( value
);
2798 pos
= SendMessageW( info
->hwnd
, LB_ADDSTRING
, 0, (LPARAM
)text
);
2799 SendMessageW( info
->hwnd
, LB_SETITEMDATA
, pos
, (LPARAM
)info
->items
[info
->addpos_items
] );
2800 info
->addpos_items
++;
2801 return ERROR_SUCCESS
;
2804 static UINT
msi_listbox_add_items( struct msi_listbox_info
*info
, LPCWSTR property
)
2806 static const WCHAR query
[] = {
2807 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2808 '`','L','i','s','t','B','o','x','`',' ','W','H','E','R','E',' ',
2809 '`','P','r','o','p','e','r','t','y','`',' ','=',' ','\'','%','s','\'',' ',
2810 'O','R','D','E','R',' ','B','Y',' ','`','O','r','d','e','r','`',0};
2815 r
= MSI_OpenQuery( info
->dialog
->package
->db
, &view
, query
, property
);
2816 if ( r
!= ERROR_SUCCESS
)
2819 /* just get the number of records */
2821 r
= MSI_IterateRecords( view
, &count
, NULL
, NULL
);
2822 if (r
!= ERROR_SUCCESS
)
2824 msiobj_release( &view
->hdr
);
2827 info
->num_items
= count
;
2828 info
->items
= msi_alloc( sizeof(*info
->items
) * count
);
2830 r
= MSI_IterateRecords( view
, NULL
, msi_listbox_add_item
, info
);
2831 msiobj_release( &view
->hdr
);
2835 static UINT
msi_dialog_listbox_handler( msi_dialog
*dialog
,
2836 msi_control
*control
, WPARAM param
)
2838 struct msi_listbox_info
*info
;
2842 if( HIWORD(param
) != LBN_SELCHANGE
)
2843 return ERROR_SUCCESS
;
2845 info
= GetPropW( control
->hwnd
, szButtonData
);
2846 index
= SendMessageW( control
->hwnd
, LB_GETCURSEL
, 0, 0 );
2847 value
= (LPCWSTR
) SendMessageW( control
->hwnd
, LB_GETITEMDATA
, index
, 0 );
2849 msi_dialog_set_property( info
->dialog
->package
, control
->property
, value
);
2850 msi_dialog_evaluate_control_conditions( info
->dialog
);
2852 return ERROR_SUCCESS
;
2855 static UINT
msi_dialog_list_box( msi_dialog
*dialog
, MSIRECORD
*rec
)
2857 struct msi_listbox_info
*info
;
2858 msi_control
*control
;
2859 DWORD attributes
, style
;
2862 info
= msi_alloc( sizeof *info
);
2864 return ERROR_FUNCTION_FAILED
;
2866 style
= WS_TABSTOP
| WS_GROUP
| WS_CHILD
| LBS_NOTIFY
| WS_VSCROLL
| WS_BORDER
;
2867 attributes
= MSI_RecordGetInteger( rec
, 8 );
2868 if (~attributes
& msidbControlAttributesSorted
)
2871 control
= msi_dialog_add_control( dialog
, rec
, WC_LISTBOXW
, style
);
2875 return ERROR_FUNCTION_FAILED
;
2878 control
->handler
= msi_dialog_listbox_handler
;
2880 prop
= MSI_RecordGetString( rec
, 9 );
2881 control
->property
= msi_dialog_dup_property( dialog
, prop
, FALSE
);
2884 info
->dialog
= dialog
;
2885 info
->hwnd
= control
->hwnd
;
2887 info
->addpos_items
= 0;
2888 info
->oldproc
= (WNDPROC
)SetWindowLongPtrW( control
->hwnd
, GWLP_WNDPROC
,
2889 (LONG_PTR
)MSIListBox_WndProc
);
2890 SetPropW( control
->hwnd
, szButtonData
, info
);
2892 if ( control
->property
)
2893 msi_listbox_add_items( info
, control
->property
);
2895 return ERROR_SUCCESS
;
2898 /******************** Directory Combo ***************************************/
2900 static void msi_dialog_update_directory_combo( msi_dialog
*dialog
, msi_control
*control
)
2905 if (!control
&& !(control
= msi_dialog_find_control_by_type( dialog
, szDirectoryCombo
)))
2908 indirect
= control
->attributes
& msidbControlAttributesIndirect
;
2909 prop
= msi_dialog_dup_property( dialog
, control
->property
, indirect
);
2910 path
= msi_dialog_dup_property( dialog
, prop
, TRUE
);
2912 PathStripPathW( path
);
2913 PathRemoveBackslashW( path
);
2915 SendMessageW( control
->hwnd
, CB_INSERTSTRING
, 0, (LPARAM
)path
);
2916 SendMessageW( control
->hwnd
, CB_SETCURSEL
, 0, 0 );
2922 static UINT
msi_dialog_directory_combo( msi_dialog
*dialog
, MSIRECORD
*rec
)
2924 msi_control
*control
;
2928 /* FIXME: use CBS_OWNERDRAWFIXED and add owner draw code */
2929 style
= CBS_DROPDOWNLIST
| CBS_HASSTRINGS
| WS_CHILD
|
2930 WS_GROUP
| WS_TABSTOP
| WS_VSCROLL
;
2931 control
= msi_dialog_add_control( dialog
, rec
, WC_COMBOBOXW
, style
);
2933 return ERROR_FUNCTION_FAILED
;
2935 control
->attributes
= MSI_RecordGetInteger( rec
, 8 );
2936 prop
= MSI_RecordGetString( rec
, 9 );
2937 control
->property
= msi_dialog_dup_property( dialog
, prop
, FALSE
);
2939 msi_dialog_update_directory_combo( dialog
, control
);
2941 return ERROR_SUCCESS
;
2944 /******************** Directory List ***************************************/
2946 static void msi_dialog_update_directory_list( msi_dialog
*dialog
, msi_control
*control
)
2948 WCHAR dir_spec
[MAX_PATH
];
2949 WIN32_FIND_DATAW wfd
;
2955 static const WCHAR asterisk
[] = {'*',0};
2957 if (!control
&& !(control
= msi_dialog_find_control_by_type( dialog
, szDirectoryList
)))
2960 /* clear the list-view */
2961 SendMessageW( control
->hwnd
, LVM_DELETEALLITEMS
, 0, 0 );
2963 indirect
= control
->attributes
& msidbControlAttributesIndirect
;
2964 prop
= msi_dialog_dup_property( dialog
, control
->property
, indirect
);
2965 path
= msi_dialog_dup_property( dialog
, prop
, TRUE
);
2967 lstrcpyW( dir_spec
, path
);
2968 lstrcatW( dir_spec
, asterisk
);
2970 file
= FindFirstFileW( dir_spec
, &wfd
);
2971 if ( file
== INVALID_HANDLE_VALUE
)
2976 if ( wfd
.dwFileAttributes
!= FILE_ATTRIBUTE_DIRECTORY
)
2979 if ( !strcmpW( wfd
.cFileName
, szDot
) || !strcmpW( wfd
.cFileName
, szDotDot
) )
2982 item
.mask
= LVIF_TEXT
;
2983 item
.cchTextMax
= MAX_PATH
;
2986 item
.pszText
= wfd
.cFileName
;
2988 SendMessageW( control
->hwnd
, LVM_INSERTITEMW
, 0, (LPARAM
)&item
);
2989 } while ( FindNextFileW( file
, &wfd
) );
2996 UINT
msi_dialog_directorylist_up( msi_dialog
*dialog
)
2998 msi_control
*control
;
2999 LPWSTR prop
, path
, ptr
;
3002 control
= msi_dialog_find_control_by_type( dialog
, szDirectoryList
);
3003 indirect
= control
->attributes
& msidbControlAttributesIndirect
;
3004 prop
= msi_dialog_dup_property( dialog
, control
->property
, indirect
);
3005 path
= msi_dialog_dup_property( dialog
, prop
, TRUE
);
3007 /* strip off the last directory */
3008 ptr
= PathFindFileNameW( path
);
3009 if (ptr
!= path
) *(ptr
- 1) = '\0';
3010 PathAddBackslashW( path
);
3012 msi_dialog_set_property( dialog
->package
, prop
, path
);
3014 msi_dialog_update_directory_list( dialog
, NULL
);
3015 msi_dialog_update_directory_combo( dialog
, NULL
);
3016 msi_dialog_update_pathedit( dialog
, NULL
);
3021 return ERROR_SUCCESS
;
3024 static UINT
msi_dialog_dirlist_handler( msi_dialog
*dialog
,
3025 msi_control
*control
, WPARAM param
)
3027 LPNMHDR nmhdr
= (LPNMHDR
)param
;
3028 WCHAR new_path
[MAX_PATH
];
3029 WCHAR text
[MAX_PATH
];
3035 if (nmhdr
->code
!= LVN_ITEMACTIVATE
)
3036 return ERROR_SUCCESS
;
3038 index
= SendMessageW( control
->hwnd
, LVM_GETNEXTITEM
, -1, LVNI_SELECTED
);
3041 ERR("No list-view item selected!\n");
3042 return ERROR_FUNCTION_FAILED
;
3046 item
.pszText
= text
;
3047 item
.cchTextMax
= MAX_PATH
;
3048 SendMessageW( control
->hwnd
, LVM_GETITEMTEXTW
, index
, (LPARAM
)&item
);
3050 indirect
= control
->attributes
& msidbControlAttributesIndirect
;
3051 prop
= msi_dialog_dup_property( dialog
, control
->property
, indirect
);
3052 path
= msi_dialog_dup_property( dialog
, prop
, TRUE
);
3054 lstrcpyW( new_path
, path
);
3055 lstrcatW( new_path
, text
);
3056 lstrcatW( new_path
, szBackSlash
);
3058 msi_dialog_set_property( dialog
->package
, prop
, new_path
);
3060 msi_dialog_update_directory_list( dialog
, NULL
);
3061 msi_dialog_update_directory_combo( dialog
, NULL
);
3062 msi_dialog_update_pathedit( dialog
, NULL
);
3066 return ERROR_SUCCESS
;
3069 static UINT
msi_dialog_directory_list( msi_dialog
*dialog
, MSIRECORD
*rec
)
3071 msi_control
*control
;
3075 style
= LVS_LIST
| WS_VSCROLL
| LVS_SHAREIMAGELISTS
|
3076 LVS_AUTOARRANGE
| LVS_SINGLESEL
| WS_BORDER
|
3077 LVS_SORTASCENDING
| WS_CHILD
| WS_GROUP
| WS_TABSTOP
;
3078 control
= msi_dialog_add_control( dialog
, rec
, WC_LISTVIEWW
, style
);
3080 return ERROR_FUNCTION_FAILED
;
3082 control
->attributes
= MSI_RecordGetInteger( rec
, 8 );
3083 control
->handler
= msi_dialog_dirlist_handler
;
3084 prop
= MSI_RecordGetString( rec
, 9 );
3085 control
->property
= msi_dialog_dup_property( dialog
, prop
, FALSE
);
3087 /* double click to activate an item in the list */
3088 SendMessageW( control
->hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
,
3089 0, LVS_EX_TWOCLICKACTIVATE
);
3091 msi_dialog_update_directory_list( dialog
, control
);
3093 return ERROR_SUCCESS
;
3096 /******************** VolumeCost List ***************************************/
3098 static BOOL
str_is_number( LPCWSTR str
)
3102 for (i
= 0; i
< lstrlenW( str
); i
++)
3103 if (!isdigitW(str
[i
]))
3109 static const WCHAR column_keys
[][80] =
3111 {'V','o','l','u','m','e','C','o','s','t','V','o','l','u','m','e',0},
3112 {'V','o','l','u','m','e','C','o','s','t','S','i','z','e',0},
3113 {'V','o','l','u','m','e','C','o','s','t','A','v','a','i','l','a','b','l','e',0},
3114 {'V','o','l','u','m','e','C','o','s','t','R','e','q','u','i','r','e','d',0},
3115 {'V','o','l','u','m','e','C','o','s','t','D','i','f','f','e','r','e','n','c','e',0}
3118 static void msi_dialog_vcl_add_columns( msi_dialog
*dialog
, msi_control
*control
, MSIRECORD
*rec
)
3120 LPCWSTR text
= MSI_RecordGetString( rec
, 10 );
3121 LPCWSTR begin
= text
, end
;
3126 static const WCHAR negative
[] = {'-',0};
3130 while ((begin
= strchrW( begin
, '{' )) && count
< 5)
3132 if (!(end
= strchrW( begin
, '}' )))
3135 num
= msi_alloc( (end
-begin
+1)*sizeof(WCHAR
) );
3139 lstrcpynW( num
, begin
+ 1, end
- begin
);
3140 begin
+= end
- begin
+ 1;
3142 /* empty braces or '0' hides the column */
3143 if ( !num
[0] || !strcmpW( num
, szZero
) )
3150 /* the width must be a positive number
3151 * if a width is invalid, all remaining columns are hidden
3153 if ( !strncmpW( num
, negative
, 1 ) || !str_is_number( num
) ) {
3158 ZeroMemory( &lvc
, sizeof(lvc
) );
3159 lvc
.mask
= LVCF_TEXT
| LVCF_WIDTH
| LVCF_SUBITEM
;
3160 lvc
.cx
= atolW( num
);
3161 lvc
.pszText
= msi_dialog_get_uitext( dialog
, column_keys
[count
] );
3163 SendMessageW( control
->hwnd
, LVM_INSERTCOLUMNW
, count
++, (LPARAM
)&lvc
);
3164 msi_free( lvc
.pszText
);
3169 static LONGLONG
msi_vcl_get_cost( msi_dialog
*dialog
)
3171 MSIFEATURE
*feature
;
3173 LONGLONG total_cost
= 0;
3175 LIST_FOR_EACH_ENTRY( feature
, &dialog
->package
->features
, MSIFEATURE
, entry
)
3177 if (ERROR_SUCCESS
== (MSI_GetFeatureCost(dialog
->package
, feature
,
3178 MSICOSTTREE_SELFONLY
, INSTALLSTATE_LOCAL
, &each_cost
)))
3180 /* each_cost is in 512-byte units */
3181 total_cost
+= each_cost
* 512;
3183 if (ERROR_SUCCESS
== (MSI_GetFeatureCost(dialog
->package
, feature
,
3184 MSICOSTTREE_SELFONLY
, INSTALLSTATE_ABSENT
, &each_cost
)))
3186 /* each_cost is in 512-byte units */
3187 total_cost
-= each_cost
* 512;
3193 static void msi_dialog_vcl_add_drives( msi_dialog
*dialog
, msi_control
*control
)
3195 ULARGE_INTEGER total
, free
;
3196 LONGLONG difference
, cost
;
3197 WCHAR size_text
[MAX_PATH
];
3198 WCHAR cost_text
[MAX_PATH
];
3204 cost
= msi_vcl_get_cost(dialog
);
3205 StrFormatByteSizeW(cost
, cost_text
, MAX_PATH
);
3207 size
= GetLogicalDriveStringsW( 0, NULL
);
3208 if ( !size
) return;
3210 drives
= msi_alloc( (size
+ 1) * sizeof(WCHAR
) );
3211 if ( !drives
) return;
3213 GetLogicalDriveStringsW( size
, drives
);
3218 lvitem
.mask
= LVIF_TEXT
;
3220 lvitem
.iSubItem
= 0;
3221 lvitem
.pszText
= ptr
;
3222 lvitem
.cchTextMax
= lstrlenW(ptr
) + 1;
3223 SendMessageW( control
->hwnd
, LVM_INSERTITEMW
, 0, (LPARAM
)&lvitem
);
3225 GetDiskFreeSpaceExW(ptr
, &free
, &total
, NULL
);
3226 difference
= free
.QuadPart
- cost
;
3228 StrFormatByteSizeW(total
.QuadPart
, size_text
, MAX_PATH
);
3229 lvitem
.iSubItem
= 1;
3230 lvitem
.pszText
= size_text
;
3231 lvitem
.cchTextMax
= lstrlenW(size_text
) + 1;
3232 SendMessageW( control
->hwnd
, LVM_SETITEMW
, 0, (LPARAM
)&lvitem
);
3234 StrFormatByteSizeW(free
.QuadPart
, size_text
, MAX_PATH
);
3235 lvitem
.iSubItem
= 2;
3236 lvitem
.pszText
= size_text
;
3237 lvitem
.cchTextMax
= lstrlenW(size_text
) + 1;
3238 SendMessageW( control
->hwnd
, LVM_SETITEMW
, 0, (LPARAM
)&lvitem
);
3240 lvitem
.iSubItem
= 3;
3241 lvitem
.pszText
= cost_text
;
3242 lvitem
.cchTextMax
= lstrlenW(cost_text
) + 1;
3243 SendMessageW( control
->hwnd
, LVM_SETITEMW
, 0, (LPARAM
)&lvitem
);
3245 StrFormatByteSizeW(difference
, size_text
, MAX_PATH
);
3246 lvitem
.iSubItem
= 4;
3247 lvitem
.pszText
= size_text
;
3248 lvitem
.cchTextMax
= lstrlenW(size_text
) + 1;
3249 SendMessageW( control
->hwnd
, LVM_SETITEMW
, 0, (LPARAM
)&lvitem
);
3251 ptr
+= lstrlenW(ptr
) + 1;
3258 static UINT
msi_dialog_volumecost_list( msi_dialog
*dialog
, MSIRECORD
*rec
)
3260 msi_control
*control
;
3263 style
= LVS_REPORT
| WS_VSCROLL
| WS_HSCROLL
| LVS_SHAREIMAGELISTS
|
3264 LVS_AUTOARRANGE
| LVS_SINGLESEL
| WS_BORDER
|
3265 WS_CHILD
| WS_TABSTOP
| WS_GROUP
;
3266 control
= msi_dialog_add_control( dialog
, rec
, WC_LISTVIEWW
, style
);
3268 return ERROR_FUNCTION_FAILED
;
3270 msi_dialog_vcl_add_columns( dialog
, control
, rec
);
3271 msi_dialog_vcl_add_drives( dialog
, control
);
3273 return ERROR_SUCCESS
;
3276 /******************** VolumeSelect Combo ***************************************/
3278 static UINT
msi_dialog_volsel_handler( msi_dialog
*dialog
,
3279 msi_control
*control
, WPARAM param
)
3281 WCHAR text
[MAX_PATH
];
3286 if (HIWORD(param
) != CBN_SELCHANGE
)
3287 return ERROR_SUCCESS
;
3289 index
= SendMessageW( control
->hwnd
, CB_GETCURSEL
, 0, 0 );
3290 if ( index
== CB_ERR
)
3292 ERR("No ComboBox item selected!\n");
3293 return ERROR_FUNCTION_FAILED
;
3296 SendMessageW( control
->hwnd
, CB_GETLBTEXT
, index
, (LPARAM
)text
);
3298 indirect
= control
->attributes
& msidbControlAttributesIndirect
;
3299 prop
= msi_dialog_dup_property( dialog
, control
->property
, indirect
);
3301 msi_dialog_set_property( dialog
->package
, prop
, text
);
3304 return ERROR_SUCCESS
;
3307 static void msi_dialog_vsc_add_drives( msi_dialog
*dialog
, msi_control
*control
)
3312 size
= GetLogicalDriveStringsW( 0, NULL
);
3313 if ( !size
) return;
3315 drives
= msi_alloc( (size
+ 1) * sizeof(WCHAR
) );
3316 if ( !drives
) return;
3318 GetLogicalDriveStringsW( size
, drives
);
3323 SendMessageW( control
->hwnd
, CB_ADDSTRING
, 0, (LPARAM
)ptr
);
3324 ptr
+= lstrlenW(ptr
) + 1;
3330 static UINT
msi_dialog_volumeselect_combo( msi_dialog
*dialog
, MSIRECORD
*rec
)
3332 msi_control
*control
;
3336 /* FIXME: CBS_OWNERDRAWFIXED */
3337 style
= WS_CHILD
| WS_VISIBLE
| WS_GROUP
| WS_TABSTOP
|
3338 CBS_DROPDOWNLIST
| CBS_SORT
| CBS_HASSTRINGS
|
3339 WS_EX_LEFT
| WS_EX_LTRREADING
| WS_EX_RIGHTSCROLLBAR
;
3340 control
= msi_dialog_add_control( dialog
, rec
, WC_COMBOBOXW
, style
);
3342 return ERROR_FUNCTION_FAILED
;
3344 control
->attributes
= MSI_RecordGetInteger( rec
, 8 );
3345 control
->handler
= msi_dialog_volsel_handler
;
3346 prop
= MSI_RecordGetString( rec
, 9 );
3347 control
->property
= msi_dialog_dup_property( dialog
, prop
, FALSE
);
3349 msi_dialog_vsc_add_drives( dialog
, control
);
3351 return ERROR_SUCCESS
;
3354 static UINT
msi_dialog_hyperlink_handler( msi_dialog
*dialog
, msi_control
*control
, WPARAM param
)
3356 static const WCHAR hrefW
[] = {'h','r','e','f'};
3357 static const WCHAR openW
[] = {'o','p','e','n',0};
3358 int len
, len_href
= sizeof(hrefW
) / sizeof(hrefW
[0]);
3363 item
.mask
= LIF_ITEMINDEX
| LIF_URL
;
3367 SendMessageW( control
->hwnd
, LM_GETITEM
, 0, (LPARAM
)&item
);
3370 while (*p
&& *p
!= '<') p
++;
3371 if (!*p
++) return ERROR_SUCCESS
;
3372 if (toupperW( *p
++ ) != 'A' || !isspaceW( *p
++ )) return ERROR_SUCCESS
;
3373 while (*p
&& isspaceW( *p
)) p
++;
3376 if (len
> len_href
&& !memicmpW( p
, hrefW
, len_href
))
3379 while (*p
&& isspaceW( *p
)) p
++;
3380 if (!*p
|| *p
++ != '=') return ERROR_SUCCESS
;
3381 while (*p
&& isspaceW( *p
)) p
++;
3383 if (*p
== '\"' || *p
== '\'') quote
= *p
++;
3387 while (*q
&& *q
!= quote
) q
++;
3388 if (*q
!= quote
) return ERROR_SUCCESS
;
3392 while (*q
&& *q
!= '>' && !isspaceW( *q
)) q
++;
3393 if (!*q
) return ERROR_SUCCESS
;
3395 item
.szUrl
[q
- item
.szUrl
] = 0;
3396 ShellExecuteW( NULL
, openW
, p
, NULL
, NULL
, SW_SHOWNORMAL
);
3398 return ERROR_SUCCESS
;
3401 static UINT
msi_dialog_hyperlink( msi_dialog
*dialog
, MSIRECORD
*rec
)
3403 msi_control
*control
;
3404 DWORD style
= WS_CHILD
| WS_TABSTOP
| WS_GROUP
;
3405 const WCHAR
*text
= MSI_RecordGetString( rec
, 10 );
3406 int len
= strlenW( text
);
3409 control
= msi_dialog_add_control( dialog
, rec
, WC_LINK
, style
);
3411 return ERROR_FUNCTION_FAILED
;
3413 control
->attributes
= MSI_RecordGetInteger( rec
, 8 );
3414 control
->handler
= msi_dialog_hyperlink_handler
;
3416 item
.mask
= LIF_ITEMINDEX
| LIF_STATE
| LIF_URL
;
3418 item
.state
= LIS_ENABLED
;
3419 item
.stateMask
= LIS_ENABLED
;
3420 if (len
< L_MAX_URL_LENGTH
) strcpyW( item
.szUrl
, text
);
3421 else item
.szUrl
[0] = 0;
3423 SendMessageW( control
->hwnd
, LM_SETITEM
, 0, (LPARAM
)&item
);
3425 return ERROR_SUCCESS
;
3428 static const struct control_handler msi_dialog_handler
[] =
3430 { szText
, msi_dialog_text_control
},
3431 { szPushButton
, msi_dialog_button_control
},
3432 { szLine
, msi_dialog_line_control
},
3433 { szBitmap
, msi_dialog_bitmap_control
},
3434 { szCheckBox
, msi_dialog_checkbox_control
},
3435 { szScrollableText
, msi_dialog_scrolltext_control
},
3436 { szComboBox
, msi_dialog_combo_control
},
3437 { szEdit
, msi_dialog_edit_control
},
3438 { szMaskedEdit
, msi_dialog_maskedit_control
},
3439 { szPathEdit
, msi_dialog_pathedit_control
},
3440 { szProgressBar
, msi_dialog_progress_bar
},
3441 { szRadioButtonGroup
, msi_dialog_radiogroup_control
},
3442 { szIcon
, msi_dialog_icon_control
},
3443 { szSelectionTree
, msi_dialog_selection_tree
},
3444 { szGroupBox
, msi_dialog_group_box
},
3445 { szListBox
, msi_dialog_list_box
},
3446 { szDirectoryCombo
, msi_dialog_directory_combo
},
3447 { szDirectoryList
, msi_dialog_directory_list
},
3448 { szVolumeCostList
, msi_dialog_volumecost_list
},
3449 { szVolumeSelectCombo
, msi_dialog_volumeselect_combo
},
3450 { szHyperLink
, msi_dialog_hyperlink
}
3453 #define NUM_CONTROL_TYPES (sizeof msi_dialog_handler/sizeof msi_dialog_handler[0])
3455 static UINT
msi_dialog_create_controls( MSIRECORD
*rec
, LPVOID param
)
3457 msi_dialog
*dialog
= param
;
3458 LPCWSTR control_type
;
3461 /* find and call the function that can create this type of control */
3462 control_type
= MSI_RecordGetString( rec
, 3 );
3463 for( i
=0; i
<NUM_CONTROL_TYPES
; i
++ )
3464 if (!strcmpiW( msi_dialog_handler
[i
].control_type
, control_type
))
3466 if( i
!= NUM_CONTROL_TYPES
)
3467 msi_dialog_handler
[i
].func( dialog
, rec
);
3469 ERR("no handler for element type %s\n", debugstr_w(control_type
));
3471 return ERROR_SUCCESS
;
3474 static UINT
msi_dialog_fill_controls( msi_dialog
*dialog
)
3476 static const WCHAR query
[] = {
3477 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
3478 'C','o','n','t','r','o','l',' ','W','H','E','R','E',' ',
3479 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',0};
3482 MSIPACKAGE
*package
= dialog
->package
;
3484 TRACE("%p %s\n", dialog
, debugstr_w(dialog
->name
) );
3486 /* query the Control table for all the elements of the control */
3487 r
= MSI_OpenQuery( package
->db
, &view
, query
, dialog
->name
);
3488 if( r
!= ERROR_SUCCESS
)
3490 ERR("query failed for dialog %s\n", debugstr_w(dialog
->name
));
3491 return ERROR_INVALID_PARAMETER
;
3494 r
= MSI_IterateRecords( view
, 0, msi_dialog_create_controls
, dialog
);
3495 msiobj_release( &view
->hdr
);
3499 UINT
msi_dialog_reset( msi_dialog
*dialog
)
3501 /* FIXME: should restore the original values of any properties we changed */
3502 return msi_dialog_evaluate_control_conditions( dialog
);
3505 /* figure out the height of 10 point MS Sans Serif */
3506 static INT
msi_dialog_get_sans_serif_height( HWND hwnd
)
3508 static const WCHAR szSansSerif
[] = {
3509 'M','S',' ','S','a','n','s',' ','S','e','r','i','f',0 };
3514 HFONT hFont
, hOldFont
;
3517 hdc
= GetDC( hwnd
);
3520 memset( &lf
, 0, sizeof lf
);
3521 lf
.lfHeight
= MulDiv(12, GetDeviceCaps(hdc
, LOGPIXELSY
), 72);
3522 strcpyW( lf
.lfFaceName
, szSansSerif
);
3523 hFont
= CreateFontIndirectW(&lf
);
3526 hOldFont
= SelectObject( hdc
, hFont
);
3527 r
= GetTextMetricsW( hdc
, &tm
);
3529 height
= tm
.tmHeight
;
3530 SelectObject( hdc
, hOldFont
);
3531 DeleteObject( hFont
);
3533 ReleaseDC( hwnd
, hdc
);
3538 /* fetch the associated record from the Dialog table */
3539 static MSIRECORD
*msi_get_dialog_record( msi_dialog
*dialog
)
3541 static const WCHAR query
[] = {
3542 'S','E','L','E','C','T',' ','*',' ',
3543 'F','R','O','M',' ','D','i','a','l','o','g',' ',
3544 'W','H','E','R','E',' ',
3545 '`','D','i','a','l','o','g','`',' ','=',' ','\'','%','s','\'',0};
3546 MSIPACKAGE
*package
= dialog
->package
;
3547 MSIRECORD
*rec
= NULL
;
3549 TRACE("%p %s\n", dialog
, debugstr_w(dialog
->name
) );
3551 rec
= MSI_QueryGetRecord( package
->db
, query
, dialog
->name
);
3553 WARN("query failed for dialog %s\n", debugstr_w(dialog
->name
));
3558 static void msi_dialog_adjust_dialog_pos( msi_dialog
*dialog
, MSIRECORD
*rec
, LPRECT pos
)
3560 static const WCHAR szScreenX
[] = {'S','c','r','e','e','n','X',0};
3561 static const WCHAR szScreenY
[] = {'S','c','r','e','e','n','Y',0};
3568 center
.x
= MSI_RecordGetInteger( rec
, 2 );
3569 center
.y
= MSI_RecordGetInteger( rec
, 3 );
3571 sz
.cx
= MSI_RecordGetInteger( rec
, 4 );
3572 sz
.cy
= MSI_RecordGetInteger( rec
, 5 );
3574 sz
.cx
= msi_dialog_scale_unit( dialog
, sz
.cx
);
3575 sz
.cy
= msi_dialog_scale_unit( dialog
, sz
.cy
);
3577 xres
= msi_get_property_int( dialog
->package
->db
, szScreenX
, 0 );
3578 yres
= msi_get_property_int( dialog
->package
->db
, szScreenY
, 0 );
3580 center
.x
= MulDiv( center
.x
, xres
, 100 );
3581 center
.y
= MulDiv( center
.y
, yres
, 100 );
3583 /* turn the client pos into the window rectangle */
3584 if (dialog
->package
->center_x
&& dialog
->package
->center_y
)
3586 pos
->left
= dialog
->package
->center_x
- sz
.cx
/ 2.0;
3587 pos
->right
= pos
->left
+ sz
.cx
;
3588 pos
->top
= dialog
->package
->center_y
- sz
.cy
/ 2.0;
3589 pos
->bottom
= pos
->top
+ sz
.cy
;
3593 pos
->left
= center
.x
- sz
.cx
/2;
3594 pos
->right
= pos
->left
+ sz
.cx
;
3595 pos
->top
= center
.y
- sz
.cy
/2;
3596 pos
->bottom
= pos
->top
+ sz
.cy
;
3598 /* save the center */
3599 dialog
->package
->center_x
= center
.x
;
3600 dialog
->package
->center_y
= center
.y
;
3603 dialog
->size
.cx
= sz
.cx
;
3604 dialog
->size
.cy
= sz
.cy
;
3606 TRACE("%u %u %u %u\n", pos
->left
, pos
->top
, pos
->right
, pos
->bottom
);
3608 style
= GetWindowLongPtrW( dialog
->hwnd
, GWL_STYLE
);
3609 AdjustWindowRect( pos
, style
, FALSE
);
3612 static void msi_dialog_set_tab_order( msi_dialog
*dialog
, LPCWSTR first
)
3614 struct list tab_chain
;
3615 msi_control
*control
;
3616 HWND prev
= HWND_TOP
;
3618 list_init( &tab_chain
);
3619 if (!(control
= msi_dialog_find_control( dialog
, first
))) return;
3621 dialog
->hWndFocus
= control
->hwnd
;
3624 list_remove( &control
->entry
);
3625 list_add_tail( &tab_chain
, &control
->entry
);
3626 if (!control
->tabnext
) break;
3627 control
= msi_dialog_find_control( dialog
, control
->tabnext
);
3630 LIST_FOR_EACH_ENTRY( control
, &tab_chain
, msi_control
, entry
)
3632 SetWindowPos( control
->hwnd
, prev
, 0, 0, 0, 0,
3633 SWP_NOMOVE
| SWP_NOOWNERZORDER
| SWP_NOREDRAW
|
3634 SWP_NOREPOSITION
| SWP_NOSENDCHANGING
| SWP_NOSIZE
);
3635 prev
= control
->hwnd
;
3638 /* put them back on the main list */
3639 list_move_head( &dialog
->controls
, &tab_chain
);
3642 static LRESULT
msi_dialog_oncreate( HWND hwnd
, LPCREATESTRUCTW cs
)
3644 static const WCHAR df
[] = {
3645 'D','e','f','a','u','l','t','U','I','F','o','n','t',0 };
3646 static const WCHAR dfv
[] = {
3647 'M','S',' ','S','h','e','l','l',' ','D','l','g',0 };
3648 msi_dialog
*dialog
= cs
->lpCreateParams
;
3649 MSIRECORD
*rec
= NULL
;
3650 LPWSTR title
= NULL
;
3653 TRACE("%p %p\n", dialog
, dialog
->package
);
3655 dialog
->hwnd
= hwnd
;
3656 SetWindowLongPtrW( hwnd
, GWLP_USERDATA
, (LONG_PTR
) dialog
);
3658 rec
= msi_get_dialog_record( dialog
);
3661 TRACE("No record found for dialog %s\n", debugstr_w(dialog
->name
));
3665 dialog
->scale
= msi_dialog_get_sans_serif_height(dialog
->hwnd
);
3667 msi_dialog_adjust_dialog_pos( dialog
, rec
, &pos
);
3669 dialog
->attributes
= MSI_RecordGetInteger( rec
, 6 );
3671 dialog
->default_font
= msi_dup_property( dialog
->package
->db
, df
);
3672 if (!dialog
->default_font
)
3674 dialog
->default_font
= strdupW(dfv
);
3675 msiobj_release( &rec
->hdr
);
3676 if (!dialog
->default_font
) return -1;
3679 title
= msi_get_deformatted_field( dialog
->package
, rec
, 7 );
3680 SetWindowTextW( hwnd
, title
);
3683 SetWindowPos( hwnd
, 0, pos
.left
, pos
.top
,
3684 pos
.right
- pos
.left
, pos
.bottom
- pos
.top
,
3685 SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_NOREDRAW
);
3687 msi_dialog_build_font_list( dialog
);
3688 msi_dialog_fill_controls( dialog
);
3689 msi_dialog_evaluate_control_conditions( dialog
);
3690 msi_dialog_set_tab_order( dialog
, MSI_RecordGetString( rec
, 8 ) );
3691 msiobj_release( &rec
->hdr
);
3696 static LRESULT
msi_dialog_oncommand( msi_dialog
*dialog
, WPARAM param
, HWND hwnd
)
3698 msi_control
*control
= NULL
;
3700 TRACE("%p %p %08lx\n", dialog
, hwnd
, param
);
3705 control
= msi_dialog_find_control( dialog
, dialog
->control_default
);
3707 case 2: /* escape */
3708 control
= msi_dialog_find_control( dialog
, dialog
->control_cancel
);
3711 control
= msi_dialog_find_control_by_hwnd( dialog
, hwnd
);
3716 if( control
->handler
)
3718 control
->handler( dialog
, control
, param
);
3719 msi_dialog_evaluate_control_conditions( dialog
);
3726 static LRESULT
msi_dialog_onnotify( msi_dialog
*dialog
, LPARAM param
)
3728 LPNMHDR nmhdr
= (LPNMHDR
) param
;
3729 msi_control
*control
= msi_dialog_find_control_by_hwnd( dialog
, nmhdr
->hwndFrom
);
3731 TRACE("%p %p\n", dialog
, nmhdr
->hwndFrom
);
3733 if ( control
&& control
->handler
)
3734 control
->handler( dialog
, control
, param
);
3739 static void dialog_setfocus( msi_dialog
*dialog
)
3741 HWND hwnd
= dialog
->hWndFocus
;
3743 hwnd
= GetNextDlgTabItem( dialog
->hwnd
, hwnd
, TRUE
);
3744 hwnd
= GetNextDlgTabItem( dialog
->hwnd
, hwnd
, FALSE
);
3746 dialog
->hWndFocus
= hwnd
;
3749 static LRESULT WINAPI
MSIDialog_WndProc( HWND hwnd
, UINT msg
,
3750 WPARAM wParam
, LPARAM lParam
)
3752 msi_dialog
*dialog
= (LPVOID
) GetWindowLongPtrW( hwnd
, GWLP_USERDATA
);
3754 TRACE("0x%04x\n", msg
);
3759 dialog
->package
->center_x
= LOWORD(lParam
) + dialog
->size
.cx
/ 2.0;
3760 dialog
->package
->center_y
= HIWORD(lParam
) + dialog
->size
.cy
/ 2.0;
3764 return msi_dialog_oncreate( hwnd
, (LPCREATESTRUCTW
)lParam
);
3767 return msi_dialog_oncommand( dialog
, wParam
, (HWND
)lParam
);
3770 if( LOWORD(wParam
) == WA_INACTIVE
)
3771 dialog
->hWndFocus
= GetFocus();
3773 dialog_setfocus( dialog
);
3777 dialog_setfocus( dialog
);
3780 /* bounce back to our subclassed static control */
3781 case WM_CTLCOLORSTATIC
:
3782 return SendMessageW( (HWND
) lParam
, WM_CTLCOLORSTATIC
, wParam
, lParam
);
3785 dialog
->hwnd
= NULL
;
3788 return msi_dialog_onnotify( dialog
, lParam
);
3790 return DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
3793 static void process_pending_messages( HWND hdlg
)
3797 while (PeekMessageW( &msg
, 0, 0, 0, PM_REMOVE
))
3799 if (hdlg
&& IsDialogMessageW( hdlg
, &msg
)) continue;
3800 TranslateMessage( &msg
);
3801 DispatchMessageW( &msg
);
3805 static UINT
dialog_run_message_loop( msi_dialog
*dialog
)
3810 if( uiThreadId
!= GetCurrentThreadId() )
3811 return SendMessageW( hMsiHiddenWindow
, WM_MSI_DIALOG_CREATE
, 0, (LPARAM
) dialog
);
3813 /* create the dialog window, don't show it yet */
3814 style
= WS_OVERLAPPED
;
3815 if( dialog
->attributes
& msidbDialogAttributesVisible
)
3816 style
|= WS_VISIBLE
;
3818 hwnd
= CreateWindowW( szMsiDialogClass
, dialog
->name
, style
,
3819 CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
,
3820 NULL
, NULL
, NULL
, dialog
);
3823 ERR("Failed to create dialog %s\n", debugstr_w( dialog
->name
));
3824 return ERROR_FUNCTION_FAILED
;
3827 ShowWindow( hwnd
, SW_SHOW
);
3828 /* UpdateWindow( hwnd ); - and causes the transparent static controls not to paint */
3830 if( dialog
->attributes
& msidbDialogAttributesModal
)
3832 while( !dialog
->finished
)
3834 MsgWaitForMultipleObjects( 0, NULL
, 0, INFINITE
, QS_ALLINPUT
);
3835 process_pending_messages( dialog
->hwnd
);
3839 return ERROR_IO_PENDING
;
3841 return ERROR_SUCCESS
;
3844 static LRESULT WINAPI
MSIHiddenWindowProc( HWND hwnd
, UINT msg
,
3845 WPARAM wParam
, LPARAM lParam
)
3847 msi_dialog
*dialog
= (msi_dialog
*) lParam
;
3849 TRACE("%d %p\n", msg
, dialog
);
3853 case WM_MSI_DIALOG_CREATE
:
3854 return dialog_run_message_loop( dialog
);
3855 case WM_MSI_DIALOG_DESTROY
:
3856 msi_dialog_destroy( dialog
);
3859 return DefWindowProcW( hwnd
, msg
, wParam
, lParam
);
3862 static BOOL
dialog_register_class( void )
3866 ZeroMemory( &cls
, sizeof cls
);
3867 cls
.lpfnWndProc
= MSIDialog_WndProc
;
3868 cls
.hInstance
= NULL
;
3869 cls
.hIcon
= LoadIconW(0, (LPWSTR
)IDI_APPLICATION
);
3870 cls
.hCursor
= LoadCursorW(0, (LPWSTR
)IDC_ARROW
);
3871 cls
.hbrBackground
= (HBRUSH
)(COLOR_3DFACE
+ 1);
3872 cls
.lpszMenuName
= NULL
;
3873 cls
.lpszClassName
= szMsiDialogClass
;
3875 if( !RegisterClassW( &cls
) )
3878 cls
.lpfnWndProc
= MSIHiddenWindowProc
;
3879 cls
.lpszClassName
= szMsiHiddenWindow
;
3881 if( !RegisterClassW( &cls
) )
3884 uiThreadId
= GetCurrentThreadId();
3886 hMsiHiddenWindow
= CreateWindowW( szMsiHiddenWindow
, NULL
, WS_OVERLAPPED
,
3887 0, 0, 100, 100, NULL
, NULL
, NULL
, NULL
);
3888 if( !hMsiHiddenWindow
)
3894 static msi_dialog
*dialog_create( MSIPACKAGE
*package
, const WCHAR
*name
, msi_dialog
*parent
,
3895 control_event_handler event_handler
)
3897 MSIRECORD
*rec
= NULL
;
3900 TRACE("%s\n", debugstr_w(name
));
3902 if (!hMsiHiddenWindow
) dialog_register_class();
3904 /* allocate the structure for the dialog to use */
3905 dialog
= msi_alloc_zero( FIELD_OFFSET( msi_dialog
, name
[strlenW( name
) + 1] ));
3908 strcpyW( dialog
->name
, name
);
3909 dialog
->parent
= parent
;
3910 msiobj_addref( &package
->hdr
);
3911 dialog
->package
= package
;
3912 dialog
->event_handler
= event_handler
;
3913 dialog
->finished
= 0;
3914 list_init( &dialog
->controls
);
3915 list_init( &dialog
->fonts
);
3917 /* verify that the dialog exists */
3918 rec
= msi_get_dialog_record( dialog
);
3921 msiobj_release( &package
->hdr
);
3925 dialog
->attributes
= MSI_RecordGetInteger( rec
, 6 );
3926 dialog
->control_default
= strdupW( MSI_RecordGetString( rec
, 9 ) );
3927 dialog
->control_cancel
= strdupW( MSI_RecordGetString( rec
, 10 ) );
3928 msiobj_release( &rec
->hdr
);
3933 void msi_dialog_end_dialog( msi_dialog
*dialog
)
3935 TRACE("%p\n", dialog
);
3936 dialog
->finished
= 1;
3937 PostMessageW(dialog
->hwnd
, WM_NULL
, 0, 0);
3940 void msi_dialog_check_messages( HANDLE handle
)
3944 /* in threads other than the UI thread, block */
3945 if( uiThreadId
!= GetCurrentThreadId() )
3947 if (!handle
) return;
3948 while (MsgWaitForMultipleObjectsEx( 1, &handle
, INFINITE
, QS_ALLINPUT
, 0 ) == WAIT_OBJECT_0
+ 1)
3951 while (PeekMessageW( &msg
, NULL
, 0, 0, PM_REMOVE
))
3953 TranslateMessage( &msg
);
3954 DispatchMessageW( &msg
);
3960 /* there's two choices for the UI thread */
3963 process_pending_messages( NULL
);
3969 * block here until somebody creates a new dialog or
3970 * the handle we're waiting on becomes ready
3972 r
= MsgWaitForMultipleObjects( 1, &handle
, 0, INFINITE
, QS_ALLINPUT
);
3973 if( r
== WAIT_OBJECT_0
)
3978 static void dialog_do_preview( msi_dialog
*dialog
)
3981 dialog
->attributes
|= msidbDialogAttributesVisible
;
3982 dialog
->attributes
&= ~msidbDialogAttributesModal
;
3983 dialog_run_message_loop( dialog
);
3986 static void free_subscriber( struct subscriber
*sub
)
3988 msi_free( sub
->event
);
3989 msi_free( sub
->control
);
3990 msi_free( sub
->attribute
);
3994 static void event_cleanup_subscriptions( MSIPACKAGE
*package
, const WCHAR
*dialog
)
3996 struct list
*item
, *next
;
3998 LIST_FOR_EACH_SAFE( item
, next
, &package
->subscriptions
)
4000 struct subscriber
*sub
= LIST_ENTRY( item
, struct subscriber
, entry
);
4002 if (strcmpW( sub
->dialog
->name
, dialog
)) continue;
4003 list_remove( &sub
->entry
);
4004 free_subscriber( sub
);
4008 void msi_dialog_destroy( msi_dialog
*dialog
)
4010 msi_font
*font
, *next
;
4012 if( uiThreadId
!= GetCurrentThreadId() )
4014 SendMessageW( hMsiHiddenWindow
, WM_MSI_DIALOG_DESTROY
, 0, (LPARAM
) dialog
);
4019 ShowWindow( dialog
->hwnd
, SW_HIDE
);
4022 DestroyWindow( dialog
->hwnd
);
4024 /* unsubscribe events */
4025 event_cleanup_subscriptions( dialog
->package
, dialog
->name
);
4027 /* destroy the list of controls */
4028 while( !list_empty( &dialog
->controls
) )
4032 t
= LIST_ENTRY( list_head( &dialog
->controls
),
4033 msi_control
, entry
);
4034 msi_destroy_control( t
);
4037 /* destroy the list of fonts */
4038 LIST_FOR_EACH_ENTRY_SAFE( font
, next
, &dialog
->fonts
, msi_font
, entry
)
4040 list_remove( &font
->entry
);
4041 DeleteObject( font
->hfont
);
4044 msi_free( dialog
->default_font
);
4046 msi_free( dialog
->control_default
);
4047 msi_free( dialog
->control_cancel
);
4048 msiobj_release( &dialog
->package
->hdr
);
4049 dialog
->package
= NULL
;
4053 void msi_dialog_unregister_class( void )
4055 DestroyWindow( hMsiHiddenWindow
);
4056 hMsiHiddenWindow
= NULL
;
4057 UnregisterClassW( szMsiDialogClass
, NULL
);
4058 UnregisterClassW( szMsiHiddenWindow
, NULL
);
4062 void msi_event_cleanup_all_subscriptions( MSIPACKAGE
*package
)
4064 struct list
*item
, *next
;
4066 LIST_FOR_EACH_SAFE( item
, next
, &package
->subscriptions
)
4068 struct subscriber
*sub
= LIST_ENTRY( item
, struct subscriber
, entry
);
4069 list_remove( &sub
->entry
);
4070 free_subscriber( sub
);
4074 static UINT
error_dialog_handler( msi_dialog
*dialog
, const WCHAR
*event
, const WCHAR
*argument
)
4076 static const WCHAR end_dialog
[] = {'E','n','d','D','i','a','l','o','g',0};
4077 static const WCHAR error_abort
[] = {'E','r','r','o','r','A','b','o','r','t',0};
4078 static const WCHAR error_cancel
[] = {'E','r','r','o','r','C','a','n','c','e','l',0};
4079 static const WCHAR error_no
[] = {'E','r','r','o','r','N','o',0};
4080 static const WCHAR result_prop
[] = {
4081 'M','S','I','E','r','r','o','r','D','i','a','l','o','g','R','e','s','u','l','t',0
4084 if ( strcmpW( event
, end_dialog
) )
4085 return ERROR_SUCCESS
;
4087 if ( !strcmpW( argument
, error_abort
) || !strcmpW( argument
, error_cancel
) ||
4088 !strcmpW( argument
, error_no
) )
4090 msi_set_property( dialog
->package
->db
, result_prop
, error_abort
, -1 );
4093 msi_event_cleanup_all_subscriptions( dialog
->package
);
4094 msi_dialog_end_dialog( dialog
);
4096 return ERROR_SUCCESS
;
4099 static UINT
msi_error_dialog_set_error( MSIPACKAGE
*package
, LPWSTR error_dialog
, LPWSTR error
)
4103 static const WCHAR update
[] =
4104 {'U','P','D','A','T','E',' ','`','C','o','n','t','r','o','l','`',' ',
4105 'S','E','T',' ','`','T','e','x','t','`',' ','=',' ','\'','%','s','\'',' ',
4106 'W','H','E','R','E', ' ','`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',' ',
4107 'A','N','D',' ','`','C','o','n','t','r','o','l','`',' ','=',' ',
4108 '\'','E','r','r','o','r','T','e','x','t','\'',0};
4110 row
= MSI_QueryGetRecord( package
->db
, update
, error
, error_dialog
);
4112 return ERROR_FUNCTION_FAILED
;
4114 msiobj_release(&row
->hdr
);
4115 return ERROR_SUCCESS
;
4118 UINT
msi_spawn_error_dialog( MSIPACKAGE
*package
, LPWSTR error_dialog
, LPWSTR error
)
4121 WCHAR result
[MAX_PATH
];
4122 UINT r
= ERROR_SUCCESS
;
4123 DWORD size
= MAX_PATH
;
4126 static const WCHAR pn_prop
[] = {'P','r','o','d','u','c','t','N','a','m','e',0};
4127 static const WCHAR title_fmt
[] = {'%','s',' ','W','a','r','n','i','n','g',0};
4128 static const WCHAR error_abort
[] = {'E','r','r','o','r','A','b','o','r','t',0};
4129 static const WCHAR result_prop
[] = {
4130 'M','S','I','E','r','r','o','r','D','i','a','l','o','g','R','e','s','u','l','t',0
4133 if ((package
->ui_level
& INSTALLUILEVEL_MASK
) == INSTALLUILEVEL_NONE
) return ERROR_SUCCESS
;
4135 if ( !error_dialog
)
4137 LPWSTR product_name
= msi_dup_property( package
->db
, pn_prop
);
4138 WCHAR title
[MAX_PATH
];
4140 sprintfW( title
, title_fmt
, product_name
);
4141 res
= MessageBoxW( NULL
, error
, title
, MB_OKCANCEL
| MB_ICONWARNING
);
4143 msi_free( product_name
);
4146 return ERROR_SUCCESS
;
4148 return ERROR_FUNCTION_FAILED
;
4151 r
= msi_error_dialog_set_error( package
, error_dialog
, error
);
4152 if ( r
!= ERROR_SUCCESS
)
4155 dialog
= dialog_create( package
, error_dialog
, package
->dialog
, error_dialog_handler
);
4157 return ERROR_FUNCTION_FAILED
;
4159 dialog
->finished
= FALSE
;
4160 r
= dialog_run_message_loop( dialog
);
4161 if ( r
!= ERROR_SUCCESS
)
4164 r
= msi_get_property( package
->db
, result_prop
, result
, &size
);
4165 if ( r
!= ERROR_SUCCESS
)
4168 if ( !strcmpW( result
, error_abort
) )
4169 r
= ERROR_FUNCTION_FAILED
;
4172 msi_dialog_destroy( dialog
);
4177 static void MSI_ClosePreview( MSIOBJECTHDR
*arg
)
4179 MSIPREVIEW
*preview
= (MSIPREVIEW
*)arg
;
4180 msiobj_release( &preview
->package
->hdr
);
4183 static MSIPREVIEW
*MSI_EnableUIPreview( MSIDATABASE
*db
)
4185 MSIPREVIEW
*preview
= NULL
;
4186 MSIPACKAGE
*package
;
4188 package
= MSI_CreatePackage( db
, NULL
);
4191 preview
= alloc_msiobject( MSIHANDLETYPE_PREVIEW
, sizeof(MSIPREVIEW
), MSI_ClosePreview
);
4194 preview
->package
= package
;
4195 msiobj_addref( &package
->hdr
);
4197 msiobj_release( &package
->hdr
);
4202 UINT WINAPI
MsiEnableUIPreview( MSIHANDLE hdb
, MSIHANDLE
*phPreview
)
4205 MSIPREVIEW
*preview
;
4206 UINT r
= ERROR_FUNCTION_FAILED
;
4208 TRACE("%d %p\n", hdb
, phPreview
);
4210 db
= msihandle2msiinfo( hdb
, MSIHANDLETYPE_DATABASE
);
4213 IWineMsiRemoteDatabase
*remote_database
;
4215 remote_database
= (IWineMsiRemoteDatabase
*)msi_get_remote( hdb
);
4216 if (!remote_database
)
4217 return ERROR_INVALID_HANDLE
;
4221 IWineMsiRemoteDatabase_Release( remote_database
);
4222 WARN("MsiEnableUIPreview not allowed during a custom action!\n");
4224 return ERROR_FUNCTION_FAILED
;
4226 preview
= MSI_EnableUIPreview( db
);
4229 *phPreview
= alloc_msihandle( &preview
->hdr
);
4230 msiobj_release( &preview
->hdr
);
4233 r
= ERROR_NOT_ENOUGH_MEMORY
;
4235 msiobj_release( &db
->hdr
);
4239 static UINT
preview_event_handler( msi_dialog
*dialog
, const WCHAR
*event
, const WCHAR
*argument
)
4241 MESSAGE("Preview dialog event '%s' (arg='%s')\n", debugstr_w(event
), debugstr_w(argument
));
4242 return ERROR_SUCCESS
;
4245 static UINT
MSI_PreviewDialogW( MSIPREVIEW
*preview
, LPCWSTR szDialogName
)
4247 msi_dialog
*dialog
= NULL
;
4248 UINT r
= ERROR_SUCCESS
;
4250 if (preview
->dialog
)
4251 msi_dialog_destroy( preview
->dialog
);
4253 /* an empty name means we should just destroy the current preview dialog */
4256 dialog
= dialog_create( preview
->package
, szDialogName
, NULL
, preview_event_handler
);
4258 dialog_do_preview( dialog
);
4260 r
= ERROR_FUNCTION_FAILED
;
4262 preview
->dialog
= dialog
;
4266 UINT WINAPI
MsiPreviewDialogW( MSIHANDLE hPreview
, LPCWSTR szDialogName
)
4268 MSIPREVIEW
*preview
;
4271 TRACE("%d %s\n", hPreview
, debugstr_w(szDialogName
));
4273 preview
= msihandle2msiinfo( hPreview
, MSIHANDLETYPE_PREVIEW
);
4275 return ERROR_INVALID_HANDLE
;
4277 r
= MSI_PreviewDialogW( preview
, szDialogName
);
4278 msiobj_release( &preview
->hdr
);
4282 UINT WINAPI
MsiPreviewDialogA( MSIHANDLE hPreview
, LPCSTR szDialogName
)
4287 TRACE("%d %s\n", hPreview
, debugstr_a(szDialogName
));
4291 strW
= strdupAtoW( szDialogName
);
4293 return ERROR_OUTOFMEMORY
;
4295 r
= MsiPreviewDialogW( hPreview
, strW
);
4300 UINT WINAPI
MsiPreviewBillboardW( MSIHANDLE hPreview
, LPCWSTR szControlName
, LPCWSTR szBillboard
)
4302 FIXME("%d %s %s\n", hPreview
, debugstr_w(szControlName
), debugstr_w(szBillboard
));
4303 return ERROR_CALL_NOT_IMPLEMENTED
;
4306 UINT WINAPI
MsiPreviewBillboardA( MSIHANDLE hPreview
, LPCSTR szControlName
, LPCSTR szBillboard
)
4308 FIXME("%d %s %s\n", hPreview
, debugstr_a(szControlName
), debugstr_a(szBillboard
));
4309 return ERROR_CALL_NOT_IMPLEMENTED
;
4312 typedef UINT (*event_handler
)( msi_dialog
*, const WCHAR
* );
4314 struct control_event
4317 event_handler handler
;
4320 static UINT
dialog_event_handler( msi_dialog
*, const WCHAR
*, const WCHAR
* );
4322 /* create a dialog box and run it if it's modal */
4323 static UINT
event_do_dialog( MSIPACKAGE
*package
, const WCHAR
*name
, msi_dialog
*parent
, BOOL destroy_modeless
)
4328 /* create a new dialog */
4329 dialog
= dialog_create( package
, name
, parent
, dialog_event_handler
);
4332 /* kill the current modeless dialog */
4333 if (destroy_modeless
&& package
->dialog
)
4335 msi_dialog_destroy( package
->dialog
);
4336 package
->dialog
= NULL
;
4339 /* modeless dialogs return an error message */
4340 r
= dialog_run_message_loop( dialog
);
4341 if (r
== ERROR_SUCCESS
)
4342 msi_dialog_destroy( dialog
);
4344 package
->dialog
= dialog
;
4346 else r
= ERROR_FUNCTION_FAILED
;
4350 /* end a modal dialog box */
4351 static UINT
event_end_dialog( msi_dialog
*dialog
, const WCHAR
*argument
)
4353 static const WCHAR exitW
[] = {'E','x','i','t',0};
4354 static const WCHAR retryW
[] = {'R','e','t','r','y',0};
4355 static const WCHAR ignoreW
[] = {'I','g','n','o','r','e',0};
4356 static const WCHAR returnW
[] = {'R','e','t','u','r','n',0};
4358 if (!strcmpW( argument
, exitW
))
4359 dialog
->package
->CurrentInstallState
= ERROR_INSTALL_USEREXIT
;
4360 else if (!strcmpW( argument
, retryW
))
4361 dialog
->package
->CurrentInstallState
= ERROR_INSTALL_SUSPEND
;
4362 else if (!strcmpW( argument
, ignoreW
))
4363 dialog
->package
->CurrentInstallState
= ERROR_SUCCESS
;
4364 else if (!strcmpW( argument
, returnW
))
4366 msi_dialog
*parent
= dialog
->parent
;
4367 msi_free( dialog
->package
->next_dialog
);
4368 dialog
->package
->next_dialog
= (parent
) ? strdupW( parent
->name
) : NULL
;
4369 dialog
->package
->CurrentInstallState
= ERROR_SUCCESS
;
4373 ERR("Unknown argument string %s\n", debugstr_w(argument
));
4374 dialog
->package
->CurrentInstallState
= ERROR_FUNCTION_FAILED
;
4376 event_cleanup_subscriptions( dialog
->package
, dialog
->name
);
4377 msi_dialog_end_dialog( dialog
);
4378 return ERROR_SUCCESS
;
4381 /* transition from one modal dialog to another modal dialog */
4382 static UINT
event_new_dialog( msi_dialog
*dialog
, const WCHAR
*argument
)
4384 /* store the name of the next dialog, and signal this one to end */
4385 dialog
->package
->next_dialog
= strdupW( argument
);
4386 msi_event_cleanup_all_subscriptions( dialog
->package
);
4387 msi_dialog_end_dialog( dialog
);
4388 return ERROR_SUCCESS
;
4391 /* create a new child dialog of an existing modal dialog */
4392 static UINT
event_spawn_dialog( msi_dialog
*dialog
, const WCHAR
*argument
)
4394 /* don't destroy a modeless dialogs that might be our parent */
4395 event_do_dialog( dialog
->package
, argument
, dialog
, FALSE
);
4396 if (dialog
->package
->CurrentInstallState
!= ERROR_SUCCESS
) msi_dialog_end_dialog( dialog
);
4397 return ERROR_SUCCESS
;
4400 /* creates a dialog that remains up for a period of time based on a condition */
4401 static UINT
event_spawn_wait_dialog( msi_dialog
*dialog
, const WCHAR
*argument
)
4403 FIXME("doing nothing\n");
4404 return ERROR_SUCCESS
;
4407 static UINT
event_do_action( msi_dialog
*dialog
, const WCHAR
*argument
)
4409 ACTION_PerformAction( dialog
->package
, argument
, SCRIPT_NONE
);
4410 return ERROR_SUCCESS
;
4413 static UINT
event_add_local( msi_dialog
*dialog
, const WCHAR
*argument
)
4415 MSIFEATURE
*feature
;
4417 LIST_FOR_EACH_ENTRY( feature
, &dialog
->package
->features
, MSIFEATURE
, entry
)
4419 if (!strcmpW( argument
, feature
->Feature
) || !strcmpW( argument
, szAll
))
4421 if (feature
->ActionRequest
!= INSTALLSTATE_LOCAL
)
4422 msi_set_property( dialog
->package
->db
, szPreselected
, szOne
, -1 );
4423 MSI_SetFeatureStateW( dialog
->package
, feature
->Feature
, INSTALLSTATE_LOCAL
);
4426 return ERROR_SUCCESS
;
4429 static UINT
event_remove( msi_dialog
*dialog
, const WCHAR
*argument
)
4431 MSIFEATURE
*feature
;
4433 LIST_FOR_EACH_ENTRY( feature
, &dialog
->package
->features
, MSIFEATURE
, entry
)
4435 if (!strcmpW( argument
, feature
->Feature
) || !strcmpW( argument
, szAll
))
4437 if (feature
->ActionRequest
!= INSTALLSTATE_ABSENT
)
4438 msi_set_property( dialog
->package
->db
, szPreselected
, szOne
, -1 );
4439 MSI_SetFeatureStateW( dialog
->package
, feature
->Feature
, INSTALLSTATE_ABSENT
);
4442 return ERROR_SUCCESS
;
4445 static UINT
event_add_source( msi_dialog
*dialog
, const WCHAR
*argument
)
4447 MSIFEATURE
*feature
;
4449 LIST_FOR_EACH_ENTRY( feature
, &dialog
->package
->features
, MSIFEATURE
, entry
)
4451 if (!strcmpW( argument
, feature
->Feature
) || !strcmpW( argument
, szAll
))
4453 if (feature
->ActionRequest
!= INSTALLSTATE_SOURCE
)
4454 msi_set_property( dialog
->package
->db
, szPreselected
, szOne
, -1 );
4455 MSI_SetFeatureStateW( dialog
->package
, feature
->Feature
, INSTALLSTATE_SOURCE
);
4458 return ERROR_SUCCESS
;
4461 void msi_event_fire( MSIPACKAGE
*package
, const WCHAR
*event
, MSIRECORD
*rec
)
4463 struct subscriber
*sub
;
4465 TRACE("firing event %s\n", debugstr_w(event
));
4467 LIST_FOR_EACH_ENTRY( sub
, &package
->subscriptions
, struct subscriber
, entry
)
4469 if (strcmpiW( sub
->event
, event
)) continue;
4470 dialog_handle_event( sub
->dialog
, sub
->control
, sub
->attribute
, rec
);
4474 static UINT
event_set_target_path( msi_dialog
*dialog
, const WCHAR
*argument
)
4476 WCHAR
*path
= msi_dup_property( dialog
->package
->db
, argument
);
4477 MSIRECORD
*rec
= MSI_CreateRecord( 1 );
4478 UINT r
= ERROR_SUCCESS
;
4480 MSI_RecordSetStringW( rec
, 1, path
);
4481 msi_event_fire( dialog
->package
, szSelectionPath
, rec
);
4484 /* failure to set the path halts the executing of control events */
4485 r
= MSI_SetTargetPathW( dialog
->package
, argument
, path
);
4488 msi_free( &rec
->hdr
);
4492 static UINT
event_reset( msi_dialog
*dialog
, const WCHAR
*argument
)
4494 msi_dialog_reset( dialog
);
4495 return ERROR_SUCCESS
;
4498 /* Return ERROR_SUCCESS if dialog is process and ERROR_FUNCTION_FAILED
4499 * if the given parameter is not a dialog box
4501 UINT
ACTION_DialogBox( MSIPACKAGE
*package
, const WCHAR
*dialog
)
4505 if (package
->next_dialog
) ERR("Already got next dialog... ignoring it\n");
4506 package
->next_dialog
= NULL
;
4508 /* Dialogs are chained by filling in the next_dialog member
4509 * of the package structure, then terminating the current dialog.
4510 * The code below sees the next_dialog member set, and runs the
4512 * We fall out of the loop below if we come across a modeless
4513 * dialog, as it returns ERROR_IO_PENDING when we try to run
4516 r
= event_do_dialog( package
, dialog
, NULL
, TRUE
);
4517 while (r
== ERROR_SUCCESS
&& package
->next_dialog
)
4519 WCHAR
*name
= package
->next_dialog
;
4521 package
->next_dialog
= NULL
;
4522 r
= event_do_dialog( package
, name
, NULL
, TRUE
);
4525 if (r
== ERROR_IO_PENDING
) r
= ERROR_SUCCESS
;
4529 static UINT
event_set_install_level( msi_dialog
*dialog
, const WCHAR
*argument
)
4531 int level
= atolW( argument
);
4533 TRACE("setting install level to %d\n", level
);
4534 return MSI_SetInstallLevel( dialog
->package
, level
);
4537 static UINT
event_directory_list_up( msi_dialog
*dialog
, const WCHAR
*argument
)
4539 return msi_dialog_directorylist_up( dialog
);
4542 static UINT
event_reinstall_mode( msi_dialog
*dialog
, const WCHAR
*argument
)
4544 return msi_set_property( dialog
->package
->db
, szReinstallMode
, argument
, -1 );
4547 static UINT
event_reinstall( msi_dialog
*dialog
, const WCHAR
*argument
)
4549 return msi_set_property( dialog
->package
->db
, szReinstall
, argument
, -1 );
4552 static UINT
event_validate_product_id( msi_dialog
*dialog
, const WCHAR
*argument
)
4554 return msi_validate_product_id( dialog
->package
);
4557 static const WCHAR end_dialogW
[] = {'E','n','d','D','i','a','l','o','g',0};
4558 static const WCHAR new_dialogW
[] = {'N','e','w','D','i','a','l','o','g',0};
4559 static const WCHAR spawn_dialogW
[] = {'S','p','a','w','n','D','i','a','l','o','g',0};
4560 static const WCHAR spawn_wait_dialogW
[] = {'S','p','a','w','n','W','a','i','t','D','i','a','l','o','g',0};
4561 static const WCHAR do_actionW
[] = {'D','o','A','c','t','i','o','n',0};
4562 static const WCHAR add_localW
[] = {'A','d','d','L','o','c','a','l',0};
4563 static const WCHAR removeW
[] = {'R','e','m','o','v','e',0};
4564 static const WCHAR add_sourceW
[] = {'A','d','d','S','o','u','r','c','e',0};
4565 static const WCHAR set_target_pathW
[] = {'S','e','t','T','a','r','g','e','t','P','a','t','h',0};
4566 static const WCHAR resetW
[] = {'R','e','s','e','t',0};
4567 static const WCHAR set_install_levelW
[] = {'S','e','t','I','n','s','t','a','l','l','L','e','v','e','l',0};
4568 static const WCHAR directory_list_upW
[] = {'D','i','r','e','c','t','o','r','y','L','i','s','t','U','p',0};
4569 static const WCHAR selection_browseW
[] = {'S','e','l','e','c','t','i','o','n','B','r','o','w','s','e',0};
4570 static const WCHAR reinstall_modeW
[] = {'R','e','i','n','s','t','a','l','l','M','o','d','e',0};
4571 static const WCHAR reinstallW
[] = {'R','e','i','n','s','t','a','l','l',0};
4572 static const WCHAR validate_product_idW
[] = {'V','a','l','i','d','a','t','e','P','r','o','d','u','c','t','I','D',0};
4574 static const struct control_event control_events
[] =
4576 { end_dialogW
, event_end_dialog
},
4577 { new_dialogW
, event_new_dialog
},
4578 { spawn_dialogW
, event_spawn_dialog
},
4579 { spawn_wait_dialogW
, event_spawn_wait_dialog
},
4580 { do_actionW
, event_do_action
},
4581 { add_localW
, event_add_local
},
4582 { removeW
, event_remove
},
4583 { add_sourceW
, event_add_source
},
4584 { set_target_pathW
, event_set_target_path
},
4585 { resetW
, event_reset
},
4586 { set_install_levelW
, event_set_install_level
},
4587 { directory_list_upW
, event_directory_list_up
},
4588 { selection_browseW
, event_spawn_dialog
},
4589 { reinstall_modeW
, event_reinstall_mode
},
4590 { reinstallW
, event_reinstall
},
4591 { validate_product_idW
, event_validate_product_id
},
4595 static UINT
dialog_event_handler( msi_dialog
*dialog
, const WCHAR
*event
, const WCHAR
*argument
)
4599 TRACE("handling event %s\n", debugstr_w(event
));
4601 if (!event
) return ERROR_SUCCESS
;
4603 for (i
= 0; control_events
[i
].event
; i
++)
4605 if (!strcmpW( control_events
[i
].event
, event
))
4606 return control_events
[i
].handler( dialog
, argument
);
4608 FIXME("unhandled event %s arg(%s)\n", debugstr_w(event
), debugstr_w(argument
));
4609 return ERROR_SUCCESS
;