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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #define NONAMELESSUNION
23 #define NONAMELESSSTRUCT
42 #include "wine/debug.h"
43 #include "wine/unicode.h"
47 WINE_DEFAULT_DEBUG_CHANNEL(msi);
50 extern HINSTANCE msi_hInstance;
52 struct msi_control_tag;
53 typedef struct msi_control_tag msi_control;
54 typedef UINT (*msi_handler)( msi_dialog *, msi_control *, WPARAM );
56 struct msi_control_tag
68 float progress_current;
74 typedef struct msi_font_tag
76 struct msi_font_tag *next;
85 msi_dialog_event_handler event_handler;
94 LPWSTR control_default;
95 LPWSTR control_cancel;
99 typedef UINT (*msi_dialog_control_func)( msi_dialog *dialog, MSIRECORD *rec );
100 struct control_handler
102 LPCWSTR control_type;
103 msi_dialog_control_func func;
112 } radio_button_group_descr;
114 static const WCHAR szMsiDialogClass[] = {
115 'M','s','i','D','i','a','l','o','g','C','l','o','s','e','C','l','a','s','s',0
117 static const WCHAR szMsiHiddenWindow[] = {
118 'M','s','i','H','i','d','d','e','n','W','i','n','d','o','w',0 };
119 static const WCHAR szStatic[] = { 'S','t','a','t','i','c',0 };
120 static const WCHAR szButton[] = { 'B','U','T','T','O','N', 0 };
121 static const WCHAR szButtonData[] = { 'M','S','I','D','A','T','A',0 };
122 static const WCHAR szProgress[] = { 'P','r','o','g','r','e','s','s',0 };
123 static const WCHAR szText[] = { 'T','e','x','t',0 };
124 static const WCHAR szPushButton[] = { 'P','u','s','h','B','u','t','t','o','n',0 };
125 static const WCHAR szLine[] = { 'L','i','n','e',0 };
126 static const WCHAR szBitmap[] = { 'B','i','t','m','a','p',0 };
127 static const WCHAR szCheckBox[] = { 'C','h','e','c','k','B','o','x',0 };
128 static const WCHAR szScrollableText[] = {
129 'S','c','r','o','l','l','a','b','l','e','T','e','x','t',0 };
130 static const WCHAR szComboBox[] = { 'C','o','m','b','o','B','o','x',0 };
131 static const WCHAR szEdit[] = { 'E','d','i','t',0 };
132 static const WCHAR szMaskedEdit[] = { 'M','a','s','k','e','d','E','d','i','t',0 };
133 static const WCHAR szPathEdit[] = { 'P','a','t','h','E','d','i','t',0 };
134 static const WCHAR szProgressBar[] = {
135 'P','r','o','g','r','e','s','s','B','a','r',0 };
136 static const WCHAR szRadioButtonGroup[] = {
137 'R','a','d','i','o','B','u','t','t','o','n','G','r','o','u','p',0 };
138 static const WCHAR szIcon[] = { 'I','c','o','n',0 };
139 static const WCHAR szSelectionTree[] = {
140 'S','e','l','e','c','t','i','o','n','T','r','e','e',0 };
141 static const WCHAR szGroupBox[] = { 'G','r','o','u','p','B','o','x',0 };
142 static const WCHAR szListBox[] = { 'L','i','s','t','B','o','x',0 };
143 static const WCHAR szDirectoryCombo[] = { 'D','i','r','e','c','t','o','r','y','C','o','m','b','o',0 };
144 static const WCHAR szDirectoryList[] = { 'D','i','r','e','c','t','o','r','y','L','i','s','t',0 };
145 static const WCHAR szVolumeCostList[] = { 'V','o','l','u','m','e','C','o','s','t','L','i','s','t',0 };
147 static UINT msi_dialog_checkbox_handler( msi_dialog *, msi_control *, WPARAM );
148 static void msi_dialog_checkbox_sync_state( msi_dialog *, msi_control * );
149 static UINT msi_dialog_button_handler( msi_dialog *, msi_control *, WPARAM );
150 static UINT msi_dialog_edit_handler( msi_dialog *, msi_control *, WPARAM );
151 static UINT msi_dialog_radiogroup_handler( msi_dialog *, msi_control *, WPARAM param );
152 static UINT msi_dialog_evaluate_control_conditions( msi_dialog *dialog );
153 static LRESULT WINAPI MSIRadioGroup_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
156 /* dialog sequencing */
158 #define WM_MSI_DIALOG_CREATE (WM_USER+0x100)
159 #define WM_MSI_DIALOG_DESTROY (WM_USER+0x101)
161 static DWORD uiThreadId;
162 static HWND hMsiHiddenWindow;
164 static INT msi_dialog_scale_unit( msi_dialog *dialog, INT val )
166 return (dialog->scale * val + 5) / 10;
169 static msi_control *msi_dialog_find_control( msi_dialog *dialog, LPCWSTR name )
171 msi_control *control;
175 LIST_FOR_EACH_ENTRY( control, &dialog->controls, msi_control, entry )
176 if( !strcmpW( control->name, name ) ) /* FIXME: case sensitive? */
181 static msi_control *msi_dialog_find_control_by_type( msi_dialog *dialog, LPCWSTR type )
183 msi_control *control;
187 LIST_FOR_EACH_ENTRY( control, &dialog->controls, msi_control, entry )
188 if( !strcmpW( control->type, type ) ) /* FIXME: case sensitive? */
193 static msi_control *msi_dialog_find_control_by_hwnd( msi_dialog *dialog, HWND hwnd )
195 msi_control *control;
197 LIST_FOR_EACH_ENTRY( control, &dialog->controls, msi_control, entry )
198 if( hwnd == control->hwnd )
203 static LPWSTR msi_get_deformatted_field( MSIPACKAGE *package, MSIRECORD *rec, int field )
205 LPCWSTR str = MSI_RecordGetString( rec, field );
209 deformat_string( package, str, &ret );
213 static LPWSTR msi_dialog_dup_property( msi_dialog *dialog, LPCWSTR property, BOOL indirect )
219 return msi_dup_property( dialog->package, property );
221 return strdupW( property );
225 * msi_dialog_get_style
227 * Extract the {\style} string from the front of the text to display and
228 * update the pointer.
230 static LPWSTR msi_dialog_get_style( LPCWSTR p, LPCWSTR *rest )
241 q = strchrW( p, '}' );
244 if( *p == '\\' || *p == '&' )
247 /* little bit of sanity checking to stop us getting confused with RTF */
249 if( *i == '}' || *i == '\\' )
255 ret = msi_alloc( len*sizeof(WCHAR) );
258 memcpy( ret, p, len*sizeof(WCHAR) );
263 static UINT msi_dialog_add_font( MSIRECORD *rec, LPVOID param )
265 msi_dialog *dialog = param;
272 /* create a font and add it to the list */
273 name = MSI_RecordGetString( rec, 1 );
274 font = msi_alloc( sizeof *font + strlenW( name )*sizeof (WCHAR) );
275 strcpyW( font->name, name );
276 font->next = dialog->font_list;
277 dialog->font_list = font;
279 font->color = MSI_RecordGetInteger( rec, 4 );
281 memset( &lf, 0, sizeof lf );
282 face = MSI_RecordGetString( rec, 2 );
283 lf.lfHeight = MSI_RecordGetInteger( rec, 3 );
284 style = MSI_RecordGetInteger( rec, 5 );
285 if( style & msidbTextStyleStyleBitsBold )
286 lf.lfWeight = FW_BOLD;
287 if( style & msidbTextStyleStyleBitsItalic )
289 if( style & msidbTextStyleStyleBitsUnderline )
290 lf.lfUnderline = TRUE;
291 if( style & msidbTextStyleStyleBitsStrike )
292 lf.lfStrikeOut = TRUE;
293 lstrcpynW( lf.lfFaceName, face, LF_FACESIZE );
295 /* adjust the height */
296 hdc = GetDC( dialog->hwnd );
299 lf.lfHeight = -MulDiv(lf.lfHeight, GetDeviceCaps(hdc, LOGPIXELSY), 72);
300 ReleaseDC( dialog->hwnd, hdc );
303 font->hfont = CreateFontIndirectW( &lf );
305 TRACE("Adding font style %s\n", debugstr_w(font->name) );
307 return ERROR_SUCCESS;
310 static msi_font *msi_dialog_find_font( msi_dialog *dialog, LPCWSTR name )
314 for( font = dialog->font_list; font; font = font->next )
315 if( !strcmpW( font->name, name ) ) /* FIXME: case sensitive? */
321 static UINT msi_dialog_set_font( msi_dialog *dialog, HWND hwnd, LPCWSTR name )
325 font = msi_dialog_find_font( dialog, name );
327 SendMessageW( hwnd, WM_SETFONT, (WPARAM) font->hfont, TRUE );
329 ERR("No font entry for %s\n", debugstr_w(name));
330 return ERROR_SUCCESS;
333 static UINT msi_dialog_build_font_list( msi_dialog *dialog )
335 static const WCHAR query[] = {
336 'S','E','L','E','C','T',' ','*',' ',
337 'F','R','O','M',' ','`','T','e','x','t','S','t','y','l','e','`',' ',0
340 MSIQUERY *view = NULL;
342 TRACE("dialog %p\n", dialog );
344 r = MSI_OpenQuery( dialog->package->db, &view, query );
345 if( r != ERROR_SUCCESS )
348 r = MSI_IterateRecords( view, NULL, msi_dialog_add_font, dialog );
349 msiobj_release( &view->hdr );
354 static msi_control *msi_dialog_create_window( msi_dialog *dialog,
355 MSIRECORD *rec, DWORD exstyle, LPCWSTR szCls, LPCWSTR name, LPCWSTR text,
356 DWORD style, HWND parent )
358 DWORD x, y, width, height;
359 LPWSTR font = NULL, title_font = NULL;
360 LPCWSTR title = NULL;
361 msi_control *control;
365 control = msi_alloc( sizeof *control + strlenW(name)*sizeof(WCHAR) );
366 strcpyW( control->name, name );
367 list_add_head( &dialog->controls, &control->entry );
368 control->handler = NULL;
369 control->property = NULL;
370 control->value = NULL;
371 control->hBitmap = NULL;
372 control->hIcon = NULL;
373 control->hDll = NULL;
374 control->tabnext = strdupW( MSI_RecordGetString( rec, 11) );
375 control->type = strdupW( MSI_RecordGetString( rec, 3 ) );
376 control->progress_current = 0;
377 control->progress_max = 100;
379 x = MSI_RecordGetInteger( rec, 4 );
380 y = MSI_RecordGetInteger( rec, 5 );
381 width = MSI_RecordGetInteger( rec, 6 );
382 height = MSI_RecordGetInteger( rec, 7 );
384 x = msi_dialog_scale_unit( dialog, x );
385 y = msi_dialog_scale_unit( dialog, y );
386 width = msi_dialog_scale_unit( dialog, width );
387 height = msi_dialog_scale_unit( dialog, height );
391 deformat_string( dialog->package, text, &title_font );
392 font = msi_dialog_get_style( title_font, &title );
395 control->hwnd = CreateWindowExW( exstyle, szCls, title, style,
396 x, y, width, height, parent, NULL, NULL, NULL );
398 TRACE("Dialog %s control %s hwnd %p\n",
399 debugstr_w(dialog->name), debugstr_w(text), control->hwnd );
401 msi_dialog_set_font( dialog, control->hwnd,
402 font ? font : dialog->default_font );
404 msi_free( title_font );
410 static MSIRECORD *msi_get_binary_record( MSIDATABASE *db, LPCWSTR name )
412 static const WCHAR query[] = {
413 's','e','l','e','c','t',' ','*',' ',
414 'f','r','o','m',' ','B','i','n','a','r','y',' ',
415 'w','h','e','r','e',' ',
416 '`','N','a','m','e','`',' ','=',' ','\'','%','s','\'',0
419 return MSI_QueryGetRecord( db, query, name );
422 static LPWSTR msi_create_tmp_path(void)
426 static const WCHAR prefix[] = { 'm','s','i',0 };
429 r = GetTempPathW( MAX_PATH, tmp );
432 len = lstrlenW( tmp ) + 20;
433 path = msi_alloc( len * sizeof (WCHAR) );
436 r = GetTempFileNameW( tmp, prefix, 0, path );
447 static HANDLE msi_load_image( MSIDATABASE *db, LPCWSTR name, UINT type,
448 UINT cx, UINT cy, UINT flags )
450 MSIRECORD *rec = NULL;
451 HANDLE himage = NULL;
455 TRACE("%p %s %u %u %08x\n", db, debugstr_w(name), cx, cy, flags);
457 tmp = msi_create_tmp_path();
461 rec = msi_get_binary_record( db, name );
464 r = MSI_RecordStreamToFile( rec, 2, tmp );
465 if( r == ERROR_SUCCESS )
467 himage = LoadImageW( 0, tmp, type, cx, cy, flags );
470 msiobj_release( &rec->hdr );
477 static HICON msi_load_icon( MSIDATABASE *db, LPCWSTR text, UINT attributes )
479 DWORD cx = 0, cy = 0, flags;
481 flags = LR_LOADFROMFILE | LR_DEFAULTSIZE;
482 if( attributes & msidbControlAttributesFixedSize )
484 flags &= ~LR_DEFAULTSIZE;
485 if( attributes & msidbControlAttributesIconSize16 )
490 if( attributes & msidbControlAttributesIconSize32 )
495 /* msidbControlAttributesIconSize48 handled by above logic */
497 return msi_load_image( db, text, IMAGE_ICON, cx, cy, flags );
501 /* called from the Control Event subscription code */
502 void msi_dialog_handle_event( msi_dialog* dialog, LPCWSTR control,
503 LPCWSTR attribute, MSIRECORD *rec )
506 LPCWSTR font_text, text = NULL;
509 ctrl = msi_dialog_find_control( dialog, control );
512 if( !lstrcmpW(attribute, szText) )
514 font_text = MSI_RecordGetString( rec , 1 );
515 font = msi_dialog_get_style( font_text, &text );
516 SetWindowTextW( ctrl->hwnd, text );
518 msi_dialog_check_messages( NULL );
520 else if( !lstrcmpW(attribute, szProgress) )
524 func = MSI_RecordGetInteger( rec , 1 );
525 val = MSI_RecordGetInteger( rec , 2 );
530 ctrl->progress_max = val;
531 ctrl->progress_current = 0;
532 SendMessageW(ctrl->hwnd, PBM_SETRANGE, 0, MAKELPARAM(0,100));
533 SendMessageW(ctrl->hwnd, PBM_SETPOS, 0, 0);
535 case 1: /* FIXME: not sure what this is supposed to do */
538 ctrl->progress_current += val;
539 SendMessageW(ctrl->hwnd, PBM_SETPOS, 100*(ctrl->progress_current/ctrl->progress_max), 0);
542 ERR("Unknown progress message %ld\n", func);
548 FIXME("Attribute %s not being set\n", debugstr_w(attribute));
553 static void msi_dialog_map_events(msi_dialog* dialog, LPCWSTR control)
555 static const WCHAR Query[] = {
556 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
557 '`','E','v','e','n','t','M','a','p','p','i','n','g','`',' ',
558 'W','H','E','R','E',' ',
559 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',' ',
561 '`','C','o','n','t','r','o','l','_','`',' ','=',' ','\'','%','s','\'',0
564 LPCWSTR event, attribute;
566 row = MSI_QueryGetRecord( dialog->package->db, Query, dialog->name, control );
570 event = MSI_RecordGetString( row, 3 );
571 attribute = MSI_RecordGetString( row, 4 );
572 ControlEvent_SubscribeToEvent( dialog->package, event, control, attribute );
573 msiobj_release( &row->hdr );
576 /* everything except radio buttons */
577 static msi_control *msi_dialog_add_control( msi_dialog *dialog,
578 MSIRECORD *rec, LPCWSTR szCls, DWORD style )
584 name = MSI_RecordGetString( rec, 2 );
585 attributes = MSI_RecordGetInteger( rec, 8 );
586 text = MSI_RecordGetString( rec, 10 );
587 if( attributes & msidbControlAttributesVisible )
589 if( ~attributes & msidbControlAttributesEnabled )
590 style |= WS_DISABLED;
591 if( attributes & msidbControlAttributesSunken )
592 exstyle |= WS_EX_CLIENTEDGE;
594 msi_dialog_map_events(dialog, name);
596 return msi_dialog_create_window( dialog, rec, exstyle, szCls, name,
597 text, style, dialog->hwnd );
608 * we don't erase our own background,
609 * so we have to make sure that the parent window redraws first
611 static void msi_text_on_settext( HWND hWnd )
616 hParent = GetParent( hWnd );
617 GetWindowRect( hWnd, &rc );
618 MapWindowPoints( NULL, hParent, (LPPOINT) &rc, 2 );
619 InvalidateRect( hParent, &rc, TRUE );
622 static LRESULT WINAPI
623 MSIText_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
625 struct msi_text_info *info;
628 TRACE("%p %04x %08x %08lx\n", hWnd, msg, wParam, lParam);
630 info = GetPropW(hWnd, szButtonData);
633 SetTextColor( (HDC)wParam, info->font->color );
635 if( msg == WM_CTLCOLORSTATIC &&
636 ( info->attributes & msidbControlAttributesTransparent ) )
638 SetBkMode( (HDC)wParam, TRANSPARENT );
639 return (LRESULT) GetStockObject(NULL_BRUSH);
642 r = CallWindowProcW(info->oldproc, hWnd, msg, wParam, lParam);
647 msi_text_on_settext( hWnd );
651 RemovePropW( hWnd, szButtonData );
658 static UINT msi_dialog_text_control( msi_dialog *dialog, MSIRECORD *rec )
660 msi_control *control;
661 struct msi_text_info *info;
665 TRACE("%p %p\n", dialog, rec);
667 control = msi_dialog_add_control( dialog, rec, szStatic, SS_LEFT | WS_GROUP );
669 return ERROR_FUNCTION_FAILED;
671 info = msi_alloc( sizeof *info );
673 return ERROR_SUCCESS;
675 text = MSI_RecordGetString( rec, 10 );
676 font_name = msi_dialog_get_style( text, &ptr );
677 info->font = ( font_name ) ? msi_dialog_find_font( dialog, font_name ) : NULL;
678 msi_free( font_name );
680 info->attributes = MSI_RecordGetInteger( rec, 8 );
681 if( info->attributes & msidbControlAttributesTransparent )
682 SetWindowLongPtrW( control->hwnd, GWL_EXSTYLE, WS_EX_TRANSPARENT );
684 info->oldproc = (WNDPROC) SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
685 (LONG_PTR)MSIText_WndProc );
686 SetPropW( control->hwnd, szButtonData, info );
688 return ERROR_SUCCESS;
691 static UINT msi_dialog_button_control( msi_dialog *dialog, MSIRECORD *rec )
693 msi_control *control;
694 UINT attributes, style;
697 TRACE("%p %p\n", dialog, rec);
700 attributes = MSI_RecordGetInteger( rec, 8 );
701 if( attributes & msidbControlAttributesIcon )
704 control = msi_dialog_add_control( dialog, rec, szButton, style );
706 return ERROR_FUNCTION_FAILED;
708 control->handler = msi_dialog_button_handler;
711 text = msi_get_deformatted_field( dialog->package, rec, 10 );
712 control->hIcon = msi_load_icon( dialog->package->db, text, attributes );
713 if( attributes & msidbControlAttributesIcon )
714 SendMessageW( control->hwnd, BM_SETIMAGE, IMAGE_ICON, (LPARAM) control->hIcon );
717 return ERROR_SUCCESS;
720 static LPWSTR msi_get_checkbox_value( msi_dialog *dialog, LPCWSTR prop )
722 static const WCHAR query[] = {
723 'S','E','L','E','C','T',' ','*',' ',
724 'F','R','O','M',' ','`','C','h','e','c','k','B','o','x',' ','`',
725 'W','H','E','R','E',' ',
726 '`','P','r','o','p','e','r','t','y','`',' ','=',' ',
729 MSIRECORD *rec = NULL;
732 /* find if there is a value associated with the checkbox */
733 rec = MSI_QueryGetRecord( dialog->package->db, query, prop );
737 ret = msi_get_deformatted_field( dialog->package, rec, 2 );
743 msiobj_release( &rec->hdr );
747 ret = msi_dup_property( dialog->package, prop );
757 static UINT msi_dialog_checkbox_control( msi_dialog *dialog, MSIRECORD *rec )
759 msi_control *control;
762 TRACE("%p %p\n", dialog, rec);
764 control = msi_dialog_add_control( dialog, rec, szButton,
765 BS_CHECKBOX | BS_MULTILINE | WS_TABSTOP );
766 control->handler = msi_dialog_checkbox_handler;
767 prop = MSI_RecordGetString( rec, 9 );
770 control->property = strdupW( prop );
771 control->value = msi_get_checkbox_value( dialog, prop );
772 TRACE("control %s value %s\n", debugstr_w(control->property),
773 debugstr_w(control->value));
775 msi_dialog_checkbox_sync_state( dialog, control );
777 return ERROR_SUCCESS;
780 static UINT msi_dialog_line_control( msi_dialog *dialog, MSIRECORD *rec )
782 TRACE("%p %p\n", dialog, rec);
784 /* line is exactly 2 units in height */
785 MSI_RecordSetInteger( rec, 7, 2 );
787 msi_dialog_add_control( dialog, rec, szStatic, SS_ETCHEDHORZ | SS_SUNKEN );
788 return ERROR_SUCCESS;
791 /******************** Scroll Text ********************************************/
793 struct msi_scrolltext_info
796 msi_control *control;
800 static LRESULT WINAPI
801 MSIScrollText_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
803 struct msi_scrolltext_info *info;
806 TRACE("%p %04x %08x %08lx\n", hWnd, msg, wParam, lParam);
808 info = GetPropW( hWnd, szButtonData );
810 r = CallWindowProcW( info->oldproc, hWnd, msg, wParam, lParam );
816 RemovePropW( hWnd, szButtonData );
819 /* native MSI sets a wait cursor here */
820 msi_dialog_button_handler( info->dialog, info->control, BN_CLICKED );
826 struct msi_streamin_info
833 static DWORD CALLBACK
834 msi_richedit_stream_in( DWORD_PTR arg, LPBYTE buffer, LONG count, LONG *pcb )
836 struct msi_streamin_info *info = (struct msi_streamin_info*) arg;
838 if( (count + info->offset) > info->length )
839 count = info->length - info->offset;
840 memcpy( buffer, &info->string[ info->offset ], count );
842 info->offset += count;
844 TRACE("%ld/%ld\n", info->offset, info->length);
849 static void msi_scrolltext_add_text( msi_control *control, LPCWSTR text )
851 struct msi_streamin_info info;
854 info.string = strdupWtoA( text );
856 info.length = lstrlenA( info.string ) + 1;
858 es.dwCookie = (DWORD_PTR) &info;
860 es.pfnCallback = msi_richedit_stream_in;
862 SendMessageW( control->hwnd, EM_STREAMIN, SF_RTF, (LPARAM) &es );
864 msi_free( info.string );
867 static UINT msi_dialog_scrolltext_control( msi_dialog *dialog, MSIRECORD *rec )
869 static const WCHAR szRichEdit20W[] = {
870 'R','i','c','h','E','d','i','t','2','0','W',0
872 struct msi_scrolltext_info *info;
873 msi_control *control;
877 info = msi_alloc( sizeof *info );
879 return ERROR_FUNCTION_FAILED;
881 hRichedit = LoadLibraryA("riched20");
883 style = WS_BORDER | ES_MULTILINE | WS_VSCROLL |
884 ES_READONLY | ES_AUTOVSCROLL | WS_TABSTOP;
885 control = msi_dialog_add_control( dialog, rec, szRichEdit20W, style );
888 FreeLibrary( hRichedit );
890 return ERROR_FUNCTION_FAILED;
893 control->hDll = hRichedit;
895 info->dialog = dialog;
896 info->control = control;
898 /* subclass the static control */
899 info->oldproc = (WNDPROC) SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
900 (LONG_PTR)MSIScrollText_WndProc );
901 SetPropW( control->hwnd, szButtonData, info );
903 /* add the text into the richedit */
904 msi_scrolltext_add_text( control, MSI_RecordGetString( rec, 10 ) );
906 return ERROR_SUCCESS;
909 static HBITMAP msi_load_picture( MSIDATABASE *db, LPCWSTR name,
910 INT cx, INT cy, DWORD flags )
912 HBITMAP hOleBitmap = 0, hBitmap = 0, hOldSrcBitmap, hOldDestBitmap;
913 MSIRECORD *rec = NULL;
915 IPicture *pic = NULL;
920 rec = msi_get_binary_record( db, name );
924 r = MSI_RecordGetIStream( rec, 2, &stm );
925 msiobj_release( &rec->hdr );
926 if( r != ERROR_SUCCESS )
929 r = OleLoadPicture( stm, 0, TRUE, &IID_IPicture, (LPVOID*) &pic );
930 IStream_Release( stm );
933 ERR("failed to load picture\n");
937 r = IPicture_get_Handle( pic, (OLE_HANDLE*) &hOleBitmap );
940 ERR("failed to get bitmap handle\n");
944 /* make the bitmap the desired size */
945 r = GetObjectW( hOleBitmap, sizeof bm, &bm );
948 ERR("failed to get bitmap size\n");
952 if (flags & LR_DEFAULTSIZE)
958 srcdc = CreateCompatibleDC( NULL );
959 hOldSrcBitmap = SelectObject( srcdc, hOleBitmap );
960 destdc = CreateCompatibleDC( NULL );
961 hBitmap = CreateCompatibleBitmap( srcdc, cx, cy );
962 hOldDestBitmap = SelectObject( destdc, hBitmap );
963 StretchBlt( destdc, 0, 0, cx, cy,
964 srcdc, 0, 0, bm.bmWidth, bm.bmHeight, SRCCOPY);
965 SelectObject( srcdc, hOldSrcBitmap );
966 SelectObject( destdc, hOldDestBitmap );
972 IPicture_Release( pic );
976 static UINT msi_dialog_bitmap_control( msi_dialog *dialog, MSIRECORD *rec )
978 UINT cx, cy, flags, style, attributes;
979 msi_control *control;
982 flags = LR_LOADFROMFILE;
983 style = SS_BITMAP | SS_LEFT | WS_GROUP;
985 attributes = MSI_RecordGetInteger( rec, 8 );
986 if( attributes & msidbControlAttributesFixedSize )
988 flags |= LR_DEFAULTSIZE;
989 style |= SS_CENTERIMAGE;
992 control = msi_dialog_add_control( dialog, rec, szStatic, style );
993 cx = MSI_RecordGetInteger( rec, 6 );
994 cy = MSI_RecordGetInteger( rec, 7 );
995 cx = msi_dialog_scale_unit( dialog, cx );
996 cy = msi_dialog_scale_unit( dialog, cy );
998 text = msi_get_deformatted_field( dialog->package, rec, 10 );
999 control->hBitmap = msi_load_picture( dialog->package->db, text, cx, cy, flags );
1000 if( control->hBitmap )
1001 SendMessageW( control->hwnd, STM_SETIMAGE,
1002 IMAGE_BITMAP, (LPARAM) control->hBitmap );
1004 ERR("Failed to load bitmap %s\n", debugstr_w(text));
1008 return ERROR_SUCCESS;
1011 static UINT msi_dialog_icon_control( msi_dialog *dialog, MSIRECORD *rec )
1013 msi_control *control;
1019 control = msi_dialog_add_control( dialog, rec, szStatic,
1020 SS_ICON | SS_CENTERIMAGE | WS_GROUP );
1022 attributes = MSI_RecordGetInteger( rec, 8 );
1023 text = msi_get_deformatted_field( dialog->package, rec, 10 );
1024 control->hIcon = msi_load_icon( dialog->package->db, text, attributes );
1025 if( control->hIcon )
1026 SendMessageW( control->hwnd, STM_SETICON, (WPARAM) control->hIcon, 0 );
1028 ERR("Failed to load bitmap %s\n", debugstr_w(text));
1030 return ERROR_SUCCESS;
1033 static UINT msi_dialog_combo_control( msi_dialog *dialog, MSIRECORD *rec )
1035 static const WCHAR szCombo[] = { 'C','O','M','B','O','B','O','X',0 };
1037 msi_dialog_add_control( dialog, rec, szCombo,
1038 SS_BITMAP | SS_LEFT | SS_CENTERIMAGE );
1039 return ERROR_SUCCESS;
1042 static UINT msi_dialog_edit_control( msi_dialog *dialog, MSIRECORD *rec )
1044 msi_control *control;
1048 control = msi_dialog_add_control( dialog, rec, szEdit,
1049 WS_BORDER | WS_TABSTOP );
1050 control->handler = msi_dialog_edit_handler;
1051 prop = MSI_RecordGetString( rec, 9 );
1053 control->property = strdupW( prop );
1054 val = msi_dup_property( dialog->package, control->property );
1055 SetWindowTextW( control->hwnd, val );
1057 return ERROR_SUCCESS;
1060 /******************** Masked Edit ********************************************/
1062 #define MASK_MAX_GROUPS 10
1064 struct msi_mask_group
1072 struct msi_maskedit_info
1080 struct msi_mask_group group[MASK_MAX_GROUPS];
1083 static BOOL msi_mask_editable( WCHAR type )
1098 static void msi_mask_control_change( struct msi_maskedit_info *info )
1103 val = msi_alloc( (info->num_chars+1)*sizeof(WCHAR) );
1104 for( i=0, n=0; i<info->num_groups; i++ )
1106 if( (info->group[i].len + n) > info->num_chars )
1108 ERR("can't fit control %d text into template\n",i);
1111 if (!msi_mask_editable(info->group[i].type))
1113 for(r=0; r<info->group[i].len; r++)
1114 val[n+r] = info->group[i].type;
1119 r = GetWindowTextW( info->group[i].hwnd, &val[n], info->group[i].len+1 );
1120 if( r != info->group[i].len )
1126 TRACE("%d/%d controls were good\n", i, info->num_groups);
1128 if( i == info->num_groups )
1130 TRACE("Set property %s to %s\n",
1131 debugstr_w(info->prop), debugstr_w(val) );
1132 CharUpperBuffW( val, info->num_chars );
1133 MSI_SetPropertyW( info->dialog->package, info->prop, val );
1134 msi_dialog_evaluate_control_conditions( info->dialog );
1139 /* now move to the next control if necessary */
1140 static VOID msi_mask_next_control( struct msi_maskedit_info *info, HWND hWnd )
1145 for( i=0; i<info->num_groups; i++ )
1146 if( info->group[i].hwnd == hWnd )
1149 /* don't move from the last control */
1150 if( i >= (info->num_groups-1) )
1153 len = SendMessageW( hWnd, WM_GETTEXTLENGTH, 0, 0 );
1154 if( len < info->group[i].len )
1157 hWndNext = GetNextDlgTabItem( GetParent( hWnd ), hWnd, FALSE );
1158 SetFocus( hWndNext );
1161 static LRESULT WINAPI
1162 MSIMaskedEdit_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
1164 struct msi_maskedit_info *info;
1167 TRACE("%p %04x %08x %08lx\n", hWnd, msg, wParam, lParam);
1169 info = GetPropW(hWnd, szButtonData);
1171 r = CallWindowProcW(info->oldproc, hWnd, msg, wParam, lParam);
1176 if (HIWORD(wParam) == EN_CHANGE)
1178 msi_mask_control_change( info );
1179 msi_mask_next_control( info, (HWND) lParam );
1183 msi_free( info->prop );
1185 RemovePropW( hWnd, szButtonData );
1192 /* fish the various bits of the property out and put them in the control */
1194 msi_maskedit_set_text( struct msi_maskedit_info *info, LPCWSTR text )
1200 for( i = 0; i < info->num_groups; i++ )
1202 if( info->group[i].len < lstrlenW( p ) )
1204 LPWSTR chunk = strdupW( p );
1205 chunk[ info->group[i].len ] = 0;
1206 SetWindowTextW( info->group[i].hwnd, chunk );
1211 SetWindowTextW( info->group[i].hwnd, p );
1214 p += info->group[i].len;
1218 static struct msi_maskedit_info * msi_dialog_parse_groups( LPCWSTR mask )
1220 struct msi_maskedit_info * info = NULL;
1221 int i = 0, n = 0, total = 0;
1224 TRACE("masked control, template %s\n", debugstr_w(mask));
1229 info = msi_alloc_zero( sizeof *info );
1233 p = strchrW(mask, '<');
1239 for( i=0; i<MASK_MAX_GROUPS; i++ )
1241 /* stop at the end of the string */
1242 if( p[0] == 0 || p[0] == '>' )
1245 /* count the number of the same identifier */
1246 for( n=0; p[n] == p[0]; n++ )
1248 info->group[i].ofs = total;
1249 info->group[i].type = p[0];
1253 total++; /* an extra not part of the group */
1255 info->group[i].len = n;
1260 TRACE("%d characters in %d groups\n", total, i );
1261 if( i == MASK_MAX_GROUPS )
1262 ERR("too many groups in PIDTemplate %s\n", debugstr_w(mask));
1264 info->num_chars = total;
1265 info->num_groups = i;
1271 msi_maskedit_create_children( struct msi_maskedit_info *info, LPCWSTR font )
1273 DWORD width, height, style, wx, ww;
1278 style = WS_CHILD | WS_BORDER | WS_VISIBLE | WS_TABSTOP | ES_AUTOHSCROLL;
1280 GetClientRect( info->hwnd, &rect );
1282 width = rect.right - rect.left;
1283 height = rect.bottom - rect.top;
1285 for( i = 0; i < info->num_groups; i++ )
1287 if (!msi_mask_editable( info->group[i].type ))
1289 wx = (info->group[i].ofs * width) / info->num_chars;
1290 ww = (info->group[i].len * width) / info->num_chars;
1292 hwnd = CreateWindowW( szEdit, NULL, style, wx, 0, ww, height,
1293 info->hwnd, NULL, NULL, NULL );
1296 ERR("failed to create mask edit sub window\n");
1300 SendMessageW( hwnd, EM_LIMITTEXT, info->group[i].len, 0 );
1302 msi_dialog_set_font( info->dialog, hwnd,
1303 font?font:info->dialog->default_font );
1304 info->group[i].hwnd = hwnd;
1309 * office 2003 uses "73931<````=````=````=````=`````>@@@@@"
1310 * delphi 7 uses "<????-??????-??????-????>" and "<???-???>"
1311 * filemaker pro 7 uses "<^^^^=^^^^=^^^^=^^^^=^^^^=^^^^=^^^^^>"
1313 static UINT msi_dialog_maskedit_control( msi_dialog *dialog, MSIRECORD *rec )
1315 LPWSTR font_mask, val = NULL, font;
1316 struct msi_maskedit_info *info = NULL;
1317 UINT ret = ERROR_SUCCESS;
1318 msi_control *control;
1323 font_mask = msi_get_deformatted_field( dialog->package, rec, 10 );
1324 font = msi_dialog_get_style( font_mask, &mask );
1327 ERR("mask template is empty\n");
1331 info = msi_dialog_parse_groups( mask );
1334 ERR("template %s is invalid\n", debugstr_w(mask));
1338 info->dialog = dialog;
1340 control = msi_dialog_add_control( dialog, rec, szStatic,
1341 SS_OWNERDRAW | WS_GROUP | WS_VISIBLE );
1344 ERR("Failed to create maskedit container\n");
1345 ret = ERROR_FUNCTION_FAILED;
1348 SetWindowLongPtrW( control->hwnd, GWL_EXSTYLE, WS_EX_CONTROLPARENT );
1350 info->hwnd = control->hwnd;
1352 /* subclass the static control */
1353 info->oldproc = (WNDPROC) SetWindowLongPtrW( info->hwnd, GWLP_WNDPROC,
1354 (LONG_PTR)MSIMaskedEdit_WndProc );
1355 SetPropW( control->hwnd, szButtonData, info );
1357 prop = MSI_RecordGetString( rec, 9 );
1359 info->prop = strdupW( prop );
1361 msi_maskedit_create_children( info, font );
1365 val = msi_dup_property( dialog->package, prop );
1368 msi_maskedit_set_text( info, val );
1374 if( ret != ERROR_SUCCESS )
1376 msi_free( font_mask );
1381 /******************** Progress Bar *****************************************/
1383 static UINT msi_dialog_progress_bar( msi_dialog *dialog, MSIRECORD *rec )
1385 msi_dialog_add_control( dialog, rec, PROGRESS_CLASSW, WS_VISIBLE );
1386 return ERROR_SUCCESS;
1389 /******************** Path Edit ********************************************/
1391 static LPWSTR msi_get_window_text( HWND hwnd )
1397 buf = msi_alloc( sz*sizeof(WCHAR) );
1400 r = GetWindowTextW( hwnd, buf, sz );
1404 buf = msi_realloc( buf, sz*sizeof(WCHAR) );
1410 static UINT msi_dialog_pathedit_handler( msi_dialog *dialog,
1411 msi_control *control, WPARAM param )
1416 if( HIWORD(param) != EN_KILLFOCUS )
1417 return ERROR_SUCCESS;
1419 indirect = control->attributes & msidbControlAttributesIndirect;
1420 prop = msi_dialog_dup_property( dialog, control->property, indirect );
1422 /* FIXME: verify the new path */
1423 buf = msi_get_window_text( control->hwnd );
1424 MSI_SetPropertyW( dialog->package, prop, buf );
1426 TRACE("edit %s contents changed, set %s\n", debugstr_w(control->name),
1432 return ERROR_SUCCESS;
1435 static void msi_dialog_update_pathedit( msi_dialog *dialog, msi_control *control )
1440 if (!control && !(control = msi_dialog_find_control_by_type( dialog, szPathEdit ) ))
1443 indirect = control->attributes & msidbControlAttributesIndirect;
1444 prop = msi_dialog_dup_property( dialog, control->property, indirect );
1446 path = msi_dup_property( dialog->package, prop );
1447 SetWindowTextW( control->hwnd, path );
1448 SendMessageW( control->hwnd, EM_SETSEL, 0, -1 );
1454 static UINT msi_dialog_pathedit_control( msi_dialog *dialog, MSIRECORD *rec )
1456 msi_control *control;
1459 control = msi_dialog_add_control( dialog, rec, szEdit,
1460 WS_BORDER | WS_TABSTOP );
1461 control->handler = msi_dialog_pathedit_handler;
1462 control->attributes = MSI_RecordGetInteger( rec, 8 );
1463 prop = MSI_RecordGetString( rec, 9 );
1464 control->property = msi_dialog_dup_property( dialog, prop, FALSE );
1466 msi_dialog_update_pathedit( dialog, control );
1468 return ERROR_SUCCESS;
1471 /* radio buttons are a bit different from normal controls */
1472 static UINT msi_dialog_create_radiobutton( MSIRECORD *rec, LPVOID param )
1474 radio_button_group_descr *group = (radio_button_group_descr *)param;
1475 msi_dialog *dialog = group->dialog;
1476 msi_control *control;
1477 LPCWSTR prop, text, name;
1478 DWORD style, attributes = group->attributes;
1480 style = WS_CHILD | BS_AUTORADIOBUTTON | BS_MULTILINE | WS_TABSTOP;
1481 name = MSI_RecordGetString( rec, 3 );
1482 text = MSI_RecordGetString( rec, 8 );
1483 if( attributes & 1 )
1484 style |= WS_VISIBLE;
1485 if( ~attributes & 2 )
1486 style |= WS_DISABLED;
1488 control = msi_dialog_create_window( dialog, rec, 0, szButton, name, text,
1489 style, group->parent->hwnd );
1491 return ERROR_FUNCTION_FAILED;
1492 control->handler = msi_dialog_radiogroup_handler;
1494 if (!lstrcmpW(control->name, group->propval))
1495 SendMessageW(control->hwnd, BM_SETCHECK, BST_CHECKED, 0);
1497 prop = MSI_RecordGetString( rec, 1 );
1499 control->property = strdupW( prop );
1501 return ERROR_SUCCESS;
1504 static UINT msi_dialog_radiogroup_control( msi_dialog *dialog, MSIRECORD *rec )
1506 static const WCHAR query[] = {
1507 'S','E','L','E','C','T',' ','*',' ',
1508 'F','R','O','M',' ','R','a','d','i','o','B','u','t','t','o','n',' ',
1509 'W','H','E','R','E',' ',
1510 '`','P','r','o','p','e','r','t','y','`',' ','=',' ','\'','%','s','\'',0};
1513 msi_control *control;
1514 MSIQUERY *view = NULL;
1515 radio_button_group_descr group;
1516 MSIPACKAGE *package = dialog->package;
1519 prop = MSI_RecordGetString( rec, 9 );
1521 TRACE("%p %p %s\n", dialog, rec, debugstr_w( prop ));
1523 /* Create parent group box to hold radio buttons */
1524 control = msi_dialog_add_control( dialog, rec, szButton, BS_OWNERDRAW|WS_GROUP );
1526 return ERROR_FUNCTION_FAILED;
1528 oldproc = (WNDPROC) SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
1529 (LONG_PTR)MSIRadioGroup_WndProc );
1530 SetPropW(control->hwnd, szButtonData, oldproc);
1531 SetWindowLongPtrW( control->hwnd, GWL_EXSTYLE, WS_EX_CONTROLPARENT );
1534 control->property = strdupW( prop );
1536 /* query the Radio Button table for all control in this group */
1537 r = MSI_OpenQuery( package->db, &view, query, prop );
1538 if( r != ERROR_SUCCESS )
1540 ERR("query failed for dialog %s radio group %s\n",
1541 debugstr_w(dialog->name), debugstr_w(prop));
1542 return ERROR_INVALID_PARAMETER;
1545 group.dialog = dialog;
1546 group.parent = control;
1547 group.attributes = MSI_RecordGetInteger( rec, 8 );
1548 group.propval = msi_dup_property( dialog->package, control->property );
1550 r = MSI_IterateRecords( view, 0, msi_dialog_create_radiobutton, &group );
1551 msiobj_release( &view->hdr );
1552 msi_free( group.propval );
1557 /******************** Selection Tree ***************************************/
1559 struct msi_selection_tree_info
1567 msi_seltree_sync_item_state( HWND hwnd, MSIFEATURE *feature, HTREEITEM hItem )
1571 TRACE("Feature %s -> %d %d %d\n", debugstr_w(feature->Title),
1572 feature->Installed, feature->Action, feature->ActionRequest);
1574 tvi.mask = TVIF_STATE;
1576 tvi.state = INDEXTOSTATEIMAGEMASK( feature->Action );
1577 tvi.stateMask = TVIS_STATEIMAGEMASK;
1579 SendMessageW( hwnd, TVM_SETITEMW, 0, (LPARAM) &tvi );
1583 msi_seltree_popup_menu( HWND hwnd, INT x, INT y )
1588 /* create a menu to display */
1589 hMenu = CreatePopupMenu();
1591 /* FIXME: load strings from resources */
1592 AppendMenuA( hMenu, MF_ENABLED, INSTALLSTATE_LOCAL, "Install feature locally");
1593 AppendMenuA( hMenu, MF_GRAYED, 0x1000, "Install entire feature");
1594 AppendMenuA( hMenu, MF_ENABLED, INSTALLSTATE_ADVERTISED, "Install on demand");
1595 AppendMenuA( hMenu, MF_ENABLED, INSTALLSTATE_ABSENT, "Don't install");
1596 r = TrackPopupMenu( hMenu, TPM_LEFTALIGN | TPM_TOPALIGN | TPM_RETURNCMD,
1597 x, y, 0, hwnd, NULL );
1598 DestroyMenu( hMenu );
1603 msi_seltree_feature_from_item( HWND hwnd, HTREEITEM hItem )
1607 /* get the feature from the item */
1608 memset( &tvi, 0, sizeof tvi );
1610 tvi.mask = TVIF_PARAM | TVIF_HANDLE;
1611 SendMessageW( hwnd, TVM_GETITEMW, 0, (LPARAM) &tvi );
1613 return (MSIFEATURE*) tvi.lParam;
1617 msi_seltree_menu( HWND hwnd, HTREEITEM hItem )
1619 MSIFEATURE *feature;
1628 feature = msi_seltree_feature_from_item( hwnd, hItem );
1631 ERR("item %p feature was NULL\n", hItem);
1635 /* get the item's rectangle to put the menu just below it */
1637 SendMessageW( hwnd, TVM_GETITEMRECT, 0, (LPARAM) &u.rc );
1638 MapWindowPoints( hwnd, NULL, u.pt, 2 );
1640 r = msi_seltree_popup_menu( hwnd, u.rc.left, u.rc.top );
1644 case INSTALLSTATE_LOCAL:
1645 case INSTALLSTATE_ADVERTISED:
1646 case INSTALLSTATE_ABSENT:
1647 feature->ActionRequest = r;
1648 feature->Action = r;
1651 FIXME("select feature and all children\n");
1655 msi_seltree_sync_item_state( hwnd, feature, hItem );
1657 /* update the feature's components */
1658 LIST_FOR_EACH_ENTRY( cl, &feature->Components, ComponentList, entry )
1660 cl->component->Action = feature->Action;
1661 cl->component->ActionRequest = feature->ActionRequest;
1667 static LRESULT WINAPI
1668 MSISelectionTree_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
1670 struct msi_selection_tree_info *info;
1671 TVHITTESTINFO tvhti;
1674 TRACE("%p %04x %08x %08lx\n", hWnd, msg, wParam, lParam);
1676 info = GetPropW(hWnd, szButtonData);
1680 case WM_LBUTTONDOWN:
1681 tvhti.pt.x = LOWORD( lParam );
1682 tvhti.pt.y = HIWORD( lParam );
1685 r = CallWindowProcW(info->oldproc, hWnd, TVM_HITTEST, 0, (LPARAM) &tvhti );
1686 if (tvhti.flags & TVHT_ONITEMSTATEICON)
1687 return msi_seltree_menu( hWnd, tvhti.hItem );
1691 r = CallWindowProcW(info->oldproc, hWnd, msg, wParam, lParam);
1697 RemovePropW( hWnd, szButtonData );
1704 msi_seltree_add_child_features( MSIPACKAGE *package, HWND hwnd,
1705 LPCWSTR parent, HTREEITEM hParent )
1707 MSIFEATURE *feature;
1708 TVINSERTSTRUCTW tvis;
1711 LIST_FOR_EACH_ENTRY( feature, &package->features, MSIFEATURE, entry )
1713 if ( lstrcmpW( parent, feature->Feature_Parent ) )
1716 if ( !feature->Title )
1719 if ( !feature->Display )
1722 memset( &tvis, 0, sizeof tvis );
1723 tvis.hParent = hParent;
1724 tvis.hInsertAfter = TVI_LAST;
1725 tvis.u.item.mask = TVIF_TEXT | TVIF_PARAM;
1726 tvis.u.item.pszText = feature->Title;
1727 tvis.u.item.lParam = (LPARAM) feature;
1729 hitem = (HTREEITEM) SendMessageW( hwnd, TVM_INSERTITEMW, 0, (LPARAM) &tvis );
1733 msi_seltree_sync_item_state( hwnd, feature, hitem );
1734 msi_seltree_add_child_features( package, hwnd,
1735 feature->Feature, hitem );
1737 /* the node is expanded if Display is odd */
1738 if ( feature->Display % 2 != 0 )
1739 SendMessageW( hwnd, TVM_EXPAND, TVE_EXPAND, (LPARAM) hitem );
1743 static void msi_seltree_create_imagelist( HWND hwnd )
1745 const int bm_width = 32, bm_height = 16, bm_count = 3;
1746 const int bm_resource = 0x1001;
1751 himl = ImageList_Create( bm_width, bm_height, FALSE, 4, 0 );
1754 ERR("failed to create image list\n");
1758 for (i=0; i<bm_count; i++)
1760 hbmp = LoadBitmapW( msi_hInstance, MAKEINTRESOURCEW(i+bm_resource) );
1763 ERR("failed to load bitmap %d\n", i);
1768 * Add a dummy bitmap at offset zero because the treeview
1769 * can't use it as a state mask (zero means no user state).
1772 ImageList_Add( himl, hbmp, NULL );
1774 ImageList_Add( himl, hbmp, NULL );
1777 SendMessageW( hwnd, TVM_SETIMAGELIST, TVSIL_STATE, (LPARAM)himl );
1780 static UINT msi_dialog_selection_tree( msi_dialog *dialog, MSIRECORD *rec )
1782 msi_control *control;
1784 MSIPACKAGE *package = dialog->package;
1786 struct msi_selection_tree_info *info;
1788 info = msi_alloc( sizeof *info );
1790 return ERROR_FUNCTION_FAILED;
1792 /* create the treeview control */
1793 prop = MSI_RecordGetString( rec, 9 );
1794 style = TVS_HASLINES | TVS_HASBUTTONS | TVS_LINESATROOT;
1795 style |= WS_GROUP | WS_VSCROLL;
1796 control = msi_dialog_add_control( dialog, rec, WC_TREEVIEWW, style );
1800 return ERROR_FUNCTION_FAILED;
1804 info->dialog = dialog;
1805 info->hwnd = control->hwnd;
1806 info->oldproc = (WNDPROC) SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
1807 (LONG_PTR)MSISelectionTree_WndProc );
1808 SetPropW( control->hwnd, szButtonData, info );
1811 msi_seltree_create_imagelist( control->hwnd );
1812 msi_seltree_add_child_features( package, control->hwnd, NULL, NULL );
1814 return ERROR_SUCCESS;
1817 /******************** Group Box ***************************************/
1819 static UINT msi_dialog_group_box( msi_dialog *dialog, MSIRECORD *rec )
1821 msi_control *control;
1824 style = BS_GROUPBOX | WS_CHILD | WS_GROUP;
1825 control = msi_dialog_add_control( dialog, rec, WC_BUTTONW, style );
1827 return ERROR_FUNCTION_FAILED;
1829 return ERROR_SUCCESS;
1832 /******************** List Box ***************************************/
1834 struct msi_listbox_item
1840 struct msi_listbox_info
1846 struct msi_listbox_item *items;
1849 static LRESULT WINAPI MSIListBox_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
1851 struct msi_listbox_info *info;
1855 TRACE("%p %04x %08x %08lx\n", hWnd, msg, wParam, lParam);
1857 info = GetPropW( hWnd, szButtonData );
1861 r = CallWindowProcW( info->oldproc, hWnd, msg, wParam, lParam );
1866 for (j = 0; j < info->num_items; j++)
1868 msi_free( info->items[j].property );
1869 msi_free( info->items[j].value );
1871 msi_free( info->items );
1873 RemovePropW( hWnd, szButtonData );
1880 static UINT msi_listbox_add_item( MSIRECORD *rec, LPVOID param )
1882 struct msi_listbox_info *info = param;
1883 struct msi_listbox_item *item;
1884 LPCWSTR property, value, text;
1885 static int index = 0;
1887 item = &info->items[index++];
1888 property = MSI_RecordGetString( rec, 1 );
1889 value = MSI_RecordGetString( rec, 3 );
1890 text = MSI_RecordGetString( rec, 4 );
1892 item->property = strdupW( property );
1893 item->value = strdupW( value );
1895 SendMessageW( info->hwnd, LB_ADDSTRING, 0, (LPARAM)text );
1897 return ERROR_SUCCESS;
1900 static UINT msi_listbox_add_items( struct msi_listbox_info *info )
1903 MSIQUERY *view = NULL;
1906 static const WCHAR query[] = {
1907 'S','E','L','E','C','T',' ','*',' ',
1908 'F','R','O','M',' ','`','L','i','s','t','B','o','x','`',' ',
1909 'O','R','D','E','R',' ','B','Y',' ','`','O','r','d','e','r','`',0
1912 r = MSI_OpenQuery( info->dialog->package->db, &view, query );
1913 if ( r != ERROR_SUCCESS )
1916 /* just get the number of records */
1917 r = MSI_IterateRecords( view, &count, NULL, NULL );
1919 info->num_items = count;
1920 info->items = msi_alloc( sizeof(*info->items) * count );
1922 r = MSI_IterateRecords( view, NULL, msi_listbox_add_item, info );
1923 msiobj_release( &view->hdr );
1928 static UINT msi_dialog_listbox_handler( msi_dialog *dialog,
1929 msi_control *control, WPARAM param )
1931 struct msi_listbox_info *info;
1934 if( HIWORD(param) != LBN_SELCHANGE )
1935 return ERROR_SUCCESS;
1937 info = GetPropW( control->hwnd, szButtonData );
1938 index = SendMessageW( control->hwnd, LB_GETCURSEL, 0, 0 );
1940 MSI_SetPropertyW( info->dialog->package,
1941 info->items[index].property, info->items[index].value );
1942 msi_dialog_evaluate_control_conditions( info->dialog );
1944 return ERROR_SUCCESS;
1947 static UINT msi_dialog_list_box( msi_dialog *dialog, MSIRECORD *rec )
1949 struct msi_listbox_info *info;
1950 msi_control *control;
1953 info = msi_alloc( sizeof *info );
1955 return ERROR_FUNCTION_FAILED;
1957 style = WS_TABSTOP | WS_GROUP | WS_CHILD | LBS_STANDARD;
1958 control = msi_dialog_add_control( dialog, rec, WC_LISTBOXW, style );
1960 return ERROR_FUNCTION_FAILED;
1962 control->handler = msi_dialog_listbox_handler;
1965 info->dialog = dialog;
1966 info->hwnd = control->hwnd;
1968 info->oldproc = (WNDPROC)SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
1969 (LONG_PTR)MSIListBox_WndProc );
1970 SetPropW( control->hwnd, szButtonData, info );
1972 msi_listbox_add_items( info );
1974 return ERROR_SUCCESS;
1977 /******************** Directory Combo ***************************************/
1979 static void msi_dialog_update_directory_combo( msi_dialog *dialog, msi_control *control )
1984 if (!control && !(control = msi_dialog_find_control_by_type( dialog, szDirectoryCombo )))
1987 indirect = control->attributes & msidbControlAttributesIndirect;
1988 prop = msi_dialog_dup_property( dialog, control->property, indirect );
1989 path = msi_dup_property( dialog->package, prop );
1991 PathStripPathW( path );
1992 PathRemoveBackslashW( path );
1994 SendMessageW( control->hwnd, CB_INSERTSTRING, 0, (LPARAM)path );
1995 SendMessageW( control->hwnd, CB_SETCURSEL, 0, 0 );
2001 static UINT msi_dialog_directory_combo( msi_dialog *dialog, MSIRECORD *rec )
2003 msi_control *control;
2007 /* FIXME: use CBS_OWNERDRAWFIXED and add owner draw code */
2008 style = CBS_DROPDOWNLIST | CBS_HASSTRINGS | WS_CHILD |
2009 WS_GROUP | WS_TABSTOP | WS_VSCROLL;
2010 control = msi_dialog_add_control( dialog, rec, WC_COMBOBOXW, style );
2012 return ERROR_FUNCTION_FAILED;
2014 control->attributes = MSI_RecordGetInteger( rec, 8 );
2015 prop = MSI_RecordGetString( rec, 9 );
2016 control->property = msi_dialog_dup_property( dialog, prop, FALSE );
2018 msi_dialog_update_directory_combo( dialog, control );
2020 return ERROR_SUCCESS;
2023 /******************** Directory List ***************************************/
2025 UINT msi_dialog_directorylist_up( msi_dialog *dialog )
2027 msi_control *control;
2028 LPWSTR prop, path, ptr;
2031 control = msi_dialog_find_control_by_type( dialog, szDirectoryList );
2032 indirect = control->attributes & msidbControlAttributesIndirect;
2033 prop = msi_dialog_dup_property( dialog, control->property, indirect );
2035 path = msi_dup_property( dialog->package, prop );
2037 /* strip off the last directory */
2038 ptr = PathFindFileNameW( path );
2039 if (ptr != path) *(ptr - 1) = '\0';
2040 PathAddBackslashW( path );
2042 MSI_SetPropertyW( dialog->package, prop, path );
2044 msi_dialog_update_directory_combo( dialog, NULL );
2045 msi_dialog_update_pathedit( dialog, NULL );
2050 return ERROR_SUCCESS;
2053 static UINT msi_dialog_directory_list( msi_dialog *dialog, MSIRECORD *rec )
2055 msi_control *control;
2059 style = LVS_LIST | LVS_EDITLABELS | WS_VSCROLL | LVS_SHAREIMAGELISTS |
2060 LVS_AUTOARRANGE | LVS_SINGLESEL | WS_BORDER |
2061 LVS_SORTASCENDING | WS_CHILD | WS_GROUP | WS_TABSTOP;
2062 control = msi_dialog_add_control( dialog, rec, WC_LISTVIEWW, style );
2064 return ERROR_FUNCTION_FAILED;
2066 control->attributes = MSI_RecordGetInteger( rec, 8 );
2067 prop = MSI_RecordGetString( rec, 9 );
2068 control->property = msi_dialog_dup_property( dialog, prop, FALSE );
2070 return ERROR_SUCCESS;
2073 /******************** VolumeCost List ***************************************/
2075 static UINT msi_dialog_volumecost_list( msi_dialog *dialog, MSIRECORD *rec )
2077 msi_control *control;
2080 style = LVS_REPORT | WS_VSCROLL | WS_HSCROLL | LVS_SHAREIMAGELISTS |
2081 LVS_AUTOARRANGE | LVS_SINGLESEL | WS_BORDER |
2082 WS_CHILD | WS_TABSTOP | WS_GROUP;
2083 control = msi_dialog_add_control( dialog, rec, WC_LISTVIEWW, style );
2085 return ERROR_FUNCTION_FAILED;
2087 return ERROR_SUCCESS;
2090 static const struct control_handler msi_dialog_handler[] =
2092 { szText, msi_dialog_text_control },
2093 { szPushButton, msi_dialog_button_control },
2094 { szLine, msi_dialog_line_control },
2095 { szBitmap, msi_dialog_bitmap_control },
2096 { szCheckBox, msi_dialog_checkbox_control },
2097 { szScrollableText, msi_dialog_scrolltext_control },
2098 { szComboBox, msi_dialog_combo_control },
2099 { szEdit, msi_dialog_edit_control },
2100 { szMaskedEdit, msi_dialog_maskedit_control },
2101 { szPathEdit, msi_dialog_pathedit_control },
2102 { szProgressBar, msi_dialog_progress_bar },
2103 { szRadioButtonGroup, msi_dialog_radiogroup_control },
2104 { szIcon, msi_dialog_icon_control },
2105 { szSelectionTree, msi_dialog_selection_tree },
2106 { szGroupBox, msi_dialog_group_box },
2107 { szListBox, msi_dialog_list_box },
2108 { szDirectoryCombo, msi_dialog_directory_combo },
2109 { szDirectoryList, msi_dialog_directory_list },
2110 { szVolumeCostList, msi_dialog_volumecost_list },
2113 #define NUM_CONTROL_TYPES (sizeof msi_dialog_handler/sizeof msi_dialog_handler[0])
2115 static UINT msi_dialog_create_controls( MSIRECORD *rec, LPVOID param )
2117 msi_dialog *dialog = param;
2118 LPCWSTR control_type;
2121 /* find and call the function that can create this type of control */
2122 control_type = MSI_RecordGetString( rec, 3 );
2123 for( i=0; i<NUM_CONTROL_TYPES; i++ )
2124 if (!strcmpiW( msi_dialog_handler[i].control_type, control_type ))
2126 if( i != NUM_CONTROL_TYPES )
2127 msi_dialog_handler[i].func( dialog, rec );
2129 ERR("no handler for element type %s\n", debugstr_w(control_type));
2131 return ERROR_SUCCESS;
2134 static UINT msi_dialog_fill_controls( msi_dialog *dialog )
2136 static const WCHAR query[] = {
2137 'S','E','L','E','C','T',' ','*',' ',
2138 'F','R','O','M',' ','C','o','n','t','r','o','l',' ',
2139 'W','H','E','R','E',' ',
2140 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',0};
2142 MSIQUERY *view = NULL;
2143 MSIPACKAGE *package = dialog->package;
2145 TRACE("%p %s\n", dialog, debugstr_w(dialog->name) );
2147 /* query the Control table for all the elements of the control */
2148 r = MSI_OpenQuery( package->db, &view, query, dialog->name );
2149 if( r != ERROR_SUCCESS )
2151 ERR("query failed for dialog %s\n", debugstr_w(dialog->name));
2152 return ERROR_INVALID_PARAMETER;
2155 r = MSI_IterateRecords( view, 0, msi_dialog_create_controls, dialog );
2156 msiobj_release( &view->hdr );
2161 static UINT msi_dialog_set_control_condition( MSIRECORD *rec, LPVOID param )
2163 static const WCHAR szHide[] = { 'H','i','d','e',0 };
2164 static const WCHAR szShow[] = { 'S','h','o','w',0 };
2165 static const WCHAR szDisable[] = { 'D','i','s','a','b','l','e',0 };
2166 static const WCHAR szEnable[] = { 'E','n','a','b','l','e',0 };
2167 msi_dialog *dialog = param;
2168 msi_control *control;
2169 LPCWSTR name, action, condition;
2172 name = MSI_RecordGetString( rec, 2 );
2173 action = MSI_RecordGetString( rec, 3 );
2174 condition = MSI_RecordGetString( rec, 4 );
2175 r = MSI_EvaluateConditionW( dialog->package, condition );
2176 control = msi_dialog_find_control( dialog, name );
2177 if( r == MSICONDITION_TRUE && control )
2179 TRACE("%s control %s\n", debugstr_w(action), debugstr_w(name));
2181 /* FIXME: case sensitive? */
2182 if(!lstrcmpW(action, szHide))
2183 ShowWindow(control->hwnd, SW_HIDE);
2184 else if(!strcmpW(action, szShow))
2185 ShowWindow(control->hwnd, SW_SHOW);
2186 else if(!strcmpW(action, szDisable))
2187 EnableWindow(control->hwnd, FALSE);
2188 else if(!strcmpW(action, szEnable))
2189 EnableWindow(control->hwnd, TRUE);
2191 FIXME("Unhandled action %s\n", debugstr_w(action));
2194 return ERROR_SUCCESS;
2197 static UINT msi_dialog_evaluate_control_conditions( msi_dialog *dialog )
2199 static const WCHAR query[] = {
2200 'S','E','L','E','C','T',' ','*',' ',
2201 'F','R','O','M',' ',
2202 'C','o','n','t','r','o','l','C','o','n','d','i','t','i','o','n',' ',
2203 'W','H','E','R','E',' ',
2204 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',0
2207 MSIQUERY *view = NULL;
2208 MSIPACKAGE *package = dialog->package;
2210 TRACE("%p %s\n", dialog, debugstr_w(dialog->name) );
2212 /* query the Control table for all the elements of the control */
2213 r = MSI_OpenQuery( package->db, &view, query, dialog->name );
2214 if( r != ERROR_SUCCESS )
2216 ERR("query failed for dialog %s\n", debugstr_w(dialog->name));
2217 return ERROR_INVALID_PARAMETER;
2220 r = MSI_IterateRecords( view, 0, msi_dialog_set_control_condition, dialog );
2221 msiobj_release( &view->hdr );
2226 UINT msi_dialog_reset( msi_dialog *dialog )
2228 /* FIXME: should restore the original values of any properties we changed */
2229 return msi_dialog_evaluate_control_conditions( dialog );
2232 /* figure out the height of 10 point MS Sans Serif */
2233 static INT msi_dialog_get_sans_serif_height( HWND hwnd )
2235 static const WCHAR szSansSerif[] = {
2236 'M','S',' ','S','a','n','s',' ','S','e','r','i','f',0 };
2241 HFONT hFont, hOldFont;
2244 hdc = GetDC( hwnd );
2247 memset( &lf, 0, sizeof lf );
2248 lf.lfHeight = MulDiv(10, GetDeviceCaps(hdc, LOGPIXELSY), 72);
2249 strcpyW( lf.lfFaceName, szSansSerif );
2250 hFont = CreateFontIndirectW(&lf);
2253 hOldFont = SelectObject( hdc, hFont );
2254 r = GetTextMetricsW( hdc, &tm );
2256 height = tm.tmHeight;
2257 SelectObject( hdc, hOldFont );
2258 DeleteObject( hFont );
2260 ReleaseDC( hwnd, hdc );
2265 /* fetch the associated record from the Dialog table */
2266 static MSIRECORD *msi_get_dialog_record( msi_dialog *dialog )
2268 static const WCHAR query[] = {
2269 'S','E','L','E','C','T',' ','*',' ',
2270 'F','R','O','M',' ','D','i','a','l','o','g',' ',
2271 'W','H','E','R','E',' ',
2272 '`','D','i','a','l','o','g','`',' ','=',' ','\'','%','s','\'',0};
2273 MSIPACKAGE *package = dialog->package;
2274 MSIRECORD *rec = NULL;
2276 TRACE("%p %s\n", dialog, debugstr_w(dialog->name) );
2278 rec = MSI_QueryGetRecord( package->db, query, dialog->name );
2280 ERR("query failed for dialog %s\n", debugstr_w(dialog->name));
2285 static void msi_dialog_adjust_dialog_pos( msi_dialog *dialog, MSIRECORD *rec, LPRECT pos )
2287 static const WCHAR szScreenX[] = {'S','c','r','e','e','n','X',0};
2288 static const WCHAR szScreenY[] = {'S','c','r','e','e','n','Y',0};
2295 center.x = MSI_RecordGetInteger( rec, 2 );
2296 center.y = MSI_RecordGetInteger( rec, 3 );
2298 sz.cx = MSI_RecordGetInteger( rec, 4 );
2299 sz.cy = MSI_RecordGetInteger( rec, 5 );
2301 sz.cx = msi_dialog_scale_unit( dialog, sz.cx );
2302 sz.cy = msi_dialog_scale_unit( dialog, sz.cy );
2304 xres = msi_get_property_int( dialog->package, szScreenX, 0 );
2305 yres = msi_get_property_int( dialog->package, szScreenY, 0 );
2307 center.x = MulDiv( center.x, xres, 100 );
2308 center.y = MulDiv( center.y, yres, 100 );
2310 /* turn the client pos into the window rectangle */
2311 pos->left = center.x - sz.cx/2;
2312 pos->right = pos->left + sz.cx;
2313 pos->top = center.y - sz.cy/2;
2314 pos->bottom = pos->top + sz.cy;
2316 TRACE("%lu %lu %lu %lu\n", pos->left, pos->top, pos->right, pos->bottom);
2318 style = GetWindowLongPtrW( dialog->hwnd, GWL_STYLE );
2319 AdjustWindowRect( pos, style, FALSE );
2322 static BOOL msi_control_set_next( msi_control *control, msi_control *next )
2324 return SetWindowPos( next->hwnd, control->hwnd, 0, 0, 0, 0,
2325 SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOREDRAW |
2326 SWP_NOREPOSITION | SWP_NOSENDCHANGING | SWP_NOSIZE );
2329 static UINT msi_dialog_set_tab_order( msi_dialog *dialog )
2331 msi_control *control, *tab_next;
2333 LIST_FOR_EACH_ENTRY( control, &dialog->controls, msi_control, entry )
2335 tab_next = msi_dialog_find_control( dialog, control->tabnext );
2338 msi_control_set_next( control, tab_next );
2341 return ERROR_SUCCESS;
2344 static void msi_dialog_set_first_control( msi_dialog* dialog, LPCWSTR name )
2346 msi_control *control;
2348 control = msi_dialog_find_control( dialog, name );
2350 dialog->hWndFocus = control->hwnd;
2352 dialog->hWndFocus = NULL;
2355 static LRESULT msi_dialog_oncreate( HWND hwnd, LPCREATESTRUCTW cs )
2357 static const WCHAR df[] = {
2358 'D','e','f','a','u','l','t','U','I','F','o','n','t',0 };
2359 static const WCHAR dfv[] = {
2360 'M','S',' ','S','h','e','l','l',' ','D','l','g',0 };
2361 msi_dialog *dialog = (msi_dialog*) cs->lpCreateParams;
2362 MSIRECORD *rec = NULL;
2363 LPWSTR title = NULL;
2366 TRACE("%p %p\n", dialog, dialog->package);
2368 dialog->hwnd = hwnd;
2369 SetWindowLongPtrW( hwnd, GWLP_USERDATA, (LONG_PTR) dialog );
2371 rec = msi_get_dialog_record( dialog );
2374 TRACE("No record found for dialog %s\n", debugstr_w(dialog->name));
2378 dialog->scale = msi_dialog_get_sans_serif_height(dialog->hwnd);
2380 msi_dialog_adjust_dialog_pos( dialog, rec, &pos );
2382 dialog->attributes = MSI_RecordGetInteger( rec, 6 );
2384 dialog->default_font = msi_dup_property( dialog->package, df );
2385 if (!dialog->default_font)
2387 dialog->default_font = strdupW(dfv);
2388 if (!dialog->default_font) return -1;
2391 title = msi_get_deformatted_field( dialog->package, rec, 7 );
2392 SetWindowTextW( hwnd, title );
2395 SetWindowPos( hwnd, 0, pos.left, pos.top,
2396 pos.right - pos.left, pos.bottom - pos.top,
2397 SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOREDRAW );
2399 msi_dialog_build_font_list( dialog );
2400 msi_dialog_fill_controls( dialog );
2401 msi_dialog_evaluate_control_conditions( dialog );
2402 msi_dialog_set_tab_order( dialog );
2403 msi_dialog_set_first_control( dialog, MSI_RecordGetString( rec, 8 ) );
2404 msiobj_release( &rec->hdr );
2409 static UINT msi_dialog_send_event( msi_dialog *dialog, LPCWSTR event, LPCWSTR arg )
2411 LPWSTR event_fmt = NULL, arg_fmt = NULL;
2413 TRACE("Sending control event %s %s\n", debugstr_w(event), debugstr_w(arg));
2415 deformat_string( dialog->package, event, &event_fmt );
2416 deformat_string( dialog->package, arg, &arg_fmt );
2418 dialog->event_handler( dialog->package, event_fmt, arg_fmt, dialog );
2420 msi_free( event_fmt );
2421 msi_free( arg_fmt );
2423 return ERROR_SUCCESS;
2426 static UINT msi_dialog_set_property( msi_dialog *dialog, LPCWSTR event, LPCWSTR arg )
2428 static const WCHAR szNullArg[] = { '{','}',0 };
2429 LPWSTR p, prop, arg_fmt = NULL;
2432 len = strlenW(event);
2433 prop = msi_alloc( len*sizeof(WCHAR));
2434 strcpyW( prop, &event[1] );
2435 p = strchrW( prop, ']' );
2436 if( p && p[1] == 0 )
2439 if( strcmpW( szNullArg, arg ) )
2440 deformat_string( dialog->package, arg, &arg_fmt );
2441 MSI_SetPropertyW( dialog->package, prop, arg_fmt );
2442 msi_free( arg_fmt );
2445 ERR("Badly formatted property string - what happens?\n");
2447 return ERROR_SUCCESS;
2450 static UINT msi_dialog_control_event( MSIRECORD *rec, LPVOID param )
2452 msi_dialog *dialog = param;
2453 LPCWSTR condition, event, arg;
2456 condition = MSI_RecordGetString( rec, 5 );
2457 r = MSI_EvaluateConditionW( dialog->package, condition );
2458 if( r == MSICONDITION_TRUE || r == MSICONDITION_NONE )
2460 event = MSI_RecordGetString( rec, 3 );
2461 arg = MSI_RecordGetString( rec, 4 );
2462 if( event[0] == '[' )
2463 msi_dialog_set_property( dialog, event, arg );
2465 msi_dialog_send_event( dialog, event, arg );
2468 return ERROR_SUCCESS;
2471 static UINT msi_dialog_button_handler( msi_dialog *dialog,
2472 msi_control *control, WPARAM param )
2474 static const WCHAR query[] = {
2475 'S','E','L','E','C','T',' ','*',' ',
2476 'F','R','O','M',' ','C','o','n','t','r','o','l','E','v','e','n','t',' ',
2477 'W','H','E','R','E',' ',
2478 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',' ',
2480 '`','C','o','n','t','r','o','l','_','`',' ','=',' ','\'','%','s','\'',' ',
2481 'O','R','D','E','R',' ','B','Y',' ','`','O','r','d','e','r','i','n','g','`',0
2483 MSIQUERY *view = NULL;
2486 if( HIWORD(param) != BN_CLICKED )
2487 return ERROR_SUCCESS;
2489 r = MSI_OpenQuery( dialog->package->db, &view, query,
2490 dialog->name, control->name );
2491 if( r != ERROR_SUCCESS )
2493 ERR("query failed\n");
2497 r = MSI_IterateRecords( view, 0, msi_dialog_control_event, dialog );
2498 msiobj_release( &view->hdr );
2503 static UINT msi_dialog_get_checkbox_state( msi_dialog *dialog,
2504 msi_control *control )
2506 WCHAR state[2] = { 0 };
2509 MSI_GetPropertyW( dialog->package, control->property, state, &sz );
2510 return state[0] ? 1 : 0;
2513 static void msi_dialog_set_checkbox_state( msi_dialog *dialog,
2514 msi_control *control, UINT state )
2516 static const WCHAR szState[] = { '1', 0 };
2519 /* if uncheck then the property is set to NULL */
2522 MSI_SetPropertyW( dialog->package, control->property, NULL );
2526 /* check for a custom state */
2527 if (control->value && control->value[0])
2528 val = control->value;
2532 MSI_SetPropertyW( dialog->package, control->property, val );
2535 static void msi_dialog_checkbox_sync_state( msi_dialog *dialog,
2536 msi_control *control )
2540 state = msi_dialog_get_checkbox_state( dialog, control );
2541 SendMessageW( control->hwnd, BM_SETCHECK,
2542 state ? BST_CHECKED : BST_UNCHECKED, 0 );
2545 static UINT msi_dialog_checkbox_handler( msi_dialog *dialog,
2546 msi_control *control, WPARAM param )
2550 if( HIWORD(param) != BN_CLICKED )
2551 return ERROR_SUCCESS;
2553 TRACE("clicked checkbox %s, set %s\n", debugstr_w(control->name),
2554 debugstr_w(control->property));
2556 state = msi_dialog_get_checkbox_state( dialog, control );
2557 state = state ? 0 : 1;
2558 msi_dialog_set_checkbox_state( dialog, control, state );
2559 msi_dialog_checkbox_sync_state( dialog, control );
2561 return msi_dialog_button_handler( dialog, control, param );
2564 static UINT msi_dialog_edit_handler( msi_dialog *dialog,
2565 msi_control *control, WPARAM param )
2569 if( HIWORD(param) != EN_CHANGE )
2570 return ERROR_SUCCESS;
2572 TRACE("edit %s contents changed, set %s\n", debugstr_w(control->name),
2573 debugstr_w(control->property));
2575 buf = msi_get_window_text( control->hwnd );
2576 MSI_SetPropertyW( dialog->package, control->property, buf );
2580 return ERROR_SUCCESS;
2583 static UINT msi_dialog_radiogroup_handler( msi_dialog *dialog,
2584 msi_control *control, WPARAM param )
2586 if( HIWORD(param) != BN_CLICKED )
2587 return ERROR_SUCCESS;
2589 TRACE("clicked radio button %s, set %s\n", debugstr_w(control->name),
2590 debugstr_w(control->property));
2592 MSI_SetPropertyW( dialog->package, control->property, control->name );
2594 return msi_dialog_button_handler( dialog, control, param );
2597 static LRESULT msi_dialog_oncommand( msi_dialog *dialog, WPARAM param, HWND hwnd )
2599 msi_control *control = NULL;
2601 TRACE("%p %p %08x\n", dialog, hwnd, param);
2606 control = msi_dialog_find_control( dialog, dialog->control_default );
2608 case 2: /* escape */
2609 control = msi_dialog_find_control( dialog, dialog->control_cancel );
2612 control = msi_dialog_find_control_by_hwnd( dialog, hwnd );
2617 if( control->handler )
2619 control->handler( dialog, control, param );
2620 msi_dialog_evaluate_control_conditions( dialog );
2624 ERR("button click from nowhere %p %d %p\n", dialog, param, hwnd);
2628 static void msi_dialog_setfocus( msi_dialog *dialog )
2630 HWND hwnd = dialog->hWndFocus;
2632 hwnd = GetNextDlgTabItem( dialog->hwnd, hwnd, TRUE);
2633 hwnd = GetNextDlgTabItem( dialog->hwnd, hwnd, FALSE);
2635 dialog->hWndFocus = hwnd;
2638 static LRESULT WINAPI MSIDialog_WndProc( HWND hwnd, UINT msg,
2639 WPARAM wParam, LPARAM lParam )
2641 msi_dialog *dialog = (LPVOID) GetWindowLongPtrW( hwnd, GWLP_USERDATA );
2643 TRACE("0x%04x\n", msg);
2648 return msi_dialog_oncreate( hwnd, (LPCREATESTRUCTW)lParam );
2651 return msi_dialog_oncommand( dialog, wParam, (HWND)lParam );
2654 if( LOWORD(wParam) == WA_INACTIVE )
2655 dialog->hWndFocus = GetFocus();
2657 msi_dialog_setfocus( dialog );
2661 msi_dialog_setfocus( dialog );
2664 /* bounce back to our subclassed static control */
2665 case WM_CTLCOLORSTATIC:
2666 return SendMessageW( (HWND) lParam, WM_CTLCOLORSTATIC, wParam, lParam );
2669 dialog->hwnd = NULL;
2672 return DefWindowProcW(hwnd, msg, wParam, lParam);
2675 static BOOL CALLBACK msi_radioground_child_enum( HWND hWnd, LPARAM lParam )
2677 EnableWindow( hWnd, lParam );
2681 static LRESULT WINAPI MSIRadioGroup_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
2683 WNDPROC oldproc = (WNDPROC) GetPropW(hWnd, szButtonData);
2686 TRACE("hWnd %p msg %04x wParam 0x%08x lParam 0x%08lx\n", hWnd, msg, wParam, lParam);
2688 if (msg == WM_COMMAND) /* Forward notifications to dialog */
2689 SendMessageW(GetParent(hWnd), msg, wParam, lParam);
2691 r = CallWindowProcW(oldproc, hWnd, msg, wParam, lParam);
2693 /* make sure the radio buttons show as disabled if the parent is disabled */
2694 if (msg == WM_ENABLE)
2695 EnumChildWindows( hWnd, msi_radioground_child_enum, wParam );
2700 static LRESULT WINAPI MSIHiddenWindowProc( HWND hwnd, UINT msg,
2701 WPARAM wParam, LPARAM lParam )
2703 msi_dialog *dialog = (msi_dialog*) lParam;
2705 TRACE("%d %p\n", msg, dialog);
2709 case WM_MSI_DIALOG_CREATE:
2710 return msi_dialog_run_message_loop( dialog );
2711 case WM_MSI_DIALOG_DESTROY:
2712 msi_dialog_destroy( dialog );
2715 return DefWindowProcW( hwnd, msg, wParam, lParam );
2718 /* functions that interface to other modules within MSI */
2720 msi_dialog *msi_dialog_create( MSIPACKAGE* package, LPCWSTR szDialogName,
2721 msi_dialog_event_handler event_handler )
2723 MSIRECORD *rec = NULL;
2726 TRACE("%p %s\n", package, debugstr_w(szDialogName));
2728 /* allocate the structure for the dialog to use */
2729 dialog = msi_alloc_zero( sizeof *dialog + sizeof(WCHAR)*strlenW(szDialogName) );
2732 strcpyW( dialog->name, szDialogName );
2733 msiobj_addref( &package->hdr );
2734 dialog->package = package;
2735 dialog->event_handler = event_handler;
2736 dialog->finished = 0;
2737 list_init( &dialog->controls );
2739 /* verify that the dialog exists */
2740 rec = msi_get_dialog_record( dialog );
2743 msiobj_release( &package->hdr );
2747 dialog->attributes = MSI_RecordGetInteger( rec, 6 );
2748 dialog->control_default = strdupW( MSI_RecordGetString( rec, 9 ) );
2749 dialog->control_cancel = strdupW( MSI_RecordGetString( rec, 10 ) );
2750 msiobj_release( &rec->hdr );
2755 static void msi_process_pending_messages( HWND hdlg )
2759 while( PeekMessageW( &msg, 0, 0, 0, PM_REMOVE ) )
2761 if( hdlg && IsDialogMessageW( hdlg, &msg ))
2763 TranslateMessage( &msg );
2764 DispatchMessageW( &msg );
2768 void msi_dialog_end_dialog( msi_dialog *dialog )
2770 TRACE("%p\n", dialog);
2771 dialog->finished = 1;
2772 PostMessageW(dialog->hwnd, WM_NULL, 0, 0);
2775 void msi_dialog_check_messages( HANDLE handle )
2779 /* in threads other than the UI thread, block */
2780 if( uiThreadId != GetCurrentThreadId() )
2783 WaitForSingleObject( handle, INFINITE );
2787 /* there's two choices for the UI thread */
2790 msi_process_pending_messages( NULL );
2796 * block here until somebody creates a new dialog or
2797 * the handle we're waiting on becomes ready
2799 r = MsgWaitForMultipleObjects( 1, &handle, 0, INFINITE, QS_ALLINPUT );
2800 if( r == WAIT_OBJECT_0 )
2805 UINT msi_dialog_run_message_loop( msi_dialog *dialog )
2810 if( uiThreadId != GetCurrentThreadId() )
2811 return SendMessageW( hMsiHiddenWindow, WM_MSI_DIALOG_CREATE, 0, (LPARAM) dialog );
2813 /* create the dialog window, don't show it yet */
2814 style = WS_OVERLAPPED;
2815 if( dialog->attributes & msidbDialogAttributesVisible )
2816 style |= WS_VISIBLE;
2818 hwnd = CreateWindowW( szMsiDialogClass, dialog->name, style,
2819 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
2820 NULL, NULL, NULL, dialog );
2823 ERR("Failed to create dialog %s\n", debugstr_w( dialog->name ));
2824 return ERROR_FUNCTION_FAILED;
2827 ShowWindow( hwnd, SW_SHOW );
2828 /* UpdateWindow( hwnd ); - and causes the transparent static controls not to paint */
2830 if( dialog->attributes & msidbDialogAttributesModal )
2832 while( !dialog->finished )
2834 MsgWaitForMultipleObjects( 0, NULL, 0, INFINITE, QS_ALLINPUT );
2835 msi_process_pending_messages( dialog->hwnd );
2839 return ERROR_IO_PENDING;
2841 return ERROR_SUCCESS;
2844 void msi_dialog_do_preview( msi_dialog *dialog )
2847 dialog->attributes |= msidbDialogAttributesVisible;
2848 dialog->attributes &= ~msidbDialogAttributesModal;
2849 msi_dialog_run_message_loop( dialog );
2852 void msi_dialog_destroy( msi_dialog *dialog )
2854 if( uiThreadId != GetCurrentThreadId() )
2856 SendMessageW( hMsiHiddenWindow, WM_MSI_DIALOG_DESTROY, 0, (LPARAM) dialog );
2861 ShowWindow( dialog->hwnd, SW_HIDE );
2864 DestroyWindow( dialog->hwnd );
2866 /* destroy the list of controls */
2867 while( !list_empty( &dialog->controls ) )
2869 msi_control *t = LIST_ENTRY( list_head( &dialog->controls ),
2870 msi_control, entry );
2871 list_remove( &t->entry );
2872 /* leave dialog->hwnd - destroying parent destroys child windows */
2873 msi_free( t->property );
2874 msi_free( t->value );
2876 DeleteObject( t->hBitmap );
2878 DestroyIcon( t->hIcon );
2879 msi_free( t->tabnext );
2880 msi_free( t->type );
2883 FreeLibrary( t->hDll );
2886 /* destroy the list of fonts */
2887 while( dialog->font_list )
2889 msi_font *t = dialog->font_list;
2890 dialog->font_list = t->next;
2891 DeleteObject( t->hfont );
2894 msi_free( dialog->default_font );
2896 msi_free( dialog->control_default );
2897 msi_free( dialog->control_cancel );
2898 msiobj_release( &dialog->package->hdr );
2899 dialog->package = NULL;
2903 BOOL msi_dialog_register_class( void )
2907 ZeroMemory( &cls, sizeof cls );
2908 cls.lpfnWndProc = MSIDialog_WndProc;
2909 cls.hInstance = NULL;
2910 cls.hIcon = LoadIconW(0, (LPWSTR)IDI_APPLICATION);
2911 cls.hCursor = LoadCursorW(0, (LPWSTR)IDC_ARROW);
2912 cls.hbrBackground = (HBRUSH)(COLOR_3DFACE + 1);
2913 cls.lpszMenuName = NULL;
2914 cls.lpszClassName = szMsiDialogClass;
2916 if( !RegisterClassW( &cls ) )
2919 cls.lpfnWndProc = MSIHiddenWindowProc;
2920 cls.lpszClassName = szMsiHiddenWindow;
2922 if( !RegisterClassW( &cls ) )
2925 uiThreadId = GetCurrentThreadId();
2927 hMsiHiddenWindow = CreateWindowW( szMsiHiddenWindow, NULL, WS_OVERLAPPED,
2928 0, 0, 100, 100, NULL, NULL, NULL, NULL );
2929 if( !hMsiHiddenWindow )
2935 void msi_dialog_unregister_class( void )
2937 DestroyWindow( hMsiHiddenWindow );
2938 hMsiHiddenWindow = NULL;
2939 UnregisterClassW( szMsiDialogClass, NULL );
2940 UnregisterClassW( szMsiHiddenWindow, NULL );