msi: Only print fixme for progress attribute once.
[wine/dcerpc.git] / dlls / msi / dialog.c
blobc3b305e44bdfcc5a720caaf92bf9365c848e66ef
1 /*
2 * Implementation of the Microsoft Installer (msi.dll)
4 * Copyright 2005 Mike McCormack for CodeWeavers
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #define COBJMACROS
22 #define NONAMELESSUNION
23 #define NONAMELESSSTRUCT
25 #include <stdarg.h>
27 #include "windef.h"
28 #include "winbase.h"
29 #include "winuser.h"
30 #include "winnls.h"
31 #include "wingdi.h"
32 #include "msi.h"
33 #include "msipriv.h"
34 #include "msidefs.h"
35 #include "ocidl.h"
36 #include "olectl.h"
37 #include "richedit.h"
38 #include "commctrl.h"
40 #include "wine/debug.h"
41 #include "wine/unicode.h"
43 #include "action.h"
45 WINE_DEFAULT_DEBUG_CHANNEL(msi);
48 extern HINSTANCE msi_hInstance;
50 struct msi_control_tag;
51 typedef struct msi_control_tag msi_control;
52 typedef UINT (*msi_handler)( msi_dialog *, msi_control *, WPARAM );
54 struct msi_control_tag
56 struct list entry;
57 HWND hwnd;
58 msi_handler handler;
59 LPWSTR property;
60 LPWSTR value;
61 HBITMAP hBitmap;
62 HICON hIcon;
63 LPWSTR tabnext;
64 HMODULE hDll;
65 WCHAR name[1];
68 typedef struct msi_font_tag
70 struct msi_font_tag *next;
71 HFONT hfont;
72 WCHAR name[1];
73 } msi_font;
75 struct msi_dialog_tag
77 MSIPACKAGE *package;
78 msi_dialog_event_handler event_handler;
79 BOOL finished;
80 INT scale;
81 DWORD attributes;
82 HWND hwnd;
83 LPWSTR default_font;
84 msi_font *font_list;
85 struct list controls;
86 HWND hWndFocus;
87 LPWSTR control_default;
88 LPWSTR control_cancel;
89 WCHAR name[1];
92 typedef UINT (*msi_dialog_control_func)( msi_dialog *dialog, MSIRECORD *rec );
93 struct control_handler
95 LPCWSTR control_type;
96 msi_dialog_control_func func;
99 typedef struct
101 msi_dialog* dialog;
102 msi_control *parent;
103 DWORD attributes;
104 } radio_button_group_descr;
106 const WCHAR szMsiDialogClass[] = {
107 'M','s','i','D','i','a','l','o','g','C','l','o','s','e','C','l','a','s','s',0
109 const WCHAR szMsiHiddenWindow[] = {
110 '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[] = {
121 'S','c','r','o','l','l','a','b','l','e','T','e','x','t',0 };
122 static const WCHAR szComboBox[] = { 'C','o','m','b','o','B','o','x',0 };
123 static const WCHAR szEdit[] = { 'E','d','i','t',0 };
124 static const WCHAR szMaskedEdit[] = { 'M','a','s','k','e','d','E','d','i','t',0 };
125 static const WCHAR szPathEdit[] = { 'P','a','t','h','E','d','i','t',0 };
126 static const WCHAR szProgressBar[] = {
127 'P','r','o','g','r','e','s','s','B','a','r',0 };
128 static const WCHAR szRadioButtonGroup[] = {
129 'R','a','d','i','o','B','u','t','t','o','n','G','r','o','u','p',0 };
130 static const WCHAR szIcon[] = { 'I','c','o','n',0 };
131 static const WCHAR szSelectionTree[] = {
132 'S','e','l','e','c','t','i','o','n','T','r','e','e',0 };
134 static UINT msi_dialog_checkbox_handler( msi_dialog *, msi_control *, WPARAM );
135 static void msi_dialog_checkbox_sync_state( msi_dialog *, msi_control * );
136 static UINT msi_dialog_button_handler( msi_dialog *, msi_control *, WPARAM );
137 static UINT msi_dialog_edit_handler( msi_dialog *, msi_control *, WPARAM );
138 static UINT msi_dialog_radiogroup_handler( msi_dialog *, msi_control *, WPARAM param );
139 static UINT msi_dialog_evaluate_control_conditions( msi_dialog *dialog );
140 static LRESULT WINAPI MSIRadioGroup_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
143 /* dialog sequencing */
145 #define WM_MSI_DIALOG_CREATE (WM_USER+0x100)
146 #define WM_MSI_DIALOG_DESTROY (WM_USER+0x101)
148 static DWORD uiThreadId;
149 static HWND hMsiHiddenWindow;
151 static INT msi_dialog_scale_unit( msi_dialog *dialog, INT val )
153 return (dialog->scale * val + 5) / 10;
156 static msi_control *msi_dialog_find_control( msi_dialog *dialog, LPCWSTR name )
158 msi_control *control;
160 if( !name )
161 return NULL;
162 LIST_FOR_EACH_ENTRY( control, &dialog->controls, msi_control, entry )
163 if( !strcmpW( control->name, name ) ) /* FIXME: case sensitive? */
164 return control;
165 return NULL;
168 static msi_control *msi_dialog_find_control_by_hwnd( msi_dialog *dialog, HWND hwnd )
170 msi_control *control;
172 LIST_FOR_EACH_ENTRY( control, &dialog->controls, msi_control, entry )
173 if( hwnd == control->hwnd )
174 return control;
175 return NULL;
178 static LPWSTR msi_get_deformatted_field( MSIPACKAGE *package, MSIRECORD *rec, int field )
180 LPCWSTR str = MSI_RecordGetString( rec, field );
181 LPWSTR ret = NULL;
183 if (str)
184 deformat_string( package, str, &ret );
185 return ret;
189 * msi_dialog_get_style
191 * Extract the {\style} string from the front of the text to display and
192 * update the pointer.
194 static LPWSTR msi_dialog_get_style( LPCWSTR p, LPCWSTR *rest )
196 LPWSTR ret = NULL;
197 LPCWSTR q, i;
198 DWORD len;
200 *rest = p;
201 if( !p )
202 return ret;
203 if( *p++ != '{' )
204 return ret;
205 q = strchrW( p, '}' );
206 if( !q )
207 return ret;
208 if( *p == '\\' || *p == '&' )
209 p++;
211 /* little bit of sanity checking to stop us getting confused with RTF */
212 for( i=p; i<q; i++ )
213 if( *i == '}' || *i == '\\' )
214 return ret;
216 *rest = ++q;
217 len = q - p;
219 ret = msi_alloc( len*sizeof(WCHAR) );
220 if( !ret )
221 return ret;
222 memcpy( ret, p, len*sizeof(WCHAR) );
223 ret[len-1] = 0;
224 return ret;
227 static UINT msi_dialog_add_font( MSIRECORD *rec, LPVOID param )
229 msi_dialog *dialog = param;
230 msi_font *font;
231 LPCWSTR face, name;
232 LOGFONTW lf;
233 INT style;
234 HDC hdc;
236 /* create a font and add it to the list */
237 name = MSI_RecordGetString( rec, 1 );
238 font = msi_alloc( sizeof *font + strlenW( name )*sizeof (WCHAR) );
239 strcpyW( font->name, name );
240 font->next = dialog->font_list;
241 dialog->font_list = font;
243 memset( &lf, 0, sizeof lf );
244 face = MSI_RecordGetString( rec, 2 );
245 lf.lfHeight = MSI_RecordGetInteger( rec, 3 );
246 style = MSI_RecordGetInteger( rec, 5 );
247 if( style & msidbTextStyleStyleBitsBold )
248 lf.lfWeight = FW_BOLD;
249 if( style & msidbTextStyleStyleBitsItalic )
250 lf.lfItalic = TRUE;
251 if( style & msidbTextStyleStyleBitsUnderline )
252 lf.lfUnderline = TRUE;
253 if( style & msidbTextStyleStyleBitsStrike )
254 lf.lfStrikeOut = TRUE;
255 lstrcpynW( lf.lfFaceName, face, LF_FACESIZE );
257 /* adjust the height */
258 hdc = GetDC( dialog->hwnd );
259 if (hdc)
261 lf.lfHeight = -MulDiv(lf.lfHeight, GetDeviceCaps(hdc, LOGPIXELSY), 72);
262 ReleaseDC( dialog->hwnd, hdc );
265 font->hfont = CreateFontIndirectW( &lf );
267 TRACE("Adding font style %s\n", debugstr_w(font->name) );
269 return ERROR_SUCCESS;
272 static msi_font *msi_dialog_find_font( msi_dialog *dialog, LPCWSTR name )
274 msi_font *font;
276 for( font = dialog->font_list; font; font = font->next )
277 if( !strcmpW( font->name, name ) ) /* FIXME: case sensitive? */
278 break;
280 return font;
283 static UINT msi_dialog_set_font( msi_dialog *dialog, HWND hwnd, LPCWSTR name )
285 msi_font *font;
287 font = msi_dialog_find_font( dialog, name );
288 if( font )
289 SendMessageW( hwnd, WM_SETFONT, (WPARAM) font->hfont, TRUE );
290 else
291 ERR("No font entry for %s\n", debugstr_w(name));
292 return ERROR_SUCCESS;
295 static UINT msi_dialog_build_font_list( msi_dialog *dialog )
297 static const WCHAR query[] = {
298 'S','E','L','E','C','T',' ','*',' ',
299 'F','R','O','M',' ','`','T','e','x','t','S','t','y','l','e','`',' ',0
301 UINT r;
302 MSIQUERY *view = NULL;
304 TRACE("dialog %p\n", dialog );
306 r = MSI_OpenQuery( dialog->package->db, &view, query );
307 if( r != ERROR_SUCCESS )
308 return r;
310 r = MSI_IterateRecords( view, NULL, msi_dialog_add_font, dialog );
311 msiobj_release( &view->hdr );
313 return r;
316 static msi_control *msi_dialog_create_window( msi_dialog *dialog,
317 MSIRECORD *rec, LPCWSTR szCls, LPCWSTR name, LPCWSTR text,
318 DWORD style, HWND parent )
320 DWORD x, y, width, height;
321 LPWSTR font = NULL, title_font = NULL;
322 LPCWSTR title = NULL;
323 msi_control *control;
325 style |= WS_CHILD;
327 control = msi_alloc( sizeof *control + strlenW(name)*sizeof(WCHAR) );
328 strcpyW( control->name, name );
329 list_add_head( &dialog->controls, &control->entry );
330 control->handler = NULL;
331 control->property = NULL;
332 control->value = NULL;
333 control->hBitmap = NULL;
334 control->hIcon = NULL;
335 control->hDll = NULL;
336 control->tabnext = strdupW( MSI_RecordGetString( rec, 11) );
338 x = MSI_RecordGetInteger( rec, 4 );
339 y = MSI_RecordGetInteger( rec, 5 );
340 width = MSI_RecordGetInteger( rec, 6 );
341 height = MSI_RecordGetInteger( rec, 7 );
343 x = msi_dialog_scale_unit( dialog, x );
344 y = msi_dialog_scale_unit( dialog, y );
345 width = msi_dialog_scale_unit( dialog, width );
346 height = msi_dialog_scale_unit( dialog, height );
348 if( text )
350 deformat_string( dialog->package, text, &title_font );
351 font = msi_dialog_get_style( title_font, &title );
354 control->hwnd = CreateWindowW( szCls, title, style,
355 x, y, width, height, parent, NULL, NULL, NULL );
357 TRACE("Dialog %s control %s hwnd %p\n",
358 debugstr_w(dialog->name), debugstr_w(text), control->hwnd );
360 msi_dialog_set_font( dialog, control->hwnd,
361 font ? font : dialog->default_font );
363 msi_free( title_font );
364 msi_free( font );
366 return control;
369 static MSIRECORD *msi_get_binary_record( MSIDATABASE *db, LPCWSTR name )
371 static const WCHAR query[] = {
372 's','e','l','e','c','t',' ','*',' ',
373 'f','r','o','m',' ','B','i','n','a','r','y',' ',
374 'w','h','e','r','e',' ',
375 '`','N','a','m','e','`',' ','=',' ','\'','%','s','\'',0
378 return MSI_QueryGetRecord( db, query, name );
381 static LPWSTR msi_create_tmp_path(void)
383 WCHAR tmp[MAX_PATH];
384 LPWSTR path = NULL;
385 static const WCHAR prefix[] = { 'm','s','i',0 };
386 DWORD len, r;
388 r = GetTempPathW( MAX_PATH, tmp );
389 if( !r )
390 return path;
391 len = lstrlenW( tmp ) + 20;
392 path = msi_alloc( len * sizeof (WCHAR) );
393 if( path )
395 r = GetTempFileNameW( tmp, prefix, 0, path );
396 if (!r)
398 msi_free( path );
399 path = NULL;
402 return path;
406 static HANDLE msi_load_image( MSIDATABASE *db, LPCWSTR name, UINT type,
407 UINT cx, UINT cy, UINT flags )
409 MSIRECORD *rec = NULL;
410 HANDLE himage = NULL;
411 LPWSTR tmp;
412 UINT r;
414 TRACE("%p %s %u %u %08x\n", db, debugstr_w(name), cx, cy, flags);
416 tmp = msi_create_tmp_path();
417 if( !tmp )
418 return himage;
420 rec = msi_get_binary_record( db, name );
421 if( rec )
423 r = MSI_RecordStreamToFile( rec, 2, tmp );
424 if( r == ERROR_SUCCESS )
426 himage = LoadImageW( 0, tmp, type, cx, cy, flags );
427 DeleteFileW( tmp );
429 msiobj_release( &rec->hdr );
432 msi_free( tmp );
433 return himage;
436 static HICON msi_load_icon( MSIDATABASE *db, LPCWSTR text, UINT attributes )
438 DWORD cx = 0, cy = 0, flags;
440 flags = LR_LOADFROMFILE | LR_DEFAULTSIZE;
441 if( attributes & msidbControlAttributesFixedSize )
443 flags &= ~LR_DEFAULTSIZE;
444 if( attributes & msidbControlAttributesIconSize16 )
446 cx += 16;
447 cy += 16;
449 if( attributes & msidbControlAttributesIconSize32 )
451 cx += 32;
452 cy += 32;
454 /* msidbControlAttributesIconSize48 handled by above logic */
456 return msi_load_image( db, text, IMAGE_ICON, cx, cy, flags );
460 /* called from the Control Event subscription code */
461 void msi_dialog_handle_event( msi_dialog* dialog, LPCWSTR control,
462 LPCWSTR attribute, MSIRECORD *rec )
464 msi_control* ctrl;
465 LPCWSTR font_text, text = NULL;
466 LPWSTR font;
468 ctrl = msi_dialog_find_control( dialog, control );
469 if (!ctrl)
470 return;
471 if( !lstrcmpW(attribute, szText) )
473 font_text = MSI_RecordGetString( rec , 1 );
474 font = msi_dialog_get_style( font_text, &text );
475 SetWindowTextW( ctrl->hwnd, text );
476 msi_free( font );
477 msi_dialog_check_messages( NULL );
479 else if( !lstrcmpW(attribute, szProgress) )
481 /* FIXME: should forward to progress bar */
482 static int display_fixme = 1;
483 if (display_fixme)
484 FIXME("Attribute %s not being set\n", debugstr_w(attribute));
485 display_fixme = 0;
487 else
489 FIXME("Attribute %s not being set\n", debugstr_w(attribute));
490 return;
494 static void msi_dialog_map_events(msi_dialog* dialog, LPCWSTR control)
496 static WCHAR Query[] = {
497 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
498 '`','E','v','e','n','t','M','a','p','p','i','n','g','`',' ',
499 'W','H','E','R','E',' ',
500 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',' ',
501 'A','N','D',' ',
502 '`','C','o','n','t','r','o','l','_','`',' ','=',' ','\'','%','s','\'',0
504 MSIRECORD *row;
505 LPCWSTR event, attribute;
507 row = MSI_QueryGetRecord( dialog->package->db, Query, dialog->name, control );
508 if (!row)
509 return;
511 event = MSI_RecordGetString( row, 3 );
512 attribute = MSI_RecordGetString( row, 4 );
513 ControlEvent_SubscribeToEvent( dialog->package, event, control, attribute );
514 msiobj_release( &row->hdr );
517 /* everything except radio buttons */
518 static msi_control *msi_dialog_add_control( msi_dialog *dialog,
519 MSIRECORD *rec, LPCWSTR szCls, DWORD style )
521 DWORD attributes;
522 LPCWSTR text, name;
524 name = MSI_RecordGetString( rec, 2 );
525 attributes = MSI_RecordGetInteger( rec, 8 );
526 text = MSI_RecordGetString( rec, 10 );
527 if( attributes & msidbControlAttributesVisible )
528 style |= WS_VISIBLE;
529 if( ~attributes & msidbControlAttributesEnabled )
530 style |= WS_DISABLED;
532 msi_dialog_map_events(dialog, name);
534 return msi_dialog_create_window( dialog, rec, szCls, name, text,
535 style, dialog->hwnd );
538 struct msi_text_info
540 WNDPROC oldproc;
541 DWORD attributes;
545 * we don't erase our own background,
546 * so we have to make sure that the parent window redraws first
548 static void msi_text_on_settext( HWND hWnd )
550 HWND hParent;
551 RECT rc;
553 hParent = GetParent( hWnd );
554 GetWindowRect( hWnd, &rc );
555 MapWindowPoints( NULL, hParent, (LPPOINT) &rc, 2 );
556 InvalidateRect( hParent, &rc, TRUE );
559 static LRESULT WINAPI
560 MSIText_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
562 struct msi_text_info *info;
563 LRESULT r = 0;
565 TRACE("%p %04x %08x %08lx\n", hWnd, msg, wParam, lParam);
567 info = GetPropW(hWnd, szButtonData);
569 if( msg == WM_CTLCOLORSTATIC &&
570 ( info->attributes & msidbControlAttributesTransparent ) )
572 SetBkMode( (HDC)wParam, TRANSPARENT );
573 return (LRESULT) GetStockObject(NULL_BRUSH);
576 r = CallWindowProcW(info->oldproc, hWnd, msg, wParam, lParam);
578 switch( msg )
580 case WM_SETTEXT:
581 msi_text_on_settext( hWnd );
582 break;
583 case WM_NCDESTROY:
584 msi_free( info );
585 RemovePropW( hWnd, szButtonData );
586 break;
589 return r;
592 static UINT msi_dialog_text_control( msi_dialog *dialog, MSIRECORD *rec )
594 msi_control *control;
595 struct msi_text_info *info;
597 TRACE("%p %p\n", dialog, rec);
599 control = msi_dialog_add_control( dialog, rec, szStatic, SS_LEFT | WS_GROUP );
600 if( !control )
601 return ERROR_FUNCTION_FAILED;
603 info = msi_alloc( sizeof *info );
604 if( !info )
605 return ERROR_SUCCESS;
607 info->attributes = MSI_RecordGetInteger( rec, 8 );
608 if( info->attributes & msidbControlAttributesTransparent )
609 SetWindowLongPtrW( control->hwnd, GWL_EXSTYLE, WS_EX_TRANSPARENT );
611 info->oldproc = (WNDPROC) SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
612 (LONG_PTR)MSIText_WndProc );
613 SetPropW( control->hwnd, szButtonData, info );
615 return ERROR_SUCCESS;
618 static UINT msi_dialog_button_control( msi_dialog *dialog, MSIRECORD *rec )
620 msi_control *control;
621 UINT attributes, style;
622 LPWSTR text;
624 TRACE("%p %p\n", dialog, rec);
626 style = WS_TABSTOP;
627 attributes = MSI_RecordGetInteger( rec, 8 );
628 if( attributes & msidbControlAttributesIcon )
629 style |= BS_ICON;
631 control = msi_dialog_add_control( dialog, rec, szButton, style );
632 if( !control )
633 return ERROR_FUNCTION_FAILED;
635 control->handler = msi_dialog_button_handler;
637 /* set the icon */
638 text = msi_get_deformatted_field( dialog->package, rec, 10 );
639 control->hIcon = msi_load_icon( dialog->package->db, text, attributes );
640 if( attributes & msidbControlAttributesIcon )
641 SendMessageW( control->hwnd, BM_SETIMAGE, IMAGE_ICON, (LPARAM) control->hIcon );
642 msi_free( text );
644 return ERROR_SUCCESS;
647 static LPWSTR msi_get_checkbox_value( msi_dialog *dialog, LPCWSTR prop )
649 static const WCHAR query[] = {
650 'S','E','L','E','C','T',' ','*',' ',
651 'F','R','O','M',' ','`','C','h','e','c','k','B','o','x',' ','`',
652 'W','H','E','R','E',' ',
653 '`','P','r','o','p','e','r','t','y','`',' ','=',' ',
654 '\'','%','s','\'',0
656 MSIRECORD *rec = NULL;
657 LPWSTR ret = NULL;
659 /* find if there is a value associated with the checkbox */
660 rec = MSI_QueryGetRecord( dialog->package->db, query, prop );
661 if (!rec)
662 return ret;
664 ret = msi_get_deformatted_field( dialog->package, rec, 2 );
665 if( ret && !ret[0] )
667 msi_free( ret );
668 ret = NULL;
670 msiobj_release( &rec->hdr );
671 if (ret)
672 return ret;
674 ret = msi_dup_property( dialog->package, prop );
675 if( ret && !ret[0] )
677 msi_free( ret );
678 ret = NULL;
681 return ret;
684 static UINT msi_dialog_checkbox_control( msi_dialog *dialog, MSIRECORD *rec )
686 msi_control *control;
687 LPCWSTR prop;
689 TRACE("%p %p\n", dialog, rec);
691 control = msi_dialog_add_control( dialog, rec, szButton,
692 BS_CHECKBOX | BS_MULTILINE | WS_TABSTOP );
693 control->handler = msi_dialog_checkbox_handler;
694 prop = MSI_RecordGetString( rec, 9 );
695 if( prop )
697 control->property = strdupW( prop );
698 control->value = msi_get_checkbox_value( dialog, prop );
699 TRACE("control %s value %s\n", debugstr_w(control->property),
700 debugstr_w(control->value));
702 msi_dialog_checkbox_sync_state( dialog, control );
704 return ERROR_SUCCESS;
707 static UINT msi_dialog_line_control( msi_dialog *dialog, MSIRECORD *rec )
709 TRACE("%p %p\n", dialog, rec);
711 msi_dialog_add_control( dialog, rec, szStatic, SS_ETCHEDHORZ | SS_SUNKEN );
712 return ERROR_SUCCESS;
715 /******************** Scroll Text ********************************************/
717 struct msi_scrolltext_info
719 msi_dialog *dialog;
720 msi_control *control;
721 WNDPROC oldproc;
724 static LRESULT WINAPI
725 MSIScrollText_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
727 struct msi_scrolltext_info *info;
728 HRESULT r;
730 TRACE("%p %04x %08x %08lx\n", hWnd, msg, wParam, lParam);
732 info = GetPropW( hWnd, szButtonData );
734 r = CallWindowProcW( info->oldproc, hWnd, msg, wParam, lParam );
736 switch( msg )
738 case WM_NCDESTROY:
739 msi_free( info );
740 RemovePropW( hWnd, szButtonData );
741 break;
742 case WM_PAINT:
743 /* native MSI sets a wait cursor here */
744 msi_dialog_button_handler( info->dialog, info->control, BN_CLICKED );
745 break;
747 return r;
750 struct msi_streamin_info
752 LPSTR string;
753 DWORD offset;
754 DWORD length;
757 static DWORD CALLBACK
758 msi_richedit_stream_in( DWORD_PTR arg, LPBYTE buffer, LONG count, LONG *pcb )
760 struct msi_streamin_info *info = (struct msi_streamin_info*) arg;
762 if( (count + info->offset) > info->length )
763 count = info->length - info->offset;
764 memcpy( buffer, &info->string[ info->offset ], count );
765 *pcb = count;
766 info->offset += count;
768 TRACE("%ld/%ld\n", info->offset, info->length);
770 return 0;
773 static void msi_scrolltext_add_text( msi_control *control, LPCWSTR text )
775 struct msi_streamin_info info;
776 EDITSTREAM es;
778 info.string = strdupWtoA( text );
779 info.offset = 0;
780 info.length = lstrlenA( info.string ) + 1;
782 es.dwCookie = (DWORD_PTR) &info;
783 es.dwError = 0;
784 es.pfnCallback = msi_richedit_stream_in;
786 SendMessageW( control->hwnd, EM_STREAMIN, SF_RTF, (LPARAM) &es );
788 msi_free( info.string );
791 static UINT msi_dialog_scrolltext_control( msi_dialog *dialog, MSIRECORD *rec )
793 static const WCHAR szRichEdit20W[] = {
794 'R','i','c','h','E','d','i','t','2','0','W',0
796 struct msi_scrolltext_info *info;
797 msi_control *control;
798 HMODULE hRichedit;
799 DWORD style;
801 info = msi_alloc( sizeof *info );
802 if (!info)
803 return ERROR_FUNCTION_FAILED;
805 hRichedit = LoadLibraryA("riched20");
807 style = WS_BORDER | ES_MULTILINE | WS_VSCROLL |
808 ES_READONLY | ES_AUTOVSCROLL | WS_TABSTOP;
809 control = msi_dialog_add_control( dialog, rec, szRichEdit20W, style );
810 if (!control)
812 FreeLibrary( hRichedit );
813 msi_free( info );
814 return ERROR_FUNCTION_FAILED;
817 control->hDll = hRichedit;
819 info->dialog = dialog;
820 info->control = control;
822 /* subclass the static control */
823 info->oldproc = (WNDPROC) SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
824 (LONG_PTR)MSIScrollText_WndProc );
825 SetPropW( control->hwnd, szButtonData, info );
827 /* add the text into the richedit */
828 msi_scrolltext_add_text( control, MSI_RecordGetString( rec, 10 ) );
830 return ERROR_SUCCESS;
833 static HBITMAP msi_load_picture( MSIDATABASE *db, LPCWSTR name,
834 INT cx, INT cy, DWORD flags )
836 HBITMAP hOleBitmap = 0, hBitmap = 0, hOldSrcBitmap, hOldDestBitmap;
837 MSIRECORD *rec = NULL;
838 IStream *stm = NULL;
839 IPicture *pic = NULL;
840 HDC srcdc, destdc;
841 BITMAP bm;
842 UINT r;
844 rec = msi_get_binary_record( db, name );
845 if( !rec )
846 goto end;
848 r = MSI_RecordGetIStream( rec, 2, &stm );
849 msiobj_release( &rec->hdr );
850 if( r != ERROR_SUCCESS )
851 goto end;
853 r = OleLoadPicture( stm, 0, TRUE, &IID_IPicture, (LPVOID*) &pic );
854 IStream_Release( stm );
855 if( FAILED( r ) )
857 ERR("failed to load picture\n");
858 goto end;
861 r = IPicture_get_Handle( pic, (OLE_HANDLE*) &hOleBitmap );
862 if( FAILED( r ) )
864 ERR("failed to get bitmap handle\n");
865 goto end;
868 /* make the bitmap the desired size */
869 r = GetObjectW( hOleBitmap, sizeof bm, &bm );
870 if (r != sizeof bm )
872 ERR("failed to get bitmap size\n");
873 goto end;
876 if (flags & LR_DEFAULTSIZE)
878 cx = bm.bmWidth;
879 cy = bm.bmHeight;
882 srcdc = CreateCompatibleDC( NULL );
883 hOldSrcBitmap = SelectObject( srcdc, hOleBitmap );
884 destdc = CreateCompatibleDC( NULL );
885 hBitmap = CreateCompatibleBitmap( srcdc, cx, cy );
886 hOldDestBitmap = SelectObject( destdc, hBitmap );
887 StretchBlt( destdc, 0, 0, cx, cy,
888 srcdc, 0, 0, bm.bmWidth, bm.bmHeight, SRCCOPY);
889 SelectObject( srcdc, hOldSrcBitmap );
890 SelectObject( destdc, hOldDestBitmap );
891 DeleteDC( srcdc );
892 DeleteDC( destdc );
894 end:
895 if ( pic )
896 IPicture_Release( pic );
897 return hBitmap;
900 static UINT msi_dialog_bitmap_control( msi_dialog *dialog, MSIRECORD *rec )
902 UINT cx, cy, flags, style, attributes;
903 msi_control *control;
904 LPWSTR text;
906 flags = LR_LOADFROMFILE;
907 style = SS_BITMAP | SS_LEFT | WS_GROUP;
909 attributes = MSI_RecordGetInteger( rec, 8 );
910 if( attributes & msidbControlAttributesFixedSize )
912 flags |= LR_DEFAULTSIZE;
913 style |= SS_CENTERIMAGE;
916 control = msi_dialog_add_control( dialog, rec, szStatic, style );
917 cx = MSI_RecordGetInteger( rec, 6 );
918 cy = MSI_RecordGetInteger( rec, 7 );
919 cx = msi_dialog_scale_unit( dialog, cx );
920 cy = msi_dialog_scale_unit( dialog, cy );
922 text = msi_get_deformatted_field( dialog->package, rec, 10 );
923 control->hBitmap = msi_load_picture( dialog->package->db, text, cx, cy, flags );
924 if( control->hBitmap )
925 SendMessageW( control->hwnd, STM_SETIMAGE,
926 IMAGE_BITMAP, (LPARAM) control->hBitmap );
927 else
928 ERR("Failed to load bitmap %s\n", debugstr_w(text));
930 msi_free( text );
932 return ERROR_SUCCESS;
935 static UINT msi_dialog_icon_control( msi_dialog *dialog, MSIRECORD *rec )
937 msi_control *control;
938 DWORD attributes;
939 LPWSTR text;
941 TRACE("\n");
943 control = msi_dialog_add_control( dialog, rec, szStatic,
944 SS_ICON | SS_CENTERIMAGE | WS_GROUP );
946 attributes = MSI_RecordGetInteger( rec, 8 );
947 text = msi_get_deformatted_field( dialog->package, rec, 10 );
948 control->hIcon = msi_load_icon( dialog->package->db, text, attributes );
949 if( control->hIcon )
950 SendMessageW( control->hwnd, STM_SETICON, (WPARAM) control->hIcon, 0 );
951 else
952 ERR("Failed to load bitmap %s\n", debugstr_w(text));
953 msi_free( text );
954 return ERROR_SUCCESS;
957 static UINT msi_dialog_combo_control( msi_dialog *dialog, MSIRECORD *rec )
959 static const WCHAR szCombo[] = { 'C','O','M','B','O','B','O','X',0 };
961 msi_dialog_add_control( dialog, rec, szCombo,
962 SS_BITMAP | SS_LEFT | SS_CENTERIMAGE );
963 return ERROR_SUCCESS;
966 static UINT msi_dialog_edit_control( msi_dialog *dialog, MSIRECORD *rec )
968 msi_control *control;
969 LPCWSTR prop;
970 LPWSTR val;
972 control = msi_dialog_add_control( dialog, rec, szEdit,
973 WS_BORDER | WS_TABSTOP );
974 control->handler = msi_dialog_edit_handler;
975 prop = MSI_RecordGetString( rec, 9 );
976 if( prop )
977 control->property = strdupW( prop );
978 val = msi_dup_property( dialog->package, control->property );
979 SetWindowTextW( control->hwnd, val );
980 msi_free( val );
981 return ERROR_SUCCESS;
984 /******************** Masked Edit ********************************************/
986 #define MASK_MAX_GROUPS 10
988 struct msi_mask_group
990 UINT len;
991 UINT ofs;
992 WCHAR type;
993 HWND hwnd;
996 struct msi_maskedit_info
998 msi_dialog *dialog;
999 WNDPROC oldproc;
1000 HWND hwnd;
1001 LPWSTR prop;
1002 UINT num_chars;
1003 UINT num_groups;
1004 struct msi_mask_group group[MASK_MAX_GROUPS];
1007 static BOOL msi_mask_editable( WCHAR type )
1009 switch (type)
1011 case '%':
1012 case '#':
1013 case '&':
1014 case '`':
1015 case '?':
1016 case '^':
1017 return TRUE;
1019 return FALSE;
1022 static void msi_mask_control_change( struct msi_maskedit_info *info )
1024 LPWSTR val;
1025 UINT i, n, r;
1027 val = msi_alloc( (info->num_chars+1)*sizeof(WCHAR) );
1028 for( i=0, n=0; i<info->num_groups; i++ )
1030 if( (info->group[i].len + n) > info->num_chars )
1032 ERR("can't fit control %d text into template\n",i);
1033 break;
1035 if (!msi_mask_editable(info->group[i].type))
1037 for(r=0; r<info->group[i].len; r++)
1038 val[n+r] = info->group[i].type;
1039 val[n+r] = 0;
1041 else
1043 r = GetWindowTextW( info->group[i].hwnd, &val[n], info->group[i].len+1 );
1044 if( r != info->group[i].len )
1045 break;
1047 n += r;
1050 TRACE("%d/%d controls were good\n", i, info->num_groups);
1052 if( i == info->num_groups )
1054 TRACE("Set property %s to %s\n",
1055 debugstr_w(info->prop), debugstr_w(val) );
1056 CharUpperBuffW( val, info->num_chars );
1057 MSI_SetPropertyW( info->dialog->package, info->prop, val );
1058 msi_dialog_evaluate_control_conditions( info->dialog );
1060 msi_free( val );
1063 /* now move to the next control if necessary */
1064 static VOID msi_mask_next_control( struct msi_maskedit_info *info, HWND hWnd )
1066 HWND hWndNext;
1067 UINT len, i;
1069 for( i=0; i<info->num_groups; i++ )
1070 if( info->group[i].hwnd == hWnd )
1071 break;
1073 /* don't move from the last control */
1074 if( i >= (info->num_groups-1) )
1075 return;
1077 len = SendMessageW( hWnd, WM_GETTEXTLENGTH, 0, 0 );
1078 if( len < info->group[i].len )
1079 return;
1081 hWndNext = GetNextDlgTabItem( GetParent( hWnd ), hWnd, FALSE );
1082 SetFocus( hWndNext );
1085 static LRESULT WINAPI
1086 MSIMaskedEdit_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
1088 struct msi_maskedit_info *info;
1089 HRESULT r;
1091 TRACE("%p %04x %08x %08lx\n", hWnd, msg, wParam, lParam);
1093 info = GetPropW(hWnd, szButtonData);
1095 r = CallWindowProcW(info->oldproc, hWnd, msg, wParam, lParam);
1097 switch( msg )
1099 case WM_COMMAND:
1100 if (HIWORD(wParam) == EN_CHANGE)
1102 msi_mask_control_change( info );
1103 msi_mask_next_control( info, (HWND) lParam );
1105 break;
1106 case WM_NCDESTROY:
1107 msi_free( info->prop );
1108 msi_free( info );
1109 RemovePropW( hWnd, szButtonData );
1110 break;
1113 return r;
1116 /* fish the various bits of the property out and put them in the control */
1117 static void
1118 msi_maskedit_set_text( struct msi_maskedit_info *info, LPCWSTR text )
1120 LPCWSTR p;
1121 UINT i;
1123 p = text;
1124 for( i = 0; i < info->num_groups; i++ )
1126 if( info->group[i].len < lstrlenW( p ) )
1128 LPWSTR chunk = strdupW( p );
1129 chunk[ info->group[i].len ] = 0;
1130 SetWindowTextW( info->group[i].hwnd, chunk );
1131 msi_free( chunk );
1133 else
1135 SetWindowTextW( info->group[i].hwnd, p );
1136 break;
1138 p += info->group[i].len;
1142 static struct msi_maskedit_info * msi_dialog_parse_groups( LPCWSTR mask )
1144 struct msi_maskedit_info * info = NULL;
1145 int i = 0, n = 0, total = 0;
1146 LPCWSTR p;
1148 TRACE("masked control, template %s\n", debugstr_w(mask));
1150 if( !mask )
1151 return info;
1153 info = msi_alloc_zero( sizeof *info );
1154 if( !info )
1155 return info;
1157 p = strchrW(mask, '<');
1158 if( p )
1159 p++;
1160 else
1161 p = mask;
1163 for( i=0; i<MASK_MAX_GROUPS; i++ )
1165 /* stop at the end of the string */
1166 if( p[0] == 0 || p[0] == '>' )
1167 break;
1169 /* count the number of the same identifier */
1170 for( n=0; p[n] == p[0]; n++ )
1172 info->group[i].ofs = total;
1173 info->group[i].type = p[0];
1174 if( p[n] == '=' )
1176 n++;
1177 total++; /* an extra not part of the group */
1179 info->group[i].len = n;
1180 total += n;
1181 p += n;
1184 TRACE("%d characters in %d groups\n", total, i );
1185 if( i == MASK_MAX_GROUPS )
1186 ERR("too many groups in PIDTemplate %s\n", debugstr_w(mask));
1188 info->num_chars = total;
1189 info->num_groups = i;
1191 return info;
1194 static void
1195 msi_maskedit_create_children( struct msi_maskedit_info *info, LPCWSTR font )
1197 DWORD width, height, style, wx, ww;
1198 RECT rect;
1199 HWND hwnd;
1200 UINT i;
1202 style = WS_CHILD | WS_BORDER | WS_VISIBLE | WS_TABSTOP | ES_AUTOHSCROLL;
1204 GetClientRect( info->hwnd, &rect );
1206 width = rect.right - rect.left;
1207 height = rect.bottom - rect.top;
1209 for( i = 0; i < info->num_groups; i++ )
1211 if (!msi_mask_editable( info->group[i].type ))
1212 continue;
1213 wx = (info->group[i].ofs * width) / info->num_chars;
1214 ww = (info->group[i].len * width) / info->num_chars;
1216 hwnd = CreateWindowW( szEdit, NULL, style, wx, 0, ww, height,
1217 info->hwnd, NULL, NULL, NULL );
1218 if( !hwnd )
1220 ERR("failed to create mask edit sub window\n");
1221 break;
1224 SendMessageW( hwnd, EM_LIMITTEXT, info->group[i].len, 0 );
1226 msi_dialog_set_font( info->dialog, hwnd,
1227 font?font:info->dialog->default_font );
1228 info->group[i].hwnd = hwnd;
1233 * office 2003 uses "73931<````=````=````=````=`````>@@@@@"
1234 * delphi 7 uses "<????-??????-??????-????>" and "<???-???>"
1235 * filemaker pro 7 uses "<^^^^=^^^^=^^^^=^^^^=^^^^=^^^^=^^^^^>"
1237 static UINT msi_dialog_maskedit_control( msi_dialog *dialog, MSIRECORD *rec )
1239 LPWSTR font_mask, val = NULL, font;
1240 struct msi_maskedit_info *info = NULL;
1241 UINT ret = ERROR_SUCCESS;
1242 msi_control *control;
1243 LPCWSTR prop, mask;
1245 TRACE("\n");
1247 font_mask = msi_get_deformatted_field( dialog->package, rec, 10 );
1248 font = msi_dialog_get_style( font_mask, &mask );
1249 if( !mask )
1251 ERR("mask template is empty\n");
1252 goto end;
1255 info = msi_dialog_parse_groups( mask );
1256 if( !info )
1258 ERR("template %s is invalid\n", debugstr_w(mask));
1259 goto end;
1262 info->dialog = dialog;
1264 control = msi_dialog_add_control( dialog, rec, szStatic,
1265 SS_OWNERDRAW | WS_GROUP | WS_VISIBLE );
1266 if( !control )
1268 ERR("Failed to create maskedit container\n");
1269 ret = ERROR_FUNCTION_FAILED;
1270 goto end;
1272 SetWindowLongPtrW( control->hwnd, GWL_EXSTYLE, WS_EX_CONTROLPARENT );
1274 info->hwnd = control->hwnd;
1276 /* subclass the static control */
1277 info->oldproc = (WNDPROC) SetWindowLongPtrW( info->hwnd, GWLP_WNDPROC,
1278 (LONG_PTR)MSIMaskedEdit_WndProc );
1279 SetPropW( control->hwnd, szButtonData, info );
1281 prop = MSI_RecordGetString( rec, 9 );
1282 if( prop )
1283 info->prop = strdupW( prop );
1285 msi_maskedit_create_children( info, font );
1287 if( prop )
1289 val = msi_dup_property( dialog->package, prop );
1290 if( val )
1292 msi_maskedit_set_text( info, val );
1293 msi_free( val );
1297 end:
1298 if( ret != ERROR_SUCCESS )
1299 msi_free( info );
1300 msi_free( font_mask );
1301 msi_free( font );
1302 return ret;
1305 /******************** Progress Bar *****************************************/
1307 static UINT msi_dialog_progress_bar( msi_dialog *dialog, MSIRECORD *rec )
1309 msi_dialog_add_control( dialog, rec, PROGRESS_CLASSW, WS_VISIBLE );
1310 return ERROR_SUCCESS;
1313 /******************** Path Edit ********************************************/
1315 static UINT msi_dialog_pathedit_control( msi_dialog *dialog, MSIRECORD *rec )
1317 FIXME("not implemented properly\n");
1318 return msi_dialog_edit_control( dialog, rec );
1321 /* radio buttons are a bit different from normal controls */
1322 static UINT msi_dialog_create_radiobutton( MSIRECORD *rec, LPVOID param )
1324 radio_button_group_descr *group = (radio_button_group_descr *)param;
1325 msi_dialog *dialog = group->dialog;
1326 msi_control *control;
1327 LPCWSTR prop, text, name;
1328 DWORD style, attributes = group->attributes;
1330 style = WS_CHILD | BS_AUTORADIOBUTTON | BS_MULTILINE | WS_TABSTOP;
1331 name = MSI_RecordGetString( rec, 3 );
1332 text = MSI_RecordGetString( rec, 8 );
1333 if( attributes & 1 )
1334 style |= WS_VISIBLE;
1335 if( ~attributes & 2 )
1336 style |= WS_DISABLED;
1338 control = msi_dialog_create_window( dialog, rec, szButton, name, text,
1339 style, group->parent->hwnd );
1340 if (!control)
1341 return ERROR_FUNCTION_FAILED;
1342 control->handler = msi_dialog_radiogroup_handler;
1344 prop = MSI_RecordGetString( rec, 1 );
1345 if( prop )
1346 control->property = strdupW( prop );
1348 return ERROR_SUCCESS;
1351 static UINT msi_dialog_radiogroup_control( msi_dialog *dialog, MSIRECORD *rec )
1353 static const WCHAR query[] = {
1354 'S','E','L','E','C','T',' ','*',' ',
1355 'F','R','O','M',' ','R','a','d','i','o','B','u','t','t','o','n',' ',
1356 'W','H','E','R','E',' ',
1357 '`','P','r','o','p','e','r','t','y','`',' ','=',' ','\'','%','s','\'',0};
1358 UINT r;
1359 LPCWSTR prop;
1360 msi_control *control;
1361 MSIQUERY *view = NULL;
1362 radio_button_group_descr group;
1363 MSIPACKAGE *package = dialog->package;
1364 WNDPROC oldproc;
1366 prop = MSI_RecordGetString( rec, 9 );
1368 TRACE("%p %p %s\n", dialog, rec, debugstr_w( prop ));
1370 /* Create parent group box to hold radio buttons */
1371 control = msi_dialog_add_control( dialog, rec, szButton, BS_OWNERDRAW|WS_GROUP );
1372 if( !control )
1373 return ERROR_FUNCTION_FAILED;
1375 oldproc = (WNDPROC) SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
1376 (LONG_PTR)MSIRadioGroup_WndProc );
1377 SetPropW(control->hwnd, szButtonData, oldproc);
1378 SetWindowLongPtrW( control->hwnd, GWL_EXSTYLE, WS_EX_CONTROLPARENT );
1380 if( prop )
1381 control->property = strdupW( prop );
1383 /* query the Radio Button table for all control in this group */
1384 r = MSI_OpenQuery( package->db, &view, query, prop );
1385 if( r != ERROR_SUCCESS )
1387 ERR("query failed for dialog %s radio group %s\n",
1388 debugstr_w(dialog->name), debugstr_w(prop));
1389 return ERROR_INVALID_PARAMETER;
1392 group.dialog = dialog;
1393 group.parent = control;
1394 group.attributes = MSI_RecordGetInteger( rec, 8 );
1396 r = MSI_IterateRecords( view, 0, msi_dialog_create_radiobutton, &group );
1397 msiobj_release( &view->hdr );
1399 return r;
1402 /******************** Selection Tree ***************************************/
1404 struct msi_selection_tree_info
1406 msi_dialog *dialog;
1407 HWND hwnd;
1408 WNDPROC oldproc;
1411 static void
1412 msi_seltree_sync_item_state( HWND hwnd, MSIFEATURE *feature, HTREEITEM hItem )
1414 TVITEMW tvi;
1416 TRACE("Feature %s -> %d %d %d\n", debugstr_w(feature->Title),
1417 feature->Installed, feature->Action, feature->ActionRequest);
1419 tvi.mask = TVIF_STATE;
1420 tvi.hItem = hItem;
1421 tvi.state = INDEXTOSTATEIMAGEMASK( feature->Action );
1422 tvi.stateMask = TVIS_STATEIMAGEMASK;
1424 SendMessageW( hwnd, TVM_SETITEMW, 0, (LPARAM) &tvi );
1427 static UINT
1428 msi_seltree_popup_menu( HWND hwnd, INT x, INT y )
1430 HMENU hMenu;
1431 INT r;
1433 /* create a menu to display */
1434 hMenu = CreatePopupMenu();
1436 /* FIXME: load strings from resources */
1437 AppendMenuA( hMenu, MF_ENABLED, INSTALLSTATE_LOCAL, "Install feature locally");
1438 AppendMenuA( hMenu, MF_GRAYED, 0x1000, "Install entire feature");
1439 AppendMenuA( hMenu, MF_ENABLED, INSTALLSTATE_ADVERTISED, "Install on demand");
1440 AppendMenuA( hMenu, MF_ENABLED, INSTALLSTATE_ABSENT, "Don't install");
1441 r = TrackPopupMenu( hMenu, TPM_LEFTALIGN | TPM_TOPALIGN | TPM_RETURNCMD,
1442 x, y, 0, hwnd, NULL );
1443 DestroyMenu( hMenu );
1444 return r;
1447 static MSIFEATURE *
1448 msi_seltree_feature_from_item( HWND hwnd, HTREEITEM hItem )
1450 TVITEMW tvi;
1452 /* get the feature from the item */
1453 memset( &tvi, 0, sizeof tvi );
1454 tvi.hItem = hItem;
1455 tvi.mask = TVIF_PARAM | TVIF_HANDLE;
1456 SendMessageW( hwnd, TVM_GETITEMW, 0, (LPARAM) &tvi );
1458 return (MSIFEATURE*) tvi.lParam;
1461 static LRESULT
1462 msi_seltree_menu( HWND hwnd, HTREEITEM hItem )
1464 MSIFEATURE *feature;
1465 union {
1466 RECT rc;
1467 POINT pt[2];
1468 HTREEITEM hItem;
1469 } u;
1470 UINT r;
1472 feature = msi_seltree_feature_from_item( hwnd, hItem );
1473 if (!feature)
1475 ERR("item %p feature was NULL\n", hItem);
1476 return 0;
1479 /* get the item's rectangle to put the menu just below it */
1480 u.hItem = hItem;
1481 SendMessageW( hwnd, TVM_GETITEMRECT, 0, (LPARAM) &u.rc );
1482 MapWindowPoints( hwnd, NULL, u.pt, 2 );
1484 r = msi_seltree_popup_menu( hwnd, u.rc.left, u.rc.top );
1486 switch (r)
1488 case INSTALLSTATE_LOCAL:
1489 case INSTALLSTATE_ADVERTISED:
1490 case INSTALLSTATE_ABSENT:
1491 feature->ActionRequest = r;
1492 feature->Action = r;
1493 break;
1494 default:
1495 FIXME("select feature and all children\n");
1498 /* update */
1499 msi_seltree_sync_item_state( hwnd, feature, hItem );
1501 return 0;
1504 static LRESULT WINAPI
1505 MSISelectionTree_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
1507 struct msi_selection_tree_info *info;
1508 TVHITTESTINFO tvhti;
1509 HRESULT r;
1511 TRACE("%p %04x %08x %08lx\n", hWnd, msg, wParam, lParam);
1513 info = GetPropW(hWnd, szButtonData);
1515 switch( msg )
1517 case WM_LBUTTONDOWN:
1518 tvhti.pt.x = LOWORD( lParam );
1519 tvhti.pt.y = HIWORD( lParam );
1520 tvhti.flags = 0;
1521 tvhti.hItem = 0;
1522 r = CallWindowProcW(info->oldproc, hWnd, TVM_HITTEST, 0, (LPARAM) &tvhti );
1523 if (tvhti.flags & TVHT_ONITEMSTATEICON)
1524 return msi_seltree_menu( hWnd, tvhti.hItem );
1525 break;
1528 r = CallWindowProcW(info->oldproc, hWnd, msg, wParam, lParam);
1530 switch( msg )
1532 case WM_NCDESTROY:
1533 msi_free( info );
1534 RemovePropW( hWnd, szButtonData );
1535 break;
1537 return r;
1540 static void
1541 msi_seltree_add_child_features( MSIPACKAGE *package, HWND hwnd,
1542 LPCWSTR parent, HTREEITEM hParent )
1544 MSIFEATURE *feature;
1545 TVINSERTSTRUCTW tvis;
1546 HTREEITEM hitem;
1548 LIST_FOR_EACH_ENTRY( feature, &package->features, MSIFEATURE, entry )
1550 if ( lstrcmpW( parent, feature->Feature_Parent ) )
1551 continue;
1553 if ( !feature->Title )
1554 continue;
1556 memset( &tvis, 0, sizeof tvis );
1557 tvis.hParent = hParent;
1558 tvis.hInsertAfter = TVI_SORT;
1559 tvis.u.item.mask = TVIF_TEXT | TVIF_PARAM;
1560 tvis.u.item.pszText = feature->Title;
1561 tvis.u.item.lParam = (LPARAM) feature;
1563 hitem = (HTREEITEM) SendMessageW( hwnd, TVM_INSERTITEMW, 0, (LPARAM) &tvis );
1564 if (!hitem)
1565 continue;
1567 msi_seltree_sync_item_state( hwnd, feature, hitem );
1568 msi_seltree_add_child_features( package, hwnd,
1569 feature->Feature, hitem );
1573 static void msi_seltree_create_imagelist( HWND hwnd )
1575 const int bm_width = 32, bm_height = 16, bm_count = 3;
1576 const int bm_resource = 0x1001;
1577 HIMAGELIST himl;
1578 int i;
1579 HBITMAP hbmp;
1581 himl = ImageList_Create( bm_width, bm_height, FALSE, 4, 0 );
1582 if (!himl)
1584 ERR("failed to create image list\n");
1585 return;
1588 for (i=0; i<bm_count; i++)
1590 hbmp = LoadBitmapW( msi_hInstance, MAKEINTRESOURCEW(i+bm_resource) );
1591 if (!hbmp)
1593 ERR("failed to load bitmap %d\n", i);
1594 break;
1598 * Add a dummy bitmap at offset zero because the treeview
1599 * can't use it as a state mask (zero means no user state).
1601 if (!i)
1602 ImageList_Add( himl, hbmp, NULL );
1604 ImageList_Add( himl, hbmp, NULL );
1607 SendMessageW( hwnd, TVM_SETIMAGELIST, TVSIL_STATE, (LPARAM)himl );
1610 static UINT msi_dialog_selection_tree( msi_dialog *dialog, MSIRECORD *rec )
1612 msi_control *control;
1613 LPCWSTR prop;
1614 MSIPACKAGE *package = dialog->package;
1615 DWORD style;
1616 struct msi_selection_tree_info *info;
1618 info = msi_alloc( sizeof *info );
1619 if (!info)
1620 return ERROR_FUNCTION_FAILED;
1622 /* create the treeview control */
1623 prop = MSI_RecordGetString( rec, 9 );
1624 style = TVS_HASLINES | TVS_HASBUTTONS | TVS_LINESATROOT;
1625 style |= WS_GROUP | WS_VSCROLL;
1626 control = msi_dialog_add_control( dialog, rec, WC_TREEVIEWW, style );
1627 if (!control)
1629 msi_free(info);
1630 return ERROR_FUNCTION_FAILED;
1633 /* subclass */
1634 info->dialog = dialog;
1635 info->hwnd = control->hwnd;
1636 info->oldproc = (WNDPROC) SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
1637 (LONG_PTR)MSISelectionTree_WndProc );
1638 SetPropW( control->hwnd, szButtonData, info );
1640 /* initialize it */
1641 msi_seltree_create_imagelist( control->hwnd );
1642 msi_seltree_add_child_features( package, control->hwnd, NULL, NULL );
1644 return ERROR_SUCCESS;
1647 struct control_handler msi_dialog_handler[] =
1649 { szText, msi_dialog_text_control },
1650 { szPushButton, msi_dialog_button_control },
1651 { szLine, msi_dialog_line_control },
1652 { szBitmap, msi_dialog_bitmap_control },
1653 { szCheckBox, msi_dialog_checkbox_control },
1654 { szScrollableText, msi_dialog_scrolltext_control },
1655 { szComboBox, msi_dialog_combo_control },
1656 { szEdit, msi_dialog_edit_control },
1657 { szMaskedEdit, msi_dialog_maskedit_control },
1658 { szPathEdit, msi_dialog_pathedit_control },
1659 { szProgressBar, msi_dialog_progress_bar },
1660 { szRadioButtonGroup, msi_dialog_radiogroup_control },
1661 { szIcon, msi_dialog_icon_control },
1662 { szSelectionTree, msi_dialog_selection_tree },
1665 #define NUM_CONTROL_TYPES (sizeof msi_dialog_handler/sizeof msi_dialog_handler[0])
1667 static UINT msi_dialog_create_controls( MSIRECORD *rec, LPVOID param )
1669 msi_dialog *dialog = param;
1670 LPCWSTR control_type;
1671 UINT i;
1673 /* find and call the function that can create this type of control */
1674 control_type = MSI_RecordGetString( rec, 3 );
1675 for( i=0; i<NUM_CONTROL_TYPES; i++ )
1676 if (!strcmpiW( msi_dialog_handler[i].control_type, control_type ))
1677 break;
1678 if( i != NUM_CONTROL_TYPES )
1679 msi_dialog_handler[i].func( dialog, rec );
1680 else
1681 ERR("no handler for element type %s\n", debugstr_w(control_type));
1683 return ERROR_SUCCESS;
1686 static UINT msi_dialog_fill_controls( msi_dialog *dialog )
1688 static const WCHAR query[] = {
1689 'S','E','L','E','C','T',' ','*',' ',
1690 'F','R','O','M',' ','C','o','n','t','r','o','l',' ',
1691 'W','H','E','R','E',' ',
1692 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',0};
1693 UINT r;
1694 MSIQUERY *view = NULL;
1695 MSIPACKAGE *package = dialog->package;
1697 TRACE("%p %s\n", dialog, debugstr_w(dialog->name) );
1699 /* query the Control table for all the elements of the control */
1700 r = MSI_OpenQuery( package->db, &view, query, dialog->name );
1701 if( r != ERROR_SUCCESS )
1703 ERR("query failed for dialog %s\n", debugstr_w(dialog->name));
1704 return ERROR_INVALID_PARAMETER;
1707 r = MSI_IterateRecords( view, 0, msi_dialog_create_controls, dialog );
1708 msiobj_release( &view->hdr );
1710 return r;
1713 static UINT msi_dialog_set_control_condition( MSIRECORD *rec, LPVOID param )
1715 static const WCHAR szHide[] = { 'H','i','d','e',0 };
1716 static const WCHAR szShow[] = { 'S','h','o','w',0 };
1717 static const WCHAR szDisable[] = { 'D','i','s','a','b','l','e',0 };
1718 static const WCHAR szEnable[] = { 'E','n','a','b','l','e',0 };
1719 msi_dialog *dialog = param;
1720 msi_control *control;
1721 LPCWSTR name, action, condition;
1722 UINT r;
1724 name = MSI_RecordGetString( rec, 2 );
1725 action = MSI_RecordGetString( rec, 3 );
1726 condition = MSI_RecordGetString( rec, 4 );
1727 r = MSI_EvaluateConditionW( dialog->package, condition );
1728 control = msi_dialog_find_control( dialog, name );
1729 if( r == MSICONDITION_TRUE && control )
1731 TRACE("%s control %s\n", debugstr_w(action), debugstr_w(name));
1733 /* FIXME: case sensitive? */
1734 if(!lstrcmpW(action, szHide))
1735 ShowWindow(control->hwnd, SW_HIDE);
1736 else if(!strcmpW(action, szShow))
1737 ShowWindow(control->hwnd, SW_SHOW);
1738 else if(!strcmpW(action, szDisable))
1739 EnableWindow(control->hwnd, FALSE);
1740 else if(!strcmpW(action, szEnable))
1741 EnableWindow(control->hwnd, TRUE);
1742 else
1743 FIXME("Unhandled action %s\n", debugstr_w(action));
1746 return ERROR_SUCCESS;
1749 static UINT msi_dialog_evaluate_control_conditions( msi_dialog *dialog )
1751 static const WCHAR query[] = {
1752 'S','E','L','E','C','T',' ','*',' ',
1753 'F','R','O','M',' ',
1754 'C','o','n','t','r','o','l','C','o','n','d','i','t','i','o','n',' ',
1755 'W','H','E','R','E',' ',
1756 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',0
1758 UINT r;
1759 MSIQUERY *view = NULL;
1760 MSIPACKAGE *package = dialog->package;
1762 TRACE("%p %s\n", dialog, debugstr_w(dialog->name) );
1764 /* query the Control table for all the elements of the control */
1765 r = MSI_OpenQuery( package->db, &view, query, dialog->name );
1766 if( r != ERROR_SUCCESS )
1768 ERR("query failed for dialog %s\n", debugstr_w(dialog->name));
1769 return ERROR_INVALID_PARAMETER;
1772 r = MSI_IterateRecords( view, 0, msi_dialog_set_control_condition, dialog );
1773 msiobj_release( &view->hdr );
1775 return r;
1778 UINT msi_dialog_reset( msi_dialog *dialog )
1780 /* FIXME: should restore the original values of any properties we changed */
1781 return msi_dialog_evaluate_control_conditions( dialog );
1784 /* figure out the height of 10 point MS Sans Serif */
1785 static INT msi_dialog_get_sans_serif_height( HWND hwnd )
1787 static const WCHAR szSansSerif[] = {
1788 'M','S',' ','S','a','n','s',' ','S','e','r','i','f',0 };
1789 LOGFONTW lf;
1790 TEXTMETRICW tm;
1791 BOOL r;
1792 LONG height = 0;
1793 HFONT hFont, hOldFont;
1794 HDC hdc;
1796 hdc = GetDC( hwnd );
1797 if (hdc)
1799 memset( &lf, 0, sizeof lf );
1800 lf.lfHeight = MulDiv(10, GetDeviceCaps(hdc, LOGPIXELSY), 72);
1801 strcpyW( lf.lfFaceName, szSansSerif );
1802 hFont = CreateFontIndirectW(&lf);
1803 if (hFont)
1805 hOldFont = SelectObject( hdc, hFont );
1806 r = GetTextMetricsW( hdc, &tm );
1807 if (r)
1808 height = tm.tmHeight;
1809 SelectObject( hdc, hOldFont );
1810 DeleteObject( hFont );
1812 ReleaseDC( hwnd, hdc );
1814 return height;
1817 /* fetch the associated record from the Dialog table */
1818 static MSIRECORD *msi_get_dialog_record( msi_dialog *dialog )
1820 static const WCHAR query[] = {
1821 'S','E','L','E','C','T',' ','*',' ',
1822 'F','R','O','M',' ','D','i','a','l','o','g',' ',
1823 'W','H','E','R','E',' ',
1824 '`','D','i','a','l','o','g','`',' ','=',' ','\'','%','s','\'',0};
1825 MSIPACKAGE *package = dialog->package;
1826 MSIRECORD *rec = NULL;
1828 TRACE("%p %s\n", dialog, debugstr_w(dialog->name) );
1830 rec = MSI_QueryGetRecord( package->db, query, dialog->name );
1831 if( !rec )
1832 ERR("query failed for dialog %s\n", debugstr_w(dialog->name));
1834 return rec;
1837 static void msi_dialog_adjust_dialog_size( msi_dialog *dialog, LPSIZE sz )
1839 RECT rect;
1840 LONG style;
1842 /* turn the client size into the window rectangle */
1843 rect.left = 0;
1844 rect.top = 0;
1845 rect.right = msi_dialog_scale_unit( dialog, sz->cx );
1846 rect.bottom = msi_dialog_scale_unit( dialog, sz->cy );
1847 style = GetWindowLongPtrW( dialog->hwnd, GWL_STYLE );
1848 AdjustWindowRect( &rect, style, FALSE );
1849 sz->cx = rect.right - rect.left;
1850 sz->cy = rect.bottom - rect.top;
1853 static BOOL msi_control_set_next( msi_control *control, msi_control *next )
1855 return SetWindowPos( next->hwnd, control->hwnd, 0, 0, 0, 0,
1856 SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOREDRAW |
1857 SWP_NOREPOSITION | SWP_NOSENDCHANGING | SWP_NOSIZE );
1860 static UINT msi_dialog_set_tab_order( msi_dialog *dialog )
1862 msi_control *control, *tab_next;
1864 LIST_FOR_EACH_ENTRY( control, &dialog->controls, msi_control, entry )
1866 tab_next = msi_dialog_find_control( dialog, control->tabnext );
1867 if( !tab_next )
1868 continue;
1869 msi_control_set_next( control, tab_next );
1872 return ERROR_SUCCESS;
1875 static void msi_dialog_set_first_control( msi_dialog* dialog, LPCWSTR name )
1877 msi_control *control;
1879 control = msi_dialog_find_control( dialog, name );
1880 if( control )
1881 dialog->hWndFocus = control->hwnd;
1882 else
1883 dialog->hWndFocus = NULL;
1886 static LRESULT msi_dialog_oncreate( HWND hwnd, LPCREATESTRUCTW cs )
1888 static const WCHAR df[] = {
1889 'D','e','f','a','u','l','t','U','I','F','o','n','t',0 };
1890 static const WCHAR dfv[] = {
1891 'M','S',' ','S','h','e','l','l',' ','D','l','g',0 };
1892 msi_dialog *dialog = (msi_dialog*) cs->lpCreateParams;
1893 MSIRECORD *rec = NULL;
1894 LPWSTR title = NULL;
1895 SIZE size;
1897 TRACE("%p %p\n", dialog, dialog->package);
1899 dialog->hwnd = hwnd;
1900 SetWindowLongPtrW( hwnd, GWLP_USERDATA, (LONG_PTR) dialog );
1902 rec = msi_get_dialog_record( dialog );
1903 if( !rec )
1905 TRACE("No record found for dialog %s\n", debugstr_w(dialog->name));
1906 return -1;
1909 dialog->scale = msi_dialog_get_sans_serif_height(dialog->hwnd);
1911 size.cx = MSI_RecordGetInteger( rec, 4 );
1912 size.cy = MSI_RecordGetInteger( rec, 5 );
1913 msi_dialog_adjust_dialog_size( dialog, &size );
1915 dialog->attributes = MSI_RecordGetInteger( rec, 6 );
1917 dialog->default_font = msi_dup_property( dialog->package, df );
1918 if (!dialog->default_font)
1920 dialog->default_font = strdupW(dfv);
1921 if (!dialog->default_font) return -1;
1924 title = msi_get_deformatted_field( dialog->package, rec, 7 );
1925 SetWindowTextW( hwnd, title );
1926 msi_free( title );
1928 SetWindowPos( hwnd, 0, 0, 0, size.cx, size.cy,
1929 SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOREDRAW );
1932 msi_dialog_build_font_list( dialog );
1933 msi_dialog_fill_controls( dialog );
1934 msi_dialog_evaluate_control_conditions( dialog );
1935 msi_dialog_set_tab_order( dialog );
1936 msi_dialog_set_first_control( dialog, MSI_RecordGetString( rec, 8 ) );
1937 msiobj_release( &rec->hdr );
1939 return 0;
1942 static UINT msi_dialog_send_event( msi_dialog *dialog, LPCWSTR event, LPCWSTR arg )
1944 LPWSTR event_fmt = NULL, arg_fmt = NULL;
1946 TRACE("Sending control event %s %s\n", debugstr_w(event), debugstr_w(arg));
1948 deformat_string( dialog->package, event, &event_fmt );
1949 deformat_string( dialog->package, arg, &arg_fmt );
1951 dialog->event_handler( dialog->package, event_fmt, arg_fmt, dialog );
1953 msi_free( event_fmt );
1954 msi_free( arg_fmt );
1956 return ERROR_SUCCESS;
1959 static UINT msi_dialog_set_property( msi_dialog *dialog, LPCWSTR event, LPCWSTR arg )
1961 static const WCHAR szNullArg[] = { '{','}',0 };
1962 LPWSTR p, prop, arg_fmt = NULL;
1963 UINT len;
1965 len = strlenW(event);
1966 prop = msi_alloc( len*sizeof(WCHAR));
1967 strcpyW( prop, &event[1] );
1968 p = strchrW( prop, ']' );
1969 if( p && p[1] == 0 )
1971 *p = 0;
1972 if( strcmpW( szNullArg, arg ) )
1973 deformat_string( dialog->package, arg, &arg_fmt );
1974 MSI_SetPropertyW( dialog->package, prop, arg_fmt );
1975 msi_free( arg_fmt );
1977 else
1978 ERR("Badly formatted property string - what happens?\n");
1979 msi_free( prop );
1980 return ERROR_SUCCESS;
1983 static UINT msi_dialog_control_event( MSIRECORD *rec, LPVOID param )
1985 msi_dialog *dialog = param;
1986 LPCWSTR condition, event, arg;
1987 UINT r;
1989 condition = MSI_RecordGetString( rec, 5 );
1990 r = MSI_EvaluateConditionW( dialog->package, condition );
1991 if( r == MSICONDITION_TRUE )
1993 event = MSI_RecordGetString( rec, 3 );
1994 arg = MSI_RecordGetString( rec, 4 );
1995 if( event[0] == '[' )
1996 msi_dialog_set_property( dialog, event, arg );
1997 else
1998 msi_dialog_send_event( dialog, event, arg );
2001 return ERROR_SUCCESS;
2004 static UINT msi_dialog_button_handler( msi_dialog *dialog,
2005 msi_control *control, WPARAM param )
2007 static const WCHAR query[] = {
2008 'S','E','L','E','C','T',' ','*',' ',
2009 'F','R','O','M',' ','C','o','n','t','r','o','l','E','v','e','n','t',' ',
2010 'W','H','E','R','E',' ',
2011 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',' ',
2012 'A','N','D',' ',
2013 '`','C','o','n','t','r','o','l','_','`',' ','=',' ','\'','%','s','\'',' ',
2014 'O','R','D','E','R',' ','B','Y',' ','`','O','r','d','e','r','i','n','g','`',0
2016 MSIQUERY *view = NULL;
2017 UINT r;
2019 if( HIWORD(param) != BN_CLICKED )
2020 return ERROR_SUCCESS;
2022 r = MSI_OpenQuery( dialog->package->db, &view, query,
2023 dialog->name, control->name );
2024 if( r != ERROR_SUCCESS )
2026 ERR("query failed\n");
2027 return 0;
2030 r = MSI_IterateRecords( view, 0, msi_dialog_control_event, dialog );
2031 msiobj_release( &view->hdr );
2033 return r;
2036 static UINT msi_dialog_get_checkbox_state( msi_dialog *dialog,
2037 msi_control *control )
2039 WCHAR state[2] = { 0 };
2040 DWORD sz = 2;
2042 MSI_GetPropertyW( dialog->package, control->property, state, &sz );
2043 return state[0] ? 1 : 0;
2046 static void msi_dialog_set_checkbox_state( msi_dialog *dialog,
2047 msi_control *control, UINT state )
2049 static const WCHAR szState[] = { '1', 0 };
2050 LPCWSTR val;
2052 /* if uncheck then the property is set to NULL */
2053 if (!state)
2055 MSI_SetPropertyW( dialog->package, control->property, NULL );
2056 return;
2059 /* check for a custom state */
2060 if (control->value && control->value[0])
2061 val = control->value;
2062 else
2063 val = szState;
2065 MSI_SetPropertyW( dialog->package, control->property, val );
2068 static void msi_dialog_checkbox_sync_state( msi_dialog *dialog,
2069 msi_control *control )
2071 UINT state;
2073 state = msi_dialog_get_checkbox_state( dialog, control );
2074 SendMessageW( control->hwnd, BM_SETCHECK,
2075 state ? BST_CHECKED : BST_UNCHECKED, 0 );
2078 static UINT msi_dialog_checkbox_handler( msi_dialog *dialog,
2079 msi_control *control, WPARAM param )
2081 UINT state;
2083 if( HIWORD(param) != BN_CLICKED )
2084 return ERROR_SUCCESS;
2086 TRACE("clicked checkbox %s, set %s\n", debugstr_w(control->name),
2087 debugstr_w(control->property));
2089 state = msi_dialog_get_checkbox_state( dialog, control );
2090 state = state ? 0 : 1;
2091 msi_dialog_set_checkbox_state( dialog, control, state );
2092 msi_dialog_checkbox_sync_state( dialog, control );
2094 return msi_dialog_button_handler( dialog, control, param );
2097 static UINT msi_dialog_edit_handler( msi_dialog *dialog,
2098 msi_control *control, WPARAM param )
2100 UINT sz, r;
2101 LPWSTR buf;
2103 if( HIWORD(param) != EN_CHANGE )
2104 return ERROR_SUCCESS;
2106 TRACE("edit %s contents changed, set %s\n", debugstr_w(control->name),
2107 debugstr_w(control->property));
2109 sz = 0x20;
2110 buf = msi_alloc( sz*sizeof(WCHAR) );
2111 while( buf )
2113 r = GetWindowTextW( control->hwnd, buf, sz );
2114 if( r < (sz-1) )
2115 break;
2116 sz *= 2;
2117 buf = msi_realloc( buf, sz*sizeof(WCHAR) );
2120 MSI_SetPropertyW( dialog->package, control->property, buf );
2122 msi_free( buf );
2124 return ERROR_SUCCESS;
2127 static UINT msi_dialog_radiogroup_handler( msi_dialog *dialog,
2128 msi_control *control, WPARAM param )
2130 if( HIWORD(param) != BN_CLICKED )
2131 return ERROR_SUCCESS;
2133 TRACE("clicked radio button %s, set %s\n", debugstr_w(control->name),
2134 debugstr_w(control->property));
2136 MSI_SetPropertyW( dialog->package, control->property, control->name );
2138 return msi_dialog_button_handler( dialog, control, param );
2141 static LRESULT msi_dialog_oncommand( msi_dialog *dialog, WPARAM param, HWND hwnd )
2143 msi_control *control = NULL;
2145 TRACE("%p %p %08x\n", dialog, hwnd, param);
2147 switch (param)
2149 case 1: /* enter */
2150 control = msi_dialog_find_control( dialog, dialog->control_default );
2151 break;
2152 case 2: /* escape */
2153 control = msi_dialog_find_control( dialog, dialog->control_cancel );
2154 break;
2155 default:
2156 control = msi_dialog_find_control_by_hwnd( dialog, hwnd );
2159 if( control )
2161 if( control->handler )
2163 control->handler( dialog, control, param );
2164 msi_dialog_evaluate_control_conditions( dialog );
2167 else
2168 ERR("button click from nowhere %p %d %p\n", dialog, param, hwnd);
2169 return 0;
2172 static void msi_dialog_setfocus( msi_dialog *dialog )
2174 HWND hwnd = dialog->hWndFocus;
2176 hwnd = GetNextDlgTabItem( dialog->hwnd, hwnd, TRUE);
2177 hwnd = GetNextDlgTabItem( dialog->hwnd, hwnd, FALSE);
2178 SetFocus( hwnd );
2179 dialog->hWndFocus = hwnd;
2182 static LRESULT WINAPI MSIDialog_WndProc( HWND hwnd, UINT msg,
2183 WPARAM wParam, LPARAM lParam )
2185 msi_dialog *dialog = (LPVOID) GetWindowLongPtrW( hwnd, GWLP_USERDATA );
2187 TRACE("0x%04x\n", msg);
2189 switch (msg)
2191 case WM_CREATE:
2192 return msi_dialog_oncreate( hwnd, (LPCREATESTRUCTW)lParam );
2194 case WM_COMMAND:
2195 return msi_dialog_oncommand( dialog, wParam, (HWND)lParam );
2197 case WM_ACTIVATE:
2198 if( LOWORD(wParam) == WA_INACTIVE )
2199 dialog->hWndFocus = GetFocus();
2200 else
2201 msi_dialog_setfocus( dialog );
2202 return 0;
2204 case WM_SETFOCUS:
2205 msi_dialog_setfocus( dialog );
2206 return 0;
2208 /* bounce back to our subclassed static control */
2209 case WM_CTLCOLORSTATIC:
2210 return SendMessageW( (HWND) lParam, WM_CTLCOLORSTATIC, wParam, lParam );
2212 case WM_DESTROY:
2213 dialog->hwnd = NULL;
2214 return 0;
2216 return DefWindowProcW(hwnd, msg, wParam, lParam);
2219 static BOOL CALLBACK msi_radioground_child_enum( HWND hWnd, LPARAM lParam )
2221 EnableWindow( hWnd, lParam );
2222 return TRUE;
2225 static LRESULT WINAPI MSIRadioGroup_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
2227 WNDPROC oldproc = (WNDPROC) GetPropW(hWnd, szButtonData);
2228 LRESULT r;
2230 TRACE("hWnd %p msg %04x wParam 0x%08x lParam 0x%08lx\n", hWnd, msg, wParam, lParam);
2232 if (msg == WM_COMMAND) /* Forward notifications to dialog */
2233 SendMessageW(GetParent(hWnd), msg, wParam, lParam);
2235 r = CallWindowProcW(oldproc, hWnd, msg, wParam, lParam);
2237 /* make sure the radio buttons show as disabled if the parent is disabled */
2238 if (msg == WM_ENABLE)
2239 EnumChildWindows( hWnd, msi_radioground_child_enum, wParam );
2241 return r;
2244 static LRESULT WINAPI MSIHiddenWindowProc( HWND hwnd, UINT msg,
2245 WPARAM wParam, LPARAM lParam )
2247 msi_dialog *dialog = (msi_dialog*) lParam;
2249 TRACE("%d %p\n", msg, dialog);
2251 switch (msg)
2253 case WM_MSI_DIALOG_CREATE:
2254 return msi_dialog_run_message_loop( dialog );
2255 case WM_MSI_DIALOG_DESTROY:
2256 msi_dialog_destroy( dialog );
2257 return 0;
2259 return DefWindowProcW( hwnd, msg, wParam, lParam );
2262 /* functions that interface to other modules within MSI */
2264 msi_dialog *msi_dialog_create( MSIPACKAGE* package, LPCWSTR szDialogName,
2265 msi_dialog_event_handler event_handler )
2267 MSIRECORD *rec = NULL;
2268 msi_dialog *dialog;
2270 TRACE("%p %s\n", package, debugstr_w(szDialogName));
2272 /* allocate the structure for the dialog to use */
2273 dialog = msi_alloc_zero( sizeof *dialog + sizeof(WCHAR)*strlenW(szDialogName) );
2274 if( !dialog )
2275 return NULL;
2276 strcpyW( dialog->name, szDialogName );
2277 msiobj_addref( &package->hdr );
2278 dialog->package = package;
2279 dialog->event_handler = event_handler;
2280 dialog->finished = 0;
2281 list_init( &dialog->controls );
2283 /* verify that the dialog exists */
2284 rec = msi_get_dialog_record( dialog );
2285 if( !rec )
2287 msiobj_release( &package->hdr );
2288 msi_free( dialog );
2289 return NULL;
2291 dialog->attributes = MSI_RecordGetInteger( rec, 6 );
2292 dialog->control_default = strdupW( MSI_RecordGetString( rec, 9 ) );
2293 dialog->control_cancel = strdupW( MSI_RecordGetString( rec, 10 ) );
2294 msiobj_release( &rec->hdr );
2296 return dialog;
2299 static void msi_process_pending_messages( HWND hdlg )
2301 MSG msg;
2303 while( PeekMessageW( &msg, 0, 0, 0, PM_REMOVE ) )
2305 if( hdlg && IsDialogMessageW( hdlg, &msg ))
2306 continue;
2307 TranslateMessage( &msg );
2308 DispatchMessageW( &msg );
2312 void msi_dialog_end_dialog( msi_dialog *dialog )
2314 TRACE("%p\n", dialog);
2315 dialog->finished = 1;
2316 PostMessageW(dialog->hwnd, WM_NULL, 0, 0);
2319 void msi_dialog_check_messages( HANDLE handle )
2321 DWORD r;
2323 /* in threads other than the UI thread, block */
2324 if( uiThreadId != GetCurrentThreadId() )
2326 if( handle )
2327 WaitForSingleObject( handle, INFINITE );
2328 return;
2331 /* there's two choices for the UI thread */
2332 while (1)
2334 msi_process_pending_messages( NULL );
2336 if( !handle )
2337 break;
2340 * block here until somebody creates a new dialog or
2341 * the handle we're waiting on becomes ready
2343 r = MsgWaitForMultipleObjects( 1, &handle, 0, INFINITE, QS_ALLINPUT );
2344 if( r == WAIT_OBJECT_0 )
2345 break;
2349 UINT msi_dialog_run_message_loop( msi_dialog *dialog )
2351 HWND hwnd;
2353 if( !(dialog->attributes & msidbDialogAttributesVisible) )
2354 return ERROR_SUCCESS;
2356 if( uiThreadId != GetCurrentThreadId() )
2357 return SendMessageW( hMsiHiddenWindow, WM_MSI_DIALOG_CREATE, 0, (LPARAM) dialog );
2359 /* create the dialog window, don't show it yet */
2360 hwnd = CreateWindowW( szMsiDialogClass, dialog->name, WS_OVERLAPPEDWINDOW,
2361 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
2362 NULL, NULL, NULL, dialog );
2363 if( !hwnd )
2365 ERR("Failed to create dialog %s\n", debugstr_w( dialog->name ));
2366 return ERROR_FUNCTION_FAILED;
2369 ShowWindow( hwnd, SW_SHOW );
2370 /* UpdateWindow( hwnd ); - and causes the transparent static controls not to paint */
2372 if( dialog->attributes & msidbDialogAttributesModal )
2374 while( !dialog->finished )
2376 MsgWaitForMultipleObjects( 0, NULL, 0, INFINITE, QS_ALLEVENTS );
2377 msi_process_pending_messages( dialog->hwnd );
2380 else
2381 return ERROR_IO_PENDING;
2383 return ERROR_SUCCESS;
2386 void msi_dialog_do_preview( msi_dialog *dialog )
2388 TRACE("\n");
2389 dialog->attributes |= msidbDialogAttributesVisible;
2390 dialog->attributes &= ~msidbDialogAttributesModal;
2391 msi_dialog_run_message_loop( dialog );
2394 void msi_dialog_destroy( msi_dialog *dialog )
2396 if( uiThreadId != GetCurrentThreadId() )
2398 SendMessageW( hMsiHiddenWindow, WM_MSI_DIALOG_DESTROY, 0, (LPARAM) dialog );
2399 return;
2402 if( dialog->hwnd )
2403 ShowWindow( dialog->hwnd, SW_HIDE );
2405 if( dialog->hwnd )
2406 DestroyWindow( dialog->hwnd );
2408 /* destroy the list of controls */
2409 while( !list_empty( &dialog->controls ) )
2411 msi_control *t = LIST_ENTRY( list_head( &dialog->controls ),
2412 msi_control, entry );
2413 list_remove( &t->entry );
2414 /* leave dialog->hwnd - destroying parent destroys child windows */
2415 msi_free( t->property );
2416 msi_free( t->value );
2417 if( t->hBitmap )
2418 DeleteObject( t->hBitmap );
2419 if( t->hIcon )
2420 DestroyIcon( t->hIcon );
2421 msi_free( t->tabnext );
2422 msi_free( t );
2423 if (t->hDll)
2424 FreeLibrary( t->hDll );
2427 /* destroy the list of fonts */
2428 while( dialog->font_list )
2430 msi_font *t = dialog->font_list;
2431 dialog->font_list = t->next;
2432 DeleteObject( t->hfont );
2433 msi_free( t );
2435 msi_free( dialog->default_font );
2437 msi_free( dialog->control_default );
2438 msi_free( dialog->control_cancel );
2439 msiobj_release( &dialog->package->hdr );
2440 dialog->package = NULL;
2441 msi_free( dialog );
2444 BOOL msi_dialog_register_class( void )
2446 WNDCLASSW cls;
2448 ZeroMemory( &cls, sizeof cls );
2449 cls.lpfnWndProc = MSIDialog_WndProc;
2450 cls.hInstance = NULL;
2451 cls.hIcon = LoadIconW(0, (LPWSTR)IDI_APPLICATION);
2452 cls.hCursor = LoadCursorW(0, (LPWSTR)IDC_ARROW);
2453 cls.hbrBackground = (HBRUSH)(COLOR_3DFACE + 1);
2454 cls.lpszMenuName = NULL;
2455 cls.lpszClassName = szMsiDialogClass;
2457 if( !RegisterClassW( &cls ) )
2458 return FALSE;
2460 cls.lpfnWndProc = MSIHiddenWindowProc;
2461 cls.lpszClassName = szMsiHiddenWindow;
2463 if( !RegisterClassW( &cls ) )
2464 return FALSE;
2466 uiThreadId = GetCurrentThreadId();
2468 hMsiHiddenWindow = CreateWindowW( szMsiHiddenWindow, NULL, WS_OVERLAPPED,
2469 0, 0, 100, 100, NULL, NULL, NULL, NULL );
2470 if( !hMsiHiddenWindow )
2471 return FALSE;
2473 return TRUE;
2476 void msi_dialog_unregister_class( void )
2478 DestroyWindow( hMsiHiddenWindow );
2479 hMsiHiddenWindow = NULL;
2480 UnregisterClassW( szMsiDialogClass, NULL );
2481 UnregisterClassW( szMsiHiddenWindow, NULL );
2482 uiThreadId = 0;