2 * Implementation of the Microsoft Installer (msi.dll)
4 * Copyright 2005 Mike McCormack for CodeWeavers
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #define NONAMELESSUNION
23 #define NONAMELESSSTRUCT
42 #include "wine/debug.h"
43 #include "wine/unicode.h"
45 WINE_DEFAULT_DEBUG_CHANNEL(msi
);
48 extern HINSTANCE msi_hInstance
;
50 struct msi_control_tag
;
51 typedef struct msi_control_tag msi_control
;
52 typedef UINT (*msi_handler
)( msi_dialog
*, msi_control
*, WPARAM
);
53 typedef void (*msi_update
)( msi_dialog
*, msi_control
* );
55 struct msi_control_tag
68 float progress_current
;
74 typedef struct msi_font_tag
76 struct msi_font_tag
*next
;
86 msi_dialog_event_handler event_handler
;
96 LPWSTR control_default
;
97 LPWSTR control_cancel
;
101 typedef UINT (*msi_dialog_control_func
)( msi_dialog
*dialog
, MSIRECORD
*rec
);
102 struct control_handler
104 LPCWSTR control_type
;
105 msi_dialog_control_func func
;
114 } radio_button_group_descr
;
116 static const WCHAR szMsiDialogClass
[] = {
117 'M','s','i','D','i','a','l','o','g','C','l','o','s','e','C','l','a','s','s',0
119 static const WCHAR szMsiHiddenWindow
[] = {
120 'M','s','i','H','i','d','d','e','n','W','i','n','d','o','w',0 };
121 static const WCHAR szStatic
[] = { 'S','t','a','t','i','c',0 };
122 static const WCHAR szButton
[] = { 'B','U','T','T','O','N', 0 };
123 static const WCHAR szButtonData
[] = { 'M','S','I','D','A','T','A',0 };
124 static const WCHAR szProgress
[] = { 'P','r','o','g','r','e','s','s',0 };
125 static const WCHAR szText
[] = { 'T','e','x','t',0 };
126 static const WCHAR szPushButton
[] = { 'P','u','s','h','B','u','t','t','o','n',0 };
127 static const WCHAR szLine
[] = { 'L','i','n','e',0 };
128 static const WCHAR szBitmap
[] = { 'B','i','t','m','a','p',0 };
129 static const WCHAR szCheckBox
[] = { 'C','h','e','c','k','B','o','x',0 };
130 static const WCHAR szScrollableText
[] = {
131 'S','c','r','o','l','l','a','b','l','e','T','e','x','t',0 };
132 static const WCHAR szComboBox
[] = { 'C','o','m','b','o','B','o','x',0 };
133 static const WCHAR szEdit
[] = { 'E','d','i','t',0 };
134 static const WCHAR szMaskedEdit
[] = { 'M','a','s','k','e','d','E','d','i','t',0 };
135 static const WCHAR szPathEdit
[] = { 'P','a','t','h','E','d','i','t',0 };
136 static const WCHAR szProgressBar
[] = {
137 'P','r','o','g','r','e','s','s','B','a','r',0 };
138 static const WCHAR szRadioButtonGroup
[] = {
139 'R','a','d','i','o','B','u','t','t','o','n','G','r','o','u','p',0 };
140 static const WCHAR szIcon
[] = { 'I','c','o','n',0 };
141 static const WCHAR szSelectionTree
[] = {
142 'S','e','l','e','c','t','i','o','n','T','r','e','e',0 };
143 static const WCHAR szGroupBox
[] = { 'G','r','o','u','p','B','o','x',0 };
144 static const WCHAR szListBox
[] = { 'L','i','s','t','B','o','x',0 };
145 static const WCHAR szDirectoryCombo
[] = { 'D','i','r','e','c','t','o','r','y','C','o','m','b','o',0 };
146 static const WCHAR szDirectoryList
[] = { 'D','i','r','e','c','t','o','r','y','L','i','s','t',0 };
147 static const WCHAR szVolumeCostList
[] = { 'V','o','l','u','m','e','C','o','s','t','L','i','s','t',0 };
148 static const WCHAR szVolumeSelectCombo
[] = { 'V','o','l','u','m','e','S','e','l','e','c','t','C','o','m','b','o',0 };
149 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};
150 static const WCHAR szSelectionPath
[] = {'S','e','l','e','c','t','i','o','n','P','a','t','h',0};
151 static const WCHAR szProperty
[] = {'P','r','o','p','e','r','t','y',0};
153 static UINT
msi_dialog_checkbox_handler( msi_dialog
*, msi_control
*, WPARAM
);
154 static void msi_dialog_checkbox_sync_state( msi_dialog
*, msi_control
* );
155 static UINT
msi_dialog_button_handler( msi_dialog
*, msi_control
*, WPARAM
);
156 static UINT
msi_dialog_edit_handler( msi_dialog
*, msi_control
*, WPARAM
);
157 static UINT
msi_dialog_radiogroup_handler( msi_dialog
*, msi_control
*, WPARAM
);
158 static UINT
msi_dialog_evaluate_control_conditions( msi_dialog
*dialog
);
159 static LRESULT WINAPI
MSIRadioGroup_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
);
160 static MSIFEATURE
*msi_seltree_get_selected_feature( msi_control
*control
);
162 /* dialog sequencing */
164 #define WM_MSI_DIALOG_CREATE (WM_USER+0x100)
165 #define WM_MSI_DIALOG_DESTROY (WM_USER+0x101)
167 static DWORD uiThreadId
;
168 static HWND hMsiHiddenWindow
;
170 static INT
msi_dialog_scale_unit( msi_dialog
*dialog
, INT val
)
172 return (dialog
->scale
* val
+ 5) / 10;
175 static msi_control
*msi_dialog_find_control( msi_dialog
*dialog
, LPCWSTR name
)
177 msi_control
*control
;
183 LIST_FOR_EACH_ENTRY( control
, &dialog
->controls
, msi_control
, entry
)
184 if( !strcmpW( control
->name
, name
) ) /* FIXME: case sensitive? */
189 static msi_control
*msi_dialog_find_control_by_type( msi_dialog
*dialog
, LPCWSTR type
)
191 msi_control
*control
;
197 LIST_FOR_EACH_ENTRY( control
, &dialog
->controls
, msi_control
, entry
)
198 if( !strcmpW( control
->type
, type
) ) /* FIXME: case sensitive? */
203 static msi_control
*msi_dialog_find_control_by_hwnd( msi_dialog
*dialog
, HWND hwnd
)
205 msi_control
*control
;
209 LIST_FOR_EACH_ENTRY( control
, &dialog
->controls
, msi_control
, entry
)
210 if( hwnd
== control
->hwnd
)
215 static LPWSTR
msi_get_deformatted_field( MSIPACKAGE
*package
, MSIRECORD
*rec
, int field
)
217 LPCWSTR str
= MSI_RecordGetString( rec
, field
);
221 deformat_string( package
, str
, &ret
);
225 static LPWSTR
msi_dialog_dup_property( msi_dialog
*dialog
, LPCWSTR property
, BOOL indirect
)
233 prop
= msi_dup_property( dialog
->package
, property
);
236 prop
= strdupW( property
);
241 msi_dialog
*msi_dialog_get_parent( msi_dialog
*dialog
)
243 return dialog
->parent
;
246 LPWSTR
msi_dialog_get_name( msi_dialog
*dialog
)
252 * msi_dialog_get_style
254 * Extract the {\style} string from the front of the text to display and
255 * update the pointer. Only the last style in a list is applied.
257 static LPWSTR
msi_dialog_get_style( LPCWSTR p
, LPCWSTR
*rest
)
268 while ((first
= strchrW( p
, '{' )) && (q
= strchrW( first
+ 1, '}' )))
271 if( *p
!= '\\' && *p
!= '&' )
274 /* little bit of sanity checking to stop us getting confused with RTF */
275 for( i
=++p
; i
<q
; i
++ )
276 if( *i
== '}' || *i
== '\\' )
286 ret
= msi_alloc( len
*sizeof(WCHAR
) );
289 memcpy( ret
, p
, len
*sizeof(WCHAR
) );
294 static UINT
msi_dialog_add_font( MSIRECORD
*rec
, LPVOID param
)
296 msi_dialog
*dialog
= param
;
303 /* create a font and add it to the list */
304 name
= MSI_RecordGetString( rec
, 1 );
305 font
= msi_alloc( sizeof *font
+ strlenW( name
)*sizeof (WCHAR
) );
306 strcpyW( font
->name
, name
);
307 font
->next
= dialog
->font_list
;
308 dialog
->font_list
= font
;
310 font
->color
= MSI_RecordGetInteger( rec
, 4 );
312 memset( &lf
, 0, sizeof lf
);
313 face
= MSI_RecordGetString( rec
, 2 );
314 lf
.lfHeight
= MSI_RecordGetInteger( rec
, 3 );
315 style
= MSI_RecordGetInteger( rec
, 5 );
316 if( style
& msidbTextStyleStyleBitsBold
)
317 lf
.lfWeight
= FW_BOLD
;
318 if( style
& msidbTextStyleStyleBitsItalic
)
320 if( style
& msidbTextStyleStyleBitsUnderline
)
321 lf
.lfUnderline
= TRUE
;
322 if( style
& msidbTextStyleStyleBitsStrike
)
323 lf
.lfStrikeOut
= TRUE
;
324 lstrcpynW( lf
.lfFaceName
, face
, LF_FACESIZE
);
326 /* adjust the height */
327 hdc
= GetDC( dialog
->hwnd
);
330 lf
.lfHeight
= -MulDiv(lf
.lfHeight
, GetDeviceCaps(hdc
, LOGPIXELSY
), 72);
331 ReleaseDC( dialog
->hwnd
, hdc
);
334 font
->hfont
= CreateFontIndirectW( &lf
);
336 TRACE("Adding font style %s\n", debugstr_w(font
->name
) );
338 return ERROR_SUCCESS
;
341 static msi_font
*msi_dialog_find_font( msi_dialog
*dialog
, LPCWSTR name
)
345 for( font
= dialog
->font_list
; font
; font
= font
->next
)
346 if( !strcmpW( font
->name
, name
) ) /* FIXME: case sensitive? */
352 static UINT
msi_dialog_set_font( msi_dialog
*dialog
, HWND hwnd
, LPCWSTR name
)
356 font
= msi_dialog_find_font( dialog
, name
);
358 SendMessageW( hwnd
, WM_SETFONT
, (WPARAM
) font
->hfont
, TRUE
);
360 ERR("No font entry for %s\n", debugstr_w(name
));
361 return ERROR_SUCCESS
;
364 static UINT
msi_dialog_build_font_list( msi_dialog
*dialog
)
366 static const WCHAR query
[] = {
367 'S','E','L','E','C','T',' ','*',' ',
368 'F','R','O','M',' ','`','T','e','x','t','S','t','y','l','e','`',' ',0
371 MSIQUERY
*view
= NULL
;
373 TRACE("dialog %p\n", dialog
);
375 r
= MSI_OpenQuery( dialog
->package
->db
, &view
, query
);
376 if( r
!= ERROR_SUCCESS
)
379 r
= MSI_IterateRecords( view
, NULL
, msi_dialog_add_font
, dialog
);
380 msiobj_release( &view
->hdr
);
385 static void msi_destroy_control( msi_control
*t
)
387 list_remove( &t
->entry
);
388 /* leave dialog->hwnd - destroying parent destroys child windows */
389 msi_free( t
->property
);
390 msi_free( t
->value
);
392 DeleteObject( t
->hBitmap
);
394 DestroyIcon( t
->hIcon
);
395 msi_free( t
->tabnext
);
398 FreeLibrary( t
->hDll
);
402 static msi_control
*msi_dialog_create_window( msi_dialog
*dialog
,
403 MSIRECORD
*rec
, DWORD exstyle
, LPCWSTR szCls
, LPCWSTR name
, LPCWSTR text
,
404 DWORD style
, HWND parent
)
406 DWORD x
, y
, width
, height
;
407 LPWSTR font
= NULL
, title_font
= NULL
;
408 LPCWSTR title
= NULL
;
409 msi_control
*control
;
413 control
= msi_alloc( sizeof *control
+ strlenW(name
)*sizeof(WCHAR
) );
417 strcpyW( control
->name
, name
);
418 list_add_head( &dialog
->controls
, &control
->entry
);
419 control
->handler
= NULL
;
420 control
->property
= NULL
;
421 control
->value
= NULL
;
422 control
->hBitmap
= NULL
;
423 control
->hIcon
= NULL
;
424 control
->hDll
= NULL
;
425 control
->tabnext
= strdupW( MSI_RecordGetString( rec
, 11) );
426 control
->type
= strdupW( MSI_RecordGetString( rec
, 3 ) );
427 control
->progress_current
= 0;
428 control
->progress_max
= 100;
430 x
= MSI_RecordGetInteger( rec
, 4 );
431 y
= MSI_RecordGetInteger( rec
, 5 );
432 width
= MSI_RecordGetInteger( rec
, 6 );
433 height
= MSI_RecordGetInteger( rec
, 7 );
435 x
= msi_dialog_scale_unit( dialog
, x
);
436 y
= msi_dialog_scale_unit( dialog
, y
);
437 width
= msi_dialog_scale_unit( dialog
, width
);
438 height
= msi_dialog_scale_unit( dialog
, height
);
442 deformat_string( dialog
->package
, text
, &title_font
);
443 font
= msi_dialog_get_style( title_font
, &title
);
446 control
->hwnd
= CreateWindowExW( exstyle
, szCls
, title
, style
,
447 x
, y
, width
, height
, parent
, NULL
, NULL
, NULL
);
449 TRACE("Dialog %s control %s hwnd %p\n",
450 debugstr_w(dialog
->name
), debugstr_w(text
), control
->hwnd
);
452 msi_dialog_set_font( dialog
, control
->hwnd
,
453 font
? font
: dialog
->default_font
);
455 msi_free( title_font
);
461 static LPWSTR
msi_dialog_get_uitext( msi_dialog
*dialog
, LPCWSTR key
)
466 static const WCHAR query
[] = {
467 's','e','l','e','c','t',' ','*',' ',
468 'f','r','o','m',' ','`','U','I','T','e','x','t','`',' ',
469 'w','h','e','r','e',' ','`','K','e','y','`',' ','=',' ','\'','%','s','\'',0
472 rec
= MSI_QueryGetRecord( dialog
->package
->db
, query
, key
);
473 if (!rec
) return NULL
;
474 text
= strdupW( MSI_RecordGetString( rec
, 2 ) );
475 msiobj_release( &rec
->hdr
);
479 static MSIRECORD
*msi_get_binary_record( MSIDATABASE
*db
, LPCWSTR name
)
481 static const WCHAR query
[] = {
482 's','e','l','e','c','t',' ','*',' ',
483 'f','r','o','m',' ','B','i','n','a','r','y',' ',
484 'w','h','e','r','e',' ',
485 '`','N','a','m','e','`',' ','=',' ','\'','%','s','\'',0
488 return MSI_QueryGetRecord( db
, query
, name
);
491 static LPWSTR
msi_create_tmp_path(void)
495 static const WCHAR prefix
[] = { 'm','s','i',0 };
498 r
= GetTempPathW( MAX_PATH
, tmp
);
501 len
= lstrlenW( tmp
) + 20;
502 path
= msi_alloc( len
* sizeof (WCHAR
) );
505 r
= GetTempFileNameW( tmp
, prefix
, 0, path
);
516 static HANDLE
msi_load_image( MSIDATABASE
*db
, LPCWSTR name
, UINT type
,
517 UINT cx
, UINT cy
, UINT flags
)
519 MSIRECORD
*rec
= NULL
;
520 HANDLE himage
= NULL
;
524 TRACE("%p %s %u %u %08x\n", db
, debugstr_w(name
), cx
, cy
, flags
);
526 tmp
= msi_create_tmp_path();
530 rec
= msi_get_binary_record( db
, name
);
533 r
= MSI_RecordStreamToFile( rec
, 2, tmp
);
534 if( r
== ERROR_SUCCESS
)
536 himage
= LoadImageW( 0, tmp
, type
, cx
, cy
, flags
);
538 msiobj_release( &rec
->hdr
);
546 static HICON
msi_load_icon( MSIDATABASE
*db
, LPCWSTR text
, UINT attributes
)
548 DWORD cx
= 0, cy
= 0, flags
;
550 flags
= LR_LOADFROMFILE
| LR_DEFAULTSIZE
;
551 if( attributes
& msidbControlAttributesFixedSize
)
553 flags
&= ~LR_DEFAULTSIZE
;
554 if( attributes
& msidbControlAttributesIconSize16
)
559 if( attributes
& msidbControlAttributesIconSize32
)
564 /* msidbControlAttributesIconSize48 handled by above logic */
566 return msi_load_image( db
, text
, IMAGE_ICON
, cx
, cy
, flags
);
569 static void msi_dialog_update_controls( msi_dialog
*dialog
, LPCWSTR property
)
571 msi_control
*control
;
573 LIST_FOR_EACH_ENTRY( control
, &dialog
->controls
, msi_control
, entry
)
575 if ( !lstrcmpW( control
->property
, property
) && control
->update
)
576 control
->update( dialog
, control
);
580 /* called from the Control Event subscription code */
581 void msi_dialog_handle_event( msi_dialog
* dialog
, LPCWSTR control
,
582 LPCWSTR attribute
, MSIRECORD
*rec
)
585 LPCWSTR font_text
, text
= NULL
;
588 static const WCHAR empty
[] = {0};
590 ctrl
= msi_dialog_find_control( dialog
, control
);
593 if( !lstrcmpW(attribute
, szText
) )
595 font_text
= MSI_RecordGetString( rec
, 1 );
596 font
= msi_dialog_get_style( font_text
, &text
);
597 if (!text
) text
= empty
;
598 SetWindowTextW( ctrl
->hwnd
, text
);
600 msi_dialog_check_messages( NULL
);
602 else if( !lstrcmpW(attribute
, szProgress
) )
606 func
= MSI_RecordGetInteger( rec
, 1 );
607 val
= MSI_RecordGetInteger( rec
, 2 );
612 ctrl
->progress_max
= val
;
613 ctrl
->progress_current
= 0;
614 SendMessageW(ctrl
->hwnd
, PBM_SETRANGE
, 0, MAKELPARAM(0,100));
615 SendMessageW(ctrl
->hwnd
, PBM_SETPOS
, 0, 0);
617 case 1: /* FIXME: not sure what this is supposed to do */
620 ctrl
->progress_current
+= val
;
621 SendMessageW(ctrl
->hwnd
, PBM_SETPOS
, 100*(ctrl
->progress_current
/ctrl
->progress_max
), 0);
624 ERR("Unknown progress message %d\n", func
);
628 else if ( !lstrcmpW(attribute
, szProperty
) )
630 MSIFEATURE
*feature
= msi_seltree_get_selected_feature( ctrl
);
631 MSI_SetPropertyW( dialog
->package
, ctrl
->property
, feature
->Directory
);
633 else if ( !lstrcmpW(attribute
, szSelectionPath
) )
635 LPWSTR prop
= msi_dialog_dup_property( dialog
, ctrl
->property
, TRUE
);
638 path
= msi_dup_property( dialog
->package
, prop
);
639 SetWindowTextW( ctrl
->hwnd
, path
);
645 FIXME("Attribute %s not being set\n", debugstr_w(attribute
));
650 static void msi_dialog_map_events(msi_dialog
* dialog
, LPCWSTR control
)
652 static const WCHAR Query
[] = {
653 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
654 '`','E','v','e','n','t','M','a','p','p','i','n','g','`',' ',
655 'W','H','E','R','E',' ',
656 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',' ',
658 '`','C','o','n','t','r','o','l','_','`',' ','=',' ','\'','%','s','\'',0
661 LPCWSTR event
, attribute
;
663 row
= MSI_QueryGetRecord( dialog
->package
->db
, Query
, dialog
->name
, control
);
667 event
= MSI_RecordGetString( row
, 3 );
668 attribute
= MSI_RecordGetString( row
, 4 );
669 ControlEvent_SubscribeToEvent( dialog
->package
, dialog
, event
, control
, attribute
);
670 msiobj_release( &row
->hdr
);
673 /* everything except radio buttons */
674 static msi_control
*msi_dialog_add_control( msi_dialog
*dialog
,
675 MSIRECORD
*rec
, LPCWSTR szCls
, DWORD style
)
681 name
= MSI_RecordGetString( rec
, 2 );
682 attributes
= MSI_RecordGetInteger( rec
, 8 );
683 text
= MSI_RecordGetString( rec
, 10 );
684 if( attributes
& msidbControlAttributesVisible
)
686 if( ~attributes
& msidbControlAttributesEnabled
)
687 style
|= WS_DISABLED
;
688 if( attributes
& msidbControlAttributesSunken
)
689 exstyle
|= WS_EX_CLIENTEDGE
;
691 msi_dialog_map_events(dialog
, name
);
693 return msi_dialog_create_window( dialog
, rec
, exstyle
, szCls
, name
,
694 text
, style
, dialog
->hwnd
);
705 * we don't erase our own background,
706 * so we have to make sure that the parent window redraws first
708 static void msi_text_on_settext( HWND hWnd
)
713 hParent
= GetParent( hWnd
);
714 GetWindowRect( hWnd
, &rc
);
715 MapWindowPoints( NULL
, hParent
, (LPPOINT
) &rc
, 2 );
716 InvalidateRect( hParent
, &rc
, TRUE
);
719 static LRESULT WINAPI
720 MSIText_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
722 struct msi_text_info
*info
;
725 TRACE("%p %04x %08lx %08lx\n", hWnd
, msg
, wParam
, lParam
);
727 info
= GetPropW(hWnd
, szButtonData
);
729 if( msg
== WM_CTLCOLORSTATIC
&&
730 ( info
->attributes
& msidbControlAttributesTransparent
) )
732 SetBkMode( (HDC
)wParam
, TRANSPARENT
);
733 return (LRESULT
) GetStockObject(NULL_BRUSH
);
736 r
= CallWindowProcW(info
->oldproc
, hWnd
, msg
, wParam
, lParam
);
738 SetTextColor( (HDC
)wParam
, info
->font
->color
);
743 msi_text_on_settext( hWnd
);
747 RemovePropW( hWnd
, szButtonData
);
754 static UINT
msi_dialog_text_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
756 msi_control
*control
;
757 struct msi_text_info
*info
;
758 LPCWSTR text
, ptr
, prop
;
761 TRACE("%p %p\n", dialog
, rec
);
763 control
= msi_dialog_add_control( dialog
, rec
, szStatic
, SS_LEFT
| WS_GROUP
);
765 return ERROR_FUNCTION_FAILED
;
767 info
= msi_alloc( sizeof *info
);
769 return ERROR_SUCCESS
;
771 control
->attributes
= MSI_RecordGetInteger( rec
, 8 );
772 prop
= MSI_RecordGetString( rec
, 9 );
773 control
->property
= msi_dialog_dup_property( dialog
, prop
, FALSE
);
775 text
= MSI_RecordGetString( rec
, 10 );
776 font_name
= msi_dialog_get_style( text
, &ptr
);
777 info
->font
= ( font_name
) ? msi_dialog_find_font( dialog
, font_name
) : NULL
;
778 msi_free( font_name
);
780 info
->attributes
= MSI_RecordGetInteger( rec
, 8 );
781 if( info
->attributes
& msidbControlAttributesTransparent
)
782 SetWindowLongPtrW( control
->hwnd
, GWL_EXSTYLE
, WS_EX_TRANSPARENT
);
784 info
->oldproc
= (WNDPROC
) SetWindowLongPtrW( control
->hwnd
, GWLP_WNDPROC
,
785 (LONG_PTR
)MSIText_WndProc
);
786 SetPropW( control
->hwnd
, szButtonData
, info
);
788 ControlEvent_SubscribeToEvent( dialog
->package
, dialog
,
789 szSelectionPath
, control
->name
, szSelectionPath
);
791 return ERROR_SUCCESS
;
794 static UINT
msi_dialog_button_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
796 msi_control
*control
;
797 UINT attributes
, style
;
800 TRACE("%p %p\n", dialog
, rec
);
803 attributes
= MSI_RecordGetInteger( rec
, 8 );
804 if( attributes
& msidbControlAttributesIcon
)
807 control
= msi_dialog_add_control( dialog
, rec
, szButton
, style
);
809 return ERROR_FUNCTION_FAILED
;
811 control
->handler
= msi_dialog_button_handler
;
814 text
= msi_get_deformatted_field( dialog
->package
, rec
, 10 );
815 control
->hIcon
= msi_load_icon( dialog
->package
->db
, text
, attributes
);
816 if( attributes
& msidbControlAttributesIcon
)
817 SendMessageW( control
->hwnd
, BM_SETIMAGE
, IMAGE_ICON
, (LPARAM
) control
->hIcon
);
820 return ERROR_SUCCESS
;
823 static LPWSTR
msi_get_checkbox_value( msi_dialog
*dialog
, LPCWSTR prop
)
825 static const WCHAR query
[] = {
826 'S','E','L','E','C','T',' ','*',' ',
827 'F','R','O','M',' ','`','C','h','e','c','k','B','o','x','`',' ',
828 'W','H','E','R','E',' ',
829 '`','P','r','o','p','e','r','t','y','`',' ','=',' ',
832 MSIRECORD
*rec
= NULL
;
835 /* find if there is a value associated with the checkbox */
836 rec
= MSI_QueryGetRecord( dialog
->package
->db
, query
, prop
);
840 ret
= msi_get_deformatted_field( dialog
->package
, rec
, 2 );
846 msiobj_release( &rec
->hdr
);
850 ret
= msi_dup_property( dialog
->package
, prop
);
860 static UINT
msi_dialog_checkbox_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
862 msi_control
*control
;
865 TRACE("%p %p\n", dialog
, rec
);
867 control
= msi_dialog_add_control( dialog
, rec
, szButton
,
868 BS_CHECKBOX
| BS_MULTILINE
| WS_TABSTOP
);
869 control
->handler
= msi_dialog_checkbox_handler
;
870 control
->update
= msi_dialog_checkbox_sync_state
;
871 prop
= MSI_RecordGetString( rec
, 9 );
874 control
->property
= strdupW( prop
);
875 control
->value
= msi_get_checkbox_value( dialog
, prop
);
876 TRACE("control %s value %s\n", debugstr_w(control
->property
),
877 debugstr_w(control
->value
));
879 msi_dialog_checkbox_sync_state( dialog
, control
);
881 return ERROR_SUCCESS
;
884 static UINT
msi_dialog_line_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
888 DWORD style
, exstyle
= 0;
889 DWORD x
, y
, width
, height
;
890 msi_control
*control
;
892 TRACE("%p %p\n", dialog
, rec
);
894 style
= WS_CHILD
| SS_ETCHEDHORZ
| SS_SUNKEN
;
896 name
= MSI_RecordGetString( rec
, 2 );
897 attributes
= MSI_RecordGetInteger( rec
, 8 );
899 if( attributes
& msidbControlAttributesVisible
)
901 if( ~attributes
& msidbControlAttributesEnabled
)
902 style
|= WS_DISABLED
;
903 if( attributes
& msidbControlAttributesSunken
)
904 exstyle
|= WS_EX_CLIENTEDGE
;
906 msi_dialog_map_events(dialog
, name
);
908 control
= msi_alloc( sizeof(*control
) + strlenW(name
) * sizeof(WCHAR
) );
910 return ERROR_OUTOFMEMORY
;
912 strcpyW( control
->name
, name
);
913 list_add_head( &dialog
->controls
, &control
->entry
);
914 control
->handler
= NULL
;
915 control
->property
= NULL
;
916 control
->value
= NULL
;
917 control
->hBitmap
= NULL
;
918 control
->hIcon
= NULL
;
919 control
->hDll
= NULL
;
920 control
->tabnext
= strdupW( MSI_RecordGetString( rec
, 11) );
921 control
->type
= strdupW( MSI_RecordGetString( rec
, 3 ) );
922 control
->progress_current
= 0;
923 control
->progress_max
= 100;
925 x
= MSI_RecordGetInteger( rec
, 4 );
926 y
= MSI_RecordGetInteger( rec
, 5 );
927 width
= MSI_RecordGetInteger( rec
, 6 );
929 x
= msi_dialog_scale_unit( dialog
, x
);
930 y
= msi_dialog_scale_unit( dialog
, y
);
931 width
= msi_dialog_scale_unit( dialog
, width
);
932 height
= 2; /* line is exactly 2 units in height */
934 control
->hwnd
= CreateWindowExW( exstyle
, szStatic
, NULL
, style
,
935 x
, y
, width
, height
, dialog
->hwnd
, NULL
, NULL
, NULL
);
937 TRACE("Dialog %s control %s hwnd %p\n",
938 debugstr_w(dialog
->name
), debugstr_w(name
), control
->hwnd
);
940 return ERROR_SUCCESS
;
943 /******************** Scroll Text ********************************************/
945 struct msi_scrolltext_info
948 msi_control
*control
;
952 static LRESULT WINAPI
953 MSIScrollText_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
955 struct msi_scrolltext_info
*info
;
958 TRACE("%p %04x %08lx %08lx\n", hWnd
, msg
, wParam
, lParam
);
960 info
= GetPropW( hWnd
, szButtonData
);
962 r
= CallWindowProcW( info
->oldproc
, hWnd
, msg
, wParam
, lParam
);
968 RemovePropW( hWnd
, szButtonData
);
971 /* native MSI sets a wait cursor here */
972 msi_dialog_button_handler( info
->dialog
, info
->control
, BN_CLICKED
);
978 struct msi_streamin_info
985 static DWORD CALLBACK
986 msi_richedit_stream_in( DWORD_PTR arg
, LPBYTE buffer
, LONG count
, LONG
*pcb
)
988 struct msi_streamin_info
*info
= (struct msi_streamin_info
*) arg
;
990 if( (count
+ info
->offset
) > info
->length
)
991 count
= info
->length
- info
->offset
;
992 memcpy( buffer
, &info
->string
[ info
->offset
], count
);
994 info
->offset
+= count
;
996 TRACE("%d/%d\n", info
->offset
, info
->length
);
1001 static void msi_scrolltext_add_text( msi_control
*control
, LPCWSTR text
)
1003 struct msi_streamin_info info
;
1006 info
.string
= strdupWtoA( text
);
1008 info
.length
= lstrlenA( info
.string
) + 1;
1010 es
.dwCookie
= (DWORD_PTR
) &info
;
1012 es
.pfnCallback
= msi_richedit_stream_in
;
1014 SendMessageW( control
->hwnd
, EM_STREAMIN
, SF_RTF
, (LPARAM
) &es
);
1016 msi_free( info
.string
);
1019 static UINT
msi_dialog_scrolltext_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1021 static const WCHAR szRichEdit20W
[] = {
1022 'R','i','c','h','E','d','i','t','2','0','W',0
1024 struct msi_scrolltext_info
*info
;
1025 msi_control
*control
;
1030 info
= msi_alloc( sizeof *info
);
1032 return ERROR_FUNCTION_FAILED
;
1034 hRichedit
= LoadLibraryA("riched20");
1036 style
= WS_BORDER
| ES_MULTILINE
| WS_VSCROLL
|
1037 ES_READONLY
| ES_AUTOVSCROLL
| WS_TABSTOP
;
1038 control
= msi_dialog_add_control( dialog
, rec
, szRichEdit20W
, style
);
1041 FreeLibrary( hRichedit
);
1043 return ERROR_FUNCTION_FAILED
;
1046 control
->hDll
= hRichedit
;
1048 info
->dialog
= dialog
;
1049 info
->control
= control
;
1051 /* subclass the static control */
1052 info
->oldproc
= (WNDPROC
) SetWindowLongPtrW( control
->hwnd
, GWLP_WNDPROC
,
1053 (LONG_PTR
)MSIScrollText_WndProc
);
1054 SetPropW( control
->hwnd
, szButtonData
, info
);
1056 /* add the text into the richedit */
1057 text
= MSI_RecordGetString( rec
, 10 );
1059 msi_scrolltext_add_text( control
, text
);
1061 return ERROR_SUCCESS
;
1064 static HBITMAP
msi_load_picture( MSIDATABASE
*db
, LPCWSTR name
,
1065 INT cx
, INT cy
, DWORD flags
)
1067 HBITMAP hOleBitmap
= 0, hBitmap
= 0, hOldSrcBitmap
, hOldDestBitmap
;
1068 MSIRECORD
*rec
= NULL
;
1069 IStream
*stm
= NULL
;
1070 IPicture
*pic
= NULL
;
1075 rec
= msi_get_binary_record( db
, name
);
1079 r
= MSI_RecordGetIStream( rec
, 2, &stm
);
1080 msiobj_release( &rec
->hdr
);
1081 if( r
!= ERROR_SUCCESS
)
1084 r
= OleLoadPicture( stm
, 0, TRUE
, &IID_IPicture
, (LPVOID
*) &pic
);
1085 IStream_Release( stm
);
1088 ERR("failed to load picture\n");
1092 r
= IPicture_get_Handle( pic
, (OLE_HANDLE
*) &hOleBitmap
);
1095 ERR("failed to get bitmap handle\n");
1099 /* make the bitmap the desired size */
1100 r
= GetObjectW( hOleBitmap
, sizeof bm
, &bm
);
1101 if (r
!= sizeof bm
)
1103 ERR("failed to get bitmap size\n");
1107 if (flags
& LR_DEFAULTSIZE
)
1113 srcdc
= CreateCompatibleDC( NULL
);
1114 hOldSrcBitmap
= SelectObject( srcdc
, hOleBitmap
);
1115 destdc
= CreateCompatibleDC( NULL
);
1116 hBitmap
= CreateCompatibleBitmap( srcdc
, cx
, cy
);
1117 hOldDestBitmap
= SelectObject( destdc
, hBitmap
);
1118 StretchBlt( destdc
, 0, 0, cx
, cy
,
1119 srcdc
, 0, 0, bm
.bmWidth
, bm
.bmHeight
, SRCCOPY
);
1120 SelectObject( srcdc
, hOldSrcBitmap
);
1121 SelectObject( destdc
, hOldDestBitmap
);
1127 IPicture_Release( pic
);
1131 static UINT
msi_dialog_bitmap_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1133 UINT cx
, cy
, flags
, style
, attributes
;
1134 msi_control
*control
;
1137 flags
= LR_LOADFROMFILE
;
1138 style
= SS_BITMAP
| SS_LEFT
| WS_GROUP
;
1140 attributes
= MSI_RecordGetInteger( rec
, 8 );
1141 if( attributes
& msidbControlAttributesFixedSize
)
1143 flags
|= LR_DEFAULTSIZE
;
1144 style
|= SS_CENTERIMAGE
;
1147 control
= msi_dialog_add_control( dialog
, rec
, szStatic
, style
);
1148 cx
= MSI_RecordGetInteger( rec
, 6 );
1149 cy
= MSI_RecordGetInteger( rec
, 7 );
1150 cx
= msi_dialog_scale_unit( dialog
, cx
);
1151 cy
= msi_dialog_scale_unit( dialog
, cy
);
1153 text
= msi_get_deformatted_field( dialog
->package
, rec
, 10 );
1154 control
->hBitmap
= msi_load_picture( dialog
->package
->db
, text
, cx
, cy
, flags
);
1155 if( control
->hBitmap
)
1156 SendMessageW( control
->hwnd
, STM_SETIMAGE
,
1157 IMAGE_BITMAP
, (LPARAM
) control
->hBitmap
);
1159 ERR("Failed to load bitmap %s\n", debugstr_w(text
));
1163 return ERROR_SUCCESS
;
1166 static UINT
msi_dialog_icon_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1168 msi_control
*control
;
1174 control
= msi_dialog_add_control( dialog
, rec
, szStatic
,
1175 SS_ICON
| SS_CENTERIMAGE
| WS_GROUP
);
1177 attributes
= MSI_RecordGetInteger( rec
, 8 );
1178 text
= msi_get_deformatted_field( dialog
->package
, rec
, 10 );
1179 control
->hIcon
= msi_load_icon( dialog
->package
->db
, text
, attributes
);
1180 if( control
->hIcon
)
1181 SendMessageW( control
->hwnd
, STM_SETICON
, (WPARAM
) control
->hIcon
, 0 );
1183 ERR("Failed to load bitmap %s\n", debugstr_w(text
));
1185 return ERROR_SUCCESS
;
1188 static UINT
msi_dialog_combo_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1190 static const WCHAR szCombo
[] = { 'C','O','M','B','O','B','O','X',0 };
1191 DWORD attributes
, style
;
1193 style
= CBS_AUTOHSCROLL
| WS_TABSTOP
| WS_GROUP
| WS_CHILD
;
1194 attributes
= MSI_RecordGetInteger( rec
, 8 );
1195 if ( ~attributes
& msidbControlAttributesSorted
)
1197 if ( attributes
& msidbControlAttributesComboList
)
1198 style
|= CBS_DROPDOWNLIST
;
1200 style
|= CBS_DROPDOWN
;
1202 msi_dialog_add_control( dialog
, rec
, szCombo
, style
);
1203 return ERROR_SUCCESS
;
1206 static UINT
msi_dialog_edit_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1208 msi_control
*control
;
1210 LPWSTR val
, begin
, end
;
1214 control
= msi_dialog_add_control( dialog
, rec
, szEdit
,
1215 WS_BORDER
| WS_TABSTOP
| ES_AUTOHSCROLL
);
1216 control
->handler
= msi_dialog_edit_handler
;
1218 text
= MSI_RecordGetString( rec
, 10 );
1221 begin
= strchrW( text
, '{' );
1222 end
= strchrW( text
, '}' );
1224 if ( begin
&& end
&& end
> begin
)
1226 lstrcpynW( num
, begin
+ 1, end
- begin
);
1227 limit
= atolW( num
);
1229 SendMessageW( control
->hwnd
, EM_SETLIMITTEXT
, limit
, 0 );
1233 prop
= MSI_RecordGetString( rec
, 9 );
1235 control
->property
= strdupW( prop
);
1237 val
= msi_dup_property( dialog
->package
, control
->property
);
1238 SetWindowTextW( control
->hwnd
, val
);
1240 return ERROR_SUCCESS
;
1243 /******************** Masked Edit ********************************************/
1245 #define MASK_MAX_GROUPS 20
1247 struct msi_mask_group
1255 struct msi_maskedit_info
1263 struct msi_mask_group group
[MASK_MAX_GROUPS
];
1266 static BOOL
msi_mask_editable( WCHAR type
)
1281 static void msi_mask_control_change( struct msi_maskedit_info
*info
)
1286 val
= msi_alloc( (info
->num_chars
+1)*sizeof(WCHAR
) );
1287 for( i
=0, n
=0; i
<info
->num_groups
; i
++ )
1289 if( (info
->group
[i
].len
+ n
) > info
->num_chars
)
1291 ERR("can't fit control %d text into template\n",i
);
1294 if (!msi_mask_editable(info
->group
[i
].type
))
1296 for(r
=0; r
<info
->group
[i
].len
; r
++)
1297 val
[n
+r
] = info
->group
[i
].type
;
1302 r
= GetWindowTextW( info
->group
[i
].hwnd
, &val
[n
], info
->group
[i
].len
+1 );
1303 if( r
!= info
->group
[i
].len
)
1309 TRACE("%d/%d controls were good\n", i
, info
->num_groups
);
1311 if( i
== info
->num_groups
)
1313 TRACE("Set property %s to %s\n",
1314 debugstr_w(info
->prop
), debugstr_w(val
) );
1315 CharUpperBuffW( val
, info
->num_chars
);
1316 MSI_SetPropertyW( info
->dialog
->package
, info
->prop
, val
);
1317 msi_dialog_evaluate_control_conditions( info
->dialog
);
1322 /* now move to the next control if necessary */
1323 static VOID
msi_mask_next_control( struct msi_maskedit_info
*info
, HWND hWnd
)
1328 for( i
=0; i
<info
->num_groups
; i
++ )
1329 if( info
->group
[i
].hwnd
== hWnd
)
1332 /* don't move from the last control */
1333 if( i
>= (info
->num_groups
-1) )
1336 len
= SendMessageW( hWnd
, WM_GETTEXTLENGTH
, 0, 0 );
1337 if( len
< info
->group
[i
].len
)
1340 hWndNext
= GetNextDlgTabItem( GetParent( hWnd
), hWnd
, FALSE
);
1341 SetFocus( hWndNext
);
1344 static LRESULT WINAPI
1345 MSIMaskedEdit_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1347 struct msi_maskedit_info
*info
;
1350 TRACE("%p %04x %08lx %08lx\n", hWnd
, msg
, wParam
, lParam
);
1352 info
= GetPropW(hWnd
, szButtonData
);
1354 r
= CallWindowProcW(info
->oldproc
, hWnd
, msg
, wParam
, lParam
);
1359 if (HIWORD(wParam
) == EN_CHANGE
)
1361 msi_mask_control_change( info
);
1362 msi_mask_next_control( info
, (HWND
) lParam
);
1366 msi_free( info
->prop
);
1368 RemovePropW( hWnd
, szButtonData
);
1375 /* fish the various bits of the property out and put them in the control */
1377 msi_maskedit_set_text( struct msi_maskedit_info
*info
, LPCWSTR text
)
1383 for( i
= 0; i
< info
->num_groups
; i
++ )
1385 if( info
->group
[i
].len
< lstrlenW( p
) )
1387 LPWSTR chunk
= strdupW( p
);
1388 chunk
[ info
->group
[i
].len
] = 0;
1389 SetWindowTextW( info
->group
[i
].hwnd
, chunk
);
1394 SetWindowTextW( info
->group
[i
].hwnd
, p
);
1397 p
+= info
->group
[i
].len
;
1401 static struct msi_maskedit_info
* msi_dialog_parse_groups( LPCWSTR mask
)
1403 struct msi_maskedit_info
* info
= NULL
;
1404 int i
= 0, n
= 0, total
= 0;
1407 TRACE("masked control, template %s\n", debugstr_w(mask
));
1412 info
= msi_alloc_zero( sizeof *info
);
1416 p
= strchrW(mask
, '<');
1422 for( i
=0; i
<MASK_MAX_GROUPS
; i
++ )
1424 /* stop at the end of the string */
1425 if( p
[0] == 0 || p
[0] == '>' )
1428 /* count the number of the same identifier */
1429 for( n
=0; p
[n
] == p
[0]; n
++ )
1431 info
->group
[i
].ofs
= total
;
1432 info
->group
[i
].type
= p
[0];
1436 total
++; /* an extra not part of the group */
1438 info
->group
[i
].len
= n
;
1443 TRACE("%d characters in %d groups\n", total
, i
);
1444 if( i
== MASK_MAX_GROUPS
)
1445 ERR("too many groups in PIDTemplate %s\n", debugstr_w(mask
));
1447 info
->num_chars
= total
;
1448 info
->num_groups
= i
;
1454 msi_maskedit_create_children( struct msi_maskedit_info
*info
, LPCWSTR font
)
1456 DWORD width
, height
, style
, wx
, ww
;
1461 style
= WS_CHILD
| WS_BORDER
| WS_VISIBLE
| WS_TABSTOP
| ES_AUTOHSCROLL
;
1463 GetClientRect( info
->hwnd
, &rect
);
1465 width
= rect
.right
- rect
.left
;
1466 height
= rect
.bottom
- rect
.top
;
1468 for( i
= 0; i
< info
->num_groups
; i
++ )
1470 if (!msi_mask_editable( info
->group
[i
].type
))
1472 wx
= (info
->group
[i
].ofs
* width
) / info
->num_chars
;
1473 ww
= (info
->group
[i
].len
* width
) / info
->num_chars
;
1475 hwnd
= CreateWindowW( szEdit
, NULL
, style
, wx
, 0, ww
, height
,
1476 info
->hwnd
, NULL
, NULL
, NULL
);
1479 ERR("failed to create mask edit sub window\n");
1483 SendMessageW( hwnd
, EM_LIMITTEXT
, info
->group
[i
].len
, 0 );
1485 msi_dialog_set_font( info
->dialog
, hwnd
,
1486 font
?font
:info
->dialog
->default_font
);
1487 info
->group
[i
].hwnd
= hwnd
;
1492 * office 2003 uses "73931<````=````=````=````=`````>@@@@@"
1493 * delphi 7 uses "<????-??????-??????-????>" and "<???-???>"
1494 * filemaker pro 7 uses "<^^^^=^^^^=^^^^=^^^^=^^^^=^^^^=^^^^^>"
1496 static UINT
msi_dialog_maskedit_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1498 LPWSTR font_mask
, val
= NULL
, font
;
1499 struct msi_maskedit_info
*info
= NULL
;
1500 UINT ret
= ERROR_SUCCESS
;
1501 msi_control
*control
;
1506 font_mask
= msi_get_deformatted_field( dialog
->package
, rec
, 10 );
1507 font
= msi_dialog_get_style( font_mask
, &mask
);
1510 ERR("mask template is empty\n");
1514 info
= msi_dialog_parse_groups( mask
);
1517 ERR("template %s is invalid\n", debugstr_w(mask
));
1521 info
->dialog
= dialog
;
1523 control
= msi_dialog_add_control( dialog
, rec
, szStatic
,
1524 SS_OWNERDRAW
| WS_GROUP
| WS_VISIBLE
);
1527 ERR("Failed to create maskedit container\n");
1528 ret
= ERROR_FUNCTION_FAILED
;
1531 SetWindowLongPtrW( control
->hwnd
, GWL_EXSTYLE
, WS_EX_CONTROLPARENT
);
1533 info
->hwnd
= control
->hwnd
;
1535 /* subclass the static control */
1536 info
->oldproc
= (WNDPROC
) SetWindowLongPtrW( info
->hwnd
, GWLP_WNDPROC
,
1537 (LONG_PTR
)MSIMaskedEdit_WndProc
);
1538 SetPropW( control
->hwnd
, szButtonData
, info
);
1540 prop
= MSI_RecordGetString( rec
, 9 );
1542 info
->prop
= strdupW( prop
);
1544 msi_maskedit_create_children( info
, font
);
1548 val
= msi_dup_property( dialog
->package
, prop
);
1551 msi_maskedit_set_text( info
, val
);
1557 if( ret
!= ERROR_SUCCESS
)
1559 msi_free( font_mask
);
1564 /******************** Progress Bar *****************************************/
1566 static UINT
msi_dialog_progress_bar( msi_dialog
*dialog
, MSIRECORD
*rec
)
1568 msi_dialog_add_control( dialog
, rec
, PROGRESS_CLASSW
, WS_VISIBLE
);
1569 return ERROR_SUCCESS
;
1572 /******************** Path Edit ********************************************/
1574 struct msi_pathedit_info
1577 msi_control
*control
;
1581 static LPWSTR
msi_get_window_text( HWND hwnd
)
1587 buf
= msi_alloc( sz
*sizeof(WCHAR
) );
1590 r
= GetWindowTextW( hwnd
, buf
, sz
);
1594 buf
= msi_realloc( buf
, sz
*sizeof(WCHAR
) );
1600 static void msi_dialog_update_pathedit( msi_dialog
*dialog
, msi_control
*control
)
1605 if (!control
&& !(control
= msi_dialog_find_control_by_type( dialog
, szPathEdit
)))
1608 indirect
= control
->attributes
& msidbControlAttributesIndirect
;
1609 prop
= msi_dialog_dup_property( dialog
, control
->property
, indirect
);
1610 path
= msi_dialog_dup_property( dialog
, prop
, TRUE
);
1612 SetWindowTextW( control
->hwnd
, path
);
1613 SendMessageW( control
->hwnd
, EM_SETSEL
, 0, -1 );
1619 /* FIXME: test when this should fail */
1620 static BOOL
msi_dialog_verify_path( LPWSTR path
)
1622 if ( !lstrlenW( path
) )
1625 if ( PathIsRelativeW( path
) )
1631 /* returns TRUE if the path is valid, FALSE otherwise */
1632 static BOOL
msi_dialog_onkillfocus( msi_dialog
*dialog
, msi_control
*control
)
1638 indirect
= control
->attributes
& msidbControlAttributesIndirect
;
1639 prop
= msi_dialog_dup_property( dialog
, control
->property
, indirect
);
1641 buf
= msi_get_window_text( control
->hwnd
);
1643 if ( !msi_dialog_verify_path( buf
) )
1645 /* FIXME: display an error message box */
1646 ERR("Invalid path %s\n", debugstr_w( buf
));
1648 SetFocus( control
->hwnd
);
1653 MSI_SetPropertyW( dialog
->package
, prop
, buf
);
1656 msi_dialog_update_pathedit( dialog
, control
);
1658 TRACE("edit %s contents changed, set %s\n", debugstr_w(control
->name
),
1667 static LRESULT WINAPI
MSIPathEdit_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1669 struct msi_pathedit_info
*info
= GetPropW(hWnd
, szButtonData
);
1672 TRACE("%p %04x %08lx %08lx\n", hWnd
, msg
, wParam
, lParam
);
1674 if ( msg
== WM_KILLFOCUS
)
1676 /* if the path is invalid, don't handle this message */
1677 if ( !msi_dialog_onkillfocus( info
->dialog
, info
->control
) )
1681 r
= CallWindowProcW(info
->oldproc
, hWnd
, msg
, wParam
, lParam
);
1683 if ( msg
== WM_NCDESTROY
)
1686 RemovePropW( hWnd
, szButtonData
);
1692 static UINT
msi_dialog_pathedit_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1694 struct msi_pathedit_info
*info
;
1695 msi_control
*control
;
1698 info
= msi_alloc( sizeof *info
);
1700 return ERROR_FUNCTION_FAILED
;
1702 control
= msi_dialog_add_control( dialog
, rec
, szEdit
,
1703 WS_BORDER
| WS_TABSTOP
);
1704 control
->attributes
= MSI_RecordGetInteger( rec
, 8 );
1705 prop
= MSI_RecordGetString( rec
, 9 );
1706 control
->property
= msi_dialog_dup_property( dialog
, prop
, FALSE
);
1708 info
->dialog
= dialog
;
1709 info
->control
= control
;
1710 info
->oldproc
= (WNDPROC
) SetWindowLongPtrW( control
->hwnd
, GWLP_WNDPROC
,
1711 (LONG_PTR
)MSIPathEdit_WndProc
);
1712 SetPropW( control
->hwnd
, szButtonData
, info
);
1714 msi_dialog_update_pathedit( dialog
, control
);
1716 return ERROR_SUCCESS
;
1719 /* radio buttons are a bit different from normal controls */
1720 static UINT
msi_dialog_create_radiobutton( MSIRECORD
*rec
, LPVOID param
)
1722 radio_button_group_descr
*group
= (radio_button_group_descr
*)param
;
1723 msi_dialog
*dialog
= group
->dialog
;
1724 msi_control
*control
;
1725 LPCWSTR prop
, text
, name
;
1726 DWORD style
, attributes
= group
->attributes
;
1728 style
= WS_CHILD
| BS_AUTORADIOBUTTON
| BS_MULTILINE
| WS_TABSTOP
;
1729 name
= MSI_RecordGetString( rec
, 3 );
1730 text
= MSI_RecordGetString( rec
, 8 );
1731 if( attributes
& msidbControlAttributesVisible
)
1732 style
|= WS_VISIBLE
;
1733 if( ~attributes
& msidbControlAttributesEnabled
)
1734 style
|= WS_DISABLED
;
1736 control
= msi_dialog_create_window( dialog
, rec
, 0, szButton
, name
, text
,
1737 style
, group
->parent
->hwnd
);
1739 return ERROR_FUNCTION_FAILED
;
1740 control
->handler
= msi_dialog_radiogroup_handler
;
1742 if (!lstrcmpW(control
->name
, group
->propval
))
1743 SendMessageW(control
->hwnd
, BM_SETCHECK
, BST_CHECKED
, 0);
1745 prop
= MSI_RecordGetString( rec
, 1 );
1747 control
->property
= strdupW( prop
);
1749 return ERROR_SUCCESS
;
1752 static UINT
msi_dialog_radiogroup_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1754 static const WCHAR query
[] = {
1755 'S','E','L','E','C','T',' ','*',' ',
1756 'F','R','O','M',' ','R','a','d','i','o','B','u','t','t','o','n',' ',
1757 'W','H','E','R','E',' ',
1758 '`','P','r','o','p','e','r','t','y','`',' ','=',' ','\'','%','s','\'',0};
1761 msi_control
*control
;
1762 MSIQUERY
*view
= NULL
;
1763 radio_button_group_descr group
;
1764 MSIPACKAGE
*package
= dialog
->package
;
1766 DWORD attr
, style
= WS_GROUP
;
1768 prop
= MSI_RecordGetString( rec
, 9 );
1770 TRACE("%p %p %s\n", dialog
, rec
, debugstr_w( prop
));
1772 attr
= MSI_RecordGetInteger( rec
, 8 );
1773 if (attr
& msidbControlAttributesHasBorder
)
1774 style
|= BS_GROUPBOX
;
1776 style
|= BS_OWNERDRAW
;
1778 /* Create parent group box to hold radio buttons */
1779 control
= msi_dialog_add_control( dialog
, rec
, szButton
, style
);
1781 return ERROR_FUNCTION_FAILED
;
1783 oldproc
= (WNDPROC
) SetWindowLongPtrW( control
->hwnd
, GWLP_WNDPROC
,
1784 (LONG_PTR
)MSIRadioGroup_WndProc
);
1785 SetPropW(control
->hwnd
, szButtonData
, oldproc
);
1786 SetWindowLongPtrW( control
->hwnd
, GWL_EXSTYLE
, WS_EX_CONTROLPARENT
);
1789 control
->property
= strdupW( prop
);
1791 /* query the Radio Button table for all control in this group */
1792 r
= MSI_OpenQuery( package
->db
, &view
, query
, prop
);
1793 if( r
!= ERROR_SUCCESS
)
1795 ERR("query failed for dialog %s radio group %s\n",
1796 debugstr_w(dialog
->name
), debugstr_w(prop
));
1797 return ERROR_INVALID_PARAMETER
;
1800 group
.dialog
= dialog
;
1801 group
.parent
= control
;
1802 group
.attributes
= MSI_RecordGetInteger( rec
, 8 );
1803 group
.propval
= msi_dup_property( dialog
->package
, control
->property
);
1805 r
= MSI_IterateRecords( view
, 0, msi_dialog_create_radiobutton
, &group
);
1806 msiobj_release( &view
->hdr
);
1807 msi_free( group
.propval
);
1812 /******************** Selection Tree ***************************************/
1814 struct msi_selection_tree_info
1823 msi_seltree_sync_item_state( HWND hwnd
, MSIFEATURE
*feature
, HTREEITEM hItem
)
1826 DWORD index
= feature
->Action
;
1828 TRACE("Feature %s -> %d %d %d\n", debugstr_w(feature
->Title
),
1829 feature
->Installed
, feature
->Action
, feature
->ActionRequest
);
1831 if (index
== INSTALLSTATE_UNKNOWN
)
1832 index
= INSTALLSTATE_ABSENT
;
1834 tvi
.mask
= TVIF_STATE
;
1836 tvi
.state
= INDEXTOSTATEIMAGEMASK( index
);
1837 tvi
.stateMask
= TVIS_STATEIMAGEMASK
;
1839 SendMessageW( hwnd
, TVM_SETITEMW
, 0, (LPARAM
) &tvi
);
1843 msi_seltree_popup_menu( HWND hwnd
, INT x
, INT y
)
1848 /* create a menu to display */
1849 hMenu
= CreatePopupMenu();
1851 /* FIXME: load strings from resources */
1852 AppendMenuA( hMenu
, MF_ENABLED
, INSTALLSTATE_LOCAL
, "Install feature locally");
1853 AppendMenuA( hMenu
, MF_GRAYED
, 0x1000, "Install entire feature");
1854 AppendMenuA( hMenu
, MF_ENABLED
, INSTALLSTATE_ADVERTISED
, "Install on demand");
1855 AppendMenuA( hMenu
, MF_ENABLED
, INSTALLSTATE_ABSENT
, "Don't install");
1856 r
= TrackPopupMenu( hMenu
, TPM_LEFTALIGN
| TPM_TOPALIGN
| TPM_RETURNCMD
,
1857 x
, y
, 0, hwnd
, NULL
);
1858 DestroyMenu( hMenu
);
1863 msi_seltree_feature_from_item( HWND hwnd
, HTREEITEM hItem
)
1867 /* get the feature from the item */
1868 memset( &tvi
, 0, sizeof tvi
);
1870 tvi
.mask
= TVIF_PARAM
| TVIF_HANDLE
;
1871 SendMessageW( hwnd
, TVM_GETITEMW
, 0, (LPARAM
) &tvi
);
1873 return (MSIFEATURE
*) tvi
.lParam
;
1877 msi_seltree_menu( HWND hwnd
, HTREEITEM hItem
)
1879 struct msi_selection_tree_info
*info
;
1880 MSIFEATURE
*feature
;
1881 MSIPACKAGE
*package
;
1889 info
= GetPropW(hwnd
, szButtonData
);
1890 package
= info
->dialog
->package
;
1892 feature
= msi_seltree_feature_from_item( hwnd
, hItem
);
1895 ERR("item %p feature was NULL\n", hItem
);
1899 /* get the item's rectangle to put the menu just below it */
1901 SendMessageW( hwnd
, TVM_GETITEMRECT
, 0, (LPARAM
) &u
.rc
);
1902 MapWindowPoints( hwnd
, NULL
, u
.pt
, 2 );
1904 r
= msi_seltree_popup_menu( hwnd
, u
.rc
.left
, u
.rc
.top
);
1908 case INSTALLSTATE_LOCAL
:
1909 case INSTALLSTATE_ADVERTISED
:
1910 case INSTALLSTATE_ABSENT
:
1911 msi_feature_set_state( feature
, r
);
1914 FIXME("select feature and all children\n");
1918 msi_seltree_sync_item_state( hwnd
, feature
, hItem
);
1919 ACTION_UpdateComponentStates( package
, feature
->Feature
);
1924 static MSIFEATURE
*msi_seltree_get_selected_feature( msi_control
*control
)
1926 struct msi_selection_tree_info
*info
= GetPropW(control
->hwnd
, szButtonData
);
1927 return msi_seltree_feature_from_item( control
->hwnd
, info
->selected
);
1930 static LRESULT WINAPI
1931 MSISelectionTree_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1933 struct msi_selection_tree_info
*info
;
1934 TVHITTESTINFO tvhti
;
1937 TRACE("%p %04x %08lx %08lx\n", hWnd
, msg
, wParam
, lParam
);
1939 info
= GetPropW(hWnd
, szButtonData
);
1943 case WM_LBUTTONDOWN
:
1944 tvhti
.pt
.x
= (short)LOWORD( lParam
);
1945 tvhti
.pt
.y
= (short)HIWORD( lParam
);
1948 r
= CallWindowProcW(info
->oldproc
, hWnd
, TVM_HITTEST
, 0, (LPARAM
) &tvhti
);
1949 if (tvhti
.flags
& TVHT_ONITEMSTATEICON
)
1950 return msi_seltree_menu( hWnd
, tvhti
.hItem
);
1954 r
= CallWindowProcW(info
->oldproc
, hWnd
, msg
, wParam
, lParam
);
1960 RemovePropW( hWnd
, szButtonData
);
1967 msi_seltree_add_child_features( MSIPACKAGE
*package
, HWND hwnd
,
1968 LPCWSTR parent
, HTREEITEM hParent
)
1970 struct msi_selection_tree_info
*info
= GetPropW( hwnd
, szButtonData
);
1971 MSIFEATURE
*feature
;
1972 TVINSERTSTRUCTW tvis
;
1973 HTREEITEM hitem
, hfirst
= NULL
;
1975 LIST_FOR_EACH_ENTRY( feature
, &package
->features
, MSIFEATURE
, entry
)
1977 if ( lstrcmpW( parent
, feature
->Feature_Parent
) )
1980 if ( !feature
->Title
)
1983 if ( !feature
->Display
)
1986 memset( &tvis
, 0, sizeof tvis
);
1987 tvis
.hParent
= hParent
;
1988 tvis
.hInsertAfter
= TVI_LAST
;
1989 tvis
.u
.item
.mask
= TVIF_TEXT
| TVIF_PARAM
;
1990 tvis
.u
.item
.pszText
= feature
->Title
;
1991 tvis
.u
.item
.lParam
= (LPARAM
) feature
;
1993 hitem
= (HTREEITEM
) SendMessageW( hwnd
, TVM_INSERTITEMW
, 0, (LPARAM
) &tvis
);
2000 msi_seltree_sync_item_state( hwnd
, feature
, hitem
);
2001 msi_seltree_add_child_features( package
, hwnd
,
2002 feature
->Feature
, hitem
);
2004 /* the node is expanded if Display is odd */
2005 if ( feature
->Display
% 2 != 0 )
2006 SendMessageW( hwnd
, TVM_EXPAND
, TVE_EXPAND
, (LPARAM
) hitem
);
2009 /* select the first item */
2010 SendMessageW( hwnd
, TVM_SELECTITEM
, TVGN_CARET
| TVGN_DROPHILITE
, (LPARAM
) hfirst
);
2011 info
->selected
= hfirst
;
2014 static void msi_seltree_create_imagelist( HWND hwnd
)
2016 const int bm_width
= 32, bm_height
= 16, bm_count
= 3;
2017 const int bm_resource
= 0x1001;
2022 himl
= ImageList_Create( bm_width
, bm_height
, FALSE
, 4, 0 );
2025 ERR("failed to create image list\n");
2029 for (i
=0; i
<bm_count
; i
++)
2031 hbmp
= LoadBitmapW( msi_hInstance
, MAKEINTRESOURCEW(i
+bm_resource
) );
2034 ERR("failed to load bitmap %d\n", i
);
2039 * Add a dummy bitmap at offset zero because the treeview
2040 * can't use it as a state mask (zero means no user state).
2043 ImageList_Add( himl
, hbmp
, NULL
);
2045 ImageList_Add( himl
, hbmp
, NULL
);
2048 SendMessageW( hwnd
, TVM_SETIMAGELIST
, TVSIL_STATE
, (LPARAM
)himl
);
2051 static UINT
msi_dialog_seltree_handler( msi_dialog
*dialog
,
2052 msi_control
*control
, WPARAM param
)
2054 struct msi_selection_tree_info
*info
= GetPropW( control
->hwnd
, szButtonData
);
2055 LPNMTREEVIEWW tv
= (LPNMTREEVIEWW
)param
;
2056 MSIRECORD
*row
, *rec
;
2059 UINT r
= ERROR_SUCCESS
;
2061 static const WCHAR select
[] = {
2062 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2063 '`','F','e','a','t','u','r','e','`',' ','W','H','E','R','E',' ',
2064 '`','T','i','t','l','e','`',' ','=',' ','\'','%','s','\'',0
2067 if (tv
->hdr
.code
!= TVN_SELCHANGINGW
)
2068 return ERROR_SUCCESS
;
2070 info
->selected
= tv
->itemNew
.hItem
;
2072 row
= MSI_QueryGetRecord( dialog
->package
->db
, select
, tv
->itemNew
.pszText
);
2074 return ERROR_FUNCTION_FAILED
;
2076 rec
= MSI_CreateRecord( 1 );
2078 MSI_RecordSetStringW( rec
, 1, MSI_RecordGetString( row
, 4 ) );
2079 ControlEvent_FireSubscribedEvent( dialog
->package
, szSelectionDescription
, rec
);
2081 dir
= MSI_RecordGetString( row
, 7 );
2082 folder
= get_loaded_folder( dialog
->package
, dir
);
2085 r
= ERROR_FUNCTION_FAILED
;
2089 MSI_RecordSetStringW( rec
, 1, folder
->ResolvedTarget
);
2090 ControlEvent_FireSubscribedEvent( dialog
->package
, szSelectionPath
, rec
);
2093 msiobj_release(&row
->hdr
);
2094 msiobj_release(&rec
->hdr
);
2099 static UINT
msi_dialog_selection_tree( msi_dialog
*dialog
, MSIRECORD
*rec
)
2101 msi_control
*control
;
2103 MSIPACKAGE
*package
= dialog
->package
;
2105 struct msi_selection_tree_info
*info
;
2107 info
= msi_alloc( sizeof *info
);
2109 return ERROR_FUNCTION_FAILED
;
2111 /* create the treeview control */
2112 style
= TVS_HASLINES
| TVS_HASBUTTONS
| TVS_LINESATROOT
;
2113 style
|= WS_GROUP
| WS_VSCROLL
;
2114 control
= msi_dialog_add_control( dialog
, rec
, WC_TREEVIEWW
, style
);
2118 return ERROR_FUNCTION_FAILED
;
2121 control
->handler
= msi_dialog_seltree_handler
;
2122 control
->attributes
= MSI_RecordGetInteger( rec
, 8 );
2123 prop
= MSI_RecordGetString( rec
, 9 );
2124 control
->property
= msi_dialog_dup_property( dialog
, prop
, FALSE
);
2127 info
->dialog
= dialog
;
2128 info
->hwnd
= control
->hwnd
;
2129 info
->oldproc
= (WNDPROC
) SetWindowLongPtrW( control
->hwnd
, GWLP_WNDPROC
,
2130 (LONG_PTR
)MSISelectionTree_WndProc
);
2131 SetPropW( control
->hwnd
, szButtonData
, info
);
2133 ControlEvent_SubscribeToEvent( dialog
->package
, dialog
,
2134 szSelectionPath
, control
->name
, szProperty
);
2137 msi_seltree_create_imagelist( control
->hwnd
);
2138 msi_seltree_add_child_features( package
, control
->hwnd
, NULL
, NULL
);
2140 return ERROR_SUCCESS
;
2143 /******************** Group Box ***************************************/
2145 static UINT
msi_dialog_group_box( msi_dialog
*dialog
, MSIRECORD
*rec
)
2147 msi_control
*control
;
2150 style
= BS_GROUPBOX
| WS_CHILD
| WS_GROUP
;
2151 control
= msi_dialog_add_control( dialog
, rec
, WC_BUTTONW
, style
);
2153 return ERROR_FUNCTION_FAILED
;
2155 return ERROR_SUCCESS
;
2158 /******************** List Box ***************************************/
2160 struct msi_listbox_info
2170 static LRESULT WINAPI
MSIListBox_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
2172 struct msi_listbox_info
*info
;
2176 TRACE("%p %04x %08lx %08lx\n", hWnd
, msg
, wParam
, lParam
);
2178 info
= GetPropW( hWnd
, szButtonData
);
2182 r
= CallWindowProcW( info
->oldproc
, hWnd
, msg
, wParam
, lParam
);
2187 for (j
= 0; j
< info
->num_items
; j
++)
2188 msi_free( info
->items
[j
] );
2189 msi_free( info
->items
);
2191 RemovePropW( hWnd
, szButtonData
);
2198 static UINT
msi_listbox_add_item( MSIRECORD
*rec
, LPVOID param
)
2200 struct msi_listbox_info
*info
= param
;
2201 LPCWSTR value
, text
;
2204 value
= MSI_RecordGetString( rec
, 3 );
2205 text
= MSI_RecordGetString( rec
, 4 );
2207 info
->items
[info
->addpos_items
] = strdupW( value
);
2209 pos
= SendMessageW( info
->hwnd
, LB_ADDSTRING
, 0, (LPARAM
)text
);
2210 SendMessageW( info
->hwnd
, LB_SETITEMDATA
, pos
, (LPARAM
)info
->items
[info
->addpos_items
] );
2211 info
->addpos_items
++;
2212 return ERROR_SUCCESS
;
2215 static UINT
msi_listbox_add_items( struct msi_listbox_info
*info
, LPCWSTR property
)
2218 MSIQUERY
*view
= NULL
;
2221 static const WCHAR query
[] = {
2222 'S','E','L','E','C','T',' ','*',' ',
2223 'F','R','O','M',' ','`','L','i','s','t','B','o','x','`',' ',
2224 'W','H','E','R','E',' ',
2225 '`','P','r','o','p','e','r','t','y','`',' ','=',' ','\'','%','s','\'',' ',
2226 'O','R','D','E','R',' ','B','Y',' ','`','O','r','d','e','r','`',0
2229 r
= MSI_OpenQuery( info
->dialog
->package
->db
, &view
, query
, property
);
2230 if ( r
!= ERROR_SUCCESS
)
2233 /* just get the number of records */
2234 r
= MSI_IterateRecords( view
, &count
, NULL
, NULL
);
2236 info
->num_items
= count
;
2237 info
->items
= msi_alloc( sizeof(*info
->items
) * count
);
2239 r
= MSI_IterateRecords( view
, NULL
, msi_listbox_add_item
, info
);
2240 msiobj_release( &view
->hdr
);
2245 static UINT
msi_dialog_listbox_handler( msi_dialog
*dialog
,
2246 msi_control
*control
, WPARAM param
)
2248 struct msi_listbox_info
*info
;
2252 if( HIWORD(param
) != LBN_SELCHANGE
)
2253 return ERROR_SUCCESS
;
2255 info
= GetPropW( control
->hwnd
, szButtonData
);
2256 index
= SendMessageW( control
->hwnd
, LB_GETCURSEL
, 0, 0 );
2257 value
= (LPCWSTR
) SendMessageW( control
->hwnd
, LB_GETITEMDATA
, index
, 0 );
2259 MSI_SetPropertyW( info
->dialog
->package
,
2260 control
->property
, value
);
2261 msi_dialog_evaluate_control_conditions( info
->dialog
);
2263 return ERROR_SUCCESS
;
2266 static UINT
msi_dialog_list_box( msi_dialog
*dialog
, MSIRECORD
*rec
)
2268 struct msi_listbox_info
*info
;
2269 msi_control
*control
;
2270 DWORD attributes
, style
;
2273 info
= msi_alloc( sizeof *info
);
2275 return ERROR_FUNCTION_FAILED
;
2277 style
= WS_TABSTOP
| WS_GROUP
| WS_CHILD
| LBS_NOTIFY
| WS_VSCROLL
| WS_BORDER
;
2278 attributes
= MSI_RecordGetInteger( rec
, 8 );
2279 if (~attributes
& msidbControlAttributesSorted
)
2282 control
= msi_dialog_add_control( dialog
, rec
, WC_LISTBOXW
, style
);
2286 return ERROR_FUNCTION_FAILED
;
2289 control
->handler
= msi_dialog_listbox_handler
;
2291 prop
= MSI_RecordGetString( rec
, 9 );
2292 control
->property
= msi_dialog_dup_property( dialog
, prop
, FALSE
);
2295 info
->dialog
= dialog
;
2296 info
->hwnd
= control
->hwnd
;
2298 info
->addpos_items
= 0;
2299 info
->oldproc
= (WNDPROC
)SetWindowLongPtrW( control
->hwnd
, GWLP_WNDPROC
,
2300 (LONG_PTR
)MSIListBox_WndProc
);
2301 SetPropW( control
->hwnd
, szButtonData
, info
);
2303 if ( control
->property
)
2304 msi_listbox_add_items( info
, control
->property
);
2306 return ERROR_SUCCESS
;
2309 /******************** Directory Combo ***************************************/
2311 static void msi_dialog_update_directory_combo( msi_dialog
*dialog
, msi_control
*control
)
2316 if (!control
&& !(control
= msi_dialog_find_control_by_type( dialog
, szDirectoryCombo
)))
2319 indirect
= control
->attributes
& msidbControlAttributesIndirect
;
2320 prop
= msi_dialog_dup_property( dialog
, control
->property
, indirect
);
2321 path
= msi_dialog_dup_property( dialog
, prop
, TRUE
);
2323 PathStripPathW( path
);
2324 PathRemoveBackslashW( path
);
2326 SendMessageW( control
->hwnd
, CB_INSERTSTRING
, 0, (LPARAM
)path
);
2327 SendMessageW( control
->hwnd
, CB_SETCURSEL
, 0, 0 );
2333 static UINT
msi_dialog_directory_combo( msi_dialog
*dialog
, MSIRECORD
*rec
)
2335 msi_control
*control
;
2339 /* FIXME: use CBS_OWNERDRAWFIXED and add owner draw code */
2340 style
= CBS_DROPDOWNLIST
| CBS_HASSTRINGS
| WS_CHILD
|
2341 WS_GROUP
| WS_TABSTOP
| WS_VSCROLL
;
2342 control
= msi_dialog_add_control( dialog
, rec
, WC_COMBOBOXW
, style
);
2344 return ERROR_FUNCTION_FAILED
;
2346 control
->attributes
= MSI_RecordGetInteger( rec
, 8 );
2347 prop
= MSI_RecordGetString( rec
, 9 );
2348 control
->property
= msi_dialog_dup_property( dialog
, prop
, FALSE
);
2350 msi_dialog_update_directory_combo( dialog
, control
);
2352 return ERROR_SUCCESS
;
2355 /******************** Directory List ***************************************/
2357 static void msi_dialog_update_directory_list( msi_dialog
*dialog
, msi_control
*control
)
2359 WCHAR dir_spec
[MAX_PATH
];
2360 WIN32_FIND_DATAW wfd
;
2366 static const WCHAR asterisk
[] = {'*',0};
2367 static const WCHAR dot
[] = {'.',0};
2368 static const WCHAR dotdot
[] = {'.','.',0};
2370 if (!control
&& !(control
= msi_dialog_find_control_by_type( dialog
, szDirectoryList
)))
2373 /* clear the list-view */
2374 SendMessageW( control
->hwnd
, LVM_DELETEALLITEMS
, 0, 0 );
2376 indirect
= control
->attributes
& msidbControlAttributesIndirect
;
2377 prop
= msi_dialog_dup_property( dialog
, control
->property
, indirect
);
2378 path
= msi_dialog_dup_property( dialog
, prop
, TRUE
);
2380 lstrcpyW( dir_spec
, path
);
2381 lstrcatW( dir_spec
, asterisk
);
2383 file
= FindFirstFileW( dir_spec
, &wfd
);
2384 if ( file
== INVALID_HANDLE_VALUE
)
2389 if ( wfd
.dwFileAttributes
!= FILE_ATTRIBUTE_DIRECTORY
)
2392 if ( !lstrcmpW( wfd
.cFileName
, dot
) || !lstrcmpW( wfd
.cFileName
, dotdot
) )
2395 item
.mask
= LVIF_TEXT
;
2396 item
.cchTextMax
= MAX_PATH
;
2399 item
.pszText
= wfd
.cFileName
;
2401 SendMessageW( control
->hwnd
, LVM_INSERTITEMW
, 0, (LPARAM
)&item
);
2402 } while ( FindNextFileW( file
, &wfd
) );
2409 UINT
msi_dialog_directorylist_up( msi_dialog
*dialog
)
2411 msi_control
*control
;
2412 LPWSTR prop
, path
, ptr
;
2415 control
= msi_dialog_find_control_by_type( dialog
, szDirectoryList
);
2416 indirect
= control
->attributes
& msidbControlAttributesIndirect
;
2417 prop
= msi_dialog_dup_property( dialog
, control
->property
, indirect
);
2418 path
= msi_dialog_dup_property( dialog
, prop
, TRUE
);
2420 /* strip off the last directory */
2421 ptr
= PathFindFileNameW( path
);
2422 if (ptr
!= path
) *(ptr
- 1) = '\0';
2423 PathAddBackslashW( path
);
2425 MSI_SetPropertyW( dialog
->package
, prop
, path
);
2427 msi_dialog_update_directory_list( dialog
, NULL
);
2428 msi_dialog_update_directory_combo( dialog
, NULL
);
2429 msi_dialog_update_pathedit( dialog
, NULL
);
2434 return ERROR_SUCCESS
;
2437 static UINT
msi_dialog_dirlist_handler( msi_dialog
*dialog
,
2438 msi_control
*control
, WPARAM param
)
2440 LPNMHDR nmhdr
= (LPNMHDR
)param
;
2441 WCHAR new_path
[MAX_PATH
];
2442 WCHAR text
[MAX_PATH
];
2448 static const WCHAR backslash
[] = {'\\',0};
2450 if (nmhdr
->code
!= LVN_ITEMACTIVATE
)
2451 return ERROR_SUCCESS
;
2453 index
= SendMessageW( control
->hwnd
, LVM_GETNEXTITEM
, -1, LVNI_SELECTED
);
2456 ERR("No list-view item selected!\n");
2457 return ERROR_FUNCTION_FAILED
;
2461 item
.pszText
= text
;
2462 item
.cchTextMax
= MAX_PATH
;
2463 SendMessageW( control
->hwnd
, LVM_GETITEMTEXTW
, index
, (LPARAM
)&item
);
2465 indirect
= control
->attributes
& msidbControlAttributesIndirect
;
2466 prop
= msi_dialog_dup_property( dialog
, control
->property
, indirect
);
2467 path
= msi_dialog_dup_property( dialog
, prop
, TRUE
);
2469 lstrcpyW( new_path
, path
);
2470 lstrcatW( new_path
, text
);
2471 lstrcatW( new_path
, backslash
);
2473 MSI_SetPropertyW( dialog
->package
, prop
, new_path
);
2475 msi_dialog_update_directory_list( dialog
, NULL
);
2476 msi_dialog_update_directory_combo( dialog
, NULL
);
2477 msi_dialog_update_pathedit( dialog
, NULL
);
2481 return ERROR_SUCCESS
;
2484 static UINT
msi_dialog_directory_list( msi_dialog
*dialog
, MSIRECORD
*rec
)
2486 msi_control
*control
;
2490 style
= LVS_LIST
| WS_VSCROLL
| LVS_SHAREIMAGELISTS
|
2491 LVS_AUTOARRANGE
| LVS_SINGLESEL
| WS_BORDER
|
2492 LVS_SORTASCENDING
| WS_CHILD
| WS_GROUP
| WS_TABSTOP
;
2493 control
= msi_dialog_add_control( dialog
, rec
, WC_LISTVIEWW
, style
);
2495 return ERROR_FUNCTION_FAILED
;
2497 control
->attributes
= MSI_RecordGetInteger( rec
, 8 );
2498 control
->handler
= msi_dialog_dirlist_handler
;
2499 prop
= MSI_RecordGetString( rec
, 9 );
2500 control
->property
= msi_dialog_dup_property( dialog
, prop
, FALSE
);
2502 /* double click to activate an item in the list */
2503 SendMessageW( control
->hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
,
2504 0, LVS_EX_TWOCLICKACTIVATE
);
2506 msi_dialog_update_directory_list( dialog
, control
);
2508 return ERROR_SUCCESS
;
2511 /******************** VolumeCost List ***************************************/
2513 static BOOL
str_is_number( LPCWSTR str
)
2517 for (i
= 0; i
< lstrlenW( str
); i
++)
2518 if (!isdigitW(str
[i
]))
2524 static const WCHAR column_keys
[][80] =
2526 {'V','o','l','u','m','e','C','o','s','t','V','o','l','u','m','e',0},
2527 {'V','o','l','u','m','e','C','o','s','t','S','i','z','e',0},
2528 {'V','o','l','u','m','e','C','o','s','t','A','v','a','i','l','a','b','l','e',0},
2529 {'V','o','l','u','m','e','C','o','s','t','R','e','q','u','i','r','e','d',0},
2530 {'V','o','l','u','m','e','C','o','s','t','D','i','f','f','e','r','e','n','c','e',0}
2533 static void msi_dialog_vcl_add_columns( msi_dialog
*dialog
, msi_control
*control
, MSIRECORD
*rec
)
2535 LPCWSTR text
= MSI_RecordGetString( rec
, 10 );
2536 LPCWSTR begin
= text
, end
;
2541 static const WCHAR zero
[] = {'0',0};
2542 static const WCHAR negative
[] = {'-',0};
2546 while ((begin
= strchrW( begin
, '{' )) && count
< 5)
2548 if (!(end
= strchrW( begin
, '}' )))
2551 num
= msi_alloc( (end
-begin
+1)*sizeof(WCHAR
) );
2555 lstrcpynW( num
, begin
+ 1, end
- begin
);
2556 begin
+= end
- begin
+ 1;
2558 /* empty braces or '0' hides the column */
2559 if ( !num
[0] || !lstrcmpW( num
, zero
) )
2566 /* the width must be a positive number
2567 * if a width is invalid, all remaining columns are hidden
2569 if ( !strncmpW( num
, negative
, 1 ) || !str_is_number( num
) ) {
2574 ZeroMemory( &lvc
, sizeof(lvc
) );
2575 lvc
.mask
= LVCF_TEXT
| LVCF_WIDTH
| LVCF_SUBITEM
;
2576 lvc
.cx
= atolW( num
);
2577 lvc
.pszText
= msi_dialog_get_uitext( dialog
, column_keys
[count
] );
2579 SendMessageW( control
->hwnd
, LVM_INSERTCOLUMNW
, count
++, (LPARAM
)&lvc
);
2580 msi_free( lvc
.pszText
);
2585 static void msi_dialog_vcl_add_drives( msi_dialog
*dialog
, msi_control
*control
)
2587 ULARGE_INTEGER total
, free
;
2588 WCHAR size_text
[MAX_PATH
];
2594 size
= GetLogicalDriveStringsW( 0, NULL
);
2595 if ( !size
) return;
2597 drives
= msi_alloc( (size
+ 1) * sizeof(WCHAR
) );
2598 if ( !drives
) return;
2600 GetLogicalDriveStringsW( size
, drives
);
2605 lvitem
.mask
= LVIF_TEXT
;
2607 lvitem
.iSubItem
= 0;
2608 lvitem
.pszText
= ptr
;
2609 lvitem
.cchTextMax
= lstrlenW(ptr
) + 1;
2610 SendMessageW( control
->hwnd
, LVM_INSERTITEMW
, 0, (LPARAM
)&lvitem
);
2612 GetDiskFreeSpaceExW(ptr
, &free
, &total
, NULL
);
2614 StrFormatByteSizeW(total
.QuadPart
, size_text
, MAX_PATH
);
2615 lvitem
.iSubItem
= 1;
2616 lvitem
.pszText
= size_text
;
2617 lvitem
.cchTextMax
= lstrlenW(size_text
) + 1;
2618 SendMessageW( control
->hwnd
, LVM_SETITEMW
, 0, (LPARAM
)&lvitem
);
2620 StrFormatByteSizeW(free
.QuadPart
, size_text
, MAX_PATH
);
2621 lvitem
.iSubItem
= 2;
2622 lvitem
.pszText
= size_text
;
2623 lvitem
.cchTextMax
= lstrlenW(size_text
) + 1;
2624 SendMessageW( control
->hwnd
, LVM_SETITEMW
, 0, (LPARAM
)&lvitem
);
2626 ptr
+= lstrlenW(ptr
) + 1;
2633 static UINT
msi_dialog_volumecost_list( msi_dialog
*dialog
, MSIRECORD
*rec
)
2635 msi_control
*control
;
2638 style
= LVS_REPORT
| WS_VSCROLL
| WS_HSCROLL
| LVS_SHAREIMAGELISTS
|
2639 LVS_AUTOARRANGE
| LVS_SINGLESEL
| WS_BORDER
|
2640 WS_CHILD
| WS_TABSTOP
| WS_GROUP
;
2641 control
= msi_dialog_add_control( dialog
, rec
, WC_LISTVIEWW
, style
);
2643 return ERROR_FUNCTION_FAILED
;
2645 msi_dialog_vcl_add_columns( dialog
, control
, rec
);
2646 msi_dialog_vcl_add_drives( dialog
, control
);
2648 return ERROR_SUCCESS
;
2651 /******************** VolumeSelect Combo ***************************************/
2653 static UINT
msi_dialog_volsel_handler( msi_dialog
*dialog
,
2654 msi_control
*control
, WPARAM param
)
2656 WCHAR text
[MAX_PATH
];
2661 if (HIWORD(param
) != CBN_SELCHANGE
)
2662 return ERROR_SUCCESS
;
2664 index
= SendMessageW( control
->hwnd
, CB_GETCURSEL
, 0, 0 );
2665 if ( index
== CB_ERR
)
2667 ERR("No ComboBox item selected!\n");
2668 return ERROR_FUNCTION_FAILED
;
2671 SendMessageW( control
->hwnd
, CB_GETLBTEXT
, index
, (LPARAM
)text
);
2673 indirect
= control
->attributes
& msidbControlAttributesIndirect
;
2674 prop
= msi_dialog_dup_property( dialog
, control
->property
, indirect
);
2676 MSI_SetPropertyW( dialog
->package
, prop
, text
);
2679 return ERROR_SUCCESS
;
2682 static void msi_dialog_vsc_add_drives( msi_dialog
*dialog
, msi_control
*control
)
2687 size
= GetLogicalDriveStringsW( 0, NULL
);
2688 if ( !size
) return;
2690 drives
= msi_alloc( (size
+ 1) * sizeof(WCHAR
) );
2691 if ( !drives
) return;
2693 GetLogicalDriveStringsW( size
, drives
);
2698 SendMessageW( control
->hwnd
, CB_ADDSTRING
, 0, (LPARAM
)ptr
);
2699 ptr
+= lstrlenW(ptr
) + 1;
2705 static UINT
msi_dialog_volumeselect_combo( msi_dialog
*dialog
, MSIRECORD
*rec
)
2707 msi_control
*control
;
2711 /* FIXME: CBS_OWNERDRAWFIXED */
2712 style
= WS_CHILD
| WS_VISIBLE
| WS_GROUP
| WS_TABSTOP
|
2713 CBS_DROPDOWNLIST
| CBS_SORT
| CBS_HASSTRINGS
|
2714 WS_EX_LEFT
| WS_EX_LTRREADING
| WS_EX_RIGHTSCROLLBAR
;
2715 control
= msi_dialog_add_control( dialog
, rec
, WC_COMBOBOXW
, style
);
2717 return ERROR_FUNCTION_FAILED
;
2719 control
->attributes
= MSI_RecordGetInteger( rec
, 8 );
2720 control
->handler
= msi_dialog_volsel_handler
;
2721 prop
= MSI_RecordGetString( rec
, 9 );
2722 control
->property
= msi_dialog_dup_property( dialog
, prop
, FALSE
);
2724 msi_dialog_vsc_add_drives( dialog
, control
);
2726 return ERROR_SUCCESS
;
2729 static const struct control_handler msi_dialog_handler
[] =
2731 { szText
, msi_dialog_text_control
},
2732 { szPushButton
, msi_dialog_button_control
},
2733 { szLine
, msi_dialog_line_control
},
2734 { szBitmap
, msi_dialog_bitmap_control
},
2735 { szCheckBox
, msi_dialog_checkbox_control
},
2736 { szScrollableText
, msi_dialog_scrolltext_control
},
2737 { szComboBox
, msi_dialog_combo_control
},
2738 { szEdit
, msi_dialog_edit_control
},
2739 { szMaskedEdit
, msi_dialog_maskedit_control
},
2740 { szPathEdit
, msi_dialog_pathedit_control
},
2741 { szProgressBar
, msi_dialog_progress_bar
},
2742 { szRadioButtonGroup
, msi_dialog_radiogroup_control
},
2743 { szIcon
, msi_dialog_icon_control
},
2744 { szSelectionTree
, msi_dialog_selection_tree
},
2745 { szGroupBox
, msi_dialog_group_box
},
2746 { szListBox
, msi_dialog_list_box
},
2747 { szDirectoryCombo
, msi_dialog_directory_combo
},
2748 { szDirectoryList
, msi_dialog_directory_list
},
2749 { szVolumeCostList
, msi_dialog_volumecost_list
},
2750 { szVolumeSelectCombo
, msi_dialog_volumeselect_combo
},
2753 #define NUM_CONTROL_TYPES (sizeof msi_dialog_handler/sizeof msi_dialog_handler[0])
2755 static UINT
msi_dialog_create_controls( MSIRECORD
*rec
, LPVOID param
)
2757 msi_dialog
*dialog
= param
;
2758 LPCWSTR control_type
;
2761 /* find and call the function that can create this type of control */
2762 control_type
= MSI_RecordGetString( rec
, 3 );
2763 for( i
=0; i
<NUM_CONTROL_TYPES
; i
++ )
2764 if (!strcmpiW( msi_dialog_handler
[i
].control_type
, control_type
))
2766 if( i
!= NUM_CONTROL_TYPES
)
2767 msi_dialog_handler
[i
].func( dialog
, rec
);
2769 ERR("no handler for element type %s\n", debugstr_w(control_type
));
2771 return ERROR_SUCCESS
;
2774 static UINT
msi_dialog_fill_controls( msi_dialog
*dialog
)
2776 static const WCHAR query
[] = {
2777 'S','E','L','E','C','T',' ','*',' ',
2778 'F','R','O','M',' ','C','o','n','t','r','o','l',' ',
2779 'W','H','E','R','E',' ',
2780 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',0};
2782 MSIQUERY
*view
= NULL
;
2783 MSIPACKAGE
*package
= dialog
->package
;
2785 TRACE("%p %s\n", dialog
, debugstr_w(dialog
->name
) );
2787 /* query the Control table for all the elements of the control */
2788 r
= MSI_OpenQuery( package
->db
, &view
, query
, dialog
->name
);
2789 if( r
!= ERROR_SUCCESS
)
2791 ERR("query failed for dialog %s\n", debugstr_w(dialog
->name
));
2792 return ERROR_INVALID_PARAMETER
;
2795 r
= MSI_IterateRecords( view
, 0, msi_dialog_create_controls
, dialog
);
2796 msiobj_release( &view
->hdr
);
2801 static UINT
msi_dialog_set_control_condition( MSIRECORD
*rec
, LPVOID param
)
2803 static const WCHAR szHide
[] = { 'H','i','d','e',0 };
2804 static const WCHAR szShow
[] = { 'S','h','o','w',0 };
2805 static const WCHAR szDisable
[] = { 'D','i','s','a','b','l','e',0 };
2806 static const WCHAR szEnable
[] = { 'E','n','a','b','l','e',0 };
2807 static const WCHAR szDefault
[] = { 'D','e','f','a','u','l','t',0 };
2808 msi_dialog
*dialog
= param
;
2809 msi_control
*control
;
2810 LPCWSTR name
, action
, condition
;
2813 name
= MSI_RecordGetString( rec
, 2 );
2814 action
= MSI_RecordGetString( rec
, 3 );
2815 condition
= MSI_RecordGetString( rec
, 4 );
2816 r
= MSI_EvaluateConditionW( dialog
->package
, condition
);
2817 control
= msi_dialog_find_control( dialog
, name
);
2818 if( r
== MSICONDITION_TRUE
&& control
)
2820 TRACE("%s control %s\n", debugstr_w(action
), debugstr_w(name
));
2822 /* FIXME: case sensitive? */
2823 if(!lstrcmpW(action
, szHide
))
2824 ShowWindow(control
->hwnd
, SW_HIDE
);
2825 else if(!strcmpW(action
, szShow
))
2826 ShowWindow(control
->hwnd
, SW_SHOW
);
2827 else if(!strcmpW(action
, szDisable
))
2828 EnableWindow(control
->hwnd
, FALSE
);
2829 else if(!strcmpW(action
, szEnable
))
2830 EnableWindow(control
->hwnd
, TRUE
);
2831 else if(!strcmpW(action
, szDefault
))
2832 SetFocus(control
->hwnd
);
2834 FIXME("Unhandled action %s\n", debugstr_w(action
));
2837 return ERROR_SUCCESS
;
2840 static UINT
msi_dialog_evaluate_control_conditions( msi_dialog
*dialog
)
2842 static const WCHAR query
[] = {
2843 'S','E','L','E','C','T',' ','*',' ',
2844 'F','R','O','M',' ',
2845 'C','o','n','t','r','o','l','C','o','n','d','i','t','i','o','n',' ',
2846 'W','H','E','R','E',' ',
2847 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',0
2850 MSIQUERY
*view
= NULL
;
2851 MSIPACKAGE
*package
= dialog
->package
;
2853 TRACE("%p %s\n", dialog
, debugstr_w(dialog
->name
) );
2855 /* query the Control table for all the elements of the control */
2856 r
= MSI_OpenQuery( package
->db
, &view
, query
, dialog
->name
);
2857 if( r
!= ERROR_SUCCESS
)
2858 return ERROR_SUCCESS
;
2860 r
= MSI_IterateRecords( view
, 0, msi_dialog_set_control_condition
, dialog
);
2861 msiobj_release( &view
->hdr
);
2866 UINT
msi_dialog_reset( msi_dialog
*dialog
)
2868 /* FIXME: should restore the original values of any properties we changed */
2869 return msi_dialog_evaluate_control_conditions( dialog
);
2872 /* figure out the height of 10 point MS Sans Serif */
2873 static INT
msi_dialog_get_sans_serif_height( HWND hwnd
)
2875 static const WCHAR szSansSerif
[] = {
2876 'M','S',' ','S','a','n','s',' ','S','e','r','i','f',0 };
2881 HFONT hFont
, hOldFont
;
2884 hdc
= GetDC( hwnd
);
2887 memset( &lf
, 0, sizeof lf
);
2888 lf
.lfHeight
= MulDiv(10, GetDeviceCaps(hdc
, LOGPIXELSY
), 72);
2889 strcpyW( lf
.lfFaceName
, szSansSerif
);
2890 hFont
= CreateFontIndirectW(&lf
);
2893 hOldFont
= SelectObject( hdc
, hFont
);
2894 r
= GetTextMetricsW( hdc
, &tm
);
2896 height
= tm
.tmHeight
;
2897 SelectObject( hdc
, hOldFont
);
2898 DeleteObject( hFont
);
2900 ReleaseDC( hwnd
, hdc
);
2905 /* fetch the associated record from the Dialog table */
2906 static MSIRECORD
*msi_get_dialog_record( msi_dialog
*dialog
)
2908 static const WCHAR query
[] = {
2909 'S','E','L','E','C','T',' ','*',' ',
2910 'F','R','O','M',' ','D','i','a','l','o','g',' ',
2911 'W','H','E','R','E',' ',
2912 '`','D','i','a','l','o','g','`',' ','=',' ','\'','%','s','\'',0};
2913 MSIPACKAGE
*package
= dialog
->package
;
2914 MSIRECORD
*rec
= NULL
;
2916 TRACE("%p %s\n", dialog
, debugstr_w(dialog
->name
) );
2918 rec
= MSI_QueryGetRecord( package
->db
, query
, dialog
->name
);
2920 WARN("query failed for dialog %s\n", debugstr_w(dialog
->name
));
2925 static void msi_dialog_adjust_dialog_pos( msi_dialog
*dialog
, MSIRECORD
*rec
, LPRECT pos
)
2927 static const WCHAR szScreenX
[] = {'S','c','r','e','e','n','X',0};
2928 static const WCHAR szScreenY
[] = {'S','c','r','e','e','n','Y',0};
2935 center
.x
= MSI_RecordGetInteger( rec
, 2 );
2936 center
.y
= MSI_RecordGetInteger( rec
, 3 );
2938 sz
.cx
= MSI_RecordGetInteger( rec
, 4 );
2939 sz
.cy
= MSI_RecordGetInteger( rec
, 5 );
2941 sz
.cx
= msi_dialog_scale_unit( dialog
, sz
.cx
);
2942 sz
.cy
= msi_dialog_scale_unit( dialog
, sz
.cy
);
2944 xres
= msi_get_property_int( dialog
->package
, szScreenX
, 0 );
2945 yres
= msi_get_property_int( dialog
->package
, szScreenY
, 0 );
2947 center
.x
= MulDiv( center
.x
, xres
, 100 );
2948 center
.y
= MulDiv( center
.y
, yres
, 100 );
2950 /* turn the client pos into the window rectangle */
2951 if (dialog
->package
->center_x
&& dialog
->package
->center_y
)
2953 pos
->left
= dialog
->package
->center_x
- sz
.cx
/ 2.0;
2954 pos
->right
= pos
->left
+ sz
.cx
;
2955 pos
->top
= dialog
->package
->center_y
- sz
.cy
/ 2.0;
2956 pos
->bottom
= pos
->top
+ sz
.cy
;
2960 pos
->left
= center
.x
- sz
.cx
/2;
2961 pos
->right
= pos
->left
+ sz
.cx
;
2962 pos
->top
= center
.y
- sz
.cy
/2;
2963 pos
->bottom
= pos
->top
+ sz
.cy
;
2965 /* save the center */
2966 dialog
->package
->center_x
= center
.x
;
2967 dialog
->package
->center_y
= center
.y
;
2970 dialog
->size
.cx
= sz
.cx
;
2971 dialog
->size
.cy
= sz
.cy
;
2973 TRACE("%u %u %u %u\n", pos
->left
, pos
->top
, pos
->right
, pos
->bottom
);
2975 style
= GetWindowLongPtrW( dialog
->hwnd
, GWL_STYLE
);
2976 AdjustWindowRect( pos
, style
, FALSE
);
2979 static BOOL
msi_control_set_next( msi_control
*control
, msi_control
*next
)
2981 return SetWindowPos( next
->hwnd
, control
->hwnd
, 0, 0, 0, 0,
2982 SWP_NOMOVE
| SWP_NOOWNERZORDER
| SWP_NOREDRAW
|
2983 SWP_NOREPOSITION
| SWP_NOSENDCHANGING
| SWP_NOSIZE
);
2986 static UINT
msi_dialog_set_tab_order( msi_dialog
*dialog
)
2988 msi_control
*control
, *tab_next
;
2990 LIST_FOR_EACH_ENTRY( control
, &dialog
->controls
, msi_control
, entry
)
2992 tab_next
= msi_dialog_find_control( dialog
, control
->tabnext
);
2995 msi_control_set_next( control
, tab_next
);
2998 return ERROR_SUCCESS
;
3001 static void msi_dialog_set_first_control( msi_dialog
* dialog
, LPCWSTR name
)
3003 msi_control
*control
;
3005 control
= msi_dialog_find_control( dialog
, name
);
3007 dialog
->hWndFocus
= control
->hwnd
;
3009 dialog
->hWndFocus
= NULL
;
3012 static LRESULT
msi_dialog_oncreate( HWND hwnd
, LPCREATESTRUCTW cs
)
3014 static const WCHAR df
[] = {
3015 'D','e','f','a','u','l','t','U','I','F','o','n','t',0 };
3016 static const WCHAR dfv
[] = {
3017 'M','S',' ','S','h','e','l','l',' ','D','l','g',0 };
3018 msi_dialog
*dialog
= (msi_dialog
*) cs
->lpCreateParams
;
3019 MSIRECORD
*rec
= NULL
;
3020 LPWSTR title
= NULL
;
3023 TRACE("%p %p\n", dialog
, dialog
->package
);
3025 dialog
->hwnd
= hwnd
;
3026 SetWindowLongPtrW( hwnd
, GWLP_USERDATA
, (LONG_PTR
) dialog
);
3028 rec
= msi_get_dialog_record( dialog
);
3031 TRACE("No record found for dialog %s\n", debugstr_w(dialog
->name
));
3035 dialog
->scale
= msi_dialog_get_sans_serif_height(dialog
->hwnd
);
3037 msi_dialog_adjust_dialog_pos( dialog
, rec
, &pos
);
3039 dialog
->attributes
= MSI_RecordGetInteger( rec
, 6 );
3041 dialog
->default_font
= msi_dup_property( dialog
->package
, df
);
3042 if (!dialog
->default_font
)
3044 dialog
->default_font
= strdupW(dfv
);
3045 if (!dialog
->default_font
) return -1;
3048 title
= msi_get_deformatted_field( dialog
->package
, rec
, 7 );
3049 SetWindowTextW( hwnd
, title
);
3052 SetWindowPos( hwnd
, 0, pos
.left
, pos
.top
,
3053 pos
.right
- pos
.left
, pos
.bottom
- pos
.top
,
3054 SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_NOREDRAW
);
3056 msi_dialog_build_font_list( dialog
);
3057 msi_dialog_fill_controls( dialog
);
3058 msi_dialog_evaluate_control_conditions( dialog
);
3059 msi_dialog_set_tab_order( dialog
);
3060 msi_dialog_set_first_control( dialog
, MSI_RecordGetString( rec
, 8 ) );
3061 msiobj_release( &rec
->hdr
);
3066 static UINT
msi_dialog_send_event( msi_dialog
*dialog
, LPCWSTR event
, LPCWSTR arg
)
3068 LPWSTR event_fmt
= NULL
, arg_fmt
= NULL
;
3070 TRACE("Sending control event %s %s\n", debugstr_w(event
), debugstr_w(arg
));
3072 deformat_string( dialog
->package
, event
, &event_fmt
);
3073 deformat_string( dialog
->package
, arg
, &arg_fmt
);
3075 dialog
->event_handler( dialog
->package
, event_fmt
, arg_fmt
, dialog
);
3077 msi_free( event_fmt
);
3078 msi_free( arg_fmt
);
3080 return ERROR_SUCCESS
;
3083 static UINT
msi_dialog_set_property( msi_dialog
*dialog
, LPCWSTR event
, LPCWSTR arg
)
3085 static const WCHAR szNullArg
[] = { '{','}',0 };
3086 LPWSTR p
, prop
, arg_fmt
= NULL
;
3089 len
= strlenW(event
);
3090 prop
= msi_alloc( len
*sizeof(WCHAR
));
3091 strcpyW( prop
, &event
[1] );
3092 p
= strchrW( prop
, ']' );
3093 if( p
&& (p
[1] == 0 || p
[1] == ' ') )
3096 if( strcmpW( szNullArg
, arg
) )
3097 deformat_string( dialog
->package
, arg
, &arg_fmt
);
3098 MSI_SetPropertyW( dialog
->package
, prop
, arg_fmt
);
3099 msi_dialog_update_controls( dialog
, prop
);
3100 msi_free( arg_fmt
);
3103 ERR("Badly formatted property string - what happens?\n");
3105 return ERROR_SUCCESS
;
3108 static UINT
msi_dialog_control_event( MSIRECORD
*rec
, LPVOID param
)
3110 msi_dialog
*dialog
= param
;
3111 LPCWSTR condition
, event
, arg
;
3114 condition
= MSI_RecordGetString( rec
, 5 );
3115 r
= MSI_EvaluateConditionW( dialog
->package
, condition
);
3116 if( r
== MSICONDITION_TRUE
|| r
== MSICONDITION_NONE
)
3118 event
= MSI_RecordGetString( rec
, 3 );
3119 arg
= MSI_RecordGetString( rec
, 4 );
3120 if( event
[0] == '[' )
3121 msi_dialog_set_property( dialog
, event
, arg
);
3123 msi_dialog_send_event( dialog
, event
, arg
);
3126 return ERROR_SUCCESS
;
3135 static UINT
add_rec_to_list( MSIRECORD
*rec
, LPVOID param
)
3137 struct rec_list
*add_rec
;
3138 struct list
*records
= (struct list
*)param
;
3140 msiobj_addref( &rec
->hdr
);
3142 add_rec
= msi_alloc( sizeof( *add_rec
) );
3145 msiobj_release( &rec
->hdr
);
3146 return ERROR_OUTOFMEMORY
;
3150 list_add_tail( records
, &add_rec
->entry
);
3151 return ERROR_SUCCESS
;
3154 static inline void remove_rec_from_list( struct rec_list
*rec_entry
)
3156 msiobj_release( &rec_entry
->rec
->hdr
);
3157 list_remove( &rec_entry
->entry
);
3158 msi_free( rec_entry
);
3161 static UINT
msi_dialog_button_handler( msi_dialog
*dialog
,
3162 msi_control
*control
, WPARAM param
)
3164 static const WCHAR query
[] = {
3165 'S','E','L','E','C','T',' ','*',' ',
3166 'F','R','O','M',' ','C','o','n','t','r','o','l','E','v','e','n','t',' ',
3167 'W','H','E','R','E',' ',
3168 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',' ',
3170 '`','C','o','n','t','r','o','l','_','`',' ','=',' ','\'','%','s','\'',' ',
3171 'O','R','D','E','R',' ','B','Y',' ','`','O','r','d','e','r','i','n','g','`',0
3173 MSIQUERY
*view
= NULL
;
3174 struct rec_list
*rec_entry
, *next
;
3178 if( HIWORD(param
) != BN_CLICKED
)
3179 return ERROR_SUCCESS
;
3181 list_init( &events
);
3183 r
= MSI_OpenQuery( dialog
->package
->db
, &view
, query
,
3184 dialog
->name
, control
->name
);
3185 if( r
!= ERROR_SUCCESS
)
3187 ERR("query failed\n");
3191 r
= MSI_IterateRecords( view
, 0, add_rec_to_list
, &events
);
3192 msiobj_release( &view
->hdr
);
3193 if (r
!= ERROR_SUCCESS
)
3196 /* handle all SetProperty events first */
3197 LIST_FOR_EACH_ENTRY_SAFE( rec_entry
, next
, &events
, struct rec_list
, entry
)
3199 LPCWSTR event
= MSI_RecordGetString( rec_entry
->rec
, 3 );
3201 if ( event
[0] != '[' )
3204 r
= msi_dialog_control_event( rec_entry
->rec
, dialog
);
3205 remove_rec_from_list( rec_entry
);
3207 if ( r
!= ERROR_SUCCESS
)
3211 /* handle all other events */
3212 LIST_FOR_EACH_ENTRY_SAFE( rec_entry
, next
, &events
, struct rec_list
, entry
)
3214 r
= msi_dialog_control_event( rec_entry
->rec
, dialog
);
3215 remove_rec_from_list( rec_entry
);
3217 if ( r
!= ERROR_SUCCESS
)
3222 LIST_FOR_EACH_ENTRY_SAFE( rec_entry
, next
, &events
, struct rec_list
, entry
)
3224 remove_rec_from_list( rec_entry
);
3230 static UINT
msi_dialog_get_checkbox_state( msi_dialog
*dialog
,
3231 msi_control
*control
)
3233 WCHAR state
[2] = { 0 };
3236 MSI_GetPropertyW( dialog
->package
, control
->property
, state
, &sz
);
3237 return state
[0] ? 1 : 0;
3240 static void msi_dialog_set_checkbox_state( msi_dialog
*dialog
,
3241 msi_control
*control
, UINT state
)
3243 static const WCHAR szState
[] = { '1', 0 };
3246 /* if uncheck then the property is set to NULL */
3249 MSI_SetPropertyW( dialog
->package
, control
->property
, NULL
);
3253 /* check for a custom state */
3254 if (control
->value
&& control
->value
[0])
3255 val
= control
->value
;
3259 MSI_SetPropertyW( dialog
->package
, control
->property
, val
);
3262 static void msi_dialog_checkbox_sync_state( msi_dialog
*dialog
,
3263 msi_control
*control
)
3267 state
= msi_dialog_get_checkbox_state( dialog
, control
);
3268 SendMessageW( control
->hwnd
, BM_SETCHECK
,
3269 state
? BST_CHECKED
: BST_UNCHECKED
, 0 );
3272 static UINT
msi_dialog_checkbox_handler( msi_dialog
*dialog
,
3273 msi_control
*control
, WPARAM param
)
3277 if( HIWORD(param
) != BN_CLICKED
)
3278 return ERROR_SUCCESS
;
3280 TRACE("clicked checkbox %s, set %s\n", debugstr_w(control
->name
),
3281 debugstr_w(control
->property
));
3283 state
= msi_dialog_get_checkbox_state( dialog
, control
);
3284 state
= state
? 0 : 1;
3285 msi_dialog_set_checkbox_state( dialog
, control
, state
);
3286 msi_dialog_checkbox_sync_state( dialog
, control
);
3288 return msi_dialog_button_handler( dialog
, control
, param
);
3291 static UINT
msi_dialog_edit_handler( msi_dialog
*dialog
,
3292 msi_control
*control
, WPARAM param
)
3296 if( HIWORD(param
) != EN_CHANGE
)
3297 return ERROR_SUCCESS
;
3299 TRACE("edit %s contents changed, set %s\n", debugstr_w(control
->name
),
3300 debugstr_w(control
->property
));
3302 buf
= msi_get_window_text( control
->hwnd
);
3303 MSI_SetPropertyW( dialog
->package
, control
->property
, buf
);
3307 return ERROR_SUCCESS
;
3310 static UINT
msi_dialog_radiogroup_handler( msi_dialog
*dialog
,
3311 msi_control
*control
, WPARAM param
)
3313 if( HIWORD(param
) != BN_CLICKED
)
3314 return ERROR_SUCCESS
;
3316 TRACE("clicked radio button %s, set %s\n", debugstr_w(control
->name
),
3317 debugstr_w(control
->property
));
3319 MSI_SetPropertyW( dialog
->package
, control
->property
, control
->name
);
3321 return msi_dialog_button_handler( dialog
, control
, param
);
3324 static LRESULT
msi_dialog_oncommand( msi_dialog
*dialog
, WPARAM param
, HWND hwnd
)
3326 msi_control
*control
= NULL
;
3328 TRACE("%p %p %08lx\n", dialog
, hwnd
, param
);
3333 control
= msi_dialog_find_control( dialog
, dialog
->control_default
);
3335 case 2: /* escape */
3336 control
= msi_dialog_find_control( dialog
, dialog
->control_cancel
);
3339 control
= msi_dialog_find_control_by_hwnd( dialog
, hwnd
);
3344 if( control
->handler
)
3346 control
->handler( dialog
, control
, param
);
3347 msi_dialog_evaluate_control_conditions( dialog
);
3354 static LRESULT
msi_dialog_onnotify( msi_dialog
*dialog
, LPARAM param
)
3356 LPNMHDR nmhdr
= (LPNMHDR
) param
;
3357 msi_control
*control
= msi_dialog_find_control_by_hwnd( dialog
, nmhdr
->hwndFrom
);
3359 TRACE("%p %p\n", dialog
, nmhdr
->hwndFrom
);
3361 if ( control
&& control
->handler
)
3362 control
->handler( dialog
, control
, param
);
3367 static void msi_dialog_setfocus( msi_dialog
*dialog
)
3369 HWND hwnd
= dialog
->hWndFocus
;
3371 hwnd
= GetNextDlgTabItem( dialog
->hwnd
, hwnd
, TRUE
);
3372 hwnd
= GetNextDlgTabItem( dialog
->hwnd
, hwnd
, FALSE
);
3374 dialog
->hWndFocus
= hwnd
;
3377 static LRESULT WINAPI
MSIDialog_WndProc( HWND hwnd
, UINT msg
,
3378 WPARAM wParam
, LPARAM lParam
)
3380 msi_dialog
*dialog
= (LPVOID
) GetWindowLongPtrW( hwnd
, GWLP_USERDATA
);
3382 TRACE("0x%04x\n", msg
);
3387 dialog
->package
->center_x
= LOWORD(lParam
) + dialog
->size
.cx
/ 2.0;
3388 dialog
->package
->center_y
= HIWORD(lParam
) + dialog
->size
.cy
/ 2.0;
3392 return msi_dialog_oncreate( hwnd
, (LPCREATESTRUCTW
)lParam
);
3395 return msi_dialog_oncommand( dialog
, wParam
, (HWND
)lParam
);
3398 if( LOWORD(wParam
) == WA_INACTIVE
)
3399 dialog
->hWndFocus
= GetFocus();
3401 msi_dialog_setfocus( dialog
);
3405 msi_dialog_setfocus( dialog
);
3408 /* bounce back to our subclassed static control */
3409 case WM_CTLCOLORSTATIC
:
3410 return SendMessageW( (HWND
) lParam
, WM_CTLCOLORSTATIC
, wParam
, lParam
);
3413 dialog
->hwnd
= NULL
;
3416 return msi_dialog_onnotify( dialog
, lParam
);
3418 return DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
3421 static BOOL CALLBACK
msi_radioground_child_enum( HWND hWnd
, LPARAM lParam
)
3423 EnableWindow( hWnd
, lParam
);
3427 static LRESULT WINAPI
MSIRadioGroup_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
3429 WNDPROC oldproc
= (WNDPROC
) GetPropW(hWnd
, szButtonData
);
3432 TRACE("hWnd %p msg %04x wParam 0x%08lx lParam 0x%08lx\n", hWnd
, msg
, wParam
, lParam
);
3434 if (msg
== WM_COMMAND
) /* Forward notifications to dialog */
3435 SendMessageW(GetParent(hWnd
), msg
, wParam
, lParam
);
3437 r
= CallWindowProcW(oldproc
, hWnd
, msg
, wParam
, lParam
);
3439 /* make sure the radio buttons show as disabled if the parent is disabled */
3440 if (msg
== WM_ENABLE
)
3441 EnumChildWindows( hWnd
, msi_radioground_child_enum
, wParam
);
3446 static LRESULT WINAPI
MSIHiddenWindowProc( HWND hwnd
, UINT msg
,
3447 WPARAM wParam
, LPARAM lParam
)
3449 msi_dialog
*dialog
= (msi_dialog
*) lParam
;
3451 TRACE("%d %p\n", msg
, dialog
);
3455 case WM_MSI_DIALOG_CREATE
:
3456 return msi_dialog_run_message_loop( dialog
);
3457 case WM_MSI_DIALOG_DESTROY
:
3458 msi_dialog_destroy( dialog
);
3461 return DefWindowProcW( hwnd
, msg
, wParam
, lParam
);
3464 /* functions that interface to other modules within MSI */
3466 msi_dialog
*msi_dialog_create( MSIPACKAGE
* package
,
3467 LPCWSTR szDialogName
, msi_dialog
*parent
,
3468 msi_dialog_event_handler event_handler
)
3470 MSIRECORD
*rec
= NULL
;
3473 TRACE("%p %s\n", package
, debugstr_w(szDialogName
));
3475 /* allocate the structure for the dialog to use */
3476 dialog
= msi_alloc_zero( sizeof *dialog
+ sizeof(WCHAR
)*strlenW(szDialogName
) );
3479 strcpyW( dialog
->name
, szDialogName
);
3480 dialog
->parent
= parent
;
3481 msiobj_addref( &package
->hdr
);
3482 dialog
->package
= package
;
3483 dialog
->event_handler
= event_handler
;
3484 dialog
->finished
= 0;
3485 list_init( &dialog
->controls
);
3487 /* verify that the dialog exists */
3488 rec
= msi_get_dialog_record( dialog
);
3491 msiobj_release( &package
->hdr
);
3495 dialog
->attributes
= MSI_RecordGetInteger( rec
, 6 );
3496 dialog
->control_default
= strdupW( MSI_RecordGetString( rec
, 9 ) );
3497 dialog
->control_cancel
= strdupW( MSI_RecordGetString( rec
, 10 ) );
3498 msiobj_release( &rec
->hdr
);
3503 static void msi_process_pending_messages( HWND hdlg
)
3507 while( PeekMessageW( &msg
, 0, 0, 0, PM_REMOVE
) )
3509 if( hdlg
&& IsDialogMessageW( hdlg
, &msg
))
3511 TranslateMessage( &msg
);
3512 DispatchMessageW( &msg
);
3516 void msi_dialog_end_dialog( msi_dialog
*dialog
)
3518 TRACE("%p\n", dialog
);
3519 dialog
->finished
= 1;
3520 PostMessageW(dialog
->hwnd
, WM_NULL
, 0, 0);
3523 void msi_dialog_check_messages( HANDLE handle
)
3527 /* in threads other than the UI thread, block */
3528 if( uiThreadId
!= GetCurrentThreadId() )
3531 WaitForSingleObject( handle
, INFINITE
);
3535 /* there's two choices for the UI thread */
3538 msi_process_pending_messages( NULL
);
3544 * block here until somebody creates a new dialog or
3545 * the handle we're waiting on becomes ready
3547 r
= MsgWaitForMultipleObjects( 1, &handle
, 0, INFINITE
, QS_ALLINPUT
);
3548 if( r
== WAIT_OBJECT_0
)
3553 UINT
msi_dialog_run_message_loop( msi_dialog
*dialog
)
3558 if( uiThreadId
!= GetCurrentThreadId() )
3559 return SendMessageW( hMsiHiddenWindow
, WM_MSI_DIALOG_CREATE
, 0, (LPARAM
) dialog
);
3561 /* create the dialog window, don't show it yet */
3562 style
= WS_OVERLAPPED
;
3563 if( dialog
->attributes
& msidbDialogAttributesVisible
)
3564 style
|= WS_VISIBLE
;
3566 hwnd
= CreateWindowW( szMsiDialogClass
, dialog
->name
, style
,
3567 CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
,
3568 NULL
, NULL
, NULL
, dialog
);
3571 ERR("Failed to create dialog %s\n", debugstr_w( dialog
->name
));
3572 return ERROR_FUNCTION_FAILED
;
3575 ShowWindow( hwnd
, SW_SHOW
);
3576 /* UpdateWindow( hwnd ); - and causes the transparent static controls not to paint */
3578 if( dialog
->attributes
& msidbDialogAttributesModal
)
3580 while( !dialog
->finished
)
3582 MsgWaitForMultipleObjects( 0, NULL
, 0, INFINITE
, QS_ALLINPUT
);
3583 msi_process_pending_messages( dialog
->hwnd
);
3587 return ERROR_IO_PENDING
;
3589 return ERROR_SUCCESS
;
3592 void msi_dialog_do_preview( msi_dialog
*dialog
)
3595 dialog
->attributes
|= msidbDialogAttributesVisible
;
3596 dialog
->attributes
&= ~msidbDialogAttributesModal
;
3597 msi_dialog_run_message_loop( dialog
);
3600 void msi_dialog_destroy( msi_dialog
*dialog
)
3602 if( uiThreadId
!= GetCurrentThreadId() )
3604 SendMessageW( hMsiHiddenWindow
, WM_MSI_DIALOG_DESTROY
, 0, (LPARAM
) dialog
);
3609 ShowWindow( dialog
->hwnd
, SW_HIDE
);
3612 DestroyWindow( dialog
->hwnd
);
3614 /* unsubscribe events */
3615 ControlEvent_CleanupDialogSubscriptions(dialog
->package
, dialog
->name
);
3617 /* destroy the list of controls */
3618 while( !list_empty( &dialog
->controls
) )
3622 t
= LIST_ENTRY( list_head( &dialog
->controls
),
3623 msi_control
, entry
);
3624 msi_destroy_control( t
);
3627 /* destroy the list of fonts */
3628 while( dialog
->font_list
)
3630 msi_font
*t
= dialog
->font_list
;
3631 dialog
->font_list
= t
->next
;
3632 DeleteObject( t
->hfont
);
3635 msi_free( dialog
->default_font
);
3637 msi_free( dialog
->control_default
);
3638 msi_free( dialog
->control_cancel
);
3639 msiobj_release( &dialog
->package
->hdr
);
3640 dialog
->package
= NULL
;
3644 BOOL
msi_dialog_register_class( void )
3648 ZeroMemory( &cls
, sizeof cls
);
3649 cls
.lpfnWndProc
= MSIDialog_WndProc
;
3650 cls
.hInstance
= NULL
;
3651 cls
.hIcon
= LoadIconW(0, (LPWSTR
)IDI_APPLICATION
);
3652 cls
.hCursor
= LoadCursorW(0, (LPWSTR
)IDC_ARROW
);
3653 cls
.hbrBackground
= (HBRUSH
)(COLOR_3DFACE
+ 1);
3654 cls
.lpszMenuName
= NULL
;
3655 cls
.lpszClassName
= szMsiDialogClass
;
3657 if( !RegisterClassW( &cls
) )
3660 cls
.lpfnWndProc
= MSIHiddenWindowProc
;
3661 cls
.lpszClassName
= szMsiHiddenWindow
;
3663 if( !RegisterClassW( &cls
) )
3666 uiThreadId
= GetCurrentThreadId();
3668 hMsiHiddenWindow
= CreateWindowW( szMsiHiddenWindow
, NULL
, WS_OVERLAPPED
,
3669 0, 0, 100, 100, NULL
, NULL
, NULL
, NULL
);
3670 if( !hMsiHiddenWindow
)
3676 void msi_dialog_unregister_class( void )
3678 DestroyWindow( hMsiHiddenWindow
);
3679 hMsiHiddenWindow
= NULL
;
3680 UnregisterClassW( szMsiDialogClass
, NULL
);
3681 UnregisterClassW( szMsiHiddenWindow
, NULL
);
3685 static UINT
error_dialog_handler(MSIPACKAGE
*package
, LPCWSTR event
,
3686 LPCWSTR argument
, msi_dialog
* dialog
)
3688 static const WCHAR end_dialog
[] = {'E','n','d','D','i','a','l','o','g',0};
3689 static const WCHAR error_abort
[] = {'E','r','r','o','r','A','b','o','r','t',0};
3690 static const WCHAR error_cancel
[] = {'E','r','r','o','r','C','a','n','c','e','l',0};
3691 static const WCHAR error_no
[] = {'E','r','r','o','r','N','o',0};
3692 static const WCHAR result_prop
[] = {
3693 'M','S','I','E','r','r','o','r','D','i','a','l','o','g','R','e','s','u','l','t',0
3696 if ( lstrcmpW( event
, end_dialog
) )
3697 return ERROR_SUCCESS
;
3699 if ( !lstrcmpW( argument
, error_abort
) || !lstrcmpW( argument
, error_cancel
) ||
3700 !lstrcmpW( argument
, error_no
) )
3702 MSI_SetPropertyW( package
, result_prop
, error_abort
);
3705 ControlEvent_CleanupSubscriptions(package
);
3706 msi_dialog_end_dialog( dialog
);
3708 return ERROR_SUCCESS
;
3711 static UINT
msi_error_dialog_set_error( MSIPACKAGE
*package
, LPWSTR error_dialog
, LPWSTR error
)
3715 static const WCHAR update
[] =
3716 {'U','P','D','A','T','E',' ','`','C','o','n','t','r','o','l','`',' ',
3717 'S','E','T',' ','`','T','e','x','t','`',' ','=',' ','\'','%','s','\'',' ',
3718 'W','H','E','R','E', ' ','`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',' ',
3719 'A','N','D',' ','`','C','o','n','t','r','o','l','`',' ','=',' ',
3720 '\'','E','r','r','o','r','T','e','x','t','\'',0};
3722 row
= MSI_QueryGetRecord( package
->db
, update
, error
, error_dialog
);
3724 return ERROR_FUNCTION_FAILED
;
3726 msiobj_release(&row
->hdr
);
3727 return ERROR_SUCCESS
;
3730 UINT
msi_spawn_error_dialog( MSIPACKAGE
*package
, LPWSTR error_dialog
, LPWSTR error
)
3733 WCHAR result
[MAX_PATH
];
3734 UINT r
= ERROR_SUCCESS
;
3735 DWORD size
= MAX_PATH
;
3738 static const WCHAR szUILevel
[] = {'U','I','L','e','v','e','l',0};
3739 static const WCHAR pn_prop
[] = {'P','r','o','d','u','c','t','N','a','m','e',0};
3740 static const WCHAR title_fmt
[] = {'%','s',' ','W','a','r','n','i','n','g',0};
3741 static const WCHAR error_abort
[] = {'E','r','r','o','r','A','b','o','r','t',0};
3742 static const WCHAR result_prop
[] = {
3743 'M','S','I','E','r','r','o','r','D','i','a','l','o','g','R','e','s','u','l','t',0
3746 if ( (msi_get_property_int(package
, szUILevel
, 0) & INSTALLUILEVEL_MASK
) == INSTALLUILEVEL_NONE
)
3747 return ERROR_SUCCESS
;
3749 if ( !error_dialog
)
3751 LPWSTR product_name
= msi_dup_property( package
, pn_prop
);
3752 WCHAR title
[MAX_PATH
];
3754 sprintfW( title
, title_fmt
, product_name
);
3755 res
= MessageBoxW( NULL
, error
, title
, MB_OKCANCEL
| MB_ICONWARNING
);
3757 msi_free( product_name
);
3760 return ERROR_SUCCESS
;
3762 return ERROR_FUNCTION_FAILED
;
3765 r
= msi_error_dialog_set_error( package
, error_dialog
, error
);
3766 if ( r
!= ERROR_SUCCESS
)
3769 dialog
= msi_dialog_create( package
, error_dialog
, package
->dialog
,
3770 error_dialog_handler
);
3772 return ERROR_FUNCTION_FAILED
;
3774 dialog
->finished
= FALSE
;
3775 r
= msi_dialog_run_message_loop( dialog
);
3776 if ( r
!= ERROR_SUCCESS
)
3779 r
= MSI_GetPropertyW( package
, result_prop
, result
, &size
);
3780 if ( r
!= ERROR_SUCCESS
)
3783 if ( !lstrcmpW( result
, error_abort
) )
3784 r
= ERROR_FUNCTION_FAILED
;
3787 msi_dialog_destroy( dialog
);