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
22 #define NONAMELESSUNION
23 #define NONAMELESSSTRUCT
40 #include "wine/debug.h"
41 #include "wine/unicode.h"
45 WINE_DEFAULT_DEBUG_CHANNEL(msi);
48 struct msi_control_tag;
49 typedef struct msi_control_tag msi_control;
50 typedef UINT (*msi_handler)( msi_dialog *, msi_control *, WPARAM );
52 struct msi_control_tag
66 typedef struct msi_font_tag
68 struct msi_font_tag *next;
76 msi_dialog_event_handler event_handler;
85 LPWSTR control_default;
86 LPWSTR control_cancel;
90 typedef UINT (*msi_dialog_control_func)( msi_dialog *dialog, MSIRECORD *rec );
91 struct control_handler
94 msi_dialog_control_func func;
102 } radio_button_group_descr;
104 const WCHAR szMsiDialogClass[] = {
105 'M','s','i','D','i','a','l','o','g','C','l','o','s','e','C','l','a','s','s',0
107 const WCHAR szMsiHiddenWindow[] = {
108 'M','s','i','H','i','d','d','e','n','W','i','n','d','o','w',0 };
109 static const WCHAR szStatic[] = { 'S','t','a','t','i','c',0 };
110 static const WCHAR szButton[] = { 'B','U','T','T','O','N', 0 };
111 static const WCHAR szButtonData[] = { 'M','S','I','D','A','T','A',0 };
112 static const WCHAR szText[] = { 'T','e','x','t',0 };
113 static const WCHAR szPushButton[] = { 'P','u','s','h','B','u','t','t','o','n',0 };
114 static const WCHAR szLine[] = { 'L','i','n','e',0 };
115 static const WCHAR szBitmap[] = { 'B','i','t','m','a','p',0 };
116 static const WCHAR szCheckBox[] = { 'C','h','e','c','k','B','o','x',0 };
117 static const WCHAR szScrollableText[] = {
118 'S','c','r','o','l','l','a','b','l','e','T','e','x','t',0 };
119 static const WCHAR szComboBox[] = { 'C','o','m','b','o','B','o','x',0 };
120 static const WCHAR szEdit[] = { 'E','d','i','t',0 };
121 static const WCHAR szMaskedEdit[] = { 'M','a','s','k','e','d','E','d','i','t',0 };
122 static const WCHAR szPathEdit[] = { 'P','a','t','h','E','d','i','t',0 };
123 static const WCHAR szProgressBar[] = {
124 'P','r','o','g','r','e','s','s','B','a','r',0 };
125 static const WCHAR szRadioButtonGroup[] = {
126 'R','a','d','i','o','B','u','t','t','o','n','G','r','o','u','p',0 };
127 static const WCHAR szIcon[] = { 'I','c','o','n',0 };
128 static const WCHAR szSelectionTree[] = {
129 'S','e','l','e','c','t','i','o','n','T','r','e','e',0 };
131 static UINT msi_dialog_checkbox_handler( msi_dialog *, msi_control *, WPARAM );
132 static void msi_dialog_checkbox_sync_state( msi_dialog *, msi_control * );
133 static UINT msi_dialog_button_handler( msi_dialog *, msi_control *, WPARAM );
134 static UINT msi_dialog_edit_handler( msi_dialog *, msi_control *, WPARAM );
135 static UINT msi_dialog_radiogroup_handler( msi_dialog *, msi_control *, WPARAM param );
136 static UINT msi_dialog_evaluate_control_conditions( msi_dialog *dialog );
137 static LRESULT WINAPI MSIRadioGroup_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
140 /* dialog sequencing */
142 #define WM_MSI_DIALOG_CREATE (WM_USER+0x100)
143 #define WM_MSI_DIALOG_DESTROY (WM_USER+0x101)
145 static DWORD uiThreadId;
146 static HWND hMsiHiddenWindow;
148 static INT msi_dialog_scale_unit( msi_dialog *dialog, INT val )
150 return (dialog->scale * val + 5) / 10;
153 static msi_control *msi_dialog_find_control( msi_dialog *dialog, LPCWSTR name )
155 msi_control *control;
159 LIST_FOR_EACH_ENTRY( control, &dialog->controls, msi_control, entry )
160 if( !strcmpW( control->name, name ) ) /* FIXME: case sensitive? */
165 static msi_control *msi_dialog_find_control_by_hwnd( msi_dialog *dialog, HWND hwnd )
167 msi_control *control;
169 LIST_FOR_EACH_ENTRY( control, &dialog->controls, msi_control, entry )
170 if( hwnd == control->hwnd )
175 static LPWSTR msi_get_deformatted_field( MSIPACKAGE *package, MSIRECORD *rec, int field )
177 LPCWSTR str = MSI_RecordGetString( rec, field );
181 deformat_string( package, str, &ret );
186 * msi_dialog_get_style
188 * Extract the {\style} string from the front of the text to display and
189 * update the pointer.
191 static LPWSTR msi_dialog_get_style( LPCWSTR p, LPCWSTR *rest )
202 q = strchrW( p, '}' );
205 if( *p == '\\' || *p == '&' )
208 /* little bit of sanity checking to stop us getting confused with RTF */
210 if( *i == '}' || *i == '\\' )
216 ret = msi_alloc( len*sizeof(WCHAR) );
219 memcpy( ret, p, len*sizeof(WCHAR) );
224 static UINT msi_dialog_add_font( MSIRECORD *rec, LPVOID param )
226 msi_dialog *dialog = param;
233 /* create a font and add it to the list */
234 name = MSI_RecordGetString( rec, 1 );
235 font = msi_alloc( sizeof *font + strlenW( name )*sizeof (WCHAR) );
236 strcpyW( font->name, name );
237 font->next = dialog->font_list;
238 dialog->font_list = font;
240 memset( &lf, 0, sizeof lf );
241 face = MSI_RecordGetString( rec, 2 );
242 lf.lfHeight = MSI_RecordGetInteger( rec, 3 );
243 style = MSI_RecordGetInteger( rec, 5 );
244 if( style & msidbTextStyleStyleBitsBold )
245 lf.lfWeight = FW_BOLD;
246 if( style & msidbTextStyleStyleBitsItalic )
248 if( style & msidbTextStyleStyleBitsUnderline )
249 lf.lfUnderline = TRUE;
250 if( style & msidbTextStyleStyleBitsStrike )
251 lf.lfStrikeOut = TRUE;
252 lstrcpynW( lf.lfFaceName, face, LF_FACESIZE );
254 /* adjust the height */
255 hdc = GetDC( dialog->hwnd );
258 lf.lfHeight = -MulDiv(lf.lfHeight, GetDeviceCaps(hdc, LOGPIXELSY), 72);
259 ReleaseDC( dialog->hwnd, hdc );
262 font->hfont = CreateFontIndirectW( &lf );
264 TRACE("Adding font style %s\n", debugstr_w(font->name) );
266 return ERROR_SUCCESS;
269 static msi_font *msi_dialog_find_font( msi_dialog *dialog, LPCWSTR name )
273 for( font = dialog->font_list; font; font = font->next )
274 if( !strcmpW( font->name, name ) ) /* FIXME: case sensitive? */
280 static UINT msi_dialog_set_font( msi_dialog *dialog, HWND hwnd, LPCWSTR name )
284 font = msi_dialog_find_font( dialog, name );
286 SendMessageW( hwnd, WM_SETFONT, (WPARAM) font->hfont, TRUE );
288 ERR("No font entry for %s\n", debugstr_w(name));
289 return ERROR_SUCCESS;
292 static UINT msi_dialog_build_font_list( msi_dialog *dialog )
294 static const WCHAR query[] = {
295 'S','E','L','E','C','T',' ','*',' ',
296 'F','R','O','M',' ','`','T','e','x','t','S','t','y','l','e','`',' ',0
299 MSIQUERY *view = NULL;
301 TRACE("dialog %p\n", dialog );
303 r = MSI_OpenQuery( dialog->package->db, &view, query );
304 if( r != ERROR_SUCCESS )
307 r = MSI_IterateRecords( view, NULL, msi_dialog_add_font, dialog );
308 msiobj_release( &view->hdr );
313 static msi_control *msi_dialog_create_window( msi_dialog *dialog,
314 MSIRECORD *rec, LPCWSTR szCls, LPCWSTR name, LPCWSTR text,
315 DWORD style, HWND parent )
317 DWORD x, y, width, height;
318 LPWSTR font = NULL, title_font = NULL;
319 LPCWSTR title = NULL;
320 msi_control *control;
324 control = msi_alloc( sizeof *control + strlenW(name)*sizeof(WCHAR) );
325 strcpyW( control->name, name );
326 list_add_head( &dialog->controls, &control->entry );
327 control->handler = NULL;
328 control->property = NULL;
329 control->value = NULL;
330 control->hBitmap = NULL;
331 control->hIcon = NULL;
332 control->hDll = NULL;
333 control->tabnext = strdupW( MSI_RecordGetString( rec, 11) );
335 x = MSI_RecordGetInteger( rec, 4 );
336 y = MSI_RecordGetInteger( rec, 5 );
337 width = MSI_RecordGetInteger( rec, 6 );
338 height = MSI_RecordGetInteger( rec, 7 );
340 x = msi_dialog_scale_unit( dialog, x );
341 y = msi_dialog_scale_unit( dialog, y );
342 width = msi_dialog_scale_unit( dialog, width );
343 height = msi_dialog_scale_unit( dialog, height );
347 deformat_string( dialog->package, text, &title_font );
348 font = msi_dialog_get_style( title_font, &title );
351 control->hwnd = CreateWindowW( szCls, title, style,
352 x, y, width, height, parent, NULL, NULL, NULL );
354 TRACE("Dialog %s control %s hwnd %p\n",
355 debugstr_w(dialog->name), debugstr_w(text), control->hwnd );
357 msi_dialog_set_font( dialog, control->hwnd,
358 font ? font : dialog->default_font );
360 msi_free( title_font );
366 static MSIRECORD *msi_get_binary_record( MSIDATABASE *db, LPCWSTR name )
368 static const WCHAR query[] = {
369 's','e','l','e','c','t',' ','*',' ',
370 'f','r','o','m',' ','B','i','n','a','r','y',' ',
371 'w','h','e','r','e',' ',
372 '`','N','a','m','e','`',' ','=',' ','\'','%','s','\'',0
375 return MSI_QueryGetRecord( db, query, name );
378 static LPWSTR msi_create_tmp_path(void)
382 static const WCHAR prefix[] = { 'm','s','i',0 };
385 r = GetTempPathW( MAX_PATH, tmp );
388 len = lstrlenW( tmp ) + 20;
389 path = msi_alloc( len * sizeof (WCHAR) );
392 r = GetTempFileNameW( tmp, prefix, 0, path );
403 static HANDLE msi_load_image( MSIDATABASE *db, LPCWSTR name, UINT type,
404 UINT cx, UINT cy, UINT flags )
406 MSIRECORD *rec = NULL;
407 HANDLE himage = NULL;
411 TRACE("%p %s %u %u %08x\n", db, debugstr_w(name), cx, cy, flags);
413 tmp = msi_create_tmp_path();
417 rec = msi_get_binary_record( db, name );
420 r = MSI_RecordStreamToFile( rec, 2, tmp );
421 if( r == ERROR_SUCCESS )
423 himage = LoadImageW( 0, tmp, type, cx, cy, flags );
426 msiobj_release( &rec->hdr );
433 static HICON msi_load_icon( MSIDATABASE *db, LPCWSTR text, UINT attributes )
435 DWORD cx = 0, cy = 0, flags;
437 flags = LR_LOADFROMFILE | LR_DEFAULTSIZE;
438 if( attributes & msidbControlAttributesFixedSize )
440 flags &= ~LR_DEFAULTSIZE;
441 if( attributes & msidbControlAttributesIconSize16 )
446 if( attributes & msidbControlAttributesIconSize32 )
451 /* msidbControlAttributesIconSize48 handled by above logic */
453 return msi_load_image( db, text, IMAGE_ICON, cx, cy, flags );
457 /* called from the Control Event subscription code */
458 void msi_dialog_handle_event( msi_dialog* dialog, LPCWSTR control,
459 LPCWSTR attribute, MSIRECORD *rec )
462 LPCWSTR font_text, text = NULL;
465 ctrl = msi_dialog_find_control( dialog, control );
468 if( lstrcmpW(attribute, szText) )
470 ERR("Attribute %s\n", debugstr_w(attribute));
473 font_text = MSI_RecordGetString( rec , 1 );
474 font = msi_dialog_get_style( font_text, &text );
475 SetWindowTextW( ctrl->hwnd, text );
477 msi_dialog_check_messages( NULL );
480 static void msi_dialog_map_events(msi_dialog* dialog, LPCWSTR control)
482 static WCHAR Query[] = {
483 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
484 '`','E','v','e','n','t','M','a','p','p','i','n','g','`',' ',
485 'W','H','E','R','E',' ',
486 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',' ',
488 '`','C','o','n','t','r','o','l','_','`',' ','=',' ','\'','%','s','\'',0
491 LPCWSTR event, attribute;
493 row = MSI_QueryGetRecord( dialog->package->db, Query, dialog->name, control );
497 event = MSI_RecordGetString( row, 3 );
498 attribute = MSI_RecordGetString( row, 4 );
499 ControlEvent_SubscribeToEvent( dialog->package, event, control, attribute );
500 msiobj_release( &row->hdr );
503 /* everything except radio buttons */
504 static msi_control *msi_dialog_add_control( msi_dialog *dialog,
505 MSIRECORD *rec, LPCWSTR szCls, DWORD style )
510 name = MSI_RecordGetString( rec, 2 );
511 attributes = MSI_RecordGetInteger( rec, 8 );
512 text = MSI_RecordGetString( rec, 10 );
513 if( attributes & msidbControlAttributesVisible )
515 if( ~attributes & msidbControlAttributesEnabled )
516 style |= WS_DISABLED;
518 msi_dialog_map_events(dialog, name);
520 return msi_dialog_create_window( dialog, rec, szCls, name, text,
521 style, dialog->hwnd );
531 * we don't erase our own background,
532 * so we have to make sure that the parent window redraws first
534 static void msi_text_on_settext( HWND hWnd )
539 hParent = GetParent( hWnd );
540 GetWindowRect( hWnd, &rc );
541 MapWindowPoints( NULL, hParent, (LPPOINT) &rc, 2 );
542 InvalidateRect( hParent, &rc, TRUE );
545 static LRESULT WINAPI
546 MSIText_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
548 struct msi_text_info *info;
551 TRACE("%p %04x %08x %08lx\n", hWnd, msg, wParam, lParam);
553 info = GetPropW(hWnd, szButtonData);
555 if( msg == WM_CTLCOLORSTATIC &&
556 ( info->attributes & msidbControlAttributesTransparent ) )
558 SetBkMode( (HDC)wParam, TRANSPARENT );
559 return (LRESULT) GetStockObject(NULL_BRUSH);
562 r = CallWindowProcW(info->oldproc, hWnd, msg, wParam, lParam);
567 msi_text_on_settext( hWnd );
571 RemovePropW( hWnd, szButtonData );
578 static UINT msi_dialog_text_control( msi_dialog *dialog, MSIRECORD *rec )
580 msi_control *control;
581 struct msi_text_info *info;
583 TRACE("%p %p\n", dialog, rec);
585 control = msi_dialog_add_control( dialog, rec, szStatic, SS_LEFT | WS_GROUP );
587 return ERROR_FUNCTION_FAILED;
589 info = msi_alloc( sizeof *info );
591 return ERROR_SUCCESS;
593 info->attributes = MSI_RecordGetInteger( rec, 8 );
594 if( info->attributes & msidbControlAttributesTransparent )
595 SetWindowLongPtrW( control->hwnd, GWL_EXSTYLE, WS_EX_TRANSPARENT );
597 info->oldproc = (WNDPROC) SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
598 (LONG_PTR)MSIText_WndProc );
599 SetPropW( control->hwnd, szButtonData, info );
601 return ERROR_SUCCESS;
604 static UINT msi_dialog_button_control( msi_dialog *dialog, MSIRECORD *rec )
606 msi_control *control;
607 UINT attributes, style;
610 TRACE("%p %p\n", dialog, rec);
613 attributes = MSI_RecordGetInteger( rec, 8 );
614 if( attributes & msidbControlAttributesIcon )
617 control = msi_dialog_add_control( dialog, rec, szButton, style );
619 return ERROR_FUNCTION_FAILED;
621 control->handler = msi_dialog_button_handler;
624 text = msi_get_deformatted_field( dialog->package, rec, 10 );
625 control->hIcon = msi_load_icon( dialog->package->db, text, attributes );
626 if( attributes & msidbControlAttributesIcon )
627 SendMessageW( control->hwnd, BM_SETIMAGE, IMAGE_ICON, (LPARAM) control->hIcon );
630 return ERROR_SUCCESS;
633 static LPWSTR msi_get_checkbox_value( msi_dialog *dialog, LPCWSTR prop )
635 static const WCHAR query[] = {
636 'S','E','L','E','C','T',' ','*',' ',
637 'F','R','O','M',' ','`','C','h','e','c','k','B','o','x',' ','`',
638 'W','H','E','R','E',' ',
639 '`','P','r','o','p','e','r','t','y','`',' ','=',' ',
642 MSIRECORD *rec = NULL;
645 /* find if there is a value associated with the checkbox */
646 rec = MSI_QueryGetRecord( dialog->package->db, query, prop );
650 ret = msi_get_deformatted_field( dialog->package, rec, 2 );
656 msiobj_release( &rec->hdr );
660 ret = msi_dup_property( dialog->package, prop );
670 static UINT msi_dialog_checkbox_control( msi_dialog *dialog, MSIRECORD *rec )
672 msi_control *control;
675 TRACE("%p %p\n", dialog, rec);
677 control = msi_dialog_add_control( dialog, rec, szButton,
678 BS_CHECKBOX | BS_MULTILINE | WS_TABSTOP );
679 control->handler = msi_dialog_checkbox_handler;
680 prop = MSI_RecordGetString( rec, 9 );
683 control->property = strdupW( prop );
684 control->value = msi_get_checkbox_value( dialog, prop );
685 TRACE("control %s value %s\n", debugstr_w(control->property),
686 debugstr_w(control->value));
688 msi_dialog_checkbox_sync_state( dialog, control );
690 return ERROR_SUCCESS;
693 static UINT msi_dialog_line_control( msi_dialog *dialog, MSIRECORD *rec )
695 TRACE("%p %p\n", dialog, rec);
697 msi_dialog_add_control( dialog, rec, szStatic, SS_ETCHEDHORZ | SS_SUNKEN );
698 return ERROR_SUCCESS;
701 /******************** Scroll Text ********************************************/
703 struct msi_scrolltext_info
706 msi_control *control;
710 static LRESULT WINAPI
711 MSIScrollText_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
713 struct msi_scrolltext_info *info;
716 TRACE("%p %04x %08x %08lx\n", hWnd, msg, wParam, lParam);
718 info = GetPropW( hWnd, szButtonData );
720 r = CallWindowProcW( info->oldproc, hWnd, msg, wParam, lParam );
726 RemovePropW( hWnd, szButtonData );
729 /* native MSI sets a wait cursor here */
730 msi_dialog_button_handler( info->dialog, info->control, BN_CLICKED );
736 struct msi_streamin_info
743 static DWORD CALLBACK
744 msi_richedit_stream_in( DWORD_PTR arg, LPBYTE buffer, LONG count, LONG *pcb )
746 struct msi_streamin_info *info = (struct msi_streamin_info*) arg;
748 if( (count + info->offset) > info->length )
749 count = info->length - info->offset;
750 memcpy( buffer, &info->string[ info->offset ], count );
752 info->offset += count;
754 TRACE("%ld/%ld\n", info->offset, info->length);
759 static void msi_scrolltext_add_text( msi_control *control, LPCWSTR text )
761 struct msi_streamin_info info;
764 info.string = strdupWtoA( text );
766 info.length = lstrlenA( info.string ) + 1;
768 es.dwCookie = (DWORD_PTR) &info;
770 es.pfnCallback = msi_richedit_stream_in;
772 SendMessageW( control->hwnd, EM_STREAMIN, SF_RTF, (LPARAM) &es );
774 msi_free( info.string );
777 static UINT msi_dialog_scrolltext_control( msi_dialog *dialog, MSIRECORD *rec )
779 static const WCHAR szRichEdit20W[] = {
780 'R','i','c','h','E','d','i','t','2','0','W',0
782 struct msi_scrolltext_info *info;
783 msi_control *control;
787 info = msi_alloc( sizeof *info );
789 return ERROR_FUNCTION_FAILED;
791 hRichedit = LoadLibraryA("riched20");
793 style = WS_BORDER | ES_MULTILINE | WS_VSCROLL |
794 ES_READONLY | ES_AUTOVSCROLL | WS_TABSTOP;
795 control = msi_dialog_add_control( dialog, rec, szRichEdit20W, style );
798 FreeLibrary( hRichedit );
800 return ERROR_FUNCTION_FAILED;
803 control->hDll = hRichedit;
805 info->dialog = dialog;
806 info->control = control;
808 /* subclass the static control */
809 info->oldproc = (WNDPROC) SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
810 (LONG_PTR)MSIScrollText_WndProc );
811 SetPropW( control->hwnd, szButtonData, info );
813 /* add the text into the richedit */
814 msi_scrolltext_add_text( control, MSI_RecordGetString( rec, 10 ) );
816 return ERROR_SUCCESS;
819 static HBITMAP msi_load_picture( MSIDATABASE *db, LPCWSTR name,
820 INT cx, INT cy, DWORD flags )
822 HBITMAP hOleBitmap = 0, hBitmap = 0, hOldSrcBitmap, hOldDestBitmap;
823 MSIRECORD *rec = NULL;
825 IPicture *pic = NULL;
830 rec = msi_get_binary_record( db, name );
834 r = MSI_RecordGetIStream( rec, 2, &stm );
835 msiobj_release( &rec->hdr );
836 if( r != ERROR_SUCCESS )
839 r = OleLoadPicture( stm, 0, TRUE, &IID_IPicture, (LPVOID*) &pic );
840 IStream_Release( stm );
843 ERR("failed to load picture\n");
847 r = IPicture_get_Handle( pic, (OLE_HANDLE*) &hOleBitmap );
850 ERR("failed to get bitmap handle\n");
854 /* make the bitmap the desired size */
855 r = GetObjectW( hOleBitmap, sizeof bm, &bm );
858 ERR("failed to get bitmap size\n");
862 if (flags & LR_DEFAULTSIZE)
868 srcdc = CreateCompatibleDC( NULL );
869 hOldSrcBitmap = SelectObject( srcdc, hOleBitmap );
870 destdc = CreateCompatibleDC( NULL );
871 hBitmap = CreateCompatibleBitmap( srcdc, cx, cy );
872 hOldDestBitmap = SelectObject( destdc, hBitmap );
873 StretchBlt( destdc, 0, 0, cx, cy,
874 srcdc, 0, 0, bm.bmWidth, bm.bmHeight, SRCCOPY);
875 SelectObject( srcdc, hOldSrcBitmap );
876 SelectObject( destdc, hOldDestBitmap );
882 IPicture_Release( pic );
886 static UINT msi_dialog_bitmap_control( msi_dialog *dialog, MSIRECORD *rec )
888 UINT cx, cy, flags, style, attributes;
889 msi_control *control;
892 flags = LR_LOADFROMFILE;
893 style = SS_BITMAP | SS_LEFT | WS_GROUP;
895 attributes = MSI_RecordGetInteger( rec, 8 );
896 if( attributes & msidbControlAttributesFixedSize )
898 flags |= LR_DEFAULTSIZE;
899 style |= SS_CENTERIMAGE;
902 control = msi_dialog_add_control( dialog, rec, szStatic, style );
903 cx = MSI_RecordGetInteger( rec, 6 );
904 cy = MSI_RecordGetInteger( rec, 7 );
905 cx = msi_dialog_scale_unit( dialog, cx );
906 cy = msi_dialog_scale_unit( dialog, cy );
908 text = msi_get_deformatted_field( dialog->package, rec, 10 );
909 control->hBitmap = msi_load_picture( dialog->package->db, text, cx, cy, flags );
910 if( control->hBitmap )
911 SendMessageW( control->hwnd, STM_SETIMAGE,
912 IMAGE_BITMAP, (LPARAM) control->hBitmap );
914 ERR("Failed to load bitmap %s\n", debugstr_w(text));
918 return ERROR_SUCCESS;
921 static UINT msi_dialog_icon_control( msi_dialog *dialog, MSIRECORD *rec )
923 msi_control *control;
929 control = msi_dialog_add_control( dialog, rec, szStatic,
930 SS_ICON | SS_CENTERIMAGE | WS_GROUP );
932 attributes = MSI_RecordGetInteger( rec, 8 );
933 text = msi_get_deformatted_field( dialog->package, rec, 10 );
934 control->hIcon = msi_load_icon( dialog->package->db, text, attributes );
936 SendMessageW( control->hwnd, STM_SETICON, (WPARAM) control->hIcon, 0 );
938 ERR("Failed to load bitmap %s\n", debugstr_w(text));
940 return ERROR_SUCCESS;
943 static UINT msi_dialog_combo_control( msi_dialog *dialog, MSIRECORD *rec )
945 static const WCHAR szCombo[] = { 'C','O','M','B','O','B','O','X',0 };
947 msi_dialog_add_control( dialog, rec, szCombo,
948 SS_BITMAP | SS_LEFT | SS_CENTERIMAGE );
949 return ERROR_SUCCESS;
952 static UINT msi_dialog_edit_control( msi_dialog *dialog, MSIRECORD *rec )
954 msi_control *control;
958 control = msi_dialog_add_control( dialog, rec, szEdit,
959 WS_BORDER | WS_TABSTOP );
960 control->handler = msi_dialog_edit_handler;
961 prop = MSI_RecordGetString( rec, 9 );
963 control->property = strdupW( prop );
964 val = msi_dup_property( dialog->package, control->property );
965 SetWindowTextW( control->hwnd, val );
967 return ERROR_SUCCESS;
970 /******************** Masked Edit ********************************************/
972 #define MASK_MAX_GROUPS 10
974 struct msi_mask_group
982 struct msi_maskedit_info
990 struct msi_mask_group group[MASK_MAX_GROUPS];
993 static BOOL msi_mask_editable( WCHAR type )
1008 static void msi_mask_control_change( struct msi_maskedit_info *info )
1013 val = msi_alloc( (info->num_chars+1)*sizeof(WCHAR) );
1014 for( i=0, n=0; i<info->num_groups; i++ )
1016 if( (info->group[i].len + n) > info->num_chars )
1018 ERR("can't fit control %d text into template\n",i);
1021 if (!msi_mask_editable(info->group[i].type))
1023 for(r=0; r<info->group[i].len; r++)
1024 val[n+r] = info->group[i].type;
1029 r = GetWindowTextW( info->group[i].hwnd, &val[n], info->group[i].len+1 );
1030 if( r != info->group[i].len )
1036 TRACE("%d/%d controls were good\n", i, info->num_groups);
1038 if( i == info->num_groups )
1040 TRACE("Set property %s to %s\n",
1041 debugstr_w(info->prop), debugstr_w(val) );
1042 CharUpperBuffW( val, info->num_chars );
1043 MSI_SetPropertyW( info->dialog->package, info->prop, val );
1044 msi_dialog_evaluate_control_conditions( info->dialog );
1049 /* now move to the next control if necessary */
1050 static VOID msi_mask_next_control( struct msi_maskedit_info *info, HWND hWnd )
1055 for( i=0; i<info->num_groups; i++ )
1056 if( info->group[i].hwnd == hWnd )
1059 /* don't move from the last control */
1060 if( i >= (info->num_groups-1) )
1063 len = SendMessageW( hWnd, WM_GETTEXTLENGTH, 0, 0 );
1064 if( len < info->group[i].len )
1067 hWndNext = GetNextDlgTabItem( GetParent( hWnd ), hWnd, FALSE );
1068 SetFocus( hWndNext );
1071 static LRESULT WINAPI
1072 MSIMaskedEdit_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
1074 struct msi_maskedit_info *info;
1077 TRACE("%p %04x %08x %08lx\n", hWnd, msg, wParam, lParam);
1079 info = GetPropW(hWnd, szButtonData);
1081 r = CallWindowProcW(info->oldproc, hWnd, msg, wParam, lParam);
1086 if (HIWORD(wParam) == EN_CHANGE)
1088 msi_mask_control_change( info );
1089 msi_mask_next_control( info, (HWND) lParam );
1093 msi_free( info->prop );
1095 RemovePropW( hWnd, szButtonData );
1102 /* fish the various bits of the property out and put them in the control */
1104 msi_maskedit_set_text( struct msi_maskedit_info *info, LPCWSTR text )
1110 for( i = 0; i < info->num_groups; i++ )
1112 if( info->group[i].len < lstrlenW( p ) )
1114 LPWSTR chunk = strdupW( p );
1115 chunk[ info->group[i].len ] = 0;
1116 SetWindowTextW( info->group[i].hwnd, chunk );
1121 SetWindowTextW( info->group[i].hwnd, p );
1124 p += info->group[i].len;
1128 static struct msi_maskedit_info * msi_dialog_parse_groups( LPCWSTR mask )
1130 struct msi_maskedit_info * info = NULL;
1131 int i = 0, n = 0, total = 0;
1134 TRACE("masked control, template %s\n", debugstr_w(mask));
1139 info = msi_alloc_zero( sizeof *info );
1143 p = strchrW(mask, '<');
1149 for( i=0; i<MASK_MAX_GROUPS; i++ )
1151 /* stop at the end of the string */
1152 if( p[0] == 0 || p[0] == '>' )
1155 /* count the number of the same identifier */
1156 for( n=0; p[n] == p[0]; n++ )
1158 info->group[i].ofs = total;
1159 info->group[i].type = p[0];
1163 total++; /* an extra not part of the group */
1165 info->group[i].len = n;
1170 TRACE("%d characters in %d groups\n", total, i );
1171 if( i == MASK_MAX_GROUPS )
1172 ERR("too many groups in PIDTemplate %s\n", debugstr_w(mask));
1174 info->num_chars = total;
1175 info->num_groups = i;
1181 msi_maskedit_create_children( struct msi_maskedit_info *info, LPCWSTR font )
1183 DWORD width, height, style, wx, ww;
1188 style = WS_CHILD | WS_BORDER | WS_VISIBLE | WS_TABSTOP | ES_AUTOHSCROLL;
1190 GetClientRect( info->hwnd, &rect );
1192 width = rect.right - rect.left;
1193 height = rect.bottom - rect.top;
1195 for( i = 0; i < info->num_groups; i++ )
1197 if (!msi_mask_editable( info->group[i].type ))
1199 wx = (info->group[i].ofs * width) / info->num_chars;
1200 ww = (info->group[i].len * width) / info->num_chars;
1202 hwnd = CreateWindowW( szEdit, NULL, style, wx, 0, ww, height,
1203 info->hwnd, NULL, NULL, NULL );
1206 ERR("failed to create mask edit sub window\n");
1210 SendMessageW( hwnd, EM_LIMITTEXT, info->group[i].len, 0 );
1212 msi_dialog_set_font( info->dialog, hwnd,
1213 font?font:info->dialog->default_font );
1214 info->group[i].hwnd = hwnd;
1219 * office 2003 uses "73931<````=````=````=````=`````>@@@@@"
1220 * delphi 7 uses "<????-??????-??????-????>" and "<???-???>"
1221 * filemaker pro 7 uses "<^^^^=^^^^=^^^^=^^^^=^^^^=^^^^=^^^^^>"
1223 static UINT msi_dialog_maskedit_control( msi_dialog *dialog, MSIRECORD *rec )
1225 LPWSTR font_mask, val = NULL, font;
1226 struct msi_maskedit_info *info = NULL;
1227 UINT ret = ERROR_SUCCESS;
1228 msi_control *control;
1233 font_mask = msi_get_deformatted_field( dialog->package, rec, 10 );
1234 font = msi_dialog_get_style( font_mask, &mask );
1237 ERR("mask template is empty\n");
1241 info = msi_dialog_parse_groups( mask );
1244 ERR("template %s is invalid\n", debugstr_w(mask));
1248 info->dialog = dialog;
1250 control = msi_dialog_add_control( dialog, rec, szStatic,
1251 SS_OWNERDRAW | WS_GROUP | WS_VISIBLE );
1254 ERR("Failed to create maskedit container\n");
1255 ret = ERROR_FUNCTION_FAILED;
1258 SetWindowLongPtrW( control->hwnd, GWL_EXSTYLE, WS_EX_CONTROLPARENT );
1260 info->hwnd = control->hwnd;
1262 /* subclass the static control */
1263 info->oldproc = (WNDPROC) SetWindowLongPtrW( info->hwnd, GWLP_WNDPROC,
1264 (LONG_PTR)MSIMaskedEdit_WndProc );
1265 SetPropW( control->hwnd, szButtonData, info );
1267 prop = MSI_RecordGetString( rec, 9 );
1269 info->prop = strdupW( prop );
1271 msi_maskedit_create_children( info, font );
1275 val = msi_dup_property( dialog->package, prop );
1278 msi_maskedit_set_text( info, val );
1284 if( ret != ERROR_SUCCESS )
1286 msi_free( font_mask );
1291 /******************** Progress Bar *****************************************/
1293 static UINT msi_dialog_progress_bar( msi_dialog *dialog, MSIRECORD *rec )
1295 msi_dialog_add_control( dialog, rec, PROGRESS_CLASSW, WS_VISIBLE );
1296 return ERROR_SUCCESS;
1299 /******************** Path Edit ********************************************/
1301 static UINT msi_dialog_pathedit_control( msi_dialog *dialog, MSIRECORD *rec )
1303 FIXME("not implemented properly\n");
1304 return msi_dialog_edit_control( dialog, rec );
1307 /* radio buttons are a bit different from normal controls */
1308 static UINT msi_dialog_create_radiobutton( MSIRECORD *rec, LPVOID param )
1310 radio_button_group_descr *group = (radio_button_group_descr *)param;
1311 msi_dialog *dialog = group->dialog;
1312 msi_control *control;
1313 LPCWSTR prop, text, name;
1314 DWORD style, attributes = group->attributes;
1316 style = WS_CHILD | BS_AUTORADIOBUTTON | BS_MULTILINE | WS_TABSTOP;
1317 name = MSI_RecordGetString( rec, 3 );
1318 text = MSI_RecordGetString( rec, 8 );
1319 if( attributes & 1 )
1320 style |= WS_VISIBLE;
1321 if( ~attributes & 2 )
1322 style |= WS_DISABLED;
1324 control = msi_dialog_create_window( dialog, rec, szButton, name, text,
1325 style, group->parent->hwnd );
1327 return ERROR_FUNCTION_FAILED;
1328 control->handler = msi_dialog_radiogroup_handler;
1330 prop = MSI_RecordGetString( rec, 1 );
1332 control->property = strdupW( prop );
1334 return ERROR_SUCCESS;
1337 static UINT msi_dialog_radiogroup_control( msi_dialog *dialog, MSIRECORD *rec )
1339 static const WCHAR query[] = {
1340 'S','E','L','E','C','T',' ','*',' ',
1341 'F','R','O','M',' ','R','a','d','i','o','B','u','t','t','o','n',' ',
1342 'W','H','E','R','E',' ',
1343 '`','P','r','o','p','e','r','t','y','`',' ','=',' ','\'','%','s','\'',0};
1346 msi_control *control;
1347 MSIQUERY *view = NULL;
1348 radio_button_group_descr group;
1349 MSIPACKAGE *package = dialog->package;
1352 prop = MSI_RecordGetString( rec, 9 );
1354 TRACE("%p %p %s\n", dialog, rec, debugstr_w( prop ));
1356 /* Create parent group box to hold radio buttons */
1357 control = msi_dialog_add_control( dialog, rec, szButton, BS_OWNERDRAW|WS_GROUP );
1359 return ERROR_FUNCTION_FAILED;
1361 oldproc = (WNDPROC) SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
1362 (LONG_PTR)MSIRadioGroup_WndProc );
1363 SetPropW(control->hwnd, szButtonData, oldproc);
1364 SetWindowLongPtrW( control->hwnd, GWL_EXSTYLE, WS_EX_CONTROLPARENT );
1367 control->property = strdupW( prop );
1369 /* query the Radio Button table for all control in this group */
1370 r = MSI_OpenQuery( package->db, &view, query, prop );
1371 if( r != ERROR_SUCCESS )
1373 ERR("query failed for dialog %s radio group %s\n",
1374 debugstr_w(dialog->name), debugstr_w(prop));
1375 return ERROR_INVALID_PARAMETER;
1378 group.dialog = dialog;
1379 group.parent = control;
1380 group.attributes = MSI_RecordGetInteger( rec, 8 );
1382 r = MSI_IterateRecords( view, 0, msi_dialog_create_radiobutton, &group );
1383 msiobj_release( &view->hdr );
1388 /******************** Selection Tree ***************************************/
1391 msi_dialog_tv_add_child_features( MSIPACKAGE *package, HWND hwnd,
1392 LPCWSTR parent, HTREEITEM hParent )
1394 MSIFEATURE *feature;
1395 TVINSERTSTRUCTW tvis;
1398 LIST_FOR_EACH_ENTRY( feature, &package->features, MSIFEATURE, entry )
1400 if ( lstrcmpW( parent, feature->Feature_Parent ) )
1403 if ( !feature->Title )
1406 memset( &tvis, 0, sizeof tvis );
1407 tvis.hParent = hParent;
1408 tvis.hInsertAfter = TVI_SORT;
1411 tvis.u.item.mask = TVIF_TEXT;
1412 tvis.u.item.pszText = feature->Title;
1414 tvis.u.item.lParam = (LPARAM) feature;
1415 hitem = (HTREEITEM) SendMessageW( hwnd, TVM_INSERTITEMW, 0, (LPARAM) &tvis );
1419 msi_dialog_tv_add_child_features( package, hwnd,
1420 feature->Feature, hitem );
1424 static UINT msi_dialog_selection_tree( msi_dialog *dialog, MSIRECORD *rec )
1426 msi_control *control;
1429 MSIPACKAGE *package = dialog->package;
1431 prop = MSI_RecordGetString( rec, 9 );
1432 val = msi_dup_property( package, prop );
1433 control = msi_dialog_add_control( dialog, rec, WC_TREEVIEWW,
1434 TVS_HASBUTTONS | WS_GROUP | WS_VSCROLL );
1436 return ERROR_FUNCTION_FAILED;
1438 msi_dialog_tv_add_child_features( package, control->hwnd, NULL, NULL );
1442 return ERROR_SUCCESS;
1445 struct control_handler msi_dialog_handler[] =
1447 { szText, msi_dialog_text_control },
1448 { szPushButton, msi_dialog_button_control },
1449 { szLine, msi_dialog_line_control },
1450 { szBitmap, msi_dialog_bitmap_control },
1451 { szCheckBox, msi_dialog_checkbox_control },
1452 { szScrollableText, msi_dialog_scrolltext_control },
1453 { szComboBox, msi_dialog_combo_control },
1454 { szEdit, msi_dialog_edit_control },
1455 { szMaskedEdit, msi_dialog_maskedit_control },
1456 { szPathEdit, msi_dialog_pathedit_control },
1457 { szProgressBar, msi_dialog_progress_bar },
1458 { szRadioButtonGroup, msi_dialog_radiogroup_control },
1459 { szIcon, msi_dialog_icon_control },
1460 { szSelectionTree, msi_dialog_selection_tree },
1463 #define NUM_CONTROL_TYPES (sizeof msi_dialog_handler/sizeof msi_dialog_handler[0])
1465 static UINT msi_dialog_create_controls( MSIRECORD *rec, LPVOID param )
1467 msi_dialog *dialog = param;
1468 LPCWSTR control_type;
1471 /* find and call the function that can create this type of control */
1472 control_type = MSI_RecordGetString( rec, 3 );
1473 for( i=0; i<NUM_CONTROL_TYPES; i++ )
1474 if (!strcmpiW( msi_dialog_handler[i].control_type, control_type ))
1476 if( i != NUM_CONTROL_TYPES )
1477 msi_dialog_handler[i].func( dialog, rec );
1479 ERR("no handler for element type %s\n", debugstr_w(control_type));
1481 return ERROR_SUCCESS;
1484 static UINT msi_dialog_fill_controls( msi_dialog *dialog )
1486 static const WCHAR query[] = {
1487 'S','E','L','E','C','T',' ','*',' ',
1488 'F','R','O','M',' ','C','o','n','t','r','o','l',' ',
1489 'W','H','E','R','E',' ',
1490 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',0};
1492 MSIQUERY *view = NULL;
1493 MSIPACKAGE *package = dialog->package;
1495 TRACE("%p %s\n", dialog, debugstr_w(dialog->name) );
1497 /* query the Control table for all the elements of the control */
1498 r = MSI_OpenQuery( package->db, &view, query, dialog->name );
1499 if( r != ERROR_SUCCESS )
1501 ERR("query failed for dialog %s\n", debugstr_w(dialog->name));
1502 return ERROR_INVALID_PARAMETER;
1505 r = MSI_IterateRecords( view, 0, msi_dialog_create_controls, dialog );
1506 msiobj_release( &view->hdr );
1511 static UINT msi_dialog_set_control_condition( MSIRECORD *rec, LPVOID param )
1513 static const WCHAR szHide[] = { 'H','i','d','e',0 };
1514 static const WCHAR szShow[] = { 'S','h','o','w',0 };
1515 static const WCHAR szDisable[] = { 'D','i','s','a','b','l','e',0 };
1516 static const WCHAR szEnable[] = { 'E','n','a','b','l','e',0 };
1517 msi_dialog *dialog = param;
1518 msi_control *control;
1519 LPCWSTR name, action, condition;
1522 name = MSI_RecordGetString( rec, 2 );
1523 action = MSI_RecordGetString( rec, 3 );
1524 condition = MSI_RecordGetString( rec, 4 );
1525 r = MSI_EvaluateConditionW( dialog->package, condition );
1526 control = msi_dialog_find_control( dialog, name );
1527 if( r == MSICONDITION_TRUE && control )
1529 TRACE("%s control %s\n", debugstr_w(action), debugstr_w(name));
1531 /* FIXME: case sensitive? */
1532 if(!lstrcmpW(action, szHide))
1533 ShowWindow(control->hwnd, SW_HIDE);
1534 else if(!strcmpW(action, szShow))
1535 ShowWindow(control->hwnd, SW_SHOW);
1536 else if(!strcmpW(action, szDisable))
1537 EnableWindow(control->hwnd, FALSE);
1538 else if(!strcmpW(action, szEnable))
1539 EnableWindow(control->hwnd, TRUE);
1541 FIXME("Unhandled action %s\n", debugstr_w(action));
1544 return ERROR_SUCCESS;
1547 static UINT msi_dialog_evaluate_control_conditions( msi_dialog *dialog )
1549 static const WCHAR query[] = {
1550 'S','E','L','E','C','T',' ','*',' ',
1551 'F','R','O','M',' ',
1552 'C','o','n','t','r','o','l','C','o','n','d','i','t','i','o','n',' ',
1553 'W','H','E','R','E',' ',
1554 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',0
1557 MSIQUERY *view = NULL;
1558 MSIPACKAGE *package = dialog->package;
1560 TRACE("%p %s\n", dialog, debugstr_w(dialog->name) );
1562 /* query the Control table for all the elements of the control */
1563 r = MSI_OpenQuery( package->db, &view, query, dialog->name );
1564 if( r != ERROR_SUCCESS )
1566 ERR("query failed for dialog %s\n", debugstr_w(dialog->name));
1567 return ERROR_INVALID_PARAMETER;
1570 r = MSI_IterateRecords( view, 0, msi_dialog_set_control_condition, dialog );
1571 msiobj_release( &view->hdr );
1576 UINT msi_dialog_reset( msi_dialog *dialog )
1578 /* FIXME: should restore the original values of any properties we changed */
1579 return msi_dialog_evaluate_control_conditions( dialog );
1582 /* figure out the height of 10 point MS Sans Serif */
1583 static INT msi_dialog_get_sans_serif_height( HWND hwnd )
1585 static const WCHAR szSansSerif[] = {
1586 'M','S',' ','S','a','n','s',' ','S','e','r','i','f',0 };
1591 HFONT hFont, hOldFont;
1594 hdc = GetDC( hwnd );
1597 memset( &lf, 0, sizeof lf );
1598 lf.lfHeight = MulDiv(10, GetDeviceCaps(hdc, LOGPIXELSY), 72);
1599 strcpyW( lf.lfFaceName, szSansSerif );
1600 hFont = CreateFontIndirectW(&lf);
1603 hOldFont = SelectObject( hdc, hFont );
1604 r = GetTextMetricsW( hdc, &tm );
1606 height = tm.tmHeight;
1607 SelectObject( hdc, hOldFont );
1608 DeleteObject( hFont );
1610 ReleaseDC( hwnd, hdc );
1615 /* fetch the associated record from the Dialog table */
1616 static MSIRECORD *msi_get_dialog_record( msi_dialog *dialog )
1618 static const WCHAR query[] = {
1619 'S','E','L','E','C','T',' ','*',' ',
1620 'F','R','O','M',' ','D','i','a','l','o','g',' ',
1621 'W','H','E','R','E',' ',
1622 '`','D','i','a','l','o','g','`',' ','=',' ','\'','%','s','\'',0};
1623 MSIPACKAGE *package = dialog->package;
1624 MSIRECORD *rec = NULL;
1626 TRACE("%p %s\n", dialog, debugstr_w(dialog->name) );
1628 rec = MSI_QueryGetRecord( package->db, query, dialog->name );
1630 ERR("query failed for dialog %s\n", debugstr_w(dialog->name));
1635 static void msi_dialog_adjust_dialog_size( msi_dialog *dialog, LPSIZE sz )
1640 /* turn the client size into the window rectangle */
1643 rect.right = msi_dialog_scale_unit( dialog, sz->cx );
1644 rect.bottom = msi_dialog_scale_unit( dialog, sz->cy );
1645 style = GetWindowLongPtrW( dialog->hwnd, GWL_STYLE );
1646 AdjustWindowRect( &rect, style, FALSE );
1647 sz->cx = rect.right - rect.left;
1648 sz->cy = rect.bottom - rect.top;
1651 static BOOL msi_control_set_next( msi_control *control, msi_control *next )
1653 return SetWindowPos( next->hwnd, control->hwnd, 0, 0, 0, 0,
1654 SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOREDRAW |
1655 SWP_NOREPOSITION | SWP_NOSENDCHANGING | SWP_NOSIZE );
1658 static UINT msi_dialog_set_tab_order( msi_dialog *dialog )
1660 msi_control *control, *tab_next;
1662 LIST_FOR_EACH_ENTRY( control, &dialog->controls, msi_control, entry )
1664 tab_next = msi_dialog_find_control( dialog, control->tabnext );
1667 msi_control_set_next( control, tab_next );
1670 return ERROR_SUCCESS;
1673 static void msi_dialog_set_first_control( msi_dialog* dialog, LPCWSTR name )
1675 msi_control *control;
1677 control = msi_dialog_find_control( dialog, name );
1679 dialog->hWndFocus = control->hwnd;
1681 dialog->hWndFocus = NULL;
1684 static LRESULT msi_dialog_oncreate( HWND hwnd, LPCREATESTRUCTW cs )
1686 static const WCHAR df[] = {
1687 'D','e','f','a','u','l','t','U','I','F','o','n','t',0 };
1688 static const WCHAR dfv[] = {
1689 'M','S',' ','S','h','e','l','l',' ','D','l','g',0 };
1690 msi_dialog *dialog = (msi_dialog*) cs->lpCreateParams;
1691 MSIRECORD *rec = NULL;
1692 LPWSTR title = NULL;
1695 TRACE("%p %p\n", dialog, dialog->package);
1697 dialog->hwnd = hwnd;
1698 SetWindowLongPtrW( hwnd, GWLP_USERDATA, (LONG_PTR) dialog );
1700 rec = msi_get_dialog_record( dialog );
1703 TRACE("No record found for dialog %s\n", debugstr_w(dialog->name));
1707 dialog->scale = msi_dialog_get_sans_serif_height(dialog->hwnd);
1709 size.cx = MSI_RecordGetInteger( rec, 4 );
1710 size.cy = MSI_RecordGetInteger( rec, 5 );
1711 msi_dialog_adjust_dialog_size( dialog, &size );
1713 dialog->attributes = MSI_RecordGetInteger( rec, 6 );
1715 dialog->default_font = msi_dup_property( dialog->package, df );
1716 if (!dialog->default_font)
1718 dialog->default_font = strdupW(dfv);
1719 if (!dialog->default_font) return -1;
1722 title = msi_get_deformatted_field( dialog->package, rec, 7 );
1723 SetWindowTextW( hwnd, title );
1726 SetWindowPos( hwnd, 0, 0, 0, size.cx, size.cy,
1727 SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOREDRAW );
1730 msi_dialog_build_font_list( dialog );
1731 msi_dialog_fill_controls( dialog );
1732 msi_dialog_evaluate_control_conditions( dialog );
1733 msi_dialog_set_tab_order( dialog );
1734 msi_dialog_set_first_control( dialog, MSI_RecordGetString( rec, 8 ) );
1735 msiobj_release( &rec->hdr );
1740 static UINT msi_dialog_send_event( msi_dialog *dialog, LPCWSTR event, LPCWSTR arg )
1742 LPWSTR event_fmt = NULL, arg_fmt = NULL;
1744 TRACE("Sending control event %s %s\n", debugstr_w(event), debugstr_w(arg));
1746 deformat_string( dialog->package, event, &event_fmt );
1747 deformat_string( dialog->package, arg, &arg_fmt );
1749 dialog->event_handler( dialog->package, event_fmt, arg_fmt, dialog );
1751 msi_free( event_fmt );
1752 msi_free( arg_fmt );
1754 return ERROR_SUCCESS;
1757 static UINT msi_dialog_set_property( msi_dialog *dialog, LPCWSTR event, LPCWSTR arg )
1759 static const WCHAR szNullArg[] = { '{','}',0 };
1760 LPWSTR p, prop, arg_fmt = NULL;
1763 len = strlenW(event);
1764 prop = msi_alloc( len*sizeof(WCHAR));
1765 strcpyW( prop, &event[1] );
1766 p = strchrW( prop, ']' );
1767 if( p && p[1] == 0 )
1770 if( strcmpW( szNullArg, arg ) )
1771 deformat_string( dialog->package, arg, &arg_fmt );
1772 MSI_SetPropertyW( dialog->package, prop, arg_fmt );
1773 msi_free( arg_fmt );
1776 ERR("Badly formatted property string - what happens?\n");
1778 return ERROR_SUCCESS;
1781 static UINT msi_dialog_control_event( MSIRECORD *rec, LPVOID param )
1783 msi_dialog *dialog = param;
1784 LPCWSTR condition, event, arg;
1787 condition = MSI_RecordGetString( rec, 5 );
1788 r = MSI_EvaluateConditionW( dialog->package, condition );
1789 if( r == MSICONDITION_TRUE )
1791 event = MSI_RecordGetString( rec, 3 );
1792 arg = MSI_RecordGetString( rec, 4 );
1793 if( event[0] == '[' )
1794 msi_dialog_set_property( dialog, event, arg );
1796 msi_dialog_send_event( dialog, event, arg );
1799 return ERROR_SUCCESS;
1802 static UINT msi_dialog_button_handler( msi_dialog *dialog,
1803 msi_control *control, WPARAM param )
1805 static const WCHAR query[] = {
1806 'S','E','L','E','C','T',' ','*',' ',
1807 'F','R','O','M',' ','C','o','n','t','r','o','l','E','v','e','n','t',' ',
1808 'W','H','E','R','E',' ',
1809 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',' ',
1811 '`','C','o','n','t','r','o','l','_','`',' ','=',' ','\'','%','s','\'',' ',
1812 'O','R','D','E','R',' ','B','Y',' ','`','O','r','d','e','r','i','n','g','`',0
1814 MSIQUERY *view = NULL;
1817 if( HIWORD(param) != BN_CLICKED )
1818 return ERROR_SUCCESS;
1820 r = MSI_OpenQuery( dialog->package->db, &view, query,
1821 dialog->name, control->name );
1822 if( r != ERROR_SUCCESS )
1824 ERR("query failed\n");
1828 r = MSI_IterateRecords( view, 0, msi_dialog_control_event, dialog );
1829 msiobj_release( &view->hdr );
1834 static UINT msi_dialog_get_checkbox_state( msi_dialog *dialog,
1835 msi_control *control )
1837 WCHAR state[2] = { 0 };
1840 MSI_GetPropertyW( dialog->package, control->property, state, &sz );
1841 return state[0] ? 1 : 0;
1844 static void msi_dialog_set_checkbox_state( msi_dialog *dialog,
1845 msi_control *control, UINT state )
1847 static const WCHAR szState[] = { '1', 0 };
1850 /* if uncheck then the property is set to NULL */
1853 MSI_SetPropertyW( dialog->package, control->property, NULL );
1857 /* check for a custom state */
1858 if (control->value && control->value[0])
1859 val = control->value;
1863 MSI_SetPropertyW( dialog->package, control->property, val );
1866 static void msi_dialog_checkbox_sync_state( msi_dialog *dialog,
1867 msi_control *control )
1871 state = msi_dialog_get_checkbox_state( dialog, control );
1872 SendMessageW( control->hwnd, BM_SETCHECK,
1873 state ? BST_CHECKED : BST_UNCHECKED, 0 );
1876 static UINT msi_dialog_checkbox_handler( msi_dialog *dialog,
1877 msi_control *control, WPARAM param )
1881 if( HIWORD(param) != BN_CLICKED )
1882 return ERROR_SUCCESS;
1884 TRACE("clicked checkbox %s, set %s\n", debugstr_w(control->name),
1885 debugstr_w(control->property));
1887 state = msi_dialog_get_checkbox_state( dialog, control );
1888 state = state ? 0 : 1;
1889 msi_dialog_set_checkbox_state( dialog, control, state );
1890 msi_dialog_checkbox_sync_state( dialog, control );
1892 return msi_dialog_button_handler( dialog, control, param );
1895 static UINT msi_dialog_edit_handler( msi_dialog *dialog,
1896 msi_control *control, WPARAM param )
1901 if( HIWORD(param) != EN_CHANGE )
1902 return ERROR_SUCCESS;
1904 TRACE("edit %s contents changed, set %s\n", debugstr_w(control->name),
1905 debugstr_w(control->property));
1908 buf = msi_alloc( sz*sizeof(WCHAR) );
1911 r = GetWindowTextW( control->hwnd, buf, sz );
1915 buf = msi_realloc( buf, sz*sizeof(WCHAR) );
1918 MSI_SetPropertyW( dialog->package, control->property, buf );
1922 return ERROR_SUCCESS;
1925 static UINT msi_dialog_radiogroup_handler( msi_dialog *dialog,
1926 msi_control *control, WPARAM param )
1928 if( HIWORD(param) != BN_CLICKED )
1929 return ERROR_SUCCESS;
1931 TRACE("clicked radio button %s, set %s\n", debugstr_w(control->name),
1932 debugstr_w(control->property));
1934 MSI_SetPropertyW( dialog->package, control->property, control->name );
1936 return msi_dialog_button_handler( dialog, control, param );
1939 static LRESULT msi_dialog_oncommand( msi_dialog *dialog, WPARAM param, HWND hwnd )
1941 msi_control *control = NULL;
1943 TRACE("%p %p %08x\n", dialog, hwnd, param);
1948 control = msi_dialog_find_control( dialog, dialog->control_default );
1950 case 2: /* escape */
1951 control = msi_dialog_find_control( dialog, dialog->control_cancel );
1954 control = msi_dialog_find_control_by_hwnd( dialog, hwnd );
1959 if( control->handler )
1961 control->handler( dialog, control, param );
1962 msi_dialog_evaluate_control_conditions( dialog );
1966 ERR("button click from nowhere %p %d %p\n", dialog, param, hwnd);
1970 static void msi_dialog_setfocus( msi_dialog *dialog )
1972 HWND hwnd = dialog->hWndFocus;
1974 hwnd = GetNextDlgTabItem( dialog->hwnd, hwnd, TRUE);
1975 hwnd = GetNextDlgTabItem( dialog->hwnd, hwnd, FALSE);
1977 dialog->hWndFocus = hwnd;
1980 static LRESULT WINAPI MSIDialog_WndProc( HWND hwnd, UINT msg,
1981 WPARAM wParam, LPARAM lParam )
1983 msi_dialog *dialog = (LPVOID) GetWindowLongPtrW( hwnd, GWLP_USERDATA );
1985 TRACE("0x%04x\n", msg);
1990 return msi_dialog_oncreate( hwnd, (LPCREATESTRUCTW)lParam );
1993 return msi_dialog_oncommand( dialog, wParam, (HWND)lParam );
1996 if( LOWORD(wParam) == WA_INACTIVE )
1997 dialog->hWndFocus = GetFocus();
1999 msi_dialog_setfocus( dialog );
2003 msi_dialog_setfocus( dialog );
2006 /* bounce back to our subclassed static control */
2007 case WM_CTLCOLORSTATIC:
2008 return SendMessageW( (HWND) lParam, WM_CTLCOLORSTATIC, wParam, lParam );
2011 dialog->hwnd = NULL;
2014 return DefWindowProcW(hwnd, msg, wParam, lParam);
2017 static BOOL CALLBACK msi_radioground_child_enum( HWND hWnd, LPARAM lParam )
2019 EnableWindow( hWnd, lParam );
2023 static LRESULT WINAPI MSIRadioGroup_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
2025 WNDPROC oldproc = (WNDPROC) GetPropW(hWnd, szButtonData);
2028 TRACE("hWnd %p msg %04x wParam 0x%08x lParam 0x%08lx\n", hWnd, msg, wParam, lParam);
2030 if (msg == WM_COMMAND) /* Forward notifications to dialog */
2031 SendMessageW(GetParent(hWnd), msg, wParam, lParam);
2033 r = CallWindowProcW(oldproc, hWnd, msg, wParam, lParam);
2035 /* make sure the radio buttons show as disabled if the parent is disabled */
2036 if (msg == WM_ENABLE)
2037 EnumChildWindows( hWnd, msi_radioground_child_enum, wParam );
2042 static LRESULT WINAPI MSIHiddenWindowProc( HWND hwnd, UINT msg,
2043 WPARAM wParam, LPARAM lParam )
2045 msi_dialog *dialog = (msi_dialog*) lParam;
2047 TRACE("%d %p\n", msg, dialog);
2051 case WM_MSI_DIALOG_CREATE:
2052 return msi_dialog_run_message_loop( dialog );
2053 case WM_MSI_DIALOG_DESTROY:
2054 msi_dialog_destroy( dialog );
2057 return DefWindowProcW( hwnd, msg, wParam, lParam );
2060 /* functions that interface to other modules within MSI */
2062 msi_dialog *msi_dialog_create( MSIPACKAGE* package, LPCWSTR szDialogName,
2063 msi_dialog_event_handler event_handler )
2065 MSIRECORD *rec = NULL;
2068 TRACE("%p %s\n", package, debugstr_w(szDialogName));
2070 /* allocate the structure for the dialog to use */
2071 dialog = msi_alloc_zero( sizeof *dialog + sizeof(WCHAR)*strlenW(szDialogName) );
2074 strcpyW( dialog->name, szDialogName );
2075 msiobj_addref( &package->hdr );
2076 dialog->package = package;
2077 dialog->event_handler = event_handler;
2078 dialog->finished = 0;
2079 list_init( &dialog->controls );
2081 /* verify that the dialog exists */
2082 rec = msi_get_dialog_record( dialog );
2085 msiobj_release( &package->hdr );
2089 dialog->attributes = MSI_RecordGetInteger( rec, 6 );
2090 dialog->control_default = strdupW( MSI_RecordGetString( rec, 9 ) );
2091 dialog->control_cancel = strdupW( MSI_RecordGetString( rec, 10 ) );
2092 msiobj_release( &rec->hdr );
2097 static void msi_process_pending_messages( HWND hdlg )
2101 while( PeekMessageW( &msg, 0, 0, 0, PM_REMOVE ) )
2103 if( hdlg && IsDialogMessageW( hdlg, &msg ))
2105 TranslateMessage( &msg );
2106 DispatchMessageW( &msg );
2110 void msi_dialog_end_dialog( msi_dialog *dialog )
2112 TRACE("%p\n", dialog);
2113 dialog->finished = 1;
2114 PostMessageW(dialog->hwnd, WM_NULL, 0, 0);
2117 void msi_dialog_check_messages( HANDLE handle )
2121 /* in threads other than the UI thread, block */
2122 if( uiThreadId != GetCurrentThreadId() )
2125 WaitForSingleObject( handle, INFINITE );
2129 /* there's two choices for the UI thread */
2132 msi_process_pending_messages( NULL );
2138 * block here until somebody creates a new dialog or
2139 * the handle we're waiting on becomes ready
2141 r = MsgWaitForMultipleObjects( 1, &handle, 0, INFINITE, QS_ALLINPUT );
2142 if( r == WAIT_OBJECT_0 )
2147 UINT msi_dialog_run_message_loop( msi_dialog *dialog )
2151 if( !(dialog->attributes & msidbDialogAttributesVisible) )
2152 return ERROR_SUCCESS;
2154 if( uiThreadId != GetCurrentThreadId() )
2155 return SendMessageW( hMsiHiddenWindow, WM_MSI_DIALOG_CREATE, 0, (LPARAM) dialog );
2157 /* create the dialog window, don't show it yet */
2158 hwnd = CreateWindowW( szMsiDialogClass, dialog->name, WS_OVERLAPPEDWINDOW,
2159 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
2160 NULL, NULL, NULL, dialog );
2163 ERR("Failed to create dialog %s\n", debugstr_w( dialog->name ));
2164 return ERROR_FUNCTION_FAILED;
2167 ShowWindow( hwnd, SW_SHOW );
2168 /* UpdateWindow( hwnd ); - and causes the transparent static controls not to paint */
2170 if( dialog->attributes & msidbDialogAttributesModal )
2172 while( !dialog->finished )
2174 MsgWaitForMultipleObjects( 0, NULL, 0, INFINITE, QS_ALLEVENTS );
2175 msi_process_pending_messages( dialog->hwnd );
2179 return ERROR_IO_PENDING;
2181 return ERROR_SUCCESS;
2184 void msi_dialog_do_preview( msi_dialog *dialog )
2187 dialog->attributes |= msidbDialogAttributesVisible;
2188 dialog->attributes &= ~msidbDialogAttributesModal;
2189 msi_dialog_run_message_loop( dialog );
2192 void msi_dialog_destroy( msi_dialog *dialog )
2194 if( uiThreadId != GetCurrentThreadId() )
2196 SendMessageW( hMsiHiddenWindow, WM_MSI_DIALOG_DESTROY, 0, (LPARAM) dialog );
2201 ShowWindow( dialog->hwnd, SW_HIDE );
2204 DestroyWindow( dialog->hwnd );
2206 /* destroy the list of controls */
2207 while( !list_empty( &dialog->controls ) )
2209 msi_control *t = LIST_ENTRY( list_head( &dialog->controls ),
2210 msi_control, entry );
2211 list_remove( &t->entry );
2212 /* leave dialog->hwnd - destroying parent destroys child windows */
2213 msi_free( t->property );
2214 msi_free( t->value );
2216 DeleteObject( t->hBitmap );
2218 DestroyIcon( t->hIcon );
2219 msi_free( t->tabnext );
2222 FreeLibrary( t->hDll );
2225 /* destroy the list of fonts */
2226 while( dialog->font_list )
2228 msi_font *t = dialog->font_list;
2229 dialog->font_list = t->next;
2230 DeleteObject( t->hfont );
2233 msi_free( dialog->default_font );
2235 msi_free( dialog->control_default );
2236 msi_free( dialog->control_cancel );
2237 msiobj_release( &dialog->package->hdr );
2238 dialog->package = NULL;
2242 BOOL msi_dialog_register_class( void )
2246 ZeroMemory( &cls, sizeof cls );
2247 cls.lpfnWndProc = MSIDialog_WndProc;
2248 cls.hInstance = NULL;
2249 cls.hIcon = LoadIconW(0, (LPWSTR)IDI_APPLICATION);
2250 cls.hCursor = LoadCursorW(0, (LPWSTR)IDC_ARROW);
2251 cls.hbrBackground = (HBRUSH)(COLOR_3DFACE + 1);
2252 cls.lpszMenuName = NULL;
2253 cls.lpszClassName = szMsiDialogClass;
2255 if( !RegisterClassW( &cls ) )
2258 cls.lpfnWndProc = MSIHiddenWindowProc;
2259 cls.lpszClassName = szMsiHiddenWindow;
2261 if( !RegisterClassW( &cls ) )
2264 uiThreadId = GetCurrentThreadId();
2266 hMsiHiddenWindow = CreateWindowW( szMsiHiddenWindow, NULL, WS_OVERLAPPED,
2267 0, 0, 100, 100, NULL, NULL, NULL, NULL );
2268 if( !hMsiHiddenWindow )
2274 void msi_dialog_unregister_class( void )
2276 DestroyWindow( hMsiHiddenWindow );
2277 hMsiHiddenWindow = NULL;
2278 UnregisterClassW( szMsiDialogClass, NULL );
2279 UnregisterClassW( szMsiHiddenWindow, NULL );