2 * Implementation of the Microsoft Installer (msi.dll)
4 * Copyright 2005 Mike McCormack for CodeWeavers
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #define NONAMELESSUNION
23 #define NONAMELESSSTRUCT
40 #include "wine/debug.h"
41 #include "wine/unicode.h"
45 WINE_DEFAULT_DEBUG_CHANNEL(msi);
48 extern HINSTANCE msi_hInstance;
50 struct msi_control_tag;
51 typedef struct msi_control_tag msi_control;
52 typedef UINT (*msi_handler)( msi_dialog *, msi_control *, WPARAM );
54 struct msi_control_tag
68 typedef struct msi_font_tag
70 struct msi_font_tag *next;
78 msi_dialog_event_handler event_handler;
87 LPWSTR control_default;
88 LPWSTR control_cancel;
92 typedef UINT (*msi_dialog_control_func)( msi_dialog *dialog, MSIRECORD *rec );
93 struct control_handler
96 msi_dialog_control_func func;
105 } radio_button_group_descr;
107 const WCHAR szMsiDialogClass[] = {
108 'M','s','i','D','i','a','l','o','g','C','l','o','s','e','C','l','a','s','s',0
110 const WCHAR szMsiHiddenWindow[] = {
111 'M','s','i','H','i','d','d','e','n','W','i','n','d','o','w',0 };
112 static const WCHAR szStatic[] = { 'S','t','a','t','i','c',0 };
113 static const WCHAR szButton[] = { 'B','U','T','T','O','N', 0 };
114 static const WCHAR szButtonData[] = { 'M','S','I','D','A','T','A',0 };
115 static const WCHAR szProgress[] = { 'P','r','o','g','r','e','s','s',0 };
116 static const WCHAR szText[] = { 'T','e','x','t',0 };
117 static const WCHAR szPushButton[] = { 'P','u','s','h','B','u','t','t','o','n',0 };
118 static const WCHAR szLine[] = { 'L','i','n','e',0 };
119 static const WCHAR szBitmap[] = { 'B','i','t','m','a','p',0 };
120 static const WCHAR szCheckBox[] = { 'C','h','e','c','k','B','o','x',0 };
121 static const WCHAR szScrollableText[] = {
122 'S','c','r','o','l','l','a','b','l','e','T','e','x','t',0 };
123 static const WCHAR szComboBox[] = { 'C','o','m','b','o','B','o','x',0 };
124 static const WCHAR szEdit[] = { 'E','d','i','t',0 };
125 static const WCHAR szMaskedEdit[] = { 'M','a','s','k','e','d','E','d','i','t',0 };
126 static const WCHAR szPathEdit[] = { 'P','a','t','h','E','d','i','t',0 };
127 static const WCHAR szProgressBar[] = {
128 'P','r','o','g','r','e','s','s','B','a','r',0 };
129 static const WCHAR szRadioButtonGroup[] = {
130 'R','a','d','i','o','B','u','t','t','o','n','G','r','o','u','p',0 };
131 static const WCHAR szIcon[] = { 'I','c','o','n',0 };
132 static const WCHAR szSelectionTree[] = {
133 'S','e','l','e','c','t','i','o','n','T','r','e','e',0 };
135 static UINT msi_dialog_checkbox_handler( msi_dialog *, msi_control *, WPARAM );
136 static void msi_dialog_checkbox_sync_state( msi_dialog *, msi_control * );
137 static UINT msi_dialog_button_handler( msi_dialog *, msi_control *, WPARAM );
138 static UINT msi_dialog_edit_handler( msi_dialog *, msi_control *, WPARAM );
139 static UINT msi_dialog_radiogroup_handler( msi_dialog *, msi_control *, WPARAM param );
140 static UINT msi_dialog_evaluate_control_conditions( msi_dialog *dialog );
141 static LRESULT WINAPI MSIRadioGroup_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
144 /* dialog sequencing */
146 #define WM_MSI_DIALOG_CREATE (WM_USER+0x100)
147 #define WM_MSI_DIALOG_DESTROY (WM_USER+0x101)
149 static DWORD uiThreadId;
150 static HWND hMsiHiddenWindow;
152 static INT msi_dialog_scale_unit( msi_dialog *dialog, INT val )
154 return (dialog->scale * val + 5) / 10;
157 static msi_control *msi_dialog_find_control( msi_dialog *dialog, LPCWSTR name )
159 msi_control *control;
163 LIST_FOR_EACH_ENTRY( control, &dialog->controls, msi_control, entry )
164 if( !strcmpW( control->name, name ) ) /* FIXME: case sensitive? */
169 static msi_control *msi_dialog_find_control_by_hwnd( msi_dialog *dialog, HWND hwnd )
171 msi_control *control;
173 LIST_FOR_EACH_ENTRY( control, &dialog->controls, msi_control, entry )
174 if( hwnd == control->hwnd )
179 static LPWSTR msi_get_deformatted_field( MSIPACKAGE *package, MSIRECORD *rec, int field )
181 LPCWSTR str = MSI_RecordGetString( rec, field );
185 deformat_string( package, str, &ret );
190 * msi_dialog_get_style
192 * Extract the {\style} string from the front of the text to display and
193 * update the pointer.
195 static LPWSTR msi_dialog_get_style( LPCWSTR p, LPCWSTR *rest )
206 q = strchrW( p, '}' );
209 if( *p == '\\' || *p == '&' )
212 /* little bit of sanity checking to stop us getting confused with RTF */
214 if( *i == '}' || *i == '\\' )
220 ret = msi_alloc( len*sizeof(WCHAR) );
223 memcpy( ret, p, len*sizeof(WCHAR) );
228 static UINT msi_dialog_add_font( MSIRECORD *rec, LPVOID param )
230 msi_dialog *dialog = param;
237 /* create a font and add it to the list */
238 name = MSI_RecordGetString( rec, 1 );
239 font = msi_alloc( sizeof *font + strlenW( name )*sizeof (WCHAR) );
240 strcpyW( font->name, name );
241 font->next = dialog->font_list;
242 dialog->font_list = font;
244 memset( &lf, 0, sizeof lf );
245 face = MSI_RecordGetString( rec, 2 );
246 lf.lfHeight = MSI_RecordGetInteger( rec, 3 );
247 style = MSI_RecordGetInteger( rec, 5 );
248 if( style & msidbTextStyleStyleBitsBold )
249 lf.lfWeight = FW_BOLD;
250 if( style & msidbTextStyleStyleBitsItalic )
252 if( style & msidbTextStyleStyleBitsUnderline )
253 lf.lfUnderline = TRUE;
254 if( style & msidbTextStyleStyleBitsStrike )
255 lf.lfStrikeOut = TRUE;
256 lstrcpynW( lf.lfFaceName, face, LF_FACESIZE );
258 /* adjust the height */
259 hdc = GetDC( dialog->hwnd );
262 lf.lfHeight = -MulDiv(lf.lfHeight, GetDeviceCaps(hdc, LOGPIXELSY), 72);
263 ReleaseDC( dialog->hwnd, hdc );
266 font->hfont = CreateFontIndirectW( &lf );
268 TRACE("Adding font style %s\n", debugstr_w(font->name) );
270 return ERROR_SUCCESS;
273 static msi_font *msi_dialog_find_font( msi_dialog *dialog, LPCWSTR name )
277 for( font = dialog->font_list; font; font = font->next )
278 if( !strcmpW( font->name, name ) ) /* FIXME: case sensitive? */
284 static UINT msi_dialog_set_font( msi_dialog *dialog, HWND hwnd, LPCWSTR name )
288 font = msi_dialog_find_font( dialog, name );
290 SendMessageW( hwnd, WM_SETFONT, (WPARAM) font->hfont, TRUE );
292 ERR("No font entry for %s\n", debugstr_w(name));
293 return ERROR_SUCCESS;
296 static UINT msi_dialog_build_font_list( msi_dialog *dialog )
298 static const WCHAR query[] = {
299 'S','E','L','E','C','T',' ','*',' ',
300 'F','R','O','M',' ','`','T','e','x','t','S','t','y','l','e','`',' ',0
303 MSIQUERY *view = NULL;
305 TRACE("dialog %p\n", dialog );
307 r = MSI_OpenQuery( dialog->package->db, &view, query );
308 if( r != ERROR_SUCCESS )
311 r = MSI_IterateRecords( view, NULL, msi_dialog_add_font, dialog );
312 msiobj_release( &view->hdr );
317 static msi_control *msi_dialog_create_window( msi_dialog *dialog,
318 MSIRECORD *rec, DWORD exstyle, LPCWSTR szCls, LPCWSTR name, LPCWSTR text,
319 DWORD style, HWND parent )
321 DWORD x, y, width, height;
322 LPWSTR font = NULL, title_font = NULL;
323 LPCWSTR title = NULL;
324 msi_control *control;
328 control = msi_alloc( sizeof *control + strlenW(name)*sizeof(WCHAR) );
329 strcpyW( control->name, name );
330 list_add_head( &dialog->controls, &control->entry );
331 control->handler = NULL;
332 control->property = NULL;
333 control->value = NULL;
334 control->hBitmap = NULL;
335 control->hIcon = NULL;
336 control->hDll = NULL;
337 control->tabnext = strdupW( MSI_RecordGetString( rec, 11) );
339 x = MSI_RecordGetInteger( rec, 4 );
340 y = MSI_RecordGetInteger( rec, 5 );
341 width = MSI_RecordGetInteger( rec, 6 );
342 height = MSI_RecordGetInteger( rec, 7 );
344 x = msi_dialog_scale_unit( dialog, x );
345 y = msi_dialog_scale_unit( dialog, y );
346 width = msi_dialog_scale_unit( dialog, width );
347 height = msi_dialog_scale_unit( dialog, height );
351 deformat_string( dialog->package, text, &title_font );
352 font = msi_dialog_get_style( title_font, &title );
355 control->hwnd = CreateWindowExW( exstyle, szCls, title, style,
356 x, y, width, height, parent, NULL, NULL, NULL );
358 TRACE("Dialog %s control %s hwnd %p\n",
359 debugstr_w(dialog->name), debugstr_w(text), control->hwnd );
361 msi_dialog_set_font( dialog, control->hwnd,
362 font ? font : dialog->default_font );
364 msi_free( title_font );
370 static MSIRECORD *msi_get_binary_record( MSIDATABASE *db, LPCWSTR name )
372 static const WCHAR query[] = {
373 's','e','l','e','c','t',' ','*',' ',
374 'f','r','o','m',' ','B','i','n','a','r','y',' ',
375 'w','h','e','r','e',' ',
376 '`','N','a','m','e','`',' ','=',' ','\'','%','s','\'',0
379 return MSI_QueryGetRecord( db, query, name );
382 static LPWSTR msi_create_tmp_path(void)
386 static const WCHAR prefix[] = { 'm','s','i',0 };
389 r = GetTempPathW( MAX_PATH, tmp );
392 len = lstrlenW( tmp ) + 20;
393 path = msi_alloc( len * sizeof (WCHAR) );
396 r = GetTempFileNameW( tmp, prefix, 0, path );
407 static HANDLE msi_load_image( MSIDATABASE *db, LPCWSTR name, UINT type,
408 UINT cx, UINT cy, UINT flags )
410 MSIRECORD *rec = NULL;
411 HANDLE himage = NULL;
415 TRACE("%p %s %u %u %08x\n", db, debugstr_w(name), cx, cy, flags);
417 tmp = msi_create_tmp_path();
421 rec = msi_get_binary_record( db, name );
424 r = MSI_RecordStreamToFile( rec, 2, tmp );
425 if( r == ERROR_SUCCESS )
427 himage = LoadImageW( 0, tmp, type, cx, cy, flags );
430 msiobj_release( &rec->hdr );
437 static HICON msi_load_icon( MSIDATABASE *db, LPCWSTR text, UINT attributes )
439 DWORD cx = 0, cy = 0, flags;
441 flags = LR_LOADFROMFILE | LR_DEFAULTSIZE;
442 if( attributes & msidbControlAttributesFixedSize )
444 flags &= ~LR_DEFAULTSIZE;
445 if( attributes & msidbControlAttributesIconSize16 )
450 if( attributes & msidbControlAttributesIconSize32 )
455 /* msidbControlAttributesIconSize48 handled by above logic */
457 return msi_load_image( db, text, IMAGE_ICON, cx, cy, flags );
461 /* called from the Control Event subscription code */
462 void msi_dialog_handle_event( msi_dialog* dialog, LPCWSTR control,
463 LPCWSTR attribute, MSIRECORD *rec )
466 LPCWSTR font_text, text = NULL;
469 ctrl = msi_dialog_find_control( dialog, control );
472 if( !lstrcmpW(attribute, szText) )
474 font_text = MSI_RecordGetString( rec , 1 );
475 font = msi_dialog_get_style( font_text, &text );
476 SetWindowTextW( ctrl->hwnd, text );
478 msi_dialog_check_messages( NULL );
480 else if( !lstrcmpW(attribute, szProgress) )
482 /* FIXME: should forward to progress bar */
483 static int display_fixme = 1;
485 FIXME("Attribute %s not being set\n", debugstr_w(attribute));
490 FIXME("Attribute %s not being set\n", debugstr_w(attribute));
495 static void msi_dialog_map_events(msi_dialog* dialog, LPCWSTR control)
497 static const WCHAR Query[] = {
498 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
499 '`','E','v','e','n','t','M','a','p','p','i','n','g','`',' ',
500 'W','H','E','R','E',' ',
501 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',' ',
503 '`','C','o','n','t','r','o','l','_','`',' ','=',' ','\'','%','s','\'',0
506 LPCWSTR event, attribute;
508 row = MSI_QueryGetRecord( dialog->package->db, Query, dialog->name, control );
512 event = MSI_RecordGetString( row, 3 );
513 attribute = MSI_RecordGetString( row, 4 );
514 ControlEvent_SubscribeToEvent( dialog->package, event, control, attribute );
515 msiobj_release( &row->hdr );
518 /* everything except radio buttons */
519 static msi_control *msi_dialog_add_control( msi_dialog *dialog,
520 MSIRECORD *rec, LPCWSTR szCls, DWORD style )
526 name = MSI_RecordGetString( rec, 2 );
527 attributes = MSI_RecordGetInteger( rec, 8 );
528 text = MSI_RecordGetString( rec, 10 );
529 if( attributes & msidbControlAttributesVisible )
531 if( ~attributes & msidbControlAttributesEnabled )
532 style |= WS_DISABLED;
533 if( attributes & msidbControlAttributesSunken )
534 exstyle |= WS_EX_CLIENTEDGE;
536 msi_dialog_map_events(dialog, name);
538 return msi_dialog_create_window( dialog, rec, exstyle, szCls, name,
539 text, style, dialog->hwnd );
549 * we don't erase our own background,
550 * so we have to make sure that the parent window redraws first
552 static void msi_text_on_settext( HWND hWnd )
557 hParent = GetParent( hWnd );
558 GetWindowRect( hWnd, &rc );
559 MapWindowPoints( NULL, hParent, (LPPOINT) &rc, 2 );
560 InvalidateRect( hParent, &rc, TRUE );
563 static LRESULT WINAPI
564 MSIText_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
566 struct msi_text_info *info;
569 TRACE("%p %04x %08x %08lx\n", hWnd, msg, wParam, lParam);
571 info = GetPropW(hWnd, szButtonData);
573 if( msg == WM_CTLCOLORSTATIC &&
574 ( info->attributes & msidbControlAttributesTransparent ) )
576 SetBkMode( (HDC)wParam, TRANSPARENT );
577 return (LRESULT) GetStockObject(NULL_BRUSH);
580 r = CallWindowProcW(info->oldproc, hWnd, msg, wParam, lParam);
585 msi_text_on_settext( hWnd );
589 RemovePropW( hWnd, szButtonData );
596 static UINT msi_dialog_text_control( msi_dialog *dialog, MSIRECORD *rec )
598 msi_control *control;
599 struct msi_text_info *info;
601 TRACE("%p %p\n", dialog, rec);
603 control = msi_dialog_add_control( dialog, rec, szStatic, SS_LEFT | WS_GROUP );
605 return ERROR_FUNCTION_FAILED;
607 info = msi_alloc( sizeof *info );
609 return ERROR_SUCCESS;
611 info->attributes = MSI_RecordGetInteger( rec, 8 );
612 if( info->attributes & msidbControlAttributesTransparent )
613 SetWindowLongPtrW( control->hwnd, GWL_EXSTYLE, WS_EX_TRANSPARENT );
615 info->oldproc = (WNDPROC) SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
616 (LONG_PTR)MSIText_WndProc );
617 SetPropW( control->hwnd, szButtonData, info );
619 return ERROR_SUCCESS;
622 static UINT msi_dialog_button_control( msi_dialog *dialog, MSIRECORD *rec )
624 msi_control *control;
625 UINT attributes, style;
628 TRACE("%p %p\n", dialog, rec);
631 attributes = MSI_RecordGetInteger( rec, 8 );
632 if( attributes & msidbControlAttributesIcon )
635 control = msi_dialog_add_control( dialog, rec, szButton, style );
637 return ERROR_FUNCTION_FAILED;
639 control->handler = msi_dialog_button_handler;
642 text = msi_get_deformatted_field( dialog->package, rec, 10 );
643 control->hIcon = msi_load_icon( dialog->package->db, text, attributes );
644 if( attributes & msidbControlAttributesIcon )
645 SendMessageW( control->hwnd, BM_SETIMAGE, IMAGE_ICON, (LPARAM) control->hIcon );
648 return ERROR_SUCCESS;
651 static LPWSTR msi_get_checkbox_value( msi_dialog *dialog, LPCWSTR prop )
653 static const WCHAR query[] = {
654 'S','E','L','E','C','T',' ','*',' ',
655 'F','R','O','M',' ','`','C','h','e','c','k','B','o','x',' ','`',
656 'W','H','E','R','E',' ',
657 '`','P','r','o','p','e','r','t','y','`',' ','=',' ',
660 MSIRECORD *rec = NULL;
663 /* find if there is a value associated with the checkbox */
664 rec = MSI_QueryGetRecord( dialog->package->db, query, prop );
668 ret = msi_get_deformatted_field( dialog->package, rec, 2 );
674 msiobj_release( &rec->hdr );
678 ret = msi_dup_property( dialog->package, prop );
688 static UINT msi_dialog_checkbox_control( msi_dialog *dialog, MSIRECORD *rec )
690 msi_control *control;
693 TRACE("%p %p\n", dialog, rec);
695 control = msi_dialog_add_control( dialog, rec, szButton,
696 BS_CHECKBOX | BS_MULTILINE | WS_TABSTOP );
697 control->handler = msi_dialog_checkbox_handler;
698 prop = MSI_RecordGetString( rec, 9 );
701 control->property = strdupW( prop );
702 control->value = msi_get_checkbox_value( dialog, prop );
703 TRACE("control %s value %s\n", debugstr_w(control->property),
704 debugstr_w(control->value));
706 msi_dialog_checkbox_sync_state( dialog, control );
708 return ERROR_SUCCESS;
711 static UINT msi_dialog_line_control( msi_dialog *dialog, MSIRECORD *rec )
713 TRACE("%p %p\n", dialog, rec);
715 msi_dialog_add_control( dialog, rec, szStatic, SS_ETCHEDHORZ | SS_SUNKEN );
716 return ERROR_SUCCESS;
719 /******************** Scroll Text ********************************************/
721 struct msi_scrolltext_info
724 msi_control *control;
728 static LRESULT WINAPI
729 MSIScrollText_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
731 struct msi_scrolltext_info *info;
734 TRACE("%p %04x %08x %08lx\n", hWnd, msg, wParam, lParam);
736 info = GetPropW( hWnd, szButtonData );
738 r = CallWindowProcW( info->oldproc, hWnd, msg, wParam, lParam );
744 RemovePropW( hWnd, szButtonData );
747 /* native MSI sets a wait cursor here */
748 msi_dialog_button_handler( info->dialog, info->control, BN_CLICKED );
754 struct msi_streamin_info
761 static DWORD CALLBACK
762 msi_richedit_stream_in( DWORD_PTR arg, LPBYTE buffer, LONG count, LONG *pcb )
764 struct msi_streamin_info *info = (struct msi_streamin_info*) arg;
766 if( (count + info->offset) > info->length )
767 count = info->length - info->offset;
768 memcpy( buffer, &info->string[ info->offset ], count );
770 info->offset += count;
772 TRACE("%ld/%ld\n", info->offset, info->length);
777 static void msi_scrolltext_add_text( msi_control *control, LPCWSTR text )
779 struct msi_streamin_info info;
782 info.string = strdupWtoA( text );
784 info.length = lstrlenA( info.string ) + 1;
786 es.dwCookie = (DWORD_PTR) &info;
788 es.pfnCallback = msi_richedit_stream_in;
790 SendMessageW( control->hwnd, EM_STREAMIN, SF_RTF, (LPARAM) &es );
792 msi_free( info.string );
795 static UINT msi_dialog_scrolltext_control( msi_dialog *dialog, MSIRECORD *rec )
797 static const WCHAR szRichEdit20W[] = {
798 'R','i','c','h','E','d','i','t','2','0','W',0
800 struct msi_scrolltext_info *info;
801 msi_control *control;
805 info = msi_alloc( sizeof *info );
807 return ERROR_FUNCTION_FAILED;
809 hRichedit = LoadLibraryA("riched20");
811 style = WS_BORDER | ES_MULTILINE | WS_VSCROLL |
812 ES_READONLY | ES_AUTOVSCROLL | WS_TABSTOP;
813 control = msi_dialog_add_control( dialog, rec, szRichEdit20W, style );
816 FreeLibrary( hRichedit );
818 return ERROR_FUNCTION_FAILED;
821 control->hDll = hRichedit;
823 info->dialog = dialog;
824 info->control = control;
826 /* subclass the static control */
827 info->oldproc = (WNDPROC) SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
828 (LONG_PTR)MSIScrollText_WndProc );
829 SetPropW( control->hwnd, szButtonData, info );
831 /* add the text into the richedit */
832 msi_scrolltext_add_text( control, MSI_RecordGetString( rec, 10 ) );
834 return ERROR_SUCCESS;
837 static HBITMAP msi_load_picture( MSIDATABASE *db, LPCWSTR name,
838 INT cx, INT cy, DWORD flags )
840 HBITMAP hOleBitmap = 0, hBitmap = 0, hOldSrcBitmap, hOldDestBitmap;
841 MSIRECORD *rec = NULL;
843 IPicture *pic = NULL;
848 rec = msi_get_binary_record( db, name );
852 r = MSI_RecordGetIStream( rec, 2, &stm );
853 msiobj_release( &rec->hdr );
854 if( r != ERROR_SUCCESS )
857 r = OleLoadPicture( stm, 0, TRUE, &IID_IPicture, (LPVOID*) &pic );
858 IStream_Release( stm );
861 ERR("failed to load picture\n");
865 r = IPicture_get_Handle( pic, (OLE_HANDLE*) &hOleBitmap );
868 ERR("failed to get bitmap handle\n");
872 /* make the bitmap the desired size */
873 r = GetObjectW( hOleBitmap, sizeof bm, &bm );
876 ERR("failed to get bitmap size\n");
880 if (flags & LR_DEFAULTSIZE)
886 srcdc = CreateCompatibleDC( NULL );
887 hOldSrcBitmap = SelectObject( srcdc, hOleBitmap );
888 destdc = CreateCompatibleDC( NULL );
889 hBitmap = CreateCompatibleBitmap( srcdc, cx, cy );
890 hOldDestBitmap = SelectObject( destdc, hBitmap );
891 StretchBlt( destdc, 0, 0, cx, cy,
892 srcdc, 0, 0, bm.bmWidth, bm.bmHeight, SRCCOPY);
893 SelectObject( srcdc, hOldSrcBitmap );
894 SelectObject( destdc, hOldDestBitmap );
900 IPicture_Release( pic );
904 static UINT msi_dialog_bitmap_control( msi_dialog *dialog, MSIRECORD *rec )
906 UINT cx, cy, flags, style, attributes;
907 msi_control *control;
910 flags = LR_LOADFROMFILE;
911 style = SS_BITMAP | SS_LEFT | WS_GROUP;
913 attributes = MSI_RecordGetInteger( rec, 8 );
914 if( attributes & msidbControlAttributesFixedSize )
916 flags |= LR_DEFAULTSIZE;
917 style |= SS_CENTERIMAGE;
920 control = msi_dialog_add_control( dialog, rec, szStatic, style );
921 cx = MSI_RecordGetInteger( rec, 6 );
922 cy = MSI_RecordGetInteger( rec, 7 );
923 cx = msi_dialog_scale_unit( dialog, cx );
924 cy = msi_dialog_scale_unit( dialog, cy );
926 text = msi_get_deformatted_field( dialog->package, rec, 10 );
927 control->hBitmap = msi_load_picture( dialog->package->db, text, cx, cy, flags );
928 if( control->hBitmap )
929 SendMessageW( control->hwnd, STM_SETIMAGE,
930 IMAGE_BITMAP, (LPARAM) control->hBitmap );
932 ERR("Failed to load bitmap %s\n", debugstr_w(text));
936 return ERROR_SUCCESS;
939 static UINT msi_dialog_icon_control( msi_dialog *dialog, MSIRECORD *rec )
941 msi_control *control;
947 control = msi_dialog_add_control( dialog, rec, szStatic,
948 SS_ICON | SS_CENTERIMAGE | WS_GROUP );
950 attributes = MSI_RecordGetInteger( rec, 8 );
951 text = msi_get_deformatted_field( dialog->package, rec, 10 );
952 control->hIcon = msi_load_icon( dialog->package->db, text, attributes );
954 SendMessageW( control->hwnd, STM_SETICON, (WPARAM) control->hIcon, 0 );
956 ERR("Failed to load bitmap %s\n", debugstr_w(text));
958 return ERROR_SUCCESS;
961 static UINT msi_dialog_combo_control( msi_dialog *dialog, MSIRECORD *rec )
963 static const WCHAR szCombo[] = { 'C','O','M','B','O','B','O','X',0 };
965 msi_dialog_add_control( dialog, rec, szCombo,
966 SS_BITMAP | SS_LEFT | SS_CENTERIMAGE );
967 return ERROR_SUCCESS;
970 static UINT msi_dialog_edit_control( msi_dialog *dialog, MSIRECORD *rec )
972 msi_control *control;
976 control = msi_dialog_add_control( dialog, rec, szEdit,
977 WS_BORDER | WS_TABSTOP );
978 control->handler = msi_dialog_edit_handler;
979 prop = MSI_RecordGetString( rec, 9 );
981 control->property = strdupW( prop );
982 val = msi_dup_property( dialog->package, control->property );
983 SetWindowTextW( control->hwnd, val );
985 return ERROR_SUCCESS;
988 /******************** Masked Edit ********************************************/
990 #define MASK_MAX_GROUPS 10
992 struct msi_mask_group
1000 struct msi_maskedit_info
1008 struct msi_mask_group group[MASK_MAX_GROUPS];
1011 static BOOL msi_mask_editable( WCHAR type )
1026 static void msi_mask_control_change( struct msi_maskedit_info *info )
1031 val = msi_alloc( (info->num_chars+1)*sizeof(WCHAR) );
1032 for( i=0, n=0; i<info->num_groups; i++ )
1034 if( (info->group[i].len + n) > info->num_chars )
1036 ERR("can't fit control %d text into template\n",i);
1039 if (!msi_mask_editable(info->group[i].type))
1041 for(r=0; r<info->group[i].len; r++)
1042 val[n+r] = info->group[i].type;
1047 r = GetWindowTextW( info->group[i].hwnd, &val[n], info->group[i].len+1 );
1048 if( r != info->group[i].len )
1054 TRACE("%d/%d controls were good\n", i, info->num_groups);
1056 if( i == info->num_groups )
1058 TRACE("Set property %s to %s\n",
1059 debugstr_w(info->prop), debugstr_w(val) );
1060 CharUpperBuffW( val, info->num_chars );
1061 MSI_SetPropertyW( info->dialog->package, info->prop, val );
1062 msi_dialog_evaluate_control_conditions( info->dialog );
1067 /* now move to the next control if necessary */
1068 static VOID msi_mask_next_control( struct msi_maskedit_info *info, HWND hWnd )
1073 for( i=0; i<info->num_groups; i++ )
1074 if( info->group[i].hwnd == hWnd )
1077 /* don't move from the last control */
1078 if( i >= (info->num_groups-1) )
1081 len = SendMessageW( hWnd, WM_GETTEXTLENGTH, 0, 0 );
1082 if( len < info->group[i].len )
1085 hWndNext = GetNextDlgTabItem( GetParent( hWnd ), hWnd, FALSE );
1086 SetFocus( hWndNext );
1089 static LRESULT WINAPI
1090 MSIMaskedEdit_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
1092 struct msi_maskedit_info *info;
1095 TRACE("%p %04x %08x %08lx\n", hWnd, msg, wParam, lParam);
1097 info = GetPropW(hWnd, szButtonData);
1099 r = CallWindowProcW(info->oldproc, hWnd, msg, wParam, lParam);
1104 if (HIWORD(wParam) == EN_CHANGE)
1106 msi_mask_control_change( info );
1107 msi_mask_next_control( info, (HWND) lParam );
1111 msi_free( info->prop );
1113 RemovePropW( hWnd, szButtonData );
1120 /* fish the various bits of the property out and put them in the control */
1122 msi_maskedit_set_text( struct msi_maskedit_info *info, LPCWSTR text )
1128 for( i = 0; i < info->num_groups; i++ )
1130 if( info->group[i].len < lstrlenW( p ) )
1132 LPWSTR chunk = strdupW( p );
1133 chunk[ info->group[i].len ] = 0;
1134 SetWindowTextW( info->group[i].hwnd, chunk );
1139 SetWindowTextW( info->group[i].hwnd, p );
1142 p += info->group[i].len;
1146 static struct msi_maskedit_info * msi_dialog_parse_groups( LPCWSTR mask )
1148 struct msi_maskedit_info * info = NULL;
1149 int i = 0, n = 0, total = 0;
1152 TRACE("masked control, template %s\n", debugstr_w(mask));
1157 info = msi_alloc_zero( sizeof *info );
1161 p = strchrW(mask, '<');
1167 for( i=0; i<MASK_MAX_GROUPS; i++ )
1169 /* stop at the end of the string */
1170 if( p[0] == 0 || p[0] == '>' )
1173 /* count the number of the same identifier */
1174 for( n=0; p[n] == p[0]; n++ )
1176 info->group[i].ofs = total;
1177 info->group[i].type = p[0];
1181 total++; /* an extra not part of the group */
1183 info->group[i].len = n;
1188 TRACE("%d characters in %d groups\n", total, i );
1189 if( i == MASK_MAX_GROUPS )
1190 ERR("too many groups in PIDTemplate %s\n", debugstr_w(mask));
1192 info->num_chars = total;
1193 info->num_groups = i;
1199 msi_maskedit_create_children( struct msi_maskedit_info *info, LPCWSTR font )
1201 DWORD width, height, style, wx, ww;
1206 style = WS_CHILD | WS_BORDER | WS_VISIBLE | WS_TABSTOP | ES_AUTOHSCROLL;
1208 GetClientRect( info->hwnd, &rect );
1210 width = rect.right - rect.left;
1211 height = rect.bottom - rect.top;
1213 for( i = 0; i < info->num_groups; i++ )
1215 if (!msi_mask_editable( info->group[i].type ))
1217 wx = (info->group[i].ofs * width) / info->num_chars;
1218 ww = (info->group[i].len * width) / info->num_chars;
1220 hwnd = CreateWindowW( szEdit, NULL, style, wx, 0, ww, height,
1221 info->hwnd, NULL, NULL, NULL );
1224 ERR("failed to create mask edit sub window\n");
1228 SendMessageW( hwnd, EM_LIMITTEXT, info->group[i].len, 0 );
1230 msi_dialog_set_font( info->dialog, hwnd,
1231 font?font:info->dialog->default_font );
1232 info->group[i].hwnd = hwnd;
1237 * office 2003 uses "73931<````=````=````=````=`````>@@@@@"
1238 * delphi 7 uses "<????-??????-??????-????>" and "<???-???>"
1239 * filemaker pro 7 uses "<^^^^=^^^^=^^^^=^^^^=^^^^=^^^^=^^^^^>"
1241 static UINT msi_dialog_maskedit_control( msi_dialog *dialog, MSIRECORD *rec )
1243 LPWSTR font_mask, val = NULL, font;
1244 struct msi_maskedit_info *info = NULL;
1245 UINT ret = ERROR_SUCCESS;
1246 msi_control *control;
1251 font_mask = msi_get_deformatted_field( dialog->package, rec, 10 );
1252 font = msi_dialog_get_style( font_mask, &mask );
1255 ERR("mask template is empty\n");
1259 info = msi_dialog_parse_groups( mask );
1262 ERR("template %s is invalid\n", debugstr_w(mask));
1266 info->dialog = dialog;
1268 control = msi_dialog_add_control( dialog, rec, szStatic,
1269 SS_OWNERDRAW | WS_GROUP | WS_VISIBLE );
1272 ERR("Failed to create maskedit container\n");
1273 ret = ERROR_FUNCTION_FAILED;
1276 SetWindowLongPtrW( control->hwnd, GWL_EXSTYLE, WS_EX_CONTROLPARENT );
1278 info->hwnd = control->hwnd;
1280 /* subclass the static control */
1281 info->oldproc = (WNDPROC) SetWindowLongPtrW( info->hwnd, GWLP_WNDPROC,
1282 (LONG_PTR)MSIMaskedEdit_WndProc );
1283 SetPropW( control->hwnd, szButtonData, info );
1285 prop = MSI_RecordGetString( rec, 9 );
1287 info->prop = strdupW( prop );
1289 msi_maskedit_create_children( info, font );
1293 val = msi_dup_property( dialog->package, prop );
1296 msi_maskedit_set_text( info, val );
1302 if( ret != ERROR_SUCCESS )
1304 msi_free( font_mask );
1309 /******************** Progress Bar *****************************************/
1311 static UINT msi_dialog_progress_bar( msi_dialog *dialog, MSIRECORD *rec )
1313 msi_dialog_add_control( dialog, rec, PROGRESS_CLASSW, WS_VISIBLE );
1314 return ERROR_SUCCESS;
1317 /******************** Path Edit ********************************************/
1319 static UINT msi_dialog_pathedit_control( msi_dialog *dialog, MSIRECORD *rec )
1321 FIXME("not implemented properly\n");
1322 return msi_dialog_edit_control( dialog, rec );
1325 /* radio buttons are a bit different from normal controls */
1326 static UINT msi_dialog_create_radiobutton( MSIRECORD *rec, LPVOID param )
1328 radio_button_group_descr *group = (radio_button_group_descr *)param;
1329 msi_dialog *dialog = group->dialog;
1330 msi_control *control;
1331 LPCWSTR prop, text, name;
1332 DWORD style, attributes = group->attributes;
1334 style = WS_CHILD | BS_AUTORADIOBUTTON | BS_MULTILINE | WS_TABSTOP;
1335 name = MSI_RecordGetString( rec, 3 );
1336 text = MSI_RecordGetString( rec, 8 );
1337 if( attributes & 1 )
1338 style |= WS_VISIBLE;
1339 if( ~attributes & 2 )
1340 style |= WS_DISABLED;
1342 control = msi_dialog_create_window( dialog, rec, 0, szButton, name, text,
1343 style, group->parent->hwnd );
1345 return ERROR_FUNCTION_FAILED;
1346 control->handler = msi_dialog_radiogroup_handler;
1348 if (!lstrcmpW(control->name, group->propval))
1349 SendMessageW(control->hwnd, BM_SETCHECK, BST_CHECKED, 0);
1351 prop = MSI_RecordGetString( rec, 1 );
1353 control->property = strdupW( prop );
1355 return ERROR_SUCCESS;
1358 static UINT msi_dialog_radiogroup_control( msi_dialog *dialog, MSIRECORD *rec )
1360 static const WCHAR query[] = {
1361 'S','E','L','E','C','T',' ','*',' ',
1362 'F','R','O','M',' ','R','a','d','i','o','B','u','t','t','o','n',' ',
1363 'W','H','E','R','E',' ',
1364 '`','P','r','o','p','e','r','t','y','`',' ','=',' ','\'','%','s','\'',0};
1367 msi_control *control;
1368 MSIQUERY *view = NULL;
1369 radio_button_group_descr group;
1370 MSIPACKAGE *package = dialog->package;
1373 prop = MSI_RecordGetString( rec, 9 );
1375 TRACE("%p %p %s\n", dialog, rec, debugstr_w( prop ));
1377 /* Create parent group box to hold radio buttons */
1378 control = msi_dialog_add_control( dialog, rec, szButton, BS_OWNERDRAW|WS_GROUP );
1380 return ERROR_FUNCTION_FAILED;
1382 oldproc = (WNDPROC) SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
1383 (LONG_PTR)MSIRadioGroup_WndProc );
1384 SetPropW(control->hwnd, szButtonData, oldproc);
1385 SetWindowLongPtrW( control->hwnd, GWL_EXSTYLE, WS_EX_CONTROLPARENT );
1388 control->property = strdupW( prop );
1390 /* query the Radio Button table for all control in this group */
1391 r = MSI_OpenQuery( package->db, &view, query, prop );
1392 if( r != ERROR_SUCCESS )
1394 ERR("query failed for dialog %s radio group %s\n",
1395 debugstr_w(dialog->name), debugstr_w(prop));
1396 return ERROR_INVALID_PARAMETER;
1399 group.dialog = dialog;
1400 group.parent = control;
1401 group.attributes = MSI_RecordGetInteger( rec, 8 );
1402 group.propval = msi_dup_property( dialog->package, control->property );
1404 r = MSI_IterateRecords( view, 0, msi_dialog_create_radiobutton, &group );
1405 msiobj_release( &view->hdr );
1406 msi_free( group.propval );
1411 /******************** Selection Tree ***************************************/
1413 struct msi_selection_tree_info
1421 msi_seltree_sync_item_state( HWND hwnd, MSIFEATURE *feature, HTREEITEM hItem )
1425 TRACE("Feature %s -> %d %d %d\n", debugstr_w(feature->Title),
1426 feature->Installed, feature->Action, feature->ActionRequest);
1428 tvi.mask = TVIF_STATE;
1430 tvi.state = INDEXTOSTATEIMAGEMASK( feature->Action );
1431 tvi.stateMask = TVIS_STATEIMAGEMASK;
1433 SendMessageW( hwnd, TVM_SETITEMW, 0, (LPARAM) &tvi );
1437 msi_seltree_popup_menu( HWND hwnd, INT x, INT y )
1442 /* create a menu to display */
1443 hMenu = CreatePopupMenu();
1445 /* FIXME: load strings from resources */
1446 AppendMenuA( hMenu, MF_ENABLED, INSTALLSTATE_LOCAL, "Install feature locally");
1447 AppendMenuA( hMenu, MF_GRAYED, 0x1000, "Install entire feature");
1448 AppendMenuA( hMenu, MF_ENABLED, INSTALLSTATE_ADVERTISED, "Install on demand");
1449 AppendMenuA( hMenu, MF_ENABLED, INSTALLSTATE_ABSENT, "Don't install");
1450 r = TrackPopupMenu( hMenu, TPM_LEFTALIGN | TPM_TOPALIGN | TPM_RETURNCMD,
1451 x, y, 0, hwnd, NULL );
1452 DestroyMenu( hMenu );
1457 msi_seltree_feature_from_item( HWND hwnd, HTREEITEM hItem )
1461 /* get the feature from the item */
1462 memset( &tvi, 0, sizeof tvi );
1464 tvi.mask = TVIF_PARAM | TVIF_HANDLE;
1465 SendMessageW( hwnd, TVM_GETITEMW, 0, (LPARAM) &tvi );
1467 return (MSIFEATURE*) tvi.lParam;
1471 msi_seltree_menu( HWND hwnd, HTREEITEM hItem )
1473 MSIFEATURE *feature;
1481 feature = msi_seltree_feature_from_item( hwnd, hItem );
1484 ERR("item %p feature was NULL\n", hItem);
1488 /* get the item's rectangle to put the menu just below it */
1490 SendMessageW( hwnd, TVM_GETITEMRECT, 0, (LPARAM) &u.rc );
1491 MapWindowPoints( hwnd, NULL, u.pt, 2 );
1493 r = msi_seltree_popup_menu( hwnd, u.rc.left, u.rc.top );
1497 case INSTALLSTATE_LOCAL:
1498 case INSTALLSTATE_ADVERTISED:
1499 case INSTALLSTATE_ABSENT:
1500 feature->ActionRequest = r;
1501 feature->Action = r;
1504 FIXME("select feature and all children\n");
1508 msi_seltree_sync_item_state( hwnd, feature, hItem );
1513 static LRESULT WINAPI
1514 MSISelectionTree_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
1516 struct msi_selection_tree_info *info;
1517 TVHITTESTINFO tvhti;
1520 TRACE("%p %04x %08x %08lx\n", hWnd, msg, wParam, lParam);
1522 info = GetPropW(hWnd, szButtonData);
1526 case WM_LBUTTONDOWN:
1527 tvhti.pt.x = LOWORD( lParam );
1528 tvhti.pt.y = HIWORD( lParam );
1531 r = CallWindowProcW(info->oldproc, hWnd, TVM_HITTEST, 0, (LPARAM) &tvhti );
1532 if (tvhti.flags & TVHT_ONITEMSTATEICON)
1533 return msi_seltree_menu( hWnd, tvhti.hItem );
1537 r = CallWindowProcW(info->oldproc, hWnd, msg, wParam, lParam);
1543 RemovePropW( hWnd, szButtonData );
1550 msi_seltree_add_child_features( MSIPACKAGE *package, HWND hwnd,
1551 LPCWSTR parent, HTREEITEM hParent )
1553 MSIFEATURE *feature;
1554 TVINSERTSTRUCTW tvis;
1557 LIST_FOR_EACH_ENTRY( feature, &package->features, MSIFEATURE, entry )
1559 if ( lstrcmpW( parent, feature->Feature_Parent ) )
1562 if ( !feature->Title )
1565 memset( &tvis, 0, sizeof tvis );
1566 tvis.hParent = hParent;
1567 tvis.hInsertAfter = TVI_SORT;
1568 tvis.u.item.mask = TVIF_TEXT | TVIF_PARAM;
1569 tvis.u.item.pszText = feature->Title;
1570 tvis.u.item.lParam = (LPARAM) feature;
1572 hitem = (HTREEITEM) SendMessageW( hwnd, TVM_INSERTITEMW, 0, (LPARAM) &tvis );
1576 msi_seltree_sync_item_state( hwnd, feature, hitem );
1577 msi_seltree_add_child_features( package, hwnd,
1578 feature->Feature, hitem );
1582 static void msi_seltree_create_imagelist( HWND hwnd )
1584 const int bm_width = 32, bm_height = 16, bm_count = 3;
1585 const int bm_resource = 0x1001;
1590 himl = ImageList_Create( bm_width, bm_height, FALSE, 4, 0 );
1593 ERR("failed to create image list\n");
1597 for (i=0; i<bm_count; i++)
1599 hbmp = LoadBitmapW( msi_hInstance, MAKEINTRESOURCEW(i+bm_resource) );
1602 ERR("failed to load bitmap %d\n", i);
1607 * Add a dummy bitmap at offset zero because the treeview
1608 * can't use it as a state mask (zero means no user state).
1611 ImageList_Add( himl, hbmp, NULL );
1613 ImageList_Add( himl, hbmp, NULL );
1616 SendMessageW( hwnd, TVM_SETIMAGELIST, TVSIL_STATE, (LPARAM)himl );
1619 static UINT msi_dialog_selection_tree( msi_dialog *dialog, MSIRECORD *rec )
1621 msi_control *control;
1623 MSIPACKAGE *package = dialog->package;
1625 struct msi_selection_tree_info *info;
1627 info = msi_alloc( sizeof *info );
1629 return ERROR_FUNCTION_FAILED;
1631 /* create the treeview control */
1632 prop = MSI_RecordGetString( rec, 9 );
1633 style = TVS_HASLINES | TVS_HASBUTTONS | TVS_LINESATROOT;
1634 style |= WS_GROUP | WS_VSCROLL;
1635 control = msi_dialog_add_control( dialog, rec, WC_TREEVIEWW, style );
1639 return ERROR_FUNCTION_FAILED;
1643 info->dialog = dialog;
1644 info->hwnd = control->hwnd;
1645 info->oldproc = (WNDPROC) SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
1646 (LONG_PTR)MSISelectionTree_WndProc );
1647 SetPropW( control->hwnd, szButtonData, info );
1650 msi_seltree_create_imagelist( control->hwnd );
1651 msi_seltree_add_child_features( package, control->hwnd, NULL, NULL );
1653 return ERROR_SUCCESS;
1656 struct control_handler msi_dialog_handler[] =
1658 { szText, msi_dialog_text_control },
1659 { szPushButton, msi_dialog_button_control },
1660 { szLine, msi_dialog_line_control },
1661 { szBitmap, msi_dialog_bitmap_control },
1662 { szCheckBox, msi_dialog_checkbox_control },
1663 { szScrollableText, msi_dialog_scrolltext_control },
1664 { szComboBox, msi_dialog_combo_control },
1665 { szEdit, msi_dialog_edit_control },
1666 { szMaskedEdit, msi_dialog_maskedit_control },
1667 { szPathEdit, msi_dialog_pathedit_control },
1668 { szProgressBar, msi_dialog_progress_bar },
1669 { szRadioButtonGroup, msi_dialog_radiogroup_control },
1670 { szIcon, msi_dialog_icon_control },
1671 { szSelectionTree, msi_dialog_selection_tree },
1674 #define NUM_CONTROL_TYPES (sizeof msi_dialog_handler/sizeof msi_dialog_handler[0])
1676 static UINT msi_dialog_create_controls( MSIRECORD *rec, LPVOID param )
1678 msi_dialog *dialog = param;
1679 LPCWSTR control_type;
1682 /* find and call the function that can create this type of control */
1683 control_type = MSI_RecordGetString( rec, 3 );
1684 for( i=0; i<NUM_CONTROL_TYPES; i++ )
1685 if (!strcmpiW( msi_dialog_handler[i].control_type, control_type ))
1687 if( i != NUM_CONTROL_TYPES )
1688 msi_dialog_handler[i].func( dialog, rec );
1690 ERR("no handler for element type %s\n", debugstr_w(control_type));
1692 return ERROR_SUCCESS;
1695 static UINT msi_dialog_fill_controls( msi_dialog *dialog )
1697 static const WCHAR query[] = {
1698 'S','E','L','E','C','T',' ','*',' ',
1699 'F','R','O','M',' ','C','o','n','t','r','o','l',' ',
1700 'W','H','E','R','E',' ',
1701 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',0};
1703 MSIQUERY *view = NULL;
1704 MSIPACKAGE *package = dialog->package;
1706 TRACE("%p %s\n", dialog, debugstr_w(dialog->name) );
1708 /* query the Control table for all the elements of the control */
1709 r = MSI_OpenQuery( package->db, &view, query, dialog->name );
1710 if( r != ERROR_SUCCESS )
1712 ERR("query failed for dialog %s\n", debugstr_w(dialog->name));
1713 return ERROR_INVALID_PARAMETER;
1716 r = MSI_IterateRecords( view, 0, msi_dialog_create_controls, dialog );
1717 msiobj_release( &view->hdr );
1722 static UINT msi_dialog_set_control_condition( MSIRECORD *rec, LPVOID param )
1724 static const WCHAR szHide[] = { 'H','i','d','e',0 };
1725 static const WCHAR szShow[] = { 'S','h','o','w',0 };
1726 static const WCHAR szDisable[] = { 'D','i','s','a','b','l','e',0 };
1727 static const WCHAR szEnable[] = { 'E','n','a','b','l','e',0 };
1728 msi_dialog *dialog = param;
1729 msi_control *control;
1730 LPCWSTR name, action, condition;
1733 name = MSI_RecordGetString( rec, 2 );
1734 action = MSI_RecordGetString( rec, 3 );
1735 condition = MSI_RecordGetString( rec, 4 );
1736 r = MSI_EvaluateConditionW( dialog->package, condition );
1737 control = msi_dialog_find_control( dialog, name );
1738 if( r == MSICONDITION_TRUE && control )
1740 TRACE("%s control %s\n", debugstr_w(action), debugstr_w(name));
1742 /* FIXME: case sensitive? */
1743 if(!lstrcmpW(action, szHide))
1744 ShowWindow(control->hwnd, SW_HIDE);
1745 else if(!strcmpW(action, szShow))
1746 ShowWindow(control->hwnd, SW_SHOW);
1747 else if(!strcmpW(action, szDisable))
1748 EnableWindow(control->hwnd, FALSE);
1749 else if(!strcmpW(action, szEnable))
1750 EnableWindow(control->hwnd, TRUE);
1752 FIXME("Unhandled action %s\n", debugstr_w(action));
1755 return ERROR_SUCCESS;
1758 static UINT msi_dialog_evaluate_control_conditions( msi_dialog *dialog )
1760 static const WCHAR query[] = {
1761 'S','E','L','E','C','T',' ','*',' ',
1762 'F','R','O','M',' ',
1763 'C','o','n','t','r','o','l','C','o','n','d','i','t','i','o','n',' ',
1764 'W','H','E','R','E',' ',
1765 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',0
1768 MSIQUERY *view = NULL;
1769 MSIPACKAGE *package = dialog->package;
1771 TRACE("%p %s\n", dialog, debugstr_w(dialog->name) );
1773 /* query the Control table for all the elements of the control */
1774 r = MSI_OpenQuery( package->db, &view, query, dialog->name );
1775 if( r != ERROR_SUCCESS )
1777 ERR("query failed for dialog %s\n", debugstr_w(dialog->name));
1778 return ERROR_INVALID_PARAMETER;
1781 r = MSI_IterateRecords( view, 0, msi_dialog_set_control_condition, dialog );
1782 msiobj_release( &view->hdr );
1787 UINT msi_dialog_reset( msi_dialog *dialog )
1789 /* FIXME: should restore the original values of any properties we changed */
1790 return msi_dialog_evaluate_control_conditions( dialog );
1793 /* figure out the height of 10 point MS Sans Serif */
1794 static INT msi_dialog_get_sans_serif_height( HWND hwnd )
1796 static const WCHAR szSansSerif[] = {
1797 'M','S',' ','S','a','n','s',' ','S','e','r','i','f',0 };
1802 HFONT hFont, hOldFont;
1805 hdc = GetDC( hwnd );
1808 memset( &lf, 0, sizeof lf );
1809 lf.lfHeight = MulDiv(10, GetDeviceCaps(hdc, LOGPIXELSY), 72);
1810 strcpyW( lf.lfFaceName, szSansSerif );
1811 hFont = CreateFontIndirectW(&lf);
1814 hOldFont = SelectObject( hdc, hFont );
1815 r = GetTextMetricsW( hdc, &tm );
1817 height = tm.tmHeight;
1818 SelectObject( hdc, hOldFont );
1819 DeleteObject( hFont );
1821 ReleaseDC( hwnd, hdc );
1826 /* fetch the associated record from the Dialog table */
1827 static MSIRECORD *msi_get_dialog_record( msi_dialog *dialog )
1829 static const WCHAR query[] = {
1830 'S','E','L','E','C','T',' ','*',' ',
1831 'F','R','O','M',' ','D','i','a','l','o','g',' ',
1832 'W','H','E','R','E',' ',
1833 '`','D','i','a','l','o','g','`',' ','=',' ','\'','%','s','\'',0};
1834 MSIPACKAGE *package = dialog->package;
1835 MSIRECORD *rec = NULL;
1837 TRACE("%p %s\n", dialog, debugstr_w(dialog->name) );
1839 rec = MSI_QueryGetRecord( package->db, query, dialog->name );
1841 ERR("query failed for dialog %s\n", debugstr_w(dialog->name));
1846 static void msi_dialog_adjust_dialog_size( msi_dialog *dialog, LPSIZE sz )
1851 /* turn the client size into the window rectangle */
1854 rect.right = msi_dialog_scale_unit( dialog, sz->cx );
1855 rect.bottom = msi_dialog_scale_unit( dialog, sz->cy );
1856 style = GetWindowLongPtrW( dialog->hwnd, GWL_STYLE );
1857 AdjustWindowRect( &rect, style, FALSE );
1858 sz->cx = rect.right - rect.left;
1859 sz->cy = rect.bottom - rect.top;
1862 static BOOL msi_control_set_next( msi_control *control, msi_control *next )
1864 return SetWindowPos( next->hwnd, control->hwnd, 0, 0, 0, 0,
1865 SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOREDRAW |
1866 SWP_NOREPOSITION | SWP_NOSENDCHANGING | SWP_NOSIZE );
1869 static UINT msi_dialog_set_tab_order( msi_dialog *dialog )
1871 msi_control *control, *tab_next;
1873 LIST_FOR_EACH_ENTRY( control, &dialog->controls, msi_control, entry )
1875 tab_next = msi_dialog_find_control( dialog, control->tabnext );
1878 msi_control_set_next( control, tab_next );
1881 return ERROR_SUCCESS;
1884 static void msi_dialog_set_first_control( msi_dialog* dialog, LPCWSTR name )
1886 msi_control *control;
1888 control = msi_dialog_find_control( dialog, name );
1890 dialog->hWndFocus = control->hwnd;
1892 dialog->hWndFocus = NULL;
1895 static LRESULT msi_dialog_oncreate( HWND hwnd, LPCREATESTRUCTW cs )
1897 static const WCHAR df[] = {
1898 'D','e','f','a','u','l','t','U','I','F','o','n','t',0 };
1899 static const WCHAR dfv[] = {
1900 'M','S',' ','S','h','e','l','l',' ','D','l','g',0 };
1901 msi_dialog *dialog = (msi_dialog*) cs->lpCreateParams;
1902 MSIRECORD *rec = NULL;
1903 LPWSTR title = NULL;
1906 TRACE("%p %p\n", dialog, dialog->package);
1908 dialog->hwnd = hwnd;
1909 SetWindowLongPtrW( hwnd, GWLP_USERDATA, (LONG_PTR) dialog );
1911 rec = msi_get_dialog_record( dialog );
1914 TRACE("No record found for dialog %s\n", debugstr_w(dialog->name));
1918 dialog->scale = msi_dialog_get_sans_serif_height(dialog->hwnd);
1920 size.cx = MSI_RecordGetInteger( rec, 4 );
1921 size.cy = MSI_RecordGetInteger( rec, 5 );
1922 msi_dialog_adjust_dialog_size( dialog, &size );
1924 dialog->attributes = MSI_RecordGetInteger( rec, 6 );
1926 dialog->default_font = msi_dup_property( dialog->package, df );
1927 if (!dialog->default_font)
1929 dialog->default_font = strdupW(dfv);
1930 if (!dialog->default_font) return -1;
1933 title = msi_get_deformatted_field( dialog->package, rec, 7 );
1934 SetWindowTextW( hwnd, title );
1937 SetWindowPos( hwnd, 0, 0, 0, size.cx, size.cy,
1938 SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOREDRAW );
1940 msi_dialog_build_font_list( dialog );
1941 msi_dialog_fill_controls( dialog );
1942 msi_dialog_evaluate_control_conditions( dialog );
1943 msi_dialog_set_tab_order( dialog );
1944 msi_dialog_set_first_control( dialog, MSI_RecordGetString( rec, 8 ) );
1945 msiobj_release( &rec->hdr );
1950 static UINT msi_dialog_send_event( msi_dialog *dialog, LPCWSTR event, LPCWSTR arg )
1952 LPWSTR event_fmt = NULL, arg_fmt = NULL;
1954 TRACE("Sending control event %s %s\n", debugstr_w(event), debugstr_w(arg));
1956 deformat_string( dialog->package, event, &event_fmt );
1957 deformat_string( dialog->package, arg, &arg_fmt );
1959 dialog->event_handler( dialog->package, event_fmt, arg_fmt, dialog );
1961 msi_free( event_fmt );
1962 msi_free( arg_fmt );
1964 return ERROR_SUCCESS;
1967 static UINT msi_dialog_set_property( msi_dialog *dialog, LPCWSTR event, LPCWSTR arg )
1969 static const WCHAR szNullArg[] = { '{','}',0 };
1970 LPWSTR p, prop, arg_fmt = NULL;
1973 len = strlenW(event);
1974 prop = msi_alloc( len*sizeof(WCHAR));
1975 strcpyW( prop, &event[1] );
1976 p = strchrW( prop, ']' );
1977 if( p && p[1] == 0 )
1980 if( strcmpW( szNullArg, arg ) )
1981 deformat_string( dialog->package, arg, &arg_fmt );
1982 MSI_SetPropertyW( dialog->package, prop, arg_fmt );
1983 msi_free( arg_fmt );
1986 ERR("Badly formatted property string - what happens?\n");
1988 return ERROR_SUCCESS;
1991 static UINT msi_dialog_control_event( MSIRECORD *rec, LPVOID param )
1993 msi_dialog *dialog = param;
1994 LPCWSTR condition, event, arg;
1997 condition = MSI_RecordGetString( rec, 5 );
1998 r = MSI_EvaluateConditionW( dialog->package, condition );
1999 if( r == MSICONDITION_TRUE || r == MSICONDITION_NONE )
2001 event = MSI_RecordGetString( rec, 3 );
2002 arg = MSI_RecordGetString( rec, 4 );
2003 if( event[0] == '[' )
2004 msi_dialog_set_property( dialog, event, arg );
2006 msi_dialog_send_event( dialog, event, arg );
2009 return ERROR_SUCCESS;
2012 static UINT msi_dialog_button_handler( msi_dialog *dialog,
2013 msi_control *control, WPARAM param )
2015 static const WCHAR query[] = {
2016 'S','E','L','E','C','T',' ','*',' ',
2017 'F','R','O','M',' ','C','o','n','t','r','o','l','E','v','e','n','t',' ',
2018 'W','H','E','R','E',' ',
2019 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',' ',
2021 '`','C','o','n','t','r','o','l','_','`',' ','=',' ','\'','%','s','\'',' ',
2022 'O','R','D','E','R',' ','B','Y',' ','`','O','r','d','e','r','i','n','g','`',0
2024 MSIQUERY *view = NULL;
2027 if( HIWORD(param) != BN_CLICKED )
2028 return ERROR_SUCCESS;
2030 r = MSI_OpenQuery( dialog->package->db, &view, query,
2031 dialog->name, control->name );
2032 if( r != ERROR_SUCCESS )
2034 ERR("query failed\n");
2038 r = MSI_IterateRecords( view, 0, msi_dialog_control_event, dialog );
2039 msiobj_release( &view->hdr );
2044 static UINT msi_dialog_get_checkbox_state( msi_dialog *dialog,
2045 msi_control *control )
2047 WCHAR state[2] = { 0 };
2050 MSI_GetPropertyW( dialog->package, control->property, state, &sz );
2051 return state[0] ? 1 : 0;
2054 static void msi_dialog_set_checkbox_state( msi_dialog *dialog,
2055 msi_control *control, UINT state )
2057 static const WCHAR szState[] = { '1', 0 };
2060 /* if uncheck then the property is set to NULL */
2063 MSI_SetPropertyW( dialog->package, control->property, NULL );
2067 /* check for a custom state */
2068 if (control->value && control->value[0])
2069 val = control->value;
2073 MSI_SetPropertyW( dialog->package, control->property, val );
2076 static void msi_dialog_checkbox_sync_state( msi_dialog *dialog,
2077 msi_control *control )
2081 state = msi_dialog_get_checkbox_state( dialog, control );
2082 SendMessageW( control->hwnd, BM_SETCHECK,
2083 state ? BST_CHECKED : BST_UNCHECKED, 0 );
2086 static UINT msi_dialog_checkbox_handler( msi_dialog *dialog,
2087 msi_control *control, WPARAM param )
2091 if( HIWORD(param) != BN_CLICKED )
2092 return ERROR_SUCCESS;
2094 TRACE("clicked checkbox %s, set %s\n", debugstr_w(control->name),
2095 debugstr_w(control->property));
2097 state = msi_dialog_get_checkbox_state( dialog, control );
2098 state = state ? 0 : 1;
2099 msi_dialog_set_checkbox_state( dialog, control, state );
2100 msi_dialog_checkbox_sync_state( dialog, control );
2102 return msi_dialog_button_handler( dialog, control, param );
2105 static UINT msi_dialog_edit_handler( msi_dialog *dialog,
2106 msi_control *control, WPARAM param )
2111 if( HIWORD(param) != EN_CHANGE )
2112 return ERROR_SUCCESS;
2114 TRACE("edit %s contents changed, set %s\n", debugstr_w(control->name),
2115 debugstr_w(control->property));
2118 buf = msi_alloc( sz*sizeof(WCHAR) );
2121 r = GetWindowTextW( control->hwnd, buf, sz );
2125 buf = msi_realloc( buf, sz*sizeof(WCHAR) );
2128 MSI_SetPropertyW( dialog->package, control->property, buf );
2132 return ERROR_SUCCESS;
2135 static UINT msi_dialog_radiogroup_handler( msi_dialog *dialog,
2136 msi_control *control, WPARAM param )
2138 if( HIWORD(param) != BN_CLICKED )
2139 return ERROR_SUCCESS;
2141 TRACE("clicked radio button %s, set %s\n", debugstr_w(control->name),
2142 debugstr_w(control->property));
2144 MSI_SetPropertyW( dialog->package, control->property, control->name );
2146 return msi_dialog_button_handler( dialog, control, param );
2149 static LRESULT msi_dialog_oncommand( msi_dialog *dialog, WPARAM param, HWND hwnd )
2151 msi_control *control = NULL;
2153 TRACE("%p %p %08x\n", dialog, hwnd, param);
2158 control = msi_dialog_find_control( dialog, dialog->control_default );
2160 case 2: /* escape */
2161 control = msi_dialog_find_control( dialog, dialog->control_cancel );
2164 control = msi_dialog_find_control_by_hwnd( dialog, hwnd );
2169 if( control->handler )
2171 control->handler( dialog, control, param );
2172 msi_dialog_evaluate_control_conditions( dialog );
2176 ERR("button click from nowhere %p %d %p\n", dialog, param, hwnd);
2180 static void msi_dialog_setfocus( msi_dialog *dialog )
2182 HWND hwnd = dialog->hWndFocus;
2184 hwnd = GetNextDlgTabItem( dialog->hwnd, hwnd, TRUE);
2185 hwnd = GetNextDlgTabItem( dialog->hwnd, hwnd, FALSE);
2187 dialog->hWndFocus = hwnd;
2190 static LRESULT WINAPI MSIDialog_WndProc( HWND hwnd, UINT msg,
2191 WPARAM wParam, LPARAM lParam )
2193 msi_dialog *dialog = (LPVOID) GetWindowLongPtrW( hwnd, GWLP_USERDATA );
2195 TRACE("0x%04x\n", msg);
2200 return msi_dialog_oncreate( hwnd, (LPCREATESTRUCTW)lParam );
2203 return msi_dialog_oncommand( dialog, wParam, (HWND)lParam );
2206 if( LOWORD(wParam) == WA_INACTIVE )
2207 dialog->hWndFocus = GetFocus();
2209 msi_dialog_setfocus( dialog );
2213 msi_dialog_setfocus( dialog );
2216 /* bounce back to our subclassed static control */
2217 case WM_CTLCOLORSTATIC:
2218 return SendMessageW( (HWND) lParam, WM_CTLCOLORSTATIC, wParam, lParam );
2221 dialog->hwnd = NULL;
2224 return DefWindowProcW(hwnd, msg, wParam, lParam);
2227 static BOOL CALLBACK msi_radioground_child_enum( HWND hWnd, LPARAM lParam )
2229 EnableWindow( hWnd, lParam );
2233 static LRESULT WINAPI MSIRadioGroup_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
2235 WNDPROC oldproc = (WNDPROC) GetPropW(hWnd, szButtonData);
2238 TRACE("hWnd %p msg %04x wParam 0x%08x lParam 0x%08lx\n", hWnd, msg, wParam, lParam);
2240 if (msg == WM_COMMAND) /* Forward notifications to dialog */
2241 SendMessageW(GetParent(hWnd), msg, wParam, lParam);
2243 r = CallWindowProcW(oldproc, hWnd, msg, wParam, lParam);
2245 /* make sure the radio buttons show as disabled if the parent is disabled */
2246 if (msg == WM_ENABLE)
2247 EnumChildWindows( hWnd, msi_radioground_child_enum, wParam );
2252 static LRESULT WINAPI MSIHiddenWindowProc( HWND hwnd, UINT msg,
2253 WPARAM wParam, LPARAM lParam )
2255 msi_dialog *dialog = (msi_dialog*) lParam;
2257 TRACE("%d %p\n", msg, dialog);
2261 case WM_MSI_DIALOG_CREATE:
2262 return msi_dialog_run_message_loop( dialog );
2263 case WM_MSI_DIALOG_DESTROY:
2264 msi_dialog_destroy( dialog );
2267 return DefWindowProcW( hwnd, msg, wParam, lParam );
2270 /* functions that interface to other modules within MSI */
2272 msi_dialog *msi_dialog_create( MSIPACKAGE* package, LPCWSTR szDialogName,
2273 msi_dialog_event_handler event_handler )
2275 MSIRECORD *rec = NULL;
2278 TRACE("%p %s\n", package, debugstr_w(szDialogName));
2280 /* allocate the structure for the dialog to use */
2281 dialog = msi_alloc_zero( sizeof *dialog + sizeof(WCHAR)*strlenW(szDialogName) );
2284 strcpyW( dialog->name, szDialogName );
2285 msiobj_addref( &package->hdr );
2286 dialog->package = package;
2287 dialog->event_handler = event_handler;
2288 dialog->finished = 0;
2289 list_init( &dialog->controls );
2291 /* verify that the dialog exists */
2292 rec = msi_get_dialog_record( dialog );
2295 msiobj_release( &package->hdr );
2299 dialog->attributes = MSI_RecordGetInteger( rec, 6 );
2300 dialog->control_default = strdupW( MSI_RecordGetString( rec, 9 ) );
2301 dialog->control_cancel = strdupW( MSI_RecordGetString( rec, 10 ) );
2302 msiobj_release( &rec->hdr );
2307 static void msi_process_pending_messages( HWND hdlg )
2311 while( PeekMessageW( &msg, 0, 0, 0, PM_REMOVE ) )
2313 if( hdlg && IsDialogMessageW( hdlg, &msg ))
2315 TranslateMessage( &msg );
2316 DispatchMessageW( &msg );
2320 void msi_dialog_end_dialog( msi_dialog *dialog )
2322 TRACE("%p\n", dialog);
2323 dialog->finished = 1;
2324 PostMessageW(dialog->hwnd, WM_NULL, 0, 0);
2327 void msi_dialog_check_messages( HANDLE handle )
2331 /* in threads other than the UI thread, block */
2332 if( uiThreadId != GetCurrentThreadId() )
2335 WaitForSingleObject( handle, INFINITE );
2339 /* there's two choices for the UI thread */
2342 msi_process_pending_messages( NULL );
2348 * block here until somebody creates a new dialog or
2349 * the handle we're waiting on becomes ready
2351 r = MsgWaitForMultipleObjects( 1, &handle, 0, INFINITE, QS_ALLINPUT );
2352 if( r == WAIT_OBJECT_0 )
2357 UINT msi_dialog_run_message_loop( msi_dialog *dialog )
2362 if( uiThreadId != GetCurrentThreadId() )
2363 return SendMessageW( hMsiHiddenWindow, WM_MSI_DIALOG_CREATE, 0, (LPARAM) dialog );
2365 /* create the dialog window, don't show it yet */
2366 style = WS_OVERLAPPED;
2367 if( dialog->attributes & msidbDialogAttributesVisible )
2368 style |= WS_VISIBLE;
2370 hwnd = CreateWindowW( szMsiDialogClass, dialog->name, style,
2371 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
2372 NULL, NULL, NULL, dialog );
2375 ERR("Failed to create dialog %s\n", debugstr_w( dialog->name ));
2376 return ERROR_FUNCTION_FAILED;
2379 ShowWindow( hwnd, SW_SHOW );
2380 /* UpdateWindow( hwnd ); - and causes the transparent static controls not to paint */
2382 if( dialog->attributes & msidbDialogAttributesModal )
2384 while( !dialog->finished )
2386 MsgWaitForMultipleObjects( 0, NULL, 0, INFINITE, QS_ALLEVENTS );
2387 msi_process_pending_messages( dialog->hwnd );
2391 return ERROR_IO_PENDING;
2393 return ERROR_SUCCESS;
2396 void msi_dialog_do_preview( msi_dialog *dialog )
2399 dialog->attributes |= msidbDialogAttributesVisible;
2400 dialog->attributes &= ~msidbDialogAttributesModal;
2401 msi_dialog_run_message_loop( dialog );
2404 void msi_dialog_destroy( msi_dialog *dialog )
2406 if( uiThreadId != GetCurrentThreadId() )
2408 SendMessageW( hMsiHiddenWindow, WM_MSI_DIALOG_DESTROY, 0, (LPARAM) dialog );
2413 ShowWindow( dialog->hwnd, SW_HIDE );
2416 DestroyWindow( dialog->hwnd );
2418 /* destroy the list of controls */
2419 while( !list_empty( &dialog->controls ) )
2421 msi_control *t = LIST_ENTRY( list_head( &dialog->controls ),
2422 msi_control, entry );
2423 list_remove( &t->entry );
2424 /* leave dialog->hwnd - destroying parent destroys child windows */
2425 msi_free( t->property );
2426 msi_free( t->value );
2428 DeleteObject( t->hBitmap );
2430 DestroyIcon( t->hIcon );
2431 msi_free( t->tabnext );
2434 FreeLibrary( t->hDll );
2437 /* destroy the list of fonts */
2438 while( dialog->font_list )
2440 msi_font *t = dialog->font_list;
2441 dialog->font_list = t->next;
2442 DeleteObject( t->hfont );
2445 msi_free( dialog->default_font );
2447 msi_free( dialog->control_default );
2448 msi_free( dialog->control_cancel );
2449 msiobj_release( &dialog->package->hdr );
2450 dialog->package = NULL;
2454 BOOL msi_dialog_register_class( void )
2458 ZeroMemory( &cls, sizeof cls );
2459 cls.lpfnWndProc = MSIDialog_WndProc;
2460 cls.hInstance = NULL;
2461 cls.hIcon = LoadIconW(0, (LPWSTR)IDI_APPLICATION);
2462 cls.hCursor = LoadCursorW(0, (LPWSTR)IDC_ARROW);
2463 cls.hbrBackground = (HBRUSH)(COLOR_3DFACE + 1);
2464 cls.lpszMenuName = NULL;
2465 cls.lpszClassName = szMsiDialogClass;
2467 if( !RegisterClassW( &cls ) )
2470 cls.lpfnWndProc = MSIHiddenWindowProc;
2471 cls.lpszClassName = szMsiHiddenWindow;
2473 if( !RegisterClassW( &cls ) )
2476 uiThreadId = GetCurrentThreadId();
2478 hMsiHiddenWindow = CreateWindowW( szMsiHiddenWindow, NULL, WS_OVERLAPPED,
2479 0, 0, 100, 100, NULL, NULL, NULL, NULL );
2480 if( !hMsiHiddenWindow )
2486 void msi_dialog_unregister_class( void )
2488 DestroyWindow( hMsiHiddenWindow );
2489 hMsiHiddenWindow = NULL;
2490 UnregisterClassW( szMsiDialogClass, NULL );
2491 UnregisterClassW( szMsiHiddenWindow, NULL );