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
41 #include "msiserver.h"
43 #include "wine/debug.h"
44 #include "wine/unicode.h"
46 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
;
70 BOOL progress_backwards
;
75 typedef struct msi_font_tag
87 msi_dialog_event_handler event_handler
;
97 LPWSTR control_default
;
98 LPWSTR control_cancel
;
102 typedef UINT (*msi_dialog_control_func
)( msi_dialog
*dialog
, MSIRECORD
*rec
);
103 struct control_handler
105 LPCWSTR control_type
;
106 msi_dialog_control_func func
;
115 } radio_button_group_descr
;
117 static const WCHAR szMsiDialogClass
[] = { 'M','s','i','D','i','a','l','o','g','C','l','o','s','e','C','l','a','s','s',0 };
118 static const WCHAR szMsiHiddenWindow
[] = { 'M','s','i','H','i','d','d','e','n','W','i','n','d','o','w',0 };
119 static const WCHAR szStatic
[] = { 'S','t','a','t','i','c',0 };
120 static const WCHAR szButton
[] = { 'B','U','T','T','O','N', 0 };
121 static const WCHAR szButtonData
[] = { 'M','S','I','D','A','T','A',0 };
122 static const WCHAR szProgress
[] = { 'P','r','o','g','r','e','s','s',0 };
123 static const WCHAR szText
[] = { 'T','e','x','t',0 };
124 static const WCHAR szPushButton
[] = { 'P','u','s','h','B','u','t','t','o','n',0 };
125 static const WCHAR szLine
[] = { 'L','i','n','e',0 };
126 static const WCHAR szBitmap
[] = { 'B','i','t','m','a','p',0 };
127 static const WCHAR szCheckBox
[] = { 'C','h','e','c','k','B','o','x',0 };
128 static const WCHAR szScrollableText
[] = { 'S','c','r','o','l','l','a','b','l','e','T','e','x','t',0 };
129 static const WCHAR szComboBox
[] = { 'C','o','m','b','o','B','o','x',0 };
130 static const WCHAR szEdit
[] = { 'E','d','i','t',0 };
131 static const WCHAR szMaskedEdit
[] = { 'M','a','s','k','e','d','E','d','i','t',0 };
132 static const WCHAR szPathEdit
[] = { 'P','a','t','h','E','d','i','t',0 };
133 static const WCHAR szProgressBar
[] = { 'P','r','o','g','r','e','s','s','B','a','r',0 };
134 static const WCHAR szSetProgress
[] = { 'S','e','t','P','r','o','g','r','e','s','s',0 };
135 static const WCHAR szRadioButtonGroup
[] = { 'R','a','d','i','o','B','u','t','t','o','n','G','r','o','u','p',0 };
136 static const WCHAR szIcon
[] = { 'I','c','o','n',0 };
137 static const WCHAR szSelectionTree
[] = { 'S','e','l','e','c','t','i','o','n','T','r','e','e',0 };
138 static const WCHAR szGroupBox
[] = { 'G','r','o','u','p','B','o','x',0 };
139 static const WCHAR szListBox
[] = { 'L','i','s','t','B','o','x',0 };
140 static const WCHAR szDirectoryCombo
[] = { 'D','i','r','e','c','t','o','r','y','C','o','m','b','o',0 };
141 static const WCHAR szDirectoryList
[] = { 'D','i','r','e','c','t','o','r','y','L','i','s','t',0 };
142 static const WCHAR szVolumeCostList
[] = { 'V','o','l','u','m','e','C','o','s','t','L','i','s','t',0 };
143 static const WCHAR szVolumeSelectCombo
[] = { 'V','o','l','u','m','e','S','e','l','e','c','t','C','o','m','b','o',0 };
144 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};
145 static const WCHAR szSelectionPath
[] = {'S','e','l','e','c','t','i','o','n','P','a','t','h',0};
146 static const WCHAR szProperty
[] = {'P','r','o','p','e','r','t','y',0};
148 /* dialog sequencing */
150 #define WM_MSI_DIALOG_CREATE (WM_USER+0x100)
151 #define WM_MSI_DIALOG_DESTROY (WM_USER+0x101)
153 #define USER_INSTALLSTATE_ALL 0x1000
155 static DWORD uiThreadId
;
156 static HWND hMsiHiddenWindow
;
158 static LPWSTR
msi_get_window_text( HWND hwnd
)
164 buf
= msi_alloc( sz
*sizeof(WCHAR
) );
167 r
= GetWindowTextW( hwnd
, buf
, sz
);
171 buf
= msi_realloc( buf
, sz
*sizeof(WCHAR
) );
177 static INT
msi_dialog_scale_unit( msi_dialog
*dialog
, INT val
)
179 return MulDiv( val
, dialog
->scale
, 12 );
182 static msi_control
*msi_dialog_find_control( msi_dialog
*dialog
, LPCWSTR name
)
184 msi_control
*control
;
190 LIST_FOR_EACH_ENTRY( control
, &dialog
->controls
, msi_control
, entry
)
191 if( !strcmpW( control
->name
, name
) ) /* FIXME: case sensitive? */
196 static msi_control
*msi_dialog_find_control_by_type( msi_dialog
*dialog
, LPCWSTR type
)
198 msi_control
*control
;
204 LIST_FOR_EACH_ENTRY( control
, &dialog
->controls
, msi_control
, entry
)
205 if( !strcmpW( control
->type
, type
) ) /* FIXME: case sensitive? */
210 static msi_control
*msi_dialog_find_control_by_hwnd( msi_dialog
*dialog
, HWND hwnd
)
212 msi_control
*control
;
216 LIST_FOR_EACH_ENTRY( control
, &dialog
->controls
, msi_control
, entry
)
217 if( hwnd
== control
->hwnd
)
222 static LPWSTR
msi_get_deformatted_field( MSIPACKAGE
*package
, MSIRECORD
*rec
, int field
)
224 LPCWSTR str
= MSI_RecordGetString( rec
, field
);
228 deformat_string( package
, str
, &ret
);
232 static LPWSTR
msi_dialog_dup_property( msi_dialog
*dialog
, LPCWSTR property
, BOOL indirect
)
240 prop
= msi_dup_property( dialog
->package
->db
, property
);
243 prop
= strdupW( property
);
248 msi_dialog
*msi_dialog_get_parent( msi_dialog
*dialog
)
250 return dialog
->parent
;
253 LPWSTR
msi_dialog_get_name( msi_dialog
*dialog
)
259 * msi_dialog_get_style
261 * Extract the {\style} string from the front of the text to display and
262 * update the pointer. Only the last style in a list is applied.
264 static LPWSTR
msi_dialog_get_style( LPCWSTR p
, LPCWSTR
*rest
)
275 while ((first
= strchrW( p
, '{' )) && (q
= strchrW( first
+ 1, '}' )))
278 if( *p
!= '\\' && *p
!= '&' )
281 /* little bit of sanity checking to stop us getting confused with RTF */
282 for( i
=++p
; i
<q
; i
++ )
283 if( *i
== '}' || *i
== '\\' )
293 ret
= msi_alloc( len
*sizeof(WCHAR
) );
296 memcpy( ret
, p
, len
*sizeof(WCHAR
) );
301 static UINT
msi_dialog_add_font( MSIRECORD
*rec
, LPVOID param
)
303 msi_dialog
*dialog
= param
;
310 /* create a font and add it to the list */
311 name
= MSI_RecordGetString( rec
, 1 );
312 font
= msi_alloc( sizeof *font
+ strlenW( name
)*sizeof (WCHAR
) );
313 strcpyW( font
->name
, name
);
314 list_add_head( &dialog
->fonts
, &font
->entry
);
316 font
->color
= MSI_RecordGetInteger( rec
, 4 );
318 memset( &lf
, 0, sizeof lf
);
319 face
= MSI_RecordGetString( rec
, 2 );
320 lf
.lfHeight
= MSI_RecordGetInteger( rec
, 3 );
321 style
= MSI_RecordGetInteger( rec
, 5 );
322 if( style
& msidbTextStyleStyleBitsBold
)
323 lf
.lfWeight
= FW_BOLD
;
324 if( style
& msidbTextStyleStyleBitsItalic
)
326 if( style
& msidbTextStyleStyleBitsUnderline
)
327 lf
.lfUnderline
= TRUE
;
328 if( style
& msidbTextStyleStyleBitsStrike
)
329 lf
.lfStrikeOut
= TRUE
;
330 lstrcpynW( lf
.lfFaceName
, face
, LF_FACESIZE
);
332 /* adjust the height */
333 hdc
= GetDC( dialog
->hwnd
);
336 lf
.lfHeight
= -MulDiv(lf
.lfHeight
, GetDeviceCaps(hdc
, LOGPIXELSY
), 72);
337 ReleaseDC( dialog
->hwnd
, hdc
);
340 font
->hfont
= CreateFontIndirectW( &lf
);
342 TRACE("Adding font style %s\n", debugstr_w(font
->name
) );
344 return ERROR_SUCCESS
;
347 static msi_font
*msi_dialog_find_font( msi_dialog
*dialog
, LPCWSTR name
)
349 msi_font
*font
= NULL
;
351 LIST_FOR_EACH_ENTRY( font
, &dialog
->fonts
, msi_font
, entry
)
352 if( !strcmpW( font
->name
, name
) ) /* FIXME: case sensitive? */
358 static UINT
msi_dialog_set_font( msi_dialog
*dialog
, HWND hwnd
, LPCWSTR name
)
362 font
= msi_dialog_find_font( dialog
, name
);
364 SendMessageW( hwnd
, WM_SETFONT
, (WPARAM
) font
->hfont
, TRUE
);
366 ERR("No font entry for %s\n", debugstr_w(name
));
367 return ERROR_SUCCESS
;
370 static UINT
msi_dialog_build_font_list( msi_dialog
*dialog
)
372 static const WCHAR query
[] = {
373 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
374 '`','T','e','x','t','S','t','y','l','e','`',0};
378 TRACE("dialog %p\n", dialog
);
380 r
= MSI_OpenQuery( dialog
->package
->db
, &view
, query
);
381 if( r
!= ERROR_SUCCESS
)
384 r
= MSI_IterateRecords( view
, NULL
, msi_dialog_add_font
, dialog
);
385 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;
434 control
->progress_backwards
= FALSE
;
436 x
= MSI_RecordGetInteger( rec
, 4 );
437 y
= MSI_RecordGetInteger( rec
, 5 );
438 width
= MSI_RecordGetInteger( rec
, 6 );
439 height
= MSI_RecordGetInteger( rec
, 7 );
441 x
= msi_dialog_scale_unit( dialog
, x
);
442 y
= msi_dialog_scale_unit( dialog
, y
);
443 width
= msi_dialog_scale_unit( dialog
, width
);
444 height
= msi_dialog_scale_unit( dialog
, height
);
448 deformat_string( dialog
->package
, text
, &title_font
);
449 font
= msi_dialog_get_style( title_font
, &title
);
452 control
->hwnd
= CreateWindowExW( exstyle
, szCls
, title
, style
,
453 x
, y
, width
, height
, parent
, NULL
, NULL
, NULL
);
455 TRACE("Dialog %s control %s hwnd %p\n",
456 debugstr_w(dialog
->name
), debugstr_w(text
), control
->hwnd
);
458 msi_dialog_set_font( dialog
, control
->hwnd
,
459 font
? font
: dialog
->default_font
);
461 msi_free( title_font
);
467 static LPWSTR
msi_dialog_get_uitext( msi_dialog
*dialog
, LPCWSTR key
)
472 static const WCHAR query
[] = {
473 's','e','l','e','c','t',' ','*',' ',
474 'f','r','o','m',' ','`','U','I','T','e','x','t','`',' ',
475 'w','h','e','r','e',' ','`','K','e','y','`',' ','=',' ','\'','%','s','\'',0
478 rec
= MSI_QueryGetRecord( dialog
->package
->db
, query
, key
);
479 if (!rec
) return NULL
;
480 text
= strdupW( MSI_RecordGetString( rec
, 2 ) );
481 msiobj_release( &rec
->hdr
);
485 static MSIRECORD
*msi_get_binary_record( MSIDATABASE
*db
, LPCWSTR name
)
487 static const WCHAR query
[] = {
488 's','e','l','e','c','t',' ','*',' ',
489 'f','r','o','m',' ','B','i','n','a','r','y',' ',
490 'w','h','e','r','e',' ',
491 '`','N','a','m','e','`',' ','=',' ','\'','%','s','\'',0
494 return MSI_QueryGetRecord( db
, query
, name
);
497 static LPWSTR
msi_create_tmp_path(void)
503 r
= GetTempPathW( MAX_PATH
, tmp
);
506 len
= lstrlenW( tmp
) + 20;
507 path
= msi_alloc( len
* sizeof (WCHAR
) );
510 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 ( control
->property
&& !strcmpW( control
->property
, property
) && control
->update
)
580 control
->update( dialog
, control
);
584 static void msi_dialog_set_property( MSIPACKAGE
*package
, LPCWSTR property
, LPCWSTR value
)
586 UINT r
= msi_set_property( package
->db
, property
, value
);
587 if (r
== ERROR_SUCCESS
&& !strcmpW( property
, szSourceDir
))
588 msi_reset_folders( package
, TRUE
);
591 static MSIFEATURE
*msi_seltree_feature_from_item( HWND hwnd
, HTREEITEM hItem
)
595 /* get the feature from the item */
596 memset( &tvi
, 0, sizeof tvi
);
598 tvi
.mask
= TVIF_PARAM
| TVIF_HANDLE
;
599 SendMessageW( hwnd
, TVM_GETITEMW
, 0, (LPARAM
)&tvi
);
600 return (MSIFEATURE
*)tvi
.lParam
;
603 struct msi_selection_tree_info
611 static MSIFEATURE
*msi_seltree_get_selected_feature( msi_control
*control
)
613 struct msi_selection_tree_info
*info
= GetPropW( control
->hwnd
, szButtonData
);
614 return msi_seltree_feature_from_item( control
->hwnd
, info
->selected
);
617 /* called from the Control Event subscription code */
618 void msi_dialog_handle_event( msi_dialog
* dialog
, LPCWSTR control
,
619 LPCWSTR attribute
, MSIRECORD
*rec
)
622 LPCWSTR font_text
, text
= NULL
;
625 ctrl
= msi_dialog_find_control( dialog
, control
);
628 if( !strcmpW( attribute
, szText
) )
630 font_text
= MSI_RecordGetString( rec
, 1 );
631 font
= msi_dialog_get_style( font_text
, &text
);
632 if (!text
) text
= szEmpty
;
633 SetWindowTextW( ctrl
->hwnd
, text
);
635 msi_dialog_check_messages( NULL
);
637 else if( !strcmpW( attribute
, szProgress
) )
639 DWORD func
, val1
, val2
, units
;
641 func
= MSI_RecordGetInteger( rec
, 1 );
642 val1
= MSI_RecordGetInteger( rec
, 2 );
643 val2
= MSI_RecordGetInteger( rec
, 3 );
645 TRACE("progress: func %u val1 %u val2 %u\n", func
, val1
, val2
);
651 SendMessageW( ctrl
->hwnd
, PBM_SETRANGE
, 0, MAKELPARAM(0,100) );
654 ctrl
->progress_max
= units
? units
: 100;
655 ctrl
->progress_current
= units
;
656 ctrl
->progress_backwards
= TRUE
;
657 SendMessageW( ctrl
->hwnd
, PBM_SETPOS
, 100, 0 );
661 ctrl
->progress_max
= units
? units
: 100;
662 ctrl
->progress_current
= 0;
663 ctrl
->progress_backwards
= FALSE
;
664 SendMessageW( ctrl
->hwnd
, PBM_SETPOS
, 0, 0 );
667 case 1: /* action data increment */
668 if (val2
) dialog
->package
->action_progress_increment
= val1
;
669 else dialog
->package
->action_progress_increment
= 0;
672 if (ctrl
->progress_backwards
)
674 if (units
>= ctrl
->progress_current
) ctrl
->progress_current
-= units
;
675 else ctrl
->progress_current
= 0;
679 if (ctrl
->progress_current
+ units
< ctrl
->progress_max
) ctrl
->progress_current
+= units
;
680 else ctrl
->progress_current
= ctrl
->progress_max
;
682 SendMessageW( ctrl
->hwnd
, PBM_SETPOS
, MulDiv(100, ctrl
->progress_current
, ctrl
->progress_max
), 0 );
685 ctrl
->progress_max
+= units
;
688 FIXME("Unknown progress message %u\n", func
);
692 else if ( !strcmpW( attribute
, szProperty
) )
694 MSIFEATURE
*feature
= msi_seltree_get_selected_feature( ctrl
);
695 msi_dialog_set_property( dialog
->package
, ctrl
->property
, feature
->Directory
);
697 else if ( !strcmpW( attribute
, szSelectionPath
) )
699 BOOL indirect
= ctrl
->attributes
& msidbControlAttributesIndirect
;
700 LPWSTR path
= msi_dialog_dup_property( dialog
, ctrl
->property
, indirect
);
702 SetWindowTextW( ctrl
->hwnd
, path
);
707 FIXME("Attribute %s not being set\n", debugstr_w(attribute
));
712 static void msi_dialog_map_events(msi_dialog
* dialog
, LPCWSTR control
)
714 static const WCHAR Query
[] = {
715 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
716 '`','E','v','e','n','t','M','a','p','p','i','n','g','`',' ',
717 'W','H','E','R','E',' ',
718 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',' ',
720 '`','C','o','n','t','r','o','l','_','`',' ','=',' ','\'','%','s','\'',0
723 LPCWSTR event
, attribute
;
725 row
= MSI_QueryGetRecord( dialog
->package
->db
, Query
, dialog
->name
, control
);
729 event
= MSI_RecordGetString( row
, 3 );
730 attribute
= MSI_RecordGetString( row
, 4 );
731 ControlEvent_SubscribeToEvent( dialog
->package
, dialog
, event
, control
, attribute
);
732 msiobj_release( &row
->hdr
);
735 /* everything except radio buttons */
736 static msi_control
*msi_dialog_add_control( msi_dialog
*dialog
,
737 MSIRECORD
*rec
, LPCWSTR szCls
, DWORD style
)
743 name
= MSI_RecordGetString( rec
, 2 );
744 attributes
= MSI_RecordGetInteger( rec
, 8 );
745 text
= MSI_RecordGetString( rec
, 10 );
747 TRACE("%s, %s, %08x, %s, %08x\n", debugstr_w(szCls
), debugstr_w(name
),
748 attributes
, debugstr_w(text
), style
);
750 if( attributes
& msidbControlAttributesVisible
)
752 if( ~attributes
& msidbControlAttributesEnabled
)
753 style
|= WS_DISABLED
;
754 if( attributes
& msidbControlAttributesSunken
)
755 exstyle
|= WS_EX_CLIENTEDGE
;
757 msi_dialog_map_events(dialog
, name
);
759 return msi_dialog_create_window( dialog
, rec
, exstyle
, szCls
, name
,
760 text
, style
, dialog
->hwnd
);
771 * we don't erase our own background,
772 * so we have to make sure that the parent window redraws first
774 static void msi_text_on_settext( HWND hWnd
)
779 hParent
= GetParent( hWnd
);
780 GetWindowRect( hWnd
, &rc
);
781 MapWindowPoints( NULL
, hParent
, (LPPOINT
) &rc
, 2 );
782 InvalidateRect( hParent
, &rc
, TRUE
);
785 static LRESULT WINAPI
786 MSIText_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
788 struct msi_text_info
*info
;
791 TRACE("%p %04x %08lx %08lx\n", hWnd
, msg
, wParam
, lParam
);
793 info
= GetPropW(hWnd
, szButtonData
);
795 if( msg
== WM_CTLCOLORSTATIC
&&
796 ( info
->attributes
& msidbControlAttributesTransparent
) )
798 SetBkMode( (HDC
)wParam
, TRANSPARENT
);
799 return (LRESULT
) GetStockObject(NULL_BRUSH
);
802 r
= CallWindowProcW(info
->oldproc
, hWnd
, msg
, wParam
, lParam
);
804 SetTextColor( (HDC
)wParam
, info
->font
->color
);
809 msi_text_on_settext( hWnd
);
813 RemovePropW( hWnd
, szButtonData
);
820 static UINT
msi_dialog_text_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
822 msi_control
*control
;
823 struct msi_text_info
*info
;
824 LPCWSTR text
, ptr
, prop
, control_name
;
827 TRACE("%p %p\n", dialog
, rec
);
829 control
= msi_dialog_add_control( dialog
, rec
, szStatic
, SS_LEFT
| WS_GROUP
);
831 return ERROR_FUNCTION_FAILED
;
833 info
= msi_alloc( sizeof *info
);
835 return ERROR_SUCCESS
;
837 control_name
= MSI_RecordGetString( rec
, 2 );
838 control
->attributes
= MSI_RecordGetInteger( rec
, 8 );
839 prop
= MSI_RecordGetString( rec
, 9 );
840 control
->property
= msi_dialog_dup_property( dialog
, prop
, FALSE
);
842 text
= MSI_RecordGetString( rec
, 10 );
843 font_name
= msi_dialog_get_style( text
, &ptr
);
844 info
->font
= ( font_name
) ? msi_dialog_find_font( dialog
, font_name
) : NULL
;
845 msi_free( font_name
);
847 info
->attributes
= MSI_RecordGetInteger( rec
, 8 );
848 if( info
->attributes
& msidbControlAttributesTransparent
)
849 SetWindowLongPtrW( control
->hwnd
, GWL_EXSTYLE
, WS_EX_TRANSPARENT
);
851 info
->oldproc
= (WNDPROC
) SetWindowLongPtrW( control
->hwnd
, GWLP_WNDPROC
,
852 (LONG_PTR
)MSIText_WndProc
);
853 SetPropW( control
->hwnd
, szButtonData
, info
);
855 ControlEvent_SubscribeToEvent( dialog
->package
, dialog
,
856 szSelectionPath
, control_name
, szSelectionPath
);
858 return ERROR_SUCCESS
;
861 /* strip any leading text style label from text field */
862 static WCHAR
*msi_get_binary_name( MSIPACKAGE
*package
, MSIRECORD
*rec
)
866 text
= msi_get_deformatted_field( package
, rec
, 10 );
871 while (*p
&& *p
!= '{') p
++;
872 if (!*p
++) return text
;
874 while (*p
&& *p
!= '}') p
++;
875 if (!*p
++) return text
;
882 static UINT
msi_dialog_set_property_event( msi_dialog
*dialog
, LPCWSTR event
, LPCWSTR arg
)
884 static const WCHAR szNullArg
[] = {'{','}',0};
885 LPWSTR p
, prop
, arg_fmt
= NULL
;
888 len
= strlenW( event
);
889 prop
= msi_alloc( len
* sizeof(WCHAR
) );
890 strcpyW( prop
, &event
[1] );
891 p
= strchrW( prop
, ']' );
892 if (p
&& (p
[1] == 0 || p
[1] == ' '))
895 if (strcmpW( szNullArg
, arg
))
896 deformat_string( dialog
->package
, arg
, &arg_fmt
);
897 msi_dialog_set_property( dialog
->package
, prop
, arg_fmt
);
898 msi_dialog_update_controls( dialog
, prop
);
901 else ERR("Badly formatted property string - what happens?\n");
903 return ERROR_SUCCESS
;
906 static UINT
msi_dialog_send_event( msi_dialog
*dialog
, LPCWSTR event
, LPCWSTR arg
)
908 LPWSTR event_fmt
= NULL
, arg_fmt
= NULL
;
910 TRACE("Sending control event %s %s\n", debugstr_w(event
), debugstr_w(arg
));
912 deformat_string( dialog
->package
, event
, &event_fmt
);
913 deformat_string( dialog
->package
, arg
, &arg_fmt
);
915 dialog
->event_handler( dialog
->package
, event_fmt
, arg_fmt
, dialog
);
917 msi_free( event_fmt
);
920 return ERROR_SUCCESS
;
923 static UINT
msi_dialog_control_event( MSIRECORD
*rec
, LPVOID param
)
925 msi_dialog
*dialog
= param
;
926 LPCWSTR condition
, event
, arg
;
929 condition
= MSI_RecordGetString( rec
, 5 );
930 r
= MSI_EvaluateConditionW( dialog
->package
, condition
);
931 if (r
== MSICONDITION_TRUE
|| r
== MSICONDITION_NONE
)
933 event
= MSI_RecordGetString( rec
, 3 );
934 arg
= MSI_RecordGetString( rec
, 4 );
936 msi_dialog_set_property_event( dialog
, event
, arg
);
938 msi_dialog_send_event( dialog
, event
, arg
);
940 return ERROR_SUCCESS
;
943 static UINT
msi_dialog_button_handler( msi_dialog
*dialog
, msi_control
*control
, WPARAM param
)
945 static const WCHAR query
[] = {
946 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
947 'C','o','n','t','r','o','l','E','v','e','n','t',' ','W','H','E','R','E',' ',
948 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',' ','A','N','D',' ',
949 '`','C','o','n','t','r','o','l','_','`',' ','=',' ','\'','%','s','\'',' ',
950 'O','R','D','E','R',' ','B','Y',' ','`','O','r','d','e','r','i','n','g','`',0};
954 if (HIWORD(param
) != BN_CLICKED
)
955 return ERROR_SUCCESS
;
957 r
= MSI_OpenQuery( dialog
->package
->db
, &view
, query
, dialog
->name
, control
->name
);
958 if (r
!= ERROR_SUCCESS
)
960 ERR("query failed\n");
961 return ERROR_SUCCESS
;
963 r
= MSI_IterateRecords( view
, 0, msi_dialog_control_event
, dialog
);
964 msiobj_release( &view
->hdr
);
968 static UINT
msi_dialog_button_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
970 msi_control
*control
;
971 UINT attributes
, style
;
973 TRACE("%p %p\n", dialog
, rec
);
976 attributes
= MSI_RecordGetInteger( rec
, 8 );
977 if( attributes
& msidbControlAttributesIcon
)
980 control
= msi_dialog_add_control( dialog
, rec
, szButton
, style
);
982 return ERROR_FUNCTION_FAILED
;
984 control
->handler
= msi_dialog_button_handler
;
986 if (attributes
& msidbControlAttributesIcon
)
989 LPWSTR name
= msi_get_binary_name( dialog
->package
, rec
);
990 control
->hIcon
= msi_load_icon( dialog
->package
->db
, name
, attributes
);
993 SendMessageW( control
->hwnd
, BM_SETIMAGE
, IMAGE_ICON
, (LPARAM
) control
->hIcon
);
996 ERR("Failed to load icon %s\n", debugstr_w(name
));
1000 return ERROR_SUCCESS
;
1003 static LPWSTR
msi_get_checkbox_value( msi_dialog
*dialog
, LPCWSTR prop
)
1005 static const WCHAR query
[] = {
1006 'S','E','L','E','C','T',' ','*',' ',
1007 'F','R','O','M',' ','`','C','h','e','c','k','B','o','x','`',' ',
1008 'W','H','E','R','E',' ',
1009 '`','P','r','o','p','e','r','t','y','`',' ','=',' ',
1012 MSIRECORD
*rec
= NULL
;
1015 /* find if there is a value associated with the checkbox */
1016 rec
= MSI_QueryGetRecord( dialog
->package
->db
, query
, prop
);
1020 ret
= msi_get_deformatted_field( dialog
->package
, rec
, 2 );
1021 if( ret
&& !ret
[0] )
1026 msiobj_release( &rec
->hdr
);
1030 ret
= msi_dup_property( dialog
->package
->db
, prop
);
1031 if( ret
&& !ret
[0] )
1040 static UINT
msi_dialog_get_checkbox_state( msi_dialog
*dialog
, msi_control
*control
)
1042 WCHAR state
[2] = {0};
1045 msi_get_property( dialog
->package
->db
, control
->property
, state
, &sz
);
1046 return state
[0] ? 1 : 0;
1049 static void msi_dialog_set_checkbox_state( msi_dialog
*dialog
, msi_control
*control
, UINT state
)
1051 static const WCHAR szState
[] = {'1',0};
1054 /* if uncheck then the property is set to NULL */
1057 msi_dialog_set_property( dialog
->package
, control
->property
, NULL
);
1061 /* check for a custom state */
1062 if (control
->value
&& control
->value
[0])
1063 val
= control
->value
;
1067 msi_dialog_set_property( dialog
->package
, control
->property
, val
);
1070 static void msi_dialog_checkbox_sync_state( msi_dialog
*dialog
, msi_control
*control
)
1072 UINT state
= msi_dialog_get_checkbox_state( dialog
, control
);
1073 SendMessageW( control
->hwnd
, BM_SETCHECK
, state
? BST_CHECKED
: BST_UNCHECKED
, 0 );
1076 static UINT
msi_dialog_checkbox_handler( msi_dialog
*dialog
, msi_control
*control
, WPARAM param
)
1080 if (HIWORD(param
) != BN_CLICKED
)
1081 return ERROR_SUCCESS
;
1083 TRACE("clicked checkbox %s, set %s\n", debugstr_w(control
->name
), debugstr_w(control
->property
));
1085 state
= msi_dialog_get_checkbox_state( dialog
, control
);
1086 state
= state
? 0 : 1;
1087 msi_dialog_set_checkbox_state( dialog
, control
, state
);
1088 msi_dialog_checkbox_sync_state( dialog
, control
);
1090 return msi_dialog_button_handler( dialog
, control
, param
);
1093 static UINT
msi_dialog_checkbox_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1095 msi_control
*control
;
1098 TRACE("%p %p\n", dialog
, rec
);
1100 control
= msi_dialog_add_control( dialog
, rec
, szButton
, BS_CHECKBOX
| BS_MULTILINE
| WS_TABSTOP
);
1101 control
->handler
= msi_dialog_checkbox_handler
;
1102 control
->update
= msi_dialog_checkbox_sync_state
;
1103 prop
= MSI_RecordGetString( rec
, 9 );
1106 control
->property
= strdupW( prop
);
1107 control
->value
= msi_get_checkbox_value( dialog
, prop
);
1108 TRACE("control %s value %s\n", debugstr_w(control
->property
), debugstr_w(control
->value
));
1110 msi_dialog_checkbox_sync_state( dialog
, control
);
1111 return ERROR_SUCCESS
;
1114 static UINT
msi_dialog_line_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1118 DWORD style
, exstyle
= 0;
1119 DWORD x
, y
, width
, height
;
1120 msi_control
*control
;
1122 TRACE("%p %p\n", dialog
, rec
);
1124 style
= WS_CHILD
| SS_ETCHEDHORZ
| SS_SUNKEN
;
1126 name
= MSI_RecordGetString( rec
, 2 );
1127 attributes
= MSI_RecordGetInteger( rec
, 8 );
1129 if( attributes
& msidbControlAttributesVisible
)
1130 style
|= WS_VISIBLE
;
1131 if( ~attributes
& msidbControlAttributesEnabled
)
1132 style
|= WS_DISABLED
;
1133 if( attributes
& msidbControlAttributesSunken
)
1134 exstyle
|= WS_EX_CLIENTEDGE
;
1136 msi_dialog_map_events(dialog
, name
);
1138 control
= msi_alloc( sizeof(*control
) + strlenW(name
) * sizeof(WCHAR
) );
1140 return ERROR_OUTOFMEMORY
;
1142 strcpyW( control
->name
, name
);
1143 list_add_head( &dialog
->controls
, &control
->entry
);
1144 control
->handler
= NULL
;
1145 control
->property
= NULL
;
1146 control
->value
= NULL
;
1147 control
->hBitmap
= NULL
;
1148 control
->hIcon
= NULL
;
1149 control
->hDll
= NULL
;
1150 control
->tabnext
= strdupW( MSI_RecordGetString( rec
, 11) );
1151 control
->type
= strdupW( MSI_RecordGetString( rec
, 3 ) );
1152 control
->progress_current
= 0;
1153 control
->progress_max
= 100;
1154 control
->progress_backwards
= FALSE
;
1156 x
= MSI_RecordGetInteger( rec
, 4 );
1157 y
= MSI_RecordGetInteger( rec
, 5 );
1158 width
= MSI_RecordGetInteger( rec
, 6 );
1160 x
= msi_dialog_scale_unit( dialog
, x
);
1161 y
= msi_dialog_scale_unit( dialog
, y
);
1162 width
= msi_dialog_scale_unit( dialog
, width
);
1163 height
= 2; /* line is exactly 2 units in height */
1165 control
->hwnd
= CreateWindowExW( exstyle
, szStatic
, NULL
, style
,
1166 x
, y
, width
, height
, dialog
->hwnd
, NULL
, NULL
, NULL
);
1168 TRACE("Dialog %s control %s hwnd %p\n",
1169 debugstr_w(dialog
->name
), debugstr_w(name
), control
->hwnd
);
1171 return ERROR_SUCCESS
;
1174 /******************** Scroll Text ********************************************/
1176 struct msi_scrolltext_info
1179 msi_control
*control
;
1183 static LRESULT WINAPI
1184 MSIScrollText_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1186 struct msi_scrolltext_info
*info
;
1189 TRACE("%p %04x %08lx %08lx\n", hWnd
, msg
, wParam
, lParam
);
1191 info
= GetPropW( hWnd
, szButtonData
);
1193 r
= CallWindowProcW( info
->oldproc
, hWnd
, msg
, wParam
, lParam
);
1198 return DLGC_WANTARROWS
;
1201 RemovePropW( hWnd
, szButtonData
);
1204 /* native MSI sets a wait cursor here */
1205 msi_dialog_button_handler( info
->dialog
, info
->control
, BN_CLICKED
);
1211 struct msi_streamin_info
1218 static DWORD CALLBACK
1219 msi_richedit_stream_in( DWORD_PTR arg
, LPBYTE buffer
, LONG count
, LONG
*pcb
)
1221 struct msi_streamin_info
*info
= (struct msi_streamin_info
*) arg
;
1223 if( (count
+ info
->offset
) > info
->length
)
1224 count
= info
->length
- info
->offset
;
1225 memcpy( buffer
, &info
->string
[ info
->offset
], count
);
1227 info
->offset
+= count
;
1229 TRACE("%d/%d\n", info
->offset
, info
->length
);
1234 static void msi_scrolltext_add_text( msi_control
*control
, LPCWSTR text
)
1236 struct msi_streamin_info info
;
1239 info
.string
= strdupWtoA( text
);
1241 info
.length
= lstrlenA( info
.string
) + 1;
1243 es
.dwCookie
= (DWORD_PTR
) &info
;
1245 es
.pfnCallback
= msi_richedit_stream_in
;
1247 SendMessageW( control
->hwnd
, EM_STREAMIN
, SF_RTF
, (LPARAM
) &es
);
1249 msi_free( info
.string
);
1252 static UINT
msi_dialog_scrolltext_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1254 static const WCHAR szRichEdit20W
[] = {'R','i','c','h','E','d','i','t','2','0','W',0};
1255 struct msi_scrolltext_info
*info
;
1256 msi_control
*control
;
1261 info
= msi_alloc( sizeof *info
);
1263 return ERROR_FUNCTION_FAILED
;
1265 hRichedit
= LoadLibraryA("riched20");
1267 style
= WS_BORDER
| ES_MULTILINE
| WS_VSCROLL
|
1268 ES_READONLY
| ES_AUTOVSCROLL
| WS_TABSTOP
;
1269 control
= msi_dialog_add_control( dialog
, rec
, szRichEdit20W
, style
);
1272 FreeLibrary( hRichedit
);
1274 return ERROR_FUNCTION_FAILED
;
1277 control
->hDll
= hRichedit
;
1279 info
->dialog
= dialog
;
1280 info
->control
= control
;
1282 /* subclass the static control */
1283 info
->oldproc
= (WNDPROC
) SetWindowLongPtrW( control
->hwnd
, GWLP_WNDPROC
,
1284 (LONG_PTR
)MSIScrollText_WndProc
);
1285 SetPropW( control
->hwnd
, szButtonData
, info
);
1287 /* add the text into the richedit */
1288 text
= MSI_RecordGetString( rec
, 10 );
1290 msi_scrolltext_add_text( control
, text
);
1292 return ERROR_SUCCESS
;
1295 static HBITMAP
msi_load_picture( MSIDATABASE
*db
, LPCWSTR name
,
1296 INT cx
, INT cy
, DWORD flags
)
1298 HBITMAP hOleBitmap
= 0, hBitmap
= 0, hOldSrcBitmap
, hOldDestBitmap
;
1299 MSIRECORD
*rec
= NULL
;
1300 IStream
*stm
= NULL
;
1301 IPicture
*pic
= NULL
;
1306 rec
= msi_get_binary_record( db
, name
);
1310 r
= MSI_RecordGetIStream( rec
, 2, &stm
);
1311 msiobj_release( &rec
->hdr
);
1312 if( r
!= ERROR_SUCCESS
)
1315 r
= OleLoadPicture( stm
, 0, TRUE
, &IID_IPicture
, (LPVOID
*) &pic
);
1316 IStream_Release( stm
);
1319 ERR("failed to load picture\n");
1323 r
= IPicture_get_Handle( pic
, (OLE_HANDLE
*) &hOleBitmap
);
1326 ERR("failed to get bitmap handle\n");
1330 /* make the bitmap the desired size */
1331 r
= GetObjectW( hOleBitmap
, sizeof bm
, &bm
);
1332 if (r
!= sizeof bm
)
1334 ERR("failed to get bitmap size\n");
1338 if (flags
& LR_DEFAULTSIZE
)
1344 srcdc
= CreateCompatibleDC( NULL
);
1345 hOldSrcBitmap
= SelectObject( srcdc
, hOleBitmap
);
1346 destdc
= CreateCompatibleDC( NULL
);
1347 hBitmap
= CreateCompatibleBitmap( srcdc
, cx
, cy
);
1348 hOldDestBitmap
= SelectObject( destdc
, hBitmap
);
1349 StretchBlt( destdc
, 0, 0, cx
, cy
,
1350 srcdc
, 0, 0, bm
.bmWidth
, bm
.bmHeight
, SRCCOPY
);
1351 SelectObject( srcdc
, hOldSrcBitmap
);
1352 SelectObject( destdc
, hOldDestBitmap
);
1358 IPicture_Release( pic
);
1362 static UINT
msi_dialog_bitmap_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1364 UINT cx
, cy
, flags
, style
, attributes
;
1365 msi_control
*control
;
1368 flags
= LR_LOADFROMFILE
;
1369 style
= SS_BITMAP
| SS_LEFT
| WS_GROUP
;
1371 attributes
= MSI_RecordGetInteger( rec
, 8 );
1372 if( attributes
& msidbControlAttributesFixedSize
)
1374 flags
|= LR_DEFAULTSIZE
;
1375 style
|= SS_CENTERIMAGE
;
1378 control
= msi_dialog_add_control( dialog
, rec
, szStatic
, style
);
1379 cx
= MSI_RecordGetInteger( rec
, 6 );
1380 cy
= MSI_RecordGetInteger( rec
, 7 );
1381 cx
= msi_dialog_scale_unit( dialog
, cx
);
1382 cy
= msi_dialog_scale_unit( dialog
, cy
);
1384 name
= msi_get_binary_name( dialog
->package
, rec
);
1385 control
->hBitmap
= msi_load_picture( dialog
->package
->db
, name
, cx
, cy
, flags
);
1386 if( control
->hBitmap
)
1387 SendMessageW( control
->hwnd
, STM_SETIMAGE
,
1388 IMAGE_BITMAP
, (LPARAM
) control
->hBitmap
);
1390 ERR("Failed to load bitmap %s\n", debugstr_w(name
));
1394 return ERROR_SUCCESS
;
1397 static UINT
msi_dialog_icon_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1399 msi_control
*control
;
1405 control
= msi_dialog_add_control( dialog
, rec
, szStatic
,
1406 SS_ICON
| SS_CENTERIMAGE
| WS_GROUP
);
1408 attributes
= MSI_RecordGetInteger( rec
, 8 );
1409 name
= msi_get_binary_name( dialog
->package
, rec
);
1410 control
->hIcon
= msi_load_icon( dialog
->package
->db
, name
, attributes
);
1411 if( control
->hIcon
)
1412 SendMessageW( control
->hwnd
, STM_SETICON
, (WPARAM
) control
->hIcon
, 0 );
1414 ERR("Failed to load bitmap %s\n", debugstr_w(name
));
1416 return ERROR_SUCCESS
;
1419 /******************** Combo Box ***************************************/
1421 struct msi_combobox_info
1431 static LRESULT WINAPI
MSIComboBox_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1433 struct msi_combobox_info
*info
;
1437 TRACE("%p %04x %08lx %08lx\n", hWnd
, msg
, wParam
, lParam
);
1439 info
= GetPropW( hWnd
, szButtonData
);
1443 r
= CallWindowProcW( info
->oldproc
, hWnd
, msg
, wParam
, lParam
);
1448 for (j
= 0; j
< info
->num_items
; j
++)
1449 msi_free( info
->items
[j
] );
1450 msi_free( info
->items
);
1452 RemovePropW( hWnd
, szButtonData
);
1459 static UINT
msi_combobox_add_item( MSIRECORD
*rec
, LPVOID param
)
1461 struct msi_combobox_info
*info
= param
;
1462 LPCWSTR value
, text
;
1465 value
= MSI_RecordGetString( rec
, 3 );
1466 text
= MSI_RecordGetString( rec
, 4 );
1468 info
->items
[info
->addpos_items
] = strdupW( value
);
1470 pos
= SendMessageW( info
->hwnd
, CB_ADDSTRING
, 0, (LPARAM
)text
);
1471 SendMessageW( info
->hwnd
, CB_SETITEMDATA
, pos
, (LPARAM
)info
->items
[info
->addpos_items
] );
1472 info
->addpos_items
++;
1474 return ERROR_SUCCESS
;
1477 static UINT
msi_combobox_add_items( struct msi_combobox_info
*info
, LPCWSTR property
)
1479 static const WCHAR query
[] = {
1480 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
1481 '`','C','o','m','b','o','B','o','x','`',' ','W','H','E','R','E',' ',
1482 '`','P','r','o','p','e','r','t','y','`',' ','=',' ','\'','%','s','\'',' ',
1483 'O','R','D','E','R',' ','B','Y',' ','`','O','r','d','e','r','`',0};
1488 r
= MSI_OpenQuery( info
->dialog
->package
->db
, &view
, query
, property
);
1489 if (r
!= ERROR_SUCCESS
)
1492 /* just get the number of records */
1494 r
= MSI_IterateRecords( view
, &count
, NULL
, NULL
);
1495 if (r
!= ERROR_SUCCESS
)
1497 msiobj_release( &view
->hdr
);
1500 info
->num_items
= count
;
1501 info
->items
= msi_alloc( sizeof(*info
->items
) * count
);
1503 r
= MSI_IterateRecords( view
, NULL
, msi_combobox_add_item
, info
);
1504 msiobj_release( &view
->hdr
);
1508 static UINT
msi_dialog_set_control_condition( MSIRECORD
*rec
, LPVOID param
)
1510 static const WCHAR szHide
[] = {'H','i','d','e',0};
1511 static const WCHAR szShow
[] = {'S','h','o','w',0};
1512 static const WCHAR szDisable
[] = {'D','i','s','a','b','l','e',0};
1513 static const WCHAR szEnable
[] = {'E','n','a','b','l','e',0};
1514 static const WCHAR szDefault
[] = {'D','e','f','a','u','l','t',0};
1515 msi_dialog
*dialog
= param
;
1516 msi_control
*control
;
1517 LPCWSTR name
, action
, condition
;
1520 name
= MSI_RecordGetString( rec
, 2 );
1521 action
= MSI_RecordGetString( rec
, 3 );
1522 condition
= MSI_RecordGetString( rec
, 4 );
1523 r
= MSI_EvaluateConditionW( dialog
->package
, condition
);
1524 control
= msi_dialog_find_control( dialog
, name
);
1525 if (r
== MSICONDITION_TRUE
&& control
)
1527 TRACE("%s control %s\n", debugstr_w(action
), debugstr_w(name
));
1529 /* FIXME: case sensitive? */
1530 if (!strcmpW( action
, szHide
))
1531 ShowWindow(control
->hwnd
, SW_HIDE
);
1532 else if (!strcmpW( action
, szShow
))
1533 ShowWindow(control
->hwnd
, SW_SHOW
);
1534 else if (!strcmpW( action
, szDisable
))
1535 EnableWindow(control
->hwnd
, FALSE
);
1536 else if (!strcmpW( action
, szEnable
))
1537 EnableWindow(control
->hwnd
, TRUE
);
1538 else if (!strcmpW( action
, szDefault
))
1539 SetFocus(control
->hwnd
);
1541 FIXME("Unhandled action %s\n", debugstr_w(action
));
1543 return ERROR_SUCCESS
;
1546 static UINT
msi_dialog_evaluate_control_conditions( msi_dialog
*dialog
)
1548 static const WCHAR query
[] = {
1549 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
1550 'C','o','n','t','r','o','l','C','o','n','d','i','t','i','o','n',' ',
1551 'W','H','E','R','E',' ','`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',0};
1554 MSIPACKAGE
*package
= dialog
->package
;
1556 TRACE("%p %s\n", dialog
, debugstr_w(dialog
->name
));
1558 /* query the Control table for all the elements of the control */
1559 r
= MSI_OpenQuery( package
->db
, &view
, query
, dialog
->name
);
1560 if (r
!= ERROR_SUCCESS
)
1561 return ERROR_SUCCESS
;
1563 r
= MSI_IterateRecords( view
, 0, msi_dialog_set_control_condition
, dialog
);
1564 msiobj_release( &view
->hdr
);
1568 static UINT
msi_dialog_combobox_handler( msi_dialog
*dialog
, msi_control
*control
, WPARAM param
)
1570 struct msi_combobox_info
*info
;
1574 if (HIWORD(param
) != CBN_SELCHANGE
&& HIWORD(param
) != CBN_EDITCHANGE
)
1575 return ERROR_SUCCESS
;
1577 info
= GetPropW( control
->hwnd
, szButtonData
);
1578 index
= SendMessageW( control
->hwnd
, CB_GETCURSEL
, 0, 0 );
1579 if (index
== CB_ERR
)
1580 value
= msi_get_window_text( control
->hwnd
);
1582 value
= (LPWSTR
) SendMessageW( control
->hwnd
, CB_GETITEMDATA
, index
, 0 );
1584 msi_dialog_set_property( info
->dialog
->package
, control
->property
, value
);
1585 msi_dialog_evaluate_control_conditions( info
->dialog
);
1587 if (index
== CB_ERR
)
1590 return ERROR_SUCCESS
;
1593 static void msi_dialog_combobox_update( msi_dialog
*dialog
, msi_control
*control
)
1595 struct msi_combobox_info
*info
;
1599 info
= GetPropW( control
->hwnd
, szButtonData
);
1601 value
= msi_dup_property( dialog
->package
->db
, control
->property
);
1604 SendMessageW( control
->hwnd
, CB_SETCURSEL
, -1, 0 );
1608 for (j
= 0; j
< info
->num_items
; j
++)
1610 tmp
= (LPWSTR
) SendMessageW( control
->hwnd
, CB_GETITEMDATA
, j
, 0 );
1611 if (!strcmpW( value
, tmp
))
1615 if (j
< info
->num_items
)
1617 SendMessageW( control
->hwnd
, CB_SETCURSEL
, j
, 0 );
1621 SendMessageW( control
->hwnd
, CB_SETCURSEL
, -1, 0 );
1622 SetWindowTextW( control
->hwnd
, value
);
1628 static UINT
msi_dialog_combo_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1630 struct msi_combobox_info
*info
;
1631 msi_control
*control
;
1632 DWORD attributes
, style
;
1635 info
= msi_alloc( sizeof *info
);
1637 return ERROR_FUNCTION_FAILED
;
1639 style
= CBS_AUTOHSCROLL
| WS_TABSTOP
| WS_GROUP
| WS_CHILD
;
1640 attributes
= MSI_RecordGetInteger( rec
, 8 );
1641 if ( ~attributes
& msidbControlAttributesSorted
)
1643 if ( attributes
& msidbControlAttributesComboList
)
1644 style
|= CBS_DROPDOWNLIST
;
1646 style
|= CBS_DROPDOWN
;
1648 control
= msi_dialog_add_control( dialog
, rec
, WC_COMBOBOXW
, style
);
1652 return ERROR_FUNCTION_FAILED
;
1655 control
->handler
= msi_dialog_combobox_handler
;
1656 control
->update
= msi_dialog_combobox_update
;
1658 prop
= MSI_RecordGetString( rec
, 9 );
1659 control
->property
= msi_dialog_dup_property( dialog
, prop
, FALSE
);
1662 info
->dialog
= dialog
;
1663 info
->hwnd
= control
->hwnd
;
1665 info
->addpos_items
= 0;
1666 info
->oldproc
= (WNDPROC
)SetWindowLongPtrW( control
->hwnd
, GWLP_WNDPROC
,
1667 (LONG_PTR
)MSIComboBox_WndProc
);
1668 SetPropW( control
->hwnd
, szButtonData
, info
);
1670 if (control
->property
)
1671 msi_combobox_add_items( info
, control
->property
);
1673 msi_dialog_combobox_update( dialog
, control
);
1675 return ERROR_SUCCESS
;
1678 static UINT
msi_dialog_edit_handler( msi_dialog
*dialog
, msi_control
*control
, WPARAM param
)
1682 if (HIWORD(param
) != EN_CHANGE
)
1683 return ERROR_SUCCESS
;
1685 TRACE("edit %s contents changed, set %s\n", debugstr_w(control
->name
), debugstr_w(control
->property
));
1687 buf
= msi_get_window_text( control
->hwnd
);
1688 msi_dialog_set_property( dialog
->package
, control
->property
, buf
);
1691 return ERROR_SUCCESS
;
1694 /* length of 2^32 + 1 */
1695 #define MAX_NUM_DIGITS 11
1697 static UINT
msi_dialog_edit_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1699 msi_control
*control
;
1701 LPWSTR val
, begin
, end
;
1702 WCHAR num
[MAX_NUM_DIGITS
];
1705 control
= msi_dialog_add_control( dialog
, rec
, szEdit
,
1706 WS_BORDER
| WS_TABSTOP
| ES_AUTOHSCROLL
);
1707 control
->handler
= msi_dialog_edit_handler
;
1709 text
= MSI_RecordGetString( rec
, 10 );
1712 begin
= strchrW( text
, '{' );
1713 end
= strchrW( text
, '}' );
1715 if ( begin
&& end
&& end
> begin
&&
1716 begin
[0] >= '0' && begin
[0] <= '9' &&
1717 end
- begin
< MAX_NUM_DIGITS
)
1719 lstrcpynW( num
, begin
+ 1, end
- begin
);
1720 limit
= atolW( num
);
1722 SendMessageW( control
->hwnd
, EM_SETLIMITTEXT
, limit
, 0 );
1726 prop
= MSI_RecordGetString( rec
, 9 );
1728 control
->property
= strdupW( prop
);
1730 val
= msi_dup_property( dialog
->package
->db
, control
->property
);
1731 SetWindowTextW( control
->hwnd
, val
);
1733 return ERROR_SUCCESS
;
1736 /******************** Masked Edit ********************************************/
1738 #define MASK_MAX_GROUPS 20
1740 struct msi_mask_group
1748 struct msi_maskedit_info
1756 struct msi_mask_group group
[MASK_MAX_GROUPS
];
1759 static BOOL
msi_mask_editable( WCHAR type
)
1774 static void msi_mask_control_change( struct msi_maskedit_info
*info
)
1779 val
= msi_alloc( (info
->num_chars
+1)*sizeof(WCHAR
) );
1780 for( i
=0, n
=0; i
<info
->num_groups
; i
++ )
1782 if( (info
->group
[i
].len
+ n
) > info
->num_chars
)
1784 ERR("can't fit control %d text into template\n",i
);
1787 if (!msi_mask_editable(info
->group
[i
].type
))
1789 for(r
=0; r
<info
->group
[i
].len
; r
++)
1790 val
[n
+r
] = info
->group
[i
].type
;
1795 r
= GetWindowTextW( info
->group
[i
].hwnd
, &val
[n
], info
->group
[i
].len
+1 );
1796 if( r
!= info
->group
[i
].len
)
1802 TRACE("%d/%d controls were good\n", i
, info
->num_groups
);
1804 if( i
== info
->num_groups
)
1806 TRACE("Set property %s to %s\n", debugstr_w(info
->prop
), debugstr_w(val
));
1807 CharUpperBuffW( val
, info
->num_chars
);
1808 msi_dialog_set_property( info
->dialog
->package
, info
->prop
, val
);
1809 msi_dialog_evaluate_control_conditions( info
->dialog
);
1814 /* now move to the next control if necessary */
1815 static VOID
msi_mask_next_control( struct msi_maskedit_info
*info
, HWND hWnd
)
1820 for( i
=0; i
<info
->num_groups
; i
++ )
1821 if( info
->group
[i
].hwnd
== hWnd
)
1824 /* don't move from the last control */
1825 if( i
>= (info
->num_groups
-1) )
1828 len
= SendMessageW( hWnd
, WM_GETTEXTLENGTH
, 0, 0 );
1829 if( len
< info
->group
[i
].len
)
1832 hWndNext
= GetNextDlgTabItem( GetParent( hWnd
), hWnd
, FALSE
);
1833 SetFocus( hWndNext
);
1836 static LRESULT WINAPI
1837 MSIMaskedEdit_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1839 struct msi_maskedit_info
*info
;
1842 TRACE("%p %04x %08lx %08lx\n", hWnd
, msg
, wParam
, lParam
);
1844 info
= GetPropW(hWnd
, szButtonData
);
1846 r
= CallWindowProcW(info
->oldproc
, hWnd
, msg
, wParam
, lParam
);
1851 if (HIWORD(wParam
) == EN_CHANGE
)
1853 msi_mask_control_change( info
);
1854 msi_mask_next_control( info
, (HWND
) lParam
);
1858 msi_free( info
->prop
);
1860 RemovePropW( hWnd
, szButtonData
);
1867 /* fish the various bits of the property out and put them in the control */
1869 msi_maskedit_set_text( struct msi_maskedit_info
*info
, LPCWSTR text
)
1875 for( i
= 0; i
< info
->num_groups
; i
++ )
1877 if( info
->group
[i
].len
< strlenW( p
) )
1879 LPWSTR chunk
= strdupW( p
);
1880 chunk
[ info
->group
[i
].len
] = 0;
1881 SetWindowTextW( info
->group
[i
].hwnd
, chunk
);
1886 SetWindowTextW( info
->group
[i
].hwnd
, p
);
1889 p
+= info
->group
[i
].len
;
1893 static struct msi_maskedit_info
* msi_dialog_parse_groups( LPCWSTR mask
)
1895 struct msi_maskedit_info
* info
= NULL
;
1896 int i
= 0, n
= 0, total
= 0;
1899 TRACE("masked control, template %s\n", debugstr_w(mask
));
1904 info
= msi_alloc_zero( sizeof *info
);
1908 p
= strchrW(mask
, '<');
1914 for( i
=0; i
<MASK_MAX_GROUPS
; i
++ )
1916 /* stop at the end of the string */
1917 if( p
[0] == 0 || p
[0] == '>' )
1920 /* count the number of the same identifier */
1921 for( n
=0; p
[n
] == p
[0]; n
++ )
1923 info
->group
[i
].ofs
= total
;
1924 info
->group
[i
].type
= p
[0];
1928 total
++; /* an extra not part of the group */
1930 info
->group
[i
].len
= n
;
1935 TRACE("%d characters in %d groups\n", total
, i
);
1936 if( i
== MASK_MAX_GROUPS
)
1937 ERR("too many groups in PIDTemplate %s\n", debugstr_w(mask
));
1939 info
->num_chars
= total
;
1940 info
->num_groups
= i
;
1946 msi_maskedit_create_children( struct msi_maskedit_info
*info
, LPCWSTR font
)
1948 DWORD width
, height
, style
, wx
, ww
;
1953 style
= WS_CHILD
| WS_BORDER
| WS_VISIBLE
| WS_TABSTOP
| ES_AUTOHSCROLL
;
1955 GetClientRect( info
->hwnd
, &rect
);
1957 width
= rect
.right
- rect
.left
;
1958 height
= rect
.bottom
- rect
.top
;
1960 for( i
= 0; i
< info
->num_groups
; i
++ )
1962 if (!msi_mask_editable( info
->group
[i
].type
))
1964 wx
= (info
->group
[i
].ofs
* width
) / info
->num_chars
;
1965 ww
= (info
->group
[i
].len
* width
) / info
->num_chars
;
1967 hwnd
= CreateWindowW( szEdit
, NULL
, style
, wx
, 0, ww
, height
,
1968 info
->hwnd
, NULL
, NULL
, NULL
);
1971 ERR("failed to create mask edit sub window\n");
1975 SendMessageW( hwnd
, EM_LIMITTEXT
, info
->group
[i
].len
, 0 );
1977 msi_dialog_set_font( info
->dialog
, hwnd
,
1978 font
?font
:info
->dialog
->default_font
);
1979 info
->group
[i
].hwnd
= hwnd
;
1984 * office 2003 uses "73931<````=````=````=````=`````>@@@@@"
1985 * delphi 7 uses "<????-??????-??????-????>" and "<???-???>"
1986 * filemaker pro 7 uses "<^^^^=^^^^=^^^^=^^^^=^^^^=^^^^=^^^^^>"
1988 static UINT
msi_dialog_maskedit_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1990 LPWSTR font_mask
, val
= NULL
, font
;
1991 struct msi_maskedit_info
*info
= NULL
;
1992 UINT ret
= ERROR_SUCCESS
;
1993 msi_control
*control
;
1998 font_mask
= msi_get_deformatted_field( dialog
->package
, rec
, 10 );
1999 font
= msi_dialog_get_style( font_mask
, &mask
);
2002 WARN("mask template is empty\n");
2006 info
= msi_dialog_parse_groups( mask
);
2009 ERR("template %s is invalid\n", debugstr_w(mask
));
2013 info
->dialog
= dialog
;
2015 control
= msi_dialog_add_control( dialog
, rec
, szStatic
,
2016 SS_OWNERDRAW
| WS_GROUP
| WS_VISIBLE
);
2019 ERR("Failed to create maskedit container\n");
2020 ret
= ERROR_FUNCTION_FAILED
;
2023 SetWindowLongPtrW( control
->hwnd
, GWL_EXSTYLE
, WS_EX_CONTROLPARENT
);
2025 info
->hwnd
= control
->hwnd
;
2027 /* subclass the static control */
2028 info
->oldproc
= (WNDPROC
) SetWindowLongPtrW( info
->hwnd
, GWLP_WNDPROC
,
2029 (LONG_PTR
)MSIMaskedEdit_WndProc
);
2030 SetPropW( control
->hwnd
, szButtonData
, info
);
2032 prop
= MSI_RecordGetString( rec
, 9 );
2034 info
->prop
= strdupW( prop
);
2036 msi_maskedit_create_children( info
, font
);
2040 val
= msi_dup_property( dialog
->package
->db
, prop
);
2043 msi_maskedit_set_text( info
, val
);
2049 if( ret
!= ERROR_SUCCESS
)
2051 msi_free( font_mask
);
2056 /******************** Progress Bar *****************************************/
2058 static UINT
msi_dialog_progress_bar( msi_dialog
*dialog
, MSIRECORD
*rec
)
2060 msi_control
*control
;
2061 DWORD attributes
, style
;
2064 attributes
= MSI_RecordGetInteger( rec
, 8 );
2065 if( !(attributes
& msidbControlAttributesProgress95
) )
2066 style
|= PBS_SMOOTH
;
2068 control
= msi_dialog_add_control( dialog
, rec
, PROGRESS_CLASSW
, style
);
2070 return ERROR_FUNCTION_FAILED
;
2072 ControlEvent_SubscribeToEvent( dialog
->package
, dialog
,
2073 szSetProgress
, control
->name
, szProgress
);
2074 return ERROR_SUCCESS
;
2077 /******************** Path Edit ********************************************/
2079 struct msi_pathedit_info
2082 msi_control
*control
;
2086 static void msi_dialog_update_pathedit( msi_dialog
*dialog
, msi_control
*control
)
2091 if (!control
&& !(control
= msi_dialog_find_control_by_type( dialog
, szPathEdit
)))
2094 indirect
= control
->attributes
& msidbControlAttributesIndirect
;
2095 prop
= msi_dialog_dup_property( dialog
, control
->property
, indirect
);
2096 path
= msi_dialog_dup_property( dialog
, prop
, TRUE
);
2098 SetWindowTextW( control
->hwnd
, path
);
2099 SendMessageW( control
->hwnd
, EM_SETSEL
, 0, -1 );
2105 /* FIXME: test when this should fail */
2106 static BOOL
msi_dialog_verify_path( LPWSTR path
)
2108 if ( !lstrlenW( path
) )
2111 if ( PathIsRelativeW( path
) )
2117 /* returns TRUE if the path is valid, FALSE otherwise */
2118 static BOOL
msi_dialog_onkillfocus( msi_dialog
*dialog
, msi_control
*control
)
2124 indirect
= control
->attributes
& msidbControlAttributesIndirect
;
2125 prop
= msi_dialog_dup_property( dialog
, control
->property
, indirect
);
2127 buf
= msi_get_window_text( control
->hwnd
);
2129 if ( !msi_dialog_verify_path( buf
) )
2131 /* FIXME: display an error message box */
2132 ERR("Invalid path %s\n", debugstr_w( buf
));
2134 SetFocus( control
->hwnd
);
2139 msi_dialog_set_property( dialog
->package
, prop
, buf
);
2142 msi_dialog_update_pathedit( dialog
, control
);
2144 TRACE("edit %s contents changed, set %s\n", debugstr_w(control
->name
),
2153 static LRESULT WINAPI
MSIPathEdit_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
2155 struct msi_pathedit_info
*info
= GetPropW(hWnd
, szButtonData
);
2158 TRACE("%p %04x %08lx %08lx\n", hWnd
, msg
, wParam
, lParam
);
2160 if ( msg
== WM_KILLFOCUS
)
2162 /* if the path is invalid, don't handle this message */
2163 if ( !msi_dialog_onkillfocus( info
->dialog
, info
->control
) )
2167 r
= CallWindowProcW(info
->oldproc
, hWnd
, msg
, wParam
, lParam
);
2169 if ( msg
== WM_NCDESTROY
)
2172 RemovePropW( hWnd
, szButtonData
);
2178 static UINT
msi_dialog_pathedit_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
2180 struct msi_pathedit_info
*info
;
2181 msi_control
*control
;
2184 info
= msi_alloc( sizeof *info
);
2186 return ERROR_FUNCTION_FAILED
;
2188 control
= msi_dialog_add_control( dialog
, rec
, szEdit
,
2189 WS_BORDER
| WS_TABSTOP
);
2190 control
->attributes
= MSI_RecordGetInteger( rec
, 8 );
2191 prop
= MSI_RecordGetString( rec
, 9 );
2192 control
->property
= msi_dialog_dup_property( dialog
, prop
, FALSE
);
2194 info
->dialog
= dialog
;
2195 info
->control
= control
;
2196 info
->oldproc
= (WNDPROC
) SetWindowLongPtrW( control
->hwnd
, GWLP_WNDPROC
,
2197 (LONG_PTR
)MSIPathEdit_WndProc
);
2198 SetPropW( control
->hwnd
, szButtonData
, info
);
2200 msi_dialog_update_pathedit( dialog
, control
);
2202 return ERROR_SUCCESS
;
2205 static UINT
msi_dialog_radiogroup_handler( msi_dialog
*dialog
, msi_control
*control
, WPARAM param
)
2207 if (HIWORD(param
) != BN_CLICKED
)
2208 return ERROR_SUCCESS
;
2210 TRACE("clicked radio button %s, set %s\n", debugstr_w(control
->name
), debugstr_w(control
->property
));
2212 msi_dialog_set_property( dialog
->package
, control
->property
, control
->name
);
2214 return msi_dialog_button_handler( dialog
, control
, param
);
2217 /* radio buttons are a bit different from normal controls */
2218 static UINT
msi_dialog_create_radiobutton( MSIRECORD
*rec
, LPVOID param
)
2220 radio_button_group_descr
*group
= param
;
2221 msi_dialog
*dialog
= group
->dialog
;
2222 msi_control
*control
;
2223 LPCWSTR prop
, text
, name
;
2224 DWORD style
, attributes
= group
->attributes
;
2226 style
= WS_CHILD
| BS_AUTORADIOBUTTON
| BS_MULTILINE
| WS_TABSTOP
;
2227 name
= MSI_RecordGetString( rec
, 3 );
2228 text
= MSI_RecordGetString( rec
, 8 );
2229 if( attributes
& msidbControlAttributesVisible
)
2230 style
|= WS_VISIBLE
;
2231 if( ~attributes
& msidbControlAttributesEnabled
)
2232 style
|= WS_DISABLED
;
2234 control
= msi_dialog_create_window( dialog
, rec
, 0, szButton
, name
, text
,
2235 style
, group
->parent
->hwnd
);
2237 return ERROR_FUNCTION_FAILED
;
2238 control
->handler
= msi_dialog_radiogroup_handler
;
2240 if (group
->propval
&& !strcmpW( control
->name
, group
->propval
))
2241 SendMessageW(control
->hwnd
, BM_SETCHECK
, BST_CHECKED
, 0);
2243 prop
= MSI_RecordGetString( rec
, 1 );
2245 control
->property
= strdupW( prop
);
2247 return ERROR_SUCCESS
;
2250 static BOOL CALLBACK
msi_radioground_child_enum( HWND hWnd
, LPARAM lParam
)
2252 EnableWindow( hWnd
, lParam
);
2256 static LRESULT WINAPI
MSIRadioGroup_WndProc( HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
2258 WNDPROC oldproc
= (WNDPROC
)GetPropW( hWnd
, szButtonData
);
2261 TRACE("hWnd %p msg %04x wParam 0x%08lx lParam 0x%08lx\n", hWnd
, msg
, wParam
, lParam
);
2263 if (msg
== WM_COMMAND
) /* Forward notifications to dialog */
2264 SendMessageW( GetParent( hWnd
), msg
, wParam
, lParam
);
2266 r
= CallWindowProcW( oldproc
, hWnd
, msg
, wParam
, lParam
);
2268 /* make sure the radio buttons show as disabled if the parent is disabled */
2269 if (msg
== WM_ENABLE
)
2270 EnumChildWindows( hWnd
, msi_radioground_child_enum
, wParam
);
2275 static UINT
msi_dialog_radiogroup_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
2277 static const WCHAR query
[] = {
2278 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2279 'R','a','d','i','o','B','u','t','t','o','n',' ','W','H','E','R','E',' ',
2280 '`','P','r','o','p','e','r','t','y','`',' ','=',' ','\'','%','s','\'',0};
2283 msi_control
*control
;
2285 radio_button_group_descr group
;
2286 MSIPACKAGE
*package
= dialog
->package
;
2288 DWORD attr
, style
= WS_GROUP
;
2290 prop
= MSI_RecordGetString( rec
, 9 );
2292 TRACE("%p %p %s\n", dialog
, rec
, debugstr_w( prop
));
2294 attr
= MSI_RecordGetInteger( rec
, 8 );
2295 if (attr
& msidbControlAttributesHasBorder
)
2296 style
|= BS_GROUPBOX
;
2298 style
|= BS_OWNERDRAW
;
2300 /* Create parent group box to hold radio buttons */
2301 control
= msi_dialog_add_control( dialog
, rec
, szButton
, style
);
2303 return ERROR_FUNCTION_FAILED
;
2305 oldproc
= (WNDPROC
) SetWindowLongPtrW( control
->hwnd
, GWLP_WNDPROC
,
2306 (LONG_PTR
)MSIRadioGroup_WndProc
);
2307 SetPropW(control
->hwnd
, szButtonData
, oldproc
);
2308 SetWindowLongPtrW( control
->hwnd
, GWL_EXSTYLE
, WS_EX_CONTROLPARENT
);
2311 control
->property
= strdupW( prop
);
2313 /* query the Radio Button table for all control in this group */
2314 r
= MSI_OpenQuery( package
->db
, &view
, query
, prop
);
2315 if( r
!= ERROR_SUCCESS
)
2317 ERR("query failed for dialog %s radio group %s\n",
2318 debugstr_w(dialog
->name
), debugstr_w(prop
));
2319 return ERROR_INVALID_PARAMETER
;
2322 group
.dialog
= dialog
;
2323 group
.parent
= control
;
2324 group
.attributes
= MSI_RecordGetInteger( rec
, 8 );
2325 group
.propval
= msi_dup_property( dialog
->package
->db
, control
->property
);
2327 r
= MSI_IterateRecords( view
, 0, msi_dialog_create_radiobutton
, &group
);
2328 msiobj_release( &view
->hdr
);
2329 msi_free( group
.propval
);
2334 msi_seltree_sync_item_state( HWND hwnd
, MSIFEATURE
*feature
, HTREEITEM hItem
)
2337 DWORD index
= feature
->ActionRequest
;
2339 TRACE("Feature %s -> %d %d %d\n", debugstr_w(feature
->Title
),
2340 feature
->Installed
, feature
->Action
, feature
->ActionRequest
);
2342 if (index
== INSTALLSTATE_UNKNOWN
)
2343 index
= INSTALLSTATE_ABSENT
;
2345 tvi
.mask
= TVIF_STATE
;
2347 tvi
.state
= INDEXTOSTATEIMAGEMASK( index
);
2348 tvi
.stateMask
= TVIS_STATEIMAGEMASK
;
2350 SendMessageW( hwnd
, TVM_SETITEMW
, 0, (LPARAM
) &tvi
);
2354 msi_seltree_popup_menu( HWND hwnd
, INT x
, INT y
)
2359 /* create a menu to display */
2360 hMenu
= CreatePopupMenu();
2362 /* FIXME: load strings from resources */
2363 AppendMenuA( hMenu
, MF_ENABLED
, INSTALLSTATE_LOCAL
, "Install feature locally");
2364 AppendMenuA( hMenu
, MF_ENABLED
, USER_INSTALLSTATE_ALL
, "Install entire feature");
2365 AppendMenuA( hMenu
, MF_ENABLED
, INSTALLSTATE_ADVERTISED
, "Install on demand");
2366 AppendMenuA( hMenu
, MF_ENABLED
, INSTALLSTATE_ABSENT
, "Don't install");
2367 r
= TrackPopupMenu( hMenu
, TPM_LEFTALIGN
| TPM_TOPALIGN
| TPM_RETURNCMD
,
2368 x
, y
, 0, hwnd
, NULL
);
2369 DestroyMenu( hMenu
);
2374 msi_seltree_update_feature_installstate( HWND hwnd
, HTREEITEM hItem
,
2375 MSIPACKAGE
*package
, MSIFEATURE
*feature
, INSTALLSTATE state
)
2377 feature
->ActionRequest
= state
;
2378 msi_seltree_sync_item_state( hwnd
, feature
, hItem
);
2379 ACTION_UpdateComponentStates( package
, feature
);
2383 msi_seltree_update_siblings_and_children_installstate( HWND hwnd
, HTREEITEM curr
,
2384 MSIPACKAGE
*package
, INSTALLSTATE state
)
2386 /* update all siblings */
2389 MSIFEATURE
*feature
;
2392 feature
= msi_seltree_feature_from_item( hwnd
, curr
);
2393 msi_seltree_update_feature_installstate( hwnd
, curr
, package
, feature
, state
);
2395 /* update this sibling's children */
2396 child
= (HTREEITEM
)SendMessageW( hwnd
, TVM_GETNEXTITEM
, (WPARAM
)TVGN_CHILD
, (LPARAM
)curr
);
2398 msi_seltree_update_siblings_and_children_installstate( hwnd
, child
,
2401 while ((curr
= (HTREEITEM
)SendMessageW( hwnd
, TVM_GETNEXTITEM
, (WPARAM
)TVGN_NEXT
, (LPARAM
)curr
)));
2405 msi_seltree_menu( HWND hwnd
, HTREEITEM hItem
)
2407 struct msi_selection_tree_info
*info
;
2408 MSIFEATURE
*feature
;
2409 MSIPACKAGE
*package
;
2417 info
= GetPropW(hwnd
, szButtonData
);
2418 package
= info
->dialog
->package
;
2420 feature
= msi_seltree_feature_from_item( hwnd
, hItem
);
2423 ERR("item %p feature was NULL\n", hItem
);
2427 /* get the item's rectangle to put the menu just below it */
2429 SendMessageW( hwnd
, TVM_GETITEMRECT
, 0, (LPARAM
) &u
.rc
);
2430 MapWindowPoints( hwnd
, NULL
, u
.pt
, 2 );
2432 r
= msi_seltree_popup_menu( hwnd
, u
.rc
.left
, u
.rc
.top
);
2436 case USER_INSTALLSTATE_ALL
:
2437 r
= INSTALLSTATE_LOCAL
;
2439 case INSTALLSTATE_ADVERTISED
:
2440 case INSTALLSTATE_ABSENT
:
2443 child
= (HTREEITEM
)SendMessageW( hwnd
, TVM_GETNEXTITEM
, (WPARAM
)TVGN_CHILD
, (LPARAM
)hItem
);
2445 msi_seltree_update_siblings_and_children_installstate( hwnd
, child
, package
, r
);
2448 case INSTALLSTATE_LOCAL
:
2449 msi_seltree_update_feature_installstate( hwnd
, hItem
, package
, feature
, r
);
2456 static LRESULT WINAPI
2457 MSISelectionTree_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
2459 struct msi_selection_tree_info
*info
;
2460 TVHITTESTINFO tvhti
;
2463 TRACE("%p %04x %08lx %08lx\n", hWnd
, msg
, wParam
, lParam
);
2465 info
= GetPropW(hWnd
, szButtonData
);
2469 case WM_LBUTTONDOWN
:
2470 tvhti
.pt
.x
= (short)LOWORD( lParam
);
2471 tvhti
.pt
.y
= (short)HIWORD( lParam
);
2474 CallWindowProcW(info
->oldproc
, hWnd
, TVM_HITTEST
, 0, (LPARAM
) &tvhti
);
2475 if (tvhti
.flags
& TVHT_ONITEMSTATEICON
)
2476 return msi_seltree_menu( hWnd
, tvhti
.hItem
);
2479 r
= CallWindowProcW(info
->oldproc
, hWnd
, msg
, wParam
, lParam
);
2485 RemovePropW( hWnd
, szButtonData
);
2492 msi_seltree_add_child_features( MSIPACKAGE
*package
, HWND hwnd
,
2493 LPCWSTR parent
, HTREEITEM hParent
)
2495 struct msi_selection_tree_info
*info
= GetPropW( hwnd
, szButtonData
);
2496 MSIFEATURE
*feature
;
2497 TVINSERTSTRUCTW tvis
;
2498 HTREEITEM hitem
, hfirst
= NULL
;
2500 LIST_FOR_EACH_ENTRY( feature
, &package
->features
, MSIFEATURE
, entry
)
2502 if ( parent
&& feature
->Feature_Parent
&& strcmpW( parent
, feature
->Feature_Parent
))
2504 else if ( parent
&& !feature
->Feature_Parent
)
2506 else if ( !parent
&& feature
->Feature_Parent
)
2509 if ( !feature
->Title
)
2512 if ( !feature
->Display
)
2515 memset( &tvis
, 0, sizeof tvis
);
2516 tvis
.hParent
= hParent
;
2517 tvis
.hInsertAfter
= TVI_LAST
;
2518 tvis
.u
.item
.mask
= TVIF_TEXT
| TVIF_PARAM
;
2519 tvis
.u
.item
.pszText
= feature
->Title
;
2520 tvis
.u
.item
.lParam
= (LPARAM
) feature
;
2522 hitem
= (HTREEITEM
) SendMessageW( hwnd
, TVM_INSERTITEMW
, 0, (LPARAM
) &tvis
);
2529 msi_seltree_sync_item_state( hwnd
, feature
, hitem
);
2530 msi_seltree_add_child_features( package
, hwnd
,
2531 feature
->Feature
, hitem
);
2533 /* the node is expanded if Display is odd */
2534 if ( feature
->Display
% 2 != 0 )
2535 SendMessageW( hwnd
, TVM_EXPAND
, TVE_EXPAND
, (LPARAM
) hitem
);
2538 /* select the first item */
2539 SendMessageW( hwnd
, TVM_SELECTITEM
, TVGN_CARET
| TVGN_DROPHILITE
, (LPARAM
) hfirst
);
2540 info
->selected
= hfirst
;
2543 static void msi_seltree_create_imagelist( HWND hwnd
)
2545 const int bm_width
= 32, bm_height
= 16, bm_count
= 3;
2546 const int bm_resource
= 0x1001;
2551 himl
= ImageList_Create( bm_width
, bm_height
, FALSE
, 4, 0 );
2554 ERR("failed to create image list\n");
2558 for (i
=0; i
<bm_count
; i
++)
2560 hbmp
= LoadBitmapW( msi_hInstance
, MAKEINTRESOURCEW(i
+bm_resource
) );
2563 ERR("failed to load bitmap %d\n", i
);
2568 * Add a dummy bitmap at offset zero because the treeview
2569 * can't use it as a state mask (zero means no user state).
2572 ImageList_Add( himl
, hbmp
, NULL
);
2574 ImageList_Add( himl
, hbmp
, NULL
);
2577 SendMessageW( hwnd
, TVM_SETIMAGELIST
, TVSIL_STATE
, (LPARAM
)himl
);
2580 static UINT
msi_dialog_seltree_handler( msi_dialog
*dialog
,
2581 msi_control
*control
, WPARAM param
)
2583 struct msi_selection_tree_info
*info
= GetPropW( control
->hwnd
, szButtonData
);
2584 LPNMTREEVIEWW tv
= (LPNMTREEVIEWW
)param
;
2585 MSIRECORD
*row
, *rec
;
2587 MSIFEATURE
*feature
;
2588 LPCWSTR dir
, title
= NULL
;
2589 UINT r
= ERROR_SUCCESS
;
2591 static const WCHAR select
[] = {
2592 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2593 '`','F','e','a','t','u','r','e','`',' ','W','H','E','R','E',' ',
2594 '`','T','i','t','l','e','`',' ','=',' ','\'','%','s','\'',0
2597 if (tv
->hdr
.code
!= TVN_SELCHANGINGW
)
2598 return ERROR_SUCCESS
;
2600 info
->selected
= tv
->itemNew
.hItem
;
2602 if (!(tv
->itemNew
.mask
& TVIF_TEXT
))
2604 feature
= msi_seltree_feature_from_item( control
->hwnd
, tv
->itemNew
.hItem
);
2606 title
= feature
->Title
;
2609 title
= tv
->itemNew
.pszText
;
2611 row
= MSI_QueryGetRecord( dialog
->package
->db
, select
, title
);
2613 return ERROR_FUNCTION_FAILED
;
2615 rec
= MSI_CreateRecord( 1 );
2617 MSI_RecordSetStringW( rec
, 1, MSI_RecordGetString( row
, 4 ) );
2618 ControlEvent_FireSubscribedEvent( dialog
->package
, szSelectionDescription
, rec
);
2620 dir
= MSI_RecordGetString( row
, 7 );
2623 folder
= msi_get_loaded_folder( dialog
->package
, dir
);
2626 r
= ERROR_FUNCTION_FAILED
;
2629 MSI_RecordSetStringW( rec
, 1, folder
->ResolvedTarget
);
2632 MSI_RecordSetStringW( rec
, 1, NULL
);
2634 ControlEvent_FireSubscribedEvent( dialog
->package
, szSelectionPath
, rec
);
2637 msiobj_release(&row
->hdr
);
2638 msiobj_release(&rec
->hdr
);
2643 static UINT
msi_dialog_selection_tree( msi_dialog
*dialog
, MSIRECORD
*rec
)
2645 msi_control
*control
;
2646 LPCWSTR prop
, control_name
;
2647 MSIPACKAGE
*package
= dialog
->package
;
2649 struct msi_selection_tree_info
*info
;
2651 info
= msi_alloc( sizeof *info
);
2653 return ERROR_FUNCTION_FAILED
;
2655 /* create the treeview control */
2656 style
= TVS_HASLINES
| TVS_HASBUTTONS
| TVS_LINESATROOT
;
2657 style
|= WS_GROUP
| WS_VSCROLL
;
2658 control
= msi_dialog_add_control( dialog
, rec
, WC_TREEVIEWW
, style
);
2662 return ERROR_FUNCTION_FAILED
;
2665 control
->handler
= msi_dialog_seltree_handler
;
2666 control_name
= MSI_RecordGetString( rec
, 2 );
2667 control
->attributes
= MSI_RecordGetInteger( rec
, 8 );
2668 prop
= MSI_RecordGetString( rec
, 9 );
2669 control
->property
= msi_dialog_dup_property( dialog
, prop
, FALSE
);
2672 info
->dialog
= dialog
;
2673 info
->hwnd
= control
->hwnd
;
2674 info
->oldproc
= (WNDPROC
) SetWindowLongPtrW( control
->hwnd
, GWLP_WNDPROC
,
2675 (LONG_PTR
)MSISelectionTree_WndProc
);
2676 SetPropW( control
->hwnd
, szButtonData
, info
);
2678 ControlEvent_SubscribeToEvent( dialog
->package
, dialog
,
2679 szSelectionPath
, control_name
, szProperty
);
2682 msi_seltree_create_imagelist( control
->hwnd
);
2683 msi_seltree_add_child_features( package
, control
->hwnd
, NULL
, NULL
);
2685 return ERROR_SUCCESS
;
2688 /******************** Group Box ***************************************/
2690 static UINT
msi_dialog_group_box( msi_dialog
*dialog
, MSIRECORD
*rec
)
2692 msi_control
*control
;
2695 style
= BS_GROUPBOX
| WS_CHILD
| WS_GROUP
;
2696 control
= msi_dialog_add_control( dialog
, rec
, WC_BUTTONW
, style
);
2698 return ERROR_FUNCTION_FAILED
;
2700 return ERROR_SUCCESS
;
2703 /******************** List Box ***************************************/
2705 struct msi_listbox_info
2715 static LRESULT WINAPI
MSIListBox_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
2717 struct msi_listbox_info
*info
;
2721 TRACE("%p %04x %08lx %08lx\n", hWnd
, msg
, wParam
, lParam
);
2723 info
= GetPropW( hWnd
, szButtonData
);
2727 r
= CallWindowProcW( info
->oldproc
, hWnd
, msg
, wParam
, lParam
);
2732 for (j
= 0; j
< info
->num_items
; j
++)
2733 msi_free( info
->items
[j
] );
2734 msi_free( info
->items
);
2736 RemovePropW( hWnd
, szButtonData
);
2743 static UINT
msi_listbox_add_item( MSIRECORD
*rec
, LPVOID param
)
2745 struct msi_listbox_info
*info
= param
;
2746 LPCWSTR value
, text
;
2749 value
= MSI_RecordGetString( rec
, 3 );
2750 text
= MSI_RecordGetString( rec
, 4 );
2752 info
->items
[info
->addpos_items
] = strdupW( value
);
2754 pos
= SendMessageW( info
->hwnd
, LB_ADDSTRING
, 0, (LPARAM
)text
);
2755 SendMessageW( info
->hwnd
, LB_SETITEMDATA
, pos
, (LPARAM
)info
->items
[info
->addpos_items
] );
2756 info
->addpos_items
++;
2757 return ERROR_SUCCESS
;
2760 static UINT
msi_listbox_add_items( struct msi_listbox_info
*info
, LPCWSTR property
)
2762 static const WCHAR query
[] = {
2763 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2764 '`','L','i','s','t','B','o','x','`',' ','W','H','E','R','E',' ',
2765 '`','P','r','o','p','e','r','t','y','`',' ','=',' ','\'','%','s','\'',' ',
2766 'O','R','D','E','R',' ','B','Y',' ','`','O','r','d','e','r','`',0};
2771 r
= MSI_OpenQuery( info
->dialog
->package
->db
, &view
, query
, property
);
2772 if ( r
!= ERROR_SUCCESS
)
2775 /* just get the number of records */
2777 r
= MSI_IterateRecords( view
, &count
, NULL
, NULL
);
2778 if (r
!= ERROR_SUCCESS
)
2780 msiobj_release( &view
->hdr
);
2783 info
->num_items
= count
;
2784 info
->items
= msi_alloc( sizeof(*info
->items
) * count
);
2786 r
= MSI_IterateRecords( view
, NULL
, msi_listbox_add_item
, info
);
2787 msiobj_release( &view
->hdr
);
2791 static UINT
msi_dialog_listbox_handler( msi_dialog
*dialog
,
2792 msi_control
*control
, WPARAM param
)
2794 struct msi_listbox_info
*info
;
2798 if( HIWORD(param
) != LBN_SELCHANGE
)
2799 return ERROR_SUCCESS
;
2801 info
= GetPropW( control
->hwnd
, szButtonData
);
2802 index
= SendMessageW( control
->hwnd
, LB_GETCURSEL
, 0, 0 );
2803 value
= (LPCWSTR
) SendMessageW( control
->hwnd
, LB_GETITEMDATA
, index
, 0 );
2805 msi_dialog_set_property( info
->dialog
->package
, control
->property
, value
);
2806 msi_dialog_evaluate_control_conditions( info
->dialog
);
2808 return ERROR_SUCCESS
;
2811 static UINT
msi_dialog_list_box( msi_dialog
*dialog
, MSIRECORD
*rec
)
2813 struct msi_listbox_info
*info
;
2814 msi_control
*control
;
2815 DWORD attributes
, style
;
2818 info
= msi_alloc( sizeof *info
);
2820 return ERROR_FUNCTION_FAILED
;
2822 style
= WS_TABSTOP
| WS_GROUP
| WS_CHILD
| LBS_NOTIFY
| WS_VSCROLL
| WS_BORDER
;
2823 attributes
= MSI_RecordGetInteger( rec
, 8 );
2824 if (~attributes
& msidbControlAttributesSorted
)
2827 control
= msi_dialog_add_control( dialog
, rec
, WC_LISTBOXW
, style
);
2831 return ERROR_FUNCTION_FAILED
;
2834 control
->handler
= msi_dialog_listbox_handler
;
2836 prop
= MSI_RecordGetString( rec
, 9 );
2837 control
->property
= msi_dialog_dup_property( dialog
, prop
, FALSE
);
2840 info
->dialog
= dialog
;
2841 info
->hwnd
= control
->hwnd
;
2843 info
->addpos_items
= 0;
2844 info
->oldproc
= (WNDPROC
)SetWindowLongPtrW( control
->hwnd
, GWLP_WNDPROC
,
2845 (LONG_PTR
)MSIListBox_WndProc
);
2846 SetPropW( control
->hwnd
, szButtonData
, info
);
2848 if ( control
->property
)
2849 msi_listbox_add_items( info
, control
->property
);
2851 return ERROR_SUCCESS
;
2854 /******************** Directory Combo ***************************************/
2856 static void msi_dialog_update_directory_combo( msi_dialog
*dialog
, msi_control
*control
)
2861 if (!control
&& !(control
= msi_dialog_find_control_by_type( dialog
, szDirectoryCombo
)))
2864 indirect
= control
->attributes
& msidbControlAttributesIndirect
;
2865 prop
= msi_dialog_dup_property( dialog
, control
->property
, indirect
);
2866 path
= msi_dialog_dup_property( dialog
, prop
, TRUE
);
2868 PathStripPathW( path
);
2869 PathRemoveBackslashW( path
);
2871 SendMessageW( control
->hwnd
, CB_INSERTSTRING
, 0, (LPARAM
)path
);
2872 SendMessageW( control
->hwnd
, CB_SETCURSEL
, 0, 0 );
2878 static UINT
msi_dialog_directory_combo( msi_dialog
*dialog
, MSIRECORD
*rec
)
2880 msi_control
*control
;
2884 /* FIXME: use CBS_OWNERDRAWFIXED and add owner draw code */
2885 style
= CBS_DROPDOWNLIST
| CBS_HASSTRINGS
| WS_CHILD
|
2886 WS_GROUP
| WS_TABSTOP
| WS_VSCROLL
;
2887 control
= msi_dialog_add_control( dialog
, rec
, WC_COMBOBOXW
, style
);
2889 return ERROR_FUNCTION_FAILED
;
2891 control
->attributes
= MSI_RecordGetInteger( rec
, 8 );
2892 prop
= MSI_RecordGetString( rec
, 9 );
2893 control
->property
= msi_dialog_dup_property( dialog
, prop
, FALSE
);
2895 msi_dialog_update_directory_combo( dialog
, control
);
2897 return ERROR_SUCCESS
;
2900 /******************** Directory List ***************************************/
2902 static void msi_dialog_update_directory_list( msi_dialog
*dialog
, msi_control
*control
)
2904 WCHAR dir_spec
[MAX_PATH
];
2905 WIN32_FIND_DATAW wfd
;
2911 static const WCHAR asterisk
[] = {'*',0};
2913 if (!control
&& !(control
= msi_dialog_find_control_by_type( dialog
, szDirectoryList
)))
2916 /* clear the list-view */
2917 SendMessageW( control
->hwnd
, LVM_DELETEALLITEMS
, 0, 0 );
2919 indirect
= control
->attributes
& msidbControlAttributesIndirect
;
2920 prop
= msi_dialog_dup_property( dialog
, control
->property
, indirect
);
2921 path
= msi_dialog_dup_property( dialog
, prop
, TRUE
);
2923 lstrcpyW( dir_spec
, path
);
2924 lstrcatW( dir_spec
, asterisk
);
2926 file
= FindFirstFileW( dir_spec
, &wfd
);
2927 if ( file
== INVALID_HANDLE_VALUE
)
2932 if ( wfd
.dwFileAttributes
!= FILE_ATTRIBUTE_DIRECTORY
)
2935 if ( !strcmpW( wfd
.cFileName
, szDot
) || !strcmpW( wfd
.cFileName
, szDotDot
) )
2938 item
.mask
= LVIF_TEXT
;
2939 item
.cchTextMax
= MAX_PATH
;
2942 item
.pszText
= wfd
.cFileName
;
2944 SendMessageW( control
->hwnd
, LVM_INSERTITEMW
, 0, (LPARAM
)&item
);
2945 } while ( FindNextFileW( file
, &wfd
) );
2952 UINT
msi_dialog_directorylist_up( msi_dialog
*dialog
)
2954 msi_control
*control
;
2955 LPWSTR prop
, path
, ptr
;
2958 control
= msi_dialog_find_control_by_type( dialog
, szDirectoryList
);
2959 indirect
= control
->attributes
& msidbControlAttributesIndirect
;
2960 prop
= msi_dialog_dup_property( dialog
, control
->property
, indirect
);
2961 path
= msi_dialog_dup_property( dialog
, prop
, TRUE
);
2963 /* strip off the last directory */
2964 ptr
= PathFindFileNameW( path
);
2965 if (ptr
!= path
) *(ptr
- 1) = '\0';
2966 PathAddBackslashW( path
);
2968 msi_dialog_set_property( dialog
->package
, prop
, path
);
2970 msi_dialog_update_directory_list( dialog
, NULL
);
2971 msi_dialog_update_directory_combo( dialog
, NULL
);
2972 msi_dialog_update_pathedit( dialog
, NULL
);
2977 return ERROR_SUCCESS
;
2980 static UINT
msi_dialog_dirlist_handler( msi_dialog
*dialog
,
2981 msi_control
*control
, WPARAM param
)
2983 LPNMHDR nmhdr
= (LPNMHDR
)param
;
2984 WCHAR new_path
[MAX_PATH
];
2985 WCHAR text
[MAX_PATH
];
2991 if (nmhdr
->code
!= LVN_ITEMACTIVATE
)
2992 return ERROR_SUCCESS
;
2994 index
= SendMessageW( control
->hwnd
, LVM_GETNEXTITEM
, -1, LVNI_SELECTED
);
2997 ERR("No list-view item selected!\n");
2998 return ERROR_FUNCTION_FAILED
;
3002 item
.pszText
= text
;
3003 item
.cchTextMax
= MAX_PATH
;
3004 SendMessageW( control
->hwnd
, LVM_GETITEMTEXTW
, index
, (LPARAM
)&item
);
3006 indirect
= control
->attributes
& msidbControlAttributesIndirect
;
3007 prop
= msi_dialog_dup_property( dialog
, control
->property
, indirect
);
3008 path
= msi_dialog_dup_property( dialog
, prop
, TRUE
);
3010 lstrcpyW( new_path
, path
);
3011 lstrcatW( new_path
, text
);
3012 lstrcatW( new_path
, szBackSlash
);
3014 msi_dialog_set_property( dialog
->package
, prop
, new_path
);
3016 msi_dialog_update_directory_list( dialog
, NULL
);
3017 msi_dialog_update_directory_combo( dialog
, NULL
);
3018 msi_dialog_update_pathedit( dialog
, NULL
);
3022 return ERROR_SUCCESS
;
3025 static UINT
msi_dialog_directory_list( msi_dialog
*dialog
, MSIRECORD
*rec
)
3027 msi_control
*control
;
3031 style
= LVS_LIST
| WS_VSCROLL
| LVS_SHAREIMAGELISTS
|
3032 LVS_AUTOARRANGE
| LVS_SINGLESEL
| WS_BORDER
|
3033 LVS_SORTASCENDING
| WS_CHILD
| WS_GROUP
| WS_TABSTOP
;
3034 control
= msi_dialog_add_control( dialog
, rec
, WC_LISTVIEWW
, style
);
3036 return ERROR_FUNCTION_FAILED
;
3038 control
->attributes
= MSI_RecordGetInteger( rec
, 8 );
3039 control
->handler
= msi_dialog_dirlist_handler
;
3040 prop
= MSI_RecordGetString( rec
, 9 );
3041 control
->property
= msi_dialog_dup_property( dialog
, prop
, FALSE
);
3043 /* double click to activate an item in the list */
3044 SendMessageW( control
->hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
,
3045 0, LVS_EX_TWOCLICKACTIVATE
);
3047 msi_dialog_update_directory_list( dialog
, control
);
3049 return ERROR_SUCCESS
;
3052 /******************** VolumeCost List ***************************************/
3054 static BOOL
str_is_number( LPCWSTR str
)
3058 for (i
= 0; i
< lstrlenW( str
); i
++)
3059 if (!isdigitW(str
[i
]))
3065 static const WCHAR column_keys
[][80] =
3067 {'V','o','l','u','m','e','C','o','s','t','V','o','l','u','m','e',0},
3068 {'V','o','l','u','m','e','C','o','s','t','S','i','z','e',0},
3069 {'V','o','l','u','m','e','C','o','s','t','A','v','a','i','l','a','b','l','e',0},
3070 {'V','o','l','u','m','e','C','o','s','t','R','e','q','u','i','r','e','d',0},
3071 {'V','o','l','u','m','e','C','o','s','t','D','i','f','f','e','r','e','n','c','e',0}
3074 static void msi_dialog_vcl_add_columns( msi_dialog
*dialog
, msi_control
*control
, MSIRECORD
*rec
)
3076 LPCWSTR text
= MSI_RecordGetString( rec
, 10 );
3077 LPCWSTR begin
= text
, end
;
3082 static const WCHAR negative
[] = {'-',0};
3086 while ((begin
= strchrW( begin
, '{' )) && count
< 5)
3088 if (!(end
= strchrW( begin
, '}' )))
3091 num
= msi_alloc( (end
-begin
+1)*sizeof(WCHAR
) );
3095 lstrcpynW( num
, begin
+ 1, end
- begin
);
3096 begin
+= end
- begin
+ 1;
3098 /* empty braces or '0' hides the column */
3099 if ( !num
[0] || !strcmpW( num
, szZero
) )
3106 /* the width must be a positive number
3107 * if a width is invalid, all remaining columns are hidden
3109 if ( !strncmpW( num
, negative
, 1 ) || !str_is_number( num
) ) {
3114 ZeroMemory( &lvc
, sizeof(lvc
) );
3115 lvc
.mask
= LVCF_TEXT
| LVCF_WIDTH
| LVCF_SUBITEM
;
3116 lvc
.cx
= atolW( num
);
3117 lvc
.pszText
= msi_dialog_get_uitext( dialog
, column_keys
[count
] );
3119 SendMessageW( control
->hwnd
, LVM_INSERTCOLUMNW
, count
++, (LPARAM
)&lvc
);
3120 msi_free( lvc
.pszText
);
3125 static LONGLONG
msi_vcl_get_cost( msi_dialog
*dialog
)
3127 MSIFEATURE
*feature
;
3129 LONGLONG total_cost
= 0;
3131 LIST_FOR_EACH_ENTRY( feature
, &dialog
->package
->features
, MSIFEATURE
, entry
)
3133 if (ERROR_SUCCESS
== (MSI_GetFeatureCost(dialog
->package
, feature
,
3134 MSICOSTTREE_SELFONLY
, INSTALLSTATE_LOCAL
, &each_cost
)))
3136 /* each_cost is in 512-byte units */
3137 total_cost
+= each_cost
* 512;
3139 if (ERROR_SUCCESS
== (MSI_GetFeatureCost(dialog
->package
, feature
,
3140 MSICOSTTREE_SELFONLY
, INSTALLSTATE_ABSENT
, &each_cost
)))
3142 /* each_cost is in 512-byte units */
3143 total_cost
-= each_cost
* 512;
3149 static void msi_dialog_vcl_add_drives( msi_dialog
*dialog
, msi_control
*control
)
3151 ULARGE_INTEGER total
, free
;
3152 LONGLONG difference
, cost
;
3153 WCHAR size_text
[MAX_PATH
];
3154 WCHAR cost_text
[MAX_PATH
];
3160 cost
= msi_vcl_get_cost(dialog
);
3161 StrFormatByteSizeW(cost
, cost_text
, MAX_PATH
);
3163 size
= GetLogicalDriveStringsW( 0, NULL
);
3164 if ( !size
) return;
3166 drives
= msi_alloc( (size
+ 1) * sizeof(WCHAR
) );
3167 if ( !drives
) return;
3169 GetLogicalDriveStringsW( size
, drives
);
3174 lvitem
.mask
= LVIF_TEXT
;
3176 lvitem
.iSubItem
= 0;
3177 lvitem
.pszText
= ptr
;
3178 lvitem
.cchTextMax
= lstrlenW(ptr
) + 1;
3179 SendMessageW( control
->hwnd
, LVM_INSERTITEMW
, 0, (LPARAM
)&lvitem
);
3181 GetDiskFreeSpaceExW(ptr
, &free
, &total
, NULL
);
3182 difference
= free
.QuadPart
- cost
;
3184 StrFormatByteSizeW(total
.QuadPart
, size_text
, MAX_PATH
);
3185 lvitem
.iSubItem
= 1;
3186 lvitem
.pszText
= size_text
;
3187 lvitem
.cchTextMax
= lstrlenW(size_text
) + 1;
3188 SendMessageW( control
->hwnd
, LVM_SETITEMW
, 0, (LPARAM
)&lvitem
);
3190 StrFormatByteSizeW(free
.QuadPart
, size_text
, MAX_PATH
);
3191 lvitem
.iSubItem
= 2;
3192 lvitem
.pszText
= size_text
;
3193 lvitem
.cchTextMax
= lstrlenW(size_text
) + 1;
3194 SendMessageW( control
->hwnd
, LVM_SETITEMW
, 0, (LPARAM
)&lvitem
);
3196 lvitem
.iSubItem
= 3;
3197 lvitem
.pszText
= cost_text
;
3198 lvitem
.cchTextMax
= lstrlenW(cost_text
) + 1;
3199 SendMessageW( control
->hwnd
, LVM_SETITEMW
, 0, (LPARAM
)&lvitem
);
3201 StrFormatByteSizeW(difference
, size_text
, MAX_PATH
);
3202 lvitem
.iSubItem
= 4;
3203 lvitem
.pszText
= size_text
;
3204 lvitem
.cchTextMax
= lstrlenW(size_text
) + 1;
3205 SendMessageW( control
->hwnd
, LVM_SETITEMW
, 0, (LPARAM
)&lvitem
);
3207 ptr
+= lstrlenW(ptr
) + 1;
3214 static UINT
msi_dialog_volumecost_list( msi_dialog
*dialog
, MSIRECORD
*rec
)
3216 msi_control
*control
;
3219 style
= LVS_REPORT
| WS_VSCROLL
| WS_HSCROLL
| LVS_SHAREIMAGELISTS
|
3220 LVS_AUTOARRANGE
| LVS_SINGLESEL
| WS_BORDER
|
3221 WS_CHILD
| WS_TABSTOP
| WS_GROUP
;
3222 control
= msi_dialog_add_control( dialog
, rec
, WC_LISTVIEWW
, style
);
3224 return ERROR_FUNCTION_FAILED
;
3226 msi_dialog_vcl_add_columns( dialog
, control
, rec
);
3227 msi_dialog_vcl_add_drives( dialog
, control
);
3229 return ERROR_SUCCESS
;
3232 /******************** VolumeSelect Combo ***************************************/
3234 static UINT
msi_dialog_volsel_handler( msi_dialog
*dialog
,
3235 msi_control
*control
, WPARAM param
)
3237 WCHAR text
[MAX_PATH
];
3242 if (HIWORD(param
) != CBN_SELCHANGE
)
3243 return ERROR_SUCCESS
;
3245 index
= SendMessageW( control
->hwnd
, CB_GETCURSEL
, 0, 0 );
3246 if ( index
== CB_ERR
)
3248 ERR("No ComboBox item selected!\n");
3249 return ERROR_FUNCTION_FAILED
;
3252 SendMessageW( control
->hwnd
, CB_GETLBTEXT
, index
, (LPARAM
)text
);
3254 indirect
= control
->attributes
& msidbControlAttributesIndirect
;
3255 prop
= msi_dialog_dup_property( dialog
, control
->property
, indirect
);
3257 msi_dialog_set_property( dialog
->package
, prop
, text
);
3260 return ERROR_SUCCESS
;
3263 static void msi_dialog_vsc_add_drives( msi_dialog
*dialog
, msi_control
*control
)
3268 size
= GetLogicalDriveStringsW( 0, NULL
);
3269 if ( !size
) return;
3271 drives
= msi_alloc( (size
+ 1) * sizeof(WCHAR
) );
3272 if ( !drives
) return;
3274 GetLogicalDriveStringsW( size
, drives
);
3279 SendMessageW( control
->hwnd
, CB_ADDSTRING
, 0, (LPARAM
)ptr
);
3280 ptr
+= lstrlenW(ptr
) + 1;
3286 static UINT
msi_dialog_volumeselect_combo( msi_dialog
*dialog
, MSIRECORD
*rec
)
3288 msi_control
*control
;
3292 /* FIXME: CBS_OWNERDRAWFIXED */
3293 style
= WS_CHILD
| WS_VISIBLE
| WS_GROUP
| WS_TABSTOP
|
3294 CBS_DROPDOWNLIST
| CBS_SORT
| CBS_HASSTRINGS
|
3295 WS_EX_LEFT
| WS_EX_LTRREADING
| WS_EX_RIGHTSCROLLBAR
;
3296 control
= msi_dialog_add_control( dialog
, rec
, WC_COMBOBOXW
, style
);
3298 return ERROR_FUNCTION_FAILED
;
3300 control
->attributes
= MSI_RecordGetInteger( rec
, 8 );
3301 control
->handler
= msi_dialog_volsel_handler
;
3302 prop
= MSI_RecordGetString( rec
, 9 );
3303 control
->property
= msi_dialog_dup_property( dialog
, prop
, FALSE
);
3305 msi_dialog_vsc_add_drives( dialog
, control
);
3307 return ERROR_SUCCESS
;
3310 static const struct control_handler msi_dialog_handler
[] =
3312 { szText
, msi_dialog_text_control
},
3313 { szPushButton
, msi_dialog_button_control
},
3314 { szLine
, msi_dialog_line_control
},
3315 { szBitmap
, msi_dialog_bitmap_control
},
3316 { szCheckBox
, msi_dialog_checkbox_control
},
3317 { szScrollableText
, msi_dialog_scrolltext_control
},
3318 { szComboBox
, msi_dialog_combo_control
},
3319 { szEdit
, msi_dialog_edit_control
},
3320 { szMaskedEdit
, msi_dialog_maskedit_control
},
3321 { szPathEdit
, msi_dialog_pathedit_control
},
3322 { szProgressBar
, msi_dialog_progress_bar
},
3323 { szRadioButtonGroup
, msi_dialog_radiogroup_control
},
3324 { szIcon
, msi_dialog_icon_control
},
3325 { szSelectionTree
, msi_dialog_selection_tree
},
3326 { szGroupBox
, msi_dialog_group_box
},
3327 { szListBox
, msi_dialog_list_box
},
3328 { szDirectoryCombo
, msi_dialog_directory_combo
},
3329 { szDirectoryList
, msi_dialog_directory_list
},
3330 { szVolumeCostList
, msi_dialog_volumecost_list
},
3331 { szVolumeSelectCombo
, msi_dialog_volumeselect_combo
},
3334 #define NUM_CONTROL_TYPES (sizeof msi_dialog_handler/sizeof msi_dialog_handler[0])
3336 static UINT
msi_dialog_create_controls( MSIRECORD
*rec
, LPVOID param
)
3338 msi_dialog
*dialog
= param
;
3339 LPCWSTR control_type
;
3342 /* find and call the function that can create this type of control */
3343 control_type
= MSI_RecordGetString( rec
, 3 );
3344 for( i
=0; i
<NUM_CONTROL_TYPES
; i
++ )
3345 if (!strcmpiW( msi_dialog_handler
[i
].control_type
, control_type
))
3347 if( i
!= NUM_CONTROL_TYPES
)
3348 msi_dialog_handler
[i
].func( dialog
, rec
);
3350 ERR("no handler for element type %s\n", debugstr_w(control_type
));
3352 return ERROR_SUCCESS
;
3355 static UINT
msi_dialog_fill_controls( msi_dialog
*dialog
)
3357 static const WCHAR query
[] = {
3358 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
3359 'C','o','n','t','r','o','l',' ','W','H','E','R','E',' ',
3360 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',0};
3363 MSIPACKAGE
*package
= dialog
->package
;
3365 TRACE("%p %s\n", dialog
, debugstr_w(dialog
->name
) );
3367 /* query the Control table for all the elements of the control */
3368 r
= MSI_OpenQuery( package
->db
, &view
, query
, dialog
->name
);
3369 if( r
!= ERROR_SUCCESS
)
3371 ERR("query failed for dialog %s\n", debugstr_w(dialog
->name
));
3372 return ERROR_INVALID_PARAMETER
;
3375 r
= MSI_IterateRecords( view
, 0, msi_dialog_create_controls
, dialog
);
3376 msiobj_release( &view
->hdr
);
3380 UINT
msi_dialog_reset( msi_dialog
*dialog
)
3382 /* FIXME: should restore the original values of any properties we changed */
3383 return msi_dialog_evaluate_control_conditions( dialog
);
3386 /* figure out the height of 10 point MS Sans Serif */
3387 static INT
msi_dialog_get_sans_serif_height( HWND hwnd
)
3389 static const WCHAR szSansSerif
[] = {
3390 'M','S',' ','S','a','n','s',' ','S','e','r','i','f',0 };
3395 HFONT hFont
, hOldFont
;
3398 hdc
= GetDC( hwnd
);
3401 memset( &lf
, 0, sizeof lf
);
3402 lf
.lfHeight
= MulDiv(12, GetDeviceCaps(hdc
, LOGPIXELSY
), 72);
3403 strcpyW( lf
.lfFaceName
, szSansSerif
);
3404 hFont
= CreateFontIndirectW(&lf
);
3407 hOldFont
= SelectObject( hdc
, hFont
);
3408 r
= GetTextMetricsW( hdc
, &tm
);
3410 height
= tm
.tmHeight
;
3411 SelectObject( hdc
, hOldFont
);
3412 DeleteObject( hFont
);
3414 ReleaseDC( hwnd
, hdc
);
3419 /* fetch the associated record from the Dialog table */
3420 static MSIRECORD
*msi_get_dialog_record( msi_dialog
*dialog
)
3422 static const WCHAR query
[] = {
3423 'S','E','L','E','C','T',' ','*',' ',
3424 'F','R','O','M',' ','D','i','a','l','o','g',' ',
3425 'W','H','E','R','E',' ',
3426 '`','D','i','a','l','o','g','`',' ','=',' ','\'','%','s','\'',0};
3427 MSIPACKAGE
*package
= dialog
->package
;
3428 MSIRECORD
*rec
= NULL
;
3430 TRACE("%p %s\n", dialog
, debugstr_w(dialog
->name
) );
3432 rec
= MSI_QueryGetRecord( package
->db
, query
, dialog
->name
);
3434 WARN("query failed for dialog %s\n", debugstr_w(dialog
->name
));
3439 static void msi_dialog_adjust_dialog_pos( msi_dialog
*dialog
, MSIRECORD
*rec
, LPRECT pos
)
3441 static const WCHAR szScreenX
[] = {'S','c','r','e','e','n','X',0};
3442 static const WCHAR szScreenY
[] = {'S','c','r','e','e','n','Y',0};
3449 center
.x
= MSI_RecordGetInteger( rec
, 2 );
3450 center
.y
= MSI_RecordGetInteger( rec
, 3 );
3452 sz
.cx
= MSI_RecordGetInteger( rec
, 4 );
3453 sz
.cy
= MSI_RecordGetInteger( rec
, 5 );
3455 sz
.cx
= msi_dialog_scale_unit( dialog
, sz
.cx
);
3456 sz
.cy
= msi_dialog_scale_unit( dialog
, sz
.cy
);
3458 xres
= msi_get_property_int( dialog
->package
->db
, szScreenX
, 0 );
3459 yres
= msi_get_property_int( dialog
->package
->db
, szScreenY
, 0 );
3461 center
.x
= MulDiv( center
.x
, xres
, 100 );
3462 center
.y
= MulDiv( center
.y
, yres
, 100 );
3464 /* turn the client pos into the window rectangle */
3465 if (dialog
->package
->center_x
&& dialog
->package
->center_y
)
3467 pos
->left
= dialog
->package
->center_x
- sz
.cx
/ 2.0;
3468 pos
->right
= pos
->left
+ sz
.cx
;
3469 pos
->top
= dialog
->package
->center_y
- sz
.cy
/ 2.0;
3470 pos
->bottom
= pos
->top
+ sz
.cy
;
3474 pos
->left
= center
.x
- sz
.cx
/2;
3475 pos
->right
= pos
->left
+ sz
.cx
;
3476 pos
->top
= center
.y
- sz
.cy
/2;
3477 pos
->bottom
= pos
->top
+ sz
.cy
;
3479 /* save the center */
3480 dialog
->package
->center_x
= center
.x
;
3481 dialog
->package
->center_y
= center
.y
;
3484 dialog
->size
.cx
= sz
.cx
;
3485 dialog
->size
.cy
= sz
.cy
;
3487 TRACE("%u %u %u %u\n", pos
->left
, pos
->top
, pos
->right
, pos
->bottom
);
3489 style
= GetWindowLongPtrW( dialog
->hwnd
, GWL_STYLE
);
3490 AdjustWindowRect( pos
, style
, FALSE
);
3493 static void msi_dialog_set_tab_order( msi_dialog
*dialog
, LPCWSTR first
)
3495 struct list tab_chain
;
3496 msi_control
*control
;
3497 HWND prev
= HWND_TOP
;
3499 list_init( &tab_chain
);
3500 if (!(control
= msi_dialog_find_control( dialog
, first
))) return;
3502 dialog
->hWndFocus
= control
->hwnd
;
3505 list_remove( &control
->entry
);
3506 list_add_tail( &tab_chain
, &control
->entry
);
3507 if (!control
->tabnext
) break;
3508 control
= msi_dialog_find_control( dialog
, control
->tabnext
);
3511 LIST_FOR_EACH_ENTRY( control
, &tab_chain
, msi_control
, entry
)
3513 SetWindowPos( control
->hwnd
, prev
, 0, 0, 0, 0,
3514 SWP_NOMOVE
| SWP_NOOWNERZORDER
| SWP_NOREDRAW
|
3515 SWP_NOREPOSITION
| SWP_NOSENDCHANGING
| SWP_NOSIZE
);
3516 prev
= control
->hwnd
;
3519 /* put them back on the main list */
3520 list_move_head( &dialog
->controls
, &tab_chain
);
3523 static LRESULT
msi_dialog_oncreate( HWND hwnd
, LPCREATESTRUCTW cs
)
3525 static const WCHAR df
[] = {
3526 'D','e','f','a','u','l','t','U','I','F','o','n','t',0 };
3527 static const WCHAR dfv
[] = {
3528 'M','S',' ','S','h','e','l','l',' ','D','l','g',0 };
3529 msi_dialog
*dialog
= cs
->lpCreateParams
;
3530 MSIRECORD
*rec
= NULL
;
3531 LPWSTR title
= NULL
;
3534 TRACE("%p %p\n", dialog
, dialog
->package
);
3536 dialog
->hwnd
= hwnd
;
3537 SetWindowLongPtrW( hwnd
, GWLP_USERDATA
, (LONG_PTR
) dialog
);
3539 rec
= msi_get_dialog_record( dialog
);
3542 TRACE("No record found for dialog %s\n", debugstr_w(dialog
->name
));
3546 dialog
->scale
= msi_dialog_get_sans_serif_height(dialog
->hwnd
);
3548 msi_dialog_adjust_dialog_pos( dialog
, rec
, &pos
);
3550 dialog
->attributes
= MSI_RecordGetInteger( rec
, 6 );
3552 dialog
->default_font
= msi_dup_property( dialog
->package
->db
, df
);
3553 if (!dialog
->default_font
)
3555 dialog
->default_font
= strdupW(dfv
);
3556 if (!dialog
->default_font
) return -1;
3559 title
= msi_get_deformatted_field( dialog
->package
, rec
, 7 );
3560 SetWindowTextW( hwnd
, title
);
3563 SetWindowPos( hwnd
, 0, pos
.left
, pos
.top
,
3564 pos
.right
- pos
.left
, pos
.bottom
- pos
.top
,
3565 SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_NOREDRAW
);
3567 msi_dialog_build_font_list( dialog
);
3568 msi_dialog_fill_controls( dialog
);
3569 msi_dialog_evaluate_control_conditions( dialog
);
3570 msi_dialog_set_tab_order( dialog
, MSI_RecordGetString( rec
, 8 ) );
3571 msiobj_release( &rec
->hdr
);
3576 static LRESULT
msi_dialog_oncommand( msi_dialog
*dialog
, WPARAM param
, HWND hwnd
)
3578 msi_control
*control
= NULL
;
3580 TRACE("%p %p %08lx\n", dialog
, hwnd
, param
);
3585 control
= msi_dialog_find_control( dialog
, dialog
->control_default
);
3587 case 2: /* escape */
3588 control
= msi_dialog_find_control( dialog
, dialog
->control_cancel
);
3591 control
= msi_dialog_find_control_by_hwnd( dialog
, hwnd
);
3596 if( control
->handler
)
3598 control
->handler( dialog
, control
, param
);
3599 msi_dialog_evaluate_control_conditions( dialog
);
3606 static LRESULT
msi_dialog_onnotify( msi_dialog
*dialog
, LPARAM param
)
3608 LPNMHDR nmhdr
= (LPNMHDR
) param
;
3609 msi_control
*control
= msi_dialog_find_control_by_hwnd( dialog
, nmhdr
->hwndFrom
);
3611 TRACE("%p %p\n", dialog
, nmhdr
->hwndFrom
);
3613 if ( control
&& control
->handler
)
3614 control
->handler( dialog
, control
, param
);
3619 static void msi_dialog_setfocus( msi_dialog
*dialog
)
3621 HWND hwnd
= dialog
->hWndFocus
;
3623 hwnd
= GetNextDlgTabItem( dialog
->hwnd
, hwnd
, TRUE
);
3624 hwnd
= GetNextDlgTabItem( dialog
->hwnd
, hwnd
, FALSE
);
3626 dialog
->hWndFocus
= hwnd
;
3629 static LRESULT WINAPI
MSIDialog_WndProc( HWND hwnd
, UINT msg
,
3630 WPARAM wParam
, LPARAM lParam
)
3632 msi_dialog
*dialog
= (LPVOID
) GetWindowLongPtrW( hwnd
, GWLP_USERDATA
);
3634 TRACE("0x%04x\n", msg
);
3639 dialog
->package
->center_x
= LOWORD(lParam
) + dialog
->size
.cx
/ 2.0;
3640 dialog
->package
->center_y
= HIWORD(lParam
) + dialog
->size
.cy
/ 2.0;
3644 return msi_dialog_oncreate( hwnd
, (LPCREATESTRUCTW
)lParam
);
3647 return msi_dialog_oncommand( dialog
, wParam
, (HWND
)lParam
);
3650 if( LOWORD(wParam
) == WA_INACTIVE
)
3651 dialog
->hWndFocus
= GetFocus();
3653 msi_dialog_setfocus( dialog
);
3657 msi_dialog_setfocus( dialog
);
3660 /* bounce back to our subclassed static control */
3661 case WM_CTLCOLORSTATIC
:
3662 return SendMessageW( (HWND
) lParam
, WM_CTLCOLORSTATIC
, wParam
, lParam
);
3665 dialog
->hwnd
= NULL
;
3668 return msi_dialog_onnotify( dialog
, lParam
);
3670 return DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
3673 static LRESULT WINAPI
MSIHiddenWindowProc( HWND hwnd
, UINT msg
,
3674 WPARAM wParam
, LPARAM lParam
)
3676 msi_dialog
*dialog
= (msi_dialog
*) lParam
;
3678 TRACE("%d %p\n", msg
, dialog
);
3682 case WM_MSI_DIALOG_CREATE
:
3683 return msi_dialog_run_message_loop( dialog
);
3684 case WM_MSI_DIALOG_DESTROY
:
3685 msi_dialog_destroy( dialog
);
3688 return DefWindowProcW( hwnd
, msg
, wParam
, lParam
);
3691 static BOOL
msi_dialog_register_class( void )
3695 ZeroMemory( &cls
, sizeof cls
);
3696 cls
.lpfnWndProc
= MSIDialog_WndProc
;
3697 cls
.hInstance
= NULL
;
3698 cls
.hIcon
= LoadIconW(0, (LPWSTR
)IDI_APPLICATION
);
3699 cls
.hCursor
= LoadCursorW(0, (LPWSTR
)IDC_ARROW
);
3700 cls
.hbrBackground
= (HBRUSH
)(COLOR_3DFACE
+ 1);
3701 cls
.lpszMenuName
= NULL
;
3702 cls
.lpszClassName
= szMsiDialogClass
;
3704 if( !RegisterClassW( &cls
) )
3707 cls
.lpfnWndProc
= MSIHiddenWindowProc
;
3708 cls
.lpszClassName
= szMsiHiddenWindow
;
3710 if( !RegisterClassW( &cls
) )
3713 uiThreadId
= GetCurrentThreadId();
3715 hMsiHiddenWindow
= CreateWindowW( szMsiHiddenWindow
, NULL
, WS_OVERLAPPED
,
3716 0, 0, 100, 100, NULL
, NULL
, NULL
, NULL
);
3717 if( !hMsiHiddenWindow
)
3723 /* functions that interface to other modules within MSI */
3725 msi_dialog
*msi_dialog_create( MSIPACKAGE
* package
,
3726 LPCWSTR szDialogName
, msi_dialog
*parent
,
3727 msi_dialog_event_handler event_handler
)
3729 MSIRECORD
*rec
= NULL
;
3732 TRACE("%p %s\n", package
, debugstr_w(szDialogName
));
3734 if (!hMsiHiddenWindow
)
3735 msi_dialog_register_class();
3737 /* allocate the structure for the dialog to use */
3738 dialog
= msi_alloc_zero( sizeof *dialog
+ sizeof(WCHAR
)*strlenW(szDialogName
) );
3741 strcpyW( dialog
->name
, szDialogName
);
3742 dialog
->parent
= parent
;
3743 msiobj_addref( &package
->hdr
);
3744 dialog
->package
= package
;
3745 dialog
->event_handler
= event_handler
;
3746 dialog
->finished
= 0;
3747 list_init( &dialog
->controls
);
3748 list_init( &dialog
->fonts
);
3750 /* verify that the dialog exists */
3751 rec
= msi_get_dialog_record( dialog
);
3754 msiobj_release( &package
->hdr
);
3758 dialog
->attributes
= MSI_RecordGetInteger( rec
, 6 );
3759 dialog
->control_default
= strdupW( MSI_RecordGetString( rec
, 9 ) );
3760 dialog
->control_cancel
= strdupW( MSI_RecordGetString( rec
, 10 ) );
3761 msiobj_release( &rec
->hdr
);
3766 static void msi_process_pending_messages( HWND hdlg
)
3770 while( PeekMessageW( &msg
, 0, 0, 0, PM_REMOVE
) )
3772 if( hdlg
&& IsDialogMessageW( hdlg
, &msg
))
3774 TranslateMessage( &msg
);
3775 DispatchMessageW( &msg
);
3779 void msi_dialog_end_dialog( msi_dialog
*dialog
)
3781 TRACE("%p\n", dialog
);
3782 dialog
->finished
= 1;
3783 PostMessageW(dialog
->hwnd
, WM_NULL
, 0, 0);
3786 void msi_dialog_check_messages( HANDLE handle
)
3790 /* in threads other than the UI thread, block */
3791 if( uiThreadId
!= GetCurrentThreadId() )
3793 if (!handle
) return;
3794 while (MsgWaitForMultipleObjectsEx( 1, &handle
, INFINITE
, QS_ALLINPUT
, 0 ) == WAIT_OBJECT_0
+ 1)
3797 while (PeekMessageW( &msg
, NULL
, 0, 0, PM_REMOVE
))
3799 TranslateMessage( &msg
);
3800 DispatchMessageW( &msg
);
3806 /* there's two choices for the UI thread */
3809 msi_process_pending_messages( NULL
);
3815 * block here until somebody creates a new dialog or
3816 * the handle we're waiting on becomes ready
3818 r
= MsgWaitForMultipleObjects( 1, &handle
, 0, INFINITE
, QS_ALLINPUT
);
3819 if( r
== WAIT_OBJECT_0
)
3824 UINT
msi_dialog_run_message_loop( msi_dialog
*dialog
)
3829 if( uiThreadId
!= GetCurrentThreadId() )
3830 return SendMessageW( hMsiHiddenWindow
, WM_MSI_DIALOG_CREATE
, 0, (LPARAM
) dialog
);
3832 /* create the dialog window, don't show it yet */
3833 style
= WS_OVERLAPPED
;
3834 if( dialog
->attributes
& msidbDialogAttributesVisible
)
3835 style
|= WS_VISIBLE
;
3837 hwnd
= CreateWindowW( szMsiDialogClass
, dialog
->name
, style
,
3838 CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
,
3839 NULL
, NULL
, NULL
, dialog
);
3842 ERR("Failed to create dialog %s\n", debugstr_w( dialog
->name
));
3843 return ERROR_FUNCTION_FAILED
;
3846 ShowWindow( hwnd
, SW_SHOW
);
3847 /* UpdateWindow( hwnd ); - and causes the transparent static controls not to paint */
3849 if( dialog
->attributes
& msidbDialogAttributesModal
)
3851 while( !dialog
->finished
)
3853 MsgWaitForMultipleObjects( 0, NULL
, 0, INFINITE
, QS_ALLINPUT
);
3854 msi_process_pending_messages( dialog
->hwnd
);
3858 return ERROR_IO_PENDING
;
3860 return ERROR_SUCCESS
;
3863 static void msi_dialog_do_preview( msi_dialog
*dialog
)
3866 dialog
->attributes
|= msidbDialogAttributesVisible
;
3867 dialog
->attributes
&= ~msidbDialogAttributesModal
;
3868 msi_dialog_run_message_loop( dialog
);
3871 void msi_dialog_destroy( msi_dialog
*dialog
)
3873 msi_font
*font
, *next
;
3875 if( uiThreadId
!= GetCurrentThreadId() )
3877 SendMessageW( hMsiHiddenWindow
, WM_MSI_DIALOG_DESTROY
, 0, (LPARAM
) dialog
);
3882 ShowWindow( dialog
->hwnd
, SW_HIDE
);
3885 DestroyWindow( dialog
->hwnd
);
3887 /* unsubscribe events */
3888 ControlEvent_CleanupDialogSubscriptions(dialog
->package
, dialog
->name
);
3890 /* destroy the list of controls */
3891 while( !list_empty( &dialog
->controls
) )
3895 t
= LIST_ENTRY( list_head( &dialog
->controls
),
3896 msi_control
, entry
);
3897 msi_destroy_control( t
);
3900 /* destroy the list of fonts */
3901 LIST_FOR_EACH_ENTRY_SAFE( font
, next
, &dialog
->fonts
, msi_font
, entry
)
3903 list_remove( &font
->entry
);
3904 DeleteObject( font
->hfont
);
3907 msi_free( dialog
->default_font
);
3909 msi_free( dialog
->control_default
);
3910 msi_free( dialog
->control_cancel
);
3911 msiobj_release( &dialog
->package
->hdr
);
3912 dialog
->package
= NULL
;
3916 void msi_dialog_unregister_class( void )
3918 DestroyWindow( hMsiHiddenWindow
);
3919 hMsiHiddenWindow
= NULL
;
3920 UnregisterClassW( szMsiDialogClass
, NULL
);
3921 UnregisterClassW( szMsiHiddenWindow
, NULL
);
3925 static UINT
error_dialog_handler(MSIPACKAGE
*package
, LPCWSTR event
,
3926 LPCWSTR argument
, msi_dialog
* dialog
)
3928 static const WCHAR end_dialog
[] = {'E','n','d','D','i','a','l','o','g',0};
3929 static const WCHAR error_abort
[] = {'E','r','r','o','r','A','b','o','r','t',0};
3930 static const WCHAR error_cancel
[] = {'E','r','r','o','r','C','a','n','c','e','l',0};
3931 static const WCHAR error_no
[] = {'E','r','r','o','r','N','o',0};
3932 static const WCHAR result_prop
[] = {
3933 'M','S','I','E','r','r','o','r','D','i','a','l','o','g','R','e','s','u','l','t',0
3936 if ( strcmpW( event
, end_dialog
) )
3937 return ERROR_SUCCESS
;
3939 if ( !strcmpW( argument
, error_abort
) || !strcmpW( argument
, error_cancel
) ||
3940 !strcmpW( argument
, error_no
) )
3942 msi_set_property( package
->db
, result_prop
, error_abort
);
3945 ControlEvent_CleanupSubscriptions(package
);
3946 msi_dialog_end_dialog( dialog
);
3948 return ERROR_SUCCESS
;
3951 static UINT
msi_error_dialog_set_error( MSIPACKAGE
*package
, LPWSTR error_dialog
, LPWSTR error
)
3955 static const WCHAR update
[] =
3956 {'U','P','D','A','T','E',' ','`','C','o','n','t','r','o','l','`',' ',
3957 'S','E','T',' ','`','T','e','x','t','`',' ','=',' ','\'','%','s','\'',' ',
3958 'W','H','E','R','E', ' ','`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',' ',
3959 'A','N','D',' ','`','C','o','n','t','r','o','l','`',' ','=',' ',
3960 '\'','E','r','r','o','r','T','e','x','t','\'',0};
3962 row
= MSI_QueryGetRecord( package
->db
, update
, error
, error_dialog
);
3964 return ERROR_FUNCTION_FAILED
;
3966 msiobj_release(&row
->hdr
);
3967 return ERROR_SUCCESS
;
3970 UINT
msi_spawn_error_dialog( MSIPACKAGE
*package
, LPWSTR error_dialog
, LPWSTR error
)
3973 WCHAR result
[MAX_PATH
];
3974 UINT r
= ERROR_SUCCESS
;
3975 DWORD size
= MAX_PATH
;
3978 static const WCHAR pn_prop
[] = {'P','r','o','d','u','c','t','N','a','m','e',0};
3979 static const WCHAR title_fmt
[] = {'%','s',' ','W','a','r','n','i','n','g',0};
3980 static const WCHAR error_abort
[] = {'E','r','r','o','r','A','b','o','r','t',0};
3981 static const WCHAR result_prop
[] = {
3982 'M','S','I','E','r','r','o','r','D','i','a','l','o','g','R','e','s','u','l','t',0
3985 if ((package
->ui_level
& INSTALLUILEVEL_MASK
) == INSTALLUILEVEL_NONE
) return ERROR_SUCCESS
;
3987 if ( !error_dialog
)
3989 LPWSTR product_name
= msi_dup_property( package
->db
, pn_prop
);
3990 WCHAR title
[MAX_PATH
];
3992 sprintfW( title
, title_fmt
, product_name
);
3993 res
= MessageBoxW( NULL
, error
, title
, MB_OKCANCEL
| MB_ICONWARNING
);
3995 msi_free( product_name
);
3998 return ERROR_SUCCESS
;
4000 return ERROR_FUNCTION_FAILED
;
4003 r
= msi_error_dialog_set_error( package
, error_dialog
, error
);
4004 if ( r
!= ERROR_SUCCESS
)
4007 dialog
= msi_dialog_create( package
, error_dialog
, package
->dialog
,
4008 error_dialog_handler
);
4010 return ERROR_FUNCTION_FAILED
;
4012 dialog
->finished
= FALSE
;
4013 r
= msi_dialog_run_message_loop( dialog
);
4014 if ( r
!= ERROR_SUCCESS
)
4017 r
= msi_get_property( package
->db
, result_prop
, result
, &size
);
4018 if ( r
!= ERROR_SUCCESS
)
4021 if ( !strcmpW( result
, error_abort
) )
4022 r
= ERROR_FUNCTION_FAILED
;
4025 msi_dialog_destroy( dialog
);
4030 static void MSI_ClosePreview( MSIOBJECTHDR
*arg
)
4032 MSIPREVIEW
*preview
= (MSIPREVIEW
*)arg
;
4033 msiobj_release( &preview
->package
->hdr
);
4036 static MSIPREVIEW
*MSI_EnableUIPreview( MSIDATABASE
*db
)
4038 MSIPREVIEW
*preview
= NULL
;
4039 MSIPACKAGE
*package
;
4041 package
= MSI_CreatePackage( db
, NULL
);
4044 preview
= alloc_msiobject( MSIHANDLETYPE_PREVIEW
, sizeof(MSIPREVIEW
), MSI_ClosePreview
);
4047 preview
->package
= package
;
4048 msiobj_addref( &package
->hdr
);
4050 msiobj_release( &package
->hdr
);
4055 UINT WINAPI
MsiEnableUIPreview( MSIHANDLE hdb
, MSIHANDLE
*phPreview
)
4058 MSIPREVIEW
*preview
;
4059 UINT r
= ERROR_FUNCTION_FAILED
;
4061 TRACE("%d %p\n", hdb
, phPreview
);
4063 db
= msihandle2msiinfo( hdb
, MSIHANDLETYPE_DATABASE
);
4066 IWineMsiRemoteDatabase
*remote_database
;
4068 remote_database
= (IWineMsiRemoteDatabase
*)msi_get_remote( hdb
);
4069 if (!remote_database
)
4070 return ERROR_INVALID_HANDLE
;
4074 IWineMsiRemoteDatabase_Release( remote_database
);
4075 WARN("MsiEnableUIPreview not allowed during a custom action!\n");
4077 return ERROR_FUNCTION_FAILED
;
4079 preview
= MSI_EnableUIPreview( db
);
4082 *phPreview
= alloc_msihandle( &preview
->hdr
);
4083 msiobj_release( &preview
->hdr
);
4086 r
= ERROR_NOT_ENOUGH_MEMORY
;
4088 msiobj_release( &db
->hdr
);
4092 static UINT
preview_event_handler( MSIPACKAGE
*package
, LPCWSTR event
,
4093 LPCWSTR argument
, msi_dialog
*dialog
)
4095 MESSAGE("Preview dialog event '%s' (arg='%s')\n", debugstr_w(event
), debugstr_w(argument
));
4096 return ERROR_SUCCESS
;
4099 static UINT
MSI_PreviewDialogW( MSIPREVIEW
*preview
, LPCWSTR szDialogName
)
4101 msi_dialog
*dialog
= NULL
;
4102 UINT r
= ERROR_SUCCESS
;
4104 if (preview
->dialog
)
4105 msi_dialog_destroy( preview
->dialog
);
4107 /* an empty name means we should just destroy the current preview dialog */
4110 dialog
= msi_dialog_create( preview
->package
, szDialogName
, NULL
, preview_event_handler
);
4112 msi_dialog_do_preview( dialog
);
4114 r
= ERROR_FUNCTION_FAILED
;
4116 preview
->dialog
= dialog
;
4120 UINT WINAPI
MsiPreviewDialogW( MSIHANDLE hPreview
, LPCWSTR szDialogName
)
4122 MSIPREVIEW
*preview
;
4125 TRACE("%d %s\n", hPreview
, debugstr_w(szDialogName
));
4127 preview
= msihandle2msiinfo( hPreview
, MSIHANDLETYPE_PREVIEW
);
4129 return ERROR_INVALID_HANDLE
;
4131 r
= MSI_PreviewDialogW( preview
, szDialogName
);
4132 msiobj_release( &preview
->hdr
);
4136 UINT WINAPI
MsiPreviewDialogA( MSIHANDLE hPreview
, LPCSTR szDialogName
)
4141 TRACE("%d %s\n", hPreview
, debugstr_a(szDialogName
));
4145 strW
= strdupAtoW( szDialogName
);
4147 return ERROR_OUTOFMEMORY
;
4149 r
= MsiPreviewDialogW( hPreview
, strW
);
4154 UINT WINAPI
MsiPreviewBillboardW( MSIHANDLE hPreview
, LPCWSTR szControlName
, LPCWSTR szBillboard
)
4156 FIXME("%d %s %s\n", hPreview
, debugstr_w(szControlName
), debugstr_w(szBillboard
));
4157 return ERROR_CALL_NOT_IMPLEMENTED
;
4160 UINT WINAPI
MsiPreviewBillboardA( MSIHANDLE hPreview
, LPCSTR szControlName
, LPCSTR szBillboard
)
4162 FIXME("%d %s %s\n", hPreview
, debugstr_a(szControlName
), debugstr_a(szBillboard
));
4163 return ERROR_CALL_NOT_IMPLEMENTED
;