qcap/tests: Add media tests for the SmartTee filter.
[wine/multimedia.git] / dlls / oledlg / oledlg_main.c
bloba1f4db40822223e8f5df61cc9e424dfc5bc43436
1 /*
2 * OLEDLG library
4 * Copyright 1998 Patrik Stridvall
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
21 #define COBJMACROS
23 #include <stdarg.h>
25 #include "windef.h"
26 #include "winbase.h"
27 #include "winerror.h"
28 #include "wingdi.h"
29 #include "winuser.h"
30 #include "oledlg.h"
31 #include "ole2.h"
32 #include "oledlg_private.h"
33 #include "resource.h"
35 #include "wine/debug.h"
36 #include "wine/unicode.h"
38 WINE_DEFAULT_DEBUG_CHANNEL(ole);
40 HINSTANCE OLEDLG_hInstance = 0;
42 UINT cf_embed_source;
43 UINT cf_embedded_object;
44 UINT cf_link_source;
45 UINT cf_object_descriptor;
46 UINT cf_link_src_descriptor;
47 UINT cf_ownerlink;
48 UINT cf_filename;
49 UINT cf_filenamew;
51 UINT oleui_msg_help;
52 UINT oleui_msg_enddialog;
54 static void register_clipboard_formats(void)
56 /* These used to be declared in olestd.h, but that seems to have been removed from the api */
57 static const WCHAR CF_EMBEDSOURCEW[] = { 'E','m','b','e','d',' ','S','o','u','r','c','e',0 };
58 static const WCHAR CF_EMBEDDEDOBJECTW[] = { 'E','m','b','e','d','d','e','d',' ','O','b','j','e','c','t',0 };
59 static const WCHAR CF_LINKSOURCEW[] = { 'L','i','n','k',' ','S','o','u','r','c','e',0 };
60 static const WCHAR CF_OBJECTDESCRIPTORW[] = { 'O','b','j','e','c','t',' ','D','e','s','c','r','i','p','t','o','r',0 };
61 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 };
62 static const WCHAR CF_OWNERLINKW[] = { 'O','w','n','e','r','L','i','n','k',0 };
63 static const WCHAR CF_FILENAMEW[] = { 'F','i','l','e','N','a','m','e',0 };
64 static const WCHAR CF_FILENAMEWW[] = { 'F','i','l','e','N','a','m','e','W',0 };
66 /* Load in the same order as native to make debugging easier */
67 cf_object_descriptor = RegisterClipboardFormatW(CF_OBJECTDESCRIPTORW);
68 cf_link_src_descriptor = RegisterClipboardFormatW(CF_LINKSRCDESCRIPTORW);
69 cf_embed_source = RegisterClipboardFormatW(CF_EMBEDSOURCEW);
70 cf_embedded_object = RegisterClipboardFormatW(CF_EMBEDDEDOBJECTW);
71 cf_link_source = RegisterClipboardFormatW(CF_LINKSOURCEW);
72 cf_ownerlink = RegisterClipboardFormatW(CF_OWNERLINKW);
73 cf_filename = RegisterClipboardFormatW(CF_FILENAMEW);
74 cf_filenamew = RegisterClipboardFormatW(CF_FILENAMEWW);
77 static void register_messages(void)
79 oleui_msg_help = RegisterWindowMessageW(SZOLEUI_MSG_HELPW);
80 oleui_msg_enddialog = RegisterWindowMessageW(SZOLEUI_MSG_ENDDIALOGW);
83 /***********************************************************************
84 * DllMain
86 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID fImpLoad)
88 TRACE("%p 0x%x %p\n", hinstDLL, fdwReason, fImpLoad);
90 switch(fdwReason) {
91 case DLL_PROCESS_ATTACH:
92 DisableThreadLibraryCalls(hinstDLL);
93 OLEDLG_hInstance = hinstDLL;
94 register_clipboard_formats();
95 register_messages();
96 break;
98 return TRUE;
102 /***********************************************************************
103 * OleUIAddVerbMenuA (OLEDLG.1)
105 BOOL WINAPI OleUIAddVerbMenuA(IOleObject *object, LPCSTR shorttype,
106 HMENU hMenu, UINT uPos, UINT uIDVerbMin, UINT uIDVerbMax,
107 BOOL addConvert, UINT idConvert, HMENU *lphMenu)
109 WCHAR *shorttypeW = NULL;
110 BOOL ret;
112 TRACE("(%p, %s, %p, %d, %d, %d, %d, %d, %p)\n", object, debugstr_a(shorttype),
113 hMenu, uPos, uIDVerbMin, uIDVerbMax, addConvert, idConvert, lphMenu);
115 if (shorttype)
117 INT len = MultiByteToWideChar(CP_ACP, 0, shorttype, -1, NULL, 0);
118 shorttypeW = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
119 if (shorttypeW)
120 MultiByteToWideChar(CP_ACP, 0, shorttype, -1, shorttypeW, len);
123 ret = OleUIAddVerbMenuW(object, shorttypeW, hMenu, uPos, uIDVerbMin, uIDVerbMax,
124 addConvert, idConvert, lphMenu);
125 HeapFree(GetProcessHeap(), 0, shorttypeW);
126 return ret;
129 static inline BOOL is_verb_in_range(const OLEVERB *verb, UINT idmin, UINT idmax)
131 if (idmax == 0) return TRUE;
132 return (verb->lVerb + idmin <= idmax);
135 static HRESULT get_next_insertable_verb(IEnumOLEVERB *enumverbs, UINT idmin, UINT idmax, OLEVERB *verb)
137 memset(verb, 0, sizeof(*verb));
139 while (IEnumOLEVERB_Next(enumverbs, 1, verb, NULL) == S_OK) {
140 if (is_verb_in_range(verb, idmin, idmax) && (verb->grfAttribs & OLEVERBATTRIB_ONCONTAINERMENU))
141 return S_OK;
143 CoTaskMemFree(verb->lpszVerbName);
144 memset(verb, 0, sizeof(*verb));
147 return S_FALSE;
150 static void insert_verb_to_menu(HMENU menu, UINT idmin, const OLEVERB *verb)
152 InsertMenuW(menu, ~0, verb->fuFlags | MF_BYPOSITION | MF_STRING, verb->lVerb + idmin, verb->lpszVerbName);
155 /***********************************************************************
156 * OleUIAddVerbMenuW (OLEDLG.14)
158 BOOL WINAPI OleUIAddVerbMenuW(IOleObject *object, LPCWSTR shorttype,
159 HMENU hMenu, UINT uPos, UINT idmin, UINT idmax, BOOL addConvert, UINT idConvert, HMENU *ret_submenu)
161 static const WCHAR spaceW[] = {' ',0};
162 IEnumOLEVERB *enumverbs = NULL;
163 WCHAR *rootname, *objecttype;
164 LPOLESTR usertype = NULL;
165 OLEVERB firstverb, verb;
166 WCHAR resstrW[32]; /* should be enough */
167 BOOL singleverb;
168 HMENU submenu;
170 TRACE("(%p, %s, %p, %d, %d, %d, %d, %d, %p)\n", object, debugstr_w(shorttype),
171 hMenu, uPos, idmin, idmax, addConvert, idConvert, ret_submenu);
173 if (ret_submenu)
174 *ret_submenu = NULL;
176 if (!hMenu || !ret_submenu)
177 return FALSE;
179 /* check if we can get verbs at all */
180 if (object)
181 IOleObject_EnumVerbs(object, &enumverbs);
183 LoadStringW(OLEDLG_hInstance, IDS_VERBMENU_OBJECT, resstrW, sizeof(resstrW)/sizeof(WCHAR));
184 /* no object, or object without enumeration support */
185 if (!object || (object && !enumverbs)) {
186 InsertMenuW(hMenu, uPos, MF_BYPOSITION|MF_STRING|MF_GRAYED, idmin, resstrW);
187 return FALSE;
190 /* root entry string */
191 if (!shorttype && (IOleObject_GetUserType(object, USERCLASSTYPE_SHORT, &usertype) == S_OK))
192 objecttype = usertype;
193 else
194 objecttype = (WCHAR*)shorttype;
196 rootname = CoTaskMemAlloc((strlenW(objecttype) + strlenW(resstrW) + 2)*sizeof(WCHAR));
197 strcpyW(rootname, objecttype);
198 strcatW(rootname, spaceW);
199 strcatW(rootname, resstrW);
200 CoTaskMemFree(usertype);
202 /* iterate through verbs */
204 /* find first suitable verb */
205 get_next_insertable_verb(enumverbs, idmin, idmax, &firstverb);
206 singleverb = get_next_insertable_verb(enumverbs, idmin, idmax, &verb) != S_OK;
208 if (singleverb && !addConvert) {
209 WCHAR *str = CoTaskMemAlloc((strlenW(rootname) + strlenW(firstverb.lpszVerbName) + 2)*sizeof(WCHAR));
211 strcpyW(str, firstverb.lpszVerbName);
212 strcatW(str, spaceW);
213 strcatW(str, rootname);
215 RemoveMenu(hMenu, uPos, MF_BYPOSITION);
216 InsertMenuW(hMenu, uPos, MF_BYPOSITION|MF_STRING, idmin, str);
217 CoTaskMemFree(firstverb.lpszVerbName);
218 CoTaskMemFree(rootname);
219 CoTaskMemFree(str);
220 IEnumOLEVERB_Release(enumverbs);
221 return TRUE;
224 submenu = CreatePopupMenu();
225 insert_verb_to_menu(submenu, idmin, &firstverb);
226 CoTaskMemFree(firstverb.lpszVerbName);
228 if (!singleverb) {
229 insert_verb_to_menu(submenu, idmin, &verb);
230 CoTaskMemFree(verb.lpszVerbName);
233 while (get_next_insertable_verb(enumverbs, idmin, idmax, &verb) == S_OK) {
234 insert_verb_to_menu(submenu, idmin, &verb);
235 CoTaskMemFree(verb.lpszVerbName);
238 /* convert verb is at the bottom of a popup, separated from verbs */
239 if (addConvert) {
240 LoadStringW(OLEDLG_hInstance, IDS_VERBMENU_CONVERT, resstrW, sizeof(resstrW)/sizeof(WCHAR));
241 InsertMenuW(submenu, ~0, MF_BYPOSITION|MF_SEPARATOR, 0, NULL);
242 InsertMenuW(submenu, ~0, MF_BYPOSITION|MF_STRING, idConvert, resstrW);
245 if (submenu)
246 *ret_submenu = submenu;
248 /* now submenu is ready, add root entry to original menu, attach submenu */
249 InsertMenuW(hMenu, uPos, MF_BYPOSITION|MF_POPUP|MF_STRING, (UINT_PTR)submenu, rootname);
250 IEnumOLEVERB_Release(enumverbs);
251 CoTaskMemFree(rootname);
252 return TRUE;
255 /***********************************************************************
256 * OleUICanConvertOrActivateAs (OLEDLG.2)
258 BOOL WINAPI OleUICanConvertOrActivateAs(
259 REFCLSID rClsid, BOOL fIsLinkedObject, WORD wFormat)
261 FIXME("(%p, %d, %hd): stub\n",
262 rClsid, fIsLinkedObject, wFormat
264 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
265 return FALSE;
268 /***********************************************************************
269 * OleUIInsertObjectW (OLEDLG.20)
271 UINT WINAPI OleUIInsertObjectW(LPOLEUIINSERTOBJECTW lpOleUIInsertObject)
273 FIXME("(%p): stub\n", lpOleUIInsertObject);
274 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
275 return OLEUI_FALSE;
278 /***********************************************************************
279 * OleUIEditLinksA (OLEDLG.5)
281 UINT WINAPI OleUIEditLinksA(LPOLEUIEDITLINKSA lpOleUIEditLinks)
283 FIXME("(%p): stub\n", lpOleUIEditLinks);
284 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
285 return OLEUI_FALSE;
288 /***********************************************************************
289 * OleUIEditLinksW (OLEDLG.19)
291 UINT WINAPI OleUIEditLinksW(LPOLEUIEDITLINKSW lpOleUIEditLinks)
293 FIXME("(%p): stub\n", lpOleUIEditLinks);
294 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
295 return OLEUI_FALSE;
298 /***********************************************************************
299 * OleUIChangeIconA (OLEDLG.6)
301 UINT WINAPI OleUIChangeIconA(
302 LPOLEUICHANGEICONA lpOleUIChangeIcon)
304 FIXME("(%p): stub\n", lpOleUIChangeIcon);
305 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
306 return OLEUI_FALSE;
309 /***********************************************************************
310 * OleUIChangeIconW (OLEDLG.16)
312 UINT WINAPI OleUIChangeIconW(
313 LPOLEUICHANGEICONW lpOleUIChangeIcon)
315 FIXME("(%p): stub\n", lpOleUIChangeIcon);
316 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
317 return OLEUI_FALSE;
320 /***********************************************************************
321 * OleUIConvertA (OLEDLG.7)
323 UINT WINAPI OleUIConvertA(LPOLEUICONVERTA lpOleUIConvert)
325 FIXME("(%p): stub\n", lpOleUIConvert);
326 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
327 return OLEUI_FALSE;
330 /***********************************************************************
331 * OleUIConvertW (OLEDLG.18)
333 UINT WINAPI OleUIConvertW(LPOLEUICONVERTW lpOleUIConvert)
335 FIXME("(%p): stub\n", lpOleUIConvert);
336 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
337 return OLEUI_FALSE;
340 /***********************************************************************
341 * OleUIBusyA (OLEDLG.8)
343 UINT WINAPI OleUIBusyA(LPOLEUIBUSYA lpOleUIBusy)
345 FIXME("(%p): stub\n", lpOleUIBusy);
346 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
347 return OLEUI_FALSE;
350 /***********************************************************************
351 * OleUIBusyW (OLEDLG.15)
353 UINT WINAPI OleUIBusyW(LPOLEUIBUSYW lpOleUIBusy)
355 FIXME("(%p): stub\n", lpOleUIBusy);
356 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
357 return OLEUI_FALSE;
360 /***********************************************************************
361 * OleUIUpdateLinksA (OLEDLG.9)
363 BOOL WINAPI OleUIUpdateLinksA(
364 LPOLEUILINKCONTAINERA lpOleUILinkCntr,
365 HWND hwndParent, LPSTR lpszTitle, INT cLinks)
367 FIXME("(%p, %p, %s, %d): stub\n",
368 lpOleUILinkCntr, hwndParent, debugstr_a(lpszTitle), cLinks
370 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
371 return FALSE;
374 /***********************************************************************
375 * OleUIUpdateLinksW (OLEDLG.23)
377 BOOL WINAPI OleUIUpdateLinksW(
378 LPOLEUILINKCONTAINERW lpOleUILinkCntr,
379 HWND hwndParent, LPWSTR lpszTitle, INT cLinks)
381 FIXME("(%p, %p, %s, %d): stub\n",
382 lpOleUILinkCntr, hwndParent, debugstr_w(lpszTitle), cLinks
384 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
385 return FALSE;
388 /***********************************************************************
389 * OleUIPromptUserA (OLEDLG.10)
391 INT WINAPIV OleUIPromptUserA(
392 INT nTemplate, HWND hwndParent, ...)
394 FIXME("(%d, %p, ...): stub\n", nTemplate, hwndParent);
395 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
396 return OLEUI_FALSE;
399 /***********************************************************************
400 * OleUIPromptUserW (OLEDLG.13)
402 INT WINAPIV OleUIPromptUserW(
403 INT nTemplate, HWND hwndParent, ...)
405 FIXME("(%d, %p, ...): stub\n", nTemplate, hwndParent);
406 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
407 return OLEUI_FALSE;
410 /***********************************************************************
411 * OleUIObjectPropertiesA (OLEDLG.11)
413 UINT WINAPI OleUIObjectPropertiesA(
414 LPOLEUIOBJECTPROPSA lpOleUIObjectProps)
416 FIXME("(%p): stub\n", lpOleUIObjectProps);
417 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
418 return OLEUI_FALSE;
421 /***********************************************************************
422 * OleUIObjectPropertiesW (OLEDLG.21)
424 UINT WINAPI OleUIObjectPropertiesW(
425 LPOLEUIOBJECTPROPSW lpOleUIObjectProps)
427 FIXME("(%p): stub\n", lpOleUIObjectProps);
428 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
429 return OLEUI_FALSE;
432 /***********************************************************************
433 * OleUIChangeSourceA (OLEDLG.12)
435 UINT WINAPI OleUIChangeSourceA(
436 LPOLEUICHANGESOURCEA lpOleUIChangeSource)
438 FIXME("(%p): stub\n", lpOleUIChangeSource);
439 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
440 return OLEUI_FALSE;
443 /***********************************************************************
444 * OleUIChangeSourceW (OLEDLG.17)
446 UINT WINAPI OleUIChangeSourceW(
447 LPOLEUICHANGESOURCEW lpOleUIChangeSource)
449 FIXME("(%p): stub\n", lpOleUIChangeSource);
450 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
451 return OLEUI_FALSE;