msi: Fixes for the MaskedEdit control.
[wine/multimedia.git] / dlls / msi / dialog.c
blob1384e229caa052e742caf937bd5fb7c5fb98bd9d
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 info = msi_alloc_zero( sizeof *info );
1133 if( !info )
1134 return info;
1136 p = strchrW(mask, '<');
1137 if( p )
1138 p++;
1139 else
1140 p = mask;
1142 for( i=0; i<MASK_MAX_GROUPS; i++ )
1144 /* stop at the end of the string */
1145 if( p[0] == 0 || p[0] == '>' )
1146 break;
1148 /* count the number of the same identifier */
1149 for( n=0; p[n] == p[0]; n++ )
1151 info->group[i].ofs = total;
1152 info->group[i].type = p[0];
1153 if( p[n] == '=' )
1155 n++;
1156 total++; /* an extra not part of the group */
1158 info->group[i].len = n;
1159 total += n;
1160 p += n;
1163 TRACE("%d characters in %d groups\n", total, i );
1164 if( i == MASK_MAX_GROUPS )
1165 ERR("too many groups in PIDTemplate %s\n", debugstr_w(mask));
1167 info->num_chars = total;
1168 info->num_groups = i;
1170 return info;
1173 static void
1174 msi_maskedit_create_children( struct msi_maskedit_info *info, LPCWSTR font )
1176 DWORD width, height, style, wx, ww;
1177 RECT rect;
1178 HWND hwnd;
1179 UINT i;
1181 style = WS_CHILD | WS_BORDER | WS_VISIBLE | WS_TABSTOP | ES_AUTOHSCROLL;
1183 GetClientRect( info->hwnd, &rect );
1185 width = rect.right - rect.left;
1186 height = rect.bottom - rect.top;
1188 for( i = 0; i < info->num_groups; i++ )
1190 if (!msi_mask_editable( info->group[i].type ))
1191 continue;
1192 wx = (info->group[i].ofs * width) / info->num_chars;
1193 ww = (info->group[i].len * width) / info->num_chars;
1195 hwnd = CreateWindowW( szEdit, NULL, style, wx, 0, ww, height,
1196 info->hwnd, NULL, NULL, NULL );
1197 if( !hwnd )
1199 ERR("failed to create mask edit sub window\n");
1200 break;
1203 SendMessageW( hwnd, EM_LIMITTEXT, info->group[i].len, 0 );
1205 msi_dialog_set_font( info->dialog, hwnd,
1206 font?font:info->dialog->default_font );
1207 info->group[i].hwnd = hwnd;
1212 * office 2003 uses "73931<````=````=````=````=`````>@@@@@"
1213 * delphi 7 uses "<????-??????-??????-????>" and "<???-???>"
1214 * filemaker pro 7 uses "<^^^^=^^^^=^^^^=^^^^=^^^^=^^^^=^^^^^>"
1216 static UINT msi_dialog_maskedit_control( msi_dialog *dialog, MSIRECORD *rec )
1218 LPWSTR font_mask, val = NULL, font;
1219 struct msi_maskedit_info *info = NULL;
1220 UINT ret = ERROR_SUCCESS;
1221 msi_control *control;
1222 LPCWSTR prop, mask;
1224 TRACE("\n");
1226 font_mask = msi_get_deformatted_field( dialog->package, rec, 10 );
1227 font = msi_dialog_get_style( font_mask, &mask );
1228 if( !mask )
1230 ERR("mask template is empty\n");
1231 goto end;
1234 info = msi_dialog_parse_groups( mask );
1235 if( !info )
1237 ERR("template %s is invalid\n", debugstr_w(mask));
1238 goto end;
1241 info->dialog = dialog;
1243 control = msi_dialog_add_control( dialog, rec, szStatic,
1244 SS_OWNERDRAW | WS_GROUP | WS_VISIBLE );
1245 if( !control )
1247 ERR("Failed to create maskedit container\n");
1248 ret = ERROR_FUNCTION_FAILED;
1249 goto end;
1251 SetWindowLongPtrW( control->hwnd, GWL_EXSTYLE, WS_EX_CONTROLPARENT );
1253 info->hwnd = control->hwnd;
1255 /* subclass the static control */
1256 info->oldproc = (WNDPROC) SetWindowLongPtrW( info->hwnd, GWLP_WNDPROC,
1257 (LONG_PTR)MSIMaskedEdit_WndProc );
1258 SetPropW( control->hwnd, szButtonData, info );
1260 prop = MSI_RecordGetString( rec, 9 );
1261 if( prop )
1262 info->prop = strdupW( prop );
1264 msi_maskedit_create_children( info, font );
1266 if( prop )
1268 val = msi_dup_property( dialog->package, prop );
1269 if( val )
1271 msi_maskedit_set_text( info, val );
1272 msi_free( val );
1276 end:
1277 if( ret != ERROR_SUCCESS )
1278 msi_free( info );
1279 msi_free( font_mask );
1280 msi_free( font );
1281 return ret;
1284 /******************** Progress Bar *****************************************/
1286 static UINT msi_dialog_progress_bar( msi_dialog *dialog, MSIRECORD *rec )
1288 msi_dialog_add_control( dialog, rec, PROGRESS_CLASSW, WS_VISIBLE );
1289 return ERROR_SUCCESS;
1292 /******************** Path Edit ********************************************/
1294 static UINT msi_dialog_pathedit_control( msi_dialog *dialog, MSIRECORD *rec )
1296 FIXME("not implemented properly\n");
1297 return msi_dialog_edit_control( dialog, rec );
1300 /* radio buttons are a bit different from normal controls */
1301 static UINT msi_dialog_create_radiobutton( MSIRECORD *rec, LPVOID param )
1303 radio_button_group_descr *group = (radio_button_group_descr *)param;
1304 msi_dialog *dialog = group->dialog;
1305 msi_control *control;
1306 LPCWSTR prop, text, name;
1307 DWORD style, attributes = group->attributes;
1309 style = WS_CHILD | BS_AUTORADIOBUTTON | BS_MULTILINE | WS_TABSTOP;
1310 name = MSI_RecordGetString( rec, 3 );
1311 text = MSI_RecordGetString( rec, 8 );
1312 if( attributes & 1 )
1313 style |= WS_VISIBLE;
1314 if( ~attributes & 2 )
1315 style |= WS_DISABLED;
1317 control = msi_dialog_create_window( dialog, rec, szButton, name, text,
1318 style, group->parent->hwnd );
1319 if (!control)
1320 return ERROR_FUNCTION_FAILED;
1321 control->handler = msi_dialog_radiogroup_handler;
1323 prop = MSI_RecordGetString( rec, 1 );
1324 if( prop )
1325 control->property = strdupW( prop );
1327 return ERROR_SUCCESS;
1330 static UINT msi_dialog_radiogroup_control( msi_dialog *dialog, MSIRECORD *rec )
1332 static const WCHAR query[] = {
1333 'S','E','L','E','C','T',' ','*',' ',
1334 'F','R','O','M',' ','R','a','d','i','o','B','u','t','t','o','n',' ',
1335 'W','H','E','R','E',' ',
1336 '`','P','r','o','p','e','r','t','y','`',' ','=',' ','\'','%','s','\'',0};
1337 UINT r;
1338 LPCWSTR prop;
1339 msi_control *control;
1340 MSIQUERY *view = NULL;
1341 radio_button_group_descr group;
1342 MSIPACKAGE *package = dialog->package;
1343 WNDPROC oldproc;
1345 prop = MSI_RecordGetString( rec, 9 );
1347 TRACE("%p %p %s\n", dialog, rec, debugstr_w( prop ));
1349 /* Create parent group box to hold radio buttons */
1350 control = msi_dialog_add_control( dialog, rec, szButton, BS_OWNERDRAW|WS_GROUP );
1351 if( !control )
1352 return ERROR_FUNCTION_FAILED;
1354 oldproc = (WNDPROC) SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
1355 (LONG_PTR)MSIRadioGroup_WndProc );
1356 SetPropW(control->hwnd, szButtonData, oldproc);
1357 SetWindowLongPtrW( control->hwnd, GWL_EXSTYLE, WS_EX_CONTROLPARENT );
1359 if( prop )
1360 control->property = strdupW( prop );
1362 /* query the Radio Button table for all control in this group */
1363 r = MSI_OpenQuery( package->db, &view, query, prop );
1364 if( r != ERROR_SUCCESS )
1366 ERR("query failed for dialog %s radio group %s\n",
1367 debugstr_w(dialog->name), debugstr_w(prop));
1368 return ERROR_INVALID_PARAMETER;
1371 group.dialog = dialog;
1372 group.parent = control;
1373 group.attributes = MSI_RecordGetInteger( rec, 8 );
1375 r = MSI_IterateRecords( view, 0, msi_dialog_create_radiobutton, &group );
1376 msiobj_release( &view->hdr );
1378 return r;
1381 /******************** Selection Tree ***************************************/
1383 static void
1384 msi_dialog_tv_add_child_features( MSIPACKAGE *package, HWND hwnd,
1385 LPCWSTR parent, HTREEITEM hParent )
1387 MSIFEATURE *feature;
1388 TVINSERTSTRUCTW tvis;
1389 HTREEITEM hitem;
1391 LIST_FOR_EACH_ENTRY( feature, &package->features, MSIFEATURE, entry )
1393 if ( lstrcmpW( parent, feature->Feature_Parent ) )
1394 continue;
1396 if ( !feature->Title )
1397 continue;
1399 memset( &tvis, 0, sizeof tvis );
1400 tvis.hParent = hParent;
1401 tvis.hInsertAfter = TVI_SORT;
1402 if (feature->Title)
1404 tvis.u.item.mask = TVIF_TEXT;
1405 tvis.u.item.pszText = feature->Title;
1407 tvis.u.item.lParam = (LPARAM) feature;
1408 hitem = (HTREEITEM) SendMessageW( hwnd, TVM_INSERTITEMW, 0, (LPARAM) &tvis );
1409 if (!hitem)
1410 continue;
1412 msi_dialog_tv_add_child_features( package, hwnd,
1413 feature->Feature, hitem );
1417 static UINT msi_dialog_selection_tree( msi_dialog *dialog, MSIRECORD *rec )
1419 msi_control *control;
1420 LPCWSTR prop;
1421 LPWSTR val;
1422 MSIPACKAGE *package = dialog->package;
1424 prop = MSI_RecordGetString( rec, 9 );
1425 val = msi_dup_property( package, prop );
1426 control = msi_dialog_add_control( dialog, rec, WC_TREEVIEWW,
1427 TVS_HASBUTTONS | WS_GROUP | WS_VSCROLL );
1428 if (!control)
1429 return ERROR_FUNCTION_FAILED;
1431 msi_dialog_tv_add_child_features( package, control->hwnd, NULL, NULL );
1433 msi_free( val );
1435 return ERROR_SUCCESS;
1438 struct control_handler msi_dialog_handler[] =
1440 { szText, msi_dialog_text_control },
1441 { szPushButton, msi_dialog_button_control },
1442 { szLine, msi_dialog_line_control },
1443 { szBitmap, msi_dialog_bitmap_control },
1444 { szCheckBox, msi_dialog_checkbox_control },
1445 { szScrollableText, msi_dialog_scrolltext_control },
1446 { szComboBox, msi_dialog_combo_control },
1447 { szEdit, msi_dialog_edit_control },
1448 { szMaskedEdit, msi_dialog_maskedit_control },
1449 { szPathEdit, msi_dialog_pathedit_control },
1450 { szProgressBar, msi_dialog_progress_bar },
1451 { szRadioButtonGroup, msi_dialog_radiogroup_control },
1452 { szIcon, msi_dialog_icon_control },
1453 { szSelectionTree, msi_dialog_selection_tree },
1456 #define NUM_CONTROL_TYPES (sizeof msi_dialog_handler/sizeof msi_dialog_handler[0])
1458 static UINT msi_dialog_create_controls( MSIRECORD *rec, LPVOID param )
1460 msi_dialog *dialog = param;
1461 LPCWSTR control_type;
1462 UINT i;
1464 /* find and call the function that can create this type of control */
1465 control_type = MSI_RecordGetString( rec, 3 );
1466 for( i=0; i<NUM_CONTROL_TYPES; i++ )
1467 if (!strcmpiW( msi_dialog_handler[i].control_type, control_type ))
1468 break;
1469 if( i != NUM_CONTROL_TYPES )
1470 msi_dialog_handler[i].func( dialog, rec );
1471 else
1472 ERR("no handler for element type %s\n", debugstr_w(control_type));
1474 return ERROR_SUCCESS;
1477 static UINT msi_dialog_fill_controls( msi_dialog *dialog )
1479 static const WCHAR query[] = {
1480 'S','E','L','E','C','T',' ','*',' ',
1481 'F','R','O','M',' ','C','o','n','t','r','o','l',' ',
1482 'W','H','E','R','E',' ',
1483 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',0};
1484 UINT r;
1485 MSIQUERY *view = NULL;
1486 MSIPACKAGE *package = dialog->package;
1488 TRACE("%p %s\n", dialog, debugstr_w(dialog->name) );
1490 /* query the Control table for all the elements of the control */
1491 r = MSI_OpenQuery( package->db, &view, query, dialog->name );
1492 if( r != ERROR_SUCCESS )
1494 ERR("query failed for dialog %s\n", debugstr_w(dialog->name));
1495 return ERROR_INVALID_PARAMETER;
1498 r = MSI_IterateRecords( view, 0, msi_dialog_create_controls, dialog );
1499 msiobj_release( &view->hdr );
1501 return r;
1504 static UINT msi_dialog_set_control_condition( MSIRECORD *rec, LPVOID param )
1506 static const WCHAR szHide[] = { 'H','i','d','e',0 };
1507 static const WCHAR szShow[] = { 'S','h','o','w',0 };
1508 static const WCHAR szDisable[] = { 'D','i','s','a','b','l','e',0 };
1509 static const WCHAR szEnable[] = { 'E','n','a','b','l','e',0 };
1510 msi_dialog *dialog = param;
1511 msi_control *control;
1512 LPCWSTR name, action, condition;
1513 UINT r;
1515 name = MSI_RecordGetString( rec, 2 );
1516 action = MSI_RecordGetString( rec, 3 );
1517 condition = MSI_RecordGetString( rec, 4 );
1518 r = MSI_EvaluateConditionW( dialog->package, condition );
1519 control = msi_dialog_find_control( dialog, name );
1520 if( r == MSICONDITION_TRUE && control )
1522 TRACE("%s control %s\n", debugstr_w(action), debugstr_w(name));
1524 /* FIXME: case sensitive? */
1525 if(!lstrcmpW(action, szHide))
1526 ShowWindow(control->hwnd, SW_HIDE);
1527 else if(!strcmpW(action, szShow))
1528 ShowWindow(control->hwnd, SW_SHOW);
1529 else if(!strcmpW(action, szDisable))
1530 EnableWindow(control->hwnd, FALSE);
1531 else if(!strcmpW(action, szEnable))
1532 EnableWindow(control->hwnd, TRUE);
1533 else
1534 FIXME("Unhandled action %s\n", debugstr_w(action));
1537 return ERROR_SUCCESS;
1540 static UINT msi_dialog_evaluate_control_conditions( msi_dialog *dialog )
1542 static const WCHAR query[] = {
1543 'S','E','L','E','C','T',' ','*',' ',
1544 'F','R','O','M',' ',
1545 'C','o','n','t','r','o','l','C','o','n','d','i','t','i','o','n',' ',
1546 'W','H','E','R','E',' ',
1547 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',0
1549 UINT r;
1550 MSIQUERY *view = NULL;
1551 MSIPACKAGE *package = dialog->package;
1553 TRACE("%p %s\n", dialog, debugstr_w(dialog->name) );
1555 /* query the Control table for all the elements of the control */
1556 r = MSI_OpenQuery( package->db, &view, query, dialog->name );
1557 if( r != ERROR_SUCCESS )
1559 ERR("query failed for dialog %s\n", debugstr_w(dialog->name));
1560 return ERROR_INVALID_PARAMETER;
1563 r = MSI_IterateRecords( view, 0, msi_dialog_set_control_condition, dialog );
1564 msiobj_release( &view->hdr );
1566 return r;
1569 UINT msi_dialog_reset( msi_dialog *dialog )
1571 /* FIXME: should restore the original values of any properties we changed */
1572 return msi_dialog_evaluate_control_conditions( dialog );
1575 /* figure out the height of 10 point MS Sans Serif */
1576 static INT msi_dialog_get_sans_serif_height( HWND hwnd )
1578 static const WCHAR szSansSerif[] = {
1579 'M','S',' ','S','a','n','s',' ','S','e','r','i','f',0 };
1580 LOGFONTW lf;
1581 TEXTMETRICW tm;
1582 BOOL r;
1583 LONG height = 0;
1584 HFONT hFont, hOldFont;
1585 HDC hdc;
1587 hdc = GetDC( hwnd );
1588 if (hdc)
1590 memset( &lf, 0, sizeof lf );
1591 lf.lfHeight = MulDiv(10, GetDeviceCaps(hdc, LOGPIXELSY), 72);
1592 strcpyW( lf.lfFaceName, szSansSerif );
1593 hFont = CreateFontIndirectW(&lf);
1594 if (hFont)
1596 hOldFont = SelectObject( hdc, hFont );
1597 r = GetTextMetricsW( hdc, &tm );
1598 if (r)
1599 height = tm.tmHeight;
1600 SelectObject( hdc, hOldFont );
1601 DeleteObject( hFont );
1603 ReleaseDC( hwnd, hdc );
1605 return height;
1608 /* fetch the associated record from the Dialog table */
1609 static MSIRECORD *msi_get_dialog_record( msi_dialog *dialog )
1611 static const WCHAR query[] = {
1612 'S','E','L','E','C','T',' ','*',' ',
1613 'F','R','O','M',' ','D','i','a','l','o','g',' ',
1614 'W','H','E','R','E',' ',
1615 '`','D','i','a','l','o','g','`',' ','=',' ','\'','%','s','\'',0};
1616 MSIPACKAGE *package = dialog->package;
1617 MSIRECORD *rec = NULL;
1619 TRACE("%p %s\n", dialog, debugstr_w(dialog->name) );
1621 rec = MSI_QueryGetRecord( package->db, query, dialog->name );
1622 if( !rec )
1623 ERR("query failed for dialog %s\n", debugstr_w(dialog->name));
1625 return rec;
1628 static void msi_dialog_adjust_dialog_size( msi_dialog *dialog, LPSIZE sz )
1630 RECT rect;
1631 LONG style;
1633 /* turn the client size into the window rectangle */
1634 rect.left = 0;
1635 rect.top = 0;
1636 rect.right = msi_dialog_scale_unit( dialog, sz->cx );
1637 rect.bottom = msi_dialog_scale_unit( dialog, sz->cy );
1638 style = GetWindowLongPtrW( dialog->hwnd, GWL_STYLE );
1639 AdjustWindowRect( &rect, style, FALSE );
1640 sz->cx = rect.right - rect.left;
1641 sz->cy = rect.bottom - rect.top;
1644 static BOOL msi_control_set_next( msi_control *control, msi_control *next )
1646 return SetWindowPos( next->hwnd, control->hwnd, 0, 0, 0, 0,
1647 SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOREDRAW |
1648 SWP_NOREPOSITION | SWP_NOSENDCHANGING | SWP_NOSIZE );
1651 static UINT msi_dialog_set_tab_order( msi_dialog *dialog )
1653 msi_control *control, *tab_next;
1655 LIST_FOR_EACH_ENTRY( control, &dialog->controls, msi_control, entry )
1657 tab_next = msi_dialog_find_control( dialog, control->tabnext );
1658 if( !tab_next )
1659 continue;
1660 msi_control_set_next( control, tab_next );
1663 return ERROR_SUCCESS;
1666 static void msi_dialog_set_first_control( msi_dialog* dialog, LPCWSTR name )
1668 msi_control *control;
1670 control = msi_dialog_find_control( dialog, name );
1671 if( control )
1672 dialog->hWndFocus = control->hwnd;
1673 else
1674 dialog->hWndFocus = NULL;
1677 static LRESULT msi_dialog_oncreate( HWND hwnd, LPCREATESTRUCTW cs )
1679 static const WCHAR df[] = {
1680 'D','e','f','a','u','l','t','U','I','F','o','n','t',0 };
1681 static const WCHAR dfv[] = {
1682 'M','S',' ','S','h','e','l','l',' ','D','l','g',0 };
1683 msi_dialog *dialog = (msi_dialog*) cs->lpCreateParams;
1684 MSIRECORD *rec = NULL;
1685 LPWSTR title = NULL;
1686 SIZE size;
1688 TRACE("%p %p\n", dialog, dialog->package);
1690 dialog->hwnd = hwnd;
1691 SetWindowLongPtrW( hwnd, GWLP_USERDATA, (LONG_PTR) dialog );
1693 rec = msi_get_dialog_record( dialog );
1694 if( !rec )
1696 TRACE("No record found for dialog %s\n", debugstr_w(dialog->name));
1697 return -1;
1700 dialog->scale = msi_dialog_get_sans_serif_height(dialog->hwnd);
1702 size.cx = MSI_RecordGetInteger( rec, 4 );
1703 size.cy = MSI_RecordGetInteger( rec, 5 );
1704 msi_dialog_adjust_dialog_size( dialog, &size );
1706 dialog->attributes = MSI_RecordGetInteger( rec, 6 );
1708 dialog->default_font = msi_dup_property( dialog->package, df );
1709 if (!dialog->default_font)
1711 dialog->default_font = strdupW(dfv);
1712 if (!dialog->default_font) return -1;
1715 title = msi_get_deformatted_field( dialog->package, rec, 7 );
1716 SetWindowTextW( hwnd, title );
1717 msi_free( title );
1719 SetWindowPos( hwnd, 0, 0, 0, size.cx, size.cy,
1720 SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOREDRAW );
1723 msi_dialog_build_font_list( dialog );
1724 msi_dialog_fill_controls( dialog );
1725 msi_dialog_evaluate_control_conditions( dialog );
1726 msi_dialog_set_tab_order( dialog );
1727 msi_dialog_set_first_control( dialog, MSI_RecordGetString( rec, 8 ) );
1728 msiobj_release( &rec->hdr );
1730 return 0;
1733 static UINT msi_dialog_send_event( msi_dialog *dialog, LPCWSTR event, LPCWSTR arg )
1735 LPWSTR event_fmt = NULL, arg_fmt = NULL;
1737 TRACE("Sending control event %s %s\n", debugstr_w(event), debugstr_w(arg));
1739 deformat_string( dialog->package, event, &event_fmt );
1740 deformat_string( dialog->package, arg, &arg_fmt );
1742 dialog->event_handler( dialog->package, event_fmt, arg_fmt, dialog );
1744 msi_free( event_fmt );
1745 msi_free( arg_fmt );
1747 return ERROR_SUCCESS;
1750 static UINT msi_dialog_set_property( msi_dialog *dialog, LPCWSTR event, LPCWSTR arg )
1752 static const WCHAR szNullArg[] = { '{','}',0 };
1753 LPWSTR p, prop, arg_fmt = NULL;
1754 UINT len;
1756 len = strlenW(event);
1757 prop = msi_alloc( len*sizeof(WCHAR));
1758 strcpyW( prop, &event[1] );
1759 p = strchrW( prop, ']' );
1760 if( p && p[1] == 0 )
1762 *p = 0;
1763 if( strcmpW( szNullArg, arg ) )
1764 deformat_string( dialog->package, arg, &arg_fmt );
1765 MSI_SetPropertyW( dialog->package, prop, arg_fmt );
1766 msi_free( arg_fmt );
1768 else
1769 ERR("Badly formatted property string - what happens?\n");
1770 msi_free( prop );
1771 return ERROR_SUCCESS;
1774 static UINT msi_dialog_control_event( MSIRECORD *rec, LPVOID param )
1776 msi_dialog *dialog = param;
1777 LPCWSTR condition, event, arg;
1778 UINT r;
1780 condition = MSI_RecordGetString( rec, 5 );
1781 r = MSI_EvaluateConditionW( dialog->package, condition );
1782 if( r == MSICONDITION_TRUE )
1784 event = MSI_RecordGetString( rec, 3 );
1785 arg = MSI_RecordGetString( rec, 4 );
1786 if( event[0] == '[' )
1787 msi_dialog_set_property( dialog, event, arg );
1788 else
1789 msi_dialog_send_event( dialog, event, arg );
1792 return ERROR_SUCCESS;
1795 static UINT msi_dialog_button_handler( msi_dialog *dialog,
1796 msi_control *control, WPARAM param )
1798 static const WCHAR query[] = {
1799 'S','E','L','E','C','T',' ','*',' ',
1800 'F','R','O','M',' ','C','o','n','t','r','o','l','E','v','e','n','t',' ',
1801 'W','H','E','R','E',' ',
1802 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',' ',
1803 'A','N','D',' ',
1804 '`','C','o','n','t','r','o','l','_','`',' ','=',' ','\'','%','s','\'',' ',
1805 'O','R','D','E','R',' ','B','Y',' ','`','O','r','d','e','r','i','n','g','`',0
1807 MSIQUERY *view = NULL;
1808 UINT r;
1810 if( HIWORD(param) != BN_CLICKED )
1811 return ERROR_SUCCESS;
1813 r = MSI_OpenQuery( dialog->package->db, &view, query,
1814 dialog->name, control->name );
1815 if( r != ERROR_SUCCESS )
1817 ERR("query failed\n");
1818 return 0;
1821 r = MSI_IterateRecords( view, 0, msi_dialog_control_event, dialog );
1822 msiobj_release( &view->hdr );
1824 return r;
1827 static UINT msi_dialog_get_checkbox_state( msi_dialog *dialog,
1828 msi_control *control )
1830 WCHAR state[2] = { 0 };
1831 DWORD sz = 2;
1833 MSI_GetPropertyW( dialog->package, control->property, state, &sz );
1834 return state[0] ? 1 : 0;
1837 static void msi_dialog_set_checkbox_state( msi_dialog *dialog,
1838 msi_control *control, UINT state )
1840 static const WCHAR szState[] = { '1', 0 };
1841 LPCWSTR val;
1843 /* if uncheck then the property is set to NULL */
1844 if (!state)
1846 MSI_SetPropertyW( dialog->package, control->property, NULL );
1847 return;
1850 /* check for a custom state */
1851 if (control->value && control->value[0])
1852 val = control->value;
1853 else
1854 val = szState;
1856 MSI_SetPropertyW( dialog->package, control->property, val );
1859 static void msi_dialog_checkbox_sync_state( msi_dialog *dialog,
1860 msi_control *control )
1862 UINT state;
1864 state = msi_dialog_get_checkbox_state( dialog, control );
1865 SendMessageW( control->hwnd, BM_SETCHECK,
1866 state ? BST_CHECKED : BST_UNCHECKED, 0 );
1869 static UINT msi_dialog_checkbox_handler( msi_dialog *dialog,
1870 msi_control *control, WPARAM param )
1872 UINT state;
1874 if( HIWORD(param) != BN_CLICKED )
1875 return ERROR_SUCCESS;
1877 TRACE("clicked checkbox %s, set %s\n", debugstr_w(control->name),
1878 debugstr_w(control->property));
1880 state = msi_dialog_get_checkbox_state( dialog, control );
1881 state = state ? 0 : 1;
1882 msi_dialog_set_checkbox_state( dialog, control, state );
1883 msi_dialog_checkbox_sync_state( dialog, control );
1885 return msi_dialog_button_handler( dialog, control, param );
1888 static UINT msi_dialog_edit_handler( msi_dialog *dialog,
1889 msi_control *control, WPARAM param )
1891 UINT sz, r;
1892 LPWSTR buf;
1894 if( HIWORD(param) != EN_CHANGE )
1895 return ERROR_SUCCESS;
1897 TRACE("edit %s contents changed, set %s\n", debugstr_w(control->name),
1898 debugstr_w(control->property));
1900 sz = 0x20;
1901 buf = msi_alloc( sz*sizeof(WCHAR) );
1902 while( buf )
1904 r = GetWindowTextW( control->hwnd, buf, sz );
1905 if( r < (sz-1) )
1906 break;
1907 sz *= 2;
1908 buf = msi_realloc( buf, sz*sizeof(WCHAR) );
1911 MSI_SetPropertyW( dialog->package, control->property, buf );
1913 msi_free( buf );
1915 return ERROR_SUCCESS;
1918 static UINT msi_dialog_radiogroup_handler( msi_dialog *dialog,
1919 msi_control *control, WPARAM param )
1921 if( HIWORD(param) != BN_CLICKED )
1922 return ERROR_SUCCESS;
1924 TRACE("clicked radio button %s, set %s\n", debugstr_w(control->name),
1925 debugstr_w(control->property));
1927 MSI_SetPropertyW( dialog->package, control->property, control->name );
1929 return msi_dialog_button_handler( dialog, control, param );
1932 static LRESULT msi_dialog_oncommand( msi_dialog *dialog, WPARAM param, HWND hwnd )
1934 msi_control *control = NULL;
1936 TRACE("%p %p %08x\n", dialog, hwnd, param);
1938 switch (param)
1940 case 1: /* enter */
1941 control = msi_dialog_find_control( dialog, dialog->control_default );
1942 break;
1943 case 2: /* escape */
1944 control = msi_dialog_find_control( dialog, dialog->control_cancel );
1945 break;
1946 default:
1947 control = msi_dialog_find_control_by_hwnd( dialog, hwnd );
1950 if( control )
1952 if( control->handler )
1954 control->handler( dialog, control, param );
1955 msi_dialog_evaluate_control_conditions( dialog );
1958 else
1959 ERR("button click from nowhere %p %d %p\n", dialog, param, hwnd);
1960 return 0;
1963 static void msi_dialog_setfocus( msi_dialog *dialog )
1965 HWND hwnd = dialog->hWndFocus;
1967 hwnd = GetNextDlgTabItem( dialog->hwnd, hwnd, TRUE);
1968 hwnd = GetNextDlgTabItem( dialog->hwnd, hwnd, FALSE);
1969 SetFocus( hwnd );
1970 dialog->hWndFocus = hwnd;
1973 static LRESULT WINAPI MSIDialog_WndProc( HWND hwnd, UINT msg,
1974 WPARAM wParam, LPARAM lParam )
1976 msi_dialog *dialog = (LPVOID) GetWindowLongPtrW( hwnd, GWLP_USERDATA );
1978 TRACE("0x%04x\n", msg);
1980 switch (msg)
1982 case WM_CREATE:
1983 return msi_dialog_oncreate( hwnd, (LPCREATESTRUCTW)lParam );
1985 case WM_COMMAND:
1986 return msi_dialog_oncommand( dialog, wParam, (HWND)lParam );
1988 case WM_ACTIVATE:
1989 if( LOWORD(wParam) == WA_INACTIVE )
1990 dialog->hWndFocus = GetFocus();
1991 else
1992 msi_dialog_setfocus( dialog );
1993 return 0;
1995 case WM_SETFOCUS:
1996 msi_dialog_setfocus( dialog );
1997 return 0;
1999 /* bounce back to our subclassed static control */
2000 case WM_CTLCOLORSTATIC:
2001 return SendMessageW( (HWND) lParam, WM_CTLCOLORSTATIC, wParam, lParam );
2003 case WM_DESTROY:
2004 dialog->hwnd = NULL;
2005 return 0;
2007 return DefWindowProcW(hwnd, msg, wParam, lParam);
2010 static LRESULT WINAPI MSIRadioGroup_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
2012 WNDPROC oldproc = (WNDPROC) GetPropW(hWnd, szButtonData);
2014 TRACE("hWnd %p msg %04x wParam 0x%08x lParam 0x%08lx\n", hWnd, msg, wParam, lParam);
2016 if (msg == WM_COMMAND) /* Forward notifications to dialog */
2017 SendMessageW(GetParent(hWnd), msg, wParam, lParam);
2019 return CallWindowProcW(oldproc, hWnd, msg, wParam, lParam);
2022 static LRESULT WINAPI MSIHiddenWindowProc( HWND hwnd, UINT msg,
2023 WPARAM wParam, LPARAM lParam )
2025 msi_dialog *dialog = (msi_dialog*) lParam;
2027 TRACE("%d %p\n", msg, dialog);
2029 switch (msg)
2031 case WM_MSI_DIALOG_CREATE:
2032 return msi_dialog_run_message_loop( dialog );
2033 case WM_MSI_DIALOG_DESTROY:
2034 msi_dialog_destroy( dialog );
2035 return 0;
2037 return DefWindowProcW( hwnd, msg, wParam, lParam );
2040 /* functions that interface to other modules within MSI */
2042 msi_dialog *msi_dialog_create( MSIPACKAGE* package, LPCWSTR szDialogName,
2043 msi_dialog_event_handler event_handler )
2045 MSIRECORD *rec = NULL;
2046 msi_dialog *dialog;
2048 TRACE("%p %s\n", package, debugstr_w(szDialogName));
2050 /* allocate the structure for the dialog to use */
2051 dialog = msi_alloc_zero( sizeof *dialog + sizeof(WCHAR)*strlenW(szDialogName) );
2052 if( !dialog )
2053 return NULL;
2054 strcpyW( dialog->name, szDialogName );
2055 msiobj_addref( &package->hdr );
2056 dialog->package = package;
2057 dialog->event_handler = event_handler;
2058 dialog->finished = 0;
2059 list_init( &dialog->controls );
2061 /* verify that the dialog exists */
2062 rec = msi_get_dialog_record( dialog );
2063 if( !rec )
2065 msiobj_release( &package->hdr );
2066 msi_free( dialog );
2067 return NULL;
2069 dialog->attributes = MSI_RecordGetInteger( rec, 6 );
2070 dialog->control_default = strdupW( MSI_RecordGetString( rec, 9 ) );
2071 dialog->control_cancel = strdupW( MSI_RecordGetString( rec, 10 ) );
2072 msiobj_release( &rec->hdr );
2074 return dialog;
2077 static void msi_process_pending_messages( HWND hdlg )
2079 MSG msg;
2081 while( PeekMessageW( &msg, 0, 0, 0, PM_REMOVE ) )
2083 if( hdlg && IsDialogMessageW( hdlg, &msg ))
2084 continue;
2085 TranslateMessage( &msg );
2086 DispatchMessageW( &msg );
2090 void msi_dialog_end_dialog( msi_dialog *dialog )
2092 TRACE("%p\n", dialog);
2093 dialog->finished = 1;
2094 PostMessageW(dialog->hwnd, WM_NULL, 0, 0);
2097 void msi_dialog_check_messages( HANDLE handle )
2099 DWORD r;
2101 /* in threads other than the UI thread, block */
2102 if( uiThreadId != GetCurrentThreadId() )
2104 if( handle )
2105 WaitForSingleObject( handle, INFINITE );
2106 return;
2109 /* there's two choices for the UI thread */
2110 while (1)
2112 msi_process_pending_messages( NULL );
2114 if( !handle )
2115 break;
2118 * block here until somebody creates a new dialog or
2119 * the handle we're waiting on becomes ready
2121 r = MsgWaitForMultipleObjects( 1, &handle, 0, INFINITE, QS_ALLINPUT );
2122 if( r == WAIT_OBJECT_0 )
2123 break;
2127 UINT msi_dialog_run_message_loop( msi_dialog *dialog )
2129 HWND hwnd;
2131 if( !(dialog->attributes & msidbDialogAttributesVisible) )
2132 return ERROR_SUCCESS;
2134 if( uiThreadId != GetCurrentThreadId() )
2135 return SendMessageW( hMsiHiddenWindow, WM_MSI_DIALOG_CREATE, 0, (LPARAM) dialog );
2137 /* create the dialog window, don't show it yet */
2138 hwnd = CreateWindowW( szMsiDialogClass, dialog->name, WS_OVERLAPPEDWINDOW,
2139 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
2140 NULL, NULL, NULL, dialog );
2141 if( !hwnd )
2143 ERR("Failed to create dialog %s\n", debugstr_w( dialog->name ));
2144 return ERROR_FUNCTION_FAILED;
2147 ShowWindow( hwnd, SW_SHOW );
2148 /* UpdateWindow( hwnd ); - and causes the transparent static controls not to paint */
2150 if( dialog->attributes & msidbDialogAttributesModal )
2152 while( !dialog->finished )
2154 MsgWaitForMultipleObjects( 0, NULL, 0, INFINITE, QS_ALLEVENTS );
2155 msi_process_pending_messages( dialog->hwnd );
2158 else
2159 return ERROR_IO_PENDING;
2161 return ERROR_SUCCESS;
2164 void msi_dialog_do_preview( msi_dialog *dialog )
2166 TRACE("\n");
2167 dialog->attributes |= msidbDialogAttributesVisible;
2168 dialog->attributes &= ~msidbDialogAttributesModal;
2169 msi_dialog_run_message_loop( dialog );
2172 void msi_dialog_destroy( msi_dialog *dialog )
2174 if( uiThreadId != GetCurrentThreadId() )
2176 SendMessageW( hMsiHiddenWindow, WM_MSI_DIALOG_DESTROY, 0, (LPARAM) dialog );
2177 return;
2180 if( dialog->hwnd )
2181 ShowWindow( dialog->hwnd, SW_HIDE );
2183 if( dialog->hwnd )
2184 DestroyWindow( dialog->hwnd );
2186 /* destroy the list of controls */
2187 while( !list_empty( &dialog->controls ) )
2189 msi_control *t = LIST_ENTRY( list_head( &dialog->controls ),
2190 msi_control, entry );
2191 list_remove( &t->entry );
2192 /* leave dialog->hwnd - destroying parent destroys child windows */
2193 msi_free( t->property );
2194 msi_free( t->value );
2195 if( t->hBitmap )
2196 DeleteObject( t->hBitmap );
2197 if( t->hIcon )
2198 DestroyIcon( t->hIcon );
2199 msi_free( t->tabnext );
2200 msi_free( t );
2203 /* destroy the list of fonts */
2204 while( dialog->font_list )
2206 msi_font *t = dialog->font_list;
2207 dialog->font_list = t->next;
2208 DeleteObject( t->hfont );
2209 msi_free( t );
2211 msi_free( dialog->default_font );
2213 msi_free( dialog->control_default );
2214 msi_free( dialog->control_cancel );
2215 msiobj_release( &dialog->package->hdr );
2216 dialog->package = NULL;
2217 msi_free( dialog );
2220 BOOL msi_dialog_register_class( void )
2222 WNDCLASSW cls;
2224 ZeroMemory( &cls, sizeof cls );
2225 cls.lpfnWndProc = MSIDialog_WndProc;
2226 cls.hInstance = NULL;
2227 cls.hIcon = LoadIconW(0, (LPWSTR)IDI_APPLICATION);
2228 cls.hCursor = LoadCursorW(0, (LPWSTR)IDC_ARROW);
2229 cls.hbrBackground = (HBRUSH)(COLOR_3DFACE + 1);
2230 cls.lpszMenuName = NULL;
2231 cls.lpszClassName = szMsiDialogClass;
2233 if( !RegisterClassW( &cls ) )
2234 return FALSE;
2236 cls.lpfnWndProc = MSIHiddenWindowProc;
2237 cls.lpszClassName = szMsiHiddenWindow;
2239 if( !RegisterClassW( &cls ) )
2240 return FALSE;
2242 uiThreadId = GetCurrentThreadId();
2244 hMsiHiddenWindow = CreateWindowW( szMsiHiddenWindow, NULL, WS_OVERLAPPED,
2245 0, 0, 100, 100, NULL, NULL, NULL, NULL );
2246 if( !hMsiHiddenWindow )
2247 return FALSE;
2249 return TRUE;
2252 void msi_dialog_unregister_class( void )
2254 DestroyWindow( hMsiHiddenWindow );
2255 hMsiHiddenWindow = NULL;
2256 UnregisterClassW( szMsiDialogClass, NULL );
2257 UnregisterClassW( szMsiHiddenWindow, NULL );
2258 uiThreadId = 0;