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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #define NONAMELESSUNION
23 #define NONAMELESSSTRUCT
42 #include "wine/debug.h"
43 #include "wine/unicode.h"
45 WINE_DEFAULT_DEBUG_CHANNEL(msi
);
48 extern HINSTANCE msi_hInstance
;
50 struct msi_control_tag
;
51 typedef struct msi_control_tag msi_control
;
52 typedef UINT (*msi_handler
)( msi_dialog
*, msi_control
*, WPARAM
);
53 typedef void (*msi_update
)( msi_dialog
*, msi_control
* );
55 struct msi_control_tag
68 float progress_current
;
74 typedef struct msi_font_tag
76 struct msi_font_tag
*next
;
86 msi_dialog_event_handler event_handler
;
96 LPWSTR control_default
;
97 LPWSTR control_cancel
;
101 typedef UINT (*msi_dialog_control_func
)( msi_dialog
*dialog
, MSIRECORD
*rec
);
102 struct control_handler
104 LPCWSTR control_type
;
105 msi_dialog_control_func func
;
114 } radio_button_group_descr
;
116 static const WCHAR szMsiDialogClass
[] = {
117 'M','s','i','D','i','a','l','o','g','C','l','o','s','e','C','l','a','s','s',0
119 static const WCHAR szMsiHiddenWindow
[] = {
120 'M','s','i','H','i','d','d','e','n','W','i','n','d','o','w',0 };
121 static const WCHAR szStatic
[] = { 'S','t','a','t','i','c',0 };
122 static const WCHAR szButton
[] = { 'B','U','T','T','O','N', 0 };
123 static const WCHAR szButtonData
[] = { 'M','S','I','D','A','T','A',0 };
124 static const WCHAR szProgress
[] = { 'P','r','o','g','r','e','s','s',0 };
125 static const WCHAR szText
[] = { 'T','e','x','t',0 };
126 static const WCHAR szPushButton
[] = { 'P','u','s','h','B','u','t','t','o','n',0 };
127 static const WCHAR szLine
[] = { 'L','i','n','e',0 };
128 static const WCHAR szBitmap
[] = { 'B','i','t','m','a','p',0 };
129 static const WCHAR szCheckBox
[] = { 'C','h','e','c','k','B','o','x',0 };
130 static const WCHAR szScrollableText
[] = {
131 'S','c','r','o','l','l','a','b','l','e','T','e','x','t',0 };
132 static const WCHAR szComboBox
[] = { 'C','o','m','b','o','B','o','x',0 };
133 static const WCHAR szEdit
[] = { 'E','d','i','t',0 };
134 static const WCHAR szMaskedEdit
[] = { 'M','a','s','k','e','d','E','d','i','t',0 };
135 static const WCHAR szPathEdit
[] = { 'P','a','t','h','E','d','i','t',0 };
136 static const WCHAR szProgressBar
[] = {
137 'P','r','o','g','r','e','s','s','B','a','r',0 };
138 static const WCHAR szSetProgress
[] = {
139 'S','e','t','P','r','o','g','r','e','s','s',0 };
140 static const WCHAR szRadioButtonGroup
[] = {
141 'R','a','d','i','o','B','u','t','t','o','n','G','r','o','u','p',0 };
142 static const WCHAR szIcon
[] = { 'I','c','o','n',0 };
143 static const WCHAR szSelectionTree
[] = {
144 'S','e','l','e','c','t','i','o','n','T','r','e','e',0 };
145 static const WCHAR szGroupBox
[] = { 'G','r','o','u','p','B','o','x',0 };
146 static const WCHAR szListBox
[] = { 'L','i','s','t','B','o','x',0 };
147 static const WCHAR szDirectoryCombo
[] = { 'D','i','r','e','c','t','o','r','y','C','o','m','b','o',0 };
148 static const WCHAR szDirectoryList
[] = { 'D','i','r','e','c','t','o','r','y','L','i','s','t',0 };
149 static const WCHAR szVolumeCostList
[] = { 'V','o','l','u','m','e','C','o','s','t','L','i','s','t',0 };
150 static const WCHAR szVolumeSelectCombo
[] = { 'V','o','l','u','m','e','S','e','l','e','c','t','C','o','m','b','o',0 };
151 static const WCHAR szSelectionDescription
[] = {'S','e','l','e','c','t','i','o','n','D','e','s','c','r','i','p','t','i','o','n',0};
152 static const WCHAR szSelectionPath
[] = {'S','e','l','e','c','t','i','o','n','P','a','t','h',0};
153 static const WCHAR szProperty
[] = {'P','r','o','p','e','r','t','y',0};
155 static UINT
msi_dialog_checkbox_handler( msi_dialog
*, msi_control
*, WPARAM
);
156 static void msi_dialog_checkbox_sync_state( msi_dialog
*, msi_control
* );
157 static UINT
msi_dialog_button_handler( msi_dialog
*, msi_control
*, WPARAM
);
158 static UINT
msi_dialog_edit_handler( msi_dialog
*, msi_control
*, WPARAM
);
159 static UINT
msi_dialog_radiogroup_handler( msi_dialog
*, msi_control
*, WPARAM
);
160 static UINT
msi_dialog_evaluate_control_conditions( msi_dialog
*dialog
);
161 static LRESULT WINAPI
MSIRadioGroup_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
);
162 static MSIFEATURE
*msi_seltree_get_selected_feature( msi_control
*control
);
164 /* dialog sequencing */
166 #define WM_MSI_DIALOG_CREATE (WM_USER+0x100)
167 #define WM_MSI_DIALOG_DESTROY (WM_USER+0x101)
169 #define USER_INSTALLSTATE_ALL 0x1000
171 static DWORD uiThreadId
;
172 static HWND hMsiHiddenWindow
;
174 static INT
msi_dialog_scale_unit( msi_dialog
*dialog
, INT val
)
176 return MulDiv( val
, dialog
->scale
, 12 );
179 static msi_control
*msi_dialog_find_control( msi_dialog
*dialog
, LPCWSTR name
)
181 msi_control
*control
;
187 LIST_FOR_EACH_ENTRY( control
, &dialog
->controls
, msi_control
, entry
)
188 if( !strcmpW( control
->name
, name
) ) /* FIXME: case sensitive? */
193 static msi_control
*msi_dialog_find_control_by_type( msi_dialog
*dialog
, LPCWSTR type
)
195 msi_control
*control
;
201 LIST_FOR_EACH_ENTRY( control
, &dialog
->controls
, msi_control
, entry
)
202 if( !strcmpW( control
->type
, type
) ) /* FIXME: case sensitive? */
207 static msi_control
*msi_dialog_find_control_by_hwnd( msi_dialog
*dialog
, HWND hwnd
)
209 msi_control
*control
;
213 LIST_FOR_EACH_ENTRY( control
, &dialog
->controls
, msi_control
, entry
)
214 if( hwnd
== control
->hwnd
)
219 static LPWSTR
msi_get_deformatted_field( MSIPACKAGE
*package
, MSIRECORD
*rec
, int field
)
221 LPCWSTR str
= MSI_RecordGetString( rec
, field
);
225 deformat_string( package
, str
, &ret
);
229 static LPWSTR
msi_dialog_dup_property( msi_dialog
*dialog
, LPCWSTR property
, BOOL indirect
)
237 prop
= msi_dup_property( dialog
->package
, property
);
240 prop
= strdupW( property
);
245 msi_dialog
*msi_dialog_get_parent( msi_dialog
*dialog
)
247 return dialog
->parent
;
250 LPWSTR
msi_dialog_get_name( msi_dialog
*dialog
)
256 * msi_dialog_get_style
258 * Extract the {\style} string from the front of the text to display and
259 * update the pointer. Only the last style in a list is applied.
261 static LPWSTR
msi_dialog_get_style( LPCWSTR p
, LPCWSTR
*rest
)
272 while ((first
= strchrW( p
, '{' )) && (q
= strchrW( first
+ 1, '}' )))
275 if( *p
!= '\\' && *p
!= '&' )
278 /* little bit of sanity checking to stop us getting confused with RTF */
279 for( i
=++p
; i
<q
; i
++ )
280 if( *i
== '}' || *i
== '\\' )
290 ret
= msi_alloc( len
*sizeof(WCHAR
) );
293 memcpy( ret
, p
, len
*sizeof(WCHAR
) );
298 static UINT
msi_dialog_add_font( MSIRECORD
*rec
, LPVOID param
)
300 msi_dialog
*dialog
= param
;
307 /* create a font and add it to the list */
308 name
= MSI_RecordGetString( rec
, 1 );
309 font
= msi_alloc( sizeof *font
+ strlenW( name
)*sizeof (WCHAR
) );
310 strcpyW( font
->name
, name
);
311 font
->next
= dialog
->font_list
;
312 dialog
->font_list
= font
;
314 font
->color
= MSI_RecordGetInteger( rec
, 4 );
316 memset( &lf
, 0, sizeof lf
);
317 face
= MSI_RecordGetString( rec
, 2 );
318 lf
.lfHeight
= MSI_RecordGetInteger( rec
, 3 );
319 style
= MSI_RecordGetInteger( rec
, 5 );
320 if( style
& msidbTextStyleStyleBitsBold
)
321 lf
.lfWeight
= FW_BOLD
;
322 if( style
& msidbTextStyleStyleBitsItalic
)
324 if( style
& msidbTextStyleStyleBitsUnderline
)
325 lf
.lfUnderline
= TRUE
;
326 if( style
& msidbTextStyleStyleBitsStrike
)
327 lf
.lfStrikeOut
= TRUE
;
328 lstrcpynW( lf
.lfFaceName
, face
, LF_FACESIZE
);
330 /* adjust the height */
331 hdc
= GetDC( dialog
->hwnd
);
334 lf
.lfHeight
= -MulDiv(lf
.lfHeight
, GetDeviceCaps(hdc
, LOGPIXELSY
), 72);
335 ReleaseDC( dialog
->hwnd
, hdc
);
338 font
->hfont
= CreateFontIndirectW( &lf
);
340 TRACE("Adding font style %s\n", debugstr_w(font
->name
) );
342 return ERROR_SUCCESS
;
345 static msi_font
*msi_dialog_find_font( msi_dialog
*dialog
, LPCWSTR name
)
349 for( font
= dialog
->font_list
; font
; font
= font
->next
)
350 if( !strcmpW( font
->name
, name
) ) /* FIXME: case sensitive? */
356 static UINT
msi_dialog_set_font( msi_dialog
*dialog
, HWND hwnd
, LPCWSTR name
)
360 font
= msi_dialog_find_font( dialog
, name
);
362 SendMessageW( hwnd
, WM_SETFONT
, (WPARAM
) font
->hfont
, TRUE
);
364 ERR("No font entry for %s\n", debugstr_w(name
));
365 return ERROR_SUCCESS
;
368 static UINT
msi_dialog_build_font_list( msi_dialog
*dialog
)
370 static const WCHAR query
[] = {
371 'S','E','L','E','C','T',' ','*',' ',
372 'F','R','O','M',' ','`','T','e','x','t','S','t','y','l','e','`',' ',0
375 MSIQUERY
*view
= NULL
;
377 TRACE("dialog %p\n", dialog
);
379 r
= MSI_OpenQuery( dialog
->package
->db
, &view
, query
);
380 if( r
!= ERROR_SUCCESS
)
383 r
= MSI_IterateRecords( view
, NULL
, msi_dialog_add_font
, dialog
);
384 msiobj_release( &view
->hdr
);
389 static void msi_destroy_control( msi_control
*t
)
391 list_remove( &t
->entry
);
392 /* leave dialog->hwnd - destroying parent destroys child windows */
393 msi_free( t
->property
);
394 msi_free( t
->value
);
396 DeleteObject( t
->hBitmap
);
398 DestroyIcon( t
->hIcon
);
399 msi_free( t
->tabnext
);
402 FreeLibrary( t
->hDll
);
406 static msi_control
*msi_dialog_create_window( msi_dialog
*dialog
,
407 MSIRECORD
*rec
, DWORD exstyle
, LPCWSTR szCls
, LPCWSTR name
, LPCWSTR text
,
408 DWORD style
, HWND parent
)
410 DWORD x
, y
, width
, height
;
411 LPWSTR font
= NULL
, title_font
= NULL
;
412 LPCWSTR title
= NULL
;
413 msi_control
*control
;
417 control
= msi_alloc( sizeof *control
+ strlenW(name
)*sizeof(WCHAR
) );
421 strcpyW( control
->name
, name
);
422 list_add_tail( &dialog
->controls
, &control
->entry
);
423 control
->handler
= NULL
;
424 control
->update
= NULL
;
425 control
->property
= NULL
;
426 control
->value
= NULL
;
427 control
->hBitmap
= NULL
;
428 control
->hIcon
= NULL
;
429 control
->hDll
= NULL
;
430 control
->tabnext
= strdupW( MSI_RecordGetString( rec
, 11) );
431 control
->type
= strdupW( MSI_RecordGetString( rec
, 3 ) );
432 control
->progress_current
= 0;
433 control
->progress_max
= 100;
435 x
= MSI_RecordGetInteger( rec
, 4 );
436 y
= MSI_RecordGetInteger( rec
, 5 );
437 width
= MSI_RecordGetInteger( rec
, 6 );
438 height
= MSI_RecordGetInteger( rec
, 7 );
440 x
= msi_dialog_scale_unit( dialog
, x
);
441 y
= msi_dialog_scale_unit( dialog
, y
);
442 width
= msi_dialog_scale_unit( dialog
, width
);
443 height
= msi_dialog_scale_unit( dialog
, height
);
447 deformat_string( dialog
->package
, text
, &title_font
);
448 font
= msi_dialog_get_style( title_font
, &title
);
451 control
->hwnd
= CreateWindowExW( exstyle
, szCls
, title
, style
,
452 x
, y
, width
, height
, parent
, NULL
, NULL
, NULL
);
454 TRACE("Dialog %s control %s hwnd %p\n",
455 debugstr_w(dialog
->name
), debugstr_w(text
), control
->hwnd
);
457 msi_dialog_set_font( dialog
, control
->hwnd
,
458 font
? font
: dialog
->default_font
);
460 msi_free( title_font
);
466 static LPWSTR
msi_dialog_get_uitext( msi_dialog
*dialog
, LPCWSTR key
)
471 static const WCHAR query
[] = {
472 's','e','l','e','c','t',' ','*',' ',
473 'f','r','o','m',' ','`','U','I','T','e','x','t','`',' ',
474 'w','h','e','r','e',' ','`','K','e','y','`',' ','=',' ','\'','%','s','\'',0
477 rec
= MSI_QueryGetRecord( dialog
->package
->db
, query
, key
);
478 if (!rec
) return NULL
;
479 text
= strdupW( MSI_RecordGetString( rec
, 2 ) );
480 msiobj_release( &rec
->hdr
);
484 static MSIRECORD
*msi_get_binary_record( MSIDATABASE
*db
, LPCWSTR name
)
486 static const WCHAR query
[] = {
487 's','e','l','e','c','t',' ','*',' ',
488 'f','r','o','m',' ','B','i','n','a','r','y',' ',
489 'w','h','e','r','e',' ',
490 '`','N','a','m','e','`',' ','=',' ','\'','%','s','\'',0
493 return MSI_QueryGetRecord( db
, query
, name
);
496 static LPWSTR
msi_create_tmp_path(void)
502 r
= GetTempPathW( MAX_PATH
, tmp
);
505 len
= lstrlenW( tmp
) + 20;
506 path
= msi_alloc( len
* sizeof (WCHAR
) );
509 r
= GetTempFileNameW( tmp
, szMsi
, 0, path
);
520 static HANDLE
msi_load_image( MSIDATABASE
*db
, LPCWSTR name
, UINT type
,
521 UINT cx
, UINT cy
, UINT flags
)
523 MSIRECORD
*rec
= NULL
;
524 HANDLE himage
= NULL
;
528 TRACE("%p %s %u %u %08x\n", db
, debugstr_w(name
), cx
, cy
, flags
);
530 tmp
= msi_create_tmp_path();
534 rec
= msi_get_binary_record( db
, name
);
537 r
= MSI_RecordStreamToFile( rec
, 2, tmp
);
538 if( r
== ERROR_SUCCESS
)
540 himage
= LoadImageW( 0, tmp
, type
, cx
, cy
, flags
);
542 msiobj_release( &rec
->hdr
);
550 static HICON
msi_load_icon( MSIDATABASE
*db
, LPCWSTR text
, UINT attributes
)
552 DWORD cx
= 0, cy
= 0, flags
;
554 flags
= LR_LOADFROMFILE
| LR_DEFAULTSIZE
;
555 if( attributes
& msidbControlAttributesFixedSize
)
557 flags
&= ~LR_DEFAULTSIZE
;
558 if( attributes
& msidbControlAttributesIconSize16
)
563 if( attributes
& msidbControlAttributesIconSize32
)
568 /* msidbControlAttributesIconSize48 handled by above logic */
570 return msi_load_image( db
, text
, IMAGE_ICON
, cx
, cy
, flags
);
573 static void msi_dialog_update_controls( msi_dialog
*dialog
, LPCWSTR property
)
575 msi_control
*control
;
577 LIST_FOR_EACH_ENTRY( control
, &dialog
->controls
, msi_control
, entry
)
579 if ( !lstrcmpW( control
->property
, property
) && control
->update
)
580 control
->update( dialog
, control
);
584 /* called from the Control Event subscription code */
585 void msi_dialog_handle_event( msi_dialog
* dialog
, LPCWSTR control
,
586 LPCWSTR attribute
, MSIRECORD
*rec
)
589 LPCWSTR font_text
, text
= NULL
;
592 ctrl
= msi_dialog_find_control( dialog
, control
);
595 if( !lstrcmpW(attribute
, szText
) )
597 font_text
= MSI_RecordGetString( rec
, 1 );
598 font
= msi_dialog_get_style( font_text
, &text
);
599 if (!text
) text
= szEmpty
;
600 SetWindowTextW( ctrl
->hwnd
, text
);
602 msi_dialog_check_messages( NULL
);
604 else if( !lstrcmpW(attribute
, szProgress
) )
608 func
= MSI_RecordGetInteger( rec
, 1 );
609 val
= MSI_RecordGetInteger( rec
, 2 );
611 TRACE("progress: func %u, val %u\n", func
, val
);
616 ctrl
->progress_max
= val
;
617 ctrl
->progress_current
= 0;
618 SendMessageW(ctrl
->hwnd
, PBM_SETRANGE
, 0, MAKELPARAM(0,100));
619 SendMessageW(ctrl
->hwnd
, PBM_SETPOS
, 0, 0);
621 case 1: /* FIXME: not sure what this is supposed to do */
624 ctrl
->progress_current
+= val
;
625 if (ctrl
->progress_current
> ctrl
->progress_max
)
626 ctrl
->progress_current
= ctrl
->progress_max
;
627 SendMessageW(ctrl
->hwnd
, PBM_SETPOS
, MulDiv(100, ctrl
->progress_current
, ctrl
->progress_max
), 0);
630 FIXME("Unknown progress message %u\n", func
);
634 else if ( !lstrcmpW(attribute
, szProperty
) )
636 MSIFEATURE
*feature
= msi_seltree_get_selected_feature( ctrl
);
637 MSI_SetPropertyW( dialog
->package
, ctrl
->property
, feature
->Directory
);
639 else if ( !lstrcmpW(attribute
, szSelectionPath
) )
641 LPWSTR prop
= msi_dialog_dup_property( dialog
, ctrl
->property
, TRUE
);
644 path
= msi_dup_property( dialog
->package
, prop
);
645 SetWindowTextW( ctrl
->hwnd
, path
);
651 FIXME("Attribute %s not being set\n", debugstr_w(attribute
));
656 static void msi_dialog_map_events(msi_dialog
* dialog
, LPCWSTR control
)
658 static const WCHAR Query
[] = {
659 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
660 '`','E','v','e','n','t','M','a','p','p','i','n','g','`',' ',
661 'W','H','E','R','E',' ',
662 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',' ',
664 '`','C','o','n','t','r','o','l','_','`',' ','=',' ','\'','%','s','\'',0
667 LPCWSTR event
, attribute
;
669 row
= MSI_QueryGetRecord( dialog
->package
->db
, Query
, dialog
->name
, control
);
673 event
= MSI_RecordGetString( row
, 3 );
674 attribute
= MSI_RecordGetString( row
, 4 );
675 ControlEvent_SubscribeToEvent( dialog
->package
, dialog
, event
, control
, attribute
);
676 msiobj_release( &row
->hdr
);
679 /* everything except radio buttons */
680 static msi_control
*msi_dialog_add_control( msi_dialog
*dialog
,
681 MSIRECORD
*rec
, LPCWSTR szCls
, DWORD style
)
687 name
= MSI_RecordGetString( rec
, 2 );
688 attributes
= MSI_RecordGetInteger( rec
, 8 );
689 text
= MSI_RecordGetString( rec
, 10 );
691 TRACE("%s, %s, %08x, %s, %08x\n", debugstr_w(szCls
), debugstr_w(name
),
692 attributes
, debugstr_w(text
), style
);
694 if( attributes
& msidbControlAttributesVisible
)
696 if( ~attributes
& msidbControlAttributesEnabled
)
697 style
|= WS_DISABLED
;
698 if( attributes
& msidbControlAttributesSunken
)
699 exstyle
|= WS_EX_CLIENTEDGE
;
701 msi_dialog_map_events(dialog
, name
);
703 return msi_dialog_create_window( dialog
, rec
, exstyle
, szCls
, name
,
704 text
, style
, dialog
->hwnd
);
715 * we don't erase our own background,
716 * so we have to make sure that the parent window redraws first
718 static void msi_text_on_settext( HWND hWnd
)
723 hParent
= GetParent( hWnd
);
724 GetWindowRect( hWnd
, &rc
);
725 MapWindowPoints( NULL
, hParent
, (LPPOINT
) &rc
, 2 );
726 InvalidateRect( hParent
, &rc
, TRUE
);
729 static LRESULT WINAPI
730 MSIText_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
732 struct msi_text_info
*info
;
735 TRACE("%p %04x %08lx %08lx\n", hWnd
, msg
, wParam
, lParam
);
737 info
= GetPropW(hWnd
, szButtonData
);
739 if( msg
== WM_CTLCOLORSTATIC
&&
740 ( info
->attributes
& msidbControlAttributesTransparent
) )
742 SetBkMode( (HDC
)wParam
, TRANSPARENT
);
743 return (LRESULT
) GetStockObject(NULL_BRUSH
);
746 r
= CallWindowProcW(info
->oldproc
, hWnd
, msg
, wParam
, lParam
);
748 SetTextColor( (HDC
)wParam
, info
->font
->color
);
753 msi_text_on_settext( hWnd
);
757 RemovePropW( hWnd
, szButtonData
);
764 static UINT
msi_dialog_text_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
766 msi_control
*control
;
767 struct msi_text_info
*info
;
768 LPCWSTR text
, ptr
, prop
;
771 TRACE("%p %p\n", dialog
, rec
);
773 control
= msi_dialog_add_control( dialog
, rec
, szStatic
, SS_LEFT
| WS_GROUP
);
775 return ERROR_FUNCTION_FAILED
;
777 info
= msi_alloc( sizeof *info
);
779 return ERROR_SUCCESS
;
781 control
->attributes
= MSI_RecordGetInteger( rec
, 8 );
782 prop
= MSI_RecordGetString( rec
, 9 );
783 control
->property
= msi_dialog_dup_property( dialog
, prop
, FALSE
);
785 text
= MSI_RecordGetString( rec
, 10 );
786 font_name
= msi_dialog_get_style( text
, &ptr
);
787 info
->font
= ( font_name
) ? msi_dialog_find_font( dialog
, font_name
) : NULL
;
788 msi_free( font_name
);
790 info
->attributes
= MSI_RecordGetInteger( rec
, 8 );
791 if( info
->attributes
& msidbControlAttributesTransparent
)
792 SetWindowLongPtrW( control
->hwnd
, GWL_EXSTYLE
, WS_EX_TRANSPARENT
);
794 info
->oldproc
= (WNDPROC
) SetWindowLongPtrW( control
->hwnd
, GWLP_WNDPROC
,
795 (LONG_PTR
)MSIText_WndProc
);
796 SetPropW( control
->hwnd
, szButtonData
, info
);
798 ControlEvent_SubscribeToEvent( dialog
->package
, dialog
,
799 szSelectionPath
, control
->name
, szSelectionPath
);
801 return ERROR_SUCCESS
;
804 static UINT
msi_dialog_button_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
806 msi_control
*control
;
807 UINT attributes
, style
;
810 TRACE("%p %p\n", dialog
, rec
);
813 attributes
= MSI_RecordGetInteger( rec
, 8 );
814 if( attributes
& msidbControlAttributesIcon
)
817 control
= msi_dialog_add_control( dialog
, rec
, szButton
, style
);
819 return ERROR_FUNCTION_FAILED
;
821 control
->handler
= msi_dialog_button_handler
;
824 text
= msi_get_deformatted_field( dialog
->package
, rec
, 10 );
825 control
->hIcon
= msi_load_icon( dialog
->package
->db
, text
, attributes
);
826 if( attributes
& msidbControlAttributesIcon
)
827 SendMessageW( control
->hwnd
, BM_SETIMAGE
, IMAGE_ICON
, (LPARAM
) control
->hIcon
);
830 return ERROR_SUCCESS
;
833 static LPWSTR
msi_get_checkbox_value( msi_dialog
*dialog
, LPCWSTR prop
)
835 static const WCHAR query
[] = {
836 'S','E','L','E','C','T',' ','*',' ',
837 'F','R','O','M',' ','`','C','h','e','c','k','B','o','x','`',' ',
838 'W','H','E','R','E',' ',
839 '`','P','r','o','p','e','r','t','y','`',' ','=',' ',
842 MSIRECORD
*rec
= NULL
;
845 /* find if there is a value associated with the checkbox */
846 rec
= MSI_QueryGetRecord( dialog
->package
->db
, query
, prop
);
850 ret
= msi_get_deformatted_field( dialog
->package
, rec
, 2 );
856 msiobj_release( &rec
->hdr
);
860 ret
= msi_dup_property( dialog
->package
, prop
);
870 static UINT
msi_dialog_checkbox_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
872 msi_control
*control
;
875 TRACE("%p %p\n", dialog
, rec
);
877 control
= msi_dialog_add_control( dialog
, rec
, szButton
,
878 BS_CHECKBOX
| BS_MULTILINE
| WS_TABSTOP
);
879 control
->handler
= msi_dialog_checkbox_handler
;
880 control
->update
= msi_dialog_checkbox_sync_state
;
881 prop
= MSI_RecordGetString( rec
, 9 );
884 control
->property
= strdupW( prop
);
885 control
->value
= msi_get_checkbox_value( dialog
, prop
);
886 TRACE("control %s value %s\n", debugstr_w(control
->property
),
887 debugstr_w(control
->value
));
889 msi_dialog_checkbox_sync_state( dialog
, control
);
891 return ERROR_SUCCESS
;
894 static UINT
msi_dialog_line_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
898 DWORD style
, exstyle
= 0;
899 DWORD x
, y
, width
, height
;
900 msi_control
*control
;
902 TRACE("%p %p\n", dialog
, rec
);
904 style
= WS_CHILD
| SS_ETCHEDHORZ
| SS_SUNKEN
;
906 name
= MSI_RecordGetString( rec
, 2 );
907 attributes
= MSI_RecordGetInteger( rec
, 8 );
909 if( attributes
& msidbControlAttributesVisible
)
911 if( ~attributes
& msidbControlAttributesEnabled
)
912 style
|= WS_DISABLED
;
913 if( attributes
& msidbControlAttributesSunken
)
914 exstyle
|= WS_EX_CLIENTEDGE
;
916 msi_dialog_map_events(dialog
, name
);
918 control
= msi_alloc( sizeof(*control
) + strlenW(name
) * sizeof(WCHAR
) );
920 return ERROR_OUTOFMEMORY
;
922 strcpyW( control
->name
, name
);
923 list_add_head( &dialog
->controls
, &control
->entry
);
924 control
->handler
= NULL
;
925 control
->property
= NULL
;
926 control
->value
= NULL
;
927 control
->hBitmap
= NULL
;
928 control
->hIcon
= NULL
;
929 control
->hDll
= NULL
;
930 control
->tabnext
= strdupW( MSI_RecordGetString( rec
, 11) );
931 control
->type
= strdupW( MSI_RecordGetString( rec
, 3 ) );
932 control
->progress_current
= 0;
933 control
->progress_max
= 100;
935 x
= MSI_RecordGetInteger( rec
, 4 );
936 y
= MSI_RecordGetInteger( rec
, 5 );
937 width
= MSI_RecordGetInteger( rec
, 6 );
939 x
= msi_dialog_scale_unit( dialog
, x
);
940 y
= msi_dialog_scale_unit( dialog
, y
);
941 width
= msi_dialog_scale_unit( dialog
, width
);
942 height
= 2; /* line is exactly 2 units in height */
944 control
->hwnd
= CreateWindowExW( exstyle
, szStatic
, NULL
, style
,
945 x
, y
, width
, height
, dialog
->hwnd
, NULL
, NULL
, NULL
);
947 TRACE("Dialog %s control %s hwnd %p\n",
948 debugstr_w(dialog
->name
), debugstr_w(name
), control
->hwnd
);
950 return ERROR_SUCCESS
;
953 /******************** Scroll Text ********************************************/
955 struct msi_scrolltext_info
958 msi_control
*control
;
962 static LRESULT WINAPI
963 MSIScrollText_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
965 struct msi_scrolltext_info
*info
;
968 TRACE("%p %04x %08lx %08lx\n", hWnd
, msg
, wParam
, lParam
);
970 info
= GetPropW( hWnd
, szButtonData
);
972 r
= CallWindowProcW( info
->oldproc
, hWnd
, msg
, wParam
, lParam
);
978 RemovePropW( hWnd
, szButtonData
);
981 /* native MSI sets a wait cursor here */
982 msi_dialog_button_handler( info
->dialog
, info
->control
, BN_CLICKED
);
988 struct msi_streamin_info
995 static DWORD CALLBACK
996 msi_richedit_stream_in( DWORD_PTR arg
, LPBYTE buffer
, LONG count
, LONG
*pcb
)
998 struct msi_streamin_info
*info
= (struct msi_streamin_info
*) arg
;
1000 if( (count
+ info
->offset
) > info
->length
)
1001 count
= info
->length
- info
->offset
;
1002 memcpy( buffer
, &info
->string
[ info
->offset
], count
);
1004 info
->offset
+= count
;
1006 TRACE("%d/%d\n", info
->offset
, info
->length
);
1011 static void msi_scrolltext_add_text( msi_control
*control
, LPCWSTR text
)
1013 struct msi_streamin_info info
;
1016 info
.string
= strdupWtoA( text
);
1018 info
.length
= lstrlenA( info
.string
) + 1;
1020 es
.dwCookie
= (DWORD_PTR
) &info
;
1022 es
.pfnCallback
= msi_richedit_stream_in
;
1024 SendMessageW( control
->hwnd
, EM_STREAMIN
, SF_RTF
, (LPARAM
) &es
);
1026 msi_free( info
.string
);
1029 static UINT
msi_dialog_scrolltext_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1031 static const WCHAR szRichEdit20W
[] = {
1032 'R','i','c','h','E','d','i','t','2','0','W',0
1034 struct msi_scrolltext_info
*info
;
1035 msi_control
*control
;
1040 info
= msi_alloc( sizeof *info
);
1042 return ERROR_FUNCTION_FAILED
;
1044 hRichedit
= LoadLibraryA("riched20");
1046 style
= WS_BORDER
| ES_MULTILINE
| WS_VSCROLL
|
1047 ES_READONLY
| ES_AUTOVSCROLL
| WS_TABSTOP
;
1048 control
= msi_dialog_add_control( dialog
, rec
, szRichEdit20W
, style
);
1051 FreeLibrary( hRichedit
);
1053 return ERROR_FUNCTION_FAILED
;
1056 control
->hDll
= hRichedit
;
1058 info
->dialog
= dialog
;
1059 info
->control
= control
;
1061 /* subclass the static control */
1062 info
->oldproc
= (WNDPROC
) SetWindowLongPtrW( control
->hwnd
, GWLP_WNDPROC
,
1063 (LONG_PTR
)MSIScrollText_WndProc
);
1064 SetPropW( control
->hwnd
, szButtonData
, info
);
1066 /* add the text into the richedit */
1067 text
= MSI_RecordGetString( rec
, 10 );
1069 msi_scrolltext_add_text( control
, text
);
1071 return ERROR_SUCCESS
;
1074 static HBITMAP
msi_load_picture( MSIDATABASE
*db
, LPCWSTR name
,
1075 INT cx
, INT cy
, DWORD flags
)
1077 HBITMAP hOleBitmap
= 0, hBitmap
= 0, hOldSrcBitmap
, hOldDestBitmap
;
1078 MSIRECORD
*rec
= NULL
;
1079 IStream
*stm
= NULL
;
1080 IPicture
*pic
= NULL
;
1085 rec
= msi_get_binary_record( db
, name
);
1089 r
= MSI_RecordGetIStream( rec
, 2, &stm
);
1090 msiobj_release( &rec
->hdr
);
1091 if( r
!= ERROR_SUCCESS
)
1094 r
= OleLoadPicture( stm
, 0, TRUE
, &IID_IPicture
, (LPVOID
*) &pic
);
1095 IStream_Release( stm
);
1098 ERR("failed to load picture\n");
1102 r
= IPicture_get_Handle( pic
, (OLE_HANDLE
*) &hOleBitmap
);
1105 ERR("failed to get bitmap handle\n");
1109 /* make the bitmap the desired size */
1110 r
= GetObjectW( hOleBitmap
, sizeof bm
, &bm
);
1111 if (r
!= sizeof bm
)
1113 ERR("failed to get bitmap size\n");
1117 if (flags
& LR_DEFAULTSIZE
)
1123 srcdc
= CreateCompatibleDC( NULL
);
1124 hOldSrcBitmap
= SelectObject( srcdc
, hOleBitmap
);
1125 destdc
= CreateCompatibleDC( NULL
);
1126 hBitmap
= CreateCompatibleBitmap( srcdc
, cx
, cy
);
1127 hOldDestBitmap
= SelectObject( destdc
, hBitmap
);
1128 StretchBlt( destdc
, 0, 0, cx
, cy
,
1129 srcdc
, 0, 0, bm
.bmWidth
, bm
.bmHeight
, SRCCOPY
);
1130 SelectObject( srcdc
, hOldSrcBitmap
);
1131 SelectObject( destdc
, hOldDestBitmap
);
1137 IPicture_Release( pic
);
1141 static UINT
msi_dialog_bitmap_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1143 UINT cx
, cy
, flags
, style
, attributes
;
1144 msi_control
*control
;
1147 flags
= LR_LOADFROMFILE
;
1148 style
= SS_BITMAP
| SS_LEFT
| WS_GROUP
;
1150 attributes
= MSI_RecordGetInteger( rec
, 8 );
1151 if( attributes
& msidbControlAttributesFixedSize
)
1153 flags
|= LR_DEFAULTSIZE
;
1154 style
|= SS_CENTERIMAGE
;
1157 control
= msi_dialog_add_control( dialog
, rec
, szStatic
, style
);
1158 cx
= MSI_RecordGetInteger( rec
, 6 );
1159 cy
= MSI_RecordGetInteger( rec
, 7 );
1160 cx
= msi_dialog_scale_unit( dialog
, cx
);
1161 cy
= msi_dialog_scale_unit( dialog
, cy
);
1163 text
= msi_get_deformatted_field( dialog
->package
, rec
, 10 );
1164 control
->hBitmap
= msi_load_picture( dialog
->package
->db
, text
, cx
, cy
, flags
);
1165 if( control
->hBitmap
)
1166 SendMessageW( control
->hwnd
, STM_SETIMAGE
,
1167 IMAGE_BITMAP
, (LPARAM
) control
->hBitmap
);
1169 ERR("Failed to load bitmap %s\n", debugstr_w(text
));
1173 return ERROR_SUCCESS
;
1176 static UINT
msi_dialog_icon_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1178 msi_control
*control
;
1184 control
= msi_dialog_add_control( dialog
, rec
, szStatic
,
1185 SS_ICON
| SS_CENTERIMAGE
| WS_GROUP
);
1187 attributes
= MSI_RecordGetInteger( rec
, 8 );
1188 text
= msi_get_deformatted_field( dialog
->package
, rec
, 10 );
1189 control
->hIcon
= msi_load_icon( dialog
->package
->db
, text
, attributes
);
1190 if( control
->hIcon
)
1191 SendMessageW( control
->hwnd
, STM_SETICON
, (WPARAM
) control
->hIcon
, 0 );
1193 ERR("Failed to load bitmap %s\n", debugstr_w(text
));
1195 return ERROR_SUCCESS
;
1198 static UINT
msi_dialog_combo_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1200 static const WCHAR szCombo
[] = { 'C','O','M','B','O','B','O','X',0 };
1201 DWORD attributes
, style
;
1203 style
= CBS_AUTOHSCROLL
| WS_TABSTOP
| WS_GROUP
| WS_CHILD
;
1204 attributes
= MSI_RecordGetInteger( rec
, 8 );
1205 if ( ~attributes
& msidbControlAttributesSorted
)
1207 if ( attributes
& msidbControlAttributesComboList
)
1208 style
|= CBS_DROPDOWNLIST
;
1210 style
|= CBS_DROPDOWN
;
1212 msi_dialog_add_control( dialog
, rec
, szCombo
, style
);
1213 return ERROR_SUCCESS
;
1216 /* length of 2^32 + 1 */
1217 #define MAX_NUM_DIGITS 11
1219 static UINT
msi_dialog_edit_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1221 msi_control
*control
;
1223 LPWSTR val
, begin
, end
;
1224 WCHAR num
[MAX_NUM_DIGITS
];
1227 control
= msi_dialog_add_control( dialog
, rec
, szEdit
,
1228 WS_BORDER
| WS_TABSTOP
| ES_AUTOHSCROLL
);
1229 control
->handler
= msi_dialog_edit_handler
;
1231 text
= MSI_RecordGetString( rec
, 10 );
1234 begin
= strchrW( text
, '{' );
1235 end
= strchrW( text
, '}' );
1237 if ( begin
&& end
&& end
> begin
&&
1238 begin
[0] >= '0' && begin
[0] <= '9' &&
1239 end
- begin
< MAX_NUM_DIGITS
)
1241 lstrcpynW( num
, begin
+ 1, end
- begin
);
1242 limit
= atolW( num
);
1244 SendMessageW( control
->hwnd
, EM_SETLIMITTEXT
, limit
, 0 );
1248 prop
= MSI_RecordGetString( rec
, 9 );
1250 control
->property
= strdupW( prop
);
1252 val
= msi_dup_property( dialog
->package
, control
->property
);
1253 SetWindowTextW( control
->hwnd
, val
);
1255 return ERROR_SUCCESS
;
1258 /******************** Masked Edit ********************************************/
1260 #define MASK_MAX_GROUPS 20
1262 struct msi_mask_group
1270 struct msi_maskedit_info
1278 struct msi_mask_group group
[MASK_MAX_GROUPS
];
1281 static BOOL
msi_mask_editable( WCHAR type
)
1296 static void msi_mask_control_change( struct msi_maskedit_info
*info
)
1301 val
= msi_alloc( (info
->num_chars
+1)*sizeof(WCHAR
) );
1302 for( i
=0, n
=0; i
<info
->num_groups
; i
++ )
1304 if( (info
->group
[i
].len
+ n
) > info
->num_chars
)
1306 ERR("can't fit control %d text into template\n",i
);
1309 if (!msi_mask_editable(info
->group
[i
].type
))
1311 for(r
=0; r
<info
->group
[i
].len
; r
++)
1312 val
[n
+r
] = info
->group
[i
].type
;
1317 r
= GetWindowTextW( info
->group
[i
].hwnd
, &val
[n
], info
->group
[i
].len
+1 );
1318 if( r
!= info
->group
[i
].len
)
1324 TRACE("%d/%d controls were good\n", i
, info
->num_groups
);
1326 if( i
== info
->num_groups
)
1328 TRACE("Set property %s to %s\n",
1329 debugstr_w(info
->prop
), debugstr_w(val
) );
1330 CharUpperBuffW( val
, info
->num_chars
);
1331 MSI_SetPropertyW( info
->dialog
->package
, info
->prop
, val
);
1332 msi_dialog_evaluate_control_conditions( info
->dialog
);
1337 /* now move to the next control if necessary */
1338 static VOID
msi_mask_next_control( struct msi_maskedit_info
*info
, HWND hWnd
)
1343 for( i
=0; i
<info
->num_groups
; i
++ )
1344 if( info
->group
[i
].hwnd
== hWnd
)
1347 /* don't move from the last control */
1348 if( i
>= (info
->num_groups
-1) )
1351 len
= SendMessageW( hWnd
, WM_GETTEXTLENGTH
, 0, 0 );
1352 if( len
< info
->group
[i
].len
)
1355 hWndNext
= GetNextDlgTabItem( GetParent( hWnd
), hWnd
, FALSE
);
1356 SetFocus( hWndNext
);
1359 static LRESULT WINAPI
1360 MSIMaskedEdit_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1362 struct msi_maskedit_info
*info
;
1365 TRACE("%p %04x %08lx %08lx\n", hWnd
, msg
, wParam
, lParam
);
1367 info
= GetPropW(hWnd
, szButtonData
);
1369 r
= CallWindowProcW(info
->oldproc
, hWnd
, msg
, wParam
, lParam
);
1374 if (HIWORD(wParam
) == EN_CHANGE
)
1376 msi_mask_control_change( info
);
1377 msi_mask_next_control( info
, (HWND
) lParam
);
1381 msi_free( info
->prop
);
1383 RemovePropW( hWnd
, szButtonData
);
1390 /* fish the various bits of the property out and put them in the control */
1392 msi_maskedit_set_text( struct msi_maskedit_info
*info
, LPCWSTR text
)
1398 for( i
= 0; i
< info
->num_groups
; i
++ )
1400 if( info
->group
[i
].len
< strlenW( p
) )
1402 LPWSTR chunk
= strdupW( p
);
1403 chunk
[ info
->group
[i
].len
] = 0;
1404 SetWindowTextW( info
->group
[i
].hwnd
, chunk
);
1409 SetWindowTextW( info
->group
[i
].hwnd
, p
);
1412 p
+= info
->group
[i
].len
;
1416 static struct msi_maskedit_info
* msi_dialog_parse_groups( LPCWSTR mask
)
1418 struct msi_maskedit_info
* info
= NULL
;
1419 int i
= 0, n
= 0, total
= 0;
1422 TRACE("masked control, template %s\n", debugstr_w(mask
));
1427 info
= msi_alloc_zero( sizeof *info
);
1431 p
= strchrW(mask
, '<');
1437 for( i
=0; i
<MASK_MAX_GROUPS
; i
++ )
1439 /* stop at the end of the string */
1440 if( p
[0] == 0 || p
[0] == '>' )
1443 /* count the number of the same identifier */
1444 for( n
=0; p
[n
] == p
[0]; n
++ )
1446 info
->group
[i
].ofs
= total
;
1447 info
->group
[i
].type
= p
[0];
1451 total
++; /* an extra not part of the group */
1453 info
->group
[i
].len
= n
;
1458 TRACE("%d characters in %d groups\n", total
, i
);
1459 if( i
== MASK_MAX_GROUPS
)
1460 ERR("too many groups in PIDTemplate %s\n", debugstr_w(mask
));
1462 info
->num_chars
= total
;
1463 info
->num_groups
= i
;
1469 msi_maskedit_create_children( struct msi_maskedit_info
*info
, LPCWSTR font
)
1471 DWORD width
, height
, style
, wx
, ww
;
1476 style
= WS_CHILD
| WS_BORDER
| WS_VISIBLE
| WS_TABSTOP
| ES_AUTOHSCROLL
;
1478 GetClientRect( info
->hwnd
, &rect
);
1480 width
= rect
.right
- rect
.left
;
1481 height
= rect
.bottom
- rect
.top
;
1483 for( i
= 0; i
< info
->num_groups
; i
++ )
1485 if (!msi_mask_editable( info
->group
[i
].type
))
1487 wx
= (info
->group
[i
].ofs
* width
) / info
->num_chars
;
1488 ww
= (info
->group
[i
].len
* width
) / info
->num_chars
;
1490 hwnd
= CreateWindowW( szEdit
, NULL
, style
, wx
, 0, ww
, height
,
1491 info
->hwnd
, NULL
, NULL
, NULL
);
1494 ERR("failed to create mask edit sub window\n");
1498 SendMessageW( hwnd
, EM_LIMITTEXT
, info
->group
[i
].len
, 0 );
1500 msi_dialog_set_font( info
->dialog
, hwnd
,
1501 font
?font
:info
->dialog
->default_font
);
1502 info
->group
[i
].hwnd
= hwnd
;
1507 * office 2003 uses "73931<````=````=````=````=`````>@@@@@"
1508 * delphi 7 uses "<????-??????-??????-????>" and "<???-???>"
1509 * filemaker pro 7 uses "<^^^^=^^^^=^^^^=^^^^=^^^^=^^^^=^^^^^>"
1511 static UINT
msi_dialog_maskedit_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1513 LPWSTR font_mask
, val
= NULL
, font
;
1514 struct msi_maskedit_info
*info
= NULL
;
1515 UINT ret
= ERROR_SUCCESS
;
1516 msi_control
*control
;
1521 font_mask
= msi_get_deformatted_field( dialog
->package
, rec
, 10 );
1522 font
= msi_dialog_get_style( font_mask
, &mask
);
1525 ERR("mask template is empty\n");
1529 info
= msi_dialog_parse_groups( mask
);
1532 ERR("template %s is invalid\n", debugstr_w(mask
));
1536 info
->dialog
= dialog
;
1538 control
= msi_dialog_add_control( dialog
, rec
, szStatic
,
1539 SS_OWNERDRAW
| WS_GROUP
| WS_VISIBLE
);
1542 ERR("Failed to create maskedit container\n");
1543 ret
= ERROR_FUNCTION_FAILED
;
1546 SetWindowLongPtrW( control
->hwnd
, GWL_EXSTYLE
, WS_EX_CONTROLPARENT
);
1548 info
->hwnd
= control
->hwnd
;
1550 /* subclass the static control */
1551 info
->oldproc
= (WNDPROC
) SetWindowLongPtrW( info
->hwnd
, GWLP_WNDPROC
,
1552 (LONG_PTR
)MSIMaskedEdit_WndProc
);
1553 SetPropW( control
->hwnd
, szButtonData
, info
);
1555 prop
= MSI_RecordGetString( rec
, 9 );
1557 info
->prop
= strdupW( prop
);
1559 msi_maskedit_create_children( info
, font
);
1563 val
= msi_dup_property( dialog
->package
, prop
);
1566 msi_maskedit_set_text( info
, val
);
1572 if( ret
!= ERROR_SUCCESS
)
1574 msi_free( font_mask
);
1579 /******************** Progress Bar *****************************************/
1581 static UINT
msi_dialog_progress_bar( msi_dialog
*dialog
, MSIRECORD
*rec
)
1583 msi_control
*control
;
1584 DWORD attributes
, style
;
1587 attributes
= MSI_RecordGetInteger( rec
, 8 );
1588 if( !(attributes
& msidbControlAttributesProgress95
) )
1589 style
|= PBS_SMOOTH
;
1591 control
= msi_dialog_add_control( dialog
, rec
, PROGRESS_CLASSW
, style
);
1593 return ERROR_FUNCTION_FAILED
;
1595 ControlEvent_SubscribeToEvent( dialog
->package
, dialog
,
1596 szSetProgress
, control
->name
, szProgress
);
1597 return ERROR_SUCCESS
;
1600 /******************** Path Edit ********************************************/
1602 struct msi_pathedit_info
1605 msi_control
*control
;
1609 static LPWSTR
msi_get_window_text( HWND hwnd
)
1615 buf
= msi_alloc( sz
*sizeof(WCHAR
) );
1618 r
= GetWindowTextW( hwnd
, buf
, sz
);
1622 buf
= msi_realloc( buf
, sz
*sizeof(WCHAR
) );
1628 static void msi_dialog_update_pathedit( msi_dialog
*dialog
, msi_control
*control
)
1633 if (!control
&& !(control
= msi_dialog_find_control_by_type( dialog
, szPathEdit
)))
1636 indirect
= control
->attributes
& msidbControlAttributesIndirect
;
1637 prop
= msi_dialog_dup_property( dialog
, control
->property
, indirect
);
1638 path
= msi_dialog_dup_property( dialog
, prop
, TRUE
);
1640 SetWindowTextW( control
->hwnd
, path
);
1641 SendMessageW( control
->hwnd
, EM_SETSEL
, 0, -1 );
1647 /* FIXME: test when this should fail */
1648 static BOOL
msi_dialog_verify_path( LPWSTR path
)
1650 if ( !lstrlenW( path
) )
1653 if ( PathIsRelativeW( path
) )
1659 /* returns TRUE if the path is valid, FALSE otherwise */
1660 static BOOL
msi_dialog_onkillfocus( msi_dialog
*dialog
, msi_control
*control
)
1666 indirect
= control
->attributes
& msidbControlAttributesIndirect
;
1667 prop
= msi_dialog_dup_property( dialog
, control
->property
, indirect
);
1669 buf
= msi_get_window_text( control
->hwnd
);
1671 if ( !msi_dialog_verify_path( buf
) )
1673 /* FIXME: display an error message box */
1674 ERR("Invalid path %s\n", debugstr_w( buf
));
1676 SetFocus( control
->hwnd
);
1681 MSI_SetPropertyW( dialog
->package
, prop
, buf
);
1684 msi_dialog_update_pathedit( dialog
, control
);
1686 TRACE("edit %s contents changed, set %s\n", debugstr_w(control
->name
),
1695 static LRESULT WINAPI
MSIPathEdit_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1697 struct msi_pathedit_info
*info
= GetPropW(hWnd
, szButtonData
);
1700 TRACE("%p %04x %08lx %08lx\n", hWnd
, msg
, wParam
, lParam
);
1702 if ( msg
== WM_KILLFOCUS
)
1704 /* if the path is invalid, don't handle this message */
1705 if ( !msi_dialog_onkillfocus( info
->dialog
, info
->control
) )
1709 r
= CallWindowProcW(info
->oldproc
, hWnd
, msg
, wParam
, lParam
);
1711 if ( msg
== WM_NCDESTROY
)
1714 RemovePropW( hWnd
, szButtonData
);
1720 static UINT
msi_dialog_pathedit_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1722 struct msi_pathedit_info
*info
;
1723 msi_control
*control
;
1726 info
= msi_alloc( sizeof *info
);
1728 return ERROR_FUNCTION_FAILED
;
1730 control
= msi_dialog_add_control( dialog
, rec
, szEdit
,
1731 WS_BORDER
| WS_TABSTOP
);
1732 control
->attributes
= MSI_RecordGetInteger( rec
, 8 );
1733 prop
= MSI_RecordGetString( rec
, 9 );
1734 control
->property
= msi_dialog_dup_property( dialog
, prop
, FALSE
);
1736 info
->dialog
= dialog
;
1737 info
->control
= control
;
1738 info
->oldproc
= (WNDPROC
) SetWindowLongPtrW( control
->hwnd
, GWLP_WNDPROC
,
1739 (LONG_PTR
)MSIPathEdit_WndProc
);
1740 SetPropW( control
->hwnd
, szButtonData
, info
);
1742 msi_dialog_update_pathedit( dialog
, control
);
1744 return ERROR_SUCCESS
;
1747 /* radio buttons are a bit different from normal controls */
1748 static UINT
msi_dialog_create_radiobutton( MSIRECORD
*rec
, LPVOID param
)
1750 radio_button_group_descr
*group
= param
;
1751 msi_dialog
*dialog
= group
->dialog
;
1752 msi_control
*control
;
1753 LPCWSTR prop
, text
, name
;
1754 DWORD style
, attributes
= group
->attributes
;
1756 style
= WS_CHILD
| BS_AUTORADIOBUTTON
| BS_MULTILINE
| WS_TABSTOP
;
1757 name
= MSI_RecordGetString( rec
, 3 );
1758 text
= MSI_RecordGetString( rec
, 8 );
1759 if( attributes
& msidbControlAttributesVisible
)
1760 style
|= WS_VISIBLE
;
1761 if( ~attributes
& msidbControlAttributesEnabled
)
1762 style
|= WS_DISABLED
;
1764 control
= msi_dialog_create_window( dialog
, rec
, 0, szButton
, name
, text
,
1765 style
, group
->parent
->hwnd
);
1767 return ERROR_FUNCTION_FAILED
;
1768 control
->handler
= msi_dialog_radiogroup_handler
;
1770 if (!lstrcmpW(control
->name
, group
->propval
))
1771 SendMessageW(control
->hwnd
, BM_SETCHECK
, BST_CHECKED
, 0);
1773 prop
= MSI_RecordGetString( rec
, 1 );
1775 control
->property
= strdupW( prop
);
1777 return ERROR_SUCCESS
;
1780 static UINT
msi_dialog_radiogroup_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1782 static const WCHAR query
[] = {
1783 'S','E','L','E','C','T',' ','*',' ',
1784 'F','R','O','M',' ','R','a','d','i','o','B','u','t','t','o','n',' ',
1785 'W','H','E','R','E',' ',
1786 '`','P','r','o','p','e','r','t','y','`',' ','=',' ','\'','%','s','\'',0};
1789 msi_control
*control
;
1790 MSIQUERY
*view
= NULL
;
1791 radio_button_group_descr group
;
1792 MSIPACKAGE
*package
= dialog
->package
;
1794 DWORD attr
, style
= WS_GROUP
;
1796 prop
= MSI_RecordGetString( rec
, 9 );
1798 TRACE("%p %p %s\n", dialog
, rec
, debugstr_w( prop
));
1800 attr
= MSI_RecordGetInteger( rec
, 8 );
1801 if (attr
& msidbControlAttributesHasBorder
)
1802 style
|= BS_GROUPBOX
;
1804 style
|= BS_OWNERDRAW
;
1806 /* Create parent group box to hold radio buttons */
1807 control
= msi_dialog_add_control( dialog
, rec
, szButton
, style
);
1809 return ERROR_FUNCTION_FAILED
;
1811 oldproc
= (WNDPROC
) SetWindowLongPtrW( control
->hwnd
, GWLP_WNDPROC
,
1812 (LONG_PTR
)MSIRadioGroup_WndProc
);
1813 SetPropW(control
->hwnd
, szButtonData
, oldproc
);
1814 SetWindowLongPtrW( control
->hwnd
, GWL_EXSTYLE
, WS_EX_CONTROLPARENT
);
1817 control
->property
= strdupW( prop
);
1819 /* query the Radio Button table for all control in this group */
1820 r
= MSI_OpenQuery( package
->db
, &view
, query
, prop
);
1821 if( r
!= ERROR_SUCCESS
)
1823 ERR("query failed for dialog %s radio group %s\n",
1824 debugstr_w(dialog
->name
), debugstr_w(prop
));
1825 return ERROR_INVALID_PARAMETER
;
1828 group
.dialog
= dialog
;
1829 group
.parent
= control
;
1830 group
.attributes
= MSI_RecordGetInteger( rec
, 8 );
1831 group
.propval
= msi_dup_property( dialog
->package
, control
->property
);
1833 r
= MSI_IterateRecords( view
, 0, msi_dialog_create_radiobutton
, &group
);
1834 msiobj_release( &view
->hdr
);
1835 msi_free( group
.propval
);
1840 /******************** Selection Tree ***************************************/
1842 struct msi_selection_tree_info
1851 msi_seltree_sync_item_state( HWND hwnd
, MSIFEATURE
*feature
, HTREEITEM hItem
)
1854 DWORD index
= feature
->Action
;
1856 TRACE("Feature %s -> %d %d %d\n", debugstr_w(feature
->Title
),
1857 feature
->Installed
, feature
->Action
, feature
->ActionRequest
);
1859 if (index
== INSTALLSTATE_UNKNOWN
)
1860 index
= INSTALLSTATE_ABSENT
;
1862 tvi
.mask
= TVIF_STATE
;
1864 tvi
.state
= INDEXTOSTATEIMAGEMASK( index
);
1865 tvi
.stateMask
= TVIS_STATEIMAGEMASK
;
1867 SendMessageW( hwnd
, TVM_SETITEMW
, 0, (LPARAM
) &tvi
);
1871 msi_seltree_popup_menu( HWND hwnd
, INT x
, INT y
)
1876 /* create a menu to display */
1877 hMenu
= CreatePopupMenu();
1879 /* FIXME: load strings from resources */
1880 AppendMenuA( hMenu
, MF_ENABLED
, INSTALLSTATE_LOCAL
, "Install feature locally");
1881 AppendMenuA( hMenu
, MF_ENABLED
, USER_INSTALLSTATE_ALL
, "Install entire feature");
1882 AppendMenuA( hMenu
, MF_ENABLED
, INSTALLSTATE_ADVERTISED
, "Install on demand");
1883 AppendMenuA( hMenu
, MF_ENABLED
, INSTALLSTATE_ABSENT
, "Don't install");
1884 r
= TrackPopupMenu( hMenu
, TPM_LEFTALIGN
| TPM_TOPALIGN
| TPM_RETURNCMD
,
1885 x
, y
, 0, hwnd
, NULL
);
1886 DestroyMenu( hMenu
);
1891 msi_seltree_feature_from_item( HWND hwnd
, HTREEITEM hItem
)
1895 /* get the feature from the item */
1896 memset( &tvi
, 0, sizeof tvi
);
1898 tvi
.mask
= TVIF_PARAM
| TVIF_HANDLE
;
1899 SendMessageW( hwnd
, TVM_GETITEMW
, 0, (LPARAM
) &tvi
);
1901 return (MSIFEATURE
*) tvi
.lParam
;
1905 msi_seltree_update_feature_installstate( HWND hwnd
, HTREEITEM hItem
,
1906 MSIPACKAGE
*package
, MSIFEATURE
*feature
, INSTALLSTATE state
)
1908 msi_feature_set_state( package
, feature
, state
);
1909 msi_seltree_sync_item_state( hwnd
, feature
, hItem
);
1910 ACTION_UpdateComponentStates( package
, feature
->Feature
);
1914 msi_seltree_update_siblings_and_children_installstate( HWND hwnd
, HTREEITEM curr
,
1915 MSIPACKAGE
*package
, INSTALLSTATE state
)
1917 /* update all siblings */
1920 MSIFEATURE
*feature
;
1923 feature
= msi_seltree_feature_from_item( hwnd
, curr
);
1924 msi_seltree_update_feature_installstate( hwnd
, curr
, package
, feature
, state
);
1926 /* update this sibling's children */
1927 child
= (HTREEITEM
)SendMessageW( hwnd
, TVM_GETNEXTITEM
, (WPARAM
)TVGN_CHILD
, (LPARAM
)curr
);
1929 msi_seltree_update_siblings_and_children_installstate( hwnd
, child
,
1932 while ((curr
= (HTREEITEM
)SendMessageW( hwnd
, TVM_GETNEXTITEM
, (WPARAM
)TVGN_NEXT
, (LPARAM
)curr
)));
1936 msi_seltree_menu( HWND hwnd
, HTREEITEM hItem
)
1938 struct msi_selection_tree_info
*info
;
1939 MSIFEATURE
*feature
;
1940 MSIPACKAGE
*package
;
1948 info
= GetPropW(hwnd
, szButtonData
);
1949 package
= info
->dialog
->package
;
1951 feature
= msi_seltree_feature_from_item( hwnd
, hItem
);
1954 ERR("item %p feature was NULL\n", hItem
);
1958 /* get the item's rectangle to put the menu just below it */
1960 SendMessageW( hwnd
, TVM_GETITEMRECT
, 0, (LPARAM
) &u
.rc
);
1961 MapWindowPoints( hwnd
, NULL
, u
.pt
, 2 );
1963 r
= msi_seltree_popup_menu( hwnd
, u
.rc
.left
, u
.rc
.top
);
1967 case USER_INSTALLSTATE_ALL
:
1968 r
= INSTALLSTATE_LOCAL
;
1970 case INSTALLSTATE_ADVERTISED
:
1971 case INSTALLSTATE_ABSENT
:
1974 child
= (HTREEITEM
)SendMessageW( hwnd
, TVM_GETNEXTITEM
, (WPARAM
)TVGN_CHILD
, (LPARAM
)hItem
);
1976 msi_seltree_update_siblings_and_children_installstate( hwnd
, child
, package
, r
);
1979 case INSTALLSTATE_LOCAL
:
1980 msi_seltree_update_feature_installstate( hwnd
, hItem
, package
, feature
, r
);
1987 static MSIFEATURE
*msi_seltree_get_selected_feature( msi_control
*control
)
1989 struct msi_selection_tree_info
*info
= GetPropW(control
->hwnd
, szButtonData
);
1990 return msi_seltree_feature_from_item( control
->hwnd
, info
->selected
);
1993 static LRESULT WINAPI
1994 MSISelectionTree_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1996 struct msi_selection_tree_info
*info
;
1997 TVHITTESTINFO tvhti
;
2000 TRACE("%p %04x %08lx %08lx\n", hWnd
, msg
, wParam
, lParam
);
2002 info
= GetPropW(hWnd
, szButtonData
);
2006 case WM_LBUTTONDOWN
:
2007 tvhti
.pt
.x
= (short)LOWORD( lParam
);
2008 tvhti
.pt
.y
= (short)HIWORD( lParam
);
2011 r
= CallWindowProcW(info
->oldproc
, hWnd
, TVM_HITTEST
, 0, (LPARAM
) &tvhti
);
2012 if (tvhti
.flags
& TVHT_ONITEMSTATEICON
)
2013 return msi_seltree_menu( hWnd
, tvhti
.hItem
);
2017 r
= CallWindowProcW(info
->oldproc
, hWnd
, msg
, wParam
, lParam
);
2023 RemovePropW( hWnd
, szButtonData
);
2030 msi_seltree_add_child_features( MSIPACKAGE
*package
, HWND hwnd
,
2031 LPCWSTR parent
, HTREEITEM hParent
)
2033 struct msi_selection_tree_info
*info
= GetPropW( hwnd
, szButtonData
);
2034 MSIFEATURE
*feature
;
2035 TVINSERTSTRUCTW tvis
;
2036 HTREEITEM hitem
, hfirst
= NULL
;
2038 LIST_FOR_EACH_ENTRY( feature
, &package
->features
, MSIFEATURE
, entry
)
2040 if ( lstrcmpW( parent
, feature
->Feature_Parent
) )
2043 if ( !feature
->Title
)
2046 if ( !feature
->Display
)
2049 memset( &tvis
, 0, sizeof tvis
);
2050 tvis
.hParent
= hParent
;
2051 tvis
.hInsertAfter
= TVI_LAST
;
2052 tvis
.u
.item
.mask
= TVIF_TEXT
| TVIF_PARAM
;
2053 tvis
.u
.item
.pszText
= feature
->Title
;
2054 tvis
.u
.item
.lParam
= (LPARAM
) feature
;
2056 hitem
= (HTREEITEM
) SendMessageW( hwnd
, TVM_INSERTITEMW
, 0, (LPARAM
) &tvis
);
2063 msi_seltree_sync_item_state( hwnd
, feature
, hitem
);
2064 msi_seltree_add_child_features( package
, hwnd
,
2065 feature
->Feature
, hitem
);
2067 /* the node is expanded if Display is odd */
2068 if ( feature
->Display
% 2 != 0 )
2069 SendMessageW( hwnd
, TVM_EXPAND
, TVE_EXPAND
, (LPARAM
) hitem
);
2072 /* select the first item */
2073 SendMessageW( hwnd
, TVM_SELECTITEM
, TVGN_CARET
| TVGN_DROPHILITE
, (LPARAM
) hfirst
);
2074 info
->selected
= hfirst
;
2077 static void msi_seltree_create_imagelist( HWND hwnd
)
2079 const int bm_width
= 32, bm_height
= 16, bm_count
= 3;
2080 const int bm_resource
= 0x1001;
2085 himl
= ImageList_Create( bm_width
, bm_height
, FALSE
, 4, 0 );
2088 ERR("failed to create image list\n");
2092 for (i
=0; i
<bm_count
; i
++)
2094 hbmp
= LoadBitmapW( msi_hInstance
, MAKEINTRESOURCEW(i
+bm_resource
) );
2097 ERR("failed to load bitmap %d\n", i
);
2102 * Add a dummy bitmap at offset zero because the treeview
2103 * can't use it as a state mask (zero means no user state).
2106 ImageList_Add( himl
, hbmp
, NULL
);
2108 ImageList_Add( himl
, hbmp
, NULL
);
2111 SendMessageW( hwnd
, TVM_SETIMAGELIST
, TVSIL_STATE
, (LPARAM
)himl
);
2114 static UINT
msi_dialog_seltree_handler( msi_dialog
*dialog
,
2115 msi_control
*control
, WPARAM param
)
2117 struct msi_selection_tree_info
*info
= GetPropW( control
->hwnd
, szButtonData
);
2118 LPNMTREEVIEWW tv
= (LPNMTREEVIEWW
)param
;
2119 MSIRECORD
*row
, *rec
;
2121 MSIFEATURE
*feature
;
2122 LPCWSTR dir
, title
= NULL
;
2123 UINT r
= ERROR_SUCCESS
;
2125 static const WCHAR select
[] = {
2126 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2127 '`','F','e','a','t','u','r','e','`',' ','W','H','E','R','E',' ',
2128 '`','T','i','t','l','e','`',' ','=',' ','\'','%','s','\'',0
2131 if (tv
->hdr
.code
!= TVN_SELCHANGINGW
)
2132 return ERROR_SUCCESS
;
2134 info
->selected
= tv
->itemNew
.hItem
;
2136 if (!(tv
->itemNew
.mask
& TVIF_TEXT
))
2138 feature
= msi_seltree_feature_from_item( control
->hwnd
, tv
->itemNew
.hItem
);
2140 title
= feature
->Title
;
2143 title
= tv
->itemNew
.pszText
;
2145 row
= MSI_QueryGetRecord( dialog
->package
->db
, select
, title
);
2147 return ERROR_FUNCTION_FAILED
;
2149 rec
= MSI_CreateRecord( 1 );
2151 MSI_RecordSetStringW( rec
, 1, MSI_RecordGetString( row
, 4 ) );
2152 ControlEvent_FireSubscribedEvent( dialog
->package
, szSelectionDescription
, rec
);
2154 dir
= MSI_RecordGetString( row
, 7 );
2155 folder
= get_loaded_folder( dialog
->package
, dir
);
2158 r
= ERROR_FUNCTION_FAILED
;
2162 MSI_RecordSetStringW( rec
, 1, folder
->ResolvedTarget
);
2163 ControlEvent_FireSubscribedEvent( dialog
->package
, szSelectionPath
, rec
);
2166 msiobj_release(&row
->hdr
);
2167 msiobj_release(&rec
->hdr
);
2172 static UINT
msi_dialog_selection_tree( msi_dialog
*dialog
, MSIRECORD
*rec
)
2174 msi_control
*control
;
2176 MSIPACKAGE
*package
= dialog
->package
;
2178 struct msi_selection_tree_info
*info
;
2180 info
= msi_alloc( sizeof *info
);
2182 return ERROR_FUNCTION_FAILED
;
2184 /* create the treeview control */
2185 style
= TVS_HASLINES
| TVS_HASBUTTONS
| TVS_LINESATROOT
;
2186 style
|= WS_GROUP
| WS_VSCROLL
;
2187 control
= msi_dialog_add_control( dialog
, rec
, WC_TREEVIEWW
, style
);
2191 return ERROR_FUNCTION_FAILED
;
2194 control
->handler
= msi_dialog_seltree_handler
;
2195 control
->attributes
= MSI_RecordGetInteger( rec
, 8 );
2196 prop
= MSI_RecordGetString( rec
, 9 );
2197 control
->property
= msi_dialog_dup_property( dialog
, prop
, FALSE
);
2200 info
->dialog
= dialog
;
2201 info
->hwnd
= control
->hwnd
;
2202 info
->oldproc
= (WNDPROC
) SetWindowLongPtrW( control
->hwnd
, GWLP_WNDPROC
,
2203 (LONG_PTR
)MSISelectionTree_WndProc
);
2204 SetPropW( control
->hwnd
, szButtonData
, info
);
2206 ControlEvent_SubscribeToEvent( dialog
->package
, dialog
,
2207 szSelectionPath
, control
->name
, szProperty
);
2210 msi_seltree_create_imagelist( control
->hwnd
);
2211 msi_seltree_add_child_features( package
, control
->hwnd
, NULL
, NULL
);
2213 return ERROR_SUCCESS
;
2216 /******************** Group Box ***************************************/
2218 static UINT
msi_dialog_group_box( msi_dialog
*dialog
, MSIRECORD
*rec
)
2220 msi_control
*control
;
2223 style
= BS_GROUPBOX
| WS_CHILD
| WS_GROUP
;
2224 control
= msi_dialog_add_control( dialog
, rec
, WC_BUTTONW
, style
);
2226 return ERROR_FUNCTION_FAILED
;
2228 return ERROR_SUCCESS
;
2231 /******************** List Box ***************************************/
2233 struct msi_listbox_info
2243 static LRESULT WINAPI
MSIListBox_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
2245 struct msi_listbox_info
*info
;
2249 TRACE("%p %04x %08lx %08lx\n", hWnd
, msg
, wParam
, lParam
);
2251 info
= GetPropW( hWnd
, szButtonData
);
2255 r
= CallWindowProcW( info
->oldproc
, hWnd
, msg
, wParam
, lParam
);
2260 for (j
= 0; j
< info
->num_items
; j
++)
2261 msi_free( info
->items
[j
] );
2262 msi_free( info
->items
);
2264 RemovePropW( hWnd
, szButtonData
);
2271 static UINT
msi_listbox_add_item( MSIRECORD
*rec
, LPVOID param
)
2273 struct msi_listbox_info
*info
= param
;
2274 LPCWSTR value
, text
;
2277 value
= MSI_RecordGetString( rec
, 3 );
2278 text
= MSI_RecordGetString( rec
, 4 );
2280 info
->items
[info
->addpos_items
] = strdupW( value
);
2282 pos
= SendMessageW( info
->hwnd
, LB_ADDSTRING
, 0, (LPARAM
)text
);
2283 SendMessageW( info
->hwnd
, LB_SETITEMDATA
, pos
, (LPARAM
)info
->items
[info
->addpos_items
] );
2284 info
->addpos_items
++;
2285 return ERROR_SUCCESS
;
2288 static UINT
msi_listbox_add_items( struct msi_listbox_info
*info
, LPCWSTR property
)
2291 MSIQUERY
*view
= NULL
;
2294 static const WCHAR query
[] = {
2295 'S','E','L','E','C','T',' ','*',' ',
2296 'F','R','O','M',' ','`','L','i','s','t','B','o','x','`',' ',
2297 'W','H','E','R','E',' ',
2298 '`','P','r','o','p','e','r','t','y','`',' ','=',' ','\'','%','s','\'',' ',
2299 'O','R','D','E','R',' ','B','Y',' ','`','O','r','d','e','r','`',0
2302 r
= MSI_OpenQuery( info
->dialog
->package
->db
, &view
, query
, property
);
2303 if ( r
!= ERROR_SUCCESS
)
2306 /* just get the number of records */
2308 r
= MSI_IterateRecords( view
, &count
, NULL
, NULL
);
2310 info
->num_items
= count
;
2311 info
->items
= msi_alloc( sizeof(*info
->items
) * count
);
2313 r
= MSI_IterateRecords( view
, NULL
, msi_listbox_add_item
, info
);
2314 msiobj_release( &view
->hdr
);
2319 static UINT
msi_dialog_listbox_handler( msi_dialog
*dialog
,
2320 msi_control
*control
, WPARAM param
)
2322 struct msi_listbox_info
*info
;
2326 if( HIWORD(param
) != LBN_SELCHANGE
)
2327 return ERROR_SUCCESS
;
2329 info
= GetPropW( control
->hwnd
, szButtonData
);
2330 index
= SendMessageW( control
->hwnd
, LB_GETCURSEL
, 0, 0 );
2331 value
= (LPCWSTR
) SendMessageW( control
->hwnd
, LB_GETITEMDATA
, index
, 0 );
2333 MSI_SetPropertyW( info
->dialog
->package
,
2334 control
->property
, value
);
2335 msi_dialog_evaluate_control_conditions( info
->dialog
);
2337 return ERROR_SUCCESS
;
2340 static UINT
msi_dialog_list_box( msi_dialog
*dialog
, MSIRECORD
*rec
)
2342 struct msi_listbox_info
*info
;
2343 msi_control
*control
;
2344 DWORD attributes
, style
;
2347 info
= msi_alloc( sizeof *info
);
2349 return ERROR_FUNCTION_FAILED
;
2351 style
= WS_TABSTOP
| WS_GROUP
| WS_CHILD
| LBS_NOTIFY
| WS_VSCROLL
| WS_BORDER
;
2352 attributes
= MSI_RecordGetInteger( rec
, 8 );
2353 if (~attributes
& msidbControlAttributesSorted
)
2356 control
= msi_dialog_add_control( dialog
, rec
, WC_LISTBOXW
, style
);
2360 return ERROR_FUNCTION_FAILED
;
2363 control
->handler
= msi_dialog_listbox_handler
;
2365 prop
= MSI_RecordGetString( rec
, 9 );
2366 control
->property
= msi_dialog_dup_property( dialog
, prop
, FALSE
);
2369 info
->dialog
= dialog
;
2370 info
->hwnd
= control
->hwnd
;
2372 info
->addpos_items
= 0;
2373 info
->oldproc
= (WNDPROC
)SetWindowLongPtrW( control
->hwnd
, GWLP_WNDPROC
,
2374 (LONG_PTR
)MSIListBox_WndProc
);
2375 SetPropW( control
->hwnd
, szButtonData
, info
);
2377 if ( control
->property
)
2378 msi_listbox_add_items( info
, control
->property
);
2380 return ERROR_SUCCESS
;
2383 /******************** Directory Combo ***************************************/
2385 static void msi_dialog_update_directory_combo( msi_dialog
*dialog
, msi_control
*control
)
2390 if (!control
&& !(control
= msi_dialog_find_control_by_type( dialog
, szDirectoryCombo
)))
2393 indirect
= control
->attributes
& msidbControlAttributesIndirect
;
2394 prop
= msi_dialog_dup_property( dialog
, control
->property
, indirect
);
2395 path
= msi_dialog_dup_property( dialog
, prop
, TRUE
);
2397 PathStripPathW( path
);
2398 PathRemoveBackslashW( path
);
2400 SendMessageW( control
->hwnd
, CB_INSERTSTRING
, 0, (LPARAM
)path
);
2401 SendMessageW( control
->hwnd
, CB_SETCURSEL
, 0, 0 );
2407 static UINT
msi_dialog_directory_combo( msi_dialog
*dialog
, MSIRECORD
*rec
)
2409 msi_control
*control
;
2413 /* FIXME: use CBS_OWNERDRAWFIXED and add owner draw code */
2414 style
= CBS_DROPDOWNLIST
| CBS_HASSTRINGS
| WS_CHILD
|
2415 WS_GROUP
| WS_TABSTOP
| WS_VSCROLL
;
2416 control
= msi_dialog_add_control( dialog
, rec
, WC_COMBOBOXW
, style
);
2418 return ERROR_FUNCTION_FAILED
;
2420 control
->attributes
= MSI_RecordGetInteger( rec
, 8 );
2421 prop
= MSI_RecordGetString( rec
, 9 );
2422 control
->property
= msi_dialog_dup_property( dialog
, prop
, FALSE
);
2424 msi_dialog_update_directory_combo( dialog
, control
);
2426 return ERROR_SUCCESS
;
2429 /******************** Directory List ***************************************/
2431 static void msi_dialog_update_directory_list( msi_dialog
*dialog
, msi_control
*control
)
2433 WCHAR dir_spec
[MAX_PATH
];
2434 WIN32_FIND_DATAW wfd
;
2440 static const WCHAR asterisk
[] = {'*',0};
2442 if (!control
&& !(control
= msi_dialog_find_control_by_type( dialog
, szDirectoryList
)))
2445 /* clear the list-view */
2446 SendMessageW( control
->hwnd
, LVM_DELETEALLITEMS
, 0, 0 );
2448 indirect
= control
->attributes
& msidbControlAttributesIndirect
;
2449 prop
= msi_dialog_dup_property( dialog
, control
->property
, indirect
);
2450 path
= msi_dialog_dup_property( dialog
, prop
, TRUE
);
2452 lstrcpyW( dir_spec
, path
);
2453 lstrcatW( dir_spec
, asterisk
);
2455 file
= FindFirstFileW( dir_spec
, &wfd
);
2456 if ( file
== INVALID_HANDLE_VALUE
)
2461 if ( wfd
.dwFileAttributes
!= FILE_ATTRIBUTE_DIRECTORY
)
2464 if ( !lstrcmpW( wfd
.cFileName
, szDot
) || !lstrcmpW( wfd
.cFileName
, szDotDot
) )
2467 item
.mask
= LVIF_TEXT
;
2468 item
.cchTextMax
= MAX_PATH
;
2471 item
.pszText
= wfd
.cFileName
;
2473 SendMessageW( control
->hwnd
, LVM_INSERTITEMW
, 0, (LPARAM
)&item
);
2474 } while ( FindNextFileW( file
, &wfd
) );
2481 UINT
msi_dialog_directorylist_up( msi_dialog
*dialog
)
2483 msi_control
*control
;
2484 LPWSTR prop
, path
, ptr
;
2487 control
= msi_dialog_find_control_by_type( dialog
, szDirectoryList
);
2488 indirect
= control
->attributes
& msidbControlAttributesIndirect
;
2489 prop
= msi_dialog_dup_property( dialog
, control
->property
, indirect
);
2490 path
= msi_dialog_dup_property( dialog
, prop
, TRUE
);
2492 /* strip off the last directory */
2493 ptr
= PathFindFileNameW( path
);
2494 if (ptr
!= path
) *(ptr
- 1) = '\0';
2495 PathAddBackslashW( path
);
2497 MSI_SetPropertyW( dialog
->package
, prop
, path
);
2499 msi_dialog_update_directory_list( dialog
, NULL
);
2500 msi_dialog_update_directory_combo( dialog
, NULL
);
2501 msi_dialog_update_pathedit( dialog
, NULL
);
2506 return ERROR_SUCCESS
;
2509 static UINT
msi_dialog_dirlist_handler( msi_dialog
*dialog
,
2510 msi_control
*control
, WPARAM param
)
2512 LPNMHDR nmhdr
= (LPNMHDR
)param
;
2513 WCHAR new_path
[MAX_PATH
];
2514 WCHAR text
[MAX_PATH
];
2520 if (nmhdr
->code
!= LVN_ITEMACTIVATE
)
2521 return ERROR_SUCCESS
;
2523 index
= SendMessageW( control
->hwnd
, LVM_GETNEXTITEM
, -1, LVNI_SELECTED
);
2526 ERR("No list-view item selected!\n");
2527 return ERROR_FUNCTION_FAILED
;
2531 item
.pszText
= text
;
2532 item
.cchTextMax
= MAX_PATH
;
2533 SendMessageW( control
->hwnd
, LVM_GETITEMTEXTW
, index
, (LPARAM
)&item
);
2535 indirect
= control
->attributes
& msidbControlAttributesIndirect
;
2536 prop
= msi_dialog_dup_property( dialog
, control
->property
, indirect
);
2537 path
= msi_dialog_dup_property( dialog
, prop
, TRUE
);
2539 lstrcpyW( new_path
, path
);
2540 lstrcatW( new_path
, text
);
2541 lstrcatW( new_path
, szBackSlash
);
2543 MSI_SetPropertyW( dialog
->package
, prop
, new_path
);
2545 msi_dialog_update_directory_list( dialog
, NULL
);
2546 msi_dialog_update_directory_combo( dialog
, NULL
);
2547 msi_dialog_update_pathedit( dialog
, NULL
);
2551 return ERROR_SUCCESS
;
2554 static UINT
msi_dialog_directory_list( msi_dialog
*dialog
, MSIRECORD
*rec
)
2556 msi_control
*control
;
2560 style
= LVS_LIST
| WS_VSCROLL
| LVS_SHAREIMAGELISTS
|
2561 LVS_AUTOARRANGE
| LVS_SINGLESEL
| WS_BORDER
|
2562 LVS_SORTASCENDING
| WS_CHILD
| WS_GROUP
| WS_TABSTOP
;
2563 control
= msi_dialog_add_control( dialog
, rec
, WC_LISTVIEWW
, style
);
2565 return ERROR_FUNCTION_FAILED
;
2567 control
->attributes
= MSI_RecordGetInteger( rec
, 8 );
2568 control
->handler
= msi_dialog_dirlist_handler
;
2569 prop
= MSI_RecordGetString( rec
, 9 );
2570 control
->property
= msi_dialog_dup_property( dialog
, prop
, FALSE
);
2572 /* double click to activate an item in the list */
2573 SendMessageW( control
->hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
,
2574 0, LVS_EX_TWOCLICKACTIVATE
);
2576 msi_dialog_update_directory_list( dialog
, control
);
2578 return ERROR_SUCCESS
;
2581 /******************** VolumeCost List ***************************************/
2583 static BOOL
str_is_number( LPCWSTR str
)
2587 for (i
= 0; i
< lstrlenW( str
); i
++)
2588 if (!isdigitW(str
[i
]))
2594 static const WCHAR column_keys
[][80] =
2596 {'V','o','l','u','m','e','C','o','s','t','V','o','l','u','m','e',0},
2597 {'V','o','l','u','m','e','C','o','s','t','S','i','z','e',0},
2598 {'V','o','l','u','m','e','C','o','s','t','A','v','a','i','l','a','b','l','e',0},
2599 {'V','o','l','u','m','e','C','o','s','t','R','e','q','u','i','r','e','d',0},
2600 {'V','o','l','u','m','e','C','o','s','t','D','i','f','f','e','r','e','n','c','e',0}
2603 static void msi_dialog_vcl_add_columns( msi_dialog
*dialog
, msi_control
*control
, MSIRECORD
*rec
)
2605 LPCWSTR text
= MSI_RecordGetString( rec
, 10 );
2606 LPCWSTR begin
= text
, end
;
2611 static const WCHAR negative
[] = {'-',0};
2615 while ((begin
= strchrW( begin
, '{' )) && count
< 5)
2617 if (!(end
= strchrW( begin
, '}' )))
2620 num
= msi_alloc( (end
-begin
+1)*sizeof(WCHAR
) );
2624 lstrcpynW( num
, begin
+ 1, end
- begin
);
2625 begin
+= end
- begin
+ 1;
2627 /* empty braces or '0' hides the column */
2628 if ( !num
[0] || !lstrcmpW( num
, szZero
) )
2635 /* the width must be a positive number
2636 * if a width is invalid, all remaining columns are hidden
2638 if ( !strncmpW( num
, negative
, 1 ) || !str_is_number( num
) ) {
2643 ZeroMemory( &lvc
, sizeof(lvc
) );
2644 lvc
.mask
= LVCF_TEXT
| LVCF_WIDTH
| LVCF_SUBITEM
;
2645 lvc
.cx
= atolW( num
);
2646 lvc
.pszText
= msi_dialog_get_uitext( dialog
, column_keys
[count
] );
2648 SendMessageW( control
->hwnd
, LVM_INSERTCOLUMNW
, count
++, (LPARAM
)&lvc
);
2649 msi_free( lvc
.pszText
);
2654 static LONGLONG
msi_vcl_get_cost( msi_dialog
*dialog
)
2656 MSIFEATURE
*feature
;
2658 LONGLONG total_cost
= 0;
2660 LIST_FOR_EACH_ENTRY( feature
, &dialog
->package
->features
, MSIFEATURE
, entry
)
2662 if (ERROR_SUCCESS
== (MSI_GetFeatureCost(dialog
->package
, feature
,
2663 MSICOSTTREE_SELFONLY
, INSTALLSTATE_LOCAL
, &each_cost
)))
2665 /* each_cost is in 512-byte units */
2666 total_cost
+= each_cost
* 512;
2668 if (ERROR_SUCCESS
== (MSI_GetFeatureCost(dialog
->package
, feature
,
2669 MSICOSTTREE_SELFONLY
, INSTALLSTATE_ABSENT
, &each_cost
)))
2671 /* each_cost is in 512-byte units */
2672 total_cost
-= each_cost
* 512;
2678 static void msi_dialog_vcl_add_drives( msi_dialog
*dialog
, msi_control
*control
)
2680 ULARGE_INTEGER total
, free
;
2681 LONGLONG difference
, cost
;
2682 WCHAR size_text
[MAX_PATH
];
2683 WCHAR cost_text
[MAX_PATH
];
2689 cost
= msi_vcl_get_cost(dialog
);
2690 StrFormatByteSizeW(cost
, cost_text
, MAX_PATH
);
2692 size
= GetLogicalDriveStringsW( 0, NULL
);
2693 if ( !size
) return;
2695 drives
= msi_alloc( (size
+ 1) * sizeof(WCHAR
) );
2696 if ( !drives
) return;
2698 GetLogicalDriveStringsW( size
, drives
);
2703 lvitem
.mask
= LVIF_TEXT
;
2705 lvitem
.iSubItem
= 0;
2706 lvitem
.pszText
= ptr
;
2707 lvitem
.cchTextMax
= lstrlenW(ptr
) + 1;
2708 SendMessageW( control
->hwnd
, LVM_INSERTITEMW
, 0, (LPARAM
)&lvitem
);
2710 GetDiskFreeSpaceExW(ptr
, &free
, &total
, NULL
);
2711 difference
= free
.QuadPart
- cost
;
2713 StrFormatByteSizeW(total
.QuadPart
, size_text
, MAX_PATH
);
2714 lvitem
.iSubItem
= 1;
2715 lvitem
.pszText
= size_text
;
2716 lvitem
.cchTextMax
= lstrlenW(size_text
) + 1;
2717 SendMessageW( control
->hwnd
, LVM_SETITEMW
, 0, (LPARAM
)&lvitem
);
2719 StrFormatByteSizeW(free
.QuadPart
, size_text
, MAX_PATH
);
2720 lvitem
.iSubItem
= 2;
2721 lvitem
.pszText
= size_text
;
2722 lvitem
.cchTextMax
= lstrlenW(size_text
) + 1;
2723 SendMessageW( control
->hwnd
, LVM_SETITEMW
, 0, (LPARAM
)&lvitem
);
2725 lvitem
.iSubItem
= 3;
2726 lvitem
.pszText
= cost_text
;
2727 lvitem
.cchTextMax
= lstrlenW(cost_text
) + 1;
2728 SendMessageW( control
->hwnd
, LVM_SETITEMW
, 0, (LPARAM
)&lvitem
);
2730 StrFormatByteSizeW(difference
, size_text
, MAX_PATH
);
2731 lvitem
.iSubItem
= 4;
2732 lvitem
.pszText
= size_text
;
2733 lvitem
.cchTextMax
= lstrlenW(size_text
) + 1;
2734 SendMessageW( control
->hwnd
, LVM_SETITEMW
, 0, (LPARAM
)&lvitem
);
2736 ptr
+= lstrlenW(ptr
) + 1;
2743 static UINT
msi_dialog_volumecost_list( msi_dialog
*dialog
, MSIRECORD
*rec
)
2745 msi_control
*control
;
2748 style
= LVS_REPORT
| WS_VSCROLL
| WS_HSCROLL
| LVS_SHAREIMAGELISTS
|
2749 LVS_AUTOARRANGE
| LVS_SINGLESEL
| WS_BORDER
|
2750 WS_CHILD
| WS_TABSTOP
| WS_GROUP
;
2751 control
= msi_dialog_add_control( dialog
, rec
, WC_LISTVIEWW
, style
);
2753 return ERROR_FUNCTION_FAILED
;
2755 msi_dialog_vcl_add_columns( dialog
, control
, rec
);
2756 msi_dialog_vcl_add_drives( dialog
, control
);
2758 return ERROR_SUCCESS
;
2761 /******************** VolumeSelect Combo ***************************************/
2763 static UINT
msi_dialog_volsel_handler( msi_dialog
*dialog
,
2764 msi_control
*control
, WPARAM param
)
2766 WCHAR text
[MAX_PATH
];
2771 if (HIWORD(param
) != CBN_SELCHANGE
)
2772 return ERROR_SUCCESS
;
2774 index
= SendMessageW( control
->hwnd
, CB_GETCURSEL
, 0, 0 );
2775 if ( index
== CB_ERR
)
2777 ERR("No ComboBox item selected!\n");
2778 return ERROR_FUNCTION_FAILED
;
2781 SendMessageW( control
->hwnd
, CB_GETLBTEXT
, index
, (LPARAM
)text
);
2783 indirect
= control
->attributes
& msidbControlAttributesIndirect
;
2784 prop
= msi_dialog_dup_property( dialog
, control
->property
, indirect
);
2786 MSI_SetPropertyW( dialog
->package
, prop
, text
);
2789 return ERROR_SUCCESS
;
2792 static void msi_dialog_vsc_add_drives( msi_dialog
*dialog
, msi_control
*control
)
2797 size
= GetLogicalDriveStringsW( 0, NULL
);
2798 if ( !size
) return;
2800 drives
= msi_alloc( (size
+ 1) * sizeof(WCHAR
) );
2801 if ( !drives
) return;
2803 GetLogicalDriveStringsW( size
, drives
);
2808 SendMessageW( control
->hwnd
, CB_ADDSTRING
, 0, (LPARAM
)ptr
);
2809 ptr
+= lstrlenW(ptr
) + 1;
2815 static UINT
msi_dialog_volumeselect_combo( msi_dialog
*dialog
, MSIRECORD
*rec
)
2817 msi_control
*control
;
2821 /* FIXME: CBS_OWNERDRAWFIXED */
2822 style
= WS_CHILD
| WS_VISIBLE
| WS_GROUP
| WS_TABSTOP
|
2823 CBS_DROPDOWNLIST
| CBS_SORT
| CBS_HASSTRINGS
|
2824 WS_EX_LEFT
| WS_EX_LTRREADING
| WS_EX_RIGHTSCROLLBAR
;
2825 control
= msi_dialog_add_control( dialog
, rec
, WC_COMBOBOXW
, style
);
2827 return ERROR_FUNCTION_FAILED
;
2829 control
->attributes
= MSI_RecordGetInteger( rec
, 8 );
2830 control
->handler
= msi_dialog_volsel_handler
;
2831 prop
= MSI_RecordGetString( rec
, 9 );
2832 control
->property
= msi_dialog_dup_property( dialog
, prop
, FALSE
);
2834 msi_dialog_vsc_add_drives( dialog
, control
);
2836 return ERROR_SUCCESS
;
2839 static const struct control_handler msi_dialog_handler
[] =
2841 { szText
, msi_dialog_text_control
},
2842 { szPushButton
, msi_dialog_button_control
},
2843 { szLine
, msi_dialog_line_control
},
2844 { szBitmap
, msi_dialog_bitmap_control
},
2845 { szCheckBox
, msi_dialog_checkbox_control
},
2846 { szScrollableText
, msi_dialog_scrolltext_control
},
2847 { szComboBox
, msi_dialog_combo_control
},
2848 { szEdit
, msi_dialog_edit_control
},
2849 { szMaskedEdit
, msi_dialog_maskedit_control
},
2850 { szPathEdit
, msi_dialog_pathedit_control
},
2851 { szProgressBar
, msi_dialog_progress_bar
},
2852 { szRadioButtonGroup
, msi_dialog_radiogroup_control
},
2853 { szIcon
, msi_dialog_icon_control
},
2854 { szSelectionTree
, msi_dialog_selection_tree
},
2855 { szGroupBox
, msi_dialog_group_box
},
2856 { szListBox
, msi_dialog_list_box
},
2857 { szDirectoryCombo
, msi_dialog_directory_combo
},
2858 { szDirectoryList
, msi_dialog_directory_list
},
2859 { szVolumeCostList
, msi_dialog_volumecost_list
},
2860 { szVolumeSelectCombo
, msi_dialog_volumeselect_combo
},
2863 #define NUM_CONTROL_TYPES (sizeof msi_dialog_handler/sizeof msi_dialog_handler[0])
2865 static UINT
msi_dialog_create_controls( MSIRECORD
*rec
, LPVOID param
)
2867 msi_dialog
*dialog
= param
;
2868 LPCWSTR control_type
;
2871 /* find and call the function that can create this type of control */
2872 control_type
= MSI_RecordGetString( rec
, 3 );
2873 for( i
=0; i
<NUM_CONTROL_TYPES
; i
++ )
2874 if (!strcmpiW( msi_dialog_handler
[i
].control_type
, control_type
))
2876 if( i
!= NUM_CONTROL_TYPES
)
2877 msi_dialog_handler
[i
].func( dialog
, rec
);
2879 ERR("no handler for element type %s\n", debugstr_w(control_type
));
2881 return ERROR_SUCCESS
;
2884 static UINT
msi_dialog_fill_controls( msi_dialog
*dialog
)
2886 static const WCHAR query
[] = {
2887 'S','E','L','E','C','T',' ','*',' ',
2888 'F','R','O','M',' ','C','o','n','t','r','o','l',' ',
2889 'W','H','E','R','E',' ',
2890 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',0};
2892 MSIQUERY
*view
= NULL
;
2893 MSIPACKAGE
*package
= dialog
->package
;
2895 TRACE("%p %s\n", dialog
, debugstr_w(dialog
->name
) );
2897 /* query the Control table for all the elements of the control */
2898 r
= MSI_OpenQuery( package
->db
, &view
, query
, dialog
->name
);
2899 if( r
!= ERROR_SUCCESS
)
2901 ERR("query failed for dialog %s\n", debugstr_w(dialog
->name
));
2902 return ERROR_INVALID_PARAMETER
;
2905 r
= MSI_IterateRecords( view
, 0, msi_dialog_create_controls
, dialog
);
2906 msiobj_release( &view
->hdr
);
2911 static UINT
msi_dialog_set_control_condition( MSIRECORD
*rec
, LPVOID param
)
2913 static const WCHAR szHide
[] = { 'H','i','d','e',0 };
2914 static const WCHAR szShow
[] = { 'S','h','o','w',0 };
2915 static const WCHAR szDisable
[] = { 'D','i','s','a','b','l','e',0 };
2916 static const WCHAR szEnable
[] = { 'E','n','a','b','l','e',0 };
2917 static const WCHAR szDefault
[] = { 'D','e','f','a','u','l','t',0 };
2918 msi_dialog
*dialog
= param
;
2919 msi_control
*control
;
2920 LPCWSTR name
, action
, condition
;
2923 name
= MSI_RecordGetString( rec
, 2 );
2924 action
= MSI_RecordGetString( rec
, 3 );
2925 condition
= MSI_RecordGetString( rec
, 4 );
2926 r
= MSI_EvaluateConditionW( dialog
->package
, condition
);
2927 control
= msi_dialog_find_control( dialog
, name
);
2928 if( r
== MSICONDITION_TRUE
&& control
)
2930 TRACE("%s control %s\n", debugstr_w(action
), debugstr_w(name
));
2932 /* FIXME: case sensitive? */
2933 if(!lstrcmpW(action
, szHide
))
2934 ShowWindow(control
->hwnd
, SW_HIDE
);
2935 else if(!strcmpW(action
, szShow
))
2936 ShowWindow(control
->hwnd
, SW_SHOW
);
2937 else if(!strcmpW(action
, szDisable
))
2938 EnableWindow(control
->hwnd
, FALSE
);
2939 else if(!strcmpW(action
, szEnable
))
2940 EnableWindow(control
->hwnd
, TRUE
);
2941 else if(!strcmpW(action
, szDefault
))
2942 SetFocus(control
->hwnd
);
2944 FIXME("Unhandled action %s\n", debugstr_w(action
));
2947 return ERROR_SUCCESS
;
2950 static UINT
msi_dialog_evaluate_control_conditions( msi_dialog
*dialog
)
2952 static const WCHAR query
[] = {
2953 'S','E','L','E','C','T',' ','*',' ',
2954 'F','R','O','M',' ',
2955 'C','o','n','t','r','o','l','C','o','n','d','i','t','i','o','n',' ',
2956 'W','H','E','R','E',' ',
2957 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',0
2960 MSIQUERY
*view
= NULL
;
2961 MSIPACKAGE
*package
= dialog
->package
;
2963 TRACE("%p %s\n", dialog
, debugstr_w(dialog
->name
) );
2965 /* query the Control table for all the elements of the control */
2966 r
= MSI_OpenQuery( package
->db
, &view
, query
, dialog
->name
);
2967 if( r
!= ERROR_SUCCESS
)
2968 return ERROR_SUCCESS
;
2970 r
= MSI_IterateRecords( view
, 0, msi_dialog_set_control_condition
, dialog
);
2971 msiobj_release( &view
->hdr
);
2976 UINT
msi_dialog_reset( msi_dialog
*dialog
)
2978 /* FIXME: should restore the original values of any properties we changed */
2979 return msi_dialog_evaluate_control_conditions( dialog
);
2982 /* figure out the height of 10 point MS Sans Serif */
2983 static INT
msi_dialog_get_sans_serif_height( HWND hwnd
)
2985 static const WCHAR szSansSerif
[] = {
2986 'M','S',' ','S','a','n','s',' ','S','e','r','i','f',0 };
2991 HFONT hFont
, hOldFont
;
2994 hdc
= GetDC( hwnd
);
2997 memset( &lf
, 0, sizeof lf
);
2998 lf
.lfHeight
= MulDiv(12, GetDeviceCaps(hdc
, LOGPIXELSY
), 72);
2999 strcpyW( lf
.lfFaceName
, szSansSerif
);
3000 hFont
= CreateFontIndirectW(&lf
);
3003 hOldFont
= SelectObject( hdc
, hFont
);
3004 r
= GetTextMetricsW( hdc
, &tm
);
3006 height
= tm
.tmHeight
;
3007 SelectObject( hdc
, hOldFont
);
3008 DeleteObject( hFont
);
3010 ReleaseDC( hwnd
, hdc
);
3015 /* fetch the associated record from the Dialog table */
3016 static MSIRECORD
*msi_get_dialog_record( msi_dialog
*dialog
)
3018 static const WCHAR query
[] = {
3019 'S','E','L','E','C','T',' ','*',' ',
3020 'F','R','O','M',' ','D','i','a','l','o','g',' ',
3021 'W','H','E','R','E',' ',
3022 '`','D','i','a','l','o','g','`',' ','=',' ','\'','%','s','\'',0};
3023 MSIPACKAGE
*package
= dialog
->package
;
3024 MSIRECORD
*rec
= NULL
;
3026 TRACE("%p %s\n", dialog
, debugstr_w(dialog
->name
) );
3028 rec
= MSI_QueryGetRecord( package
->db
, query
, dialog
->name
);
3030 WARN("query failed for dialog %s\n", debugstr_w(dialog
->name
));
3035 static void msi_dialog_adjust_dialog_pos( msi_dialog
*dialog
, MSIRECORD
*rec
, LPRECT pos
)
3037 static const WCHAR szScreenX
[] = {'S','c','r','e','e','n','X',0};
3038 static const WCHAR szScreenY
[] = {'S','c','r','e','e','n','Y',0};
3045 center
.x
= MSI_RecordGetInteger( rec
, 2 );
3046 center
.y
= MSI_RecordGetInteger( rec
, 3 );
3048 sz
.cx
= MSI_RecordGetInteger( rec
, 4 );
3049 sz
.cy
= MSI_RecordGetInteger( rec
, 5 );
3051 sz
.cx
= msi_dialog_scale_unit( dialog
, sz
.cx
);
3052 sz
.cy
= msi_dialog_scale_unit( dialog
, sz
.cy
);
3054 xres
= msi_get_property_int( dialog
->package
, szScreenX
, 0 );
3055 yres
= msi_get_property_int( dialog
->package
, szScreenY
, 0 );
3057 center
.x
= MulDiv( center
.x
, xres
, 100 );
3058 center
.y
= MulDiv( center
.y
, yres
, 100 );
3060 /* turn the client pos into the window rectangle */
3061 if (dialog
->package
->center_x
&& dialog
->package
->center_y
)
3063 pos
->left
= dialog
->package
->center_x
- sz
.cx
/ 2.0;
3064 pos
->right
= pos
->left
+ sz
.cx
;
3065 pos
->top
= dialog
->package
->center_y
- sz
.cy
/ 2.0;
3066 pos
->bottom
= pos
->top
+ sz
.cy
;
3070 pos
->left
= center
.x
- sz
.cx
/2;
3071 pos
->right
= pos
->left
+ sz
.cx
;
3072 pos
->top
= center
.y
- sz
.cy
/2;
3073 pos
->bottom
= pos
->top
+ sz
.cy
;
3075 /* save the center */
3076 dialog
->package
->center_x
= center
.x
;
3077 dialog
->package
->center_y
= center
.y
;
3080 dialog
->size
.cx
= sz
.cx
;
3081 dialog
->size
.cy
= sz
.cy
;
3083 TRACE("%u %u %u %u\n", pos
->left
, pos
->top
, pos
->right
, pos
->bottom
);
3085 style
= GetWindowLongPtrW( dialog
->hwnd
, GWL_STYLE
);
3086 AdjustWindowRect( pos
, style
, FALSE
);
3089 static void msi_dialog_set_tab_order( msi_dialog
*dialog
, LPCWSTR first
)
3091 struct list tab_chain
;
3092 msi_control
*control
;
3093 HWND prev
= HWND_TOP
;
3095 list_init( &tab_chain
);
3096 if (!(control
= msi_dialog_find_control( dialog
, first
))) return;
3098 dialog
->hWndFocus
= control
->hwnd
;
3101 list_remove( &control
->entry
);
3102 list_add_tail( &tab_chain
, &control
->entry
);
3103 if (!control
->tabnext
) break;
3104 control
= msi_dialog_find_control( dialog
, control
->tabnext
);
3107 LIST_FOR_EACH_ENTRY( control
, &tab_chain
, msi_control
, entry
)
3109 SetWindowPos( control
->hwnd
, prev
, 0, 0, 0, 0,
3110 SWP_NOMOVE
| SWP_NOOWNERZORDER
| SWP_NOREDRAW
|
3111 SWP_NOREPOSITION
| SWP_NOSENDCHANGING
| SWP_NOSIZE
);
3112 prev
= control
->hwnd
;
3115 /* put them back on the main list */
3116 list_move_head( &dialog
->controls
, &tab_chain
);
3119 static LRESULT
msi_dialog_oncreate( HWND hwnd
, LPCREATESTRUCTW cs
)
3121 static const WCHAR df
[] = {
3122 'D','e','f','a','u','l','t','U','I','F','o','n','t',0 };
3123 static const WCHAR dfv
[] = {
3124 'M','S',' ','S','h','e','l','l',' ','D','l','g',0 };
3125 msi_dialog
*dialog
= cs
->lpCreateParams
;
3126 MSIRECORD
*rec
= NULL
;
3127 LPWSTR title
= NULL
;
3130 TRACE("%p %p\n", dialog
, dialog
->package
);
3132 dialog
->hwnd
= hwnd
;
3133 SetWindowLongPtrW( hwnd
, GWLP_USERDATA
, (LONG_PTR
) dialog
);
3135 rec
= msi_get_dialog_record( dialog
);
3138 TRACE("No record found for dialog %s\n", debugstr_w(dialog
->name
));
3142 dialog
->scale
= msi_dialog_get_sans_serif_height(dialog
->hwnd
);
3144 msi_dialog_adjust_dialog_pos( dialog
, rec
, &pos
);
3146 dialog
->attributes
= MSI_RecordGetInteger( rec
, 6 );
3148 dialog
->default_font
= msi_dup_property( dialog
->package
, df
);
3149 if (!dialog
->default_font
)
3151 dialog
->default_font
= strdupW(dfv
);
3152 if (!dialog
->default_font
) return -1;
3155 title
= msi_get_deformatted_field( dialog
->package
, rec
, 7 );
3156 SetWindowTextW( hwnd
, title
);
3159 SetWindowPos( hwnd
, 0, pos
.left
, pos
.top
,
3160 pos
.right
- pos
.left
, pos
.bottom
- pos
.top
,
3161 SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_NOREDRAW
);
3163 msi_dialog_build_font_list( dialog
);
3164 msi_dialog_fill_controls( dialog
);
3165 msi_dialog_evaluate_control_conditions( dialog
);
3166 msi_dialog_set_tab_order( dialog
, MSI_RecordGetString( rec
, 8 ) );
3167 msiobj_release( &rec
->hdr
);
3172 static UINT
msi_dialog_send_event( msi_dialog
*dialog
, LPCWSTR event
, LPCWSTR arg
)
3174 LPWSTR event_fmt
= NULL
, arg_fmt
= NULL
;
3176 TRACE("Sending control event %s %s\n", debugstr_w(event
), debugstr_w(arg
));
3178 deformat_string( dialog
->package
, event
, &event_fmt
);
3179 deformat_string( dialog
->package
, arg
, &arg_fmt
);
3181 dialog
->event_handler( dialog
->package
, event_fmt
, arg_fmt
, dialog
);
3183 msi_free( event_fmt
);
3184 msi_free( arg_fmt
);
3186 return ERROR_SUCCESS
;
3189 static UINT
msi_dialog_set_property( msi_dialog
*dialog
, LPCWSTR event
, LPCWSTR arg
)
3191 static const WCHAR szNullArg
[] = { '{','}',0 };
3192 LPWSTR p
, prop
, arg_fmt
= NULL
;
3195 len
= strlenW(event
);
3196 prop
= msi_alloc( len
*sizeof(WCHAR
));
3197 strcpyW( prop
, &event
[1] );
3198 p
= strchrW( prop
, ']' );
3199 if( p
&& (p
[1] == 0 || p
[1] == ' ') )
3202 if( strcmpW( szNullArg
, arg
) )
3203 deformat_string( dialog
->package
, arg
, &arg_fmt
);
3204 MSI_SetPropertyW( dialog
->package
, prop
, arg_fmt
);
3205 msi_dialog_update_controls( dialog
, prop
);
3206 msi_free( arg_fmt
);
3209 ERR("Badly formatted property string - what happens?\n");
3211 return ERROR_SUCCESS
;
3214 static UINT
msi_dialog_control_event( MSIRECORD
*rec
, LPVOID param
)
3216 msi_dialog
*dialog
= param
;
3217 LPCWSTR condition
, event
, arg
;
3220 condition
= MSI_RecordGetString( rec
, 5 );
3221 r
= MSI_EvaluateConditionW( dialog
->package
, condition
);
3222 if( r
== MSICONDITION_TRUE
|| r
== MSICONDITION_NONE
)
3224 event
= MSI_RecordGetString( rec
, 3 );
3225 arg
= MSI_RecordGetString( rec
, 4 );
3226 if( event
[0] == '[' )
3227 msi_dialog_set_property( dialog
, event
, arg
);
3229 msi_dialog_send_event( dialog
, event
, arg
);
3232 return ERROR_SUCCESS
;
3241 static UINT
add_rec_to_list( MSIRECORD
*rec
, LPVOID param
)
3243 struct rec_list
*add_rec
;
3244 struct list
*records
= param
;
3246 msiobj_addref( &rec
->hdr
);
3248 add_rec
= msi_alloc( sizeof( *add_rec
) );
3251 msiobj_release( &rec
->hdr
);
3252 return ERROR_OUTOFMEMORY
;
3256 list_add_tail( records
, &add_rec
->entry
);
3257 return ERROR_SUCCESS
;
3260 static inline void remove_rec_from_list( struct rec_list
*rec_entry
)
3262 msiobj_release( &rec_entry
->rec
->hdr
);
3263 list_remove( &rec_entry
->entry
);
3264 msi_free( rec_entry
);
3267 static UINT
msi_dialog_button_handler( msi_dialog
*dialog
,
3268 msi_control
*control
, WPARAM param
)
3270 static const WCHAR query
[] = {
3271 'S','E','L','E','C','T',' ','*',' ',
3272 'F','R','O','M',' ','C','o','n','t','r','o','l','E','v','e','n','t',' ',
3273 'W','H','E','R','E',' ',
3274 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',' ',
3276 '`','C','o','n','t','r','o','l','_','`',' ','=',' ','\'','%','s','\'',' ',
3277 'O','R','D','E','R',' ','B','Y',' ','`','O','r','d','e','r','i','n','g','`',0
3279 MSIQUERY
*view
= NULL
;
3280 struct rec_list
*rec_entry
, *next
;
3284 if( HIWORD(param
) != BN_CLICKED
)
3285 return ERROR_SUCCESS
;
3287 list_init( &events
);
3289 r
= MSI_OpenQuery( dialog
->package
->db
, &view
, query
,
3290 dialog
->name
, control
->name
);
3291 if( r
!= ERROR_SUCCESS
)
3293 ERR("query failed\n");
3297 r
= MSI_IterateRecords( view
, 0, add_rec_to_list
, &events
);
3298 msiobj_release( &view
->hdr
);
3299 if (r
!= ERROR_SUCCESS
)
3302 /* handle all SetProperty events first */
3303 LIST_FOR_EACH_ENTRY_SAFE( rec_entry
, next
, &events
, struct rec_list
, entry
)
3305 LPCWSTR event
= MSI_RecordGetString( rec_entry
->rec
, 3 );
3307 if ( event
[0] != '[' )
3310 r
= msi_dialog_control_event( rec_entry
->rec
, dialog
);
3311 remove_rec_from_list( rec_entry
);
3313 if ( r
!= ERROR_SUCCESS
)
3317 /* handle all other events */
3318 LIST_FOR_EACH_ENTRY_SAFE( rec_entry
, next
, &events
, struct rec_list
, entry
)
3320 r
= msi_dialog_control_event( rec_entry
->rec
, dialog
);
3321 remove_rec_from_list( rec_entry
);
3323 if ( r
!= ERROR_SUCCESS
)
3328 LIST_FOR_EACH_ENTRY_SAFE( rec_entry
, next
, &events
, struct rec_list
, entry
)
3330 remove_rec_from_list( rec_entry
);
3336 static UINT
msi_dialog_get_checkbox_state( msi_dialog
*dialog
,
3337 msi_control
*control
)
3339 WCHAR state
[2] = { 0 };
3342 MSI_GetPropertyW( dialog
->package
, control
->property
, state
, &sz
);
3343 return state
[0] ? 1 : 0;
3346 static void msi_dialog_set_checkbox_state( msi_dialog
*dialog
,
3347 msi_control
*control
, UINT state
)
3349 static const WCHAR szState
[] = { '1', 0 };
3352 /* if uncheck then the property is set to NULL */
3355 MSI_SetPropertyW( dialog
->package
, control
->property
, NULL
);
3359 /* check for a custom state */
3360 if (control
->value
&& control
->value
[0])
3361 val
= control
->value
;
3365 MSI_SetPropertyW( dialog
->package
, control
->property
, val
);
3368 static void msi_dialog_checkbox_sync_state( msi_dialog
*dialog
,
3369 msi_control
*control
)
3373 state
= msi_dialog_get_checkbox_state( dialog
, control
);
3374 SendMessageW( control
->hwnd
, BM_SETCHECK
,
3375 state
? BST_CHECKED
: BST_UNCHECKED
, 0 );
3378 static UINT
msi_dialog_checkbox_handler( msi_dialog
*dialog
,
3379 msi_control
*control
, WPARAM param
)
3383 if( HIWORD(param
) != BN_CLICKED
)
3384 return ERROR_SUCCESS
;
3386 TRACE("clicked checkbox %s, set %s\n", debugstr_w(control
->name
),
3387 debugstr_w(control
->property
));
3389 state
= msi_dialog_get_checkbox_state( dialog
, control
);
3390 state
= state
? 0 : 1;
3391 msi_dialog_set_checkbox_state( dialog
, control
, state
);
3392 msi_dialog_checkbox_sync_state( dialog
, control
);
3394 return msi_dialog_button_handler( dialog
, control
, param
);
3397 static UINT
msi_dialog_edit_handler( msi_dialog
*dialog
,
3398 msi_control
*control
, WPARAM param
)
3402 if( HIWORD(param
) != EN_CHANGE
)
3403 return ERROR_SUCCESS
;
3405 TRACE("edit %s contents changed, set %s\n", debugstr_w(control
->name
),
3406 debugstr_w(control
->property
));
3408 buf
= msi_get_window_text( control
->hwnd
);
3409 MSI_SetPropertyW( dialog
->package
, control
->property
, buf
);
3413 return ERROR_SUCCESS
;
3416 static UINT
msi_dialog_radiogroup_handler( msi_dialog
*dialog
,
3417 msi_control
*control
, WPARAM param
)
3419 if( HIWORD(param
) != BN_CLICKED
)
3420 return ERROR_SUCCESS
;
3422 TRACE("clicked radio button %s, set %s\n", debugstr_w(control
->name
),
3423 debugstr_w(control
->property
));
3425 MSI_SetPropertyW( dialog
->package
, control
->property
, control
->name
);
3427 return msi_dialog_button_handler( dialog
, control
, param
);
3430 static LRESULT
msi_dialog_oncommand( msi_dialog
*dialog
, WPARAM param
, HWND hwnd
)
3432 msi_control
*control
= NULL
;
3434 TRACE("%p %p %08lx\n", dialog
, hwnd
, param
);
3439 control
= msi_dialog_find_control( dialog
, dialog
->control_default
);
3441 case 2: /* escape */
3442 control
= msi_dialog_find_control( dialog
, dialog
->control_cancel
);
3445 control
= msi_dialog_find_control_by_hwnd( dialog
, hwnd
);
3450 if( control
->handler
)
3452 control
->handler( dialog
, control
, param
);
3453 msi_dialog_evaluate_control_conditions( dialog
);
3460 static LRESULT
msi_dialog_onnotify( msi_dialog
*dialog
, LPARAM param
)
3462 LPNMHDR nmhdr
= (LPNMHDR
) param
;
3463 msi_control
*control
= msi_dialog_find_control_by_hwnd( dialog
, nmhdr
->hwndFrom
);
3465 TRACE("%p %p\n", dialog
, nmhdr
->hwndFrom
);
3467 if ( control
&& control
->handler
)
3468 control
->handler( dialog
, control
, param
);
3473 static void msi_dialog_setfocus( msi_dialog
*dialog
)
3475 HWND hwnd
= dialog
->hWndFocus
;
3477 hwnd
= GetNextDlgTabItem( dialog
->hwnd
, hwnd
, TRUE
);
3478 hwnd
= GetNextDlgTabItem( dialog
->hwnd
, hwnd
, FALSE
);
3480 dialog
->hWndFocus
= hwnd
;
3483 static LRESULT WINAPI
MSIDialog_WndProc( HWND hwnd
, UINT msg
,
3484 WPARAM wParam
, LPARAM lParam
)
3486 msi_dialog
*dialog
= (LPVOID
) GetWindowLongPtrW( hwnd
, GWLP_USERDATA
);
3488 TRACE("0x%04x\n", msg
);
3493 dialog
->package
->center_x
= LOWORD(lParam
) + dialog
->size
.cx
/ 2.0;
3494 dialog
->package
->center_y
= HIWORD(lParam
) + dialog
->size
.cy
/ 2.0;
3498 return msi_dialog_oncreate( hwnd
, (LPCREATESTRUCTW
)lParam
);
3501 return msi_dialog_oncommand( dialog
, wParam
, (HWND
)lParam
);
3504 if( LOWORD(wParam
) == WA_INACTIVE
)
3505 dialog
->hWndFocus
= GetFocus();
3507 msi_dialog_setfocus( dialog
);
3511 msi_dialog_setfocus( dialog
);
3514 /* bounce back to our subclassed static control */
3515 case WM_CTLCOLORSTATIC
:
3516 return SendMessageW( (HWND
) lParam
, WM_CTLCOLORSTATIC
, wParam
, lParam
);
3519 dialog
->hwnd
= NULL
;
3522 return msi_dialog_onnotify( dialog
, lParam
);
3524 return DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
3527 static BOOL CALLBACK
msi_radioground_child_enum( HWND hWnd
, LPARAM lParam
)
3529 EnableWindow( hWnd
, lParam
);
3533 static LRESULT WINAPI
MSIRadioGroup_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
3535 WNDPROC oldproc
= (WNDPROC
) GetPropW(hWnd
, szButtonData
);
3538 TRACE("hWnd %p msg %04x wParam 0x%08lx lParam 0x%08lx\n", hWnd
, msg
, wParam
, lParam
);
3540 if (msg
== WM_COMMAND
) /* Forward notifications to dialog */
3541 SendMessageW(GetParent(hWnd
), msg
, wParam
, lParam
);
3543 r
= CallWindowProcW(oldproc
, hWnd
, msg
, wParam
, lParam
);
3545 /* make sure the radio buttons show as disabled if the parent is disabled */
3546 if (msg
== WM_ENABLE
)
3547 EnumChildWindows( hWnd
, msi_radioground_child_enum
, wParam
);
3552 static LRESULT WINAPI
MSIHiddenWindowProc( HWND hwnd
, UINT msg
,
3553 WPARAM wParam
, LPARAM lParam
)
3555 msi_dialog
*dialog
= (msi_dialog
*) lParam
;
3557 TRACE("%d %p\n", msg
, dialog
);
3561 case WM_MSI_DIALOG_CREATE
:
3562 return msi_dialog_run_message_loop( dialog
);
3563 case WM_MSI_DIALOG_DESTROY
:
3564 msi_dialog_destroy( dialog
);
3567 return DefWindowProcW( hwnd
, msg
, wParam
, lParam
);
3570 static BOOL
msi_dialog_register_class( void )
3574 ZeroMemory( &cls
, sizeof cls
);
3575 cls
.lpfnWndProc
= MSIDialog_WndProc
;
3576 cls
.hInstance
= NULL
;
3577 cls
.hIcon
= LoadIconW(0, (LPWSTR
)IDI_APPLICATION
);
3578 cls
.hCursor
= LoadCursorW(0, (LPWSTR
)IDC_ARROW
);
3579 cls
.hbrBackground
= (HBRUSH
)(COLOR_3DFACE
+ 1);
3580 cls
.lpszMenuName
= NULL
;
3581 cls
.lpszClassName
= szMsiDialogClass
;
3583 if( !RegisterClassW( &cls
) )
3586 cls
.lpfnWndProc
= MSIHiddenWindowProc
;
3587 cls
.lpszClassName
= szMsiHiddenWindow
;
3589 if( !RegisterClassW( &cls
) )
3592 uiThreadId
= GetCurrentThreadId();
3594 hMsiHiddenWindow
= CreateWindowW( szMsiHiddenWindow
, NULL
, WS_OVERLAPPED
,
3595 0, 0, 100, 100, NULL
, NULL
, NULL
, NULL
);
3596 if( !hMsiHiddenWindow
)
3602 /* functions that interface to other modules within MSI */
3604 msi_dialog
*msi_dialog_create( MSIPACKAGE
* package
,
3605 LPCWSTR szDialogName
, msi_dialog
*parent
,
3606 msi_dialog_event_handler event_handler
)
3608 MSIRECORD
*rec
= NULL
;
3611 TRACE("%p %s\n", package
, debugstr_w(szDialogName
));
3613 if (!hMsiHiddenWindow
)
3614 msi_dialog_register_class();
3616 /* allocate the structure for the dialog to use */
3617 dialog
= msi_alloc_zero( sizeof *dialog
+ sizeof(WCHAR
)*strlenW(szDialogName
) );
3620 strcpyW( dialog
->name
, szDialogName
);
3621 dialog
->parent
= parent
;
3622 msiobj_addref( &package
->hdr
);
3623 dialog
->package
= package
;
3624 dialog
->event_handler
= event_handler
;
3625 dialog
->finished
= 0;
3626 list_init( &dialog
->controls
);
3628 /* verify that the dialog exists */
3629 rec
= msi_get_dialog_record( dialog
);
3632 msiobj_release( &package
->hdr
);
3636 dialog
->attributes
= MSI_RecordGetInteger( rec
, 6 );
3637 dialog
->control_default
= strdupW( MSI_RecordGetString( rec
, 9 ) );
3638 dialog
->control_cancel
= strdupW( MSI_RecordGetString( rec
, 10 ) );
3639 msiobj_release( &rec
->hdr
);
3644 static void msi_process_pending_messages( HWND hdlg
)
3648 while( PeekMessageW( &msg
, 0, 0, 0, PM_REMOVE
) )
3650 if( hdlg
&& IsDialogMessageW( hdlg
, &msg
))
3652 TranslateMessage( &msg
);
3653 DispatchMessageW( &msg
);
3657 void msi_dialog_end_dialog( msi_dialog
*dialog
)
3659 TRACE("%p\n", dialog
);
3660 dialog
->finished
= 1;
3661 PostMessageW(dialog
->hwnd
, WM_NULL
, 0, 0);
3664 void msi_dialog_check_messages( HANDLE handle
)
3668 /* in threads other than the UI thread, block */
3669 if( uiThreadId
!= GetCurrentThreadId() )
3672 WaitForSingleObject( handle
, INFINITE
);
3676 /* there's two choices for the UI thread */
3679 msi_process_pending_messages( NULL
);
3685 * block here until somebody creates a new dialog or
3686 * the handle we're waiting on becomes ready
3688 r
= MsgWaitForMultipleObjects( 1, &handle
, 0, INFINITE
, QS_ALLINPUT
);
3689 if( r
== WAIT_OBJECT_0
)
3694 UINT
msi_dialog_run_message_loop( msi_dialog
*dialog
)
3699 if( uiThreadId
!= GetCurrentThreadId() )
3700 return SendMessageW( hMsiHiddenWindow
, WM_MSI_DIALOG_CREATE
, 0, (LPARAM
) dialog
);
3702 /* create the dialog window, don't show it yet */
3703 style
= WS_OVERLAPPED
;
3704 if( dialog
->attributes
& msidbDialogAttributesVisible
)
3705 style
|= WS_VISIBLE
;
3707 hwnd
= CreateWindowW( szMsiDialogClass
, dialog
->name
, style
,
3708 CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
,
3709 NULL
, NULL
, NULL
, dialog
);
3712 ERR("Failed to create dialog %s\n", debugstr_w( dialog
->name
));
3713 return ERROR_FUNCTION_FAILED
;
3716 ShowWindow( hwnd
, SW_SHOW
);
3717 /* UpdateWindow( hwnd ); - and causes the transparent static controls not to paint */
3719 if( dialog
->attributes
& msidbDialogAttributesModal
)
3721 while( !dialog
->finished
)
3723 MsgWaitForMultipleObjects( 0, NULL
, 0, INFINITE
, QS_ALLINPUT
);
3724 msi_process_pending_messages( dialog
->hwnd
);
3728 return ERROR_IO_PENDING
;
3730 return ERROR_SUCCESS
;
3733 void msi_dialog_do_preview( msi_dialog
*dialog
)
3736 dialog
->attributes
|= msidbDialogAttributesVisible
;
3737 dialog
->attributes
&= ~msidbDialogAttributesModal
;
3738 msi_dialog_run_message_loop( dialog
);
3741 void msi_dialog_destroy( msi_dialog
*dialog
)
3743 if( uiThreadId
!= GetCurrentThreadId() )
3745 SendMessageW( hMsiHiddenWindow
, WM_MSI_DIALOG_DESTROY
, 0, (LPARAM
) dialog
);
3750 ShowWindow( dialog
->hwnd
, SW_HIDE
);
3753 DestroyWindow( dialog
->hwnd
);
3755 /* unsubscribe events */
3756 ControlEvent_CleanupDialogSubscriptions(dialog
->package
, dialog
->name
);
3758 /* destroy the list of controls */
3759 while( !list_empty( &dialog
->controls
) )
3763 t
= LIST_ENTRY( list_head( &dialog
->controls
),
3764 msi_control
, entry
);
3765 msi_destroy_control( t
);
3768 /* destroy the list of fonts */
3769 while( dialog
->font_list
)
3771 msi_font
*t
= dialog
->font_list
;
3772 dialog
->font_list
= t
->next
;
3773 DeleteObject( t
->hfont
);
3776 msi_free( dialog
->default_font
);
3778 msi_free( dialog
->control_default
);
3779 msi_free( dialog
->control_cancel
);
3780 msiobj_release( &dialog
->package
->hdr
);
3781 dialog
->package
= NULL
;
3785 void msi_dialog_unregister_class( void )
3787 DestroyWindow( hMsiHiddenWindow
);
3788 hMsiHiddenWindow
= NULL
;
3789 UnregisterClassW( szMsiDialogClass
, NULL
);
3790 UnregisterClassW( szMsiHiddenWindow
, NULL
);
3794 static UINT
error_dialog_handler(MSIPACKAGE
*package
, LPCWSTR event
,
3795 LPCWSTR argument
, msi_dialog
* dialog
)
3797 static const WCHAR end_dialog
[] = {'E','n','d','D','i','a','l','o','g',0};
3798 static const WCHAR error_abort
[] = {'E','r','r','o','r','A','b','o','r','t',0};
3799 static const WCHAR error_cancel
[] = {'E','r','r','o','r','C','a','n','c','e','l',0};
3800 static const WCHAR error_no
[] = {'E','r','r','o','r','N','o',0};
3801 static const WCHAR result_prop
[] = {
3802 'M','S','I','E','r','r','o','r','D','i','a','l','o','g','R','e','s','u','l','t',0
3805 if ( lstrcmpW( event
, end_dialog
) )
3806 return ERROR_SUCCESS
;
3808 if ( !lstrcmpW( argument
, error_abort
) || !lstrcmpW( argument
, error_cancel
) ||
3809 !lstrcmpW( argument
, error_no
) )
3811 MSI_SetPropertyW( package
, result_prop
, error_abort
);
3814 ControlEvent_CleanupSubscriptions(package
);
3815 msi_dialog_end_dialog( dialog
);
3817 return ERROR_SUCCESS
;
3820 static UINT
msi_error_dialog_set_error( MSIPACKAGE
*package
, LPWSTR error_dialog
, LPWSTR error
)
3824 static const WCHAR update
[] =
3825 {'U','P','D','A','T','E',' ','`','C','o','n','t','r','o','l','`',' ',
3826 'S','E','T',' ','`','T','e','x','t','`',' ','=',' ','\'','%','s','\'',' ',
3827 'W','H','E','R','E', ' ','`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',' ',
3828 'A','N','D',' ','`','C','o','n','t','r','o','l','`',' ','=',' ',
3829 '\'','E','r','r','o','r','T','e','x','t','\'',0};
3831 row
= MSI_QueryGetRecord( package
->db
, update
, error
, error_dialog
);
3833 return ERROR_FUNCTION_FAILED
;
3835 msiobj_release(&row
->hdr
);
3836 return ERROR_SUCCESS
;
3839 UINT
msi_spawn_error_dialog( MSIPACKAGE
*package
, LPWSTR error_dialog
, LPWSTR error
)
3842 WCHAR result
[MAX_PATH
];
3843 UINT r
= ERROR_SUCCESS
;
3844 DWORD size
= MAX_PATH
;
3847 static const WCHAR pn_prop
[] = {'P','r','o','d','u','c','t','N','a','m','e',0};
3848 static const WCHAR title_fmt
[] = {'%','s',' ','W','a','r','n','i','n','g',0};
3849 static const WCHAR error_abort
[] = {'E','r','r','o','r','A','b','o','r','t',0};
3850 static const WCHAR result_prop
[] = {
3851 'M','S','I','E','r','r','o','r','D','i','a','l','o','g','R','e','s','u','l','t',0
3854 if ( (msi_get_property_int(package
, szUILevel
, 0) & INSTALLUILEVEL_MASK
) == INSTALLUILEVEL_NONE
)
3855 return ERROR_SUCCESS
;
3857 if ( !error_dialog
)
3859 LPWSTR product_name
= msi_dup_property( package
, pn_prop
);
3860 WCHAR title
[MAX_PATH
];
3862 sprintfW( title
, title_fmt
, product_name
);
3863 res
= MessageBoxW( NULL
, error
, title
, MB_OKCANCEL
| MB_ICONWARNING
);
3865 msi_free( product_name
);
3868 return ERROR_SUCCESS
;
3870 return ERROR_FUNCTION_FAILED
;
3873 r
= msi_error_dialog_set_error( package
, error_dialog
, error
);
3874 if ( r
!= ERROR_SUCCESS
)
3877 dialog
= msi_dialog_create( package
, error_dialog
, package
->dialog
,
3878 error_dialog_handler
);
3880 return ERROR_FUNCTION_FAILED
;
3882 dialog
->finished
= FALSE
;
3883 r
= msi_dialog_run_message_loop( dialog
);
3884 if ( r
!= ERROR_SUCCESS
)
3887 r
= MSI_GetPropertyW( package
, result_prop
, result
, &size
);
3888 if ( r
!= ERROR_SUCCESS
)
3891 if ( !lstrcmpW( result
, error_abort
) )
3892 r
= ERROR_FUNCTION_FAILED
;
3895 msi_dialog_destroy( dialog
);