secur32: Replace const pointer parameters with correct pointers to const.
[wine] / dlls / msi / preview.c
1 /*
2  * Implementation of the Microsoft Installer (msi.dll)
3  *
4  * Copyright 2005 Mike McCormack for CodeWeavers
5  *
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.
10  *
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.
15  *
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
19  */
20
21 #include <stdarg.h>
22
23 #include "windef.h"
24 #include "winbase.h"
25 #include "winnls.h"
26 #include "msi.h"
27 #include "msipriv.h"
28
29 #include "wine/debug.h"
30 #include "wine/unicode.h"
31
32 WINE_DEFAULT_DEBUG_CHANNEL(msi);
33
34 static void MSI_ClosePreview( MSIOBJECTHDR *arg )
35 {
36     MSIPREVIEW *preview = (MSIPREVIEW *) arg;
37
38     msiobj_release( &preview->package->hdr );
39 }
40
41 MSIPREVIEW *MSI_EnableUIPreview( MSIDATABASE *db )
42 {
43     MSIPREVIEW *preview = NULL;
44     MSIPACKAGE *package;
45
46     package = MSI_CreatePackage( db, NULL );
47     if( package )
48     {
49         preview = alloc_msiobject( MSIHANDLETYPE_PREVIEW, sizeof (MSIPREVIEW),
50                                MSI_ClosePreview );
51         if( preview )
52         {
53             preview->package = package;
54             preview->dialog = 0;
55             msiobj_addref( &package->hdr );
56         }
57         msiobj_release( &package->hdr );
58     }
59     return preview;
60 }
61
62 UINT WINAPI MsiEnableUIPreview( MSIHANDLE hdb, MSIHANDLE* phPreview )
63 {
64     MSIDATABASE *db;
65     MSIPREVIEW *preview;
66     UINT r = ERROR_FUNCTION_FAILED;
67
68     TRACE("%ld %p\n", hdb, phPreview);
69
70     db = msihandle2msiinfo( hdb, MSIHANDLETYPE_DATABASE );
71     if( !db )
72         return ERROR_INVALID_HANDLE;
73     preview = MSI_EnableUIPreview( db );
74     if( preview )
75     {
76         *phPreview = alloc_msihandle( &preview->hdr );
77         msiobj_release( &preview->hdr );
78         r = ERROR_SUCCESS;
79         if (! *phPreview)
80             r = ERROR_NOT_ENOUGH_MEMORY;
81     }
82     msiobj_release( &db->hdr );
83
84     return r;
85 }
86
87 static UINT preview_event_handler( MSIPACKAGE *package, LPCWSTR event,
88                                    LPCWSTR argument, msi_dialog *dialog )
89 {
90     MESSAGE("Preview dialog event '%s' (arg='%s')\n",
91             debugstr_w( event ), debugstr_w( argument ));
92     return ERROR_SUCCESS;
93 }
94
95 UINT MSI_PreviewDialogW( MSIPREVIEW *preview, LPCWSTR szDialogName )
96 {
97     msi_dialog *dialog = NULL;
98     UINT r = ERROR_SUCCESS;
99
100     if( preview->dialog )
101         msi_dialog_destroy( preview->dialog );
102
103     /* an empty name means we should just destroy the current preview dialog */
104     if( szDialogName )
105     {
106         dialog = msi_dialog_create( preview->package, szDialogName, NULL,
107                                     preview_event_handler );
108         if( dialog )
109             msi_dialog_do_preview( dialog );
110         else
111             r = ERROR_FUNCTION_FAILED;
112     }
113     preview->dialog = dialog;
114
115     return r;
116 }
117
118 UINT WINAPI MsiPreviewDialogW( MSIHANDLE hPreview, LPCWSTR szDialogName )
119 {
120     MSIPREVIEW *preview;
121     UINT r;
122
123     TRACE("%ld %s\n", hPreview, debugstr_w(szDialogName));
124
125     preview = msihandle2msiinfo( hPreview, MSIHANDLETYPE_PREVIEW );
126     if( !preview )
127         return ERROR_INVALID_HANDLE;
128
129     r = MSI_PreviewDialogW( preview, szDialogName );
130
131     msiobj_release( &preview->hdr );
132
133     return r;
134 }
135
136 UINT WINAPI MsiPreviewDialogA( MSIHANDLE hPreview, LPCSTR szDialogName )
137 {
138     UINT r;
139     LPWSTR strW = NULL;
140
141     TRACE("%ld %s\n", hPreview, debugstr_a(szDialogName));
142
143     if( szDialogName )
144     {
145         strW = strdupAtoW( szDialogName );
146         if( !strW )
147             return ERROR_OUTOFMEMORY;
148     }
149     r = MsiPreviewDialogW( hPreview, strW );
150     msi_free( strW );
151     return r;
152 }
153
154 UINT WINAPI MsiPreviewBillboardW( MSIHANDLE hPreview, LPCWSTR szControlName,
155                                   LPCWSTR szBillboard)
156 {
157     FIXME("%ld %s %s\n", hPreview, debugstr_w(szControlName),
158           debugstr_w(szBillboard));
159     return ERROR_CALL_NOT_IMPLEMENTED;
160 }
161
162 UINT WINAPI MsiPreviewBillboardA( MSIHANDLE hPreview, LPCSTR szControlName,
163                                   LPCSTR szBillboard)
164 {
165     FIXME("%ld %s %s\n", hPreview, debugstr_a(szControlName),
166           debugstr_a(szBillboard));
167     return ERROR_CALL_NOT_IMPLEMENTED;
168 }