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_click_handler
)( msi_dialog
*, msi_control
* );
49 struct msi_control_tag
51 struct msi_control_tag
*next
;
53 msi_click_handler click_handler
;
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_click( msi_dialog
*, msi_control
* );
87 static void msi_dialog_checkbox_sync_state( msi_dialog
*, msi_control
* );
88 static UINT
msi_dialog_button_click( msi_dialog
*, msi_control
* );
91 INT
msi_dialog_scale_unit( msi_dialog
*dialog
, INT val
)
93 return (dialog
->scale
* val
+ 5) / 10;
97 * msi_dialog_get_style
99 * Extract the {\style} string from the front of the text to display and
100 * update the pointer.
102 static LPWSTR
msi_dialog_get_style( LPCWSTR
*text
)
105 LPCWSTR p
= *text
, q
;
110 q
= strchrW( p
, '}' );
118 ret
= HeapAlloc( GetProcessHeap(), 0, len
*sizeof(WCHAR
) );
121 strncpyW( ret
, p
, len
);
126 static UINT
msi_dialog_add_font( MSIRECORD
*rec
, LPVOID param
)
128 msi_dialog
*dialog
= param
;
135 /* create a font and add it to the list */
136 name
= MSI_RecordGetString( rec
, 1 );
137 font
= HeapAlloc( GetProcessHeap(), 0,
138 sizeof *font
+ strlenW( name
)*sizeof (WCHAR
) );
139 strcpyW( font
->name
, name
);
140 font
->next
= dialog
->font_list
;
141 dialog
->font_list
= font
;
143 memset( &lf
, 0, sizeof lf
);
144 face
= MSI_RecordGetString( rec
, 2 );
145 lf
.lfHeight
= MSI_RecordGetInteger( rec
, 3 );
146 style
= MSI_RecordGetInteger( rec
, 5 );
147 if( style
& msidbTextStyleStyleBitsBold
)
148 lf
.lfWeight
= FW_BOLD
;
149 if( style
& msidbTextStyleStyleBitsItalic
)
151 if( style
& msidbTextStyleStyleBitsUnderline
)
152 lf
.lfUnderline
= TRUE
;
153 if( style
& msidbTextStyleStyleBitsStrike
)
154 lf
.lfStrikeOut
= TRUE
;
155 lstrcpynW( lf
.lfFaceName
, face
, LF_FACESIZE
);
157 /* adjust the height */
158 hdc
= GetDC( dialog
->hwnd
);
161 lf
.lfHeight
= -MulDiv(lf
.lfHeight
, GetDeviceCaps(hdc
, LOGPIXELSY
), 72);
162 ReleaseDC( dialog
->hwnd
, hdc
);
165 font
->hfont
= CreateFontIndirectW( &lf
);
167 TRACE("Adding font style %s\n", debugstr_w(font
->name
) );
169 return ERROR_SUCCESS
;
172 static msi_font
*msi_dialog_find_font( msi_dialog
*dialog
, LPCWSTR name
)
176 for( font
= dialog
->font_list
; font
; font
= font
->next
)
177 if( !strcmpW( font
->name
, name
) ) /* FIXME: case sensitive? */
183 static UINT
msi_dialog_set_font( msi_dialog
*dialog
, HWND hwnd
, LPCWSTR name
)
187 font
= msi_dialog_find_font( dialog
, name
);
189 SendMessageW( hwnd
, WM_SETFONT
, (WPARAM
) font
->hfont
, TRUE
);
191 ERR("No font entry for %s\n", debugstr_w(name
));
192 return ERROR_SUCCESS
;
195 static UINT
msi_dialog_build_font_list( msi_dialog
*dialog
)
197 static const WCHAR query
[] = {
198 'S','E','L','E','C','T',' ','*',' ',
199 'F','R','O','M',' ','`','T','e','x','t','S','t','y','l','e','`',' ',0
202 MSIQUERY
*view
= NULL
;
204 TRACE("dialog %p\n", dialog
);
206 r
= MSI_OpenQuery( dialog
->package
->db
, &view
, query
);
207 if( r
!= ERROR_SUCCESS
)
210 r
= MSI_IterateRecords( view
, NULL
, msi_dialog_add_font
, dialog
);
211 msiobj_release( &view
->hdr
);
216 static msi_control
*msi_dialog_add_control( msi_dialog
*dialog
,
217 MSIRECORD
*rec
, LPCWSTR szCls
, DWORD style
)
219 DWORD x
, y
, width
, height
;
221 LPWSTR font
= NULL
, title
= NULL
;
222 msi_control
*control
= NULL
;
224 style
|= WS_CHILD
| WS_VISIBLE
| WS_GROUP
;
226 name
= MSI_RecordGetString( rec
, 2 );
227 control
= HeapAlloc( GetProcessHeap(), 0,
228 sizeof *control
+ strlenW(name
)*sizeof(WCHAR
) );
229 strcpyW( control
->name
, name
);
230 control
->next
= dialog
->control_list
;
231 dialog
->control_list
= control
;
232 control
->click_handler
= NULL
;
233 control
->property
= NULL
;
235 x
= MSI_RecordGetInteger( rec
, 4 );
236 y
= MSI_RecordGetInteger( rec
, 5 );
237 width
= MSI_RecordGetInteger( rec
, 6 );
238 height
= MSI_RecordGetInteger( rec
, 7 );
239 text
= MSI_RecordGetString( rec
, 10 );
241 TRACE("Dialog %s control %s\n", debugstr_w(dialog
->name
), debugstr_w(text
));
243 x
= msi_dialog_scale_unit( dialog
, x
);
244 y
= msi_dialog_scale_unit( dialog
, y
);
245 width
= msi_dialog_scale_unit( dialog
, width
);
246 height
= msi_dialog_scale_unit( dialog
, height
);
250 font
= msi_dialog_get_style( &text
);
251 deformat_string( dialog
->package
, text
, &title
);
253 control
->hwnd
= CreateWindowW( szCls
, title
, style
,
254 x
, y
, width
, height
, dialog
->hwnd
, NULL
, NULL
, NULL
);
255 msi_dialog_set_font( dialog
, control
->hwnd
,
256 font
? font
: dialog
->default_font
);
257 HeapFree( GetProcessHeap(), 0, font
);
258 HeapFree( GetProcessHeap(), 0, title
);
262 static UINT
msi_dialog_text_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
264 TRACE("%p %p\n", dialog
, rec
);
266 msi_dialog_add_control( dialog
, rec
, szStatic
, 0 );
267 return ERROR_SUCCESS
;
270 static UINT
msi_dialog_button_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
272 const static WCHAR szButton
[] = { 'B','U','T','T','O','N', 0 };
273 msi_control
*control
;
275 TRACE("%p %p\n", dialog
, rec
);
277 control
= msi_dialog_add_control( dialog
, rec
, szButton
, 0 );
278 control
->click_handler
= msi_dialog_button_click
;
280 return ERROR_SUCCESS
;
283 static UINT
msi_dialog_checkbox_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
285 const static WCHAR szButton
[] = { 'B','U','T','T','O','N', 0 };
286 msi_control
*control
;
289 TRACE("%p %p\n", dialog
, rec
);
291 control
= msi_dialog_add_control( dialog
, rec
, szButton
,
292 BS_CHECKBOX
| BS_MULTILINE
);
293 control
->click_handler
= msi_dialog_checkbox_click
;
294 prop
= MSI_RecordGetString( rec
, 9 );
296 control
->property
= dupstrW( prop
);
297 msi_dialog_checkbox_sync_state( dialog
, control
);
299 return ERROR_SUCCESS
;
302 static UINT
msi_dialog_line_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
304 TRACE("%p %p\n", dialog
, rec
);
306 msi_dialog_add_control( dialog
, rec
, szStatic
, SS_ETCHEDHORZ
| SS_SUNKEN
);
307 return ERROR_SUCCESS
;
310 static UINT
msi_dialog_scrolltext_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
312 const static WCHAR szEdit
[] = { 'E','D','I','T',0 };
314 TRACE("%p %p\n", dialog
, rec
);
316 msi_dialog_add_control( dialog
, rec
, szEdit
,
317 ES_MULTILINE
| WS_VSCROLL
| ES_READONLY
| ES_AUTOVSCROLL
);
319 return ERROR_SUCCESS
;
322 static UINT
msi_dialog_bitmap_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
324 TRACE("%p %p\n", dialog
, rec
);
326 msi_dialog_add_control( dialog
, rec
, szStatic
,
327 SS_BITMAP
| SS_LEFT
| SS_CENTERIMAGE
);
328 return ERROR_SUCCESS
;
331 static const WCHAR szText
[] = { 'T','e','x','t',0 };
332 static const WCHAR szButton
[] = { 'P','u','s','h','B','u','t','t','o','n',0 };
333 static const WCHAR szLine
[] = { 'L','i','n','e',0 };
334 static const WCHAR szBitmap
[] = { 'B','i','t','m','a','p',0 };
335 static const WCHAR szCheckBox
[] = { 'C','h','e','c','k','B','o','x',0 };
336 static const WCHAR szScrollableText
[] = {
337 'S','c','r','o','l','l','a','b','l','e','T','e','x','t',0 };
339 struct control_handler msi_dialog_handler
[] =
341 { szText
, msi_dialog_text_control
},
342 { szButton
, msi_dialog_button_control
},
343 { szLine
, msi_dialog_line_control
},
344 { szBitmap
, msi_dialog_bitmap_control
},
345 { szCheckBox
, msi_dialog_checkbox_control
},
346 { szScrollableText
, msi_dialog_scrolltext_control
},
349 #define NUM_CONTROL_TYPES (sizeof msi_dialog_handler/sizeof msi_dialog_handler[0])
351 static UINT
msi_dialog_create_controls( MSIRECORD
*rec
, LPVOID param
)
353 msi_dialog
*dialog
= param
;
354 LPCWSTR control_type
;
357 /* find and call the function that can create this type of control */
358 control_type
= MSI_RecordGetString( rec
, 3 );
359 for( i
=0; i
<NUM_CONTROL_TYPES
; i
++ )
360 if (!strcmpiW( msi_dialog_handler
[i
].control_type
, control_type
))
362 if( i
!= NUM_CONTROL_TYPES
)
363 msi_dialog_handler
[i
].func( dialog
, rec
);
365 ERR("no handler for element type %s\n", debugstr_w(control_type
));
367 return ERROR_SUCCESS
;
370 static UINT
msi_dialog_fill_controls( msi_dialog
*dialog
)
372 static const WCHAR query
[] = {
373 'S','E','L','E','C','T',' ','*',' ',
374 'F','R','O','M',' ','C','o','n','t','r','o','l',' ',
375 'W','H','E','R','E',' ',
376 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',0};
378 MSIQUERY
*view
= NULL
;
379 MSIPACKAGE
*package
= dialog
->package
;
381 TRACE("%p %s\n", dialog
, debugstr_w(dialog
->name
) );
383 /* query the Control table for all the elements of the control */
384 r
= MSI_OpenQuery( package
->db
, &view
, query
, dialog
->name
);
385 if( r
!= ERROR_SUCCESS
)
387 ERR("query failed for dialog %s\n", debugstr_w(dialog
->name
));
388 return ERROR_INVALID_PARAMETER
;
391 r
= MSI_IterateRecords( view
, 0, msi_dialog_create_controls
, dialog
);
392 msiobj_release( &view
->hdr
);
397 static msi_control
*msi_dialog_find_control( msi_dialog
*dialog
, LPCWSTR name
)
399 msi_control
*control
;
401 for( control
= dialog
->control_list
; control
; control
= control
->next
)
402 if( !strcmpW( control
->name
, name
) ) /* FIXME: case sensitive? */
407 static msi_control
*msi_dialog_find_control_by_hwnd( msi_dialog
*dialog
, HWND hwnd
)
409 msi_control
*control
;
411 for( control
= dialog
->control_list
; control
; control
= control
->next
)
412 if( hwnd
== control
->hwnd
)
417 static UINT
msi_dialog_set_control_condition( MSIRECORD
*rec
, LPVOID param
)
419 static const WCHAR szHide
[] = { 'H','i','d','e',0 };
420 static const WCHAR szShow
[] = { 'S','h','o','w',0 };
421 static const WCHAR szDisable
[] = { 'D','i','s','a','b','l','e',0 };
422 static const WCHAR szEnable
[] = { 'E','n','a','b','l','e',0 };
423 msi_dialog
*dialog
= param
;
424 msi_control
*control
;
425 LPCWSTR name
, action
, condition
;
428 name
= MSI_RecordGetString( rec
, 2 );
429 action
= MSI_RecordGetString( rec
, 3 );
430 condition
= MSI_RecordGetString( rec
, 4 );
431 r
= MSI_EvaluateConditionW( dialog
->package
, condition
);
432 control
= msi_dialog_find_control( dialog
, name
);
435 TRACE("%s control %s\n", debugstr_w(action
), debugstr_w(name
));
437 /* FIXME: case sensitive? */
438 if(!strcmpW(action
, szHide
))
439 ShowWindow(control
->hwnd
, SW_HIDE
);
440 else if(!strcmpW(action
, szShow
))
441 ShowWindow(control
->hwnd
, SW_SHOW
);
442 else if(!strcmpW(action
, szDisable
))
443 EnableWindow(control
->hwnd
, FALSE
);
444 else if(!strcmpW(action
, szEnable
))
445 EnableWindow(control
->hwnd
, TRUE
);
447 FIXME("Unhandled action %s\n", debugstr_w(action
));
450 return ERROR_SUCCESS
;
453 static UINT
msi_dialog_evaluate_control_conditions( msi_dialog
*dialog
)
455 static const WCHAR query
[] = {
456 'S','E','L','E','C','T',' ','*',' ',
458 'C','o','n','t','r','o','l','C','o','n','d','i','t','i','o','n',' ',
459 'W','H','E','R','E',' ',
460 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',0
463 MSIQUERY
*view
= NULL
;
464 MSIPACKAGE
*package
= dialog
->package
;
466 TRACE("%p %s\n", dialog
, debugstr_w(dialog
->name
) );
468 /* query the Control table for all the elements of the control */
469 r
= MSI_OpenQuery( package
->db
, &view
, query
, dialog
->name
);
470 if( r
!= ERROR_SUCCESS
)
472 ERR("query failed for dialog %s\n", debugstr_w(dialog
->name
));
473 return ERROR_INVALID_PARAMETER
;
476 r
= MSI_IterateRecords( view
, 0, msi_dialog_set_control_condition
, dialog
);
477 msiobj_release( &view
->hdr
);
482 /* figure out the height of 10 point MS Sans Serif */
483 static INT
msi_dialog_get_sans_serif_height( HWND hwnd
)
485 static const WCHAR szSansSerif
[] = {
486 'M','S',' ','S','a','n','s',' ','S','e','r','i','f',0 };
491 HFONT hFont
, hOldFont
;
497 memset( &lf
, 0, sizeof lf
);
498 lf
.lfHeight
= MulDiv(10, GetDeviceCaps(hdc
, LOGPIXELSY
), 72);
499 strcpyW( lf
.lfFaceName
, szSansSerif
);
500 hFont
= CreateFontIndirectW(&lf
);
503 hOldFont
= SelectObject( hdc
, hFont
);
504 r
= GetTextMetricsW( hdc
, &tm
);
506 height
= tm
.tmHeight
;
507 SelectObject( hdc
, hOldFont
);
508 DeleteObject( hFont
);
510 ReleaseDC( hwnd
, hdc
);
515 static LRESULT
msi_dialog_oncreate( HWND hwnd
, LPCREATESTRUCTW cs
)
517 static const WCHAR query
[] = {
518 'S','E','L','E','C','T',' ','*',' ',
519 'F','R','O','M',' ','D','i','a','l','o','g',' ',
520 'W','H','E','R','E',' ',
521 '`','D','i','a','l','o','g','`',' ','=',' ','\'','%','s','\'',0};
522 static const WCHAR df
[] = {
523 'D','e','f','a','u','l','t','U','I','F','o','n','t',0 };
524 msi_dialog
*dialog
= (msi_dialog
*) cs
->lpCreateParams
;
525 MSIPACKAGE
*package
= dialog
->package
;
526 MSIQUERY
*view
= NULL
;
527 MSIRECORD
*rec
= NULL
;
533 TRACE("%p %p\n", dialog
, package
);
536 SetWindowLongPtrW( hwnd
, GWLP_USERDATA
, (LONG_PTR
) dialog
);
538 /* fetch the associated record from the Dialog table */
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
));
545 MSI_ViewExecute( view
, NULL
);
546 MSI_ViewFetch( view
, &rec
);
547 MSI_ViewClose( view
);
548 msiobj_release( &view
->hdr
);
552 TRACE("No record found for dialog %s\n", debugstr_w(dialog
->name
));
556 dialog
->scale
= msi_dialog_get_sans_serif_height(dialog
->hwnd
);
558 width
= MSI_RecordGetInteger( rec
, 4 );
559 height
= MSI_RecordGetInteger( rec
, 5 );
560 dialog
->attributes
= MSI_RecordGetInteger( rec
, 6 );
561 text
= MSI_RecordGetString( rec
, 7 );
563 width
= msi_dialog_scale_unit( dialog
, width
);
564 height
= msi_dialog_scale_unit( dialog
, height
) + 25; /* FIXME */
566 dialog
->default_font
= load_dynamic_property( dialog
->package
, df
, NULL
);
568 deformat_string( dialog
->package
, text
, &title
);
569 SetWindowTextW( hwnd
, title
);
570 SetWindowPos( hwnd
, 0, 0, 0, width
, height
,
571 SWP_NOMOVE
| SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_NOREDRAW
);
573 HeapFree( GetProcessHeap(), 0, title
);
574 msiobj_release( &rec
->hdr
);
576 msi_dialog_build_font_list( dialog
);
577 msi_dialog_fill_controls( dialog
);
578 msi_dialog_evaluate_control_conditions( dialog
);
583 static UINT
msi_dialog_send_event( msi_dialog
*dialog
, LPCWSTR event
, LPCWSTR arg
)
585 LPWSTR event_fmt
= NULL
, arg_fmt
= NULL
;
587 TRACE("Sending control event %s %s\n", debugstr_w(event
), debugstr_w(arg
));
589 deformat_string( dialog
->package
, event
, &event_fmt
);
590 deformat_string( dialog
->package
, arg
, &arg_fmt
);
592 dialog
->event_handler( dialog
->package
, event_fmt
, arg_fmt
, dialog
);
594 HeapFree( GetProcessHeap(), 0, event_fmt
);
595 HeapFree( GetProcessHeap(), 0, arg_fmt
);
597 return ERROR_SUCCESS
;
600 static UINT
msi_dialog_set_property( msi_dialog
*dialog
, LPCWSTR event
, LPCWSTR arg
)
602 static const WCHAR szNullArg
[] = { '{','}',0 };
603 LPWSTR p
, prop
, arg_fmt
= NULL
;
606 len
= strlenW(event
);
607 prop
= HeapAlloc( GetProcessHeap(), 0, len
*sizeof(WCHAR
));
608 strcpyW( prop
, &event
[1] );
609 p
= strchrW( prop
, ']' );
613 if( strcmpW( szNullArg
, arg
) )
614 deformat_string( dialog
->package
, arg
, &arg_fmt
);
615 MSI_SetPropertyW( dialog
->package
, prop
, arg_fmt
);
618 ERR("Badly formatted property string - what happens?\n");
619 HeapFree( GetProcessHeap(), 0, prop
);
620 return ERROR_SUCCESS
;
623 static UINT
msi_dialog_control_event( MSIRECORD
*rec
, LPVOID param
)
625 msi_dialog
*dialog
= param
;
626 LPCWSTR condition
, event
, arg
;
629 condition
= MSI_RecordGetString( rec
, 5 );
630 r
= MSI_EvaluateConditionW( dialog
->package
, condition
);
633 event
= MSI_RecordGetString( rec
, 3 );
634 arg
= MSI_RecordGetString( rec
, 4 );
635 if( event
[0] == '[' )
636 msi_dialog_set_property( dialog
, event
, arg
);
638 msi_dialog_send_event( dialog
, event
, arg
);
641 return ERROR_SUCCESS
;
644 static UINT
msi_dialog_button_click( msi_dialog
*dialog
, msi_control
*control
)
646 static const WCHAR query
[] = {
647 'S','E','L','E','C','T',' ','*',' ',
648 'F','R','O','M',' ','C','o','n','t','r','o','l','E','v','e','n','t',' ',
649 'W','H','E','R','E',' ',
650 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',' ',
652 '`','C','o','n','t','r','o','l','_','`',' ','=',' ','\'','%','s','\'',' ',
653 'O','R','D','E','R',' ','B','Y',' ','`','O','r','d','e','r','i','n','g','`',0
655 MSIQUERY
*view
= NULL
;
658 r
= MSI_OpenQuery( dialog
->package
->db
, &view
, query
,
659 dialog
->name
, control
->name
);
660 if( r
!= ERROR_SUCCESS
)
662 ERR("query failed\n");
666 r
= MSI_IterateRecords( view
, 0, msi_dialog_control_event
, dialog
);
667 msiobj_release( &view
->hdr
);
672 static UINT
msi_dialog_get_checkbox_state( msi_dialog
*dialog
,
673 msi_control
*control
)
675 WCHAR state
[2] = { 0 };
678 MSI_GetPropertyW( dialog
->package
, control
->property
, state
, &sz
);
679 return atoiW( state
) ? 1 : 0;
682 static void msi_dialog_set_checkbox_state( msi_dialog
*dialog
,
683 msi_control
*control
, UINT state
)
685 WCHAR szState
[2] = { '0', 0 };
689 MSI_SetPropertyW( dialog
->package
, control
->property
, szState
);
692 static void msi_dialog_checkbox_sync_state( msi_dialog
*dialog
,
693 msi_control
*control
)
697 state
= msi_dialog_get_checkbox_state( dialog
, control
);
698 SendMessageW( control
->hwnd
, BM_SETCHECK
,
699 state
? BST_CHECKED
: BST_UNCHECKED
, 0 );
702 static UINT
msi_dialog_checkbox_click( msi_dialog
*dialog
,
703 msi_control
*control
)
707 TRACE("clicked checkbox %s, set %s\n", debugstr_w(control
->name
),
708 debugstr_w(control
->property
));
710 state
= msi_dialog_get_checkbox_state( dialog
, control
);
711 state
= state
? 0 : 1;
712 msi_dialog_set_checkbox_state( dialog
, control
, state
);
713 msi_dialog_checkbox_sync_state( dialog
, control
);
715 return msi_dialog_button_click( dialog
, control
);
718 static LRESULT
msi_dialog_handle_click( msi_dialog
*dialog
, HWND hwnd
)
720 msi_control
*control
;
722 TRACE("BN_CLICKED %p %p\n", dialog
, hwnd
);
724 control
= msi_dialog_find_control_by_hwnd( dialog
, hwnd
);
727 if( control
->click_handler
)
729 control
->click_handler( dialog
, control
);
730 msi_dialog_evaluate_control_conditions( dialog
);
734 ERR("button click from nowhere\n");
738 static LRESULT WINAPI
MSIDialog_WndProc( HWND hwnd
, UINT msg
,
739 WPARAM wParam
, LPARAM lParam
)
741 msi_dialog
*dialog
= (LPVOID
) GetWindowLongPtrW( hwnd
, GWLP_USERDATA
);
746 return msi_dialog_oncreate( hwnd
, (LPCREATESTRUCTW
)lParam
);
749 if( HIWORD(wParam
) == BN_CLICKED
)
750 return msi_dialog_handle_click( dialog
, (HWND
)lParam
);
757 return DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
760 /* functions that interface to other modules within MSI */
762 msi_dialog
*msi_dialog_create( MSIPACKAGE
* package
, LPCWSTR szDialogName
,
763 msi_dialog_event_handler event_handler
)
768 TRACE("%p %s\n", package
, debugstr_w(szDialogName
));
770 /* allocate the structure for the dialog to use */
771 dialog
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
,
772 sizeof *dialog
+ sizeof(WCHAR
)*strlenW(szDialogName
) );
775 strcpyW( dialog
->name
, szDialogName
);
776 dialog
->package
= package
;
777 dialog
->event_handler
= event_handler
;
779 /* create the dialog window, don't show it yet */
780 hwnd
= CreateWindowW( szMsiDialogClass
, szDialogName
, WS_OVERLAPPEDWINDOW
,
781 CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
,
782 NULL
, NULL
, NULL
, dialog
);
785 ERR("Failed to create dialog %s\n", debugstr_w( szDialogName
));
786 msi_dialog_destroy( dialog
);
793 void msi_dialog_end_dialog( msi_dialog
*dialog
)
795 dialog
->finished
= 1;
798 UINT
msi_dialog_run_message_loop( msi_dialog
*dialog
)
802 if( dialog
->attributes
& msidbDialogAttributesVisible
)
804 ShowWindow( dialog
->hwnd
, SW_SHOW
);
805 UpdateWindow( dialog
->hwnd
);
808 if( dialog
->attributes
& msidbDialogAttributesModal
)
810 while( !dialog
->finished
&& GetMessageW( &msg
, 0, 0, 0 ) )
812 TranslateMessage( &msg
);
813 DispatchMessageW( &msg
);
817 return ERROR_IO_PENDING
;
819 return ERROR_SUCCESS
;
822 void msi_dialog_check_messages( msi_dialog
*dialog
, HANDLE handle
)
829 while( PeekMessageW( &msg
, 0, 0, 0, PM_REMOVE
) )
831 TranslateMessage( &msg
);
832 DispatchMessageW( &msg
);
836 r
= MsgWaitForMultipleObjects( 1, &handle
, 0, INFINITE
, QS_ALLEVENTS
);
838 while( WAIT_OBJECT_0
!= r
);
841 void msi_dialog_do_preview( msi_dialog
*dialog
)
843 dialog
->attributes
|= msidbDialogAttributesVisible
;
844 dialog
->attributes
&= ~msidbDialogAttributesModal
;
845 msi_dialog_run_message_loop( dialog
);
848 void msi_dialog_destroy( msi_dialog
*dialog
)
851 ShowWindow( dialog
->hwnd
, SW_HIDE
);
853 /* destroy the list of controls */
854 while( dialog
->control_list
)
856 msi_control
*t
= dialog
->control_list
;
857 dialog
->control_list
= t
->next
;
858 /* leave dialog->hwnd - destroying parent destroys child windows */
859 HeapFree( GetProcessHeap(), 0, t
->property
);
860 HeapFree( GetProcessHeap(), 0, t
);
863 /* destroy the list of fonts */
864 while( dialog
->font_list
)
866 msi_font
*t
= dialog
->font_list
;
867 dialog
->font_list
= t
->next
;
868 DeleteObject( t
->hfont
);
869 HeapFree( GetProcessHeap(), 0, t
);
871 HeapFree( GetProcessHeap(), 0, dialog
->default_font
);
874 DestroyWindow( dialog
->hwnd
);
876 dialog
->package
= NULL
;
877 HeapFree( GetProcessHeap(), 0, dialog
);
880 void msi_dialog_register_class( void )
884 ZeroMemory( &cls
, sizeof cls
);
885 cls
.lpfnWndProc
= MSIDialog_WndProc
;
886 cls
.hInstance
= NULL
;
887 cls
.hIcon
= LoadIconW(0, (LPWSTR
)IDI_APPLICATION
);
888 cls
.hCursor
= LoadCursorW(0, (LPWSTR
)IDC_ARROW
);
889 cls
.hbrBackground
= (HBRUSH
)(COLOR_WINDOW
);
890 cls
.lpszMenuName
= NULL
;
891 cls
.lpszClassName
= szMsiDialogClass
;
893 RegisterClassW( &cls
);
896 void msi_dialog_unregister_class( void )
898 UnregisterClassW( szMsiDialogClass
, NULL
);