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
42 #include "wine/debug.h"
43 #include "wine/unicode.h"
47 WINE_DEFAULT_DEBUG_CHANNEL(msi);
50 extern HINSTANCE msi_hInstance;
52 struct msi_control_tag;
53 typedef struct msi_control_tag msi_control;
54 typedef UINT (*msi_handler)( msi_dialog *, msi_control *, WPARAM );
56 struct msi_control_tag
67 float progress_current;
73 typedef struct msi_font_tag
75 struct msi_font_tag *next;
84 msi_dialog_event_handler event_handler;
93 LPWSTR control_default;
94 LPWSTR control_cancel;
98 typedef UINT (*msi_dialog_control_func)( msi_dialog *dialog, MSIRECORD *rec );
99 struct control_handler
101 LPCWSTR control_type;
102 msi_dialog_control_func func;
111 } radio_button_group_descr;
113 static const WCHAR szMsiDialogClass[] = {
114 'M','s','i','D','i','a','l','o','g','C','l','o','s','e','C','l','a','s','s',0
116 static const WCHAR szMsiHiddenWindow[] = {
117 'M','s','i','H','i','d','d','e','n','W','i','n','d','o','w',0 };
118 static const WCHAR szStatic[] = { 'S','t','a','t','i','c',0 };
119 static const WCHAR szButton[] = { 'B','U','T','T','O','N', 0 };
120 static const WCHAR szButtonData[] = { 'M','S','I','D','A','T','A',0 };
121 static const WCHAR szProgress[] = { 'P','r','o','g','r','e','s','s',0 };
122 static const WCHAR szText[] = { 'T','e','x','t',0 };
123 static const WCHAR szPushButton[] = { 'P','u','s','h','B','u','t','t','o','n',0 };
124 static const WCHAR szLine[] = { 'L','i','n','e',0 };
125 static const WCHAR szBitmap[] = { 'B','i','t','m','a','p',0 };
126 static const WCHAR szCheckBox[] = { 'C','h','e','c','k','B','o','x',0 };
127 static const WCHAR szScrollableText[] = {
128 'S','c','r','o','l','l','a','b','l','e','T','e','x','t',0 };
129 static const WCHAR szComboBox[] = { 'C','o','m','b','o','B','o','x',0 };
130 static const WCHAR szEdit[] = { 'E','d','i','t',0 };
131 static const WCHAR szMaskedEdit[] = { 'M','a','s','k','e','d','E','d','i','t',0 };
132 static const WCHAR szPathEdit[] = { 'P','a','t','h','E','d','i','t',0 };
133 static const WCHAR szProgressBar[] = {
134 'P','r','o','g','r','e','s','s','B','a','r',0 };
135 static const WCHAR szRadioButtonGroup[] = {
136 'R','a','d','i','o','B','u','t','t','o','n','G','r','o','u','p',0 };
137 static const WCHAR szIcon[] = { 'I','c','o','n',0 };
138 static const WCHAR szSelectionTree[] = {
139 'S','e','l','e','c','t','i','o','n','T','r','e','e',0 };
140 static const WCHAR szGroupBox[] = { 'G','r','o','u','p','B','o','x',0 };
141 static const WCHAR szListBox[] = { 'L','i','s','t','B','o','x',0 };
142 static const WCHAR szDirectoryCombo[] = { 'D','i','r','e','c','t','o','r','y','C','o','m','b','o',0 };
143 static const WCHAR szDirectoryList[] = { 'D','i','r','e','c','t','o','r','y','L','i','s','t',0 };
144 static const WCHAR szVolumeCostList[] = { 'V','o','l','u','m','e','C','o','s','t','L','i','s','t',0 };
146 static UINT msi_dialog_checkbox_handler( msi_dialog *, msi_control *, WPARAM );
147 static void msi_dialog_checkbox_sync_state( msi_dialog *, msi_control * );
148 static UINT msi_dialog_button_handler( msi_dialog *, msi_control *, WPARAM );
149 static UINT msi_dialog_edit_handler( msi_dialog *, msi_control *, WPARAM );
150 static UINT msi_dialog_radiogroup_handler( msi_dialog *, msi_control *, WPARAM param );
151 static UINT msi_dialog_evaluate_control_conditions( msi_dialog *dialog );
152 static LRESULT WINAPI MSIRadioGroup_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
155 /* dialog sequencing */
157 #define WM_MSI_DIALOG_CREATE (WM_USER+0x100)
158 #define WM_MSI_DIALOG_DESTROY (WM_USER+0x101)
160 static DWORD uiThreadId;
161 static HWND hMsiHiddenWindow;
163 static INT msi_dialog_scale_unit( msi_dialog *dialog, INT val )
165 return (dialog->scale * val + 5) / 10;
168 static msi_control *msi_dialog_find_control( msi_dialog *dialog, LPCWSTR name )
170 msi_control *control;
174 LIST_FOR_EACH_ENTRY( control, &dialog->controls, msi_control, entry )
175 if( !strcmpW( control->name, name ) ) /* FIXME: case sensitive? */
180 static msi_control *msi_dialog_find_control_by_hwnd( msi_dialog *dialog, HWND hwnd )
182 msi_control *control;
184 LIST_FOR_EACH_ENTRY( control, &dialog->controls, msi_control, entry )
185 if( hwnd == control->hwnd )
190 static LPWSTR msi_get_deformatted_field( MSIPACKAGE *package, MSIRECORD *rec, int field )
192 LPCWSTR str = MSI_RecordGetString( rec, field );
196 deformat_string( package, str, &ret );
201 * msi_dialog_get_style
203 * Extract the {\style} string from the front of the text to display and
204 * update the pointer.
206 static LPWSTR msi_dialog_get_style( LPCWSTR p, LPCWSTR *rest )
217 q = strchrW( p, '}' );
220 if( *p == '\\' || *p == '&' )
223 /* little bit of sanity checking to stop us getting confused with RTF */
225 if( *i == '}' || *i == '\\' )
231 ret = msi_alloc( len*sizeof(WCHAR) );
234 memcpy( ret, p, len*sizeof(WCHAR) );
239 static UINT msi_dialog_add_font( MSIRECORD *rec, LPVOID param )
241 msi_dialog *dialog = param;
248 /* create a font and add it to the list */
249 name = MSI_RecordGetString( rec, 1 );
250 font = msi_alloc( sizeof *font + strlenW( name )*sizeof (WCHAR) );
251 strcpyW( font->name, name );
252 font->next = dialog->font_list;
253 dialog->font_list = font;
255 font->color = MSI_RecordGetInteger( rec, 4 );
257 memset( &lf, 0, sizeof lf );
258 face = MSI_RecordGetString( rec, 2 );
259 lf.lfHeight = MSI_RecordGetInteger( rec, 3 );
260 style = MSI_RecordGetInteger( rec, 5 );
261 if( style & msidbTextStyleStyleBitsBold )
262 lf.lfWeight = FW_BOLD;
263 if( style & msidbTextStyleStyleBitsItalic )
265 if( style & msidbTextStyleStyleBitsUnderline )
266 lf.lfUnderline = TRUE;
267 if( style & msidbTextStyleStyleBitsStrike )
268 lf.lfStrikeOut = TRUE;
269 lstrcpynW( lf.lfFaceName, face, LF_FACESIZE );
271 /* adjust the height */
272 hdc = GetDC( dialog->hwnd );
275 lf.lfHeight = -MulDiv(lf.lfHeight, GetDeviceCaps(hdc, LOGPIXELSY), 72);
276 ReleaseDC( dialog->hwnd, hdc );
279 font->hfont = CreateFontIndirectW( &lf );
281 TRACE("Adding font style %s\n", debugstr_w(font->name) );
283 return ERROR_SUCCESS;
286 static msi_font *msi_dialog_find_font( msi_dialog *dialog, LPCWSTR name )
290 for( font = dialog->font_list; font; font = font->next )
291 if( !strcmpW( font->name, name ) ) /* FIXME: case sensitive? */
297 static UINT msi_dialog_set_font( msi_dialog *dialog, HWND hwnd, LPCWSTR name )
301 font = msi_dialog_find_font( dialog, name );
303 SendMessageW( hwnd, WM_SETFONT, (WPARAM) font->hfont, TRUE );
305 ERR("No font entry for %s\n", debugstr_w(name));
306 return ERROR_SUCCESS;
309 static UINT msi_dialog_build_font_list( msi_dialog *dialog )
311 static const WCHAR query[] = {
312 'S','E','L','E','C','T',' ','*',' ',
313 'F','R','O','M',' ','`','T','e','x','t','S','t','y','l','e','`',' ',0
316 MSIQUERY *view = NULL;
318 TRACE("dialog %p\n", dialog );
320 r = MSI_OpenQuery( dialog->package->db, &view, query );
321 if( r != ERROR_SUCCESS )
324 r = MSI_IterateRecords( view, NULL, msi_dialog_add_font, dialog );
325 msiobj_release( &view->hdr );
330 static msi_control *msi_dialog_create_window( msi_dialog *dialog,
331 MSIRECORD *rec, DWORD exstyle, LPCWSTR szCls, LPCWSTR name, LPCWSTR text,
332 DWORD style, HWND parent )
334 DWORD x, y, width, height;
335 LPWSTR font = NULL, title_font = NULL;
336 LPCWSTR title = NULL;
337 msi_control *control;
341 control = msi_alloc( sizeof *control + strlenW(name)*sizeof(WCHAR) );
342 strcpyW( control->name, name );
343 list_add_head( &dialog->controls, &control->entry );
344 control->handler = NULL;
345 control->property = NULL;
346 control->value = NULL;
347 control->hBitmap = NULL;
348 control->hIcon = NULL;
349 control->hDll = NULL;
350 control->tabnext = strdupW( MSI_RecordGetString( rec, 11) );
351 control->progress_current = 0;
352 control->progress_max = 100;
354 x = MSI_RecordGetInteger( rec, 4 );
355 y = MSI_RecordGetInteger( rec, 5 );
356 width = MSI_RecordGetInteger( rec, 6 );
357 height = MSI_RecordGetInteger( rec, 7 );
359 x = msi_dialog_scale_unit( dialog, x );
360 y = msi_dialog_scale_unit( dialog, y );
361 width = msi_dialog_scale_unit( dialog, width );
362 height = msi_dialog_scale_unit( dialog, height );
366 deformat_string( dialog->package, text, &title_font );
367 font = msi_dialog_get_style( title_font, &title );
370 control->hwnd = CreateWindowExW( exstyle, szCls, title, style,
371 x, y, width, height, parent, NULL, NULL, NULL );
373 TRACE("Dialog %s control %s hwnd %p\n",
374 debugstr_w(dialog->name), debugstr_w(text), control->hwnd );
376 msi_dialog_set_font( dialog, control->hwnd,
377 font ? font : dialog->default_font );
379 msi_free( title_font );
385 static MSIRECORD *msi_get_binary_record( MSIDATABASE *db, LPCWSTR name )
387 static const WCHAR query[] = {
388 's','e','l','e','c','t',' ','*',' ',
389 'f','r','o','m',' ','B','i','n','a','r','y',' ',
390 'w','h','e','r','e',' ',
391 '`','N','a','m','e','`',' ','=',' ','\'','%','s','\'',0
394 return MSI_QueryGetRecord( db, query, name );
397 static LPWSTR msi_create_tmp_path(void)
401 static const WCHAR prefix[] = { 'm','s','i',0 };
404 r = GetTempPathW( MAX_PATH, tmp );
407 len = lstrlenW( tmp ) + 20;
408 path = msi_alloc( len * sizeof (WCHAR) );
411 r = GetTempFileNameW( tmp, prefix, 0, path );
422 static HANDLE msi_load_image( MSIDATABASE *db, LPCWSTR name, UINT type,
423 UINT cx, UINT cy, UINT flags )
425 MSIRECORD *rec = NULL;
426 HANDLE himage = NULL;
430 TRACE("%p %s %u %u %08x\n", db, debugstr_w(name), cx, cy, flags);
432 tmp = msi_create_tmp_path();
436 rec = msi_get_binary_record( db, name );
439 r = MSI_RecordStreamToFile( rec, 2, tmp );
440 if( r == ERROR_SUCCESS )
442 himage = LoadImageW( 0, tmp, type, cx, cy, flags );
445 msiobj_release( &rec->hdr );
452 static HICON msi_load_icon( MSIDATABASE *db, LPCWSTR text, UINT attributes )
454 DWORD cx = 0, cy = 0, flags;
456 flags = LR_LOADFROMFILE | LR_DEFAULTSIZE;
457 if( attributes & msidbControlAttributesFixedSize )
459 flags &= ~LR_DEFAULTSIZE;
460 if( attributes & msidbControlAttributesIconSize16 )
465 if( attributes & msidbControlAttributesIconSize32 )
470 /* msidbControlAttributesIconSize48 handled by above logic */
472 return msi_load_image( db, text, IMAGE_ICON, cx, cy, flags );
476 /* called from the Control Event subscription code */
477 void msi_dialog_handle_event( msi_dialog* dialog, LPCWSTR control,
478 LPCWSTR attribute, MSIRECORD *rec )
481 LPCWSTR font_text, text = NULL;
484 ctrl = msi_dialog_find_control( dialog, control );
487 if( !lstrcmpW(attribute, szText) )
489 font_text = MSI_RecordGetString( rec , 1 );
490 font = msi_dialog_get_style( font_text, &text );
491 SetWindowTextW( ctrl->hwnd, text );
493 msi_dialog_check_messages( NULL );
495 else if( !lstrcmpW(attribute, szProgress) )
499 func = MSI_RecordGetInteger( rec , 1 );
500 val = MSI_RecordGetInteger( rec , 2 );
505 ctrl->progress_max = val;
506 ctrl->progress_current = 0;
507 SendMessageW(ctrl->hwnd, PBM_SETRANGE, 0, MAKELPARAM(0,100));
508 SendMessageW(ctrl->hwnd, PBM_SETPOS, 0, 0);
510 case 1: /* FIXME: not sure what this is supposed to do */
513 ctrl->progress_current += val;
514 SendMessageW(ctrl->hwnd, PBM_SETPOS, 100*(ctrl->progress_current/ctrl->progress_max), 0);
517 ERR("Unknown progress message %ld\n", func);
523 FIXME("Attribute %s not being set\n", debugstr_w(attribute));
528 static void msi_dialog_map_events(msi_dialog* dialog, LPCWSTR control)
530 static const WCHAR Query[] = {
531 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
532 '`','E','v','e','n','t','M','a','p','p','i','n','g','`',' ',
533 'W','H','E','R','E',' ',
534 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',' ',
536 '`','C','o','n','t','r','o','l','_','`',' ','=',' ','\'','%','s','\'',0
539 LPCWSTR event, attribute;
541 row = MSI_QueryGetRecord( dialog->package->db, Query, dialog->name, control );
545 event = MSI_RecordGetString( row, 3 );
546 attribute = MSI_RecordGetString( row, 4 );
547 ControlEvent_SubscribeToEvent( dialog->package, event, control, attribute );
548 msiobj_release( &row->hdr );
551 /* everything except radio buttons */
552 static msi_control *msi_dialog_add_control( msi_dialog *dialog,
553 MSIRECORD *rec, LPCWSTR szCls, DWORD style )
559 name = MSI_RecordGetString( rec, 2 );
560 attributes = MSI_RecordGetInteger( rec, 8 );
561 text = MSI_RecordGetString( rec, 10 );
562 if( attributes & msidbControlAttributesVisible )
564 if( ~attributes & msidbControlAttributesEnabled )
565 style |= WS_DISABLED;
566 if( attributes & msidbControlAttributesSunken )
567 exstyle |= WS_EX_CLIENTEDGE;
569 msi_dialog_map_events(dialog, name);
571 return msi_dialog_create_window( dialog, rec, exstyle, szCls, name,
572 text, style, dialog->hwnd );
583 * we don't erase our own background,
584 * so we have to make sure that the parent window redraws first
586 static void msi_text_on_settext( HWND hWnd )
591 hParent = GetParent( hWnd );
592 GetWindowRect( hWnd, &rc );
593 MapWindowPoints( NULL, hParent, (LPPOINT) &rc, 2 );
594 InvalidateRect( hParent, &rc, TRUE );
597 static LRESULT WINAPI
598 MSIText_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
600 struct msi_text_info *info;
603 TRACE("%p %04x %08x %08lx\n", hWnd, msg, wParam, lParam);
605 info = GetPropW(hWnd, szButtonData);
608 SetTextColor( (HDC)wParam, info->font->color );
610 if( msg == WM_CTLCOLORSTATIC &&
611 ( info->attributes & msidbControlAttributesTransparent ) )
613 SetBkMode( (HDC)wParam, TRANSPARENT );
614 return (LRESULT) GetStockObject(NULL_BRUSH);
617 r = CallWindowProcW(info->oldproc, hWnd, msg, wParam, lParam);
622 msi_text_on_settext( hWnd );
626 RemovePropW( hWnd, szButtonData );
633 static UINT msi_dialog_text_control( msi_dialog *dialog, MSIRECORD *rec )
635 msi_control *control;
636 struct msi_text_info *info;
640 TRACE("%p %p\n", dialog, rec);
642 control = msi_dialog_add_control( dialog, rec, szStatic, SS_LEFT | WS_GROUP );
644 return ERROR_FUNCTION_FAILED;
646 info = msi_alloc( sizeof *info );
648 return ERROR_SUCCESS;
650 text = MSI_RecordGetString( rec, 10 );
651 font_name = msi_dialog_get_style( text, &ptr );
652 info->font = ( font_name ) ? msi_dialog_find_font( dialog, font_name ) : NULL;
653 msi_free( font_name );
655 info->attributes = MSI_RecordGetInteger( rec, 8 );
656 if( info->attributes & msidbControlAttributesTransparent )
657 SetWindowLongPtrW( control->hwnd, GWL_EXSTYLE, WS_EX_TRANSPARENT );
659 info->oldproc = (WNDPROC) SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
660 (LONG_PTR)MSIText_WndProc );
661 SetPropW( control->hwnd, szButtonData, info );
663 return ERROR_SUCCESS;
666 static UINT msi_dialog_button_control( msi_dialog *dialog, MSIRECORD *rec )
668 msi_control *control;
669 UINT attributes, style;
672 TRACE("%p %p\n", dialog, rec);
675 attributes = MSI_RecordGetInteger( rec, 8 );
676 if( attributes & msidbControlAttributesIcon )
679 control = msi_dialog_add_control( dialog, rec, szButton, style );
681 return ERROR_FUNCTION_FAILED;
683 control->handler = msi_dialog_button_handler;
686 text = msi_get_deformatted_field( dialog->package, rec, 10 );
687 control->hIcon = msi_load_icon( dialog->package->db, text, attributes );
688 if( attributes & msidbControlAttributesIcon )
689 SendMessageW( control->hwnd, BM_SETIMAGE, IMAGE_ICON, (LPARAM) control->hIcon );
692 return ERROR_SUCCESS;
695 static LPWSTR msi_get_checkbox_value( msi_dialog *dialog, LPCWSTR prop )
697 static const WCHAR query[] = {
698 'S','E','L','E','C','T',' ','*',' ',
699 'F','R','O','M',' ','`','C','h','e','c','k','B','o','x',' ','`',
700 'W','H','E','R','E',' ',
701 '`','P','r','o','p','e','r','t','y','`',' ','=',' ',
704 MSIRECORD *rec = NULL;
707 /* find if there is a value associated with the checkbox */
708 rec = MSI_QueryGetRecord( dialog->package->db, query, prop );
712 ret = msi_get_deformatted_field( dialog->package, rec, 2 );
718 msiobj_release( &rec->hdr );
722 ret = msi_dup_property( dialog->package, prop );
732 static UINT msi_dialog_checkbox_control( msi_dialog *dialog, MSIRECORD *rec )
734 msi_control *control;
737 TRACE("%p %p\n", dialog, rec);
739 control = msi_dialog_add_control( dialog, rec, szButton,
740 BS_CHECKBOX | BS_MULTILINE | WS_TABSTOP );
741 control->handler = msi_dialog_checkbox_handler;
742 prop = MSI_RecordGetString( rec, 9 );
745 control->property = strdupW( prop );
746 control->value = msi_get_checkbox_value( dialog, prop );
747 TRACE("control %s value %s\n", debugstr_w(control->property),
748 debugstr_w(control->value));
750 msi_dialog_checkbox_sync_state( dialog, control );
752 return ERROR_SUCCESS;
755 static UINT msi_dialog_line_control( msi_dialog *dialog, MSIRECORD *rec )
757 TRACE("%p %p\n", dialog, rec);
759 /* line is exactly 2 units in height */
760 MSI_RecordSetInteger( rec, 7, 2 );
762 msi_dialog_add_control( dialog, rec, szStatic, SS_ETCHEDHORZ | SS_SUNKEN );
763 return ERROR_SUCCESS;
766 /******************** Scroll Text ********************************************/
768 struct msi_scrolltext_info
771 msi_control *control;
775 static LRESULT WINAPI
776 MSIScrollText_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
778 struct msi_scrolltext_info *info;
781 TRACE("%p %04x %08x %08lx\n", hWnd, msg, wParam, lParam);
783 info = GetPropW( hWnd, szButtonData );
785 r = CallWindowProcW( info->oldproc, hWnd, msg, wParam, lParam );
791 RemovePropW( hWnd, szButtonData );
794 /* native MSI sets a wait cursor here */
795 msi_dialog_button_handler( info->dialog, info->control, BN_CLICKED );
801 struct msi_streamin_info
808 static DWORD CALLBACK
809 msi_richedit_stream_in( DWORD_PTR arg, LPBYTE buffer, LONG count, LONG *pcb )
811 struct msi_streamin_info *info = (struct msi_streamin_info*) arg;
813 if( (count + info->offset) > info->length )
814 count = info->length - info->offset;
815 memcpy( buffer, &info->string[ info->offset ], count );
817 info->offset += count;
819 TRACE("%ld/%ld\n", info->offset, info->length);
824 static void msi_scrolltext_add_text( msi_control *control, LPCWSTR text )
826 struct msi_streamin_info info;
829 info.string = strdupWtoA( text );
831 info.length = lstrlenA( info.string ) + 1;
833 es.dwCookie = (DWORD_PTR) &info;
835 es.pfnCallback = msi_richedit_stream_in;
837 SendMessageW( control->hwnd, EM_STREAMIN, SF_RTF, (LPARAM) &es );
839 msi_free( info.string );
842 static UINT msi_dialog_scrolltext_control( msi_dialog *dialog, MSIRECORD *rec )
844 static const WCHAR szRichEdit20W[] = {
845 'R','i','c','h','E','d','i','t','2','0','W',0
847 struct msi_scrolltext_info *info;
848 msi_control *control;
852 info = msi_alloc( sizeof *info );
854 return ERROR_FUNCTION_FAILED;
856 hRichedit = LoadLibraryA("riched20");
858 style = WS_BORDER | ES_MULTILINE | WS_VSCROLL |
859 ES_READONLY | ES_AUTOVSCROLL | WS_TABSTOP;
860 control = msi_dialog_add_control( dialog, rec, szRichEdit20W, style );
863 FreeLibrary( hRichedit );
865 return ERROR_FUNCTION_FAILED;
868 control->hDll = hRichedit;
870 info->dialog = dialog;
871 info->control = control;
873 /* subclass the static control */
874 info->oldproc = (WNDPROC) SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
875 (LONG_PTR)MSIScrollText_WndProc );
876 SetPropW( control->hwnd, szButtonData, info );
878 /* add the text into the richedit */
879 msi_scrolltext_add_text( control, MSI_RecordGetString( rec, 10 ) );
881 return ERROR_SUCCESS;
884 static HBITMAP msi_load_picture( MSIDATABASE *db, LPCWSTR name,
885 INT cx, INT cy, DWORD flags )
887 HBITMAP hOleBitmap = 0, hBitmap = 0, hOldSrcBitmap, hOldDestBitmap;
888 MSIRECORD *rec = NULL;
890 IPicture *pic = NULL;
895 rec = msi_get_binary_record( db, name );
899 r = MSI_RecordGetIStream( rec, 2, &stm );
900 msiobj_release( &rec->hdr );
901 if( r != ERROR_SUCCESS )
904 r = OleLoadPicture( stm, 0, TRUE, &IID_IPicture, (LPVOID*) &pic );
905 IStream_Release( stm );
908 ERR("failed to load picture\n");
912 r = IPicture_get_Handle( pic, (OLE_HANDLE*) &hOleBitmap );
915 ERR("failed to get bitmap handle\n");
919 /* make the bitmap the desired size */
920 r = GetObjectW( hOleBitmap, sizeof bm, &bm );
923 ERR("failed to get bitmap size\n");
927 if (flags & LR_DEFAULTSIZE)
933 srcdc = CreateCompatibleDC( NULL );
934 hOldSrcBitmap = SelectObject( srcdc, hOleBitmap );
935 destdc = CreateCompatibleDC( NULL );
936 hBitmap = CreateCompatibleBitmap( srcdc, cx, cy );
937 hOldDestBitmap = SelectObject( destdc, hBitmap );
938 StretchBlt( destdc, 0, 0, cx, cy,
939 srcdc, 0, 0, bm.bmWidth, bm.bmHeight, SRCCOPY);
940 SelectObject( srcdc, hOldSrcBitmap );
941 SelectObject( destdc, hOldDestBitmap );
947 IPicture_Release( pic );
951 static UINT msi_dialog_bitmap_control( msi_dialog *dialog, MSIRECORD *rec )
953 UINT cx, cy, flags, style, attributes;
954 msi_control *control;
957 flags = LR_LOADFROMFILE;
958 style = SS_BITMAP | SS_LEFT | WS_GROUP;
960 attributes = MSI_RecordGetInteger( rec, 8 );
961 if( attributes & msidbControlAttributesFixedSize )
963 flags |= LR_DEFAULTSIZE;
964 style |= SS_CENTERIMAGE;
967 control = msi_dialog_add_control( dialog, rec, szStatic, style );
968 cx = MSI_RecordGetInteger( rec, 6 );
969 cy = MSI_RecordGetInteger( rec, 7 );
970 cx = msi_dialog_scale_unit( dialog, cx );
971 cy = msi_dialog_scale_unit( dialog, cy );
973 text = msi_get_deformatted_field( dialog->package, rec, 10 );
974 control->hBitmap = msi_load_picture( dialog->package->db, text, cx, cy, flags );
975 if( control->hBitmap )
976 SendMessageW( control->hwnd, STM_SETIMAGE,
977 IMAGE_BITMAP, (LPARAM) control->hBitmap );
979 ERR("Failed to load bitmap %s\n", debugstr_w(text));
983 return ERROR_SUCCESS;
986 static UINT msi_dialog_icon_control( msi_dialog *dialog, MSIRECORD *rec )
988 msi_control *control;
994 control = msi_dialog_add_control( dialog, rec, szStatic,
995 SS_ICON | SS_CENTERIMAGE | WS_GROUP );
997 attributes = MSI_RecordGetInteger( rec, 8 );
998 text = msi_get_deformatted_field( dialog->package, rec, 10 );
999 control->hIcon = msi_load_icon( dialog->package->db, text, attributes );
1000 if( control->hIcon )
1001 SendMessageW( control->hwnd, STM_SETICON, (WPARAM) control->hIcon, 0 );
1003 ERR("Failed to load bitmap %s\n", debugstr_w(text));
1005 return ERROR_SUCCESS;
1008 static UINT msi_dialog_combo_control( msi_dialog *dialog, MSIRECORD *rec )
1010 static const WCHAR szCombo[] = { 'C','O','M','B','O','B','O','X',0 };
1012 msi_dialog_add_control( dialog, rec, szCombo,
1013 SS_BITMAP | SS_LEFT | SS_CENTERIMAGE );
1014 return ERROR_SUCCESS;
1017 static UINT msi_dialog_edit_control( msi_dialog *dialog, MSIRECORD *rec )
1019 msi_control *control;
1023 control = msi_dialog_add_control( dialog, rec, szEdit,
1024 WS_BORDER | WS_TABSTOP );
1025 control->handler = msi_dialog_edit_handler;
1026 prop = MSI_RecordGetString( rec, 9 );
1028 control->property = strdupW( prop );
1029 val = msi_dup_property( dialog->package, control->property );
1030 SetWindowTextW( control->hwnd, val );
1032 return ERROR_SUCCESS;
1035 /******************** Masked Edit ********************************************/
1037 #define MASK_MAX_GROUPS 10
1039 struct msi_mask_group
1047 struct msi_maskedit_info
1055 struct msi_mask_group group[MASK_MAX_GROUPS];
1058 static BOOL msi_mask_editable( WCHAR type )
1073 static void msi_mask_control_change( struct msi_maskedit_info *info )
1078 val = msi_alloc( (info->num_chars+1)*sizeof(WCHAR) );
1079 for( i=0, n=0; i<info->num_groups; i++ )
1081 if( (info->group[i].len + n) > info->num_chars )
1083 ERR("can't fit control %d text into template\n",i);
1086 if (!msi_mask_editable(info->group[i].type))
1088 for(r=0; r<info->group[i].len; r++)
1089 val[n+r] = info->group[i].type;
1094 r = GetWindowTextW( info->group[i].hwnd, &val[n], info->group[i].len+1 );
1095 if( r != info->group[i].len )
1101 TRACE("%d/%d controls were good\n", i, info->num_groups);
1103 if( i == info->num_groups )
1105 TRACE("Set property %s to %s\n",
1106 debugstr_w(info->prop), debugstr_w(val) );
1107 CharUpperBuffW( val, info->num_chars );
1108 MSI_SetPropertyW( info->dialog->package, info->prop, val );
1109 msi_dialog_evaluate_control_conditions( info->dialog );
1114 /* now move to the next control if necessary */
1115 static VOID msi_mask_next_control( struct msi_maskedit_info *info, HWND hWnd )
1120 for( i=0; i<info->num_groups; i++ )
1121 if( info->group[i].hwnd == hWnd )
1124 /* don't move from the last control */
1125 if( i >= (info->num_groups-1) )
1128 len = SendMessageW( hWnd, WM_GETTEXTLENGTH, 0, 0 );
1129 if( len < info->group[i].len )
1132 hWndNext = GetNextDlgTabItem( GetParent( hWnd ), hWnd, FALSE );
1133 SetFocus( hWndNext );
1136 static LRESULT WINAPI
1137 MSIMaskedEdit_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
1139 struct msi_maskedit_info *info;
1142 TRACE("%p %04x %08x %08lx\n", hWnd, msg, wParam, lParam);
1144 info = GetPropW(hWnd, szButtonData);
1146 r = CallWindowProcW(info->oldproc, hWnd, msg, wParam, lParam);
1151 if (HIWORD(wParam) == EN_CHANGE)
1153 msi_mask_control_change( info );
1154 msi_mask_next_control( info, (HWND) lParam );
1158 msi_free( info->prop );
1160 RemovePropW( hWnd, szButtonData );
1167 /* fish the various bits of the property out and put them in the control */
1169 msi_maskedit_set_text( struct msi_maskedit_info *info, LPCWSTR text )
1175 for( i = 0; i < info->num_groups; i++ )
1177 if( info->group[i].len < lstrlenW( p ) )
1179 LPWSTR chunk = strdupW( p );
1180 chunk[ info->group[i].len ] = 0;
1181 SetWindowTextW( info->group[i].hwnd, chunk );
1186 SetWindowTextW( info->group[i].hwnd, p );
1189 p += info->group[i].len;
1193 static struct msi_maskedit_info * msi_dialog_parse_groups( LPCWSTR mask )
1195 struct msi_maskedit_info * info = NULL;
1196 int i = 0, n = 0, total = 0;
1199 TRACE("masked control, template %s\n", debugstr_w(mask));
1204 info = msi_alloc_zero( sizeof *info );
1208 p = strchrW(mask, '<');
1214 for( i=0; i<MASK_MAX_GROUPS; i++ )
1216 /* stop at the end of the string */
1217 if( p[0] == 0 || p[0] == '>' )
1220 /* count the number of the same identifier */
1221 for( n=0; p[n] == p[0]; n++ )
1223 info->group[i].ofs = total;
1224 info->group[i].type = p[0];
1228 total++; /* an extra not part of the group */
1230 info->group[i].len = n;
1235 TRACE("%d characters in %d groups\n", total, i );
1236 if( i == MASK_MAX_GROUPS )
1237 ERR("too many groups in PIDTemplate %s\n", debugstr_w(mask));
1239 info->num_chars = total;
1240 info->num_groups = i;
1246 msi_maskedit_create_children( struct msi_maskedit_info *info, LPCWSTR font )
1248 DWORD width, height, style, wx, ww;
1253 style = WS_CHILD | WS_BORDER | WS_VISIBLE | WS_TABSTOP | ES_AUTOHSCROLL;
1255 GetClientRect( info->hwnd, &rect );
1257 width = rect.right - rect.left;
1258 height = rect.bottom - rect.top;
1260 for( i = 0; i < info->num_groups; i++ )
1262 if (!msi_mask_editable( info->group[i].type ))
1264 wx = (info->group[i].ofs * width) / info->num_chars;
1265 ww = (info->group[i].len * width) / info->num_chars;
1267 hwnd = CreateWindowW( szEdit, NULL, style, wx, 0, ww, height,
1268 info->hwnd, NULL, NULL, NULL );
1271 ERR("failed to create mask edit sub window\n");
1275 SendMessageW( hwnd, EM_LIMITTEXT, info->group[i].len, 0 );
1277 msi_dialog_set_font( info->dialog, hwnd,
1278 font?font:info->dialog->default_font );
1279 info->group[i].hwnd = hwnd;
1284 * office 2003 uses "73931<````=````=````=````=`````>@@@@@"
1285 * delphi 7 uses "<????-??????-??????-????>" and "<???-???>"
1286 * filemaker pro 7 uses "<^^^^=^^^^=^^^^=^^^^=^^^^=^^^^=^^^^^>"
1288 static UINT msi_dialog_maskedit_control( msi_dialog *dialog, MSIRECORD *rec )
1290 LPWSTR font_mask, val = NULL, font;
1291 struct msi_maskedit_info *info = NULL;
1292 UINT ret = ERROR_SUCCESS;
1293 msi_control *control;
1298 font_mask = msi_get_deformatted_field( dialog->package, rec, 10 );
1299 font = msi_dialog_get_style( font_mask, &mask );
1302 ERR("mask template is empty\n");
1306 info = msi_dialog_parse_groups( mask );
1309 ERR("template %s is invalid\n", debugstr_w(mask));
1313 info->dialog = dialog;
1315 control = msi_dialog_add_control( dialog, rec, szStatic,
1316 SS_OWNERDRAW | WS_GROUP | WS_VISIBLE );
1319 ERR("Failed to create maskedit container\n");
1320 ret = ERROR_FUNCTION_FAILED;
1323 SetWindowLongPtrW( control->hwnd, GWL_EXSTYLE, WS_EX_CONTROLPARENT );
1325 info->hwnd = control->hwnd;
1327 /* subclass the static control */
1328 info->oldproc = (WNDPROC) SetWindowLongPtrW( info->hwnd, GWLP_WNDPROC,
1329 (LONG_PTR)MSIMaskedEdit_WndProc );
1330 SetPropW( control->hwnd, szButtonData, info );
1332 prop = MSI_RecordGetString( rec, 9 );
1334 info->prop = strdupW( prop );
1336 msi_maskedit_create_children( info, font );
1340 val = msi_dup_property( dialog->package, prop );
1343 msi_maskedit_set_text( info, val );
1349 if( ret != ERROR_SUCCESS )
1351 msi_free( font_mask );
1356 /******************** Progress Bar *****************************************/
1358 static UINT msi_dialog_progress_bar( msi_dialog *dialog, MSIRECORD *rec )
1360 msi_dialog_add_control( dialog, rec, PROGRESS_CLASSW, WS_VISIBLE );
1361 return ERROR_SUCCESS;
1364 /******************** Path Edit ********************************************/
1366 static LPWSTR msi_get_window_text( HWND hwnd )
1372 buf = msi_alloc( sz*sizeof(WCHAR) );
1375 r = GetWindowTextW( hwnd, buf, sz );
1379 buf = msi_realloc( buf, sz*sizeof(WCHAR) );
1385 static UINT msi_dialog_pathedit_handler( msi_dialog *dialog,
1386 msi_control *control, WPARAM param )
1389 LPWSTR buf, indirect = NULL;
1391 if( HIWORD(param) != EN_KILLFOCUS )
1392 return ERROR_SUCCESS;
1394 prop = control->property;
1395 if ( control->attributes & msidbControlAttributesIndirect )
1397 indirect = msi_dup_property( dialog->package, control->property );
1401 /* FIXME: verify the new path */
1402 buf = msi_get_window_text( control->hwnd );
1403 MSI_SetPropertyW( dialog->package, prop, buf );
1405 TRACE("edit %s contents changed, set %s\n", debugstr_w(control->name),
1409 msi_free( indirect );
1411 return ERROR_SUCCESS;
1414 static UINT msi_dialog_pathedit_control( msi_dialog *dialog, MSIRECORD *rec )
1416 msi_control *control;
1418 LPWSTR val, indirect = NULL;
1420 control = msi_dialog_add_control( dialog, rec, szEdit,
1421 WS_BORDER | WS_TABSTOP );
1422 control->handler = msi_dialog_pathedit_handler;
1423 control->attributes = MSI_RecordGetInteger( rec, 8 );
1425 prop = MSI_RecordGetString( rec, 9 );
1427 control->property = strdupW( prop );
1429 if ( control->attributes & msidbControlAttributesIndirect )
1431 indirect = msi_dup_property( dialog->package, control->property );
1435 val = msi_dup_property( dialog->package, prop );
1436 SetWindowTextW( control->hwnd, val );
1438 msi_free( indirect );
1440 return ERROR_SUCCESS;
1443 /* radio buttons are a bit different from normal controls */
1444 static UINT msi_dialog_create_radiobutton( MSIRECORD *rec, LPVOID param )
1446 radio_button_group_descr *group = (radio_button_group_descr *)param;
1447 msi_dialog *dialog = group->dialog;
1448 msi_control *control;
1449 LPCWSTR prop, text, name;
1450 DWORD style, attributes = group->attributes;
1452 style = WS_CHILD | BS_AUTORADIOBUTTON | BS_MULTILINE | WS_TABSTOP;
1453 name = MSI_RecordGetString( rec, 3 );
1454 text = MSI_RecordGetString( rec, 8 );
1455 if( attributes & 1 )
1456 style |= WS_VISIBLE;
1457 if( ~attributes & 2 )
1458 style |= WS_DISABLED;
1460 control = msi_dialog_create_window( dialog, rec, 0, szButton, name, text,
1461 style, group->parent->hwnd );
1463 return ERROR_FUNCTION_FAILED;
1464 control->handler = msi_dialog_radiogroup_handler;
1466 if (!lstrcmpW(control->name, group->propval))
1467 SendMessageW(control->hwnd, BM_SETCHECK, BST_CHECKED, 0);
1469 prop = MSI_RecordGetString( rec, 1 );
1471 control->property = strdupW( prop );
1473 return ERROR_SUCCESS;
1476 static UINT msi_dialog_radiogroup_control( msi_dialog *dialog, MSIRECORD *rec )
1478 static const WCHAR query[] = {
1479 'S','E','L','E','C','T',' ','*',' ',
1480 'F','R','O','M',' ','R','a','d','i','o','B','u','t','t','o','n',' ',
1481 'W','H','E','R','E',' ',
1482 '`','P','r','o','p','e','r','t','y','`',' ','=',' ','\'','%','s','\'',0};
1485 msi_control *control;
1486 MSIQUERY *view = NULL;
1487 radio_button_group_descr group;
1488 MSIPACKAGE *package = dialog->package;
1491 prop = MSI_RecordGetString( rec, 9 );
1493 TRACE("%p %p %s\n", dialog, rec, debugstr_w( prop ));
1495 /* Create parent group box to hold radio buttons */
1496 control = msi_dialog_add_control( dialog, rec, szButton, BS_OWNERDRAW|WS_GROUP );
1498 return ERROR_FUNCTION_FAILED;
1500 oldproc = (WNDPROC) SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
1501 (LONG_PTR)MSIRadioGroup_WndProc );
1502 SetPropW(control->hwnd, szButtonData, oldproc);
1503 SetWindowLongPtrW( control->hwnd, GWL_EXSTYLE, WS_EX_CONTROLPARENT );
1506 control->property = strdupW( prop );
1508 /* query the Radio Button table for all control in this group */
1509 r = MSI_OpenQuery( package->db, &view, query, prop );
1510 if( r != ERROR_SUCCESS )
1512 ERR("query failed for dialog %s radio group %s\n",
1513 debugstr_w(dialog->name), debugstr_w(prop));
1514 return ERROR_INVALID_PARAMETER;
1517 group.dialog = dialog;
1518 group.parent = control;
1519 group.attributes = MSI_RecordGetInteger( rec, 8 );
1520 group.propval = msi_dup_property( dialog->package, control->property );
1522 r = MSI_IterateRecords( view, 0, msi_dialog_create_radiobutton, &group );
1523 msiobj_release( &view->hdr );
1524 msi_free( group.propval );
1529 /******************** Selection Tree ***************************************/
1531 struct msi_selection_tree_info
1539 msi_seltree_sync_item_state( HWND hwnd, MSIFEATURE *feature, HTREEITEM hItem )
1543 TRACE("Feature %s -> %d %d %d\n", debugstr_w(feature->Title),
1544 feature->Installed, feature->Action, feature->ActionRequest);
1546 tvi.mask = TVIF_STATE;
1548 tvi.state = INDEXTOSTATEIMAGEMASK( feature->Action );
1549 tvi.stateMask = TVIS_STATEIMAGEMASK;
1551 SendMessageW( hwnd, TVM_SETITEMW, 0, (LPARAM) &tvi );
1555 msi_seltree_popup_menu( HWND hwnd, INT x, INT y )
1560 /* create a menu to display */
1561 hMenu = CreatePopupMenu();
1563 /* FIXME: load strings from resources */
1564 AppendMenuA( hMenu, MF_ENABLED, INSTALLSTATE_LOCAL, "Install feature locally");
1565 AppendMenuA( hMenu, MF_GRAYED, 0x1000, "Install entire feature");
1566 AppendMenuA( hMenu, MF_ENABLED, INSTALLSTATE_ADVERTISED, "Install on demand");
1567 AppendMenuA( hMenu, MF_ENABLED, INSTALLSTATE_ABSENT, "Don't install");
1568 r = TrackPopupMenu( hMenu, TPM_LEFTALIGN | TPM_TOPALIGN | TPM_RETURNCMD,
1569 x, y, 0, hwnd, NULL );
1570 DestroyMenu( hMenu );
1575 msi_seltree_feature_from_item( HWND hwnd, HTREEITEM hItem )
1579 /* get the feature from the item */
1580 memset( &tvi, 0, sizeof tvi );
1582 tvi.mask = TVIF_PARAM | TVIF_HANDLE;
1583 SendMessageW( hwnd, TVM_GETITEMW, 0, (LPARAM) &tvi );
1585 return (MSIFEATURE*) tvi.lParam;
1589 msi_seltree_menu( HWND hwnd, HTREEITEM hItem )
1591 MSIFEATURE *feature;
1600 feature = msi_seltree_feature_from_item( hwnd, hItem );
1603 ERR("item %p feature was NULL\n", hItem);
1607 /* get the item's rectangle to put the menu just below it */
1609 SendMessageW( hwnd, TVM_GETITEMRECT, 0, (LPARAM) &u.rc );
1610 MapWindowPoints( hwnd, NULL, u.pt, 2 );
1612 r = msi_seltree_popup_menu( hwnd, u.rc.left, u.rc.top );
1616 case INSTALLSTATE_LOCAL:
1617 case INSTALLSTATE_ADVERTISED:
1618 case INSTALLSTATE_ABSENT:
1619 feature->ActionRequest = r;
1620 feature->Action = r;
1623 FIXME("select feature and all children\n");
1627 msi_seltree_sync_item_state( hwnd, feature, hItem );
1629 /* update the feature's components */
1630 LIST_FOR_EACH_ENTRY( cl, &feature->Components, ComponentList, entry )
1632 cl->component->Action = feature->Action;
1633 cl->component->ActionRequest = feature->ActionRequest;
1639 static LRESULT WINAPI
1640 MSISelectionTree_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
1642 struct msi_selection_tree_info *info;
1643 TVHITTESTINFO tvhti;
1646 TRACE("%p %04x %08x %08lx\n", hWnd, msg, wParam, lParam);
1648 info = GetPropW(hWnd, szButtonData);
1652 case WM_LBUTTONDOWN:
1653 tvhti.pt.x = LOWORD( lParam );
1654 tvhti.pt.y = HIWORD( lParam );
1657 r = CallWindowProcW(info->oldproc, hWnd, TVM_HITTEST, 0, (LPARAM) &tvhti );
1658 if (tvhti.flags & TVHT_ONITEMSTATEICON)
1659 return msi_seltree_menu( hWnd, tvhti.hItem );
1663 r = CallWindowProcW(info->oldproc, hWnd, msg, wParam, lParam);
1669 RemovePropW( hWnd, szButtonData );
1676 msi_seltree_add_child_features( MSIPACKAGE *package, HWND hwnd,
1677 LPCWSTR parent, HTREEITEM hParent )
1679 MSIFEATURE *feature;
1680 TVINSERTSTRUCTW tvis;
1683 LIST_FOR_EACH_ENTRY( feature, &package->features, MSIFEATURE, entry )
1685 if ( lstrcmpW( parent, feature->Feature_Parent ) )
1688 if ( !feature->Title )
1691 if ( !feature->Display )
1694 memset( &tvis, 0, sizeof tvis );
1695 tvis.hParent = hParent;
1696 tvis.hInsertAfter = TVI_LAST;
1697 tvis.u.item.mask = TVIF_TEXT | TVIF_PARAM;
1698 tvis.u.item.pszText = feature->Title;
1699 tvis.u.item.lParam = (LPARAM) feature;
1701 hitem = (HTREEITEM) SendMessageW( hwnd, TVM_INSERTITEMW, 0, (LPARAM) &tvis );
1705 msi_seltree_sync_item_state( hwnd, feature, hitem );
1706 msi_seltree_add_child_features( package, hwnd,
1707 feature->Feature, hitem );
1709 /* the node is expanded if Display is odd */
1710 if ( feature->Display % 2 != 0 )
1711 SendMessageW( hwnd, TVM_EXPAND, TVE_EXPAND, (LPARAM) hitem );
1715 static void msi_seltree_create_imagelist( HWND hwnd )
1717 const int bm_width = 32, bm_height = 16, bm_count = 3;
1718 const int bm_resource = 0x1001;
1723 himl = ImageList_Create( bm_width, bm_height, FALSE, 4, 0 );
1726 ERR("failed to create image list\n");
1730 for (i=0; i<bm_count; i++)
1732 hbmp = LoadBitmapW( msi_hInstance, MAKEINTRESOURCEW(i+bm_resource) );
1735 ERR("failed to load bitmap %d\n", i);
1740 * Add a dummy bitmap at offset zero because the treeview
1741 * can't use it as a state mask (zero means no user state).
1744 ImageList_Add( himl, hbmp, NULL );
1746 ImageList_Add( himl, hbmp, NULL );
1749 SendMessageW( hwnd, TVM_SETIMAGELIST, TVSIL_STATE, (LPARAM)himl );
1752 static UINT msi_dialog_selection_tree( msi_dialog *dialog, MSIRECORD *rec )
1754 msi_control *control;
1756 MSIPACKAGE *package = dialog->package;
1758 struct msi_selection_tree_info *info;
1760 info = msi_alloc( sizeof *info );
1762 return ERROR_FUNCTION_FAILED;
1764 /* create the treeview control */
1765 prop = MSI_RecordGetString( rec, 9 );
1766 style = TVS_HASLINES | TVS_HASBUTTONS | TVS_LINESATROOT;
1767 style |= WS_GROUP | WS_VSCROLL;
1768 control = msi_dialog_add_control( dialog, rec, WC_TREEVIEWW, style );
1772 return ERROR_FUNCTION_FAILED;
1776 info->dialog = dialog;
1777 info->hwnd = control->hwnd;
1778 info->oldproc = (WNDPROC) SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
1779 (LONG_PTR)MSISelectionTree_WndProc );
1780 SetPropW( control->hwnd, szButtonData, info );
1783 msi_seltree_create_imagelist( control->hwnd );
1784 msi_seltree_add_child_features( package, control->hwnd, NULL, NULL );
1786 return ERROR_SUCCESS;
1789 /******************** Group Box ***************************************/
1791 static UINT msi_dialog_group_box( msi_dialog *dialog, MSIRECORD *rec )
1793 msi_control *control;
1796 style = BS_GROUPBOX | WS_CHILD | WS_GROUP;
1797 control = msi_dialog_add_control( dialog, rec, WC_BUTTONW, style );
1799 return ERROR_FUNCTION_FAILED;
1801 return ERROR_SUCCESS;
1804 /******************** List Box ***************************************/
1806 struct msi_listbox_item
1812 struct msi_listbox_info
1818 struct msi_listbox_item *items;
1821 static LRESULT WINAPI MSIListBox_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
1823 struct msi_listbox_info *info;
1827 TRACE("%p %04x %08x %08lx\n", hWnd, msg, wParam, lParam);
1829 info = GetPropW( hWnd, szButtonData );
1833 r = CallWindowProcW( info->oldproc, hWnd, msg, wParam, lParam );
1838 for (j = 0; j < info->num_items; j++)
1840 msi_free( info->items[j].property );
1841 msi_free( info->items[j].value );
1843 msi_free( info->items );
1845 RemovePropW( hWnd, szButtonData );
1852 static UINT msi_listbox_add_item( MSIRECORD *rec, LPVOID param )
1854 struct msi_listbox_info *info = param;
1855 struct msi_listbox_item *item;
1856 LPCWSTR property, value, text;
1857 static int index = 0;
1859 item = &info->items[index++];
1860 property = MSI_RecordGetString( rec, 1 );
1861 value = MSI_RecordGetString( rec, 3 );
1862 text = MSI_RecordGetString( rec, 4 );
1864 item->property = strdupW( property );
1865 item->value = strdupW( value );
1867 SendMessageW( info->hwnd, LB_ADDSTRING, 0, (LPARAM)text );
1869 return ERROR_SUCCESS;
1872 static UINT msi_listbox_add_items( struct msi_listbox_info *info )
1875 MSIQUERY *view = NULL;
1878 static const WCHAR query[] = {
1879 'S','E','L','E','C','T',' ','*',' ',
1880 'F','R','O','M',' ','`','L','i','s','t','B','o','x','`',' ',
1881 'O','R','D','E','R',' ','B','Y',' ','`','O','r','d','e','r','`',0
1884 r = MSI_OpenQuery( info->dialog->package->db, &view, query );
1885 if ( r != ERROR_SUCCESS )
1888 /* just get the number of records */
1889 r = MSI_IterateRecords( view, &count, NULL, NULL );
1891 info->num_items = count;
1892 info->items = msi_alloc( sizeof(*info->items) * count );
1894 r = MSI_IterateRecords( view, NULL, msi_listbox_add_item, info );
1895 msiobj_release( &view->hdr );
1900 static UINT msi_dialog_listbox_handler( msi_dialog *dialog,
1901 msi_control *control, WPARAM param )
1903 struct msi_listbox_info *info;
1906 if( HIWORD(param) != LBN_SELCHANGE )
1907 return ERROR_SUCCESS;
1909 info = GetPropW( control->hwnd, szButtonData );
1910 index = SendMessageW( control->hwnd, LB_GETCURSEL, 0, 0 );
1912 MSI_SetPropertyW( info->dialog->package,
1913 info->items[index].property, info->items[index].value );
1914 msi_dialog_evaluate_control_conditions( info->dialog );
1916 return ERROR_SUCCESS;
1919 static UINT msi_dialog_list_box( msi_dialog *dialog, MSIRECORD *rec )
1921 struct msi_listbox_info *info;
1922 msi_control *control;
1925 info = msi_alloc( sizeof *info );
1927 return ERROR_FUNCTION_FAILED;
1929 style = WS_TABSTOP | WS_GROUP | WS_CHILD | LBS_STANDARD;
1930 control = msi_dialog_add_control( dialog, rec, WC_LISTBOXW, style );
1932 return ERROR_FUNCTION_FAILED;
1934 control->handler = msi_dialog_listbox_handler;
1937 info->dialog = dialog;
1938 info->hwnd = control->hwnd;
1940 info->oldproc = (WNDPROC)SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
1941 (LONG_PTR)MSIListBox_WndProc );
1942 SetPropW( control->hwnd, szButtonData, info );
1944 msi_listbox_add_items( info );
1946 return ERROR_SUCCESS;
1949 /******************** Directory Combo ***************************************/
1951 static LPWSTR msi_dialog_dup_property( msi_dialog *dialog, LPCWSTR property, BOOL indirect )
1957 return msi_dup_property( dialog->package, property );
1959 return strdupW( property );
1962 static UINT msi_dialog_directory_combo( msi_dialog *dialog, MSIRECORD *rec )
1964 msi_control *control;
1965 LPWSTR path, propval;
1970 /* FIXME: use CBS_OWNERDRAWFIXED and add owner draw code */
1971 style = CBS_DROPDOWNLIST | CBS_HASSTRINGS | WS_CHILD |
1972 WS_GROUP | WS_TABSTOP | WS_VSCROLL;
1973 control = msi_dialog_add_control( dialog, rec, WC_COMBOBOXW, style );
1975 return ERROR_FUNCTION_FAILED;
1977 control->attributes = MSI_RecordGetInteger( rec, 8 );
1978 prop = MSI_RecordGetString( rec, 9 );
1979 control->property = msi_dialog_dup_property( dialog, prop, FALSE );
1981 indirect = control->attributes & msidbControlAttributesIndirect;
1982 propval = msi_dialog_dup_property( dialog, prop, indirect );
1983 path = msi_dup_property( dialog->package, propval );
1985 PathStripPathW( path );
1986 PathRemoveBackslashW( path );
1988 /* FIXME: Add whole directory structure to combo box */
1989 SendMessageW( control->hwnd, CB_ADDSTRING, 0, (LPARAM)path );
1990 SendMessageW( control->hwnd, CB_SETCURSEL, 0, 0 );
1993 msi_free( propval );
1994 return ERROR_SUCCESS;
1997 /******************** Directory List ***************************************/
1999 UINT msi_dialog_directorylist_up( msi_dialog *dialog )
2001 msi_control *control;
2002 LPWSTR prop, path, ptr;
2005 control = msi_dialog_find_control( dialog, szDirectoryList );
2006 indirect = control->attributes & msidbControlAttributesIndirect;
2007 prop = msi_dialog_dup_property( dialog, control->property, indirect );
2009 path = msi_dup_property( dialog->package, prop );
2011 /* strip off the last directory */
2012 ptr = PathFindFileNameW( path );
2013 if (ptr != path) *(ptr - 1) = '\0';
2014 PathAddBackslashW( path );
2016 MSI_SetPropertyW( dialog->package, prop, path );
2021 return ERROR_SUCCESS;
2024 static UINT msi_dialog_directory_list( msi_dialog *dialog, MSIRECORD *rec )
2026 msi_control *control;
2030 style = LVS_LIST | LVS_EDITLABELS | WS_VSCROLL | LVS_SHAREIMAGELISTS |
2031 LVS_AUTOARRANGE | LVS_SINGLESEL | WS_BORDER |
2032 LVS_SORTASCENDING | WS_CHILD | WS_GROUP | WS_TABSTOP;
2033 control = msi_dialog_add_control( dialog, rec, WC_LISTVIEWW, style );
2035 return ERROR_FUNCTION_FAILED;
2037 control->attributes = MSI_RecordGetInteger( rec, 8 );
2038 prop = MSI_RecordGetString( rec, 9 );
2039 control->property = msi_dialog_dup_property( dialog, prop, FALSE );
2041 return ERROR_SUCCESS;
2044 /******************** VolumeCost List ***************************************/
2046 static UINT msi_dialog_volumecost_list( msi_dialog *dialog, MSIRECORD *rec )
2048 msi_control *control;
2051 style = LVS_REPORT | WS_VSCROLL | WS_HSCROLL | LVS_SHAREIMAGELISTS |
2052 LVS_AUTOARRANGE | LVS_SINGLESEL | WS_BORDER |
2053 WS_CHILD | WS_TABSTOP | WS_GROUP;
2054 control = msi_dialog_add_control( dialog, rec, WC_LISTVIEWW, style );
2056 return ERROR_FUNCTION_FAILED;
2058 return ERROR_SUCCESS;
2061 static const struct control_handler msi_dialog_handler[] =
2063 { szText, msi_dialog_text_control },
2064 { szPushButton, msi_dialog_button_control },
2065 { szLine, msi_dialog_line_control },
2066 { szBitmap, msi_dialog_bitmap_control },
2067 { szCheckBox, msi_dialog_checkbox_control },
2068 { szScrollableText, msi_dialog_scrolltext_control },
2069 { szComboBox, msi_dialog_combo_control },
2070 { szEdit, msi_dialog_edit_control },
2071 { szMaskedEdit, msi_dialog_maskedit_control },
2072 { szPathEdit, msi_dialog_pathedit_control },
2073 { szProgressBar, msi_dialog_progress_bar },
2074 { szRadioButtonGroup, msi_dialog_radiogroup_control },
2075 { szIcon, msi_dialog_icon_control },
2076 { szSelectionTree, msi_dialog_selection_tree },
2077 { szGroupBox, msi_dialog_group_box },
2078 { szListBox, msi_dialog_list_box },
2079 { szDirectoryCombo, msi_dialog_directory_combo },
2080 { szDirectoryList, msi_dialog_directory_list },
2081 { szVolumeCostList, msi_dialog_volumecost_list },
2084 #define NUM_CONTROL_TYPES (sizeof msi_dialog_handler/sizeof msi_dialog_handler[0])
2086 static UINT msi_dialog_create_controls( MSIRECORD *rec, LPVOID param )
2088 msi_dialog *dialog = param;
2089 LPCWSTR control_type;
2092 /* find and call the function that can create this type of control */
2093 control_type = MSI_RecordGetString( rec, 3 );
2094 for( i=0; i<NUM_CONTROL_TYPES; i++ )
2095 if (!strcmpiW( msi_dialog_handler[i].control_type, control_type ))
2097 if( i != NUM_CONTROL_TYPES )
2098 msi_dialog_handler[i].func( dialog, rec );
2100 ERR("no handler for element type %s\n", debugstr_w(control_type));
2102 return ERROR_SUCCESS;
2105 static UINT msi_dialog_fill_controls( msi_dialog *dialog )
2107 static const WCHAR query[] = {
2108 'S','E','L','E','C','T',' ','*',' ',
2109 'F','R','O','M',' ','C','o','n','t','r','o','l',' ',
2110 'W','H','E','R','E',' ',
2111 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',0};
2113 MSIQUERY *view = NULL;
2114 MSIPACKAGE *package = dialog->package;
2116 TRACE("%p %s\n", dialog, debugstr_w(dialog->name) );
2118 /* query the Control table for all the elements of the control */
2119 r = MSI_OpenQuery( package->db, &view, query, dialog->name );
2120 if( r != ERROR_SUCCESS )
2122 ERR("query failed for dialog %s\n", debugstr_w(dialog->name));
2123 return ERROR_INVALID_PARAMETER;
2126 r = MSI_IterateRecords( view, 0, msi_dialog_create_controls, dialog );
2127 msiobj_release( &view->hdr );
2132 static UINT msi_dialog_set_control_condition( MSIRECORD *rec, LPVOID param )
2134 static const WCHAR szHide[] = { 'H','i','d','e',0 };
2135 static const WCHAR szShow[] = { 'S','h','o','w',0 };
2136 static const WCHAR szDisable[] = { 'D','i','s','a','b','l','e',0 };
2137 static const WCHAR szEnable[] = { 'E','n','a','b','l','e',0 };
2138 msi_dialog *dialog = param;
2139 msi_control *control;
2140 LPCWSTR name, action, condition;
2143 name = MSI_RecordGetString( rec, 2 );
2144 action = MSI_RecordGetString( rec, 3 );
2145 condition = MSI_RecordGetString( rec, 4 );
2146 r = MSI_EvaluateConditionW( dialog->package, condition );
2147 control = msi_dialog_find_control( dialog, name );
2148 if( r == MSICONDITION_TRUE && control )
2150 TRACE("%s control %s\n", debugstr_w(action), debugstr_w(name));
2152 /* FIXME: case sensitive? */
2153 if(!lstrcmpW(action, szHide))
2154 ShowWindow(control->hwnd, SW_HIDE);
2155 else if(!strcmpW(action, szShow))
2156 ShowWindow(control->hwnd, SW_SHOW);
2157 else if(!strcmpW(action, szDisable))
2158 EnableWindow(control->hwnd, FALSE);
2159 else if(!strcmpW(action, szEnable))
2160 EnableWindow(control->hwnd, TRUE);
2162 FIXME("Unhandled action %s\n", debugstr_w(action));
2165 return ERROR_SUCCESS;
2168 static UINT msi_dialog_evaluate_control_conditions( msi_dialog *dialog )
2170 static const WCHAR query[] = {
2171 'S','E','L','E','C','T',' ','*',' ',
2172 'F','R','O','M',' ',
2173 'C','o','n','t','r','o','l','C','o','n','d','i','t','i','o','n',' ',
2174 'W','H','E','R','E',' ',
2175 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',0
2178 MSIQUERY *view = NULL;
2179 MSIPACKAGE *package = dialog->package;
2181 TRACE("%p %s\n", dialog, debugstr_w(dialog->name) );
2183 /* query the Control table for all the elements of the control */
2184 r = MSI_OpenQuery( package->db, &view, query, dialog->name );
2185 if( r != ERROR_SUCCESS )
2187 ERR("query failed for dialog %s\n", debugstr_w(dialog->name));
2188 return ERROR_INVALID_PARAMETER;
2191 r = MSI_IterateRecords( view, 0, msi_dialog_set_control_condition, dialog );
2192 msiobj_release( &view->hdr );
2197 UINT msi_dialog_reset( msi_dialog *dialog )
2199 /* FIXME: should restore the original values of any properties we changed */
2200 return msi_dialog_evaluate_control_conditions( dialog );
2203 /* figure out the height of 10 point MS Sans Serif */
2204 static INT msi_dialog_get_sans_serif_height( HWND hwnd )
2206 static const WCHAR szSansSerif[] = {
2207 'M','S',' ','S','a','n','s',' ','S','e','r','i','f',0 };
2212 HFONT hFont, hOldFont;
2215 hdc = GetDC( hwnd );
2218 memset( &lf, 0, sizeof lf );
2219 lf.lfHeight = MulDiv(10, GetDeviceCaps(hdc, LOGPIXELSY), 72);
2220 strcpyW( lf.lfFaceName, szSansSerif );
2221 hFont = CreateFontIndirectW(&lf);
2224 hOldFont = SelectObject( hdc, hFont );
2225 r = GetTextMetricsW( hdc, &tm );
2227 height = tm.tmHeight;
2228 SelectObject( hdc, hOldFont );
2229 DeleteObject( hFont );
2231 ReleaseDC( hwnd, hdc );
2236 /* fetch the associated record from the Dialog table */
2237 static MSIRECORD *msi_get_dialog_record( msi_dialog *dialog )
2239 static const WCHAR query[] = {
2240 'S','E','L','E','C','T',' ','*',' ',
2241 'F','R','O','M',' ','D','i','a','l','o','g',' ',
2242 'W','H','E','R','E',' ',
2243 '`','D','i','a','l','o','g','`',' ','=',' ','\'','%','s','\'',0};
2244 MSIPACKAGE *package = dialog->package;
2245 MSIRECORD *rec = NULL;
2247 TRACE("%p %s\n", dialog, debugstr_w(dialog->name) );
2249 rec = MSI_QueryGetRecord( package->db, query, dialog->name );
2251 ERR("query failed for dialog %s\n", debugstr_w(dialog->name));
2256 static void msi_dialog_adjust_dialog_pos( msi_dialog *dialog, MSIRECORD *rec, LPRECT pos )
2258 static const WCHAR szScreenX[] = {'S','c','r','e','e','n','X',0};
2259 static const WCHAR szScreenY[] = {'S','c','r','e','e','n','Y',0};
2266 center.x = MSI_RecordGetInteger( rec, 2 );
2267 center.y = MSI_RecordGetInteger( rec, 3 );
2269 sz.cx = MSI_RecordGetInteger( rec, 4 );
2270 sz.cy = MSI_RecordGetInteger( rec, 5 );
2272 sz.cx = msi_dialog_scale_unit( dialog, sz.cx );
2273 sz.cy = msi_dialog_scale_unit( dialog, sz.cy );
2275 xres = msi_get_property_int( dialog->package, szScreenX, 0 );
2276 yres = msi_get_property_int( dialog->package, szScreenY, 0 );
2278 center.x = MulDiv( center.x, xres, 100 );
2279 center.y = MulDiv( center.y, yres, 100 );
2281 /* turn the client pos into the window rectangle */
2282 pos->left = center.x - sz.cx/2;
2283 pos->right = pos->left + sz.cx;
2284 pos->top = center.y - sz.cy/2;
2285 pos->bottom = pos->top + sz.cy;
2287 TRACE("%lu %lu %lu %lu\n", pos->left, pos->top, pos->right, pos->bottom);
2289 style = GetWindowLongPtrW( dialog->hwnd, GWL_STYLE );
2290 AdjustWindowRect( pos, style, FALSE );
2293 static BOOL msi_control_set_next( msi_control *control, msi_control *next )
2295 return SetWindowPos( next->hwnd, control->hwnd, 0, 0, 0, 0,
2296 SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOREDRAW |
2297 SWP_NOREPOSITION | SWP_NOSENDCHANGING | SWP_NOSIZE );
2300 static UINT msi_dialog_set_tab_order( msi_dialog *dialog )
2302 msi_control *control, *tab_next;
2304 LIST_FOR_EACH_ENTRY( control, &dialog->controls, msi_control, entry )
2306 tab_next = msi_dialog_find_control( dialog, control->tabnext );
2309 msi_control_set_next( control, tab_next );
2312 return ERROR_SUCCESS;
2315 static void msi_dialog_set_first_control( msi_dialog* dialog, LPCWSTR name )
2317 msi_control *control;
2319 control = msi_dialog_find_control( dialog, name );
2321 dialog->hWndFocus = control->hwnd;
2323 dialog->hWndFocus = NULL;
2326 static LRESULT msi_dialog_oncreate( HWND hwnd, LPCREATESTRUCTW cs )
2328 static const WCHAR df[] = {
2329 'D','e','f','a','u','l','t','U','I','F','o','n','t',0 };
2330 static const WCHAR dfv[] = {
2331 'M','S',' ','S','h','e','l','l',' ','D','l','g',0 };
2332 msi_dialog *dialog = (msi_dialog*) cs->lpCreateParams;
2333 MSIRECORD *rec = NULL;
2334 LPWSTR title = NULL;
2337 TRACE("%p %p\n", dialog, dialog->package);
2339 dialog->hwnd = hwnd;
2340 SetWindowLongPtrW( hwnd, GWLP_USERDATA, (LONG_PTR) dialog );
2342 rec = msi_get_dialog_record( dialog );
2345 TRACE("No record found for dialog %s\n", debugstr_w(dialog->name));
2349 dialog->scale = msi_dialog_get_sans_serif_height(dialog->hwnd);
2351 msi_dialog_adjust_dialog_pos( dialog, rec, &pos );
2353 dialog->attributes = MSI_RecordGetInteger( rec, 6 );
2355 dialog->default_font = msi_dup_property( dialog->package, df );
2356 if (!dialog->default_font)
2358 dialog->default_font = strdupW(dfv);
2359 if (!dialog->default_font) return -1;
2362 title = msi_get_deformatted_field( dialog->package, rec, 7 );
2363 SetWindowTextW( hwnd, title );
2366 SetWindowPos( hwnd, 0, pos.left, pos.top,
2367 pos.right - pos.left, pos.bottom - pos.top,
2368 SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOREDRAW );
2370 msi_dialog_build_font_list( dialog );
2371 msi_dialog_fill_controls( dialog );
2372 msi_dialog_evaluate_control_conditions( dialog );
2373 msi_dialog_set_tab_order( dialog );
2374 msi_dialog_set_first_control( dialog, MSI_RecordGetString( rec, 8 ) );
2375 msiobj_release( &rec->hdr );
2380 static UINT msi_dialog_send_event( msi_dialog *dialog, LPCWSTR event, LPCWSTR arg )
2382 LPWSTR event_fmt = NULL, arg_fmt = NULL;
2384 TRACE("Sending control event %s %s\n", debugstr_w(event), debugstr_w(arg));
2386 deformat_string( dialog->package, event, &event_fmt );
2387 deformat_string( dialog->package, arg, &arg_fmt );
2389 dialog->event_handler( dialog->package, event_fmt, arg_fmt, dialog );
2391 msi_free( event_fmt );
2392 msi_free( arg_fmt );
2394 return ERROR_SUCCESS;
2397 static UINT msi_dialog_set_property( msi_dialog *dialog, LPCWSTR event, LPCWSTR arg )
2399 static const WCHAR szNullArg[] = { '{','}',0 };
2400 LPWSTR p, prop, arg_fmt = NULL;
2403 len = strlenW(event);
2404 prop = msi_alloc( len*sizeof(WCHAR));
2405 strcpyW( prop, &event[1] );
2406 p = strchrW( prop, ']' );
2407 if( p && p[1] == 0 )
2410 if( strcmpW( szNullArg, arg ) )
2411 deformat_string( dialog->package, arg, &arg_fmt );
2412 MSI_SetPropertyW( dialog->package, prop, arg_fmt );
2413 msi_free( arg_fmt );
2416 ERR("Badly formatted property string - what happens?\n");
2418 return ERROR_SUCCESS;
2421 static UINT msi_dialog_control_event( MSIRECORD *rec, LPVOID param )
2423 msi_dialog *dialog = param;
2424 LPCWSTR condition, event, arg;
2427 condition = MSI_RecordGetString( rec, 5 );
2428 r = MSI_EvaluateConditionW( dialog->package, condition );
2429 if( r == MSICONDITION_TRUE || r == MSICONDITION_NONE )
2431 event = MSI_RecordGetString( rec, 3 );
2432 arg = MSI_RecordGetString( rec, 4 );
2433 if( event[0] == '[' )
2434 msi_dialog_set_property( dialog, event, arg );
2436 msi_dialog_send_event( dialog, event, arg );
2439 return ERROR_SUCCESS;
2442 static UINT msi_dialog_button_handler( msi_dialog *dialog,
2443 msi_control *control, WPARAM param )
2445 static const WCHAR query[] = {
2446 'S','E','L','E','C','T',' ','*',' ',
2447 'F','R','O','M',' ','C','o','n','t','r','o','l','E','v','e','n','t',' ',
2448 'W','H','E','R','E',' ',
2449 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',' ',
2451 '`','C','o','n','t','r','o','l','_','`',' ','=',' ','\'','%','s','\'',' ',
2452 'O','R','D','E','R',' ','B','Y',' ','`','O','r','d','e','r','i','n','g','`',0
2454 MSIQUERY *view = NULL;
2457 if( HIWORD(param) != BN_CLICKED )
2458 return ERROR_SUCCESS;
2460 r = MSI_OpenQuery( dialog->package->db, &view, query,
2461 dialog->name, control->name );
2462 if( r != ERROR_SUCCESS )
2464 ERR("query failed\n");
2468 r = MSI_IterateRecords( view, 0, msi_dialog_control_event, dialog );
2469 msiobj_release( &view->hdr );
2474 static UINT msi_dialog_get_checkbox_state( msi_dialog *dialog,
2475 msi_control *control )
2477 WCHAR state[2] = { 0 };
2480 MSI_GetPropertyW( dialog->package, control->property, state, &sz );
2481 return state[0] ? 1 : 0;
2484 static void msi_dialog_set_checkbox_state( msi_dialog *dialog,
2485 msi_control *control, UINT state )
2487 static const WCHAR szState[] = { '1', 0 };
2490 /* if uncheck then the property is set to NULL */
2493 MSI_SetPropertyW( dialog->package, control->property, NULL );
2497 /* check for a custom state */
2498 if (control->value && control->value[0])
2499 val = control->value;
2503 MSI_SetPropertyW( dialog->package, control->property, val );
2506 static void msi_dialog_checkbox_sync_state( msi_dialog *dialog,
2507 msi_control *control )
2511 state = msi_dialog_get_checkbox_state( dialog, control );
2512 SendMessageW( control->hwnd, BM_SETCHECK,
2513 state ? BST_CHECKED : BST_UNCHECKED, 0 );
2516 static UINT msi_dialog_checkbox_handler( msi_dialog *dialog,
2517 msi_control *control, WPARAM param )
2521 if( HIWORD(param) != BN_CLICKED )
2522 return ERROR_SUCCESS;
2524 TRACE("clicked checkbox %s, set %s\n", debugstr_w(control->name),
2525 debugstr_w(control->property));
2527 state = msi_dialog_get_checkbox_state( dialog, control );
2528 state = state ? 0 : 1;
2529 msi_dialog_set_checkbox_state( dialog, control, state );
2530 msi_dialog_checkbox_sync_state( dialog, control );
2532 return msi_dialog_button_handler( dialog, control, param );
2535 static UINT msi_dialog_edit_handler( msi_dialog *dialog,
2536 msi_control *control, WPARAM param )
2540 if( HIWORD(param) != EN_CHANGE )
2541 return ERROR_SUCCESS;
2543 TRACE("edit %s contents changed, set %s\n", debugstr_w(control->name),
2544 debugstr_w(control->property));
2546 buf = msi_get_window_text( control->hwnd );
2547 MSI_SetPropertyW( dialog->package, control->property, buf );
2551 return ERROR_SUCCESS;
2554 static UINT msi_dialog_radiogroup_handler( msi_dialog *dialog,
2555 msi_control *control, WPARAM param )
2557 if( HIWORD(param) != BN_CLICKED )
2558 return ERROR_SUCCESS;
2560 TRACE("clicked radio button %s, set %s\n", debugstr_w(control->name),
2561 debugstr_w(control->property));
2563 MSI_SetPropertyW( dialog->package, control->property, control->name );
2565 return msi_dialog_button_handler( dialog, control, param );
2568 static LRESULT msi_dialog_oncommand( msi_dialog *dialog, WPARAM param, HWND hwnd )
2570 msi_control *control = NULL;
2572 TRACE("%p %p %08x\n", dialog, hwnd, param);
2577 control = msi_dialog_find_control( dialog, dialog->control_default );
2579 case 2: /* escape */
2580 control = msi_dialog_find_control( dialog, dialog->control_cancel );
2583 control = msi_dialog_find_control_by_hwnd( dialog, hwnd );
2588 if( control->handler )
2590 control->handler( dialog, control, param );
2591 msi_dialog_evaluate_control_conditions( dialog );
2595 ERR("button click from nowhere %p %d %p\n", dialog, param, hwnd);
2599 static void msi_dialog_setfocus( msi_dialog *dialog )
2601 HWND hwnd = dialog->hWndFocus;
2603 hwnd = GetNextDlgTabItem( dialog->hwnd, hwnd, TRUE);
2604 hwnd = GetNextDlgTabItem( dialog->hwnd, hwnd, FALSE);
2606 dialog->hWndFocus = hwnd;
2609 static LRESULT WINAPI MSIDialog_WndProc( HWND hwnd, UINT msg,
2610 WPARAM wParam, LPARAM lParam )
2612 msi_dialog *dialog = (LPVOID) GetWindowLongPtrW( hwnd, GWLP_USERDATA );
2614 TRACE("0x%04x\n", msg);
2619 return msi_dialog_oncreate( hwnd, (LPCREATESTRUCTW)lParam );
2622 return msi_dialog_oncommand( dialog, wParam, (HWND)lParam );
2625 if( LOWORD(wParam) == WA_INACTIVE )
2626 dialog->hWndFocus = GetFocus();
2628 msi_dialog_setfocus( dialog );
2632 msi_dialog_setfocus( dialog );
2635 /* bounce back to our subclassed static control */
2636 case WM_CTLCOLORSTATIC:
2637 return SendMessageW( (HWND) lParam, WM_CTLCOLORSTATIC, wParam, lParam );
2640 dialog->hwnd = NULL;
2643 return DefWindowProcW(hwnd, msg, wParam, lParam);
2646 static BOOL CALLBACK msi_radioground_child_enum( HWND hWnd, LPARAM lParam )
2648 EnableWindow( hWnd, lParam );
2652 static LRESULT WINAPI MSIRadioGroup_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
2654 WNDPROC oldproc = (WNDPROC) GetPropW(hWnd, szButtonData);
2657 TRACE("hWnd %p msg %04x wParam 0x%08x lParam 0x%08lx\n", hWnd, msg, wParam, lParam);
2659 if (msg == WM_COMMAND) /* Forward notifications to dialog */
2660 SendMessageW(GetParent(hWnd), msg, wParam, lParam);
2662 r = CallWindowProcW(oldproc, hWnd, msg, wParam, lParam);
2664 /* make sure the radio buttons show as disabled if the parent is disabled */
2665 if (msg == WM_ENABLE)
2666 EnumChildWindows( hWnd, msi_radioground_child_enum, wParam );
2671 static LRESULT WINAPI MSIHiddenWindowProc( HWND hwnd, UINT msg,
2672 WPARAM wParam, LPARAM lParam )
2674 msi_dialog *dialog = (msi_dialog*) lParam;
2676 TRACE("%d %p\n", msg, dialog);
2680 case WM_MSI_DIALOG_CREATE:
2681 return msi_dialog_run_message_loop( dialog );
2682 case WM_MSI_DIALOG_DESTROY:
2683 msi_dialog_destroy( dialog );
2686 return DefWindowProcW( hwnd, msg, wParam, lParam );
2689 /* functions that interface to other modules within MSI */
2691 msi_dialog *msi_dialog_create( MSIPACKAGE* package, LPCWSTR szDialogName,
2692 msi_dialog_event_handler event_handler )
2694 MSIRECORD *rec = NULL;
2697 TRACE("%p %s\n", package, debugstr_w(szDialogName));
2699 /* allocate the structure for the dialog to use */
2700 dialog = msi_alloc_zero( sizeof *dialog + sizeof(WCHAR)*strlenW(szDialogName) );
2703 strcpyW( dialog->name, szDialogName );
2704 msiobj_addref( &package->hdr );
2705 dialog->package = package;
2706 dialog->event_handler = event_handler;
2707 dialog->finished = 0;
2708 list_init( &dialog->controls );
2710 /* verify that the dialog exists */
2711 rec = msi_get_dialog_record( dialog );
2714 msiobj_release( &package->hdr );
2718 dialog->attributes = MSI_RecordGetInteger( rec, 6 );
2719 dialog->control_default = strdupW( MSI_RecordGetString( rec, 9 ) );
2720 dialog->control_cancel = strdupW( MSI_RecordGetString( rec, 10 ) );
2721 msiobj_release( &rec->hdr );
2726 static void msi_process_pending_messages( HWND hdlg )
2730 while( PeekMessageW( &msg, 0, 0, 0, PM_REMOVE ) )
2732 if( hdlg && IsDialogMessageW( hdlg, &msg ))
2734 TranslateMessage( &msg );
2735 DispatchMessageW( &msg );
2739 void msi_dialog_end_dialog( msi_dialog *dialog )
2741 TRACE("%p\n", dialog);
2742 dialog->finished = 1;
2743 PostMessageW(dialog->hwnd, WM_NULL, 0, 0);
2746 void msi_dialog_check_messages( HANDLE handle )
2750 /* in threads other than the UI thread, block */
2751 if( uiThreadId != GetCurrentThreadId() )
2754 WaitForSingleObject( handle, INFINITE );
2758 /* there's two choices for the UI thread */
2761 msi_process_pending_messages( NULL );
2767 * block here until somebody creates a new dialog or
2768 * the handle we're waiting on becomes ready
2770 r = MsgWaitForMultipleObjects( 1, &handle, 0, INFINITE, QS_ALLINPUT );
2771 if( r == WAIT_OBJECT_0 )
2776 UINT msi_dialog_run_message_loop( msi_dialog *dialog )
2781 if( uiThreadId != GetCurrentThreadId() )
2782 return SendMessageW( hMsiHiddenWindow, WM_MSI_DIALOG_CREATE, 0, (LPARAM) dialog );
2784 /* create the dialog window, don't show it yet */
2785 style = WS_OVERLAPPED;
2786 if( dialog->attributes & msidbDialogAttributesVisible )
2787 style |= WS_VISIBLE;
2789 hwnd = CreateWindowW( szMsiDialogClass, dialog->name, style,
2790 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
2791 NULL, NULL, NULL, dialog );
2794 ERR("Failed to create dialog %s\n", debugstr_w( dialog->name ));
2795 return ERROR_FUNCTION_FAILED;
2798 ShowWindow( hwnd, SW_SHOW );
2799 /* UpdateWindow( hwnd ); - and causes the transparent static controls not to paint */
2801 if( dialog->attributes & msidbDialogAttributesModal )
2803 while( !dialog->finished )
2805 MsgWaitForMultipleObjects( 0, NULL, 0, INFINITE, QS_ALLINPUT );
2806 msi_process_pending_messages( dialog->hwnd );
2810 return ERROR_IO_PENDING;
2812 return ERROR_SUCCESS;
2815 void msi_dialog_do_preview( msi_dialog *dialog )
2818 dialog->attributes |= msidbDialogAttributesVisible;
2819 dialog->attributes &= ~msidbDialogAttributesModal;
2820 msi_dialog_run_message_loop( dialog );
2823 void msi_dialog_destroy( msi_dialog *dialog )
2825 if( uiThreadId != GetCurrentThreadId() )
2827 SendMessageW( hMsiHiddenWindow, WM_MSI_DIALOG_DESTROY, 0, (LPARAM) dialog );
2832 ShowWindow( dialog->hwnd, SW_HIDE );
2835 DestroyWindow( dialog->hwnd );
2837 /* destroy the list of controls */
2838 while( !list_empty( &dialog->controls ) )
2840 msi_control *t = LIST_ENTRY( list_head( &dialog->controls ),
2841 msi_control, entry );
2842 list_remove( &t->entry );
2843 /* leave dialog->hwnd - destroying parent destroys child windows */
2844 msi_free( t->property );
2845 msi_free( t->value );
2847 DeleteObject( t->hBitmap );
2849 DestroyIcon( t->hIcon );
2850 msi_free( t->tabnext );
2853 FreeLibrary( t->hDll );
2856 /* destroy the list of fonts */
2857 while( dialog->font_list )
2859 msi_font *t = dialog->font_list;
2860 dialog->font_list = t->next;
2861 DeleteObject( t->hfont );
2864 msi_free( dialog->default_font );
2866 msi_free( dialog->control_default );
2867 msi_free( dialog->control_cancel );
2868 msiobj_release( &dialog->package->hdr );
2869 dialog->package = NULL;
2873 BOOL msi_dialog_register_class( void )
2877 ZeroMemory( &cls, sizeof cls );
2878 cls.lpfnWndProc = MSIDialog_WndProc;
2879 cls.hInstance = NULL;
2880 cls.hIcon = LoadIconW(0, (LPWSTR)IDI_APPLICATION);
2881 cls.hCursor = LoadCursorW(0, (LPWSTR)IDC_ARROW);
2882 cls.hbrBackground = (HBRUSH)(COLOR_3DFACE + 1);
2883 cls.lpszMenuName = NULL;
2884 cls.lpszClassName = szMsiDialogClass;
2886 if( !RegisterClassW( &cls ) )
2889 cls.lpfnWndProc = MSIHiddenWindowProc;
2890 cls.lpszClassName = szMsiHiddenWindow;
2892 if( !RegisterClassW( &cls ) )
2895 uiThreadId = GetCurrentThreadId();
2897 hMsiHiddenWindow = CreateWindowW( szMsiHiddenWindow, NULL, WS_OVERLAPPED,
2898 0, 0, 100, 100, NULL, NULL, NULL, NULL );
2899 if( !hMsiHiddenWindow )
2905 void msi_dialog_unregister_class( void )
2907 DestroyWindow( hMsiHiddenWindow );
2908 hMsiHiddenWindow = NULL;
2909 UnregisterClassW( szMsiDialogClass, NULL );
2910 UnregisterClassW( szMsiHiddenWindow, NULL );