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
51 struct msi_control_tag
*next
;
62 typedef struct msi_font_tag
64 struct msi_font_tag
*next
;
72 msi_dialog_event_handler event_handler
;
79 msi_control
*control_list
;
84 typedef UINT (*msi_dialog_control_func
)( msi_dialog
*dialog
, MSIRECORD
*rec
);
85 struct control_handler
88 msi_dialog_control_func func
;
96 } radio_button_group_descr
;
98 const WCHAR szMsiDialogClass
[] = {
99 'M','s','i','D','i','a','l','o','g','C','l','o','s','e','C','l','a','s','s',0
101 const WCHAR szMsiHiddenWindow
[] = {
102 'M','s','i','H','i','d','d','e','n','W','i','n','d','o','w',0 };
103 const static WCHAR szStatic
[] = { 'S','t','a','t','i','c',0 };
104 const static WCHAR szButton
[] = { 'B','U','T','T','O','N', 0 };
105 const static WCHAR szButtonData
[] = { 'M','S','I','D','A','T','A',0 };
106 static const WCHAR szText
[] = { 'T','e','x','t',0 };
107 static const WCHAR szPushButton
[] = { 'P','u','s','h','B','u','t','t','o','n',0 };
108 static const WCHAR szLine
[] = { 'L','i','n','e',0 };
109 static const WCHAR szBitmap
[] = { 'B','i','t','m','a','p',0 };
110 static const WCHAR szCheckBox
[] = { 'C','h','e','c','k','B','o','x',0 };
111 static const WCHAR szScrollableText
[] = {
112 'S','c','r','o','l','l','a','b','l','e','T','e','x','t',0 };
113 static const WCHAR szComboBox
[] = { 'C','o','m','b','o','B','o','x',0 };
114 static const WCHAR szEdit
[] = { 'E','d','i','t',0 };
115 static const WCHAR szMaskedEdit
[] = { 'M','a','s','k','e','d','E','d','i','t',0 };
116 static const WCHAR szPathEdit
[] = { 'P','a','t','h','E','d','i','t',0 };
117 static const WCHAR szRadioButtonGroup
[] = {
118 'R','a','d','i','o','B','u','t','t','o','n','G','r','o','u','p',0 };
119 static const WCHAR szIcon
[] = { 'I','c','o','n',0 };
121 static UINT
msi_dialog_checkbox_handler( msi_dialog
*, msi_control
*, WPARAM
);
122 static void msi_dialog_checkbox_sync_state( msi_dialog
*, msi_control
* );
123 static UINT
msi_dialog_button_handler( msi_dialog
*, msi_control
*, WPARAM
);
124 static UINT
msi_dialog_edit_handler( msi_dialog
*, msi_control
*, WPARAM
);
125 static UINT
msi_dialog_radiogroup_handler( msi_dialog
*, msi_control
*, WPARAM param
);
126 static UINT
msi_dialog_evaluate_control_conditions( msi_dialog
*dialog
);
127 static LRESULT WINAPI
MSIRadioGroup_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
);
130 /* dialog sequencing */
132 #define WM_MSI_DIALOG_CREATE (WM_USER+0x100)
133 #define WM_MSI_DIALOG_DESTROY (WM_USER+0x101)
135 static DWORD uiThreadId
;
136 static HWND hMsiHiddenWindow
;
137 static HMODULE hRichedit
;
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 for( control
= dialog
->control_list
; control
; control
= control
->next
)
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 for( control
= dialog
->control_list
; control
; control
= control
->next
)
161 if( hwnd
== control
->hwnd
)
167 * msi_dialog_get_style
169 * Extract the {\style} string from the front of the text to display and
170 * update the pointer.
172 static LPWSTR
msi_dialog_get_style( LPCWSTR
*text
)
175 LPCWSTR p
= *text
, q
;
180 q
= strchrW( p
, '}' );
188 ret
= HeapAlloc( GetProcessHeap(), 0, len
*sizeof(WCHAR
) );
191 memcpy( ret
, p
, len
*sizeof(WCHAR
) );
196 static UINT
msi_dialog_add_font( MSIRECORD
*rec
, LPVOID param
)
198 msi_dialog
*dialog
= param
;
205 /* create a font and add it to the list */
206 name
= MSI_RecordGetString( rec
, 1 );
207 font
= HeapAlloc( GetProcessHeap(), 0,
208 sizeof *font
+ strlenW( name
)*sizeof (WCHAR
) );
209 strcpyW( font
->name
, name
);
210 font
->next
= dialog
->font_list
;
211 dialog
->font_list
= font
;
213 memset( &lf
, 0, sizeof lf
);
214 face
= MSI_RecordGetString( rec
, 2 );
215 lf
.lfHeight
= MSI_RecordGetInteger( rec
, 3 );
216 style
= MSI_RecordGetInteger( rec
, 5 );
217 if( style
& msidbTextStyleStyleBitsBold
)
218 lf
.lfWeight
= FW_BOLD
;
219 if( style
& msidbTextStyleStyleBitsItalic
)
221 if( style
& msidbTextStyleStyleBitsUnderline
)
222 lf
.lfUnderline
= TRUE
;
223 if( style
& msidbTextStyleStyleBitsStrike
)
224 lf
.lfStrikeOut
= TRUE
;
225 lstrcpynW( lf
.lfFaceName
, face
, LF_FACESIZE
);
227 /* adjust the height */
228 hdc
= GetDC( dialog
->hwnd
);
231 lf
.lfHeight
= -MulDiv(lf
.lfHeight
, GetDeviceCaps(hdc
, LOGPIXELSY
), 72);
232 ReleaseDC( dialog
->hwnd
, hdc
);
235 font
->hfont
= CreateFontIndirectW( &lf
);
237 TRACE("Adding font style %s\n", debugstr_w(font
->name
) );
239 return ERROR_SUCCESS
;
242 static msi_font
*msi_dialog_find_font( msi_dialog
*dialog
, LPCWSTR name
)
246 for( font
= dialog
->font_list
; font
; font
= font
->next
)
247 if( !strcmpW( font
->name
, name
) ) /* FIXME: case sensitive? */
253 static UINT
msi_dialog_set_font( msi_dialog
*dialog
, HWND hwnd
, LPCWSTR name
)
257 font
= msi_dialog_find_font( dialog
, name
);
259 SendMessageW( hwnd
, WM_SETFONT
, (WPARAM
) font
->hfont
, TRUE
);
261 ERR("No font entry for %s\n", debugstr_w(name
));
262 return ERROR_SUCCESS
;
265 static UINT
msi_dialog_build_font_list( msi_dialog
*dialog
)
267 static const WCHAR query
[] = {
268 'S','E','L','E','C','T',' ','*',' ',
269 'F','R','O','M',' ','`','T','e','x','t','S','t','y','l','e','`',' ',0
272 MSIQUERY
*view
= NULL
;
274 TRACE("dialog %p\n", dialog
);
276 r
= MSI_OpenQuery( dialog
->package
->db
, &view
, query
);
277 if( r
!= ERROR_SUCCESS
)
280 r
= MSI_IterateRecords( view
, NULL
, msi_dialog_add_font
, dialog
);
281 msiobj_release( &view
->hdr
);
286 static msi_control
*msi_dialog_create_window( msi_dialog
*dialog
,
287 MSIRECORD
*rec
, LPCWSTR szCls
, LPCWSTR name
, LPCWSTR text
,
288 DWORD style
, HWND parent
)
290 DWORD x
, y
, width
, height
;
291 LPWSTR font
= NULL
, title
= NULL
;
292 msi_control
*control
;
296 control
= HeapAlloc( GetProcessHeap(), 0,
297 sizeof *control
+ strlenW(name
)*sizeof(WCHAR
) );
298 strcpyW( control
->name
, name
);
299 control
->next
= dialog
->control_list
;
300 dialog
->control_list
= control
;
301 control
->handler
= NULL
;
302 control
->property
= NULL
;
303 control
->value
= NULL
;
304 control
->hBitmap
= NULL
;
305 control
->hIcon
= NULL
;
306 control
->tabnext
= strdupW( MSI_RecordGetString( rec
, 11) );
308 x
= MSI_RecordGetInteger( rec
, 4 );
309 y
= MSI_RecordGetInteger( rec
, 5 );
310 width
= MSI_RecordGetInteger( rec
, 6 );
311 height
= MSI_RecordGetInteger( rec
, 7 );
313 x
= msi_dialog_scale_unit( dialog
, x
);
314 y
= msi_dialog_scale_unit( dialog
, y
);
315 width
= msi_dialog_scale_unit( dialog
, width
);
316 height
= msi_dialog_scale_unit( dialog
, height
);
320 font
= msi_dialog_get_style( &text
);
321 deformat_string( dialog
->package
, text
, &title
);
324 control
->hwnd
= CreateWindowW( szCls
, title
, style
,
325 x
, y
, width
, height
, parent
, NULL
, NULL
, NULL
);
327 TRACE("Dialog %s control %s hwnd %p\n",
328 debugstr_w(dialog
->name
), debugstr_w(text
), control
->hwnd
);
330 msi_dialog_set_font( dialog
, control
->hwnd
,
331 font
? font
: dialog
->default_font
);
333 HeapFree( GetProcessHeap(), 0, font
);
334 HeapFree( GetProcessHeap(), 0, title
);
339 static MSIRECORD
*msi_get_binary_record( MSIDATABASE
*db
, LPCWSTR name
)
341 const static WCHAR query
[] = {
342 's','e','l','e','c','t',' ','*',' ',
343 'f','r','o','m',' ','B','i','n','a','r','y',' ',
344 'w','h','e','r','e',' ',
345 '`','N','a','m','e','`',' ','=',' ','\'','%','s','\'',0
348 return MSI_QueryGetRecord( db
, query
, name
);
351 static LPWSTR
msi_create_tmp_path(void)
355 static const WCHAR prefix
[] = { 'm','s','i',0 };
358 r
= GetTempPathW( MAX_PATH
, tmp
);
361 len
= lstrlenW( tmp
) + 20;
362 path
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof (WCHAR
) );
365 r
= GetTempFileNameW( tmp
, prefix
, 0, path
);
368 HeapFree( GetProcessHeap(), 0, path
);
376 static HANDLE
msi_load_image( MSIDATABASE
*db
, LPCWSTR name
, UINT type
,
377 UINT cx
, UINT cy
, UINT flags
)
379 MSIRECORD
*rec
= NULL
;
380 HANDLE himage
= NULL
;
384 TRACE("%p %s %u %u %08x\n", db
, debugstr_w(name
), cx
, cy
, flags
);
386 tmp
= msi_create_tmp_path();
390 rec
= msi_get_binary_record( db
, name
);
393 r
= MSI_RecordStreamToFile( rec
, 2, tmp
);
394 if( r
== ERROR_SUCCESS
)
396 himage
= LoadImageW( 0, tmp
, type
, cx
, cy
, flags
);
399 msiobj_release( &rec
->hdr
);
402 HeapFree( GetProcessHeap(), 0, tmp
);
406 static HICON
msi_load_icon( MSIDATABASE
*db
, LPCWSTR text
, UINT attributes
)
408 DWORD cx
= 0, cy
= 0, flags
;
410 flags
= LR_LOADFROMFILE
| LR_DEFAULTSIZE
;
411 if( attributes
& msidbControlAttributesFixedSize
)
413 flags
&= ~LR_DEFAULTSIZE
;
414 if( attributes
& msidbControlAttributesIconSize16
)
419 if( attributes
& msidbControlAttributesIconSize32
)
424 /* msidbControlAttributesIconSize48 handled by above logic */
426 return msi_load_image( db
, text
, IMAGE_ICON
, cx
, cy
, flags
);
430 /* called from the Control Event subscription code */
431 void msi_dialog_handle_event( msi_dialog
* dialog
, LPCWSTR control
,
432 LPCWSTR attribute
, MSIRECORD
*rec
)
437 ctrl
= msi_dialog_find_control( dialog
, control
);
440 if( lstrcmpW(attribute
, szText
) )
442 text
= MSI_RecordGetString( rec
, 1 );
443 SetWindowTextW( ctrl
->hwnd
, text
);
444 msi_dialog_check_messages( NULL
);
447 static void msi_dialog_map_events(msi_dialog
* dialog
, LPCWSTR control
)
449 static WCHAR Query
[] = {
450 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
451 '`','E','v','e','n','t','M','a','p','p','i','n','g','`',' ',
452 'W','H','E','R','E',' ',
453 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',' ',
455 '`','C','o','n','t','r','o','l','_','`',' ','=',' ','\'','%','s','\'',0
458 LPCWSTR event
, attribute
;
460 row
= MSI_QueryGetRecord( dialog
->package
->db
, Query
, dialog
->name
, control
);
464 event
= MSI_RecordGetString( row
, 3 );
465 attribute
= MSI_RecordGetString( row
, 4 );
466 ControlEvent_SubscribeToEvent( dialog
->package
, event
, control
, attribute
);
467 msiobj_release( &row
->hdr
);
470 /* everything except radio buttons */
471 static msi_control
*msi_dialog_add_control( msi_dialog
*dialog
,
472 MSIRECORD
*rec
, LPCWSTR szCls
, DWORD style
)
477 name
= MSI_RecordGetString( rec
, 2 );
478 attributes
= MSI_RecordGetInteger( rec
, 8 );
479 text
= MSI_RecordGetString( rec
, 10 );
480 if( attributes
& msidbControlAttributesVisible
)
482 if( ~attributes
& msidbControlAttributesEnabled
)
483 style
|= WS_DISABLED
;
485 msi_dialog_map_events(dialog
, name
);
487 return msi_dialog_create_window( dialog
, rec
, szCls
, name
, text
,
488 style
, dialog
->hwnd
);
498 * we don't erase our own background,
499 * so we have to make sure that the parent window redraws first
501 static void msi_text_on_settext( HWND hWnd
)
506 hParent
= GetParent( hWnd
);
507 GetWindowRect( hWnd
, &rc
);
508 MapWindowPoints( NULL
, hParent
, (LPPOINT
) &rc
, 2 );
509 InvalidateRect( hParent
, &rc
, TRUE
);
512 static LRESULT WINAPI
513 MSIText_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
515 struct msi_text_info
*info
;
518 TRACE("%p %04x %08x %08lx\n", hWnd
, msg
, wParam
, lParam
);
520 info
= GetPropW(hWnd
, szButtonData
);
522 if( msg
== WM_CTLCOLORSTATIC
&&
523 ( info
->attributes
& msidbControlAttributesTransparent
) )
525 SetBkMode( (HDC
)wParam
, TRANSPARENT
);
526 return (LRESULT
) GetStockObject(NULL_BRUSH
);
529 r
= CallWindowProcW(info
->oldproc
, hWnd
, msg
, wParam
, lParam
);
534 msi_text_on_settext( hWnd
);
537 HeapFree( GetProcessHeap(), 0, info
);
538 RemovePropW( hWnd
, szButtonData
);
545 static UINT
msi_dialog_text_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
547 msi_control
*control
;
548 struct msi_text_info
*info
;
550 TRACE("%p %p\n", dialog
, rec
);
552 control
= msi_dialog_add_control( dialog
, rec
, szStatic
, SS_LEFT
| WS_GROUP
);
554 return ERROR_FUNCTION_FAILED
;
556 info
= HeapAlloc( GetProcessHeap(), 0, sizeof *info
);
558 return ERROR_SUCCESS
;
560 info
->attributes
= MSI_RecordGetInteger( rec
, 8 );
561 if( info
->attributes
& msidbControlAttributesTransparent
)
562 SetWindowLongPtrW( control
->hwnd
, GWL_EXSTYLE
, WS_EX_TRANSPARENT
);
564 info
->oldproc
= (WNDPROC
) SetWindowLongPtrW( control
->hwnd
, GWLP_WNDPROC
,
565 (LONG_PTR
)MSIText_WndProc
);
566 SetPropW( control
->hwnd
, szButtonData
, info
);
568 return ERROR_SUCCESS
;
571 static UINT
msi_dialog_button_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
573 msi_control
*control
;
574 UINT attributes
, style
;
577 TRACE("%p %p\n", dialog
, rec
);
580 attributes
= MSI_RecordGetInteger( rec
, 8 );
581 if( attributes
& msidbControlAttributesIcon
)
584 control
= msi_dialog_add_control( dialog
, rec
, szButton
, style
);
586 return ERROR_FUNCTION_FAILED
;
588 control
->handler
= msi_dialog_button_handler
;
591 text
= MSI_RecordGetString( rec
, 10 );
592 control
->hIcon
= msi_load_icon( dialog
->package
->db
, text
, attributes
);
593 if( attributes
& msidbControlAttributesIcon
)
594 SendMessageW( control
->hwnd
, BM_SETIMAGE
, IMAGE_ICON
, (LPARAM
) control
->hIcon
);
596 return ERROR_SUCCESS
;
599 static LPWSTR
msi_get_checkbox_value( msi_dialog
*dialog
, LPCWSTR prop
)
601 const static WCHAR query
[] = {
602 'S','E','L','E','C','T',' ','*',' ',
603 'F','R','O','M',' ','`','C','h','e','c','k','B','o','x',' ','`',
604 'W','H','E','R','E',' ',
605 '`','P','r','o','p','e','r','t','y','`',' ','=',' ',
608 MSIRECORD
*rec
= NULL
;
612 /* find if there is a value associated with the checkbox */
613 rec
= MSI_QueryGetRecord( dialog
->package
->db
, query
, prop
);
617 val
= MSI_RecordGetString( rec
, 2 );
620 deformat_string( dialog
->package
, val
, &ret
);
623 HeapFree( GetProcessHeap(), 0, ret
);
627 msiobj_release( &rec
->hdr
);
631 ret
= load_dynamic_property(dialog
->package
, prop
, NULL
);
634 HeapFree( GetProcessHeap(), 0, ret
);
641 static UINT
msi_dialog_checkbox_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
643 msi_control
*control
;
646 TRACE("%p %p\n", dialog
, rec
);
648 control
= msi_dialog_add_control( dialog
, rec
, szButton
,
649 BS_CHECKBOX
| BS_MULTILINE
| WS_TABSTOP
);
650 control
->handler
= msi_dialog_checkbox_handler
;
651 prop
= MSI_RecordGetString( rec
, 9 );
654 control
->property
= strdupW( prop
);
655 control
->value
= msi_get_checkbox_value( dialog
, prop
);
656 TRACE("control %s value %s\n", debugstr_w(control
->property
),
657 debugstr_w(control
->value
));
659 msi_dialog_checkbox_sync_state( dialog
, control
);
661 return ERROR_SUCCESS
;
664 static UINT
msi_dialog_line_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
666 TRACE("%p %p\n", dialog
, rec
);
668 msi_dialog_add_control( dialog
, rec
, szStatic
, SS_ETCHEDHORZ
| SS_SUNKEN
);
669 return ERROR_SUCCESS
;
672 struct msi_streamin_info
679 static DWORD CALLBACK
680 msi_richedit_stream_in( DWORD_PTR arg
, LPBYTE buffer
, LONG count
, LONG
*pcb
)
682 struct msi_streamin_info
*info
= (struct msi_streamin_info
*) arg
;
684 if( (count
+ info
->offset
) > info
->length
)
685 count
= info
->length
- info
->offset
;
686 memcpy( buffer
, &info
->string
[ info
->offset
], count
);
688 info
->offset
+= count
;
690 TRACE("%ld/%ld\n", info
->offset
, info
->length
);
695 static UINT
msi_dialog_scrolltext_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
697 const static WCHAR szRichEdit20W
[] = {
698 'R','i','c','h','E','d','i','t','2','0','W',0
700 struct msi_streamin_info info
;
701 msi_control
*control
;
706 style
= WS_BORDER
| ES_MULTILINE
| WS_VSCROLL
|
707 ES_READONLY
| ES_AUTOVSCROLL
| WS_TABSTOP
;
708 control
= msi_dialog_add_control( dialog
, rec
, szRichEdit20W
, style
);
710 text
= MSI_RecordGetString( rec
, 10 );
711 info
.string
= strdupWtoA( text
);
713 info
.length
= lstrlenA( info
.string
) + 1;
715 es
.dwCookie
= (DWORD_PTR
) &info
;
717 es
.pfnCallback
= msi_richedit_stream_in
;
719 SendMessageW( control
->hwnd
, EM_STREAMIN
, SF_RTF
, (LPARAM
) &es
);
721 HeapFree( GetProcessHeap(), 0, info
.string
);
723 return ERROR_SUCCESS
;
726 static UINT
msi_dialog_bitmap_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
728 UINT cx
, cy
, flags
, style
, attributes
;
729 msi_control
*control
;
732 flags
= LR_LOADFROMFILE
;
733 style
= SS_BITMAP
| SS_LEFT
| WS_GROUP
;
735 attributes
= MSI_RecordGetInteger( rec
, 8 );
736 if( attributes
& msidbControlAttributesFixedSize
)
738 flags
|= LR_DEFAULTSIZE
;
739 style
|= SS_CENTERIMAGE
;
742 control
= msi_dialog_add_control( dialog
, rec
, szStatic
, style
);
743 text
= MSI_RecordGetString( rec
, 10 );
744 cx
= MSI_RecordGetInteger( rec
, 6 );
745 cy
= MSI_RecordGetInteger( rec
, 7 );
746 cx
= msi_dialog_scale_unit( dialog
, cx
);
747 cy
= msi_dialog_scale_unit( dialog
, cy
);
749 control
->hBitmap
= msi_load_image( dialog
->package
->db
, text
,
750 IMAGE_BITMAP
, cx
, cy
, flags
);
751 if( control
->hBitmap
)
752 SendMessageW( control
->hwnd
, STM_SETIMAGE
,
753 IMAGE_BITMAP
, (LPARAM
) control
->hBitmap
);
755 ERR("Failed to load bitmap %s\n", debugstr_w(text
));
757 return ERROR_SUCCESS
;
760 static UINT
msi_dialog_icon_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
762 msi_control
*control
;
768 control
= msi_dialog_add_control( dialog
, rec
, szStatic
,
769 SS_ICON
| SS_CENTERIMAGE
| WS_GROUP
);
771 attributes
= MSI_RecordGetInteger( rec
, 8 );
772 text
= MSI_RecordGetString( rec
, 10 );
773 control
->hIcon
= msi_load_icon( dialog
->package
->db
, text
, attributes
);
775 SendMessageW( control
->hwnd
, STM_SETICON
, (WPARAM
) control
->hIcon
, 0 );
777 ERR("Failed to load bitmap %s\n", debugstr_w(text
));
778 return ERROR_SUCCESS
;
781 static UINT
msi_dialog_combo_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
783 static const WCHAR szCombo
[] = { 'C','O','M','B','O','B','O','X',0 };
785 msi_dialog_add_control( dialog
, rec
, szCombo
,
786 SS_BITMAP
| SS_LEFT
| SS_CENTERIMAGE
);
787 return ERROR_SUCCESS
;
790 static UINT
msi_dialog_edit_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
792 msi_control
*control
;
796 control
= msi_dialog_add_control( dialog
, rec
, szEdit
,
797 WS_BORDER
| WS_TABSTOP
);
798 control
->handler
= msi_dialog_edit_handler
;
799 prop
= MSI_RecordGetString( rec
, 9 );
801 control
->property
= strdupW( prop
);
802 val
= load_dynamic_property( dialog
->package
, control
->property
, NULL
);
803 SetWindowTextW( control
->hwnd
, val
);
804 HeapFree( GetProcessHeap(), 0, val
);
805 return ERROR_SUCCESS
;
808 /******************** Masked Edit ********************************************/
810 #define MASK_MAX_GROUPS 10
812 struct msi_mask_group
820 struct msi_maskedit_info
828 struct msi_mask_group group
[MASK_MAX_GROUPS
];
831 static void msi_mask_control_change( struct msi_maskedit_info
*info
)
836 val
= HeapAlloc( GetProcessHeap(), 0, (info
->num_chars
+1)*sizeof(WCHAR
) );
837 for( i
=0, n
=0; i
<info
->num_groups
; i
++ )
839 if( (info
->group
[i
].len
+ n
) > info
->num_chars
)
841 ERR("can't fit control %d text into template\n",i
);
844 r
= GetWindowTextW( info
->group
[i
].hwnd
, &val
[n
], info
->group
[i
].len
+1 );
845 if( r
!= info
->group
[i
].len
)
850 TRACE("%d/%d controls were good\n", i
, info
->num_groups
);
852 if( i
== info
->num_groups
)
854 TRACE("Set property %s to %s\n",
855 debugstr_w(info
->prop
), debugstr_w(val
) );
856 CharUpperBuffW( val
, info
->num_chars
);
857 MSI_SetPropertyW( info
->dialog
->package
, info
->prop
, val
);
858 msi_dialog_evaluate_control_conditions( info
->dialog
);
860 HeapFree( GetProcessHeap(), 0, val
);
863 /* now move to the next control if necessary */
864 static VOID
msi_mask_next_control( struct msi_maskedit_info
*info
, HWND hWnd
)
869 for( i
=0; i
<info
->num_groups
; i
++ )
870 if( info
->group
[i
].hwnd
== hWnd
)
873 /* don't move from the last control */
874 if( i
>= (info
->num_groups
-1) )
877 len
= SendMessageW( hWnd
, WM_GETTEXTLENGTH
, 0, 0 );
878 if( len
< info
->group
[i
].len
)
881 hWndNext
= GetNextDlgTabItem( GetParent( hWnd
), hWnd
, FALSE
);
882 SetFocus( hWndNext
);
885 static LRESULT WINAPI
886 MSIMaskedEdit_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
888 struct msi_maskedit_info
*info
;
891 TRACE("%p %04x %08x %08lx\n", hWnd
, msg
, wParam
, lParam
);
893 info
= GetPropW(hWnd
, szButtonData
);
895 r
= CallWindowProcW(info
->oldproc
, hWnd
, msg
, wParam
, lParam
);
900 if (HIWORD(wParam
) == EN_CHANGE
)
902 msi_mask_control_change( info
);
903 msi_mask_next_control( info
, (HWND
) lParam
);
907 HeapFree( GetProcessHeap(), 0, info
->prop
);
908 HeapFree( GetProcessHeap(), 0, info
);
909 RemovePropW( hWnd
, szButtonData
);
916 /* fish the various bits of the property out and put them in the control */
918 msi_maskedit_set_text( struct msi_maskedit_info
*info
, LPCWSTR text
)
924 for( i
= 0; i
< info
->num_groups
; i
++ )
926 if( info
->group
[i
].len
< lstrlenW( p
) )
928 LPWSTR chunk
= strdupW( p
);
929 chunk
[ info
->group
[i
].len
] = 0;
930 SetWindowTextW( info
->group
[i
].hwnd
, chunk
);
931 HeapFree( GetProcessHeap(), 0, chunk
);
935 SetWindowTextW( info
->group
[i
].hwnd
, p
);
938 p
+= info
->group
[i
].len
;
942 static struct msi_maskedit_info
* msi_dialog_parse_groups( LPCWSTR mask
)
944 struct msi_maskedit_info
* info
= NULL
;
945 int i
= 0, n
= 0, total
= 0;
948 TRACE("masked control, template %s\n", debugstr_w(mask
));
953 p
= strchrW(mask
, '<');
957 info
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof *info
);
962 for( i
=0; i
<MASK_MAX_GROUPS
; i
++ )
964 /* stop at the end of the string */
965 if( p
[0] == 0 || p
[0] == '>' )
968 /* count the number of the same identifier */
969 for( n
=0; p
[n
] == p
[0]; n
++ )
971 info
->group
[i
].ofs
= total
;
972 info
->group
[i
].type
= p
[0];
976 total
++; /* an extra not part of the group */
978 info
->group
[i
].len
= n
;
983 TRACE("%d characters in %d groups\n", total
, info
->num_groups
);
984 if( i
== MASK_MAX_GROUPS
)
985 ERR("too many groups in PIDTemplate %s\n", debugstr_w(mask
));
987 info
->num_chars
= total
;
988 info
->num_groups
= i
;
994 msi_maskedit_create_children( struct msi_maskedit_info
*info
)
996 DWORD width
, height
, style
, wx
, ww
;
997 LPCWSTR text
, font
= NULL
;
1002 style
= WS_CHILD
| WS_BORDER
| WS_VISIBLE
| WS_TABSTOP
;
1004 GetClientRect( info
->hwnd
, &rect
);
1006 width
= rect
.right
- rect
.left
;
1007 height
= rect
.bottom
- rect
.top
;
1010 font
= msi_dialog_get_style( &text
);
1012 for( i
= 0; i
< info
->num_groups
; i
++ )
1014 wx
= (info
->group
[i
].ofs
* width
) / info
->num_chars
;
1015 ww
= (info
->group
[i
].len
* width
) / info
->num_chars
;
1017 hwnd
= CreateWindowW( szEdit
, NULL
, style
, wx
, 0, ww
, height
,
1018 info
->hwnd
, NULL
, NULL
, NULL
);
1021 ERR("failed to create mask edit sub window\n");
1025 SendMessageW( hwnd
, EM_LIMITTEXT
, info
->group
[i
].len
, 0 );
1027 msi_dialog_set_font( info
->dialog
, hwnd
,
1028 font
? font
: info
->dialog
->default_font
);
1029 info
->group
[i
].hwnd
= hwnd
;
1033 /* office 2003 uses "73931<````=````=````=````=`````>@@@@@" */
1034 static UINT
msi_dialog_maskedit_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1036 const static WCHAR pidt
[] = {'P','I','D','T','e','m','p','l','a','t','e',0};
1037 LPWSTR mask
= NULL
, title
= NULL
, val
= NULL
;
1038 struct msi_maskedit_info
*info
= NULL
;
1039 UINT ret
= ERROR_SUCCESS
;
1040 msi_control
*control
;
1043 mask
= load_dynamic_property( dialog
->package
, pidt
, NULL
);
1046 ERR("PIDTemplate is empty\n");
1050 info
= msi_dialog_parse_groups( mask
);
1053 ERR("template %s is invalid\n", debugstr_w(mask
));
1057 info
->dialog
= dialog
;
1059 control
= msi_dialog_add_control( dialog
, rec
, szStatic
,
1060 SS_OWNERDRAW
| WS_GROUP
| WS_VISIBLE
);
1063 ERR("Failed to create maskedit container\n");
1064 ret
= ERROR_FUNCTION_FAILED
;
1067 SetWindowLongPtrW( control
->hwnd
, GWL_EXSTYLE
, WS_EX_CONTROLPARENT
);
1069 info
->hwnd
= control
->hwnd
;
1071 /* subclass the static control */
1072 info
->oldproc
= (WNDPROC
) SetWindowLongPtrW( info
->hwnd
, GWLP_WNDPROC
,
1073 (LONG_PTR
)MSIMaskedEdit_WndProc
);
1074 SetPropW( control
->hwnd
, szButtonData
, info
);
1076 prop
= MSI_RecordGetString( rec
, 9 );
1078 info
->prop
= strdupW( prop
);
1080 msi_maskedit_create_children( info
);
1084 val
= load_dynamic_property( dialog
->package
, prop
, NULL
);
1087 msi_maskedit_set_text( info
, val
);
1088 HeapFree( GetProcessHeap(), 0, val
);
1093 if( ret
!= ERROR_SUCCESS
)
1094 HeapFree( GetProcessHeap(), 0, info
);
1095 HeapFree( GetProcessHeap(), 0, title
);
1096 HeapFree( GetProcessHeap(), 0, mask
);
1100 /******************** Path Edit ********************************************/
1102 static UINT
msi_dialog_pathedit_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1104 FIXME("not implemented properly\n");
1105 return msi_dialog_edit_control( dialog
, rec
);
1108 /* radio buttons are a bit different from normal controls */
1109 static UINT
msi_dialog_create_radiobutton( MSIRECORD
*rec
, LPVOID param
)
1111 radio_button_group_descr
*group
= (radio_button_group_descr
*)param
;
1112 msi_dialog
*dialog
= group
->dialog
;
1113 msi_control
*control
;
1114 LPCWSTR prop
, text
, name
;
1116 DWORD attributes
= group
->attributes
;
1118 style
= WS_CHILD
| BS_AUTORADIOBUTTON
| BS_MULTILINE
| WS_TABSTOP
;
1119 name
= MSI_RecordGetString( rec
, 3 );
1120 text
= MSI_RecordGetString( rec
, 8 );
1121 if( attributes
& 1 )
1122 style
|= WS_VISIBLE
;
1123 if( ~attributes
& 2 )
1124 style
|= WS_DISABLED
;
1126 control
= msi_dialog_create_window( dialog
, rec
, szButton
, name
, text
,
1127 style
, group
->parent
->hwnd
);
1128 control
->handler
= msi_dialog_radiogroup_handler
;
1130 prop
= MSI_RecordGetString( rec
, 1 );
1132 control
->property
= strdupW( prop
);
1134 return ERROR_SUCCESS
;
1137 static UINT
msi_dialog_radiogroup_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1139 static const WCHAR query
[] = {
1140 'S','E','L','E','C','T',' ','*',' ',
1141 'F','R','O','M',' ','R','a','d','i','o','B','u','t','t','o','n',' ',
1142 'W','H','E','R','E',' ',
1143 '`','P','r','o','p','e','r','t','y','`',' ','=',' ','\'','%','s','\'',0};
1146 msi_control
*control
;
1147 MSIQUERY
*view
= NULL
;
1148 radio_button_group_descr group
;
1149 MSIPACKAGE
*package
= dialog
->package
;
1152 prop
= MSI_RecordGetString( rec
, 9 );
1154 TRACE("%p %p %s\n", dialog
, rec
, debugstr_w( prop
));
1156 /* Create parent group box to hold radio buttons */
1157 control
= msi_dialog_add_control( dialog
, rec
, szButton
, BS_OWNERDRAW
|WS_GROUP
);
1159 return ERROR_FUNCTION_FAILED
;
1161 oldproc
= (WNDPROC
) SetWindowLongPtrW( control
->hwnd
, GWLP_WNDPROC
,
1162 (LONG_PTR
)MSIRadioGroup_WndProc
);
1163 SetPropW(control
->hwnd
, szButtonData
, oldproc
);
1164 SetWindowLongPtrW( control
->hwnd
, GWL_EXSTYLE
, WS_EX_CONTROLPARENT
);
1167 control
->property
= strdupW( prop
);
1169 /* query the Radio Button table for all control in this group */
1170 r
= MSI_OpenQuery( package
->db
, &view
, query
, prop
);
1171 if( r
!= ERROR_SUCCESS
)
1173 ERR("query failed for dialog %s radio group %s\n",
1174 debugstr_w(dialog
->name
), debugstr_w(prop
));
1175 return ERROR_INVALID_PARAMETER
;
1178 group
.dialog
= dialog
;
1179 group
.parent
= control
;
1180 group
.attributes
= MSI_RecordGetInteger( rec
, 8 );
1182 r
= MSI_IterateRecords( view
, 0, msi_dialog_create_radiobutton
, &group
);
1183 msiobj_release( &view
->hdr
);
1188 struct control_handler msi_dialog_handler
[] =
1190 { szText
, msi_dialog_text_control
},
1191 { szPushButton
, msi_dialog_button_control
},
1192 { szLine
, msi_dialog_line_control
},
1193 { szBitmap
, msi_dialog_bitmap_control
},
1194 { szCheckBox
, msi_dialog_checkbox_control
},
1195 { szScrollableText
, msi_dialog_scrolltext_control
},
1196 { szComboBox
, msi_dialog_combo_control
},
1197 { szEdit
, msi_dialog_edit_control
},
1198 { szMaskedEdit
, msi_dialog_maskedit_control
},
1199 { szPathEdit
, msi_dialog_pathedit_control
},
1200 { szRadioButtonGroup
, msi_dialog_radiogroup_control
},
1201 { szIcon
, msi_dialog_icon_control
},
1204 #define NUM_CONTROL_TYPES (sizeof msi_dialog_handler/sizeof msi_dialog_handler[0])
1206 static UINT
msi_dialog_create_controls( MSIRECORD
*rec
, LPVOID param
)
1208 msi_dialog
*dialog
= param
;
1209 LPCWSTR control_type
;
1212 /* find and call the function that can create this type of control */
1213 control_type
= MSI_RecordGetString( rec
, 3 );
1214 for( i
=0; i
<NUM_CONTROL_TYPES
; i
++ )
1215 if (!strcmpiW( msi_dialog_handler
[i
].control_type
, control_type
))
1217 if( i
!= NUM_CONTROL_TYPES
)
1218 msi_dialog_handler
[i
].func( dialog
, rec
);
1220 ERR("no handler for element type %s\n", debugstr_w(control_type
));
1222 return ERROR_SUCCESS
;
1225 static UINT
msi_dialog_fill_controls( msi_dialog
*dialog
)
1227 static const WCHAR query
[] = {
1228 'S','E','L','E','C','T',' ','*',' ',
1229 'F','R','O','M',' ','C','o','n','t','r','o','l',' ',
1230 'W','H','E','R','E',' ',
1231 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',0};
1233 MSIQUERY
*view
= NULL
;
1234 MSIPACKAGE
*package
= dialog
->package
;
1236 TRACE("%p %s\n", dialog
, debugstr_w(dialog
->name
) );
1238 /* query the Control table for all the elements of the control */
1239 r
= MSI_OpenQuery( package
->db
, &view
, query
, dialog
->name
);
1240 if( r
!= ERROR_SUCCESS
)
1242 ERR("query failed for dialog %s\n", debugstr_w(dialog
->name
));
1243 return ERROR_INVALID_PARAMETER
;
1246 r
= MSI_IterateRecords( view
, 0, msi_dialog_create_controls
, dialog
);
1247 msiobj_release( &view
->hdr
);
1252 static UINT
msi_dialog_set_control_condition( MSIRECORD
*rec
, LPVOID param
)
1254 static const WCHAR szHide
[] = { 'H','i','d','e',0 };
1255 static const WCHAR szShow
[] = { 'S','h','o','w',0 };
1256 static const WCHAR szDisable
[] = { 'D','i','s','a','b','l','e',0 };
1257 static const WCHAR szEnable
[] = { 'E','n','a','b','l','e',0 };
1258 msi_dialog
*dialog
= param
;
1259 msi_control
*control
;
1260 LPCWSTR name
, action
, condition
;
1263 name
= MSI_RecordGetString( rec
, 2 );
1264 action
= MSI_RecordGetString( rec
, 3 );
1265 condition
= MSI_RecordGetString( rec
, 4 );
1266 r
= MSI_EvaluateConditionW( dialog
->package
, condition
);
1267 control
= msi_dialog_find_control( dialog
, name
);
1270 TRACE("%s control %s\n", debugstr_w(action
), debugstr_w(name
));
1272 /* FIXME: case sensitive? */
1273 if(!lstrcmpW(action
, szHide
))
1274 ShowWindow(control
->hwnd
, SW_HIDE
);
1275 else if(!strcmpW(action
, szShow
))
1276 ShowWindow(control
->hwnd
, SW_SHOW
);
1277 else if(!strcmpW(action
, szDisable
))
1278 EnableWindow(control
->hwnd
, FALSE
);
1279 else if(!strcmpW(action
, szEnable
))
1280 EnableWindow(control
->hwnd
, TRUE
);
1282 FIXME("Unhandled action %s\n", debugstr_w(action
));
1285 return ERROR_SUCCESS
;
1288 static UINT
msi_dialog_evaluate_control_conditions( msi_dialog
*dialog
)
1290 static const WCHAR query
[] = {
1291 'S','E','L','E','C','T',' ','*',' ',
1292 'F','R','O','M',' ',
1293 'C','o','n','t','r','o','l','C','o','n','d','i','t','i','o','n',' ',
1294 'W','H','E','R','E',' ',
1295 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',0
1298 MSIQUERY
*view
= NULL
;
1299 MSIPACKAGE
*package
= dialog
->package
;
1301 TRACE("%p %s\n", dialog
, debugstr_w(dialog
->name
) );
1303 /* query the Control table for all the elements of the control */
1304 r
= MSI_OpenQuery( package
->db
, &view
, query
, dialog
->name
);
1305 if( r
!= ERROR_SUCCESS
)
1307 ERR("query failed for dialog %s\n", debugstr_w(dialog
->name
));
1308 return ERROR_INVALID_PARAMETER
;
1311 r
= MSI_IterateRecords( view
, 0, msi_dialog_set_control_condition
, dialog
);
1312 msiobj_release( &view
->hdr
);
1317 /* figure out the height of 10 point MS Sans Serif */
1318 static INT
msi_dialog_get_sans_serif_height( HWND hwnd
)
1320 static const WCHAR szSansSerif
[] = {
1321 'M','S',' ','S','a','n','s',' ','S','e','r','i','f',0 };
1326 HFONT hFont
, hOldFont
;
1329 hdc
= GetDC( hwnd
);
1332 memset( &lf
, 0, sizeof lf
);
1333 lf
.lfHeight
= MulDiv(10, GetDeviceCaps(hdc
, LOGPIXELSY
), 72);
1334 strcpyW( lf
.lfFaceName
, szSansSerif
);
1335 hFont
= CreateFontIndirectW(&lf
);
1338 hOldFont
= SelectObject( hdc
, hFont
);
1339 r
= GetTextMetricsW( hdc
, &tm
);
1341 height
= tm
.tmHeight
;
1342 SelectObject( hdc
, hOldFont
);
1343 DeleteObject( hFont
);
1345 ReleaseDC( hwnd
, hdc
);
1350 /* fetch the associated record from the Dialog table */
1351 static MSIRECORD
*msi_get_dialog_record( msi_dialog
*dialog
)
1353 static const WCHAR query
[] = {
1354 'S','E','L','E','C','T',' ','*',' ',
1355 'F','R','O','M',' ','D','i','a','l','o','g',' ',
1356 'W','H','E','R','E',' ',
1357 '`','D','i','a','l','o','g','`',' ','=',' ','\'','%','s','\'',0};
1358 MSIPACKAGE
*package
= dialog
->package
;
1359 MSIRECORD
*rec
= NULL
;
1361 TRACE("%p %s\n", dialog
, debugstr_w(dialog
->name
) );
1363 rec
= MSI_QueryGetRecord( package
->db
, query
, dialog
->name
);
1365 ERR("query failed for dialog %s\n", debugstr_w(dialog
->name
));
1370 static void msi_dialog_adjust_dialog_size( msi_dialog
*dialog
, LPSIZE sz
)
1375 /* turn the client size into the window rectangle */
1378 rect
.right
= msi_dialog_scale_unit( dialog
, sz
->cx
);
1379 rect
.bottom
= msi_dialog_scale_unit( dialog
, sz
->cy
);
1380 style
= GetWindowLongPtrW( dialog
->hwnd
, GWL_STYLE
);
1381 AdjustWindowRect( &rect
, style
, FALSE
);
1382 sz
->cx
= rect
.right
- rect
.left
;
1383 sz
->cy
= rect
.bottom
- rect
.top
;
1386 static BOOL
msi_control_set_next( msi_control
*control
, msi_control
*next
)
1388 return SetWindowPos( next
->hwnd
, control
->hwnd
, 0, 0, 0, 0,
1389 SWP_NOMOVE
| SWP_NOOWNERZORDER
| SWP_NOREDRAW
|
1390 SWP_NOREPOSITION
| SWP_NOSENDCHANGING
| SWP_NOSIZE
);
1393 static UINT
msi_dialog_set_tab_order( msi_dialog
*dialog
)
1395 msi_control
*control
, *tab_next
;
1397 for( control
= dialog
->control_list
; control
; control
= control
->next
)
1399 tab_next
= msi_dialog_find_control( dialog
, control
->tabnext
);
1402 msi_control_set_next( control
, tab_next
);
1405 return ERROR_SUCCESS
;
1408 static void msi_dialog_set_first_control( msi_dialog
* dialog
, LPCWSTR name
)
1410 msi_control
*control
;
1412 control
= msi_dialog_find_control( dialog
, name
);
1414 dialog
->hWndFocus
= control
->hwnd
;
1416 dialog
->hWndFocus
= NULL
;
1419 static LRESULT
msi_dialog_oncreate( HWND hwnd
, LPCREATESTRUCTW cs
)
1421 static const WCHAR df
[] = {
1422 'D','e','f','a','u','l','t','U','I','F','o','n','t',0 };
1423 msi_dialog
*dialog
= (msi_dialog
*) cs
->lpCreateParams
;
1424 MSIRECORD
*rec
= NULL
;
1426 LPWSTR title
= NULL
;
1429 TRACE("%p %p\n", dialog
, dialog
->package
);
1431 dialog
->hwnd
= hwnd
;
1432 SetWindowLongPtrW( hwnd
, GWLP_USERDATA
, (LONG_PTR
) dialog
);
1434 rec
= msi_get_dialog_record( dialog
);
1437 TRACE("No record found for dialog %s\n", debugstr_w(dialog
->name
));
1441 dialog
->scale
= msi_dialog_get_sans_serif_height(dialog
->hwnd
);
1443 size
.cx
= MSI_RecordGetInteger( rec
, 4 );
1444 size
.cy
= MSI_RecordGetInteger( rec
, 5 );
1445 msi_dialog_adjust_dialog_size( dialog
, &size
);
1447 dialog
->attributes
= MSI_RecordGetInteger( rec
, 6 );
1448 text
= MSI_RecordGetString( rec
, 7 );
1450 dialog
->default_font
= load_dynamic_property( dialog
->package
, df
, NULL
);
1452 deformat_string( dialog
->package
, text
, &title
);
1453 SetWindowTextW( hwnd
, title
);
1454 SetWindowPos( hwnd
, 0, 0, 0, size
.cx
, size
.cy
,
1455 SWP_NOMOVE
| SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_NOREDRAW
);
1457 HeapFree( GetProcessHeap(), 0, title
);
1459 msi_dialog_build_font_list( dialog
);
1460 msi_dialog_fill_controls( dialog
);
1461 msi_dialog_evaluate_control_conditions( dialog
);
1462 msi_dialog_set_tab_order( dialog
);
1463 msi_dialog_set_first_control( dialog
, MSI_RecordGetString( rec
, 8 ) );
1464 msiobj_release( &rec
->hdr
);
1469 static UINT
msi_dialog_send_event( msi_dialog
*dialog
, LPCWSTR event
, LPCWSTR arg
)
1471 LPWSTR event_fmt
= NULL
, arg_fmt
= NULL
;
1473 TRACE("Sending control event %s %s\n", debugstr_w(event
), debugstr_w(arg
));
1475 deformat_string( dialog
->package
, event
, &event_fmt
);
1476 deformat_string( dialog
->package
, arg
, &arg_fmt
);
1478 dialog
->event_handler( dialog
->package
, event_fmt
, arg_fmt
, dialog
);
1480 HeapFree( GetProcessHeap(), 0, event_fmt
);
1481 HeapFree( GetProcessHeap(), 0, arg_fmt
);
1483 return ERROR_SUCCESS
;
1486 static UINT
msi_dialog_set_property( msi_dialog
*dialog
, LPCWSTR event
, LPCWSTR arg
)
1488 static const WCHAR szNullArg
[] = { '{','}',0 };
1489 LPWSTR p
, prop
, arg_fmt
= NULL
;
1492 len
= strlenW(event
);
1493 prop
= HeapAlloc( GetProcessHeap(), 0, len
*sizeof(WCHAR
));
1494 strcpyW( prop
, &event
[1] );
1495 p
= strchrW( prop
, ']' );
1496 if( p
&& p
[1] == 0 )
1499 if( strcmpW( szNullArg
, arg
) )
1500 deformat_string( dialog
->package
, arg
, &arg_fmt
);
1501 MSI_SetPropertyW( dialog
->package
, prop
, arg_fmt
);
1504 ERR("Badly formatted property string - what happens?\n");
1505 HeapFree( GetProcessHeap(), 0, prop
);
1506 return ERROR_SUCCESS
;
1509 static UINT
msi_dialog_control_event( MSIRECORD
*rec
, LPVOID param
)
1511 msi_dialog
*dialog
= param
;
1512 LPCWSTR condition
, event
, arg
;
1515 condition
= MSI_RecordGetString( rec
, 5 );
1516 r
= MSI_EvaluateConditionW( dialog
->package
, condition
);
1519 event
= MSI_RecordGetString( rec
, 3 );
1520 arg
= MSI_RecordGetString( rec
, 4 );
1521 if( event
[0] == '[' )
1522 msi_dialog_set_property( dialog
, event
, arg
);
1524 msi_dialog_send_event( dialog
, event
, arg
);
1527 return ERROR_SUCCESS
;
1530 static UINT
msi_dialog_button_handler( msi_dialog
*dialog
,
1531 msi_control
*control
, WPARAM param
)
1533 static const WCHAR query
[] = {
1534 'S','E','L','E','C','T',' ','*',' ',
1535 'F','R','O','M',' ','C','o','n','t','r','o','l','E','v','e','n','t',' ',
1536 'W','H','E','R','E',' ',
1537 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',' ',
1539 '`','C','o','n','t','r','o','l','_','`',' ','=',' ','\'','%','s','\'',' ',
1540 'O','R','D','E','R',' ','B','Y',' ','`','O','r','d','e','r','i','n','g','`',0
1542 MSIQUERY
*view
= NULL
;
1545 if( HIWORD(param
) != BN_CLICKED
)
1546 return ERROR_SUCCESS
;
1548 r
= MSI_OpenQuery( dialog
->package
->db
, &view
, query
,
1549 dialog
->name
, control
->name
);
1550 if( r
!= ERROR_SUCCESS
)
1552 ERR("query failed\n");
1556 r
= MSI_IterateRecords( view
, 0, msi_dialog_control_event
, dialog
);
1557 msiobj_release( &view
->hdr
);
1562 static UINT
msi_dialog_get_checkbox_state( msi_dialog
*dialog
,
1563 msi_control
*control
)
1565 WCHAR state
[2] = { 0 };
1568 MSI_GetPropertyW( dialog
->package
, control
->property
, state
, &sz
);
1569 return state
[0] ? 1 : 0;
1572 static void msi_dialog_set_checkbox_state( msi_dialog
*dialog
,
1573 msi_control
*control
, UINT state
)
1575 static const WCHAR szState
[] = { '1', 0 };
1578 /* if uncheck then the property is set to NULL */
1581 MSI_SetPropertyW( dialog
->package
, control
->property
, NULL
);
1585 /* check for a custom state */
1586 if (control
->value
&& control
->value
[0])
1587 val
= control
->value
;
1591 MSI_SetPropertyW( dialog
->package
, control
->property
, val
);
1594 static void msi_dialog_checkbox_sync_state( msi_dialog
*dialog
,
1595 msi_control
*control
)
1599 state
= msi_dialog_get_checkbox_state( dialog
, control
);
1600 SendMessageW( control
->hwnd
, BM_SETCHECK
,
1601 state
? BST_CHECKED
: BST_UNCHECKED
, 0 );
1604 static UINT
msi_dialog_checkbox_handler( msi_dialog
*dialog
,
1605 msi_control
*control
, WPARAM param
)
1609 if( HIWORD(param
) != BN_CLICKED
)
1610 return ERROR_SUCCESS
;
1612 TRACE("clicked checkbox %s, set %s\n", debugstr_w(control
->name
),
1613 debugstr_w(control
->property
));
1615 state
= msi_dialog_get_checkbox_state( dialog
, control
);
1616 state
= state
? 0 : 1;
1617 msi_dialog_set_checkbox_state( dialog
, control
, state
);
1618 msi_dialog_checkbox_sync_state( dialog
, control
);
1620 return msi_dialog_button_handler( dialog
, control
, param
);
1623 static UINT
msi_dialog_edit_handler( msi_dialog
*dialog
,
1624 msi_control
*control
, WPARAM param
)
1629 if( HIWORD(param
) != EN_CHANGE
)
1630 return ERROR_SUCCESS
;
1632 TRACE("edit %s contents changed, set %s\n", debugstr_w(control
->name
),
1633 debugstr_w(control
->property
));
1636 buf
= HeapAlloc( GetProcessHeap(), 0, sz
*sizeof(WCHAR
) );
1639 r
= GetWindowTextW( control
->hwnd
, buf
, sz
);
1643 buf
= HeapReAlloc( GetProcessHeap(), 0, buf
, sz
*sizeof(WCHAR
) );
1646 MSI_SetPropertyW( dialog
->package
, control
->property
, buf
);
1648 HeapFree( GetProcessHeap(), 0, buf
);
1650 return ERROR_SUCCESS
;
1653 static UINT
msi_dialog_radiogroup_handler( msi_dialog
*dialog
,
1654 msi_control
*control
, WPARAM param
)
1656 if( HIWORD(param
) != BN_CLICKED
)
1657 return ERROR_SUCCESS
;
1659 TRACE("clicked radio button %s, set %s\n", debugstr_w(control
->name
),
1660 debugstr_w(control
->property
));
1662 MSI_SetPropertyW( dialog
->package
, control
->property
, control
->name
);
1664 return msi_dialog_button_handler( dialog
, control
, param
);
1667 static LRESULT
msi_dialog_oncommand( msi_dialog
*dialog
, WPARAM param
, HWND hwnd
)
1669 msi_control
*control
;
1671 TRACE("%p %p %08x\n", dialog
, hwnd
, param
);
1673 control
= msi_dialog_find_control_by_hwnd( dialog
, hwnd
);
1676 if( control
->handler
)
1678 control
->handler( dialog
, control
, param
);
1679 msi_dialog_evaluate_control_conditions( dialog
);
1683 ERR("button click from nowhere\n");
1687 static void msi_dialog_setfocus( msi_dialog
*dialog
)
1689 HWND hwnd
= dialog
->hWndFocus
;
1691 hwnd
= GetNextDlgTabItem( dialog
->hwnd
, hwnd
, TRUE
);
1692 hwnd
= GetNextDlgTabItem( dialog
->hwnd
, hwnd
, FALSE
);
1694 dialog
->hWndFocus
= hwnd
;
1697 static LRESULT WINAPI
MSIDialog_WndProc( HWND hwnd
, UINT msg
,
1698 WPARAM wParam
, LPARAM lParam
)
1700 msi_dialog
*dialog
= (LPVOID
) GetWindowLongPtrW( hwnd
, GWLP_USERDATA
);
1702 TRACE("0x%04x\n", msg
);
1707 return msi_dialog_oncreate( hwnd
, (LPCREATESTRUCTW
)lParam
);
1710 return msi_dialog_oncommand( dialog
, wParam
, (HWND
)lParam
);
1713 if( LOWORD(wParam
) == WA_INACTIVE
)
1714 dialog
->hWndFocus
= GetFocus();
1716 msi_dialog_setfocus( dialog
);
1720 msi_dialog_setfocus( dialog
);
1723 /* bounce back to our subclassed static control */
1724 case WM_CTLCOLORSTATIC
:
1725 return SendMessageW( (HWND
) lParam
, WM_CTLCOLORSTATIC
, wParam
, lParam
);
1728 dialog
->hwnd
= NULL
;
1731 return DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
1734 static LRESULT WINAPI
MSIRadioGroup_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1736 WNDPROC oldproc
= (WNDPROC
) GetPropW(hWnd
, szButtonData
);
1738 TRACE("hWnd %p msg %04x wParam 0x%08x lParam 0x%08lx\n", hWnd
, msg
, wParam
, lParam
);
1740 if (msg
== WM_COMMAND
) /* Forward notifications to dialog */
1741 SendMessageW(GetParent(hWnd
), msg
, wParam
, lParam
);
1743 return CallWindowProcW(oldproc
, hWnd
, msg
, wParam
, lParam
);
1746 static LRESULT WINAPI
MSIHiddenWindowProc( HWND hwnd
, UINT msg
,
1747 WPARAM wParam
, LPARAM lParam
)
1749 msi_dialog
*dialog
= (msi_dialog
*) lParam
;
1751 TRACE("%d %p\n", msg
, dialog
);
1755 case WM_MSI_DIALOG_CREATE
:
1756 return msi_dialog_run_message_loop( dialog
);
1757 case WM_MSI_DIALOG_DESTROY
:
1758 msi_dialog_destroy( dialog
);
1761 return DefWindowProcW( hwnd
, msg
, wParam
, lParam
);
1764 /* functions that interface to other modules within MSI */
1766 msi_dialog
*msi_dialog_create( MSIPACKAGE
* package
, LPCWSTR szDialogName
,
1767 msi_dialog_event_handler event_handler
)
1769 MSIRECORD
*rec
= NULL
;
1772 TRACE("%p %s\n", package
, debugstr_w(szDialogName
));
1774 /* allocate the structure for the dialog to use */
1775 dialog
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
,
1776 sizeof *dialog
+ sizeof(WCHAR
)*strlenW(szDialogName
) );
1779 strcpyW( dialog
->name
, szDialogName
);
1780 msiobj_addref( &package
->hdr
);
1781 dialog
->package
= package
;
1782 dialog
->event_handler
= event_handler
;
1783 dialog
->finished
= 0;
1785 /* verify that the dialog exists */
1786 rec
= msi_get_dialog_record( dialog
);
1789 HeapFree( GetProcessHeap(), 0, dialog
);
1792 dialog
->attributes
= MSI_RecordGetInteger( rec
, 6 );
1793 msiobj_release( &rec
->hdr
);
1798 static void msi_process_pending_messages( HWND hdlg
)
1802 while( PeekMessageW( &msg
, 0, 0, 0, PM_REMOVE
) )
1804 if( hdlg
&& IsDialogMessageW( hdlg
, &msg
))
1806 TranslateMessage( &msg
);
1807 DispatchMessageW( &msg
);
1811 void msi_dialog_end_dialog( msi_dialog
*dialog
)
1813 TRACE("%p\n", dialog
);
1814 dialog
->finished
= 1;
1815 PostMessageW(dialog
->hwnd
, WM_NULL
, 0, 0);
1818 void msi_dialog_check_messages( HANDLE handle
)
1822 /* in threads other than the UI thread, block */
1823 if( uiThreadId
!= GetCurrentThreadId() )
1826 WaitForSingleObject( handle
, INFINITE
);
1830 /* there's two choices for the UI thread */
1833 msi_process_pending_messages( NULL
);
1839 * block here until somebody creates a new dialog or
1840 * the handle we're waiting on becomes ready
1842 r
= MsgWaitForMultipleObjects( 1, &handle
, 0, INFINITE
, QS_ALLINPUT
);
1843 if( r
== WAIT_OBJECT_0
)
1848 UINT
msi_dialog_run_message_loop( msi_dialog
*dialog
)
1852 if( !(dialog
->attributes
& msidbDialogAttributesVisible
) )
1853 return ERROR_SUCCESS
;
1855 if( uiThreadId
!= GetCurrentThreadId() )
1856 return SendMessageW( hMsiHiddenWindow
, WM_MSI_DIALOG_CREATE
, 0, (LPARAM
) dialog
);
1858 /* create the dialog window, don't show it yet */
1859 hwnd
= CreateWindowW( szMsiDialogClass
, dialog
->name
, WS_OVERLAPPEDWINDOW
,
1860 CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
,
1861 NULL
, NULL
, NULL
, dialog
);
1864 ERR("Failed to create dialog %s\n", debugstr_w( dialog
->name
));
1865 return ERROR_FUNCTION_FAILED
;
1868 ShowWindow( hwnd
, SW_SHOW
);
1869 UpdateWindow( hwnd
);
1871 if( dialog
->attributes
& msidbDialogAttributesModal
)
1873 while( !dialog
->finished
)
1875 MsgWaitForMultipleObjects( 0, NULL
, 0, INFINITE
, QS_ALLEVENTS
);
1876 msi_process_pending_messages( dialog
->hwnd
);
1880 return ERROR_IO_PENDING
;
1882 return ERROR_SUCCESS
;
1885 void msi_dialog_do_preview( msi_dialog
*dialog
)
1888 dialog
->attributes
|= msidbDialogAttributesVisible
;
1889 dialog
->attributes
&= ~msidbDialogAttributesModal
;
1890 msi_dialog_run_message_loop( dialog
);
1893 void msi_dialog_destroy( msi_dialog
*dialog
)
1895 if( uiThreadId
!= GetCurrentThreadId() )
1897 SendMessageW( hMsiHiddenWindow
, WM_MSI_DIALOG_DESTROY
, 0, (LPARAM
) dialog
);
1902 ShowWindow( dialog
->hwnd
, SW_HIDE
);
1904 /* destroy the list of controls */
1905 while( dialog
->control_list
)
1907 msi_control
*t
= dialog
->control_list
;
1908 dialog
->control_list
= t
->next
;
1909 /* leave dialog->hwnd - destroying parent destroys child windows */
1910 HeapFree( GetProcessHeap(), 0, t
->property
);
1911 HeapFree( GetProcessHeap(), 0, t
->value
);
1913 DeleteObject( t
->hBitmap
);
1915 DestroyIcon( t
->hIcon
);
1916 HeapFree( GetProcessHeap(), 0, t
->tabnext
);
1917 HeapFree( GetProcessHeap(), 0, t
);
1920 /* destroy the list of fonts */
1921 while( dialog
->font_list
)
1923 msi_font
*t
= dialog
->font_list
;
1924 dialog
->font_list
= t
->next
;
1925 DeleteObject( t
->hfont
);
1926 HeapFree( GetProcessHeap(), 0, t
);
1928 HeapFree( GetProcessHeap(), 0, dialog
->default_font
);
1931 DestroyWindow( dialog
->hwnd
);
1933 msiobj_release( &dialog
->package
->hdr
);
1934 dialog
->package
= NULL
;
1935 HeapFree( GetProcessHeap(), 0, dialog
);
1938 BOOL
msi_dialog_register_class( void )
1942 ZeroMemory( &cls
, sizeof cls
);
1943 cls
.lpfnWndProc
= MSIDialog_WndProc
;
1944 cls
.hInstance
= NULL
;
1945 cls
.hIcon
= LoadIconW(0, (LPWSTR
)IDI_APPLICATION
);
1946 cls
.hCursor
= LoadCursorW(0, (LPWSTR
)IDC_ARROW
);
1947 cls
.hbrBackground
= (HBRUSH
)(COLOR_WINDOW
);
1948 cls
.lpszMenuName
= NULL
;
1949 cls
.lpszClassName
= szMsiDialogClass
;
1951 if( !RegisterClassW( &cls
) )
1954 cls
.lpfnWndProc
= MSIHiddenWindowProc
;
1955 cls
.lpszClassName
= szMsiHiddenWindow
;
1957 if( !RegisterClassW( &cls
) )
1960 uiThreadId
= GetCurrentThreadId();
1962 hMsiHiddenWindow
= CreateWindowW( szMsiHiddenWindow
, NULL
, WS_OVERLAPPED
,
1963 0, 0, 100, 100, NULL
, NULL
, NULL
, NULL
);
1964 if( !hMsiHiddenWindow
)
1967 hRichedit
= LoadLibraryA("riched20");
1972 void msi_dialog_unregister_class( void )
1974 DestroyWindow( hMsiHiddenWindow
);
1975 UnregisterClassW( szMsiDialogClass
, NULL
);
1977 FreeLibrary( hRichedit
);