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"
47 WINE_DEFAULT_DEBUG_CHANNEL(msi);
50 extern HINSTANCE msi_hInstance;
52 struct msi_control_tag;
53 typedef struct msi_control_tag msi_control;
54 typedef UINT (*msi_handler)( msi_dialog *, msi_control *, WPARAM );
56 struct msi_control_tag
67 float progress_current;
73 typedef struct msi_font_tag
75 struct msi_font_tag *next;
84 msi_dialog_event_handler event_handler;
93 LPWSTR control_default;
94 LPWSTR control_cancel;
98 typedef UINT (*msi_dialog_control_func)( msi_dialog *dialog, MSIRECORD *rec );
99 struct control_handler
101 LPCWSTR control_type;
102 msi_dialog_control_func func;
111 } radio_button_group_descr;
113 static const WCHAR szMsiDialogClass[] = {
114 'M','s','i','D','i','a','l','o','g','C','l','o','s','e','C','l','a','s','s',0
116 static const WCHAR szMsiHiddenWindow[] = {
117 'M','s','i','H','i','d','d','e','n','W','i','n','d','o','w',0 };
118 static const WCHAR szStatic[] = { 'S','t','a','t','i','c',0 };
119 static const WCHAR szButton[] = { 'B','U','T','T','O','N', 0 };
120 static const WCHAR szButtonData[] = { 'M','S','I','D','A','T','A',0 };
121 static const WCHAR szProgress[] = { 'P','r','o','g','r','e','s','s',0 };
122 static const WCHAR szText[] = { 'T','e','x','t',0 };
123 static const WCHAR szPushButton[] = { 'P','u','s','h','B','u','t','t','o','n',0 };
124 static const WCHAR szLine[] = { 'L','i','n','e',0 };
125 static const WCHAR szBitmap[] = { 'B','i','t','m','a','p',0 };
126 static const WCHAR szCheckBox[] = { 'C','h','e','c','k','B','o','x',0 };
127 static const WCHAR szScrollableText[] = {
128 'S','c','r','o','l','l','a','b','l','e','T','e','x','t',0 };
129 static const WCHAR szComboBox[] = { 'C','o','m','b','o','B','o','x',0 };
130 static const WCHAR szEdit[] = { 'E','d','i','t',0 };
131 static const WCHAR szMaskedEdit[] = { 'M','a','s','k','e','d','E','d','i','t',0 };
132 static const WCHAR szPathEdit[] = { 'P','a','t','h','E','d','i','t',0 };
133 static const WCHAR szProgressBar[] = {
134 'P','r','o','g','r','e','s','s','B','a','r',0 };
135 static const WCHAR szRadioButtonGroup[] = {
136 'R','a','d','i','o','B','u','t','t','o','n','G','r','o','u','p',0 };
137 static const WCHAR szIcon[] = { 'I','c','o','n',0 };
138 static const WCHAR szSelectionTree[] = {
139 'S','e','l','e','c','t','i','o','n','T','r','e','e',0 };
140 static const WCHAR szGroupBox[] = { 'G','r','o','u','p','B','o','x',0 };
141 static const WCHAR szListBox[] = { 'L','i','s','t','B','o','x',0 };
142 static const WCHAR szDirectoryCombo[] = { 'D','i','r','e','c','t','o','r','y','C','o','m','b','o',0 };
143 static const WCHAR szDirectoryList[] = { 'D','i','r','e','c','t','o','r','y','L','i','s','t',0 };
144 static const WCHAR szVolumeCostList[] = { 'V','o','l','u','m','e','C','o','s','t','L','i','s','t',0 };
146 static UINT msi_dialog_checkbox_handler( msi_dialog *, msi_control *, WPARAM );
147 static void msi_dialog_checkbox_sync_state( msi_dialog *, msi_control * );
148 static UINT msi_dialog_button_handler( msi_dialog *, msi_control *, WPARAM );
149 static UINT msi_dialog_edit_handler( msi_dialog *, msi_control *, WPARAM );
150 static UINT msi_dialog_radiogroup_handler( msi_dialog *, msi_control *, WPARAM param );
151 static UINT msi_dialog_evaluate_control_conditions( msi_dialog *dialog );
152 static LRESULT WINAPI MSIRadioGroup_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
155 /* dialog sequencing */
157 #define WM_MSI_DIALOG_CREATE (WM_USER+0x100)
158 #define WM_MSI_DIALOG_DESTROY (WM_USER+0x101)
160 static DWORD uiThreadId;
161 static HWND hMsiHiddenWindow;
163 static INT msi_dialog_scale_unit( msi_dialog *dialog, INT val )
165 return (dialog->scale * val + 5) / 10;
168 static msi_control *msi_dialog_find_control( msi_dialog *dialog, LPCWSTR name )
170 msi_control *control;
174 LIST_FOR_EACH_ENTRY( control, &dialog->controls, msi_control, entry )
175 if( !strcmpW( control->name, name ) ) /* FIXME: case sensitive? */
180 static msi_control *msi_dialog_find_control_by_hwnd( msi_dialog *dialog, HWND hwnd )
182 msi_control *control;
184 LIST_FOR_EACH_ENTRY( control, &dialog->controls, msi_control, entry )
185 if( hwnd == control->hwnd )
190 static LPWSTR msi_get_deformatted_field( MSIPACKAGE *package, MSIRECORD *rec, int field )
192 LPCWSTR str = MSI_RecordGetString( rec, field );
196 deformat_string( package, str, &ret );
200 static LPWSTR msi_dialog_dup_property( msi_dialog *dialog, LPCWSTR property, BOOL indirect )
206 return msi_dup_property( dialog->package, property );
208 return strdupW( property );
212 * msi_dialog_get_style
214 * Extract the {\style} string from the front of the text to display and
215 * update the pointer.
217 static LPWSTR msi_dialog_get_style( LPCWSTR p, LPCWSTR *rest )
228 q = strchrW( p, '}' );
231 if( *p == '\\' || *p == '&' )
234 /* little bit of sanity checking to stop us getting confused with RTF */
236 if( *i == '}' || *i == '\\' )
242 ret = msi_alloc( len*sizeof(WCHAR) );
245 memcpy( ret, p, len*sizeof(WCHAR) );
250 static UINT msi_dialog_add_font( MSIRECORD *rec, LPVOID param )
252 msi_dialog *dialog = param;
259 /* create a font and add it to the list */
260 name = MSI_RecordGetString( rec, 1 );
261 font = msi_alloc( sizeof *font + strlenW( name )*sizeof (WCHAR) );
262 strcpyW( font->name, name );
263 font->next = dialog->font_list;
264 dialog->font_list = font;
266 font->color = MSI_RecordGetInteger( rec, 4 );
268 memset( &lf, 0, sizeof lf );
269 face = MSI_RecordGetString( rec, 2 );
270 lf.lfHeight = MSI_RecordGetInteger( rec, 3 );
271 style = MSI_RecordGetInteger( rec, 5 );
272 if( style & msidbTextStyleStyleBitsBold )
273 lf.lfWeight = FW_BOLD;
274 if( style & msidbTextStyleStyleBitsItalic )
276 if( style & msidbTextStyleStyleBitsUnderline )
277 lf.lfUnderline = TRUE;
278 if( style & msidbTextStyleStyleBitsStrike )
279 lf.lfStrikeOut = TRUE;
280 lstrcpynW( lf.lfFaceName, face, LF_FACESIZE );
282 /* adjust the height */
283 hdc = GetDC( dialog->hwnd );
286 lf.lfHeight = -MulDiv(lf.lfHeight, GetDeviceCaps(hdc, LOGPIXELSY), 72);
287 ReleaseDC( dialog->hwnd, hdc );
290 font->hfont = CreateFontIndirectW( &lf );
292 TRACE("Adding font style %s\n", debugstr_w(font->name) );
294 return ERROR_SUCCESS;
297 static msi_font *msi_dialog_find_font( msi_dialog *dialog, LPCWSTR name )
301 for( font = dialog->font_list; font; font = font->next )
302 if( !strcmpW( font->name, name ) ) /* FIXME: case sensitive? */
308 static UINT msi_dialog_set_font( msi_dialog *dialog, HWND hwnd, LPCWSTR name )
312 font = msi_dialog_find_font( dialog, name );
314 SendMessageW( hwnd, WM_SETFONT, (WPARAM) font->hfont, TRUE );
316 ERR("No font entry for %s\n", debugstr_w(name));
317 return ERROR_SUCCESS;
320 static UINT msi_dialog_build_font_list( msi_dialog *dialog )
322 static const WCHAR query[] = {
323 'S','E','L','E','C','T',' ','*',' ',
324 'F','R','O','M',' ','`','T','e','x','t','S','t','y','l','e','`',' ',0
327 MSIQUERY *view = NULL;
329 TRACE("dialog %p\n", dialog );
331 r = MSI_OpenQuery( dialog->package->db, &view, query );
332 if( r != ERROR_SUCCESS )
335 r = MSI_IterateRecords( view, NULL, msi_dialog_add_font, dialog );
336 msiobj_release( &view->hdr );
341 static msi_control *msi_dialog_create_window( msi_dialog *dialog,
342 MSIRECORD *rec, DWORD exstyle, LPCWSTR szCls, LPCWSTR name, LPCWSTR text,
343 DWORD style, HWND parent )
345 DWORD x, y, width, height;
346 LPWSTR font = NULL, title_font = NULL;
347 LPCWSTR title = NULL;
348 msi_control *control;
352 control = msi_alloc( sizeof *control + strlenW(name)*sizeof(WCHAR) );
353 strcpyW( control->name, name );
354 list_add_head( &dialog->controls, &control->entry );
355 control->handler = NULL;
356 control->property = NULL;
357 control->value = NULL;
358 control->hBitmap = NULL;
359 control->hIcon = NULL;
360 control->hDll = NULL;
361 control->tabnext = strdupW( MSI_RecordGetString( rec, 11) );
362 control->progress_current = 0;
363 control->progress_max = 100;
365 x = MSI_RecordGetInteger( rec, 4 );
366 y = MSI_RecordGetInteger( rec, 5 );
367 width = MSI_RecordGetInteger( rec, 6 );
368 height = MSI_RecordGetInteger( rec, 7 );
370 x = msi_dialog_scale_unit( dialog, x );
371 y = msi_dialog_scale_unit( dialog, y );
372 width = msi_dialog_scale_unit( dialog, width );
373 height = msi_dialog_scale_unit( dialog, height );
377 deformat_string( dialog->package, text, &title_font );
378 font = msi_dialog_get_style( title_font, &title );
381 control->hwnd = CreateWindowExW( exstyle, szCls, title, style,
382 x, y, width, height, parent, NULL, NULL, NULL );
384 TRACE("Dialog %s control %s hwnd %p\n",
385 debugstr_w(dialog->name), debugstr_w(text), control->hwnd );
387 msi_dialog_set_font( dialog, control->hwnd,
388 font ? font : dialog->default_font );
390 msi_free( title_font );
396 static MSIRECORD *msi_get_binary_record( MSIDATABASE *db, LPCWSTR name )
398 static const WCHAR query[] = {
399 's','e','l','e','c','t',' ','*',' ',
400 'f','r','o','m',' ','B','i','n','a','r','y',' ',
401 'w','h','e','r','e',' ',
402 '`','N','a','m','e','`',' ','=',' ','\'','%','s','\'',0
405 return MSI_QueryGetRecord( db, query, name );
408 static LPWSTR msi_create_tmp_path(void)
412 static const WCHAR prefix[] = { 'm','s','i',0 };
415 r = GetTempPathW( MAX_PATH, tmp );
418 len = lstrlenW( tmp ) + 20;
419 path = msi_alloc( len * sizeof (WCHAR) );
422 r = GetTempFileNameW( tmp, prefix, 0, path );
433 static HANDLE msi_load_image( MSIDATABASE *db, LPCWSTR name, UINT type,
434 UINT cx, UINT cy, UINT flags )
436 MSIRECORD *rec = NULL;
437 HANDLE himage = NULL;
441 TRACE("%p %s %u %u %08x\n", db, debugstr_w(name), cx, cy, flags);
443 tmp = msi_create_tmp_path();
447 rec = msi_get_binary_record( db, name );
450 r = MSI_RecordStreamToFile( rec, 2, tmp );
451 if( r == ERROR_SUCCESS )
453 himage = LoadImageW( 0, tmp, type, cx, cy, flags );
456 msiobj_release( &rec->hdr );
463 static HICON msi_load_icon( MSIDATABASE *db, LPCWSTR text, UINT attributes )
465 DWORD cx = 0, cy = 0, flags;
467 flags = LR_LOADFROMFILE | LR_DEFAULTSIZE;
468 if( attributes & msidbControlAttributesFixedSize )
470 flags &= ~LR_DEFAULTSIZE;
471 if( attributes & msidbControlAttributesIconSize16 )
476 if( attributes & msidbControlAttributesIconSize32 )
481 /* msidbControlAttributesIconSize48 handled by above logic */
483 return msi_load_image( db, text, IMAGE_ICON, cx, cy, flags );
487 /* called from the Control Event subscription code */
488 void msi_dialog_handle_event( msi_dialog* dialog, LPCWSTR control,
489 LPCWSTR attribute, MSIRECORD *rec )
492 LPCWSTR font_text, text = NULL;
495 ctrl = msi_dialog_find_control( dialog, control );
498 if( !lstrcmpW(attribute, szText) )
500 font_text = MSI_RecordGetString( rec , 1 );
501 font = msi_dialog_get_style( font_text, &text );
502 SetWindowTextW( ctrl->hwnd, text );
504 msi_dialog_check_messages( NULL );
506 else if( !lstrcmpW(attribute, szProgress) )
510 func = MSI_RecordGetInteger( rec , 1 );
511 val = MSI_RecordGetInteger( rec , 2 );
516 ctrl->progress_max = val;
517 ctrl->progress_current = 0;
518 SendMessageW(ctrl->hwnd, PBM_SETRANGE, 0, MAKELPARAM(0,100));
519 SendMessageW(ctrl->hwnd, PBM_SETPOS, 0, 0);
521 case 1: /* FIXME: not sure what this is supposed to do */
524 ctrl->progress_current += val;
525 SendMessageW(ctrl->hwnd, PBM_SETPOS, 100*(ctrl->progress_current/ctrl->progress_max), 0);
528 ERR("Unknown progress message %ld\n", func);
534 FIXME("Attribute %s not being set\n", debugstr_w(attribute));
539 static void msi_dialog_map_events(msi_dialog* dialog, LPCWSTR control)
541 static const WCHAR Query[] = {
542 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
543 '`','E','v','e','n','t','M','a','p','p','i','n','g','`',' ',
544 'W','H','E','R','E',' ',
545 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',' ',
547 '`','C','o','n','t','r','o','l','_','`',' ','=',' ','\'','%','s','\'',0
550 LPCWSTR event, attribute;
552 row = MSI_QueryGetRecord( dialog->package->db, Query, dialog->name, control );
556 event = MSI_RecordGetString( row, 3 );
557 attribute = MSI_RecordGetString( row, 4 );
558 ControlEvent_SubscribeToEvent( dialog->package, event, control, attribute );
559 msiobj_release( &row->hdr );
562 /* everything except radio buttons */
563 static msi_control *msi_dialog_add_control( msi_dialog *dialog,
564 MSIRECORD *rec, LPCWSTR szCls, DWORD style )
570 name = MSI_RecordGetString( rec, 2 );
571 attributes = MSI_RecordGetInteger( rec, 8 );
572 text = MSI_RecordGetString( rec, 10 );
573 if( attributes & msidbControlAttributesVisible )
575 if( ~attributes & msidbControlAttributesEnabled )
576 style |= WS_DISABLED;
577 if( attributes & msidbControlAttributesSunken )
578 exstyle |= WS_EX_CLIENTEDGE;
580 msi_dialog_map_events(dialog, name);
582 return msi_dialog_create_window( dialog, rec, exstyle, szCls, name,
583 text, style, dialog->hwnd );
594 * we don't erase our own background,
595 * so we have to make sure that the parent window redraws first
597 static void msi_text_on_settext( HWND hWnd )
602 hParent = GetParent( hWnd );
603 GetWindowRect( hWnd, &rc );
604 MapWindowPoints( NULL, hParent, (LPPOINT) &rc, 2 );
605 InvalidateRect( hParent, &rc, TRUE );
608 static LRESULT WINAPI
609 MSIText_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
611 struct msi_text_info *info;
614 TRACE("%p %04x %08x %08lx\n", hWnd, msg, wParam, lParam);
616 info = GetPropW(hWnd, szButtonData);
619 SetTextColor( (HDC)wParam, info->font->color );
621 if( msg == WM_CTLCOLORSTATIC &&
622 ( info->attributes & msidbControlAttributesTransparent ) )
624 SetBkMode( (HDC)wParam, TRANSPARENT );
625 return (LRESULT) GetStockObject(NULL_BRUSH);
628 r = CallWindowProcW(info->oldproc, hWnd, msg, wParam, lParam);
633 msi_text_on_settext( hWnd );
637 RemovePropW( hWnd, szButtonData );
644 static UINT msi_dialog_text_control( msi_dialog *dialog, MSIRECORD *rec )
646 msi_control *control;
647 struct msi_text_info *info;
651 TRACE("%p %p\n", dialog, rec);
653 control = msi_dialog_add_control( dialog, rec, szStatic, SS_LEFT | WS_GROUP );
655 return ERROR_FUNCTION_FAILED;
657 info = msi_alloc( sizeof *info );
659 return ERROR_SUCCESS;
661 text = MSI_RecordGetString( rec, 10 );
662 font_name = msi_dialog_get_style( text, &ptr );
663 info->font = ( font_name ) ? msi_dialog_find_font( dialog, font_name ) : NULL;
664 msi_free( font_name );
666 info->attributes = MSI_RecordGetInteger( rec, 8 );
667 if( info->attributes & msidbControlAttributesTransparent )
668 SetWindowLongPtrW( control->hwnd, GWL_EXSTYLE, WS_EX_TRANSPARENT );
670 info->oldproc = (WNDPROC) SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
671 (LONG_PTR)MSIText_WndProc );
672 SetPropW( control->hwnd, szButtonData, info );
674 return ERROR_SUCCESS;
677 static UINT msi_dialog_button_control( msi_dialog *dialog, MSIRECORD *rec )
679 msi_control *control;
680 UINT attributes, style;
683 TRACE("%p %p\n", dialog, rec);
686 attributes = MSI_RecordGetInteger( rec, 8 );
687 if( attributes & msidbControlAttributesIcon )
690 control = msi_dialog_add_control( dialog, rec, szButton, style );
692 return ERROR_FUNCTION_FAILED;
694 control->handler = msi_dialog_button_handler;
697 text = msi_get_deformatted_field( dialog->package, rec, 10 );
698 control->hIcon = msi_load_icon( dialog->package->db, text, attributes );
699 if( attributes & msidbControlAttributesIcon )
700 SendMessageW( control->hwnd, BM_SETIMAGE, IMAGE_ICON, (LPARAM) control->hIcon );
703 return ERROR_SUCCESS;
706 static LPWSTR msi_get_checkbox_value( msi_dialog *dialog, LPCWSTR prop )
708 static const WCHAR query[] = {
709 'S','E','L','E','C','T',' ','*',' ',
710 'F','R','O','M',' ','`','C','h','e','c','k','B','o','x',' ','`',
711 'W','H','E','R','E',' ',
712 '`','P','r','o','p','e','r','t','y','`',' ','=',' ',
715 MSIRECORD *rec = NULL;
718 /* find if there is a value associated with the checkbox */
719 rec = MSI_QueryGetRecord( dialog->package->db, query, prop );
723 ret = msi_get_deformatted_field( dialog->package, rec, 2 );
729 msiobj_release( &rec->hdr );
733 ret = msi_dup_property( dialog->package, prop );
743 static UINT msi_dialog_checkbox_control( msi_dialog *dialog, MSIRECORD *rec )
745 msi_control *control;
748 TRACE("%p %p\n", dialog, rec);
750 control = msi_dialog_add_control( dialog, rec, szButton,
751 BS_CHECKBOX | BS_MULTILINE | WS_TABSTOP );
752 control->handler = msi_dialog_checkbox_handler;
753 prop = MSI_RecordGetString( rec, 9 );
756 control->property = strdupW( prop );
757 control->value = msi_get_checkbox_value( dialog, prop );
758 TRACE("control %s value %s\n", debugstr_w(control->property),
759 debugstr_w(control->value));
761 msi_dialog_checkbox_sync_state( dialog, control );
763 return ERROR_SUCCESS;
766 static UINT msi_dialog_line_control( msi_dialog *dialog, MSIRECORD *rec )
768 TRACE("%p %p\n", dialog, rec);
770 /* line is exactly 2 units in height */
771 MSI_RecordSetInteger( rec, 7, 2 );
773 msi_dialog_add_control( dialog, rec, szStatic, SS_ETCHEDHORZ | SS_SUNKEN );
774 return ERROR_SUCCESS;
777 /******************** Scroll Text ********************************************/
779 struct msi_scrolltext_info
782 msi_control *control;
786 static LRESULT WINAPI
787 MSIScrollText_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
789 struct msi_scrolltext_info *info;
792 TRACE("%p %04x %08x %08lx\n", hWnd, msg, wParam, lParam);
794 info = GetPropW( hWnd, szButtonData );
796 r = CallWindowProcW( info->oldproc, hWnd, msg, wParam, lParam );
802 RemovePropW( hWnd, szButtonData );
805 /* native MSI sets a wait cursor here */
806 msi_dialog_button_handler( info->dialog, info->control, BN_CLICKED );
812 struct msi_streamin_info
819 static DWORD CALLBACK
820 msi_richedit_stream_in( DWORD_PTR arg, LPBYTE buffer, LONG count, LONG *pcb )
822 struct msi_streamin_info *info = (struct msi_streamin_info*) arg;
824 if( (count + info->offset) > info->length )
825 count = info->length - info->offset;
826 memcpy( buffer, &info->string[ info->offset ], count );
828 info->offset += count;
830 TRACE("%ld/%ld\n", info->offset, info->length);
835 static void msi_scrolltext_add_text( msi_control *control, LPCWSTR text )
837 struct msi_streamin_info info;
840 info.string = strdupWtoA( text );
842 info.length = lstrlenA( info.string ) + 1;
844 es.dwCookie = (DWORD_PTR) &info;
846 es.pfnCallback = msi_richedit_stream_in;
848 SendMessageW( control->hwnd, EM_STREAMIN, SF_RTF, (LPARAM) &es );
850 msi_free( info.string );
853 static UINT msi_dialog_scrolltext_control( msi_dialog *dialog, MSIRECORD *rec )
855 static const WCHAR szRichEdit20W[] = {
856 'R','i','c','h','E','d','i','t','2','0','W',0
858 struct msi_scrolltext_info *info;
859 msi_control *control;
863 info = msi_alloc( sizeof *info );
865 return ERROR_FUNCTION_FAILED;
867 hRichedit = LoadLibraryA("riched20");
869 style = WS_BORDER | ES_MULTILINE | WS_VSCROLL |
870 ES_READONLY | ES_AUTOVSCROLL | WS_TABSTOP;
871 control = msi_dialog_add_control( dialog, rec, szRichEdit20W, style );
874 FreeLibrary( hRichedit );
876 return ERROR_FUNCTION_FAILED;
879 control->hDll = hRichedit;
881 info->dialog = dialog;
882 info->control = control;
884 /* subclass the static control */
885 info->oldproc = (WNDPROC) SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
886 (LONG_PTR)MSIScrollText_WndProc );
887 SetPropW( control->hwnd, szButtonData, info );
889 /* add the text into the richedit */
890 msi_scrolltext_add_text( control, MSI_RecordGetString( rec, 10 ) );
892 return ERROR_SUCCESS;
895 static HBITMAP msi_load_picture( MSIDATABASE *db, LPCWSTR name,
896 INT cx, INT cy, DWORD flags )
898 HBITMAP hOleBitmap = 0, hBitmap = 0, hOldSrcBitmap, hOldDestBitmap;
899 MSIRECORD *rec = NULL;
901 IPicture *pic = NULL;
906 rec = msi_get_binary_record( db, name );
910 r = MSI_RecordGetIStream( rec, 2, &stm );
911 msiobj_release( &rec->hdr );
912 if( r != ERROR_SUCCESS )
915 r = OleLoadPicture( stm, 0, TRUE, &IID_IPicture, (LPVOID*) &pic );
916 IStream_Release( stm );
919 ERR("failed to load picture\n");
923 r = IPicture_get_Handle( pic, (OLE_HANDLE*) &hOleBitmap );
926 ERR("failed to get bitmap handle\n");
930 /* make the bitmap the desired size */
931 r = GetObjectW( hOleBitmap, sizeof bm, &bm );
934 ERR("failed to get bitmap size\n");
938 if (flags & LR_DEFAULTSIZE)
944 srcdc = CreateCompatibleDC( NULL );
945 hOldSrcBitmap = SelectObject( srcdc, hOleBitmap );
946 destdc = CreateCompatibleDC( NULL );
947 hBitmap = CreateCompatibleBitmap( srcdc, cx, cy );
948 hOldDestBitmap = SelectObject( destdc, hBitmap );
949 StretchBlt( destdc, 0, 0, cx, cy,
950 srcdc, 0, 0, bm.bmWidth, bm.bmHeight, SRCCOPY);
951 SelectObject( srcdc, hOldSrcBitmap );
952 SelectObject( destdc, hOldDestBitmap );
958 IPicture_Release( pic );
962 static UINT msi_dialog_bitmap_control( msi_dialog *dialog, MSIRECORD *rec )
964 UINT cx, cy, flags, style, attributes;
965 msi_control *control;
968 flags = LR_LOADFROMFILE;
969 style = SS_BITMAP | SS_LEFT | WS_GROUP;
971 attributes = MSI_RecordGetInteger( rec, 8 );
972 if( attributes & msidbControlAttributesFixedSize )
974 flags |= LR_DEFAULTSIZE;
975 style |= SS_CENTERIMAGE;
978 control = msi_dialog_add_control( dialog, rec, szStatic, style );
979 cx = MSI_RecordGetInteger( rec, 6 );
980 cy = MSI_RecordGetInteger( rec, 7 );
981 cx = msi_dialog_scale_unit( dialog, cx );
982 cy = msi_dialog_scale_unit( dialog, cy );
984 text = msi_get_deformatted_field( dialog->package, rec, 10 );
985 control->hBitmap = msi_load_picture( dialog->package->db, text, cx, cy, flags );
986 if( control->hBitmap )
987 SendMessageW( control->hwnd, STM_SETIMAGE,
988 IMAGE_BITMAP, (LPARAM) control->hBitmap );
990 ERR("Failed to load bitmap %s\n", debugstr_w(text));
994 return ERROR_SUCCESS;
997 static UINT msi_dialog_icon_control( msi_dialog *dialog, MSIRECORD *rec )
999 msi_control *control;
1005 control = msi_dialog_add_control( dialog, rec, szStatic,
1006 SS_ICON | SS_CENTERIMAGE | WS_GROUP );
1008 attributes = MSI_RecordGetInteger( rec, 8 );
1009 text = msi_get_deformatted_field( dialog->package, rec, 10 );
1010 control->hIcon = msi_load_icon( dialog->package->db, text, attributes );
1011 if( control->hIcon )
1012 SendMessageW( control->hwnd, STM_SETICON, (WPARAM) control->hIcon, 0 );
1014 ERR("Failed to load bitmap %s\n", debugstr_w(text));
1016 return ERROR_SUCCESS;
1019 static UINT msi_dialog_combo_control( msi_dialog *dialog, MSIRECORD *rec )
1021 static const WCHAR szCombo[] = { 'C','O','M','B','O','B','O','X',0 };
1023 msi_dialog_add_control( dialog, rec, szCombo,
1024 SS_BITMAP | SS_LEFT | SS_CENTERIMAGE );
1025 return ERROR_SUCCESS;
1028 static UINT msi_dialog_edit_control( msi_dialog *dialog, MSIRECORD *rec )
1030 msi_control *control;
1034 control = msi_dialog_add_control( dialog, rec, szEdit,
1035 WS_BORDER | WS_TABSTOP );
1036 control->handler = msi_dialog_edit_handler;
1037 prop = MSI_RecordGetString( rec, 9 );
1039 control->property = strdupW( prop );
1040 val = msi_dup_property( dialog->package, control->property );
1041 SetWindowTextW( control->hwnd, val );
1043 return ERROR_SUCCESS;
1046 /******************** Masked Edit ********************************************/
1048 #define MASK_MAX_GROUPS 10
1050 struct msi_mask_group
1058 struct msi_maskedit_info
1066 struct msi_mask_group group[MASK_MAX_GROUPS];
1069 static BOOL msi_mask_editable( WCHAR type )
1084 static void msi_mask_control_change( struct msi_maskedit_info *info )
1089 val = msi_alloc( (info->num_chars+1)*sizeof(WCHAR) );
1090 for( i=0, n=0; i<info->num_groups; i++ )
1092 if( (info->group[i].len + n) > info->num_chars )
1094 ERR("can't fit control %d text into template\n",i);
1097 if (!msi_mask_editable(info->group[i].type))
1099 for(r=0; r<info->group[i].len; r++)
1100 val[n+r] = info->group[i].type;
1105 r = GetWindowTextW( info->group[i].hwnd, &val[n], info->group[i].len+1 );
1106 if( r != info->group[i].len )
1112 TRACE("%d/%d controls were good\n", i, info->num_groups);
1114 if( i == info->num_groups )
1116 TRACE("Set property %s to %s\n",
1117 debugstr_w(info->prop), debugstr_w(val) );
1118 CharUpperBuffW( val, info->num_chars );
1119 MSI_SetPropertyW( info->dialog->package, info->prop, val );
1120 msi_dialog_evaluate_control_conditions( info->dialog );
1125 /* now move to the next control if necessary */
1126 static VOID msi_mask_next_control( struct msi_maskedit_info *info, HWND hWnd )
1131 for( i=0; i<info->num_groups; i++ )
1132 if( info->group[i].hwnd == hWnd )
1135 /* don't move from the last control */
1136 if( i >= (info->num_groups-1) )
1139 len = SendMessageW( hWnd, WM_GETTEXTLENGTH, 0, 0 );
1140 if( len < info->group[i].len )
1143 hWndNext = GetNextDlgTabItem( GetParent( hWnd ), hWnd, FALSE );
1144 SetFocus( hWndNext );
1147 static LRESULT WINAPI
1148 MSIMaskedEdit_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
1150 struct msi_maskedit_info *info;
1153 TRACE("%p %04x %08x %08lx\n", hWnd, msg, wParam, lParam);
1155 info = GetPropW(hWnd, szButtonData);
1157 r = CallWindowProcW(info->oldproc, hWnd, msg, wParam, lParam);
1162 if (HIWORD(wParam) == EN_CHANGE)
1164 msi_mask_control_change( info );
1165 msi_mask_next_control( info, (HWND) lParam );
1169 msi_free( info->prop );
1171 RemovePropW( hWnd, szButtonData );
1178 /* fish the various bits of the property out and put them in the control */
1180 msi_maskedit_set_text( struct msi_maskedit_info *info, LPCWSTR text )
1186 for( i = 0; i < info->num_groups; i++ )
1188 if( info->group[i].len < lstrlenW( p ) )
1190 LPWSTR chunk = strdupW( p );
1191 chunk[ info->group[i].len ] = 0;
1192 SetWindowTextW( info->group[i].hwnd, chunk );
1197 SetWindowTextW( info->group[i].hwnd, p );
1200 p += info->group[i].len;
1204 static struct msi_maskedit_info * msi_dialog_parse_groups( LPCWSTR mask )
1206 struct msi_maskedit_info * info = NULL;
1207 int i = 0, n = 0, total = 0;
1210 TRACE("masked control, template %s\n", debugstr_w(mask));
1215 info = msi_alloc_zero( sizeof *info );
1219 p = strchrW(mask, '<');
1225 for( i=0; i<MASK_MAX_GROUPS; i++ )
1227 /* stop at the end of the string */
1228 if( p[0] == 0 || p[0] == '>' )
1231 /* count the number of the same identifier */
1232 for( n=0; p[n] == p[0]; n++ )
1234 info->group[i].ofs = total;
1235 info->group[i].type = p[0];
1239 total++; /* an extra not part of the group */
1241 info->group[i].len = n;
1246 TRACE("%d characters in %d groups\n", total, i );
1247 if( i == MASK_MAX_GROUPS )
1248 ERR("too many groups in PIDTemplate %s\n", debugstr_w(mask));
1250 info->num_chars = total;
1251 info->num_groups = i;
1257 msi_maskedit_create_children( struct msi_maskedit_info *info, LPCWSTR font )
1259 DWORD width, height, style, wx, ww;
1264 style = WS_CHILD | WS_BORDER | WS_VISIBLE | WS_TABSTOP | ES_AUTOHSCROLL;
1266 GetClientRect( info->hwnd, &rect );
1268 width = rect.right - rect.left;
1269 height = rect.bottom - rect.top;
1271 for( i = 0; i < info->num_groups; i++ )
1273 if (!msi_mask_editable( info->group[i].type ))
1275 wx = (info->group[i].ofs * width) / info->num_chars;
1276 ww = (info->group[i].len * width) / info->num_chars;
1278 hwnd = CreateWindowW( szEdit, NULL, style, wx, 0, ww, height,
1279 info->hwnd, NULL, NULL, NULL );
1282 ERR("failed to create mask edit sub window\n");
1286 SendMessageW( hwnd, EM_LIMITTEXT, info->group[i].len, 0 );
1288 msi_dialog_set_font( info->dialog, hwnd,
1289 font?font:info->dialog->default_font );
1290 info->group[i].hwnd = hwnd;
1295 * office 2003 uses "73931<````=````=````=````=`````>@@@@@"
1296 * delphi 7 uses "<????-??????-??????-????>" and "<???-???>"
1297 * filemaker pro 7 uses "<^^^^=^^^^=^^^^=^^^^=^^^^=^^^^=^^^^^>"
1299 static UINT msi_dialog_maskedit_control( msi_dialog *dialog, MSIRECORD *rec )
1301 LPWSTR font_mask, val = NULL, font;
1302 struct msi_maskedit_info *info = NULL;
1303 UINT ret = ERROR_SUCCESS;
1304 msi_control *control;
1309 font_mask = msi_get_deformatted_field( dialog->package, rec, 10 );
1310 font = msi_dialog_get_style( font_mask, &mask );
1313 ERR("mask template is empty\n");
1317 info = msi_dialog_parse_groups( mask );
1320 ERR("template %s is invalid\n", debugstr_w(mask));
1324 info->dialog = dialog;
1326 control = msi_dialog_add_control( dialog, rec, szStatic,
1327 SS_OWNERDRAW | WS_GROUP | WS_VISIBLE );
1330 ERR("Failed to create maskedit container\n");
1331 ret = ERROR_FUNCTION_FAILED;
1334 SetWindowLongPtrW( control->hwnd, GWL_EXSTYLE, WS_EX_CONTROLPARENT );
1336 info->hwnd = control->hwnd;
1338 /* subclass the static control */
1339 info->oldproc = (WNDPROC) SetWindowLongPtrW( info->hwnd, GWLP_WNDPROC,
1340 (LONG_PTR)MSIMaskedEdit_WndProc );
1341 SetPropW( control->hwnd, szButtonData, info );
1343 prop = MSI_RecordGetString( rec, 9 );
1345 info->prop = strdupW( prop );
1347 msi_maskedit_create_children( info, font );
1351 val = msi_dup_property( dialog->package, prop );
1354 msi_maskedit_set_text( info, val );
1360 if( ret != ERROR_SUCCESS )
1362 msi_free( font_mask );
1367 /******************** Progress Bar *****************************************/
1369 static UINT msi_dialog_progress_bar( msi_dialog *dialog, MSIRECORD *rec )
1371 msi_dialog_add_control( dialog, rec, PROGRESS_CLASSW, WS_VISIBLE );
1372 return ERROR_SUCCESS;
1375 /******************** Path Edit ********************************************/
1377 static LPWSTR msi_get_window_text( HWND hwnd )
1383 buf = msi_alloc( sz*sizeof(WCHAR) );
1386 r = GetWindowTextW( hwnd, buf, sz );
1390 buf = msi_realloc( buf, sz*sizeof(WCHAR) );
1396 static UINT msi_dialog_pathedit_handler( msi_dialog *dialog,
1397 msi_control *control, WPARAM param )
1402 if( HIWORD(param) != EN_KILLFOCUS )
1403 return ERROR_SUCCESS;
1405 indirect = control->attributes & msidbControlAttributesIndirect;
1406 prop = msi_dialog_dup_property( dialog, control->property, indirect );
1408 /* FIXME: verify the new path */
1409 buf = msi_get_window_text( control->hwnd );
1410 MSI_SetPropertyW( dialog->package, prop, buf );
1412 TRACE("edit %s contents changed, set %s\n", debugstr_w(control->name),
1418 return ERROR_SUCCESS;
1421 static void msi_dialog_update_pathedit( msi_dialog *dialog )
1423 msi_control *control;
1427 control = msi_dialog_find_control( dialog, szPathEdit );
1430 indirect = control->attributes & msidbControlAttributesIndirect;
1431 prop = msi_dialog_dup_property( dialog, control->property, indirect );
1433 path = msi_dup_property( dialog->package, prop );
1434 SetWindowTextW( control->hwnd, path );
1435 SendMessageW( control->hwnd, EM_SETSEL, 0, -1 );
1441 static UINT msi_dialog_pathedit_control( msi_dialog *dialog, MSIRECORD *rec )
1443 msi_control *control;
1446 control = msi_dialog_add_control( dialog, rec, szEdit,
1447 WS_BORDER | WS_TABSTOP );
1448 control->handler = msi_dialog_pathedit_handler;
1449 control->attributes = MSI_RecordGetInteger( rec, 8 );
1450 prop = MSI_RecordGetString( rec, 9 );
1451 control->property = msi_dialog_dup_property( dialog, prop, FALSE );
1453 msi_dialog_update_pathedit( dialog );
1455 return ERROR_SUCCESS;
1458 /* radio buttons are a bit different from normal controls */
1459 static UINT msi_dialog_create_radiobutton( MSIRECORD *rec, LPVOID param )
1461 radio_button_group_descr *group = (radio_button_group_descr *)param;
1462 msi_dialog *dialog = group->dialog;
1463 msi_control *control;
1464 LPCWSTR prop, text, name;
1465 DWORD style, attributes = group->attributes;
1467 style = WS_CHILD | BS_AUTORADIOBUTTON | BS_MULTILINE | WS_TABSTOP;
1468 name = MSI_RecordGetString( rec, 3 );
1469 text = MSI_RecordGetString( rec, 8 );
1470 if( attributes & 1 )
1471 style |= WS_VISIBLE;
1472 if( ~attributes & 2 )
1473 style |= WS_DISABLED;
1475 control = msi_dialog_create_window( dialog, rec, 0, szButton, name, text,
1476 style, group->parent->hwnd );
1478 return ERROR_FUNCTION_FAILED;
1479 control->handler = msi_dialog_radiogroup_handler;
1481 if (!lstrcmpW(control->name, group->propval))
1482 SendMessageW(control->hwnd, BM_SETCHECK, BST_CHECKED, 0);
1484 prop = MSI_RecordGetString( rec, 1 );
1486 control->property = strdupW( prop );
1488 return ERROR_SUCCESS;
1491 static UINT msi_dialog_radiogroup_control( msi_dialog *dialog, MSIRECORD *rec )
1493 static const WCHAR query[] = {
1494 'S','E','L','E','C','T',' ','*',' ',
1495 'F','R','O','M',' ','R','a','d','i','o','B','u','t','t','o','n',' ',
1496 'W','H','E','R','E',' ',
1497 '`','P','r','o','p','e','r','t','y','`',' ','=',' ','\'','%','s','\'',0};
1500 msi_control *control;
1501 MSIQUERY *view = NULL;
1502 radio_button_group_descr group;
1503 MSIPACKAGE *package = dialog->package;
1506 prop = MSI_RecordGetString( rec, 9 );
1508 TRACE("%p %p %s\n", dialog, rec, debugstr_w( prop ));
1510 /* Create parent group box to hold radio buttons */
1511 control = msi_dialog_add_control( dialog, rec, szButton, BS_OWNERDRAW|WS_GROUP );
1513 return ERROR_FUNCTION_FAILED;
1515 oldproc = (WNDPROC) SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
1516 (LONG_PTR)MSIRadioGroup_WndProc );
1517 SetPropW(control->hwnd, szButtonData, oldproc);
1518 SetWindowLongPtrW( control->hwnd, GWL_EXSTYLE, WS_EX_CONTROLPARENT );
1521 control->property = strdupW( prop );
1523 /* query the Radio Button table for all control in this group */
1524 r = MSI_OpenQuery( package->db, &view, query, prop );
1525 if( r != ERROR_SUCCESS )
1527 ERR("query failed for dialog %s radio group %s\n",
1528 debugstr_w(dialog->name), debugstr_w(prop));
1529 return ERROR_INVALID_PARAMETER;
1532 group.dialog = dialog;
1533 group.parent = control;
1534 group.attributes = MSI_RecordGetInteger( rec, 8 );
1535 group.propval = msi_dup_property( dialog->package, control->property );
1537 r = MSI_IterateRecords( view, 0, msi_dialog_create_radiobutton, &group );
1538 msiobj_release( &view->hdr );
1539 msi_free( group.propval );
1544 /******************** Selection Tree ***************************************/
1546 struct msi_selection_tree_info
1554 msi_seltree_sync_item_state( HWND hwnd, MSIFEATURE *feature, HTREEITEM hItem )
1558 TRACE("Feature %s -> %d %d %d\n", debugstr_w(feature->Title),
1559 feature->Installed, feature->Action, feature->ActionRequest);
1561 tvi.mask = TVIF_STATE;
1563 tvi.state = INDEXTOSTATEIMAGEMASK( feature->Action );
1564 tvi.stateMask = TVIS_STATEIMAGEMASK;
1566 SendMessageW( hwnd, TVM_SETITEMW, 0, (LPARAM) &tvi );
1570 msi_seltree_popup_menu( HWND hwnd, INT x, INT y )
1575 /* create a menu to display */
1576 hMenu = CreatePopupMenu();
1578 /* FIXME: load strings from resources */
1579 AppendMenuA( hMenu, MF_ENABLED, INSTALLSTATE_LOCAL, "Install feature locally");
1580 AppendMenuA( hMenu, MF_GRAYED, 0x1000, "Install entire feature");
1581 AppendMenuA( hMenu, MF_ENABLED, INSTALLSTATE_ADVERTISED, "Install on demand");
1582 AppendMenuA( hMenu, MF_ENABLED, INSTALLSTATE_ABSENT, "Don't install");
1583 r = TrackPopupMenu( hMenu, TPM_LEFTALIGN | TPM_TOPALIGN | TPM_RETURNCMD,
1584 x, y, 0, hwnd, NULL );
1585 DestroyMenu( hMenu );
1590 msi_seltree_feature_from_item( HWND hwnd, HTREEITEM hItem )
1594 /* get the feature from the item */
1595 memset( &tvi, 0, sizeof tvi );
1597 tvi.mask = TVIF_PARAM | TVIF_HANDLE;
1598 SendMessageW( hwnd, TVM_GETITEMW, 0, (LPARAM) &tvi );
1600 return (MSIFEATURE*) tvi.lParam;
1604 msi_seltree_menu( HWND hwnd, HTREEITEM hItem )
1606 MSIFEATURE *feature;
1615 feature = msi_seltree_feature_from_item( hwnd, hItem );
1618 ERR("item %p feature was NULL\n", hItem);
1622 /* get the item's rectangle to put the menu just below it */
1624 SendMessageW( hwnd, TVM_GETITEMRECT, 0, (LPARAM) &u.rc );
1625 MapWindowPoints( hwnd, NULL, u.pt, 2 );
1627 r = msi_seltree_popup_menu( hwnd, u.rc.left, u.rc.top );
1631 case INSTALLSTATE_LOCAL:
1632 case INSTALLSTATE_ADVERTISED:
1633 case INSTALLSTATE_ABSENT:
1634 feature->ActionRequest = r;
1635 feature->Action = r;
1638 FIXME("select feature and all children\n");
1642 msi_seltree_sync_item_state( hwnd, feature, hItem );
1644 /* update the feature's components */
1645 LIST_FOR_EACH_ENTRY( cl, &feature->Components, ComponentList, entry )
1647 cl->component->Action = feature->Action;
1648 cl->component->ActionRequest = feature->ActionRequest;
1654 static LRESULT WINAPI
1655 MSISelectionTree_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
1657 struct msi_selection_tree_info *info;
1658 TVHITTESTINFO tvhti;
1661 TRACE("%p %04x %08x %08lx\n", hWnd, msg, wParam, lParam);
1663 info = GetPropW(hWnd, szButtonData);
1667 case WM_LBUTTONDOWN:
1668 tvhti.pt.x = LOWORD( lParam );
1669 tvhti.pt.y = HIWORD( lParam );
1672 r = CallWindowProcW(info->oldproc, hWnd, TVM_HITTEST, 0, (LPARAM) &tvhti );
1673 if (tvhti.flags & TVHT_ONITEMSTATEICON)
1674 return msi_seltree_menu( hWnd, tvhti.hItem );
1678 r = CallWindowProcW(info->oldproc, hWnd, msg, wParam, lParam);
1684 RemovePropW( hWnd, szButtonData );
1691 msi_seltree_add_child_features( MSIPACKAGE *package, HWND hwnd,
1692 LPCWSTR parent, HTREEITEM hParent )
1694 MSIFEATURE *feature;
1695 TVINSERTSTRUCTW tvis;
1698 LIST_FOR_EACH_ENTRY( feature, &package->features, MSIFEATURE, entry )
1700 if ( lstrcmpW( parent, feature->Feature_Parent ) )
1703 if ( !feature->Title )
1706 if ( !feature->Display )
1709 memset( &tvis, 0, sizeof tvis );
1710 tvis.hParent = hParent;
1711 tvis.hInsertAfter = TVI_LAST;
1712 tvis.u.item.mask = TVIF_TEXT | TVIF_PARAM;
1713 tvis.u.item.pszText = feature->Title;
1714 tvis.u.item.lParam = (LPARAM) feature;
1716 hitem = (HTREEITEM) SendMessageW( hwnd, TVM_INSERTITEMW, 0, (LPARAM) &tvis );
1720 msi_seltree_sync_item_state( hwnd, feature, hitem );
1721 msi_seltree_add_child_features( package, hwnd,
1722 feature->Feature, hitem );
1724 /* the node is expanded if Display is odd */
1725 if ( feature->Display % 2 != 0 )
1726 SendMessageW( hwnd, TVM_EXPAND, TVE_EXPAND, (LPARAM) hitem );
1730 static void msi_seltree_create_imagelist( HWND hwnd )
1732 const int bm_width = 32, bm_height = 16, bm_count = 3;
1733 const int bm_resource = 0x1001;
1738 himl = ImageList_Create( bm_width, bm_height, FALSE, 4, 0 );
1741 ERR("failed to create image list\n");
1745 for (i=0; i<bm_count; i++)
1747 hbmp = LoadBitmapW( msi_hInstance, MAKEINTRESOURCEW(i+bm_resource) );
1750 ERR("failed to load bitmap %d\n", i);
1755 * Add a dummy bitmap at offset zero because the treeview
1756 * can't use it as a state mask (zero means no user state).
1759 ImageList_Add( himl, hbmp, NULL );
1761 ImageList_Add( himl, hbmp, NULL );
1764 SendMessageW( hwnd, TVM_SETIMAGELIST, TVSIL_STATE, (LPARAM)himl );
1767 static UINT msi_dialog_selection_tree( msi_dialog *dialog, MSIRECORD *rec )
1769 msi_control *control;
1771 MSIPACKAGE *package = dialog->package;
1773 struct msi_selection_tree_info *info;
1775 info = msi_alloc( sizeof *info );
1777 return ERROR_FUNCTION_FAILED;
1779 /* create the treeview control */
1780 prop = MSI_RecordGetString( rec, 9 );
1781 style = TVS_HASLINES | TVS_HASBUTTONS | TVS_LINESATROOT;
1782 style |= WS_GROUP | WS_VSCROLL;
1783 control = msi_dialog_add_control( dialog, rec, WC_TREEVIEWW, style );
1787 return ERROR_FUNCTION_FAILED;
1791 info->dialog = dialog;
1792 info->hwnd = control->hwnd;
1793 info->oldproc = (WNDPROC) SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
1794 (LONG_PTR)MSISelectionTree_WndProc );
1795 SetPropW( control->hwnd, szButtonData, info );
1798 msi_seltree_create_imagelist( control->hwnd );
1799 msi_seltree_add_child_features( package, control->hwnd, NULL, NULL );
1801 return ERROR_SUCCESS;
1804 /******************** Group Box ***************************************/
1806 static UINT msi_dialog_group_box( msi_dialog *dialog, MSIRECORD *rec )
1808 msi_control *control;
1811 style = BS_GROUPBOX | WS_CHILD | WS_GROUP;
1812 control = msi_dialog_add_control( dialog, rec, WC_BUTTONW, style );
1814 return ERROR_FUNCTION_FAILED;
1816 return ERROR_SUCCESS;
1819 /******************** List Box ***************************************/
1821 struct msi_listbox_item
1827 struct msi_listbox_info
1833 struct msi_listbox_item *items;
1836 static LRESULT WINAPI MSIListBox_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
1838 struct msi_listbox_info *info;
1842 TRACE("%p %04x %08x %08lx\n", hWnd, msg, wParam, lParam);
1844 info = GetPropW( hWnd, szButtonData );
1848 r = CallWindowProcW( info->oldproc, hWnd, msg, wParam, lParam );
1853 for (j = 0; j < info->num_items; j++)
1855 msi_free( info->items[j].property );
1856 msi_free( info->items[j].value );
1858 msi_free( info->items );
1860 RemovePropW( hWnd, szButtonData );
1867 static UINT msi_listbox_add_item( MSIRECORD *rec, LPVOID param )
1869 struct msi_listbox_info *info = param;
1870 struct msi_listbox_item *item;
1871 LPCWSTR property, value, text;
1872 static int index = 0;
1874 item = &info->items[index++];
1875 property = MSI_RecordGetString( rec, 1 );
1876 value = MSI_RecordGetString( rec, 3 );
1877 text = MSI_RecordGetString( rec, 4 );
1879 item->property = strdupW( property );
1880 item->value = strdupW( value );
1882 SendMessageW( info->hwnd, LB_ADDSTRING, 0, (LPARAM)text );
1884 return ERROR_SUCCESS;
1887 static UINT msi_listbox_add_items( struct msi_listbox_info *info )
1890 MSIQUERY *view = NULL;
1893 static const WCHAR query[] = {
1894 'S','E','L','E','C','T',' ','*',' ',
1895 'F','R','O','M',' ','`','L','i','s','t','B','o','x','`',' ',
1896 'O','R','D','E','R',' ','B','Y',' ','`','O','r','d','e','r','`',0
1899 r = MSI_OpenQuery( info->dialog->package->db, &view, query );
1900 if ( r != ERROR_SUCCESS )
1903 /* just get the number of records */
1904 r = MSI_IterateRecords( view, &count, NULL, NULL );
1906 info->num_items = count;
1907 info->items = msi_alloc( sizeof(*info->items) * count );
1909 r = MSI_IterateRecords( view, NULL, msi_listbox_add_item, info );
1910 msiobj_release( &view->hdr );
1915 static UINT msi_dialog_listbox_handler( msi_dialog *dialog,
1916 msi_control *control, WPARAM param )
1918 struct msi_listbox_info *info;
1921 if( HIWORD(param) != LBN_SELCHANGE )
1922 return ERROR_SUCCESS;
1924 info = GetPropW( control->hwnd, szButtonData );
1925 index = SendMessageW( control->hwnd, LB_GETCURSEL, 0, 0 );
1927 MSI_SetPropertyW( info->dialog->package,
1928 info->items[index].property, info->items[index].value );
1929 msi_dialog_evaluate_control_conditions( info->dialog );
1931 return ERROR_SUCCESS;
1934 static UINT msi_dialog_list_box( msi_dialog *dialog, MSIRECORD *rec )
1936 struct msi_listbox_info *info;
1937 msi_control *control;
1940 info = msi_alloc( sizeof *info );
1942 return ERROR_FUNCTION_FAILED;
1944 style = WS_TABSTOP | WS_GROUP | WS_CHILD | LBS_STANDARD;
1945 control = msi_dialog_add_control( dialog, rec, WC_LISTBOXW, style );
1947 return ERROR_FUNCTION_FAILED;
1949 control->handler = msi_dialog_listbox_handler;
1952 info->dialog = dialog;
1953 info->hwnd = control->hwnd;
1955 info->oldproc = (WNDPROC)SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
1956 (LONG_PTR)MSIListBox_WndProc );
1957 SetPropW( control->hwnd, szButtonData, info );
1959 msi_listbox_add_items( info );
1961 return ERROR_SUCCESS;
1964 /******************** Directory Combo ***************************************/
1966 static void msi_dialog_update_directory_combo( msi_dialog *dialog )
1968 msi_control *control;
1972 control = msi_dialog_find_control( dialog, szDirectoryCombo );
1973 indirect = control->attributes & msidbControlAttributesIndirect;
1974 prop = msi_dialog_dup_property( dialog, control->property, indirect );
1975 path = msi_dup_property( dialog->package, prop );
1977 PathStripPathW( path );
1978 PathRemoveBackslashW( path );
1980 SendMessageW( control->hwnd, CB_INSERTSTRING, 0, (LPARAM)path );
1981 SendMessageW( control->hwnd, CB_SETCURSEL, 0, 0 );
1987 static UINT msi_dialog_directory_combo( msi_dialog *dialog, MSIRECORD *rec )
1989 msi_control *control;
1993 /* FIXME: use CBS_OWNERDRAWFIXED and add owner draw code */
1994 style = CBS_DROPDOWNLIST | CBS_HASSTRINGS | WS_CHILD |
1995 WS_GROUP | WS_TABSTOP | WS_VSCROLL;
1996 control = msi_dialog_add_control( dialog, rec, WC_COMBOBOXW, style );
1998 return ERROR_FUNCTION_FAILED;
2000 control->attributes = MSI_RecordGetInteger( rec, 8 );
2001 prop = MSI_RecordGetString( rec, 9 );
2002 control->property = msi_dialog_dup_property( dialog, prop, FALSE );
2004 msi_dialog_update_directory_combo( dialog );
2006 return ERROR_SUCCESS;
2009 /******************** Directory List ***************************************/
2011 UINT msi_dialog_directorylist_up( msi_dialog *dialog )
2013 msi_control *control;
2014 LPWSTR prop, path, ptr;
2017 control = msi_dialog_find_control( dialog, szDirectoryList );
2018 indirect = control->attributes & msidbControlAttributesIndirect;
2019 prop = msi_dialog_dup_property( dialog, control->property, indirect );
2021 path = msi_dup_property( dialog->package, prop );
2023 /* strip off the last directory */
2024 ptr = PathFindFileNameW( path );
2025 if (ptr != path) *(ptr - 1) = '\0';
2026 PathAddBackslashW( path );
2028 MSI_SetPropertyW( dialog->package, prop, path );
2030 msi_dialog_update_directory_combo( dialog );
2031 msi_dialog_update_pathedit( dialog );
2036 return ERROR_SUCCESS;
2039 static UINT msi_dialog_directory_list( msi_dialog *dialog, MSIRECORD *rec )
2041 msi_control *control;
2045 style = LVS_LIST | LVS_EDITLABELS | WS_VSCROLL | LVS_SHAREIMAGELISTS |
2046 LVS_AUTOARRANGE | LVS_SINGLESEL | WS_BORDER |
2047 LVS_SORTASCENDING | WS_CHILD | WS_GROUP | WS_TABSTOP;
2048 control = msi_dialog_add_control( dialog, rec, WC_LISTVIEWW, style );
2050 return ERROR_FUNCTION_FAILED;
2052 control->attributes = MSI_RecordGetInteger( rec, 8 );
2053 prop = MSI_RecordGetString( rec, 9 );
2054 control->property = msi_dialog_dup_property( dialog, prop, FALSE );
2056 return ERROR_SUCCESS;
2059 /******************** VolumeCost List ***************************************/
2061 static UINT msi_dialog_volumecost_list( msi_dialog *dialog, MSIRECORD *rec )
2063 msi_control *control;
2066 style = LVS_REPORT | WS_VSCROLL | WS_HSCROLL | LVS_SHAREIMAGELISTS |
2067 LVS_AUTOARRANGE | LVS_SINGLESEL | WS_BORDER |
2068 WS_CHILD | WS_TABSTOP | WS_GROUP;
2069 control = msi_dialog_add_control( dialog, rec, WC_LISTVIEWW, style );
2071 return ERROR_FUNCTION_FAILED;
2073 return ERROR_SUCCESS;
2076 static const struct control_handler msi_dialog_handler[] =
2078 { szText, msi_dialog_text_control },
2079 { szPushButton, msi_dialog_button_control },
2080 { szLine, msi_dialog_line_control },
2081 { szBitmap, msi_dialog_bitmap_control },
2082 { szCheckBox, msi_dialog_checkbox_control },
2083 { szScrollableText, msi_dialog_scrolltext_control },
2084 { szComboBox, msi_dialog_combo_control },
2085 { szEdit, msi_dialog_edit_control },
2086 { szMaskedEdit, msi_dialog_maskedit_control },
2087 { szPathEdit, msi_dialog_pathedit_control },
2088 { szProgressBar, msi_dialog_progress_bar },
2089 { szRadioButtonGroup, msi_dialog_radiogroup_control },
2090 { szIcon, msi_dialog_icon_control },
2091 { szSelectionTree, msi_dialog_selection_tree },
2092 { szGroupBox, msi_dialog_group_box },
2093 { szListBox, msi_dialog_list_box },
2094 { szDirectoryCombo, msi_dialog_directory_combo },
2095 { szDirectoryList, msi_dialog_directory_list },
2096 { szVolumeCostList, msi_dialog_volumecost_list },
2099 #define NUM_CONTROL_TYPES (sizeof msi_dialog_handler/sizeof msi_dialog_handler[0])
2101 static UINT msi_dialog_create_controls( MSIRECORD *rec, LPVOID param )
2103 msi_dialog *dialog = param;
2104 LPCWSTR control_type;
2107 /* find and call the function that can create this type of control */
2108 control_type = MSI_RecordGetString( rec, 3 );
2109 for( i=0; i<NUM_CONTROL_TYPES; i++ )
2110 if (!strcmpiW( msi_dialog_handler[i].control_type, control_type ))
2112 if( i != NUM_CONTROL_TYPES )
2113 msi_dialog_handler[i].func( dialog, rec );
2115 ERR("no handler for element type %s\n", debugstr_w(control_type));
2117 return ERROR_SUCCESS;
2120 static UINT msi_dialog_fill_controls( msi_dialog *dialog )
2122 static const WCHAR query[] = {
2123 'S','E','L','E','C','T',' ','*',' ',
2124 'F','R','O','M',' ','C','o','n','t','r','o','l',' ',
2125 'W','H','E','R','E',' ',
2126 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',0};
2128 MSIQUERY *view = NULL;
2129 MSIPACKAGE *package = dialog->package;
2131 TRACE("%p %s\n", dialog, debugstr_w(dialog->name) );
2133 /* query the Control table for all the elements of the control */
2134 r = MSI_OpenQuery( package->db, &view, query, dialog->name );
2135 if( r != ERROR_SUCCESS )
2137 ERR("query failed for dialog %s\n", debugstr_w(dialog->name));
2138 return ERROR_INVALID_PARAMETER;
2141 r = MSI_IterateRecords( view, 0, msi_dialog_create_controls, dialog );
2142 msiobj_release( &view->hdr );
2147 static UINT msi_dialog_set_control_condition( MSIRECORD *rec, LPVOID param )
2149 static const WCHAR szHide[] = { 'H','i','d','e',0 };
2150 static const WCHAR szShow[] = { 'S','h','o','w',0 };
2151 static const WCHAR szDisable[] = { 'D','i','s','a','b','l','e',0 };
2152 static const WCHAR szEnable[] = { 'E','n','a','b','l','e',0 };
2153 msi_dialog *dialog = param;
2154 msi_control *control;
2155 LPCWSTR name, action, condition;
2158 name = MSI_RecordGetString( rec, 2 );
2159 action = MSI_RecordGetString( rec, 3 );
2160 condition = MSI_RecordGetString( rec, 4 );
2161 r = MSI_EvaluateConditionW( dialog->package, condition );
2162 control = msi_dialog_find_control( dialog, name );
2163 if( r == MSICONDITION_TRUE && control )
2165 TRACE("%s control %s\n", debugstr_w(action), debugstr_w(name));
2167 /* FIXME: case sensitive? */
2168 if(!lstrcmpW(action, szHide))
2169 ShowWindow(control->hwnd, SW_HIDE);
2170 else if(!strcmpW(action, szShow))
2171 ShowWindow(control->hwnd, SW_SHOW);
2172 else if(!strcmpW(action, szDisable))
2173 EnableWindow(control->hwnd, FALSE);
2174 else if(!strcmpW(action, szEnable))
2175 EnableWindow(control->hwnd, TRUE);
2177 FIXME("Unhandled action %s\n", debugstr_w(action));
2180 return ERROR_SUCCESS;
2183 static UINT msi_dialog_evaluate_control_conditions( msi_dialog *dialog )
2185 static const WCHAR query[] = {
2186 'S','E','L','E','C','T',' ','*',' ',
2187 'F','R','O','M',' ',
2188 'C','o','n','t','r','o','l','C','o','n','d','i','t','i','o','n',' ',
2189 'W','H','E','R','E',' ',
2190 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',0
2193 MSIQUERY *view = NULL;
2194 MSIPACKAGE *package = dialog->package;
2196 TRACE("%p %s\n", dialog, debugstr_w(dialog->name) );
2198 /* query the Control table for all the elements of the control */
2199 r = MSI_OpenQuery( package->db, &view, query, dialog->name );
2200 if( r != ERROR_SUCCESS )
2202 ERR("query failed for dialog %s\n", debugstr_w(dialog->name));
2203 return ERROR_INVALID_PARAMETER;
2206 r = MSI_IterateRecords( view, 0, msi_dialog_set_control_condition, dialog );
2207 msiobj_release( &view->hdr );
2212 UINT msi_dialog_reset( msi_dialog *dialog )
2214 /* FIXME: should restore the original values of any properties we changed */
2215 return msi_dialog_evaluate_control_conditions( dialog );
2218 /* figure out the height of 10 point MS Sans Serif */
2219 static INT msi_dialog_get_sans_serif_height( HWND hwnd )
2221 static const WCHAR szSansSerif[] = {
2222 'M','S',' ','S','a','n','s',' ','S','e','r','i','f',0 };
2227 HFONT hFont, hOldFont;
2230 hdc = GetDC( hwnd );
2233 memset( &lf, 0, sizeof lf );
2234 lf.lfHeight = MulDiv(10, GetDeviceCaps(hdc, LOGPIXELSY), 72);
2235 strcpyW( lf.lfFaceName, szSansSerif );
2236 hFont = CreateFontIndirectW(&lf);
2239 hOldFont = SelectObject( hdc, hFont );
2240 r = GetTextMetricsW( hdc, &tm );
2242 height = tm.tmHeight;
2243 SelectObject( hdc, hOldFont );
2244 DeleteObject( hFont );
2246 ReleaseDC( hwnd, hdc );
2251 /* fetch the associated record from the Dialog table */
2252 static MSIRECORD *msi_get_dialog_record( msi_dialog *dialog )
2254 static const WCHAR query[] = {
2255 'S','E','L','E','C','T',' ','*',' ',
2256 'F','R','O','M',' ','D','i','a','l','o','g',' ',
2257 'W','H','E','R','E',' ',
2258 '`','D','i','a','l','o','g','`',' ','=',' ','\'','%','s','\'',0};
2259 MSIPACKAGE *package = dialog->package;
2260 MSIRECORD *rec = NULL;
2262 TRACE("%p %s\n", dialog, debugstr_w(dialog->name) );
2264 rec = MSI_QueryGetRecord( package->db, query, dialog->name );
2266 ERR("query failed for dialog %s\n", debugstr_w(dialog->name));
2271 static void msi_dialog_adjust_dialog_pos( msi_dialog *dialog, MSIRECORD *rec, LPRECT pos )
2273 static const WCHAR szScreenX[] = {'S','c','r','e','e','n','X',0};
2274 static const WCHAR szScreenY[] = {'S','c','r','e','e','n','Y',0};
2281 center.x = MSI_RecordGetInteger( rec, 2 );
2282 center.y = MSI_RecordGetInteger( rec, 3 );
2284 sz.cx = MSI_RecordGetInteger( rec, 4 );
2285 sz.cy = MSI_RecordGetInteger( rec, 5 );
2287 sz.cx = msi_dialog_scale_unit( dialog, sz.cx );
2288 sz.cy = msi_dialog_scale_unit( dialog, sz.cy );
2290 xres = msi_get_property_int( dialog->package, szScreenX, 0 );
2291 yres = msi_get_property_int( dialog->package, szScreenY, 0 );
2293 center.x = MulDiv( center.x, xres, 100 );
2294 center.y = MulDiv( center.y, yres, 100 );
2296 /* turn the client pos into the window rectangle */
2297 pos->left = center.x - sz.cx/2;
2298 pos->right = pos->left + sz.cx;
2299 pos->top = center.y - sz.cy/2;
2300 pos->bottom = pos->top + sz.cy;
2302 TRACE("%lu %lu %lu %lu\n", pos->left, pos->top, pos->right, pos->bottom);
2304 style = GetWindowLongPtrW( dialog->hwnd, GWL_STYLE );
2305 AdjustWindowRect( pos, style, FALSE );
2308 static BOOL msi_control_set_next( msi_control *control, msi_control *next )
2310 return SetWindowPos( next->hwnd, control->hwnd, 0, 0, 0, 0,
2311 SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOREDRAW |
2312 SWP_NOREPOSITION | SWP_NOSENDCHANGING | SWP_NOSIZE );
2315 static UINT msi_dialog_set_tab_order( msi_dialog *dialog )
2317 msi_control *control, *tab_next;
2319 LIST_FOR_EACH_ENTRY( control, &dialog->controls, msi_control, entry )
2321 tab_next = msi_dialog_find_control( dialog, control->tabnext );
2324 msi_control_set_next( control, tab_next );
2327 return ERROR_SUCCESS;
2330 static void msi_dialog_set_first_control( msi_dialog* dialog, LPCWSTR name )
2332 msi_control *control;
2334 control = msi_dialog_find_control( dialog, name );
2336 dialog->hWndFocus = control->hwnd;
2338 dialog->hWndFocus = NULL;
2341 static LRESULT msi_dialog_oncreate( HWND hwnd, LPCREATESTRUCTW cs )
2343 static const WCHAR df[] = {
2344 'D','e','f','a','u','l','t','U','I','F','o','n','t',0 };
2345 static const WCHAR dfv[] = {
2346 'M','S',' ','S','h','e','l','l',' ','D','l','g',0 };
2347 msi_dialog *dialog = (msi_dialog*) cs->lpCreateParams;
2348 MSIRECORD *rec = NULL;
2349 LPWSTR title = NULL;
2352 TRACE("%p %p\n", dialog, dialog->package);
2354 dialog->hwnd = hwnd;
2355 SetWindowLongPtrW( hwnd, GWLP_USERDATA, (LONG_PTR) dialog );
2357 rec = msi_get_dialog_record( dialog );
2360 TRACE("No record found for dialog %s\n", debugstr_w(dialog->name));
2364 dialog->scale = msi_dialog_get_sans_serif_height(dialog->hwnd);
2366 msi_dialog_adjust_dialog_pos( dialog, rec, &pos );
2368 dialog->attributes = MSI_RecordGetInteger( rec, 6 );
2370 dialog->default_font = msi_dup_property( dialog->package, df );
2371 if (!dialog->default_font)
2373 dialog->default_font = strdupW(dfv);
2374 if (!dialog->default_font) return -1;
2377 title = msi_get_deformatted_field( dialog->package, rec, 7 );
2378 SetWindowTextW( hwnd, title );
2381 SetWindowPos( hwnd, 0, pos.left, pos.top,
2382 pos.right - pos.left, pos.bottom - pos.top,
2383 SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOREDRAW );
2385 msi_dialog_build_font_list( dialog );
2386 msi_dialog_fill_controls( dialog );
2387 msi_dialog_evaluate_control_conditions( dialog );
2388 msi_dialog_set_tab_order( dialog );
2389 msi_dialog_set_first_control( dialog, MSI_RecordGetString( rec, 8 ) );
2390 msiobj_release( &rec->hdr );
2395 static UINT msi_dialog_send_event( msi_dialog *dialog, LPCWSTR event, LPCWSTR arg )
2397 LPWSTR event_fmt = NULL, arg_fmt = NULL;
2399 TRACE("Sending control event %s %s\n", debugstr_w(event), debugstr_w(arg));
2401 deformat_string( dialog->package, event, &event_fmt );
2402 deformat_string( dialog->package, arg, &arg_fmt );
2404 dialog->event_handler( dialog->package, event_fmt, arg_fmt, dialog );
2406 msi_free( event_fmt );
2407 msi_free( arg_fmt );
2409 return ERROR_SUCCESS;
2412 static UINT msi_dialog_set_property( msi_dialog *dialog, LPCWSTR event, LPCWSTR arg )
2414 static const WCHAR szNullArg[] = { '{','}',0 };
2415 LPWSTR p, prop, arg_fmt = NULL;
2418 len = strlenW(event);
2419 prop = msi_alloc( len*sizeof(WCHAR));
2420 strcpyW( prop, &event[1] );
2421 p = strchrW( prop, ']' );
2422 if( p && p[1] == 0 )
2425 if( strcmpW( szNullArg, arg ) )
2426 deformat_string( dialog->package, arg, &arg_fmt );
2427 MSI_SetPropertyW( dialog->package, prop, arg_fmt );
2428 msi_free( arg_fmt );
2431 ERR("Badly formatted property string - what happens?\n");
2433 return ERROR_SUCCESS;
2436 static UINT msi_dialog_control_event( MSIRECORD *rec, LPVOID param )
2438 msi_dialog *dialog = param;
2439 LPCWSTR condition, event, arg;
2442 condition = MSI_RecordGetString( rec, 5 );
2443 r = MSI_EvaluateConditionW( dialog->package, condition );
2444 if( r == MSICONDITION_TRUE || r == MSICONDITION_NONE )
2446 event = MSI_RecordGetString( rec, 3 );
2447 arg = MSI_RecordGetString( rec, 4 );
2448 if( event[0] == '[' )
2449 msi_dialog_set_property( dialog, event, arg );
2451 msi_dialog_send_event( dialog, event, arg );
2454 return ERROR_SUCCESS;
2457 static UINT msi_dialog_button_handler( msi_dialog *dialog,
2458 msi_control *control, WPARAM param )
2460 static const WCHAR query[] = {
2461 'S','E','L','E','C','T',' ','*',' ',
2462 'F','R','O','M',' ','C','o','n','t','r','o','l','E','v','e','n','t',' ',
2463 'W','H','E','R','E',' ',
2464 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',' ',
2466 '`','C','o','n','t','r','o','l','_','`',' ','=',' ','\'','%','s','\'',' ',
2467 'O','R','D','E','R',' ','B','Y',' ','`','O','r','d','e','r','i','n','g','`',0
2469 MSIQUERY *view = NULL;
2472 if( HIWORD(param) != BN_CLICKED )
2473 return ERROR_SUCCESS;
2475 r = MSI_OpenQuery( dialog->package->db, &view, query,
2476 dialog->name, control->name );
2477 if( r != ERROR_SUCCESS )
2479 ERR("query failed\n");
2483 r = MSI_IterateRecords( view, 0, msi_dialog_control_event, dialog );
2484 msiobj_release( &view->hdr );
2489 static UINT msi_dialog_get_checkbox_state( msi_dialog *dialog,
2490 msi_control *control )
2492 WCHAR state[2] = { 0 };
2495 MSI_GetPropertyW( dialog->package, control->property, state, &sz );
2496 return state[0] ? 1 : 0;
2499 static void msi_dialog_set_checkbox_state( msi_dialog *dialog,
2500 msi_control *control, UINT state )
2502 static const WCHAR szState[] = { '1', 0 };
2505 /* if uncheck then the property is set to NULL */
2508 MSI_SetPropertyW( dialog->package, control->property, NULL );
2512 /* check for a custom state */
2513 if (control->value && control->value[0])
2514 val = control->value;
2518 MSI_SetPropertyW( dialog->package, control->property, val );
2521 static void msi_dialog_checkbox_sync_state( msi_dialog *dialog,
2522 msi_control *control )
2526 state = msi_dialog_get_checkbox_state( dialog, control );
2527 SendMessageW( control->hwnd, BM_SETCHECK,
2528 state ? BST_CHECKED : BST_UNCHECKED, 0 );
2531 static UINT msi_dialog_checkbox_handler( msi_dialog *dialog,
2532 msi_control *control, WPARAM param )
2536 if( HIWORD(param) != BN_CLICKED )
2537 return ERROR_SUCCESS;
2539 TRACE("clicked checkbox %s, set %s\n", debugstr_w(control->name),
2540 debugstr_w(control->property));
2542 state = msi_dialog_get_checkbox_state( dialog, control );
2543 state = state ? 0 : 1;
2544 msi_dialog_set_checkbox_state( dialog, control, state );
2545 msi_dialog_checkbox_sync_state( dialog, control );
2547 return msi_dialog_button_handler( dialog, control, param );
2550 static UINT msi_dialog_edit_handler( msi_dialog *dialog,
2551 msi_control *control, WPARAM param )
2555 if( HIWORD(param) != EN_CHANGE )
2556 return ERROR_SUCCESS;
2558 TRACE("edit %s contents changed, set %s\n", debugstr_w(control->name),
2559 debugstr_w(control->property));
2561 buf = msi_get_window_text( control->hwnd );
2562 MSI_SetPropertyW( dialog->package, control->property, buf );
2566 return ERROR_SUCCESS;
2569 static UINT msi_dialog_radiogroup_handler( msi_dialog *dialog,
2570 msi_control *control, WPARAM param )
2572 if( HIWORD(param) != BN_CLICKED )
2573 return ERROR_SUCCESS;
2575 TRACE("clicked radio button %s, set %s\n", debugstr_w(control->name),
2576 debugstr_w(control->property));
2578 MSI_SetPropertyW( dialog->package, control->property, control->name );
2580 return msi_dialog_button_handler( dialog, control, param );
2583 static LRESULT msi_dialog_oncommand( msi_dialog *dialog, WPARAM param, HWND hwnd )
2585 msi_control *control = NULL;
2587 TRACE("%p %p %08x\n", dialog, hwnd, param);
2592 control = msi_dialog_find_control( dialog, dialog->control_default );
2594 case 2: /* escape */
2595 control = msi_dialog_find_control( dialog, dialog->control_cancel );
2598 control = msi_dialog_find_control_by_hwnd( dialog, hwnd );
2603 if( control->handler )
2605 control->handler( dialog, control, param );
2606 msi_dialog_evaluate_control_conditions( dialog );
2610 ERR("button click from nowhere %p %d %p\n", dialog, param, hwnd);
2614 static void msi_dialog_setfocus( msi_dialog *dialog )
2616 HWND hwnd = dialog->hWndFocus;
2618 hwnd = GetNextDlgTabItem( dialog->hwnd, hwnd, TRUE);
2619 hwnd = GetNextDlgTabItem( dialog->hwnd, hwnd, FALSE);
2621 dialog->hWndFocus = hwnd;
2624 static LRESULT WINAPI MSIDialog_WndProc( HWND hwnd, UINT msg,
2625 WPARAM wParam, LPARAM lParam )
2627 msi_dialog *dialog = (LPVOID) GetWindowLongPtrW( hwnd, GWLP_USERDATA );
2629 TRACE("0x%04x\n", msg);
2634 return msi_dialog_oncreate( hwnd, (LPCREATESTRUCTW)lParam );
2637 return msi_dialog_oncommand( dialog, wParam, (HWND)lParam );
2640 if( LOWORD(wParam) == WA_INACTIVE )
2641 dialog->hWndFocus = GetFocus();
2643 msi_dialog_setfocus( dialog );
2647 msi_dialog_setfocus( dialog );
2650 /* bounce back to our subclassed static control */
2651 case WM_CTLCOLORSTATIC:
2652 return SendMessageW( (HWND) lParam, WM_CTLCOLORSTATIC, wParam, lParam );
2655 dialog->hwnd = NULL;
2658 return DefWindowProcW(hwnd, msg, wParam, lParam);
2661 static BOOL CALLBACK msi_radioground_child_enum( HWND hWnd, LPARAM lParam )
2663 EnableWindow( hWnd, lParam );
2667 static LRESULT WINAPI MSIRadioGroup_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
2669 WNDPROC oldproc = (WNDPROC) GetPropW(hWnd, szButtonData);
2672 TRACE("hWnd %p msg %04x wParam 0x%08x lParam 0x%08lx\n", hWnd, msg, wParam, lParam);
2674 if (msg == WM_COMMAND) /* Forward notifications to dialog */
2675 SendMessageW(GetParent(hWnd), msg, wParam, lParam);
2677 r = CallWindowProcW(oldproc, hWnd, msg, wParam, lParam);
2679 /* make sure the radio buttons show as disabled if the parent is disabled */
2680 if (msg == WM_ENABLE)
2681 EnumChildWindows( hWnd, msi_radioground_child_enum, wParam );
2686 static LRESULT WINAPI MSIHiddenWindowProc( HWND hwnd, UINT msg,
2687 WPARAM wParam, LPARAM lParam )
2689 msi_dialog *dialog = (msi_dialog*) lParam;
2691 TRACE("%d %p\n", msg, dialog);
2695 case WM_MSI_DIALOG_CREATE:
2696 return msi_dialog_run_message_loop( dialog );
2697 case WM_MSI_DIALOG_DESTROY:
2698 msi_dialog_destroy( dialog );
2701 return DefWindowProcW( hwnd, msg, wParam, lParam );
2704 /* functions that interface to other modules within MSI */
2706 msi_dialog *msi_dialog_create( MSIPACKAGE* package, LPCWSTR szDialogName,
2707 msi_dialog_event_handler event_handler )
2709 MSIRECORD *rec = NULL;
2712 TRACE("%p %s\n", package, debugstr_w(szDialogName));
2714 /* allocate the structure for the dialog to use */
2715 dialog = msi_alloc_zero( sizeof *dialog + sizeof(WCHAR)*strlenW(szDialogName) );
2718 strcpyW( dialog->name, szDialogName );
2719 msiobj_addref( &package->hdr );
2720 dialog->package = package;
2721 dialog->event_handler = event_handler;
2722 dialog->finished = 0;
2723 list_init( &dialog->controls );
2725 /* verify that the dialog exists */
2726 rec = msi_get_dialog_record( dialog );
2729 msiobj_release( &package->hdr );
2733 dialog->attributes = MSI_RecordGetInteger( rec, 6 );
2734 dialog->control_default = strdupW( MSI_RecordGetString( rec, 9 ) );
2735 dialog->control_cancel = strdupW( MSI_RecordGetString( rec, 10 ) );
2736 msiobj_release( &rec->hdr );
2741 static void msi_process_pending_messages( HWND hdlg )
2745 while( PeekMessageW( &msg, 0, 0, 0, PM_REMOVE ) )
2747 if( hdlg && IsDialogMessageW( hdlg, &msg ))
2749 TranslateMessage( &msg );
2750 DispatchMessageW( &msg );
2754 void msi_dialog_end_dialog( msi_dialog *dialog )
2756 TRACE("%p\n", dialog);
2757 dialog->finished = 1;
2758 PostMessageW(dialog->hwnd, WM_NULL, 0, 0);
2761 void msi_dialog_check_messages( HANDLE handle )
2765 /* in threads other than the UI thread, block */
2766 if( uiThreadId != GetCurrentThreadId() )
2769 WaitForSingleObject( handle, INFINITE );
2773 /* there's two choices for the UI thread */
2776 msi_process_pending_messages( NULL );
2782 * block here until somebody creates a new dialog or
2783 * the handle we're waiting on becomes ready
2785 r = MsgWaitForMultipleObjects( 1, &handle, 0, INFINITE, QS_ALLINPUT );
2786 if( r == WAIT_OBJECT_0 )
2791 UINT msi_dialog_run_message_loop( msi_dialog *dialog )
2796 if( uiThreadId != GetCurrentThreadId() )
2797 return SendMessageW( hMsiHiddenWindow, WM_MSI_DIALOG_CREATE, 0, (LPARAM) dialog );
2799 /* create the dialog window, don't show it yet */
2800 style = WS_OVERLAPPED;
2801 if( dialog->attributes & msidbDialogAttributesVisible )
2802 style |= WS_VISIBLE;
2804 hwnd = CreateWindowW( szMsiDialogClass, dialog->name, style,
2805 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
2806 NULL, NULL, NULL, dialog );
2809 ERR("Failed to create dialog %s\n", debugstr_w( dialog->name ));
2810 return ERROR_FUNCTION_FAILED;
2813 ShowWindow( hwnd, SW_SHOW );
2814 /* UpdateWindow( hwnd ); - and causes the transparent static controls not to paint */
2816 if( dialog->attributes & msidbDialogAttributesModal )
2818 while( !dialog->finished )
2820 MsgWaitForMultipleObjects( 0, NULL, 0, INFINITE, QS_ALLINPUT );
2821 msi_process_pending_messages( dialog->hwnd );
2825 return ERROR_IO_PENDING;
2827 return ERROR_SUCCESS;
2830 void msi_dialog_do_preview( msi_dialog *dialog )
2833 dialog->attributes |= msidbDialogAttributesVisible;
2834 dialog->attributes &= ~msidbDialogAttributesModal;
2835 msi_dialog_run_message_loop( dialog );
2838 void msi_dialog_destroy( msi_dialog *dialog )
2840 if( uiThreadId != GetCurrentThreadId() )
2842 SendMessageW( hMsiHiddenWindow, WM_MSI_DIALOG_DESTROY, 0, (LPARAM) dialog );
2847 ShowWindow( dialog->hwnd, SW_HIDE );
2850 DestroyWindow( dialog->hwnd );
2852 /* destroy the list of controls */
2853 while( !list_empty( &dialog->controls ) )
2855 msi_control *t = LIST_ENTRY( list_head( &dialog->controls ),
2856 msi_control, entry );
2857 list_remove( &t->entry );
2858 /* leave dialog->hwnd - destroying parent destroys child windows */
2859 msi_free( t->property );
2860 msi_free( t->value );
2862 DeleteObject( t->hBitmap );
2864 DestroyIcon( t->hIcon );
2865 msi_free( t->tabnext );
2868 FreeLibrary( t->hDll );
2871 /* destroy the list of fonts */
2872 while( dialog->font_list )
2874 msi_font *t = dialog->font_list;
2875 dialog->font_list = t->next;
2876 DeleteObject( t->hfont );
2879 msi_free( dialog->default_font );
2881 msi_free( dialog->control_default );
2882 msi_free( dialog->control_cancel );
2883 msiobj_release( &dialog->package->hdr );
2884 dialog->package = NULL;
2888 BOOL msi_dialog_register_class( void )
2892 ZeroMemory( &cls, sizeof cls );
2893 cls.lpfnWndProc = MSIDialog_WndProc;
2894 cls.hInstance = NULL;
2895 cls.hIcon = LoadIconW(0, (LPWSTR)IDI_APPLICATION);
2896 cls.hCursor = LoadCursorW(0, (LPWSTR)IDC_ARROW);
2897 cls.hbrBackground = (HBRUSH)(COLOR_3DFACE + 1);
2898 cls.lpszMenuName = NULL;
2899 cls.lpszClassName = szMsiDialogClass;
2901 if( !RegisterClassW( &cls ) )
2904 cls.lpfnWndProc = MSIHiddenWindowProc;
2905 cls.lpszClassName = szMsiHiddenWindow;
2907 if( !RegisterClassW( &cls ) )
2910 uiThreadId = GetCurrentThreadId();
2912 hMsiHiddenWindow = CreateWindowW( szMsiHiddenWindow, NULL, WS_OVERLAPPED,
2913 0, 0, 100, 100, NULL, NULL, NULL, NULL );
2914 if( !hMsiHiddenWindow )
2920 void msi_dialog_unregister_class( void )
2922 DestroyWindow( hMsiHiddenWindow );
2923 hMsiHiddenWindow = NULL;
2924 UnregisterClassW( szMsiDialogClass, NULL );
2925 UnregisterClassW( szMsiHiddenWindow, NULL );