abeb1454ac9aa20cc1f6cea8cff3ed7ef4fe99dd
[reactos.git] / reactos / dll / win32 / oledlg / oledlg_main.c
1 /*
2 * OLEDLG library
3 *
4 * Copyright 1998 Patrik Stridvall
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 "oledlg_private.h"
22
23 WINE_DEFAULT_DEBUG_CHANNEL(ole);
24
25 HINSTANCE OLEDLG_hInstance = 0;
26
27 UINT cf_embed_source;
28 UINT cf_embedded_object;
29 UINT cf_link_source;
30 UINT cf_object_descriptor;
31 UINT cf_link_src_descriptor;
32 UINT cf_ownerlink;
33 UINT cf_filename;
34 UINT cf_filenamew;
35
36 UINT oleui_msg_help;
37 UINT oleui_msg_enddialog;
38
39 static void register_clipboard_formats(void)
40 {
41 /* These used to be declared in olestd.h, but that seems to have been removed from the api */
42 static const WCHAR CF_EMBEDSOURCEW[] = { 'E','m','b','e','d',' ','S','o','u','r','c','e',0 };
43 static const WCHAR CF_EMBEDDEDOBJECTW[] = { 'E','m','b','e','d','d','e','d',' ','O','b','j','e','c','t',0 };
44 static const WCHAR CF_LINKSOURCEW[] = { 'L','i','n','k',' ','S','o','u','r','c','e',0 };
45 static const WCHAR CF_OBJECTDESCRIPTORW[] = { 'O','b','j','e','c','t',' ','D','e','s','c','r','i','p','t','o','r',0 };
46 static const WCHAR CF_LINKSRCDESCRIPTORW[] = { 'L','i','n','k',' ','S','o','u','r','c','e',' ','D','e','s','c','r','i','p','t','o','r',0 };
47 static const WCHAR CF_OWNERLINKW[] = { 'O','w','n','e','r','L','i','n','k',0 };
48 static const WCHAR CF_FILENAMEW[] = { 'F','i','l','e','N','a','m','e',0 };
49 static const WCHAR CF_FILENAMEWW[] = { 'F','i','l','e','N','a','m','e','W',0 };
50
51 /* Load in the same order as native to make debugging easier */
52 cf_object_descriptor = RegisterClipboardFormatW(CF_OBJECTDESCRIPTORW);
53 cf_link_src_descriptor = RegisterClipboardFormatW(CF_LINKSRCDESCRIPTORW);
54 cf_embed_source = RegisterClipboardFormatW(CF_EMBEDSOURCEW);
55 cf_embedded_object = RegisterClipboardFormatW(CF_EMBEDDEDOBJECTW);
56 cf_link_source = RegisterClipboardFormatW(CF_LINKSOURCEW);
57 cf_ownerlink = RegisterClipboardFormatW(CF_OWNERLINKW);
58 cf_filename = RegisterClipboardFormatW(CF_FILENAMEW);
59 cf_filenamew = RegisterClipboardFormatW(CF_FILENAMEWW);
60 }
61
62 static void register_messages(void)
63 {
64 oleui_msg_help = RegisterWindowMessageW(SZOLEUI_MSG_HELPW);
65 oleui_msg_enddialog = RegisterWindowMessageW(SZOLEUI_MSG_ENDDIALOGW);
66 }
67
68 /***********************************************************************
69 * DllMain
70 */
71 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID fImpLoad)
72 {
73 TRACE("%p 0x%x %p\n", hinstDLL, fdwReason, fImpLoad);
74
75 switch(fdwReason) {
76 case DLL_PROCESS_ATTACH:
77 DisableThreadLibraryCalls(hinstDLL);
78 OLEDLG_hInstance = hinstDLL;
79 register_clipboard_formats();
80 register_messages();
81 break;
82 }
83 return TRUE;
84 }
85
86
87 /***********************************************************************
88 * OleUIAddVerbMenuA (OLEDLG.1)
89 */
90 BOOL WINAPI OleUIAddVerbMenuA(IOleObject *object, LPCSTR shorttype,
91 HMENU hMenu, UINT uPos, UINT uIDVerbMin, UINT uIDVerbMax,
92 BOOL addConvert, UINT idConvert, HMENU *lphMenu)
93 {
94 WCHAR *shorttypeW = NULL;
95 BOOL ret;
96
97 TRACE("(%p, %s, %p, %d, %d, %d, %d, %d, %p)\n", object, debugstr_a(shorttype),
98 hMenu, uPos, uIDVerbMin, uIDVerbMax, addConvert, idConvert, lphMenu);
99
100 if (shorttype)
101 {
102 INT len = MultiByteToWideChar(CP_ACP, 0, shorttype, -1, NULL, 0);
103 shorttypeW = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
104 if (shorttypeW)
105 MultiByteToWideChar(CP_ACP, 0, shorttype, -1, shorttypeW, len);
106 }
107
108 ret = OleUIAddVerbMenuW(object, shorttypeW, hMenu, uPos, uIDVerbMin, uIDVerbMax,
109 addConvert, idConvert, lphMenu);
110 HeapFree(GetProcessHeap(), 0, shorttypeW);
111 return ret;
112 }
113
114 static inline BOOL is_verb_in_range(const OLEVERB *verb, UINT idmin, UINT idmax)
115 {
116 if (idmax == 0) return TRUE;
117 return (verb->lVerb + idmin <= idmax);
118 }
119
120 static HRESULT get_next_insertable_verb(IEnumOLEVERB *enumverbs, UINT idmin, UINT idmax, OLEVERB *verb)
121 {
122 memset(verb, 0, sizeof(*verb));
123
124 while (IEnumOLEVERB_Next(enumverbs, 1, verb, NULL) == S_OK) {
125 if (is_verb_in_range(verb, idmin, idmax) && (verb->grfAttribs & OLEVERBATTRIB_ONCONTAINERMENU))
126 return S_OK;
127
128 CoTaskMemFree(verb->lpszVerbName);
129 memset(verb, 0, sizeof(*verb));
130 }
131
132 return S_FALSE;
133 }
134
135 static void insert_verb_to_menu(HMENU menu, UINT idmin, const OLEVERB *verb)
136 {
137 InsertMenuW(menu, ~0, verb->fuFlags | MF_BYPOSITION | MF_STRING, verb->lVerb + idmin, verb->lpszVerbName);
138 }
139
140 /***********************************************************************
141 * OleUIAddVerbMenuW (OLEDLG.14)
142 */
143 BOOL WINAPI OleUIAddVerbMenuW(IOleObject *object, LPCWSTR shorttype,
144 HMENU hMenu, UINT uPos, UINT idmin, UINT idmax, BOOL addConvert, UINT idConvert, HMENU *ret_submenu)
145 {
146 static const WCHAR spaceW[] = {' ',0};
147 IEnumOLEVERB *enumverbs = NULL;
148 WCHAR *rootname, *objecttype;
149 LPOLESTR usertype = NULL;
150 OLEVERB firstverb, verb;
151 WCHAR resstrW[32]; /* should be enough */
152 BOOL singleverb;
153 HMENU submenu;
154
155 TRACE("(%p, %s, %p, %d, %d, %d, %d, %d, %p)\n", object, debugstr_w(shorttype),
156 hMenu, uPos, idmin, idmax, addConvert, idConvert, ret_submenu);
157
158 if (ret_submenu)
159 *ret_submenu = NULL;
160
161 if (!hMenu || !ret_submenu)
162 return FALSE;
163
164 /* check if we can get verbs at all */
165 if (object)
166 IOleObject_EnumVerbs(object, &enumverbs);
167
168 LoadStringW(OLEDLG_hInstance, IDS_VERBMENU_OBJECT, resstrW, sizeof(resstrW)/sizeof(WCHAR));
169 /* no object, or object without enumeration support */
170 if (!object || (object && !enumverbs)) {
171 InsertMenuW(hMenu, uPos, MF_BYPOSITION|MF_STRING|MF_GRAYED, idmin, resstrW);
172 return FALSE;
173 }
174
175 /* root entry string */
176 if (!shorttype && (IOleObject_GetUserType(object, USERCLASSTYPE_SHORT, &usertype) == S_OK))
177 objecttype = usertype;
178 else
179 objecttype = (WCHAR*)shorttype;
180
181 rootname = CoTaskMemAlloc((strlenW(objecttype) + strlenW(resstrW) + 2)*sizeof(WCHAR));
182 strcpyW(rootname, objecttype);
183 strcatW(rootname, spaceW);
184 strcatW(rootname, resstrW);
185 CoTaskMemFree(usertype);
186
187 /* iterate through verbs */
188
189 /* find first suitable verb */
190 get_next_insertable_verb(enumverbs, idmin, idmax, &firstverb);
191 singleverb = get_next_insertable_verb(enumverbs, idmin, idmax, &verb) != S_OK;
192
193 if (singleverb && !addConvert) {
194 WCHAR *str = CoTaskMemAlloc((strlenW(rootname) + strlenW(firstverb.lpszVerbName) + 2)*sizeof(WCHAR));
195
196 strcpyW(str, firstverb.lpszVerbName);
197 strcatW(str, spaceW);
198 strcatW(str, rootname);
199
200 RemoveMenu(hMenu, uPos, MF_BYPOSITION);
201 InsertMenuW(hMenu, uPos, MF_BYPOSITION|MF_STRING, idmin, str);
202 CoTaskMemFree(firstverb.lpszVerbName);
203 CoTaskMemFree(rootname);
204 CoTaskMemFree(str);
205 IEnumOLEVERB_Release(enumverbs);
206 return TRUE;
207 }
208
209 submenu = CreatePopupMenu();
210 insert_verb_to_menu(submenu, idmin, &firstverb);
211 CoTaskMemFree(firstverb.lpszVerbName);
212
213 if (!singleverb) {
214 insert_verb_to_menu(submenu, idmin, &verb);
215 CoTaskMemFree(verb.lpszVerbName);
216 }
217
218 while (get_next_insertable_verb(enumverbs, idmin, idmax, &verb) == S_OK) {
219 insert_verb_to_menu(submenu, idmin, &verb);
220 CoTaskMemFree(verb.lpszVerbName);
221 }
222
223 /* convert verb is at the bottom of a popup, separated from verbs */
224 if (addConvert) {
225 LoadStringW(OLEDLG_hInstance, IDS_VERBMENU_CONVERT, resstrW, sizeof(resstrW)/sizeof(WCHAR));
226 InsertMenuW(submenu, ~0, MF_BYPOSITION|MF_SEPARATOR, 0, NULL);
227 InsertMenuW(submenu, ~0, MF_BYPOSITION|MF_STRING, idConvert, resstrW);
228 }
229
230 if (submenu)
231 *ret_submenu = submenu;
232
233 /* now submenu is ready, add root entry to original menu, attach submenu */
234 InsertMenuW(hMenu, uPos, MF_BYPOSITION|MF_POPUP|MF_STRING, (UINT_PTR)submenu, rootname);
235 IEnumOLEVERB_Release(enumverbs);
236 CoTaskMemFree(rootname);
237 return TRUE;
238 }
239
240 /***********************************************************************
241 * OleUICanConvertOrActivateAs (OLEDLG.2)
242 */
243 BOOL WINAPI OleUICanConvertOrActivateAs(
244 REFCLSID rClsid, BOOL fIsLinkedObject, WORD wFormat)
245 {
246 FIXME("(%p, %d, %hd): stub\n",
247 rClsid, fIsLinkedObject, wFormat
248 );
249 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
250 return FALSE;
251 }
252
253 /***********************************************************************
254 * OleUIInsertObjectW (OLEDLG.20)
255 */
256 UINT WINAPI OleUIInsertObjectW(LPOLEUIINSERTOBJECTW lpOleUIInsertObject)
257 {
258 FIXME("(%p): stub\n", lpOleUIInsertObject);
259 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
260 return OLEUI_FALSE;
261 }
262
263 /***********************************************************************
264 * OleUIEditLinksA (OLEDLG.5)
265 */
266 UINT WINAPI OleUIEditLinksA(LPOLEUIEDITLINKSA lpOleUIEditLinks)
267 {
268 FIXME("(%p): stub\n", lpOleUIEditLinks);
269 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
270 return OLEUI_FALSE;
271 }
272
273 /***********************************************************************
274 * OleUIEditLinksW (OLEDLG.19)
275 */
276 UINT WINAPI OleUIEditLinksW(LPOLEUIEDITLINKSW lpOleUIEditLinks)
277 {
278 FIXME("(%p): stub\n", lpOleUIEditLinks);
279 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
280 return OLEUI_FALSE;
281 }
282
283 /***********************************************************************
284 * OleUIChangeIconA (OLEDLG.6)
285 */
286 UINT WINAPI OleUIChangeIconA(
287 LPOLEUICHANGEICONA lpOleUIChangeIcon)
288 {
289 FIXME("(%p): stub\n", lpOleUIChangeIcon);
290 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
291 return OLEUI_FALSE;
292 }
293
294 /***********************************************************************
295 * OleUIChangeIconW (OLEDLG.16)
296 */
297 UINT WINAPI OleUIChangeIconW(
298 LPOLEUICHANGEICONW lpOleUIChangeIcon)
299 {
300 FIXME("(%p): stub\n", lpOleUIChangeIcon);
301 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
302 return OLEUI_FALSE;
303 }
304
305 /***********************************************************************
306 * OleUIConvertA (OLEDLG.7)
307 */
308 UINT WINAPI OleUIConvertA(LPOLEUICONVERTA lpOleUIConvert)
309 {
310 FIXME("(%p): stub\n", lpOleUIConvert);
311 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
312 return OLEUI_FALSE;
313 }
314
315 /***********************************************************************
316 * OleUIConvertW (OLEDLG.18)
317 */
318 UINT WINAPI OleUIConvertW(LPOLEUICONVERTW lpOleUIConvert)
319 {
320 FIXME("(%p): stub\n", lpOleUIConvert);
321 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
322 return OLEUI_FALSE;
323 }
324
325 /***********************************************************************
326 * OleUIBusyA (OLEDLG.8)
327 */
328 UINT WINAPI OleUIBusyA(LPOLEUIBUSYA lpOleUIBusy)
329 {
330 FIXME("(%p): stub\n", lpOleUIBusy);
331 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
332 return OLEUI_FALSE;
333 }
334
335 /***********************************************************************
336 * OleUIBusyW (OLEDLG.15)
337 */
338 UINT WINAPI OleUIBusyW(LPOLEUIBUSYW lpOleUIBusy)
339 {
340 FIXME("(%p): stub\n", lpOleUIBusy);
341 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
342 return OLEUI_FALSE;
343 }
344
345 /***********************************************************************
346 * OleUIUpdateLinksA (OLEDLG.9)
347 */
348 BOOL WINAPI OleUIUpdateLinksA(
349 LPOLEUILINKCONTAINERA lpOleUILinkCntr,
350 HWND hwndParent, LPSTR lpszTitle, INT cLinks)
351 {
352 FIXME("(%p, %p, %s, %d): stub\n",
353 lpOleUILinkCntr, hwndParent, debugstr_a(lpszTitle), cLinks
354 );
355 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
356 return FALSE;
357 }
358
359 /***********************************************************************
360 * OleUIUpdateLinksW (OLEDLG.23)
361 */
362 BOOL WINAPI OleUIUpdateLinksW(
363 LPOLEUILINKCONTAINERW lpOleUILinkCntr,
364 HWND hwndParent, LPWSTR lpszTitle, INT cLinks)
365 {
366 FIXME("(%p, %p, %s, %d): stub\n",
367 lpOleUILinkCntr, hwndParent, debugstr_w(lpszTitle), cLinks
368 );
369 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
370 return FALSE;
371 }
372
373 /***********************************************************************
374 * OleUIPromptUserA (OLEDLG.10)
375 */
376 INT WINAPIV OleUIPromptUserA(
377 INT nTemplate, HWND hwndParent, ...)
378 {
379 FIXME("(%d, %p, ...): stub\n", nTemplate, hwndParent);
380 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
381 return OLEUI_FALSE;
382 }
383
384 /***********************************************************************
385 * OleUIPromptUserW (OLEDLG.13)
386 */
387 INT WINAPIV OleUIPromptUserW(
388 INT nTemplate, HWND hwndParent, ...)
389 {
390 FIXME("(%d, %p, ...): stub\n", nTemplate, hwndParent);
391 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
392 return OLEUI_FALSE;
393 }
394
395 /***********************************************************************
396 * OleUIObjectPropertiesA (OLEDLG.11)
397 */
398 UINT WINAPI OleUIObjectPropertiesA(
399 LPOLEUIOBJECTPROPSA lpOleUIObjectProps)
400 {
401 FIXME("(%p): stub\n", lpOleUIObjectProps);
402 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
403 return OLEUI_FALSE;
404 }
405
406 /***********************************************************************
407 * OleUIObjectPropertiesW (OLEDLG.21)
408 */
409 UINT WINAPI OleUIObjectPropertiesW(
410 LPOLEUIOBJECTPROPSW lpOleUIObjectProps)
411 {
412 FIXME("(%p): stub\n", lpOleUIObjectProps);
413 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
414 return OLEUI_FALSE;
415 }
416
417 /***********************************************************************
418 * OleUIChangeSourceA (OLEDLG.12)
419 */
420 UINT WINAPI OleUIChangeSourceA(
421 LPOLEUICHANGESOURCEA lpOleUIChangeSource)
422 {
423 FIXME("(%p): stub\n", lpOleUIChangeSource);
424 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
425 return OLEUI_FALSE;
426 }
427
428 /***********************************************************************
429 * OleUIChangeSourceW (OLEDLG.17)
430 */
431 UINT WINAPI OleUIChangeSourceW(
432 LPOLEUICHANGESOURCEW lpOleUIChangeSource)
433 {
434 FIXME("(%p): stub\n", lpOleUIChangeSource);
435 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
436 return OLEUI_FALSE;
437 }