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
38 #include "wine/debug.h"
39 #include "wine/unicode.h"
43 WINE_DEFAULT_DEBUG_CHANNEL(msi
);
46 struct msi_control_tag
;
47 typedef struct msi_control_tag msi_control
;
48 typedef UINT (*msi_handler
)( msi_dialog
*, msi_control
*, WPARAM
);
50 struct msi_control_tag
64 typedef struct msi_font_tag
66 struct msi_font_tag
*next
;
74 msi_dialog_event_handler event_handler
;
86 typedef UINT (*msi_dialog_control_func
)( msi_dialog
*dialog
, MSIRECORD
*rec
);
87 struct control_handler
90 msi_dialog_control_func func
;
98 } radio_button_group_descr
;
100 const WCHAR szMsiDialogClass
[] = {
101 'M','s','i','D','i','a','l','o','g','C','l','o','s','e','C','l','a','s','s',0
103 const WCHAR szMsiHiddenWindow
[] = {
104 'M','s','i','H','i','d','d','e','n','W','i','n','d','o','w',0 };
105 const static WCHAR szStatic
[] = { 'S','t','a','t','i','c',0 };
106 const static WCHAR szButton
[] = { 'B','U','T','T','O','N', 0 };
107 const static WCHAR szButtonData
[] = { 'M','S','I','D','A','T','A',0 };
108 static const WCHAR szText
[] = { 'T','e','x','t',0 };
109 static const WCHAR szPushButton
[] = { 'P','u','s','h','B','u','t','t','o','n',0 };
110 static const WCHAR szLine
[] = { 'L','i','n','e',0 };
111 static const WCHAR szBitmap
[] = { 'B','i','t','m','a','p',0 };
112 static const WCHAR szCheckBox
[] = { 'C','h','e','c','k','B','o','x',0 };
113 static const WCHAR szScrollableText
[] = {
114 'S','c','r','o','l','l','a','b','l','e','T','e','x','t',0 };
115 static const WCHAR szComboBox
[] = { 'C','o','m','b','o','B','o','x',0 };
116 static const WCHAR szEdit
[] = { 'E','d','i','t',0 };
117 static const WCHAR szMaskedEdit
[] = { 'M','a','s','k','e','d','E','d','i','t',0 };
118 static const WCHAR szPathEdit
[] = { 'P','a','t','h','E','d','i','t',0 };
119 static const WCHAR szProgressBar
[] = {
120 'P','r','o','g','r','e','s','s','B','a','r',0 };
121 static const WCHAR szRadioButtonGroup
[] = {
122 'R','a','d','i','o','B','u','t','t','o','n','G','r','o','u','p',0 };
123 static const WCHAR szIcon
[] = { 'I','c','o','n',0 };
125 static UINT
msi_dialog_checkbox_handler( msi_dialog
*, msi_control
*, WPARAM
);
126 static void msi_dialog_checkbox_sync_state( msi_dialog
*, msi_control
* );
127 static UINT
msi_dialog_button_handler( msi_dialog
*, msi_control
*, WPARAM
);
128 static UINT
msi_dialog_edit_handler( msi_dialog
*, msi_control
*, WPARAM
);
129 static UINT
msi_dialog_radiogroup_handler( msi_dialog
*, msi_control
*, WPARAM param
);
130 static UINT
msi_dialog_evaluate_control_conditions( msi_dialog
*dialog
);
131 static LRESULT WINAPI
MSIRadioGroup_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
);
134 /* dialog sequencing */
136 #define WM_MSI_DIALOG_CREATE (WM_USER+0x100)
137 #define WM_MSI_DIALOG_DESTROY (WM_USER+0x101)
139 static DWORD uiThreadId
;
140 static HWND hMsiHiddenWindow
;
142 static INT
msi_dialog_scale_unit( msi_dialog
*dialog
, INT val
)
144 return (dialog
->scale
* val
+ 5) / 10;
147 static msi_control
*msi_dialog_find_control( msi_dialog
*dialog
, LPCWSTR name
)
149 msi_control
*control
;
153 LIST_FOR_EACH_ENTRY( control
, &dialog
->controls
, msi_control
, entry
)
154 if( !strcmpW( control
->name
, name
) ) /* FIXME: case sensitive? */
159 static msi_control
*msi_dialog_find_control_by_hwnd( msi_dialog
*dialog
, HWND hwnd
)
161 msi_control
*control
;
163 LIST_FOR_EACH_ENTRY( control
, &dialog
->controls
, msi_control
, entry
)
164 if( hwnd
== control
->hwnd
)
169 static LPWSTR
msi_get_deformatted_field( MSIPACKAGE
*package
, MSIRECORD
*rec
, int field
)
171 LPCWSTR str
= MSI_RecordGetString( rec
, field
);
175 deformat_string( package
, str
, &ret
);
180 * msi_dialog_get_style
182 * Extract the {\style} string from the front of the text to display and
183 * update the pointer.
185 static LPWSTR
msi_dialog_get_style( LPCWSTR p
, LPCWSTR
*rest
)
196 q
= strchrW( p
, '}' );
199 if( *p
== '\\' || *p
== '&' )
202 /* little bit of sanity checking to stop us getting confused with RTF */
204 if( *i
== '}' || *i
== '\\' )
210 ret
= msi_alloc( len
*sizeof(WCHAR
) );
213 memcpy( ret
, p
, len
*sizeof(WCHAR
) );
218 static UINT
msi_dialog_add_font( MSIRECORD
*rec
, LPVOID param
)
220 msi_dialog
*dialog
= param
;
227 /* create a font and add it to the list */
228 name
= MSI_RecordGetString( rec
, 1 );
229 font
= msi_alloc( sizeof *font
+ strlenW( name
)*sizeof (WCHAR
) );
230 strcpyW( font
->name
, name
);
231 font
->next
= dialog
->font_list
;
232 dialog
->font_list
= font
;
234 memset( &lf
, 0, sizeof lf
);
235 face
= MSI_RecordGetString( rec
, 2 );
236 lf
.lfHeight
= MSI_RecordGetInteger( rec
, 3 );
237 style
= MSI_RecordGetInteger( rec
, 5 );
238 if( style
& msidbTextStyleStyleBitsBold
)
239 lf
.lfWeight
= FW_BOLD
;
240 if( style
& msidbTextStyleStyleBitsItalic
)
242 if( style
& msidbTextStyleStyleBitsUnderline
)
243 lf
.lfUnderline
= TRUE
;
244 if( style
& msidbTextStyleStyleBitsStrike
)
245 lf
.lfStrikeOut
= TRUE
;
246 lstrcpynW( lf
.lfFaceName
, face
, LF_FACESIZE
);
248 /* adjust the height */
249 hdc
= GetDC( dialog
->hwnd
);
252 lf
.lfHeight
= -MulDiv(lf
.lfHeight
, GetDeviceCaps(hdc
, LOGPIXELSY
), 72);
253 ReleaseDC( dialog
->hwnd
, hdc
);
256 font
->hfont
= CreateFontIndirectW( &lf
);
258 TRACE("Adding font style %s\n", debugstr_w(font
->name
) );
260 return ERROR_SUCCESS
;
263 static msi_font
*msi_dialog_find_font( msi_dialog
*dialog
, LPCWSTR name
)
267 for( font
= dialog
->font_list
; font
; font
= font
->next
)
268 if( !strcmpW( font
->name
, name
) ) /* FIXME: case sensitive? */
274 static UINT
msi_dialog_set_font( msi_dialog
*dialog
, HWND hwnd
, LPCWSTR name
)
278 font
= msi_dialog_find_font( dialog
, name
);
280 SendMessageW( hwnd
, WM_SETFONT
, (WPARAM
) font
->hfont
, TRUE
);
282 ERR("No font entry for %s\n", debugstr_w(name
));
283 return ERROR_SUCCESS
;
286 static UINT
msi_dialog_build_font_list( msi_dialog
*dialog
)
288 static const WCHAR query
[] = {
289 'S','E','L','E','C','T',' ','*',' ',
290 'F','R','O','M',' ','`','T','e','x','t','S','t','y','l','e','`',' ',0
293 MSIQUERY
*view
= NULL
;
295 TRACE("dialog %p\n", dialog
);
297 r
= MSI_OpenQuery( dialog
->package
->db
, &view
, query
);
298 if( r
!= ERROR_SUCCESS
)
301 r
= MSI_IterateRecords( view
, NULL
, msi_dialog_add_font
, dialog
);
302 msiobj_release( &view
->hdr
);
307 static msi_control
*msi_dialog_create_window( msi_dialog
*dialog
,
308 MSIRECORD
*rec
, LPCWSTR szCls
, LPCWSTR name
, LPCWSTR text
,
309 DWORD style
, HWND parent
)
311 DWORD x
, y
, width
, height
;
312 LPWSTR font
= NULL
, title_font
= NULL
;
313 LPCWSTR title
= NULL
;
314 msi_control
*control
;
318 control
= msi_alloc( sizeof *control
+ strlenW(name
)*sizeof(WCHAR
) );
319 strcpyW( control
->name
, name
);
320 list_add_head( &dialog
->controls
, &control
->entry
);
321 control
->handler
= NULL
;
322 control
->property
= NULL
;
323 control
->value
= NULL
;
324 control
->hBitmap
= NULL
;
325 control
->hIcon
= NULL
;
326 control
->hDll
= NULL
;
327 control
->tabnext
= strdupW( MSI_RecordGetString( rec
, 11) );
329 x
= MSI_RecordGetInteger( rec
, 4 );
330 y
= MSI_RecordGetInteger( rec
, 5 );
331 width
= MSI_RecordGetInteger( rec
, 6 );
332 height
= MSI_RecordGetInteger( rec
, 7 );
334 x
= msi_dialog_scale_unit( dialog
, x
);
335 y
= msi_dialog_scale_unit( dialog
, y
);
336 width
= msi_dialog_scale_unit( dialog
, width
);
337 height
= msi_dialog_scale_unit( dialog
, height
);
341 deformat_string( dialog
->package
, text
, &title_font
);
342 font
= msi_dialog_get_style( title_font
, &title
);
345 control
->hwnd
= CreateWindowW( szCls
, title
, style
,
346 x
, y
, width
, height
, parent
, NULL
, NULL
, NULL
);
348 TRACE("Dialog %s control %s hwnd %p\n",
349 debugstr_w(dialog
->name
), debugstr_w(text
), control
->hwnd
);
351 msi_dialog_set_font( dialog
, control
->hwnd
,
352 font
? font
: dialog
->default_font
);
354 msi_free( title_font
);
360 static MSIRECORD
*msi_get_binary_record( MSIDATABASE
*db
, LPCWSTR name
)
362 const static WCHAR query
[] = {
363 's','e','l','e','c','t',' ','*',' ',
364 'f','r','o','m',' ','B','i','n','a','r','y',' ',
365 'w','h','e','r','e',' ',
366 '`','N','a','m','e','`',' ','=',' ','\'','%','s','\'',0
369 return MSI_QueryGetRecord( db
, query
, name
);
372 static LPWSTR
msi_create_tmp_path(void)
376 static const WCHAR prefix
[] = { 'm','s','i',0 };
379 r
= GetTempPathW( MAX_PATH
, tmp
);
382 len
= lstrlenW( tmp
) + 20;
383 path
= msi_alloc( len
* sizeof (WCHAR
) );
386 r
= GetTempFileNameW( tmp
, prefix
, 0, path
);
397 static HANDLE
msi_load_image( MSIDATABASE
*db
, LPCWSTR name
, UINT type
,
398 UINT cx
, UINT cy
, UINT flags
)
400 MSIRECORD
*rec
= NULL
;
401 HANDLE himage
= NULL
;
405 TRACE("%p %s %u %u %08x\n", db
, debugstr_w(name
), cx
, cy
, flags
);
407 tmp
= msi_create_tmp_path();
411 rec
= msi_get_binary_record( db
, name
);
414 r
= MSI_RecordStreamToFile( rec
, 2, tmp
);
415 if( r
== ERROR_SUCCESS
)
417 himage
= LoadImageW( 0, tmp
, type
, cx
, cy
, flags
);
420 msiobj_release( &rec
->hdr
);
427 static HICON
msi_load_icon( MSIDATABASE
*db
, LPCWSTR text
, UINT attributes
)
429 DWORD cx
= 0, cy
= 0, flags
;
431 flags
= LR_LOADFROMFILE
| LR_DEFAULTSIZE
;
432 if( attributes
& msidbControlAttributesFixedSize
)
434 flags
&= ~LR_DEFAULTSIZE
;
435 if( attributes
& msidbControlAttributesIconSize16
)
440 if( attributes
& msidbControlAttributesIconSize32
)
445 /* msidbControlAttributesIconSize48 handled by above logic */
447 return msi_load_image( db
, text
, IMAGE_ICON
, cx
, cy
, flags
);
451 /* called from the Control Event subscription code */
452 void msi_dialog_handle_event( msi_dialog
* dialog
, LPCWSTR control
,
453 LPCWSTR attribute
, MSIRECORD
*rec
)
458 ctrl
= msi_dialog_find_control( dialog
, control
);
461 if( lstrcmpW(attribute
, szText
) )
463 ERR("Attribute %s\n", debugstr_w(attribute
));
466 text
= MSI_RecordGetString( rec
, 1 );
467 SetWindowTextW( ctrl
->hwnd
, text
);
468 msi_dialog_check_messages( NULL
);
471 static void msi_dialog_map_events(msi_dialog
* dialog
, LPCWSTR control
)
473 static WCHAR Query
[] = {
474 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
475 '`','E','v','e','n','t','M','a','p','p','i','n','g','`',' ',
476 'W','H','E','R','E',' ',
477 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',' ',
479 '`','C','o','n','t','r','o','l','_','`',' ','=',' ','\'','%','s','\'',0
482 LPCWSTR event
, attribute
;
484 row
= MSI_QueryGetRecord( dialog
->package
->db
, Query
, dialog
->name
, control
);
488 event
= MSI_RecordGetString( row
, 3 );
489 attribute
= MSI_RecordGetString( row
, 4 );
490 ControlEvent_SubscribeToEvent( dialog
->package
, event
, control
, attribute
);
491 msiobj_release( &row
->hdr
);
494 /* everything except radio buttons */
495 static msi_control
*msi_dialog_add_control( msi_dialog
*dialog
,
496 MSIRECORD
*rec
, LPCWSTR szCls
, DWORD style
)
501 name
= MSI_RecordGetString( rec
, 2 );
502 attributes
= MSI_RecordGetInteger( rec
, 8 );
503 text
= MSI_RecordGetString( rec
, 10 );
504 if( attributes
& msidbControlAttributesVisible
)
506 if( ~attributes
& msidbControlAttributesEnabled
)
507 style
|= WS_DISABLED
;
509 msi_dialog_map_events(dialog
, name
);
511 return msi_dialog_create_window( dialog
, rec
, szCls
, name
, text
,
512 style
, dialog
->hwnd
);
522 * we don't erase our own background,
523 * so we have to make sure that the parent window redraws first
525 static void msi_text_on_settext( HWND hWnd
)
530 hParent
= GetParent( hWnd
);
531 GetWindowRect( hWnd
, &rc
);
532 MapWindowPoints( NULL
, hParent
, (LPPOINT
) &rc
, 2 );
533 InvalidateRect( hParent
, &rc
, TRUE
);
536 static LRESULT WINAPI
537 MSIText_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
539 struct msi_text_info
*info
;
542 TRACE("%p %04x %08x %08lx\n", hWnd
, msg
, wParam
, lParam
);
544 info
= GetPropW(hWnd
, szButtonData
);
546 if( msg
== WM_CTLCOLORSTATIC
&&
547 ( info
->attributes
& msidbControlAttributesTransparent
) )
549 SetBkMode( (HDC
)wParam
, TRANSPARENT
);
550 return (LRESULT
) GetStockObject(NULL_BRUSH
);
553 r
= CallWindowProcW(info
->oldproc
, hWnd
, msg
, wParam
, lParam
);
558 msi_text_on_settext( hWnd
);
562 RemovePropW( hWnd
, szButtonData
);
569 static UINT
msi_dialog_text_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
571 msi_control
*control
;
572 struct msi_text_info
*info
;
574 TRACE("%p %p\n", dialog
, rec
);
576 control
= msi_dialog_add_control( dialog
, rec
, szStatic
, SS_LEFT
| WS_GROUP
);
578 return ERROR_FUNCTION_FAILED
;
580 info
= msi_alloc( sizeof *info
);
582 return ERROR_SUCCESS
;
584 info
->attributes
= MSI_RecordGetInteger( rec
, 8 );
585 if( info
->attributes
& msidbControlAttributesTransparent
)
586 SetWindowLongPtrW( control
->hwnd
, GWL_EXSTYLE
, WS_EX_TRANSPARENT
);
588 info
->oldproc
= (WNDPROC
) SetWindowLongPtrW( control
->hwnd
, GWLP_WNDPROC
,
589 (LONG_PTR
)MSIText_WndProc
);
590 SetPropW( control
->hwnd
, szButtonData
, info
);
592 return ERROR_SUCCESS
;
595 static UINT
msi_dialog_button_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
597 msi_control
*control
;
598 UINT attributes
, style
;
601 TRACE("%p %p\n", dialog
, rec
);
604 attributes
= MSI_RecordGetInteger( rec
, 8 );
605 if( attributes
& msidbControlAttributesIcon
)
608 control
= msi_dialog_add_control( dialog
, rec
, szButton
, style
);
610 return ERROR_FUNCTION_FAILED
;
612 control
->handler
= msi_dialog_button_handler
;
615 text
= msi_get_deformatted_field( dialog
->package
, rec
, 10 );
616 control
->hIcon
= msi_load_icon( dialog
->package
->db
, text
, attributes
);
617 if( attributes
& msidbControlAttributesIcon
)
618 SendMessageW( control
->hwnd
, BM_SETIMAGE
, IMAGE_ICON
, (LPARAM
) control
->hIcon
);
621 return ERROR_SUCCESS
;
624 static LPWSTR
msi_get_checkbox_value( msi_dialog
*dialog
, LPCWSTR prop
)
626 const static WCHAR query
[] = {
627 'S','E','L','E','C','T',' ','*',' ',
628 'F','R','O','M',' ','`','C','h','e','c','k','B','o','x',' ','`',
629 'W','H','E','R','E',' ',
630 '`','P','r','o','p','e','r','t','y','`',' ','=',' ',
633 MSIRECORD
*rec
= NULL
;
636 /* find if there is a value associated with the checkbox */
637 rec
= MSI_QueryGetRecord( dialog
->package
->db
, query
, prop
);
641 ret
= msi_get_deformatted_field( dialog
->package
, rec
, 2 );
647 msiobj_release( &rec
->hdr
);
651 ret
= msi_dup_property( dialog
->package
, prop
);
661 static UINT
msi_dialog_checkbox_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
663 msi_control
*control
;
666 TRACE("%p %p\n", dialog
, rec
);
668 control
= msi_dialog_add_control( dialog
, rec
, szButton
,
669 BS_CHECKBOX
| BS_MULTILINE
| WS_TABSTOP
);
670 control
->handler
= msi_dialog_checkbox_handler
;
671 prop
= MSI_RecordGetString( rec
, 9 );
674 control
->property
= strdupW( prop
);
675 control
->value
= msi_get_checkbox_value( dialog
, prop
);
676 TRACE("control %s value %s\n", debugstr_w(control
->property
),
677 debugstr_w(control
->value
));
679 msi_dialog_checkbox_sync_state( dialog
, control
);
681 return ERROR_SUCCESS
;
684 static UINT
msi_dialog_line_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
686 TRACE("%p %p\n", dialog
, rec
);
688 msi_dialog_add_control( dialog
, rec
, szStatic
, SS_ETCHEDHORZ
| SS_SUNKEN
);
689 return ERROR_SUCCESS
;
692 struct msi_streamin_info
699 static DWORD CALLBACK
700 msi_richedit_stream_in( DWORD_PTR arg
, LPBYTE buffer
, LONG count
, LONG
*pcb
)
702 struct msi_streamin_info
*info
= (struct msi_streamin_info
*) arg
;
704 if( (count
+ info
->offset
) > info
->length
)
705 count
= info
->length
- info
->offset
;
706 memcpy( buffer
, &info
->string
[ info
->offset
], count
);
708 info
->offset
+= count
;
710 TRACE("%ld/%ld\n", info
->offset
, info
->length
);
715 static UINT
msi_dialog_scrolltext_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
717 const static WCHAR szRichEdit20W
[] = {
718 'R','i','c','h','E','d','i','t','2','0','W',0
720 struct msi_streamin_info info
;
721 msi_control
*control
;
727 hRichedit
= LoadLibraryA("riched20");
729 style
= WS_BORDER
| ES_MULTILINE
| WS_VSCROLL
|
730 ES_READONLY
| ES_AUTOVSCROLL
| WS_TABSTOP
;
731 control
= msi_dialog_add_control( dialog
, rec
, szRichEdit20W
, style
);
733 return ERROR_FUNCTION_FAILED
;
735 control
->hDll
= hRichedit
;
737 text
= MSI_RecordGetString( rec
, 10 );
738 info
.string
= strdupWtoA( text
);
740 info
.length
= lstrlenA( info
.string
) + 1;
742 es
.dwCookie
= (DWORD_PTR
) &info
;
744 es
.pfnCallback
= msi_richedit_stream_in
;
746 SendMessageW( control
->hwnd
, EM_STREAMIN
, SF_RTF
, (LPARAM
) &es
);
748 msi_free( info
.string
);
750 return ERROR_SUCCESS
;
753 static UINT
msi_dialog_bitmap_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
755 UINT cx
, cy
, flags
, style
, attributes
;
756 msi_control
*control
;
759 flags
= LR_LOADFROMFILE
;
760 style
= SS_BITMAP
| SS_LEFT
| WS_GROUP
;
762 attributes
= MSI_RecordGetInteger( rec
, 8 );
763 if( attributes
& msidbControlAttributesFixedSize
)
765 flags
|= LR_DEFAULTSIZE
;
766 style
|= SS_CENTERIMAGE
;
769 control
= msi_dialog_add_control( dialog
, rec
, szStatic
, style
);
770 cx
= MSI_RecordGetInteger( rec
, 6 );
771 cy
= MSI_RecordGetInteger( rec
, 7 );
772 cx
= msi_dialog_scale_unit( dialog
, cx
);
773 cy
= msi_dialog_scale_unit( dialog
, cy
);
775 text
= msi_get_deformatted_field( dialog
->package
, rec
, 10 );
776 control
->hBitmap
= msi_load_image( dialog
->package
->db
, text
,
777 IMAGE_BITMAP
, cx
, cy
, flags
);
778 if( control
->hBitmap
)
779 SendMessageW( control
->hwnd
, STM_SETIMAGE
,
780 IMAGE_BITMAP
, (LPARAM
) control
->hBitmap
);
782 ERR("Failed to load bitmap %s\n", debugstr_w(text
));
786 return ERROR_SUCCESS
;
789 static UINT
msi_dialog_icon_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
791 msi_control
*control
;
797 control
= msi_dialog_add_control( dialog
, rec
, szStatic
,
798 SS_ICON
| SS_CENTERIMAGE
| WS_GROUP
);
800 attributes
= MSI_RecordGetInteger( rec
, 8 );
801 text
= msi_get_deformatted_field( dialog
->package
, rec
, 10 );
802 control
->hIcon
= msi_load_icon( dialog
->package
->db
, text
, attributes
);
804 SendMessageW( control
->hwnd
, STM_SETICON
, (WPARAM
) control
->hIcon
, 0 );
806 ERR("Failed to load bitmap %s\n", debugstr_w(text
));
808 return ERROR_SUCCESS
;
811 static UINT
msi_dialog_combo_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
813 static const WCHAR szCombo
[] = { 'C','O','M','B','O','B','O','X',0 };
815 msi_dialog_add_control( dialog
, rec
, szCombo
,
816 SS_BITMAP
| SS_LEFT
| SS_CENTERIMAGE
);
817 return ERROR_SUCCESS
;
820 static UINT
msi_dialog_edit_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
822 msi_control
*control
;
826 control
= msi_dialog_add_control( dialog
, rec
, szEdit
,
827 WS_BORDER
| WS_TABSTOP
);
828 control
->handler
= msi_dialog_edit_handler
;
829 prop
= MSI_RecordGetString( rec
, 9 );
831 control
->property
= strdupW( prop
);
832 val
= msi_dup_property( dialog
->package
, control
->property
);
833 SetWindowTextW( control
->hwnd
, val
);
835 return ERROR_SUCCESS
;
838 /******************** Masked Edit ********************************************/
840 #define MASK_MAX_GROUPS 10
842 struct msi_mask_group
850 struct msi_maskedit_info
858 struct msi_mask_group group
[MASK_MAX_GROUPS
];
861 static void msi_mask_control_change( struct msi_maskedit_info
*info
)
866 val
= msi_alloc( (info
->num_chars
+1)*sizeof(WCHAR
) );
867 for( i
=0, n
=0; i
<info
->num_groups
; i
++ )
869 if( (info
->group
[i
].len
+ n
) > info
->num_chars
)
871 ERR("can't fit control %d text into template\n",i
);
874 r
= GetWindowTextW( info
->group
[i
].hwnd
, &val
[n
], info
->group
[i
].len
+1 );
875 if( r
!= info
->group
[i
].len
)
880 TRACE("%d/%d controls were good\n", i
, info
->num_groups
);
882 if( i
== info
->num_groups
)
884 TRACE("Set property %s to %s\n",
885 debugstr_w(info
->prop
), debugstr_w(val
) );
886 CharUpperBuffW( val
, info
->num_chars
);
887 MSI_SetPropertyW( info
->dialog
->package
, info
->prop
, val
);
888 msi_dialog_evaluate_control_conditions( info
->dialog
);
893 /* now move to the next control if necessary */
894 static VOID
msi_mask_next_control( struct msi_maskedit_info
*info
, HWND hWnd
)
899 for( i
=0; i
<info
->num_groups
; i
++ )
900 if( info
->group
[i
].hwnd
== hWnd
)
903 /* don't move from the last control */
904 if( i
>= (info
->num_groups
-1) )
907 len
= SendMessageW( hWnd
, WM_GETTEXTLENGTH
, 0, 0 );
908 if( len
< info
->group
[i
].len
)
911 hWndNext
= GetNextDlgTabItem( GetParent( hWnd
), hWnd
, FALSE
);
912 SetFocus( hWndNext
);
915 static LRESULT WINAPI
916 MSIMaskedEdit_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
918 struct msi_maskedit_info
*info
;
921 TRACE("%p %04x %08x %08lx\n", hWnd
, msg
, wParam
, lParam
);
923 info
= GetPropW(hWnd
, szButtonData
);
925 r
= CallWindowProcW(info
->oldproc
, hWnd
, msg
, wParam
, lParam
);
930 if (HIWORD(wParam
) == EN_CHANGE
)
932 msi_mask_control_change( info
);
933 msi_mask_next_control( info
, (HWND
) lParam
);
937 msi_free( info
->prop
);
939 RemovePropW( hWnd
, szButtonData
);
946 /* fish the various bits of the property out and put them in the control */
948 msi_maskedit_set_text( struct msi_maskedit_info
*info
, LPCWSTR text
)
954 for( i
= 0; i
< info
->num_groups
; i
++ )
956 if( info
->group
[i
].len
< lstrlenW( p
) )
958 LPWSTR chunk
= strdupW( p
);
959 chunk
[ info
->group
[i
].len
] = 0;
960 SetWindowTextW( info
->group
[i
].hwnd
, chunk
);
965 SetWindowTextW( info
->group
[i
].hwnd
, p
);
968 p
+= info
->group
[i
].len
;
972 static struct msi_maskedit_info
* msi_dialog_parse_groups( LPCWSTR mask
)
974 struct msi_maskedit_info
* info
= NULL
;
975 int i
= 0, n
= 0, total
= 0;
978 TRACE("masked control, template %s\n", debugstr_w(mask
));
983 p
= strchrW(mask
, '<');
987 info
= msi_alloc_zero( sizeof *info
);
992 for( i
=0; i
<MASK_MAX_GROUPS
; i
++ )
1000 /* stop at the end of the string */
1001 if( p
[0] == 0 || p
[0] == '>' )
1004 /* count the number of the same identifier */
1005 for( n
=0; p
[n
] == p
[0]; n
++ )
1007 info
->group
[i
].ofs
= total
;
1008 info
->group
[i
].type
= p
[0];
1012 total
++; /* an extra not part of the group */
1014 info
->group
[i
].len
= n
;
1019 TRACE("%d characters in %d groups\n", total
, i
);
1020 if( i
== MASK_MAX_GROUPS
)
1021 ERR("too many groups in PIDTemplate %s\n", debugstr_w(mask
));
1023 info
->num_chars
= total
;
1024 info
->num_groups
= i
;
1030 msi_maskedit_create_children( struct msi_maskedit_info
*info
, LPCWSTR font
)
1032 DWORD width
, height
, style
, wx
, ww
;
1037 style
= WS_CHILD
| WS_BORDER
| WS_VISIBLE
| WS_TABSTOP
;
1039 GetClientRect( info
->hwnd
, &rect
);
1041 width
= rect
.right
- rect
.left
;
1042 height
= rect
.bottom
- rect
.top
;
1044 for( i
= 0; i
< info
->num_groups
; i
++ )
1046 wx
= (info
->group
[i
].ofs
* width
) / info
->num_chars
;
1047 ww
= (info
->group
[i
].len
* width
) / info
->num_chars
;
1049 hwnd
= CreateWindowW( szEdit
, NULL
, style
, wx
, 0, ww
, height
,
1050 info
->hwnd
, NULL
, NULL
, NULL
);
1053 ERR("failed to create mask edit sub window\n");
1057 SendMessageW( hwnd
, EM_LIMITTEXT
, info
->group
[i
].len
, 0 );
1059 msi_dialog_set_font( info
->dialog
, hwnd
,
1060 font
?font
:info
->dialog
->default_font
);
1061 info
->group
[i
].hwnd
= hwnd
;
1065 /* office 2003 uses "73931<````=````=````=````=`````>@@@@@" */
1066 static UINT
msi_dialog_maskedit_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1068 LPWSTR font_mask
, val
= NULL
, font
;
1069 struct msi_maskedit_info
*info
= NULL
;
1070 UINT ret
= ERROR_SUCCESS
;
1071 msi_control
*control
;
1076 font_mask
= msi_get_deformatted_field( dialog
->package
, rec
, 10 );
1077 font
= msi_dialog_get_style( font_mask
, &mask
);
1080 ERR("mask template is empty\n");
1084 info
= msi_dialog_parse_groups( mask
);
1087 ERR("template %s is invalid\n", debugstr_w(mask
));
1091 info
->dialog
= dialog
;
1093 control
= msi_dialog_add_control( dialog
, rec
, szStatic
,
1094 SS_OWNERDRAW
| WS_GROUP
| WS_VISIBLE
);
1097 ERR("Failed to create maskedit container\n");
1098 ret
= ERROR_FUNCTION_FAILED
;
1101 SetWindowLongPtrW( control
->hwnd
, GWL_EXSTYLE
, WS_EX_CONTROLPARENT
);
1103 info
->hwnd
= control
->hwnd
;
1105 /* subclass the static control */
1106 info
->oldproc
= (WNDPROC
) SetWindowLongPtrW( info
->hwnd
, GWLP_WNDPROC
,
1107 (LONG_PTR
)MSIMaskedEdit_WndProc
);
1108 SetPropW( control
->hwnd
, szButtonData
, info
);
1110 prop
= MSI_RecordGetString( rec
, 9 );
1112 info
->prop
= strdupW( prop
);
1114 msi_maskedit_create_children( info
, font
);
1118 val
= msi_dup_property( dialog
->package
, prop
);
1121 msi_maskedit_set_text( info
, val
);
1127 if( ret
!= ERROR_SUCCESS
)
1129 msi_free( font_mask
);
1134 /******************** Progress Bar *****************************************/
1136 static UINT
msi_dialog_progress_bar( msi_dialog
*dialog
, MSIRECORD
*rec
)
1138 msi_dialog_add_control( dialog
, rec
, PROGRESS_CLASSW
, WS_VISIBLE
);
1139 return ERROR_SUCCESS
;
1142 /******************** Path Edit ********************************************/
1144 static UINT
msi_dialog_pathedit_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1146 FIXME("not implemented properly\n");
1147 return msi_dialog_edit_control( dialog
, rec
);
1150 /* radio buttons are a bit different from normal controls */
1151 static UINT
msi_dialog_create_radiobutton( MSIRECORD
*rec
, LPVOID param
)
1153 radio_button_group_descr
*group
= (radio_button_group_descr
*)param
;
1154 msi_dialog
*dialog
= group
->dialog
;
1155 msi_control
*control
;
1156 LPCWSTR prop
, text
, name
;
1157 DWORD style
, attributes
= group
->attributes
;
1159 style
= WS_CHILD
| BS_AUTORADIOBUTTON
| BS_MULTILINE
| WS_TABSTOP
;
1160 name
= MSI_RecordGetString( rec
, 3 );
1161 text
= MSI_RecordGetString( rec
, 8 );
1162 if( attributes
& 1 )
1163 style
|= WS_VISIBLE
;
1164 if( ~attributes
& 2 )
1165 style
|= WS_DISABLED
;
1167 control
= msi_dialog_create_window( dialog
, rec
, szButton
, name
, text
,
1168 style
, group
->parent
->hwnd
);
1170 return ERROR_FUNCTION_FAILED
;
1171 control
->handler
= msi_dialog_radiogroup_handler
;
1173 prop
= MSI_RecordGetString( rec
, 1 );
1175 control
->property
= strdupW( prop
);
1177 return ERROR_SUCCESS
;
1180 static UINT
msi_dialog_radiogroup_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1182 static const WCHAR query
[] = {
1183 'S','E','L','E','C','T',' ','*',' ',
1184 'F','R','O','M',' ','R','a','d','i','o','B','u','t','t','o','n',' ',
1185 'W','H','E','R','E',' ',
1186 '`','P','r','o','p','e','r','t','y','`',' ','=',' ','\'','%','s','\'',0};
1189 msi_control
*control
;
1190 MSIQUERY
*view
= NULL
;
1191 radio_button_group_descr group
;
1192 MSIPACKAGE
*package
= dialog
->package
;
1195 prop
= MSI_RecordGetString( rec
, 9 );
1197 TRACE("%p %p %s\n", dialog
, rec
, debugstr_w( prop
));
1199 /* Create parent group box to hold radio buttons */
1200 control
= msi_dialog_add_control( dialog
, rec
, szButton
, BS_OWNERDRAW
|WS_GROUP
);
1202 return ERROR_FUNCTION_FAILED
;
1204 oldproc
= (WNDPROC
) SetWindowLongPtrW( control
->hwnd
, GWLP_WNDPROC
,
1205 (LONG_PTR
)MSIRadioGroup_WndProc
);
1206 SetPropW(control
->hwnd
, szButtonData
, oldproc
);
1207 SetWindowLongPtrW( control
->hwnd
, GWL_EXSTYLE
, WS_EX_CONTROLPARENT
);
1210 control
->property
= strdupW( prop
);
1212 /* query the Radio Button table for all control in this group */
1213 r
= MSI_OpenQuery( package
->db
, &view
, query
, prop
);
1214 if( r
!= ERROR_SUCCESS
)
1216 ERR("query failed for dialog %s radio group %s\n",
1217 debugstr_w(dialog
->name
), debugstr_w(prop
));
1218 return ERROR_INVALID_PARAMETER
;
1221 group
.dialog
= dialog
;
1222 group
.parent
= control
;
1223 group
.attributes
= MSI_RecordGetInteger( rec
, 8 );
1225 r
= MSI_IterateRecords( view
, 0, msi_dialog_create_radiobutton
, &group
);
1226 msiobj_release( &view
->hdr
);
1231 struct control_handler msi_dialog_handler
[] =
1233 { szText
, msi_dialog_text_control
},
1234 { szPushButton
, msi_dialog_button_control
},
1235 { szLine
, msi_dialog_line_control
},
1236 { szBitmap
, msi_dialog_bitmap_control
},
1237 { szCheckBox
, msi_dialog_checkbox_control
},
1238 { szScrollableText
, msi_dialog_scrolltext_control
},
1239 { szComboBox
, msi_dialog_combo_control
},
1240 { szEdit
, msi_dialog_edit_control
},
1241 { szMaskedEdit
, msi_dialog_maskedit_control
},
1242 { szPathEdit
, msi_dialog_pathedit_control
},
1243 { szProgressBar
, msi_dialog_progress_bar
},
1244 { szRadioButtonGroup
, msi_dialog_radiogroup_control
},
1245 { szIcon
, msi_dialog_icon_control
},
1248 #define NUM_CONTROL_TYPES (sizeof msi_dialog_handler/sizeof msi_dialog_handler[0])
1250 static UINT
msi_dialog_create_controls( MSIRECORD
*rec
, LPVOID param
)
1252 msi_dialog
*dialog
= param
;
1253 LPCWSTR control_type
;
1256 /* find and call the function that can create this type of control */
1257 control_type
= MSI_RecordGetString( rec
, 3 );
1258 for( i
=0; i
<NUM_CONTROL_TYPES
; i
++ )
1259 if (!strcmpiW( msi_dialog_handler
[i
].control_type
, control_type
))
1261 if( i
!= NUM_CONTROL_TYPES
)
1262 msi_dialog_handler
[i
].func( dialog
, rec
);
1264 ERR("no handler for element type %s\n", debugstr_w(control_type
));
1266 return ERROR_SUCCESS
;
1269 static UINT
msi_dialog_fill_controls( msi_dialog
*dialog
)
1271 static const WCHAR query
[] = {
1272 'S','E','L','E','C','T',' ','*',' ',
1273 'F','R','O','M',' ','C','o','n','t','r','o','l',' ',
1274 'W','H','E','R','E',' ',
1275 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',0};
1277 MSIQUERY
*view
= NULL
;
1278 MSIPACKAGE
*package
= dialog
->package
;
1280 TRACE("%p %s\n", dialog
, debugstr_w(dialog
->name
) );
1282 /* query the Control table for all the elements of the control */
1283 r
= MSI_OpenQuery( package
->db
, &view
, query
, dialog
->name
);
1284 if( r
!= ERROR_SUCCESS
)
1286 ERR("query failed for dialog %s\n", debugstr_w(dialog
->name
));
1287 return ERROR_INVALID_PARAMETER
;
1290 r
= MSI_IterateRecords( view
, 0, msi_dialog_create_controls
, dialog
);
1291 msiobj_release( &view
->hdr
);
1296 static UINT
msi_dialog_set_control_condition( MSIRECORD
*rec
, LPVOID param
)
1298 static const WCHAR szHide
[] = { 'H','i','d','e',0 };
1299 static const WCHAR szShow
[] = { 'S','h','o','w',0 };
1300 static const WCHAR szDisable
[] = { 'D','i','s','a','b','l','e',0 };
1301 static const WCHAR szEnable
[] = { 'E','n','a','b','l','e',0 };
1302 msi_dialog
*dialog
= param
;
1303 msi_control
*control
;
1304 LPCWSTR name
, action
, condition
;
1307 name
= MSI_RecordGetString( rec
, 2 );
1308 action
= MSI_RecordGetString( rec
, 3 );
1309 condition
= MSI_RecordGetString( rec
, 4 );
1310 r
= MSI_EvaluateConditionW( dialog
->package
, condition
);
1311 control
= msi_dialog_find_control( dialog
, name
);
1314 TRACE("%s control %s\n", debugstr_w(action
), debugstr_w(name
));
1316 /* FIXME: case sensitive? */
1317 if(!lstrcmpW(action
, szHide
))
1318 ShowWindow(control
->hwnd
, SW_HIDE
);
1319 else if(!strcmpW(action
, szShow
))
1320 ShowWindow(control
->hwnd
, SW_SHOW
);
1321 else if(!strcmpW(action
, szDisable
))
1322 EnableWindow(control
->hwnd
, FALSE
);
1323 else if(!strcmpW(action
, szEnable
))
1324 EnableWindow(control
->hwnd
, TRUE
);
1326 FIXME("Unhandled action %s\n", debugstr_w(action
));
1329 return ERROR_SUCCESS
;
1332 static UINT
msi_dialog_evaluate_control_conditions( msi_dialog
*dialog
)
1334 static const WCHAR query
[] = {
1335 'S','E','L','E','C','T',' ','*',' ',
1336 'F','R','O','M',' ',
1337 'C','o','n','t','r','o','l','C','o','n','d','i','t','i','o','n',' ',
1338 'W','H','E','R','E',' ',
1339 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',0
1342 MSIQUERY
*view
= NULL
;
1343 MSIPACKAGE
*package
= dialog
->package
;
1345 TRACE("%p %s\n", dialog
, debugstr_w(dialog
->name
) );
1347 /* query the Control table for all the elements of the control */
1348 r
= MSI_OpenQuery( package
->db
, &view
, query
, dialog
->name
);
1349 if( r
!= ERROR_SUCCESS
)
1351 ERR("query failed for dialog %s\n", debugstr_w(dialog
->name
));
1352 return ERROR_INVALID_PARAMETER
;
1355 r
= MSI_IterateRecords( view
, 0, msi_dialog_set_control_condition
, dialog
);
1356 msiobj_release( &view
->hdr
);
1361 /* figure out the height of 10 point MS Sans Serif */
1362 static INT
msi_dialog_get_sans_serif_height( HWND hwnd
)
1364 static const WCHAR szSansSerif
[] = {
1365 'M','S',' ','S','a','n','s',' ','S','e','r','i','f',0 };
1370 HFONT hFont
, hOldFont
;
1373 hdc
= GetDC( hwnd
);
1376 memset( &lf
, 0, sizeof lf
);
1377 lf
.lfHeight
= MulDiv(10, GetDeviceCaps(hdc
, LOGPIXELSY
), 72);
1378 strcpyW( lf
.lfFaceName
, szSansSerif
);
1379 hFont
= CreateFontIndirectW(&lf
);
1382 hOldFont
= SelectObject( hdc
, hFont
);
1383 r
= GetTextMetricsW( hdc
, &tm
);
1385 height
= tm
.tmHeight
;
1386 SelectObject( hdc
, hOldFont
);
1387 DeleteObject( hFont
);
1389 ReleaseDC( hwnd
, hdc
);
1394 /* fetch the associated record from the Dialog table */
1395 static MSIRECORD
*msi_get_dialog_record( msi_dialog
*dialog
)
1397 static const WCHAR query
[] = {
1398 'S','E','L','E','C','T',' ','*',' ',
1399 'F','R','O','M',' ','D','i','a','l','o','g',' ',
1400 'W','H','E','R','E',' ',
1401 '`','D','i','a','l','o','g','`',' ','=',' ','\'','%','s','\'',0};
1402 MSIPACKAGE
*package
= dialog
->package
;
1403 MSIRECORD
*rec
= NULL
;
1405 TRACE("%p %s\n", dialog
, debugstr_w(dialog
->name
) );
1407 rec
= MSI_QueryGetRecord( package
->db
, query
, dialog
->name
);
1409 ERR("query failed for dialog %s\n", debugstr_w(dialog
->name
));
1414 static void msi_dialog_adjust_dialog_size( msi_dialog
*dialog
, LPSIZE sz
)
1419 /* turn the client size into the window rectangle */
1422 rect
.right
= msi_dialog_scale_unit( dialog
, sz
->cx
);
1423 rect
.bottom
= msi_dialog_scale_unit( dialog
, sz
->cy
);
1424 style
= GetWindowLongPtrW( dialog
->hwnd
, GWL_STYLE
);
1425 AdjustWindowRect( &rect
, style
, FALSE
);
1426 sz
->cx
= rect
.right
- rect
.left
;
1427 sz
->cy
= rect
.bottom
- rect
.top
;
1430 static BOOL
msi_control_set_next( msi_control
*control
, msi_control
*next
)
1432 return SetWindowPos( next
->hwnd
, control
->hwnd
, 0, 0, 0, 0,
1433 SWP_NOMOVE
| SWP_NOOWNERZORDER
| SWP_NOREDRAW
|
1434 SWP_NOREPOSITION
| SWP_NOSENDCHANGING
| SWP_NOSIZE
);
1437 static UINT
msi_dialog_set_tab_order( msi_dialog
*dialog
)
1439 msi_control
*control
, *tab_next
;
1441 LIST_FOR_EACH_ENTRY( control
, &dialog
->controls
, msi_control
, entry
)
1443 tab_next
= msi_dialog_find_control( dialog
, control
->tabnext
);
1446 msi_control_set_next( control
, tab_next
);
1449 return ERROR_SUCCESS
;
1452 static void msi_dialog_set_first_control( msi_dialog
* dialog
, LPCWSTR name
)
1454 msi_control
*control
;
1456 control
= msi_dialog_find_control( dialog
, name
);
1458 dialog
->hWndFocus
= control
->hwnd
;
1460 dialog
->hWndFocus
= NULL
;
1463 static LRESULT
msi_dialog_oncreate( HWND hwnd
, LPCREATESTRUCTW cs
)
1465 static const WCHAR df
[] = {
1466 'D','e','f','a','u','l','t','U','I','F','o','n','t',0 };
1467 msi_dialog
*dialog
= (msi_dialog
*) cs
->lpCreateParams
;
1468 MSIRECORD
*rec
= NULL
;
1469 LPWSTR title
= NULL
;
1472 TRACE("%p %p\n", dialog
, dialog
->package
);
1474 dialog
->hwnd
= hwnd
;
1475 SetWindowLongPtrW( hwnd
, GWLP_USERDATA
, (LONG_PTR
) dialog
);
1477 rec
= msi_get_dialog_record( dialog
);
1480 TRACE("No record found for dialog %s\n", debugstr_w(dialog
->name
));
1484 dialog
->scale
= msi_dialog_get_sans_serif_height(dialog
->hwnd
);
1486 size
.cx
= MSI_RecordGetInteger( rec
, 4 );
1487 size
.cy
= MSI_RecordGetInteger( rec
, 5 );
1488 msi_dialog_adjust_dialog_size( dialog
, &size
);
1490 dialog
->attributes
= MSI_RecordGetInteger( rec
, 6 );
1492 dialog
->default_font
= msi_dup_property( dialog
->package
, df
);
1494 title
= msi_get_deformatted_field( dialog
->package
, rec
, 7 );
1495 SetWindowTextW( hwnd
, title
);
1498 SetWindowPos( hwnd
, 0, 0, 0, size
.cx
, size
.cy
,
1499 SWP_NOMOVE
| SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_NOREDRAW
);
1502 msi_dialog_build_font_list( dialog
);
1503 msi_dialog_fill_controls( dialog
);
1504 msi_dialog_evaluate_control_conditions( dialog
);
1505 msi_dialog_set_tab_order( dialog
);
1506 msi_dialog_set_first_control( dialog
, MSI_RecordGetString( rec
, 8 ) );
1507 msiobj_release( &rec
->hdr
);
1512 static UINT
msi_dialog_send_event( msi_dialog
*dialog
, LPCWSTR event
, LPCWSTR arg
)
1514 LPWSTR event_fmt
= NULL
, arg_fmt
= NULL
;
1516 TRACE("Sending control event %s %s\n", debugstr_w(event
), debugstr_w(arg
));
1518 deformat_string( dialog
->package
, event
, &event_fmt
);
1519 deformat_string( dialog
->package
, arg
, &arg_fmt
);
1521 dialog
->event_handler( dialog
->package
, event_fmt
, arg_fmt
, dialog
);
1523 msi_free( event_fmt
);
1524 msi_free( arg_fmt
);
1526 return ERROR_SUCCESS
;
1529 static UINT
msi_dialog_set_property( msi_dialog
*dialog
, LPCWSTR event
, LPCWSTR arg
)
1531 static const WCHAR szNullArg
[] = { '{','}',0 };
1532 LPWSTR p
, prop
, arg_fmt
= NULL
;
1535 len
= strlenW(event
);
1536 prop
= msi_alloc( len
*sizeof(WCHAR
));
1537 strcpyW( prop
, &event
[1] );
1538 p
= strchrW( prop
, ']' );
1539 if( p
&& p
[1] == 0 )
1542 if( strcmpW( szNullArg
, arg
) )
1543 deformat_string( dialog
->package
, arg
, &arg_fmt
);
1544 MSI_SetPropertyW( dialog
->package
, prop
, arg_fmt
);
1545 msi_free( arg_fmt
);
1548 ERR("Badly formatted property string - what happens?\n");
1550 return ERROR_SUCCESS
;
1553 static UINT
msi_dialog_control_event( MSIRECORD
*rec
, LPVOID param
)
1555 msi_dialog
*dialog
= param
;
1556 LPCWSTR condition
, event
, arg
;
1559 condition
= MSI_RecordGetString( rec
, 5 );
1560 r
= MSI_EvaluateConditionW( dialog
->package
, condition
);
1563 event
= MSI_RecordGetString( rec
, 3 );
1564 arg
= MSI_RecordGetString( rec
, 4 );
1565 if( event
[0] == '[' )
1566 msi_dialog_set_property( dialog
, event
, arg
);
1568 msi_dialog_send_event( dialog
, event
, arg
);
1571 return ERROR_SUCCESS
;
1574 static UINT
msi_dialog_button_handler( msi_dialog
*dialog
,
1575 msi_control
*control
, WPARAM param
)
1577 static const WCHAR query
[] = {
1578 'S','E','L','E','C','T',' ','*',' ',
1579 'F','R','O','M',' ','C','o','n','t','r','o','l','E','v','e','n','t',' ',
1580 'W','H','E','R','E',' ',
1581 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',' ',
1583 '`','C','o','n','t','r','o','l','_','`',' ','=',' ','\'','%','s','\'',' ',
1584 'O','R','D','E','R',' ','B','Y',' ','`','O','r','d','e','r','i','n','g','`',0
1586 MSIQUERY
*view
= NULL
;
1589 if( HIWORD(param
) != BN_CLICKED
)
1590 return ERROR_SUCCESS
;
1592 r
= MSI_OpenQuery( dialog
->package
->db
, &view
, query
,
1593 dialog
->name
, control
->name
);
1594 if( r
!= ERROR_SUCCESS
)
1596 ERR("query failed\n");
1600 r
= MSI_IterateRecords( view
, 0, msi_dialog_control_event
, dialog
);
1601 msiobj_release( &view
->hdr
);
1606 static UINT
msi_dialog_get_checkbox_state( msi_dialog
*dialog
,
1607 msi_control
*control
)
1609 WCHAR state
[2] = { 0 };
1612 MSI_GetPropertyW( dialog
->package
, control
->property
, state
, &sz
);
1613 return state
[0] ? 1 : 0;
1616 static void msi_dialog_set_checkbox_state( msi_dialog
*dialog
,
1617 msi_control
*control
, UINT state
)
1619 static const WCHAR szState
[] = { '1', 0 };
1622 /* if uncheck then the property is set to NULL */
1625 MSI_SetPropertyW( dialog
->package
, control
->property
, NULL
);
1629 /* check for a custom state */
1630 if (control
->value
&& control
->value
[0])
1631 val
= control
->value
;
1635 MSI_SetPropertyW( dialog
->package
, control
->property
, val
);
1638 static void msi_dialog_checkbox_sync_state( msi_dialog
*dialog
,
1639 msi_control
*control
)
1643 state
= msi_dialog_get_checkbox_state( dialog
, control
);
1644 SendMessageW( control
->hwnd
, BM_SETCHECK
,
1645 state
? BST_CHECKED
: BST_UNCHECKED
, 0 );
1648 static UINT
msi_dialog_checkbox_handler( msi_dialog
*dialog
,
1649 msi_control
*control
, WPARAM param
)
1653 if( HIWORD(param
) != BN_CLICKED
)
1654 return ERROR_SUCCESS
;
1656 TRACE("clicked checkbox %s, set %s\n", debugstr_w(control
->name
),
1657 debugstr_w(control
->property
));
1659 state
= msi_dialog_get_checkbox_state( dialog
, control
);
1660 state
= state
? 0 : 1;
1661 msi_dialog_set_checkbox_state( dialog
, control
, state
);
1662 msi_dialog_checkbox_sync_state( dialog
, control
);
1664 return msi_dialog_button_handler( dialog
, control
, param
);
1667 static UINT
msi_dialog_edit_handler( msi_dialog
*dialog
,
1668 msi_control
*control
, WPARAM param
)
1673 if( HIWORD(param
) != EN_CHANGE
)
1674 return ERROR_SUCCESS
;
1676 TRACE("edit %s contents changed, set %s\n", debugstr_w(control
->name
),
1677 debugstr_w(control
->property
));
1680 buf
= msi_alloc( sz
*sizeof(WCHAR
) );
1683 r
= GetWindowTextW( control
->hwnd
, buf
, sz
);
1687 buf
= msi_realloc( buf
, sz
*sizeof(WCHAR
) );
1690 MSI_SetPropertyW( dialog
->package
, control
->property
, buf
);
1694 return ERROR_SUCCESS
;
1697 static UINT
msi_dialog_radiogroup_handler( msi_dialog
*dialog
,
1698 msi_control
*control
, WPARAM param
)
1700 if( HIWORD(param
) != BN_CLICKED
)
1701 return ERROR_SUCCESS
;
1703 TRACE("clicked radio button %s, set %s\n", debugstr_w(control
->name
),
1704 debugstr_w(control
->property
));
1706 MSI_SetPropertyW( dialog
->package
, control
->property
, control
->name
);
1708 return msi_dialog_button_handler( dialog
, control
, param
);
1711 static LRESULT
msi_dialog_oncommand( msi_dialog
*dialog
, WPARAM param
, HWND hwnd
)
1713 msi_control
*control
;
1715 TRACE("%p %p %08x\n", dialog
, hwnd
, param
);
1717 control
= msi_dialog_find_control_by_hwnd( dialog
, hwnd
);
1720 if( control
->handler
)
1722 control
->handler( dialog
, control
, param
);
1723 msi_dialog_evaluate_control_conditions( dialog
);
1727 ERR("button click from nowhere\n");
1731 static void msi_dialog_setfocus( msi_dialog
*dialog
)
1733 HWND hwnd
= dialog
->hWndFocus
;
1735 hwnd
= GetNextDlgTabItem( dialog
->hwnd
, hwnd
, TRUE
);
1736 hwnd
= GetNextDlgTabItem( dialog
->hwnd
, hwnd
, FALSE
);
1738 dialog
->hWndFocus
= hwnd
;
1741 static LRESULT WINAPI
MSIDialog_WndProc( HWND hwnd
, UINT msg
,
1742 WPARAM wParam
, LPARAM lParam
)
1744 msi_dialog
*dialog
= (LPVOID
) GetWindowLongPtrW( hwnd
, GWLP_USERDATA
);
1746 TRACE("0x%04x\n", msg
);
1751 return msi_dialog_oncreate( hwnd
, (LPCREATESTRUCTW
)lParam
);
1754 return msi_dialog_oncommand( dialog
, wParam
, (HWND
)lParam
);
1757 if( LOWORD(wParam
) == WA_INACTIVE
)
1758 dialog
->hWndFocus
= GetFocus();
1760 msi_dialog_setfocus( dialog
);
1764 msi_dialog_setfocus( dialog
);
1767 /* bounce back to our subclassed static control */
1768 case WM_CTLCOLORSTATIC
:
1769 return SendMessageW( (HWND
) lParam
, WM_CTLCOLORSTATIC
, wParam
, lParam
);
1772 dialog
->hwnd
= NULL
;
1775 return DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
1778 static LRESULT WINAPI
MSIRadioGroup_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1780 WNDPROC oldproc
= (WNDPROC
) GetPropW(hWnd
, szButtonData
);
1782 TRACE("hWnd %p msg %04x wParam 0x%08x lParam 0x%08lx\n", hWnd
, msg
, wParam
, lParam
);
1784 if (msg
== WM_COMMAND
) /* Forward notifications to dialog */
1785 SendMessageW(GetParent(hWnd
), msg
, wParam
, lParam
);
1787 return CallWindowProcW(oldproc
, hWnd
, msg
, wParam
, lParam
);
1790 static LRESULT WINAPI
MSIHiddenWindowProc( HWND hwnd
, UINT msg
,
1791 WPARAM wParam
, LPARAM lParam
)
1793 msi_dialog
*dialog
= (msi_dialog
*) lParam
;
1795 TRACE("%d %p\n", msg
, dialog
);
1799 case WM_MSI_DIALOG_CREATE
:
1800 return msi_dialog_run_message_loop( dialog
);
1801 case WM_MSI_DIALOG_DESTROY
:
1802 msi_dialog_destroy( dialog
);
1805 return DefWindowProcW( hwnd
, msg
, wParam
, lParam
);
1808 /* functions that interface to other modules within MSI */
1810 msi_dialog
*msi_dialog_create( MSIPACKAGE
* package
, LPCWSTR szDialogName
,
1811 msi_dialog_event_handler event_handler
)
1813 MSIRECORD
*rec
= NULL
;
1816 TRACE("%p %s\n", package
, debugstr_w(szDialogName
));
1818 /* allocate the structure for the dialog to use */
1819 dialog
= msi_alloc_zero( sizeof *dialog
+ sizeof(WCHAR
)*strlenW(szDialogName
) );
1822 strcpyW( dialog
->name
, szDialogName
);
1823 msiobj_addref( &package
->hdr
);
1824 dialog
->package
= package
;
1825 dialog
->event_handler
= event_handler
;
1826 dialog
->finished
= 0;
1827 list_init( &dialog
->controls
);
1829 /* verify that the dialog exists */
1830 rec
= msi_get_dialog_record( dialog
);
1833 msiobj_release( &package
->hdr
);
1837 dialog
->attributes
= MSI_RecordGetInteger( rec
, 6 );
1838 msiobj_release( &rec
->hdr
);
1843 static void msi_process_pending_messages( HWND hdlg
)
1847 while( PeekMessageW( &msg
, 0, 0, 0, PM_REMOVE
) )
1849 if( hdlg
&& IsDialogMessageW( hdlg
, &msg
))
1851 TranslateMessage( &msg
);
1852 DispatchMessageW( &msg
);
1856 void msi_dialog_end_dialog( msi_dialog
*dialog
)
1858 TRACE("%p\n", dialog
);
1859 dialog
->finished
= 1;
1860 PostMessageW(dialog
->hwnd
, WM_NULL
, 0, 0);
1863 void msi_dialog_check_messages( HANDLE handle
)
1867 /* in threads other than the UI thread, block */
1868 if( uiThreadId
!= GetCurrentThreadId() )
1871 WaitForSingleObject( handle
, INFINITE
);
1875 /* there's two choices for the UI thread */
1878 msi_process_pending_messages( NULL
);
1884 * block here until somebody creates a new dialog or
1885 * the handle we're waiting on becomes ready
1887 r
= MsgWaitForMultipleObjects( 1, &handle
, 0, INFINITE
, QS_ALLINPUT
);
1888 if( r
== WAIT_OBJECT_0
)
1893 UINT
msi_dialog_run_message_loop( msi_dialog
*dialog
)
1897 if( !(dialog
->attributes
& msidbDialogAttributesVisible
) )
1898 return ERROR_SUCCESS
;
1900 if( uiThreadId
!= GetCurrentThreadId() )
1901 return SendMessageW( hMsiHiddenWindow
, WM_MSI_DIALOG_CREATE
, 0, (LPARAM
) dialog
);
1903 /* create the dialog window, don't show it yet */
1904 hwnd
= CreateWindowW( szMsiDialogClass
, dialog
->name
, WS_OVERLAPPEDWINDOW
,
1905 CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
,
1906 NULL
, NULL
, NULL
, dialog
);
1909 ERR("Failed to create dialog %s\n", debugstr_w( dialog
->name
));
1910 return ERROR_FUNCTION_FAILED
;
1913 ShowWindow( hwnd
, SW_SHOW
);
1914 /* UpdateWindow( hwnd ); - and causes the transparent static controls not to paint */
1916 if( dialog
->attributes
& msidbDialogAttributesModal
)
1918 while( !dialog
->finished
)
1920 MsgWaitForMultipleObjects( 0, NULL
, 0, INFINITE
, QS_ALLEVENTS
);
1921 msi_process_pending_messages( dialog
->hwnd
);
1925 return ERROR_IO_PENDING
;
1927 return ERROR_SUCCESS
;
1930 void msi_dialog_do_preview( msi_dialog
*dialog
)
1933 dialog
->attributes
|= msidbDialogAttributesVisible
;
1934 dialog
->attributes
&= ~msidbDialogAttributesModal
;
1935 msi_dialog_run_message_loop( dialog
);
1938 void msi_dialog_destroy( msi_dialog
*dialog
)
1940 if( uiThreadId
!= GetCurrentThreadId() )
1942 SendMessageW( hMsiHiddenWindow
, WM_MSI_DIALOG_DESTROY
, 0, (LPARAM
) dialog
);
1947 ShowWindow( dialog
->hwnd
, SW_HIDE
);
1950 DestroyWindow( dialog
->hwnd
);
1952 /* destroy the list of controls */
1953 while( !list_empty( &dialog
->controls
) )
1955 msi_control
*t
= LIST_ENTRY( list_head( &dialog
->controls
),
1956 msi_control
, entry
);
1957 list_remove( &t
->entry
);
1958 /* leave dialog->hwnd - destroying parent destroys child windows */
1959 msi_free( t
->property
);
1960 msi_free( t
->value
);
1962 DeleteObject( t
->hBitmap
);
1964 DestroyIcon( t
->hIcon
);
1965 msi_free( t
->tabnext
);
1968 FreeLibrary( t
->hDll
);
1971 /* destroy the list of fonts */
1972 while( dialog
->font_list
)
1974 msi_font
*t
= dialog
->font_list
;
1975 dialog
->font_list
= t
->next
;
1976 DeleteObject( t
->hfont
);
1979 msi_free( dialog
->default_font
);
1981 msiobj_release( &dialog
->package
->hdr
);
1982 dialog
->package
= NULL
;
1986 BOOL
msi_dialog_register_class( void )
1990 ZeroMemory( &cls
, sizeof cls
);
1991 cls
.lpfnWndProc
= MSIDialog_WndProc
;
1992 cls
.hInstance
= NULL
;
1993 cls
.hIcon
= LoadIconW(0, (LPWSTR
)IDI_APPLICATION
);
1994 cls
.hCursor
= LoadCursorW(0, (LPWSTR
)IDC_ARROW
);
1995 cls
.hbrBackground
= (HBRUSH
)(COLOR_3DFACE
+ 1);
1996 cls
.lpszMenuName
= NULL
;
1997 cls
.lpszClassName
= szMsiDialogClass
;
1999 if( !RegisterClassW( &cls
) )
2002 cls
.lpfnWndProc
= MSIHiddenWindowProc
;
2003 cls
.lpszClassName
= szMsiHiddenWindow
;
2005 if( !RegisterClassW( &cls
) )
2008 uiThreadId
= GetCurrentThreadId();
2010 hMsiHiddenWindow
= CreateWindowW( szMsiHiddenWindow
, NULL
, WS_OVERLAPPED
,
2011 0, 0, 100, 100, NULL
, NULL
, NULL
, NULL
);
2012 if( !hMsiHiddenWindow
)
2018 void msi_dialog_unregister_class( void )
2020 DestroyWindow( hMsiHiddenWindow
);
2021 UnregisterClassW( szMsiDialogClass
, NULL
);