2 * Implementation of the Microsoft Installer (msi.dll)
4 * Copyright 2005 Mike McCormack for CodeWeavers
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #define NONAMELESSUNION
23 #define NONAMELESSSTRUCT
42 #include "wine/debug.h"
43 #include "wine/unicode.h"
45 WINE_DEFAULT_DEBUG_CHANNEL(msi
);
48 extern HINSTANCE msi_hInstance
;
50 struct msi_control_tag
;
51 typedef struct msi_control_tag msi_control
;
52 typedef UINT (*msi_handler
)( msi_dialog
*, msi_control
*, WPARAM
);
53 typedef void (*msi_update
)( msi_dialog
*, msi_control
* );
55 struct msi_control_tag
68 float progress_current
;
74 typedef struct msi_font_tag
76 struct msi_font_tag
*next
;
86 msi_dialog_event_handler event_handler
;
96 LPWSTR control_default
;
97 LPWSTR control_cancel
;
101 typedef UINT (*msi_dialog_control_func
)( msi_dialog
*dialog
, MSIRECORD
*rec
);
102 struct control_handler
104 LPCWSTR control_type
;
105 msi_dialog_control_func func
;
114 } radio_button_group_descr
;
116 static const WCHAR szMsiDialogClass
[] = {
117 'M','s','i','D','i','a','l','o','g','C','l','o','s','e','C','l','a','s','s',0
119 static const WCHAR szMsiHiddenWindow
[] = {
120 'M','s','i','H','i','d','d','e','n','W','i','n','d','o','w',0 };
121 static const WCHAR szStatic
[] = { 'S','t','a','t','i','c',0 };
122 static const WCHAR szButton
[] = { 'B','U','T','T','O','N', 0 };
123 static const WCHAR szButtonData
[] = { 'M','S','I','D','A','T','A',0 };
124 static const WCHAR szProgress
[] = { 'P','r','o','g','r','e','s','s',0 };
125 static const WCHAR szText
[] = { 'T','e','x','t',0 };
126 static const WCHAR szPushButton
[] = { 'P','u','s','h','B','u','t','t','o','n',0 };
127 static const WCHAR szLine
[] = { 'L','i','n','e',0 };
128 static const WCHAR szBitmap
[] = { 'B','i','t','m','a','p',0 };
129 static const WCHAR szCheckBox
[] = { 'C','h','e','c','k','B','o','x',0 };
130 static const WCHAR szScrollableText
[] = {
131 'S','c','r','o','l','l','a','b','l','e','T','e','x','t',0 };
132 static const WCHAR szComboBox
[] = { 'C','o','m','b','o','B','o','x',0 };
133 static const WCHAR szEdit
[] = { 'E','d','i','t',0 };
134 static const WCHAR szMaskedEdit
[] = { 'M','a','s','k','e','d','E','d','i','t',0 };
135 static const WCHAR szPathEdit
[] = { 'P','a','t','h','E','d','i','t',0 };
136 static const WCHAR szProgressBar
[] = {
137 'P','r','o','g','r','e','s','s','B','a','r',0 };
138 static const WCHAR szSetProgress
[] = {
139 'S','e','t','P','r','o','g','r','e','s','s',0 };
140 static const WCHAR szRadioButtonGroup
[] = {
141 'R','a','d','i','o','B','u','t','t','o','n','G','r','o','u','p',0 };
142 static const WCHAR szIcon
[] = { 'I','c','o','n',0 };
143 static const WCHAR szSelectionTree
[] = {
144 'S','e','l','e','c','t','i','o','n','T','r','e','e',0 };
145 static const WCHAR szGroupBox
[] = { 'G','r','o','u','p','B','o','x',0 };
146 static const WCHAR szListBox
[] = { 'L','i','s','t','B','o','x',0 };
147 static const WCHAR szDirectoryCombo
[] = { 'D','i','r','e','c','t','o','r','y','C','o','m','b','o',0 };
148 static const WCHAR szDirectoryList
[] = { 'D','i','r','e','c','t','o','r','y','L','i','s','t',0 };
149 static const WCHAR szVolumeCostList
[] = { 'V','o','l','u','m','e','C','o','s','t','L','i','s','t',0 };
150 static const WCHAR szVolumeSelectCombo
[] = { 'V','o','l','u','m','e','S','e','l','e','c','t','C','o','m','b','o',0 };
151 static const WCHAR szSelectionDescription
[] = {'S','e','l','e','c','t','i','o','n','D','e','s','c','r','i','p','t','i','o','n',0};
152 static const WCHAR szSelectionPath
[] = {'S','e','l','e','c','t','i','o','n','P','a','t','h',0};
153 static const WCHAR szProperty
[] = {'P','r','o','p','e','r','t','y',0};
155 static UINT
msi_dialog_checkbox_handler( msi_dialog
*, msi_control
*, WPARAM
);
156 static void msi_dialog_checkbox_sync_state( msi_dialog
*, msi_control
* );
157 static UINT
msi_dialog_button_handler( msi_dialog
*, msi_control
*, WPARAM
);
158 static UINT
msi_dialog_edit_handler( msi_dialog
*, msi_control
*, WPARAM
);
159 static UINT
msi_dialog_radiogroup_handler( msi_dialog
*, msi_control
*, WPARAM
);
160 static UINT
msi_dialog_evaluate_control_conditions( msi_dialog
*dialog
);
161 static LRESULT WINAPI
MSIRadioGroup_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
);
162 static MSIFEATURE
*msi_seltree_get_selected_feature( msi_control
*control
);
164 /* dialog sequencing */
166 #define WM_MSI_DIALOG_CREATE (WM_USER+0x100)
167 #define WM_MSI_DIALOG_DESTROY (WM_USER+0x101)
169 #define USER_INSTALLSTATE_ALL 0x1000
171 static DWORD uiThreadId
;
172 static HWND hMsiHiddenWindow
;
174 static LPWSTR
msi_get_window_text( HWND hwnd
);
176 static INT
msi_dialog_scale_unit( msi_dialog
*dialog
, INT val
)
178 return MulDiv( val
, dialog
->scale
, 12 );
181 static msi_control
*msi_dialog_find_control( msi_dialog
*dialog
, LPCWSTR name
)
183 msi_control
*control
;
189 LIST_FOR_EACH_ENTRY( control
, &dialog
->controls
, msi_control
, entry
)
190 if( !strcmpW( control
->name
, name
) ) /* FIXME: case sensitive? */
195 static msi_control
*msi_dialog_find_control_by_type( msi_dialog
*dialog
, LPCWSTR type
)
197 msi_control
*control
;
203 LIST_FOR_EACH_ENTRY( control
, &dialog
->controls
, msi_control
, entry
)
204 if( !strcmpW( control
->type
, type
) ) /* FIXME: case sensitive? */
209 static msi_control
*msi_dialog_find_control_by_hwnd( msi_dialog
*dialog
, HWND hwnd
)
211 msi_control
*control
;
215 LIST_FOR_EACH_ENTRY( control
, &dialog
->controls
, msi_control
, entry
)
216 if( hwnd
== control
->hwnd
)
221 static LPWSTR
msi_get_deformatted_field( MSIPACKAGE
*package
, MSIRECORD
*rec
, int field
)
223 LPCWSTR str
= MSI_RecordGetString( rec
, field
);
227 deformat_string( package
, str
, &ret
);
231 static LPWSTR
msi_dialog_dup_property( msi_dialog
*dialog
, LPCWSTR property
, BOOL indirect
)
239 prop
= msi_dup_property( dialog
->package
->db
, property
);
242 prop
= strdupW( property
);
247 msi_dialog
*msi_dialog_get_parent( msi_dialog
*dialog
)
249 return dialog
->parent
;
252 LPWSTR
msi_dialog_get_name( msi_dialog
*dialog
)
258 * msi_dialog_get_style
260 * Extract the {\style} string from the front of the text to display and
261 * update the pointer. Only the last style in a list is applied.
263 static LPWSTR
msi_dialog_get_style( LPCWSTR p
, LPCWSTR
*rest
)
274 while ((first
= strchrW( p
, '{' )) && (q
= strchrW( first
+ 1, '}' )))
277 if( *p
!= '\\' && *p
!= '&' )
280 /* little bit of sanity checking to stop us getting confused with RTF */
281 for( i
=++p
; i
<q
; i
++ )
282 if( *i
== '}' || *i
== '\\' )
292 ret
= msi_alloc( len
*sizeof(WCHAR
) );
295 memcpy( ret
, p
, len
*sizeof(WCHAR
) );
300 static UINT
msi_dialog_add_font( MSIRECORD
*rec
, LPVOID param
)
302 msi_dialog
*dialog
= param
;
309 /* create a font and add it to the list */
310 name
= MSI_RecordGetString( rec
, 1 );
311 font
= msi_alloc( sizeof *font
+ strlenW( name
)*sizeof (WCHAR
) );
312 strcpyW( font
->name
, name
);
313 font
->next
= dialog
->font_list
;
314 dialog
->font_list
= font
;
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
)
351 for( font
= dialog
->font_list
; font
; font
= font
->next
)
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',' ','*',' ',
374 'F','R','O','M',' ','`','T','e','x','t','S','t','y','l','e','`',' ',0
377 MSIQUERY
*view
= NULL
;
379 TRACE("dialog %p\n", dialog
);
381 r
= MSI_OpenQuery( dialog
->package
->db
, &view
, query
);
382 if( r
!= ERROR_SUCCESS
)
385 r
= MSI_IterateRecords( view
, NULL
, msi_dialog_add_font
, dialog
);
386 msiobj_release( &view
->hdr
);
391 static void msi_destroy_control( msi_control
*t
)
393 list_remove( &t
->entry
);
394 /* leave dialog->hwnd - destroying parent destroys child windows */
395 msi_free( t
->property
);
396 msi_free( t
->value
);
398 DeleteObject( t
->hBitmap
);
400 DestroyIcon( t
->hIcon
);
401 msi_free( t
->tabnext
);
404 FreeLibrary( t
->hDll
);
408 static msi_control
*msi_dialog_create_window( msi_dialog
*dialog
,
409 MSIRECORD
*rec
, DWORD exstyle
, LPCWSTR szCls
, LPCWSTR name
, LPCWSTR text
,
410 DWORD style
, HWND parent
)
412 DWORD x
, y
, width
, height
;
413 LPWSTR font
= NULL
, title_font
= NULL
;
414 LPCWSTR title
= NULL
;
415 msi_control
*control
;
419 control
= msi_alloc( sizeof *control
+ strlenW(name
)*sizeof(WCHAR
) );
423 strcpyW( control
->name
, name
);
424 list_add_tail( &dialog
->controls
, &control
->entry
);
425 control
->handler
= NULL
;
426 control
->update
= NULL
;
427 control
->property
= NULL
;
428 control
->value
= NULL
;
429 control
->hBitmap
= NULL
;
430 control
->hIcon
= NULL
;
431 control
->hDll
= NULL
;
432 control
->tabnext
= strdupW( MSI_RecordGetString( rec
, 11) );
433 control
->type
= strdupW( MSI_RecordGetString( rec
, 3 ) );
434 control
->progress_current
= 0;
435 control
->progress_max
= 100;
437 x
= MSI_RecordGetInteger( rec
, 4 );
438 y
= MSI_RecordGetInteger( rec
, 5 );
439 width
= MSI_RecordGetInteger( rec
, 6 );
440 height
= MSI_RecordGetInteger( rec
, 7 );
442 x
= msi_dialog_scale_unit( dialog
, x
);
443 y
= msi_dialog_scale_unit( dialog
, y
);
444 width
= msi_dialog_scale_unit( dialog
, width
);
445 height
= msi_dialog_scale_unit( dialog
, height
);
449 deformat_string( dialog
->package
, text
, &title_font
);
450 font
= msi_dialog_get_style( title_font
, &title
);
453 control
->hwnd
= CreateWindowExW( exstyle
, szCls
, title
, style
,
454 x
, y
, width
, height
, parent
, NULL
, NULL
, NULL
);
456 TRACE("Dialog %s control %s hwnd %p\n",
457 debugstr_w(dialog
->name
), debugstr_w(text
), control
->hwnd
);
459 msi_dialog_set_font( dialog
, control
->hwnd
,
460 font
? font
: dialog
->default_font
);
462 msi_free( title_font
);
468 static LPWSTR
msi_dialog_get_uitext( msi_dialog
*dialog
, LPCWSTR key
)
473 static const WCHAR query
[] = {
474 's','e','l','e','c','t',' ','*',' ',
475 'f','r','o','m',' ','`','U','I','T','e','x','t','`',' ',
476 'w','h','e','r','e',' ','`','K','e','y','`',' ','=',' ','\'','%','s','\'',0
479 rec
= MSI_QueryGetRecord( dialog
->package
->db
, query
, key
);
480 if (!rec
) return NULL
;
481 text
= strdupW( MSI_RecordGetString( rec
, 2 ) );
482 msiobj_release( &rec
->hdr
);
486 static MSIRECORD
*msi_get_binary_record( MSIDATABASE
*db
, LPCWSTR name
)
488 static const WCHAR query
[] = {
489 's','e','l','e','c','t',' ','*',' ',
490 'f','r','o','m',' ','B','i','n','a','r','y',' ',
491 'w','h','e','r','e',' ',
492 '`','N','a','m','e','`',' ','=',' ','\'','%','s','\'',0
495 return MSI_QueryGetRecord( db
, query
, name
);
498 static LPWSTR
msi_create_tmp_path(void)
504 r
= GetTempPathW( MAX_PATH
, tmp
);
507 len
= lstrlenW( tmp
) + 20;
508 path
= msi_alloc( len
* sizeof (WCHAR
) );
511 r
= GetTempFileNameW( tmp
, szMsi
, 0, path
);
522 static HANDLE
msi_load_image( MSIDATABASE
*db
, LPCWSTR name
, UINT type
,
523 UINT cx
, UINT cy
, UINT flags
)
525 MSIRECORD
*rec
= NULL
;
526 HANDLE himage
= NULL
;
530 TRACE("%p %s %u %u %08x\n", db
, debugstr_w(name
), cx
, cy
, flags
);
532 tmp
= msi_create_tmp_path();
536 rec
= msi_get_binary_record( db
, name
);
539 r
= MSI_RecordStreamToFile( rec
, 2, tmp
);
540 if( r
== ERROR_SUCCESS
)
542 himage
= LoadImageW( 0, tmp
, type
, cx
, cy
, flags
);
544 msiobj_release( &rec
->hdr
);
552 static HICON
msi_load_icon( MSIDATABASE
*db
, LPCWSTR text
, UINT attributes
)
554 DWORD cx
= 0, cy
= 0, flags
;
556 flags
= LR_LOADFROMFILE
| LR_DEFAULTSIZE
;
557 if( attributes
& msidbControlAttributesFixedSize
)
559 flags
&= ~LR_DEFAULTSIZE
;
560 if( attributes
& msidbControlAttributesIconSize16
)
565 if( attributes
& msidbControlAttributesIconSize32
)
570 /* msidbControlAttributesIconSize48 handled by above logic */
572 return msi_load_image( db
, text
, IMAGE_ICON
, cx
, cy
, flags
);
575 static void msi_dialog_update_controls( msi_dialog
*dialog
, LPCWSTR property
)
577 msi_control
*control
;
579 LIST_FOR_EACH_ENTRY( control
, &dialog
->controls
, msi_control
, entry
)
581 if ( control
->property
&& !strcmpW( control
->property
, property
) && control
->update
)
582 control
->update( dialog
, control
);
586 static void msi_dialog_set_property( MSIPACKAGE
*package
, LPCWSTR property
, LPCWSTR value
)
588 UINT r
= msi_set_property( package
->db
, property
, value
);
589 if (r
== ERROR_SUCCESS
&& !strcmpW( property
, cszSourceDir
))
590 msi_reset_folders( package
, TRUE
);
593 /* called from the Control Event subscription code */
594 void msi_dialog_handle_event( msi_dialog
* dialog
, LPCWSTR control
,
595 LPCWSTR attribute
, MSIRECORD
*rec
)
598 LPCWSTR font_text
, text
= NULL
;
601 ctrl
= msi_dialog_find_control( dialog
, control
);
604 if( !strcmpW( attribute
, szText
) )
606 font_text
= MSI_RecordGetString( rec
, 1 );
607 font
= msi_dialog_get_style( font_text
, &text
);
608 if (!text
) text
= szEmpty
;
609 SetWindowTextW( ctrl
->hwnd
, text
);
611 msi_dialog_check_messages( NULL
);
613 else if( !strcmpW( attribute
, szProgress
) )
617 func
= MSI_RecordGetInteger( rec
, 1 );
618 val
= MSI_RecordGetInteger( rec
, 2 );
620 TRACE("progress: func %u, val %u\n", func
, val
);
625 ctrl
->progress_max
= val
;
626 ctrl
->progress_current
= 0;
627 SendMessageW(ctrl
->hwnd
, PBM_SETRANGE
, 0, MAKELPARAM(0,100));
628 SendMessageW(ctrl
->hwnd
, PBM_SETPOS
, 0, 0);
630 case 1: /* FIXME: not sure what this is supposed to do */
633 ctrl
->progress_current
+= val
;
634 if (ctrl
->progress_current
> ctrl
->progress_max
)
635 ctrl
->progress_current
= ctrl
->progress_max
;
636 SendMessageW(ctrl
->hwnd
, PBM_SETPOS
, MulDiv(100, ctrl
->progress_current
, ctrl
->progress_max
), 0);
639 FIXME("Unknown progress message %u\n", func
);
643 else if ( !strcmpW( attribute
, szProperty
) )
645 MSIFEATURE
*feature
= msi_seltree_get_selected_feature( ctrl
);
646 msi_dialog_set_property( dialog
->package
, ctrl
->property
, feature
->Directory
);
648 else if ( !strcmpW( attribute
, szSelectionPath
) )
650 LPWSTR prop
= msi_dialog_dup_property( dialog
, ctrl
->property
, TRUE
);
653 path
= msi_dup_property( dialog
->package
->db
, prop
);
654 SetWindowTextW( ctrl
->hwnd
, path
);
660 FIXME("Attribute %s not being set\n", debugstr_w(attribute
));
665 static void msi_dialog_map_events(msi_dialog
* dialog
, LPCWSTR control
)
667 static const WCHAR Query
[] = {
668 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
669 '`','E','v','e','n','t','M','a','p','p','i','n','g','`',' ',
670 'W','H','E','R','E',' ',
671 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',' ',
673 '`','C','o','n','t','r','o','l','_','`',' ','=',' ','\'','%','s','\'',0
676 LPCWSTR event
, attribute
;
678 row
= MSI_QueryGetRecord( dialog
->package
->db
, Query
, dialog
->name
, control
);
682 event
= MSI_RecordGetString( row
, 3 );
683 attribute
= MSI_RecordGetString( row
, 4 );
684 ControlEvent_SubscribeToEvent( dialog
->package
, dialog
, event
, control
, attribute
);
685 msiobj_release( &row
->hdr
);
688 /* everything except radio buttons */
689 static msi_control
*msi_dialog_add_control( msi_dialog
*dialog
,
690 MSIRECORD
*rec
, LPCWSTR szCls
, DWORD style
)
696 name
= MSI_RecordGetString( rec
, 2 );
697 attributes
= MSI_RecordGetInteger( rec
, 8 );
698 text
= MSI_RecordGetString( rec
, 10 );
700 TRACE("%s, %s, %08x, %s, %08x\n", debugstr_w(szCls
), debugstr_w(name
),
701 attributes
, debugstr_w(text
), style
);
703 if( attributes
& msidbControlAttributesVisible
)
705 if( ~attributes
& msidbControlAttributesEnabled
)
706 style
|= WS_DISABLED
;
707 if( attributes
& msidbControlAttributesSunken
)
708 exstyle
|= WS_EX_CLIENTEDGE
;
710 msi_dialog_map_events(dialog
, name
);
712 return msi_dialog_create_window( dialog
, rec
, exstyle
, szCls
, name
,
713 text
, style
, dialog
->hwnd
);
724 * we don't erase our own background,
725 * so we have to make sure that the parent window redraws first
727 static void msi_text_on_settext( HWND hWnd
)
732 hParent
= GetParent( hWnd
);
733 GetWindowRect( hWnd
, &rc
);
734 MapWindowPoints( NULL
, hParent
, (LPPOINT
) &rc
, 2 );
735 InvalidateRect( hParent
, &rc
, TRUE
);
738 static LRESULT WINAPI
739 MSIText_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
741 struct msi_text_info
*info
;
744 TRACE("%p %04x %08lx %08lx\n", hWnd
, msg
, wParam
, lParam
);
746 info
= GetPropW(hWnd
, szButtonData
);
748 if( msg
== WM_CTLCOLORSTATIC
&&
749 ( info
->attributes
& msidbControlAttributesTransparent
) )
751 SetBkMode( (HDC
)wParam
, TRANSPARENT
);
752 return (LRESULT
) GetStockObject(NULL_BRUSH
);
755 r
= CallWindowProcW(info
->oldproc
, hWnd
, msg
, wParam
, lParam
);
757 SetTextColor( (HDC
)wParam
, info
->font
->color
);
762 msi_text_on_settext( hWnd
);
766 RemovePropW( hWnd
, szButtonData
);
773 static UINT
msi_dialog_text_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
775 msi_control
*control
;
776 struct msi_text_info
*info
;
777 LPCWSTR text
, ptr
, prop
, control_name
;
780 TRACE("%p %p\n", dialog
, rec
);
782 control
= msi_dialog_add_control( dialog
, rec
, szStatic
, SS_LEFT
| WS_GROUP
);
784 return ERROR_FUNCTION_FAILED
;
786 info
= msi_alloc( sizeof *info
);
788 return ERROR_SUCCESS
;
790 control_name
= MSI_RecordGetString( rec
, 2 );
791 control
->attributes
= MSI_RecordGetInteger( rec
, 8 );
792 prop
= MSI_RecordGetString( rec
, 9 );
793 control
->property
= msi_dialog_dup_property( dialog
, prop
, FALSE
);
795 text
= MSI_RecordGetString( rec
, 10 );
796 font_name
= msi_dialog_get_style( text
, &ptr
);
797 info
->font
= ( font_name
) ? msi_dialog_find_font( dialog
, font_name
) : NULL
;
798 msi_free( font_name
);
800 info
->attributes
= MSI_RecordGetInteger( rec
, 8 );
801 if( info
->attributes
& msidbControlAttributesTransparent
)
802 SetWindowLongPtrW( control
->hwnd
, GWL_EXSTYLE
, WS_EX_TRANSPARENT
);
804 info
->oldproc
= (WNDPROC
) SetWindowLongPtrW( control
->hwnd
, GWLP_WNDPROC
,
805 (LONG_PTR
)MSIText_WndProc
);
806 SetPropW( control
->hwnd
, szButtonData
, info
);
808 ControlEvent_SubscribeToEvent( dialog
->package
, dialog
,
809 szSelectionPath
, control_name
, szSelectionPath
);
811 return ERROR_SUCCESS
;
814 /* strip any leading text style label from text field */
815 static WCHAR
*msi_get_binary_name( MSIPACKAGE
*package
, MSIRECORD
*rec
)
819 text
= msi_get_deformatted_field( package
, rec
, 10 );
824 while (*p
&& *p
!= '{') p
++;
825 if (!*p
++) return text
;
827 while (*p
&& *p
!= '}') p
++;
828 if (!*p
++) return text
;
835 static UINT
msi_dialog_button_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
837 msi_control
*control
;
838 UINT attributes
, style
;
840 TRACE("%p %p\n", dialog
, rec
);
843 attributes
= MSI_RecordGetInteger( rec
, 8 );
844 if( attributes
& msidbControlAttributesIcon
)
847 control
= msi_dialog_add_control( dialog
, rec
, szButton
, style
);
849 return ERROR_FUNCTION_FAILED
;
851 control
->handler
= msi_dialog_button_handler
;
853 if (attributes
& msidbControlAttributesIcon
)
856 LPWSTR name
= msi_get_binary_name( dialog
->package
, rec
);
857 control
->hIcon
= msi_load_icon( dialog
->package
->db
, name
, attributes
);
860 SendMessageW( control
->hwnd
, BM_SETIMAGE
, IMAGE_ICON
, (LPARAM
) control
->hIcon
);
863 ERR("Failed to load icon %s\n", debugstr_w(name
));
867 return ERROR_SUCCESS
;
870 static LPWSTR
msi_get_checkbox_value( msi_dialog
*dialog
, LPCWSTR prop
)
872 static const WCHAR query
[] = {
873 'S','E','L','E','C','T',' ','*',' ',
874 'F','R','O','M',' ','`','C','h','e','c','k','B','o','x','`',' ',
875 'W','H','E','R','E',' ',
876 '`','P','r','o','p','e','r','t','y','`',' ','=',' ',
879 MSIRECORD
*rec
= NULL
;
882 /* find if there is a value associated with the checkbox */
883 rec
= MSI_QueryGetRecord( dialog
->package
->db
, query
, prop
);
887 ret
= msi_get_deformatted_field( dialog
->package
, rec
, 2 );
893 msiobj_release( &rec
->hdr
);
897 ret
= msi_dup_property( dialog
->package
->db
, prop
);
907 static UINT
msi_dialog_checkbox_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
909 msi_control
*control
;
912 TRACE("%p %p\n", dialog
, rec
);
914 control
= msi_dialog_add_control( dialog
, rec
, szButton
,
915 BS_CHECKBOX
| BS_MULTILINE
| WS_TABSTOP
);
916 control
->handler
= msi_dialog_checkbox_handler
;
917 control
->update
= msi_dialog_checkbox_sync_state
;
918 prop
= MSI_RecordGetString( rec
, 9 );
921 control
->property
= strdupW( prop
);
922 control
->value
= msi_get_checkbox_value( dialog
, prop
);
923 TRACE("control %s value %s\n", debugstr_w(control
->property
),
924 debugstr_w(control
->value
));
926 msi_dialog_checkbox_sync_state( dialog
, control
);
928 return ERROR_SUCCESS
;
931 static UINT
msi_dialog_line_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
935 DWORD style
, exstyle
= 0;
936 DWORD x
, y
, width
, height
;
937 msi_control
*control
;
939 TRACE("%p %p\n", dialog
, rec
);
941 style
= WS_CHILD
| SS_ETCHEDHORZ
| SS_SUNKEN
;
943 name
= MSI_RecordGetString( rec
, 2 );
944 attributes
= MSI_RecordGetInteger( rec
, 8 );
946 if( attributes
& msidbControlAttributesVisible
)
948 if( ~attributes
& msidbControlAttributesEnabled
)
949 style
|= WS_DISABLED
;
950 if( attributes
& msidbControlAttributesSunken
)
951 exstyle
|= WS_EX_CLIENTEDGE
;
953 msi_dialog_map_events(dialog
, name
);
955 control
= msi_alloc( sizeof(*control
) + strlenW(name
) * sizeof(WCHAR
) );
957 return ERROR_OUTOFMEMORY
;
959 strcpyW( control
->name
, name
);
960 list_add_head( &dialog
->controls
, &control
->entry
);
961 control
->handler
= NULL
;
962 control
->property
= NULL
;
963 control
->value
= NULL
;
964 control
->hBitmap
= NULL
;
965 control
->hIcon
= NULL
;
966 control
->hDll
= NULL
;
967 control
->tabnext
= strdupW( MSI_RecordGetString( rec
, 11) );
968 control
->type
= strdupW( MSI_RecordGetString( rec
, 3 ) );
969 control
->progress_current
= 0;
970 control
->progress_max
= 100;
972 x
= MSI_RecordGetInteger( rec
, 4 );
973 y
= MSI_RecordGetInteger( rec
, 5 );
974 width
= MSI_RecordGetInteger( rec
, 6 );
976 x
= msi_dialog_scale_unit( dialog
, x
);
977 y
= msi_dialog_scale_unit( dialog
, y
);
978 width
= msi_dialog_scale_unit( dialog
, width
);
979 height
= 2; /* line is exactly 2 units in height */
981 control
->hwnd
= CreateWindowExW( exstyle
, szStatic
, NULL
, style
,
982 x
, y
, width
, height
, dialog
->hwnd
, NULL
, NULL
, NULL
);
984 TRACE("Dialog %s control %s hwnd %p\n",
985 debugstr_w(dialog
->name
), debugstr_w(name
), control
->hwnd
);
987 return ERROR_SUCCESS
;
990 /******************** Scroll Text ********************************************/
992 struct msi_scrolltext_info
995 msi_control
*control
;
999 static LRESULT WINAPI
1000 MSIScrollText_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1002 struct msi_scrolltext_info
*info
;
1005 TRACE("%p %04x %08lx %08lx\n", hWnd
, msg
, wParam
, lParam
);
1007 info
= GetPropW( hWnd
, szButtonData
);
1009 r
= CallWindowProcW( info
->oldproc
, hWnd
, msg
, wParam
, lParam
);
1014 return DLGC_WANTARROWS
;
1017 RemovePropW( hWnd
, szButtonData
);
1020 /* native MSI sets a wait cursor here */
1021 msi_dialog_button_handler( info
->dialog
, info
->control
, BN_CLICKED
);
1027 struct msi_streamin_info
1034 static DWORD CALLBACK
1035 msi_richedit_stream_in( DWORD_PTR arg
, LPBYTE buffer
, LONG count
, LONG
*pcb
)
1037 struct msi_streamin_info
*info
= (struct msi_streamin_info
*) arg
;
1039 if( (count
+ info
->offset
) > info
->length
)
1040 count
= info
->length
- info
->offset
;
1041 memcpy( buffer
, &info
->string
[ info
->offset
], count
);
1043 info
->offset
+= count
;
1045 TRACE("%d/%d\n", info
->offset
, info
->length
);
1050 static void msi_scrolltext_add_text( msi_control
*control
, LPCWSTR text
)
1052 struct msi_streamin_info info
;
1055 info
.string
= strdupWtoA( text
);
1057 info
.length
= lstrlenA( info
.string
) + 1;
1059 es
.dwCookie
= (DWORD_PTR
) &info
;
1061 es
.pfnCallback
= msi_richedit_stream_in
;
1063 SendMessageW( control
->hwnd
, EM_STREAMIN
, SF_RTF
, (LPARAM
) &es
);
1065 msi_free( info
.string
);
1068 static UINT
msi_dialog_scrolltext_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1070 static const WCHAR szRichEdit20W
[] = {
1071 'R','i','c','h','E','d','i','t','2','0','W',0
1073 struct msi_scrolltext_info
*info
;
1074 msi_control
*control
;
1079 info
= msi_alloc( sizeof *info
);
1081 return ERROR_FUNCTION_FAILED
;
1083 hRichedit
= LoadLibraryA("riched20");
1085 style
= WS_BORDER
| ES_MULTILINE
| WS_VSCROLL
|
1086 ES_READONLY
| ES_AUTOVSCROLL
| WS_TABSTOP
;
1087 control
= msi_dialog_add_control( dialog
, rec
, szRichEdit20W
, style
);
1090 FreeLibrary( hRichedit
);
1092 return ERROR_FUNCTION_FAILED
;
1095 control
->hDll
= hRichedit
;
1097 info
->dialog
= dialog
;
1098 info
->control
= control
;
1100 /* subclass the static control */
1101 info
->oldproc
= (WNDPROC
) SetWindowLongPtrW( control
->hwnd
, GWLP_WNDPROC
,
1102 (LONG_PTR
)MSIScrollText_WndProc
);
1103 SetPropW( control
->hwnd
, szButtonData
, info
);
1105 /* add the text into the richedit */
1106 text
= MSI_RecordGetString( rec
, 10 );
1108 msi_scrolltext_add_text( control
, text
);
1110 return ERROR_SUCCESS
;
1113 static HBITMAP
msi_load_picture( MSIDATABASE
*db
, LPCWSTR name
,
1114 INT cx
, INT cy
, DWORD flags
)
1116 HBITMAP hOleBitmap
= 0, hBitmap
= 0, hOldSrcBitmap
, hOldDestBitmap
;
1117 MSIRECORD
*rec
= NULL
;
1118 IStream
*stm
= NULL
;
1119 IPicture
*pic
= NULL
;
1124 rec
= msi_get_binary_record( db
, name
);
1128 r
= MSI_RecordGetIStream( rec
, 2, &stm
);
1129 msiobj_release( &rec
->hdr
);
1130 if( r
!= ERROR_SUCCESS
)
1133 r
= OleLoadPicture( stm
, 0, TRUE
, &IID_IPicture
, (LPVOID
*) &pic
);
1134 IStream_Release( stm
);
1137 ERR("failed to load picture\n");
1141 r
= IPicture_get_Handle( pic
, (OLE_HANDLE
*) &hOleBitmap
);
1144 ERR("failed to get bitmap handle\n");
1148 /* make the bitmap the desired size */
1149 r
= GetObjectW( hOleBitmap
, sizeof bm
, &bm
);
1150 if (r
!= sizeof bm
)
1152 ERR("failed to get bitmap size\n");
1156 if (flags
& LR_DEFAULTSIZE
)
1162 srcdc
= CreateCompatibleDC( NULL
);
1163 hOldSrcBitmap
= SelectObject( srcdc
, hOleBitmap
);
1164 destdc
= CreateCompatibleDC( NULL
);
1165 hBitmap
= CreateCompatibleBitmap( srcdc
, cx
, cy
);
1166 hOldDestBitmap
= SelectObject( destdc
, hBitmap
);
1167 StretchBlt( destdc
, 0, 0, cx
, cy
,
1168 srcdc
, 0, 0, bm
.bmWidth
, bm
.bmHeight
, SRCCOPY
);
1169 SelectObject( srcdc
, hOldSrcBitmap
);
1170 SelectObject( destdc
, hOldDestBitmap
);
1176 IPicture_Release( pic
);
1180 static UINT
msi_dialog_bitmap_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1182 UINT cx
, cy
, flags
, style
, attributes
;
1183 msi_control
*control
;
1186 flags
= LR_LOADFROMFILE
;
1187 style
= SS_BITMAP
| SS_LEFT
| WS_GROUP
;
1189 attributes
= MSI_RecordGetInteger( rec
, 8 );
1190 if( attributes
& msidbControlAttributesFixedSize
)
1192 flags
|= LR_DEFAULTSIZE
;
1193 style
|= SS_CENTERIMAGE
;
1196 control
= msi_dialog_add_control( dialog
, rec
, szStatic
, style
);
1197 cx
= MSI_RecordGetInteger( rec
, 6 );
1198 cy
= MSI_RecordGetInteger( rec
, 7 );
1199 cx
= msi_dialog_scale_unit( dialog
, cx
);
1200 cy
= msi_dialog_scale_unit( dialog
, cy
);
1202 name
= msi_get_binary_name( dialog
->package
, rec
);
1203 control
->hBitmap
= msi_load_picture( dialog
->package
->db
, name
, cx
, cy
, flags
);
1204 if( control
->hBitmap
)
1205 SendMessageW( control
->hwnd
, STM_SETIMAGE
,
1206 IMAGE_BITMAP
, (LPARAM
) control
->hBitmap
);
1208 ERR("Failed to load bitmap %s\n", debugstr_w(name
));
1212 return ERROR_SUCCESS
;
1215 static UINT
msi_dialog_icon_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1217 msi_control
*control
;
1223 control
= msi_dialog_add_control( dialog
, rec
, szStatic
,
1224 SS_ICON
| SS_CENTERIMAGE
| WS_GROUP
);
1226 attributes
= MSI_RecordGetInteger( rec
, 8 );
1227 name
= msi_get_binary_name( dialog
->package
, rec
);
1228 control
->hIcon
= msi_load_icon( dialog
->package
->db
, name
, attributes
);
1229 if( control
->hIcon
)
1230 SendMessageW( control
->hwnd
, STM_SETICON
, (WPARAM
) control
->hIcon
, 0 );
1232 ERR("Failed to load bitmap %s\n", debugstr_w(name
));
1234 return ERROR_SUCCESS
;
1237 /******************** Combo Box ***************************************/
1239 struct msi_combobox_info
1249 static LRESULT WINAPI
MSIComboBox_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1251 struct msi_combobox_info
*info
;
1255 TRACE("%p %04x %08lx %08lx\n", hWnd
, msg
, wParam
, lParam
);
1257 info
= GetPropW( hWnd
, szButtonData
);
1261 r
= CallWindowProcW( info
->oldproc
, hWnd
, msg
, wParam
, lParam
);
1266 for (j
= 0; j
< info
->num_items
; j
++)
1267 msi_free( info
->items
[j
] );
1268 msi_free( info
->items
);
1270 RemovePropW( hWnd
, szButtonData
);
1277 static UINT
msi_combobox_add_item( MSIRECORD
*rec
, LPVOID param
)
1279 struct msi_combobox_info
*info
= param
;
1280 LPCWSTR value
, text
;
1283 value
= MSI_RecordGetString( rec
, 3 );
1284 text
= MSI_RecordGetString( rec
, 4 );
1286 info
->items
[info
->addpos_items
] = strdupW( value
);
1288 pos
= SendMessageW( info
->hwnd
, CB_ADDSTRING
, 0, (LPARAM
)text
);
1289 SendMessageW( info
->hwnd
, CB_SETITEMDATA
, pos
, (LPARAM
)info
->items
[info
->addpos_items
] );
1290 info
->addpos_items
++;
1292 return ERROR_SUCCESS
;
1295 static UINT
msi_combobox_add_items( struct msi_combobox_info
*info
, LPCWSTR property
)
1298 MSIQUERY
*view
= NULL
;
1301 static const WCHAR query
[] = {
1302 'S','E','L','E','C','T',' ','*',' ',
1303 'F','R','O','M',' ','`','C','o','m','b','o','B','o','x','`',' ',
1304 'W','H','E','R','E',' ',
1305 '`','P','r','o','p','e','r','t','y','`',' ','=',' ','\'','%','s','\'',' ',
1306 'O','R','D','E','R',' ','B','Y',' ','`','O','r','d','e','r','`',0
1309 r
= MSI_OpenQuery( info
->dialog
->package
->db
, &view
, query
, property
);
1310 if (r
!= ERROR_SUCCESS
)
1313 /* just get the number of records */
1315 r
= MSI_IterateRecords( view
, &count
, NULL
, NULL
);
1317 info
->num_items
= count
;
1318 info
->items
= msi_alloc( sizeof(*info
->items
) * count
);
1320 r
= MSI_IterateRecords( view
, NULL
, msi_combobox_add_item
, info
);
1321 msiobj_release( &view
->hdr
);
1326 static UINT
msi_dialog_combobox_handler( msi_dialog
*dialog
,
1327 msi_control
*control
, WPARAM param
)
1329 struct msi_combobox_info
*info
;
1333 if (HIWORD(param
) != CBN_SELCHANGE
&& HIWORD(param
) != CBN_EDITCHANGE
)
1334 return ERROR_SUCCESS
;
1336 info
= GetPropW( control
->hwnd
, szButtonData
);
1337 index
= SendMessageW( control
->hwnd
, CB_GETCURSEL
, 0, 0 );
1338 if (index
== CB_ERR
)
1339 value
= msi_get_window_text( control
->hwnd
);
1341 value
= (LPWSTR
) SendMessageW( control
->hwnd
, CB_GETITEMDATA
, index
, 0 );
1343 msi_dialog_set_property( info
->dialog
->package
, control
->property
, value
);
1344 msi_dialog_evaluate_control_conditions( info
->dialog
);
1346 if (index
== CB_ERR
)
1349 return ERROR_SUCCESS
;
1352 static void msi_dialog_combobox_update( msi_dialog
*dialog
,
1353 msi_control
*control
)
1355 struct msi_combobox_info
*info
;
1359 info
= GetPropW( control
->hwnd
, szButtonData
);
1361 value
= msi_dup_property( dialog
->package
->db
, control
->property
);
1364 SendMessageW( control
->hwnd
, CB_SETCURSEL
, -1, 0 );
1368 for (j
= 0; j
< info
->num_items
; j
++)
1370 tmp
= (LPWSTR
) SendMessageW( control
->hwnd
, CB_GETITEMDATA
, j
, 0 );
1371 if (!strcmpW( value
, tmp
))
1375 if (j
< info
->num_items
)
1377 SendMessageW( control
->hwnd
, CB_SETCURSEL
, j
, 0 );
1381 SendMessageW( control
->hwnd
, CB_SETCURSEL
, -1, 0 );
1382 SetWindowTextW( control
->hwnd
, value
);
1388 static UINT
msi_dialog_combo_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1390 struct msi_combobox_info
*info
;
1391 msi_control
*control
;
1392 DWORD attributes
, style
;
1395 info
= msi_alloc( sizeof *info
);
1397 return ERROR_FUNCTION_FAILED
;
1399 style
= CBS_AUTOHSCROLL
| WS_TABSTOP
| WS_GROUP
| WS_CHILD
;
1400 attributes
= MSI_RecordGetInteger( rec
, 8 );
1401 if ( ~attributes
& msidbControlAttributesSorted
)
1403 if ( attributes
& msidbControlAttributesComboList
)
1404 style
|= CBS_DROPDOWNLIST
;
1406 style
|= CBS_DROPDOWN
;
1408 control
= msi_dialog_add_control( dialog
, rec
, WC_COMBOBOXW
, style
);
1412 return ERROR_FUNCTION_FAILED
;
1415 control
->handler
= msi_dialog_combobox_handler
;
1416 control
->update
= msi_dialog_combobox_update
;
1418 prop
= MSI_RecordGetString( rec
, 9 );
1419 control
->property
= msi_dialog_dup_property( dialog
, prop
, FALSE
);
1422 info
->dialog
= dialog
;
1423 info
->hwnd
= control
->hwnd
;
1425 info
->addpos_items
= 0;
1426 info
->oldproc
= (WNDPROC
)SetWindowLongPtrW( control
->hwnd
, GWLP_WNDPROC
,
1427 (LONG_PTR
)MSIComboBox_WndProc
);
1428 SetPropW( control
->hwnd
, szButtonData
, info
);
1430 if (control
->property
)
1431 msi_combobox_add_items( info
, control
->property
);
1433 msi_dialog_combobox_update( dialog
, control
);
1435 return ERROR_SUCCESS
;
1438 /* length of 2^32 + 1 */
1439 #define MAX_NUM_DIGITS 11
1441 static UINT
msi_dialog_edit_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1443 msi_control
*control
;
1445 LPWSTR val
, begin
, end
;
1446 WCHAR num
[MAX_NUM_DIGITS
];
1449 control
= msi_dialog_add_control( dialog
, rec
, szEdit
,
1450 WS_BORDER
| WS_TABSTOP
| ES_AUTOHSCROLL
);
1451 control
->handler
= msi_dialog_edit_handler
;
1453 text
= MSI_RecordGetString( rec
, 10 );
1456 begin
= strchrW( text
, '{' );
1457 end
= strchrW( text
, '}' );
1459 if ( begin
&& end
&& end
> begin
&&
1460 begin
[0] >= '0' && begin
[0] <= '9' &&
1461 end
- begin
< MAX_NUM_DIGITS
)
1463 lstrcpynW( num
, begin
+ 1, end
- begin
);
1464 limit
= atolW( num
);
1466 SendMessageW( control
->hwnd
, EM_SETLIMITTEXT
, limit
, 0 );
1470 prop
= MSI_RecordGetString( rec
, 9 );
1472 control
->property
= strdupW( prop
);
1474 val
= msi_dup_property( dialog
->package
->db
, control
->property
);
1475 SetWindowTextW( control
->hwnd
, val
);
1477 return ERROR_SUCCESS
;
1480 /******************** Masked Edit ********************************************/
1482 #define MASK_MAX_GROUPS 20
1484 struct msi_mask_group
1492 struct msi_maskedit_info
1500 struct msi_mask_group group
[MASK_MAX_GROUPS
];
1503 static BOOL
msi_mask_editable( WCHAR type
)
1518 static void msi_mask_control_change( struct msi_maskedit_info
*info
)
1523 val
= msi_alloc( (info
->num_chars
+1)*sizeof(WCHAR
) );
1524 for( i
=0, n
=0; i
<info
->num_groups
; i
++ )
1526 if( (info
->group
[i
].len
+ n
) > info
->num_chars
)
1528 ERR("can't fit control %d text into template\n",i
);
1531 if (!msi_mask_editable(info
->group
[i
].type
))
1533 for(r
=0; r
<info
->group
[i
].len
; r
++)
1534 val
[n
+r
] = info
->group
[i
].type
;
1539 r
= GetWindowTextW( info
->group
[i
].hwnd
, &val
[n
], info
->group
[i
].len
+1 );
1540 if( r
!= info
->group
[i
].len
)
1546 TRACE("%d/%d controls were good\n", i
, info
->num_groups
);
1548 if( i
== info
->num_groups
)
1550 TRACE("Set property %s to %s\n", debugstr_w(info
->prop
), debugstr_w(val
));
1551 CharUpperBuffW( val
, info
->num_chars
);
1552 msi_dialog_set_property( info
->dialog
->package
, info
->prop
, val
);
1553 msi_dialog_evaluate_control_conditions( info
->dialog
);
1558 /* now move to the next control if necessary */
1559 static VOID
msi_mask_next_control( struct msi_maskedit_info
*info
, HWND hWnd
)
1564 for( i
=0; i
<info
->num_groups
; i
++ )
1565 if( info
->group
[i
].hwnd
== hWnd
)
1568 /* don't move from the last control */
1569 if( i
>= (info
->num_groups
-1) )
1572 len
= SendMessageW( hWnd
, WM_GETTEXTLENGTH
, 0, 0 );
1573 if( len
< info
->group
[i
].len
)
1576 hWndNext
= GetNextDlgTabItem( GetParent( hWnd
), hWnd
, FALSE
);
1577 SetFocus( hWndNext
);
1580 static LRESULT WINAPI
1581 MSIMaskedEdit_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1583 struct msi_maskedit_info
*info
;
1586 TRACE("%p %04x %08lx %08lx\n", hWnd
, msg
, wParam
, lParam
);
1588 info
= GetPropW(hWnd
, szButtonData
);
1590 r
= CallWindowProcW(info
->oldproc
, hWnd
, msg
, wParam
, lParam
);
1595 if (HIWORD(wParam
) == EN_CHANGE
)
1597 msi_mask_control_change( info
);
1598 msi_mask_next_control( info
, (HWND
) lParam
);
1602 msi_free( info
->prop
);
1604 RemovePropW( hWnd
, szButtonData
);
1611 /* fish the various bits of the property out and put them in the control */
1613 msi_maskedit_set_text( struct msi_maskedit_info
*info
, LPCWSTR text
)
1619 for( i
= 0; i
< info
->num_groups
; i
++ )
1621 if( info
->group
[i
].len
< strlenW( p
) )
1623 LPWSTR chunk
= strdupW( p
);
1624 chunk
[ info
->group
[i
].len
] = 0;
1625 SetWindowTextW( info
->group
[i
].hwnd
, chunk
);
1630 SetWindowTextW( info
->group
[i
].hwnd
, p
);
1633 p
+= info
->group
[i
].len
;
1637 static struct msi_maskedit_info
* msi_dialog_parse_groups( LPCWSTR mask
)
1639 struct msi_maskedit_info
* info
= NULL
;
1640 int i
= 0, n
= 0, total
= 0;
1643 TRACE("masked control, template %s\n", debugstr_w(mask
));
1648 info
= msi_alloc_zero( sizeof *info
);
1652 p
= strchrW(mask
, '<');
1658 for( i
=0; i
<MASK_MAX_GROUPS
; i
++ )
1660 /* stop at the end of the string */
1661 if( p
[0] == 0 || p
[0] == '>' )
1664 /* count the number of the same identifier */
1665 for( n
=0; p
[n
] == p
[0]; n
++ )
1667 info
->group
[i
].ofs
= total
;
1668 info
->group
[i
].type
= p
[0];
1672 total
++; /* an extra not part of the group */
1674 info
->group
[i
].len
= n
;
1679 TRACE("%d characters in %d groups\n", total
, i
);
1680 if( i
== MASK_MAX_GROUPS
)
1681 ERR("too many groups in PIDTemplate %s\n", debugstr_w(mask
));
1683 info
->num_chars
= total
;
1684 info
->num_groups
= i
;
1690 msi_maskedit_create_children( struct msi_maskedit_info
*info
, LPCWSTR font
)
1692 DWORD width
, height
, style
, wx
, ww
;
1697 style
= WS_CHILD
| WS_BORDER
| WS_VISIBLE
| WS_TABSTOP
| ES_AUTOHSCROLL
;
1699 GetClientRect( info
->hwnd
, &rect
);
1701 width
= rect
.right
- rect
.left
;
1702 height
= rect
.bottom
- rect
.top
;
1704 for( i
= 0; i
< info
->num_groups
; i
++ )
1706 if (!msi_mask_editable( info
->group
[i
].type
))
1708 wx
= (info
->group
[i
].ofs
* width
) / info
->num_chars
;
1709 ww
= (info
->group
[i
].len
* width
) / info
->num_chars
;
1711 hwnd
= CreateWindowW( szEdit
, NULL
, style
, wx
, 0, ww
, height
,
1712 info
->hwnd
, NULL
, NULL
, NULL
);
1715 ERR("failed to create mask edit sub window\n");
1719 SendMessageW( hwnd
, EM_LIMITTEXT
, info
->group
[i
].len
, 0 );
1721 msi_dialog_set_font( info
->dialog
, hwnd
,
1722 font
?font
:info
->dialog
->default_font
);
1723 info
->group
[i
].hwnd
= hwnd
;
1728 * office 2003 uses "73931<````=````=````=````=`````>@@@@@"
1729 * delphi 7 uses "<????-??????-??????-????>" and "<???-???>"
1730 * filemaker pro 7 uses "<^^^^=^^^^=^^^^=^^^^=^^^^=^^^^=^^^^^>"
1732 static UINT
msi_dialog_maskedit_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1734 LPWSTR font_mask
, val
= NULL
, font
;
1735 struct msi_maskedit_info
*info
= NULL
;
1736 UINT ret
= ERROR_SUCCESS
;
1737 msi_control
*control
;
1742 font_mask
= msi_get_deformatted_field( dialog
->package
, rec
, 10 );
1743 font
= msi_dialog_get_style( font_mask
, &mask
);
1746 WARN("mask template is empty\n");
1750 info
= msi_dialog_parse_groups( mask
);
1753 ERR("template %s is invalid\n", debugstr_w(mask
));
1757 info
->dialog
= dialog
;
1759 control
= msi_dialog_add_control( dialog
, rec
, szStatic
,
1760 SS_OWNERDRAW
| WS_GROUP
| WS_VISIBLE
);
1763 ERR("Failed to create maskedit container\n");
1764 ret
= ERROR_FUNCTION_FAILED
;
1767 SetWindowLongPtrW( control
->hwnd
, GWL_EXSTYLE
, WS_EX_CONTROLPARENT
);
1769 info
->hwnd
= control
->hwnd
;
1771 /* subclass the static control */
1772 info
->oldproc
= (WNDPROC
) SetWindowLongPtrW( info
->hwnd
, GWLP_WNDPROC
,
1773 (LONG_PTR
)MSIMaskedEdit_WndProc
);
1774 SetPropW( control
->hwnd
, szButtonData
, info
);
1776 prop
= MSI_RecordGetString( rec
, 9 );
1778 info
->prop
= strdupW( prop
);
1780 msi_maskedit_create_children( info
, font
);
1784 val
= msi_dup_property( dialog
->package
->db
, prop
);
1787 msi_maskedit_set_text( info
, val
);
1793 if( ret
!= ERROR_SUCCESS
)
1795 msi_free( font_mask
);
1800 /******************** Progress Bar *****************************************/
1802 static UINT
msi_dialog_progress_bar( msi_dialog
*dialog
, MSIRECORD
*rec
)
1804 msi_control
*control
;
1805 DWORD attributes
, style
;
1808 attributes
= MSI_RecordGetInteger( rec
, 8 );
1809 if( !(attributes
& msidbControlAttributesProgress95
) )
1810 style
|= PBS_SMOOTH
;
1812 control
= msi_dialog_add_control( dialog
, rec
, PROGRESS_CLASSW
, style
);
1814 return ERROR_FUNCTION_FAILED
;
1816 ControlEvent_SubscribeToEvent( dialog
->package
, dialog
,
1817 szSetProgress
, control
->name
, szProgress
);
1818 return ERROR_SUCCESS
;
1821 /******************** Path Edit ********************************************/
1823 struct msi_pathedit_info
1826 msi_control
*control
;
1830 static LPWSTR
msi_get_window_text( HWND hwnd
)
1836 buf
= msi_alloc( sz
*sizeof(WCHAR
) );
1839 r
= GetWindowTextW( hwnd
, buf
, sz
);
1843 buf
= msi_realloc( buf
, sz
*sizeof(WCHAR
) );
1849 static void msi_dialog_update_pathedit( msi_dialog
*dialog
, msi_control
*control
)
1854 if (!control
&& !(control
= msi_dialog_find_control_by_type( dialog
, szPathEdit
)))
1857 indirect
= control
->attributes
& msidbControlAttributesIndirect
;
1858 prop
= msi_dialog_dup_property( dialog
, control
->property
, indirect
);
1859 path
= msi_dialog_dup_property( dialog
, prop
, TRUE
);
1861 SetWindowTextW( control
->hwnd
, path
);
1862 SendMessageW( control
->hwnd
, EM_SETSEL
, 0, -1 );
1868 /* FIXME: test when this should fail */
1869 static BOOL
msi_dialog_verify_path( LPWSTR path
)
1871 if ( !lstrlenW( path
) )
1874 if ( PathIsRelativeW( path
) )
1880 /* returns TRUE if the path is valid, FALSE otherwise */
1881 static BOOL
msi_dialog_onkillfocus( msi_dialog
*dialog
, msi_control
*control
)
1887 indirect
= control
->attributes
& msidbControlAttributesIndirect
;
1888 prop
= msi_dialog_dup_property( dialog
, control
->property
, indirect
);
1890 buf
= msi_get_window_text( control
->hwnd
);
1892 if ( !msi_dialog_verify_path( buf
) )
1894 /* FIXME: display an error message box */
1895 ERR("Invalid path %s\n", debugstr_w( buf
));
1897 SetFocus( control
->hwnd
);
1902 msi_dialog_set_property( dialog
->package
, prop
, buf
);
1905 msi_dialog_update_pathedit( dialog
, control
);
1907 TRACE("edit %s contents changed, set %s\n", debugstr_w(control
->name
),
1916 static LRESULT WINAPI
MSIPathEdit_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1918 struct msi_pathedit_info
*info
= GetPropW(hWnd
, szButtonData
);
1921 TRACE("%p %04x %08lx %08lx\n", hWnd
, msg
, wParam
, lParam
);
1923 if ( msg
== WM_KILLFOCUS
)
1925 /* if the path is invalid, don't handle this message */
1926 if ( !msi_dialog_onkillfocus( info
->dialog
, info
->control
) )
1930 r
= CallWindowProcW(info
->oldproc
, hWnd
, msg
, wParam
, lParam
);
1932 if ( msg
== WM_NCDESTROY
)
1935 RemovePropW( hWnd
, szButtonData
);
1941 static UINT
msi_dialog_pathedit_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
1943 struct msi_pathedit_info
*info
;
1944 msi_control
*control
;
1947 info
= msi_alloc( sizeof *info
);
1949 return ERROR_FUNCTION_FAILED
;
1951 control
= msi_dialog_add_control( dialog
, rec
, szEdit
,
1952 WS_BORDER
| WS_TABSTOP
);
1953 control
->attributes
= MSI_RecordGetInteger( rec
, 8 );
1954 prop
= MSI_RecordGetString( rec
, 9 );
1955 control
->property
= msi_dialog_dup_property( dialog
, prop
, FALSE
);
1957 info
->dialog
= dialog
;
1958 info
->control
= control
;
1959 info
->oldproc
= (WNDPROC
) SetWindowLongPtrW( control
->hwnd
, GWLP_WNDPROC
,
1960 (LONG_PTR
)MSIPathEdit_WndProc
);
1961 SetPropW( control
->hwnd
, szButtonData
, info
);
1963 msi_dialog_update_pathedit( dialog
, control
);
1965 return ERROR_SUCCESS
;
1968 /* radio buttons are a bit different from normal controls */
1969 static UINT
msi_dialog_create_radiobutton( MSIRECORD
*rec
, LPVOID param
)
1971 radio_button_group_descr
*group
= param
;
1972 msi_dialog
*dialog
= group
->dialog
;
1973 msi_control
*control
;
1974 LPCWSTR prop
, text
, name
;
1975 DWORD style
, attributes
= group
->attributes
;
1977 style
= WS_CHILD
| BS_AUTORADIOBUTTON
| BS_MULTILINE
| WS_TABSTOP
;
1978 name
= MSI_RecordGetString( rec
, 3 );
1979 text
= MSI_RecordGetString( rec
, 8 );
1980 if( attributes
& msidbControlAttributesVisible
)
1981 style
|= WS_VISIBLE
;
1982 if( ~attributes
& msidbControlAttributesEnabled
)
1983 style
|= WS_DISABLED
;
1985 control
= msi_dialog_create_window( dialog
, rec
, 0, szButton
, name
, text
,
1986 style
, group
->parent
->hwnd
);
1988 return ERROR_FUNCTION_FAILED
;
1989 control
->handler
= msi_dialog_radiogroup_handler
;
1991 if (group
->propval
&& !strcmpW( control
->name
, group
->propval
))
1992 SendMessageW(control
->hwnd
, BM_SETCHECK
, BST_CHECKED
, 0);
1994 prop
= MSI_RecordGetString( rec
, 1 );
1996 control
->property
= strdupW( prop
);
1998 return ERROR_SUCCESS
;
2001 static UINT
msi_dialog_radiogroup_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
2003 static const WCHAR query
[] = {
2004 'S','E','L','E','C','T',' ','*',' ',
2005 'F','R','O','M',' ','R','a','d','i','o','B','u','t','t','o','n',' ',
2006 'W','H','E','R','E',' ',
2007 '`','P','r','o','p','e','r','t','y','`',' ','=',' ','\'','%','s','\'',0};
2010 msi_control
*control
;
2011 MSIQUERY
*view
= NULL
;
2012 radio_button_group_descr group
;
2013 MSIPACKAGE
*package
= dialog
->package
;
2015 DWORD attr
, style
= WS_GROUP
;
2017 prop
= MSI_RecordGetString( rec
, 9 );
2019 TRACE("%p %p %s\n", dialog
, rec
, debugstr_w( prop
));
2021 attr
= MSI_RecordGetInteger( rec
, 8 );
2022 if (attr
& msidbControlAttributesHasBorder
)
2023 style
|= BS_GROUPBOX
;
2025 style
|= BS_OWNERDRAW
;
2027 /* Create parent group box to hold radio buttons */
2028 control
= msi_dialog_add_control( dialog
, rec
, szButton
, style
);
2030 return ERROR_FUNCTION_FAILED
;
2032 oldproc
= (WNDPROC
) SetWindowLongPtrW( control
->hwnd
, GWLP_WNDPROC
,
2033 (LONG_PTR
)MSIRadioGroup_WndProc
);
2034 SetPropW(control
->hwnd
, szButtonData
, oldproc
);
2035 SetWindowLongPtrW( control
->hwnd
, GWL_EXSTYLE
, WS_EX_CONTROLPARENT
);
2038 control
->property
= strdupW( prop
);
2040 /* query the Radio Button table for all control in this group */
2041 r
= MSI_OpenQuery( package
->db
, &view
, query
, prop
);
2042 if( r
!= ERROR_SUCCESS
)
2044 ERR("query failed for dialog %s radio group %s\n",
2045 debugstr_w(dialog
->name
), debugstr_w(prop
));
2046 return ERROR_INVALID_PARAMETER
;
2049 group
.dialog
= dialog
;
2050 group
.parent
= control
;
2051 group
.attributes
= MSI_RecordGetInteger( rec
, 8 );
2052 group
.propval
= msi_dup_property( dialog
->package
->db
, control
->property
);
2054 r
= MSI_IterateRecords( view
, 0, msi_dialog_create_radiobutton
, &group
);
2055 msiobj_release( &view
->hdr
);
2056 msi_free( group
.propval
);
2061 /******************** Selection Tree ***************************************/
2063 struct msi_selection_tree_info
2072 msi_seltree_sync_item_state( HWND hwnd
, MSIFEATURE
*feature
, HTREEITEM hItem
)
2075 DWORD index
= feature
->Action
;
2077 TRACE("Feature %s -> %d %d %d\n", debugstr_w(feature
->Title
),
2078 feature
->Installed
, feature
->Action
, feature
->ActionRequest
);
2080 if (index
== INSTALLSTATE_UNKNOWN
)
2081 index
= INSTALLSTATE_ABSENT
;
2083 tvi
.mask
= TVIF_STATE
;
2085 tvi
.state
= INDEXTOSTATEIMAGEMASK( index
);
2086 tvi
.stateMask
= TVIS_STATEIMAGEMASK
;
2088 SendMessageW( hwnd
, TVM_SETITEMW
, 0, (LPARAM
) &tvi
);
2092 msi_seltree_popup_menu( HWND hwnd
, INT x
, INT y
)
2097 /* create a menu to display */
2098 hMenu
= CreatePopupMenu();
2100 /* FIXME: load strings from resources */
2101 AppendMenuA( hMenu
, MF_ENABLED
, INSTALLSTATE_LOCAL
, "Install feature locally");
2102 AppendMenuA( hMenu
, MF_ENABLED
, USER_INSTALLSTATE_ALL
, "Install entire feature");
2103 AppendMenuA( hMenu
, MF_ENABLED
, INSTALLSTATE_ADVERTISED
, "Install on demand");
2104 AppendMenuA( hMenu
, MF_ENABLED
, INSTALLSTATE_ABSENT
, "Don't install");
2105 r
= TrackPopupMenu( hMenu
, TPM_LEFTALIGN
| TPM_TOPALIGN
| TPM_RETURNCMD
,
2106 x
, y
, 0, hwnd
, NULL
);
2107 DestroyMenu( hMenu
);
2112 msi_seltree_feature_from_item( HWND hwnd
, HTREEITEM hItem
)
2116 /* get the feature from the item */
2117 memset( &tvi
, 0, sizeof tvi
);
2119 tvi
.mask
= TVIF_PARAM
| TVIF_HANDLE
;
2120 SendMessageW( hwnd
, TVM_GETITEMW
, 0, (LPARAM
) &tvi
);
2122 return (MSIFEATURE
*) tvi
.lParam
;
2126 msi_seltree_update_feature_installstate( HWND hwnd
, HTREEITEM hItem
,
2127 MSIPACKAGE
*package
, MSIFEATURE
*feature
, INSTALLSTATE state
)
2129 msi_feature_set_state( package
, feature
, state
);
2130 msi_seltree_sync_item_state( hwnd
, feature
, hItem
);
2131 ACTION_UpdateComponentStates( package
, feature
->Feature
);
2135 msi_seltree_update_siblings_and_children_installstate( HWND hwnd
, HTREEITEM curr
,
2136 MSIPACKAGE
*package
, INSTALLSTATE state
)
2138 /* update all siblings */
2141 MSIFEATURE
*feature
;
2144 feature
= msi_seltree_feature_from_item( hwnd
, curr
);
2145 msi_seltree_update_feature_installstate( hwnd
, curr
, package
, feature
, state
);
2147 /* update this sibling's children */
2148 child
= (HTREEITEM
)SendMessageW( hwnd
, TVM_GETNEXTITEM
, (WPARAM
)TVGN_CHILD
, (LPARAM
)curr
);
2150 msi_seltree_update_siblings_and_children_installstate( hwnd
, child
,
2153 while ((curr
= (HTREEITEM
)SendMessageW( hwnd
, TVM_GETNEXTITEM
, (WPARAM
)TVGN_NEXT
, (LPARAM
)curr
)));
2157 msi_seltree_menu( HWND hwnd
, HTREEITEM hItem
)
2159 struct msi_selection_tree_info
*info
;
2160 MSIFEATURE
*feature
;
2161 MSIPACKAGE
*package
;
2169 info
= GetPropW(hwnd
, szButtonData
);
2170 package
= info
->dialog
->package
;
2172 feature
= msi_seltree_feature_from_item( hwnd
, hItem
);
2175 ERR("item %p feature was NULL\n", hItem
);
2179 /* get the item's rectangle to put the menu just below it */
2181 SendMessageW( hwnd
, TVM_GETITEMRECT
, 0, (LPARAM
) &u
.rc
);
2182 MapWindowPoints( hwnd
, NULL
, u
.pt
, 2 );
2184 r
= msi_seltree_popup_menu( hwnd
, u
.rc
.left
, u
.rc
.top
);
2188 case USER_INSTALLSTATE_ALL
:
2189 r
= INSTALLSTATE_LOCAL
;
2191 case INSTALLSTATE_ADVERTISED
:
2192 case INSTALLSTATE_ABSENT
:
2195 child
= (HTREEITEM
)SendMessageW( hwnd
, TVM_GETNEXTITEM
, (WPARAM
)TVGN_CHILD
, (LPARAM
)hItem
);
2197 msi_seltree_update_siblings_and_children_installstate( hwnd
, child
, package
, r
);
2200 case INSTALLSTATE_LOCAL
:
2201 msi_seltree_update_feature_installstate( hwnd
, hItem
, package
, feature
, r
);
2208 static MSIFEATURE
*msi_seltree_get_selected_feature( msi_control
*control
)
2210 struct msi_selection_tree_info
*info
= GetPropW(control
->hwnd
, szButtonData
);
2211 return msi_seltree_feature_from_item( control
->hwnd
, info
->selected
);
2214 static LRESULT WINAPI
2215 MSISelectionTree_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
2217 struct msi_selection_tree_info
*info
;
2218 TVHITTESTINFO tvhti
;
2221 TRACE("%p %04x %08lx %08lx\n", hWnd
, msg
, wParam
, lParam
);
2223 info
= GetPropW(hWnd
, szButtonData
);
2227 case WM_LBUTTONDOWN
:
2228 tvhti
.pt
.x
= (short)LOWORD( lParam
);
2229 tvhti
.pt
.y
= (short)HIWORD( lParam
);
2232 r
= CallWindowProcW(info
->oldproc
, hWnd
, TVM_HITTEST
, 0, (LPARAM
) &tvhti
);
2233 if (tvhti
.flags
& TVHT_ONITEMSTATEICON
)
2234 return msi_seltree_menu( hWnd
, tvhti
.hItem
);
2238 r
= CallWindowProcW(info
->oldproc
, hWnd
, msg
, wParam
, lParam
);
2244 RemovePropW( hWnd
, szButtonData
);
2251 msi_seltree_add_child_features( MSIPACKAGE
*package
, HWND hwnd
,
2252 LPCWSTR parent
, HTREEITEM hParent
)
2254 struct msi_selection_tree_info
*info
= GetPropW( hwnd
, szButtonData
);
2255 MSIFEATURE
*feature
;
2256 TVINSERTSTRUCTW tvis
;
2257 HTREEITEM hitem
, hfirst
= NULL
;
2259 LIST_FOR_EACH_ENTRY( feature
, &package
->features
, MSIFEATURE
, entry
)
2261 if ( parent
&& feature
->Feature_Parent
&& strcmpW( parent
, feature
->Feature_Parent
))
2263 else if ( parent
&& !feature
->Feature_Parent
)
2265 else if ( !parent
&& feature
->Feature_Parent
)
2268 if ( !feature
->Title
)
2271 if ( !feature
->Display
)
2274 memset( &tvis
, 0, sizeof tvis
);
2275 tvis
.hParent
= hParent
;
2276 tvis
.hInsertAfter
= TVI_LAST
;
2277 tvis
.u
.item
.mask
= TVIF_TEXT
| TVIF_PARAM
;
2278 tvis
.u
.item
.pszText
= feature
->Title
;
2279 tvis
.u
.item
.lParam
= (LPARAM
) feature
;
2281 hitem
= (HTREEITEM
) SendMessageW( hwnd
, TVM_INSERTITEMW
, 0, (LPARAM
) &tvis
);
2288 msi_seltree_sync_item_state( hwnd
, feature
, hitem
);
2289 msi_seltree_add_child_features( package
, hwnd
,
2290 feature
->Feature
, hitem
);
2292 /* the node is expanded if Display is odd */
2293 if ( feature
->Display
% 2 != 0 )
2294 SendMessageW( hwnd
, TVM_EXPAND
, TVE_EXPAND
, (LPARAM
) hitem
);
2297 /* select the first item */
2298 SendMessageW( hwnd
, TVM_SELECTITEM
, TVGN_CARET
| TVGN_DROPHILITE
, (LPARAM
) hfirst
);
2299 info
->selected
= hfirst
;
2302 static void msi_seltree_create_imagelist( HWND hwnd
)
2304 const int bm_width
= 32, bm_height
= 16, bm_count
= 3;
2305 const int bm_resource
= 0x1001;
2310 himl
= ImageList_Create( bm_width
, bm_height
, FALSE
, 4, 0 );
2313 ERR("failed to create image list\n");
2317 for (i
=0; i
<bm_count
; i
++)
2319 hbmp
= LoadBitmapW( msi_hInstance
, MAKEINTRESOURCEW(i
+bm_resource
) );
2322 ERR("failed to load bitmap %d\n", i
);
2327 * Add a dummy bitmap at offset zero because the treeview
2328 * can't use it as a state mask (zero means no user state).
2331 ImageList_Add( himl
, hbmp
, NULL
);
2333 ImageList_Add( himl
, hbmp
, NULL
);
2336 SendMessageW( hwnd
, TVM_SETIMAGELIST
, TVSIL_STATE
, (LPARAM
)himl
);
2339 static UINT
msi_dialog_seltree_handler( msi_dialog
*dialog
,
2340 msi_control
*control
, WPARAM param
)
2342 struct msi_selection_tree_info
*info
= GetPropW( control
->hwnd
, szButtonData
);
2343 LPNMTREEVIEWW tv
= (LPNMTREEVIEWW
)param
;
2344 MSIRECORD
*row
, *rec
;
2346 MSIFEATURE
*feature
;
2347 LPCWSTR dir
, title
= NULL
;
2348 UINT r
= ERROR_SUCCESS
;
2350 static const WCHAR select
[] = {
2351 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2352 '`','F','e','a','t','u','r','e','`',' ','W','H','E','R','E',' ',
2353 '`','T','i','t','l','e','`',' ','=',' ','\'','%','s','\'',0
2356 if (tv
->hdr
.code
!= TVN_SELCHANGINGW
)
2357 return ERROR_SUCCESS
;
2359 info
->selected
= tv
->itemNew
.hItem
;
2361 if (!(tv
->itemNew
.mask
& TVIF_TEXT
))
2363 feature
= msi_seltree_feature_from_item( control
->hwnd
, tv
->itemNew
.hItem
);
2365 title
= feature
->Title
;
2368 title
= tv
->itemNew
.pszText
;
2370 row
= MSI_QueryGetRecord( dialog
->package
->db
, select
, title
);
2372 return ERROR_FUNCTION_FAILED
;
2374 rec
= MSI_CreateRecord( 1 );
2376 MSI_RecordSetStringW( rec
, 1, MSI_RecordGetString( row
, 4 ) );
2377 ControlEvent_FireSubscribedEvent( dialog
->package
, szSelectionDescription
, rec
);
2379 dir
= MSI_RecordGetString( row
, 7 );
2382 folder
= get_loaded_folder( dialog
->package
, dir
);
2385 r
= ERROR_FUNCTION_FAILED
;
2388 MSI_RecordSetStringW( rec
, 1, folder
->ResolvedTarget
);
2391 MSI_RecordSetStringW( rec
, 1, NULL
);
2393 ControlEvent_FireSubscribedEvent( dialog
->package
, szSelectionPath
, rec
);
2396 msiobj_release(&row
->hdr
);
2397 msiobj_release(&rec
->hdr
);
2402 static UINT
msi_dialog_selection_tree( msi_dialog
*dialog
, MSIRECORD
*rec
)
2404 msi_control
*control
;
2405 LPCWSTR prop
, control_name
;
2406 MSIPACKAGE
*package
= dialog
->package
;
2408 struct msi_selection_tree_info
*info
;
2410 info
= msi_alloc( sizeof *info
);
2412 return ERROR_FUNCTION_FAILED
;
2414 /* create the treeview control */
2415 style
= TVS_HASLINES
| TVS_HASBUTTONS
| TVS_LINESATROOT
;
2416 style
|= WS_GROUP
| WS_VSCROLL
;
2417 control
= msi_dialog_add_control( dialog
, rec
, WC_TREEVIEWW
, style
);
2421 return ERROR_FUNCTION_FAILED
;
2424 control
->handler
= msi_dialog_seltree_handler
;
2425 control_name
= MSI_RecordGetString( rec
, 2 );
2426 control
->attributes
= MSI_RecordGetInteger( rec
, 8 );
2427 prop
= MSI_RecordGetString( rec
, 9 );
2428 control
->property
= msi_dialog_dup_property( dialog
, prop
, FALSE
);
2431 info
->dialog
= dialog
;
2432 info
->hwnd
= control
->hwnd
;
2433 info
->oldproc
= (WNDPROC
) SetWindowLongPtrW( control
->hwnd
, GWLP_WNDPROC
,
2434 (LONG_PTR
)MSISelectionTree_WndProc
);
2435 SetPropW( control
->hwnd
, szButtonData
, info
);
2437 ControlEvent_SubscribeToEvent( dialog
->package
, dialog
,
2438 szSelectionPath
, control_name
, szProperty
);
2441 msi_seltree_create_imagelist( control
->hwnd
);
2442 msi_seltree_add_child_features( package
, control
->hwnd
, NULL
, NULL
);
2444 return ERROR_SUCCESS
;
2447 /******************** Group Box ***************************************/
2449 static UINT
msi_dialog_group_box( msi_dialog
*dialog
, MSIRECORD
*rec
)
2451 msi_control
*control
;
2454 style
= BS_GROUPBOX
| WS_CHILD
| WS_GROUP
;
2455 control
= msi_dialog_add_control( dialog
, rec
, WC_BUTTONW
, style
);
2457 return ERROR_FUNCTION_FAILED
;
2459 return ERROR_SUCCESS
;
2462 /******************** List Box ***************************************/
2464 struct msi_listbox_info
2474 static LRESULT WINAPI
MSIListBox_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
2476 struct msi_listbox_info
*info
;
2480 TRACE("%p %04x %08lx %08lx\n", hWnd
, msg
, wParam
, lParam
);
2482 info
= GetPropW( hWnd
, szButtonData
);
2486 r
= CallWindowProcW( info
->oldproc
, hWnd
, msg
, wParam
, lParam
);
2491 for (j
= 0; j
< info
->num_items
; j
++)
2492 msi_free( info
->items
[j
] );
2493 msi_free( info
->items
);
2495 RemovePropW( hWnd
, szButtonData
);
2502 static UINT
msi_listbox_add_item( MSIRECORD
*rec
, LPVOID param
)
2504 struct msi_listbox_info
*info
= param
;
2505 LPCWSTR value
, text
;
2508 value
= MSI_RecordGetString( rec
, 3 );
2509 text
= MSI_RecordGetString( rec
, 4 );
2511 info
->items
[info
->addpos_items
] = strdupW( value
);
2513 pos
= SendMessageW( info
->hwnd
, LB_ADDSTRING
, 0, (LPARAM
)text
);
2514 SendMessageW( info
->hwnd
, LB_SETITEMDATA
, pos
, (LPARAM
)info
->items
[info
->addpos_items
] );
2515 info
->addpos_items
++;
2516 return ERROR_SUCCESS
;
2519 static UINT
msi_listbox_add_items( struct msi_listbox_info
*info
, LPCWSTR property
)
2522 MSIQUERY
*view
= NULL
;
2525 static const WCHAR query
[] = {
2526 'S','E','L','E','C','T',' ','*',' ',
2527 'F','R','O','M',' ','`','L','i','s','t','B','o','x','`',' ',
2528 'W','H','E','R','E',' ',
2529 '`','P','r','o','p','e','r','t','y','`',' ','=',' ','\'','%','s','\'',' ',
2530 'O','R','D','E','R',' ','B','Y',' ','`','O','r','d','e','r','`',0
2533 r
= MSI_OpenQuery( info
->dialog
->package
->db
, &view
, query
, property
);
2534 if ( r
!= ERROR_SUCCESS
)
2537 /* just get the number of records */
2539 r
= MSI_IterateRecords( view
, &count
, NULL
, NULL
);
2541 info
->num_items
= count
;
2542 info
->items
= msi_alloc( sizeof(*info
->items
) * count
);
2544 r
= MSI_IterateRecords( view
, NULL
, msi_listbox_add_item
, info
);
2545 msiobj_release( &view
->hdr
);
2550 static UINT
msi_dialog_listbox_handler( msi_dialog
*dialog
,
2551 msi_control
*control
, WPARAM param
)
2553 struct msi_listbox_info
*info
;
2557 if( HIWORD(param
) != LBN_SELCHANGE
)
2558 return ERROR_SUCCESS
;
2560 info
= GetPropW( control
->hwnd
, szButtonData
);
2561 index
= SendMessageW( control
->hwnd
, LB_GETCURSEL
, 0, 0 );
2562 value
= (LPCWSTR
) SendMessageW( control
->hwnd
, LB_GETITEMDATA
, index
, 0 );
2564 msi_dialog_set_property( info
->dialog
->package
, control
->property
, value
);
2565 msi_dialog_evaluate_control_conditions( info
->dialog
);
2567 return ERROR_SUCCESS
;
2570 static UINT
msi_dialog_list_box( msi_dialog
*dialog
, MSIRECORD
*rec
)
2572 struct msi_listbox_info
*info
;
2573 msi_control
*control
;
2574 DWORD attributes
, style
;
2577 info
= msi_alloc( sizeof *info
);
2579 return ERROR_FUNCTION_FAILED
;
2581 style
= WS_TABSTOP
| WS_GROUP
| WS_CHILD
| LBS_NOTIFY
| WS_VSCROLL
| WS_BORDER
;
2582 attributes
= MSI_RecordGetInteger( rec
, 8 );
2583 if (~attributes
& msidbControlAttributesSorted
)
2586 control
= msi_dialog_add_control( dialog
, rec
, WC_LISTBOXW
, style
);
2590 return ERROR_FUNCTION_FAILED
;
2593 control
->handler
= msi_dialog_listbox_handler
;
2595 prop
= MSI_RecordGetString( rec
, 9 );
2596 control
->property
= msi_dialog_dup_property( dialog
, prop
, FALSE
);
2599 info
->dialog
= dialog
;
2600 info
->hwnd
= control
->hwnd
;
2602 info
->addpos_items
= 0;
2603 info
->oldproc
= (WNDPROC
)SetWindowLongPtrW( control
->hwnd
, GWLP_WNDPROC
,
2604 (LONG_PTR
)MSIListBox_WndProc
);
2605 SetPropW( control
->hwnd
, szButtonData
, info
);
2607 if ( control
->property
)
2608 msi_listbox_add_items( info
, control
->property
);
2610 return ERROR_SUCCESS
;
2613 /******************** Directory Combo ***************************************/
2615 static void msi_dialog_update_directory_combo( msi_dialog
*dialog
, msi_control
*control
)
2620 if (!control
&& !(control
= msi_dialog_find_control_by_type( dialog
, szDirectoryCombo
)))
2623 indirect
= control
->attributes
& msidbControlAttributesIndirect
;
2624 prop
= msi_dialog_dup_property( dialog
, control
->property
, indirect
);
2625 path
= msi_dialog_dup_property( dialog
, prop
, TRUE
);
2627 PathStripPathW( path
);
2628 PathRemoveBackslashW( path
);
2630 SendMessageW( control
->hwnd
, CB_INSERTSTRING
, 0, (LPARAM
)path
);
2631 SendMessageW( control
->hwnd
, CB_SETCURSEL
, 0, 0 );
2637 static UINT
msi_dialog_directory_combo( msi_dialog
*dialog
, MSIRECORD
*rec
)
2639 msi_control
*control
;
2643 /* FIXME: use CBS_OWNERDRAWFIXED and add owner draw code */
2644 style
= CBS_DROPDOWNLIST
| CBS_HASSTRINGS
| WS_CHILD
|
2645 WS_GROUP
| WS_TABSTOP
| WS_VSCROLL
;
2646 control
= msi_dialog_add_control( dialog
, rec
, WC_COMBOBOXW
, style
);
2648 return ERROR_FUNCTION_FAILED
;
2650 control
->attributes
= MSI_RecordGetInteger( rec
, 8 );
2651 prop
= MSI_RecordGetString( rec
, 9 );
2652 control
->property
= msi_dialog_dup_property( dialog
, prop
, FALSE
);
2654 msi_dialog_update_directory_combo( dialog
, control
);
2656 return ERROR_SUCCESS
;
2659 /******************** Directory List ***************************************/
2661 static void msi_dialog_update_directory_list( msi_dialog
*dialog
, msi_control
*control
)
2663 WCHAR dir_spec
[MAX_PATH
];
2664 WIN32_FIND_DATAW wfd
;
2670 static const WCHAR asterisk
[] = {'*',0};
2672 if (!control
&& !(control
= msi_dialog_find_control_by_type( dialog
, szDirectoryList
)))
2675 /* clear the list-view */
2676 SendMessageW( control
->hwnd
, LVM_DELETEALLITEMS
, 0, 0 );
2678 indirect
= control
->attributes
& msidbControlAttributesIndirect
;
2679 prop
= msi_dialog_dup_property( dialog
, control
->property
, indirect
);
2680 path
= msi_dialog_dup_property( dialog
, prop
, TRUE
);
2682 lstrcpyW( dir_spec
, path
);
2683 lstrcatW( dir_spec
, asterisk
);
2685 file
= FindFirstFileW( dir_spec
, &wfd
);
2686 if ( file
== INVALID_HANDLE_VALUE
)
2691 if ( wfd
.dwFileAttributes
!= FILE_ATTRIBUTE_DIRECTORY
)
2694 if ( !strcmpW( wfd
.cFileName
, szDot
) || !strcmpW( wfd
.cFileName
, szDotDot
) )
2697 item
.mask
= LVIF_TEXT
;
2698 item
.cchTextMax
= MAX_PATH
;
2701 item
.pszText
= wfd
.cFileName
;
2703 SendMessageW( control
->hwnd
, LVM_INSERTITEMW
, 0, (LPARAM
)&item
);
2704 } while ( FindNextFileW( file
, &wfd
) );
2711 UINT
msi_dialog_directorylist_up( msi_dialog
*dialog
)
2713 msi_control
*control
;
2714 LPWSTR prop
, path
, ptr
;
2717 control
= msi_dialog_find_control_by_type( dialog
, szDirectoryList
);
2718 indirect
= control
->attributes
& msidbControlAttributesIndirect
;
2719 prop
= msi_dialog_dup_property( dialog
, control
->property
, indirect
);
2720 path
= msi_dialog_dup_property( dialog
, prop
, TRUE
);
2722 /* strip off the last directory */
2723 ptr
= PathFindFileNameW( path
);
2724 if (ptr
!= path
) *(ptr
- 1) = '\0';
2725 PathAddBackslashW( path
);
2727 msi_dialog_set_property( dialog
->package
, prop
, path
);
2729 msi_dialog_update_directory_list( dialog
, NULL
);
2730 msi_dialog_update_directory_combo( dialog
, NULL
);
2731 msi_dialog_update_pathedit( dialog
, NULL
);
2736 return ERROR_SUCCESS
;
2739 static UINT
msi_dialog_dirlist_handler( msi_dialog
*dialog
,
2740 msi_control
*control
, WPARAM param
)
2742 LPNMHDR nmhdr
= (LPNMHDR
)param
;
2743 WCHAR new_path
[MAX_PATH
];
2744 WCHAR text
[MAX_PATH
];
2750 if (nmhdr
->code
!= LVN_ITEMACTIVATE
)
2751 return ERROR_SUCCESS
;
2753 index
= SendMessageW( control
->hwnd
, LVM_GETNEXTITEM
, -1, LVNI_SELECTED
);
2756 ERR("No list-view item selected!\n");
2757 return ERROR_FUNCTION_FAILED
;
2761 item
.pszText
= text
;
2762 item
.cchTextMax
= MAX_PATH
;
2763 SendMessageW( control
->hwnd
, LVM_GETITEMTEXTW
, index
, (LPARAM
)&item
);
2765 indirect
= control
->attributes
& msidbControlAttributesIndirect
;
2766 prop
= msi_dialog_dup_property( dialog
, control
->property
, indirect
);
2767 path
= msi_dialog_dup_property( dialog
, prop
, TRUE
);
2769 lstrcpyW( new_path
, path
);
2770 lstrcatW( new_path
, text
);
2771 lstrcatW( new_path
, szBackSlash
);
2773 msi_dialog_set_property( dialog
->package
, prop
, new_path
);
2775 msi_dialog_update_directory_list( dialog
, NULL
);
2776 msi_dialog_update_directory_combo( dialog
, NULL
);
2777 msi_dialog_update_pathedit( dialog
, NULL
);
2781 return ERROR_SUCCESS
;
2784 static UINT
msi_dialog_directory_list( msi_dialog
*dialog
, MSIRECORD
*rec
)
2786 msi_control
*control
;
2790 style
= LVS_LIST
| WS_VSCROLL
| LVS_SHAREIMAGELISTS
|
2791 LVS_AUTOARRANGE
| LVS_SINGLESEL
| WS_BORDER
|
2792 LVS_SORTASCENDING
| WS_CHILD
| WS_GROUP
| WS_TABSTOP
;
2793 control
= msi_dialog_add_control( dialog
, rec
, WC_LISTVIEWW
, style
);
2795 return ERROR_FUNCTION_FAILED
;
2797 control
->attributes
= MSI_RecordGetInteger( rec
, 8 );
2798 control
->handler
= msi_dialog_dirlist_handler
;
2799 prop
= MSI_RecordGetString( rec
, 9 );
2800 control
->property
= msi_dialog_dup_property( dialog
, prop
, FALSE
);
2802 /* double click to activate an item in the list */
2803 SendMessageW( control
->hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
,
2804 0, LVS_EX_TWOCLICKACTIVATE
);
2806 msi_dialog_update_directory_list( dialog
, control
);
2808 return ERROR_SUCCESS
;
2811 /******************** VolumeCost List ***************************************/
2813 static BOOL
str_is_number( LPCWSTR str
)
2817 for (i
= 0; i
< lstrlenW( str
); i
++)
2818 if (!isdigitW(str
[i
]))
2824 static const WCHAR column_keys
[][80] =
2826 {'V','o','l','u','m','e','C','o','s','t','V','o','l','u','m','e',0},
2827 {'V','o','l','u','m','e','C','o','s','t','S','i','z','e',0},
2828 {'V','o','l','u','m','e','C','o','s','t','A','v','a','i','l','a','b','l','e',0},
2829 {'V','o','l','u','m','e','C','o','s','t','R','e','q','u','i','r','e','d',0},
2830 {'V','o','l','u','m','e','C','o','s','t','D','i','f','f','e','r','e','n','c','e',0}
2833 static void msi_dialog_vcl_add_columns( msi_dialog
*dialog
, msi_control
*control
, MSIRECORD
*rec
)
2835 LPCWSTR text
= MSI_RecordGetString( rec
, 10 );
2836 LPCWSTR begin
= text
, end
;
2841 static const WCHAR negative
[] = {'-',0};
2845 while ((begin
= strchrW( begin
, '{' )) && count
< 5)
2847 if (!(end
= strchrW( begin
, '}' )))
2850 num
= msi_alloc( (end
-begin
+1)*sizeof(WCHAR
) );
2854 lstrcpynW( num
, begin
+ 1, end
- begin
);
2855 begin
+= end
- begin
+ 1;
2857 /* empty braces or '0' hides the column */
2858 if ( !num
[0] || !strcmpW( num
, szZero
) )
2865 /* the width must be a positive number
2866 * if a width is invalid, all remaining columns are hidden
2868 if ( !strncmpW( num
, negative
, 1 ) || !str_is_number( num
) ) {
2873 ZeroMemory( &lvc
, sizeof(lvc
) );
2874 lvc
.mask
= LVCF_TEXT
| LVCF_WIDTH
| LVCF_SUBITEM
;
2875 lvc
.cx
= atolW( num
);
2876 lvc
.pszText
= msi_dialog_get_uitext( dialog
, column_keys
[count
] );
2878 SendMessageW( control
->hwnd
, LVM_INSERTCOLUMNW
, count
++, (LPARAM
)&lvc
);
2879 msi_free( lvc
.pszText
);
2884 static LONGLONG
msi_vcl_get_cost( msi_dialog
*dialog
)
2886 MSIFEATURE
*feature
;
2888 LONGLONG total_cost
= 0;
2890 LIST_FOR_EACH_ENTRY( feature
, &dialog
->package
->features
, MSIFEATURE
, entry
)
2892 if (ERROR_SUCCESS
== (MSI_GetFeatureCost(dialog
->package
, feature
,
2893 MSICOSTTREE_SELFONLY
, INSTALLSTATE_LOCAL
, &each_cost
)))
2895 /* each_cost is in 512-byte units */
2896 total_cost
+= each_cost
* 512;
2898 if (ERROR_SUCCESS
== (MSI_GetFeatureCost(dialog
->package
, feature
,
2899 MSICOSTTREE_SELFONLY
, INSTALLSTATE_ABSENT
, &each_cost
)))
2901 /* each_cost is in 512-byte units */
2902 total_cost
-= each_cost
* 512;
2908 static void msi_dialog_vcl_add_drives( msi_dialog
*dialog
, msi_control
*control
)
2910 ULARGE_INTEGER total
, free
;
2911 LONGLONG difference
, cost
;
2912 WCHAR size_text
[MAX_PATH
];
2913 WCHAR cost_text
[MAX_PATH
];
2919 cost
= msi_vcl_get_cost(dialog
);
2920 StrFormatByteSizeW(cost
, cost_text
, MAX_PATH
);
2922 size
= GetLogicalDriveStringsW( 0, NULL
);
2923 if ( !size
) return;
2925 drives
= msi_alloc( (size
+ 1) * sizeof(WCHAR
) );
2926 if ( !drives
) return;
2928 GetLogicalDriveStringsW( size
, drives
);
2933 lvitem
.mask
= LVIF_TEXT
;
2935 lvitem
.iSubItem
= 0;
2936 lvitem
.pszText
= ptr
;
2937 lvitem
.cchTextMax
= lstrlenW(ptr
) + 1;
2938 SendMessageW( control
->hwnd
, LVM_INSERTITEMW
, 0, (LPARAM
)&lvitem
);
2940 GetDiskFreeSpaceExW(ptr
, &free
, &total
, NULL
);
2941 difference
= free
.QuadPart
- cost
;
2943 StrFormatByteSizeW(total
.QuadPart
, size_text
, MAX_PATH
);
2944 lvitem
.iSubItem
= 1;
2945 lvitem
.pszText
= size_text
;
2946 lvitem
.cchTextMax
= lstrlenW(size_text
) + 1;
2947 SendMessageW( control
->hwnd
, LVM_SETITEMW
, 0, (LPARAM
)&lvitem
);
2949 StrFormatByteSizeW(free
.QuadPart
, size_text
, MAX_PATH
);
2950 lvitem
.iSubItem
= 2;
2951 lvitem
.pszText
= size_text
;
2952 lvitem
.cchTextMax
= lstrlenW(size_text
) + 1;
2953 SendMessageW( control
->hwnd
, LVM_SETITEMW
, 0, (LPARAM
)&lvitem
);
2955 lvitem
.iSubItem
= 3;
2956 lvitem
.pszText
= cost_text
;
2957 lvitem
.cchTextMax
= lstrlenW(cost_text
) + 1;
2958 SendMessageW( control
->hwnd
, LVM_SETITEMW
, 0, (LPARAM
)&lvitem
);
2960 StrFormatByteSizeW(difference
, size_text
, MAX_PATH
);
2961 lvitem
.iSubItem
= 4;
2962 lvitem
.pszText
= size_text
;
2963 lvitem
.cchTextMax
= lstrlenW(size_text
) + 1;
2964 SendMessageW( control
->hwnd
, LVM_SETITEMW
, 0, (LPARAM
)&lvitem
);
2966 ptr
+= lstrlenW(ptr
) + 1;
2973 static UINT
msi_dialog_volumecost_list( msi_dialog
*dialog
, MSIRECORD
*rec
)
2975 msi_control
*control
;
2978 style
= LVS_REPORT
| WS_VSCROLL
| WS_HSCROLL
| LVS_SHAREIMAGELISTS
|
2979 LVS_AUTOARRANGE
| LVS_SINGLESEL
| WS_BORDER
|
2980 WS_CHILD
| WS_TABSTOP
| WS_GROUP
;
2981 control
= msi_dialog_add_control( dialog
, rec
, WC_LISTVIEWW
, style
);
2983 return ERROR_FUNCTION_FAILED
;
2985 msi_dialog_vcl_add_columns( dialog
, control
, rec
);
2986 msi_dialog_vcl_add_drives( dialog
, control
);
2988 return ERROR_SUCCESS
;
2991 /******************** VolumeSelect Combo ***************************************/
2993 static UINT
msi_dialog_volsel_handler( msi_dialog
*dialog
,
2994 msi_control
*control
, WPARAM param
)
2996 WCHAR text
[MAX_PATH
];
3001 if (HIWORD(param
) != CBN_SELCHANGE
)
3002 return ERROR_SUCCESS
;
3004 index
= SendMessageW( control
->hwnd
, CB_GETCURSEL
, 0, 0 );
3005 if ( index
== CB_ERR
)
3007 ERR("No ComboBox item selected!\n");
3008 return ERROR_FUNCTION_FAILED
;
3011 SendMessageW( control
->hwnd
, CB_GETLBTEXT
, index
, (LPARAM
)text
);
3013 indirect
= control
->attributes
& msidbControlAttributesIndirect
;
3014 prop
= msi_dialog_dup_property( dialog
, control
->property
, indirect
);
3016 msi_dialog_set_property( dialog
->package
, prop
, text
);
3019 return ERROR_SUCCESS
;
3022 static void msi_dialog_vsc_add_drives( msi_dialog
*dialog
, msi_control
*control
)
3027 size
= GetLogicalDriveStringsW( 0, NULL
);
3028 if ( !size
) return;
3030 drives
= msi_alloc( (size
+ 1) * sizeof(WCHAR
) );
3031 if ( !drives
) return;
3033 GetLogicalDriveStringsW( size
, drives
);
3038 SendMessageW( control
->hwnd
, CB_ADDSTRING
, 0, (LPARAM
)ptr
);
3039 ptr
+= lstrlenW(ptr
) + 1;
3045 static UINT
msi_dialog_volumeselect_combo( msi_dialog
*dialog
, MSIRECORD
*rec
)
3047 msi_control
*control
;
3051 /* FIXME: CBS_OWNERDRAWFIXED */
3052 style
= WS_CHILD
| WS_VISIBLE
| WS_GROUP
| WS_TABSTOP
|
3053 CBS_DROPDOWNLIST
| CBS_SORT
| CBS_HASSTRINGS
|
3054 WS_EX_LEFT
| WS_EX_LTRREADING
| WS_EX_RIGHTSCROLLBAR
;
3055 control
= msi_dialog_add_control( dialog
, rec
, WC_COMBOBOXW
, style
);
3057 return ERROR_FUNCTION_FAILED
;
3059 control
->attributes
= MSI_RecordGetInteger( rec
, 8 );
3060 control
->handler
= msi_dialog_volsel_handler
;
3061 prop
= MSI_RecordGetString( rec
, 9 );
3062 control
->property
= msi_dialog_dup_property( dialog
, prop
, FALSE
);
3064 msi_dialog_vsc_add_drives( dialog
, control
);
3066 return ERROR_SUCCESS
;
3069 static const struct control_handler msi_dialog_handler
[] =
3071 { szText
, msi_dialog_text_control
},
3072 { szPushButton
, msi_dialog_button_control
},
3073 { szLine
, msi_dialog_line_control
},
3074 { szBitmap
, msi_dialog_bitmap_control
},
3075 { szCheckBox
, msi_dialog_checkbox_control
},
3076 { szScrollableText
, msi_dialog_scrolltext_control
},
3077 { szComboBox
, msi_dialog_combo_control
},
3078 { szEdit
, msi_dialog_edit_control
},
3079 { szMaskedEdit
, msi_dialog_maskedit_control
},
3080 { szPathEdit
, msi_dialog_pathedit_control
},
3081 { szProgressBar
, msi_dialog_progress_bar
},
3082 { szRadioButtonGroup
, msi_dialog_radiogroup_control
},
3083 { szIcon
, msi_dialog_icon_control
},
3084 { szSelectionTree
, msi_dialog_selection_tree
},
3085 { szGroupBox
, msi_dialog_group_box
},
3086 { szListBox
, msi_dialog_list_box
},
3087 { szDirectoryCombo
, msi_dialog_directory_combo
},
3088 { szDirectoryList
, msi_dialog_directory_list
},
3089 { szVolumeCostList
, msi_dialog_volumecost_list
},
3090 { szVolumeSelectCombo
, msi_dialog_volumeselect_combo
},
3093 #define NUM_CONTROL_TYPES (sizeof msi_dialog_handler/sizeof msi_dialog_handler[0])
3095 static UINT
msi_dialog_create_controls( MSIRECORD
*rec
, LPVOID param
)
3097 msi_dialog
*dialog
= param
;
3098 LPCWSTR control_type
;
3101 /* find and call the function that can create this type of control */
3102 control_type
= MSI_RecordGetString( rec
, 3 );
3103 for( i
=0; i
<NUM_CONTROL_TYPES
; i
++ )
3104 if (!strcmpiW( msi_dialog_handler
[i
].control_type
, control_type
))
3106 if( i
!= NUM_CONTROL_TYPES
)
3107 msi_dialog_handler
[i
].func( dialog
, rec
);
3109 ERR("no handler for element type %s\n", debugstr_w(control_type
));
3111 return ERROR_SUCCESS
;
3114 static UINT
msi_dialog_fill_controls( msi_dialog
*dialog
)
3116 static const WCHAR query
[] = {
3117 'S','E','L','E','C','T',' ','*',' ',
3118 'F','R','O','M',' ','C','o','n','t','r','o','l',' ',
3119 'W','H','E','R','E',' ',
3120 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',0};
3122 MSIQUERY
*view
= NULL
;
3123 MSIPACKAGE
*package
= dialog
->package
;
3125 TRACE("%p %s\n", dialog
, debugstr_w(dialog
->name
) );
3127 /* query the Control table for all the elements of the control */
3128 r
= MSI_OpenQuery( package
->db
, &view
, query
, dialog
->name
);
3129 if( r
!= ERROR_SUCCESS
)
3131 ERR("query failed for dialog %s\n", debugstr_w(dialog
->name
));
3132 return ERROR_INVALID_PARAMETER
;
3135 r
= MSI_IterateRecords( view
, 0, msi_dialog_create_controls
, dialog
);
3136 msiobj_release( &view
->hdr
);
3141 static UINT
msi_dialog_set_control_condition( MSIRECORD
*rec
, LPVOID param
)
3143 static const WCHAR szHide
[] = { 'H','i','d','e',0 };
3144 static const WCHAR szShow
[] = { 'S','h','o','w',0 };
3145 static const WCHAR szDisable
[] = { 'D','i','s','a','b','l','e',0 };
3146 static const WCHAR szEnable
[] = { 'E','n','a','b','l','e',0 };
3147 static const WCHAR szDefault
[] = { 'D','e','f','a','u','l','t',0 };
3148 msi_dialog
*dialog
= param
;
3149 msi_control
*control
;
3150 LPCWSTR name
, action
, condition
;
3153 name
= MSI_RecordGetString( rec
, 2 );
3154 action
= MSI_RecordGetString( rec
, 3 );
3155 condition
= MSI_RecordGetString( rec
, 4 );
3156 r
= MSI_EvaluateConditionW( dialog
->package
, condition
);
3157 control
= msi_dialog_find_control( dialog
, name
);
3158 if( r
== MSICONDITION_TRUE
&& control
)
3160 TRACE("%s control %s\n", debugstr_w(action
), debugstr_w(name
));
3162 /* FIXME: case sensitive? */
3163 if (!strcmpW( action
, szHide
))
3164 ShowWindow(control
->hwnd
, SW_HIDE
);
3165 else if (!strcmpW( action
, szShow
))
3166 ShowWindow(control
->hwnd
, SW_SHOW
);
3167 else if (!strcmpW( action
, szDisable
))
3168 EnableWindow(control
->hwnd
, FALSE
);
3169 else if (!strcmpW( action
, szEnable
))
3170 EnableWindow(control
->hwnd
, TRUE
);
3171 else if (!strcmpW( action
, szDefault
))
3172 SetFocus(control
->hwnd
);
3174 FIXME("Unhandled action %s\n", debugstr_w(action
));
3177 return ERROR_SUCCESS
;
3180 static UINT
msi_dialog_evaluate_control_conditions( msi_dialog
*dialog
)
3182 static const WCHAR query
[] = {
3183 'S','E','L','E','C','T',' ','*',' ',
3184 'F','R','O','M',' ',
3185 'C','o','n','t','r','o','l','C','o','n','d','i','t','i','o','n',' ',
3186 'W','H','E','R','E',' ',
3187 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',0
3190 MSIQUERY
*view
= NULL
;
3191 MSIPACKAGE
*package
= dialog
->package
;
3193 TRACE("%p %s\n", dialog
, debugstr_w(dialog
->name
) );
3195 /* query the Control table for all the elements of the control */
3196 r
= MSI_OpenQuery( package
->db
, &view
, query
, dialog
->name
);
3197 if( r
!= ERROR_SUCCESS
)
3198 return ERROR_SUCCESS
;
3200 r
= MSI_IterateRecords( view
, 0, msi_dialog_set_control_condition
, dialog
);
3201 msiobj_release( &view
->hdr
);
3206 UINT
msi_dialog_reset( msi_dialog
*dialog
)
3208 /* FIXME: should restore the original values of any properties we changed */
3209 return msi_dialog_evaluate_control_conditions( dialog
);
3212 /* figure out the height of 10 point MS Sans Serif */
3213 static INT
msi_dialog_get_sans_serif_height( HWND hwnd
)
3215 static const WCHAR szSansSerif
[] = {
3216 'M','S',' ','S','a','n','s',' ','S','e','r','i','f',0 };
3221 HFONT hFont
, hOldFont
;
3224 hdc
= GetDC( hwnd
);
3227 memset( &lf
, 0, sizeof lf
);
3228 lf
.lfHeight
= MulDiv(12, GetDeviceCaps(hdc
, LOGPIXELSY
), 72);
3229 strcpyW( lf
.lfFaceName
, szSansSerif
);
3230 hFont
= CreateFontIndirectW(&lf
);
3233 hOldFont
= SelectObject( hdc
, hFont
);
3234 r
= GetTextMetricsW( hdc
, &tm
);
3236 height
= tm
.tmHeight
;
3237 SelectObject( hdc
, hOldFont
);
3238 DeleteObject( hFont
);
3240 ReleaseDC( hwnd
, hdc
);
3245 /* fetch the associated record from the Dialog table */
3246 static MSIRECORD
*msi_get_dialog_record( msi_dialog
*dialog
)
3248 static const WCHAR query
[] = {
3249 'S','E','L','E','C','T',' ','*',' ',
3250 'F','R','O','M',' ','D','i','a','l','o','g',' ',
3251 'W','H','E','R','E',' ',
3252 '`','D','i','a','l','o','g','`',' ','=',' ','\'','%','s','\'',0};
3253 MSIPACKAGE
*package
= dialog
->package
;
3254 MSIRECORD
*rec
= NULL
;
3256 TRACE("%p %s\n", dialog
, debugstr_w(dialog
->name
) );
3258 rec
= MSI_QueryGetRecord( package
->db
, query
, dialog
->name
);
3260 WARN("query failed for dialog %s\n", debugstr_w(dialog
->name
));
3265 static void msi_dialog_adjust_dialog_pos( msi_dialog
*dialog
, MSIRECORD
*rec
, LPRECT pos
)
3267 static const WCHAR szScreenX
[] = {'S','c','r','e','e','n','X',0};
3268 static const WCHAR szScreenY
[] = {'S','c','r','e','e','n','Y',0};
3275 center
.x
= MSI_RecordGetInteger( rec
, 2 );
3276 center
.y
= MSI_RecordGetInteger( rec
, 3 );
3278 sz
.cx
= MSI_RecordGetInteger( rec
, 4 );
3279 sz
.cy
= MSI_RecordGetInteger( rec
, 5 );
3281 sz
.cx
= msi_dialog_scale_unit( dialog
, sz
.cx
);
3282 sz
.cy
= msi_dialog_scale_unit( dialog
, sz
.cy
);
3284 xres
= msi_get_property_int( dialog
->package
->db
, szScreenX
, 0 );
3285 yres
= msi_get_property_int( dialog
->package
->db
, szScreenY
, 0 );
3287 center
.x
= MulDiv( center
.x
, xres
, 100 );
3288 center
.y
= MulDiv( center
.y
, yres
, 100 );
3290 /* turn the client pos into the window rectangle */
3291 if (dialog
->package
->center_x
&& dialog
->package
->center_y
)
3293 pos
->left
= dialog
->package
->center_x
- sz
.cx
/ 2.0;
3294 pos
->right
= pos
->left
+ sz
.cx
;
3295 pos
->top
= dialog
->package
->center_y
- sz
.cy
/ 2.0;
3296 pos
->bottom
= pos
->top
+ sz
.cy
;
3300 pos
->left
= center
.x
- sz
.cx
/2;
3301 pos
->right
= pos
->left
+ sz
.cx
;
3302 pos
->top
= center
.y
- sz
.cy
/2;
3303 pos
->bottom
= pos
->top
+ sz
.cy
;
3305 /* save the center */
3306 dialog
->package
->center_x
= center
.x
;
3307 dialog
->package
->center_y
= center
.y
;
3310 dialog
->size
.cx
= sz
.cx
;
3311 dialog
->size
.cy
= sz
.cy
;
3313 TRACE("%u %u %u %u\n", pos
->left
, pos
->top
, pos
->right
, pos
->bottom
);
3315 style
= GetWindowLongPtrW( dialog
->hwnd
, GWL_STYLE
);
3316 AdjustWindowRect( pos
, style
, FALSE
);
3319 static void msi_dialog_set_tab_order( msi_dialog
*dialog
, LPCWSTR first
)
3321 struct list tab_chain
;
3322 msi_control
*control
;
3323 HWND prev
= HWND_TOP
;
3325 list_init( &tab_chain
);
3326 if (!(control
= msi_dialog_find_control( dialog
, first
))) return;
3328 dialog
->hWndFocus
= control
->hwnd
;
3331 list_remove( &control
->entry
);
3332 list_add_tail( &tab_chain
, &control
->entry
);
3333 if (!control
->tabnext
) break;
3334 control
= msi_dialog_find_control( dialog
, control
->tabnext
);
3337 LIST_FOR_EACH_ENTRY( control
, &tab_chain
, msi_control
, entry
)
3339 SetWindowPos( control
->hwnd
, prev
, 0, 0, 0, 0,
3340 SWP_NOMOVE
| SWP_NOOWNERZORDER
| SWP_NOREDRAW
|
3341 SWP_NOREPOSITION
| SWP_NOSENDCHANGING
| SWP_NOSIZE
);
3342 prev
= control
->hwnd
;
3345 /* put them back on the main list */
3346 list_move_head( &dialog
->controls
, &tab_chain
);
3349 static LRESULT
msi_dialog_oncreate( HWND hwnd
, LPCREATESTRUCTW cs
)
3351 static const WCHAR df
[] = {
3352 'D','e','f','a','u','l','t','U','I','F','o','n','t',0 };
3353 static const WCHAR dfv
[] = {
3354 'M','S',' ','S','h','e','l','l',' ','D','l','g',0 };
3355 msi_dialog
*dialog
= cs
->lpCreateParams
;
3356 MSIRECORD
*rec
= NULL
;
3357 LPWSTR title
= NULL
;
3360 TRACE("%p %p\n", dialog
, dialog
->package
);
3362 dialog
->hwnd
= hwnd
;
3363 SetWindowLongPtrW( hwnd
, GWLP_USERDATA
, (LONG_PTR
) dialog
);
3365 rec
= msi_get_dialog_record( dialog
);
3368 TRACE("No record found for dialog %s\n", debugstr_w(dialog
->name
));
3372 dialog
->scale
= msi_dialog_get_sans_serif_height(dialog
->hwnd
);
3374 msi_dialog_adjust_dialog_pos( dialog
, rec
, &pos
);
3376 dialog
->attributes
= MSI_RecordGetInteger( rec
, 6 );
3378 dialog
->default_font
= msi_dup_property( dialog
->package
->db
, df
);
3379 if (!dialog
->default_font
)
3381 dialog
->default_font
= strdupW(dfv
);
3382 if (!dialog
->default_font
) return -1;
3385 title
= msi_get_deformatted_field( dialog
->package
, rec
, 7 );
3386 SetWindowTextW( hwnd
, title
);
3389 SetWindowPos( hwnd
, 0, pos
.left
, pos
.top
,
3390 pos
.right
- pos
.left
, pos
.bottom
- pos
.top
,
3391 SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_NOREDRAW
);
3393 msi_dialog_build_font_list( dialog
);
3394 msi_dialog_fill_controls( dialog
);
3395 msi_dialog_evaluate_control_conditions( dialog
);
3396 msi_dialog_set_tab_order( dialog
, MSI_RecordGetString( rec
, 8 ) );
3397 msiobj_release( &rec
->hdr
);
3402 static UINT
msi_dialog_send_event( msi_dialog
*dialog
, LPCWSTR event
, LPCWSTR arg
)
3404 LPWSTR event_fmt
= NULL
, arg_fmt
= NULL
;
3406 TRACE("Sending control event %s %s\n", debugstr_w(event
), debugstr_w(arg
));
3408 deformat_string( dialog
->package
, event
, &event_fmt
);
3409 deformat_string( dialog
->package
, arg
, &arg_fmt
);
3411 dialog
->event_handler( dialog
->package
, event_fmt
, arg_fmt
, dialog
);
3413 msi_free( event_fmt
);
3414 msi_free( arg_fmt
);
3416 return ERROR_SUCCESS
;
3419 static UINT
msi_dialog_set_property_event( msi_dialog
*dialog
, LPCWSTR event
, LPCWSTR arg
)
3421 static const WCHAR szNullArg
[] = { '{','}',0 };
3422 LPWSTR p
, prop
, arg_fmt
= NULL
;
3425 len
= strlenW(event
);
3426 prop
= msi_alloc( len
*sizeof(WCHAR
));
3427 strcpyW( prop
, &event
[1] );
3428 p
= strchrW( prop
, ']' );
3429 if( p
&& (p
[1] == 0 || p
[1] == ' ') )
3432 if( strcmpW( szNullArg
, arg
) )
3433 deformat_string( dialog
->package
, arg
, &arg_fmt
);
3434 msi_dialog_set_property( dialog
->package
, prop
, arg_fmt
);
3435 msi_dialog_update_controls( dialog
, prop
);
3436 msi_free( arg_fmt
);
3439 ERR("Badly formatted property string - what happens?\n");
3441 return ERROR_SUCCESS
;
3444 static UINT
msi_dialog_control_event( MSIRECORD
*rec
, LPVOID param
)
3446 msi_dialog
*dialog
= param
;
3447 LPCWSTR condition
, event
, arg
;
3450 condition
= MSI_RecordGetString( rec
, 5 );
3451 r
= MSI_EvaluateConditionW( dialog
->package
, condition
);
3452 if( r
== MSICONDITION_TRUE
|| r
== MSICONDITION_NONE
)
3454 event
= MSI_RecordGetString( rec
, 3 );
3455 arg
= MSI_RecordGetString( rec
, 4 );
3456 if( event
[0] == '[' )
3457 msi_dialog_set_property_event( dialog
, event
, arg
);
3459 msi_dialog_send_event( dialog
, event
, arg
);
3462 return ERROR_SUCCESS
;
3471 static UINT
add_rec_to_list( MSIRECORD
*rec
, LPVOID param
)
3473 struct rec_list
*add_rec
;
3474 struct list
*records
= param
;
3476 msiobj_addref( &rec
->hdr
);
3478 add_rec
= msi_alloc( sizeof( *add_rec
) );
3481 msiobj_release( &rec
->hdr
);
3482 return ERROR_OUTOFMEMORY
;
3486 list_add_tail( records
, &add_rec
->entry
);
3487 return ERROR_SUCCESS
;
3490 static inline void remove_rec_from_list( struct rec_list
*rec_entry
)
3492 msiobj_release( &rec_entry
->rec
->hdr
);
3493 list_remove( &rec_entry
->entry
);
3494 msi_free( rec_entry
);
3497 static UINT
msi_dialog_button_handler( msi_dialog
*dialog
,
3498 msi_control
*control
, WPARAM param
)
3500 static const WCHAR query
[] = {
3501 'S','E','L','E','C','T',' ','*',' ',
3502 'F','R','O','M',' ','C','o','n','t','r','o','l','E','v','e','n','t',' ',
3503 'W','H','E','R','E',' ',
3504 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',' ',
3506 '`','C','o','n','t','r','o','l','_','`',' ','=',' ','\'','%','s','\'',' ',
3507 'O','R','D','E','R',' ','B','Y',' ','`','O','r','d','e','r','i','n','g','`',0
3509 MSIQUERY
*view
= NULL
;
3510 struct rec_list
*rec_entry
, *next
;
3514 if( HIWORD(param
) != BN_CLICKED
)
3515 return ERROR_SUCCESS
;
3517 list_init( &events
);
3519 r
= MSI_OpenQuery( dialog
->package
->db
, &view
, query
,
3520 dialog
->name
, control
->name
);
3521 if( r
!= ERROR_SUCCESS
)
3523 ERR("query failed\n");
3527 r
= MSI_IterateRecords( view
, 0, add_rec_to_list
, &events
);
3528 msiobj_release( &view
->hdr
);
3529 if (r
!= ERROR_SUCCESS
)
3532 /* handle all SetProperty events first */
3533 LIST_FOR_EACH_ENTRY_SAFE( rec_entry
, next
, &events
, struct rec_list
, entry
)
3535 LPCWSTR event
= MSI_RecordGetString( rec_entry
->rec
, 3 );
3537 if ( event
[0] != '[' )
3540 r
= msi_dialog_control_event( rec_entry
->rec
, dialog
);
3541 remove_rec_from_list( rec_entry
);
3543 if ( r
!= ERROR_SUCCESS
)
3547 /* handle all other events */
3548 LIST_FOR_EACH_ENTRY_SAFE( rec_entry
, next
, &events
, struct rec_list
, entry
)
3550 r
= msi_dialog_control_event( rec_entry
->rec
, dialog
);
3551 remove_rec_from_list( rec_entry
);
3553 if ( r
!= ERROR_SUCCESS
)
3558 LIST_FOR_EACH_ENTRY_SAFE( rec_entry
, next
, &events
, struct rec_list
, entry
)
3560 remove_rec_from_list( rec_entry
);
3566 static UINT
msi_dialog_get_checkbox_state( msi_dialog
*dialog
,
3567 msi_control
*control
)
3569 WCHAR state
[2] = { 0 };
3572 msi_get_property( dialog
->package
->db
, control
->property
, state
, &sz
);
3573 return state
[0] ? 1 : 0;
3576 static void msi_dialog_set_checkbox_state( msi_dialog
*dialog
,
3577 msi_control
*control
, UINT state
)
3579 static const WCHAR szState
[] = { '1', 0 };
3582 /* if uncheck then the property is set to NULL */
3585 msi_dialog_set_property( dialog
->package
, control
->property
, NULL
);
3589 /* check for a custom state */
3590 if (control
->value
&& control
->value
[0])
3591 val
= control
->value
;
3595 msi_dialog_set_property( dialog
->package
, control
->property
, val
);
3598 static void msi_dialog_checkbox_sync_state( msi_dialog
*dialog
,
3599 msi_control
*control
)
3603 state
= msi_dialog_get_checkbox_state( dialog
, control
);
3604 SendMessageW( control
->hwnd
, BM_SETCHECK
,
3605 state
? BST_CHECKED
: BST_UNCHECKED
, 0 );
3608 static UINT
msi_dialog_checkbox_handler( msi_dialog
*dialog
,
3609 msi_control
*control
, WPARAM param
)
3613 if( HIWORD(param
) != BN_CLICKED
)
3614 return ERROR_SUCCESS
;
3616 TRACE("clicked checkbox %s, set %s\n", debugstr_w(control
->name
),
3617 debugstr_w(control
->property
));
3619 state
= msi_dialog_get_checkbox_state( dialog
, control
);
3620 state
= state
? 0 : 1;
3621 msi_dialog_set_checkbox_state( dialog
, control
, state
);
3622 msi_dialog_checkbox_sync_state( dialog
, control
);
3624 return msi_dialog_button_handler( dialog
, control
, param
);
3627 static UINT
msi_dialog_edit_handler( msi_dialog
*dialog
,
3628 msi_control
*control
, WPARAM param
)
3632 if( HIWORD(param
) != EN_CHANGE
)
3633 return ERROR_SUCCESS
;
3635 TRACE("edit %s contents changed, set %s\n", debugstr_w(control
->name
),
3636 debugstr_w(control
->property
));
3638 buf
= msi_get_window_text( control
->hwnd
);
3639 msi_dialog_set_property( dialog
->package
, control
->property
, buf
);
3642 return ERROR_SUCCESS
;
3645 static UINT
msi_dialog_radiogroup_handler( msi_dialog
*dialog
,
3646 msi_control
*control
, WPARAM param
)
3648 if( HIWORD(param
) != BN_CLICKED
)
3649 return ERROR_SUCCESS
;
3651 TRACE("clicked radio button %s, set %s\n", debugstr_w(control
->name
),
3652 debugstr_w(control
->property
));
3654 msi_dialog_set_property( dialog
->package
, control
->property
, control
->name
);
3656 return msi_dialog_button_handler( dialog
, control
, param
);
3659 static LRESULT
msi_dialog_oncommand( msi_dialog
*dialog
, WPARAM param
, HWND hwnd
)
3661 msi_control
*control
= NULL
;
3663 TRACE("%p %p %08lx\n", dialog
, hwnd
, param
);
3668 control
= msi_dialog_find_control( dialog
, dialog
->control_default
);
3670 case 2: /* escape */
3671 control
= msi_dialog_find_control( dialog
, dialog
->control_cancel
);
3674 control
= msi_dialog_find_control_by_hwnd( dialog
, hwnd
);
3679 if( control
->handler
)
3681 control
->handler( dialog
, control
, param
);
3682 msi_dialog_evaluate_control_conditions( dialog
);
3689 static LRESULT
msi_dialog_onnotify( msi_dialog
*dialog
, LPARAM param
)
3691 LPNMHDR nmhdr
= (LPNMHDR
) param
;
3692 msi_control
*control
= msi_dialog_find_control_by_hwnd( dialog
, nmhdr
->hwndFrom
);
3694 TRACE("%p %p\n", dialog
, nmhdr
->hwndFrom
);
3696 if ( control
&& control
->handler
)
3697 control
->handler( dialog
, control
, param
);
3702 static void msi_dialog_setfocus( msi_dialog
*dialog
)
3704 HWND hwnd
= dialog
->hWndFocus
;
3706 hwnd
= GetNextDlgTabItem( dialog
->hwnd
, hwnd
, TRUE
);
3707 hwnd
= GetNextDlgTabItem( dialog
->hwnd
, hwnd
, FALSE
);
3709 dialog
->hWndFocus
= hwnd
;
3712 static LRESULT WINAPI
MSIDialog_WndProc( HWND hwnd
, UINT msg
,
3713 WPARAM wParam
, LPARAM lParam
)
3715 msi_dialog
*dialog
= (LPVOID
) GetWindowLongPtrW( hwnd
, GWLP_USERDATA
);
3717 TRACE("0x%04x\n", msg
);
3722 dialog
->package
->center_x
= LOWORD(lParam
) + dialog
->size
.cx
/ 2.0;
3723 dialog
->package
->center_y
= HIWORD(lParam
) + dialog
->size
.cy
/ 2.0;
3727 return msi_dialog_oncreate( hwnd
, (LPCREATESTRUCTW
)lParam
);
3730 return msi_dialog_oncommand( dialog
, wParam
, (HWND
)lParam
);
3733 if( LOWORD(wParam
) == WA_INACTIVE
)
3734 dialog
->hWndFocus
= GetFocus();
3736 msi_dialog_setfocus( dialog
);
3740 msi_dialog_setfocus( dialog
);
3743 /* bounce back to our subclassed static control */
3744 case WM_CTLCOLORSTATIC
:
3745 return SendMessageW( (HWND
) lParam
, WM_CTLCOLORSTATIC
, wParam
, lParam
);
3748 dialog
->hwnd
= NULL
;
3751 return msi_dialog_onnotify( dialog
, lParam
);
3753 return DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
3756 static BOOL CALLBACK
msi_radioground_child_enum( HWND hWnd
, LPARAM lParam
)
3758 EnableWindow( hWnd
, lParam
);
3762 static LRESULT WINAPI
MSIRadioGroup_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
3764 WNDPROC oldproc
= (WNDPROC
) GetPropW(hWnd
, szButtonData
);
3767 TRACE("hWnd %p msg %04x wParam 0x%08lx lParam 0x%08lx\n", hWnd
, msg
, wParam
, lParam
);
3769 if (msg
== WM_COMMAND
) /* Forward notifications to dialog */
3770 SendMessageW(GetParent(hWnd
), msg
, wParam
, lParam
);
3772 r
= CallWindowProcW(oldproc
, hWnd
, msg
, wParam
, lParam
);
3774 /* make sure the radio buttons show as disabled if the parent is disabled */
3775 if (msg
== WM_ENABLE
)
3776 EnumChildWindows( hWnd
, msi_radioground_child_enum
, wParam
);
3781 static LRESULT WINAPI
MSIHiddenWindowProc( HWND hwnd
, UINT msg
,
3782 WPARAM wParam
, LPARAM lParam
)
3784 msi_dialog
*dialog
= (msi_dialog
*) lParam
;
3786 TRACE("%d %p\n", msg
, dialog
);
3790 case WM_MSI_DIALOG_CREATE
:
3791 return msi_dialog_run_message_loop( dialog
);
3792 case WM_MSI_DIALOG_DESTROY
:
3793 msi_dialog_destroy( dialog
);
3796 return DefWindowProcW( hwnd
, msg
, wParam
, lParam
);
3799 static BOOL
msi_dialog_register_class( void )
3803 ZeroMemory( &cls
, sizeof cls
);
3804 cls
.lpfnWndProc
= MSIDialog_WndProc
;
3805 cls
.hInstance
= NULL
;
3806 cls
.hIcon
= LoadIconW(0, (LPWSTR
)IDI_APPLICATION
);
3807 cls
.hCursor
= LoadCursorW(0, (LPWSTR
)IDC_ARROW
);
3808 cls
.hbrBackground
= (HBRUSH
)(COLOR_3DFACE
+ 1);
3809 cls
.lpszMenuName
= NULL
;
3810 cls
.lpszClassName
= szMsiDialogClass
;
3812 if( !RegisterClassW( &cls
) )
3815 cls
.lpfnWndProc
= MSIHiddenWindowProc
;
3816 cls
.lpszClassName
= szMsiHiddenWindow
;
3818 if( !RegisterClassW( &cls
) )
3821 uiThreadId
= GetCurrentThreadId();
3823 hMsiHiddenWindow
= CreateWindowW( szMsiHiddenWindow
, NULL
, WS_OVERLAPPED
,
3824 0, 0, 100, 100, NULL
, NULL
, NULL
, NULL
);
3825 if( !hMsiHiddenWindow
)
3831 /* functions that interface to other modules within MSI */
3833 msi_dialog
*msi_dialog_create( MSIPACKAGE
* package
,
3834 LPCWSTR szDialogName
, msi_dialog
*parent
,
3835 msi_dialog_event_handler event_handler
)
3837 MSIRECORD
*rec
= NULL
;
3840 TRACE("%p %s\n", package
, debugstr_w(szDialogName
));
3842 if (!hMsiHiddenWindow
)
3843 msi_dialog_register_class();
3845 /* allocate the structure for the dialog to use */
3846 dialog
= msi_alloc_zero( sizeof *dialog
+ sizeof(WCHAR
)*strlenW(szDialogName
) );
3849 strcpyW( dialog
->name
, szDialogName
);
3850 dialog
->parent
= parent
;
3851 msiobj_addref( &package
->hdr
);
3852 dialog
->package
= package
;
3853 dialog
->event_handler
= event_handler
;
3854 dialog
->finished
= 0;
3855 list_init( &dialog
->controls
);
3857 /* verify that the dialog exists */
3858 rec
= msi_get_dialog_record( dialog
);
3861 msiobj_release( &package
->hdr
);
3865 dialog
->attributes
= MSI_RecordGetInteger( rec
, 6 );
3866 dialog
->control_default
= strdupW( MSI_RecordGetString( rec
, 9 ) );
3867 dialog
->control_cancel
= strdupW( MSI_RecordGetString( rec
, 10 ) );
3868 msiobj_release( &rec
->hdr
);
3873 static void msi_process_pending_messages( HWND hdlg
)
3877 while( PeekMessageW( &msg
, 0, 0, 0, PM_REMOVE
) )
3879 if( hdlg
&& IsDialogMessageW( hdlg
, &msg
))
3881 TranslateMessage( &msg
);
3882 DispatchMessageW( &msg
);
3886 void msi_dialog_end_dialog( msi_dialog
*dialog
)
3888 TRACE("%p\n", dialog
);
3889 dialog
->finished
= 1;
3890 PostMessageW(dialog
->hwnd
, WM_NULL
, 0, 0);
3893 void msi_dialog_check_messages( HANDLE handle
)
3897 /* in threads other than the UI thread, block */
3898 if( uiThreadId
!= GetCurrentThreadId() )
3901 WaitForSingleObject( handle
, INFINITE
);
3905 /* there's two choices for the UI thread */
3908 msi_process_pending_messages( NULL
);
3914 * block here until somebody creates a new dialog or
3915 * the handle we're waiting on becomes ready
3917 r
= MsgWaitForMultipleObjects( 1, &handle
, 0, INFINITE
, QS_ALLINPUT
);
3918 if( r
== WAIT_OBJECT_0
)
3923 UINT
msi_dialog_run_message_loop( msi_dialog
*dialog
)
3928 if( uiThreadId
!= GetCurrentThreadId() )
3929 return SendMessageW( hMsiHiddenWindow
, WM_MSI_DIALOG_CREATE
, 0, (LPARAM
) dialog
);
3931 /* create the dialog window, don't show it yet */
3932 style
= WS_OVERLAPPED
;
3933 if( dialog
->attributes
& msidbDialogAttributesVisible
)
3934 style
|= WS_VISIBLE
;
3936 hwnd
= CreateWindowW( szMsiDialogClass
, dialog
->name
, style
,
3937 CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
,
3938 NULL
, NULL
, NULL
, dialog
);
3941 ERR("Failed to create dialog %s\n", debugstr_w( dialog
->name
));
3942 return ERROR_FUNCTION_FAILED
;
3945 ShowWindow( hwnd
, SW_SHOW
);
3946 /* UpdateWindow( hwnd ); - and causes the transparent static controls not to paint */
3948 if( dialog
->attributes
& msidbDialogAttributesModal
)
3950 while( !dialog
->finished
)
3952 MsgWaitForMultipleObjects( 0, NULL
, 0, INFINITE
, QS_ALLINPUT
);
3953 msi_process_pending_messages( dialog
->hwnd
);
3957 return ERROR_IO_PENDING
;
3959 return ERROR_SUCCESS
;
3962 void msi_dialog_do_preview( msi_dialog
*dialog
)
3965 dialog
->attributes
|= msidbDialogAttributesVisible
;
3966 dialog
->attributes
&= ~msidbDialogAttributesModal
;
3967 msi_dialog_run_message_loop( dialog
);
3970 void msi_dialog_destroy( msi_dialog
*dialog
)
3972 if( uiThreadId
!= GetCurrentThreadId() )
3974 SendMessageW( hMsiHiddenWindow
, WM_MSI_DIALOG_DESTROY
, 0, (LPARAM
) dialog
);
3979 ShowWindow( dialog
->hwnd
, SW_HIDE
);
3982 DestroyWindow( dialog
->hwnd
);
3984 /* unsubscribe events */
3985 ControlEvent_CleanupDialogSubscriptions(dialog
->package
, dialog
->name
);
3987 /* destroy the list of controls */
3988 while( !list_empty( &dialog
->controls
) )
3992 t
= LIST_ENTRY( list_head( &dialog
->controls
),
3993 msi_control
, entry
);
3994 msi_destroy_control( t
);
3997 /* destroy the list of fonts */
3998 while( dialog
->font_list
)
4000 msi_font
*t
= dialog
->font_list
;
4001 dialog
->font_list
= t
->next
;
4002 DeleteObject( t
->hfont
);
4005 msi_free( dialog
->default_font
);
4007 msi_free( dialog
->control_default
);
4008 msi_free( dialog
->control_cancel
);
4009 msiobj_release( &dialog
->package
->hdr
);
4010 dialog
->package
= NULL
;
4014 void msi_dialog_unregister_class( void )
4016 DestroyWindow( hMsiHiddenWindow
);
4017 hMsiHiddenWindow
= NULL
;
4018 UnregisterClassW( szMsiDialogClass
, NULL
);
4019 UnregisterClassW( szMsiHiddenWindow
, NULL
);
4023 static UINT
error_dialog_handler(MSIPACKAGE
*package
, LPCWSTR event
,
4024 LPCWSTR argument
, msi_dialog
* dialog
)
4026 static const WCHAR end_dialog
[] = {'E','n','d','D','i','a','l','o','g',0};
4027 static const WCHAR error_abort
[] = {'E','r','r','o','r','A','b','o','r','t',0};
4028 static const WCHAR error_cancel
[] = {'E','r','r','o','r','C','a','n','c','e','l',0};
4029 static const WCHAR error_no
[] = {'E','r','r','o','r','N','o',0};
4030 static const WCHAR result_prop
[] = {
4031 'M','S','I','E','r','r','o','r','D','i','a','l','o','g','R','e','s','u','l','t',0
4034 if ( strcmpW( event
, end_dialog
) )
4035 return ERROR_SUCCESS
;
4037 if ( !strcmpW( argument
, error_abort
) || !strcmpW( argument
, error_cancel
) ||
4038 !strcmpW( argument
, error_no
) )
4040 msi_set_property( package
->db
, result_prop
, error_abort
);
4043 ControlEvent_CleanupSubscriptions(package
);
4044 msi_dialog_end_dialog( dialog
);
4046 return ERROR_SUCCESS
;
4049 static UINT
msi_error_dialog_set_error( MSIPACKAGE
*package
, LPWSTR error_dialog
, LPWSTR error
)
4053 static const WCHAR update
[] =
4054 {'U','P','D','A','T','E',' ','`','C','o','n','t','r','o','l','`',' ',
4055 'S','E','T',' ','`','T','e','x','t','`',' ','=',' ','\'','%','s','\'',' ',
4056 'W','H','E','R','E', ' ','`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',' ',
4057 'A','N','D',' ','`','C','o','n','t','r','o','l','`',' ','=',' ',
4058 '\'','E','r','r','o','r','T','e','x','t','\'',0};
4060 row
= MSI_QueryGetRecord( package
->db
, update
, error
, error_dialog
);
4062 return ERROR_FUNCTION_FAILED
;
4064 msiobj_release(&row
->hdr
);
4065 return ERROR_SUCCESS
;
4068 UINT
msi_spawn_error_dialog( MSIPACKAGE
*package
, LPWSTR error_dialog
, LPWSTR error
)
4071 WCHAR result
[MAX_PATH
];
4072 UINT r
= ERROR_SUCCESS
;
4073 DWORD size
= MAX_PATH
;
4076 static const WCHAR pn_prop
[] = {'P','r','o','d','u','c','t','N','a','m','e',0};
4077 static const WCHAR title_fmt
[] = {'%','s',' ','W','a','r','n','i','n','g',0};
4078 static const WCHAR error_abort
[] = {'E','r','r','o','r','A','b','o','r','t',0};
4079 static const WCHAR result_prop
[] = {
4080 'M','S','I','E','r','r','o','r','D','i','a','l','o','g','R','e','s','u','l','t',0
4083 if ( (msi_get_property_int( package
->db
, szUILevel
, 0 ) & INSTALLUILEVEL_MASK
) == INSTALLUILEVEL_NONE
)
4084 return ERROR_SUCCESS
;
4086 if ( !error_dialog
)
4088 LPWSTR product_name
= msi_dup_property( package
->db
, pn_prop
);
4089 WCHAR title
[MAX_PATH
];
4091 sprintfW( title
, title_fmt
, product_name
);
4092 res
= MessageBoxW( NULL
, error
, title
, MB_OKCANCEL
| MB_ICONWARNING
);
4094 msi_free( product_name
);
4097 return ERROR_SUCCESS
;
4099 return ERROR_FUNCTION_FAILED
;
4102 r
= msi_error_dialog_set_error( package
, error_dialog
, error
);
4103 if ( r
!= ERROR_SUCCESS
)
4106 dialog
= msi_dialog_create( package
, error_dialog
, package
->dialog
,
4107 error_dialog_handler
);
4109 return ERROR_FUNCTION_FAILED
;
4111 dialog
->finished
= FALSE
;
4112 r
= msi_dialog_run_message_loop( dialog
);
4113 if ( r
!= ERROR_SUCCESS
)
4116 r
= msi_get_property( package
->db
, result_prop
, result
, &size
);
4117 if ( r
!= ERROR_SUCCESS
)
4120 if ( !strcmpW( result
, error_abort
) )
4121 r
= ERROR_FUNCTION_FAILED
;
4124 msi_dialog_destroy( dialog
);