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
40 #include "wine/debug.h"
41 #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
65 float progress_current
;
70 typedef struct msi_font_tag
72 struct msi_font_tag
*next
;
81 msi_dialog_event_handler event_handler
;
90 LPWSTR control_default
;
91 LPWSTR control_cancel
;
95 typedef UINT (*msi_dialog_control_func
)( msi_dialog
*dialog
, MSIRECORD
*rec
);
96 struct control_handler
99 msi_dialog_control_func func
;
108 } radio_button_group_descr
;
110 static const WCHAR szMsiDialogClass
[] = {
111 'M','s','i','D','i','a','l','o','g','C','l','o','s','e','C','l','a','s','s',0
113 static const WCHAR szMsiHiddenWindow
[] = {
114 'M','s','i','H','i','d','d','e','n','W','i','n','d','o','w',0 };
115 static const WCHAR szStatic
[] = { 'S','t','a','t','i','c',0 };
116 static const WCHAR szButton
[] = { 'B','U','T','T','O','N', 0 };
117 static const WCHAR szButtonData
[] = { 'M','S','I','D','A','T','A',0 };
118 static const WCHAR szProgress
[] = { 'P','r','o','g','r','e','s','s',0 };
119 static const WCHAR szText
[] = { 'T','e','x','t',0 };
120 static const WCHAR szPushButton
[] = { 'P','u','s','h','B','u','t','t','o','n',0 };
121 static const WCHAR szLine
[] = { 'L','i','n','e',0 };
122 static const WCHAR szBitmap
[] = { 'B','i','t','m','a','p',0 };
123 static const WCHAR szCheckBox
[] = { 'C','h','e','c','k','B','o','x',0 };
124 static const WCHAR szScrollableText
[] = {
125 'S','c','r','o','l','l','a','b','l','e','T','e','x','t',0 };
126 static const WCHAR szComboBox
[] = { 'C','o','m','b','o','B','o','x',0 };
127 static const WCHAR szEdit
[] = { 'E','d','i','t',0 };
128 static const WCHAR szMaskedEdit
[] = { 'M','a','s','k','e','d','E','d','i','t',0 };
129 static const WCHAR szPathEdit
[] = { 'P','a','t','h','E','d','i','t',0 };
130 static const WCHAR szProgressBar
[] = {
131 'P','r','o','g','r','e','s','s','B','a','r',0 };
132 static const WCHAR szRadioButtonGroup
[] = {
133 'R','a','d','i','o','B','u','t','t','o','n','G','r','o','u','p',0 };
134 static const WCHAR szIcon
[] = { 'I','c','o','n',0 };
135 static const WCHAR szSelectionTree
[] = {
136 'S','e','l','e','c','t','i','o','n','T','r','e','e',0 };
137 static const WCHAR szGroupBox
[] = { 'G','r','o','u','p','B','o','x',0 };
139 static UINT
msi_dialog_checkbox_handler( msi_dialog
*, msi_control
*, WPARAM
);
140 static void msi_dialog_checkbox_sync_state( msi_dialog
*, msi_control
* );
141 static UINT
msi_dialog_button_handler( msi_dialog
*, msi_control
*, WPARAM
);
142 static UINT
msi_dialog_edit_handler( msi_dialog
*, msi_control
*, WPARAM
);
143 static UINT
msi_dialog_radiogroup_handler( msi_dialog
*, msi_control
*, WPARAM param
);
144 static UINT
msi_dialog_evaluate_control_conditions( msi_dialog
*dialog
);
145 static LRESULT WINAPI
MSIRadioGroup_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
);
148 /* dialog sequencing */
150 #define WM_MSI_DIALOG_CREATE (WM_USER+0x100)
151 #define WM_MSI_DIALOG_DESTROY (WM_USER+0x101)
153 static DWORD uiThreadId
;
154 static HWND hMsiHiddenWindow
;
156 static INT
msi_dialog_scale_unit( msi_dialog
*dialog
, INT val
)
158 return (dialog
->scale
* val
+ 5) / 10;
161 static msi_control
*msi_dialog_find_control( msi_dialog
*dialog
, LPCWSTR name
)
163 msi_control
*control
;
167 LIST_FOR_EACH_ENTRY( control
, &dialog
->controls
, msi_control
, entry
)
168 if( !strcmpW( control
->name
, name
) ) /* FIXME: case sensitive? */
173 static msi_control
*msi_dialog_find_control_by_hwnd( msi_dialog
*dialog
, HWND hwnd
)
175 msi_control
*control
;
177 LIST_FOR_EACH_ENTRY( control
, &dialog
->controls
, msi_control
, entry
)
178 if( hwnd
== control
->hwnd
)
183 static LPWSTR
msi_get_deformatted_field( MSIPACKAGE
*package
, MSIRECORD
*rec
, int field
)
185 LPCWSTR str
= MSI_RecordGetString( rec
, field
);
189 deformat_string( package
, str
, &ret
);
194 * msi_dialog_get_style
196 * Extract the {\style} string from the front of the text to display and
197 * update the pointer.
199 static LPWSTR
msi_dialog_get_style( LPCWSTR p
, LPCWSTR
*rest
)
210 q
= strchrW( p
, '}' );
213 if( *p
== '\\' || *p
== '&' )
216 /* little bit of sanity checking to stop us getting confused with RTF */
218 if( *i
== '}' || *i
== '\\' )
224 ret
= msi_alloc( len
*sizeof(WCHAR
) );
227 memcpy( ret
, p
, len
*sizeof(WCHAR
) );
232 static UINT
msi_dialog_add_font( MSIRECORD
*rec
, LPVOID param
)
234 msi_dialog
*dialog
= param
;
241 /* create a font and add it to the list */
242 name
= MSI_RecordGetString( rec
, 1 );
243 font
= msi_alloc( sizeof *font
+ strlenW( name
)*sizeof (WCHAR
) );
244 strcpyW( font
->name
, name
);
245 font
->next
= dialog
->font_list
;
246 dialog
->font_list
= font
;
248 font
->color
= MSI_RecordGetInteger( rec
, 4 );
250 memset( &lf
, 0, sizeof lf
);
251 face
= MSI_RecordGetString( rec
, 2 );
252 lf
.lfHeight
= MSI_RecordGetInteger( rec
, 3 );
253 style
= MSI_RecordGetInteger( rec
, 5 );
254 if( style
& msidbTextStyleStyleBitsBold
)
255 lf
.lfWeight
= FW_BOLD
;
256 if( style
& msidbTextStyleStyleBitsItalic
)
258 if( style
& msidbTextStyleStyleBitsUnderline
)
259 lf
.lfUnderline
= TRUE
;
260 if( style
& msidbTextStyleStyleBitsStrike
)
261 lf
.lfStrikeOut
= TRUE
;
262 lstrcpynW( lf
.lfFaceName
, face
, LF_FACESIZE
);
264 /* adjust the height */
265 hdc
= GetDC( dialog
->hwnd
);
268 lf
.lfHeight
= -MulDiv(lf
.lfHeight
, GetDeviceCaps(hdc
, LOGPIXELSY
), 72);
269 ReleaseDC( dialog
->hwnd
, hdc
);
272 font
->hfont
= CreateFontIndirectW( &lf
);
274 TRACE("Adding font style %s\n", debugstr_w(font
->name
) );
276 return ERROR_SUCCESS
;
279 static msi_font
*msi_dialog_find_font( msi_dialog
*dialog
, LPCWSTR name
)
283 for( font
= dialog
->font_list
; font
; font
= font
->next
)
284 if( !strcmpW( font
->name
, name
) ) /* FIXME: case sensitive? */
290 static UINT
msi_dialog_set_font( msi_dialog
*dialog
, HWND hwnd
, LPCWSTR name
)
294 font
= msi_dialog_find_font( dialog
, name
);
296 SendMessageW( hwnd
, WM_SETFONT
, (WPARAM
) font
->hfont
, TRUE
);
298 ERR("No font entry for %s\n", debugstr_w(name
));
299 return ERROR_SUCCESS
;
302 static UINT
msi_dialog_build_font_list( msi_dialog
*dialog
)
304 static const WCHAR query
[] = {
305 'S','E','L','E','C','T',' ','*',' ',
306 'F','R','O','M',' ','`','T','e','x','t','S','t','y','l','e','`',' ',0
309 MSIQUERY
*view
= NULL
;
311 TRACE("dialog %p\n", dialog
);
313 r
= MSI_OpenQuery( dialog
->package
->db
, &view
, query
);
314 if( r
!= ERROR_SUCCESS
)
317 r
= MSI_IterateRecords( view
, NULL
, msi_dialog_add_font
, dialog
);
318 msiobj_release( &view
->hdr
);
323 static msi_control
*msi_dialog_create_window( msi_dialog
*dialog
,
324 MSIRECORD
*rec
, DWORD exstyle
, LPCWSTR szCls
, LPCWSTR name
, LPCWSTR text
,
325 DWORD style
, HWND parent
)
327 DWORD x
, y
, width
, height
;
328 LPWSTR font
= NULL
, title_font
= NULL
;
329 LPCWSTR title
= NULL
;
330 msi_control
*control
;
334 control
= msi_alloc( sizeof *control
+ strlenW(name
)*sizeof(WCHAR
) );
335 strcpyW( control
->name
, name
);
336 list_add_head( &dialog
->controls
, &control
->entry
);
337 control
->handler
= NULL
;
338 control
->property
= NULL
;
339 control
->value
= NULL
;
340 control
->hBitmap
= NULL
;
341 control
->hIcon
= NULL
;
342 control
->hDll
= NULL
;
343 control
->tabnext
= strdupW( MSI_RecordGetString( rec
, 11) );
344 control
->progress_current
= 0;
345 control
->progress_max
= 100;
347 x
= MSI_RecordGetInteger( rec
, 4 );
348 y
= MSI_RecordGetInteger( rec
, 5 );
349 width
= MSI_RecordGetInteger( rec
, 6 );
350 height
= MSI_RecordGetInteger( rec
, 7 );
352 x
= msi_dialog_scale_unit( dialog
, x
);
353 y
= msi_dialog_scale_unit( dialog
, y
);
354 width
= msi_dialog_scale_unit( dialog
, width
);
355 height
= msi_dialog_scale_unit( dialog
, height
);
359 deformat_string( dialog
->package
, text
, &title_font
);
360 font
= msi_dialog_get_style( title_font
, &title
);
363 control
->hwnd
= CreateWindowExW( exstyle
, szCls
, title
, style
,
364 x
, y
, width
, height
, parent
, NULL
, NULL
, NULL
);
366 TRACE("Dialog %s control %s hwnd %p\n",
367 debugstr_w(dialog
->name
), debugstr_w(text
), control
->hwnd
);
369 msi_dialog_set_font( dialog
, control
->hwnd
,
370 font
? font
: dialog
->default_font
);
372 msi_free( title_font
);
378 static MSIRECORD
*msi_get_binary_record( MSIDATABASE
*db
, LPCWSTR name
)
380 static const WCHAR query
[] = {
381 's','e','l','e','c','t',' ','*',' ',
382 'f','r','o','m',' ','B','i','n','a','r','y',' ',
383 'w','h','e','r','e',' ',
384 '`','N','a','m','e','`',' ','=',' ','\'','%','s','\'',0
387 return MSI_QueryGetRecord( db
, query
, name
);
390 static LPWSTR
msi_create_tmp_path(void)
394 static const WCHAR prefix
[] = { 'm','s','i',0 };
397 r
= GetTempPathW( MAX_PATH
, tmp
);
400 len
= lstrlenW( tmp
) + 20;
401 path
= msi_alloc( len
* sizeof (WCHAR
) );
404 r
= GetTempFileNameW( tmp
, prefix
, 0, path
);
415 static HANDLE
msi_load_image( MSIDATABASE
*db
, LPCWSTR name
, UINT type
,
416 UINT cx
, UINT cy
, UINT flags
)
418 MSIRECORD
*rec
= NULL
;
419 HANDLE himage
= NULL
;
423 TRACE("%p %s %u %u %08x\n", db
, debugstr_w(name
), cx
, cy
, flags
);
425 tmp
= msi_create_tmp_path();
429 rec
= msi_get_binary_record( db
, name
);
432 r
= MSI_RecordStreamToFile( rec
, 2, tmp
);
433 if( r
== ERROR_SUCCESS
)
435 himage
= LoadImageW( 0, tmp
, type
, cx
, cy
, flags
);
438 msiobj_release( &rec
->hdr
);
445 static HICON
msi_load_icon( MSIDATABASE
*db
, LPCWSTR text
, UINT attributes
)
447 DWORD cx
= 0, cy
= 0, flags
;
449 flags
= LR_LOADFROMFILE
| LR_DEFAULTSIZE
;
450 if( attributes
& msidbControlAttributesFixedSize
)
452 flags
&= ~LR_DEFAULTSIZE
;
453 if( attributes
& msidbControlAttributesIconSize16
)
458 if( attributes
& msidbControlAttributesIconSize32
)
463 /* msidbControlAttributesIconSize48 handled by above logic */
465 return msi_load_image( db
, text
, IMAGE_ICON
, cx
, cy
, flags
);
469 /* called from the Control Event subscription code */
470 void msi_dialog_handle_event( msi_dialog
* dialog
, LPCWSTR control
,
471 LPCWSTR attribute
, MSIRECORD
*rec
)
474 LPCWSTR font_text
, text
= NULL
;
477 ctrl
= msi_dialog_find_control( dialog
, control
);
480 if( !lstrcmpW(attribute
, szText
) )
482 font_text
= MSI_RecordGetString( rec
, 1 );
483 font
= msi_dialog_get_style( font_text
, &text
);
484 SetWindowTextW( ctrl
->hwnd
, text
);
486 msi_dialog_check_messages( NULL
);
488 else if( !lstrcmpW(attribute
, szProgress
) )
492 func
= MSI_RecordGetInteger( rec
, 1 );
493 val
= MSI_RecordGetInteger( rec
, 2 );
498 ctrl
->progress_max
= val
;
499 ctrl
->progress_current
= 0;
500 SendMessageW(ctrl
->hwnd
, PBM_SETRANGE
, 0, MAKELPARAM(0,100));
501 SendMessageW(ctrl
->hwnd
, PBM_SETPOS
, 0, 0);
503 case 1: /* FIXME: not sure what this is supposed to do */
506 ctrl
->progress_current
+= val
;
507 SendMessageW(ctrl
->hwnd
, PBM_SETPOS
, 100*(ctrl
->progress_current
/ctrl
->progress_max
), 0);
510 ERR("Unknown progress message %ld\n", func
);
516 FIXME("Attribute %s not being set\n", debugstr_w(attribute
));
521 static void msi_dialog_map_events(msi_dialog
* dialog
, LPCWSTR control
)
523 static const WCHAR Query
[] = {
524 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
525 '`','E','v','e','n','t','M','a','p','p','i','n','g','`',' ',
526 'W','H','E','R','E',' ',
527 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',' ',
529 '`','C','o','n','t','r','o','l','_','`',' ','=',' ','\'','%','s','\'',0
532 LPCWSTR event
, attribute
;
534 row
= MSI_QueryGetRecord( dialog
->package
->db
, Query
, dialog
->name
, control
);
538 event
= MSI_RecordGetString( row
, 3 );
539 attribute
= MSI_RecordGetString( row
, 4 );
540 ControlEvent_SubscribeToEvent( dialog
->package
, event
, control
, attribute
);
541 msiobj_release( &row
->hdr
);
544 /* everything except radio buttons */
545 static msi_control
*msi_dialog_add_control( msi_dialog
*dialog
,
546 MSIRECORD
*rec
, LPCWSTR szCls
, DWORD style
)
552 name
= MSI_RecordGetString( rec
, 2 );
553 attributes
= MSI_RecordGetInteger( rec
, 8 );
554 text
= MSI_RecordGetString( rec
, 10 );
555 if( attributes
& msidbControlAttributesVisible
)
557 if( ~attributes
& msidbControlAttributesEnabled
)
558 style
|= WS_DISABLED
;
559 if( attributes
& msidbControlAttributesSunken
)
560 exstyle
|= WS_EX_CLIENTEDGE
;
562 msi_dialog_map_events(dialog
, name
);
564 return msi_dialog_create_window( dialog
, rec
, exstyle
, szCls
, name
,
565 text
, style
, dialog
->hwnd
);
576 * we don't erase our own background,
577 * so we have to make sure that the parent window redraws first
579 static void msi_text_on_settext( HWND hWnd
)
584 hParent
= GetParent( hWnd
);
585 GetWindowRect( hWnd
, &rc
);
586 MapWindowPoints( NULL
, hParent
, (LPPOINT
) &rc
, 2 );
587 InvalidateRect( hParent
, &rc
, TRUE
);
590 static LRESULT WINAPI
591 MSIText_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
593 struct msi_text_info
*info
;
596 TRACE("%p %04x %08x %08lx\n", hWnd
, msg
, wParam
, lParam
);
598 info
= GetPropW(hWnd
, szButtonData
);
601 SetTextColor( (HDC
)wParam
, info
->font
->color
);
603 if( msg
== WM_CTLCOLORSTATIC
&&
604 ( info
->attributes
& msidbControlAttributesTransparent
) )
606 SetBkMode( (HDC
)wParam
, TRANSPARENT
);
607 return (LRESULT
) GetStockObject(NULL_BRUSH
);
610 r
= CallWindowProcW(info
->oldproc
, hWnd
, msg
, wParam
, lParam
);
615 msi_text_on_settext( hWnd
);
619 RemovePropW( hWnd
, szButtonData
);
626 static UINT
msi_dialog_text_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
628 msi_control
*control
;
629 struct msi_text_info
*info
;
633 TRACE("%p %p\n", dialog
, rec
);
635 control
= msi_dialog_add_control( dialog
, rec
, szStatic
, SS_LEFT
| WS_GROUP
);
637 return ERROR_FUNCTION_FAILED
;
639 info
= msi_alloc( sizeof *info
);
641 return ERROR_SUCCESS
;
643 text
= MSI_RecordGetString( rec
, 10 );
644 font_name
= msi_dialog_get_style( text
, &ptr
);
645 info
->font
= ( font_name
) ? msi_dialog_find_font( dialog
, font_name
) : NULL
;
646 msi_free( font_name
);
648 info
->attributes
= MSI_RecordGetInteger( rec
, 8 );
649 if( info
->attributes
& msidbControlAttributesTransparent
)
650 SetWindowLongPtrW( control
->hwnd
, GWL_EXSTYLE
, WS_EX_TRANSPARENT
);
652 info
->oldproc
= (WNDPROC
) SetWindowLongPtrW( control
->hwnd
, GWLP_WNDPROC
,
653 (LONG_PTR
)MSIText_WndProc
);
654 SetPropW( control
->hwnd
, szButtonData
, info
);
656 return ERROR_SUCCESS
;
659 static UINT
msi_dialog_button_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
661 msi_control
*control
;
662 UINT attributes
, style
;
665 TRACE("%p %p\n", dialog
, rec
);
668 attributes
= MSI_RecordGetInteger( rec
, 8 );
669 if( attributes
& msidbControlAttributesIcon
)
672 control
= msi_dialog_add_control( dialog
, rec
, szButton
, style
);
674 return ERROR_FUNCTION_FAILED
;
676 control
->handler
= msi_dialog_button_handler
;
679 text
= msi_get_deformatted_field( dialog
->package
, rec
, 10 );
680 control
->hIcon
= msi_load_icon( dialog
->package
->db
, text
, attributes
);
681 if( attributes
& msidbControlAttributesIcon
)
682 SendMessageW( control
->hwnd
, BM_SETIMAGE
, IMAGE_ICON
, (LPARAM
) control
->hIcon
);
685 return ERROR_SUCCESS
;
688 static LPWSTR
msi_get_checkbox_value( msi_dialog
*dialog
, LPCWSTR prop
)
690 static const WCHAR query
[] = {
691 'S','E','L','E','C','T',' ','*',' ',
692 'F','R','O','M',' ','`','C','h','e','c','k','B','o','x',' ','`',
693 'W','H','E','R','E',' ',
694 '`','P','r','o','p','e','r','t','y','`',' ','=',' ',
697 MSIRECORD
*rec
= NULL
;
700 /* find if there is a value associated with the checkbox */
701 rec
= MSI_QueryGetRecord( dialog
->package
->db
, query
, prop
);
705 ret
= msi_get_deformatted_field( dialog
->package
, rec
, 2 );
711 msiobj_release( &rec
->hdr
);
715 ret
= msi_dup_property( dialog
->package
, prop
);
725 static UINT
msi_dialog_checkbox_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
727 msi_control
*control
;
730 TRACE("%p %p\n", dialog
, rec
);
732 control
= msi_dialog_add_control( dialog
, rec
, szButton
,
733 BS_CHECKBOX
| BS_MULTILINE
| WS_TABSTOP
);
734 control
->handler
= msi_dialog_checkbox_handler
;
735 prop
= MSI_RecordGetString( rec
, 9 );
738 control
->property
= strdupW( prop
);
739 control
->value
= msi_get_checkbox_value( dialog
, prop
);
740 TRACE("control %s value %s\n", debugstr_w(control
->property
),
741 debugstr_w(control
->value
));
743 msi_dialog_checkbox_sync_state( dialog
, control
);
745 return ERROR_SUCCESS
;
748 static UINT
msi_dialog_line_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
750 TRACE("%p %p\n", dialog
, rec
);
752 msi_dialog_add_control( dialog
, rec
, szStatic
, SS_ETCHEDHORZ
| SS_SUNKEN
);
753 return ERROR_SUCCESS
;
756 /******************** Scroll Text ********************************************/
758 struct msi_scrolltext_info
761 msi_control
*control
;
765 static LRESULT WINAPI
766 MSIScrollText_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
768 struct msi_scrolltext_info
*info
;
771 TRACE("%p %04x %08x %08lx\n", hWnd
, msg
, wParam
, lParam
);
773 info
= GetPropW( hWnd
, szButtonData
);
775 r
= CallWindowProcW( info
->oldproc
, hWnd
, msg
, wParam
, lParam
);
781 RemovePropW( hWnd
, szButtonData
);
784 /* native MSI sets a wait cursor here */
785 msi_dialog_button_handler( info
->dialog
, info
->control
, BN_CLICKED
);
791 struct msi_streamin_info
798 static DWORD CALLBACK
799 msi_richedit_stream_in( DWORD_PTR arg
, LPBYTE buffer
, LONG count
, LONG
*pcb
)
801 struct msi_streamin_info
*info
= (struct msi_streamin_info
*) arg
;
803 if( (count
+ info
->offset
) > info
->length
)
804 count
= info
->length
- info
->offset
;
805 memcpy( buffer
, &info
->string
[ info
->offset
], count
);
807 info
->offset
+= count
;
809 TRACE("%ld/%ld\n", info
->offset
, info
->length
);
814 static void msi_scrolltext_add_text( msi_control
*control
, LPCWSTR text
)
816 struct msi_streamin_info info
;
819 info
.string
= strdupWtoA( text
);
821 info
.length
= lstrlenA( info
.string
) + 1;
823 es
.dwCookie
= (DWORD_PTR
) &info
;
825 es
.pfnCallback
= msi_richedit_stream_in
;
827 SendMessageW( control
->hwnd
, EM_STREAMIN
, SF_RTF
, (LPARAM
) &es
);
829 msi_free( info
.string
);
832 static UINT
msi_dialog_scrolltext_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
834 static const WCHAR szRichEdit20W
[] = {
835 'R','i','c','h','E','d','i','t','2','0','W',0
837 struct msi_scrolltext_info
*info
;
838 msi_control
*control
;
842 info
= msi_alloc( sizeof *info
);
844 return ERROR_FUNCTION_FAILED
;
846 hRichedit
= LoadLibraryA("riched20");
848 style
= WS_BORDER
| ES_MULTILINE
| WS_VSCROLL
|
849 ES_READONLY
| ES_AUTOVSCROLL
| WS_TABSTOP
;
850 control
= msi_dialog_add_control( dialog
, rec
, szRichEdit20W
, style
);
853 FreeLibrary( hRichedit
);
855 return ERROR_FUNCTION_FAILED
;
858 control
->hDll
= hRichedit
;
860 info
->dialog
= dialog
;
861 info
->control
= control
;
863 /* subclass the static control */
864 info
->oldproc
= (WNDPROC
) SetWindowLongPtrW( control
->hwnd
, GWLP_WNDPROC
,
865 (LONG_PTR
)MSIScrollText_WndProc
);
866 SetPropW( control
->hwnd
, szButtonData
, info
);
868 /* add the text into the richedit */
869 msi_scrolltext_add_text( control
, MSI_RecordGetString( rec
, 10 ) );
871 return ERROR_SUCCESS
;
874 static HBITMAP
msi_load_picture( MSIDATABASE
*db
, LPCWSTR name
,
875 INT cx
, INT cy
, DWORD flags
)
877 HBITMAP hOleBitmap
= 0, hBitmap
= 0, hOldSrcBitmap
, hOldDestBitmap
;
878 MSIRECORD
*rec
= NULL
;
880 IPicture
*pic
= NULL
;
885 rec
= msi_get_binary_record( db
, name
);
889 r
= MSI_RecordGetIStream( rec
, 2, &stm
);
890 msiobj_release( &rec
->hdr
);
891 if( r
!= ERROR_SUCCESS
)
894 r
= OleLoadPicture( stm
, 0, TRUE
, &IID_IPicture
, (LPVOID
*) &pic
);
895 IStream_Release( stm
);
898 ERR("failed to load picture\n");
902 r
= IPicture_get_Handle( pic
, (OLE_HANDLE
*) &hOleBitmap
);
905 ERR("failed to get bitmap handle\n");
909 /* make the bitmap the desired size */
910 r
= GetObjectW( hOleBitmap
, sizeof bm
, &bm
);
913 ERR("failed to get bitmap size\n");
917 if (flags
& LR_DEFAULTSIZE
)
923 srcdc
= CreateCompatibleDC( NULL
);
924 hOldSrcBitmap
= SelectObject( srcdc
, hOleBitmap
);
925 destdc
= CreateCompatibleDC( NULL
);
926 hBitmap
= CreateCompatibleBitmap( srcdc
, cx
, cy
);
927 hOldDestBitmap
= SelectObject( destdc
, hBitmap
);
928 StretchBlt( destdc
, 0, 0, cx
, cy
,
929 srcdc
, 0, 0, bm
.bmWidth
, bm
.bmHeight
, SRCCOPY
);
930 SelectObject( srcdc
, hOldSrcBitmap
);
931 SelectObject( destdc
, hOldDestBitmap
);
937 IPicture_Release( pic
);
941 static UINT
msi_dialog_bitmap_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
943 UINT cx
, cy
, flags
, style
, attributes
;
944 msi_control
*control
;
947 flags
= LR_LOADFROMFILE
;
948 style
= SS_BITMAP
| SS_LEFT
| WS_GROUP
;
950 attributes
= MSI_RecordGetInteger( rec
, 8 );
951 if( attributes
& msidbControlAttributesFixedSize
)
953 flags
|= LR_DEFAULTSIZE
;
954 style
|= SS_CENTERIMAGE
;
957 control
= msi_dialog_add_control( dialog
, rec
, szStatic
, style
);
958 cx
= MSI_RecordGetInteger( rec
, 6 );
959 cy
= MSI_RecordGetInteger( rec
, 7 );
960 cx
= msi_dialog_scale_unit( dialog
, cx
);
961 cy
= msi_dialog_scale_unit( dialog
, cy
);
963 text
= msi_get_deformatted_field( dialog
->package
, rec
, 10 );
964 control
->hBitmap
= msi_load_picture( dialog
->package
->db
, text
, cx
, cy
, flags
);
965 if( control
->hBitmap
)
966 SendMessageW( control
->hwnd
, STM_SETIMAGE
,
967 IMAGE_BITMAP
, (LPARAM
) control
->hBitmap
);
969 ERR("Failed to load bitmap %s\n", debugstr_w(text
));
973 return ERROR_SUCCESS
;
976 static UINT
msi_dialog_icon_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
978 msi_control
*control
;
984 control
= msi_dialog_add_control( dialog
, rec
, szStatic
,
985 SS_ICON
| SS_CENTERIMAGE
| WS_GROUP
);
987 attributes
= MSI_RecordGetInteger( rec
, 8 );
988 text
= msi_get_deformatted_field( dialog
->package
, rec
, 10 );
989 control
->hIcon
= msi_load_icon( dialog
->package
->db
, text
, attributes
);
991 SendMessageW( control
->hwnd
, STM_SETICON
, (WPARAM
) control
->hIcon
, 0 );
993 ERR("Failed to load bitmap %s\n", debugstr_w(text
));
995 return ERROR_SUCCESS
;
998 static UINT
msi_dialog_combo_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1000 static const WCHAR szCombo
[] = { 'C','O','M','B','O','B','O','X',0 };
1002 msi_dialog_add_control( dialog
, rec
, szCombo
,
1003 SS_BITMAP
| SS_LEFT
| SS_CENTERIMAGE
);
1004 return ERROR_SUCCESS
;
1007 static UINT
msi_dialog_edit_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1009 msi_control
*control
;
1013 control
= msi_dialog_add_control( dialog
, rec
, szEdit
,
1014 WS_BORDER
| WS_TABSTOP
);
1015 control
->handler
= msi_dialog_edit_handler
;
1016 prop
= MSI_RecordGetString( rec
, 9 );
1018 control
->property
= strdupW( prop
);
1019 val
= msi_dup_property( dialog
->package
, control
->property
);
1020 SetWindowTextW( control
->hwnd
, val
);
1022 return ERROR_SUCCESS
;
1025 /******************** Masked Edit ********************************************/
1027 #define MASK_MAX_GROUPS 10
1029 struct msi_mask_group
1037 struct msi_maskedit_info
1045 struct msi_mask_group group
[MASK_MAX_GROUPS
];
1048 static BOOL
msi_mask_editable( WCHAR type
)
1063 static void msi_mask_control_change( struct msi_maskedit_info
*info
)
1068 val
= msi_alloc( (info
->num_chars
+1)*sizeof(WCHAR
) );
1069 for( i
=0, n
=0; i
<info
->num_groups
; i
++ )
1071 if( (info
->group
[i
].len
+ n
) > info
->num_chars
)
1073 ERR("can't fit control %d text into template\n",i
);
1076 if (!msi_mask_editable(info
->group
[i
].type
))
1078 for(r
=0; r
<info
->group
[i
].len
; r
++)
1079 val
[n
+r
] = info
->group
[i
].type
;
1084 r
= GetWindowTextW( info
->group
[i
].hwnd
, &val
[n
], info
->group
[i
].len
+1 );
1085 if( r
!= info
->group
[i
].len
)
1091 TRACE("%d/%d controls were good\n", i
, info
->num_groups
);
1093 if( i
== info
->num_groups
)
1095 TRACE("Set property %s to %s\n",
1096 debugstr_w(info
->prop
), debugstr_w(val
) );
1097 CharUpperBuffW( val
, info
->num_chars
);
1098 MSI_SetPropertyW( info
->dialog
->package
, info
->prop
, val
);
1099 msi_dialog_evaluate_control_conditions( info
->dialog
);
1104 /* now move to the next control if necessary */
1105 static VOID
msi_mask_next_control( struct msi_maskedit_info
*info
, HWND hWnd
)
1110 for( i
=0; i
<info
->num_groups
; i
++ )
1111 if( info
->group
[i
].hwnd
== hWnd
)
1114 /* don't move from the last control */
1115 if( i
>= (info
->num_groups
-1) )
1118 len
= SendMessageW( hWnd
, WM_GETTEXTLENGTH
, 0, 0 );
1119 if( len
< info
->group
[i
].len
)
1122 hWndNext
= GetNextDlgTabItem( GetParent( hWnd
), hWnd
, FALSE
);
1123 SetFocus( hWndNext
);
1126 static LRESULT WINAPI
1127 MSIMaskedEdit_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1129 struct msi_maskedit_info
*info
;
1132 TRACE("%p %04x %08x %08lx\n", hWnd
, msg
, wParam
, lParam
);
1134 info
= GetPropW(hWnd
, szButtonData
);
1136 r
= CallWindowProcW(info
->oldproc
, hWnd
, msg
, wParam
, lParam
);
1141 if (HIWORD(wParam
) == EN_CHANGE
)
1143 msi_mask_control_change( info
);
1144 msi_mask_next_control( info
, (HWND
) lParam
);
1148 msi_free( info
->prop
);
1150 RemovePropW( hWnd
, szButtonData
);
1157 /* fish the various bits of the property out and put them in the control */
1159 msi_maskedit_set_text( struct msi_maskedit_info
*info
, LPCWSTR text
)
1165 for( i
= 0; i
< info
->num_groups
; i
++ )
1167 if( info
->group
[i
].len
< lstrlenW( p
) )
1169 LPWSTR chunk
= strdupW( p
);
1170 chunk
[ info
->group
[i
].len
] = 0;
1171 SetWindowTextW( info
->group
[i
].hwnd
, chunk
);
1176 SetWindowTextW( info
->group
[i
].hwnd
, p
);
1179 p
+= info
->group
[i
].len
;
1183 static struct msi_maskedit_info
* msi_dialog_parse_groups( LPCWSTR mask
)
1185 struct msi_maskedit_info
* info
= NULL
;
1186 int i
= 0, n
= 0, total
= 0;
1189 TRACE("masked control, template %s\n", debugstr_w(mask
));
1194 info
= msi_alloc_zero( sizeof *info
);
1198 p
= strchrW(mask
, '<');
1204 for( i
=0; i
<MASK_MAX_GROUPS
; i
++ )
1206 /* stop at the end of the string */
1207 if( p
[0] == 0 || p
[0] == '>' )
1210 /* count the number of the same identifier */
1211 for( n
=0; p
[n
] == p
[0]; n
++ )
1213 info
->group
[i
].ofs
= total
;
1214 info
->group
[i
].type
= p
[0];
1218 total
++; /* an extra not part of the group */
1220 info
->group
[i
].len
= n
;
1225 TRACE("%d characters in %d groups\n", total
, i
);
1226 if( i
== MASK_MAX_GROUPS
)
1227 ERR("too many groups in PIDTemplate %s\n", debugstr_w(mask
));
1229 info
->num_chars
= total
;
1230 info
->num_groups
= i
;
1236 msi_maskedit_create_children( struct msi_maskedit_info
*info
, LPCWSTR font
)
1238 DWORD width
, height
, style
, wx
, ww
;
1243 style
= WS_CHILD
| WS_BORDER
| WS_VISIBLE
| WS_TABSTOP
| ES_AUTOHSCROLL
;
1245 GetClientRect( info
->hwnd
, &rect
);
1247 width
= rect
.right
- rect
.left
;
1248 height
= rect
.bottom
- rect
.top
;
1250 for( i
= 0; i
< info
->num_groups
; i
++ )
1252 if (!msi_mask_editable( info
->group
[i
].type
))
1254 wx
= (info
->group
[i
].ofs
* width
) / info
->num_chars
;
1255 ww
= (info
->group
[i
].len
* width
) / info
->num_chars
;
1257 hwnd
= CreateWindowW( szEdit
, NULL
, style
, wx
, 0, ww
, height
,
1258 info
->hwnd
, NULL
, NULL
, NULL
);
1261 ERR("failed to create mask edit sub window\n");
1265 SendMessageW( hwnd
, EM_LIMITTEXT
, info
->group
[i
].len
, 0 );
1267 msi_dialog_set_font( info
->dialog
, hwnd
,
1268 font
?font
:info
->dialog
->default_font
);
1269 info
->group
[i
].hwnd
= hwnd
;
1274 * office 2003 uses "73931<````=````=````=````=`````>@@@@@"
1275 * delphi 7 uses "<????-??????-??????-????>" and "<???-???>"
1276 * filemaker pro 7 uses "<^^^^=^^^^=^^^^=^^^^=^^^^=^^^^=^^^^^>"
1278 static UINT
msi_dialog_maskedit_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1280 LPWSTR font_mask
, val
= NULL
, font
;
1281 struct msi_maskedit_info
*info
= NULL
;
1282 UINT ret
= ERROR_SUCCESS
;
1283 msi_control
*control
;
1288 font_mask
= msi_get_deformatted_field( dialog
->package
, rec
, 10 );
1289 font
= msi_dialog_get_style( font_mask
, &mask
);
1292 ERR("mask template is empty\n");
1296 info
= msi_dialog_parse_groups( mask
);
1299 ERR("template %s is invalid\n", debugstr_w(mask
));
1303 info
->dialog
= dialog
;
1305 control
= msi_dialog_add_control( dialog
, rec
, szStatic
,
1306 SS_OWNERDRAW
| WS_GROUP
| WS_VISIBLE
);
1309 ERR("Failed to create maskedit container\n");
1310 ret
= ERROR_FUNCTION_FAILED
;
1313 SetWindowLongPtrW( control
->hwnd
, GWL_EXSTYLE
, WS_EX_CONTROLPARENT
);
1315 info
->hwnd
= control
->hwnd
;
1317 /* subclass the static control */
1318 info
->oldproc
= (WNDPROC
) SetWindowLongPtrW( info
->hwnd
, GWLP_WNDPROC
,
1319 (LONG_PTR
)MSIMaskedEdit_WndProc
);
1320 SetPropW( control
->hwnd
, szButtonData
, info
);
1322 prop
= MSI_RecordGetString( rec
, 9 );
1324 info
->prop
= strdupW( prop
);
1326 msi_maskedit_create_children( info
, font
);
1330 val
= msi_dup_property( dialog
->package
, prop
);
1333 msi_maskedit_set_text( info
, val
);
1339 if( ret
!= ERROR_SUCCESS
)
1341 msi_free( font_mask
);
1346 /******************** Progress Bar *****************************************/
1348 static UINT
msi_dialog_progress_bar( msi_dialog
*dialog
, MSIRECORD
*rec
)
1350 msi_dialog_add_control( dialog
, rec
, PROGRESS_CLASSW
, WS_VISIBLE
);
1351 return ERROR_SUCCESS
;
1354 /******************** Path Edit ********************************************/
1356 static UINT
msi_dialog_pathedit_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1358 FIXME("not implemented properly\n");
1359 return msi_dialog_edit_control( dialog
, rec
);
1362 /* radio buttons are a bit different from normal controls */
1363 static UINT
msi_dialog_create_radiobutton( MSIRECORD
*rec
, LPVOID param
)
1365 radio_button_group_descr
*group
= (radio_button_group_descr
*)param
;
1366 msi_dialog
*dialog
= group
->dialog
;
1367 msi_control
*control
;
1368 LPCWSTR prop
, text
, name
;
1369 DWORD style
, attributes
= group
->attributes
;
1371 style
= WS_CHILD
| BS_AUTORADIOBUTTON
| BS_MULTILINE
| WS_TABSTOP
;
1372 name
= MSI_RecordGetString( rec
, 3 );
1373 text
= MSI_RecordGetString( rec
, 8 );
1374 if( attributes
& 1 )
1375 style
|= WS_VISIBLE
;
1376 if( ~attributes
& 2 )
1377 style
|= WS_DISABLED
;
1379 control
= msi_dialog_create_window( dialog
, rec
, 0, szButton
, name
, text
,
1380 style
, group
->parent
->hwnd
);
1382 return ERROR_FUNCTION_FAILED
;
1383 control
->handler
= msi_dialog_radiogroup_handler
;
1385 if (!lstrcmpW(control
->name
, group
->propval
))
1386 SendMessageW(control
->hwnd
, BM_SETCHECK
, BST_CHECKED
, 0);
1388 prop
= MSI_RecordGetString( rec
, 1 );
1390 control
->property
= strdupW( prop
);
1392 return ERROR_SUCCESS
;
1395 static UINT
msi_dialog_radiogroup_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1397 static const WCHAR query
[] = {
1398 'S','E','L','E','C','T',' ','*',' ',
1399 'F','R','O','M',' ','R','a','d','i','o','B','u','t','t','o','n',' ',
1400 'W','H','E','R','E',' ',
1401 '`','P','r','o','p','e','r','t','y','`',' ','=',' ','\'','%','s','\'',0};
1404 msi_control
*control
;
1405 MSIQUERY
*view
= NULL
;
1406 radio_button_group_descr group
;
1407 MSIPACKAGE
*package
= dialog
->package
;
1410 prop
= MSI_RecordGetString( rec
, 9 );
1412 TRACE("%p %p %s\n", dialog
, rec
, debugstr_w( prop
));
1414 /* Create parent group box to hold radio buttons */
1415 control
= msi_dialog_add_control( dialog
, rec
, szButton
, BS_OWNERDRAW
|WS_GROUP
);
1417 return ERROR_FUNCTION_FAILED
;
1419 oldproc
= (WNDPROC
) SetWindowLongPtrW( control
->hwnd
, GWLP_WNDPROC
,
1420 (LONG_PTR
)MSIRadioGroup_WndProc
);
1421 SetPropW(control
->hwnd
, szButtonData
, oldproc
);
1422 SetWindowLongPtrW( control
->hwnd
, GWL_EXSTYLE
, WS_EX_CONTROLPARENT
);
1425 control
->property
= strdupW( prop
);
1427 /* query the Radio Button table for all control in this group */
1428 r
= MSI_OpenQuery( package
->db
, &view
, query
, prop
);
1429 if( r
!= ERROR_SUCCESS
)
1431 ERR("query failed for dialog %s radio group %s\n",
1432 debugstr_w(dialog
->name
), debugstr_w(prop
));
1433 return ERROR_INVALID_PARAMETER
;
1436 group
.dialog
= dialog
;
1437 group
.parent
= control
;
1438 group
.attributes
= MSI_RecordGetInteger( rec
, 8 );
1439 group
.propval
= msi_dup_property( dialog
->package
, control
->property
);
1441 r
= MSI_IterateRecords( view
, 0, msi_dialog_create_radiobutton
, &group
);
1442 msiobj_release( &view
->hdr
);
1443 msi_free( group
.propval
);
1448 /******************** Selection Tree ***************************************/
1450 struct msi_selection_tree_info
1458 msi_seltree_sync_item_state( HWND hwnd
, MSIFEATURE
*feature
, HTREEITEM hItem
)
1462 TRACE("Feature %s -> %d %d %d\n", debugstr_w(feature
->Title
),
1463 feature
->Installed
, feature
->Action
, feature
->ActionRequest
);
1465 tvi
.mask
= TVIF_STATE
;
1467 tvi
.state
= INDEXTOSTATEIMAGEMASK( feature
->Action
);
1468 tvi
.stateMask
= TVIS_STATEIMAGEMASK
;
1470 SendMessageW( hwnd
, TVM_SETITEMW
, 0, (LPARAM
) &tvi
);
1474 msi_seltree_popup_menu( HWND hwnd
, INT x
, INT y
)
1479 /* create a menu to display */
1480 hMenu
= CreatePopupMenu();
1482 /* FIXME: load strings from resources */
1483 AppendMenuA( hMenu
, MF_ENABLED
, INSTALLSTATE_LOCAL
, "Install feature locally");
1484 AppendMenuA( hMenu
, MF_GRAYED
, 0x1000, "Install entire feature");
1485 AppendMenuA( hMenu
, MF_ENABLED
, INSTALLSTATE_ADVERTISED
, "Install on demand");
1486 AppendMenuA( hMenu
, MF_ENABLED
, INSTALLSTATE_ABSENT
, "Don't install");
1487 r
= TrackPopupMenu( hMenu
, TPM_LEFTALIGN
| TPM_TOPALIGN
| TPM_RETURNCMD
,
1488 x
, y
, 0, hwnd
, NULL
);
1489 DestroyMenu( hMenu
);
1494 msi_seltree_feature_from_item( HWND hwnd
, HTREEITEM hItem
)
1498 /* get the feature from the item */
1499 memset( &tvi
, 0, sizeof tvi
);
1501 tvi
.mask
= TVIF_PARAM
| TVIF_HANDLE
;
1502 SendMessageW( hwnd
, TVM_GETITEMW
, 0, (LPARAM
) &tvi
);
1504 return (MSIFEATURE
*) tvi
.lParam
;
1508 msi_seltree_menu( HWND hwnd
, HTREEITEM hItem
)
1510 MSIFEATURE
*feature
;
1518 feature
= msi_seltree_feature_from_item( hwnd
, hItem
);
1521 ERR("item %p feature was NULL\n", hItem
);
1525 /* get the item's rectangle to put the menu just below it */
1527 SendMessageW( hwnd
, TVM_GETITEMRECT
, 0, (LPARAM
) &u
.rc
);
1528 MapWindowPoints( hwnd
, NULL
, u
.pt
, 2 );
1530 r
= msi_seltree_popup_menu( hwnd
, u
.rc
.left
, u
.rc
.top
);
1534 case INSTALLSTATE_LOCAL
:
1535 case INSTALLSTATE_ADVERTISED
:
1536 case INSTALLSTATE_ABSENT
:
1537 feature
->ActionRequest
= r
;
1538 feature
->Action
= r
;
1541 FIXME("select feature and all children\n");
1545 msi_seltree_sync_item_state( hwnd
, feature
, hItem
);
1550 static LRESULT WINAPI
1551 MSISelectionTree_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1553 struct msi_selection_tree_info
*info
;
1554 TVHITTESTINFO tvhti
;
1557 TRACE("%p %04x %08x %08lx\n", hWnd
, msg
, wParam
, lParam
);
1559 info
= GetPropW(hWnd
, szButtonData
);
1563 case WM_LBUTTONDOWN
:
1564 tvhti
.pt
.x
= LOWORD( lParam
);
1565 tvhti
.pt
.y
= HIWORD( lParam
);
1568 r
= CallWindowProcW(info
->oldproc
, hWnd
, TVM_HITTEST
, 0, (LPARAM
) &tvhti
);
1569 if (tvhti
.flags
& TVHT_ONITEMSTATEICON
)
1570 return msi_seltree_menu( hWnd
, tvhti
.hItem
);
1574 r
= CallWindowProcW(info
->oldproc
, hWnd
, msg
, wParam
, lParam
);
1580 RemovePropW( hWnd
, szButtonData
);
1587 msi_seltree_add_child_features( MSIPACKAGE
*package
, HWND hwnd
,
1588 LPCWSTR parent
, HTREEITEM hParent
)
1590 MSIFEATURE
*feature
;
1591 TVINSERTSTRUCTW tvis
;
1594 LIST_FOR_EACH_ENTRY( feature
, &package
->features
, MSIFEATURE
, entry
)
1596 if ( lstrcmpW( parent
, feature
->Feature_Parent
) )
1599 if ( !feature
->Title
)
1602 memset( &tvis
, 0, sizeof tvis
);
1603 tvis
.hParent
= hParent
;
1604 tvis
.hInsertAfter
= TVI_SORT
;
1605 tvis
.u
.item
.mask
= TVIF_TEXT
| TVIF_PARAM
;
1606 tvis
.u
.item
.pszText
= feature
->Title
;
1607 tvis
.u
.item
.lParam
= (LPARAM
) feature
;
1609 hitem
= (HTREEITEM
) SendMessageW( hwnd
, TVM_INSERTITEMW
, 0, (LPARAM
) &tvis
);
1613 msi_seltree_sync_item_state( hwnd
, feature
, hitem
);
1614 msi_seltree_add_child_features( package
, hwnd
,
1615 feature
->Feature
, hitem
);
1619 static void msi_seltree_create_imagelist( HWND hwnd
)
1621 const int bm_width
= 32, bm_height
= 16, bm_count
= 3;
1622 const int bm_resource
= 0x1001;
1627 himl
= ImageList_Create( bm_width
, bm_height
, FALSE
, 4, 0 );
1630 ERR("failed to create image list\n");
1634 for (i
=0; i
<bm_count
; i
++)
1636 hbmp
= LoadBitmapW( msi_hInstance
, MAKEINTRESOURCEW(i
+bm_resource
) );
1639 ERR("failed to load bitmap %d\n", i
);
1644 * Add a dummy bitmap at offset zero because the treeview
1645 * can't use it as a state mask (zero means no user state).
1648 ImageList_Add( himl
, hbmp
, NULL
);
1650 ImageList_Add( himl
, hbmp
, NULL
);
1653 SendMessageW( hwnd
, TVM_SETIMAGELIST
, TVSIL_STATE
, (LPARAM
)himl
);
1656 static UINT
msi_dialog_selection_tree( msi_dialog
*dialog
, MSIRECORD
*rec
)
1658 msi_control
*control
;
1660 MSIPACKAGE
*package
= dialog
->package
;
1662 struct msi_selection_tree_info
*info
;
1664 info
= msi_alloc( sizeof *info
);
1666 return ERROR_FUNCTION_FAILED
;
1668 /* create the treeview control */
1669 prop
= MSI_RecordGetString( rec
, 9 );
1670 style
= TVS_HASLINES
| TVS_HASBUTTONS
| TVS_LINESATROOT
;
1671 style
|= WS_GROUP
| WS_VSCROLL
;
1672 control
= msi_dialog_add_control( dialog
, rec
, WC_TREEVIEWW
, style
);
1676 return ERROR_FUNCTION_FAILED
;
1680 info
->dialog
= dialog
;
1681 info
->hwnd
= control
->hwnd
;
1682 info
->oldproc
= (WNDPROC
) SetWindowLongPtrW( control
->hwnd
, GWLP_WNDPROC
,
1683 (LONG_PTR
)MSISelectionTree_WndProc
);
1684 SetPropW( control
->hwnd
, szButtonData
, info
);
1687 msi_seltree_create_imagelist( control
->hwnd
);
1688 msi_seltree_add_child_features( package
, control
->hwnd
, NULL
, NULL
);
1690 return ERROR_SUCCESS
;
1693 /******************** Group Box ***************************************/
1695 static UINT
msi_dialog_group_box( msi_dialog
*dialog
, MSIRECORD
*rec
)
1697 msi_control
*control
;
1700 style
= BS_GROUPBOX
| WS_CHILD
| WS_GROUP
;
1701 control
= msi_dialog_add_control( dialog
, rec
, WC_BUTTONW
, style
);
1703 return ERROR_FUNCTION_FAILED
;
1705 return ERROR_SUCCESS
;
1708 static const struct control_handler msi_dialog_handler
[] =
1710 { szText
, msi_dialog_text_control
},
1711 { szPushButton
, msi_dialog_button_control
},
1712 { szLine
, msi_dialog_line_control
},
1713 { szBitmap
, msi_dialog_bitmap_control
},
1714 { szCheckBox
, msi_dialog_checkbox_control
},
1715 { szScrollableText
, msi_dialog_scrolltext_control
},
1716 { szComboBox
, msi_dialog_combo_control
},
1717 { szEdit
, msi_dialog_edit_control
},
1718 { szMaskedEdit
, msi_dialog_maskedit_control
},
1719 { szPathEdit
, msi_dialog_pathedit_control
},
1720 { szProgressBar
, msi_dialog_progress_bar
},
1721 { szRadioButtonGroup
, msi_dialog_radiogroup_control
},
1722 { szIcon
, msi_dialog_icon_control
},
1723 { szSelectionTree
, msi_dialog_selection_tree
},
1724 { szGroupBox
, msi_dialog_group_box
},
1727 #define NUM_CONTROL_TYPES (sizeof msi_dialog_handler/sizeof msi_dialog_handler[0])
1729 static UINT
msi_dialog_create_controls( MSIRECORD
*rec
, LPVOID param
)
1731 msi_dialog
*dialog
= param
;
1732 LPCWSTR control_type
;
1735 /* find and call the function that can create this type of control */
1736 control_type
= MSI_RecordGetString( rec
, 3 );
1737 for( i
=0; i
<NUM_CONTROL_TYPES
; i
++ )
1738 if (!strcmpiW( msi_dialog_handler
[i
].control_type
, control_type
))
1740 if( i
!= NUM_CONTROL_TYPES
)
1741 msi_dialog_handler
[i
].func( dialog
, rec
);
1743 ERR("no handler for element type %s\n", debugstr_w(control_type
));
1745 return ERROR_SUCCESS
;
1748 static UINT
msi_dialog_fill_controls( msi_dialog
*dialog
)
1750 static const WCHAR query
[] = {
1751 'S','E','L','E','C','T',' ','*',' ',
1752 'F','R','O','M',' ','C','o','n','t','r','o','l',' ',
1753 'W','H','E','R','E',' ',
1754 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',0};
1756 MSIQUERY
*view
= NULL
;
1757 MSIPACKAGE
*package
= dialog
->package
;
1759 TRACE("%p %s\n", dialog
, debugstr_w(dialog
->name
) );
1761 /* query the Control table for all the elements of the control */
1762 r
= MSI_OpenQuery( package
->db
, &view
, query
, dialog
->name
);
1763 if( r
!= ERROR_SUCCESS
)
1765 ERR("query failed for dialog %s\n", debugstr_w(dialog
->name
));
1766 return ERROR_INVALID_PARAMETER
;
1769 r
= MSI_IterateRecords( view
, 0, msi_dialog_create_controls
, dialog
);
1770 msiobj_release( &view
->hdr
);
1775 static UINT
msi_dialog_set_control_condition( MSIRECORD
*rec
, LPVOID param
)
1777 static const WCHAR szHide
[] = { 'H','i','d','e',0 };
1778 static const WCHAR szShow
[] = { 'S','h','o','w',0 };
1779 static const WCHAR szDisable
[] = { 'D','i','s','a','b','l','e',0 };
1780 static const WCHAR szEnable
[] = { 'E','n','a','b','l','e',0 };
1781 msi_dialog
*dialog
= param
;
1782 msi_control
*control
;
1783 LPCWSTR name
, action
, condition
;
1786 name
= MSI_RecordGetString( rec
, 2 );
1787 action
= MSI_RecordGetString( rec
, 3 );
1788 condition
= MSI_RecordGetString( rec
, 4 );
1789 r
= MSI_EvaluateConditionW( dialog
->package
, condition
);
1790 control
= msi_dialog_find_control( dialog
, name
);
1791 if( r
== MSICONDITION_TRUE
&& control
)
1793 TRACE("%s control %s\n", debugstr_w(action
), debugstr_w(name
));
1795 /* FIXME: case sensitive? */
1796 if(!lstrcmpW(action
, szHide
))
1797 ShowWindow(control
->hwnd
, SW_HIDE
);
1798 else if(!strcmpW(action
, szShow
))
1799 ShowWindow(control
->hwnd
, SW_SHOW
);
1800 else if(!strcmpW(action
, szDisable
))
1801 EnableWindow(control
->hwnd
, FALSE
);
1802 else if(!strcmpW(action
, szEnable
))
1803 EnableWindow(control
->hwnd
, TRUE
);
1805 FIXME("Unhandled action %s\n", debugstr_w(action
));
1808 return ERROR_SUCCESS
;
1811 static UINT
msi_dialog_evaluate_control_conditions( msi_dialog
*dialog
)
1813 static const WCHAR query
[] = {
1814 'S','E','L','E','C','T',' ','*',' ',
1815 'F','R','O','M',' ',
1816 'C','o','n','t','r','o','l','C','o','n','d','i','t','i','o','n',' ',
1817 'W','H','E','R','E',' ',
1818 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',0
1821 MSIQUERY
*view
= NULL
;
1822 MSIPACKAGE
*package
= dialog
->package
;
1824 TRACE("%p %s\n", dialog
, debugstr_w(dialog
->name
) );
1826 /* query the Control table for all the elements of the control */
1827 r
= MSI_OpenQuery( package
->db
, &view
, query
, dialog
->name
);
1828 if( r
!= ERROR_SUCCESS
)
1830 ERR("query failed for dialog %s\n", debugstr_w(dialog
->name
));
1831 return ERROR_INVALID_PARAMETER
;
1834 r
= MSI_IterateRecords( view
, 0, msi_dialog_set_control_condition
, dialog
);
1835 msiobj_release( &view
->hdr
);
1840 UINT
msi_dialog_reset( msi_dialog
*dialog
)
1842 /* FIXME: should restore the original values of any properties we changed */
1843 return msi_dialog_evaluate_control_conditions( dialog
);
1846 /* figure out the height of 10 point MS Sans Serif */
1847 static INT
msi_dialog_get_sans_serif_height( HWND hwnd
)
1849 static const WCHAR szSansSerif
[] = {
1850 'M','S',' ','S','a','n','s',' ','S','e','r','i','f',0 };
1855 HFONT hFont
, hOldFont
;
1858 hdc
= GetDC( hwnd
);
1861 memset( &lf
, 0, sizeof lf
);
1862 lf
.lfHeight
= MulDiv(10, GetDeviceCaps(hdc
, LOGPIXELSY
), 72);
1863 strcpyW( lf
.lfFaceName
, szSansSerif
);
1864 hFont
= CreateFontIndirectW(&lf
);
1867 hOldFont
= SelectObject( hdc
, hFont
);
1868 r
= GetTextMetricsW( hdc
, &tm
);
1870 height
= tm
.tmHeight
;
1871 SelectObject( hdc
, hOldFont
);
1872 DeleteObject( hFont
);
1874 ReleaseDC( hwnd
, hdc
);
1879 /* fetch the associated record from the Dialog table */
1880 static MSIRECORD
*msi_get_dialog_record( msi_dialog
*dialog
)
1882 static const WCHAR query
[] = {
1883 'S','E','L','E','C','T',' ','*',' ',
1884 'F','R','O','M',' ','D','i','a','l','o','g',' ',
1885 'W','H','E','R','E',' ',
1886 '`','D','i','a','l','o','g','`',' ','=',' ','\'','%','s','\'',0};
1887 MSIPACKAGE
*package
= dialog
->package
;
1888 MSIRECORD
*rec
= NULL
;
1890 TRACE("%p %s\n", dialog
, debugstr_w(dialog
->name
) );
1892 rec
= MSI_QueryGetRecord( package
->db
, query
, dialog
->name
);
1894 ERR("query failed for dialog %s\n", debugstr_w(dialog
->name
));
1899 static void msi_dialog_adjust_dialog_size( msi_dialog
*dialog
, LPSIZE sz
)
1904 /* turn the client size into the window rectangle */
1907 rect
.right
= msi_dialog_scale_unit( dialog
, sz
->cx
);
1908 rect
.bottom
= msi_dialog_scale_unit( dialog
, sz
->cy
);
1909 style
= GetWindowLongPtrW( dialog
->hwnd
, GWL_STYLE
);
1910 AdjustWindowRect( &rect
, style
, FALSE
);
1911 sz
->cx
= rect
.right
- rect
.left
;
1912 sz
->cy
= rect
.bottom
- rect
.top
;
1915 static BOOL
msi_control_set_next( msi_control
*control
, msi_control
*next
)
1917 return SetWindowPos( next
->hwnd
, control
->hwnd
, 0, 0, 0, 0,
1918 SWP_NOMOVE
| SWP_NOOWNERZORDER
| SWP_NOREDRAW
|
1919 SWP_NOREPOSITION
| SWP_NOSENDCHANGING
| SWP_NOSIZE
);
1922 static UINT
msi_dialog_set_tab_order( msi_dialog
*dialog
)
1924 msi_control
*control
, *tab_next
;
1926 LIST_FOR_EACH_ENTRY( control
, &dialog
->controls
, msi_control
, entry
)
1928 tab_next
= msi_dialog_find_control( dialog
, control
->tabnext
);
1931 msi_control_set_next( control
, tab_next
);
1934 return ERROR_SUCCESS
;
1937 static void msi_dialog_set_first_control( msi_dialog
* dialog
, LPCWSTR name
)
1939 msi_control
*control
;
1941 control
= msi_dialog_find_control( dialog
, name
);
1943 dialog
->hWndFocus
= control
->hwnd
;
1945 dialog
->hWndFocus
= NULL
;
1948 static LRESULT
msi_dialog_oncreate( HWND hwnd
, LPCREATESTRUCTW cs
)
1950 static const WCHAR df
[] = {
1951 'D','e','f','a','u','l','t','U','I','F','o','n','t',0 };
1952 static const WCHAR dfv
[] = {
1953 'M','S',' ','S','h','e','l','l',' ','D','l','g',0 };
1954 msi_dialog
*dialog
= (msi_dialog
*) cs
->lpCreateParams
;
1955 MSIRECORD
*rec
= NULL
;
1956 LPWSTR title
= NULL
;
1959 TRACE("%p %p\n", dialog
, dialog
->package
);
1961 dialog
->hwnd
= hwnd
;
1962 SetWindowLongPtrW( hwnd
, GWLP_USERDATA
, (LONG_PTR
) dialog
);
1964 rec
= msi_get_dialog_record( dialog
);
1967 TRACE("No record found for dialog %s\n", debugstr_w(dialog
->name
));
1971 dialog
->scale
= msi_dialog_get_sans_serif_height(dialog
->hwnd
);
1973 size
.cx
= MSI_RecordGetInteger( rec
, 4 );
1974 size
.cy
= MSI_RecordGetInteger( rec
, 5 );
1975 msi_dialog_adjust_dialog_size( dialog
, &size
);
1977 dialog
->attributes
= MSI_RecordGetInteger( rec
, 6 );
1979 dialog
->default_font
= msi_dup_property( dialog
->package
, df
);
1980 if (!dialog
->default_font
)
1982 dialog
->default_font
= strdupW(dfv
);
1983 if (!dialog
->default_font
) return -1;
1986 title
= msi_get_deformatted_field( dialog
->package
, rec
, 7 );
1987 SetWindowTextW( hwnd
, title
);
1990 SetWindowPos( hwnd
, 0, 0, 0, size
.cx
, size
.cy
,
1991 SWP_NOMOVE
| SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_NOREDRAW
);
1993 msi_dialog_build_font_list( dialog
);
1994 msi_dialog_fill_controls( dialog
);
1995 msi_dialog_evaluate_control_conditions( dialog
);
1996 msi_dialog_set_tab_order( dialog
);
1997 msi_dialog_set_first_control( dialog
, MSI_RecordGetString( rec
, 8 ) );
1998 msiobj_release( &rec
->hdr
);
2003 static UINT
msi_dialog_send_event( msi_dialog
*dialog
, LPCWSTR event
, LPCWSTR arg
)
2005 LPWSTR event_fmt
= NULL
, arg_fmt
= NULL
;
2007 TRACE("Sending control event %s %s\n", debugstr_w(event
), debugstr_w(arg
));
2009 deformat_string( dialog
->package
, event
, &event_fmt
);
2010 deformat_string( dialog
->package
, arg
, &arg_fmt
);
2012 dialog
->event_handler( dialog
->package
, event_fmt
, arg_fmt
, dialog
);
2014 msi_free( event_fmt
);
2015 msi_free( arg_fmt
);
2017 return ERROR_SUCCESS
;
2020 static UINT
msi_dialog_set_property( msi_dialog
*dialog
, LPCWSTR event
, LPCWSTR arg
)
2022 static const WCHAR szNullArg
[] = { '{','}',0 };
2023 LPWSTR p
, prop
, arg_fmt
= NULL
;
2026 len
= strlenW(event
);
2027 prop
= msi_alloc( len
*sizeof(WCHAR
));
2028 strcpyW( prop
, &event
[1] );
2029 p
= strchrW( prop
, ']' );
2030 if( p
&& p
[1] == 0 )
2033 if( strcmpW( szNullArg
, arg
) )
2034 deformat_string( dialog
->package
, arg
, &arg_fmt
);
2035 MSI_SetPropertyW( dialog
->package
, prop
, arg_fmt
);
2036 msi_free( arg_fmt
);
2039 ERR("Badly formatted property string - what happens?\n");
2041 return ERROR_SUCCESS
;
2044 static UINT
msi_dialog_control_event( MSIRECORD
*rec
, LPVOID param
)
2046 msi_dialog
*dialog
= param
;
2047 LPCWSTR condition
, event
, arg
;
2050 condition
= MSI_RecordGetString( rec
, 5 );
2051 r
= MSI_EvaluateConditionW( dialog
->package
, condition
);
2052 if( r
== MSICONDITION_TRUE
|| r
== MSICONDITION_NONE
)
2054 event
= MSI_RecordGetString( rec
, 3 );
2055 arg
= MSI_RecordGetString( rec
, 4 );
2056 if( event
[0] == '[' )
2057 msi_dialog_set_property( dialog
, event
, arg
);
2059 msi_dialog_send_event( dialog
, event
, arg
);
2062 return ERROR_SUCCESS
;
2065 static UINT
msi_dialog_button_handler( msi_dialog
*dialog
,
2066 msi_control
*control
, WPARAM param
)
2068 static const WCHAR query
[] = {
2069 'S','E','L','E','C','T',' ','*',' ',
2070 'F','R','O','M',' ','C','o','n','t','r','o','l','E','v','e','n','t',' ',
2071 'W','H','E','R','E',' ',
2072 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',' ',
2074 '`','C','o','n','t','r','o','l','_','`',' ','=',' ','\'','%','s','\'',' ',
2075 'O','R','D','E','R',' ','B','Y',' ','`','O','r','d','e','r','i','n','g','`',0
2077 MSIQUERY
*view
= NULL
;
2080 if( HIWORD(param
) != BN_CLICKED
)
2081 return ERROR_SUCCESS
;
2083 r
= MSI_OpenQuery( dialog
->package
->db
, &view
, query
,
2084 dialog
->name
, control
->name
);
2085 if( r
!= ERROR_SUCCESS
)
2087 ERR("query failed\n");
2091 r
= MSI_IterateRecords( view
, 0, msi_dialog_control_event
, dialog
);
2092 msiobj_release( &view
->hdr
);
2097 static UINT
msi_dialog_get_checkbox_state( msi_dialog
*dialog
,
2098 msi_control
*control
)
2100 WCHAR state
[2] = { 0 };
2103 MSI_GetPropertyW( dialog
->package
, control
->property
, state
, &sz
);
2104 return state
[0] ? 1 : 0;
2107 static void msi_dialog_set_checkbox_state( msi_dialog
*dialog
,
2108 msi_control
*control
, UINT state
)
2110 static const WCHAR szState
[] = { '1', 0 };
2113 /* if uncheck then the property is set to NULL */
2116 MSI_SetPropertyW( dialog
->package
, control
->property
, NULL
);
2120 /* check for a custom state */
2121 if (control
->value
&& control
->value
[0])
2122 val
= control
->value
;
2126 MSI_SetPropertyW( dialog
->package
, control
->property
, val
);
2129 static void msi_dialog_checkbox_sync_state( msi_dialog
*dialog
,
2130 msi_control
*control
)
2134 state
= msi_dialog_get_checkbox_state( dialog
, control
);
2135 SendMessageW( control
->hwnd
, BM_SETCHECK
,
2136 state
? BST_CHECKED
: BST_UNCHECKED
, 0 );
2139 static UINT
msi_dialog_checkbox_handler( msi_dialog
*dialog
,
2140 msi_control
*control
, WPARAM param
)
2144 if( HIWORD(param
) != BN_CLICKED
)
2145 return ERROR_SUCCESS
;
2147 TRACE("clicked checkbox %s, set %s\n", debugstr_w(control
->name
),
2148 debugstr_w(control
->property
));
2150 state
= msi_dialog_get_checkbox_state( dialog
, control
);
2151 state
= state
? 0 : 1;
2152 msi_dialog_set_checkbox_state( dialog
, control
, state
);
2153 msi_dialog_checkbox_sync_state( dialog
, control
);
2155 return msi_dialog_button_handler( dialog
, control
, param
);
2158 static UINT
msi_dialog_edit_handler( msi_dialog
*dialog
,
2159 msi_control
*control
, WPARAM param
)
2164 if( HIWORD(param
) != EN_CHANGE
)
2165 return ERROR_SUCCESS
;
2167 TRACE("edit %s contents changed, set %s\n", debugstr_w(control
->name
),
2168 debugstr_w(control
->property
));
2171 buf
= msi_alloc( sz
*sizeof(WCHAR
) );
2174 r
= GetWindowTextW( control
->hwnd
, buf
, sz
);
2178 buf
= msi_realloc( buf
, sz
*sizeof(WCHAR
) );
2181 MSI_SetPropertyW( dialog
->package
, control
->property
, buf
);
2185 return ERROR_SUCCESS
;
2188 static UINT
msi_dialog_radiogroup_handler( msi_dialog
*dialog
,
2189 msi_control
*control
, WPARAM param
)
2191 if( HIWORD(param
) != BN_CLICKED
)
2192 return ERROR_SUCCESS
;
2194 TRACE("clicked radio button %s, set %s\n", debugstr_w(control
->name
),
2195 debugstr_w(control
->property
));
2197 MSI_SetPropertyW( dialog
->package
, control
->property
, control
->name
);
2199 return msi_dialog_button_handler( dialog
, control
, param
);
2202 static LRESULT
msi_dialog_oncommand( msi_dialog
*dialog
, WPARAM param
, HWND hwnd
)
2204 msi_control
*control
= NULL
;
2206 TRACE("%p %p %08x\n", dialog
, hwnd
, param
);
2211 control
= msi_dialog_find_control( dialog
, dialog
->control_default
);
2213 case 2: /* escape */
2214 control
= msi_dialog_find_control( dialog
, dialog
->control_cancel
);
2217 control
= msi_dialog_find_control_by_hwnd( dialog
, hwnd
);
2222 if( control
->handler
)
2224 control
->handler( dialog
, control
, param
);
2225 msi_dialog_evaluate_control_conditions( dialog
);
2229 ERR("button click from nowhere %p %d %p\n", dialog
, param
, hwnd
);
2233 static void msi_dialog_setfocus( msi_dialog
*dialog
)
2235 HWND hwnd
= dialog
->hWndFocus
;
2237 hwnd
= GetNextDlgTabItem( dialog
->hwnd
, hwnd
, TRUE
);
2238 hwnd
= GetNextDlgTabItem( dialog
->hwnd
, hwnd
, FALSE
);
2240 dialog
->hWndFocus
= hwnd
;
2243 static LRESULT WINAPI
MSIDialog_WndProc( HWND hwnd
, UINT msg
,
2244 WPARAM wParam
, LPARAM lParam
)
2246 msi_dialog
*dialog
= (LPVOID
) GetWindowLongPtrW( hwnd
, GWLP_USERDATA
);
2248 TRACE("0x%04x\n", msg
);
2253 return msi_dialog_oncreate( hwnd
, (LPCREATESTRUCTW
)lParam
);
2256 return msi_dialog_oncommand( dialog
, wParam
, (HWND
)lParam
);
2259 if( LOWORD(wParam
) == WA_INACTIVE
)
2260 dialog
->hWndFocus
= GetFocus();
2262 msi_dialog_setfocus( dialog
);
2266 msi_dialog_setfocus( dialog
);
2269 /* bounce back to our subclassed static control */
2270 case WM_CTLCOLORSTATIC
:
2271 return SendMessageW( (HWND
) lParam
, WM_CTLCOLORSTATIC
, wParam
, lParam
);
2274 dialog
->hwnd
= NULL
;
2277 return DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
2280 static BOOL CALLBACK
msi_radioground_child_enum( HWND hWnd
, LPARAM lParam
)
2282 EnableWindow( hWnd
, lParam
);
2286 static LRESULT WINAPI
MSIRadioGroup_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
2288 WNDPROC oldproc
= (WNDPROC
) GetPropW(hWnd
, szButtonData
);
2291 TRACE("hWnd %p msg %04x wParam 0x%08x lParam 0x%08lx\n", hWnd
, msg
, wParam
, lParam
);
2293 if (msg
== WM_COMMAND
) /* Forward notifications to dialog */
2294 SendMessageW(GetParent(hWnd
), msg
, wParam
, lParam
);
2296 r
= CallWindowProcW(oldproc
, hWnd
, msg
, wParam
, lParam
);
2298 /* make sure the radio buttons show as disabled if the parent is disabled */
2299 if (msg
== WM_ENABLE
)
2300 EnumChildWindows( hWnd
, msi_radioground_child_enum
, wParam
);
2305 static LRESULT WINAPI
MSIHiddenWindowProc( HWND hwnd
, UINT msg
,
2306 WPARAM wParam
, LPARAM lParam
)
2308 msi_dialog
*dialog
= (msi_dialog
*) lParam
;
2310 TRACE("%d %p\n", msg
, dialog
);
2314 case WM_MSI_DIALOG_CREATE
:
2315 return msi_dialog_run_message_loop( dialog
);
2316 case WM_MSI_DIALOG_DESTROY
:
2317 msi_dialog_destroy( dialog
);
2320 return DefWindowProcW( hwnd
, msg
, wParam
, lParam
);
2323 /* functions that interface to other modules within MSI */
2325 msi_dialog
*msi_dialog_create( MSIPACKAGE
* package
, LPCWSTR szDialogName
,
2326 msi_dialog_event_handler event_handler
)
2328 MSIRECORD
*rec
= NULL
;
2331 TRACE("%p %s\n", package
, debugstr_w(szDialogName
));
2333 /* allocate the structure for the dialog to use */
2334 dialog
= msi_alloc_zero( sizeof *dialog
+ sizeof(WCHAR
)*strlenW(szDialogName
) );
2337 strcpyW( dialog
->name
, szDialogName
);
2338 msiobj_addref( &package
->hdr
);
2339 dialog
->package
= package
;
2340 dialog
->event_handler
= event_handler
;
2341 dialog
->finished
= 0;
2342 list_init( &dialog
->controls
);
2344 /* verify that the dialog exists */
2345 rec
= msi_get_dialog_record( dialog
);
2348 msiobj_release( &package
->hdr
);
2352 dialog
->attributes
= MSI_RecordGetInteger( rec
, 6 );
2353 dialog
->control_default
= strdupW( MSI_RecordGetString( rec
, 9 ) );
2354 dialog
->control_cancel
= strdupW( MSI_RecordGetString( rec
, 10 ) );
2355 msiobj_release( &rec
->hdr
);
2360 static void msi_process_pending_messages( HWND hdlg
)
2364 while( PeekMessageW( &msg
, 0, 0, 0, PM_REMOVE
) )
2366 if( hdlg
&& IsDialogMessageW( hdlg
, &msg
))
2368 TranslateMessage( &msg
);
2369 DispatchMessageW( &msg
);
2373 void msi_dialog_end_dialog( msi_dialog
*dialog
)
2375 TRACE("%p\n", dialog
);
2376 dialog
->finished
= 1;
2377 PostMessageW(dialog
->hwnd
, WM_NULL
, 0, 0);
2380 void msi_dialog_check_messages( HANDLE handle
)
2384 /* in threads other than the UI thread, block */
2385 if( uiThreadId
!= GetCurrentThreadId() )
2388 WaitForSingleObject( handle
, INFINITE
);
2392 /* there's two choices for the UI thread */
2395 msi_process_pending_messages( NULL
);
2401 * block here until somebody creates a new dialog or
2402 * the handle we're waiting on becomes ready
2404 r
= MsgWaitForMultipleObjects( 1, &handle
, 0, INFINITE
, QS_ALLINPUT
);
2405 if( r
== WAIT_OBJECT_0
)
2410 UINT
msi_dialog_run_message_loop( msi_dialog
*dialog
)
2415 if( uiThreadId
!= GetCurrentThreadId() )
2416 return SendMessageW( hMsiHiddenWindow
, WM_MSI_DIALOG_CREATE
, 0, (LPARAM
) dialog
);
2418 /* create the dialog window, don't show it yet */
2419 style
= WS_OVERLAPPED
;
2420 if( dialog
->attributes
& msidbDialogAttributesVisible
)
2421 style
|= WS_VISIBLE
;
2423 hwnd
= CreateWindowW( szMsiDialogClass
, dialog
->name
, style
,
2424 CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
,
2425 NULL
, NULL
, NULL
, dialog
);
2428 ERR("Failed to create dialog %s\n", debugstr_w( dialog
->name
));
2429 return ERROR_FUNCTION_FAILED
;
2432 ShowWindow( hwnd
, SW_SHOW
);
2433 /* UpdateWindow( hwnd ); - and causes the transparent static controls not to paint */
2435 if( dialog
->attributes
& msidbDialogAttributesModal
)
2437 while( !dialog
->finished
)
2439 MsgWaitForMultipleObjects( 0, NULL
, 0, INFINITE
, QS_ALLEVENTS
);
2440 msi_process_pending_messages( dialog
->hwnd
);
2444 return ERROR_IO_PENDING
;
2446 return ERROR_SUCCESS
;
2449 void msi_dialog_do_preview( msi_dialog
*dialog
)
2452 dialog
->attributes
|= msidbDialogAttributesVisible
;
2453 dialog
->attributes
&= ~msidbDialogAttributesModal
;
2454 msi_dialog_run_message_loop( dialog
);
2457 void msi_dialog_destroy( msi_dialog
*dialog
)
2459 if( uiThreadId
!= GetCurrentThreadId() )
2461 SendMessageW( hMsiHiddenWindow
, WM_MSI_DIALOG_DESTROY
, 0, (LPARAM
) dialog
);
2466 ShowWindow( dialog
->hwnd
, SW_HIDE
);
2469 DestroyWindow( dialog
->hwnd
);
2471 /* destroy the list of controls */
2472 while( !list_empty( &dialog
->controls
) )
2474 msi_control
*t
= LIST_ENTRY( list_head( &dialog
->controls
),
2475 msi_control
, entry
);
2476 list_remove( &t
->entry
);
2477 /* leave dialog->hwnd - destroying parent destroys child windows */
2478 msi_free( t
->property
);
2479 msi_free( t
->value
);
2481 DeleteObject( t
->hBitmap
);
2483 DestroyIcon( t
->hIcon
);
2484 msi_free( t
->tabnext
);
2487 FreeLibrary( t
->hDll
);
2490 /* destroy the list of fonts */
2491 while( dialog
->font_list
)
2493 msi_font
*t
= dialog
->font_list
;
2494 dialog
->font_list
= t
->next
;
2495 DeleteObject( t
->hfont
);
2498 msi_free( dialog
->default_font
);
2500 msi_free( dialog
->control_default
);
2501 msi_free( dialog
->control_cancel
);
2502 msiobj_release( &dialog
->package
->hdr
);
2503 dialog
->package
= NULL
;
2507 BOOL
msi_dialog_register_class( void )
2511 ZeroMemory( &cls
, sizeof cls
);
2512 cls
.lpfnWndProc
= MSIDialog_WndProc
;
2513 cls
.hInstance
= NULL
;
2514 cls
.hIcon
= LoadIconW(0, (LPWSTR
)IDI_APPLICATION
);
2515 cls
.hCursor
= LoadCursorW(0, (LPWSTR
)IDC_ARROW
);
2516 cls
.hbrBackground
= (HBRUSH
)(COLOR_3DFACE
+ 1);
2517 cls
.lpszMenuName
= NULL
;
2518 cls
.lpszClassName
= szMsiDialogClass
;
2520 if( !RegisterClassW( &cls
) )
2523 cls
.lpfnWndProc
= MSIHiddenWindowProc
;
2524 cls
.lpszClassName
= szMsiHiddenWindow
;
2526 if( !RegisterClassW( &cls
) )
2529 uiThreadId
= GetCurrentThreadId();
2531 hMsiHiddenWindow
= CreateWindowW( szMsiHiddenWindow
, NULL
, WS_OVERLAPPED
,
2532 0, 0, 100, 100, NULL
, NULL
, NULL
, NULL
);
2533 if( !hMsiHiddenWindow
)
2539 void msi_dialog_unregister_class( void )
2541 DestroyWindow( hMsiHiddenWindow
);
2542 hMsiHiddenWindow
= NULL
;
2543 UnregisterClassW( szMsiDialogClass
, NULL
);
2544 UnregisterClassW( szMsiHiddenWindow
, NULL
);