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
;
83 typedef UINT (*msi_dialog_control_func
)( msi_dialog
*dialog
, MSIRECORD
*rec
);
84 struct control_handler
87 msi_dialog_control_func func
;
95 } radio_button_group_descr
;
97 const WCHAR szMsiDialogClass
[] = {
98 'M','s','i','D','i','a','l','o','g','C','l','o','s','e','C','l','a','s','s',0
100 const WCHAR szMsiHiddenWindow
[] = {
101 'M','s','i','H','i','d','d','e','n','W','i','n','d','o','w',0 };
102 const static WCHAR szStatic
[] = { 'S','t','a','t','i','c',0 };
103 const static WCHAR szButton
[] = { 'B','U','T','T','O','N', 0 };
104 const static WCHAR szButtonData
[] = { 'M','S','I','D','A','T','A',0 };
105 static const WCHAR szText
[] = { 'T','e','x','t',0 };
106 static const WCHAR szPushButton
[] = { 'P','u','s','h','B','u','t','t','o','n',0 };
107 static const WCHAR szLine
[] = { 'L','i','n','e',0 };
108 static const WCHAR szBitmap
[] = { 'B','i','t','m','a','p',0 };
109 static const WCHAR szCheckBox
[] = { 'C','h','e','c','k','B','o','x',0 };
110 static const WCHAR szScrollableText
[] = {
111 'S','c','r','o','l','l','a','b','l','e','T','e','x','t',0 };
112 static const WCHAR szComboBox
[] = { 'C','o','m','b','o','B','o','x',0 };
113 static const WCHAR szEdit
[] = { 'E','d','i','t',0 };
114 static const WCHAR szMaskedEdit
[] = { 'M','a','s','k','e','d','E','d','i','t',0 };
115 static const WCHAR szPathEdit
[] = { 'P','a','t','h','E','d','i','t',0 };
116 static const WCHAR szRadioButtonGroup
[] = {
117 'R','a','d','i','o','B','u','t','t','o','n','G','r','o','u','p',0 };
118 static const WCHAR szIcon
[] = { 'I','c','o','n',0 };
120 static UINT
msi_dialog_checkbox_handler( msi_dialog
*, msi_control
*, WPARAM
);
121 static void msi_dialog_checkbox_sync_state( msi_dialog
*, msi_control
* );
122 static UINT
msi_dialog_button_handler( msi_dialog
*, msi_control
*, WPARAM
);
123 static UINT
msi_dialog_edit_handler( msi_dialog
*, msi_control
*, WPARAM
);
124 static UINT
msi_dialog_radiogroup_handler( msi_dialog
*, msi_control
*, WPARAM param
);
125 static UINT
msi_dialog_evaluate_control_conditions( msi_dialog
*dialog
);
126 static LRESULT WINAPI
MSIRadioGroup_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
);
129 /* dialog sequencing */
131 #define WM_MSI_DIALOG_CREATE (WM_USER+0x100)
132 #define WM_MSI_DIALOG_DESTROY (WM_USER+0x101)
134 static DWORD uiThreadId
;
135 static HWND hMsiHiddenWindow
;
136 static HMODULE hRichedit
;
138 static INT
msi_dialog_scale_unit( msi_dialog
*dialog
, INT val
)
140 return (dialog
->scale
* val
+ 5) / 10;
143 static msi_control
*msi_dialog_find_control( msi_dialog
*dialog
, LPCWSTR name
)
145 msi_control
*control
;
149 for( control
= dialog
->control_list
; control
; control
= control
->next
)
150 if( !strcmpW( control
->name
, name
) ) /* FIXME: case sensitive? */
155 static msi_control
*msi_dialog_find_control_by_hwnd( msi_dialog
*dialog
, HWND hwnd
)
157 msi_control
*control
;
159 for( control
= dialog
->control_list
; control
; control
= control
->next
)
160 if( hwnd
== control
->hwnd
)
166 * msi_dialog_get_style
168 * Extract the {\style} string from the front of the text to display and
169 * update the pointer.
171 static LPWSTR
msi_dialog_get_style( LPCWSTR
*text
)
174 LPCWSTR p
= *text
, q
;
179 q
= strchrW( p
, '}' );
187 ret
= HeapAlloc( GetProcessHeap(), 0, len
*sizeof(WCHAR
) );
190 memcpy( ret
, p
, len
*sizeof(WCHAR
) );
195 static UINT
msi_dialog_add_font( MSIRECORD
*rec
, LPVOID param
)
197 msi_dialog
*dialog
= param
;
204 /* create a font and add it to the list */
205 name
= MSI_RecordGetString( rec
, 1 );
206 font
= HeapAlloc( GetProcessHeap(), 0,
207 sizeof *font
+ strlenW( name
)*sizeof (WCHAR
) );
208 strcpyW( font
->name
, name
);
209 font
->next
= dialog
->font_list
;
210 dialog
->font_list
= font
;
212 memset( &lf
, 0, sizeof lf
);
213 face
= MSI_RecordGetString( rec
, 2 );
214 lf
.lfHeight
= MSI_RecordGetInteger( rec
, 3 );
215 style
= MSI_RecordGetInteger( rec
, 5 );
216 if( style
& msidbTextStyleStyleBitsBold
)
217 lf
.lfWeight
= FW_BOLD
;
218 if( style
& msidbTextStyleStyleBitsItalic
)
220 if( style
& msidbTextStyleStyleBitsUnderline
)
221 lf
.lfUnderline
= TRUE
;
222 if( style
& msidbTextStyleStyleBitsStrike
)
223 lf
.lfStrikeOut
= TRUE
;
224 lstrcpynW( lf
.lfFaceName
, face
, LF_FACESIZE
);
226 /* adjust the height */
227 hdc
= GetDC( dialog
->hwnd
);
230 lf
.lfHeight
= -MulDiv(lf
.lfHeight
, GetDeviceCaps(hdc
, LOGPIXELSY
), 72);
231 ReleaseDC( dialog
->hwnd
, hdc
);
234 font
->hfont
= CreateFontIndirectW( &lf
);
236 TRACE("Adding font style %s\n", debugstr_w(font
->name
) );
238 return ERROR_SUCCESS
;
241 static msi_font
*msi_dialog_find_font( msi_dialog
*dialog
, LPCWSTR name
)
245 for( font
= dialog
->font_list
; font
; font
= font
->next
)
246 if( !strcmpW( font
->name
, name
) ) /* FIXME: case sensitive? */
252 static UINT
msi_dialog_set_font( msi_dialog
*dialog
, HWND hwnd
, LPCWSTR name
)
256 font
= msi_dialog_find_font( dialog
, name
);
258 SendMessageW( hwnd
, WM_SETFONT
, (WPARAM
) font
->hfont
, TRUE
);
260 ERR("No font entry for %s\n", debugstr_w(name
));
261 return ERROR_SUCCESS
;
264 static UINT
msi_dialog_build_font_list( msi_dialog
*dialog
)
266 static const WCHAR query
[] = {
267 'S','E','L','E','C','T',' ','*',' ',
268 'F','R','O','M',' ','`','T','e','x','t','S','t','y','l','e','`',' ',0
271 MSIQUERY
*view
= NULL
;
273 TRACE("dialog %p\n", dialog
);
275 r
= MSI_OpenQuery( dialog
->package
->db
, &view
, query
);
276 if( r
!= ERROR_SUCCESS
)
279 r
= MSI_IterateRecords( view
, NULL
, msi_dialog_add_font
, dialog
);
280 msiobj_release( &view
->hdr
);
285 static msi_control
*msi_dialog_create_window( msi_dialog
*dialog
,
286 MSIRECORD
*rec
, LPCWSTR szCls
, LPCWSTR name
, LPCWSTR text
,
287 DWORD style
, HWND parent
)
289 DWORD x
, y
, width
, height
;
290 LPWSTR font
= NULL
, title
= NULL
;
291 msi_control
*control
;
295 control
= HeapAlloc( GetProcessHeap(), 0,
296 sizeof *control
+ strlenW(name
)*sizeof(WCHAR
) );
297 strcpyW( control
->name
, name
);
298 control
->next
= dialog
->control_list
;
299 dialog
->control_list
= control
;
300 control
->handler
= NULL
;
301 control
->property
= NULL
;
302 control
->value
= NULL
;
304 control
->hIcon
= NULL
;
305 control
->tabnext
= strdupW( MSI_RecordGetString( rec
, 11) );
307 x
= MSI_RecordGetInteger( rec
, 4 );
308 y
= MSI_RecordGetInteger( rec
, 5 );
309 width
= MSI_RecordGetInteger( rec
, 6 );
310 height
= MSI_RecordGetInteger( rec
, 7 );
312 x
= msi_dialog_scale_unit( dialog
, x
);
313 y
= msi_dialog_scale_unit( dialog
, y
);
314 width
= msi_dialog_scale_unit( dialog
, width
);
315 height
= msi_dialog_scale_unit( dialog
, height
);
319 font
= msi_dialog_get_style( &text
);
320 deformat_string( dialog
->package
, text
, &title
);
323 control
->hwnd
= CreateWindowW( szCls
, title
, style
,
324 x
, y
, width
, height
, parent
, NULL
, NULL
, NULL
);
326 TRACE("Dialog %s control %s hwnd %p\n",
327 debugstr_w(dialog
->name
), debugstr_w(text
), control
->hwnd
);
329 msi_dialog_set_font( dialog
, control
->hwnd
,
330 font
? font
: dialog
->default_font
);
332 HeapFree( GetProcessHeap(), 0, font
);
333 HeapFree( GetProcessHeap(), 0, title
);
338 /* called from the Control Event subscription code */
339 void msi_dialog_handle_event( msi_dialog
* dialog
, LPCWSTR control
,
340 LPCWSTR attribute
, MSIRECORD
*rec
)
345 ctrl
= msi_dialog_find_control( dialog
, control
);
348 if( lstrcmpW(attribute
, szText
) )
350 text
= MSI_RecordGetString( rec
, 1 );
351 SetWindowTextW( ctrl
->hwnd
, text
);
352 msi_dialog_check_messages( NULL
);
355 static void msi_dialog_map_events(msi_dialog
* dialog
, LPCWSTR control
)
357 static WCHAR Query
[] = {
358 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
359 '`','E','v','e','n','t','M','a','p','p','i','n','g','`',' ',
360 'W','H','E','R','E',' ',
361 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',' ',
363 '`','C','o','n','t','r','o','l','_','`',' ','=',' ','\'','%','s','\'',0
366 LPCWSTR event
, attribute
;
368 row
= MSI_QueryGetRecord( dialog
->package
->db
, Query
, dialog
->name
, control
);
372 event
= MSI_RecordGetString( row
, 3 );
373 attribute
= MSI_RecordGetString( row
, 4 );
374 ControlEvent_SubscribeToEvent( dialog
->package
, event
, control
, attribute
);
375 msiobj_release( &row
->hdr
);
378 /* everything except radio buttons */
379 static msi_control
*msi_dialog_add_control( msi_dialog
*dialog
,
380 MSIRECORD
*rec
, LPCWSTR szCls
, DWORD style
)
385 name
= MSI_RecordGetString( rec
, 2 );
386 attributes
= MSI_RecordGetInteger( rec
, 8 );
387 text
= MSI_RecordGetString( rec
, 10 );
388 if( attributes
& msidbControlAttributesVisible
)
390 if( ~attributes
& msidbControlAttributesEnabled
)
391 style
|= WS_DISABLED
;
393 msi_dialog_map_events(dialog
, name
);
395 return msi_dialog_create_window( dialog
, rec
, szCls
, name
, text
,
396 style
, dialog
->hwnd
);
406 * we don't erase our own background,
407 * so we have to make sure that the parent window redraws first
409 static void msi_text_on_settext( HWND hWnd
)
414 hParent
= GetParent( hWnd
);
415 GetWindowRect( hWnd
, &rc
);
416 MapWindowPoints( NULL
, hParent
, (LPPOINT
) &rc
, 2 );
417 InvalidateRect( hParent
, &rc
, TRUE
);
420 static LRESULT WINAPI
421 MSIText_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
423 struct msi_text_info
*info
;
426 TRACE("%p %04x %08x %08lx\n", hWnd
, msg
, wParam
, lParam
);
428 info
= GetPropW(hWnd
, szButtonData
);
430 if( msg
== WM_CTLCOLORSTATIC
&&
431 ( info
->attributes
& msidbControlAttributesTransparent
) )
433 SetBkMode( (HDC
)wParam
, TRANSPARENT
);
434 return (LRESULT
) GetStockObject(NULL_BRUSH
);
437 r
= CallWindowProcW(info
->oldproc
, hWnd
, msg
, wParam
, lParam
);
442 msi_text_on_settext( hWnd
);
445 HeapFree( GetProcessHeap(), 0, info
);
446 RemovePropW( hWnd
, szButtonData
);
453 static UINT
msi_dialog_text_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
455 msi_control
*control
;
456 struct msi_text_info
*info
;
458 TRACE("%p %p\n", dialog
, rec
);
460 control
= msi_dialog_add_control( dialog
, rec
, szStatic
, SS_LEFT
| WS_GROUP
);
462 return ERROR_FUNCTION_FAILED
;
464 info
= HeapAlloc( GetProcessHeap(), 0, sizeof *info
);
466 return ERROR_SUCCESS
;
468 info
->attributes
= MSI_RecordGetInteger( rec
, 8 );
469 if( info
->attributes
& msidbControlAttributesTransparent
)
470 SetWindowLongPtrW( control
->hwnd
, GWL_EXSTYLE
, WS_EX_TRANSPARENT
);
472 info
->oldproc
= (WNDPROC
) SetWindowLongPtrW( control
->hwnd
, GWLP_WNDPROC
,
473 (LONG_PTR
)MSIText_WndProc
);
474 SetPropW( control
->hwnd
, szButtonData
, info
);
476 return ERROR_SUCCESS
;
479 static UINT
msi_dialog_button_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
481 msi_control
*control
;
483 TRACE("%p %p\n", dialog
, rec
);
485 control
= msi_dialog_add_control( dialog
, rec
, szButton
, WS_TABSTOP
);
486 control
->handler
= msi_dialog_button_handler
;
488 return ERROR_SUCCESS
;
491 static LPWSTR
msi_get_checkbox_value( msi_dialog
*dialog
, LPCWSTR prop
)
493 const static WCHAR query
[] = {
494 'S','E','L','E','C','T',' ','*',' ',
495 'F','R','O','M',' ','`','C','h','e','c','k','B','o','x',' ','`',
496 'W','H','E','R','E',' ',
497 '`','P','r','o','p','e','r','t','y','`',' ','=',' ',
500 MSIRECORD
*rec
= NULL
;
504 /* find if there is a value associated with the checkbox */
505 rec
= MSI_QueryGetRecord( dialog
->package
->db
, query
, prop
);
509 val
= MSI_RecordGetString( rec
, 2 );
512 deformat_string( dialog
->package
, val
, &ret
);
515 HeapFree( GetProcessHeap(), 0, ret
);
519 msiobj_release( &rec
->hdr
);
523 ret
= load_dynamic_property(dialog
->package
, prop
, NULL
);
526 HeapFree( GetProcessHeap(), 0, ret
);
533 static UINT
msi_dialog_checkbox_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
535 msi_control
*control
;
538 TRACE("%p %p\n", dialog
, rec
);
540 control
= msi_dialog_add_control( dialog
, rec
, szButton
,
541 BS_CHECKBOX
| BS_MULTILINE
| WS_TABSTOP
);
542 control
->handler
= msi_dialog_checkbox_handler
;
543 prop
= MSI_RecordGetString( rec
, 9 );
546 control
->property
= strdupW( prop
);
547 control
->value
= msi_get_checkbox_value( dialog
, prop
);
548 TRACE("control %s value %s\n", debugstr_w(control
->property
),
549 debugstr_w(control
->value
));
551 msi_dialog_checkbox_sync_state( dialog
, control
);
553 return ERROR_SUCCESS
;
556 static UINT
msi_dialog_line_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
558 TRACE("%p %p\n", dialog
, rec
);
560 msi_dialog_add_control( dialog
, rec
, szStatic
, SS_ETCHEDHORZ
| SS_SUNKEN
);
561 return ERROR_SUCCESS
;
564 struct msi_streamin_info
571 static DWORD CALLBACK
572 msi_richedit_stream_in( DWORD_PTR arg
, LPBYTE buffer
, LONG count
, LONG
*pcb
)
574 struct msi_streamin_info
*info
= (struct msi_streamin_info
*) arg
;
576 if( (count
+ info
->offset
) > info
->length
)
577 count
= info
->length
- info
->offset
;
578 memcpy( buffer
, &info
->string
[ info
->offset
], count
);
580 info
->offset
+= count
;
582 TRACE("%ld/%ld\n", info
->offset
, info
->length
);
587 static UINT
msi_dialog_scrolltext_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
589 const static WCHAR szRichEdit20W
[] = {
590 'R','i','c','h','E','d','i','t','2','0','W',0
592 struct msi_streamin_info info
;
593 msi_control
*control
;
598 style
= WS_BORDER
| ES_MULTILINE
| WS_VSCROLL
|
599 ES_READONLY
| ES_AUTOVSCROLL
| WS_TABSTOP
;
600 control
= msi_dialog_add_control( dialog
, rec
, szRichEdit20W
, style
);
602 text
= MSI_RecordGetString( rec
, 10 );
603 info
.string
= strdupWtoA( text
);
605 info
.length
= lstrlenA( info
.string
) + 1;
607 es
.dwCookie
= (DWORD_PTR
) &info
;
609 es
.pfnCallback
= msi_richedit_stream_in
;
611 SendMessageW( control
->hwnd
, EM_STREAMIN
, SF_RTF
, (LPARAM
) &es
);
613 HeapFree( GetProcessHeap(), 0, info
.string
);
615 return ERROR_SUCCESS
;
618 static MSIRECORD
*msi_get_binary_record( MSIDATABASE
*db
, LPCWSTR name
)
620 const static WCHAR query
[] = {
621 's','e','l','e','c','t',' ','*',' ',
622 'f','r','o','m',' ','B','i','n','a','r','y',' ',
623 'w','h','e','r','e',' ',
624 '`','N','a','m','e','`',' ','=',' ','\'','%','s','\'',0
627 return MSI_QueryGetRecord( db
, query
, name
);
630 static UINT
msi_load_bitmap( MSIDATABASE
*db
, LPCWSTR name
, IPicture
**pic
)
632 MSIRECORD
*rec
= NULL
;
636 rec
= msi_get_binary_record( db
, name
);
638 return ERROR_FUNCTION_FAILED
;
640 r
= MSI_RecordGetIStream( rec
, 2, &stm
);
641 msiobj_release( &rec
->hdr
);
642 if( r
!= ERROR_SUCCESS
)
645 r
= OleLoadPicture( stm
, 0, TRUE
, &IID_IPicture
, (LPVOID
*) pic
);
646 IStream_Release( stm
);
648 return ERROR_FUNCTION_FAILED
;
650 return ERROR_SUCCESS
;
653 static UINT
msi_dialog_bitmap_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
655 IPicture
*pic
= NULL
;
656 msi_control
*control
;
657 OLE_HANDLE hBitmap
= 0;
661 control
= msi_dialog_add_control( dialog
, rec
, szStatic
,
662 SS_BITMAP
| SS_LEFT
| SS_CENTERIMAGE
);
663 text
= MSI_RecordGetString( rec
, 10 );
664 r
= msi_load_bitmap( dialog
->package
->db
, text
, &pic
);
665 if( r
== ERROR_SUCCESS
)
667 r
= IPicture_get_Handle( pic
, &hBitmap
);
669 SendMessageW( control
->hwnd
, STM_SETIMAGE
, IMAGE_BITMAP
, hBitmap
);
673 return ERROR_SUCCESS
;
676 static LPWSTR
msi_create_tmp_path(void)
680 static const WCHAR prefix
[] = { 'm','s','i',0 };
683 r
= GetTempPathW( MAX_PATH
, tmp
);
686 len
= lstrlenW( tmp
) + 20;
687 path
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof (WCHAR
) );
690 r
= GetTempFileNameW( tmp
, prefix
, 0, path
);
693 HeapFree( GetProcessHeap(), 0, path
);
701 msi_load_icon( MSIDATABASE
*db
, LPCWSTR name
, DWORD attributes
, HICON
*picon
)
703 UINT r
= ERROR_FUNCTION_FAILED
;
708 TRACE("loading %s\n", debugstr_w( name
) );
710 tmp
= msi_create_tmp_path();
714 rec
= msi_get_binary_record( db
, name
);
717 r
= MSI_RecordStreamToFile( rec
, 2, tmp
);
718 if( r
== ERROR_SUCCESS
)
720 DWORD cx
= 0, cy
= 0, flags
= LR_LOADFROMFILE
| LR_DEFAULTSIZE
;
722 if( attributes
& msidbControlAttributesFixedSize
)
724 flags
&= ~LR_DEFAULTSIZE
;
725 if( attributes
& msidbControlAttributesIconSize16
)
730 if( attributes
& msidbControlAttributesIconSize32
)
735 /* msidbControlAttributesIconSize48 handled by above logic */
738 hicon
= LoadImageW( 0, tmp
, IMAGE_ICON
, cx
, cy
, flags
);
742 ERR("failed to load icon from %s\n", debugstr_w( tmp
));
745 msiobj_release( &rec
->hdr
);
748 HeapFree( GetProcessHeap(), 0, tmp
);
753 static UINT
msi_dialog_icon_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
755 msi_control
*control
;
763 control
= msi_dialog_add_control( dialog
, rec
, szStatic
,
764 SS_ICON
| SS_CENTERIMAGE
| WS_GROUP
);
765 text
= MSI_RecordGetString( rec
, 10 );
766 attributes
= MSI_RecordGetInteger( rec
, 8 );
767 r
= msi_load_icon( dialog
->package
->db
, text
, attributes
, &hIcon
);
768 if( r
== ERROR_SUCCESS
)
770 r
= SendMessageW( control
->hwnd
, STM_SETICON
, (WPARAM
) hIcon
, 0 );
771 control
->hIcon
= hIcon
;
774 ERR("Failed to load bitmap %s\n", debugstr_w(text
));
775 return ERROR_SUCCESS
;
778 static UINT
msi_dialog_combo_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
780 static const WCHAR szCombo
[] = { 'C','O','M','B','O','B','O','X',0 };
782 msi_dialog_add_control( dialog
, rec
, szCombo
,
783 SS_BITMAP
| SS_LEFT
| SS_CENTERIMAGE
);
784 return ERROR_SUCCESS
;
787 static UINT
msi_dialog_edit_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
789 msi_control
*control
;
793 control
= msi_dialog_add_control( dialog
, rec
, szEdit
,
794 WS_BORDER
| WS_TABSTOP
);
795 control
->handler
= msi_dialog_edit_handler
;
796 prop
= MSI_RecordGetString( rec
, 9 );
798 control
->property
= strdupW( prop
);
799 val
= load_dynamic_property( dialog
->package
, control
->property
, NULL
);
800 SetWindowTextW( control
->hwnd
, val
);
801 HeapFree( GetProcessHeap(), 0, val
);
802 return ERROR_SUCCESS
;
805 /******************** Masked Edit ********************************************/
807 #define MASK_MAX_GROUPS 10
809 struct msi_mask_group
817 struct msi_maskedit_info
825 struct msi_mask_group group
[MASK_MAX_GROUPS
];
828 static void msi_mask_control_change( struct msi_maskedit_info
*info
)
833 val
= HeapAlloc( GetProcessHeap(), 0, (info
->num_chars
+1)*sizeof(WCHAR
) );
834 for( i
=0, n
=0; i
<info
->num_groups
; i
++ )
836 if( (info
->group
[i
].len
+ n
) > info
->num_chars
)
838 ERR("can't fit control %d text into template\n",i
);
841 r
= GetWindowTextW( info
->group
[i
].hwnd
, &val
[n
], info
->group
[i
].len
+1 );
842 if( r
!= info
->group
[i
].len
)
847 TRACE("%d/%d controls were good\n", i
, info
->num_groups
);
849 if( i
== info
->num_groups
)
851 TRACE("Set property %s to %s\n",
852 debugstr_w(info
->prop
), debugstr_w(val
) );
853 CharUpperBuffW( val
, info
->num_chars
);
854 MSI_SetPropertyW( info
->dialog
->package
, info
->prop
, val
);
855 msi_dialog_evaluate_control_conditions( info
->dialog
);
857 HeapFree( GetProcessHeap(), 0, val
);
860 /* now move to the next control if necessary */
861 static VOID
msi_mask_next_control( struct msi_maskedit_info
*info
, HWND hWnd
)
866 for( i
=0; i
<info
->num_groups
; i
++ )
867 if( info
->group
[i
].hwnd
== hWnd
)
870 /* don't move from the last control */
871 if( i
>= (info
->num_groups
-1) )
874 len
= SendMessageW( hWnd
, WM_GETTEXTLENGTH
, 0, 0 );
875 if( len
< info
->group
[i
].len
)
878 hWndNext
= GetNextDlgTabItem( GetParent( hWnd
), hWnd
, FALSE
);
879 SetFocus( hWndNext
);
882 static LRESULT WINAPI
883 MSIMaskedEdit_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
885 struct msi_maskedit_info
*info
;
888 TRACE("%p %04x %08x %08lx\n", hWnd
, msg
, wParam
, lParam
);
890 info
= GetPropW(hWnd
, szButtonData
);
892 r
= CallWindowProcW(info
->oldproc
, hWnd
, msg
, wParam
, lParam
);
897 if (HIWORD(wParam
) == EN_CHANGE
)
899 msi_mask_control_change( info
);
900 msi_mask_next_control( info
, (HWND
) lParam
);
904 HeapFree( GetProcessHeap(), 0, info
->prop
);
905 HeapFree( GetProcessHeap(), 0, info
);
906 RemovePropW( hWnd
, szButtonData
);
913 /* fish the various bits of the property out and put them in the control */
915 msi_maskedit_set_text( struct msi_maskedit_info
*info
, LPCWSTR text
)
921 for( i
= 0; i
< info
->num_groups
; i
++ )
923 if( info
->group
[i
].len
< lstrlenW( p
) )
925 LPWSTR chunk
= strdupW( p
);
926 chunk
[ info
->group
[i
].len
] = 0;
927 SetWindowTextW( info
->group
[i
].hwnd
, chunk
);
928 HeapFree( GetProcessHeap(), 0, chunk
);
932 SetWindowTextW( info
->group
[i
].hwnd
, p
);
935 p
+= info
->group
[i
].len
;
939 static struct msi_maskedit_info
* msi_dialog_parse_groups( LPCWSTR mask
)
941 struct msi_maskedit_info
* info
= NULL
;
942 int i
= 0, n
= 0, total
= 0;
945 TRACE("masked control, template %s\n", debugstr_w(mask
));
950 p
= strchrW(mask
, '<');
954 info
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof *info
);
959 for( i
=0; i
<MASK_MAX_GROUPS
; i
++ )
961 /* stop at the end of the string */
962 if( p
[0] == 0 || p
[0] == '>' )
965 /* count the number of the same identifier */
966 for( n
=0; p
[n
] == p
[0]; n
++ )
968 info
->group
[i
].ofs
= total
;
969 info
->group
[i
].type
= p
[0];
973 total
++; /* an extra not part of the group */
975 info
->group
[i
].len
= n
;
980 TRACE("%d characters in %d groups\n", total
, info
->num_groups
);
981 if( i
== MASK_MAX_GROUPS
)
982 ERR("too many groups in PIDTemplate %s\n", debugstr_w(mask
));
984 info
->num_chars
= total
;
985 info
->num_groups
= i
;
991 msi_maskedit_create_children( struct msi_maskedit_info
*info
)
993 DWORD width
, height
, style
, wx
, ww
;
994 LPCWSTR text
, font
= NULL
;
999 style
= WS_CHILD
| WS_BORDER
| WS_VISIBLE
| WS_TABSTOP
;
1001 GetClientRect( info
->hwnd
, &rect
);
1003 width
= rect
.right
- rect
.left
;
1004 height
= rect
.bottom
- rect
.top
;
1007 font
= msi_dialog_get_style( &text
);
1009 for( i
= 0; i
< info
->num_groups
; i
++ )
1011 wx
= (info
->group
[i
].ofs
* width
) / info
->num_chars
;
1012 ww
= (info
->group
[i
].len
* width
) / info
->num_chars
;
1014 hwnd
= CreateWindowW( szEdit
, NULL
, style
, wx
, 0, ww
, height
,
1015 info
->hwnd
, NULL
, NULL
, NULL
);
1018 ERR("failed to create mask edit sub window\n");
1022 SendMessageW( hwnd
, EM_LIMITTEXT
, info
->group
[i
].len
, 0 );
1024 msi_dialog_set_font( info
->dialog
, hwnd
,
1025 font
? font
: info
->dialog
->default_font
);
1026 info
->group
[i
].hwnd
= hwnd
;
1030 /* office 2003 uses "73931<````=````=````=````=`````>@@@@@" */
1031 static UINT
msi_dialog_maskedit_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1033 const static WCHAR pidt
[] = {'P','I','D','T','e','m','p','l','a','t','e',0};
1034 LPWSTR mask
= NULL
, title
= NULL
, val
= NULL
;
1035 struct msi_maskedit_info
*info
= NULL
;
1036 UINT ret
= ERROR_SUCCESS
;
1037 msi_control
*control
;
1040 mask
= load_dynamic_property( dialog
->package
, pidt
, NULL
);
1043 ERR("PIDTemplate is empty\n");
1047 info
= msi_dialog_parse_groups( mask
);
1050 ERR("template %s is invalid\n", debugstr_w(mask
));
1054 info
->dialog
= dialog
;
1056 control
= msi_dialog_add_control( dialog
, rec
, szStatic
,
1057 SS_OWNERDRAW
| WS_GROUP
| WS_VISIBLE
);
1060 ERR("Failed to create maskedit container\n");
1061 ret
= ERROR_FUNCTION_FAILED
;
1064 SetWindowLongPtrW( control
->hwnd
, GWL_EXSTYLE
, WS_EX_CONTROLPARENT
);
1066 info
->hwnd
= control
->hwnd
;
1068 /* subclass the static control */
1069 info
->oldproc
= (WNDPROC
) SetWindowLongPtrW( info
->hwnd
, GWLP_WNDPROC
,
1070 (LONG_PTR
)MSIMaskedEdit_WndProc
);
1071 SetPropW( control
->hwnd
, szButtonData
, info
);
1073 prop
= MSI_RecordGetString( rec
, 9 );
1075 info
->prop
= strdupW( prop
);
1077 msi_maskedit_create_children( info
);
1081 val
= load_dynamic_property( dialog
->package
, prop
, NULL
);
1084 msi_maskedit_set_text( info
, val
);
1085 HeapFree( GetProcessHeap(), 0, val
);
1090 if( ret
!= ERROR_SUCCESS
)
1091 HeapFree( GetProcessHeap(), 0, info
);
1092 HeapFree( GetProcessHeap(), 0, title
);
1093 HeapFree( GetProcessHeap(), 0, mask
);
1097 /******************** Path Edit ********************************************/
1099 static UINT
msi_dialog_pathedit_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1101 FIXME("not implemented properly\n");
1102 return msi_dialog_edit_control( dialog
, rec
);
1105 /* radio buttons are a bit different from normal controls */
1106 static UINT
msi_dialog_create_radiobutton( MSIRECORD
*rec
, LPVOID param
)
1108 radio_button_group_descr
*group
= (radio_button_group_descr
*)param
;
1109 msi_dialog
*dialog
= group
->dialog
;
1110 msi_control
*control
;
1111 LPCWSTR prop
, text
, name
;
1113 DWORD attributes
= group
->attributes
;
1115 style
= WS_CHILD
| BS_AUTORADIOBUTTON
| BS_MULTILINE
| WS_TABSTOP
;
1116 name
= MSI_RecordGetString( rec
, 3 );
1117 text
= MSI_RecordGetString( rec
, 8 );
1118 if( attributes
& 1 )
1119 style
|= WS_VISIBLE
;
1120 if( ~attributes
& 2 )
1121 style
|= WS_DISABLED
;
1123 control
= msi_dialog_create_window( dialog
, rec
, szButton
, name
, text
,
1124 style
, group
->parent
->hwnd
);
1125 control
->handler
= msi_dialog_radiogroup_handler
;
1127 prop
= MSI_RecordGetString( rec
, 1 );
1129 control
->property
= strdupW( prop
);
1131 return ERROR_SUCCESS
;
1134 static UINT
msi_dialog_radiogroup_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1136 static const WCHAR query
[] = {
1137 'S','E','L','E','C','T',' ','*',' ',
1138 'F','R','O','M',' ','R','a','d','i','o','B','u','t','t','o','n',' ',
1139 'W','H','E','R','E',' ',
1140 '`','P','r','o','p','e','r','t','y','`',' ','=',' ','\'','%','s','\'',0};
1143 msi_control
*control
;
1144 MSIQUERY
*view
= NULL
;
1145 radio_button_group_descr group
;
1146 MSIPACKAGE
*package
= dialog
->package
;
1149 prop
= MSI_RecordGetString( rec
, 9 );
1151 TRACE("%p %p %s\n", dialog
, rec
, debugstr_w( prop
));
1153 /* Create parent group box to hold radio buttons */
1154 control
= msi_dialog_add_control( dialog
, rec
, szButton
, BS_OWNERDRAW
|WS_GROUP
);
1156 return ERROR_FUNCTION_FAILED
;
1158 oldproc
= (WNDPROC
) SetWindowLongPtrW( control
->hwnd
, GWLP_WNDPROC
,
1159 (LONG_PTR
)MSIRadioGroup_WndProc
);
1160 SetPropW(control
->hwnd
, szButtonData
, oldproc
);
1161 SetWindowLongPtrW( control
->hwnd
, GWL_EXSTYLE
, WS_EX_CONTROLPARENT
);
1164 control
->property
= strdupW( prop
);
1166 /* query the Radio Button table for all control in this group */
1167 r
= MSI_OpenQuery( package
->db
, &view
, query
, prop
);
1168 if( r
!= ERROR_SUCCESS
)
1170 ERR("query failed for dialog %s radio group %s\n",
1171 debugstr_w(dialog
->name
), debugstr_w(prop
));
1172 return ERROR_INVALID_PARAMETER
;
1175 group
.dialog
= dialog
;
1176 group
.parent
= control
;
1177 group
.attributes
= MSI_RecordGetInteger( rec
, 8 );
1179 r
= MSI_IterateRecords( view
, 0, msi_dialog_create_radiobutton
, &group
);
1180 msiobj_release( &view
->hdr
);
1185 struct control_handler msi_dialog_handler
[] =
1187 { szText
, msi_dialog_text_control
},
1188 { szPushButton
, msi_dialog_button_control
},
1189 { szLine
, msi_dialog_line_control
},
1190 { szBitmap
, msi_dialog_bitmap_control
},
1191 { szCheckBox
, msi_dialog_checkbox_control
},
1192 { szScrollableText
, msi_dialog_scrolltext_control
},
1193 { szComboBox
, msi_dialog_combo_control
},
1194 { szEdit
, msi_dialog_edit_control
},
1195 { szMaskedEdit
, msi_dialog_maskedit_control
},
1196 { szPathEdit
, msi_dialog_pathedit_control
},
1197 { szRadioButtonGroup
, msi_dialog_radiogroup_control
},
1198 { szIcon
, msi_dialog_icon_control
},
1201 #define NUM_CONTROL_TYPES (sizeof msi_dialog_handler/sizeof msi_dialog_handler[0])
1203 static UINT
msi_dialog_create_controls( MSIRECORD
*rec
, LPVOID param
)
1205 msi_dialog
*dialog
= param
;
1206 LPCWSTR control_type
;
1209 /* find and call the function that can create this type of control */
1210 control_type
= MSI_RecordGetString( rec
, 3 );
1211 for( i
=0; i
<NUM_CONTROL_TYPES
; i
++ )
1212 if (!strcmpiW( msi_dialog_handler
[i
].control_type
, control_type
))
1214 if( i
!= NUM_CONTROL_TYPES
)
1215 msi_dialog_handler
[i
].func( dialog
, rec
);
1217 ERR("no handler for element type %s\n", debugstr_w(control_type
));
1219 return ERROR_SUCCESS
;
1222 static UINT
msi_dialog_fill_controls( msi_dialog
*dialog
)
1224 static const WCHAR query
[] = {
1225 'S','E','L','E','C','T',' ','*',' ',
1226 'F','R','O','M',' ','C','o','n','t','r','o','l',' ',
1227 'W','H','E','R','E',' ',
1228 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',0};
1230 MSIQUERY
*view
= NULL
;
1231 MSIPACKAGE
*package
= dialog
->package
;
1233 TRACE("%p %s\n", dialog
, debugstr_w(dialog
->name
) );
1235 /* query the Control table for all the elements of the control */
1236 r
= MSI_OpenQuery( package
->db
, &view
, query
, dialog
->name
);
1237 if( r
!= ERROR_SUCCESS
)
1239 ERR("query failed for dialog %s\n", debugstr_w(dialog
->name
));
1240 return ERROR_INVALID_PARAMETER
;
1243 r
= MSI_IterateRecords( view
, 0, msi_dialog_create_controls
, dialog
);
1244 msiobj_release( &view
->hdr
);
1249 static UINT
msi_dialog_set_control_condition( MSIRECORD
*rec
, LPVOID param
)
1251 static const WCHAR szHide
[] = { 'H','i','d','e',0 };
1252 static const WCHAR szShow
[] = { 'S','h','o','w',0 };
1253 static const WCHAR szDisable
[] = { 'D','i','s','a','b','l','e',0 };
1254 static const WCHAR szEnable
[] = { 'E','n','a','b','l','e',0 };
1255 msi_dialog
*dialog
= param
;
1256 msi_control
*control
;
1257 LPCWSTR name
, action
, condition
;
1260 name
= MSI_RecordGetString( rec
, 2 );
1261 action
= MSI_RecordGetString( rec
, 3 );
1262 condition
= MSI_RecordGetString( rec
, 4 );
1263 r
= MSI_EvaluateConditionW( dialog
->package
, condition
);
1264 control
= msi_dialog_find_control( dialog
, name
);
1267 TRACE("%s control %s\n", debugstr_w(action
), debugstr_w(name
));
1269 /* FIXME: case sensitive? */
1270 if(!lstrcmpW(action
, szHide
))
1271 ShowWindow(control
->hwnd
, SW_HIDE
);
1272 else if(!strcmpW(action
, szShow
))
1273 ShowWindow(control
->hwnd
, SW_SHOW
);
1274 else if(!strcmpW(action
, szDisable
))
1275 EnableWindow(control
->hwnd
, FALSE
);
1276 else if(!strcmpW(action
, szEnable
))
1277 EnableWindow(control
->hwnd
, TRUE
);
1279 FIXME("Unhandled action %s\n", debugstr_w(action
));
1282 return ERROR_SUCCESS
;
1285 static UINT
msi_dialog_evaluate_control_conditions( msi_dialog
*dialog
)
1287 static const WCHAR query
[] = {
1288 'S','E','L','E','C','T',' ','*',' ',
1289 'F','R','O','M',' ',
1290 'C','o','n','t','r','o','l','C','o','n','d','i','t','i','o','n',' ',
1291 'W','H','E','R','E',' ',
1292 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',0
1295 MSIQUERY
*view
= NULL
;
1296 MSIPACKAGE
*package
= dialog
->package
;
1298 TRACE("%p %s\n", dialog
, debugstr_w(dialog
->name
) );
1300 /* query the Control table for all the elements of the control */
1301 r
= MSI_OpenQuery( package
->db
, &view
, query
, dialog
->name
);
1302 if( r
!= ERROR_SUCCESS
)
1304 ERR("query failed for dialog %s\n", debugstr_w(dialog
->name
));
1305 return ERROR_INVALID_PARAMETER
;
1308 r
= MSI_IterateRecords( view
, 0, msi_dialog_set_control_condition
, dialog
);
1309 msiobj_release( &view
->hdr
);
1314 /* figure out the height of 10 point MS Sans Serif */
1315 static INT
msi_dialog_get_sans_serif_height( HWND hwnd
)
1317 static const WCHAR szSansSerif
[] = {
1318 'M','S',' ','S','a','n','s',' ','S','e','r','i','f',0 };
1323 HFONT hFont
, hOldFont
;
1326 hdc
= GetDC( hwnd
);
1329 memset( &lf
, 0, sizeof lf
);
1330 lf
.lfHeight
= MulDiv(10, GetDeviceCaps(hdc
, LOGPIXELSY
), 72);
1331 strcpyW( lf
.lfFaceName
, szSansSerif
);
1332 hFont
= CreateFontIndirectW(&lf
);
1335 hOldFont
= SelectObject( hdc
, hFont
);
1336 r
= GetTextMetricsW( hdc
, &tm
);
1338 height
= tm
.tmHeight
;
1339 SelectObject( hdc
, hOldFont
);
1340 DeleteObject( hFont
);
1342 ReleaseDC( hwnd
, hdc
);
1347 /* fetch the associated record from the Dialog table */
1348 static MSIRECORD
*msi_get_dialog_record( msi_dialog
*dialog
)
1350 static const WCHAR query
[] = {
1351 'S','E','L','E','C','T',' ','*',' ',
1352 'F','R','O','M',' ','D','i','a','l','o','g',' ',
1353 'W','H','E','R','E',' ',
1354 '`','D','i','a','l','o','g','`',' ','=',' ','\'','%','s','\'',0};
1355 MSIPACKAGE
*package
= dialog
->package
;
1356 MSIRECORD
*rec
= NULL
;
1358 TRACE("%p %s\n", dialog
, debugstr_w(dialog
->name
) );
1360 rec
= MSI_QueryGetRecord( package
->db
, query
, dialog
->name
);
1362 ERR("query failed for dialog %s\n", debugstr_w(dialog
->name
));
1367 static void msi_dialog_adjust_dialog_size( msi_dialog
*dialog
, LPSIZE sz
)
1372 /* turn the client size into the window rectangle */
1375 rect
.right
= msi_dialog_scale_unit( dialog
, sz
->cx
);
1376 rect
.bottom
= msi_dialog_scale_unit( dialog
, sz
->cy
);
1377 style
= GetWindowLongPtrW( dialog
->hwnd
, GWL_STYLE
);
1378 AdjustWindowRect( &rect
, style
, FALSE
);
1379 sz
->cx
= rect
.right
- rect
.left
;
1380 sz
->cy
= rect
.bottom
- rect
.top
;
1383 static BOOL
msi_control_set_next( msi_control
*control
, msi_control
*next
)
1385 return SetWindowPos( next
->hwnd
, control
->hwnd
, 0, 0, 0, 0,
1386 SWP_NOMOVE
| SWP_NOOWNERZORDER
| SWP_NOREDRAW
|
1387 SWP_NOREPOSITION
| SWP_NOSENDCHANGING
| SWP_NOSIZE
);
1390 static UINT
msi_dialog_set_tab_order( msi_dialog
*dialog
)
1392 msi_control
*control
, *tab_next
;
1394 for( control
= dialog
->control_list
; control
; control
= control
->next
)
1396 tab_next
= msi_dialog_find_control( dialog
, control
->tabnext
);
1399 msi_control_set_next( control
, tab_next
);
1402 return ERROR_SUCCESS
;
1405 static LRESULT
msi_dialog_oncreate( HWND hwnd
, LPCREATESTRUCTW cs
)
1407 static const WCHAR df
[] = {
1408 'D','e','f','a','u','l','t','U','I','F','o','n','t',0 };
1409 msi_dialog
*dialog
= (msi_dialog
*) cs
->lpCreateParams
;
1410 MSIRECORD
*rec
= NULL
;
1412 LPWSTR title
= NULL
;
1415 TRACE("%p %p\n", dialog
, dialog
->package
);
1417 dialog
->hwnd
= hwnd
;
1418 SetWindowLongPtrW( hwnd
, GWLP_USERDATA
, (LONG_PTR
) dialog
);
1420 rec
= msi_get_dialog_record( dialog
);
1423 TRACE("No record found for dialog %s\n", debugstr_w(dialog
->name
));
1427 dialog
->scale
= msi_dialog_get_sans_serif_height(dialog
->hwnd
);
1429 size
.cx
= MSI_RecordGetInteger( rec
, 4 );
1430 size
.cy
= MSI_RecordGetInteger( rec
, 5 );
1431 msi_dialog_adjust_dialog_size( dialog
, &size
);
1433 dialog
->attributes
= MSI_RecordGetInteger( rec
, 6 );
1434 text
= MSI_RecordGetString( rec
, 7 );
1436 dialog
->default_font
= load_dynamic_property( dialog
->package
, df
, NULL
);
1438 deformat_string( dialog
->package
, text
, &title
);
1439 SetWindowTextW( hwnd
, title
);
1440 SetWindowPos( hwnd
, 0, 0, 0, size
.cx
, size
.cy
,
1441 SWP_NOMOVE
| SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_NOREDRAW
);
1443 HeapFree( GetProcessHeap(), 0, title
);
1444 msiobj_release( &rec
->hdr
);
1446 msi_dialog_build_font_list( dialog
);
1447 msi_dialog_fill_controls( dialog
);
1448 msi_dialog_evaluate_control_conditions( dialog
);
1449 msi_dialog_set_tab_order( dialog
);
1454 static UINT
msi_dialog_send_event( msi_dialog
*dialog
, LPCWSTR event
, LPCWSTR arg
)
1456 LPWSTR event_fmt
= NULL
, arg_fmt
= NULL
;
1458 TRACE("Sending control event %s %s\n", debugstr_w(event
), debugstr_w(arg
));
1460 deformat_string( dialog
->package
, event
, &event_fmt
);
1461 deformat_string( dialog
->package
, arg
, &arg_fmt
);
1463 dialog
->event_handler( dialog
->package
, event_fmt
, arg_fmt
, dialog
);
1465 HeapFree( GetProcessHeap(), 0, event_fmt
);
1466 HeapFree( GetProcessHeap(), 0, arg_fmt
);
1468 return ERROR_SUCCESS
;
1471 static UINT
msi_dialog_set_property( msi_dialog
*dialog
, LPCWSTR event
, LPCWSTR arg
)
1473 static const WCHAR szNullArg
[] = { '{','}',0 };
1474 LPWSTR p
, prop
, arg_fmt
= NULL
;
1477 len
= strlenW(event
);
1478 prop
= HeapAlloc( GetProcessHeap(), 0, len
*sizeof(WCHAR
));
1479 strcpyW( prop
, &event
[1] );
1480 p
= strchrW( prop
, ']' );
1481 if( p
&& p
[1] == 0 )
1484 if( strcmpW( szNullArg
, arg
) )
1485 deformat_string( dialog
->package
, arg
, &arg_fmt
);
1486 MSI_SetPropertyW( dialog
->package
, prop
, arg_fmt
);
1489 ERR("Badly formatted property string - what happens?\n");
1490 HeapFree( GetProcessHeap(), 0, prop
);
1491 return ERROR_SUCCESS
;
1494 static UINT
msi_dialog_control_event( MSIRECORD
*rec
, LPVOID param
)
1496 msi_dialog
*dialog
= param
;
1497 LPCWSTR condition
, event
, arg
;
1500 condition
= MSI_RecordGetString( rec
, 5 );
1501 r
= MSI_EvaluateConditionW( dialog
->package
, condition
);
1504 event
= MSI_RecordGetString( rec
, 3 );
1505 arg
= MSI_RecordGetString( rec
, 4 );
1506 if( event
[0] == '[' )
1507 msi_dialog_set_property( dialog
, event
, arg
);
1509 msi_dialog_send_event( dialog
, event
, arg
);
1512 return ERROR_SUCCESS
;
1515 static UINT
msi_dialog_button_handler( msi_dialog
*dialog
,
1516 msi_control
*control
, WPARAM param
)
1518 static const WCHAR query
[] = {
1519 'S','E','L','E','C','T',' ','*',' ',
1520 'F','R','O','M',' ','C','o','n','t','r','o','l','E','v','e','n','t',' ',
1521 'W','H','E','R','E',' ',
1522 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',' ',
1524 '`','C','o','n','t','r','o','l','_','`',' ','=',' ','\'','%','s','\'',' ',
1525 'O','R','D','E','R',' ','B','Y',' ','`','O','r','d','e','r','i','n','g','`',0
1527 MSIQUERY
*view
= NULL
;
1530 if( HIWORD(param
) != BN_CLICKED
)
1531 return ERROR_SUCCESS
;
1533 r
= MSI_OpenQuery( dialog
->package
->db
, &view
, query
,
1534 dialog
->name
, control
->name
);
1535 if( r
!= ERROR_SUCCESS
)
1537 ERR("query failed\n");
1541 r
= MSI_IterateRecords( view
, 0, msi_dialog_control_event
, dialog
);
1542 msiobj_release( &view
->hdr
);
1547 static UINT
msi_dialog_get_checkbox_state( msi_dialog
*dialog
,
1548 msi_control
*control
)
1550 WCHAR state
[2] = { 0 };
1553 MSI_GetPropertyW( dialog
->package
, control
->property
, state
, &sz
);
1554 return state
[0] ? 1 : 0;
1557 static void msi_dialog_set_checkbox_state( msi_dialog
*dialog
,
1558 msi_control
*control
, UINT state
)
1560 static const WCHAR szState
[] = { '1', 0 };
1563 /* if uncheck then the property is set to NULL */
1566 MSI_SetPropertyW( dialog
->package
, control
->property
, NULL
);
1570 /* check for a custom state */
1571 if (control
->value
&& control
->value
[0])
1572 val
= control
->value
;
1576 MSI_SetPropertyW( dialog
->package
, control
->property
, val
);
1579 static void msi_dialog_checkbox_sync_state( msi_dialog
*dialog
,
1580 msi_control
*control
)
1584 state
= msi_dialog_get_checkbox_state( dialog
, control
);
1585 SendMessageW( control
->hwnd
, BM_SETCHECK
,
1586 state
? BST_CHECKED
: BST_UNCHECKED
, 0 );
1589 static UINT
msi_dialog_checkbox_handler( msi_dialog
*dialog
,
1590 msi_control
*control
, WPARAM param
)
1594 if( HIWORD(param
) != BN_CLICKED
)
1595 return ERROR_SUCCESS
;
1597 TRACE("clicked checkbox %s, set %s\n", debugstr_w(control
->name
),
1598 debugstr_w(control
->property
));
1600 state
= msi_dialog_get_checkbox_state( dialog
, control
);
1601 state
= state
? 0 : 1;
1602 msi_dialog_set_checkbox_state( dialog
, control
, state
);
1603 msi_dialog_checkbox_sync_state( dialog
, control
);
1605 return msi_dialog_button_handler( dialog
, control
, param
);
1608 static UINT
msi_dialog_edit_handler( msi_dialog
*dialog
,
1609 msi_control
*control
, WPARAM param
)
1614 if( HIWORD(param
) != EN_CHANGE
)
1615 return ERROR_SUCCESS
;
1617 TRACE("edit %s contents changed, set %s\n", debugstr_w(control
->name
),
1618 debugstr_w(control
->property
));
1621 buf
= HeapAlloc( GetProcessHeap(), 0, sz
*sizeof(WCHAR
) );
1624 r
= GetWindowTextW( control
->hwnd
, buf
, sz
);
1628 buf
= HeapReAlloc( GetProcessHeap(), 0, buf
, sz
*sizeof(WCHAR
) );
1631 MSI_SetPropertyW( dialog
->package
, control
->property
, buf
);
1633 HeapFree( GetProcessHeap(), 0, buf
);
1635 return ERROR_SUCCESS
;
1638 static UINT
msi_dialog_radiogroup_handler( msi_dialog
*dialog
,
1639 msi_control
*control
, WPARAM param
)
1641 if( HIWORD(param
) != BN_CLICKED
)
1642 return ERROR_SUCCESS
;
1644 TRACE("clicked radio button %s, set %s\n", debugstr_w(control
->name
),
1645 debugstr_w(control
->property
));
1647 MSI_SetPropertyW( dialog
->package
, control
->property
, control
->name
);
1649 return msi_dialog_button_handler( dialog
, control
, param
);
1652 static LRESULT
msi_dialog_oncommand( msi_dialog
*dialog
, WPARAM param
, HWND hwnd
)
1654 msi_control
*control
;
1656 TRACE("%p %p %08x\n", dialog
, hwnd
, param
);
1658 control
= msi_dialog_find_control_by_hwnd( dialog
, hwnd
);
1661 if( control
->handler
)
1663 control
->handler( dialog
, control
, param
);
1664 msi_dialog_evaluate_control_conditions( dialog
);
1668 ERR("button click from nowhere\n");
1672 static LRESULT WINAPI
MSIDialog_WndProc( HWND hwnd
, UINT msg
,
1673 WPARAM wParam
, LPARAM lParam
)
1675 msi_dialog
*dialog
= (LPVOID
) GetWindowLongPtrW( hwnd
, GWLP_USERDATA
);
1677 TRACE("0x%04x\n", msg
);
1682 return msi_dialog_oncreate( hwnd
, (LPCREATESTRUCTW
)lParam
);
1685 return msi_dialog_oncommand( dialog
, wParam
, (HWND
)lParam
);
1687 /* bounce back to our subclassed static control */
1688 case WM_CTLCOLORSTATIC
:
1689 return SendMessageW( (HWND
) lParam
, WM_CTLCOLORSTATIC
, wParam
, lParam
);
1692 dialog
->hwnd
= NULL
;
1695 return DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
1698 static LRESULT WINAPI
MSIRadioGroup_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1700 WNDPROC oldproc
= (WNDPROC
) GetPropW(hWnd
, szButtonData
);
1702 TRACE("hWnd %p msg %04x wParam 0x%08x lParam 0x%08lx\n", hWnd
, msg
, wParam
, lParam
);
1704 if (msg
== WM_COMMAND
) /* Forward notifications to dialog */
1705 SendMessageW(GetParent(hWnd
), msg
, wParam
, lParam
);
1707 return CallWindowProcW(oldproc
, hWnd
, msg
, wParam
, lParam
);
1710 static LRESULT WINAPI
MSIHiddenWindowProc( HWND hwnd
, UINT msg
,
1711 WPARAM wParam
, LPARAM lParam
)
1713 msi_dialog
*dialog
= (msi_dialog
*) lParam
;
1715 TRACE("%d %p\n", msg
, dialog
);
1719 case WM_MSI_DIALOG_CREATE
:
1720 return msi_dialog_run_message_loop( dialog
);
1721 case WM_MSI_DIALOG_DESTROY
:
1722 msi_dialog_destroy( dialog
);
1725 return DefWindowProcW( hwnd
, msg
, wParam
, lParam
);
1728 /* functions that interface to other modules within MSI */
1730 msi_dialog
*msi_dialog_create( MSIPACKAGE
* package
, LPCWSTR szDialogName
,
1731 msi_dialog_event_handler event_handler
)
1733 MSIRECORD
*rec
= NULL
;
1736 TRACE("%p %s\n", package
, debugstr_w(szDialogName
));
1738 /* allocate the structure for the dialog to use */
1739 dialog
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
,
1740 sizeof *dialog
+ sizeof(WCHAR
)*strlenW(szDialogName
) );
1743 strcpyW( dialog
->name
, szDialogName
);
1744 msiobj_addref( &package
->hdr
);
1745 dialog
->package
= package
;
1746 dialog
->event_handler
= event_handler
;
1747 dialog
->finished
= 0;
1749 /* verify that the dialog exists */
1750 rec
= msi_get_dialog_record( dialog
);
1753 HeapFree( GetProcessHeap(), 0, dialog
);
1756 dialog
->attributes
= MSI_RecordGetInteger( rec
, 6 );
1757 msiobj_release( &rec
->hdr
);
1762 static void msi_process_pending_messages( HWND hdlg
)
1766 while( PeekMessageW( &msg
, 0, 0, 0, PM_REMOVE
) )
1768 if( hdlg
&& IsDialogMessageW( hdlg
, &msg
))
1770 TranslateMessage( &msg
);
1771 DispatchMessageW( &msg
);
1775 void msi_dialog_end_dialog( msi_dialog
*dialog
)
1777 TRACE("%p\n", dialog
);
1778 dialog
->finished
= 1;
1779 PostMessageW(dialog
->hwnd
, WM_NULL
, 0, 0);
1782 void msi_dialog_check_messages( HANDLE handle
)
1786 /* in threads other than the UI thread, block */
1787 if( uiThreadId
!= GetCurrentThreadId() )
1790 WaitForSingleObject( handle
, INFINITE
);
1794 /* there's two choices for the UI thread */
1797 msi_process_pending_messages( NULL
);
1803 * block here until somebody creates a new dialog or
1804 * the handle we're waiting on becomes ready
1806 r
= MsgWaitForMultipleObjects( 1, &handle
, 0, INFINITE
, QS_ALLINPUT
);
1807 if( r
== WAIT_OBJECT_0
)
1812 UINT
msi_dialog_run_message_loop( msi_dialog
*dialog
)
1816 if( !(dialog
->attributes
& msidbDialogAttributesVisible
) )
1817 return ERROR_SUCCESS
;
1819 if( uiThreadId
!= GetCurrentThreadId() )
1820 return SendMessageW( hMsiHiddenWindow
, WM_MSI_DIALOG_CREATE
, 0, (LPARAM
) dialog
);
1822 /* create the dialog window, don't show it yet */
1823 hwnd
= CreateWindowW( szMsiDialogClass
, dialog
->name
, WS_OVERLAPPEDWINDOW
,
1824 CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
,
1825 NULL
, NULL
, NULL
, dialog
);
1828 ERR("Failed to create dialog %s\n", debugstr_w( dialog
->name
));
1829 return ERROR_FUNCTION_FAILED
;
1832 ShowWindow( hwnd
, SW_SHOW
);
1833 UpdateWindow( hwnd
);
1835 if( dialog
->attributes
& msidbDialogAttributesModal
)
1837 while( !dialog
->finished
)
1839 MsgWaitForMultipleObjects( 0, NULL
, 0, INFINITE
, QS_ALLEVENTS
);
1840 msi_process_pending_messages( dialog
->hwnd
);
1844 return ERROR_IO_PENDING
;
1846 return ERROR_SUCCESS
;
1849 void msi_dialog_do_preview( msi_dialog
*dialog
)
1852 dialog
->attributes
|= msidbDialogAttributesVisible
;
1853 dialog
->attributes
&= ~msidbDialogAttributesModal
;
1854 msi_dialog_run_message_loop( dialog
);
1857 void msi_dialog_destroy( msi_dialog
*dialog
)
1859 if( uiThreadId
!= GetCurrentThreadId() )
1861 SendMessageW( hMsiHiddenWindow
, WM_MSI_DIALOG_DESTROY
, 0, (LPARAM
) dialog
);
1866 ShowWindow( dialog
->hwnd
, SW_HIDE
);
1868 /* destroy the list of controls */
1869 while( dialog
->control_list
)
1871 msi_control
*t
= dialog
->control_list
;
1872 dialog
->control_list
= t
->next
;
1873 /* leave dialog->hwnd - destroying parent destroys child windows */
1874 HeapFree( GetProcessHeap(), 0, t
->property
);
1875 HeapFree( GetProcessHeap(), 0, t
->value
);
1877 IPicture_Release( t
->pic
);
1879 DestroyIcon( t
->hIcon
);
1880 HeapFree( GetProcessHeap(), 0, t
->tabnext
);
1881 HeapFree( GetProcessHeap(), 0, t
);
1884 /* destroy the list of fonts */
1885 while( dialog
->font_list
)
1887 msi_font
*t
= dialog
->font_list
;
1888 dialog
->font_list
= t
->next
;
1889 DeleteObject( t
->hfont
);
1890 HeapFree( GetProcessHeap(), 0, t
);
1892 HeapFree( GetProcessHeap(), 0, dialog
->default_font
);
1895 DestroyWindow( dialog
->hwnd
);
1897 msiobj_release( &dialog
->package
->hdr
);
1898 dialog
->package
= NULL
;
1899 HeapFree( GetProcessHeap(), 0, dialog
);
1902 BOOL
msi_dialog_register_class( void )
1906 ZeroMemory( &cls
, sizeof cls
);
1907 cls
.lpfnWndProc
= MSIDialog_WndProc
;
1908 cls
.hInstance
= NULL
;
1909 cls
.hIcon
= LoadIconW(0, (LPWSTR
)IDI_APPLICATION
);
1910 cls
.hCursor
= LoadCursorW(0, (LPWSTR
)IDC_ARROW
);
1911 cls
.hbrBackground
= (HBRUSH
)(COLOR_WINDOW
);
1912 cls
.lpszMenuName
= NULL
;
1913 cls
.lpszClassName
= szMsiDialogClass
;
1915 if( !RegisterClassW( &cls
) )
1918 cls
.lpfnWndProc
= MSIHiddenWindowProc
;
1919 cls
.lpszClassName
= szMsiHiddenWindow
;
1921 if( !RegisterClassW( &cls
) )
1924 uiThreadId
= GetCurrentThreadId();
1926 hMsiHiddenWindow
= CreateWindowW( szMsiHiddenWindow
, NULL
, WS_OVERLAPPED
,
1927 0, 0, 100, 100, NULL
, NULL
, NULL
, NULL
);
1928 if( !hMsiHiddenWindow
)
1931 hRichedit
= LoadLibraryA("riched20");
1936 void msi_dialog_unregister_class( void )
1938 DestroyWindow( hMsiHiddenWindow
);
1939 UnregisterClassW( szMsiDialogClass
, NULL
);
1941 FreeLibrary( hRichedit
);