quartz: Free two assert calls from having side effects.
[wine/testsucceed.git] / dlls / msi / dialog.c
blob7074a7be67d803067c6bd324bd3595a1f13e3ce5
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"
41 #include "msiserver.h"
43 #include "wine/debug.h"
44 #include "wine/unicode.h"
46 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 );
53 typedef void (*msi_update)( msi_dialog *, msi_control * );
55 struct msi_control_tag
57 struct list entry;
58 HWND hwnd;
59 msi_handler handler;
60 msi_update update;
61 LPWSTR property;
62 LPWSTR value;
63 HBITMAP hBitmap;
64 HICON hIcon;
65 LPWSTR tabnext;
66 LPWSTR type;
67 HMODULE hDll;
68 float progress_current;
69 float progress_max;
70 BOOL progress_backwards;
71 DWORD attributes;
72 WCHAR name[1];
75 typedef struct msi_font_tag
77 struct list entry;
78 HFONT hfont;
79 COLORREF color;
80 WCHAR name[1];
81 } msi_font;
83 struct msi_dialog_tag
85 MSIPACKAGE *package;
86 msi_dialog *parent;
87 msi_dialog_event_handler event_handler;
88 BOOL finished;
89 INT scale;
90 DWORD attributes;
91 SIZE size;
92 HWND hwnd;
93 LPWSTR default_font;
94 struct list fonts;
95 struct list controls;
96 HWND hWndFocus;
97 LPWSTR control_default;
98 LPWSTR control_cancel;
99 WCHAR name[1];
102 typedef UINT (*msi_dialog_control_func)( msi_dialog *dialog, MSIRECORD *rec );
103 struct control_handler
105 LPCWSTR control_type;
106 msi_dialog_control_func func;
109 typedef struct
111 msi_dialog* dialog;
112 msi_control *parent;
113 DWORD attributes;
114 LPWSTR propval;
115 } radio_button_group_descr;
117 static const WCHAR szMsiDialogClass[] = { 'M','s','i','D','i','a','l','o','g','C','l','o','s','e','C','l','a','s','s',0 };
118 static const WCHAR szMsiHiddenWindow[] = { '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[] = { 'S','c','r','o','l','l','a','b','l','e','T','e','x','t',0 };
129 static const WCHAR szComboBox[] = { 'C','o','m','b','o','B','o','x',0 };
130 static const WCHAR szEdit[] = { 'E','d','i','t',0 };
131 static const WCHAR szMaskedEdit[] = { 'M','a','s','k','e','d','E','d','i','t',0 };
132 static const WCHAR szPathEdit[] = { 'P','a','t','h','E','d','i','t',0 };
133 static const WCHAR szProgressBar[] = { 'P','r','o','g','r','e','s','s','B','a','r',0 };
134 static const WCHAR szSetProgress[] = { 'S','e','t','P','r','o','g','r','e','s','s',0 };
135 static const WCHAR szRadioButtonGroup[] = { 'R','a','d','i','o','B','u','t','t','o','n','G','r','o','u','p',0 };
136 static const WCHAR szIcon[] = { 'I','c','o','n',0 };
137 static const WCHAR szSelectionTree[] = { 'S','e','l','e','c','t','i','o','n','T','r','e','e',0 };
138 static const WCHAR szGroupBox[] = { 'G','r','o','u','p','B','o','x',0 };
139 static const WCHAR szListBox[] = { 'L','i','s','t','B','o','x',0 };
140 static const WCHAR szDirectoryCombo[] = { 'D','i','r','e','c','t','o','r','y','C','o','m','b','o',0 };
141 static const WCHAR szDirectoryList[] = { 'D','i','r','e','c','t','o','r','y','L','i','s','t',0 };
142 static const WCHAR szVolumeCostList[] = { 'V','o','l','u','m','e','C','o','s','t','L','i','s','t',0 };
143 static const WCHAR szVolumeSelectCombo[] = { 'V','o','l','u','m','e','S','e','l','e','c','t','C','o','m','b','o',0 };
144 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};
145 static const WCHAR szSelectionPath[] = {'S','e','l','e','c','t','i','o','n','P','a','t','h',0};
146 static const WCHAR szProperty[] = {'P','r','o','p','e','r','t','y',0};
148 /* dialog sequencing */
150 #define WM_MSI_DIALOG_CREATE (WM_USER+0x100)
151 #define WM_MSI_DIALOG_DESTROY (WM_USER+0x101)
153 #define USER_INSTALLSTATE_ALL 0x1000
155 static DWORD uiThreadId;
156 static HWND hMsiHiddenWindow;
158 static LPWSTR msi_get_window_text( HWND hwnd )
160 UINT sz, r;
161 LPWSTR buf;
163 sz = 0x20;
164 buf = msi_alloc( sz*sizeof(WCHAR) );
165 while ( buf )
167 r = GetWindowTextW( hwnd, buf, sz );
168 if ( r < (sz - 1) )
169 break;
170 sz *= 2;
171 buf = msi_realloc( buf, sz*sizeof(WCHAR) );
174 return buf;
177 static INT msi_dialog_scale_unit( msi_dialog *dialog, INT val )
179 return MulDiv( val, dialog->scale, 12 );
182 static msi_control *msi_dialog_find_control( msi_dialog *dialog, LPCWSTR name )
184 msi_control *control;
186 if( !name )
187 return NULL;
188 if( !dialog->hwnd )
189 return NULL;
190 LIST_FOR_EACH_ENTRY( control, &dialog->controls, msi_control, entry )
191 if( !strcmpW( control->name, name ) ) /* FIXME: case sensitive? */
192 return control;
193 return NULL;
196 static msi_control *msi_dialog_find_control_by_type( msi_dialog *dialog, LPCWSTR type )
198 msi_control *control;
200 if( !type )
201 return NULL;
202 if( !dialog->hwnd )
203 return NULL;
204 LIST_FOR_EACH_ENTRY( control, &dialog->controls, msi_control, entry )
205 if( !strcmpW( control->type, type ) ) /* FIXME: case sensitive? */
206 return control;
207 return NULL;
210 static msi_control *msi_dialog_find_control_by_hwnd( msi_dialog *dialog, HWND hwnd )
212 msi_control *control;
214 if( !dialog->hwnd )
215 return NULL;
216 LIST_FOR_EACH_ENTRY( control, &dialog->controls, msi_control, entry )
217 if( hwnd == control->hwnd )
218 return control;
219 return NULL;
222 static LPWSTR msi_get_deformatted_field( MSIPACKAGE *package, MSIRECORD *rec, int field )
224 LPCWSTR str = MSI_RecordGetString( rec, field );
225 LPWSTR ret = NULL;
227 if (str)
228 deformat_string( package, str, &ret );
229 return ret;
232 static LPWSTR msi_dialog_dup_property( msi_dialog *dialog, LPCWSTR property, BOOL indirect )
234 LPWSTR prop = NULL;
236 if (!property)
237 return NULL;
239 if (indirect)
240 prop = msi_dup_property( dialog->package->db, property );
242 if (!prop)
243 prop = strdupW( property );
245 return prop;
248 msi_dialog *msi_dialog_get_parent( msi_dialog *dialog )
250 return dialog->parent;
253 LPWSTR msi_dialog_get_name( msi_dialog *dialog )
255 return dialog->name;
259 * msi_dialog_get_style
261 * Extract the {\style} string from the front of the text to display and
262 * update the pointer. Only the last style in a list is applied.
264 static LPWSTR msi_dialog_get_style( LPCWSTR p, LPCWSTR *rest )
266 LPWSTR ret;
267 LPCWSTR q, i, first;
268 DWORD len;
270 q = NULL;
271 *rest = p;
272 if( !p )
273 return NULL;
275 while ((first = strchrW( p, '{' )) && (q = strchrW( first + 1, '}' )))
277 p = first + 1;
278 if( *p != '\\' && *p != '&' )
279 return NULL;
281 /* little bit of sanity checking to stop us getting confused with RTF */
282 for( i=++p; i<q; i++ )
283 if( *i == '}' || *i == '\\' )
284 return NULL;
287 if (!q)
288 return NULL;
290 *rest = ++q;
291 len = q - p;
293 ret = msi_alloc( len*sizeof(WCHAR) );
294 if( !ret )
295 return ret;
296 memcpy( ret, p, len*sizeof(WCHAR) );
297 ret[len-1] = 0;
298 return ret;
301 static UINT msi_dialog_add_font( MSIRECORD *rec, LPVOID param )
303 msi_dialog *dialog = param;
304 msi_font *font;
305 LPCWSTR face, name;
306 LOGFONTW lf;
307 INT style;
308 HDC hdc;
310 /* create a font and add it to the list */
311 name = MSI_RecordGetString( rec, 1 );
312 font = msi_alloc( sizeof *font + strlenW( name )*sizeof (WCHAR) );
313 strcpyW( font->name, name );
314 list_add_head( &dialog->fonts, &font->entry );
316 font->color = MSI_RecordGetInteger( rec, 4 );
318 memset( &lf, 0, sizeof lf );
319 face = MSI_RecordGetString( rec, 2 );
320 lf.lfHeight = MSI_RecordGetInteger( rec, 3 );
321 style = MSI_RecordGetInteger( rec, 5 );
322 if( style & msidbTextStyleStyleBitsBold )
323 lf.lfWeight = FW_BOLD;
324 if( style & msidbTextStyleStyleBitsItalic )
325 lf.lfItalic = TRUE;
326 if( style & msidbTextStyleStyleBitsUnderline )
327 lf.lfUnderline = TRUE;
328 if( style & msidbTextStyleStyleBitsStrike )
329 lf.lfStrikeOut = TRUE;
330 lstrcpynW( lf.lfFaceName, face, LF_FACESIZE );
332 /* adjust the height */
333 hdc = GetDC( dialog->hwnd );
334 if (hdc)
336 lf.lfHeight = -MulDiv(lf.lfHeight, GetDeviceCaps(hdc, LOGPIXELSY), 72);
337 ReleaseDC( dialog->hwnd, hdc );
340 font->hfont = CreateFontIndirectW( &lf );
342 TRACE("Adding font style %s\n", debugstr_w(font->name) );
344 return ERROR_SUCCESS;
347 static msi_font *msi_dialog_find_font( msi_dialog *dialog, LPCWSTR name )
349 msi_font *font = NULL;
351 LIST_FOR_EACH_ENTRY( font, &dialog->fonts, msi_font, entry )
352 if( !strcmpW( font->name, name ) ) /* FIXME: case sensitive? */
353 break;
355 return font;
358 static UINT msi_dialog_set_font( msi_dialog *dialog, HWND hwnd, LPCWSTR name )
360 msi_font *font;
362 font = msi_dialog_find_font( dialog, name );
363 if( font )
364 SendMessageW( hwnd, WM_SETFONT, (WPARAM) font->hfont, TRUE );
365 else
366 ERR("No font entry for %s\n", debugstr_w(name));
367 return ERROR_SUCCESS;
370 static UINT msi_dialog_build_font_list( msi_dialog *dialog )
372 static const WCHAR query[] = {
373 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
374 '`','T','e','x','t','S','t','y','l','e','`',0};
375 MSIQUERY *view;
376 UINT r;
378 TRACE("dialog %p\n", dialog );
380 r = MSI_OpenQuery( dialog->package->db, &view, query );
381 if( r != ERROR_SUCCESS )
382 return r;
384 r = MSI_IterateRecords( view, NULL, msi_dialog_add_font, dialog );
385 msiobj_release( &view->hdr );
386 return r;
389 static void msi_destroy_control( msi_control *t )
391 list_remove( &t->entry );
392 /* leave dialog->hwnd - destroying parent destroys child windows */
393 msi_free( t->property );
394 msi_free( t->value );
395 if( t->hBitmap )
396 DeleteObject( t->hBitmap );
397 if( t->hIcon )
398 DestroyIcon( t->hIcon );
399 msi_free( t->tabnext );
400 msi_free( t->type );
401 if (t->hDll)
402 FreeLibrary( t->hDll );
403 msi_free( t );
406 static msi_control *msi_dialog_create_window( msi_dialog *dialog,
407 MSIRECORD *rec, DWORD exstyle, LPCWSTR szCls, LPCWSTR name, LPCWSTR text,
408 DWORD style, HWND parent )
410 DWORD x, y, width, height;
411 LPWSTR font = NULL, title_font = NULL;
412 LPCWSTR title = NULL;
413 msi_control *control;
415 style |= WS_CHILD;
417 control = msi_alloc( sizeof *control + strlenW(name)*sizeof(WCHAR) );
418 if (!control)
419 return NULL;
421 strcpyW( control->name, name );
422 list_add_tail( &dialog->controls, &control->entry );
423 control->handler = NULL;
424 control->update = NULL;
425 control->property = NULL;
426 control->value = NULL;
427 control->hBitmap = NULL;
428 control->hIcon = NULL;
429 control->hDll = NULL;
430 control->tabnext = strdupW( MSI_RecordGetString( rec, 11) );
431 control->type = strdupW( MSI_RecordGetString( rec, 3 ) );
432 control->progress_current = 0;
433 control->progress_max = 100;
434 control->progress_backwards = FALSE;
436 x = MSI_RecordGetInteger( rec, 4 );
437 y = MSI_RecordGetInteger( rec, 5 );
438 width = MSI_RecordGetInteger( rec, 6 );
439 height = MSI_RecordGetInteger( rec, 7 );
441 x = msi_dialog_scale_unit( dialog, x );
442 y = msi_dialog_scale_unit( dialog, y );
443 width = msi_dialog_scale_unit( dialog, width );
444 height = msi_dialog_scale_unit( dialog, height );
446 if( text )
448 deformat_string( dialog->package, text, &title_font );
449 font = msi_dialog_get_style( title_font, &title );
452 control->hwnd = CreateWindowExW( exstyle, szCls, title, style,
453 x, y, width, height, parent, NULL, NULL, NULL );
455 TRACE("Dialog %s control %s hwnd %p\n",
456 debugstr_w(dialog->name), debugstr_w(text), control->hwnd );
458 msi_dialog_set_font( dialog, control->hwnd,
459 font ? font : dialog->default_font );
461 msi_free( title_font );
462 msi_free( font );
464 return control;
467 static LPWSTR msi_dialog_get_uitext( msi_dialog *dialog, LPCWSTR key )
469 MSIRECORD *rec;
470 LPWSTR text;
472 static const WCHAR query[] = {
473 's','e','l','e','c','t',' ','*',' ',
474 'f','r','o','m',' ','`','U','I','T','e','x','t','`',' ',
475 'w','h','e','r','e',' ','`','K','e','y','`',' ','=',' ','\'','%','s','\'',0
478 rec = MSI_QueryGetRecord( dialog->package->db, query, key );
479 if (!rec) return NULL;
480 text = strdupW( MSI_RecordGetString( rec, 2 ) );
481 msiobj_release( &rec->hdr );
482 return text;
485 static MSIRECORD *msi_get_binary_record( MSIDATABASE *db, LPCWSTR name )
487 static const WCHAR query[] = {
488 's','e','l','e','c','t',' ','*',' ',
489 'f','r','o','m',' ','B','i','n','a','r','y',' ',
490 'w','h','e','r','e',' ',
491 '`','N','a','m','e','`',' ','=',' ','\'','%','s','\'',0
494 return MSI_QueryGetRecord( db, query, name );
497 static LPWSTR msi_create_tmp_path(void)
499 WCHAR tmp[MAX_PATH];
500 LPWSTR path = NULL;
501 DWORD len, r;
503 r = GetTempPathW( MAX_PATH, tmp );
504 if( !r )
505 return path;
506 len = lstrlenW( tmp ) + 20;
507 path = msi_alloc( len * sizeof (WCHAR) );
508 if( path )
510 r = GetTempFileNameW( tmp, szMsi, 0, path );
511 if (!r)
513 msi_free( path );
514 path = NULL;
517 return path;
520 static HANDLE msi_load_image( MSIDATABASE *db, LPCWSTR name, UINT type,
521 UINT cx, UINT cy, UINT flags )
523 MSIRECORD *rec = NULL;
524 HANDLE himage = NULL;
525 LPWSTR tmp;
526 UINT r;
528 TRACE("%p %s %u %u %08x\n", db, debugstr_w(name), cx, cy, flags);
530 tmp = msi_create_tmp_path();
531 if( !tmp )
532 return himage;
534 rec = msi_get_binary_record( db, name );
535 if( rec )
537 r = MSI_RecordStreamToFile( rec, 2, tmp );
538 if( r == ERROR_SUCCESS )
540 himage = LoadImageW( 0, tmp, type, cx, cy, flags );
542 msiobj_release( &rec->hdr );
544 DeleteFileW( tmp );
546 msi_free( tmp );
547 return himage;
550 static HICON msi_load_icon( MSIDATABASE *db, LPCWSTR text, UINT attributes )
552 DWORD cx = 0, cy = 0, flags;
554 flags = LR_LOADFROMFILE | LR_DEFAULTSIZE;
555 if( attributes & msidbControlAttributesFixedSize )
557 flags &= ~LR_DEFAULTSIZE;
558 if( attributes & msidbControlAttributesIconSize16 )
560 cx += 16;
561 cy += 16;
563 if( attributes & msidbControlAttributesIconSize32 )
565 cx += 32;
566 cy += 32;
568 /* msidbControlAttributesIconSize48 handled by above logic */
570 return msi_load_image( db, text, IMAGE_ICON, cx, cy, flags );
573 static void msi_dialog_update_controls( msi_dialog *dialog, LPCWSTR property )
575 msi_control *control;
577 LIST_FOR_EACH_ENTRY( control, &dialog->controls, msi_control, entry )
579 if ( control->property && !strcmpW( control->property, property ) && control->update )
580 control->update( dialog, control );
584 static void msi_dialog_set_property( MSIPACKAGE *package, LPCWSTR property, LPCWSTR value )
586 UINT r = msi_set_property( package->db, property, value );
587 if (r == ERROR_SUCCESS && !strcmpW( property, szSourceDir ))
588 msi_reset_folders( package, TRUE );
591 static MSIFEATURE *msi_seltree_feature_from_item( HWND hwnd, HTREEITEM hItem )
593 TVITEMW tvi;
595 /* get the feature from the item */
596 memset( &tvi, 0, sizeof tvi );
597 tvi.hItem = hItem;
598 tvi.mask = TVIF_PARAM | TVIF_HANDLE;
599 SendMessageW( hwnd, TVM_GETITEMW, 0, (LPARAM)&tvi );
600 return (MSIFEATURE *)tvi.lParam;
603 struct msi_selection_tree_info
605 msi_dialog *dialog;
606 HWND hwnd;
607 WNDPROC oldproc;
608 HTREEITEM selected;
611 static MSIFEATURE *msi_seltree_get_selected_feature( msi_control *control )
613 struct msi_selection_tree_info *info = GetPropW( control->hwnd, szButtonData );
614 return msi_seltree_feature_from_item( control->hwnd, info->selected );
617 /* called from the Control Event subscription code */
618 void msi_dialog_handle_event( msi_dialog* dialog, LPCWSTR control,
619 LPCWSTR attribute, MSIRECORD *rec )
621 msi_control* ctrl;
622 LPCWSTR font_text, text = NULL;
623 LPWSTR font;
625 ctrl = msi_dialog_find_control( dialog, control );
626 if (!ctrl)
627 return;
628 if( !strcmpW( attribute, szText ) )
630 font_text = MSI_RecordGetString( rec , 1 );
631 font = msi_dialog_get_style( font_text, &text );
632 if (!text) text = szEmpty;
633 SetWindowTextW( ctrl->hwnd, text );
634 msi_free( font );
635 msi_dialog_check_messages( NULL );
637 else if( !strcmpW( attribute, szProgress ) )
639 DWORD func, val1, val2, units;
641 func = MSI_RecordGetInteger( rec, 1 );
642 val1 = MSI_RecordGetInteger( rec, 2 );
643 val2 = MSI_RecordGetInteger( rec, 3 );
645 TRACE("progress: func %u val1 %u val2 %u\n", func, val1, val2);
647 switch (func)
649 case 0: /* init */
650 SendMessageW( ctrl->hwnd, PBM_SETRANGE, 0, MAKELPARAM(0,100) );
651 units = val1 / 512;
652 if (val2)
654 ctrl->progress_max = units ? units : 100;
655 ctrl->progress_current = units;
656 ctrl->progress_backwards = TRUE;
657 SendMessageW( ctrl->hwnd, PBM_SETPOS, 100, 0 );
659 else
661 ctrl->progress_max = units ? units : 100;
662 ctrl->progress_current = 0;
663 ctrl->progress_backwards = FALSE;
664 SendMessageW( ctrl->hwnd, PBM_SETPOS, 0, 0 );
666 break;
667 case 1: /* FIXME: not sure what this is supposed to do */
668 break;
669 case 2: /* move */
670 units = val1 / 512;
671 if (ctrl->progress_backwards)
673 if (units >= ctrl->progress_current) ctrl->progress_current -= units;
674 else ctrl->progress_current = 0;
676 else
678 if (ctrl->progress_current + units < ctrl->progress_max) ctrl->progress_current += units;
679 else ctrl->progress_current = ctrl->progress_max;
681 SendMessageW( ctrl->hwnd, PBM_SETPOS, MulDiv(100, ctrl->progress_current, ctrl->progress_max), 0 );
682 break;
683 default:
684 FIXME("Unknown progress message %u\n", func);
685 break;
688 else if ( !strcmpW( attribute, szProperty ) )
690 MSIFEATURE *feature = msi_seltree_get_selected_feature( ctrl );
691 msi_dialog_set_property( dialog->package, ctrl->property, feature->Directory );
693 else if ( !strcmpW( attribute, szSelectionPath ) )
695 BOOL indirect = ctrl->attributes & msidbControlAttributesIndirect;
696 LPWSTR path = msi_dialog_dup_property( dialog, ctrl->property, indirect );
697 if (!path) return;
698 SetWindowTextW( ctrl->hwnd, path );
699 msi_free(path);
701 else
703 FIXME("Attribute %s not being set\n", debugstr_w(attribute));
704 return;
708 static void msi_dialog_map_events(msi_dialog* dialog, LPCWSTR control)
710 static const WCHAR Query[] = {
711 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
712 '`','E','v','e','n','t','M','a','p','p','i','n','g','`',' ',
713 'W','H','E','R','E',' ',
714 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',' ',
715 'A','N','D',' ',
716 '`','C','o','n','t','r','o','l','_','`',' ','=',' ','\'','%','s','\'',0
718 MSIRECORD *row;
719 LPCWSTR event, attribute;
721 row = MSI_QueryGetRecord( dialog->package->db, Query, dialog->name, control );
722 if (!row)
723 return;
725 event = MSI_RecordGetString( row, 3 );
726 attribute = MSI_RecordGetString( row, 4 );
727 ControlEvent_SubscribeToEvent( dialog->package, dialog, event, control, attribute );
728 msiobj_release( &row->hdr );
731 /* everything except radio buttons */
732 static msi_control *msi_dialog_add_control( msi_dialog *dialog,
733 MSIRECORD *rec, LPCWSTR szCls, DWORD style )
735 DWORD attributes;
736 LPCWSTR text, name;
737 DWORD exstyle = 0;
739 name = MSI_RecordGetString( rec, 2 );
740 attributes = MSI_RecordGetInteger( rec, 8 );
741 text = MSI_RecordGetString( rec, 10 );
743 TRACE("%s, %s, %08x, %s, %08x\n", debugstr_w(szCls), debugstr_w(name),
744 attributes, debugstr_w(text), style);
746 if( attributes & msidbControlAttributesVisible )
747 style |= WS_VISIBLE;
748 if( ~attributes & msidbControlAttributesEnabled )
749 style |= WS_DISABLED;
750 if( attributes & msidbControlAttributesSunken )
751 exstyle |= WS_EX_CLIENTEDGE;
753 msi_dialog_map_events(dialog, name);
755 return msi_dialog_create_window( dialog, rec, exstyle, szCls, name,
756 text, style, dialog->hwnd );
759 struct msi_text_info
761 msi_font *font;
762 WNDPROC oldproc;
763 DWORD attributes;
767 * we don't erase our own background,
768 * so we have to make sure that the parent window redraws first
770 static void msi_text_on_settext( HWND hWnd )
772 HWND hParent;
773 RECT rc;
775 hParent = GetParent( hWnd );
776 GetWindowRect( hWnd, &rc );
777 MapWindowPoints( NULL, hParent, (LPPOINT) &rc, 2 );
778 InvalidateRect( hParent, &rc, TRUE );
781 static LRESULT WINAPI
782 MSIText_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
784 struct msi_text_info *info;
785 LRESULT r = 0;
787 TRACE("%p %04x %08lx %08lx\n", hWnd, msg, wParam, lParam);
789 info = GetPropW(hWnd, szButtonData);
791 if( msg == WM_CTLCOLORSTATIC &&
792 ( info->attributes & msidbControlAttributesTransparent ) )
794 SetBkMode( (HDC)wParam, TRANSPARENT );
795 return (LRESULT) GetStockObject(NULL_BRUSH);
798 r = CallWindowProcW(info->oldproc, hWnd, msg, wParam, lParam);
799 if ( info->font )
800 SetTextColor( (HDC)wParam, info->font->color );
802 switch( msg )
804 case WM_SETTEXT:
805 msi_text_on_settext( hWnd );
806 break;
807 case WM_NCDESTROY:
808 msi_free( info );
809 RemovePropW( hWnd, szButtonData );
810 break;
813 return r;
816 static UINT msi_dialog_text_control( msi_dialog *dialog, MSIRECORD *rec )
818 msi_control *control;
819 struct msi_text_info *info;
820 LPCWSTR text, ptr, prop, control_name;
821 LPWSTR font_name;
823 TRACE("%p %p\n", dialog, rec);
825 control = msi_dialog_add_control( dialog, rec, szStatic, SS_LEFT | WS_GROUP );
826 if( !control )
827 return ERROR_FUNCTION_FAILED;
829 info = msi_alloc( sizeof *info );
830 if( !info )
831 return ERROR_SUCCESS;
833 control_name = MSI_RecordGetString( rec, 2 );
834 control->attributes = MSI_RecordGetInteger( rec, 8 );
835 prop = MSI_RecordGetString( rec, 9 );
836 control->property = msi_dialog_dup_property( dialog, prop, FALSE );
838 text = MSI_RecordGetString( rec, 10 );
839 font_name = msi_dialog_get_style( text, &ptr );
840 info->font = ( font_name ) ? msi_dialog_find_font( dialog, font_name ) : NULL;
841 msi_free( font_name );
843 info->attributes = MSI_RecordGetInteger( rec, 8 );
844 if( info->attributes & msidbControlAttributesTransparent )
845 SetWindowLongPtrW( control->hwnd, GWL_EXSTYLE, WS_EX_TRANSPARENT );
847 info->oldproc = (WNDPROC) SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
848 (LONG_PTR)MSIText_WndProc );
849 SetPropW( control->hwnd, szButtonData, info );
851 ControlEvent_SubscribeToEvent( dialog->package, dialog,
852 szSelectionPath, control_name, szSelectionPath );
854 return ERROR_SUCCESS;
857 /* strip any leading text style label from text field */
858 static WCHAR *msi_get_binary_name( MSIPACKAGE *package, MSIRECORD *rec )
860 WCHAR *p, *text;
862 text = msi_get_deformatted_field( package, rec, 10 );
863 if (!text)
864 return NULL;
866 p = text;
867 while (*p && *p != '{') p++;
868 if (!*p++) return text;
870 while (*p && *p != '}') p++;
871 if (!*p++) return text;
873 p = strdupW( p );
874 msi_free( text );
875 return p;
878 static UINT msi_dialog_set_property_event( msi_dialog *dialog, LPCWSTR event, LPCWSTR arg )
880 static const WCHAR szNullArg[] = {'{','}',0};
881 LPWSTR p, prop, arg_fmt = NULL;
882 UINT len;
884 len = strlenW( event );
885 prop = msi_alloc( len * sizeof(WCHAR) );
886 strcpyW( prop, &event[1] );
887 p = strchrW( prop, ']' );
888 if (p && (p[1] == 0 || p[1] == ' '))
890 *p = 0;
891 if (strcmpW( szNullArg, arg ))
892 deformat_string( dialog->package, arg, &arg_fmt );
893 msi_dialog_set_property( dialog->package, prop, arg_fmt );
894 msi_dialog_update_controls( dialog, prop );
895 msi_free( arg_fmt );
897 else ERR("Badly formatted property string - what happens?\n");
898 msi_free( prop );
899 return ERROR_SUCCESS;
902 static UINT msi_dialog_send_event( msi_dialog *dialog, LPCWSTR event, LPCWSTR arg )
904 LPWSTR event_fmt = NULL, arg_fmt = NULL;
906 TRACE("Sending control event %s %s\n", debugstr_w(event), debugstr_w(arg));
908 deformat_string( dialog->package, event, &event_fmt );
909 deformat_string( dialog->package, arg, &arg_fmt );
911 dialog->event_handler( dialog->package, event_fmt, arg_fmt, dialog );
913 msi_free( event_fmt );
914 msi_free( arg_fmt );
916 return ERROR_SUCCESS;
919 static UINT msi_dialog_control_event( MSIRECORD *rec, LPVOID param )
921 msi_dialog *dialog = param;
922 LPCWSTR condition, event, arg;
923 UINT r;
925 condition = MSI_RecordGetString( rec, 5 );
926 r = MSI_EvaluateConditionW( dialog->package, condition );
927 if (r == MSICONDITION_TRUE || r == MSICONDITION_NONE)
929 event = MSI_RecordGetString( rec, 3 );
930 arg = MSI_RecordGetString( rec, 4 );
931 if (event[0] == '[')
932 msi_dialog_set_property_event( dialog, event, arg );
933 else
934 msi_dialog_send_event( dialog, event, arg );
936 return ERROR_SUCCESS;
939 static UINT msi_dialog_button_handler( msi_dialog *dialog, msi_control *control, WPARAM param )
941 static const WCHAR query[] = {
942 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
943 'C','o','n','t','r','o','l','E','v','e','n','t',' ','W','H','E','R','E',' ',
944 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',' ','A','N','D',' ',
945 '`','C','o','n','t','r','o','l','_','`',' ','=',' ','\'','%','s','\'',' ',
946 'O','R','D','E','R',' ','B','Y',' ','`','O','r','d','e','r','i','n','g','`',0};
947 MSIQUERY *view;
948 UINT r;
950 if (HIWORD(param) != BN_CLICKED)
951 return ERROR_SUCCESS;
953 r = MSI_OpenQuery( dialog->package->db, &view, query, dialog->name, control->name );
954 if (r != ERROR_SUCCESS)
956 ERR("query failed\n");
957 return ERROR_SUCCESS;
959 r = MSI_IterateRecords( view, 0, msi_dialog_control_event, dialog );
960 msiobj_release( &view->hdr );
961 return r;
964 static UINT msi_dialog_button_control( msi_dialog *dialog, MSIRECORD *rec )
966 msi_control *control;
967 UINT attributes, style;
969 TRACE("%p %p\n", dialog, rec);
971 style = WS_TABSTOP;
972 attributes = MSI_RecordGetInteger( rec, 8 );
973 if( attributes & msidbControlAttributesIcon )
974 style |= BS_ICON;
976 control = msi_dialog_add_control( dialog, rec, szButton, style );
977 if( !control )
978 return ERROR_FUNCTION_FAILED;
980 control->handler = msi_dialog_button_handler;
982 if (attributes & msidbControlAttributesIcon)
984 /* set the icon */
985 LPWSTR name = msi_get_binary_name( dialog->package, rec );
986 control->hIcon = msi_load_icon( dialog->package->db, name, attributes );
987 if (control->hIcon)
989 SendMessageW( control->hwnd, BM_SETIMAGE, IMAGE_ICON, (LPARAM) control->hIcon );
991 else
992 ERR("Failed to load icon %s\n", debugstr_w(name));
993 msi_free( name );
996 return ERROR_SUCCESS;
999 static LPWSTR msi_get_checkbox_value( msi_dialog *dialog, LPCWSTR prop )
1001 static const WCHAR query[] = {
1002 'S','E','L','E','C','T',' ','*',' ',
1003 'F','R','O','M',' ','`','C','h','e','c','k','B','o','x','`',' ',
1004 'W','H','E','R','E',' ',
1005 '`','P','r','o','p','e','r','t','y','`',' ','=',' ',
1006 '\'','%','s','\'',0
1008 MSIRECORD *rec = NULL;
1009 LPWSTR ret = NULL;
1011 /* find if there is a value associated with the checkbox */
1012 rec = MSI_QueryGetRecord( dialog->package->db, query, prop );
1013 if (!rec)
1014 return ret;
1016 ret = msi_get_deformatted_field( dialog->package, rec, 2 );
1017 if( ret && !ret[0] )
1019 msi_free( ret );
1020 ret = NULL;
1022 msiobj_release( &rec->hdr );
1023 if (ret)
1024 return ret;
1026 ret = msi_dup_property( dialog->package->db, prop );
1027 if( ret && !ret[0] )
1029 msi_free( ret );
1030 ret = NULL;
1033 return ret;
1036 static UINT msi_dialog_get_checkbox_state( msi_dialog *dialog, msi_control *control )
1038 WCHAR state[2] = {0};
1039 DWORD sz = 2;
1041 msi_get_property( dialog->package->db, control->property, state, &sz );
1042 return state[0] ? 1 : 0;
1045 static void msi_dialog_set_checkbox_state( msi_dialog *dialog, msi_control *control, UINT state )
1047 static const WCHAR szState[] = {'1',0};
1048 LPCWSTR val;
1050 /* if uncheck then the property is set to NULL */
1051 if (!state)
1053 msi_dialog_set_property( dialog->package, control->property, NULL );
1054 return;
1057 /* check for a custom state */
1058 if (control->value && control->value[0])
1059 val = control->value;
1060 else
1061 val = szState;
1063 msi_dialog_set_property( dialog->package, control->property, val );
1066 static void msi_dialog_checkbox_sync_state( msi_dialog *dialog, msi_control *control )
1068 UINT state = msi_dialog_get_checkbox_state( dialog, control );
1069 SendMessageW( control->hwnd, BM_SETCHECK, state ? BST_CHECKED : BST_UNCHECKED, 0 );
1072 static UINT msi_dialog_checkbox_handler( msi_dialog *dialog, msi_control *control, WPARAM param )
1074 UINT state;
1076 if (HIWORD(param) != BN_CLICKED)
1077 return ERROR_SUCCESS;
1079 TRACE("clicked checkbox %s, set %s\n", debugstr_w(control->name), debugstr_w(control->property));
1081 state = msi_dialog_get_checkbox_state( dialog, control );
1082 state = state ? 0 : 1;
1083 msi_dialog_set_checkbox_state( dialog, control, state );
1084 msi_dialog_checkbox_sync_state( dialog, control );
1086 return msi_dialog_button_handler( dialog, control, param );
1089 static UINT msi_dialog_checkbox_control( msi_dialog *dialog, MSIRECORD *rec )
1091 msi_control *control;
1092 LPCWSTR prop;
1094 TRACE("%p %p\n", dialog, rec);
1096 control = msi_dialog_add_control( dialog, rec, szButton, BS_CHECKBOX | BS_MULTILINE | WS_TABSTOP );
1097 control->handler = msi_dialog_checkbox_handler;
1098 control->update = msi_dialog_checkbox_sync_state;
1099 prop = MSI_RecordGetString( rec, 9 );
1100 if (prop)
1102 control->property = strdupW( prop );
1103 control->value = msi_get_checkbox_value( dialog, prop );
1104 TRACE("control %s value %s\n", debugstr_w(control->property), debugstr_w(control->value));
1106 msi_dialog_checkbox_sync_state( dialog, control );
1107 return ERROR_SUCCESS;
1110 static UINT msi_dialog_line_control( msi_dialog *dialog, MSIRECORD *rec )
1112 DWORD attributes;
1113 LPCWSTR name;
1114 DWORD style, exstyle = 0;
1115 DWORD x, y, width, height;
1116 msi_control *control;
1118 TRACE("%p %p\n", dialog, rec);
1120 style = WS_CHILD | SS_ETCHEDHORZ | SS_SUNKEN;
1122 name = MSI_RecordGetString( rec, 2 );
1123 attributes = MSI_RecordGetInteger( rec, 8 );
1125 if( attributes & msidbControlAttributesVisible )
1126 style |= WS_VISIBLE;
1127 if( ~attributes & msidbControlAttributesEnabled )
1128 style |= WS_DISABLED;
1129 if( attributes & msidbControlAttributesSunken )
1130 exstyle |= WS_EX_CLIENTEDGE;
1132 msi_dialog_map_events(dialog, name);
1134 control = msi_alloc( sizeof(*control) + strlenW(name) * sizeof(WCHAR) );
1135 if (!control)
1136 return ERROR_OUTOFMEMORY;
1138 strcpyW( control->name, name );
1139 list_add_head( &dialog->controls, &control->entry );
1140 control->handler = NULL;
1141 control->property = NULL;
1142 control->value = NULL;
1143 control->hBitmap = NULL;
1144 control->hIcon = NULL;
1145 control->hDll = NULL;
1146 control->tabnext = strdupW( MSI_RecordGetString( rec, 11) );
1147 control->type = strdupW( MSI_RecordGetString( rec, 3 ) );
1148 control->progress_current = 0;
1149 control->progress_max = 100;
1150 control->progress_backwards = FALSE;
1152 x = MSI_RecordGetInteger( rec, 4 );
1153 y = MSI_RecordGetInteger( rec, 5 );
1154 width = MSI_RecordGetInteger( rec, 6 );
1156 x = msi_dialog_scale_unit( dialog, x );
1157 y = msi_dialog_scale_unit( dialog, y );
1158 width = msi_dialog_scale_unit( dialog, width );
1159 height = 2; /* line is exactly 2 units in height */
1161 control->hwnd = CreateWindowExW( exstyle, szStatic, NULL, style,
1162 x, y, width, height, dialog->hwnd, NULL, NULL, NULL );
1164 TRACE("Dialog %s control %s hwnd %p\n",
1165 debugstr_w(dialog->name), debugstr_w(name), control->hwnd );
1167 return ERROR_SUCCESS;
1170 /******************** Scroll Text ********************************************/
1172 struct msi_scrolltext_info
1174 msi_dialog *dialog;
1175 msi_control *control;
1176 WNDPROC oldproc;
1179 static LRESULT WINAPI
1180 MSIScrollText_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
1182 struct msi_scrolltext_info *info;
1183 HRESULT r;
1185 TRACE("%p %04x %08lx %08lx\n", hWnd, msg, wParam, lParam);
1187 info = GetPropW( hWnd, szButtonData );
1189 r = CallWindowProcW( info->oldproc, hWnd, msg, wParam, lParam );
1191 switch( msg )
1193 case WM_GETDLGCODE:
1194 return DLGC_WANTARROWS;
1195 case WM_NCDESTROY:
1196 msi_free( info );
1197 RemovePropW( hWnd, szButtonData );
1198 break;
1199 case WM_PAINT:
1200 /* native MSI sets a wait cursor here */
1201 msi_dialog_button_handler( info->dialog, info->control, BN_CLICKED );
1202 break;
1204 return r;
1207 struct msi_streamin_info
1209 LPSTR string;
1210 DWORD offset;
1211 DWORD length;
1214 static DWORD CALLBACK
1215 msi_richedit_stream_in( DWORD_PTR arg, LPBYTE buffer, LONG count, LONG *pcb )
1217 struct msi_streamin_info *info = (struct msi_streamin_info*) arg;
1219 if( (count + info->offset) > info->length )
1220 count = info->length - info->offset;
1221 memcpy( buffer, &info->string[ info->offset ], count );
1222 *pcb = count;
1223 info->offset += count;
1225 TRACE("%d/%d\n", info->offset, info->length);
1227 return 0;
1230 static void msi_scrolltext_add_text( msi_control *control, LPCWSTR text )
1232 struct msi_streamin_info info;
1233 EDITSTREAM es;
1235 info.string = strdupWtoA( text );
1236 info.offset = 0;
1237 info.length = lstrlenA( info.string ) + 1;
1239 es.dwCookie = (DWORD_PTR) &info;
1240 es.dwError = 0;
1241 es.pfnCallback = msi_richedit_stream_in;
1243 SendMessageW( control->hwnd, EM_STREAMIN, SF_RTF, (LPARAM) &es );
1245 msi_free( info.string );
1248 static UINT msi_dialog_scrolltext_control( msi_dialog *dialog, MSIRECORD *rec )
1250 static const WCHAR szRichEdit20W[] = {'R','i','c','h','E','d','i','t','2','0','W',0};
1251 struct msi_scrolltext_info *info;
1252 msi_control *control;
1253 HMODULE hRichedit;
1254 LPCWSTR text;
1255 DWORD style;
1257 info = msi_alloc( sizeof *info );
1258 if (!info)
1259 return ERROR_FUNCTION_FAILED;
1261 hRichedit = LoadLibraryA("riched20");
1263 style = WS_BORDER | ES_MULTILINE | WS_VSCROLL |
1264 ES_READONLY | ES_AUTOVSCROLL | WS_TABSTOP;
1265 control = msi_dialog_add_control( dialog, rec, szRichEdit20W, style );
1266 if (!control)
1268 FreeLibrary( hRichedit );
1269 msi_free( info );
1270 return ERROR_FUNCTION_FAILED;
1273 control->hDll = hRichedit;
1275 info->dialog = dialog;
1276 info->control = control;
1278 /* subclass the static control */
1279 info->oldproc = (WNDPROC) SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
1280 (LONG_PTR)MSIScrollText_WndProc );
1281 SetPropW( control->hwnd, szButtonData, info );
1283 /* add the text into the richedit */
1284 text = MSI_RecordGetString( rec, 10 );
1285 if (text)
1286 msi_scrolltext_add_text( control, text );
1288 return ERROR_SUCCESS;
1291 static HBITMAP msi_load_picture( MSIDATABASE *db, LPCWSTR name,
1292 INT cx, INT cy, DWORD flags )
1294 HBITMAP hOleBitmap = 0, hBitmap = 0, hOldSrcBitmap, hOldDestBitmap;
1295 MSIRECORD *rec = NULL;
1296 IStream *stm = NULL;
1297 IPicture *pic = NULL;
1298 HDC srcdc, destdc;
1299 BITMAP bm;
1300 UINT r;
1302 rec = msi_get_binary_record( db, name );
1303 if( !rec )
1304 goto end;
1306 r = MSI_RecordGetIStream( rec, 2, &stm );
1307 msiobj_release( &rec->hdr );
1308 if( r != ERROR_SUCCESS )
1309 goto end;
1311 r = OleLoadPicture( stm, 0, TRUE, &IID_IPicture, (LPVOID*) &pic );
1312 IStream_Release( stm );
1313 if( FAILED( r ) )
1315 ERR("failed to load picture\n");
1316 goto end;
1319 r = IPicture_get_Handle( pic, (OLE_HANDLE*) &hOleBitmap );
1320 if( FAILED( r ) )
1322 ERR("failed to get bitmap handle\n");
1323 goto end;
1326 /* make the bitmap the desired size */
1327 r = GetObjectW( hOleBitmap, sizeof bm, &bm );
1328 if (r != sizeof bm )
1330 ERR("failed to get bitmap size\n");
1331 goto end;
1334 if (flags & LR_DEFAULTSIZE)
1336 cx = bm.bmWidth;
1337 cy = bm.bmHeight;
1340 srcdc = CreateCompatibleDC( NULL );
1341 hOldSrcBitmap = SelectObject( srcdc, hOleBitmap );
1342 destdc = CreateCompatibleDC( NULL );
1343 hBitmap = CreateCompatibleBitmap( srcdc, cx, cy );
1344 hOldDestBitmap = SelectObject( destdc, hBitmap );
1345 StretchBlt( destdc, 0, 0, cx, cy,
1346 srcdc, 0, 0, bm.bmWidth, bm.bmHeight, SRCCOPY);
1347 SelectObject( srcdc, hOldSrcBitmap );
1348 SelectObject( destdc, hOldDestBitmap );
1349 DeleteDC( srcdc );
1350 DeleteDC( destdc );
1352 end:
1353 if ( pic )
1354 IPicture_Release( pic );
1355 return hBitmap;
1358 static UINT msi_dialog_bitmap_control( msi_dialog *dialog, MSIRECORD *rec )
1360 UINT cx, cy, flags, style, attributes;
1361 msi_control *control;
1362 LPWSTR name;
1364 flags = LR_LOADFROMFILE;
1365 style = SS_BITMAP | SS_LEFT | WS_GROUP;
1367 attributes = MSI_RecordGetInteger( rec, 8 );
1368 if( attributes & msidbControlAttributesFixedSize )
1370 flags |= LR_DEFAULTSIZE;
1371 style |= SS_CENTERIMAGE;
1374 control = msi_dialog_add_control( dialog, rec, szStatic, style );
1375 cx = MSI_RecordGetInteger( rec, 6 );
1376 cy = MSI_RecordGetInteger( rec, 7 );
1377 cx = msi_dialog_scale_unit( dialog, cx );
1378 cy = msi_dialog_scale_unit( dialog, cy );
1380 name = msi_get_binary_name( dialog->package, rec );
1381 control->hBitmap = msi_load_picture( dialog->package->db, name, cx, cy, flags );
1382 if( control->hBitmap )
1383 SendMessageW( control->hwnd, STM_SETIMAGE,
1384 IMAGE_BITMAP, (LPARAM) control->hBitmap );
1385 else
1386 ERR("Failed to load bitmap %s\n", debugstr_w(name));
1388 msi_free( name );
1390 return ERROR_SUCCESS;
1393 static UINT msi_dialog_icon_control( msi_dialog *dialog, MSIRECORD *rec )
1395 msi_control *control;
1396 DWORD attributes;
1397 LPWSTR name;
1399 TRACE("\n");
1401 control = msi_dialog_add_control( dialog, rec, szStatic,
1402 SS_ICON | SS_CENTERIMAGE | WS_GROUP );
1404 attributes = MSI_RecordGetInteger( rec, 8 );
1405 name = msi_get_binary_name( dialog->package, rec );
1406 control->hIcon = msi_load_icon( dialog->package->db, name, attributes );
1407 if( control->hIcon )
1408 SendMessageW( control->hwnd, STM_SETICON, (WPARAM) control->hIcon, 0 );
1409 else
1410 ERR("Failed to load bitmap %s\n", debugstr_w(name));
1411 msi_free( name );
1412 return ERROR_SUCCESS;
1415 /******************** Combo Box ***************************************/
1417 struct msi_combobox_info
1419 msi_dialog *dialog;
1420 HWND hwnd;
1421 WNDPROC oldproc;
1422 DWORD num_items;
1423 DWORD addpos_items;
1424 LPWSTR *items;
1427 static LRESULT WINAPI MSIComboBox_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
1429 struct msi_combobox_info *info;
1430 LRESULT r;
1431 DWORD j;
1433 TRACE("%p %04x %08lx %08lx\n", hWnd, msg, wParam, lParam);
1435 info = GetPropW( hWnd, szButtonData );
1436 if (!info)
1437 return 0;
1439 r = CallWindowProcW( info->oldproc, hWnd, msg, wParam, lParam );
1441 switch (msg)
1443 case WM_NCDESTROY:
1444 for (j = 0; j < info->num_items; j++)
1445 msi_free( info->items[j] );
1446 msi_free( info->items );
1447 msi_free( info );
1448 RemovePropW( hWnd, szButtonData );
1449 break;
1452 return r;
1455 static UINT msi_combobox_add_item( MSIRECORD *rec, LPVOID param )
1457 struct msi_combobox_info *info = param;
1458 LPCWSTR value, text;
1459 int pos;
1461 value = MSI_RecordGetString( rec, 3 );
1462 text = MSI_RecordGetString( rec, 4 );
1464 info->items[info->addpos_items] = strdupW( value );
1466 pos = SendMessageW( info->hwnd, CB_ADDSTRING, 0, (LPARAM)text );
1467 SendMessageW( info->hwnd, CB_SETITEMDATA, pos, (LPARAM)info->items[info->addpos_items] );
1468 info->addpos_items++;
1470 return ERROR_SUCCESS;
1473 static UINT msi_combobox_add_items( struct msi_combobox_info *info, LPCWSTR property )
1475 static const WCHAR query[] = {
1476 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
1477 '`','C','o','m','b','o','B','o','x','`',' ','W','H','E','R','E',' ',
1478 '`','P','r','o','p','e','r','t','y','`',' ','=',' ','\'','%','s','\'',' ',
1479 'O','R','D','E','R',' ','B','Y',' ','`','O','r','d','e','r','`',0};
1480 MSIQUERY *view;
1481 DWORD count;
1482 UINT r;
1484 r = MSI_OpenQuery( info->dialog->package->db, &view, query, property );
1485 if (r != ERROR_SUCCESS)
1486 return r;
1488 /* just get the number of records */
1489 count = 0;
1490 r = MSI_IterateRecords( view, &count, NULL, NULL );
1491 if (r != ERROR_SUCCESS)
1493 msiobj_release( &view->hdr );
1494 return r;
1496 info->num_items = count;
1497 info->items = msi_alloc( sizeof(*info->items) * count );
1499 r = MSI_IterateRecords( view, NULL, msi_combobox_add_item, info );
1500 msiobj_release( &view->hdr );
1501 return r;
1504 static UINT msi_dialog_set_control_condition( MSIRECORD *rec, LPVOID param )
1506 static const WCHAR szHide[] = {'H','i','d','e',0};
1507 static const WCHAR szShow[] = {'S','h','o','w',0};
1508 static const WCHAR szDisable[] = {'D','i','s','a','b','l','e',0};
1509 static const WCHAR szEnable[] = {'E','n','a','b','l','e',0};
1510 static const WCHAR szDefault[] = {'D','e','f','a','u','l','t',0};
1511 msi_dialog *dialog = param;
1512 msi_control *control;
1513 LPCWSTR name, action, condition;
1514 UINT r;
1516 name = MSI_RecordGetString( rec, 2 );
1517 action = MSI_RecordGetString( rec, 3 );
1518 condition = MSI_RecordGetString( rec, 4 );
1519 r = MSI_EvaluateConditionW( dialog->package, condition );
1520 control = msi_dialog_find_control( dialog, name );
1521 if (r == MSICONDITION_TRUE && control)
1523 TRACE("%s control %s\n", debugstr_w(action), debugstr_w(name));
1525 /* FIXME: case sensitive? */
1526 if (!strcmpW( action, szHide ))
1527 ShowWindow(control->hwnd, SW_HIDE);
1528 else if (!strcmpW( action, szShow ))
1529 ShowWindow(control->hwnd, SW_SHOW);
1530 else if (!strcmpW( action, szDisable ))
1531 EnableWindow(control->hwnd, FALSE);
1532 else if (!strcmpW( action, szEnable ))
1533 EnableWindow(control->hwnd, TRUE);
1534 else if (!strcmpW( action, szDefault ))
1535 SetFocus(control->hwnd);
1536 else
1537 FIXME("Unhandled action %s\n", debugstr_w(action));
1539 return ERROR_SUCCESS;
1542 static UINT msi_dialog_evaluate_control_conditions( msi_dialog *dialog )
1544 static const WCHAR query[] = {
1545 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
1546 'C','o','n','t','r','o','l','C','o','n','d','i','t','i','o','n',' ',
1547 'W','H','E','R','E',' ','`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',0};
1548 UINT r;
1549 MSIQUERY *view;
1550 MSIPACKAGE *package = dialog->package;
1552 TRACE("%p %s\n", dialog, debugstr_w(dialog->name));
1554 /* query the Control table for all the elements of the control */
1555 r = MSI_OpenQuery( package->db, &view, query, dialog->name );
1556 if (r != ERROR_SUCCESS)
1557 return ERROR_SUCCESS;
1559 r = MSI_IterateRecords( view, 0, msi_dialog_set_control_condition, dialog );
1560 msiobj_release( &view->hdr );
1561 return r;
1564 static UINT msi_dialog_combobox_handler( msi_dialog *dialog, msi_control *control, WPARAM param )
1566 struct msi_combobox_info *info;
1567 int index;
1568 LPWSTR value;
1570 if (HIWORD(param) != CBN_SELCHANGE && HIWORD(param) != CBN_EDITCHANGE)
1571 return ERROR_SUCCESS;
1573 info = GetPropW( control->hwnd, szButtonData );
1574 index = SendMessageW( control->hwnd, CB_GETCURSEL, 0, 0 );
1575 if (index == CB_ERR)
1576 value = msi_get_window_text( control->hwnd );
1577 else
1578 value = (LPWSTR) SendMessageW( control->hwnd, CB_GETITEMDATA, index, 0 );
1580 msi_dialog_set_property( info->dialog->package, control->property, value );
1581 msi_dialog_evaluate_control_conditions( info->dialog );
1583 if (index == CB_ERR)
1584 msi_free( value );
1586 return ERROR_SUCCESS;
1589 static void msi_dialog_combobox_update( msi_dialog *dialog, msi_control *control )
1591 struct msi_combobox_info *info;
1592 LPWSTR value, tmp;
1593 DWORD j;
1595 info = GetPropW( control->hwnd, szButtonData );
1597 value = msi_dup_property( dialog->package->db, control->property );
1598 if (!value)
1600 SendMessageW( control->hwnd, CB_SETCURSEL, -1, 0 );
1601 return;
1604 for (j = 0; j < info->num_items; j++)
1606 tmp = (LPWSTR) SendMessageW( control->hwnd, CB_GETITEMDATA, j, 0 );
1607 if (!strcmpW( value, tmp ))
1608 break;
1611 if (j < info->num_items)
1613 SendMessageW( control->hwnd, CB_SETCURSEL, j, 0 );
1615 else
1617 SendMessageW( control->hwnd, CB_SETCURSEL, -1, 0 );
1618 SetWindowTextW( control->hwnd, value );
1621 msi_free(value);
1624 static UINT msi_dialog_combo_control( msi_dialog *dialog, MSIRECORD *rec )
1626 struct msi_combobox_info *info;
1627 msi_control *control;
1628 DWORD attributes, style;
1629 LPCWSTR prop;
1631 info = msi_alloc( sizeof *info );
1632 if (!info)
1633 return ERROR_FUNCTION_FAILED;
1635 style = CBS_AUTOHSCROLL | WS_TABSTOP | WS_GROUP | WS_CHILD;
1636 attributes = MSI_RecordGetInteger( rec, 8 );
1637 if ( ~attributes & msidbControlAttributesSorted)
1638 style |= CBS_SORT;
1639 if ( attributes & msidbControlAttributesComboList)
1640 style |= CBS_DROPDOWNLIST;
1641 else
1642 style |= CBS_DROPDOWN;
1644 control = msi_dialog_add_control( dialog, rec, WC_COMBOBOXW, style );
1645 if (!control)
1647 msi_free( info );
1648 return ERROR_FUNCTION_FAILED;
1651 control->handler = msi_dialog_combobox_handler;
1652 control->update = msi_dialog_combobox_update;
1654 prop = MSI_RecordGetString( rec, 9 );
1655 control->property = msi_dialog_dup_property( dialog, prop, FALSE );
1657 /* subclass */
1658 info->dialog = dialog;
1659 info->hwnd = control->hwnd;
1660 info->items = NULL;
1661 info->addpos_items = 0;
1662 info->oldproc = (WNDPROC)SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
1663 (LONG_PTR)MSIComboBox_WndProc );
1664 SetPropW( control->hwnd, szButtonData, info );
1666 if (control->property)
1667 msi_combobox_add_items( info, control->property );
1669 msi_dialog_combobox_update( dialog, control );
1671 return ERROR_SUCCESS;
1674 static UINT msi_dialog_edit_handler( msi_dialog *dialog, msi_control *control, WPARAM param )
1676 LPWSTR buf;
1678 if (HIWORD(param) != EN_CHANGE)
1679 return ERROR_SUCCESS;
1681 TRACE("edit %s contents changed, set %s\n", debugstr_w(control->name), debugstr_w(control->property));
1683 buf = msi_get_window_text( control->hwnd );
1684 msi_dialog_set_property( dialog->package, control->property, buf );
1685 msi_free( buf );
1687 return ERROR_SUCCESS;
1690 /* length of 2^32 + 1 */
1691 #define MAX_NUM_DIGITS 11
1693 static UINT msi_dialog_edit_control( msi_dialog *dialog, MSIRECORD *rec )
1695 msi_control *control;
1696 LPCWSTR prop, text;
1697 LPWSTR val, begin, end;
1698 WCHAR num[MAX_NUM_DIGITS];
1699 DWORD limit;
1701 control = msi_dialog_add_control( dialog, rec, szEdit,
1702 WS_BORDER | WS_TABSTOP | ES_AUTOHSCROLL );
1703 control->handler = msi_dialog_edit_handler;
1705 text = MSI_RecordGetString( rec, 10 );
1706 if ( text )
1708 begin = strchrW( text, '{' );
1709 end = strchrW( text, '}' );
1711 if ( begin && end && end > begin &&
1712 begin[0] >= '0' && begin[0] <= '9' &&
1713 end - begin < MAX_NUM_DIGITS)
1715 lstrcpynW( num, begin + 1, end - begin );
1716 limit = atolW( num );
1718 SendMessageW( control->hwnd, EM_SETLIMITTEXT, limit, 0 );
1722 prop = MSI_RecordGetString( rec, 9 );
1723 if( prop )
1724 control->property = strdupW( prop );
1726 val = msi_dup_property( dialog->package->db, control->property );
1727 SetWindowTextW( control->hwnd, val );
1728 msi_free( val );
1729 return ERROR_SUCCESS;
1732 /******************** Masked Edit ********************************************/
1734 #define MASK_MAX_GROUPS 20
1736 struct msi_mask_group
1738 UINT len;
1739 UINT ofs;
1740 WCHAR type;
1741 HWND hwnd;
1744 struct msi_maskedit_info
1746 msi_dialog *dialog;
1747 WNDPROC oldproc;
1748 HWND hwnd;
1749 LPWSTR prop;
1750 UINT num_chars;
1751 UINT num_groups;
1752 struct msi_mask_group group[MASK_MAX_GROUPS];
1755 static BOOL msi_mask_editable( WCHAR type )
1757 switch (type)
1759 case '%':
1760 case '#':
1761 case '&':
1762 case '`':
1763 case '?':
1764 case '^':
1765 return TRUE;
1767 return FALSE;
1770 static void msi_mask_control_change( struct msi_maskedit_info *info )
1772 LPWSTR val;
1773 UINT i, n, r;
1775 val = msi_alloc( (info->num_chars+1)*sizeof(WCHAR) );
1776 for( i=0, n=0; i<info->num_groups; i++ )
1778 if( (info->group[i].len + n) > info->num_chars )
1780 ERR("can't fit control %d text into template\n",i);
1781 break;
1783 if (!msi_mask_editable(info->group[i].type))
1785 for(r=0; r<info->group[i].len; r++)
1786 val[n+r] = info->group[i].type;
1787 val[n+r] = 0;
1789 else
1791 r = GetWindowTextW( info->group[i].hwnd, &val[n], info->group[i].len+1 );
1792 if( r != info->group[i].len )
1793 break;
1795 n += r;
1798 TRACE("%d/%d controls were good\n", i, info->num_groups);
1800 if( i == info->num_groups )
1802 TRACE("Set property %s to %s\n", debugstr_w(info->prop), debugstr_w(val));
1803 CharUpperBuffW( val, info->num_chars );
1804 msi_dialog_set_property( info->dialog->package, info->prop, val );
1805 msi_dialog_evaluate_control_conditions( info->dialog );
1807 msi_free( val );
1810 /* now move to the next control if necessary */
1811 static VOID msi_mask_next_control( struct msi_maskedit_info *info, HWND hWnd )
1813 HWND hWndNext;
1814 UINT len, i;
1816 for( i=0; i<info->num_groups; i++ )
1817 if( info->group[i].hwnd == hWnd )
1818 break;
1820 /* don't move from the last control */
1821 if( i >= (info->num_groups-1) )
1822 return;
1824 len = SendMessageW( hWnd, WM_GETTEXTLENGTH, 0, 0 );
1825 if( len < info->group[i].len )
1826 return;
1828 hWndNext = GetNextDlgTabItem( GetParent( hWnd ), hWnd, FALSE );
1829 SetFocus( hWndNext );
1832 static LRESULT WINAPI
1833 MSIMaskedEdit_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
1835 struct msi_maskedit_info *info;
1836 HRESULT r;
1838 TRACE("%p %04x %08lx %08lx\n", hWnd, msg, wParam, lParam);
1840 info = GetPropW(hWnd, szButtonData);
1842 r = CallWindowProcW(info->oldproc, hWnd, msg, wParam, lParam);
1844 switch( msg )
1846 case WM_COMMAND:
1847 if (HIWORD(wParam) == EN_CHANGE)
1849 msi_mask_control_change( info );
1850 msi_mask_next_control( info, (HWND) lParam );
1852 break;
1853 case WM_NCDESTROY:
1854 msi_free( info->prop );
1855 msi_free( info );
1856 RemovePropW( hWnd, szButtonData );
1857 break;
1860 return r;
1863 /* fish the various bits of the property out and put them in the control */
1864 static void
1865 msi_maskedit_set_text( struct msi_maskedit_info *info, LPCWSTR text )
1867 LPCWSTR p;
1868 UINT i;
1870 p = text;
1871 for( i = 0; i < info->num_groups; i++ )
1873 if( info->group[i].len < strlenW( p ) )
1875 LPWSTR chunk = strdupW( p );
1876 chunk[ info->group[i].len ] = 0;
1877 SetWindowTextW( info->group[i].hwnd, chunk );
1878 msi_free( chunk );
1880 else
1882 SetWindowTextW( info->group[i].hwnd, p );
1883 break;
1885 p += info->group[i].len;
1889 static struct msi_maskedit_info * msi_dialog_parse_groups( LPCWSTR mask )
1891 struct msi_maskedit_info * info = NULL;
1892 int i = 0, n = 0, total = 0;
1893 LPCWSTR p;
1895 TRACE("masked control, template %s\n", debugstr_w(mask));
1897 if( !mask )
1898 return info;
1900 info = msi_alloc_zero( sizeof *info );
1901 if( !info )
1902 return info;
1904 p = strchrW(mask, '<');
1905 if( p )
1906 p++;
1907 else
1908 p = mask;
1910 for( i=0; i<MASK_MAX_GROUPS; i++ )
1912 /* stop at the end of the string */
1913 if( p[0] == 0 || p[0] == '>' )
1914 break;
1916 /* count the number of the same identifier */
1917 for( n=0; p[n] == p[0]; n++ )
1919 info->group[i].ofs = total;
1920 info->group[i].type = p[0];
1921 if( p[n] == '=' )
1923 n++;
1924 total++; /* an extra not part of the group */
1926 info->group[i].len = n;
1927 total += n;
1928 p += n;
1931 TRACE("%d characters in %d groups\n", total, i );
1932 if( i == MASK_MAX_GROUPS )
1933 ERR("too many groups in PIDTemplate %s\n", debugstr_w(mask));
1935 info->num_chars = total;
1936 info->num_groups = i;
1938 return info;
1941 static void
1942 msi_maskedit_create_children( struct msi_maskedit_info *info, LPCWSTR font )
1944 DWORD width, height, style, wx, ww;
1945 RECT rect;
1946 HWND hwnd;
1947 UINT i;
1949 style = WS_CHILD | WS_BORDER | WS_VISIBLE | WS_TABSTOP | ES_AUTOHSCROLL;
1951 GetClientRect( info->hwnd, &rect );
1953 width = rect.right - rect.left;
1954 height = rect.bottom - rect.top;
1956 for( i = 0; i < info->num_groups; i++ )
1958 if (!msi_mask_editable( info->group[i].type ))
1959 continue;
1960 wx = (info->group[i].ofs * width) / info->num_chars;
1961 ww = (info->group[i].len * width) / info->num_chars;
1963 hwnd = CreateWindowW( szEdit, NULL, style, wx, 0, ww, height,
1964 info->hwnd, NULL, NULL, NULL );
1965 if( !hwnd )
1967 ERR("failed to create mask edit sub window\n");
1968 break;
1971 SendMessageW( hwnd, EM_LIMITTEXT, info->group[i].len, 0 );
1973 msi_dialog_set_font( info->dialog, hwnd,
1974 font?font:info->dialog->default_font );
1975 info->group[i].hwnd = hwnd;
1980 * office 2003 uses "73931<````=````=````=````=`````>@@@@@"
1981 * delphi 7 uses "<????-??????-??????-????>" and "<???-???>"
1982 * filemaker pro 7 uses "<^^^^=^^^^=^^^^=^^^^=^^^^=^^^^=^^^^^>"
1984 static UINT msi_dialog_maskedit_control( msi_dialog *dialog, MSIRECORD *rec )
1986 LPWSTR font_mask, val = NULL, font;
1987 struct msi_maskedit_info *info = NULL;
1988 UINT ret = ERROR_SUCCESS;
1989 msi_control *control;
1990 LPCWSTR prop, mask;
1992 TRACE("\n");
1994 font_mask = msi_get_deformatted_field( dialog->package, rec, 10 );
1995 font = msi_dialog_get_style( font_mask, &mask );
1996 if( !mask )
1998 WARN("mask template is empty\n");
1999 goto end;
2002 info = msi_dialog_parse_groups( mask );
2003 if( !info )
2005 ERR("template %s is invalid\n", debugstr_w(mask));
2006 goto end;
2009 info->dialog = dialog;
2011 control = msi_dialog_add_control( dialog, rec, szStatic,
2012 SS_OWNERDRAW | WS_GROUP | WS_VISIBLE );
2013 if( !control )
2015 ERR("Failed to create maskedit container\n");
2016 ret = ERROR_FUNCTION_FAILED;
2017 goto end;
2019 SetWindowLongPtrW( control->hwnd, GWL_EXSTYLE, WS_EX_CONTROLPARENT );
2021 info->hwnd = control->hwnd;
2023 /* subclass the static control */
2024 info->oldproc = (WNDPROC) SetWindowLongPtrW( info->hwnd, GWLP_WNDPROC,
2025 (LONG_PTR)MSIMaskedEdit_WndProc );
2026 SetPropW( control->hwnd, szButtonData, info );
2028 prop = MSI_RecordGetString( rec, 9 );
2029 if( prop )
2030 info->prop = strdupW( prop );
2032 msi_maskedit_create_children( info, font );
2034 if( prop )
2036 val = msi_dup_property( dialog->package->db, prop );
2037 if( val )
2039 msi_maskedit_set_text( info, val );
2040 msi_free( val );
2044 end:
2045 if( ret != ERROR_SUCCESS )
2046 msi_free( info );
2047 msi_free( font_mask );
2048 msi_free( font );
2049 return ret;
2052 /******************** Progress Bar *****************************************/
2054 static UINT msi_dialog_progress_bar( msi_dialog *dialog, MSIRECORD *rec )
2056 msi_control *control;
2057 DWORD attributes, style;
2059 style = WS_VISIBLE;
2060 attributes = MSI_RecordGetInteger( rec, 8 );
2061 if( !(attributes & msidbControlAttributesProgress95) )
2062 style |= PBS_SMOOTH;
2064 control = msi_dialog_add_control( dialog, rec, PROGRESS_CLASSW, style );
2065 if( !control )
2066 return ERROR_FUNCTION_FAILED;
2068 ControlEvent_SubscribeToEvent( dialog->package, dialog,
2069 szSetProgress, control->name, szProgress );
2070 return ERROR_SUCCESS;
2073 /******************** Path Edit ********************************************/
2075 struct msi_pathedit_info
2077 msi_dialog *dialog;
2078 msi_control *control;
2079 WNDPROC oldproc;
2082 static void msi_dialog_update_pathedit( msi_dialog *dialog, msi_control *control )
2084 LPWSTR prop, path;
2085 BOOL indirect;
2087 if (!control && !(control = msi_dialog_find_control_by_type( dialog, szPathEdit )))
2088 return;
2090 indirect = control->attributes & msidbControlAttributesIndirect;
2091 prop = msi_dialog_dup_property( dialog, control->property, indirect );
2092 path = msi_dialog_dup_property( dialog, prop, TRUE );
2094 SetWindowTextW( control->hwnd, path );
2095 SendMessageW( control->hwnd, EM_SETSEL, 0, -1 );
2097 msi_free( path );
2098 msi_free( prop );
2101 /* FIXME: test when this should fail */
2102 static BOOL msi_dialog_verify_path( LPWSTR path )
2104 if ( !lstrlenW( path ) )
2105 return FALSE;
2107 if ( PathIsRelativeW( path ) )
2108 return FALSE;
2110 return TRUE;
2113 /* returns TRUE if the path is valid, FALSE otherwise */
2114 static BOOL msi_dialog_onkillfocus( msi_dialog *dialog, msi_control *control )
2116 LPWSTR buf, prop;
2117 BOOL indirect;
2118 BOOL valid;
2120 indirect = control->attributes & msidbControlAttributesIndirect;
2121 prop = msi_dialog_dup_property( dialog, control->property, indirect );
2123 buf = msi_get_window_text( control->hwnd );
2125 if ( !msi_dialog_verify_path( buf ) )
2127 /* FIXME: display an error message box */
2128 ERR("Invalid path %s\n", debugstr_w( buf ));
2129 valid = FALSE;
2130 SetFocus( control->hwnd );
2132 else
2134 valid = TRUE;
2135 msi_dialog_set_property( dialog->package, prop, buf );
2138 msi_dialog_update_pathedit( dialog, control );
2140 TRACE("edit %s contents changed, set %s\n", debugstr_w(control->name),
2141 debugstr_w(prop));
2143 msi_free( buf );
2144 msi_free( prop );
2146 return valid;
2149 static LRESULT WINAPI MSIPathEdit_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
2151 struct msi_pathedit_info *info = GetPropW(hWnd, szButtonData);
2152 LRESULT r = 0;
2154 TRACE("%p %04x %08lx %08lx\n", hWnd, msg, wParam, lParam);
2156 if ( msg == WM_KILLFOCUS )
2158 /* if the path is invalid, don't handle this message */
2159 if ( !msi_dialog_onkillfocus( info->dialog, info->control ) )
2160 return 0;
2163 r = CallWindowProcW(info->oldproc, hWnd, msg, wParam, lParam);
2165 if ( msg == WM_NCDESTROY )
2167 msi_free( info );
2168 RemovePropW( hWnd, szButtonData );
2171 return r;
2174 static UINT msi_dialog_pathedit_control( msi_dialog *dialog, MSIRECORD *rec )
2176 struct msi_pathedit_info *info;
2177 msi_control *control;
2178 LPCWSTR prop;
2180 info = msi_alloc( sizeof *info );
2181 if (!info)
2182 return ERROR_FUNCTION_FAILED;
2184 control = msi_dialog_add_control( dialog, rec, szEdit,
2185 WS_BORDER | WS_TABSTOP );
2186 control->attributes = MSI_RecordGetInteger( rec, 8 );
2187 prop = MSI_RecordGetString( rec, 9 );
2188 control->property = msi_dialog_dup_property( dialog, prop, FALSE );
2190 info->dialog = dialog;
2191 info->control = control;
2192 info->oldproc = (WNDPROC) SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
2193 (LONG_PTR)MSIPathEdit_WndProc );
2194 SetPropW( control->hwnd, szButtonData, info );
2196 msi_dialog_update_pathedit( dialog, control );
2198 return ERROR_SUCCESS;
2201 static UINT msi_dialog_radiogroup_handler( msi_dialog *dialog, msi_control *control, WPARAM param )
2203 if (HIWORD(param) != BN_CLICKED)
2204 return ERROR_SUCCESS;
2206 TRACE("clicked radio button %s, set %s\n", debugstr_w(control->name), debugstr_w(control->property));
2208 msi_dialog_set_property( dialog->package, control->property, control->name );
2210 return msi_dialog_button_handler( dialog, control, param );
2213 /* radio buttons are a bit different from normal controls */
2214 static UINT msi_dialog_create_radiobutton( MSIRECORD *rec, LPVOID param )
2216 radio_button_group_descr *group = param;
2217 msi_dialog *dialog = group->dialog;
2218 msi_control *control;
2219 LPCWSTR prop, text, name;
2220 DWORD style, attributes = group->attributes;
2222 style = WS_CHILD | BS_AUTORADIOBUTTON | BS_MULTILINE | WS_TABSTOP;
2223 name = MSI_RecordGetString( rec, 3 );
2224 text = MSI_RecordGetString( rec, 8 );
2225 if( attributes & msidbControlAttributesVisible )
2226 style |= WS_VISIBLE;
2227 if( ~attributes & msidbControlAttributesEnabled )
2228 style |= WS_DISABLED;
2230 control = msi_dialog_create_window( dialog, rec, 0, szButton, name, text,
2231 style, group->parent->hwnd );
2232 if (!control)
2233 return ERROR_FUNCTION_FAILED;
2234 control->handler = msi_dialog_radiogroup_handler;
2236 if (group->propval && !strcmpW( control->name, group->propval ))
2237 SendMessageW(control->hwnd, BM_SETCHECK, BST_CHECKED, 0);
2239 prop = MSI_RecordGetString( rec, 1 );
2240 if( prop )
2241 control->property = strdupW( prop );
2243 return ERROR_SUCCESS;
2246 static BOOL CALLBACK msi_radioground_child_enum( HWND hWnd, LPARAM lParam )
2248 EnableWindow( hWnd, lParam );
2249 return TRUE;
2252 static LRESULT WINAPI MSIRadioGroup_WndProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
2254 WNDPROC oldproc = (WNDPROC)GetPropW( hWnd, szButtonData );
2255 LRESULT r;
2257 TRACE("hWnd %p msg %04x wParam 0x%08lx lParam 0x%08lx\n", hWnd, msg, wParam, lParam);
2259 if (msg == WM_COMMAND) /* Forward notifications to dialog */
2260 SendMessageW( GetParent( hWnd ), msg, wParam, lParam );
2262 r = CallWindowProcW( oldproc, hWnd, msg, wParam, lParam );
2264 /* make sure the radio buttons show as disabled if the parent is disabled */
2265 if (msg == WM_ENABLE)
2266 EnumChildWindows( hWnd, msi_radioground_child_enum, wParam );
2268 return r;
2271 static UINT msi_dialog_radiogroup_control( msi_dialog *dialog, MSIRECORD *rec )
2273 static const WCHAR query[] = {
2274 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2275 'R','a','d','i','o','B','u','t','t','o','n',' ','W','H','E','R','E',' ',
2276 '`','P','r','o','p','e','r','t','y','`',' ','=',' ','\'','%','s','\'',0};
2277 UINT r;
2278 LPCWSTR prop;
2279 msi_control *control;
2280 MSIQUERY *view;
2281 radio_button_group_descr group;
2282 MSIPACKAGE *package = dialog->package;
2283 WNDPROC oldproc;
2284 DWORD attr, style = WS_GROUP;
2286 prop = MSI_RecordGetString( rec, 9 );
2288 TRACE("%p %p %s\n", dialog, rec, debugstr_w( prop ));
2290 attr = MSI_RecordGetInteger( rec, 8 );
2291 if (attr & msidbControlAttributesHasBorder)
2292 style |= BS_GROUPBOX;
2293 else
2294 style |= BS_OWNERDRAW;
2296 /* Create parent group box to hold radio buttons */
2297 control = msi_dialog_add_control( dialog, rec, szButton, style );
2298 if( !control )
2299 return ERROR_FUNCTION_FAILED;
2301 oldproc = (WNDPROC) SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
2302 (LONG_PTR)MSIRadioGroup_WndProc );
2303 SetPropW(control->hwnd, szButtonData, oldproc);
2304 SetWindowLongPtrW( control->hwnd, GWL_EXSTYLE, WS_EX_CONTROLPARENT );
2306 if( prop )
2307 control->property = strdupW( prop );
2309 /* query the Radio Button table for all control in this group */
2310 r = MSI_OpenQuery( package->db, &view, query, prop );
2311 if( r != ERROR_SUCCESS )
2313 ERR("query failed for dialog %s radio group %s\n",
2314 debugstr_w(dialog->name), debugstr_w(prop));
2315 return ERROR_INVALID_PARAMETER;
2318 group.dialog = dialog;
2319 group.parent = control;
2320 group.attributes = MSI_RecordGetInteger( rec, 8 );
2321 group.propval = msi_dup_property( dialog->package->db, control->property );
2323 r = MSI_IterateRecords( view, 0, msi_dialog_create_radiobutton, &group );
2324 msiobj_release( &view->hdr );
2325 msi_free( group.propval );
2326 return r;
2329 static void
2330 msi_seltree_sync_item_state( HWND hwnd, MSIFEATURE *feature, HTREEITEM hItem )
2332 TVITEMW tvi;
2333 DWORD index = feature->ActionRequest;
2335 TRACE("Feature %s -> %d %d %d\n", debugstr_w(feature->Title),
2336 feature->Installed, feature->Action, feature->ActionRequest);
2338 if (index == INSTALLSTATE_UNKNOWN)
2339 index = INSTALLSTATE_ABSENT;
2341 tvi.mask = TVIF_STATE;
2342 tvi.hItem = hItem;
2343 tvi.state = INDEXTOSTATEIMAGEMASK( index );
2344 tvi.stateMask = TVIS_STATEIMAGEMASK;
2346 SendMessageW( hwnd, TVM_SETITEMW, 0, (LPARAM) &tvi );
2349 static UINT
2350 msi_seltree_popup_menu( HWND hwnd, INT x, INT y )
2352 HMENU hMenu;
2353 INT r;
2355 /* create a menu to display */
2356 hMenu = CreatePopupMenu();
2358 /* FIXME: load strings from resources */
2359 AppendMenuA( hMenu, MF_ENABLED, INSTALLSTATE_LOCAL, "Install feature locally");
2360 AppendMenuA( hMenu, MF_ENABLED, USER_INSTALLSTATE_ALL, "Install entire feature");
2361 AppendMenuA( hMenu, MF_ENABLED, INSTALLSTATE_ADVERTISED, "Install on demand");
2362 AppendMenuA( hMenu, MF_ENABLED, INSTALLSTATE_ABSENT, "Don't install");
2363 r = TrackPopupMenu( hMenu, TPM_LEFTALIGN | TPM_TOPALIGN | TPM_RETURNCMD,
2364 x, y, 0, hwnd, NULL );
2365 DestroyMenu( hMenu );
2366 return r;
2369 static void
2370 msi_seltree_update_feature_installstate( HWND hwnd, HTREEITEM hItem,
2371 MSIPACKAGE *package, MSIFEATURE *feature, INSTALLSTATE state )
2373 feature->ActionRequest = state;
2374 msi_seltree_sync_item_state( hwnd, feature, hItem );
2375 ACTION_UpdateComponentStates( package, feature );
2378 static void
2379 msi_seltree_update_siblings_and_children_installstate( HWND hwnd, HTREEITEM curr,
2380 MSIPACKAGE *package, INSTALLSTATE state)
2382 /* update all siblings */
2385 MSIFEATURE *feature;
2386 HTREEITEM child;
2388 feature = msi_seltree_feature_from_item( hwnd, curr );
2389 msi_seltree_update_feature_installstate( hwnd, curr, package, feature, state );
2391 /* update this sibling's children */
2392 child = (HTREEITEM)SendMessageW( hwnd, TVM_GETNEXTITEM, (WPARAM)TVGN_CHILD, (LPARAM)curr );
2393 if (child)
2394 msi_seltree_update_siblings_and_children_installstate( hwnd, child,
2395 package, state );
2397 while ((curr = (HTREEITEM)SendMessageW( hwnd, TVM_GETNEXTITEM, (WPARAM)TVGN_NEXT, (LPARAM)curr )));
2400 static LRESULT
2401 msi_seltree_menu( HWND hwnd, HTREEITEM hItem )
2403 struct msi_selection_tree_info *info;
2404 MSIFEATURE *feature;
2405 MSIPACKAGE *package;
2406 union {
2407 RECT rc;
2408 POINT pt[2];
2409 HTREEITEM hItem;
2410 } u;
2411 UINT r;
2413 info = GetPropW(hwnd, szButtonData);
2414 package = info->dialog->package;
2416 feature = msi_seltree_feature_from_item( hwnd, hItem );
2417 if (!feature)
2419 ERR("item %p feature was NULL\n", hItem);
2420 return 0;
2423 /* get the item's rectangle to put the menu just below it */
2424 u.hItem = hItem;
2425 SendMessageW( hwnd, TVM_GETITEMRECT, 0, (LPARAM) &u.rc );
2426 MapWindowPoints( hwnd, NULL, u.pt, 2 );
2428 r = msi_seltree_popup_menu( hwnd, u.rc.left, u.rc.top );
2430 switch (r)
2432 case USER_INSTALLSTATE_ALL:
2433 r = INSTALLSTATE_LOCAL;
2434 /* fall-through */
2435 case INSTALLSTATE_ADVERTISED:
2436 case INSTALLSTATE_ABSENT:
2438 HTREEITEM child;
2439 child = (HTREEITEM)SendMessageW( hwnd, TVM_GETNEXTITEM, (WPARAM)TVGN_CHILD, (LPARAM)hItem );
2440 if (child)
2441 msi_seltree_update_siblings_and_children_installstate( hwnd, child, package, r );
2443 /* fall-through */
2444 case INSTALLSTATE_LOCAL:
2445 msi_seltree_update_feature_installstate( hwnd, hItem, package, feature, r );
2446 break;
2449 return 0;
2452 static LRESULT WINAPI
2453 MSISelectionTree_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
2455 struct msi_selection_tree_info *info;
2456 TVHITTESTINFO tvhti;
2457 HRESULT r;
2459 TRACE("%p %04x %08lx %08lx\n", hWnd, msg, wParam, lParam);
2461 info = GetPropW(hWnd, szButtonData);
2463 switch( msg )
2465 case WM_LBUTTONDOWN:
2466 tvhti.pt.x = (short)LOWORD( lParam );
2467 tvhti.pt.y = (short)HIWORD( lParam );
2468 tvhti.flags = 0;
2469 tvhti.hItem = 0;
2470 CallWindowProcW(info->oldproc, hWnd, TVM_HITTEST, 0, (LPARAM) &tvhti );
2471 if (tvhti.flags & TVHT_ONITEMSTATEICON)
2472 return msi_seltree_menu( hWnd, tvhti.hItem );
2473 break;
2475 r = CallWindowProcW(info->oldproc, hWnd, msg, wParam, lParam);
2477 switch( msg )
2479 case WM_NCDESTROY:
2480 msi_free( info );
2481 RemovePropW( hWnd, szButtonData );
2482 break;
2484 return r;
2487 static void
2488 msi_seltree_add_child_features( MSIPACKAGE *package, HWND hwnd,
2489 LPCWSTR parent, HTREEITEM hParent )
2491 struct msi_selection_tree_info *info = GetPropW( hwnd, szButtonData );
2492 MSIFEATURE *feature;
2493 TVINSERTSTRUCTW tvis;
2494 HTREEITEM hitem, hfirst = NULL;
2496 LIST_FOR_EACH_ENTRY( feature, &package->features, MSIFEATURE, entry )
2498 if ( parent && feature->Feature_Parent && strcmpW( parent, feature->Feature_Parent ))
2499 continue;
2500 else if ( parent && !feature->Feature_Parent )
2501 continue;
2502 else if ( !parent && feature->Feature_Parent )
2503 continue;
2505 if ( !feature->Title )
2506 continue;
2508 if ( !feature->Display )
2509 continue;
2511 memset( &tvis, 0, sizeof tvis );
2512 tvis.hParent = hParent;
2513 tvis.hInsertAfter = TVI_LAST;
2514 tvis.u.item.mask = TVIF_TEXT | TVIF_PARAM;
2515 tvis.u.item.pszText = feature->Title;
2516 tvis.u.item.lParam = (LPARAM) feature;
2518 hitem = (HTREEITEM) SendMessageW( hwnd, TVM_INSERTITEMW, 0, (LPARAM) &tvis );
2519 if (!hitem)
2520 continue;
2522 if (!hfirst)
2523 hfirst = hitem;
2525 msi_seltree_sync_item_state( hwnd, feature, hitem );
2526 msi_seltree_add_child_features( package, hwnd,
2527 feature->Feature, hitem );
2529 /* the node is expanded if Display is odd */
2530 if ( feature->Display % 2 != 0 )
2531 SendMessageW( hwnd, TVM_EXPAND, TVE_EXPAND, (LPARAM) hitem );
2534 /* select the first item */
2535 SendMessageW( hwnd, TVM_SELECTITEM, TVGN_CARET | TVGN_DROPHILITE, (LPARAM) hfirst );
2536 info->selected = hfirst;
2539 static void msi_seltree_create_imagelist( HWND hwnd )
2541 const int bm_width = 32, bm_height = 16, bm_count = 3;
2542 const int bm_resource = 0x1001;
2543 HIMAGELIST himl;
2544 int i;
2545 HBITMAP hbmp;
2547 himl = ImageList_Create( bm_width, bm_height, FALSE, 4, 0 );
2548 if (!himl)
2550 ERR("failed to create image list\n");
2551 return;
2554 for (i=0; i<bm_count; i++)
2556 hbmp = LoadBitmapW( msi_hInstance, MAKEINTRESOURCEW(i+bm_resource) );
2557 if (!hbmp)
2559 ERR("failed to load bitmap %d\n", i);
2560 break;
2564 * Add a dummy bitmap at offset zero because the treeview
2565 * can't use it as a state mask (zero means no user state).
2567 if (!i)
2568 ImageList_Add( himl, hbmp, NULL );
2570 ImageList_Add( himl, hbmp, NULL );
2573 SendMessageW( hwnd, TVM_SETIMAGELIST, TVSIL_STATE, (LPARAM)himl );
2576 static UINT msi_dialog_seltree_handler( msi_dialog *dialog,
2577 msi_control *control, WPARAM param )
2579 struct msi_selection_tree_info *info = GetPropW( control->hwnd, szButtonData );
2580 LPNMTREEVIEWW tv = (LPNMTREEVIEWW)param;
2581 MSIRECORD *row, *rec;
2582 MSIFOLDER *folder;
2583 MSIFEATURE *feature;
2584 LPCWSTR dir, title = NULL;
2585 UINT r = ERROR_SUCCESS;
2587 static const WCHAR select[] = {
2588 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2589 '`','F','e','a','t','u','r','e','`',' ','W','H','E','R','E',' ',
2590 '`','T','i','t','l','e','`',' ','=',' ','\'','%','s','\'',0
2593 if (tv->hdr.code != TVN_SELCHANGINGW)
2594 return ERROR_SUCCESS;
2596 info->selected = tv->itemNew.hItem;
2598 if (!(tv->itemNew.mask & TVIF_TEXT))
2600 feature = msi_seltree_feature_from_item( control->hwnd, tv->itemNew.hItem );
2601 if (feature)
2602 title = feature->Title;
2604 else
2605 title = tv->itemNew.pszText;
2607 row = MSI_QueryGetRecord( dialog->package->db, select, title );
2608 if (!row)
2609 return ERROR_FUNCTION_FAILED;
2611 rec = MSI_CreateRecord( 1 );
2613 MSI_RecordSetStringW( rec, 1, MSI_RecordGetString( row, 4 ) );
2614 ControlEvent_FireSubscribedEvent( dialog->package, szSelectionDescription, rec );
2616 dir = MSI_RecordGetString( row, 7 );
2617 if (dir)
2619 folder = msi_get_loaded_folder( dialog->package, dir );
2620 if (!folder)
2622 r = ERROR_FUNCTION_FAILED;
2623 goto done;
2625 MSI_RecordSetStringW( rec, 1, folder->ResolvedTarget );
2627 else
2628 MSI_RecordSetStringW( rec, 1, NULL );
2630 ControlEvent_FireSubscribedEvent( dialog->package, szSelectionPath, rec );
2632 done:
2633 msiobj_release(&row->hdr);
2634 msiobj_release(&rec->hdr);
2636 return r;
2639 static UINT msi_dialog_selection_tree( msi_dialog *dialog, MSIRECORD *rec )
2641 msi_control *control;
2642 LPCWSTR prop, control_name;
2643 MSIPACKAGE *package = dialog->package;
2644 DWORD style;
2645 struct msi_selection_tree_info *info;
2647 info = msi_alloc( sizeof *info );
2648 if (!info)
2649 return ERROR_FUNCTION_FAILED;
2651 /* create the treeview control */
2652 style = TVS_HASLINES | TVS_HASBUTTONS | TVS_LINESATROOT;
2653 style |= WS_GROUP | WS_VSCROLL;
2654 control = msi_dialog_add_control( dialog, rec, WC_TREEVIEWW, style );
2655 if (!control)
2657 msi_free(info);
2658 return ERROR_FUNCTION_FAILED;
2661 control->handler = msi_dialog_seltree_handler;
2662 control_name = MSI_RecordGetString( rec, 2 );
2663 control->attributes = MSI_RecordGetInteger( rec, 8 );
2664 prop = MSI_RecordGetString( rec, 9 );
2665 control->property = msi_dialog_dup_property( dialog, prop, FALSE );
2667 /* subclass */
2668 info->dialog = dialog;
2669 info->hwnd = control->hwnd;
2670 info->oldproc = (WNDPROC) SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
2671 (LONG_PTR)MSISelectionTree_WndProc );
2672 SetPropW( control->hwnd, szButtonData, info );
2674 ControlEvent_SubscribeToEvent( dialog->package, dialog,
2675 szSelectionPath, control_name, szProperty );
2677 /* initialize it */
2678 msi_seltree_create_imagelist( control->hwnd );
2679 msi_seltree_add_child_features( package, control->hwnd, NULL, NULL );
2681 return ERROR_SUCCESS;
2684 /******************** Group Box ***************************************/
2686 static UINT msi_dialog_group_box( msi_dialog *dialog, MSIRECORD *rec )
2688 msi_control *control;
2689 DWORD style;
2691 style = BS_GROUPBOX | WS_CHILD | WS_GROUP;
2692 control = msi_dialog_add_control( dialog, rec, WC_BUTTONW, style );
2693 if (!control)
2694 return ERROR_FUNCTION_FAILED;
2696 return ERROR_SUCCESS;
2699 /******************** List Box ***************************************/
2701 struct msi_listbox_info
2703 msi_dialog *dialog;
2704 HWND hwnd;
2705 WNDPROC oldproc;
2706 DWORD num_items;
2707 DWORD addpos_items;
2708 LPWSTR *items;
2711 static LRESULT WINAPI MSIListBox_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
2713 struct msi_listbox_info *info;
2714 LRESULT r;
2715 DWORD j;
2717 TRACE("%p %04x %08lx %08lx\n", hWnd, msg, wParam, lParam);
2719 info = GetPropW( hWnd, szButtonData );
2720 if (!info)
2721 return 0;
2723 r = CallWindowProcW( info->oldproc, hWnd, msg, wParam, lParam );
2725 switch( msg )
2727 case WM_NCDESTROY:
2728 for (j = 0; j < info->num_items; j++)
2729 msi_free( info->items[j] );
2730 msi_free( info->items );
2731 msi_free( info );
2732 RemovePropW( hWnd, szButtonData );
2733 break;
2736 return r;
2739 static UINT msi_listbox_add_item( MSIRECORD *rec, LPVOID param )
2741 struct msi_listbox_info *info = param;
2742 LPCWSTR value, text;
2743 int pos;
2745 value = MSI_RecordGetString( rec, 3 );
2746 text = MSI_RecordGetString( rec, 4 );
2748 info->items[info->addpos_items] = strdupW( value );
2750 pos = SendMessageW( info->hwnd, LB_ADDSTRING, 0, (LPARAM)text );
2751 SendMessageW( info->hwnd, LB_SETITEMDATA, pos, (LPARAM)info->items[info->addpos_items] );
2752 info->addpos_items++;
2753 return ERROR_SUCCESS;
2756 static UINT msi_listbox_add_items( struct msi_listbox_info *info, LPCWSTR property )
2758 static const WCHAR query[] = {
2759 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2760 '`','L','i','s','t','B','o','x','`',' ','W','H','E','R','E',' ',
2761 '`','P','r','o','p','e','r','t','y','`',' ','=',' ','\'','%','s','\'',' ',
2762 'O','R','D','E','R',' ','B','Y',' ','`','O','r','d','e','r','`',0};
2763 MSIQUERY *view;
2764 DWORD count;
2765 UINT r;
2767 r = MSI_OpenQuery( info->dialog->package->db, &view, query, property );
2768 if ( r != ERROR_SUCCESS )
2769 return r;
2771 /* just get the number of records */
2772 count = 0;
2773 r = MSI_IterateRecords( view, &count, NULL, NULL );
2774 if (r != ERROR_SUCCESS)
2776 msiobj_release( &view->hdr );
2777 return r;
2779 info->num_items = count;
2780 info->items = msi_alloc( sizeof(*info->items) * count );
2782 r = MSI_IterateRecords( view, NULL, msi_listbox_add_item, info );
2783 msiobj_release( &view->hdr );
2784 return r;
2787 static UINT msi_dialog_listbox_handler( msi_dialog *dialog,
2788 msi_control *control, WPARAM param )
2790 struct msi_listbox_info *info;
2791 int index;
2792 LPCWSTR value;
2794 if( HIWORD(param) != LBN_SELCHANGE )
2795 return ERROR_SUCCESS;
2797 info = GetPropW( control->hwnd, szButtonData );
2798 index = SendMessageW( control->hwnd, LB_GETCURSEL, 0, 0 );
2799 value = (LPCWSTR) SendMessageW( control->hwnd, LB_GETITEMDATA, index, 0 );
2801 msi_dialog_set_property( info->dialog->package, control->property, value );
2802 msi_dialog_evaluate_control_conditions( info->dialog );
2804 return ERROR_SUCCESS;
2807 static UINT msi_dialog_list_box( msi_dialog *dialog, MSIRECORD *rec )
2809 struct msi_listbox_info *info;
2810 msi_control *control;
2811 DWORD attributes, style;
2812 LPCWSTR prop;
2814 info = msi_alloc( sizeof *info );
2815 if (!info)
2816 return ERROR_FUNCTION_FAILED;
2818 style = WS_TABSTOP | WS_GROUP | WS_CHILD | LBS_NOTIFY | WS_VSCROLL | WS_BORDER;
2819 attributes = MSI_RecordGetInteger( rec, 8 );
2820 if (~attributes & msidbControlAttributesSorted)
2821 style |= LBS_SORT;
2823 control = msi_dialog_add_control( dialog, rec, WC_LISTBOXW, style );
2824 if (!control)
2826 msi_free(info);
2827 return ERROR_FUNCTION_FAILED;
2830 control->handler = msi_dialog_listbox_handler;
2832 prop = MSI_RecordGetString( rec, 9 );
2833 control->property = msi_dialog_dup_property( dialog, prop, FALSE );
2835 /* subclass */
2836 info->dialog = dialog;
2837 info->hwnd = control->hwnd;
2838 info->items = NULL;
2839 info->addpos_items = 0;
2840 info->oldproc = (WNDPROC)SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
2841 (LONG_PTR)MSIListBox_WndProc );
2842 SetPropW( control->hwnd, szButtonData, info );
2844 if ( control->property )
2845 msi_listbox_add_items( info, control->property );
2847 return ERROR_SUCCESS;
2850 /******************** Directory Combo ***************************************/
2852 static void msi_dialog_update_directory_combo( msi_dialog *dialog, msi_control *control )
2854 LPWSTR prop, path;
2855 BOOL indirect;
2857 if (!control && !(control = msi_dialog_find_control_by_type( dialog, szDirectoryCombo )))
2858 return;
2860 indirect = control->attributes & msidbControlAttributesIndirect;
2861 prop = msi_dialog_dup_property( dialog, control->property, indirect );
2862 path = msi_dialog_dup_property( dialog, prop, TRUE );
2864 PathStripPathW( path );
2865 PathRemoveBackslashW( path );
2867 SendMessageW( control->hwnd, CB_INSERTSTRING, 0, (LPARAM)path );
2868 SendMessageW( control->hwnd, CB_SETCURSEL, 0, 0 );
2870 msi_free( path );
2871 msi_free( prop );
2874 static UINT msi_dialog_directory_combo( msi_dialog *dialog, MSIRECORD *rec )
2876 msi_control *control;
2877 LPCWSTR prop;
2878 DWORD style;
2880 /* FIXME: use CBS_OWNERDRAWFIXED and add owner draw code */
2881 style = CBS_DROPDOWNLIST | CBS_HASSTRINGS | WS_CHILD |
2882 WS_GROUP | WS_TABSTOP | WS_VSCROLL;
2883 control = msi_dialog_add_control( dialog, rec, WC_COMBOBOXW, style );
2884 if (!control)
2885 return ERROR_FUNCTION_FAILED;
2887 control->attributes = MSI_RecordGetInteger( rec, 8 );
2888 prop = MSI_RecordGetString( rec, 9 );
2889 control->property = msi_dialog_dup_property( dialog, prop, FALSE );
2891 msi_dialog_update_directory_combo( dialog, control );
2893 return ERROR_SUCCESS;
2896 /******************** Directory List ***************************************/
2898 static void msi_dialog_update_directory_list( msi_dialog *dialog, msi_control *control )
2900 WCHAR dir_spec[MAX_PATH];
2901 WIN32_FIND_DATAW wfd;
2902 LPWSTR prop, path;
2903 BOOL indirect;
2904 LVITEMW item;
2905 HANDLE file;
2907 static const WCHAR asterisk[] = {'*',0};
2909 if (!control && !(control = msi_dialog_find_control_by_type( dialog, szDirectoryList )))
2910 return;
2912 /* clear the list-view */
2913 SendMessageW( control->hwnd, LVM_DELETEALLITEMS, 0, 0 );
2915 indirect = control->attributes & msidbControlAttributesIndirect;
2916 prop = msi_dialog_dup_property( dialog, control->property, indirect );
2917 path = msi_dialog_dup_property( dialog, prop, TRUE );
2919 lstrcpyW( dir_spec, path );
2920 lstrcatW( dir_spec, asterisk );
2922 file = FindFirstFileW( dir_spec, &wfd );
2923 if ( file == INVALID_HANDLE_VALUE )
2924 return;
2928 if ( wfd.dwFileAttributes != FILE_ATTRIBUTE_DIRECTORY )
2929 continue;
2931 if ( !strcmpW( wfd.cFileName, szDot ) || !strcmpW( wfd.cFileName, szDotDot ) )
2932 continue;
2934 item.mask = LVIF_TEXT;
2935 item.cchTextMax = MAX_PATH;
2936 item.iItem = 0;
2937 item.iSubItem = 0;
2938 item.pszText = wfd.cFileName;
2940 SendMessageW( control->hwnd, LVM_INSERTITEMW, 0, (LPARAM)&item );
2941 } while ( FindNextFileW( file, &wfd ) );
2943 msi_free( prop );
2944 msi_free( path );
2945 FindClose( file );
2948 UINT msi_dialog_directorylist_up( msi_dialog *dialog )
2950 msi_control *control;
2951 LPWSTR prop, path, ptr;
2952 BOOL indirect;
2954 control = msi_dialog_find_control_by_type( dialog, szDirectoryList );
2955 indirect = control->attributes & msidbControlAttributesIndirect;
2956 prop = msi_dialog_dup_property( dialog, control->property, indirect );
2957 path = msi_dialog_dup_property( dialog, prop, TRUE );
2959 /* strip off the last directory */
2960 ptr = PathFindFileNameW( path );
2961 if (ptr != path) *(ptr - 1) = '\0';
2962 PathAddBackslashW( path );
2964 msi_dialog_set_property( dialog->package, prop, path );
2966 msi_dialog_update_directory_list( dialog, NULL );
2967 msi_dialog_update_directory_combo( dialog, NULL );
2968 msi_dialog_update_pathedit( dialog, NULL );
2970 msi_free( path );
2971 msi_free( prop );
2973 return ERROR_SUCCESS;
2976 static UINT msi_dialog_dirlist_handler( msi_dialog *dialog,
2977 msi_control *control, WPARAM param )
2979 LPNMHDR nmhdr = (LPNMHDR)param;
2980 WCHAR new_path[MAX_PATH];
2981 WCHAR text[MAX_PATH];
2982 LPWSTR path, prop;
2983 BOOL indirect;
2984 LVITEMW item;
2985 int index;
2987 if (nmhdr->code != LVN_ITEMACTIVATE)
2988 return ERROR_SUCCESS;
2990 index = SendMessageW( control->hwnd, LVM_GETNEXTITEM, -1, LVNI_SELECTED );
2991 if ( index < 0 )
2993 ERR("No list-view item selected!\n");
2994 return ERROR_FUNCTION_FAILED;
2997 item.iSubItem = 0;
2998 item.pszText = text;
2999 item.cchTextMax = MAX_PATH;
3000 SendMessageW( control->hwnd, LVM_GETITEMTEXTW, index, (LPARAM)&item );
3002 indirect = control->attributes & msidbControlAttributesIndirect;
3003 prop = msi_dialog_dup_property( dialog, control->property, indirect );
3004 path = msi_dialog_dup_property( dialog, prop, TRUE );
3006 lstrcpyW( new_path, path );
3007 lstrcatW( new_path, text );
3008 lstrcatW( new_path, szBackSlash );
3010 msi_dialog_set_property( dialog->package, prop, new_path );
3012 msi_dialog_update_directory_list( dialog, NULL );
3013 msi_dialog_update_directory_combo( dialog, NULL );
3014 msi_dialog_update_pathedit( dialog, NULL );
3016 msi_free( prop );
3017 msi_free( path );
3018 return ERROR_SUCCESS;
3021 static UINT msi_dialog_directory_list( msi_dialog *dialog, MSIRECORD *rec )
3023 msi_control *control;
3024 LPCWSTR prop;
3025 DWORD style;
3027 style = LVS_LIST | WS_VSCROLL | LVS_SHAREIMAGELISTS |
3028 LVS_AUTOARRANGE | LVS_SINGLESEL | WS_BORDER |
3029 LVS_SORTASCENDING | WS_CHILD | WS_GROUP | WS_TABSTOP;
3030 control = msi_dialog_add_control( dialog, rec, WC_LISTVIEWW, style );
3031 if (!control)
3032 return ERROR_FUNCTION_FAILED;
3034 control->attributes = MSI_RecordGetInteger( rec, 8 );
3035 control->handler = msi_dialog_dirlist_handler;
3036 prop = MSI_RecordGetString( rec, 9 );
3037 control->property = msi_dialog_dup_property( dialog, prop, FALSE );
3039 /* double click to activate an item in the list */
3040 SendMessageW( control->hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE,
3041 0, LVS_EX_TWOCLICKACTIVATE );
3043 msi_dialog_update_directory_list( dialog, control );
3045 return ERROR_SUCCESS;
3048 /******************** VolumeCost List ***************************************/
3050 static BOOL str_is_number( LPCWSTR str )
3052 int i;
3054 for (i = 0; i < lstrlenW( str ); i++)
3055 if (!isdigitW(str[i]))
3056 return FALSE;
3058 return TRUE;
3061 static const WCHAR column_keys[][80] =
3063 {'V','o','l','u','m','e','C','o','s','t','V','o','l','u','m','e',0},
3064 {'V','o','l','u','m','e','C','o','s','t','S','i','z','e',0},
3065 {'V','o','l','u','m','e','C','o','s','t','A','v','a','i','l','a','b','l','e',0},
3066 {'V','o','l','u','m','e','C','o','s','t','R','e','q','u','i','r','e','d',0},
3067 {'V','o','l','u','m','e','C','o','s','t','D','i','f','f','e','r','e','n','c','e',0}
3070 static void msi_dialog_vcl_add_columns( msi_dialog *dialog, msi_control *control, MSIRECORD *rec )
3072 LPCWSTR text = MSI_RecordGetString( rec, 10 );
3073 LPCWSTR begin = text, end;
3074 WCHAR *num;
3075 LVCOLUMNW lvc;
3076 DWORD count = 0;
3078 static const WCHAR negative[] = {'-',0};
3080 if (!text) return;
3082 while ((begin = strchrW( begin, '{' )) && count < 5)
3084 if (!(end = strchrW( begin, '}' )))
3085 return;
3087 num = msi_alloc( (end-begin+1)*sizeof(WCHAR) );
3088 if (!num)
3089 return;
3091 lstrcpynW( num, begin + 1, end - begin );
3092 begin += end - begin + 1;
3094 /* empty braces or '0' hides the column */
3095 if ( !num[0] || !strcmpW( num, szZero ) )
3097 count++;
3098 msi_free( num );
3099 continue;
3102 /* the width must be a positive number
3103 * if a width is invalid, all remaining columns are hidden
3105 if ( !strncmpW( num, negative, 1 ) || !str_is_number( num ) ) {
3106 msi_free( num );
3107 return;
3110 ZeroMemory( &lvc, sizeof(lvc) );
3111 lvc.mask = LVCF_TEXT | LVCF_WIDTH | LVCF_SUBITEM;
3112 lvc.cx = atolW( num );
3113 lvc.pszText = msi_dialog_get_uitext( dialog, column_keys[count] );
3115 SendMessageW( control->hwnd, LVM_INSERTCOLUMNW, count++, (LPARAM)&lvc );
3116 msi_free( lvc.pszText );
3117 msi_free( num );
3121 static LONGLONG msi_vcl_get_cost( msi_dialog *dialog )
3123 MSIFEATURE *feature;
3124 INT each_cost;
3125 LONGLONG total_cost = 0;
3127 LIST_FOR_EACH_ENTRY( feature, &dialog->package->features, MSIFEATURE, entry )
3129 if (ERROR_SUCCESS == (MSI_GetFeatureCost(dialog->package, feature,
3130 MSICOSTTREE_SELFONLY, INSTALLSTATE_LOCAL, &each_cost)))
3132 /* each_cost is in 512-byte units */
3133 total_cost += each_cost * 512;
3135 if (ERROR_SUCCESS == (MSI_GetFeatureCost(dialog->package, feature,
3136 MSICOSTTREE_SELFONLY, INSTALLSTATE_ABSENT, &each_cost)))
3138 /* each_cost is in 512-byte units */
3139 total_cost -= each_cost * 512;
3142 return total_cost;
3145 static void msi_dialog_vcl_add_drives( msi_dialog *dialog, msi_control *control )
3147 ULARGE_INTEGER total, free;
3148 LONGLONG difference, cost;
3149 WCHAR size_text[MAX_PATH];
3150 WCHAR cost_text[MAX_PATH];
3151 LPWSTR drives, ptr;
3152 LVITEMW lvitem;
3153 DWORD size;
3154 int i = 0;
3156 cost = msi_vcl_get_cost(dialog);
3157 StrFormatByteSizeW(cost, cost_text, MAX_PATH);
3159 size = GetLogicalDriveStringsW( 0, NULL );
3160 if ( !size ) return;
3162 drives = msi_alloc( (size + 1) * sizeof(WCHAR) );
3163 if ( !drives ) return;
3165 GetLogicalDriveStringsW( size, drives );
3167 ptr = drives;
3168 while (*ptr)
3170 lvitem.mask = LVIF_TEXT;
3171 lvitem.iItem = i;
3172 lvitem.iSubItem = 0;
3173 lvitem.pszText = ptr;
3174 lvitem.cchTextMax = lstrlenW(ptr) + 1;
3175 SendMessageW( control->hwnd, LVM_INSERTITEMW, 0, (LPARAM)&lvitem );
3177 GetDiskFreeSpaceExW(ptr, &free, &total, NULL);
3178 difference = free.QuadPart - cost;
3180 StrFormatByteSizeW(total.QuadPart, size_text, MAX_PATH);
3181 lvitem.iSubItem = 1;
3182 lvitem.pszText = size_text;
3183 lvitem.cchTextMax = lstrlenW(size_text) + 1;
3184 SendMessageW( control->hwnd, LVM_SETITEMW, 0, (LPARAM)&lvitem );
3186 StrFormatByteSizeW(free.QuadPart, size_text, MAX_PATH);
3187 lvitem.iSubItem = 2;
3188 lvitem.pszText = size_text;
3189 lvitem.cchTextMax = lstrlenW(size_text) + 1;
3190 SendMessageW( control->hwnd, LVM_SETITEMW, 0, (LPARAM)&lvitem );
3192 lvitem.iSubItem = 3;
3193 lvitem.pszText = cost_text;
3194 lvitem.cchTextMax = lstrlenW(cost_text) + 1;
3195 SendMessageW( control->hwnd, LVM_SETITEMW, 0, (LPARAM)&lvitem );
3197 StrFormatByteSizeW(difference, size_text, MAX_PATH);
3198 lvitem.iSubItem = 4;
3199 lvitem.pszText = size_text;
3200 lvitem.cchTextMax = lstrlenW(size_text) + 1;
3201 SendMessageW( control->hwnd, LVM_SETITEMW, 0, (LPARAM)&lvitem );
3203 ptr += lstrlenW(ptr) + 1;
3204 i++;
3207 msi_free( drives );
3210 static UINT msi_dialog_volumecost_list( msi_dialog *dialog, MSIRECORD *rec )
3212 msi_control *control;
3213 DWORD style;
3215 style = LVS_REPORT | WS_VSCROLL | WS_HSCROLL | LVS_SHAREIMAGELISTS |
3216 LVS_AUTOARRANGE | LVS_SINGLESEL | WS_BORDER |
3217 WS_CHILD | WS_TABSTOP | WS_GROUP;
3218 control = msi_dialog_add_control( dialog, rec, WC_LISTVIEWW, style );
3219 if (!control)
3220 return ERROR_FUNCTION_FAILED;
3222 msi_dialog_vcl_add_columns( dialog, control, rec );
3223 msi_dialog_vcl_add_drives( dialog, control );
3225 return ERROR_SUCCESS;
3228 /******************** VolumeSelect Combo ***************************************/
3230 static UINT msi_dialog_volsel_handler( msi_dialog *dialog,
3231 msi_control *control, WPARAM param )
3233 WCHAR text[MAX_PATH];
3234 LPWSTR prop;
3235 BOOL indirect;
3236 int index;
3238 if (HIWORD(param) != CBN_SELCHANGE)
3239 return ERROR_SUCCESS;
3241 index = SendMessageW( control->hwnd, CB_GETCURSEL, 0, 0 );
3242 if ( index == CB_ERR )
3244 ERR("No ComboBox item selected!\n");
3245 return ERROR_FUNCTION_FAILED;
3248 SendMessageW( control->hwnd, CB_GETLBTEXT, index, (LPARAM)text );
3250 indirect = control->attributes & msidbControlAttributesIndirect;
3251 prop = msi_dialog_dup_property( dialog, control->property, indirect );
3253 msi_dialog_set_property( dialog->package, prop, text );
3255 msi_free( prop );
3256 return ERROR_SUCCESS;
3259 static void msi_dialog_vsc_add_drives( msi_dialog *dialog, msi_control *control )
3261 LPWSTR drives, ptr;
3262 DWORD size;
3264 size = GetLogicalDriveStringsW( 0, NULL );
3265 if ( !size ) return;
3267 drives = msi_alloc( (size + 1) * sizeof(WCHAR) );
3268 if ( !drives ) return;
3270 GetLogicalDriveStringsW( size, drives );
3272 ptr = drives;
3273 while (*ptr)
3275 SendMessageW( control->hwnd, CB_ADDSTRING, 0, (LPARAM)ptr );
3276 ptr += lstrlenW(ptr) + 1;
3279 msi_free( drives );
3282 static UINT msi_dialog_volumeselect_combo( msi_dialog *dialog, MSIRECORD *rec )
3284 msi_control *control;
3285 LPCWSTR prop;
3286 DWORD style;
3288 /* FIXME: CBS_OWNERDRAWFIXED */
3289 style = WS_CHILD | WS_VISIBLE | WS_GROUP | WS_TABSTOP |
3290 CBS_DROPDOWNLIST | CBS_SORT | CBS_HASSTRINGS |
3291 WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_RIGHTSCROLLBAR;
3292 control = msi_dialog_add_control( dialog, rec, WC_COMBOBOXW, style );
3293 if (!control)
3294 return ERROR_FUNCTION_FAILED;
3296 control->attributes = MSI_RecordGetInteger( rec, 8 );
3297 control->handler = msi_dialog_volsel_handler;
3298 prop = MSI_RecordGetString( rec, 9 );
3299 control->property = msi_dialog_dup_property( dialog, prop, FALSE );
3301 msi_dialog_vsc_add_drives( dialog, control );
3303 return ERROR_SUCCESS;
3306 static const struct control_handler msi_dialog_handler[] =
3308 { szText, msi_dialog_text_control },
3309 { szPushButton, msi_dialog_button_control },
3310 { szLine, msi_dialog_line_control },
3311 { szBitmap, msi_dialog_bitmap_control },
3312 { szCheckBox, msi_dialog_checkbox_control },
3313 { szScrollableText, msi_dialog_scrolltext_control },
3314 { szComboBox, msi_dialog_combo_control },
3315 { szEdit, msi_dialog_edit_control },
3316 { szMaskedEdit, msi_dialog_maskedit_control },
3317 { szPathEdit, msi_dialog_pathedit_control },
3318 { szProgressBar, msi_dialog_progress_bar },
3319 { szRadioButtonGroup, msi_dialog_radiogroup_control },
3320 { szIcon, msi_dialog_icon_control },
3321 { szSelectionTree, msi_dialog_selection_tree },
3322 { szGroupBox, msi_dialog_group_box },
3323 { szListBox, msi_dialog_list_box },
3324 { szDirectoryCombo, msi_dialog_directory_combo },
3325 { szDirectoryList, msi_dialog_directory_list },
3326 { szVolumeCostList, msi_dialog_volumecost_list },
3327 { szVolumeSelectCombo, msi_dialog_volumeselect_combo },
3330 #define NUM_CONTROL_TYPES (sizeof msi_dialog_handler/sizeof msi_dialog_handler[0])
3332 static UINT msi_dialog_create_controls( MSIRECORD *rec, LPVOID param )
3334 msi_dialog *dialog = param;
3335 LPCWSTR control_type;
3336 UINT i;
3338 /* find and call the function that can create this type of control */
3339 control_type = MSI_RecordGetString( rec, 3 );
3340 for( i=0; i<NUM_CONTROL_TYPES; i++ )
3341 if (!strcmpiW( msi_dialog_handler[i].control_type, control_type ))
3342 break;
3343 if( i != NUM_CONTROL_TYPES )
3344 msi_dialog_handler[i].func( dialog, rec );
3345 else
3346 ERR("no handler for element type %s\n", debugstr_w(control_type));
3348 return ERROR_SUCCESS;
3351 static UINT msi_dialog_fill_controls( msi_dialog *dialog )
3353 static const WCHAR query[] = {
3354 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
3355 'C','o','n','t','r','o','l',' ','W','H','E','R','E',' ',
3356 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',0};
3357 UINT r;
3358 MSIQUERY *view;
3359 MSIPACKAGE *package = dialog->package;
3361 TRACE("%p %s\n", dialog, debugstr_w(dialog->name) );
3363 /* query the Control table for all the elements of the control */
3364 r = MSI_OpenQuery( package->db, &view, query, dialog->name );
3365 if( r != ERROR_SUCCESS )
3367 ERR("query failed for dialog %s\n", debugstr_w(dialog->name));
3368 return ERROR_INVALID_PARAMETER;
3371 r = MSI_IterateRecords( view, 0, msi_dialog_create_controls, dialog );
3372 msiobj_release( &view->hdr );
3373 return r;
3376 UINT msi_dialog_reset( msi_dialog *dialog )
3378 /* FIXME: should restore the original values of any properties we changed */
3379 return msi_dialog_evaluate_control_conditions( dialog );
3382 /* figure out the height of 10 point MS Sans Serif */
3383 static INT msi_dialog_get_sans_serif_height( HWND hwnd )
3385 static const WCHAR szSansSerif[] = {
3386 'M','S',' ','S','a','n','s',' ','S','e','r','i','f',0 };
3387 LOGFONTW lf;
3388 TEXTMETRICW tm;
3389 BOOL r;
3390 LONG height = 0;
3391 HFONT hFont, hOldFont;
3392 HDC hdc;
3394 hdc = GetDC( hwnd );
3395 if (hdc)
3397 memset( &lf, 0, sizeof lf );
3398 lf.lfHeight = MulDiv(12, GetDeviceCaps(hdc, LOGPIXELSY), 72);
3399 strcpyW( lf.lfFaceName, szSansSerif );
3400 hFont = CreateFontIndirectW(&lf);
3401 if (hFont)
3403 hOldFont = SelectObject( hdc, hFont );
3404 r = GetTextMetricsW( hdc, &tm );
3405 if (r)
3406 height = tm.tmHeight;
3407 SelectObject( hdc, hOldFont );
3408 DeleteObject( hFont );
3410 ReleaseDC( hwnd, hdc );
3412 return height;
3415 /* fetch the associated record from the Dialog table */
3416 static MSIRECORD *msi_get_dialog_record( msi_dialog *dialog )
3418 static const WCHAR query[] = {
3419 'S','E','L','E','C','T',' ','*',' ',
3420 'F','R','O','M',' ','D','i','a','l','o','g',' ',
3421 'W','H','E','R','E',' ',
3422 '`','D','i','a','l','o','g','`',' ','=',' ','\'','%','s','\'',0};
3423 MSIPACKAGE *package = dialog->package;
3424 MSIRECORD *rec = NULL;
3426 TRACE("%p %s\n", dialog, debugstr_w(dialog->name) );
3428 rec = MSI_QueryGetRecord( package->db, query, dialog->name );
3429 if( !rec )
3430 WARN("query failed for dialog %s\n", debugstr_w(dialog->name));
3432 return rec;
3435 static void msi_dialog_adjust_dialog_pos( msi_dialog *dialog, MSIRECORD *rec, LPRECT pos )
3437 static const WCHAR szScreenX[] = {'S','c','r','e','e','n','X',0};
3438 static const WCHAR szScreenY[] = {'S','c','r','e','e','n','Y',0};
3440 UINT xres, yres;
3441 POINT center;
3442 SIZE sz;
3443 LONG style;
3445 center.x = MSI_RecordGetInteger( rec, 2 );
3446 center.y = MSI_RecordGetInteger( rec, 3 );
3448 sz.cx = MSI_RecordGetInteger( rec, 4 );
3449 sz.cy = MSI_RecordGetInteger( rec, 5 );
3451 sz.cx = msi_dialog_scale_unit( dialog, sz.cx );
3452 sz.cy = msi_dialog_scale_unit( dialog, sz.cy );
3454 xres = msi_get_property_int( dialog->package->db, szScreenX, 0 );
3455 yres = msi_get_property_int( dialog->package->db, szScreenY, 0 );
3457 center.x = MulDiv( center.x, xres, 100 );
3458 center.y = MulDiv( center.y, yres, 100 );
3460 /* turn the client pos into the window rectangle */
3461 if (dialog->package->center_x && dialog->package->center_y)
3463 pos->left = dialog->package->center_x - sz.cx / 2.0;
3464 pos->right = pos->left + sz.cx;
3465 pos->top = dialog->package->center_y - sz.cy / 2.0;
3466 pos->bottom = pos->top + sz.cy;
3468 else
3470 pos->left = center.x - sz.cx/2;
3471 pos->right = pos->left + sz.cx;
3472 pos->top = center.y - sz.cy/2;
3473 pos->bottom = pos->top + sz.cy;
3475 /* save the center */
3476 dialog->package->center_x = center.x;
3477 dialog->package->center_y = center.y;
3480 dialog->size.cx = sz.cx;
3481 dialog->size.cy = sz.cy;
3483 TRACE("%u %u %u %u\n", pos->left, pos->top, pos->right, pos->bottom);
3485 style = GetWindowLongPtrW( dialog->hwnd, GWL_STYLE );
3486 AdjustWindowRect( pos, style, FALSE );
3489 static void msi_dialog_set_tab_order( msi_dialog *dialog, LPCWSTR first )
3491 struct list tab_chain;
3492 msi_control *control;
3493 HWND prev = HWND_TOP;
3495 list_init( &tab_chain );
3496 if (!(control = msi_dialog_find_control( dialog, first ))) return;
3498 dialog->hWndFocus = control->hwnd;
3499 while (control)
3501 list_remove( &control->entry );
3502 list_add_tail( &tab_chain, &control->entry );
3503 if (!control->tabnext) break;
3504 control = msi_dialog_find_control( dialog, control->tabnext );
3507 LIST_FOR_EACH_ENTRY( control, &tab_chain, msi_control, entry )
3509 SetWindowPos( control->hwnd, prev, 0, 0, 0, 0,
3510 SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOREDRAW |
3511 SWP_NOREPOSITION | SWP_NOSENDCHANGING | SWP_NOSIZE );
3512 prev = control->hwnd;
3515 /* put them back on the main list */
3516 list_move_head( &dialog->controls, &tab_chain );
3519 static LRESULT msi_dialog_oncreate( HWND hwnd, LPCREATESTRUCTW cs )
3521 static const WCHAR df[] = {
3522 'D','e','f','a','u','l','t','U','I','F','o','n','t',0 };
3523 static const WCHAR dfv[] = {
3524 'M','S',' ','S','h','e','l','l',' ','D','l','g',0 };
3525 msi_dialog *dialog = cs->lpCreateParams;
3526 MSIRECORD *rec = NULL;
3527 LPWSTR title = NULL;
3528 RECT pos;
3530 TRACE("%p %p\n", dialog, dialog->package);
3532 dialog->hwnd = hwnd;
3533 SetWindowLongPtrW( hwnd, GWLP_USERDATA, (LONG_PTR) dialog );
3535 rec = msi_get_dialog_record( dialog );
3536 if( !rec )
3538 TRACE("No record found for dialog %s\n", debugstr_w(dialog->name));
3539 return -1;
3542 dialog->scale = msi_dialog_get_sans_serif_height(dialog->hwnd);
3544 msi_dialog_adjust_dialog_pos( dialog, rec, &pos );
3546 dialog->attributes = MSI_RecordGetInteger( rec, 6 );
3548 dialog->default_font = msi_dup_property( dialog->package->db, df );
3549 if (!dialog->default_font)
3551 dialog->default_font = strdupW(dfv);
3552 if (!dialog->default_font) return -1;
3555 title = msi_get_deformatted_field( dialog->package, rec, 7 );
3556 SetWindowTextW( hwnd, title );
3557 msi_free( title );
3559 SetWindowPos( hwnd, 0, pos.left, pos.top,
3560 pos.right - pos.left, pos.bottom - pos.top,
3561 SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOREDRAW );
3563 msi_dialog_build_font_list( dialog );
3564 msi_dialog_fill_controls( dialog );
3565 msi_dialog_evaluate_control_conditions( dialog );
3566 msi_dialog_set_tab_order( dialog, MSI_RecordGetString( rec, 8 ) );
3567 msiobj_release( &rec->hdr );
3569 return 0;
3572 static LRESULT msi_dialog_oncommand( msi_dialog *dialog, WPARAM param, HWND hwnd )
3574 msi_control *control = NULL;
3576 TRACE("%p %p %08lx\n", dialog, hwnd, param);
3578 switch (param)
3580 case 1: /* enter */
3581 control = msi_dialog_find_control( dialog, dialog->control_default );
3582 break;
3583 case 2: /* escape */
3584 control = msi_dialog_find_control( dialog, dialog->control_cancel );
3585 break;
3586 default:
3587 control = msi_dialog_find_control_by_hwnd( dialog, hwnd );
3590 if( control )
3592 if( control->handler )
3594 control->handler( dialog, control, param );
3595 msi_dialog_evaluate_control_conditions( dialog );
3599 return 0;
3602 static LRESULT msi_dialog_onnotify( msi_dialog *dialog, LPARAM param )
3604 LPNMHDR nmhdr = (LPNMHDR) param;
3605 msi_control *control = msi_dialog_find_control_by_hwnd( dialog, nmhdr->hwndFrom );
3607 TRACE("%p %p\n", dialog, nmhdr->hwndFrom);
3609 if ( control && control->handler )
3610 control->handler( dialog, control, param );
3612 return 0;
3615 static void msi_dialog_setfocus( msi_dialog *dialog )
3617 HWND hwnd = dialog->hWndFocus;
3619 hwnd = GetNextDlgTabItem( dialog->hwnd, hwnd, TRUE);
3620 hwnd = GetNextDlgTabItem( dialog->hwnd, hwnd, FALSE);
3621 SetFocus( hwnd );
3622 dialog->hWndFocus = hwnd;
3625 static LRESULT WINAPI MSIDialog_WndProc( HWND hwnd, UINT msg,
3626 WPARAM wParam, LPARAM lParam )
3628 msi_dialog *dialog = (LPVOID) GetWindowLongPtrW( hwnd, GWLP_USERDATA );
3630 TRACE("0x%04x\n", msg);
3632 switch (msg)
3634 case WM_MOVE:
3635 dialog->package->center_x = LOWORD(lParam) + dialog->size.cx / 2.0;
3636 dialog->package->center_y = HIWORD(lParam) + dialog->size.cy / 2.0;
3637 break;
3639 case WM_CREATE:
3640 return msi_dialog_oncreate( hwnd, (LPCREATESTRUCTW)lParam );
3642 case WM_COMMAND:
3643 return msi_dialog_oncommand( dialog, wParam, (HWND)lParam );
3645 case WM_ACTIVATE:
3646 if( LOWORD(wParam) == WA_INACTIVE )
3647 dialog->hWndFocus = GetFocus();
3648 else
3649 msi_dialog_setfocus( dialog );
3650 return 0;
3652 case WM_SETFOCUS:
3653 msi_dialog_setfocus( dialog );
3654 return 0;
3656 /* bounce back to our subclassed static control */
3657 case WM_CTLCOLORSTATIC:
3658 return SendMessageW( (HWND) lParam, WM_CTLCOLORSTATIC, wParam, lParam );
3660 case WM_DESTROY:
3661 dialog->hwnd = NULL;
3662 return 0;
3663 case WM_NOTIFY:
3664 return msi_dialog_onnotify( dialog, lParam );
3666 return DefWindowProcW(hwnd, msg, wParam, lParam);
3669 static LRESULT WINAPI MSIHiddenWindowProc( HWND hwnd, UINT msg,
3670 WPARAM wParam, LPARAM lParam )
3672 msi_dialog *dialog = (msi_dialog*) lParam;
3674 TRACE("%d %p\n", msg, dialog);
3676 switch (msg)
3678 case WM_MSI_DIALOG_CREATE:
3679 return msi_dialog_run_message_loop( dialog );
3680 case WM_MSI_DIALOG_DESTROY:
3681 msi_dialog_destroy( dialog );
3682 return 0;
3684 return DefWindowProcW( hwnd, msg, wParam, lParam );
3687 static BOOL msi_dialog_register_class( void )
3689 WNDCLASSW cls;
3691 ZeroMemory( &cls, sizeof cls );
3692 cls.lpfnWndProc = MSIDialog_WndProc;
3693 cls.hInstance = NULL;
3694 cls.hIcon = LoadIconW(0, (LPWSTR)IDI_APPLICATION);
3695 cls.hCursor = LoadCursorW(0, (LPWSTR)IDC_ARROW);
3696 cls.hbrBackground = (HBRUSH)(COLOR_3DFACE + 1);
3697 cls.lpszMenuName = NULL;
3698 cls.lpszClassName = szMsiDialogClass;
3700 if( !RegisterClassW( &cls ) )
3701 return FALSE;
3703 cls.lpfnWndProc = MSIHiddenWindowProc;
3704 cls.lpszClassName = szMsiHiddenWindow;
3706 if( !RegisterClassW( &cls ) )
3707 return FALSE;
3709 uiThreadId = GetCurrentThreadId();
3711 hMsiHiddenWindow = CreateWindowW( szMsiHiddenWindow, NULL, WS_OVERLAPPED,
3712 0, 0, 100, 100, NULL, NULL, NULL, NULL );
3713 if( !hMsiHiddenWindow )
3714 return FALSE;
3716 return TRUE;
3719 /* functions that interface to other modules within MSI */
3721 msi_dialog *msi_dialog_create( MSIPACKAGE* package,
3722 LPCWSTR szDialogName, msi_dialog *parent,
3723 msi_dialog_event_handler event_handler )
3725 MSIRECORD *rec = NULL;
3726 msi_dialog *dialog;
3728 TRACE("%p %s\n", package, debugstr_w(szDialogName));
3730 if (!hMsiHiddenWindow)
3731 msi_dialog_register_class();
3733 /* allocate the structure for the dialog to use */
3734 dialog = msi_alloc_zero( sizeof *dialog + sizeof(WCHAR)*strlenW(szDialogName) );
3735 if( !dialog )
3736 return NULL;
3737 strcpyW( dialog->name, szDialogName );
3738 dialog->parent = parent;
3739 msiobj_addref( &package->hdr );
3740 dialog->package = package;
3741 dialog->event_handler = event_handler;
3742 dialog->finished = 0;
3743 list_init( &dialog->controls );
3744 list_init( &dialog->fonts );
3746 /* verify that the dialog exists */
3747 rec = msi_get_dialog_record( dialog );
3748 if( !rec )
3750 msiobj_release( &package->hdr );
3751 msi_free( dialog );
3752 return NULL;
3754 dialog->attributes = MSI_RecordGetInteger( rec, 6 );
3755 dialog->control_default = strdupW( MSI_RecordGetString( rec, 9 ) );
3756 dialog->control_cancel = strdupW( MSI_RecordGetString( rec, 10 ) );
3757 msiobj_release( &rec->hdr );
3759 return dialog;
3762 static void msi_process_pending_messages( HWND hdlg )
3764 MSG msg;
3766 while( PeekMessageW( &msg, 0, 0, 0, PM_REMOVE ) )
3768 if( hdlg && IsDialogMessageW( hdlg, &msg ))
3769 continue;
3770 TranslateMessage( &msg );
3771 DispatchMessageW( &msg );
3775 void msi_dialog_end_dialog( msi_dialog *dialog )
3777 TRACE("%p\n", dialog);
3778 dialog->finished = 1;
3779 PostMessageW(dialog->hwnd, WM_NULL, 0, 0);
3782 void msi_dialog_check_messages( HANDLE handle )
3784 DWORD r;
3786 /* in threads other than the UI thread, block */
3787 if( uiThreadId != GetCurrentThreadId() )
3789 if( handle )
3790 WaitForSingleObject( handle, INFINITE );
3791 return;
3794 /* there's two choices for the UI thread */
3795 while (1)
3797 msi_process_pending_messages( NULL );
3799 if( !handle )
3800 break;
3803 * block here until somebody creates a new dialog or
3804 * the handle we're waiting on becomes ready
3806 r = MsgWaitForMultipleObjects( 1, &handle, 0, INFINITE, QS_ALLINPUT );
3807 if( r == WAIT_OBJECT_0 )
3808 break;
3812 UINT msi_dialog_run_message_loop( msi_dialog *dialog )
3814 DWORD style;
3815 HWND hwnd;
3817 if( uiThreadId != GetCurrentThreadId() )
3818 return SendMessageW( hMsiHiddenWindow, WM_MSI_DIALOG_CREATE, 0, (LPARAM) dialog );
3820 /* create the dialog window, don't show it yet */
3821 style = WS_OVERLAPPED;
3822 if( dialog->attributes & msidbDialogAttributesVisible )
3823 style |= WS_VISIBLE;
3825 hwnd = CreateWindowW( szMsiDialogClass, dialog->name, style,
3826 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
3827 NULL, NULL, NULL, dialog );
3828 if( !hwnd )
3830 ERR("Failed to create dialog %s\n", debugstr_w( dialog->name ));
3831 return ERROR_FUNCTION_FAILED;
3834 ShowWindow( hwnd, SW_SHOW );
3835 /* UpdateWindow( hwnd ); - and causes the transparent static controls not to paint */
3837 if( dialog->attributes & msidbDialogAttributesModal )
3839 while( !dialog->finished )
3841 MsgWaitForMultipleObjects( 0, NULL, 0, INFINITE, QS_ALLINPUT );
3842 msi_process_pending_messages( dialog->hwnd );
3845 else
3846 return ERROR_IO_PENDING;
3848 return ERROR_SUCCESS;
3851 static void msi_dialog_do_preview( msi_dialog *dialog )
3853 TRACE("\n");
3854 dialog->attributes |= msidbDialogAttributesVisible;
3855 dialog->attributes &= ~msidbDialogAttributesModal;
3856 msi_dialog_run_message_loop( dialog );
3859 void msi_dialog_destroy( msi_dialog *dialog )
3861 msi_font *font, *next;
3863 if( uiThreadId != GetCurrentThreadId() )
3865 SendMessageW( hMsiHiddenWindow, WM_MSI_DIALOG_DESTROY, 0, (LPARAM) dialog );
3866 return;
3869 if( dialog->hwnd )
3870 ShowWindow( dialog->hwnd, SW_HIDE );
3872 if( dialog->hwnd )
3873 DestroyWindow( dialog->hwnd );
3875 /* unsubscribe events */
3876 ControlEvent_CleanupDialogSubscriptions(dialog->package, dialog->name);
3878 /* destroy the list of controls */
3879 while( !list_empty( &dialog->controls ) )
3881 msi_control *t;
3883 t = LIST_ENTRY( list_head( &dialog->controls ),
3884 msi_control, entry );
3885 msi_destroy_control( t );
3888 /* destroy the list of fonts */
3889 LIST_FOR_EACH_ENTRY_SAFE( font, next, &dialog->fonts, msi_font, entry )
3891 list_remove( &font->entry );
3892 DeleteObject( font->hfont );
3893 msi_free( font );
3895 msi_free( dialog->default_font );
3897 msi_free( dialog->control_default );
3898 msi_free( dialog->control_cancel );
3899 msiobj_release( &dialog->package->hdr );
3900 dialog->package = NULL;
3901 msi_free( dialog );
3904 void msi_dialog_unregister_class( void )
3906 DestroyWindow( hMsiHiddenWindow );
3907 hMsiHiddenWindow = NULL;
3908 UnregisterClassW( szMsiDialogClass, NULL );
3909 UnregisterClassW( szMsiHiddenWindow, NULL );
3910 uiThreadId = 0;
3913 static UINT error_dialog_handler(MSIPACKAGE *package, LPCWSTR event,
3914 LPCWSTR argument, msi_dialog* dialog)
3916 static const WCHAR end_dialog[] = {'E','n','d','D','i','a','l','o','g',0};
3917 static const WCHAR error_abort[] = {'E','r','r','o','r','A','b','o','r','t',0};
3918 static const WCHAR error_cancel[] = {'E','r','r','o','r','C','a','n','c','e','l',0};
3919 static const WCHAR error_no[] = {'E','r','r','o','r','N','o',0};
3920 static const WCHAR result_prop[] = {
3921 'M','S','I','E','r','r','o','r','D','i','a','l','o','g','R','e','s','u','l','t',0
3924 if ( strcmpW( event, end_dialog ) )
3925 return ERROR_SUCCESS;
3927 if ( !strcmpW( argument, error_abort ) || !strcmpW( argument, error_cancel ) ||
3928 !strcmpW( argument, error_no ) )
3930 msi_set_property( package->db, result_prop, error_abort );
3933 ControlEvent_CleanupSubscriptions(package);
3934 msi_dialog_end_dialog( dialog );
3936 return ERROR_SUCCESS;
3939 static UINT msi_error_dialog_set_error( MSIPACKAGE *package, LPWSTR error_dialog, LPWSTR error )
3941 MSIRECORD * row;
3943 static const WCHAR update[] =
3944 {'U','P','D','A','T','E',' ','`','C','o','n','t','r','o','l','`',' ',
3945 'S','E','T',' ','`','T','e','x','t','`',' ','=',' ','\'','%','s','\'',' ',
3946 'W','H','E','R','E', ' ','`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',' ',
3947 'A','N','D',' ','`','C','o','n','t','r','o','l','`',' ','=',' ',
3948 '\'','E','r','r','o','r','T','e','x','t','\'',0};
3950 row = MSI_QueryGetRecord( package->db, update, error, error_dialog );
3951 if (!row)
3952 return ERROR_FUNCTION_FAILED;
3954 msiobj_release(&row->hdr);
3955 return ERROR_SUCCESS;
3958 UINT msi_spawn_error_dialog( MSIPACKAGE *package, LPWSTR error_dialog, LPWSTR error )
3960 msi_dialog *dialog;
3961 WCHAR result[MAX_PATH];
3962 UINT r = ERROR_SUCCESS;
3963 DWORD size = MAX_PATH;
3964 int res;
3966 static const WCHAR pn_prop[] = {'P','r','o','d','u','c','t','N','a','m','e',0};
3967 static const WCHAR title_fmt[] = {'%','s',' ','W','a','r','n','i','n','g',0};
3968 static const WCHAR error_abort[] = {'E','r','r','o','r','A','b','o','r','t',0};
3969 static const WCHAR result_prop[] = {
3970 'M','S','I','E','r','r','o','r','D','i','a','l','o','g','R','e','s','u','l','t',0
3973 if ( (msi_get_property_int( package->db, szUILevel, 0 ) & INSTALLUILEVEL_MASK) == INSTALLUILEVEL_NONE )
3974 return ERROR_SUCCESS;
3976 if ( !error_dialog )
3978 LPWSTR product_name = msi_dup_property( package->db, pn_prop );
3979 WCHAR title[MAX_PATH];
3981 sprintfW( title, title_fmt, product_name );
3982 res = MessageBoxW( NULL, error, title, MB_OKCANCEL | MB_ICONWARNING );
3984 msi_free( product_name );
3986 if ( res == IDOK )
3987 return ERROR_SUCCESS;
3988 else
3989 return ERROR_FUNCTION_FAILED;
3992 r = msi_error_dialog_set_error( package, error_dialog, error );
3993 if ( r != ERROR_SUCCESS )
3994 return r;
3996 dialog = msi_dialog_create( package, error_dialog, package->dialog,
3997 error_dialog_handler );
3998 if ( !dialog )
3999 return ERROR_FUNCTION_FAILED;
4001 dialog->finished = FALSE;
4002 r = msi_dialog_run_message_loop( dialog );
4003 if ( r != ERROR_SUCCESS )
4004 goto done;
4006 r = msi_get_property( package->db, result_prop, result, &size );
4007 if ( r != ERROR_SUCCESS)
4008 r = ERROR_SUCCESS;
4010 if ( !strcmpW( result, error_abort ) )
4011 r = ERROR_FUNCTION_FAILED;
4013 done:
4014 msi_dialog_destroy( dialog );
4016 return r;
4019 static void MSI_ClosePreview( MSIOBJECTHDR *arg )
4021 MSIPREVIEW *preview = (MSIPREVIEW *)arg;
4022 msiobj_release( &preview->package->hdr );
4025 static MSIPREVIEW *MSI_EnableUIPreview( MSIDATABASE *db )
4027 MSIPREVIEW *preview = NULL;
4028 MSIPACKAGE *package;
4030 package = MSI_CreatePackage( db, NULL );
4031 if (package)
4033 preview = alloc_msiobject( MSIHANDLETYPE_PREVIEW, sizeof(MSIPREVIEW), MSI_ClosePreview );
4034 if (preview)
4036 preview->package = package;
4037 msiobj_addref( &package->hdr );
4039 msiobj_release( &package->hdr );
4041 return preview;
4044 UINT WINAPI MsiEnableUIPreview( MSIHANDLE hdb, MSIHANDLE *phPreview )
4046 MSIDATABASE *db;
4047 MSIPREVIEW *preview;
4048 UINT r = ERROR_FUNCTION_FAILED;
4050 TRACE("%d %p\n", hdb, phPreview);
4052 db = msihandle2msiinfo( hdb, MSIHANDLETYPE_DATABASE );
4053 if (!db)
4055 IWineMsiRemoteDatabase *remote_database;
4057 remote_database = (IWineMsiRemoteDatabase *)msi_get_remote( hdb );
4058 if (!remote_database)
4059 return ERROR_INVALID_HANDLE;
4061 *phPreview = 0;
4063 IWineMsiRemoteDatabase_Release( remote_database );
4064 WARN("MsiEnableUIPreview not allowed during a custom action!\n");
4066 return ERROR_FUNCTION_FAILED;
4068 preview = MSI_EnableUIPreview( db );
4069 if (preview)
4071 *phPreview = alloc_msihandle( &preview->hdr );
4072 msiobj_release( &preview->hdr );
4073 r = ERROR_SUCCESS;
4074 if (!*phPreview)
4075 r = ERROR_NOT_ENOUGH_MEMORY;
4077 msiobj_release( &db->hdr );
4078 return r;
4081 static UINT preview_event_handler( MSIPACKAGE *package, LPCWSTR event,
4082 LPCWSTR argument, msi_dialog *dialog )
4084 MESSAGE("Preview dialog event '%s' (arg='%s')\n", debugstr_w(event), debugstr_w(argument));
4085 return ERROR_SUCCESS;
4088 static UINT MSI_PreviewDialogW( MSIPREVIEW *preview, LPCWSTR szDialogName )
4090 msi_dialog *dialog = NULL;
4091 UINT r = ERROR_SUCCESS;
4093 if (preview->dialog)
4094 msi_dialog_destroy( preview->dialog );
4096 /* an empty name means we should just destroy the current preview dialog */
4097 if (szDialogName)
4099 dialog = msi_dialog_create( preview->package, szDialogName, NULL, preview_event_handler );
4100 if (dialog)
4101 msi_dialog_do_preview( dialog );
4102 else
4103 r = ERROR_FUNCTION_FAILED;
4105 preview->dialog = dialog;
4106 return r;
4109 UINT WINAPI MsiPreviewDialogW( MSIHANDLE hPreview, LPCWSTR szDialogName )
4111 MSIPREVIEW *preview;
4112 UINT r;
4114 TRACE("%d %s\n", hPreview, debugstr_w(szDialogName));
4116 preview = msihandle2msiinfo( hPreview, MSIHANDLETYPE_PREVIEW );
4117 if (!preview)
4118 return ERROR_INVALID_HANDLE;
4120 r = MSI_PreviewDialogW( preview, szDialogName );
4121 msiobj_release( &preview->hdr );
4122 return r;
4125 UINT WINAPI MsiPreviewDialogA( MSIHANDLE hPreview, LPCSTR szDialogName )
4127 UINT r;
4128 LPWSTR strW = NULL;
4130 TRACE("%d %s\n", hPreview, debugstr_a(szDialogName));
4132 if (szDialogName)
4134 strW = strdupAtoW( szDialogName );
4135 if (!strW)
4136 return ERROR_OUTOFMEMORY;
4138 r = MsiPreviewDialogW( hPreview, strW );
4139 msi_free( strW );
4140 return r;
4143 UINT WINAPI MsiPreviewBillboardW( MSIHANDLE hPreview, LPCWSTR szControlName, LPCWSTR szBillboard )
4145 FIXME("%d %s %s\n", hPreview, debugstr_w(szControlName), debugstr_w(szBillboard));
4146 return ERROR_CALL_NOT_IMPLEMENTED;
4149 UINT WINAPI MsiPreviewBillboardA( MSIHANDLE hPreview, LPCSTR szControlName, LPCSTR szBillboard )
4151 FIXME("%d %s %s\n", hPreview, debugstr_a(szControlName), debugstr_a(szBillboard));
4152 return ERROR_CALL_NOT_IMPLEMENTED;