4 * Copyright 1995 Martin von Loewis
5 * Copyright 1999 Francis Beaudet
6 * Copyright 1999 Noel Borthwick
14 #include <ole32/ole32.h>
16 #include <storage32.h>
17 #include "ole32_main.h"
23 /******************************************************************************
24 * These are static/global variables and internal data structures that the
25 * OLE module uses to maintain it's state.
27 typedef struct tagDropTargetNode
30 IDropTarget* dropTarget;
31 struct tagDropTargetNode* prevDropTarget;
32 struct tagDropTargetNode* nextDropTarget;
35 typedef struct tagTrackerWindowInfo
37 IDataObject* dataObject;
38 IDropSource* dropSource;
45 HWND curDragTargetHWND;
46 IDropTarget* curDragTarget;
49 typedef struct tagOleMenuDescriptor /* OleMenuDescriptor */
51 HWND hwndFrame; /* The containers frame window */
52 HWND hwndActiveObject; /* The active objects window */
53 OLEMENUGROUPWIDTHS mgw; /* OLE menu group widths for the shared menu */
54 HMENU hmenuCombined; /* The combined menu */
55 BOOL bIsServerItem; /* True if the currently open popup belongs to the server */
58 typedef struct tagOleMenuHookItem /* OleMenu hook item in per thread hook list */
60 DWORD tid; /* Thread Id */
61 HANDLE hHeap; /* Heap this is allocated from */
62 HHOOK GetMsg_hHook; /* message hook for WH_GETMESSAGE */
63 HHOOK CallWndProc_hHook; /* message hook for WH_CALLWNDPROC */
64 struct tagOleMenuHookItem *next;
67 static OleMenuHookItem *hook_list;
70 * This is the lock count on the OLE library. It is controlled by the
71 * OLEInitialize/OLEUninitialize methods.
73 static ULONG OLE_moduleLockCount = 0;
76 * Name of our registered window class.
78 static const char OLEDD_DRAGTRACKERCLASS[] = "WineDragDropTracker32";
81 * This is the head of the Drop target container.
83 static DropTargetNode* targetListHead = NULL;
85 /******************************************************************************
86 * These are the prototypes of miscelaneous utility methods
88 static void OLEUTL_ReadRegistryDWORDValue(HKEY regKey, DWORD* pdwValue);
90 /******************************************************************************
91 * These are the prototypes of the utility methods used to manage a shared menu
93 static void OLEMenu_Initialize();
94 static void OLEMenu_UnInitialize();
95 BOOL OLEMenu_InstallHooks( DWORD tid );
96 BOOL OLEMenu_UnInstallHooks( DWORD tid );
97 OleMenuHookItem * OLEMenu_IsHookInstalled( DWORD tid );
98 static BOOL OLEMenu_FindMainMenuIndex( HMENU hMainMenu, HMENU hPopupMenu, UINT *pnPos );
99 BOOL OLEMenu_SetIsServerMenu( HMENU hmenu, OleMenuDescriptor *pOleMenuDescriptor );
100 LRESULT CALLBACK OLEMenu_CallWndProc(INT code, WPARAM wParam, LPARAM lParam);
101 LRESULT CALLBACK OLEMenu_GetMsgProc(INT code, WPARAM wParam, LPARAM lParam);
103 /******************************************************************************
104 * These are the prototypes of the OLE Clipboard initialization methods (in clipboard.c)
106 void OLEClipbrd_UnInitialize();
107 void OLEClipbrd_Initialize();
109 /******************************************************************************
110 * These are the prototypes of the utility methods used for OLE Drag n Drop
112 static void OLEDD_Initialize();
113 static void OLEDD_UnInitialize();
114 static void OLEDD_InsertDropTarget(
115 DropTargetNode* nodeToAdd);
116 static DropTargetNode* OLEDD_ExtractDropTarget(
118 static DropTargetNode* OLEDD_FindDropTarget(
120 static LRESULT WINAPI OLEDD_DragTrackerWindowProc(
125 static void OLEDD_TrackMouseMove(
126 TrackerWindowInfo* trackerInfo,
129 static void OLEDD_TrackStateChange(
130 TrackerWindowInfo* trackerInfo,
133 static DWORD OLEDD_GetButtonState();
136 /******************************************************************************
137 * OleBuildVersion [OLE2.1]
139 DWORD WINAPI OleBuildVersion(void)
141 Print(MAX_TRACE, ("Returning version %d, build %d.\n", 1, 0));
145 /***********************************************************************
146 * OleInitialize (OLE2.2) (OLE32.108)
148 HRESULT WINAPI OleInitialize(LPVOID reserved)
152 Print(MAX_TRACE, ("(%p)\n", reserved));
155 * The first duty of the OleInitialize is to initialize the COM libraries.
157 hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
160 * If the CoInitializeEx call failed, the OLE libraries can't be
167 * Then, it has to initialize the OLE specific modules.
171 * Object linking and Embedding
172 * In-place activation
174 if (OLE_moduleLockCount==0)
177 * Initialize the libraries.
179 Print(MAX_TRACE, ("() - Initializing the OLE libraries\n"));
184 OLEClipbrd_Initialize();
194 OLEMenu_Initialize();
198 * Then, we increase the lock count on the OLE module.
200 OLE_moduleLockCount++;
205 /******************************************************************************
206 * CoGetCurrentProcess [COMPOBJ.34] [OLE2.2][OLE32.108]
209 * Is DWORD really the correct return type for this function?
211 DWORD WINAPI CoGetCurrentProcess(void)
213 return GetCurrentProcessId();
216 /******************************************************************************
217 * OleUninitialize [OLE2.3] [OLE32.131]
219 void WINAPI OleUninitialize(void)
221 Print(MAX_TRACE, ("()\n"));
224 * Decrease the lock count on the OLE module.
226 OLE_moduleLockCount--;
229 * If we hit the bottom of the lock stack, free the libraries.
231 if (OLE_moduleLockCount==0)
234 * Actually free the libraries.
236 Print(MAX_TRACE, ("() - Freeing the last reference count\n"));
241 OLEClipbrd_UnInitialize();
246 OLEDD_UnInitialize();
251 OLEMenu_UnInitialize();
255 * Then, uninitialize the COM libraries.
260 /******************************************************************************
261 * CoRegisterMessageFilter [OLE32.38]
263 HRESULT WINAPI CoRegisterMessageFilter(
264 LPMESSAGEFILTER lpMessageFilter, /* [in] Pointer to interface */
265 LPMESSAGEFILTER *lplpMessageFilter /* [out] Indirect pointer to prior instance if non-NULL */
267 Print(MIN_TRACE, ("stub\n"));
268 if (lplpMessageFilter) {
269 *lplpMessageFilter = NULL;
274 /******************************************************************************
275 * OleInitializeWOW [OLE32.109]
277 HRESULT WINAPI OleInitializeWOW(DWORD x) {
278 Print(MIN_TRACE, ("(0x%08lx),stub!\n",x));
282 /***********************************************************************
283 * RegisterDragDrop16 (OLE2.35)
285 HRESULT WINAPI RegisterDragDrop16(
287 LPDROPTARGET pDropTarget
293 /***********************************************************************
294 * RegisterDragDrop (OLE32.139)
296 HRESULT WINAPI RegisterDragDrop(
298 LPDROPTARGET pDropTarget)
300 DropTargetNode* dropTargetInfo;
302 Print(MAX_TRACE, ("(0x%x,%p)\n", hwnd, pDropTarget));
305 * First, check if the window is already registered.
307 dropTargetInfo = OLEDD_FindDropTarget(hwnd);
309 if (dropTargetInfo!=NULL)
310 return DRAGDROP_E_ALREADYREGISTERED;
313 * If it's not there, we can add it. We first create a node for it.
315 dropTargetInfo = HeapAlloc(GetProcessHeap(), 0, sizeof(DropTargetNode));
317 if (dropTargetInfo==NULL)
318 return E_OUTOFMEMORY;
320 dropTargetInfo->hwndTarget = hwnd;
321 dropTargetInfo->prevDropTarget = NULL;
322 dropTargetInfo->nextDropTarget = NULL;
325 * Don't forget that this is an interface pointer, need to nail it down since
326 * we keep a copy of it.
328 dropTargetInfo->dropTarget = pDropTarget;
329 IDropTarget_AddRef(dropTargetInfo->dropTarget);
331 OLEDD_InsertDropTarget(dropTargetInfo);
336 /***********************************************************************
337 * RevokeDragDrop16 (OLE2.36)
339 HRESULT WINAPI RevokeDragDrop16(
346 /***********************************************************************
347 * RevokeDragDrop (OLE32.141)
349 HRESULT WINAPI RevokeDragDrop(
352 DropTargetNode* dropTargetInfo;
354 Print(MAX_TRACE, ("(0x%x)\n", hwnd));
357 * First, check if the window is already registered.
359 dropTargetInfo = OLEDD_ExtractDropTarget(hwnd);
362 * If it ain't in there, it's an error.
364 if (dropTargetInfo==NULL)
365 return DRAGDROP_E_NOTREGISTERED;
368 * If it's in there, clean-up it's used memory and
371 IDropTarget_Release(dropTargetInfo->dropTarget);
372 HeapFree(GetProcessHeap(), 0, dropTargetInfo);
377 /***********************************************************************
378 * OleRegGetUserType (OLE32.122)
380 * This implementation of OleRegGetUserType ignores the dwFormOfType
381 * parameter and always returns the full name of the object. This is
382 * not too bad since this is the case for many objects because of the
383 * way they are registered.
385 HRESULT WINAPI OleRegGetUserType(
388 LPOLESTR* pszUserType)
398 * Initialize the out parameter.
403 * Build the key name we're looking for
405 sprintf( keyName, "CLSID\\{%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}\\",
406 clsid->Data1, clsid->Data2, clsid->Data3,
407 clsid->Data4[0], clsid->Data4[1], clsid->Data4[2], clsid->Data4[3],
408 clsid->Data4[4], clsid->Data4[5], clsid->Data4[6], clsid->Data4[7] );
410 Print(MAX_TRACE, ("(%s, %ld, %p)\n", keyName, dwFormOfType, pszUserType));
413 * Open the class id Key
415 hres = RegOpenKeyA(HKEY_CLASSES_ROOT,
419 if (hres != ERROR_SUCCESS)
420 return REGDB_E_CLASSNOTREG;
423 * Retrieve the size of the name string.
427 hres = RegQueryValueExA(clsidKey,
434 if (hres!=ERROR_SUCCESS)
436 RegCloseKey(clsidKey);
437 return REGDB_E_READREGDB;
441 * Allocate a buffer for the registry value.
443 *pszUserType = CoTaskMemAlloc(cbData*2);
445 if (*pszUserType==NULL)
447 RegCloseKey(clsidKey);
448 return E_OUTOFMEMORY;
451 buffer = HeapAlloc(GetProcessHeap(), 0, cbData);
455 RegCloseKey(clsidKey);
456 CoTaskMemFree(*pszUserType);
458 return E_OUTOFMEMORY;
461 hres = RegQueryValueExA(clsidKey,
468 RegCloseKey(clsidKey);
471 if (hres!=ERROR_SUCCESS)
473 CoTaskMemFree(*pszUserType);
476 retVal = REGDB_E_READREGDB;
480 MultiByteToWideChar( CP_ACP, 0, buffer, -1, *pszUserType, cbData /*FIXME*/ );
483 HeapFree(GetProcessHeap(), 0, buffer);
488 /***********************************************************************
489 * DoDragDrop [OLE32.65]
491 HRESULT WINAPI DoDragDrop (
492 IDataObject *pDataObject, /* [in] ptr to the data obj */
493 IDropSource* pDropSource, /* [in] ptr to the source obj */
494 DWORD dwOKEffect, /* [in] effects allowed by the source */
495 DWORD *pdwEffect) /* [out] ptr to effects of the source */
497 TrackerWindowInfo trackerInfo;
498 HWND hwndTrackWindow;
501 Print(MAX_TRACE, ("(DataObject %p, DropSource %p)\n", pDataObject, pDropSource));
504 * Setup the drag n drop tracking window.
506 trackerInfo.dataObject = pDataObject;
507 trackerInfo.dropSource = pDropSource;
508 trackerInfo.dwOKEffect = dwOKEffect;
509 trackerInfo.pdwEffect = pdwEffect;
510 trackerInfo.trackingDone = FALSE;
511 trackerInfo.escPressed = FALSE;
512 trackerInfo.curDragTargetHWND = 0;
513 trackerInfo.curDragTarget = 0;
515 hwndTrackWindow = CreateWindowA(OLEDD_DRAGTRACKERCLASS,
518 CW_USEDEFAULT, CW_USEDEFAULT,
519 CW_USEDEFAULT, CW_USEDEFAULT,
523 (LPVOID)&trackerInfo);
525 if (hwndTrackWindow!=0)
528 * Capture the mouse input
530 SetCapture(hwndTrackWindow);
533 * Pump messages. All mouse input should go the the capture window.
535 while (!trackerInfo.trackingDone && GetMessageA(&msg, 0, 0, 0) )
537 if ( (msg.message >= WM_KEYFIRST) &&
538 (msg.message <= WM_KEYLAST) )
541 * When keyboard messages are sent to windows on this thread, we
542 * want to ignore notify the drop source that the state changed.
543 * in the case of the Escape key, we also notify the drop source
544 * we give it a special meaning.
546 if ( (msg.message==WM_KEYDOWN) &&
547 (msg.wParam==VK_ESCAPE) )
549 trackerInfo.escPressed = TRUE;
553 * Notify the drop source.
555 OLEDD_TrackStateChange(&trackerInfo,
557 OLEDD_GetButtonState());
562 * Dispatch the messages only when it's not a keyboard message.
564 DispatchMessageA(&msg);
569 * Destroy the temporary window.
571 DestroyWindow(hwndTrackWindow);
573 return trackerInfo.returnValue;
579 /***********************************************************************
580 * OleQueryLinkFromData [OLE32.118]
582 HRESULT WINAPI OleQueryLinkFromData(
583 IDataObject* pSrcDataObject)
585 Print(MIN_TRACE, ("(%p),stub!\n", pSrcDataObject));
589 /***********************************************************************
590 * OleRegGetMiscStatus [OLE32.121]
592 HRESULT WINAPI OleRegGetMiscStatus(
604 * Initialize the out parameter.
609 * Build the key name we're looking for
611 sprintf( keyName, "CLSID\\{%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}\\",
612 clsid->Data1, clsid->Data2, clsid->Data3,
613 clsid->Data4[0], clsid->Data4[1], clsid->Data4[2], clsid->Data4[3],
614 clsid->Data4[4], clsid->Data4[5], clsid->Data4[6], clsid->Data4[7] );
616 Print(MAX_TRACE, ("(%s, %ld, %p)\n", keyName, dwAspect, pdwStatus));
619 * Open the class id Key
621 result = RegOpenKeyA(HKEY_CLASSES_ROOT,
625 if (result != ERROR_SUCCESS)
626 return REGDB_E_CLASSNOTREG;
631 result = RegOpenKeyA(clsidKey,
636 if (result != ERROR_SUCCESS)
638 RegCloseKey(clsidKey);
639 return REGDB_E_READREGDB;
643 * Read the default value
645 OLEUTL_ReadRegistryDWORDValue(miscStatusKey, pdwStatus);
648 * Open the key specific to the requested aspect.
650 sprintf(keyName, "%ld", dwAspect);
652 result = RegOpenKeyA(miscStatusKey,
656 if (result == ERROR_SUCCESS)
658 OLEUTL_ReadRegistryDWORDValue(aspectKey, pdwStatus);
659 RegCloseKey(aspectKey);
665 RegCloseKey(miscStatusKey);
666 RegCloseKey(clsidKey);
671 /******************************************************************************
672 * OleSetContainedObject [OLE32.128]
674 HRESULT WINAPI OleSetContainedObject(
678 IRunnableObject* runnable = NULL;
681 Print(MAX_TRACE, ("(%p,%x), stub!\n", pUnknown, fContained));
683 hres = IUnknown_QueryInterface(pUnknown,
684 &IID_IRunnableObject,
689 hres = IRunnableObject_SetContainedObject(runnable, fContained);
691 IRunnableObject_Release(runnable);
699 /******************************************************************************
700 * OleLoad [OLE32.112]
702 HRESULT WINAPI OleLoad(
705 LPOLECLIENTSITE pClientSite,
708 IPersistStorage* persistStorage = NULL;
709 IOleObject* oleObject = NULL;
713 Print(MAX_TRACE, ("(%p,%p,%p,%p)\n", pStg, riid, pClientSite, ppvObj));
716 * TODO, Conversion ... OleDoAutoConvert
720 * Get the class ID for the object.
722 hres = IStorage_Stat(pStg, &storageInfo, STATFLAG_NONAME);
725 * Now, try and create the handler for the object
727 hres = CoCreateInstance(&storageInfo.clsid,
729 CLSCTX_INPROC_HANDLER,
734 * If that fails, as it will most times, load the default
739 hres = OleCreateDefaultHandler(&storageInfo.clsid,
746 * If we couldn't find a handler... this is bad. Abort the whole thing.
752 * Inform the new object of it's client site.
754 hres = IOleObject_SetClientSite(oleObject, pClientSite);
757 * Initialize the object with it's IPersistStorage interface.
759 hres = IOleObject_QueryInterface(oleObject,
760 &IID_IPersistStorage,
761 (void**)&persistStorage);
765 IPersistStorage_Load(persistStorage, pStg);
767 IPersistStorage_Release(persistStorage);
768 persistStorage = NULL;
772 * Return the requested interface to the caller.
774 hres = IOleObject_QueryInterface(oleObject, riid, ppvObj);
777 * Cleanup interfaces used internally
779 IOleObject_Release(oleObject);
784 /***********************************************************************
785 * OleSave [OLE32.124]
787 HRESULT WINAPI OleSave(
788 LPPERSISTSTORAGE pPS,
795 Print(MAX_TRACE, ("(%p,%p,%x)\n", pPS, pStg, fSameAsLoad));
798 * First, we transfer the class ID (if available)
800 hres = IPersistStorage_GetClassID(pPS, &objectClass);
804 WriteClassStg(pStg, &objectClass);
808 * Then, we ask the object to save itself to the
809 * storage. If it is successful, we commit the storage.
811 hres = IPersistStorage_Save(pPS, pStg, fSameAsLoad);
815 IStorage_Commit(pStg,
823 /******************************************************************************
824 * OleLockRunning [OLE32.114]
826 HRESULT WINAPI OleLockRunning(LPUNKNOWN pUnknown, BOOL fLock, BOOL fLastUnlockCloses)
828 IRunnableObject* runnable = NULL;
831 Print(MAX_TRACE, ("(%p,%x,%x)\n", pUnknown, fLock, fLastUnlockCloses));
833 hres = IUnknown_QueryInterface(pUnknown,
834 &IID_IRunnableObject,
839 hres = IRunnableObject_LockRunning(runnable, fLock, fLastUnlockCloses);
841 IRunnableObject_Release(runnable);
850 /**************************************************************************
851 * Internal methods to manage the shared OLE menu in response to the
852 * OLE***MenuDescriptor API
856 * OLEMenu_Initialize()
858 * Initializes the OLEMENU data structures.
860 static void OLEMenu_Initialize()
865 * OLEMenu_UnInitialize()
867 * Releases the OLEMENU data structures.
869 static void OLEMenu_UnInitialize()
873 /*************************************************************************
874 * OLEMenu_InstallHooks
875 * Install thread scope message hooks for WH_GETMESSAGE and WH_CALLWNDPROC
877 * RETURNS: TRUE if message hooks were succesfully installed
880 BOOL OLEMenu_InstallHooks( DWORD tid )
882 OleMenuHookItem *pHookItem = NULL;
884 /* Create an entry for the hook table */
885 if ( !(pHookItem = HeapAlloc(GetProcessHeap(), 0,
886 sizeof(OleMenuHookItem)) ) )
889 pHookItem->tid = tid;
890 pHookItem->hHeap = GetProcessHeap();
892 /* Install a thread scope message hook for WH_GETMESSAGE */
893 pHookItem->GetMsg_hHook = SetWindowsHookExA( WH_GETMESSAGE, OLEMenu_GetMsgProc,
894 0, GetCurrentThreadId() );
895 if ( !pHookItem->GetMsg_hHook )
898 /* Install a thread scope message hook for WH_CALLWNDPROC */
899 pHookItem->CallWndProc_hHook = SetWindowsHookExA( WH_CALLWNDPROC, OLEMenu_CallWndProc,
900 0, GetCurrentThreadId() );
901 if ( !pHookItem->CallWndProc_hHook )
904 /* Insert the hook table entry */
905 pHookItem->next = hook_list;
906 hook_list = pHookItem;
911 /* Unhook any hooks */
912 if ( pHookItem->GetMsg_hHook )
913 UnhookWindowsHookEx( pHookItem->GetMsg_hHook );
914 if ( pHookItem->CallWndProc_hHook )
915 UnhookWindowsHookEx( pHookItem->CallWndProc_hHook );
916 /* Release the hook table entry */
917 HeapFree(pHookItem->hHeap, 0, pHookItem );
922 /*************************************************************************
923 * OLEMenu_UnInstallHooks
924 * UnInstall thread scope message hooks for WH_GETMESSAGE and WH_CALLWNDPROC
926 * RETURNS: TRUE if message hooks were succesfully installed
929 BOOL OLEMenu_UnInstallHooks( DWORD tid )
931 OleMenuHookItem *pHookItem = NULL;
932 OleMenuHookItem **ppHook = &hook_list;
936 if ((*ppHook)->tid == tid)
939 *ppHook = pHookItem->next;
942 ppHook = &(*ppHook)->next;
944 if (!pHookItem) return FALSE;
946 /* Uninstall the hooks installed for this thread */
947 if ( !UnhookWindowsHookEx( pHookItem->GetMsg_hHook ) )
949 if ( !UnhookWindowsHookEx( pHookItem->CallWndProc_hHook ) )
952 /* Release the hook table entry */
953 HeapFree(pHookItem->hHeap, 0, pHookItem );
958 /* Release the hook table entry */
960 HeapFree(pHookItem->hHeap, 0, pHookItem );
965 /*************************************************************************
966 * OLEMenu_IsHookInstalled
967 * Tests if OLEMenu hooks have been installed for a thread
969 * RETURNS: The pointer and index of the hook table entry for the tid
970 * NULL and -1 for the index if no hooks were installed for this thread
972 OleMenuHookItem * OLEMenu_IsHookInstalled( DWORD tid )
974 OleMenuHookItem *pHookItem = NULL;
976 /* Do a simple linear search for an entry whose tid matches ours.
977 * We really need a map but efficiency is not a concern here. */
978 for (pHookItem = hook_list; pHookItem; pHookItem = pHookItem->next)
980 if ( tid == pHookItem->tid )
987 /***********************************************************************
988 * OLEMenu_FindMainMenuIndex
990 * Used by OLEMenu API to find the top level group a menu item belongs to.
991 * On success pnPos contains the index of the item in the top level menu group
993 * RETURNS: TRUE if the ID was found, FALSE on failure
995 static BOOL OLEMenu_FindMainMenuIndex( HMENU hMainMenu, HMENU hPopupMenu, UINT *pnPos )
999 nItems = GetMenuItemCount( hMainMenu );
1001 for (i = 0; i < nItems; i++)
1005 /* Is the current item a submenu? */
1006 if ( (hsubmenu = GetSubMenu(hMainMenu, i)) )
1008 /* If the handle is the same we're done */
1009 if ( hsubmenu == hPopupMenu )
1015 /* Recursively search without updating pnPos */
1016 else if ( OLEMenu_FindMainMenuIndex( hsubmenu, hPopupMenu, NULL ) )
1028 /***********************************************************************
1029 * OLEMenu_SetIsServerMenu
1031 * Checks whether a popup menu belongs to a shared menu group which is
1032 * owned by the server, and sets the menu descriptor state accordingly.
1033 * All menu messages from these groups should be routed to the server.
1035 * RETURNS: TRUE if the popup menu is part of a server owned group
1036 * FASE if the popup menu is part of a container owned group
1038 BOOL OLEMenu_SetIsServerMenu( HMENU hmenu, OleMenuDescriptor *pOleMenuDescriptor )
1040 UINT nPos = 0, nWidth, i;
1042 pOleMenuDescriptor->bIsServerItem = FALSE;
1044 /* Don't bother searching if the popup is the combined menu itself */
1045 if ( hmenu == pOleMenuDescriptor->hmenuCombined )
1048 /* Find the menu item index in the shared OLE menu that this item belongs to */
1049 if ( !OLEMenu_FindMainMenuIndex( pOleMenuDescriptor->hmenuCombined, hmenu, &nPos ) )
1052 /* The group widths array has counts for the number of elements
1053 * in the groups File, Edit, Container, Object, Window, Help.
1054 * The Edit, Object & Help groups belong to the server object
1055 * and the other three belong to the container.
1056 * Loop thru the group widths and locate the group we are a member of.
1058 for ( i = 0, nWidth = 0; i < 6; i++ )
1060 nWidth += pOleMenuDescriptor->mgw.width[i];
1061 if ( nPos < nWidth )
1063 /* Odd elements are server menu widths */
1064 pOleMenuDescriptor->bIsServerItem = (i%2) ? TRUE : FALSE;
1069 return pOleMenuDescriptor->bIsServerItem;
1072 /*************************************************************************
1073 * OLEMenu_CallWndProc
1074 * Thread scope WH_CALLWNDPROC hook proc filter function (callback)
1075 * This is invoked from a message hook installed in OleSetMenuDescriptor.
1077 LRESULT CALLBACK OLEMenu_CallWndProc(INT code, WPARAM wParam, LPARAM lParam)
1080 LPCWPSTRUCT pMsg = NULL;
1081 HOLEMENU hOleMenu = 0;
1082 OleMenuDescriptor *pOleMenuDescriptor = NULL;
1083 OleMenuHookItem *pHookItem = NULL;
1086 Print(MAX_TRACE, ("%i, %04x, %08x\n", code, wParam, (unsigned)lParam ));
1088 /* Check if we're being asked to process the message */
1089 if ( HC_ACTION != code )
1092 /* Retrieve the current message being dispatched from lParam */
1093 pMsg = (LPCWPSTRUCT)lParam;
1095 /* Check if the message is destined for a window we are interested in:
1096 * If the window has an OLEMenu property we may need to dispatch
1097 * the menu message to its active objects window instead. */
1099 hOleMenu = (HOLEMENU)GetPropA( pMsg->hwnd, "PROP_OLEMenuDescriptor" );
1103 /* Get the menu descriptor */
1104 pOleMenuDescriptor = (OleMenuDescriptor *) GlobalLock( hOleMenu );
1105 if ( !pOleMenuDescriptor ) /* Bad descriptor! */
1108 /* Process menu messages */
1109 switch( pMsg->message )
1113 /* Reset the menu descriptor state */
1114 pOleMenuDescriptor->bIsServerItem = FALSE;
1116 /* Send this message to the server as well */
1117 SendMessageA( pOleMenuDescriptor->hwndActiveObject,
1118 pMsg->message, pMsg->wParam, pMsg->lParam );
1122 case WM_INITMENUPOPUP:
1124 /* Save the state for whether this is a server owned menu */
1125 OLEMenu_SetIsServerMenu( (HMENU)pMsg->wParam, pOleMenuDescriptor );
1131 fuFlags = HIWORD(pMsg->wParam); /* Get flags */
1132 if ( fuFlags & MF_SYSMENU )
1135 /* Save the state for whether this is a server owned popup menu */
1136 else if ( fuFlags & MF_POPUP )
1137 OLEMenu_SetIsServerMenu( (HMENU)pMsg->lParam, pOleMenuDescriptor );
1144 LPDRAWITEMSTRUCT lpdis = (LPDRAWITEMSTRUCT) pMsg->lParam;
1145 if ( pMsg->wParam != 0 || lpdis->CtlType != ODT_MENU )
1146 goto NEXTHOOK; /* Not a menu message */
1155 /* If the message was for the server dispatch it accordingly */
1156 if ( pOleMenuDescriptor->bIsServerItem )
1158 SendMessageA( pOleMenuDescriptor->hwndActiveObject,
1159 pMsg->message, pMsg->wParam, pMsg->lParam );
1163 if ( pOleMenuDescriptor )
1164 GlobalUnlock( hOleMenu );
1166 /* Lookup the hook item for the current thread */
1167 if ( !( pHookItem = OLEMenu_IsHookInstalled( GetCurrentThreadId() ) ) )
1169 /* This should never fail!! */
1170 Print(MID_TRACE, ("could not retrieve hHook for current thread!\n" ));
1174 /* Pass on the message to the next hooker */
1175 return CallNextHookEx( pHookItem->CallWndProc_hHook, code, wParam, lParam );
1183 /*************************************************************************
1184 * OLEMenu_GetMsgProc
1185 * Thread scope WH_GETMESSAGE hook proc filter function (callback)
1186 * This is invoked from a message hook installed in OleSetMenuDescriptor.
1188 LRESULT CALLBACK OLEMenu_GetMsgProc(INT code, WPARAM wParam, LPARAM lParam)
1191 HOLEMENU hOleMenu = 0;
1192 OleMenuDescriptor *pOleMenuDescriptor = NULL;
1193 OleMenuHookItem *pHookItem = NULL;
1196 Print(MAX_TRACE, ("%i, %04x, %08x\n", code, wParam, (unsigned)lParam ));
1198 /* Check if we're being asked to process a messages */
1199 if ( HC_ACTION != code )
1202 /* Retrieve the current message being dispatched from lParam */
1203 pMsg = (LPMSG)lParam;
1205 /* Check if the message is destined for a window we are interested in:
1206 * If the window has an OLEMenu property we may need to dispatch
1207 * the menu message to its active objects window instead. */
1209 hOleMenu = (HOLEMENU)GetPropA( pMsg->hwnd, "PROP_OLEMenuDescriptor" );
1213 /* Process menu messages */
1214 switch( pMsg->message )
1218 wCode = HIWORD(pMsg->wParam); /* Get notification code */
1220 goto NEXTHOOK; /* Not a menu message */
1227 /* Get the menu descriptor */
1228 pOleMenuDescriptor = (OleMenuDescriptor *) GlobalLock( hOleMenu );
1229 if ( !pOleMenuDescriptor ) /* Bad descriptor! */
1232 /* If the message was for the server dispatch it accordingly */
1233 if ( pOleMenuDescriptor->bIsServerItem )
1235 /* Change the hWnd in the message to the active objects hWnd.
1236 * The message loop which reads this message will automatically
1237 * dispatch it to the embedded objects window. */
1238 pMsg->hwnd = pOleMenuDescriptor->hwndActiveObject;
1242 if ( pOleMenuDescriptor )
1243 GlobalUnlock( hOleMenu );
1245 /* Lookup the hook item for the current thread */
1246 if ( !( pHookItem = OLEMenu_IsHookInstalled( GetCurrentThreadId() ) ) )
1248 /* This should never fail!! */
1249 Print(MID_TRACE, ("could not retrieve hHook for current thread!\n" ));
1253 /* Pass on the message to the next hooker */
1254 return CallNextHookEx( pHookItem->GetMsg_hHook, code, wParam, lParam );
1257 /***********************************************************************
1258 * OleCreateMenuDescriptor [OLE32.97]
1259 * Creates an OLE menu descriptor for OLE to use when dispatching
1260 * menu messages and commands.
1263 * hmenuCombined - Handle to the objects combined menu
1264 * lpMenuWidths - Pointer to array of 6 LONG's indicating menus per group
1267 HOLEMENU WINAPI OleCreateMenuDescriptor(
1268 HMENU hmenuCombined,
1269 LPOLEMENUGROUPWIDTHS lpMenuWidths)
1272 OleMenuDescriptor *pOleMenuDescriptor;
1275 if ( !hmenuCombined || !lpMenuWidths )
1278 /* Create an OLE menu descriptor */
1279 if ( !(hOleMenu = GlobalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT,
1280 sizeof(OleMenuDescriptor) ) ) )
1283 pOleMenuDescriptor = (OleMenuDescriptor *) GlobalLock( hOleMenu );
1284 if ( !pOleMenuDescriptor )
1287 /* Initialize menu group widths and hmenu */
1288 for ( i = 0; i < 6; i++ )
1289 pOleMenuDescriptor->mgw.width[i] = lpMenuWidths->width[i];
1291 pOleMenuDescriptor->hmenuCombined = hmenuCombined;
1292 pOleMenuDescriptor->bIsServerItem = FALSE;
1293 GlobalUnlock( hOleMenu );
1298 /***********************************************************************
1299 * OleDestroyMenuDescriptor [OLE32.99]
1300 * Destroy the shared menu descriptor
1302 HRESULT WINAPI OleDestroyMenuDescriptor(
1303 HOLEMENU hmenuDescriptor)
1305 if ( hmenuDescriptor )
1306 GlobalFree( hmenuDescriptor );
1310 /***********************************************************************
1311 * OleSetMenuDescriptor [OLE32.129]
1312 * Installs or removes OLE dispatching code for the containers frame window
1313 * FIXME: The lpFrame and lpActiveObject parameters are currently ignored
1314 * OLE should install context sensitive help F1 filtering for the app when
1315 * these are non null.
1318 * hOleMenu Handle to composite menu descriptor
1319 * hwndFrame Handle to containers frame window
1320 * hwndActiveObject Handle to objects in-place activation window
1321 * lpFrame Pointer to IOleInPlaceFrame on containers window
1322 * lpActiveObject Pointer to IOleInPlaceActiveObject on active in-place object
1325 * S_OK - menu installed correctly
1326 * E_FAIL, E_INVALIDARG, E_UNEXPECTED - failure
1328 HRESULT WINAPI OleSetMenuDescriptor(
1331 HWND hwndActiveObject,
1332 LPOLEINPLACEFRAME lpFrame,
1333 LPOLEINPLACEACTIVEOBJECT lpActiveObject)
1335 OleMenuDescriptor *pOleMenuDescriptor = NULL;
1338 if ( !hwndFrame || (hOleMenu && !hwndActiveObject) )
1339 return E_INVALIDARG;
1341 if ( lpFrame || lpActiveObject )
1343 Print(MIN_TRACE, ("(%x, %x, %x, %p, %p), Context sensitive help filtering not implemented!\n",
1344 (unsigned int)hOleMenu,
1351 /* Set up a message hook to intercept the containers frame window messages.
1352 * The message filter is responsible for dispatching menu messages from the
1353 * shared menu which are intended for the object.
1356 if ( hOleMenu ) /* Want to install dispatching code */
1358 /* If OLEMenu hooks are already installed for this thread, fail
1359 * Note: This effectively means that OleSetMenuDescriptor cannot
1360 * be called twice in succession on the same frame window
1361 * without first calling it with a null hOleMenu to uninstall */
1362 if ( OLEMenu_IsHookInstalled( GetCurrentThreadId() ) )
1365 /* Get the menu descriptor */
1366 pOleMenuDescriptor = (OleMenuDescriptor *) GlobalLock( hOleMenu );
1367 if ( !pOleMenuDescriptor )
1368 return E_UNEXPECTED;
1370 /* Update the menu descriptor */
1371 pOleMenuDescriptor->hwndFrame = hwndFrame;
1372 pOleMenuDescriptor->hwndActiveObject = hwndActiveObject;
1374 GlobalUnlock( hOleMenu );
1375 pOleMenuDescriptor = NULL;
1377 /* Add a menu descriptor windows property to the frame window */
1378 SetPropA( hwndFrame, "PROP_OLEMenuDescriptor", hOleMenu );
1380 /* Install thread scope message hooks for WH_GETMESSAGE and WH_CALLWNDPROC */
1381 if ( !OLEMenu_InstallHooks( GetCurrentThreadId() ) )
1384 else /* Want to uninstall dispatching code */
1386 /* Uninstall the hooks */
1387 if ( !OLEMenu_UnInstallHooks( GetCurrentThreadId() ) )
1390 /* Remove the menu descriptor property from the frame window */
1391 RemovePropA( hwndFrame, "PROP_OLEMenuDescriptor" );
1397 /******************************************************************************
1398 * IsAccelerator [OLE32.75]
1399 * Mostly copied from controls/menu.c TranslateAccelerator implementation
1401 BOOL WINAPI IsAccelerator(HACCEL hAccel, int cAccelEntries, LPMSG lpMsg, WORD* lpwCmd)
1405 LPACCEL16 lpAccelTbl;
1408 if(!lpMsg) return FALSE;
1409 if (!hAccel || !(lpAccelTbl = (LPACCEL16)LockResource16(hAccel)))
1411 WARN_(accel)("invalid accel handle=%04x\n", hAccel);
1414 if((lpMsg->message != WM_KEYDOWN &&
1415 lpMsg->message != WM_KEYUP &&
1416 lpMsg->message != WM_SYSKEYDOWN &&
1417 lpMsg->message != WM_SYSKEYUP &&
1418 lpMsg->message != WM_CHAR)) return FALSE;
1420 Print(MAX_TRACE, ("hAccel=%04x, cAccelEntries=%d,"
1421 "msg->hwnd=%04x, msg->message=%04x, wParam=%08x, lParam=%08lx\n",
1422 hAccel, cAccelEntries,
1423 lpMsg->hwnd, lpMsg->message, lpMsg->wParam, lpMsg->lParam));
1424 for(i = 0; i < cAccelEntries; i++)
1426 if(lpAccelTbl[i].key != lpMsg->wParam)
1429 if(lpMsg->message == WM_CHAR)
1431 if(!(lpAccelTbl[i].fVirt & FALT) && !(lpAccelTbl[i].fVirt & FVIRTKEY))
1433 Print(MAX_TRACE, ("found accel for WM_CHAR: ('%c')\n", lpMsg->wParam & 0xff));
1439 if(lpAccelTbl[i].fVirt & FVIRTKEY)
1442 Print(MAX_TRACE, ("found accel for virt_key %04x (scan %04x)\n",
1443 lpMsg->wParam, HIWORD(lpMsg->lParam) & 0xff));
1444 if(GetKeyState(VK_SHIFT) & 0x8000) mask |= FSHIFT;
1445 if(GetKeyState(VK_CONTROL) & 0x8000) mask |= FCONTROL;
1446 if(GetKeyState(VK_MENU) & 0x8000) mask |= FALT;
1447 if(mask == (lpAccelTbl[i].fVirt & (FSHIFT | FCONTROL | FALT))) goto found;
1448 Print(MAX_TRACE, ("incorrect SHIFT/CTRL/ALT-state\n"));
1452 if(!(lpMsg->lParam & 0x01000000)) /* no special_key */
1454 if((lpAccelTbl[i].fVirt & FALT) && (lpMsg->lParam & 0x20000000))
1455 { /* ^^ ALT pressed */
1456 Print(MAX_TRACE, ("found accel for Alt-%c\n", lpMsg->wParam & 0xff));
1464 WARN_(accel)("couldn't translate accelerator key\n");
1468 if(lpwCmd) *lpwCmd = lpAccelTbl[i].cmd;
1475 /***********************************************************************
1476 * ReleaseStgMedium [OLE32.140]
1478 void WINAPI ReleaseStgMedium(
1481 switch (pmedium->tymed)
1485 if ( (pmedium->pUnkForRelease==0) &&
1486 (pmedium->u.hGlobal!=0) )
1487 GlobalFree(pmedium->u.hGlobal);
1489 pmedium->u.hGlobal = 0;
1494 if (pmedium->u.lpszFileName!=0)
1496 if (pmedium->pUnkForRelease==0)
1498 DeleteFileW(pmedium->u.lpszFileName);
1501 CoTaskMemFree(pmedium->u.lpszFileName);
1504 pmedium->u.lpszFileName = 0;
1509 if (pmedium->u.pstm!=0)
1511 IStream_Release(pmedium->u.pstm);
1514 pmedium->u.pstm = 0;
1517 case TYMED_ISTORAGE:
1519 if (pmedium->u.pstg!=0)
1521 IStorage_Release(pmedium->u.pstg);
1524 pmedium->u.pstg = 0;
1529 if ( (pmedium->pUnkForRelease==0) &&
1530 (pmedium->u.hGlobal!=0) )
1531 DeleteObject(pmedium->u.hGlobal);
1533 pmedium->u.hGlobal = 0;
1538 if ( (pmedium->pUnkForRelease==0) &&
1539 (pmedium->u.hMetaFilePict!=0) )
1542 LPMETAFILEPICT pMP = GlobalLock(pmedium->u.hMetaFilePict);
1543 DeleteMetaFile(pMP->hMF);
1545 Print(MIN_TRACE, ("Depending on MetaFile implementation\n"));
1547 GlobalUnlock(pmedium->u.hMetaFilePict);
1548 GlobalFree(pmedium->u.hMetaFilePict);
1551 pmedium->u.hMetaFilePict = 0;
1556 if ( (pmedium->pUnkForRelease==0) &&
1557 (pmedium->u.hEnhMetaFile!=0) )
1559 DeleteEnhMetaFile(pmedium->u.hEnhMetaFile);
1562 pmedium->u.hEnhMetaFile = 0;
1571 * After cleaning up, the unknown is released
1573 if (pmedium->pUnkForRelease!=0)
1575 IUnknown_Release(pmedium->pUnkForRelease);
1576 pmedium->pUnkForRelease = 0;
1581 * OLEDD_Initialize()
1583 * Initializes the OLE drag and drop data structures.
1585 static void OLEDD_Initialize()
1589 ZeroMemory (&wndClass, sizeof(WNDCLASS));
1590 wndClass.style = CS_GLOBALCLASS;
1591 wndClass.lpfnWndProc = (WNDPROC)OLEDD_DragTrackerWindowProc;
1592 wndClass.cbClsExtra = 0;
1593 wndClass.cbWndExtra = sizeof(TrackerWindowInfo*);
1594 wndClass.hCursor = 0;
1595 wndClass.hbrBackground = 0;
1596 wndClass.lpszClassName = OLEDD_DRAGTRACKERCLASS;
1598 RegisterClassA (&wndClass);
1602 * OLEDD_UnInitialize()
1604 * Releases the OLE drag and drop data structures.
1606 static void OLEDD_UnInitialize()
1609 * Simply empty the list.
1611 while (targetListHead!=NULL)
1613 RevokeDragDrop(targetListHead->hwndTarget);
1618 * OLEDD_InsertDropTarget()
1620 * Insert the target node in the tree.
1622 static void OLEDD_InsertDropTarget(DropTargetNode* nodeToAdd)
1624 DropTargetNode* curNode;
1625 DropTargetNode** parentNodeLink;
1628 * Iterate the tree to find the insertion point.
1630 curNode = targetListHead;
1631 parentNodeLink = &targetListHead;
1633 while (curNode!=NULL)
1635 if (nodeToAdd->hwndTarget<curNode->hwndTarget)
1638 * If the node we want to add has a smaller HWND, go left
1640 parentNodeLink = &curNode->prevDropTarget;
1641 curNode = curNode->prevDropTarget;
1643 else if (nodeToAdd->hwndTarget>curNode->hwndTarget)
1646 * If the node we want to add has a larger HWND, go right
1648 parentNodeLink = &curNode->nextDropTarget;
1649 curNode = curNode->nextDropTarget;
1654 * The item was found in the list. It shouldn't have been there
1662 * If we get here, we have found a spot for our item. The parentNodeLink
1663 * pointer points to the pointer that we have to modify.
1664 * The curNode should be NULL. We just have to establish the link and Voila!
1666 assert(curNode==NULL);
1667 assert(parentNodeLink!=NULL);
1668 assert(*parentNodeLink==NULL);
1670 *parentNodeLink=nodeToAdd;
1674 * OLEDD_ExtractDropTarget()
1676 * Removes the target node from the tree.
1678 static DropTargetNode* OLEDD_ExtractDropTarget(HWND hwndOfTarget)
1680 DropTargetNode* curNode;
1681 DropTargetNode** parentNodeLink;
1684 * Iterate the tree to find the insertion point.
1686 curNode = targetListHead;
1687 parentNodeLink = &targetListHead;
1689 while (curNode!=NULL)
1691 if (hwndOfTarget<curNode->hwndTarget)
1694 * If the node we want to add has a smaller HWND, go left
1696 parentNodeLink = &curNode->prevDropTarget;
1697 curNode = curNode->prevDropTarget;
1699 else if (hwndOfTarget>curNode->hwndTarget)
1702 * If the node we want to add has a larger HWND, go right
1704 parentNodeLink = &curNode->nextDropTarget;
1705 curNode = curNode->nextDropTarget;
1710 * The item was found in the list. Detach it from it's parent and
1711 * re-insert it's kids in the tree.
1713 assert(parentNodeLink!=NULL);
1714 assert(*parentNodeLink==curNode);
1717 * We arbitrately re-attach the left sub-tree to the parent.
1719 *parentNodeLink = curNode->prevDropTarget;
1722 * And we re-insert the right subtree
1724 if (curNode->nextDropTarget!=NULL)
1726 OLEDD_InsertDropTarget(curNode->nextDropTarget);
1730 * The node we found is still a valid node once we complete
1731 * the unlinking of the kids.
1733 curNode->nextDropTarget=NULL;
1734 curNode->prevDropTarget=NULL;
1741 * If we get here, the node is not in the tree
1747 * OLEDD_FindDropTarget()
1749 * Finds information about the drop target.
1751 static DropTargetNode* OLEDD_FindDropTarget(HWND hwndOfTarget)
1753 DropTargetNode* curNode;
1756 * Iterate the tree to find the HWND value.
1758 curNode = targetListHead;
1760 while (curNode!=NULL)
1762 if (hwndOfTarget<curNode->hwndTarget)
1765 * If the node we want to add has a smaller HWND, go left
1767 curNode = curNode->prevDropTarget;
1769 else if (hwndOfTarget>curNode->hwndTarget)
1772 * If the node we want to add has a larger HWND, go right
1774 curNode = curNode->nextDropTarget;
1779 * The item was found in the list.
1786 * If we get here, the item is not in the list
1792 * OLEDD_DragTrackerWindowProc()
1794 * This method is the WindowProcedure of the drag n drop tracking
1795 * window. During a drag n Drop operation, an invisible window is created
1796 * to receive the user input and act upon it. This procedure is in charge
1799 static LRESULT WINAPI OLEDD_DragTrackerWindowProc(
1809 LPCREATESTRUCT createStruct = (LPCREATESTRUCT)lParam;
1811 SetWindowLongA(hwnd, 0, (LONG)createStruct->lpCreateParams);
1818 TrackerWindowInfo* trackerInfo = (TrackerWindowInfo*)GetWindowLongA(hwnd, 0);
1822 * Get the current mouse position in screen coordinates.
1824 mousePos.x = LOWORD(lParam);
1825 mousePos.y = HIWORD(lParam);
1826 ClientToScreen(hwnd, &mousePos);
1829 * Track the movement of the mouse.
1831 OLEDD_TrackMouseMove(trackerInfo, mousePos, wParam);
1838 case WM_LBUTTONDOWN:
1839 case WM_MBUTTONDOWN:
1840 case WM_RBUTTONDOWN:
1842 TrackerWindowInfo* trackerInfo = (TrackerWindowInfo*)GetWindowLongA(hwnd, 0);
1846 * Get the current mouse position in screen coordinates.
1848 mousePos.x = LOWORD(lParam);
1849 mousePos.y = HIWORD(lParam);
1850 ClientToScreen(hwnd, &mousePos);
1853 * Notify everyone that the button state changed
1854 * TODO: Check if the "escape" key was pressed.
1856 OLEDD_TrackStateChange(trackerInfo, mousePos, wParam);
1863 * This is a window proc after all. Let's call the default.
1865 return DefWindowProcA (hwnd, uMsg, wParam, lParam);
1869 * OLEDD_TrackMouseMove()
1871 * This method is invoked while a drag and drop operation is in effect.
1872 * it will generate the appropriate callbacks in the drop source
1873 * and drop target. It will also provide the expected feedback to
1877 * trackerInfo - Pointer to the structure identifying the
1878 * drag & drop operation that is currently
1880 * mousePos - Current position of the mouse in screen
1882 * keyState - Contains the state of the shift keys and the
1883 * mouse buttons (MK_LBUTTON and the like)
1885 static void OLEDD_TrackMouseMove(
1886 TrackerWindowInfo* trackerInfo,
1890 HWND hwndNewTarget = 0;
1894 * Get the handle of the window under the mouse
1896 hwndNewTarget = WindowFromPoint(mousePos);
1899 * Every time, we re-initialize the effects passed to the
1900 * IDropTarget to the effects allowed by the source.
1902 *trackerInfo->pdwEffect = trackerInfo->dwOKEffect;
1905 * If we are hovering over the same target as before, send the
1906 * DragOver notification
1908 if ( (trackerInfo->curDragTarget != 0) &&
1909 (trackerInfo->curDragTargetHWND==hwndNewTarget) )
1911 POINTL mousePosParam;
1914 * The documentation tells me that the coordinate should be in the target
1915 * window's coordinate space. However, the tests I made tell me the
1916 * coordinates should be in screen coordinates.
1918 mousePosParam.x = mousePos.x;
1919 mousePosParam.y = mousePos.y;
1921 IDropTarget_DragOver(trackerInfo->curDragTarget,
1924 trackerInfo->pdwEffect);
1928 DropTargetNode* newDropTargetNode = 0;
1931 * If we changed window, we have to notify our old target and check for
1934 if (trackerInfo->curDragTarget!=0)
1936 IDropTarget_DragLeave(trackerInfo->curDragTarget);
1940 * Make sure we're hovering over a window.
1942 if (hwndNewTarget!=0)
1945 * Find-out if there is a drag target under the mouse
1947 HWND nexttar = hwndNewTarget;
1949 newDropTargetNode = OLEDD_FindDropTarget(nexttar);
1950 } while (!newDropTargetNode && (nexttar = GetParent(nexttar)) != 0);
1951 if(nexttar) hwndNewTarget = nexttar;
1953 trackerInfo->curDragTargetHWND = hwndNewTarget;
1954 trackerInfo->curDragTarget = newDropTargetNode ? newDropTargetNode->dropTarget : 0;
1957 * If there is, notify it that we just dragged-in
1959 if (trackerInfo->curDragTarget!=0)
1961 POINTL mousePosParam;
1964 * The documentation tells me that the coordinate should be in the target
1965 * window's coordinate space. However, the tests I made tell me the
1966 * coordinates should be in screen coordinates.
1968 mousePosParam.x = mousePos.x;
1969 mousePosParam.y = mousePos.y;
1971 IDropTarget_DragEnter(trackerInfo->curDragTarget,
1972 trackerInfo->dataObject,
1975 trackerInfo->pdwEffect);
1981 * The mouse is not over a window so we don't track anything.
1983 trackerInfo->curDragTargetHWND = 0;
1984 trackerInfo->curDragTarget = 0;
1989 * Now that we have done that, we have to tell the source to give
1990 * us feedback on the work being done by the target. If we don't
1991 * have a target, simulate no effect.
1993 if (trackerInfo->curDragTarget==0)
1995 *trackerInfo->pdwEffect = DROPEFFECT_NONE;
1998 hr = IDropSource_GiveFeedback(trackerInfo->dropSource,
1999 *trackerInfo->pdwEffect);
2002 * When we ask for feedback from the drop source, sometimes it will
2003 * do all the necessary work and sometimes it will not handle it
2004 * when that's the case, we must display the standard drag and drop
2007 if (hr==DRAGDROP_S_USEDEFAULTCURSORS)
2009 if (*trackerInfo->pdwEffect & DROPEFFECT_MOVE)
2011 SetCursor(LoadCursorA(OLE32_hInstance, MAKEINTRESOURCE(1)));
2013 else if (*trackerInfo->pdwEffect & DROPEFFECT_COPY)
2015 SetCursor(LoadCursorA(OLE32_hInstance, MAKEINTRESOURCE(2)));
2017 else if (*trackerInfo->pdwEffect & DROPEFFECT_LINK)
2019 SetCursor(LoadCursorA(OLE32_hInstance, MAKEINTRESOURCE(3)));
2023 SetCursor(LoadCursorA(OLE32_hInstance, MAKEINTRESOURCE(0)));
2029 * OLEDD_TrackStateChange()
2031 * This method is invoked while a drag and drop operation is in effect.
2032 * It is used to notify the drop target/drop source callbacks when
2033 * the state of the keyboard or mouse button change.
2036 * trackerInfo - Pointer to the structure identifying the
2037 * drag & drop operation that is currently
2039 * mousePos - Current position of the mouse in screen
2041 * keyState - Contains the state of the shift keys and the
2042 * mouse buttons (MK_LBUTTON and the like)
2044 static void OLEDD_TrackStateChange(
2045 TrackerWindowInfo* trackerInfo,
2050 * Ask the drop source what to do with the operation.
2052 trackerInfo->returnValue = IDropSource_QueryContinueDrag(
2053 trackerInfo->dropSource,
2054 trackerInfo->escPressed,
2058 * All the return valued will stop the operation except the S_OK
2061 if (trackerInfo->returnValue!=S_OK)
2064 * Make sure the message loop in DoDragDrop stops
2066 trackerInfo->trackingDone = TRUE;
2069 * Release the mouse in case the drop target decides to show a popup
2070 * or a menu or something.
2075 * If we end-up over a target, drop the object in the target or
2076 * inform the target that the operation was cancelled.
2078 if (trackerInfo->curDragTarget!=0)
2080 switch (trackerInfo->returnValue)
2083 * If the source wants us to complete the operation, we tell
2084 * the drop target that we just dropped the object in it.
2086 case DRAGDROP_S_DROP:
2088 POINTL mousePosParam;
2091 * The documentation tells me that the coordinate should be
2092 * in the target window's coordinate space. However, the tests
2093 * I made tell me the coordinates should be in screen coordinates.
2095 mousePosParam.x = mousePos.x;
2096 mousePosParam.y = mousePos.y;
2098 IDropTarget_Drop(trackerInfo->curDragTarget,
2099 trackerInfo->dataObject,
2102 trackerInfo->pdwEffect);
2106 * If the source told us that we should cancel, fool the drop
2107 * target by telling it that the mouse left it's window.
2108 * Also set the drop effect to "NONE" in case the application
2109 * ignores the result of DoDragDrop.
2111 case DRAGDROP_S_CANCEL:
2112 IDropTarget_DragLeave(trackerInfo->curDragTarget);
2113 *trackerInfo->pdwEffect = DROPEFFECT_NONE;
2121 * OLEDD_GetButtonState()
2123 * This method will use the current state of the keyboard to build
2124 * a button state mask equivalent to the one passed in the
2125 * WM_MOUSEMOVE wParam.
2127 static DWORD OLEDD_GetButtonState()
2129 BYTE keyboardState[256];
2132 GetKeyboardState(keyboardState);
2134 if ( (keyboardState[VK_SHIFT] & 0x80) !=0)
2135 keyMask |= MK_SHIFT;
2137 if ( (keyboardState[VK_CONTROL] & 0x80) !=0)
2138 keyMask |= MK_CONTROL;
2140 if ( (keyboardState[VK_LBUTTON] & 0x80) !=0)
2141 keyMask |= MK_LBUTTON;
2143 if ( (keyboardState[VK_RBUTTON] & 0x80) !=0)
2144 keyMask |= MK_RBUTTON;
2146 if ( (keyboardState[VK_MBUTTON] & 0x80) !=0)
2147 keyMask |= MK_MBUTTON;
2153 * OLEDD_GetButtonState()
2155 * This method will read the default value of the registry key in
2156 * parameter and extract a DWORD value from it. The registry key value
2157 * can be in a string key or a DWORD key.
2160 * regKey - Key to read the default value from
2161 * pdwValue - Pointer to the location where the DWORD
2162 * value is returned. This value is not modified
2163 * if the value is not found.
2166 static void OLEUTL_ReadRegistryDWORDValue(
2175 lres = RegQueryValueExA(regKey,
2182 if (lres==ERROR_SUCCESS)
2187 *pdwValue = *(DWORD*)buffer;
2192 *pdwValue = (DWORD)strtoul(buffer, NULL, 10);
2198 /******************************************************************************
2199 * OleMetaFilePictFromIconAndLabel
2201 * Returns a global memory handle to a metafile which contains the icon and
2203 * I guess the result of that should look somehow like desktop icons.
2204 * If no hIcon is given, we load the icon via lpszSourceFile and iIconIndex.
2205 * This code might be wrong at some places.
2207 DWORD WINAPI OleMetaFilePictFromIconAndLabel16(
2210 PVOID lpszSourceFile,
2217 /******************************************************************************
2218 * DllDebugObjectRPCHook
2219 * turns on and off internal debugging, pointer is only used on macintosh
2222 BOOL WINAPI DllDebugObjectRPCHook(BOOL b, void *dummy)
2224 Print(MIN_TRACE, ("stub\n"));