* Implementation of the Microsoft Installer (msi.dll)
*
* Copyright 2005 Mike McCormack for CodeWeavers
+ * Copyright 2005 Aric Stewart for CodeWeavers
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
#include <winreg.h>
#include <shlwapi.h>
#include <msiserver.h>
+#include <shellapi.h>
#include <wine/debug.h>
#include <wine/unicode.h>
typedef struct msi_control_tag msi_control;
typedef UINT (*msi_handler)( msi_dialog *, msi_control *, WPARAM );
typedef void (*msi_update)( msi_dialog *, msi_control * );
+typedef UINT (*control_event_handler)( msi_dialog *, const WCHAR *, const WCHAR * );
struct msi_control_tag
{
{
MSIPACKAGE *package;
msi_dialog *parent;
- msi_dialog_event_handler event_handler;
+ control_event_handler event_handler;
BOOL finished;
INT scale;
DWORD attributes;
WCHAR name[1];
};
+struct subscriber
+{
+ struct list entry;
+ msi_dialog *dialog;
+ WCHAR *event;
+ WCHAR *control;
+ WCHAR *attribute;
+};
+
typedef UINT (*msi_dialog_control_func)( msi_dialog *dialog, MSIRECORD *rec );
struct control_handler
{
static const WCHAR szSelectionDescription[] = {'S','e','l','e','c','t','i','o','n','D','e','s','c','r','i','p','t','i','o','n',0};
static const WCHAR szSelectionPath[] = {'S','e','l','e','c','t','i','o','n','P','a','t','h',0};
static const WCHAR szProperty[] = {'P','r','o','p','e','r','t','y',0};
+static const WCHAR szHyperLink[] = {'H','y','p','e','r','L','i','n','k',0};
/* dialog sequencing */
return prop;
}
-msi_dialog *msi_dialog_get_parent( msi_dialog *dialog )
-{
- return dialog->parent;
-}
-
-LPWSTR msi_dialog_get_name( msi_dialog *dialog )
-{
- return dialog->name;
-}
-
/*
* msi_dialog_get_style
*
msi_free( t );
}
-static msi_control *msi_dialog_create_window( msi_dialog *dialog,
- MSIRECORD *rec, DWORD exstyle, LPCWSTR szCls, LPCWSTR name, LPCWSTR text,
- DWORD style, HWND parent )
+static msi_control *dialog_create_window( msi_dialog *dialog, MSIRECORD *rec, DWORD exstyle,
+ const WCHAR *szCls, const WCHAR *name, const WCHAR *text,
+ DWORD style, HWND parent )
{
DWORD x, y, width, height;
LPWSTR font = NULL, title_font = NULL;
return msi_seltree_feature_from_item( control->hwnd, info->selected );
}
-/* called from the Control Event subscription code */
-void msi_dialog_handle_event( msi_dialog* dialog, LPCWSTR control,
- LPCWSTR attribute, MSIRECORD *rec )
+static void dialog_handle_event( msi_dialog *dialog, const WCHAR *control,
+ const WCHAR *attribute, MSIRECORD *rec )
{
msi_control* ctrl;
- LPCWSTR font_text, text = NULL;
- LPWSTR font;
ctrl = msi_dialog_find_control( dialog, control );
if (!ctrl)
return;
if( !strcmpW( attribute, szText ) )
{
+ const WCHAR *font_text, *text = NULL;
+ WCHAR *font, *text_fmt = NULL;
+
font_text = MSI_RecordGetString( rec , 1 );
font = msi_dialog_get_style( font_text, &text );
- if (!text) text = szEmpty;
+ deformat_string( dialog->package, text, &text_fmt );
+ if (text_fmt) text = text_fmt;
+ else text = szEmpty;
+
SetWindowTextW( ctrl->hwnd, text );
+
msi_free( font );
+ msi_free( text_fmt );
msi_dialog_check_messages( NULL );
}
else if( !strcmpW( attribute, szProgress ) )
}
}
-static void msi_dialog_map_events(msi_dialog* dialog, LPCWSTR control)
+static void event_subscribe( msi_dialog *dialog, const WCHAR *event, const WCHAR *control, const WCHAR *attribute )
{
- static const WCHAR Query[] = {
- 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
+ struct subscriber *sub;
+
+ TRACE("event %s control %s attribute %s\n", debugstr_w(event), debugstr_w(control), debugstr_w(attribute));
+
+ LIST_FOR_EACH_ENTRY( sub, &dialog->package->subscriptions, struct subscriber, entry )
+ {
+ if (!strcmpiW( sub->event, event ) &&
+ !strcmpiW( sub->control, control ) &&
+ !strcmpiW( sub->attribute, attribute ))
+ {
+ TRACE("already subscribed\n");
+ return;
+ };
+ }
+ if (!(sub = msi_alloc( sizeof(*sub) ))) return;
+ sub->dialog = dialog;
+ sub->event = strdupW( event );
+ sub->control = strdupW( control );
+ sub->attribute = strdupW( attribute );
+ list_add_tail( &dialog->package->subscriptions, &sub->entry );
+}
+
+struct dialog_control
+{
+ msi_dialog *dialog;
+ const WCHAR *control;
+};
+
+static UINT map_event( MSIRECORD *row, void *param )
+{
+ struct dialog_control *dc = param;
+ const WCHAR *event = MSI_RecordGetString( row, 3 );
+ const WCHAR *attribute = MSI_RecordGetString( row, 4 );
+
+ event_subscribe( dc->dialog, event, dc->control, attribute );
+ return ERROR_SUCCESS;
+}
+
+static void dialog_map_events( msi_dialog *dialog, const WCHAR *control )
+{
+ static const WCHAR queryW[] =
+ {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
'`','E','v','e','n','t','M','a','p','p','i','n','g','`',' ',
- 'W','H','E','R','E',' ',
- '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',' ',
- 'A','N','D',' ',
- '`','C','o','n','t','r','o','l','_','`',' ','=',' ','\'','%','s','\'',0
+ 'W','H','E','R','E',' ','`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',' ',
+ 'A','N','D',' ','`','C','o','n','t','r','o','l','_','`',' ','=',' ','\'','%','s','\'',0};
+ MSIQUERY *view;
+ struct dialog_control dialog_control =
+ {
+ dialog,
+ control
};
- MSIRECORD *row;
- LPCWSTR event, attribute;
- row = MSI_QueryGetRecord( dialog->package->db, Query, dialog->name, control );
- if (!row)
- return;
-
- event = MSI_RecordGetString( row, 3 );
- attribute = MSI_RecordGetString( row, 4 );
- ControlEvent_SubscribeToEvent( dialog->package, dialog, event, control, attribute );
- msiobj_release( &row->hdr );
+ if (!MSI_OpenQuery( dialog->package->db, &view, queryW, dialog->name, control ))
+ {
+ MSI_IterateRecords( view, NULL, map_event, &dialog_control );
+ msiobj_release( &view->hdr );
+ }
}
/* everything except radio buttons */
if( attributes & msidbControlAttributesSunken )
exstyle |= WS_EX_CLIENTEDGE;
- msi_dialog_map_events(dialog, name);
+ dialog_map_events( dialog, name );
- return msi_dialog_create_window( dialog, rec, exstyle, szCls, name,
- text, style, dialog->hwnd );
+ return dialog_create_window( dialog, rec, exstyle, szCls, name, text, style, dialog->hwnd );
}
struct msi_text_info
(LONG_PTR)MSIText_WndProc );
SetPropW( control->hwnd, szButtonData, info );
- ControlEvent_SubscribeToEvent( dialog->package, dialog,
- szSelectionPath, control_name, szSelectionPath );
-
+ event_subscribe( dialog, szSelectionPath, control_name, szSelectionPath );
return ERROR_SUCCESS;
}
deformat_string( dialog->package, event, &event_fmt );
deformat_string( dialog->package, arg, &arg_fmt );
- dialog->event_handler( dialog->package, event_fmt, arg_fmt, dialog );
+ dialog->event_handler( dialog, event_fmt, arg_fmt );
msi_free( event_fmt );
msi_free( arg_fmt );
if( attributes & msidbControlAttributesSunken )
exstyle |= WS_EX_CLIENTEDGE;
- msi_dialog_map_events(dialog, name);
+ dialog_map_events( dialog, name );
control = msi_alloc( FIELD_OFFSET(msi_control, name[strlenW( name ) + 1] ));
if (!control)
if( !control )
return ERROR_FUNCTION_FAILED;
- ControlEvent_SubscribeToEvent( dialog->package, dialog,
- szSetProgress, control->name, szProgress );
+ event_subscribe( dialog, szSetProgress, control->name, szProgress );
return ERROR_SUCCESS;
}
if( ~attributes & msidbControlAttributesEnabled )
style |= WS_DISABLED;
- control = msi_dialog_create_window( dialog, rec, 0, szButton, name, text,
- style, group->parent->hwnd );
+ control = dialog_create_window( dialog, rec, 0, szButton, name, text, style,
+ group->parent->hwnd );
if (!control)
return ERROR_FUNCTION_FAILED;
control->handler = msi_dialog_radiogroup_handler;
rec = MSI_CreateRecord( 1 );
MSI_RecordSetStringW( rec, 1, MSI_RecordGetString( row, 4 ) );
- ControlEvent_FireSubscribedEvent( dialog->package, szSelectionDescription, rec );
+ msi_event_fire( dialog->package, szSelectionDescription, rec );
dir = MSI_RecordGetString( row, 7 );
if (dir)
else
MSI_RecordSetStringW( rec, 1, NULL );
- ControlEvent_FireSubscribedEvent( dialog->package, szSelectionPath, rec );
+ msi_event_fire( dialog->package, szSelectionPath, rec );
done:
msiobj_release(&row->hdr);
(LONG_PTR)MSISelectionTree_WndProc );
SetPropW( control->hwnd, szButtonData, info );
- ControlEvent_SubscribeToEvent( dialog->package, dialog,
- szSelectionPath, control_name, szProperty );
+ event_subscribe( dialog, szSelectionPath, control_name, szProperty );
/* initialize it */
msi_seltree_create_imagelist( control->hwnd );
return ERROR_SUCCESS;
}
+static UINT msi_dialog_hyperlink_handler( msi_dialog *dialog, msi_control *control, WPARAM param )
+{
+ static const WCHAR hrefW[] = {'h','r','e','f'};
+ static const WCHAR openW[] = {'o','p','e','n',0};
+ int len, len_href = sizeof(hrefW) / sizeof(hrefW[0]);
+ const WCHAR *p, *q;
+ WCHAR quote = 0;
+ LITEM item;
+
+ item.mask = LIF_ITEMINDEX | LIF_URL;
+ item.iLink = 0;
+ item.szUrl[0] = 0;
+
+ SendMessageW( control->hwnd, LM_GETITEM, 0, (LPARAM)&item );
+
+ p = item.szUrl;
+ while (*p && *p != '<') p++;
+ if (!*p++) return ERROR_SUCCESS;
+ if (toupperW( *p++ ) != 'A' || !isspaceW( *p++ )) return ERROR_SUCCESS;
+ while (*p && isspaceW( *p )) p++;
+
+ len = strlenW( p );
+ if (len > len_href && !memicmpW( p, hrefW, len_href ))
+ {
+ p += len_href;
+ while (*p && isspaceW( *p )) p++;
+ if (!*p || *p++ != '=') return ERROR_SUCCESS;
+ while (*p && isspaceW( *p )) p++;
+
+ if (*p == '\"' || *p == '\'') quote = *p++;
+ q = p;
+ if (quote)
+ {
+ while (*q && *q != quote) q++;
+ if (*q != quote) return ERROR_SUCCESS;
+ }
+ else
+ {
+ while (*q && *q != '>' && !isspaceW( *q )) q++;
+ if (!*q) return ERROR_SUCCESS;
+ }
+ item.szUrl[q - item.szUrl] = 0;
+ ShellExecuteW( NULL, openW, p, NULL, NULL, SW_SHOWNORMAL );
+ }
+ return ERROR_SUCCESS;
+}
+
+static UINT msi_dialog_hyperlink( msi_dialog *dialog, MSIRECORD *rec )
+{
+ msi_control *control;
+ DWORD style = WS_CHILD | WS_TABSTOP | WS_GROUP;
+ const WCHAR *text = MSI_RecordGetString( rec, 10 );
+ int len = strlenW( text );
+ LITEM item;
+
+ control = msi_dialog_add_control( dialog, rec, WC_LINK, style );
+ if (!control)
+ return ERROR_FUNCTION_FAILED;
+
+ control->attributes = MSI_RecordGetInteger( rec, 8 );
+ control->handler = msi_dialog_hyperlink_handler;
+
+ item.mask = LIF_ITEMINDEX | LIF_STATE | LIF_URL;
+ item.iLink = 0;
+ item.state = LIS_ENABLED;
+ item.stateMask = LIS_ENABLED;
+ if (len < L_MAX_URL_LENGTH) strcpyW( item.szUrl, text );
+ else item.szUrl[0] = 0;
+
+ SendMessageW( control->hwnd, LM_SETITEM, 0, (LPARAM)&item );
+
+ return ERROR_SUCCESS;
+}
+
static const struct control_handler msi_dialog_handler[] =
{
{ szText, msi_dialog_text_control },
{ szDirectoryList, msi_dialog_directory_list },
{ szVolumeCostList, msi_dialog_volumecost_list },
{ szVolumeSelectCombo, msi_dialog_volumeselect_combo },
+ { szHyperLink, msi_dialog_hyperlink }
};
#define NUM_CONTROL_TYPES (sizeof msi_dialog_handler/sizeof msi_dialog_handler[0])
if (!dialog->default_font)
{
dialog->default_font = strdupW(dfv);
+ msiobj_release( &rec->hdr );
if (!dialog->default_font) return -1;
}
return 0;
}
-static void msi_dialog_setfocus( msi_dialog *dialog )
+static void dialog_setfocus( msi_dialog *dialog )
{
HWND hwnd = dialog->hWndFocus;
if( LOWORD(wParam) == WA_INACTIVE )
dialog->hWndFocus = GetFocus();
else
- msi_dialog_setfocus( dialog );
+ dialog_setfocus( dialog );
return 0;
case WM_SETFOCUS:
- msi_dialog_setfocus( dialog );
+ dialog_setfocus( dialog );
return 0;
/* bounce back to our subclassed static control */
return DefWindowProcW(hwnd, msg, wParam, lParam);
}
+static void process_pending_messages( HWND hdlg )
+{
+ MSG msg;
+
+ while (PeekMessageW( &msg, 0, 0, 0, PM_REMOVE ))
+ {
+ if (hdlg && IsDialogMessageW( hdlg, &msg )) continue;
+ TranslateMessage( &msg );
+ DispatchMessageW( &msg );
+ }
+}
+
+static UINT dialog_run_message_loop( msi_dialog *dialog )
+{
+ DWORD style;
+ HWND hwnd;
+
+ if( uiThreadId != GetCurrentThreadId() )
+ return SendMessageW( hMsiHiddenWindow, WM_MSI_DIALOG_CREATE, 0, (LPARAM) dialog );
+
+ /* create the dialog window, don't show it yet */
+ style = WS_OVERLAPPED;
+ if( dialog->attributes & msidbDialogAttributesVisible )
+ style |= WS_VISIBLE;
+
+ hwnd = CreateWindowW( szMsiDialogClass, dialog->name, style,
+ CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
+ NULL, NULL, NULL, dialog );
+ if( !hwnd )
+ {
+ ERR("Failed to create dialog %s\n", debugstr_w( dialog->name ));
+ return ERROR_FUNCTION_FAILED;
+ }
+
+ ShowWindow( hwnd, SW_SHOW );
+ /* UpdateWindow( hwnd ); - and causes the transparent static controls not to paint */
+
+ if( dialog->attributes & msidbDialogAttributesModal )
+ {
+ while( !dialog->finished )
+ {
+ MsgWaitForMultipleObjects( 0, NULL, 0, INFINITE, QS_ALLINPUT );
+ process_pending_messages( dialog->hwnd );
+ }
+ }
+ else
+ return ERROR_IO_PENDING;
+
+ return ERROR_SUCCESS;
+}
+
static LRESULT WINAPI MSIHiddenWindowProc( HWND hwnd, UINT msg,
WPARAM wParam, LPARAM lParam )
{
switch (msg)
{
case WM_MSI_DIALOG_CREATE:
- return msi_dialog_run_message_loop( dialog );
+ return dialog_run_message_loop( dialog );
case WM_MSI_DIALOG_DESTROY:
msi_dialog_destroy( dialog );
return 0;
return DefWindowProcW( hwnd, msg, wParam, lParam );
}
-static BOOL msi_dialog_register_class( void )
+static BOOL dialog_register_class( void )
{
WNDCLASSW cls;
return TRUE;
}
-/* functions that interface to other modules within MSI */
-
-msi_dialog *msi_dialog_create( MSIPACKAGE* package,
- LPCWSTR szDialogName, msi_dialog *parent,
- msi_dialog_event_handler event_handler )
+static msi_dialog *dialog_create( MSIPACKAGE *package, const WCHAR *name, msi_dialog *parent,
+ control_event_handler event_handler )
{
MSIRECORD *rec = NULL;
msi_dialog *dialog;
- TRACE("%p %s\n", package, debugstr_w(szDialogName));
+ TRACE("%s\n", debugstr_w(name));
- if (!hMsiHiddenWindow)
- msi_dialog_register_class();
+ if (!hMsiHiddenWindow) dialog_register_class();
/* allocate the structure for the dialog to use */
- dialog = msi_alloc_zero( FIELD_OFFSET( msi_dialog, name[strlenW( szDialogName ) + 1] ));
+ dialog = msi_alloc_zero( FIELD_OFFSET( msi_dialog, name[strlenW( name ) + 1] ));
if( !dialog )
return NULL;
- strcpyW( dialog->name, szDialogName );
+ strcpyW( dialog->name, name );
dialog->parent = parent;
msiobj_addref( &package->hdr );
dialog->package = package;
return dialog;
}
-static void msi_process_pending_messages( HWND hdlg )
-{
- MSG msg;
-
- while( PeekMessageW( &msg, 0, 0, 0, PM_REMOVE ) )
- {
- if( hdlg && IsDialogMessageW( hdlg, &msg ))
- continue;
- TranslateMessage( &msg );
- DispatchMessageW( &msg );
- }
-}
-
void msi_dialog_end_dialog( msi_dialog *dialog )
{
TRACE("%p\n", dialog);
/* there's two choices for the UI thread */
while (1)
{
- msi_process_pending_messages( NULL );
+ process_pending_messages( NULL );
if( !handle )
break;
}
}
-UINT msi_dialog_run_message_loop( msi_dialog *dialog )
+static void dialog_do_preview( msi_dialog *dialog )
{
- DWORD style;
- HWND hwnd;
+ TRACE("\n");
+ dialog->attributes |= msidbDialogAttributesVisible;
+ dialog->attributes &= ~msidbDialogAttributesModal;
+ dialog_run_message_loop( dialog );
+}
- if( uiThreadId != GetCurrentThreadId() )
- return SendMessageW( hMsiHiddenWindow, WM_MSI_DIALOG_CREATE, 0, (LPARAM) dialog );
+static void free_subscriber( struct subscriber *sub )
+{
+ msi_free( sub->event );
+ msi_free( sub->control );
+ msi_free( sub->attribute );
+ msi_free( sub );
+}
- /* create the dialog window, don't show it yet */
- style = WS_OVERLAPPED;
- if( dialog->attributes & msidbDialogAttributesVisible )
- style |= WS_VISIBLE;
+static void event_cleanup_subscriptions( MSIPACKAGE *package, const WCHAR *dialog )
+{
+ struct list *item, *next;
- hwnd = CreateWindowW( szMsiDialogClass, dialog->name, style,
- CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
- NULL, NULL, NULL, dialog );
- if( !hwnd )
+ LIST_FOR_EACH_SAFE( item, next, &package->subscriptions )
{
- ERR("Failed to create dialog %s\n", debugstr_w( dialog->name ));
- return ERROR_FUNCTION_FAILED;
- }
-
- ShowWindow( hwnd, SW_SHOW );
- /* UpdateWindow( hwnd ); - and causes the transparent static controls not to paint */
+ struct subscriber *sub = LIST_ENTRY( item, struct subscriber, entry );
- if( dialog->attributes & msidbDialogAttributesModal )
- {
- while( !dialog->finished )
- {
- MsgWaitForMultipleObjects( 0, NULL, 0, INFINITE, QS_ALLINPUT );
- msi_process_pending_messages( dialog->hwnd );
- }
+ if (strcmpW( sub->dialog->name, dialog )) continue;
+ list_remove( &sub->entry );
+ free_subscriber( sub );
}
- else
- return ERROR_IO_PENDING;
-
- return ERROR_SUCCESS;
-}
-
-static void msi_dialog_do_preview( msi_dialog *dialog )
-{
- TRACE("\n");
- dialog->attributes |= msidbDialogAttributesVisible;
- dialog->attributes &= ~msidbDialogAttributesModal;
- msi_dialog_run_message_loop( dialog );
}
void msi_dialog_destroy( msi_dialog *dialog )
DestroyWindow( dialog->hwnd );
/* unsubscribe events */
- ControlEvent_CleanupDialogSubscriptions(dialog->package, dialog->name);
+ event_cleanup_subscriptions( dialog->package, dialog->name );
/* destroy the list of controls */
while( !list_empty( &dialog->controls ) )
uiThreadId = 0;
}
-static UINT error_dialog_handler(MSIPACKAGE *package, LPCWSTR event,
- LPCWSTR argument, msi_dialog* dialog)
+void msi_event_cleanup_all_subscriptions( MSIPACKAGE *package )
+{
+ struct list *item, *next;
+
+ LIST_FOR_EACH_SAFE( item, next, &package->subscriptions )
+ {
+ struct subscriber *sub = LIST_ENTRY( item, struct subscriber, entry );
+ list_remove( &sub->entry );
+ free_subscriber( sub );
+ }
+}
+
+static UINT error_dialog_handler( msi_dialog *dialog, const WCHAR *event, const WCHAR *argument )
{
static const WCHAR end_dialog[] = {'E','n','d','D','i','a','l','o','g',0};
static const WCHAR error_abort[] = {'E','r','r','o','r','A','b','o','r','t',0};
if ( !strcmpW( argument, error_abort ) || !strcmpW( argument, error_cancel ) ||
!strcmpW( argument, error_no ) )
{
- msi_set_property( package->db, result_prop, error_abort, -1 );
+ msi_set_property( dialog->package->db, result_prop, error_abort, -1 );
}
- ControlEvent_CleanupSubscriptions(package);
+ msi_event_cleanup_all_subscriptions( dialog->package );
msi_dialog_end_dialog( dialog );
return ERROR_SUCCESS;
if ( r != ERROR_SUCCESS )
return r;
- dialog = msi_dialog_create( package, error_dialog, package->dialog,
- error_dialog_handler );
+ dialog = dialog_create( package, error_dialog, package->dialog, error_dialog_handler );
if ( !dialog )
return ERROR_FUNCTION_FAILED;
dialog->finished = FALSE;
- r = msi_dialog_run_message_loop( dialog );
+ r = dialog_run_message_loop( dialog );
if ( r != ERROR_SUCCESS )
goto done;
return r;
}
-static UINT preview_event_handler( MSIPACKAGE *package, LPCWSTR event,
- LPCWSTR argument, msi_dialog *dialog )
+static UINT preview_event_handler( msi_dialog *dialog, const WCHAR *event, const WCHAR *argument )
{
MESSAGE("Preview dialog event '%s' (arg='%s')\n", debugstr_w(event), debugstr_w(argument));
return ERROR_SUCCESS;
/* an empty name means we should just destroy the current preview dialog */
if (szDialogName)
{
- dialog = msi_dialog_create( preview->package, szDialogName, NULL, preview_event_handler );
+ dialog = dialog_create( preview->package, szDialogName, NULL, preview_event_handler );
if (dialog)
- msi_dialog_do_preview( dialog );
+ dialog_do_preview( dialog );
else
r = ERROR_FUNCTION_FAILED;
}
FIXME("%d %s %s\n", hPreview, debugstr_a(szControlName), debugstr_a(szBillboard));
return ERROR_CALL_NOT_IMPLEMENTED;
}
+
+typedef UINT (*event_handler)( msi_dialog *, const WCHAR * );
+
+struct control_event
+{
+ const WCHAR *event;
+ event_handler handler;
+};
+
+static UINT dialog_event_handler( msi_dialog *, const WCHAR *, const WCHAR * );
+
+/* create a dialog box and run it if it's modal */
+static UINT event_do_dialog( MSIPACKAGE *package, const WCHAR *name, msi_dialog *parent, BOOL destroy_modeless )
+{
+ msi_dialog *dialog;
+ UINT r;
+
+ /* create a new dialog */
+ dialog = dialog_create( package, name, parent, dialog_event_handler );
+ if (dialog)
+ {
+ /* kill the current modeless dialog */
+ if (destroy_modeless && package->dialog)
+ {
+ msi_dialog_destroy( package->dialog );
+ package->dialog = NULL;
+ }
+
+ /* modeless dialogs return an error message */
+ r = dialog_run_message_loop( dialog );
+ if (r == ERROR_SUCCESS)
+ msi_dialog_destroy( dialog );
+ else
+ package->dialog = dialog;
+ }
+ else r = ERROR_FUNCTION_FAILED;
+ return r;
+}
+
+/* end a modal dialog box */
+static UINT event_end_dialog( msi_dialog *dialog, const WCHAR *argument )
+{
+ static const WCHAR exitW[] = {'E','x','i','t',0};
+ static const WCHAR retryW[] = {'R','e','t','r','y',0};
+ static const WCHAR ignoreW[] = {'I','g','n','o','r','e',0};
+ static const WCHAR returnW[] = {'R','e','t','u','r','n',0};
+
+ if (!strcmpW( argument, exitW ))
+ dialog->package->CurrentInstallState = ERROR_INSTALL_USEREXIT;
+ else if (!strcmpW( argument, retryW ))
+ dialog->package->CurrentInstallState = ERROR_INSTALL_SUSPEND;
+ else if (!strcmpW( argument, ignoreW ))
+ dialog->package->CurrentInstallState = ERROR_SUCCESS;
+ else if (!strcmpW( argument, returnW ))
+ {
+ msi_dialog *parent = dialog->parent;
+ msi_free( dialog->package->next_dialog );
+ dialog->package->next_dialog = (parent) ? strdupW( parent->name ) : NULL;
+ dialog->package->CurrentInstallState = ERROR_SUCCESS;
+ }
+ else
+ {
+ ERR("Unknown argument string %s\n", debugstr_w(argument));
+ dialog->package->CurrentInstallState = ERROR_FUNCTION_FAILED;
+ }
+ event_cleanup_subscriptions( dialog->package, dialog->name );
+ msi_dialog_end_dialog( dialog );
+ return ERROR_SUCCESS;
+}
+
+/* transition from one modal dialog to another modal dialog */
+static UINT event_new_dialog( msi_dialog *dialog, const WCHAR *argument )
+{
+ /* store the name of the next dialog, and signal this one to end */
+ dialog->package->next_dialog = strdupW( argument );
+ msi_event_cleanup_all_subscriptions( dialog->package );
+ msi_dialog_end_dialog( dialog );
+ return ERROR_SUCCESS;
+}
+
+/* create a new child dialog of an existing modal dialog */
+static UINT event_spawn_dialog( msi_dialog *dialog, const WCHAR *argument )
+{
+ /* don't destroy a modeless dialogs that might be our parent */
+ event_do_dialog( dialog->package, argument, dialog, FALSE );
+ if (dialog->package->CurrentInstallState != ERROR_SUCCESS) msi_dialog_end_dialog( dialog );
+ return ERROR_SUCCESS;
+}
+
+/* creates a dialog that remains up for a period of time based on a condition */
+static UINT event_spawn_wait_dialog( msi_dialog *dialog, const WCHAR *argument )
+{
+ FIXME("doing nothing\n");
+ return ERROR_SUCCESS;
+}
+
+static UINT event_do_action( msi_dialog *dialog, const WCHAR *argument )
+{
+ ACTION_PerformAction( dialog->package, argument, SCRIPT_NONE );
+ return ERROR_SUCCESS;
+}
+
+static UINT event_add_local( msi_dialog *dialog, const WCHAR *argument )
+{
+ MSIFEATURE *feature;
+
+ LIST_FOR_EACH_ENTRY( feature, &dialog->package->features, MSIFEATURE, entry )
+ {
+ if (!strcmpW( argument, feature->Feature ) || !strcmpW( argument, szAll ))
+ {
+ if (feature->ActionRequest != INSTALLSTATE_LOCAL)
+ msi_set_property( dialog->package->db, szPreselected, szOne, -1 );
+ MSI_SetFeatureStateW( dialog->package, feature->Feature, INSTALLSTATE_LOCAL );
+ }
+ }
+ return ERROR_SUCCESS;
+}
+
+static UINT event_remove( msi_dialog *dialog, const WCHAR *argument )
+{
+ MSIFEATURE *feature;
+
+ LIST_FOR_EACH_ENTRY( feature, &dialog->package->features, MSIFEATURE, entry )
+ {
+ if (!strcmpW( argument, feature->Feature ) || !strcmpW( argument, szAll ))
+ {
+ if (feature->ActionRequest != INSTALLSTATE_ABSENT)
+ msi_set_property( dialog->package->db, szPreselected, szOne, -1 );
+ MSI_SetFeatureStateW( dialog->package, feature->Feature, INSTALLSTATE_ABSENT );
+ }
+ }
+ return ERROR_SUCCESS;
+}
+
+static UINT event_add_source( msi_dialog *dialog, const WCHAR *argument )
+{
+ MSIFEATURE *feature;
+
+ LIST_FOR_EACH_ENTRY( feature, &dialog->package->features, MSIFEATURE, entry )
+ {
+ if (!strcmpW( argument, feature->Feature ) || !strcmpW( argument, szAll ))
+ {
+ if (feature->ActionRequest != INSTALLSTATE_SOURCE)
+ msi_set_property( dialog->package->db, szPreselected, szOne, -1 );
+ MSI_SetFeatureStateW( dialog->package, feature->Feature, INSTALLSTATE_SOURCE );
+ }
+ }
+ return ERROR_SUCCESS;
+}
+
+void msi_event_fire( MSIPACKAGE *package, const WCHAR *event, MSIRECORD *rec )
+{
+ struct subscriber *sub;
+
+ TRACE("firing event %s\n", debugstr_w(event));
+
+ LIST_FOR_EACH_ENTRY( sub, &package->subscriptions, struct subscriber, entry )
+ {
+ if (strcmpiW( sub->event, event )) continue;
+ dialog_handle_event( sub->dialog, sub->control, sub->attribute, rec );
+ }
+}
+
+static UINT event_set_target_path( msi_dialog *dialog, const WCHAR *argument )
+{
+ WCHAR *path = msi_dup_property( dialog->package->db, argument );
+ MSIRECORD *rec = MSI_CreateRecord( 1 );
+ UINT r = ERROR_SUCCESS;
+
+ MSI_RecordSetStringW( rec, 1, path );
+ msi_event_fire( dialog->package, szSelectionPath, rec );
+ if (path)
+ {
+ /* failure to set the path halts the executing of control events */
+ r = MSI_SetTargetPathW( dialog->package, argument, path );
+ msi_free( path );
+ }
+ msi_free( &rec->hdr );
+ return r;
+}
+
+static UINT event_reset( msi_dialog *dialog, const WCHAR *argument )
+{
+ msi_dialog_reset( dialog );
+ return ERROR_SUCCESS;
+}
+
+/* Return ERROR_SUCCESS if dialog is process and ERROR_FUNCTION_FAILED
+ * if the given parameter is not a dialog box
+ */
+UINT ACTION_DialogBox( MSIPACKAGE *package, const WCHAR *dialog )
+{
+ UINT r;
+
+ if (package->next_dialog) ERR("Already got next dialog... ignoring it\n");
+ package->next_dialog = NULL;
+
+ /* Dialogs are chained by filling in the next_dialog member
+ * of the package structure, then terminating the current dialog.
+ * The code below sees the next_dialog member set, and runs the
+ * next dialog.
+ * We fall out of the loop below if we come across a modeless
+ * dialog, as it returns ERROR_IO_PENDING when we try to run
+ * its message loop.
+ */
+ r = event_do_dialog( package, dialog, NULL, TRUE );
+ while (r == ERROR_SUCCESS && package->next_dialog)
+ {
+ WCHAR *name = package->next_dialog;
+
+ package->next_dialog = NULL;
+ r = event_do_dialog( package, name, NULL, TRUE );
+ msi_free( name );
+ }
+ if (r == ERROR_IO_PENDING) r = ERROR_SUCCESS;
+ return r;
+}
+
+static UINT event_set_install_level( msi_dialog *dialog, const WCHAR *argument )
+{
+ int level = atolW( argument );
+
+ TRACE("setting install level to %d\n", level);
+ return MSI_SetInstallLevel( dialog->package, level );
+}
+
+static UINT event_directory_list_up( msi_dialog *dialog, const WCHAR *argument )
+{
+ return msi_dialog_directorylist_up( dialog );
+}
+
+static UINT event_reinstall_mode( msi_dialog *dialog, const WCHAR *argument )
+{
+ return msi_set_property( dialog->package->db, szReinstallMode, argument, -1 );
+}
+
+static UINT event_reinstall( msi_dialog *dialog, const WCHAR *argument )
+{
+ return msi_set_property( dialog->package->db, szReinstall, argument, -1 );
+}
+
+static UINT event_validate_product_id( msi_dialog *dialog, const WCHAR *argument )
+{
+ return msi_validate_product_id( dialog->package );
+}
+
+static const WCHAR end_dialogW[] = {'E','n','d','D','i','a','l','o','g',0};
+static const WCHAR new_dialogW[] = {'N','e','w','D','i','a','l','o','g',0};
+static const WCHAR spawn_dialogW[] = {'S','p','a','w','n','D','i','a','l','o','g',0};
+static const WCHAR spawn_wait_dialogW[] = {'S','p','a','w','n','W','a','i','t','D','i','a','l','o','g',0};
+static const WCHAR do_actionW[] = {'D','o','A','c','t','i','o','n',0};
+static const WCHAR add_localW[] = {'A','d','d','L','o','c','a','l',0};
+static const WCHAR removeW[] = {'R','e','m','o','v','e',0};
+static const WCHAR add_sourceW[] = {'A','d','d','S','o','u','r','c','e',0};
+static const WCHAR set_target_pathW[] = {'S','e','t','T','a','r','g','e','t','P','a','t','h',0};
+static const WCHAR resetW[] = {'R','e','s','e','t',0};
+static const WCHAR set_install_levelW[] = {'S','e','t','I','n','s','t','a','l','l','L','e','v','e','l',0};
+static const WCHAR directory_list_upW[] = {'D','i','r','e','c','t','o','r','y','L','i','s','t','U','p',0};
+static const WCHAR selection_browseW[] = {'S','e','l','e','c','t','i','o','n','B','r','o','w','s','e',0};
+static const WCHAR reinstall_modeW[] = {'R','e','i','n','s','t','a','l','l','M','o','d','e',0};
+static const WCHAR reinstallW[] = {'R','e','i','n','s','t','a','l','l',0};
+static const WCHAR validate_product_idW[] = {'V','a','l','i','d','a','t','e','P','r','o','d','u','c','t','I','D',0};
+
+static const struct control_event control_events[] =
+{
+ { end_dialogW, event_end_dialog },
+ { new_dialogW, event_new_dialog },
+ { spawn_dialogW, event_spawn_dialog },
+ { spawn_wait_dialogW, event_spawn_wait_dialog },
+ { do_actionW, event_do_action },
+ { add_localW, event_add_local },
+ { removeW, event_remove },
+ { add_sourceW, event_add_source },
+ { set_target_pathW, event_set_target_path },
+ { resetW, event_reset },
+ { set_install_levelW, event_set_install_level },
+ { directory_list_upW, event_directory_list_up },
+ { selection_browseW, event_spawn_dialog },
+ { reinstall_modeW, event_reinstall_mode },
+ { reinstallW, event_reinstall },
+ { validate_product_idW, event_validate_product_id },
+ { NULL, NULL }
+};
+
+static UINT dialog_event_handler( msi_dialog *dialog, const WCHAR *event, const WCHAR *argument )
+{
+ unsigned int i;
+
+ TRACE("handling event %s\n", debugstr_w(event));
+
+ if (!event) return ERROR_SUCCESS;
+
+ for (i = 0; control_events[i].event; i++)
+ {
+ if (!strcmpW( control_events[i].event, event ))
+ return control_events[i].handler( dialog, argument );
+ }
+ FIXME("unhandled event %s arg(%s)\n", debugstr_w(event), debugstr_w(argument));
+ return ERROR_SUCCESS;
+}