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 };
149 static UINT msi_dialog_checkbox_handler( msi_dialog *, msi_control *, WPARAM );
150 static void msi_dialog_checkbox_sync_state( msi_dialog *, msi_control * );
151 static UINT msi_dialog_button_handler( msi_dialog *, msi_control *, WPARAM );
152 static UINT msi_dialog_edit_handler( msi_dialog *, msi_control *, WPARAM );
153 static UINT msi_dialog_radiogroup_handler( msi_dialog *, msi_control *, WPARAM param );
154 static UINT msi_dialog_evaluate_control_conditions( msi_dialog *dialog );
155 static LRESULT WINAPI MSIRadioGroup_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
158 /* dialog sequencing */
160 #define WM_MSI_DIALOG_CREATE (WM_USER+0x100)
161 #define WM_MSI_DIALOG_DESTROY (WM_USER+0x101)
163 static DWORD uiThreadId;
164 static HWND hMsiHiddenWindow;
166 static INT msi_dialog_scale_unit( msi_dialog *dialog, INT val )
168 return (dialog->scale * val + 5) / 10;
171 static msi_control *msi_dialog_find_control( msi_dialog *dialog, LPCWSTR name )
173 msi_control *control;
177 LIST_FOR_EACH_ENTRY( control, &dialog->controls, msi_control, entry )
178 if( !strcmpW( control->name, name ) ) /* FIXME: case sensitive? */
183 static msi_control *msi_dialog_find_control_by_type( msi_dialog *dialog, LPCWSTR type )
185 msi_control *control;
189 LIST_FOR_EACH_ENTRY( control, &dialog->controls, msi_control, entry )
190 if( !strcmpW( control->type, type ) ) /* FIXME: case sensitive? */
195 static msi_control *msi_dialog_find_control_by_hwnd( msi_dialog *dialog, HWND hwnd )
197 msi_control *control;
199 LIST_FOR_EACH_ENTRY( control, &dialog->controls, msi_control, entry )
200 if( hwnd == control->hwnd )
205 static LPWSTR msi_get_deformatted_field( MSIPACKAGE *package, MSIRECORD *rec, int field )
207 LPCWSTR str = MSI_RecordGetString( rec, field );
211 deformat_string( package, str, &ret );
215 static LPWSTR msi_dialog_dup_property( msi_dialog *dialog, LPCWSTR property, BOOL indirect )
221 return msi_dup_property( dialog->package, property );
223 return strdupW( property );
226 msi_dialog *msi_dialog_get_parent( msi_dialog *dialog )
228 return dialog->parent;
231 LPWSTR msi_dialog_get_name( msi_dialog *dialog )
237 * msi_dialog_get_style
239 * Extract the {\style} string from the front of the text to display and
240 * update the pointer.
242 static LPWSTR msi_dialog_get_style( LPCWSTR p, LPCWSTR *rest )
253 q = strchrW( p, '}' );
256 if( *p == '\\' || *p == '&' )
259 /* little bit of sanity checking to stop us getting confused with RTF */
261 if( *i == '}' || *i == '\\' )
267 ret = msi_alloc( len*sizeof(WCHAR) );
270 memcpy( ret, p, len*sizeof(WCHAR) );
275 static UINT msi_dialog_add_font( MSIRECORD *rec, LPVOID param )
277 msi_dialog *dialog = param;
284 /* create a font and add it to the list */
285 name = MSI_RecordGetString( rec, 1 );
286 font = msi_alloc( sizeof *font + strlenW( name )*sizeof (WCHAR) );
287 strcpyW( font->name, name );
288 font->next = dialog->font_list;
289 dialog->font_list = font;
291 font->color = MSI_RecordGetInteger( rec, 4 );
293 memset( &lf, 0, sizeof lf );
294 face = MSI_RecordGetString( rec, 2 );
295 lf.lfHeight = MSI_RecordGetInteger( rec, 3 );
296 style = MSI_RecordGetInteger( rec, 5 );
297 if( style & msidbTextStyleStyleBitsBold )
298 lf.lfWeight = FW_BOLD;
299 if( style & msidbTextStyleStyleBitsItalic )
301 if( style & msidbTextStyleStyleBitsUnderline )
302 lf.lfUnderline = TRUE;
303 if( style & msidbTextStyleStyleBitsStrike )
304 lf.lfStrikeOut = TRUE;
305 lstrcpynW( lf.lfFaceName, face, LF_FACESIZE );
307 /* adjust the height */
308 hdc = GetDC( dialog->hwnd );
311 lf.lfHeight = -MulDiv(lf.lfHeight, GetDeviceCaps(hdc, LOGPIXELSY), 72);
312 ReleaseDC( dialog->hwnd, hdc );
315 font->hfont = CreateFontIndirectW( &lf );
317 TRACE("Adding font style %s\n", debugstr_w(font->name) );
319 return ERROR_SUCCESS;
322 static msi_font *msi_dialog_find_font( msi_dialog *dialog, LPCWSTR name )
326 for( font = dialog->font_list; font; font = font->next )
327 if( !strcmpW( font->name, name ) ) /* FIXME: case sensitive? */
333 static UINT msi_dialog_set_font( msi_dialog *dialog, HWND hwnd, LPCWSTR name )
337 font = msi_dialog_find_font( dialog, name );
339 SendMessageW( hwnd, WM_SETFONT, (WPARAM) font->hfont, TRUE );
341 ERR("No font entry for %s\n", debugstr_w(name));
342 return ERROR_SUCCESS;
345 static UINT msi_dialog_build_font_list( msi_dialog *dialog )
347 static const WCHAR query[] = {
348 'S','E','L','E','C','T',' ','*',' ',
349 'F','R','O','M',' ','`','T','e','x','t','S','t','y','l','e','`',' ',0
352 MSIQUERY *view = NULL;
354 TRACE("dialog %p\n", dialog );
356 r = MSI_OpenQuery( dialog->package->db, &view, query );
357 if( r != ERROR_SUCCESS )
360 r = MSI_IterateRecords( view, NULL, msi_dialog_add_font, dialog );
361 msiobj_release( &view->hdr );
366 static msi_control *msi_dialog_create_window( msi_dialog *dialog,
367 MSIRECORD *rec, DWORD exstyle, LPCWSTR szCls, LPCWSTR name, LPCWSTR text,
368 DWORD style, HWND parent )
370 DWORD x, y, width, height;
371 LPWSTR font = NULL, title_font = NULL;
372 LPCWSTR title = NULL;
373 msi_control *control;
377 control = msi_alloc( sizeof *control + strlenW(name)*sizeof(WCHAR) );
378 strcpyW( control->name, name );
379 list_add_head( &dialog->controls, &control->entry );
380 control->handler = NULL;
381 control->property = NULL;
382 control->value = NULL;
383 control->hBitmap = NULL;
384 control->hIcon = NULL;
385 control->hDll = NULL;
386 control->tabnext = strdupW( MSI_RecordGetString( rec, 11) );
387 control->type = strdupW( MSI_RecordGetString( rec, 3 ) );
388 control->progress_current = 0;
389 control->progress_max = 100;
391 x = MSI_RecordGetInteger( rec, 4 );
392 y = MSI_RecordGetInteger( rec, 5 );
393 width = MSI_RecordGetInteger( rec, 6 );
394 height = MSI_RecordGetInteger( rec, 7 );
396 x = msi_dialog_scale_unit( dialog, x );
397 y = msi_dialog_scale_unit( dialog, y );
398 width = msi_dialog_scale_unit( dialog, width );
399 height = msi_dialog_scale_unit( dialog, height );
403 deformat_string( dialog->package, text, &title_font );
404 font = msi_dialog_get_style( title_font, &title );
407 control->hwnd = CreateWindowExW( exstyle, szCls, title, style,
408 x, y, width, height, parent, NULL, NULL, NULL );
410 TRACE("Dialog %s control %s hwnd %p\n",
411 debugstr_w(dialog->name), debugstr_w(text), control->hwnd );
413 msi_dialog_set_font( dialog, control->hwnd,
414 font ? font : dialog->default_font );
416 msi_free( title_font );
422 static LPWSTR msi_dialog_get_uitext( msi_dialog *dialog, LPCWSTR key )
427 static const WCHAR query[] = {
428 's','e','l','e','c','t',' ','*',' ',
429 'f','r','o','m',' ','`','U','I','T','e','x','t','`',' ',
430 'w','h','e','r','e',' ','`','K','e','y','`',' ','=',' ','\'','%','s','\'',0
433 rec = MSI_QueryGetRecord( dialog->package->db, query, key );
434 if (!rec) return NULL;
435 text = strdupW( MSI_RecordGetString( rec, 2 ) );
436 msiobj_release( &rec->hdr );
440 static MSIRECORD *msi_get_binary_record( MSIDATABASE *db, LPCWSTR name )
442 static const WCHAR query[] = {
443 's','e','l','e','c','t',' ','*',' ',
444 'f','r','o','m',' ','B','i','n','a','r','y',' ',
445 'w','h','e','r','e',' ',
446 '`','N','a','m','e','`',' ','=',' ','\'','%','s','\'',0
449 return MSI_QueryGetRecord( db, query, name );
452 static LPWSTR msi_create_tmp_path(void)
456 static const WCHAR prefix[] = { 'm','s','i',0 };
459 r = GetTempPathW( MAX_PATH, tmp );
462 len = lstrlenW( tmp ) + 20;
463 path = msi_alloc( len * sizeof (WCHAR) );
466 r = GetTempFileNameW( tmp, prefix, 0, path );
477 static HANDLE msi_load_image( MSIDATABASE *db, LPCWSTR name, UINT type,
478 UINT cx, UINT cy, UINT flags )
480 MSIRECORD *rec = NULL;
481 HANDLE himage = NULL;
485 TRACE("%p %s %u %u %08x\n", db, debugstr_w(name), cx, cy, flags);
487 tmp = msi_create_tmp_path();
491 rec = msi_get_binary_record( db, name );
494 r = MSI_RecordStreamToFile( rec, 2, tmp );
495 if( r == ERROR_SUCCESS )
497 himage = LoadImageW( 0, tmp, type, cx, cy, flags );
500 msiobj_release( &rec->hdr );
507 static HICON msi_load_icon( MSIDATABASE *db, LPCWSTR text, UINT attributes )
509 DWORD cx = 0, cy = 0, flags;
511 flags = LR_LOADFROMFILE | LR_DEFAULTSIZE;
512 if( attributes & msidbControlAttributesFixedSize )
514 flags &= ~LR_DEFAULTSIZE;
515 if( attributes & msidbControlAttributesIconSize16 )
520 if( attributes & msidbControlAttributesIconSize32 )
525 /* msidbControlAttributesIconSize48 handled by above logic */
527 return msi_load_image( db, text, IMAGE_ICON, cx, cy, flags );
531 /* called from the Control Event subscription code */
532 void msi_dialog_handle_event( msi_dialog* dialog, LPCWSTR control,
533 LPCWSTR attribute, MSIRECORD *rec )
536 LPCWSTR font_text, text = NULL;
539 ctrl = msi_dialog_find_control( dialog, control );
542 if( !lstrcmpW(attribute, szText) )
544 font_text = MSI_RecordGetString( rec , 1 );
545 font = msi_dialog_get_style( font_text, &text );
546 SetWindowTextW( ctrl->hwnd, text );
548 msi_dialog_check_messages( NULL );
550 else if( !lstrcmpW(attribute, szProgress) )
554 func = MSI_RecordGetInteger( rec , 1 );
555 val = MSI_RecordGetInteger( rec , 2 );
560 ctrl->progress_max = val;
561 ctrl->progress_current = 0;
562 SendMessageW(ctrl->hwnd, PBM_SETRANGE, 0, MAKELPARAM(0,100));
563 SendMessageW(ctrl->hwnd, PBM_SETPOS, 0, 0);
565 case 1: /* FIXME: not sure what this is supposed to do */
568 ctrl->progress_current += val;
569 SendMessageW(ctrl->hwnd, PBM_SETPOS, 100*(ctrl->progress_current/ctrl->progress_max), 0);
572 ERR("Unknown progress message %ld\n", func);
578 FIXME("Attribute %s not being set\n", debugstr_w(attribute));
583 static void msi_dialog_map_events(msi_dialog* dialog, LPCWSTR control)
585 static const WCHAR Query[] = {
586 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
587 '`','E','v','e','n','t','M','a','p','p','i','n','g','`',' ',
588 'W','H','E','R','E',' ',
589 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',' ',
591 '`','C','o','n','t','r','o','l','_','`',' ','=',' ','\'','%','s','\'',0
594 LPCWSTR event, attribute;
596 row = MSI_QueryGetRecord( dialog->package->db, Query, dialog->name, control );
600 event = MSI_RecordGetString( row, 3 );
601 attribute = MSI_RecordGetString( row, 4 );
602 ControlEvent_SubscribeToEvent( dialog->package, event, control, attribute );
603 msiobj_release( &row->hdr );
606 /* everything except radio buttons */
607 static msi_control *msi_dialog_add_control( msi_dialog *dialog,
608 MSIRECORD *rec, LPCWSTR szCls, DWORD style )
614 name = MSI_RecordGetString( rec, 2 );
615 attributes = MSI_RecordGetInteger( rec, 8 );
616 text = MSI_RecordGetString( rec, 10 );
617 if( attributes & msidbControlAttributesVisible )
619 if( ~attributes & msidbControlAttributesEnabled )
620 style |= WS_DISABLED;
621 if( attributes & msidbControlAttributesSunken )
622 exstyle |= WS_EX_CLIENTEDGE;
624 msi_dialog_map_events(dialog, name);
626 return msi_dialog_create_window( dialog, rec, exstyle, szCls, name,
627 text, style, dialog->hwnd );
638 * we don't erase our own background,
639 * so we have to make sure that the parent window redraws first
641 static void msi_text_on_settext( HWND hWnd )
646 hParent = GetParent( hWnd );
647 GetWindowRect( hWnd, &rc );
648 MapWindowPoints( NULL, hParent, (LPPOINT) &rc, 2 );
649 InvalidateRect( hParent, &rc, TRUE );
652 static LRESULT WINAPI
653 MSIText_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
655 struct msi_text_info *info;
658 TRACE("%p %04x %08x %08lx\n", hWnd, msg, wParam, lParam);
660 info = GetPropW(hWnd, szButtonData);
663 SetTextColor( (HDC)wParam, info->font->color );
665 if( msg == WM_CTLCOLORSTATIC &&
666 ( info->attributes & msidbControlAttributesTransparent ) )
668 SetBkMode( (HDC)wParam, TRANSPARENT );
669 return (LRESULT) GetStockObject(NULL_BRUSH);
672 r = CallWindowProcW(info->oldproc, hWnd, msg, wParam, lParam);
677 msi_text_on_settext( hWnd );
681 RemovePropW( hWnd, szButtonData );
688 static UINT msi_dialog_text_control( msi_dialog *dialog, MSIRECORD *rec )
690 msi_control *control;
691 struct msi_text_info *info;
695 TRACE("%p %p\n", dialog, rec);
697 control = msi_dialog_add_control( dialog, rec, szStatic, SS_LEFT | WS_GROUP );
699 return ERROR_FUNCTION_FAILED;
701 info = msi_alloc( sizeof *info );
703 return ERROR_SUCCESS;
705 text = MSI_RecordGetString( rec, 10 );
706 font_name = msi_dialog_get_style( text, &ptr );
707 info->font = ( font_name ) ? msi_dialog_find_font( dialog, font_name ) : NULL;
708 msi_free( font_name );
710 info->attributes = MSI_RecordGetInteger( rec, 8 );
711 if( info->attributes & msidbControlAttributesTransparent )
712 SetWindowLongPtrW( control->hwnd, GWL_EXSTYLE, WS_EX_TRANSPARENT );
714 info->oldproc = (WNDPROC) SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
715 (LONG_PTR)MSIText_WndProc );
716 SetPropW( control->hwnd, szButtonData, info );
718 return ERROR_SUCCESS;
721 static UINT msi_dialog_button_control( msi_dialog *dialog, MSIRECORD *rec )
723 msi_control *control;
724 UINT attributes, style;
727 TRACE("%p %p\n", dialog, rec);
730 attributes = MSI_RecordGetInteger( rec, 8 );
731 if( attributes & msidbControlAttributesIcon )
734 control = msi_dialog_add_control( dialog, rec, szButton, style );
736 return ERROR_FUNCTION_FAILED;
738 control->handler = msi_dialog_button_handler;
741 text = msi_get_deformatted_field( dialog->package, rec, 10 );
742 control->hIcon = msi_load_icon( dialog->package->db, text, attributes );
743 if( attributes & msidbControlAttributesIcon )
744 SendMessageW( control->hwnd, BM_SETIMAGE, IMAGE_ICON, (LPARAM) control->hIcon );
747 return ERROR_SUCCESS;
750 static LPWSTR msi_get_checkbox_value( msi_dialog *dialog, LPCWSTR prop )
752 static const WCHAR query[] = {
753 'S','E','L','E','C','T',' ','*',' ',
754 'F','R','O','M',' ','`','C','h','e','c','k','B','o','x',' ','`',
755 'W','H','E','R','E',' ',
756 '`','P','r','o','p','e','r','t','y','`',' ','=',' ',
759 MSIRECORD *rec = NULL;
762 /* find if there is a value associated with the checkbox */
763 rec = MSI_QueryGetRecord( dialog->package->db, query, prop );
767 ret = msi_get_deformatted_field( dialog->package, rec, 2 );
773 msiobj_release( &rec->hdr );
777 ret = msi_dup_property( dialog->package, prop );
787 static UINT msi_dialog_checkbox_control( msi_dialog *dialog, MSIRECORD *rec )
789 msi_control *control;
792 TRACE("%p %p\n", dialog, rec);
794 control = msi_dialog_add_control( dialog, rec, szButton,
795 BS_CHECKBOX | BS_MULTILINE | WS_TABSTOP );
796 control->handler = msi_dialog_checkbox_handler;
797 prop = MSI_RecordGetString( rec, 9 );
800 control->property = strdupW( prop );
801 control->value = msi_get_checkbox_value( dialog, prop );
802 TRACE("control %s value %s\n", debugstr_w(control->property),
803 debugstr_w(control->value));
805 msi_dialog_checkbox_sync_state( dialog, control );
807 return ERROR_SUCCESS;
810 static UINT msi_dialog_line_control( msi_dialog *dialog, MSIRECORD *rec )
812 TRACE("%p %p\n", dialog, rec);
814 /* line is exactly 2 units in height */
815 MSI_RecordSetInteger( rec, 7, 2 );
817 msi_dialog_add_control( dialog, rec, szStatic, SS_ETCHEDHORZ | SS_SUNKEN );
818 return ERROR_SUCCESS;
821 /******************** Scroll Text ********************************************/
823 struct msi_scrolltext_info
826 msi_control *control;
830 static LRESULT WINAPI
831 MSIScrollText_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
833 struct msi_scrolltext_info *info;
836 TRACE("%p %04x %08x %08lx\n", hWnd, msg, wParam, lParam);
838 info = GetPropW( hWnd, szButtonData );
840 r = CallWindowProcW( info->oldproc, hWnd, msg, wParam, lParam );
846 RemovePropW( hWnd, szButtonData );
849 /* native MSI sets a wait cursor here */
850 msi_dialog_button_handler( info->dialog, info->control, BN_CLICKED );
856 struct msi_streamin_info
863 static DWORD CALLBACK
864 msi_richedit_stream_in( DWORD_PTR arg, LPBYTE buffer, LONG count, LONG *pcb )
866 struct msi_streamin_info *info = (struct msi_streamin_info*) arg;
868 if( (count + info->offset) > info->length )
869 count = info->length - info->offset;
870 memcpy( buffer, &info->string[ info->offset ], count );
872 info->offset += count;
874 TRACE("%ld/%ld\n", info->offset, info->length);
879 static void msi_scrolltext_add_text( msi_control *control, LPCWSTR text )
881 struct msi_streamin_info info;
884 info.string = strdupWtoA( text );
886 info.length = lstrlenA( info.string ) + 1;
888 es.dwCookie = (DWORD_PTR) &info;
890 es.pfnCallback = msi_richedit_stream_in;
892 SendMessageW( control->hwnd, EM_STREAMIN, SF_RTF, (LPARAM) &es );
894 msi_free( info.string );
897 static UINT msi_dialog_scrolltext_control( msi_dialog *dialog, MSIRECORD *rec )
899 static const WCHAR szRichEdit20W[] = {
900 'R','i','c','h','E','d','i','t','2','0','W',0
902 struct msi_scrolltext_info *info;
903 msi_control *control;
907 info = msi_alloc( sizeof *info );
909 return ERROR_FUNCTION_FAILED;
911 hRichedit = LoadLibraryA("riched20");
913 style = WS_BORDER | ES_MULTILINE | WS_VSCROLL |
914 ES_READONLY | ES_AUTOVSCROLL | WS_TABSTOP;
915 control = msi_dialog_add_control( dialog, rec, szRichEdit20W, style );
918 FreeLibrary( hRichedit );
920 return ERROR_FUNCTION_FAILED;
923 control->hDll = hRichedit;
925 info->dialog = dialog;
926 info->control = control;
928 /* subclass the static control */
929 info->oldproc = (WNDPROC) SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
930 (LONG_PTR)MSIScrollText_WndProc );
931 SetPropW( control->hwnd, szButtonData, info );
933 /* add the text into the richedit */
934 msi_scrolltext_add_text( control, MSI_RecordGetString( rec, 10 ) );
936 return ERROR_SUCCESS;
939 static HBITMAP msi_load_picture( MSIDATABASE *db, LPCWSTR name,
940 INT cx, INT cy, DWORD flags )
942 HBITMAP hOleBitmap = 0, hBitmap = 0, hOldSrcBitmap, hOldDestBitmap;
943 MSIRECORD *rec = NULL;
945 IPicture *pic = NULL;
950 rec = msi_get_binary_record( db, name );
954 r = MSI_RecordGetIStream( rec, 2, &stm );
955 msiobj_release( &rec->hdr );
956 if( r != ERROR_SUCCESS )
959 r = OleLoadPicture( stm, 0, TRUE, &IID_IPicture, (LPVOID*) &pic );
960 IStream_Release( stm );
963 ERR("failed to load picture\n");
967 r = IPicture_get_Handle( pic, (OLE_HANDLE*) &hOleBitmap );
970 ERR("failed to get bitmap handle\n");
974 /* make the bitmap the desired size */
975 r = GetObjectW( hOleBitmap, sizeof bm, &bm );
978 ERR("failed to get bitmap size\n");
982 if (flags & LR_DEFAULTSIZE)
988 srcdc = CreateCompatibleDC( NULL );
989 hOldSrcBitmap = SelectObject( srcdc, hOleBitmap );
990 destdc = CreateCompatibleDC( NULL );
991 hBitmap = CreateCompatibleBitmap( srcdc, cx, cy );
992 hOldDestBitmap = SelectObject( destdc, hBitmap );
993 StretchBlt( destdc, 0, 0, cx, cy,
994 srcdc, 0, 0, bm.bmWidth, bm.bmHeight, SRCCOPY);
995 SelectObject( srcdc, hOldSrcBitmap );
996 SelectObject( destdc, hOldDestBitmap );
1002 IPicture_Release( pic );
1006 static UINT msi_dialog_bitmap_control( msi_dialog *dialog, MSIRECORD *rec )
1008 UINT cx, cy, flags, style, attributes;
1009 msi_control *control;
1012 flags = LR_LOADFROMFILE;
1013 style = SS_BITMAP | SS_LEFT | WS_GROUP;
1015 attributes = MSI_RecordGetInteger( rec, 8 );
1016 if( attributes & msidbControlAttributesFixedSize )
1018 flags |= LR_DEFAULTSIZE;
1019 style |= SS_CENTERIMAGE;
1022 control = msi_dialog_add_control( dialog, rec, szStatic, style );
1023 cx = MSI_RecordGetInteger( rec, 6 );
1024 cy = MSI_RecordGetInteger( rec, 7 );
1025 cx = msi_dialog_scale_unit( dialog, cx );
1026 cy = msi_dialog_scale_unit( dialog, cy );
1028 text = msi_get_deformatted_field( dialog->package, rec, 10 );
1029 control->hBitmap = msi_load_picture( dialog->package->db, text, cx, cy, flags );
1030 if( control->hBitmap )
1031 SendMessageW( control->hwnd, STM_SETIMAGE,
1032 IMAGE_BITMAP, (LPARAM) control->hBitmap );
1034 ERR("Failed to load bitmap %s\n", debugstr_w(text));
1038 return ERROR_SUCCESS;
1041 static UINT msi_dialog_icon_control( msi_dialog *dialog, MSIRECORD *rec )
1043 msi_control *control;
1049 control = msi_dialog_add_control( dialog, rec, szStatic,
1050 SS_ICON | SS_CENTERIMAGE | WS_GROUP );
1052 attributes = MSI_RecordGetInteger( rec, 8 );
1053 text = msi_get_deformatted_field( dialog->package, rec, 10 );
1054 control->hIcon = msi_load_icon( dialog->package->db, text, attributes );
1055 if( control->hIcon )
1056 SendMessageW( control->hwnd, STM_SETICON, (WPARAM) control->hIcon, 0 );
1058 ERR("Failed to load bitmap %s\n", debugstr_w(text));
1060 return ERROR_SUCCESS;
1063 static UINT msi_dialog_combo_control( msi_dialog *dialog, MSIRECORD *rec )
1065 static const WCHAR szCombo[] = { 'C','O','M','B','O','B','O','X',0 };
1067 msi_dialog_add_control( dialog, rec, szCombo,
1068 SS_BITMAP | SS_LEFT | SS_CENTERIMAGE );
1069 return ERROR_SUCCESS;
1072 static UINT msi_dialog_edit_control( msi_dialog *dialog, MSIRECORD *rec )
1074 msi_control *control;
1078 control = msi_dialog_add_control( dialog, rec, szEdit,
1079 WS_BORDER | WS_TABSTOP );
1080 control->handler = msi_dialog_edit_handler;
1081 prop = MSI_RecordGetString( rec, 9 );
1083 control->property = strdupW( prop );
1084 val = msi_dup_property( dialog->package, control->property );
1085 SetWindowTextW( control->hwnd, val );
1087 return ERROR_SUCCESS;
1090 /******************** Masked Edit ********************************************/
1092 #define MASK_MAX_GROUPS 20
1094 struct msi_mask_group
1102 struct msi_maskedit_info
1110 struct msi_mask_group group[MASK_MAX_GROUPS];
1113 static BOOL msi_mask_editable( WCHAR type )
1128 static void msi_mask_control_change( struct msi_maskedit_info *info )
1133 val = msi_alloc( (info->num_chars+1)*sizeof(WCHAR) );
1134 for( i=0, n=0; i<info->num_groups; i++ )
1136 if( (info->group[i].len + n) > info->num_chars )
1138 ERR("can't fit control %d text into template\n",i);
1141 if (!msi_mask_editable(info->group[i].type))
1143 for(r=0; r<info->group[i].len; r++)
1144 val[n+r] = info->group[i].type;
1149 r = GetWindowTextW( info->group[i].hwnd, &val[n], info->group[i].len+1 );
1150 if( r != info->group[i].len )
1156 TRACE("%d/%d controls were good\n", i, info->num_groups);
1158 if( i == info->num_groups )
1160 TRACE("Set property %s to %s\n",
1161 debugstr_w(info->prop), debugstr_w(val) );
1162 CharUpperBuffW( val, info->num_chars );
1163 MSI_SetPropertyW( info->dialog->package, info->prop, val );
1164 msi_dialog_evaluate_control_conditions( info->dialog );
1169 /* now move to the next control if necessary */
1170 static VOID msi_mask_next_control( struct msi_maskedit_info *info, HWND hWnd )
1175 for( i=0; i<info->num_groups; i++ )
1176 if( info->group[i].hwnd == hWnd )
1179 /* don't move from the last control */
1180 if( i >= (info->num_groups-1) )
1183 len = SendMessageW( hWnd, WM_GETTEXTLENGTH, 0, 0 );
1184 if( len < info->group[i].len )
1187 hWndNext = GetNextDlgTabItem( GetParent( hWnd ), hWnd, FALSE );
1188 SetFocus( hWndNext );
1191 static LRESULT WINAPI
1192 MSIMaskedEdit_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
1194 struct msi_maskedit_info *info;
1197 TRACE("%p %04x %08x %08lx\n", hWnd, msg, wParam, lParam);
1199 info = GetPropW(hWnd, szButtonData);
1201 r = CallWindowProcW(info->oldproc, hWnd, msg, wParam, lParam);
1206 if (HIWORD(wParam) == EN_CHANGE)
1208 msi_mask_control_change( info );
1209 msi_mask_next_control( info, (HWND) lParam );
1213 msi_free( info->prop );
1215 RemovePropW( hWnd, szButtonData );
1222 /* fish the various bits of the property out and put them in the control */
1224 msi_maskedit_set_text( struct msi_maskedit_info *info, LPCWSTR text )
1230 for( i = 0; i < info->num_groups; i++ )
1232 if( info->group[i].len < lstrlenW( p ) )
1234 LPWSTR chunk = strdupW( p );
1235 chunk[ info->group[i].len ] = 0;
1236 SetWindowTextW( info->group[i].hwnd, chunk );
1241 SetWindowTextW( info->group[i].hwnd, p );
1244 p += info->group[i].len;
1248 static struct msi_maskedit_info * msi_dialog_parse_groups( LPCWSTR mask )
1250 struct msi_maskedit_info * info = NULL;
1251 int i = 0, n = 0, total = 0;
1254 TRACE("masked control, template %s\n", debugstr_w(mask));
1259 info = msi_alloc_zero( sizeof *info );
1263 p = strchrW(mask, '<');
1269 for( i=0; i<MASK_MAX_GROUPS; i++ )
1271 /* stop at the end of the string */
1272 if( p[0] == 0 || p[0] == '>' )
1275 /* count the number of the same identifier */
1276 for( n=0; p[n] == p[0]; n++ )
1278 info->group[i].ofs = total;
1279 info->group[i].type = p[0];
1283 total++; /* an extra not part of the group */
1285 info->group[i].len = n;
1290 TRACE("%d characters in %d groups\n", total, i );
1291 if( i == MASK_MAX_GROUPS )
1292 ERR("too many groups in PIDTemplate %s\n", debugstr_w(mask));
1294 info->num_chars = total;
1295 info->num_groups = i;
1301 msi_maskedit_create_children( struct msi_maskedit_info *info, LPCWSTR font )
1303 DWORD width, height, style, wx, ww;
1308 style = WS_CHILD | WS_BORDER | WS_VISIBLE | WS_TABSTOP | ES_AUTOHSCROLL;
1310 GetClientRect( info->hwnd, &rect );
1312 width = rect.right - rect.left;
1313 height = rect.bottom - rect.top;
1315 for( i = 0; i < info->num_groups; i++ )
1317 if (!msi_mask_editable( info->group[i].type ))
1319 wx = (info->group[i].ofs * width) / info->num_chars;
1320 ww = (info->group[i].len * width) / info->num_chars;
1322 hwnd = CreateWindowW( szEdit, NULL, style, wx, 0, ww, height,
1323 info->hwnd, NULL, NULL, NULL );
1326 ERR("failed to create mask edit sub window\n");
1330 SendMessageW( hwnd, EM_LIMITTEXT, info->group[i].len, 0 );
1332 msi_dialog_set_font( info->dialog, hwnd,
1333 font?font:info->dialog->default_font );
1334 info->group[i].hwnd = hwnd;
1339 * office 2003 uses "73931<````=````=````=````=`````>@@@@@"
1340 * delphi 7 uses "<????-??????-??????-????>" and "<???-???>"
1341 * filemaker pro 7 uses "<^^^^=^^^^=^^^^=^^^^=^^^^=^^^^=^^^^^>"
1343 static UINT msi_dialog_maskedit_control( msi_dialog *dialog, MSIRECORD *rec )
1345 LPWSTR font_mask, val = NULL, font;
1346 struct msi_maskedit_info *info = NULL;
1347 UINT ret = ERROR_SUCCESS;
1348 msi_control *control;
1353 font_mask = msi_get_deformatted_field( dialog->package, rec, 10 );
1354 font = msi_dialog_get_style( font_mask, &mask );
1357 ERR("mask template is empty\n");
1361 info = msi_dialog_parse_groups( mask );
1364 ERR("template %s is invalid\n", debugstr_w(mask));
1368 info->dialog = dialog;
1370 control = msi_dialog_add_control( dialog, rec, szStatic,
1371 SS_OWNERDRAW | WS_GROUP | WS_VISIBLE );
1374 ERR("Failed to create maskedit container\n");
1375 ret = ERROR_FUNCTION_FAILED;
1378 SetWindowLongPtrW( control->hwnd, GWL_EXSTYLE, WS_EX_CONTROLPARENT );
1380 info->hwnd = control->hwnd;
1382 /* subclass the static control */
1383 info->oldproc = (WNDPROC) SetWindowLongPtrW( info->hwnd, GWLP_WNDPROC,
1384 (LONG_PTR)MSIMaskedEdit_WndProc );
1385 SetPropW( control->hwnd, szButtonData, info );
1387 prop = MSI_RecordGetString( rec, 9 );
1389 info->prop = strdupW( prop );
1391 msi_maskedit_create_children( info, font );
1395 val = msi_dup_property( dialog->package, prop );
1398 msi_maskedit_set_text( info, val );
1404 if( ret != ERROR_SUCCESS )
1406 msi_free( font_mask );
1411 /******************** Progress Bar *****************************************/
1413 static UINT msi_dialog_progress_bar( msi_dialog *dialog, MSIRECORD *rec )
1415 msi_dialog_add_control( dialog, rec, PROGRESS_CLASSW, WS_VISIBLE );
1416 return ERROR_SUCCESS;
1419 /******************** Path Edit ********************************************/
1421 struct msi_pathedit_info
1424 msi_control *control;
1428 static LPWSTR msi_get_window_text( HWND hwnd )
1434 buf = msi_alloc( sz*sizeof(WCHAR) );
1437 r = GetWindowTextW( hwnd, buf, sz );
1441 buf = msi_realloc( buf, sz*sizeof(WCHAR) );
1447 static void msi_dialog_update_pathedit( msi_dialog *dialog, msi_control *control )
1452 if (!control && !(control = msi_dialog_find_control_by_type( dialog, szPathEdit )))
1455 indirect = control->attributes & msidbControlAttributesIndirect;
1456 prop = msi_dialog_dup_property( dialog, control->property, indirect );
1458 path = msi_dup_property( dialog->package, prop );
1459 SetWindowTextW( control->hwnd, path );
1460 SendMessageW( control->hwnd, EM_SETSEL, 0, -1 );
1466 /* FIXME: test when this should fail */
1467 static BOOL msi_dialog_verify_path( LPWSTR path )
1469 if ( !lstrlenW( path ) )
1472 if ( PathIsRelativeW( path ) )
1478 /* returns TRUE if the path is valid, FALSE otherwise */
1479 static BOOL msi_dialog_onkillfocus( msi_dialog *dialog, msi_control *control )
1485 indirect = control->attributes & msidbControlAttributesIndirect;
1486 prop = msi_dialog_dup_property( dialog, control->property, indirect );
1488 buf = msi_get_window_text( control->hwnd );
1490 if ( !msi_dialog_verify_path( buf ) )
1492 /* FIXME: display an error message box */
1493 ERR("Invalid path %s\n", debugstr_w( buf ));
1495 SetFocus( control->hwnd );
1500 MSI_SetPropertyW( dialog->package, prop, buf );
1503 msi_dialog_update_pathedit( dialog, control );
1505 TRACE("edit %s contents changed, set %s\n", debugstr_w(control->name),
1514 static LRESULT WINAPI MSIPathEdit_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
1516 struct msi_pathedit_info *info = GetPropW(hWnd, szButtonData);
1519 TRACE("%p %04x %08x %08lx\n", hWnd, msg, wParam, lParam);
1521 if ( msg == WM_KILLFOCUS )
1523 /* if the path is invalid, don't handle this message */
1524 if ( !msi_dialog_onkillfocus( info->dialog, info->control ) )
1528 r = CallWindowProcW(info->oldproc, hWnd, msg, wParam, lParam);
1530 if ( msg == WM_NCDESTROY )
1533 RemovePropW( hWnd, szButtonData );
1539 static UINT msi_dialog_pathedit_control( msi_dialog *dialog, MSIRECORD *rec )
1541 struct msi_pathedit_info *info;
1542 msi_control *control;
1545 info = msi_alloc( sizeof *info );
1547 return ERROR_FUNCTION_FAILED;
1549 control = msi_dialog_add_control( dialog, rec, szEdit,
1550 WS_BORDER | WS_TABSTOP );
1551 control->attributes = MSI_RecordGetInteger( rec, 8 );
1552 prop = MSI_RecordGetString( rec, 9 );
1553 control->property = msi_dialog_dup_property( dialog, prop, FALSE );
1555 info->dialog = dialog;
1556 info->control = control;
1557 info->oldproc = (WNDPROC) SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
1558 (LONG_PTR)MSIPathEdit_WndProc );
1559 SetPropW( control->hwnd, szButtonData, info );
1561 msi_dialog_update_pathedit( dialog, control );
1563 return ERROR_SUCCESS;
1566 /* radio buttons are a bit different from normal controls */
1567 static UINT msi_dialog_create_radiobutton( MSIRECORD *rec, LPVOID param )
1569 radio_button_group_descr *group = (radio_button_group_descr *)param;
1570 msi_dialog *dialog = group->dialog;
1571 msi_control *control;
1572 LPCWSTR prop, text, name;
1573 DWORD style, attributes = group->attributes;
1575 style = WS_CHILD | BS_AUTORADIOBUTTON | BS_MULTILINE | WS_TABSTOP;
1576 name = MSI_RecordGetString( rec, 3 );
1577 text = MSI_RecordGetString( rec, 8 );
1578 if( attributes & 1 )
1579 style |= WS_VISIBLE;
1580 if( ~attributes & 2 )
1581 style |= WS_DISABLED;
1583 control = msi_dialog_create_window( dialog, rec, 0, szButton, name, text,
1584 style, group->parent->hwnd );
1586 return ERROR_FUNCTION_FAILED;
1587 control->handler = msi_dialog_radiogroup_handler;
1589 if (!lstrcmpW(control->name, group->propval))
1590 SendMessageW(control->hwnd, BM_SETCHECK, BST_CHECKED, 0);
1592 prop = MSI_RecordGetString( rec, 1 );
1594 control->property = strdupW( prop );
1596 return ERROR_SUCCESS;
1599 static UINT msi_dialog_radiogroup_control( msi_dialog *dialog, MSIRECORD *rec )
1601 static const WCHAR query[] = {
1602 'S','E','L','E','C','T',' ','*',' ',
1603 'F','R','O','M',' ','R','a','d','i','o','B','u','t','t','o','n',' ',
1604 'W','H','E','R','E',' ',
1605 '`','P','r','o','p','e','r','t','y','`',' ','=',' ','\'','%','s','\'',0};
1608 msi_control *control;
1609 MSIQUERY *view = NULL;
1610 radio_button_group_descr group;
1611 MSIPACKAGE *package = dialog->package;
1614 prop = MSI_RecordGetString( rec, 9 );
1616 TRACE("%p %p %s\n", dialog, rec, debugstr_w( prop ));
1618 /* Create parent group box to hold radio buttons */
1619 control = msi_dialog_add_control( dialog, rec, szButton, BS_OWNERDRAW|WS_GROUP );
1621 return ERROR_FUNCTION_FAILED;
1623 oldproc = (WNDPROC) SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
1624 (LONG_PTR)MSIRadioGroup_WndProc );
1625 SetPropW(control->hwnd, szButtonData, oldproc);
1626 SetWindowLongPtrW( control->hwnd, GWL_EXSTYLE, WS_EX_CONTROLPARENT );
1629 control->property = strdupW( prop );
1631 /* query the Radio Button table for all control in this group */
1632 r = MSI_OpenQuery( package->db, &view, query, prop );
1633 if( r != ERROR_SUCCESS )
1635 ERR("query failed for dialog %s radio group %s\n",
1636 debugstr_w(dialog->name), debugstr_w(prop));
1637 return ERROR_INVALID_PARAMETER;
1640 group.dialog = dialog;
1641 group.parent = control;
1642 group.attributes = MSI_RecordGetInteger( rec, 8 );
1643 group.propval = msi_dup_property( dialog->package, control->property );
1645 r = MSI_IterateRecords( view, 0, msi_dialog_create_radiobutton, &group );
1646 msiobj_release( &view->hdr );
1647 msi_free( group.propval );
1652 /******************** Selection Tree ***************************************/
1654 struct msi_selection_tree_info
1662 msi_seltree_sync_item_state( HWND hwnd, MSIFEATURE *feature, HTREEITEM hItem )
1665 DWORD index = feature->Action;
1667 TRACE("Feature %s -> %d %d %d\n", debugstr_w(feature->Title),
1668 feature->Installed, feature->Action, feature->ActionRequest);
1670 if (index == INSTALLSTATE_UNKNOWN)
1671 index = INSTALLSTATE_ABSENT;
1673 tvi.mask = TVIF_STATE;
1675 tvi.state = INDEXTOSTATEIMAGEMASK( index );
1676 tvi.stateMask = TVIS_STATEIMAGEMASK;
1678 SendMessageW( hwnd, TVM_SETITEMW, 0, (LPARAM) &tvi );
1682 msi_seltree_popup_menu( HWND hwnd, INT x, INT y )
1687 /* create a menu to display */
1688 hMenu = CreatePopupMenu();
1690 /* FIXME: load strings from resources */
1691 AppendMenuA( hMenu, MF_ENABLED, INSTALLSTATE_LOCAL, "Install feature locally");
1692 AppendMenuA( hMenu, MF_GRAYED, 0x1000, "Install entire feature");
1693 AppendMenuA( hMenu, MF_ENABLED, INSTALLSTATE_ADVERTISED, "Install on demand");
1694 AppendMenuA( hMenu, MF_ENABLED, INSTALLSTATE_ABSENT, "Don't install");
1695 r = TrackPopupMenu( hMenu, TPM_LEFTALIGN | TPM_TOPALIGN | TPM_RETURNCMD,
1696 x, y, 0, hwnd, NULL );
1697 DestroyMenu( hMenu );
1702 msi_seltree_feature_from_item( HWND hwnd, HTREEITEM hItem )
1706 /* get the feature from the item */
1707 memset( &tvi, 0, sizeof tvi );
1709 tvi.mask = TVIF_PARAM | TVIF_HANDLE;
1710 SendMessageW( hwnd, TVM_GETITEMW, 0, (LPARAM) &tvi );
1712 return (MSIFEATURE*) tvi.lParam;
1716 msi_seltree_menu( HWND hwnd, HTREEITEM hItem )
1718 struct msi_selection_tree_info *info;
1719 MSIFEATURE *feature;
1720 MSIPACKAGE *package;
1728 info = GetPropW(hwnd, szButtonData);
1729 package = info->dialog->package;
1731 feature = msi_seltree_feature_from_item( hwnd, hItem );
1734 ERR("item %p feature was NULL\n", hItem);
1738 /* get the item's rectangle to put the menu just below it */
1740 SendMessageW( hwnd, TVM_GETITEMRECT, 0, (LPARAM) &u.rc );
1741 MapWindowPoints( hwnd, NULL, u.pt, 2 );
1743 r = msi_seltree_popup_menu( hwnd, u.rc.left, u.rc.top );
1747 case INSTALLSTATE_LOCAL:
1748 case INSTALLSTATE_ADVERTISED:
1749 case INSTALLSTATE_ABSENT:
1750 feature->ActionRequest = r;
1751 feature->Action = r;
1754 FIXME("select feature and all children\n");
1758 msi_seltree_sync_item_state( hwnd, feature, hItem );
1759 ACTION_UpdateComponentStates( package, feature->Feature );
1764 static LRESULT WINAPI
1765 MSISelectionTree_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
1767 struct msi_selection_tree_info *info;
1768 TVHITTESTINFO tvhti;
1771 TRACE("%p %04x %08x %08lx\n", hWnd, msg, wParam, lParam);
1773 info = GetPropW(hWnd, szButtonData);
1777 case WM_LBUTTONDOWN:
1778 tvhti.pt.x = LOWORD( lParam );
1779 tvhti.pt.y = HIWORD( lParam );
1782 r = CallWindowProcW(info->oldproc, hWnd, TVM_HITTEST, 0, (LPARAM) &tvhti );
1783 if (tvhti.flags & TVHT_ONITEMSTATEICON)
1784 return msi_seltree_menu( hWnd, tvhti.hItem );
1788 r = CallWindowProcW(info->oldproc, hWnd, msg, wParam, lParam);
1794 RemovePropW( hWnd, szButtonData );
1801 msi_seltree_add_child_features( MSIPACKAGE *package, HWND hwnd,
1802 LPCWSTR parent, HTREEITEM hParent )
1804 MSIFEATURE *feature;
1805 TVINSERTSTRUCTW tvis;
1808 LIST_FOR_EACH_ENTRY( feature, &package->features, MSIFEATURE, entry )
1810 if ( lstrcmpW( parent, feature->Feature_Parent ) )
1813 if ( !feature->Title )
1816 if ( !feature->Display )
1819 memset( &tvis, 0, sizeof tvis );
1820 tvis.hParent = hParent;
1821 tvis.hInsertAfter = TVI_LAST;
1822 tvis.u.item.mask = TVIF_TEXT | TVIF_PARAM;
1823 tvis.u.item.pszText = feature->Title;
1824 tvis.u.item.lParam = (LPARAM) feature;
1826 hitem = (HTREEITEM) SendMessageW( hwnd, TVM_INSERTITEMW, 0, (LPARAM) &tvis );
1830 msi_seltree_sync_item_state( hwnd, feature, hitem );
1831 msi_seltree_add_child_features( package, hwnd,
1832 feature->Feature, hitem );
1834 /* the node is expanded if Display is odd */
1835 if ( feature->Display % 2 != 0 )
1836 SendMessageW( hwnd, TVM_EXPAND, TVE_EXPAND, (LPARAM) hitem );
1840 static void msi_seltree_create_imagelist( HWND hwnd )
1842 const int bm_width = 32, bm_height = 16, bm_count = 3;
1843 const int bm_resource = 0x1001;
1848 himl = ImageList_Create( bm_width, bm_height, FALSE, 4, 0 );
1851 ERR("failed to create image list\n");
1855 for (i=0; i<bm_count; i++)
1857 hbmp = LoadBitmapW( msi_hInstance, MAKEINTRESOURCEW(i+bm_resource) );
1860 ERR("failed to load bitmap %d\n", i);
1865 * Add a dummy bitmap at offset zero because the treeview
1866 * can't use it as a state mask (zero means no user state).
1869 ImageList_Add( himl, hbmp, NULL );
1871 ImageList_Add( himl, hbmp, NULL );
1874 SendMessageW( hwnd, TVM_SETIMAGELIST, TVSIL_STATE, (LPARAM)himl );
1877 static UINT msi_dialog_selection_tree( msi_dialog *dialog, MSIRECORD *rec )
1879 msi_control *control;
1881 MSIPACKAGE *package = dialog->package;
1883 struct msi_selection_tree_info *info;
1885 info = msi_alloc( sizeof *info );
1887 return ERROR_FUNCTION_FAILED;
1889 /* create the treeview control */
1890 prop = MSI_RecordGetString( rec, 9 );
1891 style = TVS_HASLINES | TVS_HASBUTTONS | TVS_LINESATROOT;
1892 style |= WS_GROUP | WS_VSCROLL;
1893 control = msi_dialog_add_control( dialog, rec, WC_TREEVIEWW, style );
1897 return ERROR_FUNCTION_FAILED;
1901 info->dialog = dialog;
1902 info->hwnd = control->hwnd;
1903 info->oldproc = (WNDPROC) SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
1904 (LONG_PTR)MSISelectionTree_WndProc );
1905 SetPropW( control->hwnd, szButtonData, info );
1908 msi_seltree_create_imagelist( control->hwnd );
1909 msi_seltree_add_child_features( package, control->hwnd, NULL, NULL );
1911 return ERROR_SUCCESS;
1914 /******************** Group Box ***************************************/
1916 static UINT msi_dialog_group_box( msi_dialog *dialog, MSIRECORD *rec )
1918 msi_control *control;
1921 style = BS_GROUPBOX | WS_CHILD | WS_GROUP;
1922 control = msi_dialog_add_control( dialog, rec, WC_BUTTONW, style );
1924 return ERROR_FUNCTION_FAILED;
1926 return ERROR_SUCCESS;
1929 /******************** List Box ***************************************/
1931 struct msi_listbox_item
1937 struct msi_listbox_info
1943 struct msi_listbox_item *items;
1946 static LRESULT WINAPI MSIListBox_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
1948 struct msi_listbox_info *info;
1952 TRACE("%p %04x %08x %08lx\n", hWnd, msg, wParam, lParam);
1954 info = GetPropW( hWnd, szButtonData );
1958 r = CallWindowProcW( info->oldproc, hWnd, msg, wParam, lParam );
1963 for (j = 0; j < info->num_items; j++)
1965 msi_free( info->items[j].property );
1966 msi_free( info->items[j].value );
1968 msi_free( info->items );
1970 RemovePropW( hWnd, szButtonData );
1977 static UINT msi_listbox_add_item( MSIRECORD *rec, LPVOID param )
1979 struct msi_listbox_info *info = param;
1980 struct msi_listbox_item *item;
1981 LPCWSTR property, value, text;
1982 static int index = 0;
1984 item = &info->items[index++];
1985 property = MSI_RecordGetString( rec, 1 );
1986 value = MSI_RecordGetString( rec, 3 );
1987 text = MSI_RecordGetString( rec, 4 );
1989 item->property = strdupW( property );
1990 item->value = strdupW( value );
1992 SendMessageW( info->hwnd, LB_ADDSTRING, 0, (LPARAM)text );
1994 return ERROR_SUCCESS;
1997 static UINT msi_listbox_add_items( struct msi_listbox_info *info )
2000 MSIQUERY *view = NULL;
2003 static const WCHAR query[] = {
2004 'S','E','L','E','C','T',' ','*',' ',
2005 'F','R','O','M',' ','`','L','i','s','t','B','o','x','`',' ',
2006 'O','R','D','E','R',' ','B','Y',' ','`','O','r','d','e','r','`',0
2009 r = MSI_OpenQuery( info->dialog->package->db, &view, query );
2010 if ( r != ERROR_SUCCESS )
2013 /* just get the number of records */
2014 r = MSI_IterateRecords( view, &count, NULL, NULL );
2016 info->num_items = count;
2017 info->items = msi_alloc( sizeof(*info->items) * count );
2019 r = MSI_IterateRecords( view, NULL, msi_listbox_add_item, info );
2020 msiobj_release( &view->hdr );
2025 static UINT msi_dialog_listbox_handler( msi_dialog *dialog,
2026 msi_control *control, WPARAM param )
2028 struct msi_listbox_info *info;
2031 if( HIWORD(param) != LBN_SELCHANGE )
2032 return ERROR_SUCCESS;
2034 info = GetPropW( control->hwnd, szButtonData );
2035 index = SendMessageW( control->hwnd, LB_GETCURSEL, 0, 0 );
2037 MSI_SetPropertyW( info->dialog->package,
2038 info->items[index].property, info->items[index].value );
2039 msi_dialog_evaluate_control_conditions( info->dialog );
2041 return ERROR_SUCCESS;
2044 static UINT msi_dialog_list_box( msi_dialog *dialog, MSIRECORD *rec )
2046 struct msi_listbox_info *info;
2047 msi_control *control;
2050 info = msi_alloc( sizeof *info );
2052 return ERROR_FUNCTION_FAILED;
2054 style = WS_TABSTOP | WS_GROUP | WS_CHILD | LBS_STANDARD;
2055 control = msi_dialog_add_control( dialog, rec, WC_LISTBOXW, style );
2057 return ERROR_FUNCTION_FAILED;
2059 control->handler = msi_dialog_listbox_handler;
2062 info->dialog = dialog;
2063 info->hwnd = control->hwnd;
2065 info->oldproc = (WNDPROC)SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
2066 (LONG_PTR)MSIListBox_WndProc );
2067 SetPropW( control->hwnd, szButtonData, info );
2069 msi_listbox_add_items( info );
2071 return ERROR_SUCCESS;
2074 /******************** Directory Combo ***************************************/
2076 static void msi_dialog_update_directory_combo( msi_dialog *dialog, msi_control *control )
2081 if (!control && !(control = msi_dialog_find_control_by_type( dialog, szDirectoryCombo )))
2084 indirect = control->attributes & msidbControlAttributesIndirect;
2085 prop = msi_dialog_dup_property( dialog, control->property, indirect );
2086 path = msi_dup_property( dialog->package, prop );
2088 PathStripPathW( path );
2089 PathRemoveBackslashW( path );
2091 SendMessageW( control->hwnd, CB_INSERTSTRING, 0, (LPARAM)path );
2092 SendMessageW( control->hwnd, CB_SETCURSEL, 0, 0 );
2098 static UINT msi_dialog_directory_combo( msi_dialog *dialog, MSIRECORD *rec )
2100 msi_control *control;
2104 /* FIXME: use CBS_OWNERDRAWFIXED and add owner draw code */
2105 style = CBS_DROPDOWNLIST | CBS_HASSTRINGS | WS_CHILD |
2106 WS_GROUP | WS_TABSTOP | WS_VSCROLL;
2107 control = msi_dialog_add_control( dialog, rec, WC_COMBOBOXW, style );
2109 return ERROR_FUNCTION_FAILED;
2111 control->attributes = MSI_RecordGetInteger( rec, 8 );
2112 prop = MSI_RecordGetString( rec, 9 );
2113 control->property = msi_dialog_dup_property( dialog, prop, FALSE );
2115 msi_dialog_update_directory_combo( dialog, control );
2117 return ERROR_SUCCESS;
2120 /******************** Directory List ***************************************/
2122 static void msi_dialog_update_directory_list( msi_dialog *dialog, msi_control *control )
2124 WCHAR dir_spec[MAX_PATH];
2125 WIN32_FIND_DATAW wfd;
2131 static const WCHAR asterisk[] = {'*',0};
2132 static const WCHAR dot[] = {'.',0};
2133 static const WCHAR dotdot[] = {'.','.',0};
2135 if (!control && !(control = msi_dialog_find_control_by_type( dialog, szDirectoryList )))
2138 /* clear the list-view */
2139 SendMessageW( control->hwnd, LVM_DELETEALLITEMS, 0, 0 );
2141 indirect = control->attributes & msidbControlAttributesIndirect;
2142 prop = msi_dialog_dup_property( dialog, control->property, indirect );
2143 path = msi_dup_property( dialog->package, prop );
2145 lstrcpyW( dir_spec, path );
2146 lstrcatW( dir_spec, asterisk );
2148 file = FindFirstFileW( dir_spec, &wfd );
2149 if ( file == INVALID_HANDLE_VALUE )
2154 if ( wfd.dwFileAttributes != FILE_ATTRIBUTE_DIRECTORY )
2157 if ( !lstrcmpW( wfd.cFileName, dot ) || !lstrcmpW( wfd.cFileName, dotdot ) )
2160 item.mask = LVIF_TEXT;
2161 item.cchTextMax = MAX_PATH;
2164 item.pszText = wfd.cFileName;
2166 SendMessageW( control->hwnd, LVM_INSERTITEMW, 0, (LPARAM)&item );
2167 } while ( FindNextFileW( file, &wfd ) );
2174 UINT msi_dialog_directorylist_up( msi_dialog *dialog )
2176 msi_control *control;
2177 LPWSTR prop, path, ptr;
2180 control = msi_dialog_find_control_by_type( dialog, szDirectoryList );
2181 indirect = control->attributes & msidbControlAttributesIndirect;
2182 prop = msi_dialog_dup_property( dialog, control->property, indirect );
2184 path = msi_dup_property( dialog->package, prop );
2186 /* strip off the last directory */
2187 ptr = PathFindFileNameW( path );
2188 if (ptr != path) *(ptr - 1) = '\0';
2189 PathAddBackslashW( path );
2191 MSI_SetPropertyW( dialog->package, prop, path );
2193 msi_dialog_update_directory_list( dialog, NULL );
2194 msi_dialog_update_directory_combo( dialog, NULL );
2195 msi_dialog_update_pathedit( dialog, NULL );
2200 return ERROR_SUCCESS;
2203 static UINT msi_dialog_dirlist_handler( msi_dialog *dialog,
2204 msi_control *control, WPARAM param )
2206 LPNMHDR nmhdr = (LPNMHDR)param;
2207 WCHAR new_path[MAX_PATH];
2208 WCHAR text[MAX_PATH];
2214 static const WCHAR backslash[] = {'\\',0};
2216 if (nmhdr->code != LVN_ITEMACTIVATE)
2217 return ERROR_SUCCESS;
2219 index = SendMessageW( control->hwnd, LVM_GETNEXTITEM, -1, LVNI_SELECTED );
2222 ERR("No list-view item selected!\n");
2223 return ERROR_FUNCTION_FAILED;
2227 item.pszText = text;
2228 item.cchTextMax = MAX_PATH;
2229 SendMessageW( control->hwnd, LVM_GETITEMTEXTW, index, (LPARAM)&item );
2231 indirect = control->attributes & msidbControlAttributesIndirect;
2232 prop = msi_dialog_dup_property( dialog, control->property, indirect );
2233 path = msi_dup_property( dialog->package, prop );
2235 lstrcpyW( new_path, path );
2236 lstrcatW( new_path, text );
2237 lstrcatW( new_path, backslash );
2239 MSI_SetPropertyW( dialog->package, prop, new_path );
2241 msi_dialog_update_directory_list( dialog, NULL );
2242 msi_dialog_update_directory_combo( dialog, NULL );
2243 msi_dialog_update_pathedit( dialog, NULL );
2247 return ERROR_SUCCESS;
2250 static UINT msi_dialog_directory_list( msi_dialog *dialog, MSIRECORD *rec )
2252 msi_control *control;
2256 style = LVS_LIST | WS_VSCROLL | LVS_SHAREIMAGELISTS |
2257 LVS_AUTOARRANGE | LVS_SINGLESEL | WS_BORDER |
2258 LVS_SORTASCENDING | WS_CHILD | WS_GROUP | WS_TABSTOP;
2259 control = msi_dialog_add_control( dialog, rec, WC_LISTVIEWW, style );
2261 return ERROR_FUNCTION_FAILED;
2263 control->attributes = MSI_RecordGetInteger( rec, 8 );
2264 control->handler = msi_dialog_dirlist_handler;
2265 prop = MSI_RecordGetString( rec, 9 );
2266 control->property = msi_dialog_dup_property( dialog, prop, FALSE );
2268 /* double click to activate an item in the list */
2269 SendMessageW( control->hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE,
2270 0, LVS_EX_TWOCLICKACTIVATE );
2272 msi_dialog_update_directory_list( dialog, control );
2274 return ERROR_SUCCESS;
2277 /******************** VolumeCost List ***************************************/
2279 static BOOL str_is_number( LPCWSTR str )
2283 for (i = 0; i < lstrlenW( str ); i++)
2284 if (!isdigitW(str[i]))
2290 WCHAR column_keys[][80] =
2292 {'V','o','l','u','m','e','C','o','s','t','V','o','l','u','m','e',0},
2293 {'V','o','l','u','m','e','C','o','s','t','S','i','z','e',0},
2294 {'V','o','l','u','m','e','C','o','s','t','A','v','a','i','l','a','b','l','e',0},
2295 {'V','o','l','u','m','e','C','o','s','t','R','e','q','u','i','r','e','d',0},
2296 {'V','o','l','u','m','e','C','o','s','t','D','i','f','f','e','r','e','n','c','e',0}
2299 static void msi_dialog_vcl_add_columns( msi_dialog *dialog, msi_control *control, MSIRECORD *rec )
2301 LPCWSTR text = MSI_RecordGetString( rec, 10 );
2302 LPCWSTR begin = text, end;
2307 static const WCHAR zero[] = {'0',0};
2308 static const WCHAR negative[] = {'-',0};
2310 while ((begin = strchrW( begin, '{' )) && count < 5)
2312 if (!(end = strchrW( begin, '}' )))
2315 lstrcpynW( num, begin + 1, end - begin );
2316 begin += end - begin + 1;
2318 /* empty braces or '0' hides the column */
2319 if ( !num[0] || !lstrcmpW( num, zero ) )
2325 /* the width must be a positive number
2326 * if a width is invalid, all remaining columns are hidden
2328 if ( !strncmpW( num, negative, 1 ) || !str_is_number( num ) )
2331 ZeroMemory( &lvc, sizeof(lvc) );
2332 lvc.mask = LVCF_TEXT | LVCF_WIDTH | LVCF_SUBITEM;
2333 lvc.cx = atolW( num );
2334 lvc.pszText = msi_dialog_get_uitext( dialog, column_keys[count] );
2336 SendMessageW( control->hwnd, LVM_INSERTCOLUMNW, count++, (LPARAM)&lvc );
2337 msi_free( lvc.pszText );
2341 static void msi_dialog_vcl_add_drives( msi_dialog *dialog, msi_control *control )
2343 ULARGE_INTEGER total, free;
2344 WCHAR size_text[MAX_PATH];
2350 size = GetLogicalDriveStringsW( 0, NULL );
2351 if ( !size ) return;
2353 drives = msi_alloc( (size + 1) * sizeof(WCHAR) );
2354 if ( !drives ) return;
2356 GetLogicalDriveStringsW( size, drives );
2361 lvitem.mask = LVIF_TEXT;
2363 lvitem.iSubItem = 0;
2364 lvitem.pszText = ptr;
2365 lvitem.cchTextMax = lstrlenW(ptr) + 1;
2366 SendMessageW( control->hwnd, LVM_INSERTITEMW, 0, (LPARAM)&lvitem );
2368 GetDiskFreeSpaceExW(ptr, &free, &total, NULL);
2370 StrFormatByteSizeW(total.QuadPart, size_text, MAX_PATH);
2371 lvitem.iSubItem = 1;
2372 lvitem.pszText = size_text;
2373 lvitem.cchTextMax = lstrlenW(size_text) + 1;
2374 SendMessageW( control->hwnd, LVM_SETITEMW, 0, (LPARAM)&lvitem );
2376 StrFormatByteSizeW(free.QuadPart, size_text, MAX_PATH);
2377 lvitem.iSubItem = 2;
2378 lvitem.pszText = size_text;
2379 lvitem.cchTextMax = lstrlenW(size_text) + 1;
2380 SendMessageW( control->hwnd, LVM_SETITEMW, 0, (LPARAM)&lvitem );
2382 ptr += lstrlenW(ptr) + 1;
2389 static UINT msi_dialog_volumecost_list( msi_dialog *dialog, MSIRECORD *rec )
2391 msi_control *control;
2394 style = LVS_REPORT | WS_VSCROLL | WS_HSCROLL | LVS_SHAREIMAGELISTS |
2395 LVS_AUTOARRANGE | LVS_SINGLESEL | WS_BORDER |
2396 WS_CHILD | WS_TABSTOP | WS_GROUP;
2397 control = msi_dialog_add_control( dialog, rec, WC_LISTVIEWW, style );
2399 return ERROR_FUNCTION_FAILED;
2401 msi_dialog_vcl_add_columns( dialog, control, rec );
2402 msi_dialog_vcl_add_drives( dialog, control );
2404 return ERROR_SUCCESS;
2407 static const struct control_handler msi_dialog_handler[] =
2409 { szText, msi_dialog_text_control },
2410 { szPushButton, msi_dialog_button_control },
2411 { szLine, msi_dialog_line_control },
2412 { szBitmap, msi_dialog_bitmap_control },
2413 { szCheckBox, msi_dialog_checkbox_control },
2414 { szScrollableText, msi_dialog_scrolltext_control },
2415 { szComboBox, msi_dialog_combo_control },
2416 { szEdit, msi_dialog_edit_control },
2417 { szMaskedEdit, msi_dialog_maskedit_control },
2418 { szPathEdit, msi_dialog_pathedit_control },
2419 { szProgressBar, msi_dialog_progress_bar },
2420 { szRadioButtonGroup, msi_dialog_radiogroup_control },
2421 { szIcon, msi_dialog_icon_control },
2422 { szSelectionTree, msi_dialog_selection_tree },
2423 { szGroupBox, msi_dialog_group_box },
2424 { szListBox, msi_dialog_list_box },
2425 { szDirectoryCombo, msi_dialog_directory_combo },
2426 { szDirectoryList, msi_dialog_directory_list },
2427 { szVolumeCostList, msi_dialog_volumecost_list },
2430 #define NUM_CONTROL_TYPES (sizeof msi_dialog_handler/sizeof msi_dialog_handler[0])
2432 static UINT msi_dialog_create_controls( MSIRECORD *rec, LPVOID param )
2434 msi_dialog *dialog = param;
2435 LPCWSTR control_type;
2438 /* find and call the function that can create this type of control */
2439 control_type = MSI_RecordGetString( rec, 3 );
2440 for( i=0; i<NUM_CONTROL_TYPES; i++ )
2441 if (!strcmpiW( msi_dialog_handler[i].control_type, control_type ))
2443 if( i != NUM_CONTROL_TYPES )
2444 msi_dialog_handler[i].func( dialog, rec );
2446 ERR("no handler for element type %s\n", debugstr_w(control_type));
2448 return ERROR_SUCCESS;
2451 static UINT msi_dialog_fill_controls( msi_dialog *dialog )
2453 static const WCHAR query[] = {
2454 'S','E','L','E','C','T',' ','*',' ',
2455 'F','R','O','M',' ','C','o','n','t','r','o','l',' ',
2456 'W','H','E','R','E',' ',
2457 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',0};
2459 MSIQUERY *view = NULL;
2460 MSIPACKAGE *package = dialog->package;
2462 TRACE("%p %s\n", dialog, debugstr_w(dialog->name) );
2464 /* query the Control table for all the elements of the control */
2465 r = MSI_OpenQuery( package->db, &view, query, dialog->name );
2466 if( r != ERROR_SUCCESS )
2468 ERR("query failed for dialog %s\n", debugstr_w(dialog->name));
2469 return ERROR_INVALID_PARAMETER;
2472 r = MSI_IterateRecords( view, 0, msi_dialog_create_controls, dialog );
2473 msiobj_release( &view->hdr );
2478 static UINT msi_dialog_set_control_condition( MSIRECORD *rec, LPVOID param )
2480 static const WCHAR szHide[] = { 'H','i','d','e',0 };
2481 static const WCHAR szShow[] = { 'S','h','o','w',0 };
2482 static const WCHAR szDisable[] = { 'D','i','s','a','b','l','e',0 };
2483 static const WCHAR szEnable[] = { 'E','n','a','b','l','e',0 };
2484 msi_dialog *dialog = param;
2485 msi_control *control;
2486 LPCWSTR name, action, condition;
2489 name = MSI_RecordGetString( rec, 2 );
2490 action = MSI_RecordGetString( rec, 3 );
2491 condition = MSI_RecordGetString( rec, 4 );
2492 r = MSI_EvaluateConditionW( dialog->package, condition );
2493 control = msi_dialog_find_control( dialog, name );
2494 if( r == MSICONDITION_TRUE && control )
2496 TRACE("%s control %s\n", debugstr_w(action), debugstr_w(name));
2498 /* FIXME: case sensitive? */
2499 if(!lstrcmpW(action, szHide))
2500 ShowWindow(control->hwnd, SW_HIDE);
2501 else if(!strcmpW(action, szShow))
2502 ShowWindow(control->hwnd, SW_SHOW);
2503 else if(!strcmpW(action, szDisable))
2504 EnableWindow(control->hwnd, FALSE);
2505 else if(!strcmpW(action, szEnable))
2506 EnableWindow(control->hwnd, TRUE);
2508 FIXME("Unhandled action %s\n", debugstr_w(action));
2511 return ERROR_SUCCESS;
2514 static UINT msi_dialog_evaluate_control_conditions( msi_dialog *dialog )
2516 static const WCHAR query[] = {
2517 'S','E','L','E','C','T',' ','*',' ',
2518 'F','R','O','M',' ',
2519 'C','o','n','t','r','o','l','C','o','n','d','i','t','i','o','n',' ',
2520 'W','H','E','R','E',' ',
2521 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',0
2524 MSIQUERY *view = NULL;
2525 MSIPACKAGE *package = dialog->package;
2527 TRACE("%p %s\n", dialog, debugstr_w(dialog->name) );
2529 /* query the Control table for all the elements of the control */
2530 r = MSI_OpenQuery( package->db, &view, query, dialog->name );
2531 if( r != ERROR_SUCCESS )
2533 ERR("query failed for dialog %s\n", debugstr_w(dialog->name));
2534 return ERROR_INVALID_PARAMETER;
2537 r = MSI_IterateRecords( view, 0, msi_dialog_set_control_condition, dialog );
2538 msiobj_release( &view->hdr );
2543 UINT msi_dialog_reset( msi_dialog *dialog )
2545 /* FIXME: should restore the original values of any properties we changed */
2546 return msi_dialog_evaluate_control_conditions( dialog );
2549 /* figure out the height of 10 point MS Sans Serif */
2550 static INT msi_dialog_get_sans_serif_height( HWND hwnd )
2552 static const WCHAR szSansSerif[] = {
2553 'M','S',' ','S','a','n','s',' ','S','e','r','i','f',0 };
2558 HFONT hFont, hOldFont;
2561 hdc = GetDC( hwnd );
2564 memset( &lf, 0, sizeof lf );
2565 lf.lfHeight = MulDiv(10, GetDeviceCaps(hdc, LOGPIXELSY), 72);
2566 strcpyW( lf.lfFaceName, szSansSerif );
2567 hFont = CreateFontIndirectW(&lf);
2570 hOldFont = SelectObject( hdc, hFont );
2571 r = GetTextMetricsW( hdc, &tm );
2573 height = tm.tmHeight;
2574 SelectObject( hdc, hOldFont );
2575 DeleteObject( hFont );
2577 ReleaseDC( hwnd, hdc );
2582 /* fetch the associated record from the Dialog table */
2583 static MSIRECORD *msi_get_dialog_record( msi_dialog *dialog )
2585 static const WCHAR query[] = {
2586 'S','E','L','E','C','T',' ','*',' ',
2587 'F','R','O','M',' ','D','i','a','l','o','g',' ',
2588 'W','H','E','R','E',' ',
2589 '`','D','i','a','l','o','g','`',' ','=',' ','\'','%','s','\'',0};
2590 MSIPACKAGE *package = dialog->package;
2591 MSIRECORD *rec = NULL;
2593 TRACE("%p %s\n", dialog, debugstr_w(dialog->name) );
2595 rec = MSI_QueryGetRecord( package->db, query, dialog->name );
2597 ERR("query failed for dialog %s\n", debugstr_w(dialog->name));
2602 static void msi_dialog_adjust_dialog_pos( msi_dialog *dialog, MSIRECORD *rec, LPRECT pos )
2604 static const WCHAR szScreenX[] = {'S','c','r','e','e','n','X',0};
2605 static const WCHAR szScreenY[] = {'S','c','r','e','e','n','Y',0};
2612 center.x = MSI_RecordGetInteger( rec, 2 );
2613 center.y = MSI_RecordGetInteger( rec, 3 );
2615 sz.cx = MSI_RecordGetInteger( rec, 4 );
2616 sz.cy = MSI_RecordGetInteger( rec, 5 );
2618 sz.cx = msi_dialog_scale_unit( dialog, sz.cx );
2619 sz.cy = msi_dialog_scale_unit( dialog, sz.cy );
2621 xres = msi_get_property_int( dialog->package, szScreenX, 0 );
2622 yres = msi_get_property_int( dialog->package, szScreenY, 0 );
2624 center.x = MulDiv( center.x, xres, 100 );
2625 center.y = MulDiv( center.y, yres, 100 );
2627 /* turn the client pos into the window rectangle */
2628 if (dialog->package->center_x && dialog->package->center_y)
2630 pos->left = dialog->package->center_x - sz.cx / 2.0;
2631 pos->right = pos->left + sz.cx;
2632 pos->top = dialog->package->center_y - sz.cy / 2.0;
2633 pos->bottom = pos->top + sz.cy;
2637 pos->left = center.x - sz.cx/2;
2638 pos->right = pos->left + sz.cx;
2639 pos->top = center.y - sz.cy/2;
2640 pos->bottom = pos->top + sz.cy;
2642 /* save the center */
2643 dialog->package->center_x = center.x;
2644 dialog->package->center_y = center.y;
2647 dialog->size.cx = sz.cx;
2648 dialog->size.cy = sz.cy;
2650 TRACE("%lu %lu %lu %lu\n", pos->left, pos->top, pos->right, pos->bottom);
2652 style = GetWindowLongPtrW( dialog->hwnd, GWL_STYLE );
2653 AdjustWindowRect( pos, style, FALSE );
2656 static BOOL msi_control_set_next( msi_control *control, msi_control *next )
2658 return SetWindowPos( next->hwnd, control->hwnd, 0, 0, 0, 0,
2659 SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOREDRAW |
2660 SWP_NOREPOSITION | SWP_NOSENDCHANGING | SWP_NOSIZE );
2663 static UINT msi_dialog_set_tab_order( msi_dialog *dialog )
2665 msi_control *control, *tab_next;
2667 LIST_FOR_EACH_ENTRY( control, &dialog->controls, msi_control, entry )
2669 tab_next = msi_dialog_find_control( dialog, control->tabnext );
2672 msi_control_set_next( control, tab_next );
2675 return ERROR_SUCCESS;
2678 static void msi_dialog_set_first_control( msi_dialog* dialog, LPCWSTR name )
2680 msi_control *control;
2682 control = msi_dialog_find_control( dialog, name );
2684 dialog->hWndFocus = control->hwnd;
2686 dialog->hWndFocus = NULL;
2689 static LRESULT msi_dialog_oncreate( HWND hwnd, LPCREATESTRUCTW cs )
2691 static const WCHAR df[] = {
2692 'D','e','f','a','u','l','t','U','I','F','o','n','t',0 };
2693 static const WCHAR dfv[] = {
2694 'M','S',' ','S','h','e','l','l',' ','D','l','g',0 };
2695 msi_dialog *dialog = (msi_dialog*) cs->lpCreateParams;
2696 MSIRECORD *rec = NULL;
2697 LPWSTR title = NULL;
2700 TRACE("%p %p\n", dialog, dialog->package);
2702 dialog->hwnd = hwnd;
2703 SetWindowLongPtrW( hwnd, GWLP_USERDATA, (LONG_PTR) dialog );
2705 rec = msi_get_dialog_record( dialog );
2708 TRACE("No record found for dialog %s\n", debugstr_w(dialog->name));
2712 dialog->scale = msi_dialog_get_sans_serif_height(dialog->hwnd);
2714 msi_dialog_adjust_dialog_pos( dialog, rec, &pos );
2716 dialog->attributes = MSI_RecordGetInteger( rec, 6 );
2718 dialog->default_font = msi_dup_property( dialog->package, df );
2719 if (!dialog->default_font)
2721 dialog->default_font = strdupW(dfv);
2722 if (!dialog->default_font) return -1;
2725 title = msi_get_deformatted_field( dialog->package, rec, 7 );
2726 SetWindowTextW( hwnd, title );
2729 SetWindowPos( hwnd, 0, pos.left, pos.top,
2730 pos.right - pos.left, pos.bottom - pos.top,
2731 SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOREDRAW );
2733 msi_dialog_build_font_list( dialog );
2734 msi_dialog_fill_controls( dialog );
2735 msi_dialog_evaluate_control_conditions( dialog );
2736 msi_dialog_set_tab_order( dialog );
2737 msi_dialog_set_first_control( dialog, MSI_RecordGetString( rec, 8 ) );
2738 msiobj_release( &rec->hdr );
2743 static UINT msi_dialog_send_event( msi_dialog *dialog, LPCWSTR event, LPCWSTR arg )
2745 LPWSTR event_fmt = NULL, arg_fmt = NULL;
2747 TRACE("Sending control event %s %s\n", debugstr_w(event), debugstr_w(arg));
2749 deformat_string( dialog->package, event, &event_fmt );
2750 deformat_string( dialog->package, arg, &arg_fmt );
2752 dialog->event_handler( dialog->package, event_fmt, arg_fmt, dialog );
2754 msi_free( event_fmt );
2755 msi_free( arg_fmt );
2757 return ERROR_SUCCESS;
2760 static UINT msi_dialog_set_property( msi_dialog *dialog, LPCWSTR event, LPCWSTR arg )
2762 static const WCHAR szNullArg[] = { '{','}',0 };
2763 LPWSTR p, prop, arg_fmt = NULL;
2766 len = strlenW(event);
2767 prop = msi_alloc( len*sizeof(WCHAR));
2768 strcpyW( prop, &event[1] );
2769 p = strchrW( prop, ']' );
2770 if( p && p[1] == 0 )
2773 if( strcmpW( szNullArg, arg ) )
2774 deformat_string( dialog->package, arg, &arg_fmt );
2775 MSI_SetPropertyW( dialog->package, prop, arg_fmt );
2776 msi_free( arg_fmt );
2779 ERR("Badly formatted property string - what happens?\n");
2781 return ERROR_SUCCESS;
2784 static UINT msi_dialog_control_event( MSIRECORD *rec, LPVOID param )
2786 msi_dialog *dialog = param;
2787 LPCWSTR condition, event, arg;
2790 condition = MSI_RecordGetString( rec, 5 );
2791 r = MSI_EvaluateConditionW( dialog->package, condition );
2792 if( r == MSICONDITION_TRUE || r == MSICONDITION_NONE )
2794 event = MSI_RecordGetString( rec, 3 );
2795 arg = MSI_RecordGetString( rec, 4 );
2796 if( event[0] == '[' )
2797 msi_dialog_set_property( dialog, event, arg );
2799 msi_dialog_send_event( dialog, event, arg );
2802 return ERROR_SUCCESS;
2805 static UINT msi_dialog_button_handler( msi_dialog *dialog,
2806 msi_control *control, WPARAM param )
2808 static const WCHAR query[] = {
2809 'S','E','L','E','C','T',' ','*',' ',
2810 'F','R','O','M',' ','C','o','n','t','r','o','l','E','v','e','n','t',' ',
2811 'W','H','E','R','E',' ',
2812 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',' ',
2814 '`','C','o','n','t','r','o','l','_','`',' ','=',' ','\'','%','s','\'',' ',
2815 'O','R','D','E','R',' ','B','Y',' ','`','O','r','d','e','r','i','n','g','`',0
2817 MSIQUERY *view = NULL;
2820 if( HIWORD(param) != BN_CLICKED )
2821 return ERROR_SUCCESS;
2823 r = MSI_OpenQuery( dialog->package->db, &view, query,
2824 dialog->name, control->name );
2825 if( r != ERROR_SUCCESS )
2827 ERR("query failed\n");
2831 r = MSI_IterateRecords( view, 0, msi_dialog_control_event, dialog );
2832 msiobj_release( &view->hdr );
2837 static UINT msi_dialog_get_checkbox_state( msi_dialog *dialog,
2838 msi_control *control )
2840 WCHAR state[2] = { 0 };
2843 MSI_GetPropertyW( dialog->package, control->property, state, &sz );
2844 return state[0] ? 1 : 0;
2847 static void msi_dialog_set_checkbox_state( msi_dialog *dialog,
2848 msi_control *control, UINT state )
2850 static const WCHAR szState[] = { '1', 0 };
2853 /* if uncheck then the property is set to NULL */
2856 MSI_SetPropertyW( dialog->package, control->property, NULL );
2860 /* check for a custom state */
2861 if (control->value && control->value[0])
2862 val = control->value;
2866 MSI_SetPropertyW( dialog->package, control->property, val );
2869 static void msi_dialog_checkbox_sync_state( msi_dialog *dialog,
2870 msi_control *control )
2874 state = msi_dialog_get_checkbox_state( dialog, control );
2875 SendMessageW( control->hwnd, BM_SETCHECK,
2876 state ? BST_CHECKED : BST_UNCHECKED, 0 );
2879 static UINT msi_dialog_checkbox_handler( msi_dialog *dialog,
2880 msi_control *control, WPARAM param )
2884 if( HIWORD(param) != BN_CLICKED )
2885 return ERROR_SUCCESS;
2887 TRACE("clicked checkbox %s, set %s\n", debugstr_w(control->name),
2888 debugstr_w(control->property));
2890 state = msi_dialog_get_checkbox_state( dialog, control );
2891 state = state ? 0 : 1;
2892 msi_dialog_set_checkbox_state( dialog, control, state );
2893 msi_dialog_checkbox_sync_state( dialog, control );
2895 return msi_dialog_button_handler( dialog, control, param );
2898 static UINT msi_dialog_edit_handler( msi_dialog *dialog,
2899 msi_control *control, WPARAM param )
2903 if( HIWORD(param) != EN_CHANGE )
2904 return ERROR_SUCCESS;
2906 TRACE("edit %s contents changed, set %s\n", debugstr_w(control->name),
2907 debugstr_w(control->property));
2909 buf = msi_get_window_text( control->hwnd );
2910 MSI_SetPropertyW( dialog->package, control->property, buf );
2914 return ERROR_SUCCESS;
2917 static UINT msi_dialog_radiogroup_handler( msi_dialog *dialog,
2918 msi_control *control, WPARAM param )
2920 if( HIWORD(param) != BN_CLICKED )
2921 return ERROR_SUCCESS;
2923 TRACE("clicked radio button %s, set %s\n", debugstr_w(control->name),
2924 debugstr_w(control->property));
2926 MSI_SetPropertyW( dialog->package, control->property, control->name );
2928 return msi_dialog_button_handler( dialog, control, param );
2931 static LRESULT msi_dialog_oncommand( msi_dialog *dialog, WPARAM param, HWND hwnd )
2933 msi_control *control = NULL;
2935 TRACE("%p %p %08x\n", dialog, hwnd, param);
2940 control = msi_dialog_find_control( dialog, dialog->control_default );
2942 case 2: /* escape */
2943 control = msi_dialog_find_control( dialog, dialog->control_cancel );
2946 control = msi_dialog_find_control_by_hwnd( dialog, hwnd );
2951 if( control->handler )
2953 control->handler( dialog, control, param );
2954 msi_dialog_evaluate_control_conditions( dialog );
2958 ERR("button click from nowhere %p %d %p\n", dialog, param, hwnd);
2962 static LRESULT msi_dialog_onnotify( msi_dialog *dialog, LPARAM param )
2964 LPNMHDR nmhdr = (LPNMHDR) param;
2965 msi_control *control = msi_dialog_find_control_by_hwnd( dialog, nmhdr->hwndFrom );
2967 TRACE("%p %p", dialog, nmhdr->hwndFrom);
2969 if ( control && control->handler )
2970 control->handler( dialog, control, param );
2975 static void msi_dialog_setfocus( msi_dialog *dialog )
2977 HWND hwnd = dialog->hWndFocus;
2979 hwnd = GetNextDlgTabItem( dialog->hwnd, hwnd, TRUE);
2980 hwnd = GetNextDlgTabItem( dialog->hwnd, hwnd, FALSE);
2982 dialog->hWndFocus = hwnd;
2985 static LRESULT WINAPI MSIDialog_WndProc( HWND hwnd, UINT msg,
2986 WPARAM wParam, LPARAM lParam )
2988 msi_dialog *dialog = (LPVOID) GetWindowLongPtrW( hwnd, GWLP_USERDATA );
2990 TRACE("0x%04x\n", msg);
2995 dialog->package->center_x = LOWORD(lParam) + dialog->size.cx / 2.0;
2996 dialog->package->center_y = HIWORD(lParam) + dialog->size.cy / 2.0;
3000 return msi_dialog_oncreate( hwnd, (LPCREATESTRUCTW)lParam );
3003 return msi_dialog_oncommand( dialog, wParam, (HWND)lParam );
3006 if( LOWORD(wParam) == WA_INACTIVE )
3007 dialog->hWndFocus = GetFocus();
3009 msi_dialog_setfocus( dialog );
3013 msi_dialog_setfocus( dialog );
3016 /* bounce back to our subclassed static control */
3017 case WM_CTLCOLORSTATIC:
3018 return SendMessageW( (HWND) lParam, WM_CTLCOLORSTATIC, wParam, lParam );
3021 dialog->hwnd = NULL;
3024 return msi_dialog_onnotify( dialog, lParam );
3026 return DefWindowProcW(hwnd, msg, wParam, lParam);
3029 static BOOL CALLBACK msi_radioground_child_enum( HWND hWnd, LPARAM lParam )
3031 EnableWindow( hWnd, lParam );
3035 static LRESULT WINAPI MSIRadioGroup_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
3037 WNDPROC oldproc = (WNDPROC) GetPropW(hWnd, szButtonData);
3040 TRACE("hWnd %p msg %04x wParam 0x%08x lParam 0x%08lx\n", hWnd, msg, wParam, lParam);
3042 if (msg == WM_COMMAND) /* Forward notifications to dialog */
3043 SendMessageW(GetParent(hWnd), msg, wParam, lParam);
3045 r = CallWindowProcW(oldproc, hWnd, msg, wParam, lParam);
3047 /* make sure the radio buttons show as disabled if the parent is disabled */
3048 if (msg == WM_ENABLE)
3049 EnumChildWindows( hWnd, msi_radioground_child_enum, wParam );
3054 static LRESULT WINAPI MSIHiddenWindowProc( HWND hwnd, UINT msg,
3055 WPARAM wParam, LPARAM lParam )
3057 msi_dialog *dialog = (msi_dialog*) lParam;
3059 TRACE("%d %p\n", msg, dialog);
3063 case WM_MSI_DIALOG_CREATE:
3064 return msi_dialog_run_message_loop( dialog );
3065 case WM_MSI_DIALOG_DESTROY:
3066 msi_dialog_destroy( dialog );
3069 return DefWindowProcW( hwnd, msg, wParam, lParam );
3072 /* functions that interface to other modules within MSI */
3074 msi_dialog *msi_dialog_create( MSIPACKAGE* package,
3075 LPCWSTR szDialogName, msi_dialog *parent,
3076 msi_dialog_event_handler event_handler )
3078 MSIRECORD *rec = NULL;
3081 TRACE("%p %s\n", package, debugstr_w(szDialogName));
3083 /* allocate the structure for the dialog to use */
3084 dialog = msi_alloc_zero( sizeof *dialog + sizeof(WCHAR)*strlenW(szDialogName) );
3087 strcpyW( dialog->name, szDialogName );
3088 dialog->parent = parent;
3089 msiobj_addref( &package->hdr );
3090 dialog->package = package;
3091 dialog->event_handler = event_handler;
3092 dialog->finished = 0;
3093 list_init( &dialog->controls );
3095 /* verify that the dialog exists */
3096 rec = msi_get_dialog_record( dialog );
3099 msiobj_release( &package->hdr );
3103 dialog->attributes = MSI_RecordGetInteger( rec, 6 );
3104 dialog->control_default = strdupW( MSI_RecordGetString( rec, 9 ) );
3105 dialog->control_cancel = strdupW( MSI_RecordGetString( rec, 10 ) );
3106 msiobj_release( &rec->hdr );
3111 static void msi_process_pending_messages( HWND hdlg )
3115 while( PeekMessageW( &msg, 0, 0, 0, PM_REMOVE ) )
3117 if( hdlg && IsDialogMessageW( hdlg, &msg ))
3119 TranslateMessage( &msg );
3120 DispatchMessageW( &msg );
3124 void msi_dialog_end_dialog( msi_dialog *dialog )
3126 TRACE("%p\n", dialog);
3127 dialog->finished = 1;
3128 PostMessageW(dialog->hwnd, WM_NULL, 0, 0);
3131 void msi_dialog_check_messages( HANDLE handle )
3135 /* in threads other than the UI thread, block */
3136 if( uiThreadId != GetCurrentThreadId() )
3139 WaitForSingleObject( handle, INFINITE );
3143 /* there's two choices for the UI thread */
3146 msi_process_pending_messages( NULL );
3152 * block here until somebody creates a new dialog or
3153 * the handle we're waiting on becomes ready
3155 r = MsgWaitForMultipleObjects( 1, &handle, 0, INFINITE, QS_ALLINPUT );
3156 if( r == WAIT_OBJECT_0 )
3161 UINT msi_dialog_run_message_loop( msi_dialog *dialog )
3166 if( uiThreadId != GetCurrentThreadId() )
3167 return SendMessageW( hMsiHiddenWindow, WM_MSI_DIALOG_CREATE, 0, (LPARAM) dialog );
3169 /* create the dialog window, don't show it yet */
3170 style = WS_OVERLAPPED;
3171 if( dialog->attributes & msidbDialogAttributesVisible )
3172 style |= WS_VISIBLE;
3174 hwnd = CreateWindowW( szMsiDialogClass, dialog->name, style,
3175 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
3176 NULL, NULL, NULL, dialog );
3179 ERR("Failed to create dialog %s\n", debugstr_w( dialog->name ));
3180 return ERROR_FUNCTION_FAILED;
3183 ShowWindow( hwnd, SW_SHOW );
3184 /* UpdateWindow( hwnd ); - and causes the transparent static controls not to paint */
3186 if( dialog->attributes & msidbDialogAttributesModal )
3188 while( !dialog->finished )
3190 MsgWaitForMultipleObjects( 0, NULL, 0, INFINITE, QS_ALLINPUT );
3191 msi_process_pending_messages( dialog->hwnd );
3195 return ERROR_IO_PENDING;
3197 return ERROR_SUCCESS;
3200 void msi_dialog_do_preview( msi_dialog *dialog )
3203 dialog->attributes |= msidbDialogAttributesVisible;
3204 dialog->attributes &= ~msidbDialogAttributesModal;
3205 msi_dialog_run_message_loop( dialog );
3208 void msi_dialog_destroy( msi_dialog *dialog )
3210 if( uiThreadId != GetCurrentThreadId() )
3212 SendMessageW( hMsiHiddenWindow, WM_MSI_DIALOG_DESTROY, 0, (LPARAM) dialog );
3217 ShowWindow( dialog->hwnd, SW_HIDE );
3220 DestroyWindow( dialog->hwnd );
3222 /* destroy the list of controls */
3223 while( !list_empty( &dialog->controls ) )
3225 msi_control *t = LIST_ENTRY( list_head( &dialog->controls ),
3226 msi_control, entry );
3227 list_remove( &t->entry );
3228 /* leave dialog->hwnd - destroying parent destroys child windows */
3229 msi_free( t->property );
3230 msi_free( t->value );
3232 DeleteObject( t->hBitmap );
3234 DestroyIcon( t->hIcon );
3235 msi_free( t->tabnext );
3236 msi_free( t->type );
3239 FreeLibrary( t->hDll );
3242 /* destroy the list of fonts */
3243 while( dialog->font_list )
3245 msi_font *t = dialog->font_list;
3246 dialog->font_list = t->next;
3247 DeleteObject( t->hfont );
3250 msi_free( dialog->default_font );
3252 msi_free( dialog->control_default );
3253 msi_free( dialog->control_cancel );
3254 msiobj_release( &dialog->package->hdr );
3255 dialog->package = NULL;
3259 BOOL msi_dialog_register_class( void )
3263 ZeroMemory( &cls, sizeof cls );
3264 cls.lpfnWndProc = MSIDialog_WndProc;
3265 cls.hInstance = NULL;
3266 cls.hIcon = LoadIconW(0, (LPWSTR)IDI_APPLICATION);
3267 cls.hCursor = LoadCursorW(0, (LPWSTR)IDC_ARROW);
3268 cls.hbrBackground = (HBRUSH)(COLOR_3DFACE + 1);
3269 cls.lpszMenuName = NULL;
3270 cls.lpszClassName = szMsiDialogClass;
3272 if( !RegisterClassW( &cls ) )
3275 cls.lpfnWndProc = MSIHiddenWindowProc;
3276 cls.lpszClassName = szMsiHiddenWindow;
3278 if( !RegisterClassW( &cls ) )
3281 uiThreadId = GetCurrentThreadId();
3283 hMsiHiddenWindow = CreateWindowW( szMsiHiddenWindow, NULL, WS_OVERLAPPED,
3284 0, 0, 100, 100, NULL, NULL, NULL, NULL );
3285 if( !hMsiHiddenWindow )
3291 void msi_dialog_unregister_class( void )
3293 DestroyWindow( hMsiHiddenWindow );
3294 hMsiHiddenWindow = NULL;
3295 UnregisterClassW( szMsiDialogClass, NULL );
3296 UnregisterClassW( szMsiHiddenWindow, NULL );