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