msi: Subclass the Richedit control.
[wine/gsoc_dplay.git] / dlls / msi / dialog.c
blobd7b3fdd68080af4f900f8a9e19e085ca1fa75c9d
1 /*
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
21 #define COBJMACROS
22 #define NONAMELESSUNION
23 #define NONAMELESSSTRUCT
25 #include <stdarg.h>
27 #include "windef.h"
28 #include "winbase.h"
29 #include "winuser.h"
30 #include "winnls.h"
31 #include "wingdi.h"
32 #include "msi.h"
33 #include "msipriv.h"
34 #include "msidefs.h"
35 #include "ocidl.h"
36 #include "olectl.h"
37 #include "richedit.h"
38 #include "commctrl.h"
40 #include "wine/debug.h"
41 #include "wine/unicode.h"
43 #include "action.h"
45 WINE_DEFAULT_DEBUG_CHANNEL(msi);
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 list entry;
55 HWND hwnd;
56 msi_handler handler;
57 LPWSTR property;
58 LPWSTR value;
59 HBITMAP hBitmap;
60 HICON hIcon;
61 LPWSTR tabnext;
62 WCHAR name[1];
65 typedef struct msi_font_tag
67 struct msi_font_tag *next;
68 HFONT hfont;
69 WCHAR name[1];
70 } msi_font;
72 struct msi_dialog_tag
74 MSIPACKAGE *package;
75 msi_dialog_event_handler event_handler;
76 BOOL finished;
77 INT scale;
78 DWORD attributes;
79 HWND hwnd;
80 LPWSTR default_font;
81 msi_font *font_list;
82 struct list controls;
83 HWND hWndFocus;
84 LPWSTR control_default;
85 LPWSTR control_cancel;
86 WCHAR name[1];
89 typedef UINT (*msi_dialog_control_func)( msi_dialog *dialog, MSIRECORD *rec );
90 struct control_handler
92 LPCWSTR control_type;
93 msi_dialog_control_func func;
96 typedef struct
98 msi_dialog* dialog;
99 msi_control *parent;
100 DWORD attributes;
101 } radio_button_group_descr;
103 const WCHAR szMsiDialogClass[] = {
104 'M','s','i','D','i','a','l','o','g','C','l','o','s','e','C','l','a','s','s',0
106 const WCHAR szMsiHiddenWindow[] = {
107 'M','s','i','H','i','d','d','e','n','W','i','n','d','o','w',0 };
108 static const WCHAR szStatic[] = { 'S','t','a','t','i','c',0 };
109 static const WCHAR szButton[] = { 'B','U','T','T','O','N', 0 };
110 static const WCHAR szButtonData[] = { 'M','S','I','D','A','T','A',0 };
111 static const WCHAR szText[] = { 'T','e','x','t',0 };
112 static const WCHAR szPushButton[] = { 'P','u','s','h','B','u','t','t','o','n',0 };
113 static const WCHAR szLine[] = { 'L','i','n','e',0 };
114 static const WCHAR szBitmap[] = { 'B','i','t','m','a','p',0 };
115 static const WCHAR szCheckBox[] = { 'C','h','e','c','k','B','o','x',0 };
116 static const WCHAR szScrollableText[] = {
117 'S','c','r','o','l','l','a','b','l','e','T','e','x','t',0 };
118 static const WCHAR szComboBox[] = { 'C','o','m','b','o','B','o','x',0 };
119 static const WCHAR szEdit[] = { 'E','d','i','t',0 };
120 static const WCHAR szMaskedEdit[] = { 'M','a','s','k','e','d','E','d','i','t',0 };
121 static const WCHAR szPathEdit[] = { 'P','a','t','h','E','d','i','t',0 };
122 static const WCHAR szProgressBar[] = {
123 'P','r','o','g','r','e','s','s','B','a','r',0 };
124 static const WCHAR szRadioButtonGroup[] = {
125 'R','a','d','i','o','B','u','t','t','o','n','G','r','o','u','p',0 };
126 static const WCHAR szIcon[] = { 'I','c','o','n',0 };
127 static const WCHAR szSelectionTree[] = {
128 'S','e','l','e','c','t','i','o','n','T','r','e','e',0 };
130 static UINT msi_dialog_checkbox_handler( msi_dialog *, msi_control *, WPARAM );
131 static void msi_dialog_checkbox_sync_state( msi_dialog *, msi_control * );
132 static UINT msi_dialog_button_handler( msi_dialog *, msi_control *, WPARAM );
133 static UINT msi_dialog_edit_handler( msi_dialog *, msi_control *, WPARAM );
134 static UINT msi_dialog_radiogroup_handler( msi_dialog *, msi_control *, WPARAM param );
135 static UINT msi_dialog_evaluate_control_conditions( msi_dialog *dialog );
136 static LRESULT WINAPI MSIRadioGroup_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
139 /* dialog sequencing */
141 #define WM_MSI_DIALOG_CREATE (WM_USER+0x100)
142 #define WM_MSI_DIALOG_DESTROY (WM_USER+0x101)
144 static DWORD uiThreadId;
145 static HWND hMsiHiddenWindow;
147 static INT msi_dialog_scale_unit( msi_dialog *dialog, INT val )
149 return (dialog->scale * val + 5) / 10;
152 static msi_control *msi_dialog_find_control( msi_dialog *dialog, LPCWSTR name )
154 msi_control *control;
156 if( !name )
157 return NULL;
158 LIST_FOR_EACH_ENTRY( control, &dialog->controls, msi_control, entry )
159 if( !strcmpW( control->name, name ) ) /* FIXME: case sensitive? */
160 return control;
161 return NULL;
164 static msi_control *msi_dialog_find_control_by_hwnd( msi_dialog *dialog, HWND hwnd )
166 msi_control *control;
168 LIST_FOR_EACH_ENTRY( control, &dialog->controls, msi_control, entry )
169 if( hwnd == control->hwnd )
170 return control;
171 return NULL;
174 static LPWSTR msi_get_deformatted_field( MSIPACKAGE *package, MSIRECORD *rec, int field )
176 LPCWSTR str = MSI_RecordGetString( rec, field );
177 LPWSTR ret = NULL;
179 if (str)
180 deformat_string( package, str, &ret );
181 return ret;
185 * msi_dialog_get_style
187 * Extract the {\style} string from the front of the text to display and
188 * update the pointer.
190 static LPWSTR msi_dialog_get_style( LPCWSTR p, LPCWSTR *rest )
192 LPWSTR ret = NULL;
193 LPCWSTR q, i;
194 DWORD len;
196 *rest = p;
197 if( !p )
198 return ret;
199 if( *p++ != '{' )
200 return ret;
201 q = strchrW( p, '}' );
202 if( !q )
203 return ret;
204 if( *p == '\\' || *p == '&' )
205 p++;
207 /* little bit of sanity checking to stop us getting confused with RTF */
208 for( i=p; i<q; i++ )
209 if( *i == '}' || *i == '\\' )
210 return ret;
212 *rest = ++q;
213 len = q - p;
215 ret = msi_alloc( len*sizeof(WCHAR) );
216 if( !ret )
217 return ret;
218 memcpy( ret, p, len*sizeof(WCHAR) );
219 ret[len-1] = 0;
220 return ret;
223 static UINT msi_dialog_add_font( MSIRECORD *rec, LPVOID param )
225 msi_dialog *dialog = param;
226 msi_font *font;
227 LPCWSTR face, name;
228 LOGFONTW lf;
229 INT style;
230 HDC hdc;
232 /* create a font and add it to the list */
233 name = MSI_RecordGetString( rec, 1 );
234 font = msi_alloc( sizeof *font + strlenW( name )*sizeof (WCHAR) );
235 strcpyW( font->name, name );
236 font->next = dialog->font_list;
237 dialog->font_list = font;
239 memset( &lf, 0, sizeof lf );
240 face = MSI_RecordGetString( rec, 2 );
241 lf.lfHeight = MSI_RecordGetInteger( rec, 3 );
242 style = MSI_RecordGetInteger( rec, 5 );
243 if( style & msidbTextStyleStyleBitsBold )
244 lf.lfWeight = FW_BOLD;
245 if( style & msidbTextStyleStyleBitsItalic )
246 lf.lfItalic = TRUE;
247 if( style & msidbTextStyleStyleBitsUnderline )
248 lf.lfUnderline = TRUE;
249 if( style & msidbTextStyleStyleBitsStrike )
250 lf.lfStrikeOut = TRUE;
251 lstrcpynW( lf.lfFaceName, face, LF_FACESIZE );
253 /* adjust the height */
254 hdc = GetDC( dialog->hwnd );
255 if (hdc)
257 lf.lfHeight = -MulDiv(lf.lfHeight, GetDeviceCaps(hdc, LOGPIXELSY), 72);
258 ReleaseDC( dialog->hwnd, hdc );
261 font->hfont = CreateFontIndirectW( &lf );
263 TRACE("Adding font style %s\n", debugstr_w(font->name) );
265 return ERROR_SUCCESS;
268 static msi_font *msi_dialog_find_font( msi_dialog *dialog, LPCWSTR name )
270 msi_font *font;
272 for( font = dialog->font_list; font; font = font->next )
273 if( !strcmpW( font->name, name ) ) /* FIXME: case sensitive? */
274 break;
276 return font;
279 static UINT msi_dialog_set_font( msi_dialog *dialog, HWND hwnd, LPCWSTR name )
281 msi_font *font;
283 font = msi_dialog_find_font( dialog, name );
284 if( font )
285 SendMessageW( hwnd, WM_SETFONT, (WPARAM) font->hfont, TRUE );
286 else
287 ERR("No font entry for %s\n", debugstr_w(name));
288 return ERROR_SUCCESS;
291 static UINT msi_dialog_build_font_list( msi_dialog *dialog )
293 static const WCHAR query[] = {
294 'S','E','L','E','C','T',' ','*',' ',
295 'F','R','O','M',' ','`','T','e','x','t','S','t','y','l','e','`',' ',0
297 UINT r;
298 MSIQUERY *view = NULL;
300 TRACE("dialog %p\n", dialog );
302 r = MSI_OpenQuery( dialog->package->db, &view, query );
303 if( r != ERROR_SUCCESS )
304 return r;
306 r = MSI_IterateRecords( view, NULL, msi_dialog_add_font, dialog );
307 msiobj_release( &view->hdr );
309 return r;
312 static msi_control *msi_dialog_create_window( msi_dialog *dialog,
313 MSIRECORD *rec, LPCWSTR szCls, LPCWSTR name, LPCWSTR text,
314 DWORD style, HWND parent )
316 DWORD x, y, width, height;
317 LPWSTR font = NULL, title_font = NULL;
318 LPCWSTR title = NULL;
319 msi_control *control;
321 style |= WS_CHILD;
323 control = msi_alloc( sizeof *control + strlenW(name)*sizeof(WCHAR) );
324 strcpyW( control->name, name );
325 list_add_head( &dialog->controls, &control->entry );
326 control->handler = NULL;
327 control->property = NULL;
328 control->value = NULL;
329 control->hBitmap = NULL;
330 control->hIcon = NULL;
331 control->tabnext = strdupW( MSI_RecordGetString( rec, 11) );
333 x = MSI_RecordGetInteger( rec, 4 );
334 y = MSI_RecordGetInteger( rec, 5 );
335 width = MSI_RecordGetInteger( rec, 6 );
336 height = MSI_RecordGetInteger( rec, 7 );
338 x = msi_dialog_scale_unit( dialog, x );
339 y = msi_dialog_scale_unit( dialog, y );
340 width = msi_dialog_scale_unit( dialog, width );
341 height = msi_dialog_scale_unit( dialog, height );
343 if( text )
345 deformat_string( dialog->package, text, &title_font );
346 font = msi_dialog_get_style( title_font, &title );
349 control->hwnd = CreateWindowW( szCls, title, style,
350 x, y, width, height, parent, NULL, NULL, NULL );
352 TRACE("Dialog %s control %s hwnd %p\n",
353 debugstr_w(dialog->name), debugstr_w(text), control->hwnd );
355 msi_dialog_set_font( dialog, control->hwnd,
356 font ? font : dialog->default_font );
358 msi_free( title_font );
359 msi_free( font );
361 return control;
364 static MSIRECORD *msi_get_binary_record( MSIDATABASE *db, LPCWSTR name )
366 static const WCHAR query[] = {
367 's','e','l','e','c','t',' ','*',' ',
368 'f','r','o','m',' ','B','i','n','a','r','y',' ',
369 'w','h','e','r','e',' ',
370 '`','N','a','m','e','`',' ','=',' ','\'','%','s','\'',0
373 return MSI_QueryGetRecord( db, query, name );
376 static LPWSTR msi_create_tmp_path(void)
378 WCHAR tmp[MAX_PATH];
379 LPWSTR path = NULL;
380 static const WCHAR prefix[] = { 'm','s','i',0 };
381 DWORD len, r;
383 r = GetTempPathW( MAX_PATH, tmp );
384 if( !r )
385 return path;
386 len = lstrlenW( tmp ) + 20;
387 path = msi_alloc( len * sizeof (WCHAR) );
388 if( path )
390 r = GetTempFileNameW( tmp, prefix, 0, path );
391 if (!r)
393 msi_free( path );
394 path = NULL;
397 return path;
401 static HANDLE msi_load_image( MSIDATABASE *db, LPCWSTR name, UINT type,
402 UINT cx, UINT cy, UINT flags )
404 MSIRECORD *rec = NULL;
405 HANDLE himage = NULL;
406 LPWSTR tmp;
407 UINT r;
409 TRACE("%p %s %u %u %08x\n", db, debugstr_w(name), cx, cy, flags);
411 tmp = msi_create_tmp_path();
412 if( !tmp )
413 return himage;
415 rec = msi_get_binary_record( db, name );
416 if( rec )
418 r = MSI_RecordStreamToFile( rec, 2, tmp );
419 if( r == ERROR_SUCCESS )
421 himage = LoadImageW( 0, tmp, type, cx, cy, flags );
422 DeleteFileW( tmp );
424 msiobj_release( &rec->hdr );
427 msi_free( tmp );
428 return himage;
431 static HICON msi_load_icon( MSIDATABASE *db, LPCWSTR text, UINT attributes )
433 DWORD cx = 0, cy = 0, flags;
435 flags = LR_LOADFROMFILE | LR_DEFAULTSIZE;
436 if( attributes & msidbControlAttributesFixedSize )
438 flags &= ~LR_DEFAULTSIZE;
439 if( attributes & msidbControlAttributesIconSize16 )
441 cx += 16;
442 cy += 16;
444 if( attributes & msidbControlAttributesIconSize32 )
446 cx += 32;
447 cy += 32;
449 /* msidbControlAttributesIconSize48 handled by above logic */
451 return msi_load_image( db, text, IMAGE_ICON, cx, cy, flags );
455 /* called from the Control Event subscription code */
456 void msi_dialog_handle_event( msi_dialog* dialog, LPCWSTR control,
457 LPCWSTR attribute, MSIRECORD *rec )
459 msi_control* ctrl;
460 LPCWSTR text;
462 ctrl = msi_dialog_find_control( dialog, control );
463 if (!ctrl)
464 return;
465 if( lstrcmpW(attribute, szText) )
467 ERR("Attribute %s\n", debugstr_w(attribute));
468 return;
470 text = MSI_RecordGetString( rec , 1 );
471 SetWindowTextW( ctrl->hwnd, text );
472 msi_dialog_check_messages( NULL );
475 static void msi_dialog_map_events(msi_dialog* dialog, LPCWSTR control)
477 static WCHAR Query[] = {
478 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
479 '`','E','v','e','n','t','M','a','p','p','i','n','g','`',' ',
480 'W','H','E','R','E',' ',
481 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',' ',
482 'A','N','D',' ',
483 '`','C','o','n','t','r','o','l','_','`',' ','=',' ','\'','%','s','\'',0
485 MSIRECORD *row;
486 LPCWSTR event, attribute;
488 row = MSI_QueryGetRecord( dialog->package->db, Query, dialog->name, control );
489 if (!row)
490 return;
492 event = MSI_RecordGetString( row, 3 );
493 attribute = MSI_RecordGetString( row, 4 );
494 ControlEvent_SubscribeToEvent( dialog->package, event, control, attribute );
495 msiobj_release( &row->hdr );
498 /* everything except radio buttons */
499 static msi_control *msi_dialog_add_control( msi_dialog *dialog,
500 MSIRECORD *rec, LPCWSTR szCls, DWORD style )
502 DWORD attributes;
503 LPCWSTR text, name;
505 name = MSI_RecordGetString( rec, 2 );
506 attributes = MSI_RecordGetInteger( rec, 8 );
507 text = MSI_RecordGetString( rec, 10 );
508 if( attributes & msidbControlAttributesVisible )
509 style |= WS_VISIBLE;
510 if( ~attributes & msidbControlAttributesEnabled )
511 style |= WS_DISABLED;
513 msi_dialog_map_events(dialog, name);
515 return msi_dialog_create_window( dialog, rec, szCls, name, text,
516 style, dialog->hwnd );
519 struct msi_text_info
521 WNDPROC oldproc;
522 DWORD attributes;
526 * we don't erase our own background,
527 * so we have to make sure that the parent window redraws first
529 static void msi_text_on_settext( HWND hWnd )
531 HWND hParent;
532 RECT rc;
534 hParent = GetParent( hWnd );
535 GetWindowRect( hWnd, &rc );
536 MapWindowPoints( NULL, hParent, (LPPOINT) &rc, 2 );
537 InvalidateRect( hParent, &rc, TRUE );
540 static LRESULT WINAPI
541 MSIText_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
543 struct msi_text_info *info;
544 LRESULT r = 0;
546 TRACE("%p %04x %08x %08lx\n", hWnd, msg, wParam, lParam);
548 info = GetPropW(hWnd, szButtonData);
550 if( msg == WM_CTLCOLORSTATIC &&
551 ( info->attributes & msidbControlAttributesTransparent ) )
553 SetBkMode( (HDC)wParam, TRANSPARENT );
554 return (LRESULT) GetStockObject(NULL_BRUSH);
557 r = CallWindowProcW(info->oldproc, hWnd, msg, wParam, lParam);
559 switch( msg )
561 case WM_SETTEXT:
562 msi_text_on_settext( hWnd );
563 break;
564 case WM_NCDESTROY:
565 msi_free( info );
566 RemovePropW( hWnd, szButtonData );
567 break;
570 return r;
573 static UINT msi_dialog_text_control( msi_dialog *dialog, MSIRECORD *rec )
575 msi_control *control;
576 struct msi_text_info *info;
578 TRACE("%p %p\n", dialog, rec);
580 control = msi_dialog_add_control( dialog, rec, szStatic, SS_LEFT | WS_GROUP );
581 if( !control )
582 return ERROR_FUNCTION_FAILED;
584 info = msi_alloc( sizeof *info );
585 if( !info )
586 return ERROR_SUCCESS;
588 info->attributes = MSI_RecordGetInteger( rec, 8 );
589 if( info->attributes & msidbControlAttributesTransparent )
590 SetWindowLongPtrW( control->hwnd, GWL_EXSTYLE, WS_EX_TRANSPARENT );
592 info->oldproc = (WNDPROC) SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
593 (LONG_PTR)MSIText_WndProc );
594 SetPropW( control->hwnd, szButtonData, info );
596 return ERROR_SUCCESS;
599 static UINT msi_dialog_button_control( msi_dialog *dialog, MSIRECORD *rec )
601 msi_control *control;
602 UINT attributes, style;
603 LPWSTR text;
605 TRACE("%p %p\n", dialog, rec);
607 style = WS_TABSTOP;
608 attributes = MSI_RecordGetInteger( rec, 8 );
609 if( attributes & msidbControlAttributesIcon )
610 style |= BS_ICON;
612 control = msi_dialog_add_control( dialog, rec, szButton, style );
613 if( !control )
614 return ERROR_FUNCTION_FAILED;
616 control->handler = msi_dialog_button_handler;
618 /* set the icon */
619 text = msi_get_deformatted_field( dialog->package, rec, 10 );
620 control->hIcon = msi_load_icon( dialog->package->db, text, attributes );
621 if( attributes & msidbControlAttributesIcon )
622 SendMessageW( control->hwnd, BM_SETIMAGE, IMAGE_ICON, (LPARAM) control->hIcon );
623 msi_free( text );
625 return ERROR_SUCCESS;
628 static LPWSTR msi_get_checkbox_value( msi_dialog *dialog, LPCWSTR prop )
630 static const WCHAR query[] = {
631 'S','E','L','E','C','T',' ','*',' ',
632 'F','R','O','M',' ','`','C','h','e','c','k','B','o','x',' ','`',
633 'W','H','E','R','E',' ',
634 '`','P','r','o','p','e','r','t','y','`',' ','=',' ',
635 '\'','%','s','\'',0
637 MSIRECORD *rec = NULL;
638 LPWSTR ret = NULL;
640 /* find if there is a value associated with the checkbox */
641 rec = MSI_QueryGetRecord( dialog->package->db, query, prop );
642 if (!rec)
643 return ret;
645 ret = msi_get_deformatted_field( dialog->package, rec, 2 );
646 if( ret && !ret[0] )
648 msi_free( ret );
649 ret = NULL;
651 msiobj_release( &rec->hdr );
652 if (ret)
653 return ret;
655 ret = msi_dup_property( dialog->package, prop );
656 if( ret && !ret[0] )
658 msi_free( ret );
659 ret = NULL;
662 return ret;
665 static UINT msi_dialog_checkbox_control( msi_dialog *dialog, MSIRECORD *rec )
667 msi_control *control;
668 LPCWSTR prop;
670 TRACE("%p %p\n", dialog, rec);
672 control = msi_dialog_add_control( dialog, rec, szButton,
673 BS_CHECKBOX | BS_MULTILINE | WS_TABSTOP );
674 control->handler = msi_dialog_checkbox_handler;
675 prop = MSI_RecordGetString( rec, 9 );
676 if( prop )
678 control->property = strdupW( prop );
679 control->value = msi_get_checkbox_value( dialog, prop );
680 TRACE("control %s value %s\n", debugstr_w(control->property),
681 debugstr_w(control->value));
683 msi_dialog_checkbox_sync_state( dialog, control );
685 return ERROR_SUCCESS;
688 static UINT msi_dialog_line_control( msi_dialog *dialog, MSIRECORD *rec )
690 TRACE("%p %p\n", dialog, rec);
692 msi_dialog_add_control( dialog, rec, szStatic, SS_ETCHEDHORZ | SS_SUNKEN );
693 return ERROR_SUCCESS;
696 /******************** Scroll Text ********************************************/
698 struct msi_scrolltext_info
700 msi_dialog *dialog;
701 msi_control *control;
702 WNDPROC oldproc;
703 HMODULE hRichedit;
706 static LRESULT WINAPI
707 MSIScrollText_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
709 struct msi_scrolltext_info *info;
710 HRESULT r;
712 TRACE("%p %04x %08x %08lx\n", hWnd, msg, wParam, lParam);
714 info = GetPropW( hWnd, szButtonData );
716 r = CallWindowProcW( info->oldproc, hWnd, msg, wParam, lParam );
718 switch( msg )
720 case WM_NCDESTROY:
721 FreeLibrary( info->hRichedit );
722 msi_free( info );
723 RemovePropW( hWnd, szButtonData );
724 break;
725 case WM_VSCROLL:
726 msi_dialog_button_handler( info->dialog, info->control, BN_CLICKED );
727 break;
729 return r;
732 struct msi_streamin_info
734 LPSTR string;
735 DWORD offset;
736 DWORD length;
739 static DWORD CALLBACK
740 msi_richedit_stream_in( DWORD_PTR arg, LPBYTE buffer, LONG count, LONG *pcb )
742 struct msi_streamin_info *info = (struct msi_streamin_info*) arg;
744 if( (count + info->offset) > info->length )
745 count = info->length - info->offset;
746 memcpy( buffer, &info->string[ info->offset ], count );
747 *pcb = count;
748 info->offset += count;
750 TRACE("%ld/%ld\n", info->offset, info->length);
752 return 0;
755 static void msi_scrolltext_add_text( msi_control *control, LPCWSTR text )
757 struct msi_streamin_info info;
758 EDITSTREAM es;
760 info.string = strdupWtoA( text );
761 info.offset = 0;
762 info.length = lstrlenA( info.string ) + 1;
764 es.dwCookie = (DWORD_PTR) &info;
765 es.dwError = 0;
766 es.pfnCallback = msi_richedit_stream_in;
768 SendMessageW( control->hwnd, EM_STREAMIN, SF_RTF, (LPARAM) &es );
770 msi_free( info.string );
773 static UINT msi_dialog_scrolltext_control( msi_dialog *dialog, MSIRECORD *rec )
775 static const WCHAR szRichEdit20W[] = {
776 'R','i','c','h','E','d','i','t','2','0','W',0
778 struct msi_scrolltext_info *info;
779 msi_control *control;
780 DWORD style;
782 info = msi_alloc( sizeof *info );
783 if (!info)
784 return ERROR_FUNCTION_FAILED;
786 info->hRichedit = LoadLibraryA("riched20");
788 style = WS_BORDER | ES_MULTILINE | WS_VSCROLL |
789 ES_READONLY | ES_AUTOVSCROLL | WS_TABSTOP;
790 control = msi_dialog_add_control( dialog, rec, szRichEdit20W, style );
791 if (!control)
793 FreeLibrary( info->hRichedit );
794 msi_free( info );
795 return ERROR_FUNCTION_FAILED;
798 info->dialog = dialog;
799 info->control = control;
801 /* subclass the static control */
802 info->oldproc = (WNDPROC) SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
803 (LONG_PTR)MSIScrollText_WndProc );
804 SetPropW( control->hwnd, szButtonData, info );
806 /* add the text into the richedit */
807 msi_scrolltext_add_text( control, MSI_RecordGetString( rec, 10 ) );
809 return ERROR_SUCCESS;
812 static HBITMAP msi_load_picture( MSIDATABASE *db, LPCWSTR name,
813 INT cx, INT cy, DWORD flags )
815 HBITMAP hOleBitmap = 0, hBitmap = 0, hOldSrcBitmap, hOldDestBitmap;
816 MSIRECORD *rec = NULL;
817 IStream *stm = NULL;
818 IPicture *pic = NULL;
819 HDC srcdc, destdc;
820 BITMAP bm;
821 UINT r;
823 rec = msi_get_binary_record( db, name );
824 if( !rec )
825 goto end;
827 r = MSI_RecordGetIStream( rec, 2, &stm );
828 msiobj_release( &rec->hdr );
829 if( r != ERROR_SUCCESS )
830 goto end;
832 r = OleLoadPicture( stm, 0, TRUE, &IID_IPicture, (LPVOID*) &pic );
833 IStream_Release( stm );
834 if( FAILED( r ) )
836 ERR("failed to load picture\n");
837 goto end;
840 r = IPicture_get_Handle( pic, (OLE_HANDLE*) &hOleBitmap );
841 if( FAILED( r ) )
843 ERR("failed to get bitmap handle\n");
844 goto end;
847 /* make the bitmap the desired size */
848 r = GetObjectW( hOleBitmap, sizeof bm, &bm );
849 if (r != sizeof bm )
851 ERR("failed to get bitmap size\n");
852 goto end;
855 if (flags & LR_DEFAULTSIZE)
857 cx = bm.bmWidth;
858 cy = bm.bmHeight;
861 srcdc = CreateCompatibleDC( NULL );
862 hOldSrcBitmap = SelectObject( srcdc, hOleBitmap );
863 destdc = CreateCompatibleDC( NULL );
864 hBitmap = CreateCompatibleBitmap( srcdc, cx, cy );
865 hOldDestBitmap = SelectObject( destdc, hBitmap );
866 StretchBlt( destdc, 0, 0, cx, cy,
867 srcdc, 0, 0, bm.bmWidth, bm.bmHeight, SRCCOPY);
868 SelectObject( srcdc, hOldSrcBitmap );
869 SelectObject( destdc, hOldDestBitmap );
870 DeleteDC( srcdc );
871 DeleteDC( destdc );
873 end:
874 if ( pic )
875 IPicture_Release( pic );
876 return hBitmap;
879 static UINT msi_dialog_bitmap_control( msi_dialog *dialog, MSIRECORD *rec )
881 UINT cx, cy, flags, style, attributes;
882 msi_control *control;
883 LPWSTR text;
885 flags = LR_LOADFROMFILE;
886 style = SS_BITMAP | SS_LEFT | WS_GROUP;
888 attributes = MSI_RecordGetInteger( rec, 8 );
889 if( attributes & msidbControlAttributesFixedSize )
891 flags |= LR_DEFAULTSIZE;
892 style |= SS_CENTERIMAGE;
895 control = msi_dialog_add_control( dialog, rec, szStatic, style );
896 cx = MSI_RecordGetInteger( rec, 6 );
897 cy = MSI_RecordGetInteger( rec, 7 );
898 cx = msi_dialog_scale_unit( dialog, cx );
899 cy = msi_dialog_scale_unit( dialog, cy );
901 text = msi_get_deformatted_field( dialog->package, rec, 10 );
902 control->hBitmap = msi_load_picture( dialog->package->db, text, cx, cy, flags );
903 if( control->hBitmap )
904 SendMessageW( control->hwnd, STM_SETIMAGE,
905 IMAGE_BITMAP, (LPARAM) control->hBitmap );
906 else
907 ERR("Failed to load bitmap %s\n", debugstr_w(text));
909 msi_free( text );
911 return ERROR_SUCCESS;
914 static UINT msi_dialog_icon_control( msi_dialog *dialog, MSIRECORD *rec )
916 msi_control *control;
917 DWORD attributes;
918 LPWSTR text;
920 TRACE("\n");
922 control = msi_dialog_add_control( dialog, rec, szStatic,
923 SS_ICON | SS_CENTERIMAGE | WS_GROUP );
925 attributes = MSI_RecordGetInteger( rec, 8 );
926 text = msi_get_deformatted_field( dialog->package, rec, 10 );
927 control->hIcon = msi_load_icon( dialog->package->db, text, attributes );
928 if( control->hIcon )
929 SendMessageW( control->hwnd, STM_SETICON, (WPARAM) control->hIcon, 0 );
930 else
931 ERR("Failed to load bitmap %s\n", debugstr_w(text));
932 msi_free( text );
933 return ERROR_SUCCESS;
936 static UINT msi_dialog_combo_control( msi_dialog *dialog, MSIRECORD *rec )
938 static const WCHAR szCombo[] = { 'C','O','M','B','O','B','O','X',0 };
940 msi_dialog_add_control( dialog, rec, szCombo,
941 SS_BITMAP | SS_LEFT | SS_CENTERIMAGE );
942 return ERROR_SUCCESS;
945 static UINT msi_dialog_edit_control( msi_dialog *dialog, MSIRECORD *rec )
947 msi_control *control;
948 LPCWSTR prop;
949 LPWSTR val;
951 control = msi_dialog_add_control( dialog, rec, szEdit,
952 WS_BORDER | WS_TABSTOP );
953 control->handler = msi_dialog_edit_handler;
954 prop = MSI_RecordGetString( rec, 9 );
955 if( prop )
956 control->property = strdupW( prop );
957 val = msi_dup_property( dialog->package, control->property );
958 SetWindowTextW( control->hwnd, val );
959 msi_free( val );
960 return ERROR_SUCCESS;
963 /******************** Masked Edit ********************************************/
965 #define MASK_MAX_GROUPS 10
967 struct msi_mask_group
969 UINT len;
970 UINT ofs;
971 WCHAR type;
972 HWND hwnd;
975 struct msi_maskedit_info
977 msi_dialog *dialog;
978 WNDPROC oldproc;
979 HWND hwnd;
980 LPWSTR prop;
981 UINT num_chars;
982 UINT num_groups;
983 struct msi_mask_group group[MASK_MAX_GROUPS];
986 static BOOL msi_mask_editable( WCHAR type )
988 switch (type)
990 case '%':
991 case '#':
992 case '&':
993 case '`':
994 case '?':
995 case '^':
996 return TRUE;
998 return FALSE;
1001 static void msi_mask_control_change( struct msi_maskedit_info *info )
1003 LPWSTR val;
1004 UINT i, n, r;
1006 val = msi_alloc( (info->num_chars+1)*sizeof(WCHAR) );
1007 for( i=0, n=0; i<info->num_groups; i++ )
1009 if( (info->group[i].len + n) > info->num_chars )
1011 ERR("can't fit control %d text into template\n",i);
1012 break;
1014 if (!msi_mask_editable(info->group[i].type))
1016 for(r=0; r<info->group[i].len; r++)
1017 val[n+r] = info->group[i].type;
1018 val[n+r] = 0;
1020 else
1022 r = GetWindowTextW( info->group[i].hwnd, &val[n], info->group[i].len+1 );
1023 if( r != info->group[i].len )
1024 break;
1026 n += r;
1029 TRACE("%d/%d controls were good\n", i, info->num_groups);
1031 if( i == info->num_groups )
1033 TRACE("Set property %s to %s\n",
1034 debugstr_w(info->prop), debugstr_w(val) );
1035 CharUpperBuffW( val, info->num_chars );
1036 MSI_SetPropertyW( info->dialog->package, info->prop, val );
1037 msi_dialog_evaluate_control_conditions( info->dialog );
1039 msi_free( val );
1042 /* now move to the next control if necessary */
1043 static VOID msi_mask_next_control( struct msi_maskedit_info *info, HWND hWnd )
1045 HWND hWndNext;
1046 UINT len, i;
1048 for( i=0; i<info->num_groups; i++ )
1049 if( info->group[i].hwnd == hWnd )
1050 break;
1052 /* don't move from the last control */
1053 if( i >= (info->num_groups-1) )
1054 return;
1056 len = SendMessageW( hWnd, WM_GETTEXTLENGTH, 0, 0 );
1057 if( len < info->group[i].len )
1058 return;
1060 hWndNext = GetNextDlgTabItem( GetParent( hWnd ), hWnd, FALSE );
1061 SetFocus( hWndNext );
1064 static LRESULT WINAPI
1065 MSIMaskedEdit_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
1067 struct msi_maskedit_info *info;
1068 HRESULT r;
1070 TRACE("%p %04x %08x %08lx\n", hWnd, msg, wParam, lParam);
1072 info = GetPropW(hWnd, szButtonData);
1074 r = CallWindowProcW(info->oldproc, hWnd, msg, wParam, lParam);
1076 switch( msg )
1078 case WM_COMMAND:
1079 if (HIWORD(wParam) == EN_CHANGE)
1081 msi_mask_control_change( info );
1082 msi_mask_next_control( info, (HWND) lParam );
1084 break;
1085 case WM_NCDESTROY:
1086 msi_free( info->prop );
1087 msi_free( info );
1088 RemovePropW( hWnd, szButtonData );
1089 break;
1092 return r;
1095 /* fish the various bits of the property out and put them in the control */
1096 static void
1097 msi_maskedit_set_text( struct msi_maskedit_info *info, LPCWSTR text )
1099 LPCWSTR p;
1100 UINT i;
1102 p = text;
1103 for( i = 0; i < info->num_groups; i++ )
1105 if( info->group[i].len < lstrlenW( p ) )
1107 LPWSTR chunk = strdupW( p );
1108 chunk[ info->group[i].len ] = 0;
1109 SetWindowTextW( info->group[i].hwnd, chunk );
1110 msi_free( chunk );
1112 else
1114 SetWindowTextW( info->group[i].hwnd, p );
1115 break;
1117 p += info->group[i].len;
1121 static struct msi_maskedit_info * msi_dialog_parse_groups( LPCWSTR mask )
1123 struct msi_maskedit_info * info = NULL;
1124 int i = 0, n = 0, total = 0;
1125 LPCWSTR p;
1127 TRACE("masked control, template %s\n", debugstr_w(mask));
1129 if( !mask )
1130 return info;
1132 p = strchrW(mask, '<');
1133 if( !p )
1134 return info;
1136 info = msi_alloc_zero( sizeof *info );
1137 if( !info )
1138 return info;
1140 p++;
1141 for( i=0; i<MASK_MAX_GROUPS; i++ )
1143 /* stop at the end of the string */
1144 if( p[0] == 0 || p[0] == '>' )
1145 break;
1147 /* count the number of the same identifier */
1148 for( n=0; p[n] == p[0]; n++ )
1150 info->group[i].ofs = total;
1151 info->group[i].type = p[0];
1152 if( p[n] == '=' )
1154 n++;
1155 total++; /* an extra not part of the group */
1157 info->group[i].len = n;
1158 total += n;
1159 p += n;
1162 TRACE("%d characters in %d groups\n", total, i );
1163 if( i == MASK_MAX_GROUPS )
1164 ERR("too many groups in PIDTemplate %s\n", debugstr_w(mask));
1166 info->num_chars = total;
1167 info->num_groups = i;
1169 return info;
1172 static void
1173 msi_maskedit_create_children( struct msi_maskedit_info *info, LPCWSTR font )
1175 DWORD width, height, style, wx, ww;
1176 RECT rect;
1177 HWND hwnd;
1178 UINT i;
1180 style = WS_CHILD | WS_BORDER | WS_VISIBLE | WS_TABSTOP;
1182 GetClientRect( info->hwnd, &rect );
1184 width = rect.right - rect.left;
1185 height = rect.bottom - rect.top;
1187 for( i = 0; i < info->num_groups; i++ )
1189 if (!msi_mask_editable( info->group[i].type ))
1190 continue;
1191 wx = (info->group[i].ofs * width) / info->num_chars;
1192 ww = (info->group[i].len * width) / info->num_chars;
1194 hwnd = CreateWindowW( szEdit, NULL, style, wx, 0, ww, height,
1195 info->hwnd, NULL, NULL, NULL );
1196 if( !hwnd )
1198 ERR("failed to create mask edit sub window\n");
1199 break;
1202 SendMessageW( hwnd, EM_LIMITTEXT, info->group[i].len, 0 );
1204 msi_dialog_set_font( info->dialog, hwnd,
1205 font?font:info->dialog->default_font );
1206 info->group[i].hwnd = hwnd;
1211 * office 2003 uses "73931<````=````=````=````=`````>@@@@@"
1212 * delphi 7 uses "<????-??????-??????-????>" and "<???-???>"
1213 * filemaker pro 7 uses "<^^^^=^^^^=^^^^=^^^^=^^^^=^^^^=^^^^^>"
1215 static UINT msi_dialog_maskedit_control( msi_dialog *dialog, MSIRECORD *rec )
1217 LPWSTR font_mask, val = NULL, font;
1218 struct msi_maskedit_info *info = NULL;
1219 UINT ret = ERROR_SUCCESS;
1220 msi_control *control;
1221 LPCWSTR prop, mask;
1223 TRACE("\n");
1225 font_mask = msi_get_deformatted_field( dialog->package, rec, 10 );
1226 font = msi_dialog_get_style( font_mask, &mask );
1227 if( !mask )
1229 ERR("mask template is empty\n");
1230 goto end;
1233 info = msi_dialog_parse_groups( mask );
1234 if( !info )
1236 ERR("template %s is invalid\n", debugstr_w(mask));
1237 goto end;
1240 info->dialog = dialog;
1242 control = msi_dialog_add_control( dialog, rec, szStatic,
1243 SS_OWNERDRAW | WS_GROUP | WS_VISIBLE );
1244 if( !control )
1246 ERR("Failed to create maskedit container\n");
1247 ret = ERROR_FUNCTION_FAILED;
1248 goto end;
1250 SetWindowLongPtrW( control->hwnd, GWL_EXSTYLE, WS_EX_CONTROLPARENT );
1252 info->hwnd = control->hwnd;
1254 /* subclass the static control */
1255 info->oldproc = (WNDPROC) SetWindowLongPtrW( info->hwnd, GWLP_WNDPROC,
1256 (LONG_PTR)MSIMaskedEdit_WndProc );
1257 SetPropW( control->hwnd, szButtonData, info );
1259 prop = MSI_RecordGetString( rec, 9 );
1260 if( prop )
1261 info->prop = strdupW( prop );
1263 msi_maskedit_create_children( info, font );
1265 if( prop )
1267 val = msi_dup_property( dialog->package, prop );
1268 if( val )
1270 msi_maskedit_set_text( info, val );
1271 msi_free( val );
1275 end:
1276 if( ret != ERROR_SUCCESS )
1277 msi_free( info );
1278 msi_free( font_mask );
1279 msi_free( font );
1280 return ret;
1283 /******************** Progress Bar *****************************************/
1285 static UINT msi_dialog_progress_bar( msi_dialog *dialog, MSIRECORD *rec )
1287 msi_dialog_add_control( dialog, rec, PROGRESS_CLASSW, WS_VISIBLE );
1288 return ERROR_SUCCESS;
1291 /******************** Path Edit ********************************************/
1293 static UINT msi_dialog_pathedit_control( msi_dialog *dialog, MSIRECORD *rec )
1295 FIXME("not implemented properly\n");
1296 return msi_dialog_edit_control( dialog, rec );
1299 /* radio buttons are a bit different from normal controls */
1300 static UINT msi_dialog_create_radiobutton( MSIRECORD *rec, LPVOID param )
1302 radio_button_group_descr *group = (radio_button_group_descr *)param;
1303 msi_dialog *dialog = group->dialog;
1304 msi_control *control;
1305 LPCWSTR prop, text, name;
1306 DWORD style, attributes = group->attributes;
1308 style = WS_CHILD | BS_AUTORADIOBUTTON | BS_MULTILINE | WS_TABSTOP;
1309 name = MSI_RecordGetString( rec, 3 );
1310 text = MSI_RecordGetString( rec, 8 );
1311 if( attributes & 1 )
1312 style |= WS_VISIBLE;
1313 if( ~attributes & 2 )
1314 style |= WS_DISABLED;
1316 control = msi_dialog_create_window( dialog, rec, szButton, name, text,
1317 style, group->parent->hwnd );
1318 if (!control)
1319 return ERROR_FUNCTION_FAILED;
1320 control->handler = msi_dialog_radiogroup_handler;
1322 prop = MSI_RecordGetString( rec, 1 );
1323 if( prop )
1324 control->property = strdupW( prop );
1326 return ERROR_SUCCESS;
1329 static UINT msi_dialog_radiogroup_control( msi_dialog *dialog, MSIRECORD *rec )
1331 static const WCHAR query[] = {
1332 'S','E','L','E','C','T',' ','*',' ',
1333 'F','R','O','M',' ','R','a','d','i','o','B','u','t','t','o','n',' ',
1334 'W','H','E','R','E',' ',
1335 '`','P','r','o','p','e','r','t','y','`',' ','=',' ','\'','%','s','\'',0};
1336 UINT r;
1337 LPCWSTR prop;
1338 msi_control *control;
1339 MSIQUERY *view = NULL;
1340 radio_button_group_descr group;
1341 MSIPACKAGE *package = dialog->package;
1342 WNDPROC oldproc;
1344 prop = MSI_RecordGetString( rec, 9 );
1346 TRACE("%p %p %s\n", dialog, rec, debugstr_w( prop ));
1348 /* Create parent group box to hold radio buttons */
1349 control = msi_dialog_add_control( dialog, rec, szButton, BS_OWNERDRAW|WS_GROUP );
1350 if( !control )
1351 return ERROR_FUNCTION_FAILED;
1353 oldproc = (WNDPROC) SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
1354 (LONG_PTR)MSIRadioGroup_WndProc );
1355 SetPropW(control->hwnd, szButtonData, oldproc);
1356 SetWindowLongPtrW( control->hwnd, GWL_EXSTYLE, WS_EX_CONTROLPARENT );
1358 if( prop )
1359 control->property = strdupW( prop );
1361 /* query the Radio Button table for all control in this group */
1362 r = MSI_OpenQuery( package->db, &view, query, prop );
1363 if( r != ERROR_SUCCESS )
1365 ERR("query failed for dialog %s radio group %s\n",
1366 debugstr_w(dialog->name), debugstr_w(prop));
1367 return ERROR_INVALID_PARAMETER;
1370 group.dialog = dialog;
1371 group.parent = control;
1372 group.attributes = MSI_RecordGetInteger( rec, 8 );
1374 r = MSI_IterateRecords( view, 0, msi_dialog_create_radiobutton, &group );
1375 msiobj_release( &view->hdr );
1377 return r;
1380 /******************** Selection Tree ***************************************/
1382 static void
1383 msi_dialog_tv_add_child_features( MSIPACKAGE *package, HWND hwnd,
1384 LPCWSTR parent, HTREEITEM hParent )
1386 MSIFEATURE *feature;
1387 TVINSERTSTRUCTW tvis;
1388 HTREEITEM hitem;
1390 LIST_FOR_EACH_ENTRY( feature, &package->features, MSIFEATURE, entry )
1392 if ( lstrcmpW( parent, feature->Feature_Parent ) )
1393 continue;
1395 if ( !feature->Title )
1396 continue;
1398 memset( &tvis, 0, sizeof tvis );
1399 tvis.hParent = hParent;
1400 tvis.hInsertAfter = TVI_SORT;
1401 if (feature->Title)
1403 tvis.u.item.mask = TVIF_TEXT;
1404 tvis.u.item.pszText = feature->Title;
1406 tvis.u.item.lParam = (LPARAM) feature;
1407 hitem = (HTREEITEM) SendMessageW( hwnd, TVM_INSERTITEMW, 0, (LPARAM) &tvis );
1408 if (!hitem)
1409 continue;
1411 msi_dialog_tv_add_child_features( package, hwnd,
1412 feature->Feature, hitem );
1416 static UINT msi_dialog_selection_tree( msi_dialog *dialog, MSIRECORD *rec )
1418 msi_control *control;
1419 LPCWSTR prop;
1420 LPWSTR val;
1421 MSIPACKAGE *package = dialog->package;
1423 prop = MSI_RecordGetString( rec, 9 );
1424 val = msi_dup_property( package, prop );
1425 control = msi_dialog_add_control( dialog, rec, WC_TREEVIEWW,
1426 TVS_HASBUTTONS | WS_GROUP | WS_VSCROLL );
1427 if (!control)
1428 return ERROR_FUNCTION_FAILED;
1430 msi_dialog_tv_add_child_features( package, control->hwnd, NULL, NULL );
1432 msi_free( val );
1434 return ERROR_SUCCESS;
1437 struct control_handler msi_dialog_handler[] =
1439 { szText, msi_dialog_text_control },
1440 { szPushButton, msi_dialog_button_control },
1441 { szLine, msi_dialog_line_control },
1442 { szBitmap, msi_dialog_bitmap_control },
1443 { szCheckBox, msi_dialog_checkbox_control },
1444 { szScrollableText, msi_dialog_scrolltext_control },
1445 { szComboBox, msi_dialog_combo_control },
1446 { szEdit, msi_dialog_edit_control },
1447 { szMaskedEdit, msi_dialog_maskedit_control },
1448 { szPathEdit, msi_dialog_pathedit_control },
1449 { szProgressBar, msi_dialog_progress_bar },
1450 { szRadioButtonGroup, msi_dialog_radiogroup_control },
1451 { szIcon, msi_dialog_icon_control },
1452 { szSelectionTree, msi_dialog_selection_tree },
1455 #define NUM_CONTROL_TYPES (sizeof msi_dialog_handler/sizeof msi_dialog_handler[0])
1457 static UINT msi_dialog_create_controls( MSIRECORD *rec, LPVOID param )
1459 msi_dialog *dialog = param;
1460 LPCWSTR control_type;
1461 UINT i;
1463 /* find and call the function that can create this type of control */
1464 control_type = MSI_RecordGetString( rec, 3 );
1465 for( i=0; i<NUM_CONTROL_TYPES; i++ )
1466 if (!strcmpiW( msi_dialog_handler[i].control_type, control_type ))
1467 break;
1468 if( i != NUM_CONTROL_TYPES )
1469 msi_dialog_handler[i].func( dialog, rec );
1470 else
1471 ERR("no handler for element type %s\n", debugstr_w(control_type));
1473 return ERROR_SUCCESS;
1476 static UINT msi_dialog_fill_controls( msi_dialog *dialog )
1478 static const WCHAR query[] = {
1479 'S','E','L','E','C','T',' ','*',' ',
1480 'F','R','O','M',' ','C','o','n','t','r','o','l',' ',
1481 'W','H','E','R','E',' ',
1482 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',0};
1483 UINT r;
1484 MSIQUERY *view = NULL;
1485 MSIPACKAGE *package = dialog->package;
1487 TRACE("%p %s\n", dialog, debugstr_w(dialog->name) );
1489 /* query the Control table for all the elements of the control */
1490 r = MSI_OpenQuery( package->db, &view, query, dialog->name );
1491 if( r != ERROR_SUCCESS )
1493 ERR("query failed for dialog %s\n", debugstr_w(dialog->name));
1494 return ERROR_INVALID_PARAMETER;
1497 r = MSI_IterateRecords( view, 0, msi_dialog_create_controls, dialog );
1498 msiobj_release( &view->hdr );
1500 return r;
1503 static UINT msi_dialog_set_control_condition( MSIRECORD *rec, LPVOID param )
1505 static const WCHAR szHide[] = { 'H','i','d','e',0 };
1506 static const WCHAR szShow[] = { 'S','h','o','w',0 };
1507 static const WCHAR szDisable[] = { 'D','i','s','a','b','l','e',0 };
1508 static const WCHAR szEnable[] = { 'E','n','a','b','l','e',0 };
1509 msi_dialog *dialog = param;
1510 msi_control *control;
1511 LPCWSTR name, action, condition;
1512 UINT r;
1514 name = MSI_RecordGetString( rec, 2 );
1515 action = MSI_RecordGetString( rec, 3 );
1516 condition = MSI_RecordGetString( rec, 4 );
1517 r = MSI_EvaluateConditionW( dialog->package, condition );
1518 control = msi_dialog_find_control( dialog, name );
1519 if( r == MSICONDITION_TRUE && control )
1521 TRACE("%s control %s\n", debugstr_w(action), debugstr_w(name));
1523 /* FIXME: case sensitive? */
1524 if(!lstrcmpW(action, szHide))
1525 ShowWindow(control->hwnd, SW_HIDE);
1526 else if(!strcmpW(action, szShow))
1527 ShowWindow(control->hwnd, SW_SHOW);
1528 else if(!strcmpW(action, szDisable))
1529 EnableWindow(control->hwnd, FALSE);
1530 else if(!strcmpW(action, szEnable))
1531 EnableWindow(control->hwnd, TRUE);
1532 else
1533 FIXME("Unhandled action %s\n", debugstr_w(action));
1536 return ERROR_SUCCESS;
1539 static UINT msi_dialog_evaluate_control_conditions( msi_dialog *dialog )
1541 static const WCHAR query[] = {
1542 'S','E','L','E','C','T',' ','*',' ',
1543 'F','R','O','M',' ',
1544 'C','o','n','t','r','o','l','C','o','n','d','i','t','i','o','n',' ',
1545 'W','H','E','R','E',' ',
1546 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',0
1548 UINT r;
1549 MSIQUERY *view = NULL;
1550 MSIPACKAGE *package = dialog->package;
1552 TRACE("%p %s\n", dialog, debugstr_w(dialog->name) );
1554 /* query the Control table for all the elements of the control */
1555 r = MSI_OpenQuery( package->db, &view, query, dialog->name );
1556 if( r != ERROR_SUCCESS )
1558 ERR("query failed for dialog %s\n", debugstr_w(dialog->name));
1559 return ERROR_INVALID_PARAMETER;
1562 r = MSI_IterateRecords( view, 0, msi_dialog_set_control_condition, dialog );
1563 msiobj_release( &view->hdr );
1565 return r;
1568 UINT msi_dialog_reset( msi_dialog *dialog )
1570 /* FIXME: should restore the original values of any properties we changed */
1571 return msi_dialog_evaluate_control_conditions( dialog );
1574 /* figure out the height of 10 point MS Sans Serif */
1575 static INT msi_dialog_get_sans_serif_height( HWND hwnd )
1577 static const WCHAR szSansSerif[] = {
1578 'M','S',' ','S','a','n','s',' ','S','e','r','i','f',0 };
1579 LOGFONTW lf;
1580 TEXTMETRICW tm;
1581 BOOL r;
1582 LONG height = 0;
1583 HFONT hFont, hOldFont;
1584 HDC hdc;
1586 hdc = GetDC( hwnd );
1587 if (hdc)
1589 memset( &lf, 0, sizeof lf );
1590 lf.lfHeight = MulDiv(10, GetDeviceCaps(hdc, LOGPIXELSY), 72);
1591 strcpyW( lf.lfFaceName, szSansSerif );
1592 hFont = CreateFontIndirectW(&lf);
1593 if (hFont)
1595 hOldFont = SelectObject( hdc, hFont );
1596 r = GetTextMetricsW( hdc, &tm );
1597 if (r)
1598 height = tm.tmHeight;
1599 SelectObject( hdc, hOldFont );
1600 DeleteObject( hFont );
1602 ReleaseDC( hwnd, hdc );
1604 return height;
1607 /* fetch the associated record from the Dialog table */
1608 static MSIRECORD *msi_get_dialog_record( msi_dialog *dialog )
1610 static const WCHAR query[] = {
1611 'S','E','L','E','C','T',' ','*',' ',
1612 'F','R','O','M',' ','D','i','a','l','o','g',' ',
1613 'W','H','E','R','E',' ',
1614 '`','D','i','a','l','o','g','`',' ','=',' ','\'','%','s','\'',0};
1615 MSIPACKAGE *package = dialog->package;
1616 MSIRECORD *rec = NULL;
1618 TRACE("%p %s\n", dialog, debugstr_w(dialog->name) );
1620 rec = MSI_QueryGetRecord( package->db, query, dialog->name );
1621 if( !rec )
1622 ERR("query failed for dialog %s\n", debugstr_w(dialog->name));
1624 return rec;
1627 static void msi_dialog_adjust_dialog_size( msi_dialog *dialog, LPSIZE sz )
1629 RECT rect;
1630 LONG style;
1632 /* turn the client size into the window rectangle */
1633 rect.left = 0;
1634 rect.top = 0;
1635 rect.right = msi_dialog_scale_unit( dialog, sz->cx );
1636 rect.bottom = msi_dialog_scale_unit( dialog, sz->cy );
1637 style = GetWindowLongPtrW( dialog->hwnd, GWL_STYLE );
1638 AdjustWindowRect( &rect, style, FALSE );
1639 sz->cx = rect.right - rect.left;
1640 sz->cy = rect.bottom - rect.top;
1643 static BOOL msi_control_set_next( msi_control *control, msi_control *next )
1645 return SetWindowPos( next->hwnd, control->hwnd, 0, 0, 0, 0,
1646 SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOREDRAW |
1647 SWP_NOREPOSITION | SWP_NOSENDCHANGING | SWP_NOSIZE );
1650 static UINT msi_dialog_set_tab_order( msi_dialog *dialog )
1652 msi_control *control, *tab_next;
1654 LIST_FOR_EACH_ENTRY( control, &dialog->controls, msi_control, entry )
1656 tab_next = msi_dialog_find_control( dialog, control->tabnext );
1657 if( !tab_next )
1658 continue;
1659 msi_control_set_next( control, tab_next );
1662 return ERROR_SUCCESS;
1665 static void msi_dialog_set_first_control( msi_dialog* dialog, LPCWSTR name )
1667 msi_control *control;
1669 control = msi_dialog_find_control( dialog, name );
1670 if( control )
1671 dialog->hWndFocus = control->hwnd;
1672 else
1673 dialog->hWndFocus = NULL;
1676 static LRESULT msi_dialog_oncreate( HWND hwnd, LPCREATESTRUCTW cs )
1678 static const WCHAR df[] = {
1679 'D','e','f','a','u','l','t','U','I','F','o','n','t',0 };
1680 static const WCHAR dfv[] = {
1681 'M','S',' ','S','h','e','l','l',' ','D','l','g',0 };
1682 msi_dialog *dialog = (msi_dialog*) cs->lpCreateParams;
1683 MSIRECORD *rec = NULL;
1684 LPWSTR title = NULL;
1685 SIZE size;
1687 TRACE("%p %p\n", dialog, dialog->package);
1689 dialog->hwnd = hwnd;
1690 SetWindowLongPtrW( hwnd, GWLP_USERDATA, (LONG_PTR) dialog );
1692 rec = msi_get_dialog_record( dialog );
1693 if( !rec )
1695 TRACE("No record found for dialog %s\n", debugstr_w(dialog->name));
1696 return -1;
1699 dialog->scale = msi_dialog_get_sans_serif_height(dialog->hwnd);
1701 size.cx = MSI_RecordGetInteger( rec, 4 );
1702 size.cy = MSI_RecordGetInteger( rec, 5 );
1703 msi_dialog_adjust_dialog_size( dialog, &size );
1705 dialog->attributes = MSI_RecordGetInteger( rec, 6 );
1707 dialog->default_font = msi_dup_property( dialog->package, df );
1708 if (!dialog->default_font)
1710 dialog->default_font = strdupW(dfv);
1711 if (!dialog->default_font) return -1;
1714 title = msi_get_deformatted_field( dialog->package, rec, 7 );
1715 SetWindowTextW( hwnd, title );
1716 msi_free( title );
1718 SetWindowPos( hwnd, 0, 0, 0, size.cx, size.cy,
1719 SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOREDRAW );
1722 msi_dialog_build_font_list( dialog );
1723 msi_dialog_fill_controls( dialog );
1724 msi_dialog_evaluate_control_conditions( dialog );
1725 msi_dialog_set_tab_order( dialog );
1726 msi_dialog_set_first_control( dialog, MSI_RecordGetString( rec, 8 ) );
1727 msiobj_release( &rec->hdr );
1729 return 0;
1732 static UINT msi_dialog_send_event( msi_dialog *dialog, LPCWSTR event, LPCWSTR arg )
1734 LPWSTR event_fmt = NULL, arg_fmt = NULL;
1736 TRACE("Sending control event %s %s\n", debugstr_w(event), debugstr_w(arg));
1738 deformat_string( dialog->package, event, &event_fmt );
1739 deformat_string( dialog->package, arg, &arg_fmt );
1741 dialog->event_handler( dialog->package, event_fmt, arg_fmt, dialog );
1743 msi_free( event_fmt );
1744 msi_free( arg_fmt );
1746 return ERROR_SUCCESS;
1749 static UINT msi_dialog_set_property( msi_dialog *dialog, LPCWSTR event, LPCWSTR arg )
1751 static const WCHAR szNullArg[] = { '{','}',0 };
1752 LPWSTR p, prop, arg_fmt = NULL;
1753 UINT len;
1755 len = strlenW(event);
1756 prop = msi_alloc( len*sizeof(WCHAR));
1757 strcpyW( prop, &event[1] );
1758 p = strchrW( prop, ']' );
1759 if( p && p[1] == 0 )
1761 *p = 0;
1762 if( strcmpW( szNullArg, arg ) )
1763 deformat_string( dialog->package, arg, &arg_fmt );
1764 MSI_SetPropertyW( dialog->package, prop, arg_fmt );
1765 msi_free( arg_fmt );
1767 else
1768 ERR("Badly formatted property string - what happens?\n");
1769 msi_free( prop );
1770 return ERROR_SUCCESS;
1773 static UINT msi_dialog_control_event( MSIRECORD *rec, LPVOID param )
1775 msi_dialog *dialog = param;
1776 LPCWSTR condition, event, arg;
1777 UINT r;
1779 condition = MSI_RecordGetString( rec, 5 );
1780 r = MSI_EvaluateConditionW( dialog->package, condition );
1781 if( r == MSICONDITION_TRUE )
1783 event = MSI_RecordGetString( rec, 3 );
1784 arg = MSI_RecordGetString( rec, 4 );
1785 if( event[0] == '[' )
1786 msi_dialog_set_property( dialog, event, arg );
1787 else
1788 msi_dialog_send_event( dialog, event, arg );
1791 return ERROR_SUCCESS;
1794 static UINT msi_dialog_button_handler( msi_dialog *dialog,
1795 msi_control *control, WPARAM param )
1797 static const WCHAR query[] = {
1798 'S','E','L','E','C','T',' ','*',' ',
1799 'F','R','O','M',' ','C','o','n','t','r','o','l','E','v','e','n','t',' ',
1800 'W','H','E','R','E',' ',
1801 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',' ',
1802 'A','N','D',' ',
1803 '`','C','o','n','t','r','o','l','_','`',' ','=',' ','\'','%','s','\'',' ',
1804 'O','R','D','E','R',' ','B','Y',' ','`','O','r','d','e','r','i','n','g','`',0
1806 MSIQUERY *view = NULL;
1807 UINT r;
1809 if( HIWORD(param) != BN_CLICKED )
1810 return ERROR_SUCCESS;
1812 r = MSI_OpenQuery( dialog->package->db, &view, query,
1813 dialog->name, control->name );
1814 if( r != ERROR_SUCCESS )
1816 ERR("query failed\n");
1817 return 0;
1820 r = MSI_IterateRecords( view, 0, msi_dialog_control_event, dialog );
1821 msiobj_release( &view->hdr );
1823 return r;
1826 static UINT msi_dialog_get_checkbox_state( msi_dialog *dialog,
1827 msi_control *control )
1829 WCHAR state[2] = { 0 };
1830 DWORD sz = 2;
1832 MSI_GetPropertyW( dialog->package, control->property, state, &sz );
1833 return state[0] ? 1 : 0;
1836 static void msi_dialog_set_checkbox_state( msi_dialog *dialog,
1837 msi_control *control, UINT state )
1839 static const WCHAR szState[] = { '1', 0 };
1840 LPCWSTR val;
1842 /* if uncheck then the property is set to NULL */
1843 if (!state)
1845 MSI_SetPropertyW( dialog->package, control->property, NULL );
1846 return;
1849 /* check for a custom state */
1850 if (control->value && control->value[0])
1851 val = control->value;
1852 else
1853 val = szState;
1855 MSI_SetPropertyW( dialog->package, control->property, val );
1858 static void msi_dialog_checkbox_sync_state( msi_dialog *dialog,
1859 msi_control *control )
1861 UINT state;
1863 state = msi_dialog_get_checkbox_state( dialog, control );
1864 SendMessageW( control->hwnd, BM_SETCHECK,
1865 state ? BST_CHECKED : BST_UNCHECKED, 0 );
1868 static UINT msi_dialog_checkbox_handler( msi_dialog *dialog,
1869 msi_control *control, WPARAM param )
1871 UINT state;
1873 if( HIWORD(param) != BN_CLICKED )
1874 return ERROR_SUCCESS;
1876 TRACE("clicked checkbox %s, set %s\n", debugstr_w(control->name),
1877 debugstr_w(control->property));
1879 state = msi_dialog_get_checkbox_state( dialog, control );
1880 state = state ? 0 : 1;
1881 msi_dialog_set_checkbox_state( dialog, control, state );
1882 msi_dialog_checkbox_sync_state( dialog, control );
1884 return msi_dialog_button_handler( dialog, control, param );
1887 static UINT msi_dialog_edit_handler( msi_dialog *dialog,
1888 msi_control *control, WPARAM param )
1890 UINT sz, r;
1891 LPWSTR buf;
1893 if( HIWORD(param) != EN_CHANGE )
1894 return ERROR_SUCCESS;
1896 TRACE("edit %s contents changed, set %s\n", debugstr_w(control->name),
1897 debugstr_w(control->property));
1899 sz = 0x20;
1900 buf = msi_alloc( sz*sizeof(WCHAR) );
1901 while( buf )
1903 r = GetWindowTextW( control->hwnd, buf, sz );
1904 if( r < (sz-1) )
1905 break;
1906 sz *= 2;
1907 buf = msi_realloc( buf, sz*sizeof(WCHAR) );
1910 MSI_SetPropertyW( dialog->package, control->property, buf );
1912 msi_free( buf );
1914 return ERROR_SUCCESS;
1917 static UINT msi_dialog_radiogroup_handler( msi_dialog *dialog,
1918 msi_control *control, WPARAM param )
1920 if( HIWORD(param) != BN_CLICKED )
1921 return ERROR_SUCCESS;
1923 TRACE("clicked radio button %s, set %s\n", debugstr_w(control->name),
1924 debugstr_w(control->property));
1926 MSI_SetPropertyW( dialog->package, control->property, control->name );
1928 return msi_dialog_button_handler( dialog, control, param );
1931 static LRESULT msi_dialog_oncommand( msi_dialog *dialog, WPARAM param, HWND hwnd )
1933 msi_control *control = NULL;
1935 TRACE("%p %p %08x\n", dialog, hwnd, param);
1937 switch (param)
1939 case 1: /* enter */
1940 control = msi_dialog_find_control( dialog, dialog->control_default );
1941 break;
1942 case 2: /* escape */
1943 control = msi_dialog_find_control( dialog, dialog->control_cancel );
1944 break;
1945 default:
1946 control = msi_dialog_find_control_by_hwnd( dialog, hwnd );
1949 if( control )
1951 if( control->handler )
1953 control->handler( dialog, control, param );
1954 msi_dialog_evaluate_control_conditions( dialog );
1957 else
1958 ERR("button click from nowhere %p %d %p\n", dialog, param, hwnd);
1959 return 0;
1962 static void msi_dialog_setfocus( msi_dialog *dialog )
1964 HWND hwnd = dialog->hWndFocus;
1966 hwnd = GetNextDlgTabItem( dialog->hwnd, hwnd, TRUE);
1967 hwnd = GetNextDlgTabItem( dialog->hwnd, hwnd, FALSE);
1968 SetFocus( hwnd );
1969 dialog->hWndFocus = hwnd;
1972 static LRESULT WINAPI MSIDialog_WndProc( HWND hwnd, UINT msg,
1973 WPARAM wParam, LPARAM lParam )
1975 msi_dialog *dialog = (LPVOID) GetWindowLongPtrW( hwnd, GWLP_USERDATA );
1977 TRACE("0x%04x\n", msg);
1979 switch (msg)
1981 case WM_CREATE:
1982 return msi_dialog_oncreate( hwnd, (LPCREATESTRUCTW)lParam );
1984 case WM_COMMAND:
1985 return msi_dialog_oncommand( dialog, wParam, (HWND)lParam );
1987 case WM_ACTIVATE:
1988 if( LOWORD(wParam) == WA_INACTIVE )
1989 dialog->hWndFocus = GetFocus();
1990 else
1991 msi_dialog_setfocus( dialog );
1992 return 0;
1994 case WM_SETFOCUS:
1995 msi_dialog_setfocus( dialog );
1996 return 0;
1998 /* bounce back to our subclassed static control */
1999 case WM_CTLCOLORSTATIC:
2000 return SendMessageW( (HWND) lParam, WM_CTLCOLORSTATIC, wParam, lParam );
2002 case WM_DESTROY:
2003 dialog->hwnd = NULL;
2004 return 0;
2006 return DefWindowProcW(hwnd, msg, wParam, lParam);
2009 static LRESULT WINAPI MSIRadioGroup_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
2011 WNDPROC oldproc = (WNDPROC) GetPropW(hWnd, szButtonData);
2013 TRACE("hWnd %p msg %04x wParam 0x%08x lParam 0x%08lx\n", hWnd, msg, wParam, lParam);
2015 if (msg == WM_COMMAND) /* Forward notifications to dialog */
2016 SendMessageW(GetParent(hWnd), msg, wParam, lParam);
2018 return CallWindowProcW(oldproc, hWnd, msg, wParam, lParam);
2021 static LRESULT WINAPI MSIHiddenWindowProc( HWND hwnd, UINT msg,
2022 WPARAM wParam, LPARAM lParam )
2024 msi_dialog *dialog = (msi_dialog*) lParam;
2026 TRACE("%d %p\n", msg, dialog);
2028 switch (msg)
2030 case WM_MSI_DIALOG_CREATE:
2031 return msi_dialog_run_message_loop( dialog );
2032 case WM_MSI_DIALOG_DESTROY:
2033 msi_dialog_destroy( dialog );
2034 return 0;
2036 return DefWindowProcW( hwnd, msg, wParam, lParam );
2039 /* functions that interface to other modules within MSI */
2041 msi_dialog *msi_dialog_create( MSIPACKAGE* package, LPCWSTR szDialogName,
2042 msi_dialog_event_handler event_handler )
2044 MSIRECORD *rec = NULL;
2045 msi_dialog *dialog;
2047 TRACE("%p %s\n", package, debugstr_w(szDialogName));
2049 /* allocate the structure for the dialog to use */
2050 dialog = msi_alloc_zero( sizeof *dialog + sizeof(WCHAR)*strlenW(szDialogName) );
2051 if( !dialog )
2052 return NULL;
2053 strcpyW( dialog->name, szDialogName );
2054 msiobj_addref( &package->hdr );
2055 dialog->package = package;
2056 dialog->event_handler = event_handler;
2057 dialog->finished = 0;
2058 list_init( &dialog->controls );
2060 /* verify that the dialog exists */
2061 rec = msi_get_dialog_record( dialog );
2062 if( !rec )
2064 msiobj_release( &package->hdr );
2065 msi_free( dialog );
2066 return NULL;
2068 dialog->attributes = MSI_RecordGetInteger( rec, 6 );
2069 dialog->control_default = strdupW( MSI_RecordGetString( rec, 9 ) );
2070 dialog->control_cancel = strdupW( MSI_RecordGetString( rec, 10 ) );
2071 msiobj_release( &rec->hdr );
2073 return dialog;
2076 static void msi_process_pending_messages( HWND hdlg )
2078 MSG msg;
2080 while( PeekMessageW( &msg, 0, 0, 0, PM_REMOVE ) )
2082 if( hdlg && IsDialogMessageW( hdlg, &msg ))
2083 continue;
2084 TranslateMessage( &msg );
2085 DispatchMessageW( &msg );
2089 void msi_dialog_end_dialog( msi_dialog *dialog )
2091 TRACE("%p\n", dialog);
2092 dialog->finished = 1;
2093 PostMessageW(dialog->hwnd, WM_NULL, 0, 0);
2096 void msi_dialog_check_messages( HANDLE handle )
2098 DWORD r;
2100 /* in threads other than the UI thread, block */
2101 if( uiThreadId != GetCurrentThreadId() )
2103 if( handle )
2104 WaitForSingleObject( handle, INFINITE );
2105 return;
2108 /* there's two choices for the UI thread */
2109 while (1)
2111 msi_process_pending_messages( NULL );
2113 if( !handle )
2114 break;
2117 * block here until somebody creates a new dialog or
2118 * the handle we're waiting on becomes ready
2120 r = MsgWaitForMultipleObjects( 1, &handle, 0, INFINITE, QS_ALLINPUT );
2121 if( r == WAIT_OBJECT_0 )
2122 break;
2126 UINT msi_dialog_run_message_loop( msi_dialog *dialog )
2128 HWND hwnd;
2130 if( !(dialog->attributes & msidbDialogAttributesVisible) )
2131 return ERROR_SUCCESS;
2133 if( uiThreadId != GetCurrentThreadId() )
2134 return SendMessageW( hMsiHiddenWindow, WM_MSI_DIALOG_CREATE, 0, (LPARAM) dialog );
2136 /* create the dialog window, don't show it yet */
2137 hwnd = CreateWindowW( szMsiDialogClass, dialog->name, WS_OVERLAPPEDWINDOW,
2138 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
2139 NULL, NULL, NULL, dialog );
2140 if( !hwnd )
2142 ERR("Failed to create dialog %s\n", debugstr_w( dialog->name ));
2143 return ERROR_FUNCTION_FAILED;
2146 ShowWindow( hwnd, SW_SHOW );
2147 /* UpdateWindow( hwnd ); - and causes the transparent static controls not to paint */
2149 if( dialog->attributes & msidbDialogAttributesModal )
2151 while( !dialog->finished )
2153 MsgWaitForMultipleObjects( 0, NULL, 0, INFINITE, QS_ALLEVENTS );
2154 msi_process_pending_messages( dialog->hwnd );
2157 else
2158 return ERROR_IO_PENDING;
2160 return ERROR_SUCCESS;
2163 void msi_dialog_do_preview( msi_dialog *dialog )
2165 TRACE("\n");
2166 dialog->attributes |= msidbDialogAttributesVisible;
2167 dialog->attributes &= ~msidbDialogAttributesModal;
2168 msi_dialog_run_message_loop( dialog );
2171 void msi_dialog_destroy( msi_dialog *dialog )
2173 if( uiThreadId != GetCurrentThreadId() )
2175 SendMessageW( hMsiHiddenWindow, WM_MSI_DIALOG_DESTROY, 0, (LPARAM) dialog );
2176 return;
2179 if( dialog->hwnd )
2180 ShowWindow( dialog->hwnd, SW_HIDE );
2182 if( dialog->hwnd )
2183 DestroyWindow( dialog->hwnd );
2185 /* destroy the list of controls */
2186 while( !list_empty( &dialog->controls ) )
2188 msi_control *t = LIST_ENTRY( list_head( &dialog->controls ),
2189 msi_control, entry );
2190 list_remove( &t->entry );
2191 /* leave dialog->hwnd - destroying parent destroys child windows */
2192 msi_free( t->property );
2193 msi_free( t->value );
2194 if( t->hBitmap )
2195 DeleteObject( t->hBitmap );
2196 if( t->hIcon )
2197 DestroyIcon( t->hIcon );
2198 msi_free( t->tabnext );
2199 msi_free( t );
2202 /* destroy the list of fonts */
2203 while( dialog->font_list )
2205 msi_font *t = dialog->font_list;
2206 dialog->font_list = t->next;
2207 DeleteObject( t->hfont );
2208 msi_free( t );
2210 msi_free( dialog->default_font );
2212 msi_free( dialog->control_default );
2213 msi_free( dialog->control_cancel );
2214 msiobj_release( &dialog->package->hdr );
2215 dialog->package = NULL;
2216 msi_free( dialog );
2219 BOOL msi_dialog_register_class( void )
2221 WNDCLASSW cls;
2223 ZeroMemory( &cls, sizeof cls );
2224 cls.lpfnWndProc = MSIDialog_WndProc;
2225 cls.hInstance = NULL;
2226 cls.hIcon = LoadIconW(0, (LPWSTR)IDI_APPLICATION);
2227 cls.hCursor = LoadCursorW(0, (LPWSTR)IDC_ARROW);
2228 cls.hbrBackground = (HBRUSH)(COLOR_3DFACE + 1);
2229 cls.lpszMenuName = NULL;
2230 cls.lpszClassName = szMsiDialogClass;
2232 if( !RegisterClassW( &cls ) )
2233 return FALSE;
2235 cls.lpfnWndProc = MSIHiddenWindowProc;
2236 cls.lpszClassName = szMsiHiddenWindow;
2238 if( !RegisterClassW( &cls ) )
2239 return FALSE;
2241 uiThreadId = GetCurrentThreadId();
2243 hMsiHiddenWindow = CreateWindowW( szMsiHiddenWindow, NULL, WS_OVERLAPPED,
2244 0, 0, 100, 100, NULL, NULL, NULL, NULL );
2245 if( !hMsiHiddenWindow )
2246 return FALSE;
2248 return TRUE;
2251 void msi_dialog_unregister_class( void )
2253 DestroyWindow( hMsiHiddenWindow );
2254 hMsiHiddenWindow = NULL;
2255 UnregisterClassW( szMsiDialogClass, NULL );
2256 UnregisterClassW( szMsiHiddenWindow, NULL );
2257 uiThreadId = 0;