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 };
45 struct msi_control_tag;
46 typedef struct msi_control_tag msi_control;
47 typedef UINT (*msi_handler)( msi_dialog *, msi_control *, WPARAM );
49 struct msi_control_tag
51 struct msi_control_tag *next;
58 typedef struct msi_font_tag
60 struct msi_font_tag *next;
68 msi_dialog_event_handler event_handler;
75 msi_control *control_list;
79 typedef UINT (*msi_dialog_control_func)( msi_dialog *dialog, MSIRECORD *rec );
80 struct control_handler
83 msi_dialog_control_func func;
86 static UINT msi_dialog_checkbox_handler( msi_dialog *, msi_control *, WPARAM );
87 static void msi_dialog_checkbox_sync_state( msi_dialog *, msi_control * );
88 static UINT msi_dialog_button_handler( msi_dialog *, msi_control *, WPARAM );
89 static UINT msi_dialog_edit_handler( msi_dialog *, msi_control *, WPARAM );
92 INT msi_dialog_scale_unit( msi_dialog *dialog, INT val )
94 return (dialog->scale * val + 5) / 10;
98 * msi_dialog_get_style
100 * Extract the {\style} string from the front of the text to display and
101 * update the pointer.
103 static LPWSTR msi_dialog_get_style( LPCWSTR *text )
106 LPCWSTR p = *text, q;
111 q = strchrW( p, '}' );
119 ret = HeapAlloc( GetProcessHeap(), 0, len*sizeof(WCHAR) );
122 strncpyW( ret, p, len );
127 static UINT msi_dialog_add_font( MSIRECORD *rec, LPVOID param )
129 msi_dialog *dialog = param;
136 /* create a font and add it to the list */
137 name = MSI_RecordGetString( rec, 1 );
138 font = HeapAlloc( GetProcessHeap(), 0,
139 sizeof *font + strlenW( name )*sizeof (WCHAR) );
140 strcpyW( font->name, name );
141 font->next = dialog->font_list;
142 dialog->font_list = font;
144 memset( &lf, 0, sizeof lf );
145 face = MSI_RecordGetString( rec, 2 );
146 lf.lfHeight = MSI_RecordGetInteger( rec, 3 );
147 style = MSI_RecordGetInteger( rec, 5 );
148 if( style & msidbTextStyleStyleBitsBold )
149 lf.lfWeight = FW_BOLD;
150 if( style & msidbTextStyleStyleBitsItalic )
152 if( style & msidbTextStyleStyleBitsUnderline )
153 lf.lfUnderline = TRUE;
154 if( style & msidbTextStyleStyleBitsStrike )
155 lf.lfStrikeOut = TRUE;
156 lstrcpynW( lf.lfFaceName, face, LF_FACESIZE );
158 /* adjust the height */
159 hdc = GetDC( dialog->hwnd );
162 lf.lfHeight = -MulDiv(lf.lfHeight, GetDeviceCaps(hdc, LOGPIXELSY), 72);
163 ReleaseDC( dialog->hwnd, hdc );
166 font->hfont = CreateFontIndirectW( &lf );
168 TRACE("Adding font style %s\n", debugstr_w(font->name) );
170 return ERROR_SUCCESS;
173 static msi_font *msi_dialog_find_font( msi_dialog *dialog, LPCWSTR name )
177 for( font = dialog->font_list; font; font = font->next )
178 if( !strcmpW( font->name, name ) ) /* FIXME: case sensitive? */
184 static UINT msi_dialog_set_font( msi_dialog *dialog, HWND hwnd, LPCWSTR name )
188 font = msi_dialog_find_font( dialog, name );
190 SendMessageW( hwnd, WM_SETFONT, (WPARAM) font->hfont, TRUE );
192 ERR("No font entry for %s\n", debugstr_w(name));
193 return ERROR_SUCCESS;
196 static UINT msi_dialog_build_font_list( msi_dialog *dialog )
198 static const WCHAR query[] = {
199 'S','E','L','E','C','T',' ','*',' ',
200 'F','R','O','M',' ','`','T','e','x','t','S','t','y','l','e','`',' ',0
203 MSIQUERY *view = NULL;
205 TRACE("dialog %p\n", dialog );
207 r = MSI_OpenQuery( dialog->package->db, &view, query );
208 if( r != ERROR_SUCCESS )
211 r = MSI_IterateRecords( view, NULL, msi_dialog_add_font, dialog );
212 msiobj_release( &view->hdr );
217 static msi_control *msi_dialog_add_control( msi_dialog *dialog,
218 MSIRECORD *rec, LPCWSTR szCls, DWORD style )
220 DWORD x, y, width, height, attributes;
222 LPWSTR font = NULL, title = NULL;
223 msi_control *control = NULL;
225 style |= WS_CHILD | WS_GROUP;
227 name = MSI_RecordGetString( rec, 2 );
228 control = HeapAlloc( GetProcessHeap(), 0,
229 sizeof *control + strlenW(name)*sizeof(WCHAR) );
230 strcpyW( control->name, name );
231 control->next = dialog->control_list;
232 dialog->control_list = control;
233 control->handler = NULL;
234 control->property = NULL;
236 x = MSI_RecordGetInteger( rec, 4 );
237 y = MSI_RecordGetInteger( rec, 5 );
238 width = MSI_RecordGetInteger( rec, 6 );
239 height = MSI_RecordGetInteger( rec, 7 );
240 attributes = MSI_RecordGetInteger( rec, 8 );
241 text = MSI_RecordGetString( rec, 10 );
243 TRACE("Dialog %s control %s\n", debugstr_w(dialog->name), debugstr_w(text));
245 x = msi_dialog_scale_unit( dialog, x );
246 y = msi_dialog_scale_unit( dialog, y );
247 width = msi_dialog_scale_unit( dialog, width );
248 height = msi_dialog_scale_unit( dialog, height );
252 if( ~attributes & 2 )
253 style |= WS_DISABLED;
256 font = msi_dialog_get_style( &text );
257 deformat_string( dialog->package, text, &title );
259 control->hwnd = CreateWindowW( szCls, title, style,
260 x, y, width, height, dialog->hwnd, NULL, NULL, NULL );
261 msi_dialog_set_font( dialog, control->hwnd,
262 font ? font : dialog->default_font );
263 HeapFree( GetProcessHeap(), 0, font );
264 HeapFree( GetProcessHeap(), 0, title );
268 static UINT msi_dialog_text_control( msi_dialog *dialog, MSIRECORD *rec )
270 TRACE("%p %p\n", dialog, rec);
272 msi_dialog_add_control( dialog, rec, szStatic, 0 );
273 return ERROR_SUCCESS;
276 static UINT msi_dialog_button_control( msi_dialog *dialog, MSIRECORD *rec )
278 const static WCHAR szButton[] = { 'B','U','T','T','O','N', 0 };
279 msi_control *control;
281 TRACE("%p %p\n", dialog, rec);
283 control = msi_dialog_add_control( dialog, rec, szButton, 0 );
284 control->handler = msi_dialog_button_handler;
286 return ERROR_SUCCESS;
289 static UINT msi_dialog_checkbox_control( msi_dialog *dialog, MSIRECORD *rec )
291 const static WCHAR szButton[] = { 'B','U','T','T','O','N', 0 };
292 msi_control *control;
295 TRACE("%p %p\n", dialog, rec);
297 control = msi_dialog_add_control( dialog, rec, szButton,
298 BS_CHECKBOX | BS_MULTILINE );
299 control->handler = msi_dialog_checkbox_handler;
300 prop = MSI_RecordGetString( rec, 9 );
302 control->property = dupstrW( prop );
303 msi_dialog_checkbox_sync_state( dialog, control );
305 return ERROR_SUCCESS;
308 static UINT msi_dialog_line_control( msi_dialog *dialog, MSIRECORD *rec )
310 TRACE("%p %p\n", dialog, rec);
312 msi_dialog_add_control( dialog, rec, szStatic, SS_ETCHEDHORZ | SS_SUNKEN );
313 return ERROR_SUCCESS;
316 static UINT msi_dialog_scrolltext_control( msi_dialog *dialog, MSIRECORD *rec )
318 const static WCHAR szEdit[] = { 'E','D','I','T',0 };
320 TRACE("%p %p\n", dialog, rec);
322 msi_dialog_add_control( dialog, rec, szEdit, WS_BORDER |
323 ES_MULTILINE | WS_VSCROLL | ES_READONLY | ES_AUTOVSCROLL );
325 return ERROR_SUCCESS;
328 static UINT msi_dialog_bitmap_control( msi_dialog *dialog, MSIRECORD *rec )
330 TRACE("%p %p\n", dialog, rec);
332 msi_dialog_add_control( dialog, rec, szStatic,
333 SS_BITMAP | SS_LEFT | SS_CENTERIMAGE );
334 return ERROR_SUCCESS;
337 static UINT msi_dialog_combo_control( msi_dialog *dialog, MSIRECORD *rec )
339 static const WCHAR szCombo[] = { 'C','O','M','B','O','B','O','X',0 };
341 msi_dialog_add_control( dialog, rec, szCombo,
342 SS_BITMAP | SS_LEFT | SS_CENTERIMAGE );
343 return ERROR_SUCCESS;
346 static UINT msi_dialog_edit_control( msi_dialog *dialog, MSIRECORD *rec )
348 const static WCHAR szEdit[] = { 'E','D','I','T',0 };
349 msi_control *control;
353 control = msi_dialog_add_control( dialog, rec, szEdit, WS_BORDER );
354 control->handler = msi_dialog_edit_handler;
355 prop = MSI_RecordGetString( rec, 9 );
357 control->property = dupstrW( prop );
358 val = load_dynamic_property( dialog->package, control->property, NULL );
359 SetWindowTextW( control->hwnd, val );
360 HeapFree( GetProcessHeap(), 0, val );
361 return ERROR_SUCCESS;
364 static UINT msi_dialog_pathedit_control( msi_dialog *dialog, MSIRECORD *rec )
366 FIXME("not implemented properly\n");
367 return msi_dialog_edit_control( dialog, rec );
370 static UINT msi_dialog_radiogroup_control( msi_dialog *dialog, MSIRECORD *rec )
374 name = MSI_RecordGetString( rec, 2 );
375 FIXME("Radio group %s\n", debugstr_w( name ) );
376 return ERROR_SUCCESS;
379 static const WCHAR szText[] = { 'T','e','x','t',0 };
380 static const WCHAR szButton[] = { 'P','u','s','h','B','u','t','t','o','n',0 };
381 static const WCHAR szLine[] = { 'L','i','n','e',0 };
382 static const WCHAR szBitmap[] = { 'B','i','t','m','a','p',0 };
383 static const WCHAR szCheckBox[] = { 'C','h','e','c','k','B','o','x',0 };
384 static const WCHAR szScrollableText[] = {
385 'S','c','r','o','l','l','a','b','l','e','T','e','x','t',0 };
386 static const WCHAR szComboBox[] = { 'C','o','m','b','o','B','o','x',0 };
387 static const WCHAR szEdit[] = { 'E','d','i','t',0 };
388 static const WCHAR szMaskedEdit[] = { 'M','a','s','k','e','d','E','d','i','t',0 };
389 static const WCHAR szPathEdit[] = { 'P','a','t','h','E','d','i','t',0 };
390 static const WCHAR szRadioButtonGroup[] = {
391 'R','a','d','i','o','B','u','t','t','o','n','G','r','o','u','p',0 };
393 struct control_handler msi_dialog_handler[] =
395 { szText, msi_dialog_text_control },
396 { szButton, msi_dialog_button_control },
397 { szLine, msi_dialog_line_control },
398 { szBitmap, msi_dialog_bitmap_control },
399 { szCheckBox, msi_dialog_checkbox_control },
400 { szScrollableText, msi_dialog_scrolltext_control },
401 { szComboBox, msi_dialog_combo_control },
402 { szEdit, msi_dialog_edit_control },
403 { szMaskedEdit, msi_dialog_edit_control },
404 { szPathEdit, msi_dialog_pathedit_control },
405 { szRadioButtonGroup, msi_dialog_radiogroup_control },
408 #define NUM_CONTROL_TYPES (sizeof msi_dialog_handler/sizeof msi_dialog_handler[0])
410 static UINT msi_dialog_create_controls( MSIRECORD *rec, LPVOID param )
412 msi_dialog *dialog = param;
413 LPCWSTR control_type;
416 /* find and call the function that can create this type of control */
417 control_type = MSI_RecordGetString( rec, 3 );
418 for( i=0; i<NUM_CONTROL_TYPES; i++ )
419 if (!strcmpiW( msi_dialog_handler[i].control_type, control_type ))
421 if( i != NUM_CONTROL_TYPES )
422 msi_dialog_handler[i].func( dialog, rec );
424 ERR("no handler for element type %s\n", debugstr_w(control_type));
426 return ERROR_SUCCESS;
429 static UINT msi_dialog_fill_controls( msi_dialog *dialog )
431 static const WCHAR query[] = {
432 'S','E','L','E','C','T',' ','*',' ',
433 'F','R','O','M',' ','C','o','n','t','r','o','l',' ',
434 'W','H','E','R','E',' ',
435 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',0};
437 MSIQUERY *view = NULL;
438 MSIPACKAGE *package = dialog->package;
440 TRACE("%p %s\n", dialog, debugstr_w(dialog->name) );
442 /* query the Control table for all the elements of the control */
443 r = MSI_OpenQuery( package->db, &view, query, dialog->name );
444 if( r != ERROR_SUCCESS )
446 ERR("query failed for dialog %s\n", debugstr_w(dialog->name));
447 return ERROR_INVALID_PARAMETER;
450 r = MSI_IterateRecords( view, 0, msi_dialog_create_controls, dialog );
451 msiobj_release( &view->hdr );
456 static msi_control *msi_dialog_find_control( msi_dialog *dialog, LPCWSTR name )
458 msi_control *control;
460 for( control = dialog->control_list; control; control = control->next )
461 if( !strcmpW( control->name, name ) ) /* FIXME: case sensitive? */
466 static msi_control *msi_dialog_find_control_by_hwnd( msi_dialog *dialog, HWND hwnd )
468 msi_control *control;
470 for( control = dialog->control_list; control; control = control->next )
471 if( hwnd == control->hwnd )
476 static UINT msi_dialog_set_control_condition( MSIRECORD *rec, LPVOID param )
478 static const WCHAR szHide[] = { 'H','i','d','e',0 };
479 static const WCHAR szShow[] = { 'S','h','o','w',0 };
480 static const WCHAR szDisable[] = { 'D','i','s','a','b','l','e',0 };
481 static const WCHAR szEnable[] = { 'E','n','a','b','l','e',0 };
482 msi_dialog *dialog = param;
483 msi_control *control;
484 LPCWSTR name, action, condition;
487 name = MSI_RecordGetString( rec, 2 );
488 action = MSI_RecordGetString( rec, 3 );
489 condition = MSI_RecordGetString( rec, 4 );
490 r = MSI_EvaluateConditionW( dialog->package, condition );
491 control = msi_dialog_find_control( dialog, name );
494 TRACE("%s control %s\n", debugstr_w(action), debugstr_w(name));
496 /* FIXME: case sensitive? */
497 if(!strcmpW(action, szHide))
498 ShowWindow(control->hwnd, SW_HIDE);
499 else if(!strcmpW(action, szShow))
500 ShowWindow(control->hwnd, SW_SHOW);
501 else if(!strcmpW(action, szDisable))
502 EnableWindow(control->hwnd, FALSE);
503 else if(!strcmpW(action, szEnable))
504 EnableWindow(control->hwnd, TRUE);
506 FIXME("Unhandled action %s\n", debugstr_w(action));
509 return ERROR_SUCCESS;
512 static UINT msi_dialog_evaluate_control_conditions( msi_dialog *dialog )
514 static const WCHAR query[] = {
515 'S','E','L','E','C','T',' ','*',' ',
517 'C','o','n','t','r','o','l','C','o','n','d','i','t','i','o','n',' ',
518 'W','H','E','R','E',' ',
519 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',0
522 MSIQUERY *view = NULL;
523 MSIPACKAGE *package = dialog->package;
525 TRACE("%p %s\n", dialog, debugstr_w(dialog->name) );
527 /* query the Control table for all the elements of the control */
528 r = MSI_OpenQuery( package->db, &view, query, dialog->name );
529 if( r != ERROR_SUCCESS )
531 ERR("query failed for dialog %s\n", debugstr_w(dialog->name));
532 return ERROR_INVALID_PARAMETER;
535 r = MSI_IterateRecords( view, 0, msi_dialog_set_control_condition, dialog );
536 msiobj_release( &view->hdr );
541 /* figure out the height of 10 point MS Sans Serif */
542 static INT msi_dialog_get_sans_serif_height( HWND hwnd )
544 static const WCHAR szSansSerif[] = {
545 'M','S',' ','S','a','n','s',' ','S','e','r','i','f',0 };
550 HFONT hFont, hOldFont;
556 memset( &lf, 0, sizeof lf );
557 lf.lfHeight = MulDiv(10, GetDeviceCaps(hdc, LOGPIXELSY), 72);
558 strcpyW( lf.lfFaceName, szSansSerif );
559 hFont = CreateFontIndirectW(&lf);
562 hOldFont = SelectObject( hdc, hFont );
563 r = GetTextMetricsW( hdc, &tm );
565 height = tm.tmHeight;
566 SelectObject( hdc, hOldFont );
567 DeleteObject( hFont );
569 ReleaseDC( hwnd, hdc );
574 static LRESULT msi_dialog_oncreate( HWND hwnd, LPCREATESTRUCTW cs )
576 static const WCHAR query[] = {
577 'S','E','L','E','C','T',' ','*',' ',
578 'F','R','O','M',' ','D','i','a','l','o','g',' ',
579 'W','H','E','R','E',' ',
580 '`','D','i','a','l','o','g','`',' ','=',' ','\'','%','s','\'',0};
581 static const WCHAR df[] = {
582 'D','e','f','a','u','l','t','U','I','F','o','n','t',0 };
583 msi_dialog *dialog = (msi_dialog*) cs->lpCreateParams;
584 MSIPACKAGE *package = dialog->package;
585 MSIQUERY *view = NULL;
586 MSIRECORD *rec = NULL;
592 TRACE("%p %p\n", dialog, package);
595 SetWindowLongPtrW( hwnd, GWLP_USERDATA, (LONG_PTR) dialog );
597 /* fetch the associated record from the Dialog table */
598 r = MSI_OpenQuery( package->db, &view, query, dialog->name );
599 if( r != ERROR_SUCCESS )
601 ERR("query failed for dialog %s\n", debugstr_w(dialog->name));
604 MSI_ViewExecute( view, NULL );
605 MSI_ViewFetch( view, &rec );
606 MSI_ViewClose( view );
607 msiobj_release( &view->hdr );
611 TRACE("No record found for dialog %s\n", debugstr_w(dialog->name));
615 dialog->scale = msi_dialog_get_sans_serif_height(dialog->hwnd);
617 width = MSI_RecordGetInteger( rec, 4 );
618 height = MSI_RecordGetInteger( rec, 5 );
619 dialog->attributes = MSI_RecordGetInteger( rec, 6 );
620 text = MSI_RecordGetString( rec, 7 );
622 width = msi_dialog_scale_unit( dialog, width );
623 height = msi_dialog_scale_unit( dialog, height ) + 25; /* FIXME */
625 dialog->default_font = load_dynamic_property( dialog->package, df, NULL );
627 deformat_string( dialog->package, text, &title );
628 SetWindowTextW( hwnd, title );
629 SetWindowPos( hwnd, 0, 0, 0, width, height,
630 SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOREDRAW );
632 HeapFree( GetProcessHeap(), 0, title );
633 msiobj_release( &rec->hdr );
635 msi_dialog_build_font_list( dialog );
636 msi_dialog_fill_controls( dialog );
637 msi_dialog_evaluate_control_conditions( dialog );
642 static UINT msi_dialog_send_event( msi_dialog *dialog, LPCWSTR event, LPCWSTR arg )
644 LPWSTR event_fmt = NULL, arg_fmt = NULL;
646 TRACE("Sending control event %s %s\n", debugstr_w(event), debugstr_w(arg));
648 deformat_string( dialog->package, event, &event_fmt );
649 deformat_string( dialog->package, arg, &arg_fmt );
651 dialog->event_handler( dialog->package, event_fmt, arg_fmt, dialog );
653 HeapFree( GetProcessHeap(), 0, event_fmt );
654 HeapFree( GetProcessHeap(), 0, arg_fmt );
656 return ERROR_SUCCESS;
659 static UINT msi_dialog_set_property( msi_dialog *dialog, LPCWSTR event, LPCWSTR arg )
661 static const WCHAR szNullArg[] = { '{','}',0 };
662 LPWSTR p, prop, arg_fmt = NULL;
665 len = strlenW(event);
666 prop = HeapAlloc( GetProcessHeap(), 0, len*sizeof(WCHAR));
667 strcpyW( prop, &event[1] );
668 p = strchrW( prop, ']' );
672 if( strcmpW( szNullArg, arg ) )
673 deformat_string( dialog->package, arg, &arg_fmt );
674 MSI_SetPropertyW( dialog->package, prop, arg_fmt );
677 ERR("Badly formatted property string - what happens?\n");
678 HeapFree( GetProcessHeap(), 0, prop );
679 return ERROR_SUCCESS;
682 static UINT msi_dialog_control_event( MSIRECORD *rec, LPVOID param )
684 msi_dialog *dialog = param;
685 LPCWSTR condition, event, arg;
688 condition = MSI_RecordGetString( rec, 5 );
689 r = MSI_EvaluateConditionW( dialog->package, condition );
692 event = MSI_RecordGetString( rec, 3 );
693 arg = MSI_RecordGetString( rec, 4 );
694 if( event[0] == '[' )
695 msi_dialog_set_property( dialog, event, arg );
697 msi_dialog_send_event( dialog, event, arg );
700 return ERROR_SUCCESS;
703 static UINT msi_dialog_button_handler( msi_dialog *dialog,
704 msi_control *control, WPARAM param )
706 static const WCHAR query[] = {
707 'S','E','L','E','C','T',' ','*',' ',
708 'F','R','O','M',' ','C','o','n','t','r','o','l','E','v','e','n','t',' ',
709 'W','H','E','R','E',' ',
710 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',' ',
712 '`','C','o','n','t','r','o','l','_','`',' ','=',' ','\'','%','s','\'',' ',
713 'O','R','D','E','R',' ','B','Y',' ','`','O','r','d','e','r','i','n','g','`',0
715 MSIQUERY *view = NULL;
718 if( HIWORD(param) != BN_CLICKED )
719 return ERROR_SUCCESS;
721 r = MSI_OpenQuery( dialog->package->db, &view, query,
722 dialog->name, control->name );
723 if( r != ERROR_SUCCESS )
725 ERR("query failed\n");
729 r = MSI_IterateRecords( view, 0, msi_dialog_control_event, dialog );
730 msiobj_release( &view->hdr );
735 static UINT msi_dialog_get_checkbox_state( msi_dialog *dialog,
736 msi_control *control )
738 WCHAR state[2] = { 0 };
741 MSI_GetPropertyW( dialog->package, control->property, state, &sz );
742 return atoiW( state ) ? 1 : 0;
745 static void msi_dialog_set_checkbox_state( msi_dialog *dialog,
746 msi_control *control, UINT state )
748 WCHAR szState[2] = { '0', 0 };
752 MSI_SetPropertyW( dialog->package, control->property, szState );
755 static void msi_dialog_checkbox_sync_state( msi_dialog *dialog,
756 msi_control *control )
760 state = msi_dialog_get_checkbox_state( dialog, control );
761 SendMessageW( control->hwnd, BM_SETCHECK,
762 state ? BST_CHECKED : BST_UNCHECKED, 0 );
765 static UINT msi_dialog_checkbox_handler( msi_dialog *dialog,
766 msi_control *control, WPARAM param )
770 if( HIWORD(param) != BN_CLICKED )
771 return ERROR_SUCCESS;
773 TRACE("clicked checkbox %s, set %s\n", debugstr_w(control->name),
774 debugstr_w(control->property));
776 state = msi_dialog_get_checkbox_state( dialog, control );
777 state = state ? 0 : 1;
778 msi_dialog_set_checkbox_state( dialog, control, state );
779 msi_dialog_checkbox_sync_state( dialog, control );
781 return msi_dialog_button_handler( dialog, control, param );
784 static UINT msi_dialog_edit_handler( msi_dialog *dialog,
785 msi_control *control, WPARAM param )
790 if( HIWORD(param) != EN_CHANGE )
791 return ERROR_SUCCESS;
793 TRACE("edit %s contents changed, set %s\n", debugstr_w(control->name),
794 debugstr_w(control->property));
797 buf = HeapAlloc( GetProcessHeap(), 0, sz*sizeof(WCHAR) );
800 r = GetWindowTextW( control->hwnd, buf, sz );
804 buf = HeapReAlloc( GetProcessHeap(), 0, buf, sz*sizeof(WCHAR) );
807 MSI_SetPropertyW( dialog->package, control->property, buf );
809 HeapFree( GetProcessHeap(), 0, buf );
811 return ERROR_SUCCESS;
814 static LRESULT msi_dialog_oncommand( msi_dialog *dialog, WPARAM param, HWND hwnd )
816 msi_control *control;
818 TRACE("%p %p %08x\n", dialog, hwnd, param);
820 control = msi_dialog_find_control_by_hwnd( dialog, hwnd );
823 if( control->handler )
825 control->handler( dialog, control, param );
826 msi_dialog_evaluate_control_conditions( dialog );
830 ERR("button click from nowhere\n");
834 static LRESULT WINAPI MSIDialog_WndProc( HWND hwnd, UINT msg,
835 WPARAM wParam, LPARAM lParam )
837 msi_dialog *dialog = (LPVOID) GetWindowLongPtrW( hwnd, GWLP_USERDATA );
842 return msi_dialog_oncreate( hwnd, (LPCREATESTRUCTW)lParam );
845 return msi_dialog_oncommand( dialog, wParam, (HWND)lParam );
851 return DefWindowProcW(hwnd, msg, wParam, lParam);
854 /* functions that interface to other modules within MSI */
856 msi_dialog *msi_dialog_create( MSIPACKAGE* package, LPCWSTR szDialogName,
857 msi_dialog_event_handler event_handler )
862 TRACE("%p %s\n", package, debugstr_w(szDialogName));
864 /* allocate the structure for the dialog to use */
865 dialog = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
866 sizeof *dialog + sizeof(WCHAR)*strlenW(szDialogName) );
869 strcpyW( dialog->name, szDialogName );
870 dialog->package = package;
871 dialog->event_handler = event_handler;
873 /* create the dialog window, don't show it yet */
874 hwnd = CreateWindowW( szMsiDialogClass, szDialogName, WS_OVERLAPPEDWINDOW,
875 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
876 NULL, NULL, NULL, dialog );
879 ERR("Failed to create dialog %s\n", debugstr_w( szDialogName ));
880 msi_dialog_destroy( dialog );
887 void msi_dialog_end_dialog( msi_dialog *dialog )
889 dialog->finished = 1;
892 UINT msi_dialog_run_message_loop( msi_dialog *dialog )
896 if( dialog->attributes & msidbDialogAttributesVisible )
898 ShowWindow( dialog->hwnd, SW_SHOW );
899 UpdateWindow( dialog->hwnd );
902 if( dialog->attributes & msidbDialogAttributesModal )
904 while( !dialog->finished && GetMessageW( &msg, 0, 0, 0 ) )
906 TranslateMessage( &msg );
907 DispatchMessageW( &msg );
911 return ERROR_IO_PENDING;
913 return ERROR_SUCCESS;
916 void msi_dialog_check_messages( msi_dialog *dialog, HANDLE handle )
923 while( PeekMessageW( &msg, 0, 0, 0, PM_REMOVE ) )
925 TranslateMessage( &msg );
926 DispatchMessageW( &msg );
930 r = MsgWaitForMultipleObjects( 1, &handle, 0, INFINITE, QS_ALLEVENTS );
932 while( WAIT_OBJECT_0 != r );
935 void msi_dialog_do_preview( msi_dialog *dialog )
937 dialog->attributes |= msidbDialogAttributesVisible;
938 dialog->attributes &= ~msidbDialogAttributesModal;
939 msi_dialog_run_message_loop( dialog );
942 void msi_dialog_destroy( msi_dialog *dialog )
945 ShowWindow( dialog->hwnd, SW_HIDE );
947 /* destroy the list of controls */
948 while( dialog->control_list )
950 msi_control *t = dialog->control_list;
951 dialog->control_list = t->next;
952 /* leave dialog->hwnd - destroying parent destroys child windows */
953 HeapFree( GetProcessHeap(), 0, t->property );
954 HeapFree( GetProcessHeap(), 0, t );
957 /* destroy the list of fonts */
958 while( dialog->font_list )
960 msi_font *t = dialog->font_list;
961 dialog->font_list = t->next;
962 DeleteObject( t->hfont );
963 HeapFree( GetProcessHeap(), 0, t );
965 HeapFree( GetProcessHeap(), 0, dialog->default_font );
968 DestroyWindow( dialog->hwnd );
970 dialog->package = NULL;
971 HeapFree( GetProcessHeap(), 0, dialog );
974 void msi_dialog_register_class( void )
978 ZeroMemory( &cls, sizeof cls );
979 cls.lpfnWndProc = MSIDialog_WndProc;
980 cls.hInstance = NULL;
981 cls.hIcon = LoadIconW(0, (LPWSTR)IDI_APPLICATION);
982 cls.hCursor = LoadCursorW(0, (LPWSTR)IDC_ARROW);
983 cls.hbrBackground = (HBRUSH)(COLOR_WINDOW);
984 cls.lpszMenuName = NULL;
985 cls.lpszClassName = szMsiDialogClass;
987 RegisterClassW( &cls );
990 void msi_dialog_unregister_class( void )
992 UnregisterClassW( szMsiDialogClass, NULL );