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
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 szRadioButtonGroup[] = {
139 'R','a','d','i','o','B','u','t','t','o','n','G','r','o','u','p',0 };
140 static const WCHAR szIcon[] = { 'I','c','o','n',0 };
141 static const WCHAR szSelectionTree[] = {
142 'S','e','l','e','c','t','i','o','n','T','r','e','e',0 };
143 static const WCHAR szGroupBox[] = { 'G','r','o','u','p','B','o','x',0 };
144 static const WCHAR szListBox[] = { 'L','i','s','t','B','o','x',0 };
145 static const WCHAR szDirectoryCombo[] = { 'D','i','r','e','c','t','o','r','y','C','o','m','b','o',0 };
146 static const WCHAR szDirectoryList[] = { 'D','i','r','e','c','t','o','r','y','L','i','s','t',0 };
147 static const WCHAR szVolumeCostList[] = { 'V','o','l','u','m','e','C','o','s','t','L','i','s','t',0 };
148 static const WCHAR szSelectionDescription[] = {'S','e','l','e','c','t','i','o','n','D','e','s','c','r','i','p','t','i','o','n',0};
149 static const WCHAR szSelectionPath[] = {'S','e','l','e','c','t','i','o','n','P','a','t','h',0};
150 static const WCHAR szProperty[] = {'P','r','o','p','e','r','t','y',0};
152 static UINT msi_dialog_checkbox_handler( msi_dialog *, msi_control *, WPARAM );
153 static void msi_dialog_checkbox_sync_state( msi_dialog *, msi_control * );
154 static UINT msi_dialog_button_handler( msi_dialog *, msi_control *, WPARAM );
155 static UINT msi_dialog_edit_handler( msi_dialog *, msi_control *, WPARAM );
156 static UINT msi_dialog_radiogroup_handler( msi_dialog *, msi_control *, WPARAM param );
157 static UINT msi_dialog_evaluate_control_conditions( msi_dialog *dialog );
158 static LRESULT WINAPI MSIRadioGroup_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
159 static MSIFEATURE *msi_seltree_get_selected_feature( msi_control *control );
161 /* dialog sequencing */
163 #define WM_MSI_DIALOG_CREATE (WM_USER+0x100)
164 #define WM_MSI_DIALOG_DESTROY (WM_USER+0x101)
166 static DWORD uiThreadId;
167 static HWND hMsiHiddenWindow;
169 static INT msi_dialog_scale_unit( msi_dialog *dialog, INT val )
171 return (dialog->scale * val + 5) / 10;
174 static msi_control *msi_dialog_find_control( msi_dialog *dialog, LPCWSTR name )
176 msi_control *control;
180 LIST_FOR_EACH_ENTRY( control, &dialog->controls, msi_control, entry )
181 if( !strcmpW( control->name, name ) ) /* FIXME: case sensitive? */
186 static msi_control *msi_dialog_find_control_by_type( msi_dialog *dialog, LPCWSTR type )
188 msi_control *control;
192 LIST_FOR_EACH_ENTRY( control, &dialog->controls, msi_control, entry )
193 if( !strcmpW( control->type, type ) ) /* FIXME: case sensitive? */
198 static msi_control *msi_dialog_find_control_by_hwnd( msi_dialog *dialog, HWND hwnd )
200 msi_control *control;
202 LIST_FOR_EACH_ENTRY( control, &dialog->controls, msi_control, entry )
203 if( hwnd == control->hwnd )
208 static LPWSTR msi_get_deformatted_field( MSIPACKAGE *package, MSIRECORD *rec, int field )
210 LPCWSTR str = MSI_RecordGetString( rec, field );
214 deformat_string( package, str, &ret );
218 static LPWSTR msi_dialog_dup_property( msi_dialog *dialog, LPCWSTR property, BOOL indirect )
224 return msi_dup_property( dialog->package, property );
226 return strdupW( property );
229 msi_dialog *msi_dialog_get_parent( msi_dialog *dialog )
231 return dialog->parent;
234 LPWSTR msi_dialog_get_name( msi_dialog *dialog )
240 * msi_dialog_get_style
242 * Extract the {\style} string from the front of the text to display and
243 * update the pointer.
245 static LPWSTR msi_dialog_get_style( LPCWSTR p, LPCWSTR *rest )
256 q = strchrW( p, '}' );
259 if( *p == '\\' || *p == '&' )
262 /* little bit of sanity checking to stop us getting confused with RTF */
264 if( *i == '}' || *i == '\\' )
270 ret = msi_alloc( len*sizeof(WCHAR) );
273 memcpy( ret, p, len*sizeof(WCHAR) );
278 static UINT msi_dialog_add_font( MSIRECORD *rec, LPVOID param )
280 msi_dialog *dialog = param;
287 /* create a font and add it to the list */
288 name = MSI_RecordGetString( rec, 1 );
289 font = msi_alloc( sizeof *font + strlenW( name )*sizeof (WCHAR) );
290 strcpyW( font->name, name );
291 font->next = dialog->font_list;
292 dialog->font_list = font;
294 font->color = MSI_RecordGetInteger( rec, 4 );
296 memset( &lf, 0, sizeof lf );
297 face = MSI_RecordGetString( rec, 2 );
298 lf.lfHeight = MSI_RecordGetInteger( rec, 3 );
299 style = MSI_RecordGetInteger( rec, 5 );
300 if( style & msidbTextStyleStyleBitsBold )
301 lf.lfWeight = FW_BOLD;
302 if( style & msidbTextStyleStyleBitsItalic )
304 if( style & msidbTextStyleStyleBitsUnderline )
305 lf.lfUnderline = TRUE;
306 if( style & msidbTextStyleStyleBitsStrike )
307 lf.lfStrikeOut = TRUE;
308 lstrcpynW( lf.lfFaceName, face, LF_FACESIZE );
310 /* adjust the height */
311 hdc = GetDC( dialog->hwnd );
314 lf.lfHeight = -MulDiv(lf.lfHeight, GetDeviceCaps(hdc, LOGPIXELSY), 72);
315 ReleaseDC( dialog->hwnd, hdc );
318 font->hfont = CreateFontIndirectW( &lf );
320 TRACE("Adding font style %s\n", debugstr_w(font->name) );
322 return ERROR_SUCCESS;
325 static msi_font *msi_dialog_find_font( msi_dialog *dialog, LPCWSTR name )
329 for( font = dialog->font_list; font; font = font->next )
330 if( !strcmpW( font->name, name ) ) /* FIXME: case sensitive? */
336 static UINT msi_dialog_set_font( msi_dialog *dialog, HWND hwnd, LPCWSTR name )
340 font = msi_dialog_find_font( dialog, name );
342 SendMessageW( hwnd, WM_SETFONT, (WPARAM) font->hfont, TRUE );
344 ERR("No font entry for %s\n", debugstr_w(name));
345 return ERROR_SUCCESS;
348 static UINT msi_dialog_build_font_list( msi_dialog *dialog )
350 static const WCHAR query[] = {
351 'S','E','L','E','C','T',' ','*',' ',
352 'F','R','O','M',' ','`','T','e','x','t','S','t','y','l','e','`',' ',0
355 MSIQUERY *view = NULL;
357 TRACE("dialog %p\n", dialog );
359 r = MSI_OpenQuery( dialog->package->db, &view, query );
360 if( r != ERROR_SUCCESS )
363 r = MSI_IterateRecords( view, NULL, msi_dialog_add_font, dialog );
364 msiobj_release( &view->hdr );
369 static msi_control *msi_dialog_create_window( msi_dialog *dialog,
370 MSIRECORD *rec, DWORD exstyle, LPCWSTR szCls, LPCWSTR name, LPCWSTR text,
371 DWORD style, HWND parent )
373 DWORD x, y, width, height;
374 LPWSTR font = NULL, title_font = NULL;
375 LPCWSTR title = NULL;
376 msi_control *control;
380 control = msi_alloc( sizeof *control + strlenW(name)*sizeof(WCHAR) );
381 strcpyW( control->name, name );
382 list_add_head( &dialog->controls, &control->entry );
383 control->handler = NULL;
384 control->property = NULL;
385 control->value = NULL;
386 control->hBitmap = NULL;
387 control->hIcon = NULL;
388 control->hDll = NULL;
389 control->tabnext = strdupW( MSI_RecordGetString( rec, 11) );
390 control->type = strdupW( MSI_RecordGetString( rec, 3 ) );
391 control->progress_current = 0;
392 control->progress_max = 100;
394 x = MSI_RecordGetInteger( rec, 4 );
395 y = MSI_RecordGetInteger( rec, 5 );
396 width = MSI_RecordGetInteger( rec, 6 );
397 height = MSI_RecordGetInteger( rec, 7 );
399 x = msi_dialog_scale_unit( dialog, x );
400 y = msi_dialog_scale_unit( dialog, y );
401 width = msi_dialog_scale_unit( dialog, width );
402 height = msi_dialog_scale_unit( dialog, height );
406 deformat_string( dialog->package, text, &title_font );
407 font = msi_dialog_get_style( title_font, &title );
410 control->hwnd = CreateWindowExW( exstyle, szCls, title, style,
411 x, y, width, height, parent, NULL, NULL, NULL );
413 TRACE("Dialog %s control %s hwnd %p\n",
414 debugstr_w(dialog->name), debugstr_w(text), control->hwnd );
416 msi_dialog_set_font( dialog, control->hwnd,
417 font ? font : dialog->default_font );
419 msi_free( title_font );
425 static LPWSTR msi_dialog_get_uitext( msi_dialog *dialog, LPCWSTR key )
430 static const WCHAR query[] = {
431 's','e','l','e','c','t',' ','*',' ',
432 'f','r','o','m',' ','`','U','I','T','e','x','t','`',' ',
433 'w','h','e','r','e',' ','`','K','e','y','`',' ','=',' ','\'','%','s','\'',0
436 rec = MSI_QueryGetRecord( dialog->package->db, query, key );
437 if (!rec) return NULL;
438 text = strdupW( MSI_RecordGetString( rec, 2 ) );
439 msiobj_release( &rec->hdr );
443 static MSIRECORD *msi_get_binary_record( MSIDATABASE *db, LPCWSTR name )
445 static const WCHAR query[] = {
446 's','e','l','e','c','t',' ','*',' ',
447 'f','r','o','m',' ','B','i','n','a','r','y',' ',
448 'w','h','e','r','e',' ',
449 '`','N','a','m','e','`',' ','=',' ','\'','%','s','\'',0
452 return MSI_QueryGetRecord( db, query, name );
455 static LPWSTR msi_create_tmp_path(void)
459 static const WCHAR prefix[] = { 'm','s','i',0 };
462 r = GetTempPathW( MAX_PATH, tmp );
465 len = lstrlenW( tmp ) + 20;
466 path = msi_alloc( len * sizeof (WCHAR) );
469 r = GetTempFileNameW( tmp, prefix, 0, path );
480 static HANDLE msi_load_image( MSIDATABASE *db, LPCWSTR name, UINT type,
481 UINT cx, UINT cy, UINT flags )
483 MSIRECORD *rec = NULL;
484 HANDLE himage = NULL;
488 TRACE("%p %s %u %u %08x\n", db, debugstr_w(name), cx, cy, flags);
490 tmp = msi_create_tmp_path();
494 rec = msi_get_binary_record( db, name );
497 r = MSI_RecordStreamToFile( rec, 2, tmp );
498 if( r == ERROR_SUCCESS )
500 himage = LoadImageW( 0, tmp, type, cx, cy, flags );
503 msiobj_release( &rec->hdr );
510 static HICON msi_load_icon( MSIDATABASE *db, LPCWSTR text, UINT attributes )
512 DWORD cx = 0, cy = 0, flags;
514 flags = LR_LOADFROMFILE | LR_DEFAULTSIZE;
515 if( attributes & msidbControlAttributesFixedSize )
517 flags &= ~LR_DEFAULTSIZE;
518 if( attributes & msidbControlAttributesIconSize16 )
523 if( attributes & msidbControlAttributesIconSize32 )
528 /* msidbControlAttributesIconSize48 handled by above logic */
530 return msi_load_image( db, text, IMAGE_ICON, cx, cy, flags );
534 /* called from the Control Event subscription code */
535 void msi_dialog_handle_event( msi_dialog* dialog, LPCWSTR control,
536 LPCWSTR attribute, MSIRECORD *rec )
539 LPCWSTR font_text, text = NULL;
542 static const WCHAR empty[] = {0};
544 ctrl = msi_dialog_find_control( dialog, control );
547 if( !lstrcmpW(attribute, szText) )
549 font_text = MSI_RecordGetString( rec , 1 );
550 font = msi_dialog_get_style( font_text, &text );
551 if (!text) text = empty;
552 SetWindowTextW( ctrl->hwnd, text );
554 msi_dialog_check_messages( NULL );
556 else if( !lstrcmpW(attribute, szProgress) )
560 func = MSI_RecordGetInteger( rec , 1 );
561 val = MSI_RecordGetInteger( rec , 2 );
566 ctrl->progress_max = val;
567 ctrl->progress_current = 0;
568 SendMessageW(ctrl->hwnd, PBM_SETRANGE, 0, MAKELPARAM(0,100));
569 SendMessageW(ctrl->hwnd, PBM_SETPOS, 0, 0);
571 case 1: /* FIXME: not sure what this is supposed to do */
574 ctrl->progress_current += val;
575 SendMessageW(ctrl->hwnd, PBM_SETPOS, 100*(ctrl->progress_current/ctrl->progress_max), 0);
578 ERR("Unknown progress message %ld\n", func);
582 else if ( !lstrcmpW(attribute, szProperty) )
584 MSIFEATURE *feature = msi_seltree_get_selected_feature( ctrl );
585 MSI_SetPropertyW( dialog->package, ctrl->property, feature->Directory );
589 FIXME("Attribute %s not being set\n", debugstr_w(attribute));
594 static void msi_dialog_map_events(msi_dialog* dialog, LPCWSTR control)
596 static const WCHAR Query[] = {
597 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
598 '`','E','v','e','n','t','M','a','p','p','i','n','g','`',' ',
599 'W','H','E','R','E',' ',
600 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',' ',
602 '`','C','o','n','t','r','o','l','_','`',' ','=',' ','\'','%','s','\'',0
605 LPCWSTR event, attribute;
607 row = MSI_QueryGetRecord( dialog->package->db, Query, dialog->name, control );
611 event = MSI_RecordGetString( row, 3 );
612 attribute = MSI_RecordGetString( row, 4 );
613 ControlEvent_SubscribeToEvent( dialog->package, dialog, event, control, attribute );
614 msiobj_release( &row->hdr );
617 /* everything except radio buttons */
618 static msi_control *msi_dialog_add_control( msi_dialog *dialog,
619 MSIRECORD *rec, LPCWSTR szCls, DWORD style )
625 name = MSI_RecordGetString( rec, 2 );
626 attributes = MSI_RecordGetInteger( rec, 8 );
627 text = MSI_RecordGetString( rec, 10 );
628 if( attributes & msidbControlAttributesVisible )
630 if( ~attributes & msidbControlAttributesEnabled )
631 style |= WS_DISABLED;
632 if( attributes & msidbControlAttributesSunken )
633 exstyle |= WS_EX_CLIENTEDGE;
635 msi_dialog_map_events(dialog, name);
637 return msi_dialog_create_window( dialog, rec, exstyle, szCls, name,
638 text, style, dialog->hwnd );
649 * we don't erase our own background,
650 * so we have to make sure that the parent window redraws first
652 static void msi_text_on_settext( HWND hWnd )
657 hParent = GetParent( hWnd );
658 GetWindowRect( hWnd, &rc );
659 MapWindowPoints( NULL, hParent, (LPPOINT) &rc, 2 );
660 InvalidateRect( hParent, &rc, TRUE );
663 static LRESULT WINAPI
664 MSIText_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
666 struct msi_text_info *info;
669 TRACE("%p %04x %08x %08lx\n", hWnd, msg, wParam, lParam);
671 info = GetPropW(hWnd, szButtonData);
674 SetTextColor( (HDC)wParam, info->font->color );
676 if( msg == WM_CTLCOLORSTATIC &&
677 ( info->attributes & msidbControlAttributesTransparent ) )
679 SetBkMode( (HDC)wParam, TRANSPARENT );
680 return (LRESULT) GetStockObject(NULL_BRUSH);
683 r = CallWindowProcW(info->oldproc, hWnd, msg, wParam, lParam);
688 msi_text_on_settext( hWnd );
692 RemovePropW( hWnd, szButtonData );
699 static UINT msi_dialog_text_control( msi_dialog *dialog, MSIRECORD *rec )
701 msi_control *control;
702 struct msi_text_info *info;
706 TRACE("%p %p\n", dialog, rec);
708 control = msi_dialog_add_control( dialog, rec, szStatic, SS_LEFT | WS_GROUP );
710 return ERROR_FUNCTION_FAILED;
712 info = msi_alloc( sizeof *info );
714 return ERROR_SUCCESS;
716 text = MSI_RecordGetString( rec, 10 );
717 font_name = msi_dialog_get_style( text, &ptr );
718 info->font = ( font_name ) ? msi_dialog_find_font( dialog, font_name ) : NULL;
719 msi_free( font_name );
721 info->attributes = MSI_RecordGetInteger( rec, 8 );
722 if( info->attributes & msidbControlAttributesTransparent )
723 SetWindowLongPtrW( control->hwnd, GWL_EXSTYLE, WS_EX_TRANSPARENT );
725 info->oldproc = (WNDPROC) SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
726 (LONG_PTR)MSIText_WndProc );
727 SetPropW( control->hwnd, szButtonData, info );
729 return ERROR_SUCCESS;
732 static UINT msi_dialog_button_control( msi_dialog *dialog, MSIRECORD *rec )
734 msi_control *control;
735 UINT attributes, style;
738 TRACE("%p %p\n", dialog, rec);
741 attributes = MSI_RecordGetInteger( rec, 8 );
742 if( attributes & msidbControlAttributesIcon )
745 control = msi_dialog_add_control( dialog, rec, szButton, style );
747 return ERROR_FUNCTION_FAILED;
749 control->handler = msi_dialog_button_handler;
752 text = msi_get_deformatted_field( dialog->package, rec, 10 );
753 control->hIcon = msi_load_icon( dialog->package->db, text, attributes );
754 if( attributes & msidbControlAttributesIcon )
755 SendMessageW( control->hwnd, BM_SETIMAGE, IMAGE_ICON, (LPARAM) control->hIcon );
758 return ERROR_SUCCESS;
761 static LPWSTR msi_get_checkbox_value( msi_dialog *dialog, LPCWSTR prop )
763 static const WCHAR query[] = {
764 'S','E','L','E','C','T',' ','*',' ',
765 'F','R','O','M',' ','`','C','h','e','c','k','B','o','x',' ','`',
766 'W','H','E','R','E',' ',
767 '`','P','r','o','p','e','r','t','y','`',' ','=',' ',
770 MSIRECORD *rec = NULL;
773 /* find if there is a value associated with the checkbox */
774 rec = MSI_QueryGetRecord( dialog->package->db, query, prop );
778 ret = msi_get_deformatted_field( dialog->package, rec, 2 );
784 msiobj_release( &rec->hdr );
788 ret = msi_dup_property( dialog->package, prop );
798 static UINT msi_dialog_checkbox_control( msi_dialog *dialog, MSIRECORD *rec )
800 msi_control *control;
803 TRACE("%p %p\n", dialog, rec);
805 control = msi_dialog_add_control( dialog, rec, szButton,
806 BS_CHECKBOX | BS_MULTILINE | WS_TABSTOP );
807 control->handler = msi_dialog_checkbox_handler;
808 prop = MSI_RecordGetString( rec, 9 );
811 control->property = strdupW( prop );
812 control->value = msi_get_checkbox_value( dialog, prop );
813 TRACE("control %s value %s\n", debugstr_w(control->property),
814 debugstr_w(control->value));
816 msi_dialog_checkbox_sync_state( dialog, control );
818 return ERROR_SUCCESS;
821 static UINT msi_dialog_line_control( msi_dialog *dialog, MSIRECORD *rec )
823 TRACE("%p %p\n", dialog, rec);
825 /* line is exactly 2 units in height */
826 MSI_RecordSetInteger( rec, 7, 2 );
828 msi_dialog_add_control( dialog, rec, szStatic, SS_ETCHEDHORZ | SS_SUNKEN );
829 return ERROR_SUCCESS;
832 /******************** Scroll Text ********************************************/
834 struct msi_scrolltext_info
837 msi_control *control;
841 static LRESULT WINAPI
842 MSIScrollText_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
844 struct msi_scrolltext_info *info;
847 TRACE("%p %04x %08x %08lx\n", hWnd, msg, wParam, lParam);
849 info = GetPropW( hWnd, szButtonData );
851 r = CallWindowProcW( info->oldproc, hWnd, msg, wParam, lParam );
857 RemovePropW( hWnd, szButtonData );
860 /* native MSI sets a wait cursor here */
861 msi_dialog_button_handler( info->dialog, info->control, BN_CLICKED );
867 struct msi_streamin_info
874 static DWORD CALLBACK
875 msi_richedit_stream_in( DWORD_PTR arg, LPBYTE buffer, LONG count, LONG *pcb )
877 struct msi_streamin_info *info = (struct msi_streamin_info*) arg;
879 if( (count + info->offset) > info->length )
880 count = info->length - info->offset;
881 memcpy( buffer, &info->string[ info->offset ], count );
883 info->offset += count;
885 TRACE("%ld/%ld\n", info->offset, info->length);
890 static void msi_scrolltext_add_text( msi_control *control, LPCWSTR text )
892 struct msi_streamin_info info;
895 info.string = strdupWtoA( text );
897 info.length = lstrlenA( info.string ) + 1;
899 es.dwCookie = (DWORD_PTR) &info;
901 es.pfnCallback = msi_richedit_stream_in;
903 SendMessageW( control->hwnd, EM_STREAMIN, SF_RTF, (LPARAM) &es );
905 msi_free( info.string );
908 static UINT msi_dialog_scrolltext_control( msi_dialog *dialog, MSIRECORD *rec )
910 static const WCHAR szRichEdit20W[] = {
911 'R','i','c','h','E','d','i','t','2','0','W',0
913 struct msi_scrolltext_info *info;
914 msi_control *control;
918 info = msi_alloc( sizeof *info );
920 return ERROR_FUNCTION_FAILED;
922 hRichedit = LoadLibraryA("riched20");
924 style = WS_BORDER | ES_MULTILINE | WS_VSCROLL |
925 ES_READONLY | ES_AUTOVSCROLL | WS_TABSTOP;
926 control = msi_dialog_add_control( dialog, rec, szRichEdit20W, style );
929 FreeLibrary( hRichedit );
931 return ERROR_FUNCTION_FAILED;
934 control->hDll = hRichedit;
936 info->dialog = dialog;
937 info->control = control;
939 /* subclass the static control */
940 info->oldproc = (WNDPROC) SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
941 (LONG_PTR)MSIScrollText_WndProc );
942 SetPropW( control->hwnd, szButtonData, info );
944 /* add the text into the richedit */
945 msi_scrolltext_add_text( control, MSI_RecordGetString( rec, 10 ) );
947 return ERROR_SUCCESS;
950 static HBITMAP msi_load_picture( MSIDATABASE *db, LPCWSTR name,
951 INT cx, INT cy, DWORD flags )
953 HBITMAP hOleBitmap = 0, hBitmap = 0, hOldSrcBitmap, hOldDestBitmap;
954 MSIRECORD *rec = NULL;
956 IPicture *pic = NULL;
961 rec = msi_get_binary_record( db, name );
965 r = MSI_RecordGetIStream( rec, 2, &stm );
966 msiobj_release( &rec->hdr );
967 if( r != ERROR_SUCCESS )
970 r = OleLoadPicture( stm, 0, TRUE, &IID_IPicture, (LPVOID*) &pic );
971 IStream_Release( stm );
974 ERR("failed to load picture\n");
978 r = IPicture_get_Handle( pic, (OLE_HANDLE*) &hOleBitmap );
981 ERR("failed to get bitmap handle\n");
985 /* make the bitmap the desired size */
986 r = GetObjectW( hOleBitmap, sizeof bm, &bm );
989 ERR("failed to get bitmap size\n");
993 if (flags & LR_DEFAULTSIZE)
999 srcdc = CreateCompatibleDC( NULL );
1000 hOldSrcBitmap = SelectObject( srcdc, hOleBitmap );
1001 destdc = CreateCompatibleDC( NULL );
1002 hBitmap = CreateCompatibleBitmap( srcdc, cx, cy );
1003 hOldDestBitmap = SelectObject( destdc, hBitmap );
1004 StretchBlt( destdc, 0, 0, cx, cy,
1005 srcdc, 0, 0, bm.bmWidth, bm.bmHeight, SRCCOPY);
1006 SelectObject( srcdc, hOldSrcBitmap );
1007 SelectObject( destdc, hOldDestBitmap );
1013 IPicture_Release( pic );
1017 static UINT msi_dialog_bitmap_control( msi_dialog *dialog, MSIRECORD *rec )
1019 UINT cx, cy, flags, style, attributes;
1020 msi_control *control;
1023 flags = LR_LOADFROMFILE;
1024 style = SS_BITMAP | SS_LEFT | WS_GROUP;
1026 attributes = MSI_RecordGetInteger( rec, 8 );
1027 if( attributes & msidbControlAttributesFixedSize )
1029 flags |= LR_DEFAULTSIZE;
1030 style |= SS_CENTERIMAGE;
1033 control = msi_dialog_add_control( dialog, rec, szStatic, style );
1034 cx = MSI_RecordGetInteger( rec, 6 );
1035 cy = MSI_RecordGetInteger( rec, 7 );
1036 cx = msi_dialog_scale_unit( dialog, cx );
1037 cy = msi_dialog_scale_unit( dialog, cy );
1039 text = msi_get_deformatted_field( dialog->package, rec, 10 );
1040 control->hBitmap = msi_load_picture( dialog->package->db, text, cx, cy, flags );
1041 if( control->hBitmap )
1042 SendMessageW( control->hwnd, STM_SETIMAGE,
1043 IMAGE_BITMAP, (LPARAM) control->hBitmap );
1045 ERR("Failed to load bitmap %s\n", debugstr_w(text));
1049 return ERROR_SUCCESS;
1052 static UINT msi_dialog_icon_control( msi_dialog *dialog, MSIRECORD *rec )
1054 msi_control *control;
1060 control = msi_dialog_add_control( dialog, rec, szStatic,
1061 SS_ICON | SS_CENTERIMAGE | WS_GROUP );
1063 attributes = MSI_RecordGetInteger( rec, 8 );
1064 text = msi_get_deformatted_field( dialog->package, rec, 10 );
1065 control->hIcon = msi_load_icon( dialog->package->db, text, attributes );
1066 if( control->hIcon )
1067 SendMessageW( control->hwnd, STM_SETICON, (WPARAM) control->hIcon, 0 );
1069 ERR("Failed to load bitmap %s\n", debugstr_w(text));
1071 return ERROR_SUCCESS;
1074 static UINT msi_dialog_combo_control( msi_dialog *dialog, MSIRECORD *rec )
1076 static const WCHAR szCombo[] = { 'C','O','M','B','O','B','O','X',0 };
1078 msi_dialog_add_control( dialog, rec, szCombo,
1079 SS_BITMAP | SS_LEFT | SS_CENTERIMAGE );
1080 return ERROR_SUCCESS;
1083 static UINT msi_dialog_edit_control( msi_dialog *dialog, MSIRECORD *rec )
1085 msi_control *control;
1089 control = msi_dialog_add_control( dialog, rec, szEdit,
1090 WS_BORDER | WS_TABSTOP );
1091 control->handler = msi_dialog_edit_handler;
1092 prop = MSI_RecordGetString( rec, 9 );
1094 control->property = strdupW( prop );
1095 val = msi_dup_property( dialog->package, control->property );
1096 SetWindowTextW( control->hwnd, val );
1098 return ERROR_SUCCESS;
1101 /******************** Masked Edit ********************************************/
1103 #define MASK_MAX_GROUPS 20
1105 struct msi_mask_group
1113 struct msi_maskedit_info
1121 struct msi_mask_group group[MASK_MAX_GROUPS];
1124 static BOOL msi_mask_editable( WCHAR type )
1139 static void msi_mask_control_change( struct msi_maskedit_info *info )
1144 val = msi_alloc( (info->num_chars+1)*sizeof(WCHAR) );
1145 for( i=0, n=0; i<info->num_groups; i++ )
1147 if( (info->group[i].len + n) > info->num_chars )
1149 ERR("can't fit control %d text into template\n",i);
1152 if (!msi_mask_editable(info->group[i].type))
1154 for(r=0; r<info->group[i].len; r++)
1155 val[n+r] = info->group[i].type;
1160 r = GetWindowTextW( info->group[i].hwnd, &val[n], info->group[i].len+1 );
1161 if( r != info->group[i].len )
1167 TRACE("%d/%d controls were good\n", i, info->num_groups);
1169 if( i == info->num_groups )
1171 TRACE("Set property %s to %s\n",
1172 debugstr_w(info->prop), debugstr_w(val) );
1173 CharUpperBuffW( val, info->num_chars );
1174 MSI_SetPropertyW( info->dialog->package, info->prop, val );
1175 msi_dialog_evaluate_control_conditions( info->dialog );
1180 /* now move to the next control if necessary */
1181 static VOID msi_mask_next_control( struct msi_maskedit_info *info, HWND hWnd )
1186 for( i=0; i<info->num_groups; i++ )
1187 if( info->group[i].hwnd == hWnd )
1190 /* don't move from the last control */
1191 if( i >= (info->num_groups-1) )
1194 len = SendMessageW( hWnd, WM_GETTEXTLENGTH, 0, 0 );
1195 if( len < info->group[i].len )
1198 hWndNext = GetNextDlgTabItem( GetParent( hWnd ), hWnd, FALSE );
1199 SetFocus( hWndNext );
1202 static LRESULT WINAPI
1203 MSIMaskedEdit_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
1205 struct msi_maskedit_info *info;
1208 TRACE("%p %04x %08x %08lx\n", hWnd, msg, wParam, lParam);
1210 info = GetPropW(hWnd, szButtonData);
1212 r = CallWindowProcW(info->oldproc, hWnd, msg, wParam, lParam);
1217 if (HIWORD(wParam) == EN_CHANGE)
1219 msi_mask_control_change( info );
1220 msi_mask_next_control( info, (HWND) lParam );
1224 msi_free( info->prop );
1226 RemovePropW( hWnd, szButtonData );
1233 /* fish the various bits of the property out and put them in the control */
1235 msi_maskedit_set_text( struct msi_maskedit_info *info, LPCWSTR text )
1241 for( i = 0; i < info->num_groups; i++ )
1243 if( info->group[i].len < lstrlenW( p ) )
1245 LPWSTR chunk = strdupW( p );
1246 chunk[ info->group[i].len ] = 0;
1247 SetWindowTextW( info->group[i].hwnd, chunk );
1252 SetWindowTextW( info->group[i].hwnd, p );
1255 p += info->group[i].len;
1259 static struct msi_maskedit_info * msi_dialog_parse_groups( LPCWSTR mask )
1261 struct msi_maskedit_info * info = NULL;
1262 int i = 0, n = 0, total = 0;
1265 TRACE("masked control, template %s\n", debugstr_w(mask));
1270 info = msi_alloc_zero( sizeof *info );
1274 p = strchrW(mask, '<');
1280 for( i=0; i<MASK_MAX_GROUPS; i++ )
1282 /* stop at the end of the string */
1283 if( p[0] == 0 || p[0] == '>' )
1286 /* count the number of the same identifier */
1287 for( n=0; p[n] == p[0]; n++ )
1289 info->group[i].ofs = total;
1290 info->group[i].type = p[0];
1294 total++; /* an extra not part of the group */
1296 info->group[i].len = n;
1301 TRACE("%d characters in %d groups\n", total, i );
1302 if( i == MASK_MAX_GROUPS )
1303 ERR("too many groups in PIDTemplate %s\n", debugstr_w(mask));
1305 info->num_chars = total;
1306 info->num_groups = i;
1312 msi_maskedit_create_children( struct msi_maskedit_info *info, LPCWSTR font )
1314 DWORD width, height, style, wx, ww;
1319 style = WS_CHILD | WS_BORDER | WS_VISIBLE | WS_TABSTOP | ES_AUTOHSCROLL;
1321 GetClientRect( info->hwnd, &rect );
1323 width = rect.right - rect.left;
1324 height = rect.bottom - rect.top;
1326 for( i = 0; i < info->num_groups; i++ )
1328 if (!msi_mask_editable( info->group[i].type ))
1330 wx = (info->group[i].ofs * width) / info->num_chars;
1331 ww = (info->group[i].len * width) / info->num_chars;
1333 hwnd = CreateWindowW( szEdit, NULL, style, wx, 0, ww, height,
1334 info->hwnd, NULL, NULL, NULL );
1337 ERR("failed to create mask edit sub window\n");
1341 SendMessageW( hwnd, EM_LIMITTEXT, info->group[i].len, 0 );
1343 msi_dialog_set_font( info->dialog, hwnd,
1344 font?font:info->dialog->default_font );
1345 info->group[i].hwnd = hwnd;
1350 * office 2003 uses "73931<````=````=````=````=`````>@@@@@"
1351 * delphi 7 uses "<????-??????-??????-????>" and "<???-???>"
1352 * filemaker pro 7 uses "<^^^^=^^^^=^^^^=^^^^=^^^^=^^^^=^^^^^>"
1354 static UINT msi_dialog_maskedit_control( msi_dialog *dialog, MSIRECORD *rec )
1356 LPWSTR font_mask, val = NULL, font;
1357 struct msi_maskedit_info *info = NULL;
1358 UINT ret = ERROR_SUCCESS;
1359 msi_control *control;
1364 font_mask = msi_get_deformatted_field( dialog->package, rec, 10 );
1365 font = msi_dialog_get_style( font_mask, &mask );
1368 ERR("mask template is empty\n");
1372 info = msi_dialog_parse_groups( mask );
1375 ERR("template %s is invalid\n", debugstr_w(mask));
1379 info->dialog = dialog;
1381 control = msi_dialog_add_control( dialog, rec, szStatic,
1382 SS_OWNERDRAW | WS_GROUP | WS_VISIBLE );
1385 ERR("Failed to create maskedit container\n");
1386 ret = ERROR_FUNCTION_FAILED;
1389 SetWindowLongPtrW( control->hwnd, GWL_EXSTYLE, WS_EX_CONTROLPARENT );
1391 info->hwnd = control->hwnd;
1393 /* subclass the static control */
1394 info->oldproc = (WNDPROC) SetWindowLongPtrW( info->hwnd, GWLP_WNDPROC,
1395 (LONG_PTR)MSIMaskedEdit_WndProc );
1396 SetPropW( control->hwnd, szButtonData, info );
1398 prop = MSI_RecordGetString( rec, 9 );
1400 info->prop = strdupW( prop );
1402 msi_maskedit_create_children( info, font );
1406 val = msi_dup_property( dialog->package, prop );
1409 msi_maskedit_set_text( info, val );
1415 if( ret != ERROR_SUCCESS )
1417 msi_free( font_mask );
1422 /******************** Progress Bar *****************************************/
1424 static UINT msi_dialog_progress_bar( msi_dialog *dialog, MSIRECORD *rec )
1426 msi_dialog_add_control( dialog, rec, PROGRESS_CLASSW, WS_VISIBLE );
1427 return ERROR_SUCCESS;
1430 /******************** Path Edit ********************************************/
1432 struct msi_pathedit_info
1435 msi_control *control;
1439 static LPWSTR msi_get_window_text( HWND hwnd )
1445 buf = msi_alloc( sz*sizeof(WCHAR) );
1448 r = GetWindowTextW( hwnd, buf, sz );
1452 buf = msi_realloc( buf, sz*sizeof(WCHAR) );
1458 static void msi_dialog_update_pathedit( msi_dialog *dialog, msi_control *control )
1463 if (!control && !(control = msi_dialog_find_control_by_type( dialog, szPathEdit )))
1466 indirect = control->attributes & msidbControlAttributesIndirect;
1467 prop = msi_dialog_dup_property( dialog, control->property, indirect );
1469 path = msi_dup_property( dialog->package, prop );
1473 SetWindowTextW( control->hwnd, path );
1474 SendMessageW( control->hwnd, EM_SETSEL, 0, -1 );
1480 /* FIXME: test when this should fail */
1481 static BOOL msi_dialog_verify_path( LPWSTR path )
1483 if ( !lstrlenW( path ) )
1486 if ( PathIsRelativeW( path ) )
1492 /* returns TRUE if the path is valid, FALSE otherwise */
1493 static BOOL msi_dialog_onkillfocus( msi_dialog *dialog, msi_control *control )
1499 indirect = control->attributes & msidbControlAttributesIndirect;
1500 prop = msi_dialog_dup_property( dialog, control->property, indirect );
1502 buf = msi_get_window_text( control->hwnd );
1504 if ( !msi_dialog_verify_path( buf ) )
1506 /* FIXME: display an error message box */
1507 ERR("Invalid path %s\n", debugstr_w( buf ));
1509 SetFocus( control->hwnd );
1514 MSI_SetPropertyW( dialog->package, prop, buf );
1517 msi_dialog_update_pathedit( dialog, control );
1519 TRACE("edit %s contents changed, set %s\n", debugstr_w(control->name),
1528 static LRESULT WINAPI MSIPathEdit_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
1530 struct msi_pathedit_info *info = GetPropW(hWnd, szButtonData);
1533 TRACE("%p %04x %08x %08lx\n", hWnd, msg, wParam, lParam);
1535 if ( msg == WM_KILLFOCUS )
1537 /* if the path is invalid, don't handle this message */
1538 if ( !msi_dialog_onkillfocus( info->dialog, info->control ) )
1542 r = CallWindowProcW(info->oldproc, hWnd, msg, wParam, lParam);
1544 if ( msg == WM_NCDESTROY )
1547 RemovePropW( hWnd, szButtonData );
1553 static UINT msi_dialog_pathedit_control( msi_dialog *dialog, MSIRECORD *rec )
1555 struct msi_pathedit_info *info;
1556 msi_control *control;
1559 info = msi_alloc( sizeof *info );
1561 return ERROR_FUNCTION_FAILED;
1563 control = msi_dialog_add_control( dialog, rec, szEdit,
1564 WS_BORDER | WS_TABSTOP );
1565 control->attributes = MSI_RecordGetInteger( rec, 8 );
1566 prop = MSI_RecordGetString( rec, 9 );
1567 control->property = msi_dialog_dup_property( dialog, prop, FALSE );
1569 info->dialog = dialog;
1570 info->control = control;
1571 info->oldproc = (WNDPROC) SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
1572 (LONG_PTR)MSIPathEdit_WndProc );
1573 SetPropW( control->hwnd, szButtonData, info );
1575 msi_dialog_update_pathedit( dialog, control );
1577 return ERROR_SUCCESS;
1580 /* radio buttons are a bit different from normal controls */
1581 static UINT msi_dialog_create_radiobutton( MSIRECORD *rec, LPVOID param )
1583 radio_button_group_descr *group = (radio_button_group_descr *)param;
1584 msi_dialog *dialog = group->dialog;
1585 msi_control *control;
1586 LPCWSTR prop, text, name;
1587 DWORD style, attributes = group->attributes;
1589 style = WS_CHILD | BS_AUTORADIOBUTTON | BS_MULTILINE | WS_TABSTOP;
1590 name = MSI_RecordGetString( rec, 3 );
1591 text = MSI_RecordGetString( rec, 8 );
1592 if( attributes & 1 )
1593 style |= WS_VISIBLE;
1594 if( ~attributes & 2 )
1595 style |= WS_DISABLED;
1597 control = msi_dialog_create_window( dialog, rec, 0, szButton, name, text,
1598 style, group->parent->hwnd );
1600 return ERROR_FUNCTION_FAILED;
1601 control->handler = msi_dialog_radiogroup_handler;
1603 if (!lstrcmpW(control->name, group->propval))
1604 SendMessageW(control->hwnd, BM_SETCHECK, BST_CHECKED, 0);
1606 prop = MSI_RecordGetString( rec, 1 );
1608 control->property = strdupW( prop );
1610 return ERROR_SUCCESS;
1613 static UINT msi_dialog_radiogroup_control( msi_dialog *dialog, MSIRECORD *rec )
1615 static const WCHAR query[] = {
1616 'S','E','L','E','C','T',' ','*',' ',
1617 'F','R','O','M',' ','R','a','d','i','o','B','u','t','t','o','n',' ',
1618 'W','H','E','R','E',' ',
1619 '`','P','r','o','p','e','r','t','y','`',' ','=',' ','\'','%','s','\'',0};
1622 msi_control *control;
1623 MSIQUERY *view = NULL;
1624 radio_button_group_descr group;
1625 MSIPACKAGE *package = dialog->package;
1628 prop = MSI_RecordGetString( rec, 9 );
1630 TRACE("%p %p %s\n", dialog, rec, debugstr_w( prop ));
1632 /* Create parent group box to hold radio buttons */
1633 control = msi_dialog_add_control( dialog, rec, szButton, BS_OWNERDRAW|WS_GROUP );
1635 return ERROR_FUNCTION_FAILED;
1637 oldproc = (WNDPROC) SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
1638 (LONG_PTR)MSIRadioGroup_WndProc );
1639 SetPropW(control->hwnd, szButtonData, oldproc);
1640 SetWindowLongPtrW( control->hwnd, GWL_EXSTYLE, WS_EX_CONTROLPARENT );
1643 control->property = strdupW( prop );
1645 /* query the Radio Button table for all control in this group */
1646 r = MSI_OpenQuery( package->db, &view, query, prop );
1647 if( r != ERROR_SUCCESS )
1649 ERR("query failed for dialog %s radio group %s\n",
1650 debugstr_w(dialog->name), debugstr_w(prop));
1651 return ERROR_INVALID_PARAMETER;
1654 group.dialog = dialog;
1655 group.parent = control;
1656 group.attributes = MSI_RecordGetInteger( rec, 8 );
1657 group.propval = msi_dup_property( dialog->package, control->property );
1659 r = MSI_IterateRecords( view, 0, msi_dialog_create_radiobutton, &group );
1660 msiobj_release( &view->hdr );
1661 msi_free( group.propval );
1666 /******************** Selection Tree ***************************************/
1668 struct msi_selection_tree_info
1677 msi_seltree_sync_item_state( HWND hwnd, MSIFEATURE *feature, HTREEITEM hItem )
1680 DWORD index = feature->Action;
1682 TRACE("Feature %s -> %d %d %d\n", debugstr_w(feature->Title),
1683 feature->Installed, feature->Action, feature->ActionRequest);
1685 if (index == INSTALLSTATE_UNKNOWN)
1686 index = INSTALLSTATE_ABSENT;
1688 tvi.mask = TVIF_STATE;
1690 tvi.state = INDEXTOSTATEIMAGEMASK( index );
1691 tvi.stateMask = TVIS_STATEIMAGEMASK;
1693 SendMessageW( hwnd, TVM_SETITEMW, 0, (LPARAM) &tvi );
1697 msi_seltree_popup_menu( HWND hwnd, INT x, INT y )
1702 /* create a menu to display */
1703 hMenu = CreatePopupMenu();
1705 /* FIXME: load strings from resources */
1706 AppendMenuA( hMenu, MF_ENABLED, INSTALLSTATE_LOCAL, "Install feature locally");
1707 AppendMenuA( hMenu, MF_GRAYED, 0x1000, "Install entire feature");
1708 AppendMenuA( hMenu, MF_ENABLED, INSTALLSTATE_ADVERTISED, "Install on demand");
1709 AppendMenuA( hMenu, MF_ENABLED, INSTALLSTATE_ABSENT, "Don't install");
1710 r = TrackPopupMenu( hMenu, TPM_LEFTALIGN | TPM_TOPALIGN | TPM_RETURNCMD,
1711 x, y, 0, hwnd, NULL );
1712 DestroyMenu( hMenu );
1717 msi_seltree_feature_from_item( HWND hwnd, HTREEITEM hItem )
1721 /* get the feature from the item */
1722 memset( &tvi, 0, sizeof tvi );
1724 tvi.mask = TVIF_PARAM | TVIF_HANDLE;
1725 SendMessageW( hwnd, TVM_GETITEMW, 0, (LPARAM) &tvi );
1727 return (MSIFEATURE*) tvi.lParam;
1731 msi_seltree_menu( HWND hwnd, HTREEITEM hItem )
1733 struct msi_selection_tree_info *info;
1734 MSIFEATURE *feature;
1735 MSIPACKAGE *package;
1743 info = GetPropW(hwnd, szButtonData);
1744 package = info->dialog->package;
1746 feature = msi_seltree_feature_from_item( hwnd, hItem );
1749 ERR("item %p feature was NULL\n", hItem);
1753 /* get the item's rectangle to put the menu just below it */
1755 SendMessageW( hwnd, TVM_GETITEMRECT, 0, (LPARAM) &u.rc );
1756 MapWindowPoints( hwnd, NULL, u.pt, 2 );
1758 r = msi_seltree_popup_menu( hwnd, u.rc.left, u.rc.top );
1762 case INSTALLSTATE_LOCAL:
1763 case INSTALLSTATE_ADVERTISED:
1764 case INSTALLSTATE_ABSENT:
1765 feature->ActionRequest = r;
1766 feature->Action = r;
1769 FIXME("select feature and all children\n");
1773 msi_seltree_sync_item_state( hwnd, feature, hItem );
1774 ACTION_UpdateComponentStates( package, feature->Feature );
1779 static MSIFEATURE *msi_seltree_get_selected_feature( msi_control *control )
1781 struct msi_selection_tree_info *info = GetPropW(control->hwnd, szButtonData);
1782 return msi_seltree_feature_from_item( control->hwnd, info->selected );
1785 static LRESULT WINAPI
1786 MSISelectionTree_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
1788 struct msi_selection_tree_info *info;
1789 TVHITTESTINFO tvhti;
1792 TRACE("%p %04x %08x %08lx\n", hWnd, msg, wParam, lParam);
1794 info = GetPropW(hWnd, szButtonData);
1798 case WM_LBUTTONDOWN:
1799 tvhti.pt.x = LOWORD( lParam );
1800 tvhti.pt.y = HIWORD( lParam );
1803 r = CallWindowProcW(info->oldproc, hWnd, TVM_HITTEST, 0, (LPARAM) &tvhti );
1804 if (tvhti.flags & TVHT_ONITEMSTATEICON)
1805 return msi_seltree_menu( hWnd, tvhti.hItem );
1809 r = CallWindowProcW(info->oldproc, hWnd, msg, wParam, lParam);
1815 RemovePropW( hWnd, szButtonData );
1822 msi_seltree_add_child_features( MSIPACKAGE *package, HWND hwnd,
1823 LPCWSTR parent, HTREEITEM hParent )
1825 struct msi_selection_tree_info *info = GetPropW( hwnd, szButtonData );
1826 MSIFEATURE *feature;
1827 TVINSERTSTRUCTW tvis;
1828 HTREEITEM hitem, hfirst = NULL;
1830 LIST_FOR_EACH_ENTRY( feature, &package->features, MSIFEATURE, entry )
1832 if ( lstrcmpW( parent, feature->Feature_Parent ) )
1835 if ( !feature->Title )
1838 if ( !feature->Display )
1841 memset( &tvis, 0, sizeof tvis );
1842 tvis.hParent = hParent;
1843 tvis.hInsertAfter = TVI_LAST;
1844 tvis.u.item.mask = TVIF_TEXT | TVIF_PARAM;
1845 tvis.u.item.pszText = feature->Title;
1846 tvis.u.item.lParam = (LPARAM) feature;
1848 hitem = (HTREEITEM) SendMessageW( hwnd, TVM_INSERTITEMW, 0, (LPARAM) &tvis );
1855 msi_seltree_sync_item_state( hwnd, feature, hitem );
1856 msi_seltree_add_child_features( package, hwnd,
1857 feature->Feature, hitem );
1859 /* the node is expanded if Display is odd */
1860 if ( feature->Display % 2 != 0 )
1861 SendMessageW( hwnd, TVM_EXPAND, TVE_EXPAND, (LPARAM) hitem );
1864 /* select the first item */
1865 SendMessageW( hwnd, TVM_SELECTITEM, TVGN_CARET | TVGN_DROPHILITE, (LPARAM) hfirst );
1866 info->selected = hfirst;
1869 static void msi_seltree_create_imagelist( HWND hwnd )
1871 const int bm_width = 32, bm_height = 16, bm_count = 3;
1872 const int bm_resource = 0x1001;
1877 himl = ImageList_Create( bm_width, bm_height, FALSE, 4, 0 );
1880 ERR("failed to create image list\n");
1884 for (i=0; i<bm_count; i++)
1886 hbmp = LoadBitmapW( msi_hInstance, MAKEINTRESOURCEW(i+bm_resource) );
1889 ERR("failed to load bitmap %d\n", i);
1894 * Add a dummy bitmap at offset zero because the treeview
1895 * can't use it as a state mask (zero means no user state).
1898 ImageList_Add( himl, hbmp, NULL );
1900 ImageList_Add( himl, hbmp, NULL );
1903 SendMessageW( hwnd, TVM_SETIMAGELIST, TVSIL_STATE, (LPARAM)himl );
1906 static UINT msi_dialog_seltree_handler( msi_dialog *dialog,
1907 msi_control *control, WPARAM param )
1909 struct msi_selection_tree_info *info = GetPropW( control->hwnd, szButtonData );
1910 LPNMTREEVIEWW tv = (LPNMTREEVIEWW)param;
1911 MSIRECORD *row, *rec;
1914 UINT r = ERROR_SUCCESS;
1916 static const WCHAR select[] = {
1917 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
1918 '`','F','e','a','t','u','r','e','`',' ','W','H','E','R','E',' ',
1919 '`','T','i','t','l','e','`',' ','=',' ','\'','%','s','\'',0
1922 if (tv->hdr.code != TVN_SELCHANGINGW)
1923 return ERROR_SUCCESS;
1925 info->selected = tv->itemNew.hItem;
1927 row = MSI_QueryGetRecord( dialog->package->db, select, tv->itemNew.pszText );
1929 return ERROR_FUNCTION_FAILED;
1931 rec = MSI_CreateRecord( 1 );
1933 MSI_RecordSetStringW( rec, 1, MSI_RecordGetString( row, 4 ) );
1934 ControlEvent_FireSubscribedEvent( dialog->package, szSelectionDescription, rec );
1936 dir = MSI_RecordGetString( row, 7 );
1937 folder = get_loaded_folder( dialog->package, dir );
1940 r = ERROR_FUNCTION_FAILED;
1944 MSI_RecordSetStringW( rec, 1, folder->ResolvedTarget );
1945 ControlEvent_FireSubscribedEvent( dialog->package, szSelectionPath, rec );
1948 msiobj_release(&row->hdr);
1949 msiobj_release(&rec->hdr);
1954 static UINT msi_dialog_selection_tree( msi_dialog *dialog, MSIRECORD *rec )
1956 msi_control *control;
1958 MSIPACKAGE *package = dialog->package;
1960 struct msi_selection_tree_info *info;
1962 info = msi_alloc( sizeof *info );
1964 return ERROR_FUNCTION_FAILED;
1966 /* create the treeview control */
1967 style = TVS_HASLINES | TVS_HASBUTTONS | TVS_LINESATROOT;
1968 style |= WS_GROUP | WS_VSCROLL;
1969 control = msi_dialog_add_control( dialog, rec, WC_TREEVIEWW, style );
1973 return ERROR_FUNCTION_FAILED;
1976 control->handler = msi_dialog_seltree_handler;
1977 control->attributes = MSI_RecordGetInteger( rec, 8 );
1978 prop = MSI_RecordGetString( rec, 9 );
1979 control->property = msi_dialog_dup_property( dialog, prop, FALSE );
1982 info->dialog = dialog;
1983 info->hwnd = control->hwnd;
1984 info->oldproc = (WNDPROC) SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
1985 (LONG_PTR)MSISelectionTree_WndProc );
1986 SetPropW( control->hwnd, szButtonData, info );
1988 ControlEvent_SubscribeToEvent( dialog->package, dialog,
1989 szSelectionPath, control->name, szProperty );
1992 msi_seltree_create_imagelist( control->hwnd );
1993 msi_seltree_add_child_features( package, control->hwnd, NULL, NULL );
1995 return ERROR_SUCCESS;
1998 /******************** Group Box ***************************************/
2000 static UINT msi_dialog_group_box( msi_dialog *dialog, MSIRECORD *rec )
2002 msi_control *control;
2005 style = BS_GROUPBOX | WS_CHILD | WS_GROUP;
2006 control = msi_dialog_add_control( dialog, rec, WC_BUTTONW, style );
2008 return ERROR_FUNCTION_FAILED;
2010 return ERROR_SUCCESS;
2013 /******************** List Box ***************************************/
2015 struct msi_listbox_item
2021 struct msi_listbox_info
2027 struct msi_listbox_item *items;
2030 static LRESULT WINAPI MSIListBox_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
2032 struct msi_listbox_info *info;
2036 TRACE("%p %04x %08x %08lx\n", hWnd, msg, wParam, lParam);
2038 info = GetPropW( hWnd, szButtonData );
2042 r = CallWindowProcW( info->oldproc, hWnd, msg, wParam, lParam );
2047 for (j = 0; j < info->num_items; j++)
2049 msi_free( info->items[j].property );
2050 msi_free( info->items[j].value );
2052 msi_free( info->items );
2054 RemovePropW( hWnd, szButtonData );
2061 static UINT msi_listbox_add_item( MSIRECORD *rec, LPVOID param )
2063 struct msi_listbox_info *info = param;
2064 struct msi_listbox_item *item;
2065 LPCWSTR property, value, text;
2066 static int index = 0;
2068 item = &info->items[index++];
2069 property = MSI_RecordGetString( rec, 1 );
2070 value = MSI_RecordGetString( rec, 3 );
2071 text = MSI_RecordGetString( rec, 4 );
2073 item->property = strdupW( property );
2074 item->value = strdupW( value );
2076 SendMessageW( info->hwnd, LB_ADDSTRING, 0, (LPARAM)text );
2078 return ERROR_SUCCESS;
2081 static UINT msi_listbox_add_items( struct msi_listbox_info *info )
2084 MSIQUERY *view = NULL;
2087 static const WCHAR query[] = {
2088 'S','E','L','E','C','T',' ','*',' ',
2089 'F','R','O','M',' ','`','L','i','s','t','B','o','x','`',' ',
2090 'O','R','D','E','R',' ','B','Y',' ','`','O','r','d','e','r','`',0
2093 r = MSI_OpenQuery( info->dialog->package->db, &view, query );
2094 if ( r != ERROR_SUCCESS )
2097 /* just get the number of records */
2098 r = MSI_IterateRecords( view, &count, NULL, NULL );
2100 info->num_items = count;
2101 info->items = msi_alloc( sizeof(*info->items) * count );
2103 r = MSI_IterateRecords( view, NULL, msi_listbox_add_item, info );
2104 msiobj_release( &view->hdr );
2109 static UINT msi_dialog_listbox_handler( msi_dialog *dialog,
2110 msi_control *control, WPARAM param )
2112 struct msi_listbox_info *info;
2115 if( HIWORD(param) != LBN_SELCHANGE )
2116 return ERROR_SUCCESS;
2118 info = GetPropW( control->hwnd, szButtonData );
2119 index = SendMessageW( control->hwnd, LB_GETCURSEL, 0, 0 );
2121 MSI_SetPropertyW( info->dialog->package,
2122 info->items[index].property, info->items[index].value );
2123 msi_dialog_evaluate_control_conditions( info->dialog );
2125 return ERROR_SUCCESS;
2128 static UINT msi_dialog_list_box( msi_dialog *dialog, MSIRECORD *rec )
2130 struct msi_listbox_info *info;
2131 msi_control *control;
2134 info = msi_alloc( sizeof *info );
2136 return ERROR_FUNCTION_FAILED;
2138 style = WS_TABSTOP | WS_GROUP | WS_CHILD | LBS_STANDARD;
2139 control = msi_dialog_add_control( dialog, rec, WC_LISTBOXW, style );
2141 return ERROR_FUNCTION_FAILED;
2143 control->handler = msi_dialog_listbox_handler;
2146 info->dialog = dialog;
2147 info->hwnd = control->hwnd;
2149 info->oldproc = (WNDPROC)SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
2150 (LONG_PTR)MSIListBox_WndProc );
2151 SetPropW( control->hwnd, szButtonData, info );
2153 msi_listbox_add_items( info );
2155 return ERROR_SUCCESS;
2158 /******************** Directory Combo ***************************************/
2160 static void msi_dialog_update_directory_combo( msi_dialog *dialog, msi_control *control )
2165 if (!control && !(control = msi_dialog_find_control_by_type( dialog, szDirectoryCombo )))
2168 indirect = control->attributes & msidbControlAttributesIndirect;
2169 prop = msi_dialog_dup_property( dialog, control->property, indirect );
2171 path = msi_dup_property( dialog->package, prop );
2175 PathStripPathW( path );
2176 PathRemoveBackslashW( path );
2178 SendMessageW( control->hwnd, CB_INSERTSTRING, 0, (LPARAM)path );
2179 SendMessageW( control->hwnd, CB_SETCURSEL, 0, 0 );
2185 static UINT msi_dialog_directory_combo( msi_dialog *dialog, MSIRECORD *rec )
2187 msi_control *control;
2191 /* FIXME: use CBS_OWNERDRAWFIXED and add owner draw code */
2192 style = CBS_DROPDOWNLIST | CBS_HASSTRINGS | WS_CHILD |
2193 WS_GROUP | WS_TABSTOP | WS_VSCROLL;
2194 control = msi_dialog_add_control( dialog, rec, WC_COMBOBOXW, style );
2196 return ERROR_FUNCTION_FAILED;
2198 control->attributes = MSI_RecordGetInteger( rec, 8 );
2199 prop = MSI_RecordGetString( rec, 9 );
2200 control->property = msi_dialog_dup_property( dialog, prop, FALSE );
2202 msi_dialog_update_directory_combo( dialog, control );
2204 return ERROR_SUCCESS;
2207 /******************** Directory List ***************************************/
2209 static void msi_dialog_update_directory_list( msi_dialog *dialog, msi_control *control )
2211 WCHAR dir_spec[MAX_PATH];
2212 WIN32_FIND_DATAW wfd;
2218 static const WCHAR asterisk[] = {'*',0};
2219 static const WCHAR dot[] = {'.',0};
2220 static const WCHAR dotdot[] = {'.','.',0};
2222 if (!control && !(control = msi_dialog_find_control_by_type( dialog, szDirectoryList )))
2225 /* clear the list-view */
2226 SendMessageW( control->hwnd, LVM_DELETEALLITEMS, 0, 0 );
2228 indirect = control->attributes & msidbControlAttributesIndirect;
2229 prop = msi_dialog_dup_property( dialog, control->property, indirect );
2231 path = msi_dup_property( dialog->package, prop );
2235 lstrcpyW( dir_spec, path );
2236 lstrcatW( dir_spec, asterisk );
2238 file = FindFirstFileW( dir_spec, &wfd );
2239 if ( file == INVALID_HANDLE_VALUE )
2244 if ( wfd.dwFileAttributes != FILE_ATTRIBUTE_DIRECTORY )
2247 if ( !lstrcmpW( wfd.cFileName, dot ) || !lstrcmpW( wfd.cFileName, dotdot ) )
2250 item.mask = LVIF_TEXT;
2251 item.cchTextMax = MAX_PATH;
2254 item.pszText = wfd.cFileName;
2256 SendMessageW( control->hwnd, LVM_INSERTITEMW, 0, (LPARAM)&item );
2257 } while ( FindNextFileW( file, &wfd ) );
2264 UINT msi_dialog_directorylist_up( msi_dialog *dialog )
2266 msi_control *control;
2267 LPWSTR prop, path, ptr;
2270 control = msi_dialog_find_control_by_type( dialog, szDirectoryList );
2271 indirect = control->attributes & msidbControlAttributesIndirect;
2272 prop = msi_dialog_dup_property( dialog, control->property, indirect );
2274 path = msi_dup_property( dialog->package, prop );
2278 /* strip off the last directory */
2279 ptr = PathFindFileNameW( path );
2280 if (ptr != path) *(ptr - 1) = '\0';
2281 PathAddBackslashW( path );
2283 MSI_SetPropertyW( dialog->package, prop, path );
2285 msi_dialog_update_directory_list( dialog, NULL );
2286 msi_dialog_update_directory_combo( dialog, NULL );
2287 msi_dialog_update_pathedit( dialog, NULL );
2292 return ERROR_SUCCESS;
2295 static UINT msi_dialog_dirlist_handler( msi_dialog *dialog,
2296 msi_control *control, WPARAM param )
2298 LPNMHDR nmhdr = (LPNMHDR)param;
2299 WCHAR new_path[MAX_PATH];
2300 WCHAR text[MAX_PATH];
2306 static const WCHAR backslash[] = {'\\',0};
2308 if (nmhdr->code != LVN_ITEMACTIVATE)
2309 return ERROR_SUCCESS;
2311 index = SendMessageW( control->hwnd, LVM_GETNEXTITEM, -1, LVNI_SELECTED );
2314 ERR("No list-view item selected!\n");
2315 return ERROR_FUNCTION_FAILED;
2319 item.pszText = text;
2320 item.cchTextMax = MAX_PATH;
2321 SendMessageW( control->hwnd, LVM_GETITEMTEXTW, index, (LPARAM)&item );
2323 indirect = control->attributes & msidbControlAttributesIndirect;
2324 prop = msi_dialog_dup_property( dialog, control->property, indirect );
2326 path = msi_dup_property( dialog->package, prop );
2330 lstrcpyW( new_path, path );
2331 lstrcatW( new_path, text );
2332 lstrcatW( new_path, backslash );
2334 MSI_SetPropertyW( dialog->package, prop, new_path );
2336 msi_dialog_update_directory_list( dialog, NULL );
2337 msi_dialog_update_directory_combo( dialog, NULL );
2338 msi_dialog_update_pathedit( dialog, NULL );
2342 return ERROR_SUCCESS;
2345 static UINT msi_dialog_directory_list( msi_dialog *dialog, MSIRECORD *rec )
2347 msi_control *control;
2351 style = LVS_LIST | WS_VSCROLL | LVS_SHAREIMAGELISTS |
2352 LVS_AUTOARRANGE | LVS_SINGLESEL | WS_BORDER |
2353 LVS_SORTASCENDING | WS_CHILD | WS_GROUP | WS_TABSTOP;
2354 control = msi_dialog_add_control( dialog, rec, WC_LISTVIEWW, style );
2356 return ERROR_FUNCTION_FAILED;
2358 control->attributes = MSI_RecordGetInteger( rec, 8 );
2359 control->handler = msi_dialog_dirlist_handler;
2360 prop = MSI_RecordGetString( rec, 9 );
2361 control->property = msi_dialog_dup_property( dialog, prop, FALSE );
2363 /* double click to activate an item in the list */
2364 SendMessageW( control->hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE,
2365 0, LVS_EX_TWOCLICKACTIVATE );
2367 msi_dialog_update_directory_list( dialog, control );
2369 return ERROR_SUCCESS;
2372 /******************** VolumeCost List ***************************************/
2374 static BOOL str_is_number( LPCWSTR str )
2378 for (i = 0; i < lstrlenW( str ); i++)
2379 if (!isdigitW(str[i]))
2385 WCHAR column_keys[][80] =
2387 {'V','o','l','u','m','e','C','o','s','t','V','o','l','u','m','e',0},
2388 {'V','o','l','u','m','e','C','o','s','t','S','i','z','e',0},
2389 {'V','o','l','u','m','e','C','o','s','t','A','v','a','i','l','a','b','l','e',0},
2390 {'V','o','l','u','m','e','C','o','s','t','R','e','q','u','i','r','e','d',0},
2391 {'V','o','l','u','m','e','C','o','s','t','D','i','f','f','e','r','e','n','c','e',0}
2394 static void msi_dialog_vcl_add_columns( msi_dialog *dialog, msi_control *control, MSIRECORD *rec )
2396 LPCWSTR text = MSI_RecordGetString( rec, 10 );
2397 LPCWSTR begin = text, end;
2402 static const WCHAR zero[] = {'0',0};
2403 static const WCHAR negative[] = {'-',0};
2405 while ((begin = strchrW( begin, '{' )) && count < 5)
2407 if (!(end = strchrW( begin, '}' )))
2410 lstrcpynW( num, begin + 1, end - begin );
2411 begin += end - begin + 1;
2413 /* empty braces or '0' hides the column */
2414 if ( !num[0] || !lstrcmpW( num, zero ) )
2420 /* the width must be a positive number
2421 * if a width is invalid, all remaining columns are hidden
2423 if ( !strncmpW( num, negative, 1 ) || !str_is_number( num ) )
2426 ZeroMemory( &lvc, sizeof(lvc) );
2427 lvc.mask = LVCF_TEXT | LVCF_WIDTH | LVCF_SUBITEM;
2428 lvc.cx = atolW( num );
2429 lvc.pszText = msi_dialog_get_uitext( dialog, column_keys[count] );
2431 SendMessageW( control->hwnd, LVM_INSERTCOLUMNW, count++, (LPARAM)&lvc );
2432 msi_free( lvc.pszText );
2436 static void msi_dialog_vcl_add_drives( msi_dialog *dialog, msi_control *control )
2438 ULARGE_INTEGER total, free;
2439 WCHAR size_text[MAX_PATH];
2445 size = GetLogicalDriveStringsW( 0, NULL );
2446 if ( !size ) return;
2448 drives = msi_alloc( (size + 1) * sizeof(WCHAR) );
2449 if ( !drives ) return;
2451 GetLogicalDriveStringsW( size, drives );
2456 lvitem.mask = LVIF_TEXT;
2458 lvitem.iSubItem = 0;
2459 lvitem.pszText = ptr;
2460 lvitem.cchTextMax = lstrlenW(ptr) + 1;
2461 SendMessageW( control->hwnd, LVM_INSERTITEMW, 0, (LPARAM)&lvitem );
2463 GetDiskFreeSpaceExW(ptr, &free, &total, NULL);
2465 StrFormatByteSizeW(total.QuadPart, size_text, MAX_PATH);
2466 lvitem.iSubItem = 1;
2467 lvitem.pszText = size_text;
2468 lvitem.cchTextMax = lstrlenW(size_text) + 1;
2469 SendMessageW( control->hwnd, LVM_SETITEMW, 0, (LPARAM)&lvitem );
2471 StrFormatByteSizeW(free.QuadPart, size_text, MAX_PATH);
2472 lvitem.iSubItem = 2;
2473 lvitem.pszText = size_text;
2474 lvitem.cchTextMax = lstrlenW(size_text) + 1;
2475 SendMessageW( control->hwnd, LVM_SETITEMW, 0, (LPARAM)&lvitem );
2477 ptr += lstrlenW(ptr) + 1;
2484 static UINT msi_dialog_volumecost_list( msi_dialog *dialog, MSIRECORD *rec )
2486 msi_control *control;
2489 style = LVS_REPORT | WS_VSCROLL | WS_HSCROLL | LVS_SHAREIMAGELISTS |
2490 LVS_AUTOARRANGE | LVS_SINGLESEL | WS_BORDER |
2491 WS_CHILD | WS_TABSTOP | WS_GROUP;
2492 control = msi_dialog_add_control( dialog, rec, WC_LISTVIEWW, style );
2494 return ERROR_FUNCTION_FAILED;
2496 msi_dialog_vcl_add_columns( dialog, control, rec );
2497 msi_dialog_vcl_add_drives( dialog, control );
2499 return ERROR_SUCCESS;
2502 static const struct control_handler msi_dialog_handler[] =
2504 { szText, msi_dialog_text_control },
2505 { szPushButton, msi_dialog_button_control },
2506 { szLine, msi_dialog_line_control },
2507 { szBitmap, msi_dialog_bitmap_control },
2508 { szCheckBox, msi_dialog_checkbox_control },
2509 { szScrollableText, msi_dialog_scrolltext_control },
2510 { szComboBox, msi_dialog_combo_control },
2511 { szEdit, msi_dialog_edit_control },
2512 { szMaskedEdit, msi_dialog_maskedit_control },
2513 { szPathEdit, msi_dialog_pathedit_control },
2514 { szProgressBar, msi_dialog_progress_bar },
2515 { szRadioButtonGroup, msi_dialog_radiogroup_control },
2516 { szIcon, msi_dialog_icon_control },
2517 { szSelectionTree, msi_dialog_selection_tree },
2518 { szGroupBox, msi_dialog_group_box },
2519 { szListBox, msi_dialog_list_box },
2520 { szDirectoryCombo, msi_dialog_directory_combo },
2521 { szDirectoryList, msi_dialog_directory_list },
2522 { szVolumeCostList, msi_dialog_volumecost_list },
2525 #define NUM_CONTROL_TYPES (sizeof msi_dialog_handler/sizeof msi_dialog_handler[0])
2527 static UINT msi_dialog_create_controls( MSIRECORD *rec, LPVOID param )
2529 msi_dialog *dialog = param;
2530 LPCWSTR control_type;
2533 /* find and call the function that can create this type of control */
2534 control_type = MSI_RecordGetString( rec, 3 );
2535 for( i=0; i<NUM_CONTROL_TYPES; i++ )
2536 if (!strcmpiW( msi_dialog_handler[i].control_type, control_type ))
2538 if( i != NUM_CONTROL_TYPES )
2539 msi_dialog_handler[i].func( dialog, rec );
2541 ERR("no handler for element type %s\n", debugstr_w(control_type));
2543 return ERROR_SUCCESS;
2546 static UINT msi_dialog_fill_controls( msi_dialog *dialog )
2548 static const WCHAR query[] = {
2549 'S','E','L','E','C','T',' ','*',' ',
2550 'F','R','O','M',' ','C','o','n','t','r','o','l',' ',
2551 'W','H','E','R','E',' ',
2552 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',0};
2554 MSIQUERY *view = NULL;
2555 MSIPACKAGE *package = dialog->package;
2557 TRACE("%p %s\n", dialog, debugstr_w(dialog->name) );
2559 /* query the Control table for all the elements of the control */
2560 r = MSI_OpenQuery( package->db, &view, query, dialog->name );
2561 if( r != ERROR_SUCCESS )
2563 ERR("query failed for dialog %s\n", debugstr_w(dialog->name));
2564 return ERROR_INVALID_PARAMETER;
2567 r = MSI_IterateRecords( view, 0, msi_dialog_create_controls, dialog );
2568 msiobj_release( &view->hdr );
2573 static UINT msi_dialog_set_control_condition( MSIRECORD *rec, LPVOID param )
2575 static const WCHAR szHide[] = { 'H','i','d','e',0 };
2576 static const WCHAR szShow[] = { 'S','h','o','w',0 };
2577 static const WCHAR szDisable[] = { 'D','i','s','a','b','l','e',0 };
2578 static const WCHAR szEnable[] = { 'E','n','a','b','l','e',0 };
2579 msi_dialog *dialog = param;
2580 msi_control *control;
2581 LPCWSTR name, action, condition;
2584 name = MSI_RecordGetString( rec, 2 );
2585 action = MSI_RecordGetString( rec, 3 );
2586 condition = MSI_RecordGetString( rec, 4 );
2587 r = MSI_EvaluateConditionW( dialog->package, condition );
2588 control = msi_dialog_find_control( dialog, name );
2589 if( r == MSICONDITION_TRUE && control )
2591 TRACE("%s control %s\n", debugstr_w(action), debugstr_w(name));
2593 /* FIXME: case sensitive? */
2594 if(!lstrcmpW(action, szHide))
2595 ShowWindow(control->hwnd, SW_HIDE);
2596 else if(!strcmpW(action, szShow))
2597 ShowWindow(control->hwnd, SW_SHOW);
2598 else if(!strcmpW(action, szDisable))
2599 EnableWindow(control->hwnd, FALSE);
2600 else if(!strcmpW(action, szEnable))
2601 EnableWindow(control->hwnd, TRUE);
2603 FIXME("Unhandled action %s\n", debugstr_w(action));
2606 return ERROR_SUCCESS;
2609 static UINT msi_dialog_evaluate_control_conditions( msi_dialog *dialog )
2611 static const WCHAR query[] = {
2612 'S','E','L','E','C','T',' ','*',' ',
2613 'F','R','O','M',' ',
2614 'C','o','n','t','r','o','l','C','o','n','d','i','t','i','o','n',' ',
2615 'W','H','E','R','E',' ',
2616 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',0
2619 MSIQUERY *view = NULL;
2620 MSIPACKAGE *package = dialog->package;
2622 TRACE("%p %s\n", dialog, debugstr_w(dialog->name) );
2624 /* query the Control table for all the elements of the control */
2625 r = MSI_OpenQuery( package->db, &view, query, dialog->name );
2626 if( r != ERROR_SUCCESS )
2627 return ERROR_SUCCESS;
2629 r = MSI_IterateRecords( view, 0, msi_dialog_set_control_condition, dialog );
2630 msiobj_release( &view->hdr );
2635 UINT msi_dialog_reset( msi_dialog *dialog )
2637 /* FIXME: should restore the original values of any properties we changed */
2638 return msi_dialog_evaluate_control_conditions( dialog );
2641 /* figure out the height of 10 point MS Sans Serif */
2642 static INT msi_dialog_get_sans_serif_height( HWND hwnd )
2644 static const WCHAR szSansSerif[] = {
2645 'M','S',' ','S','a','n','s',' ','S','e','r','i','f',0 };
2650 HFONT hFont, hOldFont;
2653 hdc = GetDC( hwnd );
2656 memset( &lf, 0, sizeof lf );
2657 lf.lfHeight = MulDiv(10, GetDeviceCaps(hdc, LOGPIXELSY), 72);
2658 strcpyW( lf.lfFaceName, szSansSerif );
2659 hFont = CreateFontIndirectW(&lf);
2662 hOldFont = SelectObject( hdc, hFont );
2663 r = GetTextMetricsW( hdc, &tm );
2665 height = tm.tmHeight;
2666 SelectObject( hdc, hOldFont );
2667 DeleteObject( hFont );
2669 ReleaseDC( hwnd, hdc );
2674 /* fetch the associated record from the Dialog table */
2675 static MSIRECORD *msi_get_dialog_record( msi_dialog *dialog )
2677 static const WCHAR query[] = {
2678 'S','E','L','E','C','T',' ','*',' ',
2679 'F','R','O','M',' ','D','i','a','l','o','g',' ',
2680 'W','H','E','R','E',' ',
2681 '`','D','i','a','l','o','g','`',' ','=',' ','\'','%','s','\'',0};
2682 MSIPACKAGE *package = dialog->package;
2683 MSIRECORD *rec = NULL;
2685 TRACE("%p %s\n", dialog, debugstr_w(dialog->name) );
2687 rec = MSI_QueryGetRecord( package->db, query, dialog->name );
2689 ERR("query failed for dialog %s\n", debugstr_w(dialog->name));
2694 static void msi_dialog_adjust_dialog_pos( msi_dialog *dialog, MSIRECORD *rec, LPRECT pos )
2696 static const WCHAR szScreenX[] = {'S','c','r','e','e','n','X',0};
2697 static const WCHAR szScreenY[] = {'S','c','r','e','e','n','Y',0};
2704 center.x = MSI_RecordGetInteger( rec, 2 );
2705 center.y = MSI_RecordGetInteger( rec, 3 );
2707 sz.cx = MSI_RecordGetInteger( rec, 4 );
2708 sz.cy = MSI_RecordGetInteger( rec, 5 );
2710 sz.cx = msi_dialog_scale_unit( dialog, sz.cx );
2711 sz.cy = msi_dialog_scale_unit( dialog, sz.cy );
2713 xres = msi_get_property_int( dialog->package, szScreenX, 0 );
2714 yres = msi_get_property_int( dialog->package, szScreenY, 0 );
2716 center.x = MulDiv( center.x, xres, 100 );
2717 center.y = MulDiv( center.y, yres, 100 );
2719 /* turn the client pos into the window rectangle */
2720 if (dialog->package->center_x && dialog->package->center_y)
2722 pos->left = dialog->package->center_x - sz.cx / 2.0;
2723 pos->right = pos->left + sz.cx;
2724 pos->top = dialog->package->center_y - sz.cy / 2.0;
2725 pos->bottom = pos->top + sz.cy;
2729 pos->left = center.x - sz.cx/2;
2730 pos->right = pos->left + sz.cx;
2731 pos->top = center.y - sz.cy/2;
2732 pos->bottom = pos->top + sz.cy;
2734 /* save the center */
2735 dialog->package->center_x = center.x;
2736 dialog->package->center_y = center.y;
2739 dialog->size.cx = sz.cx;
2740 dialog->size.cy = sz.cy;
2742 TRACE("%lu %lu %lu %lu\n", pos->left, pos->top, pos->right, pos->bottom);
2744 style = GetWindowLongPtrW( dialog->hwnd, GWL_STYLE );
2745 AdjustWindowRect( pos, style, FALSE );
2748 static BOOL msi_control_set_next( msi_control *control, msi_control *next )
2750 return SetWindowPos( next->hwnd, control->hwnd, 0, 0, 0, 0,
2751 SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOREDRAW |
2752 SWP_NOREPOSITION | SWP_NOSENDCHANGING | SWP_NOSIZE );
2755 static UINT msi_dialog_set_tab_order( msi_dialog *dialog )
2757 msi_control *control, *tab_next;
2759 LIST_FOR_EACH_ENTRY( control, &dialog->controls, msi_control, entry )
2761 tab_next = msi_dialog_find_control( dialog, control->tabnext );
2764 msi_control_set_next( control, tab_next );
2767 return ERROR_SUCCESS;
2770 static void msi_dialog_set_first_control( msi_dialog* dialog, LPCWSTR name )
2772 msi_control *control;
2774 control = msi_dialog_find_control( dialog, name );
2776 dialog->hWndFocus = control->hwnd;
2778 dialog->hWndFocus = NULL;
2781 static LRESULT msi_dialog_oncreate( HWND hwnd, LPCREATESTRUCTW cs )
2783 static const WCHAR df[] = {
2784 'D','e','f','a','u','l','t','U','I','F','o','n','t',0 };
2785 static const WCHAR dfv[] = {
2786 'M','S',' ','S','h','e','l','l',' ','D','l','g',0 };
2787 msi_dialog *dialog = (msi_dialog*) cs->lpCreateParams;
2788 MSIRECORD *rec = NULL;
2789 LPWSTR title = NULL;
2792 TRACE("%p %p\n", dialog, dialog->package);
2794 dialog->hwnd = hwnd;
2795 SetWindowLongPtrW( hwnd, GWLP_USERDATA, (LONG_PTR) dialog );
2797 rec = msi_get_dialog_record( dialog );
2800 TRACE("No record found for dialog %s\n", debugstr_w(dialog->name));
2804 dialog->scale = msi_dialog_get_sans_serif_height(dialog->hwnd);
2806 msi_dialog_adjust_dialog_pos( dialog, rec, &pos );
2808 dialog->attributes = MSI_RecordGetInteger( rec, 6 );
2810 dialog->default_font = msi_dup_property( dialog->package, df );
2811 if (!dialog->default_font)
2813 dialog->default_font = strdupW(dfv);
2814 if (!dialog->default_font) return -1;
2817 title = msi_get_deformatted_field( dialog->package, rec, 7 );
2818 SetWindowTextW( hwnd, title );
2821 SetWindowPos( hwnd, 0, pos.left, pos.top,
2822 pos.right - pos.left, pos.bottom - pos.top,
2823 SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOREDRAW );
2825 msi_dialog_build_font_list( dialog );
2826 msi_dialog_fill_controls( dialog );
2827 msi_dialog_evaluate_control_conditions( dialog );
2828 msi_dialog_set_tab_order( dialog );
2829 msi_dialog_set_first_control( dialog, MSI_RecordGetString( rec, 8 ) );
2830 msiobj_release( &rec->hdr );
2835 static UINT msi_dialog_send_event( msi_dialog *dialog, LPCWSTR event, LPCWSTR arg )
2837 LPWSTR event_fmt = NULL, arg_fmt = NULL;
2839 TRACE("Sending control event %s %s\n", debugstr_w(event), debugstr_w(arg));
2841 deformat_string( dialog->package, event, &event_fmt );
2842 deformat_string( dialog->package, arg, &arg_fmt );
2844 dialog->event_handler( dialog->package, event_fmt, arg_fmt, dialog );
2846 msi_free( event_fmt );
2847 msi_free( arg_fmt );
2849 return ERROR_SUCCESS;
2852 static UINT msi_dialog_set_property( msi_dialog *dialog, LPCWSTR event, LPCWSTR arg )
2854 static const WCHAR szNullArg[] = { '{','}',0 };
2855 LPWSTR p, prop, arg_fmt = NULL;
2858 len = strlenW(event);
2859 prop = msi_alloc( len*sizeof(WCHAR));
2860 strcpyW( prop, &event[1] );
2861 p = strchrW( prop, ']' );
2862 if( p && p[1] == 0 )
2865 if( strcmpW( szNullArg, arg ) )
2866 deformat_string( dialog->package, arg, &arg_fmt );
2867 MSI_SetPropertyW( dialog->package, prop, arg_fmt );
2868 msi_free( arg_fmt );
2871 ERR("Badly formatted property string - what happens?\n");
2873 return ERROR_SUCCESS;
2876 static UINT msi_dialog_control_event( MSIRECORD *rec, LPVOID param )
2878 msi_dialog *dialog = param;
2879 LPCWSTR condition, event, arg;
2882 condition = MSI_RecordGetString( rec, 5 );
2883 r = MSI_EvaluateConditionW( dialog->package, condition );
2884 if( r == MSICONDITION_TRUE || r == MSICONDITION_NONE )
2886 event = MSI_RecordGetString( rec, 3 );
2887 arg = MSI_RecordGetString( rec, 4 );
2888 if( event[0] == '[' )
2889 msi_dialog_set_property( dialog, event, arg );
2891 msi_dialog_send_event( dialog, event, arg );
2894 return ERROR_SUCCESS;
2897 static UINT msi_dialog_button_handler( msi_dialog *dialog,
2898 msi_control *control, WPARAM param )
2900 static const WCHAR query[] = {
2901 'S','E','L','E','C','T',' ','*',' ',
2902 'F','R','O','M',' ','C','o','n','t','r','o','l','E','v','e','n','t',' ',
2903 'W','H','E','R','E',' ',
2904 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',' ',
2906 '`','C','o','n','t','r','o','l','_','`',' ','=',' ','\'','%','s','\'',' ',
2907 'O','R','D','E','R',' ','B','Y',' ','`','O','r','d','e','r','i','n','g','`',0
2909 MSIQUERY *view = NULL;
2912 if( HIWORD(param) != BN_CLICKED )
2913 return ERROR_SUCCESS;
2915 r = MSI_OpenQuery( dialog->package->db, &view, query,
2916 dialog->name, control->name );
2917 if( r != ERROR_SUCCESS )
2919 ERR("query failed\n");
2923 r = MSI_IterateRecords( view, 0, msi_dialog_control_event, dialog );
2924 msiobj_release( &view->hdr );
2929 static UINT msi_dialog_get_checkbox_state( msi_dialog *dialog,
2930 msi_control *control )
2932 WCHAR state[2] = { 0 };
2935 MSI_GetPropertyW( dialog->package, control->property, state, &sz );
2936 return state[0] ? 1 : 0;
2939 static void msi_dialog_set_checkbox_state( msi_dialog *dialog,
2940 msi_control *control, UINT state )
2942 static const WCHAR szState[] = { '1', 0 };
2945 /* if uncheck then the property is set to NULL */
2948 MSI_SetPropertyW( dialog->package, control->property, NULL );
2952 /* check for a custom state */
2953 if (control->value && control->value[0])
2954 val = control->value;
2958 MSI_SetPropertyW( dialog->package, control->property, val );
2961 static void msi_dialog_checkbox_sync_state( msi_dialog *dialog,
2962 msi_control *control )
2966 state = msi_dialog_get_checkbox_state( dialog, control );
2967 SendMessageW( control->hwnd, BM_SETCHECK,
2968 state ? BST_CHECKED : BST_UNCHECKED, 0 );
2971 static UINT msi_dialog_checkbox_handler( msi_dialog *dialog,
2972 msi_control *control, WPARAM param )
2976 if( HIWORD(param) != BN_CLICKED )
2977 return ERROR_SUCCESS;
2979 TRACE("clicked checkbox %s, set %s\n", debugstr_w(control->name),
2980 debugstr_w(control->property));
2982 state = msi_dialog_get_checkbox_state( dialog, control );
2983 state = state ? 0 : 1;
2984 msi_dialog_set_checkbox_state( dialog, control, state );
2985 msi_dialog_checkbox_sync_state( dialog, control );
2987 return msi_dialog_button_handler( dialog, control, param );
2990 static UINT msi_dialog_edit_handler( msi_dialog *dialog,
2991 msi_control *control, WPARAM param )
2995 if( HIWORD(param) != EN_CHANGE )
2996 return ERROR_SUCCESS;
2998 TRACE("edit %s contents changed, set %s\n", debugstr_w(control->name),
2999 debugstr_w(control->property));
3001 buf = msi_get_window_text( control->hwnd );
3002 MSI_SetPropertyW( dialog->package, control->property, buf );
3006 return ERROR_SUCCESS;
3009 static UINT msi_dialog_radiogroup_handler( msi_dialog *dialog,
3010 msi_control *control, WPARAM param )
3012 if( HIWORD(param) != BN_CLICKED )
3013 return ERROR_SUCCESS;
3015 TRACE("clicked radio button %s, set %s\n", debugstr_w(control->name),
3016 debugstr_w(control->property));
3018 MSI_SetPropertyW( dialog->package, control->property, control->name );
3020 return msi_dialog_button_handler( dialog, control, param );
3023 static LRESULT msi_dialog_oncommand( msi_dialog *dialog, WPARAM param, HWND hwnd )
3025 msi_control *control = NULL;
3027 TRACE("%p %p %08x\n", dialog, hwnd, param);
3032 control = msi_dialog_find_control( dialog, dialog->control_default );
3034 case 2: /* escape */
3035 control = msi_dialog_find_control( dialog, dialog->control_cancel );
3038 control = msi_dialog_find_control_by_hwnd( dialog, hwnd );
3043 if( control->handler )
3045 control->handler( dialog, control, param );
3046 msi_dialog_evaluate_control_conditions( dialog );
3050 ERR("button click from nowhere %p %d %p\n", dialog, param, hwnd);
3054 static LRESULT msi_dialog_onnotify( msi_dialog *dialog, LPARAM param )
3056 LPNMHDR nmhdr = (LPNMHDR) param;
3057 msi_control *control = msi_dialog_find_control_by_hwnd( dialog, nmhdr->hwndFrom );
3059 TRACE("%p %p\n", dialog, nmhdr->hwndFrom);
3061 if ( control && control->handler )
3062 control->handler( dialog, control, param );
3067 static void msi_dialog_setfocus( msi_dialog *dialog )
3069 HWND hwnd = dialog->hWndFocus;
3071 hwnd = GetNextDlgTabItem( dialog->hwnd, hwnd, TRUE);
3072 hwnd = GetNextDlgTabItem( dialog->hwnd, hwnd, FALSE);
3074 dialog->hWndFocus = hwnd;
3077 static LRESULT WINAPI MSIDialog_WndProc( HWND hwnd, UINT msg,
3078 WPARAM wParam, LPARAM lParam )
3080 msi_dialog *dialog = (LPVOID) GetWindowLongPtrW( hwnd, GWLP_USERDATA );
3082 TRACE("0x%04x\n", msg);
3087 dialog->package->center_x = LOWORD(lParam) + dialog->size.cx / 2.0;
3088 dialog->package->center_y = HIWORD(lParam) + dialog->size.cy / 2.0;
3092 return msi_dialog_oncreate( hwnd, (LPCREATESTRUCTW)lParam );
3095 return msi_dialog_oncommand( dialog, wParam, (HWND)lParam );
3098 if( LOWORD(wParam) == WA_INACTIVE )
3099 dialog->hWndFocus = GetFocus();
3101 msi_dialog_setfocus( dialog );
3105 msi_dialog_setfocus( dialog );
3108 /* bounce back to our subclassed static control */
3109 case WM_CTLCOLORSTATIC:
3110 return SendMessageW( (HWND) lParam, WM_CTLCOLORSTATIC, wParam, lParam );
3113 dialog->hwnd = NULL;
3116 return msi_dialog_onnotify( dialog, lParam );
3118 return DefWindowProcW(hwnd, msg, wParam, lParam);
3121 static BOOL CALLBACK msi_radioground_child_enum( HWND hWnd, LPARAM lParam )
3123 EnableWindow( hWnd, lParam );
3127 static LRESULT WINAPI MSIRadioGroup_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
3129 WNDPROC oldproc = (WNDPROC) GetPropW(hWnd, szButtonData);
3132 TRACE("hWnd %p msg %04x wParam 0x%08x lParam 0x%08lx\n", hWnd, msg, wParam, lParam);
3134 if (msg == WM_COMMAND) /* Forward notifications to dialog */
3135 SendMessageW(GetParent(hWnd), msg, wParam, lParam);
3137 r = CallWindowProcW(oldproc, hWnd, msg, wParam, lParam);
3139 /* make sure the radio buttons show as disabled if the parent is disabled */
3140 if (msg == WM_ENABLE)
3141 EnumChildWindows( hWnd, msi_radioground_child_enum, wParam );
3146 static LRESULT WINAPI MSIHiddenWindowProc( HWND hwnd, UINT msg,
3147 WPARAM wParam, LPARAM lParam )
3149 msi_dialog *dialog = (msi_dialog*) lParam;
3151 TRACE("%d %p\n", msg, dialog);
3155 case WM_MSI_DIALOG_CREATE:
3156 return msi_dialog_run_message_loop( dialog );
3157 case WM_MSI_DIALOG_DESTROY:
3158 msi_dialog_destroy( dialog );
3161 return DefWindowProcW( hwnd, msg, wParam, lParam );
3164 /* functions that interface to other modules within MSI */
3166 msi_dialog *msi_dialog_create( MSIPACKAGE* package,
3167 LPCWSTR szDialogName, msi_dialog *parent,
3168 msi_dialog_event_handler event_handler )
3170 MSIRECORD *rec = NULL;
3173 TRACE("%p %s\n", package, debugstr_w(szDialogName));
3175 /* allocate the structure for the dialog to use */
3176 dialog = msi_alloc_zero( sizeof *dialog + sizeof(WCHAR)*strlenW(szDialogName) );
3179 strcpyW( dialog->name, szDialogName );
3180 dialog->parent = parent;
3181 msiobj_addref( &package->hdr );
3182 dialog->package = package;
3183 dialog->event_handler = event_handler;
3184 dialog->finished = 0;
3185 list_init( &dialog->controls );
3187 /* verify that the dialog exists */
3188 rec = msi_get_dialog_record( dialog );
3191 msiobj_release( &package->hdr );
3195 dialog->attributes = MSI_RecordGetInteger( rec, 6 );
3196 dialog->control_default = strdupW( MSI_RecordGetString( rec, 9 ) );
3197 dialog->control_cancel = strdupW( MSI_RecordGetString( rec, 10 ) );
3198 msiobj_release( &rec->hdr );
3203 static void msi_process_pending_messages( HWND hdlg )
3207 while( PeekMessageW( &msg, 0, 0, 0, PM_REMOVE ) )
3209 if( hdlg && IsDialogMessageW( hdlg, &msg ))
3211 TranslateMessage( &msg );
3212 DispatchMessageW( &msg );
3216 void msi_dialog_end_dialog( msi_dialog *dialog )
3218 TRACE("%p\n", dialog);
3219 dialog->finished = 1;
3220 PostMessageW(dialog->hwnd, WM_NULL, 0, 0);
3223 void msi_dialog_check_messages( HANDLE handle )
3227 /* in threads other than the UI thread, block */
3228 if( uiThreadId != GetCurrentThreadId() )
3231 WaitForSingleObject( handle, INFINITE );
3235 /* there's two choices for the UI thread */
3238 msi_process_pending_messages( NULL );
3244 * block here until somebody creates a new dialog or
3245 * the handle we're waiting on becomes ready
3247 r = MsgWaitForMultipleObjects( 1, &handle, 0, INFINITE, QS_ALLINPUT );
3248 if( r == WAIT_OBJECT_0 )
3253 UINT msi_dialog_run_message_loop( msi_dialog *dialog )
3258 if( uiThreadId != GetCurrentThreadId() )
3259 return SendMessageW( hMsiHiddenWindow, WM_MSI_DIALOG_CREATE, 0, (LPARAM) dialog );
3261 /* create the dialog window, don't show it yet */
3262 style = WS_OVERLAPPED;
3263 if( dialog->attributes & msidbDialogAttributesVisible )
3264 style |= WS_VISIBLE;
3266 hwnd = CreateWindowW( szMsiDialogClass, dialog->name, style,
3267 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
3268 NULL, NULL, NULL, dialog );
3271 ERR("Failed to create dialog %s\n", debugstr_w( dialog->name ));
3272 return ERROR_FUNCTION_FAILED;
3275 ShowWindow( hwnd, SW_SHOW );
3276 /* UpdateWindow( hwnd ); - and causes the transparent static controls not to paint */
3278 if( dialog->attributes & msidbDialogAttributesModal )
3280 while( !dialog->finished )
3282 MsgWaitForMultipleObjects( 0, NULL, 0, INFINITE, QS_ALLINPUT );
3283 msi_process_pending_messages( dialog->hwnd );
3287 return ERROR_IO_PENDING;
3289 return ERROR_SUCCESS;
3292 void msi_dialog_do_preview( msi_dialog *dialog )
3295 dialog->attributes |= msidbDialogAttributesVisible;
3296 dialog->attributes &= ~msidbDialogAttributesModal;
3297 msi_dialog_run_message_loop( dialog );
3300 void msi_dialog_destroy( msi_dialog *dialog )
3302 if( uiThreadId != GetCurrentThreadId() )
3304 SendMessageW( hMsiHiddenWindow, WM_MSI_DIALOG_DESTROY, 0, (LPARAM) dialog );
3309 ShowWindow( dialog->hwnd, SW_HIDE );
3312 DestroyWindow( dialog->hwnd );
3314 /* destroy the list of controls */
3315 while( !list_empty( &dialog->controls ) )
3317 msi_control *t = LIST_ENTRY( list_head( &dialog->controls ),
3318 msi_control, entry );
3319 list_remove( &t->entry );
3320 /* leave dialog->hwnd - destroying parent destroys child windows */
3321 msi_free( t->property );
3322 msi_free( t->value );
3324 DeleteObject( t->hBitmap );
3326 DestroyIcon( t->hIcon );
3327 msi_free( t->tabnext );
3328 msi_free( t->type );
3331 FreeLibrary( t->hDll );
3334 /* destroy the list of fonts */
3335 while( dialog->font_list )
3337 msi_font *t = dialog->font_list;
3338 dialog->font_list = t->next;
3339 DeleteObject( t->hfont );
3342 msi_free( dialog->default_font );
3344 msi_free( dialog->control_default );
3345 msi_free( dialog->control_cancel );
3346 msiobj_release( &dialog->package->hdr );
3347 dialog->package = NULL;
3351 BOOL msi_dialog_register_class( void )
3355 ZeroMemory( &cls, sizeof cls );
3356 cls.lpfnWndProc = MSIDialog_WndProc;
3357 cls.hInstance = NULL;
3358 cls.hIcon = LoadIconW(0, (LPWSTR)IDI_APPLICATION);
3359 cls.hCursor = LoadCursorW(0, (LPWSTR)IDC_ARROW);
3360 cls.hbrBackground = (HBRUSH)(COLOR_3DFACE + 1);
3361 cls.lpszMenuName = NULL;
3362 cls.lpszClassName = szMsiDialogClass;
3364 if( !RegisterClassW( &cls ) )
3367 cls.lpfnWndProc = MSIHiddenWindowProc;
3368 cls.lpszClassName = szMsiHiddenWindow;
3370 if( !RegisterClassW( &cls ) )
3373 uiThreadId = GetCurrentThreadId();
3375 hMsiHiddenWindow = CreateWindowW( szMsiHiddenWindow, NULL, WS_OVERLAPPED,
3376 0, 0, 100, 100, NULL, NULL, NULL, NULL );
3377 if( !hMsiHiddenWindow )
3383 void msi_dialog_unregister_class( void )
3385 DestroyWindow( hMsiHiddenWindow );
3386 hMsiHiddenWindow = NULL;
3387 UnregisterClassW( szMsiDialogClass, NULL );
3388 UnregisterClassW( szMsiHiddenWindow, NULL );