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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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
68 typedef struct msi_font_tag
70 struct msi_font_tag
*next
;
78 msi_dialog_event_handler event_handler
;
87 LPWSTR control_default
;
88 LPWSTR control_cancel
;
92 typedef UINT (*msi_dialog_control_func
)( msi_dialog
*dialog
, MSIRECORD
*rec
);
93 struct control_handler
96 msi_dialog_control_func func
;
104 } radio_button_group_descr
;
106 const WCHAR szMsiDialogClass
[] = {
107 'M','s','i','D','i','a','l','o','g','C','l','o','s','e','C','l','a','s','s',0
109 const WCHAR szMsiHiddenWindow
[] = {
110 'M','s','i','H','i','d','d','e','n','W','i','n','d','o','w',0 };
111 static const WCHAR szStatic
[] = { 'S','t','a','t','i','c',0 };
112 static const WCHAR szButton
[] = { 'B','U','T','T','O','N', 0 };
113 static const WCHAR szButtonData
[] = { 'M','S','I','D','A','T','A',0 };
114 static const WCHAR szText
[] = { 'T','e','x','t',0 };
115 static const WCHAR szPushButton
[] = { 'P','u','s','h','B','u','t','t','o','n',0 };
116 static const WCHAR szLine
[] = { 'L','i','n','e',0 };
117 static const WCHAR szBitmap
[] = { 'B','i','t','m','a','p',0 };
118 static const WCHAR szCheckBox
[] = { 'C','h','e','c','k','B','o','x',0 };
119 static const WCHAR szScrollableText
[] = {
120 'S','c','r','o','l','l','a','b','l','e','T','e','x','t',0 };
121 static const WCHAR szComboBox
[] = { 'C','o','m','b','o','B','o','x',0 };
122 static const WCHAR szEdit
[] = { 'E','d','i','t',0 };
123 static const WCHAR szMaskedEdit
[] = { 'M','a','s','k','e','d','E','d','i','t',0 };
124 static const WCHAR szPathEdit
[] = { 'P','a','t','h','E','d','i','t',0 };
125 static const WCHAR szProgressBar
[] = {
126 'P','r','o','g','r','e','s','s','B','a','r',0 };
127 static const WCHAR szRadioButtonGroup
[] = {
128 'R','a','d','i','o','B','u','t','t','o','n','G','r','o','u','p',0 };
129 static const WCHAR szIcon
[] = { 'I','c','o','n',0 };
130 static const WCHAR szSelectionTree
[] = {
131 'S','e','l','e','c','t','i','o','n','T','r','e','e',0 };
133 static UINT
msi_dialog_checkbox_handler( msi_dialog
*, msi_control
*, WPARAM
);
134 static void msi_dialog_checkbox_sync_state( msi_dialog
*, msi_control
* );
135 static UINT
msi_dialog_button_handler( msi_dialog
*, msi_control
*, WPARAM
);
136 static UINT
msi_dialog_edit_handler( msi_dialog
*, msi_control
*, WPARAM
);
137 static UINT
msi_dialog_radiogroup_handler( msi_dialog
*, msi_control
*, WPARAM param
);
138 static UINT
msi_dialog_evaluate_control_conditions( msi_dialog
*dialog
);
139 static LRESULT WINAPI
MSIRadioGroup_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
);
142 /* dialog sequencing */
144 #define WM_MSI_DIALOG_CREATE (WM_USER+0x100)
145 #define WM_MSI_DIALOG_DESTROY (WM_USER+0x101)
147 static DWORD uiThreadId
;
148 static HWND hMsiHiddenWindow
;
150 static INT
msi_dialog_scale_unit( msi_dialog
*dialog
, INT val
)
152 return (dialog
->scale
* val
+ 5) / 10;
155 static msi_control
*msi_dialog_find_control( msi_dialog
*dialog
, LPCWSTR name
)
157 msi_control
*control
;
161 LIST_FOR_EACH_ENTRY( control
, &dialog
->controls
, msi_control
, entry
)
162 if( !strcmpW( control
->name
, name
) ) /* FIXME: case sensitive? */
167 static msi_control
*msi_dialog_find_control_by_hwnd( msi_dialog
*dialog
, HWND hwnd
)
169 msi_control
*control
;
171 LIST_FOR_EACH_ENTRY( control
, &dialog
->controls
, msi_control
, entry
)
172 if( hwnd
== control
->hwnd
)
177 static LPWSTR
msi_get_deformatted_field( MSIPACKAGE
*package
, MSIRECORD
*rec
, int field
)
179 LPCWSTR str
= MSI_RecordGetString( rec
, field
);
183 deformat_string( package
, str
, &ret
);
188 * msi_dialog_get_style
190 * Extract the {\style} string from the front of the text to display and
191 * update the pointer.
193 static LPWSTR
msi_dialog_get_style( LPCWSTR p
, LPCWSTR
*rest
)
204 q
= strchrW( p
, '}' );
207 if( *p
== '\\' || *p
== '&' )
210 /* little bit of sanity checking to stop us getting confused with RTF */
212 if( *i
== '}' || *i
== '\\' )
218 ret
= msi_alloc( len
*sizeof(WCHAR
) );
221 memcpy( ret
, p
, len
*sizeof(WCHAR
) );
226 static UINT
msi_dialog_add_font( MSIRECORD
*rec
, LPVOID param
)
228 msi_dialog
*dialog
= param
;
235 /* create a font and add it to the list */
236 name
= MSI_RecordGetString( rec
, 1 );
237 font
= msi_alloc( sizeof *font
+ strlenW( name
)*sizeof (WCHAR
) );
238 strcpyW( font
->name
, name
);
239 font
->next
= dialog
->font_list
;
240 dialog
->font_list
= font
;
242 memset( &lf
, 0, sizeof lf
);
243 face
= MSI_RecordGetString( rec
, 2 );
244 lf
.lfHeight
= MSI_RecordGetInteger( rec
, 3 );
245 style
= MSI_RecordGetInteger( rec
, 5 );
246 if( style
& msidbTextStyleStyleBitsBold
)
247 lf
.lfWeight
= FW_BOLD
;
248 if( style
& msidbTextStyleStyleBitsItalic
)
250 if( style
& msidbTextStyleStyleBitsUnderline
)
251 lf
.lfUnderline
= TRUE
;
252 if( style
& msidbTextStyleStyleBitsStrike
)
253 lf
.lfStrikeOut
= TRUE
;
254 lstrcpynW( lf
.lfFaceName
, face
, LF_FACESIZE
);
256 /* adjust the height */
257 hdc
= GetDC( dialog
->hwnd
);
260 lf
.lfHeight
= -MulDiv(lf
.lfHeight
, GetDeviceCaps(hdc
, LOGPIXELSY
), 72);
261 ReleaseDC( dialog
->hwnd
, hdc
);
264 font
->hfont
= CreateFontIndirectW( &lf
);
266 TRACE("Adding font style %s\n", debugstr_w(font
->name
) );
268 return ERROR_SUCCESS
;
271 static msi_font
*msi_dialog_find_font( msi_dialog
*dialog
, LPCWSTR name
)
275 for( font
= dialog
->font_list
; font
; font
= font
->next
)
276 if( !strcmpW( font
->name
, name
) ) /* FIXME: case sensitive? */
282 static UINT
msi_dialog_set_font( msi_dialog
*dialog
, HWND hwnd
, LPCWSTR name
)
286 font
= msi_dialog_find_font( dialog
, name
);
288 SendMessageW( hwnd
, WM_SETFONT
, (WPARAM
) font
->hfont
, TRUE
);
290 ERR("No font entry for %s\n", debugstr_w(name
));
291 return ERROR_SUCCESS
;
294 static UINT
msi_dialog_build_font_list( msi_dialog
*dialog
)
296 static const WCHAR query
[] = {
297 'S','E','L','E','C','T',' ','*',' ',
298 'F','R','O','M',' ','`','T','e','x','t','S','t','y','l','e','`',' ',0
301 MSIQUERY
*view
= NULL
;
303 TRACE("dialog %p\n", dialog
);
305 r
= MSI_OpenQuery( dialog
->package
->db
, &view
, query
);
306 if( r
!= ERROR_SUCCESS
)
309 r
= MSI_IterateRecords( view
, NULL
, msi_dialog_add_font
, dialog
);
310 msiobj_release( &view
->hdr
);
315 static msi_control
*msi_dialog_create_window( msi_dialog
*dialog
,
316 MSIRECORD
*rec
, LPCWSTR szCls
, LPCWSTR name
, LPCWSTR text
,
317 DWORD style
, HWND parent
)
319 DWORD x
, y
, width
, height
;
320 LPWSTR font
= NULL
, title_font
= NULL
;
321 LPCWSTR title
= NULL
;
322 msi_control
*control
;
326 control
= msi_alloc( sizeof *control
+ strlenW(name
)*sizeof(WCHAR
) );
327 strcpyW( control
->name
, name
);
328 list_add_head( &dialog
->controls
, &control
->entry
);
329 control
->handler
= NULL
;
330 control
->property
= NULL
;
331 control
->value
= NULL
;
332 control
->hBitmap
= NULL
;
333 control
->hIcon
= NULL
;
334 control
->hDll
= NULL
;
335 control
->tabnext
= strdupW( MSI_RecordGetString( rec
, 11) );
337 x
= MSI_RecordGetInteger( rec
, 4 );
338 y
= MSI_RecordGetInteger( rec
, 5 );
339 width
= MSI_RecordGetInteger( rec
, 6 );
340 height
= MSI_RecordGetInteger( rec
, 7 );
342 x
= msi_dialog_scale_unit( dialog
, x
);
343 y
= msi_dialog_scale_unit( dialog
, y
);
344 width
= msi_dialog_scale_unit( dialog
, width
);
345 height
= msi_dialog_scale_unit( dialog
, height
);
349 deformat_string( dialog
->package
, text
, &title_font
);
350 font
= msi_dialog_get_style( title_font
, &title
);
353 control
->hwnd
= CreateWindowW( szCls
, title
, style
,
354 x
, y
, width
, height
, parent
, NULL
, NULL
, NULL
);
356 TRACE("Dialog %s control %s hwnd %p\n",
357 debugstr_w(dialog
->name
), debugstr_w(text
), control
->hwnd
);
359 msi_dialog_set_font( dialog
, control
->hwnd
,
360 font
? font
: dialog
->default_font
);
362 msi_free( title_font
);
368 static MSIRECORD
*msi_get_binary_record( MSIDATABASE
*db
, LPCWSTR name
)
370 static const WCHAR query
[] = {
371 's','e','l','e','c','t',' ','*',' ',
372 'f','r','o','m',' ','B','i','n','a','r','y',' ',
373 'w','h','e','r','e',' ',
374 '`','N','a','m','e','`',' ','=',' ','\'','%','s','\'',0
377 return MSI_QueryGetRecord( db
, query
, name
);
380 static LPWSTR
msi_create_tmp_path(void)
384 static const WCHAR prefix
[] = { 'm','s','i',0 };
387 r
= GetTempPathW( MAX_PATH
, tmp
);
390 len
= lstrlenW( tmp
) + 20;
391 path
= msi_alloc( len
* sizeof (WCHAR
) );
394 r
= GetTempFileNameW( tmp
, prefix
, 0, path
);
405 static HANDLE
msi_load_image( MSIDATABASE
*db
, LPCWSTR name
, UINT type
,
406 UINT cx
, UINT cy
, UINT flags
)
408 MSIRECORD
*rec
= NULL
;
409 HANDLE himage
= NULL
;
413 TRACE("%p %s %u %u %08x\n", db
, debugstr_w(name
), cx
, cy
, flags
);
415 tmp
= msi_create_tmp_path();
419 rec
= msi_get_binary_record( db
, name
);
422 r
= MSI_RecordStreamToFile( rec
, 2, tmp
);
423 if( r
== ERROR_SUCCESS
)
425 himage
= LoadImageW( 0, tmp
, type
, cx
, cy
, flags
);
428 msiobj_release( &rec
->hdr
);
435 static HICON
msi_load_icon( MSIDATABASE
*db
, LPCWSTR text
, UINT attributes
)
437 DWORD cx
= 0, cy
= 0, flags
;
439 flags
= LR_LOADFROMFILE
| LR_DEFAULTSIZE
;
440 if( attributes
& msidbControlAttributesFixedSize
)
442 flags
&= ~LR_DEFAULTSIZE
;
443 if( attributes
& msidbControlAttributesIconSize16
)
448 if( attributes
& msidbControlAttributesIconSize32
)
453 /* msidbControlAttributesIconSize48 handled by above logic */
455 return msi_load_image( db
, text
, IMAGE_ICON
, cx
, cy
, flags
);
459 /* called from the Control Event subscription code */
460 void msi_dialog_handle_event( msi_dialog
* dialog
, LPCWSTR control
,
461 LPCWSTR attribute
, MSIRECORD
*rec
)
464 LPCWSTR font_text
, text
= NULL
;
467 ctrl
= msi_dialog_find_control( dialog
, control
);
470 if( lstrcmpW(attribute
, szText
) )
472 ERR("Attribute %s\n", debugstr_w(attribute
));
475 font_text
= MSI_RecordGetString( rec
, 1 );
476 font
= msi_dialog_get_style( font_text
, &text
);
477 SetWindowTextW( ctrl
->hwnd
, text
);
479 msi_dialog_check_messages( NULL
);
482 static void msi_dialog_map_events(msi_dialog
* dialog
, LPCWSTR control
)
484 static WCHAR Query
[] = {
485 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
486 '`','E','v','e','n','t','M','a','p','p','i','n','g','`',' ',
487 'W','H','E','R','E',' ',
488 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',' ',
490 '`','C','o','n','t','r','o','l','_','`',' ','=',' ','\'','%','s','\'',0
493 LPCWSTR event
, attribute
;
495 row
= MSI_QueryGetRecord( dialog
->package
->db
, Query
, dialog
->name
, control
);
499 event
= MSI_RecordGetString( row
, 3 );
500 attribute
= MSI_RecordGetString( row
, 4 );
501 ControlEvent_SubscribeToEvent( dialog
->package
, event
, control
, attribute
);
502 msiobj_release( &row
->hdr
);
505 /* everything except radio buttons */
506 static msi_control
*msi_dialog_add_control( msi_dialog
*dialog
,
507 MSIRECORD
*rec
, LPCWSTR szCls
, DWORD style
)
512 name
= MSI_RecordGetString( rec
, 2 );
513 attributes
= MSI_RecordGetInteger( rec
, 8 );
514 text
= MSI_RecordGetString( rec
, 10 );
515 if( attributes
& msidbControlAttributesVisible
)
517 if( ~attributes
& msidbControlAttributesEnabled
)
518 style
|= WS_DISABLED
;
520 msi_dialog_map_events(dialog
, name
);
522 return msi_dialog_create_window( dialog
, rec
, szCls
, name
, text
,
523 style
, dialog
->hwnd
);
533 * we don't erase our own background,
534 * so we have to make sure that the parent window redraws first
536 static void msi_text_on_settext( HWND hWnd
)
541 hParent
= GetParent( hWnd
);
542 GetWindowRect( hWnd
, &rc
);
543 MapWindowPoints( NULL
, hParent
, (LPPOINT
) &rc
, 2 );
544 InvalidateRect( hParent
, &rc
, TRUE
);
547 static LRESULT WINAPI
548 MSIText_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
550 struct msi_text_info
*info
;
553 TRACE("%p %04x %08x %08lx\n", hWnd
, msg
, wParam
, lParam
);
555 info
= GetPropW(hWnd
, szButtonData
);
557 if( msg
== WM_CTLCOLORSTATIC
&&
558 ( info
->attributes
& msidbControlAttributesTransparent
) )
560 SetBkMode( (HDC
)wParam
, TRANSPARENT
);
561 return (LRESULT
) GetStockObject(NULL_BRUSH
);
564 r
= CallWindowProcW(info
->oldproc
, hWnd
, msg
, wParam
, lParam
);
569 msi_text_on_settext( hWnd
);
573 RemovePropW( hWnd
, szButtonData
);
580 static UINT
msi_dialog_text_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
582 msi_control
*control
;
583 struct msi_text_info
*info
;
585 TRACE("%p %p\n", dialog
, rec
);
587 control
= msi_dialog_add_control( dialog
, rec
, szStatic
, SS_LEFT
| WS_GROUP
);
589 return ERROR_FUNCTION_FAILED
;
591 info
= msi_alloc( sizeof *info
);
593 return ERROR_SUCCESS
;
595 info
->attributes
= MSI_RecordGetInteger( rec
, 8 );
596 if( info
->attributes
& msidbControlAttributesTransparent
)
597 SetWindowLongPtrW( control
->hwnd
, GWL_EXSTYLE
, WS_EX_TRANSPARENT
);
599 info
->oldproc
= (WNDPROC
) SetWindowLongPtrW( control
->hwnd
, GWLP_WNDPROC
,
600 (LONG_PTR
)MSIText_WndProc
);
601 SetPropW( control
->hwnd
, szButtonData
, info
);
603 return ERROR_SUCCESS
;
606 static UINT
msi_dialog_button_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
608 msi_control
*control
;
609 UINT attributes
, style
;
612 TRACE("%p %p\n", dialog
, rec
);
615 attributes
= MSI_RecordGetInteger( rec
, 8 );
616 if( attributes
& msidbControlAttributesIcon
)
619 control
= msi_dialog_add_control( dialog
, rec
, szButton
, style
);
621 return ERROR_FUNCTION_FAILED
;
623 control
->handler
= msi_dialog_button_handler
;
626 text
= msi_get_deformatted_field( dialog
->package
, rec
, 10 );
627 control
->hIcon
= msi_load_icon( dialog
->package
->db
, text
, attributes
);
628 if( attributes
& msidbControlAttributesIcon
)
629 SendMessageW( control
->hwnd
, BM_SETIMAGE
, IMAGE_ICON
, (LPARAM
) control
->hIcon
);
632 return ERROR_SUCCESS
;
635 static LPWSTR
msi_get_checkbox_value( msi_dialog
*dialog
, LPCWSTR prop
)
637 static const WCHAR query
[] = {
638 'S','E','L','E','C','T',' ','*',' ',
639 'F','R','O','M',' ','`','C','h','e','c','k','B','o','x',' ','`',
640 'W','H','E','R','E',' ',
641 '`','P','r','o','p','e','r','t','y','`',' ','=',' ',
644 MSIRECORD
*rec
= NULL
;
647 /* find if there is a value associated with the checkbox */
648 rec
= MSI_QueryGetRecord( dialog
->package
->db
, query
, prop
);
652 ret
= msi_get_deformatted_field( dialog
->package
, rec
, 2 );
658 msiobj_release( &rec
->hdr
);
662 ret
= msi_dup_property( dialog
->package
, prop
);
672 static UINT
msi_dialog_checkbox_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
674 msi_control
*control
;
677 TRACE("%p %p\n", dialog
, rec
);
679 control
= msi_dialog_add_control( dialog
, rec
, szButton
,
680 BS_CHECKBOX
| BS_MULTILINE
| WS_TABSTOP
);
681 control
->handler
= msi_dialog_checkbox_handler
;
682 prop
= MSI_RecordGetString( rec
, 9 );
685 control
->property
= strdupW( prop
);
686 control
->value
= msi_get_checkbox_value( dialog
, prop
);
687 TRACE("control %s value %s\n", debugstr_w(control
->property
),
688 debugstr_w(control
->value
));
690 msi_dialog_checkbox_sync_state( dialog
, control
);
692 return ERROR_SUCCESS
;
695 static UINT
msi_dialog_line_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
697 TRACE("%p %p\n", dialog
, rec
);
699 msi_dialog_add_control( dialog
, rec
, szStatic
, SS_ETCHEDHORZ
| SS_SUNKEN
);
700 return ERROR_SUCCESS
;
703 /******************** Scroll Text ********************************************/
705 struct msi_scrolltext_info
708 msi_control
*control
;
712 static LRESULT WINAPI
713 MSIScrollText_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
715 struct msi_scrolltext_info
*info
;
718 TRACE("%p %04x %08x %08lx\n", hWnd
, msg
, wParam
, lParam
);
720 info
= GetPropW( hWnd
, szButtonData
);
722 r
= CallWindowProcW( info
->oldproc
, hWnd
, msg
, wParam
, lParam
);
728 RemovePropW( hWnd
, szButtonData
);
731 /* native MSI sets a wait cursor here */
732 msi_dialog_button_handler( info
->dialog
, info
->control
, BN_CLICKED
);
738 struct msi_streamin_info
745 static DWORD CALLBACK
746 msi_richedit_stream_in( DWORD_PTR arg
, LPBYTE buffer
, LONG count
, LONG
*pcb
)
748 struct msi_streamin_info
*info
= (struct msi_streamin_info
*) arg
;
750 if( (count
+ info
->offset
) > info
->length
)
751 count
= info
->length
- info
->offset
;
752 memcpy( buffer
, &info
->string
[ info
->offset
], count
);
754 info
->offset
+= count
;
756 TRACE("%ld/%ld\n", info
->offset
, info
->length
);
761 static void msi_scrolltext_add_text( msi_control
*control
, LPCWSTR text
)
763 struct msi_streamin_info info
;
766 info
.string
= strdupWtoA( text
);
768 info
.length
= lstrlenA( info
.string
) + 1;
770 es
.dwCookie
= (DWORD_PTR
) &info
;
772 es
.pfnCallback
= msi_richedit_stream_in
;
774 SendMessageW( control
->hwnd
, EM_STREAMIN
, SF_RTF
, (LPARAM
) &es
);
776 msi_free( info
.string
);
779 static UINT
msi_dialog_scrolltext_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
781 static const WCHAR szRichEdit20W
[] = {
782 'R','i','c','h','E','d','i','t','2','0','W',0
784 struct msi_scrolltext_info
*info
;
785 msi_control
*control
;
789 info
= msi_alloc( sizeof *info
);
791 return ERROR_FUNCTION_FAILED
;
793 hRichedit
= LoadLibraryA("riched20");
795 style
= WS_BORDER
| ES_MULTILINE
| WS_VSCROLL
|
796 ES_READONLY
| ES_AUTOVSCROLL
| WS_TABSTOP
;
797 control
= msi_dialog_add_control( dialog
, rec
, szRichEdit20W
, style
);
800 FreeLibrary( hRichedit
);
802 return ERROR_FUNCTION_FAILED
;
805 control
->hDll
= hRichedit
;
807 info
->dialog
= dialog
;
808 info
->control
= control
;
810 /* subclass the static control */
811 info
->oldproc
= (WNDPROC
) SetWindowLongPtrW( control
->hwnd
, GWLP_WNDPROC
,
812 (LONG_PTR
)MSIScrollText_WndProc
);
813 SetPropW( control
->hwnd
, szButtonData
, info
);
815 /* add the text into the richedit */
816 msi_scrolltext_add_text( control
, MSI_RecordGetString( rec
, 10 ) );
818 return ERROR_SUCCESS
;
821 static HBITMAP
msi_load_picture( MSIDATABASE
*db
, LPCWSTR name
,
822 INT cx
, INT cy
, DWORD flags
)
824 HBITMAP hOleBitmap
= 0, hBitmap
= 0, hOldSrcBitmap
, hOldDestBitmap
;
825 MSIRECORD
*rec
= NULL
;
827 IPicture
*pic
= NULL
;
832 rec
= msi_get_binary_record( db
, name
);
836 r
= MSI_RecordGetIStream( rec
, 2, &stm
);
837 msiobj_release( &rec
->hdr
);
838 if( r
!= ERROR_SUCCESS
)
841 r
= OleLoadPicture( stm
, 0, TRUE
, &IID_IPicture
, (LPVOID
*) &pic
);
842 IStream_Release( stm
);
845 ERR("failed to load picture\n");
849 r
= IPicture_get_Handle( pic
, (OLE_HANDLE
*) &hOleBitmap
);
852 ERR("failed to get bitmap handle\n");
856 /* make the bitmap the desired size */
857 r
= GetObjectW( hOleBitmap
, sizeof bm
, &bm
);
860 ERR("failed to get bitmap size\n");
864 if (flags
& LR_DEFAULTSIZE
)
870 srcdc
= CreateCompatibleDC( NULL
);
871 hOldSrcBitmap
= SelectObject( srcdc
, hOleBitmap
);
872 destdc
= CreateCompatibleDC( NULL
);
873 hBitmap
= CreateCompatibleBitmap( srcdc
, cx
, cy
);
874 hOldDestBitmap
= SelectObject( destdc
, hBitmap
);
875 StretchBlt( destdc
, 0, 0, cx
, cy
,
876 srcdc
, 0, 0, bm
.bmWidth
, bm
.bmHeight
, SRCCOPY
);
877 SelectObject( srcdc
, hOldSrcBitmap
);
878 SelectObject( destdc
, hOldDestBitmap
);
884 IPicture_Release( pic
);
888 static UINT
msi_dialog_bitmap_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
890 UINT cx
, cy
, flags
, style
, attributes
;
891 msi_control
*control
;
894 flags
= LR_LOADFROMFILE
;
895 style
= SS_BITMAP
| SS_LEFT
| WS_GROUP
;
897 attributes
= MSI_RecordGetInteger( rec
, 8 );
898 if( attributes
& msidbControlAttributesFixedSize
)
900 flags
|= LR_DEFAULTSIZE
;
901 style
|= SS_CENTERIMAGE
;
904 control
= msi_dialog_add_control( dialog
, rec
, szStatic
, style
);
905 cx
= MSI_RecordGetInteger( rec
, 6 );
906 cy
= MSI_RecordGetInteger( rec
, 7 );
907 cx
= msi_dialog_scale_unit( dialog
, cx
);
908 cy
= msi_dialog_scale_unit( dialog
, cy
);
910 text
= msi_get_deformatted_field( dialog
->package
, rec
, 10 );
911 control
->hBitmap
= msi_load_picture( dialog
->package
->db
, text
, cx
, cy
, flags
);
912 if( control
->hBitmap
)
913 SendMessageW( control
->hwnd
, STM_SETIMAGE
,
914 IMAGE_BITMAP
, (LPARAM
) control
->hBitmap
);
916 ERR("Failed to load bitmap %s\n", debugstr_w(text
));
920 return ERROR_SUCCESS
;
923 static UINT
msi_dialog_icon_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
925 msi_control
*control
;
931 control
= msi_dialog_add_control( dialog
, rec
, szStatic
,
932 SS_ICON
| SS_CENTERIMAGE
| WS_GROUP
);
934 attributes
= MSI_RecordGetInteger( rec
, 8 );
935 text
= msi_get_deformatted_field( dialog
->package
, rec
, 10 );
936 control
->hIcon
= msi_load_icon( dialog
->package
->db
, text
, attributes
);
938 SendMessageW( control
->hwnd
, STM_SETICON
, (WPARAM
) control
->hIcon
, 0 );
940 ERR("Failed to load bitmap %s\n", debugstr_w(text
));
942 return ERROR_SUCCESS
;
945 static UINT
msi_dialog_combo_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
947 static const WCHAR szCombo
[] = { 'C','O','M','B','O','B','O','X',0 };
949 msi_dialog_add_control( dialog
, rec
, szCombo
,
950 SS_BITMAP
| SS_LEFT
| SS_CENTERIMAGE
);
951 return ERROR_SUCCESS
;
954 static UINT
msi_dialog_edit_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
956 msi_control
*control
;
960 control
= msi_dialog_add_control( dialog
, rec
, szEdit
,
961 WS_BORDER
| WS_TABSTOP
);
962 control
->handler
= msi_dialog_edit_handler
;
963 prop
= MSI_RecordGetString( rec
, 9 );
965 control
->property
= strdupW( prop
);
966 val
= msi_dup_property( dialog
->package
, control
->property
);
967 SetWindowTextW( control
->hwnd
, val
);
969 return ERROR_SUCCESS
;
972 /******************** Masked Edit ********************************************/
974 #define MASK_MAX_GROUPS 10
976 struct msi_mask_group
984 struct msi_maskedit_info
992 struct msi_mask_group group
[MASK_MAX_GROUPS
];
995 static BOOL
msi_mask_editable( WCHAR type
)
1010 static void msi_mask_control_change( struct msi_maskedit_info
*info
)
1015 val
= msi_alloc( (info
->num_chars
+1)*sizeof(WCHAR
) );
1016 for( i
=0, n
=0; i
<info
->num_groups
; i
++ )
1018 if( (info
->group
[i
].len
+ n
) > info
->num_chars
)
1020 ERR("can't fit control %d text into template\n",i
);
1023 if (!msi_mask_editable(info
->group
[i
].type
))
1025 for(r
=0; r
<info
->group
[i
].len
; r
++)
1026 val
[n
+r
] = info
->group
[i
].type
;
1031 r
= GetWindowTextW( info
->group
[i
].hwnd
, &val
[n
], info
->group
[i
].len
+1 );
1032 if( r
!= info
->group
[i
].len
)
1038 TRACE("%d/%d controls were good\n", i
, info
->num_groups
);
1040 if( i
== info
->num_groups
)
1042 TRACE("Set property %s to %s\n",
1043 debugstr_w(info
->prop
), debugstr_w(val
) );
1044 CharUpperBuffW( val
, info
->num_chars
);
1045 MSI_SetPropertyW( info
->dialog
->package
, info
->prop
, val
);
1046 msi_dialog_evaluate_control_conditions( info
->dialog
);
1051 /* now move to the next control if necessary */
1052 static VOID
msi_mask_next_control( struct msi_maskedit_info
*info
, HWND hWnd
)
1057 for( i
=0; i
<info
->num_groups
; i
++ )
1058 if( info
->group
[i
].hwnd
== hWnd
)
1061 /* don't move from the last control */
1062 if( i
>= (info
->num_groups
-1) )
1065 len
= SendMessageW( hWnd
, WM_GETTEXTLENGTH
, 0, 0 );
1066 if( len
< info
->group
[i
].len
)
1069 hWndNext
= GetNextDlgTabItem( GetParent( hWnd
), hWnd
, FALSE
);
1070 SetFocus( hWndNext
);
1073 static LRESULT WINAPI
1074 MSIMaskedEdit_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1076 struct msi_maskedit_info
*info
;
1079 TRACE("%p %04x %08x %08lx\n", hWnd
, msg
, wParam
, lParam
);
1081 info
= GetPropW(hWnd
, szButtonData
);
1083 r
= CallWindowProcW(info
->oldproc
, hWnd
, msg
, wParam
, lParam
);
1088 if (HIWORD(wParam
) == EN_CHANGE
)
1090 msi_mask_control_change( info
);
1091 msi_mask_next_control( info
, (HWND
) lParam
);
1095 msi_free( info
->prop
);
1097 RemovePropW( hWnd
, szButtonData
);
1104 /* fish the various bits of the property out and put them in the control */
1106 msi_maskedit_set_text( struct msi_maskedit_info
*info
, LPCWSTR text
)
1112 for( i
= 0; i
< info
->num_groups
; i
++ )
1114 if( info
->group
[i
].len
< lstrlenW( p
) )
1116 LPWSTR chunk
= strdupW( p
);
1117 chunk
[ info
->group
[i
].len
] = 0;
1118 SetWindowTextW( info
->group
[i
].hwnd
, chunk
);
1123 SetWindowTextW( info
->group
[i
].hwnd
, p
);
1126 p
+= info
->group
[i
].len
;
1130 static struct msi_maskedit_info
* msi_dialog_parse_groups( LPCWSTR mask
)
1132 struct msi_maskedit_info
* info
= NULL
;
1133 int i
= 0, n
= 0, total
= 0;
1136 TRACE("masked control, template %s\n", debugstr_w(mask
));
1141 info
= msi_alloc_zero( sizeof *info
);
1145 p
= strchrW(mask
, '<');
1151 for( i
=0; i
<MASK_MAX_GROUPS
; i
++ )
1153 /* stop at the end of the string */
1154 if( p
[0] == 0 || p
[0] == '>' )
1157 /* count the number of the same identifier */
1158 for( n
=0; p
[n
] == p
[0]; n
++ )
1160 info
->group
[i
].ofs
= total
;
1161 info
->group
[i
].type
= p
[0];
1165 total
++; /* an extra not part of the group */
1167 info
->group
[i
].len
= n
;
1172 TRACE("%d characters in %d groups\n", total
, i
);
1173 if( i
== MASK_MAX_GROUPS
)
1174 ERR("too many groups in PIDTemplate %s\n", debugstr_w(mask
));
1176 info
->num_chars
= total
;
1177 info
->num_groups
= i
;
1183 msi_maskedit_create_children( struct msi_maskedit_info
*info
, LPCWSTR font
)
1185 DWORD width
, height
, style
, wx
, ww
;
1190 style
= WS_CHILD
| WS_BORDER
| WS_VISIBLE
| WS_TABSTOP
| ES_AUTOHSCROLL
;
1192 GetClientRect( info
->hwnd
, &rect
);
1194 width
= rect
.right
- rect
.left
;
1195 height
= rect
.bottom
- rect
.top
;
1197 for( i
= 0; i
< info
->num_groups
; i
++ )
1199 if (!msi_mask_editable( info
->group
[i
].type
))
1201 wx
= (info
->group
[i
].ofs
* width
) / info
->num_chars
;
1202 ww
= (info
->group
[i
].len
* width
) / info
->num_chars
;
1204 hwnd
= CreateWindowW( szEdit
, NULL
, style
, wx
, 0, ww
, height
,
1205 info
->hwnd
, NULL
, NULL
, NULL
);
1208 ERR("failed to create mask edit sub window\n");
1212 SendMessageW( hwnd
, EM_LIMITTEXT
, info
->group
[i
].len
, 0 );
1214 msi_dialog_set_font( info
->dialog
, hwnd
,
1215 font
?font
:info
->dialog
->default_font
);
1216 info
->group
[i
].hwnd
= hwnd
;
1221 * office 2003 uses "73931<````=````=````=````=`````>@@@@@"
1222 * delphi 7 uses "<????-??????-??????-????>" and "<???-???>"
1223 * filemaker pro 7 uses "<^^^^=^^^^=^^^^=^^^^=^^^^=^^^^=^^^^^>"
1225 static UINT
msi_dialog_maskedit_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1227 LPWSTR font_mask
, val
= NULL
, font
;
1228 struct msi_maskedit_info
*info
= NULL
;
1229 UINT ret
= ERROR_SUCCESS
;
1230 msi_control
*control
;
1235 font_mask
= msi_get_deformatted_field( dialog
->package
, rec
, 10 );
1236 font
= msi_dialog_get_style( font_mask
, &mask
);
1239 ERR("mask template is empty\n");
1243 info
= msi_dialog_parse_groups( mask
);
1246 ERR("template %s is invalid\n", debugstr_w(mask
));
1250 info
->dialog
= dialog
;
1252 control
= msi_dialog_add_control( dialog
, rec
, szStatic
,
1253 SS_OWNERDRAW
| WS_GROUP
| WS_VISIBLE
);
1256 ERR("Failed to create maskedit container\n");
1257 ret
= ERROR_FUNCTION_FAILED
;
1260 SetWindowLongPtrW( control
->hwnd
, GWL_EXSTYLE
, WS_EX_CONTROLPARENT
);
1262 info
->hwnd
= control
->hwnd
;
1264 /* subclass the static control */
1265 info
->oldproc
= (WNDPROC
) SetWindowLongPtrW( info
->hwnd
, GWLP_WNDPROC
,
1266 (LONG_PTR
)MSIMaskedEdit_WndProc
);
1267 SetPropW( control
->hwnd
, szButtonData
, info
);
1269 prop
= MSI_RecordGetString( rec
, 9 );
1271 info
->prop
= strdupW( prop
);
1273 msi_maskedit_create_children( info
, font
);
1277 val
= msi_dup_property( dialog
->package
, prop
);
1280 msi_maskedit_set_text( info
, val
);
1286 if( ret
!= ERROR_SUCCESS
)
1288 msi_free( font_mask
);
1293 /******************** Progress Bar *****************************************/
1295 static UINT
msi_dialog_progress_bar( msi_dialog
*dialog
, MSIRECORD
*rec
)
1297 msi_dialog_add_control( dialog
, rec
, PROGRESS_CLASSW
, WS_VISIBLE
);
1298 return ERROR_SUCCESS
;
1301 /******************** Path Edit ********************************************/
1303 static UINT
msi_dialog_pathedit_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1305 FIXME("not implemented properly\n");
1306 return msi_dialog_edit_control( dialog
, rec
);
1309 /* radio buttons are a bit different from normal controls */
1310 static UINT
msi_dialog_create_radiobutton( MSIRECORD
*rec
, LPVOID param
)
1312 radio_button_group_descr
*group
= (radio_button_group_descr
*)param
;
1313 msi_dialog
*dialog
= group
->dialog
;
1314 msi_control
*control
;
1315 LPCWSTR prop
, text
, name
;
1316 DWORD style
, attributes
= group
->attributes
;
1318 style
= WS_CHILD
| BS_AUTORADIOBUTTON
| BS_MULTILINE
| WS_TABSTOP
;
1319 name
= MSI_RecordGetString( rec
, 3 );
1320 text
= MSI_RecordGetString( rec
, 8 );
1321 if( attributes
& 1 )
1322 style
|= WS_VISIBLE
;
1323 if( ~attributes
& 2 )
1324 style
|= WS_DISABLED
;
1326 control
= msi_dialog_create_window( dialog
, rec
, szButton
, name
, text
,
1327 style
, group
->parent
->hwnd
);
1329 return ERROR_FUNCTION_FAILED
;
1330 control
->handler
= msi_dialog_radiogroup_handler
;
1332 prop
= MSI_RecordGetString( rec
, 1 );
1334 control
->property
= strdupW( prop
);
1336 return ERROR_SUCCESS
;
1339 static UINT
msi_dialog_radiogroup_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1341 static const WCHAR query
[] = {
1342 'S','E','L','E','C','T',' ','*',' ',
1343 'F','R','O','M',' ','R','a','d','i','o','B','u','t','t','o','n',' ',
1344 'W','H','E','R','E',' ',
1345 '`','P','r','o','p','e','r','t','y','`',' ','=',' ','\'','%','s','\'',0};
1348 msi_control
*control
;
1349 MSIQUERY
*view
= NULL
;
1350 radio_button_group_descr group
;
1351 MSIPACKAGE
*package
= dialog
->package
;
1354 prop
= MSI_RecordGetString( rec
, 9 );
1356 TRACE("%p %p %s\n", dialog
, rec
, debugstr_w( prop
));
1358 /* Create parent group box to hold radio buttons */
1359 control
= msi_dialog_add_control( dialog
, rec
, szButton
, BS_OWNERDRAW
|WS_GROUP
);
1361 return ERROR_FUNCTION_FAILED
;
1363 oldproc
= (WNDPROC
) SetWindowLongPtrW( control
->hwnd
, GWLP_WNDPROC
,
1364 (LONG_PTR
)MSIRadioGroup_WndProc
);
1365 SetPropW(control
->hwnd
, szButtonData
, oldproc
);
1366 SetWindowLongPtrW( control
->hwnd
, GWL_EXSTYLE
, WS_EX_CONTROLPARENT
);
1369 control
->property
= strdupW( prop
);
1371 /* query the Radio Button table for all control in this group */
1372 r
= MSI_OpenQuery( package
->db
, &view
, query
, prop
);
1373 if( r
!= ERROR_SUCCESS
)
1375 ERR("query failed for dialog %s radio group %s\n",
1376 debugstr_w(dialog
->name
), debugstr_w(prop
));
1377 return ERROR_INVALID_PARAMETER
;
1380 group
.dialog
= dialog
;
1381 group
.parent
= control
;
1382 group
.attributes
= MSI_RecordGetInteger( rec
, 8 );
1384 r
= MSI_IterateRecords( view
, 0, msi_dialog_create_radiobutton
, &group
);
1385 msiobj_release( &view
->hdr
);
1390 /******************** Selection Tree ***************************************/
1392 struct msi_selection_tree_info
1400 msi_seltree_sync_item_state( HWND hwnd
, MSIFEATURE
*feature
, HTREEITEM hItem
)
1404 TRACE("Feature %s -> %d %d %d\n", debugstr_w(feature
->Title
),
1405 feature
->Installed
, feature
->Action
, feature
->ActionRequest
);
1407 tvi
.mask
= TVIF_STATE
;
1409 tvi
.state
= INDEXTOSTATEIMAGEMASK( feature
->Action
);
1410 tvi
.stateMask
= TVIS_STATEIMAGEMASK
;
1412 SendMessageW( hwnd
, TVM_SETITEMW
, 0, (LPARAM
) &tvi
);
1416 msi_seltree_popup_menu( HWND hwnd
, INT x
, INT y
)
1421 /* create a menu to display */
1422 hMenu
= CreatePopupMenu();
1424 /* FIXME: load strings from resources */
1425 AppendMenuA( hMenu
, MF_ENABLED
, INSTALLSTATE_LOCAL
, "Install feature locally");
1426 AppendMenuA( hMenu
, MF_GRAYED
, 0x1000, "Install entire feature");
1427 AppendMenuA( hMenu
, MF_ENABLED
, INSTALLSTATE_ADVERTISED
, "Install on demand");
1428 AppendMenuA( hMenu
, MF_ENABLED
, INSTALLSTATE_ABSENT
, "Don't install");
1429 r
= TrackPopupMenu( hMenu
, TPM_LEFTALIGN
| TPM_TOPALIGN
| TPM_RETURNCMD
,
1430 x
, y
, 0, hwnd
, NULL
);
1431 DestroyMenu( hMenu
);
1436 msi_seltree_feature_from_item( HWND hwnd
, HTREEITEM hItem
)
1440 /* get the feature from the item */
1441 memset( &tvi
, 0, sizeof tvi
);
1443 tvi
.mask
= TVIF_PARAM
| TVIF_HANDLE
;
1444 SendMessageW( hwnd
, TVM_GETITEMW
, 0, (LPARAM
) &tvi
);
1446 return (MSIFEATURE
*) tvi
.lParam
;
1450 msi_seltree_menu( HWND hwnd
, HTREEITEM hItem
)
1452 MSIFEATURE
*feature
;
1460 feature
= msi_seltree_feature_from_item( hwnd
, hItem
);
1463 ERR("item %p feature was NULL\n", hItem
);
1467 /* get the item's rectangle to put the menu just below it */
1469 SendMessageW( hwnd
, TVM_GETITEMRECT
, 0, (LPARAM
) &u
.rc
);
1470 MapWindowPoints( hwnd
, NULL
, u
.pt
, 2 );
1472 r
= msi_seltree_popup_menu( hwnd
, u
.rc
.left
, u
.rc
.top
);
1476 case INSTALLSTATE_LOCAL
:
1477 case INSTALLSTATE_ADVERTISED
:
1478 case INSTALLSTATE_ABSENT
:
1479 feature
->ActionRequest
= r
;
1480 feature
->Action
= r
;
1483 FIXME("select feature and all children\n");
1487 msi_seltree_sync_item_state( hwnd
, feature
, hItem
);
1492 static LRESULT WINAPI
1493 MSISelectionTree_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1495 struct msi_selection_tree_info
*info
;
1496 TVHITTESTINFO tvhti
;
1499 TRACE("%p %04x %08x %08lx\n", hWnd
, msg
, wParam
, lParam
);
1501 info
= GetPropW(hWnd
, szButtonData
);
1505 case WM_LBUTTONDOWN
:
1506 tvhti
.pt
.x
= LOWORD( lParam
);
1507 tvhti
.pt
.y
= HIWORD( lParam
);
1510 r
= CallWindowProcW(info
->oldproc
, hWnd
, TVM_HITTEST
, 0, (LPARAM
) &tvhti
);
1511 if (tvhti
.flags
& TVHT_ONITEMSTATEICON
)
1512 return msi_seltree_menu( hWnd
, tvhti
.hItem
);
1516 r
= CallWindowProcW(info
->oldproc
, hWnd
, msg
, wParam
, lParam
);
1522 RemovePropW( hWnd
, szButtonData
);
1529 msi_seltree_add_child_features( MSIPACKAGE
*package
, HWND hwnd
,
1530 LPCWSTR parent
, HTREEITEM hParent
)
1532 MSIFEATURE
*feature
;
1533 TVINSERTSTRUCTW tvis
;
1536 LIST_FOR_EACH_ENTRY( feature
, &package
->features
, MSIFEATURE
, entry
)
1538 if ( lstrcmpW( parent
, feature
->Feature_Parent
) )
1541 if ( !feature
->Title
)
1544 memset( &tvis
, 0, sizeof tvis
);
1545 tvis
.hParent
= hParent
;
1546 tvis
.hInsertAfter
= TVI_SORT
;
1547 tvis
.u
.item
.mask
= TVIF_TEXT
| TVIF_PARAM
;
1548 tvis
.u
.item
.pszText
= feature
->Title
;
1549 tvis
.u
.item
.lParam
= (LPARAM
) feature
;
1551 hitem
= (HTREEITEM
) SendMessageW( hwnd
, TVM_INSERTITEMW
, 0, (LPARAM
) &tvis
);
1555 msi_seltree_sync_item_state( hwnd
, feature
, hitem
);
1556 msi_seltree_add_child_features( package
, hwnd
,
1557 feature
->Feature
, hitem
);
1561 static void msi_seltree_create_imagelist( HWND hwnd
)
1563 const int bm_width
= 32, bm_height
= 16, bm_count
= 3;
1564 const int bm_resource
= 0x1001;
1569 himl
= ImageList_Create( bm_width
, bm_height
, FALSE
, 4, 0 );
1572 ERR("failed to create image list\n");
1576 for (i
=0; i
<bm_count
; i
++)
1578 hbmp
= LoadBitmapW( msi_hInstance
, MAKEINTRESOURCEW(i
+bm_resource
) );
1581 ERR("failed to load bitmap %d\n", i
);
1586 * Add a dummy bitmap at offset zero because the treeview
1587 * can't use it as a state mask (zero means no user state).
1590 ImageList_Add( himl
, hbmp
, NULL
);
1592 ImageList_Add( himl
, hbmp
, NULL
);
1595 SendMessageW( hwnd
, TVM_SETIMAGELIST
, TVSIL_STATE
, (LPARAM
)himl
);
1598 static UINT
msi_dialog_selection_tree( msi_dialog
*dialog
, MSIRECORD
*rec
)
1600 msi_control
*control
;
1602 MSIPACKAGE
*package
= dialog
->package
;
1604 struct msi_selection_tree_info
*info
;
1606 info
= msi_alloc( sizeof *info
);
1608 return ERROR_FUNCTION_FAILED
;
1610 /* create the treeview control */
1611 prop
= MSI_RecordGetString( rec
, 9 );
1612 style
= TVS_HASLINES
| TVS_HASBUTTONS
| TVS_LINESATROOT
;
1613 style
|= WS_GROUP
| WS_VSCROLL
;
1614 control
= msi_dialog_add_control( dialog
, rec
, WC_TREEVIEWW
, style
);
1618 return ERROR_FUNCTION_FAILED
;
1622 info
->dialog
= dialog
;
1623 info
->hwnd
= control
->hwnd
;
1624 info
->oldproc
= (WNDPROC
) SetWindowLongPtrW( control
->hwnd
, GWLP_WNDPROC
,
1625 (LONG_PTR
)MSISelectionTree_WndProc
);
1626 SetPropW( control
->hwnd
, szButtonData
, info
);
1629 msi_seltree_create_imagelist( control
->hwnd
);
1630 msi_seltree_add_child_features( package
, control
->hwnd
, NULL
, NULL
);
1632 return ERROR_SUCCESS
;
1635 struct control_handler msi_dialog_handler
[] =
1637 { szText
, msi_dialog_text_control
},
1638 { szPushButton
, msi_dialog_button_control
},
1639 { szLine
, msi_dialog_line_control
},
1640 { szBitmap
, msi_dialog_bitmap_control
},
1641 { szCheckBox
, msi_dialog_checkbox_control
},
1642 { szScrollableText
, msi_dialog_scrolltext_control
},
1643 { szComboBox
, msi_dialog_combo_control
},
1644 { szEdit
, msi_dialog_edit_control
},
1645 { szMaskedEdit
, msi_dialog_maskedit_control
},
1646 { szPathEdit
, msi_dialog_pathedit_control
},
1647 { szProgressBar
, msi_dialog_progress_bar
},
1648 { szRadioButtonGroup
, msi_dialog_radiogroup_control
},
1649 { szIcon
, msi_dialog_icon_control
},
1650 { szSelectionTree
, msi_dialog_selection_tree
},
1653 #define NUM_CONTROL_TYPES (sizeof msi_dialog_handler/sizeof msi_dialog_handler[0])
1655 static UINT
msi_dialog_create_controls( MSIRECORD
*rec
, LPVOID param
)
1657 msi_dialog
*dialog
= param
;
1658 LPCWSTR control_type
;
1661 /* find and call the function that can create this type of control */
1662 control_type
= MSI_RecordGetString( rec
, 3 );
1663 for( i
=0; i
<NUM_CONTROL_TYPES
; i
++ )
1664 if (!strcmpiW( msi_dialog_handler
[i
].control_type
, control_type
))
1666 if( i
!= NUM_CONTROL_TYPES
)
1667 msi_dialog_handler
[i
].func( dialog
, rec
);
1669 ERR("no handler for element type %s\n", debugstr_w(control_type
));
1671 return ERROR_SUCCESS
;
1674 static UINT
msi_dialog_fill_controls( msi_dialog
*dialog
)
1676 static const WCHAR query
[] = {
1677 'S','E','L','E','C','T',' ','*',' ',
1678 'F','R','O','M',' ','C','o','n','t','r','o','l',' ',
1679 'W','H','E','R','E',' ',
1680 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',0};
1682 MSIQUERY
*view
= NULL
;
1683 MSIPACKAGE
*package
= dialog
->package
;
1685 TRACE("%p %s\n", dialog
, debugstr_w(dialog
->name
) );
1687 /* query the Control table for all the elements of the control */
1688 r
= MSI_OpenQuery( package
->db
, &view
, query
, dialog
->name
);
1689 if( r
!= ERROR_SUCCESS
)
1691 ERR("query failed for dialog %s\n", debugstr_w(dialog
->name
));
1692 return ERROR_INVALID_PARAMETER
;
1695 r
= MSI_IterateRecords( view
, 0, msi_dialog_create_controls
, dialog
);
1696 msiobj_release( &view
->hdr
);
1701 static UINT
msi_dialog_set_control_condition( MSIRECORD
*rec
, LPVOID param
)
1703 static const WCHAR szHide
[] = { 'H','i','d','e',0 };
1704 static const WCHAR szShow
[] = { 'S','h','o','w',0 };
1705 static const WCHAR szDisable
[] = { 'D','i','s','a','b','l','e',0 };
1706 static const WCHAR szEnable
[] = { 'E','n','a','b','l','e',0 };
1707 msi_dialog
*dialog
= param
;
1708 msi_control
*control
;
1709 LPCWSTR name
, action
, condition
;
1712 name
= MSI_RecordGetString( rec
, 2 );
1713 action
= MSI_RecordGetString( rec
, 3 );
1714 condition
= MSI_RecordGetString( rec
, 4 );
1715 r
= MSI_EvaluateConditionW( dialog
->package
, condition
);
1716 control
= msi_dialog_find_control( dialog
, name
);
1717 if( r
== MSICONDITION_TRUE
&& control
)
1719 TRACE("%s control %s\n", debugstr_w(action
), debugstr_w(name
));
1721 /* FIXME: case sensitive? */
1722 if(!lstrcmpW(action
, szHide
))
1723 ShowWindow(control
->hwnd
, SW_HIDE
);
1724 else if(!strcmpW(action
, szShow
))
1725 ShowWindow(control
->hwnd
, SW_SHOW
);
1726 else if(!strcmpW(action
, szDisable
))
1727 EnableWindow(control
->hwnd
, FALSE
);
1728 else if(!strcmpW(action
, szEnable
))
1729 EnableWindow(control
->hwnd
, TRUE
);
1731 FIXME("Unhandled action %s\n", debugstr_w(action
));
1734 return ERROR_SUCCESS
;
1737 static UINT
msi_dialog_evaluate_control_conditions( msi_dialog
*dialog
)
1739 static const WCHAR query
[] = {
1740 'S','E','L','E','C','T',' ','*',' ',
1741 'F','R','O','M',' ',
1742 'C','o','n','t','r','o','l','C','o','n','d','i','t','i','o','n',' ',
1743 'W','H','E','R','E',' ',
1744 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',0
1747 MSIQUERY
*view
= NULL
;
1748 MSIPACKAGE
*package
= dialog
->package
;
1750 TRACE("%p %s\n", dialog
, debugstr_w(dialog
->name
) );
1752 /* query the Control table for all the elements of the control */
1753 r
= MSI_OpenQuery( package
->db
, &view
, query
, dialog
->name
);
1754 if( r
!= ERROR_SUCCESS
)
1756 ERR("query failed for dialog %s\n", debugstr_w(dialog
->name
));
1757 return ERROR_INVALID_PARAMETER
;
1760 r
= MSI_IterateRecords( view
, 0, msi_dialog_set_control_condition
, dialog
);
1761 msiobj_release( &view
->hdr
);
1766 UINT
msi_dialog_reset( msi_dialog
*dialog
)
1768 /* FIXME: should restore the original values of any properties we changed */
1769 return msi_dialog_evaluate_control_conditions( dialog
);
1772 /* figure out the height of 10 point MS Sans Serif */
1773 static INT
msi_dialog_get_sans_serif_height( HWND hwnd
)
1775 static const WCHAR szSansSerif
[] = {
1776 'M','S',' ','S','a','n','s',' ','S','e','r','i','f',0 };
1781 HFONT hFont
, hOldFont
;
1784 hdc
= GetDC( hwnd
);
1787 memset( &lf
, 0, sizeof lf
);
1788 lf
.lfHeight
= MulDiv(10, GetDeviceCaps(hdc
, LOGPIXELSY
), 72);
1789 strcpyW( lf
.lfFaceName
, szSansSerif
);
1790 hFont
= CreateFontIndirectW(&lf
);
1793 hOldFont
= SelectObject( hdc
, hFont
);
1794 r
= GetTextMetricsW( hdc
, &tm
);
1796 height
= tm
.tmHeight
;
1797 SelectObject( hdc
, hOldFont
);
1798 DeleteObject( hFont
);
1800 ReleaseDC( hwnd
, hdc
);
1805 /* fetch the associated record from the Dialog table */
1806 static MSIRECORD
*msi_get_dialog_record( msi_dialog
*dialog
)
1808 static const WCHAR query
[] = {
1809 'S','E','L','E','C','T',' ','*',' ',
1810 'F','R','O','M',' ','D','i','a','l','o','g',' ',
1811 'W','H','E','R','E',' ',
1812 '`','D','i','a','l','o','g','`',' ','=',' ','\'','%','s','\'',0};
1813 MSIPACKAGE
*package
= dialog
->package
;
1814 MSIRECORD
*rec
= NULL
;
1816 TRACE("%p %s\n", dialog
, debugstr_w(dialog
->name
) );
1818 rec
= MSI_QueryGetRecord( package
->db
, query
, dialog
->name
);
1820 ERR("query failed for dialog %s\n", debugstr_w(dialog
->name
));
1825 static void msi_dialog_adjust_dialog_size( msi_dialog
*dialog
, LPSIZE sz
)
1830 /* turn the client size into the window rectangle */
1833 rect
.right
= msi_dialog_scale_unit( dialog
, sz
->cx
);
1834 rect
.bottom
= msi_dialog_scale_unit( dialog
, sz
->cy
);
1835 style
= GetWindowLongPtrW( dialog
->hwnd
, GWL_STYLE
);
1836 AdjustWindowRect( &rect
, style
, FALSE
);
1837 sz
->cx
= rect
.right
- rect
.left
;
1838 sz
->cy
= rect
.bottom
- rect
.top
;
1841 static BOOL
msi_control_set_next( msi_control
*control
, msi_control
*next
)
1843 return SetWindowPos( next
->hwnd
, control
->hwnd
, 0, 0, 0, 0,
1844 SWP_NOMOVE
| SWP_NOOWNERZORDER
| SWP_NOREDRAW
|
1845 SWP_NOREPOSITION
| SWP_NOSENDCHANGING
| SWP_NOSIZE
);
1848 static UINT
msi_dialog_set_tab_order( msi_dialog
*dialog
)
1850 msi_control
*control
, *tab_next
;
1852 LIST_FOR_EACH_ENTRY( control
, &dialog
->controls
, msi_control
, entry
)
1854 tab_next
= msi_dialog_find_control( dialog
, control
->tabnext
);
1857 msi_control_set_next( control
, tab_next
);
1860 return ERROR_SUCCESS
;
1863 static void msi_dialog_set_first_control( msi_dialog
* dialog
, LPCWSTR name
)
1865 msi_control
*control
;
1867 control
= msi_dialog_find_control( dialog
, name
);
1869 dialog
->hWndFocus
= control
->hwnd
;
1871 dialog
->hWndFocus
= NULL
;
1874 static LRESULT
msi_dialog_oncreate( HWND hwnd
, LPCREATESTRUCTW cs
)
1876 static const WCHAR df
[] = {
1877 'D','e','f','a','u','l','t','U','I','F','o','n','t',0 };
1878 static const WCHAR dfv
[] = {
1879 'M','S',' ','S','h','e','l','l',' ','D','l','g',0 };
1880 msi_dialog
*dialog
= (msi_dialog
*) cs
->lpCreateParams
;
1881 MSIRECORD
*rec
= NULL
;
1882 LPWSTR title
= NULL
;
1885 TRACE("%p %p\n", dialog
, dialog
->package
);
1887 dialog
->hwnd
= hwnd
;
1888 SetWindowLongPtrW( hwnd
, GWLP_USERDATA
, (LONG_PTR
) dialog
);
1890 rec
= msi_get_dialog_record( dialog
);
1893 TRACE("No record found for dialog %s\n", debugstr_w(dialog
->name
));
1897 dialog
->scale
= msi_dialog_get_sans_serif_height(dialog
->hwnd
);
1899 size
.cx
= MSI_RecordGetInteger( rec
, 4 );
1900 size
.cy
= MSI_RecordGetInteger( rec
, 5 );
1901 msi_dialog_adjust_dialog_size( dialog
, &size
);
1903 dialog
->attributes
= MSI_RecordGetInteger( rec
, 6 );
1905 dialog
->default_font
= msi_dup_property( dialog
->package
, df
);
1906 if (!dialog
->default_font
)
1908 dialog
->default_font
= strdupW(dfv
);
1909 if (!dialog
->default_font
) return -1;
1912 title
= msi_get_deformatted_field( dialog
->package
, rec
, 7 );
1913 SetWindowTextW( hwnd
, title
);
1916 SetWindowPos( hwnd
, 0, 0, 0, size
.cx
, size
.cy
,
1917 SWP_NOMOVE
| SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_NOREDRAW
);
1920 msi_dialog_build_font_list( dialog
);
1921 msi_dialog_fill_controls( dialog
);
1922 msi_dialog_evaluate_control_conditions( dialog
);
1923 msi_dialog_set_tab_order( dialog
);
1924 msi_dialog_set_first_control( dialog
, MSI_RecordGetString( rec
, 8 ) );
1925 msiobj_release( &rec
->hdr
);
1930 static UINT
msi_dialog_send_event( msi_dialog
*dialog
, LPCWSTR event
, LPCWSTR arg
)
1932 LPWSTR event_fmt
= NULL
, arg_fmt
= NULL
;
1934 TRACE("Sending control event %s %s\n", debugstr_w(event
), debugstr_w(arg
));
1936 deformat_string( dialog
->package
, event
, &event_fmt
);
1937 deformat_string( dialog
->package
, arg
, &arg_fmt
);
1939 dialog
->event_handler( dialog
->package
, event_fmt
, arg_fmt
, dialog
);
1941 msi_free( event_fmt
);
1942 msi_free( arg_fmt
);
1944 return ERROR_SUCCESS
;
1947 static UINT
msi_dialog_set_property( msi_dialog
*dialog
, LPCWSTR event
, LPCWSTR arg
)
1949 static const WCHAR szNullArg
[] = { '{','}',0 };
1950 LPWSTR p
, prop
, arg_fmt
= NULL
;
1953 len
= strlenW(event
);
1954 prop
= msi_alloc( len
*sizeof(WCHAR
));
1955 strcpyW( prop
, &event
[1] );
1956 p
= strchrW( prop
, ']' );
1957 if( p
&& p
[1] == 0 )
1960 if( strcmpW( szNullArg
, arg
) )
1961 deformat_string( dialog
->package
, arg
, &arg_fmt
);
1962 MSI_SetPropertyW( dialog
->package
, prop
, arg_fmt
);
1963 msi_free( arg_fmt
);
1966 ERR("Badly formatted property string - what happens?\n");
1968 return ERROR_SUCCESS
;
1971 static UINT
msi_dialog_control_event( MSIRECORD
*rec
, LPVOID param
)
1973 msi_dialog
*dialog
= param
;
1974 LPCWSTR condition
, event
, arg
;
1977 condition
= MSI_RecordGetString( rec
, 5 );
1978 r
= MSI_EvaluateConditionW( dialog
->package
, condition
);
1979 if( r
== MSICONDITION_TRUE
)
1981 event
= MSI_RecordGetString( rec
, 3 );
1982 arg
= MSI_RecordGetString( rec
, 4 );
1983 if( event
[0] == '[' )
1984 msi_dialog_set_property( dialog
, event
, arg
);
1986 msi_dialog_send_event( dialog
, event
, arg
);
1989 return ERROR_SUCCESS
;
1992 static UINT
msi_dialog_button_handler( msi_dialog
*dialog
,
1993 msi_control
*control
, WPARAM param
)
1995 static const WCHAR query
[] = {
1996 'S','E','L','E','C','T',' ','*',' ',
1997 'F','R','O','M',' ','C','o','n','t','r','o','l','E','v','e','n','t',' ',
1998 'W','H','E','R','E',' ',
1999 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',' ',
2001 '`','C','o','n','t','r','o','l','_','`',' ','=',' ','\'','%','s','\'',' ',
2002 'O','R','D','E','R',' ','B','Y',' ','`','O','r','d','e','r','i','n','g','`',0
2004 MSIQUERY
*view
= NULL
;
2007 if( HIWORD(param
) != BN_CLICKED
)
2008 return ERROR_SUCCESS
;
2010 r
= MSI_OpenQuery( dialog
->package
->db
, &view
, query
,
2011 dialog
->name
, control
->name
);
2012 if( r
!= ERROR_SUCCESS
)
2014 ERR("query failed\n");
2018 r
= MSI_IterateRecords( view
, 0, msi_dialog_control_event
, dialog
);
2019 msiobj_release( &view
->hdr
);
2024 static UINT
msi_dialog_get_checkbox_state( msi_dialog
*dialog
,
2025 msi_control
*control
)
2027 WCHAR state
[2] = { 0 };
2030 MSI_GetPropertyW( dialog
->package
, control
->property
, state
, &sz
);
2031 return state
[0] ? 1 : 0;
2034 static void msi_dialog_set_checkbox_state( msi_dialog
*dialog
,
2035 msi_control
*control
, UINT state
)
2037 static const WCHAR szState
[] = { '1', 0 };
2040 /* if uncheck then the property is set to NULL */
2043 MSI_SetPropertyW( dialog
->package
, control
->property
, NULL
);
2047 /* check for a custom state */
2048 if (control
->value
&& control
->value
[0])
2049 val
= control
->value
;
2053 MSI_SetPropertyW( dialog
->package
, control
->property
, val
);
2056 static void msi_dialog_checkbox_sync_state( msi_dialog
*dialog
,
2057 msi_control
*control
)
2061 state
= msi_dialog_get_checkbox_state( dialog
, control
);
2062 SendMessageW( control
->hwnd
, BM_SETCHECK
,
2063 state
? BST_CHECKED
: BST_UNCHECKED
, 0 );
2066 static UINT
msi_dialog_checkbox_handler( msi_dialog
*dialog
,
2067 msi_control
*control
, WPARAM param
)
2071 if( HIWORD(param
) != BN_CLICKED
)
2072 return ERROR_SUCCESS
;
2074 TRACE("clicked checkbox %s, set %s\n", debugstr_w(control
->name
),
2075 debugstr_w(control
->property
));
2077 state
= msi_dialog_get_checkbox_state( dialog
, control
);
2078 state
= state
? 0 : 1;
2079 msi_dialog_set_checkbox_state( dialog
, control
, state
);
2080 msi_dialog_checkbox_sync_state( dialog
, control
);
2082 return msi_dialog_button_handler( dialog
, control
, param
);
2085 static UINT
msi_dialog_edit_handler( msi_dialog
*dialog
,
2086 msi_control
*control
, WPARAM param
)
2091 if( HIWORD(param
) != EN_CHANGE
)
2092 return ERROR_SUCCESS
;
2094 TRACE("edit %s contents changed, set %s\n", debugstr_w(control
->name
),
2095 debugstr_w(control
->property
));
2098 buf
= msi_alloc( sz
*sizeof(WCHAR
) );
2101 r
= GetWindowTextW( control
->hwnd
, buf
, sz
);
2105 buf
= msi_realloc( buf
, sz
*sizeof(WCHAR
) );
2108 MSI_SetPropertyW( dialog
->package
, control
->property
, buf
);
2112 return ERROR_SUCCESS
;
2115 static UINT
msi_dialog_radiogroup_handler( msi_dialog
*dialog
,
2116 msi_control
*control
, WPARAM param
)
2118 if( HIWORD(param
) != BN_CLICKED
)
2119 return ERROR_SUCCESS
;
2121 TRACE("clicked radio button %s, set %s\n", debugstr_w(control
->name
),
2122 debugstr_w(control
->property
));
2124 MSI_SetPropertyW( dialog
->package
, control
->property
, control
->name
);
2126 return msi_dialog_button_handler( dialog
, control
, param
);
2129 static LRESULT
msi_dialog_oncommand( msi_dialog
*dialog
, WPARAM param
, HWND hwnd
)
2131 msi_control
*control
= NULL
;
2133 TRACE("%p %p %08x\n", dialog
, hwnd
, param
);
2138 control
= msi_dialog_find_control( dialog
, dialog
->control_default
);
2140 case 2: /* escape */
2141 control
= msi_dialog_find_control( dialog
, dialog
->control_cancel
);
2144 control
= msi_dialog_find_control_by_hwnd( dialog
, hwnd
);
2149 if( control
->handler
)
2151 control
->handler( dialog
, control
, param
);
2152 msi_dialog_evaluate_control_conditions( dialog
);
2156 ERR("button click from nowhere %p %d %p\n", dialog
, param
, hwnd
);
2160 static void msi_dialog_setfocus( msi_dialog
*dialog
)
2162 HWND hwnd
= dialog
->hWndFocus
;
2164 hwnd
= GetNextDlgTabItem( dialog
->hwnd
, hwnd
, TRUE
);
2165 hwnd
= GetNextDlgTabItem( dialog
->hwnd
, hwnd
, FALSE
);
2167 dialog
->hWndFocus
= hwnd
;
2170 static LRESULT WINAPI
MSIDialog_WndProc( HWND hwnd
, UINT msg
,
2171 WPARAM wParam
, LPARAM lParam
)
2173 msi_dialog
*dialog
= (LPVOID
) GetWindowLongPtrW( hwnd
, GWLP_USERDATA
);
2175 TRACE("0x%04x\n", msg
);
2180 return msi_dialog_oncreate( hwnd
, (LPCREATESTRUCTW
)lParam
);
2183 return msi_dialog_oncommand( dialog
, wParam
, (HWND
)lParam
);
2186 if( LOWORD(wParam
) == WA_INACTIVE
)
2187 dialog
->hWndFocus
= GetFocus();
2189 msi_dialog_setfocus( dialog
);
2193 msi_dialog_setfocus( dialog
);
2196 /* bounce back to our subclassed static control */
2197 case WM_CTLCOLORSTATIC
:
2198 return SendMessageW( (HWND
) lParam
, WM_CTLCOLORSTATIC
, wParam
, lParam
);
2201 dialog
->hwnd
= NULL
;
2204 return DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
2207 static BOOL CALLBACK
msi_radioground_child_enum( HWND hWnd
, LPARAM lParam
)
2209 EnableWindow( hWnd
, lParam
);
2213 static LRESULT WINAPI
MSIRadioGroup_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
2215 WNDPROC oldproc
= (WNDPROC
) GetPropW(hWnd
, szButtonData
);
2218 TRACE("hWnd %p msg %04x wParam 0x%08x lParam 0x%08lx\n", hWnd
, msg
, wParam
, lParam
);
2220 if (msg
== WM_COMMAND
) /* Forward notifications to dialog */
2221 SendMessageW(GetParent(hWnd
), msg
, wParam
, lParam
);
2223 r
= CallWindowProcW(oldproc
, hWnd
, msg
, wParam
, lParam
);
2225 /* make sure the radio buttons show as disabled if the parent is disabled */
2226 if (msg
== WM_ENABLE
)
2227 EnumChildWindows( hWnd
, msi_radioground_child_enum
, wParam
);
2232 static LRESULT WINAPI
MSIHiddenWindowProc( HWND hwnd
, UINT msg
,
2233 WPARAM wParam
, LPARAM lParam
)
2235 msi_dialog
*dialog
= (msi_dialog
*) lParam
;
2237 TRACE("%d %p\n", msg
, dialog
);
2241 case WM_MSI_DIALOG_CREATE
:
2242 return msi_dialog_run_message_loop( dialog
);
2243 case WM_MSI_DIALOG_DESTROY
:
2244 msi_dialog_destroy( dialog
);
2247 return DefWindowProcW( hwnd
, msg
, wParam
, lParam
);
2250 /* functions that interface to other modules within MSI */
2252 msi_dialog
*msi_dialog_create( MSIPACKAGE
* package
, LPCWSTR szDialogName
,
2253 msi_dialog_event_handler event_handler
)
2255 MSIRECORD
*rec
= NULL
;
2258 TRACE("%p %s\n", package
, debugstr_w(szDialogName
));
2260 /* allocate the structure for the dialog to use */
2261 dialog
= msi_alloc_zero( sizeof *dialog
+ sizeof(WCHAR
)*strlenW(szDialogName
) );
2264 strcpyW( dialog
->name
, szDialogName
);
2265 msiobj_addref( &package
->hdr
);
2266 dialog
->package
= package
;
2267 dialog
->event_handler
= event_handler
;
2268 dialog
->finished
= 0;
2269 list_init( &dialog
->controls
);
2271 /* verify that the dialog exists */
2272 rec
= msi_get_dialog_record( dialog
);
2275 msiobj_release( &package
->hdr
);
2279 dialog
->attributes
= MSI_RecordGetInteger( rec
, 6 );
2280 dialog
->control_default
= strdupW( MSI_RecordGetString( rec
, 9 ) );
2281 dialog
->control_cancel
= strdupW( MSI_RecordGetString( rec
, 10 ) );
2282 msiobj_release( &rec
->hdr
);
2287 static void msi_process_pending_messages( HWND hdlg
)
2291 while( PeekMessageW( &msg
, 0, 0, 0, PM_REMOVE
) )
2293 if( hdlg
&& IsDialogMessageW( hdlg
, &msg
))
2295 TranslateMessage( &msg
);
2296 DispatchMessageW( &msg
);
2300 void msi_dialog_end_dialog( msi_dialog
*dialog
)
2302 TRACE("%p\n", dialog
);
2303 dialog
->finished
= 1;
2304 PostMessageW(dialog
->hwnd
, WM_NULL
, 0, 0);
2307 void msi_dialog_check_messages( HANDLE handle
)
2311 /* in threads other than the UI thread, block */
2312 if( uiThreadId
!= GetCurrentThreadId() )
2315 WaitForSingleObject( handle
, INFINITE
);
2319 /* there's two choices for the UI thread */
2322 msi_process_pending_messages( NULL
);
2328 * block here until somebody creates a new dialog or
2329 * the handle we're waiting on becomes ready
2331 r
= MsgWaitForMultipleObjects( 1, &handle
, 0, INFINITE
, QS_ALLINPUT
);
2332 if( r
== WAIT_OBJECT_0
)
2337 UINT
msi_dialog_run_message_loop( msi_dialog
*dialog
)
2341 if( !(dialog
->attributes
& msidbDialogAttributesVisible
) )
2342 return ERROR_SUCCESS
;
2344 if( uiThreadId
!= GetCurrentThreadId() )
2345 return SendMessageW( hMsiHiddenWindow
, WM_MSI_DIALOG_CREATE
, 0, (LPARAM
) dialog
);
2347 /* create the dialog window, don't show it yet */
2348 hwnd
= CreateWindowW( szMsiDialogClass
, dialog
->name
, WS_OVERLAPPEDWINDOW
,
2349 CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
,
2350 NULL
, NULL
, NULL
, dialog
);
2353 ERR("Failed to create dialog %s\n", debugstr_w( dialog
->name
));
2354 return ERROR_FUNCTION_FAILED
;
2357 ShowWindow( hwnd
, SW_SHOW
);
2358 /* UpdateWindow( hwnd ); - and causes the transparent static controls not to paint */
2360 if( dialog
->attributes
& msidbDialogAttributesModal
)
2362 while( !dialog
->finished
)
2364 MsgWaitForMultipleObjects( 0, NULL
, 0, INFINITE
, QS_ALLEVENTS
);
2365 msi_process_pending_messages( dialog
->hwnd
);
2369 return ERROR_IO_PENDING
;
2371 return ERROR_SUCCESS
;
2374 void msi_dialog_do_preview( msi_dialog
*dialog
)
2377 dialog
->attributes
|= msidbDialogAttributesVisible
;
2378 dialog
->attributes
&= ~msidbDialogAttributesModal
;
2379 msi_dialog_run_message_loop( dialog
);
2382 void msi_dialog_destroy( msi_dialog
*dialog
)
2384 if( uiThreadId
!= GetCurrentThreadId() )
2386 SendMessageW( hMsiHiddenWindow
, WM_MSI_DIALOG_DESTROY
, 0, (LPARAM
) dialog
);
2391 ShowWindow( dialog
->hwnd
, SW_HIDE
);
2394 DestroyWindow( dialog
->hwnd
);
2396 /* destroy the list of controls */
2397 while( !list_empty( &dialog
->controls
) )
2399 msi_control
*t
= LIST_ENTRY( list_head( &dialog
->controls
),
2400 msi_control
, entry
);
2401 list_remove( &t
->entry
);
2402 /* leave dialog->hwnd - destroying parent destroys child windows */
2403 msi_free( t
->property
);
2404 msi_free( t
->value
);
2406 DeleteObject( t
->hBitmap
);
2408 DestroyIcon( t
->hIcon
);
2409 msi_free( t
->tabnext
);
2412 FreeLibrary( t
->hDll
);
2415 /* destroy the list of fonts */
2416 while( dialog
->font_list
)
2418 msi_font
*t
= dialog
->font_list
;
2419 dialog
->font_list
= t
->next
;
2420 DeleteObject( t
->hfont
);
2423 msi_free( dialog
->default_font
);
2425 msi_free( dialog
->control_default
);
2426 msi_free( dialog
->control_cancel
);
2427 msiobj_release( &dialog
->package
->hdr
);
2428 dialog
->package
= NULL
;
2432 BOOL
msi_dialog_register_class( void )
2436 ZeroMemory( &cls
, sizeof cls
);
2437 cls
.lpfnWndProc
= MSIDialog_WndProc
;
2438 cls
.hInstance
= NULL
;
2439 cls
.hIcon
= LoadIconW(0, (LPWSTR
)IDI_APPLICATION
);
2440 cls
.hCursor
= LoadCursorW(0, (LPWSTR
)IDC_ARROW
);
2441 cls
.hbrBackground
= (HBRUSH
)(COLOR_3DFACE
+ 1);
2442 cls
.lpszMenuName
= NULL
;
2443 cls
.lpszClassName
= szMsiDialogClass
;
2445 if( !RegisterClassW( &cls
) )
2448 cls
.lpfnWndProc
= MSIHiddenWindowProc
;
2449 cls
.lpszClassName
= szMsiHiddenWindow
;
2451 if( !RegisterClassW( &cls
) )
2454 uiThreadId
= GetCurrentThreadId();
2456 hMsiHiddenWindow
= CreateWindowW( szMsiHiddenWindow
, NULL
, WS_OVERLAPPED
,
2457 0, 0, 100, 100, NULL
, NULL
, NULL
, NULL
);
2458 if( !hMsiHiddenWindow
)
2464 void msi_dialog_unregister_class( void )
2466 DestroyWindow( hMsiHiddenWindow
);
2467 hMsiHiddenWindow
= NULL
;
2468 UnregisterClassW( szMsiDialogClass
, NULL
);
2469 UnregisterClassW( szMsiHiddenWindow
, NULL
);