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;
85 msi_dialog_event_handler event_handler;
95 LPWSTR control_default;
96 LPWSTR control_cancel;
100 typedef UINT (*msi_dialog_control_func)( msi_dialog *dialog, MSIRECORD *rec );
101 struct control_handler
103 LPCWSTR control_type;
104 msi_dialog_control_func func;
113 } radio_button_group_descr;
115 static const WCHAR szMsiDialogClass[] = {
116 'M','s','i','D','i','a','l','o','g','C','l','o','s','e','C','l','a','s','s',0
118 static const WCHAR szMsiHiddenWindow[] = {
119 'M','s','i','H','i','d','d','e','n','W','i','n','d','o','w',0 };
120 static const WCHAR szStatic[] = { 'S','t','a','t','i','c',0 };
121 static const WCHAR szButton[] = { 'B','U','T','T','O','N', 0 };
122 static const WCHAR szButtonData[] = { 'M','S','I','D','A','T','A',0 };
123 static const WCHAR szProgress[] = { 'P','r','o','g','r','e','s','s',0 };
124 static const WCHAR szText[] = { 'T','e','x','t',0 };
125 static const WCHAR szPushButton[] = { 'P','u','s','h','B','u','t','t','o','n',0 };
126 static const WCHAR szLine[] = { 'L','i','n','e',0 };
127 static const WCHAR szBitmap[] = { 'B','i','t','m','a','p',0 };
128 static const WCHAR szCheckBox[] = { 'C','h','e','c','k','B','o','x',0 };
129 static const WCHAR szScrollableText[] = {
130 'S','c','r','o','l','l','a','b','l','e','T','e','x','t',0 };
131 static const WCHAR szComboBox[] = { 'C','o','m','b','o','B','o','x',0 };
132 static const WCHAR szEdit[] = { 'E','d','i','t',0 };
133 static const WCHAR szMaskedEdit[] = { 'M','a','s','k','e','d','E','d','i','t',0 };
134 static const WCHAR szPathEdit[] = { 'P','a','t','h','E','d','i','t',0 };
135 static const WCHAR szProgressBar[] = {
136 'P','r','o','g','r','e','s','s','B','a','r',0 };
137 static const WCHAR szRadioButtonGroup[] = {
138 'R','a','d','i','o','B','u','t','t','o','n','G','r','o','u','p',0 };
139 static const WCHAR szIcon[] = { 'I','c','o','n',0 };
140 static const WCHAR szSelectionTree[] = {
141 'S','e','l','e','c','t','i','o','n','T','r','e','e',0 };
142 static const WCHAR szGroupBox[] = { 'G','r','o','u','p','B','o','x',0 };
143 static const WCHAR szListBox[] = { 'L','i','s','t','B','o','x',0 };
144 static const WCHAR szDirectoryCombo[] = { 'D','i','r','e','c','t','o','r','y','C','o','m','b','o',0 };
145 static const WCHAR szDirectoryList[] = { 'D','i','r','e','c','t','o','r','y','L','i','s','t',0 };
146 static const WCHAR szVolumeCostList[] = { 'V','o','l','u','m','e','C','o','s','t','L','i','s','t',0 };
148 static UINT msi_dialog_checkbox_handler( msi_dialog *, msi_control *, WPARAM );
149 static void msi_dialog_checkbox_sync_state( msi_dialog *, msi_control * );
150 static UINT msi_dialog_button_handler( msi_dialog *, msi_control *, WPARAM );
151 static UINT msi_dialog_edit_handler( msi_dialog *, msi_control *, WPARAM );
152 static UINT msi_dialog_radiogroup_handler( msi_dialog *, msi_control *, WPARAM param );
153 static UINT msi_dialog_evaluate_control_conditions( msi_dialog *dialog );
154 static LRESULT WINAPI MSIRadioGroup_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
157 /* dialog sequencing */
159 #define WM_MSI_DIALOG_CREATE (WM_USER+0x100)
160 #define WM_MSI_DIALOG_DESTROY (WM_USER+0x101)
162 static DWORD uiThreadId;
163 static HWND hMsiHiddenWindow;
165 static INT msi_dialog_scale_unit( msi_dialog *dialog, INT val )
167 return (dialog->scale * val + 5) / 10;
170 static msi_control *msi_dialog_find_control( msi_dialog *dialog, LPCWSTR name )
172 msi_control *control;
176 LIST_FOR_EACH_ENTRY( control, &dialog->controls, msi_control, entry )
177 if( !strcmpW( control->name, name ) ) /* FIXME: case sensitive? */
182 static msi_control *msi_dialog_find_control_by_type( msi_dialog *dialog, LPCWSTR type )
184 msi_control *control;
188 LIST_FOR_EACH_ENTRY( control, &dialog->controls, msi_control, entry )
189 if( !strcmpW( control->type, type ) ) /* FIXME: case sensitive? */
194 static msi_control *msi_dialog_find_control_by_hwnd( msi_dialog *dialog, HWND hwnd )
196 msi_control *control;
198 LIST_FOR_EACH_ENTRY( control, &dialog->controls, msi_control, entry )
199 if( hwnd == control->hwnd )
204 static LPWSTR msi_get_deformatted_field( MSIPACKAGE *package, MSIRECORD *rec, int field )
206 LPCWSTR str = MSI_RecordGetString( rec, field );
210 deformat_string( package, str, &ret );
214 static LPWSTR msi_dialog_dup_property( msi_dialog *dialog, LPCWSTR property, BOOL indirect )
220 return msi_dup_property( dialog->package, property );
222 return strdupW( property );
226 * msi_dialog_get_style
228 * Extract the {\style} string from the front of the text to display and
229 * update the pointer.
231 static LPWSTR msi_dialog_get_style( LPCWSTR p, LPCWSTR *rest )
242 q = strchrW( p, '}' );
245 if( *p == '\\' || *p == '&' )
248 /* little bit of sanity checking to stop us getting confused with RTF */
250 if( *i == '}' || *i == '\\' )
256 ret = msi_alloc( len*sizeof(WCHAR) );
259 memcpy( ret, p, len*sizeof(WCHAR) );
264 static UINT msi_dialog_add_font( MSIRECORD *rec, LPVOID param )
266 msi_dialog *dialog = param;
273 /* create a font and add it to the list */
274 name = MSI_RecordGetString( rec, 1 );
275 font = msi_alloc( sizeof *font + strlenW( name )*sizeof (WCHAR) );
276 strcpyW( font->name, name );
277 font->next = dialog->font_list;
278 dialog->font_list = font;
280 font->color = MSI_RecordGetInteger( rec, 4 );
282 memset( &lf, 0, sizeof lf );
283 face = MSI_RecordGetString( rec, 2 );
284 lf.lfHeight = MSI_RecordGetInteger( rec, 3 );
285 style = MSI_RecordGetInteger( rec, 5 );
286 if( style & msidbTextStyleStyleBitsBold )
287 lf.lfWeight = FW_BOLD;
288 if( style & msidbTextStyleStyleBitsItalic )
290 if( style & msidbTextStyleStyleBitsUnderline )
291 lf.lfUnderline = TRUE;
292 if( style & msidbTextStyleStyleBitsStrike )
293 lf.lfStrikeOut = TRUE;
294 lstrcpynW( lf.lfFaceName, face, LF_FACESIZE );
296 /* adjust the height */
297 hdc = GetDC( dialog->hwnd );
300 lf.lfHeight = -MulDiv(lf.lfHeight, GetDeviceCaps(hdc, LOGPIXELSY), 72);
301 ReleaseDC( dialog->hwnd, hdc );
304 font->hfont = CreateFontIndirectW( &lf );
306 TRACE("Adding font style %s\n", debugstr_w(font->name) );
308 return ERROR_SUCCESS;
311 static msi_font *msi_dialog_find_font( msi_dialog *dialog, LPCWSTR name )
315 for( font = dialog->font_list; font; font = font->next )
316 if( !strcmpW( font->name, name ) ) /* FIXME: case sensitive? */
322 static UINT msi_dialog_set_font( msi_dialog *dialog, HWND hwnd, LPCWSTR name )
326 font = msi_dialog_find_font( dialog, name );
328 SendMessageW( hwnd, WM_SETFONT, (WPARAM) font->hfont, TRUE );
330 ERR("No font entry for %s\n", debugstr_w(name));
331 return ERROR_SUCCESS;
334 static UINT msi_dialog_build_font_list( msi_dialog *dialog )
336 static const WCHAR query[] = {
337 'S','E','L','E','C','T',' ','*',' ',
338 'F','R','O','M',' ','`','T','e','x','t','S','t','y','l','e','`',' ',0
341 MSIQUERY *view = NULL;
343 TRACE("dialog %p\n", dialog );
345 r = MSI_OpenQuery( dialog->package->db, &view, query );
346 if( r != ERROR_SUCCESS )
349 r = MSI_IterateRecords( view, NULL, msi_dialog_add_font, dialog );
350 msiobj_release( &view->hdr );
355 static msi_control *msi_dialog_create_window( msi_dialog *dialog,
356 MSIRECORD *rec, DWORD exstyle, LPCWSTR szCls, LPCWSTR name, LPCWSTR text,
357 DWORD style, HWND parent )
359 DWORD x, y, width, height;
360 LPWSTR font = NULL, title_font = NULL;
361 LPCWSTR title = NULL;
362 msi_control *control;
366 control = msi_alloc( sizeof *control + strlenW(name)*sizeof(WCHAR) );
367 strcpyW( control->name, name );
368 list_add_head( &dialog->controls, &control->entry );
369 control->handler = NULL;
370 control->property = NULL;
371 control->value = NULL;
372 control->hBitmap = NULL;
373 control->hIcon = NULL;
374 control->hDll = NULL;
375 control->tabnext = strdupW( MSI_RecordGetString( rec, 11) );
376 control->type = strdupW( MSI_RecordGetString( rec, 3 ) );
377 control->progress_current = 0;
378 control->progress_max = 100;
380 x = MSI_RecordGetInteger( rec, 4 );
381 y = MSI_RecordGetInteger( rec, 5 );
382 width = MSI_RecordGetInteger( rec, 6 );
383 height = MSI_RecordGetInteger( rec, 7 );
385 x = msi_dialog_scale_unit( dialog, x );
386 y = msi_dialog_scale_unit( dialog, y );
387 width = msi_dialog_scale_unit( dialog, width );
388 height = msi_dialog_scale_unit( dialog, height );
392 deformat_string( dialog->package, text, &title_font );
393 font = msi_dialog_get_style( title_font, &title );
396 control->hwnd = CreateWindowExW( exstyle, szCls, title, style,
397 x, y, width, height, parent, NULL, NULL, NULL );
399 TRACE("Dialog %s control %s hwnd %p\n",
400 debugstr_w(dialog->name), debugstr_w(text), control->hwnd );
402 msi_dialog_set_font( dialog, control->hwnd,
403 font ? font : dialog->default_font );
405 msi_free( title_font );
411 static LPWSTR msi_dialog_get_uitext( msi_dialog *dialog, LPCWSTR key )
416 static const WCHAR query[] = {
417 's','e','l','e','c','t',' ','*',' ',
418 'f','r','o','m',' ','`','U','I','T','e','x','t','`',' ',
419 'w','h','e','r','e',' ','`','K','e','y','`',' ','=',' ','\'','%','s','\'',0
422 rec = MSI_QueryGetRecord( dialog->package->db, query, key );
423 if (!rec) return NULL;
424 text = strdupW( MSI_RecordGetString( rec, 2 ) );
425 msiobj_release( &rec->hdr );
429 static MSIRECORD *msi_get_binary_record( MSIDATABASE *db, LPCWSTR name )
431 static const WCHAR query[] = {
432 's','e','l','e','c','t',' ','*',' ',
433 'f','r','o','m',' ','B','i','n','a','r','y',' ',
434 'w','h','e','r','e',' ',
435 '`','N','a','m','e','`',' ','=',' ','\'','%','s','\'',0
438 return MSI_QueryGetRecord( db, query, name );
441 static LPWSTR msi_create_tmp_path(void)
445 static const WCHAR prefix[] = { 'm','s','i',0 };
448 r = GetTempPathW( MAX_PATH, tmp );
451 len = lstrlenW( tmp ) + 20;
452 path = msi_alloc( len * sizeof (WCHAR) );
455 r = GetTempFileNameW( tmp, prefix, 0, path );
466 static HANDLE msi_load_image( MSIDATABASE *db, LPCWSTR name, UINT type,
467 UINT cx, UINT cy, UINT flags )
469 MSIRECORD *rec = NULL;
470 HANDLE himage = NULL;
474 TRACE("%p %s %u %u %08x\n", db, debugstr_w(name), cx, cy, flags);
476 tmp = msi_create_tmp_path();
480 rec = msi_get_binary_record( db, name );
483 r = MSI_RecordStreamToFile( rec, 2, tmp );
484 if( r == ERROR_SUCCESS )
486 himage = LoadImageW( 0, tmp, type, cx, cy, flags );
489 msiobj_release( &rec->hdr );
496 static HICON msi_load_icon( MSIDATABASE *db, LPCWSTR text, UINT attributes )
498 DWORD cx = 0, cy = 0, flags;
500 flags = LR_LOADFROMFILE | LR_DEFAULTSIZE;
501 if( attributes & msidbControlAttributesFixedSize )
503 flags &= ~LR_DEFAULTSIZE;
504 if( attributes & msidbControlAttributesIconSize16 )
509 if( attributes & msidbControlAttributesIconSize32 )
514 /* msidbControlAttributesIconSize48 handled by above logic */
516 return msi_load_image( db, text, IMAGE_ICON, cx, cy, flags );
520 /* called from the Control Event subscription code */
521 void msi_dialog_handle_event( msi_dialog* dialog, LPCWSTR control,
522 LPCWSTR attribute, MSIRECORD *rec )
525 LPCWSTR font_text, text = NULL;
528 ctrl = msi_dialog_find_control( dialog, control );
531 if( !lstrcmpW(attribute, szText) )
533 font_text = MSI_RecordGetString( rec , 1 );
534 font = msi_dialog_get_style( font_text, &text );
535 SetWindowTextW( ctrl->hwnd, text );
537 msi_dialog_check_messages( NULL );
539 else if( !lstrcmpW(attribute, szProgress) )
543 func = MSI_RecordGetInteger( rec , 1 );
544 val = MSI_RecordGetInteger( rec , 2 );
549 ctrl->progress_max = val;
550 ctrl->progress_current = 0;
551 SendMessageW(ctrl->hwnd, PBM_SETRANGE, 0, MAKELPARAM(0,100));
552 SendMessageW(ctrl->hwnd, PBM_SETPOS, 0, 0);
554 case 1: /* FIXME: not sure what this is supposed to do */
557 ctrl->progress_current += val;
558 SendMessageW(ctrl->hwnd, PBM_SETPOS, 100*(ctrl->progress_current/ctrl->progress_max), 0);
561 ERR("Unknown progress message %ld\n", func);
567 FIXME("Attribute %s not being set\n", debugstr_w(attribute));
572 static void msi_dialog_map_events(msi_dialog* dialog, LPCWSTR control)
574 static const WCHAR Query[] = {
575 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
576 '`','E','v','e','n','t','M','a','p','p','i','n','g','`',' ',
577 'W','H','E','R','E',' ',
578 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',' ',
580 '`','C','o','n','t','r','o','l','_','`',' ','=',' ','\'','%','s','\'',0
583 LPCWSTR event, attribute;
585 row = MSI_QueryGetRecord( dialog->package->db, Query, dialog->name, control );
589 event = MSI_RecordGetString( row, 3 );
590 attribute = MSI_RecordGetString( row, 4 );
591 ControlEvent_SubscribeToEvent( dialog->package, event, control, attribute );
592 msiobj_release( &row->hdr );
595 /* everything except radio buttons */
596 static msi_control *msi_dialog_add_control( msi_dialog *dialog,
597 MSIRECORD *rec, LPCWSTR szCls, DWORD style )
603 name = MSI_RecordGetString( rec, 2 );
604 attributes = MSI_RecordGetInteger( rec, 8 );
605 text = MSI_RecordGetString( rec, 10 );
606 if( attributes & msidbControlAttributesVisible )
608 if( ~attributes & msidbControlAttributesEnabled )
609 style |= WS_DISABLED;
610 if( attributes & msidbControlAttributesSunken )
611 exstyle |= WS_EX_CLIENTEDGE;
613 msi_dialog_map_events(dialog, name);
615 return msi_dialog_create_window( dialog, rec, exstyle, szCls, name,
616 text, style, dialog->hwnd );
627 * we don't erase our own background,
628 * so we have to make sure that the parent window redraws first
630 static void msi_text_on_settext( HWND hWnd )
635 hParent = GetParent( hWnd );
636 GetWindowRect( hWnd, &rc );
637 MapWindowPoints( NULL, hParent, (LPPOINT) &rc, 2 );
638 InvalidateRect( hParent, &rc, TRUE );
641 static LRESULT WINAPI
642 MSIText_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
644 struct msi_text_info *info;
647 TRACE("%p %04x %08x %08lx\n", hWnd, msg, wParam, lParam);
649 info = GetPropW(hWnd, szButtonData);
652 SetTextColor( (HDC)wParam, info->font->color );
654 if( msg == WM_CTLCOLORSTATIC &&
655 ( info->attributes & msidbControlAttributesTransparent ) )
657 SetBkMode( (HDC)wParam, TRANSPARENT );
658 return (LRESULT) GetStockObject(NULL_BRUSH);
661 r = CallWindowProcW(info->oldproc, hWnd, msg, wParam, lParam);
666 msi_text_on_settext( hWnd );
670 RemovePropW( hWnd, szButtonData );
677 static UINT msi_dialog_text_control( msi_dialog *dialog, MSIRECORD *rec )
679 msi_control *control;
680 struct msi_text_info *info;
684 TRACE("%p %p\n", dialog, rec);
686 control = msi_dialog_add_control( dialog, rec, szStatic, SS_LEFT | WS_GROUP );
688 return ERROR_FUNCTION_FAILED;
690 info = msi_alloc( sizeof *info );
692 return ERROR_SUCCESS;
694 text = MSI_RecordGetString( rec, 10 );
695 font_name = msi_dialog_get_style( text, &ptr );
696 info->font = ( font_name ) ? msi_dialog_find_font( dialog, font_name ) : NULL;
697 msi_free( font_name );
699 info->attributes = MSI_RecordGetInteger( rec, 8 );
700 if( info->attributes & msidbControlAttributesTransparent )
701 SetWindowLongPtrW( control->hwnd, GWL_EXSTYLE, WS_EX_TRANSPARENT );
703 info->oldproc = (WNDPROC) SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
704 (LONG_PTR)MSIText_WndProc );
705 SetPropW( control->hwnd, szButtonData, info );
707 return ERROR_SUCCESS;
710 static UINT msi_dialog_button_control( msi_dialog *dialog, MSIRECORD *rec )
712 msi_control *control;
713 UINT attributes, style;
716 TRACE("%p %p\n", dialog, rec);
719 attributes = MSI_RecordGetInteger( rec, 8 );
720 if( attributes & msidbControlAttributesIcon )
723 control = msi_dialog_add_control( dialog, rec, szButton, style );
725 return ERROR_FUNCTION_FAILED;
727 control->handler = msi_dialog_button_handler;
730 text = msi_get_deformatted_field( dialog->package, rec, 10 );
731 control->hIcon = msi_load_icon( dialog->package->db, text, attributes );
732 if( attributes & msidbControlAttributesIcon )
733 SendMessageW( control->hwnd, BM_SETIMAGE, IMAGE_ICON, (LPARAM) control->hIcon );
736 return ERROR_SUCCESS;
739 static LPWSTR msi_get_checkbox_value( msi_dialog *dialog, LPCWSTR prop )
741 static const WCHAR query[] = {
742 'S','E','L','E','C','T',' ','*',' ',
743 'F','R','O','M',' ','`','C','h','e','c','k','B','o','x',' ','`',
744 'W','H','E','R','E',' ',
745 '`','P','r','o','p','e','r','t','y','`',' ','=',' ',
748 MSIRECORD *rec = NULL;
751 /* find if there is a value associated with the checkbox */
752 rec = MSI_QueryGetRecord( dialog->package->db, query, prop );
756 ret = msi_get_deformatted_field( dialog->package, rec, 2 );
762 msiobj_release( &rec->hdr );
766 ret = msi_dup_property( dialog->package, prop );
776 static UINT msi_dialog_checkbox_control( msi_dialog *dialog, MSIRECORD *rec )
778 msi_control *control;
781 TRACE("%p %p\n", dialog, rec);
783 control = msi_dialog_add_control( dialog, rec, szButton,
784 BS_CHECKBOX | BS_MULTILINE | WS_TABSTOP );
785 control->handler = msi_dialog_checkbox_handler;
786 prop = MSI_RecordGetString( rec, 9 );
789 control->property = strdupW( prop );
790 control->value = msi_get_checkbox_value( dialog, prop );
791 TRACE("control %s value %s\n", debugstr_w(control->property),
792 debugstr_w(control->value));
794 msi_dialog_checkbox_sync_state( dialog, control );
796 return ERROR_SUCCESS;
799 static UINT msi_dialog_line_control( msi_dialog *dialog, MSIRECORD *rec )
801 TRACE("%p %p\n", dialog, rec);
803 /* line is exactly 2 units in height */
804 MSI_RecordSetInteger( rec, 7, 2 );
806 msi_dialog_add_control( dialog, rec, szStatic, SS_ETCHEDHORZ | SS_SUNKEN );
807 return ERROR_SUCCESS;
810 /******************** Scroll Text ********************************************/
812 struct msi_scrolltext_info
815 msi_control *control;
819 static LRESULT WINAPI
820 MSIScrollText_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
822 struct msi_scrolltext_info *info;
825 TRACE("%p %04x %08x %08lx\n", hWnd, msg, wParam, lParam);
827 info = GetPropW( hWnd, szButtonData );
829 r = CallWindowProcW( info->oldproc, hWnd, msg, wParam, lParam );
835 RemovePropW( hWnd, szButtonData );
838 /* native MSI sets a wait cursor here */
839 msi_dialog_button_handler( info->dialog, info->control, BN_CLICKED );
845 struct msi_streamin_info
852 static DWORD CALLBACK
853 msi_richedit_stream_in( DWORD_PTR arg, LPBYTE buffer, LONG count, LONG *pcb )
855 struct msi_streamin_info *info = (struct msi_streamin_info*) arg;
857 if( (count + info->offset) > info->length )
858 count = info->length - info->offset;
859 memcpy( buffer, &info->string[ info->offset ], count );
861 info->offset += count;
863 TRACE("%ld/%ld\n", info->offset, info->length);
868 static void msi_scrolltext_add_text( msi_control *control, LPCWSTR text )
870 struct msi_streamin_info info;
873 info.string = strdupWtoA( text );
875 info.length = lstrlenA( info.string ) + 1;
877 es.dwCookie = (DWORD_PTR) &info;
879 es.pfnCallback = msi_richedit_stream_in;
881 SendMessageW( control->hwnd, EM_STREAMIN, SF_RTF, (LPARAM) &es );
883 msi_free( info.string );
886 static UINT msi_dialog_scrolltext_control( msi_dialog *dialog, MSIRECORD *rec )
888 static const WCHAR szRichEdit20W[] = {
889 'R','i','c','h','E','d','i','t','2','0','W',0
891 struct msi_scrolltext_info *info;
892 msi_control *control;
896 info = msi_alloc( sizeof *info );
898 return ERROR_FUNCTION_FAILED;
900 hRichedit = LoadLibraryA("riched20");
902 style = WS_BORDER | ES_MULTILINE | WS_VSCROLL |
903 ES_READONLY | ES_AUTOVSCROLL | WS_TABSTOP;
904 control = msi_dialog_add_control( dialog, rec, szRichEdit20W, style );
907 FreeLibrary( hRichedit );
909 return ERROR_FUNCTION_FAILED;
912 control->hDll = hRichedit;
914 info->dialog = dialog;
915 info->control = control;
917 /* subclass the static control */
918 info->oldproc = (WNDPROC) SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
919 (LONG_PTR)MSIScrollText_WndProc );
920 SetPropW( control->hwnd, szButtonData, info );
922 /* add the text into the richedit */
923 msi_scrolltext_add_text( control, MSI_RecordGetString( rec, 10 ) );
925 return ERROR_SUCCESS;
928 static HBITMAP msi_load_picture( MSIDATABASE *db, LPCWSTR name,
929 INT cx, INT cy, DWORD flags )
931 HBITMAP hOleBitmap = 0, hBitmap = 0, hOldSrcBitmap, hOldDestBitmap;
932 MSIRECORD *rec = NULL;
934 IPicture *pic = NULL;
939 rec = msi_get_binary_record( db, name );
943 r = MSI_RecordGetIStream( rec, 2, &stm );
944 msiobj_release( &rec->hdr );
945 if( r != ERROR_SUCCESS )
948 r = OleLoadPicture( stm, 0, TRUE, &IID_IPicture, (LPVOID*) &pic );
949 IStream_Release( stm );
952 ERR("failed to load picture\n");
956 r = IPicture_get_Handle( pic, (OLE_HANDLE*) &hOleBitmap );
959 ERR("failed to get bitmap handle\n");
963 /* make the bitmap the desired size */
964 r = GetObjectW( hOleBitmap, sizeof bm, &bm );
967 ERR("failed to get bitmap size\n");
971 if (flags & LR_DEFAULTSIZE)
977 srcdc = CreateCompatibleDC( NULL );
978 hOldSrcBitmap = SelectObject( srcdc, hOleBitmap );
979 destdc = CreateCompatibleDC( NULL );
980 hBitmap = CreateCompatibleBitmap( srcdc, cx, cy );
981 hOldDestBitmap = SelectObject( destdc, hBitmap );
982 StretchBlt( destdc, 0, 0, cx, cy,
983 srcdc, 0, 0, bm.bmWidth, bm.bmHeight, SRCCOPY);
984 SelectObject( srcdc, hOldSrcBitmap );
985 SelectObject( destdc, hOldDestBitmap );
991 IPicture_Release( pic );
995 static UINT msi_dialog_bitmap_control( msi_dialog *dialog, MSIRECORD *rec )
997 UINT cx, cy, flags, style, attributes;
998 msi_control *control;
1001 flags = LR_LOADFROMFILE;
1002 style = SS_BITMAP | SS_LEFT | WS_GROUP;
1004 attributes = MSI_RecordGetInteger( rec, 8 );
1005 if( attributes & msidbControlAttributesFixedSize )
1007 flags |= LR_DEFAULTSIZE;
1008 style |= SS_CENTERIMAGE;
1011 control = msi_dialog_add_control( dialog, rec, szStatic, style );
1012 cx = MSI_RecordGetInteger( rec, 6 );
1013 cy = MSI_RecordGetInteger( rec, 7 );
1014 cx = msi_dialog_scale_unit( dialog, cx );
1015 cy = msi_dialog_scale_unit( dialog, cy );
1017 text = msi_get_deformatted_field( dialog->package, rec, 10 );
1018 control->hBitmap = msi_load_picture( dialog->package->db, text, cx, cy, flags );
1019 if( control->hBitmap )
1020 SendMessageW( control->hwnd, STM_SETIMAGE,
1021 IMAGE_BITMAP, (LPARAM) control->hBitmap );
1023 ERR("Failed to load bitmap %s\n", debugstr_w(text));
1027 return ERROR_SUCCESS;
1030 static UINT msi_dialog_icon_control( msi_dialog *dialog, MSIRECORD *rec )
1032 msi_control *control;
1038 control = msi_dialog_add_control( dialog, rec, szStatic,
1039 SS_ICON | SS_CENTERIMAGE | WS_GROUP );
1041 attributes = MSI_RecordGetInteger( rec, 8 );
1042 text = msi_get_deformatted_field( dialog->package, rec, 10 );
1043 control->hIcon = msi_load_icon( dialog->package->db, text, attributes );
1044 if( control->hIcon )
1045 SendMessageW( control->hwnd, STM_SETICON, (WPARAM) control->hIcon, 0 );
1047 ERR("Failed to load bitmap %s\n", debugstr_w(text));
1049 return ERROR_SUCCESS;
1052 static UINT msi_dialog_combo_control( msi_dialog *dialog, MSIRECORD *rec )
1054 static const WCHAR szCombo[] = { 'C','O','M','B','O','B','O','X',0 };
1056 msi_dialog_add_control( dialog, rec, szCombo,
1057 SS_BITMAP | SS_LEFT | SS_CENTERIMAGE );
1058 return ERROR_SUCCESS;
1061 static UINT msi_dialog_edit_control( msi_dialog *dialog, MSIRECORD *rec )
1063 msi_control *control;
1067 control = msi_dialog_add_control( dialog, rec, szEdit,
1068 WS_BORDER | WS_TABSTOP );
1069 control->handler = msi_dialog_edit_handler;
1070 prop = MSI_RecordGetString( rec, 9 );
1072 control->property = strdupW( prop );
1073 val = msi_dup_property( dialog->package, control->property );
1074 SetWindowTextW( control->hwnd, val );
1076 return ERROR_SUCCESS;
1079 /******************** Masked Edit ********************************************/
1081 #define MASK_MAX_GROUPS 10
1083 struct msi_mask_group
1091 struct msi_maskedit_info
1099 struct msi_mask_group group[MASK_MAX_GROUPS];
1102 static BOOL msi_mask_editable( WCHAR type )
1117 static void msi_mask_control_change( struct msi_maskedit_info *info )
1122 val = msi_alloc( (info->num_chars+1)*sizeof(WCHAR) );
1123 for( i=0, n=0; i<info->num_groups; i++ )
1125 if( (info->group[i].len + n) > info->num_chars )
1127 ERR("can't fit control %d text into template\n",i);
1130 if (!msi_mask_editable(info->group[i].type))
1132 for(r=0; r<info->group[i].len; r++)
1133 val[n+r] = info->group[i].type;
1138 r = GetWindowTextW( info->group[i].hwnd, &val[n], info->group[i].len+1 );
1139 if( r != info->group[i].len )
1145 TRACE("%d/%d controls were good\n", i, info->num_groups);
1147 if( i == info->num_groups )
1149 TRACE("Set property %s to %s\n",
1150 debugstr_w(info->prop), debugstr_w(val) );
1151 CharUpperBuffW( val, info->num_chars );
1152 MSI_SetPropertyW( info->dialog->package, info->prop, val );
1153 msi_dialog_evaluate_control_conditions( info->dialog );
1158 /* now move to the next control if necessary */
1159 static VOID msi_mask_next_control( struct msi_maskedit_info *info, HWND hWnd )
1164 for( i=0; i<info->num_groups; i++ )
1165 if( info->group[i].hwnd == hWnd )
1168 /* don't move from the last control */
1169 if( i >= (info->num_groups-1) )
1172 len = SendMessageW( hWnd, WM_GETTEXTLENGTH, 0, 0 );
1173 if( len < info->group[i].len )
1176 hWndNext = GetNextDlgTabItem( GetParent( hWnd ), hWnd, FALSE );
1177 SetFocus( hWndNext );
1180 static LRESULT WINAPI
1181 MSIMaskedEdit_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
1183 struct msi_maskedit_info *info;
1186 TRACE("%p %04x %08x %08lx\n", hWnd, msg, wParam, lParam);
1188 info = GetPropW(hWnd, szButtonData);
1190 r = CallWindowProcW(info->oldproc, hWnd, msg, wParam, lParam);
1195 if (HIWORD(wParam) == EN_CHANGE)
1197 msi_mask_control_change( info );
1198 msi_mask_next_control( info, (HWND) lParam );
1202 msi_free( info->prop );
1204 RemovePropW( hWnd, szButtonData );
1211 /* fish the various bits of the property out and put them in the control */
1213 msi_maskedit_set_text( struct msi_maskedit_info *info, LPCWSTR text )
1219 for( i = 0; i < info->num_groups; i++ )
1221 if( info->group[i].len < lstrlenW( p ) )
1223 LPWSTR chunk = strdupW( p );
1224 chunk[ info->group[i].len ] = 0;
1225 SetWindowTextW( info->group[i].hwnd, chunk );
1230 SetWindowTextW( info->group[i].hwnd, p );
1233 p += info->group[i].len;
1237 static struct msi_maskedit_info * msi_dialog_parse_groups( LPCWSTR mask )
1239 struct msi_maskedit_info * info = NULL;
1240 int i = 0, n = 0, total = 0;
1243 TRACE("masked control, template %s\n", debugstr_w(mask));
1248 info = msi_alloc_zero( sizeof *info );
1252 p = strchrW(mask, '<');
1258 for( i=0; i<MASK_MAX_GROUPS; i++ )
1260 /* stop at the end of the string */
1261 if( p[0] == 0 || p[0] == '>' )
1264 /* count the number of the same identifier */
1265 for( n=0; p[n] == p[0]; n++ )
1267 info->group[i].ofs = total;
1268 info->group[i].type = p[0];
1272 total++; /* an extra not part of the group */
1274 info->group[i].len = n;
1279 TRACE("%d characters in %d groups\n", total, i );
1280 if( i == MASK_MAX_GROUPS )
1281 ERR("too many groups in PIDTemplate %s\n", debugstr_w(mask));
1283 info->num_chars = total;
1284 info->num_groups = i;
1290 msi_maskedit_create_children( struct msi_maskedit_info *info, LPCWSTR font )
1292 DWORD width, height, style, wx, ww;
1297 style = WS_CHILD | WS_BORDER | WS_VISIBLE | WS_TABSTOP | ES_AUTOHSCROLL;
1299 GetClientRect( info->hwnd, &rect );
1301 width = rect.right - rect.left;
1302 height = rect.bottom - rect.top;
1304 for( i = 0; i < info->num_groups; i++ )
1306 if (!msi_mask_editable( info->group[i].type ))
1308 wx = (info->group[i].ofs * width) / info->num_chars;
1309 ww = (info->group[i].len * width) / info->num_chars;
1311 hwnd = CreateWindowW( szEdit, NULL, style, wx, 0, ww, height,
1312 info->hwnd, NULL, NULL, NULL );
1315 ERR("failed to create mask edit sub window\n");
1319 SendMessageW( hwnd, EM_LIMITTEXT, info->group[i].len, 0 );
1321 msi_dialog_set_font( info->dialog, hwnd,
1322 font?font:info->dialog->default_font );
1323 info->group[i].hwnd = hwnd;
1328 * office 2003 uses "73931<````=````=````=````=`````>@@@@@"
1329 * delphi 7 uses "<????-??????-??????-????>" and "<???-???>"
1330 * filemaker pro 7 uses "<^^^^=^^^^=^^^^=^^^^=^^^^=^^^^=^^^^^>"
1332 static UINT msi_dialog_maskedit_control( msi_dialog *dialog, MSIRECORD *rec )
1334 LPWSTR font_mask, val = NULL, font;
1335 struct msi_maskedit_info *info = NULL;
1336 UINT ret = ERROR_SUCCESS;
1337 msi_control *control;
1342 font_mask = msi_get_deformatted_field( dialog->package, rec, 10 );
1343 font = msi_dialog_get_style( font_mask, &mask );
1346 ERR("mask template is empty\n");
1350 info = msi_dialog_parse_groups( mask );
1353 ERR("template %s is invalid\n", debugstr_w(mask));
1357 info->dialog = dialog;
1359 control = msi_dialog_add_control( dialog, rec, szStatic,
1360 SS_OWNERDRAW | WS_GROUP | WS_VISIBLE );
1363 ERR("Failed to create maskedit container\n");
1364 ret = ERROR_FUNCTION_FAILED;
1367 SetWindowLongPtrW( control->hwnd, GWL_EXSTYLE, WS_EX_CONTROLPARENT );
1369 info->hwnd = control->hwnd;
1371 /* subclass the static control */
1372 info->oldproc = (WNDPROC) SetWindowLongPtrW( info->hwnd, GWLP_WNDPROC,
1373 (LONG_PTR)MSIMaskedEdit_WndProc );
1374 SetPropW( control->hwnd, szButtonData, info );
1376 prop = MSI_RecordGetString( rec, 9 );
1378 info->prop = strdupW( prop );
1380 msi_maskedit_create_children( info, font );
1384 val = msi_dup_property( dialog->package, prop );
1387 msi_maskedit_set_text( info, val );
1393 if( ret != ERROR_SUCCESS )
1395 msi_free( font_mask );
1400 /******************** Progress Bar *****************************************/
1402 static UINT msi_dialog_progress_bar( msi_dialog *dialog, MSIRECORD *rec )
1404 msi_dialog_add_control( dialog, rec, PROGRESS_CLASSW, WS_VISIBLE );
1405 return ERROR_SUCCESS;
1408 /******************** Path Edit ********************************************/
1410 struct msi_pathedit_info
1413 msi_control *control;
1417 static LPWSTR msi_get_window_text( HWND hwnd )
1423 buf = msi_alloc( sz*sizeof(WCHAR) );
1426 r = GetWindowTextW( hwnd, buf, sz );
1430 buf = msi_realloc( buf, sz*sizeof(WCHAR) );
1436 static void msi_dialog_update_pathedit( msi_dialog *dialog, msi_control *control )
1441 if (!control && !(control = msi_dialog_find_control_by_type( dialog, szPathEdit )))
1444 indirect = control->attributes & msidbControlAttributesIndirect;
1445 prop = msi_dialog_dup_property( dialog, control->property, indirect );
1447 path = msi_dup_property( dialog->package, prop );
1448 SetWindowTextW( control->hwnd, path );
1449 SendMessageW( control->hwnd, EM_SETSEL, 0, -1 );
1455 /* FIXME: test when this should fail */
1456 static BOOL msi_dialog_verify_path( LPWSTR path )
1458 if ( !lstrlenW( path ) )
1461 if ( PathIsRelativeW( path ) )
1467 /* returns TRUE if the path is valid, FALSE otherwise */
1468 static BOOL msi_dialog_onkillfocus( msi_dialog *dialog, msi_control *control )
1474 indirect = control->attributes & msidbControlAttributesIndirect;
1475 prop = msi_dialog_dup_property( dialog, control->property, indirect );
1477 buf = msi_get_window_text( control->hwnd );
1479 if ( !msi_dialog_verify_path( buf ) )
1481 /* FIXME: display an error message box */
1482 ERR("Invalid path %s\n", debugstr_w( buf ));
1484 SetFocus( control->hwnd );
1489 MSI_SetPropertyW( dialog->package, prop, buf );
1492 msi_dialog_update_pathedit( dialog, control );
1494 TRACE("edit %s contents changed, set %s\n", debugstr_w(control->name),
1503 static LRESULT WINAPI MSIPathEdit_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
1505 struct msi_pathedit_info *info = GetPropW(hWnd, szButtonData);
1508 TRACE("%p %04x %08x %08lx\n", hWnd, msg, wParam, lParam);
1510 if ( msg == WM_KILLFOCUS )
1512 /* if the path is invalid, don't handle this message */
1513 if ( !msi_dialog_onkillfocus( info->dialog, info->control ) )
1517 r = CallWindowProcW(info->oldproc, hWnd, msg, wParam, lParam);
1519 if ( msg == WM_NCDESTROY )
1522 RemovePropW( hWnd, szButtonData );
1528 static UINT msi_dialog_pathedit_control( msi_dialog *dialog, MSIRECORD *rec )
1530 struct msi_pathedit_info *info;
1531 msi_control *control;
1534 info = msi_alloc( sizeof *info );
1536 return ERROR_FUNCTION_FAILED;
1538 control = msi_dialog_add_control( dialog, rec, szEdit,
1539 WS_BORDER | WS_TABSTOP );
1540 control->attributes = MSI_RecordGetInteger( rec, 8 );
1541 prop = MSI_RecordGetString( rec, 9 );
1542 control->property = msi_dialog_dup_property( dialog, prop, FALSE );
1544 info->dialog = dialog;
1545 info->control = control;
1546 info->oldproc = (WNDPROC) SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
1547 (LONG_PTR)MSIPathEdit_WndProc );
1548 SetPropW( control->hwnd, szButtonData, info );
1550 msi_dialog_update_pathedit( dialog, control );
1552 return ERROR_SUCCESS;
1555 /* radio buttons are a bit different from normal controls */
1556 static UINT msi_dialog_create_radiobutton( MSIRECORD *rec, LPVOID param )
1558 radio_button_group_descr *group = (radio_button_group_descr *)param;
1559 msi_dialog *dialog = group->dialog;
1560 msi_control *control;
1561 LPCWSTR prop, text, name;
1562 DWORD style, attributes = group->attributes;
1564 style = WS_CHILD | BS_AUTORADIOBUTTON | BS_MULTILINE | WS_TABSTOP;
1565 name = MSI_RecordGetString( rec, 3 );
1566 text = MSI_RecordGetString( rec, 8 );
1567 if( attributes & 1 )
1568 style |= WS_VISIBLE;
1569 if( ~attributes & 2 )
1570 style |= WS_DISABLED;
1572 control = msi_dialog_create_window( dialog, rec, 0, szButton, name, text,
1573 style, group->parent->hwnd );
1575 return ERROR_FUNCTION_FAILED;
1576 control->handler = msi_dialog_radiogroup_handler;
1578 if (!lstrcmpW(control->name, group->propval))
1579 SendMessageW(control->hwnd, BM_SETCHECK, BST_CHECKED, 0);
1581 prop = MSI_RecordGetString( rec, 1 );
1583 control->property = strdupW( prop );
1585 return ERROR_SUCCESS;
1588 static UINT msi_dialog_radiogroup_control( msi_dialog *dialog, MSIRECORD *rec )
1590 static const WCHAR query[] = {
1591 'S','E','L','E','C','T',' ','*',' ',
1592 'F','R','O','M',' ','R','a','d','i','o','B','u','t','t','o','n',' ',
1593 'W','H','E','R','E',' ',
1594 '`','P','r','o','p','e','r','t','y','`',' ','=',' ','\'','%','s','\'',0};
1597 msi_control *control;
1598 MSIQUERY *view = NULL;
1599 radio_button_group_descr group;
1600 MSIPACKAGE *package = dialog->package;
1603 prop = MSI_RecordGetString( rec, 9 );
1605 TRACE("%p %p %s\n", dialog, rec, debugstr_w( prop ));
1607 /* Create parent group box to hold radio buttons */
1608 control = msi_dialog_add_control( dialog, rec, szButton, BS_OWNERDRAW|WS_GROUP );
1610 return ERROR_FUNCTION_FAILED;
1612 oldproc = (WNDPROC) SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
1613 (LONG_PTR)MSIRadioGroup_WndProc );
1614 SetPropW(control->hwnd, szButtonData, oldproc);
1615 SetWindowLongPtrW( control->hwnd, GWL_EXSTYLE, WS_EX_CONTROLPARENT );
1618 control->property = strdupW( prop );
1620 /* query the Radio Button table for all control in this group */
1621 r = MSI_OpenQuery( package->db, &view, query, prop );
1622 if( r != ERROR_SUCCESS )
1624 ERR("query failed for dialog %s radio group %s\n",
1625 debugstr_w(dialog->name), debugstr_w(prop));
1626 return ERROR_INVALID_PARAMETER;
1629 group.dialog = dialog;
1630 group.parent = control;
1631 group.attributes = MSI_RecordGetInteger( rec, 8 );
1632 group.propval = msi_dup_property( dialog->package, control->property );
1634 r = MSI_IterateRecords( view, 0, msi_dialog_create_radiobutton, &group );
1635 msiobj_release( &view->hdr );
1636 msi_free( group.propval );
1641 /******************** Selection Tree ***************************************/
1643 struct msi_selection_tree_info
1651 msi_seltree_sync_item_state( HWND hwnd, MSIFEATURE *feature, HTREEITEM hItem )
1655 TRACE("Feature %s -> %d %d %d\n", debugstr_w(feature->Title),
1656 feature->Installed, feature->Action, feature->ActionRequest);
1658 tvi.mask = TVIF_STATE;
1660 tvi.state = INDEXTOSTATEIMAGEMASK( feature->Action );
1661 tvi.stateMask = TVIS_STATEIMAGEMASK;
1663 SendMessageW( hwnd, TVM_SETITEMW, 0, (LPARAM) &tvi );
1667 msi_seltree_popup_menu( HWND hwnd, INT x, INT y )
1672 /* create a menu to display */
1673 hMenu = CreatePopupMenu();
1675 /* FIXME: load strings from resources */
1676 AppendMenuA( hMenu, MF_ENABLED, INSTALLSTATE_LOCAL, "Install feature locally");
1677 AppendMenuA( hMenu, MF_GRAYED, 0x1000, "Install entire feature");
1678 AppendMenuA( hMenu, MF_ENABLED, INSTALLSTATE_ADVERTISED, "Install on demand");
1679 AppendMenuA( hMenu, MF_ENABLED, INSTALLSTATE_ABSENT, "Don't install");
1680 r = TrackPopupMenu( hMenu, TPM_LEFTALIGN | TPM_TOPALIGN | TPM_RETURNCMD,
1681 x, y, 0, hwnd, NULL );
1682 DestroyMenu( hMenu );
1687 msi_seltree_feature_from_item( HWND hwnd, HTREEITEM hItem )
1691 /* get the feature from the item */
1692 memset( &tvi, 0, sizeof tvi );
1694 tvi.mask = TVIF_PARAM | TVIF_HANDLE;
1695 SendMessageW( hwnd, TVM_GETITEMW, 0, (LPARAM) &tvi );
1697 return (MSIFEATURE*) tvi.lParam;
1701 msi_seltree_menu( HWND hwnd, HTREEITEM hItem )
1703 MSIFEATURE *feature;
1712 feature = msi_seltree_feature_from_item( hwnd, hItem );
1715 ERR("item %p feature was NULL\n", hItem);
1719 /* get the item's rectangle to put the menu just below it */
1721 SendMessageW( hwnd, TVM_GETITEMRECT, 0, (LPARAM) &u.rc );
1722 MapWindowPoints( hwnd, NULL, u.pt, 2 );
1724 r = msi_seltree_popup_menu( hwnd, u.rc.left, u.rc.top );
1728 case INSTALLSTATE_LOCAL:
1729 case INSTALLSTATE_ADVERTISED:
1730 case INSTALLSTATE_ABSENT:
1731 feature->ActionRequest = r;
1732 feature->Action = r;
1735 FIXME("select feature and all children\n");
1739 msi_seltree_sync_item_state( hwnd, feature, hItem );
1741 /* update the feature's components */
1742 LIST_FOR_EACH_ENTRY( cl, &feature->Components, ComponentList, entry )
1744 cl->component->Action = feature->Action;
1745 cl->component->ActionRequest = feature->ActionRequest;
1751 static LRESULT WINAPI
1752 MSISelectionTree_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
1754 struct msi_selection_tree_info *info;
1755 TVHITTESTINFO tvhti;
1758 TRACE("%p %04x %08x %08lx\n", hWnd, msg, wParam, lParam);
1760 info = GetPropW(hWnd, szButtonData);
1764 case WM_LBUTTONDOWN:
1765 tvhti.pt.x = LOWORD( lParam );
1766 tvhti.pt.y = HIWORD( lParam );
1769 r = CallWindowProcW(info->oldproc, hWnd, TVM_HITTEST, 0, (LPARAM) &tvhti );
1770 if (tvhti.flags & TVHT_ONITEMSTATEICON)
1771 return msi_seltree_menu( hWnd, tvhti.hItem );
1775 r = CallWindowProcW(info->oldproc, hWnd, msg, wParam, lParam);
1781 RemovePropW( hWnd, szButtonData );
1788 msi_seltree_add_child_features( MSIPACKAGE *package, HWND hwnd,
1789 LPCWSTR parent, HTREEITEM hParent )
1791 MSIFEATURE *feature;
1792 TVINSERTSTRUCTW tvis;
1795 LIST_FOR_EACH_ENTRY( feature, &package->features, MSIFEATURE, entry )
1797 if ( lstrcmpW( parent, feature->Feature_Parent ) )
1800 if ( !feature->Title )
1803 if ( !feature->Display )
1806 memset( &tvis, 0, sizeof tvis );
1807 tvis.hParent = hParent;
1808 tvis.hInsertAfter = TVI_LAST;
1809 tvis.u.item.mask = TVIF_TEXT | TVIF_PARAM;
1810 tvis.u.item.pszText = feature->Title;
1811 tvis.u.item.lParam = (LPARAM) feature;
1813 hitem = (HTREEITEM) SendMessageW( hwnd, TVM_INSERTITEMW, 0, (LPARAM) &tvis );
1817 msi_seltree_sync_item_state( hwnd, feature, hitem );
1818 msi_seltree_add_child_features( package, hwnd,
1819 feature->Feature, hitem );
1821 /* the node is expanded if Display is odd */
1822 if ( feature->Display % 2 != 0 )
1823 SendMessageW( hwnd, TVM_EXPAND, TVE_EXPAND, (LPARAM) hitem );
1827 static void msi_seltree_create_imagelist( HWND hwnd )
1829 const int bm_width = 32, bm_height = 16, bm_count = 3;
1830 const int bm_resource = 0x1001;
1835 himl = ImageList_Create( bm_width, bm_height, FALSE, 4, 0 );
1838 ERR("failed to create image list\n");
1842 for (i=0; i<bm_count; i++)
1844 hbmp = LoadBitmapW( msi_hInstance, MAKEINTRESOURCEW(i+bm_resource) );
1847 ERR("failed to load bitmap %d\n", i);
1852 * Add a dummy bitmap at offset zero because the treeview
1853 * can't use it as a state mask (zero means no user state).
1856 ImageList_Add( himl, hbmp, NULL );
1858 ImageList_Add( himl, hbmp, NULL );
1861 SendMessageW( hwnd, TVM_SETIMAGELIST, TVSIL_STATE, (LPARAM)himl );
1864 static UINT msi_dialog_selection_tree( msi_dialog *dialog, MSIRECORD *rec )
1866 msi_control *control;
1868 MSIPACKAGE *package = dialog->package;
1870 struct msi_selection_tree_info *info;
1872 info = msi_alloc( sizeof *info );
1874 return ERROR_FUNCTION_FAILED;
1876 /* create the treeview control */
1877 prop = MSI_RecordGetString( rec, 9 );
1878 style = TVS_HASLINES | TVS_HASBUTTONS | TVS_LINESATROOT;
1879 style |= WS_GROUP | WS_VSCROLL;
1880 control = msi_dialog_add_control( dialog, rec, WC_TREEVIEWW, style );
1884 return ERROR_FUNCTION_FAILED;
1888 info->dialog = dialog;
1889 info->hwnd = control->hwnd;
1890 info->oldproc = (WNDPROC) SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
1891 (LONG_PTR)MSISelectionTree_WndProc );
1892 SetPropW( control->hwnd, szButtonData, info );
1895 msi_seltree_create_imagelist( control->hwnd );
1896 msi_seltree_add_child_features( package, control->hwnd, NULL, NULL );
1898 return ERROR_SUCCESS;
1901 /******************** Group Box ***************************************/
1903 static UINT msi_dialog_group_box( msi_dialog *dialog, MSIRECORD *rec )
1905 msi_control *control;
1908 style = BS_GROUPBOX | WS_CHILD | WS_GROUP;
1909 control = msi_dialog_add_control( dialog, rec, WC_BUTTONW, style );
1911 return ERROR_FUNCTION_FAILED;
1913 return ERROR_SUCCESS;
1916 /******************** List Box ***************************************/
1918 struct msi_listbox_item
1924 struct msi_listbox_info
1930 struct msi_listbox_item *items;
1933 static LRESULT WINAPI MSIListBox_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
1935 struct msi_listbox_info *info;
1939 TRACE("%p %04x %08x %08lx\n", hWnd, msg, wParam, lParam);
1941 info = GetPropW( hWnd, szButtonData );
1945 r = CallWindowProcW( info->oldproc, hWnd, msg, wParam, lParam );
1950 for (j = 0; j < info->num_items; j++)
1952 msi_free( info->items[j].property );
1953 msi_free( info->items[j].value );
1955 msi_free( info->items );
1957 RemovePropW( hWnd, szButtonData );
1964 static UINT msi_listbox_add_item( MSIRECORD *rec, LPVOID param )
1966 struct msi_listbox_info *info = param;
1967 struct msi_listbox_item *item;
1968 LPCWSTR property, value, text;
1969 static int index = 0;
1971 item = &info->items[index++];
1972 property = MSI_RecordGetString( rec, 1 );
1973 value = MSI_RecordGetString( rec, 3 );
1974 text = MSI_RecordGetString( rec, 4 );
1976 item->property = strdupW( property );
1977 item->value = strdupW( value );
1979 SendMessageW( info->hwnd, LB_ADDSTRING, 0, (LPARAM)text );
1981 return ERROR_SUCCESS;
1984 static UINT msi_listbox_add_items( struct msi_listbox_info *info )
1987 MSIQUERY *view = NULL;
1990 static const WCHAR query[] = {
1991 'S','E','L','E','C','T',' ','*',' ',
1992 'F','R','O','M',' ','`','L','i','s','t','B','o','x','`',' ',
1993 'O','R','D','E','R',' ','B','Y',' ','`','O','r','d','e','r','`',0
1996 r = MSI_OpenQuery( info->dialog->package->db, &view, query );
1997 if ( r != ERROR_SUCCESS )
2000 /* just get the number of records */
2001 r = MSI_IterateRecords( view, &count, NULL, NULL );
2003 info->num_items = count;
2004 info->items = msi_alloc( sizeof(*info->items) * count );
2006 r = MSI_IterateRecords( view, NULL, msi_listbox_add_item, info );
2007 msiobj_release( &view->hdr );
2012 static UINT msi_dialog_listbox_handler( msi_dialog *dialog,
2013 msi_control *control, WPARAM param )
2015 struct msi_listbox_info *info;
2018 if( HIWORD(param) != LBN_SELCHANGE )
2019 return ERROR_SUCCESS;
2021 info = GetPropW( control->hwnd, szButtonData );
2022 index = SendMessageW( control->hwnd, LB_GETCURSEL, 0, 0 );
2024 MSI_SetPropertyW( info->dialog->package,
2025 info->items[index].property, info->items[index].value );
2026 msi_dialog_evaluate_control_conditions( info->dialog );
2028 return ERROR_SUCCESS;
2031 static UINT msi_dialog_list_box( msi_dialog *dialog, MSIRECORD *rec )
2033 struct msi_listbox_info *info;
2034 msi_control *control;
2037 info = msi_alloc( sizeof *info );
2039 return ERROR_FUNCTION_FAILED;
2041 style = WS_TABSTOP | WS_GROUP | WS_CHILD | LBS_STANDARD;
2042 control = msi_dialog_add_control( dialog, rec, WC_LISTBOXW, style );
2044 return ERROR_FUNCTION_FAILED;
2046 control->handler = msi_dialog_listbox_handler;
2049 info->dialog = dialog;
2050 info->hwnd = control->hwnd;
2052 info->oldproc = (WNDPROC)SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
2053 (LONG_PTR)MSIListBox_WndProc );
2054 SetPropW( control->hwnd, szButtonData, info );
2056 msi_listbox_add_items( info );
2058 return ERROR_SUCCESS;
2061 /******************** Directory Combo ***************************************/
2063 static void msi_dialog_update_directory_combo( msi_dialog *dialog, msi_control *control )
2068 if (!control && !(control = msi_dialog_find_control_by_type( dialog, szDirectoryCombo )))
2071 indirect = control->attributes & msidbControlAttributesIndirect;
2072 prop = msi_dialog_dup_property( dialog, control->property, indirect );
2073 path = msi_dup_property( dialog->package, prop );
2075 PathStripPathW( path );
2076 PathRemoveBackslashW( path );
2078 SendMessageW( control->hwnd, CB_INSERTSTRING, 0, (LPARAM)path );
2079 SendMessageW( control->hwnd, CB_SETCURSEL, 0, 0 );
2085 static UINT msi_dialog_directory_combo( msi_dialog *dialog, MSIRECORD *rec )
2087 msi_control *control;
2091 /* FIXME: use CBS_OWNERDRAWFIXED and add owner draw code */
2092 style = CBS_DROPDOWNLIST | CBS_HASSTRINGS | WS_CHILD |
2093 WS_GROUP | WS_TABSTOP | WS_VSCROLL;
2094 control = msi_dialog_add_control( dialog, rec, WC_COMBOBOXW, style );
2096 return ERROR_FUNCTION_FAILED;
2098 control->attributes = MSI_RecordGetInteger( rec, 8 );
2099 prop = MSI_RecordGetString( rec, 9 );
2100 control->property = msi_dialog_dup_property( dialog, prop, FALSE );
2102 msi_dialog_update_directory_combo( dialog, control );
2104 return ERROR_SUCCESS;
2107 /******************** Directory List ***************************************/
2109 static void msi_dialog_update_directory_list( msi_dialog *dialog, msi_control *control )
2111 WCHAR dir_spec[MAX_PATH];
2112 WIN32_FIND_DATAW wfd;
2118 static const WCHAR asterisk[] = {'*',0};
2119 static const WCHAR dot[] = {'.',0};
2120 static const WCHAR dotdot[] = {'.','.',0};
2122 if (!control && !(control = msi_dialog_find_control_by_type( dialog, szDirectoryList )))
2125 /* clear the list-view */
2126 SendMessageW( control->hwnd, LVM_DELETEALLITEMS, 0, 0 );
2128 indirect = control->attributes & msidbControlAttributesIndirect;
2129 prop = msi_dialog_dup_property( dialog, control->property, indirect );
2130 path = msi_dup_property( dialog->package, prop );
2132 lstrcpyW( dir_spec, path );
2133 lstrcatW( dir_spec, asterisk );
2135 file = FindFirstFileW( dir_spec, &wfd );
2136 if ( file == INVALID_HANDLE_VALUE )
2141 if ( wfd.dwFileAttributes != FILE_ATTRIBUTE_DIRECTORY )
2144 if ( !lstrcmpW( wfd.cFileName, dot ) || !lstrcmpW( wfd.cFileName, dotdot ) )
2147 item.mask = LVIF_TEXT;
2148 item.cchTextMax = MAX_PATH;
2151 item.pszText = wfd.cFileName;
2153 SendMessageW( control->hwnd, LVM_INSERTITEMW, 0, (LPARAM)&item );
2154 } while ( FindNextFileW( file, &wfd ) );
2161 UINT msi_dialog_directorylist_up( msi_dialog *dialog )
2163 msi_control *control;
2164 LPWSTR prop, path, ptr;
2167 control = msi_dialog_find_control_by_type( dialog, szDirectoryList );
2168 indirect = control->attributes & msidbControlAttributesIndirect;
2169 prop = msi_dialog_dup_property( dialog, control->property, indirect );
2171 path = msi_dup_property( dialog->package, prop );
2173 /* strip off the last directory */
2174 ptr = PathFindFileNameW( path );
2175 if (ptr != path) *(ptr - 1) = '\0';
2176 PathAddBackslashW( path );
2178 MSI_SetPropertyW( dialog->package, prop, path );
2180 msi_dialog_update_directory_list( dialog, NULL );
2181 msi_dialog_update_directory_combo( dialog, NULL );
2182 msi_dialog_update_pathedit( dialog, NULL );
2187 return ERROR_SUCCESS;
2190 static UINT msi_dialog_dirlist_handler( msi_dialog *dialog,
2191 msi_control *control, WPARAM param )
2193 LPNMHDR nmhdr = (LPNMHDR)param;
2194 WCHAR new_path[MAX_PATH];
2195 WCHAR text[MAX_PATH];
2201 static const WCHAR backslash[] = {'\\',0};
2203 if (nmhdr->code != LVN_ITEMACTIVATE)
2204 return ERROR_SUCCESS;
2206 index = SendMessageW( control->hwnd, LVM_GETNEXTITEM, -1, LVNI_SELECTED );
2209 ERR("No list-view item selected!\n");
2210 return ERROR_FUNCTION_FAILED;
2214 item.pszText = text;
2215 item.cchTextMax = MAX_PATH;
2216 SendMessageW( control->hwnd, LVM_GETITEMTEXTW, index, (LPARAM)&item );
2218 indirect = control->attributes & msidbControlAttributesIndirect;
2219 prop = msi_dialog_dup_property( dialog, control->property, indirect );
2220 path = msi_dup_property( dialog->package, prop );
2222 lstrcpyW( new_path, path );
2223 lstrcatW( new_path, text );
2224 lstrcatW( new_path, backslash );
2226 MSI_SetPropertyW( dialog->package, prop, new_path );
2228 msi_dialog_update_directory_list( dialog, NULL );
2229 msi_dialog_update_directory_combo( dialog, NULL );
2230 msi_dialog_update_pathedit( dialog, NULL );
2234 return ERROR_SUCCESS;
2237 static UINT msi_dialog_directory_list( msi_dialog *dialog, MSIRECORD *rec )
2239 msi_control *control;
2243 style = LVS_LIST | WS_VSCROLL | LVS_SHAREIMAGELISTS |
2244 LVS_AUTOARRANGE | LVS_SINGLESEL | WS_BORDER |
2245 LVS_SORTASCENDING | WS_CHILD | WS_GROUP | WS_TABSTOP;
2246 control = msi_dialog_add_control( dialog, rec, WC_LISTVIEWW, style );
2248 return ERROR_FUNCTION_FAILED;
2250 control->attributes = MSI_RecordGetInteger( rec, 8 );
2251 control->handler = msi_dialog_dirlist_handler;
2252 prop = MSI_RecordGetString( rec, 9 );
2253 control->property = msi_dialog_dup_property( dialog, prop, FALSE );
2255 /* double click to activate an item in the list */
2256 SendMessageW( control->hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE,
2257 0, LVS_EX_TWOCLICKACTIVATE );
2259 msi_dialog_update_directory_list( dialog, control );
2261 return ERROR_SUCCESS;
2264 /******************** VolumeCost List ***************************************/
2266 static BOOL str_is_number( LPCWSTR str )
2270 for (i = 0; i < lstrlenW( str ); i++)
2271 if (!isdigitW(str[i]))
2277 WCHAR column_keys[][80] =
2279 {'V','o','l','u','m','e','C','o','s','t','V','o','l','u','m','e',0},
2280 {'V','o','l','u','m','e','C','o','s','t','S','i','z','e',0},
2281 {'V','o','l','u','m','e','C','o','s','t','A','v','a','i','l','a','b','l','e',0},
2282 {'V','o','l','u','m','e','C','o','s','t','R','e','q','u','i','r','e','d',0},
2283 {'V','o','l','u','m','e','C','o','s','t','D','i','f','f','e','r','e','n','c','e',0}
2286 static void msi_dialog_vcl_add_columns( msi_dialog *dialog, msi_control *control, MSIRECORD *rec )
2288 LPCWSTR text = MSI_RecordGetString( rec, 10 );
2289 LPCWSTR begin = text, end;
2295 static const WCHAR zero[] = {'0',0};
2296 static const WCHAR negative[] = {'-',0};
2298 while ((begin = strchrW( begin, '{' )) && count < 5)
2300 if (!(end = strchrW( begin, '}' )))
2303 lstrcpynW( num, begin + 1, end - begin );
2304 begin += end - begin + 1;
2306 /* empty braces or '0' hides the column */
2307 if ( !num[0] || !lstrcmpW( num, zero ) )
2313 /* the width must be a positive number
2314 * if a width is invalid, all remaining columns are hidden
2316 if ( !strncmpW( num, negative, 1 ) || !str_is_number( num ) )
2319 lvc.mask = LVCF_FMT | LVCF_ORDER | LVCF_WIDTH | LVCF_TEXT;
2321 lvc.pszText = msi_dialog_get_uitext( dialog, column_keys[count++] );
2322 lvc.cx = atolW( num );
2323 lvc.fmt = LVCFMT_LEFT;
2325 r = SendMessageW( control->hwnd, LVM_INSERTCOLUMNW, 0, (LPARAM)&lvc );
2326 msi_free( lvc.pszText );
2331 static void msi_dialog_vcl_add_drives( msi_dialog *dialog, msi_control *control )
2338 size = GetLogicalDriveStringsW( 0, NULL );
2339 if ( !size ) return;
2341 drives = msi_alloc( (size + 1) * sizeof(WCHAR) );
2342 if ( !drives ) return;
2344 GetLogicalDriveStringsW( size, drives );
2349 lvitem.mask = LVIF_TEXT;
2351 lvitem.iSubItem = 0;
2352 lvitem.pszText = ptr;
2353 lvitem.cchTextMax = lstrlenW(ptr) + 1;
2354 SendMessageW( control->hwnd, LVM_INSERTITEMW, 0, (LPARAM)&lvitem );
2356 ptr += lstrlenW(ptr) + 1;
2363 static UINT msi_dialog_volumecost_list( msi_dialog *dialog, MSIRECORD *rec )
2365 msi_control *control;
2368 style = LVS_REPORT | WS_VSCROLL | WS_HSCROLL | LVS_SHAREIMAGELISTS |
2369 LVS_AUTOARRANGE | LVS_SINGLESEL | WS_BORDER |
2370 WS_CHILD | WS_TABSTOP | WS_GROUP;
2371 control = msi_dialog_add_control( dialog, rec, WC_LISTVIEWW, style );
2373 return ERROR_FUNCTION_FAILED;
2375 msi_dialog_vcl_add_columns( dialog, control, rec );
2376 msi_dialog_vcl_add_drives( dialog, control );
2378 return ERROR_SUCCESS;
2381 static const struct control_handler msi_dialog_handler[] =
2383 { szText, msi_dialog_text_control },
2384 { szPushButton, msi_dialog_button_control },
2385 { szLine, msi_dialog_line_control },
2386 { szBitmap, msi_dialog_bitmap_control },
2387 { szCheckBox, msi_dialog_checkbox_control },
2388 { szScrollableText, msi_dialog_scrolltext_control },
2389 { szComboBox, msi_dialog_combo_control },
2390 { szEdit, msi_dialog_edit_control },
2391 { szMaskedEdit, msi_dialog_maskedit_control },
2392 { szPathEdit, msi_dialog_pathedit_control },
2393 { szProgressBar, msi_dialog_progress_bar },
2394 { szRadioButtonGroup, msi_dialog_radiogroup_control },
2395 { szIcon, msi_dialog_icon_control },
2396 { szSelectionTree, msi_dialog_selection_tree },
2397 { szGroupBox, msi_dialog_group_box },
2398 { szListBox, msi_dialog_list_box },
2399 { szDirectoryCombo, msi_dialog_directory_combo },
2400 { szDirectoryList, msi_dialog_directory_list },
2401 { szVolumeCostList, msi_dialog_volumecost_list },
2404 #define NUM_CONTROL_TYPES (sizeof msi_dialog_handler/sizeof msi_dialog_handler[0])
2406 static UINT msi_dialog_create_controls( MSIRECORD *rec, LPVOID param )
2408 msi_dialog *dialog = param;
2409 LPCWSTR control_type;
2412 /* find and call the function that can create this type of control */
2413 control_type = MSI_RecordGetString( rec, 3 );
2414 for( i=0; i<NUM_CONTROL_TYPES; i++ )
2415 if (!strcmpiW( msi_dialog_handler[i].control_type, control_type ))
2417 if( i != NUM_CONTROL_TYPES )
2418 msi_dialog_handler[i].func( dialog, rec );
2420 ERR("no handler for element type %s\n", debugstr_w(control_type));
2422 return ERROR_SUCCESS;
2425 static UINT msi_dialog_fill_controls( msi_dialog *dialog )
2427 static const WCHAR query[] = {
2428 'S','E','L','E','C','T',' ','*',' ',
2429 'F','R','O','M',' ','C','o','n','t','r','o','l',' ',
2430 'W','H','E','R','E',' ',
2431 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',0};
2433 MSIQUERY *view = NULL;
2434 MSIPACKAGE *package = dialog->package;
2436 TRACE("%p %s\n", dialog, debugstr_w(dialog->name) );
2438 /* query the Control table for all the elements of the control */
2439 r = MSI_OpenQuery( package->db, &view, query, dialog->name );
2440 if( r != ERROR_SUCCESS )
2442 ERR("query failed for dialog %s\n", debugstr_w(dialog->name));
2443 return ERROR_INVALID_PARAMETER;
2446 r = MSI_IterateRecords( view, 0, msi_dialog_create_controls, dialog );
2447 msiobj_release( &view->hdr );
2452 static UINT msi_dialog_set_control_condition( MSIRECORD *rec, LPVOID param )
2454 static const WCHAR szHide[] = { 'H','i','d','e',0 };
2455 static const WCHAR szShow[] = { 'S','h','o','w',0 };
2456 static const WCHAR szDisable[] = { 'D','i','s','a','b','l','e',0 };
2457 static const WCHAR szEnable[] = { 'E','n','a','b','l','e',0 };
2458 msi_dialog *dialog = param;
2459 msi_control *control;
2460 LPCWSTR name, action, condition;
2463 name = MSI_RecordGetString( rec, 2 );
2464 action = MSI_RecordGetString( rec, 3 );
2465 condition = MSI_RecordGetString( rec, 4 );
2466 r = MSI_EvaluateConditionW( dialog->package, condition );
2467 control = msi_dialog_find_control( dialog, name );
2468 if( r == MSICONDITION_TRUE && control )
2470 TRACE("%s control %s\n", debugstr_w(action), debugstr_w(name));
2472 /* FIXME: case sensitive? */
2473 if(!lstrcmpW(action, szHide))
2474 ShowWindow(control->hwnd, SW_HIDE);
2475 else if(!strcmpW(action, szShow))
2476 ShowWindow(control->hwnd, SW_SHOW);
2477 else if(!strcmpW(action, szDisable))
2478 EnableWindow(control->hwnd, FALSE);
2479 else if(!strcmpW(action, szEnable))
2480 EnableWindow(control->hwnd, TRUE);
2482 FIXME("Unhandled action %s\n", debugstr_w(action));
2485 return ERROR_SUCCESS;
2488 static UINT msi_dialog_evaluate_control_conditions( msi_dialog *dialog )
2490 static const WCHAR query[] = {
2491 'S','E','L','E','C','T',' ','*',' ',
2492 'F','R','O','M',' ',
2493 'C','o','n','t','r','o','l','C','o','n','d','i','t','i','o','n',' ',
2494 'W','H','E','R','E',' ',
2495 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',0
2498 MSIQUERY *view = NULL;
2499 MSIPACKAGE *package = dialog->package;
2501 TRACE("%p %s\n", dialog, debugstr_w(dialog->name) );
2503 /* query the Control table for all the elements of the control */
2504 r = MSI_OpenQuery( package->db, &view, query, dialog->name );
2505 if( r != ERROR_SUCCESS )
2507 ERR("query failed for dialog %s\n", debugstr_w(dialog->name));
2508 return ERROR_INVALID_PARAMETER;
2511 r = MSI_IterateRecords( view, 0, msi_dialog_set_control_condition, dialog );
2512 msiobj_release( &view->hdr );
2517 UINT msi_dialog_reset( msi_dialog *dialog )
2519 /* FIXME: should restore the original values of any properties we changed */
2520 return msi_dialog_evaluate_control_conditions( dialog );
2523 /* figure out the height of 10 point MS Sans Serif */
2524 static INT msi_dialog_get_sans_serif_height( HWND hwnd )
2526 static const WCHAR szSansSerif[] = {
2527 'M','S',' ','S','a','n','s',' ','S','e','r','i','f',0 };
2532 HFONT hFont, hOldFont;
2535 hdc = GetDC( hwnd );
2538 memset( &lf, 0, sizeof lf );
2539 lf.lfHeight = MulDiv(10, GetDeviceCaps(hdc, LOGPIXELSY), 72);
2540 strcpyW( lf.lfFaceName, szSansSerif );
2541 hFont = CreateFontIndirectW(&lf);
2544 hOldFont = SelectObject( hdc, hFont );
2545 r = GetTextMetricsW( hdc, &tm );
2547 height = tm.tmHeight;
2548 SelectObject( hdc, hOldFont );
2549 DeleteObject( hFont );
2551 ReleaseDC( hwnd, hdc );
2556 /* fetch the associated record from the Dialog table */
2557 static MSIRECORD *msi_get_dialog_record( msi_dialog *dialog )
2559 static const WCHAR query[] = {
2560 'S','E','L','E','C','T',' ','*',' ',
2561 'F','R','O','M',' ','D','i','a','l','o','g',' ',
2562 'W','H','E','R','E',' ',
2563 '`','D','i','a','l','o','g','`',' ','=',' ','\'','%','s','\'',0};
2564 MSIPACKAGE *package = dialog->package;
2565 MSIRECORD *rec = NULL;
2567 TRACE("%p %s\n", dialog, debugstr_w(dialog->name) );
2569 rec = MSI_QueryGetRecord( package->db, query, dialog->name );
2571 ERR("query failed for dialog %s\n", debugstr_w(dialog->name));
2576 static void msi_dialog_adjust_dialog_pos( msi_dialog *dialog, MSIRECORD *rec, LPRECT pos )
2578 static const WCHAR szScreenX[] = {'S','c','r','e','e','n','X',0};
2579 static const WCHAR szScreenY[] = {'S','c','r','e','e','n','Y',0};
2586 center.x = MSI_RecordGetInteger( rec, 2 );
2587 center.y = MSI_RecordGetInteger( rec, 3 );
2589 sz.cx = MSI_RecordGetInteger( rec, 4 );
2590 sz.cy = MSI_RecordGetInteger( rec, 5 );
2592 sz.cx = msi_dialog_scale_unit( dialog, sz.cx );
2593 sz.cy = msi_dialog_scale_unit( dialog, sz.cy );
2595 xres = msi_get_property_int( dialog->package, szScreenX, 0 );
2596 yres = msi_get_property_int( dialog->package, szScreenY, 0 );
2598 center.x = MulDiv( center.x, xres, 100 );
2599 center.y = MulDiv( center.y, yres, 100 );
2601 /* turn the client pos into the window rectangle */
2602 if (dialog->package->center_x && dialog->package->center_y)
2604 pos->left = dialog->package->center_x - sz.cx / 2.0;
2605 pos->right = pos->left + sz.cx;
2606 pos->top = dialog->package->center_y - sz.cy / 2.0;
2607 pos->bottom = pos->top + sz.cy;
2611 pos->left = center.x - sz.cx/2;
2612 pos->right = pos->left + sz.cx;
2613 pos->top = center.y - sz.cy/2;
2614 pos->bottom = pos->top + sz.cy;
2616 /* save the center */
2617 dialog->package->center_x = center.x;
2618 dialog->package->center_y = center.y;
2621 dialog->size.cx = sz.cx;
2622 dialog->size.cy = sz.cy;
2624 TRACE("%lu %lu %lu %lu\n", pos->left, pos->top, pos->right, pos->bottom);
2626 style = GetWindowLongPtrW( dialog->hwnd, GWL_STYLE );
2627 AdjustWindowRect( pos, style, FALSE );
2630 static BOOL msi_control_set_next( msi_control *control, msi_control *next )
2632 return SetWindowPos( next->hwnd, control->hwnd, 0, 0, 0, 0,
2633 SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOREDRAW |
2634 SWP_NOREPOSITION | SWP_NOSENDCHANGING | SWP_NOSIZE );
2637 static UINT msi_dialog_set_tab_order( msi_dialog *dialog )
2639 msi_control *control, *tab_next;
2641 LIST_FOR_EACH_ENTRY( control, &dialog->controls, msi_control, entry )
2643 tab_next = msi_dialog_find_control( dialog, control->tabnext );
2646 msi_control_set_next( control, tab_next );
2649 return ERROR_SUCCESS;
2652 static void msi_dialog_set_first_control( msi_dialog* dialog, LPCWSTR name )
2654 msi_control *control;
2656 control = msi_dialog_find_control( dialog, name );
2658 dialog->hWndFocus = control->hwnd;
2660 dialog->hWndFocus = NULL;
2663 static LRESULT msi_dialog_oncreate( HWND hwnd, LPCREATESTRUCTW cs )
2665 static const WCHAR df[] = {
2666 'D','e','f','a','u','l','t','U','I','F','o','n','t',0 };
2667 static const WCHAR dfv[] = {
2668 'M','S',' ','S','h','e','l','l',' ','D','l','g',0 };
2669 msi_dialog *dialog = (msi_dialog*) cs->lpCreateParams;
2670 MSIRECORD *rec = NULL;
2671 LPWSTR title = NULL;
2674 TRACE("%p %p\n", dialog, dialog->package);
2676 dialog->hwnd = hwnd;
2677 SetWindowLongPtrW( hwnd, GWLP_USERDATA, (LONG_PTR) dialog );
2679 rec = msi_get_dialog_record( dialog );
2682 TRACE("No record found for dialog %s\n", debugstr_w(dialog->name));
2686 dialog->scale = msi_dialog_get_sans_serif_height(dialog->hwnd);
2688 msi_dialog_adjust_dialog_pos( dialog, rec, &pos );
2690 dialog->attributes = MSI_RecordGetInteger( rec, 6 );
2692 dialog->default_font = msi_dup_property( dialog->package, df );
2693 if (!dialog->default_font)
2695 dialog->default_font = strdupW(dfv);
2696 if (!dialog->default_font) return -1;
2699 title = msi_get_deformatted_field( dialog->package, rec, 7 );
2700 SetWindowTextW( hwnd, title );
2703 SetWindowPos( hwnd, 0, pos.left, pos.top,
2704 pos.right - pos.left, pos.bottom - pos.top,
2705 SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOREDRAW );
2707 msi_dialog_build_font_list( dialog );
2708 msi_dialog_fill_controls( dialog );
2709 msi_dialog_evaluate_control_conditions( dialog );
2710 msi_dialog_set_tab_order( dialog );
2711 msi_dialog_set_first_control( dialog, MSI_RecordGetString( rec, 8 ) );
2712 msiobj_release( &rec->hdr );
2717 static UINT msi_dialog_send_event( msi_dialog *dialog, LPCWSTR event, LPCWSTR arg )
2719 LPWSTR event_fmt = NULL, arg_fmt = NULL;
2721 TRACE("Sending control event %s %s\n", debugstr_w(event), debugstr_w(arg));
2723 deformat_string( dialog->package, event, &event_fmt );
2724 deformat_string( dialog->package, arg, &arg_fmt );
2726 dialog->event_handler( dialog->package, event_fmt, arg_fmt, dialog );
2728 msi_free( event_fmt );
2729 msi_free( arg_fmt );
2731 return ERROR_SUCCESS;
2734 static UINT msi_dialog_set_property( msi_dialog *dialog, LPCWSTR event, LPCWSTR arg )
2736 static const WCHAR szNullArg[] = { '{','}',0 };
2737 LPWSTR p, prop, arg_fmt = NULL;
2740 len = strlenW(event);
2741 prop = msi_alloc( len*sizeof(WCHAR));
2742 strcpyW( prop, &event[1] );
2743 p = strchrW( prop, ']' );
2744 if( p && p[1] == 0 )
2747 if( strcmpW( szNullArg, arg ) )
2748 deformat_string( dialog->package, arg, &arg_fmt );
2749 MSI_SetPropertyW( dialog->package, prop, arg_fmt );
2750 msi_free( arg_fmt );
2753 ERR("Badly formatted property string - what happens?\n");
2755 return ERROR_SUCCESS;
2758 static UINT msi_dialog_control_event( MSIRECORD *rec, LPVOID param )
2760 msi_dialog *dialog = param;
2761 LPCWSTR condition, event, arg;
2764 condition = MSI_RecordGetString( rec, 5 );
2765 r = MSI_EvaluateConditionW( dialog->package, condition );
2766 if( r == MSICONDITION_TRUE || r == MSICONDITION_NONE )
2768 event = MSI_RecordGetString( rec, 3 );
2769 arg = MSI_RecordGetString( rec, 4 );
2770 if( event[0] == '[' )
2771 msi_dialog_set_property( dialog, event, arg );
2773 msi_dialog_send_event( dialog, event, arg );
2776 return ERROR_SUCCESS;
2779 static UINT msi_dialog_button_handler( msi_dialog *dialog,
2780 msi_control *control, WPARAM param )
2782 static const WCHAR query[] = {
2783 'S','E','L','E','C','T',' ','*',' ',
2784 'F','R','O','M',' ','C','o','n','t','r','o','l','E','v','e','n','t',' ',
2785 'W','H','E','R','E',' ',
2786 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',' ',
2788 '`','C','o','n','t','r','o','l','_','`',' ','=',' ','\'','%','s','\'',' ',
2789 'O','R','D','E','R',' ','B','Y',' ','`','O','r','d','e','r','i','n','g','`',0
2791 MSIQUERY *view = NULL;
2794 if( HIWORD(param) != BN_CLICKED )
2795 return ERROR_SUCCESS;
2797 r = MSI_OpenQuery( dialog->package->db, &view, query,
2798 dialog->name, control->name );
2799 if( r != ERROR_SUCCESS )
2801 ERR("query failed\n");
2805 r = MSI_IterateRecords( view, 0, msi_dialog_control_event, dialog );
2806 msiobj_release( &view->hdr );
2811 static UINT msi_dialog_get_checkbox_state( msi_dialog *dialog,
2812 msi_control *control )
2814 WCHAR state[2] = { 0 };
2817 MSI_GetPropertyW( dialog->package, control->property, state, &sz );
2818 return state[0] ? 1 : 0;
2821 static void msi_dialog_set_checkbox_state( msi_dialog *dialog,
2822 msi_control *control, UINT state )
2824 static const WCHAR szState[] = { '1', 0 };
2827 /* if uncheck then the property is set to NULL */
2830 MSI_SetPropertyW( dialog->package, control->property, NULL );
2834 /* check for a custom state */
2835 if (control->value && control->value[0])
2836 val = control->value;
2840 MSI_SetPropertyW( dialog->package, control->property, val );
2843 static void msi_dialog_checkbox_sync_state( msi_dialog *dialog,
2844 msi_control *control )
2848 state = msi_dialog_get_checkbox_state( dialog, control );
2849 SendMessageW( control->hwnd, BM_SETCHECK,
2850 state ? BST_CHECKED : BST_UNCHECKED, 0 );
2853 static UINT msi_dialog_checkbox_handler( msi_dialog *dialog,
2854 msi_control *control, WPARAM param )
2858 if( HIWORD(param) != BN_CLICKED )
2859 return ERROR_SUCCESS;
2861 TRACE("clicked checkbox %s, set %s\n", debugstr_w(control->name),
2862 debugstr_w(control->property));
2864 state = msi_dialog_get_checkbox_state( dialog, control );
2865 state = state ? 0 : 1;
2866 msi_dialog_set_checkbox_state( dialog, control, state );
2867 msi_dialog_checkbox_sync_state( dialog, control );
2869 return msi_dialog_button_handler( dialog, control, param );
2872 static UINT msi_dialog_edit_handler( msi_dialog *dialog,
2873 msi_control *control, WPARAM param )
2877 if( HIWORD(param) != EN_CHANGE )
2878 return ERROR_SUCCESS;
2880 TRACE("edit %s contents changed, set %s\n", debugstr_w(control->name),
2881 debugstr_w(control->property));
2883 buf = msi_get_window_text( control->hwnd );
2884 MSI_SetPropertyW( dialog->package, control->property, buf );
2888 return ERROR_SUCCESS;
2891 static UINT msi_dialog_radiogroup_handler( msi_dialog *dialog,
2892 msi_control *control, WPARAM param )
2894 if( HIWORD(param) != BN_CLICKED )
2895 return ERROR_SUCCESS;
2897 TRACE("clicked radio button %s, set %s\n", debugstr_w(control->name),
2898 debugstr_w(control->property));
2900 MSI_SetPropertyW( dialog->package, control->property, control->name );
2902 return msi_dialog_button_handler( dialog, control, param );
2905 static LRESULT msi_dialog_oncommand( msi_dialog *dialog, WPARAM param, HWND hwnd )
2907 msi_control *control = NULL;
2909 TRACE("%p %p %08x\n", dialog, hwnd, param);
2914 control = msi_dialog_find_control( dialog, dialog->control_default );
2916 case 2: /* escape */
2917 control = msi_dialog_find_control( dialog, dialog->control_cancel );
2920 control = msi_dialog_find_control_by_hwnd( dialog, hwnd );
2925 if( control->handler )
2927 control->handler( dialog, control, param );
2928 msi_dialog_evaluate_control_conditions( dialog );
2932 ERR("button click from nowhere %p %d %p\n", dialog, param, hwnd);
2936 static LRESULT msi_dialog_onnotify( msi_dialog *dialog, LPARAM param )
2938 LPNMHDR nmhdr = (LPNMHDR) param;
2939 msi_control *control = msi_dialog_find_control_by_hwnd( dialog, nmhdr->hwndFrom );
2941 TRACE("%p %p", dialog, nmhdr->hwndFrom);
2943 if ( control && control->handler )
2944 control->handler( dialog, control, param );
2949 static void msi_dialog_setfocus( msi_dialog *dialog )
2951 HWND hwnd = dialog->hWndFocus;
2953 hwnd = GetNextDlgTabItem( dialog->hwnd, hwnd, TRUE);
2954 hwnd = GetNextDlgTabItem( dialog->hwnd, hwnd, FALSE);
2956 dialog->hWndFocus = hwnd;
2959 static LRESULT WINAPI MSIDialog_WndProc( HWND hwnd, UINT msg,
2960 WPARAM wParam, LPARAM lParam )
2962 msi_dialog *dialog = (LPVOID) GetWindowLongPtrW( hwnd, GWLP_USERDATA );
2964 TRACE("0x%04x\n", msg);
2969 dialog->package->center_x = LOWORD(lParam) + dialog->size.cx / 2.0;
2970 dialog->package->center_y = HIWORD(lParam) + dialog->size.cy / 2.0;
2974 return msi_dialog_oncreate( hwnd, (LPCREATESTRUCTW)lParam );
2977 return msi_dialog_oncommand( dialog, wParam, (HWND)lParam );
2980 if( LOWORD(wParam) == WA_INACTIVE )
2981 dialog->hWndFocus = GetFocus();
2983 msi_dialog_setfocus( dialog );
2987 msi_dialog_setfocus( dialog );
2990 /* bounce back to our subclassed static control */
2991 case WM_CTLCOLORSTATIC:
2992 return SendMessageW( (HWND) lParam, WM_CTLCOLORSTATIC, wParam, lParam );
2995 dialog->hwnd = NULL;
2998 return msi_dialog_onnotify( dialog, lParam );
3000 return DefWindowProcW(hwnd, msg, wParam, lParam);
3003 static BOOL CALLBACK msi_radioground_child_enum( HWND hWnd, LPARAM lParam )
3005 EnableWindow( hWnd, lParam );
3009 static LRESULT WINAPI MSIRadioGroup_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
3011 WNDPROC oldproc = (WNDPROC) GetPropW(hWnd, szButtonData);
3014 TRACE("hWnd %p msg %04x wParam 0x%08x lParam 0x%08lx\n", hWnd, msg, wParam, lParam);
3016 if (msg == WM_COMMAND) /* Forward notifications to dialog */
3017 SendMessageW(GetParent(hWnd), msg, wParam, lParam);
3019 r = CallWindowProcW(oldproc, hWnd, msg, wParam, lParam);
3021 /* make sure the radio buttons show as disabled if the parent is disabled */
3022 if (msg == WM_ENABLE)
3023 EnumChildWindows( hWnd, msi_radioground_child_enum, wParam );
3028 static LRESULT WINAPI MSIHiddenWindowProc( HWND hwnd, UINT msg,
3029 WPARAM wParam, LPARAM lParam )
3031 msi_dialog *dialog = (msi_dialog*) lParam;
3033 TRACE("%d %p\n", msg, dialog);
3037 case WM_MSI_DIALOG_CREATE:
3038 return msi_dialog_run_message_loop( dialog );
3039 case WM_MSI_DIALOG_DESTROY:
3040 msi_dialog_destroy( dialog );
3043 return DefWindowProcW( hwnd, msg, wParam, lParam );
3046 /* functions that interface to other modules within MSI */
3048 msi_dialog *msi_dialog_create( MSIPACKAGE* package, LPCWSTR szDialogName,
3049 msi_dialog_event_handler event_handler )
3051 MSIRECORD *rec = NULL;
3054 TRACE("%p %s\n", package, debugstr_w(szDialogName));
3056 /* allocate the structure for the dialog to use */
3057 dialog = msi_alloc_zero( sizeof *dialog + sizeof(WCHAR)*strlenW(szDialogName) );
3060 strcpyW( dialog->name, szDialogName );
3061 msiobj_addref( &package->hdr );
3062 dialog->package = package;
3063 dialog->event_handler = event_handler;
3064 dialog->finished = 0;
3065 list_init( &dialog->controls );
3067 /* verify that the dialog exists */
3068 rec = msi_get_dialog_record( dialog );
3071 msiobj_release( &package->hdr );
3075 dialog->attributes = MSI_RecordGetInteger( rec, 6 );
3076 dialog->control_default = strdupW( MSI_RecordGetString( rec, 9 ) );
3077 dialog->control_cancel = strdupW( MSI_RecordGetString( rec, 10 ) );
3078 msiobj_release( &rec->hdr );
3083 static void msi_process_pending_messages( HWND hdlg )
3087 while( PeekMessageW( &msg, 0, 0, 0, PM_REMOVE ) )
3089 if( hdlg && IsDialogMessageW( hdlg, &msg ))
3091 TranslateMessage( &msg );
3092 DispatchMessageW( &msg );
3096 void msi_dialog_end_dialog( msi_dialog *dialog )
3098 TRACE("%p\n", dialog);
3099 dialog->finished = 1;
3100 PostMessageW(dialog->hwnd, WM_NULL, 0, 0);
3103 void msi_dialog_check_messages( HANDLE handle )
3107 /* in threads other than the UI thread, block */
3108 if( uiThreadId != GetCurrentThreadId() )
3111 WaitForSingleObject( handle, INFINITE );
3115 /* there's two choices for the UI thread */
3118 msi_process_pending_messages( NULL );
3124 * block here until somebody creates a new dialog or
3125 * the handle we're waiting on becomes ready
3127 r = MsgWaitForMultipleObjects( 1, &handle, 0, INFINITE, QS_ALLINPUT );
3128 if( r == WAIT_OBJECT_0 )
3133 UINT msi_dialog_run_message_loop( msi_dialog *dialog )
3138 if( uiThreadId != GetCurrentThreadId() )
3139 return SendMessageW( hMsiHiddenWindow, WM_MSI_DIALOG_CREATE, 0, (LPARAM) dialog );
3141 /* create the dialog window, don't show it yet */
3142 style = WS_OVERLAPPED;
3143 if( dialog->attributes & msidbDialogAttributesVisible )
3144 style |= WS_VISIBLE;
3146 hwnd = CreateWindowW( szMsiDialogClass, dialog->name, style,
3147 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
3148 NULL, NULL, NULL, dialog );
3151 ERR("Failed to create dialog %s\n", debugstr_w( dialog->name ));
3152 return ERROR_FUNCTION_FAILED;
3155 ShowWindow( hwnd, SW_SHOW );
3156 /* UpdateWindow( hwnd ); - and causes the transparent static controls not to paint */
3158 if( dialog->attributes & msidbDialogAttributesModal )
3160 while( !dialog->finished )
3162 MsgWaitForMultipleObjects( 0, NULL, 0, INFINITE, QS_ALLINPUT );
3163 msi_process_pending_messages( dialog->hwnd );
3167 return ERROR_IO_PENDING;
3169 return ERROR_SUCCESS;
3172 void msi_dialog_do_preview( msi_dialog *dialog )
3175 dialog->attributes |= msidbDialogAttributesVisible;
3176 dialog->attributes &= ~msidbDialogAttributesModal;
3177 msi_dialog_run_message_loop( dialog );
3180 void msi_dialog_destroy( msi_dialog *dialog )
3182 if( uiThreadId != GetCurrentThreadId() )
3184 SendMessageW( hMsiHiddenWindow, WM_MSI_DIALOG_DESTROY, 0, (LPARAM) dialog );
3189 ShowWindow( dialog->hwnd, SW_HIDE );
3192 DestroyWindow( dialog->hwnd );
3194 /* destroy the list of controls */
3195 while( !list_empty( &dialog->controls ) )
3197 msi_control *t = LIST_ENTRY( list_head( &dialog->controls ),
3198 msi_control, entry );
3199 list_remove( &t->entry );
3200 /* leave dialog->hwnd - destroying parent destroys child windows */
3201 msi_free( t->property );
3202 msi_free( t->value );
3204 DeleteObject( t->hBitmap );
3206 DestroyIcon( t->hIcon );
3207 msi_free( t->tabnext );
3208 msi_free( t->type );
3211 FreeLibrary( t->hDll );
3214 /* destroy the list of fonts */
3215 while( dialog->font_list )
3217 msi_font *t = dialog->font_list;
3218 dialog->font_list = t->next;
3219 DeleteObject( t->hfont );
3222 msi_free( dialog->default_font );
3224 msi_free( dialog->control_default );
3225 msi_free( dialog->control_cancel );
3226 msiobj_release( &dialog->package->hdr );
3227 dialog->package = NULL;
3231 BOOL msi_dialog_register_class( void )
3235 ZeroMemory( &cls, sizeof cls );
3236 cls.lpfnWndProc = MSIDialog_WndProc;
3237 cls.hInstance = NULL;
3238 cls.hIcon = LoadIconW(0, (LPWSTR)IDI_APPLICATION);
3239 cls.hCursor = LoadCursorW(0, (LPWSTR)IDC_ARROW);
3240 cls.hbrBackground = (HBRUSH)(COLOR_3DFACE + 1);
3241 cls.lpszMenuName = NULL;
3242 cls.lpszClassName = szMsiDialogClass;
3244 if( !RegisterClassW( &cls ) )
3247 cls.lpfnWndProc = MSIHiddenWindowProc;
3248 cls.lpszClassName = szMsiHiddenWindow;
3250 if( !RegisterClassW( &cls ) )
3253 uiThreadId = GetCurrentThreadId();
3255 hMsiHiddenWindow = CreateWindowW( szMsiHiddenWindow, NULL, WS_OVERLAPPED,
3256 0, 0, 100, 100, NULL, NULL, NULL, NULL );
3257 if( !hMsiHiddenWindow )
3263 void msi_dialog_unregister_class( void )
3265 DestroyWindow( hMsiHiddenWindow );
3266 hMsiHiddenWindow = NULL;
3267 UnregisterClassW( szMsiDialogClass, NULL );
3268 UnregisterClassW( szMsiHiddenWindow, NULL );