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"
47 WINE_DEFAULT_DEBUG_CHANNEL(msi
);
50 extern HINSTANCE msi_hInstance
;
52 struct msi_control_tag
;
53 typedef struct msi_control_tag msi_control
;
54 typedef UINT (*msi_handler
)( msi_dialog
*, msi_control
*, WPARAM
);
56 struct msi_control_tag
67 float progress_current
;
73 typedef struct msi_font_tag
75 struct msi_font_tag
*next
;
84 msi_dialog_event_handler event_handler
;
93 LPWSTR control_default
;
94 LPWSTR control_cancel
;
98 typedef UINT (*msi_dialog_control_func
)( msi_dialog
*dialog
, MSIRECORD
*rec
);
99 struct control_handler
101 LPCWSTR control_type
;
102 msi_dialog_control_func func
;
111 } radio_button_group_descr
;
113 static const WCHAR szMsiDialogClass
[] = {
114 'M','s','i','D','i','a','l','o','g','C','l','o','s','e','C','l','a','s','s',0
116 static const WCHAR szMsiHiddenWindow
[] = {
117 'M','s','i','H','i','d','d','e','n','W','i','n','d','o','w',0 };
118 static const WCHAR szStatic
[] = { 'S','t','a','t','i','c',0 };
119 static const WCHAR szButton
[] = { 'B','U','T','T','O','N', 0 };
120 static const WCHAR szButtonData
[] = { 'M','S','I','D','A','T','A',0 };
121 static const WCHAR szProgress
[] = { 'P','r','o','g','r','e','s','s',0 };
122 static const WCHAR szText
[] = { 'T','e','x','t',0 };
123 static const WCHAR szPushButton
[] = { 'P','u','s','h','B','u','t','t','o','n',0 };
124 static const WCHAR szLine
[] = { 'L','i','n','e',0 };
125 static const WCHAR szBitmap
[] = { 'B','i','t','m','a','p',0 };
126 static const WCHAR szCheckBox
[] = { 'C','h','e','c','k','B','o','x',0 };
127 static const WCHAR szScrollableText
[] = {
128 'S','c','r','o','l','l','a','b','l','e','T','e','x','t',0 };
129 static const WCHAR szComboBox
[] = { 'C','o','m','b','o','B','o','x',0 };
130 static const WCHAR szEdit
[] = { 'E','d','i','t',0 };
131 static const WCHAR szMaskedEdit
[] = { 'M','a','s','k','e','d','E','d','i','t',0 };
132 static const WCHAR szPathEdit
[] = { 'P','a','t','h','E','d','i','t',0 };
133 static const WCHAR szProgressBar
[] = {
134 'P','r','o','g','r','e','s','s','B','a','r',0 };
135 static const WCHAR szRadioButtonGroup
[] = {
136 'R','a','d','i','o','B','u','t','t','o','n','G','r','o','u','p',0 };
137 static const WCHAR szIcon
[] = { 'I','c','o','n',0 };
138 static const WCHAR szSelectionTree
[] = {
139 'S','e','l','e','c','t','i','o','n','T','r','e','e',0 };
140 static const WCHAR szGroupBox
[] = { 'G','r','o','u','p','B','o','x',0 };
141 static const WCHAR szListBox
[] = { 'L','i','s','t','B','o','x',0 };
142 static const WCHAR szDirectoryCombo
[] = { 'D','i','r','e','c','t','o','r','y','C','o','m','b','o',0 };
143 static const WCHAR szDirectoryList
[] = { 'D','i','r','e','c','t','o','r','y','L','i','s','t',0 };
144 static const WCHAR szVolumeCostList
[] = { 'V','o','l','u','m','e','C','o','s','t','L','i','s','t',0 };
146 static UINT
msi_dialog_checkbox_handler( msi_dialog
*, msi_control
*, WPARAM
);
147 static void msi_dialog_checkbox_sync_state( msi_dialog
*, msi_control
* );
148 static UINT
msi_dialog_button_handler( msi_dialog
*, msi_control
*, WPARAM
);
149 static UINT
msi_dialog_edit_handler( msi_dialog
*, msi_control
*, WPARAM
);
150 static UINT
msi_dialog_radiogroup_handler( msi_dialog
*, msi_control
*, WPARAM param
);
151 static UINT
msi_dialog_evaluate_control_conditions( msi_dialog
*dialog
);
152 static LRESULT WINAPI
MSIRadioGroup_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
);
155 /* dialog sequencing */
157 #define WM_MSI_DIALOG_CREATE (WM_USER+0x100)
158 #define WM_MSI_DIALOG_DESTROY (WM_USER+0x101)
160 static DWORD uiThreadId
;
161 static HWND hMsiHiddenWindow
;
163 static INT
msi_dialog_scale_unit( msi_dialog
*dialog
, INT val
)
165 return (dialog
->scale
* val
+ 5) / 10;
168 static msi_control
*msi_dialog_find_control( msi_dialog
*dialog
, LPCWSTR name
)
170 msi_control
*control
;
174 LIST_FOR_EACH_ENTRY( control
, &dialog
->controls
, msi_control
, entry
)
175 if( !strcmpW( control
->name
, name
) ) /* FIXME: case sensitive? */
180 static msi_control
*msi_dialog_find_control_by_hwnd( msi_dialog
*dialog
, HWND hwnd
)
182 msi_control
*control
;
184 LIST_FOR_EACH_ENTRY( control
, &dialog
->controls
, msi_control
, entry
)
185 if( hwnd
== control
->hwnd
)
190 static LPWSTR
msi_get_deformatted_field( MSIPACKAGE
*package
, MSIRECORD
*rec
, int field
)
192 LPCWSTR str
= MSI_RecordGetString( rec
, field
);
196 deformat_string( package
, str
, &ret
);
200 static LPWSTR
msi_dialog_dup_property( msi_dialog
*dialog
, LPCWSTR property
, BOOL indirect
)
206 return msi_dup_property( dialog
->package
, property
);
208 return strdupW( property
);
212 * msi_dialog_get_style
214 * Extract the {\style} string from the front of the text to display and
215 * update the pointer.
217 static LPWSTR
msi_dialog_get_style( LPCWSTR p
, LPCWSTR
*rest
)
228 q
= strchrW( p
, '}' );
231 if( *p
== '\\' || *p
== '&' )
234 /* little bit of sanity checking to stop us getting confused with RTF */
236 if( *i
== '}' || *i
== '\\' )
242 ret
= msi_alloc( len
*sizeof(WCHAR
) );
245 memcpy( ret
, p
, len
*sizeof(WCHAR
) );
250 static UINT
msi_dialog_add_font( MSIRECORD
*rec
, LPVOID param
)
252 msi_dialog
*dialog
= param
;
259 /* create a font and add it to the list */
260 name
= MSI_RecordGetString( rec
, 1 );
261 font
= msi_alloc( sizeof *font
+ strlenW( name
)*sizeof (WCHAR
) );
262 strcpyW( font
->name
, name
);
263 font
->next
= dialog
->font_list
;
264 dialog
->font_list
= font
;
266 font
->color
= MSI_RecordGetInteger( rec
, 4 );
268 memset( &lf
, 0, sizeof lf
);
269 face
= MSI_RecordGetString( rec
, 2 );
270 lf
.lfHeight
= MSI_RecordGetInteger( rec
, 3 );
271 style
= MSI_RecordGetInteger( rec
, 5 );
272 if( style
& msidbTextStyleStyleBitsBold
)
273 lf
.lfWeight
= FW_BOLD
;
274 if( style
& msidbTextStyleStyleBitsItalic
)
276 if( style
& msidbTextStyleStyleBitsUnderline
)
277 lf
.lfUnderline
= TRUE
;
278 if( style
& msidbTextStyleStyleBitsStrike
)
279 lf
.lfStrikeOut
= TRUE
;
280 lstrcpynW( lf
.lfFaceName
, face
, LF_FACESIZE
);
282 /* adjust the height */
283 hdc
= GetDC( dialog
->hwnd
);
286 lf
.lfHeight
= -MulDiv(lf
.lfHeight
, GetDeviceCaps(hdc
, LOGPIXELSY
), 72);
287 ReleaseDC( dialog
->hwnd
, hdc
);
290 font
->hfont
= CreateFontIndirectW( &lf
);
292 TRACE("Adding font style %s\n", debugstr_w(font
->name
) );
294 return ERROR_SUCCESS
;
297 static msi_font
*msi_dialog_find_font( msi_dialog
*dialog
, LPCWSTR name
)
301 for( font
= dialog
->font_list
; font
; font
= font
->next
)
302 if( !strcmpW( font
->name
, name
) ) /* FIXME: case sensitive? */
308 static UINT
msi_dialog_set_font( msi_dialog
*dialog
, HWND hwnd
, LPCWSTR name
)
312 font
= msi_dialog_find_font( dialog
, name
);
314 SendMessageW( hwnd
, WM_SETFONT
, (WPARAM
) font
->hfont
, TRUE
);
316 ERR("No font entry for %s\n", debugstr_w(name
));
317 return ERROR_SUCCESS
;
320 static UINT
msi_dialog_build_font_list( msi_dialog
*dialog
)
322 static const WCHAR query
[] = {
323 'S','E','L','E','C','T',' ','*',' ',
324 'F','R','O','M',' ','`','T','e','x','t','S','t','y','l','e','`',' ',0
327 MSIQUERY
*view
= NULL
;
329 TRACE("dialog %p\n", dialog
);
331 r
= MSI_OpenQuery( dialog
->package
->db
, &view
, query
);
332 if( r
!= ERROR_SUCCESS
)
335 r
= MSI_IterateRecords( view
, NULL
, msi_dialog_add_font
, dialog
);
336 msiobj_release( &view
->hdr
);
341 static msi_control
*msi_dialog_create_window( msi_dialog
*dialog
,
342 MSIRECORD
*rec
, DWORD exstyle
, LPCWSTR szCls
, LPCWSTR name
, LPCWSTR text
,
343 DWORD style
, HWND parent
)
345 DWORD x
, y
, width
, height
;
346 LPWSTR font
= NULL
, title_font
= NULL
;
347 LPCWSTR title
= NULL
;
348 msi_control
*control
;
352 control
= msi_alloc( sizeof *control
+ strlenW(name
)*sizeof(WCHAR
) );
353 strcpyW( control
->name
, name
);
354 list_add_head( &dialog
->controls
, &control
->entry
);
355 control
->handler
= NULL
;
356 control
->property
= NULL
;
357 control
->value
= NULL
;
358 control
->hBitmap
= NULL
;
359 control
->hIcon
= NULL
;
360 control
->hDll
= NULL
;
361 control
->tabnext
= strdupW( MSI_RecordGetString( rec
, 11) );
362 control
->progress_current
= 0;
363 control
->progress_max
= 100;
365 x
= MSI_RecordGetInteger( rec
, 4 );
366 y
= MSI_RecordGetInteger( rec
, 5 );
367 width
= MSI_RecordGetInteger( rec
, 6 );
368 height
= MSI_RecordGetInteger( rec
, 7 );
370 x
= msi_dialog_scale_unit( dialog
, x
);
371 y
= msi_dialog_scale_unit( dialog
, y
);
372 width
= msi_dialog_scale_unit( dialog
, width
);
373 height
= msi_dialog_scale_unit( dialog
, height
);
377 deformat_string( dialog
->package
, text
, &title_font
);
378 font
= msi_dialog_get_style( title_font
, &title
);
381 control
->hwnd
= CreateWindowExW( exstyle
, szCls
, title
, style
,
382 x
, y
, width
, height
, parent
, NULL
, NULL
, NULL
);
384 TRACE("Dialog %s control %s hwnd %p\n",
385 debugstr_w(dialog
->name
), debugstr_w(text
), control
->hwnd
);
387 msi_dialog_set_font( dialog
, control
->hwnd
,
388 font
? font
: dialog
->default_font
);
390 msi_free( title_font
);
396 static MSIRECORD
*msi_get_binary_record( MSIDATABASE
*db
, LPCWSTR name
)
398 static const WCHAR query
[] = {
399 's','e','l','e','c','t',' ','*',' ',
400 'f','r','o','m',' ','B','i','n','a','r','y',' ',
401 'w','h','e','r','e',' ',
402 '`','N','a','m','e','`',' ','=',' ','\'','%','s','\'',0
405 return MSI_QueryGetRecord( db
, query
, name
);
408 static LPWSTR
msi_create_tmp_path(void)
412 static const WCHAR prefix
[] = { 'm','s','i',0 };
415 r
= GetTempPathW( MAX_PATH
, tmp
);
418 len
= lstrlenW( tmp
) + 20;
419 path
= msi_alloc( len
* sizeof (WCHAR
) );
422 r
= GetTempFileNameW( tmp
, prefix
, 0, path
);
433 static HANDLE
msi_load_image( MSIDATABASE
*db
, LPCWSTR name
, UINT type
,
434 UINT cx
, UINT cy
, UINT flags
)
436 MSIRECORD
*rec
= NULL
;
437 HANDLE himage
= NULL
;
441 TRACE("%p %s %u %u %08x\n", db
, debugstr_w(name
), cx
, cy
, flags
);
443 tmp
= msi_create_tmp_path();
447 rec
= msi_get_binary_record( db
, name
);
450 r
= MSI_RecordStreamToFile( rec
, 2, tmp
);
451 if( r
== ERROR_SUCCESS
)
453 himage
= LoadImageW( 0, tmp
, type
, cx
, cy
, flags
);
456 msiobj_release( &rec
->hdr
);
463 static HICON
msi_load_icon( MSIDATABASE
*db
, LPCWSTR text
, UINT attributes
)
465 DWORD cx
= 0, cy
= 0, flags
;
467 flags
= LR_LOADFROMFILE
| LR_DEFAULTSIZE
;
468 if( attributes
& msidbControlAttributesFixedSize
)
470 flags
&= ~LR_DEFAULTSIZE
;
471 if( attributes
& msidbControlAttributesIconSize16
)
476 if( attributes
& msidbControlAttributesIconSize32
)
481 /* msidbControlAttributesIconSize48 handled by above logic */
483 return msi_load_image( db
, text
, IMAGE_ICON
, cx
, cy
, flags
);
487 /* called from the Control Event subscription code */
488 void msi_dialog_handle_event( msi_dialog
* dialog
, LPCWSTR control
,
489 LPCWSTR attribute
, MSIRECORD
*rec
)
492 LPCWSTR font_text
, text
= NULL
;
495 ctrl
= msi_dialog_find_control( dialog
, control
);
498 if( !lstrcmpW(attribute
, szText
) )
500 font_text
= MSI_RecordGetString( rec
, 1 );
501 font
= msi_dialog_get_style( font_text
, &text
);
502 SetWindowTextW( ctrl
->hwnd
, text
);
504 msi_dialog_check_messages( NULL
);
506 else if( !lstrcmpW(attribute
, szProgress
) )
510 func
= MSI_RecordGetInteger( rec
, 1 );
511 val
= MSI_RecordGetInteger( rec
, 2 );
516 ctrl
->progress_max
= val
;
517 ctrl
->progress_current
= 0;
518 SendMessageW(ctrl
->hwnd
, PBM_SETRANGE
, 0, MAKELPARAM(0,100));
519 SendMessageW(ctrl
->hwnd
, PBM_SETPOS
, 0, 0);
521 case 1: /* FIXME: not sure what this is supposed to do */
524 ctrl
->progress_current
+= val
;
525 SendMessageW(ctrl
->hwnd
, PBM_SETPOS
, 100*(ctrl
->progress_current
/ctrl
->progress_max
), 0);
528 ERR("Unknown progress message %ld\n", func
);
534 FIXME("Attribute %s not being set\n", debugstr_w(attribute
));
539 static void msi_dialog_map_events(msi_dialog
* dialog
, LPCWSTR control
)
541 static const WCHAR Query
[] = {
542 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
543 '`','E','v','e','n','t','M','a','p','p','i','n','g','`',' ',
544 'W','H','E','R','E',' ',
545 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',' ',
547 '`','C','o','n','t','r','o','l','_','`',' ','=',' ','\'','%','s','\'',0
550 LPCWSTR event
, attribute
;
552 row
= MSI_QueryGetRecord( dialog
->package
->db
, Query
, dialog
->name
, control
);
556 event
= MSI_RecordGetString( row
, 3 );
557 attribute
= MSI_RecordGetString( row
, 4 );
558 ControlEvent_SubscribeToEvent( dialog
->package
, event
, control
, attribute
);
559 msiobj_release( &row
->hdr
);
562 /* everything except radio buttons */
563 static msi_control
*msi_dialog_add_control( msi_dialog
*dialog
,
564 MSIRECORD
*rec
, LPCWSTR szCls
, DWORD style
)
570 name
= MSI_RecordGetString( rec
, 2 );
571 attributes
= MSI_RecordGetInteger( rec
, 8 );
572 text
= MSI_RecordGetString( rec
, 10 );
573 if( attributes
& msidbControlAttributesVisible
)
575 if( ~attributes
& msidbControlAttributesEnabled
)
576 style
|= WS_DISABLED
;
577 if( attributes
& msidbControlAttributesSunken
)
578 exstyle
|= WS_EX_CLIENTEDGE
;
580 msi_dialog_map_events(dialog
, name
);
582 return msi_dialog_create_window( dialog
, rec
, exstyle
, szCls
, name
,
583 text
, style
, dialog
->hwnd
);
594 * we don't erase our own background,
595 * so we have to make sure that the parent window redraws first
597 static void msi_text_on_settext( HWND hWnd
)
602 hParent
= GetParent( hWnd
);
603 GetWindowRect( hWnd
, &rc
);
604 MapWindowPoints( NULL
, hParent
, (LPPOINT
) &rc
, 2 );
605 InvalidateRect( hParent
, &rc
, TRUE
);
608 static LRESULT WINAPI
609 MSIText_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
611 struct msi_text_info
*info
;
614 TRACE("%p %04x %08x %08lx\n", hWnd
, msg
, wParam
, lParam
);
616 info
= GetPropW(hWnd
, szButtonData
);
619 SetTextColor( (HDC
)wParam
, info
->font
->color
);
621 if( msg
== WM_CTLCOLORSTATIC
&&
622 ( info
->attributes
& msidbControlAttributesTransparent
) )
624 SetBkMode( (HDC
)wParam
, TRANSPARENT
);
625 return (LRESULT
) GetStockObject(NULL_BRUSH
);
628 r
= CallWindowProcW(info
->oldproc
, hWnd
, msg
, wParam
, lParam
);
633 msi_text_on_settext( hWnd
);
637 RemovePropW( hWnd
, szButtonData
);
644 static UINT
msi_dialog_text_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
646 msi_control
*control
;
647 struct msi_text_info
*info
;
651 TRACE("%p %p\n", dialog
, rec
);
653 control
= msi_dialog_add_control( dialog
, rec
, szStatic
, SS_LEFT
| WS_GROUP
);
655 return ERROR_FUNCTION_FAILED
;
657 info
= msi_alloc( sizeof *info
);
659 return ERROR_SUCCESS
;
661 text
= MSI_RecordGetString( rec
, 10 );
662 font_name
= msi_dialog_get_style( text
, &ptr
);
663 info
->font
= ( font_name
) ? msi_dialog_find_font( dialog
, font_name
) : NULL
;
664 msi_free( font_name
);
666 info
->attributes
= MSI_RecordGetInteger( rec
, 8 );
667 if( info
->attributes
& msidbControlAttributesTransparent
)
668 SetWindowLongPtrW( control
->hwnd
, GWL_EXSTYLE
, WS_EX_TRANSPARENT
);
670 info
->oldproc
= (WNDPROC
) SetWindowLongPtrW( control
->hwnd
, GWLP_WNDPROC
,
671 (LONG_PTR
)MSIText_WndProc
);
672 SetPropW( control
->hwnd
, szButtonData
, info
);
674 return ERROR_SUCCESS
;
677 static UINT
msi_dialog_button_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
679 msi_control
*control
;
680 UINT attributes
, style
;
683 TRACE("%p %p\n", dialog
, rec
);
686 attributes
= MSI_RecordGetInteger( rec
, 8 );
687 if( attributes
& msidbControlAttributesIcon
)
690 control
= msi_dialog_add_control( dialog
, rec
, szButton
, style
);
692 return ERROR_FUNCTION_FAILED
;
694 control
->handler
= msi_dialog_button_handler
;
697 text
= msi_get_deformatted_field( dialog
->package
, rec
, 10 );
698 control
->hIcon
= msi_load_icon( dialog
->package
->db
, text
, attributes
);
699 if( attributes
& msidbControlAttributesIcon
)
700 SendMessageW( control
->hwnd
, BM_SETIMAGE
, IMAGE_ICON
, (LPARAM
) control
->hIcon
);
703 return ERROR_SUCCESS
;
706 static LPWSTR
msi_get_checkbox_value( msi_dialog
*dialog
, LPCWSTR prop
)
708 static const WCHAR query
[] = {
709 'S','E','L','E','C','T',' ','*',' ',
710 'F','R','O','M',' ','`','C','h','e','c','k','B','o','x',' ','`',
711 'W','H','E','R','E',' ',
712 '`','P','r','o','p','e','r','t','y','`',' ','=',' ',
715 MSIRECORD
*rec
= NULL
;
718 /* find if there is a value associated with the checkbox */
719 rec
= MSI_QueryGetRecord( dialog
->package
->db
, query
, prop
);
723 ret
= msi_get_deformatted_field( dialog
->package
, rec
, 2 );
729 msiobj_release( &rec
->hdr
);
733 ret
= msi_dup_property( dialog
->package
, prop
);
743 static UINT
msi_dialog_checkbox_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
745 msi_control
*control
;
748 TRACE("%p %p\n", dialog
, rec
);
750 control
= msi_dialog_add_control( dialog
, rec
, szButton
,
751 BS_CHECKBOX
| BS_MULTILINE
| WS_TABSTOP
);
752 control
->handler
= msi_dialog_checkbox_handler
;
753 prop
= MSI_RecordGetString( rec
, 9 );
756 control
->property
= strdupW( prop
);
757 control
->value
= msi_get_checkbox_value( dialog
, prop
);
758 TRACE("control %s value %s\n", debugstr_w(control
->property
),
759 debugstr_w(control
->value
));
761 msi_dialog_checkbox_sync_state( dialog
, control
);
763 return ERROR_SUCCESS
;
766 static UINT
msi_dialog_line_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
768 TRACE("%p %p\n", dialog
, rec
);
770 /* line is exactly 2 units in height */
771 MSI_RecordSetInteger( rec
, 7, 2 );
773 msi_dialog_add_control( dialog
, rec
, szStatic
, SS_ETCHEDHORZ
| SS_SUNKEN
);
774 return ERROR_SUCCESS
;
777 /******************** Scroll Text ********************************************/
779 struct msi_scrolltext_info
782 msi_control
*control
;
786 static LRESULT WINAPI
787 MSIScrollText_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
789 struct msi_scrolltext_info
*info
;
792 TRACE("%p %04x %08x %08lx\n", hWnd
, msg
, wParam
, lParam
);
794 info
= GetPropW( hWnd
, szButtonData
);
796 r
= CallWindowProcW( info
->oldproc
, hWnd
, msg
, wParam
, lParam
);
802 RemovePropW( hWnd
, szButtonData
);
805 /* native MSI sets a wait cursor here */
806 msi_dialog_button_handler( info
->dialog
, info
->control
, BN_CLICKED
);
812 struct msi_streamin_info
819 static DWORD CALLBACK
820 msi_richedit_stream_in( DWORD_PTR arg
, LPBYTE buffer
, LONG count
, LONG
*pcb
)
822 struct msi_streamin_info
*info
= (struct msi_streamin_info
*) arg
;
824 if( (count
+ info
->offset
) > info
->length
)
825 count
= info
->length
- info
->offset
;
826 memcpy( buffer
, &info
->string
[ info
->offset
], count
);
828 info
->offset
+= count
;
830 TRACE("%ld/%ld\n", info
->offset
, info
->length
);
835 static void msi_scrolltext_add_text( msi_control
*control
, LPCWSTR text
)
837 struct msi_streamin_info info
;
840 info
.string
= strdupWtoA( text
);
842 info
.length
= lstrlenA( info
.string
) + 1;
844 es
.dwCookie
= (DWORD_PTR
) &info
;
846 es
.pfnCallback
= msi_richedit_stream_in
;
848 SendMessageW( control
->hwnd
, EM_STREAMIN
, SF_RTF
, (LPARAM
) &es
);
850 msi_free( info
.string
);
853 static UINT
msi_dialog_scrolltext_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
855 static const WCHAR szRichEdit20W
[] = {
856 'R','i','c','h','E','d','i','t','2','0','W',0
858 struct msi_scrolltext_info
*info
;
859 msi_control
*control
;
863 info
= msi_alloc( sizeof *info
);
865 return ERROR_FUNCTION_FAILED
;
867 hRichedit
= LoadLibraryA("riched20");
869 style
= WS_BORDER
| ES_MULTILINE
| WS_VSCROLL
|
870 ES_READONLY
| ES_AUTOVSCROLL
| WS_TABSTOP
;
871 control
= msi_dialog_add_control( dialog
, rec
, szRichEdit20W
, style
);
874 FreeLibrary( hRichedit
);
876 return ERROR_FUNCTION_FAILED
;
879 control
->hDll
= hRichedit
;
881 info
->dialog
= dialog
;
882 info
->control
= control
;
884 /* subclass the static control */
885 info
->oldproc
= (WNDPROC
) SetWindowLongPtrW( control
->hwnd
, GWLP_WNDPROC
,
886 (LONG_PTR
)MSIScrollText_WndProc
);
887 SetPropW( control
->hwnd
, szButtonData
, info
);
889 /* add the text into the richedit */
890 msi_scrolltext_add_text( control
, MSI_RecordGetString( rec
, 10 ) );
892 return ERROR_SUCCESS
;
895 static HBITMAP
msi_load_picture( MSIDATABASE
*db
, LPCWSTR name
,
896 INT cx
, INT cy
, DWORD flags
)
898 HBITMAP hOleBitmap
= 0, hBitmap
= 0, hOldSrcBitmap
, hOldDestBitmap
;
899 MSIRECORD
*rec
= NULL
;
901 IPicture
*pic
= NULL
;
906 rec
= msi_get_binary_record( db
, name
);
910 r
= MSI_RecordGetIStream( rec
, 2, &stm
);
911 msiobj_release( &rec
->hdr
);
912 if( r
!= ERROR_SUCCESS
)
915 r
= OleLoadPicture( stm
, 0, TRUE
, &IID_IPicture
, (LPVOID
*) &pic
);
916 IStream_Release( stm
);
919 ERR("failed to load picture\n");
923 r
= IPicture_get_Handle( pic
, (OLE_HANDLE
*) &hOleBitmap
);
926 ERR("failed to get bitmap handle\n");
930 /* make the bitmap the desired size */
931 r
= GetObjectW( hOleBitmap
, sizeof bm
, &bm
);
934 ERR("failed to get bitmap size\n");
938 if (flags
& LR_DEFAULTSIZE
)
944 srcdc
= CreateCompatibleDC( NULL
);
945 hOldSrcBitmap
= SelectObject( srcdc
, hOleBitmap
);
946 destdc
= CreateCompatibleDC( NULL
);
947 hBitmap
= CreateCompatibleBitmap( srcdc
, cx
, cy
);
948 hOldDestBitmap
= SelectObject( destdc
, hBitmap
);
949 StretchBlt( destdc
, 0, 0, cx
, cy
,
950 srcdc
, 0, 0, bm
.bmWidth
, bm
.bmHeight
, SRCCOPY
);
951 SelectObject( srcdc
, hOldSrcBitmap
);
952 SelectObject( destdc
, hOldDestBitmap
);
958 IPicture_Release( pic
);
962 static UINT
msi_dialog_bitmap_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
964 UINT cx
, cy
, flags
, style
, attributes
;
965 msi_control
*control
;
968 flags
= LR_LOADFROMFILE
;
969 style
= SS_BITMAP
| SS_LEFT
| WS_GROUP
;
971 attributes
= MSI_RecordGetInteger( rec
, 8 );
972 if( attributes
& msidbControlAttributesFixedSize
)
974 flags
|= LR_DEFAULTSIZE
;
975 style
|= SS_CENTERIMAGE
;
978 control
= msi_dialog_add_control( dialog
, rec
, szStatic
, style
);
979 cx
= MSI_RecordGetInteger( rec
, 6 );
980 cy
= MSI_RecordGetInteger( rec
, 7 );
981 cx
= msi_dialog_scale_unit( dialog
, cx
);
982 cy
= msi_dialog_scale_unit( dialog
, cy
);
984 text
= msi_get_deformatted_field( dialog
->package
, rec
, 10 );
985 control
->hBitmap
= msi_load_picture( dialog
->package
->db
, text
, cx
, cy
, flags
);
986 if( control
->hBitmap
)
987 SendMessageW( control
->hwnd
, STM_SETIMAGE
,
988 IMAGE_BITMAP
, (LPARAM
) control
->hBitmap
);
990 ERR("Failed to load bitmap %s\n", debugstr_w(text
));
994 return ERROR_SUCCESS
;
997 static UINT
msi_dialog_icon_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
999 msi_control
*control
;
1005 control
= msi_dialog_add_control( dialog
, rec
, szStatic
,
1006 SS_ICON
| SS_CENTERIMAGE
| WS_GROUP
);
1008 attributes
= MSI_RecordGetInteger( rec
, 8 );
1009 text
= msi_get_deformatted_field( dialog
->package
, rec
, 10 );
1010 control
->hIcon
= msi_load_icon( dialog
->package
->db
, text
, attributes
);
1011 if( control
->hIcon
)
1012 SendMessageW( control
->hwnd
, STM_SETICON
, (WPARAM
) control
->hIcon
, 0 );
1014 ERR("Failed to load bitmap %s\n", debugstr_w(text
));
1016 return ERROR_SUCCESS
;
1019 static UINT
msi_dialog_combo_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1021 static const WCHAR szCombo
[] = { 'C','O','M','B','O','B','O','X',0 };
1023 msi_dialog_add_control( dialog
, rec
, szCombo
,
1024 SS_BITMAP
| SS_LEFT
| SS_CENTERIMAGE
);
1025 return ERROR_SUCCESS
;
1028 static UINT
msi_dialog_edit_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1030 msi_control
*control
;
1034 control
= msi_dialog_add_control( dialog
, rec
, szEdit
,
1035 WS_BORDER
| WS_TABSTOP
);
1036 control
->handler
= msi_dialog_edit_handler
;
1037 prop
= MSI_RecordGetString( rec
, 9 );
1039 control
->property
= strdupW( prop
);
1040 val
= msi_dup_property( dialog
->package
, control
->property
);
1041 SetWindowTextW( control
->hwnd
, val
);
1043 return ERROR_SUCCESS
;
1046 /******************** Masked Edit ********************************************/
1048 #define MASK_MAX_GROUPS 10
1050 struct msi_mask_group
1058 struct msi_maskedit_info
1066 struct msi_mask_group group
[MASK_MAX_GROUPS
];
1069 static BOOL
msi_mask_editable( WCHAR type
)
1084 static void msi_mask_control_change( struct msi_maskedit_info
*info
)
1089 val
= msi_alloc( (info
->num_chars
+1)*sizeof(WCHAR
) );
1090 for( i
=0, n
=0; i
<info
->num_groups
; i
++ )
1092 if( (info
->group
[i
].len
+ n
) > info
->num_chars
)
1094 ERR("can't fit control %d text into template\n",i
);
1097 if (!msi_mask_editable(info
->group
[i
].type
))
1099 for(r
=0; r
<info
->group
[i
].len
; r
++)
1100 val
[n
+r
] = info
->group
[i
].type
;
1105 r
= GetWindowTextW( info
->group
[i
].hwnd
, &val
[n
], info
->group
[i
].len
+1 );
1106 if( r
!= info
->group
[i
].len
)
1112 TRACE("%d/%d controls were good\n", i
, info
->num_groups
);
1114 if( i
== info
->num_groups
)
1116 TRACE("Set property %s to %s\n",
1117 debugstr_w(info
->prop
), debugstr_w(val
) );
1118 CharUpperBuffW( val
, info
->num_chars
);
1119 MSI_SetPropertyW( info
->dialog
->package
, info
->prop
, val
);
1120 msi_dialog_evaluate_control_conditions( info
->dialog
);
1125 /* now move to the next control if necessary */
1126 static VOID
msi_mask_next_control( struct msi_maskedit_info
*info
, HWND hWnd
)
1131 for( i
=0; i
<info
->num_groups
; i
++ )
1132 if( info
->group
[i
].hwnd
== hWnd
)
1135 /* don't move from the last control */
1136 if( i
>= (info
->num_groups
-1) )
1139 len
= SendMessageW( hWnd
, WM_GETTEXTLENGTH
, 0, 0 );
1140 if( len
< info
->group
[i
].len
)
1143 hWndNext
= GetNextDlgTabItem( GetParent( hWnd
), hWnd
, FALSE
);
1144 SetFocus( hWndNext
);
1147 static LRESULT WINAPI
1148 MSIMaskedEdit_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1150 struct msi_maskedit_info
*info
;
1153 TRACE("%p %04x %08x %08lx\n", hWnd
, msg
, wParam
, lParam
);
1155 info
= GetPropW(hWnd
, szButtonData
);
1157 r
= CallWindowProcW(info
->oldproc
, hWnd
, msg
, wParam
, lParam
);
1162 if (HIWORD(wParam
) == EN_CHANGE
)
1164 msi_mask_control_change( info
);
1165 msi_mask_next_control( info
, (HWND
) lParam
);
1169 msi_free( info
->prop
);
1171 RemovePropW( hWnd
, szButtonData
);
1178 /* fish the various bits of the property out and put them in the control */
1180 msi_maskedit_set_text( struct msi_maskedit_info
*info
, LPCWSTR text
)
1186 for( i
= 0; i
< info
->num_groups
; i
++ )
1188 if( info
->group
[i
].len
< lstrlenW( p
) )
1190 LPWSTR chunk
= strdupW( p
);
1191 chunk
[ info
->group
[i
].len
] = 0;
1192 SetWindowTextW( info
->group
[i
].hwnd
, chunk
);
1197 SetWindowTextW( info
->group
[i
].hwnd
, p
);
1200 p
+= info
->group
[i
].len
;
1204 static struct msi_maskedit_info
* msi_dialog_parse_groups( LPCWSTR mask
)
1206 struct msi_maskedit_info
* info
= NULL
;
1207 int i
= 0, n
= 0, total
= 0;
1210 TRACE("masked control, template %s\n", debugstr_w(mask
));
1215 info
= msi_alloc_zero( sizeof *info
);
1219 p
= strchrW(mask
, '<');
1225 for( i
=0; i
<MASK_MAX_GROUPS
; i
++ )
1227 /* stop at the end of the string */
1228 if( p
[0] == 0 || p
[0] == '>' )
1231 /* count the number of the same identifier */
1232 for( n
=0; p
[n
] == p
[0]; n
++ )
1234 info
->group
[i
].ofs
= total
;
1235 info
->group
[i
].type
= p
[0];
1239 total
++; /* an extra not part of the group */
1241 info
->group
[i
].len
= n
;
1246 TRACE("%d characters in %d groups\n", total
, i
);
1247 if( i
== MASK_MAX_GROUPS
)
1248 ERR("too many groups in PIDTemplate %s\n", debugstr_w(mask
));
1250 info
->num_chars
= total
;
1251 info
->num_groups
= i
;
1257 msi_maskedit_create_children( struct msi_maskedit_info
*info
, LPCWSTR font
)
1259 DWORD width
, height
, style
, wx
, ww
;
1264 style
= WS_CHILD
| WS_BORDER
| WS_VISIBLE
| WS_TABSTOP
| ES_AUTOHSCROLL
;
1266 GetClientRect( info
->hwnd
, &rect
);
1268 width
= rect
.right
- rect
.left
;
1269 height
= rect
.bottom
- rect
.top
;
1271 for( i
= 0; i
< info
->num_groups
; i
++ )
1273 if (!msi_mask_editable( info
->group
[i
].type
))
1275 wx
= (info
->group
[i
].ofs
* width
) / info
->num_chars
;
1276 ww
= (info
->group
[i
].len
* width
) / info
->num_chars
;
1278 hwnd
= CreateWindowW( szEdit
, NULL
, style
, wx
, 0, ww
, height
,
1279 info
->hwnd
, NULL
, NULL
, NULL
);
1282 ERR("failed to create mask edit sub window\n");
1286 SendMessageW( hwnd
, EM_LIMITTEXT
, info
->group
[i
].len
, 0 );
1288 msi_dialog_set_font( info
->dialog
, hwnd
,
1289 font
?font
:info
->dialog
->default_font
);
1290 info
->group
[i
].hwnd
= hwnd
;
1295 * office 2003 uses "73931<````=````=````=````=`````>@@@@@"
1296 * delphi 7 uses "<????-??????-??????-????>" and "<???-???>"
1297 * filemaker pro 7 uses "<^^^^=^^^^=^^^^=^^^^=^^^^=^^^^=^^^^^>"
1299 static UINT
msi_dialog_maskedit_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1301 LPWSTR font_mask
, val
= NULL
, font
;
1302 struct msi_maskedit_info
*info
= NULL
;
1303 UINT ret
= ERROR_SUCCESS
;
1304 msi_control
*control
;
1309 font_mask
= msi_get_deformatted_field( dialog
->package
, rec
, 10 );
1310 font
= msi_dialog_get_style( font_mask
, &mask
);
1313 ERR("mask template is empty\n");
1317 info
= msi_dialog_parse_groups( mask
);
1320 ERR("template %s is invalid\n", debugstr_w(mask
));
1324 info
->dialog
= dialog
;
1326 control
= msi_dialog_add_control( dialog
, rec
, szStatic
,
1327 SS_OWNERDRAW
| WS_GROUP
| WS_VISIBLE
);
1330 ERR("Failed to create maskedit container\n");
1331 ret
= ERROR_FUNCTION_FAILED
;
1334 SetWindowLongPtrW( control
->hwnd
, GWL_EXSTYLE
, WS_EX_CONTROLPARENT
);
1336 info
->hwnd
= control
->hwnd
;
1338 /* subclass the static control */
1339 info
->oldproc
= (WNDPROC
) SetWindowLongPtrW( info
->hwnd
, GWLP_WNDPROC
,
1340 (LONG_PTR
)MSIMaskedEdit_WndProc
);
1341 SetPropW( control
->hwnd
, szButtonData
, info
);
1343 prop
= MSI_RecordGetString( rec
, 9 );
1345 info
->prop
= strdupW( prop
);
1347 msi_maskedit_create_children( info
, font
);
1351 val
= msi_dup_property( dialog
->package
, prop
);
1354 msi_maskedit_set_text( info
, val
);
1360 if( ret
!= ERROR_SUCCESS
)
1362 msi_free( font_mask
);
1367 /******************** Progress Bar *****************************************/
1369 static UINT
msi_dialog_progress_bar( msi_dialog
*dialog
, MSIRECORD
*rec
)
1371 msi_dialog_add_control( dialog
, rec
, PROGRESS_CLASSW
, WS_VISIBLE
);
1372 return ERROR_SUCCESS
;
1375 /******************** Path Edit ********************************************/
1377 static LPWSTR
msi_get_window_text( HWND hwnd
)
1383 buf
= msi_alloc( sz
*sizeof(WCHAR
) );
1386 r
= GetWindowTextW( hwnd
, buf
, sz
);
1390 buf
= msi_realloc( buf
, sz
*sizeof(WCHAR
) );
1396 static UINT
msi_dialog_pathedit_handler( msi_dialog
*dialog
,
1397 msi_control
*control
, WPARAM param
)
1400 LPWSTR buf
, indirect
= NULL
;
1402 if( HIWORD(param
) != EN_KILLFOCUS
)
1403 return ERROR_SUCCESS
;
1405 prop
= control
->property
;
1406 if ( control
->attributes
& msidbControlAttributesIndirect
)
1408 indirect
= msi_dup_property( dialog
->package
, control
->property
);
1412 /* FIXME: verify the new path */
1413 buf
= msi_get_window_text( control
->hwnd
);
1414 MSI_SetPropertyW( dialog
->package
, prop
, buf
);
1416 TRACE("edit %s contents changed, set %s\n", debugstr_w(control
->name
),
1420 msi_free( indirect
);
1422 return ERROR_SUCCESS
;
1425 static void msi_dialog_update_pathedit( msi_dialog
*dialog
)
1427 msi_control
*control
;
1431 control
= msi_dialog_find_control( dialog
, szPathEdit
);
1432 indirect
= control
->attributes
& msidbControlAttributesIndirect
;
1433 prop
= msi_dialog_dup_property( dialog
, control
->property
, indirect
);
1435 path
= msi_dup_property( dialog
->package
, prop
);
1436 SetWindowTextW( control
->hwnd
, path
);
1437 SendMessageW( control
->hwnd
, EM_SETSEL
, 0, -1 );
1443 static UINT
msi_dialog_pathedit_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1445 msi_control
*control
;
1448 control
= msi_dialog_add_control( dialog
, rec
, szEdit
,
1449 WS_BORDER
| WS_TABSTOP
);
1450 control
->handler
= msi_dialog_pathedit_handler
;
1451 control
->attributes
= MSI_RecordGetInteger( rec
, 8 );
1453 prop
= MSI_RecordGetString( rec
, 9 );
1455 control
->property
= strdupW( prop
);
1457 msi_dialog_update_pathedit( dialog
);
1459 return ERROR_SUCCESS
;
1462 /* radio buttons are a bit different from normal controls */
1463 static UINT
msi_dialog_create_radiobutton( MSIRECORD
*rec
, LPVOID param
)
1465 radio_button_group_descr
*group
= (radio_button_group_descr
*)param
;
1466 msi_dialog
*dialog
= group
->dialog
;
1467 msi_control
*control
;
1468 LPCWSTR prop
, text
, name
;
1469 DWORD style
, attributes
= group
->attributes
;
1471 style
= WS_CHILD
| BS_AUTORADIOBUTTON
| BS_MULTILINE
| WS_TABSTOP
;
1472 name
= MSI_RecordGetString( rec
, 3 );
1473 text
= MSI_RecordGetString( rec
, 8 );
1474 if( attributes
& 1 )
1475 style
|= WS_VISIBLE
;
1476 if( ~attributes
& 2 )
1477 style
|= WS_DISABLED
;
1479 control
= msi_dialog_create_window( dialog
, rec
, 0, szButton
, name
, text
,
1480 style
, group
->parent
->hwnd
);
1482 return ERROR_FUNCTION_FAILED
;
1483 control
->handler
= msi_dialog_radiogroup_handler
;
1485 if (!lstrcmpW(control
->name
, group
->propval
))
1486 SendMessageW(control
->hwnd
, BM_SETCHECK
, BST_CHECKED
, 0);
1488 prop
= MSI_RecordGetString( rec
, 1 );
1490 control
->property
= strdupW( prop
);
1492 return ERROR_SUCCESS
;
1495 static UINT
msi_dialog_radiogroup_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1497 static const WCHAR query
[] = {
1498 'S','E','L','E','C','T',' ','*',' ',
1499 'F','R','O','M',' ','R','a','d','i','o','B','u','t','t','o','n',' ',
1500 'W','H','E','R','E',' ',
1501 '`','P','r','o','p','e','r','t','y','`',' ','=',' ','\'','%','s','\'',0};
1504 msi_control
*control
;
1505 MSIQUERY
*view
= NULL
;
1506 radio_button_group_descr group
;
1507 MSIPACKAGE
*package
= dialog
->package
;
1510 prop
= MSI_RecordGetString( rec
, 9 );
1512 TRACE("%p %p %s\n", dialog
, rec
, debugstr_w( prop
));
1514 /* Create parent group box to hold radio buttons */
1515 control
= msi_dialog_add_control( dialog
, rec
, szButton
, BS_OWNERDRAW
|WS_GROUP
);
1517 return ERROR_FUNCTION_FAILED
;
1519 oldproc
= (WNDPROC
) SetWindowLongPtrW( control
->hwnd
, GWLP_WNDPROC
,
1520 (LONG_PTR
)MSIRadioGroup_WndProc
);
1521 SetPropW(control
->hwnd
, szButtonData
, oldproc
);
1522 SetWindowLongPtrW( control
->hwnd
, GWL_EXSTYLE
, WS_EX_CONTROLPARENT
);
1525 control
->property
= strdupW( prop
);
1527 /* query the Radio Button table for all control in this group */
1528 r
= MSI_OpenQuery( package
->db
, &view
, query
, prop
);
1529 if( r
!= ERROR_SUCCESS
)
1531 ERR("query failed for dialog %s radio group %s\n",
1532 debugstr_w(dialog
->name
), debugstr_w(prop
));
1533 return ERROR_INVALID_PARAMETER
;
1536 group
.dialog
= dialog
;
1537 group
.parent
= control
;
1538 group
.attributes
= MSI_RecordGetInteger( rec
, 8 );
1539 group
.propval
= msi_dup_property( dialog
->package
, control
->property
);
1541 r
= MSI_IterateRecords( view
, 0, msi_dialog_create_radiobutton
, &group
);
1542 msiobj_release( &view
->hdr
);
1543 msi_free( group
.propval
);
1548 /******************** Selection Tree ***************************************/
1550 struct msi_selection_tree_info
1558 msi_seltree_sync_item_state( HWND hwnd
, MSIFEATURE
*feature
, HTREEITEM hItem
)
1562 TRACE("Feature %s -> %d %d %d\n", debugstr_w(feature
->Title
),
1563 feature
->Installed
, feature
->Action
, feature
->ActionRequest
);
1565 tvi
.mask
= TVIF_STATE
;
1567 tvi
.state
= INDEXTOSTATEIMAGEMASK( feature
->Action
);
1568 tvi
.stateMask
= TVIS_STATEIMAGEMASK
;
1570 SendMessageW( hwnd
, TVM_SETITEMW
, 0, (LPARAM
) &tvi
);
1574 msi_seltree_popup_menu( HWND hwnd
, INT x
, INT y
)
1579 /* create a menu to display */
1580 hMenu
= CreatePopupMenu();
1582 /* FIXME: load strings from resources */
1583 AppendMenuA( hMenu
, MF_ENABLED
, INSTALLSTATE_LOCAL
, "Install feature locally");
1584 AppendMenuA( hMenu
, MF_GRAYED
, 0x1000, "Install entire feature");
1585 AppendMenuA( hMenu
, MF_ENABLED
, INSTALLSTATE_ADVERTISED
, "Install on demand");
1586 AppendMenuA( hMenu
, MF_ENABLED
, INSTALLSTATE_ABSENT
, "Don't install");
1587 r
= TrackPopupMenu( hMenu
, TPM_LEFTALIGN
| TPM_TOPALIGN
| TPM_RETURNCMD
,
1588 x
, y
, 0, hwnd
, NULL
);
1589 DestroyMenu( hMenu
);
1594 msi_seltree_feature_from_item( HWND hwnd
, HTREEITEM hItem
)
1598 /* get the feature from the item */
1599 memset( &tvi
, 0, sizeof tvi
);
1601 tvi
.mask
= TVIF_PARAM
| TVIF_HANDLE
;
1602 SendMessageW( hwnd
, TVM_GETITEMW
, 0, (LPARAM
) &tvi
);
1604 return (MSIFEATURE
*) tvi
.lParam
;
1608 msi_seltree_menu( HWND hwnd
, HTREEITEM hItem
)
1610 MSIFEATURE
*feature
;
1619 feature
= msi_seltree_feature_from_item( hwnd
, hItem
);
1622 ERR("item %p feature was NULL\n", hItem
);
1626 /* get the item's rectangle to put the menu just below it */
1628 SendMessageW( hwnd
, TVM_GETITEMRECT
, 0, (LPARAM
) &u
.rc
);
1629 MapWindowPoints( hwnd
, NULL
, u
.pt
, 2 );
1631 r
= msi_seltree_popup_menu( hwnd
, u
.rc
.left
, u
.rc
.top
);
1635 case INSTALLSTATE_LOCAL
:
1636 case INSTALLSTATE_ADVERTISED
:
1637 case INSTALLSTATE_ABSENT
:
1638 feature
->ActionRequest
= r
;
1639 feature
->Action
= r
;
1642 FIXME("select feature and all children\n");
1646 msi_seltree_sync_item_state( hwnd
, feature
, hItem
);
1648 /* update the feature's components */
1649 LIST_FOR_EACH_ENTRY( cl
, &feature
->Components
, ComponentList
, entry
)
1651 cl
->component
->Action
= feature
->Action
;
1652 cl
->component
->ActionRequest
= feature
->ActionRequest
;
1658 static LRESULT WINAPI
1659 MSISelectionTree_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1661 struct msi_selection_tree_info
*info
;
1662 TVHITTESTINFO tvhti
;
1665 TRACE("%p %04x %08x %08lx\n", hWnd
, msg
, wParam
, lParam
);
1667 info
= GetPropW(hWnd
, szButtonData
);
1671 case WM_LBUTTONDOWN
:
1672 tvhti
.pt
.x
= LOWORD( lParam
);
1673 tvhti
.pt
.y
= HIWORD( lParam
);
1676 r
= CallWindowProcW(info
->oldproc
, hWnd
, TVM_HITTEST
, 0, (LPARAM
) &tvhti
);
1677 if (tvhti
.flags
& TVHT_ONITEMSTATEICON
)
1678 return msi_seltree_menu( hWnd
, tvhti
.hItem
);
1682 r
= CallWindowProcW(info
->oldproc
, hWnd
, msg
, wParam
, lParam
);
1688 RemovePropW( hWnd
, szButtonData
);
1695 msi_seltree_add_child_features( MSIPACKAGE
*package
, HWND hwnd
,
1696 LPCWSTR parent
, HTREEITEM hParent
)
1698 MSIFEATURE
*feature
;
1699 TVINSERTSTRUCTW tvis
;
1702 LIST_FOR_EACH_ENTRY( feature
, &package
->features
, MSIFEATURE
, entry
)
1704 if ( lstrcmpW( parent
, feature
->Feature_Parent
) )
1707 if ( !feature
->Title
)
1710 if ( !feature
->Display
)
1713 memset( &tvis
, 0, sizeof tvis
);
1714 tvis
.hParent
= hParent
;
1715 tvis
.hInsertAfter
= TVI_LAST
;
1716 tvis
.u
.item
.mask
= TVIF_TEXT
| TVIF_PARAM
;
1717 tvis
.u
.item
.pszText
= feature
->Title
;
1718 tvis
.u
.item
.lParam
= (LPARAM
) feature
;
1720 hitem
= (HTREEITEM
) SendMessageW( hwnd
, TVM_INSERTITEMW
, 0, (LPARAM
) &tvis
);
1724 msi_seltree_sync_item_state( hwnd
, feature
, hitem
);
1725 msi_seltree_add_child_features( package
, hwnd
,
1726 feature
->Feature
, hitem
);
1728 /* the node is expanded if Display is odd */
1729 if ( feature
->Display
% 2 != 0 )
1730 SendMessageW( hwnd
, TVM_EXPAND
, TVE_EXPAND
, (LPARAM
) hitem
);
1734 static void msi_seltree_create_imagelist( HWND hwnd
)
1736 const int bm_width
= 32, bm_height
= 16, bm_count
= 3;
1737 const int bm_resource
= 0x1001;
1742 himl
= ImageList_Create( bm_width
, bm_height
, FALSE
, 4, 0 );
1745 ERR("failed to create image list\n");
1749 for (i
=0; i
<bm_count
; i
++)
1751 hbmp
= LoadBitmapW( msi_hInstance
, MAKEINTRESOURCEW(i
+bm_resource
) );
1754 ERR("failed to load bitmap %d\n", i
);
1759 * Add a dummy bitmap at offset zero because the treeview
1760 * can't use it as a state mask (zero means no user state).
1763 ImageList_Add( himl
, hbmp
, NULL
);
1765 ImageList_Add( himl
, hbmp
, NULL
);
1768 SendMessageW( hwnd
, TVM_SETIMAGELIST
, TVSIL_STATE
, (LPARAM
)himl
);
1771 static UINT
msi_dialog_selection_tree( msi_dialog
*dialog
, MSIRECORD
*rec
)
1773 msi_control
*control
;
1775 MSIPACKAGE
*package
= dialog
->package
;
1777 struct msi_selection_tree_info
*info
;
1779 info
= msi_alloc( sizeof *info
);
1781 return ERROR_FUNCTION_FAILED
;
1783 /* create the treeview control */
1784 prop
= MSI_RecordGetString( rec
, 9 );
1785 style
= TVS_HASLINES
| TVS_HASBUTTONS
| TVS_LINESATROOT
;
1786 style
|= WS_GROUP
| WS_VSCROLL
;
1787 control
= msi_dialog_add_control( dialog
, rec
, WC_TREEVIEWW
, style
);
1791 return ERROR_FUNCTION_FAILED
;
1795 info
->dialog
= dialog
;
1796 info
->hwnd
= control
->hwnd
;
1797 info
->oldproc
= (WNDPROC
) SetWindowLongPtrW( control
->hwnd
, GWLP_WNDPROC
,
1798 (LONG_PTR
)MSISelectionTree_WndProc
);
1799 SetPropW( control
->hwnd
, szButtonData
, info
);
1802 msi_seltree_create_imagelist( control
->hwnd
);
1803 msi_seltree_add_child_features( package
, control
->hwnd
, NULL
, NULL
);
1805 return ERROR_SUCCESS
;
1808 /******************** Group Box ***************************************/
1810 static UINT
msi_dialog_group_box( msi_dialog
*dialog
, MSIRECORD
*rec
)
1812 msi_control
*control
;
1815 style
= BS_GROUPBOX
| WS_CHILD
| WS_GROUP
;
1816 control
= msi_dialog_add_control( dialog
, rec
, WC_BUTTONW
, style
);
1818 return ERROR_FUNCTION_FAILED
;
1820 return ERROR_SUCCESS
;
1823 /******************** List Box ***************************************/
1825 struct msi_listbox_item
1831 struct msi_listbox_info
1837 struct msi_listbox_item
*items
;
1840 static LRESULT WINAPI
MSIListBox_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1842 struct msi_listbox_info
*info
;
1846 TRACE("%p %04x %08x %08lx\n", hWnd
, msg
, wParam
, lParam
);
1848 info
= GetPropW( hWnd
, szButtonData
);
1852 r
= CallWindowProcW( info
->oldproc
, hWnd
, msg
, wParam
, lParam
);
1857 for (j
= 0; j
< info
->num_items
; j
++)
1859 msi_free( info
->items
[j
].property
);
1860 msi_free( info
->items
[j
].value
);
1862 msi_free( info
->items
);
1864 RemovePropW( hWnd
, szButtonData
);
1871 static UINT
msi_listbox_add_item( MSIRECORD
*rec
, LPVOID param
)
1873 struct msi_listbox_info
*info
= param
;
1874 struct msi_listbox_item
*item
;
1875 LPCWSTR property
, value
, text
;
1876 static int index
= 0;
1878 item
= &info
->items
[index
++];
1879 property
= MSI_RecordGetString( rec
, 1 );
1880 value
= MSI_RecordGetString( rec
, 3 );
1881 text
= MSI_RecordGetString( rec
, 4 );
1883 item
->property
= strdupW( property
);
1884 item
->value
= strdupW( value
);
1886 SendMessageW( info
->hwnd
, LB_ADDSTRING
, 0, (LPARAM
)text
);
1888 return ERROR_SUCCESS
;
1891 static UINT
msi_listbox_add_items( struct msi_listbox_info
*info
)
1894 MSIQUERY
*view
= NULL
;
1897 static const WCHAR query
[] = {
1898 'S','E','L','E','C','T',' ','*',' ',
1899 'F','R','O','M',' ','`','L','i','s','t','B','o','x','`',' ',
1900 'O','R','D','E','R',' ','B','Y',' ','`','O','r','d','e','r','`',0
1903 r
= MSI_OpenQuery( info
->dialog
->package
->db
, &view
, query
);
1904 if ( r
!= ERROR_SUCCESS
)
1907 /* just get the number of records */
1908 r
= MSI_IterateRecords( view
, &count
, NULL
, NULL
);
1910 info
->num_items
= count
;
1911 info
->items
= msi_alloc( sizeof(*info
->items
) * count
);
1913 r
= MSI_IterateRecords( view
, NULL
, msi_listbox_add_item
, info
);
1914 msiobj_release( &view
->hdr
);
1919 static UINT
msi_dialog_listbox_handler( msi_dialog
*dialog
,
1920 msi_control
*control
, WPARAM param
)
1922 struct msi_listbox_info
*info
;
1925 if( HIWORD(param
) != LBN_SELCHANGE
)
1926 return ERROR_SUCCESS
;
1928 info
= GetPropW( control
->hwnd
, szButtonData
);
1929 index
= SendMessageW( control
->hwnd
, LB_GETCURSEL
, 0, 0 );
1931 MSI_SetPropertyW( info
->dialog
->package
,
1932 info
->items
[index
].property
, info
->items
[index
].value
);
1933 msi_dialog_evaluate_control_conditions( info
->dialog
);
1935 return ERROR_SUCCESS
;
1938 static UINT
msi_dialog_list_box( msi_dialog
*dialog
, MSIRECORD
*rec
)
1940 struct msi_listbox_info
*info
;
1941 msi_control
*control
;
1944 info
= msi_alloc( sizeof *info
);
1946 return ERROR_FUNCTION_FAILED
;
1948 style
= WS_TABSTOP
| WS_GROUP
| WS_CHILD
| LBS_STANDARD
;
1949 control
= msi_dialog_add_control( dialog
, rec
, WC_LISTBOXW
, style
);
1951 return ERROR_FUNCTION_FAILED
;
1953 control
->handler
= msi_dialog_listbox_handler
;
1956 info
->dialog
= dialog
;
1957 info
->hwnd
= control
->hwnd
;
1959 info
->oldproc
= (WNDPROC
)SetWindowLongPtrW( control
->hwnd
, GWLP_WNDPROC
,
1960 (LONG_PTR
)MSIListBox_WndProc
);
1961 SetPropW( control
->hwnd
, szButtonData
, info
);
1963 msi_listbox_add_items( info
);
1965 return ERROR_SUCCESS
;
1968 /******************** Directory Combo ***************************************/
1970 static void msi_dialog_update_directory_combo( msi_dialog
*dialog
)
1972 msi_control
*control
;
1976 control
= msi_dialog_find_control( dialog
, szDirectoryCombo
);
1977 indirect
= control
->attributes
& msidbControlAttributesIndirect
;
1978 prop
= msi_dialog_dup_property( dialog
, control
->property
, indirect
);
1979 path
= msi_dup_property( dialog
->package
, prop
);
1981 PathStripPathW( path
);
1982 PathRemoveBackslashW( path
);
1984 SendMessageW( control
->hwnd
, CB_INSERTSTRING
, 0, (LPARAM
)path
);
1985 SendMessageW( control
->hwnd
, CB_SETCURSEL
, 0, 0 );
1991 static UINT
msi_dialog_directory_combo( msi_dialog
*dialog
, MSIRECORD
*rec
)
1993 msi_control
*control
;
1997 /* FIXME: use CBS_OWNERDRAWFIXED and add owner draw code */
1998 style
= CBS_DROPDOWNLIST
| CBS_HASSTRINGS
| WS_CHILD
|
1999 WS_GROUP
| WS_TABSTOP
| WS_VSCROLL
;
2000 control
= msi_dialog_add_control( dialog
, rec
, WC_COMBOBOXW
, style
);
2002 return ERROR_FUNCTION_FAILED
;
2004 control
->attributes
= MSI_RecordGetInteger( rec
, 8 );
2005 prop
= MSI_RecordGetString( rec
, 9 );
2006 control
->property
= msi_dialog_dup_property( dialog
, prop
, FALSE
);
2008 msi_dialog_update_directory_combo( dialog
);
2010 return ERROR_SUCCESS
;
2013 /******************** Directory List ***************************************/
2015 UINT
msi_dialog_directorylist_up( msi_dialog
*dialog
)
2017 msi_control
*control
;
2018 LPWSTR prop
, path
, ptr
;
2021 control
= msi_dialog_find_control( dialog
, szDirectoryList
);
2022 indirect
= control
->attributes
& msidbControlAttributesIndirect
;
2023 prop
= msi_dialog_dup_property( dialog
, control
->property
, indirect
);
2025 path
= msi_dup_property( dialog
->package
, prop
);
2027 /* strip off the last directory */
2028 ptr
= PathFindFileNameW( path
);
2029 if (ptr
!= path
) *(ptr
- 1) = '\0';
2030 PathAddBackslashW( path
);
2032 MSI_SetPropertyW( dialog
->package
, prop
, path
);
2034 msi_dialog_update_directory_combo( dialog
);
2035 msi_dialog_update_pathedit( dialog
);
2040 return ERROR_SUCCESS
;
2043 static UINT
msi_dialog_directory_list( msi_dialog
*dialog
, MSIRECORD
*rec
)
2045 msi_control
*control
;
2049 style
= LVS_LIST
| LVS_EDITLABELS
| WS_VSCROLL
| LVS_SHAREIMAGELISTS
|
2050 LVS_AUTOARRANGE
| LVS_SINGLESEL
| WS_BORDER
|
2051 LVS_SORTASCENDING
| WS_CHILD
| WS_GROUP
| WS_TABSTOP
;
2052 control
= msi_dialog_add_control( dialog
, rec
, WC_LISTVIEWW
, style
);
2054 return ERROR_FUNCTION_FAILED
;
2056 control
->attributes
= MSI_RecordGetInteger( rec
, 8 );
2057 prop
= MSI_RecordGetString( rec
, 9 );
2058 control
->property
= msi_dialog_dup_property( dialog
, prop
, FALSE
);
2060 return ERROR_SUCCESS
;
2063 /******************** VolumeCost List ***************************************/
2065 static UINT
msi_dialog_volumecost_list( msi_dialog
*dialog
, MSIRECORD
*rec
)
2067 msi_control
*control
;
2070 style
= LVS_REPORT
| WS_VSCROLL
| WS_HSCROLL
| LVS_SHAREIMAGELISTS
|
2071 LVS_AUTOARRANGE
| LVS_SINGLESEL
| WS_BORDER
|
2072 WS_CHILD
| WS_TABSTOP
| WS_GROUP
;
2073 control
= msi_dialog_add_control( dialog
, rec
, WC_LISTVIEWW
, style
);
2075 return ERROR_FUNCTION_FAILED
;
2077 return ERROR_SUCCESS
;
2080 static const struct control_handler msi_dialog_handler
[] =
2082 { szText
, msi_dialog_text_control
},
2083 { szPushButton
, msi_dialog_button_control
},
2084 { szLine
, msi_dialog_line_control
},
2085 { szBitmap
, msi_dialog_bitmap_control
},
2086 { szCheckBox
, msi_dialog_checkbox_control
},
2087 { szScrollableText
, msi_dialog_scrolltext_control
},
2088 { szComboBox
, msi_dialog_combo_control
},
2089 { szEdit
, msi_dialog_edit_control
},
2090 { szMaskedEdit
, msi_dialog_maskedit_control
},
2091 { szPathEdit
, msi_dialog_pathedit_control
},
2092 { szProgressBar
, msi_dialog_progress_bar
},
2093 { szRadioButtonGroup
, msi_dialog_radiogroup_control
},
2094 { szIcon
, msi_dialog_icon_control
},
2095 { szSelectionTree
, msi_dialog_selection_tree
},
2096 { szGroupBox
, msi_dialog_group_box
},
2097 { szListBox
, msi_dialog_list_box
},
2098 { szDirectoryCombo
, msi_dialog_directory_combo
},
2099 { szDirectoryList
, msi_dialog_directory_list
},
2100 { szVolumeCostList
, msi_dialog_volumecost_list
},
2103 #define NUM_CONTROL_TYPES (sizeof msi_dialog_handler/sizeof msi_dialog_handler[0])
2105 static UINT
msi_dialog_create_controls( MSIRECORD
*rec
, LPVOID param
)
2107 msi_dialog
*dialog
= param
;
2108 LPCWSTR control_type
;
2111 /* find and call the function that can create this type of control */
2112 control_type
= MSI_RecordGetString( rec
, 3 );
2113 for( i
=0; i
<NUM_CONTROL_TYPES
; i
++ )
2114 if (!strcmpiW( msi_dialog_handler
[i
].control_type
, control_type
))
2116 if( i
!= NUM_CONTROL_TYPES
)
2117 msi_dialog_handler
[i
].func( dialog
, rec
);
2119 ERR("no handler for element type %s\n", debugstr_w(control_type
));
2121 return ERROR_SUCCESS
;
2124 static UINT
msi_dialog_fill_controls( msi_dialog
*dialog
)
2126 static const WCHAR query
[] = {
2127 'S','E','L','E','C','T',' ','*',' ',
2128 'F','R','O','M',' ','C','o','n','t','r','o','l',' ',
2129 'W','H','E','R','E',' ',
2130 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',0};
2132 MSIQUERY
*view
= NULL
;
2133 MSIPACKAGE
*package
= dialog
->package
;
2135 TRACE("%p %s\n", dialog
, debugstr_w(dialog
->name
) );
2137 /* query the Control table for all the elements of the control */
2138 r
= MSI_OpenQuery( package
->db
, &view
, query
, dialog
->name
);
2139 if( r
!= ERROR_SUCCESS
)
2141 ERR("query failed for dialog %s\n", debugstr_w(dialog
->name
));
2142 return ERROR_INVALID_PARAMETER
;
2145 r
= MSI_IterateRecords( view
, 0, msi_dialog_create_controls
, dialog
);
2146 msiobj_release( &view
->hdr
);
2151 static UINT
msi_dialog_set_control_condition( MSIRECORD
*rec
, LPVOID param
)
2153 static const WCHAR szHide
[] = { 'H','i','d','e',0 };
2154 static const WCHAR szShow
[] = { 'S','h','o','w',0 };
2155 static const WCHAR szDisable
[] = { 'D','i','s','a','b','l','e',0 };
2156 static const WCHAR szEnable
[] = { 'E','n','a','b','l','e',0 };
2157 msi_dialog
*dialog
= param
;
2158 msi_control
*control
;
2159 LPCWSTR name
, action
, condition
;
2162 name
= MSI_RecordGetString( rec
, 2 );
2163 action
= MSI_RecordGetString( rec
, 3 );
2164 condition
= MSI_RecordGetString( rec
, 4 );
2165 r
= MSI_EvaluateConditionW( dialog
->package
, condition
);
2166 control
= msi_dialog_find_control( dialog
, name
);
2167 if( r
== MSICONDITION_TRUE
&& control
)
2169 TRACE("%s control %s\n", debugstr_w(action
), debugstr_w(name
));
2171 /* FIXME: case sensitive? */
2172 if(!lstrcmpW(action
, szHide
))
2173 ShowWindow(control
->hwnd
, SW_HIDE
);
2174 else if(!strcmpW(action
, szShow
))
2175 ShowWindow(control
->hwnd
, SW_SHOW
);
2176 else if(!strcmpW(action
, szDisable
))
2177 EnableWindow(control
->hwnd
, FALSE
);
2178 else if(!strcmpW(action
, szEnable
))
2179 EnableWindow(control
->hwnd
, TRUE
);
2181 FIXME("Unhandled action %s\n", debugstr_w(action
));
2184 return ERROR_SUCCESS
;
2187 static UINT
msi_dialog_evaluate_control_conditions( msi_dialog
*dialog
)
2189 static const WCHAR query
[] = {
2190 'S','E','L','E','C','T',' ','*',' ',
2191 'F','R','O','M',' ',
2192 'C','o','n','t','r','o','l','C','o','n','d','i','t','i','o','n',' ',
2193 'W','H','E','R','E',' ',
2194 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',0
2197 MSIQUERY
*view
= NULL
;
2198 MSIPACKAGE
*package
= dialog
->package
;
2200 TRACE("%p %s\n", dialog
, debugstr_w(dialog
->name
) );
2202 /* query the Control table for all the elements of the control */
2203 r
= MSI_OpenQuery( package
->db
, &view
, query
, dialog
->name
);
2204 if( r
!= ERROR_SUCCESS
)
2206 ERR("query failed for dialog %s\n", debugstr_w(dialog
->name
));
2207 return ERROR_INVALID_PARAMETER
;
2210 r
= MSI_IterateRecords( view
, 0, msi_dialog_set_control_condition
, dialog
);
2211 msiobj_release( &view
->hdr
);
2216 UINT
msi_dialog_reset( msi_dialog
*dialog
)
2218 /* FIXME: should restore the original values of any properties we changed */
2219 return msi_dialog_evaluate_control_conditions( dialog
);
2222 /* figure out the height of 10 point MS Sans Serif */
2223 static INT
msi_dialog_get_sans_serif_height( HWND hwnd
)
2225 static const WCHAR szSansSerif
[] = {
2226 'M','S',' ','S','a','n','s',' ','S','e','r','i','f',0 };
2231 HFONT hFont
, hOldFont
;
2234 hdc
= GetDC( hwnd
);
2237 memset( &lf
, 0, sizeof lf
);
2238 lf
.lfHeight
= MulDiv(10, GetDeviceCaps(hdc
, LOGPIXELSY
), 72);
2239 strcpyW( lf
.lfFaceName
, szSansSerif
);
2240 hFont
= CreateFontIndirectW(&lf
);
2243 hOldFont
= SelectObject( hdc
, hFont
);
2244 r
= GetTextMetricsW( hdc
, &tm
);
2246 height
= tm
.tmHeight
;
2247 SelectObject( hdc
, hOldFont
);
2248 DeleteObject( hFont
);
2250 ReleaseDC( hwnd
, hdc
);
2255 /* fetch the associated record from the Dialog table */
2256 static MSIRECORD
*msi_get_dialog_record( msi_dialog
*dialog
)
2258 static const WCHAR query
[] = {
2259 'S','E','L','E','C','T',' ','*',' ',
2260 'F','R','O','M',' ','D','i','a','l','o','g',' ',
2261 'W','H','E','R','E',' ',
2262 '`','D','i','a','l','o','g','`',' ','=',' ','\'','%','s','\'',0};
2263 MSIPACKAGE
*package
= dialog
->package
;
2264 MSIRECORD
*rec
= NULL
;
2266 TRACE("%p %s\n", dialog
, debugstr_w(dialog
->name
) );
2268 rec
= MSI_QueryGetRecord( package
->db
, query
, dialog
->name
);
2270 ERR("query failed for dialog %s\n", debugstr_w(dialog
->name
));
2275 static void msi_dialog_adjust_dialog_pos( msi_dialog
*dialog
, MSIRECORD
*rec
, LPRECT pos
)
2277 static const WCHAR szScreenX
[] = {'S','c','r','e','e','n','X',0};
2278 static const WCHAR szScreenY
[] = {'S','c','r','e','e','n','Y',0};
2285 center
.x
= MSI_RecordGetInteger( rec
, 2 );
2286 center
.y
= MSI_RecordGetInteger( rec
, 3 );
2288 sz
.cx
= MSI_RecordGetInteger( rec
, 4 );
2289 sz
.cy
= MSI_RecordGetInteger( rec
, 5 );
2291 sz
.cx
= msi_dialog_scale_unit( dialog
, sz
.cx
);
2292 sz
.cy
= msi_dialog_scale_unit( dialog
, sz
.cy
);
2294 xres
= msi_get_property_int( dialog
->package
, szScreenX
, 0 );
2295 yres
= msi_get_property_int( dialog
->package
, szScreenY
, 0 );
2297 center
.x
= MulDiv( center
.x
, xres
, 100 );
2298 center
.y
= MulDiv( center
.y
, yres
, 100 );
2300 /* turn the client pos into the window rectangle */
2301 pos
->left
= center
.x
- sz
.cx
/2;
2302 pos
->right
= pos
->left
+ sz
.cx
;
2303 pos
->top
= center
.y
- sz
.cy
/2;
2304 pos
->bottom
= pos
->top
+ sz
.cy
;
2306 TRACE("%lu %lu %lu %lu\n", pos
->left
, pos
->top
, pos
->right
, pos
->bottom
);
2308 style
= GetWindowLongPtrW( dialog
->hwnd
, GWL_STYLE
);
2309 AdjustWindowRect( pos
, style
, FALSE
);
2312 static BOOL
msi_control_set_next( msi_control
*control
, msi_control
*next
)
2314 return SetWindowPos( next
->hwnd
, control
->hwnd
, 0, 0, 0, 0,
2315 SWP_NOMOVE
| SWP_NOOWNERZORDER
| SWP_NOREDRAW
|
2316 SWP_NOREPOSITION
| SWP_NOSENDCHANGING
| SWP_NOSIZE
);
2319 static UINT
msi_dialog_set_tab_order( msi_dialog
*dialog
)
2321 msi_control
*control
, *tab_next
;
2323 LIST_FOR_EACH_ENTRY( control
, &dialog
->controls
, msi_control
, entry
)
2325 tab_next
= msi_dialog_find_control( dialog
, control
->tabnext
);
2328 msi_control_set_next( control
, tab_next
);
2331 return ERROR_SUCCESS
;
2334 static void msi_dialog_set_first_control( msi_dialog
* dialog
, LPCWSTR name
)
2336 msi_control
*control
;
2338 control
= msi_dialog_find_control( dialog
, name
);
2340 dialog
->hWndFocus
= control
->hwnd
;
2342 dialog
->hWndFocus
= NULL
;
2345 static LRESULT
msi_dialog_oncreate( HWND hwnd
, LPCREATESTRUCTW cs
)
2347 static const WCHAR df
[] = {
2348 'D','e','f','a','u','l','t','U','I','F','o','n','t',0 };
2349 static const WCHAR dfv
[] = {
2350 'M','S',' ','S','h','e','l','l',' ','D','l','g',0 };
2351 msi_dialog
*dialog
= (msi_dialog
*) cs
->lpCreateParams
;
2352 MSIRECORD
*rec
= NULL
;
2353 LPWSTR title
= NULL
;
2356 TRACE("%p %p\n", dialog
, dialog
->package
);
2358 dialog
->hwnd
= hwnd
;
2359 SetWindowLongPtrW( hwnd
, GWLP_USERDATA
, (LONG_PTR
) dialog
);
2361 rec
= msi_get_dialog_record( dialog
);
2364 TRACE("No record found for dialog %s\n", debugstr_w(dialog
->name
));
2368 dialog
->scale
= msi_dialog_get_sans_serif_height(dialog
->hwnd
);
2370 msi_dialog_adjust_dialog_pos( dialog
, rec
, &pos
);
2372 dialog
->attributes
= MSI_RecordGetInteger( rec
, 6 );
2374 dialog
->default_font
= msi_dup_property( dialog
->package
, df
);
2375 if (!dialog
->default_font
)
2377 dialog
->default_font
= strdupW(dfv
);
2378 if (!dialog
->default_font
) return -1;
2381 title
= msi_get_deformatted_field( dialog
->package
, rec
, 7 );
2382 SetWindowTextW( hwnd
, title
);
2385 SetWindowPos( hwnd
, 0, pos
.left
, pos
.top
,
2386 pos
.right
- pos
.left
, pos
.bottom
- pos
.top
,
2387 SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_NOREDRAW
);
2389 msi_dialog_build_font_list( dialog
);
2390 msi_dialog_fill_controls( dialog
);
2391 msi_dialog_evaluate_control_conditions( dialog
);
2392 msi_dialog_set_tab_order( dialog
);
2393 msi_dialog_set_first_control( dialog
, MSI_RecordGetString( rec
, 8 ) );
2394 msiobj_release( &rec
->hdr
);
2399 static UINT
msi_dialog_send_event( msi_dialog
*dialog
, LPCWSTR event
, LPCWSTR arg
)
2401 LPWSTR event_fmt
= NULL
, arg_fmt
= NULL
;
2403 TRACE("Sending control event %s %s\n", debugstr_w(event
), debugstr_w(arg
));
2405 deformat_string( dialog
->package
, event
, &event_fmt
);
2406 deformat_string( dialog
->package
, arg
, &arg_fmt
);
2408 dialog
->event_handler( dialog
->package
, event_fmt
, arg_fmt
, dialog
);
2410 msi_free( event_fmt
);
2411 msi_free( arg_fmt
);
2413 return ERROR_SUCCESS
;
2416 static UINT
msi_dialog_set_property( msi_dialog
*dialog
, LPCWSTR event
, LPCWSTR arg
)
2418 static const WCHAR szNullArg
[] = { '{','}',0 };
2419 LPWSTR p
, prop
, arg_fmt
= NULL
;
2422 len
= strlenW(event
);
2423 prop
= msi_alloc( len
*sizeof(WCHAR
));
2424 strcpyW( prop
, &event
[1] );
2425 p
= strchrW( prop
, ']' );
2426 if( p
&& p
[1] == 0 )
2429 if( strcmpW( szNullArg
, arg
) )
2430 deformat_string( dialog
->package
, arg
, &arg_fmt
);
2431 MSI_SetPropertyW( dialog
->package
, prop
, arg_fmt
);
2432 msi_free( arg_fmt
);
2435 ERR("Badly formatted property string - what happens?\n");
2437 return ERROR_SUCCESS
;
2440 static UINT
msi_dialog_control_event( MSIRECORD
*rec
, LPVOID param
)
2442 msi_dialog
*dialog
= param
;
2443 LPCWSTR condition
, event
, arg
;
2446 condition
= MSI_RecordGetString( rec
, 5 );
2447 r
= MSI_EvaluateConditionW( dialog
->package
, condition
);
2448 if( r
== MSICONDITION_TRUE
|| r
== MSICONDITION_NONE
)
2450 event
= MSI_RecordGetString( rec
, 3 );
2451 arg
= MSI_RecordGetString( rec
, 4 );
2452 if( event
[0] == '[' )
2453 msi_dialog_set_property( dialog
, event
, arg
);
2455 msi_dialog_send_event( dialog
, event
, arg
);
2458 return ERROR_SUCCESS
;
2461 static UINT
msi_dialog_button_handler( msi_dialog
*dialog
,
2462 msi_control
*control
, WPARAM param
)
2464 static const WCHAR query
[] = {
2465 'S','E','L','E','C','T',' ','*',' ',
2466 'F','R','O','M',' ','C','o','n','t','r','o','l','E','v','e','n','t',' ',
2467 'W','H','E','R','E',' ',
2468 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',' ',
2470 '`','C','o','n','t','r','o','l','_','`',' ','=',' ','\'','%','s','\'',' ',
2471 'O','R','D','E','R',' ','B','Y',' ','`','O','r','d','e','r','i','n','g','`',0
2473 MSIQUERY
*view
= NULL
;
2476 if( HIWORD(param
) != BN_CLICKED
)
2477 return ERROR_SUCCESS
;
2479 r
= MSI_OpenQuery( dialog
->package
->db
, &view
, query
,
2480 dialog
->name
, control
->name
);
2481 if( r
!= ERROR_SUCCESS
)
2483 ERR("query failed\n");
2487 r
= MSI_IterateRecords( view
, 0, msi_dialog_control_event
, dialog
);
2488 msiobj_release( &view
->hdr
);
2493 static UINT
msi_dialog_get_checkbox_state( msi_dialog
*dialog
,
2494 msi_control
*control
)
2496 WCHAR state
[2] = { 0 };
2499 MSI_GetPropertyW( dialog
->package
, control
->property
, state
, &sz
);
2500 return state
[0] ? 1 : 0;
2503 static void msi_dialog_set_checkbox_state( msi_dialog
*dialog
,
2504 msi_control
*control
, UINT state
)
2506 static const WCHAR szState
[] = { '1', 0 };
2509 /* if uncheck then the property is set to NULL */
2512 MSI_SetPropertyW( dialog
->package
, control
->property
, NULL
);
2516 /* check for a custom state */
2517 if (control
->value
&& control
->value
[0])
2518 val
= control
->value
;
2522 MSI_SetPropertyW( dialog
->package
, control
->property
, val
);
2525 static void msi_dialog_checkbox_sync_state( msi_dialog
*dialog
,
2526 msi_control
*control
)
2530 state
= msi_dialog_get_checkbox_state( dialog
, control
);
2531 SendMessageW( control
->hwnd
, BM_SETCHECK
,
2532 state
? BST_CHECKED
: BST_UNCHECKED
, 0 );
2535 static UINT
msi_dialog_checkbox_handler( msi_dialog
*dialog
,
2536 msi_control
*control
, WPARAM param
)
2540 if( HIWORD(param
) != BN_CLICKED
)
2541 return ERROR_SUCCESS
;
2543 TRACE("clicked checkbox %s, set %s\n", debugstr_w(control
->name
),
2544 debugstr_w(control
->property
));
2546 state
= msi_dialog_get_checkbox_state( dialog
, control
);
2547 state
= state
? 0 : 1;
2548 msi_dialog_set_checkbox_state( dialog
, control
, state
);
2549 msi_dialog_checkbox_sync_state( dialog
, control
);
2551 return msi_dialog_button_handler( dialog
, control
, param
);
2554 static UINT
msi_dialog_edit_handler( msi_dialog
*dialog
,
2555 msi_control
*control
, WPARAM param
)
2559 if( HIWORD(param
) != EN_CHANGE
)
2560 return ERROR_SUCCESS
;
2562 TRACE("edit %s contents changed, set %s\n", debugstr_w(control
->name
),
2563 debugstr_w(control
->property
));
2565 buf
= msi_get_window_text( control
->hwnd
);
2566 MSI_SetPropertyW( dialog
->package
, control
->property
, buf
);
2570 return ERROR_SUCCESS
;
2573 static UINT
msi_dialog_radiogroup_handler( msi_dialog
*dialog
,
2574 msi_control
*control
, WPARAM param
)
2576 if( HIWORD(param
) != BN_CLICKED
)
2577 return ERROR_SUCCESS
;
2579 TRACE("clicked radio button %s, set %s\n", debugstr_w(control
->name
),
2580 debugstr_w(control
->property
));
2582 MSI_SetPropertyW( dialog
->package
, control
->property
, control
->name
);
2584 return msi_dialog_button_handler( dialog
, control
, param
);
2587 static LRESULT
msi_dialog_oncommand( msi_dialog
*dialog
, WPARAM param
, HWND hwnd
)
2589 msi_control
*control
= NULL
;
2591 TRACE("%p %p %08x\n", dialog
, hwnd
, param
);
2596 control
= msi_dialog_find_control( dialog
, dialog
->control_default
);
2598 case 2: /* escape */
2599 control
= msi_dialog_find_control( dialog
, dialog
->control_cancel
);
2602 control
= msi_dialog_find_control_by_hwnd( dialog
, hwnd
);
2607 if( control
->handler
)
2609 control
->handler( dialog
, control
, param
);
2610 msi_dialog_evaluate_control_conditions( dialog
);
2614 ERR("button click from nowhere %p %d %p\n", dialog
, param
, hwnd
);
2618 static void msi_dialog_setfocus( msi_dialog
*dialog
)
2620 HWND hwnd
= dialog
->hWndFocus
;
2622 hwnd
= GetNextDlgTabItem( dialog
->hwnd
, hwnd
, TRUE
);
2623 hwnd
= GetNextDlgTabItem( dialog
->hwnd
, hwnd
, FALSE
);
2625 dialog
->hWndFocus
= hwnd
;
2628 static LRESULT WINAPI
MSIDialog_WndProc( HWND hwnd
, UINT msg
,
2629 WPARAM wParam
, LPARAM lParam
)
2631 msi_dialog
*dialog
= (LPVOID
) GetWindowLongPtrW( hwnd
, GWLP_USERDATA
);
2633 TRACE("0x%04x\n", msg
);
2638 return msi_dialog_oncreate( hwnd
, (LPCREATESTRUCTW
)lParam
);
2641 return msi_dialog_oncommand( dialog
, wParam
, (HWND
)lParam
);
2644 if( LOWORD(wParam
) == WA_INACTIVE
)
2645 dialog
->hWndFocus
= GetFocus();
2647 msi_dialog_setfocus( dialog
);
2651 msi_dialog_setfocus( dialog
);
2654 /* bounce back to our subclassed static control */
2655 case WM_CTLCOLORSTATIC
:
2656 return SendMessageW( (HWND
) lParam
, WM_CTLCOLORSTATIC
, wParam
, lParam
);
2659 dialog
->hwnd
= NULL
;
2662 return DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
2665 static BOOL CALLBACK
msi_radioground_child_enum( HWND hWnd
, LPARAM lParam
)
2667 EnableWindow( hWnd
, lParam
);
2671 static LRESULT WINAPI
MSIRadioGroup_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
2673 WNDPROC oldproc
= (WNDPROC
) GetPropW(hWnd
, szButtonData
);
2676 TRACE("hWnd %p msg %04x wParam 0x%08x lParam 0x%08lx\n", hWnd
, msg
, wParam
, lParam
);
2678 if (msg
== WM_COMMAND
) /* Forward notifications to dialog */
2679 SendMessageW(GetParent(hWnd
), msg
, wParam
, lParam
);
2681 r
= CallWindowProcW(oldproc
, hWnd
, msg
, wParam
, lParam
);
2683 /* make sure the radio buttons show as disabled if the parent is disabled */
2684 if (msg
== WM_ENABLE
)
2685 EnumChildWindows( hWnd
, msi_radioground_child_enum
, wParam
);
2690 static LRESULT WINAPI
MSIHiddenWindowProc( HWND hwnd
, UINT msg
,
2691 WPARAM wParam
, LPARAM lParam
)
2693 msi_dialog
*dialog
= (msi_dialog
*) lParam
;
2695 TRACE("%d %p\n", msg
, dialog
);
2699 case WM_MSI_DIALOG_CREATE
:
2700 return msi_dialog_run_message_loop( dialog
);
2701 case WM_MSI_DIALOG_DESTROY
:
2702 msi_dialog_destroy( dialog
);
2705 return DefWindowProcW( hwnd
, msg
, wParam
, lParam
);
2708 /* functions that interface to other modules within MSI */
2710 msi_dialog
*msi_dialog_create( MSIPACKAGE
* package
, LPCWSTR szDialogName
,
2711 msi_dialog_event_handler event_handler
)
2713 MSIRECORD
*rec
= NULL
;
2716 TRACE("%p %s\n", package
, debugstr_w(szDialogName
));
2718 /* allocate the structure for the dialog to use */
2719 dialog
= msi_alloc_zero( sizeof *dialog
+ sizeof(WCHAR
)*strlenW(szDialogName
) );
2722 strcpyW( dialog
->name
, szDialogName
);
2723 msiobj_addref( &package
->hdr
);
2724 dialog
->package
= package
;
2725 dialog
->event_handler
= event_handler
;
2726 dialog
->finished
= 0;
2727 list_init( &dialog
->controls
);
2729 /* verify that the dialog exists */
2730 rec
= msi_get_dialog_record( dialog
);
2733 msiobj_release( &package
->hdr
);
2737 dialog
->attributes
= MSI_RecordGetInteger( rec
, 6 );
2738 dialog
->control_default
= strdupW( MSI_RecordGetString( rec
, 9 ) );
2739 dialog
->control_cancel
= strdupW( MSI_RecordGetString( rec
, 10 ) );
2740 msiobj_release( &rec
->hdr
);
2745 static void msi_process_pending_messages( HWND hdlg
)
2749 while( PeekMessageW( &msg
, 0, 0, 0, PM_REMOVE
) )
2751 if( hdlg
&& IsDialogMessageW( hdlg
, &msg
))
2753 TranslateMessage( &msg
);
2754 DispatchMessageW( &msg
);
2758 void msi_dialog_end_dialog( msi_dialog
*dialog
)
2760 TRACE("%p\n", dialog
);
2761 dialog
->finished
= 1;
2762 PostMessageW(dialog
->hwnd
, WM_NULL
, 0, 0);
2765 void msi_dialog_check_messages( HANDLE handle
)
2769 /* in threads other than the UI thread, block */
2770 if( uiThreadId
!= GetCurrentThreadId() )
2773 WaitForSingleObject( handle
, INFINITE
);
2777 /* there's two choices for the UI thread */
2780 msi_process_pending_messages( NULL
);
2786 * block here until somebody creates a new dialog or
2787 * the handle we're waiting on becomes ready
2789 r
= MsgWaitForMultipleObjects( 1, &handle
, 0, INFINITE
, QS_ALLINPUT
);
2790 if( r
== WAIT_OBJECT_0
)
2795 UINT
msi_dialog_run_message_loop( msi_dialog
*dialog
)
2800 if( uiThreadId
!= GetCurrentThreadId() )
2801 return SendMessageW( hMsiHiddenWindow
, WM_MSI_DIALOG_CREATE
, 0, (LPARAM
) dialog
);
2803 /* create the dialog window, don't show it yet */
2804 style
= WS_OVERLAPPED
;
2805 if( dialog
->attributes
& msidbDialogAttributesVisible
)
2806 style
|= WS_VISIBLE
;
2808 hwnd
= CreateWindowW( szMsiDialogClass
, dialog
->name
, style
,
2809 CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
,
2810 NULL
, NULL
, NULL
, dialog
);
2813 ERR("Failed to create dialog %s\n", debugstr_w( dialog
->name
));
2814 return ERROR_FUNCTION_FAILED
;
2817 ShowWindow( hwnd
, SW_SHOW
);
2818 /* UpdateWindow( hwnd ); - and causes the transparent static controls not to paint */
2820 if( dialog
->attributes
& msidbDialogAttributesModal
)
2822 while( !dialog
->finished
)
2824 MsgWaitForMultipleObjects( 0, NULL
, 0, INFINITE
, QS_ALLINPUT
);
2825 msi_process_pending_messages( dialog
->hwnd
);
2829 return ERROR_IO_PENDING
;
2831 return ERROR_SUCCESS
;
2834 void msi_dialog_do_preview( msi_dialog
*dialog
)
2837 dialog
->attributes
|= msidbDialogAttributesVisible
;
2838 dialog
->attributes
&= ~msidbDialogAttributesModal
;
2839 msi_dialog_run_message_loop( dialog
);
2842 void msi_dialog_destroy( msi_dialog
*dialog
)
2844 if( uiThreadId
!= GetCurrentThreadId() )
2846 SendMessageW( hMsiHiddenWindow
, WM_MSI_DIALOG_DESTROY
, 0, (LPARAM
) dialog
);
2851 ShowWindow( dialog
->hwnd
, SW_HIDE
);
2854 DestroyWindow( dialog
->hwnd
);
2856 /* destroy the list of controls */
2857 while( !list_empty( &dialog
->controls
) )
2859 msi_control
*t
= LIST_ENTRY( list_head( &dialog
->controls
),
2860 msi_control
, entry
);
2861 list_remove( &t
->entry
);
2862 /* leave dialog->hwnd - destroying parent destroys child windows */
2863 msi_free( t
->property
);
2864 msi_free( t
->value
);
2866 DeleteObject( t
->hBitmap
);
2868 DestroyIcon( t
->hIcon
);
2869 msi_free( t
->tabnext
);
2872 FreeLibrary( t
->hDll
);
2875 /* destroy the list of fonts */
2876 while( dialog
->font_list
)
2878 msi_font
*t
= dialog
->font_list
;
2879 dialog
->font_list
= t
->next
;
2880 DeleteObject( t
->hfont
);
2883 msi_free( dialog
->default_font
);
2885 msi_free( dialog
->control_default
);
2886 msi_free( dialog
->control_cancel
);
2887 msiobj_release( &dialog
->package
->hdr
);
2888 dialog
->package
= NULL
;
2892 BOOL
msi_dialog_register_class( void )
2896 ZeroMemory( &cls
, sizeof cls
);
2897 cls
.lpfnWndProc
= MSIDialog_WndProc
;
2898 cls
.hInstance
= NULL
;
2899 cls
.hIcon
= LoadIconW(0, (LPWSTR
)IDI_APPLICATION
);
2900 cls
.hCursor
= LoadCursorW(0, (LPWSTR
)IDC_ARROW
);
2901 cls
.hbrBackground
= (HBRUSH
)(COLOR_3DFACE
+ 1);
2902 cls
.lpszMenuName
= NULL
;
2903 cls
.lpszClassName
= szMsiDialogClass
;
2905 if( !RegisterClassW( &cls
) )
2908 cls
.lpfnWndProc
= MSIHiddenWindowProc
;
2909 cls
.lpszClassName
= szMsiHiddenWindow
;
2911 if( !RegisterClassW( &cls
) )
2914 uiThreadId
= GetCurrentThreadId();
2916 hMsiHiddenWindow
= CreateWindowW( szMsiHiddenWindow
, NULL
, WS_OVERLAPPED
,
2917 0, 0, 100, 100, NULL
, NULL
, NULL
, NULL
);
2918 if( !hMsiHiddenWindow
)
2924 void msi_dialog_unregister_class( void )
2926 DestroyWindow( hMsiHiddenWindow
);
2927 hMsiHiddenWindow
= NULL
;
2928 UnregisterClassW( szMsiDialogClass
, NULL
);
2929 UnregisterClassW( szMsiHiddenWindow
, NULL
);