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