2 * Implementation of the Microsoft Installer (msi.dll)
4 * Copyright 2005 Mike McCormack for CodeWeavers
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
32 #include "wine/debug.h"
33 #include "wine/unicode.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(msi);
40 const WCHAR szMsiDialogClass[] = {
41 'M','s','i','D','i','a','l','o','g','C','l','o','s','e','C','l','a','s','s',0
43 const static WCHAR szStatic[] = { 'S','t','a','t','i','c',0 };
44 const static WCHAR szButton[] = { 'B','U','T','T','O','N', 0 };
46 const static WCHAR szButtonData[] = { 'M','S','I','D','A','T','A',0 };
48 struct msi_control_tag;
49 typedef struct msi_control_tag msi_control;
50 typedef UINT (*msi_handler)( msi_dialog *, msi_control *, WPARAM );
52 struct msi_control_tag
54 struct msi_control_tag *next;
61 typedef struct msi_font_tag
63 struct msi_font_tag *next;
71 msi_dialog_event_handler event_handler;
78 msi_control *control_list;
82 typedef UINT (*msi_dialog_control_func)( msi_dialog *dialog, MSIRECORD *rec );
83 struct control_handler
86 msi_dialog_control_func func;
94 } radio_button_group_descr;
96 static UINT msi_dialog_checkbox_handler( msi_dialog *, msi_control *, WPARAM );
97 static void msi_dialog_checkbox_sync_state( msi_dialog *, msi_control * );
98 static UINT msi_dialog_button_handler( msi_dialog *, msi_control *, WPARAM );
99 static UINT msi_dialog_edit_handler( msi_dialog *, msi_control *, WPARAM );
100 static UINT msi_dialog_radiogroup_handler( msi_dialog *, msi_control *, WPARAM param );
101 static LRESULT WINAPI MSIRadioGroup_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
104 INT msi_dialog_scale_unit( msi_dialog *dialog, INT val )
106 return (dialog->scale * val + 5) / 10;
110 * msi_dialog_get_style
112 * Extract the {\style} string from the front of the text to display and
113 * update the pointer.
115 static LPWSTR msi_dialog_get_style( LPCWSTR *text )
118 LPCWSTR p = *text, q;
123 q = strchrW( p, '}' );
131 ret = HeapAlloc( GetProcessHeap(), 0, len*sizeof(WCHAR) );
134 strncpyW( ret, p, len );
139 static UINT msi_dialog_add_font( MSIRECORD *rec, LPVOID param )
141 msi_dialog *dialog = param;
148 /* create a font and add it to the list */
149 name = MSI_RecordGetString( rec, 1 );
150 font = HeapAlloc( GetProcessHeap(), 0,
151 sizeof *font + strlenW( name )*sizeof (WCHAR) );
152 strcpyW( font->name, name );
153 font->next = dialog->font_list;
154 dialog->font_list = font;
156 memset( &lf, 0, sizeof lf );
157 face = MSI_RecordGetString( rec, 2 );
158 lf.lfHeight = MSI_RecordGetInteger( rec, 3 );
159 style = MSI_RecordGetInteger( rec, 5 );
160 if( style & msidbTextStyleStyleBitsBold )
161 lf.lfWeight = FW_BOLD;
162 if( style & msidbTextStyleStyleBitsItalic )
164 if( style & msidbTextStyleStyleBitsUnderline )
165 lf.lfUnderline = TRUE;
166 if( style & msidbTextStyleStyleBitsStrike )
167 lf.lfStrikeOut = TRUE;
168 lstrcpynW( lf.lfFaceName, face, LF_FACESIZE );
170 /* adjust the height */
171 hdc = GetDC( dialog->hwnd );
174 lf.lfHeight = -MulDiv(lf.lfHeight, GetDeviceCaps(hdc, LOGPIXELSY), 72);
175 ReleaseDC( dialog->hwnd, hdc );
178 font->hfont = CreateFontIndirectW( &lf );
180 TRACE("Adding font style %s\n", debugstr_w(font->name) );
182 return ERROR_SUCCESS;
185 static msi_font *msi_dialog_find_font( msi_dialog *dialog, LPCWSTR name )
189 for( font = dialog->font_list; font; font = font->next )
190 if( !strcmpW( font->name, name ) ) /* FIXME: case sensitive? */
196 static UINT msi_dialog_set_font( msi_dialog *dialog, HWND hwnd, LPCWSTR name )
200 font = msi_dialog_find_font( dialog, name );
202 SendMessageW( hwnd, WM_SETFONT, (WPARAM) font->hfont, TRUE );
204 ERR("No font entry for %s\n", debugstr_w(name));
205 return ERROR_SUCCESS;
208 static UINT msi_dialog_build_font_list( msi_dialog *dialog )
210 static const WCHAR query[] = {
211 'S','E','L','E','C','T',' ','*',' ',
212 'F','R','O','M',' ','`','T','e','x','t','S','t','y','l','e','`',' ',0
215 MSIQUERY *view = NULL;
217 TRACE("dialog %p\n", dialog );
219 r = MSI_OpenQuery( dialog->package->db, &view, query );
220 if( r != ERROR_SUCCESS )
223 r = MSI_IterateRecords( view, NULL, msi_dialog_add_font, dialog );
224 msiobj_release( &view->hdr );
229 static msi_control *msi_dialog_create_window( msi_dialog *dialog,
230 MSIRECORD *rec, LPCWSTR szCls, LPCWSTR name, LPCWSTR text,
231 DWORD style, HWND parent )
233 DWORD x, y, width, height;
234 LPWSTR font = NULL, title = NULL;
235 msi_control *control;
237 style |= WS_CHILD | WS_GROUP;
239 control = HeapAlloc( GetProcessHeap(), 0,
240 sizeof *control + strlenW(name)*sizeof(WCHAR) );
241 strcpyW( control->name, name );
242 control->next = dialog->control_list;
243 dialog->control_list = control;
244 control->handler = NULL;
245 control->property = NULL;
247 x = MSI_RecordGetInteger( rec, 4 );
248 y = MSI_RecordGetInteger( rec, 5 );
249 width = MSI_RecordGetInteger( rec, 6 );
250 height = MSI_RecordGetInteger( rec, 7 );
252 x = msi_dialog_scale_unit( dialog, x );
253 y = msi_dialog_scale_unit( dialog, y );
254 width = msi_dialog_scale_unit( dialog, width );
255 height = msi_dialog_scale_unit( dialog, height );
259 font = msi_dialog_get_style( &text );
260 deformat_string( dialog->package, text, &title );
263 control->hwnd = CreateWindowW( szCls, title, style,
264 x, y, width, height, parent, NULL, NULL, NULL );
266 TRACE("Dialog %s control %s hwnd %p\n",
267 debugstr_w(dialog->name), debugstr_w(text), control->hwnd );
269 msi_dialog_set_font( dialog, control->hwnd,
270 font ? font : dialog->default_font );
272 HeapFree( GetProcessHeap(), 0, font );
273 HeapFree( GetProcessHeap(), 0, title );
278 /* everything except radio buttons */
279 static msi_control *msi_dialog_add_control( msi_dialog *dialog,
280 MSIRECORD *rec, LPCWSTR szCls, DWORD style )
285 name = MSI_RecordGetString( rec, 2 );
286 attributes = MSI_RecordGetInteger( rec, 8 );
287 text = MSI_RecordGetString( rec, 10 );
290 if( ~attributes & 2 )
291 style |= WS_DISABLED;
292 return msi_dialog_create_window( dialog, rec, szCls, name, text,
293 style, dialog->hwnd );
296 static UINT msi_dialog_text_control( msi_dialog *dialog, MSIRECORD *rec )
298 TRACE("%p %p\n", dialog, rec);
300 msi_dialog_add_control( dialog, rec, szStatic, 0 );
301 return ERROR_SUCCESS;
304 static UINT msi_dialog_button_control( msi_dialog *dialog, MSIRECORD *rec )
306 msi_control *control;
308 TRACE("%p %p\n", dialog, rec);
310 control = msi_dialog_add_control( dialog, rec, szButton, 0 );
311 control->handler = msi_dialog_button_handler;
313 return ERROR_SUCCESS;
316 static UINT msi_dialog_checkbox_control( msi_dialog *dialog, MSIRECORD *rec )
318 msi_control *control;
321 TRACE("%p %p\n", dialog, rec);
323 control = msi_dialog_add_control( dialog, rec, szButton,
324 BS_CHECKBOX | BS_MULTILINE );
325 control->handler = msi_dialog_checkbox_handler;
326 prop = MSI_RecordGetString( rec, 9 );
328 control->property = strdupW( prop );
329 msi_dialog_checkbox_sync_state( dialog, control );
331 return ERROR_SUCCESS;
334 static UINT msi_dialog_line_control( msi_dialog *dialog, MSIRECORD *rec )
336 TRACE("%p %p\n", dialog, rec);
338 msi_dialog_add_control( dialog, rec, szStatic, SS_ETCHEDHORZ | SS_SUNKEN );
339 return ERROR_SUCCESS;
342 static UINT msi_dialog_scrolltext_control( msi_dialog *dialog, MSIRECORD *rec )
344 const static WCHAR szEdit[] = { 'E','D','I','T',0 };
346 FIXME("%p %p\n", dialog, rec);
348 msi_dialog_add_control( dialog, rec, szEdit, WS_BORDER |
349 ES_MULTILINE | WS_VSCROLL | ES_READONLY | ES_AUTOVSCROLL );
351 return ERROR_SUCCESS;
354 static UINT msi_dialog_bitmap_control( msi_dialog *dialog, MSIRECORD *rec )
356 TRACE("%p %p\n", dialog, rec);
358 msi_dialog_add_control( dialog, rec, szStatic,
359 SS_BITMAP | SS_LEFT | SS_CENTERIMAGE );
360 return ERROR_SUCCESS;
363 static UINT msi_dialog_combo_control( msi_dialog *dialog, MSIRECORD *rec )
365 static const WCHAR szCombo[] = { 'C','O','M','B','O','B','O','X',0 };
367 msi_dialog_add_control( dialog, rec, szCombo,
368 SS_BITMAP | SS_LEFT | SS_CENTERIMAGE );
369 return ERROR_SUCCESS;
372 static UINT msi_dialog_edit_control( msi_dialog *dialog, MSIRECORD *rec )
374 const static WCHAR szEdit[] = { 'E','D','I','T',0 };
375 msi_control *control;
379 control = msi_dialog_add_control( dialog, rec, szEdit, WS_BORDER );
380 control->handler = msi_dialog_edit_handler;
381 prop = MSI_RecordGetString( rec, 9 );
383 control->property = strdupW( prop );
384 val = load_dynamic_property( dialog->package, control->property, NULL );
385 SetWindowTextW( control->hwnd, val );
386 HeapFree( GetProcessHeap(), 0, val );
387 return ERROR_SUCCESS;
390 static UINT msi_dialog_pathedit_control( msi_dialog *dialog, MSIRECORD *rec )
392 FIXME("not implemented properly\n");
393 return msi_dialog_edit_control( dialog, rec );
396 /* radio buttons are a bit different to a normal control */
397 static UINT msi_dialog_create_radiobutton( MSIRECORD *rec, LPVOID param )
399 radio_button_group_descr *group = (radio_button_group_descr *)param;
400 msi_dialog *dialog = group->dialog;
401 msi_control *control;
402 LPCWSTR prop, text, name;
404 DWORD attributes = group->attributes;
406 style = WS_CHILD | BS_AUTORADIOBUTTON | BS_MULTILINE;
407 name = MSI_RecordGetString( rec, 3 );
408 text = MSI_RecordGetString( rec, 8 );
411 if( ~attributes & 2 )
412 style |= WS_DISABLED;
414 control = msi_dialog_create_window( dialog, rec, szButton, name, text,
415 style, group->parent->hwnd );
416 control->handler = msi_dialog_radiogroup_handler;
418 prop = MSI_RecordGetString( rec, 1 );
420 control->property = strdupW( prop );
422 return ERROR_SUCCESS;
425 static UINT msi_dialog_radiogroup_control( msi_dialog *dialog, MSIRECORD *rec )
427 static const WCHAR query[] = {
428 'S','E','L','E','C','T',' ','*',' ',
429 'F','R','O','M',' ','R','a','d','i','o','B','u','t','t','o','n',' ',
430 'W','H','E','R','E',' ',
431 '`','P','r','o','p','e','r','t','y','`',' ','=',' ','\'','%','s','\'',0};
434 msi_control *control;
435 MSIQUERY *view = NULL;
436 radio_button_group_descr group;
437 MSIPACKAGE *package = dialog->package;
439 prop = MSI_RecordGetString( rec, 9 );
441 TRACE("%p %p %s\n", dialog, rec, debugstr_w( prop ));
443 /* Create parent group box to hold radio buttons */
444 control = msi_dialog_add_control( dialog, rec, szButton, BS_OWNERDRAW );
448 WNDPROC oldproc = (WNDPROC) SetWindowLongPtrW(control->hwnd, GWLP_WNDPROC,
449 (LONG_PTR)MSIRadioGroup_WndProc);
450 SetPropW(control->hwnd, szButtonData, oldproc);
454 control->property = strdupW( prop );
456 /* query the Radio Button table for all control in this group */
457 r = MSI_OpenQuery( package->db, &view, query, prop );
458 if( r != ERROR_SUCCESS )
460 ERR("query failed for dialog %s radio group %s\n",
461 debugstr_w(dialog->name), debugstr_w(prop));
462 return ERROR_INVALID_PARAMETER;
465 group.dialog = dialog;
466 group.parent = control;
467 group.attributes = MSI_RecordGetInteger( rec, 8 );
469 r = MSI_IterateRecords( view, 0, msi_dialog_create_radiobutton, &group );
470 msiobj_release( &view->hdr );
475 static const WCHAR szText[] = { 'T','e','x','t',0 };
476 static const WCHAR szPushButton[] = { 'P','u','s','h','B','u','t','t','o','n',0 };
477 static const WCHAR szLine[] = { 'L','i','n','e',0 };
478 static const WCHAR szBitmap[] = { 'B','i','t','m','a','p',0 };
479 static const WCHAR szCheckBox[] = { 'C','h','e','c','k','B','o','x',0 };
480 static const WCHAR szScrollableText[] = {
481 'S','c','r','o','l','l','a','b','l','e','T','e','x','t',0 };
482 static const WCHAR szComboBox[] = { 'C','o','m','b','o','B','o','x',0 };
483 static const WCHAR szEdit[] = { 'E','d','i','t',0 };
484 static const WCHAR szMaskedEdit[] = { 'M','a','s','k','e','d','E','d','i','t',0 };
485 static const WCHAR szPathEdit[] = { 'P','a','t','h','E','d','i','t',0 };
486 static const WCHAR szRadioButtonGroup[] = {
487 'R','a','d','i','o','B','u','t','t','o','n','G','r','o','u','p',0 };
489 struct control_handler msi_dialog_handler[] =
491 { szText, msi_dialog_text_control },
492 { szPushButton, msi_dialog_button_control },
493 { szLine, msi_dialog_line_control },
494 { szBitmap, msi_dialog_bitmap_control },
495 { szCheckBox, msi_dialog_checkbox_control },
496 { szScrollableText, msi_dialog_scrolltext_control },
497 { szComboBox, msi_dialog_combo_control },
498 { szEdit, msi_dialog_edit_control },
499 { szMaskedEdit, msi_dialog_edit_control },
500 { szPathEdit, msi_dialog_pathedit_control },
501 { szRadioButtonGroup, msi_dialog_radiogroup_control },
504 #define NUM_CONTROL_TYPES (sizeof msi_dialog_handler/sizeof msi_dialog_handler[0])
506 static UINT msi_dialog_create_controls( MSIRECORD *rec, LPVOID param )
508 msi_dialog *dialog = param;
509 LPCWSTR control_type;
512 /* find and call the function that can create this type of control */
513 control_type = MSI_RecordGetString( rec, 3 );
514 for( i=0; i<NUM_CONTROL_TYPES; i++ )
515 if (!strcmpiW( msi_dialog_handler[i].control_type, control_type ))
517 if( i != NUM_CONTROL_TYPES )
518 msi_dialog_handler[i].func( dialog, rec );
520 ERR("no handler for element type %s\n", debugstr_w(control_type));
522 return ERROR_SUCCESS;
525 static UINT msi_dialog_fill_controls( msi_dialog *dialog )
527 static const WCHAR query[] = {
528 'S','E','L','E','C','T',' ','*',' ',
529 'F','R','O','M',' ','C','o','n','t','r','o','l',' ',
530 'W','H','E','R','E',' ',
531 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',0};
533 MSIQUERY *view = NULL;
534 MSIPACKAGE *package = dialog->package;
536 TRACE("%p %s\n", dialog, debugstr_w(dialog->name) );
538 /* query the Control table for all the elements of the control */
539 r = MSI_OpenQuery( package->db, &view, query, dialog->name );
540 if( r != ERROR_SUCCESS )
542 ERR("query failed for dialog %s\n", debugstr_w(dialog->name));
543 return ERROR_INVALID_PARAMETER;
546 r = MSI_IterateRecords( view, 0, msi_dialog_create_controls, dialog );
547 msiobj_release( &view->hdr );
552 static msi_control *msi_dialog_find_control( msi_dialog *dialog, LPCWSTR name )
554 msi_control *control;
556 for( control = dialog->control_list; control; control = control->next )
557 if( !strcmpW( control->name, name ) ) /* FIXME: case sensitive? */
562 static msi_control *msi_dialog_find_control_by_hwnd( msi_dialog *dialog, HWND hwnd )
564 msi_control *control;
566 for( control = dialog->control_list; control; control = control->next )
567 if( hwnd == control->hwnd )
572 static UINT msi_dialog_set_control_condition( MSIRECORD *rec, LPVOID param )
574 static const WCHAR szHide[] = { 'H','i','d','e',0 };
575 static const WCHAR szShow[] = { 'S','h','o','w',0 };
576 static const WCHAR szDisable[] = { 'D','i','s','a','b','l','e',0 };
577 static const WCHAR szEnable[] = { 'E','n','a','b','l','e',0 };
578 msi_dialog *dialog = param;
579 msi_control *control;
580 LPCWSTR name, action, condition;
583 name = MSI_RecordGetString( rec, 2 );
584 action = MSI_RecordGetString( rec, 3 );
585 condition = MSI_RecordGetString( rec, 4 );
586 r = MSI_EvaluateConditionW( dialog->package, condition );
587 control = msi_dialog_find_control( dialog, name );
590 TRACE("%s control %s\n", debugstr_w(action), debugstr_w(name));
592 /* FIXME: case sensitive? */
593 if(!strcmpW(action, szHide))
594 ShowWindow(control->hwnd, SW_HIDE);
595 else if(!strcmpW(action, szShow))
596 ShowWindow(control->hwnd, SW_SHOW);
597 else if(!strcmpW(action, szDisable))
598 EnableWindow(control->hwnd, FALSE);
599 else if(!strcmpW(action, szEnable))
600 EnableWindow(control->hwnd, TRUE);
602 FIXME("Unhandled action %s\n", debugstr_w(action));
605 return ERROR_SUCCESS;
608 static UINT msi_dialog_evaluate_control_conditions( msi_dialog *dialog )
610 static const WCHAR query[] = {
611 'S','E','L','E','C','T',' ','*',' ',
613 'C','o','n','t','r','o','l','C','o','n','d','i','t','i','o','n',' ',
614 'W','H','E','R','E',' ',
615 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',0
618 MSIQUERY *view = NULL;
619 MSIPACKAGE *package = dialog->package;
621 TRACE("%p %s\n", dialog, debugstr_w(dialog->name) );
623 /* query the Control table for all the elements of the control */
624 r = MSI_OpenQuery( package->db, &view, query, dialog->name );
625 if( r != ERROR_SUCCESS )
627 ERR("query failed for dialog %s\n", debugstr_w(dialog->name));
628 return ERROR_INVALID_PARAMETER;
631 r = MSI_IterateRecords( view, 0, msi_dialog_set_control_condition, dialog );
632 msiobj_release( &view->hdr );
637 /* figure out the height of 10 point MS Sans Serif */
638 static INT msi_dialog_get_sans_serif_height( HWND hwnd )
640 static const WCHAR szSansSerif[] = {
641 'M','S',' ','S','a','n','s',' ','S','e','r','i','f',0 };
646 HFONT hFont, hOldFont;
652 memset( &lf, 0, sizeof lf );
653 lf.lfHeight = MulDiv(10, GetDeviceCaps(hdc, LOGPIXELSY), 72);
654 strcpyW( lf.lfFaceName, szSansSerif );
655 hFont = CreateFontIndirectW(&lf);
658 hOldFont = SelectObject( hdc, hFont );
659 r = GetTextMetricsW( hdc, &tm );
661 height = tm.tmHeight;
662 SelectObject( hdc, hOldFont );
663 DeleteObject( hFont );
665 ReleaseDC( hwnd, hdc );
670 static LRESULT msi_dialog_oncreate( HWND hwnd, LPCREATESTRUCTW cs )
672 static const WCHAR query[] = {
673 'S','E','L','E','C','T',' ','*',' ',
674 'F','R','O','M',' ','D','i','a','l','o','g',' ',
675 'W','H','E','R','E',' ',
676 '`','D','i','a','l','o','g','`',' ','=',' ','\'','%','s','\'',0};
677 static const WCHAR df[] = {
678 'D','e','f','a','u','l','t','U','I','F','o','n','t',0 };
679 msi_dialog *dialog = (msi_dialog*) cs->lpCreateParams;
680 MSIPACKAGE *package = dialog->package;
681 MSIQUERY *view = NULL;
682 MSIRECORD *rec = NULL;
688 TRACE("%p %p\n", dialog, package);
691 SetWindowLongPtrW( hwnd, GWLP_USERDATA, (LONG_PTR) dialog );
693 /* fetch the associated record from the Dialog table */
694 r = MSI_OpenQuery( package->db, &view, query, dialog->name );
695 if( r != ERROR_SUCCESS )
697 ERR("query failed for dialog %s\n", debugstr_w(dialog->name));
700 MSI_ViewExecute( view, NULL );
701 MSI_ViewFetch( view, &rec );
702 MSI_ViewClose( view );
703 msiobj_release( &view->hdr );
707 TRACE("No record found for dialog %s\n", debugstr_w(dialog->name));
711 dialog->scale = msi_dialog_get_sans_serif_height(dialog->hwnd);
713 width = MSI_RecordGetInteger( rec, 4 );
714 height = MSI_RecordGetInteger( rec, 5 );
715 dialog->attributes = MSI_RecordGetInteger( rec, 6 );
716 text = MSI_RecordGetString( rec, 7 );
718 width = msi_dialog_scale_unit( dialog, width );
719 height = msi_dialog_scale_unit( dialog, height ) + 25; /* FIXME */
721 dialog->default_font = load_dynamic_property( dialog->package, df, NULL );
723 deformat_string( dialog->package, text, &title );
724 SetWindowTextW( hwnd, title );
725 SetWindowPos( hwnd, 0, 0, 0, width, height,
726 SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOREDRAW );
728 HeapFree( GetProcessHeap(), 0, title );
729 msiobj_release( &rec->hdr );
731 msi_dialog_build_font_list( dialog );
732 msi_dialog_fill_controls( dialog );
733 msi_dialog_evaluate_control_conditions( dialog );
738 static UINT msi_dialog_send_event( msi_dialog *dialog, LPCWSTR event, LPCWSTR arg )
740 LPWSTR event_fmt = NULL, arg_fmt = NULL;
742 TRACE("Sending control event %s %s\n", debugstr_w(event), debugstr_w(arg));
744 deformat_string( dialog->package, event, &event_fmt );
745 deformat_string( dialog->package, arg, &arg_fmt );
747 dialog->event_handler( dialog->package, event_fmt, arg_fmt, dialog );
749 HeapFree( GetProcessHeap(), 0, event_fmt );
750 HeapFree( GetProcessHeap(), 0, arg_fmt );
752 return ERROR_SUCCESS;
755 static UINT msi_dialog_set_property( msi_dialog *dialog, LPCWSTR event, LPCWSTR arg )
757 static const WCHAR szNullArg[] = { '{','}',0 };
758 LPWSTR p, prop, arg_fmt = NULL;
761 len = strlenW(event);
762 prop = HeapAlloc( GetProcessHeap(), 0, len*sizeof(WCHAR));
763 strcpyW( prop, &event[1] );
764 p = strchrW( prop, ']' );
768 if( strcmpW( szNullArg, arg ) )
769 deformat_string( dialog->package, arg, &arg_fmt );
770 MSI_SetPropertyW( dialog->package, prop, arg_fmt );
773 ERR("Badly formatted property string - what happens?\n");
774 HeapFree( GetProcessHeap(), 0, prop );
775 return ERROR_SUCCESS;
778 static UINT msi_dialog_control_event( MSIRECORD *rec, LPVOID param )
780 msi_dialog *dialog = param;
781 LPCWSTR condition, event, arg;
784 condition = MSI_RecordGetString( rec, 5 );
785 r = MSI_EvaluateConditionW( dialog->package, condition );
788 event = MSI_RecordGetString( rec, 3 );
789 arg = MSI_RecordGetString( rec, 4 );
790 if( event[0] == '[' )
791 msi_dialog_set_property( dialog, event, arg );
793 msi_dialog_send_event( dialog, event, arg );
796 return ERROR_SUCCESS;
799 static UINT msi_dialog_button_handler( msi_dialog *dialog,
800 msi_control *control, WPARAM param )
802 static const WCHAR query[] = {
803 'S','E','L','E','C','T',' ','*',' ',
804 'F','R','O','M',' ','C','o','n','t','r','o','l','E','v','e','n','t',' ',
805 'W','H','E','R','E',' ',
806 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',' ',
808 '`','C','o','n','t','r','o','l','_','`',' ','=',' ','\'','%','s','\'',' ',
809 'O','R','D','E','R',' ','B','Y',' ','`','O','r','d','e','r','i','n','g','`',0
811 MSIQUERY *view = NULL;
814 if( HIWORD(param) != BN_CLICKED )
815 return ERROR_SUCCESS;
817 r = MSI_OpenQuery( dialog->package->db, &view, query,
818 dialog->name, control->name );
819 if( r != ERROR_SUCCESS )
821 ERR("query failed\n");
825 r = MSI_IterateRecords( view, 0, msi_dialog_control_event, dialog );
826 msiobj_release( &view->hdr );
831 static UINT msi_dialog_get_checkbox_state( msi_dialog *dialog,
832 msi_control *control )
834 WCHAR state[2] = { 0 };
837 MSI_GetPropertyW( dialog->package, control->property, state, &sz );
838 return atoiW( state ) ? 1 : 0;
841 static void msi_dialog_set_checkbox_state( msi_dialog *dialog,
842 msi_control *control, UINT state )
844 WCHAR szState[2] = { '0', 0 };
848 MSI_SetPropertyW( dialog->package, control->property, szState );
851 static void msi_dialog_checkbox_sync_state( msi_dialog *dialog,
852 msi_control *control )
856 state = msi_dialog_get_checkbox_state( dialog, control );
857 SendMessageW( control->hwnd, BM_SETCHECK,
858 state ? BST_CHECKED : BST_UNCHECKED, 0 );
861 static UINT msi_dialog_checkbox_handler( msi_dialog *dialog,
862 msi_control *control, WPARAM param )
866 if( HIWORD(param) != BN_CLICKED )
867 return ERROR_SUCCESS;
869 TRACE("clicked checkbox %s, set %s\n", debugstr_w(control->name),
870 debugstr_w(control->property));
872 state = msi_dialog_get_checkbox_state( dialog, control );
873 state = state ? 0 : 1;
874 msi_dialog_set_checkbox_state( dialog, control, state );
875 msi_dialog_checkbox_sync_state( dialog, control );
877 return msi_dialog_button_handler( dialog, control, param );
880 static UINT msi_dialog_edit_handler( msi_dialog *dialog,
881 msi_control *control, WPARAM param )
886 if( HIWORD(param) != EN_CHANGE )
887 return ERROR_SUCCESS;
889 TRACE("edit %s contents changed, set %s\n", debugstr_w(control->name),
890 debugstr_w(control->property));
893 buf = HeapAlloc( GetProcessHeap(), 0, sz*sizeof(WCHAR) );
896 r = GetWindowTextW( control->hwnd, buf, sz );
900 buf = HeapReAlloc( GetProcessHeap(), 0, buf, sz*sizeof(WCHAR) );
903 MSI_SetPropertyW( dialog->package, control->property, buf );
905 HeapFree( GetProcessHeap(), 0, buf );
907 return ERROR_SUCCESS;
910 static UINT msi_dialog_radiogroup_handler( msi_dialog *dialog,
911 msi_control *control, WPARAM param )
913 if( HIWORD(param) != BN_CLICKED )
914 return ERROR_SUCCESS;
916 TRACE("clicked radio button %s, set %s\n", debugstr_w(control->name),
917 debugstr_w(control->property));
919 MSI_SetPropertyW( dialog->package, control->property, control->name );
921 return msi_dialog_button_handler( dialog, control, param );
924 static LRESULT msi_dialog_oncommand( msi_dialog *dialog, WPARAM param, HWND hwnd )
926 msi_control *control;
928 TRACE("%p %p %08x\n", dialog, hwnd, param);
930 control = msi_dialog_find_control_by_hwnd( dialog, hwnd );
933 if( control->handler )
935 control->handler( dialog, control, param );
936 msi_dialog_evaluate_control_conditions( dialog );
940 ERR("button click from nowhere\n");
944 static LRESULT WINAPI MSIDialog_WndProc( HWND hwnd, UINT msg,
945 WPARAM wParam, LPARAM lParam )
947 msi_dialog *dialog = (LPVOID) GetWindowLongPtrW( hwnd, GWLP_USERDATA );
949 TRACE(" 0x%04x\n", msg);
953 return msi_dialog_oncreate( hwnd, (LPCREATESTRUCTW)lParam );
956 return msi_dialog_oncommand( dialog, wParam, (HWND)lParam );
962 return DefWindowProcW(hwnd, msg, wParam, lParam);
965 /* functions that interface to other modules within MSI */
967 msi_dialog *msi_dialog_create( MSIPACKAGE* package, LPCWSTR szDialogName,
968 msi_dialog_event_handler event_handler )
973 TRACE("%p %s\n", package, debugstr_w(szDialogName));
975 /* allocate the structure for the dialog to use */
976 dialog = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
977 sizeof *dialog + sizeof(WCHAR)*strlenW(szDialogName) );
980 strcpyW( dialog->name, szDialogName );
981 dialog->package = package;
982 dialog->event_handler = event_handler;
984 /* create the dialog window, don't show it yet */
985 hwnd = CreateWindowW( szMsiDialogClass, szDialogName, WS_OVERLAPPEDWINDOW,
986 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
987 NULL, NULL, NULL, dialog );
990 ERR("Failed to create dialog %s\n", debugstr_w( szDialogName ));
991 msi_dialog_destroy( dialog );
998 void msi_dialog_end_dialog( msi_dialog *dialog )
1000 dialog->finished = 1;
1003 UINT msi_dialog_run_message_loop( msi_dialog *dialog )
1007 if( dialog->attributes & msidbDialogAttributesVisible )
1009 ShowWindow( dialog->hwnd, SW_SHOW );
1010 UpdateWindow( dialog->hwnd );
1013 if( dialog->attributes & msidbDialogAttributesModal )
1015 while( !dialog->finished && GetMessageW( &msg, 0, 0, 0 ) )
1017 TranslateMessage( &msg );
1018 DispatchMessageW( &msg );
1022 return ERROR_IO_PENDING;
1024 return ERROR_SUCCESS;
1027 void msi_dialog_check_messages( msi_dialog *dialog, HANDLE handle )
1034 while( PeekMessageW( &msg, 0, 0, 0, PM_REMOVE ) )
1036 TranslateMessage( &msg );
1037 DispatchMessageW( &msg );
1041 r = MsgWaitForMultipleObjects( 1, &handle, 0, INFINITE, QS_ALLEVENTS );
1043 while( WAIT_OBJECT_0 != r );
1046 void msi_dialog_do_preview( msi_dialog *dialog )
1048 dialog->attributes |= msidbDialogAttributesVisible;
1049 dialog->attributes &= ~msidbDialogAttributesModal;
1050 msi_dialog_run_message_loop( dialog );
1053 void msi_dialog_destroy( msi_dialog *dialog )
1056 ShowWindow( dialog->hwnd, SW_HIDE );
1058 /* destroy the list of controls */
1059 while( dialog->control_list )
1061 msi_control *t = dialog->control_list;
1062 dialog->control_list = t->next;
1063 /* leave dialog->hwnd - destroying parent destroys child windows */
1064 HeapFree( GetProcessHeap(), 0, t->property );
1065 HeapFree( GetProcessHeap(), 0, t );
1068 /* destroy the list of fonts */
1069 while( dialog->font_list )
1071 msi_font *t = dialog->font_list;
1072 dialog->font_list = t->next;
1073 DeleteObject( t->hfont );
1074 HeapFree( GetProcessHeap(), 0, t );
1076 HeapFree( GetProcessHeap(), 0, dialog->default_font );
1079 DestroyWindow( dialog->hwnd );
1081 dialog->package = NULL;
1082 HeapFree( GetProcessHeap(), 0, dialog );
1085 void msi_dialog_register_class( void )
1089 ZeroMemory( &cls, sizeof cls );
1090 cls.lpfnWndProc = MSIDialog_WndProc;
1091 cls.hInstance = NULL;
1092 cls.hIcon = LoadIconW(0, (LPWSTR)IDI_APPLICATION);
1093 cls.hCursor = LoadCursorW(0, (LPWSTR)IDC_ARROW);
1094 cls.hbrBackground = (HBRUSH)(COLOR_WINDOW);
1095 cls.lpszMenuName = NULL;
1096 cls.lpszClassName = szMsiDialogClass;
1098 RegisterClassW( &cls );
1101 void msi_dialog_unregister_class( void )
1103 UnregisterClassW( szMsiDialogClass, NULL );
1106 static LRESULT WINAPI MSIRadioGroup_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
1108 WNDPROC oldproc = (WNDPROC) GetPropW(hWnd, szButtonData);
1110 TRACE("hWnd %p msg %04x wParam 0x%08x lParam 0x%08lx\n", hWnd, msg, wParam, lParam);
1112 if (msg == WM_COMMAND) /* Forward notifications to dialog */
1113 SendMessageW(GetParent(hWnd), msg, wParam, lParam);
1115 return CallWindowProcW(oldproc, hWnd, msg, wParam, lParam);