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
->update
= NULL
;
421 control
->property
= NULL
;
422 control
->value
= NULL
;
423 control
->hBitmap
= NULL
;
424 control
->hIcon
= NULL
;
425 control
->hDll
= NULL
;
426 control
->tabnext
= strdupW( MSI_RecordGetString( rec
, 11) );
427 control
->type
= strdupW( MSI_RecordGetString( rec
, 3 ) );
428 control
->progress_current
= 0;
429 control
->progress_max
= 100;
431 x
= MSI_RecordGetInteger( rec
, 4 );
432 y
= MSI_RecordGetInteger( rec
, 5 );
433 width
= MSI_RecordGetInteger( rec
, 6 );
434 height
= MSI_RecordGetInteger( rec
, 7 );
436 x
= msi_dialog_scale_unit( dialog
, x
);
437 y
= msi_dialog_scale_unit( dialog
, y
);
438 width
= msi_dialog_scale_unit( dialog
, width
);
439 height
= msi_dialog_scale_unit( dialog
, height
);
443 deformat_string( dialog
->package
, text
, &title_font
);
444 font
= msi_dialog_get_style( title_font
, &title
);
447 control
->hwnd
= CreateWindowExW( exstyle
, szCls
, title
, style
,
448 x
, y
, width
, height
, parent
, NULL
, NULL
, NULL
);
450 TRACE("Dialog %s control %s hwnd %p\n",
451 debugstr_w(dialog
->name
), debugstr_w(text
), control
->hwnd
);
453 msi_dialog_set_font( dialog
, control
->hwnd
,
454 font
? font
: dialog
->default_font
);
456 msi_free( title_font
);
462 static LPWSTR
msi_dialog_get_uitext( msi_dialog
*dialog
, LPCWSTR key
)
467 static const WCHAR query
[] = {
468 's','e','l','e','c','t',' ','*',' ',
469 'f','r','o','m',' ','`','U','I','T','e','x','t','`',' ',
470 'w','h','e','r','e',' ','`','K','e','y','`',' ','=',' ','\'','%','s','\'',0
473 rec
= MSI_QueryGetRecord( dialog
->package
->db
, query
, key
);
474 if (!rec
) return NULL
;
475 text
= strdupW( MSI_RecordGetString( rec
, 2 ) );
476 msiobj_release( &rec
->hdr
);
480 static MSIRECORD
*msi_get_binary_record( MSIDATABASE
*db
, LPCWSTR name
)
482 static const WCHAR query
[] = {
483 's','e','l','e','c','t',' ','*',' ',
484 'f','r','o','m',' ','B','i','n','a','r','y',' ',
485 'w','h','e','r','e',' ',
486 '`','N','a','m','e','`',' ','=',' ','\'','%','s','\'',0
489 return MSI_QueryGetRecord( db
, query
, name
);
492 static LPWSTR
msi_create_tmp_path(void)
496 static const WCHAR prefix
[] = { 'm','s','i',0 };
499 r
= GetTempPathW( MAX_PATH
, tmp
);
502 len
= lstrlenW( tmp
) + 20;
503 path
= msi_alloc( len
* sizeof (WCHAR
) );
506 r
= GetTempFileNameW( tmp
, prefix
, 0, path
);
517 static HANDLE
msi_load_image( MSIDATABASE
*db
, LPCWSTR name
, UINT type
,
518 UINT cx
, UINT cy
, UINT flags
)
520 MSIRECORD
*rec
= NULL
;
521 HANDLE himage
= NULL
;
525 TRACE("%p %s %u %u %08x\n", db
, debugstr_w(name
), cx
, cy
, flags
);
527 tmp
= msi_create_tmp_path();
531 rec
= msi_get_binary_record( db
, name
);
534 r
= MSI_RecordStreamToFile( rec
, 2, tmp
);
535 if( r
== ERROR_SUCCESS
)
537 himage
= LoadImageW( 0, tmp
, type
, cx
, cy
, flags
);
539 msiobj_release( &rec
->hdr
);
547 static HICON
msi_load_icon( MSIDATABASE
*db
, LPCWSTR text
, UINT attributes
)
549 DWORD cx
= 0, cy
= 0, flags
;
551 flags
= LR_LOADFROMFILE
| LR_DEFAULTSIZE
;
552 if( attributes
& msidbControlAttributesFixedSize
)
554 flags
&= ~LR_DEFAULTSIZE
;
555 if( attributes
& msidbControlAttributesIconSize16
)
560 if( attributes
& msidbControlAttributesIconSize32
)
565 /* msidbControlAttributesIconSize48 handled by above logic */
567 return msi_load_image( db
, text
, IMAGE_ICON
, cx
, cy
, flags
);
570 static void msi_dialog_update_controls( msi_dialog
*dialog
, LPCWSTR property
)
572 msi_control
*control
;
574 LIST_FOR_EACH_ENTRY( control
, &dialog
->controls
, msi_control
, entry
)
576 if ( !lstrcmpW( control
->property
, property
) && control
->update
)
577 control
->update( dialog
, control
);
581 /* called from the Control Event subscription code */
582 void msi_dialog_handle_event( msi_dialog
* dialog
, LPCWSTR control
,
583 LPCWSTR attribute
, MSIRECORD
*rec
)
586 LPCWSTR font_text
, text
= NULL
;
589 static const WCHAR empty
[] = {0};
591 ctrl
= msi_dialog_find_control( dialog
, control
);
594 if( !lstrcmpW(attribute
, szText
) )
596 font_text
= MSI_RecordGetString( rec
, 1 );
597 font
= msi_dialog_get_style( font_text
, &text
);
598 if (!text
) text
= empty
;
599 SetWindowTextW( ctrl
->hwnd
, text
);
601 msi_dialog_check_messages( NULL
);
603 else if( !lstrcmpW(attribute
, szProgress
) )
607 func
= MSI_RecordGetInteger( rec
, 1 );
608 val
= MSI_RecordGetInteger( rec
, 2 );
613 ctrl
->progress_max
= val
;
614 ctrl
->progress_current
= 0;
615 SendMessageW(ctrl
->hwnd
, PBM_SETRANGE
, 0, MAKELPARAM(0,100));
616 SendMessageW(ctrl
->hwnd
, PBM_SETPOS
, 0, 0);
618 case 1: /* FIXME: not sure what this is supposed to do */
621 ctrl
->progress_current
+= val
;
622 SendMessageW(ctrl
->hwnd
, PBM_SETPOS
, 100*(ctrl
->progress_current
/ctrl
->progress_max
), 0);
625 ERR("Unknown progress message %d\n", func
);
629 else if ( !lstrcmpW(attribute
, szProperty
) )
631 MSIFEATURE
*feature
= msi_seltree_get_selected_feature( ctrl
);
632 MSI_SetPropertyW( dialog
->package
, ctrl
->property
, feature
->Directory
);
634 else if ( !lstrcmpW(attribute
, szSelectionPath
) )
636 LPWSTR prop
= msi_dialog_dup_property( dialog
, ctrl
->property
, TRUE
);
639 path
= msi_dup_property( dialog
->package
, prop
);
640 SetWindowTextW( ctrl
->hwnd
, path
);
646 FIXME("Attribute %s not being set\n", debugstr_w(attribute
));
651 static void msi_dialog_map_events(msi_dialog
* dialog
, LPCWSTR control
)
653 static const WCHAR Query
[] = {
654 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
655 '`','E','v','e','n','t','M','a','p','p','i','n','g','`',' ',
656 'W','H','E','R','E',' ',
657 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',' ',
659 '`','C','o','n','t','r','o','l','_','`',' ','=',' ','\'','%','s','\'',0
662 LPCWSTR event
, attribute
;
664 row
= MSI_QueryGetRecord( dialog
->package
->db
, Query
, dialog
->name
, control
);
668 event
= MSI_RecordGetString( row
, 3 );
669 attribute
= MSI_RecordGetString( row
, 4 );
670 ControlEvent_SubscribeToEvent( dialog
->package
, dialog
, event
, control
, attribute
);
671 msiobj_release( &row
->hdr
);
674 /* everything except radio buttons */
675 static msi_control
*msi_dialog_add_control( msi_dialog
*dialog
,
676 MSIRECORD
*rec
, LPCWSTR szCls
, DWORD style
)
682 name
= MSI_RecordGetString( rec
, 2 );
683 attributes
= MSI_RecordGetInteger( rec
, 8 );
684 text
= MSI_RecordGetString( rec
, 10 );
685 if( attributes
& msidbControlAttributesVisible
)
687 if( ~attributes
& msidbControlAttributesEnabled
)
688 style
|= WS_DISABLED
;
689 if( attributes
& msidbControlAttributesSunken
)
690 exstyle
|= WS_EX_CLIENTEDGE
;
692 msi_dialog_map_events(dialog
, name
);
694 return msi_dialog_create_window( dialog
, rec
, exstyle
, szCls
, name
,
695 text
, style
, dialog
->hwnd
);
706 * we don't erase our own background,
707 * so we have to make sure that the parent window redraws first
709 static void msi_text_on_settext( HWND hWnd
)
714 hParent
= GetParent( hWnd
);
715 GetWindowRect( hWnd
, &rc
);
716 MapWindowPoints( NULL
, hParent
, (LPPOINT
) &rc
, 2 );
717 InvalidateRect( hParent
, &rc
, TRUE
);
720 static LRESULT WINAPI
721 MSIText_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
723 struct msi_text_info
*info
;
726 TRACE("%p %04x %08lx %08lx\n", hWnd
, msg
, wParam
, lParam
);
728 info
= GetPropW(hWnd
, szButtonData
);
730 if( msg
== WM_CTLCOLORSTATIC
&&
731 ( info
->attributes
& msidbControlAttributesTransparent
) )
733 SetBkMode( (HDC
)wParam
, TRANSPARENT
);
734 return (LRESULT
) GetStockObject(NULL_BRUSH
);
737 r
= CallWindowProcW(info
->oldproc
, hWnd
, msg
, wParam
, lParam
);
739 SetTextColor( (HDC
)wParam
, info
->font
->color
);
744 msi_text_on_settext( hWnd
);
748 RemovePropW( hWnd
, szButtonData
);
755 static UINT
msi_dialog_text_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
757 msi_control
*control
;
758 struct msi_text_info
*info
;
759 LPCWSTR text
, ptr
, prop
;
762 TRACE("%p %p\n", dialog
, rec
);
764 control
= msi_dialog_add_control( dialog
, rec
, szStatic
, SS_LEFT
| WS_GROUP
);
766 return ERROR_FUNCTION_FAILED
;
768 info
= msi_alloc( sizeof *info
);
770 return ERROR_SUCCESS
;
772 control
->attributes
= MSI_RecordGetInteger( rec
, 8 );
773 prop
= MSI_RecordGetString( rec
, 9 );
774 control
->property
= msi_dialog_dup_property( dialog
, prop
, FALSE
);
776 text
= MSI_RecordGetString( rec
, 10 );
777 font_name
= msi_dialog_get_style( text
, &ptr
);
778 info
->font
= ( font_name
) ? msi_dialog_find_font( dialog
, font_name
) : NULL
;
779 msi_free( font_name
);
781 info
->attributes
= MSI_RecordGetInteger( rec
, 8 );
782 if( info
->attributes
& msidbControlAttributesTransparent
)
783 SetWindowLongPtrW( control
->hwnd
, GWL_EXSTYLE
, WS_EX_TRANSPARENT
);
785 info
->oldproc
= (WNDPROC
) SetWindowLongPtrW( control
->hwnd
, GWLP_WNDPROC
,
786 (LONG_PTR
)MSIText_WndProc
);
787 SetPropW( control
->hwnd
, szButtonData
, info
);
789 ControlEvent_SubscribeToEvent( dialog
->package
, dialog
,
790 szSelectionPath
, control
->name
, szSelectionPath
);
792 return ERROR_SUCCESS
;
795 static UINT
msi_dialog_button_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
797 msi_control
*control
;
798 UINT attributes
, style
;
801 TRACE("%p %p\n", dialog
, rec
);
804 attributes
= MSI_RecordGetInteger( rec
, 8 );
805 if( attributes
& msidbControlAttributesIcon
)
808 control
= msi_dialog_add_control( dialog
, rec
, szButton
, style
);
810 return ERROR_FUNCTION_FAILED
;
812 control
->handler
= msi_dialog_button_handler
;
815 text
= msi_get_deformatted_field( dialog
->package
, rec
, 10 );
816 control
->hIcon
= msi_load_icon( dialog
->package
->db
, text
, attributes
);
817 if( attributes
& msidbControlAttributesIcon
)
818 SendMessageW( control
->hwnd
, BM_SETIMAGE
, IMAGE_ICON
, (LPARAM
) control
->hIcon
);
821 return ERROR_SUCCESS
;
824 static LPWSTR
msi_get_checkbox_value( msi_dialog
*dialog
, LPCWSTR prop
)
826 static const WCHAR query
[] = {
827 'S','E','L','E','C','T',' ','*',' ',
828 'F','R','O','M',' ','`','C','h','e','c','k','B','o','x','`',' ',
829 'W','H','E','R','E',' ',
830 '`','P','r','o','p','e','r','t','y','`',' ','=',' ',
833 MSIRECORD
*rec
= NULL
;
836 /* find if there is a value associated with the checkbox */
837 rec
= MSI_QueryGetRecord( dialog
->package
->db
, query
, prop
);
841 ret
= msi_get_deformatted_field( dialog
->package
, rec
, 2 );
847 msiobj_release( &rec
->hdr
);
851 ret
= msi_dup_property( dialog
->package
, prop
);
861 static UINT
msi_dialog_checkbox_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
863 msi_control
*control
;
866 TRACE("%p %p\n", dialog
, rec
);
868 control
= msi_dialog_add_control( dialog
, rec
, szButton
,
869 BS_CHECKBOX
| BS_MULTILINE
| WS_TABSTOP
);
870 control
->handler
= msi_dialog_checkbox_handler
;
871 control
->update
= msi_dialog_checkbox_sync_state
;
872 prop
= MSI_RecordGetString( rec
, 9 );
875 control
->property
= strdupW( prop
);
876 control
->value
= msi_get_checkbox_value( dialog
, prop
);
877 TRACE("control %s value %s\n", debugstr_w(control
->property
),
878 debugstr_w(control
->value
));
880 msi_dialog_checkbox_sync_state( dialog
, control
);
882 return ERROR_SUCCESS
;
885 static UINT
msi_dialog_line_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
889 DWORD style
, exstyle
= 0;
890 DWORD x
, y
, width
, height
;
891 msi_control
*control
;
893 TRACE("%p %p\n", dialog
, rec
);
895 style
= WS_CHILD
| SS_ETCHEDHORZ
| SS_SUNKEN
;
897 name
= MSI_RecordGetString( rec
, 2 );
898 attributes
= MSI_RecordGetInteger( rec
, 8 );
900 if( attributes
& msidbControlAttributesVisible
)
902 if( ~attributes
& msidbControlAttributesEnabled
)
903 style
|= WS_DISABLED
;
904 if( attributes
& msidbControlAttributesSunken
)
905 exstyle
|= WS_EX_CLIENTEDGE
;
907 msi_dialog_map_events(dialog
, name
);
909 control
= msi_alloc( sizeof(*control
) + strlenW(name
) * sizeof(WCHAR
) );
911 return ERROR_OUTOFMEMORY
;
913 strcpyW( control
->name
, name
);
914 list_add_head( &dialog
->controls
, &control
->entry
);
915 control
->handler
= NULL
;
916 control
->property
= NULL
;
917 control
->value
= NULL
;
918 control
->hBitmap
= NULL
;
919 control
->hIcon
= NULL
;
920 control
->hDll
= NULL
;
921 control
->tabnext
= strdupW( MSI_RecordGetString( rec
, 11) );
922 control
->type
= strdupW( MSI_RecordGetString( rec
, 3 ) );
923 control
->progress_current
= 0;
924 control
->progress_max
= 100;
926 x
= MSI_RecordGetInteger( rec
, 4 );
927 y
= MSI_RecordGetInteger( rec
, 5 );
928 width
= MSI_RecordGetInteger( rec
, 6 );
930 x
= msi_dialog_scale_unit( dialog
, x
);
931 y
= msi_dialog_scale_unit( dialog
, y
);
932 width
= msi_dialog_scale_unit( dialog
, width
);
933 height
= 2; /* line is exactly 2 units in height */
935 control
->hwnd
= CreateWindowExW( exstyle
, szStatic
, NULL
, style
,
936 x
, y
, width
, height
, dialog
->hwnd
, NULL
, NULL
, NULL
);
938 TRACE("Dialog %s control %s hwnd %p\n",
939 debugstr_w(dialog
->name
), debugstr_w(name
), control
->hwnd
);
941 return ERROR_SUCCESS
;
944 /******************** Scroll Text ********************************************/
946 struct msi_scrolltext_info
949 msi_control
*control
;
953 static LRESULT WINAPI
954 MSIScrollText_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
956 struct msi_scrolltext_info
*info
;
959 TRACE("%p %04x %08lx %08lx\n", hWnd
, msg
, wParam
, lParam
);
961 info
= GetPropW( hWnd
, szButtonData
);
963 r
= CallWindowProcW( info
->oldproc
, hWnd
, msg
, wParam
, lParam
);
969 RemovePropW( hWnd
, szButtonData
);
972 /* native MSI sets a wait cursor here */
973 msi_dialog_button_handler( info
->dialog
, info
->control
, BN_CLICKED
);
979 struct msi_streamin_info
986 static DWORD CALLBACK
987 msi_richedit_stream_in( DWORD_PTR arg
, LPBYTE buffer
, LONG count
, LONG
*pcb
)
989 struct msi_streamin_info
*info
= (struct msi_streamin_info
*) arg
;
991 if( (count
+ info
->offset
) > info
->length
)
992 count
= info
->length
- info
->offset
;
993 memcpy( buffer
, &info
->string
[ info
->offset
], count
);
995 info
->offset
+= count
;
997 TRACE("%d/%d\n", info
->offset
, info
->length
);
1002 static void msi_scrolltext_add_text( msi_control
*control
, LPCWSTR text
)
1004 struct msi_streamin_info info
;
1007 info
.string
= strdupWtoA( text
);
1009 info
.length
= lstrlenA( info
.string
) + 1;
1011 es
.dwCookie
= (DWORD_PTR
) &info
;
1013 es
.pfnCallback
= msi_richedit_stream_in
;
1015 SendMessageW( control
->hwnd
, EM_STREAMIN
, SF_RTF
, (LPARAM
) &es
);
1017 msi_free( info
.string
);
1020 static UINT
msi_dialog_scrolltext_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1022 static const WCHAR szRichEdit20W
[] = {
1023 'R','i','c','h','E','d','i','t','2','0','W',0
1025 struct msi_scrolltext_info
*info
;
1026 msi_control
*control
;
1031 info
= msi_alloc( sizeof *info
);
1033 return ERROR_FUNCTION_FAILED
;
1035 hRichedit
= LoadLibraryA("riched20");
1037 style
= WS_BORDER
| ES_MULTILINE
| WS_VSCROLL
|
1038 ES_READONLY
| ES_AUTOVSCROLL
| WS_TABSTOP
;
1039 control
= msi_dialog_add_control( dialog
, rec
, szRichEdit20W
, style
);
1042 FreeLibrary( hRichedit
);
1044 return ERROR_FUNCTION_FAILED
;
1047 control
->hDll
= hRichedit
;
1049 info
->dialog
= dialog
;
1050 info
->control
= control
;
1052 /* subclass the static control */
1053 info
->oldproc
= (WNDPROC
) SetWindowLongPtrW( control
->hwnd
, GWLP_WNDPROC
,
1054 (LONG_PTR
)MSIScrollText_WndProc
);
1055 SetPropW( control
->hwnd
, szButtonData
, info
);
1057 /* add the text into the richedit */
1058 text
= MSI_RecordGetString( rec
, 10 );
1060 msi_scrolltext_add_text( control
, text
);
1062 return ERROR_SUCCESS
;
1065 static HBITMAP
msi_load_picture( MSIDATABASE
*db
, LPCWSTR name
,
1066 INT cx
, INT cy
, DWORD flags
)
1068 HBITMAP hOleBitmap
= 0, hBitmap
= 0, hOldSrcBitmap
, hOldDestBitmap
;
1069 MSIRECORD
*rec
= NULL
;
1070 IStream
*stm
= NULL
;
1071 IPicture
*pic
= NULL
;
1076 rec
= msi_get_binary_record( db
, name
);
1080 r
= MSI_RecordGetIStream( rec
, 2, &stm
);
1081 msiobj_release( &rec
->hdr
);
1082 if( r
!= ERROR_SUCCESS
)
1085 r
= OleLoadPicture( stm
, 0, TRUE
, &IID_IPicture
, (LPVOID
*) &pic
);
1086 IStream_Release( stm
);
1089 ERR("failed to load picture\n");
1093 r
= IPicture_get_Handle( pic
, (OLE_HANDLE
*) &hOleBitmap
);
1096 ERR("failed to get bitmap handle\n");
1100 /* make the bitmap the desired size */
1101 r
= GetObjectW( hOleBitmap
, sizeof bm
, &bm
);
1102 if (r
!= sizeof bm
)
1104 ERR("failed to get bitmap size\n");
1108 if (flags
& LR_DEFAULTSIZE
)
1114 srcdc
= CreateCompatibleDC( NULL
);
1115 hOldSrcBitmap
= SelectObject( srcdc
, hOleBitmap
);
1116 destdc
= CreateCompatibleDC( NULL
);
1117 hBitmap
= CreateCompatibleBitmap( srcdc
, cx
, cy
);
1118 hOldDestBitmap
= SelectObject( destdc
, hBitmap
);
1119 StretchBlt( destdc
, 0, 0, cx
, cy
,
1120 srcdc
, 0, 0, bm
.bmWidth
, bm
.bmHeight
, SRCCOPY
);
1121 SelectObject( srcdc
, hOldSrcBitmap
);
1122 SelectObject( destdc
, hOldDestBitmap
);
1128 IPicture_Release( pic
);
1132 static UINT
msi_dialog_bitmap_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1134 UINT cx
, cy
, flags
, style
, attributes
;
1135 msi_control
*control
;
1138 flags
= LR_LOADFROMFILE
;
1139 style
= SS_BITMAP
| SS_LEFT
| WS_GROUP
;
1141 attributes
= MSI_RecordGetInteger( rec
, 8 );
1142 if( attributes
& msidbControlAttributesFixedSize
)
1144 flags
|= LR_DEFAULTSIZE
;
1145 style
|= SS_CENTERIMAGE
;
1148 control
= msi_dialog_add_control( dialog
, rec
, szStatic
, style
);
1149 cx
= MSI_RecordGetInteger( rec
, 6 );
1150 cy
= MSI_RecordGetInteger( rec
, 7 );
1151 cx
= msi_dialog_scale_unit( dialog
, cx
);
1152 cy
= msi_dialog_scale_unit( dialog
, cy
);
1154 text
= msi_get_deformatted_field( dialog
->package
, rec
, 10 );
1155 control
->hBitmap
= msi_load_picture( dialog
->package
->db
, text
, cx
, cy
, flags
);
1156 if( control
->hBitmap
)
1157 SendMessageW( control
->hwnd
, STM_SETIMAGE
,
1158 IMAGE_BITMAP
, (LPARAM
) control
->hBitmap
);
1160 ERR("Failed to load bitmap %s\n", debugstr_w(text
));
1164 return ERROR_SUCCESS
;
1167 static UINT
msi_dialog_icon_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1169 msi_control
*control
;
1175 control
= msi_dialog_add_control( dialog
, rec
, szStatic
,
1176 SS_ICON
| SS_CENTERIMAGE
| WS_GROUP
);
1178 attributes
= MSI_RecordGetInteger( rec
, 8 );
1179 text
= msi_get_deformatted_field( dialog
->package
, rec
, 10 );
1180 control
->hIcon
= msi_load_icon( dialog
->package
->db
, text
, attributes
);
1181 if( control
->hIcon
)
1182 SendMessageW( control
->hwnd
, STM_SETICON
, (WPARAM
) control
->hIcon
, 0 );
1184 ERR("Failed to load bitmap %s\n", debugstr_w(text
));
1186 return ERROR_SUCCESS
;
1189 static UINT
msi_dialog_combo_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1191 static const WCHAR szCombo
[] = { 'C','O','M','B','O','B','O','X',0 };
1192 DWORD attributes
, style
;
1194 style
= CBS_AUTOHSCROLL
| WS_TABSTOP
| WS_GROUP
| WS_CHILD
;
1195 attributes
= MSI_RecordGetInteger( rec
, 8 );
1196 if ( ~attributes
& msidbControlAttributesSorted
)
1198 if ( attributes
& msidbControlAttributesComboList
)
1199 style
|= CBS_DROPDOWNLIST
;
1201 style
|= CBS_DROPDOWN
;
1203 msi_dialog_add_control( dialog
, rec
, szCombo
, style
);
1204 return ERROR_SUCCESS
;
1207 /* length of 2^32 + 1 */
1208 #define MAX_NUM_DIGITS 11
1210 static UINT
msi_dialog_edit_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1212 msi_control
*control
;
1214 LPWSTR val
, begin
, end
;
1215 WCHAR num
[MAX_NUM_DIGITS
];
1218 control
= msi_dialog_add_control( dialog
, rec
, szEdit
,
1219 WS_BORDER
| WS_TABSTOP
| ES_AUTOHSCROLL
);
1220 control
->handler
= msi_dialog_edit_handler
;
1222 text
= MSI_RecordGetString( rec
, 10 );
1225 begin
= strchrW( text
, '{' );
1226 end
= strchrW( text
, '}' );
1228 if ( begin
&& end
&& end
> begin
&&
1229 begin
[0] >= '0' && begin
[0] <= '9' &&
1230 end
- begin
< MAX_NUM_DIGITS
)
1232 lstrcpynW( num
, begin
+ 1, end
- begin
);
1233 limit
= atolW( num
);
1235 SendMessageW( control
->hwnd
, EM_SETLIMITTEXT
, limit
, 0 );
1239 prop
= MSI_RecordGetString( rec
, 9 );
1241 control
->property
= strdupW( prop
);
1243 val
= msi_dup_property( dialog
->package
, control
->property
);
1244 SetWindowTextW( control
->hwnd
, val
);
1246 return ERROR_SUCCESS
;
1249 /******************** Masked Edit ********************************************/
1251 #define MASK_MAX_GROUPS 20
1253 struct msi_mask_group
1261 struct msi_maskedit_info
1269 struct msi_mask_group group
[MASK_MAX_GROUPS
];
1272 static BOOL
msi_mask_editable( WCHAR type
)
1287 static void msi_mask_control_change( struct msi_maskedit_info
*info
)
1292 val
= msi_alloc( (info
->num_chars
+1)*sizeof(WCHAR
) );
1293 for( i
=0, n
=0; i
<info
->num_groups
; i
++ )
1295 if( (info
->group
[i
].len
+ n
) > info
->num_chars
)
1297 ERR("can't fit control %d text into template\n",i
);
1300 if (!msi_mask_editable(info
->group
[i
].type
))
1302 for(r
=0; r
<info
->group
[i
].len
; r
++)
1303 val
[n
+r
] = info
->group
[i
].type
;
1308 r
= GetWindowTextW( info
->group
[i
].hwnd
, &val
[n
], info
->group
[i
].len
+1 );
1309 if( r
!= info
->group
[i
].len
)
1315 TRACE("%d/%d controls were good\n", i
, info
->num_groups
);
1317 if( i
== info
->num_groups
)
1319 TRACE("Set property %s to %s\n",
1320 debugstr_w(info
->prop
), debugstr_w(val
) );
1321 CharUpperBuffW( val
, info
->num_chars
);
1322 MSI_SetPropertyW( info
->dialog
->package
, info
->prop
, val
);
1323 msi_dialog_evaluate_control_conditions( info
->dialog
);
1328 /* now move to the next control if necessary */
1329 static VOID
msi_mask_next_control( struct msi_maskedit_info
*info
, HWND hWnd
)
1334 for( i
=0; i
<info
->num_groups
; i
++ )
1335 if( info
->group
[i
].hwnd
== hWnd
)
1338 /* don't move from the last control */
1339 if( i
>= (info
->num_groups
-1) )
1342 len
= SendMessageW( hWnd
, WM_GETTEXTLENGTH
, 0, 0 );
1343 if( len
< info
->group
[i
].len
)
1346 hWndNext
= GetNextDlgTabItem( GetParent( hWnd
), hWnd
, FALSE
);
1347 SetFocus( hWndNext
);
1350 static LRESULT WINAPI
1351 MSIMaskedEdit_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1353 struct msi_maskedit_info
*info
;
1356 TRACE("%p %04x %08lx %08lx\n", hWnd
, msg
, wParam
, lParam
);
1358 info
= GetPropW(hWnd
, szButtonData
);
1360 r
= CallWindowProcW(info
->oldproc
, hWnd
, msg
, wParam
, lParam
);
1365 if (HIWORD(wParam
) == EN_CHANGE
)
1367 msi_mask_control_change( info
);
1368 msi_mask_next_control( info
, (HWND
) lParam
);
1372 msi_free( info
->prop
);
1374 RemovePropW( hWnd
, szButtonData
);
1381 /* fish the various bits of the property out and put them in the control */
1383 msi_maskedit_set_text( struct msi_maskedit_info
*info
, LPCWSTR text
)
1389 for( i
= 0; i
< info
->num_groups
; i
++ )
1391 if( info
->group
[i
].len
< strlenW( p
) )
1393 LPWSTR chunk
= strdupW( p
);
1394 chunk
[ info
->group
[i
].len
] = 0;
1395 SetWindowTextW( info
->group
[i
].hwnd
, chunk
);
1400 SetWindowTextW( info
->group
[i
].hwnd
, p
);
1403 p
+= info
->group
[i
].len
;
1407 static struct msi_maskedit_info
* msi_dialog_parse_groups( LPCWSTR mask
)
1409 struct msi_maskedit_info
* info
= NULL
;
1410 int i
= 0, n
= 0, total
= 0;
1413 TRACE("masked control, template %s\n", debugstr_w(mask
));
1418 info
= msi_alloc_zero( sizeof *info
);
1422 p
= strchrW(mask
, '<');
1428 for( i
=0; i
<MASK_MAX_GROUPS
; i
++ )
1430 /* stop at the end of the string */
1431 if( p
[0] == 0 || p
[0] == '>' )
1434 /* count the number of the same identifier */
1435 for( n
=0; p
[n
] == p
[0]; n
++ )
1437 info
->group
[i
].ofs
= total
;
1438 info
->group
[i
].type
= p
[0];
1442 total
++; /* an extra not part of the group */
1444 info
->group
[i
].len
= n
;
1449 TRACE("%d characters in %d groups\n", total
, i
);
1450 if( i
== MASK_MAX_GROUPS
)
1451 ERR("too many groups in PIDTemplate %s\n", debugstr_w(mask
));
1453 info
->num_chars
= total
;
1454 info
->num_groups
= i
;
1460 msi_maskedit_create_children( struct msi_maskedit_info
*info
, LPCWSTR font
)
1462 DWORD width
, height
, style
, wx
, ww
;
1467 style
= WS_CHILD
| WS_BORDER
| WS_VISIBLE
| WS_TABSTOP
| ES_AUTOHSCROLL
;
1469 GetClientRect( info
->hwnd
, &rect
);
1471 width
= rect
.right
- rect
.left
;
1472 height
= rect
.bottom
- rect
.top
;
1474 for( i
= 0; i
< info
->num_groups
; i
++ )
1476 if (!msi_mask_editable( info
->group
[i
].type
))
1478 wx
= (info
->group
[i
].ofs
* width
) / info
->num_chars
;
1479 ww
= (info
->group
[i
].len
* width
) / info
->num_chars
;
1481 hwnd
= CreateWindowW( szEdit
, NULL
, style
, wx
, 0, ww
, height
,
1482 info
->hwnd
, NULL
, NULL
, NULL
);
1485 ERR("failed to create mask edit sub window\n");
1489 SendMessageW( hwnd
, EM_LIMITTEXT
, info
->group
[i
].len
, 0 );
1491 msi_dialog_set_font( info
->dialog
, hwnd
,
1492 font
?font
:info
->dialog
->default_font
);
1493 info
->group
[i
].hwnd
= hwnd
;
1498 * office 2003 uses "73931<````=````=````=````=`````>@@@@@"
1499 * delphi 7 uses "<????-??????-??????-????>" and "<???-???>"
1500 * filemaker pro 7 uses "<^^^^=^^^^=^^^^=^^^^=^^^^=^^^^=^^^^^>"
1502 static UINT
msi_dialog_maskedit_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1504 LPWSTR font_mask
, val
= NULL
, font
;
1505 struct msi_maskedit_info
*info
= NULL
;
1506 UINT ret
= ERROR_SUCCESS
;
1507 msi_control
*control
;
1512 font_mask
= msi_get_deformatted_field( dialog
->package
, rec
, 10 );
1513 font
= msi_dialog_get_style( font_mask
, &mask
);
1516 ERR("mask template is empty\n");
1520 info
= msi_dialog_parse_groups( mask
);
1523 ERR("template %s is invalid\n", debugstr_w(mask
));
1527 info
->dialog
= dialog
;
1529 control
= msi_dialog_add_control( dialog
, rec
, szStatic
,
1530 SS_OWNERDRAW
| WS_GROUP
| WS_VISIBLE
);
1533 ERR("Failed to create maskedit container\n");
1534 ret
= ERROR_FUNCTION_FAILED
;
1537 SetWindowLongPtrW( control
->hwnd
, GWL_EXSTYLE
, WS_EX_CONTROLPARENT
);
1539 info
->hwnd
= control
->hwnd
;
1541 /* subclass the static control */
1542 info
->oldproc
= (WNDPROC
) SetWindowLongPtrW( info
->hwnd
, GWLP_WNDPROC
,
1543 (LONG_PTR
)MSIMaskedEdit_WndProc
);
1544 SetPropW( control
->hwnd
, szButtonData
, info
);
1546 prop
= MSI_RecordGetString( rec
, 9 );
1548 info
->prop
= strdupW( prop
);
1550 msi_maskedit_create_children( info
, font
);
1554 val
= msi_dup_property( dialog
->package
, prop
);
1557 msi_maskedit_set_text( info
, val
);
1563 if( ret
!= ERROR_SUCCESS
)
1565 msi_free( font_mask
);
1570 /******************** Progress Bar *****************************************/
1572 static UINT
msi_dialog_progress_bar( msi_dialog
*dialog
, MSIRECORD
*rec
)
1574 msi_dialog_add_control( dialog
, rec
, PROGRESS_CLASSW
, WS_VISIBLE
);
1575 return ERROR_SUCCESS
;
1578 /******************** Path Edit ********************************************/
1580 struct msi_pathedit_info
1583 msi_control
*control
;
1587 static LPWSTR
msi_get_window_text( HWND hwnd
)
1593 buf
= msi_alloc( sz
*sizeof(WCHAR
) );
1596 r
= GetWindowTextW( hwnd
, buf
, sz
);
1600 buf
= msi_realloc( buf
, sz
*sizeof(WCHAR
) );
1606 static void msi_dialog_update_pathedit( msi_dialog
*dialog
, msi_control
*control
)
1611 if (!control
&& !(control
= msi_dialog_find_control_by_type( dialog
, szPathEdit
)))
1614 indirect
= control
->attributes
& msidbControlAttributesIndirect
;
1615 prop
= msi_dialog_dup_property( dialog
, control
->property
, indirect
);
1616 path
= msi_dialog_dup_property( dialog
, prop
, TRUE
);
1618 SetWindowTextW( control
->hwnd
, path
);
1619 SendMessageW( control
->hwnd
, EM_SETSEL
, 0, -1 );
1625 /* FIXME: test when this should fail */
1626 static BOOL
msi_dialog_verify_path( LPWSTR path
)
1628 if ( !lstrlenW( path
) )
1631 if ( PathIsRelativeW( path
) )
1637 /* returns TRUE if the path is valid, FALSE otherwise */
1638 static BOOL
msi_dialog_onkillfocus( msi_dialog
*dialog
, msi_control
*control
)
1644 indirect
= control
->attributes
& msidbControlAttributesIndirect
;
1645 prop
= msi_dialog_dup_property( dialog
, control
->property
, indirect
);
1647 buf
= msi_get_window_text( control
->hwnd
);
1649 if ( !msi_dialog_verify_path( buf
) )
1651 /* FIXME: display an error message box */
1652 ERR("Invalid path %s\n", debugstr_w( buf
));
1654 SetFocus( control
->hwnd
);
1659 MSI_SetPropertyW( dialog
->package
, prop
, buf
);
1662 msi_dialog_update_pathedit( dialog
, control
);
1664 TRACE("edit %s contents changed, set %s\n", debugstr_w(control
->name
),
1673 static LRESULT WINAPI
MSIPathEdit_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1675 struct msi_pathedit_info
*info
= GetPropW(hWnd
, szButtonData
);
1678 TRACE("%p %04x %08lx %08lx\n", hWnd
, msg
, wParam
, lParam
);
1680 if ( msg
== WM_KILLFOCUS
)
1682 /* if the path is invalid, don't handle this message */
1683 if ( !msi_dialog_onkillfocus( info
->dialog
, info
->control
) )
1687 r
= CallWindowProcW(info
->oldproc
, hWnd
, msg
, wParam
, lParam
);
1689 if ( msg
== WM_NCDESTROY
)
1692 RemovePropW( hWnd
, szButtonData
);
1698 static UINT
msi_dialog_pathedit_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1700 struct msi_pathedit_info
*info
;
1701 msi_control
*control
;
1704 info
= msi_alloc( sizeof *info
);
1706 return ERROR_FUNCTION_FAILED
;
1708 control
= msi_dialog_add_control( dialog
, rec
, szEdit
,
1709 WS_BORDER
| WS_TABSTOP
);
1710 control
->attributes
= MSI_RecordGetInteger( rec
, 8 );
1711 prop
= MSI_RecordGetString( rec
, 9 );
1712 control
->property
= msi_dialog_dup_property( dialog
, prop
, FALSE
);
1714 info
->dialog
= dialog
;
1715 info
->control
= control
;
1716 info
->oldproc
= (WNDPROC
) SetWindowLongPtrW( control
->hwnd
, GWLP_WNDPROC
,
1717 (LONG_PTR
)MSIPathEdit_WndProc
);
1718 SetPropW( control
->hwnd
, szButtonData
, info
);
1720 msi_dialog_update_pathedit( dialog
, control
);
1722 return ERROR_SUCCESS
;
1725 /* radio buttons are a bit different from normal controls */
1726 static UINT
msi_dialog_create_radiobutton( MSIRECORD
*rec
, LPVOID param
)
1728 radio_button_group_descr
*group
= (radio_button_group_descr
*)param
;
1729 msi_dialog
*dialog
= group
->dialog
;
1730 msi_control
*control
;
1731 LPCWSTR prop
, text
, name
;
1732 DWORD style
, attributes
= group
->attributes
;
1734 style
= WS_CHILD
| BS_AUTORADIOBUTTON
| BS_MULTILINE
| WS_TABSTOP
;
1735 name
= MSI_RecordGetString( rec
, 3 );
1736 text
= MSI_RecordGetString( rec
, 8 );
1737 if( attributes
& msidbControlAttributesVisible
)
1738 style
|= WS_VISIBLE
;
1739 if( ~attributes
& msidbControlAttributesEnabled
)
1740 style
|= WS_DISABLED
;
1742 control
= msi_dialog_create_window( dialog
, rec
, 0, szButton
, name
, text
,
1743 style
, group
->parent
->hwnd
);
1745 return ERROR_FUNCTION_FAILED
;
1746 control
->handler
= msi_dialog_radiogroup_handler
;
1748 if (!lstrcmpW(control
->name
, group
->propval
))
1749 SendMessageW(control
->hwnd
, BM_SETCHECK
, BST_CHECKED
, 0);
1751 prop
= MSI_RecordGetString( rec
, 1 );
1753 control
->property
= strdupW( prop
);
1755 return ERROR_SUCCESS
;
1758 static UINT
msi_dialog_radiogroup_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1760 static const WCHAR query
[] = {
1761 'S','E','L','E','C','T',' ','*',' ',
1762 'F','R','O','M',' ','R','a','d','i','o','B','u','t','t','o','n',' ',
1763 'W','H','E','R','E',' ',
1764 '`','P','r','o','p','e','r','t','y','`',' ','=',' ','\'','%','s','\'',0};
1767 msi_control
*control
;
1768 MSIQUERY
*view
= NULL
;
1769 radio_button_group_descr group
;
1770 MSIPACKAGE
*package
= dialog
->package
;
1772 DWORD attr
, style
= WS_GROUP
;
1774 prop
= MSI_RecordGetString( rec
, 9 );
1776 TRACE("%p %p %s\n", dialog
, rec
, debugstr_w( prop
));
1778 attr
= MSI_RecordGetInteger( rec
, 8 );
1779 if (attr
& msidbControlAttributesHasBorder
)
1780 style
|= BS_GROUPBOX
;
1782 style
|= BS_OWNERDRAW
;
1784 /* Create parent group box to hold radio buttons */
1785 control
= msi_dialog_add_control( dialog
, rec
, szButton
, style
);
1787 return ERROR_FUNCTION_FAILED
;
1789 oldproc
= (WNDPROC
) SetWindowLongPtrW( control
->hwnd
, GWLP_WNDPROC
,
1790 (LONG_PTR
)MSIRadioGroup_WndProc
);
1791 SetPropW(control
->hwnd
, szButtonData
, oldproc
);
1792 SetWindowLongPtrW( control
->hwnd
, GWL_EXSTYLE
, WS_EX_CONTROLPARENT
);
1795 control
->property
= strdupW( prop
);
1797 /* query the Radio Button table for all control in this group */
1798 r
= MSI_OpenQuery( package
->db
, &view
, query
, prop
);
1799 if( r
!= ERROR_SUCCESS
)
1801 ERR("query failed for dialog %s radio group %s\n",
1802 debugstr_w(dialog
->name
), debugstr_w(prop
));
1803 return ERROR_INVALID_PARAMETER
;
1806 group
.dialog
= dialog
;
1807 group
.parent
= control
;
1808 group
.attributes
= MSI_RecordGetInteger( rec
, 8 );
1809 group
.propval
= msi_dup_property( dialog
->package
, control
->property
);
1811 r
= MSI_IterateRecords( view
, 0, msi_dialog_create_radiobutton
, &group
);
1812 msiobj_release( &view
->hdr
);
1813 msi_free( group
.propval
);
1818 /******************** Selection Tree ***************************************/
1820 struct msi_selection_tree_info
1829 msi_seltree_sync_item_state( HWND hwnd
, MSIFEATURE
*feature
, HTREEITEM hItem
)
1832 DWORD index
= feature
->Action
;
1834 TRACE("Feature %s -> %d %d %d\n", debugstr_w(feature
->Title
),
1835 feature
->Installed
, feature
->Action
, feature
->ActionRequest
);
1837 if (index
== INSTALLSTATE_UNKNOWN
)
1838 index
= INSTALLSTATE_ABSENT
;
1840 tvi
.mask
= TVIF_STATE
;
1842 tvi
.state
= INDEXTOSTATEIMAGEMASK( index
);
1843 tvi
.stateMask
= TVIS_STATEIMAGEMASK
;
1845 SendMessageW( hwnd
, TVM_SETITEMW
, 0, (LPARAM
) &tvi
);
1849 msi_seltree_popup_menu( HWND hwnd
, INT x
, INT y
)
1854 /* create a menu to display */
1855 hMenu
= CreatePopupMenu();
1857 /* FIXME: load strings from resources */
1858 AppendMenuA( hMenu
, MF_ENABLED
, INSTALLSTATE_LOCAL
, "Install feature locally");
1859 AppendMenuA( hMenu
, MF_GRAYED
, 0x1000, "Install entire feature");
1860 AppendMenuA( hMenu
, MF_ENABLED
, INSTALLSTATE_ADVERTISED
, "Install on demand");
1861 AppendMenuA( hMenu
, MF_ENABLED
, INSTALLSTATE_ABSENT
, "Don't install");
1862 r
= TrackPopupMenu( hMenu
, TPM_LEFTALIGN
| TPM_TOPALIGN
| TPM_RETURNCMD
,
1863 x
, y
, 0, hwnd
, NULL
);
1864 DestroyMenu( hMenu
);
1869 msi_seltree_feature_from_item( HWND hwnd
, HTREEITEM hItem
)
1873 /* get the feature from the item */
1874 memset( &tvi
, 0, sizeof tvi
);
1876 tvi
.mask
= TVIF_PARAM
| TVIF_HANDLE
;
1877 SendMessageW( hwnd
, TVM_GETITEMW
, 0, (LPARAM
) &tvi
);
1879 return (MSIFEATURE
*) tvi
.lParam
;
1883 msi_seltree_menu( HWND hwnd
, HTREEITEM hItem
)
1885 struct msi_selection_tree_info
*info
;
1886 MSIFEATURE
*feature
;
1887 MSIPACKAGE
*package
;
1895 info
= GetPropW(hwnd
, szButtonData
);
1896 package
= info
->dialog
->package
;
1898 feature
= msi_seltree_feature_from_item( hwnd
, hItem
);
1901 ERR("item %p feature was NULL\n", hItem
);
1905 /* get the item's rectangle to put the menu just below it */
1907 SendMessageW( hwnd
, TVM_GETITEMRECT
, 0, (LPARAM
) &u
.rc
);
1908 MapWindowPoints( hwnd
, NULL
, u
.pt
, 2 );
1910 r
= msi_seltree_popup_menu( hwnd
, u
.rc
.left
, u
.rc
.top
);
1914 case INSTALLSTATE_LOCAL
:
1915 case INSTALLSTATE_ADVERTISED
:
1916 case INSTALLSTATE_ABSENT
:
1917 msi_feature_set_state(package
, feature
, r
);
1920 FIXME("select feature and all children\n");
1924 msi_seltree_sync_item_state( hwnd
, feature
, hItem
);
1925 ACTION_UpdateComponentStates( package
, feature
->Feature
);
1930 static MSIFEATURE
*msi_seltree_get_selected_feature( msi_control
*control
)
1932 struct msi_selection_tree_info
*info
= GetPropW(control
->hwnd
, szButtonData
);
1933 return msi_seltree_feature_from_item( control
->hwnd
, info
->selected
);
1936 static LRESULT WINAPI
1937 MSISelectionTree_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1939 struct msi_selection_tree_info
*info
;
1940 TVHITTESTINFO tvhti
;
1943 TRACE("%p %04x %08lx %08lx\n", hWnd
, msg
, wParam
, lParam
);
1945 info
= GetPropW(hWnd
, szButtonData
);
1949 case WM_LBUTTONDOWN
:
1950 tvhti
.pt
.x
= (short)LOWORD( lParam
);
1951 tvhti
.pt
.y
= (short)HIWORD( lParam
);
1954 r
= CallWindowProcW(info
->oldproc
, hWnd
, TVM_HITTEST
, 0, (LPARAM
) &tvhti
);
1955 if (tvhti
.flags
& TVHT_ONITEMSTATEICON
)
1956 return msi_seltree_menu( hWnd
, tvhti
.hItem
);
1960 r
= CallWindowProcW(info
->oldproc
, hWnd
, msg
, wParam
, lParam
);
1966 RemovePropW( hWnd
, szButtonData
);
1973 msi_seltree_add_child_features( MSIPACKAGE
*package
, HWND hwnd
,
1974 LPCWSTR parent
, HTREEITEM hParent
)
1976 struct msi_selection_tree_info
*info
= GetPropW( hwnd
, szButtonData
);
1977 MSIFEATURE
*feature
;
1978 TVINSERTSTRUCTW tvis
;
1979 HTREEITEM hitem
, hfirst
= NULL
;
1981 LIST_FOR_EACH_ENTRY( feature
, &package
->features
, MSIFEATURE
, entry
)
1983 if ( lstrcmpW( parent
, feature
->Feature_Parent
) )
1986 if ( !feature
->Title
)
1989 if ( !feature
->Display
)
1992 memset( &tvis
, 0, sizeof tvis
);
1993 tvis
.hParent
= hParent
;
1994 tvis
.hInsertAfter
= TVI_LAST
;
1995 tvis
.u
.item
.mask
= TVIF_TEXT
| TVIF_PARAM
;
1996 tvis
.u
.item
.pszText
= feature
->Title
;
1997 tvis
.u
.item
.lParam
= (LPARAM
) feature
;
1999 hitem
= (HTREEITEM
) SendMessageW( hwnd
, TVM_INSERTITEMW
, 0, (LPARAM
) &tvis
);
2006 msi_seltree_sync_item_state( hwnd
, feature
, hitem
);
2007 msi_seltree_add_child_features( package
, hwnd
,
2008 feature
->Feature
, hitem
);
2010 /* the node is expanded if Display is odd */
2011 if ( feature
->Display
% 2 != 0 )
2012 SendMessageW( hwnd
, TVM_EXPAND
, TVE_EXPAND
, (LPARAM
) hitem
);
2015 /* select the first item */
2016 SendMessageW( hwnd
, TVM_SELECTITEM
, TVGN_CARET
| TVGN_DROPHILITE
, (LPARAM
) hfirst
);
2017 info
->selected
= hfirst
;
2020 static void msi_seltree_create_imagelist( HWND hwnd
)
2022 const int bm_width
= 32, bm_height
= 16, bm_count
= 3;
2023 const int bm_resource
= 0x1001;
2028 himl
= ImageList_Create( bm_width
, bm_height
, FALSE
, 4, 0 );
2031 ERR("failed to create image list\n");
2035 for (i
=0; i
<bm_count
; i
++)
2037 hbmp
= LoadBitmapW( msi_hInstance
, MAKEINTRESOURCEW(i
+bm_resource
) );
2040 ERR("failed to load bitmap %d\n", i
);
2045 * Add a dummy bitmap at offset zero because the treeview
2046 * can't use it as a state mask (zero means no user state).
2049 ImageList_Add( himl
, hbmp
, NULL
);
2051 ImageList_Add( himl
, hbmp
, NULL
);
2054 SendMessageW( hwnd
, TVM_SETIMAGELIST
, TVSIL_STATE
, (LPARAM
)himl
);
2057 static UINT
msi_dialog_seltree_handler( msi_dialog
*dialog
,
2058 msi_control
*control
, WPARAM param
)
2060 struct msi_selection_tree_info
*info
= GetPropW( control
->hwnd
, szButtonData
);
2061 LPNMTREEVIEWW tv
= (LPNMTREEVIEWW
)param
;
2062 MSIRECORD
*row
, *rec
;
2064 MSIFEATURE
*feature
;
2065 LPCWSTR dir
, title
= NULL
;
2066 UINT r
= ERROR_SUCCESS
;
2068 static const WCHAR select
[] = {
2069 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2070 '`','F','e','a','t','u','r','e','`',' ','W','H','E','R','E',' ',
2071 '`','T','i','t','l','e','`',' ','=',' ','\'','%','s','\'',0
2074 if (tv
->hdr
.code
!= TVN_SELCHANGINGW
)
2075 return ERROR_SUCCESS
;
2077 info
->selected
= tv
->itemNew
.hItem
;
2079 if (!(tv
->itemNew
.mask
& TVIF_TEXT
))
2081 feature
= msi_seltree_feature_from_item( control
->hwnd
, tv
->itemNew
.hItem
);
2083 title
= feature
->Title
;
2086 title
= tv
->itemNew
.pszText
;
2088 row
= MSI_QueryGetRecord( dialog
->package
->db
, select
, title
);
2090 return ERROR_FUNCTION_FAILED
;
2092 rec
= MSI_CreateRecord( 1 );
2094 MSI_RecordSetStringW( rec
, 1, MSI_RecordGetString( row
, 4 ) );
2095 ControlEvent_FireSubscribedEvent( dialog
->package
, szSelectionDescription
, rec
);
2097 dir
= MSI_RecordGetString( row
, 7 );
2098 folder
= get_loaded_folder( dialog
->package
, dir
);
2101 r
= ERROR_FUNCTION_FAILED
;
2105 MSI_RecordSetStringW( rec
, 1, folder
->ResolvedTarget
);
2106 ControlEvent_FireSubscribedEvent( dialog
->package
, szSelectionPath
, rec
);
2109 msiobj_release(&row
->hdr
);
2110 msiobj_release(&rec
->hdr
);
2115 static UINT
msi_dialog_selection_tree( msi_dialog
*dialog
, MSIRECORD
*rec
)
2117 msi_control
*control
;
2119 MSIPACKAGE
*package
= dialog
->package
;
2121 struct msi_selection_tree_info
*info
;
2123 info
= msi_alloc( sizeof *info
);
2125 return ERROR_FUNCTION_FAILED
;
2127 /* create the treeview control */
2128 style
= TVS_HASLINES
| TVS_HASBUTTONS
| TVS_LINESATROOT
;
2129 style
|= WS_GROUP
| WS_VSCROLL
;
2130 control
= msi_dialog_add_control( dialog
, rec
, WC_TREEVIEWW
, style
);
2134 return ERROR_FUNCTION_FAILED
;
2137 control
->handler
= msi_dialog_seltree_handler
;
2138 control
->attributes
= MSI_RecordGetInteger( rec
, 8 );
2139 prop
= MSI_RecordGetString( rec
, 9 );
2140 control
->property
= msi_dialog_dup_property( dialog
, prop
, FALSE
);
2143 info
->dialog
= dialog
;
2144 info
->hwnd
= control
->hwnd
;
2145 info
->oldproc
= (WNDPROC
) SetWindowLongPtrW( control
->hwnd
, GWLP_WNDPROC
,
2146 (LONG_PTR
)MSISelectionTree_WndProc
);
2147 SetPropW( control
->hwnd
, szButtonData
, info
);
2149 ControlEvent_SubscribeToEvent( dialog
->package
, dialog
,
2150 szSelectionPath
, control
->name
, szProperty
);
2153 msi_seltree_create_imagelist( control
->hwnd
);
2154 msi_seltree_add_child_features( package
, control
->hwnd
, NULL
, NULL
);
2156 return ERROR_SUCCESS
;
2159 /******************** Group Box ***************************************/
2161 static UINT
msi_dialog_group_box( msi_dialog
*dialog
, MSIRECORD
*rec
)
2163 msi_control
*control
;
2166 style
= BS_GROUPBOX
| WS_CHILD
| WS_GROUP
;
2167 control
= msi_dialog_add_control( dialog
, rec
, WC_BUTTONW
, style
);
2169 return ERROR_FUNCTION_FAILED
;
2171 return ERROR_SUCCESS
;
2174 /******************** List Box ***************************************/
2176 struct msi_listbox_info
2186 static LRESULT WINAPI
MSIListBox_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
2188 struct msi_listbox_info
*info
;
2192 TRACE("%p %04x %08lx %08lx\n", hWnd
, msg
, wParam
, lParam
);
2194 info
= GetPropW( hWnd
, szButtonData
);
2198 r
= CallWindowProcW( info
->oldproc
, hWnd
, msg
, wParam
, lParam
);
2203 for (j
= 0; j
< info
->num_items
; j
++)
2204 msi_free( info
->items
[j
] );
2205 msi_free( info
->items
);
2207 RemovePropW( hWnd
, szButtonData
);
2214 static UINT
msi_listbox_add_item( MSIRECORD
*rec
, LPVOID param
)
2216 struct msi_listbox_info
*info
= param
;
2217 LPCWSTR value
, text
;
2220 value
= MSI_RecordGetString( rec
, 3 );
2221 text
= MSI_RecordGetString( rec
, 4 );
2223 info
->items
[info
->addpos_items
] = strdupW( value
);
2225 pos
= SendMessageW( info
->hwnd
, LB_ADDSTRING
, 0, (LPARAM
)text
);
2226 SendMessageW( info
->hwnd
, LB_SETITEMDATA
, pos
, (LPARAM
)info
->items
[info
->addpos_items
] );
2227 info
->addpos_items
++;
2228 return ERROR_SUCCESS
;
2231 static UINT
msi_listbox_add_items( struct msi_listbox_info
*info
, LPCWSTR property
)
2234 MSIQUERY
*view
= NULL
;
2237 static const WCHAR query
[] = {
2238 'S','E','L','E','C','T',' ','*',' ',
2239 'F','R','O','M',' ','`','L','i','s','t','B','o','x','`',' ',
2240 'W','H','E','R','E',' ',
2241 '`','P','r','o','p','e','r','t','y','`',' ','=',' ','\'','%','s','\'',' ',
2242 'O','R','D','E','R',' ','B','Y',' ','`','O','r','d','e','r','`',0
2245 r
= MSI_OpenQuery( info
->dialog
->package
->db
, &view
, query
, property
);
2246 if ( r
!= ERROR_SUCCESS
)
2249 /* just get the number of records */
2251 r
= MSI_IterateRecords( view
, &count
, NULL
, NULL
);
2253 info
->num_items
= count
;
2254 info
->items
= msi_alloc( sizeof(*info
->items
) * count
);
2256 r
= MSI_IterateRecords( view
, NULL
, msi_listbox_add_item
, info
);
2257 msiobj_release( &view
->hdr
);
2262 static UINT
msi_dialog_listbox_handler( msi_dialog
*dialog
,
2263 msi_control
*control
, WPARAM param
)
2265 struct msi_listbox_info
*info
;
2269 if( HIWORD(param
) != LBN_SELCHANGE
)
2270 return ERROR_SUCCESS
;
2272 info
= GetPropW( control
->hwnd
, szButtonData
);
2273 index
= SendMessageW( control
->hwnd
, LB_GETCURSEL
, 0, 0 );
2274 value
= (LPCWSTR
) SendMessageW( control
->hwnd
, LB_GETITEMDATA
, index
, 0 );
2276 MSI_SetPropertyW( info
->dialog
->package
,
2277 control
->property
, value
);
2278 msi_dialog_evaluate_control_conditions( info
->dialog
);
2280 return ERROR_SUCCESS
;
2283 static UINT
msi_dialog_list_box( msi_dialog
*dialog
, MSIRECORD
*rec
)
2285 struct msi_listbox_info
*info
;
2286 msi_control
*control
;
2287 DWORD attributes
, style
;
2290 info
= msi_alloc( sizeof *info
);
2292 return ERROR_FUNCTION_FAILED
;
2294 style
= WS_TABSTOP
| WS_GROUP
| WS_CHILD
| LBS_NOTIFY
| WS_VSCROLL
| WS_BORDER
;
2295 attributes
= MSI_RecordGetInteger( rec
, 8 );
2296 if (~attributes
& msidbControlAttributesSorted
)
2299 control
= msi_dialog_add_control( dialog
, rec
, WC_LISTBOXW
, style
);
2303 return ERROR_FUNCTION_FAILED
;
2306 control
->handler
= msi_dialog_listbox_handler
;
2308 prop
= MSI_RecordGetString( rec
, 9 );
2309 control
->property
= msi_dialog_dup_property( dialog
, prop
, FALSE
);
2312 info
->dialog
= dialog
;
2313 info
->hwnd
= control
->hwnd
;
2315 info
->addpos_items
= 0;
2316 info
->oldproc
= (WNDPROC
)SetWindowLongPtrW( control
->hwnd
, GWLP_WNDPROC
,
2317 (LONG_PTR
)MSIListBox_WndProc
);
2318 SetPropW( control
->hwnd
, szButtonData
, info
);
2320 if ( control
->property
)
2321 msi_listbox_add_items( info
, control
->property
);
2323 return ERROR_SUCCESS
;
2326 /******************** Directory Combo ***************************************/
2328 static void msi_dialog_update_directory_combo( msi_dialog
*dialog
, msi_control
*control
)
2333 if (!control
&& !(control
= msi_dialog_find_control_by_type( dialog
, szDirectoryCombo
)))
2336 indirect
= control
->attributes
& msidbControlAttributesIndirect
;
2337 prop
= msi_dialog_dup_property( dialog
, control
->property
, indirect
);
2338 path
= msi_dialog_dup_property( dialog
, prop
, TRUE
);
2340 PathStripPathW( path
);
2341 PathRemoveBackslashW( path
);
2343 SendMessageW( control
->hwnd
, CB_INSERTSTRING
, 0, (LPARAM
)path
);
2344 SendMessageW( control
->hwnd
, CB_SETCURSEL
, 0, 0 );
2350 static UINT
msi_dialog_directory_combo( msi_dialog
*dialog
, MSIRECORD
*rec
)
2352 msi_control
*control
;
2356 /* FIXME: use CBS_OWNERDRAWFIXED and add owner draw code */
2357 style
= CBS_DROPDOWNLIST
| CBS_HASSTRINGS
| WS_CHILD
|
2358 WS_GROUP
| WS_TABSTOP
| WS_VSCROLL
;
2359 control
= msi_dialog_add_control( dialog
, rec
, WC_COMBOBOXW
, style
);
2361 return ERROR_FUNCTION_FAILED
;
2363 control
->attributes
= MSI_RecordGetInteger( rec
, 8 );
2364 prop
= MSI_RecordGetString( rec
, 9 );
2365 control
->property
= msi_dialog_dup_property( dialog
, prop
, FALSE
);
2367 msi_dialog_update_directory_combo( dialog
, control
);
2369 return ERROR_SUCCESS
;
2372 /******************** Directory List ***************************************/
2374 static void msi_dialog_update_directory_list( msi_dialog
*dialog
, msi_control
*control
)
2376 WCHAR dir_spec
[MAX_PATH
];
2377 WIN32_FIND_DATAW wfd
;
2383 static const WCHAR asterisk
[] = {'*',0};
2384 static const WCHAR dot
[] = {'.',0};
2385 static const WCHAR dotdot
[] = {'.','.',0};
2387 if (!control
&& !(control
= msi_dialog_find_control_by_type( dialog
, szDirectoryList
)))
2390 /* clear the list-view */
2391 SendMessageW( control
->hwnd
, LVM_DELETEALLITEMS
, 0, 0 );
2393 indirect
= control
->attributes
& msidbControlAttributesIndirect
;
2394 prop
= msi_dialog_dup_property( dialog
, control
->property
, indirect
);
2395 path
= msi_dialog_dup_property( dialog
, prop
, TRUE
);
2397 lstrcpyW( dir_spec
, path
);
2398 lstrcatW( dir_spec
, asterisk
);
2400 file
= FindFirstFileW( dir_spec
, &wfd
);
2401 if ( file
== INVALID_HANDLE_VALUE
)
2406 if ( wfd
.dwFileAttributes
!= FILE_ATTRIBUTE_DIRECTORY
)
2409 if ( !lstrcmpW( wfd
.cFileName
, dot
) || !lstrcmpW( wfd
.cFileName
, dotdot
) )
2412 item
.mask
= LVIF_TEXT
;
2413 item
.cchTextMax
= MAX_PATH
;
2416 item
.pszText
= wfd
.cFileName
;
2418 SendMessageW( control
->hwnd
, LVM_INSERTITEMW
, 0, (LPARAM
)&item
);
2419 } while ( FindNextFileW( file
, &wfd
) );
2426 UINT
msi_dialog_directorylist_up( msi_dialog
*dialog
)
2428 msi_control
*control
;
2429 LPWSTR prop
, path
, ptr
;
2432 control
= msi_dialog_find_control_by_type( dialog
, szDirectoryList
);
2433 indirect
= control
->attributes
& msidbControlAttributesIndirect
;
2434 prop
= msi_dialog_dup_property( dialog
, control
->property
, indirect
);
2435 path
= msi_dialog_dup_property( dialog
, prop
, TRUE
);
2437 /* strip off the last directory */
2438 ptr
= PathFindFileNameW( path
);
2439 if (ptr
!= path
) *(ptr
- 1) = '\0';
2440 PathAddBackslashW( path
);
2442 MSI_SetPropertyW( dialog
->package
, prop
, path
);
2444 msi_dialog_update_directory_list( dialog
, NULL
);
2445 msi_dialog_update_directory_combo( dialog
, NULL
);
2446 msi_dialog_update_pathedit( dialog
, NULL
);
2451 return ERROR_SUCCESS
;
2454 static UINT
msi_dialog_dirlist_handler( msi_dialog
*dialog
,
2455 msi_control
*control
, WPARAM param
)
2457 LPNMHDR nmhdr
= (LPNMHDR
)param
;
2458 WCHAR new_path
[MAX_PATH
];
2459 WCHAR text
[MAX_PATH
];
2465 static const WCHAR backslash
[] = {'\\',0};
2467 if (nmhdr
->code
!= LVN_ITEMACTIVATE
)
2468 return ERROR_SUCCESS
;
2470 index
= SendMessageW( control
->hwnd
, LVM_GETNEXTITEM
, -1, LVNI_SELECTED
);
2473 ERR("No list-view item selected!\n");
2474 return ERROR_FUNCTION_FAILED
;
2478 item
.pszText
= text
;
2479 item
.cchTextMax
= MAX_PATH
;
2480 SendMessageW( control
->hwnd
, LVM_GETITEMTEXTW
, index
, (LPARAM
)&item
);
2482 indirect
= control
->attributes
& msidbControlAttributesIndirect
;
2483 prop
= msi_dialog_dup_property( dialog
, control
->property
, indirect
);
2484 path
= msi_dialog_dup_property( dialog
, prop
, TRUE
);
2486 lstrcpyW( new_path
, path
);
2487 lstrcatW( new_path
, text
);
2488 lstrcatW( new_path
, backslash
);
2490 MSI_SetPropertyW( dialog
->package
, prop
, new_path
);
2492 msi_dialog_update_directory_list( dialog
, NULL
);
2493 msi_dialog_update_directory_combo( dialog
, NULL
);
2494 msi_dialog_update_pathedit( dialog
, NULL
);
2498 return ERROR_SUCCESS
;
2501 static UINT
msi_dialog_directory_list( msi_dialog
*dialog
, MSIRECORD
*rec
)
2503 msi_control
*control
;
2507 style
= LVS_LIST
| WS_VSCROLL
| LVS_SHAREIMAGELISTS
|
2508 LVS_AUTOARRANGE
| LVS_SINGLESEL
| WS_BORDER
|
2509 LVS_SORTASCENDING
| WS_CHILD
| WS_GROUP
| WS_TABSTOP
;
2510 control
= msi_dialog_add_control( dialog
, rec
, WC_LISTVIEWW
, style
);
2512 return ERROR_FUNCTION_FAILED
;
2514 control
->attributes
= MSI_RecordGetInteger( rec
, 8 );
2515 control
->handler
= msi_dialog_dirlist_handler
;
2516 prop
= MSI_RecordGetString( rec
, 9 );
2517 control
->property
= msi_dialog_dup_property( dialog
, prop
, FALSE
);
2519 /* double click to activate an item in the list */
2520 SendMessageW( control
->hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
,
2521 0, LVS_EX_TWOCLICKACTIVATE
);
2523 msi_dialog_update_directory_list( dialog
, control
);
2525 return ERROR_SUCCESS
;
2528 /******************** VolumeCost List ***************************************/
2530 static BOOL
str_is_number( LPCWSTR str
)
2534 for (i
= 0; i
< lstrlenW( str
); i
++)
2535 if (!isdigitW(str
[i
]))
2541 static const WCHAR column_keys
[][80] =
2543 {'V','o','l','u','m','e','C','o','s','t','V','o','l','u','m','e',0},
2544 {'V','o','l','u','m','e','C','o','s','t','S','i','z','e',0},
2545 {'V','o','l','u','m','e','C','o','s','t','A','v','a','i','l','a','b','l','e',0},
2546 {'V','o','l','u','m','e','C','o','s','t','R','e','q','u','i','r','e','d',0},
2547 {'V','o','l','u','m','e','C','o','s','t','D','i','f','f','e','r','e','n','c','e',0}
2550 static void msi_dialog_vcl_add_columns( msi_dialog
*dialog
, msi_control
*control
, MSIRECORD
*rec
)
2552 LPCWSTR text
= MSI_RecordGetString( rec
, 10 );
2553 LPCWSTR begin
= text
, end
;
2558 static const WCHAR zero
[] = {'0',0};
2559 static const WCHAR negative
[] = {'-',0};
2563 while ((begin
= strchrW( begin
, '{' )) && count
< 5)
2565 if (!(end
= strchrW( begin
, '}' )))
2568 num
= msi_alloc( (end
-begin
+1)*sizeof(WCHAR
) );
2572 lstrcpynW( num
, begin
+ 1, end
- begin
);
2573 begin
+= end
- begin
+ 1;
2575 /* empty braces or '0' hides the column */
2576 if ( !num
[0] || !lstrcmpW( num
, zero
) )
2583 /* the width must be a positive number
2584 * if a width is invalid, all remaining columns are hidden
2586 if ( !strncmpW( num
, negative
, 1 ) || !str_is_number( num
) ) {
2591 ZeroMemory( &lvc
, sizeof(lvc
) );
2592 lvc
.mask
= LVCF_TEXT
| LVCF_WIDTH
| LVCF_SUBITEM
;
2593 lvc
.cx
= atolW( num
);
2594 lvc
.pszText
= msi_dialog_get_uitext( dialog
, column_keys
[count
] );
2596 SendMessageW( control
->hwnd
, LVM_INSERTCOLUMNW
, count
++, (LPARAM
)&lvc
);
2597 msi_free( lvc
.pszText
);
2602 static void msi_dialog_vcl_add_drives( msi_dialog
*dialog
, msi_control
*control
)
2604 ULARGE_INTEGER total
, free
;
2605 WCHAR size_text
[MAX_PATH
];
2611 size
= GetLogicalDriveStringsW( 0, NULL
);
2612 if ( !size
) return;
2614 drives
= msi_alloc( (size
+ 1) * sizeof(WCHAR
) );
2615 if ( !drives
) return;
2617 GetLogicalDriveStringsW( size
, drives
);
2622 lvitem
.mask
= LVIF_TEXT
;
2624 lvitem
.iSubItem
= 0;
2625 lvitem
.pszText
= ptr
;
2626 lvitem
.cchTextMax
= lstrlenW(ptr
) + 1;
2627 SendMessageW( control
->hwnd
, LVM_INSERTITEMW
, 0, (LPARAM
)&lvitem
);
2629 GetDiskFreeSpaceExW(ptr
, &free
, &total
, NULL
);
2631 StrFormatByteSizeW(total
.QuadPart
, size_text
, MAX_PATH
);
2632 lvitem
.iSubItem
= 1;
2633 lvitem
.pszText
= size_text
;
2634 lvitem
.cchTextMax
= lstrlenW(size_text
) + 1;
2635 SendMessageW( control
->hwnd
, LVM_SETITEMW
, 0, (LPARAM
)&lvitem
);
2637 StrFormatByteSizeW(free
.QuadPart
, size_text
, MAX_PATH
);
2638 lvitem
.iSubItem
= 2;
2639 lvitem
.pszText
= size_text
;
2640 lvitem
.cchTextMax
= lstrlenW(size_text
) + 1;
2641 SendMessageW( control
->hwnd
, LVM_SETITEMW
, 0, (LPARAM
)&lvitem
);
2643 ptr
+= lstrlenW(ptr
) + 1;
2650 static UINT
msi_dialog_volumecost_list( msi_dialog
*dialog
, MSIRECORD
*rec
)
2652 msi_control
*control
;
2655 style
= LVS_REPORT
| WS_VSCROLL
| WS_HSCROLL
| LVS_SHAREIMAGELISTS
|
2656 LVS_AUTOARRANGE
| LVS_SINGLESEL
| WS_BORDER
|
2657 WS_CHILD
| WS_TABSTOP
| WS_GROUP
;
2658 control
= msi_dialog_add_control( dialog
, rec
, WC_LISTVIEWW
, style
);
2660 return ERROR_FUNCTION_FAILED
;
2662 msi_dialog_vcl_add_columns( dialog
, control
, rec
);
2663 msi_dialog_vcl_add_drives( dialog
, control
);
2665 return ERROR_SUCCESS
;
2668 /******************** VolumeSelect Combo ***************************************/
2670 static UINT
msi_dialog_volsel_handler( msi_dialog
*dialog
,
2671 msi_control
*control
, WPARAM param
)
2673 WCHAR text
[MAX_PATH
];
2678 if (HIWORD(param
) != CBN_SELCHANGE
)
2679 return ERROR_SUCCESS
;
2681 index
= SendMessageW( control
->hwnd
, CB_GETCURSEL
, 0, 0 );
2682 if ( index
== CB_ERR
)
2684 ERR("No ComboBox item selected!\n");
2685 return ERROR_FUNCTION_FAILED
;
2688 SendMessageW( control
->hwnd
, CB_GETLBTEXT
, index
, (LPARAM
)text
);
2690 indirect
= control
->attributes
& msidbControlAttributesIndirect
;
2691 prop
= msi_dialog_dup_property( dialog
, control
->property
, indirect
);
2693 MSI_SetPropertyW( dialog
->package
, prop
, text
);
2696 return ERROR_SUCCESS
;
2699 static void msi_dialog_vsc_add_drives( msi_dialog
*dialog
, msi_control
*control
)
2704 size
= GetLogicalDriveStringsW( 0, NULL
);
2705 if ( !size
) return;
2707 drives
= msi_alloc( (size
+ 1) * sizeof(WCHAR
) );
2708 if ( !drives
) return;
2710 GetLogicalDriveStringsW( size
, drives
);
2715 SendMessageW( control
->hwnd
, CB_ADDSTRING
, 0, (LPARAM
)ptr
);
2716 ptr
+= lstrlenW(ptr
) + 1;
2722 static UINT
msi_dialog_volumeselect_combo( msi_dialog
*dialog
, MSIRECORD
*rec
)
2724 msi_control
*control
;
2728 /* FIXME: CBS_OWNERDRAWFIXED */
2729 style
= WS_CHILD
| WS_VISIBLE
| WS_GROUP
| WS_TABSTOP
|
2730 CBS_DROPDOWNLIST
| CBS_SORT
| CBS_HASSTRINGS
|
2731 WS_EX_LEFT
| WS_EX_LTRREADING
| WS_EX_RIGHTSCROLLBAR
;
2732 control
= msi_dialog_add_control( dialog
, rec
, WC_COMBOBOXW
, style
);
2734 return ERROR_FUNCTION_FAILED
;
2736 control
->attributes
= MSI_RecordGetInteger( rec
, 8 );
2737 control
->handler
= msi_dialog_volsel_handler
;
2738 prop
= MSI_RecordGetString( rec
, 9 );
2739 control
->property
= msi_dialog_dup_property( dialog
, prop
, FALSE
);
2741 msi_dialog_vsc_add_drives( dialog
, control
);
2743 return ERROR_SUCCESS
;
2746 static const struct control_handler msi_dialog_handler
[] =
2748 { szText
, msi_dialog_text_control
},
2749 { szPushButton
, msi_dialog_button_control
},
2750 { szLine
, msi_dialog_line_control
},
2751 { szBitmap
, msi_dialog_bitmap_control
},
2752 { szCheckBox
, msi_dialog_checkbox_control
},
2753 { szScrollableText
, msi_dialog_scrolltext_control
},
2754 { szComboBox
, msi_dialog_combo_control
},
2755 { szEdit
, msi_dialog_edit_control
},
2756 { szMaskedEdit
, msi_dialog_maskedit_control
},
2757 { szPathEdit
, msi_dialog_pathedit_control
},
2758 { szProgressBar
, msi_dialog_progress_bar
},
2759 { szRadioButtonGroup
, msi_dialog_radiogroup_control
},
2760 { szIcon
, msi_dialog_icon_control
},
2761 { szSelectionTree
, msi_dialog_selection_tree
},
2762 { szGroupBox
, msi_dialog_group_box
},
2763 { szListBox
, msi_dialog_list_box
},
2764 { szDirectoryCombo
, msi_dialog_directory_combo
},
2765 { szDirectoryList
, msi_dialog_directory_list
},
2766 { szVolumeCostList
, msi_dialog_volumecost_list
},
2767 { szVolumeSelectCombo
, msi_dialog_volumeselect_combo
},
2770 #define NUM_CONTROL_TYPES (sizeof msi_dialog_handler/sizeof msi_dialog_handler[0])
2772 static UINT
msi_dialog_create_controls( MSIRECORD
*rec
, LPVOID param
)
2774 msi_dialog
*dialog
= param
;
2775 LPCWSTR control_type
;
2778 /* find and call the function that can create this type of control */
2779 control_type
= MSI_RecordGetString( rec
, 3 );
2780 for( i
=0; i
<NUM_CONTROL_TYPES
; i
++ )
2781 if (!strcmpiW( msi_dialog_handler
[i
].control_type
, control_type
))
2783 if( i
!= NUM_CONTROL_TYPES
)
2784 msi_dialog_handler
[i
].func( dialog
, rec
);
2786 ERR("no handler for element type %s\n", debugstr_w(control_type
));
2788 return ERROR_SUCCESS
;
2791 static UINT
msi_dialog_fill_controls( msi_dialog
*dialog
)
2793 static const WCHAR query
[] = {
2794 'S','E','L','E','C','T',' ','*',' ',
2795 'F','R','O','M',' ','C','o','n','t','r','o','l',' ',
2796 'W','H','E','R','E',' ',
2797 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',0};
2799 MSIQUERY
*view
= NULL
;
2800 MSIPACKAGE
*package
= dialog
->package
;
2802 TRACE("%p %s\n", dialog
, debugstr_w(dialog
->name
) );
2804 /* query the Control table for all the elements of the control */
2805 r
= MSI_OpenQuery( package
->db
, &view
, query
, dialog
->name
);
2806 if( r
!= ERROR_SUCCESS
)
2808 ERR("query failed for dialog %s\n", debugstr_w(dialog
->name
));
2809 return ERROR_INVALID_PARAMETER
;
2812 r
= MSI_IterateRecords( view
, 0, msi_dialog_create_controls
, dialog
);
2813 msiobj_release( &view
->hdr
);
2818 static UINT
msi_dialog_set_control_condition( MSIRECORD
*rec
, LPVOID param
)
2820 static const WCHAR szHide
[] = { 'H','i','d','e',0 };
2821 static const WCHAR szShow
[] = { 'S','h','o','w',0 };
2822 static const WCHAR szDisable
[] = { 'D','i','s','a','b','l','e',0 };
2823 static const WCHAR szEnable
[] = { 'E','n','a','b','l','e',0 };
2824 static const WCHAR szDefault
[] = { 'D','e','f','a','u','l','t',0 };
2825 msi_dialog
*dialog
= param
;
2826 msi_control
*control
;
2827 LPCWSTR name
, action
, condition
;
2830 name
= MSI_RecordGetString( rec
, 2 );
2831 action
= MSI_RecordGetString( rec
, 3 );
2832 condition
= MSI_RecordGetString( rec
, 4 );
2833 r
= MSI_EvaluateConditionW( dialog
->package
, condition
);
2834 control
= msi_dialog_find_control( dialog
, name
);
2835 if( r
== MSICONDITION_TRUE
&& control
)
2837 TRACE("%s control %s\n", debugstr_w(action
), debugstr_w(name
));
2839 /* FIXME: case sensitive? */
2840 if(!lstrcmpW(action
, szHide
))
2841 ShowWindow(control
->hwnd
, SW_HIDE
);
2842 else if(!strcmpW(action
, szShow
))
2843 ShowWindow(control
->hwnd
, SW_SHOW
);
2844 else if(!strcmpW(action
, szDisable
))
2845 EnableWindow(control
->hwnd
, FALSE
);
2846 else if(!strcmpW(action
, szEnable
))
2847 EnableWindow(control
->hwnd
, TRUE
);
2848 else if(!strcmpW(action
, szDefault
))
2849 SetFocus(control
->hwnd
);
2851 FIXME("Unhandled action %s\n", debugstr_w(action
));
2854 return ERROR_SUCCESS
;
2857 static UINT
msi_dialog_evaluate_control_conditions( msi_dialog
*dialog
)
2859 static const WCHAR query
[] = {
2860 'S','E','L','E','C','T',' ','*',' ',
2861 'F','R','O','M',' ',
2862 'C','o','n','t','r','o','l','C','o','n','d','i','t','i','o','n',' ',
2863 'W','H','E','R','E',' ',
2864 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',0
2867 MSIQUERY
*view
= NULL
;
2868 MSIPACKAGE
*package
= dialog
->package
;
2870 TRACE("%p %s\n", dialog
, debugstr_w(dialog
->name
) );
2872 /* query the Control table for all the elements of the control */
2873 r
= MSI_OpenQuery( package
->db
, &view
, query
, dialog
->name
);
2874 if( r
!= ERROR_SUCCESS
)
2875 return ERROR_SUCCESS
;
2877 r
= MSI_IterateRecords( view
, 0, msi_dialog_set_control_condition
, dialog
);
2878 msiobj_release( &view
->hdr
);
2883 UINT
msi_dialog_reset( msi_dialog
*dialog
)
2885 /* FIXME: should restore the original values of any properties we changed */
2886 return msi_dialog_evaluate_control_conditions( dialog
);
2889 /* figure out the height of 10 point MS Sans Serif */
2890 static INT
msi_dialog_get_sans_serif_height( HWND hwnd
)
2892 static const WCHAR szSansSerif
[] = {
2893 'M','S',' ','S','a','n','s',' ','S','e','r','i','f',0 };
2898 HFONT hFont
, hOldFont
;
2901 hdc
= GetDC( hwnd
);
2904 memset( &lf
, 0, sizeof lf
);
2905 lf
.lfHeight
= MulDiv(10, GetDeviceCaps(hdc
, LOGPIXELSY
), 72);
2906 strcpyW( lf
.lfFaceName
, szSansSerif
);
2907 hFont
= CreateFontIndirectW(&lf
);
2910 hOldFont
= SelectObject( hdc
, hFont
);
2911 r
= GetTextMetricsW( hdc
, &tm
);
2913 height
= tm
.tmHeight
;
2914 SelectObject( hdc
, hOldFont
);
2915 DeleteObject( hFont
);
2917 ReleaseDC( hwnd
, hdc
);
2922 /* fetch the associated record from the Dialog table */
2923 static MSIRECORD
*msi_get_dialog_record( msi_dialog
*dialog
)
2925 static const WCHAR query
[] = {
2926 'S','E','L','E','C','T',' ','*',' ',
2927 'F','R','O','M',' ','D','i','a','l','o','g',' ',
2928 'W','H','E','R','E',' ',
2929 '`','D','i','a','l','o','g','`',' ','=',' ','\'','%','s','\'',0};
2930 MSIPACKAGE
*package
= dialog
->package
;
2931 MSIRECORD
*rec
= NULL
;
2933 TRACE("%p %s\n", dialog
, debugstr_w(dialog
->name
) );
2935 rec
= MSI_QueryGetRecord( package
->db
, query
, dialog
->name
);
2937 WARN("query failed for dialog %s\n", debugstr_w(dialog
->name
));
2942 static void msi_dialog_adjust_dialog_pos( msi_dialog
*dialog
, MSIRECORD
*rec
, LPRECT pos
)
2944 static const WCHAR szScreenX
[] = {'S','c','r','e','e','n','X',0};
2945 static const WCHAR szScreenY
[] = {'S','c','r','e','e','n','Y',0};
2952 center
.x
= MSI_RecordGetInteger( rec
, 2 );
2953 center
.y
= MSI_RecordGetInteger( rec
, 3 );
2955 sz
.cx
= MSI_RecordGetInteger( rec
, 4 );
2956 sz
.cy
= MSI_RecordGetInteger( rec
, 5 );
2958 sz
.cx
= msi_dialog_scale_unit( dialog
, sz
.cx
);
2959 sz
.cy
= msi_dialog_scale_unit( dialog
, sz
.cy
);
2961 xres
= msi_get_property_int( dialog
->package
, szScreenX
, 0 );
2962 yres
= msi_get_property_int( dialog
->package
, szScreenY
, 0 );
2964 center
.x
= MulDiv( center
.x
, xres
, 100 );
2965 center
.y
= MulDiv( center
.y
, yres
, 100 );
2967 /* turn the client pos into the window rectangle */
2968 if (dialog
->package
->center_x
&& dialog
->package
->center_y
)
2970 pos
->left
= dialog
->package
->center_x
- sz
.cx
/ 2.0;
2971 pos
->right
= pos
->left
+ sz
.cx
;
2972 pos
->top
= dialog
->package
->center_y
- sz
.cy
/ 2.0;
2973 pos
->bottom
= pos
->top
+ sz
.cy
;
2977 pos
->left
= center
.x
- sz
.cx
/2;
2978 pos
->right
= pos
->left
+ sz
.cx
;
2979 pos
->top
= center
.y
- sz
.cy
/2;
2980 pos
->bottom
= pos
->top
+ sz
.cy
;
2982 /* save the center */
2983 dialog
->package
->center_x
= center
.x
;
2984 dialog
->package
->center_y
= center
.y
;
2987 dialog
->size
.cx
= sz
.cx
;
2988 dialog
->size
.cy
= sz
.cy
;
2990 TRACE("%u %u %u %u\n", pos
->left
, pos
->top
, pos
->right
, pos
->bottom
);
2992 style
= GetWindowLongPtrW( dialog
->hwnd
, GWL_STYLE
);
2993 AdjustWindowRect( pos
, style
, FALSE
);
2996 static BOOL
msi_control_set_next( msi_control
*control
, msi_control
*next
)
2998 return SetWindowPos( next
->hwnd
, control
->hwnd
, 0, 0, 0, 0,
2999 SWP_NOMOVE
| SWP_NOOWNERZORDER
| SWP_NOREDRAW
|
3000 SWP_NOREPOSITION
| SWP_NOSENDCHANGING
| SWP_NOSIZE
);
3003 static UINT
msi_dialog_set_tab_order( msi_dialog
*dialog
)
3005 msi_control
*control
, *tab_next
;
3007 LIST_FOR_EACH_ENTRY( control
, &dialog
->controls
, msi_control
, entry
)
3009 tab_next
= msi_dialog_find_control( dialog
, control
->tabnext
);
3012 msi_control_set_next( control
, tab_next
);
3015 return ERROR_SUCCESS
;
3018 static void msi_dialog_set_first_control( msi_dialog
* dialog
, LPCWSTR name
)
3020 msi_control
*control
;
3022 control
= msi_dialog_find_control( dialog
, name
);
3024 dialog
->hWndFocus
= control
->hwnd
;
3026 dialog
->hWndFocus
= NULL
;
3029 static LRESULT
msi_dialog_oncreate( HWND hwnd
, LPCREATESTRUCTW cs
)
3031 static const WCHAR df
[] = {
3032 'D','e','f','a','u','l','t','U','I','F','o','n','t',0 };
3033 static const WCHAR dfv
[] = {
3034 'M','S',' ','S','h','e','l','l',' ','D','l','g',0 };
3035 msi_dialog
*dialog
= (msi_dialog
*) cs
->lpCreateParams
;
3036 MSIRECORD
*rec
= NULL
;
3037 LPWSTR title
= NULL
;
3040 TRACE("%p %p\n", dialog
, dialog
->package
);
3042 dialog
->hwnd
= hwnd
;
3043 SetWindowLongPtrW( hwnd
, GWLP_USERDATA
, (LONG_PTR
) dialog
);
3045 rec
= msi_get_dialog_record( dialog
);
3048 TRACE("No record found for dialog %s\n", debugstr_w(dialog
->name
));
3052 dialog
->scale
= msi_dialog_get_sans_serif_height(dialog
->hwnd
);
3054 msi_dialog_adjust_dialog_pos( dialog
, rec
, &pos
);
3056 dialog
->attributes
= MSI_RecordGetInteger( rec
, 6 );
3058 dialog
->default_font
= msi_dup_property( dialog
->package
, df
);
3059 if (!dialog
->default_font
)
3061 dialog
->default_font
= strdupW(dfv
);
3062 if (!dialog
->default_font
) return -1;
3065 title
= msi_get_deformatted_field( dialog
->package
, rec
, 7 );
3066 SetWindowTextW( hwnd
, title
);
3069 SetWindowPos( hwnd
, 0, pos
.left
, pos
.top
,
3070 pos
.right
- pos
.left
, pos
.bottom
- pos
.top
,
3071 SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_NOREDRAW
);
3073 msi_dialog_build_font_list( dialog
);
3074 msi_dialog_fill_controls( dialog
);
3075 msi_dialog_evaluate_control_conditions( dialog
);
3076 msi_dialog_set_tab_order( dialog
);
3077 msi_dialog_set_first_control( dialog
, MSI_RecordGetString( rec
, 8 ) );
3078 msiobj_release( &rec
->hdr
);
3083 static UINT
msi_dialog_send_event( msi_dialog
*dialog
, LPCWSTR event
, LPCWSTR arg
)
3085 LPWSTR event_fmt
= NULL
, arg_fmt
= NULL
;
3087 TRACE("Sending control event %s %s\n", debugstr_w(event
), debugstr_w(arg
));
3089 deformat_string( dialog
->package
, event
, &event_fmt
);
3090 deformat_string( dialog
->package
, arg
, &arg_fmt
);
3092 dialog
->event_handler( dialog
->package
, event_fmt
, arg_fmt
, dialog
);
3094 msi_free( event_fmt
);
3095 msi_free( arg_fmt
);
3097 return ERROR_SUCCESS
;
3100 static UINT
msi_dialog_set_property( msi_dialog
*dialog
, LPCWSTR event
, LPCWSTR arg
)
3102 static const WCHAR szNullArg
[] = { '{','}',0 };
3103 LPWSTR p
, prop
, arg_fmt
= NULL
;
3106 len
= strlenW(event
);
3107 prop
= msi_alloc( len
*sizeof(WCHAR
));
3108 strcpyW( prop
, &event
[1] );
3109 p
= strchrW( prop
, ']' );
3110 if( p
&& (p
[1] == 0 || p
[1] == ' ') )
3113 if( strcmpW( szNullArg
, arg
) )
3114 deformat_string( dialog
->package
, arg
, &arg_fmt
);
3115 MSI_SetPropertyW( dialog
->package
, prop
, arg_fmt
);
3116 msi_dialog_update_controls( dialog
, prop
);
3117 msi_free( arg_fmt
);
3120 ERR("Badly formatted property string - what happens?\n");
3122 return ERROR_SUCCESS
;
3125 static UINT
msi_dialog_control_event( MSIRECORD
*rec
, LPVOID param
)
3127 msi_dialog
*dialog
= param
;
3128 LPCWSTR condition
, event
, arg
;
3131 condition
= MSI_RecordGetString( rec
, 5 );
3132 r
= MSI_EvaluateConditionW( dialog
->package
, condition
);
3133 if( r
== MSICONDITION_TRUE
|| r
== MSICONDITION_NONE
)
3135 event
= MSI_RecordGetString( rec
, 3 );
3136 arg
= MSI_RecordGetString( rec
, 4 );
3137 if( event
[0] == '[' )
3138 msi_dialog_set_property( dialog
, event
, arg
);
3140 msi_dialog_send_event( dialog
, event
, arg
);
3143 return ERROR_SUCCESS
;
3152 static UINT
add_rec_to_list( MSIRECORD
*rec
, LPVOID param
)
3154 struct rec_list
*add_rec
;
3155 struct list
*records
= (struct list
*)param
;
3157 msiobj_addref( &rec
->hdr
);
3159 add_rec
= msi_alloc( sizeof( *add_rec
) );
3162 msiobj_release( &rec
->hdr
);
3163 return ERROR_OUTOFMEMORY
;
3167 list_add_tail( records
, &add_rec
->entry
);
3168 return ERROR_SUCCESS
;
3171 static inline void remove_rec_from_list( struct rec_list
*rec_entry
)
3173 msiobj_release( &rec_entry
->rec
->hdr
);
3174 list_remove( &rec_entry
->entry
);
3175 msi_free( rec_entry
);
3178 static UINT
msi_dialog_button_handler( msi_dialog
*dialog
,
3179 msi_control
*control
, WPARAM param
)
3181 static const WCHAR query
[] = {
3182 'S','E','L','E','C','T',' ','*',' ',
3183 'F','R','O','M',' ','C','o','n','t','r','o','l','E','v','e','n','t',' ',
3184 'W','H','E','R','E',' ',
3185 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',' ',
3187 '`','C','o','n','t','r','o','l','_','`',' ','=',' ','\'','%','s','\'',' ',
3188 'O','R','D','E','R',' ','B','Y',' ','`','O','r','d','e','r','i','n','g','`',0
3190 MSIQUERY
*view
= NULL
;
3191 struct rec_list
*rec_entry
, *next
;
3195 if( HIWORD(param
) != BN_CLICKED
)
3196 return ERROR_SUCCESS
;
3198 list_init( &events
);
3200 r
= MSI_OpenQuery( dialog
->package
->db
, &view
, query
,
3201 dialog
->name
, control
->name
);
3202 if( r
!= ERROR_SUCCESS
)
3204 ERR("query failed\n");
3208 r
= MSI_IterateRecords( view
, 0, add_rec_to_list
, &events
);
3209 msiobj_release( &view
->hdr
);
3210 if (r
!= ERROR_SUCCESS
)
3213 /* handle all SetProperty events first */
3214 LIST_FOR_EACH_ENTRY_SAFE( rec_entry
, next
, &events
, struct rec_list
, entry
)
3216 LPCWSTR event
= MSI_RecordGetString( rec_entry
->rec
, 3 );
3218 if ( event
[0] != '[' )
3221 r
= msi_dialog_control_event( rec_entry
->rec
, dialog
);
3222 remove_rec_from_list( rec_entry
);
3224 if ( r
!= ERROR_SUCCESS
)
3228 /* handle all other events */
3229 LIST_FOR_EACH_ENTRY_SAFE( rec_entry
, next
, &events
, struct rec_list
, entry
)
3231 r
= msi_dialog_control_event( rec_entry
->rec
, dialog
);
3232 remove_rec_from_list( rec_entry
);
3234 if ( r
!= ERROR_SUCCESS
)
3239 LIST_FOR_EACH_ENTRY_SAFE( rec_entry
, next
, &events
, struct rec_list
, entry
)
3241 remove_rec_from_list( rec_entry
);
3247 static UINT
msi_dialog_get_checkbox_state( msi_dialog
*dialog
,
3248 msi_control
*control
)
3250 WCHAR state
[2] = { 0 };
3253 MSI_GetPropertyW( dialog
->package
, control
->property
, state
, &sz
);
3254 return state
[0] ? 1 : 0;
3257 static void msi_dialog_set_checkbox_state( msi_dialog
*dialog
,
3258 msi_control
*control
, UINT state
)
3260 static const WCHAR szState
[] = { '1', 0 };
3263 /* if uncheck then the property is set to NULL */
3266 MSI_SetPropertyW( dialog
->package
, control
->property
, NULL
);
3270 /* check for a custom state */
3271 if (control
->value
&& control
->value
[0])
3272 val
= control
->value
;
3276 MSI_SetPropertyW( dialog
->package
, control
->property
, val
);
3279 static void msi_dialog_checkbox_sync_state( msi_dialog
*dialog
,
3280 msi_control
*control
)
3284 state
= msi_dialog_get_checkbox_state( dialog
, control
);
3285 SendMessageW( control
->hwnd
, BM_SETCHECK
,
3286 state
? BST_CHECKED
: BST_UNCHECKED
, 0 );
3289 static UINT
msi_dialog_checkbox_handler( msi_dialog
*dialog
,
3290 msi_control
*control
, WPARAM param
)
3294 if( HIWORD(param
) != BN_CLICKED
)
3295 return ERROR_SUCCESS
;
3297 TRACE("clicked checkbox %s, set %s\n", debugstr_w(control
->name
),
3298 debugstr_w(control
->property
));
3300 state
= msi_dialog_get_checkbox_state( dialog
, control
);
3301 state
= state
? 0 : 1;
3302 msi_dialog_set_checkbox_state( dialog
, control
, state
);
3303 msi_dialog_checkbox_sync_state( dialog
, control
);
3305 return msi_dialog_button_handler( dialog
, control
, param
);
3308 static UINT
msi_dialog_edit_handler( msi_dialog
*dialog
,
3309 msi_control
*control
, WPARAM param
)
3313 if( HIWORD(param
) != EN_CHANGE
)
3314 return ERROR_SUCCESS
;
3316 TRACE("edit %s contents changed, set %s\n", debugstr_w(control
->name
),
3317 debugstr_w(control
->property
));
3319 buf
= msi_get_window_text( control
->hwnd
);
3320 MSI_SetPropertyW( dialog
->package
, control
->property
, buf
);
3324 return ERROR_SUCCESS
;
3327 static UINT
msi_dialog_radiogroup_handler( msi_dialog
*dialog
,
3328 msi_control
*control
, WPARAM param
)
3330 if( HIWORD(param
) != BN_CLICKED
)
3331 return ERROR_SUCCESS
;
3333 TRACE("clicked radio button %s, set %s\n", debugstr_w(control
->name
),
3334 debugstr_w(control
->property
));
3336 MSI_SetPropertyW( dialog
->package
, control
->property
, control
->name
);
3338 return msi_dialog_button_handler( dialog
, control
, param
);
3341 static LRESULT
msi_dialog_oncommand( msi_dialog
*dialog
, WPARAM param
, HWND hwnd
)
3343 msi_control
*control
= NULL
;
3345 TRACE("%p %p %08lx\n", dialog
, hwnd
, param
);
3350 control
= msi_dialog_find_control( dialog
, dialog
->control_default
);
3352 case 2: /* escape */
3353 control
= msi_dialog_find_control( dialog
, dialog
->control_cancel
);
3356 control
= msi_dialog_find_control_by_hwnd( dialog
, hwnd
);
3361 if( control
->handler
)
3363 control
->handler( dialog
, control
, param
);
3364 msi_dialog_evaluate_control_conditions( dialog
);
3371 static LRESULT
msi_dialog_onnotify( msi_dialog
*dialog
, LPARAM param
)
3373 LPNMHDR nmhdr
= (LPNMHDR
) param
;
3374 msi_control
*control
= msi_dialog_find_control_by_hwnd( dialog
, nmhdr
->hwndFrom
);
3376 TRACE("%p %p\n", dialog
, nmhdr
->hwndFrom
);
3378 if ( control
&& control
->handler
)
3379 control
->handler( dialog
, control
, param
);
3384 static void msi_dialog_setfocus( msi_dialog
*dialog
)
3386 HWND hwnd
= dialog
->hWndFocus
;
3388 hwnd
= GetNextDlgTabItem( dialog
->hwnd
, hwnd
, TRUE
);
3389 hwnd
= GetNextDlgTabItem( dialog
->hwnd
, hwnd
, FALSE
);
3391 dialog
->hWndFocus
= hwnd
;
3394 static LRESULT WINAPI
MSIDialog_WndProc( HWND hwnd
, UINT msg
,
3395 WPARAM wParam
, LPARAM lParam
)
3397 msi_dialog
*dialog
= (LPVOID
) GetWindowLongPtrW( hwnd
, GWLP_USERDATA
);
3399 TRACE("0x%04x\n", msg
);
3404 dialog
->package
->center_x
= LOWORD(lParam
) + dialog
->size
.cx
/ 2.0;
3405 dialog
->package
->center_y
= HIWORD(lParam
) + dialog
->size
.cy
/ 2.0;
3409 return msi_dialog_oncreate( hwnd
, (LPCREATESTRUCTW
)lParam
);
3412 return msi_dialog_oncommand( dialog
, wParam
, (HWND
)lParam
);
3415 if( LOWORD(wParam
) == WA_INACTIVE
)
3416 dialog
->hWndFocus
= GetFocus();
3418 msi_dialog_setfocus( dialog
);
3422 msi_dialog_setfocus( dialog
);
3425 /* bounce back to our subclassed static control */
3426 case WM_CTLCOLORSTATIC
:
3427 return SendMessageW( (HWND
) lParam
, WM_CTLCOLORSTATIC
, wParam
, lParam
);
3430 dialog
->hwnd
= NULL
;
3433 return msi_dialog_onnotify( dialog
, lParam
);
3435 return DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
3438 static BOOL CALLBACK
msi_radioground_child_enum( HWND hWnd
, LPARAM lParam
)
3440 EnableWindow( hWnd
, lParam
);
3444 static LRESULT WINAPI
MSIRadioGroup_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
3446 WNDPROC oldproc
= (WNDPROC
) GetPropW(hWnd
, szButtonData
);
3449 TRACE("hWnd %p msg %04x wParam 0x%08lx lParam 0x%08lx\n", hWnd
, msg
, wParam
, lParam
);
3451 if (msg
== WM_COMMAND
) /* Forward notifications to dialog */
3452 SendMessageW(GetParent(hWnd
), msg
, wParam
, lParam
);
3454 r
= CallWindowProcW(oldproc
, hWnd
, msg
, wParam
, lParam
);
3456 /* make sure the radio buttons show as disabled if the parent is disabled */
3457 if (msg
== WM_ENABLE
)
3458 EnumChildWindows( hWnd
, msi_radioground_child_enum
, wParam
);
3463 static LRESULT WINAPI
MSIHiddenWindowProc( HWND hwnd
, UINT msg
,
3464 WPARAM wParam
, LPARAM lParam
)
3466 msi_dialog
*dialog
= (msi_dialog
*) lParam
;
3468 TRACE("%d %p\n", msg
, dialog
);
3472 case WM_MSI_DIALOG_CREATE
:
3473 return msi_dialog_run_message_loop( dialog
);
3474 case WM_MSI_DIALOG_DESTROY
:
3475 msi_dialog_destroy( dialog
);
3478 return DefWindowProcW( hwnd
, msg
, wParam
, lParam
);
3481 /* functions that interface to other modules within MSI */
3483 msi_dialog
*msi_dialog_create( MSIPACKAGE
* package
,
3484 LPCWSTR szDialogName
, msi_dialog
*parent
,
3485 msi_dialog_event_handler event_handler
)
3487 MSIRECORD
*rec
= NULL
;
3490 TRACE("%p %s\n", package
, debugstr_w(szDialogName
));
3492 if (!hMsiHiddenWindow
)
3493 msi_dialog_register_class();
3495 /* allocate the structure for the dialog to use */
3496 dialog
= msi_alloc_zero( sizeof *dialog
+ sizeof(WCHAR
)*strlenW(szDialogName
) );
3499 strcpyW( dialog
->name
, szDialogName
);
3500 dialog
->parent
= parent
;
3501 msiobj_addref( &package
->hdr
);
3502 dialog
->package
= package
;
3503 dialog
->event_handler
= event_handler
;
3504 dialog
->finished
= 0;
3505 list_init( &dialog
->controls
);
3507 /* verify that the dialog exists */
3508 rec
= msi_get_dialog_record( dialog
);
3511 msiobj_release( &package
->hdr
);
3515 dialog
->attributes
= MSI_RecordGetInteger( rec
, 6 );
3516 dialog
->control_default
= strdupW( MSI_RecordGetString( rec
, 9 ) );
3517 dialog
->control_cancel
= strdupW( MSI_RecordGetString( rec
, 10 ) );
3518 msiobj_release( &rec
->hdr
);
3523 static void msi_process_pending_messages( HWND hdlg
)
3527 while( PeekMessageW( &msg
, 0, 0, 0, PM_REMOVE
) )
3529 if( hdlg
&& IsDialogMessageW( hdlg
, &msg
))
3531 TranslateMessage( &msg
);
3532 DispatchMessageW( &msg
);
3536 void msi_dialog_end_dialog( msi_dialog
*dialog
)
3538 TRACE("%p\n", dialog
);
3539 dialog
->finished
= 1;
3540 PostMessageW(dialog
->hwnd
, WM_NULL
, 0, 0);
3543 void msi_dialog_check_messages( HANDLE handle
)
3547 /* in threads other than the UI thread, block */
3548 if( uiThreadId
!= GetCurrentThreadId() )
3551 WaitForSingleObject( handle
, INFINITE
);
3555 /* there's two choices for the UI thread */
3558 msi_process_pending_messages( NULL
);
3564 * block here until somebody creates a new dialog or
3565 * the handle we're waiting on becomes ready
3567 r
= MsgWaitForMultipleObjects( 1, &handle
, 0, INFINITE
, QS_ALLINPUT
);
3568 if( r
== WAIT_OBJECT_0
)
3573 UINT
msi_dialog_run_message_loop( msi_dialog
*dialog
)
3578 if( uiThreadId
!= GetCurrentThreadId() )
3579 return SendMessageW( hMsiHiddenWindow
, WM_MSI_DIALOG_CREATE
, 0, (LPARAM
) dialog
);
3581 /* create the dialog window, don't show it yet */
3582 style
= WS_OVERLAPPED
;
3583 if( dialog
->attributes
& msidbDialogAttributesVisible
)
3584 style
|= WS_VISIBLE
;
3586 hwnd
= CreateWindowW( szMsiDialogClass
, dialog
->name
, style
,
3587 CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
,
3588 NULL
, NULL
, NULL
, dialog
);
3591 ERR("Failed to create dialog %s\n", debugstr_w( dialog
->name
));
3592 return ERROR_FUNCTION_FAILED
;
3595 ShowWindow( hwnd
, SW_SHOW
);
3596 /* UpdateWindow( hwnd ); - and causes the transparent static controls not to paint */
3598 if( dialog
->attributes
& msidbDialogAttributesModal
)
3600 while( !dialog
->finished
)
3602 MsgWaitForMultipleObjects( 0, NULL
, 0, INFINITE
, QS_ALLINPUT
);
3603 msi_process_pending_messages( dialog
->hwnd
);
3607 return ERROR_IO_PENDING
;
3609 return ERROR_SUCCESS
;
3612 void msi_dialog_do_preview( msi_dialog
*dialog
)
3615 dialog
->attributes
|= msidbDialogAttributesVisible
;
3616 dialog
->attributes
&= ~msidbDialogAttributesModal
;
3617 msi_dialog_run_message_loop( dialog
);
3620 void msi_dialog_destroy( msi_dialog
*dialog
)
3622 if( uiThreadId
!= GetCurrentThreadId() )
3624 SendMessageW( hMsiHiddenWindow
, WM_MSI_DIALOG_DESTROY
, 0, (LPARAM
) dialog
);
3629 ShowWindow( dialog
->hwnd
, SW_HIDE
);
3632 DestroyWindow( dialog
->hwnd
);
3634 /* unsubscribe events */
3635 ControlEvent_CleanupDialogSubscriptions(dialog
->package
, dialog
->name
);
3637 /* destroy the list of controls */
3638 while( !list_empty( &dialog
->controls
) )
3642 t
= LIST_ENTRY( list_head( &dialog
->controls
),
3643 msi_control
, entry
);
3644 msi_destroy_control( t
);
3647 /* destroy the list of fonts */
3648 while( dialog
->font_list
)
3650 msi_font
*t
= dialog
->font_list
;
3651 dialog
->font_list
= t
->next
;
3652 DeleteObject( t
->hfont
);
3655 msi_free( dialog
->default_font
);
3657 msi_free( dialog
->control_default
);
3658 msi_free( dialog
->control_cancel
);
3659 msiobj_release( &dialog
->package
->hdr
);
3660 dialog
->package
= NULL
;
3664 BOOL
msi_dialog_register_class( void )
3668 ZeroMemory( &cls
, sizeof cls
);
3669 cls
.lpfnWndProc
= MSIDialog_WndProc
;
3670 cls
.hInstance
= NULL
;
3671 cls
.hIcon
= LoadIconW(0, (LPWSTR
)IDI_APPLICATION
);
3672 cls
.hCursor
= LoadCursorW(0, (LPWSTR
)IDC_ARROW
);
3673 cls
.hbrBackground
= (HBRUSH
)(COLOR_3DFACE
+ 1);
3674 cls
.lpszMenuName
= NULL
;
3675 cls
.lpszClassName
= szMsiDialogClass
;
3677 if( !RegisterClassW( &cls
) )
3680 cls
.lpfnWndProc
= MSIHiddenWindowProc
;
3681 cls
.lpszClassName
= szMsiHiddenWindow
;
3683 if( !RegisterClassW( &cls
) )
3686 uiThreadId
= GetCurrentThreadId();
3688 hMsiHiddenWindow
= CreateWindowW( szMsiHiddenWindow
, NULL
, WS_OVERLAPPED
,
3689 0, 0, 100, 100, NULL
, NULL
, NULL
, NULL
);
3690 if( !hMsiHiddenWindow
)
3696 void msi_dialog_unregister_class( void )
3698 DestroyWindow( hMsiHiddenWindow
);
3699 hMsiHiddenWindow
= NULL
;
3700 UnregisterClassW( szMsiDialogClass
, NULL
);
3701 UnregisterClassW( szMsiHiddenWindow
, NULL
);
3705 static UINT
error_dialog_handler(MSIPACKAGE
*package
, LPCWSTR event
,
3706 LPCWSTR argument
, msi_dialog
* dialog
)
3708 static const WCHAR end_dialog
[] = {'E','n','d','D','i','a','l','o','g',0};
3709 static const WCHAR error_abort
[] = {'E','r','r','o','r','A','b','o','r','t',0};
3710 static const WCHAR error_cancel
[] = {'E','r','r','o','r','C','a','n','c','e','l',0};
3711 static const WCHAR error_no
[] = {'E','r','r','o','r','N','o',0};
3712 static const WCHAR result_prop
[] = {
3713 'M','S','I','E','r','r','o','r','D','i','a','l','o','g','R','e','s','u','l','t',0
3716 if ( lstrcmpW( event
, end_dialog
) )
3717 return ERROR_SUCCESS
;
3719 if ( !lstrcmpW( argument
, error_abort
) || !lstrcmpW( argument
, error_cancel
) ||
3720 !lstrcmpW( argument
, error_no
) )
3722 MSI_SetPropertyW( package
, result_prop
, error_abort
);
3725 ControlEvent_CleanupSubscriptions(package
);
3726 msi_dialog_end_dialog( dialog
);
3728 return ERROR_SUCCESS
;
3731 static UINT
msi_error_dialog_set_error( MSIPACKAGE
*package
, LPWSTR error_dialog
, LPWSTR error
)
3735 static const WCHAR update
[] =
3736 {'U','P','D','A','T','E',' ','`','C','o','n','t','r','o','l','`',' ',
3737 'S','E','T',' ','`','T','e','x','t','`',' ','=',' ','\'','%','s','\'',' ',
3738 'W','H','E','R','E', ' ','`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',' ',
3739 'A','N','D',' ','`','C','o','n','t','r','o','l','`',' ','=',' ',
3740 '\'','E','r','r','o','r','T','e','x','t','\'',0};
3742 row
= MSI_QueryGetRecord( package
->db
, update
, error
, error_dialog
);
3744 return ERROR_FUNCTION_FAILED
;
3746 msiobj_release(&row
->hdr
);
3747 return ERROR_SUCCESS
;
3750 UINT
msi_spawn_error_dialog( MSIPACKAGE
*package
, LPWSTR error_dialog
, LPWSTR error
)
3753 WCHAR result
[MAX_PATH
];
3754 UINT r
= ERROR_SUCCESS
;
3755 DWORD size
= MAX_PATH
;
3758 static const WCHAR szUILevel
[] = {'U','I','L','e','v','e','l',0};
3759 static const WCHAR pn_prop
[] = {'P','r','o','d','u','c','t','N','a','m','e',0};
3760 static const WCHAR title_fmt
[] = {'%','s',' ','W','a','r','n','i','n','g',0};
3761 static const WCHAR error_abort
[] = {'E','r','r','o','r','A','b','o','r','t',0};
3762 static const WCHAR result_prop
[] = {
3763 'M','S','I','E','r','r','o','r','D','i','a','l','o','g','R','e','s','u','l','t',0
3766 if ( (msi_get_property_int(package
, szUILevel
, 0) & INSTALLUILEVEL_MASK
) == INSTALLUILEVEL_NONE
)
3767 return ERROR_SUCCESS
;
3769 if ( !error_dialog
)
3771 LPWSTR product_name
= msi_dup_property( package
, pn_prop
);
3772 WCHAR title
[MAX_PATH
];
3774 sprintfW( title
, title_fmt
, product_name
);
3775 res
= MessageBoxW( NULL
, error
, title
, MB_OKCANCEL
| MB_ICONWARNING
);
3777 msi_free( product_name
);
3780 return ERROR_SUCCESS
;
3782 return ERROR_FUNCTION_FAILED
;
3785 r
= msi_error_dialog_set_error( package
, error_dialog
, error
);
3786 if ( r
!= ERROR_SUCCESS
)
3789 dialog
= msi_dialog_create( package
, error_dialog
, package
->dialog
,
3790 error_dialog_handler
);
3792 return ERROR_FUNCTION_FAILED
;
3794 dialog
->finished
= FALSE
;
3795 r
= msi_dialog_run_message_loop( dialog
);
3796 if ( r
!= ERROR_SUCCESS
)
3799 r
= MSI_GetPropertyW( package
, result_prop
, result
, &size
);
3800 if ( r
!= ERROR_SUCCESS
)
3803 if ( !lstrcmpW( result
, error_abort
) )
3804 r
= ERROR_FUNCTION_FAILED
;
3807 msi_dialog_destroy( dialog
);