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;
83 LPWSTR control_default;
84 LPWSTR control_cancel;
88 typedef UINT (*msi_dialog_control_func)( msi_dialog *dialog, MSIRECORD *rec );
89 struct control_handler
92 msi_dialog_control_func func;
100 } radio_button_group_descr;
102 const WCHAR szMsiDialogClass[] = {
103 'M','s','i','D','i','a','l','o','g','C','l','o','s','e','C','l','a','s','s',0
105 const WCHAR szMsiHiddenWindow[] = {
106 'M','s','i','H','i','d','d','e','n','W','i','n','d','o','w',0 };
107 const static WCHAR szStatic[] = { 'S','t','a','t','i','c',0 };
108 const static WCHAR szButton[] = { 'B','U','T','T','O','N', 0 };
109 const static WCHAR szButtonData[] = { 'M','S','I','D','A','T','A',0 };
110 static const WCHAR szText[] = { 'T','e','x','t',0 };
111 static const WCHAR szPushButton[] = { 'P','u','s','h','B','u','t','t','o','n',0 };
112 static const WCHAR szLine[] = { 'L','i','n','e',0 };
113 static const WCHAR szBitmap[] = { 'B','i','t','m','a','p',0 };
114 static const WCHAR szCheckBox[] = { 'C','h','e','c','k','B','o','x',0 };
115 static const WCHAR szScrollableText[] = {
116 'S','c','r','o','l','l','a','b','l','e','T','e','x','t',0 };
117 static const WCHAR szComboBox[] = { 'C','o','m','b','o','B','o','x',0 };
118 static const WCHAR szEdit[] = { 'E','d','i','t',0 };
119 static const WCHAR szMaskedEdit[] = { 'M','a','s','k','e','d','E','d','i','t',0 };
120 static const WCHAR szPathEdit[] = { 'P','a','t','h','E','d','i','t',0 };
121 static const WCHAR szProgressBar[] = {
122 'P','r','o','g','r','e','s','s','B','a','r',0 };
123 static const WCHAR szRadioButtonGroup[] = {
124 'R','a','d','i','o','B','u','t','t','o','n','G','r','o','u','p',0 };
125 static const WCHAR szIcon[] = { 'I','c','o','n',0 };
127 static UINT msi_dialog_checkbox_handler( msi_dialog *, msi_control *, WPARAM );
128 static void msi_dialog_checkbox_sync_state( msi_dialog *, msi_control * );
129 static UINT msi_dialog_button_handler( msi_dialog *, msi_control *, WPARAM );
130 static UINT msi_dialog_edit_handler( msi_dialog *, msi_control *, WPARAM );
131 static UINT msi_dialog_radiogroup_handler( msi_dialog *, msi_control *, WPARAM param );
132 static UINT msi_dialog_evaluate_control_conditions( msi_dialog *dialog );
133 static LRESULT WINAPI MSIRadioGroup_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
136 /* dialog sequencing */
138 #define WM_MSI_DIALOG_CREATE (WM_USER+0x100)
139 #define WM_MSI_DIALOG_DESTROY (WM_USER+0x101)
141 static DWORD uiThreadId;
142 static HWND hMsiHiddenWindow;
144 static INT msi_dialog_scale_unit( msi_dialog *dialog, INT val )
146 return (dialog->scale * val + 5) / 10;
149 static msi_control *msi_dialog_find_control( msi_dialog *dialog, LPCWSTR name )
151 msi_control *control;
155 LIST_FOR_EACH_ENTRY( control, &dialog->controls, msi_control, entry )
156 if( !strcmpW( control->name, name ) ) /* FIXME: case sensitive? */
161 static msi_control *msi_dialog_find_control_by_hwnd( msi_dialog *dialog, HWND hwnd )
163 msi_control *control;
165 LIST_FOR_EACH_ENTRY( control, &dialog->controls, msi_control, entry )
166 if( hwnd == control->hwnd )
171 static LPWSTR msi_get_deformatted_field( MSIPACKAGE *package, MSIRECORD *rec, int field )
173 LPCWSTR str = MSI_RecordGetString( rec, field );
177 deformat_string( package, str, &ret );
182 * msi_dialog_get_style
184 * Extract the {\style} string from the front of the text to display and
185 * update the pointer.
187 static LPWSTR msi_dialog_get_style( LPCWSTR p, LPCWSTR *rest )
198 q = strchrW( p, '}' );
201 if( *p == '\\' || *p == '&' )
204 /* little bit of sanity checking to stop us getting confused with RTF */
206 if( *i == '}' || *i == '\\' )
212 ret = msi_alloc( len*sizeof(WCHAR) );
215 memcpy( ret, p, len*sizeof(WCHAR) );
220 static UINT msi_dialog_add_font( MSIRECORD *rec, LPVOID param )
222 msi_dialog *dialog = param;
229 /* create a font and add it to the list */
230 name = MSI_RecordGetString( rec, 1 );
231 font = msi_alloc( sizeof *font + strlenW( name )*sizeof (WCHAR) );
232 strcpyW( font->name, name );
233 font->next = dialog->font_list;
234 dialog->font_list = font;
236 memset( &lf, 0, sizeof lf );
237 face = MSI_RecordGetString( rec, 2 );
238 lf.lfHeight = MSI_RecordGetInteger( rec, 3 );
239 style = MSI_RecordGetInteger( rec, 5 );
240 if( style & msidbTextStyleStyleBitsBold )
241 lf.lfWeight = FW_BOLD;
242 if( style & msidbTextStyleStyleBitsItalic )
244 if( style & msidbTextStyleStyleBitsUnderline )
245 lf.lfUnderline = TRUE;
246 if( style & msidbTextStyleStyleBitsStrike )
247 lf.lfStrikeOut = TRUE;
248 lstrcpynW( lf.lfFaceName, face, LF_FACESIZE );
250 /* adjust the height */
251 hdc = GetDC( dialog->hwnd );
254 lf.lfHeight = -MulDiv(lf.lfHeight, GetDeviceCaps(hdc, LOGPIXELSY), 72);
255 ReleaseDC( dialog->hwnd, hdc );
258 font->hfont = CreateFontIndirectW( &lf );
260 TRACE("Adding font style %s\n", debugstr_w(font->name) );
262 return ERROR_SUCCESS;
265 static msi_font *msi_dialog_find_font( msi_dialog *dialog, LPCWSTR name )
269 for( font = dialog->font_list; font; font = font->next )
270 if( !strcmpW( font->name, name ) ) /* FIXME: case sensitive? */
276 static UINT msi_dialog_set_font( msi_dialog *dialog, HWND hwnd, LPCWSTR name )
280 font = msi_dialog_find_font( dialog, name );
282 SendMessageW( hwnd, WM_SETFONT, (WPARAM) font->hfont, TRUE );
284 ERR("No font entry for %s\n", debugstr_w(name));
285 return ERROR_SUCCESS;
288 static UINT msi_dialog_build_font_list( msi_dialog *dialog )
290 static const WCHAR query[] = {
291 'S','E','L','E','C','T',' ','*',' ',
292 'F','R','O','M',' ','`','T','e','x','t','S','t','y','l','e','`',' ',0
295 MSIQUERY *view = NULL;
297 TRACE("dialog %p\n", dialog );
299 r = MSI_OpenQuery( dialog->package->db, &view, query );
300 if( r != ERROR_SUCCESS )
303 r = MSI_IterateRecords( view, NULL, msi_dialog_add_font, dialog );
304 msiobj_release( &view->hdr );
309 static msi_control *msi_dialog_create_window( msi_dialog *dialog,
310 MSIRECORD *rec, LPCWSTR szCls, LPCWSTR name, LPCWSTR text,
311 DWORD style, HWND parent )
313 DWORD x, y, width, height;
314 LPWSTR font = NULL, title_font = NULL;
315 LPCWSTR title = NULL;
316 msi_control *control;
320 control = msi_alloc( sizeof *control + strlenW(name)*sizeof(WCHAR) );
321 strcpyW( control->name, name );
322 list_add_head( &dialog->controls, &control->entry );
323 control->handler = NULL;
324 control->property = NULL;
325 control->value = NULL;
326 control->hBitmap = NULL;
327 control->hIcon = NULL;
328 control->hDll = NULL;
329 control->tabnext = strdupW( MSI_RecordGetString( rec, 11) );
331 x = MSI_RecordGetInteger( rec, 4 );
332 y = MSI_RecordGetInteger( rec, 5 );
333 width = MSI_RecordGetInteger( rec, 6 );
334 height = MSI_RecordGetInteger( rec, 7 );
336 x = msi_dialog_scale_unit( dialog, x );
337 y = msi_dialog_scale_unit( dialog, y );
338 width = msi_dialog_scale_unit( dialog, width );
339 height = msi_dialog_scale_unit( dialog, height );
343 deformat_string( dialog->package, text, &title_font );
344 font = msi_dialog_get_style( title_font, &title );
347 control->hwnd = CreateWindowW( szCls, title, style,
348 x, y, width, height, parent, NULL, NULL, NULL );
350 TRACE("Dialog %s control %s hwnd %p\n",
351 debugstr_w(dialog->name), debugstr_w(text), control->hwnd );
353 msi_dialog_set_font( dialog, control->hwnd,
354 font ? font : dialog->default_font );
356 msi_free( title_font );
362 static MSIRECORD *msi_get_binary_record( MSIDATABASE *db, LPCWSTR name )
364 const static WCHAR query[] = {
365 's','e','l','e','c','t',' ','*',' ',
366 'f','r','o','m',' ','B','i','n','a','r','y',' ',
367 'w','h','e','r','e',' ',
368 '`','N','a','m','e','`',' ','=',' ','\'','%','s','\'',0
371 return MSI_QueryGetRecord( db, query, name );
374 static LPWSTR msi_create_tmp_path(void)
378 static const WCHAR prefix[] = { 'm','s','i',0 };
381 r = GetTempPathW( MAX_PATH, tmp );
384 len = lstrlenW( tmp ) + 20;
385 path = msi_alloc( len * sizeof (WCHAR) );
388 r = GetTempFileNameW( tmp, prefix, 0, path );
399 static HANDLE msi_load_image( MSIDATABASE *db, LPCWSTR name, UINT type,
400 UINT cx, UINT cy, UINT flags )
402 MSIRECORD *rec = NULL;
403 HANDLE himage = NULL;
407 TRACE("%p %s %u %u %08x\n", db, debugstr_w(name), cx, cy, flags);
409 tmp = msi_create_tmp_path();
413 rec = msi_get_binary_record( db, name );
416 r = MSI_RecordStreamToFile( rec, 2, tmp );
417 if( r == ERROR_SUCCESS )
419 himage = LoadImageW( 0, tmp, type, cx, cy, flags );
422 msiobj_release( &rec->hdr );
429 static HICON msi_load_icon( MSIDATABASE *db, LPCWSTR text, UINT attributes )
431 DWORD cx = 0, cy = 0, flags;
433 flags = LR_LOADFROMFILE | LR_DEFAULTSIZE;
434 if( attributes & msidbControlAttributesFixedSize )
436 flags &= ~LR_DEFAULTSIZE;
437 if( attributes & msidbControlAttributesIconSize16 )
442 if( attributes & msidbControlAttributesIconSize32 )
447 /* msidbControlAttributesIconSize48 handled by above logic */
449 return msi_load_image( db, text, IMAGE_ICON, cx, cy, flags );
453 /* called from the Control Event subscription code */
454 void msi_dialog_handle_event( msi_dialog* dialog, LPCWSTR control,
455 LPCWSTR attribute, MSIRECORD *rec )
460 ctrl = msi_dialog_find_control( dialog, control );
463 if( lstrcmpW(attribute, szText) )
465 ERR("Attribute %s\n", debugstr_w(attribute));
468 text = MSI_RecordGetString( rec , 1 );
469 SetWindowTextW( ctrl->hwnd, text );
470 msi_dialog_check_messages( NULL );
473 static void msi_dialog_map_events(msi_dialog* dialog, LPCWSTR control)
475 static WCHAR Query[] = {
476 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
477 '`','E','v','e','n','t','M','a','p','p','i','n','g','`',' ',
478 'W','H','E','R','E',' ',
479 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',' ',
481 '`','C','o','n','t','r','o','l','_','`',' ','=',' ','\'','%','s','\'',0
484 LPCWSTR event, attribute;
486 row = MSI_QueryGetRecord( dialog->package->db, Query, dialog->name, control );
490 event = MSI_RecordGetString( row, 3 );
491 attribute = MSI_RecordGetString( row, 4 );
492 ControlEvent_SubscribeToEvent( dialog->package, event, control, attribute );
493 msiobj_release( &row->hdr );
496 /* everything except radio buttons */
497 static msi_control *msi_dialog_add_control( msi_dialog *dialog,
498 MSIRECORD *rec, LPCWSTR szCls, DWORD style )
503 name = MSI_RecordGetString( rec, 2 );
504 attributes = MSI_RecordGetInteger( rec, 8 );
505 text = MSI_RecordGetString( rec, 10 );
506 if( attributes & msidbControlAttributesVisible )
508 if( ~attributes & msidbControlAttributesEnabled )
509 style |= WS_DISABLED;
511 msi_dialog_map_events(dialog, name);
513 return msi_dialog_create_window( dialog, rec, szCls, name, text,
514 style, dialog->hwnd );
524 * we don't erase our own background,
525 * so we have to make sure that the parent window redraws first
527 static void msi_text_on_settext( HWND hWnd )
532 hParent = GetParent( hWnd );
533 GetWindowRect( hWnd, &rc );
534 MapWindowPoints( NULL, hParent, (LPPOINT) &rc, 2 );
535 InvalidateRect( hParent, &rc, TRUE );
538 static LRESULT WINAPI
539 MSIText_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
541 struct msi_text_info *info;
544 TRACE("%p %04x %08x %08lx\n", hWnd, msg, wParam, lParam);
546 info = GetPropW(hWnd, szButtonData);
548 if( msg == WM_CTLCOLORSTATIC &&
549 ( info->attributes & msidbControlAttributesTransparent ) )
551 SetBkMode( (HDC)wParam, TRANSPARENT );
552 return (LRESULT) GetStockObject(NULL_BRUSH);
555 r = CallWindowProcW(info->oldproc, hWnd, msg, wParam, lParam);
560 msi_text_on_settext( hWnd );
564 RemovePropW( hWnd, szButtonData );
571 static UINT msi_dialog_text_control( msi_dialog *dialog, MSIRECORD *rec )
573 msi_control *control;
574 struct msi_text_info *info;
576 TRACE("%p %p\n", dialog, rec);
578 control = msi_dialog_add_control( dialog, rec, szStatic, SS_LEFT | WS_GROUP );
580 return ERROR_FUNCTION_FAILED;
582 info = msi_alloc( sizeof *info );
584 return ERROR_SUCCESS;
586 info->attributes = MSI_RecordGetInteger( rec, 8 );
587 if( info->attributes & msidbControlAttributesTransparent )
588 SetWindowLongPtrW( control->hwnd, GWL_EXSTYLE, WS_EX_TRANSPARENT );
590 info->oldproc = (WNDPROC) SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
591 (LONG_PTR)MSIText_WndProc );
592 SetPropW( control->hwnd, szButtonData, info );
594 return ERROR_SUCCESS;
597 static UINT msi_dialog_button_control( msi_dialog *dialog, MSIRECORD *rec )
599 msi_control *control;
600 UINT attributes, style;
603 TRACE("%p %p\n", dialog, rec);
606 attributes = MSI_RecordGetInteger( rec, 8 );
607 if( attributes & msidbControlAttributesIcon )
610 control = msi_dialog_add_control( dialog, rec, szButton, style );
612 return ERROR_FUNCTION_FAILED;
614 control->handler = msi_dialog_button_handler;
617 text = msi_get_deformatted_field( dialog->package, rec, 10 );
618 control->hIcon = msi_load_icon( dialog->package->db, text, attributes );
619 if( attributes & msidbControlAttributesIcon )
620 SendMessageW( control->hwnd, BM_SETIMAGE, IMAGE_ICON, (LPARAM) control->hIcon );
623 return ERROR_SUCCESS;
626 static LPWSTR msi_get_checkbox_value( msi_dialog *dialog, LPCWSTR prop )
628 const static WCHAR query[] = {
629 'S','E','L','E','C','T',' ','*',' ',
630 'F','R','O','M',' ','`','C','h','e','c','k','B','o','x',' ','`',
631 'W','H','E','R','E',' ',
632 '`','P','r','o','p','e','r','t','y','`',' ','=',' ',
635 MSIRECORD *rec = NULL;
638 /* find if there is a value associated with the checkbox */
639 rec = MSI_QueryGetRecord( dialog->package->db, query, prop );
643 ret = msi_get_deformatted_field( dialog->package, rec, 2 );
649 msiobj_release( &rec->hdr );
653 ret = msi_dup_property( dialog->package, prop );
663 static UINT msi_dialog_checkbox_control( msi_dialog *dialog, MSIRECORD *rec )
665 msi_control *control;
668 TRACE("%p %p\n", dialog, rec);
670 control = msi_dialog_add_control( dialog, rec, szButton,
671 BS_CHECKBOX | BS_MULTILINE | WS_TABSTOP );
672 control->handler = msi_dialog_checkbox_handler;
673 prop = MSI_RecordGetString( rec, 9 );
676 control->property = strdupW( prop );
677 control->value = msi_get_checkbox_value( dialog, prop );
678 TRACE("control %s value %s\n", debugstr_w(control->property),
679 debugstr_w(control->value));
681 msi_dialog_checkbox_sync_state( dialog, control );
683 return ERROR_SUCCESS;
686 static UINT msi_dialog_line_control( msi_dialog *dialog, MSIRECORD *rec )
688 TRACE("%p %p\n", dialog, rec);
690 msi_dialog_add_control( dialog, rec, szStatic, SS_ETCHEDHORZ | SS_SUNKEN );
691 return ERROR_SUCCESS;
694 struct msi_streamin_info
701 static DWORD CALLBACK
702 msi_richedit_stream_in( DWORD_PTR arg, LPBYTE buffer, LONG count, LONG *pcb )
704 struct msi_streamin_info *info = (struct msi_streamin_info*) arg;
706 if( (count + info->offset) > info->length )
707 count = info->length - info->offset;
708 memcpy( buffer, &info->string[ info->offset ], count );
710 info->offset += count;
712 TRACE("%ld/%ld\n", info->offset, info->length);
717 static UINT msi_dialog_scrolltext_control( msi_dialog *dialog, MSIRECORD *rec )
719 const static WCHAR szRichEdit20W[] = {
720 'R','i','c','h','E','d','i','t','2','0','W',0
722 struct msi_streamin_info info;
723 msi_control *control;
729 hRichedit = LoadLibraryA("riched20");
731 style = WS_BORDER | ES_MULTILINE | WS_VSCROLL |
732 ES_READONLY | ES_AUTOVSCROLL | WS_TABSTOP;
733 control = msi_dialog_add_control( dialog, rec, szRichEdit20W, style );
735 return ERROR_FUNCTION_FAILED;
737 control->hDll = hRichedit;
739 text = MSI_RecordGetString( rec, 10 );
740 info.string = strdupWtoA( text );
742 info.length = lstrlenA( info.string ) + 1;
744 es.dwCookie = (DWORD_PTR) &info;
746 es.pfnCallback = msi_richedit_stream_in;
748 SendMessageW( control->hwnd, EM_STREAMIN, SF_RTF, (LPARAM) &es );
750 msi_free( info.string );
752 return ERROR_SUCCESS;
755 static HBITMAP msi_load_picture( MSIDATABASE *db, LPCWSTR name,
756 INT cx, INT cy, DWORD flags )
758 HBITMAP hOleBitmap = 0, hBitmap = 0, hOldSrcBitmap, hOldDestBitmap;
759 MSIRECORD *rec = NULL;
761 IPicture *pic = NULL;
766 rec = msi_get_binary_record( db, name );
770 r = MSI_RecordGetIStream( rec, 2, &stm );
771 msiobj_release( &rec->hdr );
772 if( r != ERROR_SUCCESS )
775 r = OleLoadPicture( stm, 0, TRUE, &IID_IPicture, (LPVOID*) &pic );
776 IStream_Release( stm );
779 ERR("failed to load picture\n");
783 r = IPicture_get_Handle( pic, (OLE_HANDLE*) &hOleBitmap );
786 ERR("failed to get bitmap handle\n");
790 /* make the bitmap the desired size */
791 r = GetObjectW( hOleBitmap, sizeof bm, &bm );
794 ERR("failed to get bitmap size\n");
798 if (flags & LR_DEFAULTSIZE)
804 srcdc = CreateCompatibleDC( NULL );
805 hOldSrcBitmap = SelectObject( srcdc, hOleBitmap );
806 destdc = CreateCompatibleDC( NULL );
807 hBitmap = CreateCompatibleBitmap( srcdc, cx, cy );
808 hOldDestBitmap = SelectObject( destdc, hBitmap );
809 StretchBlt( destdc, 0, 0, cx, cy,
810 srcdc, 0, 0, bm.bmWidth, bm.bmHeight, SRCCOPY);
811 SelectObject( srcdc, hOldSrcBitmap );
812 SelectObject( destdc, hOldDestBitmap );
818 IPicture_Release( pic );
822 static UINT msi_dialog_bitmap_control( msi_dialog *dialog, MSIRECORD *rec )
824 UINT cx, cy, flags, style, attributes;
825 msi_control *control;
828 flags = LR_LOADFROMFILE;
829 style = SS_BITMAP | SS_LEFT | WS_GROUP;
831 attributes = MSI_RecordGetInteger( rec, 8 );
832 if( attributes & msidbControlAttributesFixedSize )
834 flags |= LR_DEFAULTSIZE;
835 style |= SS_CENTERIMAGE;
838 control = msi_dialog_add_control( dialog, rec, szStatic, style );
839 cx = MSI_RecordGetInteger( rec, 6 );
840 cy = MSI_RecordGetInteger( rec, 7 );
841 cx = msi_dialog_scale_unit( dialog, cx );
842 cy = msi_dialog_scale_unit( dialog, cy );
844 text = msi_get_deformatted_field( dialog->package, rec, 10 );
845 control->hBitmap = msi_load_picture( dialog->package->db, text, cx, cy, flags );
846 if( control->hBitmap )
847 SendMessageW( control->hwnd, STM_SETIMAGE,
848 IMAGE_BITMAP, (LPARAM) control->hBitmap );
850 ERR("Failed to load bitmap %s\n", debugstr_w(text));
854 return ERROR_SUCCESS;
857 static UINT msi_dialog_icon_control( msi_dialog *dialog, MSIRECORD *rec )
859 msi_control *control;
865 control = msi_dialog_add_control( dialog, rec, szStatic,
866 SS_ICON | SS_CENTERIMAGE | WS_GROUP );
868 attributes = MSI_RecordGetInteger( rec, 8 );
869 text = msi_get_deformatted_field( dialog->package, rec, 10 );
870 control->hIcon = msi_load_icon( dialog->package->db, text, attributes );
872 SendMessageW( control->hwnd, STM_SETICON, (WPARAM) control->hIcon, 0 );
874 ERR("Failed to load bitmap %s\n", debugstr_w(text));
876 return ERROR_SUCCESS;
879 static UINT msi_dialog_combo_control( msi_dialog *dialog, MSIRECORD *rec )
881 static const WCHAR szCombo[] = { 'C','O','M','B','O','B','O','X',0 };
883 msi_dialog_add_control( dialog, rec, szCombo,
884 SS_BITMAP | SS_LEFT | SS_CENTERIMAGE );
885 return ERROR_SUCCESS;
888 static UINT msi_dialog_edit_control( msi_dialog *dialog, MSIRECORD *rec )
890 msi_control *control;
894 control = msi_dialog_add_control( dialog, rec, szEdit,
895 WS_BORDER | WS_TABSTOP );
896 control->handler = msi_dialog_edit_handler;
897 prop = MSI_RecordGetString( rec, 9 );
899 control->property = strdupW( prop );
900 val = msi_dup_property( dialog->package, control->property );
901 SetWindowTextW( control->hwnd, val );
903 return ERROR_SUCCESS;
906 /******************** Masked Edit ********************************************/
908 #define MASK_MAX_GROUPS 10
910 struct msi_mask_group
918 struct msi_maskedit_info
926 struct msi_mask_group group[MASK_MAX_GROUPS];
929 static void msi_mask_control_change( struct msi_maskedit_info *info )
934 val = msi_alloc( (info->num_chars+1)*sizeof(WCHAR) );
935 for( i=0, n=0; i<info->num_groups; i++ )
937 if( (info->group[i].len + n) > info->num_chars )
939 ERR("can't fit control %d text into template\n",i);
942 r = GetWindowTextW( info->group[i].hwnd, &val[n], info->group[i].len+1 );
943 if( r != info->group[i].len )
948 TRACE("%d/%d controls were good\n", i, info->num_groups);
950 if( i == info->num_groups )
952 TRACE("Set property %s to %s\n",
953 debugstr_w(info->prop), debugstr_w(val) );
954 CharUpperBuffW( val, info->num_chars );
955 MSI_SetPropertyW( info->dialog->package, info->prop, val );
956 msi_dialog_evaluate_control_conditions( info->dialog );
961 /* now move to the next control if necessary */
962 static VOID msi_mask_next_control( struct msi_maskedit_info *info, HWND hWnd )
967 for( i=0; i<info->num_groups; i++ )
968 if( info->group[i].hwnd == hWnd )
971 /* don't move from the last control */
972 if( i >= (info->num_groups-1) )
975 len = SendMessageW( hWnd, WM_GETTEXTLENGTH, 0, 0 );
976 if( len < info->group[i].len )
979 hWndNext = GetNextDlgTabItem( GetParent( hWnd ), hWnd, FALSE );
980 SetFocus( hWndNext );
983 static LRESULT WINAPI
984 MSIMaskedEdit_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
986 struct msi_maskedit_info *info;
989 TRACE("%p %04x %08x %08lx\n", hWnd, msg, wParam, lParam);
991 info = GetPropW(hWnd, szButtonData);
993 r = CallWindowProcW(info->oldproc, hWnd, msg, wParam, lParam);
998 if (HIWORD(wParam) == EN_CHANGE)
1000 msi_mask_control_change( info );
1001 msi_mask_next_control( info, (HWND) lParam );
1005 msi_free( info->prop );
1007 RemovePropW( hWnd, szButtonData );
1014 /* fish the various bits of the property out and put them in the control */
1016 msi_maskedit_set_text( struct msi_maskedit_info *info, LPCWSTR text )
1022 for( i = 0; i < info->num_groups; i++ )
1024 if( info->group[i].len < lstrlenW( p ) )
1026 LPWSTR chunk = strdupW( p );
1027 chunk[ info->group[i].len ] = 0;
1028 SetWindowTextW( info->group[i].hwnd, chunk );
1033 SetWindowTextW( info->group[i].hwnd, p );
1036 p += info->group[i].len;
1040 static struct msi_maskedit_info * msi_dialog_parse_groups( LPCWSTR mask )
1042 struct msi_maskedit_info * info = NULL;
1043 int i = 0, n = 0, total = 0;
1046 TRACE("masked control, template %s\n", debugstr_w(mask));
1051 p = strchrW(mask, '<');
1055 info = msi_alloc_zero( sizeof *info );
1060 for( i=0; i<MASK_MAX_GROUPS; i++ )
1068 /* stop at the end of the string */
1069 if( p[0] == 0 || p[0] == '>' )
1072 /* count the number of the same identifier */
1073 for( n=0; p[n] == p[0]; n++ )
1075 info->group[i].ofs = total;
1076 info->group[i].type = p[0];
1080 total++; /* an extra not part of the group */
1082 info->group[i].len = n;
1087 TRACE("%d characters in %d groups\n", total, i );
1088 if( i == MASK_MAX_GROUPS )
1089 ERR("too many groups in PIDTemplate %s\n", debugstr_w(mask));
1091 info->num_chars = total;
1092 info->num_groups = i;
1098 msi_maskedit_create_children( struct msi_maskedit_info *info, LPCWSTR font )
1100 DWORD width, height, style, wx, ww;
1105 style = WS_CHILD | WS_BORDER | WS_VISIBLE | WS_TABSTOP;
1107 GetClientRect( info->hwnd, &rect );
1109 width = rect.right - rect.left;
1110 height = rect.bottom - rect.top;
1112 for( i = 0; i < info->num_groups; i++ )
1114 wx = (info->group[i].ofs * width) / info->num_chars;
1115 ww = (info->group[i].len * width) / info->num_chars;
1117 hwnd = CreateWindowW( szEdit, NULL, style, wx, 0, ww, height,
1118 info->hwnd, NULL, NULL, NULL );
1121 ERR("failed to create mask edit sub window\n");
1125 SendMessageW( hwnd, EM_LIMITTEXT, info->group[i].len, 0 );
1127 msi_dialog_set_font( info->dialog, hwnd,
1128 font?font:info->dialog->default_font );
1129 info->group[i].hwnd = hwnd;
1133 /* office 2003 uses "73931<````=````=````=````=`````>@@@@@" */
1134 static UINT msi_dialog_maskedit_control( msi_dialog *dialog, MSIRECORD *rec )
1136 LPWSTR font_mask, val = NULL, font;
1137 struct msi_maskedit_info *info = NULL;
1138 UINT ret = ERROR_SUCCESS;
1139 msi_control *control;
1144 font_mask = msi_get_deformatted_field( dialog->package, rec, 10 );
1145 font = msi_dialog_get_style( font_mask, &mask );
1148 ERR("mask template is empty\n");
1152 info = msi_dialog_parse_groups( mask );
1155 ERR("template %s is invalid\n", debugstr_w(mask));
1159 info->dialog = dialog;
1161 control = msi_dialog_add_control( dialog, rec, szStatic,
1162 SS_OWNERDRAW | WS_GROUP | WS_VISIBLE );
1165 ERR("Failed to create maskedit container\n");
1166 ret = ERROR_FUNCTION_FAILED;
1169 SetWindowLongPtrW( control->hwnd, GWL_EXSTYLE, WS_EX_CONTROLPARENT );
1171 info->hwnd = control->hwnd;
1173 /* subclass the static control */
1174 info->oldproc = (WNDPROC) SetWindowLongPtrW( info->hwnd, GWLP_WNDPROC,
1175 (LONG_PTR)MSIMaskedEdit_WndProc );
1176 SetPropW( control->hwnd, szButtonData, info );
1178 prop = MSI_RecordGetString( rec, 9 );
1180 info->prop = strdupW( prop );
1182 msi_maskedit_create_children( info, font );
1186 val = msi_dup_property( dialog->package, prop );
1189 msi_maskedit_set_text( info, val );
1195 if( ret != ERROR_SUCCESS )
1197 msi_free( font_mask );
1202 /******************** Progress Bar *****************************************/
1204 static UINT msi_dialog_progress_bar( msi_dialog *dialog, MSIRECORD *rec )
1206 msi_dialog_add_control( dialog, rec, PROGRESS_CLASSW, WS_VISIBLE );
1207 return ERROR_SUCCESS;
1210 /******************** Path Edit ********************************************/
1212 static UINT msi_dialog_pathedit_control( msi_dialog *dialog, MSIRECORD *rec )
1214 FIXME("not implemented properly\n");
1215 return msi_dialog_edit_control( dialog, rec );
1218 /* radio buttons are a bit different from normal controls */
1219 static UINT msi_dialog_create_radiobutton( MSIRECORD *rec, LPVOID param )
1221 radio_button_group_descr *group = (radio_button_group_descr *)param;
1222 msi_dialog *dialog = group->dialog;
1223 msi_control *control;
1224 LPCWSTR prop, text, name;
1225 DWORD style, attributes = group->attributes;
1227 style = WS_CHILD | BS_AUTORADIOBUTTON | BS_MULTILINE | WS_TABSTOP;
1228 name = MSI_RecordGetString( rec, 3 );
1229 text = MSI_RecordGetString( rec, 8 );
1230 if( attributes & 1 )
1231 style |= WS_VISIBLE;
1232 if( ~attributes & 2 )
1233 style |= WS_DISABLED;
1235 control = msi_dialog_create_window( dialog, rec, szButton, name, text,
1236 style, group->parent->hwnd );
1238 return ERROR_FUNCTION_FAILED;
1239 control->handler = msi_dialog_radiogroup_handler;
1241 prop = MSI_RecordGetString( rec, 1 );
1243 control->property = strdupW( prop );
1245 return ERROR_SUCCESS;
1248 static UINT msi_dialog_radiogroup_control( msi_dialog *dialog, MSIRECORD *rec )
1250 static const WCHAR query[] = {
1251 'S','E','L','E','C','T',' ','*',' ',
1252 'F','R','O','M',' ','R','a','d','i','o','B','u','t','t','o','n',' ',
1253 'W','H','E','R','E',' ',
1254 '`','P','r','o','p','e','r','t','y','`',' ','=',' ','\'','%','s','\'',0};
1257 msi_control *control;
1258 MSIQUERY *view = NULL;
1259 radio_button_group_descr group;
1260 MSIPACKAGE *package = dialog->package;
1263 prop = MSI_RecordGetString( rec, 9 );
1265 TRACE("%p %p %s\n", dialog, rec, debugstr_w( prop ));
1267 /* Create parent group box to hold radio buttons */
1268 control = msi_dialog_add_control( dialog, rec, szButton, BS_OWNERDRAW|WS_GROUP );
1270 return ERROR_FUNCTION_FAILED;
1272 oldproc = (WNDPROC) SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
1273 (LONG_PTR)MSIRadioGroup_WndProc );
1274 SetPropW(control->hwnd, szButtonData, oldproc);
1275 SetWindowLongPtrW( control->hwnd, GWL_EXSTYLE, WS_EX_CONTROLPARENT );
1278 control->property = strdupW( prop );
1280 /* query the Radio Button table for all control in this group */
1281 r = MSI_OpenQuery( package->db, &view, query, prop );
1282 if( r != ERROR_SUCCESS )
1284 ERR("query failed for dialog %s radio group %s\n",
1285 debugstr_w(dialog->name), debugstr_w(prop));
1286 return ERROR_INVALID_PARAMETER;
1289 group.dialog = dialog;
1290 group.parent = control;
1291 group.attributes = MSI_RecordGetInteger( rec, 8 );
1293 r = MSI_IterateRecords( view, 0, msi_dialog_create_radiobutton, &group );
1294 msiobj_release( &view->hdr );
1299 struct control_handler msi_dialog_handler[] =
1301 { szText, msi_dialog_text_control },
1302 { szPushButton, msi_dialog_button_control },
1303 { szLine, msi_dialog_line_control },
1304 { szBitmap, msi_dialog_bitmap_control },
1305 { szCheckBox, msi_dialog_checkbox_control },
1306 { szScrollableText, msi_dialog_scrolltext_control },
1307 { szComboBox, msi_dialog_combo_control },
1308 { szEdit, msi_dialog_edit_control },
1309 { szMaskedEdit, msi_dialog_maskedit_control },
1310 { szPathEdit, msi_dialog_pathedit_control },
1311 { szProgressBar, msi_dialog_progress_bar },
1312 { szRadioButtonGroup, msi_dialog_radiogroup_control },
1313 { szIcon, msi_dialog_icon_control },
1316 #define NUM_CONTROL_TYPES (sizeof msi_dialog_handler/sizeof msi_dialog_handler[0])
1318 static UINT msi_dialog_create_controls( MSIRECORD *rec, LPVOID param )
1320 msi_dialog *dialog = param;
1321 LPCWSTR control_type;
1324 /* find and call the function that can create this type of control */
1325 control_type = MSI_RecordGetString( rec, 3 );
1326 for( i=0; i<NUM_CONTROL_TYPES; i++ )
1327 if (!strcmpiW( msi_dialog_handler[i].control_type, control_type ))
1329 if( i != NUM_CONTROL_TYPES )
1330 msi_dialog_handler[i].func( dialog, rec );
1332 ERR("no handler for element type %s\n", debugstr_w(control_type));
1334 return ERROR_SUCCESS;
1337 static UINT msi_dialog_fill_controls( msi_dialog *dialog )
1339 static const WCHAR query[] = {
1340 'S','E','L','E','C','T',' ','*',' ',
1341 'F','R','O','M',' ','C','o','n','t','r','o','l',' ',
1342 'W','H','E','R','E',' ',
1343 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',0};
1345 MSIQUERY *view = NULL;
1346 MSIPACKAGE *package = dialog->package;
1348 TRACE("%p %s\n", dialog, debugstr_w(dialog->name) );
1350 /* query the Control table for all the elements of the control */
1351 r = MSI_OpenQuery( package->db, &view, query, dialog->name );
1352 if( r != ERROR_SUCCESS )
1354 ERR("query failed for dialog %s\n", debugstr_w(dialog->name));
1355 return ERROR_INVALID_PARAMETER;
1358 r = MSI_IterateRecords( view, 0, msi_dialog_create_controls, dialog );
1359 msiobj_release( &view->hdr );
1364 static UINT msi_dialog_set_control_condition( MSIRECORD *rec, LPVOID param )
1366 static const WCHAR szHide[] = { 'H','i','d','e',0 };
1367 static const WCHAR szShow[] = { 'S','h','o','w',0 };
1368 static const WCHAR szDisable[] = { 'D','i','s','a','b','l','e',0 };
1369 static const WCHAR szEnable[] = { 'E','n','a','b','l','e',0 };
1370 msi_dialog *dialog = param;
1371 msi_control *control;
1372 LPCWSTR name, action, condition;
1375 name = MSI_RecordGetString( rec, 2 );
1376 action = MSI_RecordGetString( rec, 3 );
1377 condition = MSI_RecordGetString( rec, 4 );
1378 r = MSI_EvaluateConditionW( dialog->package, condition );
1379 control = msi_dialog_find_control( dialog, name );
1382 TRACE("%s control %s\n", debugstr_w(action), debugstr_w(name));
1384 /* FIXME: case sensitive? */
1385 if(!lstrcmpW(action, szHide))
1386 ShowWindow(control->hwnd, SW_HIDE);
1387 else if(!strcmpW(action, szShow))
1388 ShowWindow(control->hwnd, SW_SHOW);
1389 else if(!strcmpW(action, szDisable))
1390 EnableWindow(control->hwnd, FALSE);
1391 else if(!strcmpW(action, szEnable))
1392 EnableWindow(control->hwnd, TRUE);
1394 FIXME("Unhandled action %s\n", debugstr_w(action));
1397 return ERROR_SUCCESS;
1400 static UINT msi_dialog_evaluate_control_conditions( msi_dialog *dialog )
1402 static const WCHAR query[] = {
1403 'S','E','L','E','C','T',' ','*',' ',
1404 'F','R','O','M',' ',
1405 'C','o','n','t','r','o','l','C','o','n','d','i','t','i','o','n',' ',
1406 'W','H','E','R','E',' ',
1407 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',0
1410 MSIQUERY *view = NULL;
1411 MSIPACKAGE *package = dialog->package;
1413 TRACE("%p %s\n", dialog, debugstr_w(dialog->name) );
1415 /* query the Control table for all the elements of the control */
1416 r = MSI_OpenQuery( package->db, &view, query, dialog->name );
1417 if( r != ERROR_SUCCESS )
1419 ERR("query failed for dialog %s\n", debugstr_w(dialog->name));
1420 return ERROR_INVALID_PARAMETER;
1423 r = MSI_IterateRecords( view, 0, msi_dialog_set_control_condition, dialog );
1424 msiobj_release( &view->hdr );
1429 /* figure out the height of 10 point MS Sans Serif */
1430 static INT msi_dialog_get_sans_serif_height( HWND hwnd )
1432 static const WCHAR szSansSerif[] = {
1433 'M','S',' ','S','a','n','s',' ','S','e','r','i','f',0 };
1438 HFONT hFont, hOldFont;
1441 hdc = GetDC( hwnd );
1444 memset( &lf, 0, sizeof lf );
1445 lf.lfHeight = MulDiv(10, GetDeviceCaps(hdc, LOGPIXELSY), 72);
1446 strcpyW( lf.lfFaceName, szSansSerif );
1447 hFont = CreateFontIndirectW(&lf);
1450 hOldFont = SelectObject( hdc, hFont );
1451 r = GetTextMetricsW( hdc, &tm );
1453 height = tm.tmHeight;
1454 SelectObject( hdc, hOldFont );
1455 DeleteObject( hFont );
1457 ReleaseDC( hwnd, hdc );
1462 /* fetch the associated record from the Dialog table */
1463 static MSIRECORD *msi_get_dialog_record( msi_dialog *dialog )
1465 static const WCHAR query[] = {
1466 'S','E','L','E','C','T',' ','*',' ',
1467 'F','R','O','M',' ','D','i','a','l','o','g',' ',
1468 'W','H','E','R','E',' ',
1469 '`','D','i','a','l','o','g','`',' ','=',' ','\'','%','s','\'',0};
1470 MSIPACKAGE *package = dialog->package;
1471 MSIRECORD *rec = NULL;
1473 TRACE("%p %s\n", dialog, debugstr_w(dialog->name) );
1475 rec = MSI_QueryGetRecord( package->db, query, dialog->name );
1477 ERR("query failed for dialog %s\n", debugstr_w(dialog->name));
1482 static void msi_dialog_adjust_dialog_size( msi_dialog *dialog, LPSIZE sz )
1487 /* turn the client size into the window rectangle */
1490 rect.right = msi_dialog_scale_unit( dialog, sz->cx );
1491 rect.bottom = msi_dialog_scale_unit( dialog, sz->cy );
1492 style = GetWindowLongPtrW( dialog->hwnd, GWL_STYLE );
1493 AdjustWindowRect( &rect, style, FALSE );
1494 sz->cx = rect.right - rect.left;
1495 sz->cy = rect.bottom - rect.top;
1498 static BOOL msi_control_set_next( msi_control *control, msi_control *next )
1500 return SetWindowPos( next->hwnd, control->hwnd, 0, 0, 0, 0,
1501 SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOREDRAW |
1502 SWP_NOREPOSITION | SWP_NOSENDCHANGING | SWP_NOSIZE );
1505 static UINT msi_dialog_set_tab_order( msi_dialog *dialog )
1507 msi_control *control, *tab_next;
1509 LIST_FOR_EACH_ENTRY( control, &dialog->controls, msi_control, entry )
1511 tab_next = msi_dialog_find_control( dialog, control->tabnext );
1514 msi_control_set_next( control, tab_next );
1517 return ERROR_SUCCESS;
1520 static void msi_dialog_set_first_control( msi_dialog* dialog, LPCWSTR name )
1522 msi_control *control;
1524 control = msi_dialog_find_control( dialog, name );
1526 dialog->hWndFocus = control->hwnd;
1528 dialog->hWndFocus = NULL;
1531 static LRESULT msi_dialog_oncreate( HWND hwnd, LPCREATESTRUCTW cs )
1533 static const WCHAR df[] = {
1534 'D','e','f','a','u','l','t','U','I','F','o','n','t',0 };
1535 msi_dialog *dialog = (msi_dialog*) cs->lpCreateParams;
1536 MSIRECORD *rec = NULL;
1537 LPWSTR title = NULL;
1540 TRACE("%p %p\n", dialog, dialog->package);
1542 dialog->hwnd = hwnd;
1543 SetWindowLongPtrW( hwnd, GWLP_USERDATA, (LONG_PTR) dialog );
1545 rec = msi_get_dialog_record( dialog );
1548 TRACE("No record found for dialog %s\n", debugstr_w(dialog->name));
1552 dialog->scale = msi_dialog_get_sans_serif_height(dialog->hwnd);
1554 size.cx = MSI_RecordGetInteger( rec, 4 );
1555 size.cy = MSI_RecordGetInteger( rec, 5 );
1556 msi_dialog_adjust_dialog_size( dialog, &size );
1558 dialog->attributes = MSI_RecordGetInteger( rec, 6 );
1560 dialog->default_font = msi_dup_property( dialog->package, df );
1562 title = msi_get_deformatted_field( dialog->package, rec, 7 );
1563 SetWindowTextW( hwnd, title );
1566 SetWindowPos( hwnd, 0, 0, 0, size.cx, size.cy,
1567 SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOREDRAW );
1570 msi_dialog_build_font_list( dialog );
1571 msi_dialog_fill_controls( dialog );
1572 msi_dialog_evaluate_control_conditions( dialog );
1573 msi_dialog_set_tab_order( dialog );
1574 msi_dialog_set_first_control( dialog, MSI_RecordGetString( rec, 8 ) );
1575 msiobj_release( &rec->hdr );
1580 static UINT msi_dialog_send_event( msi_dialog *dialog, LPCWSTR event, LPCWSTR arg )
1582 LPWSTR event_fmt = NULL, arg_fmt = NULL;
1584 TRACE("Sending control event %s %s\n", debugstr_w(event), debugstr_w(arg));
1586 deformat_string( dialog->package, event, &event_fmt );
1587 deformat_string( dialog->package, arg, &arg_fmt );
1589 dialog->event_handler( dialog->package, event_fmt, arg_fmt, dialog );
1591 msi_free( event_fmt );
1592 msi_free( arg_fmt );
1594 return ERROR_SUCCESS;
1597 static UINT msi_dialog_set_property( msi_dialog *dialog, LPCWSTR event, LPCWSTR arg )
1599 static const WCHAR szNullArg[] = { '{','}',0 };
1600 LPWSTR p, prop, arg_fmt = NULL;
1603 len = strlenW(event);
1604 prop = msi_alloc( len*sizeof(WCHAR));
1605 strcpyW( prop, &event[1] );
1606 p = strchrW( prop, ']' );
1607 if( p && p[1] == 0 )
1610 if( strcmpW( szNullArg, arg ) )
1611 deformat_string( dialog->package, arg, &arg_fmt );
1612 MSI_SetPropertyW( dialog->package, prop, arg_fmt );
1613 msi_free( arg_fmt );
1616 ERR("Badly formatted property string - what happens?\n");
1618 return ERROR_SUCCESS;
1621 static UINT msi_dialog_control_event( MSIRECORD *rec, LPVOID param )
1623 msi_dialog *dialog = param;
1624 LPCWSTR condition, event, arg;
1627 condition = MSI_RecordGetString( rec, 5 );
1628 r = MSI_EvaluateConditionW( dialog->package, condition );
1631 event = MSI_RecordGetString( rec, 3 );
1632 arg = MSI_RecordGetString( rec, 4 );
1633 if( event[0] == '[' )
1634 msi_dialog_set_property( dialog, event, arg );
1636 msi_dialog_send_event( dialog, event, arg );
1639 return ERROR_SUCCESS;
1642 static UINT msi_dialog_button_handler( msi_dialog *dialog,
1643 msi_control *control, WPARAM param )
1645 static const WCHAR query[] = {
1646 'S','E','L','E','C','T',' ','*',' ',
1647 'F','R','O','M',' ','C','o','n','t','r','o','l','E','v','e','n','t',' ',
1648 'W','H','E','R','E',' ',
1649 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',' ',
1651 '`','C','o','n','t','r','o','l','_','`',' ','=',' ','\'','%','s','\'',' ',
1652 'O','R','D','E','R',' ','B','Y',' ','`','O','r','d','e','r','i','n','g','`',0
1654 MSIQUERY *view = NULL;
1657 if( HIWORD(param) != BN_CLICKED )
1658 return ERROR_SUCCESS;
1660 r = MSI_OpenQuery( dialog->package->db, &view, query,
1661 dialog->name, control->name );
1662 if( r != ERROR_SUCCESS )
1664 ERR("query failed\n");
1668 r = MSI_IterateRecords( view, 0, msi_dialog_control_event, dialog );
1669 msiobj_release( &view->hdr );
1674 static UINT msi_dialog_get_checkbox_state( msi_dialog *dialog,
1675 msi_control *control )
1677 WCHAR state[2] = { 0 };
1680 MSI_GetPropertyW( dialog->package, control->property, state, &sz );
1681 return state[0] ? 1 : 0;
1684 static void msi_dialog_set_checkbox_state( msi_dialog *dialog,
1685 msi_control *control, UINT state )
1687 static const WCHAR szState[] = { '1', 0 };
1690 /* if uncheck then the property is set to NULL */
1693 MSI_SetPropertyW( dialog->package, control->property, NULL );
1697 /* check for a custom state */
1698 if (control->value && control->value[0])
1699 val = control->value;
1703 MSI_SetPropertyW( dialog->package, control->property, val );
1706 static void msi_dialog_checkbox_sync_state( msi_dialog *dialog,
1707 msi_control *control )
1711 state = msi_dialog_get_checkbox_state( dialog, control );
1712 SendMessageW( control->hwnd, BM_SETCHECK,
1713 state ? BST_CHECKED : BST_UNCHECKED, 0 );
1716 static UINT msi_dialog_checkbox_handler( msi_dialog *dialog,
1717 msi_control *control, WPARAM param )
1721 if( HIWORD(param) != BN_CLICKED )
1722 return ERROR_SUCCESS;
1724 TRACE("clicked checkbox %s, set %s\n", debugstr_w(control->name),
1725 debugstr_w(control->property));
1727 state = msi_dialog_get_checkbox_state( dialog, control );
1728 state = state ? 0 : 1;
1729 msi_dialog_set_checkbox_state( dialog, control, state );
1730 msi_dialog_checkbox_sync_state( dialog, control );
1732 return msi_dialog_button_handler( dialog, control, param );
1735 static UINT msi_dialog_edit_handler( msi_dialog *dialog,
1736 msi_control *control, WPARAM param )
1741 if( HIWORD(param) != EN_CHANGE )
1742 return ERROR_SUCCESS;
1744 TRACE("edit %s contents changed, set %s\n", debugstr_w(control->name),
1745 debugstr_w(control->property));
1748 buf = msi_alloc( sz*sizeof(WCHAR) );
1751 r = GetWindowTextW( control->hwnd, buf, sz );
1755 buf = msi_realloc( buf, sz*sizeof(WCHAR) );
1758 MSI_SetPropertyW( dialog->package, control->property, buf );
1762 return ERROR_SUCCESS;
1765 static UINT msi_dialog_radiogroup_handler( msi_dialog *dialog,
1766 msi_control *control, WPARAM param )
1768 if( HIWORD(param) != BN_CLICKED )
1769 return ERROR_SUCCESS;
1771 TRACE("clicked radio button %s, set %s\n", debugstr_w(control->name),
1772 debugstr_w(control->property));
1774 MSI_SetPropertyW( dialog->package, control->property, control->name );
1776 return msi_dialog_button_handler( dialog, control, param );
1779 static LRESULT msi_dialog_oncommand( msi_dialog *dialog, WPARAM param, HWND hwnd )
1781 msi_control *control = NULL;
1783 TRACE("%p %p %08x\n", dialog, hwnd, param);
1788 control = msi_dialog_find_control( dialog, dialog->control_default );
1790 case 2: /* escape */
1791 control = msi_dialog_find_control( dialog, dialog->control_cancel );
1794 control = msi_dialog_find_control_by_hwnd( dialog, hwnd );
1799 if( control->handler )
1801 control->handler( dialog, control, param );
1802 msi_dialog_evaluate_control_conditions( dialog );
1806 ERR("button click from nowhere %p %d %p\n", dialog, param, hwnd);
1810 static void msi_dialog_setfocus( msi_dialog *dialog )
1812 HWND hwnd = dialog->hWndFocus;
1814 hwnd = GetNextDlgTabItem( dialog->hwnd, hwnd, TRUE);
1815 hwnd = GetNextDlgTabItem( dialog->hwnd, hwnd, FALSE);
1817 dialog->hWndFocus = hwnd;
1820 static LRESULT WINAPI MSIDialog_WndProc( HWND hwnd, UINT msg,
1821 WPARAM wParam, LPARAM lParam )
1823 msi_dialog *dialog = (LPVOID) GetWindowLongPtrW( hwnd, GWLP_USERDATA );
1825 TRACE("0x%04x\n", msg);
1830 return msi_dialog_oncreate( hwnd, (LPCREATESTRUCTW)lParam );
1833 return msi_dialog_oncommand( dialog, wParam, (HWND)lParam );
1836 if( LOWORD(wParam) == WA_INACTIVE )
1837 dialog->hWndFocus = GetFocus();
1839 msi_dialog_setfocus( dialog );
1843 msi_dialog_setfocus( dialog );
1846 /* bounce back to our subclassed static control */
1847 case WM_CTLCOLORSTATIC:
1848 return SendMessageW( (HWND) lParam, WM_CTLCOLORSTATIC, wParam, lParam );
1851 dialog->hwnd = NULL;
1854 return DefWindowProcW(hwnd, msg, wParam, lParam);
1857 static LRESULT WINAPI MSIRadioGroup_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
1859 WNDPROC oldproc = (WNDPROC) GetPropW(hWnd, szButtonData);
1861 TRACE("hWnd %p msg %04x wParam 0x%08x lParam 0x%08lx\n", hWnd, msg, wParam, lParam);
1863 if (msg == WM_COMMAND) /* Forward notifications to dialog */
1864 SendMessageW(GetParent(hWnd), msg, wParam, lParam);
1866 return CallWindowProcW(oldproc, hWnd, msg, wParam, lParam);
1869 static LRESULT WINAPI MSIHiddenWindowProc( HWND hwnd, UINT msg,
1870 WPARAM wParam, LPARAM lParam )
1872 msi_dialog *dialog = (msi_dialog*) lParam;
1874 TRACE("%d %p\n", msg, dialog);
1878 case WM_MSI_DIALOG_CREATE:
1879 return msi_dialog_run_message_loop( dialog );
1880 case WM_MSI_DIALOG_DESTROY:
1881 msi_dialog_destroy( dialog );
1884 return DefWindowProcW( hwnd, msg, wParam, lParam );
1887 /* functions that interface to other modules within MSI */
1889 msi_dialog *msi_dialog_create( MSIPACKAGE* package, LPCWSTR szDialogName,
1890 msi_dialog_event_handler event_handler )
1892 MSIRECORD *rec = NULL;
1895 TRACE("%p %s\n", package, debugstr_w(szDialogName));
1897 /* allocate the structure for the dialog to use */
1898 dialog = msi_alloc_zero( sizeof *dialog + sizeof(WCHAR)*strlenW(szDialogName) );
1901 strcpyW( dialog->name, szDialogName );
1902 msiobj_addref( &package->hdr );
1903 dialog->package = package;
1904 dialog->event_handler = event_handler;
1905 dialog->finished = 0;
1906 list_init( &dialog->controls );
1908 /* verify that the dialog exists */
1909 rec = msi_get_dialog_record( dialog );
1912 msiobj_release( &package->hdr );
1916 dialog->attributes = MSI_RecordGetInteger( rec, 6 );
1917 dialog->control_default = strdupW( MSI_RecordGetString( rec, 9 ) );
1918 dialog->control_cancel = strdupW( MSI_RecordGetString( rec, 10 ) );
1919 msiobj_release( &rec->hdr );
1924 static void msi_process_pending_messages( HWND hdlg )
1928 while( PeekMessageW( &msg, 0, 0, 0, PM_REMOVE ) )
1930 if( hdlg && IsDialogMessageW( hdlg, &msg ))
1932 TranslateMessage( &msg );
1933 DispatchMessageW( &msg );
1937 void msi_dialog_end_dialog( msi_dialog *dialog )
1939 TRACE("%p\n", dialog);
1940 dialog->finished = 1;
1941 PostMessageW(dialog->hwnd, WM_NULL, 0, 0);
1944 void msi_dialog_check_messages( HANDLE handle )
1948 /* in threads other than the UI thread, block */
1949 if( uiThreadId != GetCurrentThreadId() )
1952 WaitForSingleObject( handle, INFINITE );
1956 /* there's two choices for the UI thread */
1959 msi_process_pending_messages( NULL );
1965 * block here until somebody creates a new dialog or
1966 * the handle we're waiting on becomes ready
1968 r = MsgWaitForMultipleObjects( 1, &handle, 0, INFINITE, QS_ALLINPUT );
1969 if( r == WAIT_OBJECT_0 )
1974 UINT msi_dialog_run_message_loop( msi_dialog *dialog )
1978 if( !(dialog->attributes & msidbDialogAttributesVisible) )
1979 return ERROR_SUCCESS;
1981 if( uiThreadId != GetCurrentThreadId() )
1982 return SendMessageW( hMsiHiddenWindow, WM_MSI_DIALOG_CREATE, 0, (LPARAM) dialog );
1984 /* create the dialog window, don't show it yet */
1985 hwnd = CreateWindowW( szMsiDialogClass, dialog->name, WS_OVERLAPPEDWINDOW,
1986 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
1987 NULL, NULL, NULL, dialog );
1990 ERR("Failed to create dialog %s\n", debugstr_w( dialog->name ));
1991 return ERROR_FUNCTION_FAILED;
1994 ShowWindow( hwnd, SW_SHOW );
1995 /* UpdateWindow( hwnd ); - and causes the transparent static controls not to paint */
1997 if( dialog->attributes & msidbDialogAttributesModal )
1999 while( !dialog->finished )
2001 MsgWaitForMultipleObjects( 0, NULL, 0, INFINITE, QS_ALLEVENTS );
2002 msi_process_pending_messages( dialog->hwnd );
2006 return ERROR_IO_PENDING;
2008 return ERROR_SUCCESS;
2011 void msi_dialog_do_preview( msi_dialog *dialog )
2014 dialog->attributes |= msidbDialogAttributesVisible;
2015 dialog->attributes &= ~msidbDialogAttributesModal;
2016 msi_dialog_run_message_loop( dialog );
2019 void msi_dialog_destroy( msi_dialog *dialog )
2021 if( uiThreadId != GetCurrentThreadId() )
2023 SendMessageW( hMsiHiddenWindow, WM_MSI_DIALOG_DESTROY, 0, (LPARAM) dialog );
2028 ShowWindow( dialog->hwnd, SW_HIDE );
2031 DestroyWindow( dialog->hwnd );
2033 /* destroy the list of controls */
2034 while( !list_empty( &dialog->controls ) )
2036 msi_control *t = LIST_ENTRY( list_head( &dialog->controls ),
2037 msi_control, entry );
2038 list_remove( &t->entry );
2039 /* leave dialog->hwnd - destroying parent destroys child windows */
2040 msi_free( t->property );
2041 msi_free( t->value );
2043 DeleteObject( t->hBitmap );
2045 DestroyIcon( t->hIcon );
2046 msi_free( t->tabnext );
2049 FreeLibrary( t->hDll );
2052 /* destroy the list of fonts */
2053 while( dialog->font_list )
2055 msi_font *t = dialog->font_list;
2056 dialog->font_list = t->next;
2057 DeleteObject( t->hfont );
2060 msi_free( dialog->default_font );
2062 msi_free( dialog->control_default );
2063 msi_free( dialog->control_cancel );
2064 msiobj_release( &dialog->package->hdr );
2065 dialog->package = NULL;
2069 BOOL msi_dialog_register_class( void )
2073 ZeroMemory( &cls, sizeof cls );
2074 cls.lpfnWndProc = MSIDialog_WndProc;
2075 cls.hInstance = NULL;
2076 cls.hIcon = LoadIconW(0, (LPWSTR)IDI_APPLICATION);
2077 cls.hCursor = LoadCursorW(0, (LPWSTR)IDC_ARROW);
2078 cls.hbrBackground = (HBRUSH)(COLOR_3DFACE + 1);
2079 cls.lpszMenuName = NULL;
2080 cls.lpszClassName = szMsiDialogClass;
2082 if( !RegisterClassW( &cls ) )
2085 cls.lpfnWndProc = MSIHiddenWindowProc;
2086 cls.lpszClassName = szMsiHiddenWindow;
2088 if( !RegisterClassW( &cls ) )
2091 uiThreadId = GetCurrentThreadId();
2093 hMsiHiddenWindow = CreateWindowW( szMsiHiddenWindow, NULL, WS_OVERLAPPED,
2094 0, 0, 100, 100, NULL, NULL, NULL, NULL );
2095 if( !hMsiHiddenWindow )
2101 void msi_dialog_unregister_class( void )
2103 DestroyWindow( hMsiHiddenWindow );
2104 UnregisterClassW( szMsiDialogClass, NULL );