d3d8: Backport null pointer check in SetCursorProperties.
[wine/testsucceed.git] / dlls / msi / dialog.c
blobd928edc30dc92fa59627b3c7fed275477c10370a
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 WINE_DEFAULT_DEBUG_CHANNEL(msi);
48 extern HINSTANCE msi_hInstance;
50 struct msi_control_tag;
51 typedef struct msi_control_tag msi_control;
52 typedef UINT (*msi_handler)( msi_dialog *, msi_control *, WPARAM );
54 struct msi_control_tag
56 struct list entry;
57 HWND hwnd;
58 msi_handler handler;
59 LPWSTR property;
60 LPWSTR value;
61 HBITMAP hBitmap;
62 HICON hIcon;
63 LPWSTR tabnext;
64 LPWSTR type;
65 HMODULE hDll;
66 float progress_current;
67 float progress_max;
68 DWORD attributes;
69 WCHAR name[1];
72 typedef struct msi_font_tag
74 struct msi_font_tag *next;
75 HFONT hfont;
76 COLORREF color;
77 WCHAR name[1];
78 } msi_font;
80 struct msi_dialog_tag
82 MSIPACKAGE *package;
83 msi_dialog *parent;
84 msi_dialog_event_handler event_handler;
85 BOOL finished;
86 INT scale;
87 DWORD attributes;
88 SIZE size;
89 HWND hwnd;
90 LPWSTR default_font;
91 msi_font *font_list;
92 struct list controls;
93 HWND hWndFocus;
94 LPWSTR control_default;
95 LPWSTR control_cancel;
96 WCHAR name[1];
99 typedef UINT (*msi_dialog_control_func)( msi_dialog *dialog, MSIRECORD *rec );
100 struct control_handler
102 LPCWSTR control_type;
103 msi_dialog_control_func func;
106 typedef struct
108 msi_dialog* dialog;
109 msi_control *parent;
110 DWORD attributes;
111 LPWSTR propval;
112 } radio_button_group_descr;
114 static const WCHAR szMsiDialogClass[] = {
115 'M','s','i','D','i','a','l','o','g','C','l','o','s','e','C','l','a','s','s',0
117 static const WCHAR szMsiHiddenWindow[] = {
118 'M','s','i','H','i','d','d','e','n','W','i','n','d','o','w',0 };
119 static const WCHAR szStatic[] = { 'S','t','a','t','i','c',0 };
120 static const WCHAR szButton[] = { 'B','U','T','T','O','N', 0 };
121 static const WCHAR szButtonData[] = { 'M','S','I','D','A','T','A',0 };
122 static const WCHAR szProgress[] = { 'P','r','o','g','r','e','s','s',0 };
123 static const WCHAR szText[] = { 'T','e','x','t',0 };
124 static const WCHAR szPushButton[] = { 'P','u','s','h','B','u','t','t','o','n',0 };
125 static const WCHAR szLine[] = { 'L','i','n','e',0 };
126 static const WCHAR szBitmap[] = { 'B','i','t','m','a','p',0 };
127 static const WCHAR szCheckBox[] = { 'C','h','e','c','k','B','o','x',0 };
128 static const WCHAR szScrollableText[] = {
129 'S','c','r','o','l','l','a','b','l','e','T','e','x','t',0 };
130 static const WCHAR szComboBox[] = { 'C','o','m','b','o','B','o','x',0 };
131 static const WCHAR szEdit[] = { 'E','d','i','t',0 };
132 static const WCHAR szMaskedEdit[] = { 'M','a','s','k','e','d','E','d','i','t',0 };
133 static const WCHAR szPathEdit[] = { 'P','a','t','h','E','d','i','t',0 };
134 static const WCHAR szProgressBar[] = {
135 'P','r','o','g','r','e','s','s','B','a','r',0 };
136 static const WCHAR szRadioButtonGroup[] = {
137 'R','a','d','i','o','B','u','t','t','o','n','G','r','o','u','p',0 };
138 static const WCHAR szIcon[] = { 'I','c','o','n',0 };
139 static const WCHAR szSelectionTree[] = {
140 'S','e','l','e','c','t','i','o','n','T','r','e','e',0 };
141 static const WCHAR szGroupBox[] = { 'G','r','o','u','p','B','o','x',0 };
142 static const WCHAR szListBox[] = { 'L','i','s','t','B','o','x',0 };
143 static const WCHAR szDirectoryCombo[] = { 'D','i','r','e','c','t','o','r','y','C','o','m','b','o',0 };
144 static const WCHAR szDirectoryList[] = { 'D','i','r','e','c','t','o','r','y','L','i','s','t',0 };
145 static const WCHAR szVolumeCostList[] = { 'V','o','l','u','m','e','C','o','s','t','L','i','s','t',0 };
146 static const WCHAR szSelectionDescription[] = {'S','e','l','e','c','t','i','o','n','D','e','s','c','r','i','p','t','i','o','n',0};
147 static const WCHAR szSelectionPath[] = {'S','e','l','e','c','t','i','o','n','P','a','t','h',0};
148 static const WCHAR szProperty[] = {'P','r','o','p','e','r','t','y',0};
150 static UINT msi_dialog_checkbox_handler( msi_dialog *, msi_control *, WPARAM );
151 static void msi_dialog_checkbox_sync_state( msi_dialog *, msi_control * );
152 static UINT msi_dialog_button_handler( msi_dialog *, msi_control *, WPARAM );
153 static UINT msi_dialog_edit_handler( msi_dialog *, msi_control *, WPARAM );
154 static UINT msi_dialog_radiogroup_handler( msi_dialog *, msi_control *, WPARAM param );
155 static UINT msi_dialog_evaluate_control_conditions( msi_dialog *dialog );
156 static LRESULT WINAPI MSIRadioGroup_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
157 static MSIFEATURE *msi_seltree_get_selected_feature( msi_control *control );
159 /* dialog sequencing */
161 #define WM_MSI_DIALOG_CREATE (WM_USER+0x100)
162 #define WM_MSI_DIALOG_DESTROY (WM_USER+0x101)
164 static DWORD uiThreadId;
165 static HWND hMsiHiddenWindow;
167 static INT msi_dialog_scale_unit( msi_dialog *dialog, INT val )
169 return (dialog->scale * val + 5) / 10;
172 static msi_control *msi_dialog_find_control( msi_dialog *dialog, LPCWSTR name )
174 msi_control *control;
176 if( !name )
177 return NULL;
178 LIST_FOR_EACH_ENTRY( control, &dialog->controls, msi_control, entry )
179 if( !strcmpW( control->name, name ) ) /* FIXME: case sensitive? */
180 return control;
181 return NULL;
184 static msi_control *msi_dialog_find_control_by_type( msi_dialog *dialog, LPCWSTR type )
186 msi_control *control;
188 if( !type )
189 return NULL;
190 LIST_FOR_EACH_ENTRY( control, &dialog->controls, msi_control, entry )
191 if( !strcmpW( control->type, type ) ) /* FIXME: case sensitive? */
192 return control;
193 return NULL;
196 static msi_control *msi_dialog_find_control_by_hwnd( msi_dialog *dialog, HWND hwnd )
198 msi_control *control;
200 LIST_FOR_EACH_ENTRY( control, &dialog->controls, msi_control, entry )
201 if( hwnd == control->hwnd )
202 return control;
203 return NULL;
206 static LPWSTR msi_get_deformatted_field( MSIPACKAGE *package, MSIRECORD *rec, int field )
208 LPCWSTR str = MSI_RecordGetString( rec, field );
209 LPWSTR ret = NULL;
211 if (str)
212 deformat_string( package, str, &ret );
213 return ret;
216 static LPWSTR msi_dialog_dup_property( msi_dialog *dialog, LPCWSTR property, BOOL indirect )
218 LPWSTR prop = NULL;
220 if (!property)
221 return NULL;
223 if (indirect)
224 prop = msi_dup_property( dialog->package, property );
226 if (!prop)
227 prop = strdupW( property );
229 return prop;
232 msi_dialog *msi_dialog_get_parent( msi_dialog *dialog )
234 return dialog->parent;
237 LPWSTR msi_dialog_get_name( msi_dialog *dialog )
239 return dialog->name;
243 * msi_dialog_get_style
245 * Extract the {\style} string from the front of the text to display and
246 * update the pointer. Only the last style in a list is applied.
248 static LPWSTR msi_dialog_get_style( LPCWSTR p, LPCWSTR *rest )
250 LPWSTR ret;
251 LPCWSTR q, i, first;
252 DWORD len;
254 q = NULL;
255 *rest = p;
256 if( !p )
257 return NULL;
259 while ((first = strchrW( p, '{' )) && (q = strchrW( first + 1, '}' )))
261 p = first + 1;
262 if( *p == '\\' || *p == '&' )
263 p++;
265 /* little bit of sanity checking to stop us getting confused with RTF */
266 for( i=p; i<q; i++ )
267 if( *i == '}' || *i == '\\' )
268 return NULL;
271 if (!p || !q)
272 return NULL;
274 *rest = ++q;
275 len = q - p;
277 ret = msi_alloc( len*sizeof(WCHAR) );
278 if( !ret )
279 return ret;
280 memcpy( ret, p, len*sizeof(WCHAR) );
281 ret[len-1] = 0;
282 return ret;
285 static UINT msi_dialog_add_font( MSIRECORD *rec, LPVOID param )
287 msi_dialog *dialog = param;
288 msi_font *font;
289 LPCWSTR face, name;
290 LOGFONTW lf;
291 INT style;
292 HDC hdc;
294 /* create a font and add it to the list */
295 name = MSI_RecordGetString( rec, 1 );
296 font = msi_alloc( sizeof *font + strlenW( name )*sizeof (WCHAR) );
297 strcpyW( font->name, name );
298 font->next = dialog->font_list;
299 dialog->font_list = font;
301 font->color = MSI_RecordGetInteger( rec, 4 );
303 memset( &lf, 0, sizeof lf );
304 face = MSI_RecordGetString( rec, 2 );
305 lf.lfHeight = MSI_RecordGetInteger( rec, 3 );
306 style = MSI_RecordGetInteger( rec, 5 );
307 if( style & msidbTextStyleStyleBitsBold )
308 lf.lfWeight = FW_BOLD;
309 if( style & msidbTextStyleStyleBitsItalic )
310 lf.lfItalic = TRUE;
311 if( style & msidbTextStyleStyleBitsUnderline )
312 lf.lfUnderline = TRUE;
313 if( style & msidbTextStyleStyleBitsStrike )
314 lf.lfStrikeOut = TRUE;
315 lstrcpynW( lf.lfFaceName, face, LF_FACESIZE );
317 /* adjust the height */
318 hdc = GetDC( dialog->hwnd );
319 if (hdc)
321 lf.lfHeight = -MulDiv(lf.lfHeight, GetDeviceCaps(hdc, LOGPIXELSY), 72);
322 ReleaseDC( dialog->hwnd, hdc );
325 font->hfont = CreateFontIndirectW( &lf );
327 TRACE("Adding font style %s\n", debugstr_w(font->name) );
329 return ERROR_SUCCESS;
332 static msi_font *msi_dialog_find_font( msi_dialog *dialog, LPCWSTR name )
334 msi_font *font;
336 for( font = dialog->font_list; font; font = font->next )
337 if( !strcmpW( font->name, name ) ) /* FIXME: case sensitive? */
338 break;
340 return font;
343 static UINT msi_dialog_set_font( msi_dialog *dialog, HWND hwnd, LPCWSTR name )
345 msi_font *font;
347 font = msi_dialog_find_font( dialog, name );
348 if( font )
349 SendMessageW( hwnd, WM_SETFONT, (WPARAM) font->hfont, TRUE );
350 else
351 ERR("No font entry for %s\n", debugstr_w(name));
352 return ERROR_SUCCESS;
355 static UINT msi_dialog_build_font_list( msi_dialog *dialog )
357 static const WCHAR query[] = {
358 'S','E','L','E','C','T',' ','*',' ',
359 'F','R','O','M',' ','`','T','e','x','t','S','t','y','l','e','`',' ',0
361 UINT r;
362 MSIQUERY *view = NULL;
364 TRACE("dialog %p\n", dialog );
366 r = MSI_OpenQuery( dialog->package->db, &view, query );
367 if( r != ERROR_SUCCESS )
368 return r;
370 r = MSI_IterateRecords( view, NULL, msi_dialog_add_font, dialog );
371 msiobj_release( &view->hdr );
373 return r;
376 static msi_control *msi_dialog_create_window( msi_dialog *dialog,
377 MSIRECORD *rec, DWORD exstyle, LPCWSTR szCls, LPCWSTR name, LPCWSTR text,
378 DWORD style, HWND parent )
380 DWORD x, y, width, height;
381 LPWSTR font = NULL, title_font = NULL;
382 LPCWSTR title = NULL;
383 msi_control *control;
385 style |= WS_CHILD;
387 control = msi_alloc( sizeof *control + strlenW(name)*sizeof(WCHAR) );
388 strcpyW( control->name, name );
389 list_add_head( &dialog->controls, &control->entry );
390 control->handler = NULL;
391 control->property = NULL;
392 control->value = NULL;
393 control->hBitmap = NULL;
394 control->hIcon = NULL;
395 control->hDll = NULL;
396 control->tabnext = strdupW( MSI_RecordGetString( rec, 11) );
397 control->type = strdupW( MSI_RecordGetString( rec, 3 ) );
398 control->progress_current = 0;
399 control->progress_max = 100;
401 x = MSI_RecordGetInteger( rec, 4 );
402 y = MSI_RecordGetInteger( rec, 5 );
403 width = MSI_RecordGetInteger( rec, 6 );
404 height = MSI_RecordGetInteger( rec, 7 );
406 x = msi_dialog_scale_unit( dialog, x );
407 y = msi_dialog_scale_unit( dialog, y );
408 width = msi_dialog_scale_unit( dialog, width );
409 height = msi_dialog_scale_unit( dialog, height );
411 if( text )
413 deformat_string( dialog->package, text, &title_font );
414 font = msi_dialog_get_style( title_font, &title );
417 control->hwnd = CreateWindowExW( exstyle, szCls, title, style,
418 x, y, width, height, parent, NULL, NULL, NULL );
420 TRACE("Dialog %s control %s hwnd %p\n",
421 debugstr_w(dialog->name), debugstr_w(text), control->hwnd );
423 msi_dialog_set_font( dialog, control->hwnd,
424 font ? font : dialog->default_font );
426 msi_free( title_font );
427 msi_free( font );
429 return control;
432 static LPWSTR msi_dialog_get_uitext( msi_dialog *dialog, LPCWSTR key )
434 MSIRECORD *rec;
435 LPWSTR text;
437 static const WCHAR query[] = {
438 's','e','l','e','c','t',' ','*',' ',
439 'f','r','o','m',' ','`','U','I','T','e','x','t','`',' ',
440 'w','h','e','r','e',' ','`','K','e','y','`',' ','=',' ','\'','%','s','\'',0
443 rec = MSI_QueryGetRecord( dialog->package->db, query, key );
444 if (!rec) return NULL;
445 text = strdupW( MSI_RecordGetString( rec, 2 ) );
446 msiobj_release( &rec->hdr );
447 return text;
450 static MSIRECORD *msi_get_binary_record( MSIDATABASE *db, LPCWSTR name )
452 static const WCHAR query[] = {
453 's','e','l','e','c','t',' ','*',' ',
454 'f','r','o','m',' ','B','i','n','a','r','y',' ',
455 'w','h','e','r','e',' ',
456 '`','N','a','m','e','`',' ','=',' ','\'','%','s','\'',0
459 return MSI_QueryGetRecord( db, query, name );
462 static LPWSTR msi_create_tmp_path(void)
464 WCHAR tmp[MAX_PATH];
465 LPWSTR path = NULL;
466 static const WCHAR prefix[] = { 'm','s','i',0 };
467 DWORD len, r;
469 r = GetTempPathW( MAX_PATH, tmp );
470 if( !r )
471 return path;
472 len = lstrlenW( tmp ) + 20;
473 path = msi_alloc( len * sizeof (WCHAR) );
474 if( path )
476 r = GetTempFileNameW( tmp, prefix, 0, path );
477 if (!r)
479 msi_free( path );
480 path = NULL;
483 return path;
487 static HANDLE msi_load_image( MSIDATABASE *db, LPCWSTR name, UINT type,
488 UINT cx, UINT cy, UINT flags )
490 MSIRECORD *rec = NULL;
491 HANDLE himage = NULL;
492 LPWSTR tmp;
493 UINT r;
495 TRACE("%p %s %u %u %08x\n", db, debugstr_w(name), cx, cy, flags);
497 tmp = msi_create_tmp_path();
498 if( !tmp )
499 return himage;
501 rec = msi_get_binary_record( db, name );
502 if( rec )
504 r = MSI_RecordStreamToFile( rec, 2, tmp );
505 if( r == ERROR_SUCCESS )
507 himage = LoadImageW( 0, tmp, type, cx, cy, flags );
508 DeleteFileW( tmp );
510 msiobj_release( &rec->hdr );
513 msi_free( tmp );
514 return himage;
517 static HICON msi_load_icon( MSIDATABASE *db, LPCWSTR text, UINT attributes )
519 DWORD cx = 0, cy = 0, flags;
521 flags = LR_LOADFROMFILE | LR_DEFAULTSIZE;
522 if( attributes & msidbControlAttributesFixedSize )
524 flags &= ~LR_DEFAULTSIZE;
525 if( attributes & msidbControlAttributesIconSize16 )
527 cx += 16;
528 cy += 16;
530 if( attributes & msidbControlAttributesIconSize32 )
532 cx += 32;
533 cy += 32;
535 /* msidbControlAttributesIconSize48 handled by above logic */
537 return msi_load_image( db, text, IMAGE_ICON, cx, cy, flags );
541 /* called from the Control Event subscription code */
542 void msi_dialog_handle_event( msi_dialog* dialog, LPCWSTR control,
543 LPCWSTR attribute, MSIRECORD *rec )
545 msi_control* ctrl;
546 LPCWSTR font_text, text = NULL;
547 LPWSTR font;
549 static const WCHAR empty[] = {0};
551 ctrl = msi_dialog_find_control( dialog, control );
552 if (!ctrl)
553 return;
554 if( !lstrcmpW(attribute, szText) )
556 font_text = MSI_RecordGetString( rec , 1 );
557 font = msi_dialog_get_style( font_text, &text );
558 if (!text) text = empty;
559 SetWindowTextW( ctrl->hwnd, text );
560 msi_free( font );
561 msi_dialog_check_messages( NULL );
563 else if( !lstrcmpW(attribute, szProgress) )
565 DWORD func, val;
567 func = MSI_RecordGetInteger( rec , 1 );
568 val = MSI_RecordGetInteger( rec , 2 );
570 switch (func)
572 case 0: /* init */
573 ctrl->progress_max = val;
574 ctrl->progress_current = 0;
575 SendMessageW(ctrl->hwnd, PBM_SETRANGE, 0, MAKELPARAM(0,100));
576 SendMessageW(ctrl->hwnd, PBM_SETPOS, 0, 0);
577 break;
578 case 1: /* FIXME: not sure what this is supposed to do */
579 break;
580 case 2: /* move */
581 ctrl->progress_current += val;
582 SendMessageW(ctrl->hwnd, PBM_SETPOS, 100*(ctrl->progress_current/ctrl->progress_max), 0);
583 break;
584 default:
585 ERR("Unknown progress message %d\n", func);
586 break;
589 else if ( !lstrcmpW(attribute, szProperty) )
591 MSIFEATURE *feature = msi_seltree_get_selected_feature( ctrl );
592 MSI_SetPropertyW( dialog->package, ctrl->property, feature->Directory );
594 else
596 FIXME("Attribute %s not being set\n", debugstr_w(attribute));
597 return;
601 static void msi_dialog_map_events(msi_dialog* dialog, LPCWSTR control)
603 static const WCHAR Query[] = {
604 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
605 '`','E','v','e','n','t','M','a','p','p','i','n','g','`',' ',
606 'W','H','E','R','E',' ',
607 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',' ',
608 'A','N','D',' ',
609 '`','C','o','n','t','r','o','l','_','`',' ','=',' ','\'','%','s','\'',0
611 MSIRECORD *row;
612 LPCWSTR event, attribute;
614 row = MSI_QueryGetRecord( dialog->package->db, Query, dialog->name, control );
615 if (!row)
616 return;
618 event = MSI_RecordGetString( row, 3 );
619 attribute = MSI_RecordGetString( row, 4 );
620 ControlEvent_SubscribeToEvent( dialog->package, dialog, event, control, attribute );
621 msiobj_release( &row->hdr );
624 /* everything except radio buttons */
625 static msi_control *msi_dialog_add_control( msi_dialog *dialog,
626 MSIRECORD *rec, LPCWSTR szCls, DWORD style )
628 DWORD attributes;
629 LPCWSTR text, name;
630 DWORD exstyle = 0;
632 name = MSI_RecordGetString( rec, 2 );
633 attributes = MSI_RecordGetInteger( rec, 8 );
634 text = MSI_RecordGetString( rec, 10 );
635 if( attributes & msidbControlAttributesVisible )
636 style |= WS_VISIBLE;
637 if( ~attributes & msidbControlAttributesEnabled )
638 style |= WS_DISABLED;
639 if( attributes & msidbControlAttributesSunken )
640 exstyle |= WS_EX_CLIENTEDGE;
642 msi_dialog_map_events(dialog, name);
644 return msi_dialog_create_window( dialog, rec, exstyle, szCls, name,
645 text, style, dialog->hwnd );
648 struct msi_text_info
650 msi_font *font;
651 WNDPROC oldproc;
652 DWORD attributes;
656 * we don't erase our own background,
657 * so we have to make sure that the parent window redraws first
659 static void msi_text_on_settext( HWND hWnd )
661 HWND hParent;
662 RECT rc;
664 hParent = GetParent( hWnd );
665 GetWindowRect( hWnd, &rc );
666 MapWindowPoints( NULL, hParent, (LPPOINT) &rc, 2 );
667 InvalidateRect( hParent, &rc, TRUE );
670 static LRESULT WINAPI
671 MSIText_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
673 struct msi_text_info *info;
674 LRESULT r = 0;
676 TRACE("%p %04x %08x %08lx\n", hWnd, msg, wParam, lParam);
678 info = GetPropW(hWnd, szButtonData);
680 if ( info->font )
681 SetTextColor( (HDC)wParam, info->font->color );
683 if( msg == WM_CTLCOLORSTATIC &&
684 ( info->attributes & msidbControlAttributesTransparent ) )
686 SetBkMode( (HDC)wParam, TRANSPARENT );
687 return (LRESULT) GetStockObject(NULL_BRUSH);
690 r = CallWindowProcW(info->oldproc, hWnd, msg, wParam, lParam);
692 switch( msg )
694 case WM_SETTEXT:
695 msi_text_on_settext( hWnd );
696 break;
697 case WM_NCDESTROY:
698 msi_free( info );
699 RemovePropW( hWnd, szButtonData );
700 break;
703 return r;
706 static UINT msi_dialog_text_control( msi_dialog *dialog, MSIRECORD *rec )
708 msi_control *control;
709 struct msi_text_info *info;
710 LPCWSTR text, ptr;
711 LPWSTR font_name;
713 TRACE("%p %p\n", dialog, rec);
715 control = msi_dialog_add_control( dialog, rec, szStatic, SS_LEFT | WS_GROUP );
716 if( !control )
717 return ERROR_FUNCTION_FAILED;
719 info = msi_alloc( sizeof *info );
720 if( !info )
721 return ERROR_SUCCESS;
723 text = MSI_RecordGetString( rec, 10 );
724 font_name = msi_dialog_get_style( text, &ptr );
725 info->font = ( font_name ) ? msi_dialog_find_font( dialog, font_name ) : NULL;
726 msi_free( font_name );
728 info->attributes = MSI_RecordGetInteger( rec, 8 );
729 if( info->attributes & msidbControlAttributesTransparent )
730 SetWindowLongPtrW( control->hwnd, GWL_EXSTYLE, WS_EX_TRANSPARENT );
732 info->oldproc = (WNDPROC) SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
733 (LONG_PTR)MSIText_WndProc );
734 SetPropW( control->hwnd, szButtonData, info );
736 return ERROR_SUCCESS;
739 static UINT msi_dialog_button_control( msi_dialog *dialog, MSIRECORD *rec )
741 msi_control *control;
742 UINT attributes, style;
743 LPWSTR text;
745 TRACE("%p %p\n", dialog, rec);
747 style = WS_TABSTOP;
748 attributes = MSI_RecordGetInteger( rec, 8 );
749 if( attributes & msidbControlAttributesIcon )
750 style |= BS_ICON;
752 control = msi_dialog_add_control( dialog, rec, szButton, style );
753 if( !control )
754 return ERROR_FUNCTION_FAILED;
756 control->handler = msi_dialog_button_handler;
758 /* set the icon */
759 text = msi_get_deformatted_field( dialog->package, rec, 10 );
760 control->hIcon = msi_load_icon( dialog->package->db, text, attributes );
761 if( attributes & msidbControlAttributesIcon )
762 SendMessageW( control->hwnd, BM_SETIMAGE, IMAGE_ICON, (LPARAM) control->hIcon );
763 msi_free( text );
765 return ERROR_SUCCESS;
768 static LPWSTR msi_get_checkbox_value( msi_dialog *dialog, LPCWSTR prop )
770 static const WCHAR query[] = {
771 'S','E','L','E','C','T',' ','*',' ',
772 'F','R','O','M',' ','`','C','h','e','c','k','B','o','x',' ','`',
773 'W','H','E','R','E',' ',
774 '`','P','r','o','p','e','r','t','y','`',' ','=',' ',
775 '\'','%','s','\'',0
777 MSIRECORD *rec = NULL;
778 LPWSTR ret = NULL;
780 /* find if there is a value associated with the checkbox */
781 rec = MSI_QueryGetRecord( dialog->package->db, query, prop );
782 if (!rec)
783 return ret;
785 ret = msi_get_deformatted_field( dialog->package, rec, 2 );
786 if( ret && !ret[0] )
788 msi_free( ret );
789 ret = NULL;
791 msiobj_release( &rec->hdr );
792 if (ret)
793 return ret;
795 ret = msi_dup_property( dialog->package, prop );
796 if( ret && !ret[0] )
798 msi_free( ret );
799 ret = NULL;
802 return ret;
805 static UINT msi_dialog_checkbox_control( msi_dialog *dialog, MSIRECORD *rec )
807 msi_control *control;
808 LPCWSTR prop;
810 TRACE("%p %p\n", dialog, rec);
812 control = msi_dialog_add_control( dialog, rec, szButton,
813 BS_CHECKBOX | BS_MULTILINE | WS_TABSTOP );
814 control->handler = msi_dialog_checkbox_handler;
815 prop = MSI_RecordGetString( rec, 9 );
816 if( prop )
818 control->property = strdupW( prop );
819 control->value = msi_get_checkbox_value( dialog, prop );
820 TRACE("control %s value %s\n", debugstr_w(control->property),
821 debugstr_w(control->value));
823 msi_dialog_checkbox_sync_state( dialog, control );
825 return ERROR_SUCCESS;
828 static UINT msi_dialog_line_control( msi_dialog *dialog, MSIRECORD *rec )
830 TRACE("%p %p\n", dialog, rec);
832 /* line is exactly 2 units in height */
833 MSI_RecordSetInteger( rec, 7, 2 );
835 msi_dialog_add_control( dialog, rec, szStatic, SS_ETCHEDHORZ | SS_SUNKEN );
836 return ERROR_SUCCESS;
839 /******************** Scroll Text ********************************************/
841 struct msi_scrolltext_info
843 msi_dialog *dialog;
844 msi_control *control;
845 WNDPROC oldproc;
848 static LRESULT WINAPI
849 MSIScrollText_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
851 struct msi_scrolltext_info *info;
852 HRESULT r;
854 TRACE("%p %04x %08x %08lx\n", hWnd, msg, wParam, lParam);
856 info = GetPropW( hWnd, szButtonData );
858 r = CallWindowProcW( info->oldproc, hWnd, msg, wParam, lParam );
860 switch( msg )
862 case WM_NCDESTROY:
863 msi_free( info );
864 RemovePropW( hWnd, szButtonData );
865 break;
866 case WM_PAINT:
867 /* native MSI sets a wait cursor here */
868 msi_dialog_button_handler( info->dialog, info->control, BN_CLICKED );
869 break;
871 return r;
874 struct msi_streamin_info
876 LPSTR string;
877 DWORD offset;
878 DWORD length;
881 static DWORD CALLBACK
882 msi_richedit_stream_in( DWORD_PTR arg, LPBYTE buffer, LONG count, LONG *pcb )
884 struct msi_streamin_info *info = (struct msi_streamin_info*) arg;
886 if( (count + info->offset) > info->length )
887 count = info->length - info->offset;
888 memcpy( buffer, &info->string[ info->offset ], count );
889 *pcb = count;
890 info->offset += count;
892 TRACE("%d/%d\n", info->offset, info->length);
894 return 0;
897 static void msi_scrolltext_add_text( msi_control *control, LPCWSTR text )
899 struct msi_streamin_info info;
900 EDITSTREAM es;
902 info.string = strdupWtoA( text );
903 info.offset = 0;
904 info.length = lstrlenA( info.string ) + 1;
906 es.dwCookie = (DWORD_PTR) &info;
907 es.dwError = 0;
908 es.pfnCallback = msi_richedit_stream_in;
910 SendMessageW( control->hwnd, EM_STREAMIN, SF_RTF, (LPARAM) &es );
912 msi_free( info.string );
915 static UINT msi_dialog_scrolltext_control( msi_dialog *dialog, MSIRECORD *rec )
917 static const WCHAR szRichEdit20W[] = {
918 'R','i','c','h','E','d','i','t','2','0','W',0
920 struct msi_scrolltext_info *info;
921 msi_control *control;
922 HMODULE hRichedit;
923 LPCWSTR text;
924 DWORD style;
926 info = msi_alloc( sizeof *info );
927 if (!info)
928 return ERROR_FUNCTION_FAILED;
930 hRichedit = LoadLibraryA("riched20");
932 style = WS_BORDER | ES_MULTILINE | WS_VSCROLL |
933 ES_READONLY | ES_AUTOVSCROLL | WS_TABSTOP;
934 control = msi_dialog_add_control( dialog, rec, szRichEdit20W, style );
935 if (!control)
937 FreeLibrary( hRichedit );
938 msi_free( info );
939 return ERROR_FUNCTION_FAILED;
942 control->hDll = hRichedit;
944 info->dialog = dialog;
945 info->control = control;
947 /* subclass the static control */
948 info->oldproc = (WNDPROC) SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
949 (LONG_PTR)MSIScrollText_WndProc );
950 SetPropW( control->hwnd, szButtonData, info );
952 /* add the text into the richedit */
953 text = MSI_RecordGetString( rec, 10 );
954 if (text)
955 msi_scrolltext_add_text( control, text );
957 return ERROR_SUCCESS;
960 static HBITMAP msi_load_picture( MSIDATABASE *db, LPCWSTR name,
961 INT cx, INT cy, DWORD flags )
963 HBITMAP hOleBitmap = 0, hBitmap = 0, hOldSrcBitmap, hOldDestBitmap;
964 MSIRECORD *rec = NULL;
965 IStream *stm = NULL;
966 IPicture *pic = NULL;
967 HDC srcdc, destdc;
968 BITMAP bm;
969 UINT r;
971 rec = msi_get_binary_record( db, name );
972 if( !rec )
973 goto end;
975 r = MSI_RecordGetIStream( rec, 2, &stm );
976 msiobj_release( &rec->hdr );
977 if( r != ERROR_SUCCESS )
978 goto end;
980 r = OleLoadPicture( stm, 0, TRUE, &IID_IPicture, (LPVOID*) &pic );
981 IStream_Release( stm );
982 if( FAILED( r ) )
984 ERR("failed to load picture\n");
985 goto end;
988 r = IPicture_get_Handle( pic, (OLE_HANDLE*) &hOleBitmap );
989 if( FAILED( r ) )
991 ERR("failed to get bitmap handle\n");
992 goto end;
995 /* make the bitmap the desired size */
996 r = GetObjectW( hOleBitmap, sizeof bm, &bm );
997 if (r != sizeof bm )
999 ERR("failed to get bitmap size\n");
1000 goto end;
1003 if (flags & LR_DEFAULTSIZE)
1005 cx = bm.bmWidth;
1006 cy = bm.bmHeight;
1009 srcdc = CreateCompatibleDC( NULL );
1010 hOldSrcBitmap = SelectObject( srcdc, hOleBitmap );
1011 destdc = CreateCompatibleDC( NULL );
1012 hBitmap = CreateCompatibleBitmap( srcdc, cx, cy );
1013 hOldDestBitmap = SelectObject( destdc, hBitmap );
1014 StretchBlt( destdc, 0, 0, cx, cy,
1015 srcdc, 0, 0, bm.bmWidth, bm.bmHeight, SRCCOPY);
1016 SelectObject( srcdc, hOldSrcBitmap );
1017 SelectObject( destdc, hOldDestBitmap );
1018 DeleteDC( srcdc );
1019 DeleteDC( destdc );
1021 end:
1022 if ( pic )
1023 IPicture_Release( pic );
1024 return hBitmap;
1027 static UINT msi_dialog_bitmap_control( msi_dialog *dialog, MSIRECORD *rec )
1029 UINT cx, cy, flags, style, attributes;
1030 msi_control *control;
1031 LPWSTR text;
1033 flags = LR_LOADFROMFILE;
1034 style = SS_BITMAP | SS_LEFT | WS_GROUP;
1036 attributes = MSI_RecordGetInteger( rec, 8 );
1037 if( attributes & msidbControlAttributesFixedSize )
1039 flags |= LR_DEFAULTSIZE;
1040 style |= SS_CENTERIMAGE;
1043 control = msi_dialog_add_control( dialog, rec, szStatic, style );
1044 cx = MSI_RecordGetInteger( rec, 6 );
1045 cy = MSI_RecordGetInteger( rec, 7 );
1046 cx = msi_dialog_scale_unit( dialog, cx );
1047 cy = msi_dialog_scale_unit( dialog, cy );
1049 text = msi_get_deformatted_field( dialog->package, rec, 10 );
1050 control->hBitmap = msi_load_picture( dialog->package->db, text, cx, cy, flags );
1051 if( control->hBitmap )
1052 SendMessageW( control->hwnd, STM_SETIMAGE,
1053 IMAGE_BITMAP, (LPARAM) control->hBitmap );
1054 else
1055 ERR("Failed to load bitmap %s\n", debugstr_w(text));
1057 msi_free( text );
1059 return ERROR_SUCCESS;
1062 static UINT msi_dialog_icon_control( msi_dialog *dialog, MSIRECORD *rec )
1064 msi_control *control;
1065 DWORD attributes;
1066 LPWSTR text;
1068 TRACE("\n");
1070 control = msi_dialog_add_control( dialog, rec, szStatic,
1071 SS_ICON | SS_CENTERIMAGE | WS_GROUP );
1073 attributes = MSI_RecordGetInteger( rec, 8 );
1074 text = msi_get_deformatted_field( dialog->package, rec, 10 );
1075 control->hIcon = msi_load_icon( dialog->package->db, text, attributes );
1076 if( control->hIcon )
1077 SendMessageW( control->hwnd, STM_SETICON, (WPARAM) control->hIcon, 0 );
1078 else
1079 ERR("Failed to load bitmap %s\n", debugstr_w(text));
1080 msi_free( text );
1081 return ERROR_SUCCESS;
1084 static UINT msi_dialog_combo_control( msi_dialog *dialog, MSIRECORD *rec )
1086 static const WCHAR szCombo[] = { 'C','O','M','B','O','B','O','X',0 };
1088 msi_dialog_add_control( dialog, rec, szCombo,
1089 SS_BITMAP | SS_LEFT | SS_CENTERIMAGE );
1090 return ERROR_SUCCESS;
1093 static UINT msi_dialog_edit_control( msi_dialog *dialog, MSIRECORD *rec )
1095 msi_control *control;
1096 LPCWSTR prop;
1097 LPWSTR val;
1099 control = msi_dialog_add_control( dialog, rec, szEdit,
1100 WS_BORDER | WS_TABSTOP );
1101 control->handler = msi_dialog_edit_handler;
1102 prop = MSI_RecordGetString( rec, 9 );
1103 if( prop )
1104 control->property = strdupW( prop );
1105 val = msi_dup_property( dialog->package, control->property );
1106 SetWindowTextW( control->hwnd, val );
1107 msi_free( val );
1108 return ERROR_SUCCESS;
1111 /******************** Masked Edit ********************************************/
1113 #define MASK_MAX_GROUPS 20
1115 struct msi_mask_group
1117 UINT len;
1118 UINT ofs;
1119 WCHAR type;
1120 HWND hwnd;
1123 struct msi_maskedit_info
1125 msi_dialog *dialog;
1126 WNDPROC oldproc;
1127 HWND hwnd;
1128 LPWSTR prop;
1129 UINT num_chars;
1130 UINT num_groups;
1131 struct msi_mask_group group[MASK_MAX_GROUPS];
1134 static BOOL msi_mask_editable( WCHAR type )
1136 switch (type)
1138 case '%':
1139 case '#':
1140 case '&':
1141 case '`':
1142 case '?':
1143 case '^':
1144 return TRUE;
1146 return FALSE;
1149 static void msi_mask_control_change( struct msi_maskedit_info *info )
1151 LPWSTR val;
1152 UINT i, n, r;
1154 val = msi_alloc( (info->num_chars+1)*sizeof(WCHAR) );
1155 for( i=0, n=0; i<info->num_groups; i++ )
1157 if( (info->group[i].len + n) > info->num_chars )
1159 ERR("can't fit control %d text into template\n",i);
1160 break;
1162 if (!msi_mask_editable(info->group[i].type))
1164 for(r=0; r<info->group[i].len; r++)
1165 val[n+r] = info->group[i].type;
1166 val[n+r] = 0;
1168 else
1170 r = GetWindowTextW( info->group[i].hwnd, &val[n], info->group[i].len+1 );
1171 if( r != info->group[i].len )
1172 break;
1174 n += r;
1177 TRACE("%d/%d controls were good\n", i, info->num_groups);
1179 if( i == info->num_groups )
1181 TRACE("Set property %s to %s\n",
1182 debugstr_w(info->prop), debugstr_w(val) );
1183 CharUpperBuffW( val, info->num_chars );
1184 MSI_SetPropertyW( info->dialog->package, info->prop, val );
1185 msi_dialog_evaluate_control_conditions( info->dialog );
1187 msi_free( val );
1190 /* now move to the next control if necessary */
1191 static VOID msi_mask_next_control( struct msi_maskedit_info *info, HWND hWnd )
1193 HWND hWndNext;
1194 UINT len, i;
1196 for( i=0; i<info->num_groups; i++ )
1197 if( info->group[i].hwnd == hWnd )
1198 break;
1200 /* don't move from the last control */
1201 if( i >= (info->num_groups-1) )
1202 return;
1204 len = SendMessageW( hWnd, WM_GETTEXTLENGTH, 0, 0 );
1205 if( len < info->group[i].len )
1206 return;
1208 hWndNext = GetNextDlgTabItem( GetParent( hWnd ), hWnd, FALSE );
1209 SetFocus( hWndNext );
1212 static LRESULT WINAPI
1213 MSIMaskedEdit_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
1215 struct msi_maskedit_info *info;
1216 HRESULT r;
1218 TRACE("%p %04x %08x %08lx\n", hWnd, msg, wParam, lParam);
1220 info = GetPropW(hWnd, szButtonData);
1222 r = CallWindowProcW(info->oldproc, hWnd, msg, wParam, lParam);
1224 switch( msg )
1226 case WM_COMMAND:
1227 if (HIWORD(wParam) == EN_CHANGE)
1229 msi_mask_control_change( info );
1230 msi_mask_next_control( info, (HWND) lParam );
1232 break;
1233 case WM_NCDESTROY:
1234 msi_free( info->prop );
1235 msi_free( info );
1236 RemovePropW( hWnd, szButtonData );
1237 break;
1240 return r;
1243 /* fish the various bits of the property out and put them in the control */
1244 static void
1245 msi_maskedit_set_text( struct msi_maskedit_info *info, LPCWSTR text )
1247 LPCWSTR p;
1248 UINT i;
1250 p = text;
1251 for( i = 0; i < info->num_groups; i++ )
1253 if( info->group[i].len < lstrlenW( p ) )
1255 LPWSTR chunk = strdupW( p );
1256 chunk[ info->group[i].len ] = 0;
1257 SetWindowTextW( info->group[i].hwnd, chunk );
1258 msi_free( chunk );
1260 else
1262 SetWindowTextW( info->group[i].hwnd, p );
1263 break;
1265 p += info->group[i].len;
1269 static struct msi_maskedit_info * msi_dialog_parse_groups( LPCWSTR mask )
1271 struct msi_maskedit_info * info = NULL;
1272 int i = 0, n = 0, total = 0;
1273 LPCWSTR p;
1275 TRACE("masked control, template %s\n", debugstr_w(mask));
1277 if( !mask )
1278 return info;
1280 info = msi_alloc_zero( sizeof *info );
1281 if( !info )
1282 return info;
1284 p = strchrW(mask, '<');
1285 if( p )
1286 p++;
1287 else
1288 p = mask;
1290 for( i=0; i<MASK_MAX_GROUPS; i++ )
1292 /* stop at the end of the string */
1293 if( p[0] == 0 || p[0] == '>' )
1294 break;
1296 /* count the number of the same identifier */
1297 for( n=0; p[n] == p[0]; n++ )
1299 info->group[i].ofs = total;
1300 info->group[i].type = p[0];
1301 if( p[n] == '=' )
1303 n++;
1304 total++; /* an extra not part of the group */
1306 info->group[i].len = n;
1307 total += n;
1308 p += n;
1311 TRACE("%d characters in %d groups\n", total, i );
1312 if( i == MASK_MAX_GROUPS )
1313 ERR("too many groups in PIDTemplate %s\n", debugstr_w(mask));
1315 info->num_chars = total;
1316 info->num_groups = i;
1318 return info;
1321 static void
1322 msi_maskedit_create_children( struct msi_maskedit_info *info, LPCWSTR font )
1324 DWORD width, height, style, wx, ww;
1325 RECT rect;
1326 HWND hwnd;
1327 UINT i;
1329 style = WS_CHILD | WS_BORDER | WS_VISIBLE | WS_TABSTOP | ES_AUTOHSCROLL;
1331 GetClientRect( info->hwnd, &rect );
1333 width = rect.right - rect.left;
1334 height = rect.bottom - rect.top;
1336 for( i = 0; i < info->num_groups; i++ )
1338 if (!msi_mask_editable( info->group[i].type ))
1339 continue;
1340 wx = (info->group[i].ofs * width) / info->num_chars;
1341 ww = (info->group[i].len * width) / info->num_chars;
1343 hwnd = CreateWindowW( szEdit, NULL, style, wx, 0, ww, height,
1344 info->hwnd, NULL, NULL, NULL );
1345 if( !hwnd )
1347 ERR("failed to create mask edit sub window\n");
1348 break;
1351 SendMessageW( hwnd, EM_LIMITTEXT, info->group[i].len, 0 );
1353 msi_dialog_set_font( info->dialog, hwnd,
1354 font?font:info->dialog->default_font );
1355 info->group[i].hwnd = hwnd;
1360 * office 2003 uses "73931<````=````=````=````=`````>@@@@@"
1361 * delphi 7 uses "<????-??????-??????-????>" and "<???-???>"
1362 * filemaker pro 7 uses "<^^^^=^^^^=^^^^=^^^^=^^^^=^^^^=^^^^^>"
1364 static UINT msi_dialog_maskedit_control( msi_dialog *dialog, MSIRECORD *rec )
1366 LPWSTR font_mask, val = NULL, font;
1367 struct msi_maskedit_info *info = NULL;
1368 UINT ret = ERROR_SUCCESS;
1369 msi_control *control;
1370 LPCWSTR prop, mask;
1372 TRACE("\n");
1374 font_mask = msi_get_deformatted_field( dialog->package, rec, 10 );
1375 font = msi_dialog_get_style( font_mask, &mask );
1376 if( !mask )
1378 ERR("mask template is empty\n");
1379 goto end;
1382 info = msi_dialog_parse_groups( mask );
1383 if( !info )
1385 ERR("template %s is invalid\n", debugstr_w(mask));
1386 goto end;
1389 info->dialog = dialog;
1391 control = msi_dialog_add_control( dialog, rec, szStatic,
1392 SS_OWNERDRAW | WS_GROUP | WS_VISIBLE );
1393 if( !control )
1395 ERR("Failed to create maskedit container\n");
1396 ret = ERROR_FUNCTION_FAILED;
1397 goto end;
1399 SetWindowLongPtrW( control->hwnd, GWL_EXSTYLE, WS_EX_CONTROLPARENT );
1401 info->hwnd = control->hwnd;
1403 /* subclass the static control */
1404 info->oldproc = (WNDPROC) SetWindowLongPtrW( info->hwnd, GWLP_WNDPROC,
1405 (LONG_PTR)MSIMaskedEdit_WndProc );
1406 SetPropW( control->hwnd, szButtonData, info );
1408 prop = MSI_RecordGetString( rec, 9 );
1409 if( prop )
1410 info->prop = strdupW( prop );
1412 msi_maskedit_create_children( info, font );
1414 if( prop )
1416 val = msi_dup_property( dialog->package, prop );
1417 if( val )
1419 msi_maskedit_set_text( info, val );
1420 msi_free( val );
1424 end:
1425 if( ret != ERROR_SUCCESS )
1426 msi_free( info );
1427 msi_free( font_mask );
1428 msi_free( font );
1429 return ret;
1432 /******************** Progress Bar *****************************************/
1434 static UINT msi_dialog_progress_bar( msi_dialog *dialog, MSIRECORD *rec )
1436 msi_dialog_add_control( dialog, rec, PROGRESS_CLASSW, WS_VISIBLE );
1437 return ERROR_SUCCESS;
1440 /******************** Path Edit ********************************************/
1442 struct msi_pathedit_info
1444 msi_dialog *dialog;
1445 msi_control *control;
1446 WNDPROC oldproc;
1449 static LPWSTR msi_get_window_text( HWND hwnd )
1451 UINT sz, r;
1452 LPWSTR buf;
1454 sz = 0x20;
1455 buf = msi_alloc( sz*sizeof(WCHAR) );
1456 while ( buf )
1458 r = GetWindowTextW( hwnd, buf, sz );
1459 if ( r < (sz - 1) )
1460 break;
1461 sz *= 2;
1462 buf = msi_realloc( buf, sz*sizeof(WCHAR) );
1465 return buf;
1468 static void msi_dialog_update_pathedit( msi_dialog *dialog, msi_control *control )
1470 LPWSTR prop, path;
1471 BOOL indirect;
1473 if (!control && !(control = msi_dialog_find_control_by_type( dialog, szPathEdit )))
1474 return;
1476 indirect = control->attributes & msidbControlAttributesIndirect;
1477 prop = msi_dialog_dup_property( dialog, control->property, indirect );
1478 path = msi_dialog_dup_property( dialog, prop, TRUE );
1480 SetWindowTextW( control->hwnd, path );
1481 SendMessageW( control->hwnd, EM_SETSEL, 0, -1 );
1483 msi_free( path );
1484 msi_free( prop );
1487 /* FIXME: test when this should fail */
1488 static BOOL msi_dialog_verify_path( LPWSTR path )
1490 if ( !lstrlenW( path ) )
1491 return FALSE;
1493 if ( PathIsRelativeW( path ) )
1494 return FALSE;
1496 return TRUE;
1499 /* returns TRUE if the path is valid, FALSE otherwise */
1500 static BOOL msi_dialog_onkillfocus( msi_dialog *dialog, msi_control *control )
1502 LPWSTR buf, prop;
1503 BOOL indirect;
1504 BOOL valid;
1506 indirect = control->attributes & msidbControlAttributesIndirect;
1507 prop = msi_dialog_dup_property( dialog, control->property, indirect );
1509 buf = msi_get_window_text( control->hwnd );
1511 if ( !msi_dialog_verify_path( buf ) )
1513 /* FIXME: display an error message box */
1514 ERR("Invalid path %s\n", debugstr_w( buf ));
1515 valid = FALSE;
1516 SetFocus( control->hwnd );
1518 else
1520 valid = TRUE;
1521 MSI_SetPropertyW( dialog->package, prop, buf );
1524 msi_dialog_update_pathedit( dialog, control );
1526 TRACE("edit %s contents changed, set %s\n", debugstr_w(control->name),
1527 debugstr_w(prop));
1529 msi_free( buf );
1530 msi_free( prop );
1532 return valid;
1535 static LRESULT WINAPI MSIPathEdit_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
1537 struct msi_pathedit_info *info = GetPropW(hWnd, szButtonData);
1538 LRESULT r = 0;
1540 TRACE("%p %04x %08x %08lx\n", hWnd, msg, wParam, lParam);
1542 if ( msg == WM_KILLFOCUS )
1544 /* if the path is invalid, don't handle this message */
1545 if ( !msi_dialog_onkillfocus( info->dialog, info->control ) )
1546 return 0;
1549 r = CallWindowProcW(info->oldproc, hWnd, msg, wParam, lParam);
1551 if ( msg == WM_NCDESTROY )
1553 msi_free( info );
1554 RemovePropW( hWnd, szButtonData );
1557 return r;
1560 static UINT msi_dialog_pathedit_control( msi_dialog *dialog, MSIRECORD *rec )
1562 struct msi_pathedit_info *info;
1563 msi_control *control;
1564 LPCWSTR prop;
1566 info = msi_alloc( sizeof *info );
1567 if (!info)
1568 return ERROR_FUNCTION_FAILED;
1570 control = msi_dialog_add_control( dialog, rec, szEdit,
1571 WS_BORDER | WS_TABSTOP );
1572 control->attributes = MSI_RecordGetInteger( rec, 8 );
1573 prop = MSI_RecordGetString( rec, 9 );
1574 control->property = msi_dialog_dup_property( dialog, prop, FALSE );
1576 info->dialog = dialog;
1577 info->control = control;
1578 info->oldproc = (WNDPROC) SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
1579 (LONG_PTR)MSIPathEdit_WndProc );
1580 SetPropW( control->hwnd, szButtonData, info );
1582 msi_dialog_update_pathedit( dialog, control );
1584 return ERROR_SUCCESS;
1587 /* radio buttons are a bit different from normal controls */
1588 static UINT msi_dialog_create_radiobutton( MSIRECORD *rec, LPVOID param )
1590 radio_button_group_descr *group = (radio_button_group_descr *)param;
1591 msi_dialog *dialog = group->dialog;
1592 msi_control *control;
1593 LPCWSTR prop, text, name;
1594 DWORD style, attributes = group->attributes;
1596 style = WS_CHILD | BS_AUTORADIOBUTTON | BS_MULTILINE | WS_TABSTOP;
1597 name = MSI_RecordGetString( rec, 3 );
1598 text = MSI_RecordGetString( rec, 8 );
1599 if( attributes & 1 )
1600 style |= WS_VISIBLE;
1601 if( ~attributes & 2 )
1602 style |= WS_DISABLED;
1604 control = msi_dialog_create_window( dialog, rec, 0, szButton, name, text,
1605 style, group->parent->hwnd );
1606 if (!control)
1607 return ERROR_FUNCTION_FAILED;
1608 control->handler = msi_dialog_radiogroup_handler;
1610 if (!lstrcmpW(control->name, group->propval))
1611 SendMessageW(control->hwnd, BM_SETCHECK, BST_CHECKED, 0);
1613 prop = MSI_RecordGetString( rec, 1 );
1614 if( prop )
1615 control->property = strdupW( prop );
1617 return ERROR_SUCCESS;
1620 static UINT msi_dialog_radiogroup_control( msi_dialog *dialog, MSIRECORD *rec )
1622 static const WCHAR query[] = {
1623 'S','E','L','E','C','T',' ','*',' ',
1624 'F','R','O','M',' ','R','a','d','i','o','B','u','t','t','o','n',' ',
1625 'W','H','E','R','E',' ',
1626 '`','P','r','o','p','e','r','t','y','`',' ','=',' ','\'','%','s','\'',0};
1627 UINT r;
1628 LPCWSTR prop;
1629 msi_control *control;
1630 MSIQUERY *view = NULL;
1631 radio_button_group_descr group;
1632 MSIPACKAGE *package = dialog->package;
1633 WNDPROC oldproc;
1635 prop = MSI_RecordGetString( rec, 9 );
1637 TRACE("%p %p %s\n", dialog, rec, debugstr_w( prop ));
1639 /* Create parent group box to hold radio buttons */
1640 control = msi_dialog_add_control( dialog, rec, szButton, BS_OWNERDRAW|WS_GROUP );
1641 if( !control )
1642 return ERROR_FUNCTION_FAILED;
1644 oldproc = (WNDPROC) SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
1645 (LONG_PTR)MSIRadioGroup_WndProc );
1646 SetPropW(control->hwnd, szButtonData, oldproc);
1647 SetWindowLongPtrW( control->hwnd, GWL_EXSTYLE, WS_EX_CONTROLPARENT );
1649 if( prop )
1650 control->property = strdupW( prop );
1652 /* query the Radio Button table for all control in this group */
1653 r = MSI_OpenQuery( package->db, &view, query, prop );
1654 if( r != ERROR_SUCCESS )
1656 ERR("query failed for dialog %s radio group %s\n",
1657 debugstr_w(dialog->name), debugstr_w(prop));
1658 return ERROR_INVALID_PARAMETER;
1661 group.dialog = dialog;
1662 group.parent = control;
1663 group.attributes = MSI_RecordGetInteger( rec, 8 );
1664 group.propval = msi_dup_property( dialog->package, control->property );
1666 r = MSI_IterateRecords( view, 0, msi_dialog_create_radiobutton, &group );
1667 msiobj_release( &view->hdr );
1668 msi_free( group.propval );
1670 return r;
1673 /******************** Selection Tree ***************************************/
1675 struct msi_selection_tree_info
1677 msi_dialog *dialog;
1678 HWND hwnd;
1679 WNDPROC oldproc;
1680 HTREEITEM selected;
1683 static void
1684 msi_seltree_sync_item_state( HWND hwnd, MSIFEATURE *feature, HTREEITEM hItem )
1686 TVITEMW tvi;
1687 DWORD index = feature->Action;
1689 TRACE("Feature %s -> %d %d %d\n", debugstr_w(feature->Title),
1690 feature->Installed, feature->Action, feature->ActionRequest);
1692 if (index == INSTALLSTATE_UNKNOWN)
1693 index = INSTALLSTATE_ABSENT;
1695 tvi.mask = TVIF_STATE;
1696 tvi.hItem = hItem;
1697 tvi.state = INDEXTOSTATEIMAGEMASK( index );
1698 tvi.stateMask = TVIS_STATEIMAGEMASK;
1700 SendMessageW( hwnd, TVM_SETITEMW, 0, (LPARAM) &tvi );
1703 static UINT
1704 msi_seltree_popup_menu( HWND hwnd, INT x, INT y )
1706 HMENU hMenu;
1707 INT r;
1709 /* create a menu to display */
1710 hMenu = CreatePopupMenu();
1712 /* FIXME: load strings from resources */
1713 AppendMenuA( hMenu, MF_ENABLED, INSTALLSTATE_LOCAL, "Install feature locally");
1714 AppendMenuA( hMenu, MF_GRAYED, 0x1000, "Install entire feature");
1715 AppendMenuA( hMenu, MF_ENABLED, INSTALLSTATE_ADVERTISED, "Install on demand");
1716 AppendMenuA( hMenu, MF_ENABLED, INSTALLSTATE_ABSENT, "Don't install");
1717 r = TrackPopupMenu( hMenu, TPM_LEFTALIGN | TPM_TOPALIGN | TPM_RETURNCMD,
1718 x, y, 0, hwnd, NULL );
1719 DestroyMenu( hMenu );
1720 return r;
1723 static MSIFEATURE *
1724 msi_seltree_feature_from_item( HWND hwnd, HTREEITEM hItem )
1726 TVITEMW tvi;
1728 /* get the feature from the item */
1729 memset( &tvi, 0, sizeof tvi );
1730 tvi.hItem = hItem;
1731 tvi.mask = TVIF_PARAM | TVIF_HANDLE;
1732 SendMessageW( hwnd, TVM_GETITEMW, 0, (LPARAM) &tvi );
1734 return (MSIFEATURE*) tvi.lParam;
1737 static LRESULT
1738 msi_seltree_menu( HWND hwnd, HTREEITEM hItem )
1740 struct msi_selection_tree_info *info;
1741 MSIFEATURE *feature;
1742 MSIPACKAGE *package;
1743 union {
1744 RECT rc;
1745 POINT pt[2];
1746 HTREEITEM hItem;
1747 } u;
1748 UINT r;
1750 info = GetPropW(hwnd, szButtonData);
1751 package = info->dialog->package;
1753 feature = msi_seltree_feature_from_item( hwnd, hItem );
1754 if (!feature)
1756 ERR("item %p feature was NULL\n", hItem);
1757 return 0;
1760 /* get the item's rectangle to put the menu just below it */
1761 u.hItem = hItem;
1762 SendMessageW( hwnd, TVM_GETITEMRECT, 0, (LPARAM) &u.rc );
1763 MapWindowPoints( hwnd, NULL, u.pt, 2 );
1765 r = msi_seltree_popup_menu( hwnd, u.rc.left, u.rc.top );
1767 switch (r)
1769 case INSTALLSTATE_LOCAL:
1770 case INSTALLSTATE_ADVERTISED:
1771 case INSTALLSTATE_ABSENT:
1772 msi_feature_set_state( feature, r );
1773 break;
1774 default:
1775 FIXME("select feature and all children\n");
1778 /* update */
1779 msi_seltree_sync_item_state( hwnd, feature, hItem );
1780 ACTION_UpdateComponentStates( package, feature->Feature );
1782 return 0;
1785 static MSIFEATURE *msi_seltree_get_selected_feature( msi_control *control )
1787 struct msi_selection_tree_info *info = GetPropW(control->hwnd, szButtonData);
1788 return msi_seltree_feature_from_item( control->hwnd, info->selected );
1791 static LRESULT WINAPI
1792 MSISelectionTree_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
1794 struct msi_selection_tree_info *info;
1795 TVHITTESTINFO tvhti;
1796 HRESULT r;
1798 TRACE("%p %04x %08x %08lx\n", hWnd, msg, wParam, lParam);
1800 info = GetPropW(hWnd, szButtonData);
1802 switch( msg )
1804 case WM_LBUTTONDOWN:
1805 tvhti.pt.x = (short)LOWORD( lParam );
1806 tvhti.pt.y = (short)HIWORD( lParam );
1807 tvhti.flags = 0;
1808 tvhti.hItem = 0;
1809 r = CallWindowProcW(info->oldproc, hWnd, TVM_HITTEST, 0, (LPARAM) &tvhti );
1810 if (tvhti.flags & TVHT_ONITEMSTATEICON)
1811 return msi_seltree_menu( hWnd, tvhti.hItem );
1812 break;
1815 r = CallWindowProcW(info->oldproc, hWnd, msg, wParam, lParam);
1817 switch( msg )
1819 case WM_NCDESTROY:
1820 msi_free( info );
1821 RemovePropW( hWnd, szButtonData );
1822 break;
1824 return r;
1827 static void
1828 msi_seltree_add_child_features( MSIPACKAGE *package, HWND hwnd,
1829 LPCWSTR parent, HTREEITEM hParent )
1831 struct msi_selection_tree_info *info = GetPropW( hwnd, szButtonData );
1832 MSIFEATURE *feature;
1833 TVINSERTSTRUCTW tvis;
1834 HTREEITEM hitem, hfirst = NULL;
1836 LIST_FOR_EACH_ENTRY( feature, &package->features, MSIFEATURE, entry )
1838 if ( lstrcmpW( parent, feature->Feature_Parent ) )
1839 continue;
1841 if ( !feature->Title )
1842 continue;
1844 if ( !feature->Display )
1845 continue;
1847 memset( &tvis, 0, sizeof tvis );
1848 tvis.hParent = hParent;
1849 tvis.hInsertAfter = TVI_LAST;
1850 tvis.u.item.mask = TVIF_TEXT | TVIF_PARAM;
1851 tvis.u.item.pszText = feature->Title;
1852 tvis.u.item.lParam = (LPARAM) feature;
1854 hitem = (HTREEITEM) SendMessageW( hwnd, TVM_INSERTITEMW, 0, (LPARAM) &tvis );
1855 if (!hitem)
1856 continue;
1858 if (!hfirst)
1859 hfirst = hitem;
1861 msi_seltree_sync_item_state( hwnd, feature, hitem );
1862 msi_seltree_add_child_features( package, hwnd,
1863 feature->Feature, hitem );
1865 /* the node is expanded if Display is odd */
1866 if ( feature->Display % 2 != 0 )
1867 SendMessageW( hwnd, TVM_EXPAND, TVE_EXPAND, (LPARAM) hitem );
1870 /* select the first item */
1871 SendMessageW( hwnd, TVM_SELECTITEM, TVGN_CARET | TVGN_DROPHILITE, (LPARAM) hfirst );
1872 info->selected = hfirst;
1875 static void msi_seltree_create_imagelist( HWND hwnd )
1877 const int bm_width = 32, bm_height = 16, bm_count = 3;
1878 const int bm_resource = 0x1001;
1879 HIMAGELIST himl;
1880 int i;
1881 HBITMAP hbmp;
1883 himl = ImageList_Create( bm_width, bm_height, FALSE, 4, 0 );
1884 if (!himl)
1886 ERR("failed to create image list\n");
1887 return;
1890 for (i=0; i<bm_count; i++)
1892 hbmp = LoadBitmapW( msi_hInstance, MAKEINTRESOURCEW(i+bm_resource) );
1893 if (!hbmp)
1895 ERR("failed to load bitmap %d\n", i);
1896 break;
1900 * Add a dummy bitmap at offset zero because the treeview
1901 * can't use it as a state mask (zero means no user state).
1903 if (!i)
1904 ImageList_Add( himl, hbmp, NULL );
1906 ImageList_Add( himl, hbmp, NULL );
1909 SendMessageW( hwnd, TVM_SETIMAGELIST, TVSIL_STATE, (LPARAM)himl );
1912 static UINT msi_dialog_seltree_handler( msi_dialog *dialog,
1913 msi_control *control, WPARAM param )
1915 struct msi_selection_tree_info *info = GetPropW( control->hwnd, szButtonData );
1916 LPNMTREEVIEWW tv = (LPNMTREEVIEWW)param;
1917 MSIRECORD *row, *rec;
1918 MSIFOLDER *folder;
1919 LPCWSTR dir;
1920 UINT r = ERROR_SUCCESS;
1922 static const WCHAR select[] = {
1923 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
1924 '`','F','e','a','t','u','r','e','`',' ','W','H','E','R','E',' ',
1925 '`','T','i','t','l','e','`',' ','=',' ','\'','%','s','\'',0
1928 if (tv->hdr.code != TVN_SELCHANGINGW)
1929 return ERROR_SUCCESS;
1931 info->selected = tv->itemNew.hItem;
1933 row = MSI_QueryGetRecord( dialog->package->db, select, tv->itemNew.pszText );
1934 if (!row)
1935 return ERROR_FUNCTION_FAILED;
1937 rec = MSI_CreateRecord( 1 );
1939 MSI_RecordSetStringW( rec, 1, MSI_RecordGetString( row, 4 ) );
1940 ControlEvent_FireSubscribedEvent( dialog->package, szSelectionDescription, rec );
1942 dir = MSI_RecordGetString( row, 7 );
1943 folder = get_loaded_folder( dialog->package, dir );
1944 if (!folder)
1946 r = ERROR_FUNCTION_FAILED;
1947 goto done;
1950 MSI_RecordSetStringW( rec, 1, folder->ResolvedTarget );
1951 ControlEvent_FireSubscribedEvent( dialog->package, szSelectionPath, rec );
1953 done:
1954 msiobj_release(&row->hdr);
1955 msiobj_release(&rec->hdr);
1957 return r;
1960 static UINT msi_dialog_selection_tree( msi_dialog *dialog, MSIRECORD *rec )
1962 msi_control *control;
1963 LPCWSTR prop;
1964 MSIPACKAGE *package = dialog->package;
1965 DWORD style;
1966 struct msi_selection_tree_info *info;
1968 info = msi_alloc( sizeof *info );
1969 if (!info)
1970 return ERROR_FUNCTION_FAILED;
1972 /* create the treeview control */
1973 style = TVS_HASLINES | TVS_HASBUTTONS | TVS_LINESATROOT;
1974 style |= WS_GROUP | WS_VSCROLL;
1975 control = msi_dialog_add_control( dialog, rec, WC_TREEVIEWW, style );
1976 if (!control)
1978 msi_free(info);
1979 return ERROR_FUNCTION_FAILED;
1982 control->handler = msi_dialog_seltree_handler;
1983 control->attributes = MSI_RecordGetInteger( rec, 8 );
1984 prop = MSI_RecordGetString( rec, 9 );
1985 control->property = msi_dialog_dup_property( dialog, prop, FALSE );
1987 /* subclass */
1988 info->dialog = dialog;
1989 info->hwnd = control->hwnd;
1990 info->oldproc = (WNDPROC) SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
1991 (LONG_PTR)MSISelectionTree_WndProc );
1992 SetPropW( control->hwnd, szButtonData, info );
1994 ControlEvent_SubscribeToEvent( dialog->package, dialog,
1995 szSelectionPath, control->name, szProperty );
1997 /* initialize it */
1998 msi_seltree_create_imagelist( control->hwnd );
1999 msi_seltree_add_child_features( package, control->hwnd, NULL, NULL );
2001 return ERROR_SUCCESS;
2004 /******************** Group Box ***************************************/
2006 static UINT msi_dialog_group_box( msi_dialog *dialog, MSIRECORD *rec )
2008 msi_control *control;
2009 DWORD style;
2011 style = BS_GROUPBOX | WS_CHILD | WS_GROUP;
2012 control = msi_dialog_add_control( dialog, rec, WC_BUTTONW, style );
2013 if (!control)
2014 return ERROR_FUNCTION_FAILED;
2016 return ERROR_SUCCESS;
2019 /******************** List Box ***************************************/
2021 struct msi_listbox_item
2023 LPWSTR property;
2024 LPWSTR value;
2027 struct msi_listbox_info
2029 msi_dialog *dialog;
2030 HWND hwnd;
2031 WNDPROC oldproc;
2032 DWORD num_items;
2033 struct msi_listbox_item *items;
2036 static LRESULT WINAPI MSIListBox_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
2038 struct msi_listbox_info *info;
2039 LRESULT r;
2040 DWORD j;
2042 TRACE("%p %04x %08x %08lx\n", hWnd, msg, wParam, lParam);
2044 info = GetPropW( hWnd, szButtonData );
2045 if (!info)
2046 return 0;
2048 r = CallWindowProcW( info->oldproc, hWnd, msg, wParam, lParam );
2050 switch( msg )
2052 case WM_NCDESTROY:
2053 for (j = 0; j < info->num_items; j++)
2055 msi_free( info->items[j].property );
2056 msi_free( info->items[j].value );
2058 msi_free( info->items );
2059 msi_free( info );
2060 RemovePropW( hWnd, szButtonData );
2061 break;
2064 return r;
2067 static UINT msi_listbox_add_item( MSIRECORD *rec, LPVOID param )
2069 struct msi_listbox_info *info = param;
2070 struct msi_listbox_item *item;
2071 LPCWSTR property, value, text;
2072 static int index = 0;
2074 item = &info->items[index++];
2075 property = MSI_RecordGetString( rec, 1 );
2076 value = MSI_RecordGetString( rec, 3 );
2077 text = MSI_RecordGetString( rec, 4 );
2079 item->property = strdupW( property );
2080 item->value = strdupW( value );
2082 SendMessageW( info->hwnd, LB_ADDSTRING, 0, (LPARAM)text );
2084 return ERROR_SUCCESS;
2087 static UINT msi_listbox_add_items( struct msi_listbox_info *info )
2089 UINT r;
2090 MSIQUERY *view = NULL;
2091 DWORD count;
2093 static const WCHAR query[] = {
2094 'S','E','L','E','C','T',' ','*',' ',
2095 'F','R','O','M',' ','`','L','i','s','t','B','o','x','`',' ',
2096 'O','R','D','E','R',' ','B','Y',' ','`','O','r','d','e','r','`',0
2099 r = MSI_OpenQuery( info->dialog->package->db, &view, query );
2100 if ( r != ERROR_SUCCESS )
2101 return r;
2103 /* just get the number of records */
2104 r = MSI_IterateRecords( view, &count, NULL, NULL );
2106 info->num_items = count;
2107 info->items = msi_alloc( sizeof(*info->items) * count );
2109 r = MSI_IterateRecords( view, NULL, msi_listbox_add_item, info );
2110 msiobj_release( &view->hdr );
2112 return r;
2115 static UINT msi_dialog_listbox_handler( msi_dialog *dialog,
2116 msi_control *control, WPARAM param )
2118 struct msi_listbox_info *info;
2119 int index;
2121 if( HIWORD(param) != LBN_SELCHANGE )
2122 return ERROR_SUCCESS;
2124 info = GetPropW( control->hwnd, szButtonData );
2125 index = SendMessageW( control->hwnd, LB_GETCURSEL, 0, 0 );
2127 MSI_SetPropertyW( info->dialog->package,
2128 info->items[index].property, info->items[index].value );
2129 msi_dialog_evaluate_control_conditions( info->dialog );
2131 return ERROR_SUCCESS;
2134 static UINT msi_dialog_list_box( msi_dialog *dialog, MSIRECORD *rec )
2136 struct msi_listbox_info *info;
2137 msi_control *control;
2138 DWORD style;
2140 info = msi_alloc( sizeof *info );
2141 if (!info)
2142 return ERROR_FUNCTION_FAILED;
2144 style = WS_TABSTOP | WS_GROUP | WS_CHILD | LBS_STANDARD;
2145 control = msi_dialog_add_control( dialog, rec, WC_LISTBOXW, style );
2146 if (!control)
2147 return ERROR_FUNCTION_FAILED;
2149 control->handler = msi_dialog_listbox_handler;
2151 /* subclass */
2152 info->dialog = dialog;
2153 info->hwnd = control->hwnd;
2154 info->items = NULL;
2155 info->oldproc = (WNDPROC)SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
2156 (LONG_PTR)MSIListBox_WndProc );
2157 SetPropW( control->hwnd, szButtonData, info );
2159 msi_listbox_add_items( info );
2161 return ERROR_SUCCESS;
2164 /******************** Directory Combo ***************************************/
2166 static void msi_dialog_update_directory_combo( msi_dialog *dialog, msi_control *control )
2168 LPWSTR prop, path;
2169 BOOL indirect;
2171 if (!control && !(control = msi_dialog_find_control_by_type( dialog, szDirectoryCombo )))
2172 return;
2174 indirect = control->attributes & msidbControlAttributesIndirect;
2175 prop = msi_dialog_dup_property( dialog, control->property, indirect );
2176 path = msi_dialog_dup_property( dialog, prop, TRUE );
2178 PathStripPathW( path );
2179 PathRemoveBackslashW( path );
2181 SendMessageW( control->hwnd, CB_INSERTSTRING, 0, (LPARAM)path );
2182 SendMessageW( control->hwnd, CB_SETCURSEL, 0, 0 );
2184 msi_free( path );
2185 msi_free( prop );
2188 static UINT msi_dialog_directory_combo( msi_dialog *dialog, MSIRECORD *rec )
2190 msi_control *control;
2191 LPCWSTR prop;
2192 DWORD style;
2194 /* FIXME: use CBS_OWNERDRAWFIXED and add owner draw code */
2195 style = CBS_DROPDOWNLIST | CBS_HASSTRINGS | WS_CHILD |
2196 WS_GROUP | WS_TABSTOP | WS_VSCROLL;
2197 control = msi_dialog_add_control( dialog, rec, WC_COMBOBOXW, style );
2198 if (!control)
2199 return ERROR_FUNCTION_FAILED;
2201 control->attributes = MSI_RecordGetInteger( rec, 8 );
2202 prop = MSI_RecordGetString( rec, 9 );
2203 control->property = msi_dialog_dup_property( dialog, prop, FALSE );
2205 msi_dialog_update_directory_combo( dialog, control );
2207 return ERROR_SUCCESS;
2210 /******************** Directory List ***************************************/
2212 static void msi_dialog_update_directory_list( msi_dialog *dialog, msi_control *control )
2214 WCHAR dir_spec[MAX_PATH];
2215 WIN32_FIND_DATAW wfd;
2216 LPWSTR prop, path;
2217 BOOL indirect;
2218 LVITEMW item;
2219 HANDLE file;
2221 static const WCHAR asterisk[] = {'*',0};
2222 static const WCHAR dot[] = {'.',0};
2223 static const WCHAR dotdot[] = {'.','.',0};
2225 if (!control && !(control = msi_dialog_find_control_by_type( dialog, szDirectoryList )))
2226 return;
2228 /* clear the list-view */
2229 SendMessageW( control->hwnd, LVM_DELETEALLITEMS, 0, 0 );
2231 indirect = control->attributes & msidbControlAttributesIndirect;
2232 prop = msi_dialog_dup_property( dialog, control->property, indirect );
2233 path = msi_dialog_dup_property( dialog, prop, TRUE );
2235 lstrcpyW( dir_spec, path );
2236 lstrcatW( dir_spec, asterisk );
2238 file = FindFirstFileW( dir_spec, &wfd );
2239 if ( file == INVALID_HANDLE_VALUE )
2240 return;
2244 if ( wfd.dwFileAttributes != FILE_ATTRIBUTE_DIRECTORY )
2245 continue;
2247 if ( !lstrcmpW( wfd.cFileName, dot ) || !lstrcmpW( wfd.cFileName, dotdot ) )
2248 continue;
2250 item.mask = LVIF_TEXT;
2251 item.cchTextMax = MAX_PATH;
2252 item.iItem = 0;
2253 item.iSubItem = 0;
2254 item.pszText = wfd.cFileName;
2256 SendMessageW( control->hwnd, LVM_INSERTITEMW, 0, (LPARAM)&item );
2257 } while ( FindNextFileW( file, &wfd ) );
2259 msi_free( prop );
2260 msi_free( path );
2261 FindClose( file );
2264 UINT msi_dialog_directorylist_up( msi_dialog *dialog )
2266 msi_control *control;
2267 LPWSTR prop, path, ptr;
2268 BOOL indirect;
2270 control = msi_dialog_find_control_by_type( dialog, szDirectoryList );
2271 indirect = control->attributes & msidbControlAttributesIndirect;
2272 prop = msi_dialog_dup_property( dialog, control->property, indirect );
2273 path = msi_dialog_dup_property( dialog, prop, TRUE );
2275 /* strip off the last directory */
2276 ptr = PathFindFileNameW( path );
2277 if (ptr != path) *(ptr - 1) = '\0';
2278 PathAddBackslashW( path );
2280 MSI_SetPropertyW( dialog->package, prop, path );
2282 msi_dialog_update_directory_list( dialog, NULL );
2283 msi_dialog_update_directory_combo( dialog, NULL );
2284 msi_dialog_update_pathedit( dialog, NULL );
2286 msi_free( path );
2287 msi_free( prop );
2289 return ERROR_SUCCESS;
2292 static UINT msi_dialog_dirlist_handler( msi_dialog *dialog,
2293 msi_control *control, WPARAM param )
2295 LPNMHDR nmhdr = (LPNMHDR)param;
2296 WCHAR new_path[MAX_PATH];
2297 WCHAR text[MAX_PATH];
2298 LPWSTR path, prop;
2299 BOOL indirect;
2300 LVITEMW item;
2301 int index;
2303 static const WCHAR backslash[] = {'\\',0};
2305 if (nmhdr->code != LVN_ITEMACTIVATE)
2306 return ERROR_SUCCESS;
2308 index = SendMessageW( control->hwnd, LVM_GETNEXTITEM, -1, LVNI_SELECTED );
2309 if ( index < 0 )
2311 ERR("No list-view item selected!\n");
2312 return ERROR_FUNCTION_FAILED;
2315 item.iSubItem = 0;
2316 item.pszText = text;
2317 item.cchTextMax = MAX_PATH;
2318 SendMessageW( control->hwnd, LVM_GETITEMTEXTW, index, (LPARAM)&item );
2320 indirect = control->attributes & msidbControlAttributesIndirect;
2321 prop = msi_dialog_dup_property( dialog, control->property, indirect );
2322 path = msi_dialog_dup_property( dialog, prop, TRUE );
2324 lstrcpyW( new_path, path );
2325 lstrcatW( new_path, text );
2326 lstrcatW( new_path, backslash );
2328 MSI_SetPropertyW( dialog->package, prop, new_path );
2330 msi_dialog_update_directory_list( dialog, NULL );
2331 msi_dialog_update_directory_combo( dialog, NULL );
2332 msi_dialog_update_pathedit( dialog, NULL );
2334 msi_free( prop );
2335 msi_free( path );
2336 return ERROR_SUCCESS;
2339 static UINT msi_dialog_directory_list( msi_dialog *dialog, MSIRECORD *rec )
2341 msi_control *control;
2342 LPCWSTR prop;
2343 DWORD style;
2345 style = LVS_LIST | WS_VSCROLL | LVS_SHAREIMAGELISTS |
2346 LVS_AUTOARRANGE | LVS_SINGLESEL | WS_BORDER |
2347 LVS_SORTASCENDING | WS_CHILD | WS_GROUP | WS_TABSTOP;
2348 control = msi_dialog_add_control( dialog, rec, WC_LISTVIEWW, style );
2349 if (!control)
2350 return ERROR_FUNCTION_FAILED;
2352 control->attributes = MSI_RecordGetInteger( rec, 8 );
2353 control->handler = msi_dialog_dirlist_handler;
2354 prop = MSI_RecordGetString( rec, 9 );
2355 control->property = msi_dialog_dup_property( dialog, prop, FALSE );
2357 /* double click to activate an item in the list */
2358 SendMessageW( control->hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE,
2359 0, LVS_EX_TWOCLICKACTIVATE );
2361 msi_dialog_update_directory_list( dialog, control );
2363 return ERROR_SUCCESS;
2366 /******************** VolumeCost List ***************************************/
2368 static BOOL str_is_number( LPCWSTR str )
2370 int i;
2372 for (i = 0; i < lstrlenW( str ); i++)
2373 if (!isdigitW(str[i]))
2374 return FALSE;
2376 return TRUE;
2379 WCHAR column_keys[][80] =
2381 {'V','o','l','u','m','e','C','o','s','t','V','o','l','u','m','e',0},
2382 {'V','o','l','u','m','e','C','o','s','t','S','i','z','e',0},
2383 {'V','o','l','u','m','e','C','o','s','t','A','v','a','i','l','a','b','l','e',0},
2384 {'V','o','l','u','m','e','C','o','s','t','R','e','q','u','i','r','e','d',0},
2385 {'V','o','l','u','m','e','C','o','s','t','D','i','f','f','e','r','e','n','c','e',0}
2388 static void msi_dialog_vcl_add_columns( msi_dialog *dialog, msi_control *control, MSIRECORD *rec )
2390 LPCWSTR text = MSI_RecordGetString( rec, 10 );
2391 LPCWSTR begin = text, end;
2392 WCHAR num[10];
2393 LVCOLUMNW lvc;
2394 DWORD count = 0;
2396 static const WCHAR zero[] = {'0',0};
2397 static const WCHAR negative[] = {'-',0};
2399 while ((begin = strchrW( begin, '{' )) && count < 5)
2401 if (!(end = strchrW( begin, '}' )))
2402 return;
2404 lstrcpynW( num, begin + 1, end - begin );
2405 begin += end - begin + 1;
2407 /* empty braces or '0' hides the column */
2408 if ( !num[0] || !lstrcmpW( num, zero ) )
2410 count++;
2411 continue;
2414 /* the width must be a positive number
2415 * if a width is invalid, all remaining columns are hidden
2417 if ( !strncmpW( num, negative, 1 ) || !str_is_number( num ) )
2418 return;
2420 ZeroMemory( &lvc, sizeof(lvc) );
2421 lvc.mask = LVCF_TEXT | LVCF_WIDTH | LVCF_SUBITEM;
2422 lvc.cx = atolW( num );
2423 lvc.pszText = msi_dialog_get_uitext( dialog, column_keys[count] );
2425 SendMessageW( control->hwnd, LVM_INSERTCOLUMNW, count++, (LPARAM)&lvc );
2426 msi_free( lvc.pszText );
2430 static void msi_dialog_vcl_add_drives( msi_dialog *dialog, msi_control *control )
2432 ULARGE_INTEGER total, free;
2433 WCHAR size_text[MAX_PATH];
2434 LPWSTR drives, ptr;
2435 LVITEMW lvitem;
2436 DWORD size;
2437 int i = 0;
2439 size = GetLogicalDriveStringsW( 0, NULL );
2440 if ( !size ) return;
2442 drives = msi_alloc( (size + 1) * sizeof(WCHAR) );
2443 if ( !drives ) return;
2445 GetLogicalDriveStringsW( size, drives );
2447 ptr = drives;
2448 while (*ptr)
2450 lvitem.mask = LVIF_TEXT;
2451 lvitem.iItem = i;
2452 lvitem.iSubItem = 0;
2453 lvitem.pszText = ptr;
2454 lvitem.cchTextMax = lstrlenW(ptr) + 1;
2455 SendMessageW( control->hwnd, LVM_INSERTITEMW, 0, (LPARAM)&lvitem );
2457 GetDiskFreeSpaceExW(ptr, &free, &total, NULL);
2459 StrFormatByteSizeW(total.QuadPart, size_text, MAX_PATH);
2460 lvitem.iSubItem = 1;
2461 lvitem.pszText = size_text;
2462 lvitem.cchTextMax = lstrlenW(size_text) + 1;
2463 SendMessageW( control->hwnd, LVM_SETITEMW, 0, (LPARAM)&lvitem );
2465 StrFormatByteSizeW(free.QuadPart, size_text, MAX_PATH);
2466 lvitem.iSubItem = 2;
2467 lvitem.pszText = size_text;
2468 lvitem.cchTextMax = lstrlenW(size_text) + 1;
2469 SendMessageW( control->hwnd, LVM_SETITEMW, 0, (LPARAM)&lvitem );
2471 ptr += lstrlenW(ptr) + 1;
2472 i++;
2475 msi_free( drives );
2478 static UINT msi_dialog_volumecost_list( msi_dialog *dialog, MSIRECORD *rec )
2480 msi_control *control;
2481 DWORD style;
2483 style = LVS_REPORT | WS_VSCROLL | WS_HSCROLL | LVS_SHAREIMAGELISTS |
2484 LVS_AUTOARRANGE | LVS_SINGLESEL | WS_BORDER |
2485 WS_CHILD | WS_TABSTOP | WS_GROUP;
2486 control = msi_dialog_add_control( dialog, rec, WC_LISTVIEWW, style );
2487 if (!control)
2488 return ERROR_FUNCTION_FAILED;
2490 msi_dialog_vcl_add_columns( dialog, control, rec );
2491 msi_dialog_vcl_add_drives( dialog, control );
2493 return ERROR_SUCCESS;
2496 static const struct control_handler msi_dialog_handler[] =
2498 { szText, msi_dialog_text_control },
2499 { szPushButton, msi_dialog_button_control },
2500 { szLine, msi_dialog_line_control },
2501 { szBitmap, msi_dialog_bitmap_control },
2502 { szCheckBox, msi_dialog_checkbox_control },
2503 { szScrollableText, msi_dialog_scrolltext_control },
2504 { szComboBox, msi_dialog_combo_control },
2505 { szEdit, msi_dialog_edit_control },
2506 { szMaskedEdit, msi_dialog_maskedit_control },
2507 { szPathEdit, msi_dialog_pathedit_control },
2508 { szProgressBar, msi_dialog_progress_bar },
2509 { szRadioButtonGroup, msi_dialog_radiogroup_control },
2510 { szIcon, msi_dialog_icon_control },
2511 { szSelectionTree, msi_dialog_selection_tree },
2512 { szGroupBox, msi_dialog_group_box },
2513 { szListBox, msi_dialog_list_box },
2514 { szDirectoryCombo, msi_dialog_directory_combo },
2515 { szDirectoryList, msi_dialog_directory_list },
2516 { szVolumeCostList, msi_dialog_volumecost_list },
2519 #define NUM_CONTROL_TYPES (sizeof msi_dialog_handler/sizeof msi_dialog_handler[0])
2521 static UINT msi_dialog_create_controls( MSIRECORD *rec, LPVOID param )
2523 msi_dialog *dialog = param;
2524 LPCWSTR control_type;
2525 UINT i;
2527 /* find and call the function that can create this type of control */
2528 control_type = MSI_RecordGetString( rec, 3 );
2529 for( i=0; i<NUM_CONTROL_TYPES; i++ )
2530 if (!strcmpiW( msi_dialog_handler[i].control_type, control_type ))
2531 break;
2532 if( i != NUM_CONTROL_TYPES )
2533 msi_dialog_handler[i].func( dialog, rec );
2534 else
2535 ERR("no handler for element type %s\n", debugstr_w(control_type));
2537 return ERROR_SUCCESS;
2540 static UINT msi_dialog_fill_controls( msi_dialog *dialog )
2542 static const WCHAR query[] = {
2543 'S','E','L','E','C','T',' ','*',' ',
2544 'F','R','O','M',' ','C','o','n','t','r','o','l',' ',
2545 'W','H','E','R','E',' ',
2546 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',0};
2547 UINT r;
2548 MSIQUERY *view = NULL;
2549 MSIPACKAGE *package = dialog->package;
2551 TRACE("%p %s\n", dialog, debugstr_w(dialog->name) );
2553 /* query the Control table for all the elements of the control */
2554 r = MSI_OpenQuery( package->db, &view, query, dialog->name );
2555 if( r != ERROR_SUCCESS )
2557 ERR("query failed for dialog %s\n", debugstr_w(dialog->name));
2558 return ERROR_INVALID_PARAMETER;
2561 r = MSI_IterateRecords( view, 0, msi_dialog_create_controls, dialog );
2562 msiobj_release( &view->hdr );
2564 return r;
2567 static UINT msi_dialog_set_control_condition( MSIRECORD *rec, LPVOID param )
2569 static const WCHAR szHide[] = { 'H','i','d','e',0 };
2570 static const WCHAR szShow[] = { 'S','h','o','w',0 };
2571 static const WCHAR szDisable[] = { 'D','i','s','a','b','l','e',0 };
2572 static const WCHAR szEnable[] = { 'E','n','a','b','l','e',0 };
2573 msi_dialog *dialog = param;
2574 msi_control *control;
2575 LPCWSTR name, action, condition;
2576 UINT r;
2578 name = MSI_RecordGetString( rec, 2 );
2579 action = MSI_RecordGetString( rec, 3 );
2580 condition = MSI_RecordGetString( rec, 4 );
2581 r = MSI_EvaluateConditionW( dialog->package, condition );
2582 control = msi_dialog_find_control( dialog, name );
2583 if( r == MSICONDITION_TRUE && control )
2585 TRACE("%s control %s\n", debugstr_w(action), debugstr_w(name));
2587 /* FIXME: case sensitive? */
2588 if(!lstrcmpW(action, szHide))
2589 ShowWindow(control->hwnd, SW_HIDE);
2590 else if(!strcmpW(action, szShow))
2591 ShowWindow(control->hwnd, SW_SHOW);
2592 else if(!strcmpW(action, szDisable))
2593 EnableWindow(control->hwnd, FALSE);
2594 else if(!strcmpW(action, szEnable))
2595 EnableWindow(control->hwnd, TRUE);
2596 else
2597 FIXME("Unhandled action %s\n", debugstr_w(action));
2600 return ERROR_SUCCESS;
2603 static UINT msi_dialog_evaluate_control_conditions( msi_dialog *dialog )
2605 static const WCHAR query[] = {
2606 'S','E','L','E','C','T',' ','*',' ',
2607 'F','R','O','M',' ',
2608 'C','o','n','t','r','o','l','C','o','n','d','i','t','i','o','n',' ',
2609 'W','H','E','R','E',' ',
2610 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',0
2612 UINT r;
2613 MSIQUERY *view = NULL;
2614 MSIPACKAGE *package = dialog->package;
2616 TRACE("%p %s\n", dialog, debugstr_w(dialog->name) );
2618 /* query the Control table for all the elements of the control */
2619 r = MSI_OpenQuery( package->db, &view, query, dialog->name );
2620 if( r != ERROR_SUCCESS )
2621 return ERROR_SUCCESS;
2623 r = MSI_IterateRecords( view, 0, msi_dialog_set_control_condition, dialog );
2624 msiobj_release( &view->hdr );
2626 return r;
2629 UINT msi_dialog_reset( msi_dialog *dialog )
2631 /* FIXME: should restore the original values of any properties we changed */
2632 return msi_dialog_evaluate_control_conditions( dialog );
2635 /* figure out the height of 10 point MS Sans Serif */
2636 static INT msi_dialog_get_sans_serif_height( HWND hwnd )
2638 static const WCHAR szSansSerif[] = {
2639 'M','S',' ','S','a','n','s',' ','S','e','r','i','f',0 };
2640 LOGFONTW lf;
2641 TEXTMETRICW tm;
2642 BOOL r;
2643 LONG height = 0;
2644 HFONT hFont, hOldFont;
2645 HDC hdc;
2647 hdc = GetDC( hwnd );
2648 if (hdc)
2650 memset( &lf, 0, sizeof lf );
2651 lf.lfHeight = MulDiv(10, GetDeviceCaps(hdc, LOGPIXELSY), 72);
2652 strcpyW( lf.lfFaceName, szSansSerif );
2653 hFont = CreateFontIndirectW(&lf);
2654 if (hFont)
2656 hOldFont = SelectObject( hdc, hFont );
2657 r = GetTextMetricsW( hdc, &tm );
2658 if (r)
2659 height = tm.tmHeight;
2660 SelectObject( hdc, hOldFont );
2661 DeleteObject( hFont );
2663 ReleaseDC( hwnd, hdc );
2665 return height;
2668 /* fetch the associated record from the Dialog table */
2669 static MSIRECORD *msi_get_dialog_record( msi_dialog *dialog )
2671 static const WCHAR query[] = {
2672 'S','E','L','E','C','T',' ','*',' ',
2673 'F','R','O','M',' ','D','i','a','l','o','g',' ',
2674 'W','H','E','R','E',' ',
2675 '`','D','i','a','l','o','g','`',' ','=',' ','\'','%','s','\'',0};
2676 MSIPACKAGE *package = dialog->package;
2677 MSIRECORD *rec = NULL;
2679 TRACE("%p %s\n", dialog, debugstr_w(dialog->name) );
2681 rec = MSI_QueryGetRecord( package->db, query, dialog->name );
2682 if( !rec )
2683 ERR("query failed for dialog %s\n", debugstr_w(dialog->name));
2685 return rec;
2688 static void msi_dialog_adjust_dialog_pos( msi_dialog *dialog, MSIRECORD *rec, LPRECT pos )
2690 static const WCHAR szScreenX[] = {'S','c','r','e','e','n','X',0};
2691 static const WCHAR szScreenY[] = {'S','c','r','e','e','n','Y',0};
2693 UINT xres, yres;
2694 POINT center;
2695 SIZE sz;
2696 LONG style;
2698 center.x = MSI_RecordGetInteger( rec, 2 );
2699 center.y = MSI_RecordGetInteger( rec, 3 );
2701 sz.cx = MSI_RecordGetInteger( rec, 4 );
2702 sz.cy = MSI_RecordGetInteger( rec, 5 );
2704 sz.cx = msi_dialog_scale_unit( dialog, sz.cx );
2705 sz.cy = msi_dialog_scale_unit( dialog, sz.cy );
2707 xres = msi_get_property_int( dialog->package, szScreenX, 0 );
2708 yres = msi_get_property_int( dialog->package, szScreenY, 0 );
2710 center.x = MulDiv( center.x, xres, 100 );
2711 center.y = MulDiv( center.y, yres, 100 );
2713 /* turn the client pos into the window rectangle */
2714 if (dialog->package->center_x && dialog->package->center_y)
2716 pos->left = dialog->package->center_x - sz.cx / 2.0;
2717 pos->right = pos->left + sz.cx;
2718 pos->top = dialog->package->center_y - sz.cy / 2.0;
2719 pos->bottom = pos->top + sz.cy;
2721 else
2723 pos->left = center.x - sz.cx/2;
2724 pos->right = pos->left + sz.cx;
2725 pos->top = center.y - sz.cy/2;
2726 pos->bottom = pos->top + sz.cy;
2728 /* save the center */
2729 dialog->package->center_x = center.x;
2730 dialog->package->center_y = center.y;
2733 dialog->size.cx = sz.cx;
2734 dialog->size.cy = sz.cy;
2736 TRACE("%u %u %u %u\n", pos->left, pos->top, pos->right, pos->bottom);
2738 style = GetWindowLongPtrW( dialog->hwnd, GWL_STYLE );
2739 AdjustWindowRect( pos, style, FALSE );
2742 static BOOL msi_control_set_next( msi_control *control, msi_control *next )
2744 return SetWindowPos( next->hwnd, control->hwnd, 0, 0, 0, 0,
2745 SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOREDRAW |
2746 SWP_NOREPOSITION | SWP_NOSENDCHANGING | SWP_NOSIZE );
2749 static UINT msi_dialog_set_tab_order( msi_dialog *dialog )
2751 msi_control *control, *tab_next;
2753 LIST_FOR_EACH_ENTRY( control, &dialog->controls, msi_control, entry )
2755 tab_next = msi_dialog_find_control( dialog, control->tabnext );
2756 if( !tab_next )
2757 continue;
2758 msi_control_set_next( control, tab_next );
2761 return ERROR_SUCCESS;
2764 static void msi_dialog_set_first_control( msi_dialog* dialog, LPCWSTR name )
2766 msi_control *control;
2768 control = msi_dialog_find_control( dialog, name );
2769 if( control )
2770 dialog->hWndFocus = control->hwnd;
2771 else
2772 dialog->hWndFocus = NULL;
2775 static LRESULT msi_dialog_oncreate( HWND hwnd, LPCREATESTRUCTW cs )
2777 static const WCHAR df[] = {
2778 'D','e','f','a','u','l','t','U','I','F','o','n','t',0 };
2779 static const WCHAR dfv[] = {
2780 'M','S',' ','S','h','e','l','l',' ','D','l','g',0 };
2781 msi_dialog *dialog = (msi_dialog*) cs->lpCreateParams;
2782 MSIRECORD *rec = NULL;
2783 LPWSTR title = NULL;
2784 RECT pos;
2786 TRACE("%p %p\n", dialog, dialog->package);
2788 dialog->hwnd = hwnd;
2789 SetWindowLongPtrW( hwnd, GWLP_USERDATA, (LONG_PTR) dialog );
2791 rec = msi_get_dialog_record( dialog );
2792 if( !rec )
2794 TRACE("No record found for dialog %s\n", debugstr_w(dialog->name));
2795 return -1;
2798 dialog->scale = msi_dialog_get_sans_serif_height(dialog->hwnd);
2800 msi_dialog_adjust_dialog_pos( dialog, rec, &pos );
2802 dialog->attributes = MSI_RecordGetInteger( rec, 6 );
2804 dialog->default_font = msi_dup_property( dialog->package, df );
2805 if (!dialog->default_font)
2807 dialog->default_font = strdupW(dfv);
2808 if (!dialog->default_font) return -1;
2811 title = msi_get_deformatted_field( dialog->package, rec, 7 );
2812 SetWindowTextW( hwnd, title );
2813 msi_free( title );
2815 SetWindowPos( hwnd, 0, pos.left, pos.top,
2816 pos.right - pos.left, pos.bottom - pos.top,
2817 SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOREDRAW );
2819 msi_dialog_build_font_list( dialog );
2820 msi_dialog_fill_controls( dialog );
2821 msi_dialog_evaluate_control_conditions( dialog );
2822 msi_dialog_set_tab_order( dialog );
2823 msi_dialog_set_first_control( dialog, MSI_RecordGetString( rec, 8 ) );
2824 msiobj_release( &rec->hdr );
2826 return 0;
2829 static UINT msi_dialog_send_event( msi_dialog *dialog, LPCWSTR event, LPCWSTR arg )
2831 LPWSTR event_fmt = NULL, arg_fmt = NULL;
2833 TRACE("Sending control event %s %s\n", debugstr_w(event), debugstr_w(arg));
2835 deformat_string( dialog->package, event, &event_fmt );
2836 deformat_string( dialog->package, arg, &arg_fmt );
2838 dialog->event_handler( dialog->package, event_fmt, arg_fmt, dialog );
2840 msi_free( event_fmt );
2841 msi_free( arg_fmt );
2843 return ERROR_SUCCESS;
2846 static UINT msi_dialog_set_property( msi_dialog *dialog, LPCWSTR event, LPCWSTR arg )
2848 static const WCHAR szNullArg[] = { '{','}',0 };
2849 LPWSTR p, prop, arg_fmt = NULL;
2850 UINT len;
2852 len = strlenW(event);
2853 prop = msi_alloc( len*sizeof(WCHAR));
2854 strcpyW( prop, &event[1] );
2855 p = strchrW( prop, ']' );
2856 if( p && p[1] == 0 )
2858 *p = 0;
2859 if( strcmpW( szNullArg, arg ) )
2860 deformat_string( dialog->package, arg, &arg_fmt );
2861 MSI_SetPropertyW( dialog->package, prop, arg_fmt );
2862 msi_free( arg_fmt );
2864 else
2865 ERR("Badly formatted property string - what happens?\n");
2866 msi_free( prop );
2867 return ERROR_SUCCESS;
2870 static UINT msi_dialog_control_event( MSIRECORD *rec, LPVOID param )
2872 msi_dialog *dialog = param;
2873 LPCWSTR condition, event, arg;
2874 UINT r;
2876 condition = MSI_RecordGetString( rec, 5 );
2877 r = MSI_EvaluateConditionW( dialog->package, condition );
2878 if( r == MSICONDITION_TRUE || r == MSICONDITION_NONE )
2880 event = MSI_RecordGetString( rec, 3 );
2881 arg = MSI_RecordGetString( rec, 4 );
2882 if( event[0] == '[' )
2883 msi_dialog_set_property( dialog, event, arg );
2884 else
2885 msi_dialog_send_event( dialog, event, arg );
2888 return ERROR_SUCCESS;
2891 struct rec_list
2893 struct list entry;
2894 MSIRECORD *rec;
2897 static UINT add_rec_to_list( MSIRECORD *rec, LPVOID param )
2899 struct rec_list *add_rec;
2900 struct list *records = (struct list *)param;
2902 msiobj_addref( &rec->hdr );
2904 add_rec = msi_alloc( sizeof( *add_rec ) );
2905 if (!add_rec)
2907 msiobj_release( &rec->hdr );
2908 return ERROR_OUTOFMEMORY;
2911 add_rec->rec = rec;
2912 list_add_tail( records, &add_rec->entry );
2913 return ERROR_SUCCESS;
2916 static inline void remove_rec_from_list( struct rec_list *rec_entry )
2918 msiobj_release( &rec_entry->rec->hdr );
2919 list_remove( &rec_entry->entry );
2920 msi_free( rec_entry );
2923 static UINT msi_dialog_button_handler( msi_dialog *dialog,
2924 msi_control *control, WPARAM param )
2926 static const WCHAR query[] = {
2927 'S','E','L','E','C','T',' ','*',' ',
2928 'F','R','O','M',' ','C','o','n','t','r','o','l','E','v','e','n','t',' ',
2929 'W','H','E','R','E',' ',
2930 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',' ',
2931 'A','N','D',' ',
2932 '`','C','o','n','t','r','o','l','_','`',' ','=',' ','\'','%','s','\'',' ',
2933 'O','R','D','E','R',' ','B','Y',' ','`','O','r','d','e','r','i','n','g','`',0
2935 MSIQUERY *view = NULL;
2936 struct rec_list *rec_entry, *next;
2937 struct list events;
2938 UINT r;
2940 if( HIWORD(param) != BN_CLICKED )
2941 return ERROR_SUCCESS;
2943 list_init( &events );
2945 r = MSI_OpenQuery( dialog->package->db, &view, query,
2946 dialog->name, control->name );
2947 if( r != ERROR_SUCCESS )
2949 ERR("query failed\n");
2950 return 0;
2953 r = MSI_IterateRecords( view, 0, add_rec_to_list, &events );
2954 msiobj_release( &view->hdr );
2955 if (r != ERROR_SUCCESS)
2956 goto done;
2958 /* handle all SetProperty events first */
2959 LIST_FOR_EACH_ENTRY_SAFE( rec_entry, next, &events, struct rec_list, entry )
2961 LPCWSTR event = MSI_RecordGetString( rec_entry->rec, 3 );
2963 if ( event[0] != '[' )
2964 continue;
2966 r = msi_dialog_control_event( rec_entry->rec, dialog );
2967 remove_rec_from_list( rec_entry );
2969 if ( r != ERROR_SUCCESS )
2970 goto done;
2973 /* handle all other events */
2974 LIST_FOR_EACH_ENTRY_SAFE( rec_entry, next, &events, struct rec_list, entry )
2976 r = msi_dialog_control_event( rec_entry->rec, dialog );
2977 remove_rec_from_list( rec_entry );
2979 if ( r != ERROR_SUCCESS )
2980 goto done;
2983 done:
2984 LIST_FOR_EACH_ENTRY_SAFE( rec_entry, next, &events, struct rec_list, entry )
2986 remove_rec_from_list( rec_entry );
2989 return r;
2992 static UINT msi_dialog_get_checkbox_state( msi_dialog *dialog,
2993 msi_control *control )
2995 WCHAR state[2] = { 0 };
2996 DWORD sz = 2;
2998 MSI_GetPropertyW( dialog->package, control->property, state, &sz );
2999 return state[0] ? 1 : 0;
3002 static void msi_dialog_set_checkbox_state( msi_dialog *dialog,
3003 msi_control *control, UINT state )
3005 static const WCHAR szState[] = { '1', 0 };
3006 LPCWSTR val;
3008 /* if uncheck then the property is set to NULL */
3009 if (!state)
3011 MSI_SetPropertyW( dialog->package, control->property, NULL );
3012 return;
3015 /* check for a custom state */
3016 if (control->value && control->value[0])
3017 val = control->value;
3018 else
3019 val = szState;
3021 MSI_SetPropertyW( dialog->package, control->property, val );
3024 static void msi_dialog_checkbox_sync_state( msi_dialog *dialog,
3025 msi_control *control )
3027 UINT state;
3029 state = msi_dialog_get_checkbox_state( dialog, control );
3030 SendMessageW( control->hwnd, BM_SETCHECK,
3031 state ? BST_CHECKED : BST_UNCHECKED, 0 );
3034 static UINT msi_dialog_checkbox_handler( msi_dialog *dialog,
3035 msi_control *control, WPARAM param )
3037 UINT state;
3039 if( HIWORD(param) != BN_CLICKED )
3040 return ERROR_SUCCESS;
3042 TRACE("clicked checkbox %s, set %s\n", debugstr_w(control->name),
3043 debugstr_w(control->property));
3045 state = msi_dialog_get_checkbox_state( dialog, control );
3046 state = state ? 0 : 1;
3047 msi_dialog_set_checkbox_state( dialog, control, state );
3048 msi_dialog_checkbox_sync_state( dialog, control );
3050 return msi_dialog_button_handler( dialog, control, param );
3053 static UINT msi_dialog_edit_handler( msi_dialog *dialog,
3054 msi_control *control, WPARAM param )
3056 LPWSTR buf;
3058 if( HIWORD(param) != EN_CHANGE )
3059 return ERROR_SUCCESS;
3061 TRACE("edit %s contents changed, set %s\n", debugstr_w(control->name),
3062 debugstr_w(control->property));
3064 buf = msi_get_window_text( control->hwnd );
3065 MSI_SetPropertyW( dialog->package, control->property, buf );
3067 msi_free( buf );
3069 return ERROR_SUCCESS;
3072 static UINT msi_dialog_radiogroup_handler( msi_dialog *dialog,
3073 msi_control *control, WPARAM param )
3075 if( HIWORD(param) != BN_CLICKED )
3076 return ERROR_SUCCESS;
3078 TRACE("clicked radio button %s, set %s\n", debugstr_w(control->name),
3079 debugstr_w(control->property));
3081 MSI_SetPropertyW( dialog->package, control->property, control->name );
3083 return msi_dialog_button_handler( dialog, control, param );
3086 static LRESULT msi_dialog_oncommand( msi_dialog *dialog, WPARAM param, HWND hwnd )
3088 msi_control *control = NULL;
3090 TRACE("%p %p %08x\n", dialog, hwnd, param);
3092 switch (param)
3094 case 1: /* enter */
3095 control = msi_dialog_find_control( dialog, dialog->control_default );
3096 break;
3097 case 2: /* escape */
3098 control = msi_dialog_find_control( dialog, dialog->control_cancel );
3099 break;
3100 default:
3101 control = msi_dialog_find_control_by_hwnd( dialog, hwnd );
3104 if( control )
3106 if( control->handler )
3108 control->handler( dialog, control, param );
3109 msi_dialog_evaluate_control_conditions( dialog );
3112 else
3113 ERR("button click from nowhere %p %d %p\n", dialog, param, hwnd);
3114 return 0;
3117 static LRESULT msi_dialog_onnotify( msi_dialog *dialog, LPARAM param )
3119 LPNMHDR nmhdr = (LPNMHDR) param;
3120 msi_control *control = msi_dialog_find_control_by_hwnd( dialog, nmhdr->hwndFrom );
3122 TRACE("%p %p\n", dialog, nmhdr->hwndFrom);
3124 if ( control && control->handler )
3125 control->handler( dialog, control, param );
3127 return 0;
3130 static void msi_dialog_setfocus( msi_dialog *dialog )
3132 HWND hwnd = dialog->hWndFocus;
3134 hwnd = GetNextDlgTabItem( dialog->hwnd, hwnd, TRUE);
3135 hwnd = GetNextDlgTabItem( dialog->hwnd, hwnd, FALSE);
3136 SetFocus( hwnd );
3137 dialog->hWndFocus = hwnd;
3140 static LRESULT WINAPI MSIDialog_WndProc( HWND hwnd, UINT msg,
3141 WPARAM wParam, LPARAM lParam )
3143 msi_dialog *dialog = (LPVOID) GetWindowLongPtrW( hwnd, GWLP_USERDATA );
3145 TRACE("0x%04x\n", msg);
3147 switch (msg)
3149 case WM_MOVE:
3150 dialog->package->center_x = LOWORD(lParam) + dialog->size.cx / 2.0;
3151 dialog->package->center_y = HIWORD(lParam) + dialog->size.cy / 2.0;
3152 break;
3154 case WM_CREATE:
3155 return msi_dialog_oncreate( hwnd, (LPCREATESTRUCTW)lParam );
3157 case WM_COMMAND:
3158 return msi_dialog_oncommand( dialog, wParam, (HWND)lParam );
3160 case WM_ACTIVATE:
3161 if( LOWORD(wParam) == WA_INACTIVE )
3162 dialog->hWndFocus = GetFocus();
3163 else
3164 msi_dialog_setfocus( dialog );
3165 return 0;
3167 case WM_SETFOCUS:
3168 msi_dialog_setfocus( dialog );
3169 return 0;
3171 /* bounce back to our subclassed static control */
3172 case WM_CTLCOLORSTATIC:
3173 return SendMessageW( (HWND) lParam, WM_CTLCOLORSTATIC, wParam, lParam );
3175 case WM_DESTROY:
3176 dialog->hwnd = NULL;
3177 return 0;
3178 case WM_NOTIFY:
3179 return msi_dialog_onnotify( dialog, lParam );
3181 return DefWindowProcW(hwnd, msg, wParam, lParam);
3184 static BOOL CALLBACK msi_radioground_child_enum( HWND hWnd, LPARAM lParam )
3186 EnableWindow( hWnd, lParam );
3187 return TRUE;
3190 static LRESULT WINAPI MSIRadioGroup_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
3192 WNDPROC oldproc = (WNDPROC) GetPropW(hWnd, szButtonData);
3193 LRESULT r;
3195 TRACE("hWnd %p msg %04x wParam 0x%08x lParam 0x%08lx\n", hWnd, msg, wParam, lParam);
3197 if (msg == WM_COMMAND) /* Forward notifications to dialog */
3198 SendMessageW(GetParent(hWnd), msg, wParam, lParam);
3200 r = CallWindowProcW(oldproc, hWnd, msg, wParam, lParam);
3202 /* make sure the radio buttons show as disabled if the parent is disabled */
3203 if (msg == WM_ENABLE)
3204 EnumChildWindows( hWnd, msi_radioground_child_enum, wParam );
3206 return r;
3209 static LRESULT WINAPI MSIHiddenWindowProc( HWND hwnd, UINT msg,
3210 WPARAM wParam, LPARAM lParam )
3212 msi_dialog *dialog = (msi_dialog*) lParam;
3214 TRACE("%d %p\n", msg, dialog);
3216 switch (msg)
3218 case WM_MSI_DIALOG_CREATE:
3219 return msi_dialog_run_message_loop( dialog );
3220 case WM_MSI_DIALOG_DESTROY:
3221 msi_dialog_destroy( dialog );
3222 return 0;
3224 return DefWindowProcW( hwnd, msg, wParam, lParam );
3227 /* functions that interface to other modules within MSI */
3229 msi_dialog *msi_dialog_create( MSIPACKAGE* package,
3230 LPCWSTR szDialogName, msi_dialog *parent,
3231 msi_dialog_event_handler event_handler )
3233 MSIRECORD *rec = NULL;
3234 msi_dialog *dialog;
3236 TRACE("%p %s\n", package, debugstr_w(szDialogName));
3238 /* allocate the structure for the dialog to use */
3239 dialog = msi_alloc_zero( sizeof *dialog + sizeof(WCHAR)*strlenW(szDialogName) );
3240 if( !dialog )
3241 return NULL;
3242 strcpyW( dialog->name, szDialogName );
3243 dialog->parent = parent;
3244 msiobj_addref( &package->hdr );
3245 dialog->package = package;
3246 dialog->event_handler = event_handler;
3247 dialog->finished = 0;
3248 list_init( &dialog->controls );
3250 /* verify that the dialog exists */
3251 rec = msi_get_dialog_record( dialog );
3252 if( !rec )
3254 msiobj_release( &package->hdr );
3255 msi_free( dialog );
3256 return NULL;
3258 dialog->attributes = MSI_RecordGetInteger( rec, 6 );
3259 dialog->control_default = strdupW( MSI_RecordGetString( rec, 9 ) );
3260 dialog->control_cancel = strdupW( MSI_RecordGetString( rec, 10 ) );
3261 msiobj_release( &rec->hdr );
3263 return dialog;
3266 static void msi_process_pending_messages( HWND hdlg )
3268 MSG msg;
3270 while( PeekMessageW( &msg, 0, 0, 0, PM_REMOVE ) )
3272 if( hdlg && IsDialogMessageW( hdlg, &msg ))
3273 continue;
3274 TranslateMessage( &msg );
3275 DispatchMessageW( &msg );
3279 void msi_dialog_end_dialog( msi_dialog *dialog )
3281 TRACE("%p\n", dialog);
3282 dialog->finished = 1;
3283 PostMessageW(dialog->hwnd, WM_NULL, 0, 0);
3286 void msi_dialog_check_messages( HANDLE handle )
3288 DWORD r;
3290 /* in threads other than the UI thread, block */
3291 if( uiThreadId != GetCurrentThreadId() )
3293 if( handle )
3294 WaitForSingleObject( handle, INFINITE );
3295 return;
3298 /* there's two choices for the UI thread */
3299 while (1)
3301 msi_process_pending_messages( NULL );
3303 if( !handle )
3304 break;
3307 * block here until somebody creates a new dialog or
3308 * the handle we're waiting on becomes ready
3310 r = MsgWaitForMultipleObjects( 1, &handle, 0, INFINITE, QS_ALLINPUT );
3311 if( r == WAIT_OBJECT_0 )
3312 break;
3316 UINT msi_dialog_run_message_loop( msi_dialog *dialog )
3318 DWORD style;
3319 HWND hwnd;
3321 if( uiThreadId != GetCurrentThreadId() )
3322 return SendMessageW( hMsiHiddenWindow, WM_MSI_DIALOG_CREATE, 0, (LPARAM) dialog );
3324 /* create the dialog window, don't show it yet */
3325 style = WS_OVERLAPPED;
3326 if( dialog->attributes & msidbDialogAttributesVisible )
3327 style |= WS_VISIBLE;
3329 hwnd = CreateWindowW( szMsiDialogClass, dialog->name, style,
3330 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
3331 NULL, NULL, NULL, dialog );
3332 if( !hwnd )
3334 ERR("Failed to create dialog %s\n", debugstr_w( dialog->name ));
3335 return ERROR_FUNCTION_FAILED;
3338 ShowWindow( hwnd, SW_SHOW );
3339 /* UpdateWindow( hwnd ); - and causes the transparent static controls not to paint */
3341 if( dialog->attributes & msidbDialogAttributesModal )
3343 while( !dialog->finished )
3345 MsgWaitForMultipleObjects( 0, NULL, 0, INFINITE, QS_ALLINPUT );
3346 msi_process_pending_messages( dialog->hwnd );
3349 else
3350 return ERROR_IO_PENDING;
3352 return ERROR_SUCCESS;
3355 void msi_dialog_do_preview( msi_dialog *dialog )
3357 TRACE("\n");
3358 dialog->attributes |= msidbDialogAttributesVisible;
3359 dialog->attributes &= ~msidbDialogAttributesModal;
3360 msi_dialog_run_message_loop( dialog );
3363 void msi_dialog_destroy( msi_dialog *dialog )
3365 if( uiThreadId != GetCurrentThreadId() )
3367 SendMessageW( hMsiHiddenWindow, WM_MSI_DIALOG_DESTROY, 0, (LPARAM) dialog );
3368 return;
3371 if( dialog->hwnd )
3372 ShowWindow( dialog->hwnd, SW_HIDE );
3374 if( dialog->hwnd )
3375 DestroyWindow( dialog->hwnd );
3377 /* destroy the list of controls */
3378 while( !list_empty( &dialog->controls ) )
3380 msi_control *t = LIST_ENTRY( list_head( &dialog->controls ),
3381 msi_control, entry );
3382 list_remove( &t->entry );
3383 /* leave dialog->hwnd - destroying parent destroys child windows */
3384 msi_free( t->property );
3385 msi_free( t->value );
3386 if( t->hBitmap )
3387 DeleteObject( t->hBitmap );
3388 if( t->hIcon )
3389 DestroyIcon( t->hIcon );
3390 msi_free( t->tabnext );
3391 msi_free( t->type );
3392 msi_free( t );
3393 if (t->hDll)
3394 FreeLibrary( t->hDll );
3397 /* destroy the list of fonts */
3398 while( dialog->font_list )
3400 msi_font *t = dialog->font_list;
3401 dialog->font_list = t->next;
3402 DeleteObject( t->hfont );
3403 msi_free( t );
3405 msi_free( dialog->default_font );
3407 msi_free( dialog->control_default );
3408 msi_free( dialog->control_cancel );
3409 msiobj_release( &dialog->package->hdr );
3410 dialog->package = NULL;
3411 msi_free( dialog );
3414 BOOL msi_dialog_register_class( void )
3416 WNDCLASSW cls;
3418 ZeroMemory( &cls, sizeof cls );
3419 cls.lpfnWndProc = MSIDialog_WndProc;
3420 cls.hInstance = NULL;
3421 cls.hIcon = LoadIconW(0, (LPWSTR)IDI_APPLICATION);
3422 cls.hCursor = LoadCursorW(0, (LPWSTR)IDC_ARROW);
3423 cls.hbrBackground = (HBRUSH)(COLOR_3DFACE + 1);
3424 cls.lpszMenuName = NULL;
3425 cls.lpszClassName = szMsiDialogClass;
3427 if( !RegisterClassW( &cls ) )
3428 return FALSE;
3430 cls.lpfnWndProc = MSIHiddenWindowProc;
3431 cls.lpszClassName = szMsiHiddenWindow;
3433 if( !RegisterClassW( &cls ) )
3434 return FALSE;
3436 uiThreadId = GetCurrentThreadId();
3438 hMsiHiddenWindow = CreateWindowW( szMsiHiddenWindow, NULL, WS_OVERLAPPED,
3439 0, 0, 100, 100, NULL, NULL, NULL, NULL );
3440 if( !hMsiHiddenWindow )
3441 return FALSE;
3443 return TRUE;
3446 void msi_dialog_unregister_class( void )
3448 DestroyWindow( hMsiHiddenWindow );
3449 hMsiHiddenWindow = NULL;
3450 UnregisterClassW( szMsiDialogClass, NULL );
3451 UnregisterClassW( szMsiHiddenWindow, NULL );
3452 uiThreadId = 0;
3455 static UINT error_dialog_handler(MSIPACKAGE *package, LPCWSTR event,
3456 LPCWSTR argument, msi_dialog* dialog)
3458 static const WCHAR end_dialog[] = {'E','n','d','D','i','a','l','o','g',0};
3459 static const WCHAR error_abort[] = {'E','r','r','o','r','A','b','o','r','t',0};
3460 static const WCHAR error_cancel[] = {'E','r','r','o','r','C','a','n','c','e','l',0};
3461 static const WCHAR error_no[] = {'E','r','r','o','r','N','o',0};
3462 static const WCHAR result_prop[] = {
3463 'M','S','I','E','r','r','o','r','D','i','a','l','o','g','R','e','s','u','l','t',0
3466 if ( lstrcmpW( event, end_dialog ) )
3467 return ERROR_SUCCESS;
3469 if ( !lstrcmpW( argument, error_abort ) || !lstrcmpW( argument, error_cancel ) ||
3470 !lstrcmpW( argument, error_no ) )
3472 MSI_SetPropertyW( package, result_prop, error_abort );
3475 ControlEvent_CleanupSubscriptions(package);
3476 msi_dialog_end_dialog( dialog );
3478 return ERROR_SUCCESS;
3481 static UINT msi_error_dialog_set_error( MSIPACKAGE *package, LPWSTR error_dialog, LPWSTR error )
3483 MSIRECORD * row;
3485 static const WCHAR update[] =
3486 {'U','P','D','A','T','E',' ','`','C','o','n','t','r','o','l','`',' ',
3487 'S','E','T',' ','`','T','e','x','t','`',' ','=',' ','\'','%','s','\'',' ',
3488 'W','H','E','R','E', ' ','`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',' ',
3489 'A','N','D',' ','`','C','o','n','t','r','o','l','`',' ','=',' ',
3490 '\'','E','r','r','o','r','T','e','x','t','\'',0};
3492 row = MSI_QueryGetRecord( package->db, update, error, error_dialog );
3493 if (!row)
3494 return ERROR_FUNCTION_FAILED;
3496 msiobj_release(&row->hdr);
3497 return ERROR_SUCCESS;
3500 UINT msi_spawn_error_dialog( MSIPACKAGE *package, LPWSTR error_dialog, LPWSTR error )
3502 msi_dialog *dialog;
3503 WCHAR result[MAX_PATH];
3504 UINT r = ERROR_SUCCESS;
3505 DWORD size = MAX_PATH;
3506 int res;
3508 static const WCHAR pn_prop[] = {'P','r','o','d','u','c','t','N','a','m','e',0};
3509 static const WCHAR title_fmt[] = {'%','s',' ','W','a','r','n','i','n','g',0};
3510 static const WCHAR error_abort[] = {'E','r','r','o','r','A','b','o','r','t',0};
3511 static const WCHAR result_prop[] = {
3512 'M','S','I','E','r','r','o','r','D','i','a','l','o','g','R','e','s','u','l','t',0
3515 if ( !error_dialog )
3517 LPWSTR product_name = msi_dup_property( package, pn_prop );
3518 WCHAR title[MAX_PATH];
3520 sprintfW( title, title_fmt, product_name );
3521 res = MessageBoxW( NULL, error, title, MB_OKCANCEL | MB_ICONWARNING );
3523 msi_free( product_name );
3525 if ( res == IDOK )
3526 return ERROR_SUCCESS;
3527 else
3528 return ERROR_FUNCTION_FAILED;
3531 r = msi_error_dialog_set_error( package, error_dialog, error );
3532 if ( r != ERROR_SUCCESS )
3533 return r;
3535 dialog = msi_dialog_create( package, error_dialog, package->dialog,
3536 error_dialog_handler );
3537 if ( !dialog )
3538 return ERROR_FUNCTION_FAILED;
3540 dialog->finished = FALSE;
3541 r = msi_dialog_run_message_loop( dialog );
3542 if ( r != ERROR_SUCCESS )
3543 goto done;
3545 r = MSI_GetPropertyW( package, result_prop, result, &size );
3546 if ( r != ERROR_SUCCESS)
3547 r = ERROR_SUCCESS;
3549 if ( !lstrcmpW( result, error_abort ) )
3550 r = ERROR_FUNCTION_FAILED;
3552 done:
3553 msi_dialog_destroy( dialog );
3555 return r;