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
21 #define WIN32_NO_STATUS
23 #define COM_NO_WINDOWS_H
26 #define NONAMELESSUNION
27 #define NONAMELESSSTRUCT
32 //#include "winbase.h"
34 //#include "winuser.h"
38 //#include "msidefs.h"
45 #include <msiserver.h>
47 #include <wine/debug.h>
48 #include <wine/unicode.h>
50 WINE_DEFAULT_DEBUG_CHANNEL(msi
);
52 extern HINSTANCE msi_hInstance
;
54 struct msi_control_tag
;
55 typedef struct msi_control_tag msi_control
;
56 typedef UINT (*msi_handler
)( msi_dialog
*, msi_control
*, WPARAM
);
57 typedef void (*msi_update
)( msi_dialog
*, msi_control
* );
59 struct msi_control_tag
72 float progress_current
;
74 BOOL progress_backwards
;
79 typedef struct msi_font_tag
91 msi_dialog_event_handler event_handler
;
101 LPWSTR control_default
;
102 LPWSTR control_cancel
;
106 typedef UINT (*msi_dialog_control_func
)( msi_dialog
*dialog
, MSIRECORD
*rec
);
107 struct control_handler
109 LPCWSTR control_type
;
110 msi_dialog_control_func func
;
119 } radio_button_group_descr
;
121 static const WCHAR szMsiDialogClass
[] = { 'M','s','i','D','i','a','l','o','g','C','l','o','s','e','C','l','a','s','s',0 };
122 static const WCHAR szMsiHiddenWindow
[] = { 'M','s','i','H','i','d','d','e','n','W','i','n','d','o','w',0 };
123 static const WCHAR szStatic
[] = { 'S','t','a','t','i','c',0 };
124 static const WCHAR szButton
[] = { 'B','U','T','T','O','N', 0 };
125 static const WCHAR szButtonData
[] = { 'M','S','I','D','A','T','A',0 };
126 static const WCHAR szProgress
[] = { 'P','r','o','g','r','e','s','s',0 };
127 static const WCHAR szText
[] = { 'T','e','x','t',0 };
128 static const WCHAR szPushButton
[] = { 'P','u','s','h','B','u','t','t','o','n',0 };
129 static const WCHAR szLine
[] = { 'L','i','n','e',0 };
130 static const WCHAR szBitmap
[] = { 'B','i','t','m','a','p',0 };
131 static const WCHAR szCheckBox
[] = { 'C','h','e','c','k','B','o','x',0 };
132 static const WCHAR szScrollableText
[] = { 'S','c','r','o','l','l','a','b','l','e','T','e','x','t',0 };
133 static const WCHAR szComboBox
[] = { 'C','o','m','b','o','B','o','x',0 };
134 static const WCHAR szEdit
[] = { 'E','d','i','t',0 };
135 static const WCHAR szMaskedEdit
[] = { 'M','a','s','k','e','d','E','d','i','t',0 };
136 static const WCHAR szPathEdit
[] = { 'P','a','t','h','E','d','i','t',0 };
137 static const WCHAR szProgressBar
[] = { 'P','r','o','g','r','e','s','s','B','a','r',0 };
138 static const WCHAR szSetProgress
[] = { 'S','e','t','P','r','o','g','r','e','s','s',0 };
139 static const WCHAR szRadioButtonGroup
[] = { 'R','a','d','i','o','B','u','t','t','o','n','G','r','o','u','p',0 };
140 static const WCHAR szIcon
[] = { 'I','c','o','n',0 };
141 static const WCHAR szSelectionTree
[] = { 'S','e','l','e','c','t','i','o','n','T','r','e','e',0 };
142 static const WCHAR szGroupBox
[] = { 'G','r','o','u','p','B','o','x',0 };
143 static const WCHAR szListBox
[] = { 'L','i','s','t','B','o','x',0 };
144 static const WCHAR szDirectoryCombo
[] = { 'D','i','r','e','c','t','o','r','y','C','o','m','b','o',0 };
145 static const WCHAR szDirectoryList
[] = { 'D','i','r','e','c','t','o','r','y','L','i','s','t',0 };
146 static const WCHAR szVolumeCostList
[] = { 'V','o','l','u','m','e','C','o','s','t','L','i','s','t',0 };
147 static const WCHAR szVolumeSelectCombo
[] = { 'V','o','l','u','m','e','S','e','l','e','c','t','C','o','m','b','o',0 };
148 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};
149 static const WCHAR szSelectionPath
[] = {'S','e','l','e','c','t','i','o','n','P','a','t','h',0};
150 static const WCHAR szProperty
[] = {'P','r','o','p','e','r','t','y',0};
152 /* dialog sequencing */
154 #define WM_MSI_DIALOG_CREATE (WM_USER+0x100)
155 #define WM_MSI_DIALOG_DESTROY (WM_USER+0x101)
157 #define USER_INSTALLSTATE_ALL 0x1000
159 static DWORD uiThreadId
;
160 static HWND hMsiHiddenWindow
;
162 static LPWSTR
msi_get_window_text( HWND hwnd
)
168 buf
= msi_alloc( sz
*sizeof(WCHAR
) );
171 r
= GetWindowTextW( hwnd
, buf
, sz
);
175 buf
= msi_realloc( buf
, sz
*sizeof(WCHAR
) );
181 static INT
msi_dialog_scale_unit( msi_dialog
*dialog
, INT val
)
183 return MulDiv( val
, dialog
->scale
, 12 );
186 static msi_control
*msi_dialog_find_control( msi_dialog
*dialog
, LPCWSTR name
)
188 msi_control
*control
;
194 LIST_FOR_EACH_ENTRY( control
, &dialog
->controls
, msi_control
, entry
)
195 if( !strcmpW( control
->name
, name
) ) /* FIXME: case sensitive? */
200 static msi_control
*msi_dialog_find_control_by_type( msi_dialog
*dialog
, LPCWSTR type
)
202 msi_control
*control
;
208 LIST_FOR_EACH_ENTRY( control
, &dialog
->controls
, msi_control
, entry
)
209 if( !strcmpW( control
->type
, type
) ) /* FIXME: case sensitive? */
214 static msi_control
*msi_dialog_find_control_by_hwnd( msi_dialog
*dialog
, HWND hwnd
)
216 msi_control
*control
;
220 LIST_FOR_EACH_ENTRY( control
, &dialog
->controls
, msi_control
, entry
)
221 if( hwnd
== control
->hwnd
)
226 static LPWSTR
msi_get_deformatted_field( MSIPACKAGE
*package
, MSIRECORD
*rec
, int field
)
228 LPCWSTR str
= MSI_RecordGetString( rec
, field
);
232 deformat_string( package
, str
, &ret
);
236 static LPWSTR
msi_dialog_dup_property( msi_dialog
*dialog
, LPCWSTR property
, BOOL indirect
)
244 prop
= msi_dup_property( dialog
->package
->db
, property
);
247 prop
= strdupW( property
);
252 msi_dialog
*msi_dialog_get_parent( msi_dialog
*dialog
)
254 return dialog
->parent
;
257 LPWSTR
msi_dialog_get_name( msi_dialog
*dialog
)
263 * msi_dialog_get_style
265 * Extract the {\style} string from the front of the text to display and
266 * update the pointer. Only the last style in a list is applied.
268 static LPWSTR
msi_dialog_get_style( LPCWSTR p
, LPCWSTR
*rest
)
279 while ((first
= strchrW( p
, '{' )) && (q
= strchrW( first
+ 1, '}' )))
282 if( *p
!= '\\' && *p
!= '&' )
285 /* little bit of sanity checking to stop us getting confused with RTF */
286 for( i
=++p
; i
<q
; i
++ )
287 if( *i
== '}' || *i
== '\\' )
297 ret
= msi_alloc( len
*sizeof(WCHAR
) );
300 memcpy( ret
, p
, len
*sizeof(WCHAR
) );
305 static UINT
msi_dialog_add_font( MSIRECORD
*rec
, LPVOID param
)
307 msi_dialog
*dialog
= param
;
314 /* create a font and add it to the list */
315 name
= MSI_RecordGetString( rec
, 1 );
316 font
= msi_alloc( FIELD_OFFSET( msi_font
, name
[strlenW( name
) + 1] ));
317 strcpyW( font
->name
, name
);
318 list_add_head( &dialog
->fonts
, &font
->entry
);
320 font
->color
= MSI_RecordGetInteger( rec
, 4 );
322 memset( &lf
, 0, sizeof lf
);
323 face
= MSI_RecordGetString( rec
, 2 );
324 lf
.lfHeight
= MSI_RecordGetInteger( rec
, 3 );
325 style
= MSI_RecordGetInteger( rec
, 5 );
326 if( style
& msidbTextStyleStyleBitsBold
)
327 lf
.lfWeight
= FW_BOLD
;
328 if( style
& msidbTextStyleStyleBitsItalic
)
330 if( style
& msidbTextStyleStyleBitsUnderline
)
331 lf
.lfUnderline
= TRUE
;
332 if( style
& msidbTextStyleStyleBitsStrike
)
333 lf
.lfStrikeOut
= TRUE
;
334 lstrcpynW( lf
.lfFaceName
, face
, LF_FACESIZE
);
336 /* adjust the height */
337 hdc
= GetDC( dialog
->hwnd
);
340 lf
.lfHeight
= -MulDiv(lf
.lfHeight
, GetDeviceCaps(hdc
, LOGPIXELSY
), 72);
341 ReleaseDC( dialog
->hwnd
, hdc
);
344 font
->hfont
= CreateFontIndirectW( &lf
);
346 TRACE("Adding font style %s\n", debugstr_w(font
->name
) );
348 return ERROR_SUCCESS
;
351 static msi_font
*msi_dialog_find_font( msi_dialog
*dialog
, LPCWSTR name
)
353 msi_font
*font
= NULL
;
355 LIST_FOR_EACH_ENTRY( font
, &dialog
->fonts
, msi_font
, entry
)
356 if( !strcmpW( font
->name
, name
) ) /* FIXME: case sensitive? */
362 static UINT
msi_dialog_set_font( msi_dialog
*dialog
, HWND hwnd
, LPCWSTR name
)
366 font
= msi_dialog_find_font( dialog
, name
);
368 SendMessageW( hwnd
, WM_SETFONT
, (WPARAM
) font
->hfont
, TRUE
);
370 ERR("No font entry for %s\n", debugstr_w(name
));
371 return ERROR_SUCCESS
;
374 static UINT
msi_dialog_build_font_list( msi_dialog
*dialog
)
376 static const WCHAR query
[] = {
377 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
378 '`','T','e','x','t','S','t','y','l','e','`',0};
382 TRACE("dialog %p\n", dialog
);
384 r
= MSI_OpenQuery( dialog
->package
->db
, &view
, query
);
385 if( r
!= ERROR_SUCCESS
)
388 r
= MSI_IterateRecords( view
, NULL
, msi_dialog_add_font
, dialog
);
389 msiobj_release( &view
->hdr
);
393 static void msi_destroy_control( msi_control
*t
)
395 list_remove( &t
->entry
);
396 /* leave dialog->hwnd - destroying parent destroys child windows */
397 msi_free( t
->property
);
398 msi_free( t
->value
);
400 DeleteObject( t
->hBitmap
);
402 DestroyIcon( t
->hIcon
);
403 msi_free( t
->tabnext
);
406 FreeLibrary( t
->hDll
);
410 static msi_control
*msi_dialog_create_window( msi_dialog
*dialog
,
411 MSIRECORD
*rec
, DWORD exstyle
, LPCWSTR szCls
, LPCWSTR name
, LPCWSTR text
,
412 DWORD style
, HWND parent
)
414 DWORD x
, y
, width
, height
;
415 LPWSTR font
= NULL
, title_font
= NULL
;
416 LPCWSTR title
= NULL
;
417 msi_control
*control
;
421 control
= msi_alloc( FIELD_OFFSET( msi_control
, name
[strlenW( name
) + 1] ));
425 strcpyW( control
->name
, name
);
426 list_add_tail( &dialog
->controls
, &control
->entry
);
427 control
->handler
= NULL
;
428 control
->update
= NULL
;
429 control
->property
= NULL
;
430 control
->value
= NULL
;
431 control
->hBitmap
= NULL
;
432 control
->hIcon
= NULL
;
433 control
->hDll
= NULL
;
434 control
->tabnext
= strdupW( MSI_RecordGetString( rec
, 11) );
435 control
->type
= strdupW( MSI_RecordGetString( rec
, 3 ) );
436 control
->progress_current
= 0;
437 control
->progress_max
= 100;
438 control
->progress_backwards
= FALSE
;
440 x
= MSI_RecordGetInteger( rec
, 4 );
441 y
= MSI_RecordGetInteger( rec
, 5 );
442 width
= MSI_RecordGetInteger( rec
, 6 );
443 height
= MSI_RecordGetInteger( rec
, 7 );
445 x
= msi_dialog_scale_unit( dialog
, x
);
446 y
= msi_dialog_scale_unit( dialog
, y
);
447 width
= msi_dialog_scale_unit( dialog
, width
);
448 height
= msi_dialog_scale_unit( dialog
, height
);
452 deformat_string( dialog
->package
, text
, &title_font
);
453 font
= msi_dialog_get_style( title_font
, &title
);
456 control
->hwnd
= CreateWindowExW( exstyle
, szCls
, title
, style
,
457 x
, y
, width
, height
, parent
, NULL
, NULL
, NULL
);
459 TRACE("Dialog %s control %s hwnd %p\n",
460 debugstr_w(dialog
->name
), debugstr_w(text
), control
->hwnd
);
462 msi_dialog_set_font( dialog
, control
->hwnd
,
463 font
? font
: dialog
->default_font
);
465 msi_free( title_font
);
471 static LPWSTR
msi_dialog_get_uitext( msi_dialog
*dialog
, LPCWSTR key
)
476 static const WCHAR query
[] = {
477 's','e','l','e','c','t',' ','*',' ',
478 'f','r','o','m',' ','`','U','I','T','e','x','t','`',' ',
479 'w','h','e','r','e',' ','`','K','e','y','`',' ','=',' ','\'','%','s','\'',0
482 rec
= MSI_QueryGetRecord( dialog
->package
->db
, query
, key
);
483 if (!rec
) return NULL
;
484 text
= strdupW( MSI_RecordGetString( rec
, 2 ) );
485 msiobj_release( &rec
->hdr
);
489 static MSIRECORD
*msi_get_binary_record( MSIDATABASE
*db
, LPCWSTR name
)
491 static const WCHAR query
[] = {
492 's','e','l','e','c','t',' ','*',' ',
493 'f','r','o','m',' ','B','i','n','a','r','y',' ',
494 'w','h','e','r','e',' ',
495 '`','N','a','m','e','`',' ','=',' ','\'','%','s','\'',0
498 return MSI_QueryGetRecord( db
, query
, name
);
501 static LPWSTR
msi_create_tmp_path(void)
507 r
= GetTempPathW( MAX_PATH
, tmp
);
510 len
= lstrlenW( tmp
) + 20;
511 path
= msi_alloc( len
* sizeof (WCHAR
) );
514 r
= GetTempFileNameW( tmp
, szMsi
, 0, path
);
524 static HANDLE
msi_load_image( MSIDATABASE
*db
, LPCWSTR name
, UINT type
,
525 UINT cx
, UINT cy
, UINT flags
)
527 MSIRECORD
*rec
= NULL
;
528 HANDLE himage
= NULL
;
532 TRACE("%p %s %u %u %08x\n", db
, debugstr_w(name
), cx
, cy
, flags
);
534 tmp
= msi_create_tmp_path();
538 rec
= msi_get_binary_record( db
, name
);
541 r
= MSI_RecordStreamToFile( rec
, 2, tmp
);
542 if( r
== ERROR_SUCCESS
)
544 himage
= LoadImageW( 0, tmp
, type
, cx
, cy
, flags
);
546 msiobj_release( &rec
->hdr
);
554 static HICON
msi_load_icon( MSIDATABASE
*db
, LPCWSTR text
, UINT attributes
)
556 DWORD cx
= 0, cy
= 0, flags
;
558 flags
= LR_LOADFROMFILE
| LR_DEFAULTSIZE
;
559 if( attributes
& msidbControlAttributesFixedSize
)
561 flags
&= ~LR_DEFAULTSIZE
;
562 if( attributes
& msidbControlAttributesIconSize16
)
567 if( attributes
& msidbControlAttributesIconSize32
)
572 /* msidbControlAttributesIconSize48 handled by above logic */
574 return msi_load_image( db
, text
, IMAGE_ICON
, cx
, cy
, flags
);
577 static void msi_dialog_update_controls( msi_dialog
*dialog
, LPCWSTR property
)
579 msi_control
*control
;
581 LIST_FOR_EACH_ENTRY( control
, &dialog
->controls
, msi_control
, entry
)
583 if ( control
->property
&& !strcmpW( control
->property
, property
) && control
->update
)
584 control
->update( dialog
, control
);
588 static void msi_dialog_set_property( MSIPACKAGE
*package
, LPCWSTR property
, LPCWSTR value
)
590 UINT r
= msi_set_property( package
->db
, property
, value
, -1 );
591 if (r
== ERROR_SUCCESS
&& !strcmpW( property
, szSourceDir
))
592 msi_reset_folders( package
, TRUE
);
595 static MSIFEATURE
*msi_seltree_feature_from_item( HWND hwnd
, HTREEITEM hItem
)
599 /* get the feature from the item */
600 memset( &tvi
, 0, sizeof tvi
);
602 tvi
.mask
= TVIF_PARAM
| TVIF_HANDLE
;
603 SendMessageW( hwnd
, TVM_GETITEMW
, 0, (LPARAM
)&tvi
);
604 return (MSIFEATURE
*)tvi
.lParam
;
607 struct msi_selection_tree_info
615 static MSIFEATURE
*msi_seltree_get_selected_feature( msi_control
*control
)
617 struct msi_selection_tree_info
*info
= GetPropW( control
->hwnd
, szButtonData
);
618 return msi_seltree_feature_from_item( control
->hwnd
, info
->selected
);
621 /* called from the Control Event subscription code */
622 void msi_dialog_handle_event( msi_dialog
* dialog
, LPCWSTR control
,
623 LPCWSTR attribute
, MSIRECORD
*rec
)
626 LPCWSTR font_text
, text
= NULL
;
629 ctrl
= msi_dialog_find_control( dialog
, control
);
632 if( !strcmpW( attribute
, szText
) )
634 font_text
= MSI_RecordGetString( rec
, 1 );
635 font
= msi_dialog_get_style( font_text
, &text
);
636 if (!text
) text
= szEmpty
;
637 SetWindowTextW( ctrl
->hwnd
, text
);
639 msi_dialog_check_messages( NULL
);
641 else if( !strcmpW( attribute
, szProgress
) )
643 DWORD func
, val1
, val2
, units
;
645 func
= MSI_RecordGetInteger( rec
, 1 );
646 val1
= MSI_RecordGetInteger( rec
, 2 );
647 val2
= MSI_RecordGetInteger( rec
, 3 );
649 TRACE("progress: func %u val1 %u val2 %u\n", func
, val1
, val2
);
655 SendMessageW( ctrl
->hwnd
, PBM_SETRANGE
, 0, MAKELPARAM(0,100) );
658 ctrl
->progress_max
= units
? units
: 100;
659 ctrl
->progress_current
= units
;
660 ctrl
->progress_backwards
= TRUE
;
661 SendMessageW( ctrl
->hwnd
, PBM_SETPOS
, 100, 0 );
665 ctrl
->progress_max
= units
? units
: 100;
666 ctrl
->progress_current
= 0;
667 ctrl
->progress_backwards
= FALSE
;
668 SendMessageW( ctrl
->hwnd
, PBM_SETPOS
, 0, 0 );
671 case 1: /* action data increment */
672 if (val2
) dialog
->package
->action_progress_increment
= val1
;
673 else dialog
->package
->action_progress_increment
= 0;
676 if (ctrl
->progress_backwards
)
678 if (units
>= ctrl
->progress_current
) ctrl
->progress_current
-= units
;
679 else ctrl
->progress_current
= 0;
683 if (ctrl
->progress_current
+ units
< ctrl
->progress_max
) ctrl
->progress_current
+= units
;
684 else ctrl
->progress_current
= ctrl
->progress_max
;
686 SendMessageW( ctrl
->hwnd
, PBM_SETPOS
, MulDiv(100, ctrl
->progress_current
, ctrl
->progress_max
), 0 );
689 ctrl
->progress_max
+= units
;
692 FIXME("Unknown progress message %u\n", func
);
696 else if ( !strcmpW( attribute
, szProperty
) )
698 MSIFEATURE
*feature
= msi_seltree_get_selected_feature( ctrl
);
699 if (feature
) msi_dialog_set_property( dialog
->package
, ctrl
->property
, feature
->Directory
);
701 else if ( !strcmpW( attribute
, szSelectionPath
) )
703 BOOL indirect
= ctrl
->attributes
& msidbControlAttributesIndirect
;
704 LPWSTR path
= msi_dialog_dup_property( dialog
, ctrl
->property
, indirect
);
706 SetWindowTextW( ctrl
->hwnd
, path
);
711 FIXME("Attribute %s not being set\n", debugstr_w(attribute
));
716 static void msi_dialog_map_events(msi_dialog
* dialog
, LPCWSTR control
)
718 static const WCHAR Query
[] = {
719 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
720 '`','E','v','e','n','t','M','a','p','p','i','n','g','`',' ',
721 'W','H','E','R','E',' ',
722 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',' ',
724 '`','C','o','n','t','r','o','l','_','`',' ','=',' ','\'','%','s','\'',0
727 LPCWSTR event
, attribute
;
729 row
= MSI_QueryGetRecord( dialog
->package
->db
, Query
, dialog
->name
, control
);
733 event
= MSI_RecordGetString( row
, 3 );
734 attribute
= MSI_RecordGetString( row
, 4 );
735 ControlEvent_SubscribeToEvent( dialog
->package
, dialog
, event
, control
, attribute
);
736 msiobj_release( &row
->hdr
);
739 /* everything except radio buttons */
740 static msi_control
*msi_dialog_add_control( msi_dialog
*dialog
,
741 MSIRECORD
*rec
, LPCWSTR szCls
, DWORD style
)
747 name
= MSI_RecordGetString( rec
, 2 );
748 attributes
= MSI_RecordGetInteger( rec
, 8 );
749 text
= MSI_RecordGetString( rec
, 10 );
751 TRACE("%s, %s, %08x, %s, %08x\n", debugstr_w(szCls
), debugstr_w(name
),
752 attributes
, debugstr_w(text
), style
);
754 if( attributes
& msidbControlAttributesVisible
)
756 if( ~attributes
& msidbControlAttributesEnabled
)
757 style
|= WS_DISABLED
;
758 if( attributes
& msidbControlAttributesSunken
)
759 exstyle
|= WS_EX_CLIENTEDGE
;
761 msi_dialog_map_events(dialog
, name
);
763 return msi_dialog_create_window( dialog
, rec
, exstyle
, szCls
, name
,
764 text
, style
, dialog
->hwnd
);
775 * we don't erase our own background,
776 * so we have to make sure that the parent window redraws first
778 static void msi_text_on_settext( HWND hWnd
)
783 hParent
= GetParent( hWnd
);
784 GetWindowRect( hWnd
, &rc
);
785 MapWindowPoints( NULL
, hParent
, (LPPOINT
) &rc
, 2 );
786 InvalidateRect( hParent
, &rc
, TRUE
);
789 static LRESULT WINAPI
790 MSIText_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
792 struct msi_text_info
*info
;
795 TRACE("%p %04x %08lx %08lx\n", hWnd
, msg
, wParam
, lParam
);
797 info
= GetPropW(hWnd
, szButtonData
);
799 if( msg
== WM_CTLCOLORSTATIC
&&
800 ( info
->attributes
& msidbControlAttributesTransparent
) )
802 SetBkMode( (HDC
)wParam
, TRANSPARENT
);
803 return (LRESULT
) GetStockObject(NULL_BRUSH
);
806 r
= CallWindowProcW(info
->oldproc
, hWnd
, msg
, wParam
, lParam
);
808 SetTextColor( (HDC
)wParam
, info
->font
->color
);
813 msi_text_on_settext( hWnd
);
817 RemovePropW( hWnd
, szButtonData
);
824 static UINT
msi_dialog_text_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
826 msi_control
*control
;
827 struct msi_text_info
*info
;
828 LPCWSTR text
, ptr
, prop
, control_name
;
831 TRACE("%p %p\n", dialog
, rec
);
833 control
= msi_dialog_add_control( dialog
, rec
, szStatic
, SS_LEFT
| WS_GROUP
);
835 return ERROR_FUNCTION_FAILED
;
837 info
= msi_alloc( sizeof *info
);
839 return ERROR_SUCCESS
;
841 control_name
= MSI_RecordGetString( rec
, 2 );
842 control
->attributes
= MSI_RecordGetInteger( rec
, 8 );
843 prop
= MSI_RecordGetString( rec
, 9 );
844 control
->property
= msi_dialog_dup_property( dialog
, prop
, FALSE
);
846 text
= MSI_RecordGetString( rec
, 10 );
847 font_name
= msi_dialog_get_style( text
, &ptr
);
848 info
->font
= ( font_name
) ? msi_dialog_find_font( dialog
, font_name
) : NULL
;
849 msi_free( font_name
);
851 info
->attributes
= MSI_RecordGetInteger( rec
, 8 );
852 if( info
->attributes
& msidbControlAttributesTransparent
)
853 SetWindowLongPtrW( control
->hwnd
, GWL_EXSTYLE
, WS_EX_TRANSPARENT
);
855 info
->oldproc
= (WNDPROC
) SetWindowLongPtrW( control
->hwnd
, GWLP_WNDPROC
,
856 (LONG_PTR
)MSIText_WndProc
);
857 SetPropW( control
->hwnd
, szButtonData
, info
);
859 ControlEvent_SubscribeToEvent( dialog
->package
, dialog
,
860 szSelectionPath
, control_name
, szSelectionPath
);
862 return ERROR_SUCCESS
;
865 /* strip any leading text style label from text field */
866 static WCHAR
*msi_get_binary_name( MSIPACKAGE
*package
, MSIRECORD
*rec
)
870 text
= msi_get_deformatted_field( package
, rec
, 10 );
875 while (*p
&& *p
!= '{') p
++;
876 if (!*p
++) return text
;
878 while (*p
&& *p
!= '}') p
++;
879 if (!*p
++) return text
;
886 static UINT
msi_dialog_set_property_event( msi_dialog
*dialog
, LPCWSTR event
, LPCWSTR arg
)
888 static const WCHAR szNullArg
[] = {'{','}',0};
889 LPWSTR p
, prop
, arg_fmt
= NULL
;
892 len
= strlenW( event
);
893 prop
= msi_alloc( len
* sizeof(WCHAR
) );
894 strcpyW( prop
, &event
[1] );
895 p
= strchrW( prop
, ']' );
896 if (p
&& (p
[1] == 0 || p
[1] == ' '))
899 if (strcmpW( szNullArg
, arg
))
900 deformat_string( dialog
->package
, arg
, &arg_fmt
);
901 msi_dialog_set_property( dialog
->package
, prop
, arg_fmt
);
902 msi_dialog_update_controls( dialog
, prop
);
905 else ERR("Badly formatted property string - what happens?\n");
907 return ERROR_SUCCESS
;
910 static UINT
msi_dialog_send_event( msi_dialog
*dialog
, LPCWSTR event
, LPCWSTR arg
)
912 LPWSTR event_fmt
= NULL
, arg_fmt
= NULL
;
914 TRACE("Sending control event %s %s\n", debugstr_w(event
), debugstr_w(arg
));
916 deformat_string( dialog
->package
, event
, &event_fmt
);
917 deformat_string( dialog
->package
, arg
, &arg_fmt
);
919 dialog
->event_handler( dialog
->package
, event_fmt
, arg_fmt
, dialog
);
921 msi_free( event_fmt
);
924 return ERROR_SUCCESS
;
927 static UINT
msi_dialog_control_event( MSIRECORD
*rec
, LPVOID param
)
929 msi_dialog
*dialog
= param
;
930 LPCWSTR condition
, event
, arg
;
933 condition
= MSI_RecordGetString( rec
, 5 );
934 r
= MSI_EvaluateConditionW( dialog
->package
, condition
);
935 if (r
== MSICONDITION_TRUE
|| r
== MSICONDITION_NONE
)
937 event
= MSI_RecordGetString( rec
, 3 );
938 arg
= MSI_RecordGetString( rec
, 4 );
940 msi_dialog_set_property_event( dialog
, event
, arg
);
942 msi_dialog_send_event( dialog
, event
, arg
);
944 return ERROR_SUCCESS
;
947 static UINT
msi_dialog_button_handler( msi_dialog
*dialog
, msi_control
*control
, WPARAM param
)
949 static const WCHAR query
[] = {
950 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
951 'C','o','n','t','r','o','l','E','v','e','n','t',' ','W','H','E','R','E',' ',
952 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',' ','A','N','D',' ',
953 '`','C','o','n','t','r','o','l','_','`',' ','=',' ','\'','%','s','\'',' ',
954 'O','R','D','E','R',' ','B','Y',' ','`','O','r','d','e','r','i','n','g','`',0};
958 if (HIWORD(param
) != BN_CLICKED
)
959 return ERROR_SUCCESS
;
961 r
= MSI_OpenQuery( dialog
->package
->db
, &view
, query
, dialog
->name
, control
->name
);
962 if (r
!= ERROR_SUCCESS
)
964 ERR("query failed\n");
965 return ERROR_SUCCESS
;
967 r
= MSI_IterateRecords( view
, 0, msi_dialog_control_event
, dialog
);
968 msiobj_release( &view
->hdr
);
972 static UINT
msi_dialog_button_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
974 msi_control
*control
;
975 UINT attributes
, style
;
977 TRACE("%p %p\n", dialog
, rec
);
980 attributes
= MSI_RecordGetInteger( rec
, 8 );
981 if( attributes
& msidbControlAttributesIcon
)
984 control
= msi_dialog_add_control( dialog
, rec
, szButton
, style
);
986 return ERROR_FUNCTION_FAILED
;
988 control
->handler
= msi_dialog_button_handler
;
990 if (attributes
& msidbControlAttributesIcon
)
993 LPWSTR name
= msi_get_binary_name( dialog
->package
, rec
);
994 control
->hIcon
= msi_load_icon( dialog
->package
->db
, name
, attributes
);
997 SendMessageW( control
->hwnd
, BM_SETIMAGE
, IMAGE_ICON
, (LPARAM
) control
->hIcon
);
1000 ERR("Failed to load icon %s\n", debugstr_w(name
));
1004 return ERROR_SUCCESS
;
1007 static LPWSTR
msi_get_checkbox_value( msi_dialog
*dialog
, LPCWSTR prop
)
1009 static const WCHAR query
[] = {
1010 'S','E','L','E','C','T',' ','*',' ',
1011 'F','R','O','M',' ','`','C','h','e','c','k','B','o','x','`',' ',
1012 'W','H','E','R','E',' ',
1013 '`','P','r','o','p','e','r','t','y','`',' ','=',' ',
1016 MSIRECORD
*rec
= NULL
;
1019 /* find if there is a value associated with the checkbox */
1020 rec
= MSI_QueryGetRecord( dialog
->package
->db
, query
, prop
);
1024 ret
= msi_get_deformatted_field( dialog
->package
, rec
, 2 );
1025 if( ret
&& !ret
[0] )
1030 msiobj_release( &rec
->hdr
);
1034 ret
= msi_dup_property( dialog
->package
->db
, prop
);
1035 if( ret
&& !ret
[0] )
1044 static UINT
msi_dialog_get_checkbox_state( msi_dialog
*dialog
, msi_control
*control
)
1046 WCHAR state
[2] = {0};
1049 msi_get_property( dialog
->package
->db
, control
->property
, state
, &sz
);
1050 return state
[0] ? 1 : 0;
1053 static void msi_dialog_set_checkbox_state( msi_dialog
*dialog
, msi_control
*control
, UINT state
)
1055 static const WCHAR szState
[] = {'1',0};
1058 /* if uncheck then the property is set to NULL */
1061 msi_dialog_set_property( dialog
->package
, control
->property
, NULL
);
1065 /* check for a custom state */
1066 if (control
->value
&& control
->value
[0])
1067 val
= control
->value
;
1071 msi_dialog_set_property( dialog
->package
, control
->property
, val
);
1074 static void msi_dialog_checkbox_sync_state( msi_dialog
*dialog
, msi_control
*control
)
1076 UINT state
= msi_dialog_get_checkbox_state( dialog
, control
);
1077 SendMessageW( control
->hwnd
, BM_SETCHECK
, state
? BST_CHECKED
: BST_UNCHECKED
, 0 );
1080 static UINT
msi_dialog_checkbox_handler( msi_dialog
*dialog
, msi_control
*control
, WPARAM param
)
1084 if (HIWORD(param
) != BN_CLICKED
)
1085 return ERROR_SUCCESS
;
1087 TRACE("clicked checkbox %s, set %s\n", debugstr_w(control
->name
), debugstr_w(control
->property
));
1089 state
= msi_dialog_get_checkbox_state( dialog
, control
);
1090 state
= state
? 0 : 1;
1091 msi_dialog_set_checkbox_state( dialog
, control
, state
);
1092 msi_dialog_checkbox_sync_state( dialog
, control
);
1094 return msi_dialog_button_handler( dialog
, control
, param
);
1097 static UINT
msi_dialog_checkbox_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1099 msi_control
*control
;
1102 TRACE("%p %p\n", dialog
, rec
);
1104 control
= msi_dialog_add_control( dialog
, rec
, szButton
, BS_CHECKBOX
| BS_MULTILINE
| WS_TABSTOP
);
1105 control
->handler
= msi_dialog_checkbox_handler
;
1106 control
->update
= msi_dialog_checkbox_sync_state
;
1107 prop
= MSI_RecordGetString( rec
, 9 );
1110 control
->property
= strdupW( prop
);
1111 control
->value
= msi_get_checkbox_value( dialog
, prop
);
1112 TRACE("control %s value %s\n", debugstr_w(control
->property
), debugstr_w(control
->value
));
1114 msi_dialog_checkbox_sync_state( dialog
, control
);
1115 return ERROR_SUCCESS
;
1118 static UINT
msi_dialog_line_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1122 DWORD style
, exstyle
= 0;
1123 DWORD x
, y
, width
, height
;
1124 msi_control
*control
;
1126 TRACE("%p %p\n", dialog
, rec
);
1128 style
= WS_CHILD
| SS_ETCHEDHORZ
| SS_SUNKEN
;
1130 name
= MSI_RecordGetString( rec
, 2 );
1131 attributes
= MSI_RecordGetInteger( rec
, 8 );
1133 if( attributes
& msidbControlAttributesVisible
)
1134 style
|= WS_VISIBLE
;
1135 if( ~attributes
& msidbControlAttributesEnabled
)
1136 style
|= WS_DISABLED
;
1137 if( attributes
& msidbControlAttributesSunken
)
1138 exstyle
|= WS_EX_CLIENTEDGE
;
1140 msi_dialog_map_events(dialog
, name
);
1142 control
= msi_alloc( FIELD_OFFSET(msi_control
, name
[strlenW( name
) + 1] ));
1144 return ERROR_OUTOFMEMORY
;
1146 strcpyW( control
->name
, name
);
1147 list_add_head( &dialog
->controls
, &control
->entry
);
1148 control
->handler
= NULL
;
1149 control
->property
= NULL
;
1150 control
->value
= NULL
;
1151 control
->hBitmap
= NULL
;
1152 control
->hIcon
= NULL
;
1153 control
->hDll
= NULL
;
1154 control
->tabnext
= strdupW( MSI_RecordGetString( rec
, 11) );
1155 control
->type
= strdupW( MSI_RecordGetString( rec
, 3 ) );
1156 control
->progress_current
= 0;
1157 control
->progress_max
= 100;
1158 control
->progress_backwards
= FALSE
;
1160 x
= MSI_RecordGetInteger( rec
, 4 );
1161 y
= MSI_RecordGetInteger( rec
, 5 );
1162 width
= MSI_RecordGetInteger( rec
, 6 );
1164 x
= msi_dialog_scale_unit( dialog
, x
);
1165 y
= msi_dialog_scale_unit( dialog
, y
);
1166 width
= msi_dialog_scale_unit( dialog
, width
);
1167 height
= 2; /* line is exactly 2 units in height */
1169 control
->hwnd
= CreateWindowExW( exstyle
, szStatic
, NULL
, style
,
1170 x
, y
, width
, height
, dialog
->hwnd
, NULL
, NULL
, NULL
);
1172 TRACE("Dialog %s control %s hwnd %p\n",
1173 debugstr_w(dialog
->name
), debugstr_w(name
), control
->hwnd
);
1175 return ERROR_SUCCESS
;
1178 /******************** Scroll Text ********************************************/
1180 struct msi_scrolltext_info
1183 msi_control
*control
;
1187 static LRESULT WINAPI
1188 MSIScrollText_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1190 struct msi_scrolltext_info
*info
;
1193 TRACE("%p %04x %08lx %08lx\n", hWnd
, msg
, wParam
, lParam
);
1195 info
= GetPropW( hWnd
, szButtonData
);
1197 r
= CallWindowProcW( info
->oldproc
, hWnd
, msg
, wParam
, lParam
);
1202 return DLGC_WANTARROWS
;
1205 RemovePropW( hWnd
, szButtonData
);
1208 /* native MSI sets a wait cursor here */
1209 msi_dialog_button_handler( info
->dialog
, info
->control
, BN_CLICKED
);
1215 struct msi_streamin_info
1222 static DWORD CALLBACK
1223 msi_richedit_stream_in( DWORD_PTR arg
, LPBYTE buffer
, LONG count
, LONG
*pcb
)
1225 struct msi_streamin_info
*info
= (struct msi_streamin_info
*) arg
;
1227 if( (count
+ info
->offset
) > info
->length
)
1228 count
= info
->length
- info
->offset
;
1229 memcpy( buffer
, &info
->string
[ info
->offset
], count
);
1231 info
->offset
+= count
;
1233 TRACE("%d/%d\n", info
->offset
, info
->length
);
1238 static void msi_scrolltext_add_text( msi_control
*control
, LPCWSTR text
)
1240 struct msi_streamin_info info
;
1243 info
.string
= strdupWtoA( text
);
1245 info
.length
= lstrlenA( info
.string
) + 1;
1247 es
.dwCookie
= (DWORD_PTR
) &info
;
1249 es
.pfnCallback
= msi_richedit_stream_in
;
1251 SendMessageW( control
->hwnd
, EM_STREAMIN
, SF_RTF
, (LPARAM
) &es
);
1253 msi_free( info
.string
);
1256 static UINT
msi_dialog_scrolltext_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1258 static const WCHAR szRichEdit20W
[] = {'R','i','c','h','E','d','i','t','2','0','W',0};
1259 struct msi_scrolltext_info
*info
;
1260 msi_control
*control
;
1265 info
= msi_alloc( sizeof *info
);
1267 return ERROR_FUNCTION_FAILED
;
1269 hRichedit
= LoadLibraryA("riched20");
1271 style
= WS_BORDER
| ES_MULTILINE
| WS_VSCROLL
|
1272 ES_READONLY
| ES_AUTOVSCROLL
| WS_TABSTOP
;
1273 control
= msi_dialog_add_control( dialog
, rec
, szRichEdit20W
, style
);
1276 FreeLibrary( hRichedit
);
1278 return ERROR_FUNCTION_FAILED
;
1281 control
->hDll
= hRichedit
;
1283 info
->dialog
= dialog
;
1284 info
->control
= control
;
1286 /* subclass the static control */
1287 info
->oldproc
= (WNDPROC
) SetWindowLongPtrW( control
->hwnd
, GWLP_WNDPROC
,
1288 (LONG_PTR
)MSIScrollText_WndProc
);
1289 SetPropW( control
->hwnd
, szButtonData
, info
);
1291 /* add the text into the richedit */
1292 text
= MSI_RecordGetString( rec
, 10 );
1294 msi_scrolltext_add_text( control
, text
);
1296 return ERROR_SUCCESS
;
1299 static HBITMAP
msi_load_picture( MSIDATABASE
*db
, LPCWSTR name
,
1300 INT cx
, INT cy
, DWORD flags
)
1302 HBITMAP hOleBitmap
= 0, hBitmap
= 0, hOldSrcBitmap
, hOldDestBitmap
;
1303 MSIRECORD
*rec
= NULL
;
1304 IStream
*stm
= NULL
;
1305 IPicture
*pic
= NULL
;
1310 rec
= msi_get_binary_record( db
, name
);
1314 r
= MSI_RecordGetIStream( rec
, 2, &stm
);
1315 msiobj_release( &rec
->hdr
);
1316 if( r
!= ERROR_SUCCESS
)
1319 r
= OleLoadPicture( stm
, 0, TRUE
, &IID_IPicture
, (LPVOID
*) &pic
);
1320 IStream_Release( stm
);
1323 ERR("failed to load picture\n");
1327 r
= IPicture_get_Handle( pic
, (OLE_HANDLE
*) &hOleBitmap
);
1330 ERR("failed to get bitmap handle\n");
1334 /* make the bitmap the desired size */
1335 r
= GetObjectW( hOleBitmap
, sizeof bm
, &bm
);
1336 if (r
!= sizeof bm
)
1338 ERR("failed to get bitmap size\n");
1342 if (flags
& LR_DEFAULTSIZE
)
1348 srcdc
= CreateCompatibleDC( NULL
);
1349 hOldSrcBitmap
= SelectObject( srcdc
, hOleBitmap
);
1350 destdc
= CreateCompatibleDC( NULL
);
1351 hBitmap
= CreateCompatibleBitmap( srcdc
, cx
, cy
);
1352 hOldDestBitmap
= SelectObject( destdc
, hBitmap
);
1353 StretchBlt( destdc
, 0, 0, cx
, cy
,
1354 srcdc
, 0, 0, bm
.bmWidth
, bm
.bmHeight
, SRCCOPY
);
1355 SelectObject( srcdc
, hOldSrcBitmap
);
1356 SelectObject( destdc
, hOldDestBitmap
);
1362 IPicture_Release( pic
);
1366 static UINT
msi_dialog_bitmap_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1368 UINT cx
, cy
, flags
, style
, attributes
;
1369 msi_control
*control
;
1372 flags
= LR_LOADFROMFILE
;
1373 style
= SS_BITMAP
| SS_LEFT
| WS_GROUP
;
1375 attributes
= MSI_RecordGetInteger( rec
, 8 );
1376 if( attributes
& msidbControlAttributesFixedSize
)
1378 flags
|= LR_DEFAULTSIZE
;
1379 style
|= SS_CENTERIMAGE
;
1382 control
= msi_dialog_add_control( dialog
, rec
, szStatic
, style
);
1383 cx
= MSI_RecordGetInteger( rec
, 6 );
1384 cy
= MSI_RecordGetInteger( rec
, 7 );
1385 cx
= msi_dialog_scale_unit( dialog
, cx
);
1386 cy
= msi_dialog_scale_unit( dialog
, cy
);
1388 name
= msi_get_binary_name( dialog
->package
, rec
);
1389 control
->hBitmap
= msi_load_picture( dialog
->package
->db
, name
, cx
, cy
, flags
);
1390 if( control
->hBitmap
)
1391 SendMessageW( control
->hwnd
, STM_SETIMAGE
,
1392 IMAGE_BITMAP
, (LPARAM
) control
->hBitmap
);
1394 ERR("Failed to load bitmap %s\n", debugstr_w(name
));
1398 return ERROR_SUCCESS
;
1401 static UINT
msi_dialog_icon_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1403 msi_control
*control
;
1409 control
= msi_dialog_add_control( dialog
, rec
, szStatic
,
1410 SS_ICON
| SS_CENTERIMAGE
| WS_GROUP
);
1412 attributes
= MSI_RecordGetInteger( rec
, 8 );
1413 name
= msi_get_binary_name( dialog
->package
, rec
);
1414 control
->hIcon
= msi_load_icon( dialog
->package
->db
, name
, attributes
);
1415 if( control
->hIcon
)
1416 SendMessageW( control
->hwnd
, STM_SETICON
, (WPARAM
) control
->hIcon
, 0 );
1418 ERR("Failed to load bitmap %s\n", debugstr_w(name
));
1420 return ERROR_SUCCESS
;
1423 /******************** Combo Box ***************************************/
1425 struct msi_combobox_info
1435 static LRESULT WINAPI
MSIComboBox_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1437 struct msi_combobox_info
*info
;
1441 TRACE("%p %04x %08lx %08lx\n", hWnd
, msg
, wParam
, lParam
);
1443 info
= GetPropW( hWnd
, szButtonData
);
1447 r
= CallWindowProcW( info
->oldproc
, hWnd
, msg
, wParam
, lParam
);
1452 for (j
= 0; j
< info
->num_items
; j
++)
1453 msi_free( info
->items
[j
] );
1454 msi_free( info
->items
);
1456 RemovePropW( hWnd
, szButtonData
);
1463 static UINT
msi_combobox_add_item( MSIRECORD
*rec
, LPVOID param
)
1465 struct msi_combobox_info
*info
= param
;
1466 LPCWSTR value
, text
;
1469 value
= MSI_RecordGetString( rec
, 3 );
1470 text
= MSI_RecordGetString( rec
, 4 );
1472 info
->items
[info
->addpos_items
] = strdupW( value
);
1474 pos
= SendMessageW( info
->hwnd
, CB_ADDSTRING
, 0, (LPARAM
)text
);
1475 SendMessageW( info
->hwnd
, CB_SETITEMDATA
, pos
, (LPARAM
)info
->items
[info
->addpos_items
] );
1476 info
->addpos_items
++;
1478 return ERROR_SUCCESS
;
1481 static UINT
msi_combobox_add_items( struct msi_combobox_info
*info
, LPCWSTR property
)
1483 static const WCHAR query
[] = {
1484 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
1485 '`','C','o','m','b','o','B','o','x','`',' ','W','H','E','R','E',' ',
1486 '`','P','r','o','p','e','r','t','y','`',' ','=',' ','\'','%','s','\'',' ',
1487 'O','R','D','E','R',' ','B','Y',' ','`','O','r','d','e','r','`',0};
1492 r
= MSI_OpenQuery( info
->dialog
->package
->db
, &view
, query
, property
);
1493 if (r
!= ERROR_SUCCESS
)
1496 /* just get the number of records */
1498 r
= MSI_IterateRecords( view
, &count
, NULL
, NULL
);
1499 if (r
!= ERROR_SUCCESS
)
1501 msiobj_release( &view
->hdr
);
1504 info
->num_items
= count
;
1505 info
->items
= msi_alloc( sizeof(*info
->items
) * count
);
1507 r
= MSI_IterateRecords( view
, NULL
, msi_combobox_add_item
, info
);
1508 msiobj_release( &view
->hdr
);
1512 static UINT
msi_dialog_set_control_condition( MSIRECORD
*rec
, LPVOID param
)
1514 static const WCHAR szHide
[] = {'H','i','d','e',0};
1515 static const WCHAR szShow
[] = {'S','h','o','w',0};
1516 static const WCHAR szDisable
[] = {'D','i','s','a','b','l','e',0};
1517 static const WCHAR szEnable
[] = {'E','n','a','b','l','e',0};
1518 static const WCHAR szDefault
[] = {'D','e','f','a','u','l','t',0};
1519 msi_dialog
*dialog
= param
;
1520 msi_control
*control
;
1521 LPCWSTR name
, action
, condition
;
1524 name
= MSI_RecordGetString( rec
, 2 );
1525 action
= MSI_RecordGetString( rec
, 3 );
1526 condition
= MSI_RecordGetString( rec
, 4 );
1527 r
= MSI_EvaluateConditionW( dialog
->package
, condition
);
1528 control
= msi_dialog_find_control( dialog
, name
);
1529 if (r
== MSICONDITION_TRUE
&& control
)
1531 TRACE("%s control %s\n", debugstr_w(action
), debugstr_w(name
));
1533 /* FIXME: case sensitive? */
1534 if (!strcmpW( action
, szHide
))
1535 ShowWindow(control
->hwnd
, SW_HIDE
);
1536 else if (!strcmpW( action
, szShow
))
1537 ShowWindow(control
->hwnd
, SW_SHOW
);
1538 else if (!strcmpW( action
, szDisable
))
1539 EnableWindow(control
->hwnd
, FALSE
);
1540 else if (!strcmpW( action
, szEnable
))
1541 EnableWindow(control
->hwnd
, TRUE
);
1542 else if (!strcmpW( action
, szDefault
))
1543 SetFocus(control
->hwnd
);
1545 FIXME("Unhandled action %s\n", debugstr_w(action
));
1547 return ERROR_SUCCESS
;
1550 static UINT
msi_dialog_evaluate_control_conditions( msi_dialog
*dialog
)
1552 static const WCHAR query
[] = {
1553 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
1554 'C','o','n','t','r','o','l','C','o','n','d','i','t','i','o','n',' ',
1555 'W','H','E','R','E',' ','`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',0};
1558 MSIPACKAGE
*package
= dialog
->package
;
1560 TRACE("%p %s\n", dialog
, debugstr_w(dialog
->name
));
1562 /* query the Control table for all the elements of the control */
1563 r
= MSI_OpenQuery( package
->db
, &view
, query
, dialog
->name
);
1564 if (r
!= ERROR_SUCCESS
)
1565 return ERROR_SUCCESS
;
1567 r
= MSI_IterateRecords( view
, 0, msi_dialog_set_control_condition
, dialog
);
1568 msiobj_release( &view
->hdr
);
1572 static UINT
msi_dialog_combobox_handler( msi_dialog
*dialog
, msi_control
*control
, WPARAM param
)
1574 struct msi_combobox_info
*info
;
1578 if (HIWORD(param
) != CBN_SELCHANGE
&& HIWORD(param
) != CBN_EDITCHANGE
)
1579 return ERROR_SUCCESS
;
1581 info
= GetPropW( control
->hwnd
, szButtonData
);
1582 index
= SendMessageW( control
->hwnd
, CB_GETCURSEL
, 0, 0 );
1583 if (index
== CB_ERR
)
1584 value
= msi_get_window_text( control
->hwnd
);
1586 value
= (LPWSTR
) SendMessageW( control
->hwnd
, CB_GETITEMDATA
, index
, 0 );
1588 msi_dialog_set_property( info
->dialog
->package
, control
->property
, value
);
1589 msi_dialog_evaluate_control_conditions( info
->dialog
);
1591 if (index
== CB_ERR
)
1594 return ERROR_SUCCESS
;
1597 static void msi_dialog_combobox_update( msi_dialog
*dialog
, msi_control
*control
)
1599 struct msi_combobox_info
*info
;
1603 info
= GetPropW( control
->hwnd
, szButtonData
);
1605 value
= msi_dup_property( dialog
->package
->db
, control
->property
);
1608 SendMessageW( control
->hwnd
, CB_SETCURSEL
, -1, 0 );
1612 for (j
= 0; j
< info
->num_items
; j
++)
1614 tmp
= (LPWSTR
) SendMessageW( control
->hwnd
, CB_GETITEMDATA
, j
, 0 );
1615 if (!strcmpW( value
, tmp
))
1619 if (j
< info
->num_items
)
1621 SendMessageW( control
->hwnd
, CB_SETCURSEL
, j
, 0 );
1625 SendMessageW( control
->hwnd
, CB_SETCURSEL
, -1, 0 );
1626 SetWindowTextW( control
->hwnd
, value
);
1632 static UINT
msi_dialog_combo_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1634 struct msi_combobox_info
*info
;
1635 msi_control
*control
;
1636 DWORD attributes
, style
;
1639 info
= msi_alloc( sizeof *info
);
1641 return ERROR_FUNCTION_FAILED
;
1643 style
= CBS_AUTOHSCROLL
| WS_TABSTOP
| WS_GROUP
| WS_CHILD
;
1644 attributes
= MSI_RecordGetInteger( rec
, 8 );
1645 if ( ~attributes
& msidbControlAttributesSorted
)
1647 if ( attributes
& msidbControlAttributesComboList
)
1648 style
|= CBS_DROPDOWNLIST
;
1650 style
|= CBS_DROPDOWN
;
1652 control
= msi_dialog_add_control( dialog
, rec
, WC_COMBOBOXW
, style
);
1656 return ERROR_FUNCTION_FAILED
;
1659 control
->handler
= msi_dialog_combobox_handler
;
1660 control
->update
= msi_dialog_combobox_update
;
1662 prop
= MSI_RecordGetString( rec
, 9 );
1663 control
->property
= msi_dialog_dup_property( dialog
, prop
, FALSE
);
1666 info
->dialog
= dialog
;
1667 info
->hwnd
= control
->hwnd
;
1669 info
->addpos_items
= 0;
1670 info
->oldproc
= (WNDPROC
)SetWindowLongPtrW( control
->hwnd
, GWLP_WNDPROC
,
1671 (LONG_PTR
)MSIComboBox_WndProc
);
1672 SetPropW( control
->hwnd
, szButtonData
, info
);
1674 if (control
->property
)
1675 msi_combobox_add_items( info
, control
->property
);
1677 msi_dialog_combobox_update( dialog
, control
);
1679 return ERROR_SUCCESS
;
1682 static UINT
msi_dialog_edit_handler( msi_dialog
*dialog
, msi_control
*control
, WPARAM param
)
1686 if (HIWORD(param
) != EN_CHANGE
)
1687 return ERROR_SUCCESS
;
1689 TRACE("edit %s contents changed, set %s\n", debugstr_w(control
->name
), debugstr_w(control
->property
));
1691 buf
= msi_get_window_text( control
->hwnd
);
1692 msi_dialog_set_property( dialog
->package
, control
->property
, buf
);
1695 return ERROR_SUCCESS
;
1698 /* length of 2^32 + 1 */
1699 #define MAX_NUM_DIGITS 11
1701 static UINT
msi_dialog_edit_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1703 msi_control
*control
;
1705 LPWSTR val
, begin
, end
;
1706 WCHAR num
[MAX_NUM_DIGITS
];
1709 control
= msi_dialog_add_control( dialog
, rec
, szEdit
,
1710 WS_BORDER
| WS_TABSTOP
| ES_AUTOHSCROLL
);
1711 control
->handler
= msi_dialog_edit_handler
;
1713 text
= MSI_RecordGetString( rec
, 10 );
1716 begin
= strchrW( text
, '{' );
1717 end
= strchrW( text
, '}' );
1719 if ( begin
&& end
&& end
> begin
&&
1720 begin
[0] >= '0' && begin
[0] <= '9' &&
1721 end
- begin
< MAX_NUM_DIGITS
)
1723 lstrcpynW( num
, begin
+ 1, end
- begin
);
1724 limit
= atolW( num
);
1726 SendMessageW( control
->hwnd
, EM_SETLIMITTEXT
, limit
, 0 );
1730 prop
= MSI_RecordGetString( rec
, 9 );
1732 control
->property
= strdupW( prop
);
1734 val
= msi_dup_property( dialog
->package
->db
, control
->property
);
1735 SetWindowTextW( control
->hwnd
, val
);
1737 return ERROR_SUCCESS
;
1740 /******************** Masked Edit ********************************************/
1742 #define MASK_MAX_GROUPS 20
1744 struct msi_mask_group
1752 struct msi_maskedit_info
1760 struct msi_mask_group group
[MASK_MAX_GROUPS
];
1763 static BOOL
msi_mask_editable( WCHAR type
)
1778 static void msi_mask_control_change( struct msi_maskedit_info
*info
)
1783 val
= msi_alloc( (info
->num_chars
+1)*sizeof(WCHAR
) );
1784 for( i
=0, n
=0; i
<info
->num_groups
; i
++ )
1786 if( (info
->group
[i
].len
+ n
) > info
->num_chars
)
1788 ERR("can't fit control %d text into template\n",i
);
1791 if (!msi_mask_editable(info
->group
[i
].type
))
1793 for(r
=0; r
<info
->group
[i
].len
; r
++)
1794 val
[n
+r
] = info
->group
[i
].type
;
1799 r
= GetWindowTextW( info
->group
[i
].hwnd
, &val
[n
], info
->group
[i
].len
+1 );
1800 if( r
!= info
->group
[i
].len
)
1806 TRACE("%d/%d controls were good\n", i
, info
->num_groups
);
1808 if( i
== info
->num_groups
)
1810 TRACE("Set property %s to %s\n", debugstr_w(info
->prop
), debugstr_w(val
));
1811 msi_dialog_set_property( info
->dialog
->package
, info
->prop
, val
);
1812 msi_dialog_evaluate_control_conditions( info
->dialog
);
1817 /* now move to the next control if necessary */
1818 static VOID
msi_mask_next_control( struct msi_maskedit_info
*info
, HWND hWnd
)
1823 for( i
=0; i
<info
->num_groups
; i
++ )
1824 if( info
->group
[i
].hwnd
== hWnd
)
1827 /* don't move from the last control */
1828 if( i
>= (info
->num_groups
-1) )
1831 len
= SendMessageW( hWnd
, WM_GETTEXTLENGTH
, 0, 0 );
1832 if( len
< info
->group
[i
].len
)
1835 hWndNext
= GetNextDlgTabItem( GetParent( hWnd
), hWnd
, FALSE
);
1836 SetFocus( hWndNext
);
1839 static LRESULT WINAPI
1840 MSIMaskedEdit_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1842 struct msi_maskedit_info
*info
;
1845 TRACE("%p %04x %08lx %08lx\n", hWnd
, msg
, wParam
, lParam
);
1847 info
= GetPropW(hWnd
, szButtonData
);
1849 r
= CallWindowProcW(info
->oldproc
, hWnd
, msg
, wParam
, lParam
);
1854 if (HIWORD(wParam
) == EN_CHANGE
)
1856 msi_mask_control_change( info
);
1857 msi_mask_next_control( info
, (HWND
) lParam
);
1861 msi_free( info
->prop
);
1863 RemovePropW( hWnd
, szButtonData
);
1870 /* fish the various bits of the property out and put them in the control */
1872 msi_maskedit_set_text( struct msi_maskedit_info
*info
, LPCWSTR text
)
1878 for( i
= 0; i
< info
->num_groups
; i
++ )
1880 if( info
->group
[i
].len
< strlenW( p
) )
1882 LPWSTR chunk
= strdupW( p
);
1883 chunk
[ info
->group
[i
].len
] = 0;
1884 SetWindowTextW( info
->group
[i
].hwnd
, chunk
);
1889 SetWindowTextW( info
->group
[i
].hwnd
, p
);
1892 p
+= info
->group
[i
].len
;
1896 static struct msi_maskedit_info
* msi_dialog_parse_groups( LPCWSTR mask
)
1898 struct msi_maskedit_info
* info
= NULL
;
1899 int i
= 0, n
= 0, total
= 0;
1902 TRACE("masked control, template %s\n", debugstr_w(mask
));
1907 info
= msi_alloc_zero( sizeof *info
);
1911 p
= strchrW(mask
, '<');
1917 for( i
=0; i
<MASK_MAX_GROUPS
; i
++ )
1919 /* stop at the end of the string */
1920 if( p
[0] == 0 || p
[0] == '>' )
1923 /* count the number of the same identifier */
1924 for( n
=0; p
[n
] == p
[0]; n
++ )
1926 info
->group
[i
].ofs
= total
;
1927 info
->group
[i
].type
= p
[0];
1931 total
++; /* an extra not part of the group */
1933 info
->group
[i
].len
= n
;
1938 TRACE("%d characters in %d groups\n", total
, i
);
1939 if( i
== MASK_MAX_GROUPS
)
1940 ERR("too many groups in PIDTemplate %s\n", debugstr_w(mask
));
1942 info
->num_chars
= total
;
1943 info
->num_groups
= i
;
1949 msi_maskedit_create_children( struct msi_maskedit_info
*info
, LPCWSTR font
)
1951 DWORD width
, height
, style
, wx
, ww
;
1956 style
= WS_CHILD
| WS_BORDER
| WS_VISIBLE
| WS_TABSTOP
| ES_AUTOHSCROLL
;
1958 GetClientRect( info
->hwnd
, &rect
);
1960 width
= rect
.right
- rect
.left
;
1961 height
= rect
.bottom
- rect
.top
;
1963 for( i
= 0; i
< info
->num_groups
; i
++ )
1965 if (!msi_mask_editable( info
->group
[i
].type
))
1967 wx
= (info
->group
[i
].ofs
* width
) / info
->num_chars
;
1968 ww
= (info
->group
[i
].len
* width
) / info
->num_chars
;
1970 hwnd
= CreateWindowW( szEdit
, NULL
, style
, wx
, 0, ww
, height
,
1971 info
->hwnd
, NULL
, NULL
, NULL
);
1974 ERR("failed to create mask edit sub window\n");
1978 SendMessageW( hwnd
, EM_LIMITTEXT
, info
->group
[i
].len
, 0 );
1980 msi_dialog_set_font( info
->dialog
, hwnd
,
1981 font
?font
:info
->dialog
->default_font
);
1982 info
->group
[i
].hwnd
= hwnd
;
1987 * office 2003 uses "73931<````=````=````=````=`````>@@@@@"
1988 * delphi 7 uses "<????-??????-??????-????>" and "<???-???>"
1989 * filemaker pro 7 uses "<^^^^=^^^^=^^^^=^^^^=^^^^=^^^^=^^^^^>"
1991 static UINT
msi_dialog_maskedit_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1993 LPWSTR font_mask
, val
= NULL
, font
;
1994 struct msi_maskedit_info
*info
= NULL
;
1995 UINT ret
= ERROR_SUCCESS
;
1996 msi_control
*control
;
2001 font_mask
= msi_get_deformatted_field( dialog
->package
, rec
, 10 );
2002 font
= msi_dialog_get_style( font_mask
, &mask
);
2005 WARN("mask template is empty\n");
2009 info
= msi_dialog_parse_groups( mask
);
2012 ERR("template %s is invalid\n", debugstr_w(mask
));
2016 info
->dialog
= dialog
;
2018 control
= msi_dialog_add_control( dialog
, rec
, szStatic
,
2019 SS_OWNERDRAW
| WS_GROUP
| WS_VISIBLE
);
2022 ERR("Failed to create maskedit container\n");
2023 ret
= ERROR_FUNCTION_FAILED
;
2026 SetWindowLongPtrW( control
->hwnd
, GWL_EXSTYLE
, WS_EX_CONTROLPARENT
);
2028 info
->hwnd
= control
->hwnd
;
2030 /* subclass the static control */
2031 info
->oldproc
= (WNDPROC
) SetWindowLongPtrW( info
->hwnd
, GWLP_WNDPROC
,
2032 (LONG_PTR
)MSIMaskedEdit_WndProc
);
2033 SetPropW( control
->hwnd
, szButtonData
, info
);
2035 prop
= MSI_RecordGetString( rec
, 9 );
2037 info
->prop
= strdupW( prop
);
2039 msi_maskedit_create_children( info
, font
);
2043 val
= msi_dup_property( dialog
->package
->db
, prop
);
2046 msi_maskedit_set_text( info
, val
);
2052 if( ret
!= ERROR_SUCCESS
)
2054 msi_free( font_mask
);
2059 /******************** Progress Bar *****************************************/
2061 static UINT
msi_dialog_progress_bar( msi_dialog
*dialog
, MSIRECORD
*rec
)
2063 msi_control
*control
;
2064 DWORD attributes
, style
;
2067 attributes
= MSI_RecordGetInteger( rec
, 8 );
2068 if( !(attributes
& msidbControlAttributesProgress95
) )
2069 style
|= PBS_SMOOTH
;
2071 control
= msi_dialog_add_control( dialog
, rec
, PROGRESS_CLASSW
, style
);
2073 return ERROR_FUNCTION_FAILED
;
2075 ControlEvent_SubscribeToEvent( dialog
->package
, dialog
,
2076 szSetProgress
, control
->name
, szProgress
);
2077 return ERROR_SUCCESS
;
2080 /******************** Path Edit ********************************************/
2082 struct msi_pathedit_info
2085 msi_control
*control
;
2089 static void msi_dialog_update_pathedit( msi_dialog
*dialog
, msi_control
*control
)
2094 if (!control
&& !(control
= msi_dialog_find_control_by_type( dialog
, szPathEdit
)))
2097 indirect
= control
->attributes
& msidbControlAttributesIndirect
;
2098 prop
= msi_dialog_dup_property( dialog
, control
->property
, indirect
);
2099 path
= msi_dialog_dup_property( dialog
, prop
, TRUE
);
2101 SetWindowTextW( control
->hwnd
, path
);
2102 SendMessageW( control
->hwnd
, EM_SETSEL
, 0, -1 );
2108 /* FIXME: test when this should fail */
2109 static BOOL
msi_dialog_verify_path( LPWSTR path
)
2111 if ( !lstrlenW( path
) )
2114 if ( PathIsRelativeW( path
) )
2120 /* returns TRUE if the path is valid, FALSE otherwise */
2121 static BOOL
msi_dialog_onkillfocus( msi_dialog
*dialog
, msi_control
*control
)
2127 indirect
= control
->attributes
& msidbControlAttributesIndirect
;
2128 prop
= msi_dialog_dup_property( dialog
, control
->property
, indirect
);
2130 buf
= msi_get_window_text( control
->hwnd
);
2132 if ( !msi_dialog_verify_path( buf
) )
2134 /* FIXME: display an error message box */
2135 ERR("Invalid path %s\n", debugstr_w( buf
));
2137 SetFocus( control
->hwnd
);
2142 msi_dialog_set_property( dialog
->package
, prop
, buf
);
2145 msi_dialog_update_pathedit( dialog
, control
);
2147 TRACE("edit %s contents changed, set %s\n", debugstr_w(control
->name
),
2156 static LRESULT WINAPI
MSIPathEdit_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
2158 struct msi_pathedit_info
*info
= GetPropW(hWnd
, szButtonData
);
2161 TRACE("%p %04x %08lx %08lx\n", hWnd
, msg
, wParam
, lParam
);
2163 if ( msg
== WM_KILLFOCUS
)
2165 /* if the path is invalid, don't handle this message */
2166 if ( !msi_dialog_onkillfocus( info
->dialog
, info
->control
) )
2170 r
= CallWindowProcW(info
->oldproc
, hWnd
, msg
, wParam
, lParam
);
2172 if ( msg
== WM_NCDESTROY
)
2175 RemovePropW( hWnd
, szButtonData
);
2181 static UINT
msi_dialog_pathedit_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
2183 struct msi_pathedit_info
*info
;
2184 msi_control
*control
;
2187 info
= msi_alloc( sizeof *info
);
2189 return ERROR_FUNCTION_FAILED
;
2191 control
= msi_dialog_add_control( dialog
, rec
, szEdit
,
2192 WS_BORDER
| WS_TABSTOP
);
2193 control
->attributes
= MSI_RecordGetInteger( rec
, 8 );
2194 prop
= MSI_RecordGetString( rec
, 9 );
2195 control
->property
= msi_dialog_dup_property( dialog
, prop
, FALSE
);
2197 info
->dialog
= dialog
;
2198 info
->control
= control
;
2199 info
->oldproc
= (WNDPROC
) SetWindowLongPtrW( control
->hwnd
, GWLP_WNDPROC
,
2200 (LONG_PTR
)MSIPathEdit_WndProc
);
2201 SetPropW( control
->hwnd
, szButtonData
, info
);
2203 msi_dialog_update_pathedit( dialog
, control
);
2205 return ERROR_SUCCESS
;
2208 static UINT
msi_dialog_radiogroup_handler( msi_dialog
*dialog
, msi_control
*control
, WPARAM param
)
2210 if (HIWORD(param
) != BN_CLICKED
)
2211 return ERROR_SUCCESS
;
2213 TRACE("clicked radio button %s, set %s\n", debugstr_w(control
->name
), debugstr_w(control
->property
));
2215 msi_dialog_set_property( dialog
->package
, control
->property
, control
->name
);
2217 return msi_dialog_button_handler( dialog
, control
, param
);
2220 /* radio buttons are a bit different from normal controls */
2221 static UINT
msi_dialog_create_radiobutton( MSIRECORD
*rec
, LPVOID param
)
2223 radio_button_group_descr
*group
= param
;
2224 msi_dialog
*dialog
= group
->dialog
;
2225 msi_control
*control
;
2226 LPCWSTR prop
, text
, name
;
2227 DWORD style
, attributes
= group
->attributes
;
2229 style
= WS_CHILD
| BS_AUTORADIOBUTTON
| BS_MULTILINE
| WS_TABSTOP
;
2230 name
= MSI_RecordGetString( rec
, 3 );
2231 text
= MSI_RecordGetString( rec
, 8 );
2232 if( attributes
& msidbControlAttributesVisible
)
2233 style
|= WS_VISIBLE
;
2234 if( ~attributes
& msidbControlAttributesEnabled
)
2235 style
|= WS_DISABLED
;
2237 control
= msi_dialog_create_window( dialog
, rec
, 0, szButton
, name
, text
,
2238 style
, group
->parent
->hwnd
);
2240 return ERROR_FUNCTION_FAILED
;
2241 control
->handler
= msi_dialog_radiogroup_handler
;
2243 if (group
->propval
&& !strcmpW( control
->name
, group
->propval
))
2244 SendMessageW(control
->hwnd
, BM_SETCHECK
, BST_CHECKED
, 0);
2246 prop
= MSI_RecordGetString( rec
, 1 );
2248 control
->property
= strdupW( prop
);
2250 return ERROR_SUCCESS
;
2253 static BOOL CALLBACK
msi_radioground_child_enum( HWND hWnd
, LPARAM lParam
)
2255 EnableWindow( hWnd
, lParam
);
2259 static LRESULT WINAPI
MSIRadioGroup_WndProc( HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
2261 WNDPROC oldproc
= (WNDPROC
)GetPropW( hWnd
, szButtonData
);
2264 TRACE("hWnd %p msg %04x wParam 0x%08lx lParam 0x%08lx\n", hWnd
, msg
, wParam
, lParam
);
2266 if (msg
== WM_COMMAND
) /* Forward notifications to dialog */
2267 SendMessageW( GetParent( hWnd
), msg
, wParam
, lParam
);
2269 r
= CallWindowProcW( oldproc
, hWnd
, msg
, wParam
, lParam
);
2271 /* make sure the radio buttons show as disabled if the parent is disabled */
2272 if (msg
== WM_ENABLE
)
2273 EnumChildWindows( hWnd
, msi_radioground_child_enum
, wParam
);
2278 static UINT
msi_dialog_radiogroup_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
2280 static const WCHAR query
[] = {
2281 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2282 'R','a','d','i','o','B','u','t','t','o','n',' ','W','H','E','R','E',' ',
2283 '`','P','r','o','p','e','r','t','y','`',' ','=',' ','\'','%','s','\'',0};
2286 msi_control
*control
;
2288 radio_button_group_descr group
;
2289 MSIPACKAGE
*package
= dialog
->package
;
2291 DWORD attr
, style
= WS_GROUP
;
2293 prop
= MSI_RecordGetString( rec
, 9 );
2295 TRACE("%p %p %s\n", dialog
, rec
, debugstr_w( prop
));
2297 attr
= MSI_RecordGetInteger( rec
, 8 );
2298 if (attr
& msidbControlAttributesHasBorder
)
2299 style
|= BS_GROUPBOX
;
2301 style
|= BS_OWNERDRAW
;
2303 /* Create parent group box to hold radio buttons */
2304 control
= msi_dialog_add_control( dialog
, rec
, szButton
, style
);
2306 return ERROR_FUNCTION_FAILED
;
2308 oldproc
= (WNDPROC
) SetWindowLongPtrW( control
->hwnd
, GWLP_WNDPROC
,
2309 (LONG_PTR
)MSIRadioGroup_WndProc
);
2310 SetPropW(control
->hwnd
, szButtonData
, oldproc
);
2311 SetWindowLongPtrW( control
->hwnd
, GWL_EXSTYLE
, WS_EX_CONTROLPARENT
);
2314 control
->property
= strdupW( prop
);
2316 /* query the Radio Button table for all control in this group */
2317 r
= MSI_OpenQuery( package
->db
, &view
, query
, prop
);
2318 if( r
!= ERROR_SUCCESS
)
2320 ERR("query failed for dialog %s radio group %s\n",
2321 debugstr_w(dialog
->name
), debugstr_w(prop
));
2322 return ERROR_INVALID_PARAMETER
;
2325 group
.dialog
= dialog
;
2326 group
.parent
= control
;
2327 group
.attributes
= MSI_RecordGetInteger( rec
, 8 );
2328 group
.propval
= msi_dup_property( dialog
->package
->db
, control
->property
);
2330 r
= MSI_IterateRecords( view
, 0, msi_dialog_create_radiobutton
, &group
);
2331 msiobj_release( &view
->hdr
);
2332 msi_free( group
.propval
);
2337 msi_seltree_sync_item_state( HWND hwnd
, MSIFEATURE
*feature
, HTREEITEM hItem
)
2340 DWORD index
= feature
->ActionRequest
;
2342 TRACE("Feature %s -> %d %d %d\n", debugstr_w(feature
->Title
),
2343 feature
->Installed
, feature
->Action
, feature
->ActionRequest
);
2345 if (index
== INSTALLSTATE_UNKNOWN
)
2346 index
= INSTALLSTATE_ABSENT
;
2348 tvi
.mask
= TVIF_STATE
;
2350 tvi
.state
= INDEXTOSTATEIMAGEMASK( index
);
2351 tvi
.stateMask
= TVIS_STATEIMAGEMASK
;
2353 SendMessageW( hwnd
, TVM_SETITEMW
, 0, (LPARAM
) &tvi
);
2357 msi_seltree_popup_menu( HWND hwnd
, INT x
, INT y
)
2362 /* create a menu to display */
2363 hMenu
= CreatePopupMenu();
2365 /* FIXME: load strings from resources */
2366 AppendMenuA( hMenu
, MF_ENABLED
, INSTALLSTATE_LOCAL
, "Install feature locally");
2367 AppendMenuA( hMenu
, MF_ENABLED
, USER_INSTALLSTATE_ALL
, "Install entire feature");
2368 AppendMenuA( hMenu
, MF_ENABLED
, INSTALLSTATE_ADVERTISED
, "Install on demand");
2369 AppendMenuA( hMenu
, MF_ENABLED
, INSTALLSTATE_ABSENT
, "Don't install");
2370 r
= TrackPopupMenu( hMenu
, TPM_LEFTALIGN
| TPM_TOPALIGN
| TPM_RETURNCMD
,
2371 x
, y
, 0, hwnd
, NULL
);
2372 DestroyMenu( hMenu
);
2377 msi_seltree_update_feature_installstate( HWND hwnd
, HTREEITEM hItem
,
2378 MSIPACKAGE
*package
, MSIFEATURE
*feature
, INSTALLSTATE state
)
2380 feature
->ActionRequest
= state
;
2381 msi_seltree_sync_item_state( hwnd
, feature
, hItem
);
2382 ACTION_UpdateComponentStates( package
, feature
);
2386 msi_seltree_update_siblings_and_children_installstate( HWND hwnd
, HTREEITEM curr
,
2387 MSIPACKAGE
*package
, INSTALLSTATE state
)
2389 /* update all siblings */
2392 MSIFEATURE
*feature
;
2395 feature
= msi_seltree_feature_from_item( hwnd
, curr
);
2396 msi_seltree_update_feature_installstate( hwnd
, curr
, package
, feature
, state
);
2398 /* update this sibling's children */
2399 child
= (HTREEITEM
)SendMessageW( hwnd
, TVM_GETNEXTITEM
, (WPARAM
)TVGN_CHILD
, (LPARAM
)curr
);
2401 msi_seltree_update_siblings_and_children_installstate( hwnd
, child
,
2404 while ((curr
= (HTREEITEM
)SendMessageW( hwnd
, TVM_GETNEXTITEM
, (WPARAM
)TVGN_NEXT
, (LPARAM
)curr
)));
2408 msi_seltree_menu( HWND hwnd
, HTREEITEM hItem
)
2410 struct msi_selection_tree_info
*info
;
2411 MSIFEATURE
*feature
;
2412 MSIPACKAGE
*package
;
2420 info
= GetPropW(hwnd
, szButtonData
);
2421 package
= info
->dialog
->package
;
2423 feature
= msi_seltree_feature_from_item( hwnd
, hItem
);
2426 ERR("item %p feature was NULL\n", hItem
);
2430 /* get the item's rectangle to put the menu just below it */
2432 SendMessageW( hwnd
, TVM_GETITEMRECT
, 0, (LPARAM
) &u
.rc
);
2433 MapWindowPoints( hwnd
, NULL
, u
.pt
, 2 );
2435 r
= msi_seltree_popup_menu( hwnd
, u
.rc
.left
, u
.rc
.top
);
2439 case USER_INSTALLSTATE_ALL
:
2440 r
= INSTALLSTATE_LOCAL
;
2442 case INSTALLSTATE_ADVERTISED
:
2443 case INSTALLSTATE_ABSENT
:
2446 child
= (HTREEITEM
)SendMessageW( hwnd
, TVM_GETNEXTITEM
, (WPARAM
)TVGN_CHILD
, (LPARAM
)hItem
);
2448 msi_seltree_update_siblings_and_children_installstate( hwnd
, child
, package
, r
);
2451 case INSTALLSTATE_LOCAL
:
2452 msi_seltree_update_feature_installstate( hwnd
, hItem
, package
, feature
, r
);
2459 static LRESULT WINAPI
2460 MSISelectionTree_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
2462 struct msi_selection_tree_info
*info
;
2463 TVHITTESTINFO tvhti
;
2466 TRACE("%p %04x %08lx %08lx\n", hWnd
, msg
, wParam
, lParam
);
2468 info
= GetPropW(hWnd
, szButtonData
);
2472 case WM_LBUTTONDOWN
:
2473 tvhti
.pt
.x
= (short)LOWORD( lParam
);
2474 tvhti
.pt
.y
= (short)HIWORD( lParam
);
2477 CallWindowProcW(info
->oldproc
, hWnd
, TVM_HITTEST
, 0, (LPARAM
) &tvhti
);
2478 if (tvhti
.flags
& TVHT_ONITEMSTATEICON
)
2479 return msi_seltree_menu( hWnd
, tvhti
.hItem
);
2482 r
= CallWindowProcW(info
->oldproc
, hWnd
, msg
, wParam
, lParam
);
2488 RemovePropW( hWnd
, szButtonData
);
2495 msi_seltree_add_child_features( MSIPACKAGE
*package
, HWND hwnd
,
2496 LPCWSTR parent
, HTREEITEM hParent
)
2498 struct msi_selection_tree_info
*info
= GetPropW( hwnd
, szButtonData
);
2499 MSIFEATURE
*feature
;
2500 TVINSERTSTRUCTW tvis
;
2501 HTREEITEM hitem
, hfirst
= NULL
;
2503 LIST_FOR_EACH_ENTRY( feature
, &package
->features
, MSIFEATURE
, entry
)
2505 if ( parent
&& feature
->Feature_Parent
&& strcmpW( parent
, feature
->Feature_Parent
))
2507 else if ( parent
&& !feature
->Feature_Parent
)
2509 else if ( !parent
&& feature
->Feature_Parent
)
2512 if ( !feature
->Title
)
2515 if ( !feature
->Display
)
2518 memset( &tvis
, 0, sizeof tvis
);
2519 tvis
.hParent
= hParent
;
2520 tvis
.hInsertAfter
= TVI_LAST
;
2521 tvis
.u
.item
.mask
= TVIF_TEXT
| TVIF_PARAM
;
2522 tvis
.u
.item
.pszText
= feature
->Title
;
2523 tvis
.u
.item
.lParam
= (LPARAM
) feature
;
2525 hitem
= (HTREEITEM
) SendMessageW( hwnd
, TVM_INSERTITEMW
, 0, (LPARAM
) &tvis
);
2532 msi_seltree_sync_item_state( hwnd
, feature
, hitem
);
2533 msi_seltree_add_child_features( package
, hwnd
,
2534 feature
->Feature
, hitem
);
2536 /* the node is expanded if Display is odd */
2537 if ( feature
->Display
% 2 != 0 )
2538 SendMessageW( hwnd
, TVM_EXPAND
, TVE_EXPAND
, (LPARAM
) hitem
);
2541 /* select the first item */
2542 SendMessageW( hwnd
, TVM_SELECTITEM
, TVGN_CARET
| TVGN_DROPHILITE
, (LPARAM
) hfirst
);
2543 info
->selected
= hfirst
;
2546 static void msi_seltree_create_imagelist( HWND hwnd
)
2548 const int bm_width
= 32, bm_height
= 16, bm_count
= 3;
2549 const int bm_resource
= 0x1001;
2554 himl
= ImageList_Create( bm_width
, bm_height
, FALSE
, 4, 0 );
2557 ERR("failed to create image list\n");
2561 for (i
=0; i
<bm_count
; i
++)
2563 hbmp
= LoadBitmapW( msi_hInstance
, MAKEINTRESOURCEW(i
+bm_resource
) );
2566 ERR("failed to load bitmap %d\n", i
);
2571 * Add a dummy bitmap at offset zero because the treeview
2572 * can't use it as a state mask (zero means no user state).
2575 ImageList_Add( himl
, hbmp
, NULL
);
2577 ImageList_Add( himl
, hbmp
, NULL
);
2580 SendMessageW( hwnd
, TVM_SETIMAGELIST
, TVSIL_STATE
, (LPARAM
)himl
);
2583 static UINT
msi_dialog_seltree_handler( msi_dialog
*dialog
,
2584 msi_control
*control
, WPARAM param
)
2586 struct msi_selection_tree_info
*info
= GetPropW( control
->hwnd
, szButtonData
);
2587 LPNMTREEVIEWW tv
= (LPNMTREEVIEWW
)param
;
2588 MSIRECORD
*row
, *rec
;
2590 MSIFEATURE
*feature
;
2591 LPCWSTR dir
, title
= NULL
;
2592 UINT r
= ERROR_SUCCESS
;
2594 static const WCHAR select
[] = {
2595 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2596 '`','F','e','a','t','u','r','e','`',' ','W','H','E','R','E',' ',
2597 '`','T','i','t','l','e','`',' ','=',' ','\'','%','s','\'',0
2600 if (tv
->hdr
.code
!= TVN_SELCHANGINGW
)
2601 return ERROR_SUCCESS
;
2603 info
->selected
= tv
->itemNew
.hItem
;
2605 if (!(tv
->itemNew
.mask
& TVIF_TEXT
))
2607 feature
= msi_seltree_feature_from_item( control
->hwnd
, tv
->itemNew
.hItem
);
2609 title
= feature
->Title
;
2612 title
= tv
->itemNew
.pszText
;
2614 row
= MSI_QueryGetRecord( dialog
->package
->db
, select
, title
);
2616 return ERROR_FUNCTION_FAILED
;
2618 rec
= MSI_CreateRecord( 1 );
2620 MSI_RecordSetStringW( rec
, 1, MSI_RecordGetString( row
, 4 ) );
2621 ControlEvent_FireSubscribedEvent( dialog
->package
, szSelectionDescription
, rec
);
2623 dir
= MSI_RecordGetString( row
, 7 );
2626 folder
= msi_get_loaded_folder( dialog
->package
, dir
);
2629 r
= ERROR_FUNCTION_FAILED
;
2632 MSI_RecordSetStringW( rec
, 1, folder
->ResolvedTarget
);
2635 MSI_RecordSetStringW( rec
, 1, NULL
);
2637 ControlEvent_FireSubscribedEvent( dialog
->package
, szSelectionPath
, rec
);
2640 msiobj_release(&row
->hdr
);
2641 msiobj_release(&rec
->hdr
);
2646 static UINT
msi_dialog_selection_tree( msi_dialog
*dialog
, MSIRECORD
*rec
)
2648 msi_control
*control
;
2649 LPCWSTR prop
, control_name
;
2650 MSIPACKAGE
*package
= dialog
->package
;
2652 struct msi_selection_tree_info
*info
;
2654 info
= msi_alloc( sizeof *info
);
2656 return ERROR_FUNCTION_FAILED
;
2658 /* create the treeview control */
2659 style
= TVS_HASLINES
| TVS_HASBUTTONS
| TVS_LINESATROOT
;
2660 style
|= WS_GROUP
| WS_VSCROLL
;
2661 control
= msi_dialog_add_control( dialog
, rec
, WC_TREEVIEWW
, style
);
2665 return ERROR_FUNCTION_FAILED
;
2668 control
->handler
= msi_dialog_seltree_handler
;
2669 control_name
= MSI_RecordGetString( rec
, 2 );
2670 control
->attributes
= MSI_RecordGetInteger( rec
, 8 );
2671 prop
= MSI_RecordGetString( rec
, 9 );
2672 control
->property
= msi_dialog_dup_property( dialog
, prop
, FALSE
);
2675 info
->dialog
= dialog
;
2676 info
->hwnd
= control
->hwnd
;
2677 info
->oldproc
= (WNDPROC
) SetWindowLongPtrW( control
->hwnd
, GWLP_WNDPROC
,
2678 (LONG_PTR
)MSISelectionTree_WndProc
);
2679 SetPropW( control
->hwnd
, szButtonData
, info
);
2681 ControlEvent_SubscribeToEvent( dialog
->package
, dialog
,
2682 szSelectionPath
, control_name
, szProperty
);
2685 msi_seltree_create_imagelist( control
->hwnd
);
2686 msi_seltree_add_child_features( package
, control
->hwnd
, NULL
, NULL
);
2688 return ERROR_SUCCESS
;
2691 /******************** Group Box ***************************************/
2693 static UINT
msi_dialog_group_box( msi_dialog
*dialog
, MSIRECORD
*rec
)
2695 msi_control
*control
;
2698 style
= BS_GROUPBOX
| WS_CHILD
| WS_GROUP
;
2699 control
= msi_dialog_add_control( dialog
, rec
, WC_BUTTONW
, style
);
2701 return ERROR_FUNCTION_FAILED
;
2703 return ERROR_SUCCESS
;
2706 /******************** List Box ***************************************/
2708 struct msi_listbox_info
2718 static LRESULT WINAPI
MSIListBox_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
2720 struct msi_listbox_info
*info
;
2724 TRACE("%p %04x %08lx %08lx\n", hWnd
, msg
, wParam
, lParam
);
2726 info
= GetPropW( hWnd
, szButtonData
);
2730 r
= CallWindowProcW( info
->oldproc
, hWnd
, msg
, wParam
, lParam
);
2735 for (j
= 0; j
< info
->num_items
; j
++)
2736 msi_free( info
->items
[j
] );
2737 msi_free( info
->items
);
2739 RemovePropW( hWnd
, szButtonData
);
2746 static UINT
msi_listbox_add_item( MSIRECORD
*rec
, LPVOID param
)
2748 struct msi_listbox_info
*info
= param
;
2749 LPCWSTR value
, text
;
2752 value
= MSI_RecordGetString( rec
, 3 );
2753 text
= MSI_RecordGetString( rec
, 4 );
2755 info
->items
[info
->addpos_items
] = strdupW( value
);
2757 pos
= SendMessageW( info
->hwnd
, LB_ADDSTRING
, 0, (LPARAM
)text
);
2758 SendMessageW( info
->hwnd
, LB_SETITEMDATA
, pos
, (LPARAM
)info
->items
[info
->addpos_items
] );
2759 info
->addpos_items
++;
2760 return ERROR_SUCCESS
;
2763 static UINT
msi_listbox_add_items( struct msi_listbox_info
*info
, LPCWSTR property
)
2765 static const WCHAR query
[] = {
2766 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2767 '`','L','i','s','t','B','o','x','`',' ','W','H','E','R','E',' ',
2768 '`','P','r','o','p','e','r','t','y','`',' ','=',' ','\'','%','s','\'',' ',
2769 'O','R','D','E','R',' ','B','Y',' ','`','O','r','d','e','r','`',0};
2774 r
= MSI_OpenQuery( info
->dialog
->package
->db
, &view
, query
, property
);
2775 if ( r
!= ERROR_SUCCESS
)
2778 /* just get the number of records */
2780 r
= MSI_IterateRecords( view
, &count
, NULL
, NULL
);
2781 if (r
!= ERROR_SUCCESS
)
2783 msiobj_release( &view
->hdr
);
2786 info
->num_items
= count
;
2787 info
->items
= msi_alloc( sizeof(*info
->items
) * count
);
2789 r
= MSI_IterateRecords( view
, NULL
, msi_listbox_add_item
, info
);
2790 msiobj_release( &view
->hdr
);
2794 static UINT
msi_dialog_listbox_handler( msi_dialog
*dialog
,
2795 msi_control
*control
, WPARAM param
)
2797 struct msi_listbox_info
*info
;
2801 if( HIWORD(param
) != LBN_SELCHANGE
)
2802 return ERROR_SUCCESS
;
2804 info
= GetPropW( control
->hwnd
, szButtonData
);
2805 index
= SendMessageW( control
->hwnd
, LB_GETCURSEL
, 0, 0 );
2806 value
= (LPCWSTR
) SendMessageW( control
->hwnd
, LB_GETITEMDATA
, index
, 0 );
2808 msi_dialog_set_property( info
->dialog
->package
, control
->property
, value
);
2809 msi_dialog_evaluate_control_conditions( info
->dialog
);
2811 return ERROR_SUCCESS
;
2814 static UINT
msi_dialog_list_box( msi_dialog
*dialog
, MSIRECORD
*rec
)
2816 struct msi_listbox_info
*info
;
2817 msi_control
*control
;
2818 DWORD attributes
, style
;
2821 info
= msi_alloc( sizeof *info
);
2823 return ERROR_FUNCTION_FAILED
;
2825 style
= WS_TABSTOP
| WS_GROUP
| WS_CHILD
| LBS_NOTIFY
| WS_VSCROLL
| WS_BORDER
;
2826 attributes
= MSI_RecordGetInteger( rec
, 8 );
2827 if (~attributes
& msidbControlAttributesSorted
)
2830 control
= msi_dialog_add_control( dialog
, rec
, WC_LISTBOXW
, style
);
2834 return ERROR_FUNCTION_FAILED
;
2837 control
->handler
= msi_dialog_listbox_handler
;
2839 prop
= MSI_RecordGetString( rec
, 9 );
2840 control
->property
= msi_dialog_dup_property( dialog
, prop
, FALSE
);
2843 info
->dialog
= dialog
;
2844 info
->hwnd
= control
->hwnd
;
2846 info
->addpos_items
= 0;
2847 info
->oldproc
= (WNDPROC
)SetWindowLongPtrW( control
->hwnd
, GWLP_WNDPROC
,
2848 (LONG_PTR
)MSIListBox_WndProc
);
2849 SetPropW( control
->hwnd
, szButtonData
, info
);
2851 if ( control
->property
)
2852 msi_listbox_add_items( info
, control
->property
);
2854 return ERROR_SUCCESS
;
2857 /******************** Directory Combo ***************************************/
2859 static void msi_dialog_update_directory_combo( msi_dialog
*dialog
, msi_control
*control
)
2864 if (!control
&& !(control
= msi_dialog_find_control_by_type( dialog
, szDirectoryCombo
)))
2867 indirect
= control
->attributes
& msidbControlAttributesIndirect
;
2868 prop
= msi_dialog_dup_property( dialog
, control
->property
, indirect
);
2869 path
= msi_dialog_dup_property( dialog
, prop
, TRUE
);
2871 PathStripPathW( path
);
2872 PathRemoveBackslashW( path
);
2874 SendMessageW( control
->hwnd
, CB_INSERTSTRING
, 0, (LPARAM
)path
);
2875 SendMessageW( control
->hwnd
, CB_SETCURSEL
, 0, 0 );
2881 static UINT
msi_dialog_directory_combo( msi_dialog
*dialog
, MSIRECORD
*rec
)
2883 msi_control
*control
;
2887 /* FIXME: use CBS_OWNERDRAWFIXED and add owner draw code */
2888 style
= CBS_DROPDOWNLIST
| CBS_HASSTRINGS
| WS_CHILD
|
2889 WS_GROUP
| WS_TABSTOP
| WS_VSCROLL
;
2890 control
= msi_dialog_add_control( dialog
, rec
, WC_COMBOBOXW
, style
);
2892 return ERROR_FUNCTION_FAILED
;
2894 control
->attributes
= MSI_RecordGetInteger( rec
, 8 );
2895 prop
= MSI_RecordGetString( rec
, 9 );
2896 control
->property
= msi_dialog_dup_property( dialog
, prop
, FALSE
);
2898 msi_dialog_update_directory_combo( dialog
, control
);
2900 return ERROR_SUCCESS
;
2903 /******************** Directory List ***************************************/
2905 static void msi_dialog_update_directory_list( msi_dialog
*dialog
, msi_control
*control
)
2907 WCHAR dir_spec
[MAX_PATH
];
2908 WIN32_FIND_DATAW wfd
;
2914 static const WCHAR asterisk
[] = {'*',0};
2916 if (!control
&& !(control
= msi_dialog_find_control_by_type( dialog
, szDirectoryList
)))
2919 /* clear the list-view */
2920 SendMessageW( control
->hwnd
, LVM_DELETEALLITEMS
, 0, 0 );
2922 indirect
= control
->attributes
& msidbControlAttributesIndirect
;
2923 prop
= msi_dialog_dup_property( dialog
, control
->property
, indirect
);
2924 path
= msi_dialog_dup_property( dialog
, prop
, TRUE
);
2926 lstrcpyW( dir_spec
, path
);
2927 lstrcatW( dir_spec
, asterisk
);
2929 file
= FindFirstFileW( dir_spec
, &wfd
);
2930 if ( file
== INVALID_HANDLE_VALUE
)
2935 if ( wfd
.dwFileAttributes
!= FILE_ATTRIBUTE_DIRECTORY
)
2938 if ( !strcmpW( wfd
.cFileName
, szDot
) || !strcmpW( wfd
.cFileName
, szDotDot
) )
2941 item
.mask
= LVIF_TEXT
;
2942 item
.cchTextMax
= MAX_PATH
;
2945 item
.pszText
= wfd
.cFileName
;
2947 SendMessageW( control
->hwnd
, LVM_INSERTITEMW
, 0, (LPARAM
)&item
);
2948 } while ( FindNextFileW( file
, &wfd
) );
2955 UINT
msi_dialog_directorylist_up( msi_dialog
*dialog
)
2957 msi_control
*control
;
2958 LPWSTR prop
, path
, ptr
;
2961 control
= msi_dialog_find_control_by_type( dialog
, szDirectoryList
);
2962 indirect
= control
->attributes
& msidbControlAttributesIndirect
;
2963 prop
= msi_dialog_dup_property( dialog
, control
->property
, indirect
);
2964 path
= msi_dialog_dup_property( dialog
, prop
, TRUE
);
2966 /* strip off the last directory */
2967 ptr
= PathFindFileNameW( path
);
2968 if (ptr
!= path
) *(ptr
- 1) = '\0';
2969 PathAddBackslashW( path
);
2971 msi_dialog_set_property( dialog
->package
, prop
, path
);
2973 msi_dialog_update_directory_list( dialog
, NULL
);
2974 msi_dialog_update_directory_combo( dialog
, NULL
);
2975 msi_dialog_update_pathedit( dialog
, NULL
);
2980 return ERROR_SUCCESS
;
2983 static UINT
msi_dialog_dirlist_handler( msi_dialog
*dialog
,
2984 msi_control
*control
, WPARAM param
)
2986 LPNMHDR nmhdr
= (LPNMHDR
)param
;
2987 WCHAR new_path
[MAX_PATH
];
2988 WCHAR text
[MAX_PATH
];
2994 if (nmhdr
->code
!= LVN_ITEMACTIVATE
)
2995 return ERROR_SUCCESS
;
2997 index
= SendMessageW( control
->hwnd
, LVM_GETNEXTITEM
, -1, LVNI_SELECTED
);
3000 ERR("No list-view item selected!\n");
3001 return ERROR_FUNCTION_FAILED
;
3005 item
.pszText
= text
;
3006 item
.cchTextMax
= MAX_PATH
;
3007 SendMessageW( control
->hwnd
, LVM_GETITEMTEXTW
, index
, (LPARAM
)&item
);
3009 indirect
= control
->attributes
& msidbControlAttributesIndirect
;
3010 prop
= msi_dialog_dup_property( dialog
, control
->property
, indirect
);
3011 path
= msi_dialog_dup_property( dialog
, prop
, TRUE
);
3013 lstrcpyW( new_path
, path
);
3014 lstrcatW( new_path
, text
);
3015 lstrcatW( new_path
, szBackSlash
);
3017 msi_dialog_set_property( dialog
->package
, prop
, new_path
);
3019 msi_dialog_update_directory_list( dialog
, NULL
);
3020 msi_dialog_update_directory_combo( dialog
, NULL
);
3021 msi_dialog_update_pathedit( dialog
, NULL
);
3025 return ERROR_SUCCESS
;
3028 static UINT
msi_dialog_directory_list( msi_dialog
*dialog
, MSIRECORD
*rec
)
3030 msi_control
*control
;
3034 style
= LVS_LIST
| WS_VSCROLL
| LVS_SHAREIMAGELISTS
|
3035 LVS_AUTOARRANGE
| LVS_SINGLESEL
| WS_BORDER
|
3036 LVS_SORTASCENDING
| WS_CHILD
| WS_GROUP
| WS_TABSTOP
;
3037 control
= msi_dialog_add_control( dialog
, rec
, WC_LISTVIEWW
, style
);
3039 return ERROR_FUNCTION_FAILED
;
3041 control
->attributes
= MSI_RecordGetInteger( rec
, 8 );
3042 control
->handler
= msi_dialog_dirlist_handler
;
3043 prop
= MSI_RecordGetString( rec
, 9 );
3044 control
->property
= msi_dialog_dup_property( dialog
, prop
, FALSE
);
3046 /* double click to activate an item in the list */
3047 SendMessageW( control
->hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
,
3048 0, LVS_EX_TWOCLICKACTIVATE
);
3050 msi_dialog_update_directory_list( dialog
, control
);
3052 return ERROR_SUCCESS
;
3055 /******************** VolumeCost List ***************************************/
3057 static BOOL
str_is_number( LPCWSTR str
)
3061 for (i
= 0; i
< lstrlenW( str
); i
++)
3062 if (!isdigitW(str
[i
]))
3068 static const WCHAR column_keys
[][80] =
3070 {'V','o','l','u','m','e','C','o','s','t','V','o','l','u','m','e',0},
3071 {'V','o','l','u','m','e','C','o','s','t','S','i','z','e',0},
3072 {'V','o','l','u','m','e','C','o','s','t','A','v','a','i','l','a','b','l','e',0},
3073 {'V','o','l','u','m','e','C','o','s','t','R','e','q','u','i','r','e','d',0},
3074 {'V','o','l','u','m','e','C','o','s','t','D','i','f','f','e','r','e','n','c','e',0}
3077 static void msi_dialog_vcl_add_columns( msi_dialog
*dialog
, msi_control
*control
, MSIRECORD
*rec
)
3079 LPCWSTR text
= MSI_RecordGetString( rec
, 10 );
3080 LPCWSTR begin
= text
, end
;
3085 static const WCHAR negative
[] = {'-',0};
3089 while ((begin
= strchrW( begin
, '{' )) && count
< 5)
3091 if (!(end
= strchrW( begin
, '}' )))
3094 num
= msi_alloc( (end
-begin
+1)*sizeof(WCHAR
) );
3098 lstrcpynW( num
, begin
+ 1, end
- begin
);
3099 begin
+= end
- begin
+ 1;
3101 /* empty braces or '0' hides the column */
3102 if ( !num
[0] || !strcmpW( num
, szZero
) )
3109 /* the width must be a positive number
3110 * if a width is invalid, all remaining columns are hidden
3112 if ( !strncmpW( num
, negative
, 1 ) || !str_is_number( num
) ) {
3117 ZeroMemory( &lvc
, sizeof(lvc
) );
3118 lvc
.mask
= LVCF_TEXT
| LVCF_WIDTH
| LVCF_SUBITEM
;
3119 lvc
.cx
= atolW( num
);
3120 lvc
.pszText
= msi_dialog_get_uitext( dialog
, column_keys
[count
] );
3122 SendMessageW( control
->hwnd
, LVM_INSERTCOLUMNW
, count
++, (LPARAM
)&lvc
);
3123 msi_free( lvc
.pszText
);
3128 static LONGLONG
msi_vcl_get_cost( msi_dialog
*dialog
)
3130 MSIFEATURE
*feature
;
3132 LONGLONG total_cost
= 0;
3134 LIST_FOR_EACH_ENTRY( feature
, &dialog
->package
->features
, MSIFEATURE
, entry
)
3136 if (ERROR_SUCCESS
== (MSI_GetFeatureCost(dialog
->package
, feature
,
3137 MSICOSTTREE_SELFONLY
, INSTALLSTATE_LOCAL
, &each_cost
)))
3139 /* each_cost is in 512-byte units */
3140 total_cost
+= each_cost
* 512;
3142 if (ERROR_SUCCESS
== (MSI_GetFeatureCost(dialog
->package
, feature
,
3143 MSICOSTTREE_SELFONLY
, INSTALLSTATE_ABSENT
, &each_cost
)))
3145 /* each_cost is in 512-byte units */
3146 total_cost
-= each_cost
* 512;
3152 static void msi_dialog_vcl_add_drives( msi_dialog
*dialog
, msi_control
*control
)
3154 ULARGE_INTEGER total
, free
;
3155 LONGLONG difference
, cost
;
3156 WCHAR size_text
[MAX_PATH
];
3157 WCHAR cost_text
[MAX_PATH
];
3163 cost
= msi_vcl_get_cost(dialog
);
3164 StrFormatByteSizeW(cost
, cost_text
, MAX_PATH
);
3166 size
= GetLogicalDriveStringsW( 0, NULL
);
3167 if ( !size
) return;
3169 drives
= msi_alloc( (size
+ 1) * sizeof(WCHAR
) );
3170 if ( !drives
) return;
3172 GetLogicalDriveStringsW( size
, drives
);
3177 lvitem
.mask
= LVIF_TEXT
;
3179 lvitem
.iSubItem
= 0;
3180 lvitem
.pszText
= ptr
;
3181 lvitem
.cchTextMax
= lstrlenW(ptr
) + 1;
3182 SendMessageW( control
->hwnd
, LVM_INSERTITEMW
, 0, (LPARAM
)&lvitem
);
3184 GetDiskFreeSpaceExW(ptr
, &free
, &total
, NULL
);
3185 difference
= free
.QuadPart
- cost
;
3187 StrFormatByteSizeW(total
.QuadPart
, size_text
, MAX_PATH
);
3188 lvitem
.iSubItem
= 1;
3189 lvitem
.pszText
= size_text
;
3190 lvitem
.cchTextMax
= lstrlenW(size_text
) + 1;
3191 SendMessageW( control
->hwnd
, LVM_SETITEMW
, 0, (LPARAM
)&lvitem
);
3193 StrFormatByteSizeW(free
.QuadPart
, size_text
, MAX_PATH
);
3194 lvitem
.iSubItem
= 2;
3195 lvitem
.pszText
= size_text
;
3196 lvitem
.cchTextMax
= lstrlenW(size_text
) + 1;
3197 SendMessageW( control
->hwnd
, LVM_SETITEMW
, 0, (LPARAM
)&lvitem
);
3199 lvitem
.iSubItem
= 3;
3200 lvitem
.pszText
= cost_text
;
3201 lvitem
.cchTextMax
= lstrlenW(cost_text
) + 1;
3202 SendMessageW( control
->hwnd
, LVM_SETITEMW
, 0, (LPARAM
)&lvitem
);
3204 StrFormatByteSizeW(difference
, size_text
, MAX_PATH
);
3205 lvitem
.iSubItem
= 4;
3206 lvitem
.pszText
= size_text
;
3207 lvitem
.cchTextMax
= lstrlenW(size_text
) + 1;
3208 SendMessageW( control
->hwnd
, LVM_SETITEMW
, 0, (LPARAM
)&lvitem
);
3210 ptr
+= lstrlenW(ptr
) + 1;
3217 static UINT
msi_dialog_volumecost_list( msi_dialog
*dialog
, MSIRECORD
*rec
)
3219 msi_control
*control
;
3222 style
= LVS_REPORT
| WS_VSCROLL
| WS_HSCROLL
| LVS_SHAREIMAGELISTS
|
3223 LVS_AUTOARRANGE
| LVS_SINGLESEL
| WS_BORDER
|
3224 WS_CHILD
| WS_TABSTOP
| WS_GROUP
;
3225 control
= msi_dialog_add_control( dialog
, rec
, WC_LISTVIEWW
, style
);
3227 return ERROR_FUNCTION_FAILED
;
3229 msi_dialog_vcl_add_columns( dialog
, control
, rec
);
3230 msi_dialog_vcl_add_drives( dialog
, control
);
3232 return ERROR_SUCCESS
;
3235 /******************** VolumeSelect Combo ***************************************/
3237 static UINT
msi_dialog_volsel_handler( msi_dialog
*dialog
,
3238 msi_control
*control
, WPARAM param
)
3240 WCHAR text
[MAX_PATH
];
3245 if (HIWORD(param
) != CBN_SELCHANGE
)
3246 return ERROR_SUCCESS
;
3248 index
= SendMessageW( control
->hwnd
, CB_GETCURSEL
, 0, 0 );
3249 if ( index
== CB_ERR
)
3251 ERR("No ComboBox item selected!\n");
3252 return ERROR_FUNCTION_FAILED
;
3255 SendMessageW( control
->hwnd
, CB_GETLBTEXT
, index
, (LPARAM
)text
);
3257 indirect
= control
->attributes
& msidbControlAttributesIndirect
;
3258 prop
= msi_dialog_dup_property( dialog
, control
->property
, indirect
);
3260 msi_dialog_set_property( dialog
->package
, prop
, text
);
3263 return ERROR_SUCCESS
;
3266 static void msi_dialog_vsc_add_drives( msi_dialog
*dialog
, msi_control
*control
)
3271 size
= GetLogicalDriveStringsW( 0, NULL
);
3272 if ( !size
) return;
3274 drives
= msi_alloc( (size
+ 1) * sizeof(WCHAR
) );
3275 if ( !drives
) return;
3277 GetLogicalDriveStringsW( size
, drives
);
3282 SendMessageW( control
->hwnd
, CB_ADDSTRING
, 0, (LPARAM
)ptr
);
3283 ptr
+= lstrlenW(ptr
) + 1;
3289 static UINT
msi_dialog_volumeselect_combo( msi_dialog
*dialog
, MSIRECORD
*rec
)
3291 msi_control
*control
;
3295 /* FIXME: CBS_OWNERDRAWFIXED */
3296 style
= WS_CHILD
| WS_VISIBLE
| WS_GROUP
| WS_TABSTOP
|
3297 CBS_DROPDOWNLIST
| CBS_SORT
| CBS_HASSTRINGS
|
3298 WS_EX_LEFT
| WS_EX_LTRREADING
| WS_EX_RIGHTSCROLLBAR
;
3299 control
= msi_dialog_add_control( dialog
, rec
, WC_COMBOBOXW
, style
);
3301 return ERROR_FUNCTION_FAILED
;
3303 control
->attributes
= MSI_RecordGetInteger( rec
, 8 );
3304 control
->handler
= msi_dialog_volsel_handler
;
3305 prop
= MSI_RecordGetString( rec
, 9 );
3306 control
->property
= msi_dialog_dup_property( dialog
, prop
, FALSE
);
3308 msi_dialog_vsc_add_drives( dialog
, control
);
3310 return ERROR_SUCCESS
;
3313 static const struct control_handler msi_dialog_handler
[] =
3315 { szText
, msi_dialog_text_control
},
3316 { szPushButton
, msi_dialog_button_control
},
3317 { szLine
, msi_dialog_line_control
},
3318 { szBitmap
, msi_dialog_bitmap_control
},
3319 { szCheckBox
, msi_dialog_checkbox_control
},
3320 { szScrollableText
, msi_dialog_scrolltext_control
},
3321 { szComboBox
, msi_dialog_combo_control
},
3322 { szEdit
, msi_dialog_edit_control
},
3323 { szMaskedEdit
, msi_dialog_maskedit_control
},
3324 { szPathEdit
, msi_dialog_pathedit_control
},
3325 { szProgressBar
, msi_dialog_progress_bar
},
3326 { szRadioButtonGroup
, msi_dialog_radiogroup_control
},
3327 { szIcon
, msi_dialog_icon_control
},
3328 { szSelectionTree
, msi_dialog_selection_tree
},
3329 { szGroupBox
, msi_dialog_group_box
},
3330 { szListBox
, msi_dialog_list_box
},
3331 { szDirectoryCombo
, msi_dialog_directory_combo
},
3332 { szDirectoryList
, msi_dialog_directory_list
},
3333 { szVolumeCostList
, msi_dialog_volumecost_list
},
3334 { szVolumeSelectCombo
, msi_dialog_volumeselect_combo
},
3337 #define NUM_CONTROL_TYPES (sizeof msi_dialog_handler/sizeof msi_dialog_handler[0])
3339 static UINT
msi_dialog_create_controls( MSIRECORD
*rec
, LPVOID param
)
3341 msi_dialog
*dialog
= param
;
3342 LPCWSTR control_type
;
3345 /* find and call the function that can create this type of control */
3346 control_type
= MSI_RecordGetString( rec
, 3 );
3347 for( i
=0; i
<NUM_CONTROL_TYPES
; i
++ )
3348 if (!strcmpiW( msi_dialog_handler
[i
].control_type
, control_type
))
3350 if( i
!= NUM_CONTROL_TYPES
)
3351 msi_dialog_handler
[i
].func( dialog
, rec
);
3353 ERR("no handler for element type %s\n", debugstr_w(control_type
));
3355 return ERROR_SUCCESS
;
3358 static UINT
msi_dialog_fill_controls( msi_dialog
*dialog
)
3360 static const WCHAR query
[] = {
3361 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
3362 'C','o','n','t','r','o','l',' ','W','H','E','R','E',' ',
3363 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',0};
3366 MSIPACKAGE
*package
= dialog
->package
;
3368 TRACE("%p %s\n", dialog
, debugstr_w(dialog
->name
) );
3370 /* query the Control table for all the elements of the control */
3371 r
= MSI_OpenQuery( package
->db
, &view
, query
, dialog
->name
);
3372 if( r
!= ERROR_SUCCESS
)
3374 ERR("query failed for dialog %s\n", debugstr_w(dialog
->name
));
3375 return ERROR_INVALID_PARAMETER
;
3378 r
= MSI_IterateRecords( view
, 0, msi_dialog_create_controls
, dialog
);
3379 msiobj_release( &view
->hdr
);
3383 UINT
msi_dialog_reset( msi_dialog
*dialog
)
3385 /* FIXME: should restore the original values of any properties we changed */
3386 return msi_dialog_evaluate_control_conditions( dialog
);
3389 /* figure out the height of 10 point MS Sans Serif */
3390 static INT
msi_dialog_get_sans_serif_height( HWND hwnd
)
3392 static const WCHAR szSansSerif
[] = {
3393 'M','S',' ','S','a','n','s',' ','S','e','r','i','f',0 };
3398 HFONT hFont
, hOldFont
;
3401 hdc
= GetDC( hwnd
);
3404 memset( &lf
, 0, sizeof lf
);
3405 lf
.lfHeight
= MulDiv(12, GetDeviceCaps(hdc
, LOGPIXELSY
), 72);
3406 strcpyW( lf
.lfFaceName
, szSansSerif
);
3407 hFont
= CreateFontIndirectW(&lf
);
3410 hOldFont
= SelectObject( hdc
, hFont
);
3411 r
= GetTextMetricsW( hdc
, &tm
);
3413 height
= tm
.tmHeight
;
3414 SelectObject( hdc
, hOldFont
);
3415 DeleteObject( hFont
);
3417 ReleaseDC( hwnd
, hdc
);
3422 /* fetch the associated record from the Dialog table */
3423 static MSIRECORD
*msi_get_dialog_record( msi_dialog
*dialog
)
3425 static const WCHAR query
[] = {
3426 'S','E','L','E','C','T',' ','*',' ',
3427 'F','R','O','M',' ','D','i','a','l','o','g',' ',
3428 'W','H','E','R','E',' ',
3429 '`','D','i','a','l','o','g','`',' ','=',' ','\'','%','s','\'',0};
3430 MSIPACKAGE
*package
= dialog
->package
;
3431 MSIRECORD
*rec
= NULL
;
3433 TRACE("%p %s\n", dialog
, debugstr_w(dialog
->name
) );
3435 rec
= MSI_QueryGetRecord( package
->db
, query
, dialog
->name
);
3437 WARN("query failed for dialog %s\n", debugstr_w(dialog
->name
));
3442 static void msi_dialog_adjust_dialog_pos( msi_dialog
*dialog
, MSIRECORD
*rec
, LPRECT pos
)
3444 static const WCHAR szScreenX
[] = {'S','c','r','e','e','n','X',0};
3445 static const WCHAR szScreenY
[] = {'S','c','r','e','e','n','Y',0};
3452 center
.x
= MSI_RecordGetInteger( rec
, 2 );
3453 center
.y
= MSI_RecordGetInteger( rec
, 3 );
3455 sz
.cx
= MSI_RecordGetInteger( rec
, 4 );
3456 sz
.cy
= MSI_RecordGetInteger( rec
, 5 );
3458 sz
.cx
= msi_dialog_scale_unit( dialog
, sz
.cx
);
3459 sz
.cy
= msi_dialog_scale_unit( dialog
, sz
.cy
);
3461 xres
= msi_get_property_int( dialog
->package
->db
, szScreenX
, 0 );
3462 yres
= msi_get_property_int( dialog
->package
->db
, szScreenY
, 0 );
3464 center
.x
= MulDiv( center
.x
, xres
, 100 );
3465 center
.y
= MulDiv( center
.y
, yres
, 100 );
3467 /* turn the client pos into the window rectangle */
3468 if (dialog
->package
->center_x
&& dialog
->package
->center_y
)
3470 pos
->left
= dialog
->package
->center_x
- sz
.cx
/ 2.0;
3471 pos
->right
= pos
->left
+ sz
.cx
;
3472 pos
->top
= dialog
->package
->center_y
- sz
.cy
/ 2.0;
3473 pos
->bottom
= pos
->top
+ sz
.cy
;
3477 pos
->left
= center
.x
- sz
.cx
/2;
3478 pos
->right
= pos
->left
+ sz
.cx
;
3479 pos
->top
= center
.y
- sz
.cy
/2;
3480 pos
->bottom
= pos
->top
+ sz
.cy
;
3482 /* save the center */
3483 dialog
->package
->center_x
= center
.x
;
3484 dialog
->package
->center_y
= center
.y
;
3487 dialog
->size
.cx
= sz
.cx
;
3488 dialog
->size
.cy
= sz
.cy
;
3490 TRACE("%u %u %u %u\n", pos
->left
, pos
->top
, pos
->right
, pos
->bottom
);
3492 style
= GetWindowLongPtrW( dialog
->hwnd
, GWL_STYLE
);
3493 AdjustWindowRect( pos
, style
, FALSE
);
3496 static void msi_dialog_set_tab_order( msi_dialog
*dialog
, LPCWSTR first
)
3498 struct list tab_chain
;
3499 msi_control
*control
;
3500 HWND prev
= HWND_TOP
;
3502 list_init( &tab_chain
);
3503 if (!(control
= msi_dialog_find_control( dialog
, first
))) return;
3505 dialog
->hWndFocus
= control
->hwnd
;
3508 list_remove( &control
->entry
);
3509 list_add_tail( &tab_chain
, &control
->entry
);
3510 if (!control
->tabnext
) break;
3511 control
= msi_dialog_find_control( dialog
, control
->tabnext
);
3514 LIST_FOR_EACH_ENTRY( control
, &tab_chain
, msi_control
, entry
)
3516 SetWindowPos( control
->hwnd
, prev
, 0, 0, 0, 0,
3517 SWP_NOMOVE
| SWP_NOOWNERZORDER
| SWP_NOREDRAW
|
3518 SWP_NOREPOSITION
| SWP_NOSENDCHANGING
| SWP_NOSIZE
);
3519 prev
= control
->hwnd
;
3522 /* put them back on the main list */
3523 list_move_head( &dialog
->controls
, &tab_chain
);
3526 static LRESULT
msi_dialog_oncreate( HWND hwnd
, LPCREATESTRUCTW cs
)
3528 static const WCHAR df
[] = {
3529 'D','e','f','a','u','l','t','U','I','F','o','n','t',0 };
3530 static const WCHAR dfv
[] = {
3531 'M','S',' ','S','h','e','l','l',' ','D','l','g',0 };
3532 msi_dialog
*dialog
= cs
->lpCreateParams
;
3533 MSIRECORD
*rec
= NULL
;
3534 LPWSTR title
= NULL
;
3537 TRACE("%p %p\n", dialog
, dialog
->package
);
3539 dialog
->hwnd
= hwnd
;
3540 SetWindowLongPtrW( hwnd
, GWLP_USERDATA
, (LONG_PTR
) dialog
);
3542 rec
= msi_get_dialog_record( dialog
);
3545 TRACE("No record found for dialog %s\n", debugstr_w(dialog
->name
));
3549 dialog
->scale
= msi_dialog_get_sans_serif_height(dialog
->hwnd
);
3551 msi_dialog_adjust_dialog_pos( dialog
, rec
, &pos
);
3553 dialog
->attributes
= MSI_RecordGetInteger( rec
, 6 );
3555 dialog
->default_font
= msi_dup_property( dialog
->package
->db
, df
);
3556 if (!dialog
->default_font
)
3558 dialog
->default_font
= strdupW(dfv
);
3559 if (!dialog
->default_font
) return -1;
3562 title
= msi_get_deformatted_field( dialog
->package
, rec
, 7 );
3563 SetWindowTextW( hwnd
, title
);
3566 SetWindowPos( hwnd
, 0, pos
.left
, pos
.top
,
3567 pos
.right
- pos
.left
, pos
.bottom
- pos
.top
,
3568 SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_NOREDRAW
);
3570 msi_dialog_build_font_list( dialog
);
3571 msi_dialog_fill_controls( dialog
);
3572 msi_dialog_evaluate_control_conditions( dialog
);
3573 msi_dialog_set_tab_order( dialog
, MSI_RecordGetString( rec
, 8 ) );
3574 msiobj_release( &rec
->hdr
);
3579 static LRESULT
msi_dialog_oncommand( msi_dialog
*dialog
, WPARAM param
, HWND hwnd
)
3581 msi_control
*control
= NULL
;
3583 TRACE("%p %p %08lx\n", dialog
, hwnd
, param
);
3588 control
= msi_dialog_find_control( dialog
, dialog
->control_default
);
3590 case 2: /* escape */
3591 control
= msi_dialog_find_control( dialog
, dialog
->control_cancel
);
3594 control
= msi_dialog_find_control_by_hwnd( dialog
, hwnd
);
3599 if( control
->handler
)
3601 control
->handler( dialog
, control
, param
);
3602 msi_dialog_evaluate_control_conditions( dialog
);
3609 static LRESULT
msi_dialog_onnotify( msi_dialog
*dialog
, LPARAM param
)
3611 LPNMHDR nmhdr
= (LPNMHDR
) param
;
3612 msi_control
*control
= msi_dialog_find_control_by_hwnd( dialog
, nmhdr
->hwndFrom
);
3614 TRACE("%p %p\n", dialog
, nmhdr
->hwndFrom
);
3616 if ( control
&& control
->handler
)
3617 control
->handler( dialog
, control
, param
);
3622 static void msi_dialog_setfocus( msi_dialog
*dialog
)
3624 HWND hwnd
= dialog
->hWndFocus
;
3626 hwnd
= GetNextDlgTabItem( dialog
->hwnd
, hwnd
, TRUE
);
3627 hwnd
= GetNextDlgTabItem( dialog
->hwnd
, hwnd
, FALSE
);
3629 dialog
->hWndFocus
= hwnd
;
3632 static LRESULT WINAPI
MSIDialog_WndProc( HWND hwnd
, UINT msg
,
3633 WPARAM wParam
, LPARAM lParam
)
3635 msi_dialog
*dialog
= (LPVOID
) GetWindowLongPtrW( hwnd
, GWLP_USERDATA
);
3637 TRACE("0x%04x\n", msg
);
3642 dialog
->package
->center_x
= LOWORD(lParam
) + dialog
->size
.cx
/ 2.0;
3643 dialog
->package
->center_y
= HIWORD(lParam
) + dialog
->size
.cy
/ 2.0;
3647 return msi_dialog_oncreate( hwnd
, (LPCREATESTRUCTW
)lParam
);
3650 return msi_dialog_oncommand( dialog
, wParam
, (HWND
)lParam
);
3653 if( LOWORD(wParam
) == WA_INACTIVE
)
3654 dialog
->hWndFocus
= GetFocus();
3656 msi_dialog_setfocus( dialog
);
3660 msi_dialog_setfocus( dialog
);
3663 /* bounce back to our subclassed static control */
3664 case WM_CTLCOLORSTATIC
:
3665 return SendMessageW( (HWND
) lParam
, WM_CTLCOLORSTATIC
, wParam
, lParam
);
3668 dialog
->hwnd
= NULL
;
3671 return msi_dialog_onnotify( dialog
, lParam
);
3673 return DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
3676 static LRESULT WINAPI
MSIHiddenWindowProc( HWND hwnd
, UINT msg
,
3677 WPARAM wParam
, LPARAM lParam
)
3679 msi_dialog
*dialog
= (msi_dialog
*) lParam
;
3681 TRACE("%d %p\n", msg
, dialog
);
3685 case WM_MSI_DIALOG_CREATE
:
3686 return msi_dialog_run_message_loop( dialog
);
3687 case WM_MSI_DIALOG_DESTROY
:
3688 msi_dialog_destroy( dialog
);
3691 return DefWindowProcW( hwnd
, msg
, wParam
, lParam
);
3694 static BOOL
msi_dialog_register_class( void )
3698 ZeroMemory( &cls
, sizeof cls
);
3699 cls
.lpfnWndProc
= MSIDialog_WndProc
;
3700 cls
.hInstance
= NULL
;
3701 cls
.hIcon
= LoadIconW(0, (LPWSTR
)IDI_APPLICATION
);
3702 cls
.hCursor
= LoadCursorW(0, (LPWSTR
)IDC_ARROW
);
3703 cls
.hbrBackground
= (HBRUSH
)(COLOR_3DFACE
+ 1);
3704 cls
.lpszMenuName
= NULL
;
3705 cls
.lpszClassName
= szMsiDialogClass
;
3707 if( !RegisterClassW( &cls
) )
3710 cls
.lpfnWndProc
= MSIHiddenWindowProc
;
3711 cls
.lpszClassName
= szMsiHiddenWindow
;
3713 if( !RegisterClassW( &cls
) )
3716 uiThreadId
= GetCurrentThreadId();
3718 hMsiHiddenWindow
= CreateWindowW( szMsiHiddenWindow
, NULL
, WS_OVERLAPPED
,
3719 0, 0, 100, 100, NULL
, NULL
, NULL
, NULL
);
3720 if( !hMsiHiddenWindow
)
3726 /* functions that interface to other modules within MSI */
3728 msi_dialog
*msi_dialog_create( MSIPACKAGE
* package
,
3729 LPCWSTR szDialogName
, msi_dialog
*parent
,
3730 msi_dialog_event_handler event_handler
)
3732 MSIRECORD
*rec
= NULL
;
3735 TRACE("%p %s\n", package
, debugstr_w(szDialogName
));
3737 if (!hMsiHiddenWindow
)
3738 msi_dialog_register_class();
3740 /* allocate the structure for the dialog to use */
3741 dialog
= msi_alloc_zero( FIELD_OFFSET( msi_dialog
, name
[strlenW( szDialogName
) + 1] ));
3744 strcpyW( dialog
->name
, szDialogName
);
3745 dialog
->parent
= parent
;
3746 msiobj_addref( &package
->hdr
);
3747 dialog
->package
= package
;
3748 dialog
->event_handler
= event_handler
;
3749 dialog
->finished
= 0;
3750 list_init( &dialog
->controls
);
3751 list_init( &dialog
->fonts
);
3753 /* verify that the dialog exists */
3754 rec
= msi_get_dialog_record( dialog
);
3757 msiobj_release( &package
->hdr
);
3761 dialog
->attributes
= MSI_RecordGetInteger( rec
, 6 );
3762 dialog
->control_default
= strdupW( MSI_RecordGetString( rec
, 9 ) );
3763 dialog
->control_cancel
= strdupW( MSI_RecordGetString( rec
, 10 ) );
3764 msiobj_release( &rec
->hdr
);
3769 static void msi_process_pending_messages( HWND hdlg
)
3773 while( PeekMessageW( &msg
, 0, 0, 0, PM_REMOVE
) )
3775 if( hdlg
&& IsDialogMessageW( hdlg
, &msg
))
3777 TranslateMessage( &msg
);
3778 DispatchMessageW( &msg
);
3782 void msi_dialog_end_dialog( msi_dialog
*dialog
)
3784 TRACE("%p\n", dialog
);
3785 dialog
->finished
= 1;
3786 PostMessageW(dialog
->hwnd
, WM_NULL
, 0, 0);
3789 void msi_dialog_check_messages( HANDLE handle
)
3793 /* in threads other than the UI thread, block */
3794 if( uiThreadId
!= GetCurrentThreadId() )
3796 if (!handle
) return;
3797 while (MsgWaitForMultipleObjectsEx( 1, &handle
, INFINITE
, QS_ALLINPUT
, 0 ) == WAIT_OBJECT_0
+ 1)
3800 while (PeekMessageW( &msg
, NULL
, 0, 0, PM_REMOVE
))
3802 TranslateMessage( &msg
);
3803 DispatchMessageW( &msg
);
3809 /* there's two choices for the UI thread */
3812 msi_process_pending_messages( NULL
);
3818 * block here until somebody creates a new dialog or
3819 * the handle we're waiting on becomes ready
3821 r
= MsgWaitForMultipleObjects( 1, &handle
, 0, INFINITE
, QS_ALLINPUT
);
3822 if( r
== WAIT_OBJECT_0
)
3827 UINT
msi_dialog_run_message_loop( msi_dialog
*dialog
)
3832 if( uiThreadId
!= GetCurrentThreadId() )
3833 return SendMessageW( hMsiHiddenWindow
, WM_MSI_DIALOG_CREATE
, 0, (LPARAM
) dialog
);
3835 /* create the dialog window, don't show it yet */
3836 style
= WS_OVERLAPPED
;
3837 if( dialog
->attributes
& msidbDialogAttributesVisible
)
3838 style
|= WS_VISIBLE
;
3840 hwnd
= CreateWindowW( szMsiDialogClass
, dialog
->name
, style
,
3841 CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
,
3842 NULL
, NULL
, NULL
, dialog
);
3845 ERR("Failed to create dialog %s\n", debugstr_w( dialog
->name
));
3846 return ERROR_FUNCTION_FAILED
;
3849 ShowWindow( hwnd
, SW_SHOW
);
3850 /* UpdateWindow( hwnd ); - and causes the transparent static controls not to paint */
3852 if( dialog
->attributes
& msidbDialogAttributesModal
)
3854 while( !dialog
->finished
)
3856 MsgWaitForMultipleObjects( 0, NULL
, 0, INFINITE
, QS_ALLINPUT
);
3857 msi_process_pending_messages( dialog
->hwnd
);
3861 return ERROR_IO_PENDING
;
3863 return ERROR_SUCCESS
;
3866 static void msi_dialog_do_preview( msi_dialog
*dialog
)
3869 dialog
->attributes
|= msidbDialogAttributesVisible
;
3870 dialog
->attributes
&= ~msidbDialogAttributesModal
;
3871 msi_dialog_run_message_loop( dialog
);
3874 void msi_dialog_destroy( msi_dialog
*dialog
)
3876 msi_font
*font
, *next
;
3878 if( uiThreadId
!= GetCurrentThreadId() )
3880 SendMessageW( hMsiHiddenWindow
, WM_MSI_DIALOG_DESTROY
, 0, (LPARAM
) dialog
);
3885 ShowWindow( dialog
->hwnd
, SW_HIDE
);
3888 DestroyWindow( dialog
->hwnd
);
3890 /* unsubscribe events */
3891 ControlEvent_CleanupDialogSubscriptions(dialog
->package
, dialog
->name
);
3893 /* destroy the list of controls */
3894 while( !list_empty( &dialog
->controls
) )
3898 t
= LIST_ENTRY( list_head( &dialog
->controls
),
3899 msi_control
, entry
);
3900 msi_destroy_control( t
);
3903 /* destroy the list of fonts */
3904 LIST_FOR_EACH_ENTRY_SAFE( font
, next
, &dialog
->fonts
, msi_font
, entry
)
3906 list_remove( &font
->entry
);
3907 DeleteObject( font
->hfont
);
3910 msi_free( dialog
->default_font
);
3912 msi_free( dialog
->control_default
);
3913 msi_free( dialog
->control_cancel
);
3914 msiobj_release( &dialog
->package
->hdr
);
3915 dialog
->package
= NULL
;
3919 void msi_dialog_unregister_class( void )
3921 DestroyWindow( hMsiHiddenWindow
);
3922 hMsiHiddenWindow
= NULL
;
3923 UnregisterClassW( szMsiDialogClass
, NULL
);
3924 UnregisterClassW( szMsiHiddenWindow
, NULL
);
3928 static UINT
error_dialog_handler(MSIPACKAGE
*package
, LPCWSTR event
,
3929 LPCWSTR argument
, msi_dialog
* dialog
)
3931 static const WCHAR end_dialog
[] = {'E','n','d','D','i','a','l','o','g',0};
3932 static const WCHAR error_abort
[] = {'E','r','r','o','r','A','b','o','r','t',0};
3933 static const WCHAR error_cancel
[] = {'E','r','r','o','r','C','a','n','c','e','l',0};
3934 static const WCHAR error_no
[] = {'E','r','r','o','r','N','o',0};
3935 static const WCHAR result_prop
[] = {
3936 'M','S','I','E','r','r','o','r','D','i','a','l','o','g','R','e','s','u','l','t',0
3939 if ( strcmpW( event
, end_dialog
) )
3940 return ERROR_SUCCESS
;
3942 if ( !strcmpW( argument
, error_abort
) || !strcmpW( argument
, error_cancel
) ||
3943 !strcmpW( argument
, error_no
) )
3945 msi_set_property( package
->db
, result_prop
, error_abort
, -1 );
3948 ControlEvent_CleanupSubscriptions(package
);
3949 msi_dialog_end_dialog( dialog
);
3951 return ERROR_SUCCESS
;
3954 static UINT
msi_error_dialog_set_error( MSIPACKAGE
*package
, LPWSTR error_dialog
, LPWSTR error
)
3958 static const WCHAR update
[] =
3959 {'U','P','D','A','T','E',' ','`','C','o','n','t','r','o','l','`',' ',
3960 'S','E','T',' ','`','T','e','x','t','`',' ','=',' ','\'','%','s','\'',' ',
3961 'W','H','E','R','E', ' ','`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',' ',
3962 'A','N','D',' ','`','C','o','n','t','r','o','l','`',' ','=',' ',
3963 '\'','E','r','r','o','r','T','e','x','t','\'',0};
3965 row
= MSI_QueryGetRecord( package
->db
, update
, error
, error_dialog
);
3967 return ERROR_FUNCTION_FAILED
;
3969 msiobj_release(&row
->hdr
);
3970 return ERROR_SUCCESS
;
3973 UINT
msi_spawn_error_dialog( MSIPACKAGE
*package
, LPWSTR error_dialog
, LPWSTR error
)
3976 WCHAR result
[MAX_PATH
];
3977 UINT r
= ERROR_SUCCESS
;
3978 DWORD size
= MAX_PATH
;
3981 static const WCHAR pn_prop
[] = {'P','r','o','d','u','c','t','N','a','m','e',0};
3982 static const WCHAR title_fmt
[] = {'%','s',' ','W','a','r','n','i','n','g',0};
3983 static const WCHAR error_abort
[] = {'E','r','r','o','r','A','b','o','r','t',0};
3984 static const WCHAR result_prop
[] = {
3985 'M','S','I','E','r','r','o','r','D','i','a','l','o','g','R','e','s','u','l','t',0
3988 if ((package
->ui_level
& INSTALLUILEVEL_MASK
) == INSTALLUILEVEL_NONE
) return ERROR_SUCCESS
;
3990 if ( !error_dialog
)
3992 LPWSTR product_name
= msi_dup_property( package
->db
, pn_prop
);
3993 WCHAR title
[MAX_PATH
];
3995 sprintfW( title
, title_fmt
, product_name
);
3996 res
= MessageBoxW( NULL
, error
, title
, MB_OKCANCEL
| MB_ICONWARNING
);
3998 msi_free( product_name
);
4001 return ERROR_SUCCESS
;
4003 return ERROR_FUNCTION_FAILED
;
4006 r
= msi_error_dialog_set_error( package
, error_dialog
, error
);
4007 if ( r
!= ERROR_SUCCESS
)
4010 dialog
= msi_dialog_create( package
, error_dialog
, package
->dialog
,
4011 error_dialog_handler
);
4013 return ERROR_FUNCTION_FAILED
;
4015 dialog
->finished
= FALSE
;
4016 r
= msi_dialog_run_message_loop( dialog
);
4017 if ( r
!= ERROR_SUCCESS
)
4020 r
= msi_get_property( package
->db
, result_prop
, result
, &size
);
4021 if ( r
!= ERROR_SUCCESS
)
4024 if ( !strcmpW( result
, error_abort
) )
4025 r
= ERROR_FUNCTION_FAILED
;
4028 msi_dialog_destroy( dialog
);
4033 static void MSI_ClosePreview( MSIOBJECTHDR
*arg
)
4035 MSIPREVIEW
*preview
= (MSIPREVIEW
*)arg
;
4036 msiobj_release( &preview
->package
->hdr
);
4039 static MSIPREVIEW
*MSI_EnableUIPreview( MSIDATABASE
*db
)
4041 MSIPREVIEW
*preview
= NULL
;
4042 MSIPACKAGE
*package
;
4044 package
= MSI_CreatePackage( db
, NULL
);
4047 preview
= alloc_msiobject( MSIHANDLETYPE_PREVIEW
, sizeof(MSIPREVIEW
), MSI_ClosePreview
);
4050 preview
->package
= package
;
4051 msiobj_addref( &package
->hdr
);
4053 msiobj_release( &package
->hdr
);
4058 UINT WINAPI
MsiEnableUIPreview( MSIHANDLE hdb
, MSIHANDLE
*phPreview
)
4061 MSIPREVIEW
*preview
;
4062 UINT r
= ERROR_FUNCTION_FAILED
;
4064 TRACE("%d %p\n", hdb
, phPreview
);
4066 db
= msihandle2msiinfo( hdb
, MSIHANDLETYPE_DATABASE
);
4069 IWineMsiRemoteDatabase
*remote_database
;
4071 remote_database
= (IWineMsiRemoteDatabase
*)msi_get_remote( hdb
);
4072 if (!remote_database
)
4073 return ERROR_INVALID_HANDLE
;
4077 IWineMsiRemoteDatabase_Release( remote_database
);
4078 WARN("MsiEnableUIPreview not allowed during a custom action!\n");
4080 return ERROR_FUNCTION_FAILED
;
4082 preview
= MSI_EnableUIPreview( db
);
4085 *phPreview
= alloc_msihandle( &preview
->hdr
);
4086 msiobj_release( &preview
->hdr
);
4089 r
= ERROR_NOT_ENOUGH_MEMORY
;
4091 msiobj_release( &db
->hdr
);
4095 static UINT
preview_event_handler( MSIPACKAGE
*package
, LPCWSTR event
,
4096 LPCWSTR argument
, msi_dialog
*dialog
)
4098 MESSAGE("Preview dialog event '%s' (arg='%s')\n", debugstr_w(event
), debugstr_w(argument
));
4099 return ERROR_SUCCESS
;
4102 static UINT
MSI_PreviewDialogW( MSIPREVIEW
*preview
, LPCWSTR szDialogName
)
4104 msi_dialog
*dialog
= NULL
;
4105 UINT r
= ERROR_SUCCESS
;
4107 if (preview
->dialog
)
4108 msi_dialog_destroy( preview
->dialog
);
4110 /* an empty name means we should just destroy the current preview dialog */
4113 dialog
= msi_dialog_create( preview
->package
, szDialogName
, NULL
, preview_event_handler
);
4115 msi_dialog_do_preview( dialog
);
4117 r
= ERROR_FUNCTION_FAILED
;
4119 preview
->dialog
= dialog
;
4123 UINT WINAPI
MsiPreviewDialogW( MSIHANDLE hPreview
, LPCWSTR szDialogName
)
4125 MSIPREVIEW
*preview
;
4128 TRACE("%d %s\n", hPreview
, debugstr_w(szDialogName
));
4130 preview
= msihandle2msiinfo( hPreview
, MSIHANDLETYPE_PREVIEW
);
4132 return ERROR_INVALID_HANDLE
;
4134 r
= MSI_PreviewDialogW( preview
, szDialogName
);
4135 msiobj_release( &preview
->hdr
);
4139 UINT WINAPI
MsiPreviewDialogA( MSIHANDLE hPreview
, LPCSTR szDialogName
)
4144 TRACE("%d %s\n", hPreview
, debugstr_a(szDialogName
));
4148 strW
= strdupAtoW( szDialogName
);
4150 return ERROR_OUTOFMEMORY
;
4152 r
= MsiPreviewDialogW( hPreview
, strW
);
4157 UINT WINAPI
MsiPreviewBillboardW( MSIHANDLE hPreview
, LPCWSTR szControlName
, LPCWSTR szBillboard
)
4159 FIXME("%d %s %s\n", hPreview
, debugstr_w(szControlName
), debugstr_w(szBillboard
));
4160 return ERROR_CALL_NOT_IMPLEMENTED
;
4163 UINT WINAPI
MsiPreviewBillboardA( MSIHANDLE hPreview
, LPCSTR szControlName
, LPCSTR szBillboard
)
4165 FIXME("%d %s %s\n", hPreview
, debugstr_a(szControlName
), debugstr_a(szBillboard
));
4166 return ERROR_CALL_NOT_IMPLEMENTED
;