2 * Implementation of the Microsoft Installer (msi.dll)
4 * Copyright 2005 Mike McCormack for CodeWeavers
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #define NONAMELESSUNION
23 #define NONAMELESSSTRUCT
41 #include "msiserver.h"
43 #include "wine/debug.h"
44 #include "wine/unicode.h"
46 WINE_DEFAULT_DEBUG_CHANNEL(msi
);
48 extern HINSTANCE msi_hInstance
;
50 struct msi_control_tag
;
51 typedef struct msi_control_tag msi_control
;
52 typedef UINT (*msi_handler
)( msi_dialog
*, msi_control
*, WPARAM
);
53 typedef void (*msi_update
)( msi_dialog
*, msi_control
* );
55 struct msi_control_tag
68 float progress_current
;
70 BOOL progress_backwards
;
75 typedef struct msi_font_tag
87 msi_dialog_event_handler event_handler
;
97 LPWSTR control_default
;
98 LPWSTR control_cancel
;
102 typedef UINT (*msi_dialog_control_func
)( msi_dialog
*dialog
, MSIRECORD
*rec
);
103 struct control_handler
105 LPCWSTR control_type
;
106 msi_dialog_control_func func
;
115 } radio_button_group_descr
;
117 static const WCHAR szMsiDialogClass
[] = { 'M','s','i','D','i','a','l','o','g','C','l','o','s','e','C','l','a','s','s',0 };
118 static const WCHAR szMsiHiddenWindow
[] = { 'M','s','i','H','i','d','d','e','n','W','i','n','d','o','w',0 };
119 static const WCHAR szStatic
[] = { 'S','t','a','t','i','c',0 };
120 static const WCHAR szButton
[] = { 'B','U','T','T','O','N', 0 };
121 static const WCHAR szButtonData
[] = { 'M','S','I','D','A','T','A',0 };
122 static const WCHAR szProgress
[] = { 'P','r','o','g','r','e','s','s',0 };
123 static const WCHAR szText
[] = { 'T','e','x','t',0 };
124 static const WCHAR szPushButton
[] = { 'P','u','s','h','B','u','t','t','o','n',0 };
125 static const WCHAR szLine
[] = { 'L','i','n','e',0 };
126 static const WCHAR szBitmap
[] = { 'B','i','t','m','a','p',0 };
127 static const WCHAR szCheckBox
[] = { 'C','h','e','c','k','B','o','x',0 };
128 static const WCHAR szScrollableText
[] = { 'S','c','r','o','l','l','a','b','l','e','T','e','x','t',0 };
129 static const WCHAR szComboBox
[] = { 'C','o','m','b','o','B','o','x',0 };
130 static const WCHAR szEdit
[] = { 'E','d','i','t',0 };
131 static const WCHAR szMaskedEdit
[] = { 'M','a','s','k','e','d','E','d','i','t',0 };
132 static const WCHAR szPathEdit
[] = { 'P','a','t','h','E','d','i','t',0 };
133 static const WCHAR szProgressBar
[] = { 'P','r','o','g','r','e','s','s','B','a','r',0 };
134 static const WCHAR szSetProgress
[] = { 'S','e','t','P','r','o','g','r','e','s','s',0 };
135 static const WCHAR szRadioButtonGroup
[] = { 'R','a','d','i','o','B','u','t','t','o','n','G','r','o','u','p',0 };
136 static const WCHAR szIcon
[] = { 'I','c','o','n',0 };
137 static const WCHAR szSelectionTree
[] = { 'S','e','l','e','c','t','i','o','n','T','r','e','e',0 };
138 static const WCHAR szGroupBox
[] = { 'G','r','o','u','p','B','o','x',0 };
139 static const WCHAR szListBox
[] = { 'L','i','s','t','B','o','x',0 };
140 static const WCHAR szDirectoryCombo
[] = { 'D','i','r','e','c','t','o','r','y','C','o','m','b','o',0 };
141 static const WCHAR szDirectoryList
[] = { 'D','i','r','e','c','t','o','r','y','L','i','s','t',0 };
142 static const WCHAR szVolumeCostList
[] = { 'V','o','l','u','m','e','C','o','s','t','L','i','s','t',0 };
143 static const WCHAR szVolumeSelectCombo
[] = { 'V','o','l','u','m','e','S','e','l','e','c','t','C','o','m','b','o',0 };
144 static const WCHAR szSelectionDescription
[] = {'S','e','l','e','c','t','i','o','n','D','e','s','c','r','i','p','t','i','o','n',0};
145 static const WCHAR szSelectionPath
[] = {'S','e','l','e','c','t','i','o','n','P','a','t','h',0};
146 static const WCHAR szProperty
[] = {'P','r','o','p','e','r','t','y',0};
148 /* dialog sequencing */
150 #define WM_MSI_DIALOG_CREATE (WM_USER+0x100)
151 #define WM_MSI_DIALOG_DESTROY (WM_USER+0x101)
153 #define USER_INSTALLSTATE_ALL 0x1000
155 static DWORD uiThreadId
;
156 static HWND hMsiHiddenWindow
;
158 static LPWSTR
msi_get_window_text( HWND hwnd
)
164 buf
= msi_alloc( sz
*sizeof(WCHAR
) );
167 r
= GetWindowTextW( hwnd
, buf
, sz
);
171 buf
= msi_realloc( buf
, sz
*sizeof(WCHAR
) );
177 static INT
msi_dialog_scale_unit( msi_dialog
*dialog
, INT val
)
179 return MulDiv( val
, dialog
->scale
, 12 );
182 static msi_control
*msi_dialog_find_control( msi_dialog
*dialog
, LPCWSTR name
)
184 msi_control
*control
;
190 LIST_FOR_EACH_ENTRY( control
, &dialog
->controls
, msi_control
, entry
)
191 if( !strcmpW( control
->name
, name
) ) /* FIXME: case sensitive? */
196 static msi_control
*msi_dialog_find_control_by_type( msi_dialog
*dialog
, LPCWSTR type
)
198 msi_control
*control
;
204 LIST_FOR_EACH_ENTRY( control
, &dialog
->controls
, msi_control
, entry
)
205 if( !strcmpW( control
->type
, type
) ) /* FIXME: case sensitive? */
210 static msi_control
*msi_dialog_find_control_by_hwnd( msi_dialog
*dialog
, HWND hwnd
)
212 msi_control
*control
;
216 LIST_FOR_EACH_ENTRY( control
, &dialog
->controls
, msi_control
, entry
)
217 if( hwnd
== control
->hwnd
)
222 static LPWSTR
msi_get_deformatted_field( MSIPACKAGE
*package
, MSIRECORD
*rec
, int field
)
224 LPCWSTR str
= MSI_RecordGetString( rec
, field
);
228 deformat_string( package
, str
, &ret
);
232 static LPWSTR
msi_dialog_dup_property( msi_dialog
*dialog
, LPCWSTR property
, BOOL indirect
)
240 prop
= msi_dup_property( dialog
->package
->db
, property
);
243 prop
= strdupW( property
);
248 msi_dialog
*msi_dialog_get_parent( msi_dialog
*dialog
)
250 return dialog
->parent
;
253 LPWSTR
msi_dialog_get_name( msi_dialog
*dialog
)
259 * msi_dialog_get_style
261 * Extract the {\style} string from the front of the text to display and
262 * update the pointer. Only the last style in a list is applied.
264 static LPWSTR
msi_dialog_get_style( LPCWSTR p
, LPCWSTR
*rest
)
275 while ((first
= strchrW( p
, '{' )) && (q
= strchrW( first
+ 1, '}' )))
278 if( *p
!= '\\' && *p
!= '&' )
281 /* little bit of sanity checking to stop us getting confused with RTF */
282 for( i
=++p
; i
<q
; i
++ )
283 if( *i
== '}' || *i
== '\\' )
293 ret
= msi_alloc( len
*sizeof(WCHAR
) );
296 memcpy( ret
, p
, len
*sizeof(WCHAR
) );
301 static UINT
msi_dialog_add_font( MSIRECORD
*rec
, LPVOID param
)
303 msi_dialog
*dialog
= param
;
310 /* create a font and add it to the list */
311 name
= MSI_RecordGetString( rec
, 1 );
312 font
= msi_alloc( sizeof *font
+ strlenW( name
)*sizeof (WCHAR
) );
313 strcpyW( font
->name
, name
);
314 list_add_head( &dialog
->fonts
, &font
->entry
);
316 font
->color
= MSI_RecordGetInteger( rec
, 4 );
318 memset( &lf
, 0, sizeof lf
);
319 face
= MSI_RecordGetString( rec
, 2 );
320 lf
.lfHeight
= MSI_RecordGetInteger( rec
, 3 );
321 style
= MSI_RecordGetInteger( rec
, 5 );
322 if( style
& msidbTextStyleStyleBitsBold
)
323 lf
.lfWeight
= FW_BOLD
;
324 if( style
& msidbTextStyleStyleBitsItalic
)
326 if( style
& msidbTextStyleStyleBitsUnderline
)
327 lf
.lfUnderline
= TRUE
;
328 if( style
& msidbTextStyleStyleBitsStrike
)
329 lf
.lfStrikeOut
= TRUE
;
330 lstrcpynW( lf
.lfFaceName
, face
, LF_FACESIZE
);
332 /* adjust the height */
333 hdc
= GetDC( dialog
->hwnd
);
336 lf
.lfHeight
= -MulDiv(lf
.lfHeight
, GetDeviceCaps(hdc
, LOGPIXELSY
), 72);
337 ReleaseDC( dialog
->hwnd
, hdc
);
340 font
->hfont
= CreateFontIndirectW( &lf
);
342 TRACE("Adding font style %s\n", debugstr_w(font
->name
) );
344 return ERROR_SUCCESS
;
347 static msi_font
*msi_dialog_find_font( msi_dialog
*dialog
, LPCWSTR name
)
349 msi_font
*font
= NULL
;
351 LIST_FOR_EACH_ENTRY( font
, &dialog
->fonts
, msi_font
, entry
)
352 if( !strcmpW( font
->name
, name
) ) /* FIXME: case sensitive? */
358 static UINT
msi_dialog_set_font( msi_dialog
*dialog
, HWND hwnd
, LPCWSTR name
)
362 font
= msi_dialog_find_font( dialog
, name
);
364 SendMessageW( hwnd
, WM_SETFONT
, (WPARAM
) font
->hfont
, TRUE
);
366 ERR("No font entry for %s\n", debugstr_w(name
));
367 return ERROR_SUCCESS
;
370 static UINT
msi_dialog_build_font_list( msi_dialog
*dialog
)
372 static const WCHAR query
[] = {
373 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
374 '`','T','e','x','t','S','t','y','l','e','`',0};
378 TRACE("dialog %p\n", dialog
);
380 r
= MSI_OpenQuery( dialog
->package
->db
, &view
, query
);
381 if( r
!= ERROR_SUCCESS
)
384 r
= MSI_IterateRecords( view
, NULL
, msi_dialog_add_font
, dialog
);
385 msiobj_release( &view
->hdr
);
389 static void msi_destroy_control( msi_control
*t
)
391 list_remove( &t
->entry
);
392 /* leave dialog->hwnd - destroying parent destroys child windows */
393 msi_free( t
->property
);
394 msi_free( t
->value
);
396 DeleteObject( t
->hBitmap
);
398 DestroyIcon( t
->hIcon
);
399 msi_free( t
->tabnext
);
402 FreeLibrary( t
->hDll
);
406 static msi_control
*msi_dialog_create_window( msi_dialog
*dialog
,
407 MSIRECORD
*rec
, DWORD exstyle
, LPCWSTR szCls
, LPCWSTR name
, LPCWSTR text
,
408 DWORD style
, HWND parent
)
410 DWORD x
, y
, width
, height
;
411 LPWSTR font
= NULL
, title_font
= NULL
;
412 LPCWSTR title
= NULL
;
413 msi_control
*control
;
417 control
= msi_alloc( sizeof *control
+ strlenW(name
)*sizeof(WCHAR
) );
421 strcpyW( control
->name
, name
);
422 list_add_tail( &dialog
->controls
, &control
->entry
);
423 control
->handler
= NULL
;
424 control
->update
= NULL
;
425 control
->property
= NULL
;
426 control
->value
= NULL
;
427 control
->hBitmap
= NULL
;
428 control
->hIcon
= NULL
;
429 control
->hDll
= NULL
;
430 control
->tabnext
= strdupW( MSI_RecordGetString( rec
, 11) );
431 control
->type
= strdupW( MSI_RecordGetString( rec
, 3 ) );
432 control
->progress_current
= 0;
433 control
->progress_max
= 100;
434 control
->progress_backwards
= FALSE
;
436 x
= MSI_RecordGetInteger( rec
, 4 );
437 y
= MSI_RecordGetInteger( rec
, 5 );
438 width
= MSI_RecordGetInteger( rec
, 6 );
439 height
= MSI_RecordGetInteger( rec
, 7 );
441 x
= msi_dialog_scale_unit( dialog
, x
);
442 y
= msi_dialog_scale_unit( dialog
, y
);
443 width
= msi_dialog_scale_unit( dialog
, width
);
444 height
= msi_dialog_scale_unit( dialog
, height
);
448 deformat_string( dialog
->package
, text
, &title_font
);
449 font
= msi_dialog_get_style( title_font
, &title
);
452 control
->hwnd
= CreateWindowExW( exstyle
, szCls
, title
, style
,
453 x
, y
, width
, height
, parent
, NULL
, NULL
, NULL
);
455 TRACE("Dialog %s control %s hwnd %p\n",
456 debugstr_w(dialog
->name
), debugstr_w(text
), control
->hwnd
);
458 msi_dialog_set_font( dialog
, control
->hwnd
,
459 font
? font
: dialog
->default_font
);
461 msi_free( title_font
);
467 static LPWSTR
msi_dialog_get_uitext( msi_dialog
*dialog
, LPCWSTR key
)
472 static const WCHAR query
[] = {
473 's','e','l','e','c','t',' ','*',' ',
474 'f','r','o','m',' ','`','U','I','T','e','x','t','`',' ',
475 'w','h','e','r','e',' ','`','K','e','y','`',' ','=',' ','\'','%','s','\'',0
478 rec
= MSI_QueryGetRecord( dialog
->package
->db
, query
, key
);
479 if (!rec
) return NULL
;
480 text
= strdupW( MSI_RecordGetString( rec
, 2 ) );
481 msiobj_release( &rec
->hdr
);
485 static MSIRECORD
*msi_get_binary_record( MSIDATABASE
*db
, LPCWSTR name
)
487 static const WCHAR query
[] = {
488 's','e','l','e','c','t',' ','*',' ',
489 'f','r','o','m',' ','B','i','n','a','r','y',' ',
490 'w','h','e','r','e',' ',
491 '`','N','a','m','e','`',' ','=',' ','\'','%','s','\'',0
494 return MSI_QueryGetRecord( db
, query
, name
);
497 static LPWSTR
msi_create_tmp_path(void)
503 r
= GetTempPathW( MAX_PATH
, tmp
);
506 len
= lstrlenW( tmp
) + 20;
507 path
= msi_alloc( len
* sizeof (WCHAR
) );
510 r
= GetTempFileNameW( tmp
, szMsi
, 0, path
);
520 static HANDLE
msi_load_image( MSIDATABASE
*db
, LPCWSTR name
, UINT type
,
521 UINT cx
, UINT cy
, UINT flags
)
523 MSIRECORD
*rec
= NULL
;
524 HANDLE himage
= NULL
;
528 TRACE("%p %s %u %u %08x\n", db
, debugstr_w(name
), cx
, cy
, flags
);
530 tmp
= msi_create_tmp_path();
534 rec
= msi_get_binary_record( db
, name
);
537 r
= MSI_RecordStreamToFile( rec
, 2, tmp
);
538 if( r
== ERROR_SUCCESS
)
540 himage
= LoadImageW( 0, tmp
, type
, cx
, cy
, flags
);
542 msiobj_release( &rec
->hdr
);
550 static HICON
msi_load_icon( MSIDATABASE
*db
, LPCWSTR text
, UINT attributes
)
552 DWORD cx
= 0, cy
= 0, flags
;
554 flags
= LR_LOADFROMFILE
| LR_DEFAULTSIZE
;
555 if( attributes
& msidbControlAttributesFixedSize
)
557 flags
&= ~LR_DEFAULTSIZE
;
558 if( attributes
& msidbControlAttributesIconSize16
)
563 if( attributes
& msidbControlAttributesIconSize32
)
568 /* msidbControlAttributesIconSize48 handled by above logic */
570 return msi_load_image( db
, text
, IMAGE_ICON
, cx
, cy
, flags
);
573 static void msi_dialog_update_controls( msi_dialog
*dialog
, LPCWSTR property
)
575 msi_control
*control
;
577 LIST_FOR_EACH_ENTRY( control
, &dialog
->controls
, msi_control
, entry
)
579 if ( control
->property
&& !strcmpW( control
->property
, property
) && control
->update
)
580 control
->update( dialog
, control
);
584 static void msi_dialog_set_property( MSIPACKAGE
*package
, LPCWSTR property
, LPCWSTR value
)
586 UINT r
= msi_set_property( package
->db
, property
, value
);
587 if (r
== ERROR_SUCCESS
&& !strcmpW( property
, szSourceDir
))
588 msi_reset_folders( package
, TRUE
);
591 static MSIFEATURE
*msi_seltree_feature_from_item( HWND hwnd
, HTREEITEM hItem
)
595 /* get the feature from the item */
596 memset( &tvi
, 0, sizeof tvi
);
598 tvi
.mask
= TVIF_PARAM
| TVIF_HANDLE
;
599 SendMessageW( hwnd
, TVM_GETITEMW
, 0, (LPARAM
)&tvi
);
600 return (MSIFEATURE
*)tvi
.lParam
;
603 struct msi_selection_tree_info
611 static MSIFEATURE
*msi_seltree_get_selected_feature( msi_control
*control
)
613 struct msi_selection_tree_info
*info
= GetPropW( control
->hwnd
, szButtonData
);
614 return msi_seltree_feature_from_item( control
->hwnd
, info
->selected
);
617 /* called from the Control Event subscription code */
618 void msi_dialog_handle_event( msi_dialog
* dialog
, LPCWSTR control
,
619 LPCWSTR attribute
, MSIRECORD
*rec
)
622 LPCWSTR font_text
, text
= NULL
;
625 ctrl
= msi_dialog_find_control( dialog
, control
);
628 if( !strcmpW( attribute
, szText
) )
630 font_text
= MSI_RecordGetString( rec
, 1 );
631 font
= msi_dialog_get_style( font_text
, &text
);
632 if (!text
) text
= szEmpty
;
633 SetWindowTextW( ctrl
->hwnd
, text
);
635 msi_dialog_check_messages( NULL
);
637 else if( !strcmpW( attribute
, szProgress
) )
639 DWORD func
, val1
, val2
, units
;
641 func
= MSI_RecordGetInteger( rec
, 1 );
642 val1
= MSI_RecordGetInteger( rec
, 2 );
643 val2
= MSI_RecordGetInteger( rec
, 3 );
645 TRACE("progress: func %u val1 %u val2 %u\n", func
, val1
, val2
);
650 SendMessageW( ctrl
->hwnd
, PBM_SETRANGE
, 0, MAKELPARAM(0,100) );
654 ctrl
->progress_max
= units
? units
: 100;
655 ctrl
->progress_current
= units
;
656 ctrl
->progress_backwards
= TRUE
;
657 SendMessageW( ctrl
->hwnd
, PBM_SETPOS
, 100, 0 );
661 ctrl
->progress_max
= units
? units
: 100;
662 ctrl
->progress_current
= 0;
663 ctrl
->progress_backwards
= FALSE
;
664 SendMessageW( ctrl
->hwnd
, PBM_SETPOS
, 0, 0 );
667 case 1: /* FIXME: not sure what this is supposed to do */
671 if (ctrl
->progress_backwards
)
673 if (units
>= ctrl
->progress_current
) ctrl
->progress_current
-= units
;
674 else ctrl
->progress_current
= 0;
678 if (ctrl
->progress_current
+ units
< ctrl
->progress_max
) ctrl
->progress_current
+= units
;
679 else ctrl
->progress_current
= ctrl
->progress_max
;
681 SendMessageW( ctrl
->hwnd
, PBM_SETPOS
, MulDiv(100, ctrl
->progress_current
, ctrl
->progress_max
), 0 );
684 FIXME("Unknown progress message %u\n", func
);
688 else if ( !strcmpW( attribute
, szProperty
) )
690 MSIFEATURE
*feature
= msi_seltree_get_selected_feature( ctrl
);
691 msi_dialog_set_property( dialog
->package
, ctrl
->property
, feature
->Directory
);
693 else if ( !strcmpW( attribute
, szSelectionPath
) )
695 BOOL indirect
= ctrl
->attributes
& msidbControlAttributesIndirect
;
696 LPWSTR path
= msi_dialog_dup_property( dialog
, ctrl
->property
, indirect
);
698 SetWindowTextW( ctrl
->hwnd
, path
);
703 FIXME("Attribute %s not being set\n", debugstr_w(attribute
));
708 static void msi_dialog_map_events(msi_dialog
* dialog
, LPCWSTR control
)
710 static const WCHAR Query
[] = {
711 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
712 '`','E','v','e','n','t','M','a','p','p','i','n','g','`',' ',
713 'W','H','E','R','E',' ',
714 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',' ',
716 '`','C','o','n','t','r','o','l','_','`',' ','=',' ','\'','%','s','\'',0
719 LPCWSTR event
, attribute
;
721 row
= MSI_QueryGetRecord( dialog
->package
->db
, Query
, dialog
->name
, control
);
725 event
= MSI_RecordGetString( row
, 3 );
726 attribute
= MSI_RecordGetString( row
, 4 );
727 ControlEvent_SubscribeToEvent( dialog
->package
, dialog
, event
, control
, attribute
);
728 msiobj_release( &row
->hdr
);
731 /* everything except radio buttons */
732 static msi_control
*msi_dialog_add_control( msi_dialog
*dialog
,
733 MSIRECORD
*rec
, LPCWSTR szCls
, DWORD style
)
739 name
= MSI_RecordGetString( rec
, 2 );
740 attributes
= MSI_RecordGetInteger( rec
, 8 );
741 text
= MSI_RecordGetString( rec
, 10 );
743 TRACE("%s, %s, %08x, %s, %08x\n", debugstr_w(szCls
), debugstr_w(name
),
744 attributes
, debugstr_w(text
), style
);
746 if( attributes
& msidbControlAttributesVisible
)
748 if( ~attributes
& msidbControlAttributesEnabled
)
749 style
|= WS_DISABLED
;
750 if( attributes
& msidbControlAttributesSunken
)
751 exstyle
|= WS_EX_CLIENTEDGE
;
753 msi_dialog_map_events(dialog
, name
);
755 return msi_dialog_create_window( dialog
, rec
, exstyle
, szCls
, name
,
756 text
, style
, dialog
->hwnd
);
767 * we don't erase our own background,
768 * so we have to make sure that the parent window redraws first
770 static void msi_text_on_settext( HWND hWnd
)
775 hParent
= GetParent( hWnd
);
776 GetWindowRect( hWnd
, &rc
);
777 MapWindowPoints( NULL
, hParent
, (LPPOINT
) &rc
, 2 );
778 InvalidateRect( hParent
, &rc
, TRUE
);
781 static LRESULT WINAPI
782 MSIText_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
784 struct msi_text_info
*info
;
787 TRACE("%p %04x %08lx %08lx\n", hWnd
, msg
, wParam
, lParam
);
789 info
= GetPropW(hWnd
, szButtonData
);
791 if( msg
== WM_CTLCOLORSTATIC
&&
792 ( info
->attributes
& msidbControlAttributesTransparent
) )
794 SetBkMode( (HDC
)wParam
, TRANSPARENT
);
795 return (LRESULT
) GetStockObject(NULL_BRUSH
);
798 r
= CallWindowProcW(info
->oldproc
, hWnd
, msg
, wParam
, lParam
);
800 SetTextColor( (HDC
)wParam
, info
->font
->color
);
805 msi_text_on_settext( hWnd
);
809 RemovePropW( hWnd
, szButtonData
);
816 static UINT
msi_dialog_text_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
818 msi_control
*control
;
819 struct msi_text_info
*info
;
820 LPCWSTR text
, ptr
, prop
, control_name
;
823 TRACE("%p %p\n", dialog
, rec
);
825 control
= msi_dialog_add_control( dialog
, rec
, szStatic
, SS_LEFT
| WS_GROUP
);
827 return ERROR_FUNCTION_FAILED
;
829 info
= msi_alloc( sizeof *info
);
831 return ERROR_SUCCESS
;
833 control_name
= MSI_RecordGetString( rec
, 2 );
834 control
->attributes
= MSI_RecordGetInteger( rec
, 8 );
835 prop
= MSI_RecordGetString( rec
, 9 );
836 control
->property
= msi_dialog_dup_property( dialog
, prop
, FALSE
);
838 text
= MSI_RecordGetString( rec
, 10 );
839 font_name
= msi_dialog_get_style( text
, &ptr
);
840 info
->font
= ( font_name
) ? msi_dialog_find_font( dialog
, font_name
) : NULL
;
841 msi_free( font_name
);
843 info
->attributes
= MSI_RecordGetInteger( rec
, 8 );
844 if( info
->attributes
& msidbControlAttributesTransparent
)
845 SetWindowLongPtrW( control
->hwnd
, GWL_EXSTYLE
, WS_EX_TRANSPARENT
);
847 info
->oldproc
= (WNDPROC
) SetWindowLongPtrW( control
->hwnd
, GWLP_WNDPROC
,
848 (LONG_PTR
)MSIText_WndProc
);
849 SetPropW( control
->hwnd
, szButtonData
, info
);
851 ControlEvent_SubscribeToEvent( dialog
->package
, dialog
,
852 szSelectionPath
, control_name
, szSelectionPath
);
854 return ERROR_SUCCESS
;
857 /* strip any leading text style label from text field */
858 static WCHAR
*msi_get_binary_name( MSIPACKAGE
*package
, MSIRECORD
*rec
)
862 text
= msi_get_deformatted_field( package
, rec
, 10 );
867 while (*p
&& *p
!= '{') p
++;
868 if (!*p
++) return text
;
870 while (*p
&& *p
!= '}') p
++;
871 if (!*p
++) return text
;
878 static UINT
msi_dialog_set_property_event( msi_dialog
*dialog
, LPCWSTR event
, LPCWSTR arg
)
880 static const WCHAR szNullArg
[] = {'{','}',0};
881 LPWSTR p
, prop
, arg_fmt
= NULL
;
884 len
= strlenW( event
);
885 prop
= msi_alloc( len
* sizeof(WCHAR
) );
886 strcpyW( prop
, &event
[1] );
887 p
= strchrW( prop
, ']' );
888 if (p
&& (p
[1] == 0 || p
[1] == ' '))
891 if (strcmpW( szNullArg
, arg
))
892 deformat_string( dialog
->package
, arg
, &arg_fmt
);
893 msi_dialog_set_property( dialog
->package
, prop
, arg_fmt
);
894 msi_dialog_update_controls( dialog
, prop
);
897 else ERR("Badly formatted property string - what happens?\n");
899 return ERROR_SUCCESS
;
902 static UINT
msi_dialog_send_event( msi_dialog
*dialog
, LPCWSTR event
, LPCWSTR arg
)
904 LPWSTR event_fmt
= NULL
, arg_fmt
= NULL
;
906 TRACE("Sending control event %s %s\n", debugstr_w(event
), debugstr_w(arg
));
908 deformat_string( dialog
->package
, event
, &event_fmt
);
909 deformat_string( dialog
->package
, arg
, &arg_fmt
);
911 dialog
->event_handler( dialog
->package
, event_fmt
, arg_fmt
, dialog
);
913 msi_free( event_fmt
);
916 return ERROR_SUCCESS
;
919 static UINT
msi_dialog_control_event( MSIRECORD
*rec
, LPVOID param
)
921 msi_dialog
*dialog
= param
;
922 LPCWSTR condition
, event
, arg
;
925 condition
= MSI_RecordGetString( rec
, 5 );
926 r
= MSI_EvaluateConditionW( dialog
->package
, condition
);
927 if (r
== MSICONDITION_TRUE
|| r
== MSICONDITION_NONE
)
929 event
= MSI_RecordGetString( rec
, 3 );
930 arg
= MSI_RecordGetString( rec
, 4 );
932 msi_dialog_set_property_event( dialog
, event
, arg
);
934 msi_dialog_send_event( dialog
, event
, arg
);
936 return ERROR_SUCCESS
;
939 static UINT
msi_dialog_button_handler( msi_dialog
*dialog
, msi_control
*control
, WPARAM param
)
941 static const WCHAR query
[] = {
942 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
943 'C','o','n','t','r','o','l','E','v','e','n','t',' ','W','H','E','R','E',' ',
944 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',' ','A','N','D',' ',
945 '`','C','o','n','t','r','o','l','_','`',' ','=',' ','\'','%','s','\'',' ',
946 'O','R','D','E','R',' ','B','Y',' ','`','O','r','d','e','r','i','n','g','`',0};
950 if (HIWORD(param
) != BN_CLICKED
)
951 return ERROR_SUCCESS
;
953 r
= MSI_OpenQuery( dialog
->package
->db
, &view
, query
, dialog
->name
, control
->name
);
954 if (r
!= ERROR_SUCCESS
)
956 ERR("query failed\n");
957 return ERROR_SUCCESS
;
959 r
= MSI_IterateRecords( view
, 0, msi_dialog_control_event
, dialog
);
960 msiobj_release( &view
->hdr
);
964 static UINT
msi_dialog_button_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
966 msi_control
*control
;
967 UINT attributes
, style
;
969 TRACE("%p %p\n", dialog
, rec
);
972 attributes
= MSI_RecordGetInteger( rec
, 8 );
973 if( attributes
& msidbControlAttributesIcon
)
976 control
= msi_dialog_add_control( dialog
, rec
, szButton
, style
);
978 return ERROR_FUNCTION_FAILED
;
980 control
->handler
= msi_dialog_button_handler
;
982 if (attributes
& msidbControlAttributesIcon
)
985 LPWSTR name
= msi_get_binary_name( dialog
->package
, rec
);
986 control
->hIcon
= msi_load_icon( dialog
->package
->db
, name
, attributes
);
989 SendMessageW( control
->hwnd
, BM_SETIMAGE
, IMAGE_ICON
, (LPARAM
) control
->hIcon
);
992 ERR("Failed to load icon %s\n", debugstr_w(name
));
996 return ERROR_SUCCESS
;
999 static LPWSTR
msi_get_checkbox_value( msi_dialog
*dialog
, LPCWSTR prop
)
1001 static const WCHAR query
[] = {
1002 'S','E','L','E','C','T',' ','*',' ',
1003 'F','R','O','M',' ','`','C','h','e','c','k','B','o','x','`',' ',
1004 'W','H','E','R','E',' ',
1005 '`','P','r','o','p','e','r','t','y','`',' ','=',' ',
1008 MSIRECORD
*rec
= NULL
;
1011 /* find if there is a value associated with the checkbox */
1012 rec
= MSI_QueryGetRecord( dialog
->package
->db
, query
, prop
);
1016 ret
= msi_get_deformatted_field( dialog
->package
, rec
, 2 );
1017 if( ret
&& !ret
[0] )
1022 msiobj_release( &rec
->hdr
);
1026 ret
= msi_dup_property( dialog
->package
->db
, prop
);
1027 if( ret
&& !ret
[0] )
1036 static UINT
msi_dialog_get_checkbox_state( msi_dialog
*dialog
, msi_control
*control
)
1038 WCHAR state
[2] = {0};
1041 msi_get_property( dialog
->package
->db
, control
->property
, state
, &sz
);
1042 return state
[0] ? 1 : 0;
1045 static void msi_dialog_set_checkbox_state( msi_dialog
*dialog
, msi_control
*control
, UINT state
)
1047 static const WCHAR szState
[] = {'1',0};
1050 /* if uncheck then the property is set to NULL */
1053 msi_dialog_set_property( dialog
->package
, control
->property
, NULL
);
1057 /* check for a custom state */
1058 if (control
->value
&& control
->value
[0])
1059 val
= control
->value
;
1063 msi_dialog_set_property( dialog
->package
, control
->property
, val
);
1066 static void msi_dialog_checkbox_sync_state( msi_dialog
*dialog
, msi_control
*control
)
1068 UINT state
= msi_dialog_get_checkbox_state( dialog
, control
);
1069 SendMessageW( control
->hwnd
, BM_SETCHECK
, state
? BST_CHECKED
: BST_UNCHECKED
, 0 );
1072 static UINT
msi_dialog_checkbox_handler( msi_dialog
*dialog
, msi_control
*control
, WPARAM param
)
1076 if (HIWORD(param
) != BN_CLICKED
)
1077 return ERROR_SUCCESS
;
1079 TRACE("clicked checkbox %s, set %s\n", debugstr_w(control
->name
), debugstr_w(control
->property
));
1081 state
= msi_dialog_get_checkbox_state( dialog
, control
);
1082 state
= state
? 0 : 1;
1083 msi_dialog_set_checkbox_state( dialog
, control
, state
);
1084 msi_dialog_checkbox_sync_state( dialog
, control
);
1086 return msi_dialog_button_handler( dialog
, control
, param
);
1089 static UINT
msi_dialog_checkbox_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1091 msi_control
*control
;
1094 TRACE("%p %p\n", dialog
, rec
);
1096 control
= msi_dialog_add_control( dialog
, rec
, szButton
, BS_CHECKBOX
| BS_MULTILINE
| WS_TABSTOP
);
1097 control
->handler
= msi_dialog_checkbox_handler
;
1098 control
->update
= msi_dialog_checkbox_sync_state
;
1099 prop
= MSI_RecordGetString( rec
, 9 );
1102 control
->property
= strdupW( prop
);
1103 control
->value
= msi_get_checkbox_value( dialog
, prop
);
1104 TRACE("control %s value %s\n", debugstr_w(control
->property
), debugstr_w(control
->value
));
1106 msi_dialog_checkbox_sync_state( dialog
, control
);
1107 return ERROR_SUCCESS
;
1110 static UINT
msi_dialog_line_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1114 DWORD style
, exstyle
= 0;
1115 DWORD x
, y
, width
, height
;
1116 msi_control
*control
;
1118 TRACE("%p %p\n", dialog
, rec
);
1120 style
= WS_CHILD
| SS_ETCHEDHORZ
| SS_SUNKEN
;
1122 name
= MSI_RecordGetString( rec
, 2 );
1123 attributes
= MSI_RecordGetInteger( rec
, 8 );
1125 if( attributes
& msidbControlAttributesVisible
)
1126 style
|= WS_VISIBLE
;
1127 if( ~attributes
& msidbControlAttributesEnabled
)
1128 style
|= WS_DISABLED
;
1129 if( attributes
& msidbControlAttributesSunken
)
1130 exstyle
|= WS_EX_CLIENTEDGE
;
1132 msi_dialog_map_events(dialog
, name
);
1134 control
= msi_alloc( sizeof(*control
) + strlenW(name
) * sizeof(WCHAR
) );
1136 return ERROR_OUTOFMEMORY
;
1138 strcpyW( control
->name
, name
);
1139 list_add_head( &dialog
->controls
, &control
->entry
);
1140 control
->handler
= NULL
;
1141 control
->property
= NULL
;
1142 control
->value
= NULL
;
1143 control
->hBitmap
= NULL
;
1144 control
->hIcon
= NULL
;
1145 control
->hDll
= NULL
;
1146 control
->tabnext
= strdupW( MSI_RecordGetString( rec
, 11) );
1147 control
->type
= strdupW( MSI_RecordGetString( rec
, 3 ) );
1148 control
->progress_current
= 0;
1149 control
->progress_max
= 100;
1150 control
->progress_backwards
= FALSE
;
1152 x
= MSI_RecordGetInteger( rec
, 4 );
1153 y
= MSI_RecordGetInteger( rec
, 5 );
1154 width
= MSI_RecordGetInteger( rec
, 6 );
1156 x
= msi_dialog_scale_unit( dialog
, x
);
1157 y
= msi_dialog_scale_unit( dialog
, y
);
1158 width
= msi_dialog_scale_unit( dialog
, width
);
1159 height
= 2; /* line is exactly 2 units in height */
1161 control
->hwnd
= CreateWindowExW( exstyle
, szStatic
, NULL
, style
,
1162 x
, y
, width
, height
, dialog
->hwnd
, NULL
, NULL
, NULL
);
1164 TRACE("Dialog %s control %s hwnd %p\n",
1165 debugstr_w(dialog
->name
), debugstr_w(name
), control
->hwnd
);
1167 return ERROR_SUCCESS
;
1170 /******************** Scroll Text ********************************************/
1172 struct msi_scrolltext_info
1175 msi_control
*control
;
1179 static LRESULT WINAPI
1180 MSIScrollText_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1182 struct msi_scrolltext_info
*info
;
1185 TRACE("%p %04x %08lx %08lx\n", hWnd
, msg
, wParam
, lParam
);
1187 info
= GetPropW( hWnd
, szButtonData
);
1189 r
= CallWindowProcW( info
->oldproc
, hWnd
, msg
, wParam
, lParam
);
1194 return DLGC_WANTARROWS
;
1197 RemovePropW( hWnd
, szButtonData
);
1200 /* native MSI sets a wait cursor here */
1201 msi_dialog_button_handler( info
->dialog
, info
->control
, BN_CLICKED
);
1207 struct msi_streamin_info
1214 static DWORD CALLBACK
1215 msi_richedit_stream_in( DWORD_PTR arg
, LPBYTE buffer
, LONG count
, LONG
*pcb
)
1217 struct msi_streamin_info
*info
= (struct msi_streamin_info
*) arg
;
1219 if( (count
+ info
->offset
) > info
->length
)
1220 count
= info
->length
- info
->offset
;
1221 memcpy( buffer
, &info
->string
[ info
->offset
], count
);
1223 info
->offset
+= count
;
1225 TRACE("%d/%d\n", info
->offset
, info
->length
);
1230 static void msi_scrolltext_add_text( msi_control
*control
, LPCWSTR text
)
1232 struct msi_streamin_info info
;
1235 info
.string
= strdupWtoA( text
);
1237 info
.length
= lstrlenA( info
.string
) + 1;
1239 es
.dwCookie
= (DWORD_PTR
) &info
;
1241 es
.pfnCallback
= msi_richedit_stream_in
;
1243 SendMessageW( control
->hwnd
, EM_STREAMIN
, SF_RTF
, (LPARAM
) &es
);
1245 msi_free( info
.string
);
1248 static UINT
msi_dialog_scrolltext_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1250 static const WCHAR szRichEdit20W
[] = {'R','i','c','h','E','d','i','t','2','0','W',0};
1251 struct msi_scrolltext_info
*info
;
1252 msi_control
*control
;
1257 info
= msi_alloc( sizeof *info
);
1259 return ERROR_FUNCTION_FAILED
;
1261 hRichedit
= LoadLibraryA("riched20");
1263 style
= WS_BORDER
| ES_MULTILINE
| WS_VSCROLL
|
1264 ES_READONLY
| ES_AUTOVSCROLL
| WS_TABSTOP
;
1265 control
= msi_dialog_add_control( dialog
, rec
, szRichEdit20W
, style
);
1268 FreeLibrary( hRichedit
);
1270 return ERROR_FUNCTION_FAILED
;
1273 control
->hDll
= hRichedit
;
1275 info
->dialog
= dialog
;
1276 info
->control
= control
;
1278 /* subclass the static control */
1279 info
->oldproc
= (WNDPROC
) SetWindowLongPtrW( control
->hwnd
, GWLP_WNDPROC
,
1280 (LONG_PTR
)MSIScrollText_WndProc
);
1281 SetPropW( control
->hwnd
, szButtonData
, info
);
1283 /* add the text into the richedit */
1284 text
= MSI_RecordGetString( rec
, 10 );
1286 msi_scrolltext_add_text( control
, text
);
1288 return ERROR_SUCCESS
;
1291 static HBITMAP
msi_load_picture( MSIDATABASE
*db
, LPCWSTR name
,
1292 INT cx
, INT cy
, DWORD flags
)
1294 HBITMAP hOleBitmap
= 0, hBitmap
= 0, hOldSrcBitmap
, hOldDestBitmap
;
1295 MSIRECORD
*rec
= NULL
;
1296 IStream
*stm
= NULL
;
1297 IPicture
*pic
= NULL
;
1302 rec
= msi_get_binary_record( db
, name
);
1306 r
= MSI_RecordGetIStream( rec
, 2, &stm
);
1307 msiobj_release( &rec
->hdr
);
1308 if( r
!= ERROR_SUCCESS
)
1311 r
= OleLoadPicture( stm
, 0, TRUE
, &IID_IPicture
, (LPVOID
*) &pic
);
1312 IStream_Release( stm
);
1315 ERR("failed to load picture\n");
1319 r
= IPicture_get_Handle( pic
, (OLE_HANDLE
*) &hOleBitmap
);
1322 ERR("failed to get bitmap handle\n");
1326 /* make the bitmap the desired size */
1327 r
= GetObjectW( hOleBitmap
, sizeof bm
, &bm
);
1328 if (r
!= sizeof bm
)
1330 ERR("failed to get bitmap size\n");
1334 if (flags
& LR_DEFAULTSIZE
)
1340 srcdc
= CreateCompatibleDC( NULL
);
1341 hOldSrcBitmap
= SelectObject( srcdc
, hOleBitmap
);
1342 destdc
= CreateCompatibleDC( NULL
);
1343 hBitmap
= CreateCompatibleBitmap( srcdc
, cx
, cy
);
1344 hOldDestBitmap
= SelectObject( destdc
, hBitmap
);
1345 StretchBlt( destdc
, 0, 0, cx
, cy
,
1346 srcdc
, 0, 0, bm
.bmWidth
, bm
.bmHeight
, SRCCOPY
);
1347 SelectObject( srcdc
, hOldSrcBitmap
);
1348 SelectObject( destdc
, hOldDestBitmap
);
1354 IPicture_Release( pic
);
1358 static UINT
msi_dialog_bitmap_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1360 UINT cx
, cy
, flags
, style
, attributes
;
1361 msi_control
*control
;
1364 flags
= LR_LOADFROMFILE
;
1365 style
= SS_BITMAP
| SS_LEFT
| WS_GROUP
;
1367 attributes
= MSI_RecordGetInteger( rec
, 8 );
1368 if( attributes
& msidbControlAttributesFixedSize
)
1370 flags
|= LR_DEFAULTSIZE
;
1371 style
|= SS_CENTERIMAGE
;
1374 control
= msi_dialog_add_control( dialog
, rec
, szStatic
, style
);
1375 cx
= MSI_RecordGetInteger( rec
, 6 );
1376 cy
= MSI_RecordGetInteger( rec
, 7 );
1377 cx
= msi_dialog_scale_unit( dialog
, cx
);
1378 cy
= msi_dialog_scale_unit( dialog
, cy
);
1380 name
= msi_get_binary_name( dialog
->package
, rec
);
1381 control
->hBitmap
= msi_load_picture( dialog
->package
->db
, name
, cx
, cy
, flags
);
1382 if( control
->hBitmap
)
1383 SendMessageW( control
->hwnd
, STM_SETIMAGE
,
1384 IMAGE_BITMAP
, (LPARAM
) control
->hBitmap
);
1386 ERR("Failed to load bitmap %s\n", debugstr_w(name
));
1390 return ERROR_SUCCESS
;
1393 static UINT
msi_dialog_icon_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1395 msi_control
*control
;
1401 control
= msi_dialog_add_control( dialog
, rec
, szStatic
,
1402 SS_ICON
| SS_CENTERIMAGE
| WS_GROUP
);
1404 attributes
= MSI_RecordGetInteger( rec
, 8 );
1405 name
= msi_get_binary_name( dialog
->package
, rec
);
1406 control
->hIcon
= msi_load_icon( dialog
->package
->db
, name
, attributes
);
1407 if( control
->hIcon
)
1408 SendMessageW( control
->hwnd
, STM_SETICON
, (WPARAM
) control
->hIcon
, 0 );
1410 ERR("Failed to load bitmap %s\n", debugstr_w(name
));
1412 return ERROR_SUCCESS
;
1415 /******************** Combo Box ***************************************/
1417 struct msi_combobox_info
1427 static LRESULT WINAPI
MSIComboBox_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1429 struct msi_combobox_info
*info
;
1433 TRACE("%p %04x %08lx %08lx\n", hWnd
, msg
, wParam
, lParam
);
1435 info
= GetPropW( hWnd
, szButtonData
);
1439 r
= CallWindowProcW( info
->oldproc
, hWnd
, msg
, wParam
, lParam
);
1444 for (j
= 0; j
< info
->num_items
; j
++)
1445 msi_free( info
->items
[j
] );
1446 msi_free( info
->items
);
1448 RemovePropW( hWnd
, szButtonData
);
1455 static UINT
msi_combobox_add_item( MSIRECORD
*rec
, LPVOID param
)
1457 struct msi_combobox_info
*info
= param
;
1458 LPCWSTR value
, text
;
1461 value
= MSI_RecordGetString( rec
, 3 );
1462 text
= MSI_RecordGetString( rec
, 4 );
1464 info
->items
[info
->addpos_items
] = strdupW( value
);
1466 pos
= SendMessageW( info
->hwnd
, CB_ADDSTRING
, 0, (LPARAM
)text
);
1467 SendMessageW( info
->hwnd
, CB_SETITEMDATA
, pos
, (LPARAM
)info
->items
[info
->addpos_items
] );
1468 info
->addpos_items
++;
1470 return ERROR_SUCCESS
;
1473 static UINT
msi_combobox_add_items( struct msi_combobox_info
*info
, LPCWSTR property
)
1475 static const WCHAR query
[] = {
1476 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
1477 '`','C','o','m','b','o','B','o','x','`',' ','W','H','E','R','E',' ',
1478 '`','P','r','o','p','e','r','t','y','`',' ','=',' ','\'','%','s','\'',' ',
1479 'O','R','D','E','R',' ','B','Y',' ','`','O','r','d','e','r','`',0};
1484 r
= MSI_OpenQuery( info
->dialog
->package
->db
, &view
, query
, property
);
1485 if (r
!= ERROR_SUCCESS
)
1488 /* just get the number of records */
1490 r
= MSI_IterateRecords( view
, &count
, NULL
, NULL
);
1491 if (r
!= ERROR_SUCCESS
)
1493 msiobj_release( &view
->hdr
);
1496 info
->num_items
= count
;
1497 info
->items
= msi_alloc( sizeof(*info
->items
) * count
);
1499 r
= MSI_IterateRecords( view
, NULL
, msi_combobox_add_item
, info
);
1500 msiobj_release( &view
->hdr
);
1504 static UINT
msi_dialog_set_control_condition( MSIRECORD
*rec
, LPVOID param
)
1506 static const WCHAR szHide
[] = {'H','i','d','e',0};
1507 static const WCHAR szShow
[] = {'S','h','o','w',0};
1508 static const WCHAR szDisable
[] = {'D','i','s','a','b','l','e',0};
1509 static const WCHAR szEnable
[] = {'E','n','a','b','l','e',0};
1510 static const WCHAR szDefault
[] = {'D','e','f','a','u','l','t',0};
1511 msi_dialog
*dialog
= param
;
1512 msi_control
*control
;
1513 LPCWSTR name
, action
, condition
;
1516 name
= MSI_RecordGetString( rec
, 2 );
1517 action
= MSI_RecordGetString( rec
, 3 );
1518 condition
= MSI_RecordGetString( rec
, 4 );
1519 r
= MSI_EvaluateConditionW( dialog
->package
, condition
);
1520 control
= msi_dialog_find_control( dialog
, name
);
1521 if (r
== MSICONDITION_TRUE
&& control
)
1523 TRACE("%s control %s\n", debugstr_w(action
), debugstr_w(name
));
1525 /* FIXME: case sensitive? */
1526 if (!strcmpW( action
, szHide
))
1527 ShowWindow(control
->hwnd
, SW_HIDE
);
1528 else if (!strcmpW( action
, szShow
))
1529 ShowWindow(control
->hwnd
, SW_SHOW
);
1530 else if (!strcmpW( action
, szDisable
))
1531 EnableWindow(control
->hwnd
, FALSE
);
1532 else if (!strcmpW( action
, szEnable
))
1533 EnableWindow(control
->hwnd
, TRUE
);
1534 else if (!strcmpW( action
, szDefault
))
1535 SetFocus(control
->hwnd
);
1537 FIXME("Unhandled action %s\n", debugstr_w(action
));
1539 return ERROR_SUCCESS
;
1542 static UINT
msi_dialog_evaluate_control_conditions( msi_dialog
*dialog
)
1544 static const WCHAR query
[] = {
1545 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
1546 'C','o','n','t','r','o','l','C','o','n','d','i','t','i','o','n',' ',
1547 'W','H','E','R','E',' ','`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',0};
1550 MSIPACKAGE
*package
= dialog
->package
;
1552 TRACE("%p %s\n", dialog
, debugstr_w(dialog
->name
));
1554 /* query the Control table for all the elements of the control */
1555 r
= MSI_OpenQuery( package
->db
, &view
, query
, dialog
->name
);
1556 if (r
!= ERROR_SUCCESS
)
1557 return ERROR_SUCCESS
;
1559 r
= MSI_IterateRecords( view
, 0, msi_dialog_set_control_condition
, dialog
);
1560 msiobj_release( &view
->hdr
);
1564 static UINT
msi_dialog_combobox_handler( msi_dialog
*dialog
, msi_control
*control
, WPARAM param
)
1566 struct msi_combobox_info
*info
;
1570 if (HIWORD(param
) != CBN_SELCHANGE
&& HIWORD(param
) != CBN_EDITCHANGE
)
1571 return ERROR_SUCCESS
;
1573 info
= GetPropW( control
->hwnd
, szButtonData
);
1574 index
= SendMessageW( control
->hwnd
, CB_GETCURSEL
, 0, 0 );
1575 if (index
== CB_ERR
)
1576 value
= msi_get_window_text( control
->hwnd
);
1578 value
= (LPWSTR
) SendMessageW( control
->hwnd
, CB_GETITEMDATA
, index
, 0 );
1580 msi_dialog_set_property( info
->dialog
->package
, control
->property
, value
);
1581 msi_dialog_evaluate_control_conditions( info
->dialog
);
1583 if (index
== CB_ERR
)
1586 return ERROR_SUCCESS
;
1589 static void msi_dialog_combobox_update( msi_dialog
*dialog
, msi_control
*control
)
1591 struct msi_combobox_info
*info
;
1595 info
= GetPropW( control
->hwnd
, szButtonData
);
1597 value
= msi_dup_property( dialog
->package
->db
, control
->property
);
1600 SendMessageW( control
->hwnd
, CB_SETCURSEL
, -1, 0 );
1604 for (j
= 0; j
< info
->num_items
; j
++)
1606 tmp
= (LPWSTR
) SendMessageW( control
->hwnd
, CB_GETITEMDATA
, j
, 0 );
1607 if (!strcmpW( value
, tmp
))
1611 if (j
< info
->num_items
)
1613 SendMessageW( control
->hwnd
, CB_SETCURSEL
, j
, 0 );
1617 SendMessageW( control
->hwnd
, CB_SETCURSEL
, -1, 0 );
1618 SetWindowTextW( control
->hwnd
, value
);
1624 static UINT
msi_dialog_combo_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1626 struct msi_combobox_info
*info
;
1627 msi_control
*control
;
1628 DWORD attributes
, style
;
1631 info
= msi_alloc( sizeof *info
);
1633 return ERROR_FUNCTION_FAILED
;
1635 style
= CBS_AUTOHSCROLL
| WS_TABSTOP
| WS_GROUP
| WS_CHILD
;
1636 attributes
= MSI_RecordGetInteger( rec
, 8 );
1637 if ( ~attributes
& msidbControlAttributesSorted
)
1639 if ( attributes
& msidbControlAttributesComboList
)
1640 style
|= CBS_DROPDOWNLIST
;
1642 style
|= CBS_DROPDOWN
;
1644 control
= msi_dialog_add_control( dialog
, rec
, WC_COMBOBOXW
, style
);
1648 return ERROR_FUNCTION_FAILED
;
1651 control
->handler
= msi_dialog_combobox_handler
;
1652 control
->update
= msi_dialog_combobox_update
;
1654 prop
= MSI_RecordGetString( rec
, 9 );
1655 control
->property
= msi_dialog_dup_property( dialog
, prop
, FALSE
);
1658 info
->dialog
= dialog
;
1659 info
->hwnd
= control
->hwnd
;
1661 info
->addpos_items
= 0;
1662 info
->oldproc
= (WNDPROC
)SetWindowLongPtrW( control
->hwnd
, GWLP_WNDPROC
,
1663 (LONG_PTR
)MSIComboBox_WndProc
);
1664 SetPropW( control
->hwnd
, szButtonData
, info
);
1666 if (control
->property
)
1667 msi_combobox_add_items( info
, control
->property
);
1669 msi_dialog_combobox_update( dialog
, control
);
1671 return ERROR_SUCCESS
;
1674 static UINT
msi_dialog_edit_handler( msi_dialog
*dialog
, msi_control
*control
, WPARAM param
)
1678 if (HIWORD(param
) != EN_CHANGE
)
1679 return ERROR_SUCCESS
;
1681 TRACE("edit %s contents changed, set %s\n", debugstr_w(control
->name
), debugstr_w(control
->property
));
1683 buf
= msi_get_window_text( control
->hwnd
);
1684 msi_dialog_set_property( dialog
->package
, control
->property
, buf
);
1687 return ERROR_SUCCESS
;
1690 /* length of 2^32 + 1 */
1691 #define MAX_NUM_DIGITS 11
1693 static UINT
msi_dialog_edit_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1695 msi_control
*control
;
1697 LPWSTR val
, begin
, end
;
1698 WCHAR num
[MAX_NUM_DIGITS
];
1701 control
= msi_dialog_add_control( dialog
, rec
, szEdit
,
1702 WS_BORDER
| WS_TABSTOP
| ES_AUTOHSCROLL
);
1703 control
->handler
= msi_dialog_edit_handler
;
1705 text
= MSI_RecordGetString( rec
, 10 );
1708 begin
= strchrW( text
, '{' );
1709 end
= strchrW( text
, '}' );
1711 if ( begin
&& end
&& end
> begin
&&
1712 begin
[0] >= '0' && begin
[0] <= '9' &&
1713 end
- begin
< MAX_NUM_DIGITS
)
1715 lstrcpynW( num
, begin
+ 1, end
- begin
);
1716 limit
= atolW( num
);
1718 SendMessageW( control
->hwnd
, EM_SETLIMITTEXT
, limit
, 0 );
1722 prop
= MSI_RecordGetString( rec
, 9 );
1724 control
->property
= strdupW( prop
);
1726 val
= msi_dup_property( dialog
->package
->db
, control
->property
);
1727 SetWindowTextW( control
->hwnd
, val
);
1729 return ERROR_SUCCESS
;
1732 /******************** Masked Edit ********************************************/
1734 #define MASK_MAX_GROUPS 20
1736 struct msi_mask_group
1744 struct msi_maskedit_info
1752 struct msi_mask_group group
[MASK_MAX_GROUPS
];
1755 static BOOL
msi_mask_editable( WCHAR type
)
1770 static void msi_mask_control_change( struct msi_maskedit_info
*info
)
1775 val
= msi_alloc( (info
->num_chars
+1)*sizeof(WCHAR
) );
1776 for( i
=0, n
=0; i
<info
->num_groups
; i
++ )
1778 if( (info
->group
[i
].len
+ n
) > info
->num_chars
)
1780 ERR("can't fit control %d text into template\n",i
);
1783 if (!msi_mask_editable(info
->group
[i
].type
))
1785 for(r
=0; r
<info
->group
[i
].len
; r
++)
1786 val
[n
+r
] = info
->group
[i
].type
;
1791 r
= GetWindowTextW( info
->group
[i
].hwnd
, &val
[n
], info
->group
[i
].len
+1 );
1792 if( r
!= info
->group
[i
].len
)
1798 TRACE("%d/%d controls were good\n", i
, info
->num_groups
);
1800 if( i
== info
->num_groups
)
1802 TRACE("Set property %s to %s\n", debugstr_w(info
->prop
), debugstr_w(val
));
1803 CharUpperBuffW( val
, info
->num_chars
);
1804 msi_dialog_set_property( info
->dialog
->package
, info
->prop
, val
);
1805 msi_dialog_evaluate_control_conditions( info
->dialog
);
1810 /* now move to the next control if necessary */
1811 static VOID
msi_mask_next_control( struct msi_maskedit_info
*info
, HWND hWnd
)
1816 for( i
=0; i
<info
->num_groups
; i
++ )
1817 if( info
->group
[i
].hwnd
== hWnd
)
1820 /* don't move from the last control */
1821 if( i
>= (info
->num_groups
-1) )
1824 len
= SendMessageW( hWnd
, WM_GETTEXTLENGTH
, 0, 0 );
1825 if( len
< info
->group
[i
].len
)
1828 hWndNext
= GetNextDlgTabItem( GetParent( hWnd
), hWnd
, FALSE
);
1829 SetFocus( hWndNext
);
1832 static LRESULT WINAPI
1833 MSIMaskedEdit_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1835 struct msi_maskedit_info
*info
;
1838 TRACE("%p %04x %08lx %08lx\n", hWnd
, msg
, wParam
, lParam
);
1840 info
= GetPropW(hWnd
, szButtonData
);
1842 r
= CallWindowProcW(info
->oldproc
, hWnd
, msg
, wParam
, lParam
);
1847 if (HIWORD(wParam
) == EN_CHANGE
)
1849 msi_mask_control_change( info
);
1850 msi_mask_next_control( info
, (HWND
) lParam
);
1854 msi_free( info
->prop
);
1856 RemovePropW( hWnd
, szButtonData
);
1863 /* fish the various bits of the property out and put them in the control */
1865 msi_maskedit_set_text( struct msi_maskedit_info
*info
, LPCWSTR text
)
1871 for( i
= 0; i
< info
->num_groups
; i
++ )
1873 if( info
->group
[i
].len
< strlenW( p
) )
1875 LPWSTR chunk
= strdupW( p
);
1876 chunk
[ info
->group
[i
].len
] = 0;
1877 SetWindowTextW( info
->group
[i
].hwnd
, chunk
);
1882 SetWindowTextW( info
->group
[i
].hwnd
, p
);
1885 p
+= info
->group
[i
].len
;
1889 static struct msi_maskedit_info
* msi_dialog_parse_groups( LPCWSTR mask
)
1891 struct msi_maskedit_info
* info
= NULL
;
1892 int i
= 0, n
= 0, total
= 0;
1895 TRACE("masked control, template %s\n", debugstr_w(mask
));
1900 info
= msi_alloc_zero( sizeof *info
);
1904 p
= strchrW(mask
, '<');
1910 for( i
=0; i
<MASK_MAX_GROUPS
; i
++ )
1912 /* stop at the end of the string */
1913 if( p
[0] == 0 || p
[0] == '>' )
1916 /* count the number of the same identifier */
1917 for( n
=0; p
[n
] == p
[0]; n
++ )
1919 info
->group
[i
].ofs
= total
;
1920 info
->group
[i
].type
= p
[0];
1924 total
++; /* an extra not part of the group */
1926 info
->group
[i
].len
= n
;
1931 TRACE("%d characters in %d groups\n", total
, i
);
1932 if( i
== MASK_MAX_GROUPS
)
1933 ERR("too many groups in PIDTemplate %s\n", debugstr_w(mask
));
1935 info
->num_chars
= total
;
1936 info
->num_groups
= i
;
1942 msi_maskedit_create_children( struct msi_maskedit_info
*info
, LPCWSTR font
)
1944 DWORD width
, height
, style
, wx
, ww
;
1949 style
= WS_CHILD
| WS_BORDER
| WS_VISIBLE
| WS_TABSTOP
| ES_AUTOHSCROLL
;
1951 GetClientRect( info
->hwnd
, &rect
);
1953 width
= rect
.right
- rect
.left
;
1954 height
= rect
.bottom
- rect
.top
;
1956 for( i
= 0; i
< info
->num_groups
; i
++ )
1958 if (!msi_mask_editable( info
->group
[i
].type
))
1960 wx
= (info
->group
[i
].ofs
* width
) / info
->num_chars
;
1961 ww
= (info
->group
[i
].len
* width
) / info
->num_chars
;
1963 hwnd
= CreateWindowW( szEdit
, NULL
, style
, wx
, 0, ww
, height
,
1964 info
->hwnd
, NULL
, NULL
, NULL
);
1967 ERR("failed to create mask edit sub window\n");
1971 SendMessageW( hwnd
, EM_LIMITTEXT
, info
->group
[i
].len
, 0 );
1973 msi_dialog_set_font( info
->dialog
, hwnd
,
1974 font
?font
:info
->dialog
->default_font
);
1975 info
->group
[i
].hwnd
= hwnd
;
1980 * office 2003 uses "73931<````=````=````=````=`````>@@@@@"
1981 * delphi 7 uses "<????-??????-??????-????>" and "<???-???>"
1982 * filemaker pro 7 uses "<^^^^=^^^^=^^^^=^^^^=^^^^=^^^^=^^^^^>"
1984 static UINT
msi_dialog_maskedit_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1986 LPWSTR font_mask
, val
= NULL
, font
;
1987 struct msi_maskedit_info
*info
= NULL
;
1988 UINT ret
= ERROR_SUCCESS
;
1989 msi_control
*control
;
1994 font_mask
= msi_get_deformatted_field( dialog
->package
, rec
, 10 );
1995 font
= msi_dialog_get_style( font_mask
, &mask
);
1998 WARN("mask template is empty\n");
2002 info
= msi_dialog_parse_groups( mask
);
2005 ERR("template %s is invalid\n", debugstr_w(mask
));
2009 info
->dialog
= dialog
;
2011 control
= msi_dialog_add_control( dialog
, rec
, szStatic
,
2012 SS_OWNERDRAW
| WS_GROUP
| WS_VISIBLE
);
2015 ERR("Failed to create maskedit container\n");
2016 ret
= ERROR_FUNCTION_FAILED
;
2019 SetWindowLongPtrW( control
->hwnd
, GWL_EXSTYLE
, WS_EX_CONTROLPARENT
);
2021 info
->hwnd
= control
->hwnd
;
2023 /* subclass the static control */
2024 info
->oldproc
= (WNDPROC
) SetWindowLongPtrW( info
->hwnd
, GWLP_WNDPROC
,
2025 (LONG_PTR
)MSIMaskedEdit_WndProc
);
2026 SetPropW( control
->hwnd
, szButtonData
, info
);
2028 prop
= MSI_RecordGetString( rec
, 9 );
2030 info
->prop
= strdupW( prop
);
2032 msi_maskedit_create_children( info
, font
);
2036 val
= msi_dup_property( dialog
->package
->db
, prop
);
2039 msi_maskedit_set_text( info
, val
);
2045 if( ret
!= ERROR_SUCCESS
)
2047 msi_free( font_mask
);
2052 /******************** Progress Bar *****************************************/
2054 static UINT
msi_dialog_progress_bar( msi_dialog
*dialog
, MSIRECORD
*rec
)
2056 msi_control
*control
;
2057 DWORD attributes
, style
;
2060 attributes
= MSI_RecordGetInteger( rec
, 8 );
2061 if( !(attributes
& msidbControlAttributesProgress95
) )
2062 style
|= PBS_SMOOTH
;
2064 control
= msi_dialog_add_control( dialog
, rec
, PROGRESS_CLASSW
, style
);
2066 return ERROR_FUNCTION_FAILED
;
2068 ControlEvent_SubscribeToEvent( dialog
->package
, dialog
,
2069 szSetProgress
, control
->name
, szProgress
);
2070 return ERROR_SUCCESS
;
2073 /******************** Path Edit ********************************************/
2075 struct msi_pathedit_info
2078 msi_control
*control
;
2082 static void msi_dialog_update_pathedit( msi_dialog
*dialog
, msi_control
*control
)
2087 if (!control
&& !(control
= msi_dialog_find_control_by_type( dialog
, szPathEdit
)))
2090 indirect
= control
->attributes
& msidbControlAttributesIndirect
;
2091 prop
= msi_dialog_dup_property( dialog
, control
->property
, indirect
);
2092 path
= msi_dialog_dup_property( dialog
, prop
, TRUE
);
2094 SetWindowTextW( control
->hwnd
, path
);
2095 SendMessageW( control
->hwnd
, EM_SETSEL
, 0, -1 );
2101 /* FIXME: test when this should fail */
2102 static BOOL
msi_dialog_verify_path( LPWSTR path
)
2104 if ( !lstrlenW( path
) )
2107 if ( PathIsRelativeW( path
) )
2113 /* returns TRUE if the path is valid, FALSE otherwise */
2114 static BOOL
msi_dialog_onkillfocus( msi_dialog
*dialog
, msi_control
*control
)
2120 indirect
= control
->attributes
& msidbControlAttributesIndirect
;
2121 prop
= msi_dialog_dup_property( dialog
, control
->property
, indirect
);
2123 buf
= msi_get_window_text( control
->hwnd
);
2125 if ( !msi_dialog_verify_path( buf
) )
2127 /* FIXME: display an error message box */
2128 ERR("Invalid path %s\n", debugstr_w( buf
));
2130 SetFocus( control
->hwnd
);
2135 msi_dialog_set_property( dialog
->package
, prop
, buf
);
2138 msi_dialog_update_pathedit( dialog
, control
);
2140 TRACE("edit %s contents changed, set %s\n", debugstr_w(control
->name
),
2149 static LRESULT WINAPI
MSIPathEdit_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
2151 struct msi_pathedit_info
*info
= GetPropW(hWnd
, szButtonData
);
2154 TRACE("%p %04x %08lx %08lx\n", hWnd
, msg
, wParam
, lParam
);
2156 if ( msg
== WM_KILLFOCUS
)
2158 /* if the path is invalid, don't handle this message */
2159 if ( !msi_dialog_onkillfocus( info
->dialog
, info
->control
) )
2163 r
= CallWindowProcW(info
->oldproc
, hWnd
, msg
, wParam
, lParam
);
2165 if ( msg
== WM_NCDESTROY
)
2168 RemovePropW( hWnd
, szButtonData
);
2174 static UINT
msi_dialog_pathedit_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
2176 struct msi_pathedit_info
*info
;
2177 msi_control
*control
;
2180 info
= msi_alloc( sizeof *info
);
2182 return ERROR_FUNCTION_FAILED
;
2184 control
= msi_dialog_add_control( dialog
, rec
, szEdit
,
2185 WS_BORDER
| WS_TABSTOP
);
2186 control
->attributes
= MSI_RecordGetInteger( rec
, 8 );
2187 prop
= MSI_RecordGetString( rec
, 9 );
2188 control
->property
= msi_dialog_dup_property( dialog
, prop
, FALSE
);
2190 info
->dialog
= dialog
;
2191 info
->control
= control
;
2192 info
->oldproc
= (WNDPROC
) SetWindowLongPtrW( control
->hwnd
, GWLP_WNDPROC
,
2193 (LONG_PTR
)MSIPathEdit_WndProc
);
2194 SetPropW( control
->hwnd
, szButtonData
, info
);
2196 msi_dialog_update_pathedit( dialog
, control
);
2198 return ERROR_SUCCESS
;
2201 static UINT
msi_dialog_radiogroup_handler( msi_dialog
*dialog
, msi_control
*control
, WPARAM param
)
2203 if (HIWORD(param
) != BN_CLICKED
)
2204 return ERROR_SUCCESS
;
2206 TRACE("clicked radio button %s, set %s\n", debugstr_w(control
->name
), debugstr_w(control
->property
));
2208 msi_dialog_set_property( dialog
->package
, control
->property
, control
->name
);
2210 return msi_dialog_button_handler( dialog
, control
, param
);
2213 /* radio buttons are a bit different from normal controls */
2214 static UINT
msi_dialog_create_radiobutton( MSIRECORD
*rec
, LPVOID param
)
2216 radio_button_group_descr
*group
= param
;
2217 msi_dialog
*dialog
= group
->dialog
;
2218 msi_control
*control
;
2219 LPCWSTR prop
, text
, name
;
2220 DWORD style
, attributes
= group
->attributes
;
2222 style
= WS_CHILD
| BS_AUTORADIOBUTTON
| BS_MULTILINE
| WS_TABSTOP
;
2223 name
= MSI_RecordGetString( rec
, 3 );
2224 text
= MSI_RecordGetString( rec
, 8 );
2225 if( attributes
& msidbControlAttributesVisible
)
2226 style
|= WS_VISIBLE
;
2227 if( ~attributes
& msidbControlAttributesEnabled
)
2228 style
|= WS_DISABLED
;
2230 control
= msi_dialog_create_window( dialog
, rec
, 0, szButton
, name
, text
,
2231 style
, group
->parent
->hwnd
);
2233 return ERROR_FUNCTION_FAILED
;
2234 control
->handler
= msi_dialog_radiogroup_handler
;
2236 if (group
->propval
&& !strcmpW( control
->name
, group
->propval
))
2237 SendMessageW(control
->hwnd
, BM_SETCHECK
, BST_CHECKED
, 0);
2239 prop
= MSI_RecordGetString( rec
, 1 );
2241 control
->property
= strdupW( prop
);
2243 return ERROR_SUCCESS
;
2246 static BOOL CALLBACK
msi_radioground_child_enum( HWND hWnd
, LPARAM lParam
)
2248 EnableWindow( hWnd
, lParam
);
2252 static LRESULT WINAPI
MSIRadioGroup_WndProc( HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
2254 WNDPROC oldproc
= (WNDPROC
)GetPropW( hWnd
, szButtonData
);
2257 TRACE("hWnd %p msg %04x wParam 0x%08lx lParam 0x%08lx\n", hWnd
, msg
, wParam
, lParam
);
2259 if (msg
== WM_COMMAND
) /* Forward notifications to dialog */
2260 SendMessageW( GetParent( hWnd
), msg
, wParam
, lParam
);
2262 r
= CallWindowProcW( oldproc
, hWnd
, msg
, wParam
, lParam
);
2264 /* make sure the radio buttons show as disabled if the parent is disabled */
2265 if (msg
== WM_ENABLE
)
2266 EnumChildWindows( hWnd
, msi_radioground_child_enum
, wParam
);
2271 static UINT
msi_dialog_radiogroup_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
2273 static const WCHAR query
[] = {
2274 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2275 'R','a','d','i','o','B','u','t','t','o','n',' ','W','H','E','R','E',' ',
2276 '`','P','r','o','p','e','r','t','y','`',' ','=',' ','\'','%','s','\'',0};
2279 msi_control
*control
;
2281 radio_button_group_descr group
;
2282 MSIPACKAGE
*package
= dialog
->package
;
2284 DWORD attr
, style
= WS_GROUP
;
2286 prop
= MSI_RecordGetString( rec
, 9 );
2288 TRACE("%p %p %s\n", dialog
, rec
, debugstr_w( prop
));
2290 attr
= MSI_RecordGetInteger( rec
, 8 );
2291 if (attr
& msidbControlAttributesHasBorder
)
2292 style
|= BS_GROUPBOX
;
2294 style
|= BS_OWNERDRAW
;
2296 /* Create parent group box to hold radio buttons */
2297 control
= msi_dialog_add_control( dialog
, rec
, szButton
, style
);
2299 return ERROR_FUNCTION_FAILED
;
2301 oldproc
= (WNDPROC
) SetWindowLongPtrW( control
->hwnd
, GWLP_WNDPROC
,
2302 (LONG_PTR
)MSIRadioGroup_WndProc
);
2303 SetPropW(control
->hwnd
, szButtonData
, oldproc
);
2304 SetWindowLongPtrW( control
->hwnd
, GWL_EXSTYLE
, WS_EX_CONTROLPARENT
);
2307 control
->property
= strdupW( prop
);
2309 /* query the Radio Button table for all control in this group */
2310 r
= MSI_OpenQuery( package
->db
, &view
, query
, prop
);
2311 if( r
!= ERROR_SUCCESS
)
2313 ERR("query failed for dialog %s radio group %s\n",
2314 debugstr_w(dialog
->name
), debugstr_w(prop
));
2315 return ERROR_INVALID_PARAMETER
;
2318 group
.dialog
= dialog
;
2319 group
.parent
= control
;
2320 group
.attributes
= MSI_RecordGetInteger( rec
, 8 );
2321 group
.propval
= msi_dup_property( dialog
->package
->db
, control
->property
);
2323 r
= MSI_IterateRecords( view
, 0, msi_dialog_create_radiobutton
, &group
);
2324 msiobj_release( &view
->hdr
);
2325 msi_free( group
.propval
);
2330 msi_seltree_sync_item_state( HWND hwnd
, MSIFEATURE
*feature
, HTREEITEM hItem
)
2333 DWORD index
= feature
->ActionRequest
;
2335 TRACE("Feature %s -> %d %d %d\n", debugstr_w(feature
->Title
),
2336 feature
->Installed
, feature
->Action
, feature
->ActionRequest
);
2338 if (index
== INSTALLSTATE_UNKNOWN
)
2339 index
= INSTALLSTATE_ABSENT
;
2341 tvi
.mask
= TVIF_STATE
;
2343 tvi
.state
= INDEXTOSTATEIMAGEMASK( index
);
2344 tvi
.stateMask
= TVIS_STATEIMAGEMASK
;
2346 SendMessageW( hwnd
, TVM_SETITEMW
, 0, (LPARAM
) &tvi
);
2350 msi_seltree_popup_menu( HWND hwnd
, INT x
, INT y
)
2355 /* create a menu to display */
2356 hMenu
= CreatePopupMenu();
2358 /* FIXME: load strings from resources */
2359 AppendMenuA( hMenu
, MF_ENABLED
, INSTALLSTATE_LOCAL
, "Install feature locally");
2360 AppendMenuA( hMenu
, MF_ENABLED
, USER_INSTALLSTATE_ALL
, "Install entire feature");
2361 AppendMenuA( hMenu
, MF_ENABLED
, INSTALLSTATE_ADVERTISED
, "Install on demand");
2362 AppendMenuA( hMenu
, MF_ENABLED
, INSTALLSTATE_ABSENT
, "Don't install");
2363 r
= TrackPopupMenu( hMenu
, TPM_LEFTALIGN
| TPM_TOPALIGN
| TPM_RETURNCMD
,
2364 x
, y
, 0, hwnd
, NULL
);
2365 DestroyMenu( hMenu
);
2370 msi_seltree_update_feature_installstate( HWND hwnd
, HTREEITEM hItem
,
2371 MSIPACKAGE
*package
, MSIFEATURE
*feature
, INSTALLSTATE state
)
2373 feature
->ActionRequest
= state
;
2374 msi_seltree_sync_item_state( hwnd
, feature
, hItem
);
2375 ACTION_UpdateComponentStates( package
, feature
);
2379 msi_seltree_update_siblings_and_children_installstate( HWND hwnd
, HTREEITEM curr
,
2380 MSIPACKAGE
*package
, INSTALLSTATE state
)
2382 /* update all siblings */
2385 MSIFEATURE
*feature
;
2388 feature
= msi_seltree_feature_from_item( hwnd
, curr
);
2389 msi_seltree_update_feature_installstate( hwnd
, curr
, package
, feature
, state
);
2391 /* update this sibling's children */
2392 child
= (HTREEITEM
)SendMessageW( hwnd
, TVM_GETNEXTITEM
, (WPARAM
)TVGN_CHILD
, (LPARAM
)curr
);
2394 msi_seltree_update_siblings_and_children_installstate( hwnd
, child
,
2397 while ((curr
= (HTREEITEM
)SendMessageW( hwnd
, TVM_GETNEXTITEM
, (WPARAM
)TVGN_NEXT
, (LPARAM
)curr
)));
2401 msi_seltree_menu( HWND hwnd
, HTREEITEM hItem
)
2403 struct msi_selection_tree_info
*info
;
2404 MSIFEATURE
*feature
;
2405 MSIPACKAGE
*package
;
2413 info
= GetPropW(hwnd
, szButtonData
);
2414 package
= info
->dialog
->package
;
2416 feature
= msi_seltree_feature_from_item( hwnd
, hItem
);
2419 ERR("item %p feature was NULL\n", hItem
);
2423 /* get the item's rectangle to put the menu just below it */
2425 SendMessageW( hwnd
, TVM_GETITEMRECT
, 0, (LPARAM
) &u
.rc
);
2426 MapWindowPoints( hwnd
, NULL
, u
.pt
, 2 );
2428 r
= msi_seltree_popup_menu( hwnd
, u
.rc
.left
, u
.rc
.top
);
2432 case USER_INSTALLSTATE_ALL
:
2433 r
= INSTALLSTATE_LOCAL
;
2435 case INSTALLSTATE_ADVERTISED
:
2436 case INSTALLSTATE_ABSENT
:
2439 child
= (HTREEITEM
)SendMessageW( hwnd
, TVM_GETNEXTITEM
, (WPARAM
)TVGN_CHILD
, (LPARAM
)hItem
);
2441 msi_seltree_update_siblings_and_children_installstate( hwnd
, child
, package
, r
);
2444 case INSTALLSTATE_LOCAL
:
2445 msi_seltree_update_feature_installstate( hwnd
, hItem
, package
, feature
, r
);
2452 static LRESULT WINAPI
2453 MSISelectionTree_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
2455 struct msi_selection_tree_info
*info
;
2456 TVHITTESTINFO tvhti
;
2459 TRACE("%p %04x %08lx %08lx\n", hWnd
, msg
, wParam
, lParam
);
2461 info
= GetPropW(hWnd
, szButtonData
);
2465 case WM_LBUTTONDOWN
:
2466 tvhti
.pt
.x
= (short)LOWORD( lParam
);
2467 tvhti
.pt
.y
= (short)HIWORD( lParam
);
2470 CallWindowProcW(info
->oldproc
, hWnd
, TVM_HITTEST
, 0, (LPARAM
) &tvhti
);
2471 if (tvhti
.flags
& TVHT_ONITEMSTATEICON
)
2472 return msi_seltree_menu( hWnd
, tvhti
.hItem
);
2475 r
= CallWindowProcW(info
->oldproc
, hWnd
, msg
, wParam
, lParam
);
2481 RemovePropW( hWnd
, szButtonData
);
2488 msi_seltree_add_child_features( MSIPACKAGE
*package
, HWND hwnd
,
2489 LPCWSTR parent
, HTREEITEM hParent
)
2491 struct msi_selection_tree_info
*info
= GetPropW( hwnd
, szButtonData
);
2492 MSIFEATURE
*feature
;
2493 TVINSERTSTRUCTW tvis
;
2494 HTREEITEM hitem
, hfirst
= NULL
;
2496 LIST_FOR_EACH_ENTRY( feature
, &package
->features
, MSIFEATURE
, entry
)
2498 if ( parent
&& feature
->Feature_Parent
&& strcmpW( parent
, feature
->Feature_Parent
))
2500 else if ( parent
&& !feature
->Feature_Parent
)
2502 else if ( !parent
&& feature
->Feature_Parent
)
2505 if ( !feature
->Title
)
2508 if ( !feature
->Display
)
2511 memset( &tvis
, 0, sizeof tvis
);
2512 tvis
.hParent
= hParent
;
2513 tvis
.hInsertAfter
= TVI_LAST
;
2514 tvis
.u
.item
.mask
= TVIF_TEXT
| TVIF_PARAM
;
2515 tvis
.u
.item
.pszText
= feature
->Title
;
2516 tvis
.u
.item
.lParam
= (LPARAM
) feature
;
2518 hitem
= (HTREEITEM
) SendMessageW( hwnd
, TVM_INSERTITEMW
, 0, (LPARAM
) &tvis
);
2525 msi_seltree_sync_item_state( hwnd
, feature
, hitem
);
2526 msi_seltree_add_child_features( package
, hwnd
,
2527 feature
->Feature
, hitem
);
2529 /* the node is expanded if Display is odd */
2530 if ( feature
->Display
% 2 != 0 )
2531 SendMessageW( hwnd
, TVM_EXPAND
, TVE_EXPAND
, (LPARAM
) hitem
);
2534 /* select the first item */
2535 SendMessageW( hwnd
, TVM_SELECTITEM
, TVGN_CARET
| TVGN_DROPHILITE
, (LPARAM
) hfirst
);
2536 info
->selected
= hfirst
;
2539 static void msi_seltree_create_imagelist( HWND hwnd
)
2541 const int bm_width
= 32, bm_height
= 16, bm_count
= 3;
2542 const int bm_resource
= 0x1001;
2547 himl
= ImageList_Create( bm_width
, bm_height
, FALSE
, 4, 0 );
2550 ERR("failed to create image list\n");
2554 for (i
=0; i
<bm_count
; i
++)
2556 hbmp
= LoadBitmapW( msi_hInstance
, MAKEINTRESOURCEW(i
+bm_resource
) );
2559 ERR("failed to load bitmap %d\n", i
);
2564 * Add a dummy bitmap at offset zero because the treeview
2565 * can't use it as a state mask (zero means no user state).
2568 ImageList_Add( himl
, hbmp
, NULL
);
2570 ImageList_Add( himl
, hbmp
, NULL
);
2573 SendMessageW( hwnd
, TVM_SETIMAGELIST
, TVSIL_STATE
, (LPARAM
)himl
);
2576 static UINT
msi_dialog_seltree_handler( msi_dialog
*dialog
,
2577 msi_control
*control
, WPARAM param
)
2579 struct msi_selection_tree_info
*info
= GetPropW( control
->hwnd
, szButtonData
);
2580 LPNMTREEVIEWW tv
= (LPNMTREEVIEWW
)param
;
2581 MSIRECORD
*row
, *rec
;
2583 MSIFEATURE
*feature
;
2584 LPCWSTR dir
, title
= NULL
;
2585 UINT r
= ERROR_SUCCESS
;
2587 static const WCHAR select
[] = {
2588 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2589 '`','F','e','a','t','u','r','e','`',' ','W','H','E','R','E',' ',
2590 '`','T','i','t','l','e','`',' ','=',' ','\'','%','s','\'',0
2593 if (tv
->hdr
.code
!= TVN_SELCHANGINGW
)
2594 return ERROR_SUCCESS
;
2596 info
->selected
= tv
->itemNew
.hItem
;
2598 if (!(tv
->itemNew
.mask
& TVIF_TEXT
))
2600 feature
= msi_seltree_feature_from_item( control
->hwnd
, tv
->itemNew
.hItem
);
2602 title
= feature
->Title
;
2605 title
= tv
->itemNew
.pszText
;
2607 row
= MSI_QueryGetRecord( dialog
->package
->db
, select
, title
);
2609 return ERROR_FUNCTION_FAILED
;
2611 rec
= MSI_CreateRecord( 1 );
2613 MSI_RecordSetStringW( rec
, 1, MSI_RecordGetString( row
, 4 ) );
2614 ControlEvent_FireSubscribedEvent( dialog
->package
, szSelectionDescription
, rec
);
2616 dir
= MSI_RecordGetString( row
, 7 );
2619 folder
= msi_get_loaded_folder( dialog
->package
, dir
);
2622 r
= ERROR_FUNCTION_FAILED
;
2625 MSI_RecordSetStringW( rec
, 1, folder
->ResolvedTarget
);
2628 MSI_RecordSetStringW( rec
, 1, NULL
);
2630 ControlEvent_FireSubscribedEvent( dialog
->package
, szSelectionPath
, rec
);
2633 msiobj_release(&row
->hdr
);
2634 msiobj_release(&rec
->hdr
);
2639 static UINT
msi_dialog_selection_tree( msi_dialog
*dialog
, MSIRECORD
*rec
)
2641 msi_control
*control
;
2642 LPCWSTR prop
, control_name
;
2643 MSIPACKAGE
*package
= dialog
->package
;
2645 struct msi_selection_tree_info
*info
;
2647 info
= msi_alloc( sizeof *info
);
2649 return ERROR_FUNCTION_FAILED
;
2651 /* create the treeview control */
2652 style
= TVS_HASLINES
| TVS_HASBUTTONS
| TVS_LINESATROOT
;
2653 style
|= WS_GROUP
| WS_VSCROLL
;
2654 control
= msi_dialog_add_control( dialog
, rec
, WC_TREEVIEWW
, style
);
2658 return ERROR_FUNCTION_FAILED
;
2661 control
->handler
= msi_dialog_seltree_handler
;
2662 control_name
= MSI_RecordGetString( rec
, 2 );
2663 control
->attributes
= MSI_RecordGetInteger( rec
, 8 );
2664 prop
= MSI_RecordGetString( rec
, 9 );
2665 control
->property
= msi_dialog_dup_property( dialog
, prop
, FALSE
);
2668 info
->dialog
= dialog
;
2669 info
->hwnd
= control
->hwnd
;
2670 info
->oldproc
= (WNDPROC
) SetWindowLongPtrW( control
->hwnd
, GWLP_WNDPROC
,
2671 (LONG_PTR
)MSISelectionTree_WndProc
);
2672 SetPropW( control
->hwnd
, szButtonData
, info
);
2674 ControlEvent_SubscribeToEvent( dialog
->package
, dialog
,
2675 szSelectionPath
, control_name
, szProperty
);
2678 msi_seltree_create_imagelist( control
->hwnd
);
2679 msi_seltree_add_child_features( package
, control
->hwnd
, NULL
, NULL
);
2681 return ERROR_SUCCESS
;
2684 /******************** Group Box ***************************************/
2686 static UINT
msi_dialog_group_box( msi_dialog
*dialog
, MSIRECORD
*rec
)
2688 msi_control
*control
;
2691 style
= BS_GROUPBOX
| WS_CHILD
| WS_GROUP
;
2692 control
= msi_dialog_add_control( dialog
, rec
, WC_BUTTONW
, style
);
2694 return ERROR_FUNCTION_FAILED
;
2696 return ERROR_SUCCESS
;
2699 /******************** List Box ***************************************/
2701 struct msi_listbox_info
2711 static LRESULT WINAPI
MSIListBox_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
2713 struct msi_listbox_info
*info
;
2717 TRACE("%p %04x %08lx %08lx\n", hWnd
, msg
, wParam
, lParam
);
2719 info
= GetPropW( hWnd
, szButtonData
);
2723 r
= CallWindowProcW( info
->oldproc
, hWnd
, msg
, wParam
, lParam
);
2728 for (j
= 0; j
< info
->num_items
; j
++)
2729 msi_free( info
->items
[j
] );
2730 msi_free( info
->items
);
2732 RemovePropW( hWnd
, szButtonData
);
2739 static UINT
msi_listbox_add_item( MSIRECORD
*rec
, LPVOID param
)
2741 struct msi_listbox_info
*info
= param
;
2742 LPCWSTR value
, text
;
2745 value
= MSI_RecordGetString( rec
, 3 );
2746 text
= MSI_RecordGetString( rec
, 4 );
2748 info
->items
[info
->addpos_items
] = strdupW( value
);
2750 pos
= SendMessageW( info
->hwnd
, LB_ADDSTRING
, 0, (LPARAM
)text
);
2751 SendMessageW( info
->hwnd
, LB_SETITEMDATA
, pos
, (LPARAM
)info
->items
[info
->addpos_items
] );
2752 info
->addpos_items
++;
2753 return ERROR_SUCCESS
;
2756 static UINT
msi_listbox_add_items( struct msi_listbox_info
*info
, LPCWSTR property
)
2758 static const WCHAR query
[] = {
2759 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2760 '`','L','i','s','t','B','o','x','`',' ','W','H','E','R','E',' ',
2761 '`','P','r','o','p','e','r','t','y','`',' ','=',' ','\'','%','s','\'',' ',
2762 'O','R','D','E','R',' ','B','Y',' ','`','O','r','d','e','r','`',0};
2767 r
= MSI_OpenQuery( info
->dialog
->package
->db
, &view
, query
, property
);
2768 if ( r
!= ERROR_SUCCESS
)
2771 /* just get the number of records */
2773 r
= MSI_IterateRecords( view
, &count
, NULL
, NULL
);
2774 if (r
!= ERROR_SUCCESS
)
2776 msiobj_release( &view
->hdr
);
2779 info
->num_items
= count
;
2780 info
->items
= msi_alloc( sizeof(*info
->items
) * count
);
2782 r
= MSI_IterateRecords( view
, NULL
, msi_listbox_add_item
, info
);
2783 msiobj_release( &view
->hdr
);
2787 static UINT
msi_dialog_listbox_handler( msi_dialog
*dialog
,
2788 msi_control
*control
, WPARAM param
)
2790 struct msi_listbox_info
*info
;
2794 if( HIWORD(param
) != LBN_SELCHANGE
)
2795 return ERROR_SUCCESS
;
2797 info
= GetPropW( control
->hwnd
, szButtonData
);
2798 index
= SendMessageW( control
->hwnd
, LB_GETCURSEL
, 0, 0 );
2799 value
= (LPCWSTR
) SendMessageW( control
->hwnd
, LB_GETITEMDATA
, index
, 0 );
2801 msi_dialog_set_property( info
->dialog
->package
, control
->property
, value
);
2802 msi_dialog_evaluate_control_conditions( info
->dialog
);
2804 return ERROR_SUCCESS
;
2807 static UINT
msi_dialog_list_box( msi_dialog
*dialog
, MSIRECORD
*rec
)
2809 struct msi_listbox_info
*info
;
2810 msi_control
*control
;
2811 DWORD attributes
, style
;
2814 info
= msi_alloc( sizeof *info
);
2816 return ERROR_FUNCTION_FAILED
;
2818 style
= WS_TABSTOP
| WS_GROUP
| WS_CHILD
| LBS_NOTIFY
| WS_VSCROLL
| WS_BORDER
;
2819 attributes
= MSI_RecordGetInteger( rec
, 8 );
2820 if (~attributes
& msidbControlAttributesSorted
)
2823 control
= msi_dialog_add_control( dialog
, rec
, WC_LISTBOXW
, style
);
2827 return ERROR_FUNCTION_FAILED
;
2830 control
->handler
= msi_dialog_listbox_handler
;
2832 prop
= MSI_RecordGetString( rec
, 9 );
2833 control
->property
= msi_dialog_dup_property( dialog
, prop
, FALSE
);
2836 info
->dialog
= dialog
;
2837 info
->hwnd
= control
->hwnd
;
2839 info
->addpos_items
= 0;
2840 info
->oldproc
= (WNDPROC
)SetWindowLongPtrW( control
->hwnd
, GWLP_WNDPROC
,
2841 (LONG_PTR
)MSIListBox_WndProc
);
2842 SetPropW( control
->hwnd
, szButtonData
, info
);
2844 if ( control
->property
)
2845 msi_listbox_add_items( info
, control
->property
);
2847 return ERROR_SUCCESS
;
2850 /******************** Directory Combo ***************************************/
2852 static void msi_dialog_update_directory_combo( msi_dialog
*dialog
, msi_control
*control
)
2857 if (!control
&& !(control
= msi_dialog_find_control_by_type( dialog
, szDirectoryCombo
)))
2860 indirect
= control
->attributes
& msidbControlAttributesIndirect
;
2861 prop
= msi_dialog_dup_property( dialog
, control
->property
, indirect
);
2862 path
= msi_dialog_dup_property( dialog
, prop
, TRUE
);
2864 PathStripPathW( path
);
2865 PathRemoveBackslashW( path
);
2867 SendMessageW( control
->hwnd
, CB_INSERTSTRING
, 0, (LPARAM
)path
);
2868 SendMessageW( control
->hwnd
, CB_SETCURSEL
, 0, 0 );
2874 static UINT
msi_dialog_directory_combo( msi_dialog
*dialog
, MSIRECORD
*rec
)
2876 msi_control
*control
;
2880 /* FIXME: use CBS_OWNERDRAWFIXED and add owner draw code */
2881 style
= CBS_DROPDOWNLIST
| CBS_HASSTRINGS
| WS_CHILD
|
2882 WS_GROUP
| WS_TABSTOP
| WS_VSCROLL
;
2883 control
= msi_dialog_add_control( dialog
, rec
, WC_COMBOBOXW
, style
);
2885 return ERROR_FUNCTION_FAILED
;
2887 control
->attributes
= MSI_RecordGetInteger( rec
, 8 );
2888 prop
= MSI_RecordGetString( rec
, 9 );
2889 control
->property
= msi_dialog_dup_property( dialog
, prop
, FALSE
);
2891 msi_dialog_update_directory_combo( dialog
, control
);
2893 return ERROR_SUCCESS
;
2896 /******************** Directory List ***************************************/
2898 static void msi_dialog_update_directory_list( msi_dialog
*dialog
, msi_control
*control
)
2900 WCHAR dir_spec
[MAX_PATH
];
2901 WIN32_FIND_DATAW wfd
;
2907 static const WCHAR asterisk
[] = {'*',0};
2909 if (!control
&& !(control
= msi_dialog_find_control_by_type( dialog
, szDirectoryList
)))
2912 /* clear the list-view */
2913 SendMessageW( control
->hwnd
, LVM_DELETEALLITEMS
, 0, 0 );
2915 indirect
= control
->attributes
& msidbControlAttributesIndirect
;
2916 prop
= msi_dialog_dup_property( dialog
, control
->property
, indirect
);
2917 path
= msi_dialog_dup_property( dialog
, prop
, TRUE
);
2919 lstrcpyW( dir_spec
, path
);
2920 lstrcatW( dir_spec
, asterisk
);
2922 file
= FindFirstFileW( dir_spec
, &wfd
);
2923 if ( file
== INVALID_HANDLE_VALUE
)
2928 if ( wfd
.dwFileAttributes
!= FILE_ATTRIBUTE_DIRECTORY
)
2931 if ( !strcmpW( wfd
.cFileName
, szDot
) || !strcmpW( wfd
.cFileName
, szDotDot
) )
2934 item
.mask
= LVIF_TEXT
;
2935 item
.cchTextMax
= MAX_PATH
;
2938 item
.pszText
= wfd
.cFileName
;
2940 SendMessageW( control
->hwnd
, LVM_INSERTITEMW
, 0, (LPARAM
)&item
);
2941 } while ( FindNextFileW( file
, &wfd
) );
2948 UINT
msi_dialog_directorylist_up( msi_dialog
*dialog
)
2950 msi_control
*control
;
2951 LPWSTR prop
, path
, ptr
;
2954 control
= msi_dialog_find_control_by_type( dialog
, szDirectoryList
);
2955 indirect
= control
->attributes
& msidbControlAttributesIndirect
;
2956 prop
= msi_dialog_dup_property( dialog
, control
->property
, indirect
);
2957 path
= msi_dialog_dup_property( dialog
, prop
, TRUE
);
2959 /* strip off the last directory */
2960 ptr
= PathFindFileNameW( path
);
2961 if (ptr
!= path
) *(ptr
- 1) = '\0';
2962 PathAddBackslashW( path
);
2964 msi_dialog_set_property( dialog
->package
, prop
, path
);
2966 msi_dialog_update_directory_list( dialog
, NULL
);
2967 msi_dialog_update_directory_combo( dialog
, NULL
);
2968 msi_dialog_update_pathedit( dialog
, NULL
);
2973 return ERROR_SUCCESS
;
2976 static UINT
msi_dialog_dirlist_handler( msi_dialog
*dialog
,
2977 msi_control
*control
, WPARAM param
)
2979 LPNMHDR nmhdr
= (LPNMHDR
)param
;
2980 WCHAR new_path
[MAX_PATH
];
2981 WCHAR text
[MAX_PATH
];
2987 if (nmhdr
->code
!= LVN_ITEMACTIVATE
)
2988 return ERROR_SUCCESS
;
2990 index
= SendMessageW( control
->hwnd
, LVM_GETNEXTITEM
, -1, LVNI_SELECTED
);
2993 ERR("No list-view item selected!\n");
2994 return ERROR_FUNCTION_FAILED
;
2998 item
.pszText
= text
;
2999 item
.cchTextMax
= MAX_PATH
;
3000 SendMessageW( control
->hwnd
, LVM_GETITEMTEXTW
, index
, (LPARAM
)&item
);
3002 indirect
= control
->attributes
& msidbControlAttributesIndirect
;
3003 prop
= msi_dialog_dup_property( dialog
, control
->property
, indirect
);
3004 path
= msi_dialog_dup_property( dialog
, prop
, TRUE
);
3006 lstrcpyW( new_path
, path
);
3007 lstrcatW( new_path
, text
);
3008 lstrcatW( new_path
, szBackSlash
);
3010 msi_dialog_set_property( dialog
->package
, prop
, new_path
);
3012 msi_dialog_update_directory_list( dialog
, NULL
);
3013 msi_dialog_update_directory_combo( dialog
, NULL
);
3014 msi_dialog_update_pathedit( dialog
, NULL
);
3018 return ERROR_SUCCESS
;
3021 static UINT
msi_dialog_directory_list( msi_dialog
*dialog
, MSIRECORD
*rec
)
3023 msi_control
*control
;
3027 style
= LVS_LIST
| WS_VSCROLL
| LVS_SHAREIMAGELISTS
|
3028 LVS_AUTOARRANGE
| LVS_SINGLESEL
| WS_BORDER
|
3029 LVS_SORTASCENDING
| WS_CHILD
| WS_GROUP
| WS_TABSTOP
;
3030 control
= msi_dialog_add_control( dialog
, rec
, WC_LISTVIEWW
, style
);
3032 return ERROR_FUNCTION_FAILED
;
3034 control
->attributes
= MSI_RecordGetInteger( rec
, 8 );
3035 control
->handler
= msi_dialog_dirlist_handler
;
3036 prop
= MSI_RecordGetString( rec
, 9 );
3037 control
->property
= msi_dialog_dup_property( dialog
, prop
, FALSE
);
3039 /* double click to activate an item in the list */
3040 SendMessageW( control
->hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
,
3041 0, LVS_EX_TWOCLICKACTIVATE
);
3043 msi_dialog_update_directory_list( dialog
, control
);
3045 return ERROR_SUCCESS
;
3048 /******************** VolumeCost List ***************************************/
3050 static BOOL
str_is_number( LPCWSTR str
)
3054 for (i
= 0; i
< lstrlenW( str
); i
++)
3055 if (!isdigitW(str
[i
]))
3061 static const WCHAR column_keys
[][80] =
3063 {'V','o','l','u','m','e','C','o','s','t','V','o','l','u','m','e',0},
3064 {'V','o','l','u','m','e','C','o','s','t','S','i','z','e',0},
3065 {'V','o','l','u','m','e','C','o','s','t','A','v','a','i','l','a','b','l','e',0},
3066 {'V','o','l','u','m','e','C','o','s','t','R','e','q','u','i','r','e','d',0},
3067 {'V','o','l','u','m','e','C','o','s','t','D','i','f','f','e','r','e','n','c','e',0}
3070 static void msi_dialog_vcl_add_columns( msi_dialog
*dialog
, msi_control
*control
, MSIRECORD
*rec
)
3072 LPCWSTR text
= MSI_RecordGetString( rec
, 10 );
3073 LPCWSTR begin
= text
, end
;
3078 static const WCHAR negative
[] = {'-',0};
3082 while ((begin
= strchrW( begin
, '{' )) && count
< 5)
3084 if (!(end
= strchrW( begin
, '}' )))
3087 num
= msi_alloc( (end
-begin
+1)*sizeof(WCHAR
) );
3091 lstrcpynW( num
, begin
+ 1, end
- begin
);
3092 begin
+= end
- begin
+ 1;
3094 /* empty braces or '0' hides the column */
3095 if ( !num
[0] || !strcmpW( num
, szZero
) )
3102 /* the width must be a positive number
3103 * if a width is invalid, all remaining columns are hidden
3105 if ( !strncmpW( num
, negative
, 1 ) || !str_is_number( num
) ) {
3110 ZeroMemory( &lvc
, sizeof(lvc
) );
3111 lvc
.mask
= LVCF_TEXT
| LVCF_WIDTH
| LVCF_SUBITEM
;
3112 lvc
.cx
= atolW( num
);
3113 lvc
.pszText
= msi_dialog_get_uitext( dialog
, column_keys
[count
] );
3115 SendMessageW( control
->hwnd
, LVM_INSERTCOLUMNW
, count
++, (LPARAM
)&lvc
);
3116 msi_free( lvc
.pszText
);
3121 static LONGLONG
msi_vcl_get_cost( msi_dialog
*dialog
)
3123 MSIFEATURE
*feature
;
3125 LONGLONG total_cost
= 0;
3127 LIST_FOR_EACH_ENTRY( feature
, &dialog
->package
->features
, MSIFEATURE
, entry
)
3129 if (ERROR_SUCCESS
== (MSI_GetFeatureCost(dialog
->package
, feature
,
3130 MSICOSTTREE_SELFONLY
, INSTALLSTATE_LOCAL
, &each_cost
)))
3132 /* each_cost is in 512-byte units */
3133 total_cost
+= each_cost
* 512;
3135 if (ERROR_SUCCESS
== (MSI_GetFeatureCost(dialog
->package
, feature
,
3136 MSICOSTTREE_SELFONLY
, INSTALLSTATE_ABSENT
, &each_cost
)))
3138 /* each_cost is in 512-byte units */
3139 total_cost
-= each_cost
* 512;
3145 static void msi_dialog_vcl_add_drives( msi_dialog
*dialog
, msi_control
*control
)
3147 ULARGE_INTEGER total
, free
;
3148 LONGLONG difference
, cost
;
3149 WCHAR size_text
[MAX_PATH
];
3150 WCHAR cost_text
[MAX_PATH
];
3156 cost
= msi_vcl_get_cost(dialog
);
3157 StrFormatByteSizeW(cost
, cost_text
, MAX_PATH
);
3159 size
= GetLogicalDriveStringsW( 0, NULL
);
3160 if ( !size
) return;
3162 drives
= msi_alloc( (size
+ 1) * sizeof(WCHAR
) );
3163 if ( !drives
) return;
3165 GetLogicalDriveStringsW( size
, drives
);
3170 lvitem
.mask
= LVIF_TEXT
;
3172 lvitem
.iSubItem
= 0;
3173 lvitem
.pszText
= ptr
;
3174 lvitem
.cchTextMax
= lstrlenW(ptr
) + 1;
3175 SendMessageW( control
->hwnd
, LVM_INSERTITEMW
, 0, (LPARAM
)&lvitem
);
3177 GetDiskFreeSpaceExW(ptr
, &free
, &total
, NULL
);
3178 difference
= free
.QuadPart
- cost
;
3180 StrFormatByteSizeW(total
.QuadPart
, size_text
, MAX_PATH
);
3181 lvitem
.iSubItem
= 1;
3182 lvitem
.pszText
= size_text
;
3183 lvitem
.cchTextMax
= lstrlenW(size_text
) + 1;
3184 SendMessageW( control
->hwnd
, LVM_SETITEMW
, 0, (LPARAM
)&lvitem
);
3186 StrFormatByteSizeW(free
.QuadPart
, size_text
, MAX_PATH
);
3187 lvitem
.iSubItem
= 2;
3188 lvitem
.pszText
= size_text
;
3189 lvitem
.cchTextMax
= lstrlenW(size_text
) + 1;
3190 SendMessageW( control
->hwnd
, LVM_SETITEMW
, 0, (LPARAM
)&lvitem
);
3192 lvitem
.iSubItem
= 3;
3193 lvitem
.pszText
= cost_text
;
3194 lvitem
.cchTextMax
= lstrlenW(cost_text
) + 1;
3195 SendMessageW( control
->hwnd
, LVM_SETITEMW
, 0, (LPARAM
)&lvitem
);
3197 StrFormatByteSizeW(difference
, size_text
, MAX_PATH
);
3198 lvitem
.iSubItem
= 4;
3199 lvitem
.pszText
= size_text
;
3200 lvitem
.cchTextMax
= lstrlenW(size_text
) + 1;
3201 SendMessageW( control
->hwnd
, LVM_SETITEMW
, 0, (LPARAM
)&lvitem
);
3203 ptr
+= lstrlenW(ptr
) + 1;
3210 static UINT
msi_dialog_volumecost_list( msi_dialog
*dialog
, MSIRECORD
*rec
)
3212 msi_control
*control
;
3215 style
= LVS_REPORT
| WS_VSCROLL
| WS_HSCROLL
| LVS_SHAREIMAGELISTS
|
3216 LVS_AUTOARRANGE
| LVS_SINGLESEL
| WS_BORDER
|
3217 WS_CHILD
| WS_TABSTOP
| WS_GROUP
;
3218 control
= msi_dialog_add_control( dialog
, rec
, WC_LISTVIEWW
, style
);
3220 return ERROR_FUNCTION_FAILED
;
3222 msi_dialog_vcl_add_columns( dialog
, control
, rec
);
3223 msi_dialog_vcl_add_drives( dialog
, control
);
3225 return ERROR_SUCCESS
;
3228 /******************** VolumeSelect Combo ***************************************/
3230 static UINT
msi_dialog_volsel_handler( msi_dialog
*dialog
,
3231 msi_control
*control
, WPARAM param
)
3233 WCHAR text
[MAX_PATH
];
3238 if (HIWORD(param
) != CBN_SELCHANGE
)
3239 return ERROR_SUCCESS
;
3241 index
= SendMessageW( control
->hwnd
, CB_GETCURSEL
, 0, 0 );
3242 if ( index
== CB_ERR
)
3244 ERR("No ComboBox item selected!\n");
3245 return ERROR_FUNCTION_FAILED
;
3248 SendMessageW( control
->hwnd
, CB_GETLBTEXT
, index
, (LPARAM
)text
);
3250 indirect
= control
->attributes
& msidbControlAttributesIndirect
;
3251 prop
= msi_dialog_dup_property( dialog
, control
->property
, indirect
);
3253 msi_dialog_set_property( dialog
->package
, prop
, text
);
3256 return ERROR_SUCCESS
;
3259 static void msi_dialog_vsc_add_drives( msi_dialog
*dialog
, msi_control
*control
)
3264 size
= GetLogicalDriveStringsW( 0, NULL
);
3265 if ( !size
) return;
3267 drives
= msi_alloc( (size
+ 1) * sizeof(WCHAR
) );
3268 if ( !drives
) return;
3270 GetLogicalDriveStringsW( size
, drives
);
3275 SendMessageW( control
->hwnd
, CB_ADDSTRING
, 0, (LPARAM
)ptr
);
3276 ptr
+= lstrlenW(ptr
) + 1;
3282 static UINT
msi_dialog_volumeselect_combo( msi_dialog
*dialog
, MSIRECORD
*rec
)
3284 msi_control
*control
;
3288 /* FIXME: CBS_OWNERDRAWFIXED */
3289 style
= WS_CHILD
| WS_VISIBLE
| WS_GROUP
| WS_TABSTOP
|
3290 CBS_DROPDOWNLIST
| CBS_SORT
| CBS_HASSTRINGS
|
3291 WS_EX_LEFT
| WS_EX_LTRREADING
| WS_EX_RIGHTSCROLLBAR
;
3292 control
= msi_dialog_add_control( dialog
, rec
, WC_COMBOBOXW
, style
);
3294 return ERROR_FUNCTION_FAILED
;
3296 control
->attributes
= MSI_RecordGetInteger( rec
, 8 );
3297 control
->handler
= msi_dialog_volsel_handler
;
3298 prop
= MSI_RecordGetString( rec
, 9 );
3299 control
->property
= msi_dialog_dup_property( dialog
, prop
, FALSE
);
3301 msi_dialog_vsc_add_drives( dialog
, control
);
3303 return ERROR_SUCCESS
;
3306 static const struct control_handler msi_dialog_handler
[] =
3308 { szText
, msi_dialog_text_control
},
3309 { szPushButton
, msi_dialog_button_control
},
3310 { szLine
, msi_dialog_line_control
},
3311 { szBitmap
, msi_dialog_bitmap_control
},
3312 { szCheckBox
, msi_dialog_checkbox_control
},
3313 { szScrollableText
, msi_dialog_scrolltext_control
},
3314 { szComboBox
, msi_dialog_combo_control
},
3315 { szEdit
, msi_dialog_edit_control
},
3316 { szMaskedEdit
, msi_dialog_maskedit_control
},
3317 { szPathEdit
, msi_dialog_pathedit_control
},
3318 { szProgressBar
, msi_dialog_progress_bar
},
3319 { szRadioButtonGroup
, msi_dialog_radiogroup_control
},
3320 { szIcon
, msi_dialog_icon_control
},
3321 { szSelectionTree
, msi_dialog_selection_tree
},
3322 { szGroupBox
, msi_dialog_group_box
},
3323 { szListBox
, msi_dialog_list_box
},
3324 { szDirectoryCombo
, msi_dialog_directory_combo
},
3325 { szDirectoryList
, msi_dialog_directory_list
},
3326 { szVolumeCostList
, msi_dialog_volumecost_list
},
3327 { szVolumeSelectCombo
, msi_dialog_volumeselect_combo
},
3330 #define NUM_CONTROL_TYPES (sizeof msi_dialog_handler/sizeof msi_dialog_handler[0])
3332 static UINT
msi_dialog_create_controls( MSIRECORD
*rec
, LPVOID param
)
3334 msi_dialog
*dialog
= param
;
3335 LPCWSTR control_type
;
3338 /* find and call the function that can create this type of control */
3339 control_type
= MSI_RecordGetString( rec
, 3 );
3340 for( i
=0; i
<NUM_CONTROL_TYPES
; i
++ )
3341 if (!strcmpiW( msi_dialog_handler
[i
].control_type
, control_type
))
3343 if( i
!= NUM_CONTROL_TYPES
)
3344 msi_dialog_handler
[i
].func( dialog
, rec
);
3346 ERR("no handler for element type %s\n", debugstr_w(control_type
));
3348 return ERROR_SUCCESS
;
3351 static UINT
msi_dialog_fill_controls( msi_dialog
*dialog
)
3353 static const WCHAR query
[] = {
3354 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
3355 'C','o','n','t','r','o','l',' ','W','H','E','R','E',' ',
3356 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',0};
3359 MSIPACKAGE
*package
= dialog
->package
;
3361 TRACE("%p %s\n", dialog
, debugstr_w(dialog
->name
) );
3363 /* query the Control table for all the elements of the control */
3364 r
= MSI_OpenQuery( package
->db
, &view
, query
, dialog
->name
);
3365 if( r
!= ERROR_SUCCESS
)
3367 ERR("query failed for dialog %s\n", debugstr_w(dialog
->name
));
3368 return ERROR_INVALID_PARAMETER
;
3371 r
= MSI_IterateRecords( view
, 0, msi_dialog_create_controls
, dialog
);
3372 msiobj_release( &view
->hdr
);
3376 UINT
msi_dialog_reset( msi_dialog
*dialog
)
3378 /* FIXME: should restore the original values of any properties we changed */
3379 return msi_dialog_evaluate_control_conditions( dialog
);
3382 /* figure out the height of 10 point MS Sans Serif */
3383 static INT
msi_dialog_get_sans_serif_height( HWND hwnd
)
3385 static const WCHAR szSansSerif
[] = {
3386 'M','S',' ','S','a','n','s',' ','S','e','r','i','f',0 };
3391 HFONT hFont
, hOldFont
;
3394 hdc
= GetDC( hwnd
);
3397 memset( &lf
, 0, sizeof lf
);
3398 lf
.lfHeight
= MulDiv(12, GetDeviceCaps(hdc
, LOGPIXELSY
), 72);
3399 strcpyW( lf
.lfFaceName
, szSansSerif
);
3400 hFont
= CreateFontIndirectW(&lf
);
3403 hOldFont
= SelectObject( hdc
, hFont
);
3404 r
= GetTextMetricsW( hdc
, &tm
);
3406 height
= tm
.tmHeight
;
3407 SelectObject( hdc
, hOldFont
);
3408 DeleteObject( hFont
);
3410 ReleaseDC( hwnd
, hdc
);
3415 /* fetch the associated record from the Dialog table */
3416 static MSIRECORD
*msi_get_dialog_record( msi_dialog
*dialog
)
3418 static const WCHAR query
[] = {
3419 'S','E','L','E','C','T',' ','*',' ',
3420 'F','R','O','M',' ','D','i','a','l','o','g',' ',
3421 'W','H','E','R','E',' ',
3422 '`','D','i','a','l','o','g','`',' ','=',' ','\'','%','s','\'',0};
3423 MSIPACKAGE
*package
= dialog
->package
;
3424 MSIRECORD
*rec
= NULL
;
3426 TRACE("%p %s\n", dialog
, debugstr_w(dialog
->name
) );
3428 rec
= MSI_QueryGetRecord( package
->db
, query
, dialog
->name
);
3430 WARN("query failed for dialog %s\n", debugstr_w(dialog
->name
));
3435 static void msi_dialog_adjust_dialog_pos( msi_dialog
*dialog
, MSIRECORD
*rec
, LPRECT pos
)
3437 static const WCHAR szScreenX
[] = {'S','c','r','e','e','n','X',0};
3438 static const WCHAR szScreenY
[] = {'S','c','r','e','e','n','Y',0};
3445 center
.x
= MSI_RecordGetInteger( rec
, 2 );
3446 center
.y
= MSI_RecordGetInteger( rec
, 3 );
3448 sz
.cx
= MSI_RecordGetInteger( rec
, 4 );
3449 sz
.cy
= MSI_RecordGetInteger( rec
, 5 );
3451 sz
.cx
= msi_dialog_scale_unit( dialog
, sz
.cx
);
3452 sz
.cy
= msi_dialog_scale_unit( dialog
, sz
.cy
);
3454 xres
= msi_get_property_int( dialog
->package
->db
, szScreenX
, 0 );
3455 yres
= msi_get_property_int( dialog
->package
->db
, szScreenY
, 0 );
3457 center
.x
= MulDiv( center
.x
, xres
, 100 );
3458 center
.y
= MulDiv( center
.y
, yres
, 100 );
3460 /* turn the client pos into the window rectangle */
3461 if (dialog
->package
->center_x
&& dialog
->package
->center_y
)
3463 pos
->left
= dialog
->package
->center_x
- sz
.cx
/ 2.0;
3464 pos
->right
= pos
->left
+ sz
.cx
;
3465 pos
->top
= dialog
->package
->center_y
- sz
.cy
/ 2.0;
3466 pos
->bottom
= pos
->top
+ sz
.cy
;
3470 pos
->left
= center
.x
- sz
.cx
/2;
3471 pos
->right
= pos
->left
+ sz
.cx
;
3472 pos
->top
= center
.y
- sz
.cy
/2;
3473 pos
->bottom
= pos
->top
+ sz
.cy
;
3475 /* save the center */
3476 dialog
->package
->center_x
= center
.x
;
3477 dialog
->package
->center_y
= center
.y
;
3480 dialog
->size
.cx
= sz
.cx
;
3481 dialog
->size
.cy
= sz
.cy
;
3483 TRACE("%u %u %u %u\n", pos
->left
, pos
->top
, pos
->right
, pos
->bottom
);
3485 style
= GetWindowLongPtrW( dialog
->hwnd
, GWL_STYLE
);
3486 AdjustWindowRect( pos
, style
, FALSE
);
3489 static void msi_dialog_set_tab_order( msi_dialog
*dialog
, LPCWSTR first
)
3491 struct list tab_chain
;
3492 msi_control
*control
;
3493 HWND prev
= HWND_TOP
;
3495 list_init( &tab_chain
);
3496 if (!(control
= msi_dialog_find_control( dialog
, first
))) return;
3498 dialog
->hWndFocus
= control
->hwnd
;
3501 list_remove( &control
->entry
);
3502 list_add_tail( &tab_chain
, &control
->entry
);
3503 if (!control
->tabnext
) break;
3504 control
= msi_dialog_find_control( dialog
, control
->tabnext
);
3507 LIST_FOR_EACH_ENTRY( control
, &tab_chain
, msi_control
, entry
)
3509 SetWindowPos( control
->hwnd
, prev
, 0, 0, 0, 0,
3510 SWP_NOMOVE
| SWP_NOOWNERZORDER
| SWP_NOREDRAW
|
3511 SWP_NOREPOSITION
| SWP_NOSENDCHANGING
| SWP_NOSIZE
);
3512 prev
= control
->hwnd
;
3515 /* put them back on the main list */
3516 list_move_head( &dialog
->controls
, &tab_chain
);
3519 static LRESULT
msi_dialog_oncreate( HWND hwnd
, LPCREATESTRUCTW cs
)
3521 static const WCHAR df
[] = {
3522 'D','e','f','a','u','l','t','U','I','F','o','n','t',0 };
3523 static const WCHAR dfv
[] = {
3524 'M','S',' ','S','h','e','l','l',' ','D','l','g',0 };
3525 msi_dialog
*dialog
= cs
->lpCreateParams
;
3526 MSIRECORD
*rec
= NULL
;
3527 LPWSTR title
= NULL
;
3530 TRACE("%p %p\n", dialog
, dialog
->package
);
3532 dialog
->hwnd
= hwnd
;
3533 SetWindowLongPtrW( hwnd
, GWLP_USERDATA
, (LONG_PTR
) dialog
);
3535 rec
= msi_get_dialog_record( dialog
);
3538 TRACE("No record found for dialog %s\n", debugstr_w(dialog
->name
));
3542 dialog
->scale
= msi_dialog_get_sans_serif_height(dialog
->hwnd
);
3544 msi_dialog_adjust_dialog_pos( dialog
, rec
, &pos
);
3546 dialog
->attributes
= MSI_RecordGetInteger( rec
, 6 );
3548 dialog
->default_font
= msi_dup_property( dialog
->package
->db
, df
);
3549 if (!dialog
->default_font
)
3551 dialog
->default_font
= strdupW(dfv
);
3552 if (!dialog
->default_font
) return -1;
3555 title
= msi_get_deformatted_field( dialog
->package
, rec
, 7 );
3556 SetWindowTextW( hwnd
, title
);
3559 SetWindowPos( hwnd
, 0, pos
.left
, pos
.top
,
3560 pos
.right
- pos
.left
, pos
.bottom
- pos
.top
,
3561 SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_NOREDRAW
);
3563 msi_dialog_build_font_list( dialog
);
3564 msi_dialog_fill_controls( dialog
);
3565 msi_dialog_evaluate_control_conditions( dialog
);
3566 msi_dialog_set_tab_order( dialog
, MSI_RecordGetString( rec
, 8 ) );
3567 msiobj_release( &rec
->hdr
);
3572 static LRESULT
msi_dialog_oncommand( msi_dialog
*dialog
, WPARAM param
, HWND hwnd
)
3574 msi_control
*control
= NULL
;
3576 TRACE("%p %p %08lx\n", dialog
, hwnd
, param
);
3581 control
= msi_dialog_find_control( dialog
, dialog
->control_default
);
3583 case 2: /* escape */
3584 control
= msi_dialog_find_control( dialog
, dialog
->control_cancel
);
3587 control
= msi_dialog_find_control_by_hwnd( dialog
, hwnd
);
3592 if( control
->handler
)
3594 control
->handler( dialog
, control
, param
);
3595 msi_dialog_evaluate_control_conditions( dialog
);
3602 static LRESULT
msi_dialog_onnotify( msi_dialog
*dialog
, LPARAM param
)
3604 LPNMHDR nmhdr
= (LPNMHDR
) param
;
3605 msi_control
*control
= msi_dialog_find_control_by_hwnd( dialog
, nmhdr
->hwndFrom
);
3607 TRACE("%p %p\n", dialog
, nmhdr
->hwndFrom
);
3609 if ( control
&& control
->handler
)
3610 control
->handler( dialog
, control
, param
);
3615 static void msi_dialog_setfocus( msi_dialog
*dialog
)
3617 HWND hwnd
= dialog
->hWndFocus
;
3619 hwnd
= GetNextDlgTabItem( dialog
->hwnd
, hwnd
, TRUE
);
3620 hwnd
= GetNextDlgTabItem( dialog
->hwnd
, hwnd
, FALSE
);
3622 dialog
->hWndFocus
= hwnd
;
3625 static LRESULT WINAPI
MSIDialog_WndProc( HWND hwnd
, UINT msg
,
3626 WPARAM wParam
, LPARAM lParam
)
3628 msi_dialog
*dialog
= (LPVOID
) GetWindowLongPtrW( hwnd
, GWLP_USERDATA
);
3630 TRACE("0x%04x\n", msg
);
3635 dialog
->package
->center_x
= LOWORD(lParam
) + dialog
->size
.cx
/ 2.0;
3636 dialog
->package
->center_y
= HIWORD(lParam
) + dialog
->size
.cy
/ 2.0;
3640 return msi_dialog_oncreate( hwnd
, (LPCREATESTRUCTW
)lParam
);
3643 return msi_dialog_oncommand( dialog
, wParam
, (HWND
)lParam
);
3646 if( LOWORD(wParam
) == WA_INACTIVE
)
3647 dialog
->hWndFocus
= GetFocus();
3649 msi_dialog_setfocus( dialog
);
3653 msi_dialog_setfocus( dialog
);
3656 /* bounce back to our subclassed static control */
3657 case WM_CTLCOLORSTATIC
:
3658 return SendMessageW( (HWND
) lParam
, WM_CTLCOLORSTATIC
, wParam
, lParam
);
3661 dialog
->hwnd
= NULL
;
3664 return msi_dialog_onnotify( dialog
, lParam
);
3666 return DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
3669 static LRESULT WINAPI
MSIHiddenWindowProc( HWND hwnd
, UINT msg
,
3670 WPARAM wParam
, LPARAM lParam
)
3672 msi_dialog
*dialog
= (msi_dialog
*) lParam
;
3674 TRACE("%d %p\n", msg
, dialog
);
3678 case WM_MSI_DIALOG_CREATE
:
3679 return msi_dialog_run_message_loop( dialog
);
3680 case WM_MSI_DIALOG_DESTROY
:
3681 msi_dialog_destroy( dialog
);
3684 return DefWindowProcW( hwnd
, msg
, wParam
, lParam
);
3687 static BOOL
msi_dialog_register_class( void )
3691 ZeroMemory( &cls
, sizeof cls
);
3692 cls
.lpfnWndProc
= MSIDialog_WndProc
;
3693 cls
.hInstance
= NULL
;
3694 cls
.hIcon
= LoadIconW(0, (LPWSTR
)IDI_APPLICATION
);
3695 cls
.hCursor
= LoadCursorW(0, (LPWSTR
)IDC_ARROW
);
3696 cls
.hbrBackground
= (HBRUSH
)(COLOR_3DFACE
+ 1);
3697 cls
.lpszMenuName
= NULL
;
3698 cls
.lpszClassName
= szMsiDialogClass
;
3700 if( !RegisterClassW( &cls
) )
3703 cls
.lpfnWndProc
= MSIHiddenWindowProc
;
3704 cls
.lpszClassName
= szMsiHiddenWindow
;
3706 if( !RegisterClassW( &cls
) )
3709 uiThreadId
= GetCurrentThreadId();
3711 hMsiHiddenWindow
= CreateWindowW( szMsiHiddenWindow
, NULL
, WS_OVERLAPPED
,
3712 0, 0, 100, 100, NULL
, NULL
, NULL
, NULL
);
3713 if( !hMsiHiddenWindow
)
3719 /* functions that interface to other modules within MSI */
3721 msi_dialog
*msi_dialog_create( MSIPACKAGE
* package
,
3722 LPCWSTR szDialogName
, msi_dialog
*parent
,
3723 msi_dialog_event_handler event_handler
)
3725 MSIRECORD
*rec
= NULL
;
3728 TRACE("%p %s\n", package
, debugstr_w(szDialogName
));
3730 if (!hMsiHiddenWindow
)
3731 msi_dialog_register_class();
3733 /* allocate the structure for the dialog to use */
3734 dialog
= msi_alloc_zero( sizeof *dialog
+ sizeof(WCHAR
)*strlenW(szDialogName
) );
3737 strcpyW( dialog
->name
, szDialogName
);
3738 dialog
->parent
= parent
;
3739 msiobj_addref( &package
->hdr
);
3740 dialog
->package
= package
;
3741 dialog
->event_handler
= event_handler
;
3742 dialog
->finished
= 0;
3743 list_init( &dialog
->controls
);
3744 list_init( &dialog
->fonts
);
3746 /* verify that the dialog exists */
3747 rec
= msi_get_dialog_record( dialog
);
3750 msiobj_release( &package
->hdr
);
3754 dialog
->attributes
= MSI_RecordGetInteger( rec
, 6 );
3755 dialog
->control_default
= strdupW( MSI_RecordGetString( rec
, 9 ) );
3756 dialog
->control_cancel
= strdupW( MSI_RecordGetString( rec
, 10 ) );
3757 msiobj_release( &rec
->hdr
);
3762 static void msi_process_pending_messages( HWND hdlg
)
3766 while( PeekMessageW( &msg
, 0, 0, 0, PM_REMOVE
) )
3768 if( hdlg
&& IsDialogMessageW( hdlg
, &msg
))
3770 TranslateMessage( &msg
);
3771 DispatchMessageW( &msg
);
3775 void msi_dialog_end_dialog( msi_dialog
*dialog
)
3777 TRACE("%p\n", dialog
);
3778 dialog
->finished
= 1;
3779 PostMessageW(dialog
->hwnd
, WM_NULL
, 0, 0);
3782 void msi_dialog_check_messages( HANDLE handle
)
3786 /* in threads other than the UI thread, block */
3787 if( uiThreadId
!= GetCurrentThreadId() )
3790 WaitForSingleObject( handle
, INFINITE
);
3794 /* there's two choices for the UI thread */
3797 msi_process_pending_messages( NULL
);
3803 * block here until somebody creates a new dialog or
3804 * the handle we're waiting on becomes ready
3806 r
= MsgWaitForMultipleObjects( 1, &handle
, 0, INFINITE
, QS_ALLINPUT
);
3807 if( r
== WAIT_OBJECT_0
)
3812 UINT
msi_dialog_run_message_loop( msi_dialog
*dialog
)
3817 if( uiThreadId
!= GetCurrentThreadId() )
3818 return SendMessageW( hMsiHiddenWindow
, WM_MSI_DIALOG_CREATE
, 0, (LPARAM
) dialog
);
3820 /* create the dialog window, don't show it yet */
3821 style
= WS_OVERLAPPED
;
3822 if( dialog
->attributes
& msidbDialogAttributesVisible
)
3823 style
|= WS_VISIBLE
;
3825 hwnd
= CreateWindowW( szMsiDialogClass
, dialog
->name
, style
,
3826 CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
,
3827 NULL
, NULL
, NULL
, dialog
);
3830 ERR("Failed to create dialog %s\n", debugstr_w( dialog
->name
));
3831 return ERROR_FUNCTION_FAILED
;
3834 ShowWindow( hwnd
, SW_SHOW
);
3835 /* UpdateWindow( hwnd ); - and causes the transparent static controls not to paint */
3837 if( dialog
->attributes
& msidbDialogAttributesModal
)
3839 while( !dialog
->finished
)
3841 MsgWaitForMultipleObjects( 0, NULL
, 0, INFINITE
, QS_ALLINPUT
);
3842 msi_process_pending_messages( dialog
->hwnd
);
3846 return ERROR_IO_PENDING
;
3848 return ERROR_SUCCESS
;
3851 static void msi_dialog_do_preview( msi_dialog
*dialog
)
3854 dialog
->attributes
|= msidbDialogAttributesVisible
;
3855 dialog
->attributes
&= ~msidbDialogAttributesModal
;
3856 msi_dialog_run_message_loop( dialog
);
3859 void msi_dialog_destroy( msi_dialog
*dialog
)
3861 msi_font
*font
, *next
;
3863 if( uiThreadId
!= GetCurrentThreadId() )
3865 SendMessageW( hMsiHiddenWindow
, WM_MSI_DIALOG_DESTROY
, 0, (LPARAM
) dialog
);
3870 ShowWindow( dialog
->hwnd
, SW_HIDE
);
3873 DestroyWindow( dialog
->hwnd
);
3875 /* unsubscribe events */
3876 ControlEvent_CleanupDialogSubscriptions(dialog
->package
, dialog
->name
);
3878 /* destroy the list of controls */
3879 while( !list_empty( &dialog
->controls
) )
3883 t
= LIST_ENTRY( list_head( &dialog
->controls
),
3884 msi_control
, entry
);
3885 msi_destroy_control( t
);
3888 /* destroy the list of fonts */
3889 LIST_FOR_EACH_ENTRY_SAFE( font
, next
, &dialog
->fonts
, msi_font
, entry
)
3891 list_remove( &font
->entry
);
3892 DeleteObject( font
->hfont
);
3895 msi_free( dialog
->default_font
);
3897 msi_free( dialog
->control_default
);
3898 msi_free( dialog
->control_cancel
);
3899 msiobj_release( &dialog
->package
->hdr
);
3900 dialog
->package
= NULL
;
3904 void msi_dialog_unregister_class( void )
3906 DestroyWindow( hMsiHiddenWindow
);
3907 hMsiHiddenWindow
= NULL
;
3908 UnregisterClassW( szMsiDialogClass
, NULL
);
3909 UnregisterClassW( szMsiHiddenWindow
, NULL
);
3913 static UINT
error_dialog_handler(MSIPACKAGE
*package
, LPCWSTR event
,
3914 LPCWSTR argument
, msi_dialog
* dialog
)
3916 static const WCHAR end_dialog
[] = {'E','n','d','D','i','a','l','o','g',0};
3917 static const WCHAR error_abort
[] = {'E','r','r','o','r','A','b','o','r','t',0};
3918 static const WCHAR error_cancel
[] = {'E','r','r','o','r','C','a','n','c','e','l',0};
3919 static const WCHAR error_no
[] = {'E','r','r','o','r','N','o',0};
3920 static const WCHAR result_prop
[] = {
3921 'M','S','I','E','r','r','o','r','D','i','a','l','o','g','R','e','s','u','l','t',0
3924 if ( strcmpW( event
, end_dialog
) )
3925 return ERROR_SUCCESS
;
3927 if ( !strcmpW( argument
, error_abort
) || !strcmpW( argument
, error_cancel
) ||
3928 !strcmpW( argument
, error_no
) )
3930 msi_set_property( package
->db
, result_prop
, error_abort
);
3933 ControlEvent_CleanupSubscriptions(package
);
3934 msi_dialog_end_dialog( dialog
);
3936 return ERROR_SUCCESS
;
3939 static UINT
msi_error_dialog_set_error( MSIPACKAGE
*package
, LPWSTR error_dialog
, LPWSTR error
)
3943 static const WCHAR update
[] =
3944 {'U','P','D','A','T','E',' ','`','C','o','n','t','r','o','l','`',' ',
3945 'S','E','T',' ','`','T','e','x','t','`',' ','=',' ','\'','%','s','\'',' ',
3946 'W','H','E','R','E', ' ','`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',' ',
3947 'A','N','D',' ','`','C','o','n','t','r','o','l','`',' ','=',' ',
3948 '\'','E','r','r','o','r','T','e','x','t','\'',0};
3950 row
= MSI_QueryGetRecord( package
->db
, update
, error
, error_dialog
);
3952 return ERROR_FUNCTION_FAILED
;
3954 msiobj_release(&row
->hdr
);
3955 return ERROR_SUCCESS
;
3958 UINT
msi_spawn_error_dialog( MSIPACKAGE
*package
, LPWSTR error_dialog
, LPWSTR error
)
3961 WCHAR result
[MAX_PATH
];
3962 UINT r
= ERROR_SUCCESS
;
3963 DWORD size
= MAX_PATH
;
3966 static const WCHAR pn_prop
[] = {'P','r','o','d','u','c','t','N','a','m','e',0};
3967 static const WCHAR title_fmt
[] = {'%','s',' ','W','a','r','n','i','n','g',0};
3968 static const WCHAR error_abort
[] = {'E','r','r','o','r','A','b','o','r','t',0};
3969 static const WCHAR result_prop
[] = {
3970 'M','S','I','E','r','r','o','r','D','i','a','l','o','g','R','e','s','u','l','t',0
3973 if ( (msi_get_property_int( package
->db
, szUILevel
, 0 ) & INSTALLUILEVEL_MASK
) == INSTALLUILEVEL_NONE
)
3974 return ERROR_SUCCESS
;
3976 if ( !error_dialog
)
3978 LPWSTR product_name
= msi_dup_property( package
->db
, pn_prop
);
3979 WCHAR title
[MAX_PATH
];
3981 sprintfW( title
, title_fmt
, product_name
);
3982 res
= MessageBoxW( NULL
, error
, title
, MB_OKCANCEL
| MB_ICONWARNING
);
3984 msi_free( product_name
);
3987 return ERROR_SUCCESS
;
3989 return ERROR_FUNCTION_FAILED
;
3992 r
= msi_error_dialog_set_error( package
, error_dialog
, error
);
3993 if ( r
!= ERROR_SUCCESS
)
3996 dialog
= msi_dialog_create( package
, error_dialog
, package
->dialog
,
3997 error_dialog_handler
);
3999 return ERROR_FUNCTION_FAILED
;
4001 dialog
->finished
= FALSE
;
4002 r
= msi_dialog_run_message_loop( dialog
);
4003 if ( r
!= ERROR_SUCCESS
)
4006 r
= msi_get_property( package
->db
, result_prop
, result
, &size
);
4007 if ( r
!= ERROR_SUCCESS
)
4010 if ( !strcmpW( result
, error_abort
) )
4011 r
= ERROR_FUNCTION_FAILED
;
4014 msi_dialog_destroy( dialog
);
4019 static void MSI_ClosePreview( MSIOBJECTHDR
*arg
)
4021 MSIPREVIEW
*preview
= (MSIPREVIEW
*)arg
;
4022 msiobj_release( &preview
->package
->hdr
);
4025 static MSIPREVIEW
*MSI_EnableUIPreview( MSIDATABASE
*db
)
4027 MSIPREVIEW
*preview
= NULL
;
4028 MSIPACKAGE
*package
;
4030 package
= MSI_CreatePackage( db
, NULL
);
4033 preview
= alloc_msiobject( MSIHANDLETYPE_PREVIEW
, sizeof(MSIPREVIEW
), MSI_ClosePreview
);
4036 preview
->package
= package
;
4037 msiobj_addref( &package
->hdr
);
4039 msiobj_release( &package
->hdr
);
4044 UINT WINAPI
MsiEnableUIPreview( MSIHANDLE hdb
, MSIHANDLE
*phPreview
)
4047 MSIPREVIEW
*preview
;
4048 UINT r
= ERROR_FUNCTION_FAILED
;
4050 TRACE("%d %p\n", hdb
, phPreview
);
4052 db
= msihandle2msiinfo( hdb
, MSIHANDLETYPE_DATABASE
);
4055 IWineMsiRemoteDatabase
*remote_database
;
4057 remote_database
= (IWineMsiRemoteDatabase
*)msi_get_remote( hdb
);
4058 if (!remote_database
)
4059 return ERROR_INVALID_HANDLE
;
4063 IWineMsiRemoteDatabase_Release( remote_database
);
4064 WARN("MsiEnableUIPreview not allowed during a custom action!\n");
4066 return ERROR_FUNCTION_FAILED
;
4068 preview
= MSI_EnableUIPreview( db
);
4071 *phPreview
= alloc_msihandle( &preview
->hdr
);
4072 msiobj_release( &preview
->hdr
);
4075 r
= ERROR_NOT_ENOUGH_MEMORY
;
4077 msiobj_release( &db
->hdr
);
4081 static UINT
preview_event_handler( MSIPACKAGE
*package
, LPCWSTR event
,
4082 LPCWSTR argument
, msi_dialog
*dialog
)
4084 MESSAGE("Preview dialog event '%s' (arg='%s')\n", debugstr_w(event
), debugstr_w(argument
));
4085 return ERROR_SUCCESS
;
4088 static UINT
MSI_PreviewDialogW( MSIPREVIEW
*preview
, LPCWSTR szDialogName
)
4090 msi_dialog
*dialog
= NULL
;
4091 UINT r
= ERROR_SUCCESS
;
4093 if (preview
->dialog
)
4094 msi_dialog_destroy( preview
->dialog
);
4096 /* an empty name means we should just destroy the current preview dialog */
4099 dialog
= msi_dialog_create( preview
->package
, szDialogName
, NULL
, preview_event_handler
);
4101 msi_dialog_do_preview( dialog
);
4103 r
= ERROR_FUNCTION_FAILED
;
4105 preview
->dialog
= dialog
;
4109 UINT WINAPI
MsiPreviewDialogW( MSIHANDLE hPreview
, LPCWSTR szDialogName
)
4111 MSIPREVIEW
*preview
;
4114 TRACE("%d %s\n", hPreview
, debugstr_w(szDialogName
));
4116 preview
= msihandle2msiinfo( hPreview
, MSIHANDLETYPE_PREVIEW
);
4118 return ERROR_INVALID_HANDLE
;
4120 r
= MSI_PreviewDialogW( preview
, szDialogName
);
4121 msiobj_release( &preview
->hdr
);
4125 UINT WINAPI
MsiPreviewDialogA( MSIHANDLE hPreview
, LPCSTR szDialogName
)
4130 TRACE("%d %s\n", hPreview
, debugstr_a(szDialogName
));
4134 strW
= strdupAtoW( szDialogName
);
4136 return ERROR_OUTOFMEMORY
;
4138 r
= MsiPreviewDialogW( hPreview
, strW
);
4143 UINT WINAPI
MsiPreviewBillboardW( MSIHANDLE hPreview
, LPCWSTR szControlName
, LPCWSTR szBillboard
)
4145 FIXME("%d %s %s\n", hPreview
, debugstr_w(szControlName
), debugstr_w(szBillboard
));
4146 return ERROR_CALL_NOT_IMPLEMENTED
;
4149 UINT WINAPI
MsiPreviewBillboardA( MSIHANDLE hPreview
, LPCSTR szControlName
, LPCSTR szBillboard
)
4151 FIXME("%d %s %s\n", hPreview
, debugstr_a(szControlName
), debugstr_a(szBillboard
));
4152 return ERROR_CALL_NOT_IMPLEMENTED
;