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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
37 #include "wine/debug.h"
38 #include "wine/unicode.h"
42 WINE_DEFAULT_DEBUG_CHANNEL(msi);
45 struct msi_control_tag;
46 typedef struct msi_control_tag msi_control;
47 typedef UINT (*msi_handler)( msi_dialog *, msi_control *, WPARAM );
49 struct msi_control_tag
51 struct msi_control_tag *next;
62 typedef struct msi_font_tag
64 struct msi_font_tag *next;
72 msi_dialog_event_handler event_handler;
79 msi_control *control_list;
84 typedef UINT (*msi_dialog_control_func)( msi_dialog *dialog, MSIRECORD *rec );
85 struct control_handler
88 msi_dialog_control_func func;
96 } radio_button_group_descr;
98 const WCHAR szMsiDialogClass[] = {
99 'M','s','i','D','i','a','l','o','g','C','l','o','s','e','C','l','a','s','s',0
101 const WCHAR szMsiHiddenWindow[] = {
102 'M','s','i','H','i','d','d','e','n','W','i','n','d','o','w',0 };
103 const static WCHAR szStatic[] = { 'S','t','a','t','i','c',0 };
104 const static WCHAR szButton[] = { 'B','U','T','T','O','N', 0 };
105 const static WCHAR szButtonData[] = { 'M','S','I','D','A','T','A',0 };
106 static const WCHAR szText[] = { 'T','e','x','t',0 };
107 static const WCHAR szPushButton[] = { 'P','u','s','h','B','u','t','t','o','n',0 };
108 static const WCHAR szLine[] = { 'L','i','n','e',0 };
109 static const WCHAR szBitmap[] = { 'B','i','t','m','a','p',0 };
110 static const WCHAR szCheckBox[] = { 'C','h','e','c','k','B','o','x',0 };
111 static const WCHAR szScrollableText[] = {
112 'S','c','r','o','l','l','a','b','l','e','T','e','x','t',0 };
113 static const WCHAR szComboBox[] = { 'C','o','m','b','o','B','o','x',0 };
114 static const WCHAR szEdit[] = { 'E','d','i','t',0 };
115 static const WCHAR szMaskedEdit[] = { 'M','a','s','k','e','d','E','d','i','t',0 };
116 static const WCHAR szPathEdit[] = { 'P','a','t','h','E','d','i','t',0 };
117 static const WCHAR szRadioButtonGroup[] = {
118 'R','a','d','i','o','B','u','t','t','o','n','G','r','o','u','p',0 };
119 static const WCHAR szIcon[] = { 'I','c','o','n',0 };
121 static UINT msi_dialog_checkbox_handler( msi_dialog *, msi_control *, WPARAM );
122 static void msi_dialog_checkbox_sync_state( msi_dialog *, msi_control * );
123 static UINT msi_dialog_button_handler( msi_dialog *, msi_control *, WPARAM );
124 static UINT msi_dialog_edit_handler( msi_dialog *, msi_control *, WPARAM );
125 static UINT msi_dialog_radiogroup_handler( msi_dialog *, msi_control *, WPARAM param );
126 static UINT msi_dialog_evaluate_control_conditions( msi_dialog *dialog );
127 static LRESULT WINAPI MSIRadioGroup_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
130 /* dialog sequencing */
132 #define WM_MSI_DIALOG_CREATE (WM_USER+0x100)
133 #define WM_MSI_DIALOG_DESTROY (WM_USER+0x101)
135 static DWORD uiThreadId;
136 static HWND hMsiHiddenWindow;
137 static HMODULE hRichedit;
139 static INT msi_dialog_scale_unit( msi_dialog *dialog, INT val )
141 return (dialog->scale * val + 5) / 10;
144 static msi_control *msi_dialog_find_control( msi_dialog *dialog, LPCWSTR name )
146 msi_control *control;
150 for( control = dialog->control_list; control; control = control->next )
151 if( !strcmpW( control->name, name ) ) /* FIXME: case sensitive? */
156 static msi_control *msi_dialog_find_control_by_hwnd( msi_dialog *dialog, HWND hwnd )
158 msi_control *control;
160 for( control = dialog->control_list; control; control = control->next )
161 if( hwnd == control->hwnd )
167 * msi_dialog_get_style
169 * Extract the {\style} string from the front of the text to display and
170 * update the pointer.
172 static LPWSTR msi_dialog_get_style( LPCWSTR *text )
175 LPCWSTR p = *text, q;
180 q = strchrW( p, '}' );
188 ret = HeapAlloc( GetProcessHeap(), 0, len*sizeof(WCHAR) );
191 memcpy( ret, p, len*sizeof(WCHAR) );
196 static UINT msi_dialog_add_font( MSIRECORD *rec, LPVOID param )
198 msi_dialog *dialog = param;
205 /* create a font and add it to the list */
206 name = MSI_RecordGetString( rec, 1 );
207 font = HeapAlloc( GetProcessHeap(), 0,
208 sizeof *font + strlenW( name )*sizeof (WCHAR) );
209 strcpyW( font->name, name );
210 font->next = dialog->font_list;
211 dialog->font_list = font;
213 memset( &lf, 0, sizeof lf );
214 face = MSI_RecordGetString( rec, 2 );
215 lf.lfHeight = MSI_RecordGetInteger( rec, 3 );
216 style = MSI_RecordGetInteger( rec, 5 );
217 if( style & msidbTextStyleStyleBitsBold )
218 lf.lfWeight = FW_BOLD;
219 if( style & msidbTextStyleStyleBitsItalic )
221 if( style & msidbTextStyleStyleBitsUnderline )
222 lf.lfUnderline = TRUE;
223 if( style & msidbTextStyleStyleBitsStrike )
224 lf.lfStrikeOut = TRUE;
225 lstrcpynW( lf.lfFaceName, face, LF_FACESIZE );
227 /* adjust the height */
228 hdc = GetDC( dialog->hwnd );
231 lf.lfHeight = -MulDiv(lf.lfHeight, GetDeviceCaps(hdc, LOGPIXELSY), 72);
232 ReleaseDC( dialog->hwnd, hdc );
235 font->hfont = CreateFontIndirectW( &lf );
237 TRACE("Adding font style %s\n", debugstr_w(font->name) );
239 return ERROR_SUCCESS;
242 static msi_font *msi_dialog_find_font( msi_dialog *dialog, LPCWSTR name )
246 for( font = dialog->font_list; font; font = font->next )
247 if( !strcmpW( font->name, name ) ) /* FIXME: case sensitive? */
253 static UINT msi_dialog_set_font( msi_dialog *dialog, HWND hwnd, LPCWSTR name )
257 font = msi_dialog_find_font( dialog, name );
259 SendMessageW( hwnd, WM_SETFONT, (WPARAM) font->hfont, TRUE );
261 ERR("No font entry for %s\n", debugstr_w(name));
262 return ERROR_SUCCESS;
265 static UINT msi_dialog_build_font_list( msi_dialog *dialog )
267 static const WCHAR query[] = {
268 'S','E','L','E','C','T',' ','*',' ',
269 'F','R','O','M',' ','`','T','e','x','t','S','t','y','l','e','`',' ',0
272 MSIQUERY *view = NULL;
274 TRACE("dialog %p\n", dialog );
276 r = MSI_OpenQuery( dialog->package->db, &view, query );
277 if( r != ERROR_SUCCESS )
280 r = MSI_IterateRecords( view, NULL, msi_dialog_add_font, dialog );
281 msiobj_release( &view->hdr );
286 static msi_control *msi_dialog_create_window( msi_dialog *dialog,
287 MSIRECORD *rec, LPCWSTR szCls, LPCWSTR name, LPCWSTR text,
288 DWORD style, HWND parent )
290 DWORD x, y, width, height;
291 LPWSTR font = NULL, title = NULL;
292 msi_control *control;
296 control = HeapAlloc( GetProcessHeap(), 0,
297 sizeof *control + strlenW(name)*sizeof(WCHAR) );
298 strcpyW( control->name, name );
299 control->next = dialog->control_list;
300 dialog->control_list = control;
301 control->handler = NULL;
302 control->property = NULL;
303 control->value = NULL;
304 control->hBitmap = NULL;
305 control->hIcon = NULL;
306 control->tabnext = strdupW( MSI_RecordGetString( rec, 11) );
308 x = MSI_RecordGetInteger( rec, 4 );
309 y = MSI_RecordGetInteger( rec, 5 );
310 width = MSI_RecordGetInteger( rec, 6 );
311 height = MSI_RecordGetInteger( rec, 7 );
313 x = msi_dialog_scale_unit( dialog, x );
314 y = msi_dialog_scale_unit( dialog, y );
315 width = msi_dialog_scale_unit( dialog, width );
316 height = msi_dialog_scale_unit( dialog, height );
320 font = msi_dialog_get_style( &text );
321 deformat_string( dialog->package, text, &title );
324 control->hwnd = CreateWindowW( szCls, title, style,
325 x, y, width, height, parent, NULL, NULL, NULL );
327 TRACE("Dialog %s control %s hwnd %p\n",
328 debugstr_w(dialog->name), debugstr_w(text), control->hwnd );
330 msi_dialog_set_font( dialog, control->hwnd,
331 font ? font : dialog->default_font );
333 HeapFree( GetProcessHeap(), 0, font );
334 HeapFree( GetProcessHeap(), 0, title );
339 static MSIRECORD *msi_get_binary_record( MSIDATABASE *db, LPCWSTR name )
341 const static WCHAR query[] = {
342 's','e','l','e','c','t',' ','*',' ',
343 'f','r','o','m',' ','B','i','n','a','r','y',' ',
344 'w','h','e','r','e',' ',
345 '`','N','a','m','e','`',' ','=',' ','\'','%','s','\'',0
348 return MSI_QueryGetRecord( db, query, name );
351 static LPWSTR msi_create_tmp_path(void)
355 static const WCHAR prefix[] = { 'm','s','i',0 };
358 r = GetTempPathW( MAX_PATH, tmp );
361 len = lstrlenW( tmp ) + 20;
362 path = HeapAlloc( GetProcessHeap(), 0, len * sizeof (WCHAR) );
365 r = GetTempFileNameW( tmp, prefix, 0, path );
368 HeapFree( GetProcessHeap(), 0, path );
376 static HANDLE msi_load_image( MSIDATABASE *db, LPCWSTR name, UINT type,
377 UINT cx, UINT cy, UINT flags )
379 MSIRECORD *rec = NULL;
380 HANDLE himage = NULL;
384 TRACE("%p %s %u %u %08x\n", db, debugstr_w(name), cx, cy, flags);
386 tmp = msi_create_tmp_path();
390 rec = msi_get_binary_record( db, name );
393 r = MSI_RecordStreamToFile( rec, 2, tmp );
394 if( r == ERROR_SUCCESS )
396 himage = LoadImageW( 0, tmp, type, cx, cy, flags );
399 msiobj_release( &rec->hdr );
402 HeapFree( GetProcessHeap(), 0, tmp );
406 static HICON msi_load_icon( MSIDATABASE *db, LPCWSTR text, UINT attributes )
408 DWORD cx = 0, cy = 0, flags;
410 flags = LR_LOADFROMFILE | LR_DEFAULTSIZE;
411 if( attributes & msidbControlAttributesFixedSize )
413 flags &= ~LR_DEFAULTSIZE;
414 if( attributes & msidbControlAttributesIconSize16 )
419 if( attributes & msidbControlAttributesIconSize32 )
424 /* msidbControlAttributesIconSize48 handled by above logic */
426 return msi_load_image( db, text, IMAGE_ICON, cx, cy, flags );
430 /* called from the Control Event subscription code */
431 void msi_dialog_handle_event( msi_dialog* dialog, LPCWSTR control,
432 LPCWSTR attribute, MSIRECORD *rec )
437 ctrl = msi_dialog_find_control( dialog, control );
440 if( lstrcmpW(attribute, szText) )
442 text = MSI_RecordGetString( rec , 1 );
443 SetWindowTextW( ctrl->hwnd, text );
444 msi_dialog_check_messages( NULL );
447 static void msi_dialog_map_events(msi_dialog* dialog, LPCWSTR control)
449 static WCHAR Query[] = {
450 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
451 '`','E','v','e','n','t','M','a','p','p','i','n','g','`',' ',
452 'W','H','E','R','E',' ',
453 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',' ',
455 '`','C','o','n','t','r','o','l','_','`',' ','=',' ','\'','%','s','\'',0
458 LPCWSTR event, attribute;
460 row = MSI_QueryGetRecord( dialog->package->db, Query, dialog->name, control );
464 event = MSI_RecordGetString( row, 3 );
465 attribute = MSI_RecordGetString( row, 4 );
466 ControlEvent_SubscribeToEvent( dialog->package, event, control, attribute );
467 msiobj_release( &row->hdr );
470 /* everything except radio buttons */
471 static msi_control *msi_dialog_add_control( msi_dialog *dialog,
472 MSIRECORD *rec, LPCWSTR szCls, DWORD style )
477 name = MSI_RecordGetString( rec, 2 );
478 attributes = MSI_RecordGetInteger( rec, 8 );
479 text = MSI_RecordGetString( rec, 10 );
480 if( attributes & msidbControlAttributesVisible )
482 if( ~attributes & msidbControlAttributesEnabled )
483 style |= WS_DISABLED;
485 msi_dialog_map_events(dialog, name);
487 return msi_dialog_create_window( dialog, rec, szCls, name, text,
488 style, dialog->hwnd );
498 * we don't erase our own background,
499 * so we have to make sure that the parent window redraws first
501 static void msi_text_on_settext( HWND hWnd )
506 hParent = GetParent( hWnd );
507 GetWindowRect( hWnd, &rc );
508 MapWindowPoints( NULL, hParent, (LPPOINT) &rc, 2 );
509 InvalidateRect( hParent, &rc, TRUE );
512 static LRESULT WINAPI
513 MSIText_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
515 struct msi_text_info *info;
518 TRACE("%p %04x %08x %08lx\n", hWnd, msg, wParam, lParam);
520 info = GetPropW(hWnd, szButtonData);
522 if( msg == WM_CTLCOLORSTATIC &&
523 ( info->attributes & msidbControlAttributesTransparent ) )
525 SetBkMode( (HDC)wParam, TRANSPARENT );
526 return (LRESULT) GetStockObject(NULL_BRUSH);
529 r = CallWindowProcW(info->oldproc, hWnd, msg, wParam, lParam);
534 msi_text_on_settext( hWnd );
537 HeapFree( GetProcessHeap(), 0, info );
538 RemovePropW( hWnd, szButtonData );
545 static UINT msi_dialog_text_control( msi_dialog *dialog, MSIRECORD *rec )
547 msi_control *control;
548 struct msi_text_info *info;
550 TRACE("%p %p\n", dialog, rec);
552 control = msi_dialog_add_control( dialog, rec, szStatic, SS_LEFT | WS_GROUP );
554 return ERROR_FUNCTION_FAILED;
556 info = HeapAlloc( GetProcessHeap(), 0, sizeof *info );
558 return ERROR_SUCCESS;
560 info->attributes = MSI_RecordGetInteger( rec, 8 );
561 if( info->attributes & msidbControlAttributesTransparent )
562 SetWindowLongPtrW( control->hwnd, GWL_EXSTYLE, WS_EX_TRANSPARENT );
564 info->oldproc = (WNDPROC) SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
565 (LONG_PTR)MSIText_WndProc );
566 SetPropW( control->hwnd, szButtonData, info );
568 return ERROR_SUCCESS;
571 static UINT msi_dialog_button_control( msi_dialog *dialog, MSIRECORD *rec )
573 msi_control *control;
574 UINT attributes, style;
577 TRACE("%p %p\n", dialog, rec);
580 attributes = MSI_RecordGetInteger( rec, 8 );
581 if( attributes & msidbControlAttributesIcon )
584 control = msi_dialog_add_control( dialog, rec, szButton, style );
586 return ERROR_FUNCTION_FAILED;
588 control->handler = msi_dialog_button_handler;
591 text = MSI_RecordGetString( rec, 10 );
592 control->hIcon = msi_load_icon( dialog->package->db, text, attributes );
593 if( attributes & msidbControlAttributesIcon )
594 SendMessageW( control->hwnd, BM_SETIMAGE, IMAGE_ICON, (LPARAM) control->hIcon );
596 return ERROR_SUCCESS;
599 static LPWSTR msi_get_checkbox_value( msi_dialog *dialog, LPCWSTR prop )
601 const static WCHAR query[] = {
602 'S','E','L','E','C','T',' ','*',' ',
603 'F','R','O','M',' ','`','C','h','e','c','k','B','o','x',' ','`',
604 'W','H','E','R','E',' ',
605 '`','P','r','o','p','e','r','t','y','`',' ','=',' ',
608 MSIRECORD *rec = NULL;
612 /* find if there is a value associated with the checkbox */
613 rec = MSI_QueryGetRecord( dialog->package->db, query, prop );
617 val = MSI_RecordGetString( rec, 2 );
620 deformat_string( dialog->package, val, &ret );
623 HeapFree( GetProcessHeap(), 0, ret );
627 msiobj_release( &rec->hdr );
631 ret = load_dynamic_property(dialog->package, prop, NULL);
634 HeapFree( GetProcessHeap(), 0, ret );
641 static UINT msi_dialog_checkbox_control( msi_dialog *dialog, MSIRECORD *rec )
643 msi_control *control;
646 TRACE("%p %p\n", dialog, rec);
648 control = msi_dialog_add_control( dialog, rec, szButton,
649 BS_CHECKBOX | BS_MULTILINE | WS_TABSTOP );
650 control->handler = msi_dialog_checkbox_handler;
651 prop = MSI_RecordGetString( rec, 9 );
654 control->property = strdupW( prop );
655 control->value = msi_get_checkbox_value( dialog, prop );
656 TRACE("control %s value %s\n", debugstr_w(control->property),
657 debugstr_w(control->value));
659 msi_dialog_checkbox_sync_state( dialog, control );
661 return ERROR_SUCCESS;
664 static UINT msi_dialog_line_control( msi_dialog *dialog, MSIRECORD *rec )
666 TRACE("%p %p\n", dialog, rec);
668 msi_dialog_add_control( dialog, rec, szStatic, SS_ETCHEDHORZ | SS_SUNKEN );
669 return ERROR_SUCCESS;
672 struct msi_streamin_info
679 static DWORD CALLBACK
680 msi_richedit_stream_in( DWORD_PTR arg, LPBYTE buffer, LONG count, LONG *pcb )
682 struct msi_streamin_info *info = (struct msi_streamin_info*) arg;
684 if( (count + info->offset) > info->length )
685 count = info->length - info->offset;
686 memcpy( buffer, &info->string[ info->offset ], count );
688 info->offset += count;
690 TRACE("%ld/%ld\n", info->offset, info->length);
695 static UINT msi_dialog_scrolltext_control( msi_dialog *dialog, MSIRECORD *rec )
697 const static WCHAR szRichEdit20W[] = {
698 'R','i','c','h','E','d','i','t','2','0','W',0
700 struct msi_streamin_info info;
701 msi_control *control;
706 style = WS_BORDER | ES_MULTILINE | WS_VSCROLL |
707 ES_READONLY | ES_AUTOVSCROLL | WS_TABSTOP;
708 control = msi_dialog_add_control( dialog, rec, szRichEdit20W, style );
710 text = MSI_RecordGetString( rec, 10 );
711 info.string = strdupWtoA( text );
713 info.length = lstrlenA( info.string ) + 1;
715 es.dwCookie = (DWORD_PTR) &info;
717 es.pfnCallback = msi_richedit_stream_in;
719 SendMessageW( control->hwnd, EM_STREAMIN, SF_RTF, (LPARAM) &es );
721 HeapFree( GetProcessHeap(), 0, info.string );
723 return ERROR_SUCCESS;
726 static UINT msi_dialog_bitmap_control( msi_dialog *dialog, MSIRECORD *rec )
728 UINT cx, cy, flags, style, attributes;
729 msi_control *control;
732 flags = LR_LOADFROMFILE;
733 style = SS_BITMAP | SS_LEFT | WS_GROUP;
735 attributes = MSI_RecordGetInteger( rec, 8 );
736 if( attributes & msidbControlAttributesFixedSize )
738 flags |= LR_DEFAULTSIZE;
739 style |= SS_CENTERIMAGE;
742 control = msi_dialog_add_control( dialog, rec, szStatic, style );
743 text = MSI_RecordGetString( rec, 10 );
744 cx = MSI_RecordGetInteger( rec, 6 );
745 cy = MSI_RecordGetInteger( rec, 7 );
746 cx = msi_dialog_scale_unit( dialog, cx );
747 cy = msi_dialog_scale_unit( dialog, cy );
749 control->hBitmap = msi_load_image( dialog->package->db, text,
750 IMAGE_BITMAP, cx, cy, flags );
751 if( control->hBitmap )
752 SendMessageW( control->hwnd, STM_SETIMAGE,
753 IMAGE_BITMAP, (LPARAM) control->hBitmap );
755 ERR("Failed to load bitmap %s\n", debugstr_w(text));
757 return ERROR_SUCCESS;
760 static UINT msi_dialog_icon_control( msi_dialog *dialog, MSIRECORD *rec )
762 msi_control *control;
768 control = msi_dialog_add_control( dialog, rec, szStatic,
769 SS_ICON | SS_CENTERIMAGE | WS_GROUP );
771 attributes = MSI_RecordGetInteger( rec, 8 );
772 text = MSI_RecordGetString( rec, 10 );
773 control->hIcon = msi_load_icon( dialog->package->db, text, attributes );
775 SendMessageW( control->hwnd, STM_SETICON, (WPARAM) control->hIcon, 0 );
777 ERR("Failed to load bitmap %s\n", debugstr_w(text));
778 return ERROR_SUCCESS;
781 static UINT msi_dialog_combo_control( msi_dialog *dialog, MSIRECORD *rec )
783 static const WCHAR szCombo[] = { 'C','O','M','B','O','B','O','X',0 };
785 msi_dialog_add_control( dialog, rec, szCombo,
786 SS_BITMAP | SS_LEFT | SS_CENTERIMAGE );
787 return ERROR_SUCCESS;
790 static UINT msi_dialog_edit_control( msi_dialog *dialog, MSIRECORD *rec )
792 msi_control *control;
796 control = msi_dialog_add_control( dialog, rec, szEdit,
797 WS_BORDER | WS_TABSTOP );
798 control->handler = msi_dialog_edit_handler;
799 prop = MSI_RecordGetString( rec, 9 );
801 control->property = strdupW( prop );
802 val = load_dynamic_property( dialog->package, control->property, NULL );
803 SetWindowTextW( control->hwnd, val );
804 HeapFree( GetProcessHeap(), 0, val );
805 return ERROR_SUCCESS;
808 /******************** Masked Edit ********************************************/
810 #define MASK_MAX_GROUPS 10
812 struct msi_mask_group
820 struct msi_maskedit_info
828 struct msi_mask_group group[MASK_MAX_GROUPS];
831 static void msi_mask_control_change( struct msi_maskedit_info *info )
836 val = HeapAlloc( GetProcessHeap(), 0, (info->num_chars+1)*sizeof(WCHAR) );
837 for( i=0, n=0; i<info->num_groups; i++ )
839 if( (info->group[i].len + n) > info->num_chars )
841 ERR("can't fit control %d text into template\n",i);
844 r = GetWindowTextW( info->group[i].hwnd, &val[n], info->group[i].len+1 );
845 if( r != info->group[i].len )
850 TRACE("%d/%d controls were good\n", i, info->num_groups);
852 if( i == info->num_groups )
854 TRACE("Set property %s to %s\n",
855 debugstr_w(info->prop), debugstr_w(val) );
856 CharUpperBuffW( val, info->num_chars );
857 MSI_SetPropertyW( info->dialog->package, info->prop, val );
858 msi_dialog_evaluate_control_conditions( info->dialog );
860 HeapFree( GetProcessHeap(), 0, val );
863 /* now move to the next control if necessary */
864 static VOID msi_mask_next_control( struct msi_maskedit_info *info, HWND hWnd )
869 for( i=0; i<info->num_groups; i++ )
870 if( info->group[i].hwnd == hWnd )
873 /* don't move from the last control */
874 if( i >= (info->num_groups-1) )
877 len = SendMessageW( hWnd, WM_GETTEXTLENGTH, 0, 0 );
878 if( len < info->group[i].len )
881 hWndNext = GetNextDlgTabItem( GetParent( hWnd ), hWnd, FALSE );
882 SetFocus( hWndNext );
885 static LRESULT WINAPI
886 MSIMaskedEdit_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
888 struct msi_maskedit_info *info;
891 TRACE("%p %04x %08x %08lx\n", hWnd, msg, wParam, lParam);
893 info = GetPropW(hWnd, szButtonData);
895 r = CallWindowProcW(info->oldproc, hWnd, msg, wParam, lParam);
900 if (HIWORD(wParam) == EN_CHANGE)
902 msi_mask_control_change( info );
903 msi_mask_next_control( info, (HWND) lParam );
907 HeapFree( GetProcessHeap(), 0, info->prop );
908 HeapFree( GetProcessHeap(), 0, info );
909 RemovePropW( hWnd, szButtonData );
916 /* fish the various bits of the property out and put them in the control */
918 msi_maskedit_set_text( struct msi_maskedit_info *info, LPCWSTR text )
924 for( i = 0; i < info->num_groups; i++ )
926 if( info->group[i].len < lstrlenW( p ) )
928 LPWSTR chunk = strdupW( p );
929 chunk[ info->group[i].len ] = 0;
930 SetWindowTextW( info->group[i].hwnd, chunk );
931 HeapFree( GetProcessHeap(), 0, chunk );
935 SetWindowTextW( info->group[i].hwnd, p );
938 p += info->group[i].len;
942 static struct msi_maskedit_info * msi_dialog_parse_groups( LPCWSTR mask )
944 struct msi_maskedit_info * info = NULL;
945 int i = 0, n = 0, total = 0;
948 TRACE("masked control, template %s\n", debugstr_w(mask));
953 p = strchrW(mask, '<');
957 info = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof *info );
962 for( i=0; i<MASK_MAX_GROUPS; i++ )
964 /* stop at the end of the string */
965 if( p[0] == 0 || p[0] == '>' )
968 /* count the number of the same identifier */
969 for( n=0; p[n] == p[0]; n++ )
971 info->group[i].ofs = total;
972 info->group[i].type = p[0];
976 total++; /* an extra not part of the group */
978 info->group[i].len = n;
983 TRACE("%d characters in %d groups\n", total, info->num_groups );
984 if( i == MASK_MAX_GROUPS )
985 ERR("too many groups in PIDTemplate %s\n", debugstr_w(mask));
987 info->num_chars = total;
988 info->num_groups = i;
994 msi_maskedit_create_children( struct msi_maskedit_info *info )
996 DWORD width, height, style, wx, ww;
1001 style = WS_CHILD | WS_BORDER | WS_VISIBLE | WS_TABSTOP;
1003 GetClientRect( info->hwnd, &rect );
1005 width = rect.right - rect.left;
1006 height = rect.bottom - rect.top;
1008 for( i = 0; i < info->num_groups; i++ )
1010 wx = (info->group[i].ofs * width) / info->num_chars;
1011 ww = (info->group[i].len * width) / info->num_chars;
1013 hwnd = CreateWindowW( szEdit, NULL, style, wx, 0, ww, height,
1014 info->hwnd, NULL, NULL, NULL );
1017 ERR("failed to create mask edit sub window\n");
1021 SendMessageW( hwnd, EM_LIMITTEXT, info->group[i].len, 0 );
1023 msi_dialog_set_font( info->dialog, hwnd, info->dialog->default_font );
1024 info->group[i].hwnd = hwnd;
1028 /* office 2003 uses "73931<````=````=````=````=`````>@@@@@" */
1029 static UINT msi_dialog_maskedit_control( msi_dialog *dialog, MSIRECORD *rec )
1031 const static WCHAR pidt[] = {'P','I','D','T','e','m','p','l','a','t','e',0};
1032 LPWSTR mask = NULL, title = NULL, val = NULL;
1033 struct msi_maskedit_info *info = NULL;
1034 UINT ret = ERROR_SUCCESS;
1035 msi_control *control;
1038 mask = load_dynamic_property( dialog->package, pidt, NULL );
1041 ERR("PIDTemplate is empty\n");
1045 info = msi_dialog_parse_groups( mask );
1048 ERR("template %s is invalid\n", debugstr_w(mask));
1052 info->dialog = dialog;
1054 control = msi_dialog_add_control( dialog, rec, szStatic,
1055 SS_OWNERDRAW | WS_GROUP | WS_VISIBLE );
1058 ERR("Failed to create maskedit container\n");
1059 ret = ERROR_FUNCTION_FAILED;
1062 SetWindowLongPtrW( control->hwnd, GWL_EXSTYLE, WS_EX_CONTROLPARENT );
1064 info->hwnd = control->hwnd;
1066 /* subclass the static control */
1067 info->oldproc = (WNDPROC) SetWindowLongPtrW( info->hwnd, GWLP_WNDPROC,
1068 (LONG_PTR)MSIMaskedEdit_WndProc );
1069 SetPropW( control->hwnd, szButtonData, info );
1071 prop = MSI_RecordGetString( rec, 9 );
1073 info->prop = strdupW( prop );
1075 msi_maskedit_create_children( info );
1079 val = load_dynamic_property( dialog->package, prop, NULL );
1082 msi_maskedit_set_text( info, val );
1083 HeapFree( GetProcessHeap(), 0, val );
1088 if( ret != ERROR_SUCCESS )
1089 HeapFree( GetProcessHeap(), 0, info );
1090 HeapFree( GetProcessHeap(), 0, title );
1091 HeapFree( GetProcessHeap(), 0, mask );
1095 /******************** Path Edit ********************************************/
1097 static UINT msi_dialog_pathedit_control( msi_dialog *dialog, MSIRECORD *rec )
1099 FIXME("not implemented properly\n");
1100 return msi_dialog_edit_control( dialog, rec );
1103 /* radio buttons are a bit different from normal controls */
1104 static UINT msi_dialog_create_radiobutton( MSIRECORD *rec, LPVOID param )
1106 radio_button_group_descr *group = (radio_button_group_descr *)param;
1107 msi_dialog *dialog = group->dialog;
1108 msi_control *control;
1109 LPCWSTR prop, text, name;
1111 DWORD attributes = group->attributes;
1113 style = WS_CHILD | BS_AUTORADIOBUTTON | BS_MULTILINE | WS_TABSTOP;
1114 name = MSI_RecordGetString( rec, 3 );
1115 text = MSI_RecordGetString( rec, 8 );
1116 if( attributes & 1 )
1117 style |= WS_VISIBLE;
1118 if( ~attributes & 2 )
1119 style |= WS_DISABLED;
1121 control = msi_dialog_create_window( dialog, rec, szButton, name, text,
1122 style, group->parent->hwnd );
1123 control->handler = msi_dialog_radiogroup_handler;
1125 prop = MSI_RecordGetString( rec, 1 );
1127 control->property = strdupW( prop );
1129 return ERROR_SUCCESS;
1132 static UINT msi_dialog_radiogroup_control( msi_dialog *dialog, MSIRECORD *rec )
1134 static const WCHAR query[] = {
1135 'S','E','L','E','C','T',' ','*',' ',
1136 'F','R','O','M',' ','R','a','d','i','o','B','u','t','t','o','n',' ',
1137 'W','H','E','R','E',' ',
1138 '`','P','r','o','p','e','r','t','y','`',' ','=',' ','\'','%','s','\'',0};
1141 msi_control *control;
1142 MSIQUERY *view = NULL;
1143 radio_button_group_descr group;
1144 MSIPACKAGE *package = dialog->package;
1147 prop = MSI_RecordGetString( rec, 9 );
1149 TRACE("%p %p %s\n", dialog, rec, debugstr_w( prop ));
1151 /* Create parent group box to hold radio buttons */
1152 control = msi_dialog_add_control( dialog, rec, szButton, BS_OWNERDRAW|WS_GROUP );
1154 return ERROR_FUNCTION_FAILED;
1156 oldproc = (WNDPROC) SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
1157 (LONG_PTR)MSIRadioGroup_WndProc );
1158 SetPropW(control->hwnd, szButtonData, oldproc);
1159 SetWindowLongPtrW( control->hwnd, GWL_EXSTYLE, WS_EX_CONTROLPARENT );
1162 control->property = strdupW( prop );
1164 /* query the Radio Button table for all control in this group */
1165 r = MSI_OpenQuery( package->db, &view, query, prop );
1166 if( r != ERROR_SUCCESS )
1168 ERR("query failed for dialog %s radio group %s\n",
1169 debugstr_w(dialog->name), debugstr_w(prop));
1170 return ERROR_INVALID_PARAMETER;
1173 group.dialog = dialog;
1174 group.parent = control;
1175 group.attributes = MSI_RecordGetInteger( rec, 8 );
1177 r = MSI_IterateRecords( view, 0, msi_dialog_create_radiobutton, &group );
1178 msiobj_release( &view->hdr );
1183 struct control_handler msi_dialog_handler[] =
1185 { szText, msi_dialog_text_control },
1186 { szPushButton, msi_dialog_button_control },
1187 { szLine, msi_dialog_line_control },
1188 { szBitmap, msi_dialog_bitmap_control },
1189 { szCheckBox, msi_dialog_checkbox_control },
1190 { szScrollableText, msi_dialog_scrolltext_control },
1191 { szComboBox, msi_dialog_combo_control },
1192 { szEdit, msi_dialog_edit_control },
1193 { szMaskedEdit, msi_dialog_maskedit_control },
1194 { szPathEdit, msi_dialog_pathedit_control },
1195 { szRadioButtonGroup, msi_dialog_radiogroup_control },
1196 { szIcon, msi_dialog_icon_control },
1199 #define NUM_CONTROL_TYPES (sizeof msi_dialog_handler/sizeof msi_dialog_handler[0])
1201 static UINT msi_dialog_create_controls( MSIRECORD *rec, LPVOID param )
1203 msi_dialog *dialog = param;
1204 LPCWSTR control_type;
1207 /* find and call the function that can create this type of control */
1208 control_type = MSI_RecordGetString( rec, 3 );
1209 for( i=0; i<NUM_CONTROL_TYPES; i++ )
1210 if (!strcmpiW( msi_dialog_handler[i].control_type, control_type ))
1212 if( i != NUM_CONTROL_TYPES )
1213 msi_dialog_handler[i].func( dialog, rec );
1215 ERR("no handler for element type %s\n", debugstr_w(control_type));
1217 return ERROR_SUCCESS;
1220 static UINT msi_dialog_fill_controls( msi_dialog *dialog )
1222 static const WCHAR query[] = {
1223 'S','E','L','E','C','T',' ','*',' ',
1224 'F','R','O','M',' ','C','o','n','t','r','o','l',' ',
1225 'W','H','E','R','E',' ',
1226 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',0};
1228 MSIQUERY *view = NULL;
1229 MSIPACKAGE *package = dialog->package;
1231 TRACE("%p %s\n", dialog, debugstr_w(dialog->name) );
1233 /* query the Control table for all the elements of the control */
1234 r = MSI_OpenQuery( package->db, &view, query, dialog->name );
1235 if( r != ERROR_SUCCESS )
1237 ERR("query failed for dialog %s\n", debugstr_w(dialog->name));
1238 return ERROR_INVALID_PARAMETER;
1241 r = MSI_IterateRecords( view, 0, msi_dialog_create_controls, dialog );
1242 msiobj_release( &view->hdr );
1247 static UINT msi_dialog_set_control_condition( MSIRECORD *rec, LPVOID param )
1249 static const WCHAR szHide[] = { 'H','i','d','e',0 };
1250 static const WCHAR szShow[] = { 'S','h','o','w',0 };
1251 static const WCHAR szDisable[] = { 'D','i','s','a','b','l','e',0 };
1252 static const WCHAR szEnable[] = { 'E','n','a','b','l','e',0 };
1253 msi_dialog *dialog = param;
1254 msi_control *control;
1255 LPCWSTR name, action, condition;
1258 name = MSI_RecordGetString( rec, 2 );
1259 action = MSI_RecordGetString( rec, 3 );
1260 condition = MSI_RecordGetString( rec, 4 );
1261 r = MSI_EvaluateConditionW( dialog->package, condition );
1262 control = msi_dialog_find_control( dialog, name );
1265 TRACE("%s control %s\n", debugstr_w(action), debugstr_w(name));
1267 /* FIXME: case sensitive? */
1268 if(!lstrcmpW(action, szHide))
1269 ShowWindow(control->hwnd, SW_HIDE);
1270 else if(!strcmpW(action, szShow))
1271 ShowWindow(control->hwnd, SW_SHOW);
1272 else if(!strcmpW(action, szDisable))
1273 EnableWindow(control->hwnd, FALSE);
1274 else if(!strcmpW(action, szEnable))
1275 EnableWindow(control->hwnd, TRUE);
1277 FIXME("Unhandled action %s\n", debugstr_w(action));
1280 return ERROR_SUCCESS;
1283 static UINT msi_dialog_evaluate_control_conditions( msi_dialog *dialog )
1285 static const WCHAR query[] = {
1286 'S','E','L','E','C','T',' ','*',' ',
1287 'F','R','O','M',' ',
1288 'C','o','n','t','r','o','l','C','o','n','d','i','t','i','o','n',' ',
1289 'W','H','E','R','E',' ',
1290 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',0
1293 MSIQUERY *view = NULL;
1294 MSIPACKAGE *package = dialog->package;
1296 TRACE("%p %s\n", dialog, debugstr_w(dialog->name) );
1298 /* query the Control table for all the elements of the control */
1299 r = MSI_OpenQuery( package->db, &view, query, dialog->name );
1300 if( r != ERROR_SUCCESS )
1302 ERR("query failed for dialog %s\n", debugstr_w(dialog->name));
1303 return ERROR_INVALID_PARAMETER;
1306 r = MSI_IterateRecords( view, 0, msi_dialog_set_control_condition, dialog );
1307 msiobj_release( &view->hdr );
1312 /* figure out the height of 10 point MS Sans Serif */
1313 static INT msi_dialog_get_sans_serif_height( HWND hwnd )
1315 static const WCHAR szSansSerif[] = {
1316 'M','S',' ','S','a','n','s',' ','S','e','r','i','f',0 };
1321 HFONT hFont, hOldFont;
1324 hdc = GetDC( hwnd );
1327 memset( &lf, 0, sizeof lf );
1328 lf.lfHeight = MulDiv(10, GetDeviceCaps(hdc, LOGPIXELSY), 72);
1329 strcpyW( lf.lfFaceName, szSansSerif );
1330 hFont = CreateFontIndirectW(&lf);
1333 hOldFont = SelectObject( hdc, hFont );
1334 r = GetTextMetricsW( hdc, &tm );
1336 height = tm.tmHeight;
1337 SelectObject( hdc, hOldFont );
1338 DeleteObject( hFont );
1340 ReleaseDC( hwnd, hdc );
1345 /* fetch the associated record from the Dialog table */
1346 static MSIRECORD *msi_get_dialog_record( msi_dialog *dialog )
1348 static const WCHAR query[] = {
1349 'S','E','L','E','C','T',' ','*',' ',
1350 'F','R','O','M',' ','D','i','a','l','o','g',' ',
1351 'W','H','E','R','E',' ',
1352 '`','D','i','a','l','o','g','`',' ','=',' ','\'','%','s','\'',0};
1353 MSIPACKAGE *package = dialog->package;
1354 MSIRECORD *rec = NULL;
1356 TRACE("%p %s\n", dialog, debugstr_w(dialog->name) );
1358 rec = MSI_QueryGetRecord( package->db, query, dialog->name );
1360 ERR("query failed for dialog %s\n", debugstr_w(dialog->name));
1365 static void msi_dialog_adjust_dialog_size( msi_dialog *dialog, LPSIZE sz )
1370 /* turn the client size into the window rectangle */
1373 rect.right = msi_dialog_scale_unit( dialog, sz->cx );
1374 rect.bottom = msi_dialog_scale_unit( dialog, sz->cy );
1375 style = GetWindowLongPtrW( dialog->hwnd, GWL_STYLE );
1376 AdjustWindowRect( &rect, style, FALSE );
1377 sz->cx = rect.right - rect.left;
1378 sz->cy = rect.bottom - rect.top;
1381 static BOOL msi_control_set_next( msi_control *control, msi_control *next )
1383 return SetWindowPos( next->hwnd, control->hwnd, 0, 0, 0, 0,
1384 SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOREDRAW |
1385 SWP_NOREPOSITION | SWP_NOSENDCHANGING | SWP_NOSIZE );
1388 static UINT msi_dialog_set_tab_order( msi_dialog *dialog )
1390 msi_control *control, *tab_next;
1392 for( control = dialog->control_list; control; control = control->next )
1394 tab_next = msi_dialog_find_control( dialog, control->tabnext );
1397 msi_control_set_next( control, tab_next );
1400 return ERROR_SUCCESS;
1403 static void msi_dialog_set_first_control( msi_dialog* dialog, LPCWSTR name )
1405 msi_control *control;
1407 control = msi_dialog_find_control( dialog, name );
1409 dialog->hWndFocus = control->hwnd;
1411 dialog->hWndFocus = NULL;
1414 static LRESULT msi_dialog_oncreate( HWND hwnd, LPCREATESTRUCTW cs )
1416 static const WCHAR df[] = {
1417 'D','e','f','a','u','l','t','U','I','F','o','n','t',0 };
1418 msi_dialog *dialog = (msi_dialog*) cs->lpCreateParams;
1419 MSIRECORD *rec = NULL;
1421 LPWSTR title = NULL;
1424 TRACE("%p %p\n", dialog, dialog->package);
1426 dialog->hwnd = hwnd;
1427 SetWindowLongPtrW( hwnd, GWLP_USERDATA, (LONG_PTR) dialog );
1429 rec = msi_get_dialog_record( dialog );
1432 TRACE("No record found for dialog %s\n", debugstr_w(dialog->name));
1436 dialog->scale = msi_dialog_get_sans_serif_height(dialog->hwnd);
1438 size.cx = MSI_RecordGetInteger( rec, 4 );
1439 size.cy = MSI_RecordGetInteger( rec, 5 );
1440 msi_dialog_adjust_dialog_size( dialog, &size );
1442 dialog->attributes = MSI_RecordGetInteger( rec, 6 );
1443 text = MSI_RecordGetString( rec, 7 );
1445 dialog->default_font = load_dynamic_property( dialog->package, df, NULL );
1447 deformat_string( dialog->package, text, &title );
1448 SetWindowTextW( hwnd, title );
1449 SetWindowPos( hwnd, 0, 0, 0, size.cx, size.cy,
1450 SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOREDRAW );
1452 HeapFree( GetProcessHeap(), 0, title );
1454 msi_dialog_build_font_list( dialog );
1455 msi_dialog_fill_controls( dialog );
1456 msi_dialog_evaluate_control_conditions( dialog );
1457 msi_dialog_set_tab_order( dialog );
1458 msi_dialog_set_first_control( dialog, MSI_RecordGetString( rec, 8 ) );
1459 msiobj_release( &rec->hdr );
1464 static UINT msi_dialog_send_event( msi_dialog *dialog, LPCWSTR event, LPCWSTR arg )
1466 LPWSTR event_fmt = NULL, arg_fmt = NULL;
1468 TRACE("Sending control event %s %s\n", debugstr_w(event), debugstr_w(arg));
1470 deformat_string( dialog->package, event, &event_fmt );
1471 deformat_string( dialog->package, arg, &arg_fmt );
1473 dialog->event_handler( dialog->package, event_fmt, arg_fmt, dialog );
1475 HeapFree( GetProcessHeap(), 0, event_fmt );
1476 HeapFree( GetProcessHeap(), 0, arg_fmt );
1478 return ERROR_SUCCESS;
1481 static UINT msi_dialog_set_property( msi_dialog *dialog, LPCWSTR event, LPCWSTR arg )
1483 static const WCHAR szNullArg[] = { '{','}',0 };
1484 LPWSTR p, prop, arg_fmt = NULL;
1487 len = strlenW(event);
1488 prop = HeapAlloc( GetProcessHeap(), 0, len*sizeof(WCHAR));
1489 strcpyW( prop, &event[1] );
1490 p = strchrW( prop, ']' );
1491 if( p && p[1] == 0 )
1494 if( strcmpW( szNullArg, arg ) )
1495 deformat_string( dialog->package, arg, &arg_fmt );
1496 MSI_SetPropertyW( dialog->package, prop, arg_fmt );
1499 ERR("Badly formatted property string - what happens?\n");
1500 HeapFree( GetProcessHeap(), 0, prop );
1501 return ERROR_SUCCESS;
1504 static UINT msi_dialog_control_event( MSIRECORD *rec, LPVOID param )
1506 msi_dialog *dialog = param;
1507 LPCWSTR condition, event, arg;
1510 condition = MSI_RecordGetString( rec, 5 );
1511 r = MSI_EvaluateConditionW( dialog->package, condition );
1514 event = MSI_RecordGetString( rec, 3 );
1515 arg = MSI_RecordGetString( rec, 4 );
1516 if( event[0] == '[' )
1517 msi_dialog_set_property( dialog, event, arg );
1519 msi_dialog_send_event( dialog, event, arg );
1522 return ERROR_SUCCESS;
1525 static UINT msi_dialog_button_handler( msi_dialog *dialog,
1526 msi_control *control, WPARAM param )
1528 static const WCHAR query[] = {
1529 'S','E','L','E','C','T',' ','*',' ',
1530 'F','R','O','M',' ','C','o','n','t','r','o','l','E','v','e','n','t',' ',
1531 'W','H','E','R','E',' ',
1532 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',' ',
1534 '`','C','o','n','t','r','o','l','_','`',' ','=',' ','\'','%','s','\'',' ',
1535 'O','R','D','E','R',' ','B','Y',' ','`','O','r','d','e','r','i','n','g','`',0
1537 MSIQUERY *view = NULL;
1540 if( HIWORD(param) != BN_CLICKED )
1541 return ERROR_SUCCESS;
1543 r = MSI_OpenQuery( dialog->package->db, &view, query,
1544 dialog->name, control->name );
1545 if( r != ERROR_SUCCESS )
1547 ERR("query failed\n");
1551 r = MSI_IterateRecords( view, 0, msi_dialog_control_event, dialog );
1552 msiobj_release( &view->hdr );
1557 static UINT msi_dialog_get_checkbox_state( msi_dialog *dialog,
1558 msi_control *control )
1560 WCHAR state[2] = { 0 };
1563 MSI_GetPropertyW( dialog->package, control->property, state, &sz );
1564 return state[0] ? 1 : 0;
1567 static void msi_dialog_set_checkbox_state( msi_dialog *dialog,
1568 msi_control *control, UINT state )
1570 static const WCHAR szState[] = { '1', 0 };
1573 /* if uncheck then the property is set to NULL */
1576 MSI_SetPropertyW( dialog->package, control->property, NULL );
1580 /* check for a custom state */
1581 if (control->value && control->value[0])
1582 val = control->value;
1586 MSI_SetPropertyW( dialog->package, control->property, val );
1589 static void msi_dialog_checkbox_sync_state( msi_dialog *dialog,
1590 msi_control *control )
1594 state = msi_dialog_get_checkbox_state( dialog, control );
1595 SendMessageW( control->hwnd, BM_SETCHECK,
1596 state ? BST_CHECKED : BST_UNCHECKED, 0 );
1599 static UINT msi_dialog_checkbox_handler( msi_dialog *dialog,
1600 msi_control *control, WPARAM param )
1604 if( HIWORD(param) != BN_CLICKED )
1605 return ERROR_SUCCESS;
1607 TRACE("clicked checkbox %s, set %s\n", debugstr_w(control->name),
1608 debugstr_w(control->property));
1610 state = msi_dialog_get_checkbox_state( dialog, control );
1611 state = state ? 0 : 1;
1612 msi_dialog_set_checkbox_state( dialog, control, state );
1613 msi_dialog_checkbox_sync_state( dialog, control );
1615 return msi_dialog_button_handler( dialog, control, param );
1618 static UINT msi_dialog_edit_handler( msi_dialog *dialog,
1619 msi_control *control, WPARAM param )
1624 if( HIWORD(param) != EN_CHANGE )
1625 return ERROR_SUCCESS;
1627 TRACE("edit %s contents changed, set %s\n", debugstr_w(control->name),
1628 debugstr_w(control->property));
1631 buf = HeapAlloc( GetProcessHeap(), 0, sz*sizeof(WCHAR) );
1634 r = GetWindowTextW( control->hwnd, buf, sz );
1638 buf = HeapReAlloc( GetProcessHeap(), 0, buf, sz*sizeof(WCHAR) );
1641 MSI_SetPropertyW( dialog->package, control->property, buf );
1643 HeapFree( GetProcessHeap(), 0, buf );
1645 return ERROR_SUCCESS;
1648 static UINT msi_dialog_radiogroup_handler( msi_dialog *dialog,
1649 msi_control *control, WPARAM param )
1651 if( HIWORD(param) != BN_CLICKED )
1652 return ERROR_SUCCESS;
1654 TRACE("clicked radio button %s, set %s\n", debugstr_w(control->name),
1655 debugstr_w(control->property));
1657 MSI_SetPropertyW( dialog->package, control->property, control->name );
1659 return msi_dialog_button_handler( dialog, control, param );
1662 static LRESULT msi_dialog_oncommand( msi_dialog *dialog, WPARAM param, HWND hwnd )
1664 msi_control *control;
1666 TRACE("%p %p %08x\n", dialog, hwnd, param);
1668 control = msi_dialog_find_control_by_hwnd( dialog, hwnd );
1671 if( control->handler )
1673 control->handler( dialog, control, param );
1674 msi_dialog_evaluate_control_conditions( dialog );
1678 ERR("button click from nowhere\n");
1682 static void msi_dialog_setfocus( msi_dialog *dialog )
1684 HWND hwnd = dialog->hWndFocus;
1686 hwnd = GetNextDlgTabItem( dialog->hwnd, hwnd, TRUE);
1687 hwnd = GetNextDlgTabItem( dialog->hwnd, hwnd, FALSE);
1689 dialog->hWndFocus = hwnd;
1692 static LRESULT WINAPI MSIDialog_WndProc( HWND hwnd, UINT msg,
1693 WPARAM wParam, LPARAM lParam )
1695 msi_dialog *dialog = (LPVOID) GetWindowLongPtrW( hwnd, GWLP_USERDATA );
1697 TRACE("0x%04x\n", msg);
1702 return msi_dialog_oncreate( hwnd, (LPCREATESTRUCTW)lParam );
1705 return msi_dialog_oncommand( dialog, wParam, (HWND)lParam );
1708 if( LOWORD(wParam) == WA_INACTIVE )
1709 dialog->hWndFocus = GetFocus();
1711 msi_dialog_setfocus( dialog );
1715 msi_dialog_setfocus( dialog );
1718 /* bounce back to our subclassed static control */
1719 case WM_CTLCOLORSTATIC:
1720 return SendMessageW( (HWND) lParam, WM_CTLCOLORSTATIC, wParam, lParam );
1723 dialog->hwnd = NULL;
1726 return DefWindowProcW(hwnd, msg, wParam, lParam);
1729 static LRESULT WINAPI MSIRadioGroup_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
1731 WNDPROC oldproc = (WNDPROC) GetPropW(hWnd, szButtonData);
1733 TRACE("hWnd %p msg %04x wParam 0x%08x lParam 0x%08lx\n", hWnd, msg, wParam, lParam);
1735 if (msg == WM_COMMAND) /* Forward notifications to dialog */
1736 SendMessageW(GetParent(hWnd), msg, wParam, lParam);
1738 return CallWindowProcW(oldproc, hWnd, msg, wParam, lParam);
1741 static LRESULT WINAPI MSIHiddenWindowProc( HWND hwnd, UINT msg,
1742 WPARAM wParam, LPARAM lParam )
1744 msi_dialog *dialog = (msi_dialog*) lParam;
1746 TRACE("%d %p\n", msg, dialog);
1750 case WM_MSI_DIALOG_CREATE:
1751 return msi_dialog_run_message_loop( dialog );
1752 case WM_MSI_DIALOG_DESTROY:
1753 msi_dialog_destroy( dialog );
1756 return DefWindowProcW( hwnd, msg, wParam, lParam );
1759 /* functions that interface to other modules within MSI */
1761 msi_dialog *msi_dialog_create( MSIPACKAGE* package, LPCWSTR szDialogName,
1762 msi_dialog_event_handler event_handler )
1764 MSIRECORD *rec = NULL;
1767 TRACE("%p %s\n", package, debugstr_w(szDialogName));
1769 /* allocate the structure for the dialog to use */
1770 dialog = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
1771 sizeof *dialog + sizeof(WCHAR)*strlenW(szDialogName) );
1774 strcpyW( dialog->name, szDialogName );
1775 msiobj_addref( &package->hdr );
1776 dialog->package = package;
1777 dialog->event_handler = event_handler;
1778 dialog->finished = 0;
1780 /* verify that the dialog exists */
1781 rec = msi_get_dialog_record( dialog );
1784 HeapFree( GetProcessHeap(), 0, dialog );
1787 dialog->attributes = MSI_RecordGetInteger( rec, 6 );
1788 msiobj_release( &rec->hdr );
1793 static void msi_process_pending_messages( HWND hdlg )
1797 while( PeekMessageW( &msg, 0, 0, 0, PM_REMOVE ) )
1799 if( hdlg && IsDialogMessageW( hdlg, &msg ))
1801 TranslateMessage( &msg );
1802 DispatchMessageW( &msg );
1806 void msi_dialog_end_dialog( msi_dialog *dialog )
1808 TRACE("%p\n", dialog);
1809 dialog->finished = 1;
1810 PostMessageW(dialog->hwnd, WM_NULL, 0, 0);
1813 void msi_dialog_check_messages( HANDLE handle )
1817 /* in threads other than the UI thread, block */
1818 if( uiThreadId != GetCurrentThreadId() )
1821 WaitForSingleObject( handle, INFINITE );
1825 /* there's two choices for the UI thread */
1828 msi_process_pending_messages( NULL );
1834 * block here until somebody creates a new dialog or
1835 * the handle we're waiting on becomes ready
1837 r = MsgWaitForMultipleObjects( 1, &handle, 0, INFINITE, QS_ALLINPUT );
1838 if( r == WAIT_OBJECT_0 )
1843 UINT msi_dialog_run_message_loop( msi_dialog *dialog )
1847 if( !(dialog->attributes & msidbDialogAttributesVisible) )
1848 return ERROR_SUCCESS;
1850 if( uiThreadId != GetCurrentThreadId() )
1851 return SendMessageW( hMsiHiddenWindow, WM_MSI_DIALOG_CREATE, 0, (LPARAM) dialog );
1853 /* create the dialog window, don't show it yet */
1854 hwnd = CreateWindowW( szMsiDialogClass, dialog->name, WS_OVERLAPPEDWINDOW,
1855 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
1856 NULL, NULL, NULL, dialog );
1859 ERR("Failed to create dialog %s\n", debugstr_w( dialog->name ));
1860 return ERROR_FUNCTION_FAILED;
1863 ShowWindow( hwnd, SW_SHOW );
1864 UpdateWindow( hwnd );
1866 if( dialog->attributes & msidbDialogAttributesModal )
1868 while( !dialog->finished )
1870 MsgWaitForMultipleObjects( 0, NULL, 0, INFINITE, QS_ALLEVENTS );
1871 msi_process_pending_messages( dialog->hwnd );
1875 return ERROR_IO_PENDING;
1877 return ERROR_SUCCESS;
1880 void msi_dialog_do_preview( msi_dialog *dialog )
1883 dialog->attributes |= msidbDialogAttributesVisible;
1884 dialog->attributes &= ~msidbDialogAttributesModal;
1885 msi_dialog_run_message_loop( dialog );
1888 void msi_dialog_destroy( msi_dialog *dialog )
1890 if( uiThreadId != GetCurrentThreadId() )
1892 SendMessageW( hMsiHiddenWindow, WM_MSI_DIALOG_DESTROY, 0, (LPARAM) dialog );
1897 ShowWindow( dialog->hwnd, SW_HIDE );
1899 /* destroy the list of controls */
1900 while( dialog->control_list )
1902 msi_control *t = dialog->control_list;
1903 dialog->control_list = t->next;
1904 /* leave dialog->hwnd - destroying parent destroys child windows */
1905 HeapFree( GetProcessHeap(), 0, t->property );
1906 HeapFree( GetProcessHeap(), 0, t->value );
1908 DeleteObject( t->hBitmap );
1910 DestroyIcon( t->hIcon );
1911 HeapFree( GetProcessHeap(), 0, t->tabnext );
1912 HeapFree( GetProcessHeap(), 0, t );
1915 /* destroy the list of fonts */
1916 while( dialog->font_list )
1918 msi_font *t = dialog->font_list;
1919 dialog->font_list = t->next;
1920 DeleteObject( t->hfont );
1921 HeapFree( GetProcessHeap(), 0, t );
1923 HeapFree( GetProcessHeap(), 0, dialog->default_font );
1926 DestroyWindow( dialog->hwnd );
1928 msiobj_release( &dialog->package->hdr );
1929 dialog->package = NULL;
1930 HeapFree( GetProcessHeap(), 0, dialog );
1933 BOOL msi_dialog_register_class( void )
1937 ZeroMemory( &cls, sizeof cls );
1938 cls.lpfnWndProc = MSIDialog_WndProc;
1939 cls.hInstance = NULL;
1940 cls.hIcon = LoadIconW(0, (LPWSTR)IDI_APPLICATION);
1941 cls.hCursor = LoadCursorW(0, (LPWSTR)IDC_ARROW);
1942 cls.hbrBackground = (HBRUSH)(COLOR_WINDOW);
1943 cls.lpszMenuName = NULL;
1944 cls.lpszClassName = szMsiDialogClass;
1946 if( !RegisterClassW( &cls ) )
1949 cls.lpfnWndProc = MSIHiddenWindowProc;
1950 cls.lpszClassName = szMsiHiddenWindow;
1952 if( !RegisterClassW( &cls ) )
1955 uiThreadId = GetCurrentThreadId();
1957 hMsiHiddenWindow = CreateWindowW( szMsiHiddenWindow, NULL, WS_OVERLAPPED,
1958 0, 0, 100, 100, NULL, NULL, NULL, NULL );
1959 if( !hMsiHiddenWindow )
1962 hRichedit = LoadLibraryA("riched20");
1967 void msi_dialog_unregister_class( void )
1969 DestroyWindow( hMsiHiddenWindow );
1970 UnregisterClassW( szMsiDialogClass, NULL );
1972 FreeLibrary( hRichedit );