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
);
54 struct msi_control_tag
66 float progress_current
;
72 typedef struct msi_font_tag
74 struct msi_font_tag
*next
;
84 msi_dialog_event_handler event_handler
;
94 LPWSTR control_default
;
95 LPWSTR control_cancel
;
99 typedef UINT (*msi_dialog_control_func
)( msi_dialog
*dialog
, MSIRECORD
*rec
);
100 struct control_handler
102 LPCWSTR control_type
;
103 msi_dialog_control_func func
;
112 } radio_button_group_descr
;
114 static const WCHAR szMsiDialogClass
[] = {
115 'M','s','i','D','i','a','l','o','g','C','l','o','s','e','C','l','a','s','s',0
117 static const WCHAR szMsiHiddenWindow
[] = {
118 'M','s','i','H','i','d','d','e','n','W','i','n','d','o','w',0 };
119 static const WCHAR szStatic
[] = { 'S','t','a','t','i','c',0 };
120 static const WCHAR szButton
[] = { 'B','U','T','T','O','N', 0 };
121 static const WCHAR szButtonData
[] = { 'M','S','I','D','A','T','A',0 };
122 static const WCHAR szProgress
[] = { 'P','r','o','g','r','e','s','s',0 };
123 static const WCHAR szText
[] = { 'T','e','x','t',0 };
124 static const WCHAR szPushButton
[] = { 'P','u','s','h','B','u','t','t','o','n',0 };
125 static const WCHAR szLine
[] = { 'L','i','n','e',0 };
126 static const WCHAR szBitmap
[] = { 'B','i','t','m','a','p',0 };
127 static const WCHAR szCheckBox
[] = { 'C','h','e','c','k','B','o','x',0 };
128 static const WCHAR szScrollableText
[] = {
129 'S','c','r','o','l','l','a','b','l','e','T','e','x','t',0 };
130 static const WCHAR szComboBox
[] = { 'C','o','m','b','o','B','o','x',0 };
131 static const WCHAR szEdit
[] = { 'E','d','i','t',0 };
132 static const WCHAR szMaskedEdit
[] = { 'M','a','s','k','e','d','E','d','i','t',0 };
133 static const WCHAR szPathEdit
[] = { 'P','a','t','h','E','d','i','t',0 };
134 static const WCHAR szProgressBar
[] = {
135 'P','r','o','g','r','e','s','s','B','a','r',0 };
136 static const WCHAR szRadioButtonGroup
[] = {
137 'R','a','d','i','o','B','u','t','t','o','n','G','r','o','u','p',0 };
138 static const WCHAR szIcon
[] = { 'I','c','o','n',0 };
139 static const WCHAR szSelectionTree
[] = {
140 'S','e','l','e','c','t','i','o','n','T','r','e','e',0 };
141 static const WCHAR szGroupBox
[] = { 'G','r','o','u','p','B','o','x',0 };
142 static const WCHAR szListBox
[] = { 'L','i','s','t','B','o','x',0 };
143 static const WCHAR szDirectoryCombo
[] = { 'D','i','r','e','c','t','o','r','y','C','o','m','b','o',0 };
144 static const WCHAR szDirectoryList
[] = { 'D','i','r','e','c','t','o','r','y','L','i','s','t',0 };
145 static const WCHAR szVolumeCostList
[] = { 'V','o','l','u','m','e','C','o','s','t','L','i','s','t',0 };
146 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};
147 static const WCHAR szSelectionPath
[] = {'S','e','l','e','c','t','i','o','n','P','a','t','h',0};
148 static const WCHAR szProperty
[] = {'P','r','o','p','e','r','t','y',0};
150 static UINT
msi_dialog_checkbox_handler( msi_dialog
*, msi_control
*, WPARAM
);
151 static void msi_dialog_checkbox_sync_state( msi_dialog
*, msi_control
* );
152 static UINT
msi_dialog_button_handler( msi_dialog
*, msi_control
*, WPARAM
);
153 static UINT
msi_dialog_edit_handler( msi_dialog
*, msi_control
*, WPARAM
);
154 static UINT
msi_dialog_radiogroup_handler( msi_dialog
*, msi_control
*, WPARAM param
);
155 static UINT
msi_dialog_evaluate_control_conditions( msi_dialog
*dialog
);
156 static LRESULT WINAPI
MSIRadioGroup_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
);
157 static MSIFEATURE
*msi_seltree_get_selected_feature( msi_control
*control
);
159 /* dialog sequencing */
161 #define WM_MSI_DIALOG_CREATE (WM_USER+0x100)
162 #define WM_MSI_DIALOG_DESTROY (WM_USER+0x101)
164 static DWORD uiThreadId
;
165 static HWND hMsiHiddenWindow
;
167 static INT
msi_dialog_scale_unit( msi_dialog
*dialog
, INT val
)
169 return (dialog
->scale
* val
+ 5) / 10;
172 static msi_control
*msi_dialog_find_control( msi_dialog
*dialog
, LPCWSTR name
)
174 msi_control
*control
;
180 LIST_FOR_EACH_ENTRY( control
, &dialog
->controls
, msi_control
, entry
)
181 if( !strcmpW( control
->name
, name
) ) /* FIXME: case sensitive? */
186 static msi_control
*msi_dialog_find_control_by_type( msi_dialog
*dialog
, LPCWSTR type
)
188 msi_control
*control
;
194 LIST_FOR_EACH_ENTRY( control
, &dialog
->controls
, msi_control
, entry
)
195 if( !strcmpW( control
->type
, type
) ) /* FIXME: case sensitive? */
200 static msi_control
*msi_dialog_find_control_by_hwnd( msi_dialog
*dialog
, HWND hwnd
)
202 msi_control
*control
;
206 LIST_FOR_EACH_ENTRY( control
, &dialog
->controls
, msi_control
, entry
)
207 if( hwnd
== control
->hwnd
)
212 static LPWSTR
msi_get_deformatted_field( MSIPACKAGE
*package
, MSIRECORD
*rec
, int field
)
214 LPCWSTR str
= MSI_RecordGetString( rec
, field
);
218 deformat_string( package
, str
, &ret
);
222 static LPWSTR
msi_dialog_dup_property( msi_dialog
*dialog
, LPCWSTR property
, BOOL indirect
)
230 prop
= msi_dup_property( dialog
->package
, property
);
233 prop
= strdupW( property
);
238 msi_dialog
*msi_dialog_get_parent( msi_dialog
*dialog
)
240 return dialog
->parent
;
243 LPWSTR
msi_dialog_get_name( msi_dialog
*dialog
)
249 * msi_dialog_get_style
251 * Extract the {\style} string from the front of the text to display and
252 * update the pointer. Only the last style in a list is applied.
254 static LPWSTR
msi_dialog_get_style( LPCWSTR p
, LPCWSTR
*rest
)
265 while ((first
= strchrW( p
, '{' )) && (q
= strchrW( first
+ 1, '}' )))
268 if( *p
== '\\' || *p
== '&' )
271 /* little bit of sanity checking to stop us getting confused with RTF */
273 if( *i
== '}' || *i
== '\\' )
283 ret
= msi_alloc( len
*sizeof(WCHAR
) );
286 memcpy( ret
, p
, len
*sizeof(WCHAR
) );
291 static UINT
msi_dialog_add_font( MSIRECORD
*rec
, LPVOID param
)
293 msi_dialog
*dialog
= param
;
300 /* create a font and add it to the list */
301 name
= MSI_RecordGetString( rec
, 1 );
302 font
= msi_alloc( sizeof *font
+ strlenW( name
)*sizeof (WCHAR
) );
303 strcpyW( font
->name
, name
);
304 font
->next
= dialog
->font_list
;
305 dialog
->font_list
= font
;
307 font
->color
= MSI_RecordGetInteger( rec
, 4 );
309 memset( &lf
, 0, sizeof lf
);
310 face
= MSI_RecordGetString( rec
, 2 );
311 lf
.lfHeight
= MSI_RecordGetInteger( rec
, 3 );
312 style
= MSI_RecordGetInteger( rec
, 5 );
313 if( style
& msidbTextStyleStyleBitsBold
)
314 lf
.lfWeight
= FW_BOLD
;
315 if( style
& msidbTextStyleStyleBitsItalic
)
317 if( style
& msidbTextStyleStyleBitsUnderline
)
318 lf
.lfUnderline
= TRUE
;
319 if( style
& msidbTextStyleStyleBitsStrike
)
320 lf
.lfStrikeOut
= TRUE
;
321 lstrcpynW( lf
.lfFaceName
, face
, LF_FACESIZE
);
323 /* adjust the height */
324 hdc
= GetDC( dialog
->hwnd
);
327 lf
.lfHeight
= -MulDiv(lf
.lfHeight
, GetDeviceCaps(hdc
, LOGPIXELSY
), 72);
328 ReleaseDC( dialog
->hwnd
, hdc
);
331 font
->hfont
= CreateFontIndirectW( &lf
);
333 TRACE("Adding font style %s\n", debugstr_w(font
->name
) );
335 return ERROR_SUCCESS
;
338 static msi_font
*msi_dialog_find_font( msi_dialog
*dialog
, LPCWSTR name
)
342 for( font
= dialog
->font_list
; font
; font
= font
->next
)
343 if( !strcmpW( font
->name
, name
) ) /* FIXME: case sensitive? */
349 static UINT
msi_dialog_set_font( msi_dialog
*dialog
, HWND hwnd
, LPCWSTR name
)
353 font
= msi_dialog_find_font( dialog
, name
);
355 SendMessageW( hwnd
, WM_SETFONT
, (WPARAM
) font
->hfont
, TRUE
);
357 ERR("No font entry for %s\n", debugstr_w(name
));
358 return ERROR_SUCCESS
;
361 static UINT
msi_dialog_build_font_list( msi_dialog
*dialog
)
363 static const WCHAR query
[] = {
364 'S','E','L','E','C','T',' ','*',' ',
365 'F','R','O','M',' ','`','T','e','x','t','S','t','y','l','e','`',' ',0
368 MSIQUERY
*view
= NULL
;
370 TRACE("dialog %p\n", dialog
);
372 r
= MSI_OpenQuery( dialog
->package
->db
, &view
, query
);
373 if( r
!= ERROR_SUCCESS
)
376 r
= MSI_IterateRecords( view
, NULL
, msi_dialog_add_font
, dialog
);
377 msiobj_release( &view
->hdr
);
382 static void msi_destroy_control( msi_control
*t
)
384 list_remove( &t
->entry
);
385 /* leave dialog->hwnd - destroying parent destroys child windows */
386 msi_free( t
->property
);
387 msi_free( t
->value
);
389 DeleteObject( t
->hBitmap
);
391 DestroyIcon( t
->hIcon
);
392 msi_free( t
->tabnext
);
395 FreeLibrary( t
->hDll
);
399 static msi_control
*msi_dialog_create_window( msi_dialog
*dialog
,
400 MSIRECORD
*rec
, DWORD exstyle
, LPCWSTR szCls
, LPCWSTR name
, LPCWSTR text
,
401 DWORD style
, HWND parent
)
403 DWORD x
, y
, width
, height
;
404 LPWSTR font
= NULL
, title_font
= NULL
;
405 LPCWSTR title
= NULL
;
406 msi_control
*control
;
410 control
= msi_alloc( sizeof *control
+ strlenW(name
)*sizeof(WCHAR
) );
411 strcpyW( control
->name
, name
);
412 list_add_head( &dialog
->controls
, &control
->entry
);
413 control
->handler
= NULL
;
414 control
->property
= NULL
;
415 control
->value
= NULL
;
416 control
->hBitmap
= NULL
;
417 control
->hIcon
= NULL
;
418 control
->hDll
= NULL
;
419 control
->tabnext
= strdupW( MSI_RecordGetString( rec
, 11) );
420 control
->type
= strdupW( MSI_RecordGetString( rec
, 3 ) );
421 control
->progress_current
= 0;
422 control
->progress_max
= 100;
424 x
= MSI_RecordGetInteger( rec
, 4 );
425 y
= MSI_RecordGetInteger( rec
, 5 );
426 width
= MSI_RecordGetInteger( rec
, 6 );
427 height
= MSI_RecordGetInteger( rec
, 7 );
429 x
= msi_dialog_scale_unit( dialog
, x
);
430 y
= msi_dialog_scale_unit( dialog
, y
);
431 width
= msi_dialog_scale_unit( dialog
, width
);
432 height
= msi_dialog_scale_unit( dialog
, height
);
436 deformat_string( dialog
->package
, text
, &title_font
);
437 font
= msi_dialog_get_style( title_font
, &title
);
440 control
->hwnd
= CreateWindowExW( exstyle
, szCls
, title
, style
,
441 x
, y
, width
, height
, parent
, NULL
, NULL
, NULL
);
443 TRACE("Dialog %s control %s hwnd %p\n",
444 debugstr_w(dialog
->name
), debugstr_w(text
), control
->hwnd
);
446 msi_dialog_set_font( dialog
, control
->hwnd
,
447 font
? font
: dialog
->default_font
);
449 msi_free( title_font
);
455 static LPWSTR
msi_dialog_get_uitext( msi_dialog
*dialog
, LPCWSTR key
)
460 static const WCHAR query
[] = {
461 's','e','l','e','c','t',' ','*',' ',
462 'f','r','o','m',' ','`','U','I','T','e','x','t','`',' ',
463 'w','h','e','r','e',' ','`','K','e','y','`',' ','=',' ','\'','%','s','\'',0
466 rec
= MSI_QueryGetRecord( dialog
->package
->db
, query
, key
);
467 if (!rec
) return NULL
;
468 text
= strdupW( MSI_RecordGetString( rec
, 2 ) );
469 msiobj_release( &rec
->hdr
);
473 static MSIRECORD
*msi_get_binary_record( MSIDATABASE
*db
, LPCWSTR name
)
475 static const WCHAR query
[] = {
476 's','e','l','e','c','t',' ','*',' ',
477 'f','r','o','m',' ','B','i','n','a','r','y',' ',
478 'w','h','e','r','e',' ',
479 '`','N','a','m','e','`',' ','=',' ','\'','%','s','\'',0
482 return MSI_QueryGetRecord( db
, query
, name
);
485 static LPWSTR
msi_create_tmp_path(void)
489 static const WCHAR prefix
[] = { 'm','s','i',0 };
492 r
= GetTempPathW( MAX_PATH
, tmp
);
495 len
= lstrlenW( tmp
) + 20;
496 path
= msi_alloc( len
* sizeof (WCHAR
) );
499 r
= GetTempFileNameW( tmp
, prefix
, 0, path
);
510 static HANDLE
msi_load_image( MSIDATABASE
*db
, LPCWSTR name
, UINT type
,
511 UINT cx
, UINT cy
, UINT flags
)
513 MSIRECORD
*rec
= NULL
;
514 HANDLE himage
= NULL
;
518 TRACE("%p %s %u %u %08x\n", db
, debugstr_w(name
), cx
, cy
, flags
);
520 tmp
= msi_create_tmp_path();
524 rec
= msi_get_binary_record( db
, name
);
527 r
= MSI_RecordStreamToFile( rec
, 2, tmp
);
528 if( r
== ERROR_SUCCESS
)
530 himage
= LoadImageW( 0, tmp
, type
, cx
, cy
, flags
);
532 msiobj_release( &rec
->hdr
);
540 static HICON
msi_load_icon( MSIDATABASE
*db
, LPCWSTR text
, UINT attributes
)
542 DWORD cx
= 0, cy
= 0, flags
;
544 flags
= LR_LOADFROMFILE
| LR_DEFAULTSIZE
;
545 if( attributes
& msidbControlAttributesFixedSize
)
547 flags
&= ~LR_DEFAULTSIZE
;
548 if( attributes
& msidbControlAttributesIconSize16
)
553 if( attributes
& msidbControlAttributesIconSize32
)
558 /* msidbControlAttributesIconSize48 handled by above logic */
560 return msi_load_image( db
, text
, IMAGE_ICON
, cx
, cy
, flags
);
564 /* called from the Control Event subscription code */
565 void msi_dialog_handle_event( msi_dialog
* dialog
, LPCWSTR control
,
566 LPCWSTR attribute
, MSIRECORD
*rec
)
569 LPCWSTR font_text
, text
= NULL
;
572 static const WCHAR empty
[] = {0};
574 ctrl
= msi_dialog_find_control( dialog
, control
);
577 if( !lstrcmpW(attribute
, szText
) )
579 font_text
= MSI_RecordGetString( rec
, 1 );
580 font
= msi_dialog_get_style( font_text
, &text
);
581 if (!text
) text
= empty
;
582 SetWindowTextW( ctrl
->hwnd
, text
);
584 msi_dialog_check_messages( NULL
);
586 else if( !lstrcmpW(attribute
, szProgress
) )
590 func
= MSI_RecordGetInteger( rec
, 1 );
591 val
= MSI_RecordGetInteger( rec
, 2 );
596 ctrl
->progress_max
= val
;
597 ctrl
->progress_current
= 0;
598 SendMessageW(ctrl
->hwnd
, PBM_SETRANGE
, 0, MAKELPARAM(0,100));
599 SendMessageW(ctrl
->hwnd
, PBM_SETPOS
, 0, 0);
601 case 1: /* FIXME: not sure what this is supposed to do */
604 ctrl
->progress_current
+= val
;
605 SendMessageW(ctrl
->hwnd
, PBM_SETPOS
, 100*(ctrl
->progress_current
/ctrl
->progress_max
), 0);
608 ERR("Unknown progress message %d\n", func
);
612 else if ( !lstrcmpW(attribute
, szProperty
) )
614 MSIFEATURE
*feature
= msi_seltree_get_selected_feature( ctrl
);
615 MSI_SetPropertyW( dialog
->package
, ctrl
->property
, feature
->Directory
);
617 else if ( !lstrcmpW(attribute
, szSelectionPath
) )
619 LPWSTR prop
= msi_dialog_dup_property( dialog
, ctrl
->property
, TRUE
);
622 path
= msi_dup_property( dialog
->package
, prop
);
623 SetWindowTextW( ctrl
->hwnd
, path
);
629 FIXME("Attribute %s not being set\n", debugstr_w(attribute
));
634 static void msi_dialog_map_events(msi_dialog
* dialog
, LPCWSTR control
)
636 static const WCHAR Query
[] = {
637 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
638 '`','E','v','e','n','t','M','a','p','p','i','n','g','`',' ',
639 'W','H','E','R','E',' ',
640 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',' ',
642 '`','C','o','n','t','r','o','l','_','`',' ','=',' ','\'','%','s','\'',0
645 LPCWSTR event
, attribute
;
647 row
= MSI_QueryGetRecord( dialog
->package
->db
, Query
, dialog
->name
, control
);
651 event
= MSI_RecordGetString( row
, 3 );
652 attribute
= MSI_RecordGetString( row
, 4 );
653 ControlEvent_SubscribeToEvent( dialog
->package
, dialog
, event
, control
, attribute
);
654 msiobj_release( &row
->hdr
);
657 /* everything except radio buttons */
658 static msi_control
*msi_dialog_add_control( msi_dialog
*dialog
,
659 MSIRECORD
*rec
, LPCWSTR szCls
, DWORD style
)
665 name
= MSI_RecordGetString( rec
, 2 );
666 attributes
= MSI_RecordGetInteger( rec
, 8 );
667 text
= MSI_RecordGetString( rec
, 10 );
668 if( attributes
& msidbControlAttributesVisible
)
670 if( ~attributes
& msidbControlAttributesEnabled
)
671 style
|= WS_DISABLED
;
672 if( attributes
& msidbControlAttributesSunken
)
673 exstyle
|= WS_EX_CLIENTEDGE
;
675 msi_dialog_map_events(dialog
, name
);
677 return msi_dialog_create_window( dialog
, rec
, exstyle
, szCls
, name
,
678 text
, style
, dialog
->hwnd
);
689 * we don't erase our own background,
690 * so we have to make sure that the parent window redraws first
692 static void msi_text_on_settext( HWND hWnd
)
697 hParent
= GetParent( hWnd
);
698 GetWindowRect( hWnd
, &rc
);
699 MapWindowPoints( NULL
, hParent
, (LPPOINT
) &rc
, 2 );
700 InvalidateRect( hParent
, &rc
, TRUE
);
703 static LRESULT WINAPI
704 MSIText_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
706 struct msi_text_info
*info
;
709 TRACE("%p %04x %08x %08lx\n", hWnd
, msg
, wParam
, lParam
);
711 info
= GetPropW(hWnd
, szButtonData
);
714 SetTextColor( (HDC
)wParam
, info
->font
->color
);
716 if( msg
== WM_CTLCOLORSTATIC
&&
717 ( info
->attributes
& msidbControlAttributesTransparent
) )
719 SetBkMode( (HDC
)wParam
, TRANSPARENT
);
720 return (LRESULT
) GetStockObject(NULL_BRUSH
);
723 r
= CallWindowProcW(info
->oldproc
, hWnd
, msg
, wParam
, lParam
);
728 msi_text_on_settext( hWnd
);
732 RemovePropW( hWnd
, szButtonData
);
739 static UINT
msi_dialog_text_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
741 msi_control
*control
;
742 struct msi_text_info
*info
;
743 LPCWSTR text
, ptr
, prop
;
746 TRACE("%p %p\n", dialog
, rec
);
748 control
= msi_dialog_add_control( dialog
, rec
, szStatic
, SS_LEFT
| WS_GROUP
);
750 return ERROR_FUNCTION_FAILED
;
752 info
= msi_alloc( sizeof *info
);
754 return ERROR_SUCCESS
;
756 control
->attributes
= MSI_RecordGetInteger( rec
, 8 );
757 prop
= MSI_RecordGetString( rec
, 9 );
758 control
->property
= msi_dialog_dup_property( dialog
, prop
, FALSE
);
760 text
= MSI_RecordGetString( rec
, 10 );
761 font_name
= msi_dialog_get_style( text
, &ptr
);
762 info
->font
= ( font_name
) ? msi_dialog_find_font( dialog
, font_name
) : NULL
;
763 msi_free( font_name
);
765 info
->attributes
= MSI_RecordGetInteger( rec
, 8 );
766 if( info
->attributes
& msidbControlAttributesTransparent
)
767 SetWindowLongPtrW( control
->hwnd
, GWL_EXSTYLE
, WS_EX_TRANSPARENT
);
769 info
->oldproc
= (WNDPROC
) SetWindowLongPtrW( control
->hwnd
, GWLP_WNDPROC
,
770 (LONG_PTR
)MSIText_WndProc
);
771 SetPropW( control
->hwnd
, szButtonData
, info
);
773 ControlEvent_SubscribeToEvent( dialog
->package
, dialog
,
774 szSelectionPath
, control
->name
, szSelectionPath
);
776 return ERROR_SUCCESS
;
779 static UINT
msi_dialog_button_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
781 msi_control
*control
;
782 UINT attributes
, style
;
785 TRACE("%p %p\n", dialog
, rec
);
788 attributes
= MSI_RecordGetInteger( rec
, 8 );
789 if( attributes
& msidbControlAttributesIcon
)
792 control
= msi_dialog_add_control( dialog
, rec
, szButton
, style
);
794 return ERROR_FUNCTION_FAILED
;
796 control
->handler
= msi_dialog_button_handler
;
799 text
= msi_get_deformatted_field( dialog
->package
, rec
, 10 );
800 control
->hIcon
= msi_load_icon( dialog
->package
->db
, text
, attributes
);
801 if( attributes
& msidbControlAttributesIcon
)
802 SendMessageW( control
->hwnd
, BM_SETIMAGE
, IMAGE_ICON
, (LPARAM
) control
->hIcon
);
805 return ERROR_SUCCESS
;
808 static LPWSTR
msi_get_checkbox_value( msi_dialog
*dialog
, LPCWSTR prop
)
810 static const WCHAR query
[] = {
811 'S','E','L','E','C','T',' ','*',' ',
812 'F','R','O','M',' ','`','C','h','e','c','k','B','o','x',' ','`',
813 'W','H','E','R','E',' ',
814 '`','P','r','o','p','e','r','t','y','`',' ','=',' ',
817 MSIRECORD
*rec
= NULL
;
820 /* find if there is a value associated with the checkbox */
821 rec
= MSI_QueryGetRecord( dialog
->package
->db
, query
, prop
);
825 ret
= msi_get_deformatted_field( dialog
->package
, rec
, 2 );
831 msiobj_release( &rec
->hdr
);
835 ret
= msi_dup_property( dialog
->package
, prop
);
845 static UINT
msi_dialog_checkbox_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
847 msi_control
*control
;
850 TRACE("%p %p\n", dialog
, rec
);
852 control
= msi_dialog_add_control( dialog
, rec
, szButton
,
853 BS_CHECKBOX
| BS_MULTILINE
| WS_TABSTOP
);
854 control
->handler
= msi_dialog_checkbox_handler
;
855 prop
= MSI_RecordGetString( rec
, 9 );
858 control
->property
= strdupW( prop
);
859 control
->value
= msi_get_checkbox_value( dialog
, prop
);
860 TRACE("control %s value %s\n", debugstr_w(control
->property
),
861 debugstr_w(control
->value
));
863 msi_dialog_checkbox_sync_state( dialog
, control
);
865 return ERROR_SUCCESS
;
868 static UINT
msi_dialog_line_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
870 TRACE("%p %p\n", dialog
, rec
);
872 /* line is exactly 2 units in height */
873 MSI_RecordSetInteger( rec
, 7, 2 );
875 msi_dialog_add_control( dialog
, rec
, szStatic
, SS_ETCHEDHORZ
| SS_SUNKEN
);
876 return ERROR_SUCCESS
;
879 /******************** Scroll Text ********************************************/
881 struct msi_scrolltext_info
884 msi_control
*control
;
888 static LRESULT WINAPI
889 MSIScrollText_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
891 struct msi_scrolltext_info
*info
;
894 TRACE("%p %04x %08x %08lx\n", hWnd
, msg
, wParam
, lParam
);
896 info
= GetPropW( hWnd
, szButtonData
);
898 r
= CallWindowProcW( info
->oldproc
, hWnd
, msg
, wParam
, lParam
);
904 RemovePropW( hWnd
, szButtonData
);
907 /* native MSI sets a wait cursor here */
908 msi_dialog_button_handler( info
->dialog
, info
->control
, BN_CLICKED
);
914 struct msi_streamin_info
921 static DWORD CALLBACK
922 msi_richedit_stream_in( DWORD_PTR arg
, LPBYTE buffer
, LONG count
, LONG
*pcb
)
924 struct msi_streamin_info
*info
= (struct msi_streamin_info
*) arg
;
926 if( (count
+ info
->offset
) > info
->length
)
927 count
= info
->length
- info
->offset
;
928 memcpy( buffer
, &info
->string
[ info
->offset
], count
);
930 info
->offset
+= count
;
932 TRACE("%d/%d\n", info
->offset
, info
->length
);
937 static void msi_scrolltext_add_text( msi_control
*control
, LPCWSTR text
)
939 struct msi_streamin_info info
;
942 info
.string
= strdupWtoA( text
);
944 info
.length
= lstrlenA( info
.string
) + 1;
946 es
.dwCookie
= (DWORD_PTR
) &info
;
948 es
.pfnCallback
= msi_richedit_stream_in
;
950 SendMessageW( control
->hwnd
, EM_STREAMIN
, SF_RTF
, (LPARAM
) &es
);
952 msi_free( info
.string
);
955 static UINT
msi_dialog_scrolltext_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
957 static const WCHAR szRichEdit20W
[] = {
958 'R','i','c','h','E','d','i','t','2','0','W',0
960 struct msi_scrolltext_info
*info
;
961 msi_control
*control
;
966 info
= msi_alloc( sizeof *info
);
968 return ERROR_FUNCTION_FAILED
;
970 hRichedit
= LoadLibraryA("riched20");
972 style
= WS_BORDER
| ES_MULTILINE
| WS_VSCROLL
|
973 ES_READONLY
| ES_AUTOVSCROLL
| WS_TABSTOP
;
974 control
= msi_dialog_add_control( dialog
, rec
, szRichEdit20W
, style
);
977 FreeLibrary( hRichedit
);
979 return ERROR_FUNCTION_FAILED
;
982 control
->hDll
= hRichedit
;
984 info
->dialog
= dialog
;
985 info
->control
= control
;
987 /* subclass the static control */
988 info
->oldproc
= (WNDPROC
) SetWindowLongPtrW( control
->hwnd
, GWLP_WNDPROC
,
989 (LONG_PTR
)MSIScrollText_WndProc
);
990 SetPropW( control
->hwnd
, szButtonData
, info
);
992 /* add the text into the richedit */
993 text
= MSI_RecordGetString( rec
, 10 );
995 msi_scrolltext_add_text( control
, text
);
997 return ERROR_SUCCESS
;
1000 static HBITMAP
msi_load_picture( MSIDATABASE
*db
, LPCWSTR name
,
1001 INT cx
, INT cy
, DWORD flags
)
1003 HBITMAP hOleBitmap
= 0, hBitmap
= 0, hOldSrcBitmap
, hOldDestBitmap
;
1004 MSIRECORD
*rec
= NULL
;
1005 IStream
*stm
= NULL
;
1006 IPicture
*pic
= NULL
;
1011 rec
= msi_get_binary_record( db
, name
);
1015 r
= MSI_RecordGetIStream( rec
, 2, &stm
);
1016 msiobj_release( &rec
->hdr
);
1017 if( r
!= ERROR_SUCCESS
)
1020 r
= OleLoadPicture( stm
, 0, TRUE
, &IID_IPicture
, (LPVOID
*) &pic
);
1021 IStream_Release( stm
);
1024 ERR("failed to load picture\n");
1028 r
= IPicture_get_Handle( pic
, (OLE_HANDLE
*) &hOleBitmap
);
1031 ERR("failed to get bitmap handle\n");
1035 /* make the bitmap the desired size */
1036 r
= GetObjectW( hOleBitmap
, sizeof bm
, &bm
);
1037 if (r
!= sizeof bm
)
1039 ERR("failed to get bitmap size\n");
1043 if (flags
& LR_DEFAULTSIZE
)
1049 srcdc
= CreateCompatibleDC( NULL
);
1050 hOldSrcBitmap
= SelectObject( srcdc
, hOleBitmap
);
1051 destdc
= CreateCompatibleDC( NULL
);
1052 hBitmap
= CreateCompatibleBitmap( srcdc
, cx
, cy
);
1053 hOldDestBitmap
= SelectObject( destdc
, hBitmap
);
1054 StretchBlt( destdc
, 0, 0, cx
, cy
,
1055 srcdc
, 0, 0, bm
.bmWidth
, bm
.bmHeight
, SRCCOPY
);
1056 SelectObject( srcdc
, hOldSrcBitmap
);
1057 SelectObject( destdc
, hOldDestBitmap
);
1063 IPicture_Release( pic
);
1067 static UINT
msi_dialog_bitmap_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1069 UINT cx
, cy
, flags
, style
, attributes
;
1070 msi_control
*control
;
1073 flags
= LR_LOADFROMFILE
;
1074 style
= SS_BITMAP
| SS_LEFT
| WS_GROUP
;
1076 attributes
= MSI_RecordGetInteger( rec
, 8 );
1077 if( attributes
& msidbControlAttributesFixedSize
)
1079 flags
|= LR_DEFAULTSIZE
;
1080 style
|= SS_CENTERIMAGE
;
1083 control
= msi_dialog_add_control( dialog
, rec
, szStatic
, style
);
1084 cx
= MSI_RecordGetInteger( rec
, 6 );
1085 cy
= MSI_RecordGetInteger( rec
, 7 );
1086 cx
= msi_dialog_scale_unit( dialog
, cx
);
1087 cy
= msi_dialog_scale_unit( dialog
, cy
);
1089 text
= msi_get_deformatted_field( dialog
->package
, rec
, 10 );
1090 control
->hBitmap
= msi_load_picture( dialog
->package
->db
, text
, cx
, cy
, flags
);
1091 if( control
->hBitmap
)
1092 SendMessageW( control
->hwnd
, STM_SETIMAGE
,
1093 IMAGE_BITMAP
, (LPARAM
) control
->hBitmap
);
1095 ERR("Failed to load bitmap %s\n", debugstr_w(text
));
1099 return ERROR_SUCCESS
;
1102 static UINT
msi_dialog_icon_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1104 msi_control
*control
;
1110 control
= msi_dialog_add_control( dialog
, rec
, szStatic
,
1111 SS_ICON
| SS_CENTERIMAGE
| WS_GROUP
);
1113 attributes
= MSI_RecordGetInteger( rec
, 8 );
1114 text
= msi_get_deformatted_field( dialog
->package
, rec
, 10 );
1115 control
->hIcon
= msi_load_icon( dialog
->package
->db
, text
, attributes
);
1116 if( control
->hIcon
)
1117 SendMessageW( control
->hwnd
, STM_SETICON
, (WPARAM
) control
->hIcon
, 0 );
1119 ERR("Failed to load bitmap %s\n", debugstr_w(text
));
1121 return ERROR_SUCCESS
;
1124 static UINT
msi_dialog_combo_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1126 static const WCHAR szCombo
[] = { 'C','O','M','B','O','B','O','X',0 };
1128 msi_dialog_add_control( dialog
, rec
, szCombo
,
1129 SS_BITMAP
| SS_LEFT
| SS_CENTERIMAGE
);
1130 return ERROR_SUCCESS
;
1133 static UINT
msi_dialog_edit_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1135 msi_control
*control
;
1139 control
= msi_dialog_add_control( dialog
, rec
, szEdit
,
1140 WS_BORDER
| WS_TABSTOP
);
1141 control
->handler
= msi_dialog_edit_handler
;
1142 prop
= MSI_RecordGetString( rec
, 9 );
1144 control
->property
= strdupW( prop
);
1145 val
= msi_dup_property( dialog
->package
, control
->property
);
1146 SetWindowTextW( control
->hwnd
, val
);
1148 return ERROR_SUCCESS
;
1151 /******************** Masked Edit ********************************************/
1153 #define MASK_MAX_GROUPS 20
1155 struct msi_mask_group
1163 struct msi_maskedit_info
1171 struct msi_mask_group group
[MASK_MAX_GROUPS
];
1174 static BOOL
msi_mask_editable( WCHAR type
)
1189 static void msi_mask_control_change( struct msi_maskedit_info
*info
)
1194 val
= msi_alloc( (info
->num_chars
+1)*sizeof(WCHAR
) );
1195 for( i
=0, n
=0; i
<info
->num_groups
; i
++ )
1197 if( (info
->group
[i
].len
+ n
) > info
->num_chars
)
1199 ERR("can't fit control %d text into template\n",i
);
1202 if (!msi_mask_editable(info
->group
[i
].type
))
1204 for(r
=0; r
<info
->group
[i
].len
; r
++)
1205 val
[n
+r
] = info
->group
[i
].type
;
1210 r
= GetWindowTextW( info
->group
[i
].hwnd
, &val
[n
], info
->group
[i
].len
+1 );
1211 if( r
!= info
->group
[i
].len
)
1217 TRACE("%d/%d controls were good\n", i
, info
->num_groups
);
1219 if( i
== info
->num_groups
)
1221 TRACE("Set property %s to %s\n",
1222 debugstr_w(info
->prop
), debugstr_w(val
) );
1223 CharUpperBuffW( val
, info
->num_chars
);
1224 MSI_SetPropertyW( info
->dialog
->package
, info
->prop
, val
);
1225 msi_dialog_evaluate_control_conditions( info
->dialog
);
1230 /* now move to the next control if necessary */
1231 static VOID
msi_mask_next_control( struct msi_maskedit_info
*info
, HWND hWnd
)
1236 for( i
=0; i
<info
->num_groups
; i
++ )
1237 if( info
->group
[i
].hwnd
== hWnd
)
1240 /* don't move from the last control */
1241 if( i
>= (info
->num_groups
-1) )
1244 len
= SendMessageW( hWnd
, WM_GETTEXTLENGTH
, 0, 0 );
1245 if( len
< info
->group
[i
].len
)
1248 hWndNext
= GetNextDlgTabItem( GetParent( hWnd
), hWnd
, FALSE
);
1249 SetFocus( hWndNext
);
1252 static LRESULT WINAPI
1253 MSIMaskedEdit_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1255 struct msi_maskedit_info
*info
;
1258 TRACE("%p %04x %08x %08lx\n", hWnd
, msg
, wParam
, lParam
);
1260 info
= GetPropW(hWnd
, szButtonData
);
1262 r
= CallWindowProcW(info
->oldproc
, hWnd
, msg
, wParam
, lParam
);
1267 if (HIWORD(wParam
) == EN_CHANGE
)
1269 msi_mask_control_change( info
);
1270 msi_mask_next_control( info
, (HWND
) lParam
);
1274 msi_free( info
->prop
);
1276 RemovePropW( hWnd
, szButtonData
);
1283 /* fish the various bits of the property out and put them in the control */
1285 msi_maskedit_set_text( struct msi_maskedit_info
*info
, LPCWSTR text
)
1291 for( i
= 0; i
< info
->num_groups
; i
++ )
1293 if( info
->group
[i
].len
< lstrlenW( p
) )
1295 LPWSTR chunk
= strdupW( p
);
1296 chunk
[ info
->group
[i
].len
] = 0;
1297 SetWindowTextW( info
->group
[i
].hwnd
, chunk
);
1302 SetWindowTextW( info
->group
[i
].hwnd
, p
);
1305 p
+= info
->group
[i
].len
;
1309 static struct msi_maskedit_info
* msi_dialog_parse_groups( LPCWSTR mask
)
1311 struct msi_maskedit_info
* info
= NULL
;
1312 int i
= 0, n
= 0, total
= 0;
1315 TRACE("masked control, template %s\n", debugstr_w(mask
));
1320 info
= msi_alloc_zero( sizeof *info
);
1324 p
= strchrW(mask
, '<');
1330 for( i
=0; i
<MASK_MAX_GROUPS
; i
++ )
1332 /* stop at the end of the string */
1333 if( p
[0] == 0 || p
[0] == '>' )
1336 /* count the number of the same identifier */
1337 for( n
=0; p
[n
] == p
[0]; n
++ )
1339 info
->group
[i
].ofs
= total
;
1340 info
->group
[i
].type
= p
[0];
1344 total
++; /* an extra not part of the group */
1346 info
->group
[i
].len
= n
;
1351 TRACE("%d characters in %d groups\n", total
, i
);
1352 if( i
== MASK_MAX_GROUPS
)
1353 ERR("too many groups in PIDTemplate %s\n", debugstr_w(mask
));
1355 info
->num_chars
= total
;
1356 info
->num_groups
= i
;
1362 msi_maskedit_create_children( struct msi_maskedit_info
*info
, LPCWSTR font
)
1364 DWORD width
, height
, style
, wx
, ww
;
1369 style
= WS_CHILD
| WS_BORDER
| WS_VISIBLE
| WS_TABSTOP
| ES_AUTOHSCROLL
;
1371 GetClientRect( info
->hwnd
, &rect
);
1373 width
= rect
.right
- rect
.left
;
1374 height
= rect
.bottom
- rect
.top
;
1376 for( i
= 0; i
< info
->num_groups
; i
++ )
1378 if (!msi_mask_editable( info
->group
[i
].type
))
1380 wx
= (info
->group
[i
].ofs
* width
) / info
->num_chars
;
1381 ww
= (info
->group
[i
].len
* width
) / info
->num_chars
;
1383 hwnd
= CreateWindowW( szEdit
, NULL
, style
, wx
, 0, ww
, height
,
1384 info
->hwnd
, NULL
, NULL
, NULL
);
1387 ERR("failed to create mask edit sub window\n");
1391 SendMessageW( hwnd
, EM_LIMITTEXT
, info
->group
[i
].len
, 0 );
1393 msi_dialog_set_font( info
->dialog
, hwnd
,
1394 font
?font
:info
->dialog
->default_font
);
1395 info
->group
[i
].hwnd
= hwnd
;
1400 * office 2003 uses "73931<````=````=````=````=`````>@@@@@"
1401 * delphi 7 uses "<????-??????-??????-????>" and "<???-???>"
1402 * filemaker pro 7 uses "<^^^^=^^^^=^^^^=^^^^=^^^^=^^^^=^^^^^>"
1404 static UINT
msi_dialog_maskedit_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1406 LPWSTR font_mask
, val
= NULL
, font
;
1407 struct msi_maskedit_info
*info
= NULL
;
1408 UINT ret
= ERROR_SUCCESS
;
1409 msi_control
*control
;
1414 font_mask
= msi_get_deformatted_field( dialog
->package
, rec
, 10 );
1415 font
= msi_dialog_get_style( font_mask
, &mask
);
1418 ERR("mask template is empty\n");
1422 info
= msi_dialog_parse_groups( mask
);
1425 ERR("template %s is invalid\n", debugstr_w(mask
));
1429 info
->dialog
= dialog
;
1431 control
= msi_dialog_add_control( dialog
, rec
, szStatic
,
1432 SS_OWNERDRAW
| WS_GROUP
| WS_VISIBLE
);
1435 ERR("Failed to create maskedit container\n");
1436 ret
= ERROR_FUNCTION_FAILED
;
1439 SetWindowLongPtrW( control
->hwnd
, GWL_EXSTYLE
, WS_EX_CONTROLPARENT
);
1441 info
->hwnd
= control
->hwnd
;
1443 /* subclass the static control */
1444 info
->oldproc
= (WNDPROC
) SetWindowLongPtrW( info
->hwnd
, GWLP_WNDPROC
,
1445 (LONG_PTR
)MSIMaskedEdit_WndProc
);
1446 SetPropW( control
->hwnd
, szButtonData
, info
);
1448 prop
= MSI_RecordGetString( rec
, 9 );
1450 info
->prop
= strdupW( prop
);
1452 msi_maskedit_create_children( info
, font
);
1456 val
= msi_dup_property( dialog
->package
, prop
);
1459 msi_maskedit_set_text( info
, val
);
1465 if( ret
!= ERROR_SUCCESS
)
1467 msi_free( font_mask
);
1472 /******************** Progress Bar *****************************************/
1474 static UINT
msi_dialog_progress_bar( msi_dialog
*dialog
, MSIRECORD
*rec
)
1476 msi_dialog_add_control( dialog
, rec
, PROGRESS_CLASSW
, WS_VISIBLE
);
1477 return ERROR_SUCCESS
;
1480 /******************** Path Edit ********************************************/
1482 struct msi_pathedit_info
1485 msi_control
*control
;
1489 static LPWSTR
msi_get_window_text( HWND hwnd
)
1495 buf
= msi_alloc( sz
*sizeof(WCHAR
) );
1498 r
= GetWindowTextW( hwnd
, buf
, sz
);
1502 buf
= msi_realloc( buf
, sz
*sizeof(WCHAR
) );
1508 static void msi_dialog_update_pathedit( msi_dialog
*dialog
, msi_control
*control
)
1513 if (!control
&& !(control
= msi_dialog_find_control_by_type( dialog
, szPathEdit
)))
1516 indirect
= control
->attributes
& msidbControlAttributesIndirect
;
1517 prop
= msi_dialog_dup_property( dialog
, control
->property
, indirect
);
1518 path
= msi_dialog_dup_property( dialog
, prop
, TRUE
);
1520 SetWindowTextW( control
->hwnd
, path
);
1521 SendMessageW( control
->hwnd
, EM_SETSEL
, 0, -1 );
1527 /* FIXME: test when this should fail */
1528 static BOOL
msi_dialog_verify_path( LPWSTR path
)
1530 if ( !lstrlenW( path
) )
1533 if ( PathIsRelativeW( path
) )
1539 /* returns TRUE if the path is valid, FALSE otherwise */
1540 static BOOL
msi_dialog_onkillfocus( msi_dialog
*dialog
, msi_control
*control
)
1546 indirect
= control
->attributes
& msidbControlAttributesIndirect
;
1547 prop
= msi_dialog_dup_property( dialog
, control
->property
, indirect
);
1549 buf
= msi_get_window_text( control
->hwnd
);
1551 if ( !msi_dialog_verify_path( buf
) )
1553 /* FIXME: display an error message box */
1554 ERR("Invalid path %s\n", debugstr_w( buf
));
1556 SetFocus( control
->hwnd
);
1561 MSI_SetPropertyW( dialog
->package
, prop
, buf
);
1564 msi_dialog_update_pathedit( dialog
, control
);
1566 TRACE("edit %s contents changed, set %s\n", debugstr_w(control
->name
),
1575 static LRESULT WINAPI
MSIPathEdit_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1577 struct msi_pathedit_info
*info
= GetPropW(hWnd
, szButtonData
);
1580 TRACE("%p %04x %08x %08lx\n", hWnd
, msg
, wParam
, lParam
);
1582 if ( msg
== WM_KILLFOCUS
)
1584 /* if the path is invalid, don't handle this message */
1585 if ( !msi_dialog_onkillfocus( info
->dialog
, info
->control
) )
1589 r
= CallWindowProcW(info
->oldproc
, hWnd
, msg
, wParam
, lParam
);
1591 if ( msg
== WM_NCDESTROY
)
1594 RemovePropW( hWnd
, szButtonData
);
1600 static UINT
msi_dialog_pathedit_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1602 struct msi_pathedit_info
*info
;
1603 msi_control
*control
;
1606 info
= msi_alloc( sizeof *info
);
1608 return ERROR_FUNCTION_FAILED
;
1610 control
= msi_dialog_add_control( dialog
, rec
, szEdit
,
1611 WS_BORDER
| WS_TABSTOP
);
1612 control
->attributes
= MSI_RecordGetInteger( rec
, 8 );
1613 prop
= MSI_RecordGetString( rec
, 9 );
1614 control
->property
= msi_dialog_dup_property( dialog
, prop
, FALSE
);
1616 info
->dialog
= dialog
;
1617 info
->control
= control
;
1618 info
->oldproc
= (WNDPROC
) SetWindowLongPtrW( control
->hwnd
, GWLP_WNDPROC
,
1619 (LONG_PTR
)MSIPathEdit_WndProc
);
1620 SetPropW( control
->hwnd
, szButtonData
, info
);
1622 msi_dialog_update_pathedit( dialog
, control
);
1624 return ERROR_SUCCESS
;
1627 /* radio buttons are a bit different from normal controls */
1628 static UINT
msi_dialog_create_radiobutton( MSIRECORD
*rec
, LPVOID param
)
1630 radio_button_group_descr
*group
= (radio_button_group_descr
*)param
;
1631 msi_dialog
*dialog
= group
->dialog
;
1632 msi_control
*control
;
1633 LPCWSTR prop
, text
, name
;
1634 DWORD style
, attributes
= group
->attributes
;
1636 style
= WS_CHILD
| BS_AUTORADIOBUTTON
| BS_MULTILINE
| WS_TABSTOP
;
1637 name
= MSI_RecordGetString( rec
, 3 );
1638 text
= MSI_RecordGetString( rec
, 8 );
1639 if( attributes
& 1 )
1640 style
|= WS_VISIBLE
;
1641 if( ~attributes
& 2 )
1642 style
|= WS_DISABLED
;
1644 control
= msi_dialog_create_window( dialog
, rec
, 0, szButton
, name
, text
,
1645 style
, group
->parent
->hwnd
);
1647 return ERROR_FUNCTION_FAILED
;
1648 control
->handler
= msi_dialog_radiogroup_handler
;
1650 if (!lstrcmpW(control
->name
, group
->propval
))
1651 SendMessageW(control
->hwnd
, BM_SETCHECK
, BST_CHECKED
, 0);
1653 prop
= MSI_RecordGetString( rec
, 1 );
1655 control
->property
= strdupW( prop
);
1657 return ERROR_SUCCESS
;
1660 static UINT
msi_dialog_radiogroup_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1662 static const WCHAR query
[] = {
1663 'S','E','L','E','C','T',' ','*',' ',
1664 'F','R','O','M',' ','R','a','d','i','o','B','u','t','t','o','n',' ',
1665 'W','H','E','R','E',' ',
1666 '`','P','r','o','p','e','r','t','y','`',' ','=',' ','\'','%','s','\'',0};
1669 msi_control
*control
;
1670 MSIQUERY
*view
= NULL
;
1671 radio_button_group_descr group
;
1672 MSIPACKAGE
*package
= dialog
->package
;
1675 prop
= MSI_RecordGetString( rec
, 9 );
1677 TRACE("%p %p %s\n", dialog
, rec
, debugstr_w( prop
));
1679 /* Create parent group box to hold radio buttons */
1680 control
= msi_dialog_add_control( dialog
, rec
, szButton
, BS_OWNERDRAW
|WS_GROUP
);
1682 return ERROR_FUNCTION_FAILED
;
1684 oldproc
= (WNDPROC
) SetWindowLongPtrW( control
->hwnd
, GWLP_WNDPROC
,
1685 (LONG_PTR
)MSIRadioGroup_WndProc
);
1686 SetPropW(control
->hwnd
, szButtonData
, oldproc
);
1687 SetWindowLongPtrW( control
->hwnd
, GWL_EXSTYLE
, WS_EX_CONTROLPARENT
);
1690 control
->property
= strdupW( prop
);
1692 /* query the Radio Button table for all control in this group */
1693 r
= MSI_OpenQuery( package
->db
, &view
, query
, prop
);
1694 if( r
!= ERROR_SUCCESS
)
1696 ERR("query failed for dialog %s radio group %s\n",
1697 debugstr_w(dialog
->name
), debugstr_w(prop
));
1698 return ERROR_INVALID_PARAMETER
;
1701 group
.dialog
= dialog
;
1702 group
.parent
= control
;
1703 group
.attributes
= MSI_RecordGetInteger( rec
, 8 );
1704 group
.propval
= msi_dup_property( dialog
->package
, control
->property
);
1706 r
= MSI_IterateRecords( view
, 0, msi_dialog_create_radiobutton
, &group
);
1707 msiobj_release( &view
->hdr
);
1708 msi_free( group
.propval
);
1713 /******************** Selection Tree ***************************************/
1715 struct msi_selection_tree_info
1724 msi_seltree_sync_item_state( HWND hwnd
, MSIFEATURE
*feature
, HTREEITEM hItem
)
1727 DWORD index
= feature
->Action
;
1729 TRACE("Feature %s -> %d %d %d\n", debugstr_w(feature
->Title
),
1730 feature
->Installed
, feature
->Action
, feature
->ActionRequest
);
1732 if (index
== INSTALLSTATE_UNKNOWN
)
1733 index
= INSTALLSTATE_ABSENT
;
1735 tvi
.mask
= TVIF_STATE
;
1737 tvi
.state
= INDEXTOSTATEIMAGEMASK( index
);
1738 tvi
.stateMask
= TVIS_STATEIMAGEMASK
;
1740 SendMessageW( hwnd
, TVM_SETITEMW
, 0, (LPARAM
) &tvi
);
1744 msi_seltree_popup_menu( HWND hwnd
, INT x
, INT y
)
1749 /* create a menu to display */
1750 hMenu
= CreatePopupMenu();
1752 /* FIXME: load strings from resources */
1753 AppendMenuA( hMenu
, MF_ENABLED
, INSTALLSTATE_LOCAL
, "Install feature locally");
1754 AppendMenuA( hMenu
, MF_GRAYED
, 0x1000, "Install entire feature");
1755 AppendMenuA( hMenu
, MF_ENABLED
, INSTALLSTATE_ADVERTISED
, "Install on demand");
1756 AppendMenuA( hMenu
, MF_ENABLED
, INSTALLSTATE_ABSENT
, "Don't install");
1757 r
= TrackPopupMenu( hMenu
, TPM_LEFTALIGN
| TPM_TOPALIGN
| TPM_RETURNCMD
,
1758 x
, y
, 0, hwnd
, NULL
);
1759 DestroyMenu( hMenu
);
1764 msi_seltree_feature_from_item( HWND hwnd
, HTREEITEM hItem
)
1768 /* get the feature from the item */
1769 memset( &tvi
, 0, sizeof tvi
);
1771 tvi
.mask
= TVIF_PARAM
| TVIF_HANDLE
;
1772 SendMessageW( hwnd
, TVM_GETITEMW
, 0, (LPARAM
) &tvi
);
1774 return (MSIFEATURE
*) tvi
.lParam
;
1778 msi_seltree_menu( HWND hwnd
, HTREEITEM hItem
)
1780 struct msi_selection_tree_info
*info
;
1781 MSIFEATURE
*feature
;
1782 MSIPACKAGE
*package
;
1790 info
= GetPropW(hwnd
, szButtonData
);
1791 package
= info
->dialog
->package
;
1793 feature
= msi_seltree_feature_from_item( hwnd
, hItem
);
1796 ERR("item %p feature was NULL\n", hItem
);
1800 /* get the item's rectangle to put the menu just below it */
1802 SendMessageW( hwnd
, TVM_GETITEMRECT
, 0, (LPARAM
) &u
.rc
);
1803 MapWindowPoints( hwnd
, NULL
, u
.pt
, 2 );
1805 r
= msi_seltree_popup_menu( hwnd
, u
.rc
.left
, u
.rc
.top
);
1809 case INSTALLSTATE_LOCAL
:
1810 case INSTALLSTATE_ADVERTISED
:
1811 case INSTALLSTATE_ABSENT
:
1812 msi_feature_set_state( feature
, r
);
1815 FIXME("select feature and all children\n");
1819 msi_seltree_sync_item_state( hwnd
, feature
, hItem
);
1820 ACTION_UpdateComponentStates( package
, feature
->Feature
);
1825 static MSIFEATURE
*msi_seltree_get_selected_feature( msi_control
*control
)
1827 struct msi_selection_tree_info
*info
= GetPropW(control
->hwnd
, szButtonData
);
1828 return msi_seltree_feature_from_item( control
->hwnd
, info
->selected
);
1831 static LRESULT WINAPI
1832 MSISelectionTree_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1834 struct msi_selection_tree_info
*info
;
1835 TVHITTESTINFO tvhti
;
1838 TRACE("%p %04x %08x %08lx\n", hWnd
, msg
, wParam
, lParam
);
1840 info
= GetPropW(hWnd
, szButtonData
);
1844 case WM_LBUTTONDOWN
:
1845 tvhti
.pt
.x
= (short)LOWORD( lParam
);
1846 tvhti
.pt
.y
= (short)HIWORD( lParam
);
1849 r
= CallWindowProcW(info
->oldproc
, hWnd
, TVM_HITTEST
, 0, (LPARAM
) &tvhti
);
1850 if (tvhti
.flags
& TVHT_ONITEMSTATEICON
)
1851 return msi_seltree_menu( hWnd
, tvhti
.hItem
);
1855 r
= CallWindowProcW(info
->oldproc
, hWnd
, msg
, wParam
, lParam
);
1861 RemovePropW( hWnd
, szButtonData
);
1868 msi_seltree_add_child_features( MSIPACKAGE
*package
, HWND hwnd
,
1869 LPCWSTR parent
, HTREEITEM hParent
)
1871 struct msi_selection_tree_info
*info
= GetPropW( hwnd
, szButtonData
);
1872 MSIFEATURE
*feature
;
1873 TVINSERTSTRUCTW tvis
;
1874 HTREEITEM hitem
, hfirst
= NULL
;
1876 LIST_FOR_EACH_ENTRY( feature
, &package
->features
, MSIFEATURE
, entry
)
1878 if ( lstrcmpW( parent
, feature
->Feature_Parent
) )
1881 if ( !feature
->Title
)
1884 if ( !feature
->Display
)
1887 memset( &tvis
, 0, sizeof tvis
);
1888 tvis
.hParent
= hParent
;
1889 tvis
.hInsertAfter
= TVI_LAST
;
1890 tvis
.u
.item
.mask
= TVIF_TEXT
| TVIF_PARAM
;
1891 tvis
.u
.item
.pszText
= feature
->Title
;
1892 tvis
.u
.item
.lParam
= (LPARAM
) feature
;
1894 hitem
= (HTREEITEM
) SendMessageW( hwnd
, TVM_INSERTITEMW
, 0, (LPARAM
) &tvis
);
1901 msi_seltree_sync_item_state( hwnd
, feature
, hitem
);
1902 msi_seltree_add_child_features( package
, hwnd
,
1903 feature
->Feature
, hitem
);
1905 /* the node is expanded if Display is odd */
1906 if ( feature
->Display
% 2 != 0 )
1907 SendMessageW( hwnd
, TVM_EXPAND
, TVE_EXPAND
, (LPARAM
) hitem
);
1910 /* select the first item */
1911 SendMessageW( hwnd
, TVM_SELECTITEM
, TVGN_CARET
| TVGN_DROPHILITE
, (LPARAM
) hfirst
);
1912 info
->selected
= hfirst
;
1915 static void msi_seltree_create_imagelist( HWND hwnd
)
1917 const int bm_width
= 32, bm_height
= 16, bm_count
= 3;
1918 const int bm_resource
= 0x1001;
1923 himl
= ImageList_Create( bm_width
, bm_height
, FALSE
, 4, 0 );
1926 ERR("failed to create image list\n");
1930 for (i
=0; i
<bm_count
; i
++)
1932 hbmp
= LoadBitmapW( msi_hInstance
, MAKEINTRESOURCEW(i
+bm_resource
) );
1935 ERR("failed to load bitmap %d\n", i
);
1940 * Add a dummy bitmap at offset zero because the treeview
1941 * can't use it as a state mask (zero means no user state).
1944 ImageList_Add( himl
, hbmp
, NULL
);
1946 ImageList_Add( himl
, hbmp
, NULL
);
1949 SendMessageW( hwnd
, TVM_SETIMAGELIST
, TVSIL_STATE
, (LPARAM
)himl
);
1952 static UINT
msi_dialog_seltree_handler( msi_dialog
*dialog
,
1953 msi_control
*control
, WPARAM param
)
1955 struct msi_selection_tree_info
*info
= GetPropW( control
->hwnd
, szButtonData
);
1956 LPNMTREEVIEWW tv
= (LPNMTREEVIEWW
)param
;
1957 MSIRECORD
*row
, *rec
;
1960 UINT r
= ERROR_SUCCESS
;
1962 static const WCHAR select
[] = {
1963 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
1964 '`','F','e','a','t','u','r','e','`',' ','W','H','E','R','E',' ',
1965 '`','T','i','t','l','e','`',' ','=',' ','\'','%','s','\'',0
1968 if (tv
->hdr
.code
!= TVN_SELCHANGINGW
)
1969 return ERROR_SUCCESS
;
1971 info
->selected
= tv
->itemNew
.hItem
;
1973 row
= MSI_QueryGetRecord( dialog
->package
->db
, select
, tv
->itemNew
.pszText
);
1975 return ERROR_FUNCTION_FAILED
;
1977 rec
= MSI_CreateRecord( 1 );
1979 MSI_RecordSetStringW( rec
, 1, MSI_RecordGetString( row
, 4 ) );
1980 ControlEvent_FireSubscribedEvent( dialog
->package
, szSelectionDescription
, rec
);
1982 dir
= MSI_RecordGetString( row
, 7 );
1983 folder
= get_loaded_folder( dialog
->package
, dir
);
1986 r
= ERROR_FUNCTION_FAILED
;
1990 MSI_RecordSetStringW( rec
, 1, folder
->ResolvedTarget
);
1991 ControlEvent_FireSubscribedEvent( dialog
->package
, szSelectionPath
, rec
);
1994 msiobj_release(&row
->hdr
);
1995 msiobj_release(&rec
->hdr
);
2000 static UINT
msi_dialog_selection_tree( msi_dialog
*dialog
, MSIRECORD
*rec
)
2002 msi_control
*control
;
2004 MSIPACKAGE
*package
= dialog
->package
;
2006 struct msi_selection_tree_info
*info
;
2008 info
= msi_alloc( sizeof *info
);
2010 return ERROR_FUNCTION_FAILED
;
2012 /* create the treeview control */
2013 style
= TVS_HASLINES
| TVS_HASBUTTONS
| TVS_LINESATROOT
;
2014 style
|= WS_GROUP
| WS_VSCROLL
;
2015 control
= msi_dialog_add_control( dialog
, rec
, WC_TREEVIEWW
, style
);
2019 return ERROR_FUNCTION_FAILED
;
2022 control
->handler
= msi_dialog_seltree_handler
;
2023 control
->attributes
= MSI_RecordGetInteger( rec
, 8 );
2024 prop
= MSI_RecordGetString( rec
, 9 );
2025 control
->property
= msi_dialog_dup_property( dialog
, prop
, FALSE
);
2028 info
->dialog
= dialog
;
2029 info
->hwnd
= control
->hwnd
;
2030 info
->oldproc
= (WNDPROC
) SetWindowLongPtrW( control
->hwnd
, GWLP_WNDPROC
,
2031 (LONG_PTR
)MSISelectionTree_WndProc
);
2032 SetPropW( control
->hwnd
, szButtonData
, info
);
2034 ControlEvent_SubscribeToEvent( dialog
->package
, dialog
,
2035 szSelectionPath
, control
->name
, szProperty
);
2038 msi_seltree_create_imagelist( control
->hwnd
);
2039 msi_seltree_add_child_features( package
, control
->hwnd
, NULL
, NULL
);
2041 return ERROR_SUCCESS
;
2044 /******************** Group Box ***************************************/
2046 static UINT
msi_dialog_group_box( msi_dialog
*dialog
, MSIRECORD
*rec
)
2048 msi_control
*control
;
2051 style
= BS_GROUPBOX
| WS_CHILD
| WS_GROUP
;
2052 control
= msi_dialog_add_control( dialog
, rec
, WC_BUTTONW
, style
);
2054 return ERROR_FUNCTION_FAILED
;
2056 return ERROR_SUCCESS
;
2059 /******************** List Box ***************************************/
2061 struct msi_listbox_item
2067 struct msi_listbox_info
2073 struct msi_listbox_item
*items
;
2076 static LRESULT WINAPI
MSIListBox_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
2078 struct msi_listbox_info
*info
;
2082 TRACE("%p %04x %08x %08lx\n", hWnd
, msg
, wParam
, lParam
);
2084 info
= GetPropW( hWnd
, szButtonData
);
2088 r
= CallWindowProcW( info
->oldproc
, hWnd
, msg
, wParam
, lParam
);
2093 for (j
= 0; j
< info
->num_items
; j
++)
2095 msi_free( info
->items
[j
].property
);
2096 msi_free( info
->items
[j
].value
);
2098 msi_free( info
->items
);
2100 RemovePropW( hWnd
, szButtonData
);
2107 static UINT
msi_listbox_add_item( MSIRECORD
*rec
, LPVOID param
)
2109 struct msi_listbox_info
*info
= param
;
2110 struct msi_listbox_item
*item
;
2111 LPCWSTR property
, value
, text
;
2112 static int index
= 0;
2114 item
= &info
->items
[index
++];
2115 property
= MSI_RecordGetString( rec
, 1 );
2116 value
= MSI_RecordGetString( rec
, 3 );
2117 text
= MSI_RecordGetString( rec
, 4 );
2119 item
->property
= strdupW( property
);
2120 item
->value
= strdupW( value
);
2122 SendMessageW( info
->hwnd
, LB_ADDSTRING
, 0, (LPARAM
)text
);
2124 return ERROR_SUCCESS
;
2127 static UINT
msi_listbox_add_items( struct msi_listbox_info
*info
)
2130 MSIQUERY
*view
= NULL
;
2133 static const WCHAR query
[] = {
2134 'S','E','L','E','C','T',' ','*',' ',
2135 'F','R','O','M',' ','`','L','i','s','t','B','o','x','`',' ',
2136 'O','R','D','E','R',' ','B','Y',' ','`','O','r','d','e','r','`',0
2139 r
= MSI_OpenQuery( info
->dialog
->package
->db
, &view
, query
);
2140 if ( r
!= ERROR_SUCCESS
)
2143 /* just get the number of records */
2144 r
= MSI_IterateRecords( view
, &count
, NULL
, NULL
);
2146 info
->num_items
= count
;
2147 info
->items
= msi_alloc( sizeof(*info
->items
) * count
);
2149 r
= MSI_IterateRecords( view
, NULL
, msi_listbox_add_item
, info
);
2150 msiobj_release( &view
->hdr
);
2155 static UINT
msi_dialog_listbox_handler( msi_dialog
*dialog
,
2156 msi_control
*control
, WPARAM param
)
2158 struct msi_listbox_info
*info
;
2161 if( HIWORD(param
) != LBN_SELCHANGE
)
2162 return ERROR_SUCCESS
;
2164 info
= GetPropW( control
->hwnd
, szButtonData
);
2165 index
= SendMessageW( control
->hwnd
, LB_GETCURSEL
, 0, 0 );
2167 MSI_SetPropertyW( info
->dialog
->package
,
2168 info
->items
[index
].property
, info
->items
[index
].value
);
2169 msi_dialog_evaluate_control_conditions( info
->dialog
);
2171 return ERROR_SUCCESS
;
2174 static UINT
msi_dialog_list_box( msi_dialog
*dialog
, MSIRECORD
*rec
)
2176 struct msi_listbox_info
*info
;
2177 msi_control
*control
;
2180 info
= msi_alloc( sizeof *info
);
2182 return ERROR_FUNCTION_FAILED
;
2184 style
= WS_TABSTOP
| WS_GROUP
| WS_CHILD
| LBS_STANDARD
;
2185 control
= msi_dialog_add_control( dialog
, rec
, WC_LISTBOXW
, style
);
2187 return ERROR_FUNCTION_FAILED
;
2189 control
->handler
= msi_dialog_listbox_handler
;
2192 info
->dialog
= dialog
;
2193 info
->hwnd
= control
->hwnd
;
2195 info
->oldproc
= (WNDPROC
)SetWindowLongPtrW( control
->hwnd
, GWLP_WNDPROC
,
2196 (LONG_PTR
)MSIListBox_WndProc
);
2197 SetPropW( control
->hwnd
, szButtonData
, info
);
2199 msi_listbox_add_items( info
);
2201 return ERROR_SUCCESS
;
2204 /******************** Directory Combo ***************************************/
2206 static void msi_dialog_update_directory_combo( msi_dialog
*dialog
, msi_control
*control
)
2211 if (!control
&& !(control
= msi_dialog_find_control_by_type( dialog
, szDirectoryCombo
)))
2214 indirect
= control
->attributes
& msidbControlAttributesIndirect
;
2215 prop
= msi_dialog_dup_property( dialog
, control
->property
, indirect
);
2216 path
= msi_dialog_dup_property( dialog
, prop
, TRUE
);
2218 PathStripPathW( path
);
2219 PathRemoveBackslashW( path
);
2221 SendMessageW( control
->hwnd
, CB_INSERTSTRING
, 0, (LPARAM
)path
);
2222 SendMessageW( control
->hwnd
, CB_SETCURSEL
, 0, 0 );
2228 static UINT
msi_dialog_directory_combo( msi_dialog
*dialog
, MSIRECORD
*rec
)
2230 msi_control
*control
;
2234 /* FIXME: use CBS_OWNERDRAWFIXED and add owner draw code */
2235 style
= CBS_DROPDOWNLIST
| CBS_HASSTRINGS
| WS_CHILD
|
2236 WS_GROUP
| WS_TABSTOP
| WS_VSCROLL
;
2237 control
= msi_dialog_add_control( dialog
, rec
, WC_COMBOBOXW
, style
);
2239 return ERROR_FUNCTION_FAILED
;
2241 control
->attributes
= MSI_RecordGetInteger( rec
, 8 );
2242 prop
= MSI_RecordGetString( rec
, 9 );
2243 control
->property
= msi_dialog_dup_property( dialog
, prop
, FALSE
);
2245 msi_dialog_update_directory_combo( dialog
, control
);
2247 return ERROR_SUCCESS
;
2250 /******************** Directory List ***************************************/
2252 static void msi_dialog_update_directory_list( msi_dialog
*dialog
, msi_control
*control
)
2254 WCHAR dir_spec
[MAX_PATH
];
2255 WIN32_FIND_DATAW wfd
;
2261 static const WCHAR asterisk
[] = {'*',0};
2262 static const WCHAR dot
[] = {'.',0};
2263 static const WCHAR dotdot
[] = {'.','.',0};
2265 if (!control
&& !(control
= msi_dialog_find_control_by_type( dialog
, szDirectoryList
)))
2268 /* clear the list-view */
2269 SendMessageW( control
->hwnd
, LVM_DELETEALLITEMS
, 0, 0 );
2271 indirect
= control
->attributes
& msidbControlAttributesIndirect
;
2272 prop
= msi_dialog_dup_property( dialog
, control
->property
, indirect
);
2273 path
= msi_dialog_dup_property( dialog
, prop
, TRUE
);
2275 lstrcpyW( dir_spec
, path
);
2276 lstrcatW( dir_spec
, asterisk
);
2278 file
= FindFirstFileW( dir_spec
, &wfd
);
2279 if ( file
== INVALID_HANDLE_VALUE
)
2284 if ( wfd
.dwFileAttributes
!= FILE_ATTRIBUTE_DIRECTORY
)
2287 if ( !lstrcmpW( wfd
.cFileName
, dot
) || !lstrcmpW( wfd
.cFileName
, dotdot
) )
2290 item
.mask
= LVIF_TEXT
;
2291 item
.cchTextMax
= MAX_PATH
;
2294 item
.pszText
= wfd
.cFileName
;
2296 SendMessageW( control
->hwnd
, LVM_INSERTITEMW
, 0, (LPARAM
)&item
);
2297 } while ( FindNextFileW( file
, &wfd
) );
2304 UINT
msi_dialog_directorylist_up( msi_dialog
*dialog
)
2306 msi_control
*control
;
2307 LPWSTR prop
, path
, ptr
;
2310 control
= msi_dialog_find_control_by_type( dialog
, szDirectoryList
);
2311 indirect
= control
->attributes
& msidbControlAttributesIndirect
;
2312 prop
= msi_dialog_dup_property( dialog
, control
->property
, indirect
);
2313 path
= msi_dialog_dup_property( dialog
, prop
, TRUE
);
2315 /* strip off the last directory */
2316 ptr
= PathFindFileNameW( path
);
2317 if (ptr
!= path
) *(ptr
- 1) = '\0';
2318 PathAddBackslashW( path
);
2320 MSI_SetPropertyW( dialog
->package
, prop
, path
);
2322 msi_dialog_update_directory_list( dialog
, NULL
);
2323 msi_dialog_update_directory_combo( dialog
, NULL
);
2324 msi_dialog_update_pathedit( dialog
, NULL
);
2329 return ERROR_SUCCESS
;
2332 static UINT
msi_dialog_dirlist_handler( msi_dialog
*dialog
,
2333 msi_control
*control
, WPARAM param
)
2335 LPNMHDR nmhdr
= (LPNMHDR
)param
;
2336 WCHAR new_path
[MAX_PATH
];
2337 WCHAR text
[MAX_PATH
];
2343 static const WCHAR backslash
[] = {'\\',0};
2345 if (nmhdr
->code
!= LVN_ITEMACTIVATE
)
2346 return ERROR_SUCCESS
;
2348 index
= SendMessageW( control
->hwnd
, LVM_GETNEXTITEM
, -1, LVNI_SELECTED
);
2351 ERR("No list-view item selected!\n");
2352 return ERROR_FUNCTION_FAILED
;
2356 item
.pszText
= text
;
2357 item
.cchTextMax
= MAX_PATH
;
2358 SendMessageW( control
->hwnd
, LVM_GETITEMTEXTW
, index
, (LPARAM
)&item
);
2360 indirect
= control
->attributes
& msidbControlAttributesIndirect
;
2361 prop
= msi_dialog_dup_property( dialog
, control
->property
, indirect
);
2362 path
= msi_dialog_dup_property( dialog
, prop
, TRUE
);
2364 lstrcpyW( new_path
, path
);
2365 lstrcatW( new_path
, text
);
2366 lstrcatW( new_path
, backslash
);
2368 MSI_SetPropertyW( dialog
->package
, prop
, new_path
);
2370 msi_dialog_update_directory_list( dialog
, NULL
);
2371 msi_dialog_update_directory_combo( dialog
, NULL
);
2372 msi_dialog_update_pathedit( dialog
, NULL
);
2376 return ERROR_SUCCESS
;
2379 static UINT
msi_dialog_directory_list( msi_dialog
*dialog
, MSIRECORD
*rec
)
2381 msi_control
*control
;
2385 style
= LVS_LIST
| WS_VSCROLL
| LVS_SHAREIMAGELISTS
|
2386 LVS_AUTOARRANGE
| LVS_SINGLESEL
| WS_BORDER
|
2387 LVS_SORTASCENDING
| WS_CHILD
| WS_GROUP
| WS_TABSTOP
;
2388 control
= msi_dialog_add_control( dialog
, rec
, WC_LISTVIEWW
, style
);
2390 return ERROR_FUNCTION_FAILED
;
2392 control
->attributes
= MSI_RecordGetInteger( rec
, 8 );
2393 control
->handler
= msi_dialog_dirlist_handler
;
2394 prop
= MSI_RecordGetString( rec
, 9 );
2395 control
->property
= msi_dialog_dup_property( dialog
, prop
, FALSE
);
2397 /* double click to activate an item in the list */
2398 SendMessageW( control
->hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
,
2399 0, LVS_EX_TWOCLICKACTIVATE
);
2401 msi_dialog_update_directory_list( dialog
, control
);
2403 return ERROR_SUCCESS
;
2406 /******************** VolumeCost List ***************************************/
2408 static BOOL
str_is_number( LPCWSTR str
)
2412 for (i
= 0; i
< lstrlenW( str
); i
++)
2413 if (!isdigitW(str
[i
]))
2419 static const WCHAR column_keys
[][80] =
2421 {'V','o','l','u','m','e','C','o','s','t','V','o','l','u','m','e',0},
2422 {'V','o','l','u','m','e','C','o','s','t','S','i','z','e',0},
2423 {'V','o','l','u','m','e','C','o','s','t','A','v','a','i','l','a','b','l','e',0},
2424 {'V','o','l','u','m','e','C','o','s','t','R','e','q','u','i','r','e','d',0},
2425 {'V','o','l','u','m','e','C','o','s','t','D','i','f','f','e','r','e','n','c','e',0}
2428 static void msi_dialog_vcl_add_columns( msi_dialog
*dialog
, msi_control
*control
, MSIRECORD
*rec
)
2430 LPCWSTR text
= MSI_RecordGetString( rec
, 10 );
2431 LPCWSTR begin
= text
, end
;
2436 static const WCHAR zero
[] = {'0',0};
2437 static const WCHAR negative
[] = {'-',0};
2439 while ((begin
= strchrW( begin
, '{' )) && count
< 5)
2441 if (!(end
= strchrW( begin
, '}' )))
2444 lstrcpynW( num
, begin
+ 1, end
- begin
);
2445 begin
+= end
- begin
+ 1;
2447 /* empty braces or '0' hides the column */
2448 if ( !num
[0] || !lstrcmpW( num
, zero
) )
2454 /* the width must be a positive number
2455 * if a width is invalid, all remaining columns are hidden
2457 if ( !strncmpW( num
, negative
, 1 ) || !str_is_number( num
) )
2460 ZeroMemory( &lvc
, sizeof(lvc
) );
2461 lvc
.mask
= LVCF_TEXT
| LVCF_WIDTH
| LVCF_SUBITEM
;
2462 lvc
.cx
= atolW( num
);
2463 lvc
.pszText
= msi_dialog_get_uitext( dialog
, column_keys
[count
] );
2465 SendMessageW( control
->hwnd
, LVM_INSERTCOLUMNW
, count
++, (LPARAM
)&lvc
);
2466 msi_free( lvc
.pszText
);
2470 static void msi_dialog_vcl_add_drives( msi_dialog
*dialog
, msi_control
*control
)
2472 ULARGE_INTEGER total
, free
;
2473 WCHAR size_text
[MAX_PATH
];
2479 size
= GetLogicalDriveStringsW( 0, NULL
);
2480 if ( !size
) return;
2482 drives
= msi_alloc( (size
+ 1) * sizeof(WCHAR
) );
2483 if ( !drives
) return;
2485 GetLogicalDriveStringsW( size
, drives
);
2490 lvitem
.mask
= LVIF_TEXT
;
2492 lvitem
.iSubItem
= 0;
2493 lvitem
.pszText
= ptr
;
2494 lvitem
.cchTextMax
= lstrlenW(ptr
) + 1;
2495 SendMessageW( control
->hwnd
, LVM_INSERTITEMW
, 0, (LPARAM
)&lvitem
);
2497 GetDiskFreeSpaceExW(ptr
, &free
, &total
, NULL
);
2499 StrFormatByteSizeW(total
.QuadPart
, size_text
, MAX_PATH
);
2500 lvitem
.iSubItem
= 1;
2501 lvitem
.pszText
= size_text
;
2502 lvitem
.cchTextMax
= lstrlenW(size_text
) + 1;
2503 SendMessageW( control
->hwnd
, LVM_SETITEMW
, 0, (LPARAM
)&lvitem
);
2505 StrFormatByteSizeW(free
.QuadPart
, size_text
, MAX_PATH
);
2506 lvitem
.iSubItem
= 2;
2507 lvitem
.pszText
= size_text
;
2508 lvitem
.cchTextMax
= lstrlenW(size_text
) + 1;
2509 SendMessageW( control
->hwnd
, LVM_SETITEMW
, 0, (LPARAM
)&lvitem
);
2511 ptr
+= lstrlenW(ptr
) + 1;
2518 static UINT
msi_dialog_volumecost_list( msi_dialog
*dialog
, MSIRECORD
*rec
)
2520 msi_control
*control
;
2523 style
= LVS_REPORT
| WS_VSCROLL
| WS_HSCROLL
| LVS_SHAREIMAGELISTS
|
2524 LVS_AUTOARRANGE
| LVS_SINGLESEL
| WS_BORDER
|
2525 WS_CHILD
| WS_TABSTOP
| WS_GROUP
;
2526 control
= msi_dialog_add_control( dialog
, rec
, WC_LISTVIEWW
, style
);
2528 return ERROR_FUNCTION_FAILED
;
2530 msi_dialog_vcl_add_columns( dialog
, control
, rec
);
2531 msi_dialog_vcl_add_drives( dialog
, control
);
2533 return ERROR_SUCCESS
;
2536 static const struct control_handler msi_dialog_handler
[] =
2538 { szText
, msi_dialog_text_control
},
2539 { szPushButton
, msi_dialog_button_control
},
2540 { szLine
, msi_dialog_line_control
},
2541 { szBitmap
, msi_dialog_bitmap_control
},
2542 { szCheckBox
, msi_dialog_checkbox_control
},
2543 { szScrollableText
, msi_dialog_scrolltext_control
},
2544 { szComboBox
, msi_dialog_combo_control
},
2545 { szEdit
, msi_dialog_edit_control
},
2546 { szMaskedEdit
, msi_dialog_maskedit_control
},
2547 { szPathEdit
, msi_dialog_pathedit_control
},
2548 { szProgressBar
, msi_dialog_progress_bar
},
2549 { szRadioButtonGroup
, msi_dialog_radiogroup_control
},
2550 { szIcon
, msi_dialog_icon_control
},
2551 { szSelectionTree
, msi_dialog_selection_tree
},
2552 { szGroupBox
, msi_dialog_group_box
},
2553 { szListBox
, msi_dialog_list_box
},
2554 { szDirectoryCombo
, msi_dialog_directory_combo
},
2555 { szDirectoryList
, msi_dialog_directory_list
},
2556 { szVolumeCostList
, msi_dialog_volumecost_list
},
2559 #define NUM_CONTROL_TYPES (sizeof msi_dialog_handler/sizeof msi_dialog_handler[0])
2561 static UINT
msi_dialog_create_controls( MSIRECORD
*rec
, LPVOID param
)
2563 msi_dialog
*dialog
= param
;
2564 LPCWSTR control_type
;
2567 /* find and call the function that can create this type of control */
2568 control_type
= MSI_RecordGetString( rec
, 3 );
2569 for( i
=0; i
<NUM_CONTROL_TYPES
; i
++ )
2570 if (!strcmpiW( msi_dialog_handler
[i
].control_type
, control_type
))
2572 if( i
!= NUM_CONTROL_TYPES
)
2573 msi_dialog_handler
[i
].func( dialog
, rec
);
2575 ERR("no handler for element type %s\n", debugstr_w(control_type
));
2577 return ERROR_SUCCESS
;
2580 static UINT
msi_dialog_fill_controls( msi_dialog
*dialog
)
2582 static const WCHAR query
[] = {
2583 'S','E','L','E','C','T',' ','*',' ',
2584 'F','R','O','M',' ','C','o','n','t','r','o','l',' ',
2585 'W','H','E','R','E',' ',
2586 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',0};
2588 MSIQUERY
*view
= NULL
;
2589 MSIPACKAGE
*package
= dialog
->package
;
2591 TRACE("%p %s\n", dialog
, debugstr_w(dialog
->name
) );
2593 /* query the Control table for all the elements of the control */
2594 r
= MSI_OpenQuery( package
->db
, &view
, query
, dialog
->name
);
2595 if( r
!= ERROR_SUCCESS
)
2597 ERR("query failed for dialog %s\n", debugstr_w(dialog
->name
));
2598 return ERROR_INVALID_PARAMETER
;
2601 r
= MSI_IterateRecords( view
, 0, msi_dialog_create_controls
, dialog
);
2602 msiobj_release( &view
->hdr
);
2607 static UINT
msi_dialog_set_control_condition( MSIRECORD
*rec
, LPVOID param
)
2609 static const WCHAR szHide
[] = { 'H','i','d','e',0 };
2610 static const WCHAR szShow
[] = { 'S','h','o','w',0 };
2611 static const WCHAR szDisable
[] = { 'D','i','s','a','b','l','e',0 };
2612 static const WCHAR szEnable
[] = { 'E','n','a','b','l','e',0 };
2613 msi_dialog
*dialog
= param
;
2614 msi_control
*control
;
2615 LPCWSTR name
, action
, condition
;
2618 name
= MSI_RecordGetString( rec
, 2 );
2619 action
= MSI_RecordGetString( rec
, 3 );
2620 condition
= MSI_RecordGetString( rec
, 4 );
2621 r
= MSI_EvaluateConditionW( dialog
->package
, condition
);
2622 control
= msi_dialog_find_control( dialog
, name
);
2623 if( r
== MSICONDITION_TRUE
&& control
)
2625 TRACE("%s control %s\n", debugstr_w(action
), debugstr_w(name
));
2627 /* FIXME: case sensitive? */
2628 if(!lstrcmpW(action
, szHide
))
2629 ShowWindow(control
->hwnd
, SW_HIDE
);
2630 else if(!strcmpW(action
, szShow
))
2631 ShowWindow(control
->hwnd
, SW_SHOW
);
2632 else if(!strcmpW(action
, szDisable
))
2633 EnableWindow(control
->hwnd
, FALSE
);
2634 else if(!strcmpW(action
, szEnable
))
2635 EnableWindow(control
->hwnd
, TRUE
);
2637 FIXME("Unhandled action %s\n", debugstr_w(action
));
2640 return ERROR_SUCCESS
;
2643 static UINT
msi_dialog_evaluate_control_conditions( msi_dialog
*dialog
)
2645 static const WCHAR query
[] = {
2646 'S','E','L','E','C','T',' ','*',' ',
2647 'F','R','O','M',' ',
2648 'C','o','n','t','r','o','l','C','o','n','d','i','t','i','o','n',' ',
2649 'W','H','E','R','E',' ',
2650 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',0
2653 MSIQUERY
*view
= NULL
;
2654 MSIPACKAGE
*package
= dialog
->package
;
2656 TRACE("%p %s\n", dialog
, debugstr_w(dialog
->name
) );
2658 /* query the Control table for all the elements of the control */
2659 r
= MSI_OpenQuery( package
->db
, &view
, query
, dialog
->name
);
2660 if( r
!= ERROR_SUCCESS
)
2661 return ERROR_SUCCESS
;
2663 r
= MSI_IterateRecords( view
, 0, msi_dialog_set_control_condition
, dialog
);
2664 msiobj_release( &view
->hdr
);
2669 UINT
msi_dialog_reset( msi_dialog
*dialog
)
2671 /* FIXME: should restore the original values of any properties we changed */
2672 return msi_dialog_evaluate_control_conditions( dialog
);
2675 /* figure out the height of 10 point MS Sans Serif */
2676 static INT
msi_dialog_get_sans_serif_height( HWND hwnd
)
2678 static const WCHAR szSansSerif
[] = {
2679 'M','S',' ','S','a','n','s',' ','S','e','r','i','f',0 };
2684 HFONT hFont
, hOldFont
;
2687 hdc
= GetDC( hwnd
);
2690 memset( &lf
, 0, sizeof lf
);
2691 lf
.lfHeight
= MulDiv(10, GetDeviceCaps(hdc
, LOGPIXELSY
), 72);
2692 strcpyW( lf
.lfFaceName
, szSansSerif
);
2693 hFont
= CreateFontIndirectW(&lf
);
2696 hOldFont
= SelectObject( hdc
, hFont
);
2697 r
= GetTextMetricsW( hdc
, &tm
);
2699 height
= tm
.tmHeight
;
2700 SelectObject( hdc
, hOldFont
);
2701 DeleteObject( hFont
);
2703 ReleaseDC( hwnd
, hdc
);
2708 /* fetch the associated record from the Dialog table */
2709 static MSIRECORD
*msi_get_dialog_record( msi_dialog
*dialog
)
2711 static const WCHAR query
[] = {
2712 'S','E','L','E','C','T',' ','*',' ',
2713 'F','R','O','M',' ','D','i','a','l','o','g',' ',
2714 'W','H','E','R','E',' ',
2715 '`','D','i','a','l','o','g','`',' ','=',' ','\'','%','s','\'',0};
2716 MSIPACKAGE
*package
= dialog
->package
;
2717 MSIRECORD
*rec
= NULL
;
2719 TRACE("%p %s\n", dialog
, debugstr_w(dialog
->name
) );
2721 rec
= MSI_QueryGetRecord( package
->db
, query
, dialog
->name
);
2723 ERR("query failed for dialog %s\n", debugstr_w(dialog
->name
));
2728 static void msi_dialog_adjust_dialog_pos( msi_dialog
*dialog
, MSIRECORD
*rec
, LPRECT pos
)
2730 static const WCHAR szScreenX
[] = {'S','c','r','e','e','n','X',0};
2731 static const WCHAR szScreenY
[] = {'S','c','r','e','e','n','Y',0};
2738 center
.x
= MSI_RecordGetInteger( rec
, 2 );
2739 center
.y
= MSI_RecordGetInteger( rec
, 3 );
2741 sz
.cx
= MSI_RecordGetInteger( rec
, 4 );
2742 sz
.cy
= MSI_RecordGetInteger( rec
, 5 );
2744 sz
.cx
= msi_dialog_scale_unit( dialog
, sz
.cx
);
2745 sz
.cy
= msi_dialog_scale_unit( dialog
, sz
.cy
);
2747 xres
= msi_get_property_int( dialog
->package
, szScreenX
, 0 );
2748 yres
= msi_get_property_int( dialog
->package
, szScreenY
, 0 );
2750 center
.x
= MulDiv( center
.x
, xres
, 100 );
2751 center
.y
= MulDiv( center
.y
, yres
, 100 );
2753 /* turn the client pos into the window rectangle */
2754 if (dialog
->package
->center_x
&& dialog
->package
->center_y
)
2756 pos
->left
= dialog
->package
->center_x
- sz
.cx
/ 2.0;
2757 pos
->right
= pos
->left
+ sz
.cx
;
2758 pos
->top
= dialog
->package
->center_y
- sz
.cy
/ 2.0;
2759 pos
->bottom
= pos
->top
+ sz
.cy
;
2763 pos
->left
= center
.x
- sz
.cx
/2;
2764 pos
->right
= pos
->left
+ sz
.cx
;
2765 pos
->top
= center
.y
- sz
.cy
/2;
2766 pos
->bottom
= pos
->top
+ sz
.cy
;
2768 /* save the center */
2769 dialog
->package
->center_x
= center
.x
;
2770 dialog
->package
->center_y
= center
.y
;
2773 dialog
->size
.cx
= sz
.cx
;
2774 dialog
->size
.cy
= sz
.cy
;
2776 TRACE("%u %u %u %u\n", pos
->left
, pos
->top
, pos
->right
, pos
->bottom
);
2778 style
= GetWindowLongPtrW( dialog
->hwnd
, GWL_STYLE
);
2779 AdjustWindowRect( pos
, style
, FALSE
);
2782 static BOOL
msi_control_set_next( msi_control
*control
, msi_control
*next
)
2784 return SetWindowPos( next
->hwnd
, control
->hwnd
, 0, 0, 0, 0,
2785 SWP_NOMOVE
| SWP_NOOWNERZORDER
| SWP_NOREDRAW
|
2786 SWP_NOREPOSITION
| SWP_NOSENDCHANGING
| SWP_NOSIZE
);
2789 static UINT
msi_dialog_set_tab_order( msi_dialog
*dialog
)
2791 msi_control
*control
, *tab_next
;
2793 LIST_FOR_EACH_ENTRY( control
, &dialog
->controls
, msi_control
, entry
)
2795 tab_next
= msi_dialog_find_control( dialog
, control
->tabnext
);
2798 msi_control_set_next( control
, tab_next
);
2801 return ERROR_SUCCESS
;
2804 static void msi_dialog_set_first_control( msi_dialog
* dialog
, LPCWSTR name
)
2806 msi_control
*control
;
2808 control
= msi_dialog_find_control( dialog
, name
);
2810 dialog
->hWndFocus
= control
->hwnd
;
2812 dialog
->hWndFocus
= NULL
;
2815 static LRESULT
msi_dialog_oncreate( HWND hwnd
, LPCREATESTRUCTW cs
)
2817 static const WCHAR df
[] = {
2818 'D','e','f','a','u','l','t','U','I','F','o','n','t',0 };
2819 static const WCHAR dfv
[] = {
2820 'M','S',' ','S','h','e','l','l',' ','D','l','g',0 };
2821 msi_dialog
*dialog
= (msi_dialog
*) cs
->lpCreateParams
;
2822 MSIRECORD
*rec
= NULL
;
2823 LPWSTR title
= NULL
;
2826 TRACE("%p %p\n", dialog
, dialog
->package
);
2828 dialog
->hwnd
= hwnd
;
2829 SetWindowLongPtrW( hwnd
, GWLP_USERDATA
, (LONG_PTR
) dialog
);
2831 rec
= msi_get_dialog_record( dialog
);
2834 TRACE("No record found for dialog %s\n", debugstr_w(dialog
->name
));
2838 dialog
->scale
= msi_dialog_get_sans_serif_height(dialog
->hwnd
);
2840 msi_dialog_adjust_dialog_pos( dialog
, rec
, &pos
);
2842 dialog
->attributes
= MSI_RecordGetInteger( rec
, 6 );
2844 dialog
->default_font
= msi_dup_property( dialog
->package
, df
);
2845 if (!dialog
->default_font
)
2847 dialog
->default_font
= strdupW(dfv
);
2848 if (!dialog
->default_font
) return -1;
2851 title
= msi_get_deformatted_field( dialog
->package
, rec
, 7 );
2852 SetWindowTextW( hwnd
, title
);
2855 SetWindowPos( hwnd
, 0, pos
.left
, pos
.top
,
2856 pos
.right
- pos
.left
, pos
.bottom
- pos
.top
,
2857 SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_NOREDRAW
);
2859 msi_dialog_build_font_list( dialog
);
2860 msi_dialog_fill_controls( dialog
);
2861 msi_dialog_evaluate_control_conditions( dialog
);
2862 msi_dialog_set_tab_order( dialog
);
2863 msi_dialog_set_first_control( dialog
, MSI_RecordGetString( rec
, 8 ) );
2864 msiobj_release( &rec
->hdr
);
2869 static UINT
msi_dialog_send_event( msi_dialog
*dialog
, LPCWSTR event
, LPCWSTR arg
)
2871 LPWSTR event_fmt
= NULL
, arg_fmt
= NULL
;
2873 TRACE("Sending control event %s %s\n", debugstr_w(event
), debugstr_w(arg
));
2875 deformat_string( dialog
->package
, event
, &event_fmt
);
2876 deformat_string( dialog
->package
, arg
, &arg_fmt
);
2878 dialog
->event_handler( dialog
->package
, event_fmt
, arg_fmt
, dialog
);
2880 msi_free( event_fmt
);
2881 msi_free( arg_fmt
);
2883 return ERROR_SUCCESS
;
2886 static UINT
msi_dialog_set_property( msi_dialog
*dialog
, LPCWSTR event
, LPCWSTR arg
)
2888 static const WCHAR szNullArg
[] = { '{','}',0 };
2889 LPWSTR p
, prop
, arg_fmt
= NULL
;
2892 len
= strlenW(event
);
2893 prop
= msi_alloc( len
*sizeof(WCHAR
));
2894 strcpyW( prop
, &event
[1] );
2895 p
= strchrW( prop
, ']' );
2896 if( p
&& p
[1] == 0 )
2899 if( strcmpW( szNullArg
, arg
) )
2900 deformat_string( dialog
->package
, arg
, &arg_fmt
);
2901 MSI_SetPropertyW( dialog
->package
, prop
, arg_fmt
);
2902 msi_free( arg_fmt
);
2905 ERR("Badly formatted property string - what happens?\n");
2907 return ERROR_SUCCESS
;
2910 static UINT
msi_dialog_control_event( MSIRECORD
*rec
, LPVOID param
)
2912 msi_dialog
*dialog
= param
;
2913 LPCWSTR condition
, event
, arg
;
2916 condition
= MSI_RecordGetString( rec
, 5 );
2917 r
= MSI_EvaluateConditionW( dialog
->package
, condition
);
2918 if( r
== MSICONDITION_TRUE
|| r
== MSICONDITION_NONE
)
2920 event
= MSI_RecordGetString( rec
, 3 );
2921 arg
= MSI_RecordGetString( rec
, 4 );
2922 if( event
[0] == '[' )
2923 msi_dialog_set_property( dialog
, event
, arg
);
2925 msi_dialog_send_event( dialog
, event
, arg
);
2928 return ERROR_SUCCESS
;
2937 static UINT
add_rec_to_list( MSIRECORD
*rec
, LPVOID param
)
2939 struct rec_list
*add_rec
;
2940 struct list
*records
= (struct list
*)param
;
2942 msiobj_addref( &rec
->hdr
);
2944 add_rec
= msi_alloc( sizeof( *add_rec
) );
2947 msiobj_release( &rec
->hdr
);
2948 return ERROR_OUTOFMEMORY
;
2952 list_add_tail( records
, &add_rec
->entry
);
2953 return ERROR_SUCCESS
;
2956 static inline void remove_rec_from_list( struct rec_list
*rec_entry
)
2958 msiobj_release( &rec_entry
->rec
->hdr
);
2959 list_remove( &rec_entry
->entry
);
2960 msi_free( rec_entry
);
2963 static UINT
msi_dialog_button_handler( msi_dialog
*dialog
,
2964 msi_control
*control
, WPARAM param
)
2966 static const WCHAR query
[] = {
2967 'S','E','L','E','C','T',' ','*',' ',
2968 'F','R','O','M',' ','C','o','n','t','r','o','l','E','v','e','n','t',' ',
2969 'W','H','E','R','E',' ',
2970 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',' ',
2972 '`','C','o','n','t','r','o','l','_','`',' ','=',' ','\'','%','s','\'',' ',
2973 'O','R','D','E','R',' ','B','Y',' ','`','O','r','d','e','r','i','n','g','`',0
2975 MSIQUERY
*view
= NULL
;
2976 struct rec_list
*rec_entry
, *next
;
2980 if( HIWORD(param
) != BN_CLICKED
)
2981 return ERROR_SUCCESS
;
2983 list_init( &events
);
2985 r
= MSI_OpenQuery( dialog
->package
->db
, &view
, query
,
2986 dialog
->name
, control
->name
);
2987 if( r
!= ERROR_SUCCESS
)
2989 ERR("query failed\n");
2993 r
= MSI_IterateRecords( view
, 0, add_rec_to_list
, &events
);
2994 msiobj_release( &view
->hdr
);
2995 if (r
!= ERROR_SUCCESS
)
2998 /* handle all SetProperty events first */
2999 LIST_FOR_EACH_ENTRY_SAFE( rec_entry
, next
, &events
, struct rec_list
, entry
)
3001 LPCWSTR event
= MSI_RecordGetString( rec_entry
->rec
, 3 );
3003 if ( event
[0] != '[' )
3006 r
= msi_dialog_control_event( rec_entry
->rec
, dialog
);
3007 remove_rec_from_list( rec_entry
);
3009 if ( r
!= ERROR_SUCCESS
)
3013 /* handle all other events */
3014 LIST_FOR_EACH_ENTRY_SAFE( rec_entry
, next
, &events
, struct rec_list
, entry
)
3016 r
= msi_dialog_control_event( rec_entry
->rec
, dialog
);
3017 remove_rec_from_list( rec_entry
);
3019 if ( r
!= ERROR_SUCCESS
)
3024 LIST_FOR_EACH_ENTRY_SAFE( rec_entry
, next
, &events
, struct rec_list
, entry
)
3026 remove_rec_from_list( rec_entry
);
3032 static UINT
msi_dialog_get_checkbox_state( msi_dialog
*dialog
,
3033 msi_control
*control
)
3035 WCHAR state
[2] = { 0 };
3038 MSI_GetPropertyW( dialog
->package
, control
->property
, state
, &sz
);
3039 return state
[0] ? 1 : 0;
3042 static void msi_dialog_set_checkbox_state( msi_dialog
*dialog
,
3043 msi_control
*control
, UINT state
)
3045 static const WCHAR szState
[] = { '1', 0 };
3048 /* if uncheck then the property is set to NULL */
3051 MSI_SetPropertyW( dialog
->package
, control
->property
, NULL
);
3055 /* check for a custom state */
3056 if (control
->value
&& control
->value
[0])
3057 val
= control
->value
;
3061 MSI_SetPropertyW( dialog
->package
, control
->property
, val
);
3064 static void msi_dialog_checkbox_sync_state( msi_dialog
*dialog
,
3065 msi_control
*control
)
3069 state
= msi_dialog_get_checkbox_state( dialog
, control
);
3070 SendMessageW( control
->hwnd
, BM_SETCHECK
,
3071 state
? BST_CHECKED
: BST_UNCHECKED
, 0 );
3074 static UINT
msi_dialog_checkbox_handler( msi_dialog
*dialog
,
3075 msi_control
*control
, WPARAM param
)
3079 if( HIWORD(param
) != BN_CLICKED
)
3080 return ERROR_SUCCESS
;
3082 TRACE("clicked checkbox %s, set %s\n", debugstr_w(control
->name
),
3083 debugstr_w(control
->property
));
3085 state
= msi_dialog_get_checkbox_state( dialog
, control
);
3086 state
= state
? 0 : 1;
3087 msi_dialog_set_checkbox_state( dialog
, control
, state
);
3088 msi_dialog_checkbox_sync_state( dialog
, control
);
3090 return msi_dialog_button_handler( dialog
, control
, param
);
3093 static UINT
msi_dialog_edit_handler( msi_dialog
*dialog
,
3094 msi_control
*control
, WPARAM param
)
3098 if( HIWORD(param
) != EN_CHANGE
)
3099 return ERROR_SUCCESS
;
3101 TRACE("edit %s contents changed, set %s\n", debugstr_w(control
->name
),
3102 debugstr_w(control
->property
));
3104 buf
= msi_get_window_text( control
->hwnd
);
3105 MSI_SetPropertyW( dialog
->package
, control
->property
, buf
);
3109 return ERROR_SUCCESS
;
3112 static UINT
msi_dialog_radiogroup_handler( msi_dialog
*dialog
,
3113 msi_control
*control
, WPARAM param
)
3115 if( HIWORD(param
) != BN_CLICKED
)
3116 return ERROR_SUCCESS
;
3118 TRACE("clicked radio button %s, set %s\n", debugstr_w(control
->name
),
3119 debugstr_w(control
->property
));
3121 MSI_SetPropertyW( dialog
->package
, control
->property
, control
->name
);
3123 return msi_dialog_button_handler( dialog
, control
, param
);
3126 static LRESULT
msi_dialog_oncommand( msi_dialog
*dialog
, WPARAM param
, HWND hwnd
)
3128 msi_control
*control
= NULL
;
3130 TRACE("%p %p %08x\n", dialog
, hwnd
, param
);
3135 control
= msi_dialog_find_control( dialog
, dialog
->control_default
);
3137 case 2: /* escape */
3138 control
= msi_dialog_find_control( dialog
, dialog
->control_cancel
);
3141 control
= msi_dialog_find_control_by_hwnd( dialog
, hwnd
);
3146 if( control
->handler
)
3148 control
->handler( dialog
, control
, param
);
3149 msi_dialog_evaluate_control_conditions( dialog
);
3153 ERR("button click from nowhere %p %d %p\n", dialog
, param
, hwnd
);
3157 static LRESULT
msi_dialog_onnotify( msi_dialog
*dialog
, LPARAM param
)
3159 LPNMHDR nmhdr
= (LPNMHDR
) param
;
3160 msi_control
*control
= msi_dialog_find_control_by_hwnd( dialog
, nmhdr
->hwndFrom
);
3162 TRACE("%p %p\n", dialog
, nmhdr
->hwndFrom
);
3164 if ( control
&& control
->handler
)
3165 control
->handler( dialog
, control
, param
);
3170 static void msi_dialog_setfocus( msi_dialog
*dialog
)
3172 HWND hwnd
= dialog
->hWndFocus
;
3174 hwnd
= GetNextDlgTabItem( dialog
->hwnd
, hwnd
, TRUE
);
3175 hwnd
= GetNextDlgTabItem( dialog
->hwnd
, hwnd
, FALSE
);
3177 dialog
->hWndFocus
= hwnd
;
3180 static LRESULT WINAPI
MSIDialog_WndProc( HWND hwnd
, UINT msg
,
3181 WPARAM wParam
, LPARAM lParam
)
3183 msi_dialog
*dialog
= (LPVOID
) GetWindowLongPtrW( hwnd
, GWLP_USERDATA
);
3185 TRACE("0x%04x\n", msg
);
3190 dialog
->package
->center_x
= LOWORD(lParam
) + dialog
->size
.cx
/ 2.0;
3191 dialog
->package
->center_y
= HIWORD(lParam
) + dialog
->size
.cy
/ 2.0;
3195 return msi_dialog_oncreate( hwnd
, (LPCREATESTRUCTW
)lParam
);
3198 return msi_dialog_oncommand( dialog
, wParam
, (HWND
)lParam
);
3201 if( LOWORD(wParam
) == WA_INACTIVE
)
3202 dialog
->hWndFocus
= GetFocus();
3204 msi_dialog_setfocus( dialog
);
3208 msi_dialog_setfocus( dialog
);
3211 /* bounce back to our subclassed static control */
3212 case WM_CTLCOLORSTATIC
:
3213 return SendMessageW( (HWND
) lParam
, WM_CTLCOLORSTATIC
, wParam
, lParam
);
3216 dialog
->hwnd
= NULL
;
3219 return msi_dialog_onnotify( dialog
, lParam
);
3221 return DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
3224 static BOOL CALLBACK
msi_radioground_child_enum( HWND hWnd
, LPARAM lParam
)
3226 EnableWindow( hWnd
, lParam
);
3230 static LRESULT WINAPI
MSIRadioGroup_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
3232 WNDPROC oldproc
= (WNDPROC
) GetPropW(hWnd
, szButtonData
);
3235 TRACE("hWnd %p msg %04x wParam 0x%08x lParam 0x%08lx\n", hWnd
, msg
, wParam
, lParam
);
3237 if (msg
== WM_COMMAND
) /* Forward notifications to dialog */
3238 SendMessageW(GetParent(hWnd
), msg
, wParam
, lParam
);
3240 r
= CallWindowProcW(oldproc
, hWnd
, msg
, wParam
, lParam
);
3242 /* make sure the radio buttons show as disabled if the parent is disabled */
3243 if (msg
== WM_ENABLE
)
3244 EnumChildWindows( hWnd
, msi_radioground_child_enum
, wParam
);
3249 static LRESULT WINAPI
MSIHiddenWindowProc( HWND hwnd
, UINT msg
,
3250 WPARAM wParam
, LPARAM lParam
)
3252 msi_dialog
*dialog
= (msi_dialog
*) lParam
;
3254 TRACE("%d %p\n", msg
, dialog
);
3258 case WM_MSI_DIALOG_CREATE
:
3259 return msi_dialog_run_message_loop( dialog
);
3260 case WM_MSI_DIALOG_DESTROY
:
3261 msi_dialog_destroy( dialog
);
3264 return DefWindowProcW( hwnd
, msg
, wParam
, lParam
);
3267 /* functions that interface to other modules within MSI */
3269 msi_dialog
*msi_dialog_create( MSIPACKAGE
* package
,
3270 LPCWSTR szDialogName
, msi_dialog
*parent
,
3271 msi_dialog_event_handler event_handler
)
3273 MSIRECORD
*rec
= NULL
;
3276 TRACE("%p %s\n", package
, debugstr_w(szDialogName
));
3278 /* allocate the structure for the dialog to use */
3279 dialog
= msi_alloc_zero( sizeof *dialog
+ sizeof(WCHAR
)*strlenW(szDialogName
) );
3282 strcpyW( dialog
->name
, szDialogName
);
3283 dialog
->parent
= parent
;
3284 msiobj_addref( &package
->hdr
);
3285 dialog
->package
= package
;
3286 dialog
->event_handler
= event_handler
;
3287 dialog
->finished
= 0;
3288 list_init( &dialog
->controls
);
3290 /* verify that the dialog exists */
3291 rec
= msi_get_dialog_record( dialog
);
3294 msiobj_release( &package
->hdr
);
3298 dialog
->attributes
= MSI_RecordGetInteger( rec
, 6 );
3299 dialog
->control_default
= strdupW( MSI_RecordGetString( rec
, 9 ) );
3300 dialog
->control_cancel
= strdupW( MSI_RecordGetString( rec
, 10 ) );
3301 msiobj_release( &rec
->hdr
);
3306 static void msi_process_pending_messages( HWND hdlg
)
3310 while( PeekMessageW( &msg
, 0, 0, 0, PM_REMOVE
) )
3312 if( hdlg
&& IsDialogMessageW( hdlg
, &msg
))
3314 TranslateMessage( &msg
);
3315 DispatchMessageW( &msg
);
3319 void msi_dialog_end_dialog( msi_dialog
*dialog
)
3321 TRACE("%p\n", dialog
);
3322 dialog
->finished
= 1;
3323 PostMessageW(dialog
->hwnd
, WM_NULL
, 0, 0);
3326 void msi_dialog_check_messages( HANDLE handle
)
3330 /* in threads other than the UI thread, block */
3331 if( uiThreadId
!= GetCurrentThreadId() )
3334 WaitForSingleObject( handle
, INFINITE
);
3338 /* there's two choices for the UI thread */
3341 msi_process_pending_messages( NULL
);
3347 * block here until somebody creates a new dialog or
3348 * the handle we're waiting on becomes ready
3350 r
= MsgWaitForMultipleObjects( 1, &handle
, 0, INFINITE
, QS_ALLINPUT
);
3351 if( r
== WAIT_OBJECT_0
)
3356 UINT
msi_dialog_run_message_loop( msi_dialog
*dialog
)
3361 if( uiThreadId
!= GetCurrentThreadId() )
3362 return SendMessageW( hMsiHiddenWindow
, WM_MSI_DIALOG_CREATE
, 0, (LPARAM
) dialog
);
3364 /* create the dialog window, don't show it yet */
3365 style
= WS_OVERLAPPED
;
3366 if( dialog
->attributes
& msidbDialogAttributesVisible
)
3367 style
|= WS_VISIBLE
;
3369 hwnd
= CreateWindowW( szMsiDialogClass
, dialog
->name
, style
,
3370 CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
,
3371 NULL
, NULL
, NULL
, dialog
);
3374 ERR("Failed to create dialog %s\n", debugstr_w( dialog
->name
));
3375 return ERROR_FUNCTION_FAILED
;
3378 ShowWindow( hwnd
, SW_SHOW
);
3379 /* UpdateWindow( hwnd ); - and causes the transparent static controls not to paint */
3381 if( dialog
->attributes
& msidbDialogAttributesModal
)
3383 while( !dialog
->finished
)
3385 MsgWaitForMultipleObjects( 0, NULL
, 0, INFINITE
, QS_ALLINPUT
);
3386 msi_process_pending_messages( dialog
->hwnd
);
3390 return ERROR_IO_PENDING
;
3392 return ERROR_SUCCESS
;
3395 void msi_dialog_do_preview( msi_dialog
*dialog
)
3398 dialog
->attributes
|= msidbDialogAttributesVisible
;
3399 dialog
->attributes
&= ~msidbDialogAttributesModal
;
3400 msi_dialog_run_message_loop( dialog
);
3403 void msi_dialog_destroy( msi_dialog
*dialog
)
3405 if( uiThreadId
!= GetCurrentThreadId() )
3407 SendMessageW( hMsiHiddenWindow
, WM_MSI_DIALOG_DESTROY
, 0, (LPARAM
) dialog
);
3412 ShowWindow( dialog
->hwnd
, SW_HIDE
);
3415 DestroyWindow( dialog
->hwnd
);
3417 /* destroy the list of controls */
3418 while( !list_empty( &dialog
->controls
) )
3422 t
= LIST_ENTRY( list_head( &dialog
->controls
),
3423 msi_control
, entry
);
3424 msi_destroy_control( t
);
3427 /* destroy the list of fonts */
3428 while( dialog
->font_list
)
3430 msi_font
*t
= dialog
->font_list
;
3431 dialog
->font_list
= t
->next
;
3432 DeleteObject( t
->hfont
);
3435 msi_free( dialog
->default_font
);
3437 msi_free( dialog
->control_default
);
3438 msi_free( dialog
->control_cancel
);
3439 msiobj_release( &dialog
->package
->hdr
);
3440 dialog
->package
= NULL
;
3444 BOOL
msi_dialog_register_class( void )
3448 ZeroMemory( &cls
, sizeof cls
);
3449 cls
.lpfnWndProc
= MSIDialog_WndProc
;
3450 cls
.hInstance
= NULL
;
3451 cls
.hIcon
= LoadIconW(0, (LPWSTR
)IDI_APPLICATION
);
3452 cls
.hCursor
= LoadCursorW(0, (LPWSTR
)IDC_ARROW
);
3453 cls
.hbrBackground
= (HBRUSH
)(COLOR_3DFACE
+ 1);
3454 cls
.lpszMenuName
= NULL
;
3455 cls
.lpszClassName
= szMsiDialogClass
;
3457 if( !RegisterClassW( &cls
) )
3460 cls
.lpfnWndProc
= MSIHiddenWindowProc
;
3461 cls
.lpszClassName
= szMsiHiddenWindow
;
3463 if( !RegisterClassW( &cls
) )
3466 uiThreadId
= GetCurrentThreadId();
3468 hMsiHiddenWindow
= CreateWindowW( szMsiHiddenWindow
, NULL
, WS_OVERLAPPED
,
3469 0, 0, 100, 100, NULL
, NULL
, NULL
, NULL
);
3470 if( !hMsiHiddenWindow
)
3476 void msi_dialog_unregister_class( void )
3478 DestroyWindow( hMsiHiddenWindow
);
3479 hMsiHiddenWindow
= NULL
;
3480 UnregisterClassW( szMsiDialogClass
, NULL
);
3481 UnregisterClassW( szMsiHiddenWindow
, NULL
);
3485 static UINT
error_dialog_handler(MSIPACKAGE
*package
, LPCWSTR event
,
3486 LPCWSTR argument
, msi_dialog
* dialog
)
3488 static const WCHAR end_dialog
[] = {'E','n','d','D','i','a','l','o','g',0};
3489 static const WCHAR error_abort
[] = {'E','r','r','o','r','A','b','o','r','t',0};
3490 static const WCHAR error_cancel
[] = {'E','r','r','o','r','C','a','n','c','e','l',0};
3491 static const WCHAR error_no
[] = {'E','r','r','o','r','N','o',0};
3492 static const WCHAR result_prop
[] = {
3493 'M','S','I','E','r','r','o','r','D','i','a','l','o','g','R','e','s','u','l','t',0
3496 if ( lstrcmpW( event
, end_dialog
) )
3497 return ERROR_SUCCESS
;
3499 if ( !lstrcmpW( argument
, error_abort
) || !lstrcmpW( argument
, error_cancel
) ||
3500 !lstrcmpW( argument
, error_no
) )
3502 MSI_SetPropertyW( package
, result_prop
, error_abort
);
3505 ControlEvent_CleanupSubscriptions(package
);
3506 msi_dialog_end_dialog( dialog
);
3508 return ERROR_SUCCESS
;
3511 static UINT
msi_error_dialog_set_error( MSIPACKAGE
*package
, LPWSTR error_dialog
, LPWSTR error
)
3515 static const WCHAR update
[] =
3516 {'U','P','D','A','T','E',' ','`','C','o','n','t','r','o','l','`',' ',
3517 'S','E','T',' ','`','T','e','x','t','`',' ','=',' ','\'','%','s','\'',' ',
3518 'W','H','E','R','E', ' ','`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',' ',
3519 'A','N','D',' ','`','C','o','n','t','r','o','l','`',' ','=',' ',
3520 '\'','E','r','r','o','r','T','e','x','t','\'',0};
3522 row
= MSI_QueryGetRecord( package
->db
, update
, error
, error_dialog
);
3524 return ERROR_FUNCTION_FAILED
;
3526 msiobj_release(&row
->hdr
);
3527 return ERROR_SUCCESS
;
3530 UINT
msi_spawn_error_dialog( MSIPACKAGE
*package
, LPWSTR error_dialog
, LPWSTR error
)
3533 WCHAR result
[MAX_PATH
];
3534 UINT r
= ERROR_SUCCESS
;
3535 DWORD size
= MAX_PATH
;
3538 static const WCHAR szUILevel
[] = {'U','I','L','e','v','e','l',0};
3539 static const WCHAR pn_prop
[] = {'P','r','o','d','u','c','t','N','a','m','e',0};
3540 static const WCHAR title_fmt
[] = {'%','s',' ','W','a','r','n','i','n','g',0};
3541 static const WCHAR error_abort
[] = {'E','r','r','o','r','A','b','o','r','t',0};
3542 static const WCHAR result_prop
[] = {
3543 'M','S','I','E','r','r','o','r','D','i','a','l','o','g','R','e','s','u','l','t',0
3546 if ( msi_get_property_int(package
, szUILevel
, 0) == INSTALLUILEVEL_NONE
)
3547 return ERROR_SUCCESS
;
3549 if ( !error_dialog
)
3551 LPWSTR product_name
= msi_dup_property( package
, pn_prop
);
3552 WCHAR title
[MAX_PATH
];
3554 sprintfW( title
, title_fmt
, product_name
);
3555 res
= MessageBoxW( NULL
, error
, title
, MB_OKCANCEL
| MB_ICONWARNING
);
3557 msi_free( product_name
);
3560 return ERROR_SUCCESS
;
3562 return ERROR_FUNCTION_FAILED
;
3565 r
= msi_error_dialog_set_error( package
, error_dialog
, error
);
3566 if ( r
!= ERROR_SUCCESS
)
3569 dialog
= msi_dialog_create( package
, error_dialog
, package
->dialog
,
3570 error_dialog_handler
);
3572 return ERROR_FUNCTION_FAILED
;
3574 dialog
->finished
= FALSE
;
3575 r
= msi_dialog_run_message_loop( dialog
);
3576 if ( r
!= ERROR_SUCCESS
)
3579 r
= MSI_GetPropertyW( package
, result_prop
, result
, &size
);
3580 if ( r
!= ERROR_SUCCESS
)
3583 if ( !lstrcmpW( result
, error_abort
) )
3584 r
= ERROR_FUNCTION_FAILED
;
3587 msi_dialog_destroy( dialog
);