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
37 #include "wine/debug.h"
38 #include "wine/unicode.h"
42 WINE_DEFAULT_DEBUG_CHANNEL(msi
);
45 struct msi_control_tag
;
46 typedef struct msi_control_tag msi_control
;
47 typedef UINT (*msi_handler
)( msi_dialog
*, msi_control
*, WPARAM
);
49 struct msi_control_tag
63 typedef struct msi_font_tag
65 struct msi_font_tag
*next
;
73 msi_dialog_event_handler event_handler
;
85 typedef UINT (*msi_dialog_control_func
)( msi_dialog
*dialog
, MSIRECORD
*rec
);
86 struct control_handler
89 msi_dialog_control_func func
;
97 } radio_button_group_descr
;
99 const WCHAR szMsiDialogClass
[] = {
100 'M','s','i','D','i','a','l','o','g','C','l','o','s','e','C','l','a','s','s',0
102 const WCHAR szMsiHiddenWindow
[] = {
103 'M','s','i','H','i','d','d','e','n','W','i','n','d','o','w',0 };
104 const static WCHAR szStatic
[] = { 'S','t','a','t','i','c',0 };
105 const static WCHAR szButton
[] = { 'B','U','T','T','O','N', 0 };
106 const static WCHAR szButtonData
[] = { 'M','S','I','D','A','T','A',0 };
107 static const WCHAR szText
[] = { 'T','e','x','t',0 };
108 static const WCHAR szPushButton
[] = { 'P','u','s','h','B','u','t','t','o','n',0 };
109 static const WCHAR szLine
[] = { 'L','i','n','e',0 };
110 static const WCHAR szBitmap
[] = { 'B','i','t','m','a','p',0 };
111 static const WCHAR szCheckBox
[] = { 'C','h','e','c','k','B','o','x',0 };
112 static const WCHAR szScrollableText
[] = {
113 'S','c','r','o','l','l','a','b','l','e','T','e','x','t',0 };
114 static const WCHAR szComboBox
[] = { 'C','o','m','b','o','B','o','x',0 };
115 static const WCHAR szEdit
[] = { 'E','d','i','t',0 };
116 static const WCHAR szMaskedEdit
[] = { 'M','a','s','k','e','d','E','d','i','t',0 };
117 static const WCHAR szPathEdit
[] = { 'P','a','t','h','E','d','i','t',0 };
118 static const WCHAR szRadioButtonGroup
[] = {
119 'R','a','d','i','o','B','u','t','t','o','n','G','r','o','u','p',0 };
120 static const WCHAR szIcon
[] = { 'I','c','o','n',0 };
122 static UINT
msi_dialog_checkbox_handler( msi_dialog
*, msi_control
*, WPARAM
);
123 static void msi_dialog_checkbox_sync_state( msi_dialog
*, msi_control
* );
124 static UINT
msi_dialog_button_handler( msi_dialog
*, msi_control
*, WPARAM
);
125 static UINT
msi_dialog_edit_handler( msi_dialog
*, msi_control
*, WPARAM
);
126 static UINT
msi_dialog_radiogroup_handler( msi_dialog
*, msi_control
*, WPARAM param
);
127 static UINT
msi_dialog_evaluate_control_conditions( msi_dialog
*dialog
);
128 static LRESULT WINAPI
MSIRadioGroup_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
);
131 /* dialog sequencing */
133 #define WM_MSI_DIALOG_CREATE (WM_USER+0x100)
134 #define WM_MSI_DIALOG_DESTROY (WM_USER+0x101)
136 static DWORD uiThreadId
;
137 static HWND hMsiHiddenWindow
;
139 static INT
msi_dialog_scale_unit( msi_dialog
*dialog
, INT val
)
141 return (dialog
->scale
* val
+ 5) / 10;
144 static msi_control
*msi_dialog_find_control( msi_dialog
*dialog
, LPCWSTR name
)
146 msi_control
*control
;
150 LIST_FOR_EACH_ENTRY( control
, &dialog
->controls
, msi_control
, entry
)
151 if( !strcmpW( control
->name
, name
) ) /* FIXME: case sensitive? */
156 static msi_control
*msi_dialog_find_control_by_hwnd( msi_dialog
*dialog
, HWND hwnd
)
158 msi_control
*control
;
160 LIST_FOR_EACH_ENTRY( control
, &dialog
->controls
, msi_control
, entry
)
161 if( hwnd
== control
->hwnd
)
166 static LPWSTR
msi_get_deformatted_field( MSIPACKAGE
*package
, MSIRECORD
*rec
, int field
)
168 LPCWSTR str
= MSI_RecordGetString( rec
, field
);
172 deformat_string( package
, str
, &ret
);
177 * msi_dialog_get_style
179 * Extract the {\style} string from the front of the text to display and
180 * update the pointer.
182 static LPWSTR
msi_dialog_get_style( LPCWSTR p
, LPCWSTR
*rest
)
193 q
= strchrW( p
, '}' );
199 /* little bit of sanity checking to stop us getting confused with RTF */
201 if( *i
== '}' || *i
== '\\' )
207 ret
= msi_alloc( len
*sizeof(WCHAR
) );
210 memcpy( ret
, p
, len
*sizeof(WCHAR
) );
215 static UINT
msi_dialog_add_font( MSIRECORD
*rec
, LPVOID param
)
217 msi_dialog
*dialog
= param
;
224 /* create a font and add it to the list */
225 name
= MSI_RecordGetString( rec
, 1 );
226 font
= msi_alloc( sizeof *font
+ strlenW( name
)*sizeof (WCHAR
) );
227 strcpyW( font
->name
, name
);
228 font
->next
= dialog
->font_list
;
229 dialog
->font_list
= font
;
231 memset( &lf
, 0, sizeof lf
);
232 face
= MSI_RecordGetString( rec
, 2 );
233 lf
.lfHeight
= MSI_RecordGetInteger( rec
, 3 );
234 style
= MSI_RecordGetInteger( rec
, 5 );
235 if( style
& msidbTextStyleStyleBitsBold
)
236 lf
.lfWeight
= FW_BOLD
;
237 if( style
& msidbTextStyleStyleBitsItalic
)
239 if( style
& msidbTextStyleStyleBitsUnderline
)
240 lf
.lfUnderline
= TRUE
;
241 if( style
& msidbTextStyleStyleBitsStrike
)
242 lf
.lfStrikeOut
= TRUE
;
243 lstrcpynW( lf
.lfFaceName
, face
, LF_FACESIZE
);
245 /* adjust the height */
246 hdc
= GetDC( dialog
->hwnd
);
249 lf
.lfHeight
= -MulDiv(lf
.lfHeight
, GetDeviceCaps(hdc
, LOGPIXELSY
), 72);
250 ReleaseDC( dialog
->hwnd
, hdc
);
253 font
->hfont
= CreateFontIndirectW( &lf
);
255 TRACE("Adding font style %s\n", debugstr_w(font
->name
) );
257 return ERROR_SUCCESS
;
260 static msi_font
*msi_dialog_find_font( msi_dialog
*dialog
, LPCWSTR name
)
264 for( font
= dialog
->font_list
; font
; font
= font
->next
)
265 if( !strcmpW( font
->name
, name
) ) /* FIXME: case sensitive? */
271 static UINT
msi_dialog_set_font( msi_dialog
*dialog
, HWND hwnd
, LPCWSTR name
)
275 font
= msi_dialog_find_font( dialog
, name
);
277 SendMessageW( hwnd
, WM_SETFONT
, (WPARAM
) font
->hfont
, TRUE
);
279 ERR("No font entry for %s\n", debugstr_w(name
));
280 return ERROR_SUCCESS
;
283 static UINT
msi_dialog_build_font_list( msi_dialog
*dialog
)
285 static const WCHAR query
[] = {
286 'S','E','L','E','C','T',' ','*',' ',
287 'F','R','O','M',' ','`','T','e','x','t','S','t','y','l','e','`',' ',0
290 MSIQUERY
*view
= NULL
;
292 TRACE("dialog %p\n", dialog
);
294 r
= MSI_OpenQuery( dialog
->package
->db
, &view
, query
);
295 if( r
!= ERROR_SUCCESS
)
298 r
= MSI_IterateRecords( view
, NULL
, msi_dialog_add_font
, dialog
);
299 msiobj_release( &view
->hdr
);
304 static msi_control
*msi_dialog_create_window( msi_dialog
*dialog
,
305 MSIRECORD
*rec
, LPCWSTR szCls
, LPCWSTR name
, LPCWSTR text
,
306 DWORD style
, HWND parent
)
308 DWORD x
, y
, width
, height
;
309 LPWSTR font
= NULL
, title_font
= NULL
;
310 LPCWSTR title
= NULL
;
311 msi_control
*control
;
315 control
= msi_alloc( sizeof *control
+ strlenW(name
)*sizeof(WCHAR
) );
316 strcpyW( control
->name
, name
);
317 list_add_head( &dialog
->controls
, &control
->entry
);
318 control
->handler
= NULL
;
319 control
->property
= NULL
;
320 control
->value
= NULL
;
321 control
->hBitmap
= NULL
;
322 control
->hIcon
= NULL
;
323 control
->hDll
= NULL
;
324 control
->tabnext
= strdupW( MSI_RecordGetString( rec
, 11) );
326 x
= MSI_RecordGetInteger( rec
, 4 );
327 y
= MSI_RecordGetInteger( rec
, 5 );
328 width
= MSI_RecordGetInteger( rec
, 6 );
329 height
= MSI_RecordGetInteger( rec
, 7 );
331 x
= msi_dialog_scale_unit( dialog
, x
);
332 y
= msi_dialog_scale_unit( dialog
, y
);
333 width
= msi_dialog_scale_unit( dialog
, width
);
334 height
= msi_dialog_scale_unit( dialog
, height
);
338 deformat_string( dialog
->package
, text
, &title_font
);
339 font
= msi_dialog_get_style( title_font
, &title
);
342 control
->hwnd
= CreateWindowW( szCls
, title
, style
,
343 x
, y
, width
, height
, parent
, NULL
, NULL
, NULL
);
345 TRACE("Dialog %s control %s hwnd %p\n",
346 debugstr_w(dialog
->name
), debugstr_w(text
), control
->hwnd
);
348 msi_dialog_set_font( dialog
, control
->hwnd
,
349 font
? font
: dialog
->default_font
);
351 msi_free( title_font
);
357 static MSIRECORD
*msi_get_binary_record( MSIDATABASE
*db
, LPCWSTR name
)
359 const static WCHAR query
[] = {
360 's','e','l','e','c','t',' ','*',' ',
361 'f','r','o','m',' ','B','i','n','a','r','y',' ',
362 'w','h','e','r','e',' ',
363 '`','N','a','m','e','`',' ','=',' ','\'','%','s','\'',0
366 return MSI_QueryGetRecord( db
, query
, name
);
369 static LPWSTR
msi_create_tmp_path(void)
373 static const WCHAR prefix
[] = { 'm','s','i',0 };
376 r
= GetTempPathW( MAX_PATH
, tmp
);
379 len
= lstrlenW( tmp
) + 20;
380 path
= msi_alloc( len
* sizeof (WCHAR
) );
383 r
= GetTempFileNameW( tmp
, prefix
, 0, path
);
394 static HANDLE
msi_load_image( MSIDATABASE
*db
, LPCWSTR name
, UINT type
,
395 UINT cx
, UINT cy
, UINT flags
)
397 MSIRECORD
*rec
= NULL
;
398 HANDLE himage
= NULL
;
402 TRACE("%p %s %u %u %08x\n", db
, debugstr_w(name
), cx
, cy
, flags
);
404 tmp
= msi_create_tmp_path();
408 rec
= msi_get_binary_record( db
, name
);
411 r
= MSI_RecordStreamToFile( rec
, 2, tmp
);
412 if( r
== ERROR_SUCCESS
)
414 himage
= LoadImageW( 0, tmp
, type
, cx
, cy
, flags
);
417 msiobj_release( &rec
->hdr
);
424 static HICON
msi_load_icon( MSIDATABASE
*db
, LPCWSTR text
, UINT attributes
)
426 DWORD cx
= 0, cy
= 0, flags
;
428 flags
= LR_LOADFROMFILE
| LR_DEFAULTSIZE
;
429 if( attributes
& msidbControlAttributesFixedSize
)
431 flags
&= ~LR_DEFAULTSIZE
;
432 if( attributes
& msidbControlAttributesIconSize16
)
437 if( attributes
& msidbControlAttributesIconSize32
)
442 /* msidbControlAttributesIconSize48 handled by above logic */
444 return msi_load_image( db
, text
, IMAGE_ICON
, cx
, cy
, flags
);
448 /* called from the Control Event subscription code */
449 void msi_dialog_handle_event( msi_dialog
* dialog
, LPCWSTR control
,
450 LPCWSTR attribute
, MSIRECORD
*rec
)
455 ctrl
= msi_dialog_find_control( dialog
, control
);
458 if( lstrcmpW(attribute
, szText
) )
460 text
= MSI_RecordGetString( rec
, 1 );
461 SetWindowTextW( ctrl
->hwnd
, text
);
462 msi_dialog_check_messages( NULL
);
465 static void msi_dialog_map_events(msi_dialog
* dialog
, LPCWSTR control
)
467 static WCHAR Query
[] = {
468 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
469 '`','E','v','e','n','t','M','a','p','p','i','n','g','`',' ',
470 'W','H','E','R','E',' ',
471 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',' ',
473 '`','C','o','n','t','r','o','l','_','`',' ','=',' ','\'','%','s','\'',0
476 LPCWSTR event
, attribute
;
478 row
= MSI_QueryGetRecord( dialog
->package
->db
, Query
, dialog
->name
, control
);
482 event
= MSI_RecordGetString( row
, 3 );
483 attribute
= MSI_RecordGetString( row
, 4 );
484 ControlEvent_SubscribeToEvent( dialog
->package
, event
, control
, attribute
);
485 msiobj_release( &row
->hdr
);
488 /* everything except radio buttons */
489 static msi_control
*msi_dialog_add_control( msi_dialog
*dialog
,
490 MSIRECORD
*rec
, LPCWSTR szCls
, DWORD style
)
495 name
= MSI_RecordGetString( rec
, 2 );
496 attributes
= MSI_RecordGetInteger( rec
, 8 );
497 text
= MSI_RecordGetString( rec
, 10 );
498 if( attributes
& msidbControlAttributesVisible
)
500 if( ~attributes
& msidbControlAttributesEnabled
)
501 style
|= WS_DISABLED
;
503 msi_dialog_map_events(dialog
, name
);
505 return msi_dialog_create_window( dialog
, rec
, szCls
, name
, text
,
506 style
, dialog
->hwnd
);
516 * we don't erase our own background,
517 * so we have to make sure that the parent window redraws first
519 static void msi_text_on_settext( HWND hWnd
)
524 hParent
= GetParent( hWnd
);
525 GetWindowRect( hWnd
, &rc
);
526 MapWindowPoints( NULL
, hParent
, (LPPOINT
) &rc
, 2 );
527 InvalidateRect( hParent
, &rc
, TRUE
);
530 static LRESULT WINAPI
531 MSIText_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
533 struct msi_text_info
*info
;
536 TRACE("%p %04x %08x %08lx\n", hWnd
, msg
, wParam
, lParam
);
538 info
= GetPropW(hWnd
, szButtonData
);
540 if( msg
== WM_CTLCOLORSTATIC
&&
541 ( info
->attributes
& msidbControlAttributesTransparent
) )
543 SetBkMode( (HDC
)wParam
, TRANSPARENT
);
544 return (LRESULT
) GetStockObject(NULL_BRUSH
);
547 r
= CallWindowProcW(info
->oldproc
, hWnd
, msg
, wParam
, lParam
);
552 msi_text_on_settext( hWnd
);
556 RemovePropW( hWnd
, szButtonData
);
563 static UINT
msi_dialog_text_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
565 msi_control
*control
;
566 struct msi_text_info
*info
;
568 TRACE("%p %p\n", dialog
, rec
);
570 control
= msi_dialog_add_control( dialog
, rec
, szStatic
, SS_LEFT
| WS_GROUP
);
572 return ERROR_FUNCTION_FAILED
;
574 info
= msi_alloc( sizeof *info
);
576 return ERROR_SUCCESS
;
578 info
->attributes
= MSI_RecordGetInteger( rec
, 8 );
579 if( info
->attributes
& msidbControlAttributesTransparent
)
580 SetWindowLongPtrW( control
->hwnd
, GWL_EXSTYLE
, WS_EX_TRANSPARENT
);
582 info
->oldproc
= (WNDPROC
) SetWindowLongPtrW( control
->hwnd
, GWLP_WNDPROC
,
583 (LONG_PTR
)MSIText_WndProc
);
584 SetPropW( control
->hwnd
, szButtonData
, info
);
586 return ERROR_SUCCESS
;
589 static UINT
msi_dialog_button_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
591 msi_control
*control
;
592 UINT attributes
, style
;
595 TRACE("%p %p\n", dialog
, rec
);
598 attributes
= MSI_RecordGetInteger( rec
, 8 );
599 if( attributes
& msidbControlAttributesIcon
)
602 control
= msi_dialog_add_control( dialog
, rec
, szButton
, style
);
604 return ERROR_FUNCTION_FAILED
;
606 control
->handler
= msi_dialog_button_handler
;
609 text
= msi_get_deformatted_field( dialog
->package
, rec
, 10 );
610 control
->hIcon
= msi_load_icon( dialog
->package
->db
, text
, attributes
);
611 if( attributes
& msidbControlAttributesIcon
)
612 SendMessageW( control
->hwnd
, BM_SETIMAGE
, IMAGE_ICON
, (LPARAM
) control
->hIcon
);
615 return ERROR_SUCCESS
;
618 static LPWSTR
msi_get_checkbox_value( msi_dialog
*dialog
, LPCWSTR prop
)
620 const static WCHAR query
[] = {
621 'S','E','L','E','C','T',' ','*',' ',
622 'F','R','O','M',' ','`','C','h','e','c','k','B','o','x',' ','`',
623 'W','H','E','R','E',' ',
624 '`','P','r','o','p','e','r','t','y','`',' ','=',' ',
627 MSIRECORD
*rec
= NULL
;
631 /* find if there is a value associated with the checkbox */
632 rec
= MSI_QueryGetRecord( dialog
->package
->db
, query
, prop
);
636 val
= MSI_RecordGetString( rec
, 2 );
639 deformat_string( dialog
->package
, val
, &ret
);
646 msiobj_release( &rec
->hdr
);
650 ret
= msi_dup_property( dialog
->package
, prop
);
660 static UINT
msi_dialog_checkbox_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
662 msi_control
*control
;
665 TRACE("%p %p\n", dialog
, rec
);
667 control
= msi_dialog_add_control( dialog
, rec
, szButton
,
668 BS_CHECKBOX
| BS_MULTILINE
| WS_TABSTOP
);
669 control
->handler
= msi_dialog_checkbox_handler
;
670 prop
= MSI_RecordGetString( rec
, 9 );
673 control
->property
= strdupW( prop
);
674 control
->value
= msi_get_checkbox_value( dialog
, prop
);
675 TRACE("control %s value %s\n", debugstr_w(control
->property
),
676 debugstr_w(control
->value
));
678 msi_dialog_checkbox_sync_state( dialog
, control
);
680 return ERROR_SUCCESS
;
683 static UINT
msi_dialog_line_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
685 TRACE("%p %p\n", dialog
, rec
);
687 msi_dialog_add_control( dialog
, rec
, szStatic
, SS_ETCHEDHORZ
| SS_SUNKEN
);
688 return ERROR_SUCCESS
;
691 struct msi_streamin_info
698 static DWORD CALLBACK
699 msi_richedit_stream_in( DWORD_PTR arg
, LPBYTE buffer
, LONG count
, LONG
*pcb
)
701 struct msi_streamin_info
*info
= (struct msi_streamin_info
*) arg
;
703 if( (count
+ info
->offset
) > info
->length
)
704 count
= info
->length
- info
->offset
;
705 memcpy( buffer
, &info
->string
[ info
->offset
], count
);
707 info
->offset
+= count
;
709 TRACE("%ld/%ld\n", info
->offset
, info
->length
);
714 static UINT
msi_dialog_scrolltext_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
716 const static WCHAR szRichEdit20W
[] = {
717 'R','i','c','h','E','d','i','t','2','0','W',0
719 struct msi_streamin_info info
;
720 msi_control
*control
;
726 hRichedit
= LoadLibraryA("riched20");
728 style
= WS_BORDER
| ES_MULTILINE
| WS_VSCROLL
|
729 ES_READONLY
| ES_AUTOVSCROLL
| WS_TABSTOP
;
730 control
= msi_dialog_add_control( dialog
, rec
, szRichEdit20W
, style
);
732 return ERROR_FUNCTION_FAILED
;
734 control
->hDll
= hRichedit
;
736 text
= MSI_RecordGetString( rec
, 10 );
737 info
.string
= strdupWtoA( text
);
739 info
.length
= lstrlenA( info
.string
) + 1;
741 es
.dwCookie
= (DWORD_PTR
) &info
;
743 es
.pfnCallback
= msi_richedit_stream_in
;
745 SendMessageW( control
->hwnd
, EM_STREAMIN
, SF_RTF
, (LPARAM
) &es
);
747 msi_free( info
.string
);
749 return ERROR_SUCCESS
;
752 static UINT
msi_dialog_bitmap_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
754 UINT cx
, cy
, flags
, style
, attributes
;
755 msi_control
*control
;
758 flags
= LR_LOADFROMFILE
;
759 style
= SS_BITMAP
| SS_LEFT
| WS_GROUP
;
761 attributes
= MSI_RecordGetInteger( rec
, 8 );
762 if( attributes
& msidbControlAttributesFixedSize
)
764 flags
|= LR_DEFAULTSIZE
;
765 style
|= SS_CENTERIMAGE
;
768 control
= msi_dialog_add_control( dialog
, rec
, szStatic
, style
);
769 cx
= MSI_RecordGetInteger( rec
, 6 );
770 cy
= MSI_RecordGetInteger( rec
, 7 );
771 cx
= msi_dialog_scale_unit( dialog
, cx
);
772 cy
= msi_dialog_scale_unit( dialog
, cy
);
774 text
= msi_get_deformatted_field( dialog
->package
, rec
, 10 );
775 control
->hBitmap
= msi_load_image( dialog
->package
->db
, text
,
776 IMAGE_BITMAP
, cx
, cy
, flags
);
777 if( control
->hBitmap
)
778 SendMessageW( control
->hwnd
, STM_SETIMAGE
,
779 IMAGE_BITMAP
, (LPARAM
) control
->hBitmap
);
781 ERR("Failed to load bitmap %s\n", debugstr_w(text
));
785 return ERROR_SUCCESS
;
788 static UINT
msi_dialog_icon_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
790 msi_control
*control
;
796 control
= msi_dialog_add_control( dialog
, rec
, szStatic
,
797 SS_ICON
| SS_CENTERIMAGE
| WS_GROUP
);
799 attributes
= MSI_RecordGetInteger( rec
, 8 );
800 text
= msi_get_deformatted_field( dialog
->package
, rec
, 10 );
801 control
->hIcon
= msi_load_icon( dialog
->package
->db
, text
, attributes
);
803 SendMessageW( control
->hwnd
, STM_SETICON
, (WPARAM
) control
->hIcon
, 0 );
805 ERR("Failed to load bitmap %s\n", debugstr_w(text
));
807 return ERROR_SUCCESS
;
810 static UINT
msi_dialog_combo_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
812 static const WCHAR szCombo
[] = { 'C','O','M','B','O','B','O','X',0 };
814 msi_dialog_add_control( dialog
, rec
, szCombo
,
815 SS_BITMAP
| SS_LEFT
| SS_CENTERIMAGE
);
816 return ERROR_SUCCESS
;
819 static UINT
msi_dialog_edit_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
821 msi_control
*control
;
825 control
= msi_dialog_add_control( dialog
, rec
, szEdit
,
826 WS_BORDER
| WS_TABSTOP
);
827 control
->handler
= msi_dialog_edit_handler
;
828 prop
= MSI_RecordGetString( rec
, 9 );
830 control
->property
= strdupW( prop
);
831 val
= msi_dup_property( dialog
->package
, control
->property
);
832 SetWindowTextW( control
->hwnd
, val
);
834 return ERROR_SUCCESS
;
837 /******************** Masked Edit ********************************************/
839 #define MASK_MAX_GROUPS 10
841 struct msi_mask_group
849 struct msi_maskedit_info
857 struct msi_mask_group group
[MASK_MAX_GROUPS
];
860 static void msi_mask_control_change( struct msi_maskedit_info
*info
)
865 val
= msi_alloc( (info
->num_chars
+1)*sizeof(WCHAR
) );
866 for( i
=0, n
=0; i
<info
->num_groups
; i
++ )
868 if( (info
->group
[i
].len
+ n
) > info
->num_chars
)
870 ERR("can't fit control %d text into template\n",i
);
873 r
= GetWindowTextW( info
->group
[i
].hwnd
, &val
[n
], info
->group
[i
].len
+1 );
874 if( r
!= info
->group
[i
].len
)
879 TRACE("%d/%d controls were good\n", i
, info
->num_groups
);
881 if( i
== info
->num_groups
)
883 TRACE("Set property %s to %s\n",
884 debugstr_w(info
->prop
), debugstr_w(val
) );
885 CharUpperBuffW( val
, info
->num_chars
);
886 MSI_SetPropertyW( info
->dialog
->package
, info
->prop
, val
);
887 msi_dialog_evaluate_control_conditions( info
->dialog
);
892 /* now move to the next control if necessary */
893 static VOID
msi_mask_next_control( struct msi_maskedit_info
*info
, HWND hWnd
)
898 for( i
=0; i
<info
->num_groups
; i
++ )
899 if( info
->group
[i
].hwnd
== hWnd
)
902 /* don't move from the last control */
903 if( i
>= (info
->num_groups
-1) )
906 len
= SendMessageW( hWnd
, WM_GETTEXTLENGTH
, 0, 0 );
907 if( len
< info
->group
[i
].len
)
910 hWndNext
= GetNextDlgTabItem( GetParent( hWnd
), hWnd
, FALSE
);
911 SetFocus( hWndNext
);
914 static LRESULT WINAPI
915 MSIMaskedEdit_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
917 struct msi_maskedit_info
*info
;
920 TRACE("%p %04x %08x %08lx\n", hWnd
, msg
, wParam
, lParam
);
922 info
= GetPropW(hWnd
, szButtonData
);
924 r
= CallWindowProcW(info
->oldproc
, hWnd
, msg
, wParam
, lParam
);
929 if (HIWORD(wParam
) == EN_CHANGE
)
931 msi_mask_control_change( info
);
932 msi_mask_next_control( info
, (HWND
) lParam
);
936 msi_free( info
->prop
);
938 RemovePropW( hWnd
, szButtonData
);
945 /* fish the various bits of the property out and put them in the control */
947 msi_maskedit_set_text( struct msi_maskedit_info
*info
, LPCWSTR text
)
953 for( i
= 0; i
< info
->num_groups
; i
++ )
955 if( info
->group
[i
].len
< lstrlenW( p
) )
957 LPWSTR chunk
= strdupW( p
);
958 chunk
[ info
->group
[i
].len
] = 0;
959 SetWindowTextW( info
->group
[i
].hwnd
, chunk
);
964 SetWindowTextW( info
->group
[i
].hwnd
, p
);
967 p
+= info
->group
[i
].len
;
971 static struct msi_maskedit_info
* msi_dialog_parse_groups( LPCWSTR mask
)
973 struct msi_maskedit_info
* info
= NULL
;
974 int i
= 0, n
= 0, total
= 0;
977 TRACE("masked control, template %s\n", debugstr_w(mask
));
982 p
= strchrW(mask
, '<');
986 info
= msi_alloc_zero( sizeof *info
);
991 for( i
=0; i
<MASK_MAX_GROUPS
; i
++ )
999 /* stop at the end of the string */
1000 if( p
[0] == 0 || p
[0] == '>' )
1003 /* count the number of the same identifier */
1004 for( n
=0; p
[n
] == p
[0]; n
++ )
1006 info
->group
[i
].ofs
= total
;
1007 info
->group
[i
].type
= p
[0];
1011 total
++; /* an extra not part of the group */
1013 info
->group
[i
].len
= n
;
1018 TRACE("%d characters in %d groups\n", total
, i
);
1019 if( i
== MASK_MAX_GROUPS
)
1020 ERR("too many groups in PIDTemplate %s\n", debugstr_w(mask
));
1022 info
->num_chars
= total
;
1023 info
->num_groups
= i
;
1029 msi_maskedit_create_children( struct msi_maskedit_info
*info
, LPCWSTR font
)
1031 DWORD width
, height
, style
, wx
, ww
;
1036 style
= WS_CHILD
| WS_BORDER
| WS_VISIBLE
| WS_TABSTOP
;
1038 GetClientRect( info
->hwnd
, &rect
);
1040 width
= rect
.right
- rect
.left
;
1041 height
= rect
.bottom
- rect
.top
;
1043 for( i
= 0; i
< info
->num_groups
; i
++ )
1045 wx
= (info
->group
[i
].ofs
* width
) / info
->num_chars
;
1046 ww
= (info
->group
[i
].len
* width
) / info
->num_chars
;
1048 hwnd
= CreateWindowW( szEdit
, NULL
, style
, wx
, 0, ww
, height
,
1049 info
->hwnd
, NULL
, NULL
, NULL
);
1052 ERR("failed to create mask edit sub window\n");
1056 SendMessageW( hwnd
, EM_LIMITTEXT
, info
->group
[i
].len
, 0 );
1058 msi_dialog_set_font( info
->dialog
, hwnd
,
1059 font
?font
:info
->dialog
->default_font
);
1060 info
->group
[i
].hwnd
= hwnd
;
1064 /* office 2003 uses "73931<````=````=````=````=`````>@@@@@" */
1065 static UINT
msi_dialog_maskedit_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1067 LPWSTR font_mask
, val
= NULL
, font
;
1068 struct msi_maskedit_info
*info
= NULL
;
1069 UINT ret
= ERROR_SUCCESS
;
1070 msi_control
*control
;
1075 font_mask
= msi_get_deformatted_field( dialog
->package
, rec
, 10 );
1076 font
= msi_dialog_get_style( font_mask
, &mask
);
1079 ERR("mask template is empty\n");
1083 info
= msi_dialog_parse_groups( mask
);
1086 ERR("template %s is invalid\n", debugstr_w(mask
));
1090 info
->dialog
= dialog
;
1092 control
= msi_dialog_add_control( dialog
, rec
, szStatic
,
1093 SS_OWNERDRAW
| WS_GROUP
| WS_VISIBLE
);
1096 ERR("Failed to create maskedit container\n");
1097 ret
= ERROR_FUNCTION_FAILED
;
1100 SetWindowLongPtrW( control
->hwnd
, GWL_EXSTYLE
, WS_EX_CONTROLPARENT
);
1102 info
->hwnd
= control
->hwnd
;
1104 /* subclass the static control */
1105 info
->oldproc
= (WNDPROC
) SetWindowLongPtrW( info
->hwnd
, GWLP_WNDPROC
,
1106 (LONG_PTR
)MSIMaskedEdit_WndProc
);
1107 SetPropW( control
->hwnd
, szButtonData
, info
);
1109 prop
= MSI_RecordGetString( rec
, 9 );
1111 info
->prop
= strdupW( prop
);
1113 msi_maskedit_create_children( info
, font
);
1117 val
= msi_dup_property( dialog
->package
, prop
);
1120 msi_maskedit_set_text( info
, val
);
1126 if( ret
!= ERROR_SUCCESS
)
1128 msi_free( font_mask
);
1133 /******************** Path Edit ********************************************/
1135 static UINT
msi_dialog_pathedit_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1137 FIXME("not implemented properly\n");
1138 return msi_dialog_edit_control( dialog
, rec
);
1141 /* radio buttons are a bit different from normal controls */
1142 static UINT
msi_dialog_create_radiobutton( MSIRECORD
*rec
, LPVOID param
)
1144 radio_button_group_descr
*group
= (radio_button_group_descr
*)param
;
1145 msi_dialog
*dialog
= group
->dialog
;
1146 msi_control
*control
;
1147 LPCWSTR prop
, text
, name
;
1148 DWORD style
, attributes
= group
->attributes
;
1150 style
= WS_CHILD
| BS_AUTORADIOBUTTON
| BS_MULTILINE
| WS_TABSTOP
;
1151 name
= MSI_RecordGetString( rec
, 3 );
1152 text
= MSI_RecordGetString( rec
, 8 );
1153 if( attributes
& 1 )
1154 style
|= WS_VISIBLE
;
1155 if( ~attributes
& 2 )
1156 style
|= WS_DISABLED
;
1158 control
= msi_dialog_create_window( dialog
, rec
, szButton
, name
, text
,
1159 style
, group
->parent
->hwnd
);
1161 return ERROR_FUNCTION_FAILED
;
1162 control
->handler
= msi_dialog_radiogroup_handler
;
1164 prop
= MSI_RecordGetString( rec
, 1 );
1166 control
->property
= strdupW( prop
);
1168 return ERROR_SUCCESS
;
1171 static UINT
msi_dialog_radiogroup_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1173 static const WCHAR query
[] = {
1174 'S','E','L','E','C','T',' ','*',' ',
1175 'F','R','O','M',' ','R','a','d','i','o','B','u','t','t','o','n',' ',
1176 'W','H','E','R','E',' ',
1177 '`','P','r','o','p','e','r','t','y','`',' ','=',' ','\'','%','s','\'',0};
1180 msi_control
*control
;
1181 MSIQUERY
*view
= NULL
;
1182 radio_button_group_descr group
;
1183 MSIPACKAGE
*package
= dialog
->package
;
1186 prop
= MSI_RecordGetString( rec
, 9 );
1188 TRACE("%p %p %s\n", dialog
, rec
, debugstr_w( prop
));
1190 /* Create parent group box to hold radio buttons */
1191 control
= msi_dialog_add_control( dialog
, rec
, szButton
, BS_OWNERDRAW
|WS_GROUP
);
1193 return ERROR_FUNCTION_FAILED
;
1195 oldproc
= (WNDPROC
) SetWindowLongPtrW( control
->hwnd
, GWLP_WNDPROC
,
1196 (LONG_PTR
)MSIRadioGroup_WndProc
);
1197 SetPropW(control
->hwnd
, szButtonData
, oldproc
);
1198 SetWindowLongPtrW( control
->hwnd
, GWL_EXSTYLE
, WS_EX_CONTROLPARENT
);
1201 control
->property
= strdupW( prop
);
1203 /* query the Radio Button table for all control in this group */
1204 r
= MSI_OpenQuery( package
->db
, &view
, query
, prop
);
1205 if( r
!= ERROR_SUCCESS
)
1207 ERR("query failed for dialog %s radio group %s\n",
1208 debugstr_w(dialog
->name
), debugstr_w(prop
));
1209 return ERROR_INVALID_PARAMETER
;
1212 group
.dialog
= dialog
;
1213 group
.parent
= control
;
1214 group
.attributes
= MSI_RecordGetInteger( rec
, 8 );
1216 r
= MSI_IterateRecords( view
, 0, msi_dialog_create_radiobutton
, &group
);
1217 msiobj_release( &view
->hdr
);
1222 struct control_handler msi_dialog_handler
[] =
1224 { szText
, msi_dialog_text_control
},
1225 { szPushButton
, msi_dialog_button_control
},
1226 { szLine
, msi_dialog_line_control
},
1227 { szBitmap
, msi_dialog_bitmap_control
},
1228 { szCheckBox
, msi_dialog_checkbox_control
},
1229 { szScrollableText
, msi_dialog_scrolltext_control
},
1230 { szComboBox
, msi_dialog_combo_control
},
1231 { szEdit
, msi_dialog_edit_control
},
1232 { szMaskedEdit
, msi_dialog_maskedit_control
},
1233 { szPathEdit
, msi_dialog_pathedit_control
},
1234 { szRadioButtonGroup
, msi_dialog_radiogroup_control
},
1235 { szIcon
, msi_dialog_icon_control
},
1238 #define NUM_CONTROL_TYPES (sizeof msi_dialog_handler/sizeof msi_dialog_handler[0])
1240 static UINT
msi_dialog_create_controls( MSIRECORD
*rec
, LPVOID param
)
1242 msi_dialog
*dialog
= param
;
1243 LPCWSTR control_type
;
1246 /* find and call the function that can create this type of control */
1247 control_type
= MSI_RecordGetString( rec
, 3 );
1248 for( i
=0; i
<NUM_CONTROL_TYPES
; i
++ )
1249 if (!strcmpiW( msi_dialog_handler
[i
].control_type
, control_type
))
1251 if( i
!= NUM_CONTROL_TYPES
)
1252 msi_dialog_handler
[i
].func( dialog
, rec
);
1254 ERR("no handler for element type %s\n", debugstr_w(control_type
));
1256 return ERROR_SUCCESS
;
1259 static UINT
msi_dialog_fill_controls( msi_dialog
*dialog
)
1261 static const WCHAR query
[] = {
1262 'S','E','L','E','C','T',' ','*',' ',
1263 'F','R','O','M',' ','C','o','n','t','r','o','l',' ',
1264 'W','H','E','R','E',' ',
1265 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',0};
1267 MSIQUERY
*view
= NULL
;
1268 MSIPACKAGE
*package
= dialog
->package
;
1270 TRACE("%p %s\n", dialog
, debugstr_w(dialog
->name
) );
1272 /* query the Control table for all the elements of the control */
1273 r
= MSI_OpenQuery( package
->db
, &view
, query
, dialog
->name
);
1274 if( r
!= ERROR_SUCCESS
)
1276 ERR("query failed for dialog %s\n", debugstr_w(dialog
->name
));
1277 return ERROR_INVALID_PARAMETER
;
1280 r
= MSI_IterateRecords( view
, 0, msi_dialog_create_controls
, dialog
);
1281 msiobj_release( &view
->hdr
);
1286 static UINT
msi_dialog_set_control_condition( MSIRECORD
*rec
, LPVOID param
)
1288 static const WCHAR szHide
[] = { 'H','i','d','e',0 };
1289 static const WCHAR szShow
[] = { 'S','h','o','w',0 };
1290 static const WCHAR szDisable
[] = { 'D','i','s','a','b','l','e',0 };
1291 static const WCHAR szEnable
[] = { 'E','n','a','b','l','e',0 };
1292 msi_dialog
*dialog
= param
;
1293 msi_control
*control
;
1294 LPCWSTR name
, action
, condition
;
1297 name
= MSI_RecordGetString( rec
, 2 );
1298 action
= MSI_RecordGetString( rec
, 3 );
1299 condition
= MSI_RecordGetString( rec
, 4 );
1300 r
= MSI_EvaluateConditionW( dialog
->package
, condition
);
1301 control
= msi_dialog_find_control( dialog
, name
);
1304 TRACE("%s control %s\n", debugstr_w(action
), debugstr_w(name
));
1306 /* FIXME: case sensitive? */
1307 if(!lstrcmpW(action
, szHide
))
1308 ShowWindow(control
->hwnd
, SW_HIDE
);
1309 else if(!strcmpW(action
, szShow
))
1310 ShowWindow(control
->hwnd
, SW_SHOW
);
1311 else if(!strcmpW(action
, szDisable
))
1312 EnableWindow(control
->hwnd
, FALSE
);
1313 else if(!strcmpW(action
, szEnable
))
1314 EnableWindow(control
->hwnd
, TRUE
);
1316 FIXME("Unhandled action %s\n", debugstr_w(action
));
1319 return ERROR_SUCCESS
;
1322 static UINT
msi_dialog_evaluate_control_conditions( msi_dialog
*dialog
)
1324 static const WCHAR query
[] = {
1325 'S','E','L','E','C','T',' ','*',' ',
1326 'F','R','O','M',' ',
1327 'C','o','n','t','r','o','l','C','o','n','d','i','t','i','o','n',' ',
1328 'W','H','E','R','E',' ',
1329 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',0
1332 MSIQUERY
*view
= NULL
;
1333 MSIPACKAGE
*package
= dialog
->package
;
1335 TRACE("%p %s\n", dialog
, debugstr_w(dialog
->name
) );
1337 /* query the Control table for all the elements of the control */
1338 r
= MSI_OpenQuery( package
->db
, &view
, query
, dialog
->name
);
1339 if( r
!= ERROR_SUCCESS
)
1341 ERR("query failed for dialog %s\n", debugstr_w(dialog
->name
));
1342 return ERROR_INVALID_PARAMETER
;
1345 r
= MSI_IterateRecords( view
, 0, msi_dialog_set_control_condition
, dialog
);
1346 msiobj_release( &view
->hdr
);
1351 /* figure out the height of 10 point MS Sans Serif */
1352 static INT
msi_dialog_get_sans_serif_height( HWND hwnd
)
1354 static const WCHAR szSansSerif
[] = {
1355 'M','S',' ','S','a','n','s',' ','S','e','r','i','f',0 };
1360 HFONT hFont
, hOldFont
;
1363 hdc
= GetDC( hwnd
);
1366 memset( &lf
, 0, sizeof lf
);
1367 lf
.lfHeight
= MulDiv(10, GetDeviceCaps(hdc
, LOGPIXELSY
), 72);
1368 strcpyW( lf
.lfFaceName
, szSansSerif
);
1369 hFont
= CreateFontIndirectW(&lf
);
1372 hOldFont
= SelectObject( hdc
, hFont
);
1373 r
= GetTextMetricsW( hdc
, &tm
);
1375 height
= tm
.tmHeight
;
1376 SelectObject( hdc
, hOldFont
);
1377 DeleteObject( hFont
);
1379 ReleaseDC( hwnd
, hdc
);
1384 /* fetch the associated record from the Dialog table */
1385 static MSIRECORD
*msi_get_dialog_record( msi_dialog
*dialog
)
1387 static const WCHAR query
[] = {
1388 'S','E','L','E','C','T',' ','*',' ',
1389 'F','R','O','M',' ','D','i','a','l','o','g',' ',
1390 'W','H','E','R','E',' ',
1391 '`','D','i','a','l','o','g','`',' ','=',' ','\'','%','s','\'',0};
1392 MSIPACKAGE
*package
= dialog
->package
;
1393 MSIRECORD
*rec
= NULL
;
1395 TRACE("%p %s\n", dialog
, debugstr_w(dialog
->name
) );
1397 rec
= MSI_QueryGetRecord( package
->db
, query
, dialog
->name
);
1399 ERR("query failed for dialog %s\n", debugstr_w(dialog
->name
));
1404 static void msi_dialog_adjust_dialog_size( msi_dialog
*dialog
, LPSIZE sz
)
1409 /* turn the client size into the window rectangle */
1412 rect
.right
= msi_dialog_scale_unit( dialog
, sz
->cx
);
1413 rect
.bottom
= msi_dialog_scale_unit( dialog
, sz
->cy
);
1414 style
= GetWindowLongPtrW( dialog
->hwnd
, GWL_STYLE
);
1415 AdjustWindowRect( &rect
, style
, FALSE
);
1416 sz
->cx
= rect
.right
- rect
.left
;
1417 sz
->cy
= rect
.bottom
- rect
.top
;
1420 static BOOL
msi_control_set_next( msi_control
*control
, msi_control
*next
)
1422 return SetWindowPos( next
->hwnd
, control
->hwnd
, 0, 0, 0, 0,
1423 SWP_NOMOVE
| SWP_NOOWNERZORDER
| SWP_NOREDRAW
|
1424 SWP_NOREPOSITION
| SWP_NOSENDCHANGING
| SWP_NOSIZE
);
1427 static UINT
msi_dialog_set_tab_order( msi_dialog
*dialog
)
1429 msi_control
*control
, *tab_next
;
1431 LIST_FOR_EACH_ENTRY( control
, &dialog
->controls
, msi_control
, entry
)
1433 tab_next
= msi_dialog_find_control( dialog
, control
->tabnext
);
1436 msi_control_set_next( control
, tab_next
);
1439 return ERROR_SUCCESS
;
1442 static void msi_dialog_set_first_control( msi_dialog
* dialog
, LPCWSTR name
)
1444 msi_control
*control
;
1446 control
= msi_dialog_find_control( dialog
, name
);
1448 dialog
->hWndFocus
= control
->hwnd
;
1450 dialog
->hWndFocus
= NULL
;
1453 static LRESULT
msi_dialog_oncreate( HWND hwnd
, LPCREATESTRUCTW cs
)
1455 static const WCHAR df
[] = {
1456 'D','e','f','a','u','l','t','U','I','F','o','n','t',0 };
1457 msi_dialog
*dialog
= (msi_dialog
*) cs
->lpCreateParams
;
1458 MSIRECORD
*rec
= NULL
;
1459 LPWSTR title
= NULL
;
1462 TRACE("%p %p\n", dialog
, dialog
->package
);
1464 dialog
->hwnd
= hwnd
;
1465 SetWindowLongPtrW( hwnd
, GWLP_USERDATA
, (LONG_PTR
) dialog
);
1467 rec
= msi_get_dialog_record( dialog
);
1470 TRACE("No record found for dialog %s\n", debugstr_w(dialog
->name
));
1474 dialog
->scale
= msi_dialog_get_sans_serif_height(dialog
->hwnd
);
1476 size
.cx
= MSI_RecordGetInteger( rec
, 4 );
1477 size
.cy
= MSI_RecordGetInteger( rec
, 5 );
1478 msi_dialog_adjust_dialog_size( dialog
, &size
);
1480 dialog
->attributes
= MSI_RecordGetInteger( rec
, 6 );
1482 dialog
->default_font
= msi_dup_property( dialog
->package
, df
);
1484 title
= msi_get_deformatted_field( dialog
->package
, rec
, 7 );
1485 SetWindowTextW( hwnd
, title
);
1488 SetWindowPos( hwnd
, 0, 0, 0, size
.cx
, size
.cy
,
1489 SWP_NOMOVE
| SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_NOREDRAW
);
1492 msi_dialog_build_font_list( dialog
);
1493 msi_dialog_fill_controls( dialog
);
1494 msi_dialog_evaluate_control_conditions( dialog
);
1495 msi_dialog_set_tab_order( dialog
);
1496 msi_dialog_set_first_control( dialog
, MSI_RecordGetString( rec
, 8 ) );
1497 msiobj_release( &rec
->hdr
);
1502 static UINT
msi_dialog_send_event( msi_dialog
*dialog
, LPCWSTR event
, LPCWSTR arg
)
1504 LPWSTR event_fmt
= NULL
, arg_fmt
= NULL
;
1506 TRACE("Sending control event %s %s\n", debugstr_w(event
), debugstr_w(arg
));
1508 deformat_string( dialog
->package
, event
, &event_fmt
);
1509 deformat_string( dialog
->package
, arg
, &arg_fmt
);
1511 dialog
->event_handler( dialog
->package
, event_fmt
, arg_fmt
, dialog
);
1513 msi_free( event_fmt
);
1514 msi_free( arg_fmt
);
1516 return ERROR_SUCCESS
;
1519 static UINT
msi_dialog_set_property( msi_dialog
*dialog
, LPCWSTR event
, LPCWSTR arg
)
1521 static const WCHAR szNullArg
[] = { '{','}',0 };
1522 LPWSTR p
, prop
, arg_fmt
= NULL
;
1525 len
= strlenW(event
);
1526 prop
= msi_alloc( len
*sizeof(WCHAR
));
1527 strcpyW( prop
, &event
[1] );
1528 p
= strchrW( prop
, ']' );
1529 if( p
&& p
[1] == 0 )
1532 if( strcmpW( szNullArg
, arg
) )
1533 deformat_string( dialog
->package
, arg
, &arg_fmt
);
1534 MSI_SetPropertyW( dialog
->package
, prop
, arg_fmt
);
1535 msi_free( arg_fmt
);
1538 ERR("Badly formatted property string - what happens?\n");
1540 return ERROR_SUCCESS
;
1543 static UINT
msi_dialog_control_event( MSIRECORD
*rec
, LPVOID param
)
1545 msi_dialog
*dialog
= param
;
1546 LPCWSTR condition
, event
, arg
;
1549 condition
= MSI_RecordGetString( rec
, 5 );
1550 r
= MSI_EvaluateConditionW( dialog
->package
, condition
);
1553 event
= MSI_RecordGetString( rec
, 3 );
1554 arg
= MSI_RecordGetString( rec
, 4 );
1555 if( event
[0] == '[' )
1556 msi_dialog_set_property( dialog
, event
, arg
);
1558 msi_dialog_send_event( dialog
, event
, arg
);
1561 return ERROR_SUCCESS
;
1564 static UINT
msi_dialog_button_handler( msi_dialog
*dialog
,
1565 msi_control
*control
, WPARAM param
)
1567 static const WCHAR query
[] = {
1568 'S','E','L','E','C','T',' ','*',' ',
1569 'F','R','O','M',' ','C','o','n','t','r','o','l','E','v','e','n','t',' ',
1570 'W','H','E','R','E',' ',
1571 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',' ',
1573 '`','C','o','n','t','r','o','l','_','`',' ','=',' ','\'','%','s','\'',' ',
1574 'O','R','D','E','R',' ','B','Y',' ','`','O','r','d','e','r','i','n','g','`',0
1576 MSIQUERY
*view
= NULL
;
1579 if( HIWORD(param
) != BN_CLICKED
)
1580 return ERROR_SUCCESS
;
1582 r
= MSI_OpenQuery( dialog
->package
->db
, &view
, query
,
1583 dialog
->name
, control
->name
);
1584 if( r
!= ERROR_SUCCESS
)
1586 ERR("query failed\n");
1590 r
= MSI_IterateRecords( view
, 0, msi_dialog_control_event
, dialog
);
1591 msiobj_release( &view
->hdr
);
1596 static UINT
msi_dialog_get_checkbox_state( msi_dialog
*dialog
,
1597 msi_control
*control
)
1599 WCHAR state
[2] = { 0 };
1602 MSI_GetPropertyW( dialog
->package
, control
->property
, state
, &sz
);
1603 return state
[0] ? 1 : 0;
1606 static void msi_dialog_set_checkbox_state( msi_dialog
*dialog
,
1607 msi_control
*control
, UINT state
)
1609 static const WCHAR szState
[] = { '1', 0 };
1612 /* if uncheck then the property is set to NULL */
1615 MSI_SetPropertyW( dialog
->package
, control
->property
, NULL
);
1619 /* check for a custom state */
1620 if (control
->value
&& control
->value
[0])
1621 val
= control
->value
;
1625 MSI_SetPropertyW( dialog
->package
, control
->property
, val
);
1628 static void msi_dialog_checkbox_sync_state( msi_dialog
*dialog
,
1629 msi_control
*control
)
1633 state
= msi_dialog_get_checkbox_state( dialog
, control
);
1634 SendMessageW( control
->hwnd
, BM_SETCHECK
,
1635 state
? BST_CHECKED
: BST_UNCHECKED
, 0 );
1638 static UINT
msi_dialog_checkbox_handler( msi_dialog
*dialog
,
1639 msi_control
*control
, WPARAM param
)
1643 if( HIWORD(param
) != BN_CLICKED
)
1644 return ERROR_SUCCESS
;
1646 TRACE("clicked checkbox %s, set %s\n", debugstr_w(control
->name
),
1647 debugstr_w(control
->property
));
1649 state
= msi_dialog_get_checkbox_state( dialog
, control
);
1650 state
= state
? 0 : 1;
1651 msi_dialog_set_checkbox_state( dialog
, control
, state
);
1652 msi_dialog_checkbox_sync_state( dialog
, control
);
1654 return msi_dialog_button_handler( dialog
, control
, param
);
1657 static UINT
msi_dialog_edit_handler( msi_dialog
*dialog
,
1658 msi_control
*control
, WPARAM param
)
1663 if( HIWORD(param
) != EN_CHANGE
)
1664 return ERROR_SUCCESS
;
1666 TRACE("edit %s contents changed, set %s\n", debugstr_w(control
->name
),
1667 debugstr_w(control
->property
));
1670 buf
= msi_alloc( sz
*sizeof(WCHAR
) );
1673 r
= GetWindowTextW( control
->hwnd
, buf
, sz
);
1677 buf
= msi_realloc( buf
, sz
*sizeof(WCHAR
) );
1680 MSI_SetPropertyW( dialog
->package
, control
->property
, buf
);
1684 return ERROR_SUCCESS
;
1687 static UINT
msi_dialog_radiogroup_handler( msi_dialog
*dialog
,
1688 msi_control
*control
, WPARAM param
)
1690 if( HIWORD(param
) != BN_CLICKED
)
1691 return ERROR_SUCCESS
;
1693 TRACE("clicked radio button %s, set %s\n", debugstr_w(control
->name
),
1694 debugstr_w(control
->property
));
1696 MSI_SetPropertyW( dialog
->package
, control
->property
, control
->name
);
1698 return msi_dialog_button_handler( dialog
, control
, param
);
1701 static LRESULT
msi_dialog_oncommand( msi_dialog
*dialog
, WPARAM param
, HWND hwnd
)
1703 msi_control
*control
;
1705 TRACE("%p %p %08x\n", dialog
, hwnd
, param
);
1707 control
= msi_dialog_find_control_by_hwnd( dialog
, hwnd
);
1710 if( control
->handler
)
1712 control
->handler( dialog
, control
, param
);
1713 msi_dialog_evaluate_control_conditions( dialog
);
1717 ERR("button click from nowhere\n");
1721 static void msi_dialog_setfocus( msi_dialog
*dialog
)
1723 HWND hwnd
= dialog
->hWndFocus
;
1725 hwnd
= GetNextDlgTabItem( dialog
->hwnd
, hwnd
, TRUE
);
1726 hwnd
= GetNextDlgTabItem( dialog
->hwnd
, hwnd
, FALSE
);
1728 dialog
->hWndFocus
= hwnd
;
1731 static LRESULT WINAPI
MSIDialog_WndProc( HWND hwnd
, UINT msg
,
1732 WPARAM wParam
, LPARAM lParam
)
1734 msi_dialog
*dialog
= (LPVOID
) GetWindowLongPtrW( hwnd
, GWLP_USERDATA
);
1736 TRACE("0x%04x\n", msg
);
1741 return msi_dialog_oncreate( hwnd
, (LPCREATESTRUCTW
)lParam
);
1744 return msi_dialog_oncommand( dialog
, wParam
, (HWND
)lParam
);
1747 if( LOWORD(wParam
) == WA_INACTIVE
)
1748 dialog
->hWndFocus
= GetFocus();
1750 msi_dialog_setfocus( dialog
);
1754 msi_dialog_setfocus( dialog
);
1757 /* bounce back to our subclassed static control */
1758 case WM_CTLCOLORSTATIC
:
1759 return SendMessageW( (HWND
) lParam
, WM_CTLCOLORSTATIC
, wParam
, lParam
);
1762 dialog
->hwnd
= NULL
;
1765 return DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
1768 static LRESULT WINAPI
MSIRadioGroup_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1770 WNDPROC oldproc
= (WNDPROC
) GetPropW(hWnd
, szButtonData
);
1772 TRACE("hWnd %p msg %04x wParam 0x%08x lParam 0x%08lx\n", hWnd
, msg
, wParam
, lParam
);
1774 if (msg
== WM_COMMAND
) /* Forward notifications to dialog */
1775 SendMessageW(GetParent(hWnd
), msg
, wParam
, lParam
);
1777 return CallWindowProcW(oldproc
, hWnd
, msg
, wParam
, lParam
);
1780 static LRESULT WINAPI
MSIHiddenWindowProc( HWND hwnd
, UINT msg
,
1781 WPARAM wParam
, LPARAM lParam
)
1783 msi_dialog
*dialog
= (msi_dialog
*) lParam
;
1785 TRACE("%d %p\n", msg
, dialog
);
1789 case WM_MSI_DIALOG_CREATE
:
1790 return msi_dialog_run_message_loop( dialog
);
1791 case WM_MSI_DIALOG_DESTROY
:
1792 msi_dialog_destroy( dialog
);
1795 return DefWindowProcW( hwnd
, msg
, wParam
, lParam
);
1798 /* functions that interface to other modules within MSI */
1800 msi_dialog
*msi_dialog_create( MSIPACKAGE
* package
, LPCWSTR szDialogName
,
1801 msi_dialog_event_handler event_handler
)
1803 MSIRECORD
*rec
= NULL
;
1806 TRACE("%p %s\n", package
, debugstr_w(szDialogName
));
1808 /* allocate the structure for the dialog to use */
1809 dialog
= msi_alloc_zero( sizeof *dialog
+ sizeof(WCHAR
)*strlenW(szDialogName
) );
1812 strcpyW( dialog
->name
, szDialogName
);
1813 msiobj_addref( &package
->hdr
);
1814 dialog
->package
= package
;
1815 dialog
->event_handler
= event_handler
;
1816 dialog
->finished
= 0;
1817 list_init( &dialog
->controls
);
1819 /* verify that the dialog exists */
1820 rec
= msi_get_dialog_record( dialog
);
1823 msiobj_release( &package
->hdr
);
1827 dialog
->attributes
= MSI_RecordGetInteger( rec
, 6 );
1828 msiobj_release( &rec
->hdr
);
1833 static void msi_process_pending_messages( HWND hdlg
)
1837 while( PeekMessageW( &msg
, 0, 0, 0, PM_REMOVE
) )
1839 if( hdlg
&& IsDialogMessageW( hdlg
, &msg
))
1841 TranslateMessage( &msg
);
1842 DispatchMessageW( &msg
);
1846 void msi_dialog_end_dialog( msi_dialog
*dialog
)
1848 TRACE("%p\n", dialog
);
1849 dialog
->finished
= 1;
1850 PostMessageW(dialog
->hwnd
, WM_NULL
, 0, 0);
1853 void msi_dialog_check_messages( HANDLE handle
)
1857 /* in threads other than the UI thread, block */
1858 if( uiThreadId
!= GetCurrentThreadId() )
1861 WaitForSingleObject( handle
, INFINITE
);
1865 /* there's two choices for the UI thread */
1868 msi_process_pending_messages( NULL
);
1874 * block here until somebody creates a new dialog or
1875 * the handle we're waiting on becomes ready
1877 r
= MsgWaitForMultipleObjects( 1, &handle
, 0, INFINITE
, QS_ALLINPUT
);
1878 if( r
== WAIT_OBJECT_0
)
1883 UINT
msi_dialog_run_message_loop( msi_dialog
*dialog
)
1887 if( !(dialog
->attributes
& msidbDialogAttributesVisible
) )
1888 return ERROR_SUCCESS
;
1890 if( uiThreadId
!= GetCurrentThreadId() )
1891 return SendMessageW( hMsiHiddenWindow
, WM_MSI_DIALOG_CREATE
, 0, (LPARAM
) dialog
);
1893 /* create the dialog window, don't show it yet */
1894 hwnd
= CreateWindowW( szMsiDialogClass
, dialog
->name
, WS_OVERLAPPEDWINDOW
,
1895 CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
,
1896 NULL
, NULL
, NULL
, dialog
);
1899 ERR("Failed to create dialog %s\n", debugstr_w( dialog
->name
));
1900 return ERROR_FUNCTION_FAILED
;
1903 ShowWindow( hwnd
, SW_SHOW
);
1904 UpdateWindow( hwnd
);
1906 if( dialog
->attributes
& msidbDialogAttributesModal
)
1908 while( !dialog
->finished
)
1910 MsgWaitForMultipleObjects( 0, NULL
, 0, INFINITE
, QS_ALLEVENTS
);
1911 msi_process_pending_messages( dialog
->hwnd
);
1915 return ERROR_IO_PENDING
;
1917 return ERROR_SUCCESS
;
1920 void msi_dialog_do_preview( msi_dialog
*dialog
)
1923 dialog
->attributes
|= msidbDialogAttributesVisible
;
1924 dialog
->attributes
&= ~msidbDialogAttributesModal
;
1925 msi_dialog_run_message_loop( dialog
);
1928 void msi_dialog_destroy( msi_dialog
*dialog
)
1930 if( uiThreadId
!= GetCurrentThreadId() )
1932 SendMessageW( hMsiHiddenWindow
, WM_MSI_DIALOG_DESTROY
, 0, (LPARAM
) dialog
);
1937 ShowWindow( dialog
->hwnd
, SW_HIDE
);
1940 DestroyWindow( dialog
->hwnd
);
1942 /* destroy the list of controls */
1943 while( !list_empty( &dialog
->controls
) )
1945 msi_control
*t
= LIST_ENTRY( list_head( &dialog
->controls
),
1946 msi_control
, entry
);
1947 list_remove( &t
->entry
);
1948 /* leave dialog->hwnd - destroying parent destroys child windows */
1949 msi_free( t
->property
);
1950 msi_free( t
->value
);
1952 DeleteObject( t
->hBitmap
);
1954 DestroyIcon( t
->hIcon
);
1955 msi_free( t
->tabnext
);
1958 FreeLibrary( t
->hDll
);
1961 /* destroy the list of fonts */
1962 while( dialog
->font_list
)
1964 msi_font
*t
= dialog
->font_list
;
1965 dialog
->font_list
= t
->next
;
1966 DeleteObject( t
->hfont
);
1969 msi_free( dialog
->default_font
);
1971 msiobj_release( &dialog
->package
->hdr
);
1972 dialog
->package
= NULL
;
1976 BOOL
msi_dialog_register_class( void )
1980 ZeroMemory( &cls
, sizeof cls
);
1981 cls
.lpfnWndProc
= MSIDialog_WndProc
;
1982 cls
.hInstance
= NULL
;
1983 cls
.hIcon
= LoadIconW(0, (LPWSTR
)IDI_APPLICATION
);
1984 cls
.hCursor
= LoadCursorW(0, (LPWSTR
)IDC_ARROW
);
1985 cls
.hbrBackground
= (HBRUSH
)(COLOR_WINDOW
+ 1);
1986 cls
.lpszMenuName
= NULL
;
1987 cls
.lpszClassName
= szMsiDialogClass
;
1989 if( !RegisterClassW( &cls
) )
1992 cls
.lpfnWndProc
= MSIHiddenWindowProc
;
1993 cls
.lpszClassName
= szMsiHiddenWindow
;
1995 if( !RegisterClassW( &cls
) )
1998 uiThreadId
= GetCurrentThreadId();
2000 hMsiHiddenWindow
= CreateWindowW( szMsiHiddenWindow
, NULL
, WS_OVERLAPPED
,
2001 0, 0, 100, 100, NULL
, NULL
, NULL
, NULL
);
2002 if( !hMsiHiddenWindow
)
2008 void msi_dialog_unregister_class( void )
2010 DestroyWindow( hMsiHiddenWindow
);
2011 UnregisterClassW( szMsiDialogClass
, NULL
);