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
22 #define NONAMELESSUNION
23 #define NONAMELESSSTRUCT
40 #include "wine/debug.h"
41 #include "wine/unicode.h"
45 WINE_DEFAULT_DEBUG_CHANNEL(msi
);
48 struct msi_control_tag
;
49 typedef struct msi_control_tag msi_control
;
50 typedef UINT (*msi_handler
)( msi_dialog
*, msi_control
*, WPARAM
);
52 struct msi_control_tag
65 typedef struct msi_font_tag
67 struct msi_font_tag
*next
;
75 msi_dialog_event_handler event_handler
;
84 LPWSTR control_default
;
85 LPWSTR control_cancel
;
89 typedef UINT (*msi_dialog_control_func
)( msi_dialog
*dialog
, MSIRECORD
*rec
);
90 struct control_handler
93 msi_dialog_control_func func
;
101 } radio_button_group_descr
;
103 const WCHAR szMsiDialogClass
[] = {
104 'M','s','i','D','i','a','l','o','g','C','l','o','s','e','C','l','a','s','s',0
106 const WCHAR szMsiHiddenWindow
[] = {
107 'M','s','i','H','i','d','d','e','n','W','i','n','d','o','w',0 };
108 static const WCHAR szStatic
[] = { 'S','t','a','t','i','c',0 };
109 static const WCHAR szButton
[] = { 'B','U','T','T','O','N', 0 };
110 static const WCHAR szButtonData
[] = { 'M','S','I','D','A','T','A',0 };
111 static const WCHAR szText
[] = { 'T','e','x','t',0 };
112 static const WCHAR szPushButton
[] = { 'P','u','s','h','B','u','t','t','o','n',0 };
113 static const WCHAR szLine
[] = { 'L','i','n','e',0 };
114 static const WCHAR szBitmap
[] = { 'B','i','t','m','a','p',0 };
115 static const WCHAR szCheckBox
[] = { 'C','h','e','c','k','B','o','x',0 };
116 static const WCHAR szScrollableText
[] = {
117 'S','c','r','o','l','l','a','b','l','e','T','e','x','t',0 };
118 static const WCHAR szComboBox
[] = { 'C','o','m','b','o','B','o','x',0 };
119 static const WCHAR szEdit
[] = { 'E','d','i','t',0 };
120 static const WCHAR szMaskedEdit
[] = { 'M','a','s','k','e','d','E','d','i','t',0 };
121 static const WCHAR szPathEdit
[] = { 'P','a','t','h','E','d','i','t',0 };
122 static const WCHAR szProgressBar
[] = {
123 'P','r','o','g','r','e','s','s','B','a','r',0 };
124 static const WCHAR szRadioButtonGroup
[] = {
125 'R','a','d','i','o','B','u','t','t','o','n','G','r','o','u','p',0 };
126 static const WCHAR szIcon
[] = { 'I','c','o','n',0 };
127 static const WCHAR szSelectionTree
[] = {
128 'S','e','l','e','c','t','i','o','n','T','r','e','e',0 };
130 static UINT
msi_dialog_checkbox_handler( msi_dialog
*, msi_control
*, WPARAM
);
131 static void msi_dialog_checkbox_sync_state( msi_dialog
*, msi_control
* );
132 static UINT
msi_dialog_button_handler( msi_dialog
*, msi_control
*, WPARAM
);
133 static UINT
msi_dialog_edit_handler( msi_dialog
*, msi_control
*, WPARAM
);
134 static UINT
msi_dialog_radiogroup_handler( msi_dialog
*, msi_control
*, WPARAM param
);
135 static UINT
msi_dialog_evaluate_control_conditions( msi_dialog
*dialog
);
136 static LRESULT WINAPI
MSIRadioGroup_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
);
139 /* dialog sequencing */
141 #define WM_MSI_DIALOG_CREATE (WM_USER+0x100)
142 #define WM_MSI_DIALOG_DESTROY (WM_USER+0x101)
144 static DWORD uiThreadId
;
145 static HWND hMsiHiddenWindow
;
147 static INT
msi_dialog_scale_unit( msi_dialog
*dialog
, INT val
)
149 return (dialog
->scale
* val
+ 5) / 10;
152 static msi_control
*msi_dialog_find_control( msi_dialog
*dialog
, LPCWSTR name
)
154 msi_control
*control
;
158 LIST_FOR_EACH_ENTRY( control
, &dialog
->controls
, msi_control
, entry
)
159 if( !strcmpW( control
->name
, name
) ) /* FIXME: case sensitive? */
164 static msi_control
*msi_dialog_find_control_by_hwnd( msi_dialog
*dialog
, HWND hwnd
)
166 msi_control
*control
;
168 LIST_FOR_EACH_ENTRY( control
, &dialog
->controls
, msi_control
, entry
)
169 if( hwnd
== control
->hwnd
)
174 static LPWSTR
msi_get_deformatted_field( MSIPACKAGE
*package
, MSIRECORD
*rec
, int field
)
176 LPCWSTR str
= MSI_RecordGetString( rec
, field
);
180 deformat_string( package
, str
, &ret
);
185 * msi_dialog_get_style
187 * Extract the {\style} string from the front of the text to display and
188 * update the pointer.
190 static LPWSTR
msi_dialog_get_style( LPCWSTR p
, LPCWSTR
*rest
)
201 q
= strchrW( p
, '}' );
204 if( *p
== '\\' || *p
== '&' )
207 /* little bit of sanity checking to stop us getting confused with RTF */
209 if( *i
== '}' || *i
== '\\' )
215 ret
= msi_alloc( len
*sizeof(WCHAR
) );
218 memcpy( ret
, p
, len
*sizeof(WCHAR
) );
223 static UINT
msi_dialog_add_font( MSIRECORD
*rec
, LPVOID param
)
225 msi_dialog
*dialog
= param
;
232 /* create a font and add it to the list */
233 name
= MSI_RecordGetString( rec
, 1 );
234 font
= msi_alloc( sizeof *font
+ strlenW( name
)*sizeof (WCHAR
) );
235 strcpyW( font
->name
, name
);
236 font
->next
= dialog
->font_list
;
237 dialog
->font_list
= font
;
239 memset( &lf
, 0, sizeof lf
);
240 face
= MSI_RecordGetString( rec
, 2 );
241 lf
.lfHeight
= MSI_RecordGetInteger( rec
, 3 );
242 style
= MSI_RecordGetInteger( rec
, 5 );
243 if( style
& msidbTextStyleStyleBitsBold
)
244 lf
.lfWeight
= FW_BOLD
;
245 if( style
& msidbTextStyleStyleBitsItalic
)
247 if( style
& msidbTextStyleStyleBitsUnderline
)
248 lf
.lfUnderline
= TRUE
;
249 if( style
& msidbTextStyleStyleBitsStrike
)
250 lf
.lfStrikeOut
= TRUE
;
251 lstrcpynW( lf
.lfFaceName
, face
, LF_FACESIZE
);
253 /* adjust the height */
254 hdc
= GetDC( dialog
->hwnd
);
257 lf
.lfHeight
= -MulDiv(lf
.lfHeight
, GetDeviceCaps(hdc
, LOGPIXELSY
), 72);
258 ReleaseDC( dialog
->hwnd
, hdc
);
261 font
->hfont
= CreateFontIndirectW( &lf
);
263 TRACE("Adding font style %s\n", debugstr_w(font
->name
) );
265 return ERROR_SUCCESS
;
268 static msi_font
*msi_dialog_find_font( msi_dialog
*dialog
, LPCWSTR name
)
272 for( font
= dialog
->font_list
; font
; font
= font
->next
)
273 if( !strcmpW( font
->name
, name
) ) /* FIXME: case sensitive? */
279 static UINT
msi_dialog_set_font( msi_dialog
*dialog
, HWND hwnd
, LPCWSTR name
)
283 font
= msi_dialog_find_font( dialog
, name
);
285 SendMessageW( hwnd
, WM_SETFONT
, (WPARAM
) font
->hfont
, TRUE
);
287 ERR("No font entry for %s\n", debugstr_w(name
));
288 return ERROR_SUCCESS
;
291 static UINT
msi_dialog_build_font_list( msi_dialog
*dialog
)
293 static const WCHAR query
[] = {
294 'S','E','L','E','C','T',' ','*',' ',
295 'F','R','O','M',' ','`','T','e','x','t','S','t','y','l','e','`',' ',0
298 MSIQUERY
*view
= NULL
;
300 TRACE("dialog %p\n", dialog
);
302 r
= MSI_OpenQuery( dialog
->package
->db
, &view
, query
);
303 if( r
!= ERROR_SUCCESS
)
306 r
= MSI_IterateRecords( view
, NULL
, msi_dialog_add_font
, dialog
);
307 msiobj_release( &view
->hdr
);
312 static msi_control
*msi_dialog_create_window( msi_dialog
*dialog
,
313 MSIRECORD
*rec
, LPCWSTR szCls
, LPCWSTR name
, LPCWSTR text
,
314 DWORD style
, HWND parent
)
316 DWORD x
, y
, width
, height
;
317 LPWSTR font
= NULL
, title_font
= NULL
;
318 LPCWSTR title
= NULL
;
319 msi_control
*control
;
323 control
= msi_alloc( sizeof *control
+ strlenW(name
)*sizeof(WCHAR
) );
324 strcpyW( control
->name
, name
);
325 list_add_head( &dialog
->controls
, &control
->entry
);
326 control
->handler
= NULL
;
327 control
->property
= NULL
;
328 control
->value
= NULL
;
329 control
->hBitmap
= NULL
;
330 control
->hIcon
= NULL
;
331 control
->tabnext
= strdupW( MSI_RecordGetString( rec
, 11) );
333 x
= MSI_RecordGetInteger( rec
, 4 );
334 y
= MSI_RecordGetInteger( rec
, 5 );
335 width
= MSI_RecordGetInteger( rec
, 6 );
336 height
= MSI_RecordGetInteger( rec
, 7 );
338 x
= msi_dialog_scale_unit( dialog
, x
);
339 y
= msi_dialog_scale_unit( dialog
, y
);
340 width
= msi_dialog_scale_unit( dialog
, width
);
341 height
= msi_dialog_scale_unit( dialog
, height
);
345 deformat_string( dialog
->package
, text
, &title_font
);
346 font
= msi_dialog_get_style( title_font
, &title
);
349 control
->hwnd
= CreateWindowW( szCls
, title
, style
,
350 x
, y
, width
, height
, parent
, NULL
, NULL
, NULL
);
352 TRACE("Dialog %s control %s hwnd %p\n",
353 debugstr_w(dialog
->name
), debugstr_w(text
), control
->hwnd
);
355 msi_dialog_set_font( dialog
, control
->hwnd
,
356 font
? font
: dialog
->default_font
);
358 msi_free( title_font
);
364 static MSIRECORD
*msi_get_binary_record( MSIDATABASE
*db
, LPCWSTR name
)
366 static const WCHAR query
[] = {
367 's','e','l','e','c','t',' ','*',' ',
368 'f','r','o','m',' ','B','i','n','a','r','y',' ',
369 'w','h','e','r','e',' ',
370 '`','N','a','m','e','`',' ','=',' ','\'','%','s','\'',0
373 return MSI_QueryGetRecord( db
, query
, name
);
376 static LPWSTR
msi_create_tmp_path(void)
380 static const WCHAR prefix
[] = { 'm','s','i',0 };
383 r
= GetTempPathW( MAX_PATH
, tmp
);
386 len
= lstrlenW( tmp
) + 20;
387 path
= msi_alloc( len
* sizeof (WCHAR
) );
390 r
= GetTempFileNameW( tmp
, prefix
, 0, path
);
401 static HANDLE
msi_load_image( MSIDATABASE
*db
, LPCWSTR name
, UINT type
,
402 UINT cx
, UINT cy
, UINT flags
)
404 MSIRECORD
*rec
= NULL
;
405 HANDLE himage
= NULL
;
409 TRACE("%p %s %u %u %08x\n", db
, debugstr_w(name
), cx
, cy
, flags
);
411 tmp
= msi_create_tmp_path();
415 rec
= msi_get_binary_record( db
, name
);
418 r
= MSI_RecordStreamToFile( rec
, 2, tmp
);
419 if( r
== ERROR_SUCCESS
)
421 himage
= LoadImageW( 0, tmp
, type
, cx
, cy
, flags
);
424 msiobj_release( &rec
->hdr
);
431 static HICON
msi_load_icon( MSIDATABASE
*db
, LPCWSTR text
, UINT attributes
)
433 DWORD cx
= 0, cy
= 0, flags
;
435 flags
= LR_LOADFROMFILE
| LR_DEFAULTSIZE
;
436 if( attributes
& msidbControlAttributesFixedSize
)
438 flags
&= ~LR_DEFAULTSIZE
;
439 if( attributes
& msidbControlAttributesIconSize16
)
444 if( attributes
& msidbControlAttributesIconSize32
)
449 /* msidbControlAttributesIconSize48 handled by above logic */
451 return msi_load_image( db
, text
, IMAGE_ICON
, cx
, cy
, flags
);
455 /* called from the Control Event subscription code */
456 void msi_dialog_handle_event( msi_dialog
* dialog
, LPCWSTR control
,
457 LPCWSTR attribute
, MSIRECORD
*rec
)
462 ctrl
= msi_dialog_find_control( dialog
, control
);
465 if( lstrcmpW(attribute
, szText
) )
467 ERR("Attribute %s\n", debugstr_w(attribute
));
470 text
= MSI_RecordGetString( rec
, 1 );
471 SetWindowTextW( ctrl
->hwnd
, text
);
472 msi_dialog_check_messages( NULL
);
475 static void msi_dialog_map_events(msi_dialog
* dialog
, LPCWSTR control
)
477 static WCHAR Query
[] = {
478 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
479 '`','E','v','e','n','t','M','a','p','p','i','n','g','`',' ',
480 'W','H','E','R','E',' ',
481 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',' ',
483 '`','C','o','n','t','r','o','l','_','`',' ','=',' ','\'','%','s','\'',0
486 LPCWSTR event
, attribute
;
488 row
= MSI_QueryGetRecord( dialog
->package
->db
, Query
, dialog
->name
, control
);
492 event
= MSI_RecordGetString( row
, 3 );
493 attribute
= MSI_RecordGetString( row
, 4 );
494 ControlEvent_SubscribeToEvent( dialog
->package
, event
, control
, attribute
);
495 msiobj_release( &row
->hdr
);
498 /* everything except radio buttons */
499 static msi_control
*msi_dialog_add_control( msi_dialog
*dialog
,
500 MSIRECORD
*rec
, LPCWSTR szCls
, DWORD style
)
505 name
= MSI_RecordGetString( rec
, 2 );
506 attributes
= MSI_RecordGetInteger( rec
, 8 );
507 text
= MSI_RecordGetString( rec
, 10 );
508 if( attributes
& msidbControlAttributesVisible
)
510 if( ~attributes
& msidbControlAttributesEnabled
)
511 style
|= WS_DISABLED
;
513 msi_dialog_map_events(dialog
, name
);
515 return msi_dialog_create_window( dialog
, rec
, szCls
, name
, text
,
516 style
, dialog
->hwnd
);
526 * we don't erase our own background,
527 * so we have to make sure that the parent window redraws first
529 static void msi_text_on_settext( HWND hWnd
)
534 hParent
= GetParent( hWnd
);
535 GetWindowRect( hWnd
, &rc
);
536 MapWindowPoints( NULL
, hParent
, (LPPOINT
) &rc
, 2 );
537 InvalidateRect( hParent
, &rc
, TRUE
);
540 static LRESULT WINAPI
541 MSIText_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
543 struct msi_text_info
*info
;
546 TRACE("%p %04x %08x %08lx\n", hWnd
, msg
, wParam
, lParam
);
548 info
= GetPropW(hWnd
, szButtonData
);
550 if( msg
== WM_CTLCOLORSTATIC
&&
551 ( info
->attributes
& msidbControlAttributesTransparent
) )
553 SetBkMode( (HDC
)wParam
, TRANSPARENT
);
554 return (LRESULT
) GetStockObject(NULL_BRUSH
);
557 r
= CallWindowProcW(info
->oldproc
, hWnd
, msg
, wParam
, lParam
);
562 msi_text_on_settext( hWnd
);
566 RemovePropW( hWnd
, szButtonData
);
573 static UINT
msi_dialog_text_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
575 msi_control
*control
;
576 struct msi_text_info
*info
;
578 TRACE("%p %p\n", dialog
, rec
);
580 control
= msi_dialog_add_control( dialog
, rec
, szStatic
, SS_LEFT
| WS_GROUP
);
582 return ERROR_FUNCTION_FAILED
;
584 info
= msi_alloc( sizeof *info
);
586 return ERROR_SUCCESS
;
588 info
->attributes
= MSI_RecordGetInteger( rec
, 8 );
589 if( info
->attributes
& msidbControlAttributesTransparent
)
590 SetWindowLongPtrW( control
->hwnd
, GWL_EXSTYLE
, WS_EX_TRANSPARENT
);
592 info
->oldproc
= (WNDPROC
) SetWindowLongPtrW( control
->hwnd
, GWLP_WNDPROC
,
593 (LONG_PTR
)MSIText_WndProc
);
594 SetPropW( control
->hwnd
, szButtonData
, info
);
596 return ERROR_SUCCESS
;
599 static UINT
msi_dialog_button_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
601 msi_control
*control
;
602 UINT attributes
, style
;
605 TRACE("%p %p\n", dialog
, rec
);
608 attributes
= MSI_RecordGetInteger( rec
, 8 );
609 if( attributes
& msidbControlAttributesIcon
)
612 control
= msi_dialog_add_control( dialog
, rec
, szButton
, style
);
614 return ERROR_FUNCTION_FAILED
;
616 control
->handler
= msi_dialog_button_handler
;
619 text
= msi_get_deformatted_field( dialog
->package
, rec
, 10 );
620 control
->hIcon
= msi_load_icon( dialog
->package
->db
, text
, attributes
);
621 if( attributes
& msidbControlAttributesIcon
)
622 SendMessageW( control
->hwnd
, BM_SETIMAGE
, IMAGE_ICON
, (LPARAM
) control
->hIcon
);
625 return ERROR_SUCCESS
;
628 static LPWSTR
msi_get_checkbox_value( msi_dialog
*dialog
, LPCWSTR prop
)
630 static const WCHAR query
[] = {
631 'S','E','L','E','C','T',' ','*',' ',
632 'F','R','O','M',' ','`','C','h','e','c','k','B','o','x',' ','`',
633 'W','H','E','R','E',' ',
634 '`','P','r','o','p','e','r','t','y','`',' ','=',' ',
637 MSIRECORD
*rec
= NULL
;
640 /* find if there is a value associated with the checkbox */
641 rec
= MSI_QueryGetRecord( dialog
->package
->db
, query
, prop
);
645 ret
= msi_get_deformatted_field( dialog
->package
, rec
, 2 );
651 msiobj_release( &rec
->hdr
);
655 ret
= msi_dup_property( dialog
->package
, prop
);
665 static UINT
msi_dialog_checkbox_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
667 msi_control
*control
;
670 TRACE("%p %p\n", dialog
, rec
);
672 control
= msi_dialog_add_control( dialog
, rec
, szButton
,
673 BS_CHECKBOX
| BS_MULTILINE
| WS_TABSTOP
);
674 control
->handler
= msi_dialog_checkbox_handler
;
675 prop
= MSI_RecordGetString( rec
, 9 );
678 control
->property
= strdupW( prop
);
679 control
->value
= msi_get_checkbox_value( dialog
, prop
);
680 TRACE("control %s value %s\n", debugstr_w(control
->property
),
681 debugstr_w(control
->value
));
683 msi_dialog_checkbox_sync_state( dialog
, control
);
685 return ERROR_SUCCESS
;
688 static UINT
msi_dialog_line_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
690 TRACE("%p %p\n", dialog
, rec
);
692 msi_dialog_add_control( dialog
, rec
, szStatic
, SS_ETCHEDHORZ
| SS_SUNKEN
);
693 return ERROR_SUCCESS
;
696 /******************** Scroll Text ********************************************/
698 struct msi_scrolltext_info
701 msi_control
*control
;
706 static LRESULT WINAPI
707 MSIScrollText_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
709 struct msi_scrolltext_info
*info
;
712 TRACE("%p %04x %08x %08lx\n", hWnd
, msg
, wParam
, lParam
);
714 info
= GetPropW( hWnd
, szButtonData
);
716 r
= CallWindowProcW( info
->oldproc
, hWnd
, msg
, wParam
, lParam
);
721 FreeLibrary( info
->hRichedit
);
723 RemovePropW( hWnd
, szButtonData
);
726 msi_dialog_button_handler( info
->dialog
, info
->control
, BN_CLICKED
);
732 struct msi_streamin_info
739 static DWORD CALLBACK
740 msi_richedit_stream_in( DWORD_PTR arg
, LPBYTE buffer
, LONG count
, LONG
*pcb
)
742 struct msi_streamin_info
*info
= (struct msi_streamin_info
*) arg
;
744 if( (count
+ info
->offset
) > info
->length
)
745 count
= info
->length
- info
->offset
;
746 memcpy( buffer
, &info
->string
[ info
->offset
], count
);
748 info
->offset
+= count
;
750 TRACE("%ld/%ld\n", info
->offset
, info
->length
);
755 static void msi_scrolltext_add_text( msi_control
*control
, LPCWSTR text
)
757 struct msi_streamin_info info
;
760 info
.string
= strdupWtoA( text
);
762 info
.length
= lstrlenA( info
.string
) + 1;
764 es
.dwCookie
= (DWORD_PTR
) &info
;
766 es
.pfnCallback
= msi_richedit_stream_in
;
768 SendMessageW( control
->hwnd
, EM_STREAMIN
, SF_RTF
, (LPARAM
) &es
);
770 msi_free( info
.string
);
773 static UINT
msi_dialog_scrolltext_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
775 static const WCHAR szRichEdit20W
[] = {
776 'R','i','c','h','E','d','i','t','2','0','W',0
778 struct msi_scrolltext_info
*info
;
779 msi_control
*control
;
782 info
= msi_alloc( sizeof *info
);
784 return ERROR_FUNCTION_FAILED
;
786 info
->hRichedit
= LoadLibraryA("riched20");
788 style
= WS_BORDER
| ES_MULTILINE
| WS_VSCROLL
|
789 ES_READONLY
| ES_AUTOVSCROLL
| WS_TABSTOP
;
790 control
= msi_dialog_add_control( dialog
, rec
, szRichEdit20W
, style
);
793 FreeLibrary( info
->hRichedit
);
795 return ERROR_FUNCTION_FAILED
;
798 info
->dialog
= dialog
;
799 info
->control
= control
;
801 /* subclass the static control */
802 info
->oldproc
= (WNDPROC
) SetWindowLongPtrW( control
->hwnd
, GWLP_WNDPROC
,
803 (LONG_PTR
)MSIScrollText_WndProc
);
804 SetPropW( control
->hwnd
, szButtonData
, info
);
806 /* add the text into the richedit */
807 msi_scrolltext_add_text( control
, MSI_RecordGetString( rec
, 10 ) );
809 return ERROR_SUCCESS
;
812 static HBITMAP
msi_load_picture( MSIDATABASE
*db
, LPCWSTR name
,
813 INT cx
, INT cy
, DWORD flags
)
815 HBITMAP hOleBitmap
= 0, hBitmap
= 0, hOldSrcBitmap
, hOldDestBitmap
;
816 MSIRECORD
*rec
= NULL
;
818 IPicture
*pic
= NULL
;
823 rec
= msi_get_binary_record( db
, name
);
827 r
= MSI_RecordGetIStream( rec
, 2, &stm
);
828 msiobj_release( &rec
->hdr
);
829 if( r
!= ERROR_SUCCESS
)
832 r
= OleLoadPicture( stm
, 0, TRUE
, &IID_IPicture
, (LPVOID
*) &pic
);
833 IStream_Release( stm
);
836 ERR("failed to load picture\n");
840 r
= IPicture_get_Handle( pic
, (OLE_HANDLE
*) &hOleBitmap
);
843 ERR("failed to get bitmap handle\n");
847 /* make the bitmap the desired size */
848 r
= GetObjectW( hOleBitmap
, sizeof bm
, &bm
);
851 ERR("failed to get bitmap size\n");
855 if (flags
& LR_DEFAULTSIZE
)
861 srcdc
= CreateCompatibleDC( NULL
);
862 hOldSrcBitmap
= SelectObject( srcdc
, hOleBitmap
);
863 destdc
= CreateCompatibleDC( NULL
);
864 hBitmap
= CreateCompatibleBitmap( srcdc
, cx
, cy
);
865 hOldDestBitmap
= SelectObject( destdc
, hBitmap
);
866 StretchBlt( destdc
, 0, 0, cx
, cy
,
867 srcdc
, 0, 0, bm
.bmWidth
, bm
.bmHeight
, SRCCOPY
);
868 SelectObject( srcdc
, hOldSrcBitmap
);
869 SelectObject( destdc
, hOldDestBitmap
);
875 IPicture_Release( pic
);
879 static UINT
msi_dialog_bitmap_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
881 UINT cx
, cy
, flags
, style
, attributes
;
882 msi_control
*control
;
885 flags
= LR_LOADFROMFILE
;
886 style
= SS_BITMAP
| SS_LEFT
| WS_GROUP
;
888 attributes
= MSI_RecordGetInteger( rec
, 8 );
889 if( attributes
& msidbControlAttributesFixedSize
)
891 flags
|= LR_DEFAULTSIZE
;
892 style
|= SS_CENTERIMAGE
;
895 control
= msi_dialog_add_control( dialog
, rec
, szStatic
, style
);
896 cx
= MSI_RecordGetInteger( rec
, 6 );
897 cy
= MSI_RecordGetInteger( rec
, 7 );
898 cx
= msi_dialog_scale_unit( dialog
, cx
);
899 cy
= msi_dialog_scale_unit( dialog
, cy
);
901 text
= msi_get_deformatted_field( dialog
->package
, rec
, 10 );
902 control
->hBitmap
= msi_load_picture( dialog
->package
->db
, text
, cx
, cy
, flags
);
903 if( control
->hBitmap
)
904 SendMessageW( control
->hwnd
, STM_SETIMAGE
,
905 IMAGE_BITMAP
, (LPARAM
) control
->hBitmap
);
907 ERR("Failed to load bitmap %s\n", debugstr_w(text
));
911 return ERROR_SUCCESS
;
914 static UINT
msi_dialog_icon_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
916 msi_control
*control
;
922 control
= msi_dialog_add_control( dialog
, rec
, szStatic
,
923 SS_ICON
| SS_CENTERIMAGE
| WS_GROUP
);
925 attributes
= MSI_RecordGetInteger( rec
, 8 );
926 text
= msi_get_deformatted_field( dialog
->package
, rec
, 10 );
927 control
->hIcon
= msi_load_icon( dialog
->package
->db
, text
, attributes
);
929 SendMessageW( control
->hwnd
, STM_SETICON
, (WPARAM
) control
->hIcon
, 0 );
931 ERR("Failed to load bitmap %s\n", debugstr_w(text
));
933 return ERROR_SUCCESS
;
936 static UINT
msi_dialog_combo_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
938 static const WCHAR szCombo
[] = { 'C','O','M','B','O','B','O','X',0 };
940 msi_dialog_add_control( dialog
, rec
, szCombo
,
941 SS_BITMAP
| SS_LEFT
| SS_CENTERIMAGE
);
942 return ERROR_SUCCESS
;
945 static UINT
msi_dialog_edit_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
947 msi_control
*control
;
951 control
= msi_dialog_add_control( dialog
, rec
, szEdit
,
952 WS_BORDER
| WS_TABSTOP
);
953 control
->handler
= msi_dialog_edit_handler
;
954 prop
= MSI_RecordGetString( rec
, 9 );
956 control
->property
= strdupW( prop
);
957 val
= msi_dup_property( dialog
->package
, control
->property
);
958 SetWindowTextW( control
->hwnd
, val
);
960 return ERROR_SUCCESS
;
963 /******************** Masked Edit ********************************************/
965 #define MASK_MAX_GROUPS 10
967 struct msi_mask_group
975 struct msi_maskedit_info
983 struct msi_mask_group group
[MASK_MAX_GROUPS
];
986 static BOOL
msi_mask_editable( WCHAR type
)
1001 static void msi_mask_control_change( struct msi_maskedit_info
*info
)
1006 val
= msi_alloc( (info
->num_chars
+1)*sizeof(WCHAR
) );
1007 for( i
=0, n
=0; i
<info
->num_groups
; i
++ )
1009 if( (info
->group
[i
].len
+ n
) > info
->num_chars
)
1011 ERR("can't fit control %d text into template\n",i
);
1014 if (!msi_mask_editable(info
->group
[i
].type
))
1016 for(r
=0; r
<info
->group
[i
].len
; r
++)
1017 val
[n
+r
] = info
->group
[i
].type
;
1022 r
= GetWindowTextW( info
->group
[i
].hwnd
, &val
[n
], info
->group
[i
].len
+1 );
1023 if( r
!= info
->group
[i
].len
)
1029 TRACE("%d/%d controls were good\n", i
, info
->num_groups
);
1031 if( i
== info
->num_groups
)
1033 TRACE("Set property %s to %s\n",
1034 debugstr_w(info
->prop
), debugstr_w(val
) );
1035 CharUpperBuffW( val
, info
->num_chars
);
1036 MSI_SetPropertyW( info
->dialog
->package
, info
->prop
, val
);
1037 msi_dialog_evaluate_control_conditions( info
->dialog
);
1042 /* now move to the next control if necessary */
1043 static VOID
msi_mask_next_control( struct msi_maskedit_info
*info
, HWND hWnd
)
1048 for( i
=0; i
<info
->num_groups
; i
++ )
1049 if( info
->group
[i
].hwnd
== hWnd
)
1052 /* don't move from the last control */
1053 if( i
>= (info
->num_groups
-1) )
1056 len
= SendMessageW( hWnd
, WM_GETTEXTLENGTH
, 0, 0 );
1057 if( len
< info
->group
[i
].len
)
1060 hWndNext
= GetNextDlgTabItem( GetParent( hWnd
), hWnd
, FALSE
);
1061 SetFocus( hWndNext
);
1064 static LRESULT WINAPI
1065 MSIMaskedEdit_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1067 struct msi_maskedit_info
*info
;
1070 TRACE("%p %04x %08x %08lx\n", hWnd
, msg
, wParam
, lParam
);
1072 info
= GetPropW(hWnd
, szButtonData
);
1074 r
= CallWindowProcW(info
->oldproc
, hWnd
, msg
, wParam
, lParam
);
1079 if (HIWORD(wParam
) == EN_CHANGE
)
1081 msi_mask_control_change( info
);
1082 msi_mask_next_control( info
, (HWND
) lParam
);
1086 msi_free( info
->prop
);
1088 RemovePropW( hWnd
, szButtonData
);
1095 /* fish the various bits of the property out and put them in the control */
1097 msi_maskedit_set_text( struct msi_maskedit_info
*info
, LPCWSTR text
)
1103 for( i
= 0; i
< info
->num_groups
; i
++ )
1105 if( info
->group
[i
].len
< lstrlenW( p
) )
1107 LPWSTR chunk
= strdupW( p
);
1108 chunk
[ info
->group
[i
].len
] = 0;
1109 SetWindowTextW( info
->group
[i
].hwnd
, chunk
);
1114 SetWindowTextW( info
->group
[i
].hwnd
, p
);
1117 p
+= info
->group
[i
].len
;
1121 static struct msi_maskedit_info
* msi_dialog_parse_groups( LPCWSTR mask
)
1123 struct msi_maskedit_info
* info
= NULL
;
1124 int i
= 0, n
= 0, total
= 0;
1127 TRACE("masked control, template %s\n", debugstr_w(mask
));
1132 info
= msi_alloc_zero( sizeof *info
);
1136 p
= strchrW(mask
, '<');
1142 for( i
=0; i
<MASK_MAX_GROUPS
; i
++ )
1144 /* stop at the end of the string */
1145 if( p
[0] == 0 || p
[0] == '>' )
1148 /* count the number of the same identifier */
1149 for( n
=0; p
[n
] == p
[0]; n
++ )
1151 info
->group
[i
].ofs
= total
;
1152 info
->group
[i
].type
= p
[0];
1156 total
++; /* an extra not part of the group */
1158 info
->group
[i
].len
= n
;
1163 TRACE("%d characters in %d groups\n", total
, i
);
1164 if( i
== MASK_MAX_GROUPS
)
1165 ERR("too many groups in PIDTemplate %s\n", debugstr_w(mask
));
1167 info
->num_chars
= total
;
1168 info
->num_groups
= i
;
1174 msi_maskedit_create_children( struct msi_maskedit_info
*info
, LPCWSTR font
)
1176 DWORD width
, height
, style
, wx
, ww
;
1181 style
= WS_CHILD
| WS_BORDER
| WS_VISIBLE
| WS_TABSTOP
| ES_AUTOHSCROLL
;
1183 GetClientRect( info
->hwnd
, &rect
);
1185 width
= rect
.right
- rect
.left
;
1186 height
= rect
.bottom
- rect
.top
;
1188 for( i
= 0; i
< info
->num_groups
; i
++ )
1190 if (!msi_mask_editable( info
->group
[i
].type
))
1192 wx
= (info
->group
[i
].ofs
* width
) / info
->num_chars
;
1193 ww
= (info
->group
[i
].len
* width
) / info
->num_chars
;
1195 hwnd
= CreateWindowW( szEdit
, NULL
, style
, wx
, 0, ww
, height
,
1196 info
->hwnd
, NULL
, NULL
, NULL
);
1199 ERR("failed to create mask edit sub window\n");
1203 SendMessageW( hwnd
, EM_LIMITTEXT
, info
->group
[i
].len
, 0 );
1205 msi_dialog_set_font( info
->dialog
, hwnd
,
1206 font
?font
:info
->dialog
->default_font
);
1207 info
->group
[i
].hwnd
= hwnd
;
1212 * office 2003 uses "73931<````=````=````=````=`````>@@@@@"
1213 * delphi 7 uses "<????-??????-??????-????>" and "<???-???>"
1214 * filemaker pro 7 uses "<^^^^=^^^^=^^^^=^^^^=^^^^=^^^^=^^^^^>"
1216 static UINT
msi_dialog_maskedit_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1218 LPWSTR font_mask
, val
= NULL
, font
;
1219 struct msi_maskedit_info
*info
= NULL
;
1220 UINT ret
= ERROR_SUCCESS
;
1221 msi_control
*control
;
1226 font_mask
= msi_get_deformatted_field( dialog
->package
, rec
, 10 );
1227 font
= msi_dialog_get_style( font_mask
, &mask
);
1230 ERR("mask template is empty\n");
1234 info
= msi_dialog_parse_groups( mask
);
1237 ERR("template %s is invalid\n", debugstr_w(mask
));
1241 info
->dialog
= dialog
;
1243 control
= msi_dialog_add_control( dialog
, rec
, szStatic
,
1244 SS_OWNERDRAW
| WS_GROUP
| WS_VISIBLE
);
1247 ERR("Failed to create maskedit container\n");
1248 ret
= ERROR_FUNCTION_FAILED
;
1251 SetWindowLongPtrW( control
->hwnd
, GWL_EXSTYLE
, WS_EX_CONTROLPARENT
);
1253 info
->hwnd
= control
->hwnd
;
1255 /* subclass the static control */
1256 info
->oldproc
= (WNDPROC
) SetWindowLongPtrW( info
->hwnd
, GWLP_WNDPROC
,
1257 (LONG_PTR
)MSIMaskedEdit_WndProc
);
1258 SetPropW( control
->hwnd
, szButtonData
, info
);
1260 prop
= MSI_RecordGetString( rec
, 9 );
1262 info
->prop
= strdupW( prop
);
1264 msi_maskedit_create_children( info
, font
);
1268 val
= msi_dup_property( dialog
->package
, prop
);
1271 msi_maskedit_set_text( info
, val
);
1277 if( ret
!= ERROR_SUCCESS
)
1279 msi_free( font_mask
);
1284 /******************** Progress Bar *****************************************/
1286 static UINT
msi_dialog_progress_bar( msi_dialog
*dialog
, MSIRECORD
*rec
)
1288 msi_dialog_add_control( dialog
, rec
, PROGRESS_CLASSW
, WS_VISIBLE
);
1289 return ERROR_SUCCESS
;
1292 /******************** Path Edit ********************************************/
1294 static UINT
msi_dialog_pathedit_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1296 FIXME("not implemented properly\n");
1297 return msi_dialog_edit_control( dialog
, rec
);
1300 /* radio buttons are a bit different from normal controls */
1301 static UINT
msi_dialog_create_radiobutton( MSIRECORD
*rec
, LPVOID param
)
1303 radio_button_group_descr
*group
= (radio_button_group_descr
*)param
;
1304 msi_dialog
*dialog
= group
->dialog
;
1305 msi_control
*control
;
1306 LPCWSTR prop
, text
, name
;
1307 DWORD style
, attributes
= group
->attributes
;
1309 style
= WS_CHILD
| BS_AUTORADIOBUTTON
| BS_MULTILINE
| WS_TABSTOP
;
1310 name
= MSI_RecordGetString( rec
, 3 );
1311 text
= MSI_RecordGetString( rec
, 8 );
1312 if( attributes
& 1 )
1313 style
|= WS_VISIBLE
;
1314 if( ~attributes
& 2 )
1315 style
|= WS_DISABLED
;
1317 control
= msi_dialog_create_window( dialog
, rec
, szButton
, name
, text
,
1318 style
, group
->parent
->hwnd
);
1320 return ERROR_FUNCTION_FAILED
;
1321 control
->handler
= msi_dialog_radiogroup_handler
;
1323 prop
= MSI_RecordGetString( rec
, 1 );
1325 control
->property
= strdupW( prop
);
1327 return ERROR_SUCCESS
;
1330 static UINT
msi_dialog_radiogroup_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1332 static const WCHAR query
[] = {
1333 'S','E','L','E','C','T',' ','*',' ',
1334 'F','R','O','M',' ','R','a','d','i','o','B','u','t','t','o','n',' ',
1335 'W','H','E','R','E',' ',
1336 '`','P','r','o','p','e','r','t','y','`',' ','=',' ','\'','%','s','\'',0};
1339 msi_control
*control
;
1340 MSIQUERY
*view
= NULL
;
1341 radio_button_group_descr group
;
1342 MSIPACKAGE
*package
= dialog
->package
;
1345 prop
= MSI_RecordGetString( rec
, 9 );
1347 TRACE("%p %p %s\n", dialog
, rec
, debugstr_w( prop
));
1349 /* Create parent group box to hold radio buttons */
1350 control
= msi_dialog_add_control( dialog
, rec
, szButton
, BS_OWNERDRAW
|WS_GROUP
);
1352 return ERROR_FUNCTION_FAILED
;
1354 oldproc
= (WNDPROC
) SetWindowLongPtrW( control
->hwnd
, GWLP_WNDPROC
,
1355 (LONG_PTR
)MSIRadioGroup_WndProc
);
1356 SetPropW(control
->hwnd
, szButtonData
, oldproc
);
1357 SetWindowLongPtrW( control
->hwnd
, GWL_EXSTYLE
, WS_EX_CONTROLPARENT
);
1360 control
->property
= strdupW( prop
);
1362 /* query the Radio Button table for all control in this group */
1363 r
= MSI_OpenQuery( package
->db
, &view
, query
, prop
);
1364 if( r
!= ERROR_SUCCESS
)
1366 ERR("query failed for dialog %s radio group %s\n",
1367 debugstr_w(dialog
->name
), debugstr_w(prop
));
1368 return ERROR_INVALID_PARAMETER
;
1371 group
.dialog
= dialog
;
1372 group
.parent
= control
;
1373 group
.attributes
= MSI_RecordGetInteger( rec
, 8 );
1375 r
= MSI_IterateRecords( view
, 0, msi_dialog_create_radiobutton
, &group
);
1376 msiobj_release( &view
->hdr
);
1381 /******************** Selection Tree ***************************************/
1384 msi_dialog_tv_add_child_features( MSIPACKAGE
*package
, HWND hwnd
,
1385 LPCWSTR parent
, HTREEITEM hParent
)
1387 MSIFEATURE
*feature
;
1388 TVINSERTSTRUCTW tvis
;
1391 LIST_FOR_EACH_ENTRY( feature
, &package
->features
, MSIFEATURE
, entry
)
1393 if ( lstrcmpW( parent
, feature
->Feature_Parent
) )
1396 if ( !feature
->Title
)
1399 memset( &tvis
, 0, sizeof tvis
);
1400 tvis
.hParent
= hParent
;
1401 tvis
.hInsertAfter
= TVI_SORT
;
1404 tvis
.u
.item
.mask
= TVIF_TEXT
;
1405 tvis
.u
.item
.pszText
= feature
->Title
;
1407 tvis
.u
.item
.lParam
= (LPARAM
) feature
;
1408 hitem
= (HTREEITEM
) SendMessageW( hwnd
, TVM_INSERTITEMW
, 0, (LPARAM
) &tvis
);
1412 msi_dialog_tv_add_child_features( package
, hwnd
,
1413 feature
->Feature
, hitem
);
1417 static UINT
msi_dialog_selection_tree( msi_dialog
*dialog
, MSIRECORD
*rec
)
1419 msi_control
*control
;
1422 MSIPACKAGE
*package
= dialog
->package
;
1424 prop
= MSI_RecordGetString( rec
, 9 );
1425 val
= msi_dup_property( package
, prop
);
1426 control
= msi_dialog_add_control( dialog
, rec
, WC_TREEVIEWW
,
1427 TVS_HASBUTTONS
| WS_GROUP
| WS_VSCROLL
);
1429 return ERROR_FUNCTION_FAILED
;
1431 msi_dialog_tv_add_child_features( package
, control
->hwnd
, NULL
, NULL
);
1435 return ERROR_SUCCESS
;
1438 struct control_handler msi_dialog_handler
[] =
1440 { szText
, msi_dialog_text_control
},
1441 { szPushButton
, msi_dialog_button_control
},
1442 { szLine
, msi_dialog_line_control
},
1443 { szBitmap
, msi_dialog_bitmap_control
},
1444 { szCheckBox
, msi_dialog_checkbox_control
},
1445 { szScrollableText
, msi_dialog_scrolltext_control
},
1446 { szComboBox
, msi_dialog_combo_control
},
1447 { szEdit
, msi_dialog_edit_control
},
1448 { szMaskedEdit
, msi_dialog_maskedit_control
},
1449 { szPathEdit
, msi_dialog_pathedit_control
},
1450 { szProgressBar
, msi_dialog_progress_bar
},
1451 { szRadioButtonGroup
, msi_dialog_radiogroup_control
},
1452 { szIcon
, msi_dialog_icon_control
},
1453 { szSelectionTree
, msi_dialog_selection_tree
},
1456 #define NUM_CONTROL_TYPES (sizeof msi_dialog_handler/sizeof msi_dialog_handler[0])
1458 static UINT
msi_dialog_create_controls( MSIRECORD
*rec
, LPVOID param
)
1460 msi_dialog
*dialog
= param
;
1461 LPCWSTR control_type
;
1464 /* find and call the function that can create this type of control */
1465 control_type
= MSI_RecordGetString( rec
, 3 );
1466 for( i
=0; i
<NUM_CONTROL_TYPES
; i
++ )
1467 if (!strcmpiW( msi_dialog_handler
[i
].control_type
, control_type
))
1469 if( i
!= NUM_CONTROL_TYPES
)
1470 msi_dialog_handler
[i
].func( dialog
, rec
);
1472 ERR("no handler for element type %s\n", debugstr_w(control_type
));
1474 return ERROR_SUCCESS
;
1477 static UINT
msi_dialog_fill_controls( msi_dialog
*dialog
)
1479 static const WCHAR query
[] = {
1480 'S','E','L','E','C','T',' ','*',' ',
1481 'F','R','O','M',' ','C','o','n','t','r','o','l',' ',
1482 'W','H','E','R','E',' ',
1483 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',0};
1485 MSIQUERY
*view
= NULL
;
1486 MSIPACKAGE
*package
= dialog
->package
;
1488 TRACE("%p %s\n", dialog
, debugstr_w(dialog
->name
) );
1490 /* query the Control table for all the elements of the control */
1491 r
= MSI_OpenQuery( package
->db
, &view
, query
, dialog
->name
);
1492 if( r
!= ERROR_SUCCESS
)
1494 ERR("query failed for dialog %s\n", debugstr_w(dialog
->name
));
1495 return ERROR_INVALID_PARAMETER
;
1498 r
= MSI_IterateRecords( view
, 0, msi_dialog_create_controls
, dialog
);
1499 msiobj_release( &view
->hdr
);
1504 static UINT
msi_dialog_set_control_condition( MSIRECORD
*rec
, LPVOID param
)
1506 static const WCHAR szHide
[] = { 'H','i','d','e',0 };
1507 static const WCHAR szShow
[] = { 'S','h','o','w',0 };
1508 static const WCHAR szDisable
[] = { 'D','i','s','a','b','l','e',0 };
1509 static const WCHAR szEnable
[] = { 'E','n','a','b','l','e',0 };
1510 msi_dialog
*dialog
= param
;
1511 msi_control
*control
;
1512 LPCWSTR name
, action
, condition
;
1515 name
= MSI_RecordGetString( rec
, 2 );
1516 action
= MSI_RecordGetString( rec
, 3 );
1517 condition
= MSI_RecordGetString( rec
, 4 );
1518 r
= MSI_EvaluateConditionW( dialog
->package
, condition
);
1519 control
= msi_dialog_find_control( dialog
, name
);
1520 if( r
== MSICONDITION_TRUE
&& control
)
1522 TRACE("%s control %s\n", debugstr_w(action
), debugstr_w(name
));
1524 /* FIXME: case sensitive? */
1525 if(!lstrcmpW(action
, szHide
))
1526 ShowWindow(control
->hwnd
, SW_HIDE
);
1527 else if(!strcmpW(action
, szShow
))
1528 ShowWindow(control
->hwnd
, SW_SHOW
);
1529 else if(!strcmpW(action
, szDisable
))
1530 EnableWindow(control
->hwnd
, FALSE
);
1531 else if(!strcmpW(action
, szEnable
))
1532 EnableWindow(control
->hwnd
, TRUE
);
1534 FIXME("Unhandled action %s\n", debugstr_w(action
));
1537 return ERROR_SUCCESS
;
1540 static UINT
msi_dialog_evaluate_control_conditions( msi_dialog
*dialog
)
1542 static const WCHAR query
[] = {
1543 'S','E','L','E','C','T',' ','*',' ',
1544 'F','R','O','M',' ',
1545 'C','o','n','t','r','o','l','C','o','n','d','i','t','i','o','n',' ',
1546 'W','H','E','R','E',' ',
1547 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',0
1550 MSIQUERY
*view
= NULL
;
1551 MSIPACKAGE
*package
= dialog
->package
;
1553 TRACE("%p %s\n", dialog
, debugstr_w(dialog
->name
) );
1555 /* query the Control table for all the elements of the control */
1556 r
= MSI_OpenQuery( package
->db
, &view
, query
, dialog
->name
);
1557 if( r
!= ERROR_SUCCESS
)
1559 ERR("query failed for dialog %s\n", debugstr_w(dialog
->name
));
1560 return ERROR_INVALID_PARAMETER
;
1563 r
= MSI_IterateRecords( view
, 0, msi_dialog_set_control_condition
, dialog
);
1564 msiobj_release( &view
->hdr
);
1569 UINT
msi_dialog_reset( msi_dialog
*dialog
)
1571 /* FIXME: should restore the original values of any properties we changed */
1572 return msi_dialog_evaluate_control_conditions( dialog
);
1575 /* figure out the height of 10 point MS Sans Serif */
1576 static INT
msi_dialog_get_sans_serif_height( HWND hwnd
)
1578 static const WCHAR szSansSerif
[] = {
1579 'M','S',' ','S','a','n','s',' ','S','e','r','i','f',0 };
1584 HFONT hFont
, hOldFont
;
1587 hdc
= GetDC( hwnd
);
1590 memset( &lf
, 0, sizeof lf
);
1591 lf
.lfHeight
= MulDiv(10, GetDeviceCaps(hdc
, LOGPIXELSY
), 72);
1592 strcpyW( lf
.lfFaceName
, szSansSerif
);
1593 hFont
= CreateFontIndirectW(&lf
);
1596 hOldFont
= SelectObject( hdc
, hFont
);
1597 r
= GetTextMetricsW( hdc
, &tm
);
1599 height
= tm
.tmHeight
;
1600 SelectObject( hdc
, hOldFont
);
1601 DeleteObject( hFont
);
1603 ReleaseDC( hwnd
, hdc
);
1608 /* fetch the associated record from the Dialog table */
1609 static MSIRECORD
*msi_get_dialog_record( msi_dialog
*dialog
)
1611 static const WCHAR query
[] = {
1612 'S','E','L','E','C','T',' ','*',' ',
1613 'F','R','O','M',' ','D','i','a','l','o','g',' ',
1614 'W','H','E','R','E',' ',
1615 '`','D','i','a','l','o','g','`',' ','=',' ','\'','%','s','\'',0};
1616 MSIPACKAGE
*package
= dialog
->package
;
1617 MSIRECORD
*rec
= NULL
;
1619 TRACE("%p %s\n", dialog
, debugstr_w(dialog
->name
) );
1621 rec
= MSI_QueryGetRecord( package
->db
, query
, dialog
->name
);
1623 ERR("query failed for dialog %s\n", debugstr_w(dialog
->name
));
1628 static void msi_dialog_adjust_dialog_size( msi_dialog
*dialog
, LPSIZE sz
)
1633 /* turn the client size into the window rectangle */
1636 rect
.right
= msi_dialog_scale_unit( dialog
, sz
->cx
);
1637 rect
.bottom
= msi_dialog_scale_unit( dialog
, sz
->cy
);
1638 style
= GetWindowLongPtrW( dialog
->hwnd
, GWL_STYLE
);
1639 AdjustWindowRect( &rect
, style
, FALSE
);
1640 sz
->cx
= rect
.right
- rect
.left
;
1641 sz
->cy
= rect
.bottom
- rect
.top
;
1644 static BOOL
msi_control_set_next( msi_control
*control
, msi_control
*next
)
1646 return SetWindowPos( next
->hwnd
, control
->hwnd
, 0, 0, 0, 0,
1647 SWP_NOMOVE
| SWP_NOOWNERZORDER
| SWP_NOREDRAW
|
1648 SWP_NOREPOSITION
| SWP_NOSENDCHANGING
| SWP_NOSIZE
);
1651 static UINT
msi_dialog_set_tab_order( msi_dialog
*dialog
)
1653 msi_control
*control
, *tab_next
;
1655 LIST_FOR_EACH_ENTRY( control
, &dialog
->controls
, msi_control
, entry
)
1657 tab_next
= msi_dialog_find_control( dialog
, control
->tabnext
);
1660 msi_control_set_next( control
, tab_next
);
1663 return ERROR_SUCCESS
;
1666 static void msi_dialog_set_first_control( msi_dialog
* dialog
, LPCWSTR name
)
1668 msi_control
*control
;
1670 control
= msi_dialog_find_control( dialog
, name
);
1672 dialog
->hWndFocus
= control
->hwnd
;
1674 dialog
->hWndFocus
= NULL
;
1677 static LRESULT
msi_dialog_oncreate( HWND hwnd
, LPCREATESTRUCTW cs
)
1679 static const WCHAR df
[] = {
1680 'D','e','f','a','u','l','t','U','I','F','o','n','t',0 };
1681 static const WCHAR dfv
[] = {
1682 'M','S',' ','S','h','e','l','l',' ','D','l','g',0 };
1683 msi_dialog
*dialog
= (msi_dialog
*) cs
->lpCreateParams
;
1684 MSIRECORD
*rec
= NULL
;
1685 LPWSTR title
= NULL
;
1688 TRACE("%p %p\n", dialog
, dialog
->package
);
1690 dialog
->hwnd
= hwnd
;
1691 SetWindowLongPtrW( hwnd
, GWLP_USERDATA
, (LONG_PTR
) dialog
);
1693 rec
= msi_get_dialog_record( dialog
);
1696 TRACE("No record found for dialog %s\n", debugstr_w(dialog
->name
));
1700 dialog
->scale
= msi_dialog_get_sans_serif_height(dialog
->hwnd
);
1702 size
.cx
= MSI_RecordGetInteger( rec
, 4 );
1703 size
.cy
= MSI_RecordGetInteger( rec
, 5 );
1704 msi_dialog_adjust_dialog_size( dialog
, &size
);
1706 dialog
->attributes
= MSI_RecordGetInteger( rec
, 6 );
1708 dialog
->default_font
= msi_dup_property( dialog
->package
, df
);
1709 if (!dialog
->default_font
)
1711 dialog
->default_font
= strdupW(dfv
);
1712 if (!dialog
->default_font
) return -1;
1715 title
= msi_get_deformatted_field( dialog
->package
, rec
, 7 );
1716 SetWindowTextW( hwnd
, title
);
1719 SetWindowPos( hwnd
, 0, 0, 0, size
.cx
, size
.cy
,
1720 SWP_NOMOVE
| SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_NOREDRAW
);
1723 msi_dialog_build_font_list( dialog
);
1724 msi_dialog_fill_controls( dialog
);
1725 msi_dialog_evaluate_control_conditions( dialog
);
1726 msi_dialog_set_tab_order( dialog
);
1727 msi_dialog_set_first_control( dialog
, MSI_RecordGetString( rec
, 8 ) );
1728 msiobj_release( &rec
->hdr
);
1733 static UINT
msi_dialog_send_event( msi_dialog
*dialog
, LPCWSTR event
, LPCWSTR arg
)
1735 LPWSTR event_fmt
= NULL
, arg_fmt
= NULL
;
1737 TRACE("Sending control event %s %s\n", debugstr_w(event
), debugstr_w(arg
));
1739 deformat_string( dialog
->package
, event
, &event_fmt
);
1740 deformat_string( dialog
->package
, arg
, &arg_fmt
);
1742 dialog
->event_handler( dialog
->package
, event_fmt
, arg_fmt
, dialog
);
1744 msi_free( event_fmt
);
1745 msi_free( arg_fmt
);
1747 return ERROR_SUCCESS
;
1750 static UINT
msi_dialog_set_property( msi_dialog
*dialog
, LPCWSTR event
, LPCWSTR arg
)
1752 static const WCHAR szNullArg
[] = { '{','}',0 };
1753 LPWSTR p
, prop
, arg_fmt
= NULL
;
1756 len
= strlenW(event
);
1757 prop
= msi_alloc( len
*sizeof(WCHAR
));
1758 strcpyW( prop
, &event
[1] );
1759 p
= strchrW( prop
, ']' );
1760 if( p
&& p
[1] == 0 )
1763 if( strcmpW( szNullArg
, arg
) )
1764 deformat_string( dialog
->package
, arg
, &arg_fmt
);
1765 MSI_SetPropertyW( dialog
->package
, prop
, arg_fmt
);
1766 msi_free( arg_fmt
);
1769 ERR("Badly formatted property string - what happens?\n");
1771 return ERROR_SUCCESS
;
1774 static UINT
msi_dialog_control_event( MSIRECORD
*rec
, LPVOID param
)
1776 msi_dialog
*dialog
= param
;
1777 LPCWSTR condition
, event
, arg
;
1780 condition
= MSI_RecordGetString( rec
, 5 );
1781 r
= MSI_EvaluateConditionW( dialog
->package
, condition
);
1782 if( r
== MSICONDITION_TRUE
)
1784 event
= MSI_RecordGetString( rec
, 3 );
1785 arg
= MSI_RecordGetString( rec
, 4 );
1786 if( event
[0] == '[' )
1787 msi_dialog_set_property( dialog
, event
, arg
);
1789 msi_dialog_send_event( dialog
, event
, arg
);
1792 return ERROR_SUCCESS
;
1795 static UINT
msi_dialog_button_handler( msi_dialog
*dialog
,
1796 msi_control
*control
, WPARAM param
)
1798 static const WCHAR query
[] = {
1799 'S','E','L','E','C','T',' ','*',' ',
1800 'F','R','O','M',' ','C','o','n','t','r','o','l','E','v','e','n','t',' ',
1801 'W','H','E','R','E',' ',
1802 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',' ',
1804 '`','C','o','n','t','r','o','l','_','`',' ','=',' ','\'','%','s','\'',' ',
1805 'O','R','D','E','R',' ','B','Y',' ','`','O','r','d','e','r','i','n','g','`',0
1807 MSIQUERY
*view
= NULL
;
1810 if( HIWORD(param
) != BN_CLICKED
)
1811 return ERROR_SUCCESS
;
1813 r
= MSI_OpenQuery( dialog
->package
->db
, &view
, query
,
1814 dialog
->name
, control
->name
);
1815 if( r
!= ERROR_SUCCESS
)
1817 ERR("query failed\n");
1821 r
= MSI_IterateRecords( view
, 0, msi_dialog_control_event
, dialog
);
1822 msiobj_release( &view
->hdr
);
1827 static UINT
msi_dialog_get_checkbox_state( msi_dialog
*dialog
,
1828 msi_control
*control
)
1830 WCHAR state
[2] = { 0 };
1833 MSI_GetPropertyW( dialog
->package
, control
->property
, state
, &sz
);
1834 return state
[0] ? 1 : 0;
1837 static void msi_dialog_set_checkbox_state( msi_dialog
*dialog
,
1838 msi_control
*control
, UINT state
)
1840 static const WCHAR szState
[] = { '1', 0 };
1843 /* if uncheck then the property is set to NULL */
1846 MSI_SetPropertyW( dialog
->package
, control
->property
, NULL
);
1850 /* check for a custom state */
1851 if (control
->value
&& control
->value
[0])
1852 val
= control
->value
;
1856 MSI_SetPropertyW( dialog
->package
, control
->property
, val
);
1859 static void msi_dialog_checkbox_sync_state( msi_dialog
*dialog
,
1860 msi_control
*control
)
1864 state
= msi_dialog_get_checkbox_state( dialog
, control
);
1865 SendMessageW( control
->hwnd
, BM_SETCHECK
,
1866 state
? BST_CHECKED
: BST_UNCHECKED
, 0 );
1869 static UINT
msi_dialog_checkbox_handler( msi_dialog
*dialog
,
1870 msi_control
*control
, WPARAM param
)
1874 if( HIWORD(param
) != BN_CLICKED
)
1875 return ERROR_SUCCESS
;
1877 TRACE("clicked checkbox %s, set %s\n", debugstr_w(control
->name
),
1878 debugstr_w(control
->property
));
1880 state
= msi_dialog_get_checkbox_state( dialog
, control
);
1881 state
= state
? 0 : 1;
1882 msi_dialog_set_checkbox_state( dialog
, control
, state
);
1883 msi_dialog_checkbox_sync_state( dialog
, control
);
1885 return msi_dialog_button_handler( dialog
, control
, param
);
1888 static UINT
msi_dialog_edit_handler( msi_dialog
*dialog
,
1889 msi_control
*control
, WPARAM param
)
1894 if( HIWORD(param
) != EN_CHANGE
)
1895 return ERROR_SUCCESS
;
1897 TRACE("edit %s contents changed, set %s\n", debugstr_w(control
->name
),
1898 debugstr_w(control
->property
));
1901 buf
= msi_alloc( sz
*sizeof(WCHAR
) );
1904 r
= GetWindowTextW( control
->hwnd
, buf
, sz
);
1908 buf
= msi_realloc( buf
, sz
*sizeof(WCHAR
) );
1911 MSI_SetPropertyW( dialog
->package
, control
->property
, buf
);
1915 return ERROR_SUCCESS
;
1918 static UINT
msi_dialog_radiogroup_handler( msi_dialog
*dialog
,
1919 msi_control
*control
, WPARAM param
)
1921 if( HIWORD(param
) != BN_CLICKED
)
1922 return ERROR_SUCCESS
;
1924 TRACE("clicked radio button %s, set %s\n", debugstr_w(control
->name
),
1925 debugstr_w(control
->property
));
1927 MSI_SetPropertyW( dialog
->package
, control
->property
, control
->name
);
1929 return msi_dialog_button_handler( dialog
, control
, param
);
1932 static LRESULT
msi_dialog_oncommand( msi_dialog
*dialog
, WPARAM param
, HWND hwnd
)
1934 msi_control
*control
= NULL
;
1936 TRACE("%p %p %08x\n", dialog
, hwnd
, param
);
1941 control
= msi_dialog_find_control( dialog
, dialog
->control_default
);
1943 case 2: /* escape */
1944 control
= msi_dialog_find_control( dialog
, dialog
->control_cancel
);
1947 control
= msi_dialog_find_control_by_hwnd( dialog
, hwnd
);
1952 if( control
->handler
)
1954 control
->handler( dialog
, control
, param
);
1955 msi_dialog_evaluate_control_conditions( dialog
);
1959 ERR("button click from nowhere %p %d %p\n", dialog
, param
, hwnd
);
1963 static void msi_dialog_setfocus( msi_dialog
*dialog
)
1965 HWND hwnd
= dialog
->hWndFocus
;
1967 hwnd
= GetNextDlgTabItem( dialog
->hwnd
, hwnd
, TRUE
);
1968 hwnd
= GetNextDlgTabItem( dialog
->hwnd
, hwnd
, FALSE
);
1970 dialog
->hWndFocus
= hwnd
;
1973 static LRESULT WINAPI
MSIDialog_WndProc( HWND hwnd
, UINT msg
,
1974 WPARAM wParam
, LPARAM lParam
)
1976 msi_dialog
*dialog
= (LPVOID
) GetWindowLongPtrW( hwnd
, GWLP_USERDATA
);
1978 TRACE("0x%04x\n", msg
);
1983 return msi_dialog_oncreate( hwnd
, (LPCREATESTRUCTW
)lParam
);
1986 return msi_dialog_oncommand( dialog
, wParam
, (HWND
)lParam
);
1989 if( LOWORD(wParam
) == WA_INACTIVE
)
1990 dialog
->hWndFocus
= GetFocus();
1992 msi_dialog_setfocus( dialog
);
1996 msi_dialog_setfocus( dialog
);
1999 /* bounce back to our subclassed static control */
2000 case WM_CTLCOLORSTATIC
:
2001 return SendMessageW( (HWND
) lParam
, WM_CTLCOLORSTATIC
, wParam
, lParam
);
2004 dialog
->hwnd
= NULL
;
2007 return DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
2010 static LRESULT WINAPI
MSIRadioGroup_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
2012 WNDPROC oldproc
= (WNDPROC
) GetPropW(hWnd
, szButtonData
);
2014 TRACE("hWnd %p msg %04x wParam 0x%08x lParam 0x%08lx\n", hWnd
, msg
, wParam
, lParam
);
2016 if (msg
== WM_COMMAND
) /* Forward notifications to dialog */
2017 SendMessageW(GetParent(hWnd
), msg
, wParam
, lParam
);
2019 return CallWindowProcW(oldproc
, hWnd
, msg
, wParam
, lParam
);
2022 static LRESULT WINAPI
MSIHiddenWindowProc( HWND hwnd
, UINT msg
,
2023 WPARAM wParam
, LPARAM lParam
)
2025 msi_dialog
*dialog
= (msi_dialog
*) lParam
;
2027 TRACE("%d %p\n", msg
, dialog
);
2031 case WM_MSI_DIALOG_CREATE
:
2032 return msi_dialog_run_message_loop( dialog
);
2033 case WM_MSI_DIALOG_DESTROY
:
2034 msi_dialog_destroy( dialog
);
2037 return DefWindowProcW( hwnd
, msg
, wParam
, lParam
);
2040 /* functions that interface to other modules within MSI */
2042 msi_dialog
*msi_dialog_create( MSIPACKAGE
* package
, LPCWSTR szDialogName
,
2043 msi_dialog_event_handler event_handler
)
2045 MSIRECORD
*rec
= NULL
;
2048 TRACE("%p %s\n", package
, debugstr_w(szDialogName
));
2050 /* allocate the structure for the dialog to use */
2051 dialog
= msi_alloc_zero( sizeof *dialog
+ sizeof(WCHAR
)*strlenW(szDialogName
) );
2054 strcpyW( dialog
->name
, szDialogName
);
2055 msiobj_addref( &package
->hdr
);
2056 dialog
->package
= package
;
2057 dialog
->event_handler
= event_handler
;
2058 dialog
->finished
= 0;
2059 list_init( &dialog
->controls
);
2061 /* verify that the dialog exists */
2062 rec
= msi_get_dialog_record( dialog
);
2065 msiobj_release( &package
->hdr
);
2069 dialog
->attributes
= MSI_RecordGetInteger( rec
, 6 );
2070 dialog
->control_default
= strdupW( MSI_RecordGetString( rec
, 9 ) );
2071 dialog
->control_cancel
= strdupW( MSI_RecordGetString( rec
, 10 ) );
2072 msiobj_release( &rec
->hdr
);
2077 static void msi_process_pending_messages( HWND hdlg
)
2081 while( PeekMessageW( &msg
, 0, 0, 0, PM_REMOVE
) )
2083 if( hdlg
&& IsDialogMessageW( hdlg
, &msg
))
2085 TranslateMessage( &msg
);
2086 DispatchMessageW( &msg
);
2090 void msi_dialog_end_dialog( msi_dialog
*dialog
)
2092 TRACE("%p\n", dialog
);
2093 dialog
->finished
= 1;
2094 PostMessageW(dialog
->hwnd
, WM_NULL
, 0, 0);
2097 void msi_dialog_check_messages( HANDLE handle
)
2101 /* in threads other than the UI thread, block */
2102 if( uiThreadId
!= GetCurrentThreadId() )
2105 WaitForSingleObject( handle
, INFINITE
);
2109 /* there's two choices for the UI thread */
2112 msi_process_pending_messages( NULL
);
2118 * block here until somebody creates a new dialog or
2119 * the handle we're waiting on becomes ready
2121 r
= MsgWaitForMultipleObjects( 1, &handle
, 0, INFINITE
, QS_ALLINPUT
);
2122 if( r
== WAIT_OBJECT_0
)
2127 UINT
msi_dialog_run_message_loop( msi_dialog
*dialog
)
2131 if( !(dialog
->attributes
& msidbDialogAttributesVisible
) )
2132 return ERROR_SUCCESS
;
2134 if( uiThreadId
!= GetCurrentThreadId() )
2135 return SendMessageW( hMsiHiddenWindow
, WM_MSI_DIALOG_CREATE
, 0, (LPARAM
) dialog
);
2137 /* create the dialog window, don't show it yet */
2138 hwnd
= CreateWindowW( szMsiDialogClass
, dialog
->name
, WS_OVERLAPPEDWINDOW
,
2139 CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
,
2140 NULL
, NULL
, NULL
, dialog
);
2143 ERR("Failed to create dialog %s\n", debugstr_w( dialog
->name
));
2144 return ERROR_FUNCTION_FAILED
;
2147 ShowWindow( hwnd
, SW_SHOW
);
2148 /* UpdateWindow( hwnd ); - and causes the transparent static controls not to paint */
2150 if( dialog
->attributes
& msidbDialogAttributesModal
)
2152 while( !dialog
->finished
)
2154 MsgWaitForMultipleObjects( 0, NULL
, 0, INFINITE
, QS_ALLEVENTS
);
2155 msi_process_pending_messages( dialog
->hwnd
);
2159 return ERROR_IO_PENDING
;
2161 return ERROR_SUCCESS
;
2164 void msi_dialog_do_preview( msi_dialog
*dialog
)
2167 dialog
->attributes
|= msidbDialogAttributesVisible
;
2168 dialog
->attributes
&= ~msidbDialogAttributesModal
;
2169 msi_dialog_run_message_loop( dialog
);
2172 void msi_dialog_destroy( msi_dialog
*dialog
)
2174 if( uiThreadId
!= GetCurrentThreadId() )
2176 SendMessageW( hMsiHiddenWindow
, WM_MSI_DIALOG_DESTROY
, 0, (LPARAM
) dialog
);
2181 ShowWindow( dialog
->hwnd
, SW_HIDE
);
2184 DestroyWindow( dialog
->hwnd
);
2186 /* destroy the list of controls */
2187 while( !list_empty( &dialog
->controls
) )
2189 msi_control
*t
= LIST_ENTRY( list_head( &dialog
->controls
),
2190 msi_control
, entry
);
2191 list_remove( &t
->entry
);
2192 /* leave dialog->hwnd - destroying parent destroys child windows */
2193 msi_free( t
->property
);
2194 msi_free( t
->value
);
2196 DeleteObject( t
->hBitmap
);
2198 DestroyIcon( t
->hIcon
);
2199 msi_free( t
->tabnext
);
2203 /* destroy the list of fonts */
2204 while( dialog
->font_list
)
2206 msi_font
*t
= dialog
->font_list
;
2207 dialog
->font_list
= t
->next
;
2208 DeleteObject( t
->hfont
);
2211 msi_free( dialog
->default_font
);
2213 msi_free( dialog
->control_default
);
2214 msi_free( dialog
->control_cancel
);
2215 msiobj_release( &dialog
->package
->hdr
);
2216 dialog
->package
= NULL
;
2220 BOOL
msi_dialog_register_class( void )
2224 ZeroMemory( &cls
, sizeof cls
);
2225 cls
.lpfnWndProc
= MSIDialog_WndProc
;
2226 cls
.hInstance
= NULL
;
2227 cls
.hIcon
= LoadIconW(0, (LPWSTR
)IDI_APPLICATION
);
2228 cls
.hCursor
= LoadCursorW(0, (LPWSTR
)IDC_ARROW
);
2229 cls
.hbrBackground
= (HBRUSH
)(COLOR_3DFACE
+ 1);
2230 cls
.lpszMenuName
= NULL
;
2231 cls
.lpszClassName
= szMsiDialogClass
;
2233 if( !RegisterClassW( &cls
) )
2236 cls
.lpfnWndProc
= MSIHiddenWindowProc
;
2237 cls
.lpszClassName
= szMsiHiddenWindow
;
2239 if( !RegisterClassW( &cls
) )
2242 uiThreadId
= GetCurrentThreadId();
2244 hMsiHiddenWindow
= CreateWindowW( szMsiHiddenWindow
, NULL
, WS_OVERLAPPED
,
2245 0, 0, 100, 100, NULL
, NULL
, NULL
, NULL
);
2246 if( !hMsiHiddenWindow
)
2252 void msi_dialog_unregister_class( void )
2254 DestroyWindow( hMsiHiddenWindow
);
2255 hMsiHiddenWindow
= NULL
;
2256 UnregisterClassW( szMsiDialogClass
, NULL
);
2257 UnregisterClassW( szMsiHiddenWindow
, NULL
);