comdlg32: Fix some alignment issues in the Dutch translation.
[wine/hramrach.git] / dlls / ole32 / ole2.c
blob2e4da539a96631dc4b3ea0d04e34c92a18ff817f
1 /*
2 * OLE2 library
4 * Copyright 1995 Martin von Loewis
5 * Copyright 1999 Francis Beaudet
6 * Copyright 1999 Noel Borthwick
7 * Copyright 1999, 2000 Marcus Meissner
8 * Copyright 2005 Juan Lang
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 #include "config.h"
27 #include <assert.h>
28 #include <stdlib.h>
29 #include <stdarg.h>
30 #include <stdio.h>
31 #include <string.h>
33 #define COBJMACROS
34 #define NONAMELESSUNION
35 #define NONAMELESSSTRUCT
37 #include "windef.h"
38 #include "winbase.h"
39 #include "winerror.h"
40 #include "wingdi.h"
41 #include "winuser.h"
42 #include "winnls.h"
43 #include "winreg.h"
44 #include "ole2.h"
45 #include "ole2ver.h"
47 #include "wine/unicode.h"
48 #include "compobj_private.h"
49 #include "wine/list.h"
51 #include "wine/debug.h"
53 WINE_DEFAULT_DEBUG_CHANNEL(ole);
54 WINE_DECLARE_DEBUG_CHANNEL(accel);
56 /******************************************************************************
57 * These are static/global variables and internal data structures that the
58 * OLE module uses to maintain it's state.
60 typedef struct tagDropTargetNode
62 HWND hwndTarget;
63 IDropTarget* dropTarget;
64 struct list entry;
65 } DropTargetNode;
67 typedef struct tagTrackerWindowInfo
69 IDataObject* dataObject;
70 IDropSource* dropSource;
71 DWORD dwOKEffect;
72 DWORD* pdwEffect;
73 BOOL trackingDone;
74 HRESULT returnValue;
76 BOOL escPressed;
77 HWND curTargetHWND; /* window the mouse is hovering over */
78 HWND curDragTargetHWND; /* might be a ancestor of curTargetHWND */
79 IDropTarget* curDragTarget;
80 POINTL curMousePos; /* current position of the mouse in screen coordinates */
81 DWORD dwKeyState; /* current state of the shift and ctrl keys and the mouse buttons */
82 } TrackerWindowInfo;
84 typedef struct tagOleMenuDescriptor /* OleMenuDescriptor */
86 HWND hwndFrame; /* The containers frame window */
87 HWND hwndActiveObject; /* The active objects window */
88 OLEMENUGROUPWIDTHS mgw; /* OLE menu group widths for the shared menu */
89 HMENU hmenuCombined; /* The combined menu */
90 BOOL bIsServerItem; /* True if the currently open popup belongs to the server */
91 } OleMenuDescriptor;
93 typedef struct tagOleMenuHookItem /* OleMenu hook item in per thread hook list */
95 DWORD tid; /* Thread Id */
96 HANDLE hHeap; /* Heap this is allocated from */
97 HHOOK GetMsg_hHook; /* message hook for WH_GETMESSAGE */
98 HHOOK CallWndProc_hHook; /* message hook for WH_CALLWNDPROC */
99 struct tagOleMenuHookItem *next;
100 } OleMenuHookItem;
102 static OleMenuHookItem *hook_list;
105 * This is the lock count on the OLE library. It is controlled by the
106 * OLEInitialize/OLEUninitialize methods.
108 static LONG OLE_moduleLockCount = 0;
111 * Name of our registered window class.
113 static const WCHAR OLEDD_DRAGTRACKERCLASS[] =
114 {'W','i','n','e','D','r','a','g','D','r','o','p','T','r','a','c','k','e','r','3','2',0};
117 * Name of menu descriptor property.
119 static const WCHAR prop_olemenuW[] =
120 {'P','R','O','P','_','O','L','E','M','e','n','u','D','e','s','c','r','i','p','t','o','r',0};
123 * This is the head of the Drop target container.
125 static struct list targetListHead = LIST_INIT(targetListHead);
127 /******************************************************************************
128 * These are the prototypes of miscellaneous utility methods
130 static void OLEUTL_ReadRegistryDWORDValue(HKEY regKey, DWORD* pdwValue);
132 /******************************************************************************
133 * These are the prototypes of the utility methods used to manage a shared menu
135 static void OLEMenu_Initialize(void);
136 static void OLEMenu_UnInitialize(void);
137 static BOOL OLEMenu_InstallHooks( DWORD tid );
138 static BOOL OLEMenu_UnInstallHooks( DWORD tid );
139 static OleMenuHookItem * OLEMenu_IsHookInstalled( DWORD tid );
140 static BOOL OLEMenu_FindMainMenuIndex( HMENU hMainMenu, HMENU hPopupMenu, UINT *pnPos );
141 static BOOL OLEMenu_SetIsServerMenu( HMENU hmenu, OleMenuDescriptor *pOleMenuDescriptor );
142 static LRESULT CALLBACK OLEMenu_CallWndProc(INT code, WPARAM wParam, LPARAM lParam);
143 static LRESULT CALLBACK OLEMenu_GetMsgProc(INT code, WPARAM wParam, LPARAM lParam);
145 /******************************************************************************
146 * These are the prototypes of the OLE Clipboard initialization methods (in clipboard.c)
148 extern void OLEClipbrd_UnInitialize(void);
149 extern void OLEClipbrd_Initialize(void);
151 /******************************************************************************
152 * These are the prototypes of the utility methods used for OLE Drag n Drop
154 static void OLEDD_Initialize(void);
155 static DropTargetNode* OLEDD_FindDropTarget(
156 HWND hwndOfTarget);
157 static void OLEDD_FreeDropTarget(DropTargetNode*, BOOL);
158 static LRESULT WINAPI OLEDD_DragTrackerWindowProc(
159 HWND hwnd,
160 UINT uMsg,
161 WPARAM wParam,
162 LPARAM lParam);
163 static void OLEDD_TrackMouseMove(
164 TrackerWindowInfo* trackerInfo);
165 static void OLEDD_TrackStateChange(
166 TrackerWindowInfo* trackerInfo);
167 static DWORD OLEDD_GetButtonState(void);
170 /******************************************************************************
171 * OleBuildVersion [OLE32.@]
173 DWORD WINAPI OleBuildVersion(void)
175 TRACE("Returning version %d, build %d.\n", rmm, rup);
176 return (rmm<<16)+rup;
179 /***********************************************************************
180 * OleInitialize (OLE32.@)
182 HRESULT WINAPI OleInitialize(LPVOID reserved)
184 HRESULT hr;
186 TRACE("(%p)\n", reserved);
189 * The first duty of the OleInitialize is to initialize the COM libraries.
191 hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
194 * If the CoInitializeEx call failed, the OLE libraries can't be
195 * initialized.
197 if (FAILED(hr))
198 return hr;
200 if (!COM_CurrentInfo()->ole_inits)
201 hr = S_OK;
204 * Then, it has to initialize the OLE specific modules.
205 * This includes:
206 * Clipboard
207 * Drag and Drop
208 * Object linking and Embedding
209 * In-place activation
211 if (!COM_CurrentInfo()->ole_inits++ &&
212 InterlockedIncrement(&OLE_moduleLockCount) == 1)
215 * Initialize the libraries.
217 TRACE("() - Initializing the OLE libraries\n");
220 * OLE Clipboard
222 OLEClipbrd_Initialize();
225 * Drag and Drop
227 OLEDD_Initialize();
230 * OLE shared menu
232 OLEMenu_Initialize();
235 return hr;
238 /******************************************************************************
239 * OleUninitialize [OLE32.@]
241 void WINAPI OleUninitialize(void)
243 TRACE("()\n");
246 * If we hit the bottom of the lock stack, free the libraries.
248 if (!--COM_CurrentInfo()->ole_inits && !InterlockedDecrement(&OLE_moduleLockCount))
251 * Actually free the libraries.
253 TRACE("() - Freeing the last reference count\n");
256 * OLE Clipboard
258 OLEClipbrd_UnInitialize();
261 * OLE shared menu
263 OLEMenu_UnInitialize();
267 * Then, uninitialize the COM libraries.
269 CoUninitialize();
272 /******************************************************************************
273 * OleInitializeWOW [OLE32.@]
275 HRESULT WINAPI OleInitializeWOW(DWORD x, DWORD y) {
276 FIXME("(0x%08x, 0x%08x),stub!\n",x, y);
277 return 0;
280 /***********************************************************************
281 * RegisterDragDrop (OLE32.@)
283 HRESULT WINAPI RegisterDragDrop(
284 HWND hwnd,
285 LPDROPTARGET pDropTarget)
287 DropTargetNode* dropTargetInfo;
289 TRACE("(%p,%p)\n", hwnd, pDropTarget);
291 if (!COM_CurrentApt())
293 ERR("COM not initialized\n");
294 return E_OUTOFMEMORY;
297 if (!pDropTarget)
298 return E_INVALIDARG;
300 if (!IsWindow(hwnd))
302 ERR("invalid hwnd %p\n", hwnd);
303 return DRAGDROP_E_INVALIDHWND;
307 * First, check if the window is already registered.
309 dropTargetInfo = OLEDD_FindDropTarget(hwnd);
311 if (dropTargetInfo!=NULL)
312 return DRAGDROP_E_ALREADYREGISTERED;
315 * If it's not there, we can add it. We first create a node for it.
317 dropTargetInfo = HeapAlloc(GetProcessHeap(), 0, sizeof(DropTargetNode));
319 if (dropTargetInfo==NULL)
320 return E_OUTOFMEMORY;
322 dropTargetInfo->hwndTarget = hwnd;
325 * Don't forget that this is an interface pointer, need to nail it down since
326 * we keep a copy of it.
328 IDropTarget_AddRef(pDropTarget);
329 dropTargetInfo->dropTarget = pDropTarget;
331 list_add_tail(&targetListHead, &dropTargetInfo->entry);
333 return S_OK;
336 /***********************************************************************
337 * RevokeDragDrop (OLE32.@)
339 HRESULT WINAPI RevokeDragDrop(
340 HWND hwnd)
342 DropTargetNode* dropTargetInfo;
344 TRACE("(%p)\n", hwnd);
346 if (!IsWindow(hwnd))
348 ERR("invalid hwnd %p\n", hwnd);
349 return DRAGDROP_E_INVALIDHWND;
353 * First, check if the window is already registered.
355 dropTargetInfo = OLEDD_FindDropTarget(hwnd);
358 * If it ain't in there, it's an error.
360 if (dropTargetInfo==NULL)
361 return DRAGDROP_E_NOTREGISTERED;
363 OLEDD_FreeDropTarget(dropTargetInfo, TRUE);
365 return S_OK;
368 /***********************************************************************
369 * OleRegGetUserType (OLE32.@)
371 * This implementation of OleRegGetUserType ignores the dwFormOfType
372 * parameter and always returns the full name of the object. This is
373 * not too bad since this is the case for many objects because of the
374 * way they are registered.
376 HRESULT WINAPI OleRegGetUserType(
377 REFCLSID clsid,
378 DWORD dwFormOfType,
379 LPOLESTR* pszUserType)
381 char keyName[60];
382 DWORD dwKeyType;
383 DWORD cbData;
384 HKEY clsidKey;
385 LONG hres;
386 LPSTR buffer;
387 HRESULT retVal;
389 * Initialize the out parameter.
391 *pszUserType = NULL;
394 * Build the key name we're looking for
396 sprintf( keyName, "CLSID\\{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}\\",
397 clsid->Data1, clsid->Data2, clsid->Data3,
398 clsid->Data4[0], clsid->Data4[1], clsid->Data4[2], clsid->Data4[3],
399 clsid->Data4[4], clsid->Data4[5], clsid->Data4[6], clsid->Data4[7] );
401 TRACE("(%s, %d, %p)\n", keyName, dwFormOfType, pszUserType);
404 * Open the class id Key
406 hres = RegOpenKeyA(HKEY_CLASSES_ROOT,
407 keyName,
408 &clsidKey);
410 if (hres != ERROR_SUCCESS)
411 return REGDB_E_CLASSNOTREG;
414 * Retrieve the size of the name string.
416 cbData = 0;
418 hres = RegQueryValueExA(clsidKey,
420 NULL,
421 &dwKeyType,
422 NULL,
423 &cbData);
425 if (hres!=ERROR_SUCCESS)
427 RegCloseKey(clsidKey);
428 return REGDB_E_READREGDB;
432 * Allocate a buffer for the registry value.
434 *pszUserType = CoTaskMemAlloc(cbData*2);
436 if (*pszUserType==NULL)
438 RegCloseKey(clsidKey);
439 return E_OUTOFMEMORY;
442 buffer = HeapAlloc(GetProcessHeap(), 0, cbData);
444 if (buffer == NULL)
446 RegCloseKey(clsidKey);
447 CoTaskMemFree(*pszUserType);
448 *pszUserType=NULL;
449 return E_OUTOFMEMORY;
452 hres = RegQueryValueExA(clsidKey,
454 NULL,
455 &dwKeyType,
456 (LPBYTE) buffer,
457 &cbData);
459 RegCloseKey(clsidKey);
462 if (hres!=ERROR_SUCCESS)
464 CoTaskMemFree(*pszUserType);
465 *pszUserType=NULL;
467 retVal = REGDB_E_READREGDB;
469 else
471 MultiByteToWideChar( CP_ACP, 0, buffer, -1, *pszUserType, cbData /*FIXME*/ );
472 retVal = S_OK;
474 HeapFree(GetProcessHeap(), 0, buffer);
476 return retVal;
479 /***********************************************************************
480 * DoDragDrop [OLE32.@]
482 HRESULT WINAPI DoDragDrop (
483 IDataObject *pDataObject, /* [in] ptr to the data obj */
484 IDropSource* pDropSource, /* [in] ptr to the source obj */
485 DWORD dwOKEffect, /* [in] effects allowed by the source */
486 DWORD *pdwEffect) /* [out] ptr to effects of the source */
488 static const WCHAR trackerW[] = {'T','r','a','c','k','e','r','W','i','n','d','o','w',0};
489 TrackerWindowInfo trackerInfo;
490 HWND hwndTrackWindow;
491 MSG msg;
493 TRACE("(%p, %p, %d, %p)\n", pDataObject, pDropSource, dwOKEffect, pdwEffect);
495 if (!pDataObject || !pDropSource || !pdwEffect)
496 return E_INVALIDARG;
499 * Setup the drag n drop tracking window.
502 trackerInfo.dataObject = pDataObject;
503 trackerInfo.dropSource = pDropSource;
504 trackerInfo.dwOKEffect = dwOKEffect;
505 trackerInfo.pdwEffect = pdwEffect;
506 trackerInfo.trackingDone = FALSE;
507 trackerInfo.escPressed = FALSE;
508 trackerInfo.curDragTargetHWND = 0;
509 trackerInfo.curTargetHWND = 0;
510 trackerInfo.curDragTarget = 0;
512 hwndTrackWindow = CreateWindowW(OLEDD_DRAGTRACKERCLASS, trackerW,
513 WS_POPUP, CW_USEDEFAULT, CW_USEDEFAULT,
514 CW_USEDEFAULT, CW_USEDEFAULT, 0, 0, 0,
515 &trackerInfo);
517 if (hwndTrackWindow)
520 * Capture the mouse input
522 SetCapture(hwndTrackWindow);
524 msg.message = 0;
527 * Pump messages. All mouse input should go to the capture window.
529 while (!trackerInfo.trackingDone && GetMessageW(&msg, 0, 0, 0) )
531 trackerInfo.curMousePos.x = msg.pt.x;
532 trackerInfo.curMousePos.y = msg.pt.y;
533 trackerInfo.dwKeyState = OLEDD_GetButtonState();
535 if ( (msg.message >= WM_KEYFIRST) &&
536 (msg.message <= WM_KEYLAST) )
539 * When keyboard messages are sent to windows on this thread, we
540 * want to ignore notify the drop source that the state changed.
541 * in the case of the Escape key, we also notify the drop source
542 * we give it a special meaning.
544 if ( (msg.message==WM_KEYDOWN) &&
545 (msg.wParam==VK_ESCAPE) )
547 trackerInfo.escPressed = TRUE;
551 * Notify the drop source.
553 OLEDD_TrackStateChange(&trackerInfo);
555 else
558 * Dispatch the messages only when it's not a keyboard message.
560 DispatchMessageW(&msg);
564 /* re-post the quit message to outer message loop */
565 if (msg.message == WM_QUIT)
566 PostQuitMessage(msg.wParam);
568 * Destroy the temporary window.
570 DestroyWindow(hwndTrackWindow);
572 return trackerInfo.returnValue;
575 return E_FAIL;
578 /***********************************************************************
579 * OleQueryLinkFromData [OLE32.@]
581 HRESULT WINAPI OleQueryLinkFromData(
582 IDataObject* pSrcDataObject)
584 FIXME("(%p),stub!\n", pSrcDataObject);
585 return S_FALSE;
588 /***********************************************************************
589 * OleRegGetMiscStatus [OLE32.@]
591 HRESULT WINAPI OleRegGetMiscStatus(
592 REFCLSID clsid,
593 DWORD dwAspect,
594 DWORD* pdwStatus)
596 char keyName[60];
597 HKEY clsidKey;
598 HKEY miscStatusKey;
599 HKEY aspectKey;
600 LONG result;
603 * Initialize the out parameter.
605 *pdwStatus = 0;
608 * Build the key name we're looking for
610 sprintf( keyName, "CLSID\\{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}\\",
611 clsid->Data1, clsid->Data2, clsid->Data3,
612 clsid->Data4[0], clsid->Data4[1], clsid->Data4[2], clsid->Data4[3],
613 clsid->Data4[4], clsid->Data4[5], clsid->Data4[6], clsid->Data4[7] );
615 TRACE("(%s, %d, %p)\n", keyName, dwAspect, pdwStatus);
618 * Open the class id Key
620 result = RegOpenKeyA(HKEY_CLASSES_ROOT,
621 keyName,
622 &clsidKey);
624 if (result != ERROR_SUCCESS)
625 return REGDB_E_CLASSNOTREG;
628 * Get the MiscStatus
630 result = RegOpenKeyA(clsidKey,
631 "MiscStatus",
632 &miscStatusKey);
635 if (result != ERROR_SUCCESS)
637 RegCloseKey(clsidKey);
638 return REGDB_E_READREGDB;
642 * Read the default value
644 OLEUTL_ReadRegistryDWORDValue(miscStatusKey, pdwStatus);
647 * Open the key specific to the requested aspect.
649 sprintf(keyName, "%d", dwAspect);
651 result = RegOpenKeyA(miscStatusKey,
652 keyName,
653 &aspectKey);
655 if (result == ERROR_SUCCESS)
657 OLEUTL_ReadRegistryDWORDValue(aspectKey, pdwStatus);
658 RegCloseKey(aspectKey);
662 * Cleanup
664 RegCloseKey(miscStatusKey);
665 RegCloseKey(clsidKey);
667 return S_OK;
670 static HRESULT EnumOLEVERB_Construct(HKEY hkeyVerb, ULONG index, IEnumOLEVERB **ppenum);
672 typedef struct
674 const IEnumOLEVERBVtbl *lpvtbl;
675 LONG ref;
677 HKEY hkeyVerb;
678 ULONG index;
679 } EnumOLEVERB;
681 static HRESULT WINAPI EnumOLEVERB_QueryInterface(
682 IEnumOLEVERB *iface, REFIID riid, void **ppv)
684 TRACE("(%s, %p)\n", debugstr_guid(riid), ppv);
685 if (IsEqualIID(riid, &IID_IUnknown) ||
686 IsEqualIID(riid, &IID_IEnumOLEVERB))
688 IUnknown_AddRef(iface);
689 *ppv = iface;
690 return S_OK;
692 return E_NOINTERFACE;
695 static ULONG WINAPI EnumOLEVERB_AddRef(
696 IEnumOLEVERB *iface)
698 EnumOLEVERB *This = (EnumOLEVERB *)iface;
699 TRACE("()\n");
700 return InterlockedIncrement(&This->ref);
703 static ULONG WINAPI EnumOLEVERB_Release(
704 IEnumOLEVERB *iface)
706 EnumOLEVERB *This = (EnumOLEVERB *)iface;
707 LONG refs = InterlockedDecrement(&This->ref);
708 TRACE("()\n");
709 if (!refs)
711 RegCloseKey(This->hkeyVerb);
712 HeapFree(GetProcessHeap(), 0, This);
714 return refs;
717 static HRESULT WINAPI EnumOLEVERB_Next(
718 IEnumOLEVERB *iface, ULONG celt, LPOLEVERB rgelt,
719 ULONG *pceltFetched)
721 EnumOLEVERB *This = (EnumOLEVERB *)iface;
722 HRESULT hr = S_OK;
724 TRACE("(%d, %p, %p)\n", celt, rgelt, pceltFetched);
726 if (pceltFetched)
727 *pceltFetched = 0;
729 for (; celt; celt--, rgelt++)
731 WCHAR wszSubKey[20];
732 LONG cbData;
733 LPWSTR pwszOLEVERB;
734 LPWSTR pwszMenuFlags;
735 LPWSTR pwszAttribs;
736 LONG res = RegEnumKeyW(This->hkeyVerb, This->index, wszSubKey, sizeof(wszSubKey)/sizeof(wszSubKey[0]));
737 if (res == ERROR_NO_MORE_ITEMS)
739 hr = S_FALSE;
740 break;
742 else if (res != ERROR_SUCCESS)
744 ERR("RegEnumKeyW failed with error %d\n", res);
745 hr = REGDB_E_READREGDB;
746 break;
748 res = RegQueryValueW(This->hkeyVerb, wszSubKey, NULL, &cbData);
749 if (res != ERROR_SUCCESS)
751 ERR("RegQueryValueW failed with error %d\n", res);
752 hr = REGDB_E_READREGDB;
753 break;
755 pwszOLEVERB = CoTaskMemAlloc(cbData);
756 if (!pwszOLEVERB)
758 hr = E_OUTOFMEMORY;
759 break;
761 res = RegQueryValueW(This->hkeyVerb, wszSubKey, pwszOLEVERB, &cbData);
762 if (res != ERROR_SUCCESS)
764 ERR("RegQueryValueW failed with error %d\n", res);
765 hr = REGDB_E_READREGDB;
766 CoTaskMemFree(pwszOLEVERB);
767 break;
770 TRACE("verb string: %s\n", debugstr_w(pwszOLEVERB));
771 pwszMenuFlags = strchrW(pwszOLEVERB, ',');
772 if (!pwszMenuFlags)
774 hr = OLEOBJ_E_INVALIDVERB;
775 CoTaskMemFree(pwszOLEVERB);
776 break;
778 /* nul terminate the name string and advance to first character */
779 *pwszMenuFlags = '\0';
780 pwszMenuFlags++;
781 pwszAttribs = strchrW(pwszMenuFlags, ',');
782 if (!pwszAttribs)
784 hr = OLEOBJ_E_INVALIDVERB;
785 CoTaskMemFree(pwszOLEVERB);
786 break;
788 /* nul terminate the menu string and advance to first character */
789 *pwszAttribs = '\0';
790 pwszAttribs++;
792 /* fill out structure for this verb */
793 rgelt->lVerb = atolW(wszSubKey);
794 rgelt->lpszVerbName = pwszOLEVERB; /* user should free */
795 rgelt->fuFlags = atolW(pwszMenuFlags);
796 rgelt->grfAttribs = atolW(pwszAttribs);
798 if (pceltFetched)
799 (*pceltFetched)++;
800 This->index++;
802 return hr;
805 static HRESULT WINAPI EnumOLEVERB_Skip(
806 IEnumOLEVERB *iface, ULONG celt)
808 EnumOLEVERB *This = (EnumOLEVERB *)iface;
810 TRACE("(%d)\n", celt);
812 This->index += celt;
813 return S_OK;
816 static HRESULT WINAPI EnumOLEVERB_Reset(
817 IEnumOLEVERB *iface)
819 EnumOLEVERB *This = (EnumOLEVERB *)iface;
821 TRACE("()\n");
823 This->index = 0;
824 return S_OK;
827 static HRESULT WINAPI EnumOLEVERB_Clone(
828 IEnumOLEVERB *iface,
829 IEnumOLEVERB **ppenum)
831 EnumOLEVERB *This = (EnumOLEVERB *)iface;
832 HKEY hkeyVerb;
833 TRACE("(%p)\n", ppenum);
834 if (!DuplicateHandle(GetCurrentProcess(), This->hkeyVerb, GetCurrentProcess(), (HANDLE *)&hkeyVerb, 0, FALSE, DUPLICATE_SAME_ACCESS))
835 return HRESULT_FROM_WIN32(GetLastError());
836 return EnumOLEVERB_Construct(hkeyVerb, This->index, ppenum);
839 static const IEnumOLEVERBVtbl EnumOLEVERB_VTable =
841 EnumOLEVERB_QueryInterface,
842 EnumOLEVERB_AddRef,
843 EnumOLEVERB_Release,
844 EnumOLEVERB_Next,
845 EnumOLEVERB_Skip,
846 EnumOLEVERB_Reset,
847 EnumOLEVERB_Clone
850 static HRESULT EnumOLEVERB_Construct(HKEY hkeyVerb, ULONG index, IEnumOLEVERB **ppenum)
852 EnumOLEVERB *This = HeapAlloc(GetProcessHeap(), 0, sizeof(*This));
853 if (!This)
855 RegCloseKey(hkeyVerb);
856 return E_OUTOFMEMORY;
858 This->lpvtbl = &EnumOLEVERB_VTable;
859 This->ref = 1;
860 This->index = index;
861 This->hkeyVerb = hkeyVerb;
862 *ppenum = (IEnumOLEVERB *)&This->lpvtbl;
863 return S_OK;
866 /***********************************************************************
867 * OleRegEnumVerbs [OLE32.@]
869 * Enumerates verbs associated with a class stored in the registry.
871 * PARAMS
872 * clsid [I] Class ID to enumerate the verbs for.
873 * ppenum [O] Enumerator.
875 * RETURNS
876 * S_OK: Success.
877 * REGDB_E_CLASSNOTREG: The specified class does not have a key in the registry.
878 * REGDB_E_READREGDB: The class key could not be opened for some other reason.
879 * OLE_E_REGDB_KEY: The Verb subkey for the class is not present.
880 * OLEOBJ_E_NOVERBS: The Verb subkey for the class is empty.
882 HRESULT WINAPI OleRegEnumVerbs (REFCLSID clsid, LPENUMOLEVERB* ppenum)
884 LONG res;
885 HKEY hkeyVerb;
886 DWORD dwSubKeys;
887 static const WCHAR wszVerb[] = {'V','e','r','b',0};
889 TRACE("(%s, %p)\n", debugstr_guid(clsid), ppenum);
891 res = COM_OpenKeyForCLSID(clsid, wszVerb, KEY_READ, &hkeyVerb);
892 if (FAILED(res))
894 if (res == REGDB_E_CLASSNOTREG)
895 ERR("CLSID %s not registered\n", debugstr_guid(clsid));
896 else if (res == REGDB_E_KEYMISSING)
897 ERR("no Verbs key for class %s\n", debugstr_guid(clsid));
898 else
899 ERR("failed to open Verbs key for CLSID %s with error %d\n",
900 debugstr_guid(clsid), res);
901 return res;
904 res = RegQueryInfoKeyW(hkeyVerb, NULL, NULL, NULL, &dwSubKeys, NULL,
905 NULL, NULL, NULL, NULL, NULL, NULL);
906 if (res != ERROR_SUCCESS)
908 ERR("failed to get subkey count with error %d\n", GetLastError());
909 return REGDB_E_READREGDB;
912 if (!dwSubKeys)
914 WARN("class %s has no verbs\n", debugstr_guid(clsid));
915 RegCloseKey(hkeyVerb);
916 return OLEOBJ_E_NOVERBS;
919 return EnumOLEVERB_Construct(hkeyVerb, 0, ppenum);
922 /******************************************************************************
923 * OleSetContainedObject [OLE32.@]
925 HRESULT WINAPI OleSetContainedObject(
926 LPUNKNOWN pUnknown,
927 BOOL fContained)
929 IRunnableObject* runnable = NULL;
930 HRESULT hres;
932 TRACE("(%p,%x)\n", pUnknown, fContained);
934 hres = IUnknown_QueryInterface(pUnknown,
935 &IID_IRunnableObject,
936 (void**)&runnable);
938 if (SUCCEEDED(hres))
940 hres = IRunnableObject_SetContainedObject(runnable, fContained);
942 IRunnableObject_Release(runnable);
944 return hres;
947 return S_OK;
950 /******************************************************************************
951 * OleRun [OLE32.@]
953 * Set the OLE object to the running state.
955 * PARAMS
956 * pUnknown [I] OLE object to run.
958 * RETURNS
959 * Success: S_OK.
960 * Failure: Any HRESULT code.
962 HRESULT WINAPI OleRun(LPUNKNOWN pUnknown)
964 IRunnableObject *runable;
965 HRESULT hres;
967 TRACE("(%p)\n", pUnknown);
969 hres = IUnknown_QueryInterface(pUnknown, &IID_IRunnableObject, (void**)&runable);
970 if (FAILED(hres))
971 return S_OK; /* Appears to return no error. */
973 hres = IRunnableObject_Run(runable, NULL);
974 IRunnableObject_Release(runable);
975 return hres;
978 /******************************************************************************
979 * OleLoad [OLE32.@]
981 HRESULT WINAPI OleLoad(
982 LPSTORAGE pStg,
983 REFIID riid,
984 LPOLECLIENTSITE pClientSite,
985 LPVOID* ppvObj)
987 IPersistStorage* persistStorage = NULL;
988 IUnknown* pUnk;
989 IOleObject* pOleObject = NULL;
990 STATSTG storageInfo;
991 HRESULT hres;
993 TRACE("(%p, %s, %p, %p)\n", pStg, debugstr_guid(riid), pClientSite, ppvObj);
995 *ppvObj = NULL;
998 * TODO, Conversion ... OleDoAutoConvert
1002 * Get the class ID for the object.
1004 hres = IStorage_Stat(pStg, &storageInfo, STATFLAG_NONAME);
1007 * Now, try and create the handler for the object
1009 hres = CoCreateInstance(&storageInfo.clsid,
1010 NULL,
1011 CLSCTX_INPROC_HANDLER|CLSCTX_INPROC_SERVER,
1012 riid,
1013 (void**)&pUnk);
1016 * If that fails, as it will most times, load the default
1017 * OLE handler.
1019 if (FAILED(hres))
1021 hres = OleCreateDefaultHandler(&storageInfo.clsid,
1022 NULL,
1023 riid,
1024 (void**)&pUnk);
1028 * If we couldn't find a handler... this is bad. Abort the whole thing.
1030 if (FAILED(hres))
1031 return hres;
1033 if (pClientSite)
1035 hres = IUnknown_QueryInterface(pUnk, &IID_IOleObject, (void **)&pOleObject);
1036 if (SUCCEEDED(hres))
1038 DWORD dwStatus;
1039 hres = IOleObject_GetMiscStatus(pOleObject, DVASPECT_CONTENT, &dwStatus);
1043 if (SUCCEEDED(hres))
1045 * Initialize the object with it's IPersistStorage interface.
1047 hres = IOleObject_QueryInterface(pUnk,
1048 &IID_IPersistStorage,
1049 (void**)&persistStorage);
1051 if (SUCCEEDED(hres))
1053 hres = IPersistStorage_Load(persistStorage, pStg);
1055 IPersistStorage_Release(persistStorage);
1056 persistStorage = NULL;
1059 if (SUCCEEDED(hres) && pClientSite)
1061 * Inform the new object of it's client site.
1063 hres = IOleObject_SetClientSite(pOleObject, pClientSite);
1066 * Cleanup interfaces used internally
1068 if (pOleObject)
1069 IOleObject_Release(pOleObject);
1071 if (SUCCEEDED(hres))
1073 IOleLink *pOleLink;
1074 HRESULT hres1;
1075 hres1 = IUnknown_QueryInterface(pUnk, &IID_IOleLink, (void **)&pOleLink);
1076 if (SUCCEEDED(hres1))
1078 FIXME("handle OLE link\n");
1079 IOleLink_Release(pOleLink);
1083 if (FAILED(hres))
1085 IUnknown_Release(pUnk);
1086 pUnk = NULL;
1089 *ppvObj = pUnk;
1091 return hres;
1094 /***********************************************************************
1095 * OleSave [OLE32.@]
1097 HRESULT WINAPI OleSave(
1098 LPPERSISTSTORAGE pPS,
1099 LPSTORAGE pStg,
1100 BOOL fSameAsLoad)
1102 HRESULT hres;
1103 CLSID objectClass;
1105 TRACE("(%p,%p,%x)\n", pPS, pStg, fSameAsLoad);
1108 * First, we transfer the class ID (if available)
1110 hres = IPersistStorage_GetClassID(pPS, &objectClass);
1112 if (SUCCEEDED(hres))
1114 WriteClassStg(pStg, &objectClass);
1118 * Then, we ask the object to save itself to the
1119 * storage. If it is successful, we commit the storage.
1121 hres = IPersistStorage_Save(pPS, pStg, fSameAsLoad);
1123 if (SUCCEEDED(hres))
1125 IStorage_Commit(pStg,
1126 STGC_DEFAULT);
1129 return hres;
1133 /******************************************************************************
1134 * OleLockRunning [OLE32.@]
1136 HRESULT WINAPI OleLockRunning(LPUNKNOWN pUnknown, BOOL fLock, BOOL fLastUnlockCloses)
1138 IRunnableObject* runnable = NULL;
1139 HRESULT hres;
1141 TRACE("(%p,%x,%x)\n", pUnknown, fLock, fLastUnlockCloses);
1143 hres = IUnknown_QueryInterface(pUnknown,
1144 &IID_IRunnableObject,
1145 (void**)&runnable);
1147 if (SUCCEEDED(hres))
1149 hres = IRunnableObject_LockRunning(runnable, fLock, fLastUnlockCloses);
1151 IRunnableObject_Release(runnable);
1153 return hres;
1156 return S_OK;
1160 /**************************************************************************
1161 * Internal methods to manage the shared OLE menu in response to the
1162 * OLE***MenuDescriptor API
1165 /***
1166 * OLEMenu_Initialize()
1168 * Initializes the OLEMENU data structures.
1170 static void OLEMenu_Initialize(void)
1174 /***
1175 * OLEMenu_UnInitialize()
1177 * Releases the OLEMENU data structures.
1179 static void OLEMenu_UnInitialize(void)
1183 /*************************************************************************
1184 * OLEMenu_InstallHooks
1185 * Install thread scope message hooks for WH_GETMESSAGE and WH_CALLWNDPROC
1187 * RETURNS: TRUE if message hooks were successfully installed
1188 * FALSE on failure
1190 static BOOL OLEMenu_InstallHooks( DWORD tid )
1192 OleMenuHookItem *pHookItem;
1194 /* Create an entry for the hook table */
1195 if ( !(pHookItem = HeapAlloc(GetProcessHeap(), 0,
1196 sizeof(OleMenuHookItem)) ) )
1197 return FALSE;
1199 pHookItem->tid = tid;
1200 pHookItem->hHeap = GetProcessHeap();
1201 pHookItem->CallWndProc_hHook = NULL;
1203 /* Install a thread scope message hook for WH_GETMESSAGE */
1204 pHookItem->GetMsg_hHook = SetWindowsHookExW( WH_GETMESSAGE, OLEMenu_GetMsgProc,
1205 0, GetCurrentThreadId() );
1206 if ( !pHookItem->GetMsg_hHook )
1207 goto CLEANUP;
1209 /* Install a thread scope message hook for WH_CALLWNDPROC */
1210 pHookItem->CallWndProc_hHook = SetWindowsHookExW( WH_CALLWNDPROC, OLEMenu_CallWndProc,
1211 0, GetCurrentThreadId() );
1212 if ( !pHookItem->CallWndProc_hHook )
1213 goto CLEANUP;
1215 /* Insert the hook table entry */
1216 pHookItem->next = hook_list;
1217 hook_list = pHookItem;
1219 return TRUE;
1221 CLEANUP:
1222 /* Unhook any hooks */
1223 if ( pHookItem->GetMsg_hHook )
1224 UnhookWindowsHookEx( pHookItem->GetMsg_hHook );
1225 if ( pHookItem->CallWndProc_hHook )
1226 UnhookWindowsHookEx( pHookItem->CallWndProc_hHook );
1227 /* Release the hook table entry */
1228 HeapFree(pHookItem->hHeap, 0, pHookItem );
1230 return FALSE;
1233 /*************************************************************************
1234 * OLEMenu_UnInstallHooks
1235 * UnInstall thread scope message hooks for WH_GETMESSAGE and WH_CALLWNDPROC
1237 * RETURNS: TRUE if message hooks were successfully installed
1238 * FALSE on failure
1240 static BOOL OLEMenu_UnInstallHooks( DWORD tid )
1242 OleMenuHookItem *pHookItem = NULL;
1243 OleMenuHookItem **ppHook = &hook_list;
1245 while (*ppHook)
1247 if ((*ppHook)->tid == tid)
1249 pHookItem = *ppHook;
1250 *ppHook = pHookItem->next;
1251 break;
1253 ppHook = &(*ppHook)->next;
1255 if (!pHookItem) return FALSE;
1257 /* Uninstall the hooks installed for this thread */
1258 if ( !UnhookWindowsHookEx( pHookItem->GetMsg_hHook ) )
1259 goto CLEANUP;
1260 if ( !UnhookWindowsHookEx( pHookItem->CallWndProc_hHook ) )
1261 goto CLEANUP;
1263 /* Release the hook table entry */
1264 HeapFree(pHookItem->hHeap, 0, pHookItem );
1266 return TRUE;
1268 CLEANUP:
1269 /* Release the hook table entry */
1270 HeapFree(pHookItem->hHeap, 0, pHookItem );
1272 return FALSE;
1275 /*************************************************************************
1276 * OLEMenu_IsHookInstalled
1277 * Tests if OLEMenu hooks have been installed for a thread
1279 * RETURNS: The pointer and index of the hook table entry for the tid
1280 * NULL and -1 for the index if no hooks were installed for this thread
1282 static OleMenuHookItem * OLEMenu_IsHookInstalled( DWORD tid )
1284 OleMenuHookItem *pHookItem;
1286 /* Do a simple linear search for an entry whose tid matches ours.
1287 * We really need a map but efficiency is not a concern here. */
1288 for (pHookItem = hook_list; pHookItem; pHookItem = pHookItem->next)
1290 if ( tid == pHookItem->tid )
1291 return pHookItem;
1294 return NULL;
1297 /***********************************************************************
1298 * OLEMenu_FindMainMenuIndex
1300 * Used by OLEMenu API to find the top level group a menu item belongs to.
1301 * On success pnPos contains the index of the item in the top level menu group
1303 * RETURNS: TRUE if the ID was found, FALSE on failure
1305 static BOOL OLEMenu_FindMainMenuIndex( HMENU hMainMenu, HMENU hPopupMenu, UINT *pnPos )
1307 INT i, nItems;
1309 nItems = GetMenuItemCount( hMainMenu );
1311 for (i = 0; i < nItems; i++)
1313 HMENU hsubmenu;
1315 /* Is the current item a submenu? */
1316 if ( (hsubmenu = GetSubMenu(hMainMenu, i)) )
1318 /* If the handle is the same we're done */
1319 if ( hsubmenu == hPopupMenu )
1321 if (pnPos)
1322 *pnPos = i;
1323 return TRUE;
1325 /* Recursively search without updating pnPos */
1326 else if ( OLEMenu_FindMainMenuIndex( hsubmenu, hPopupMenu, NULL ) )
1328 if (pnPos)
1329 *pnPos = i;
1330 return TRUE;
1335 return FALSE;
1338 /***********************************************************************
1339 * OLEMenu_SetIsServerMenu
1341 * Checks whether a popup menu belongs to a shared menu group which is
1342 * owned by the server, and sets the menu descriptor state accordingly.
1343 * All menu messages from these groups should be routed to the server.
1345 * RETURNS: TRUE if the popup menu is part of a server owned group
1346 * FALSE if the popup menu is part of a container owned group
1348 static BOOL OLEMenu_SetIsServerMenu( HMENU hmenu, OleMenuDescriptor *pOleMenuDescriptor )
1350 UINT nPos = 0, nWidth, i;
1352 pOleMenuDescriptor->bIsServerItem = FALSE;
1354 /* Don't bother searching if the popup is the combined menu itself */
1355 if ( hmenu == pOleMenuDescriptor->hmenuCombined )
1356 return FALSE;
1358 /* Find the menu item index in the shared OLE menu that this item belongs to */
1359 if ( !OLEMenu_FindMainMenuIndex( pOleMenuDescriptor->hmenuCombined, hmenu, &nPos ) )
1360 return FALSE;
1362 /* The group widths array has counts for the number of elements
1363 * in the groups File, Edit, Container, Object, Window, Help.
1364 * The Edit, Object & Help groups belong to the server object
1365 * and the other three belong to the container.
1366 * Loop through the group widths and locate the group we are a member of.
1368 for ( i = 0, nWidth = 0; i < 6; i++ )
1370 nWidth += pOleMenuDescriptor->mgw.width[i];
1371 if ( nPos < nWidth )
1373 /* Odd elements are server menu widths */
1374 pOleMenuDescriptor->bIsServerItem = (i%2) ? TRUE : FALSE;
1375 break;
1379 return pOleMenuDescriptor->bIsServerItem;
1382 /*************************************************************************
1383 * OLEMenu_CallWndProc
1384 * Thread scope WH_CALLWNDPROC hook proc filter function (callback)
1385 * This is invoked from a message hook installed in OleSetMenuDescriptor.
1387 static LRESULT CALLBACK OLEMenu_CallWndProc(INT code, WPARAM wParam, LPARAM lParam)
1389 LPCWPSTRUCT pMsg;
1390 HOLEMENU hOleMenu = 0;
1391 OleMenuDescriptor *pOleMenuDescriptor = NULL;
1392 OleMenuHookItem *pHookItem = NULL;
1393 WORD fuFlags;
1395 TRACE("%i, %04lx, %08lx\n", code, wParam, lParam );
1397 /* Check if we're being asked to process the message */
1398 if ( HC_ACTION != code )
1399 goto NEXTHOOK;
1401 /* Retrieve the current message being dispatched from lParam */
1402 pMsg = (LPCWPSTRUCT)lParam;
1404 /* Check if the message is destined for a window we are interested in:
1405 * If the window has an OLEMenu property we may need to dispatch
1406 * the menu message to its active objects window instead. */
1408 hOleMenu = GetPropW( pMsg->hwnd, prop_olemenuW );
1409 if ( !hOleMenu )
1410 goto NEXTHOOK;
1412 /* Get the menu descriptor */
1413 pOleMenuDescriptor = GlobalLock( hOleMenu );
1414 if ( !pOleMenuDescriptor ) /* Bad descriptor! */
1415 goto NEXTHOOK;
1417 /* Process menu messages */
1418 switch( pMsg->message )
1420 case WM_INITMENU:
1422 /* Reset the menu descriptor state */
1423 pOleMenuDescriptor->bIsServerItem = FALSE;
1425 /* Send this message to the server as well */
1426 SendMessageW( pOleMenuDescriptor->hwndActiveObject,
1427 pMsg->message, pMsg->wParam, pMsg->lParam );
1428 goto NEXTHOOK;
1431 case WM_INITMENUPOPUP:
1433 /* Save the state for whether this is a server owned menu */
1434 OLEMenu_SetIsServerMenu( (HMENU)pMsg->wParam, pOleMenuDescriptor );
1435 break;
1438 case WM_MENUSELECT:
1440 fuFlags = HIWORD(pMsg->wParam); /* Get flags */
1441 if ( fuFlags & MF_SYSMENU )
1442 goto NEXTHOOK;
1444 /* Save the state for whether this is a server owned popup menu */
1445 else if ( fuFlags & MF_POPUP )
1446 OLEMenu_SetIsServerMenu( (HMENU)pMsg->lParam, pOleMenuDescriptor );
1448 break;
1451 case WM_DRAWITEM:
1453 LPDRAWITEMSTRUCT lpdis = (LPDRAWITEMSTRUCT) pMsg->lParam;
1454 if ( pMsg->wParam != 0 || lpdis->CtlType != ODT_MENU )
1455 goto NEXTHOOK; /* Not a menu message */
1457 break;
1460 default:
1461 goto NEXTHOOK;
1464 /* If the message was for the server dispatch it accordingly */
1465 if ( pOleMenuDescriptor->bIsServerItem )
1467 SendMessageW( pOleMenuDescriptor->hwndActiveObject,
1468 pMsg->message, pMsg->wParam, pMsg->lParam );
1471 NEXTHOOK:
1472 if ( pOleMenuDescriptor )
1473 GlobalUnlock( hOleMenu );
1475 /* Lookup the hook item for the current thread */
1476 if ( !( pHookItem = OLEMenu_IsHookInstalled( GetCurrentThreadId() ) ) )
1478 /* This should never fail!! */
1479 WARN("could not retrieve hHook for current thread!\n" );
1480 return 0;
1483 /* Pass on the message to the next hooker */
1484 return CallNextHookEx( pHookItem->CallWndProc_hHook, code, wParam, lParam );
1487 /*************************************************************************
1488 * OLEMenu_GetMsgProc
1489 * Thread scope WH_GETMESSAGE hook proc filter function (callback)
1490 * This is invoked from a message hook installed in OleSetMenuDescriptor.
1492 static LRESULT CALLBACK OLEMenu_GetMsgProc(INT code, WPARAM wParam, LPARAM lParam)
1494 LPMSG pMsg;
1495 HOLEMENU hOleMenu = 0;
1496 OleMenuDescriptor *pOleMenuDescriptor = NULL;
1497 OleMenuHookItem *pHookItem = NULL;
1498 WORD wCode;
1500 TRACE("%i, %04lx, %08lx\n", code, wParam, lParam );
1502 /* Check if we're being asked to process a messages */
1503 if ( HC_ACTION != code )
1504 goto NEXTHOOK;
1506 /* Retrieve the current message being dispatched from lParam */
1507 pMsg = (LPMSG)lParam;
1509 /* Check if the message is destined for a window we are interested in:
1510 * If the window has an OLEMenu property we may need to dispatch
1511 * the menu message to its active objects window instead. */
1513 hOleMenu = GetPropW( pMsg->hwnd, prop_olemenuW );
1514 if ( !hOleMenu )
1515 goto NEXTHOOK;
1517 /* Process menu messages */
1518 switch( pMsg->message )
1520 case WM_COMMAND:
1522 wCode = HIWORD(pMsg->wParam); /* Get notification code */
1523 if ( wCode )
1524 goto NEXTHOOK; /* Not a menu message */
1525 break;
1527 default:
1528 goto NEXTHOOK;
1531 /* Get the menu descriptor */
1532 pOleMenuDescriptor = GlobalLock( hOleMenu );
1533 if ( !pOleMenuDescriptor ) /* Bad descriptor! */
1534 goto NEXTHOOK;
1536 /* If the message was for the server dispatch it accordingly */
1537 if ( pOleMenuDescriptor->bIsServerItem )
1539 /* Change the hWnd in the message to the active objects hWnd.
1540 * The message loop which reads this message will automatically
1541 * dispatch it to the embedded objects window. */
1542 pMsg->hwnd = pOleMenuDescriptor->hwndActiveObject;
1545 NEXTHOOK:
1546 if ( pOleMenuDescriptor )
1547 GlobalUnlock( hOleMenu );
1549 /* Lookup the hook item for the current thread */
1550 if ( !( pHookItem = OLEMenu_IsHookInstalled( GetCurrentThreadId() ) ) )
1552 /* This should never fail!! */
1553 WARN("could not retrieve hHook for current thread!\n" );
1554 return FALSE;
1557 /* Pass on the message to the next hooker */
1558 return CallNextHookEx( pHookItem->GetMsg_hHook, code, wParam, lParam );
1561 /***********************************************************************
1562 * OleCreateMenuDescriptor [OLE32.@]
1563 * Creates an OLE menu descriptor for OLE to use when dispatching
1564 * menu messages and commands.
1566 * PARAMS:
1567 * hmenuCombined - Handle to the objects combined menu
1568 * lpMenuWidths - Pointer to array of 6 LONG's indicating menus per group
1571 HOLEMENU WINAPI OleCreateMenuDescriptor(
1572 HMENU hmenuCombined,
1573 LPOLEMENUGROUPWIDTHS lpMenuWidths)
1575 HOLEMENU hOleMenu;
1576 OleMenuDescriptor *pOleMenuDescriptor;
1577 int i;
1579 if ( !hmenuCombined || !lpMenuWidths )
1580 return 0;
1582 /* Create an OLE menu descriptor */
1583 if ( !(hOleMenu = GlobalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT,
1584 sizeof(OleMenuDescriptor) ) ) )
1585 return 0;
1587 pOleMenuDescriptor = GlobalLock( hOleMenu );
1588 if ( !pOleMenuDescriptor )
1589 return 0;
1591 /* Initialize menu group widths and hmenu */
1592 for ( i = 0; i < 6; i++ )
1593 pOleMenuDescriptor->mgw.width[i] = lpMenuWidths->width[i];
1595 pOleMenuDescriptor->hmenuCombined = hmenuCombined;
1596 pOleMenuDescriptor->bIsServerItem = FALSE;
1597 GlobalUnlock( hOleMenu );
1599 return hOleMenu;
1602 /***********************************************************************
1603 * OleDestroyMenuDescriptor [OLE32.@]
1604 * Destroy the shared menu descriptor
1606 HRESULT WINAPI OleDestroyMenuDescriptor(
1607 HOLEMENU hmenuDescriptor)
1609 if ( hmenuDescriptor )
1610 GlobalFree( hmenuDescriptor );
1611 return S_OK;
1614 /***********************************************************************
1615 * OleSetMenuDescriptor [OLE32.@]
1616 * Installs or removes OLE dispatching code for the containers frame window.
1618 * PARAMS
1619 * hOleMenu Handle to composite menu descriptor
1620 * hwndFrame Handle to containers frame window
1621 * hwndActiveObject Handle to objects in-place activation window
1622 * lpFrame Pointer to IOleInPlaceFrame on containers window
1623 * lpActiveObject Pointer to IOleInPlaceActiveObject on active in-place object
1625 * RETURNS
1626 * S_OK - menu installed correctly
1627 * E_FAIL, E_INVALIDARG, E_UNEXPECTED - failure
1629 * FIXME
1630 * The lpFrame and lpActiveObject parameters are currently ignored
1631 * OLE should install context sensitive help F1 filtering for the app when
1632 * these are non null.
1634 HRESULT WINAPI OleSetMenuDescriptor(
1635 HOLEMENU hOleMenu,
1636 HWND hwndFrame,
1637 HWND hwndActiveObject,
1638 LPOLEINPLACEFRAME lpFrame,
1639 LPOLEINPLACEACTIVEOBJECT lpActiveObject)
1641 OleMenuDescriptor *pOleMenuDescriptor = NULL;
1643 /* Check args */
1644 if ( !hwndFrame || (hOleMenu && !hwndActiveObject) )
1645 return E_INVALIDARG;
1647 if ( lpFrame || lpActiveObject )
1649 FIXME("(%p, %p, %p, %p, %p), Context sensitive help filtering not implemented!\n",
1650 hOleMenu,
1651 hwndFrame,
1652 hwndActiveObject,
1653 lpFrame,
1654 lpActiveObject);
1657 /* Set up a message hook to intercept the containers frame window messages.
1658 * The message filter is responsible for dispatching menu messages from the
1659 * shared menu which are intended for the object.
1662 if ( hOleMenu ) /* Want to install dispatching code */
1664 /* If OLEMenu hooks are already installed for this thread, fail
1665 * Note: This effectively means that OleSetMenuDescriptor cannot
1666 * be called twice in succession on the same frame window
1667 * without first calling it with a null hOleMenu to uninstall */
1668 if ( OLEMenu_IsHookInstalled( GetCurrentThreadId() ) )
1669 return E_FAIL;
1671 /* Get the menu descriptor */
1672 pOleMenuDescriptor = GlobalLock( hOleMenu );
1673 if ( !pOleMenuDescriptor )
1674 return E_UNEXPECTED;
1676 /* Update the menu descriptor */
1677 pOleMenuDescriptor->hwndFrame = hwndFrame;
1678 pOleMenuDescriptor->hwndActiveObject = hwndActiveObject;
1680 GlobalUnlock( hOleMenu );
1681 pOleMenuDescriptor = NULL;
1683 /* Add a menu descriptor windows property to the frame window */
1684 SetPropW( hwndFrame, prop_olemenuW, hOleMenu );
1686 /* Install thread scope message hooks for WH_GETMESSAGE and WH_CALLWNDPROC */
1687 if ( !OLEMenu_InstallHooks( GetCurrentThreadId() ) )
1688 return E_FAIL;
1690 else /* Want to uninstall dispatching code */
1692 /* Uninstall the hooks */
1693 if ( !OLEMenu_UnInstallHooks( GetCurrentThreadId() ) )
1694 return E_FAIL;
1696 /* Remove the menu descriptor property from the frame window */
1697 RemovePropW( hwndFrame, prop_olemenuW );
1700 return S_OK;
1703 /******************************************************************************
1704 * IsAccelerator [OLE32.@]
1705 * Mostly copied from controls/menu.c TranslateAccelerator implementation
1707 BOOL WINAPI IsAccelerator(HACCEL hAccel, int cAccelEntries, LPMSG lpMsg, WORD* lpwCmd)
1709 LPACCEL lpAccelTbl;
1710 int i;
1712 if(!lpMsg) return FALSE;
1713 if (!hAccel)
1715 WARN_(accel)("NULL accel handle\n");
1716 return FALSE;
1718 if((lpMsg->message != WM_KEYDOWN &&
1719 lpMsg->message != WM_SYSKEYDOWN &&
1720 lpMsg->message != WM_SYSCHAR &&
1721 lpMsg->message != WM_CHAR)) return FALSE;
1722 lpAccelTbl = HeapAlloc(GetProcessHeap(), 0, cAccelEntries * sizeof(ACCEL));
1723 if (NULL == lpAccelTbl)
1725 return FALSE;
1727 if (CopyAcceleratorTableW(hAccel, lpAccelTbl, cAccelEntries) != cAccelEntries)
1729 WARN_(accel)("CopyAcceleratorTableW failed\n");
1730 HeapFree(GetProcessHeap(), 0, lpAccelTbl);
1731 return FALSE;
1734 TRACE_(accel)("hAccel=%p, cAccelEntries=%d,"
1735 "msg->hwnd=%p, msg->message=%04x, wParam=%08lx, lParam=%08lx\n",
1736 hAccel, cAccelEntries,
1737 lpMsg->hwnd, lpMsg->message, lpMsg->wParam, lpMsg->lParam);
1738 for(i = 0; i < cAccelEntries; i++)
1740 if(lpAccelTbl[i].key != lpMsg->wParam)
1741 continue;
1743 if(lpMsg->message == WM_CHAR)
1745 if(!(lpAccelTbl[i].fVirt & FALT) && !(lpAccelTbl[i].fVirt & FVIRTKEY))
1747 TRACE_(accel)("found accel for WM_CHAR: ('%c')\n", LOWORD(lpMsg->wParam) & 0xff);
1748 goto found;
1751 else
1753 if(lpAccelTbl[i].fVirt & FVIRTKEY)
1755 INT mask = 0;
1756 TRACE_(accel)("found accel for virt_key %04lx (scan %04x)\n",
1757 lpMsg->wParam, HIWORD(lpMsg->lParam) & 0xff);
1758 if(GetKeyState(VK_SHIFT) & 0x8000) mask |= FSHIFT;
1759 if(GetKeyState(VK_CONTROL) & 0x8000) mask |= FCONTROL;
1760 if(GetKeyState(VK_MENU) & 0x8000) mask |= FALT;
1761 if(mask == (lpAccelTbl[i].fVirt & (FSHIFT | FCONTROL | FALT))) goto found;
1762 TRACE_(accel)("incorrect SHIFT/CTRL/ALT-state\n");
1764 else
1766 if(!(lpMsg->lParam & 0x01000000)) /* no special_key */
1768 if((lpAccelTbl[i].fVirt & FALT) && (lpMsg->lParam & 0x20000000))
1769 { /* ^^ ALT pressed */
1770 TRACE_(accel)("found accel for Alt-%c\n", LOWORD(lpMsg->wParam) & 0xff);
1771 goto found;
1778 WARN_(accel)("couldn't translate accelerator key\n");
1779 HeapFree(GetProcessHeap(), 0, lpAccelTbl);
1780 return FALSE;
1782 found:
1783 if(lpwCmd) *lpwCmd = lpAccelTbl[i].cmd;
1784 HeapFree(GetProcessHeap(), 0, lpAccelTbl);
1785 return TRUE;
1788 /***********************************************************************
1789 * ReleaseStgMedium [OLE32.@]
1791 void WINAPI ReleaseStgMedium(
1792 STGMEDIUM* pmedium)
1794 switch (pmedium->tymed)
1796 case TYMED_HGLOBAL:
1798 if ( (pmedium->pUnkForRelease==0) &&
1799 (pmedium->u.hGlobal!=0) )
1800 GlobalFree(pmedium->u.hGlobal);
1801 break;
1803 case TYMED_FILE:
1805 if (pmedium->u.lpszFileName!=0)
1807 if (pmedium->pUnkForRelease==0)
1809 DeleteFileW(pmedium->u.lpszFileName);
1812 CoTaskMemFree(pmedium->u.lpszFileName);
1814 break;
1816 case TYMED_ISTREAM:
1818 if (pmedium->u.pstm!=0)
1820 IStream_Release(pmedium->u.pstm);
1822 break;
1824 case TYMED_ISTORAGE:
1826 if (pmedium->u.pstg!=0)
1828 IStorage_Release(pmedium->u.pstg);
1830 break;
1832 case TYMED_GDI:
1834 if ( (pmedium->pUnkForRelease==0) &&
1835 (pmedium->u.hBitmap!=0) )
1836 DeleteObject(pmedium->u.hBitmap);
1837 break;
1839 case TYMED_MFPICT:
1841 if ( (pmedium->pUnkForRelease==0) &&
1842 (pmedium->u.hMetaFilePict!=0) )
1844 LPMETAFILEPICT pMP = GlobalLock(pmedium->u.hMetaFilePict);
1845 DeleteMetaFile(pMP->hMF);
1846 GlobalUnlock(pmedium->u.hMetaFilePict);
1847 GlobalFree(pmedium->u.hMetaFilePict);
1849 break;
1851 case TYMED_ENHMF:
1853 if ( (pmedium->pUnkForRelease==0) &&
1854 (pmedium->u.hEnhMetaFile!=0) )
1856 DeleteEnhMetaFile(pmedium->u.hEnhMetaFile);
1858 break;
1860 case TYMED_NULL:
1861 default:
1862 break;
1864 pmedium->tymed=TYMED_NULL;
1867 * After cleaning up, the unknown is released
1869 if (pmedium->pUnkForRelease!=0)
1871 IUnknown_Release(pmedium->pUnkForRelease);
1872 pmedium->pUnkForRelease = 0;
1876 /***
1877 * OLEDD_Initialize()
1879 * Initializes the OLE drag and drop data structures.
1881 static void OLEDD_Initialize(void)
1883 WNDCLASSW wndClass;
1885 ZeroMemory (&wndClass, sizeof(WNDCLASSW));
1886 wndClass.style = CS_GLOBALCLASS;
1887 wndClass.lpfnWndProc = OLEDD_DragTrackerWindowProc;
1888 wndClass.cbClsExtra = 0;
1889 wndClass.cbWndExtra = sizeof(TrackerWindowInfo*);
1890 wndClass.hCursor = 0;
1891 wndClass.hbrBackground = 0;
1892 wndClass.lpszClassName = OLEDD_DRAGTRACKERCLASS;
1894 RegisterClassW (&wndClass);
1897 /***
1898 * OLEDD_FreeDropTarget()
1900 * Frees the drag and drop data structure
1902 static void OLEDD_FreeDropTarget(DropTargetNode *dropTargetInfo, BOOL release_drop_target)
1904 list_remove(&dropTargetInfo->entry);
1905 if (release_drop_target) IDropTarget_Release(dropTargetInfo->dropTarget);
1906 HeapFree(GetProcessHeap(), 0, dropTargetInfo);
1909 /***
1910 * OLEDD_UnInitialize()
1912 * Releases the OLE drag and drop data structures.
1914 void OLEDD_UnInitialize(void)
1917 * Simply empty the list.
1919 while (!list_empty(&targetListHead))
1921 DropTargetNode* curNode = LIST_ENTRY(list_head(&targetListHead), DropTargetNode, entry);
1922 OLEDD_FreeDropTarget(curNode, FALSE);
1926 /***
1927 * OLEDD_FindDropTarget()
1929 * Finds information about the drop target.
1931 static DropTargetNode* OLEDD_FindDropTarget(HWND hwndOfTarget)
1933 DropTargetNode* curNode;
1936 * Iterate the list to find the HWND value.
1938 LIST_FOR_EACH_ENTRY(curNode, &targetListHead, DropTargetNode, entry)
1939 if (hwndOfTarget==curNode->hwndTarget)
1940 return curNode;
1943 * If we get here, the item is not in the list
1945 return NULL;
1948 /***
1949 * OLEDD_DragTrackerWindowProc()
1951 * This method is the WindowProcedure of the drag n drop tracking
1952 * window. During a drag n Drop operation, an invisible window is created
1953 * to receive the user input and act upon it. This procedure is in charge
1954 * of this behavior.
1957 #define DRAG_TIMER_ID 1
1959 static LRESULT WINAPI OLEDD_DragTrackerWindowProc(
1960 HWND hwnd,
1961 UINT uMsg,
1962 WPARAM wParam,
1963 LPARAM lParam)
1965 switch (uMsg)
1967 case WM_CREATE:
1969 LPCREATESTRUCTA createStruct = (LPCREATESTRUCTA)lParam;
1971 SetWindowLongPtrW(hwnd, 0, (LONG_PTR)createStruct->lpCreateParams);
1972 SetTimer(hwnd, DRAG_TIMER_ID, 50, NULL);
1974 break;
1976 case WM_TIMER:
1977 case WM_MOUSEMOVE:
1979 OLEDD_TrackMouseMove((TrackerWindowInfo*)GetWindowLongPtrA(hwnd, 0));
1980 break;
1982 case WM_LBUTTONUP:
1983 case WM_MBUTTONUP:
1984 case WM_RBUTTONUP:
1985 case WM_LBUTTONDOWN:
1986 case WM_MBUTTONDOWN:
1987 case WM_RBUTTONDOWN:
1989 OLEDD_TrackStateChange((TrackerWindowInfo*)GetWindowLongPtrA(hwnd, 0));
1990 break;
1992 case WM_DESTROY:
1994 KillTimer(hwnd, DRAG_TIMER_ID);
1995 break;
2000 * This is a window proc after all. Let's call the default.
2002 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
2005 /***
2006 * OLEDD_TrackMouseMove()
2008 * This method is invoked while a drag and drop operation is in effect.
2009 * it will generate the appropriate callbacks in the drop source
2010 * and drop target. It will also provide the expected feedback to
2011 * the user.
2013 * params:
2014 * trackerInfo - Pointer to the structure identifying the
2015 * drag & drop operation that is currently
2016 * active.
2018 static void OLEDD_TrackMouseMove(TrackerWindowInfo* trackerInfo)
2020 HWND hwndNewTarget = 0;
2021 HRESULT hr = S_OK;
2022 POINT pt;
2025 * Get the handle of the window under the mouse
2027 pt.x = trackerInfo->curMousePos.x;
2028 pt.y = trackerInfo->curMousePos.y;
2029 hwndNewTarget = WindowFromPoint(pt);
2032 * Every time, we re-initialize the effects passed to the
2033 * IDropTarget to the effects allowed by the source.
2035 *trackerInfo->pdwEffect = trackerInfo->dwOKEffect;
2038 * If we are hovering over the same target as before, send the
2039 * DragOver notification
2041 if ( (trackerInfo->curDragTarget != 0) &&
2042 (trackerInfo->curTargetHWND == hwndNewTarget) )
2044 IDropTarget_DragOver(trackerInfo->curDragTarget,
2045 trackerInfo->dwKeyState,
2046 trackerInfo->curMousePos,
2047 trackerInfo->pdwEffect);
2049 else
2051 DropTargetNode* newDropTargetNode = 0;
2054 * If we changed window, we have to notify our old target and check for
2055 * the new one.
2057 if (trackerInfo->curDragTarget!=0)
2059 IDropTarget_DragLeave(trackerInfo->curDragTarget);
2063 * Make sure we're hovering over a window.
2065 if (hwndNewTarget!=0)
2068 * Find-out if there is a drag target under the mouse
2070 HWND nexttar = hwndNewTarget;
2071 trackerInfo->curTargetHWND = hwndNewTarget;
2073 do {
2074 newDropTargetNode = OLEDD_FindDropTarget(nexttar);
2075 } while (!newDropTargetNode && (nexttar = GetParent(nexttar)) != 0);
2076 if(nexttar) hwndNewTarget = nexttar;
2078 trackerInfo->curDragTargetHWND = hwndNewTarget;
2079 trackerInfo->curDragTarget = newDropTargetNode ? newDropTargetNode->dropTarget : 0;
2082 * If there is, notify it that we just dragged-in
2084 if (trackerInfo->curDragTarget)
2086 hr = IDropTarget_DragEnter(trackerInfo->curDragTarget,
2087 trackerInfo->dataObject,
2088 trackerInfo->dwKeyState,
2089 trackerInfo->curMousePos,
2090 trackerInfo->pdwEffect);
2092 /* failed DragEnter() means invalid target */
2093 if (hr != S_OK)
2095 trackerInfo->curDragTargetHWND = 0;
2096 trackerInfo->curTargetHWND = 0;
2097 trackerInfo->curDragTarget = 0;
2101 else
2104 * The mouse is not over a window so we don't track anything.
2106 trackerInfo->curDragTargetHWND = 0;
2107 trackerInfo->curTargetHWND = 0;
2108 trackerInfo->curDragTarget = 0;
2113 * Now that we have done that, we have to tell the source to give
2114 * us feedback on the work being done by the target. If we don't
2115 * have a target, simulate no effect.
2117 if (trackerInfo->curDragTarget==0)
2119 *trackerInfo->pdwEffect = DROPEFFECT_NONE;
2122 hr = IDropSource_GiveFeedback(trackerInfo->dropSource,
2123 *trackerInfo->pdwEffect);
2126 * When we ask for feedback from the drop source, sometimes it will
2127 * do all the necessary work and sometimes it will not handle it
2128 * when that's the case, we must display the standard drag and drop
2129 * cursors.
2131 if (hr == DRAGDROP_S_USEDEFAULTCURSORS)
2133 HCURSOR hCur;
2135 if (*trackerInfo->pdwEffect & DROPEFFECT_MOVE)
2137 hCur = LoadCursorW(hProxyDll, MAKEINTRESOURCEW(1));
2139 else if (*trackerInfo->pdwEffect & DROPEFFECT_COPY)
2141 hCur = LoadCursorW(hProxyDll, MAKEINTRESOURCEW(2));
2143 else if (*trackerInfo->pdwEffect & DROPEFFECT_LINK)
2145 hCur = LoadCursorW(hProxyDll, MAKEINTRESOURCEW(3));
2147 else
2149 hCur = LoadCursorW(hProxyDll, MAKEINTRESOURCEW(0));
2152 SetCursor(hCur);
2156 /***
2157 * OLEDD_TrackStateChange()
2159 * This method is invoked while a drag and drop operation is in effect.
2160 * It is used to notify the drop target/drop source callbacks when
2161 * the state of the keyboard or mouse button change.
2163 * params:
2164 * trackerInfo - Pointer to the structure identifying the
2165 * drag & drop operation that is currently
2166 * active.
2168 static void OLEDD_TrackStateChange(TrackerWindowInfo* trackerInfo)
2171 * Ask the drop source what to do with the operation.
2173 trackerInfo->returnValue = IDropSource_QueryContinueDrag(
2174 trackerInfo->dropSource,
2175 trackerInfo->escPressed,
2176 trackerInfo->dwKeyState);
2179 * All the return valued will stop the operation except the S_OK
2180 * return value.
2182 if (trackerInfo->returnValue!=S_OK)
2185 * Make sure the message loop in DoDragDrop stops
2187 trackerInfo->trackingDone = TRUE;
2190 * Release the mouse in case the drop target decides to show a popup
2191 * or a menu or something.
2193 ReleaseCapture();
2196 * If we end-up over a target, drop the object in the target or
2197 * inform the target that the operation was cancelled.
2199 if (trackerInfo->curDragTarget)
2201 switch (trackerInfo->returnValue)
2204 * If the source wants us to complete the operation, we tell
2205 * the drop target that we just dropped the object in it.
2207 case DRAGDROP_S_DROP:
2208 if (*trackerInfo->pdwEffect != DROPEFFECT_NONE)
2209 IDropTarget_Drop(trackerInfo->curDragTarget,
2210 trackerInfo->dataObject,
2211 trackerInfo->dwKeyState,
2212 trackerInfo->curMousePos,
2213 trackerInfo->pdwEffect);
2214 else
2215 IDropTarget_DragLeave(trackerInfo->curDragTarget);
2216 break;
2219 * If the source told us that we should cancel, fool the drop
2220 * target by telling it that the mouse left it's window.
2221 * Also set the drop effect to "NONE" in case the application
2222 * ignores the result of DoDragDrop.
2224 case DRAGDROP_S_CANCEL:
2225 IDropTarget_DragLeave(trackerInfo->curDragTarget);
2226 *trackerInfo->pdwEffect = DROPEFFECT_NONE;
2227 break;
2233 /***
2234 * OLEDD_GetButtonState()
2236 * This method will use the current state of the keyboard to build
2237 * a button state mask equivalent to the one passed in the
2238 * WM_MOUSEMOVE wParam.
2240 static DWORD OLEDD_GetButtonState(void)
2242 BYTE keyboardState[256];
2243 DWORD keyMask = 0;
2245 GetKeyboardState(keyboardState);
2247 if ( (keyboardState[VK_SHIFT] & 0x80) !=0)
2248 keyMask |= MK_SHIFT;
2250 if ( (keyboardState[VK_CONTROL] & 0x80) !=0)
2251 keyMask |= MK_CONTROL;
2253 if ( (keyboardState[VK_LBUTTON] & 0x80) !=0)
2254 keyMask |= MK_LBUTTON;
2256 if ( (keyboardState[VK_RBUTTON] & 0x80) !=0)
2257 keyMask |= MK_RBUTTON;
2259 if ( (keyboardState[VK_MBUTTON] & 0x80) !=0)
2260 keyMask |= MK_MBUTTON;
2262 return keyMask;
2265 /***
2266 * OLEDD_GetButtonState()
2268 * This method will read the default value of the registry key in
2269 * parameter and extract a DWORD value from it. The registry key value
2270 * can be in a string key or a DWORD key.
2272 * params:
2273 * regKey - Key to read the default value from
2274 * pdwValue - Pointer to the location where the DWORD
2275 * value is returned. This value is not modified
2276 * if the value is not found.
2279 static void OLEUTL_ReadRegistryDWORDValue(
2280 HKEY regKey,
2281 DWORD* pdwValue)
2283 char buffer[20];
2284 DWORD cbData = sizeof(buffer);
2285 DWORD dwKeyType;
2286 LONG lres;
2288 lres = RegQueryValueExA(regKey,
2290 NULL,
2291 &dwKeyType,
2292 (LPBYTE)buffer,
2293 &cbData);
2295 if (lres==ERROR_SUCCESS)
2297 switch (dwKeyType)
2299 case REG_DWORD:
2300 *pdwValue = *(DWORD*)buffer;
2301 break;
2302 case REG_EXPAND_SZ:
2303 case REG_MULTI_SZ:
2304 case REG_SZ:
2305 *pdwValue = (DWORD)strtoul(buffer, NULL, 10);
2306 break;
2311 /******************************************************************************
2312 * OleDraw (OLE32.@)
2314 * The operation of this function is documented literally in the WinAPI
2315 * documentation to involve a QueryInterface for the IViewObject interface,
2316 * followed by a call to IViewObject::Draw.
2318 HRESULT WINAPI OleDraw(
2319 IUnknown *pUnk,
2320 DWORD dwAspect,
2321 HDC hdcDraw,
2322 LPCRECT lprcBounds)
2324 HRESULT hres;
2325 IViewObject *viewobject;
2327 hres = IUnknown_QueryInterface(pUnk,
2328 &IID_IViewObject,
2329 (void**)&viewobject);
2331 if (SUCCEEDED(hres))
2333 RECTL rectl;
2335 rectl.left = lprcBounds->left;
2336 rectl.right = lprcBounds->right;
2337 rectl.top = lprcBounds->top;
2338 rectl.bottom = lprcBounds->bottom;
2339 hres = IViewObject_Draw(viewobject, dwAspect, -1, 0, 0, 0, hdcDraw, &rectl, 0, 0, 0);
2341 IViewObject_Release(viewobject);
2342 return hres;
2344 else
2346 return DV_E_NOIVIEWOBJECT;
2350 /***********************************************************************
2351 * OleTranslateAccelerator [OLE32.@]
2353 HRESULT WINAPI OleTranslateAccelerator (LPOLEINPLACEFRAME lpFrame,
2354 LPOLEINPLACEFRAMEINFO lpFrameInfo, LPMSG lpmsg)
2356 WORD wID;
2358 TRACE("(%p,%p,%p)\n", lpFrame, lpFrameInfo, lpmsg);
2360 if (IsAccelerator(lpFrameInfo->haccel,lpFrameInfo->cAccelEntries,lpmsg,&wID))
2361 return IOleInPlaceFrame_TranslateAccelerator(lpFrame,lpmsg,wID);
2363 return S_FALSE;
2366 /******************************************************************************
2367 * OleCreate [OLE32.@]
2370 HRESULT WINAPI OleCreate(
2371 REFCLSID rclsid,
2372 REFIID riid,
2373 DWORD renderopt,
2374 LPFORMATETC pFormatEtc,
2375 LPOLECLIENTSITE pClientSite,
2376 LPSTORAGE pStg,
2377 LPVOID* ppvObj)
2379 HRESULT hres;
2380 IUnknown * pUnk = NULL;
2381 IOleObject *pOleObject = NULL;
2383 TRACE("(%s, %s, %d, %p, %p, %p, %p)\n", debugstr_guid(rclsid),
2384 debugstr_guid(riid), renderopt, pFormatEtc, pClientSite, pStg, ppvObj);
2386 hres = CoCreateInstance(rclsid, 0, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER, riid, (LPVOID*)&pUnk);
2388 if (SUCCEEDED(hres))
2389 hres = IStorage_SetClass(pStg, rclsid);
2391 if (pClientSite && SUCCEEDED(hres))
2393 hres = IUnknown_QueryInterface(pUnk, &IID_IOleObject, (LPVOID*)&pOleObject);
2394 if (SUCCEEDED(hres))
2396 DWORD dwStatus;
2397 hres = IOleObject_GetMiscStatus(pOleObject, DVASPECT_CONTENT, &dwStatus);
2401 if (SUCCEEDED(hres))
2403 IPersistStorage * pPS;
2404 if (SUCCEEDED((hres = IUnknown_QueryInterface(pUnk, &IID_IPersistStorage, (LPVOID*)&pPS))))
2406 TRACE("trying to set stg %p\n", pStg);
2407 hres = IPersistStorage_InitNew(pPS, pStg);
2408 TRACE("-- result 0x%08x\n", hres);
2409 IPersistStorage_Release(pPS);
2413 if (pClientSite && SUCCEEDED(hres))
2415 TRACE("trying to set clientsite %p\n", pClientSite);
2416 hres = IOleObject_SetClientSite(pOleObject, pClientSite);
2417 TRACE("-- result 0x%08x\n", hres);
2420 if (pOleObject)
2421 IOleObject_Release(pOleObject);
2423 if (((renderopt == OLERENDER_DRAW) || (renderopt == OLERENDER_FORMAT)) &&
2424 SUCCEEDED(hres))
2426 IRunnableObject *pRunnable;
2427 IOleCache *pOleCache;
2428 HRESULT hres2;
2430 hres2 = IUnknown_QueryInterface(pUnk, &IID_IRunnableObject, (void **)&pRunnable);
2431 if (SUCCEEDED(hres2))
2433 hres = IRunnableObject_Run(pRunnable, NULL);
2434 IRunnableObject_Release(pRunnable);
2437 if (SUCCEEDED(hres))
2439 hres2 = IUnknown_QueryInterface(pUnk, &IID_IOleCache, (void **)&pOleCache);
2440 if (SUCCEEDED(hres2))
2442 DWORD dwConnection;
2443 hres = IOleCache_Cache(pOleCache, pFormatEtc, ADVF_PRIMEFIRST, &dwConnection);
2444 IOleCache_Release(pOleCache);
2449 if (FAILED(hres) && pUnk)
2451 IUnknown_Release(pUnk);
2452 pUnk = NULL;
2455 *ppvObj = pUnk;
2457 TRACE("-- %p\n", pUnk);
2458 return hres;
2461 /******************************************************************************
2462 * OleGetAutoConvert [OLE32.@]
2464 HRESULT WINAPI OleGetAutoConvert(REFCLSID clsidOld, LPCLSID pClsidNew)
2466 static const WCHAR wszAutoConvertTo[] = {'A','u','t','o','C','o','n','v','e','r','t','T','o',0};
2467 HKEY hkey = NULL;
2468 WCHAR buf[CHARS_IN_GUID];
2469 LONG len;
2470 HRESULT res = S_OK;
2472 res = COM_OpenKeyForCLSID(clsidOld, wszAutoConvertTo, KEY_READ, &hkey);
2473 if (FAILED(res))
2474 goto done;
2476 len = sizeof(buf);
2477 if (RegQueryValueW(hkey, NULL, buf, &len))
2479 res = REGDB_E_KEYMISSING;
2480 goto done;
2482 res = CLSIDFromString(buf, pClsidNew);
2483 done:
2484 if (hkey) RegCloseKey(hkey);
2485 return res;
2488 /******************************************************************************
2489 * OleSetAutoConvert [OLE32.@]
2491 HRESULT WINAPI OleSetAutoConvert(REFCLSID clsidOld, REFCLSID clsidNew)
2493 static const WCHAR wszAutoConvertTo[] = {'A','u','t','o','C','o','n','v','e','r','t','T','o',0};
2494 HKEY hkey = NULL;
2495 WCHAR szClsidNew[CHARS_IN_GUID];
2496 HRESULT res = S_OK;
2498 TRACE("(%s,%s)\n", debugstr_guid(clsidOld), debugstr_guid(clsidNew));
2500 res = COM_OpenKeyForCLSID(clsidOld, NULL, KEY_READ | KEY_WRITE, &hkey);
2501 if (FAILED(res))
2502 goto done;
2503 StringFromGUID2(clsidNew, szClsidNew, CHARS_IN_GUID);
2504 if (RegSetValueW(hkey, wszAutoConvertTo, REG_SZ, szClsidNew, (strlenW(szClsidNew)+1) * sizeof(WCHAR)))
2506 res = REGDB_E_WRITEREGDB;
2507 goto done;
2510 done:
2511 if (hkey) RegCloseKey(hkey);
2512 return res;
2515 /******************************************************************************
2516 * OleDoAutoConvert [OLE32.@]
2518 HRESULT WINAPI OleDoAutoConvert(LPSTORAGE pStg, LPCLSID pClsidNew)
2520 FIXME("(%p,%p) : stub\n",pStg,pClsidNew);
2521 return E_NOTIMPL;
2524 /******************************************************************************
2525 * OleIsRunning [OLE32.@]
2527 BOOL WINAPI OleIsRunning(LPOLEOBJECT pObject)
2529 IRunnableObject *pRunnable;
2530 HRESULT hr;
2531 BOOL running;
2533 TRACE("(%p)\n", pObject);
2535 hr = IOleObject_QueryInterface(pObject, &IID_IRunnableObject, (void **)&pRunnable);
2536 if (FAILED(hr))
2537 return TRUE;
2538 running = IRunnableObject_IsRunning(pRunnable);
2539 IRunnableObject_Release(pRunnable);
2540 return running;
2543 /***********************************************************************
2544 * OleNoteObjectVisible [OLE32.@]
2546 HRESULT WINAPI OleNoteObjectVisible(LPUNKNOWN pUnknown, BOOL bVisible)
2548 TRACE("(%p, %s)\n", pUnknown, bVisible ? "TRUE" : "FALSE");
2549 return CoLockObjectExternal(pUnknown, bVisible, TRUE);
2553 /***********************************************************************
2554 * OLE_FreeClipDataArray [internal]
2556 * NOTES:
2557 * frees the data associated with an array of CLIPDATAs
2559 static void OLE_FreeClipDataArray(ULONG count, CLIPDATA * pClipDataArray)
2561 ULONG i;
2562 for (i = 0; i < count; i++)
2563 if (pClipDataArray[i].pClipData)
2564 CoTaskMemFree(pClipDataArray[i].pClipData);
2567 /***********************************************************************
2568 * PropSysAllocString [OLE32.@]
2569 * NOTES:
2570 * Basically a copy of SysAllocStringLen.
2572 BSTR WINAPI PropSysAllocString(LPCOLESTR str)
2574 DWORD bufferSize;
2575 DWORD* newBuffer;
2576 WCHAR* stringBuffer;
2577 int len;
2579 if (!str) return 0;
2581 len = lstrlenW(str);
2583 * Find the length of the buffer passed-in, in bytes.
2585 bufferSize = len * sizeof (WCHAR);
2588 * Allocate a new buffer to hold the string.
2589 * Don't forget to keep an empty spot at the beginning of the
2590 * buffer for the character count and an extra character at the
2591 * end for the NULL.
2593 newBuffer = HeapAlloc(GetProcessHeap(), 0,
2594 bufferSize + sizeof(WCHAR) + sizeof(DWORD));
2597 * If the memory allocation failed, return a null pointer.
2599 if (newBuffer==0)
2600 return 0;
2603 * Copy the length of the string in the placeholder.
2605 *newBuffer = bufferSize;
2608 * Skip the byte count.
2610 newBuffer++;
2612 memcpy(newBuffer, str, bufferSize);
2615 * Make sure that there is a nul character at the end of the
2616 * string.
2618 stringBuffer = (WCHAR*)newBuffer;
2619 stringBuffer[len] = '\0';
2621 return stringBuffer;
2624 /***********************************************************************
2625 * PropSysFreeString [OLE32.@]
2626 * NOTES
2627 * Copy of SysFreeString.
2629 void WINAPI PropSysFreeString(LPOLESTR str)
2631 DWORD* bufferPointer;
2633 /* NULL is a valid parameter */
2634 if(!str) return;
2637 * We have to be careful when we free a BSTR pointer, it points to
2638 * the beginning of the string but it skips the byte count contained
2639 * before the string.
2641 bufferPointer = (DWORD*)str;
2643 bufferPointer--;
2646 * Free the memory from its "real" origin.
2648 HeapFree(GetProcessHeap(), 0, bufferPointer);
2651 /******************************************************************************
2652 * Check if a PROPVARIANT's type is valid.
2654 static inline HRESULT PROPVARIANT_ValidateType(VARTYPE vt)
2656 switch (vt)
2658 case VT_EMPTY:
2659 case VT_NULL:
2660 case VT_I2:
2661 case VT_I4:
2662 case VT_R4:
2663 case VT_R8:
2664 case VT_CY:
2665 case VT_DATE:
2666 case VT_BSTR:
2667 case VT_ERROR:
2668 case VT_BOOL:
2669 case VT_DECIMAL:
2670 case VT_UI1:
2671 case VT_UI2:
2672 case VT_UI4:
2673 case VT_I8:
2674 case VT_UI8:
2675 case VT_LPSTR:
2676 case VT_LPWSTR:
2677 case VT_FILETIME:
2678 case VT_BLOB:
2679 case VT_STREAM:
2680 case VT_STORAGE:
2681 case VT_STREAMED_OBJECT:
2682 case VT_STORED_OBJECT:
2683 case VT_BLOB_OBJECT:
2684 case VT_CF:
2685 case VT_CLSID:
2686 case VT_I2|VT_VECTOR:
2687 case VT_I4|VT_VECTOR:
2688 case VT_R4|VT_VECTOR:
2689 case VT_R8|VT_VECTOR:
2690 case VT_CY|VT_VECTOR:
2691 case VT_DATE|VT_VECTOR:
2692 case VT_BSTR|VT_VECTOR:
2693 case VT_ERROR|VT_VECTOR:
2694 case VT_BOOL|VT_VECTOR:
2695 case VT_VARIANT|VT_VECTOR:
2696 case VT_UI1|VT_VECTOR:
2697 case VT_UI2|VT_VECTOR:
2698 case VT_UI4|VT_VECTOR:
2699 case VT_I8|VT_VECTOR:
2700 case VT_UI8|VT_VECTOR:
2701 case VT_LPSTR|VT_VECTOR:
2702 case VT_LPWSTR|VT_VECTOR:
2703 case VT_FILETIME|VT_VECTOR:
2704 case VT_CF|VT_VECTOR:
2705 case VT_CLSID|VT_VECTOR:
2706 return S_OK;
2708 WARN("Bad type %d\n", vt);
2709 return STG_E_INVALIDPARAMETER;
2712 /***********************************************************************
2713 * PropVariantClear [OLE32.@]
2715 HRESULT WINAPI PropVariantClear(PROPVARIANT * pvar) /* [in/out] */
2717 HRESULT hr;
2719 TRACE("(%p)\n", pvar);
2721 if (!pvar)
2722 return S_OK;
2724 hr = PROPVARIANT_ValidateType(pvar->vt);
2725 if (FAILED(hr))
2726 return hr;
2728 switch(pvar->vt)
2730 case VT_EMPTY:
2731 case VT_NULL:
2732 case VT_I2:
2733 case VT_I4:
2734 case VT_R4:
2735 case VT_R8:
2736 case VT_CY:
2737 case VT_DATE:
2738 case VT_ERROR:
2739 case VT_BOOL:
2740 case VT_DECIMAL:
2741 case VT_UI1:
2742 case VT_UI2:
2743 case VT_UI4:
2744 case VT_I8:
2745 case VT_UI8:
2746 case VT_FILETIME:
2747 break;
2748 case VT_STREAM:
2749 case VT_STREAMED_OBJECT:
2750 case VT_STORAGE:
2751 case VT_STORED_OBJECT:
2752 if (pvar->u.pStream)
2753 IUnknown_Release(pvar->u.pStream);
2754 break;
2755 case VT_CLSID:
2756 case VT_LPSTR:
2757 case VT_LPWSTR:
2758 /* pick an arbitrary typed pointer - we don't care about the type
2759 * as we are just freeing it */
2760 CoTaskMemFree(pvar->u.puuid);
2761 break;
2762 case VT_BLOB:
2763 case VT_BLOB_OBJECT:
2764 CoTaskMemFree(pvar->u.blob.pBlobData);
2765 break;
2766 case VT_BSTR:
2767 if (pvar->u.bstrVal)
2768 PropSysFreeString(pvar->u.bstrVal);
2769 break;
2770 case VT_CF:
2771 if (pvar->u.pclipdata)
2773 OLE_FreeClipDataArray(1, pvar->u.pclipdata);
2774 CoTaskMemFree(pvar->u.pclipdata);
2776 break;
2777 default:
2778 if (pvar->vt & VT_VECTOR)
2780 ULONG i;
2782 switch (pvar->vt & ~VT_VECTOR)
2784 case VT_VARIANT:
2785 FreePropVariantArray(pvar->u.capropvar.cElems, pvar->u.capropvar.pElems);
2786 break;
2787 case VT_CF:
2788 OLE_FreeClipDataArray(pvar->u.caclipdata.cElems, pvar->u.caclipdata.pElems);
2789 break;
2790 case VT_BSTR:
2791 for (i = 0; i < pvar->u.cabstr.cElems; i++)
2792 PropSysFreeString(pvar->u.cabstr.pElems[i]);
2793 break;
2794 case VT_LPSTR:
2795 for (i = 0; i < pvar->u.calpstr.cElems; i++)
2796 CoTaskMemFree(pvar->u.calpstr.pElems[i]);
2797 break;
2798 case VT_LPWSTR:
2799 for (i = 0; i < pvar->u.calpwstr.cElems; i++)
2800 CoTaskMemFree(pvar->u.calpwstr.pElems[i]);
2801 break;
2803 if (pvar->vt & ~VT_VECTOR)
2805 /* pick an arbitrary VT_VECTOR structure - they all have the same
2806 * memory layout */
2807 CoTaskMemFree(pvar->u.capropvar.pElems);
2810 else
2811 WARN("Invalid/unsupported type %d\n", pvar->vt);
2814 ZeroMemory(pvar, sizeof(*pvar));
2816 return S_OK;
2819 /***********************************************************************
2820 * PropVariantCopy [OLE32.@]
2822 HRESULT WINAPI PropVariantCopy(PROPVARIANT *pvarDest, /* [out] */
2823 const PROPVARIANT *pvarSrc) /* [in] */
2825 ULONG len;
2826 HRESULT hr;
2828 TRACE("(%p, %p vt %04x)\n", pvarDest, pvarSrc, pvarSrc->vt);
2830 hr = PROPVARIANT_ValidateType(pvarSrc->vt);
2831 if (FAILED(hr))
2832 return hr;
2834 /* this will deal with most cases */
2835 *pvarDest = *pvarSrc;
2837 switch(pvarSrc->vt)
2839 case VT_EMPTY:
2840 case VT_NULL:
2841 case VT_I1:
2842 case VT_UI1:
2843 case VT_I2:
2844 case VT_UI2:
2845 case VT_BOOL:
2846 case VT_DECIMAL:
2847 case VT_I4:
2848 case VT_UI4:
2849 case VT_R4:
2850 case VT_ERROR:
2851 case VT_I8:
2852 case VT_UI8:
2853 case VT_R8:
2854 case VT_CY:
2855 case VT_DATE:
2856 case VT_FILETIME:
2857 break;
2858 case VT_STREAM:
2859 case VT_STREAMED_OBJECT:
2860 case VT_STORAGE:
2861 case VT_STORED_OBJECT:
2862 IUnknown_AddRef((LPUNKNOWN)pvarDest->u.pStream);
2863 break;
2864 case VT_CLSID:
2865 pvarDest->u.puuid = CoTaskMemAlloc(sizeof(CLSID));
2866 *pvarDest->u.puuid = *pvarSrc->u.puuid;
2867 break;
2868 case VT_LPSTR:
2869 len = strlen(pvarSrc->u.pszVal);
2870 pvarDest->u.pszVal = CoTaskMemAlloc((len+1)*sizeof(CHAR));
2871 CopyMemory(pvarDest->u.pszVal, pvarSrc->u.pszVal, (len+1)*sizeof(CHAR));
2872 break;
2873 case VT_LPWSTR:
2874 len = lstrlenW(pvarSrc->u.pwszVal);
2875 pvarDest->u.pwszVal = CoTaskMemAlloc((len+1)*sizeof(WCHAR));
2876 CopyMemory(pvarDest->u.pwszVal, pvarSrc->u.pwszVal, (len+1)*sizeof(WCHAR));
2877 break;
2878 case VT_BLOB:
2879 case VT_BLOB_OBJECT:
2880 if (pvarSrc->u.blob.pBlobData)
2882 len = pvarSrc->u.blob.cbSize;
2883 pvarDest->u.blob.pBlobData = CoTaskMemAlloc(len);
2884 CopyMemory(pvarDest->u.blob.pBlobData, pvarSrc->u.blob.pBlobData, len);
2886 break;
2887 case VT_BSTR:
2888 pvarDest->u.bstrVal = PropSysAllocString(pvarSrc->u.bstrVal);
2889 break;
2890 case VT_CF:
2891 if (pvarSrc->u.pclipdata)
2893 len = pvarSrc->u.pclipdata->cbSize - sizeof(pvarSrc->u.pclipdata->ulClipFmt);
2894 pvarDest->u.pclipdata = CoTaskMemAlloc(sizeof (CLIPDATA));
2895 pvarDest->u.pclipdata->cbSize = pvarSrc->u.pclipdata->cbSize;
2896 pvarDest->u.pclipdata->ulClipFmt = pvarSrc->u.pclipdata->ulClipFmt;
2897 pvarDest->u.pclipdata->pClipData = CoTaskMemAlloc(len);
2898 CopyMemory(pvarDest->u.pclipdata->pClipData, pvarSrc->u.pclipdata->pClipData, len);
2900 break;
2901 default:
2902 if (pvarSrc->vt & VT_VECTOR)
2904 int elemSize;
2905 ULONG i;
2907 switch(pvarSrc->vt & ~VT_VECTOR)
2909 case VT_I1: elemSize = sizeof(pvarSrc->u.cVal); break;
2910 case VT_UI1: elemSize = sizeof(pvarSrc->u.bVal); break;
2911 case VT_I2: elemSize = sizeof(pvarSrc->u.iVal); break;
2912 case VT_UI2: elemSize = sizeof(pvarSrc->u.uiVal); break;
2913 case VT_BOOL: elemSize = sizeof(pvarSrc->u.boolVal); break;
2914 case VT_I4: elemSize = sizeof(pvarSrc->u.lVal); break;
2915 case VT_UI4: elemSize = sizeof(pvarSrc->u.ulVal); break;
2916 case VT_R4: elemSize = sizeof(pvarSrc->u.fltVal); break;
2917 case VT_R8: elemSize = sizeof(pvarSrc->u.dblVal); break;
2918 case VT_ERROR: elemSize = sizeof(pvarSrc->u.scode); break;
2919 case VT_I8: elemSize = sizeof(pvarSrc->u.hVal); break;
2920 case VT_UI8: elemSize = sizeof(pvarSrc->u.uhVal); break;
2921 case VT_CY: elemSize = sizeof(pvarSrc->u.cyVal); break;
2922 case VT_DATE: elemSize = sizeof(pvarSrc->u.date); break;
2923 case VT_FILETIME: elemSize = sizeof(pvarSrc->u.filetime); break;
2924 case VT_CLSID: elemSize = sizeof(*pvarSrc->u.puuid); break;
2925 case VT_CF: elemSize = sizeof(*pvarSrc->u.pclipdata); break;
2926 case VT_BSTR: elemSize = sizeof(pvarSrc->u.bstrVal); break;
2927 case VT_LPSTR: elemSize = sizeof(pvarSrc->u.pszVal); break;
2928 case VT_LPWSTR: elemSize = sizeof(pvarSrc->u.pwszVal); break;
2929 case VT_VARIANT: elemSize = sizeof(*pvarSrc->u.pvarVal); break;
2931 default:
2932 FIXME("Invalid element type: %ul\n", pvarSrc->vt & ~VT_VECTOR);
2933 return E_INVALIDARG;
2935 len = pvarSrc->u.capropvar.cElems;
2936 pvarDest->u.capropvar.pElems = CoTaskMemAlloc(len * elemSize);
2937 if (pvarSrc->vt == (VT_VECTOR | VT_VARIANT))
2939 for (i = 0; i < len; i++)
2940 PropVariantCopy(&pvarDest->u.capropvar.pElems[i], &pvarSrc->u.capropvar.pElems[i]);
2942 else if (pvarSrc->vt == (VT_VECTOR | VT_CF))
2944 FIXME("Copy clipformats\n");
2946 else if (pvarSrc->vt == (VT_VECTOR | VT_BSTR))
2948 for (i = 0; i < len; i++)
2949 pvarDest->u.cabstr.pElems[i] = PropSysAllocString(pvarSrc->u.cabstr.pElems[i]);
2951 else if (pvarSrc->vt == (VT_VECTOR | VT_LPSTR))
2953 size_t strLen;
2954 for (i = 0; i < len; i++)
2956 strLen = lstrlenA(pvarSrc->u.calpstr.pElems[i]) + 1;
2957 pvarDest->u.calpstr.pElems[i] = CoTaskMemAlloc(strLen);
2958 memcpy(pvarDest->u.calpstr.pElems[i],
2959 pvarSrc->u.calpstr.pElems[i], strLen);
2962 else if (pvarSrc->vt == (VT_VECTOR | VT_LPWSTR))
2964 size_t strLen;
2965 for (i = 0; i < len; i++)
2967 strLen = (lstrlenW(pvarSrc->u.calpwstr.pElems[i]) + 1) *
2968 sizeof(WCHAR);
2969 pvarDest->u.calpstr.pElems[i] = CoTaskMemAlloc(strLen);
2970 memcpy(pvarDest->u.calpstr.pElems[i],
2971 pvarSrc->u.calpstr.pElems[i], strLen);
2974 else
2975 CopyMemory(pvarDest->u.capropvar.pElems, pvarSrc->u.capropvar.pElems, len * elemSize);
2977 else
2978 WARN("Invalid/unsupported type %d\n", pvarSrc->vt);
2981 return S_OK;
2984 /***********************************************************************
2985 * FreePropVariantArray [OLE32.@]
2987 HRESULT WINAPI FreePropVariantArray(ULONG cVariants, /* [in] */
2988 PROPVARIANT *rgvars) /* [in/out] */
2990 ULONG i;
2992 TRACE("(%u, %p)\n", cVariants, rgvars);
2994 if (!rgvars)
2995 return E_INVALIDARG;
2997 for(i = 0; i < cVariants; i++)
2998 PropVariantClear(&rgvars[i]);
3000 return S_OK;
3003 /******************************************************************************
3004 * DllDebugObjectRPCHook (OLE32.@)
3005 * turns on and off internal debugging, pointer is only used on macintosh
3008 BOOL WINAPI DllDebugObjectRPCHook(BOOL b, void *dummy)
3010 FIXME("stub\n");
3011 return TRUE;