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 static const WCHAR empty[] = {0};
541 ctrl = msi_dialog_find_control( dialog, control );
544 if( !lstrcmpW(attribute, szText) )
546 font_text = MSI_RecordGetString( rec , 1 );
547 font = msi_dialog_get_style( font_text, &text );
548 if (!text) text = empty;
549 SetWindowTextW( ctrl->hwnd, text );
551 msi_dialog_check_messages( NULL );
553 else if( !lstrcmpW(attribute, szProgress) )
557 func = MSI_RecordGetInteger( rec , 1 );
558 val = MSI_RecordGetInteger( rec , 2 );
563 ctrl->progress_max = val;
564 ctrl->progress_current = 0;
565 SendMessageW(ctrl->hwnd, PBM_SETRANGE, 0, MAKELPARAM(0,100));
566 SendMessageW(ctrl->hwnd, PBM_SETPOS, 0, 0);
568 case 1: /* FIXME: not sure what this is supposed to do */
571 ctrl->progress_current += val;
572 SendMessageW(ctrl->hwnd, PBM_SETPOS, 100*(ctrl->progress_current/ctrl->progress_max), 0);
575 ERR("Unknown progress message %ld\n", func);
581 FIXME("Attribute %s not being set\n", debugstr_w(attribute));
586 static void msi_dialog_map_events(msi_dialog* dialog, LPCWSTR control)
588 static const WCHAR Query[] = {
589 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
590 '`','E','v','e','n','t','M','a','p','p','i','n','g','`',' ',
591 'W','H','E','R','E',' ',
592 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',' ',
594 '`','C','o','n','t','r','o','l','_','`',' ','=',' ','\'','%','s','\'',0
597 LPCWSTR event, attribute;
599 row = MSI_QueryGetRecord( dialog->package->db, Query, dialog->name, control );
603 event = MSI_RecordGetString( row, 3 );
604 attribute = MSI_RecordGetString( row, 4 );
605 ControlEvent_SubscribeToEvent( dialog->package, event, control, attribute );
606 msiobj_release( &row->hdr );
609 /* everything except radio buttons */
610 static msi_control *msi_dialog_add_control( msi_dialog *dialog,
611 MSIRECORD *rec, LPCWSTR szCls, DWORD style )
617 name = MSI_RecordGetString( rec, 2 );
618 attributes = MSI_RecordGetInteger( rec, 8 );
619 text = MSI_RecordGetString( rec, 10 );
620 if( attributes & msidbControlAttributesVisible )
622 if( ~attributes & msidbControlAttributesEnabled )
623 style |= WS_DISABLED;
624 if( attributes & msidbControlAttributesSunken )
625 exstyle |= WS_EX_CLIENTEDGE;
627 msi_dialog_map_events(dialog, name);
629 return msi_dialog_create_window( dialog, rec, exstyle, szCls, name,
630 text, style, dialog->hwnd );
641 * we don't erase our own background,
642 * so we have to make sure that the parent window redraws first
644 static void msi_text_on_settext( HWND hWnd )
649 hParent = GetParent( hWnd );
650 GetWindowRect( hWnd, &rc );
651 MapWindowPoints( NULL, hParent, (LPPOINT) &rc, 2 );
652 InvalidateRect( hParent, &rc, TRUE );
655 static LRESULT WINAPI
656 MSIText_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
658 struct msi_text_info *info;
661 TRACE("%p %04x %08x %08lx\n", hWnd, msg, wParam, lParam);
663 info = GetPropW(hWnd, szButtonData);
666 SetTextColor( (HDC)wParam, info->font->color );
668 if( msg == WM_CTLCOLORSTATIC &&
669 ( info->attributes & msidbControlAttributesTransparent ) )
671 SetBkMode( (HDC)wParam, TRANSPARENT );
672 return (LRESULT) GetStockObject(NULL_BRUSH);
675 r = CallWindowProcW(info->oldproc, hWnd, msg, wParam, lParam);
680 msi_text_on_settext( hWnd );
684 RemovePropW( hWnd, szButtonData );
691 static UINT msi_dialog_text_control( msi_dialog *dialog, MSIRECORD *rec )
693 msi_control *control;
694 struct msi_text_info *info;
698 TRACE("%p %p\n", dialog, rec);
700 control = msi_dialog_add_control( dialog, rec, szStatic, SS_LEFT | WS_GROUP );
702 return ERROR_FUNCTION_FAILED;
704 info = msi_alloc( sizeof *info );
706 return ERROR_SUCCESS;
708 text = MSI_RecordGetString( rec, 10 );
709 font_name = msi_dialog_get_style( text, &ptr );
710 info->font = ( font_name ) ? msi_dialog_find_font( dialog, font_name ) : NULL;
711 msi_free( font_name );
713 info->attributes = MSI_RecordGetInteger( rec, 8 );
714 if( info->attributes & msidbControlAttributesTransparent )
715 SetWindowLongPtrW( control->hwnd, GWL_EXSTYLE, WS_EX_TRANSPARENT );
717 info->oldproc = (WNDPROC) SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
718 (LONG_PTR)MSIText_WndProc );
719 SetPropW( control->hwnd, szButtonData, info );
721 return ERROR_SUCCESS;
724 static UINT msi_dialog_button_control( msi_dialog *dialog, MSIRECORD *rec )
726 msi_control *control;
727 UINT attributes, style;
730 TRACE("%p %p\n", dialog, rec);
733 attributes = MSI_RecordGetInteger( rec, 8 );
734 if( attributes & msidbControlAttributesIcon )
737 control = msi_dialog_add_control( dialog, rec, szButton, style );
739 return ERROR_FUNCTION_FAILED;
741 control->handler = msi_dialog_button_handler;
744 text = msi_get_deformatted_field( dialog->package, rec, 10 );
745 control->hIcon = msi_load_icon( dialog->package->db, text, attributes );
746 if( attributes & msidbControlAttributesIcon )
747 SendMessageW( control->hwnd, BM_SETIMAGE, IMAGE_ICON, (LPARAM) control->hIcon );
750 return ERROR_SUCCESS;
753 static LPWSTR msi_get_checkbox_value( msi_dialog *dialog, LPCWSTR prop )
755 static const WCHAR query[] = {
756 'S','E','L','E','C','T',' ','*',' ',
757 'F','R','O','M',' ','`','C','h','e','c','k','B','o','x',' ','`',
758 'W','H','E','R','E',' ',
759 '`','P','r','o','p','e','r','t','y','`',' ','=',' ',
762 MSIRECORD *rec = NULL;
765 /* find if there is a value associated with the checkbox */
766 rec = MSI_QueryGetRecord( dialog->package->db, query, prop );
770 ret = msi_get_deformatted_field( dialog->package, rec, 2 );
776 msiobj_release( &rec->hdr );
780 ret = msi_dup_property( dialog->package, prop );
790 static UINT msi_dialog_checkbox_control( msi_dialog *dialog, MSIRECORD *rec )
792 msi_control *control;
795 TRACE("%p %p\n", dialog, rec);
797 control = msi_dialog_add_control( dialog, rec, szButton,
798 BS_CHECKBOX | BS_MULTILINE | WS_TABSTOP );
799 control->handler = msi_dialog_checkbox_handler;
800 prop = MSI_RecordGetString( rec, 9 );
803 control->property = strdupW( prop );
804 control->value = msi_get_checkbox_value( dialog, prop );
805 TRACE("control %s value %s\n", debugstr_w(control->property),
806 debugstr_w(control->value));
808 msi_dialog_checkbox_sync_state( dialog, control );
810 return ERROR_SUCCESS;
813 static UINT msi_dialog_line_control( msi_dialog *dialog, MSIRECORD *rec )
815 TRACE("%p %p\n", dialog, rec);
817 /* line is exactly 2 units in height */
818 MSI_RecordSetInteger( rec, 7, 2 );
820 msi_dialog_add_control( dialog, rec, szStatic, SS_ETCHEDHORZ | SS_SUNKEN );
821 return ERROR_SUCCESS;
824 /******************** Scroll Text ********************************************/
826 struct msi_scrolltext_info
829 msi_control *control;
833 static LRESULT WINAPI
834 MSIScrollText_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
836 struct msi_scrolltext_info *info;
839 TRACE("%p %04x %08x %08lx\n", hWnd, msg, wParam, lParam);
841 info = GetPropW( hWnd, szButtonData );
843 r = CallWindowProcW( info->oldproc, hWnd, msg, wParam, lParam );
849 RemovePropW( hWnd, szButtonData );
852 /* native MSI sets a wait cursor here */
853 msi_dialog_button_handler( info->dialog, info->control, BN_CLICKED );
859 struct msi_streamin_info
866 static DWORD CALLBACK
867 msi_richedit_stream_in( DWORD_PTR arg, LPBYTE buffer, LONG count, LONG *pcb )
869 struct msi_streamin_info *info = (struct msi_streamin_info*) arg;
871 if( (count + info->offset) > info->length )
872 count = info->length - info->offset;
873 memcpy( buffer, &info->string[ info->offset ], count );
875 info->offset += count;
877 TRACE("%ld/%ld\n", info->offset, info->length);
882 static void msi_scrolltext_add_text( msi_control *control, LPCWSTR text )
884 struct msi_streamin_info info;
887 info.string = strdupWtoA( text );
889 info.length = lstrlenA( info.string ) + 1;
891 es.dwCookie = (DWORD_PTR) &info;
893 es.pfnCallback = msi_richedit_stream_in;
895 SendMessageW( control->hwnd, EM_STREAMIN, SF_RTF, (LPARAM) &es );
897 msi_free( info.string );
900 static UINT msi_dialog_scrolltext_control( msi_dialog *dialog, MSIRECORD *rec )
902 static const WCHAR szRichEdit20W[] = {
903 'R','i','c','h','E','d','i','t','2','0','W',0
905 struct msi_scrolltext_info *info;
906 msi_control *control;
910 info = msi_alloc( sizeof *info );
912 return ERROR_FUNCTION_FAILED;
914 hRichedit = LoadLibraryA("riched20");
916 style = WS_BORDER | ES_MULTILINE | WS_VSCROLL |
917 ES_READONLY | ES_AUTOVSCROLL | WS_TABSTOP;
918 control = msi_dialog_add_control( dialog, rec, szRichEdit20W, style );
921 FreeLibrary( hRichedit );
923 return ERROR_FUNCTION_FAILED;
926 control->hDll = hRichedit;
928 info->dialog = dialog;
929 info->control = control;
931 /* subclass the static control */
932 info->oldproc = (WNDPROC) SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
933 (LONG_PTR)MSIScrollText_WndProc );
934 SetPropW( control->hwnd, szButtonData, info );
936 /* add the text into the richedit */
937 msi_scrolltext_add_text( control, MSI_RecordGetString( rec, 10 ) );
939 return ERROR_SUCCESS;
942 static HBITMAP msi_load_picture( MSIDATABASE *db, LPCWSTR name,
943 INT cx, INT cy, DWORD flags )
945 HBITMAP hOleBitmap = 0, hBitmap = 0, hOldSrcBitmap, hOldDestBitmap;
946 MSIRECORD *rec = NULL;
948 IPicture *pic = NULL;
953 rec = msi_get_binary_record( db, name );
957 r = MSI_RecordGetIStream( rec, 2, &stm );
958 msiobj_release( &rec->hdr );
959 if( r != ERROR_SUCCESS )
962 r = OleLoadPicture( stm, 0, TRUE, &IID_IPicture, (LPVOID*) &pic );
963 IStream_Release( stm );
966 ERR("failed to load picture\n");
970 r = IPicture_get_Handle( pic, (OLE_HANDLE*) &hOleBitmap );
973 ERR("failed to get bitmap handle\n");
977 /* make the bitmap the desired size */
978 r = GetObjectW( hOleBitmap, sizeof bm, &bm );
981 ERR("failed to get bitmap size\n");
985 if (flags & LR_DEFAULTSIZE)
991 srcdc = CreateCompatibleDC( NULL );
992 hOldSrcBitmap = SelectObject( srcdc, hOleBitmap );
993 destdc = CreateCompatibleDC( NULL );
994 hBitmap = CreateCompatibleBitmap( srcdc, cx, cy );
995 hOldDestBitmap = SelectObject( destdc, hBitmap );
996 StretchBlt( destdc, 0, 0, cx, cy,
997 srcdc, 0, 0, bm.bmWidth, bm.bmHeight, SRCCOPY);
998 SelectObject( srcdc, hOldSrcBitmap );
999 SelectObject( destdc, hOldDestBitmap );
1005 IPicture_Release( pic );
1009 static UINT msi_dialog_bitmap_control( msi_dialog *dialog, MSIRECORD *rec )
1011 UINT cx, cy, flags, style, attributes;
1012 msi_control *control;
1015 flags = LR_LOADFROMFILE;
1016 style = SS_BITMAP | SS_LEFT | WS_GROUP;
1018 attributes = MSI_RecordGetInteger( rec, 8 );
1019 if( attributes & msidbControlAttributesFixedSize )
1021 flags |= LR_DEFAULTSIZE;
1022 style |= SS_CENTERIMAGE;
1025 control = msi_dialog_add_control( dialog, rec, szStatic, style );
1026 cx = MSI_RecordGetInteger( rec, 6 );
1027 cy = MSI_RecordGetInteger( rec, 7 );
1028 cx = msi_dialog_scale_unit( dialog, cx );
1029 cy = msi_dialog_scale_unit( dialog, cy );
1031 text = msi_get_deformatted_field( dialog->package, rec, 10 );
1032 control->hBitmap = msi_load_picture( dialog->package->db, text, cx, cy, flags );
1033 if( control->hBitmap )
1034 SendMessageW( control->hwnd, STM_SETIMAGE,
1035 IMAGE_BITMAP, (LPARAM) control->hBitmap );
1037 ERR("Failed to load bitmap %s\n", debugstr_w(text));
1041 return ERROR_SUCCESS;
1044 static UINT msi_dialog_icon_control( msi_dialog *dialog, MSIRECORD *rec )
1046 msi_control *control;
1052 control = msi_dialog_add_control( dialog, rec, szStatic,
1053 SS_ICON | SS_CENTERIMAGE | WS_GROUP );
1055 attributes = MSI_RecordGetInteger( rec, 8 );
1056 text = msi_get_deformatted_field( dialog->package, rec, 10 );
1057 control->hIcon = msi_load_icon( dialog->package->db, text, attributes );
1058 if( control->hIcon )
1059 SendMessageW( control->hwnd, STM_SETICON, (WPARAM) control->hIcon, 0 );
1061 ERR("Failed to load bitmap %s\n", debugstr_w(text));
1063 return ERROR_SUCCESS;
1066 static UINT msi_dialog_combo_control( msi_dialog *dialog, MSIRECORD *rec )
1068 static const WCHAR szCombo[] = { 'C','O','M','B','O','B','O','X',0 };
1070 msi_dialog_add_control( dialog, rec, szCombo,
1071 SS_BITMAP | SS_LEFT | SS_CENTERIMAGE );
1072 return ERROR_SUCCESS;
1075 static UINT msi_dialog_edit_control( msi_dialog *dialog, MSIRECORD *rec )
1077 msi_control *control;
1081 control = msi_dialog_add_control( dialog, rec, szEdit,
1082 WS_BORDER | WS_TABSTOP );
1083 control->handler = msi_dialog_edit_handler;
1084 prop = MSI_RecordGetString( rec, 9 );
1086 control->property = strdupW( prop );
1087 val = msi_dup_property( dialog->package, control->property );
1088 SetWindowTextW( control->hwnd, val );
1090 return ERROR_SUCCESS;
1093 /******************** Masked Edit ********************************************/
1095 #define MASK_MAX_GROUPS 20
1097 struct msi_mask_group
1105 struct msi_maskedit_info
1113 struct msi_mask_group group[MASK_MAX_GROUPS];
1116 static BOOL msi_mask_editable( WCHAR type )
1131 static void msi_mask_control_change( struct msi_maskedit_info *info )
1136 val = msi_alloc( (info->num_chars+1)*sizeof(WCHAR) );
1137 for( i=0, n=0; i<info->num_groups; i++ )
1139 if( (info->group[i].len + n) > info->num_chars )
1141 ERR("can't fit control %d text into template\n",i);
1144 if (!msi_mask_editable(info->group[i].type))
1146 for(r=0; r<info->group[i].len; r++)
1147 val[n+r] = info->group[i].type;
1152 r = GetWindowTextW( info->group[i].hwnd, &val[n], info->group[i].len+1 );
1153 if( r != info->group[i].len )
1159 TRACE("%d/%d controls were good\n", i, info->num_groups);
1161 if( i == info->num_groups )
1163 TRACE("Set property %s to %s\n",
1164 debugstr_w(info->prop), debugstr_w(val) );
1165 CharUpperBuffW( val, info->num_chars );
1166 MSI_SetPropertyW( info->dialog->package, info->prop, val );
1167 msi_dialog_evaluate_control_conditions( info->dialog );
1172 /* now move to the next control if necessary */
1173 static VOID msi_mask_next_control( struct msi_maskedit_info *info, HWND hWnd )
1178 for( i=0; i<info->num_groups; i++ )
1179 if( info->group[i].hwnd == hWnd )
1182 /* don't move from the last control */
1183 if( i >= (info->num_groups-1) )
1186 len = SendMessageW( hWnd, WM_GETTEXTLENGTH, 0, 0 );
1187 if( len < info->group[i].len )
1190 hWndNext = GetNextDlgTabItem( GetParent( hWnd ), hWnd, FALSE );
1191 SetFocus( hWndNext );
1194 static LRESULT WINAPI
1195 MSIMaskedEdit_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
1197 struct msi_maskedit_info *info;
1200 TRACE("%p %04x %08x %08lx\n", hWnd, msg, wParam, lParam);
1202 info = GetPropW(hWnd, szButtonData);
1204 r = CallWindowProcW(info->oldproc, hWnd, msg, wParam, lParam);
1209 if (HIWORD(wParam) == EN_CHANGE)
1211 msi_mask_control_change( info );
1212 msi_mask_next_control( info, (HWND) lParam );
1216 msi_free( info->prop );
1218 RemovePropW( hWnd, szButtonData );
1225 /* fish the various bits of the property out and put them in the control */
1227 msi_maskedit_set_text( struct msi_maskedit_info *info, LPCWSTR text )
1233 for( i = 0; i < info->num_groups; i++ )
1235 if( info->group[i].len < lstrlenW( p ) )
1237 LPWSTR chunk = strdupW( p );
1238 chunk[ info->group[i].len ] = 0;
1239 SetWindowTextW( info->group[i].hwnd, chunk );
1244 SetWindowTextW( info->group[i].hwnd, p );
1247 p += info->group[i].len;
1251 static struct msi_maskedit_info * msi_dialog_parse_groups( LPCWSTR mask )
1253 struct msi_maskedit_info * info = NULL;
1254 int i = 0, n = 0, total = 0;
1257 TRACE("masked control, template %s\n", debugstr_w(mask));
1262 info = msi_alloc_zero( sizeof *info );
1266 p = strchrW(mask, '<');
1272 for( i=0; i<MASK_MAX_GROUPS; i++ )
1274 /* stop at the end of the string */
1275 if( p[0] == 0 || p[0] == '>' )
1278 /* count the number of the same identifier */
1279 for( n=0; p[n] == p[0]; n++ )
1281 info->group[i].ofs = total;
1282 info->group[i].type = p[0];
1286 total++; /* an extra not part of the group */
1288 info->group[i].len = n;
1293 TRACE("%d characters in %d groups\n", total, i );
1294 if( i == MASK_MAX_GROUPS )
1295 ERR("too many groups in PIDTemplate %s\n", debugstr_w(mask));
1297 info->num_chars = total;
1298 info->num_groups = i;
1304 msi_maskedit_create_children( struct msi_maskedit_info *info, LPCWSTR font )
1306 DWORD width, height, style, wx, ww;
1311 style = WS_CHILD | WS_BORDER | WS_VISIBLE | WS_TABSTOP | ES_AUTOHSCROLL;
1313 GetClientRect( info->hwnd, &rect );
1315 width = rect.right - rect.left;
1316 height = rect.bottom - rect.top;
1318 for( i = 0; i < info->num_groups; i++ )
1320 if (!msi_mask_editable( info->group[i].type ))
1322 wx = (info->group[i].ofs * width) / info->num_chars;
1323 ww = (info->group[i].len * width) / info->num_chars;
1325 hwnd = CreateWindowW( szEdit, NULL, style, wx, 0, ww, height,
1326 info->hwnd, NULL, NULL, NULL );
1329 ERR("failed to create mask edit sub window\n");
1333 SendMessageW( hwnd, EM_LIMITTEXT, info->group[i].len, 0 );
1335 msi_dialog_set_font( info->dialog, hwnd,
1336 font?font:info->dialog->default_font );
1337 info->group[i].hwnd = hwnd;
1342 * office 2003 uses "73931<````=````=````=````=`````>@@@@@"
1343 * delphi 7 uses "<????-??????-??????-????>" and "<???-???>"
1344 * filemaker pro 7 uses "<^^^^=^^^^=^^^^=^^^^=^^^^=^^^^=^^^^^>"
1346 static UINT msi_dialog_maskedit_control( msi_dialog *dialog, MSIRECORD *rec )
1348 LPWSTR font_mask, val = NULL, font;
1349 struct msi_maskedit_info *info = NULL;
1350 UINT ret = ERROR_SUCCESS;
1351 msi_control *control;
1356 font_mask = msi_get_deformatted_field( dialog->package, rec, 10 );
1357 font = msi_dialog_get_style( font_mask, &mask );
1360 ERR("mask template is empty\n");
1364 info = msi_dialog_parse_groups( mask );
1367 ERR("template %s is invalid\n", debugstr_w(mask));
1371 info->dialog = dialog;
1373 control = msi_dialog_add_control( dialog, rec, szStatic,
1374 SS_OWNERDRAW | WS_GROUP | WS_VISIBLE );
1377 ERR("Failed to create maskedit container\n");
1378 ret = ERROR_FUNCTION_FAILED;
1381 SetWindowLongPtrW( control->hwnd, GWL_EXSTYLE, WS_EX_CONTROLPARENT );
1383 info->hwnd = control->hwnd;
1385 /* subclass the static control */
1386 info->oldproc = (WNDPROC) SetWindowLongPtrW( info->hwnd, GWLP_WNDPROC,
1387 (LONG_PTR)MSIMaskedEdit_WndProc );
1388 SetPropW( control->hwnd, szButtonData, info );
1390 prop = MSI_RecordGetString( rec, 9 );
1392 info->prop = strdupW( prop );
1394 msi_maskedit_create_children( info, font );
1398 val = msi_dup_property( dialog->package, prop );
1401 msi_maskedit_set_text( info, val );
1407 if( ret != ERROR_SUCCESS )
1409 msi_free( font_mask );
1414 /******************** Progress Bar *****************************************/
1416 static UINT msi_dialog_progress_bar( msi_dialog *dialog, MSIRECORD *rec )
1418 msi_dialog_add_control( dialog, rec, PROGRESS_CLASSW, WS_VISIBLE );
1419 return ERROR_SUCCESS;
1422 /******************** Path Edit ********************************************/
1424 struct msi_pathedit_info
1427 msi_control *control;
1431 static LPWSTR msi_get_window_text( HWND hwnd )
1437 buf = msi_alloc( sz*sizeof(WCHAR) );
1440 r = GetWindowTextW( hwnd, buf, sz );
1444 buf = msi_realloc( buf, sz*sizeof(WCHAR) );
1450 static void msi_dialog_update_pathedit( msi_dialog *dialog, msi_control *control )
1455 if (!control && !(control = msi_dialog_find_control_by_type( dialog, szPathEdit )))
1458 indirect = control->attributes & msidbControlAttributesIndirect;
1459 prop = msi_dialog_dup_property( dialog, control->property, indirect );
1461 path = msi_dup_property( dialog->package, prop );
1465 SetWindowTextW( control->hwnd, path );
1466 SendMessageW( control->hwnd, EM_SETSEL, 0, -1 );
1472 /* FIXME: test when this should fail */
1473 static BOOL msi_dialog_verify_path( LPWSTR path )
1475 if ( !lstrlenW( path ) )
1478 if ( PathIsRelativeW( path ) )
1484 /* returns TRUE if the path is valid, FALSE otherwise */
1485 static BOOL msi_dialog_onkillfocus( msi_dialog *dialog, msi_control *control )
1491 indirect = control->attributes & msidbControlAttributesIndirect;
1492 prop = msi_dialog_dup_property( dialog, control->property, indirect );
1494 buf = msi_get_window_text( control->hwnd );
1496 if ( !msi_dialog_verify_path( buf ) )
1498 /* FIXME: display an error message box */
1499 ERR("Invalid path %s\n", debugstr_w( buf ));
1501 SetFocus( control->hwnd );
1506 MSI_SetPropertyW( dialog->package, prop, buf );
1509 msi_dialog_update_pathedit( dialog, control );
1511 TRACE("edit %s contents changed, set %s\n", debugstr_w(control->name),
1520 static LRESULT WINAPI MSIPathEdit_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
1522 struct msi_pathedit_info *info = GetPropW(hWnd, szButtonData);
1525 TRACE("%p %04x %08x %08lx\n", hWnd, msg, wParam, lParam);
1527 if ( msg == WM_KILLFOCUS )
1529 /* if the path is invalid, don't handle this message */
1530 if ( !msi_dialog_onkillfocus( info->dialog, info->control ) )
1534 r = CallWindowProcW(info->oldproc, hWnd, msg, wParam, lParam);
1536 if ( msg == WM_NCDESTROY )
1539 RemovePropW( hWnd, szButtonData );
1545 static UINT msi_dialog_pathedit_control( msi_dialog *dialog, MSIRECORD *rec )
1547 struct msi_pathedit_info *info;
1548 msi_control *control;
1551 info = msi_alloc( sizeof *info );
1553 return ERROR_FUNCTION_FAILED;
1555 control = msi_dialog_add_control( dialog, rec, szEdit,
1556 WS_BORDER | WS_TABSTOP );
1557 control->attributes = MSI_RecordGetInteger( rec, 8 );
1558 prop = MSI_RecordGetString( rec, 9 );
1559 control->property = msi_dialog_dup_property( dialog, prop, FALSE );
1561 info->dialog = dialog;
1562 info->control = control;
1563 info->oldproc = (WNDPROC) SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
1564 (LONG_PTR)MSIPathEdit_WndProc );
1565 SetPropW( control->hwnd, szButtonData, info );
1567 msi_dialog_update_pathedit( dialog, control );
1569 return ERROR_SUCCESS;
1572 /* radio buttons are a bit different from normal controls */
1573 static UINT msi_dialog_create_radiobutton( MSIRECORD *rec, LPVOID param )
1575 radio_button_group_descr *group = (radio_button_group_descr *)param;
1576 msi_dialog *dialog = group->dialog;
1577 msi_control *control;
1578 LPCWSTR prop, text, name;
1579 DWORD style, attributes = group->attributes;
1581 style = WS_CHILD | BS_AUTORADIOBUTTON | BS_MULTILINE | WS_TABSTOP;
1582 name = MSI_RecordGetString( rec, 3 );
1583 text = MSI_RecordGetString( rec, 8 );
1584 if( attributes & 1 )
1585 style |= WS_VISIBLE;
1586 if( ~attributes & 2 )
1587 style |= WS_DISABLED;
1589 control = msi_dialog_create_window( dialog, rec, 0, szButton, name, text,
1590 style, group->parent->hwnd );
1592 return ERROR_FUNCTION_FAILED;
1593 control->handler = msi_dialog_radiogroup_handler;
1595 if (!lstrcmpW(control->name, group->propval))
1596 SendMessageW(control->hwnd, BM_SETCHECK, BST_CHECKED, 0);
1598 prop = MSI_RecordGetString( rec, 1 );
1600 control->property = strdupW( prop );
1602 return ERROR_SUCCESS;
1605 static UINT msi_dialog_radiogroup_control( msi_dialog *dialog, MSIRECORD *rec )
1607 static const WCHAR query[] = {
1608 'S','E','L','E','C','T',' ','*',' ',
1609 'F','R','O','M',' ','R','a','d','i','o','B','u','t','t','o','n',' ',
1610 'W','H','E','R','E',' ',
1611 '`','P','r','o','p','e','r','t','y','`',' ','=',' ','\'','%','s','\'',0};
1614 msi_control *control;
1615 MSIQUERY *view = NULL;
1616 radio_button_group_descr group;
1617 MSIPACKAGE *package = dialog->package;
1620 prop = MSI_RecordGetString( rec, 9 );
1622 TRACE("%p %p %s\n", dialog, rec, debugstr_w( prop ));
1624 /* Create parent group box to hold radio buttons */
1625 control = msi_dialog_add_control( dialog, rec, szButton, BS_OWNERDRAW|WS_GROUP );
1627 return ERROR_FUNCTION_FAILED;
1629 oldproc = (WNDPROC) SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
1630 (LONG_PTR)MSIRadioGroup_WndProc );
1631 SetPropW(control->hwnd, szButtonData, oldproc);
1632 SetWindowLongPtrW( control->hwnd, GWL_EXSTYLE, WS_EX_CONTROLPARENT );
1635 control->property = strdupW( prop );
1637 /* query the Radio Button table for all control in this group */
1638 r = MSI_OpenQuery( package->db, &view, query, prop );
1639 if( r != ERROR_SUCCESS )
1641 ERR("query failed for dialog %s radio group %s\n",
1642 debugstr_w(dialog->name), debugstr_w(prop));
1643 return ERROR_INVALID_PARAMETER;
1646 group.dialog = dialog;
1647 group.parent = control;
1648 group.attributes = MSI_RecordGetInteger( rec, 8 );
1649 group.propval = msi_dup_property( dialog->package, control->property );
1651 r = MSI_IterateRecords( view, 0, msi_dialog_create_radiobutton, &group );
1652 msiobj_release( &view->hdr );
1653 msi_free( group.propval );
1658 /******************** Selection Tree ***************************************/
1660 struct msi_selection_tree_info
1668 msi_seltree_sync_item_state( HWND hwnd, MSIFEATURE *feature, HTREEITEM hItem )
1671 DWORD index = feature->Action;
1673 TRACE("Feature %s -> %d %d %d\n", debugstr_w(feature->Title),
1674 feature->Installed, feature->Action, feature->ActionRequest);
1676 if (index == INSTALLSTATE_UNKNOWN)
1677 index = INSTALLSTATE_ABSENT;
1679 tvi.mask = TVIF_STATE;
1681 tvi.state = INDEXTOSTATEIMAGEMASK( index );
1682 tvi.stateMask = TVIS_STATEIMAGEMASK;
1684 SendMessageW( hwnd, TVM_SETITEMW, 0, (LPARAM) &tvi );
1688 msi_seltree_popup_menu( HWND hwnd, INT x, INT y )
1693 /* create a menu to display */
1694 hMenu = CreatePopupMenu();
1696 /* FIXME: load strings from resources */
1697 AppendMenuA( hMenu, MF_ENABLED, INSTALLSTATE_LOCAL, "Install feature locally");
1698 AppendMenuA( hMenu, MF_GRAYED, 0x1000, "Install entire feature");
1699 AppendMenuA( hMenu, MF_ENABLED, INSTALLSTATE_ADVERTISED, "Install on demand");
1700 AppendMenuA( hMenu, MF_ENABLED, INSTALLSTATE_ABSENT, "Don't install");
1701 r = TrackPopupMenu( hMenu, TPM_LEFTALIGN | TPM_TOPALIGN | TPM_RETURNCMD,
1702 x, y, 0, hwnd, NULL );
1703 DestroyMenu( hMenu );
1708 msi_seltree_feature_from_item( HWND hwnd, HTREEITEM hItem )
1712 /* get the feature from the item */
1713 memset( &tvi, 0, sizeof tvi );
1715 tvi.mask = TVIF_PARAM | TVIF_HANDLE;
1716 SendMessageW( hwnd, TVM_GETITEMW, 0, (LPARAM) &tvi );
1718 return (MSIFEATURE*) tvi.lParam;
1722 msi_seltree_menu( HWND hwnd, HTREEITEM hItem )
1724 struct msi_selection_tree_info *info;
1725 MSIFEATURE *feature;
1726 MSIPACKAGE *package;
1734 info = GetPropW(hwnd, szButtonData);
1735 package = info->dialog->package;
1737 feature = msi_seltree_feature_from_item( hwnd, hItem );
1740 ERR("item %p feature was NULL\n", hItem);
1744 /* get the item's rectangle to put the menu just below it */
1746 SendMessageW( hwnd, TVM_GETITEMRECT, 0, (LPARAM) &u.rc );
1747 MapWindowPoints( hwnd, NULL, u.pt, 2 );
1749 r = msi_seltree_popup_menu( hwnd, u.rc.left, u.rc.top );
1753 case INSTALLSTATE_LOCAL:
1754 case INSTALLSTATE_ADVERTISED:
1755 case INSTALLSTATE_ABSENT:
1756 feature->ActionRequest = r;
1757 feature->Action = r;
1760 FIXME("select feature and all children\n");
1764 msi_seltree_sync_item_state( hwnd, feature, hItem );
1765 ACTION_UpdateComponentStates( package, feature->Feature );
1770 static LRESULT WINAPI
1771 MSISelectionTree_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
1773 struct msi_selection_tree_info *info;
1774 TVHITTESTINFO tvhti;
1777 TRACE("%p %04x %08x %08lx\n", hWnd, msg, wParam, lParam);
1779 info = GetPropW(hWnd, szButtonData);
1783 case WM_LBUTTONDOWN:
1784 tvhti.pt.x = LOWORD( lParam );
1785 tvhti.pt.y = HIWORD( lParam );
1788 r = CallWindowProcW(info->oldproc, hWnd, TVM_HITTEST, 0, (LPARAM) &tvhti );
1789 if (tvhti.flags & TVHT_ONITEMSTATEICON)
1790 return msi_seltree_menu( hWnd, tvhti.hItem );
1794 r = CallWindowProcW(info->oldproc, hWnd, msg, wParam, lParam);
1800 RemovePropW( hWnd, szButtonData );
1807 msi_seltree_add_child_features( MSIPACKAGE *package, HWND hwnd,
1808 LPCWSTR parent, HTREEITEM hParent )
1810 MSIFEATURE *feature;
1811 TVINSERTSTRUCTW tvis;
1814 LIST_FOR_EACH_ENTRY( feature, &package->features, MSIFEATURE, entry )
1816 if ( lstrcmpW( parent, feature->Feature_Parent ) )
1819 if ( !feature->Title )
1822 if ( !feature->Display )
1825 memset( &tvis, 0, sizeof tvis );
1826 tvis.hParent = hParent;
1827 tvis.hInsertAfter = TVI_LAST;
1828 tvis.u.item.mask = TVIF_TEXT | TVIF_PARAM;
1829 tvis.u.item.pszText = feature->Title;
1830 tvis.u.item.lParam = (LPARAM) feature;
1832 hitem = (HTREEITEM) SendMessageW( hwnd, TVM_INSERTITEMW, 0, (LPARAM) &tvis );
1836 msi_seltree_sync_item_state( hwnd, feature, hitem );
1837 msi_seltree_add_child_features( package, hwnd,
1838 feature->Feature, hitem );
1840 /* the node is expanded if Display is odd */
1841 if ( feature->Display % 2 != 0 )
1842 SendMessageW( hwnd, TVM_EXPAND, TVE_EXPAND, (LPARAM) hitem );
1846 static void msi_seltree_create_imagelist( HWND hwnd )
1848 const int bm_width = 32, bm_height = 16, bm_count = 3;
1849 const int bm_resource = 0x1001;
1854 himl = ImageList_Create( bm_width, bm_height, FALSE, 4, 0 );
1857 ERR("failed to create image list\n");
1861 for (i=0; i<bm_count; i++)
1863 hbmp = LoadBitmapW( msi_hInstance, MAKEINTRESOURCEW(i+bm_resource) );
1866 ERR("failed to load bitmap %d\n", i);
1871 * Add a dummy bitmap at offset zero because the treeview
1872 * can't use it as a state mask (zero means no user state).
1875 ImageList_Add( himl, hbmp, NULL );
1877 ImageList_Add( himl, hbmp, NULL );
1880 SendMessageW( hwnd, TVM_SETIMAGELIST, TVSIL_STATE, (LPARAM)himl );
1883 static UINT msi_dialog_selection_tree( msi_dialog *dialog, MSIRECORD *rec )
1885 msi_control *control;
1887 MSIPACKAGE *package = dialog->package;
1889 struct msi_selection_tree_info *info;
1891 info = msi_alloc( sizeof *info );
1893 return ERROR_FUNCTION_FAILED;
1895 /* create the treeview control */
1896 prop = MSI_RecordGetString( rec, 9 );
1897 style = TVS_HASLINES | TVS_HASBUTTONS | TVS_LINESATROOT;
1898 style |= WS_GROUP | WS_VSCROLL;
1899 control = msi_dialog_add_control( dialog, rec, WC_TREEVIEWW, style );
1903 return ERROR_FUNCTION_FAILED;
1907 info->dialog = dialog;
1908 info->hwnd = control->hwnd;
1909 info->oldproc = (WNDPROC) SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
1910 (LONG_PTR)MSISelectionTree_WndProc );
1911 SetPropW( control->hwnd, szButtonData, info );
1914 msi_seltree_create_imagelist( control->hwnd );
1915 msi_seltree_add_child_features( package, control->hwnd, NULL, NULL );
1917 return ERROR_SUCCESS;
1920 /******************** Group Box ***************************************/
1922 static UINT msi_dialog_group_box( msi_dialog *dialog, MSIRECORD *rec )
1924 msi_control *control;
1927 style = BS_GROUPBOX | WS_CHILD | WS_GROUP;
1928 control = msi_dialog_add_control( dialog, rec, WC_BUTTONW, style );
1930 return ERROR_FUNCTION_FAILED;
1932 return ERROR_SUCCESS;
1935 /******************** List Box ***************************************/
1937 struct msi_listbox_item
1943 struct msi_listbox_info
1949 struct msi_listbox_item *items;
1952 static LRESULT WINAPI MSIListBox_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
1954 struct msi_listbox_info *info;
1958 TRACE("%p %04x %08x %08lx\n", hWnd, msg, wParam, lParam);
1960 info = GetPropW( hWnd, szButtonData );
1964 r = CallWindowProcW( info->oldproc, hWnd, msg, wParam, lParam );
1969 for (j = 0; j < info->num_items; j++)
1971 msi_free( info->items[j].property );
1972 msi_free( info->items[j].value );
1974 msi_free( info->items );
1976 RemovePropW( hWnd, szButtonData );
1983 static UINT msi_listbox_add_item( MSIRECORD *rec, LPVOID param )
1985 struct msi_listbox_info *info = param;
1986 struct msi_listbox_item *item;
1987 LPCWSTR property, value, text;
1988 static int index = 0;
1990 item = &info->items[index++];
1991 property = MSI_RecordGetString( rec, 1 );
1992 value = MSI_RecordGetString( rec, 3 );
1993 text = MSI_RecordGetString( rec, 4 );
1995 item->property = strdupW( property );
1996 item->value = strdupW( value );
1998 SendMessageW( info->hwnd, LB_ADDSTRING, 0, (LPARAM)text );
2000 return ERROR_SUCCESS;
2003 static UINT msi_listbox_add_items( struct msi_listbox_info *info )
2006 MSIQUERY *view = NULL;
2009 static const WCHAR query[] = {
2010 'S','E','L','E','C','T',' ','*',' ',
2011 'F','R','O','M',' ','`','L','i','s','t','B','o','x','`',' ',
2012 'O','R','D','E','R',' ','B','Y',' ','`','O','r','d','e','r','`',0
2015 r = MSI_OpenQuery( info->dialog->package->db, &view, query );
2016 if ( r != ERROR_SUCCESS )
2019 /* just get the number of records */
2020 r = MSI_IterateRecords( view, &count, NULL, NULL );
2022 info->num_items = count;
2023 info->items = msi_alloc( sizeof(*info->items) * count );
2025 r = MSI_IterateRecords( view, NULL, msi_listbox_add_item, info );
2026 msiobj_release( &view->hdr );
2031 static UINT msi_dialog_listbox_handler( msi_dialog *dialog,
2032 msi_control *control, WPARAM param )
2034 struct msi_listbox_info *info;
2037 if( HIWORD(param) != LBN_SELCHANGE )
2038 return ERROR_SUCCESS;
2040 info = GetPropW( control->hwnd, szButtonData );
2041 index = SendMessageW( control->hwnd, LB_GETCURSEL, 0, 0 );
2043 MSI_SetPropertyW( info->dialog->package,
2044 info->items[index].property, info->items[index].value );
2045 msi_dialog_evaluate_control_conditions( info->dialog );
2047 return ERROR_SUCCESS;
2050 static UINT msi_dialog_list_box( msi_dialog *dialog, MSIRECORD *rec )
2052 struct msi_listbox_info *info;
2053 msi_control *control;
2056 info = msi_alloc( sizeof *info );
2058 return ERROR_FUNCTION_FAILED;
2060 style = WS_TABSTOP | WS_GROUP | WS_CHILD | LBS_STANDARD;
2061 control = msi_dialog_add_control( dialog, rec, WC_LISTBOXW, style );
2063 return ERROR_FUNCTION_FAILED;
2065 control->handler = msi_dialog_listbox_handler;
2068 info->dialog = dialog;
2069 info->hwnd = control->hwnd;
2071 info->oldproc = (WNDPROC)SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
2072 (LONG_PTR)MSIListBox_WndProc );
2073 SetPropW( control->hwnd, szButtonData, info );
2075 msi_listbox_add_items( info );
2077 return ERROR_SUCCESS;
2080 /******************** Directory Combo ***************************************/
2082 static void msi_dialog_update_directory_combo( msi_dialog *dialog, msi_control *control )
2087 if (!control && !(control = msi_dialog_find_control_by_type( dialog, szDirectoryCombo )))
2090 indirect = control->attributes & msidbControlAttributesIndirect;
2091 prop = msi_dialog_dup_property( dialog, control->property, indirect );
2093 path = msi_dup_property( dialog->package, prop );
2097 PathStripPathW( path );
2098 PathRemoveBackslashW( path );
2100 SendMessageW( control->hwnd, CB_INSERTSTRING, 0, (LPARAM)path );
2101 SendMessageW( control->hwnd, CB_SETCURSEL, 0, 0 );
2107 static UINT msi_dialog_directory_combo( msi_dialog *dialog, MSIRECORD *rec )
2109 msi_control *control;
2113 /* FIXME: use CBS_OWNERDRAWFIXED and add owner draw code */
2114 style = CBS_DROPDOWNLIST | CBS_HASSTRINGS | WS_CHILD |
2115 WS_GROUP | WS_TABSTOP | WS_VSCROLL;
2116 control = msi_dialog_add_control( dialog, rec, WC_COMBOBOXW, style );
2118 return ERROR_FUNCTION_FAILED;
2120 control->attributes = MSI_RecordGetInteger( rec, 8 );
2121 prop = MSI_RecordGetString( rec, 9 );
2122 control->property = msi_dialog_dup_property( dialog, prop, FALSE );
2124 msi_dialog_update_directory_combo( dialog, control );
2126 return ERROR_SUCCESS;
2129 /******************** Directory List ***************************************/
2131 static void msi_dialog_update_directory_list( msi_dialog *dialog, msi_control *control )
2133 WCHAR dir_spec[MAX_PATH];
2134 WIN32_FIND_DATAW wfd;
2140 static const WCHAR asterisk[] = {'*',0};
2141 static const WCHAR dot[] = {'.',0};
2142 static const WCHAR dotdot[] = {'.','.',0};
2144 if (!control && !(control = msi_dialog_find_control_by_type( dialog, szDirectoryList )))
2147 /* clear the list-view */
2148 SendMessageW( control->hwnd, LVM_DELETEALLITEMS, 0, 0 );
2150 indirect = control->attributes & msidbControlAttributesIndirect;
2151 prop = msi_dialog_dup_property( dialog, control->property, indirect );
2153 path = msi_dup_property( dialog->package, prop );
2157 lstrcpyW( dir_spec, path );
2158 lstrcatW( dir_spec, asterisk );
2160 file = FindFirstFileW( dir_spec, &wfd );
2161 if ( file == INVALID_HANDLE_VALUE )
2166 if ( wfd.dwFileAttributes != FILE_ATTRIBUTE_DIRECTORY )
2169 if ( !lstrcmpW( wfd.cFileName, dot ) || !lstrcmpW( wfd.cFileName, dotdot ) )
2172 item.mask = LVIF_TEXT;
2173 item.cchTextMax = MAX_PATH;
2176 item.pszText = wfd.cFileName;
2178 SendMessageW( control->hwnd, LVM_INSERTITEMW, 0, (LPARAM)&item );
2179 } while ( FindNextFileW( file, &wfd ) );
2186 UINT msi_dialog_directorylist_up( msi_dialog *dialog )
2188 msi_control *control;
2189 LPWSTR prop, path, ptr;
2192 control = msi_dialog_find_control_by_type( dialog, szDirectoryList );
2193 indirect = control->attributes & msidbControlAttributesIndirect;
2194 prop = msi_dialog_dup_property( dialog, control->property, indirect );
2196 path = msi_dup_property( dialog->package, prop );
2200 /* strip off the last directory */
2201 ptr = PathFindFileNameW( path );
2202 if (ptr != path) *(ptr - 1) = '\0';
2203 PathAddBackslashW( path );
2205 MSI_SetPropertyW( dialog->package, prop, path );
2207 msi_dialog_update_directory_list( dialog, NULL );
2208 msi_dialog_update_directory_combo( dialog, NULL );
2209 msi_dialog_update_pathedit( dialog, NULL );
2214 return ERROR_SUCCESS;
2217 static UINT msi_dialog_dirlist_handler( msi_dialog *dialog,
2218 msi_control *control, WPARAM param )
2220 LPNMHDR nmhdr = (LPNMHDR)param;
2221 WCHAR new_path[MAX_PATH];
2222 WCHAR text[MAX_PATH];
2228 static const WCHAR backslash[] = {'\\',0};
2230 if (nmhdr->code != LVN_ITEMACTIVATE)
2231 return ERROR_SUCCESS;
2233 index = SendMessageW( control->hwnd, LVM_GETNEXTITEM, -1, LVNI_SELECTED );
2236 ERR("No list-view item selected!\n");
2237 return ERROR_FUNCTION_FAILED;
2241 item.pszText = text;
2242 item.cchTextMax = MAX_PATH;
2243 SendMessageW( control->hwnd, LVM_GETITEMTEXTW, index, (LPARAM)&item );
2245 indirect = control->attributes & msidbControlAttributesIndirect;
2246 prop = msi_dialog_dup_property( dialog, control->property, indirect );
2248 path = msi_dup_property( dialog->package, prop );
2252 lstrcpyW( new_path, path );
2253 lstrcatW( new_path, text );
2254 lstrcatW( new_path, backslash );
2256 MSI_SetPropertyW( dialog->package, prop, new_path );
2258 msi_dialog_update_directory_list( dialog, NULL );
2259 msi_dialog_update_directory_combo( dialog, NULL );
2260 msi_dialog_update_pathedit( dialog, NULL );
2264 return ERROR_SUCCESS;
2267 static UINT msi_dialog_directory_list( msi_dialog *dialog, MSIRECORD *rec )
2269 msi_control *control;
2273 style = LVS_LIST | WS_VSCROLL | LVS_SHAREIMAGELISTS |
2274 LVS_AUTOARRANGE | LVS_SINGLESEL | WS_BORDER |
2275 LVS_SORTASCENDING | WS_CHILD | WS_GROUP | WS_TABSTOP;
2276 control = msi_dialog_add_control( dialog, rec, WC_LISTVIEWW, style );
2278 return ERROR_FUNCTION_FAILED;
2280 control->attributes = MSI_RecordGetInteger( rec, 8 );
2281 control->handler = msi_dialog_dirlist_handler;
2282 prop = MSI_RecordGetString( rec, 9 );
2283 control->property = msi_dialog_dup_property( dialog, prop, FALSE );
2285 /* double click to activate an item in the list */
2286 SendMessageW( control->hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE,
2287 0, LVS_EX_TWOCLICKACTIVATE );
2289 msi_dialog_update_directory_list( dialog, control );
2291 return ERROR_SUCCESS;
2294 /******************** VolumeCost List ***************************************/
2296 static BOOL str_is_number( LPCWSTR str )
2300 for (i = 0; i < lstrlenW( str ); i++)
2301 if (!isdigitW(str[i]))
2307 WCHAR column_keys[][80] =
2309 {'V','o','l','u','m','e','C','o','s','t','V','o','l','u','m','e',0},
2310 {'V','o','l','u','m','e','C','o','s','t','S','i','z','e',0},
2311 {'V','o','l','u','m','e','C','o','s','t','A','v','a','i','l','a','b','l','e',0},
2312 {'V','o','l','u','m','e','C','o','s','t','R','e','q','u','i','r','e','d',0},
2313 {'V','o','l','u','m','e','C','o','s','t','D','i','f','f','e','r','e','n','c','e',0}
2316 static void msi_dialog_vcl_add_columns( msi_dialog *dialog, msi_control *control, MSIRECORD *rec )
2318 LPCWSTR text = MSI_RecordGetString( rec, 10 );
2319 LPCWSTR begin = text, end;
2324 static const WCHAR zero[] = {'0',0};
2325 static const WCHAR negative[] = {'-',0};
2327 while ((begin = strchrW( begin, '{' )) && count < 5)
2329 if (!(end = strchrW( begin, '}' )))
2332 lstrcpynW( num, begin + 1, end - begin );
2333 begin += end - begin + 1;
2335 /* empty braces or '0' hides the column */
2336 if ( !num[0] || !lstrcmpW( num, zero ) )
2342 /* the width must be a positive number
2343 * if a width is invalid, all remaining columns are hidden
2345 if ( !strncmpW( num, negative, 1 ) || !str_is_number( num ) )
2348 ZeroMemory( &lvc, sizeof(lvc) );
2349 lvc.mask = LVCF_TEXT | LVCF_WIDTH | LVCF_SUBITEM;
2350 lvc.cx = atolW( num );
2351 lvc.pszText = msi_dialog_get_uitext( dialog, column_keys[count] );
2353 SendMessageW( control->hwnd, LVM_INSERTCOLUMNW, count++, (LPARAM)&lvc );
2354 msi_free( lvc.pszText );
2358 static void msi_dialog_vcl_add_drives( msi_dialog *dialog, msi_control *control )
2360 ULARGE_INTEGER total, free;
2361 WCHAR size_text[MAX_PATH];
2367 size = GetLogicalDriveStringsW( 0, NULL );
2368 if ( !size ) return;
2370 drives = msi_alloc( (size + 1) * sizeof(WCHAR) );
2371 if ( !drives ) return;
2373 GetLogicalDriveStringsW( size, drives );
2378 lvitem.mask = LVIF_TEXT;
2380 lvitem.iSubItem = 0;
2381 lvitem.pszText = ptr;
2382 lvitem.cchTextMax = lstrlenW(ptr) + 1;
2383 SendMessageW( control->hwnd, LVM_INSERTITEMW, 0, (LPARAM)&lvitem );
2385 GetDiskFreeSpaceExW(ptr, &free, &total, NULL);
2387 StrFormatByteSizeW(total.QuadPart, size_text, MAX_PATH);
2388 lvitem.iSubItem = 1;
2389 lvitem.pszText = size_text;
2390 lvitem.cchTextMax = lstrlenW(size_text) + 1;
2391 SendMessageW( control->hwnd, LVM_SETITEMW, 0, (LPARAM)&lvitem );
2393 StrFormatByteSizeW(free.QuadPart, size_text, MAX_PATH);
2394 lvitem.iSubItem = 2;
2395 lvitem.pszText = size_text;
2396 lvitem.cchTextMax = lstrlenW(size_text) + 1;
2397 SendMessageW( control->hwnd, LVM_SETITEMW, 0, (LPARAM)&lvitem );
2399 ptr += lstrlenW(ptr) + 1;
2406 static UINT msi_dialog_volumecost_list( msi_dialog *dialog, MSIRECORD *rec )
2408 msi_control *control;
2411 style = LVS_REPORT | WS_VSCROLL | WS_HSCROLL | LVS_SHAREIMAGELISTS |
2412 LVS_AUTOARRANGE | LVS_SINGLESEL | WS_BORDER |
2413 WS_CHILD | WS_TABSTOP | WS_GROUP;
2414 control = msi_dialog_add_control( dialog, rec, WC_LISTVIEWW, style );
2416 return ERROR_FUNCTION_FAILED;
2418 msi_dialog_vcl_add_columns( dialog, control, rec );
2419 msi_dialog_vcl_add_drives( dialog, control );
2421 return ERROR_SUCCESS;
2424 static const struct control_handler msi_dialog_handler[] =
2426 { szText, msi_dialog_text_control },
2427 { szPushButton, msi_dialog_button_control },
2428 { szLine, msi_dialog_line_control },
2429 { szBitmap, msi_dialog_bitmap_control },
2430 { szCheckBox, msi_dialog_checkbox_control },
2431 { szScrollableText, msi_dialog_scrolltext_control },
2432 { szComboBox, msi_dialog_combo_control },
2433 { szEdit, msi_dialog_edit_control },
2434 { szMaskedEdit, msi_dialog_maskedit_control },
2435 { szPathEdit, msi_dialog_pathedit_control },
2436 { szProgressBar, msi_dialog_progress_bar },
2437 { szRadioButtonGroup, msi_dialog_radiogroup_control },
2438 { szIcon, msi_dialog_icon_control },
2439 { szSelectionTree, msi_dialog_selection_tree },
2440 { szGroupBox, msi_dialog_group_box },
2441 { szListBox, msi_dialog_list_box },
2442 { szDirectoryCombo, msi_dialog_directory_combo },
2443 { szDirectoryList, msi_dialog_directory_list },
2444 { szVolumeCostList, msi_dialog_volumecost_list },
2447 #define NUM_CONTROL_TYPES (sizeof msi_dialog_handler/sizeof msi_dialog_handler[0])
2449 static UINT msi_dialog_create_controls( MSIRECORD *rec, LPVOID param )
2451 msi_dialog *dialog = param;
2452 LPCWSTR control_type;
2455 /* find and call the function that can create this type of control */
2456 control_type = MSI_RecordGetString( rec, 3 );
2457 for( i=0; i<NUM_CONTROL_TYPES; i++ )
2458 if (!strcmpiW( msi_dialog_handler[i].control_type, control_type ))
2460 if( i != NUM_CONTROL_TYPES )
2461 msi_dialog_handler[i].func( dialog, rec );
2463 ERR("no handler for element type %s\n", debugstr_w(control_type));
2465 return ERROR_SUCCESS;
2468 static UINT msi_dialog_fill_controls( msi_dialog *dialog )
2470 static const WCHAR query[] = {
2471 'S','E','L','E','C','T',' ','*',' ',
2472 'F','R','O','M',' ','C','o','n','t','r','o','l',' ',
2473 'W','H','E','R','E',' ',
2474 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',0};
2476 MSIQUERY *view = NULL;
2477 MSIPACKAGE *package = dialog->package;
2479 TRACE("%p %s\n", dialog, debugstr_w(dialog->name) );
2481 /* query the Control table for all the elements of the control */
2482 r = MSI_OpenQuery( package->db, &view, query, dialog->name );
2483 if( r != ERROR_SUCCESS )
2485 ERR("query failed for dialog %s\n", debugstr_w(dialog->name));
2486 return ERROR_INVALID_PARAMETER;
2489 r = MSI_IterateRecords( view, 0, msi_dialog_create_controls, dialog );
2490 msiobj_release( &view->hdr );
2495 static UINT msi_dialog_set_control_condition( MSIRECORD *rec, LPVOID param )
2497 static const WCHAR szHide[] = { 'H','i','d','e',0 };
2498 static const WCHAR szShow[] = { 'S','h','o','w',0 };
2499 static const WCHAR szDisable[] = { 'D','i','s','a','b','l','e',0 };
2500 static const WCHAR szEnable[] = { 'E','n','a','b','l','e',0 };
2501 msi_dialog *dialog = param;
2502 msi_control *control;
2503 LPCWSTR name, action, condition;
2506 name = MSI_RecordGetString( rec, 2 );
2507 action = MSI_RecordGetString( rec, 3 );
2508 condition = MSI_RecordGetString( rec, 4 );
2509 r = MSI_EvaluateConditionW( dialog->package, condition );
2510 control = msi_dialog_find_control( dialog, name );
2511 if( r == MSICONDITION_TRUE && control )
2513 TRACE("%s control %s\n", debugstr_w(action), debugstr_w(name));
2515 /* FIXME: case sensitive? */
2516 if(!lstrcmpW(action, szHide))
2517 ShowWindow(control->hwnd, SW_HIDE);
2518 else if(!strcmpW(action, szShow))
2519 ShowWindow(control->hwnd, SW_SHOW);
2520 else if(!strcmpW(action, szDisable))
2521 EnableWindow(control->hwnd, FALSE);
2522 else if(!strcmpW(action, szEnable))
2523 EnableWindow(control->hwnd, TRUE);
2525 FIXME("Unhandled action %s\n", debugstr_w(action));
2528 return ERROR_SUCCESS;
2531 static UINT msi_dialog_evaluate_control_conditions( msi_dialog *dialog )
2533 static const WCHAR query[] = {
2534 'S','E','L','E','C','T',' ','*',' ',
2535 'F','R','O','M',' ',
2536 'C','o','n','t','r','o','l','C','o','n','d','i','t','i','o','n',' ',
2537 'W','H','E','R','E',' ',
2538 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',0
2541 MSIQUERY *view = NULL;
2542 MSIPACKAGE *package = dialog->package;
2544 TRACE("%p %s\n", dialog, debugstr_w(dialog->name) );
2546 /* query the Control table for all the elements of the control */
2547 r = MSI_OpenQuery( package->db, &view, query, dialog->name );
2548 if( r != ERROR_SUCCESS )
2549 return ERROR_SUCCESS;
2551 r = MSI_IterateRecords( view, 0, msi_dialog_set_control_condition, dialog );
2552 msiobj_release( &view->hdr );
2557 UINT msi_dialog_reset( msi_dialog *dialog )
2559 /* FIXME: should restore the original values of any properties we changed */
2560 return msi_dialog_evaluate_control_conditions( dialog );
2563 /* figure out the height of 10 point MS Sans Serif */
2564 static INT msi_dialog_get_sans_serif_height( HWND hwnd )
2566 static const WCHAR szSansSerif[] = {
2567 'M','S',' ','S','a','n','s',' ','S','e','r','i','f',0 };
2572 HFONT hFont, hOldFont;
2575 hdc = GetDC( hwnd );
2578 memset( &lf, 0, sizeof lf );
2579 lf.lfHeight = MulDiv(10, GetDeviceCaps(hdc, LOGPIXELSY), 72);
2580 strcpyW( lf.lfFaceName, szSansSerif );
2581 hFont = CreateFontIndirectW(&lf);
2584 hOldFont = SelectObject( hdc, hFont );
2585 r = GetTextMetricsW( hdc, &tm );
2587 height = tm.tmHeight;
2588 SelectObject( hdc, hOldFont );
2589 DeleteObject( hFont );
2591 ReleaseDC( hwnd, hdc );
2596 /* fetch the associated record from the Dialog table */
2597 static MSIRECORD *msi_get_dialog_record( msi_dialog *dialog )
2599 static const WCHAR query[] = {
2600 'S','E','L','E','C','T',' ','*',' ',
2601 'F','R','O','M',' ','D','i','a','l','o','g',' ',
2602 'W','H','E','R','E',' ',
2603 '`','D','i','a','l','o','g','`',' ','=',' ','\'','%','s','\'',0};
2604 MSIPACKAGE *package = dialog->package;
2605 MSIRECORD *rec = NULL;
2607 TRACE("%p %s\n", dialog, debugstr_w(dialog->name) );
2609 rec = MSI_QueryGetRecord( package->db, query, dialog->name );
2611 ERR("query failed for dialog %s\n", debugstr_w(dialog->name));
2616 static void msi_dialog_adjust_dialog_pos( msi_dialog *dialog, MSIRECORD *rec, LPRECT pos )
2618 static const WCHAR szScreenX[] = {'S','c','r','e','e','n','X',0};
2619 static const WCHAR szScreenY[] = {'S','c','r','e','e','n','Y',0};
2626 center.x = MSI_RecordGetInteger( rec, 2 );
2627 center.y = MSI_RecordGetInteger( rec, 3 );
2629 sz.cx = MSI_RecordGetInteger( rec, 4 );
2630 sz.cy = MSI_RecordGetInteger( rec, 5 );
2632 sz.cx = msi_dialog_scale_unit( dialog, sz.cx );
2633 sz.cy = msi_dialog_scale_unit( dialog, sz.cy );
2635 xres = msi_get_property_int( dialog->package, szScreenX, 0 );
2636 yres = msi_get_property_int( dialog->package, szScreenY, 0 );
2638 center.x = MulDiv( center.x, xres, 100 );
2639 center.y = MulDiv( center.y, yres, 100 );
2641 /* turn the client pos into the window rectangle */
2642 if (dialog->package->center_x && dialog->package->center_y)
2644 pos->left = dialog->package->center_x - sz.cx / 2.0;
2645 pos->right = pos->left + sz.cx;
2646 pos->top = dialog->package->center_y - sz.cy / 2.0;
2647 pos->bottom = pos->top + sz.cy;
2651 pos->left = center.x - sz.cx/2;
2652 pos->right = pos->left + sz.cx;
2653 pos->top = center.y - sz.cy/2;
2654 pos->bottom = pos->top + sz.cy;
2656 /* save the center */
2657 dialog->package->center_x = center.x;
2658 dialog->package->center_y = center.y;
2661 dialog->size.cx = sz.cx;
2662 dialog->size.cy = sz.cy;
2664 TRACE("%lu %lu %lu %lu\n", pos->left, pos->top, pos->right, pos->bottom);
2666 style = GetWindowLongPtrW( dialog->hwnd, GWL_STYLE );
2667 AdjustWindowRect( pos, style, FALSE );
2670 static BOOL msi_control_set_next( msi_control *control, msi_control *next )
2672 return SetWindowPos( next->hwnd, control->hwnd, 0, 0, 0, 0,
2673 SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOREDRAW |
2674 SWP_NOREPOSITION | SWP_NOSENDCHANGING | SWP_NOSIZE );
2677 static UINT msi_dialog_set_tab_order( msi_dialog *dialog )
2679 msi_control *control, *tab_next;
2681 LIST_FOR_EACH_ENTRY( control, &dialog->controls, msi_control, entry )
2683 tab_next = msi_dialog_find_control( dialog, control->tabnext );
2686 msi_control_set_next( control, tab_next );
2689 return ERROR_SUCCESS;
2692 static void msi_dialog_set_first_control( msi_dialog* dialog, LPCWSTR name )
2694 msi_control *control;
2696 control = msi_dialog_find_control( dialog, name );
2698 dialog->hWndFocus = control->hwnd;
2700 dialog->hWndFocus = NULL;
2703 static LRESULT msi_dialog_oncreate( HWND hwnd, LPCREATESTRUCTW cs )
2705 static const WCHAR df[] = {
2706 'D','e','f','a','u','l','t','U','I','F','o','n','t',0 };
2707 static const WCHAR dfv[] = {
2708 'M','S',' ','S','h','e','l','l',' ','D','l','g',0 };
2709 msi_dialog *dialog = (msi_dialog*) cs->lpCreateParams;
2710 MSIRECORD *rec = NULL;
2711 LPWSTR title = NULL;
2714 TRACE("%p %p\n", dialog, dialog->package);
2716 dialog->hwnd = hwnd;
2717 SetWindowLongPtrW( hwnd, GWLP_USERDATA, (LONG_PTR) dialog );
2719 rec = msi_get_dialog_record( dialog );
2722 TRACE("No record found for dialog %s\n", debugstr_w(dialog->name));
2726 dialog->scale = msi_dialog_get_sans_serif_height(dialog->hwnd);
2728 msi_dialog_adjust_dialog_pos( dialog, rec, &pos );
2730 dialog->attributes = MSI_RecordGetInteger( rec, 6 );
2732 dialog->default_font = msi_dup_property( dialog->package, df );
2733 if (!dialog->default_font)
2735 dialog->default_font = strdupW(dfv);
2736 if (!dialog->default_font) return -1;
2739 title = msi_get_deformatted_field( dialog->package, rec, 7 );
2740 SetWindowTextW( hwnd, title );
2743 SetWindowPos( hwnd, 0, pos.left, pos.top,
2744 pos.right - pos.left, pos.bottom - pos.top,
2745 SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOREDRAW );
2747 msi_dialog_build_font_list( dialog );
2748 msi_dialog_fill_controls( dialog );
2749 msi_dialog_evaluate_control_conditions( dialog );
2750 msi_dialog_set_tab_order( dialog );
2751 msi_dialog_set_first_control( dialog, MSI_RecordGetString( rec, 8 ) );
2752 msiobj_release( &rec->hdr );
2757 static UINT msi_dialog_send_event( msi_dialog *dialog, LPCWSTR event, LPCWSTR arg )
2759 LPWSTR event_fmt = NULL, arg_fmt = NULL;
2761 TRACE("Sending control event %s %s\n", debugstr_w(event), debugstr_w(arg));
2763 deformat_string( dialog->package, event, &event_fmt );
2764 deformat_string( dialog->package, arg, &arg_fmt );
2766 dialog->event_handler( dialog->package, event_fmt, arg_fmt, dialog );
2768 msi_free( event_fmt );
2769 msi_free( arg_fmt );
2771 return ERROR_SUCCESS;
2774 static UINT msi_dialog_set_property( msi_dialog *dialog, LPCWSTR event, LPCWSTR arg )
2776 static const WCHAR szNullArg[] = { '{','}',0 };
2777 LPWSTR p, prop, arg_fmt = NULL;
2780 len = strlenW(event);
2781 prop = msi_alloc( len*sizeof(WCHAR));
2782 strcpyW( prop, &event[1] );
2783 p = strchrW( prop, ']' );
2784 if( p && p[1] == 0 )
2787 if( strcmpW( szNullArg, arg ) )
2788 deformat_string( dialog->package, arg, &arg_fmt );
2789 MSI_SetPropertyW( dialog->package, prop, arg_fmt );
2790 msi_free( arg_fmt );
2793 ERR("Badly formatted property string - what happens?\n");
2795 return ERROR_SUCCESS;
2798 static UINT msi_dialog_control_event( MSIRECORD *rec, LPVOID param )
2800 msi_dialog *dialog = param;
2801 LPCWSTR condition, event, arg;
2804 condition = MSI_RecordGetString( rec, 5 );
2805 r = MSI_EvaluateConditionW( dialog->package, condition );
2806 if( r == MSICONDITION_TRUE || r == MSICONDITION_NONE )
2808 event = MSI_RecordGetString( rec, 3 );
2809 arg = MSI_RecordGetString( rec, 4 );
2810 if( event[0] == '[' )
2811 msi_dialog_set_property( dialog, event, arg );
2813 msi_dialog_send_event( dialog, event, arg );
2816 return ERROR_SUCCESS;
2819 static UINT msi_dialog_button_handler( msi_dialog *dialog,
2820 msi_control *control, WPARAM param )
2822 static const WCHAR query[] = {
2823 'S','E','L','E','C','T',' ','*',' ',
2824 'F','R','O','M',' ','C','o','n','t','r','o','l','E','v','e','n','t',' ',
2825 'W','H','E','R','E',' ',
2826 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',' ',
2828 '`','C','o','n','t','r','o','l','_','`',' ','=',' ','\'','%','s','\'',' ',
2829 'O','R','D','E','R',' ','B','Y',' ','`','O','r','d','e','r','i','n','g','`',0
2831 MSIQUERY *view = NULL;
2834 if( HIWORD(param) != BN_CLICKED )
2835 return ERROR_SUCCESS;
2837 r = MSI_OpenQuery( dialog->package->db, &view, query,
2838 dialog->name, control->name );
2839 if( r != ERROR_SUCCESS )
2841 ERR("query failed\n");
2845 r = MSI_IterateRecords( view, 0, msi_dialog_control_event, dialog );
2846 msiobj_release( &view->hdr );
2851 static UINT msi_dialog_get_checkbox_state( msi_dialog *dialog,
2852 msi_control *control )
2854 WCHAR state[2] = { 0 };
2857 MSI_GetPropertyW( dialog->package, control->property, state, &sz );
2858 return state[0] ? 1 : 0;
2861 static void msi_dialog_set_checkbox_state( msi_dialog *dialog,
2862 msi_control *control, UINT state )
2864 static const WCHAR szState[] = { '1', 0 };
2867 /* if uncheck then the property is set to NULL */
2870 MSI_SetPropertyW( dialog->package, control->property, NULL );
2874 /* check for a custom state */
2875 if (control->value && control->value[0])
2876 val = control->value;
2880 MSI_SetPropertyW( dialog->package, control->property, val );
2883 static void msi_dialog_checkbox_sync_state( msi_dialog *dialog,
2884 msi_control *control )
2888 state = msi_dialog_get_checkbox_state( dialog, control );
2889 SendMessageW( control->hwnd, BM_SETCHECK,
2890 state ? BST_CHECKED : BST_UNCHECKED, 0 );
2893 static UINT msi_dialog_checkbox_handler( msi_dialog *dialog,
2894 msi_control *control, WPARAM param )
2898 if( HIWORD(param) != BN_CLICKED )
2899 return ERROR_SUCCESS;
2901 TRACE("clicked checkbox %s, set %s\n", debugstr_w(control->name),
2902 debugstr_w(control->property));
2904 state = msi_dialog_get_checkbox_state( dialog, control );
2905 state = state ? 0 : 1;
2906 msi_dialog_set_checkbox_state( dialog, control, state );
2907 msi_dialog_checkbox_sync_state( dialog, control );
2909 return msi_dialog_button_handler( dialog, control, param );
2912 static UINT msi_dialog_edit_handler( msi_dialog *dialog,
2913 msi_control *control, WPARAM param )
2917 if( HIWORD(param) != EN_CHANGE )
2918 return ERROR_SUCCESS;
2920 TRACE("edit %s contents changed, set %s\n", debugstr_w(control->name),
2921 debugstr_w(control->property));
2923 buf = msi_get_window_text( control->hwnd );
2924 MSI_SetPropertyW( dialog->package, control->property, buf );
2928 return ERROR_SUCCESS;
2931 static UINT msi_dialog_radiogroup_handler( msi_dialog *dialog,
2932 msi_control *control, WPARAM param )
2934 if( HIWORD(param) != BN_CLICKED )
2935 return ERROR_SUCCESS;
2937 TRACE("clicked radio button %s, set %s\n", debugstr_w(control->name),
2938 debugstr_w(control->property));
2940 MSI_SetPropertyW( dialog->package, control->property, control->name );
2942 return msi_dialog_button_handler( dialog, control, param );
2945 static LRESULT msi_dialog_oncommand( msi_dialog *dialog, WPARAM param, HWND hwnd )
2947 msi_control *control = NULL;
2949 TRACE("%p %p %08x\n", dialog, hwnd, param);
2954 control = msi_dialog_find_control( dialog, dialog->control_default );
2956 case 2: /* escape */
2957 control = msi_dialog_find_control( dialog, dialog->control_cancel );
2960 control = msi_dialog_find_control_by_hwnd( dialog, hwnd );
2965 if( control->handler )
2967 control->handler( dialog, control, param );
2968 msi_dialog_evaluate_control_conditions( dialog );
2972 ERR("button click from nowhere %p %d %p\n", dialog, param, hwnd);
2976 static LRESULT msi_dialog_onnotify( msi_dialog *dialog, LPARAM param )
2978 LPNMHDR nmhdr = (LPNMHDR) param;
2979 msi_control *control = msi_dialog_find_control_by_hwnd( dialog, nmhdr->hwndFrom );
2981 TRACE("%p %p\n", dialog, nmhdr->hwndFrom);
2983 if ( control && control->handler )
2984 control->handler( dialog, control, param );
2989 static void msi_dialog_setfocus( msi_dialog *dialog )
2991 HWND hwnd = dialog->hWndFocus;
2993 hwnd = GetNextDlgTabItem( dialog->hwnd, hwnd, TRUE);
2994 hwnd = GetNextDlgTabItem( dialog->hwnd, hwnd, FALSE);
2996 dialog->hWndFocus = hwnd;
2999 static LRESULT WINAPI MSIDialog_WndProc( HWND hwnd, UINT msg,
3000 WPARAM wParam, LPARAM lParam )
3002 msi_dialog *dialog = (LPVOID) GetWindowLongPtrW( hwnd, GWLP_USERDATA );
3004 TRACE("0x%04x\n", msg);
3009 dialog->package->center_x = LOWORD(lParam) + dialog->size.cx / 2.0;
3010 dialog->package->center_y = HIWORD(lParam) + dialog->size.cy / 2.0;
3014 return msi_dialog_oncreate( hwnd, (LPCREATESTRUCTW)lParam );
3017 return msi_dialog_oncommand( dialog, wParam, (HWND)lParam );
3020 if( LOWORD(wParam) == WA_INACTIVE )
3021 dialog->hWndFocus = GetFocus();
3023 msi_dialog_setfocus( dialog );
3027 msi_dialog_setfocus( dialog );
3030 /* bounce back to our subclassed static control */
3031 case WM_CTLCOLORSTATIC:
3032 return SendMessageW( (HWND) lParam, WM_CTLCOLORSTATIC, wParam, lParam );
3035 dialog->hwnd = NULL;
3038 return msi_dialog_onnotify( dialog, lParam );
3040 return DefWindowProcW(hwnd, msg, wParam, lParam);
3043 static BOOL CALLBACK msi_radioground_child_enum( HWND hWnd, LPARAM lParam )
3045 EnableWindow( hWnd, lParam );
3049 static LRESULT WINAPI MSIRadioGroup_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
3051 WNDPROC oldproc = (WNDPROC) GetPropW(hWnd, szButtonData);
3054 TRACE("hWnd %p msg %04x wParam 0x%08x lParam 0x%08lx\n", hWnd, msg, wParam, lParam);
3056 if (msg == WM_COMMAND) /* Forward notifications to dialog */
3057 SendMessageW(GetParent(hWnd), msg, wParam, lParam);
3059 r = CallWindowProcW(oldproc, hWnd, msg, wParam, lParam);
3061 /* make sure the radio buttons show as disabled if the parent is disabled */
3062 if (msg == WM_ENABLE)
3063 EnumChildWindows( hWnd, msi_radioground_child_enum, wParam );
3068 static LRESULT WINAPI MSIHiddenWindowProc( HWND hwnd, UINT msg,
3069 WPARAM wParam, LPARAM lParam )
3071 msi_dialog *dialog = (msi_dialog*) lParam;
3073 TRACE("%d %p\n", msg, dialog);
3077 case WM_MSI_DIALOG_CREATE:
3078 return msi_dialog_run_message_loop( dialog );
3079 case WM_MSI_DIALOG_DESTROY:
3080 msi_dialog_destroy( dialog );
3083 return DefWindowProcW( hwnd, msg, wParam, lParam );
3086 /* functions that interface to other modules within MSI */
3088 msi_dialog *msi_dialog_create( MSIPACKAGE* package,
3089 LPCWSTR szDialogName, msi_dialog *parent,
3090 msi_dialog_event_handler event_handler )
3092 MSIRECORD *rec = NULL;
3095 TRACE("%p %s\n", package, debugstr_w(szDialogName));
3097 /* allocate the structure for the dialog to use */
3098 dialog = msi_alloc_zero( sizeof *dialog + sizeof(WCHAR)*strlenW(szDialogName) );
3101 strcpyW( dialog->name, szDialogName );
3102 dialog->parent = parent;
3103 msiobj_addref( &package->hdr );
3104 dialog->package = package;
3105 dialog->event_handler = event_handler;
3106 dialog->finished = 0;
3107 list_init( &dialog->controls );
3109 /* verify that the dialog exists */
3110 rec = msi_get_dialog_record( dialog );
3113 msiobj_release( &package->hdr );
3117 dialog->attributes = MSI_RecordGetInteger( rec, 6 );
3118 dialog->control_default = strdupW( MSI_RecordGetString( rec, 9 ) );
3119 dialog->control_cancel = strdupW( MSI_RecordGetString( rec, 10 ) );
3120 msiobj_release( &rec->hdr );
3125 static void msi_process_pending_messages( HWND hdlg )
3129 while( PeekMessageW( &msg, 0, 0, 0, PM_REMOVE ) )
3131 if( hdlg && IsDialogMessageW( hdlg, &msg ))
3133 TranslateMessage( &msg );
3134 DispatchMessageW( &msg );
3138 void msi_dialog_end_dialog( msi_dialog *dialog )
3140 TRACE("%p\n", dialog);
3141 dialog->finished = 1;
3142 PostMessageW(dialog->hwnd, WM_NULL, 0, 0);
3145 void msi_dialog_check_messages( HANDLE handle )
3149 /* in threads other than the UI thread, block */
3150 if( uiThreadId != GetCurrentThreadId() )
3153 WaitForSingleObject( handle, INFINITE );
3157 /* there's two choices for the UI thread */
3160 msi_process_pending_messages( NULL );
3166 * block here until somebody creates a new dialog or
3167 * the handle we're waiting on becomes ready
3169 r = MsgWaitForMultipleObjects( 1, &handle, 0, INFINITE, QS_ALLINPUT );
3170 if( r == WAIT_OBJECT_0 )
3175 UINT msi_dialog_run_message_loop( msi_dialog *dialog )
3180 if( uiThreadId != GetCurrentThreadId() )
3181 return SendMessageW( hMsiHiddenWindow, WM_MSI_DIALOG_CREATE, 0, (LPARAM) dialog );
3183 /* create the dialog window, don't show it yet */
3184 style = WS_OVERLAPPED;
3185 if( dialog->attributes & msidbDialogAttributesVisible )
3186 style |= WS_VISIBLE;
3188 hwnd = CreateWindowW( szMsiDialogClass, dialog->name, style,
3189 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
3190 NULL, NULL, NULL, dialog );
3193 ERR("Failed to create dialog %s\n", debugstr_w( dialog->name ));
3194 return ERROR_FUNCTION_FAILED;
3197 ShowWindow( hwnd, SW_SHOW );
3198 /* UpdateWindow( hwnd ); - and causes the transparent static controls not to paint */
3200 if( dialog->attributes & msidbDialogAttributesModal )
3202 while( !dialog->finished )
3204 MsgWaitForMultipleObjects( 0, NULL, 0, INFINITE, QS_ALLINPUT );
3205 msi_process_pending_messages( dialog->hwnd );
3209 return ERROR_IO_PENDING;
3211 return ERROR_SUCCESS;
3214 void msi_dialog_do_preview( msi_dialog *dialog )
3217 dialog->attributes |= msidbDialogAttributesVisible;
3218 dialog->attributes &= ~msidbDialogAttributesModal;
3219 msi_dialog_run_message_loop( dialog );
3222 void msi_dialog_destroy( msi_dialog *dialog )
3224 if( uiThreadId != GetCurrentThreadId() )
3226 SendMessageW( hMsiHiddenWindow, WM_MSI_DIALOG_DESTROY, 0, (LPARAM) dialog );
3231 ShowWindow( dialog->hwnd, SW_HIDE );
3234 DestroyWindow( dialog->hwnd );
3236 /* destroy the list of controls */
3237 while( !list_empty( &dialog->controls ) )
3239 msi_control *t = LIST_ENTRY( list_head( &dialog->controls ),
3240 msi_control, entry );
3241 list_remove( &t->entry );
3242 /* leave dialog->hwnd - destroying parent destroys child windows */
3243 msi_free( t->property );
3244 msi_free( t->value );
3246 DeleteObject( t->hBitmap );
3248 DestroyIcon( t->hIcon );
3249 msi_free( t->tabnext );
3250 msi_free( t->type );
3253 FreeLibrary( t->hDll );
3256 /* destroy the list of fonts */
3257 while( dialog->font_list )
3259 msi_font *t = dialog->font_list;
3260 dialog->font_list = t->next;
3261 DeleteObject( t->hfont );
3264 msi_free( dialog->default_font );
3266 msi_free( dialog->control_default );
3267 msi_free( dialog->control_cancel );
3268 msiobj_release( &dialog->package->hdr );
3269 dialog->package = NULL;
3273 BOOL msi_dialog_register_class( void )
3277 ZeroMemory( &cls, sizeof cls );
3278 cls.lpfnWndProc = MSIDialog_WndProc;
3279 cls.hInstance = NULL;
3280 cls.hIcon = LoadIconW(0, (LPWSTR)IDI_APPLICATION);
3281 cls.hCursor = LoadCursorW(0, (LPWSTR)IDC_ARROW);
3282 cls.hbrBackground = (HBRUSH)(COLOR_3DFACE + 1);
3283 cls.lpszMenuName = NULL;
3284 cls.lpszClassName = szMsiDialogClass;
3286 if( !RegisterClassW( &cls ) )
3289 cls.lpfnWndProc = MSIHiddenWindowProc;
3290 cls.lpszClassName = szMsiHiddenWindow;
3292 if( !RegisterClassW( &cls ) )
3295 uiThreadId = GetCurrentThreadId();
3297 hMsiHiddenWindow = CreateWindowW( szMsiHiddenWindow, NULL, WS_OVERLAPPED,
3298 0, 0, 100, 100, NULL, NULL, NULL, NULL );
3299 if( !hMsiHiddenWindow )
3305 void msi_dialog_unregister_class( void )
3307 DestroyWindow( hMsiHiddenWindow );
3308 hMsiHiddenWindow = NULL;
3309 UnregisterClassW( szMsiDialogClass, NULL );
3310 UnregisterClassW( szMsiHiddenWindow, NULL );