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 /* called from the Control Event subscription code */
340 void msi_dialog_handle_event( msi_dialog
* dialog
, LPCWSTR control
,
341 LPCWSTR attribute
, MSIRECORD
*rec
)
346 ctrl
= msi_dialog_find_control( dialog
, control
);
349 if( lstrcmpW(attribute
, szText
) )
351 text
= MSI_RecordGetString( rec
, 1 );
352 SetWindowTextW( ctrl
->hwnd
, text
);
353 msi_dialog_check_messages( NULL
);
356 static void msi_dialog_map_events(msi_dialog
* dialog
, LPCWSTR control
)
358 static WCHAR Query
[] = {
359 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
360 '`','E','v','e','n','t','M','a','p','p','i','n','g','`',' ',
361 'W','H','E','R','E',' ',
362 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',' ',
364 '`','C','o','n','t','r','o','l','_','`',' ','=',' ','\'','%','s','\'',0
367 LPCWSTR event
, attribute
;
369 row
= MSI_QueryGetRecord( dialog
->package
->db
, Query
, dialog
->name
, control
);
373 event
= MSI_RecordGetString( row
, 3 );
374 attribute
= MSI_RecordGetString( row
, 4 );
375 ControlEvent_SubscribeToEvent( dialog
->package
, event
, control
, attribute
);
376 msiobj_release( &row
->hdr
);
379 /* everything except radio buttons */
380 static msi_control
*msi_dialog_add_control( msi_dialog
*dialog
,
381 MSIRECORD
*rec
, LPCWSTR szCls
, DWORD style
)
386 name
= MSI_RecordGetString( rec
, 2 );
387 attributes
= MSI_RecordGetInteger( rec
, 8 );
388 text
= MSI_RecordGetString( rec
, 10 );
389 if( attributes
& msidbControlAttributesVisible
)
391 if( ~attributes
& msidbControlAttributesEnabled
)
392 style
|= WS_DISABLED
;
394 msi_dialog_map_events(dialog
, name
);
396 return msi_dialog_create_window( dialog
, rec
, szCls
, name
, text
,
397 style
, dialog
->hwnd
);
407 * we don't erase our own background,
408 * so we have to make sure that the parent window redraws first
410 static void msi_text_on_settext( HWND hWnd
)
415 hParent
= GetParent( hWnd
);
416 GetWindowRect( hWnd
, &rc
);
417 MapWindowPoints( NULL
, hParent
, (LPPOINT
) &rc
, 2 );
418 InvalidateRect( hParent
, &rc
, TRUE
);
421 static LRESULT WINAPI
422 MSIText_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
424 struct msi_text_info
*info
;
427 TRACE("%p %04x %08x %08lx\n", hWnd
, msg
, wParam
, lParam
);
429 info
= GetPropW(hWnd
, szButtonData
);
431 if( msg
== WM_CTLCOLORSTATIC
&&
432 ( info
->attributes
& msidbControlAttributesTransparent
) )
434 SetBkMode( (HDC
)wParam
, TRANSPARENT
);
435 return (LRESULT
) GetStockObject(NULL_BRUSH
);
438 r
= CallWindowProcW(info
->oldproc
, hWnd
, msg
, wParam
, lParam
);
443 msi_text_on_settext( hWnd
);
446 HeapFree( GetProcessHeap(), 0, info
);
447 RemovePropW( hWnd
, szButtonData
);
454 static UINT
msi_dialog_text_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
456 msi_control
*control
;
457 struct msi_text_info
*info
;
459 TRACE("%p %p\n", dialog
, rec
);
461 control
= msi_dialog_add_control( dialog
, rec
, szStatic
, SS_LEFT
| WS_GROUP
);
463 return ERROR_FUNCTION_FAILED
;
465 info
= HeapAlloc( GetProcessHeap(), 0, sizeof *info
);
467 return ERROR_SUCCESS
;
469 info
->attributes
= MSI_RecordGetInteger( rec
, 8 );
470 if( info
->attributes
& msidbControlAttributesTransparent
)
471 SetWindowLongPtrW( control
->hwnd
, GWL_EXSTYLE
, WS_EX_TRANSPARENT
);
473 info
->oldproc
= (WNDPROC
) SetWindowLongPtrW( control
->hwnd
, GWLP_WNDPROC
,
474 (LONG_PTR
)MSIText_WndProc
);
475 SetPropW( control
->hwnd
, szButtonData
, info
);
477 return ERROR_SUCCESS
;
480 static UINT
msi_dialog_button_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
482 msi_control
*control
;
484 TRACE("%p %p\n", dialog
, rec
);
486 control
= msi_dialog_add_control( dialog
, rec
, szButton
, WS_TABSTOP
);
487 control
->handler
= msi_dialog_button_handler
;
489 return ERROR_SUCCESS
;
492 static LPWSTR
msi_get_checkbox_value( msi_dialog
*dialog
, LPCWSTR prop
)
494 const static WCHAR query
[] = {
495 'S','E','L','E','C','T',' ','*',' ',
496 'F','R','O','M',' ','`','C','h','e','c','k','B','o','x',' ','`',
497 'W','H','E','R','E',' ',
498 '`','P','r','o','p','e','r','t','y','`',' ','=',' ',
501 MSIRECORD
*rec
= NULL
;
505 /* find if there is a value associated with the checkbox */
506 rec
= MSI_QueryGetRecord( dialog
->package
->db
, query
, prop
);
510 val
= MSI_RecordGetString( rec
, 2 );
513 deformat_string( dialog
->package
, val
, &ret
);
516 HeapFree( GetProcessHeap(), 0, ret
);
520 msiobj_release( &rec
->hdr
);
524 ret
= load_dynamic_property(dialog
->package
, prop
, NULL
);
527 HeapFree( GetProcessHeap(), 0, ret
);
534 static UINT
msi_dialog_checkbox_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
536 msi_control
*control
;
539 TRACE("%p %p\n", dialog
, rec
);
541 control
= msi_dialog_add_control( dialog
, rec
, szButton
,
542 BS_CHECKBOX
| BS_MULTILINE
| WS_TABSTOP
);
543 control
->handler
= msi_dialog_checkbox_handler
;
544 prop
= MSI_RecordGetString( rec
, 9 );
547 control
->property
= strdupW( prop
);
548 control
->value
= msi_get_checkbox_value( dialog
, prop
);
549 TRACE("control %s value %s\n", debugstr_w(control
->property
),
550 debugstr_w(control
->value
));
552 msi_dialog_checkbox_sync_state( dialog
, control
);
554 return ERROR_SUCCESS
;
557 static UINT
msi_dialog_line_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
559 TRACE("%p %p\n", dialog
, rec
);
561 msi_dialog_add_control( dialog
, rec
, szStatic
, SS_ETCHEDHORZ
| SS_SUNKEN
);
562 return ERROR_SUCCESS
;
565 struct msi_streamin_info
572 static DWORD CALLBACK
573 msi_richedit_stream_in( DWORD_PTR arg
, LPBYTE buffer
, LONG count
, LONG
*pcb
)
575 struct msi_streamin_info
*info
= (struct msi_streamin_info
*) arg
;
577 if( (count
+ info
->offset
) > info
->length
)
578 count
= info
->length
- info
->offset
;
579 memcpy( buffer
, &info
->string
[ info
->offset
], count
);
581 info
->offset
+= count
;
583 TRACE("%ld/%ld\n", info
->offset
, info
->length
);
588 static UINT
msi_dialog_scrolltext_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
590 const static WCHAR szRichEdit20W
[] = {
591 'R','i','c','h','E','d','i','t','2','0','W',0
593 struct msi_streamin_info info
;
594 msi_control
*control
;
599 style
= WS_BORDER
| ES_MULTILINE
| WS_VSCROLL
|
600 ES_READONLY
| ES_AUTOVSCROLL
| WS_TABSTOP
;
601 control
= msi_dialog_add_control( dialog
, rec
, szRichEdit20W
, style
);
603 text
= MSI_RecordGetString( rec
, 10 );
604 info
.string
= strdupWtoA( text
);
606 info
.length
= lstrlenA( info
.string
) + 1;
608 es
.dwCookie
= (DWORD_PTR
) &info
;
610 es
.pfnCallback
= msi_richedit_stream_in
;
612 SendMessageW( control
->hwnd
, EM_STREAMIN
, SF_RTF
, (LPARAM
) &es
);
614 HeapFree( GetProcessHeap(), 0, info
.string
);
616 return ERROR_SUCCESS
;
619 static MSIRECORD
*msi_get_binary_record( MSIDATABASE
*db
, LPCWSTR name
)
621 const static WCHAR query
[] = {
622 's','e','l','e','c','t',' ','*',' ',
623 'f','r','o','m',' ','B','i','n','a','r','y',' ',
624 'w','h','e','r','e',' ',
625 '`','N','a','m','e','`',' ','=',' ','\'','%','s','\'',0
628 return MSI_QueryGetRecord( db
, query
, name
);
631 static LPWSTR
msi_create_tmp_path(void)
635 static const WCHAR prefix
[] = { 'm','s','i',0 };
638 r
= GetTempPathW( MAX_PATH
, tmp
);
641 len
= lstrlenW( tmp
) + 20;
642 path
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof (WCHAR
) );
645 r
= GetTempFileNameW( tmp
, prefix
, 0, path
);
648 HeapFree( GetProcessHeap(), 0, path
);
655 static HANDLE
msi_load_image( MSIDATABASE
*db
, LPCWSTR name
, UINT type
,
656 UINT cx
, UINT cy
, UINT flags
)
658 MSIRECORD
*rec
= NULL
;
659 HANDLE himage
= NULL
;
663 TRACE("%p %s %u %u %08x\n", db
, debugstr_w(name
), cx
, cy
, flags
);
665 tmp
= msi_create_tmp_path();
669 rec
= msi_get_binary_record( db
, name
);
672 r
= MSI_RecordStreamToFile( rec
, 2, tmp
);
673 if( r
== ERROR_SUCCESS
)
675 himage
= LoadImageW( 0, tmp
, type
, cx
, cy
, flags
);
678 msiobj_release( &rec
->hdr
);
681 HeapFree( GetProcessHeap(), 0, tmp
);
685 static UINT
msi_dialog_bitmap_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
687 UINT cx
, cy
, flags
, style
, attributes
;
688 msi_control
*control
;
691 flags
= LR_LOADFROMFILE
;
692 style
= SS_BITMAP
| SS_LEFT
| WS_GROUP
;
694 attributes
= MSI_RecordGetInteger( rec
, 8 );
695 if( attributes
& msidbControlAttributesFixedSize
)
697 flags
|= LR_DEFAULTSIZE
;
699 style
|= SS_CENTERIMAGE
;
701 control
= msi_dialog_add_control( dialog
, rec
, szStatic
, style
);
702 text
= MSI_RecordGetString( rec
, 10 );
703 cx
= MSI_RecordGetInteger( rec
, 6 );
704 cy
= MSI_RecordGetInteger( rec
, 7 );
705 cx
= msi_dialog_scale_unit( dialog
, cx
);
706 cy
= msi_dialog_scale_unit( dialog
, cy
);
708 control
->hBitmap
= msi_load_image( dialog
->package
->db
, text
,
709 IMAGE_BITMAP
, cx
, cy
, flags
);
710 if( control
->hBitmap
)
711 SendMessageW( control
->hwnd
, STM_SETIMAGE
,
712 IMAGE_BITMAP
, (LPARAM
) control
->hBitmap
);
714 ERR("Failed to load bitmap %s\n", debugstr_w(text
));
716 return ERROR_SUCCESS
;
719 static UINT
msi_dialog_icon_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
721 msi_control
*control
;
722 DWORD attributes
, cx
= 0, cy
= 0, flags
;
727 control
= msi_dialog_add_control( dialog
, rec
, szStatic
,
728 SS_ICON
| SS_CENTERIMAGE
| WS_GROUP
);
730 flags
= LR_LOADFROMFILE
| LR_DEFAULTSIZE
;
731 attributes
= MSI_RecordGetInteger( rec
, 8 );
732 if( attributes
& msidbControlAttributesFixedSize
)
734 flags
&= ~LR_DEFAULTSIZE
;
735 if( attributes
& msidbControlAttributesIconSize16
)
740 if( attributes
& msidbControlAttributesIconSize32
)
745 /* msidbControlAttributesIconSize48 handled by above logic */
748 text
= MSI_RecordGetString( rec
, 10 );
749 control
->hIcon
= msi_load_image( dialog
->package
->db
, text
,
750 IMAGE_ICON
, cx
, cy
, flags
);
752 SendMessageW( control
->hwnd
, STM_SETICON
, (WPARAM
) control
->hIcon
, 0 );
754 ERR("Failed to load bitmap %s\n", debugstr_w(text
));
755 return ERROR_SUCCESS
;
758 static UINT
msi_dialog_combo_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
760 static const WCHAR szCombo
[] = { 'C','O','M','B','O','B','O','X',0 };
762 msi_dialog_add_control( dialog
, rec
, szCombo
,
763 SS_BITMAP
| SS_LEFT
| SS_CENTERIMAGE
);
764 return ERROR_SUCCESS
;
767 static UINT
msi_dialog_edit_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
769 msi_control
*control
;
773 control
= msi_dialog_add_control( dialog
, rec
, szEdit
,
774 WS_BORDER
| WS_TABSTOP
);
775 control
->handler
= msi_dialog_edit_handler
;
776 prop
= MSI_RecordGetString( rec
, 9 );
778 control
->property
= strdupW( prop
);
779 val
= load_dynamic_property( dialog
->package
, control
->property
, NULL
);
780 SetWindowTextW( control
->hwnd
, val
);
781 HeapFree( GetProcessHeap(), 0, val
);
782 return ERROR_SUCCESS
;
785 /******************** Masked Edit ********************************************/
787 #define MASK_MAX_GROUPS 10
789 struct msi_mask_group
797 struct msi_maskedit_info
805 struct msi_mask_group group
[MASK_MAX_GROUPS
];
808 static void msi_mask_control_change( struct msi_maskedit_info
*info
)
813 val
= HeapAlloc( GetProcessHeap(), 0, (info
->num_chars
+1)*sizeof(WCHAR
) );
814 for( i
=0, n
=0; i
<info
->num_groups
; i
++ )
816 if( (info
->group
[i
].len
+ n
) > info
->num_chars
)
818 ERR("can't fit control %d text into template\n",i
);
821 r
= GetWindowTextW( info
->group
[i
].hwnd
, &val
[n
], info
->group
[i
].len
+1 );
822 if( r
!= info
->group
[i
].len
)
827 TRACE("%d/%d controls were good\n", i
, info
->num_groups
);
829 if( i
== info
->num_groups
)
831 TRACE("Set property %s to %s\n",
832 debugstr_w(info
->prop
), debugstr_w(val
) );
833 CharUpperBuffW( val
, info
->num_chars
);
834 MSI_SetPropertyW( info
->dialog
->package
, info
->prop
, val
);
835 msi_dialog_evaluate_control_conditions( info
->dialog
);
837 HeapFree( GetProcessHeap(), 0, val
);
840 /* now move to the next control if necessary */
841 static VOID
msi_mask_next_control( struct msi_maskedit_info
*info
, HWND hWnd
)
846 for( i
=0; i
<info
->num_groups
; i
++ )
847 if( info
->group
[i
].hwnd
== hWnd
)
850 /* don't move from the last control */
851 if( i
>= (info
->num_groups
-1) )
854 len
= SendMessageW( hWnd
, WM_GETTEXTLENGTH
, 0, 0 );
855 if( len
< info
->group
[i
].len
)
858 hWndNext
= GetNextDlgTabItem( GetParent( hWnd
), hWnd
, FALSE
);
859 SetFocus( hWndNext
);
862 static LRESULT WINAPI
863 MSIMaskedEdit_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
865 struct msi_maskedit_info
*info
;
868 TRACE("%p %04x %08x %08lx\n", hWnd
, msg
, wParam
, lParam
);
870 info
= GetPropW(hWnd
, szButtonData
);
872 r
= CallWindowProcW(info
->oldproc
, hWnd
, msg
, wParam
, lParam
);
877 if (HIWORD(wParam
) == EN_CHANGE
)
879 msi_mask_control_change( info
);
880 msi_mask_next_control( info
, (HWND
) lParam
);
884 HeapFree( GetProcessHeap(), 0, info
->prop
);
885 HeapFree( GetProcessHeap(), 0, info
);
886 RemovePropW( hWnd
, szButtonData
);
893 /* fish the various bits of the property out and put them in the control */
895 msi_maskedit_set_text( struct msi_maskedit_info
*info
, LPCWSTR text
)
901 for( i
= 0; i
< info
->num_groups
; i
++ )
903 if( info
->group
[i
].len
< lstrlenW( p
) )
905 LPWSTR chunk
= strdupW( p
);
906 chunk
[ info
->group
[i
].len
] = 0;
907 SetWindowTextW( info
->group
[i
].hwnd
, chunk
);
908 HeapFree( GetProcessHeap(), 0, chunk
);
912 SetWindowTextW( info
->group
[i
].hwnd
, p
);
915 p
+= info
->group
[i
].len
;
919 static struct msi_maskedit_info
* msi_dialog_parse_groups( LPCWSTR mask
)
921 struct msi_maskedit_info
* info
= NULL
;
922 int i
= 0, n
= 0, total
= 0;
925 TRACE("masked control, template %s\n", debugstr_w(mask
));
930 p
= strchrW(mask
, '<');
934 info
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof *info
);
939 for( i
=0; i
<MASK_MAX_GROUPS
; i
++ )
941 /* stop at the end of the string */
942 if( p
[0] == 0 || p
[0] == '>' )
945 /* count the number of the same identifier */
946 for( n
=0; p
[n
] == p
[0]; n
++ )
948 info
->group
[i
].ofs
= total
;
949 info
->group
[i
].type
= p
[0];
953 total
++; /* an extra not part of the group */
955 info
->group
[i
].len
= n
;
960 TRACE("%d characters in %d groups\n", total
, info
->num_groups
);
961 if( i
== MASK_MAX_GROUPS
)
962 ERR("too many groups in PIDTemplate %s\n", debugstr_w(mask
));
964 info
->num_chars
= total
;
965 info
->num_groups
= i
;
971 msi_maskedit_create_children( struct msi_maskedit_info
*info
)
973 DWORD width
, height
, style
, wx
, ww
;
974 LPCWSTR text
, font
= NULL
;
979 style
= WS_CHILD
| WS_BORDER
| WS_VISIBLE
| WS_TABSTOP
;
981 GetClientRect( info
->hwnd
, &rect
);
983 width
= rect
.right
- rect
.left
;
984 height
= rect
.bottom
- rect
.top
;
987 font
= msi_dialog_get_style( &text
);
989 for( i
= 0; i
< info
->num_groups
; i
++ )
991 wx
= (info
->group
[i
].ofs
* width
) / info
->num_chars
;
992 ww
= (info
->group
[i
].len
* width
) / info
->num_chars
;
994 hwnd
= CreateWindowW( szEdit
, NULL
, style
, wx
, 0, ww
, height
,
995 info
->hwnd
, NULL
, NULL
, NULL
);
998 ERR("failed to create mask edit sub window\n");
1002 SendMessageW( hwnd
, EM_LIMITTEXT
, info
->group
[i
].len
, 0 );
1004 msi_dialog_set_font( info
->dialog
, hwnd
,
1005 font
? font
: info
->dialog
->default_font
);
1006 info
->group
[i
].hwnd
= hwnd
;
1010 /* office 2003 uses "73931<````=````=````=````=`````>@@@@@" */
1011 static UINT
msi_dialog_maskedit_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1013 const static WCHAR pidt
[] = {'P','I','D','T','e','m','p','l','a','t','e',0};
1014 LPWSTR mask
= NULL
, title
= NULL
, val
= NULL
;
1015 struct msi_maskedit_info
*info
= NULL
;
1016 UINT ret
= ERROR_SUCCESS
;
1017 msi_control
*control
;
1020 mask
= load_dynamic_property( dialog
->package
, pidt
, NULL
);
1023 ERR("PIDTemplate is empty\n");
1027 info
= msi_dialog_parse_groups( mask
);
1030 ERR("template %s is invalid\n", debugstr_w(mask
));
1034 info
->dialog
= dialog
;
1036 control
= msi_dialog_add_control( dialog
, rec
, szStatic
,
1037 SS_OWNERDRAW
| WS_GROUP
| WS_VISIBLE
);
1040 ERR("Failed to create maskedit container\n");
1041 ret
= ERROR_FUNCTION_FAILED
;
1044 SetWindowLongPtrW( control
->hwnd
, GWL_EXSTYLE
, WS_EX_CONTROLPARENT
);
1046 info
->hwnd
= control
->hwnd
;
1048 /* subclass the static control */
1049 info
->oldproc
= (WNDPROC
) SetWindowLongPtrW( info
->hwnd
, GWLP_WNDPROC
,
1050 (LONG_PTR
)MSIMaskedEdit_WndProc
);
1051 SetPropW( control
->hwnd
, szButtonData
, info
);
1053 prop
= MSI_RecordGetString( rec
, 9 );
1055 info
->prop
= strdupW( prop
);
1057 msi_maskedit_create_children( info
);
1061 val
= load_dynamic_property( dialog
->package
, prop
, NULL
);
1064 msi_maskedit_set_text( info
, val
);
1065 HeapFree( GetProcessHeap(), 0, val
);
1070 if( ret
!= ERROR_SUCCESS
)
1071 HeapFree( GetProcessHeap(), 0, info
);
1072 HeapFree( GetProcessHeap(), 0, title
);
1073 HeapFree( GetProcessHeap(), 0, mask
);
1077 /******************** Path Edit ********************************************/
1079 static UINT
msi_dialog_pathedit_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1081 FIXME("not implemented properly\n");
1082 return msi_dialog_edit_control( dialog
, rec
);
1085 /* radio buttons are a bit different from normal controls */
1086 static UINT
msi_dialog_create_radiobutton( MSIRECORD
*rec
, LPVOID param
)
1088 radio_button_group_descr
*group
= (radio_button_group_descr
*)param
;
1089 msi_dialog
*dialog
= group
->dialog
;
1090 msi_control
*control
;
1091 LPCWSTR prop
, text
, name
;
1093 DWORD attributes
= group
->attributes
;
1095 style
= WS_CHILD
| BS_AUTORADIOBUTTON
| BS_MULTILINE
| WS_TABSTOP
;
1096 name
= MSI_RecordGetString( rec
, 3 );
1097 text
= MSI_RecordGetString( rec
, 8 );
1098 if( attributes
& 1 )
1099 style
|= WS_VISIBLE
;
1100 if( ~attributes
& 2 )
1101 style
|= WS_DISABLED
;
1103 control
= msi_dialog_create_window( dialog
, rec
, szButton
, name
, text
,
1104 style
, group
->parent
->hwnd
);
1105 control
->handler
= msi_dialog_radiogroup_handler
;
1107 prop
= MSI_RecordGetString( rec
, 1 );
1109 control
->property
= strdupW( prop
);
1111 return ERROR_SUCCESS
;
1114 static UINT
msi_dialog_radiogroup_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1116 static const WCHAR query
[] = {
1117 'S','E','L','E','C','T',' ','*',' ',
1118 'F','R','O','M',' ','R','a','d','i','o','B','u','t','t','o','n',' ',
1119 'W','H','E','R','E',' ',
1120 '`','P','r','o','p','e','r','t','y','`',' ','=',' ','\'','%','s','\'',0};
1123 msi_control
*control
;
1124 MSIQUERY
*view
= NULL
;
1125 radio_button_group_descr group
;
1126 MSIPACKAGE
*package
= dialog
->package
;
1129 prop
= MSI_RecordGetString( rec
, 9 );
1131 TRACE("%p %p %s\n", dialog
, rec
, debugstr_w( prop
));
1133 /* Create parent group box to hold radio buttons */
1134 control
= msi_dialog_add_control( dialog
, rec
, szButton
, BS_OWNERDRAW
|WS_GROUP
);
1136 return ERROR_FUNCTION_FAILED
;
1138 oldproc
= (WNDPROC
) SetWindowLongPtrW( control
->hwnd
, GWLP_WNDPROC
,
1139 (LONG_PTR
)MSIRadioGroup_WndProc
);
1140 SetPropW(control
->hwnd
, szButtonData
, oldproc
);
1141 SetWindowLongPtrW( control
->hwnd
, GWL_EXSTYLE
, WS_EX_CONTROLPARENT
);
1144 control
->property
= strdupW( prop
);
1146 /* query the Radio Button table for all control in this group */
1147 r
= MSI_OpenQuery( package
->db
, &view
, query
, prop
);
1148 if( r
!= ERROR_SUCCESS
)
1150 ERR("query failed for dialog %s radio group %s\n",
1151 debugstr_w(dialog
->name
), debugstr_w(prop
));
1152 return ERROR_INVALID_PARAMETER
;
1155 group
.dialog
= dialog
;
1156 group
.parent
= control
;
1157 group
.attributes
= MSI_RecordGetInteger( rec
, 8 );
1159 r
= MSI_IterateRecords( view
, 0, msi_dialog_create_radiobutton
, &group
);
1160 msiobj_release( &view
->hdr
);
1165 struct control_handler msi_dialog_handler
[] =
1167 { szText
, msi_dialog_text_control
},
1168 { szPushButton
, msi_dialog_button_control
},
1169 { szLine
, msi_dialog_line_control
},
1170 { szBitmap
, msi_dialog_bitmap_control
},
1171 { szCheckBox
, msi_dialog_checkbox_control
},
1172 { szScrollableText
, msi_dialog_scrolltext_control
},
1173 { szComboBox
, msi_dialog_combo_control
},
1174 { szEdit
, msi_dialog_edit_control
},
1175 { szMaskedEdit
, msi_dialog_maskedit_control
},
1176 { szPathEdit
, msi_dialog_pathedit_control
},
1177 { szRadioButtonGroup
, msi_dialog_radiogroup_control
},
1178 { szIcon
, msi_dialog_icon_control
},
1181 #define NUM_CONTROL_TYPES (sizeof msi_dialog_handler/sizeof msi_dialog_handler[0])
1183 static UINT
msi_dialog_create_controls( MSIRECORD
*rec
, LPVOID param
)
1185 msi_dialog
*dialog
= param
;
1186 LPCWSTR control_type
;
1189 /* find and call the function that can create this type of control */
1190 control_type
= MSI_RecordGetString( rec
, 3 );
1191 for( i
=0; i
<NUM_CONTROL_TYPES
; i
++ )
1192 if (!strcmpiW( msi_dialog_handler
[i
].control_type
, control_type
))
1194 if( i
!= NUM_CONTROL_TYPES
)
1195 msi_dialog_handler
[i
].func( dialog
, rec
);
1197 ERR("no handler for element type %s\n", debugstr_w(control_type
));
1199 return ERROR_SUCCESS
;
1202 static UINT
msi_dialog_fill_controls( msi_dialog
*dialog
)
1204 static const WCHAR query
[] = {
1205 'S','E','L','E','C','T',' ','*',' ',
1206 'F','R','O','M',' ','C','o','n','t','r','o','l',' ',
1207 'W','H','E','R','E',' ',
1208 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',0};
1210 MSIQUERY
*view
= NULL
;
1211 MSIPACKAGE
*package
= dialog
->package
;
1213 TRACE("%p %s\n", dialog
, debugstr_w(dialog
->name
) );
1215 /* query the Control table for all the elements of the control */
1216 r
= MSI_OpenQuery( package
->db
, &view
, query
, dialog
->name
);
1217 if( r
!= ERROR_SUCCESS
)
1219 ERR("query failed for dialog %s\n", debugstr_w(dialog
->name
));
1220 return ERROR_INVALID_PARAMETER
;
1223 r
= MSI_IterateRecords( view
, 0, msi_dialog_create_controls
, dialog
);
1224 msiobj_release( &view
->hdr
);
1229 static UINT
msi_dialog_set_control_condition( MSIRECORD
*rec
, LPVOID param
)
1231 static const WCHAR szHide
[] = { 'H','i','d','e',0 };
1232 static const WCHAR szShow
[] = { 'S','h','o','w',0 };
1233 static const WCHAR szDisable
[] = { 'D','i','s','a','b','l','e',0 };
1234 static const WCHAR szEnable
[] = { 'E','n','a','b','l','e',0 };
1235 msi_dialog
*dialog
= param
;
1236 msi_control
*control
;
1237 LPCWSTR name
, action
, condition
;
1240 name
= MSI_RecordGetString( rec
, 2 );
1241 action
= MSI_RecordGetString( rec
, 3 );
1242 condition
= MSI_RecordGetString( rec
, 4 );
1243 r
= MSI_EvaluateConditionW( dialog
->package
, condition
);
1244 control
= msi_dialog_find_control( dialog
, name
);
1247 TRACE("%s control %s\n", debugstr_w(action
), debugstr_w(name
));
1249 /* FIXME: case sensitive? */
1250 if(!lstrcmpW(action
, szHide
))
1251 ShowWindow(control
->hwnd
, SW_HIDE
);
1252 else if(!strcmpW(action
, szShow
))
1253 ShowWindow(control
->hwnd
, SW_SHOW
);
1254 else if(!strcmpW(action
, szDisable
))
1255 EnableWindow(control
->hwnd
, FALSE
);
1256 else if(!strcmpW(action
, szEnable
))
1257 EnableWindow(control
->hwnd
, TRUE
);
1259 FIXME("Unhandled action %s\n", debugstr_w(action
));
1262 return ERROR_SUCCESS
;
1265 static UINT
msi_dialog_evaluate_control_conditions( msi_dialog
*dialog
)
1267 static const WCHAR query
[] = {
1268 'S','E','L','E','C','T',' ','*',' ',
1269 'F','R','O','M',' ',
1270 'C','o','n','t','r','o','l','C','o','n','d','i','t','i','o','n',' ',
1271 'W','H','E','R','E',' ',
1272 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',0
1275 MSIQUERY
*view
= NULL
;
1276 MSIPACKAGE
*package
= dialog
->package
;
1278 TRACE("%p %s\n", dialog
, debugstr_w(dialog
->name
) );
1280 /* query the Control table for all the elements of the control */
1281 r
= MSI_OpenQuery( package
->db
, &view
, query
, dialog
->name
);
1282 if( r
!= ERROR_SUCCESS
)
1284 ERR("query failed for dialog %s\n", debugstr_w(dialog
->name
));
1285 return ERROR_INVALID_PARAMETER
;
1288 r
= MSI_IterateRecords( view
, 0, msi_dialog_set_control_condition
, dialog
);
1289 msiobj_release( &view
->hdr
);
1294 /* figure out the height of 10 point MS Sans Serif */
1295 static INT
msi_dialog_get_sans_serif_height( HWND hwnd
)
1297 static const WCHAR szSansSerif
[] = {
1298 'M','S',' ','S','a','n','s',' ','S','e','r','i','f',0 };
1303 HFONT hFont
, hOldFont
;
1306 hdc
= GetDC( hwnd
);
1309 memset( &lf
, 0, sizeof lf
);
1310 lf
.lfHeight
= MulDiv(10, GetDeviceCaps(hdc
, LOGPIXELSY
), 72);
1311 strcpyW( lf
.lfFaceName
, szSansSerif
);
1312 hFont
= CreateFontIndirectW(&lf
);
1315 hOldFont
= SelectObject( hdc
, hFont
);
1316 r
= GetTextMetricsW( hdc
, &tm
);
1318 height
= tm
.tmHeight
;
1319 SelectObject( hdc
, hOldFont
);
1320 DeleteObject( hFont
);
1322 ReleaseDC( hwnd
, hdc
);
1327 /* fetch the associated record from the Dialog table */
1328 static MSIRECORD
*msi_get_dialog_record( msi_dialog
*dialog
)
1330 static const WCHAR query
[] = {
1331 'S','E','L','E','C','T',' ','*',' ',
1332 'F','R','O','M',' ','D','i','a','l','o','g',' ',
1333 'W','H','E','R','E',' ',
1334 '`','D','i','a','l','o','g','`',' ','=',' ','\'','%','s','\'',0};
1335 MSIPACKAGE
*package
= dialog
->package
;
1336 MSIRECORD
*rec
= NULL
;
1338 TRACE("%p %s\n", dialog
, debugstr_w(dialog
->name
) );
1340 rec
= MSI_QueryGetRecord( package
->db
, query
, dialog
->name
);
1342 ERR("query failed for dialog %s\n", debugstr_w(dialog
->name
));
1347 static void msi_dialog_adjust_dialog_size( msi_dialog
*dialog
, LPSIZE sz
)
1352 /* turn the client size into the window rectangle */
1355 rect
.right
= msi_dialog_scale_unit( dialog
, sz
->cx
);
1356 rect
.bottom
= msi_dialog_scale_unit( dialog
, sz
->cy
);
1357 style
= GetWindowLongPtrW( dialog
->hwnd
, GWL_STYLE
);
1358 AdjustWindowRect( &rect
, style
, FALSE
);
1359 sz
->cx
= rect
.right
- rect
.left
;
1360 sz
->cy
= rect
.bottom
- rect
.top
;
1363 static BOOL
msi_control_set_next( msi_control
*control
, msi_control
*next
)
1365 return SetWindowPos( next
->hwnd
, control
->hwnd
, 0, 0, 0, 0,
1366 SWP_NOMOVE
| SWP_NOOWNERZORDER
| SWP_NOREDRAW
|
1367 SWP_NOREPOSITION
| SWP_NOSENDCHANGING
| SWP_NOSIZE
);
1370 static UINT
msi_dialog_set_tab_order( msi_dialog
*dialog
)
1372 msi_control
*control
, *tab_next
;
1374 for( control
= dialog
->control_list
; control
; control
= control
->next
)
1376 tab_next
= msi_dialog_find_control( dialog
, control
->tabnext
);
1379 msi_control_set_next( control
, tab_next
);
1382 return ERROR_SUCCESS
;
1385 static void msi_dialog_set_first_control( msi_dialog
* dialog
, LPCWSTR name
)
1387 msi_control
*control
;
1389 control
= msi_dialog_find_control( dialog
, name
);
1391 dialog
->hWndFocus
= control
->hwnd
;
1393 dialog
->hWndFocus
= NULL
;
1396 static LRESULT
msi_dialog_oncreate( HWND hwnd
, LPCREATESTRUCTW cs
)
1398 static const WCHAR df
[] = {
1399 'D','e','f','a','u','l','t','U','I','F','o','n','t',0 };
1400 msi_dialog
*dialog
= (msi_dialog
*) cs
->lpCreateParams
;
1401 MSIRECORD
*rec
= NULL
;
1403 LPWSTR title
= NULL
;
1406 TRACE("%p %p\n", dialog
, dialog
->package
);
1408 dialog
->hwnd
= hwnd
;
1409 SetWindowLongPtrW( hwnd
, GWLP_USERDATA
, (LONG_PTR
) dialog
);
1411 rec
= msi_get_dialog_record( dialog
);
1414 TRACE("No record found for dialog %s\n", debugstr_w(dialog
->name
));
1418 dialog
->scale
= msi_dialog_get_sans_serif_height(dialog
->hwnd
);
1420 size
.cx
= MSI_RecordGetInteger( rec
, 4 );
1421 size
.cy
= MSI_RecordGetInteger( rec
, 5 );
1422 msi_dialog_adjust_dialog_size( dialog
, &size
);
1424 dialog
->attributes
= MSI_RecordGetInteger( rec
, 6 );
1425 text
= MSI_RecordGetString( rec
, 7 );
1427 dialog
->default_font
= load_dynamic_property( dialog
->package
, df
, NULL
);
1429 deformat_string( dialog
->package
, text
, &title
);
1430 SetWindowTextW( hwnd
, title
);
1431 SetWindowPos( hwnd
, 0, 0, 0, size
.cx
, size
.cy
,
1432 SWP_NOMOVE
| SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_NOREDRAW
);
1434 HeapFree( GetProcessHeap(), 0, title
);
1436 msi_dialog_build_font_list( dialog
);
1437 msi_dialog_fill_controls( dialog
);
1438 msi_dialog_evaluate_control_conditions( dialog
);
1439 msi_dialog_set_tab_order( dialog
);
1440 msi_dialog_set_first_control( dialog
, MSI_RecordGetString( rec
, 8 ) );
1441 msiobj_release( &rec
->hdr
);
1446 static UINT
msi_dialog_send_event( msi_dialog
*dialog
, LPCWSTR event
, LPCWSTR arg
)
1448 LPWSTR event_fmt
= NULL
, arg_fmt
= NULL
;
1450 TRACE("Sending control event %s %s\n", debugstr_w(event
), debugstr_w(arg
));
1452 deformat_string( dialog
->package
, event
, &event_fmt
);
1453 deformat_string( dialog
->package
, arg
, &arg_fmt
);
1455 dialog
->event_handler( dialog
->package
, event_fmt
, arg_fmt
, dialog
);
1457 HeapFree( GetProcessHeap(), 0, event_fmt
);
1458 HeapFree( GetProcessHeap(), 0, arg_fmt
);
1460 return ERROR_SUCCESS
;
1463 static UINT
msi_dialog_set_property( msi_dialog
*dialog
, LPCWSTR event
, LPCWSTR arg
)
1465 static const WCHAR szNullArg
[] = { '{','}',0 };
1466 LPWSTR p
, prop
, arg_fmt
= NULL
;
1469 len
= strlenW(event
);
1470 prop
= HeapAlloc( GetProcessHeap(), 0, len
*sizeof(WCHAR
));
1471 strcpyW( prop
, &event
[1] );
1472 p
= strchrW( prop
, ']' );
1473 if( p
&& p
[1] == 0 )
1476 if( strcmpW( szNullArg
, arg
) )
1477 deformat_string( dialog
->package
, arg
, &arg_fmt
);
1478 MSI_SetPropertyW( dialog
->package
, prop
, arg_fmt
);
1481 ERR("Badly formatted property string - what happens?\n");
1482 HeapFree( GetProcessHeap(), 0, prop
);
1483 return ERROR_SUCCESS
;
1486 static UINT
msi_dialog_control_event( MSIRECORD
*rec
, LPVOID param
)
1488 msi_dialog
*dialog
= param
;
1489 LPCWSTR condition
, event
, arg
;
1492 condition
= MSI_RecordGetString( rec
, 5 );
1493 r
= MSI_EvaluateConditionW( dialog
->package
, condition
);
1496 event
= MSI_RecordGetString( rec
, 3 );
1497 arg
= MSI_RecordGetString( rec
, 4 );
1498 if( event
[0] == '[' )
1499 msi_dialog_set_property( dialog
, event
, arg
);
1501 msi_dialog_send_event( dialog
, event
, arg
);
1504 return ERROR_SUCCESS
;
1507 static UINT
msi_dialog_button_handler( msi_dialog
*dialog
,
1508 msi_control
*control
, WPARAM param
)
1510 static const WCHAR query
[] = {
1511 'S','E','L','E','C','T',' ','*',' ',
1512 'F','R','O','M',' ','C','o','n','t','r','o','l','E','v','e','n','t',' ',
1513 'W','H','E','R','E',' ',
1514 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',' ',
1516 '`','C','o','n','t','r','o','l','_','`',' ','=',' ','\'','%','s','\'',' ',
1517 'O','R','D','E','R',' ','B','Y',' ','`','O','r','d','e','r','i','n','g','`',0
1519 MSIQUERY
*view
= NULL
;
1522 if( HIWORD(param
) != BN_CLICKED
)
1523 return ERROR_SUCCESS
;
1525 r
= MSI_OpenQuery( dialog
->package
->db
, &view
, query
,
1526 dialog
->name
, control
->name
);
1527 if( r
!= ERROR_SUCCESS
)
1529 ERR("query failed\n");
1533 r
= MSI_IterateRecords( view
, 0, msi_dialog_control_event
, dialog
);
1534 msiobj_release( &view
->hdr
);
1539 static UINT
msi_dialog_get_checkbox_state( msi_dialog
*dialog
,
1540 msi_control
*control
)
1542 WCHAR state
[2] = { 0 };
1545 MSI_GetPropertyW( dialog
->package
, control
->property
, state
, &sz
);
1546 return state
[0] ? 1 : 0;
1549 static void msi_dialog_set_checkbox_state( msi_dialog
*dialog
,
1550 msi_control
*control
, UINT state
)
1552 static const WCHAR szState
[] = { '1', 0 };
1555 /* if uncheck then the property is set to NULL */
1558 MSI_SetPropertyW( dialog
->package
, control
->property
, NULL
);
1562 /* check for a custom state */
1563 if (control
->value
&& control
->value
[0])
1564 val
= control
->value
;
1568 MSI_SetPropertyW( dialog
->package
, control
->property
, val
);
1571 static void msi_dialog_checkbox_sync_state( msi_dialog
*dialog
,
1572 msi_control
*control
)
1576 state
= msi_dialog_get_checkbox_state( dialog
, control
);
1577 SendMessageW( control
->hwnd
, BM_SETCHECK
,
1578 state
? BST_CHECKED
: BST_UNCHECKED
, 0 );
1581 static UINT
msi_dialog_checkbox_handler( msi_dialog
*dialog
,
1582 msi_control
*control
, WPARAM param
)
1586 if( HIWORD(param
) != BN_CLICKED
)
1587 return ERROR_SUCCESS
;
1589 TRACE("clicked checkbox %s, set %s\n", debugstr_w(control
->name
),
1590 debugstr_w(control
->property
));
1592 state
= msi_dialog_get_checkbox_state( dialog
, control
);
1593 state
= state
? 0 : 1;
1594 msi_dialog_set_checkbox_state( dialog
, control
, state
);
1595 msi_dialog_checkbox_sync_state( dialog
, control
);
1597 return msi_dialog_button_handler( dialog
, control
, param
);
1600 static UINT
msi_dialog_edit_handler( msi_dialog
*dialog
,
1601 msi_control
*control
, WPARAM param
)
1606 if( HIWORD(param
) != EN_CHANGE
)
1607 return ERROR_SUCCESS
;
1609 TRACE("edit %s contents changed, set %s\n", debugstr_w(control
->name
),
1610 debugstr_w(control
->property
));
1613 buf
= HeapAlloc( GetProcessHeap(), 0, sz
*sizeof(WCHAR
) );
1616 r
= GetWindowTextW( control
->hwnd
, buf
, sz
);
1620 buf
= HeapReAlloc( GetProcessHeap(), 0, buf
, sz
*sizeof(WCHAR
) );
1623 MSI_SetPropertyW( dialog
->package
, control
->property
, buf
);
1625 HeapFree( GetProcessHeap(), 0, buf
);
1627 return ERROR_SUCCESS
;
1630 static UINT
msi_dialog_radiogroup_handler( msi_dialog
*dialog
,
1631 msi_control
*control
, WPARAM param
)
1633 if( HIWORD(param
) != BN_CLICKED
)
1634 return ERROR_SUCCESS
;
1636 TRACE("clicked radio button %s, set %s\n", debugstr_w(control
->name
),
1637 debugstr_w(control
->property
));
1639 MSI_SetPropertyW( dialog
->package
, control
->property
, control
->name
);
1641 return msi_dialog_button_handler( dialog
, control
, param
);
1644 static LRESULT
msi_dialog_oncommand( msi_dialog
*dialog
, WPARAM param
, HWND hwnd
)
1646 msi_control
*control
;
1648 TRACE("%p %p %08x\n", dialog
, hwnd
, param
);
1650 control
= msi_dialog_find_control_by_hwnd( dialog
, hwnd
);
1653 if( control
->handler
)
1655 control
->handler( dialog
, control
, param
);
1656 msi_dialog_evaluate_control_conditions( dialog
);
1660 ERR("button click from nowhere\n");
1664 static void msi_dialog_setfocus( msi_dialog
*dialog
)
1666 HWND hwnd
= dialog
->hWndFocus
;
1668 hwnd
= GetNextDlgTabItem( dialog
->hwnd
, hwnd
, TRUE
);
1669 hwnd
= GetNextDlgTabItem( dialog
->hwnd
, hwnd
, FALSE
);
1671 dialog
->hWndFocus
= hwnd
;
1674 static LRESULT WINAPI
MSIDialog_WndProc( HWND hwnd
, UINT msg
,
1675 WPARAM wParam
, LPARAM lParam
)
1677 msi_dialog
*dialog
= (LPVOID
) GetWindowLongPtrW( hwnd
, GWLP_USERDATA
);
1679 TRACE("0x%04x\n", msg
);
1684 return msi_dialog_oncreate( hwnd
, (LPCREATESTRUCTW
)lParam
);
1687 return msi_dialog_oncommand( dialog
, wParam
, (HWND
)lParam
);
1690 if( LOWORD(wParam
) == WA_INACTIVE
)
1691 dialog
->hWndFocus
= GetFocus();
1693 msi_dialog_setfocus( dialog
);
1697 msi_dialog_setfocus( dialog
);
1700 /* bounce back to our subclassed static control */
1701 case WM_CTLCOLORSTATIC
:
1702 return SendMessageW( (HWND
) lParam
, WM_CTLCOLORSTATIC
, wParam
, lParam
);
1705 dialog
->hwnd
= NULL
;
1708 return DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
1711 static LRESULT WINAPI
MSIRadioGroup_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1713 WNDPROC oldproc
= (WNDPROC
) GetPropW(hWnd
, szButtonData
);
1715 TRACE("hWnd %p msg %04x wParam 0x%08x lParam 0x%08lx\n", hWnd
, msg
, wParam
, lParam
);
1717 if (msg
== WM_COMMAND
) /* Forward notifications to dialog */
1718 SendMessageW(GetParent(hWnd
), msg
, wParam
, lParam
);
1720 return CallWindowProcW(oldproc
, hWnd
, msg
, wParam
, lParam
);
1723 static LRESULT WINAPI
MSIHiddenWindowProc( HWND hwnd
, UINT msg
,
1724 WPARAM wParam
, LPARAM lParam
)
1726 msi_dialog
*dialog
= (msi_dialog
*) lParam
;
1728 TRACE("%d %p\n", msg
, dialog
);
1732 case WM_MSI_DIALOG_CREATE
:
1733 return msi_dialog_run_message_loop( dialog
);
1734 case WM_MSI_DIALOG_DESTROY
:
1735 msi_dialog_destroy( dialog
);
1738 return DefWindowProcW( hwnd
, msg
, wParam
, lParam
);
1741 /* functions that interface to other modules within MSI */
1743 msi_dialog
*msi_dialog_create( MSIPACKAGE
* package
, LPCWSTR szDialogName
,
1744 msi_dialog_event_handler event_handler
)
1746 MSIRECORD
*rec
= NULL
;
1749 TRACE("%p %s\n", package
, debugstr_w(szDialogName
));
1751 /* allocate the structure for the dialog to use */
1752 dialog
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
,
1753 sizeof *dialog
+ sizeof(WCHAR
)*strlenW(szDialogName
) );
1756 strcpyW( dialog
->name
, szDialogName
);
1757 msiobj_addref( &package
->hdr
);
1758 dialog
->package
= package
;
1759 dialog
->event_handler
= event_handler
;
1760 dialog
->finished
= 0;
1762 /* verify that the dialog exists */
1763 rec
= msi_get_dialog_record( dialog
);
1766 HeapFree( GetProcessHeap(), 0, dialog
);
1769 dialog
->attributes
= MSI_RecordGetInteger( rec
, 6 );
1770 msiobj_release( &rec
->hdr
);
1775 static void msi_process_pending_messages( HWND hdlg
)
1779 while( PeekMessageW( &msg
, 0, 0, 0, PM_REMOVE
) )
1781 if( hdlg
&& IsDialogMessageW( hdlg
, &msg
))
1783 TranslateMessage( &msg
);
1784 DispatchMessageW( &msg
);
1788 void msi_dialog_end_dialog( msi_dialog
*dialog
)
1790 TRACE("%p\n", dialog
);
1791 dialog
->finished
= 1;
1792 PostMessageW(dialog
->hwnd
, WM_NULL
, 0, 0);
1795 void msi_dialog_check_messages( HANDLE handle
)
1799 /* in threads other than the UI thread, block */
1800 if( uiThreadId
!= GetCurrentThreadId() )
1803 WaitForSingleObject( handle
, INFINITE
);
1807 /* there's two choices for the UI thread */
1810 msi_process_pending_messages( NULL
);
1816 * block here until somebody creates a new dialog or
1817 * the handle we're waiting on becomes ready
1819 r
= MsgWaitForMultipleObjects( 1, &handle
, 0, INFINITE
, QS_ALLINPUT
);
1820 if( r
== WAIT_OBJECT_0
)
1825 UINT
msi_dialog_run_message_loop( msi_dialog
*dialog
)
1829 if( !(dialog
->attributes
& msidbDialogAttributesVisible
) )
1830 return ERROR_SUCCESS
;
1832 if( uiThreadId
!= GetCurrentThreadId() )
1833 return SendMessageW( hMsiHiddenWindow
, WM_MSI_DIALOG_CREATE
, 0, (LPARAM
) dialog
);
1835 /* create the dialog window, don't show it yet */
1836 hwnd
= CreateWindowW( szMsiDialogClass
, dialog
->name
, WS_OVERLAPPEDWINDOW
,
1837 CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
,
1838 NULL
, NULL
, NULL
, dialog
);
1841 ERR("Failed to create dialog %s\n", debugstr_w( dialog
->name
));
1842 return ERROR_FUNCTION_FAILED
;
1845 ShowWindow( hwnd
, SW_SHOW
);
1846 UpdateWindow( hwnd
);
1848 if( dialog
->attributes
& msidbDialogAttributesModal
)
1850 while( !dialog
->finished
)
1852 MsgWaitForMultipleObjects( 0, NULL
, 0, INFINITE
, QS_ALLEVENTS
);
1853 msi_process_pending_messages( dialog
->hwnd
);
1857 return ERROR_IO_PENDING
;
1859 return ERROR_SUCCESS
;
1862 void msi_dialog_do_preview( msi_dialog
*dialog
)
1865 dialog
->attributes
|= msidbDialogAttributesVisible
;
1866 dialog
->attributes
&= ~msidbDialogAttributesModal
;
1867 msi_dialog_run_message_loop( dialog
);
1870 void msi_dialog_destroy( msi_dialog
*dialog
)
1872 if( uiThreadId
!= GetCurrentThreadId() )
1874 SendMessageW( hMsiHiddenWindow
, WM_MSI_DIALOG_DESTROY
, 0, (LPARAM
) dialog
);
1879 ShowWindow( dialog
->hwnd
, SW_HIDE
);
1881 /* destroy the list of controls */
1882 while( dialog
->control_list
)
1884 msi_control
*t
= dialog
->control_list
;
1885 dialog
->control_list
= t
->next
;
1886 /* leave dialog->hwnd - destroying parent destroys child windows */
1887 HeapFree( GetProcessHeap(), 0, t
->property
);
1888 HeapFree( GetProcessHeap(), 0, t
->value
);
1890 DeleteObject( t
->hBitmap
);
1892 DestroyIcon( t
->hIcon
);
1893 HeapFree( GetProcessHeap(), 0, t
->tabnext
);
1894 HeapFree( GetProcessHeap(), 0, t
);
1897 /* destroy the list of fonts */
1898 while( dialog
->font_list
)
1900 msi_font
*t
= dialog
->font_list
;
1901 dialog
->font_list
= t
->next
;
1902 DeleteObject( t
->hfont
);
1903 HeapFree( GetProcessHeap(), 0, t
);
1905 HeapFree( GetProcessHeap(), 0, dialog
->default_font
);
1908 DestroyWindow( dialog
->hwnd
);
1910 msiobj_release( &dialog
->package
->hdr
);
1911 dialog
->package
= NULL
;
1912 HeapFree( GetProcessHeap(), 0, dialog
);
1915 BOOL
msi_dialog_register_class( void )
1919 ZeroMemory( &cls
, sizeof cls
);
1920 cls
.lpfnWndProc
= MSIDialog_WndProc
;
1921 cls
.hInstance
= NULL
;
1922 cls
.hIcon
= LoadIconW(0, (LPWSTR
)IDI_APPLICATION
);
1923 cls
.hCursor
= LoadCursorW(0, (LPWSTR
)IDC_ARROW
);
1924 cls
.hbrBackground
= (HBRUSH
)(COLOR_WINDOW
);
1925 cls
.lpszMenuName
= NULL
;
1926 cls
.lpszClassName
= szMsiDialogClass
;
1928 if( !RegisterClassW( &cls
) )
1931 cls
.lpfnWndProc
= MSIHiddenWindowProc
;
1932 cls
.lpszClassName
= szMsiHiddenWindow
;
1934 if( !RegisterClassW( &cls
) )
1937 uiThreadId
= GetCurrentThreadId();
1939 hMsiHiddenWindow
= CreateWindowW( szMsiHiddenWindow
, NULL
, WS_OVERLAPPED
,
1940 0, 0, 100, 100, NULL
, NULL
, NULL
, NULL
);
1941 if( !hMsiHiddenWindow
)
1944 hRichedit
= LoadLibraryA("riched20");
1949 void msi_dialog_unregister_class( void )
1951 DestroyWindow( hMsiHiddenWindow
);
1952 UnregisterClassW( szMsiDialogClass
, NULL
);
1954 FreeLibrary( hRichedit
);