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
36 #include "wine/debug.h"
37 #include "wine/unicode.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(msi
);
44 const WCHAR szMsiDialogClass
[] = {
45 'M','s','i','D','i','a','l','o','g','C','l','o','s','e','C','l','a','s','s',0
47 const static WCHAR szStatic
[] = { 'S','t','a','t','i','c',0 };
48 const static WCHAR szButton
[] = { 'B','U','T','T','O','N', 0 };
50 const static WCHAR szButtonData
[] = { 'M','S','I','D','A','T','A',0 };
52 struct msi_control_tag
;
53 typedef struct msi_control_tag msi_control
;
54 typedef UINT (*msi_handler
)( msi_dialog
*, msi_control
*, WPARAM
);
56 struct msi_control_tag
58 struct msi_control_tag
*next
;
66 typedef struct msi_font_tag
68 struct msi_font_tag
*next
;
76 msi_dialog_event_handler event_handler
;
83 msi_control
*control_list
;
87 typedef UINT (*msi_dialog_control_func
)( msi_dialog
*dialog
, MSIRECORD
*rec
);
88 struct control_handler
91 msi_dialog_control_func func
;
99 } radio_button_group_descr
;
101 static UINT
msi_dialog_checkbox_handler( msi_dialog
*, msi_control
*, WPARAM
);
102 static void msi_dialog_checkbox_sync_state( msi_dialog
*, msi_control
* );
103 static UINT
msi_dialog_button_handler( msi_dialog
*, msi_control
*, WPARAM
);
104 static UINT
msi_dialog_edit_handler( msi_dialog
*, msi_control
*, WPARAM
);
105 static UINT
msi_dialog_radiogroup_handler( msi_dialog
*, msi_control
*, WPARAM param
);
106 static LRESULT WINAPI
MSIRadioGroup_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
);
109 INT
msi_dialog_scale_unit( msi_dialog
*dialog
, INT val
)
111 return (dialog
->scale
* val
+ 5) / 10;
115 * msi_dialog_get_style
117 * Extract the {\style} string from the front of the text to display and
118 * update the pointer.
120 static LPWSTR
msi_dialog_get_style( LPCWSTR
*text
)
123 LPCWSTR p
= *text
, q
;
128 q
= strchrW( p
, '}' );
136 ret
= HeapAlloc( GetProcessHeap(), 0, len
*sizeof(WCHAR
) );
139 memcpy( ret
, p
, len
*sizeof(WCHAR
) );
144 static UINT
msi_dialog_add_font( MSIRECORD
*rec
, LPVOID param
)
146 msi_dialog
*dialog
= param
;
153 /* create a font and add it to the list */
154 name
= MSI_RecordGetString( rec
, 1 );
155 font
= HeapAlloc( GetProcessHeap(), 0,
156 sizeof *font
+ strlenW( name
)*sizeof (WCHAR
) );
157 strcpyW( font
->name
, name
);
158 font
->next
= dialog
->font_list
;
159 dialog
->font_list
= font
;
161 memset( &lf
, 0, sizeof lf
);
162 face
= MSI_RecordGetString( rec
, 2 );
163 lf
.lfHeight
= MSI_RecordGetInteger( rec
, 3 );
164 style
= MSI_RecordGetInteger( rec
, 5 );
165 if( style
& msidbTextStyleStyleBitsBold
)
166 lf
.lfWeight
= FW_BOLD
;
167 if( style
& msidbTextStyleStyleBitsItalic
)
169 if( style
& msidbTextStyleStyleBitsUnderline
)
170 lf
.lfUnderline
= TRUE
;
171 if( style
& msidbTextStyleStyleBitsStrike
)
172 lf
.lfStrikeOut
= TRUE
;
173 lstrcpynW( lf
.lfFaceName
, face
, LF_FACESIZE
);
175 /* adjust the height */
176 hdc
= GetDC( dialog
->hwnd
);
179 lf
.lfHeight
= -MulDiv(lf
.lfHeight
, GetDeviceCaps(hdc
, LOGPIXELSY
), 72);
180 ReleaseDC( dialog
->hwnd
, hdc
);
183 font
->hfont
= CreateFontIndirectW( &lf
);
185 TRACE("Adding font style %s\n", debugstr_w(font
->name
) );
187 return ERROR_SUCCESS
;
190 static msi_font
*msi_dialog_find_font( msi_dialog
*dialog
, LPCWSTR name
)
194 for( font
= dialog
->font_list
; font
; font
= font
->next
)
195 if( !strcmpW( font
->name
, name
) ) /* FIXME: case sensitive? */
201 static UINT
msi_dialog_set_font( msi_dialog
*dialog
, HWND hwnd
, LPCWSTR name
)
205 font
= msi_dialog_find_font( dialog
, name
);
207 SendMessageW( hwnd
, WM_SETFONT
, (WPARAM
) font
->hfont
, TRUE
);
209 ERR("No font entry for %s\n", debugstr_w(name
));
210 return ERROR_SUCCESS
;
213 static UINT
msi_dialog_build_font_list( msi_dialog
*dialog
)
215 static const WCHAR query
[] = {
216 'S','E','L','E','C','T',' ','*',' ',
217 'F','R','O','M',' ','`','T','e','x','t','S','t','y','l','e','`',' ',0
220 MSIQUERY
*view
= NULL
;
222 TRACE("dialog %p\n", dialog
);
224 r
= MSI_OpenQuery( dialog
->package
->db
, &view
, query
);
225 if( r
!= ERROR_SUCCESS
)
228 r
= MSI_IterateRecords( view
, NULL
, msi_dialog_add_font
, dialog
);
229 msiobj_release( &view
->hdr
);
234 static msi_control
*msi_dialog_create_window( msi_dialog
*dialog
,
235 MSIRECORD
*rec
, LPCWSTR szCls
, LPCWSTR name
, LPCWSTR text
,
236 DWORD style
, HWND parent
)
238 DWORD x
, y
, width
, height
;
239 LPWSTR font
= NULL
, title
= NULL
;
240 msi_control
*control
;
242 style
|= WS_CHILD
| WS_GROUP
;
244 control
= HeapAlloc( GetProcessHeap(), 0,
245 sizeof *control
+ strlenW(name
)*sizeof(WCHAR
) );
246 strcpyW( control
->name
, name
);
247 control
->next
= dialog
->control_list
;
248 dialog
->control_list
= control
;
249 control
->handler
= NULL
;
250 control
->property
= NULL
;
253 x
= MSI_RecordGetInteger( rec
, 4 );
254 y
= MSI_RecordGetInteger( rec
, 5 );
255 width
= MSI_RecordGetInteger( rec
, 6 );
256 height
= MSI_RecordGetInteger( rec
, 7 );
258 x
= msi_dialog_scale_unit( dialog
, x
);
259 y
= msi_dialog_scale_unit( dialog
, y
);
260 width
= msi_dialog_scale_unit( dialog
, width
);
261 height
= msi_dialog_scale_unit( dialog
, height
);
265 font
= msi_dialog_get_style( &text
);
266 deformat_string( dialog
->package
, text
, &title
);
269 control
->hwnd
= CreateWindowW( szCls
, title
, style
,
270 x
, y
, width
, height
, parent
, NULL
, NULL
, NULL
);
272 TRACE("Dialog %s control %s hwnd %p\n",
273 debugstr_w(dialog
->name
), debugstr_w(text
), control
->hwnd
);
275 msi_dialog_set_font( dialog
, control
->hwnd
,
276 font
? font
: dialog
->default_font
);
278 HeapFree( GetProcessHeap(), 0, font
);
279 HeapFree( GetProcessHeap(), 0, title
);
284 /* everything except radio buttons */
285 static msi_control
*msi_dialog_add_control( msi_dialog
*dialog
,
286 MSIRECORD
*rec
, LPCWSTR szCls
, DWORD style
)
291 name
= MSI_RecordGetString( rec
, 2 );
292 attributes
= MSI_RecordGetInteger( rec
, 8 );
293 text
= MSI_RecordGetString( rec
, 10 );
296 if( ~attributes
& 2 )
297 style
|= WS_DISABLED
;
298 return msi_dialog_create_window( dialog
, rec
, szCls
, name
, text
,
299 style
, dialog
->hwnd
);
302 static UINT
msi_dialog_text_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
304 TRACE("%p %p\n", dialog
, rec
);
306 msi_dialog_add_control( dialog
, rec
, szStatic
, 0 );
307 return ERROR_SUCCESS
;
310 static UINT
msi_dialog_button_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
312 msi_control
*control
;
314 TRACE("%p %p\n", dialog
, rec
);
316 control
= msi_dialog_add_control( dialog
, rec
, szButton
, 0 );
317 control
->handler
= msi_dialog_button_handler
;
319 return ERROR_SUCCESS
;
322 static UINT
msi_dialog_checkbox_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
324 msi_control
*control
;
327 TRACE("%p %p\n", dialog
, rec
);
329 control
= msi_dialog_add_control( dialog
, rec
, szButton
,
330 BS_CHECKBOX
| BS_MULTILINE
);
331 control
->handler
= msi_dialog_checkbox_handler
;
332 prop
= MSI_RecordGetString( rec
, 9 );
334 control
->property
= strdupW( prop
);
335 msi_dialog_checkbox_sync_state( dialog
, control
);
337 return ERROR_SUCCESS
;
340 static UINT
msi_dialog_line_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
342 TRACE("%p %p\n", dialog
, rec
);
344 msi_dialog_add_control( dialog
, rec
, szStatic
, SS_ETCHEDHORZ
| SS_SUNKEN
);
345 return ERROR_SUCCESS
;
348 static UINT
msi_dialog_scrolltext_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
350 const static WCHAR szEdit
[] = { 'E','D','I','T',0 };
352 FIXME("%p %p\n", dialog
, rec
);
354 msi_dialog_add_control( dialog
, rec
, szEdit
, WS_BORDER
|
355 ES_MULTILINE
| WS_VSCROLL
| ES_READONLY
| ES_AUTOVSCROLL
);
357 return ERROR_SUCCESS
;
360 static UINT
msi_load_bitmap( MSIDATABASE
*db
, LPCWSTR name
, IPicture
**pic
)
362 const static WCHAR query
[] = {
363 's','e','l','e','c','t',' ','*',' ',
364 'f','r','o','m',' ','B','i','n','a','r','y',' ',
365 'w','h','e','r','e',' ',
366 '`','N','a','m','e','`',' ','=',' ','\'','%','s','\'',0
368 MSIQUERY
*view
= NULL
;
369 MSIRECORD
*rec
= NULL
;
373 r
= MSI_OpenQuery( db
, &view
, query
, name
);
374 if( r
!= ERROR_SUCCESS
)
377 MSI_ViewExecute( view
, NULL
);
378 MSI_ViewFetch( view
, &rec
);
379 MSI_ViewClose( view
);
380 msiobj_release( &view
->hdr
);
383 return ERROR_FUNCTION_FAILED
;
385 r
= MSI_RecordGetIStream( rec
, 2, &stm
);
386 msiobj_release( &rec
->hdr
);
387 if( r
!= ERROR_SUCCESS
)
390 r
= OleLoadPicture( stm
, 0, TRUE
, &IID_IPicture
, (LPVOID
*) pic
);
391 IStream_Release( stm
);
393 return ERROR_FUNCTION_FAILED
;
395 return ERROR_SUCCESS
;
398 static UINT
msi_dialog_bitmap_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
400 IPicture
*pic
= NULL
;
401 msi_control
*control
;
402 OLE_HANDLE hBitmap
= 0;
406 control
= msi_dialog_add_control( dialog
, rec
, szStatic
,
407 SS_BITMAP
| SS_LEFT
| SS_CENTERIMAGE
);
408 text
= MSI_RecordGetString( rec
, 10 );
409 r
= msi_load_bitmap( dialog
->package
->db
, text
, &pic
);
410 if( r
== ERROR_SUCCESS
)
412 r
= IPicture_get_Handle( pic
, &hBitmap
);
414 SendMessageW( control
->hwnd
, STM_SETIMAGE
, IMAGE_BITMAP
, hBitmap
);
418 return ERROR_SUCCESS
;
421 static UINT
msi_dialog_combo_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
423 static const WCHAR szCombo
[] = { 'C','O','M','B','O','B','O','X',0 };
425 msi_dialog_add_control( dialog
, rec
, szCombo
,
426 SS_BITMAP
| SS_LEFT
| SS_CENTERIMAGE
);
427 return ERROR_SUCCESS
;
430 static UINT
msi_dialog_edit_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
432 const static WCHAR szEdit
[] = { 'E','D','I','T',0 };
433 msi_control
*control
;
437 control
= msi_dialog_add_control( dialog
, rec
, szEdit
, WS_BORDER
);
438 control
->handler
= msi_dialog_edit_handler
;
439 prop
= MSI_RecordGetString( rec
, 9 );
441 control
->property
= strdupW( prop
);
442 val
= load_dynamic_property( dialog
->package
, control
->property
, NULL
);
443 SetWindowTextW( control
->hwnd
, val
);
444 HeapFree( GetProcessHeap(), 0, val
);
445 return ERROR_SUCCESS
;
448 static UINT
msi_dialog_pathedit_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
450 FIXME("not implemented properly\n");
451 return msi_dialog_edit_control( dialog
, rec
);
454 /* radio buttons are a bit different from normal controls */
455 static UINT
msi_dialog_create_radiobutton( MSIRECORD
*rec
, LPVOID param
)
457 radio_button_group_descr
*group
= (radio_button_group_descr
*)param
;
458 msi_dialog
*dialog
= group
->dialog
;
459 msi_control
*control
;
460 LPCWSTR prop
, text
, name
;
462 DWORD attributes
= group
->attributes
;
464 style
= WS_CHILD
| BS_AUTORADIOBUTTON
| BS_MULTILINE
;
465 name
= MSI_RecordGetString( rec
, 3 );
466 text
= MSI_RecordGetString( rec
, 8 );
469 if( ~attributes
& 2 )
470 style
|= WS_DISABLED
;
472 control
= msi_dialog_create_window( dialog
, rec
, szButton
, name
, text
,
473 style
, group
->parent
->hwnd
);
474 control
->handler
= msi_dialog_radiogroup_handler
;
476 prop
= MSI_RecordGetString( rec
, 1 );
478 control
->property
= strdupW( prop
);
480 return ERROR_SUCCESS
;
483 static UINT
msi_dialog_radiogroup_control( msi_dialog
*dialog
, MSIRECORD
*rec
)
485 static const WCHAR query
[] = {
486 'S','E','L','E','C','T',' ','*',' ',
487 'F','R','O','M',' ','R','a','d','i','o','B','u','t','t','o','n',' ',
488 'W','H','E','R','E',' ',
489 '`','P','r','o','p','e','r','t','y','`',' ','=',' ','\'','%','s','\'',0};
492 msi_control
*control
;
493 MSIQUERY
*view
= NULL
;
494 radio_button_group_descr group
;
495 MSIPACKAGE
*package
= dialog
->package
;
497 prop
= MSI_RecordGetString( rec
, 9 );
499 TRACE("%p %p %s\n", dialog
, rec
, debugstr_w( prop
));
501 /* Create parent group box to hold radio buttons */
502 control
= msi_dialog_add_control( dialog
, rec
, szButton
, BS_OWNERDRAW
);
506 WNDPROC oldproc
= (WNDPROC
) SetWindowLongPtrW(control
->hwnd
, GWLP_WNDPROC
,
507 (LONG_PTR
)MSIRadioGroup_WndProc
);
508 SetPropW(control
->hwnd
, szButtonData
, oldproc
);
512 control
->property
= strdupW( prop
);
514 /* query the Radio Button table for all control in this group */
515 r
= MSI_OpenQuery( package
->db
, &view
, query
, prop
);
516 if( r
!= ERROR_SUCCESS
)
518 ERR("query failed for dialog %s radio group %s\n",
519 debugstr_w(dialog
->name
), debugstr_w(prop
));
520 return ERROR_INVALID_PARAMETER
;
523 group
.dialog
= dialog
;
524 group
.parent
= control
;
525 group
.attributes
= MSI_RecordGetInteger( rec
, 8 );
527 r
= MSI_IterateRecords( view
, 0, msi_dialog_create_radiobutton
, &group
);
528 msiobj_release( &view
->hdr
);
533 static const WCHAR szText
[] = { 'T','e','x','t',0 };
534 static const WCHAR szPushButton
[] = { 'P','u','s','h','B','u','t','t','o','n',0 };
535 static const WCHAR szLine
[] = { 'L','i','n','e',0 };
536 static const WCHAR szBitmap
[] = { 'B','i','t','m','a','p',0 };
537 static const WCHAR szCheckBox
[] = { 'C','h','e','c','k','B','o','x',0 };
538 static const WCHAR szScrollableText
[] = {
539 'S','c','r','o','l','l','a','b','l','e','T','e','x','t',0 };
540 static const WCHAR szComboBox
[] = { 'C','o','m','b','o','B','o','x',0 };
541 static const WCHAR szEdit
[] = { 'E','d','i','t',0 };
542 static const WCHAR szMaskedEdit
[] = { 'M','a','s','k','e','d','E','d','i','t',0 };
543 static const WCHAR szPathEdit
[] = { 'P','a','t','h','E','d','i','t',0 };
544 static const WCHAR szRadioButtonGroup
[] = {
545 'R','a','d','i','o','B','u','t','t','o','n','G','r','o','u','p',0 };
547 struct control_handler msi_dialog_handler
[] =
549 { szText
, msi_dialog_text_control
},
550 { szPushButton
, msi_dialog_button_control
},
551 { szLine
, msi_dialog_line_control
},
552 { szBitmap
, msi_dialog_bitmap_control
},
553 { szCheckBox
, msi_dialog_checkbox_control
},
554 { szScrollableText
, msi_dialog_scrolltext_control
},
555 { szComboBox
, msi_dialog_combo_control
},
556 { szEdit
, msi_dialog_edit_control
},
557 { szMaskedEdit
, msi_dialog_edit_control
},
558 { szPathEdit
, msi_dialog_pathedit_control
},
559 { szRadioButtonGroup
, msi_dialog_radiogroup_control
},
562 #define NUM_CONTROL_TYPES (sizeof msi_dialog_handler/sizeof msi_dialog_handler[0])
564 static UINT
msi_dialog_create_controls( MSIRECORD
*rec
, LPVOID param
)
566 msi_dialog
*dialog
= param
;
567 LPCWSTR control_type
;
570 /* find and call the function that can create this type of control */
571 control_type
= MSI_RecordGetString( rec
, 3 );
572 for( i
=0; i
<NUM_CONTROL_TYPES
; i
++ )
573 if (!strcmpiW( msi_dialog_handler
[i
].control_type
, control_type
))
575 if( i
!= NUM_CONTROL_TYPES
)
576 msi_dialog_handler
[i
].func( dialog
, rec
);
578 ERR("no handler for element type %s\n", debugstr_w(control_type
));
580 return ERROR_SUCCESS
;
583 static UINT
msi_dialog_fill_controls( msi_dialog
*dialog
)
585 static const WCHAR query
[] = {
586 'S','E','L','E','C','T',' ','*',' ',
587 'F','R','O','M',' ','C','o','n','t','r','o','l',' ',
588 'W','H','E','R','E',' ',
589 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',0};
591 MSIQUERY
*view
= NULL
;
592 MSIPACKAGE
*package
= dialog
->package
;
594 TRACE("%p %s\n", dialog
, debugstr_w(dialog
->name
) );
596 /* query the Control table for all the elements of the control */
597 r
= MSI_OpenQuery( package
->db
, &view
, query
, dialog
->name
);
598 if( r
!= ERROR_SUCCESS
)
600 ERR("query failed for dialog %s\n", debugstr_w(dialog
->name
));
601 return ERROR_INVALID_PARAMETER
;
604 r
= MSI_IterateRecords( view
, 0, msi_dialog_create_controls
, dialog
);
605 msiobj_release( &view
->hdr
);
610 static msi_control
*msi_dialog_find_control( msi_dialog
*dialog
, LPCWSTR name
)
612 msi_control
*control
;
614 for( control
= dialog
->control_list
; control
; control
= control
->next
)
615 if( !strcmpW( control
->name
, name
) ) /* FIXME: case sensitive? */
620 static msi_control
*msi_dialog_find_control_by_hwnd( msi_dialog
*dialog
, HWND hwnd
)
622 msi_control
*control
;
624 for( control
= dialog
->control_list
; control
; control
= control
->next
)
625 if( hwnd
== control
->hwnd
)
630 static UINT
msi_dialog_set_control_condition( MSIRECORD
*rec
, LPVOID param
)
632 static const WCHAR szHide
[] = { 'H','i','d','e',0 };
633 static const WCHAR szShow
[] = { 'S','h','o','w',0 };
634 static const WCHAR szDisable
[] = { 'D','i','s','a','b','l','e',0 };
635 static const WCHAR szEnable
[] = { 'E','n','a','b','l','e',0 };
636 msi_dialog
*dialog
= param
;
637 msi_control
*control
;
638 LPCWSTR name
, action
, condition
;
641 name
= MSI_RecordGetString( rec
, 2 );
642 action
= MSI_RecordGetString( rec
, 3 );
643 condition
= MSI_RecordGetString( rec
, 4 );
644 r
= MSI_EvaluateConditionW( dialog
->package
, condition
);
645 control
= msi_dialog_find_control( dialog
, name
);
648 TRACE("%s control %s\n", debugstr_w(action
), debugstr_w(name
));
650 /* FIXME: case sensitive? */
651 if(!strcmpW(action
, szHide
))
652 ShowWindow(control
->hwnd
, SW_HIDE
);
653 else if(!strcmpW(action
, szShow
))
654 ShowWindow(control
->hwnd
, SW_SHOW
);
655 else if(!strcmpW(action
, szDisable
))
656 EnableWindow(control
->hwnd
, FALSE
);
657 else if(!strcmpW(action
, szEnable
))
658 EnableWindow(control
->hwnd
, TRUE
);
660 FIXME("Unhandled action %s\n", debugstr_w(action
));
663 return ERROR_SUCCESS
;
666 static UINT
msi_dialog_evaluate_control_conditions( msi_dialog
*dialog
)
668 static const WCHAR query
[] = {
669 'S','E','L','E','C','T',' ','*',' ',
671 'C','o','n','t','r','o','l','C','o','n','d','i','t','i','o','n',' ',
672 'W','H','E','R','E',' ',
673 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',0
676 MSIQUERY
*view
= NULL
;
677 MSIPACKAGE
*package
= dialog
->package
;
679 TRACE("%p %s\n", dialog
, debugstr_w(dialog
->name
) );
681 /* query the Control table for all the elements of the control */
682 r
= MSI_OpenQuery( package
->db
, &view
, query
, dialog
->name
);
683 if( r
!= ERROR_SUCCESS
)
685 ERR("query failed for dialog %s\n", debugstr_w(dialog
->name
));
686 return ERROR_INVALID_PARAMETER
;
689 r
= MSI_IterateRecords( view
, 0, msi_dialog_set_control_condition
, dialog
);
690 msiobj_release( &view
->hdr
);
695 /* figure out the height of 10 point MS Sans Serif */
696 static INT
msi_dialog_get_sans_serif_height( HWND hwnd
)
698 static const WCHAR szSansSerif
[] = {
699 'M','S',' ','S','a','n','s',' ','S','e','r','i','f',0 };
704 HFONT hFont
, hOldFont
;
710 memset( &lf
, 0, sizeof lf
);
711 lf
.lfHeight
= MulDiv(10, GetDeviceCaps(hdc
, LOGPIXELSY
), 72);
712 strcpyW( lf
.lfFaceName
, szSansSerif
);
713 hFont
= CreateFontIndirectW(&lf
);
716 hOldFont
= SelectObject( hdc
, hFont
);
717 r
= GetTextMetricsW( hdc
, &tm
);
719 height
= tm
.tmHeight
;
720 SelectObject( hdc
, hOldFont
);
721 DeleteObject( hFont
);
723 ReleaseDC( hwnd
, hdc
);
728 static LRESULT
msi_dialog_oncreate( HWND hwnd
, LPCREATESTRUCTW cs
)
730 static const WCHAR query
[] = {
731 'S','E','L','E','C','T',' ','*',' ',
732 'F','R','O','M',' ','D','i','a','l','o','g',' ',
733 'W','H','E','R','E',' ',
734 '`','D','i','a','l','o','g','`',' ','=',' ','\'','%','s','\'',0};
735 static const WCHAR df
[] = {
736 'D','e','f','a','u','l','t','U','I','F','o','n','t',0 };
737 msi_dialog
*dialog
= (msi_dialog
*) cs
->lpCreateParams
;
738 MSIPACKAGE
*package
= dialog
->package
;
739 MSIQUERY
*view
= NULL
;
740 MSIRECORD
*rec
= NULL
;
746 TRACE("%p %p\n", dialog
, package
);
749 SetWindowLongPtrW( hwnd
, GWLP_USERDATA
, (LONG_PTR
) dialog
);
751 /* fetch the associated record from the Dialog table */
752 r
= MSI_OpenQuery( package
->db
, &view
, query
, dialog
->name
);
753 if( r
!= ERROR_SUCCESS
)
755 ERR("query failed for dialog %s\n", debugstr_w(dialog
->name
));
758 MSI_ViewExecute( view
, NULL
);
759 MSI_ViewFetch( view
, &rec
);
760 MSI_ViewClose( view
);
761 msiobj_release( &view
->hdr
);
765 TRACE("No record found for dialog %s\n", debugstr_w(dialog
->name
));
769 dialog
->scale
= msi_dialog_get_sans_serif_height(dialog
->hwnd
);
771 width
= MSI_RecordGetInteger( rec
, 4 );
772 height
= MSI_RecordGetInteger( rec
, 5 );
773 dialog
->attributes
= MSI_RecordGetInteger( rec
, 6 );
774 text
= MSI_RecordGetString( rec
, 7 );
776 width
= msi_dialog_scale_unit( dialog
, width
);
777 height
= msi_dialog_scale_unit( dialog
, height
) + 25; /* FIXME */
779 dialog
->default_font
= load_dynamic_property( dialog
->package
, df
, NULL
);
781 deformat_string( dialog
->package
, text
, &title
);
782 SetWindowTextW( hwnd
, title
);
783 SetWindowPos( hwnd
, 0, 0, 0, width
, height
,
784 SWP_NOMOVE
| SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_NOREDRAW
);
786 HeapFree( GetProcessHeap(), 0, title
);
787 msiobj_release( &rec
->hdr
);
789 msi_dialog_build_font_list( dialog
);
790 msi_dialog_fill_controls( dialog
);
791 msi_dialog_evaluate_control_conditions( dialog
);
796 static UINT
msi_dialog_send_event( msi_dialog
*dialog
, LPCWSTR event
, LPCWSTR arg
)
798 LPWSTR event_fmt
= NULL
, arg_fmt
= NULL
;
800 TRACE("Sending control event %s %s\n", debugstr_w(event
), debugstr_w(arg
));
802 deformat_string( dialog
->package
, event
, &event_fmt
);
803 deformat_string( dialog
->package
, arg
, &arg_fmt
);
805 dialog
->event_handler( dialog
->package
, event_fmt
, arg_fmt
, dialog
);
807 HeapFree( GetProcessHeap(), 0, event_fmt
);
808 HeapFree( GetProcessHeap(), 0, arg_fmt
);
810 return ERROR_SUCCESS
;
813 static UINT
msi_dialog_set_property( msi_dialog
*dialog
, LPCWSTR event
, LPCWSTR arg
)
815 static const WCHAR szNullArg
[] = { '{','}',0 };
816 LPWSTR p
, prop
, arg_fmt
= NULL
;
819 len
= strlenW(event
);
820 prop
= HeapAlloc( GetProcessHeap(), 0, len
*sizeof(WCHAR
));
821 strcpyW( prop
, &event
[1] );
822 p
= strchrW( prop
, ']' );
826 if( strcmpW( szNullArg
, arg
) )
827 deformat_string( dialog
->package
, arg
, &arg_fmt
);
828 MSI_SetPropertyW( dialog
->package
, prop
, arg_fmt
);
831 ERR("Badly formatted property string - what happens?\n");
832 HeapFree( GetProcessHeap(), 0, prop
);
833 return ERROR_SUCCESS
;
836 static UINT
msi_dialog_control_event( MSIRECORD
*rec
, LPVOID param
)
838 msi_dialog
*dialog
= param
;
839 LPCWSTR condition
, event
, arg
;
842 condition
= MSI_RecordGetString( rec
, 5 );
843 r
= MSI_EvaluateConditionW( dialog
->package
, condition
);
846 event
= MSI_RecordGetString( rec
, 3 );
847 arg
= MSI_RecordGetString( rec
, 4 );
848 if( event
[0] == '[' )
849 msi_dialog_set_property( dialog
, event
, arg
);
851 msi_dialog_send_event( dialog
, event
, arg
);
854 return ERROR_SUCCESS
;
857 static UINT
msi_dialog_button_handler( msi_dialog
*dialog
,
858 msi_control
*control
, WPARAM param
)
860 static const WCHAR query
[] = {
861 'S','E','L','E','C','T',' ','*',' ',
862 'F','R','O','M',' ','C','o','n','t','r','o','l','E','v','e','n','t',' ',
863 'W','H','E','R','E',' ',
864 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',' ',
866 '`','C','o','n','t','r','o','l','_','`',' ','=',' ','\'','%','s','\'',' ',
867 'O','R','D','E','R',' ','B','Y',' ','`','O','r','d','e','r','i','n','g','`',0
869 MSIQUERY
*view
= NULL
;
872 if( HIWORD(param
) != BN_CLICKED
)
873 return ERROR_SUCCESS
;
875 r
= MSI_OpenQuery( dialog
->package
->db
, &view
, query
,
876 dialog
->name
, control
->name
);
877 if( r
!= ERROR_SUCCESS
)
879 ERR("query failed\n");
883 r
= MSI_IterateRecords( view
, 0, msi_dialog_control_event
, dialog
);
884 msiobj_release( &view
->hdr
);
889 static UINT
msi_dialog_get_checkbox_state( msi_dialog
*dialog
,
890 msi_control
*control
)
892 WCHAR state
[2] = { 0 };
895 MSI_GetPropertyW( dialog
->package
, control
->property
, state
, &sz
);
896 return atoiW( state
) ? 1 : 0;
899 static void msi_dialog_set_checkbox_state( msi_dialog
*dialog
,
900 msi_control
*control
, UINT state
)
902 WCHAR szState
[2] = { '0', 0 };
906 MSI_SetPropertyW( dialog
->package
, control
->property
, szState
);
909 static void msi_dialog_checkbox_sync_state( msi_dialog
*dialog
,
910 msi_control
*control
)
914 state
= msi_dialog_get_checkbox_state( dialog
, control
);
915 SendMessageW( control
->hwnd
, BM_SETCHECK
,
916 state
? BST_CHECKED
: BST_UNCHECKED
, 0 );
919 static UINT
msi_dialog_checkbox_handler( msi_dialog
*dialog
,
920 msi_control
*control
, WPARAM param
)
924 if( HIWORD(param
) != BN_CLICKED
)
925 return ERROR_SUCCESS
;
927 TRACE("clicked checkbox %s, set %s\n", debugstr_w(control
->name
),
928 debugstr_w(control
->property
));
930 state
= msi_dialog_get_checkbox_state( dialog
, control
);
931 state
= state
? 0 : 1;
932 msi_dialog_set_checkbox_state( dialog
, control
, state
);
933 msi_dialog_checkbox_sync_state( dialog
, control
);
935 return msi_dialog_button_handler( dialog
, control
, param
);
938 static UINT
msi_dialog_edit_handler( msi_dialog
*dialog
,
939 msi_control
*control
, WPARAM param
)
944 if( HIWORD(param
) != EN_CHANGE
)
945 return ERROR_SUCCESS
;
947 TRACE("edit %s contents changed, set %s\n", debugstr_w(control
->name
),
948 debugstr_w(control
->property
));
951 buf
= HeapAlloc( GetProcessHeap(), 0, sz
*sizeof(WCHAR
) );
954 r
= GetWindowTextW( control
->hwnd
, buf
, sz
);
958 buf
= HeapReAlloc( GetProcessHeap(), 0, buf
, sz
*sizeof(WCHAR
) );
961 MSI_SetPropertyW( dialog
->package
, control
->property
, buf
);
963 HeapFree( GetProcessHeap(), 0, buf
);
965 return ERROR_SUCCESS
;
968 static UINT
msi_dialog_radiogroup_handler( msi_dialog
*dialog
,
969 msi_control
*control
, WPARAM param
)
971 if( HIWORD(param
) != BN_CLICKED
)
972 return ERROR_SUCCESS
;
974 TRACE("clicked radio button %s, set %s\n", debugstr_w(control
->name
),
975 debugstr_w(control
->property
));
977 MSI_SetPropertyW( dialog
->package
, control
->property
, control
->name
);
979 return msi_dialog_button_handler( dialog
, control
, param
);
982 static LRESULT
msi_dialog_oncommand( msi_dialog
*dialog
, WPARAM param
, HWND hwnd
)
984 msi_control
*control
;
986 TRACE("%p %p %08x\n", dialog
, hwnd
, param
);
988 control
= msi_dialog_find_control_by_hwnd( dialog
, hwnd
);
991 if( control
->handler
)
993 control
->handler( dialog
, control
, param
);
994 msi_dialog_evaluate_control_conditions( dialog
);
998 ERR("button click from nowhere\n");
1002 static LRESULT WINAPI
MSIDialog_WndProc( HWND hwnd
, UINT msg
,
1003 WPARAM wParam
, LPARAM lParam
)
1005 msi_dialog
*dialog
= (LPVOID
) GetWindowLongPtrW( hwnd
, GWLP_USERDATA
);
1007 TRACE(" 0x%04x\n", msg
);
1011 return msi_dialog_oncreate( hwnd
, (LPCREATESTRUCTW
)lParam
);
1014 return msi_dialog_oncommand( dialog
, wParam
, (HWND
)lParam
);
1017 dialog
->hwnd
= NULL
;
1020 return DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
1023 /* functions that interface to other modules within MSI */
1025 msi_dialog
*msi_dialog_create( MSIPACKAGE
* package
, LPCWSTR szDialogName
,
1026 msi_dialog_event_handler event_handler
)
1031 TRACE("%p %s\n", package
, debugstr_w(szDialogName
));
1033 /* allocate the structure for the dialog to use */
1034 dialog
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
,
1035 sizeof *dialog
+ sizeof(WCHAR
)*strlenW(szDialogName
) );
1038 strcpyW( dialog
->name
, szDialogName
);
1039 dialog
->package
= package
;
1040 dialog
->event_handler
= event_handler
;
1042 /* create the dialog window, don't show it yet */
1043 hwnd
= CreateWindowW( szMsiDialogClass
, szDialogName
, WS_OVERLAPPEDWINDOW
,
1044 CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
,
1045 NULL
, NULL
, NULL
, dialog
);
1048 ERR("Failed to create dialog %s\n", debugstr_w( szDialogName
));
1049 msi_dialog_destroy( dialog
);
1056 void msi_dialog_end_dialog( msi_dialog
*dialog
)
1058 dialog
->finished
= 1;
1061 UINT
msi_dialog_run_message_loop( msi_dialog
*dialog
)
1065 if( dialog
->attributes
& msidbDialogAttributesVisible
)
1067 ShowWindow( dialog
->hwnd
, SW_SHOW
);
1068 UpdateWindow( dialog
->hwnd
);
1071 if( dialog
->attributes
& msidbDialogAttributesModal
)
1073 while( !dialog
->finished
&& GetMessageW( &msg
, 0, 0, 0 ) )
1075 TranslateMessage( &msg
);
1076 DispatchMessageW( &msg
);
1080 return ERROR_IO_PENDING
;
1082 return ERROR_SUCCESS
;
1085 void msi_dialog_check_messages( msi_dialog
*dialog
, HANDLE handle
)
1092 while( PeekMessageW( &msg
, 0, 0, 0, PM_REMOVE
) )
1094 TranslateMessage( &msg
);
1095 DispatchMessageW( &msg
);
1099 r
= MsgWaitForMultipleObjects( 1, &handle
, 0, INFINITE
, QS_ALLEVENTS
);
1101 while( WAIT_OBJECT_0
!= r
);
1104 void msi_dialog_do_preview( msi_dialog
*dialog
)
1106 dialog
->attributes
|= msidbDialogAttributesVisible
;
1107 dialog
->attributes
&= ~msidbDialogAttributesModal
;
1108 msi_dialog_run_message_loop( dialog
);
1111 void msi_dialog_destroy( msi_dialog
*dialog
)
1114 ShowWindow( dialog
->hwnd
, SW_HIDE
);
1116 /* destroy the list of controls */
1117 while( dialog
->control_list
)
1119 msi_control
*t
= dialog
->control_list
;
1120 dialog
->control_list
= t
->next
;
1121 /* leave dialog->hwnd - destroying parent destroys child windows */
1122 HeapFree( GetProcessHeap(), 0, t
->property
);
1124 IPicture_Release( t
->pic
);
1125 HeapFree( GetProcessHeap(), 0, t
);
1128 /* destroy the list of fonts */
1129 while( dialog
->font_list
)
1131 msi_font
*t
= dialog
->font_list
;
1132 dialog
->font_list
= t
->next
;
1133 DeleteObject( t
->hfont
);
1134 HeapFree( GetProcessHeap(), 0, t
);
1136 HeapFree( GetProcessHeap(), 0, dialog
->default_font
);
1139 DestroyWindow( dialog
->hwnd
);
1141 dialog
->package
= NULL
;
1142 HeapFree( GetProcessHeap(), 0, dialog
);
1145 void msi_dialog_register_class( void )
1149 ZeroMemory( &cls
, sizeof cls
);
1150 cls
.lpfnWndProc
= MSIDialog_WndProc
;
1151 cls
.hInstance
= NULL
;
1152 cls
.hIcon
= LoadIconW(0, (LPWSTR
)IDI_APPLICATION
);
1153 cls
.hCursor
= LoadCursorW(0, (LPWSTR
)IDC_ARROW
);
1154 cls
.hbrBackground
= (HBRUSH
)(COLOR_WINDOW
);
1155 cls
.lpszMenuName
= NULL
;
1156 cls
.lpszClassName
= szMsiDialogClass
;
1158 RegisterClassW( &cls
);
1161 void msi_dialog_unregister_class( void )
1163 UnregisterClassW( szMsiDialogClass
, NULL
);
1166 static LRESULT WINAPI
MSIRadioGroup_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1168 WNDPROC oldproc
= (WNDPROC
) GetPropW(hWnd
, szButtonData
);
1170 TRACE("hWnd %p msg %04x wParam 0x%08x lParam 0x%08lx\n", hWnd
, msg
, wParam
, lParam
);
1172 if (msg
== WM_COMMAND
) /* Forward notifications to dialog */
1173 SendMessageW(GetParent(hWnd
), msg
, wParam
, lParam
);
1175 return CallWindowProcW(oldproc
, hWnd
, msg
, wParam
, lParam
);