77ebc5b6c127501813a460359705631aa5c9217e
[reactos.git] / reactos / dll / win32 / msi / dialog.c
1 /*
2 * Implementation of the Microsoft Installer (msi.dll)
3 *
4 * Copyright 2005 Mike McCormack for CodeWeavers
5 * Copyright 2005 Aric Stewart for CodeWeavers
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 */
21
22 #include "msipriv.h"
23
24 #include <olectl.h>
25 #include <richedit.h>
26 #include <shellapi.h>
27
28 WINE_DEFAULT_DEBUG_CHANNEL(msi);
29
30 extern HINSTANCE msi_hInstance;
31
32 struct msi_control_tag;
33 typedef struct msi_control_tag msi_control;
34 typedef UINT (*msi_handler)( msi_dialog *, msi_control *, WPARAM );
35 typedef void (*msi_update)( msi_dialog *, msi_control * );
36 typedef UINT (*control_event_handler)( msi_dialog *, const WCHAR *, const WCHAR * );
37
38 struct msi_control_tag
39 {
40 struct list entry;
41 HWND hwnd;
42 msi_handler handler;
43 msi_update update;
44 LPWSTR property;
45 LPWSTR value;
46 HBITMAP hBitmap;
47 HICON hIcon;
48 LPWSTR tabnext;
49 LPWSTR type;
50 HMODULE hDll;
51 float progress_current;
52 float progress_max;
53 BOOL progress_backwards;
54 DWORD attributes;
55 WCHAR name[1];
56 };
57
58 typedef struct msi_font_tag
59 {
60 struct list entry;
61 HFONT hfont;
62 COLORREF color;
63 WCHAR name[1];
64 } msi_font;
65
66 struct msi_dialog_tag
67 {
68 MSIPACKAGE *package;
69 msi_dialog *parent;
70 control_event_handler event_handler;
71 BOOL finished;
72 INT scale;
73 DWORD attributes;
74 SIZE size;
75 HWND hwnd;
76 LPWSTR default_font;
77 struct list fonts;
78 struct list controls;
79 HWND hWndFocus;
80 LPWSTR control_default;
81 LPWSTR control_cancel;
82 WCHAR name[1];
83 };
84
85 struct subscriber
86 {
87 struct list entry;
88 msi_dialog *dialog;
89 WCHAR *event;
90 WCHAR *control;
91 WCHAR *attribute;
92 };
93
94 typedef UINT (*msi_dialog_control_func)( msi_dialog *dialog, MSIRECORD *rec );
95 struct control_handler
96 {
97 LPCWSTR control_type;
98 msi_dialog_control_func func;
99 };
100
101 typedef struct
102 {
103 msi_dialog* dialog;
104 msi_control *parent;
105 LPWSTR propval;
106 } radio_button_group_descr;
107
108 static const WCHAR szMsiDialogClass[] = { 'M','s','i','D','i','a','l','o','g','C','l','o','s','e','C','l','a','s','s',0 };
109 static const WCHAR szMsiHiddenWindow[] = { 'M','s','i','H','i','d','d','e','n','W','i','n','d','o','w',0 };
110 static const WCHAR szStatic[] = { 'S','t','a','t','i','c',0 };
111 static const WCHAR szButton[] = { 'B','U','T','T','O','N', 0 };
112 static const WCHAR szButtonData[] = { 'M','S','I','D','A','T','A',0 };
113 static const WCHAR szProgress[] = { 'P','r','o','g','r','e','s','s',0 };
114 static const WCHAR szText[] = { 'T','e','x','t',0 };
115 static const WCHAR szPushButton[] = { 'P','u','s','h','B','u','t','t','o','n',0 };
116 static const WCHAR szLine[] = { 'L','i','n','e',0 };
117 static const WCHAR szBitmap[] = { 'B','i','t','m','a','p',0 };
118 static const WCHAR szCheckBox[] = { 'C','h','e','c','k','B','o','x',0 };
119 static const WCHAR szScrollableText[] = { 'S','c','r','o','l','l','a','b','l','e','T','e','x','t',0 };
120 static const WCHAR szComboBox[] = { 'C','o','m','b','o','B','o','x',0 };
121 static const WCHAR szEdit[] = { 'E','d','i','t',0 };
122 static const WCHAR szMaskedEdit[] = { 'M','a','s','k','e','d','E','d','i','t',0 };
123 static const WCHAR szPathEdit[] = { 'P','a','t','h','E','d','i','t',0 };
124 static const WCHAR szProgressBar[] = { 'P','r','o','g','r','e','s','s','B','a','r',0 };
125 static const WCHAR szSetProgress[] = { 'S','e','t','P','r','o','g','r','e','s','s',0 };
126 static const WCHAR szRadioButtonGroup[] = { 'R','a','d','i','o','B','u','t','t','o','n','G','r','o','u','p',0 };
127 static const WCHAR szIcon[] = { 'I','c','o','n',0 };
128 static const WCHAR szSelectionTree[] = { 'S','e','l','e','c','t','i','o','n','T','r','e','e',0 };
129 static const WCHAR szGroupBox[] = { 'G','r','o','u','p','B','o','x',0 };
130 static const WCHAR szListBox[] = { 'L','i','s','t','B','o','x',0 };
131 static const WCHAR szDirectoryCombo[] = { 'D','i','r','e','c','t','o','r','y','C','o','m','b','o',0 };
132 static const WCHAR szDirectoryList[] = { 'D','i','r','e','c','t','o','r','y','L','i','s','t',0 };
133 static const WCHAR szVolumeCostList[] = { 'V','o','l','u','m','e','C','o','s','t','L','i','s','t',0 };
134 static const WCHAR szVolumeSelectCombo[] = { 'V','o','l','u','m','e','S','e','l','e','c','t','C','o','m','b','o',0 };
135 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};
136 static const WCHAR szSelectionPath[] = {'S','e','l','e','c','t','i','o','n','P','a','t','h',0};
137 static const WCHAR szHyperLink[] = {'H','y','p','e','r','L','i','n','k',0};
138
139 /* dialog sequencing */
140
141 #define WM_MSI_DIALOG_CREATE (WM_USER+0x100)
142 #define WM_MSI_DIALOG_DESTROY (WM_USER+0x101)
143
144 #define USER_INSTALLSTATE_ALL 0x1000
145
146 static DWORD uiThreadId;
147 static HWND hMsiHiddenWindow;
148
149 static LPWSTR msi_get_window_text( HWND hwnd )
150 {
151 UINT sz, r;
152 LPWSTR buf;
153
154 sz = 0x20;
155 buf = msi_alloc( sz*sizeof(WCHAR) );
156 while ( buf )
157 {
158 r = GetWindowTextW( hwnd, buf, sz );
159 if ( r < (sz - 1) )
160 break;
161 sz *= 2;
162 buf = msi_realloc( buf, sz*sizeof(WCHAR) );
163 }
164
165 return buf;
166 }
167
168 static INT msi_dialog_scale_unit( msi_dialog *dialog, INT val )
169 {
170 return MulDiv( val, dialog->scale, 12 );
171 }
172
173 static msi_control *msi_dialog_find_control( msi_dialog *dialog, LPCWSTR name )
174 {
175 msi_control *control;
176
177 if( !name )
178 return NULL;
179 if( !dialog->hwnd )
180 return NULL;
181 LIST_FOR_EACH_ENTRY( control, &dialog->controls, msi_control, entry )
182 if( !strcmpW( control->name, name ) ) /* FIXME: case sensitive? */
183 return control;
184 return NULL;
185 }
186
187 static msi_control *msi_dialog_find_control_by_type( msi_dialog *dialog, LPCWSTR type )
188 {
189 msi_control *control;
190
191 if( !type )
192 return NULL;
193 if( !dialog->hwnd )
194 return NULL;
195 LIST_FOR_EACH_ENTRY( control, &dialog->controls, msi_control, entry )
196 if( !strcmpW( control->type, type ) ) /* FIXME: case sensitive? */
197 return control;
198 return NULL;
199 }
200
201 static msi_control *msi_dialog_find_control_by_hwnd( msi_dialog *dialog, HWND hwnd )
202 {
203 msi_control *control;
204
205 if( !dialog->hwnd )
206 return NULL;
207 LIST_FOR_EACH_ENTRY( control, &dialog->controls, msi_control, entry )
208 if( hwnd == control->hwnd )
209 return control;
210 return NULL;
211 }
212
213 static LPWSTR msi_get_deformatted_field( MSIPACKAGE *package, MSIRECORD *rec, int field )
214 {
215 LPCWSTR str = MSI_RecordGetString( rec, field );
216 LPWSTR ret = NULL;
217
218 if (str)
219 deformat_string( package, str, &ret );
220 return ret;
221 }
222
223 static LPWSTR msi_dialog_dup_property( msi_dialog *dialog, LPCWSTR property, BOOL indirect )
224 {
225 LPWSTR prop = NULL;
226
227 if (!property)
228 return NULL;
229
230 if (indirect)
231 prop = msi_dup_property( dialog->package->db, property );
232
233 if (!prop)
234 prop = strdupW( property );
235
236 return prop;
237 }
238
239 /*
240 * msi_dialog_get_style
241 *
242 * Extract the {\style} string from the front of the text to display and
243 * update the pointer. Only the last style in a list is applied.
244 */
245 static LPWSTR msi_dialog_get_style( LPCWSTR p, LPCWSTR *rest )
246 {
247 LPWSTR ret;
248 LPCWSTR q, i, first;
249 DWORD len;
250
251 q = NULL;
252 *rest = p;
253 if( !p )
254 return NULL;
255
256 while ((first = strchrW( p, '{' )) && (q = strchrW( first + 1, '}' )))
257 {
258 p = first + 1;
259 if( *p != '\\' && *p != '&' )
260 return NULL;
261
262 /* little bit of sanity checking to stop us getting confused with RTF */
263 for( i=++p; i<q; i++ )
264 if( *i == '}' || *i == '\\' )
265 return NULL;
266 }
267
268 if (!q)
269 return NULL;
270
271 *rest = ++q;
272 len = q - p;
273
274 ret = msi_alloc( len*sizeof(WCHAR) );
275 if( !ret )
276 return ret;
277 memcpy( ret, p, len*sizeof(WCHAR) );
278 ret[len-1] = 0;
279 return ret;
280 }
281
282 static UINT msi_dialog_add_font( MSIRECORD *rec, LPVOID param )
283 {
284 msi_dialog *dialog = param;
285 msi_font *font;
286 LPCWSTR face, name;
287 LOGFONTW lf;
288 INT style;
289 HDC hdc;
290
291 /* create a font and add it to the list */
292 name = MSI_RecordGetString( rec, 1 );
293 font = msi_alloc( FIELD_OFFSET( msi_font, name[strlenW( name ) + 1] ));
294 strcpyW( font->name, name );
295 list_add_head( &dialog->fonts, &font->entry );
296
297 font->color = MSI_RecordGetInteger( rec, 4 );
298
299 memset( &lf, 0, sizeof lf );
300 face = MSI_RecordGetString( rec, 2 );
301 lf.lfHeight = MSI_RecordGetInteger( rec, 3 );
302 style = MSI_RecordGetInteger( rec, 5 );
303 if( style & msidbTextStyleStyleBitsBold )
304 lf.lfWeight = FW_BOLD;
305 if( style & msidbTextStyleStyleBitsItalic )
306 lf.lfItalic = TRUE;
307 if( style & msidbTextStyleStyleBitsUnderline )
308 lf.lfUnderline = TRUE;
309 if( style & msidbTextStyleStyleBitsStrike )
310 lf.lfStrikeOut = TRUE;
311 lstrcpynW( lf.lfFaceName, face, LF_FACESIZE );
312
313 /* adjust the height */
314 hdc = GetDC( dialog->hwnd );
315 if (hdc)
316 {
317 lf.lfHeight = -MulDiv(lf.lfHeight, GetDeviceCaps(hdc, LOGPIXELSY), 72);
318 ReleaseDC( dialog->hwnd, hdc );
319 }
320
321 font->hfont = CreateFontIndirectW( &lf );
322
323 TRACE("Adding font style %s\n", debugstr_w(font->name) );
324
325 return ERROR_SUCCESS;
326 }
327
328 static msi_font *msi_dialog_find_font( msi_dialog *dialog, LPCWSTR name )
329 {
330 msi_font *font = NULL;
331
332 LIST_FOR_EACH_ENTRY( font, &dialog->fonts, msi_font, entry )
333 if( !strcmpW( font->name, name ) ) /* FIXME: case sensitive? */
334 break;
335
336 return font;
337 }
338
339 static UINT msi_dialog_set_font( msi_dialog *dialog, HWND hwnd, LPCWSTR name )
340 {
341 msi_font *font;
342
343 font = msi_dialog_find_font( dialog, name );
344 if( font )
345 SendMessageW( hwnd, WM_SETFONT, (WPARAM) font->hfont, TRUE );
346 else
347 ERR("No font entry for %s\n", debugstr_w(name));
348 return ERROR_SUCCESS;
349 }
350
351 static UINT msi_dialog_build_font_list( msi_dialog *dialog )
352 {
353 static const WCHAR query[] = {
354 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
355 '`','T','e','x','t','S','t','y','l','e','`',0};
356 MSIQUERY *view;
357 UINT r;
358
359 TRACE("dialog %p\n", dialog );
360
361 r = MSI_OpenQuery( dialog->package->db, &view, query );
362 if( r != ERROR_SUCCESS )
363 return r;
364
365 r = MSI_IterateRecords( view, NULL, msi_dialog_add_font, dialog );
366 msiobj_release( &view->hdr );
367 return r;
368 }
369
370 static void msi_destroy_control( msi_control *t )
371 {
372 list_remove( &t->entry );
373 /* leave dialog->hwnd - destroying parent destroys child windows */
374 msi_free( t->property );
375 msi_free( t->value );
376 if( t->hBitmap )
377 DeleteObject( t->hBitmap );
378 if( t->hIcon )
379 DestroyIcon( t->hIcon );
380 msi_free( t->tabnext );
381 msi_free( t->type );
382 if (t->hDll)
383 FreeLibrary( t->hDll );
384 msi_free( t );
385 }
386
387 static msi_control *dialog_create_window( msi_dialog *dialog, MSIRECORD *rec, DWORD exstyle,
388 const WCHAR *szCls, const WCHAR *name, const WCHAR *text,
389 DWORD style, HWND parent )
390 {
391 DWORD x, y, width, height;
392 LPWSTR font = NULL, title_font = NULL;
393 LPCWSTR title = NULL;
394 msi_control *control;
395
396 style |= WS_CHILD;
397
398 control = msi_alloc( FIELD_OFFSET( msi_control, name[strlenW( name ) + 1] ));
399 if (!control)
400 return NULL;
401
402 strcpyW( control->name, name );
403 list_add_tail( &dialog->controls, &control->entry );
404 control->handler = NULL;
405 control->update = NULL;
406 control->property = NULL;
407 control->value = NULL;
408 control->hBitmap = NULL;
409 control->hIcon = NULL;
410 control->hDll = NULL;
411 control->tabnext = strdupW( MSI_RecordGetString( rec, 11) );
412 control->type = strdupW( MSI_RecordGetString( rec, 3 ) );
413 control->progress_current = 0;
414 control->progress_max = 100;
415 control->progress_backwards = FALSE;
416
417 x = MSI_RecordGetInteger( rec, 4 );
418 y = MSI_RecordGetInteger( rec, 5 );
419 width = MSI_RecordGetInteger( rec, 6 );
420 height = MSI_RecordGetInteger( rec, 7 );
421
422 x = msi_dialog_scale_unit( dialog, x );
423 y = msi_dialog_scale_unit( dialog, y );
424 width = msi_dialog_scale_unit( dialog, width );
425 height = msi_dialog_scale_unit( dialog, height );
426
427 if( text )
428 {
429 deformat_string( dialog->package, text, &title_font );
430 font = msi_dialog_get_style( title_font, &title );
431 }
432
433 control->hwnd = CreateWindowExW( exstyle, szCls, title, style,
434 x, y, width, height, parent, NULL, NULL, NULL );
435
436 TRACE("Dialog %s control %s hwnd %p\n",
437 debugstr_w(dialog->name), debugstr_w(text), control->hwnd );
438
439 msi_dialog_set_font( dialog, control->hwnd,
440 font ? font : dialog->default_font );
441
442 msi_free( title_font );
443 msi_free( font );
444
445 return control;
446 }
447
448 static LPWSTR msi_dialog_get_uitext( msi_dialog *dialog, LPCWSTR key )
449 {
450 MSIRECORD *rec;
451 LPWSTR text;
452
453 static const WCHAR query[] = {
454 's','e','l','e','c','t',' ','*',' ',
455 'f','r','o','m',' ','`','U','I','T','e','x','t','`',' ',
456 'w','h','e','r','e',' ','`','K','e','y','`',' ','=',' ','\'','%','s','\'',0
457 };
458
459 rec = MSI_QueryGetRecord( dialog->package->db, query, key );
460 if (!rec) return NULL;
461 text = strdupW( MSI_RecordGetString( rec, 2 ) );
462 msiobj_release( &rec->hdr );
463 return text;
464 }
465
466 static MSIRECORD *msi_get_binary_record( MSIDATABASE *db, LPCWSTR name )
467 {
468 static const WCHAR query[] = {
469 's','e','l','e','c','t',' ','*',' ',
470 'f','r','o','m',' ','B','i','n','a','r','y',' ',
471 'w','h','e','r','e',' ',
472 '`','N','a','m','e','`',' ','=',' ','\'','%','s','\'',0
473 };
474
475 return MSI_QueryGetRecord( db, query, name );
476 }
477
478 static HANDLE msi_load_image( MSIDATABASE *db, LPCWSTR name, UINT type,
479 UINT cx, UINT cy, UINT flags )
480 {
481 MSIRECORD *rec;
482 HANDLE himage = NULL;
483 LPWSTR tmp;
484 UINT r;
485
486 TRACE("%p %s %u %u %08x\n", db, debugstr_w(name), cx, cy, flags);
487
488 if (!(tmp = msi_create_temp_file( db ))) return NULL;
489
490 rec = msi_get_binary_record( db, name );
491 if( rec )
492 {
493 r = MSI_RecordStreamToFile( rec, 2, tmp );
494 if( r == ERROR_SUCCESS )
495 {
496 himage = LoadImageW( 0, tmp, type, cx, cy, flags );
497 }
498 msiobj_release( &rec->hdr );
499 }
500 DeleteFileW( tmp );
501
502 msi_free( tmp );
503 return himage;
504 }
505
506 static HICON msi_load_icon( MSIDATABASE *db, LPCWSTR text, UINT attributes )
507 {
508 DWORD cx = 0, cy = 0, flags;
509
510 flags = LR_LOADFROMFILE | LR_DEFAULTSIZE;
511 if( attributes & msidbControlAttributesFixedSize )
512 {
513 flags &= ~LR_DEFAULTSIZE;
514 if( attributes & msidbControlAttributesIconSize16 )
515 {
516 cx += 16;
517 cy += 16;
518 }
519 if( attributes & msidbControlAttributesIconSize32 )
520 {
521 cx += 32;
522 cy += 32;
523 }
524 /* msidbControlAttributesIconSize48 handled by above logic */
525 }
526 return msi_load_image( db, text, IMAGE_ICON, cx, cy, flags );
527 }
528
529 static void msi_dialog_update_controls( msi_dialog *dialog, LPCWSTR property )
530 {
531 msi_control *control;
532
533 LIST_FOR_EACH_ENTRY( control, &dialog->controls, msi_control, entry )
534 {
535 if ( control->property && !strcmpW( control->property, property ) && control->update )
536 control->update( dialog, control );
537 }
538 }
539
540 static void msi_dialog_set_property( MSIPACKAGE *package, LPCWSTR property, LPCWSTR value )
541 {
542 UINT r = msi_set_property( package->db, property, value, -1 );
543 if (r == ERROR_SUCCESS && !strcmpW( property, szSourceDir ))
544 msi_reset_folders( package, TRUE );
545 }
546
547 static MSIFEATURE *msi_seltree_feature_from_item( HWND hwnd, HTREEITEM hItem )
548 {
549 TVITEMW tvi;
550
551 /* get the feature from the item */
552 memset( &tvi, 0, sizeof tvi );
553 tvi.hItem = hItem;
554 tvi.mask = TVIF_PARAM | TVIF_HANDLE;
555 SendMessageW( hwnd, TVM_GETITEMW, 0, (LPARAM)&tvi );
556 return (MSIFEATURE *)tvi.lParam;
557 }
558
559 struct msi_selection_tree_info
560 {
561 msi_dialog *dialog;
562 HWND hwnd;
563 WNDPROC oldproc;
564 HTREEITEM selected;
565 };
566
567 static MSIFEATURE *msi_seltree_get_selected_feature( msi_control *control )
568 {
569 struct msi_selection_tree_info *info = GetPropW( control->hwnd, szButtonData );
570 return msi_seltree_feature_from_item( control->hwnd, info->selected );
571 }
572
573 static void dialog_handle_event( msi_dialog *dialog, const WCHAR *control,
574 const WCHAR *attribute, MSIRECORD *rec )
575 {
576 msi_control* ctrl;
577
578 ctrl = msi_dialog_find_control( dialog, control );
579 if (!ctrl)
580 return;
581 if( !strcmpW( attribute, szText ) )
582 {
583 const WCHAR *font_text, *text = NULL;
584 WCHAR *font, *text_fmt = NULL;
585
586 font_text = MSI_RecordGetString( rec , 1 );
587 font = msi_dialog_get_style( font_text, &text );
588 deformat_string( dialog->package, text, &text_fmt );
589 if (text_fmt) text = text_fmt;
590 else text = szEmpty;
591
592 SetWindowTextW( ctrl->hwnd, text );
593
594 msi_free( font );
595 msi_free( text_fmt );
596 msi_dialog_check_messages( NULL );
597 }
598 else if( !strcmpW( attribute, szProgress ) )
599 {
600 DWORD func, val1, val2, units;
601
602 func = MSI_RecordGetInteger( rec, 1 );
603 val1 = MSI_RecordGetInteger( rec, 2 );
604 val2 = MSI_RecordGetInteger( rec, 3 );
605
606 TRACE("progress: func %u val1 %u val2 %u\n", func, val1, val2);
607
608 units = val1 / 512;
609 switch (func)
610 {
611 case 0: /* init */
612 SendMessageW( ctrl->hwnd, PBM_SETRANGE, 0, MAKELPARAM(0,100) );
613 if (val2)
614 {
615 ctrl->progress_max = units ? units : 100;
616 ctrl->progress_current = units;
617 ctrl->progress_backwards = TRUE;
618 SendMessageW( ctrl->hwnd, PBM_SETPOS, 100, 0 );
619 }
620 else
621 {
622 ctrl->progress_max = units ? units : 100;
623 ctrl->progress_current = 0;
624 ctrl->progress_backwards = FALSE;
625 SendMessageW( ctrl->hwnd, PBM_SETPOS, 0, 0 );
626 }
627 break;
628 case 1: /* action data increment */
629 if (val2) dialog->package->action_progress_increment = val1;
630 else dialog->package->action_progress_increment = 0;
631 break;
632 case 2: /* move */
633 if (ctrl->progress_backwards)
634 {
635 if (units >= ctrl->progress_current) ctrl->progress_current -= units;
636 else ctrl->progress_current = 0;
637 }
638 else
639 {
640 if (ctrl->progress_current + units < ctrl->progress_max) ctrl->progress_current += units;
641 else ctrl->progress_current = ctrl->progress_max;
642 }
643 SendMessageW( ctrl->hwnd, PBM_SETPOS, MulDiv(100, ctrl->progress_current, ctrl->progress_max), 0 );
644 break;
645 case 3: /* add */
646 ctrl->progress_max += units;
647 break;
648 default:
649 FIXME("Unknown progress message %u\n", func);
650 break;
651 }
652 }
653 else if ( !strcmpW( attribute, szProperty ) )
654 {
655 MSIFEATURE *feature = msi_seltree_get_selected_feature( ctrl );
656 if (feature) msi_dialog_set_property( dialog->package, ctrl->property, feature->Directory );
657 }
658 else if ( !strcmpW( attribute, szSelectionPath ) )
659 {
660 BOOL indirect = ctrl->attributes & msidbControlAttributesIndirect;
661 LPWSTR path = msi_dialog_dup_property( dialog, ctrl->property, indirect );
662 if (!path) return;
663 SetWindowTextW( ctrl->hwnd, path );
664 msi_free(path);
665 }
666 else
667 {
668 FIXME("Attribute %s not being set\n", debugstr_w(attribute));
669 return;
670 }
671 }
672
673 static void event_subscribe( msi_dialog *dialog, const WCHAR *event, const WCHAR *control, const WCHAR *attribute )
674 {
675 struct subscriber *sub;
676
677 TRACE("event %s control %s attribute %s\n", debugstr_w(event), debugstr_w(control), debugstr_w(attribute));
678
679 LIST_FOR_EACH_ENTRY( sub, &dialog->package->subscriptions, struct subscriber, entry )
680 {
681 if (!strcmpiW( sub->event, event ) &&
682 !strcmpiW( sub->control, control ) &&
683 !strcmpiW( sub->attribute, attribute ))
684 {
685 TRACE("already subscribed\n");
686 return;
687 };
688 }
689 if (!(sub = msi_alloc( sizeof(*sub) ))) return;
690 sub->dialog = dialog;
691 sub->event = strdupW( event );
692 sub->control = strdupW( control );
693 sub->attribute = strdupW( attribute );
694 list_add_tail( &dialog->package->subscriptions, &sub->entry );
695 }
696
697 struct dialog_control
698 {
699 msi_dialog *dialog;
700 const WCHAR *control;
701 };
702
703 static UINT map_event( MSIRECORD *row, void *param )
704 {
705 struct dialog_control *dc = param;
706 const WCHAR *event = MSI_RecordGetString( row, 3 );
707 const WCHAR *attribute = MSI_RecordGetString( row, 4 );
708
709 event_subscribe( dc->dialog, event, dc->control, attribute );
710 return ERROR_SUCCESS;
711 }
712
713 static void dialog_map_events( msi_dialog *dialog, const WCHAR *control )
714 {
715 static const WCHAR queryW[] =
716 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
717 '`','E','v','e','n','t','M','a','p','p','i','n','g','`',' ',
718 'W','H','E','R','E',' ','`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',' ',
719 'A','N','D',' ','`','C','o','n','t','r','o','l','_','`',' ','=',' ','\'','%','s','\'',0};
720 MSIQUERY *view;
721 struct dialog_control dialog_control =
722 {
723 dialog,
724 control
725 };
726
727 if (!MSI_OpenQuery( dialog->package->db, &view, queryW, dialog->name, control ))
728 {
729 MSI_IterateRecords( view, NULL, map_event, &dialog_control );
730 msiobj_release( &view->hdr );
731 }
732 }
733
734 /* everything except radio buttons */
735 static msi_control *msi_dialog_add_control( msi_dialog *dialog,
736 MSIRECORD *rec, LPCWSTR szCls, DWORD style )
737 {
738 DWORD attributes;
739 const WCHAR *text = NULL, *name, *control_type;
740 DWORD exstyle = 0;
741
742 name = MSI_RecordGetString( rec, 2 );
743 control_type = MSI_RecordGetString( rec, 3 );
744 attributes = MSI_RecordGetInteger( rec, 8 );
745 if (strcmpW( control_type, szScrollableText )) text = MSI_RecordGetString( rec, 10 );
746
747 TRACE("%s, %s, %08x, %s, %08x\n", debugstr_w(szCls), debugstr_w(name),
748 attributes, debugstr_w(text), style);
749
750 if( attributes & msidbControlAttributesVisible )
751 style |= WS_VISIBLE;
752 if( ~attributes & msidbControlAttributesEnabled )
753 style |= WS_DISABLED;
754 if( attributes & msidbControlAttributesSunken )
755 exstyle |= WS_EX_CLIENTEDGE;
756
757 dialog_map_events( dialog, name );
758
759 return dialog_create_window( dialog, rec, exstyle, szCls, name, text, style, dialog->hwnd );
760 }
761
762 struct msi_text_info
763 {
764 msi_font *font;
765 WNDPROC oldproc;
766 DWORD attributes;
767 };
768
769 /*
770 * we don't erase our own background,
771 * so we have to make sure that the parent window redraws first
772 */
773 static void msi_text_on_settext( HWND hWnd )
774 {
775 HWND hParent;
776 RECT rc;
777
778 hParent = GetParent( hWnd );
779 GetWindowRect( hWnd, &rc );
780 MapWindowPoints( NULL, hParent, (LPPOINT) &rc, 2 );
781 InvalidateRect( hParent, &rc, TRUE );
782 }
783
784 static LRESULT WINAPI
785 MSIText_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
786 {
787 struct msi_text_info *info;
788 LRESULT r = 0;
789
790 TRACE("%p %04x %08lx %08lx\n", hWnd, msg, wParam, lParam);
791
792 info = GetPropW(hWnd, szButtonData);
793
794 if( msg == WM_CTLCOLORSTATIC &&
795 ( info->attributes & msidbControlAttributesTransparent ) )
796 {
797 SetBkMode( (HDC)wParam, TRANSPARENT );
798 return (LRESULT) GetStockObject(NULL_BRUSH);
799 }
800
801 r = CallWindowProcW(info->oldproc, hWnd, msg, wParam, lParam);
802 if ( info->font )
803 SetTextColor( (HDC)wParam, info->font->color );
804
805 switch( msg )
806 {
807 case WM_SETTEXT:
808 msi_text_on_settext( hWnd );
809 break;
810 case WM_NCDESTROY:
811 msi_free( info );
812 RemovePropW( hWnd, szButtonData );
813 break;
814 }
815
816 return r;
817 }
818
819 static UINT msi_dialog_text_control( msi_dialog *dialog, MSIRECORD *rec )
820 {
821 msi_control *control;
822 struct msi_text_info *info;
823 LPCWSTR text, ptr, prop, control_name;
824 LPWSTR font_name;
825
826 TRACE("%p %p\n", dialog, rec);
827
828 control = msi_dialog_add_control( dialog, rec, szStatic, SS_LEFT | WS_GROUP );
829 if( !control )
830 return ERROR_FUNCTION_FAILED;
831
832 info = msi_alloc( sizeof *info );
833 if( !info )
834 return ERROR_SUCCESS;
835
836 control_name = MSI_RecordGetString( rec, 2 );
837 control->attributes = MSI_RecordGetInteger( rec, 8 );
838 prop = MSI_RecordGetString( rec, 9 );
839 control->property = msi_dialog_dup_property( dialog, prop, FALSE );
840
841 text = MSI_RecordGetString( rec, 10 );
842 font_name = msi_dialog_get_style( text, &ptr );
843 info->font = ( font_name ) ? msi_dialog_find_font( dialog, font_name ) : NULL;
844 msi_free( font_name );
845
846 info->attributes = MSI_RecordGetInteger( rec, 8 );
847 if( info->attributes & msidbControlAttributesTransparent )
848 SetWindowLongPtrW( control->hwnd, GWL_EXSTYLE, WS_EX_TRANSPARENT );
849
850 info->oldproc = (WNDPROC) SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
851 (LONG_PTR)MSIText_WndProc );
852 SetPropW( control->hwnd, szButtonData, info );
853
854 event_subscribe( dialog, szSelectionPath, control_name, szSelectionPath );
855 return ERROR_SUCCESS;
856 }
857
858 /* strip any leading text style label from text field */
859 static WCHAR *msi_get_binary_name( MSIPACKAGE *package, MSIRECORD *rec )
860 {
861 WCHAR *p, *text;
862
863 text = msi_get_deformatted_field( package, rec, 10 );
864 if (!text)
865 return NULL;
866
867 p = text;
868 while (*p && *p != '{') p++;
869 if (!*p++) return text;
870
871 while (*p && *p != '}') p++;
872 if (!*p++) return text;
873
874 p = strdupW( p );
875 msi_free( text );
876 return p;
877 }
878
879 static UINT msi_dialog_set_property_event( msi_dialog *dialog, LPCWSTR event, LPCWSTR arg )
880 {
881 static const WCHAR szNullArg[] = {'{','}',0};
882 LPWSTR p, prop, arg_fmt = NULL;
883 UINT len;
884
885 len = strlenW( event );
886 prop = msi_alloc( len * sizeof(WCHAR) );
887 strcpyW( prop, &event[1] );
888 p = strchrW( prop, ']' );
889 if (p && (p[1] == 0 || p[1] == ' '))
890 {
891 *p = 0;
892 if (strcmpW( szNullArg, arg ))
893 deformat_string( dialog->package, arg, &arg_fmt );
894 msi_dialog_set_property( dialog->package, prop, arg_fmt );
895 msi_dialog_update_controls( dialog, prop );
896 msi_free( arg_fmt );
897 }
898 else ERR("Badly formatted property string - what happens?\n");
899 msi_free( prop );
900 return ERROR_SUCCESS;
901 }
902
903 static UINT msi_dialog_send_event( msi_dialog *dialog, LPCWSTR event, LPCWSTR arg )
904 {
905 LPWSTR event_fmt = NULL, arg_fmt = NULL;
906
907 TRACE("Sending control event %s %s\n", debugstr_w(event), debugstr_w(arg));
908
909 deformat_string( dialog->package, event, &event_fmt );
910 deformat_string( dialog->package, arg, &arg_fmt );
911
912 dialog->event_handler( dialog, event_fmt, arg_fmt );
913
914 msi_free( event_fmt );
915 msi_free( arg_fmt );
916
917 return ERROR_SUCCESS;
918 }
919
920 static UINT msi_dialog_control_event( MSIRECORD *rec, LPVOID param )
921 {
922 msi_dialog *dialog = param;
923 LPCWSTR condition, event, arg;
924 UINT r;
925
926 condition = MSI_RecordGetString( rec, 5 );
927 r = MSI_EvaluateConditionW( dialog->package, condition );
928 if (r == MSICONDITION_TRUE || r == MSICONDITION_NONE)
929 {
930 event = MSI_RecordGetString( rec, 3 );
931 arg = MSI_RecordGetString( rec, 4 );
932 if (event[0] == '[')
933 msi_dialog_set_property_event( dialog, event, arg );
934 else
935 msi_dialog_send_event( dialog, event, arg );
936 }
937 return ERROR_SUCCESS;
938 }
939
940 static UINT msi_dialog_button_handler( msi_dialog *dialog, msi_control *control, WPARAM param )
941 {
942 static const WCHAR query[] = {
943 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
944 'C','o','n','t','r','o','l','E','v','e','n','t',' ','W','H','E','R','E',' ',
945 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',' ','A','N','D',' ',
946 '`','C','o','n','t','r','o','l','_','`',' ','=',' ','\'','%','s','\'',' ',
947 'O','R','D','E','R',' ','B','Y',' ','`','O','r','d','e','r','i','n','g','`',0};
948 MSIQUERY *view;
949 UINT r;
950
951 if (HIWORD(param) != BN_CLICKED)
952 return ERROR_SUCCESS;
953
954 r = MSI_OpenQuery( dialog->package->db, &view, query, dialog->name, control->name );
955 if (r != ERROR_SUCCESS)
956 {
957 ERR("query failed\n");
958 return ERROR_SUCCESS;
959 }
960 r = MSI_IterateRecords( view, 0, msi_dialog_control_event, dialog );
961 msiobj_release( &view->hdr );
962 return r;
963 }
964
965 static UINT msi_dialog_button_control( msi_dialog *dialog, MSIRECORD *rec )
966 {
967 msi_control *control;
968 UINT attributes, style;
969
970 TRACE("%p %p\n", dialog, rec);
971
972 style = WS_TABSTOP;
973 attributes = MSI_RecordGetInteger( rec, 8 );
974 if( attributes & msidbControlAttributesIcon )
975 style |= BS_ICON;
976
977 control = msi_dialog_add_control( dialog, rec, szButton, style );
978 if( !control )
979 return ERROR_FUNCTION_FAILED;
980
981 control->handler = msi_dialog_button_handler;
982
983 if (attributes & msidbControlAttributesIcon)
984 {
985 /* set the icon */
986 LPWSTR name = msi_get_binary_name( dialog->package, rec );
987 control->hIcon = msi_load_icon( dialog->package->db, name, attributes );
988 if (control->hIcon)
989 {
990 SendMessageW( control->hwnd, BM_SETIMAGE, IMAGE_ICON, (LPARAM) control->hIcon );
991 }
992 else
993 ERR("Failed to load icon %s\n", debugstr_w(name));
994 msi_free( name );
995 }
996
997 return ERROR_SUCCESS;
998 }
999
1000 static LPWSTR msi_get_checkbox_value( msi_dialog *dialog, LPCWSTR prop )
1001 {
1002 static const WCHAR query[] = {
1003 'S','E','L','E','C','T',' ','*',' ',
1004 'F','R','O','M',' ','`','C','h','e','c','k','B','o','x','`',' ',
1005 'W','H','E','R','E',' ',
1006 '`','P','r','o','p','e','r','t','y','`',' ','=',' ',
1007 '\'','%','s','\'',0
1008 };
1009 MSIRECORD *rec = NULL;
1010 LPWSTR ret = NULL;
1011
1012 /* find if there is a value associated with the checkbox */
1013 rec = MSI_QueryGetRecord( dialog->package->db, query, prop );
1014 if (!rec)
1015 return ret;
1016
1017 ret = msi_get_deformatted_field( dialog->package, rec, 2 );
1018 if( ret && !ret[0] )
1019 {
1020 msi_free( ret );
1021 ret = NULL;
1022 }
1023 msiobj_release( &rec->hdr );
1024 if (ret)
1025 return ret;
1026
1027 ret = msi_dup_property( dialog->package->db, prop );
1028 if( ret && !ret[0] )
1029 {
1030 msi_free( ret );
1031 ret = NULL;
1032 }
1033
1034 return ret;
1035 }
1036
1037 static UINT msi_dialog_get_checkbox_state( msi_dialog *dialog, msi_control *control )
1038 {
1039 WCHAR state[2] = {0};
1040 DWORD sz = 2;
1041
1042 msi_get_property( dialog->package->db, control->property, state, &sz );
1043 return state[0] ? 1 : 0;
1044 }
1045
1046 static void msi_dialog_set_checkbox_state( msi_dialog *dialog, msi_control *control, UINT state )
1047 {
1048 static const WCHAR szState[] = {'1',0};
1049 LPCWSTR val;
1050
1051 /* if uncheck then the property is set to NULL */
1052 if (!state)
1053 {
1054 msi_dialog_set_property( dialog->package, control->property, NULL );
1055 return;
1056 }
1057
1058 /* check for a custom state */
1059 if (control->value && control->value[0])
1060 val = control->value;
1061 else
1062 val = szState;
1063
1064 msi_dialog_set_property( dialog->package, control->property, val );
1065 }
1066
1067 static void msi_dialog_checkbox_sync_state( msi_dialog *dialog, msi_control *control )
1068 {
1069 UINT state = msi_dialog_get_checkbox_state( dialog, control );
1070 SendMessageW( control->hwnd, BM_SETCHECK, state ? BST_CHECKED : BST_UNCHECKED, 0 );
1071 }
1072
1073 static UINT msi_dialog_checkbox_handler( msi_dialog *dialog, msi_control *control, WPARAM param )
1074 {
1075 UINT state;
1076
1077 if (HIWORD(param) != BN_CLICKED)
1078 return ERROR_SUCCESS;
1079
1080 TRACE("clicked checkbox %s, set %s\n", debugstr_w(control->name), debugstr_w(control->property));
1081
1082 state = msi_dialog_get_checkbox_state( dialog, control );
1083 state = state ? 0 : 1;
1084 msi_dialog_set_checkbox_state( dialog, control, state );
1085 msi_dialog_checkbox_sync_state( dialog, control );
1086
1087 return msi_dialog_button_handler( dialog, control, param );
1088 }
1089
1090 static UINT msi_dialog_checkbox_control( msi_dialog *dialog, MSIRECORD *rec )
1091 {
1092 msi_control *control;
1093 LPCWSTR prop;
1094
1095 TRACE("%p %p\n", dialog, rec);
1096
1097 control = msi_dialog_add_control( dialog, rec, szButton, BS_CHECKBOX | BS_MULTILINE | WS_TABSTOP );
1098 control->handler = msi_dialog_checkbox_handler;
1099 control->update = msi_dialog_checkbox_sync_state;
1100 prop = MSI_RecordGetString( rec, 9 );
1101 if (prop)
1102 {
1103 control->property = strdupW( prop );
1104 control->value = msi_get_checkbox_value( dialog, prop );
1105 TRACE("control %s value %s\n", debugstr_w(control->property), debugstr_w(control->value));
1106 }
1107 msi_dialog_checkbox_sync_state( dialog, control );
1108 return ERROR_SUCCESS;
1109 }
1110
1111 static UINT msi_dialog_line_control( msi_dialog *dialog, MSIRECORD *rec )
1112 {
1113 DWORD attributes;
1114 LPCWSTR name;
1115 DWORD style, exstyle = 0;
1116 DWORD x, y, width, height;
1117 msi_control *control;
1118
1119 TRACE("%p %p\n", dialog, rec);
1120
1121 style = WS_CHILD | SS_ETCHEDHORZ | SS_SUNKEN;
1122
1123 name = MSI_RecordGetString( rec, 2 );
1124 attributes = MSI_RecordGetInteger( rec, 8 );
1125
1126 if( attributes & msidbControlAttributesVisible )
1127 style |= WS_VISIBLE;
1128 if( ~attributes & msidbControlAttributesEnabled )
1129 style |= WS_DISABLED;
1130 if( attributes & msidbControlAttributesSunken )
1131 exstyle |= WS_EX_CLIENTEDGE;
1132
1133 dialog_map_events( dialog, name );
1134
1135 control = msi_alloc( FIELD_OFFSET(msi_control, name[strlenW( name ) + 1] ));
1136 if (!control)
1137 return ERROR_OUTOFMEMORY;
1138
1139 strcpyW( control->name, name );
1140 list_add_head( &dialog->controls, &control->entry );
1141 control->handler = NULL;
1142 control->property = NULL;
1143 control->value = NULL;
1144 control->hBitmap = NULL;
1145 control->hIcon = NULL;
1146 control->hDll = NULL;
1147 control->tabnext = strdupW( MSI_RecordGetString( rec, 11) );
1148 control->type = strdupW( MSI_RecordGetString( rec, 3 ) );
1149 control->progress_current = 0;
1150 control->progress_max = 100;
1151 control->progress_backwards = FALSE;
1152
1153 x = MSI_RecordGetInteger( rec, 4 );
1154 y = MSI_RecordGetInteger( rec, 5 );
1155 width = MSI_RecordGetInteger( rec, 6 );
1156
1157 x = msi_dialog_scale_unit( dialog, x );
1158 y = msi_dialog_scale_unit( dialog, y );
1159 width = msi_dialog_scale_unit( dialog, width );
1160 height = 2; /* line is exactly 2 units in height */
1161
1162 control->hwnd = CreateWindowExW( exstyle, szStatic, NULL, style,
1163 x, y, width, height, dialog->hwnd, NULL, NULL, NULL );
1164
1165 TRACE("Dialog %s control %s hwnd %p\n",
1166 debugstr_w(dialog->name), debugstr_w(name), control->hwnd );
1167
1168 return ERROR_SUCCESS;
1169 }
1170
1171 /******************** Scroll Text ********************************************/
1172
1173 struct msi_scrolltext_info
1174 {
1175 msi_dialog *dialog;
1176 msi_control *control;
1177 WNDPROC oldproc;
1178 };
1179
1180 static LRESULT WINAPI
1181 MSIScrollText_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
1182 {
1183 struct msi_scrolltext_info *info;
1184 HRESULT r;
1185
1186 TRACE("%p %04x %08lx %08lx\n", hWnd, msg, wParam, lParam);
1187
1188 info = GetPropW( hWnd, szButtonData );
1189
1190 r = CallWindowProcW( info->oldproc, hWnd, msg, wParam, lParam );
1191
1192 switch( msg )
1193 {
1194 case WM_GETDLGCODE:
1195 return DLGC_WANTARROWS;
1196 case WM_NCDESTROY:
1197 msi_free( info );
1198 RemovePropW( hWnd, szButtonData );
1199 break;
1200 case WM_PAINT:
1201 /* native MSI sets a wait cursor here */
1202 msi_dialog_button_handler( info->dialog, info->control, BN_CLICKED );
1203 break;
1204 }
1205 return r;
1206 }
1207
1208 struct msi_streamin_info
1209 {
1210 LPSTR string;
1211 DWORD offset;
1212 DWORD length;
1213 };
1214
1215 static DWORD CALLBACK
1216 msi_richedit_stream_in( DWORD_PTR arg, LPBYTE buffer, LONG count, LONG *pcb )
1217 {
1218 struct msi_streamin_info *info = (struct msi_streamin_info*) arg;
1219
1220 if( (count + info->offset) > info->length )
1221 count = info->length - info->offset;
1222 memcpy( buffer, &info->string[ info->offset ], count );
1223 *pcb = count;
1224 info->offset += count;
1225
1226 TRACE("%d/%d\n", info->offset, info->length);
1227
1228 return 0;
1229 }
1230
1231 static void msi_scrolltext_add_text( msi_control *control, LPCWSTR text )
1232 {
1233 struct msi_streamin_info info;
1234 EDITSTREAM es;
1235
1236 info.string = strdupWtoA( text );
1237 info.offset = 0;
1238 info.length = lstrlenA( info.string ) + 1;
1239
1240 es.dwCookie = (DWORD_PTR) &info;
1241 es.dwError = 0;
1242 es.pfnCallback = msi_richedit_stream_in;
1243
1244 SendMessageW( control->hwnd, EM_STREAMIN, SF_RTF, (LPARAM) &es );
1245
1246 msi_free( info.string );
1247 }
1248
1249 static UINT msi_dialog_scrolltext_control( msi_dialog *dialog, MSIRECORD *rec )
1250 {
1251 static const WCHAR szRichEdit20W[] = {'R','i','c','h','E','d','i','t','2','0','W',0};
1252 struct msi_scrolltext_info *info;
1253 msi_control *control;
1254 HMODULE hRichedit;
1255 LPCWSTR text;
1256 DWORD style;
1257
1258 info = msi_alloc( sizeof *info );
1259 if (!info)
1260 return ERROR_FUNCTION_FAILED;
1261
1262 hRichedit = LoadLibraryA("riched20");
1263
1264 style = WS_BORDER | ES_MULTILINE | WS_VSCROLL |
1265 ES_READONLY | ES_AUTOVSCROLL | WS_TABSTOP;
1266 control = msi_dialog_add_control( dialog, rec, szRichEdit20W, style );
1267 if (!control)
1268 {
1269 FreeLibrary( hRichedit );
1270 msi_free( info );
1271 return ERROR_FUNCTION_FAILED;
1272 }
1273
1274 control->hDll = hRichedit;
1275
1276 info->dialog = dialog;
1277 info->control = control;
1278
1279 /* subclass the static control */
1280 info->oldproc = (WNDPROC) SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
1281 (LONG_PTR)MSIScrollText_WndProc );
1282 SetPropW( control->hwnd, szButtonData, info );
1283
1284 /* add the text into the richedit */
1285 text = MSI_RecordGetString( rec, 10 );
1286 if (text)
1287 msi_scrolltext_add_text( control, text );
1288
1289 return ERROR_SUCCESS;
1290 }
1291
1292 static HBITMAP msi_load_picture( MSIDATABASE *db, LPCWSTR name,
1293 INT cx, INT cy, DWORD flags )
1294 {
1295 HBITMAP hOleBitmap = 0, hBitmap = 0, hOldSrcBitmap, hOldDestBitmap;
1296 MSIRECORD *rec = NULL;
1297 IStream *stm = NULL;
1298 IPicture *pic = NULL;
1299 HDC srcdc, destdc;
1300 BITMAP bm;
1301 UINT r;
1302
1303 rec = msi_get_binary_record( db, name );
1304 if( !rec )
1305 goto end;
1306
1307 r = MSI_RecordGetIStream( rec, 2, &stm );
1308 msiobj_release( &rec->hdr );
1309 if( r != ERROR_SUCCESS )
1310 goto end;
1311
1312 r = OleLoadPicture( stm, 0, TRUE, &IID_IPicture, (LPVOID*) &pic );
1313 IStream_Release( stm );
1314 if( FAILED( r ) )
1315 {
1316 ERR("failed to load picture\n");
1317 goto end;
1318 }
1319
1320 r = IPicture_get_Handle( pic, (OLE_HANDLE*) &hOleBitmap );
1321 if( FAILED( r ) )
1322 {
1323 ERR("failed to get bitmap handle\n");
1324 goto end;
1325 }
1326
1327 /* make the bitmap the desired size */
1328 r = GetObjectW( hOleBitmap, sizeof bm, &bm );
1329 if (r != sizeof bm )
1330 {
1331 ERR("failed to get bitmap size\n");
1332 goto end;
1333 }
1334
1335 if (flags & LR_DEFAULTSIZE)
1336 {
1337 cx = bm.bmWidth;
1338 cy = bm.bmHeight;
1339 }
1340
1341 srcdc = CreateCompatibleDC( NULL );
1342 hOldSrcBitmap = SelectObject( srcdc, hOleBitmap );
1343 destdc = CreateCompatibleDC( NULL );
1344 hBitmap = CreateCompatibleBitmap( srcdc, cx, cy );
1345 hOldDestBitmap = SelectObject( destdc, hBitmap );
1346 StretchBlt( destdc, 0, 0, cx, cy,
1347 srcdc, 0, 0, bm.bmWidth, bm.bmHeight, SRCCOPY);
1348 SelectObject( srcdc, hOldSrcBitmap );
1349 SelectObject( destdc, hOldDestBitmap );
1350 DeleteDC( srcdc );
1351 DeleteDC( destdc );
1352
1353 end:
1354 if ( pic )
1355 IPicture_Release( pic );
1356 return hBitmap;
1357 }
1358
1359 static UINT msi_dialog_bitmap_control( msi_dialog *dialog, MSIRECORD *rec )
1360 {
1361 UINT cx, cy, flags, style, attributes;
1362 msi_control *control;
1363 LPWSTR name;
1364
1365 flags = LR_LOADFROMFILE;
1366 style = SS_BITMAP | SS_LEFT | WS_GROUP;
1367
1368 attributes = MSI_RecordGetInteger( rec, 8 );
1369 if( attributes & msidbControlAttributesFixedSize )
1370 {
1371 flags |= LR_DEFAULTSIZE;
1372 style |= SS_CENTERIMAGE;
1373 }
1374
1375 control = msi_dialog_add_control( dialog, rec, szStatic, style );
1376 cx = MSI_RecordGetInteger( rec, 6 );
1377 cy = MSI_RecordGetInteger( rec, 7 );
1378 cx = msi_dialog_scale_unit( dialog, cx );
1379 cy = msi_dialog_scale_unit( dialog, cy );
1380
1381 name = msi_get_binary_name( dialog->package, rec );
1382 control->hBitmap = msi_load_picture( dialog->package->db, name, cx, cy, flags );
1383 if( control->hBitmap )
1384 SendMessageW( control->hwnd, STM_SETIMAGE,
1385 IMAGE_BITMAP, (LPARAM) control->hBitmap );
1386 else
1387 ERR("Failed to load bitmap %s\n", debugstr_w(name));
1388
1389 msi_free( name );
1390
1391 return ERROR_SUCCESS;
1392 }
1393
1394 static UINT msi_dialog_icon_control( msi_dialog *dialog, MSIRECORD *rec )
1395 {
1396 msi_control *control;
1397 DWORD attributes;
1398 LPWSTR name;
1399
1400 TRACE("\n");
1401
1402 control = msi_dialog_add_control( dialog, rec, szStatic,
1403 SS_ICON | SS_CENTERIMAGE | WS_GROUP );
1404
1405 attributes = MSI_RecordGetInteger( rec, 8 );
1406 name = msi_get_binary_name( dialog->package, rec );
1407 control->hIcon = msi_load_icon( dialog->package->db, name, attributes );
1408 if( control->hIcon )
1409 SendMessageW( control->hwnd, STM_SETICON, (WPARAM) control->hIcon, 0 );
1410 else
1411 ERR("Failed to load bitmap %s\n", debugstr_w(name));
1412 msi_free( name );
1413 return ERROR_SUCCESS;
1414 }
1415
1416 /******************** Combo Box ***************************************/
1417
1418 struct msi_combobox_info
1419 {
1420 msi_dialog *dialog;
1421 HWND hwnd;
1422 WNDPROC oldproc;
1423 DWORD num_items;
1424 DWORD addpos_items;
1425 LPWSTR *items;
1426 };
1427
1428 static LRESULT WINAPI MSIComboBox_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
1429 {
1430 struct msi_combobox_info *info;
1431 LRESULT r;
1432 DWORD j;
1433
1434 TRACE("%p %04x %08lx %08lx\n", hWnd, msg, wParam, lParam);
1435
1436 info = GetPropW( hWnd, szButtonData );
1437 if (!info)
1438 return 0;
1439
1440 r = CallWindowProcW( info->oldproc, hWnd, msg, wParam, lParam );
1441
1442 switch (msg)
1443 {
1444 case WM_NCDESTROY:
1445 for (j = 0; j < info->num_items; j++)
1446 msi_free( info->items[j] );
1447 msi_free( info->items );
1448 msi_free( info );
1449 RemovePropW( hWnd, szButtonData );
1450 break;
1451 }
1452
1453 return r;
1454 }
1455
1456 static UINT msi_combobox_add_item( MSIRECORD *rec, LPVOID param )
1457 {
1458 struct msi_combobox_info *info = param;
1459 LPCWSTR value, text;
1460 int pos;
1461
1462 value = MSI_RecordGetString( rec, 3 );
1463 text = MSI_RecordGetString( rec, 4 );
1464
1465 info->items[info->addpos_items] = strdupW( value );
1466
1467 pos = SendMessageW( info->hwnd, CB_ADDSTRING, 0, (LPARAM)text );
1468 SendMessageW( info->hwnd, CB_SETITEMDATA, pos, (LPARAM)info->items[info->addpos_items] );
1469 info->addpos_items++;
1470
1471 return ERROR_SUCCESS;
1472 }
1473
1474 static UINT msi_combobox_add_items( struct msi_combobox_info *info, LPCWSTR property )
1475 {
1476 static const WCHAR query[] = {
1477 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
1478 '`','C','o','m','b','o','B','o','x','`',' ','W','H','E','R','E',' ',
1479 '`','P','r','o','p','e','r','t','y','`',' ','=',' ','\'','%','s','\'',' ',
1480 'O','R','D','E','R',' ','B','Y',' ','`','O','r','d','e','r','`',0};
1481 MSIQUERY *view;
1482 DWORD count;
1483 UINT r;
1484
1485 r = MSI_OpenQuery( info->dialog->package->db, &view, query, property );
1486 if (r != ERROR_SUCCESS)
1487 return r;
1488
1489 /* just get the number of records */
1490 count = 0;
1491 r = MSI_IterateRecords( view, &count, NULL, NULL );
1492 if (r != ERROR_SUCCESS)
1493 {
1494 msiobj_release( &view->hdr );
1495 return r;
1496 }
1497 info->num_items = count;
1498 info->items = msi_alloc( sizeof(*info->items) * count );
1499
1500 r = MSI_IterateRecords( view, NULL, msi_combobox_add_item, info );
1501 msiobj_release( &view->hdr );
1502 return r;
1503 }
1504
1505 static UINT msi_dialog_set_control_condition( MSIRECORD *rec, LPVOID param )
1506 {
1507 static const WCHAR szHide[] = {'H','i','d','e',0};
1508 static const WCHAR szShow[] = {'S','h','o','w',0};
1509 static const WCHAR szDisable[] = {'D','i','s','a','b','l','e',0};
1510 static const WCHAR szEnable[] = {'E','n','a','b','l','e',0};
1511 static const WCHAR szDefault[] = {'D','e','f','a','u','l','t',0};
1512 msi_dialog *dialog = param;
1513 msi_control *control;
1514 LPCWSTR name, action, condition;
1515 UINT r;
1516
1517 name = MSI_RecordGetString( rec, 2 );
1518 action = MSI_RecordGetString( rec, 3 );
1519 condition = MSI_RecordGetString( rec, 4 );
1520 r = MSI_EvaluateConditionW( dialog->package, condition );
1521 control = msi_dialog_find_control( dialog, name );
1522 if (r == MSICONDITION_TRUE && control)
1523 {
1524 TRACE("%s control %s\n", debugstr_w(action), debugstr_w(name));
1525
1526 /* FIXME: case sensitive? */
1527 if (!strcmpW( action, szHide ))
1528 ShowWindow(control->hwnd, SW_HIDE);
1529 else if (!strcmpW( action, szShow ))
1530 ShowWindow(control->hwnd, SW_SHOW);
1531 else if (!strcmpW( action, szDisable ))
1532 EnableWindow(control->hwnd, FALSE);
1533 else if (!strcmpW( action, szEnable ))
1534 EnableWindow(control->hwnd, TRUE);
1535 else if (!strcmpW( action, szDefault ))
1536 SetFocus(control->hwnd);
1537 else
1538 FIXME("Unhandled action %s\n", debugstr_w(action));
1539 }
1540 return ERROR_SUCCESS;
1541 }
1542
1543 static UINT msi_dialog_evaluate_control_conditions( msi_dialog *dialog )
1544 {
1545 static const WCHAR query[] = {
1546 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
1547 'C','o','n','t','r','o','l','C','o','n','d','i','t','i','o','n',' ',
1548 'W','H','E','R','E',' ','`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',0};
1549 UINT r;
1550 MSIQUERY *view;
1551 MSIPACKAGE *package = dialog->package;
1552
1553 TRACE("%p %s\n", dialog, debugstr_w(dialog->name));
1554
1555 /* query the Control table for all the elements of the control */
1556 r = MSI_OpenQuery( package->db, &view, query, dialog->name );
1557 if (r != ERROR_SUCCESS)
1558 return ERROR_SUCCESS;
1559
1560 r = MSI_IterateRecords( view, 0, msi_dialog_set_control_condition, dialog );
1561 msiobj_release( &view->hdr );
1562 return r;
1563 }
1564
1565 static UINT msi_dialog_combobox_handler( msi_dialog *dialog, msi_control *control, WPARAM param )
1566 {
1567 struct msi_combobox_info *info;
1568 int index;
1569 LPWSTR value;
1570
1571 if (HIWORD(param) != CBN_SELCHANGE && HIWORD(param) != CBN_EDITCHANGE)
1572 return ERROR_SUCCESS;
1573
1574 info = GetPropW( control->hwnd, szButtonData );
1575 index = SendMessageW( control->hwnd, CB_GETCURSEL, 0, 0 );
1576 if (index == CB_ERR)
1577 value = msi_get_window_text( control->hwnd );
1578 else
1579 value = (LPWSTR) SendMessageW( control->hwnd, CB_GETITEMDATA, index, 0 );
1580
1581 msi_dialog_set_property( info->dialog->package, control->property, value );
1582 msi_dialog_evaluate_control_conditions( info->dialog );
1583
1584 if (index == CB_ERR)
1585 msi_free( value );
1586
1587 return ERROR_SUCCESS;
1588 }
1589
1590 static void msi_dialog_combobox_update( msi_dialog *dialog, msi_control *control )
1591 {
1592 struct msi_combobox_info *info;
1593 LPWSTR value, tmp;
1594 DWORD j;
1595
1596 info = GetPropW( control->hwnd, szButtonData );
1597
1598 value = msi_dup_property( dialog->package->db, control->property );
1599 if (!value)
1600 {
1601 SendMessageW( control->hwnd, CB_SETCURSEL, -1, 0 );
1602 return;
1603 }
1604
1605 for (j = 0; j < info->num_items; j++)
1606 {
1607 tmp = (LPWSTR) SendMessageW( control->hwnd, CB_GETITEMDATA, j, 0 );
1608 if (!strcmpW( value, tmp ))
1609 break;
1610 }
1611
1612 if (j < info->num_items)
1613 {
1614 SendMessageW( control->hwnd, CB_SETCURSEL, j, 0 );
1615 }
1616 else
1617 {
1618 SendMessageW( control->hwnd, CB_SETCURSEL, -1, 0 );
1619 SetWindowTextW( control->hwnd, value );
1620 }
1621
1622 msi_free(value);
1623 }
1624
1625 static UINT msi_dialog_combo_control( msi_dialog *dialog, MSIRECORD *rec )
1626 {
1627 struct msi_combobox_info *info;
1628 msi_control *control;
1629 DWORD attributes, style;
1630 LPCWSTR prop;
1631
1632 info = msi_alloc( sizeof *info );
1633 if (!info)
1634 return ERROR_FUNCTION_FAILED;
1635
1636 style = CBS_AUTOHSCROLL | WS_TABSTOP | WS_GROUP | WS_CHILD;
1637 attributes = MSI_RecordGetInteger( rec, 8 );
1638 if ( ~attributes & msidbControlAttributesSorted)
1639 style |= CBS_SORT;
1640 if ( attributes & msidbControlAttributesComboList)
1641 style |= CBS_DROPDOWNLIST;
1642 else
1643 style |= CBS_DROPDOWN;
1644
1645 control = msi_dialog_add_control( dialog, rec, WC_COMBOBOXW, style );
1646 if (!control)
1647 {
1648 msi_free( info );
1649 return ERROR_FUNCTION_FAILED;
1650 }
1651
1652 control->handler = msi_dialog_combobox_handler;
1653 control->update = msi_dialog_combobox_update;
1654
1655 prop = MSI_RecordGetString( rec, 9 );
1656 control->property = msi_dialog_dup_property( dialog, prop, FALSE );
1657
1658 /* subclass */
1659 info->dialog = dialog;
1660 info->hwnd = control->hwnd;
1661 info->items = NULL;
1662 info->addpos_items = 0;
1663 info->oldproc = (WNDPROC)SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
1664 (LONG_PTR)MSIComboBox_WndProc );
1665 SetPropW( control->hwnd, szButtonData, info );
1666
1667 if (control->property)
1668 msi_combobox_add_items( info, control->property );
1669
1670 msi_dialog_combobox_update( dialog, control );
1671
1672 return ERROR_SUCCESS;
1673 }
1674
1675 static UINT msi_dialog_edit_handler( msi_dialog *dialog, msi_control *control, WPARAM param )
1676 {
1677 LPWSTR buf;
1678
1679 if (HIWORD(param) != EN_CHANGE)
1680 return ERROR_SUCCESS;
1681
1682 TRACE("edit %s contents changed, set %s\n", debugstr_w(control->name), debugstr_w(control->property));
1683
1684 buf = msi_get_window_text( control->hwnd );
1685 msi_dialog_set_property( dialog->package, control->property, buf );
1686 msi_free( buf );
1687
1688 return ERROR_SUCCESS;
1689 }
1690
1691 /* length of 2^32 + 1 */
1692 #define MAX_NUM_DIGITS 11
1693
1694 static UINT msi_dialog_edit_control( msi_dialog *dialog, MSIRECORD *rec )
1695 {
1696 msi_control *control;
1697 LPCWSTR prop, text;
1698 LPWSTR val, begin, end;
1699 WCHAR num[MAX_NUM_DIGITS];
1700 DWORD limit;
1701
1702 control = msi_dialog_add_control( dialog, rec, szEdit,
1703 WS_BORDER | WS_TABSTOP | ES_AUTOHSCROLL );
1704 control->handler = msi_dialog_edit_handler;
1705
1706 text = MSI_RecordGetString( rec, 10 );
1707 if ( text )
1708 {
1709 begin = strchrW( text, '{' );
1710 end = strchrW( text, '}' );
1711
1712 if ( begin && end && end > begin &&
1713 begin[0] >= '0' && begin[0] <= '9' &&
1714 end - begin < MAX_NUM_DIGITS)
1715 {
1716 lstrcpynW( num, begin + 1, end - begin );
1717 limit = atolW( num );
1718
1719 SendMessageW( control->hwnd, EM_SETLIMITTEXT, limit, 0 );
1720 }
1721 }
1722
1723 prop = MSI_RecordGetString( rec, 9 );
1724 if( prop )
1725 control->property = strdupW( prop );
1726
1727 val = msi_dup_property( dialog->package->db, control->property );
1728 SetWindowTextW( control->hwnd, val );
1729 msi_free( val );
1730 return ERROR_SUCCESS;
1731 }
1732
1733 /******************** Masked Edit ********************************************/
1734
1735 #define MASK_MAX_GROUPS 20
1736
1737 struct msi_mask_group
1738 {
1739 UINT len;
1740 UINT ofs;
1741 WCHAR type;
1742 HWND hwnd;
1743 };
1744
1745 struct msi_maskedit_info
1746 {
1747 msi_dialog *dialog;
1748 WNDPROC oldproc;
1749 HWND hwnd;
1750 LPWSTR prop;
1751 UINT num_chars;
1752 UINT num_groups;
1753 struct msi_mask_group group[MASK_MAX_GROUPS];
1754 };
1755
1756 static BOOL msi_mask_editable( WCHAR type )
1757 {
1758 switch (type)
1759 {
1760 case '%':
1761 case '#':
1762 case '&':
1763 case '`':
1764 case '?':
1765 case '^':
1766 return TRUE;
1767 }
1768 return FALSE;
1769 }
1770
1771 static void msi_mask_control_change( struct msi_maskedit_info *info )
1772 {
1773 LPWSTR val;
1774 UINT i, n, r;
1775
1776 val = msi_alloc( (info->num_chars+1)*sizeof(WCHAR) );
1777 for( i=0, n=0; i<info->num_groups; i++ )
1778 {
1779 if (info->group[i].len == ~0u)
1780 {
1781 UINT len = SendMessageW( info->group[i].hwnd, WM_GETTEXTLENGTH, 0, 0 );
1782 val = msi_realloc( val, (len + 1) * sizeof(WCHAR) );
1783 GetWindowTextW( info->group[i].hwnd, val, len + 1 );
1784 }
1785 else
1786 {
1787 if (info->group[i].len + n > info->num_chars)
1788 {
1789 ERR("can't fit control %d text into template\n",i);
1790 break;
1791 }
1792 if (!msi_mask_editable(info->group[i].type))
1793 {
1794 for(r=0; r<info->group[i].len; r++)
1795 val[n+r] = info->group[i].type;
1796 val[n+r] = 0;
1797 }
1798 else
1799 {
1800 r = GetWindowTextW( info->group[i].hwnd, &val[n], info->group[i].len+1 );
1801 if( r != info->group[i].len )
1802 break;
1803 }
1804 n += r;
1805 }
1806 }
1807
1808 TRACE("%d/%d controls were good\n", i, info->num_groups);
1809
1810 if( i == info->num_groups )
1811 {
1812 TRACE("Set property %s to %s\n", debugstr_w(info->prop), debugstr_w(val));
1813 msi_dialog_set_property( info->dialog->package, info->prop, val );
1814 msi_dialog_evaluate_control_conditions( info->dialog );
1815 }
1816 msi_free( val );
1817 }
1818
1819 /* now move to the next control if necessary */
1820 static VOID msi_mask_next_control( struct msi_maskedit_info *info, HWND hWnd )
1821 {
1822 HWND hWndNext;
1823 UINT len, i;
1824
1825 for( i=0; i<info->num_groups; i++ )
1826 if( info->group[i].hwnd == hWnd )
1827 break;
1828
1829 /* don't move from the last control */
1830 if( i >= (info->num_groups-1) )
1831 return;
1832
1833 len = SendMessageW( hWnd, WM_GETTEXTLENGTH, 0, 0 );
1834 if( len < info->group[i].len )
1835 return;
1836
1837 hWndNext = GetNextDlgTabItem( GetParent( hWnd ), hWnd, FALSE );
1838 SetFocus( hWndNext );
1839 }
1840
1841 static LRESULT WINAPI
1842 MSIMaskedEdit_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
1843 {
1844 struct msi_maskedit_info *info;
1845 HRESULT r;
1846
1847 TRACE("%p %04x %08lx %08lx\n", hWnd, msg, wParam, lParam);
1848
1849 info = GetPropW(hWnd, szButtonData);
1850
1851 r = CallWindowProcW(info->oldproc, hWnd, msg, wParam, lParam);
1852
1853 switch( msg )
1854 {
1855 case WM_COMMAND:
1856 if (HIWORD(wParam) == EN_CHANGE)
1857 {
1858 msi_mask_control_change( info );
1859 msi_mask_next_control( info, (HWND) lParam );
1860 }
1861 break;
1862 case WM_NCDESTROY:
1863 msi_free( info->prop );
1864 msi_free( info );
1865 RemovePropW( hWnd, szButtonData );
1866 break;
1867 }
1868
1869 return r;
1870 }
1871
1872 /* fish the various bits of the property out and put them in the control */
1873 static void
1874 msi_maskedit_set_text( struct msi_maskedit_info *info, LPCWSTR text )
1875 {
1876 LPCWSTR p;
1877 UINT i;
1878
1879 p = text;
1880 for( i = 0; i < info->num_groups; i++ )
1881 {
1882 if( info->group[i].len < strlenW( p ) )
1883 {
1884 LPWSTR chunk = strdupW( p );
1885 chunk[ info->group[i].len ] = 0;
1886 SetWindowTextW( info->group[i].hwnd, chunk );
1887 msi_free( chunk );
1888 }
1889 else
1890 {
1891 SetWindowTextW( info->group[i].hwnd, p );
1892 break;
1893 }
1894 p += info->group[i].len;
1895 }
1896 }
1897
1898 static struct msi_maskedit_info * msi_dialog_parse_groups( LPCWSTR mask )
1899 {
1900 struct msi_maskedit_info *info;
1901 int i = 0, n = 0, total = 0;
1902 LPCWSTR p;
1903
1904 TRACE("masked control, template %s\n", debugstr_w(mask));
1905
1906 if( !mask )
1907 return NULL;
1908
1909 info = msi_alloc_zero( sizeof *info );
1910 if( !info )
1911 return info;
1912
1913 p = strchrW(mask, '<');
1914 if( p )
1915 p++;
1916 else
1917 p = mask;
1918
1919 for( i=0; i<MASK_MAX_GROUPS; i++ )
1920 {
1921 /* stop at the end of the string */
1922 if( p[0] == 0 || p[0] == '>' )
1923 {
1924 if (!total)
1925 {
1926 /* create a group for the empty mask */
1927 info->group[0].type = '&';
1928 info->group[0].len = ~0u;
1929 i = 1;
1930 }
1931 break;
1932 }
1933
1934 /* count the number of the same identifier */
1935 for( n=0; p[n] == p[0]; n++ )
1936 ;
1937 info->group[i].ofs = total;
1938 info->group[i].type = p[0];
1939 if( p[n] == '=' )
1940 {
1941 n++;
1942 total++; /* an extra not part of the group */
1943 }
1944 info->group[i].len = n;
1945 total += n;
1946 p += n;
1947 }
1948
1949 TRACE("%d characters in %d groups\n", total, i );
1950 if( i == MASK_MAX_GROUPS )
1951 ERR("too many groups in PIDTemplate %s\n", debugstr_w(mask));
1952
1953 info->num_chars = total;
1954 info->num_groups = i;
1955
1956 return info;
1957 }
1958
1959 static void
1960 msi_maskedit_create_children( struct msi_maskedit_info *info, LPCWSTR font )
1961 {
1962 DWORD width, height, style, wx, ww;
1963 RECT rect;
1964 HWND hwnd;
1965 UINT i;
1966
1967 style = WS_CHILD | WS_BORDER | WS_VISIBLE | WS_TABSTOP | ES_AUTOHSCROLL;
1968
1969 GetClientRect( info->hwnd, &rect );
1970
1971 width = rect.right - rect.left;
1972 height = rect.bottom - rect.top;
1973
1974 for( i = 0; i < info->num_groups; i++ )
1975 {
1976 if (!msi_mask_editable( info->group[i].type ))
1977 continue;
1978 if (info->num_chars)
1979 {
1980 wx = (info->group[i].ofs * width) / info->num_chars;
1981 ww = (info->group[i].len * width) / info->num_chars;
1982 }
1983 else
1984 {
1985 wx = 0;
1986 ww = width;
1987 }
1988 hwnd = CreateWindowW( szEdit, NULL, style, wx, 0, ww, height,
1989 info->hwnd, NULL, NULL, NULL );
1990 if( !hwnd )
1991 {
1992 ERR("failed to create mask edit sub window\n");
1993 break;
1994 }
1995
1996 SendMessageW( hwnd, EM_LIMITTEXT, info->group[i].len, 0 );
1997
1998 msi_dialog_set_font( info->dialog, hwnd,
1999 font?font:info->dialog->default_font );
2000 info->group[i].hwnd = hwnd;
2001 }
2002 }
2003
2004 /*
2005 * office 2003 uses "73931<````=````=````=````=`````>@@@@@"
2006 * delphi 7 uses "<????-??????-??????-????>" and "<???-???>"
2007 * filemaker pro 7 uses "<^^^^=^^^^=^^^^=^^^^=^^^^=^^^^=^^^^^>"
2008 */
2009 static UINT msi_dialog_maskedit_control( msi_dialog *dialog, MSIRECORD *rec )
2010 {
2011 LPWSTR font_mask, val = NULL, font;
2012 struct msi_maskedit_info *info = NULL;
2013 UINT ret = ERROR_SUCCESS;
2014 msi_control *control;
2015 LPCWSTR prop, mask;
2016
2017 TRACE("\n");
2018
2019 font_mask = msi_get_deformatted_field( dialog->package, rec, 10 );
2020 font = msi_dialog_get_style( font_mask, &mask );
2021 if( !mask )
2022 {
2023 WARN("mask template is empty\n");
2024 goto end;
2025 }
2026
2027 info = msi_dialog_parse_groups( mask );
2028 if( !info )
2029 {
2030 ERR("template %s is invalid\n", debugstr_w(mask));
2031 goto end;
2032 }
2033
2034 info->dialog = dialog;
2035
2036 control = msi_dialog_add_control( dialog, rec, szStatic,
2037 SS_OWNERDRAW | WS_GROUP | WS_VISIBLE );
2038 if( !control )
2039 {
2040 ERR("Failed to create maskedit container\n");
2041 ret = ERROR_FUNCTION_FAILED;
2042 goto end;
2043 }
2044 SetWindowLongPtrW( control->hwnd, GWL_EXSTYLE, WS_EX_CONTROLPARENT );
2045
2046 info->hwnd = control->hwnd;
2047
2048 /* subclass the static control */
2049 info->oldproc = (WNDPROC) SetWindowLongPtrW( info->hwnd, GWLP_WNDPROC,
2050 (LONG_PTR)MSIMaskedEdit_WndProc );
2051 SetPropW( control->hwnd, szButtonData, info );
2052
2053 prop = MSI_RecordGetString( rec, 9 );
2054 if( prop )
2055 info->prop = strdupW( prop );
2056
2057 msi_maskedit_create_children( info, font );
2058
2059 if( prop )
2060 {
2061 val = msi_dup_property( dialog->package->db, prop );
2062 if( val )
2063 {
2064 msi_maskedit_set_text( info, val );
2065 msi_free( val );
2066 }
2067 }
2068
2069 end:
2070 if( ret != ERROR_SUCCESS )
2071 msi_free( info );
2072 msi_free( font_mask );
2073 msi_free( font );
2074 return ret;
2075 }
2076
2077 /******************** Progress Bar *****************************************/
2078
2079 static UINT msi_dialog_progress_bar( msi_dialog *dialog, MSIRECORD *rec )
2080 {
2081 msi_control *control;
2082 DWORD attributes, style;
2083
2084 style = WS_VISIBLE;
2085 attributes = MSI_RecordGetInteger( rec, 8 );
2086 if( !(attributes & msidbControlAttributesProgress95) )
2087 style |= PBS_SMOOTH;
2088
2089 control = msi_dialog_add_control( dialog, rec, PROGRESS_CLASSW, style );
2090 if( !control )
2091 return ERROR_FUNCTION_FAILED;
2092
2093 event_subscribe( dialog, szSetProgress, control->name, szProgress );
2094 return ERROR_SUCCESS;
2095 }
2096
2097 /******************** Path Edit ********************************************/
2098
2099 struct msi_pathedit_info
2100 {
2101 msi_dialog *dialog;
2102 msi_control *control;
2103 WNDPROC oldproc;
2104 };
2105
2106 static void msi_dialog_update_pathedit( msi_dialog *dialog, msi_control *control )
2107 {
2108 LPWSTR prop, path;
2109 BOOL indirect;
2110
2111 if (!control && !(control = msi_dialog_find_control_by_type( dialog, szPathEdit )))
2112 return;
2113
2114 indirect = control->attributes & msidbControlAttributesIndirect;
2115 prop = msi_dialog_dup_property( dialog, control->property, indirect );
2116 path = msi_dialog_dup_property( dialog, prop, TRUE );
2117
2118 SetWindowTextW( control->hwnd, path );
2119 SendMessageW( control->hwnd, EM_SETSEL, 0, -1 );
2120
2121 msi_free( path );
2122 msi_free( prop );
2123 }
2124
2125 /* FIXME: test when this should fail */
2126 static BOOL msi_dialog_verify_path( LPWSTR path )
2127 {
2128 if ( !path[0] )
2129 return FALSE;
2130
2131 if ( PathIsRelativeW( path ) )
2132 return FALSE;
2133
2134 return TRUE;
2135 }
2136
2137 /* returns TRUE if the path is valid, FALSE otherwise */
2138 static BOOL msi_dialog_onkillfocus( msi_dialog *dialog, msi_control *control )
2139 {
2140 LPWSTR buf, prop;
2141 BOOL indirect;
2142 BOOL valid;
2143
2144 indirect = control->attributes & msidbControlAttributesIndirect;
2145 prop = msi_dialog_dup_property( dialog, control->property, indirect );
2146
2147 buf = msi_get_window_text( control->hwnd );
2148
2149 if ( !msi_dialog_verify_path( buf ) )
2150 {
2151 /* FIXME: display an error message box */
2152 ERR("Invalid path %s\n", debugstr_w( buf ));
2153 valid = FALSE;
2154 SetFocus( control->hwnd );
2155 }
2156 else
2157 {
2158 valid = TRUE;
2159 msi_dialog_set_property( dialog->package, prop, buf );
2160 }
2161
2162 msi_dialog_update_pathedit( dialog, control );
2163
2164 TRACE("edit %s contents changed, set %s\n", debugstr_w(control->name),
2165 debugstr_w(prop));
2166
2167 msi_free( buf );
2168 msi_free( prop );
2169
2170 return valid;
2171 }
2172
2173 static LRESULT WINAPI MSIPathEdit_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
2174 {
2175 struct msi_pathedit_info *info = GetPropW(hWnd, szButtonData);
2176 LRESULT r = 0;
2177
2178 TRACE("%p %04x %08lx %08lx\n", hWnd, msg, wParam, lParam);
2179
2180 if ( msg == WM_KILLFOCUS )
2181 {
2182 /* if the path is invalid, don't handle this message */
2183 if ( !msi_dialog_onkillfocus( info->dialog, info->control ) )
2184 return 0;
2185 }
2186
2187 r = CallWindowProcW(info->oldproc, hWnd, msg, wParam, lParam);
2188
2189 if ( msg == WM_NCDESTROY )
2190 {
2191 msi_free( info );
2192 RemovePropW( hWnd, szButtonData );
2193 }
2194
2195 return r;
2196 }
2197
2198 static UINT msi_dialog_pathedit_control( msi_dialog *dialog, MSIRECORD *rec )
2199 {
2200 struct msi_pathedit_info *info;
2201 msi_control *control;
2202 LPCWSTR prop;
2203
2204 info = msi_alloc( sizeof *info );
2205 if (!info)
2206 return ERROR_FUNCTION_FAILED;
2207
2208 control = msi_dialog_add_control( dialog, rec, szEdit,
2209 WS_BORDER | WS_TABSTOP );
2210 control->attributes = MSI_RecordGetInteger( rec, 8 );
2211 prop = MSI_RecordGetString( rec, 9 );
2212 control->property = msi_dialog_dup_property( dialog, prop, FALSE );
2213
2214 info->dialog = dialog;
2215 info->control = control;
2216 info->oldproc = (WNDPROC) SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
2217 (LONG_PTR)MSIPathEdit_WndProc );
2218 SetPropW( control->hwnd, szButtonData, info );
2219
2220 msi_dialog_update_pathedit( dialog, control );
2221
2222 return ERROR_SUCCESS;
2223 }
2224
2225 static UINT msi_dialog_radiogroup_handler( msi_dialog *dialog, msi_control *control, WPARAM param )
2226 {
2227 if (HIWORD(param) != BN_CLICKED)
2228 return ERROR_SUCCESS;
2229
2230 TRACE("clicked radio button %s, set %s\n", debugstr_w(control->name), debugstr_w(control->property));
2231
2232 msi_dialog_set_property( dialog->package, control->property, control->name );
2233
2234 return msi_dialog_button_handler( dialog, control, param );
2235 }
2236
2237 /* radio buttons are a bit different from normal controls */
2238 static UINT msi_dialog_create_radiobutton( MSIRECORD *rec, LPVOID param )
2239 {
2240 radio_button_group_descr *group = param;
2241 msi_dialog *dialog = group->dialog;
2242 msi_control *control;
2243 LPCWSTR prop, text, name;
2244 DWORD style = WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_AUTORADIOBUTTON | BS_MULTILINE;
2245
2246 name = MSI_RecordGetString( rec, 3 );
2247 text = MSI_RecordGetString( rec, 8 );
2248
2249 control = dialog_create_window( dialog, rec, 0, szButton, name, text, style,
2250 group->parent->hwnd );
2251 if (!control)
2252 return ERROR_FUNCTION_FAILED;
2253 control->handler = msi_dialog_radiogroup_handler;
2254
2255 if (group->propval && !strcmpW( control->name, group->propval ))
2256 SendMessageW(control->hwnd, BM_SETCHECK, BST_CHECKED, 0);
2257
2258 prop = MSI_RecordGetString( rec, 1 );
2259 if( prop )
2260 control->property = strdupW( prop );
2261
2262 return ERROR_SUCCESS;
2263 }
2264
2265 static BOOL CALLBACK msi_radioground_child_enum( HWND hWnd, LPARAM lParam )
2266 {
2267 EnableWindow( hWnd, lParam );
2268 return TRUE;
2269 }
2270
2271 static LRESULT WINAPI MSIRadioGroup_WndProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
2272 {
2273 WNDPROC oldproc = (WNDPROC)GetPropW( hWnd, szButtonData );
2274 LRESULT r;
2275
2276 TRACE("hWnd %p msg %04x wParam 0x%08lx lParam 0x%08lx\n", hWnd, msg, wParam, lParam);
2277
2278 if (msg == WM_COMMAND) /* Forward notifications to dialog */
2279 SendMessageW( GetParent( hWnd ), msg, wParam, lParam );
2280
2281 r = CallWindowProcW( oldproc, hWnd, msg, wParam, lParam );
2282
2283 /* make sure the radio buttons show as disabled if the parent is disabled */
2284 if (msg == WM_ENABLE)
2285 EnumChildWindows( hWnd, msi_radioground_child_enum, wParam );
2286
2287 return r;
2288 }
2289
2290 static UINT msi_dialog_radiogroup_control( msi_dialog *dialog, MSIRECORD *rec )
2291 {
2292 static const WCHAR query[] = {
2293 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2294 'R','a','d','i','o','B','u','t','t','o','n',' ','W','H','E','R','E',' ',
2295 '`','P','r','o','p','e','r','t','y','`',' ','=',' ','\'','%','s','\'',0};
2296 UINT r;
2297 LPCWSTR prop;
2298 msi_control *control;
2299 MSIQUERY *view;
2300 radio_button_group_descr group;
2301 MSIPACKAGE *package = dialog->package;
2302 WNDPROC oldproc;
2303 DWORD attr, style = WS_GROUP;
2304
2305 prop = MSI_RecordGetString( rec, 9 );
2306
2307 TRACE("%p %p %s\n", dialog, rec, debugstr_w( prop ));
2308
2309 attr = MSI_RecordGetInteger( rec, 8 );
2310 if (attr & msidbControlAttributesVisible)
2311 style |= WS_VISIBLE;
2312 if (~attr & msidbControlAttributesEnabled)
2313 style |= WS_DISABLED;
2314 if (attr & msidbControlAttributesHasBorder)
2315 style |= BS_GROUPBOX;
2316 else
2317 style |= BS_OWNERDRAW;
2318
2319 /* Create parent group box to hold radio buttons */
2320 control = msi_dialog_add_control( dialog, rec, szButton, style );
2321 if( !control )
2322 return ERROR_FUNCTION_FAILED;
2323
2324 oldproc = (WNDPROC) SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
2325 (LONG_PTR)MSIRadioGroup_WndProc );
2326 SetPropW(control->hwnd, szButtonData, oldproc);
2327 SetWindowLongPtrW( control->hwnd, GWL_EXSTYLE, WS_EX_CONTROLPARENT );
2328
2329 if( prop )
2330 control->property = strdupW( prop );
2331
2332 /* query the Radio Button table for all control in this group */
2333 r = MSI_OpenQuery( package->db, &view, query, prop );
2334 if( r != ERROR_SUCCESS )
2335 {
2336 ERR("query failed for dialog %s radio group %s\n",
2337 debugstr_w(dialog->name), debugstr_w(prop));
2338 return ERROR_INVALID_PARAMETER;
2339 }
2340
2341 group.dialog = dialog;
2342 group.parent = control;
2343 group.propval = msi_dup_property( dialog->package->db, control->property );
2344
2345 r = MSI_IterateRecords( view, 0, msi_dialog_create_radiobutton, &group );
2346 msiobj_release( &view->hdr );
2347 msi_free( group.propval );
2348 return r;
2349 }
2350
2351 static void
2352 msi_seltree_sync_item_state( HWND hwnd, MSIFEATURE *feature, HTREEITEM hItem )
2353 {
2354 TVITEMW tvi;
2355 DWORD index = feature->ActionRequest;
2356
2357 TRACE("Feature %s -> %d %d %d\n", debugstr_w(feature->Title),
2358 feature->Installed, feature->Action, feature->ActionRequest);
2359
2360 if (index == INSTALLSTATE_UNKNOWN)
2361 index = INSTALLSTATE_ABSENT;
2362
2363 tvi.mask = TVIF_STATE;
2364 tvi.hItem = hItem;
2365 tvi.state = INDEXTOSTATEIMAGEMASK( index );
2366 tvi.stateMask = TVIS_STATEIMAGEMASK;
2367
2368 SendMessageW( hwnd, TVM_SETITEMW, 0, (LPARAM) &tvi );
2369 }
2370
2371 static UINT
2372 msi_seltree_popup_menu( HWND hwnd, INT x, INT y )
2373 {
2374 HMENU hMenu;
2375 INT r;
2376
2377 /* create a menu to display */
2378 hMenu = CreatePopupMenu();
2379
2380 /* FIXME: load strings from resources */
2381 AppendMenuA( hMenu, MF_ENABLED, INSTALLSTATE_LOCAL, "Install feature locally");
2382 AppendMenuA( hMenu, MF_ENABLED, USER_INSTALLSTATE_ALL, "Install entire feature");
2383 AppendMenuA( hMenu, MF_ENABLED, INSTALLSTATE_ADVERTISED, "Install on demand");
2384 AppendMenuA( hMenu, MF_ENABLED, INSTALLSTATE_ABSENT, "Don't install");
2385 r = TrackPopupMenu( hMenu, TPM_LEFTALIGN | TPM_TOPALIGN | TPM_RETURNCMD,
2386 x, y, 0, hwnd, NULL );
2387 DestroyMenu( hMenu );
2388 return r;
2389 }
2390
2391 static void
2392 msi_seltree_update_feature_installstate( HWND hwnd, HTREEITEM hItem,
2393 MSIPACKAGE *package, MSIFEATURE *feature, INSTALLSTATE state )
2394 {
2395 feature->ActionRequest = state;
2396 msi_seltree_sync_item_state( hwnd, feature, hItem );
2397 ACTION_UpdateComponentStates( package, feature );
2398 }
2399
2400 static void
2401 msi_seltree_update_siblings_and_children_installstate( HWND hwnd, HTREEITEM curr,
2402 MSIPACKAGE *package, INSTALLSTATE state)
2403 {
2404 /* update all siblings */
2405 do
2406 {
2407 MSIFEATURE *feature;
2408 HTREEITEM child;
2409
2410 feature = msi_seltree_feature_from_item( hwnd, curr );
2411 msi_seltree_update_feature_installstate( hwnd, curr, package, feature, state );
2412
2413 /* update this sibling's children */
2414 child = (HTREEITEM)SendMessageW( hwnd, TVM_GETNEXTITEM, (WPARAM)TVGN_CHILD, (LPARAM)curr );
2415 if (child)
2416 msi_seltree_update_siblings_and_children_installstate( hwnd, child,
2417 package, state );
2418 }
2419 while ((curr = (HTREEITEM)SendMessageW( hwnd, TVM_GETNEXTITEM, (WPARAM)TVGN_NEXT, (LPARAM)curr )));
2420 }
2421
2422 static LRESULT
2423 msi_seltree_menu( HWND hwnd, HTREEITEM hItem )
2424 {
2425 struct msi_selection_tree_info *info;
2426 MSIFEATURE *feature;
2427 MSIPACKAGE *package;
2428 union {
2429 RECT rc;
2430 POINT pt[2];
2431 HTREEITEM hItem;
2432 } u;
2433 UINT r;
2434
2435 info = GetPropW(hwnd, szButtonData);
2436 package = info->dialog->package;
2437
2438 feature = msi_seltree_feature_from_item( hwnd, hItem );
2439 if (!feature)
2440 {
2441 ERR("item %p feature was NULL\n", hItem);
2442 return 0;
2443 }
2444
2445 /* get the item's rectangle to put the menu just below it */
2446 u.hItem = hItem;
2447 SendMessageW( hwnd, TVM_GETITEMRECT, 0, (LPARAM) &u.rc );
2448 MapWindowPoints( hwnd, NULL, u.pt, 2 );
2449
2450 r = msi_seltree_popup_menu( hwnd, u.rc.left, u.rc.top );
2451
2452 switch (r)
2453 {
2454 case USER_INSTALLSTATE_ALL:
2455 r = INSTALLSTATE_LOCAL;
2456 /* fall-through */
2457 case INSTALLSTATE_ADVERTISED:
2458 case INSTALLSTATE_ABSENT:
2459 {
2460 HTREEITEM child;
2461 child = (HTREEITEM)SendMessageW( hwnd, TVM_GETNEXTITEM, (WPARAM)TVGN_CHILD, (LPARAM)hItem );
2462 if (child)
2463 msi_seltree_update_siblings_and_children_installstate( hwnd, child, package, r );
2464 }
2465 /* fall-through */
2466 case INSTALLSTATE_LOCAL:
2467 msi_seltree_update_feature_installstate( hwnd, hItem, package, feature, r );
2468 break;
2469 }
2470
2471 return 0;
2472 }
2473
2474 static LRESULT WINAPI
2475 MSISelectionTree_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
2476 {
2477 struct msi_selection_tree_info *info;
2478 TVHITTESTINFO tvhti;
2479 HRESULT r;
2480
2481 TRACE("%p %04x %08lx %08lx\n", hWnd, msg, wParam, lParam);
2482
2483 info = GetPropW(hWnd, szButtonData);
2484
2485 switch( msg )
2486 {
2487 case WM_LBUTTONDOWN:
2488 tvhti.pt.x = (short)LOWORD( lParam );
2489 tvhti.pt.y = (short)HIWORD( lParam );
2490 tvhti.flags = 0;
2491 tvhti.hItem = 0;
2492 CallWindowProcW(info->oldproc, hWnd, TVM_HITTEST, 0, (LPARAM) &tvhti );
2493 if (tvhti.flags & TVHT_ONITEMSTATEICON)
2494 return msi_seltree_menu( hWnd, tvhti.hItem );
2495 break;
2496 }
2497 r = CallWindowProcW(info->oldproc, hWnd, msg, wParam, lParam);
2498
2499 switch( msg )
2500 {
2501 case WM_NCDESTROY:
2502 msi_free( info );
2503 RemovePropW( hWnd, szButtonData );
2504 break;
2505 }
2506 return r;
2507 }
2508
2509 static void
2510 msi_seltree_add_child_features( MSIPACKAGE *package, HWND hwnd,
2511 LPCWSTR parent, HTREEITEM hParent )
2512 {
2513 struct msi_selection_tree_info *info = GetPropW( hwnd, szButtonData );
2514 MSIFEATURE *feature;
2515 TVINSERTSTRUCTW tvis;
2516 HTREEITEM hitem, hfirst = NULL;
2517
2518 LIST_FOR_EACH_ENTRY( feature, &package->features, MSIFEATURE, entry )
2519 {
2520 if ( parent && feature->Feature_Parent && strcmpW( parent, feature->Feature_Parent ))
2521 continue;
2522 else if ( parent && !feature->Feature_Parent )
2523 continue;
2524 else if ( !parent && feature->Feature_Parent )
2525 continue;
2526
2527 if ( !feature->Title )
2528 continue;
2529
2530 if ( !feature->Display )
2531 continue;
2532
2533 memset( &tvis, 0, sizeof tvis );
2534 tvis.hParent = hParent;
2535 tvis.hInsertAfter = TVI_LAST;
2536 tvis.u.item.mask = TVIF_TEXT | TVIF_PARAM;
2537 tvis.u.item.pszText = feature->Title;
2538 tvis.u.item.lParam = (LPARAM) feature;
2539
2540 hitem = (HTREEITEM) SendMessageW( hwnd, TVM_INSERTITEMW, 0, (LPARAM) &tvis );
2541 if (!hitem)
2542 continue;
2543
2544 if (!hfirst)
2545 hfirst = hitem;
2546
2547 msi_seltree_sync_item_state( hwnd, feature, hitem );
2548 msi_seltree_add_child_features( package, hwnd,
2549 feature->Feature, hitem );
2550
2551 /* the node is expanded if Display is odd */
2552 if ( feature->Display % 2 != 0 )
2553 SendMessageW( hwnd, TVM_EXPAND, TVE_EXPAND, (LPARAM) hitem );
2554 }
2555
2556 /* select the first item */
2557 SendMessageW( hwnd, TVM_SELECTITEM, TVGN_CARET | TVGN_DROPHILITE, (LPARAM) hfirst );
2558 info->selected = hfirst;
2559 }
2560
2561 static void msi_seltree_create_imagelist( HWND hwnd )
2562 {
2563 const int bm_width = 32, bm_height = 16, bm_count = 3;
2564 const int bm_resource = 0x1001;
2565 HIMAGELIST himl;
2566 int i;
2567 HBITMAP hbmp;
2568
2569 himl = ImageList_Create( bm_width, bm_height, FALSE, 4, 0 );
2570 if (!himl)
2571 {
2572 ERR("failed to create image list\n");
2573 return;
2574 }
2575
2576 for (i=0; i<bm_count; i++)
2577 {
2578 hbmp = LoadBitmapW( msi_hInstance, MAKEINTRESOURCEW(i+bm_resource) );
2579 if (!hbmp)
2580 {
2581 ERR("failed to load bitmap %d\n", i);
2582 break;
2583 }
2584
2585 /*
2586 * Add a dummy bitmap at offset zero because the treeview
2587 * can't use it as a state mask (zero means no user state).
2588 */
2589 if (!i)
2590 ImageList_Add( himl, hbmp, NULL );
2591
2592 ImageList_Add( himl, hbmp, NULL );
2593 }
2594
2595 SendMessageW( hwnd, TVM_SETIMAGELIST, TVSIL_STATE, (LPARAM)himl );
2596 }
2597
2598 static UINT msi_dialog_seltree_handler( msi_dialog *dialog,
2599 msi_control *control, WPARAM param )
2600 {
2601 struct msi_selection_tree_info *info = GetPropW( control->hwnd, szButtonData );
2602 LPNMTREEVIEWW tv = (LPNMTREEVIEWW)param;
2603 MSIRECORD *row, *rec;
2604 MSIFOLDER *folder;
2605 MSIFEATURE *feature;
2606 LPCWSTR dir, title = NULL;
2607 UINT r = ERROR_SUCCESS;
2608
2609 static const WCHAR select[] = {
2610 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2611 '`','F','e','a','t','u','r','e','`',' ','W','H','E','R','E',' ',
2612 '`','T','i','t','l','e','`',' ','=',' ','\'','%','s','\'',0
2613 };
2614
2615 if (tv->hdr.code != TVN_SELCHANGINGW)
2616 return ERROR_SUCCESS;
2617
2618 info->selected = tv->itemNew.hItem;
2619
2620 if (!(tv->itemNew.mask & TVIF_TEXT))
2621 {
2622 feature = msi_seltree_feature_from_item( control->hwnd, tv->itemNew.hItem );
2623 if (feature)
2624 title = feature->Title;
2625 }
2626 else
2627 title = tv->itemNew.pszText;
2628
2629 row = MSI_QueryGetRecord( dialog->package->db, select, title );
2630 if (!row)
2631 return ERROR_FUNCTION_FAILED;
2632
2633 rec = MSI_CreateRecord( 1 );
2634
2635 MSI_RecordSetStringW( rec, 1, MSI_RecordGetString( row, 4 ) );
2636 msi_event_fire( dialog->package, szSelectionDescription, rec );
2637
2638 dir = MSI_RecordGetString( row, 7 );
2639 if (dir)
2640 {
2641 folder = msi_get_loaded_folder( dialog->package, dir );
2642 if (!folder)
2643 {
2644 r = ERROR_FUNCTION_FAILED;
2645 goto done;
2646 }
2647 MSI_RecordSetStringW( rec, 1, folder->ResolvedTarget );
2648 }
2649 else
2650 MSI_RecordSetStringW( rec, 1, NULL );
2651
2652 msi_event_fire( dialog->package, szSelectionPath, rec );
2653
2654 done:
2655 msiobj_release(&row->hdr);
2656 msiobj_release(&rec->hdr);
2657
2658 return r;
2659 }
2660
2661 static UINT msi_dialog_selection_tree( msi_dialog *dialog, MSIRECORD *rec )
2662 {
2663 msi_control *control;
2664 LPCWSTR prop, control_name;
2665 MSIPACKAGE *package = dialog->package;
2666 DWORD style;
2667 struct msi_selection_tree_info *info;
2668
2669 info = msi_alloc( sizeof *info );
2670 if (!info)
2671 return ERROR_FUNCTION_FAILED;
2672
2673 /* create the treeview control */
2674 style = TVS_HASLINES | TVS_HASBUTTONS | TVS_LINESATROOT;
2675 style |= WS_GROUP | WS_VSCROLL | WS_TABSTOP;
2676 control = msi_dialog_add_control( dialog, rec, WC_TREEVIEWW, style );
2677 if (!control)
2678 {
2679 msi_free(info);
2680 return ERROR_FUNCTION_FAILED;
2681 }
2682
2683 control->handler = msi_dialog_seltree_handler;
2684 control_name = MSI_RecordGetString( rec, 2 );
2685 control->attributes = MSI_RecordGetInteger( rec, 8 );
2686 prop = MSI_RecordGetString( rec, 9 );
2687 control->property = msi_dialog_dup_property( dialog, prop, FALSE );
2688
2689 /* subclass */
2690 info->dialog = dialog;
2691 info->hwnd = control->hwnd;
2692 info->oldproc = (WNDPROC) SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
2693 (LONG_PTR)MSISelectionTree_WndProc );
2694 SetPropW( control->hwnd, szButtonData, info );
2695
2696 event_subscribe( dialog, szSelectionPath, control_name, szProperty );
2697
2698 /* initialize it */
2699 msi_seltree_create_imagelist( control->hwnd );
2700 msi_seltree_add_child_features( package, control->hwnd, NULL, NULL );
2701
2702 return ERROR_SUCCESS;
2703 }
2704
2705 /******************** Group Box ***************************************/
2706
2707 static UINT msi_dialog_group_box( msi_dialog *dialog, MSIRECORD *rec )
2708 {
2709 msi_control *control;
2710 DWORD style;
2711
2712 style = BS_GROUPBOX | WS_CHILD | WS_GROUP;
2713 control = msi_dialog_add_control( dialog, rec, WC_BUTTONW, style );
2714 if (!control)
2715 return ERROR_FUNCTION_FAILED;
2716
2717 return ERROR_SUCCESS;
2718 }
2719
2720 /******************** List Box ***************************************/
2721
2722 struct msi_listbox_info
2723 {
2724 msi_dialog *dialog;
2725 HWND hwnd;
2726 WNDPROC oldproc;
2727 DWORD num_items;
2728 DWORD addpos_items;
2729 LPWSTR *items;
2730 };
2731
2732 static LRESULT WINAPI MSIListBox_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
2733 {
2734 struct msi_listbox_info *info;
2735 LRESULT r;
2736 DWORD j;
2737
2738 TRACE("%p %04x %08lx %08lx\n", hWnd, msg, wParam, lParam);
2739
2740 info = GetPropW( hWnd, szButtonData );
2741 if (!info)
2742 return 0;
2743
2744 r = CallWindowProcW( info->oldproc, hWnd, msg, wParam, lParam );
2745
2746 switch( msg )
2747 {
2748 case WM_NCDESTROY:
2749 for (j = 0; j < info->num_items; j++)
2750 msi_free( info->items[j] );
2751 msi_free( info->items );
2752 msi_free( info );
2753 RemovePropW( hWnd, szButtonData );
2754 break;
2755 }
2756
2757 return r;
2758 }
2759
2760 static UINT msi_listbox_add_item( MSIRECORD *rec, LPVOID param )
2761 {
2762 struct msi_listbox_info *info = param;
2763 LPCWSTR value, text;
2764 int pos;
2765
2766 value = MSI_RecordGetString( rec, 3 );
2767 text = MSI_RecordGetString( rec, 4 );
2768
2769 info->items[info->addpos_items] = strdupW( value );
2770
2771 pos = SendMessageW( info->hwnd, LB_ADDSTRING, 0, (LPARAM)text );
2772 SendMessageW( info->hwnd, LB_SETITEMDATA, pos, (LPARAM)info->items[info->addpos_items] );
2773 info->addpos_items++;
2774 return ERROR_SUCCESS;
2775 }
2776
2777 static UINT msi_listbox_add_items( struct msi_listbox_info *info, LPCWSTR property )
2778 {
2779 static const WCHAR query[] = {
2780 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2781 '`','L','i','s','t','B','o','x','`',' ','W','H','E','R','E',' ',
2782 '`','P','r','o','p','e','r','t','y','`',' ','=',' ','\'','%','s','\'',' ',
2783 'O','R','D','E','R',' ','B','Y',' ','`','O','r','d','e','r','`',0};
2784 MSIQUERY *view;
2785 DWORD count;
2786 UINT r;
2787
2788 r = MSI_OpenQuery( info->dialog->package->db, &view, query, property );
2789 if ( r != ERROR_SUCCESS )
2790 return r;
2791
2792 /* just get the number of records */
2793 count = 0;
2794 r = MSI_IterateRecords( view, &count, NULL, NULL );
2795 if (r != ERROR_SUCCESS)
2796 {
2797 msiobj_release( &view->hdr );
2798 return r;
2799 }
2800 info->num_items = count;
2801 info->items = msi_alloc( sizeof(*info->items) * count );
2802
2803 r = MSI_IterateRecords( view, NULL, msi_listbox_add_item, info );
2804 msiobj_release( &view->hdr );
2805 return r;
2806 }
2807
2808 static UINT msi_dialog_listbox_handler( msi_dialog *dialog,
2809 msi_control *control, WPARAM param )
2810 {
2811 struct msi_listbox_info *info;
2812 int index;
2813 LPCWSTR value;
2814
2815 if( HIWORD(param) != LBN_SELCHANGE )
2816 return ERROR_SUCCESS;
2817
2818 info = GetPropW( control->hwnd, szButtonData );
2819 index = SendMessageW( control->hwnd, LB_GETCURSEL, 0, 0 );
2820 value = (LPCWSTR) SendMessageW( control->hwnd, LB_GETITEMDATA, index, 0 );
2821
2822 msi_dialog_set_property( info->dialog->package, control->property, value );
2823 msi_dialog_evaluate_control_conditions( info->dialog );
2824
2825 return ERROR_SUCCESS;
2826 }
2827
2828 static UINT msi_dialog_list_box( msi_dialog *dialog, MSIRECORD *rec )
2829 {
2830 struct msi_listbox_info *info;
2831 msi_control *control;
2832 DWORD attributes, style;
2833 LPCWSTR prop;
2834
2835 info = msi_alloc( sizeof *info );
2836 if (!info)
2837 return ERROR_FUNCTION_FAILED;
2838
2839 style = WS_TABSTOP | WS_GROUP | WS_CHILD | LBS_NOTIFY | WS_VSCROLL | WS_BORDER;
2840 attributes = MSI_RecordGetInteger( rec, 8 );
2841 if (~attributes & msidbControlAttributesSorted)
2842 style |= LBS_SORT;
2843
2844 control = msi_dialog_add_control( dialog, rec, WC_LISTBOXW, style );
2845 if (!control)
2846 {
2847 msi_free(info);
2848 return ERROR_FUNCTION_FAILED;
2849 }
2850
2851 control->handler = msi_dialog_listbox_handler;
2852
2853 prop = MSI_RecordGetString( rec, 9 );
2854 control->property = msi_dialog_dup_property( dialog, prop, FALSE );
2855
2856 /* subclass */
2857 info->dialog = dialog;
2858 info->hwnd = control->hwnd;
2859 info->items = NULL;
2860 info->addpos_items = 0;
2861 info->oldproc = (WNDPROC)SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
2862 (LONG_PTR)MSIListBox_WndProc );
2863 SetPropW( control->hwnd, szButtonData, info );
2864
2865 if ( control->property )
2866 msi_listbox_add_items( info, control->property );
2867
2868 return ERROR_SUCCESS;
2869 }
2870
2871 /******************** Directory Combo ***************************************/
2872
2873 static void msi_dialog_update_directory_combo( msi_dialog *dialog, msi_control *control )
2874 {
2875 LPWSTR prop, path;
2876 BOOL indirect;
2877
2878 if (!control && !(control = msi_dialog_find_control_by_type( dialog, szDirectoryCombo )))
2879 return;
2880
2881 indirect = control->attributes & msidbControlAttributesIndirect;
2882 prop = msi_dialog_dup_property( dialog, control->property, indirect );
2883 path = msi_dialog_dup_property( dialog, prop, TRUE );
2884
2885 PathStripPathW( path );
2886 PathRemoveBackslashW( path );
2887
2888 SendMessageW( control->hwnd, CB_INSERTSTRING, 0, (LPARAM)path );
2889 SendMessageW( control->hwnd, CB_SETCURSEL, 0, 0 );
2890
2891 msi_free( path );
2892 msi_free( prop );
2893 }
2894
2895 static UINT msi_dialog_directory_combo( msi_dialog *dialog, MSIRECORD *rec )
2896 {
2897 msi_control *control;
2898 LPCWSTR prop;
2899 DWORD style;
2900
2901 /* FIXME: use CBS_OWNERDRAWFIXED and add owner draw code */
2902 style = CBS_DROPDOWNLIST | CBS_HASSTRINGS | WS_CHILD |
2903 WS_GROUP | WS_TABSTOP | WS_VSCROLL;
2904 control = msi_dialog_add_control( dialog, rec, WC_COMBOBOXW, style );
2905 if (!control)
2906 return ERROR_FUNCTION_FAILED;
2907
2908 control->attributes = MSI_RecordGetInteger( rec, 8 );
2909 prop = MSI_RecordGetString( rec, 9 );
2910 control->property = msi_dialog_dup_property( dialog, prop, FALSE );
2911
2912 msi_dialog_update_directory_combo( dialog, control );
2913
2914 return ERROR_SUCCESS;
2915 }
2916
2917 /******************** Directory List ***************************************/
2918
2919 static void msi_dialog_update_directory_list( msi_dialog *dialog, msi_control *control )
2920 {
2921 WCHAR dir_spec[MAX_PATH];
2922 WIN32_FIND_DATAW wfd;
2923 LPWSTR prop, path;
2924 BOOL indirect;
2925 LVITEMW item;
2926 HANDLE file;
2927
2928 static const WCHAR asterisk[] = {'*',0};
2929
2930 if (!control && !(control = msi_dialog_find_control_by_type( dialog, szDirectoryList )))
2931 return;
2932
2933 /* clear the list-view */
2934 SendMessageW( control->hwnd, LVM_DELETEALLITEMS, 0, 0 );
2935
2936 indirect = control->attributes & msidbControlAttributesIndirect;
2937 prop = msi_dialog_dup_property( dialog, control->property, indirect );
2938 path = msi_dialog_dup_property( dialog, prop, TRUE );
2939
2940 lstrcpyW( dir_spec, path );
2941 lstrcatW( dir_spec, asterisk );
2942
2943 file = FindFirstFileW( dir_spec, &wfd );
2944 if ( file == INVALID_HANDLE_VALUE )
2945 return;
2946
2947 do
2948 {
2949 if ( wfd.dwFileAttributes != FILE_ATTRIBUTE_DIRECTORY )
2950 continue;
2951
2952 if ( !strcmpW( wfd.cFileName, szDot ) || !strcmpW( wfd.cFileName, szDotDot ) )
2953 continue;
2954
2955 item.mask = LVIF_TEXT;
2956 item.cchTextMax = MAX_PATH;
2957 item.iItem = 0;
2958 item.iSubItem = 0;
2959 item.pszText = wfd.cFileName;
2960
2961 SendMessageW( control->hwnd, LVM_INSERTITEMW, 0, (LPARAM)&item );
2962 } while ( FindNextFileW( file, &wfd ) );
2963
2964 msi_free( prop );
2965 msi_free( path );
2966 FindClose( file );
2967 }
2968
2969 static UINT msi_dialog_directorylist_up( msi_dialog *dialog )
2970 {
2971 msi_control *control;
2972 LPWSTR prop, path, ptr;
2973 BOOL indirect;
2974
2975 control = msi_dialog_find_control_by_type( dialog, szDirectoryList );
2976 indirect = control->attributes & msidbControlAttributesIndirect;
2977 prop = msi_dialog_dup_property( dialog, control->property, indirect );
2978 path = msi_dialog_dup_property( dialog, prop, TRUE );
2979
2980 /* strip off the last directory */
2981 ptr = PathFindFileNameW( path );
2982 if (ptr != path) *(ptr - 1) = '\0';
2983 PathAddBackslashW( path );
2984
2985 msi_dialog_set_property( dialog->package, prop, path );
2986
2987 msi_dialog_update_directory_list( dialog, NULL );
2988 msi_dialog_update_directory_combo( dialog, NULL );
2989 msi_dialog_update_pathedit( dialog, NULL );
2990
2991 msi_free( path );
2992 msi_free( prop );
2993
2994 return ERROR_SUCCESS;
2995 }
2996
2997 static UINT msi_dialog_dirlist_handler( msi_dialog *dialog,
2998 msi_control *control, WPARAM param )
2999 {
3000 LPNMHDR nmhdr = (LPNMHDR)param;
3001 WCHAR new_path[MAX_PATH];
3002 WCHAR text[MAX_PATH];
3003 LPWSTR path, prop;
3004 BOOL indirect;
3005 LVITEMW item;
3006 int index;
3007
3008 if (nmhdr->code != LVN_ITEMACTIVATE)
3009 return ERROR_SUCCESS;
3010
3011 index = SendMessageW( control->hwnd, LVM_GETNEXTITEM, -1, LVNI_SELECTED );
3012 if ( index < 0 )
3013 {
3014 ERR("No list-view item selected!\n");
3015 return ERROR_FUNCTION_FAILED;
3016 }
3017
3018 item.iSubItem = 0;
3019 item.pszText = text;
3020 item.cchTextMax = MAX_PATH;
3021 SendMessageW( control->hwnd, LVM_GETITEMTEXTW, index, (LPARAM)&item );
3022
3023 indirect = control->attributes & msidbControlAttributesIndirect;
3024 prop = msi_dialog_dup_property( dialog, control->property, indirect );
3025 path = msi_dialog_dup_property( dialog, prop, TRUE );
3026
3027 lstrcpyW( new_path, path );
3028 lstrcatW( new_path, text );
3029 lstrcatW( new_path, szBackSlash );
3030
3031 msi_dialog_set_property( dialog->package, prop, new_path );
3032
3033 msi_dialog_update_directory_list( dialog, NULL );
3034 msi_dialog_update_directory_combo( dialog, NULL );
3035 msi_dialog_update_pathedit( dialog, NULL );
3036
3037 msi_free( prop );
3038 msi_free( path );
3039 return ERROR_SUCCESS;
3040 }
3041
3042 static UINT msi_dialog_directory_list( msi_dialog *dialog, MSIRECORD *rec )
3043 {
3044 msi_control *control;
3045 LPCWSTR prop;
3046 DWORD style;
3047
3048 style = LVS_LIST | WS_VSCROLL | LVS_SHAREIMAGELISTS |
3049 LVS_AUTOARRANGE | LVS_SINGLESEL | WS_BORDER |
3050 LVS_SORTASCENDING | WS_CHILD | WS_GROUP | WS_TABSTOP;
3051 control = msi_dialog_add_control( dialog, rec, WC_LISTVIEWW, style );
3052 if (!control)
3053 return ERROR_FUNCTION_FAILED;
3054
3055 control->attributes = MSI_RecordGetInteger( rec, 8 );
3056 control->handler = msi_dialog_dirlist_handler;
3057 prop = MSI_RecordGetString( rec, 9 );
3058 control->property = msi_dialog_dup_property( dialog, prop, FALSE );
3059
3060 /* double click to activate an item in the list */
3061 SendMessageW( control->hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE,
3062 0, LVS_EX_TWOCLICKACTIVATE );
3063
3064 msi_dialog_update_directory_list( dialog, control );
3065
3066 return ERROR_SUCCESS;
3067 }
3068
3069 /******************** VolumeCost List ***************************************/
3070
3071 static BOOL str_is_number( LPCWSTR str )
3072 {
3073 int i;
3074
3075 for (i = 0; i < lstrlenW( str ); i++)
3076 if (!isdigitW(str[i]))
3077 return FALSE;
3078
3079 return TRUE;
3080 }
3081
3082 static const WCHAR column_keys[][80] =
3083 {
3084 {'V','o','l','u','m','e','C','o','s','t','V','o','l','u','m','e',0},
3085 {'V','o','l','u','m','e','C','o','s','t','S','i','z','e',0},
3086 {'V','o','l','u','m','e','C','o','s','t','A','v','a','i','l','a','b','l','e',0},
3087 {'V','o','l','u','m','e','C','o','s','t','R','e','q','u','i','r','e','d',0},
3088 {'V','o','l','u','m','e','C','o','s','t','D','i','f','f','e','r','e','n','c','e',0}
3089 };
3090
3091 static void msi_dialog_vcl_add_columns( msi_dialog *dialog, msi_control *control, MSIRECORD *rec )
3092 {
3093 LPCWSTR text = MSI_RecordGetString( rec, 10 );
3094 LPCWSTR begin = text, end;
3095 WCHAR *num;
3096 LVCOLUMNW lvc;
3097 DWORD count = 0;
3098
3099 static const WCHAR negative[] = {'-',0};
3100
3101 if (!text) return;
3102
3103 while ((begin = strchrW( begin, '{' )) && count < 5)
3104 {
3105 if (!(end = strchrW( begin, '}' )))
3106 return;
3107
3108 num = msi_alloc( (end-begin+1)*sizeof(WCHAR) );
3109 if (!num)
3110 return;
3111
3112 lstrcpynW( num, begin + 1, end - begin );
3113 begin += end - begin + 1;
3114
3115 /* empty braces or '0' hides the column */
3116 if ( !num[0] || !strcmpW( num, szZero ) )
3117 {
3118 count++;
3119 msi_free( num );
3120 continue;
3121 }
3122
3123 /* the width must be a positive number
3124 * if a width is invalid, all remaining columns are hidden
3125 */
3126 if ( !strncmpW( num, negative, 1 ) || !str_is_number( num ) ) {
3127 msi_free( num );
3128 return;
3129 }
3130
3131 ZeroMemory( &lvc, sizeof(lvc) );
3132 lvc.mask = LVCF_TEXT | LVCF_WIDTH | LVCF_SUBITEM;
3133 lvc.cx = atolW( num );
3134 lvc.pszText = msi_dialog_get_uitext( dialog, column_keys[count] );
3135
3136 SendMessageW( control->hwnd, LVM_INSERTCOLUMNW, count++, (LPARAM)&lvc );
3137 msi_free( lvc.pszText );
3138 msi_free( num );
3139 }
3140 }
3141
3142 static LONGLONG msi_vcl_get_cost( msi_dialog *dialog )
3143 {
3144 MSIFEATURE *feature;
3145 INT each_cost;
3146 LONGLONG total_cost = 0;
3147
3148 LIST_FOR_EACH_ENTRY( feature, &dialog->package->features, MSIFEATURE, entry )
3149 {
3150 if (ERROR_SUCCESS == (MSI_GetFeatureCost(dialog->package, feature,
3151 MSICOSTTREE_SELFONLY, INSTALLSTATE_LOCAL, &each_cost)))
3152 {
3153 /* each_cost is in 512-byte units */
3154 total_cost += each_cost * 512;
3155 }
3156 if (ERROR_SUCCESS == (MSI_GetFeatureCost(dialog->package, feature,
3157 MSICOSTTREE_SELFONLY, INSTALLSTATE_ABSENT, &each_cost)))
3158 {
3159 /* each_cost is in 512-byte units */
3160 total_cost -= each_cost * 512;
3161 }
3162 }
3163 return total_cost;
3164 }
3165
3166 static void msi_dialog_vcl_add_drives( msi_dialog *dialog, msi_control *control )
3167 {
3168 ULARGE_INTEGER total, free;
3169 LONGLONG difference, cost;
3170 WCHAR size_text[MAX_PATH];
3171 WCHAR cost_text[MAX_PATH];
3172 LPWSTR drives, ptr;
3173 LVITEMW lvitem;
3174 DWORD size;
3175 int i = 0;
3176
3177 cost = msi_vcl_get_cost(dialog);
3178 StrFormatByteSizeW(cost, cost_text, MAX_PATH);
3179
3180 size = GetLogicalDriveStringsW( 0, NULL );
3181 if ( !size ) return;
3182
3183 drives = msi_alloc( (size + 1) * sizeof(WCHAR) );
3184 if ( !drives ) return;
3185
3186 GetLogicalDriveStringsW( size, drives );
3187
3188 ptr = drives;
3189 while (*ptr)
3190 {
3191 lvitem.mask = LVIF_TEXT;
3192 lvitem.iItem = i;
3193 lvitem.iSubItem = 0;
3194 lvitem.pszText = ptr;
3195 lvitem.cchTextMax = lstrlenW(ptr) + 1;
3196 SendMessageW( control->hwnd, LVM_INSERTITEMW, 0, (LPARAM)&lvitem );
3197
3198 GetDiskFreeSpaceExW(ptr, &free, &total, NULL);
3199 difference = free.QuadPart - cost;
3200
3201 StrFormatByteSizeW(total.QuadPart, size_text, MAX_PATH);
3202 lvitem.iSubItem = 1;
3203 lvitem.pszText = size_text;
3204 lvitem.cchTextMax = lstrlenW(size_text) + 1;
3205 SendMessageW( control->hwnd, LVM_SETITEMW, 0, (LPARAM)&lvitem );
3206
3207 StrFormatByteSizeW(free.QuadPart, size_text, MAX_PATH);
3208 lvitem.iSubItem = 2;
3209 lvitem.pszText = size_text;
3210 lvitem.cchTextMax = lstrlenW(size_text) + 1;
3211 SendMessageW( control->hwnd, LVM_SETITEMW, 0, (LPARAM)&lvitem );
3212
3213 lvitem.iSubItem = 3;
3214 lvitem.pszText = cost_text;
3215 lvitem.cchTextMax = lstrlenW(cost_text) + 1;
3216 SendMessageW( control->hwnd, LVM_SETITEMW, 0, (LPARAM)&lvitem );
3217
3218 StrFormatByteSizeW(difference, size_text, MAX_PATH);
3219 lvitem.iSubItem = 4;
3220 lvitem.pszText = size_text;
3221 lvitem.cchTextMax = lstrlenW(size_text) + 1;
3222 SendMessageW( control->hwnd, LVM_SETITEMW, 0, (LPARAM)&lvitem );
3223
3224 ptr += lstrlenW(ptr) + 1;
3225 i++;
3226 }
3227
3228 msi_free( drives );
3229 }
3230
3231 static UINT msi_dialog_volumecost_list( msi_dialog *dialog, MSIRECORD *rec )
3232 {
3233 msi_control *control;
3234 DWORD style;
3235
3236 style = LVS_REPORT | WS_VSCROLL | WS_HSCROLL | LVS_SHAREIMAGELISTS |
3237 LVS_AUTOARRANGE | LVS_SINGLESEL | WS_BORDER |
3238 WS_CHILD | WS_TABSTOP | WS_GROUP;
3239 control = msi_dialog_add_control( dialog, rec, WC_LISTVIEWW, style );
3240 if (!control)
3241 return ERROR_FUNCTION_FAILED;
3242
3243 msi_dialog_vcl_add_columns( dialog, control, rec );
3244 msi_dialog_vcl_add_drives( dialog, control );
3245
3246 return ERROR_SUCCESS;
3247 }
3248
3249 /******************** VolumeSelect Combo ***************************************/
3250
3251 static UINT msi_dialog_volsel_handler( msi_dialog *dialog,
3252 msi_control *control, WPARAM param )
3253 {
3254 WCHAR text[MAX_PATH];
3255 LPWSTR prop;
3256 BOOL indirect;
3257 int index;
3258
3259 if (HIWORD(param) != CBN_SELCHANGE)
3260 return ERROR_SUCCESS;
3261
3262 index = SendMessageW( control->hwnd, CB_GETCURSEL, 0, 0 );
3263 if ( index == CB_ERR )
3264 {
3265 ERR("No ComboBox item selected!\n");
3266 return ERROR_FUNCTION_FAILED;
3267 }
3268
3269 SendMessageW( control->hwnd, CB_GETLBTEXT, index, (LPARAM)text );
3270
3271 indirect = control->attributes & msidbControlAttributesIndirect;
3272 prop = msi_dialog_dup_property( dialog, control->property, indirect );
3273
3274 msi_dialog_set_property( dialog->package, prop, text );
3275
3276 msi_free( prop );
3277 return ERROR_SUCCESS;
3278 }
3279
3280 static void msi_dialog_vsc_add_drives( msi_dialog *dialog, msi_control *control )
3281 {
3282 LPWSTR drives, ptr;
3283 DWORD size;
3284
3285 size = GetLogicalDriveStringsW( 0, NULL );
3286 if ( !size ) return;
3287
3288 drives = msi_alloc( (size + 1) * sizeof(WCHAR) );
3289 if ( !drives ) return;
3290
3291 GetLogicalDriveStringsW( size, drives );
3292
3293 ptr = drives;
3294 while (*ptr)
3295 {
3296 SendMessageW( control->hwnd, CB_ADDSTRING, 0, (LPARAM)ptr );
3297 ptr += lstrlenW(ptr) + 1;
3298 }
3299
3300 msi_free( drives );
3301 }
3302
3303 static UINT msi_dialog_volumeselect_combo( msi_dialog *dialog, MSIRECORD *rec )
3304 {
3305 msi_control *control;
3306 LPCWSTR prop;
3307 DWORD style;
3308
3309 /* FIXME: CBS_OWNERDRAWFIXED */
3310 style = WS_CHILD | WS_VISIBLE | WS_GROUP | WS_TABSTOP |
3311 CBS_DROPDOWNLIST | CBS_SORT | CBS_HASSTRINGS |
3312 WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_RIGHTSCROLLBAR;
3313 control = msi_dialog_add_control( dialog, rec, WC_COMBOBOXW, style );
3314 if (!control)
3315 return ERROR_FUNCTION_FAILED;
3316
3317 control->attributes = MSI_RecordGetInteger( rec, 8 );
3318 control->handler = msi_dialog_volsel_handler;
3319 prop = MSI_RecordGetString( rec, 9 );
3320 control->property = msi_dialog_dup_property( dialog, prop, FALSE );
3321
3322 msi_dialog_vsc_add_drives( dialog, control );
3323
3324 return ERROR_SUCCESS;
3325 }
3326
3327 static UINT msi_dialog_hyperlink_handler( msi_dialog *dialog, msi_control *control, WPARAM param )
3328 {
3329 static const WCHAR hrefW[] = {'h','r','e','f'};
3330 static const WCHAR openW[] = {'o','p','e','n',0};
3331 int len, len_href = sizeof(hrefW) / sizeof(hrefW[0]);
3332 const WCHAR *p, *q;
3333 WCHAR quote = 0;
3334 LITEM item;
3335
3336 item.mask = LIF_ITEMINDEX | LIF_URL;
3337 item.iLink = 0;
3338 item.szUrl[0] = 0;
3339
3340 SendMessageW( control->hwnd, LM_GETITEM, 0, (LPARAM)&item );
3341
3342 p = item.szUrl;
3343 while (*p && *p != '<') p++;
3344 if (!*p++) return ERROR_SUCCESS;
3345 if (toupperW( *p++ ) != 'A' || !isspaceW( *p++ )) return ERROR_SUCCESS;
3346 while (*p && isspaceW( *p )) p++;
3347
3348 len = strlenW( p );
3349 if (len > len_href && !memicmpW( p, hrefW, len_href ))
3350 {
3351 p += len_href;
3352 while (*p && isspaceW( *p )) p++;
3353 if (!*p || *p++ != '=') return ERROR_SUCCESS;
3354 while (*p && isspaceW( *p )) p++;
3355
3356 if (*p == '\"' || *p == '\'') quote = *p++;
3357 q = p;
3358 if (quote)
3359 {
3360 while (*q && *q != quote) q++;
3361 if (*q != quote) return ERROR_SUCCESS;
3362 }
3363 else
3364 {
3365 while (*q && *q != '>' && !isspaceW( *q )) q++;
3366 if (!*q) return ERROR_SUCCESS;
3367 }
3368 item.szUrl[q - item.szUrl] = 0;
3369 ShellExecuteW( NULL, openW, p, NULL, NULL, SW_SHOWNORMAL );
3370 }
3371 return ERROR_SUCCESS;
3372 }
3373
3374 static UINT msi_dialog_hyperlink( msi_dialog *dialog, MSIRECORD *rec )
3375 {
3376 msi_control *control;
3377 DWORD style = WS_CHILD | WS_TABSTOP | WS_GROUP;
3378 const WCHAR *text = MSI_RecordGetString( rec, 10 );
3379 int len = strlenW( text );
3380 LITEM item;
3381
3382 control = msi_dialog_add_control( dialog, rec, WC_LINK, style );
3383 if (!control)
3384 return ERROR_FUNCTION_FAILED;
3385
3386 control->attributes = MSI_RecordGetInteger( rec, 8 );
3387 control->handler = msi_dialog_hyperlink_handler;
3388
3389 item.mask = LIF_ITEMINDEX | LIF_STATE | LIF_URL;
3390 item.iLink = 0;
3391 item.state = LIS_ENABLED;
3392 item.stateMask = LIS_ENABLED;
3393 if (len < L_MAX_URL_LENGTH) strcpyW( item.szUrl, text );
3394 else item.szUrl[0] = 0;
3395
3396 SendMessageW( control->hwnd, LM_SETITEM, 0, (LPARAM)&item );
3397
3398 return ERROR_SUCCESS;
3399 }
3400
3401 static const struct control_handler msi_dialog_handler[] =
3402 {
3403 { szText, msi_dialog_text_control },
3404 { szPushButton, msi_dialog_button_control },
3405 { szLine, msi_dialog_line_control },
3406 { szBitmap, msi_dialog_bitmap_control },
3407 { szCheckBox, msi_dialog_checkbox_control },
3408 { szScrollableText, msi_dialog_scrolltext_control },
3409 { szComboBox, msi_dialog_combo_control },
3410 { szEdit, msi_dialog_edit_control },
3411 { szMaskedEdit, msi_dialog_maskedit_control },
3412 { szPathEdit, msi_dialog_pathedit_control },
3413 { szProgressBar, msi_dialog_progress_bar },
3414 { szRadioButtonGroup, msi_dialog_radiogroup_control },
3415 { szIcon, msi_dialog_icon_control },
3416 { szSelectionTree, msi_dialog_selection_tree },
3417 { szGroupBox, msi_dialog_group_box },
3418 { szListBox, msi_dialog_list_box },
3419 { szDirectoryCombo, msi_dialog_directory_combo },
3420 { szDirectoryList, msi_dialog_directory_list },
3421 { szVolumeCostList, msi_dialog_volumecost_list },
3422 { szVolumeSelectCombo, msi_dialog_volumeselect_combo },
3423 { szHyperLink, msi_dialog_hyperlink }
3424 };
3425
3426 #define NUM_CONTROL_TYPES (sizeof msi_dialog_handler/sizeof msi_dialog_handler[0])
3427
3428 static UINT msi_dialog_create_controls( MSIRECORD *rec, LPVOID param )
3429 {
3430 msi_dialog *dialog = param;
3431 LPCWSTR control_type;
3432 UINT i;
3433
3434 /* find and call the function that can create this type of control */
3435 control_type = MSI_RecordGetString( rec, 3 );
3436 for( i=0; i<NUM_CONTROL_TYPES; i++ )
3437 if (!strcmpiW( msi_dialog_handler[i].control_type, control_type ))
3438 break;
3439 if( i != NUM_CONTROL_TYPES )
3440 msi_dialog_handler[i].func( dialog, rec );
3441 else
3442 ERR("no handler for element type %s\n", debugstr_w(control_type));
3443
3444 return ERROR_SUCCESS;
3445 }
3446
3447 static UINT msi_dialog_fill_controls( msi_dialog *dialog )
3448 {
3449 static const WCHAR query[] = {
3450 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
3451 'C','o','n','t','r','o','l',' ','W','H','E','R','E',' ',
3452 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',0};
3453 UINT r;
3454 MSIQUERY *view;
3455 MSIPACKAGE *package = dialog->package;
3456
3457 TRACE("%p %s\n", dialog, debugstr_w(dialog->name) );
3458
3459 /* query the Control table for all the elements of the control */
3460 r = MSI_OpenQuery( package->db, &view, query, dialog->name );
3461 if( r != ERROR_SUCCESS )
3462 {
3463 ERR("query failed for dialog %s\n", debugstr_w(dialog->name));
3464 return ERROR_INVALID_PARAMETER;
3465 }
3466
3467 r = MSI_IterateRecords( view, 0, msi_dialog_create_controls, dialog );
3468 msiobj_release( &view->hdr );
3469 return r;
3470 }
3471
3472 static UINT msi_dialog_reset( msi_dialog *dialog )
3473 {
3474 /* FIXME: should restore the original values of any properties we changed */
3475 return msi_dialog_evaluate_control_conditions( dialog );
3476 }
3477
3478 /* figure out the height of 10 point MS Sans Serif */
3479 static INT msi_dialog_get_sans_serif_height( HWND hwnd )
3480 {
3481 static const WCHAR szSansSerif[] = {
3482 'M','S',' ','S','a','n','s',' ','S','e','r','i','f',0 };
3483 LOGFONTW lf;
3484 TEXTMETRICW tm;
3485 BOOL r;
3486 LONG height = 0;
3487 HFONT hFont, hOldFont;
3488 HDC hdc;
3489
3490 hdc = GetDC( hwnd );
3491 if (hdc)
3492 {
3493 memset( &lf, 0, sizeof lf );
3494 lf.lfHeight = MulDiv(12, GetDeviceCaps(hdc, LOGPIXELSY), 72);
3495 strcpyW( lf.lfFaceName, szSansSerif );
3496 hFont = CreateFontIndirectW(&lf);
3497 if (hFont)
3498 {
3499 hOldFont = SelectObject( hdc, hFont );
3500 r = GetTextMetricsW( hdc, &tm );
3501 if (r)
3502 height = tm.tmHeight;
3503 SelectObject( hdc, hOldFont );
3504 DeleteObject( hFont );
3505 }
3506 ReleaseDC( hwnd, hdc );
3507 }
3508 return height;
3509 }
3510
3511 /* fetch the associated record from the Dialog table */
3512 static MSIRECORD *msi_get_dialog_record( msi_dialog *dialog )
3513 {
3514 static const WCHAR query[] = {
3515 'S','E','L','E','C','T',' ','*',' ',
3516 'F','R','O','M',' ','D','i','a','l','o','g',' ',
3517 'W','H','E','R','E',' ',
3518 '`','D','i','a','l','o','g','`',' ','=',' ','\'','%','s','\'',0};
3519 MSIPACKAGE *package = dialog->package;
3520 MSIRECORD *rec = NULL;
3521
3522 TRACE("%p %s\n", dialog, debugstr_w(dialog->name) );
3523
3524 rec = MSI_QueryGetRecord( package->db, query, dialog->name );
3525 if( !rec )
3526 WARN("query failed for dialog %s\n", debugstr_w(dialog->name));
3527
3528 return rec;
3529 }
3530
3531 static void msi_dialog_adjust_dialog_pos( msi_dialog *dialog, MSIRECORD *rec, LPRECT pos )
3532 {
3533 static const WCHAR szScreenX[] = {'S','c','r','e','e','n','X',0};
3534 static const WCHAR szScreenY[] = {'S','c','r','e','e','n','Y',0};
3535
3536 UINT xres, yres;
3537 POINT center;
3538 SIZE sz;
3539 LONG style;
3540
3541 center.x = MSI_RecordGetInteger( rec, 2 );
3542 center.y = MSI_RecordGetInteger( rec, 3 );
3543
3544 sz.cx = MSI_RecordGetInteger( rec, 4 );
3545 sz.cy = MSI_RecordGetInteger( rec, 5 );
3546
3547 sz.cx = msi_dialog_scale_unit( dialog, sz.cx );
3548 sz.cy = msi_dialog_scale_unit( dialog, sz.cy );
3549
3550 xres = msi_get_property_int( dialog->package->db, szScreenX, 0 );
3551 yres = msi_get_property_int( dialog->package->db, szScreenY, 0 );
3552
3553 center.x = MulDiv( center.x, xres, 100 );
3554 center.y = MulDiv( center.y, yres, 100 );
3555
3556 /* turn the client pos into the window rectangle */
3557 if (dialog->package->center_x && dialog->package->center_y)
3558 {
3559 pos->left = dialog->package->center_x - sz.cx / 2.0;
3560 pos->right = pos->left + sz.cx;
3561 pos->top = dialog->package->center_y - sz.cy / 2.0;
3562 pos->bottom = pos->top + sz.cy;
3563 }
3564 else
3565 {
3566 pos->left = center.x - sz.cx/2;
3567 pos->right = pos->left + sz.cx;
3568 pos->top = center.y - sz.cy/2;
3569 pos->bottom = pos->top + sz.cy;
3570
3571 /* save the center */
3572 dialog->package->center_x = center.x;
3573 dialog->package->center_y = center.y;
3574 }
3575
3576 dialog->size.cx = sz.cx;
3577 dialog->size.cy = sz.cy;
3578
3579 TRACE("%u %u %u %u\n", pos->left, pos->top, pos->right, pos->bottom);
3580
3581 style = GetWindowLongPtrW( dialog->hwnd, GWL_STYLE );
3582 AdjustWindowRect( pos, style, FALSE );
3583 }
3584
3585 static void msi_dialog_set_tab_order( msi_dialog *dialog, LPCWSTR first )
3586 {
3587 struct list tab_chain;
3588 msi_control *control;
3589 HWND prev = HWND_TOP;
3590
3591 list_init( &tab_chain );
3592 if (!(control = msi_dialog_find_control( dialog, first ))) return;
3593
3594 dialog->hWndFocus = control->hwnd;
3595 while (control)
3596 {
3597 list_remove( &control->entry );
3598 list_add_tail( &tab_chain, &control->entry );
3599 if (!control->tabnext) break;
3600 control = msi_dialog_find_control( dialog, control->tabnext );
3601 }
3602
3603 LIST_FOR_EACH_ENTRY( control, &tab_chain, msi_control, entry )
3604 {
3605 SetWindowPos( control->hwnd, prev, 0, 0, 0, 0,
3606 SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOREDRAW |
3607 SWP_NOREPOSITION | SWP_NOSENDCHANGING | SWP_NOSIZE );
3608 prev = control->hwnd;
3609 }
3610
3611 /* put them back on the main list */
3612 list_move_head( &dialog->controls, &tab_chain );
3613 }
3614
3615 static LRESULT msi_dialog_oncreate( HWND hwnd, LPCREATESTRUCTW cs )
3616 {
3617 static const WCHAR df[] = {
3618 'D','e','f','a','u','l','t','U','I','F','o','n','t',0 };
3619 static const WCHAR dfv[] = {
3620 'M','S',' ','S','h','e','l','l',' ','D','l','g',0 };
3621 msi_dialog *dialog = cs->lpCreateParams;
3622 MSIRECORD *rec = NULL;
3623 LPWSTR title = NULL;
3624 RECT pos;
3625
3626 TRACE("%p %p\n", dialog, dialog->package);
3627
3628 dialog->hwnd = hwnd;
3629 SetWindowLongPtrW( hwnd, GWLP_USERDATA, (LONG_PTR) dialog );
3630
3631 rec = msi_get_dialog_record( dialog );
3632 if( !rec )
3633 {
3634 TRACE("No record found for dialog %s\n", debugstr_w(dialog->name));
3635 return -1;
3636 }
3637
3638 dialog->scale = msi_dialog_get_sans_serif_height(dialog->hwnd);
3639
3640 msi_dialog_adjust_dialog_pos( dialog, rec, &pos );
3641
3642 dialog->attributes = MSI_RecordGetInteger( rec, 6 );
3643
3644 dialog->default_font = msi_dup_property( dialog->package->db, df );
3645 if (!dialog->default_font)
3646 {
3647 dialog->default_font = strdupW(dfv);
3648 if (!dialog->default_font)
3649 {
3650 msiobj_release( &rec->hdr );
3651 return -1;
3652 }
3653 }
3654
3655 title = msi_get_deformatted_field( dialog->package, rec, 7 );
3656 SetWindowTextW( hwnd, title );
3657 msi_free( title );
3658
3659 SetWindowPos( hwnd, 0, pos.left, pos.top,
3660 pos.right - pos.left, pos.bottom - pos.top,
3661 SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOREDRAW );
3662
3663 msi_dialog_build_font_list( dialog );
3664 msi_dialog_fill_controls( dialog );
3665 msi_dialog_evaluate_control_conditions( dialog );
3666 msi_dialog_set_tab_order( dialog, MSI_RecordGetString( rec, 8 ) );
3667 msiobj_release( &rec->hdr );
3668
3669 return 0;
3670 }
3671
3672 static LRESULT msi_dialog_oncommand( msi_dialog *dialog, WPARAM param, HWND hwnd )
3673 {
3674 msi_control *control = NULL;
3675
3676 TRACE("%p %p %08lx\n", dialog, hwnd, param);
3677
3678 switch (param)
3679 {
3680 case 1: /* enter */
3681 control = msi_dialog_find_control( dialog, dialog->control_default );
3682 break;
3683 case 2: /* escape */
3684 control = msi_dialog_find_control( dialog, dialog->control_cancel );
3685 break;
3686 default:
3687 control = msi_dialog_find_control_by_hwnd( dialog, hwnd );
3688 }
3689
3690 if( control )
3691 {
3692 if( control->handler )
3693 {
3694 control->handler( dialog, control, param );
3695 msi_dialog_evaluate_control_conditions( dialog );
3696 }
3697 }
3698
3699 return 0;
3700 }
3701
3702 static LRESULT msi_dialog_onnotify( msi_dialog *dialog, LPARAM param )
3703 {
3704 LPNMHDR nmhdr = (LPNMHDR) param;
3705 msi_control *control = msi_dialog_find_control_by_hwnd( dialog, nmhdr->hwndFrom );
3706
3707 TRACE("%p %p\n", dialog, nmhdr->hwndFrom);
3708
3709 if ( control && control->handler )
3710 control->handler( dialog, control, param );
3711
3712 return 0;
3713 }
3714
3715 static void dialog_setfocus( msi_dialog *dialog )
3716 {
3717 HWND hwnd = dialog->hWndFocus;
3718
3719 hwnd = GetNextDlgTabItem( dialog->hwnd, hwnd, TRUE);
3720 hwnd = GetNextDlgTabItem( dialog->hwnd, hwnd, FALSE);
3721 SetFocus( hwnd );
3722 dialog->hWndFocus = hwnd;
3723 }
3724
3725 static LRESULT WINAPI MSIDialog_WndProc( HWND hwnd, UINT msg,
3726 WPARAM wParam, LPARAM lParam )
3727 {
3728 msi_dialog *dialog = (LPVOID) GetWindowLongPtrW( hwnd, GWLP_USERDATA );
3729
3730 TRACE("0x%04x\n", msg);
3731
3732 switch (msg)
3733 {
3734 case WM_MOVE:
3735 dialog->package->center_x = LOWORD(lParam) + dialog->size.cx / 2.0;
3736 dialog->package->center_y = HIWORD(lParam) + dialog->size.cy / 2.0;
3737 break;
3738
3739 case WM_CREATE:
3740 return msi_dialog_oncreate( hwnd, (LPCREATESTRUCTW)lParam );
3741
3742 case WM_COMMAND:
3743 return msi_dialog_oncommand( dialog, wParam, (HWND)lParam );
3744
3745 case WM_ACTIVATE:
3746 if( LOWORD(wParam) == WA_INACTIVE )
3747 dialog->hWndFocus = GetFocus();
3748 else
3749 dialog_setfocus( dialog );
3750 return 0;
3751
3752 case WM_SETFOCUS:
3753 dialog_setfocus( dialog );
3754 return 0;
3755
3756 /* bounce back to our subclassed static control */
3757 case WM_CTLCOLORSTATIC:
3758 return SendMessageW( (HWND) lParam, WM_CTLCOLORSTATIC, wParam, lParam );
3759
3760 case WM_DESTROY:
3761 dialog->hwnd = NULL;
3762 return 0;
3763 case WM_NOTIFY:
3764 return msi_dialog_onnotify( dialog, lParam );
3765 }
3766 return DefWindowProcW(hwnd, msg, wParam, lParam);
3767 }
3768
3769 static void process_pending_messages( HWND hdlg )
3770 {
3771 MSG msg;
3772
3773 while (PeekMessageW( &msg, 0, 0, 0, PM_REMOVE ))
3774 {
3775 if (hdlg && IsDialogMessageW( hdlg, &msg )) continue;
3776 TranslateMessage( &msg );
3777 DispatchMessageW( &msg );
3778 }
3779 }
3780
3781 static UINT dialog_run_message_loop( msi_dialog *dialog )
3782 {
3783 DWORD style;
3784 HWND hwnd;
3785
3786 if( uiThreadId != GetCurrentThreadId() )
3787 return SendMessageW( hMsiHiddenWindow, WM_MSI_DIALOG_CREATE, 0, (LPARAM) dialog );
3788
3789 /* create the dialog window, don't show it yet */
3790 style = WS_OVERLAPPED;
3791 if( dialog->attributes & msidbDialogAttributesVisible )
3792 style |= WS_VISIBLE;
3793
3794 hwnd = CreateWindowW( szMsiDialogClass, dialog->name, style,
3795 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
3796 NULL, NULL, NULL, dialog );
3797 if( !hwnd )
3798 {
3799 ERR("Failed to create dialog %s\n", debugstr_w( dialog->name ));
3800 return ERROR_FUNCTION_FAILED;
3801 }
3802
3803 ShowWindow( hwnd, SW_SHOW );
3804 /* UpdateWindow( hwnd ); - and causes the transparent static controls not to paint */
3805
3806 if( dialog->attributes & msidbDialogAttributesModal )
3807 {
3808 while( !dialog->finished )
3809 {
3810 MsgWaitForMultipleObjects( 0, NULL, 0, INFINITE, QS_ALLINPUT );
3811 process_pending_messages( dialog->hwnd );
3812 }
3813 }
3814 else
3815 return ERROR_IO_PENDING;
3816
3817 return ERROR_SUCCESS;
3818 }
3819
3820 static LRESULT WINAPI MSIHiddenWindowProc( HWND hwnd, UINT msg,
3821 WPARAM wParam, LPARAM lParam )
3822 {
3823 msi_dialog *dialog = (msi_dialog*) lParam;
3824
3825 TRACE("%d %p\n", msg, dialog);
3826
3827 switch (msg)
3828 {
3829 case WM_MSI_DIALOG_CREATE:
3830 return dialog_run_message_loop( dialog );
3831 case WM_MSI_DIALOG_DESTROY:
3832 msi_dialog_destroy( dialog );
3833 return 0;
3834 }
3835 return DefWindowProcW( hwnd, msg, wParam, lParam );
3836 }
3837
3838 static BOOL dialog_register_class( void )
3839 {
3840 WNDCLASSW cls;
3841
3842 ZeroMemory( &cls, sizeof cls );
3843 cls.lpfnWndProc = MSIDialog_WndProc;
3844 cls.hInstance = NULL;
3845 cls.hIcon = LoadIconW(0, (LPWSTR)IDI_APPLICATION);
3846 cls.hCursor = LoadCursorW(0, (LPWSTR)IDC_ARROW);
3847 cls.hbrBackground = (HBRUSH)(COLOR_3DFACE + 1);
3848 cls.lpszMenuName = NULL;
3849 cls.lpszClassName = szMsiDialogClass;
3850
3851 if( !RegisterClassW( &cls ) )
3852 return FALSE;
3853
3854 cls.lpfnWndProc = MSIHiddenWindowProc;
3855 cls.lpszClassName = szMsiHiddenWindow;
3856
3857 if( !RegisterClassW( &cls ) )
3858 return FALSE;
3859
3860 uiThreadId = GetCurrentThreadId();
3861
3862 hMsiHiddenWindow = CreateWindowW( szMsiHiddenWindow, NULL, WS_OVERLAPPED,
3863 0, 0, 100, 100, NULL, NULL, NULL, NULL );
3864 if( !hMsiHiddenWindow )
3865 return FALSE;
3866
3867 return TRUE;
3868 }
3869
3870 static msi_dialog *dialog_create( MSIPACKAGE *package, const WCHAR *name, msi_dialog *parent,
3871 control_event_handler event_handler )
3872 {
3873 MSIRECORD *rec = NULL;
3874 msi_dialog *dialog;
3875
3876 TRACE("%s\n", debugstr_w(name));
3877
3878 if (!hMsiHiddenWindow) dialog_register_class();
3879
3880 /* allocate the structure for the dialog to use */
3881 dialog = msi_alloc_zero( FIELD_OFFSET( msi_dialog, name[strlenW( name ) + 1] ));
3882 if( !dialog )
3883 return NULL;
3884 strcpyW( dialog->name, name );
3885 dialog->parent = parent;
3886 msiobj_addref( &package->hdr );
3887 dialog->package = package;
3888 dialog->event_handler = event_handler;
3889 dialog->finished = 0;
3890 list_init( &dialog->controls );
3891 list_init( &dialog->fonts );
3892
3893 /* verify that the dialog exists */
3894 rec = msi_get_dialog_record( dialog );
3895 if( !rec )
3896 {
3897 msiobj_release( &package->hdr );
3898 msi_free( dialog );
3899 return NULL;
3900 }
3901 dialog->attributes = MSI_RecordGetInteger( rec, 6 );
3902 dialog->control_default = strdupW( MSI_RecordGetString( rec, 9 ) );
3903 dialog->control_cancel = strdupW( MSI_RecordGetString( rec, 10 ) );
3904 msiobj_release( &rec->hdr );
3905
3906 return dialog;
3907 }
3908
3909 static void msi_dialog_end_dialog( msi_dialog *dialog )
3910 {
3911 TRACE("%p\n", dialog);
3912 dialog->finished = 1;
3913 PostMessageW(dialog->hwnd, WM_NULL, 0, 0);
3914 }
3915
3916 void msi_dialog_check_messages( HANDLE handle )
3917 {
3918 DWORD r;
3919
3920 /* in threads other than the UI thread, block */
3921 if( uiThreadId != GetCurrentThreadId() )
3922 {
3923 if (!handle) return;
3924 while (MsgWaitForMultipleObjectsEx( 1, &handle, INFINITE, QS_ALLINPUT, 0 ) == WAIT_OBJECT_0 + 1)
3925 {
3926 MSG msg;
3927 while (PeekMessageW( &msg, NULL, 0, 0, PM_REMOVE ))
3928 {
3929 TranslateMessage( &msg );
3930 DispatchMessageW( &msg );
3931 }
3932 }
3933 return;
3934 }
3935
3936 /* there are two choices for the UI thread */
3937 while (1)
3938 {
3939 process_pending_messages( NULL );
3940
3941 if( !handle )
3942 break;
3943
3944 /*
3945 * block here until somebody creates a new dialog or
3946 * the handle we're waiting on becomes ready
3947 */
3948 r = MsgWaitForMultipleObjects( 1, &handle, 0, INFINITE, QS_ALLINPUT );
3949 if( r == WAIT_OBJECT_0 )
3950 break;
3951 }
3952 }
3953
3954 static void dialog_do_preview( msi_dialog *dialog )
3955 {
3956 TRACE("\n");
3957 dialog->attributes |= msidbDialogAttributesVisible;
3958 dialog->attributes &= ~msidbDialogAttributesModal;
3959 dialog_run_message_loop( dialog );
3960 }
3961
3962 static void free_subscriber( struct subscriber *sub )
3963 {
3964 msi_free( sub->event );
3965 msi_free( sub->control );
3966 msi_free( sub->attribute );
3967 msi_free( sub );
3968 }
3969
3970 static void event_cleanup_subscriptions( MSIPACKAGE *package, const WCHAR *dialog )
3971 {
3972 struct list *item, *next;
3973
3974 LIST_FOR_EACH_SAFE( item, next, &package->subscriptions )
3975 {
3976 struct subscriber *sub = LIST_ENTRY( item, struct subscriber, entry );
3977
3978 if (strcmpW( sub->dialog->name, dialog )) continue;
3979 list_remove( &sub->entry );
3980 free_subscriber( sub );
3981 }
3982 }
3983
3984 void msi_dialog_destroy( msi_dialog *dialog )
3985 {
3986 msi_font *font, *next;
3987
3988 if( uiThreadId != GetCurrentThreadId() )
3989 {
3990 SendMessageW( hMsiHiddenWindow, WM_MSI_DIALOG_DESTROY, 0, (LPARAM) dialog );
3991 return;
3992 }
3993
3994 if( dialog->hwnd )
3995 ShowWindow( dialog->hwnd, SW_HIDE );
3996
3997 if( dialog->hwnd )
3998 DestroyWindow( dialog->hwnd );
3999
4000 /* unsubscribe events */
4001 event_cleanup_subscriptions( dialog->package, dialog->name );
4002
4003 /* destroy the list of controls */
4004 while( !list_empty( &dialog->controls ) )
4005 {
4006 msi_control *t;
4007
4008 t = LIST_ENTRY( list_head( &dialog->controls ),
4009 msi_control, entry );
4010 msi_destroy_control( t );
4011 }
4012
4013 /* destroy the list of fonts */
4014 LIST_FOR_EACH_ENTRY_SAFE( font, next, &dialog->fonts, msi_font, entry )
4015 {
4016 list_remove( &font->entry );
4017 DeleteObject( font->hfont );
4018 msi_free( font );
4019 }
4020 msi_free( dialog->default_font );
4021
4022 msi_free( dialog->control_default );
4023 msi_free( dialog->control_cancel );
4024 msiobj_release( &dialog->package->hdr );
4025 dialog->package = NULL;
4026 msi_free( dialog );
4027 }
4028
4029 void msi_dialog_unregister_class( void )
4030 {
4031 DestroyWindow( hMsiHiddenWindow );
4032 hMsiHiddenWindow = NULL;
4033 UnregisterClassW( szMsiDialogClass, NULL );
4034 UnregisterClassW( szMsiHiddenWindow, NULL );
4035 uiThreadId = 0;
4036 }
4037
4038 void msi_event_cleanup_all_subscriptions( MSIPACKAGE *package )
4039 {
4040 struct list *item, *next;
4041
4042 LIST_FOR_EACH_SAFE( item, next, &package->subscriptions )
4043 {
4044 struct subscriber *sub = LIST_ENTRY( item, struct subscriber, entry );
4045 list_remove( &sub->entry );
4046 free_subscriber( sub );
4047 }
4048 }
4049
4050 static UINT error_dialog_handler( msi_dialog *dialog, const WCHAR *event, const WCHAR *argument )
4051 {
4052 static const WCHAR end_dialog[] = {'E','n','d','D','i','a','l','o','g',0};
4053 static const WCHAR error_abort[] = {'E','r','r','o','r','A','b','o','r','t',0};
4054 static const WCHAR error_cancel[] = {'E','r','r','o','r','C','a','n','c','e','l',0};
4055 static const WCHAR error_no[] = {'E','r','r','o','r','N','o',0};
4056 static const WCHAR result_prop[] = {
4057 'M','S','I','E','r','r','o','r','D','i','a','l','o','g','R','e','s','u','l','t',0
4058 };
4059
4060 if ( strcmpW( event, end_dialog ) )
4061 return ERROR_SUCCESS;
4062
4063 if ( !strcmpW( argument, error_abort ) || !strcmpW( argument, error_cancel ) ||
4064 !strcmpW( argument, error_no ) )
4065 {
4066 msi_set_property( dialog->package->db, result_prop, error_abort, -1 );
4067 }
4068
4069 msi_event_cleanup_all_subscriptions( dialog->package );
4070 msi_dialog_end_dialog( dialog );
4071
4072 return ERROR_SUCCESS;
4073 }
4074
4075 static UINT msi_error_dialog_set_error( MSIPACKAGE *package, LPWSTR error_dialog, LPWSTR error )
4076 {
4077 MSIRECORD * row;
4078
4079 static const WCHAR update[] =
4080 {'U','P','D','A','T','E',' ','`','C','o','n','t','r','o','l','`',' ',
4081 'S','E','T',' ','`','T','e','x','t','`',' ','=',' ','\'','%','s','\'',' ',
4082 'W','H','E','R','E', ' ','`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',' ',
4083 'A','N','D',' ','`','C','o','n','t','r','o','l','`',' ','=',' ',
4084 '\'','E','r','r','o','r','T','e','x','t','\'',0};
4085
4086 row = MSI_QueryGetRecord( package->db, update, error, error_dialog );
4087 if (!row)
4088 return ERROR_FUNCTION_FAILED;
4089
4090 msiobj_release(&row->hdr);
4091 return ERROR_SUCCESS;
4092 }
4093
4094 UINT msi_spawn_error_dialog( MSIPACKAGE *package, LPWSTR error_dialog, LPWSTR error )
4095 {
4096 msi_dialog *dialog;
4097 WCHAR result[MAX_PATH];
4098 UINT r = ERROR_SUCCESS;
4099 DWORD size = MAX_PATH;
4100 int res;
4101
4102 static const WCHAR pn_prop[] = {'P','r','o','d','u','c','t','N','a','m','e',0};
4103 static const WCHAR title_fmt[] = {'%','s',' ','W','a','r','n','i','n','g',0};
4104 static const WCHAR error_abort[] = {'E','r','r','o','r','A','b','o','r','t',0};
4105 static const WCHAR result_prop[] = {
4106 'M','S','I','E','r','r','o','r','D','i','a','l','o','g','R','e','s','u','l','t',0
4107 };
4108
4109 if ((package->ui_level & INSTALLUILEVEL_MASK) == INSTALLUILEVEL_NONE) return ERROR_SUCCESS;
4110
4111 if ( !error_dialog )
4112 {
4113 LPWSTR product_name = msi_dup_property( package->db, pn_prop );
4114 WCHAR title[MAX_PATH];
4115
4116 sprintfW( title, title_fmt, product_name );
4117 res = MessageBoxW( NULL, error, title, MB_OKCANCEL | MB_ICONWARNING );
4118
4119 msi_free( product_name );
4120
4121 if ( res == IDOK )
4122 return ERROR_SUCCESS;
4123 else
4124 return ERROR_FUNCTION_FAILED;
4125 }
4126
4127 r = msi_error_dialog_set_error( package, error_dialog, error );
4128 if ( r != ERROR_SUCCESS )
4129 return r;
4130
4131 dialog = dialog_create( package, error_dialog, package->dialog, error_dialog_handler );
4132 if ( !dialog )
4133 return ERROR_FUNCTION_FAILED;
4134
4135 dialog->finished = FALSE;
4136 r = dialog_run_message_loop( dialog );
4137 if ( r != ERROR_SUCCESS )
4138 goto done;
4139
4140 r = msi_get_property( package->db, result_prop, result, &size );
4141 if ( r != ERROR_SUCCESS)
4142 r = ERROR_SUCCESS;
4143
4144 if ( !strcmpW( result, error_abort ) )
4145 r = ERROR_FUNCTION_FAILED;
4146
4147 done:
4148 msi_dialog_destroy( dialog );
4149
4150 return r;
4151 }
4152
4153 static void MSI_ClosePreview( MSIOBJECTHDR *arg )
4154 {
4155 MSIPREVIEW *preview = (MSIPREVIEW *)arg;
4156 msiobj_release( &preview->package->hdr );
4157 }
4158
4159 static MSIPREVIEW *MSI_EnableUIPreview( MSIDATABASE *db )
4160 {
4161 MSIPREVIEW *preview = NULL;
4162 MSIPACKAGE *package;
4163
4164 package = MSI_CreatePackage( db, NULL );
4165 if (package)
4166 {
4167 preview = alloc_msiobject( MSIHANDLETYPE_PREVIEW, sizeof(MSIPREVIEW), MSI_ClosePreview );
4168 if (preview)
4169 {
4170 preview->package = package;
4171 msiobj_addref( &package->hdr );
4172 }
4173 msiobj_release( &package->hdr );
4174 }
4175 return preview;
4176 }
4177
4178 UINT WINAPI MsiEnableUIPreview( MSIHANDLE hdb, MSIHANDLE *phPreview )
4179 {
4180 MSIDATABASE *db;
4181 MSIPREVIEW *preview;
4182 UINT r = ERROR_FUNCTION_FAILED;
4183
4184 TRACE("%d %p\n", hdb, phPreview);
4185
4186 db = msihandle2msiinfo( hdb, MSIHANDLETYPE_DATABASE );
4187 if (!db)
4188 {
4189 IWineMsiRemoteDatabase *remote_database;
4190
4191 remote_database = (IWineMsiRemoteDatabase *)msi_get_remote( hdb );
4192 if (!remote_database)
4193 return ERROR_INVALID_HANDLE;
4194
4195 *phPreview = 0;
4196
4197 IWineMsiRemoteDatabase_Release( remote_database );
4198 WARN("MsiEnableUIPreview not allowed during a custom action!\n");
4199
4200 return ERROR_FUNCTION_FAILED;
4201 }
4202 preview = MSI_EnableUIPreview( db );
4203 if (preview)
4204 {
4205 *phPreview = alloc_msihandle( &preview->hdr );
4206 msiobj_release( &preview->hdr );
4207 r = ERROR_SUCCESS;
4208 if (!*phPreview)
4209 r = ERROR_NOT_ENOUGH_MEMORY;
4210 }
4211 msiobj_release( &db->hdr );
4212 return r;
4213 }
4214
4215 static UINT preview_event_handler( msi_dialog *dialog, const WCHAR *event, const WCHAR *argument )
4216 {
4217 MESSAGE("Preview dialog event '%s' (arg='%s')\n", debugstr_w(event), debugstr_w(argument));
4218 return ERROR_SUCCESS;
4219 }
4220
4221 static UINT MSI_PreviewDialogW( MSIPREVIEW *preview, LPCWSTR szDialogName )
4222 {
4223 msi_dialog *dialog = NULL;
4224 UINT r = ERROR_SUCCESS;
4225
4226 if (preview->dialog)
4227 msi_dialog_destroy( preview->dialog );
4228
4229 /* an empty name means we should just destroy the current preview dialog */
4230 if (szDialogName)
4231 {
4232 dialog = dialog_create( preview->package, szDialogName, NULL, preview_event_handler );
4233 if (dialog)
4234 dialog_do_preview( dialog );
4235 else
4236 r = ERROR_FUNCTION_FAILED;
4237 }
4238 preview->dialog = dialog;
4239 return r;
4240 }
4241
4242 UINT WINAPI MsiPreviewDialogW( MSIHANDLE hPreview, LPCWSTR szDialogName )
4243 {
4244 MSIPREVIEW *preview;
4245 UINT r;
4246
4247 TRACE("%d %s\n", hPreview, debugstr_w(szDialogName));
4248
4249 preview = msihandle2msiinfo( hPreview, MSIHANDLETYPE_PREVIEW );
4250 if (!preview)
4251 return ERROR_INVALID_HANDLE;
4252
4253 r = MSI_PreviewDialogW( preview, szDialogName );
4254 msiobj_release( &preview->hdr );
4255 return r;
4256 }
4257
4258 UINT WINAPI MsiPreviewDialogA( MSIHANDLE hPreview, LPCSTR szDialogName )
4259 {
4260 UINT r;
4261 LPWSTR strW = NULL;
4262
4263 TRACE("%d %s\n", hPreview, debugstr_a(szDialogName));
4264
4265 if (szDialogName)
4266 {
4267 strW = strdupAtoW( szDialogName );
4268 if (!strW)
4269 return ERROR_OUTOFMEMORY;
4270 }
4271 r = MsiPreviewDialogW( hPreview, strW );
4272 msi_free( strW );
4273 return r;
4274 }
4275
4276 UINT WINAPI MsiPreviewBillboardW( MSIHANDLE hPreview, LPCWSTR szControlName, LPCWSTR szBillboard )
4277 {
4278 FIXME("%d %s %s\n", hPreview, debugstr_w(szControlName), debugstr_w(szBillboard));
4279 return ERROR_CALL_NOT_IMPLEMENTED;
4280 }
4281
4282 UINT WINAPI MsiPreviewBillboardA( MSIHANDLE hPreview, LPCSTR szControlName, LPCSTR szBillboard )
4283 {
4284 FIXME("%d %s %s\n", hPreview, debugstr_a(szControlName), debugstr_a(szBillboard));
4285 return ERROR_CALL_NOT_IMPLEMENTED;
4286 }
4287
4288 typedef UINT (*event_handler)( msi_dialog *, const WCHAR * );
4289
4290 struct control_event
4291 {
4292 const WCHAR *event;
4293 event_handler handler;
4294 };
4295
4296 static UINT dialog_event_handler( msi_dialog *, const WCHAR *, const WCHAR * );
4297
4298 /* create a dialog box and run it if it's modal */
4299 static UINT event_do_dialog( MSIPACKAGE *package, const WCHAR *name, msi_dialog *parent, BOOL destroy_modeless )
4300 {
4301 msi_dialog *dialog;
4302 UINT r;
4303
4304 /* create a new dialog */
4305 dialog = dialog_create( package, name, parent, dialog_event_handler );
4306 if (dialog)
4307 {
4308 /* kill the current modeless dialog */
4309 if (destroy_modeless && package->dialog)
4310 {
4311 msi_dialog_destroy( package->dialog );
4312 package->dialog = NULL;
4313 }
4314
4315 /* modeless dialogs return an error message */
4316 r = dialog_run_message_loop( dialog );
4317 if (r == ERROR_SUCCESS)
4318 msi_dialog_destroy( dialog );
4319 else
4320 package->dialog = dialog;
4321 }
4322 else r = ERROR_FUNCTION_FAILED;
4323 return r;
4324 }
4325
4326 /* end a modal dialog box */
4327 static UINT event_end_dialog( msi_dialog *dialog, const WCHAR *argument )
4328 {
4329 static const WCHAR exitW[] = {'E','x','i','t',0};
4330 static const WCHAR retryW[] = {'R','e','t','r','y',0};
4331 static const WCHAR ignoreW[] = {'I','g','n','o','r','e',0};
4332 static const WCHAR returnW[] = {'R','e','t','u','r','n',0};
4333
4334 if (!strcmpW( argument, exitW ))
4335 dialog->package->CurrentInstallState = ERROR_INSTALL_USEREXIT;
4336 else if (!strcmpW( argument, retryW ))
4337 dialog->package->CurrentInstallState = ERROR_INSTALL_SUSPEND;
4338 else if (!strcmpW( argument, ignoreW ))
4339 dialog->package->CurrentInstallState = ERROR_SUCCESS;
4340 else if (!strcmpW( argument, returnW ))
4341 {
4342 msi_dialog *parent = dialog->parent;
4343 msi_free( dialog->package->next_dialog );
4344 dialog->package->next_dialog = (parent) ? strdupW( parent->name ) : NULL;
4345 dialog->package->CurrentInstallState = ERROR_SUCCESS;
4346 }
4347 else
4348 {
4349 ERR("Unknown argument string %s\n", debugstr_w(argument));
4350 dialog->package->CurrentInstallState = ERROR_FUNCTION_FAILED;
4351 }
4352 event_cleanup_subscriptions( dialog->package, dialog->name );
4353 msi_dialog_end_dialog( dialog );
4354 return ERROR_SUCCESS;
4355 }
4356
4357 /* transition from one modal dialog to another modal dialog */
4358 static UINT event_new_dialog( msi_dialog *dialog, const WCHAR *argument )
4359 {
4360 /* store the name of the next dialog, and signal this one to end */
4361 dialog->package->next_dialog = strdupW( argument );
4362 msi_event_cleanup_all_subscriptions( dialog->package );
4363 msi_dialog_end_dialog( dialog );
4364 return ERROR_SUCCESS;
4365 }
4366
4367 /* create a new child dialog of an existing modal dialog */
4368 static UINT event_spawn_dialog( msi_dialog *dialog, const WCHAR *argument )
4369 {
4370 /* don't destroy a modeless dialogs that might be our parent */
4371 event_do_dialog( dialog->package, argument, dialog, FALSE );
4372 if (dialog->package->CurrentInstallState != ERROR_SUCCESS) msi_dialog_end_dialog( dialog );
4373 return ERROR_SUCCESS;
4374 }
4375
4376 /* creates a dialog that remains up for a period of time based on a condition */
4377 static UINT event_spawn_wait_dialog( msi_dialog *dialog, const WCHAR *argument )
4378 {
4379 FIXME("doing nothing\n");
4380 return ERROR_SUCCESS;
4381 }
4382
4383 static UINT event_do_action( msi_dialog *dialog, const WCHAR *argument )
4384 {
4385 ACTION_PerformAction( dialog->package, argument, SCRIPT_NONE );
4386 return ERROR_SUCCESS;
4387 }
4388
4389 static UINT event_add_local( msi_dialog *dialog, const WCHAR *argument )
4390 {
4391 MSIFEATURE *feature;
4392
4393 LIST_FOR_EACH_ENTRY( feature, &dialog->package->features, MSIFEATURE, entry )
4394 {
4395 if (!strcmpW( argument, feature->Feature ) || !strcmpW( argument, szAll ))
4396 {
4397 if (feature->ActionRequest != INSTALLSTATE_LOCAL)
4398 msi_set_property( dialog->package->db, szPreselected, szOne, -1 );
4399 MSI_SetFeatureStateW( dialog->package, feature->Feature, INSTALLSTATE_LOCAL );
4400 }
4401 }
4402 return ERROR_SUCCESS;
4403 }
4404
4405 static UINT event_remove( msi_dialog *dialog, const WCHAR *argument )
4406 {
4407 MSIFEATURE *feature;
4408
4409 LIST_FOR_EACH_ENTRY( feature, &dialog->package->features, MSIFEATURE, entry )
4410 {
4411 if (!strcmpW( argument, feature->Feature ) || !strcmpW( argument, szAll ))
4412 {
4413 if (feature->ActionRequest != INSTALLSTATE_ABSENT)
4414 msi_set_property( dialog->package->db, szPreselected, szOne, -1 );
4415 MSI_SetFeatureStateW( dialog->package, feature->Feature, INSTALLSTATE_ABSENT );
4416 }
4417 }
4418 return ERROR_SUCCESS;
4419 }
4420
4421 static UINT event_add_source( msi_dialog *dialog, const WCHAR *argument )
4422 {
4423 MSIFEATURE *feature;
4424
4425 LIST_FOR_EACH_ENTRY( feature, &dialog->package->features, MSIFEATURE, entry )
4426 {
4427 if (!strcmpW( argument, feature->Feature ) || !strcmpW( argument, szAll ))
4428 {
4429 if (feature->ActionRequest != INSTALLSTATE_SOURCE)
4430 msi_set_property( dialog->package->db, szPreselected, szOne, -1 );
4431 MSI_SetFeatureStateW( dialog->package, feature->Feature, INSTALLSTATE_SOURCE );
4432 }
4433 }
4434 return ERROR_SUCCESS;
4435 }
4436
4437 void msi_event_fire( MSIPACKAGE *package, const WCHAR *event, MSIRECORD *rec )
4438 {
4439 struct subscriber *sub;
4440
4441 TRACE("firing event %s\n", debugstr_w(event));
4442
4443 LIST_FOR_EACH_ENTRY( sub, &package->subscriptions, struct subscriber, entry )
4444 {
4445 if (strcmpiW( sub->event, event )) continue;
4446 dialog_handle_event( sub->dialog, sub->control, sub->attribute, rec );
4447 }
4448 }
4449
4450 static UINT event_set_target_path( msi_dialog *dialog, const WCHAR *argument )
4451 {
4452 WCHAR *path = msi_dup_property( dialog->package->db, argument );
4453 MSIRECORD *rec = MSI_CreateRecord( 1 );
4454 UINT r = ERROR_SUCCESS;
4455
4456 MSI_RecordSetStringW( rec, 1, path );
4457 msi_event_fire( dialog->package, szSelectionPath, rec );
4458 if (path)
4459 {
4460 /* failure to set the path halts the executing of control events */
4461 r = MSI_SetTargetPathW( dialog->package, argument, path );
4462 msi_free( path );
4463 }
4464 msi_free( &rec->hdr );
4465 return r;
4466 }
4467
4468 static UINT event_reset( msi_dialog *dialog, const WCHAR *argument )
4469 {
4470 msi_dialog_reset( dialog );
4471 return ERROR_SUCCESS;
4472 }
4473
4474 /* Return ERROR_SUCCESS if dialog is process and ERROR_FUNCTION_FAILED
4475 * if the given parameter is not a dialog box
4476 */
4477 UINT ACTION_DialogBox( MSIPACKAGE *package, const WCHAR *dialog )
4478 {
4479 UINT r;
4480
4481 if (package->next_dialog) ERR("Already got next dialog... ignoring it\n");
4482 package->next_dialog = NULL;
4483
4484 /* Dialogs are chained by filling in the next_dialog member
4485 * of the package structure, then terminating the current dialog.
4486 * The code below sees the next_dialog member set, and runs the
4487 * next dialog.
4488 * We fall out of the loop below if we come across a modeless
4489 * dialog, as it returns ERROR_IO_PENDING when we try to run
4490 * its message loop.
4491 */
4492 r = event_do_dialog( package, dialog, NULL, TRUE );
4493 while (r == ERROR_SUCCESS && package->next_dialog)
4494 {
4495 WCHAR *name = package->next_dialog;
4496
4497 package->next_dialog = NULL;
4498 r = event_do_dialog( package, name, NULL, TRUE );
4499 msi_free( name );
4500 }
4501 if (r == ERROR_IO_PENDING) r = ERROR_SUCCESS;
4502 return r;
4503 }
4504
4505 static UINT event_set_install_level( msi_dialog *dialog, const WCHAR *argument )
4506 {
4507 int level = atolW( argument );
4508
4509 TRACE("setting install level to %d\n", level);
4510 return MSI_SetInstallLevel( dialog->package, level );
4511 }
4512
4513 static UINT event_directory_list_up( msi_dialog *dialog, const WCHAR *argument )
4514 {
4515 return msi_dialog_directorylist_up( dialog );
4516 }
4517
4518 static UINT event_reinstall_mode( msi_dialog *dialog, const WCHAR *argument )
4519 {
4520 return msi_set_property( dialog->package->db, szReinstallMode, argument, -1 );
4521 }
4522
4523 static UINT event_reinstall( msi_dialog *dialog, const WCHAR *argument )
4524 {
4525 return msi_set_property( dialog->package->db, szReinstall, argument, -1 );
4526 }
4527
4528 static UINT event_validate_product_id( msi_dialog *dialog, const WCHAR *argument )
4529 {
4530 return msi_validate_product_id( dialog->package );
4531 }
4532
4533 static const WCHAR end_dialogW[] = {'E','n','d','D','i','a','l','o','g',0};
4534 static const WCHAR new_dialogW[] = {'N','e','w','D','i','a','l','o','g',0};
4535 static const WCHAR spawn_dialogW[] = {'S','p','a','w','n','D','i','a','l','o','g',0};
4536 static const WCHAR spawn_wait_dialogW[] = {'S','p','a','w','n','W','a','i','t','D','i','a','l','o','g',0};
4537 static const WCHAR do_actionW[] = {'D','o','A','c','t','i','o','n',0};
4538 static const WCHAR add_localW[] = {'A','d','d','L','o','c','a','l',0};
4539 static const WCHAR removeW[] = {'R','e','m','o','v','e',0};
4540 static const WCHAR add_sourceW[] = {'A','d','d','S','o','u','r','c','e',0};
4541 static const WCHAR set_target_pathW[] = {'S','e','t','T','a','r','g','e','t','P','a','t','h',0};
4542 static const WCHAR resetW[] = {'R','e','s','e','t',0};
4543 static const WCHAR set_install_levelW[] = {'S','e','t','I','n','s','t','a','l','l','L','e','v','e','l',0};
4544 static const WCHAR directory_list_upW[] = {'D','i','r','e','c','t','o','r','y','L','i','s','t','U','p',0};
4545 static const WCHAR selection_browseW[] = {'S','e','l','e','c','t','i','o','n','B','r','o','w','s','e',0};
4546 static const WCHAR reinstall_modeW[] = {'R','e','i','n','s','t','a','l','l','M','o','d','e',0};
4547 static const WCHAR reinstallW[] = {'R','e','i','n','s','t','a','l','l',0};
4548 static const WCHAR validate_product_idW[] = {'V','a','l','i','d','a','t','e','P','r','o','d','u','c','t','I','D',0};
4549
4550 static const struct control_event control_events[] =
4551 {
4552 { end_dialogW, event_end_dialog },
4553 { new_dialogW, event_new_dialog },
4554 { spawn_dialogW, event_spawn_dialog },
4555 { spawn_wait_dialogW, event_spawn_wait_dialog },
4556 { do_actionW, event_do_action },
4557 { add_localW, event_add_local },
4558 { removeW, event_remove },
4559 { add_sourceW, event_add_source },
4560 { set_target_pathW, event_set_target_path },
4561 { resetW, event_reset },
4562 { set_install_levelW, event_set_install_level },
4563 { directory_list_upW, event_directory_list_up },
4564 { selection_browseW, event_spawn_dialog },
4565 { reinstall_modeW, event_reinstall_mode },
4566 { reinstallW, event_reinstall },
4567 { validate_product_idW, event_validate_product_id },
4568 { NULL, NULL }
4569 };
4570
4571 static UINT dialog_event_handler( msi_dialog *dialog, const WCHAR *event, const WCHAR *argument )
4572 {
4573 unsigned int i;
4574
4575 TRACE("handling event %s\n", debugstr_w(event));
4576
4577 if (!event) return ERROR_SUCCESS;
4578
4579 for (i = 0; control_events[i].event; i++)
4580 {
4581 if (!strcmpW( control_events[i].event, event ))
4582 return control_events[i].handler( dialog, argument );
4583 }
4584 FIXME("unhandled event %s arg(%s)\n", debugstr_w(event), debugstr_w(argument));
4585 return ERROR_SUCCESS;
4586 }