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
38 #include "wine/debug.h"
39 #include "wine/unicode.h"
43 WINE_DEFAULT_DEBUG_CHANNEL(msi);
46 struct msi_control_tag;
47 typedef struct msi_control_tag msi_control;
48 typedef UINT (*msi_handler)( msi_dialog *, msi_control *, WPARAM );
50 struct msi_control_tag
64 typedef struct msi_font_tag
66 struct msi_font_tag *next;
74 msi_dialog_event_handler event_handler;
86 typedef UINT (*msi_dialog_control_func)( msi_dialog *dialog, MSIRECORD *rec );
87 struct control_handler
90 msi_dialog_control_func func;
98 } radio_button_group_descr;
100 const WCHAR szMsiDialogClass[] = {
101 'M','s','i','D','i','a','l','o','g','C','l','o','s','e','C','l','a','s','s',0
103 const WCHAR szMsiHiddenWindow[] = {
104 'M','s','i','H','i','d','d','e','n','W','i','n','d','o','w',0 };
105 const static WCHAR szStatic[] = { 'S','t','a','t','i','c',0 };
106 const static WCHAR szButton[] = { 'B','U','T','T','O','N', 0 };
107 const static WCHAR szButtonData[] = { 'M','S','I','D','A','T','A',0 };
108 static const WCHAR szText[] = { 'T','e','x','t',0 };
109 static const WCHAR szPushButton[] = { 'P','u','s','h','B','u','t','t','o','n',0 };
110 static const WCHAR szLine[] = { 'L','i','n','e',0 };
111 static const WCHAR szBitmap[] = { 'B','i','t','m','a','p',0 };
112 static const WCHAR szCheckBox[] = { 'C','h','e','c','k','B','o','x',0 };
113 static const WCHAR szScrollableText[] = {
114 'S','c','r','o','l','l','a','b','l','e','T','e','x','t',0 };
115 static const WCHAR szComboBox[] = { 'C','o','m','b','o','B','o','x',0 };
116 static const WCHAR szEdit[] = { 'E','d','i','t',0 };
117 static const WCHAR szMaskedEdit[] = { 'M','a','s','k','e','d','E','d','i','t',0 };
118 static const WCHAR szPathEdit[] = { 'P','a','t','h','E','d','i','t',0 };
119 static const WCHAR szProgressBar[] = {
120 'P','r','o','g','r','e','s','s','B','a','r',0 };
121 static const WCHAR szRadioButtonGroup[] = {
122 'R','a','d','i','o','B','u','t','t','o','n','G','r','o','u','p',0 };
123 static const WCHAR szIcon[] = { 'I','c','o','n',0 };
125 static UINT msi_dialog_checkbox_handler( msi_dialog *, msi_control *, WPARAM );
126 static void msi_dialog_checkbox_sync_state( msi_dialog *, msi_control * );
127 static UINT msi_dialog_button_handler( msi_dialog *, msi_control *, WPARAM );
128 static UINT msi_dialog_edit_handler( msi_dialog *, msi_control *, WPARAM );
129 static UINT msi_dialog_radiogroup_handler( msi_dialog *, msi_control *, WPARAM param );
130 static UINT msi_dialog_evaluate_control_conditions( msi_dialog *dialog );
131 static LRESULT WINAPI MSIRadioGroup_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
134 /* dialog sequencing */
136 #define WM_MSI_DIALOG_CREATE (WM_USER+0x100)
137 #define WM_MSI_DIALOG_DESTROY (WM_USER+0x101)
139 static DWORD uiThreadId;
140 static HWND hMsiHiddenWindow;
142 static INT msi_dialog_scale_unit( msi_dialog *dialog, INT val )
144 return (dialog->scale * val + 5) / 10;
147 static msi_control *msi_dialog_find_control( msi_dialog *dialog, LPCWSTR name )
149 msi_control *control;
153 LIST_FOR_EACH_ENTRY( control, &dialog->controls, msi_control, entry )
154 if( !strcmpW( control->name, name ) ) /* FIXME: case sensitive? */
159 static msi_control *msi_dialog_find_control_by_hwnd( msi_dialog *dialog, HWND hwnd )
161 msi_control *control;
163 LIST_FOR_EACH_ENTRY( control, &dialog->controls, msi_control, entry )
164 if( hwnd == control->hwnd )
169 static LPWSTR msi_get_deformatted_field( MSIPACKAGE *package, MSIRECORD *rec, int field )
171 LPCWSTR str = MSI_RecordGetString( rec, field );
175 deformat_string( package, str, &ret );
180 * msi_dialog_get_style
182 * Extract the {\style} string from the front of the text to display and
183 * update the pointer.
185 static LPWSTR msi_dialog_get_style( LPCWSTR p, LPCWSTR *rest )
196 q = strchrW( p, '}' );
199 if( *p == '\\' || *p == '&' )
202 /* little bit of sanity checking to stop us getting confused with RTF */
204 if( *i == '}' || *i == '\\' )
210 ret = msi_alloc( len*sizeof(WCHAR) );
213 memcpy( ret, p, len*sizeof(WCHAR) );
218 static UINT msi_dialog_add_font( MSIRECORD *rec, LPVOID param )
220 msi_dialog *dialog = param;
227 /* create a font and add it to the list */
228 name = MSI_RecordGetString( rec, 1 );
229 font = msi_alloc( sizeof *font + strlenW( name )*sizeof (WCHAR) );
230 strcpyW( font->name, name );
231 font->next = dialog->font_list;
232 dialog->font_list = font;
234 memset( &lf, 0, sizeof lf );
235 face = MSI_RecordGetString( rec, 2 );
236 lf.lfHeight = MSI_RecordGetInteger( rec, 3 );
237 style = MSI_RecordGetInteger( rec, 5 );
238 if( style & msidbTextStyleStyleBitsBold )
239 lf.lfWeight = FW_BOLD;
240 if( style & msidbTextStyleStyleBitsItalic )
242 if( style & msidbTextStyleStyleBitsUnderline )
243 lf.lfUnderline = TRUE;
244 if( style & msidbTextStyleStyleBitsStrike )
245 lf.lfStrikeOut = TRUE;
246 lstrcpynW( lf.lfFaceName, face, LF_FACESIZE );
248 /* adjust the height */
249 hdc = GetDC( dialog->hwnd );
252 lf.lfHeight = -MulDiv(lf.lfHeight, GetDeviceCaps(hdc, LOGPIXELSY), 72);
253 ReleaseDC( dialog->hwnd, hdc );
256 font->hfont = CreateFontIndirectW( &lf );
258 TRACE("Adding font style %s\n", debugstr_w(font->name) );
260 return ERROR_SUCCESS;
263 static msi_font *msi_dialog_find_font( msi_dialog *dialog, LPCWSTR name )
267 for( font = dialog->font_list; font; font = font->next )
268 if( !strcmpW( font->name, name ) ) /* FIXME: case sensitive? */
274 static UINT msi_dialog_set_font( msi_dialog *dialog, HWND hwnd, LPCWSTR name )
278 font = msi_dialog_find_font( dialog, name );
280 SendMessageW( hwnd, WM_SETFONT, (WPARAM) font->hfont, TRUE );
282 ERR("No font entry for %s\n", debugstr_w(name));
283 return ERROR_SUCCESS;
286 static UINT msi_dialog_build_font_list( msi_dialog *dialog )
288 static const WCHAR query[] = {
289 'S','E','L','E','C','T',' ','*',' ',
290 'F','R','O','M',' ','`','T','e','x','t','S','t','y','l','e','`',' ',0
293 MSIQUERY *view = NULL;
295 TRACE("dialog %p\n", dialog );
297 r = MSI_OpenQuery( dialog->package->db, &view, query );
298 if( r != ERROR_SUCCESS )
301 r = MSI_IterateRecords( view, NULL, msi_dialog_add_font, dialog );
302 msiobj_release( &view->hdr );
307 static msi_control *msi_dialog_create_window( msi_dialog *dialog,
308 MSIRECORD *rec, LPCWSTR szCls, LPCWSTR name, LPCWSTR text,
309 DWORD style, HWND parent )
311 DWORD x, y, width, height;
312 LPWSTR font = NULL, title_font = NULL;
313 LPCWSTR title = NULL;
314 msi_control *control;
318 control = msi_alloc( sizeof *control + strlenW(name)*sizeof(WCHAR) );
319 strcpyW( control->name, name );
320 list_add_head( &dialog->controls, &control->entry );
321 control->handler = NULL;
322 control->property = NULL;
323 control->value = NULL;
324 control->hBitmap = NULL;
325 control->hIcon = NULL;
326 control->hDll = NULL;
327 control->tabnext = strdupW( MSI_RecordGetString( rec, 11) );
329 x = MSI_RecordGetInteger( rec, 4 );
330 y = MSI_RecordGetInteger( rec, 5 );
331 width = MSI_RecordGetInteger( rec, 6 );
332 height = MSI_RecordGetInteger( rec, 7 );
334 x = msi_dialog_scale_unit( dialog, x );
335 y = msi_dialog_scale_unit( dialog, y );
336 width = msi_dialog_scale_unit( dialog, width );
337 height = msi_dialog_scale_unit( dialog, height );
341 deformat_string( dialog->package, text, &title_font );
342 font = msi_dialog_get_style( title_font, &title );
345 control->hwnd = CreateWindowW( szCls, title, style,
346 x, y, width, height, parent, NULL, NULL, NULL );
348 TRACE("Dialog %s control %s hwnd %p\n",
349 debugstr_w(dialog->name), debugstr_w(text), control->hwnd );
351 msi_dialog_set_font( dialog, control->hwnd,
352 font ? font : dialog->default_font );
354 msi_free( title_font );
360 static MSIRECORD *msi_get_binary_record( MSIDATABASE *db, LPCWSTR name )
362 const static WCHAR query[] = {
363 's','e','l','e','c','t',' ','*',' ',
364 'f','r','o','m',' ','B','i','n','a','r','y',' ',
365 'w','h','e','r','e',' ',
366 '`','N','a','m','e','`',' ','=',' ','\'','%','s','\'',0
369 return MSI_QueryGetRecord( db, query, name );
372 static LPWSTR msi_create_tmp_path(void)
376 static const WCHAR prefix[] = { 'm','s','i',0 };
379 r = GetTempPathW( MAX_PATH, tmp );
382 len = lstrlenW( tmp ) + 20;
383 path = msi_alloc( len * sizeof (WCHAR) );
386 r = GetTempFileNameW( tmp, prefix, 0, path );
397 static HANDLE msi_load_image( MSIDATABASE *db, LPCWSTR name, UINT type,
398 UINT cx, UINT cy, UINT flags )
400 MSIRECORD *rec = NULL;
401 HANDLE himage = NULL;
405 TRACE("%p %s %u %u %08x\n", db, debugstr_w(name), cx, cy, flags);
407 tmp = msi_create_tmp_path();
411 rec = msi_get_binary_record( db, name );
414 r = MSI_RecordStreamToFile( rec, 2, tmp );
415 if( r == ERROR_SUCCESS )
417 himage = LoadImageW( 0, tmp, type, cx, cy, flags );
420 msiobj_release( &rec->hdr );
427 static HICON msi_load_icon( MSIDATABASE *db, LPCWSTR text, UINT attributes )
429 DWORD cx = 0, cy = 0, flags;
431 flags = LR_LOADFROMFILE | LR_DEFAULTSIZE;
432 if( attributes & msidbControlAttributesFixedSize )
434 flags &= ~LR_DEFAULTSIZE;
435 if( attributes & msidbControlAttributesIconSize16 )
440 if( attributes & msidbControlAttributesIconSize32 )
445 /* msidbControlAttributesIconSize48 handled by above logic */
447 return msi_load_image( db, text, IMAGE_ICON, cx, cy, flags );
451 /* called from the Control Event subscription code */
452 void msi_dialog_handle_event( msi_dialog* dialog, LPCWSTR control,
453 LPCWSTR attribute, MSIRECORD *rec )
458 ctrl = msi_dialog_find_control( dialog, control );
461 if( lstrcmpW(attribute, szText) )
463 ERR("Attribute %s\n", debugstr_w(attribute));
466 text = MSI_RecordGetString( rec , 1 );
467 SetWindowTextW( ctrl->hwnd, text );
468 msi_dialog_check_messages( NULL );
471 static void msi_dialog_map_events(msi_dialog* dialog, LPCWSTR control)
473 static WCHAR Query[] = {
474 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
475 '`','E','v','e','n','t','M','a','p','p','i','n','g','`',' ',
476 'W','H','E','R','E',' ',
477 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',' ',
479 '`','C','o','n','t','r','o','l','_','`',' ','=',' ','\'','%','s','\'',0
482 LPCWSTR event, attribute;
484 row = MSI_QueryGetRecord( dialog->package->db, Query, dialog->name, control );
488 event = MSI_RecordGetString( row, 3 );
489 attribute = MSI_RecordGetString( row, 4 );
490 ControlEvent_SubscribeToEvent( dialog->package, event, control, attribute );
491 msiobj_release( &row->hdr );
494 /* everything except radio buttons */
495 static msi_control *msi_dialog_add_control( msi_dialog *dialog,
496 MSIRECORD *rec, LPCWSTR szCls, DWORD style )
501 name = MSI_RecordGetString( rec, 2 );
502 attributes = MSI_RecordGetInteger( rec, 8 );
503 text = MSI_RecordGetString( rec, 10 );
504 if( attributes & msidbControlAttributesVisible )
506 if( ~attributes & msidbControlAttributesEnabled )
507 style |= WS_DISABLED;
509 msi_dialog_map_events(dialog, name);
511 return msi_dialog_create_window( dialog, rec, szCls, name, text,
512 style, dialog->hwnd );
522 * we don't erase our own background,
523 * so we have to make sure that the parent window redraws first
525 static void msi_text_on_settext( HWND hWnd )
530 hParent = GetParent( hWnd );
531 GetWindowRect( hWnd, &rc );
532 MapWindowPoints( NULL, hParent, (LPPOINT) &rc, 2 );
533 InvalidateRect( hParent, &rc, TRUE );
536 static LRESULT WINAPI
537 MSIText_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
539 struct msi_text_info *info;
542 TRACE("%p %04x %08x %08lx\n", hWnd, msg, wParam, lParam);
544 info = GetPropW(hWnd, szButtonData);
546 if( msg == WM_CTLCOLORSTATIC &&
547 ( info->attributes & msidbControlAttributesTransparent ) )
549 SetBkMode( (HDC)wParam, TRANSPARENT );
550 return (LRESULT) GetStockObject(NULL_BRUSH);
553 r = CallWindowProcW(info->oldproc, hWnd, msg, wParam, lParam);
558 msi_text_on_settext( hWnd );
562 RemovePropW( hWnd, szButtonData );
569 static UINT msi_dialog_text_control( msi_dialog *dialog, MSIRECORD *rec )
571 msi_control *control;
572 struct msi_text_info *info;
574 TRACE("%p %p\n", dialog, rec);
576 control = msi_dialog_add_control( dialog, rec, szStatic, SS_LEFT | WS_GROUP );
578 return ERROR_FUNCTION_FAILED;
580 info = msi_alloc( sizeof *info );
582 return ERROR_SUCCESS;
584 info->attributes = MSI_RecordGetInteger( rec, 8 );
585 if( info->attributes & msidbControlAttributesTransparent )
586 SetWindowLongPtrW( control->hwnd, GWL_EXSTYLE, WS_EX_TRANSPARENT );
588 info->oldproc = (WNDPROC) SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
589 (LONG_PTR)MSIText_WndProc );
590 SetPropW( control->hwnd, szButtonData, info );
592 return ERROR_SUCCESS;
595 static UINT msi_dialog_button_control( msi_dialog *dialog, MSIRECORD *rec )
597 msi_control *control;
598 UINT attributes, style;
601 TRACE("%p %p\n", dialog, rec);
604 attributes = MSI_RecordGetInteger( rec, 8 );
605 if( attributes & msidbControlAttributesIcon )
608 control = msi_dialog_add_control( dialog, rec, szButton, style );
610 return ERROR_FUNCTION_FAILED;
612 control->handler = msi_dialog_button_handler;
615 text = msi_get_deformatted_field( dialog->package, rec, 10 );
616 control->hIcon = msi_load_icon( dialog->package->db, text, attributes );
617 if( attributes & msidbControlAttributesIcon )
618 SendMessageW( control->hwnd, BM_SETIMAGE, IMAGE_ICON, (LPARAM) control->hIcon );
621 return ERROR_SUCCESS;
624 static LPWSTR msi_get_checkbox_value( msi_dialog *dialog, LPCWSTR prop )
626 const static WCHAR query[] = {
627 'S','E','L','E','C','T',' ','*',' ',
628 'F','R','O','M',' ','`','C','h','e','c','k','B','o','x',' ','`',
629 'W','H','E','R','E',' ',
630 '`','P','r','o','p','e','r','t','y','`',' ','=',' ',
633 MSIRECORD *rec = NULL;
636 /* find if there is a value associated with the checkbox */
637 rec = MSI_QueryGetRecord( dialog->package->db, query, prop );
641 ret = msi_get_deformatted_field( dialog->package, rec, 2 );
647 msiobj_release( &rec->hdr );
651 ret = msi_dup_property( dialog->package, prop );
661 static UINT msi_dialog_checkbox_control( msi_dialog *dialog, MSIRECORD *rec )
663 msi_control *control;
666 TRACE("%p %p\n", dialog, rec);
668 control = msi_dialog_add_control( dialog, rec, szButton,
669 BS_CHECKBOX | BS_MULTILINE | WS_TABSTOP );
670 control->handler = msi_dialog_checkbox_handler;
671 prop = MSI_RecordGetString( rec, 9 );
674 control->property = strdupW( prop );
675 control->value = msi_get_checkbox_value( dialog, prop );
676 TRACE("control %s value %s\n", debugstr_w(control->property),
677 debugstr_w(control->value));
679 msi_dialog_checkbox_sync_state( dialog, control );
681 return ERROR_SUCCESS;
684 static UINT msi_dialog_line_control( msi_dialog *dialog, MSIRECORD *rec )
686 TRACE("%p %p\n", dialog, rec);
688 msi_dialog_add_control( dialog, rec, szStatic, SS_ETCHEDHORZ | SS_SUNKEN );
689 return ERROR_SUCCESS;
692 struct msi_streamin_info
699 static DWORD CALLBACK
700 msi_richedit_stream_in( DWORD_PTR arg, LPBYTE buffer, LONG count, LONG *pcb )
702 struct msi_streamin_info *info = (struct msi_streamin_info*) arg;
704 if( (count + info->offset) > info->length )
705 count = info->length - info->offset;
706 memcpy( buffer, &info->string[ info->offset ], count );
708 info->offset += count;
710 TRACE("%ld/%ld\n", info->offset, info->length);
715 static UINT msi_dialog_scrolltext_control( msi_dialog *dialog, MSIRECORD *rec )
717 const static WCHAR szRichEdit20W[] = {
718 'R','i','c','h','E','d','i','t','2','0','W',0
720 struct msi_streamin_info info;
721 msi_control *control;
727 hRichedit = LoadLibraryA("riched20");
729 style = WS_BORDER | ES_MULTILINE | WS_VSCROLL |
730 ES_READONLY | ES_AUTOVSCROLL | WS_TABSTOP;
731 control = msi_dialog_add_control( dialog, rec, szRichEdit20W, style );
733 return ERROR_FUNCTION_FAILED;
735 control->hDll = hRichedit;
737 text = MSI_RecordGetString( rec, 10 );
738 info.string = strdupWtoA( text );
740 info.length = lstrlenA( info.string ) + 1;
742 es.dwCookie = (DWORD_PTR) &info;
744 es.pfnCallback = msi_richedit_stream_in;
746 SendMessageW( control->hwnd, EM_STREAMIN, SF_RTF, (LPARAM) &es );
748 msi_free( info.string );
750 return ERROR_SUCCESS;
753 static HBITMAP msi_load_picture( MSIDATABASE *db, LPCWSTR name,
754 INT cx, INT cy, DWORD flags )
756 HBITMAP hOleBitmap = 0, hBitmap = 0, hOldSrcBitmap, hOldDestBitmap;
757 MSIRECORD *rec = NULL;
759 IPicture *pic = NULL;
764 rec = msi_get_binary_record( db, name );
768 r = MSI_RecordGetIStream( rec, 2, &stm );
769 msiobj_release( &rec->hdr );
770 if( r != ERROR_SUCCESS )
773 r = OleLoadPicture( stm, 0, TRUE, &IID_IPicture, (LPVOID*) &pic );
774 IStream_Release( stm );
777 ERR("failed to load picture\n");
781 r = IPicture_get_Handle( pic, (OLE_HANDLE*) &hOleBitmap );
784 ERR("failed to get bitmap handle\n");
788 /* make the bitmap the desired size */
789 r = GetObjectW( hOleBitmap, sizeof bm, &bm );
792 ERR("failed to get bitmap size\n");
796 if (flags & LR_DEFAULTSIZE)
802 srcdc = CreateCompatibleDC( NULL );
803 hOldSrcBitmap = SelectObject( srcdc, hOleBitmap );
804 destdc = CreateCompatibleDC( NULL );
805 hBitmap = CreateCompatibleBitmap( srcdc, cx, cy );
806 hOldDestBitmap = SelectObject( destdc, hBitmap );
807 StretchBlt( destdc, 0, 0, cx, cy,
808 srcdc, 0, 0, bm.bmWidth, bm.bmHeight, SRCCOPY);
809 SelectObject( srcdc, hOldSrcBitmap );
810 SelectObject( destdc, hOldDestBitmap );
816 IPicture_Release( pic );
820 static UINT msi_dialog_bitmap_control( msi_dialog *dialog, MSIRECORD *rec )
822 UINT cx, cy, flags, style, attributes;
823 msi_control *control;
826 flags = LR_LOADFROMFILE;
827 style = SS_BITMAP | SS_LEFT | WS_GROUP;
829 attributes = MSI_RecordGetInteger( rec, 8 );
830 if( attributes & msidbControlAttributesFixedSize )
832 flags |= LR_DEFAULTSIZE;
833 style |= SS_CENTERIMAGE;
836 control = msi_dialog_add_control( dialog, rec, szStatic, style );
837 cx = MSI_RecordGetInteger( rec, 6 );
838 cy = MSI_RecordGetInteger( rec, 7 );
839 cx = msi_dialog_scale_unit( dialog, cx );
840 cy = msi_dialog_scale_unit( dialog, cy );
842 text = msi_get_deformatted_field( dialog->package, rec, 10 );
843 control->hBitmap = msi_load_picture( dialog->package->db, text, cx, cy, flags );
844 if( control->hBitmap )
845 SendMessageW( control->hwnd, STM_SETIMAGE,
846 IMAGE_BITMAP, (LPARAM) control->hBitmap );
848 ERR("Failed to load bitmap %s\n", debugstr_w(text));
852 return ERROR_SUCCESS;
855 static UINT msi_dialog_icon_control( msi_dialog *dialog, MSIRECORD *rec )
857 msi_control *control;
863 control = msi_dialog_add_control( dialog, rec, szStatic,
864 SS_ICON | SS_CENTERIMAGE | WS_GROUP );
866 attributes = MSI_RecordGetInteger( rec, 8 );
867 text = msi_get_deformatted_field( dialog->package, rec, 10 );
868 control->hIcon = msi_load_icon( dialog->package->db, text, attributes );
870 SendMessageW( control->hwnd, STM_SETICON, (WPARAM) control->hIcon, 0 );
872 ERR("Failed to load bitmap %s\n", debugstr_w(text));
874 return ERROR_SUCCESS;
877 static UINT msi_dialog_combo_control( msi_dialog *dialog, MSIRECORD *rec )
879 static const WCHAR szCombo[] = { 'C','O','M','B','O','B','O','X',0 };
881 msi_dialog_add_control( dialog, rec, szCombo,
882 SS_BITMAP | SS_LEFT | SS_CENTERIMAGE );
883 return ERROR_SUCCESS;
886 static UINT msi_dialog_edit_control( msi_dialog *dialog, MSIRECORD *rec )
888 msi_control *control;
892 control = msi_dialog_add_control( dialog, rec, szEdit,
893 WS_BORDER | WS_TABSTOP );
894 control->handler = msi_dialog_edit_handler;
895 prop = MSI_RecordGetString( rec, 9 );
897 control->property = strdupW( prop );
898 val = msi_dup_property( dialog->package, control->property );
899 SetWindowTextW( control->hwnd, val );
901 return ERROR_SUCCESS;
904 /******************** Masked Edit ********************************************/
906 #define MASK_MAX_GROUPS 10
908 struct msi_mask_group
916 struct msi_maskedit_info
924 struct msi_mask_group group[MASK_MAX_GROUPS];
927 static void msi_mask_control_change( struct msi_maskedit_info *info )
932 val = msi_alloc( (info->num_chars+1)*sizeof(WCHAR) );
933 for( i=0, n=0; i<info->num_groups; i++ )
935 if( (info->group[i].len + n) > info->num_chars )
937 ERR("can't fit control %d text into template\n",i);
940 r = GetWindowTextW( info->group[i].hwnd, &val[n], info->group[i].len+1 );
941 if( r != info->group[i].len )
946 TRACE("%d/%d controls were good\n", i, info->num_groups);
948 if( i == info->num_groups )
950 TRACE("Set property %s to %s\n",
951 debugstr_w(info->prop), debugstr_w(val) );
952 CharUpperBuffW( val, info->num_chars );
953 MSI_SetPropertyW( info->dialog->package, info->prop, val );
954 msi_dialog_evaluate_control_conditions( info->dialog );
959 /* now move to the next control if necessary */
960 static VOID msi_mask_next_control( struct msi_maskedit_info *info, HWND hWnd )
965 for( i=0; i<info->num_groups; i++ )
966 if( info->group[i].hwnd == hWnd )
969 /* don't move from the last control */
970 if( i >= (info->num_groups-1) )
973 len = SendMessageW( hWnd, WM_GETTEXTLENGTH, 0, 0 );
974 if( len < info->group[i].len )
977 hWndNext = GetNextDlgTabItem( GetParent( hWnd ), hWnd, FALSE );
978 SetFocus( hWndNext );
981 static LRESULT WINAPI
982 MSIMaskedEdit_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
984 struct msi_maskedit_info *info;
987 TRACE("%p %04x %08x %08lx\n", hWnd, msg, wParam, lParam);
989 info = GetPropW(hWnd, szButtonData);
991 r = CallWindowProcW(info->oldproc, hWnd, msg, wParam, lParam);
996 if (HIWORD(wParam) == EN_CHANGE)
998 msi_mask_control_change( info );
999 msi_mask_next_control( info, (HWND) lParam );
1003 msi_free( info->prop );
1005 RemovePropW( hWnd, szButtonData );
1012 /* fish the various bits of the property out and put them in the control */
1014 msi_maskedit_set_text( struct msi_maskedit_info *info, LPCWSTR text )
1020 for( i = 0; i < info->num_groups; i++ )
1022 if( info->group[i].len < lstrlenW( p ) )
1024 LPWSTR chunk = strdupW( p );
1025 chunk[ info->group[i].len ] = 0;
1026 SetWindowTextW( info->group[i].hwnd, chunk );
1031 SetWindowTextW( info->group[i].hwnd, p );
1034 p += info->group[i].len;
1038 static struct msi_maskedit_info * msi_dialog_parse_groups( LPCWSTR mask )
1040 struct msi_maskedit_info * info = NULL;
1041 int i = 0, n = 0, total = 0;
1044 TRACE("masked control, template %s\n", debugstr_w(mask));
1049 p = strchrW(mask, '<');
1053 info = msi_alloc_zero( sizeof *info );
1058 for( i=0; i<MASK_MAX_GROUPS; i++ )
1066 /* stop at the end of the string */
1067 if( p[0] == 0 || p[0] == '>' )
1070 /* count the number of the same identifier */
1071 for( n=0; p[n] == p[0]; n++ )
1073 info->group[i].ofs = total;
1074 info->group[i].type = p[0];
1078 total++; /* an extra not part of the group */
1080 info->group[i].len = n;
1085 TRACE("%d characters in %d groups\n", total, i );
1086 if( i == MASK_MAX_GROUPS )
1087 ERR("too many groups in PIDTemplate %s\n", debugstr_w(mask));
1089 info->num_chars = total;
1090 info->num_groups = i;
1096 msi_maskedit_create_children( struct msi_maskedit_info *info, LPCWSTR font )
1098 DWORD width, height, style, wx, ww;
1103 style = WS_CHILD | WS_BORDER | WS_VISIBLE | WS_TABSTOP;
1105 GetClientRect( info->hwnd, &rect );
1107 width = rect.right - rect.left;
1108 height = rect.bottom - rect.top;
1110 for( i = 0; i < info->num_groups; i++ )
1112 wx = (info->group[i].ofs * width) / info->num_chars;
1113 ww = (info->group[i].len * width) / info->num_chars;
1115 hwnd = CreateWindowW( szEdit, NULL, style, wx, 0, ww, height,
1116 info->hwnd, NULL, NULL, NULL );
1119 ERR("failed to create mask edit sub window\n");
1123 SendMessageW( hwnd, EM_LIMITTEXT, info->group[i].len, 0 );
1125 msi_dialog_set_font( info->dialog, hwnd,
1126 font?font:info->dialog->default_font );
1127 info->group[i].hwnd = hwnd;
1131 /* office 2003 uses "73931<````=````=````=````=`````>@@@@@" */
1132 static UINT msi_dialog_maskedit_control( msi_dialog *dialog, MSIRECORD *rec )
1134 LPWSTR font_mask, val = NULL, font;
1135 struct msi_maskedit_info *info = NULL;
1136 UINT ret = ERROR_SUCCESS;
1137 msi_control *control;
1142 font_mask = msi_get_deformatted_field( dialog->package, rec, 10 );
1143 font = msi_dialog_get_style( font_mask, &mask );
1146 ERR("mask template is empty\n");
1150 info = msi_dialog_parse_groups( mask );
1153 ERR("template %s is invalid\n", debugstr_w(mask));
1157 info->dialog = dialog;
1159 control = msi_dialog_add_control( dialog, rec, szStatic,
1160 SS_OWNERDRAW | WS_GROUP | WS_VISIBLE );
1163 ERR("Failed to create maskedit container\n");
1164 ret = ERROR_FUNCTION_FAILED;
1167 SetWindowLongPtrW( control->hwnd, GWL_EXSTYLE, WS_EX_CONTROLPARENT );
1169 info->hwnd = control->hwnd;
1171 /* subclass the static control */
1172 info->oldproc = (WNDPROC) SetWindowLongPtrW( info->hwnd, GWLP_WNDPROC,
1173 (LONG_PTR)MSIMaskedEdit_WndProc );
1174 SetPropW( control->hwnd, szButtonData, info );
1176 prop = MSI_RecordGetString( rec, 9 );
1178 info->prop = strdupW( prop );
1180 msi_maskedit_create_children( info, font );
1184 val = msi_dup_property( dialog->package, prop );
1187 msi_maskedit_set_text( info, val );
1193 if( ret != ERROR_SUCCESS )
1195 msi_free( font_mask );
1200 /******************** Progress Bar *****************************************/
1202 static UINT msi_dialog_progress_bar( msi_dialog *dialog, MSIRECORD *rec )
1204 msi_dialog_add_control( dialog, rec, PROGRESS_CLASSW, WS_VISIBLE );
1205 return ERROR_SUCCESS;
1208 /******************** Path Edit ********************************************/
1210 static UINT msi_dialog_pathedit_control( msi_dialog *dialog, MSIRECORD *rec )
1212 FIXME("not implemented properly\n");
1213 return msi_dialog_edit_control( dialog, rec );
1216 /* radio buttons are a bit different from normal controls */
1217 static UINT msi_dialog_create_radiobutton( MSIRECORD *rec, LPVOID param )
1219 radio_button_group_descr *group = (radio_button_group_descr *)param;
1220 msi_dialog *dialog = group->dialog;
1221 msi_control *control;
1222 LPCWSTR prop, text, name;
1223 DWORD style, attributes = group->attributes;
1225 style = WS_CHILD | BS_AUTORADIOBUTTON | BS_MULTILINE | WS_TABSTOP;
1226 name = MSI_RecordGetString( rec, 3 );
1227 text = MSI_RecordGetString( rec, 8 );
1228 if( attributes & 1 )
1229 style |= WS_VISIBLE;
1230 if( ~attributes & 2 )
1231 style |= WS_DISABLED;
1233 control = msi_dialog_create_window( dialog, rec, szButton, name, text,
1234 style, group->parent->hwnd );
1236 return ERROR_FUNCTION_FAILED;
1237 control->handler = msi_dialog_radiogroup_handler;
1239 prop = MSI_RecordGetString( rec, 1 );
1241 control->property = strdupW( prop );
1243 return ERROR_SUCCESS;
1246 static UINT msi_dialog_radiogroup_control( msi_dialog *dialog, MSIRECORD *rec )
1248 static const WCHAR query[] = {
1249 'S','E','L','E','C','T',' ','*',' ',
1250 'F','R','O','M',' ','R','a','d','i','o','B','u','t','t','o','n',' ',
1251 'W','H','E','R','E',' ',
1252 '`','P','r','o','p','e','r','t','y','`',' ','=',' ','\'','%','s','\'',0};
1255 msi_control *control;
1256 MSIQUERY *view = NULL;
1257 radio_button_group_descr group;
1258 MSIPACKAGE *package = dialog->package;
1261 prop = MSI_RecordGetString( rec, 9 );
1263 TRACE("%p %p %s\n", dialog, rec, debugstr_w( prop ));
1265 /* Create parent group box to hold radio buttons */
1266 control = msi_dialog_add_control( dialog, rec, szButton, BS_OWNERDRAW|WS_GROUP );
1268 return ERROR_FUNCTION_FAILED;
1270 oldproc = (WNDPROC) SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
1271 (LONG_PTR)MSIRadioGroup_WndProc );
1272 SetPropW(control->hwnd, szButtonData, oldproc);
1273 SetWindowLongPtrW( control->hwnd, GWL_EXSTYLE, WS_EX_CONTROLPARENT );
1276 control->property = strdupW( prop );
1278 /* query the Radio Button table for all control in this group */
1279 r = MSI_OpenQuery( package->db, &view, query, prop );
1280 if( r != ERROR_SUCCESS )
1282 ERR("query failed for dialog %s radio group %s\n",
1283 debugstr_w(dialog->name), debugstr_w(prop));
1284 return ERROR_INVALID_PARAMETER;
1287 group.dialog = dialog;
1288 group.parent = control;
1289 group.attributes = MSI_RecordGetInteger( rec, 8 );
1291 r = MSI_IterateRecords( view, 0, msi_dialog_create_radiobutton, &group );
1292 msiobj_release( &view->hdr );
1297 struct control_handler msi_dialog_handler[] =
1299 { szText, msi_dialog_text_control },
1300 { szPushButton, msi_dialog_button_control },
1301 { szLine, msi_dialog_line_control },
1302 { szBitmap, msi_dialog_bitmap_control },
1303 { szCheckBox, msi_dialog_checkbox_control },
1304 { szScrollableText, msi_dialog_scrolltext_control },
1305 { szComboBox, msi_dialog_combo_control },
1306 { szEdit, msi_dialog_edit_control },
1307 { szMaskedEdit, msi_dialog_maskedit_control },
1308 { szPathEdit, msi_dialog_pathedit_control },
1309 { szProgressBar, msi_dialog_progress_bar },
1310 { szRadioButtonGroup, msi_dialog_radiogroup_control },
1311 { szIcon, msi_dialog_icon_control },
1314 #define NUM_CONTROL_TYPES (sizeof msi_dialog_handler/sizeof msi_dialog_handler[0])
1316 static UINT msi_dialog_create_controls( MSIRECORD *rec, LPVOID param )
1318 msi_dialog *dialog = param;
1319 LPCWSTR control_type;
1322 /* find and call the function that can create this type of control */
1323 control_type = MSI_RecordGetString( rec, 3 );
1324 for( i=0; i<NUM_CONTROL_TYPES; i++ )
1325 if (!strcmpiW( msi_dialog_handler[i].control_type, control_type ))
1327 if( i != NUM_CONTROL_TYPES )
1328 msi_dialog_handler[i].func( dialog, rec );
1330 ERR("no handler for element type %s\n", debugstr_w(control_type));
1332 return ERROR_SUCCESS;
1335 static UINT msi_dialog_fill_controls( msi_dialog *dialog )
1337 static const WCHAR query[] = {
1338 'S','E','L','E','C','T',' ','*',' ',
1339 'F','R','O','M',' ','C','o','n','t','r','o','l',' ',
1340 'W','H','E','R','E',' ',
1341 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',0};
1343 MSIQUERY *view = NULL;
1344 MSIPACKAGE *package = dialog->package;
1346 TRACE("%p %s\n", dialog, debugstr_w(dialog->name) );
1348 /* query the Control table for all the elements of the control */
1349 r = MSI_OpenQuery( package->db, &view, query, dialog->name );
1350 if( r != ERROR_SUCCESS )
1352 ERR("query failed for dialog %s\n", debugstr_w(dialog->name));
1353 return ERROR_INVALID_PARAMETER;
1356 r = MSI_IterateRecords( view, 0, msi_dialog_create_controls, dialog );
1357 msiobj_release( &view->hdr );
1362 static UINT msi_dialog_set_control_condition( MSIRECORD *rec, LPVOID param )
1364 static const WCHAR szHide[] = { 'H','i','d','e',0 };
1365 static const WCHAR szShow[] = { 'S','h','o','w',0 };
1366 static const WCHAR szDisable[] = { 'D','i','s','a','b','l','e',0 };
1367 static const WCHAR szEnable[] = { 'E','n','a','b','l','e',0 };
1368 msi_dialog *dialog = param;
1369 msi_control *control;
1370 LPCWSTR name, action, condition;
1373 name = MSI_RecordGetString( rec, 2 );
1374 action = MSI_RecordGetString( rec, 3 );
1375 condition = MSI_RecordGetString( rec, 4 );
1376 r = MSI_EvaluateConditionW( dialog->package, condition );
1377 control = msi_dialog_find_control( dialog, name );
1380 TRACE("%s control %s\n", debugstr_w(action), debugstr_w(name));
1382 /* FIXME: case sensitive? */
1383 if(!lstrcmpW(action, szHide))
1384 ShowWindow(control->hwnd, SW_HIDE);
1385 else if(!strcmpW(action, szShow))
1386 ShowWindow(control->hwnd, SW_SHOW);
1387 else if(!strcmpW(action, szDisable))
1388 EnableWindow(control->hwnd, FALSE);
1389 else if(!strcmpW(action, szEnable))
1390 EnableWindow(control->hwnd, TRUE);
1392 FIXME("Unhandled action %s\n", debugstr_w(action));
1395 return ERROR_SUCCESS;
1398 static UINT msi_dialog_evaluate_control_conditions( msi_dialog *dialog )
1400 static const WCHAR query[] = {
1401 'S','E','L','E','C','T',' ','*',' ',
1402 'F','R','O','M',' ',
1403 'C','o','n','t','r','o','l','C','o','n','d','i','t','i','o','n',' ',
1404 'W','H','E','R','E',' ',
1405 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',0
1408 MSIQUERY *view = NULL;
1409 MSIPACKAGE *package = dialog->package;
1411 TRACE("%p %s\n", dialog, debugstr_w(dialog->name) );
1413 /* query the Control table for all the elements of the control */
1414 r = MSI_OpenQuery( package->db, &view, query, dialog->name );
1415 if( r != ERROR_SUCCESS )
1417 ERR("query failed for dialog %s\n", debugstr_w(dialog->name));
1418 return ERROR_INVALID_PARAMETER;
1421 r = MSI_IterateRecords( view, 0, msi_dialog_set_control_condition, dialog );
1422 msiobj_release( &view->hdr );
1427 /* figure out the height of 10 point MS Sans Serif */
1428 static INT msi_dialog_get_sans_serif_height( HWND hwnd )
1430 static const WCHAR szSansSerif[] = {
1431 'M','S',' ','S','a','n','s',' ','S','e','r','i','f',0 };
1436 HFONT hFont, hOldFont;
1439 hdc = GetDC( hwnd );
1442 memset( &lf, 0, sizeof lf );
1443 lf.lfHeight = MulDiv(10, GetDeviceCaps(hdc, LOGPIXELSY), 72);
1444 strcpyW( lf.lfFaceName, szSansSerif );
1445 hFont = CreateFontIndirectW(&lf);
1448 hOldFont = SelectObject( hdc, hFont );
1449 r = GetTextMetricsW( hdc, &tm );
1451 height = tm.tmHeight;
1452 SelectObject( hdc, hOldFont );
1453 DeleteObject( hFont );
1455 ReleaseDC( hwnd, hdc );
1460 /* fetch the associated record from the Dialog table */
1461 static MSIRECORD *msi_get_dialog_record( msi_dialog *dialog )
1463 static const WCHAR query[] = {
1464 'S','E','L','E','C','T',' ','*',' ',
1465 'F','R','O','M',' ','D','i','a','l','o','g',' ',
1466 'W','H','E','R','E',' ',
1467 '`','D','i','a','l','o','g','`',' ','=',' ','\'','%','s','\'',0};
1468 MSIPACKAGE *package = dialog->package;
1469 MSIRECORD *rec = NULL;
1471 TRACE("%p %s\n", dialog, debugstr_w(dialog->name) );
1473 rec = MSI_QueryGetRecord( package->db, query, dialog->name );
1475 ERR("query failed for dialog %s\n", debugstr_w(dialog->name));
1480 static void msi_dialog_adjust_dialog_size( msi_dialog *dialog, LPSIZE sz )
1485 /* turn the client size into the window rectangle */
1488 rect.right = msi_dialog_scale_unit( dialog, sz->cx );
1489 rect.bottom = msi_dialog_scale_unit( dialog, sz->cy );
1490 style = GetWindowLongPtrW( dialog->hwnd, GWL_STYLE );
1491 AdjustWindowRect( &rect, style, FALSE );
1492 sz->cx = rect.right - rect.left;
1493 sz->cy = rect.bottom - rect.top;
1496 static BOOL msi_control_set_next( msi_control *control, msi_control *next )
1498 return SetWindowPos( next->hwnd, control->hwnd, 0, 0, 0, 0,
1499 SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOREDRAW |
1500 SWP_NOREPOSITION | SWP_NOSENDCHANGING | SWP_NOSIZE );
1503 static UINT msi_dialog_set_tab_order( msi_dialog *dialog )
1505 msi_control *control, *tab_next;
1507 LIST_FOR_EACH_ENTRY( control, &dialog->controls, msi_control, entry )
1509 tab_next = msi_dialog_find_control( dialog, control->tabnext );
1512 msi_control_set_next( control, tab_next );
1515 return ERROR_SUCCESS;
1518 static void msi_dialog_set_first_control( msi_dialog* dialog, LPCWSTR name )
1520 msi_control *control;
1522 control = msi_dialog_find_control( dialog, name );
1524 dialog->hWndFocus = control->hwnd;
1526 dialog->hWndFocus = NULL;
1529 static LRESULT msi_dialog_oncreate( HWND hwnd, LPCREATESTRUCTW cs )
1531 static const WCHAR df[] = {
1532 'D','e','f','a','u','l','t','U','I','F','o','n','t',0 };
1533 msi_dialog *dialog = (msi_dialog*) cs->lpCreateParams;
1534 MSIRECORD *rec = NULL;
1535 LPWSTR title = NULL;
1538 TRACE("%p %p\n", dialog, dialog->package);
1540 dialog->hwnd = hwnd;
1541 SetWindowLongPtrW( hwnd, GWLP_USERDATA, (LONG_PTR) dialog );
1543 rec = msi_get_dialog_record( dialog );
1546 TRACE("No record found for dialog %s\n", debugstr_w(dialog->name));
1550 dialog->scale = msi_dialog_get_sans_serif_height(dialog->hwnd);
1552 size.cx = MSI_RecordGetInteger( rec, 4 );
1553 size.cy = MSI_RecordGetInteger( rec, 5 );
1554 msi_dialog_adjust_dialog_size( dialog, &size );
1556 dialog->attributes = MSI_RecordGetInteger( rec, 6 );
1558 dialog->default_font = msi_dup_property( dialog->package, df );
1560 title = msi_get_deformatted_field( dialog->package, rec, 7 );
1561 SetWindowTextW( hwnd, title );
1564 SetWindowPos( hwnd, 0, 0, 0, size.cx, size.cy,
1565 SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOREDRAW );
1568 msi_dialog_build_font_list( dialog );
1569 msi_dialog_fill_controls( dialog );
1570 msi_dialog_evaluate_control_conditions( dialog );
1571 msi_dialog_set_tab_order( dialog );
1572 msi_dialog_set_first_control( dialog, MSI_RecordGetString( rec, 8 ) );
1573 msiobj_release( &rec->hdr );
1578 static UINT msi_dialog_send_event( msi_dialog *dialog, LPCWSTR event, LPCWSTR arg )
1580 LPWSTR event_fmt = NULL, arg_fmt = NULL;
1582 TRACE("Sending control event %s %s\n", debugstr_w(event), debugstr_w(arg));
1584 deformat_string( dialog->package, event, &event_fmt );
1585 deformat_string( dialog->package, arg, &arg_fmt );
1587 dialog->event_handler( dialog->package, event_fmt, arg_fmt, dialog );
1589 msi_free( event_fmt );
1590 msi_free( arg_fmt );
1592 return ERROR_SUCCESS;
1595 static UINT msi_dialog_set_property( msi_dialog *dialog, LPCWSTR event, LPCWSTR arg )
1597 static const WCHAR szNullArg[] = { '{','}',0 };
1598 LPWSTR p, prop, arg_fmt = NULL;
1601 len = strlenW(event);
1602 prop = msi_alloc( len*sizeof(WCHAR));
1603 strcpyW( prop, &event[1] );
1604 p = strchrW( prop, ']' );
1605 if( p && p[1] == 0 )
1608 if( strcmpW( szNullArg, arg ) )
1609 deformat_string( dialog->package, arg, &arg_fmt );
1610 MSI_SetPropertyW( dialog->package, prop, arg_fmt );
1611 msi_free( arg_fmt );
1614 ERR("Badly formatted property string - what happens?\n");
1616 return ERROR_SUCCESS;
1619 static UINT msi_dialog_control_event( MSIRECORD *rec, LPVOID param )
1621 msi_dialog *dialog = param;
1622 LPCWSTR condition, event, arg;
1625 condition = MSI_RecordGetString( rec, 5 );
1626 r = MSI_EvaluateConditionW( dialog->package, condition );
1629 event = MSI_RecordGetString( rec, 3 );
1630 arg = MSI_RecordGetString( rec, 4 );
1631 if( event[0] == '[' )
1632 msi_dialog_set_property( dialog, event, arg );
1634 msi_dialog_send_event( dialog, event, arg );
1637 return ERROR_SUCCESS;
1640 static UINT msi_dialog_button_handler( msi_dialog *dialog,
1641 msi_control *control, WPARAM param )
1643 static const WCHAR query[] = {
1644 'S','E','L','E','C','T',' ','*',' ',
1645 'F','R','O','M',' ','C','o','n','t','r','o','l','E','v','e','n','t',' ',
1646 'W','H','E','R','E',' ',
1647 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',' ',
1649 '`','C','o','n','t','r','o','l','_','`',' ','=',' ','\'','%','s','\'',' ',
1650 'O','R','D','E','R',' ','B','Y',' ','`','O','r','d','e','r','i','n','g','`',0
1652 MSIQUERY *view = NULL;
1655 if( HIWORD(param) != BN_CLICKED )
1656 return ERROR_SUCCESS;
1658 r = MSI_OpenQuery( dialog->package->db, &view, query,
1659 dialog->name, control->name );
1660 if( r != ERROR_SUCCESS )
1662 ERR("query failed\n");
1666 r = MSI_IterateRecords( view, 0, msi_dialog_control_event, dialog );
1667 msiobj_release( &view->hdr );
1672 static UINT msi_dialog_get_checkbox_state( msi_dialog *dialog,
1673 msi_control *control )
1675 WCHAR state[2] = { 0 };
1678 MSI_GetPropertyW( dialog->package, control->property, state, &sz );
1679 return state[0] ? 1 : 0;
1682 static void msi_dialog_set_checkbox_state( msi_dialog *dialog,
1683 msi_control *control, UINT state )
1685 static const WCHAR szState[] = { '1', 0 };
1688 /* if uncheck then the property is set to NULL */
1691 MSI_SetPropertyW( dialog->package, control->property, NULL );
1695 /* check for a custom state */
1696 if (control->value && control->value[0])
1697 val = control->value;
1701 MSI_SetPropertyW( dialog->package, control->property, val );
1704 static void msi_dialog_checkbox_sync_state( msi_dialog *dialog,
1705 msi_control *control )
1709 state = msi_dialog_get_checkbox_state( dialog, control );
1710 SendMessageW( control->hwnd, BM_SETCHECK,
1711 state ? BST_CHECKED : BST_UNCHECKED, 0 );
1714 static UINT msi_dialog_checkbox_handler( msi_dialog *dialog,
1715 msi_control *control, WPARAM param )
1719 if( HIWORD(param) != BN_CLICKED )
1720 return ERROR_SUCCESS;
1722 TRACE("clicked checkbox %s, set %s\n", debugstr_w(control->name),
1723 debugstr_w(control->property));
1725 state = msi_dialog_get_checkbox_state( dialog, control );
1726 state = state ? 0 : 1;
1727 msi_dialog_set_checkbox_state( dialog, control, state );
1728 msi_dialog_checkbox_sync_state( dialog, control );
1730 return msi_dialog_button_handler( dialog, control, param );
1733 static UINT msi_dialog_edit_handler( msi_dialog *dialog,
1734 msi_control *control, WPARAM param )
1739 if( HIWORD(param) != EN_CHANGE )
1740 return ERROR_SUCCESS;
1742 TRACE("edit %s contents changed, set %s\n", debugstr_w(control->name),
1743 debugstr_w(control->property));
1746 buf = msi_alloc( sz*sizeof(WCHAR) );
1749 r = GetWindowTextW( control->hwnd, buf, sz );
1753 buf = msi_realloc( buf, sz*sizeof(WCHAR) );
1756 MSI_SetPropertyW( dialog->package, control->property, buf );
1760 return ERROR_SUCCESS;
1763 static UINT msi_dialog_radiogroup_handler( msi_dialog *dialog,
1764 msi_control *control, WPARAM param )
1766 if( HIWORD(param) != BN_CLICKED )
1767 return ERROR_SUCCESS;
1769 TRACE("clicked radio button %s, set %s\n", debugstr_w(control->name),
1770 debugstr_w(control->property));
1772 MSI_SetPropertyW( dialog->package, control->property, control->name );
1774 return msi_dialog_button_handler( dialog, control, param );
1777 static LRESULT msi_dialog_oncommand( msi_dialog *dialog, WPARAM param, HWND hwnd )
1779 msi_control *control;
1781 TRACE("%p %p %08x\n", dialog, hwnd, param);
1783 control = msi_dialog_find_control_by_hwnd( dialog, hwnd );
1786 if( control->handler )
1788 control->handler( dialog, control, param );
1789 msi_dialog_evaluate_control_conditions( dialog );
1793 ERR("button click from nowhere\n");
1797 static void msi_dialog_setfocus( msi_dialog *dialog )
1799 HWND hwnd = dialog->hWndFocus;
1801 hwnd = GetNextDlgTabItem( dialog->hwnd, hwnd, TRUE);
1802 hwnd = GetNextDlgTabItem( dialog->hwnd, hwnd, FALSE);
1804 dialog->hWndFocus = hwnd;
1807 static LRESULT WINAPI MSIDialog_WndProc( HWND hwnd, UINT msg,
1808 WPARAM wParam, LPARAM lParam )
1810 msi_dialog *dialog = (LPVOID) GetWindowLongPtrW( hwnd, GWLP_USERDATA );
1812 TRACE("0x%04x\n", msg);
1817 return msi_dialog_oncreate( hwnd, (LPCREATESTRUCTW)lParam );
1820 return msi_dialog_oncommand( dialog, wParam, (HWND)lParam );
1823 if( LOWORD(wParam) == WA_INACTIVE )
1824 dialog->hWndFocus = GetFocus();
1826 msi_dialog_setfocus( dialog );
1830 msi_dialog_setfocus( dialog );
1833 /* bounce back to our subclassed static control */
1834 case WM_CTLCOLORSTATIC:
1835 return SendMessageW( (HWND) lParam, WM_CTLCOLORSTATIC, wParam, lParam );
1838 dialog->hwnd = NULL;
1841 return DefWindowProcW(hwnd, msg, wParam, lParam);
1844 static LRESULT WINAPI MSIRadioGroup_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
1846 WNDPROC oldproc = (WNDPROC) GetPropW(hWnd, szButtonData);
1848 TRACE("hWnd %p msg %04x wParam 0x%08x lParam 0x%08lx\n", hWnd, msg, wParam, lParam);
1850 if (msg == WM_COMMAND) /* Forward notifications to dialog */
1851 SendMessageW(GetParent(hWnd), msg, wParam, lParam);
1853 return CallWindowProcW(oldproc, hWnd, msg, wParam, lParam);
1856 static LRESULT WINAPI MSIHiddenWindowProc( HWND hwnd, UINT msg,
1857 WPARAM wParam, LPARAM lParam )
1859 msi_dialog *dialog = (msi_dialog*) lParam;
1861 TRACE("%d %p\n", msg, dialog);
1865 case WM_MSI_DIALOG_CREATE:
1866 return msi_dialog_run_message_loop( dialog );
1867 case WM_MSI_DIALOG_DESTROY:
1868 msi_dialog_destroy( dialog );
1871 return DefWindowProcW( hwnd, msg, wParam, lParam );
1874 /* functions that interface to other modules within MSI */
1876 msi_dialog *msi_dialog_create( MSIPACKAGE* package, LPCWSTR szDialogName,
1877 msi_dialog_event_handler event_handler )
1879 MSIRECORD *rec = NULL;
1882 TRACE("%p %s\n", package, debugstr_w(szDialogName));
1884 /* allocate the structure for the dialog to use */
1885 dialog = msi_alloc_zero( sizeof *dialog + sizeof(WCHAR)*strlenW(szDialogName) );
1888 strcpyW( dialog->name, szDialogName );
1889 msiobj_addref( &package->hdr );
1890 dialog->package = package;
1891 dialog->event_handler = event_handler;
1892 dialog->finished = 0;
1893 list_init( &dialog->controls );
1895 /* verify that the dialog exists */
1896 rec = msi_get_dialog_record( dialog );
1899 msiobj_release( &package->hdr );
1903 dialog->attributes = MSI_RecordGetInteger( rec, 6 );
1904 msiobj_release( &rec->hdr );
1909 static void msi_process_pending_messages( HWND hdlg )
1913 while( PeekMessageW( &msg, 0, 0, 0, PM_REMOVE ) )
1915 if( hdlg && IsDialogMessageW( hdlg, &msg ))
1917 TranslateMessage( &msg );
1918 DispatchMessageW( &msg );
1922 void msi_dialog_end_dialog( msi_dialog *dialog )
1924 TRACE("%p\n", dialog);
1925 dialog->finished = 1;
1926 PostMessageW(dialog->hwnd, WM_NULL, 0, 0);
1929 void msi_dialog_check_messages( HANDLE handle )
1933 /* in threads other than the UI thread, block */
1934 if( uiThreadId != GetCurrentThreadId() )
1937 WaitForSingleObject( handle, INFINITE );
1941 /* there's two choices for the UI thread */
1944 msi_process_pending_messages( NULL );
1950 * block here until somebody creates a new dialog or
1951 * the handle we're waiting on becomes ready
1953 r = MsgWaitForMultipleObjects( 1, &handle, 0, INFINITE, QS_ALLINPUT );
1954 if( r == WAIT_OBJECT_0 )
1959 UINT msi_dialog_run_message_loop( msi_dialog *dialog )
1963 if( !(dialog->attributes & msidbDialogAttributesVisible) )
1964 return ERROR_SUCCESS;
1966 if( uiThreadId != GetCurrentThreadId() )
1967 return SendMessageW( hMsiHiddenWindow, WM_MSI_DIALOG_CREATE, 0, (LPARAM) dialog );
1969 /* create the dialog window, don't show it yet */
1970 hwnd = CreateWindowW( szMsiDialogClass, dialog->name, WS_OVERLAPPEDWINDOW,
1971 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
1972 NULL, NULL, NULL, dialog );
1975 ERR("Failed to create dialog %s\n", debugstr_w( dialog->name ));
1976 return ERROR_FUNCTION_FAILED;
1979 ShowWindow( hwnd, SW_SHOW );
1980 /* UpdateWindow( hwnd ); - and causes the transparent static controls not to paint */
1982 if( dialog->attributes & msidbDialogAttributesModal )
1984 while( !dialog->finished )
1986 MsgWaitForMultipleObjects( 0, NULL, 0, INFINITE, QS_ALLEVENTS );
1987 msi_process_pending_messages( dialog->hwnd );
1991 return ERROR_IO_PENDING;
1993 return ERROR_SUCCESS;
1996 void msi_dialog_do_preview( msi_dialog *dialog )
1999 dialog->attributes |= msidbDialogAttributesVisible;
2000 dialog->attributes &= ~msidbDialogAttributesModal;
2001 msi_dialog_run_message_loop( dialog );
2004 void msi_dialog_destroy( msi_dialog *dialog )
2006 if( uiThreadId != GetCurrentThreadId() )
2008 SendMessageW( hMsiHiddenWindow, WM_MSI_DIALOG_DESTROY, 0, (LPARAM) dialog );
2013 ShowWindow( dialog->hwnd, SW_HIDE );
2016 DestroyWindow( dialog->hwnd );
2018 /* destroy the list of controls */
2019 while( !list_empty( &dialog->controls ) )
2021 msi_control *t = LIST_ENTRY( list_head( &dialog->controls ),
2022 msi_control, entry );
2023 list_remove( &t->entry );
2024 /* leave dialog->hwnd - destroying parent destroys child windows */
2025 msi_free( t->property );
2026 msi_free( t->value );
2028 DeleteObject( t->hBitmap );
2030 DestroyIcon( t->hIcon );
2031 msi_free( t->tabnext );
2034 FreeLibrary( t->hDll );
2037 /* destroy the list of fonts */
2038 while( dialog->font_list )
2040 msi_font *t = dialog->font_list;
2041 dialog->font_list = t->next;
2042 DeleteObject( t->hfont );
2045 msi_free( dialog->default_font );
2047 msiobj_release( &dialog->package->hdr );
2048 dialog->package = NULL;
2052 BOOL msi_dialog_register_class( void )
2056 ZeroMemory( &cls, sizeof cls );
2057 cls.lpfnWndProc = MSIDialog_WndProc;
2058 cls.hInstance = NULL;
2059 cls.hIcon = LoadIconW(0, (LPWSTR)IDI_APPLICATION);
2060 cls.hCursor = LoadCursorW(0, (LPWSTR)IDC_ARROW);
2061 cls.hbrBackground = (HBRUSH)(COLOR_3DFACE + 1);
2062 cls.lpszMenuName = NULL;
2063 cls.lpszClassName = szMsiDialogClass;
2065 if( !RegisterClassW( &cls ) )
2068 cls.lpfnWndProc = MSIHiddenWindowProc;
2069 cls.lpszClassName = szMsiHiddenWindow;
2071 if( !RegisterClassW( &cls ) )
2074 uiThreadId = GetCurrentThreadId();
2076 hMsiHiddenWindow = CreateWindowW( szMsiHiddenWindow, NULL, WS_OVERLAPPED,
2077 0, 0, 100, 100, NULL, NULL, NULL, NULL );
2078 if( !hMsiHiddenWindow )
2084 void msi_dialog_unregister_class( void )
2086 DestroyWindow( hMsiHiddenWindow );
2087 UnregisterClassW( szMsiDialogClass, NULL );