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_add_control( msi_dialog *dialog,
230 MSIRECORD *rec, LPCWSTR szCls, DWORD style )
232 DWORD x, y, width, height, attributes;
234 LPWSTR font = NULL, title = NULL;
235 msi_control *control = NULL;
237 style |= WS_CHILD | WS_GROUP;
239 name = MSI_RecordGetString( rec, 2 );
240 control = HeapAlloc( GetProcessHeap(), 0,
241 sizeof *control + strlenW(name)*sizeof(WCHAR) );
242 strcpyW( control->name, name );
243 control->next = dialog->control_list;
244 dialog->control_list = control;
245 control->handler = NULL;
246 control->property = NULL;
248 x = MSI_RecordGetInteger( rec, 4 );
249 y = MSI_RecordGetInteger( rec, 5 );
250 width = MSI_RecordGetInteger( rec, 6 );
251 height = MSI_RecordGetInteger( rec, 7 );
252 attributes = MSI_RecordGetInteger( rec, 8 );
253 text = MSI_RecordGetString( rec, 10 );
255 TRACE("Dialog %s control %s\n", debugstr_w(dialog->name), debugstr_w(text));
257 x = msi_dialog_scale_unit( dialog, x );
258 y = msi_dialog_scale_unit( dialog, y );
259 width = msi_dialog_scale_unit( dialog, width );
260 height = msi_dialog_scale_unit( dialog, height );
264 if( ~attributes & 2 )
265 style |= WS_DISABLED;
268 font = msi_dialog_get_style( &text );
269 deformat_string( dialog->package, text, &title );
271 control->hwnd = CreateWindowW( szCls, title, style,
272 x, y, width, height, dialog->hwnd, NULL, NULL, NULL );
273 msi_dialog_set_font( dialog, control->hwnd,
274 font ? font : dialog->default_font );
275 HeapFree( GetProcessHeap(), 0, font );
276 HeapFree( GetProcessHeap(), 0, title );
280 static UINT msi_dialog_text_control( msi_dialog *dialog, MSIRECORD *rec )
282 TRACE("%p %p\n", dialog, rec);
284 msi_dialog_add_control( dialog, rec, szStatic, 0 );
285 return ERROR_SUCCESS;
288 static UINT msi_dialog_button_control( msi_dialog *dialog, MSIRECORD *rec )
290 msi_control *control;
292 TRACE("%p %p\n", dialog, rec);
294 control = msi_dialog_add_control( dialog, rec, szButton, 0 );
295 control->handler = msi_dialog_button_handler;
297 return ERROR_SUCCESS;
300 static UINT msi_dialog_checkbox_control( msi_dialog *dialog, MSIRECORD *rec )
302 msi_control *control;
305 TRACE("%p %p\n", dialog, rec);
307 control = msi_dialog_add_control( dialog, rec, szButton,
308 BS_CHECKBOX | BS_MULTILINE );
309 control->handler = msi_dialog_checkbox_handler;
310 prop = MSI_RecordGetString( rec, 9 );
312 control->property = strdupW( prop );
313 msi_dialog_checkbox_sync_state( dialog, control );
315 return ERROR_SUCCESS;
318 static UINT msi_dialog_line_control( msi_dialog *dialog, MSIRECORD *rec )
320 TRACE("%p %p\n", dialog, rec);
322 msi_dialog_add_control( dialog, rec, szStatic, SS_ETCHEDHORZ | SS_SUNKEN );
323 return ERROR_SUCCESS;
326 static UINT msi_dialog_scrolltext_control( msi_dialog *dialog, MSIRECORD *rec )
328 const static WCHAR szEdit[] = { 'E','D','I','T',0 };
330 TRACE("%p %p\n", dialog, rec);
332 msi_dialog_add_control( dialog, rec, szEdit, WS_BORDER |
333 ES_MULTILINE | WS_VSCROLL | ES_READONLY | ES_AUTOVSCROLL );
335 return ERROR_SUCCESS;
338 static UINT msi_dialog_bitmap_control( msi_dialog *dialog, MSIRECORD *rec )
340 TRACE("%p %p\n", dialog, rec);
342 msi_dialog_add_control( dialog, rec, szStatic,
343 SS_BITMAP | SS_LEFT | SS_CENTERIMAGE );
344 return ERROR_SUCCESS;
347 static UINT msi_dialog_combo_control( msi_dialog *dialog, MSIRECORD *rec )
349 static const WCHAR szCombo[] = { 'C','O','M','B','O','B','O','X',0 };
351 msi_dialog_add_control( dialog, rec, szCombo,
352 SS_BITMAP | SS_LEFT | SS_CENTERIMAGE );
353 return ERROR_SUCCESS;
356 static UINT msi_dialog_edit_control( msi_dialog *dialog, MSIRECORD *rec )
358 const static WCHAR szEdit[] = { 'E','D','I','T',0 };
359 msi_control *control;
363 control = msi_dialog_add_control( dialog, rec, szEdit, WS_BORDER );
364 control->handler = msi_dialog_edit_handler;
365 prop = MSI_RecordGetString( rec, 9 );
367 control->property = strdupW( prop );
368 val = load_dynamic_property( dialog->package, control->property, NULL );
369 SetWindowTextW( control->hwnd, val );
370 HeapFree( GetProcessHeap(), 0, val );
371 return ERROR_SUCCESS;
374 static UINT msi_dialog_pathedit_control( msi_dialog *dialog, MSIRECORD *rec )
376 FIXME("not implemented properly\n");
377 return msi_dialog_edit_control( dialog, rec );
380 static UINT msi_dialog_create_radiobutton( MSIRECORD *rec, LPVOID param )
382 radio_button_group_descr *group = (radio_button_group_descr *)param;
383 msi_dialog *dialog = group->dialog;
384 msi_control *control;
386 DWORD x, y, width, height, style;
387 DWORD attributes = group->attributes;
389 LPWSTR font = NULL, title = NULL;
391 style = WS_CHILD | BS_AUTORADIOBUTTON | BS_MULTILINE;
392 name = MSI_RecordGetString( rec, 3 );
393 control = HeapAlloc( GetProcessHeap(), 0,
394 sizeof *control + strlenW(name)*sizeof(WCHAR) );
395 strcpyW( control->name, name );
396 control->next = dialog->control_list;
397 dialog->control_list = control;
399 x = MSI_RecordGetInteger( rec, 4 );
400 y = MSI_RecordGetInteger( rec, 5 );
401 width = MSI_RecordGetInteger( rec, 6 );
402 height = MSI_RecordGetInteger( rec, 7 );
403 text = MSI_RecordGetString( rec, 8 );
405 x = msi_dialog_scale_unit( dialog, x );
406 y = msi_dialog_scale_unit( dialog, y );
407 width = msi_dialog_scale_unit( dialog, width );
408 height = msi_dialog_scale_unit( dialog, height );
412 if( ~attributes & 2 )
413 style |= WS_DISABLED;
417 font = msi_dialog_get_style( &text );
418 deformat_string( dialog->package, text, &title );
421 control->hwnd = CreateWindowW( szButton, title, style, x, y, width, height,
422 group->parent->hwnd, NULL, NULL, NULL );
424 TRACE("Dialog %s control %s hwnd %p\n", debugstr_w(dialog->name), debugstr_w(text), control->hwnd);
426 msi_dialog_set_font( dialog, control->hwnd,
427 font ? font : dialog->default_font );
429 HeapFree( GetProcessHeap(), 0, font );
430 HeapFree( GetProcessHeap(), 0, title );
432 control->handler = msi_dialog_radiogroup_handler;
434 prop = MSI_RecordGetString( rec, 1 );
436 control->property = strdupW( prop );
438 return ERROR_SUCCESS;
441 static UINT msi_dialog_radiogroup_control( msi_dialog *dialog, MSIRECORD *rec )
443 static const WCHAR query[] = {
444 'S','E','L','E','C','T',' ','*',' ',
445 'F','R','O','M',' ','R','a','d','i','o','B','u','t','t','o','n',' ',
446 'W','H','E','R','E',' ',
447 '`','P','r','o','p','e','r','t','y','`',' ','=',' ','\'','%','s','\'',0};
450 msi_control *control;
451 MSIQUERY *view = NULL;
452 radio_button_group_descr group;
453 MSIPACKAGE *package = dialog->package;
455 prop = MSI_RecordGetString( rec, 9 );
457 TRACE("%p %p %s\n", dialog, rec, debugstr_w( prop ));
459 /* Create parent group box to hold radio buttons */
460 control = msi_dialog_add_control( dialog, rec, szButton, BS_OWNERDRAW );
464 WNDPROC oldproc = (WNDPROC) SetWindowLongPtrW(control->hwnd, GWLP_WNDPROC,
465 (LONG_PTR)MSIRadioGroup_WndProc);
466 SetPropW(control->hwnd, szButtonData, oldproc);
470 control->property = strdupW( prop );
472 /* query the Radio Button table for all control in this group */
473 r = MSI_OpenQuery( package->db, &view, query, prop );
474 if( r != ERROR_SUCCESS )
476 ERR("query failed for dialog %s radio group %s\n",
477 debugstr_w(dialog->name), debugstr_w(prop));
478 return ERROR_INVALID_PARAMETER;
481 group.dialog = dialog;
482 group.parent = control;
483 group.attributes = MSI_RecordGetInteger( rec, 8 );
485 r = MSI_IterateRecords( view, 0, msi_dialog_create_radiobutton, &group );
486 msiobj_release( &view->hdr );
491 static const WCHAR szText[] = { 'T','e','x','t',0 };
492 static const WCHAR szPushButton[] = { 'P','u','s','h','B','u','t','t','o','n',0 };
493 static const WCHAR szLine[] = { 'L','i','n','e',0 };
494 static const WCHAR szBitmap[] = { 'B','i','t','m','a','p',0 };
495 static const WCHAR szCheckBox[] = { 'C','h','e','c','k','B','o','x',0 };
496 static const WCHAR szScrollableText[] = {
497 'S','c','r','o','l','l','a','b','l','e','T','e','x','t',0 };
498 static const WCHAR szComboBox[] = { 'C','o','m','b','o','B','o','x',0 };
499 static const WCHAR szEdit[] = { 'E','d','i','t',0 };
500 static const WCHAR szMaskedEdit[] = { 'M','a','s','k','e','d','E','d','i','t',0 };
501 static const WCHAR szPathEdit[] = { 'P','a','t','h','E','d','i','t',0 };
502 static const WCHAR szRadioButtonGroup[] = {
503 'R','a','d','i','o','B','u','t','t','o','n','G','r','o','u','p',0 };
505 struct control_handler msi_dialog_handler[] =
507 { szText, msi_dialog_text_control },
508 { szPushButton, msi_dialog_button_control },
509 { szLine, msi_dialog_line_control },
510 { szBitmap, msi_dialog_bitmap_control },
511 { szCheckBox, msi_dialog_checkbox_control },
512 { szScrollableText, msi_dialog_scrolltext_control },
513 { szComboBox, msi_dialog_combo_control },
514 { szEdit, msi_dialog_edit_control },
515 { szMaskedEdit, msi_dialog_edit_control },
516 { szPathEdit, msi_dialog_pathedit_control },
517 { szRadioButtonGroup, msi_dialog_radiogroup_control },
520 #define NUM_CONTROL_TYPES (sizeof msi_dialog_handler/sizeof msi_dialog_handler[0])
522 static UINT msi_dialog_create_controls( MSIRECORD *rec, LPVOID param )
524 msi_dialog *dialog = param;
525 LPCWSTR control_type;
528 /* find and call the function that can create this type of control */
529 control_type = MSI_RecordGetString( rec, 3 );
530 for( i=0; i<NUM_CONTROL_TYPES; i++ )
531 if (!strcmpiW( msi_dialog_handler[i].control_type, control_type ))
533 if( i != NUM_CONTROL_TYPES )
534 msi_dialog_handler[i].func( dialog, rec );
536 ERR("no handler for element type %s\n", debugstr_w(control_type));
538 return ERROR_SUCCESS;
541 static UINT msi_dialog_fill_controls( msi_dialog *dialog )
543 static const WCHAR query[] = {
544 'S','E','L','E','C','T',' ','*',' ',
545 'F','R','O','M',' ','C','o','n','t','r','o','l',' ',
546 'W','H','E','R','E',' ',
547 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',0};
549 MSIQUERY *view = NULL;
550 MSIPACKAGE *package = dialog->package;
552 TRACE("%p %s\n", dialog, debugstr_w(dialog->name) );
554 /* query the Control table for all the elements of the control */
555 r = MSI_OpenQuery( package->db, &view, query, dialog->name );
556 if( r != ERROR_SUCCESS )
558 ERR("query failed for dialog %s\n", debugstr_w(dialog->name));
559 return ERROR_INVALID_PARAMETER;
562 r = MSI_IterateRecords( view, 0, msi_dialog_create_controls, dialog );
563 msiobj_release( &view->hdr );
568 static msi_control *msi_dialog_find_control( msi_dialog *dialog, LPCWSTR name )
570 msi_control *control;
572 for( control = dialog->control_list; control; control = control->next )
573 if( !strcmpW( control->name, name ) ) /* FIXME: case sensitive? */
578 static msi_control *msi_dialog_find_control_by_hwnd( msi_dialog *dialog, HWND hwnd )
580 msi_control *control;
582 for( control = dialog->control_list; control; control = control->next )
583 if( hwnd == control->hwnd )
588 static UINT msi_dialog_set_control_condition( MSIRECORD *rec, LPVOID param )
590 static const WCHAR szHide[] = { 'H','i','d','e',0 };
591 static const WCHAR szShow[] = { 'S','h','o','w',0 };
592 static const WCHAR szDisable[] = { 'D','i','s','a','b','l','e',0 };
593 static const WCHAR szEnable[] = { 'E','n','a','b','l','e',0 };
594 msi_dialog *dialog = param;
595 msi_control *control;
596 LPCWSTR name, action, condition;
599 name = MSI_RecordGetString( rec, 2 );
600 action = MSI_RecordGetString( rec, 3 );
601 condition = MSI_RecordGetString( rec, 4 );
602 r = MSI_EvaluateConditionW( dialog->package, condition );
603 control = msi_dialog_find_control( dialog, name );
606 TRACE("%s control %s\n", debugstr_w(action), debugstr_w(name));
608 /* FIXME: case sensitive? */
609 if(!strcmpW(action, szHide))
610 ShowWindow(control->hwnd, SW_HIDE);
611 else if(!strcmpW(action, szShow))
612 ShowWindow(control->hwnd, SW_SHOW);
613 else if(!strcmpW(action, szDisable))
614 EnableWindow(control->hwnd, FALSE);
615 else if(!strcmpW(action, szEnable))
616 EnableWindow(control->hwnd, TRUE);
618 FIXME("Unhandled action %s\n", debugstr_w(action));
621 return ERROR_SUCCESS;
624 static UINT msi_dialog_evaluate_control_conditions( msi_dialog *dialog )
626 static const WCHAR query[] = {
627 'S','E','L','E','C','T',' ','*',' ',
629 'C','o','n','t','r','o','l','C','o','n','d','i','t','i','o','n',' ',
630 'W','H','E','R','E',' ',
631 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',0
634 MSIQUERY *view = NULL;
635 MSIPACKAGE *package = dialog->package;
637 TRACE("%p %s\n", dialog, debugstr_w(dialog->name) );
639 /* query the Control table for all the elements of the control */
640 r = MSI_OpenQuery( package->db, &view, query, dialog->name );
641 if( r != ERROR_SUCCESS )
643 ERR("query failed for dialog %s\n", debugstr_w(dialog->name));
644 return ERROR_INVALID_PARAMETER;
647 r = MSI_IterateRecords( view, 0, msi_dialog_set_control_condition, dialog );
648 msiobj_release( &view->hdr );
653 /* figure out the height of 10 point MS Sans Serif */
654 static INT msi_dialog_get_sans_serif_height( HWND hwnd )
656 static const WCHAR szSansSerif[] = {
657 'M','S',' ','S','a','n','s',' ','S','e','r','i','f',0 };
662 HFONT hFont, hOldFont;
668 memset( &lf, 0, sizeof lf );
669 lf.lfHeight = MulDiv(10, GetDeviceCaps(hdc, LOGPIXELSY), 72);
670 strcpyW( lf.lfFaceName, szSansSerif );
671 hFont = CreateFontIndirectW(&lf);
674 hOldFont = SelectObject( hdc, hFont );
675 r = GetTextMetricsW( hdc, &tm );
677 height = tm.tmHeight;
678 SelectObject( hdc, hOldFont );
679 DeleteObject( hFont );
681 ReleaseDC( hwnd, hdc );
686 static LRESULT msi_dialog_oncreate( HWND hwnd, LPCREATESTRUCTW cs )
688 static const WCHAR query[] = {
689 'S','E','L','E','C','T',' ','*',' ',
690 'F','R','O','M',' ','D','i','a','l','o','g',' ',
691 'W','H','E','R','E',' ',
692 '`','D','i','a','l','o','g','`',' ','=',' ','\'','%','s','\'',0};
693 static const WCHAR df[] = {
694 'D','e','f','a','u','l','t','U','I','F','o','n','t',0 };
695 msi_dialog *dialog = (msi_dialog*) cs->lpCreateParams;
696 MSIPACKAGE *package = dialog->package;
697 MSIQUERY *view = NULL;
698 MSIRECORD *rec = NULL;
704 TRACE("%p %p\n", dialog, package);
707 SetWindowLongPtrW( hwnd, GWLP_USERDATA, (LONG_PTR) dialog );
709 /* fetch the associated record from the Dialog table */
710 r = MSI_OpenQuery( package->db, &view, query, dialog->name );
711 if( r != ERROR_SUCCESS )
713 ERR("query failed for dialog %s\n", debugstr_w(dialog->name));
716 MSI_ViewExecute( view, NULL );
717 MSI_ViewFetch( view, &rec );
718 MSI_ViewClose( view );
719 msiobj_release( &view->hdr );
723 TRACE("No record found for dialog %s\n", debugstr_w(dialog->name));
727 dialog->scale = msi_dialog_get_sans_serif_height(dialog->hwnd);
729 width = MSI_RecordGetInteger( rec, 4 );
730 height = MSI_RecordGetInteger( rec, 5 );
731 dialog->attributes = MSI_RecordGetInteger( rec, 6 );
732 text = MSI_RecordGetString( rec, 7 );
734 width = msi_dialog_scale_unit( dialog, width );
735 height = msi_dialog_scale_unit( dialog, height ) + 25; /* FIXME */
737 dialog->default_font = load_dynamic_property( dialog->package, df, NULL );
739 deformat_string( dialog->package, text, &title );
740 SetWindowTextW( hwnd, title );
741 SetWindowPos( hwnd, 0, 0, 0, width, height,
742 SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOREDRAW );
744 HeapFree( GetProcessHeap(), 0, title );
745 msiobj_release( &rec->hdr );
747 msi_dialog_build_font_list( dialog );
748 msi_dialog_fill_controls( dialog );
749 msi_dialog_evaluate_control_conditions( dialog );
754 static UINT msi_dialog_send_event( msi_dialog *dialog, LPCWSTR event, LPCWSTR arg )
756 LPWSTR event_fmt = NULL, arg_fmt = NULL;
758 TRACE("Sending control event %s %s\n", debugstr_w(event), debugstr_w(arg));
760 deformat_string( dialog->package, event, &event_fmt );
761 deformat_string( dialog->package, arg, &arg_fmt );
763 dialog->event_handler( dialog->package, event_fmt, arg_fmt, dialog );
765 HeapFree( GetProcessHeap(), 0, event_fmt );
766 HeapFree( GetProcessHeap(), 0, arg_fmt );
768 return ERROR_SUCCESS;
771 static UINT msi_dialog_set_property( msi_dialog *dialog, LPCWSTR event, LPCWSTR arg )
773 static const WCHAR szNullArg[] = { '{','}',0 };
774 LPWSTR p, prop, arg_fmt = NULL;
777 len = strlenW(event);
778 prop = HeapAlloc( GetProcessHeap(), 0, len*sizeof(WCHAR));
779 strcpyW( prop, &event[1] );
780 p = strchrW( prop, ']' );
784 if( strcmpW( szNullArg, arg ) )
785 deformat_string( dialog->package, arg, &arg_fmt );
786 MSI_SetPropertyW( dialog->package, prop, arg_fmt );
789 ERR("Badly formatted property string - what happens?\n");
790 HeapFree( GetProcessHeap(), 0, prop );
791 return ERROR_SUCCESS;
794 static UINT msi_dialog_control_event( MSIRECORD *rec, LPVOID param )
796 msi_dialog *dialog = param;
797 LPCWSTR condition, event, arg;
800 condition = MSI_RecordGetString( rec, 5 );
801 r = MSI_EvaluateConditionW( dialog->package, condition );
804 event = MSI_RecordGetString( rec, 3 );
805 arg = MSI_RecordGetString( rec, 4 );
806 if( event[0] == '[' )
807 msi_dialog_set_property( dialog, event, arg );
809 msi_dialog_send_event( dialog, event, arg );
812 return ERROR_SUCCESS;
815 static UINT msi_dialog_button_handler( msi_dialog *dialog,
816 msi_control *control, WPARAM param )
818 static const WCHAR query[] = {
819 'S','E','L','E','C','T',' ','*',' ',
820 'F','R','O','M',' ','C','o','n','t','r','o','l','E','v','e','n','t',' ',
821 'W','H','E','R','E',' ',
822 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',' ',
824 '`','C','o','n','t','r','o','l','_','`',' ','=',' ','\'','%','s','\'',' ',
825 'O','R','D','E','R',' ','B','Y',' ','`','O','r','d','e','r','i','n','g','`',0
827 MSIQUERY *view = NULL;
830 if( HIWORD(param) != BN_CLICKED )
831 return ERROR_SUCCESS;
833 r = MSI_OpenQuery( dialog->package->db, &view, query,
834 dialog->name, control->name );
835 if( r != ERROR_SUCCESS )
837 ERR("query failed\n");
841 r = MSI_IterateRecords( view, 0, msi_dialog_control_event, dialog );
842 msiobj_release( &view->hdr );
847 static UINT msi_dialog_get_checkbox_state( msi_dialog *dialog,
848 msi_control *control )
850 WCHAR state[2] = { 0 };
853 MSI_GetPropertyW( dialog->package, control->property, state, &sz );
854 return atoiW( state ) ? 1 : 0;
857 static void msi_dialog_set_checkbox_state( msi_dialog *dialog,
858 msi_control *control, UINT state )
860 WCHAR szState[2] = { '0', 0 };
864 MSI_SetPropertyW( dialog->package, control->property, szState );
867 static void msi_dialog_checkbox_sync_state( msi_dialog *dialog,
868 msi_control *control )
872 state = msi_dialog_get_checkbox_state( dialog, control );
873 SendMessageW( control->hwnd, BM_SETCHECK,
874 state ? BST_CHECKED : BST_UNCHECKED, 0 );
877 static UINT msi_dialog_checkbox_handler( msi_dialog *dialog,
878 msi_control *control, WPARAM param )
882 if( HIWORD(param) != BN_CLICKED )
883 return ERROR_SUCCESS;
885 TRACE("clicked checkbox %s, set %s\n", debugstr_w(control->name),
886 debugstr_w(control->property));
888 state = msi_dialog_get_checkbox_state( dialog, control );
889 state = state ? 0 : 1;
890 msi_dialog_set_checkbox_state( dialog, control, state );
891 msi_dialog_checkbox_sync_state( dialog, control );
893 return msi_dialog_button_handler( dialog, control, param );
896 static UINT msi_dialog_edit_handler( msi_dialog *dialog,
897 msi_control *control, WPARAM param )
902 if( HIWORD(param) != EN_CHANGE )
903 return ERROR_SUCCESS;
905 TRACE("edit %s contents changed, set %s\n", debugstr_w(control->name),
906 debugstr_w(control->property));
909 buf = HeapAlloc( GetProcessHeap(), 0, sz*sizeof(WCHAR) );
912 r = GetWindowTextW( control->hwnd, buf, sz );
916 buf = HeapReAlloc( GetProcessHeap(), 0, buf, sz*sizeof(WCHAR) );
919 MSI_SetPropertyW( dialog->package, control->property, buf );
921 HeapFree( GetProcessHeap(), 0, buf );
923 return ERROR_SUCCESS;
926 static UINT msi_dialog_radiogroup_handler( msi_dialog *dialog,
927 msi_control *control, WPARAM param )
929 if( HIWORD(param) != BN_CLICKED )
930 return ERROR_SUCCESS;
932 TRACE("clicked radio button %s, set %s\n", debugstr_w(control->name),
933 debugstr_w(control->property));
935 MSI_SetPropertyW( dialog->package, control->property, control->name );
937 return msi_dialog_button_handler( dialog, control, param );
940 static LRESULT msi_dialog_oncommand( msi_dialog *dialog, WPARAM param, HWND hwnd )
942 msi_control *control;
944 TRACE("%p %p %08x\n", dialog, hwnd, param);
946 control = msi_dialog_find_control_by_hwnd( dialog, hwnd );
949 if( control->handler )
951 control->handler( dialog, control, param );
952 msi_dialog_evaluate_control_conditions( dialog );
956 ERR("button click from nowhere\n");
960 static LRESULT WINAPI MSIDialog_WndProc( HWND hwnd, UINT msg,
961 WPARAM wParam, LPARAM lParam )
963 msi_dialog *dialog = (LPVOID) GetWindowLongPtrW( hwnd, GWLP_USERDATA );
965 TRACE(" 0x%04x\n", msg);
969 return msi_dialog_oncreate( hwnd, (LPCREATESTRUCTW)lParam );
972 return msi_dialog_oncommand( dialog, wParam, (HWND)lParam );
978 return DefWindowProcW(hwnd, msg, wParam, lParam);
981 /* functions that interface to other modules within MSI */
983 msi_dialog *msi_dialog_create( MSIPACKAGE* package, LPCWSTR szDialogName,
984 msi_dialog_event_handler event_handler )
989 TRACE("%p %s\n", package, debugstr_w(szDialogName));
991 /* allocate the structure for the dialog to use */
992 dialog = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
993 sizeof *dialog + sizeof(WCHAR)*strlenW(szDialogName) );
996 strcpyW( dialog->name, szDialogName );
997 dialog->package = package;
998 dialog->event_handler = event_handler;
1000 /* create the dialog window, don't show it yet */
1001 hwnd = CreateWindowW( szMsiDialogClass, szDialogName, WS_OVERLAPPEDWINDOW,
1002 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
1003 NULL, NULL, NULL, dialog );
1006 ERR("Failed to create dialog %s\n", debugstr_w( szDialogName ));
1007 msi_dialog_destroy( dialog );
1014 void msi_dialog_end_dialog( msi_dialog *dialog )
1016 dialog->finished = 1;
1019 UINT msi_dialog_run_message_loop( msi_dialog *dialog )
1023 if( dialog->attributes & msidbDialogAttributesVisible )
1025 ShowWindow( dialog->hwnd, SW_SHOW );
1026 UpdateWindow( dialog->hwnd );
1029 if( dialog->attributes & msidbDialogAttributesModal )
1031 while( !dialog->finished && GetMessageW( &msg, 0, 0, 0 ) )
1033 TranslateMessage( &msg );
1034 DispatchMessageW( &msg );
1038 return ERROR_IO_PENDING;
1040 return ERROR_SUCCESS;
1043 void msi_dialog_check_messages( msi_dialog *dialog, HANDLE handle )
1050 while( PeekMessageW( &msg, 0, 0, 0, PM_REMOVE ) )
1052 TranslateMessage( &msg );
1053 DispatchMessageW( &msg );
1057 r = MsgWaitForMultipleObjects( 1, &handle, 0, INFINITE, QS_ALLEVENTS );
1059 while( WAIT_OBJECT_0 != r );
1062 void msi_dialog_do_preview( msi_dialog *dialog )
1064 dialog->attributes |= msidbDialogAttributesVisible;
1065 dialog->attributes &= ~msidbDialogAttributesModal;
1066 msi_dialog_run_message_loop( dialog );
1069 void msi_dialog_destroy( msi_dialog *dialog )
1072 ShowWindow( dialog->hwnd, SW_HIDE );
1074 /* destroy the list of controls */
1075 while( dialog->control_list )
1077 msi_control *t = dialog->control_list;
1078 dialog->control_list = t->next;
1079 /* leave dialog->hwnd - destroying parent destroys child windows */
1080 HeapFree( GetProcessHeap(), 0, t->property );
1081 HeapFree( GetProcessHeap(), 0, t );
1084 /* destroy the list of fonts */
1085 while( dialog->font_list )
1087 msi_font *t = dialog->font_list;
1088 dialog->font_list = t->next;
1089 DeleteObject( t->hfont );
1090 HeapFree( GetProcessHeap(), 0, t );
1092 HeapFree( GetProcessHeap(), 0, dialog->default_font );
1095 DestroyWindow( dialog->hwnd );
1097 dialog->package = NULL;
1098 HeapFree( GetProcessHeap(), 0, dialog );
1101 void msi_dialog_register_class( void )
1105 ZeroMemory( &cls, sizeof cls );
1106 cls.lpfnWndProc = MSIDialog_WndProc;
1107 cls.hInstance = NULL;
1108 cls.hIcon = LoadIconW(0, (LPWSTR)IDI_APPLICATION);
1109 cls.hCursor = LoadCursorW(0, (LPWSTR)IDC_ARROW);
1110 cls.hbrBackground = (HBRUSH)(COLOR_WINDOW);
1111 cls.lpszMenuName = NULL;
1112 cls.lpszClassName = szMsiDialogClass;
1114 RegisterClassW( &cls );
1117 void msi_dialog_unregister_class( void )
1119 UnregisterClassW( szMsiDialogClass, NULL );
1122 static LRESULT WINAPI MSIRadioGroup_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
1124 WNDPROC oldproc = (WNDPROC) GetPropW(hWnd, szButtonData);
1126 TRACE("hWnd %p msg %04x wParam 0x%08x lParam 0x%08lx\n", hWnd, msg, wParam, lParam);
1128 if (msg == WM_COMMAND) /* Forward notifications to dialog */
1129 SendMessageW(GetParent(hWnd), msg, wParam, lParam);
1131 return CallWindowProcW(oldproc, hWnd, msg, wParam, lParam);