4 * Copyright 1995 Martin von Loewis
5 * Copyright 1999 Francis Beaudet
6 * Copyright 1999 Noel Borthwick
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
32 #define NONAMELESSUNION
33 #define NONAMELESSSTRUCT
47 #include "wine/winbase16.h"
48 #include "wine/wingdi16.h"
49 #include "wine/winuser16.h"
50 #include "ole32_main.h"
52 #include "wine/debug.h"
54 WINE_DEFAULT_DEBUG_CHANNEL(ole);
55 WINE_DECLARE_DEBUG_CHANNEL(accel);
57 #define HICON_16(h32) (LOWORD(h32))
58 #define HICON_32(h16) ((HICON)(ULONG_PTR)(h16))
59 #define HINSTANCE_32(h16) ((HINSTANCE)(ULONG_PTR)(h16))
61 /******************************************************************************
62 * These are static/global variables and internal data structures that the
63 * OLE module uses to maintain it's state.
65 typedef struct tagDropTargetNode
68 IDropTarget* dropTarget;
69 struct tagDropTargetNode* prevDropTarget;
70 struct tagDropTargetNode* nextDropTarget;
73 typedef struct tagTrackerWindowInfo
75 IDataObject* dataObject;
76 IDropSource* dropSource;
83 HWND curTargetHWND; /* window the mouse is hovering over */
84 HWND curDragTargetHWND; /* might be a ancestor of curTargetHWND */
85 IDropTarget* curDragTarget;
88 typedef struct tagOleMenuDescriptor /* OleMenuDescriptor */
90 HWND hwndFrame; /* The containers frame window */
91 HWND hwndActiveObject; /* The active objects window */
92 OLEMENUGROUPWIDTHS mgw; /* OLE menu group widths for the shared menu */
93 HMENU hmenuCombined; /* The combined menu */
94 BOOL bIsServerItem; /* True if the currently open popup belongs to the server */
97 typedef struct tagOleMenuHookItem /* OleMenu hook item in per thread hook list */
99 DWORD tid; /* Thread Id */
100 HANDLE hHeap; /* Heap this is allocated from */
101 HHOOK GetMsg_hHook; /* message hook for WH_GETMESSAGE */
102 HHOOK CallWndProc_hHook; /* message hook for WH_CALLWNDPROC */
103 struct tagOleMenuHookItem *next;
106 static OleMenuHookItem *hook_list;
109 * This is the lock count on the OLE library. It is controlled by the
110 * OLEInitialize/OLEUninitialize methods.
112 static ULONG OLE_moduleLockCount = 0;
115 * Name of our registered window class.
117 static const char OLEDD_DRAGTRACKERCLASS[] = "WineDragDropTracker32";
120 * This is the head of the Drop target container.
122 static DropTargetNode* targetListHead = NULL;
124 /******************************************************************************
125 * These are the prototypes of miscelaneous utility methods
127 static void OLEUTL_ReadRegistryDWORDValue(HKEY regKey, DWORD* pdwValue);
129 /******************************************************************************
130 * These are the prototypes of the utility methods used to manage a shared menu
132 static void OLEMenu_Initialize();
133 static void OLEMenu_UnInitialize();
134 BOOL OLEMenu_InstallHooks( DWORD tid );
135 BOOL OLEMenu_UnInstallHooks( DWORD tid );
136 OleMenuHookItem * OLEMenu_IsHookInstalled( DWORD tid );
137 static BOOL OLEMenu_FindMainMenuIndex( HMENU hMainMenu, HMENU hPopupMenu, UINT *pnPos );
138 BOOL OLEMenu_SetIsServerMenu( HMENU hmenu, OleMenuDescriptor *pOleMenuDescriptor );
139 LRESULT CALLBACK OLEMenu_CallWndProc(INT code, WPARAM wParam, LPARAM lParam);
140 LRESULT CALLBACK OLEMenu_GetMsgProc(INT code, WPARAM wParam, LPARAM lParam);
142 /******************************************************************************
143 * These are the prototypes of the OLE Clipboard initialization methods (in clipboard.c)
145 void OLEClipbrd_UnInitialize();
146 void OLEClipbrd_Initialize();
148 /******************************************************************************
149 * These are the prototypes of the utility methods used for OLE Drag n Drop
151 static void OLEDD_Initialize();
152 static void OLEDD_UnInitialize();
153 static void OLEDD_InsertDropTarget(
154 DropTargetNode* nodeToAdd);
155 static DropTargetNode* OLEDD_ExtractDropTarget(
157 static DropTargetNode* OLEDD_FindDropTarget(
159 static LRESULT WINAPI OLEDD_DragTrackerWindowProc(
164 static void OLEDD_TrackMouseMove(
165 TrackerWindowInfo* trackerInfo,
168 static void OLEDD_TrackStateChange(
169 TrackerWindowInfo* trackerInfo,
172 static DWORD OLEDD_GetButtonState();
175 /******************************************************************************
176 * OleBuildVersion [OLE2.1]
177 * OleBuildVersion [OLE32.@]
179 DWORD WINAPI OleBuildVersion(void)
181 TRACE("Returning version %d, build %d.\n", rmm, rup);
182 return (rmm<<16)+rup;
185 /***********************************************************************
186 * OleInitialize (OLE2.2)
187 * OleInitialize (OLE32.@)
189 HRESULT WINAPI OleInitialize(LPVOID reserved)
193 TRACE("(%p)\n", reserved);
196 * The first duty of the OleInitialize is to initialize the COM libraries.
198 hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
201 * If the CoInitializeEx call failed, the OLE libraries can't be
208 * Then, it has to initialize the OLE specific modules.
212 * Object linking and Embedding
213 * In-place activation
215 if (OLE_moduleLockCount==0)
218 * Initialize the libraries.
220 TRACE("() - Initializing the OLE libraries\n");
225 OLEClipbrd_Initialize();
235 OLEMenu_Initialize();
239 * Then, we increase the lock count on the OLE module.
241 OLE_moduleLockCount++;
246 /******************************************************************************
247 * CoGetCurrentProcess [COMPOBJ.34]
248 * CoGetCurrentProcess [OLE32.@]
251 * Is DWORD really the correct return type for this function?
253 DWORD WINAPI CoGetCurrentProcess(void)
255 return GetCurrentProcessId();
258 /******************************************************************************
259 * OleUninitialize [OLE2.3]
260 * OleUninitialize [OLE32.@]
262 void WINAPI OleUninitialize(void)
267 * Decrease the lock count on the OLE module.
269 OLE_moduleLockCount--;
272 * If we hit the bottom of the lock stack, free the libraries.
274 if (OLE_moduleLockCount==0)
277 * Actually free the libraries.
279 TRACE("() - Freeing the last reference count\n");
284 OLEClipbrd_UnInitialize();
289 OLEDD_UnInitialize();
294 OLEMenu_UnInitialize();
298 * Then, uninitialize the COM libraries.
303 /******************************************************************************
304 * CoRegisterMessageFilter [OLE32.@]
306 HRESULT WINAPI CoRegisterMessageFilter(
307 LPMESSAGEFILTER lpMessageFilter, /* [in] Pointer to interface */
308 LPMESSAGEFILTER *lplpMessageFilter /* [out] Indirect pointer to prior instance if non-NULL */
311 if (lplpMessageFilter) {
312 *lplpMessageFilter = NULL;
317 /******************************************************************************
318 * OleInitializeWOW [OLE32.@]
320 HRESULT WINAPI OleInitializeWOW(DWORD x) {
321 FIXME("(0x%08lx),stub!\n",x);
325 /***********************************************************************
326 * RegisterDragDrop (OLE32.@)
328 HRESULT WINAPI RegisterDragDrop(
330 LPDROPTARGET pDropTarget)
332 DropTargetNode* dropTargetInfo;
334 TRACE("(%p,%p)\n", hwnd, pDropTarget);
340 * First, check if the window is already registered.
342 dropTargetInfo = OLEDD_FindDropTarget(hwnd);
344 if (dropTargetInfo!=NULL)
345 return DRAGDROP_E_ALREADYREGISTERED;
348 * If it's not there, we can add it. We first create a node for it.
350 dropTargetInfo = HeapAlloc(GetProcessHeap(), 0, sizeof(DropTargetNode));
352 if (dropTargetInfo==NULL)
353 return E_OUTOFMEMORY;
355 dropTargetInfo->hwndTarget = hwnd;
356 dropTargetInfo->prevDropTarget = NULL;
357 dropTargetInfo->nextDropTarget = NULL;
360 * Don't forget that this is an interface pointer, need to nail it down since
361 * we keep a copy of it.
363 dropTargetInfo->dropTarget = pDropTarget;
364 IDropTarget_AddRef(dropTargetInfo->dropTarget);
366 OLEDD_InsertDropTarget(dropTargetInfo);
371 /***********************************************************************
372 * RevokeDragDrop (OLE32.@)
374 HRESULT WINAPI RevokeDragDrop(
377 DropTargetNode* dropTargetInfo;
379 TRACE("(%p)\n", hwnd);
382 * First, check if the window is already registered.
384 dropTargetInfo = OLEDD_ExtractDropTarget(hwnd);
387 * If it ain't in there, it's an error.
389 if (dropTargetInfo==NULL)
390 return DRAGDROP_E_NOTREGISTERED;
393 * If it's in there, clean-up it's used memory and
396 IDropTarget_Release(dropTargetInfo->dropTarget);
397 HeapFree(GetProcessHeap(), 0, dropTargetInfo);
402 /***********************************************************************
403 * OleRegGetUserType (OLE32.@)
405 * This implementation of OleRegGetUserType ignores the dwFormOfType
406 * parameter and always returns the full name of the object. This is
407 * not too bad since this is the case for many objects because of the
408 * way they are registered.
410 HRESULT WINAPI OleRegGetUserType(
413 LPOLESTR* pszUserType)
423 * Initialize the out parameter.
428 * Build the key name we're looking for
430 sprintf( keyName, "CLSID\\{%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}\\",
431 clsid->Data1, clsid->Data2, clsid->Data3,
432 clsid->Data4[0], clsid->Data4[1], clsid->Data4[2], clsid->Data4[3],
433 clsid->Data4[4], clsid->Data4[5], clsid->Data4[6], clsid->Data4[7] );
435 TRACE("(%s, %ld, %p)\n", keyName, dwFormOfType, pszUserType);
438 * Open the class id Key
440 hres = RegOpenKeyA(HKEY_CLASSES_ROOT,
444 if (hres != ERROR_SUCCESS)
445 return REGDB_E_CLASSNOTREG;
448 * Retrieve the size of the name string.
452 hres = RegQueryValueExA(clsidKey,
459 if (hres!=ERROR_SUCCESS)
461 RegCloseKey(clsidKey);
462 return REGDB_E_READREGDB;
466 * Allocate a buffer for the registry value.
468 *pszUserType = CoTaskMemAlloc(cbData*2);
470 if (*pszUserType==NULL)
472 RegCloseKey(clsidKey);
473 return E_OUTOFMEMORY;
476 buffer = HeapAlloc(GetProcessHeap(), 0, cbData);
480 RegCloseKey(clsidKey);
481 CoTaskMemFree(*pszUserType);
483 return E_OUTOFMEMORY;
486 hres = RegQueryValueExA(clsidKey,
493 RegCloseKey(clsidKey);
496 if (hres!=ERROR_SUCCESS)
498 CoTaskMemFree(*pszUserType);
501 retVal = REGDB_E_READREGDB;
505 MultiByteToWideChar( CP_ACP, 0, buffer, -1, *pszUserType, cbData /*FIXME*/ );
508 HeapFree(GetProcessHeap(), 0, buffer);
513 /***********************************************************************
514 * DoDragDrop [OLE32.@]
516 HRESULT WINAPI DoDragDrop (
517 IDataObject *pDataObject, /* [in] ptr to the data obj */
518 IDropSource* pDropSource, /* [in] ptr to the source obj */
519 DWORD dwOKEffect, /* [in] effects allowed by the source */
520 DWORD *pdwEffect) /* [out] ptr to effects of the source */
522 TrackerWindowInfo trackerInfo;
523 HWND hwndTrackWindow;
526 TRACE("(DataObject %p, DropSource %p)\n", pDataObject, pDropSource);
529 * Setup the drag n drop tracking window.
531 if (!IsValidInterface((LPUNKNOWN)pDropSource))
534 trackerInfo.dataObject = pDataObject;
535 trackerInfo.dropSource = pDropSource;
536 trackerInfo.dwOKEffect = dwOKEffect;
537 trackerInfo.pdwEffect = pdwEffect;
538 trackerInfo.trackingDone = FALSE;
539 trackerInfo.escPressed = FALSE;
540 trackerInfo.curDragTargetHWND = 0;
541 trackerInfo.curTargetHWND = 0;
542 trackerInfo.curDragTarget = 0;
544 hwndTrackWindow = CreateWindowA(OLEDD_DRAGTRACKERCLASS,
547 CW_USEDEFAULT, CW_USEDEFAULT,
548 CW_USEDEFAULT, CW_USEDEFAULT,
552 (LPVOID)&trackerInfo);
554 if (hwndTrackWindow!=0)
557 * Capture the mouse input
559 SetCapture(hwndTrackWindow);
562 * Pump messages. All mouse input should go the the capture window.
564 while (!trackerInfo.trackingDone && GetMessageA(&msg, 0, 0, 0) )
566 if ( (msg.message >= WM_KEYFIRST) &&
567 (msg.message <= WM_KEYLAST) )
570 * When keyboard messages are sent to windows on this thread, we
571 * want to ignore notify the drop source that the state changed.
572 * in the case of the Escape key, we also notify the drop source
573 * we give it a special meaning.
575 if ( (msg.message==WM_KEYDOWN) &&
576 (msg.wParam==VK_ESCAPE) )
578 trackerInfo.escPressed = TRUE;
582 * Notify the drop source.
584 OLEDD_TrackStateChange(&trackerInfo,
586 OLEDD_GetButtonState());
591 * Dispatch the messages only when it's not a keyboard message.
593 DispatchMessageA(&msg);
598 * Destroy the temporary window.
600 DestroyWindow(hwndTrackWindow);
602 return trackerInfo.returnValue;
608 /***********************************************************************
609 * OleQueryLinkFromData [OLE32.@]
611 HRESULT WINAPI OleQueryLinkFromData(
612 IDataObject* pSrcDataObject)
614 FIXME("(%p),stub!\n", pSrcDataObject);
618 /***********************************************************************
619 * OleRegGetMiscStatus [OLE32.@]
621 HRESULT WINAPI OleRegGetMiscStatus(
633 * Initialize the out parameter.
638 * Build the key name we're looking for
640 sprintf( keyName, "CLSID\\{%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}\\",
641 clsid->Data1, clsid->Data2, clsid->Data3,
642 clsid->Data4[0], clsid->Data4[1], clsid->Data4[2], clsid->Data4[3],
643 clsid->Data4[4], clsid->Data4[5], clsid->Data4[6], clsid->Data4[7] );
645 TRACE("(%s, %ld, %p)\n", keyName, dwAspect, pdwStatus);
648 * Open the class id Key
650 result = RegOpenKeyA(HKEY_CLASSES_ROOT,
654 if (result != ERROR_SUCCESS)
655 return REGDB_E_CLASSNOTREG;
660 result = RegOpenKeyA(clsidKey,
665 if (result != ERROR_SUCCESS)
667 RegCloseKey(clsidKey);
668 return REGDB_E_READREGDB;
672 * Read the default value
674 OLEUTL_ReadRegistryDWORDValue(miscStatusKey, pdwStatus);
677 * Open the key specific to the requested aspect.
679 sprintf(keyName, "%ld", dwAspect);
681 result = RegOpenKeyA(miscStatusKey,
685 if (result == ERROR_SUCCESS)
687 OLEUTL_ReadRegistryDWORDValue(aspectKey, pdwStatus);
688 RegCloseKey(aspectKey);
694 RegCloseKey(miscStatusKey);
695 RegCloseKey(clsidKey);
700 /******************************************************************************
701 * OleSetContainedObject [OLE32.@]
703 HRESULT WINAPI OleSetContainedObject(
707 IRunnableObject* runnable = NULL;
710 TRACE("(%p,%x), stub!\n", pUnknown, fContained);
712 hres = IUnknown_QueryInterface(pUnknown,
713 &IID_IRunnableObject,
718 hres = IRunnableObject_SetContainedObject(runnable, fContained);
720 IRunnableObject_Release(runnable);
728 /******************************************************************************
731 HRESULT WINAPI OleLoad(
734 LPOLECLIENTSITE pClientSite,
737 IPersistStorage* persistStorage = NULL;
738 IOleObject* oleObject = NULL;
742 TRACE("(%p,%p,%p,%p)\n", pStg, riid, pClientSite, ppvObj);
745 * TODO, Conversion ... OleDoAutoConvert
749 * Get the class ID for the object.
751 hres = IStorage_Stat(pStg, &storageInfo, STATFLAG_NONAME);
754 * Now, try and create the handler for the object
756 hres = CoCreateInstance(&storageInfo.clsid,
758 CLSCTX_INPROC_HANDLER,
763 * If that fails, as it will most times, load the default
768 hres = OleCreateDefaultHandler(&storageInfo.clsid,
775 * If we couldn't find a handler... this is bad. Abort the whole thing.
781 * Inform the new object of it's client site.
783 hres = IOleObject_SetClientSite(oleObject, pClientSite);
786 * Initialize the object with it's IPersistStorage interface.
788 hres = IOleObject_QueryInterface(oleObject,
789 &IID_IPersistStorage,
790 (void**)&persistStorage);
794 IPersistStorage_Load(persistStorage, pStg);
796 IPersistStorage_Release(persistStorage);
797 persistStorage = NULL;
801 * Return the requested interface to the caller.
803 hres = IOleObject_QueryInterface(oleObject, riid, ppvObj);
806 * Cleanup interfaces used internally
808 IOleObject_Release(oleObject);
813 /***********************************************************************
816 HRESULT WINAPI OleSave(
817 LPPERSISTSTORAGE pPS,
824 TRACE("(%p,%p,%x)\n", pPS, pStg, fSameAsLoad);
827 * First, we transfer the class ID (if available)
829 hres = IPersistStorage_GetClassID(pPS, &objectClass);
833 WriteClassStg(pStg, &objectClass);
837 * Then, we ask the object to save itself to the
838 * storage. If it is successful, we commit the storage.
840 hres = IPersistStorage_Save(pPS, pStg, fSameAsLoad);
844 IStorage_Commit(pStg,
852 /******************************************************************************
853 * OleLockRunning [OLE32.@]
855 HRESULT WINAPI OleLockRunning(LPUNKNOWN pUnknown, BOOL fLock, BOOL fLastUnlockCloses)
857 IRunnableObject* runnable = NULL;
860 TRACE("(%p,%x,%x)\n", pUnknown, fLock, fLastUnlockCloses);
862 hres = IUnknown_QueryInterface(pUnknown,
863 &IID_IRunnableObject,
868 hres = IRunnableObject_LockRunning(runnable, fLock, fLastUnlockCloses);
870 IRunnableObject_Release(runnable);
879 /**************************************************************************
880 * Internal methods to manage the shared OLE menu in response to the
881 * OLE***MenuDescriptor API
885 * OLEMenu_Initialize()
887 * Initializes the OLEMENU data structures.
889 static void OLEMenu_Initialize()
894 * OLEMenu_UnInitialize()
896 * Releases the OLEMENU data structures.
898 static void OLEMenu_UnInitialize()
902 /*************************************************************************
903 * OLEMenu_InstallHooks
904 * Install thread scope message hooks for WH_GETMESSAGE and WH_CALLWNDPROC
906 * RETURNS: TRUE if message hooks were successfully installed
909 BOOL OLEMenu_InstallHooks( DWORD tid )
911 OleMenuHookItem *pHookItem = NULL;
913 /* Create an entry for the hook table */
914 if ( !(pHookItem = HeapAlloc(GetProcessHeap(), 0,
915 sizeof(OleMenuHookItem)) ) )
918 pHookItem->tid = tid;
919 pHookItem->hHeap = GetProcessHeap();
921 /* Install a thread scope message hook for WH_GETMESSAGE */
922 pHookItem->GetMsg_hHook = SetWindowsHookExA( WH_GETMESSAGE, OLEMenu_GetMsgProc,
923 0, GetCurrentThreadId() );
924 if ( !pHookItem->GetMsg_hHook )
927 /* Install a thread scope message hook for WH_CALLWNDPROC */
928 pHookItem->CallWndProc_hHook = SetWindowsHookExA( WH_CALLWNDPROC, OLEMenu_CallWndProc,
929 0, GetCurrentThreadId() );
930 if ( !pHookItem->CallWndProc_hHook )
933 /* Insert the hook table entry */
934 pHookItem->next = hook_list;
935 hook_list = pHookItem;
940 /* Unhook any hooks */
941 if ( pHookItem->GetMsg_hHook )
942 UnhookWindowsHookEx( pHookItem->GetMsg_hHook );
943 if ( pHookItem->CallWndProc_hHook )
944 UnhookWindowsHookEx( pHookItem->CallWndProc_hHook );
945 /* Release the hook table entry */
946 HeapFree(pHookItem->hHeap, 0, pHookItem );
951 /*************************************************************************
952 * OLEMenu_UnInstallHooks
953 * UnInstall thread scope message hooks for WH_GETMESSAGE and WH_CALLWNDPROC
955 * RETURNS: TRUE if message hooks were successfully installed
958 BOOL OLEMenu_UnInstallHooks( DWORD tid )
960 OleMenuHookItem *pHookItem = NULL;
961 OleMenuHookItem **ppHook = &hook_list;
965 if ((*ppHook)->tid == tid)
968 *ppHook = pHookItem->next;
971 ppHook = &(*ppHook)->next;
973 if (!pHookItem) return FALSE;
975 /* Uninstall the hooks installed for this thread */
976 if ( !UnhookWindowsHookEx( pHookItem->GetMsg_hHook ) )
978 if ( !UnhookWindowsHookEx( pHookItem->CallWndProc_hHook ) )
981 /* Release the hook table entry */
982 HeapFree(pHookItem->hHeap, 0, pHookItem );
987 /* Release the hook table entry */
989 HeapFree(pHookItem->hHeap, 0, pHookItem );
994 /*************************************************************************
995 * OLEMenu_IsHookInstalled
996 * Tests if OLEMenu hooks have been installed for a thread
998 * RETURNS: The pointer and index of the hook table entry for the tid
999 * NULL and -1 for the index if no hooks were installed for this thread
1001 OleMenuHookItem * OLEMenu_IsHookInstalled( DWORD tid )
1003 OleMenuHookItem *pHookItem = NULL;
1005 /* Do a simple linear search for an entry whose tid matches ours.
1006 * We really need a map but efficiency is not a concern here. */
1007 for (pHookItem = hook_list; pHookItem; pHookItem = pHookItem->next)
1009 if ( tid == pHookItem->tid )
1016 /***********************************************************************
1017 * OLEMenu_FindMainMenuIndex
1019 * Used by OLEMenu API to find the top level group a menu item belongs to.
1020 * On success pnPos contains the index of the item in the top level menu group
1022 * RETURNS: TRUE if the ID was found, FALSE on failure
1024 static BOOL OLEMenu_FindMainMenuIndex( HMENU hMainMenu, HMENU hPopupMenu, UINT *pnPos )
1028 nItems = GetMenuItemCount( hMainMenu );
1030 for (i = 0; i < nItems; i++)
1034 /* Is the current item a submenu? */
1035 if ( (hsubmenu = GetSubMenu(hMainMenu, i)) )
1037 /* If the handle is the same we're done */
1038 if ( hsubmenu == hPopupMenu )
1044 /* Recursively search without updating pnPos */
1045 else if ( OLEMenu_FindMainMenuIndex( hsubmenu, hPopupMenu, NULL ) )
1057 /***********************************************************************
1058 * OLEMenu_SetIsServerMenu
1060 * Checks whether a popup menu belongs to a shared menu group which is
1061 * owned by the server, and sets the menu descriptor state accordingly.
1062 * All menu messages from these groups should be routed to the server.
1064 * RETURNS: TRUE if the popup menu is part of a server owned group
1065 * FASE if the popup menu is part of a container owned group
1067 BOOL OLEMenu_SetIsServerMenu( HMENU hmenu, OleMenuDescriptor *pOleMenuDescriptor )
1069 UINT nPos = 0, nWidth, i;
1071 pOleMenuDescriptor->bIsServerItem = FALSE;
1073 /* Don't bother searching if the popup is the combined menu itself */
1074 if ( hmenu == pOleMenuDescriptor->hmenuCombined )
1077 /* Find the menu item index in the shared OLE menu that this item belongs to */
1078 if ( !OLEMenu_FindMainMenuIndex( pOleMenuDescriptor->hmenuCombined, hmenu, &nPos ) )
1081 /* The group widths array has counts for the number of elements
1082 * in the groups File, Edit, Container, Object, Window, Help.
1083 * The Edit, Object & Help groups belong to the server object
1084 * and the other three belong to the container.
1085 * Loop through the group widths and locate the group we are a member of.
1087 for ( i = 0, nWidth = 0; i < 6; i++ )
1089 nWidth += pOleMenuDescriptor->mgw.width[i];
1090 if ( nPos < nWidth )
1092 /* Odd elements are server menu widths */
1093 pOleMenuDescriptor->bIsServerItem = (i%2) ? TRUE : FALSE;
1098 return pOleMenuDescriptor->bIsServerItem;
1101 /*************************************************************************
1102 * OLEMenu_CallWndProc
1103 * Thread scope WH_CALLWNDPROC hook proc filter function (callback)
1104 * This is invoked from a message hook installed in OleSetMenuDescriptor.
1106 LRESULT CALLBACK OLEMenu_CallWndProc(INT code, WPARAM wParam, LPARAM lParam)
1108 LPCWPSTRUCT pMsg = NULL;
1109 HOLEMENU hOleMenu = 0;
1110 OleMenuDescriptor *pOleMenuDescriptor = NULL;
1111 OleMenuHookItem *pHookItem = NULL;
1114 TRACE("%i, %04x, %08x\n", code, wParam, (unsigned)lParam );
1116 /* Check if we're being asked to process the message */
1117 if ( HC_ACTION != code )
1120 /* Retrieve the current message being dispatched from lParam */
1121 pMsg = (LPCWPSTRUCT)lParam;
1123 /* Check if the message is destined for a window we are interested in:
1124 * If the window has an OLEMenu property we may need to dispatch
1125 * the menu message to its active objects window instead. */
1127 hOleMenu = (HOLEMENU)GetPropA( pMsg->hwnd, "PROP_OLEMenuDescriptor" );
1131 /* Get the menu descriptor */
1132 pOleMenuDescriptor = (OleMenuDescriptor *) GlobalLock( hOleMenu );
1133 if ( !pOleMenuDescriptor ) /* Bad descriptor! */
1136 /* Process menu messages */
1137 switch( pMsg->message )
1141 /* Reset the menu descriptor state */
1142 pOleMenuDescriptor->bIsServerItem = FALSE;
1144 /* Send this message to the server as well */
1145 SendMessageA( pOleMenuDescriptor->hwndActiveObject,
1146 pMsg->message, pMsg->wParam, pMsg->lParam );
1150 case WM_INITMENUPOPUP:
1152 /* Save the state for whether this is a server owned menu */
1153 OLEMenu_SetIsServerMenu( (HMENU)pMsg->wParam, pOleMenuDescriptor );
1159 fuFlags = HIWORD(pMsg->wParam); /* Get flags */
1160 if ( fuFlags & MF_SYSMENU )
1163 /* Save the state for whether this is a server owned popup menu */
1164 else if ( fuFlags & MF_POPUP )
1165 OLEMenu_SetIsServerMenu( (HMENU)pMsg->lParam, pOleMenuDescriptor );
1172 LPDRAWITEMSTRUCT lpdis = (LPDRAWITEMSTRUCT) pMsg->lParam;
1173 if ( pMsg->wParam != 0 || lpdis->CtlType != ODT_MENU )
1174 goto NEXTHOOK; /* Not a menu message */
1183 /* If the message was for the server dispatch it accordingly */
1184 if ( pOleMenuDescriptor->bIsServerItem )
1186 SendMessageA( pOleMenuDescriptor->hwndActiveObject,
1187 pMsg->message, pMsg->wParam, pMsg->lParam );
1191 if ( pOleMenuDescriptor )
1192 GlobalUnlock( hOleMenu );
1194 /* Lookup the hook item for the current thread */
1195 if ( !( pHookItem = OLEMenu_IsHookInstalled( GetCurrentThreadId() ) ) )
1197 /* This should never fail!! */
1198 WARN("could not retrieve hHook for current thread!\n" );
1202 /* Pass on the message to the next hooker */
1203 return CallNextHookEx( pHookItem->CallWndProc_hHook, code, wParam, lParam );
1206 /*************************************************************************
1207 * OLEMenu_GetMsgProc
1208 * Thread scope WH_GETMESSAGE hook proc filter function (callback)
1209 * This is invoked from a message hook installed in OleSetMenuDescriptor.
1211 LRESULT CALLBACK OLEMenu_GetMsgProc(INT code, WPARAM wParam, LPARAM lParam)
1214 HOLEMENU hOleMenu = 0;
1215 OleMenuDescriptor *pOleMenuDescriptor = NULL;
1216 OleMenuHookItem *pHookItem = NULL;
1219 TRACE("%i, %04x, %08x\n", code, wParam, (unsigned)lParam );
1221 /* Check if we're being asked to process a messages */
1222 if ( HC_ACTION != code )
1225 /* Retrieve the current message being dispatched from lParam */
1226 pMsg = (LPMSG)lParam;
1228 /* Check if the message is destined for a window we are interested in:
1229 * If the window has an OLEMenu property we may need to dispatch
1230 * the menu message to its active objects window instead. */
1232 hOleMenu = (HOLEMENU)GetPropA( pMsg->hwnd, "PROP_OLEMenuDescriptor" );
1236 /* Process menu messages */
1237 switch( pMsg->message )
1241 wCode = HIWORD(pMsg->wParam); /* Get notification code */
1243 goto NEXTHOOK; /* Not a menu message */
1250 /* Get the menu descriptor */
1251 pOleMenuDescriptor = (OleMenuDescriptor *) GlobalLock( hOleMenu );
1252 if ( !pOleMenuDescriptor ) /* Bad descriptor! */
1255 /* If the message was for the server dispatch it accordingly */
1256 if ( pOleMenuDescriptor->bIsServerItem )
1258 /* Change the hWnd in the message to the active objects hWnd.
1259 * The message loop which reads this message will automatically
1260 * dispatch it to the embedded objects window. */
1261 pMsg->hwnd = pOleMenuDescriptor->hwndActiveObject;
1265 if ( pOleMenuDescriptor )
1266 GlobalUnlock( hOleMenu );
1268 /* Lookup the hook item for the current thread */
1269 if ( !( pHookItem = OLEMenu_IsHookInstalled( GetCurrentThreadId() ) ) )
1271 /* This should never fail!! */
1272 WARN("could not retrieve hHook for current thread!\n" );
1276 /* Pass on the message to the next hooker */
1277 return CallNextHookEx( pHookItem->GetMsg_hHook, code, wParam, lParam );
1280 /***********************************************************************
1281 * OleCreateMenuDescriptor [OLE32.@]
1282 * Creates an OLE menu descriptor for OLE to use when dispatching
1283 * menu messages and commands.
1286 * hmenuCombined - Handle to the objects combined menu
1287 * lpMenuWidths - Pointer to array of 6 LONG's indicating menus per group
1290 HOLEMENU WINAPI OleCreateMenuDescriptor(
1291 HMENU hmenuCombined,
1292 LPOLEMENUGROUPWIDTHS lpMenuWidths)
1295 OleMenuDescriptor *pOleMenuDescriptor;
1298 if ( !hmenuCombined || !lpMenuWidths )
1301 /* Create an OLE menu descriptor */
1302 if ( !(hOleMenu = GlobalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT,
1303 sizeof(OleMenuDescriptor) ) ) )
1306 pOleMenuDescriptor = (OleMenuDescriptor *) GlobalLock( hOleMenu );
1307 if ( !pOleMenuDescriptor )
1310 /* Initialize menu group widths and hmenu */
1311 for ( i = 0; i < 6; i++ )
1312 pOleMenuDescriptor->mgw.width[i] = lpMenuWidths->width[i];
1314 pOleMenuDescriptor->hmenuCombined = hmenuCombined;
1315 pOleMenuDescriptor->bIsServerItem = FALSE;
1316 GlobalUnlock( hOleMenu );
1321 /***********************************************************************
1322 * OleDestroyMenuDescriptor [OLE32.@]
1323 * Destroy the shared menu descriptor
1325 HRESULT WINAPI OleDestroyMenuDescriptor(
1326 HOLEMENU hmenuDescriptor)
1328 if ( hmenuDescriptor )
1329 GlobalFree( hmenuDescriptor );
1333 /***********************************************************************
1334 * OleSetMenuDescriptor [OLE32.@]
1335 * Installs or removes OLE dispatching code for the containers frame window
1336 * FIXME: The lpFrame and lpActiveObject parameters are currently ignored
1337 * OLE should install context sensitive help F1 filtering for the app when
1338 * these are non null.
1341 * hOleMenu Handle to composite menu descriptor
1342 * hwndFrame Handle to containers frame window
1343 * hwndActiveObject Handle to objects in-place activation window
1344 * lpFrame Pointer to IOleInPlaceFrame on containers window
1345 * lpActiveObject Pointer to IOleInPlaceActiveObject on active in-place object
1348 * S_OK - menu installed correctly
1349 * E_FAIL, E_INVALIDARG, E_UNEXPECTED - failure
1351 HRESULT WINAPI OleSetMenuDescriptor(
1354 HWND hwndActiveObject,
1355 LPOLEINPLACEFRAME lpFrame,
1356 LPOLEINPLACEACTIVEOBJECT lpActiveObject)
1358 OleMenuDescriptor *pOleMenuDescriptor = NULL;
1361 if ( !hwndFrame || (hOleMenu && !hwndActiveObject) )
1362 return E_INVALIDARG;
1364 if ( lpFrame || lpActiveObject )
1366 FIXME("(%x, %p, %p, %p, %p), Context sensitive help filtering not implemented!\n",
1367 (unsigned int)hOleMenu,
1374 /* Set up a message hook to intercept the containers frame window messages.
1375 * The message filter is responsible for dispatching menu messages from the
1376 * shared menu which are intended for the object.
1379 if ( hOleMenu ) /* Want to install dispatching code */
1381 /* If OLEMenu hooks are already installed for this thread, fail
1382 * Note: This effectively means that OleSetMenuDescriptor cannot
1383 * be called twice in succession on the same frame window
1384 * without first calling it with a null hOleMenu to uninstall */
1385 if ( OLEMenu_IsHookInstalled( GetCurrentThreadId() ) )
1388 /* Get the menu descriptor */
1389 pOleMenuDescriptor = (OleMenuDescriptor *) GlobalLock( hOleMenu );
1390 if ( !pOleMenuDescriptor )
1391 return E_UNEXPECTED;
1393 /* Update the menu descriptor */
1394 pOleMenuDescriptor->hwndFrame = hwndFrame;
1395 pOleMenuDescriptor->hwndActiveObject = hwndActiveObject;
1397 GlobalUnlock( hOleMenu );
1398 pOleMenuDescriptor = NULL;
1400 /* Add a menu descriptor windows property to the frame window */
1401 SetPropA( hwndFrame, "PROP_OLEMenuDescriptor", hOleMenu );
1403 /* Install thread scope message hooks for WH_GETMESSAGE and WH_CALLWNDPROC */
1404 if ( !OLEMenu_InstallHooks( GetCurrentThreadId() ) )
1407 else /* Want to uninstall dispatching code */
1409 /* Uninstall the hooks */
1410 if ( !OLEMenu_UnInstallHooks( GetCurrentThreadId() ) )
1413 /* Remove the menu descriptor property from the frame window */
1414 RemovePropA( hwndFrame, "PROP_OLEMenuDescriptor" );
1420 /******************************************************************************
1421 * IsAccelerator [OLE32.@]
1422 * Mostly copied from controls/menu.c TranslateAccelerator implementation
1424 BOOL WINAPI IsAccelerator(HACCEL hAccel, int cAccelEntries, LPMSG lpMsg, WORD* lpwCmd)
1429 if(!lpMsg) return FALSE;
1432 WARN_(accel)("NULL accel handle\n");
1435 if((lpMsg->message != WM_KEYDOWN &&
1436 lpMsg->message != WM_KEYUP &&
1437 lpMsg->message != WM_SYSKEYDOWN &&
1438 lpMsg->message != WM_SYSKEYUP &&
1439 lpMsg->message != WM_CHAR)) return FALSE;
1440 lpAccelTbl = HeapAlloc(GetProcessHeap(), 0, cAccelEntries * sizeof(ACCEL));
1441 if (NULL == lpAccelTbl)
1445 if (CopyAcceleratorTableW(hAccel, lpAccelTbl, cAccelEntries) != cAccelEntries)
1447 WARN_(accel)("CopyAcceleratorTableW failed\n");
1448 HeapFree(GetProcessHeap(), 0, lpAccelTbl);
1452 TRACE_(accel)("hAccel=%p, cAccelEntries=%d,"
1453 "msg->hwnd=%p, msg->message=%04x, wParam=%08x, lParam=%08lx\n",
1454 hAccel, cAccelEntries,
1455 lpMsg->hwnd, lpMsg->message, lpMsg->wParam, lpMsg->lParam);
1456 for(i = 0; i < cAccelEntries; i++)
1458 if(lpAccelTbl[i].key != lpMsg->wParam)
1461 if(lpMsg->message == WM_CHAR)
1463 if(!(lpAccelTbl[i].fVirt & FALT) && !(lpAccelTbl[i].fVirt & FVIRTKEY))
1465 TRACE_(accel)("found accel for WM_CHAR: ('%c')\n", lpMsg->wParam & 0xff);
1471 if(lpAccelTbl[i].fVirt & FVIRTKEY)
1474 TRACE_(accel)("found accel for virt_key %04x (scan %04x)\n",
1475 lpMsg->wParam, HIWORD(lpMsg->lParam) & 0xff);
1476 if(GetKeyState(VK_SHIFT) & 0x8000) mask |= FSHIFT;
1477 if(GetKeyState(VK_CONTROL) & 0x8000) mask |= FCONTROL;
1478 if(GetKeyState(VK_MENU) & 0x8000) mask |= FALT;
1479 if(mask == (lpAccelTbl[i].fVirt & (FSHIFT | FCONTROL | FALT))) goto found;
1480 TRACE_(accel)("incorrect SHIFT/CTRL/ALT-state\n");
1484 if(!(lpMsg->lParam & 0x01000000)) /* no special_key */
1486 if((lpAccelTbl[i].fVirt & FALT) && (lpMsg->lParam & 0x20000000))
1487 { /* ^^ ALT pressed */
1488 TRACE_(accel)("found accel for Alt-%c\n", lpMsg->wParam & 0xff);
1496 WARN_(accel)("couldn't translate accelerator key\n");
1497 HeapFree(GetProcessHeap(), 0, lpAccelTbl);
1501 if(lpwCmd) *lpwCmd = lpAccelTbl[i].cmd;
1502 HeapFree(GetProcessHeap(), 0, lpAccelTbl);
1506 /***********************************************************************
1507 * ReleaseStgMedium [OLE32.@]
1509 void WINAPI ReleaseStgMedium(
1512 switch (pmedium->tymed)
1516 if ( (pmedium->pUnkForRelease==0) &&
1517 (pmedium->u.hGlobal!=0) )
1518 GlobalFree(pmedium->u.hGlobal);
1523 if (pmedium->u.lpszFileName!=0)
1525 if (pmedium->pUnkForRelease==0)
1527 DeleteFileW(pmedium->u.lpszFileName);
1530 CoTaskMemFree(pmedium->u.lpszFileName);
1536 if (pmedium->u.pstm!=0)
1538 IStream_Release(pmedium->u.pstm);
1542 case TYMED_ISTORAGE:
1544 if (pmedium->u.pstg!=0)
1546 IStorage_Release(pmedium->u.pstg);
1552 if ( (pmedium->pUnkForRelease==0) &&
1553 (pmedium->u.hBitmap!=0) )
1554 DeleteObject(pmedium->u.hBitmap);
1559 if ( (pmedium->pUnkForRelease==0) &&
1560 (pmedium->u.hMetaFilePict!=0) )
1562 LPMETAFILEPICT pMP = GlobalLock(pmedium->u.hMetaFilePict);
1563 DeleteMetaFile(pMP->hMF);
1564 GlobalUnlock(pmedium->u.hMetaFilePict);
1565 GlobalFree(pmedium->u.hMetaFilePict);
1571 if ( (pmedium->pUnkForRelease==0) &&
1572 (pmedium->u.hEnhMetaFile!=0) )
1574 DeleteEnhMetaFile(pmedium->u.hEnhMetaFile);
1582 pmedium->tymed=TYMED_NULL;
1585 * After cleaning up, the unknown is released
1587 if (pmedium->pUnkForRelease!=0)
1589 IUnknown_Release(pmedium->pUnkForRelease);
1590 pmedium->pUnkForRelease = 0;
1595 * OLEDD_Initialize()
1597 * Initializes the OLE drag and drop data structures.
1599 static void OLEDD_Initialize()
1603 ZeroMemory (&wndClass, sizeof(WNDCLASSA));
1604 wndClass.style = CS_GLOBALCLASS;
1605 wndClass.lpfnWndProc = (WNDPROC)OLEDD_DragTrackerWindowProc;
1606 wndClass.cbClsExtra = 0;
1607 wndClass.cbWndExtra = sizeof(TrackerWindowInfo*);
1608 wndClass.hCursor = 0;
1609 wndClass.hbrBackground = 0;
1610 wndClass.lpszClassName = OLEDD_DRAGTRACKERCLASS;
1612 RegisterClassA (&wndClass);
1616 * OLEDD_UnInitialize()
1618 * Releases the OLE drag and drop data structures.
1620 static void OLEDD_UnInitialize()
1623 * Simply empty the list.
1625 while (targetListHead!=NULL)
1627 RevokeDragDrop(targetListHead->hwndTarget);
1632 * OLEDD_InsertDropTarget()
1634 * Insert the target node in the tree.
1636 static void OLEDD_InsertDropTarget(DropTargetNode* nodeToAdd)
1638 DropTargetNode* curNode;
1639 DropTargetNode** parentNodeLink;
1642 * Iterate the tree to find the insertion point.
1644 curNode = targetListHead;
1645 parentNodeLink = &targetListHead;
1647 while (curNode!=NULL)
1649 if (nodeToAdd->hwndTarget<curNode->hwndTarget)
1652 * If the node we want to add has a smaller HWND, go left
1654 parentNodeLink = &curNode->prevDropTarget;
1655 curNode = curNode->prevDropTarget;
1657 else if (nodeToAdd->hwndTarget>curNode->hwndTarget)
1660 * If the node we want to add has a larger HWND, go right
1662 parentNodeLink = &curNode->nextDropTarget;
1663 curNode = curNode->nextDropTarget;
1668 * The item was found in the list. It shouldn't have been there
1676 * If we get here, we have found a spot for our item. The parentNodeLink
1677 * pointer points to the pointer that we have to modify.
1678 * The curNode should be NULL. We just have to establish the link and Voila!
1680 assert(curNode==NULL);
1681 assert(parentNodeLink!=NULL);
1682 assert(*parentNodeLink==NULL);
1684 *parentNodeLink=nodeToAdd;
1688 * OLEDD_ExtractDropTarget()
1690 * Removes the target node from the tree.
1692 static DropTargetNode* OLEDD_ExtractDropTarget(HWND hwndOfTarget)
1694 DropTargetNode* curNode;
1695 DropTargetNode** parentNodeLink;
1698 * Iterate the tree to find the insertion point.
1700 curNode = targetListHead;
1701 parentNodeLink = &targetListHead;
1703 while (curNode!=NULL)
1705 if (hwndOfTarget<curNode->hwndTarget)
1708 * If the node we want to add has a smaller HWND, go left
1710 parentNodeLink = &curNode->prevDropTarget;
1711 curNode = curNode->prevDropTarget;
1713 else if (hwndOfTarget>curNode->hwndTarget)
1716 * If the node we want to add has a larger HWND, go right
1718 parentNodeLink = &curNode->nextDropTarget;
1719 curNode = curNode->nextDropTarget;
1724 * The item was found in the list. Detach it from it's parent and
1725 * re-insert it's kids in the tree.
1727 assert(parentNodeLink!=NULL);
1728 assert(*parentNodeLink==curNode);
1731 * We arbitrately re-attach the left sub-tree to the parent.
1733 *parentNodeLink = curNode->prevDropTarget;
1736 * And we re-insert the right subtree
1738 if (curNode->nextDropTarget!=NULL)
1740 OLEDD_InsertDropTarget(curNode->nextDropTarget);
1744 * The node we found is still a valid node once we complete
1745 * the unlinking of the kids.
1747 curNode->nextDropTarget=NULL;
1748 curNode->prevDropTarget=NULL;
1755 * If we get here, the node is not in the tree
1761 * OLEDD_FindDropTarget()
1763 * Finds information about the drop target.
1765 static DropTargetNode* OLEDD_FindDropTarget(HWND hwndOfTarget)
1767 DropTargetNode* curNode;
1770 * Iterate the tree to find the HWND value.
1772 curNode = targetListHead;
1774 while (curNode!=NULL)
1776 if (hwndOfTarget<curNode->hwndTarget)
1779 * If the node we want to add has a smaller HWND, go left
1781 curNode = curNode->prevDropTarget;
1783 else if (hwndOfTarget>curNode->hwndTarget)
1786 * If the node we want to add has a larger HWND, go right
1788 curNode = curNode->nextDropTarget;
1793 * The item was found in the list.
1800 * If we get here, the item is not in the list
1806 * OLEDD_DragTrackerWindowProc()
1808 * This method is the WindowProcedure of the drag n drop tracking
1809 * window. During a drag n Drop operation, an invisible window is created
1810 * to receive the user input and act upon it. This procedure is in charge
1813 static LRESULT WINAPI OLEDD_DragTrackerWindowProc(
1823 LPCREATESTRUCTA createStruct = (LPCREATESTRUCTA)lParam;
1825 SetWindowLongA(hwnd, 0, (LONG)createStruct->lpCreateParams);
1832 TrackerWindowInfo* trackerInfo = (TrackerWindowInfo*)GetWindowLongA(hwnd, 0);
1836 * Get the current mouse position in screen coordinates.
1838 mousePos.x = LOWORD(lParam);
1839 mousePos.y = HIWORD(lParam);
1840 ClientToScreen(hwnd, &mousePos);
1843 * Track the movement of the mouse.
1845 OLEDD_TrackMouseMove(trackerInfo, mousePos, wParam);
1852 case WM_LBUTTONDOWN:
1853 case WM_MBUTTONDOWN:
1854 case WM_RBUTTONDOWN:
1856 TrackerWindowInfo* trackerInfo = (TrackerWindowInfo*)GetWindowLongA(hwnd, 0);
1860 * Get the current mouse position in screen coordinates.
1862 mousePos.x = LOWORD(lParam);
1863 mousePos.y = HIWORD(lParam);
1864 ClientToScreen(hwnd, &mousePos);
1867 * Notify everyone that the button state changed
1868 * TODO: Check if the "escape" key was pressed.
1870 OLEDD_TrackStateChange(trackerInfo, mousePos, wParam);
1877 * This is a window proc after all. Let's call the default.
1879 return DefWindowProcA (hwnd, uMsg, wParam, lParam);
1883 * OLEDD_TrackMouseMove()
1885 * This method is invoked while a drag and drop operation is in effect.
1886 * it will generate the appropriate callbacks in the drop source
1887 * and drop target. It will also provide the expected feedback to
1891 * trackerInfo - Pointer to the structure identifying the
1892 * drag & drop operation that is currently
1894 * mousePos - Current position of the mouse in screen
1896 * keyState - Contains the state of the shift keys and the
1897 * mouse buttons (MK_LBUTTON and the like)
1899 static void OLEDD_TrackMouseMove(
1900 TrackerWindowInfo* trackerInfo,
1904 HWND hwndNewTarget = 0;
1908 * Get the handle of the window under the mouse
1910 hwndNewTarget = WindowFromPoint(mousePos);
1913 * Every time, we re-initialize the effects passed to the
1914 * IDropTarget to the effects allowed by the source.
1916 *trackerInfo->pdwEffect = trackerInfo->dwOKEffect;
1919 * If we are hovering over the same target as before, send the
1920 * DragOver notification
1922 if ( (trackerInfo->curDragTarget != 0) &&
1923 (trackerInfo->curTargetHWND == hwndNewTarget) )
1925 POINTL mousePosParam;
1928 * The documentation tells me that the coordinate should be in the target
1929 * window's coordinate space. However, the tests I made tell me the
1930 * coordinates should be in screen coordinates.
1932 mousePosParam.x = mousePos.x;
1933 mousePosParam.y = mousePos.y;
1935 IDropTarget_DragOver(trackerInfo->curDragTarget,
1938 trackerInfo->pdwEffect);
1942 DropTargetNode* newDropTargetNode = 0;
1945 * If we changed window, we have to notify our old target and check for
1948 if (trackerInfo->curDragTarget!=0)
1950 IDropTarget_DragLeave(trackerInfo->curDragTarget);
1954 * Make sure we're hovering over a window.
1956 if (hwndNewTarget!=0)
1959 * Find-out if there is a drag target under the mouse
1961 HWND nexttar = hwndNewTarget;
1962 trackerInfo->curTargetHWND = hwndNewTarget;
1965 newDropTargetNode = OLEDD_FindDropTarget(nexttar);
1966 } while (!newDropTargetNode && (nexttar = GetParent(nexttar)) != 0);
1967 if(nexttar) hwndNewTarget = nexttar;
1969 trackerInfo->curDragTargetHWND = hwndNewTarget;
1970 trackerInfo->curDragTarget = newDropTargetNode ? newDropTargetNode->dropTarget : 0;
1973 * If there is, notify it that we just dragged-in
1975 if (trackerInfo->curDragTarget!=0)
1977 POINTL mousePosParam;
1980 * The documentation tells me that the coordinate should be in the target
1981 * window's coordinate space. However, the tests I made tell me the
1982 * coordinates should be in screen coordinates.
1984 mousePosParam.x = mousePos.x;
1985 mousePosParam.y = mousePos.y;
1987 IDropTarget_DragEnter(trackerInfo->curDragTarget,
1988 trackerInfo->dataObject,
1991 trackerInfo->pdwEffect);
1997 * The mouse is not over a window so we don't track anything.
1999 trackerInfo->curDragTargetHWND = 0;
2000 trackerInfo->curTargetHWND = 0;
2001 trackerInfo->curDragTarget = 0;
2006 * Now that we have done that, we have to tell the source to give
2007 * us feedback on the work being done by the target. If we don't
2008 * have a target, simulate no effect.
2010 if (trackerInfo->curDragTarget==0)
2012 *trackerInfo->pdwEffect = DROPEFFECT_NONE;
2015 hr = IDropSource_GiveFeedback(trackerInfo->dropSource,
2016 *trackerInfo->pdwEffect);
2019 * When we ask for feedback from the drop source, sometimes it will
2020 * do all the necessary work and sometimes it will not handle it
2021 * when that's the case, we must display the standard drag and drop
2024 if (hr==DRAGDROP_S_USEDEFAULTCURSORS)
2026 if (*trackerInfo->pdwEffect & DROPEFFECT_MOVE)
2028 SetCursor(LoadCursorA(OLE32_hInstance, MAKEINTRESOURCEA(1)));
2030 else if (*trackerInfo->pdwEffect & DROPEFFECT_COPY)
2032 SetCursor(LoadCursorA(OLE32_hInstance, MAKEINTRESOURCEA(2)));
2034 else if (*trackerInfo->pdwEffect & DROPEFFECT_LINK)
2036 SetCursor(LoadCursorA(OLE32_hInstance, MAKEINTRESOURCEA(3)));
2040 SetCursor(LoadCursorA(OLE32_hInstance, MAKEINTRESOURCEA(0)));
2046 * OLEDD_TrackStateChange()
2048 * This method is invoked while a drag and drop operation is in effect.
2049 * It is used to notify the drop target/drop source callbacks when
2050 * the state of the keyboard or mouse button change.
2053 * trackerInfo - Pointer to the structure identifying the
2054 * drag & drop operation that is currently
2056 * mousePos - Current position of the mouse in screen
2058 * keyState - Contains the state of the shift keys and the
2059 * mouse buttons (MK_LBUTTON and the like)
2061 static void OLEDD_TrackStateChange(
2062 TrackerWindowInfo* trackerInfo,
2067 * Ask the drop source what to do with the operation.
2069 trackerInfo->returnValue = IDropSource_QueryContinueDrag(
2070 trackerInfo->dropSource,
2071 trackerInfo->escPressed,
2075 * All the return valued will stop the operation except the S_OK
2078 if (trackerInfo->returnValue!=S_OK)
2081 * Make sure the message loop in DoDragDrop stops
2083 trackerInfo->trackingDone = TRUE;
2086 * Release the mouse in case the drop target decides to show a popup
2087 * or a menu or something.
2092 * If we end-up over a target, drop the object in the target or
2093 * inform the target that the operation was cancelled.
2095 if (trackerInfo->curDragTarget!=0)
2097 switch (trackerInfo->returnValue)
2100 * If the source wants us to complete the operation, we tell
2101 * the drop target that we just dropped the object in it.
2103 case DRAGDROP_S_DROP:
2105 POINTL mousePosParam;
2108 * The documentation tells me that the coordinate should be
2109 * in the target window's coordinate space. However, the tests
2110 * I made tell me the coordinates should be in screen coordinates.
2112 mousePosParam.x = mousePos.x;
2113 mousePosParam.y = mousePos.y;
2115 IDropTarget_Drop(trackerInfo->curDragTarget,
2116 trackerInfo->dataObject,
2119 trackerInfo->pdwEffect);
2123 * If the source told us that we should cancel, fool the drop
2124 * target by telling it that the mouse left it's window.
2125 * Also set the drop effect to "NONE" in case the application
2126 * ignores the result of DoDragDrop.
2128 case DRAGDROP_S_CANCEL:
2129 IDropTarget_DragLeave(trackerInfo->curDragTarget);
2130 *trackerInfo->pdwEffect = DROPEFFECT_NONE;
2138 * OLEDD_GetButtonState()
2140 * This method will use the current state of the keyboard to build
2141 * a button state mask equivalent to the one passed in the
2142 * WM_MOUSEMOVE wParam.
2144 static DWORD OLEDD_GetButtonState()
2146 BYTE keyboardState[256];
2149 GetKeyboardState(keyboardState);
2151 if ( (keyboardState[VK_SHIFT] & 0x80) !=0)
2152 keyMask |= MK_SHIFT;
2154 if ( (keyboardState[VK_CONTROL] & 0x80) !=0)
2155 keyMask |= MK_CONTROL;
2157 if ( (keyboardState[VK_LBUTTON] & 0x80) !=0)
2158 keyMask |= MK_LBUTTON;
2160 if ( (keyboardState[VK_RBUTTON] & 0x80) !=0)
2161 keyMask |= MK_RBUTTON;
2163 if ( (keyboardState[VK_MBUTTON] & 0x80) !=0)
2164 keyMask |= MK_MBUTTON;
2170 * OLEDD_GetButtonState()
2172 * This method will read the default value of the registry key in
2173 * parameter and extract a DWORD value from it. The registry key value
2174 * can be in a string key or a DWORD key.
2177 * regKey - Key to read the default value from
2178 * pdwValue - Pointer to the location where the DWORD
2179 * value is returned. This value is not modified
2180 * if the value is not found.
2183 static void OLEUTL_ReadRegistryDWORDValue(
2192 lres = RegQueryValueExA(regKey,
2199 if (lres==ERROR_SUCCESS)
2204 *pdwValue = *(DWORD*)buffer;
2209 *pdwValue = (DWORD)strtoul(buffer, NULL, 10);
2215 /******************************************************************************
2218 * The operation of this function is documented literally in the WinAPI
2219 * documentation to involve a QueryInterface for the IViewObject interface,
2220 * followed by a call to IViewObject::Draw.
2222 HRESULT WINAPI OleDraw(
2229 IViewObject *viewobject;
2231 hres = IUnknown_QueryInterface(pUnk,
2233 (void**)&viewobject);
2235 if (SUCCEEDED(hres))
2239 rectl.left = lprcBounds->left;
2240 rectl.right = lprcBounds->right;
2241 rectl.top = lprcBounds->top;
2242 rectl.bottom = lprcBounds->bottom;
2243 hres = IViewObject_Draw(viewobject, dwAspect, -1, 0, 0, 0, hdcDraw, &rectl, 0, 0, 0);
2245 IViewObject_Release(viewobject);
2250 return DV_E_NOIVIEWOBJECT;
2254 /***********************************************************************
2255 * OleTranslateAccelerator [OLE32.@]
2257 HRESULT WINAPI OleTranslateAccelerator (LPOLEINPLACEFRAME lpFrame,
2258 LPOLEINPLACEFRAMEINFO lpFrameInfo, LPMSG lpmsg)
2262 TRACE("(%p,%p,%p)\n", lpFrame, lpFrameInfo, lpmsg);
2264 if (IsAccelerator(lpFrameInfo->haccel,lpFrameInfo->cAccelEntries,lpmsg,&wID))
2265 return IOleInPlaceFrame_TranslateAccelerator(lpFrame,lpmsg,wID);
2270 /******************************************************************************
2271 * OleCreate [OLE32.@]
2274 HRESULT WINAPI OleCreate(
2278 LPFORMATETC pFormatEtc,
2279 LPOLECLIENTSITE pClientSite,
2283 HRESULT hres, hres1;
2284 IUnknown * pUnk = NULL;
2286 FIXME("\n\t%s\n\t%s semi-stub!\n", debugstr_guid(rclsid), debugstr_guid(riid));
2288 if (SUCCEEDED((hres = CoCreateInstance(rclsid, 0, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER|CLSCTX_LOCAL_SERVER , riid, (LPVOID*)&pUnk))))
2293 IPersistStorage * pPS;
2294 if (SUCCEEDED((hres = IUnknown_QueryInterface( pUnk, &IID_IOleObject, (LPVOID*)&pOE))))
2296 TRACE("trying to set clientsite %p\n", pClientSite);
2297 hres1 = IOleObject_SetClientSite(pOE, pClientSite);
2298 TRACE("-- result 0x%08lx\n", hres1);
2299 IOleObject_Release(pOE);
2301 if (SUCCEEDED((hres = IUnknown_QueryInterface( pUnk, &IID_IPersistStorage, (LPVOID*)&pPS))))
2303 TRACE("trying to set stg %p\n", pStg);
2304 hres1 = IPersistStorage_InitNew(pPS, pStg);
2305 TRACE("-- result 0x%08lx\n", hres1);
2306 IPersistStorage_Release(pPS);
2313 TRACE("-- %p \n", pUnk);
2317 /***********************************************************************
2318 * OLE_FreeClipDataArray [internal]
2321 * frees the data associated with an array of CLIPDATAs
2323 static void OLE_FreeClipDataArray(ULONG count, CLIPDATA * pClipDataArray)
2326 for (i = 0; i < count; i++)
2327 if (pClipDataArray[i].pClipData)
2328 CoTaskMemFree(pClipDataArray[i].pClipData);
2331 /******************************************************************************
2332 * Check if a PROPVARIANT's type is valid.
2334 static inline HRESULT PROPVARIANT_ValidateType(VARTYPE vt)
2360 case VT_STREAMED_OBJECT:
2361 case VT_STORED_OBJECT:
2362 case VT_BLOB_OBJECT:
2365 case VT_I2|VT_VECTOR:
2366 case VT_I4|VT_VECTOR:
2367 case VT_R4|VT_VECTOR:
2368 case VT_R8|VT_VECTOR:
2369 case VT_CY|VT_VECTOR:
2370 case VT_DATE|VT_VECTOR:
2371 case VT_BSTR|VT_VECTOR:
2372 case VT_ERROR|VT_VECTOR:
2373 case VT_BOOL|VT_VECTOR:
2374 case VT_VARIANT|VT_VECTOR:
2375 case VT_UI1|VT_VECTOR:
2376 case VT_UI2|VT_VECTOR:
2377 case VT_UI4|VT_VECTOR:
2378 case VT_I8|VT_VECTOR:
2379 case VT_UI8|VT_VECTOR:
2380 case VT_LPSTR|VT_VECTOR:
2381 case VT_LPWSTR|VT_VECTOR:
2382 case VT_FILETIME|VT_VECTOR:
2383 case VT_CF|VT_VECTOR:
2384 case VT_CLSID|VT_VECTOR:
2387 WARN("Bad type %d\n", vt);
2388 return STG_E_INVALIDPARAMETER;
2391 /***********************************************************************
2392 * PropVariantClear [OLE32.@]
2394 HRESULT WINAPI PropVariantClear(PROPVARIANT * pvar) /* [in/out] */
2398 TRACE("(%p)\n", pvar);
2403 hr = PROPVARIANT_ValidateType(pvar->vt);
2410 case VT_STREAMED_OBJECT:
2412 case VT_STORED_OBJECT:
2413 if (pvar->u.pStream)
2414 IUnknown_Release(pvar->u.pStream);
2419 /* pick an arbitary typed pointer - we don't care about the type
2420 * as we are just freeing it */
2421 CoTaskMemFree(pvar->u.puuid);
2424 case VT_BLOB_OBJECT:
2425 CoTaskMemFree(pvar->u.blob.pBlobData);
2428 if (pvar->u.bstrVal)
2430 FIXME("Need to load OLEAUT32 for SysFreeString\n");
2431 /* SysFreeString(pvar->u.bstrVal); */
2435 if (pvar->u.pclipdata)
2437 OLE_FreeClipDataArray(1, pvar->u.pclipdata);
2438 CoTaskMemFree(pvar->u.pclipdata);
2442 switch (pvar->vt & ~VT_VECTOR)
2445 FreePropVariantArray(pvar->u.capropvar.cElems, pvar->u.capropvar.pElems);
2448 OLE_FreeClipDataArray(pvar->u.caclipdata.cElems, pvar->u.caclipdata.pElems);
2454 FIXME("Freeing of vector sub-type not supported yet\n");
2456 if (pvar->vt & ~VT_VECTOR)
2458 /* pick an arbitary VT_VECTOR structure - they all have the same
2460 CoTaskMemFree(pvar->u.capropvar.pElems);
2464 ZeroMemory(pvar, sizeof(*pvar));
2469 /***********************************************************************
2470 * PropVariantCopy [OLE32.@]
2472 HRESULT WINAPI PropVariantCopy(PROPVARIANT *pvarDest, /* [out] */
2473 const PROPVARIANT *pvarSrc) /* [in] */
2478 TRACE("(%p, %p)\n", pvarDest, pvarSrc);
2480 hr = PROPVARIANT_ValidateType(pvarSrc->vt);
2484 /* this will deal with most cases */
2485 CopyMemory(pvarDest, pvarSrc, sizeof(*pvarDest));
2490 case VT_STREAMED_OBJECT:
2492 case VT_STORED_OBJECT:
2493 IUnknown_AddRef((LPUNKNOWN)pvarDest->u.pStream);
2496 pvarDest->u.puuid = CoTaskMemAlloc(sizeof(CLSID));
2497 CopyMemory(pvarDest->u.puuid, pvarSrc->u.puuid, sizeof(CLSID));
2500 len = strlen(pvarSrc->u.pszVal);
2501 pvarDest->u.pszVal = CoTaskMemAlloc((len+1)*sizeof(CHAR));
2502 CopyMemory(pvarDest->u.pszVal, pvarSrc->u.pszVal, (len+1)*sizeof(CHAR));
2505 len = lstrlenW(pvarSrc->u.pwszVal);
2506 pvarDest->u.pwszVal = CoTaskMemAlloc((len+1)*sizeof(WCHAR));
2507 CopyMemory(pvarDest->u.pwszVal, pvarSrc->u.pwszVal, (len+1)*sizeof(WCHAR));
2510 case VT_BLOB_OBJECT:
2511 if (pvarSrc->u.blob.pBlobData)
2513 len = pvarSrc->u.blob.cbSize;
2514 pvarDest->u.blob.pBlobData = CoTaskMemAlloc(len);
2515 CopyMemory(pvarDest->u.blob.pBlobData, pvarSrc->u.blob.pBlobData, len);
2519 FIXME("Need to copy BSTR\n");
2522 if (pvarSrc->u.pclipdata)
2524 len = pvarSrc->u.pclipdata->cbSize - sizeof(pvarSrc->u.pclipdata->ulClipFmt);
2525 CoTaskMemAlloc(len);
2526 CopyMemory(pvarDest->u.pclipdata->pClipData, pvarSrc->u.pclipdata->pClipData, len);
2530 if (pvarSrc->vt & VT_VECTOR)
2533 switch(pvarSrc->vt & VT_VECTOR)
2535 case VT_I1: elemSize = sizeof(pvarSrc->u.cVal); break;
2536 case VT_UI1: elemSize = sizeof(pvarSrc->u.bVal); break;
2537 case VT_I2: elemSize = sizeof(pvarSrc->u.iVal); break;
2538 case VT_UI2: elemSize = sizeof(pvarSrc->u.uiVal); break;
2539 case VT_BOOL: elemSize = sizeof(pvarSrc->u.boolVal); break;
2540 case VT_I4: elemSize = sizeof(pvarSrc->u.lVal); break;
2541 case VT_UI4: elemSize = sizeof(pvarSrc->u.ulVal); break;
2542 case VT_R4: elemSize = sizeof(pvarSrc->u.fltVal); break;
2543 case VT_R8: elemSize = sizeof(pvarSrc->u.dblVal); break;
2544 case VT_ERROR: elemSize = sizeof(pvarSrc->u.scode); break;
2545 case VT_I8: elemSize = sizeof(pvarSrc->u.hVal); break;
2546 case VT_UI8: elemSize = sizeof(pvarSrc->u.uhVal); break;
2547 case VT_CY: elemSize = sizeof(pvarSrc->u.cyVal); break;
2548 case VT_DATE: elemSize = sizeof(pvarSrc->u.date); break;
2549 case VT_FILETIME: elemSize = sizeof(pvarSrc->u.filetime); break;
2550 case VT_CLSID: elemSize = sizeof(*pvarSrc->u.puuid); break;
2551 case VT_CF: elemSize = sizeof(*pvarSrc->u.pclipdata); break;
2558 FIXME("Invalid element type: %ul\n", pvarSrc->vt & VT_VECTOR);
2559 return E_INVALIDARG;
2561 len = pvarSrc->u.capropvar.cElems;
2562 pvarDest->u.capropvar.pElems = CoTaskMemAlloc(len * elemSize);
2563 if (pvarSrc->vt == (VT_VECTOR | VT_VARIANT))
2566 for (i = 0; i < len; i++)
2567 PropVariantCopy(&pvarDest->u.capropvar.pElems[i], &pvarSrc->u.capropvar.pElems[i]);
2569 else if (pvarSrc->vt == (VT_VECTOR | VT_CF))
2571 FIXME("Copy clipformats\n");
2573 else if (pvarSrc->vt == (VT_VECTOR | VT_BSTR))
2575 FIXME("Copy BSTRs\n");
2577 else if (pvarSrc->vt == (VT_VECTOR | VT_LPSTR))
2579 FIXME("Copy LPSTRs\n");
2581 else if (pvarSrc->vt == (VT_VECTOR | VT_LPSTR))
2583 FIXME("Copy LPWSTRs\n");
2586 CopyMemory(pvarDest->u.capropvar.pElems, pvarSrc->u.capropvar.pElems, len * elemSize);
2593 /***********************************************************************
2594 * FreePropVariantArray [OLE32.@]
2596 HRESULT WINAPI FreePropVariantArray(ULONG cVariants, /* [in] */
2597 PROPVARIANT *rgvars) /* [in/out] */
2601 TRACE("(%lu, %p)\n", cVariants, rgvars);
2603 for(i = 0; i < cVariants; i++)
2604 PropVariantClear(&rgvars[i]);
2609 /******************************************************************************
2610 * DllDebugObjectRPCHook (OLE32.@)
2611 * turns on and off internal debugging, pointer is only used on macintosh
2614 BOOL WINAPI DllDebugObjectRPCHook(BOOL b, void *dummy)