msi: Use the respective update functions when creating the Browse dialog control.
[wine/hacks.git] / dlls / msi / dialog.c
blobdb1e9f5e8517bebd52e857ba127d2fe6180f1cd7
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #define COBJMACROS
22 #define NONAMELESSUNION
23 #define NONAMELESSSTRUCT
25 #include <stdarg.h>
27 #include "windef.h"
28 #include "winbase.h"
29 #include "wingdi.h"
30 #include "winuser.h"
31 #include "winnls.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"
39 #include "winreg.h"
40 #include "shlwapi.h"
42 #include "wine/debug.h"
43 #include "wine/unicode.h"
45 #include "action.h"
47 WINE_DEFAULT_DEBUG_CHANNEL(msi);
50 extern HINSTANCE msi_hInstance;
52 struct msi_control_tag;
53 typedef struct msi_control_tag msi_control;
54 typedef UINT (*msi_handler)( msi_dialog *, msi_control *, WPARAM );
56 struct msi_control_tag
58 struct list entry;
59 HWND hwnd;
60 msi_handler handler;
61 LPWSTR property;
62 LPWSTR value;
63 HBITMAP hBitmap;
64 HICON hIcon;
65 LPWSTR tabnext;
66 HMODULE hDll;
67 float progress_current;
68 float progress_max;
69 DWORD attributes;
70 WCHAR name[1];
73 typedef struct msi_font_tag
75 struct msi_font_tag *next;
76 HFONT hfont;
77 COLORREF color;
78 WCHAR name[1];
79 } msi_font;
81 struct msi_dialog_tag
83 MSIPACKAGE *package;
84 msi_dialog_event_handler event_handler;
85 BOOL finished;
86 INT scale;
87 DWORD attributes;
88 HWND hwnd;
89 LPWSTR default_font;
90 msi_font *font_list;
91 struct list controls;
92 HWND hWndFocus;
93 LPWSTR control_default;
94 LPWSTR control_cancel;
95 WCHAR name[1];
98 typedef UINT (*msi_dialog_control_func)( msi_dialog *dialog, MSIRECORD *rec );
99 struct control_handler
101 LPCWSTR control_type;
102 msi_dialog_control_func func;
105 typedef struct
107 msi_dialog* dialog;
108 msi_control *parent;
109 DWORD attributes;
110 LPWSTR propval;
111 } radio_button_group_descr;
113 static const WCHAR szMsiDialogClass[] = {
114 'M','s','i','D','i','a','l','o','g','C','l','o','s','e','C','l','a','s','s',0
116 static const WCHAR szMsiHiddenWindow[] = {
117 'M','s','i','H','i','d','d','e','n','W','i','n','d','o','w',0 };
118 static const WCHAR szStatic[] = { 'S','t','a','t','i','c',0 };
119 static const WCHAR szButton[] = { 'B','U','T','T','O','N', 0 };
120 static const WCHAR szButtonData[] = { 'M','S','I','D','A','T','A',0 };
121 static const WCHAR szProgress[] = { 'P','r','o','g','r','e','s','s',0 };
122 static const WCHAR szText[] = { 'T','e','x','t',0 };
123 static const WCHAR szPushButton[] = { 'P','u','s','h','B','u','t','t','o','n',0 };
124 static const WCHAR szLine[] = { 'L','i','n','e',0 };
125 static const WCHAR szBitmap[] = { 'B','i','t','m','a','p',0 };
126 static const WCHAR szCheckBox[] = { 'C','h','e','c','k','B','o','x',0 };
127 static const WCHAR szScrollableText[] = {
128 'S','c','r','o','l','l','a','b','l','e','T','e','x','t',0 };
129 static const WCHAR szComboBox[] = { 'C','o','m','b','o','B','o','x',0 };
130 static const WCHAR szEdit[] = { 'E','d','i','t',0 };
131 static const WCHAR szMaskedEdit[] = { 'M','a','s','k','e','d','E','d','i','t',0 };
132 static const WCHAR szPathEdit[] = { 'P','a','t','h','E','d','i','t',0 };
133 static const WCHAR szProgressBar[] = {
134 'P','r','o','g','r','e','s','s','B','a','r',0 };
135 static const WCHAR szRadioButtonGroup[] = {
136 'R','a','d','i','o','B','u','t','t','o','n','G','r','o','u','p',0 };
137 static const WCHAR szIcon[] = { 'I','c','o','n',0 };
138 static const WCHAR szSelectionTree[] = {
139 'S','e','l','e','c','t','i','o','n','T','r','e','e',0 };
140 static const WCHAR szGroupBox[] = { 'G','r','o','u','p','B','o','x',0 };
141 static const WCHAR szListBox[] = { 'L','i','s','t','B','o','x',0 };
142 static const WCHAR szDirectoryCombo[] = { 'D','i','r','e','c','t','o','r','y','C','o','m','b','o',0 };
143 static const WCHAR szDirectoryList[] = { 'D','i','r','e','c','t','o','r','y','L','i','s','t',0 };
144 static const WCHAR szVolumeCostList[] = { 'V','o','l','u','m','e','C','o','s','t','L','i','s','t',0 };
146 static UINT msi_dialog_checkbox_handler( msi_dialog *, msi_control *, WPARAM );
147 static void msi_dialog_checkbox_sync_state( msi_dialog *, msi_control * );
148 static UINT msi_dialog_button_handler( msi_dialog *, msi_control *, WPARAM );
149 static UINT msi_dialog_edit_handler( msi_dialog *, msi_control *, WPARAM );
150 static UINT msi_dialog_radiogroup_handler( msi_dialog *, msi_control *, WPARAM param );
151 static UINT msi_dialog_evaluate_control_conditions( msi_dialog *dialog );
152 static LRESULT WINAPI MSIRadioGroup_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
155 /* dialog sequencing */
157 #define WM_MSI_DIALOG_CREATE (WM_USER+0x100)
158 #define WM_MSI_DIALOG_DESTROY (WM_USER+0x101)
160 static DWORD uiThreadId;
161 static HWND hMsiHiddenWindow;
163 static INT msi_dialog_scale_unit( msi_dialog *dialog, INT val )
165 return (dialog->scale * val + 5) / 10;
168 static msi_control *msi_dialog_find_control( msi_dialog *dialog, LPCWSTR name )
170 msi_control *control;
172 if( !name )
173 return NULL;
174 LIST_FOR_EACH_ENTRY( control, &dialog->controls, msi_control, entry )
175 if( !strcmpW( control->name, name ) ) /* FIXME: case sensitive? */
176 return control;
177 return NULL;
180 static msi_control *msi_dialog_find_control_by_hwnd( msi_dialog *dialog, HWND hwnd )
182 msi_control *control;
184 LIST_FOR_EACH_ENTRY( control, &dialog->controls, msi_control, entry )
185 if( hwnd == control->hwnd )
186 return control;
187 return NULL;
190 static LPWSTR msi_get_deformatted_field( MSIPACKAGE *package, MSIRECORD *rec, int field )
192 LPCWSTR str = MSI_RecordGetString( rec, field );
193 LPWSTR ret = NULL;
195 if (str)
196 deformat_string( package, str, &ret );
197 return ret;
200 static LPWSTR msi_dialog_dup_property( msi_dialog *dialog, LPCWSTR property, BOOL indirect )
202 if (!property)
203 return NULL;
205 if (indirect)
206 return msi_dup_property( dialog->package, property );
208 return strdupW( property );
212 * msi_dialog_get_style
214 * Extract the {\style} string from the front of the text to display and
215 * update the pointer.
217 static LPWSTR msi_dialog_get_style( LPCWSTR p, LPCWSTR *rest )
219 LPWSTR ret = NULL;
220 LPCWSTR q, i;
221 DWORD len;
223 *rest = p;
224 if( !p )
225 return ret;
226 if( *p++ != '{' )
227 return ret;
228 q = strchrW( p, '}' );
229 if( !q )
230 return ret;
231 if( *p == '\\' || *p == '&' )
232 p++;
234 /* little bit of sanity checking to stop us getting confused with RTF */
235 for( i=p; i<q; i++ )
236 if( *i == '}' || *i == '\\' )
237 return ret;
239 *rest = ++q;
240 len = q - p;
242 ret = msi_alloc( len*sizeof(WCHAR) );
243 if( !ret )
244 return ret;
245 memcpy( ret, p, len*sizeof(WCHAR) );
246 ret[len-1] = 0;
247 return ret;
250 static UINT msi_dialog_add_font( MSIRECORD *rec, LPVOID param )
252 msi_dialog *dialog = param;
253 msi_font *font;
254 LPCWSTR face, name;
255 LOGFONTW lf;
256 INT style;
257 HDC hdc;
259 /* create a font and add it to the list */
260 name = MSI_RecordGetString( rec, 1 );
261 font = msi_alloc( sizeof *font + strlenW( name )*sizeof (WCHAR) );
262 strcpyW( font->name, name );
263 font->next = dialog->font_list;
264 dialog->font_list = font;
266 font->color = MSI_RecordGetInteger( rec, 4 );
268 memset( &lf, 0, sizeof lf );
269 face = MSI_RecordGetString( rec, 2 );
270 lf.lfHeight = MSI_RecordGetInteger( rec, 3 );
271 style = MSI_RecordGetInteger( rec, 5 );
272 if( style & msidbTextStyleStyleBitsBold )
273 lf.lfWeight = FW_BOLD;
274 if( style & msidbTextStyleStyleBitsItalic )
275 lf.lfItalic = TRUE;
276 if( style & msidbTextStyleStyleBitsUnderline )
277 lf.lfUnderline = TRUE;
278 if( style & msidbTextStyleStyleBitsStrike )
279 lf.lfStrikeOut = TRUE;
280 lstrcpynW( lf.lfFaceName, face, LF_FACESIZE );
282 /* adjust the height */
283 hdc = GetDC( dialog->hwnd );
284 if (hdc)
286 lf.lfHeight = -MulDiv(lf.lfHeight, GetDeviceCaps(hdc, LOGPIXELSY), 72);
287 ReleaseDC( dialog->hwnd, hdc );
290 font->hfont = CreateFontIndirectW( &lf );
292 TRACE("Adding font style %s\n", debugstr_w(font->name) );
294 return ERROR_SUCCESS;
297 static msi_font *msi_dialog_find_font( msi_dialog *dialog, LPCWSTR name )
299 msi_font *font;
301 for( font = dialog->font_list; font; font = font->next )
302 if( !strcmpW( font->name, name ) ) /* FIXME: case sensitive? */
303 break;
305 return font;
308 static UINT msi_dialog_set_font( msi_dialog *dialog, HWND hwnd, LPCWSTR name )
310 msi_font *font;
312 font = msi_dialog_find_font( dialog, name );
313 if( font )
314 SendMessageW( hwnd, WM_SETFONT, (WPARAM) font->hfont, TRUE );
315 else
316 ERR("No font entry for %s\n", debugstr_w(name));
317 return ERROR_SUCCESS;
320 static UINT msi_dialog_build_font_list( msi_dialog *dialog )
322 static const WCHAR query[] = {
323 'S','E','L','E','C','T',' ','*',' ',
324 'F','R','O','M',' ','`','T','e','x','t','S','t','y','l','e','`',' ',0
326 UINT r;
327 MSIQUERY *view = NULL;
329 TRACE("dialog %p\n", dialog );
331 r = MSI_OpenQuery( dialog->package->db, &view, query );
332 if( r != ERROR_SUCCESS )
333 return r;
335 r = MSI_IterateRecords( view, NULL, msi_dialog_add_font, dialog );
336 msiobj_release( &view->hdr );
338 return r;
341 static msi_control *msi_dialog_create_window( msi_dialog *dialog,
342 MSIRECORD *rec, DWORD exstyle, LPCWSTR szCls, LPCWSTR name, LPCWSTR text,
343 DWORD style, HWND parent )
345 DWORD x, y, width, height;
346 LPWSTR font = NULL, title_font = NULL;
347 LPCWSTR title = NULL;
348 msi_control *control;
350 style |= WS_CHILD;
352 control = msi_alloc( sizeof *control + strlenW(name)*sizeof(WCHAR) );
353 strcpyW( control->name, name );
354 list_add_head( &dialog->controls, &control->entry );
355 control->handler = NULL;
356 control->property = NULL;
357 control->value = NULL;
358 control->hBitmap = NULL;
359 control->hIcon = NULL;
360 control->hDll = NULL;
361 control->tabnext = strdupW( MSI_RecordGetString( rec, 11) );
362 control->progress_current = 0;
363 control->progress_max = 100;
365 x = MSI_RecordGetInteger( rec, 4 );
366 y = MSI_RecordGetInteger( rec, 5 );
367 width = MSI_RecordGetInteger( rec, 6 );
368 height = MSI_RecordGetInteger( rec, 7 );
370 x = msi_dialog_scale_unit( dialog, x );
371 y = msi_dialog_scale_unit( dialog, y );
372 width = msi_dialog_scale_unit( dialog, width );
373 height = msi_dialog_scale_unit( dialog, height );
375 if( text )
377 deformat_string( dialog->package, text, &title_font );
378 font = msi_dialog_get_style( title_font, &title );
381 control->hwnd = CreateWindowExW( exstyle, szCls, title, style,
382 x, y, width, height, parent, NULL, NULL, NULL );
384 TRACE("Dialog %s control %s hwnd %p\n",
385 debugstr_w(dialog->name), debugstr_w(text), control->hwnd );
387 msi_dialog_set_font( dialog, control->hwnd,
388 font ? font : dialog->default_font );
390 msi_free( title_font );
391 msi_free( font );
393 return control;
396 static MSIRECORD *msi_get_binary_record( MSIDATABASE *db, LPCWSTR name )
398 static const WCHAR query[] = {
399 's','e','l','e','c','t',' ','*',' ',
400 'f','r','o','m',' ','B','i','n','a','r','y',' ',
401 'w','h','e','r','e',' ',
402 '`','N','a','m','e','`',' ','=',' ','\'','%','s','\'',0
405 return MSI_QueryGetRecord( db, query, name );
408 static LPWSTR msi_create_tmp_path(void)
410 WCHAR tmp[MAX_PATH];
411 LPWSTR path = NULL;
412 static const WCHAR prefix[] = { 'm','s','i',0 };
413 DWORD len, r;
415 r = GetTempPathW( MAX_PATH, tmp );
416 if( !r )
417 return path;
418 len = lstrlenW( tmp ) + 20;
419 path = msi_alloc( len * sizeof (WCHAR) );
420 if( path )
422 r = GetTempFileNameW( tmp, prefix, 0, path );
423 if (!r)
425 msi_free( path );
426 path = NULL;
429 return path;
433 static HANDLE msi_load_image( MSIDATABASE *db, LPCWSTR name, UINT type,
434 UINT cx, UINT cy, UINT flags )
436 MSIRECORD *rec = NULL;
437 HANDLE himage = NULL;
438 LPWSTR tmp;
439 UINT r;
441 TRACE("%p %s %u %u %08x\n", db, debugstr_w(name), cx, cy, flags);
443 tmp = msi_create_tmp_path();
444 if( !tmp )
445 return himage;
447 rec = msi_get_binary_record( db, name );
448 if( rec )
450 r = MSI_RecordStreamToFile( rec, 2, tmp );
451 if( r == ERROR_SUCCESS )
453 himage = LoadImageW( 0, tmp, type, cx, cy, flags );
454 DeleteFileW( tmp );
456 msiobj_release( &rec->hdr );
459 msi_free( tmp );
460 return himage;
463 static HICON msi_load_icon( MSIDATABASE *db, LPCWSTR text, UINT attributes )
465 DWORD cx = 0, cy = 0, flags;
467 flags = LR_LOADFROMFILE | LR_DEFAULTSIZE;
468 if( attributes & msidbControlAttributesFixedSize )
470 flags &= ~LR_DEFAULTSIZE;
471 if( attributes & msidbControlAttributesIconSize16 )
473 cx += 16;
474 cy += 16;
476 if( attributes & msidbControlAttributesIconSize32 )
478 cx += 32;
479 cy += 32;
481 /* msidbControlAttributesIconSize48 handled by above logic */
483 return msi_load_image( db, text, IMAGE_ICON, cx, cy, flags );
487 /* called from the Control Event subscription code */
488 void msi_dialog_handle_event( msi_dialog* dialog, LPCWSTR control,
489 LPCWSTR attribute, MSIRECORD *rec )
491 msi_control* ctrl;
492 LPCWSTR font_text, text = NULL;
493 LPWSTR font;
495 ctrl = msi_dialog_find_control( dialog, control );
496 if (!ctrl)
497 return;
498 if( !lstrcmpW(attribute, szText) )
500 font_text = MSI_RecordGetString( rec , 1 );
501 font = msi_dialog_get_style( font_text, &text );
502 SetWindowTextW( ctrl->hwnd, text );
503 msi_free( font );
504 msi_dialog_check_messages( NULL );
506 else if( !lstrcmpW(attribute, szProgress) )
508 DWORD func, val;
510 func = MSI_RecordGetInteger( rec , 1 );
511 val = MSI_RecordGetInteger( rec , 2 );
513 switch (func)
515 case 0: /* init */
516 ctrl->progress_max = val;
517 ctrl->progress_current = 0;
518 SendMessageW(ctrl->hwnd, PBM_SETRANGE, 0, MAKELPARAM(0,100));
519 SendMessageW(ctrl->hwnd, PBM_SETPOS, 0, 0);
520 break;
521 case 1: /* FIXME: not sure what this is supposed to do */
522 break;
523 case 2: /* move */
524 ctrl->progress_current += val;
525 SendMessageW(ctrl->hwnd, PBM_SETPOS, 100*(ctrl->progress_current/ctrl->progress_max), 0);
526 break;
527 default:
528 ERR("Unknown progress message %ld\n", func);
529 break;
532 else
534 FIXME("Attribute %s not being set\n", debugstr_w(attribute));
535 return;
539 static void msi_dialog_map_events(msi_dialog* dialog, LPCWSTR control)
541 static const WCHAR Query[] = {
542 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
543 '`','E','v','e','n','t','M','a','p','p','i','n','g','`',' ',
544 'W','H','E','R','E',' ',
545 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',' ',
546 'A','N','D',' ',
547 '`','C','o','n','t','r','o','l','_','`',' ','=',' ','\'','%','s','\'',0
549 MSIRECORD *row;
550 LPCWSTR event, attribute;
552 row = MSI_QueryGetRecord( dialog->package->db, Query, dialog->name, control );
553 if (!row)
554 return;
556 event = MSI_RecordGetString( row, 3 );
557 attribute = MSI_RecordGetString( row, 4 );
558 ControlEvent_SubscribeToEvent( dialog->package, event, control, attribute );
559 msiobj_release( &row->hdr );
562 /* everything except radio buttons */
563 static msi_control *msi_dialog_add_control( msi_dialog *dialog,
564 MSIRECORD *rec, LPCWSTR szCls, DWORD style )
566 DWORD attributes;
567 LPCWSTR text, name;
568 DWORD exstyle = 0;
570 name = MSI_RecordGetString( rec, 2 );
571 attributes = MSI_RecordGetInteger( rec, 8 );
572 text = MSI_RecordGetString( rec, 10 );
573 if( attributes & msidbControlAttributesVisible )
574 style |= WS_VISIBLE;
575 if( ~attributes & msidbControlAttributesEnabled )
576 style |= WS_DISABLED;
577 if( attributes & msidbControlAttributesSunken )
578 exstyle |= WS_EX_CLIENTEDGE;
580 msi_dialog_map_events(dialog, name);
582 return msi_dialog_create_window( dialog, rec, exstyle, szCls, name,
583 text, style, dialog->hwnd );
586 struct msi_text_info
588 msi_font *font;
589 WNDPROC oldproc;
590 DWORD attributes;
594 * we don't erase our own background,
595 * so we have to make sure that the parent window redraws first
597 static void msi_text_on_settext( HWND hWnd )
599 HWND hParent;
600 RECT rc;
602 hParent = GetParent( hWnd );
603 GetWindowRect( hWnd, &rc );
604 MapWindowPoints( NULL, hParent, (LPPOINT) &rc, 2 );
605 InvalidateRect( hParent, &rc, TRUE );
608 static LRESULT WINAPI
609 MSIText_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
611 struct msi_text_info *info;
612 LRESULT r = 0;
614 TRACE("%p %04x %08x %08lx\n", hWnd, msg, wParam, lParam);
616 info = GetPropW(hWnd, szButtonData);
618 if ( info->font )
619 SetTextColor( (HDC)wParam, info->font->color );
621 if( msg == WM_CTLCOLORSTATIC &&
622 ( info->attributes & msidbControlAttributesTransparent ) )
624 SetBkMode( (HDC)wParam, TRANSPARENT );
625 return (LRESULT) GetStockObject(NULL_BRUSH);
628 r = CallWindowProcW(info->oldproc, hWnd, msg, wParam, lParam);
630 switch( msg )
632 case WM_SETTEXT:
633 msi_text_on_settext( hWnd );
634 break;
635 case WM_NCDESTROY:
636 msi_free( info );
637 RemovePropW( hWnd, szButtonData );
638 break;
641 return r;
644 static UINT msi_dialog_text_control( msi_dialog *dialog, MSIRECORD *rec )
646 msi_control *control;
647 struct msi_text_info *info;
648 LPCWSTR text, ptr;
649 LPWSTR font_name;
651 TRACE("%p %p\n", dialog, rec);
653 control = msi_dialog_add_control( dialog, rec, szStatic, SS_LEFT | WS_GROUP );
654 if( !control )
655 return ERROR_FUNCTION_FAILED;
657 info = msi_alloc( sizeof *info );
658 if( !info )
659 return ERROR_SUCCESS;
661 text = MSI_RecordGetString( rec, 10 );
662 font_name = msi_dialog_get_style( text, &ptr );
663 info->font = ( font_name ) ? msi_dialog_find_font( dialog, font_name ) : NULL;
664 msi_free( font_name );
666 info->attributes = MSI_RecordGetInteger( rec, 8 );
667 if( info->attributes & msidbControlAttributesTransparent )
668 SetWindowLongPtrW( control->hwnd, GWL_EXSTYLE, WS_EX_TRANSPARENT );
670 info->oldproc = (WNDPROC) SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
671 (LONG_PTR)MSIText_WndProc );
672 SetPropW( control->hwnd, szButtonData, info );
674 return ERROR_SUCCESS;
677 static UINT msi_dialog_button_control( msi_dialog *dialog, MSIRECORD *rec )
679 msi_control *control;
680 UINT attributes, style;
681 LPWSTR text;
683 TRACE("%p %p\n", dialog, rec);
685 style = WS_TABSTOP;
686 attributes = MSI_RecordGetInteger( rec, 8 );
687 if( attributes & msidbControlAttributesIcon )
688 style |= BS_ICON;
690 control = msi_dialog_add_control( dialog, rec, szButton, style );
691 if( !control )
692 return ERROR_FUNCTION_FAILED;
694 control->handler = msi_dialog_button_handler;
696 /* set the icon */
697 text = msi_get_deformatted_field( dialog->package, rec, 10 );
698 control->hIcon = msi_load_icon( dialog->package->db, text, attributes );
699 if( attributes & msidbControlAttributesIcon )
700 SendMessageW( control->hwnd, BM_SETIMAGE, IMAGE_ICON, (LPARAM) control->hIcon );
701 msi_free( text );
703 return ERROR_SUCCESS;
706 static LPWSTR msi_get_checkbox_value( msi_dialog *dialog, LPCWSTR prop )
708 static const WCHAR query[] = {
709 'S','E','L','E','C','T',' ','*',' ',
710 'F','R','O','M',' ','`','C','h','e','c','k','B','o','x',' ','`',
711 'W','H','E','R','E',' ',
712 '`','P','r','o','p','e','r','t','y','`',' ','=',' ',
713 '\'','%','s','\'',0
715 MSIRECORD *rec = NULL;
716 LPWSTR ret = NULL;
718 /* find if there is a value associated with the checkbox */
719 rec = MSI_QueryGetRecord( dialog->package->db, query, prop );
720 if (!rec)
721 return ret;
723 ret = msi_get_deformatted_field( dialog->package, rec, 2 );
724 if( ret && !ret[0] )
726 msi_free( ret );
727 ret = NULL;
729 msiobj_release( &rec->hdr );
730 if (ret)
731 return ret;
733 ret = msi_dup_property( dialog->package, prop );
734 if( ret && !ret[0] )
736 msi_free( ret );
737 ret = NULL;
740 return ret;
743 static UINT msi_dialog_checkbox_control( msi_dialog *dialog, MSIRECORD *rec )
745 msi_control *control;
746 LPCWSTR prop;
748 TRACE("%p %p\n", dialog, rec);
750 control = msi_dialog_add_control( dialog, rec, szButton,
751 BS_CHECKBOX | BS_MULTILINE | WS_TABSTOP );
752 control->handler = msi_dialog_checkbox_handler;
753 prop = MSI_RecordGetString( rec, 9 );
754 if( prop )
756 control->property = strdupW( prop );
757 control->value = msi_get_checkbox_value( dialog, prop );
758 TRACE("control %s value %s\n", debugstr_w(control->property),
759 debugstr_w(control->value));
761 msi_dialog_checkbox_sync_state( dialog, control );
763 return ERROR_SUCCESS;
766 static UINT msi_dialog_line_control( msi_dialog *dialog, MSIRECORD *rec )
768 TRACE("%p %p\n", dialog, rec);
770 /* line is exactly 2 units in height */
771 MSI_RecordSetInteger( rec, 7, 2 );
773 msi_dialog_add_control( dialog, rec, szStatic, SS_ETCHEDHORZ | SS_SUNKEN );
774 return ERROR_SUCCESS;
777 /******************** Scroll Text ********************************************/
779 struct msi_scrolltext_info
781 msi_dialog *dialog;
782 msi_control *control;
783 WNDPROC oldproc;
786 static LRESULT WINAPI
787 MSIScrollText_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
789 struct msi_scrolltext_info *info;
790 HRESULT r;
792 TRACE("%p %04x %08x %08lx\n", hWnd, msg, wParam, lParam);
794 info = GetPropW( hWnd, szButtonData );
796 r = CallWindowProcW( info->oldproc, hWnd, msg, wParam, lParam );
798 switch( msg )
800 case WM_NCDESTROY:
801 msi_free( info );
802 RemovePropW( hWnd, szButtonData );
803 break;
804 case WM_PAINT:
805 /* native MSI sets a wait cursor here */
806 msi_dialog_button_handler( info->dialog, info->control, BN_CLICKED );
807 break;
809 return r;
812 struct msi_streamin_info
814 LPSTR string;
815 DWORD offset;
816 DWORD length;
819 static DWORD CALLBACK
820 msi_richedit_stream_in( DWORD_PTR arg, LPBYTE buffer, LONG count, LONG *pcb )
822 struct msi_streamin_info *info = (struct msi_streamin_info*) arg;
824 if( (count + info->offset) > info->length )
825 count = info->length - info->offset;
826 memcpy( buffer, &info->string[ info->offset ], count );
827 *pcb = count;
828 info->offset += count;
830 TRACE("%ld/%ld\n", info->offset, info->length);
832 return 0;
835 static void msi_scrolltext_add_text( msi_control *control, LPCWSTR text )
837 struct msi_streamin_info info;
838 EDITSTREAM es;
840 info.string = strdupWtoA( text );
841 info.offset = 0;
842 info.length = lstrlenA( info.string ) + 1;
844 es.dwCookie = (DWORD_PTR) &info;
845 es.dwError = 0;
846 es.pfnCallback = msi_richedit_stream_in;
848 SendMessageW( control->hwnd, EM_STREAMIN, SF_RTF, (LPARAM) &es );
850 msi_free( info.string );
853 static UINT msi_dialog_scrolltext_control( msi_dialog *dialog, MSIRECORD *rec )
855 static const WCHAR szRichEdit20W[] = {
856 'R','i','c','h','E','d','i','t','2','0','W',0
858 struct msi_scrolltext_info *info;
859 msi_control *control;
860 HMODULE hRichedit;
861 DWORD style;
863 info = msi_alloc( sizeof *info );
864 if (!info)
865 return ERROR_FUNCTION_FAILED;
867 hRichedit = LoadLibraryA("riched20");
869 style = WS_BORDER | ES_MULTILINE | WS_VSCROLL |
870 ES_READONLY | ES_AUTOVSCROLL | WS_TABSTOP;
871 control = msi_dialog_add_control( dialog, rec, szRichEdit20W, style );
872 if (!control)
874 FreeLibrary( hRichedit );
875 msi_free( info );
876 return ERROR_FUNCTION_FAILED;
879 control->hDll = hRichedit;
881 info->dialog = dialog;
882 info->control = control;
884 /* subclass the static control */
885 info->oldproc = (WNDPROC) SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
886 (LONG_PTR)MSIScrollText_WndProc );
887 SetPropW( control->hwnd, szButtonData, info );
889 /* add the text into the richedit */
890 msi_scrolltext_add_text( control, MSI_RecordGetString( rec, 10 ) );
892 return ERROR_SUCCESS;
895 static HBITMAP msi_load_picture( MSIDATABASE *db, LPCWSTR name,
896 INT cx, INT cy, DWORD flags )
898 HBITMAP hOleBitmap = 0, hBitmap = 0, hOldSrcBitmap, hOldDestBitmap;
899 MSIRECORD *rec = NULL;
900 IStream *stm = NULL;
901 IPicture *pic = NULL;
902 HDC srcdc, destdc;
903 BITMAP bm;
904 UINT r;
906 rec = msi_get_binary_record( db, name );
907 if( !rec )
908 goto end;
910 r = MSI_RecordGetIStream( rec, 2, &stm );
911 msiobj_release( &rec->hdr );
912 if( r != ERROR_SUCCESS )
913 goto end;
915 r = OleLoadPicture( stm, 0, TRUE, &IID_IPicture, (LPVOID*) &pic );
916 IStream_Release( stm );
917 if( FAILED( r ) )
919 ERR("failed to load picture\n");
920 goto end;
923 r = IPicture_get_Handle( pic, (OLE_HANDLE*) &hOleBitmap );
924 if( FAILED( r ) )
926 ERR("failed to get bitmap handle\n");
927 goto end;
930 /* make the bitmap the desired size */
931 r = GetObjectW( hOleBitmap, sizeof bm, &bm );
932 if (r != sizeof bm )
934 ERR("failed to get bitmap size\n");
935 goto end;
938 if (flags & LR_DEFAULTSIZE)
940 cx = bm.bmWidth;
941 cy = bm.bmHeight;
944 srcdc = CreateCompatibleDC( NULL );
945 hOldSrcBitmap = SelectObject( srcdc, hOleBitmap );
946 destdc = CreateCompatibleDC( NULL );
947 hBitmap = CreateCompatibleBitmap( srcdc, cx, cy );
948 hOldDestBitmap = SelectObject( destdc, hBitmap );
949 StretchBlt( destdc, 0, 0, cx, cy,
950 srcdc, 0, 0, bm.bmWidth, bm.bmHeight, SRCCOPY);
951 SelectObject( srcdc, hOldSrcBitmap );
952 SelectObject( destdc, hOldDestBitmap );
953 DeleteDC( srcdc );
954 DeleteDC( destdc );
956 end:
957 if ( pic )
958 IPicture_Release( pic );
959 return hBitmap;
962 static UINT msi_dialog_bitmap_control( msi_dialog *dialog, MSIRECORD *rec )
964 UINT cx, cy, flags, style, attributes;
965 msi_control *control;
966 LPWSTR text;
968 flags = LR_LOADFROMFILE;
969 style = SS_BITMAP | SS_LEFT | WS_GROUP;
971 attributes = MSI_RecordGetInteger( rec, 8 );
972 if( attributes & msidbControlAttributesFixedSize )
974 flags |= LR_DEFAULTSIZE;
975 style |= SS_CENTERIMAGE;
978 control = msi_dialog_add_control( dialog, rec, szStatic, style );
979 cx = MSI_RecordGetInteger( rec, 6 );
980 cy = MSI_RecordGetInteger( rec, 7 );
981 cx = msi_dialog_scale_unit( dialog, cx );
982 cy = msi_dialog_scale_unit( dialog, cy );
984 text = msi_get_deformatted_field( dialog->package, rec, 10 );
985 control->hBitmap = msi_load_picture( dialog->package->db, text, cx, cy, flags );
986 if( control->hBitmap )
987 SendMessageW( control->hwnd, STM_SETIMAGE,
988 IMAGE_BITMAP, (LPARAM) control->hBitmap );
989 else
990 ERR("Failed to load bitmap %s\n", debugstr_w(text));
992 msi_free( text );
994 return ERROR_SUCCESS;
997 static UINT msi_dialog_icon_control( msi_dialog *dialog, MSIRECORD *rec )
999 msi_control *control;
1000 DWORD attributes;
1001 LPWSTR text;
1003 TRACE("\n");
1005 control = msi_dialog_add_control( dialog, rec, szStatic,
1006 SS_ICON | SS_CENTERIMAGE | WS_GROUP );
1008 attributes = MSI_RecordGetInteger( rec, 8 );
1009 text = msi_get_deformatted_field( dialog->package, rec, 10 );
1010 control->hIcon = msi_load_icon( dialog->package->db, text, attributes );
1011 if( control->hIcon )
1012 SendMessageW( control->hwnd, STM_SETICON, (WPARAM) control->hIcon, 0 );
1013 else
1014 ERR("Failed to load bitmap %s\n", debugstr_w(text));
1015 msi_free( text );
1016 return ERROR_SUCCESS;
1019 static UINT msi_dialog_combo_control( msi_dialog *dialog, MSIRECORD *rec )
1021 static const WCHAR szCombo[] = { 'C','O','M','B','O','B','O','X',0 };
1023 msi_dialog_add_control( dialog, rec, szCombo,
1024 SS_BITMAP | SS_LEFT | SS_CENTERIMAGE );
1025 return ERROR_SUCCESS;
1028 static UINT msi_dialog_edit_control( msi_dialog *dialog, MSIRECORD *rec )
1030 msi_control *control;
1031 LPCWSTR prop;
1032 LPWSTR val;
1034 control = msi_dialog_add_control( dialog, rec, szEdit,
1035 WS_BORDER | WS_TABSTOP );
1036 control->handler = msi_dialog_edit_handler;
1037 prop = MSI_RecordGetString( rec, 9 );
1038 if( prop )
1039 control->property = strdupW( prop );
1040 val = msi_dup_property( dialog->package, control->property );
1041 SetWindowTextW( control->hwnd, val );
1042 msi_free( val );
1043 return ERROR_SUCCESS;
1046 /******************** Masked Edit ********************************************/
1048 #define MASK_MAX_GROUPS 10
1050 struct msi_mask_group
1052 UINT len;
1053 UINT ofs;
1054 WCHAR type;
1055 HWND hwnd;
1058 struct msi_maskedit_info
1060 msi_dialog *dialog;
1061 WNDPROC oldproc;
1062 HWND hwnd;
1063 LPWSTR prop;
1064 UINT num_chars;
1065 UINT num_groups;
1066 struct msi_mask_group group[MASK_MAX_GROUPS];
1069 static BOOL msi_mask_editable( WCHAR type )
1071 switch (type)
1073 case '%':
1074 case '#':
1075 case '&':
1076 case '`':
1077 case '?':
1078 case '^':
1079 return TRUE;
1081 return FALSE;
1084 static void msi_mask_control_change( struct msi_maskedit_info *info )
1086 LPWSTR val;
1087 UINT i, n, r;
1089 val = msi_alloc( (info->num_chars+1)*sizeof(WCHAR) );
1090 for( i=0, n=0; i<info->num_groups; i++ )
1092 if( (info->group[i].len + n) > info->num_chars )
1094 ERR("can't fit control %d text into template\n",i);
1095 break;
1097 if (!msi_mask_editable(info->group[i].type))
1099 for(r=0; r<info->group[i].len; r++)
1100 val[n+r] = info->group[i].type;
1101 val[n+r] = 0;
1103 else
1105 r = GetWindowTextW( info->group[i].hwnd, &val[n], info->group[i].len+1 );
1106 if( r != info->group[i].len )
1107 break;
1109 n += r;
1112 TRACE("%d/%d controls were good\n", i, info->num_groups);
1114 if( i == info->num_groups )
1116 TRACE("Set property %s to %s\n",
1117 debugstr_w(info->prop), debugstr_w(val) );
1118 CharUpperBuffW( val, info->num_chars );
1119 MSI_SetPropertyW( info->dialog->package, info->prop, val );
1120 msi_dialog_evaluate_control_conditions( info->dialog );
1122 msi_free( val );
1125 /* now move to the next control if necessary */
1126 static VOID msi_mask_next_control( struct msi_maskedit_info *info, HWND hWnd )
1128 HWND hWndNext;
1129 UINT len, i;
1131 for( i=0; i<info->num_groups; i++ )
1132 if( info->group[i].hwnd == hWnd )
1133 break;
1135 /* don't move from the last control */
1136 if( i >= (info->num_groups-1) )
1137 return;
1139 len = SendMessageW( hWnd, WM_GETTEXTLENGTH, 0, 0 );
1140 if( len < info->group[i].len )
1141 return;
1143 hWndNext = GetNextDlgTabItem( GetParent( hWnd ), hWnd, FALSE );
1144 SetFocus( hWndNext );
1147 static LRESULT WINAPI
1148 MSIMaskedEdit_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
1150 struct msi_maskedit_info *info;
1151 HRESULT r;
1153 TRACE("%p %04x %08x %08lx\n", hWnd, msg, wParam, lParam);
1155 info = GetPropW(hWnd, szButtonData);
1157 r = CallWindowProcW(info->oldproc, hWnd, msg, wParam, lParam);
1159 switch( msg )
1161 case WM_COMMAND:
1162 if (HIWORD(wParam) == EN_CHANGE)
1164 msi_mask_control_change( info );
1165 msi_mask_next_control( info, (HWND) lParam );
1167 break;
1168 case WM_NCDESTROY:
1169 msi_free( info->prop );
1170 msi_free( info );
1171 RemovePropW( hWnd, szButtonData );
1172 break;
1175 return r;
1178 /* fish the various bits of the property out and put them in the control */
1179 static void
1180 msi_maskedit_set_text( struct msi_maskedit_info *info, LPCWSTR text )
1182 LPCWSTR p;
1183 UINT i;
1185 p = text;
1186 for( i = 0; i < info->num_groups; i++ )
1188 if( info->group[i].len < lstrlenW( p ) )
1190 LPWSTR chunk = strdupW( p );
1191 chunk[ info->group[i].len ] = 0;
1192 SetWindowTextW( info->group[i].hwnd, chunk );
1193 msi_free( chunk );
1195 else
1197 SetWindowTextW( info->group[i].hwnd, p );
1198 break;
1200 p += info->group[i].len;
1204 static struct msi_maskedit_info * msi_dialog_parse_groups( LPCWSTR mask )
1206 struct msi_maskedit_info * info = NULL;
1207 int i = 0, n = 0, total = 0;
1208 LPCWSTR p;
1210 TRACE("masked control, template %s\n", debugstr_w(mask));
1212 if( !mask )
1213 return info;
1215 info = msi_alloc_zero( sizeof *info );
1216 if( !info )
1217 return info;
1219 p = strchrW(mask, '<');
1220 if( p )
1221 p++;
1222 else
1223 p = mask;
1225 for( i=0; i<MASK_MAX_GROUPS; i++ )
1227 /* stop at the end of the string */
1228 if( p[0] == 0 || p[0] == '>' )
1229 break;
1231 /* count the number of the same identifier */
1232 for( n=0; p[n] == p[0]; n++ )
1234 info->group[i].ofs = total;
1235 info->group[i].type = p[0];
1236 if( p[n] == '=' )
1238 n++;
1239 total++; /* an extra not part of the group */
1241 info->group[i].len = n;
1242 total += n;
1243 p += n;
1246 TRACE("%d characters in %d groups\n", total, i );
1247 if( i == MASK_MAX_GROUPS )
1248 ERR("too many groups in PIDTemplate %s\n", debugstr_w(mask));
1250 info->num_chars = total;
1251 info->num_groups = i;
1253 return info;
1256 static void
1257 msi_maskedit_create_children( struct msi_maskedit_info *info, LPCWSTR font )
1259 DWORD width, height, style, wx, ww;
1260 RECT rect;
1261 HWND hwnd;
1262 UINT i;
1264 style = WS_CHILD | WS_BORDER | WS_VISIBLE | WS_TABSTOP | ES_AUTOHSCROLL;
1266 GetClientRect( info->hwnd, &rect );
1268 width = rect.right - rect.left;
1269 height = rect.bottom - rect.top;
1271 for( i = 0; i < info->num_groups; i++ )
1273 if (!msi_mask_editable( info->group[i].type ))
1274 continue;
1275 wx = (info->group[i].ofs * width) / info->num_chars;
1276 ww = (info->group[i].len * width) / info->num_chars;
1278 hwnd = CreateWindowW( szEdit, NULL, style, wx, 0, ww, height,
1279 info->hwnd, NULL, NULL, NULL );
1280 if( !hwnd )
1282 ERR("failed to create mask edit sub window\n");
1283 break;
1286 SendMessageW( hwnd, EM_LIMITTEXT, info->group[i].len, 0 );
1288 msi_dialog_set_font( info->dialog, hwnd,
1289 font?font:info->dialog->default_font );
1290 info->group[i].hwnd = hwnd;
1295 * office 2003 uses "73931<````=````=````=````=`````>@@@@@"
1296 * delphi 7 uses "<????-??????-??????-????>" and "<???-???>"
1297 * filemaker pro 7 uses "<^^^^=^^^^=^^^^=^^^^=^^^^=^^^^=^^^^^>"
1299 static UINT msi_dialog_maskedit_control( msi_dialog *dialog, MSIRECORD *rec )
1301 LPWSTR font_mask, val = NULL, font;
1302 struct msi_maskedit_info *info = NULL;
1303 UINT ret = ERROR_SUCCESS;
1304 msi_control *control;
1305 LPCWSTR prop, mask;
1307 TRACE("\n");
1309 font_mask = msi_get_deformatted_field( dialog->package, rec, 10 );
1310 font = msi_dialog_get_style( font_mask, &mask );
1311 if( !mask )
1313 ERR("mask template is empty\n");
1314 goto end;
1317 info = msi_dialog_parse_groups( mask );
1318 if( !info )
1320 ERR("template %s is invalid\n", debugstr_w(mask));
1321 goto end;
1324 info->dialog = dialog;
1326 control = msi_dialog_add_control( dialog, rec, szStatic,
1327 SS_OWNERDRAW | WS_GROUP | WS_VISIBLE );
1328 if( !control )
1330 ERR("Failed to create maskedit container\n");
1331 ret = ERROR_FUNCTION_FAILED;
1332 goto end;
1334 SetWindowLongPtrW( control->hwnd, GWL_EXSTYLE, WS_EX_CONTROLPARENT );
1336 info->hwnd = control->hwnd;
1338 /* subclass the static control */
1339 info->oldproc = (WNDPROC) SetWindowLongPtrW( info->hwnd, GWLP_WNDPROC,
1340 (LONG_PTR)MSIMaskedEdit_WndProc );
1341 SetPropW( control->hwnd, szButtonData, info );
1343 prop = MSI_RecordGetString( rec, 9 );
1344 if( prop )
1345 info->prop = strdupW( prop );
1347 msi_maskedit_create_children( info, font );
1349 if( prop )
1351 val = msi_dup_property( dialog->package, prop );
1352 if( val )
1354 msi_maskedit_set_text( info, val );
1355 msi_free( val );
1359 end:
1360 if( ret != ERROR_SUCCESS )
1361 msi_free( info );
1362 msi_free( font_mask );
1363 msi_free( font );
1364 return ret;
1367 /******************** Progress Bar *****************************************/
1369 static UINT msi_dialog_progress_bar( msi_dialog *dialog, MSIRECORD *rec )
1371 msi_dialog_add_control( dialog, rec, PROGRESS_CLASSW, WS_VISIBLE );
1372 return ERROR_SUCCESS;
1375 /******************** Path Edit ********************************************/
1377 static LPWSTR msi_get_window_text( HWND hwnd )
1379 UINT sz, r;
1380 LPWSTR buf;
1382 sz = 0x20;
1383 buf = msi_alloc( sz*sizeof(WCHAR) );
1384 while ( buf )
1386 r = GetWindowTextW( hwnd, buf, sz );
1387 if ( r < (sz - 1) )
1388 break;
1389 sz *= 2;
1390 buf = msi_realloc( buf, sz*sizeof(WCHAR) );
1393 return buf;
1396 static UINT msi_dialog_pathedit_handler( msi_dialog *dialog,
1397 msi_control *control, WPARAM param )
1399 LPCWSTR prop;
1400 LPWSTR buf, indirect = NULL;
1402 if( HIWORD(param) != EN_KILLFOCUS )
1403 return ERROR_SUCCESS;
1405 prop = control->property;
1406 if ( control->attributes & msidbControlAttributesIndirect )
1408 indirect = msi_dup_property( dialog->package, control->property );
1409 prop = indirect;
1412 /* FIXME: verify the new path */
1413 buf = msi_get_window_text( control->hwnd );
1414 MSI_SetPropertyW( dialog->package, prop, buf );
1416 TRACE("edit %s contents changed, set %s\n", debugstr_w(control->name),
1417 debugstr_w(prop));
1419 msi_free( buf );
1420 msi_free( indirect );
1422 return ERROR_SUCCESS;
1425 static void msi_dialog_update_pathedit( msi_dialog *dialog )
1427 msi_control *control;
1428 LPWSTR prop, path;
1429 BOOL indirect;
1431 control = msi_dialog_find_control( dialog, szPathEdit );
1432 indirect = control->attributes & msidbControlAttributesIndirect;
1433 prop = msi_dialog_dup_property( dialog, control->property, indirect );
1435 path = msi_dup_property( dialog->package, prop );
1436 SetWindowTextW( control->hwnd, path );
1437 SendMessageW( control->hwnd, EM_SETSEL, 0, -1 );
1439 msi_free( path );
1440 msi_free( prop );
1443 static UINT msi_dialog_pathedit_control( msi_dialog *dialog, MSIRECORD *rec )
1445 msi_control *control;
1446 LPCWSTR prop;
1448 control = msi_dialog_add_control( dialog, rec, szEdit,
1449 WS_BORDER | WS_TABSTOP );
1450 control->handler = msi_dialog_pathedit_handler;
1451 control->attributes = MSI_RecordGetInteger( rec, 8 );
1453 prop = MSI_RecordGetString( rec, 9 );
1454 if ( prop )
1455 control->property = strdupW( prop );
1457 msi_dialog_update_pathedit( dialog );
1459 return ERROR_SUCCESS;
1462 /* radio buttons are a bit different from normal controls */
1463 static UINT msi_dialog_create_radiobutton( MSIRECORD *rec, LPVOID param )
1465 radio_button_group_descr *group = (radio_button_group_descr *)param;
1466 msi_dialog *dialog = group->dialog;
1467 msi_control *control;
1468 LPCWSTR prop, text, name;
1469 DWORD style, attributes = group->attributes;
1471 style = WS_CHILD | BS_AUTORADIOBUTTON | BS_MULTILINE | WS_TABSTOP;
1472 name = MSI_RecordGetString( rec, 3 );
1473 text = MSI_RecordGetString( rec, 8 );
1474 if( attributes & 1 )
1475 style |= WS_VISIBLE;
1476 if( ~attributes & 2 )
1477 style |= WS_DISABLED;
1479 control = msi_dialog_create_window( dialog, rec, 0, szButton, name, text,
1480 style, group->parent->hwnd );
1481 if (!control)
1482 return ERROR_FUNCTION_FAILED;
1483 control->handler = msi_dialog_radiogroup_handler;
1485 if (!lstrcmpW(control->name, group->propval))
1486 SendMessageW(control->hwnd, BM_SETCHECK, BST_CHECKED, 0);
1488 prop = MSI_RecordGetString( rec, 1 );
1489 if( prop )
1490 control->property = strdupW( prop );
1492 return ERROR_SUCCESS;
1495 static UINT msi_dialog_radiogroup_control( msi_dialog *dialog, MSIRECORD *rec )
1497 static const WCHAR query[] = {
1498 'S','E','L','E','C','T',' ','*',' ',
1499 'F','R','O','M',' ','R','a','d','i','o','B','u','t','t','o','n',' ',
1500 'W','H','E','R','E',' ',
1501 '`','P','r','o','p','e','r','t','y','`',' ','=',' ','\'','%','s','\'',0};
1502 UINT r;
1503 LPCWSTR prop;
1504 msi_control *control;
1505 MSIQUERY *view = NULL;
1506 radio_button_group_descr group;
1507 MSIPACKAGE *package = dialog->package;
1508 WNDPROC oldproc;
1510 prop = MSI_RecordGetString( rec, 9 );
1512 TRACE("%p %p %s\n", dialog, rec, debugstr_w( prop ));
1514 /* Create parent group box to hold radio buttons */
1515 control = msi_dialog_add_control( dialog, rec, szButton, BS_OWNERDRAW|WS_GROUP );
1516 if( !control )
1517 return ERROR_FUNCTION_FAILED;
1519 oldproc = (WNDPROC) SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
1520 (LONG_PTR)MSIRadioGroup_WndProc );
1521 SetPropW(control->hwnd, szButtonData, oldproc);
1522 SetWindowLongPtrW( control->hwnd, GWL_EXSTYLE, WS_EX_CONTROLPARENT );
1524 if( prop )
1525 control->property = strdupW( prop );
1527 /* query the Radio Button table for all control in this group */
1528 r = MSI_OpenQuery( package->db, &view, query, prop );
1529 if( r != ERROR_SUCCESS )
1531 ERR("query failed for dialog %s radio group %s\n",
1532 debugstr_w(dialog->name), debugstr_w(prop));
1533 return ERROR_INVALID_PARAMETER;
1536 group.dialog = dialog;
1537 group.parent = control;
1538 group.attributes = MSI_RecordGetInteger( rec, 8 );
1539 group.propval = msi_dup_property( dialog->package, control->property );
1541 r = MSI_IterateRecords( view, 0, msi_dialog_create_radiobutton, &group );
1542 msiobj_release( &view->hdr );
1543 msi_free( group.propval );
1545 return r;
1548 /******************** Selection Tree ***************************************/
1550 struct msi_selection_tree_info
1552 msi_dialog *dialog;
1553 HWND hwnd;
1554 WNDPROC oldproc;
1557 static void
1558 msi_seltree_sync_item_state( HWND hwnd, MSIFEATURE *feature, HTREEITEM hItem )
1560 TVITEMW tvi;
1562 TRACE("Feature %s -> %d %d %d\n", debugstr_w(feature->Title),
1563 feature->Installed, feature->Action, feature->ActionRequest);
1565 tvi.mask = TVIF_STATE;
1566 tvi.hItem = hItem;
1567 tvi.state = INDEXTOSTATEIMAGEMASK( feature->Action );
1568 tvi.stateMask = TVIS_STATEIMAGEMASK;
1570 SendMessageW( hwnd, TVM_SETITEMW, 0, (LPARAM) &tvi );
1573 static UINT
1574 msi_seltree_popup_menu( HWND hwnd, INT x, INT y )
1576 HMENU hMenu;
1577 INT r;
1579 /* create a menu to display */
1580 hMenu = CreatePopupMenu();
1582 /* FIXME: load strings from resources */
1583 AppendMenuA( hMenu, MF_ENABLED, INSTALLSTATE_LOCAL, "Install feature locally");
1584 AppendMenuA( hMenu, MF_GRAYED, 0x1000, "Install entire feature");
1585 AppendMenuA( hMenu, MF_ENABLED, INSTALLSTATE_ADVERTISED, "Install on demand");
1586 AppendMenuA( hMenu, MF_ENABLED, INSTALLSTATE_ABSENT, "Don't install");
1587 r = TrackPopupMenu( hMenu, TPM_LEFTALIGN | TPM_TOPALIGN | TPM_RETURNCMD,
1588 x, y, 0, hwnd, NULL );
1589 DestroyMenu( hMenu );
1590 return r;
1593 static MSIFEATURE *
1594 msi_seltree_feature_from_item( HWND hwnd, HTREEITEM hItem )
1596 TVITEMW tvi;
1598 /* get the feature from the item */
1599 memset( &tvi, 0, sizeof tvi );
1600 tvi.hItem = hItem;
1601 tvi.mask = TVIF_PARAM | TVIF_HANDLE;
1602 SendMessageW( hwnd, TVM_GETITEMW, 0, (LPARAM) &tvi );
1604 return (MSIFEATURE*) tvi.lParam;
1607 static LRESULT
1608 msi_seltree_menu( HWND hwnd, HTREEITEM hItem )
1610 MSIFEATURE *feature;
1611 ComponentList *cl;
1612 union {
1613 RECT rc;
1614 POINT pt[2];
1615 HTREEITEM hItem;
1616 } u;
1617 UINT r;
1619 feature = msi_seltree_feature_from_item( hwnd, hItem );
1620 if (!feature)
1622 ERR("item %p feature was NULL\n", hItem);
1623 return 0;
1626 /* get the item's rectangle to put the menu just below it */
1627 u.hItem = hItem;
1628 SendMessageW( hwnd, TVM_GETITEMRECT, 0, (LPARAM) &u.rc );
1629 MapWindowPoints( hwnd, NULL, u.pt, 2 );
1631 r = msi_seltree_popup_menu( hwnd, u.rc.left, u.rc.top );
1633 switch (r)
1635 case INSTALLSTATE_LOCAL:
1636 case INSTALLSTATE_ADVERTISED:
1637 case INSTALLSTATE_ABSENT:
1638 feature->ActionRequest = r;
1639 feature->Action = r;
1640 break;
1641 default:
1642 FIXME("select feature and all children\n");
1645 /* update */
1646 msi_seltree_sync_item_state( hwnd, feature, hItem );
1648 /* update the feature's components */
1649 LIST_FOR_EACH_ENTRY( cl, &feature->Components, ComponentList, entry )
1651 cl->component->Action = feature->Action;
1652 cl->component->ActionRequest = feature->ActionRequest;
1655 return 0;
1658 static LRESULT WINAPI
1659 MSISelectionTree_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
1661 struct msi_selection_tree_info *info;
1662 TVHITTESTINFO tvhti;
1663 HRESULT r;
1665 TRACE("%p %04x %08x %08lx\n", hWnd, msg, wParam, lParam);
1667 info = GetPropW(hWnd, szButtonData);
1669 switch( msg )
1671 case WM_LBUTTONDOWN:
1672 tvhti.pt.x = LOWORD( lParam );
1673 tvhti.pt.y = HIWORD( lParam );
1674 tvhti.flags = 0;
1675 tvhti.hItem = 0;
1676 r = CallWindowProcW(info->oldproc, hWnd, TVM_HITTEST, 0, (LPARAM) &tvhti );
1677 if (tvhti.flags & TVHT_ONITEMSTATEICON)
1678 return msi_seltree_menu( hWnd, tvhti.hItem );
1679 break;
1682 r = CallWindowProcW(info->oldproc, hWnd, msg, wParam, lParam);
1684 switch( msg )
1686 case WM_NCDESTROY:
1687 msi_free( info );
1688 RemovePropW( hWnd, szButtonData );
1689 break;
1691 return r;
1694 static void
1695 msi_seltree_add_child_features( MSIPACKAGE *package, HWND hwnd,
1696 LPCWSTR parent, HTREEITEM hParent )
1698 MSIFEATURE *feature;
1699 TVINSERTSTRUCTW tvis;
1700 HTREEITEM hitem;
1702 LIST_FOR_EACH_ENTRY( feature, &package->features, MSIFEATURE, entry )
1704 if ( lstrcmpW( parent, feature->Feature_Parent ) )
1705 continue;
1707 if ( !feature->Title )
1708 continue;
1710 if ( !feature->Display )
1711 continue;
1713 memset( &tvis, 0, sizeof tvis );
1714 tvis.hParent = hParent;
1715 tvis.hInsertAfter = TVI_LAST;
1716 tvis.u.item.mask = TVIF_TEXT | TVIF_PARAM;
1717 tvis.u.item.pszText = feature->Title;
1718 tvis.u.item.lParam = (LPARAM) feature;
1720 hitem = (HTREEITEM) SendMessageW( hwnd, TVM_INSERTITEMW, 0, (LPARAM) &tvis );
1721 if (!hitem)
1722 continue;
1724 msi_seltree_sync_item_state( hwnd, feature, hitem );
1725 msi_seltree_add_child_features( package, hwnd,
1726 feature->Feature, hitem );
1728 /* the node is expanded if Display is odd */
1729 if ( feature->Display % 2 != 0 )
1730 SendMessageW( hwnd, TVM_EXPAND, TVE_EXPAND, (LPARAM) hitem );
1734 static void msi_seltree_create_imagelist( HWND hwnd )
1736 const int bm_width = 32, bm_height = 16, bm_count = 3;
1737 const int bm_resource = 0x1001;
1738 HIMAGELIST himl;
1739 int i;
1740 HBITMAP hbmp;
1742 himl = ImageList_Create( bm_width, bm_height, FALSE, 4, 0 );
1743 if (!himl)
1745 ERR("failed to create image list\n");
1746 return;
1749 for (i=0; i<bm_count; i++)
1751 hbmp = LoadBitmapW( msi_hInstance, MAKEINTRESOURCEW(i+bm_resource) );
1752 if (!hbmp)
1754 ERR("failed to load bitmap %d\n", i);
1755 break;
1759 * Add a dummy bitmap at offset zero because the treeview
1760 * can't use it as a state mask (zero means no user state).
1762 if (!i)
1763 ImageList_Add( himl, hbmp, NULL );
1765 ImageList_Add( himl, hbmp, NULL );
1768 SendMessageW( hwnd, TVM_SETIMAGELIST, TVSIL_STATE, (LPARAM)himl );
1771 static UINT msi_dialog_selection_tree( msi_dialog *dialog, MSIRECORD *rec )
1773 msi_control *control;
1774 LPCWSTR prop;
1775 MSIPACKAGE *package = dialog->package;
1776 DWORD style;
1777 struct msi_selection_tree_info *info;
1779 info = msi_alloc( sizeof *info );
1780 if (!info)
1781 return ERROR_FUNCTION_FAILED;
1783 /* create the treeview control */
1784 prop = MSI_RecordGetString( rec, 9 );
1785 style = TVS_HASLINES | TVS_HASBUTTONS | TVS_LINESATROOT;
1786 style |= WS_GROUP | WS_VSCROLL;
1787 control = msi_dialog_add_control( dialog, rec, WC_TREEVIEWW, style );
1788 if (!control)
1790 msi_free(info);
1791 return ERROR_FUNCTION_FAILED;
1794 /* subclass */
1795 info->dialog = dialog;
1796 info->hwnd = control->hwnd;
1797 info->oldproc = (WNDPROC) SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
1798 (LONG_PTR)MSISelectionTree_WndProc );
1799 SetPropW( control->hwnd, szButtonData, info );
1801 /* initialize it */
1802 msi_seltree_create_imagelist( control->hwnd );
1803 msi_seltree_add_child_features( package, control->hwnd, NULL, NULL );
1805 return ERROR_SUCCESS;
1808 /******************** Group Box ***************************************/
1810 static UINT msi_dialog_group_box( msi_dialog *dialog, MSIRECORD *rec )
1812 msi_control *control;
1813 DWORD style;
1815 style = BS_GROUPBOX | WS_CHILD | WS_GROUP;
1816 control = msi_dialog_add_control( dialog, rec, WC_BUTTONW, style );
1817 if (!control)
1818 return ERROR_FUNCTION_FAILED;
1820 return ERROR_SUCCESS;
1823 /******************** List Box ***************************************/
1825 struct msi_listbox_item
1827 LPWSTR property;
1828 LPWSTR value;
1831 struct msi_listbox_info
1833 msi_dialog *dialog;
1834 HWND hwnd;
1835 WNDPROC oldproc;
1836 DWORD num_items;
1837 struct msi_listbox_item *items;
1840 static LRESULT WINAPI MSIListBox_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
1842 struct msi_listbox_info *info;
1843 LRESULT r;
1844 DWORD j;
1846 TRACE("%p %04x %08x %08lx\n", hWnd, msg, wParam, lParam);
1848 info = GetPropW( hWnd, szButtonData );
1849 if (!info)
1850 return 0;
1852 r = CallWindowProcW( info->oldproc, hWnd, msg, wParam, lParam );
1854 switch( msg )
1856 case WM_NCDESTROY:
1857 for (j = 0; j < info->num_items; j++)
1859 msi_free( info->items[j].property );
1860 msi_free( info->items[j].value );
1862 msi_free( info->items );
1863 msi_free( info );
1864 RemovePropW( hWnd, szButtonData );
1865 break;
1868 return r;
1871 static UINT msi_listbox_add_item( MSIRECORD *rec, LPVOID param )
1873 struct msi_listbox_info *info = param;
1874 struct msi_listbox_item *item;
1875 LPCWSTR property, value, text;
1876 static int index = 0;
1878 item = &info->items[index++];
1879 property = MSI_RecordGetString( rec, 1 );
1880 value = MSI_RecordGetString( rec, 3 );
1881 text = MSI_RecordGetString( rec, 4 );
1883 item->property = strdupW( property );
1884 item->value = strdupW( value );
1886 SendMessageW( info->hwnd, LB_ADDSTRING, 0, (LPARAM)text );
1888 return ERROR_SUCCESS;
1891 static UINT msi_listbox_add_items( struct msi_listbox_info *info )
1893 UINT r;
1894 MSIQUERY *view = NULL;
1895 DWORD count;
1897 static const WCHAR query[] = {
1898 'S','E','L','E','C','T',' ','*',' ',
1899 'F','R','O','M',' ','`','L','i','s','t','B','o','x','`',' ',
1900 'O','R','D','E','R',' ','B','Y',' ','`','O','r','d','e','r','`',0
1903 r = MSI_OpenQuery( info->dialog->package->db, &view, query );
1904 if ( r != ERROR_SUCCESS )
1905 return r;
1907 /* just get the number of records */
1908 r = MSI_IterateRecords( view, &count, NULL, NULL );
1910 info->num_items = count;
1911 info->items = msi_alloc( sizeof(*info->items) * count );
1913 r = MSI_IterateRecords( view, NULL, msi_listbox_add_item, info );
1914 msiobj_release( &view->hdr );
1916 return r;
1919 static UINT msi_dialog_listbox_handler( msi_dialog *dialog,
1920 msi_control *control, WPARAM param )
1922 struct msi_listbox_info *info;
1923 int index;
1925 if( HIWORD(param) != LBN_SELCHANGE )
1926 return ERROR_SUCCESS;
1928 info = GetPropW( control->hwnd, szButtonData );
1929 index = SendMessageW( control->hwnd, LB_GETCURSEL, 0, 0 );
1931 MSI_SetPropertyW( info->dialog->package,
1932 info->items[index].property, info->items[index].value );
1933 msi_dialog_evaluate_control_conditions( info->dialog );
1935 return ERROR_SUCCESS;
1938 static UINT msi_dialog_list_box( msi_dialog *dialog, MSIRECORD *rec )
1940 struct msi_listbox_info *info;
1941 msi_control *control;
1942 DWORD style;
1944 info = msi_alloc( sizeof *info );
1945 if (!info)
1946 return ERROR_FUNCTION_FAILED;
1948 style = WS_TABSTOP | WS_GROUP | WS_CHILD | LBS_STANDARD;
1949 control = msi_dialog_add_control( dialog, rec, WC_LISTBOXW, style );
1950 if (!control)
1951 return ERROR_FUNCTION_FAILED;
1953 control->handler = msi_dialog_listbox_handler;
1955 /* subclass */
1956 info->dialog = dialog;
1957 info->hwnd = control->hwnd;
1958 info->items = NULL;
1959 info->oldproc = (WNDPROC)SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
1960 (LONG_PTR)MSIListBox_WndProc );
1961 SetPropW( control->hwnd, szButtonData, info );
1963 msi_listbox_add_items( info );
1965 return ERROR_SUCCESS;
1968 /******************** Directory Combo ***************************************/
1970 static void msi_dialog_update_directory_combo( msi_dialog *dialog )
1972 msi_control *control;
1973 LPWSTR prop, path;
1974 BOOL indirect;
1976 control = msi_dialog_find_control( dialog, szDirectoryCombo );
1977 indirect = control->attributes & msidbControlAttributesIndirect;
1978 prop = msi_dialog_dup_property( dialog, control->property, indirect );
1979 path = msi_dup_property( dialog->package, prop );
1981 PathStripPathW( path );
1982 PathRemoveBackslashW( path );
1984 SendMessageW( control->hwnd, CB_INSERTSTRING, 0, (LPARAM)path );
1985 SendMessageW( control->hwnd, CB_SETCURSEL, 0, 0 );
1987 msi_free( path );
1988 msi_free( prop );
1991 static UINT msi_dialog_directory_combo( msi_dialog *dialog, MSIRECORD *rec )
1993 msi_control *control;
1994 LPCWSTR prop;
1995 DWORD style;
1997 /* FIXME: use CBS_OWNERDRAWFIXED and add owner draw code */
1998 style = CBS_DROPDOWNLIST | CBS_HASSTRINGS | WS_CHILD |
1999 WS_GROUP | WS_TABSTOP | WS_VSCROLL;
2000 control = msi_dialog_add_control( dialog, rec, WC_COMBOBOXW, style );
2001 if (!control)
2002 return ERROR_FUNCTION_FAILED;
2004 control->attributes = MSI_RecordGetInteger( rec, 8 );
2005 prop = MSI_RecordGetString( rec, 9 );
2006 control->property = msi_dialog_dup_property( dialog, prop, FALSE );
2008 msi_dialog_update_directory_combo( dialog );
2010 return ERROR_SUCCESS;
2013 /******************** Directory List ***************************************/
2015 UINT msi_dialog_directorylist_up( msi_dialog *dialog )
2017 msi_control *control;
2018 LPWSTR prop, path, ptr;
2019 BOOL indirect;
2021 control = msi_dialog_find_control( dialog, szDirectoryList );
2022 indirect = control->attributes & msidbControlAttributesIndirect;
2023 prop = msi_dialog_dup_property( dialog, control->property, indirect );
2025 path = msi_dup_property( dialog->package, prop );
2027 /* strip off the last directory */
2028 ptr = PathFindFileNameW( path );
2029 if (ptr != path) *(ptr - 1) = '\0';
2030 PathAddBackslashW( path );
2032 MSI_SetPropertyW( dialog->package, prop, path );
2034 msi_dialog_update_directory_combo( dialog );
2035 msi_dialog_update_pathedit( dialog );
2037 msi_free( path );
2038 msi_free( prop );
2040 return ERROR_SUCCESS;
2043 static UINT msi_dialog_directory_list( msi_dialog *dialog, MSIRECORD *rec )
2045 msi_control *control;
2046 LPCWSTR prop;
2047 DWORD style;
2049 style = LVS_LIST | LVS_EDITLABELS | WS_VSCROLL | LVS_SHAREIMAGELISTS |
2050 LVS_AUTOARRANGE | LVS_SINGLESEL | WS_BORDER |
2051 LVS_SORTASCENDING | WS_CHILD | WS_GROUP | WS_TABSTOP;
2052 control = msi_dialog_add_control( dialog, rec, WC_LISTVIEWW, style );
2053 if (!control)
2054 return ERROR_FUNCTION_FAILED;
2056 control->attributes = MSI_RecordGetInteger( rec, 8 );
2057 prop = MSI_RecordGetString( rec, 9 );
2058 control->property = msi_dialog_dup_property( dialog, prop, FALSE );
2060 return ERROR_SUCCESS;
2063 /******************** VolumeCost List ***************************************/
2065 static UINT msi_dialog_volumecost_list( msi_dialog *dialog, MSIRECORD *rec )
2067 msi_control *control;
2068 DWORD style;
2070 style = LVS_REPORT | WS_VSCROLL | WS_HSCROLL | LVS_SHAREIMAGELISTS |
2071 LVS_AUTOARRANGE | LVS_SINGLESEL | WS_BORDER |
2072 WS_CHILD | WS_TABSTOP | WS_GROUP;
2073 control = msi_dialog_add_control( dialog, rec, WC_LISTVIEWW, style );
2074 if (!control)
2075 return ERROR_FUNCTION_FAILED;
2077 return ERROR_SUCCESS;
2080 static const struct control_handler msi_dialog_handler[] =
2082 { szText, msi_dialog_text_control },
2083 { szPushButton, msi_dialog_button_control },
2084 { szLine, msi_dialog_line_control },
2085 { szBitmap, msi_dialog_bitmap_control },
2086 { szCheckBox, msi_dialog_checkbox_control },
2087 { szScrollableText, msi_dialog_scrolltext_control },
2088 { szComboBox, msi_dialog_combo_control },
2089 { szEdit, msi_dialog_edit_control },
2090 { szMaskedEdit, msi_dialog_maskedit_control },
2091 { szPathEdit, msi_dialog_pathedit_control },
2092 { szProgressBar, msi_dialog_progress_bar },
2093 { szRadioButtonGroup, msi_dialog_radiogroup_control },
2094 { szIcon, msi_dialog_icon_control },
2095 { szSelectionTree, msi_dialog_selection_tree },
2096 { szGroupBox, msi_dialog_group_box },
2097 { szListBox, msi_dialog_list_box },
2098 { szDirectoryCombo, msi_dialog_directory_combo },
2099 { szDirectoryList, msi_dialog_directory_list },
2100 { szVolumeCostList, msi_dialog_volumecost_list },
2103 #define NUM_CONTROL_TYPES (sizeof msi_dialog_handler/sizeof msi_dialog_handler[0])
2105 static UINT msi_dialog_create_controls( MSIRECORD *rec, LPVOID param )
2107 msi_dialog *dialog = param;
2108 LPCWSTR control_type;
2109 UINT i;
2111 /* find and call the function that can create this type of control */
2112 control_type = MSI_RecordGetString( rec, 3 );
2113 for( i=0; i<NUM_CONTROL_TYPES; i++ )
2114 if (!strcmpiW( msi_dialog_handler[i].control_type, control_type ))
2115 break;
2116 if( i != NUM_CONTROL_TYPES )
2117 msi_dialog_handler[i].func( dialog, rec );
2118 else
2119 ERR("no handler for element type %s\n", debugstr_w(control_type));
2121 return ERROR_SUCCESS;
2124 static UINT msi_dialog_fill_controls( msi_dialog *dialog )
2126 static const WCHAR query[] = {
2127 'S','E','L','E','C','T',' ','*',' ',
2128 'F','R','O','M',' ','C','o','n','t','r','o','l',' ',
2129 'W','H','E','R','E',' ',
2130 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',0};
2131 UINT r;
2132 MSIQUERY *view = NULL;
2133 MSIPACKAGE *package = dialog->package;
2135 TRACE("%p %s\n", dialog, debugstr_w(dialog->name) );
2137 /* query the Control table for all the elements of the control */
2138 r = MSI_OpenQuery( package->db, &view, query, dialog->name );
2139 if( r != ERROR_SUCCESS )
2141 ERR("query failed for dialog %s\n", debugstr_w(dialog->name));
2142 return ERROR_INVALID_PARAMETER;
2145 r = MSI_IterateRecords( view, 0, msi_dialog_create_controls, dialog );
2146 msiobj_release( &view->hdr );
2148 return r;
2151 static UINT msi_dialog_set_control_condition( MSIRECORD *rec, LPVOID param )
2153 static const WCHAR szHide[] = { 'H','i','d','e',0 };
2154 static const WCHAR szShow[] = { 'S','h','o','w',0 };
2155 static const WCHAR szDisable[] = { 'D','i','s','a','b','l','e',0 };
2156 static const WCHAR szEnable[] = { 'E','n','a','b','l','e',0 };
2157 msi_dialog *dialog = param;
2158 msi_control *control;
2159 LPCWSTR name, action, condition;
2160 UINT r;
2162 name = MSI_RecordGetString( rec, 2 );
2163 action = MSI_RecordGetString( rec, 3 );
2164 condition = MSI_RecordGetString( rec, 4 );
2165 r = MSI_EvaluateConditionW( dialog->package, condition );
2166 control = msi_dialog_find_control( dialog, name );
2167 if( r == MSICONDITION_TRUE && control )
2169 TRACE("%s control %s\n", debugstr_w(action), debugstr_w(name));
2171 /* FIXME: case sensitive? */
2172 if(!lstrcmpW(action, szHide))
2173 ShowWindow(control->hwnd, SW_HIDE);
2174 else if(!strcmpW(action, szShow))
2175 ShowWindow(control->hwnd, SW_SHOW);
2176 else if(!strcmpW(action, szDisable))
2177 EnableWindow(control->hwnd, FALSE);
2178 else if(!strcmpW(action, szEnable))
2179 EnableWindow(control->hwnd, TRUE);
2180 else
2181 FIXME("Unhandled action %s\n", debugstr_w(action));
2184 return ERROR_SUCCESS;
2187 static UINT msi_dialog_evaluate_control_conditions( msi_dialog *dialog )
2189 static const WCHAR query[] = {
2190 'S','E','L','E','C','T',' ','*',' ',
2191 'F','R','O','M',' ',
2192 'C','o','n','t','r','o','l','C','o','n','d','i','t','i','o','n',' ',
2193 'W','H','E','R','E',' ',
2194 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',0
2196 UINT r;
2197 MSIQUERY *view = NULL;
2198 MSIPACKAGE *package = dialog->package;
2200 TRACE("%p %s\n", dialog, debugstr_w(dialog->name) );
2202 /* query the Control table for all the elements of the control */
2203 r = MSI_OpenQuery( package->db, &view, query, dialog->name );
2204 if( r != ERROR_SUCCESS )
2206 ERR("query failed for dialog %s\n", debugstr_w(dialog->name));
2207 return ERROR_INVALID_PARAMETER;
2210 r = MSI_IterateRecords( view, 0, msi_dialog_set_control_condition, dialog );
2211 msiobj_release( &view->hdr );
2213 return r;
2216 UINT msi_dialog_reset( msi_dialog *dialog )
2218 /* FIXME: should restore the original values of any properties we changed */
2219 return msi_dialog_evaluate_control_conditions( dialog );
2222 /* figure out the height of 10 point MS Sans Serif */
2223 static INT msi_dialog_get_sans_serif_height( HWND hwnd )
2225 static const WCHAR szSansSerif[] = {
2226 'M','S',' ','S','a','n','s',' ','S','e','r','i','f',0 };
2227 LOGFONTW lf;
2228 TEXTMETRICW tm;
2229 BOOL r;
2230 LONG height = 0;
2231 HFONT hFont, hOldFont;
2232 HDC hdc;
2234 hdc = GetDC( hwnd );
2235 if (hdc)
2237 memset( &lf, 0, sizeof lf );
2238 lf.lfHeight = MulDiv(10, GetDeviceCaps(hdc, LOGPIXELSY), 72);
2239 strcpyW( lf.lfFaceName, szSansSerif );
2240 hFont = CreateFontIndirectW(&lf);
2241 if (hFont)
2243 hOldFont = SelectObject( hdc, hFont );
2244 r = GetTextMetricsW( hdc, &tm );
2245 if (r)
2246 height = tm.tmHeight;
2247 SelectObject( hdc, hOldFont );
2248 DeleteObject( hFont );
2250 ReleaseDC( hwnd, hdc );
2252 return height;
2255 /* fetch the associated record from the Dialog table */
2256 static MSIRECORD *msi_get_dialog_record( msi_dialog *dialog )
2258 static const WCHAR query[] = {
2259 'S','E','L','E','C','T',' ','*',' ',
2260 'F','R','O','M',' ','D','i','a','l','o','g',' ',
2261 'W','H','E','R','E',' ',
2262 '`','D','i','a','l','o','g','`',' ','=',' ','\'','%','s','\'',0};
2263 MSIPACKAGE *package = dialog->package;
2264 MSIRECORD *rec = NULL;
2266 TRACE("%p %s\n", dialog, debugstr_w(dialog->name) );
2268 rec = MSI_QueryGetRecord( package->db, query, dialog->name );
2269 if( !rec )
2270 ERR("query failed for dialog %s\n", debugstr_w(dialog->name));
2272 return rec;
2275 static void msi_dialog_adjust_dialog_pos( msi_dialog *dialog, MSIRECORD *rec, LPRECT pos )
2277 static const WCHAR szScreenX[] = {'S','c','r','e','e','n','X',0};
2278 static const WCHAR szScreenY[] = {'S','c','r','e','e','n','Y',0};
2280 UINT xres, yres;
2281 POINT center;
2282 SIZE sz;
2283 LONG style;
2285 center.x = MSI_RecordGetInteger( rec, 2 );
2286 center.y = MSI_RecordGetInteger( rec, 3 );
2288 sz.cx = MSI_RecordGetInteger( rec, 4 );
2289 sz.cy = MSI_RecordGetInteger( rec, 5 );
2291 sz.cx = msi_dialog_scale_unit( dialog, sz.cx );
2292 sz.cy = msi_dialog_scale_unit( dialog, sz.cy );
2294 xres = msi_get_property_int( dialog->package, szScreenX, 0 );
2295 yres = msi_get_property_int( dialog->package, szScreenY, 0 );
2297 center.x = MulDiv( center.x, xres, 100 );
2298 center.y = MulDiv( center.y, yres, 100 );
2300 /* turn the client pos into the window rectangle */
2301 pos->left = center.x - sz.cx/2;
2302 pos->right = pos->left + sz.cx;
2303 pos->top = center.y - sz.cy/2;
2304 pos->bottom = pos->top + sz.cy;
2306 TRACE("%lu %lu %lu %lu\n", pos->left, pos->top, pos->right, pos->bottom);
2308 style = GetWindowLongPtrW( dialog->hwnd, GWL_STYLE );
2309 AdjustWindowRect( pos, style, FALSE );
2312 static BOOL msi_control_set_next( msi_control *control, msi_control *next )
2314 return SetWindowPos( next->hwnd, control->hwnd, 0, 0, 0, 0,
2315 SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOREDRAW |
2316 SWP_NOREPOSITION | SWP_NOSENDCHANGING | SWP_NOSIZE );
2319 static UINT msi_dialog_set_tab_order( msi_dialog *dialog )
2321 msi_control *control, *tab_next;
2323 LIST_FOR_EACH_ENTRY( control, &dialog->controls, msi_control, entry )
2325 tab_next = msi_dialog_find_control( dialog, control->tabnext );
2326 if( !tab_next )
2327 continue;
2328 msi_control_set_next( control, tab_next );
2331 return ERROR_SUCCESS;
2334 static void msi_dialog_set_first_control( msi_dialog* dialog, LPCWSTR name )
2336 msi_control *control;
2338 control = msi_dialog_find_control( dialog, name );
2339 if( control )
2340 dialog->hWndFocus = control->hwnd;
2341 else
2342 dialog->hWndFocus = NULL;
2345 static LRESULT msi_dialog_oncreate( HWND hwnd, LPCREATESTRUCTW cs )
2347 static const WCHAR df[] = {
2348 'D','e','f','a','u','l','t','U','I','F','o','n','t',0 };
2349 static const WCHAR dfv[] = {
2350 'M','S',' ','S','h','e','l','l',' ','D','l','g',0 };
2351 msi_dialog *dialog = (msi_dialog*) cs->lpCreateParams;
2352 MSIRECORD *rec = NULL;
2353 LPWSTR title = NULL;
2354 RECT pos;
2356 TRACE("%p %p\n", dialog, dialog->package);
2358 dialog->hwnd = hwnd;
2359 SetWindowLongPtrW( hwnd, GWLP_USERDATA, (LONG_PTR) dialog );
2361 rec = msi_get_dialog_record( dialog );
2362 if( !rec )
2364 TRACE("No record found for dialog %s\n", debugstr_w(dialog->name));
2365 return -1;
2368 dialog->scale = msi_dialog_get_sans_serif_height(dialog->hwnd);
2370 msi_dialog_adjust_dialog_pos( dialog, rec, &pos );
2372 dialog->attributes = MSI_RecordGetInteger( rec, 6 );
2374 dialog->default_font = msi_dup_property( dialog->package, df );
2375 if (!dialog->default_font)
2377 dialog->default_font = strdupW(dfv);
2378 if (!dialog->default_font) return -1;
2381 title = msi_get_deformatted_field( dialog->package, rec, 7 );
2382 SetWindowTextW( hwnd, title );
2383 msi_free( title );
2385 SetWindowPos( hwnd, 0, pos.left, pos.top,
2386 pos.right - pos.left, pos.bottom - pos.top,
2387 SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOREDRAW );
2389 msi_dialog_build_font_list( dialog );
2390 msi_dialog_fill_controls( dialog );
2391 msi_dialog_evaluate_control_conditions( dialog );
2392 msi_dialog_set_tab_order( dialog );
2393 msi_dialog_set_first_control( dialog, MSI_RecordGetString( rec, 8 ) );
2394 msiobj_release( &rec->hdr );
2396 return 0;
2399 static UINT msi_dialog_send_event( msi_dialog *dialog, LPCWSTR event, LPCWSTR arg )
2401 LPWSTR event_fmt = NULL, arg_fmt = NULL;
2403 TRACE("Sending control event %s %s\n", debugstr_w(event), debugstr_w(arg));
2405 deformat_string( dialog->package, event, &event_fmt );
2406 deformat_string( dialog->package, arg, &arg_fmt );
2408 dialog->event_handler( dialog->package, event_fmt, arg_fmt, dialog );
2410 msi_free( event_fmt );
2411 msi_free( arg_fmt );
2413 return ERROR_SUCCESS;
2416 static UINT msi_dialog_set_property( msi_dialog *dialog, LPCWSTR event, LPCWSTR arg )
2418 static const WCHAR szNullArg[] = { '{','}',0 };
2419 LPWSTR p, prop, arg_fmt = NULL;
2420 UINT len;
2422 len = strlenW(event);
2423 prop = msi_alloc( len*sizeof(WCHAR));
2424 strcpyW( prop, &event[1] );
2425 p = strchrW( prop, ']' );
2426 if( p && p[1] == 0 )
2428 *p = 0;
2429 if( strcmpW( szNullArg, arg ) )
2430 deformat_string( dialog->package, arg, &arg_fmt );
2431 MSI_SetPropertyW( dialog->package, prop, arg_fmt );
2432 msi_free( arg_fmt );
2434 else
2435 ERR("Badly formatted property string - what happens?\n");
2436 msi_free( prop );
2437 return ERROR_SUCCESS;
2440 static UINT msi_dialog_control_event( MSIRECORD *rec, LPVOID param )
2442 msi_dialog *dialog = param;
2443 LPCWSTR condition, event, arg;
2444 UINT r;
2446 condition = MSI_RecordGetString( rec, 5 );
2447 r = MSI_EvaluateConditionW( dialog->package, condition );
2448 if( r == MSICONDITION_TRUE || r == MSICONDITION_NONE )
2450 event = MSI_RecordGetString( rec, 3 );
2451 arg = MSI_RecordGetString( rec, 4 );
2452 if( event[0] == '[' )
2453 msi_dialog_set_property( dialog, event, arg );
2454 else
2455 msi_dialog_send_event( dialog, event, arg );
2458 return ERROR_SUCCESS;
2461 static UINT msi_dialog_button_handler( msi_dialog *dialog,
2462 msi_control *control, WPARAM param )
2464 static const WCHAR query[] = {
2465 'S','E','L','E','C','T',' ','*',' ',
2466 'F','R','O','M',' ','C','o','n','t','r','o','l','E','v','e','n','t',' ',
2467 'W','H','E','R','E',' ',
2468 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',' ',
2469 'A','N','D',' ',
2470 '`','C','o','n','t','r','o','l','_','`',' ','=',' ','\'','%','s','\'',' ',
2471 'O','R','D','E','R',' ','B','Y',' ','`','O','r','d','e','r','i','n','g','`',0
2473 MSIQUERY *view = NULL;
2474 UINT r;
2476 if( HIWORD(param) != BN_CLICKED )
2477 return ERROR_SUCCESS;
2479 r = MSI_OpenQuery( dialog->package->db, &view, query,
2480 dialog->name, control->name );
2481 if( r != ERROR_SUCCESS )
2483 ERR("query failed\n");
2484 return 0;
2487 r = MSI_IterateRecords( view, 0, msi_dialog_control_event, dialog );
2488 msiobj_release( &view->hdr );
2490 return r;
2493 static UINT msi_dialog_get_checkbox_state( msi_dialog *dialog,
2494 msi_control *control )
2496 WCHAR state[2] = { 0 };
2497 DWORD sz = 2;
2499 MSI_GetPropertyW( dialog->package, control->property, state, &sz );
2500 return state[0] ? 1 : 0;
2503 static void msi_dialog_set_checkbox_state( msi_dialog *dialog,
2504 msi_control *control, UINT state )
2506 static const WCHAR szState[] = { '1', 0 };
2507 LPCWSTR val;
2509 /* if uncheck then the property is set to NULL */
2510 if (!state)
2512 MSI_SetPropertyW( dialog->package, control->property, NULL );
2513 return;
2516 /* check for a custom state */
2517 if (control->value && control->value[0])
2518 val = control->value;
2519 else
2520 val = szState;
2522 MSI_SetPropertyW( dialog->package, control->property, val );
2525 static void msi_dialog_checkbox_sync_state( msi_dialog *dialog,
2526 msi_control *control )
2528 UINT state;
2530 state = msi_dialog_get_checkbox_state( dialog, control );
2531 SendMessageW( control->hwnd, BM_SETCHECK,
2532 state ? BST_CHECKED : BST_UNCHECKED, 0 );
2535 static UINT msi_dialog_checkbox_handler( msi_dialog *dialog,
2536 msi_control *control, WPARAM param )
2538 UINT state;
2540 if( HIWORD(param) != BN_CLICKED )
2541 return ERROR_SUCCESS;
2543 TRACE("clicked checkbox %s, set %s\n", debugstr_w(control->name),
2544 debugstr_w(control->property));
2546 state = msi_dialog_get_checkbox_state( dialog, control );
2547 state = state ? 0 : 1;
2548 msi_dialog_set_checkbox_state( dialog, control, state );
2549 msi_dialog_checkbox_sync_state( dialog, control );
2551 return msi_dialog_button_handler( dialog, control, param );
2554 static UINT msi_dialog_edit_handler( msi_dialog *dialog,
2555 msi_control *control, WPARAM param )
2557 LPWSTR buf;
2559 if( HIWORD(param) != EN_CHANGE )
2560 return ERROR_SUCCESS;
2562 TRACE("edit %s contents changed, set %s\n", debugstr_w(control->name),
2563 debugstr_w(control->property));
2565 buf = msi_get_window_text( control->hwnd );
2566 MSI_SetPropertyW( dialog->package, control->property, buf );
2568 msi_free( buf );
2570 return ERROR_SUCCESS;
2573 static UINT msi_dialog_radiogroup_handler( msi_dialog *dialog,
2574 msi_control *control, WPARAM param )
2576 if( HIWORD(param) != BN_CLICKED )
2577 return ERROR_SUCCESS;
2579 TRACE("clicked radio button %s, set %s\n", debugstr_w(control->name),
2580 debugstr_w(control->property));
2582 MSI_SetPropertyW( dialog->package, control->property, control->name );
2584 return msi_dialog_button_handler( dialog, control, param );
2587 static LRESULT msi_dialog_oncommand( msi_dialog *dialog, WPARAM param, HWND hwnd )
2589 msi_control *control = NULL;
2591 TRACE("%p %p %08x\n", dialog, hwnd, param);
2593 switch (param)
2595 case 1: /* enter */
2596 control = msi_dialog_find_control( dialog, dialog->control_default );
2597 break;
2598 case 2: /* escape */
2599 control = msi_dialog_find_control( dialog, dialog->control_cancel );
2600 break;
2601 default:
2602 control = msi_dialog_find_control_by_hwnd( dialog, hwnd );
2605 if( control )
2607 if( control->handler )
2609 control->handler( dialog, control, param );
2610 msi_dialog_evaluate_control_conditions( dialog );
2613 else
2614 ERR("button click from nowhere %p %d %p\n", dialog, param, hwnd);
2615 return 0;
2618 static void msi_dialog_setfocus( msi_dialog *dialog )
2620 HWND hwnd = dialog->hWndFocus;
2622 hwnd = GetNextDlgTabItem( dialog->hwnd, hwnd, TRUE);
2623 hwnd = GetNextDlgTabItem( dialog->hwnd, hwnd, FALSE);
2624 SetFocus( hwnd );
2625 dialog->hWndFocus = hwnd;
2628 static LRESULT WINAPI MSIDialog_WndProc( HWND hwnd, UINT msg,
2629 WPARAM wParam, LPARAM lParam )
2631 msi_dialog *dialog = (LPVOID) GetWindowLongPtrW( hwnd, GWLP_USERDATA );
2633 TRACE("0x%04x\n", msg);
2635 switch (msg)
2637 case WM_CREATE:
2638 return msi_dialog_oncreate( hwnd, (LPCREATESTRUCTW)lParam );
2640 case WM_COMMAND:
2641 return msi_dialog_oncommand( dialog, wParam, (HWND)lParam );
2643 case WM_ACTIVATE:
2644 if( LOWORD(wParam) == WA_INACTIVE )
2645 dialog->hWndFocus = GetFocus();
2646 else
2647 msi_dialog_setfocus( dialog );
2648 return 0;
2650 case WM_SETFOCUS:
2651 msi_dialog_setfocus( dialog );
2652 return 0;
2654 /* bounce back to our subclassed static control */
2655 case WM_CTLCOLORSTATIC:
2656 return SendMessageW( (HWND) lParam, WM_CTLCOLORSTATIC, wParam, lParam );
2658 case WM_DESTROY:
2659 dialog->hwnd = NULL;
2660 return 0;
2662 return DefWindowProcW(hwnd, msg, wParam, lParam);
2665 static BOOL CALLBACK msi_radioground_child_enum( HWND hWnd, LPARAM lParam )
2667 EnableWindow( hWnd, lParam );
2668 return TRUE;
2671 static LRESULT WINAPI MSIRadioGroup_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
2673 WNDPROC oldproc = (WNDPROC) GetPropW(hWnd, szButtonData);
2674 LRESULT r;
2676 TRACE("hWnd %p msg %04x wParam 0x%08x lParam 0x%08lx\n", hWnd, msg, wParam, lParam);
2678 if (msg == WM_COMMAND) /* Forward notifications to dialog */
2679 SendMessageW(GetParent(hWnd), msg, wParam, lParam);
2681 r = CallWindowProcW(oldproc, hWnd, msg, wParam, lParam);
2683 /* make sure the radio buttons show as disabled if the parent is disabled */
2684 if (msg == WM_ENABLE)
2685 EnumChildWindows( hWnd, msi_radioground_child_enum, wParam );
2687 return r;
2690 static LRESULT WINAPI MSIHiddenWindowProc( HWND hwnd, UINT msg,
2691 WPARAM wParam, LPARAM lParam )
2693 msi_dialog *dialog = (msi_dialog*) lParam;
2695 TRACE("%d %p\n", msg, dialog);
2697 switch (msg)
2699 case WM_MSI_DIALOG_CREATE:
2700 return msi_dialog_run_message_loop( dialog );
2701 case WM_MSI_DIALOG_DESTROY:
2702 msi_dialog_destroy( dialog );
2703 return 0;
2705 return DefWindowProcW( hwnd, msg, wParam, lParam );
2708 /* functions that interface to other modules within MSI */
2710 msi_dialog *msi_dialog_create( MSIPACKAGE* package, LPCWSTR szDialogName,
2711 msi_dialog_event_handler event_handler )
2713 MSIRECORD *rec = NULL;
2714 msi_dialog *dialog;
2716 TRACE("%p %s\n", package, debugstr_w(szDialogName));
2718 /* allocate the structure for the dialog to use */
2719 dialog = msi_alloc_zero( sizeof *dialog + sizeof(WCHAR)*strlenW(szDialogName) );
2720 if( !dialog )
2721 return NULL;
2722 strcpyW( dialog->name, szDialogName );
2723 msiobj_addref( &package->hdr );
2724 dialog->package = package;
2725 dialog->event_handler = event_handler;
2726 dialog->finished = 0;
2727 list_init( &dialog->controls );
2729 /* verify that the dialog exists */
2730 rec = msi_get_dialog_record( dialog );
2731 if( !rec )
2733 msiobj_release( &package->hdr );
2734 msi_free( dialog );
2735 return NULL;
2737 dialog->attributes = MSI_RecordGetInteger( rec, 6 );
2738 dialog->control_default = strdupW( MSI_RecordGetString( rec, 9 ) );
2739 dialog->control_cancel = strdupW( MSI_RecordGetString( rec, 10 ) );
2740 msiobj_release( &rec->hdr );
2742 return dialog;
2745 static void msi_process_pending_messages( HWND hdlg )
2747 MSG msg;
2749 while( PeekMessageW( &msg, 0, 0, 0, PM_REMOVE ) )
2751 if( hdlg && IsDialogMessageW( hdlg, &msg ))
2752 continue;
2753 TranslateMessage( &msg );
2754 DispatchMessageW( &msg );
2758 void msi_dialog_end_dialog( msi_dialog *dialog )
2760 TRACE("%p\n", dialog);
2761 dialog->finished = 1;
2762 PostMessageW(dialog->hwnd, WM_NULL, 0, 0);
2765 void msi_dialog_check_messages( HANDLE handle )
2767 DWORD r;
2769 /* in threads other than the UI thread, block */
2770 if( uiThreadId != GetCurrentThreadId() )
2772 if( handle )
2773 WaitForSingleObject( handle, INFINITE );
2774 return;
2777 /* there's two choices for the UI thread */
2778 while (1)
2780 msi_process_pending_messages( NULL );
2782 if( !handle )
2783 break;
2786 * block here until somebody creates a new dialog or
2787 * the handle we're waiting on becomes ready
2789 r = MsgWaitForMultipleObjects( 1, &handle, 0, INFINITE, QS_ALLINPUT );
2790 if( r == WAIT_OBJECT_0 )
2791 break;
2795 UINT msi_dialog_run_message_loop( msi_dialog *dialog )
2797 DWORD style;
2798 HWND hwnd;
2800 if( uiThreadId != GetCurrentThreadId() )
2801 return SendMessageW( hMsiHiddenWindow, WM_MSI_DIALOG_CREATE, 0, (LPARAM) dialog );
2803 /* create the dialog window, don't show it yet */
2804 style = WS_OVERLAPPED;
2805 if( dialog->attributes & msidbDialogAttributesVisible )
2806 style |= WS_VISIBLE;
2808 hwnd = CreateWindowW( szMsiDialogClass, dialog->name, style,
2809 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
2810 NULL, NULL, NULL, dialog );
2811 if( !hwnd )
2813 ERR("Failed to create dialog %s\n", debugstr_w( dialog->name ));
2814 return ERROR_FUNCTION_FAILED;
2817 ShowWindow( hwnd, SW_SHOW );
2818 /* UpdateWindow( hwnd ); - and causes the transparent static controls not to paint */
2820 if( dialog->attributes & msidbDialogAttributesModal )
2822 while( !dialog->finished )
2824 MsgWaitForMultipleObjects( 0, NULL, 0, INFINITE, QS_ALLINPUT );
2825 msi_process_pending_messages( dialog->hwnd );
2828 else
2829 return ERROR_IO_PENDING;
2831 return ERROR_SUCCESS;
2834 void msi_dialog_do_preview( msi_dialog *dialog )
2836 TRACE("\n");
2837 dialog->attributes |= msidbDialogAttributesVisible;
2838 dialog->attributes &= ~msidbDialogAttributesModal;
2839 msi_dialog_run_message_loop( dialog );
2842 void msi_dialog_destroy( msi_dialog *dialog )
2844 if( uiThreadId != GetCurrentThreadId() )
2846 SendMessageW( hMsiHiddenWindow, WM_MSI_DIALOG_DESTROY, 0, (LPARAM) dialog );
2847 return;
2850 if( dialog->hwnd )
2851 ShowWindow( dialog->hwnd, SW_HIDE );
2853 if( dialog->hwnd )
2854 DestroyWindow( dialog->hwnd );
2856 /* destroy the list of controls */
2857 while( !list_empty( &dialog->controls ) )
2859 msi_control *t = LIST_ENTRY( list_head( &dialog->controls ),
2860 msi_control, entry );
2861 list_remove( &t->entry );
2862 /* leave dialog->hwnd - destroying parent destroys child windows */
2863 msi_free( t->property );
2864 msi_free( t->value );
2865 if( t->hBitmap )
2866 DeleteObject( t->hBitmap );
2867 if( t->hIcon )
2868 DestroyIcon( t->hIcon );
2869 msi_free( t->tabnext );
2870 msi_free( t );
2871 if (t->hDll)
2872 FreeLibrary( t->hDll );
2875 /* destroy the list of fonts */
2876 while( dialog->font_list )
2878 msi_font *t = dialog->font_list;
2879 dialog->font_list = t->next;
2880 DeleteObject( t->hfont );
2881 msi_free( t );
2883 msi_free( dialog->default_font );
2885 msi_free( dialog->control_default );
2886 msi_free( dialog->control_cancel );
2887 msiobj_release( &dialog->package->hdr );
2888 dialog->package = NULL;
2889 msi_free( dialog );
2892 BOOL msi_dialog_register_class( void )
2894 WNDCLASSW cls;
2896 ZeroMemory( &cls, sizeof cls );
2897 cls.lpfnWndProc = MSIDialog_WndProc;
2898 cls.hInstance = NULL;
2899 cls.hIcon = LoadIconW(0, (LPWSTR)IDI_APPLICATION);
2900 cls.hCursor = LoadCursorW(0, (LPWSTR)IDC_ARROW);
2901 cls.hbrBackground = (HBRUSH)(COLOR_3DFACE + 1);
2902 cls.lpszMenuName = NULL;
2903 cls.lpszClassName = szMsiDialogClass;
2905 if( !RegisterClassW( &cls ) )
2906 return FALSE;
2908 cls.lpfnWndProc = MSIHiddenWindowProc;
2909 cls.lpszClassName = szMsiHiddenWindow;
2911 if( !RegisterClassW( &cls ) )
2912 return FALSE;
2914 uiThreadId = GetCurrentThreadId();
2916 hMsiHiddenWindow = CreateWindowW( szMsiHiddenWindow, NULL, WS_OVERLAPPED,
2917 0, 0, 100, 100, NULL, NULL, NULL, NULL );
2918 if( !hMsiHiddenWindow )
2919 return FALSE;
2921 return TRUE;
2924 void msi_dialog_unregister_class( void )
2926 DestroyWindow( hMsiHiddenWindow );
2927 hMsiHiddenWindow = NULL;
2928 UnregisterClassW( szMsiDialogClass, NULL );
2929 UnregisterClassW( szMsiHiddenWindow, NULL );
2930 uiThreadId = 0;