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