5 * Copyright 1995 Martin von Loewis
6 * Copyright 1999 Francis Beaudet
7 * Copyright 1999 Noel Borthwick
26 #include "wine/obj_clientserver.h"
27 #include "wine/winbase16.h"
28 #include "wine/wingdi16.h"
29 #include "wine/winuser16.h"
30 #include "ole32_main.h"
32 #include "debugtools.h"
34 DEFAULT_DEBUG_CHANNEL(ole);
35 DECLARE_DEBUG_CHANNEL(accel);
37 /******************************************************************************
38 * These are static/global variables and internal data structures that the
39 * OLE module uses to maintain it's state.
41 typedef struct tagDropTargetNode
44 IDropTarget* dropTarget;
45 struct tagDropTargetNode* prevDropTarget;
46 struct tagDropTargetNode* nextDropTarget;
49 typedef struct tagTrackerWindowInfo
51 IDataObject* dataObject;
52 IDropSource* dropSource;
59 HWND curDragTargetHWND;
60 IDropTarget* curDragTarget;
63 typedef struct tagOleMenuDescriptor /* OleMenuDescriptor */
65 HWND hwndFrame; /* The containers frame window */
66 HWND hwndActiveObject; /* The active objects window */
67 OLEMENUGROUPWIDTHS mgw; /* OLE menu group widths for the shared menu */
68 HMENU hmenuCombined; /* The combined menu */
69 BOOL bIsServerItem; /* True if the currently open popup belongs to the server */
72 typedef struct tagOleMenuHookItem /* OleMenu hook item in per thread hook list */
74 DWORD tid; /* Thread Id */
75 HANDLE hHeap; /* Heap this is allocated from */
76 HHOOK GetMsg_hHook; /* message hook for WH_GETMESSAGE */
77 HHOOK CallWndProc_hHook; /* message hook for WH_CALLWNDPROC */
78 struct tagOleMenuHookItem *next;
81 static OleMenuHookItem *hook_list;
84 * This is the lock count on the OLE library. It is controlled by the
85 * OLEInitialize/OLEUninitialize methods.
87 static ULONG OLE_moduleLockCount = 0;
90 * Name of our registered window class.
92 static const char OLEDD_DRAGTRACKERCLASS[] = "WineDragDropTracker32";
95 * This is the head of the Drop target container.
97 static DropTargetNode* targetListHead = NULL;
99 /******************************************************************************
100 * These are the prototypes of miscelaneous utility methods
102 static void OLEUTL_ReadRegistryDWORDValue(HKEY regKey, DWORD* pdwValue);
104 /******************************************************************************
105 * These are the prototypes of the utility methods used to manage a shared menu
107 static void OLEMenu_Initialize();
108 static void OLEMenu_UnInitialize();
109 BOOL OLEMenu_InstallHooks( DWORD tid );
110 BOOL OLEMenu_UnInstallHooks( DWORD tid );
111 OleMenuHookItem * OLEMenu_IsHookInstalled( DWORD tid );
112 static BOOL OLEMenu_FindMainMenuIndex( HMENU hMainMenu, HMENU hPopupMenu, UINT *pnPos );
113 BOOL OLEMenu_SetIsServerMenu( HMENU hmenu, OleMenuDescriptor *pOleMenuDescriptor );
114 LRESULT CALLBACK OLEMenu_CallWndProc(INT code, WPARAM wParam, LPARAM lParam);
115 LRESULT CALLBACK OLEMenu_GetMsgProc(INT code, WPARAM wParam, LPARAM lParam);
117 /******************************************************************************
118 * These are the prototypes of the OLE Clipboard initialization methods (in clipboard.c)
120 void OLEClipbrd_UnInitialize();
121 void OLEClipbrd_Initialize();
123 /******************************************************************************
124 * These are the prototypes of the utility methods used for OLE Drag n Drop
126 static void OLEDD_Initialize();
127 static void OLEDD_UnInitialize();
128 static void OLEDD_InsertDropTarget(
129 DropTargetNode* nodeToAdd);
130 static DropTargetNode* OLEDD_ExtractDropTarget(
132 static DropTargetNode* OLEDD_FindDropTarget(
134 static LRESULT WINAPI OLEDD_DragTrackerWindowProc(
139 static void OLEDD_TrackMouseMove(
140 TrackerWindowInfo* trackerInfo,
143 static void OLEDD_TrackStateChange(
144 TrackerWindowInfo* trackerInfo,
147 static DWORD OLEDD_GetButtonState();
150 /******************************************************************************
151 * OleBuildVersion [OLE2.1]
152 * OleBuildVersion [OLE32.84]
154 DWORD WINAPI OleBuildVersion(void)
156 TRACE("Returning version %d, build %d.\n", rmm, rup);
157 return (rmm<<16)+rup;
160 /***********************************************************************
161 * OleInitialize (OLE2.2)
162 * OleInitialize (OLE32.108)
164 HRESULT WINAPI OleInitialize(LPVOID reserved)
168 TRACE("(%p)\n", reserved);
171 * The first duty of the OleInitialize is to initialize the COM libraries.
173 hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
176 * If the CoInitializeEx call failed, the OLE libraries can't be
183 * Then, it has to initialize the OLE specific modules.
187 * Object linking and Embedding
188 * In-place activation
190 if (OLE_moduleLockCount==0)
193 * Initialize the libraries.
195 TRACE("() - Initializing the OLE libraries\n");
200 OLEClipbrd_Initialize();
210 OLEMenu_Initialize();
214 * Then, we increase the lock count on the OLE module.
216 OLE_moduleLockCount++;
221 /******************************************************************************
222 * CoGetCurrentProcess [COMPOBJ.34]
223 * CoGetCurrentProcess [OLE32.18]
226 * Is DWORD really the correct return type for this function?
228 DWORD WINAPI CoGetCurrentProcess(void)
230 return GetCurrentProcessId();
233 /******************************************************************************
234 * OleUninitialize [OLE2.3]
235 * OleUninitialize [OLE32.131]
237 void WINAPI OleUninitialize(void)
242 * Decrease the lock count on the OLE module.
244 OLE_moduleLockCount--;
247 * If we hit the bottom of the lock stack, free the libraries.
249 if (OLE_moduleLockCount==0)
252 * Actually free the libraries.
254 TRACE("() - Freeing the last reference count\n");
259 OLEClipbrd_UnInitialize();
264 OLEDD_UnInitialize();
269 OLEMenu_UnInitialize();
273 * Then, uninitialize the COM libraries.
278 /******************************************************************************
279 * CoRegisterMessageFilter [OLE32.38]
281 HRESULT WINAPI CoRegisterMessageFilter(
282 LPMESSAGEFILTER lpMessageFilter, /* [in] Pointer to interface */
283 LPMESSAGEFILTER *lplpMessageFilter /* [out] Indirect pointer to prior instance if non-NULL */
286 if (lplpMessageFilter) {
287 *lplpMessageFilter = NULL;
292 /******************************************************************************
293 * OleInitializeWOW [OLE32.109]
295 HRESULT WINAPI OleInitializeWOW(DWORD x) {
296 FIXME("(0x%08lx),stub!\n",x);
300 /***********************************************************************
301 * RegisterDragDrop (OLE2.35)
303 HRESULT WINAPI RegisterDragDrop16(
305 LPDROPTARGET pDropTarget
307 FIXME("(0x%04x,%p),stub!\n",hwnd,pDropTarget);
311 /***********************************************************************
312 * RegisterDragDrop (OLE32.139)
314 HRESULT WINAPI RegisterDragDrop(
316 LPDROPTARGET pDropTarget)
318 DropTargetNode* dropTargetInfo;
320 TRACE("(0x%x,%p)\n", hwnd, pDropTarget);
323 * First, check if the window is already registered.
325 dropTargetInfo = OLEDD_FindDropTarget(hwnd);
327 if (dropTargetInfo!=NULL)
328 return DRAGDROP_E_ALREADYREGISTERED;
331 * If it's not there, we can add it. We first create a node for it.
333 dropTargetInfo = HeapAlloc(GetProcessHeap(), 0, sizeof(DropTargetNode));
335 if (dropTargetInfo==NULL)
336 return E_OUTOFMEMORY;
338 dropTargetInfo->hwndTarget = hwnd;
339 dropTargetInfo->prevDropTarget = NULL;
340 dropTargetInfo->nextDropTarget = NULL;
343 * Don't forget that this is an interface pointer, need to nail it down since
344 * we keep a copy of it.
346 dropTargetInfo->dropTarget = pDropTarget;
347 IDropTarget_AddRef(dropTargetInfo->dropTarget);
349 OLEDD_InsertDropTarget(dropTargetInfo);
354 /***********************************************************************
355 * RevokeDragDrop (OLE2.36)
357 HRESULT WINAPI RevokeDragDrop16(
360 FIXME("(0x%04x),stub!\n",hwnd);
364 /***********************************************************************
365 * RevokeDragDrop (OLE32.141)
367 HRESULT WINAPI RevokeDragDrop(
370 DropTargetNode* dropTargetInfo;
372 TRACE("(0x%x)\n", hwnd);
375 * First, check if the window is already registered.
377 dropTargetInfo = OLEDD_ExtractDropTarget(hwnd);
380 * If it ain't in there, it's an error.
382 if (dropTargetInfo==NULL)
383 return DRAGDROP_E_NOTREGISTERED;
386 * If it's in there, clean-up it's used memory and
389 IDropTarget_Release(dropTargetInfo->dropTarget);
390 HeapFree(GetProcessHeap(), 0, dropTargetInfo);
395 /***********************************************************************
396 * OleRegGetUserType (OLE32.122)
398 * This implementation of OleRegGetUserType ignores the dwFormOfType
399 * parameter and always returns the full name of the object. This is
400 * not too bad since this is the case for many objects because of the
401 * way they are registered.
403 HRESULT WINAPI OleRegGetUserType(
406 LPOLESTR* pszUserType)
416 * Initialize the out parameter.
421 * Build the key name we're looking for
423 sprintf( keyName, "CLSID\\{%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}\\",
424 clsid->Data1, clsid->Data2, clsid->Data3,
425 clsid->Data4[0], clsid->Data4[1], clsid->Data4[2], clsid->Data4[3],
426 clsid->Data4[4], clsid->Data4[5], clsid->Data4[6], clsid->Data4[7] );
428 TRACE("(%s, %ld, %p)\n", keyName, dwFormOfType, pszUserType);
431 * Open the class id Key
433 hres = RegOpenKeyA(HKEY_CLASSES_ROOT,
437 if (hres != ERROR_SUCCESS)
438 return REGDB_E_CLASSNOTREG;
441 * Retrieve the size of the name string.
445 hres = RegQueryValueExA(clsidKey,
452 if (hres!=ERROR_SUCCESS)
454 RegCloseKey(clsidKey);
455 return REGDB_E_READREGDB;
459 * Allocate a buffer for the registry value.
461 *pszUserType = CoTaskMemAlloc(cbData*2);
463 if (*pszUserType==NULL)
465 RegCloseKey(clsidKey);
466 return E_OUTOFMEMORY;
469 buffer = HeapAlloc(GetProcessHeap(), 0, cbData);
473 RegCloseKey(clsidKey);
474 CoTaskMemFree(*pszUserType);
476 return E_OUTOFMEMORY;
479 hres = RegQueryValueExA(clsidKey,
486 RegCloseKey(clsidKey);
489 if (hres!=ERROR_SUCCESS)
491 CoTaskMemFree(*pszUserType);
494 retVal = REGDB_E_READREGDB;
498 MultiByteToWideChar( CP_ACP, 0, buffer, -1, *pszUserType, cbData /*FIXME*/ );
501 HeapFree(GetProcessHeap(), 0, buffer);
506 /***********************************************************************
507 * DoDragDrop [OLE32.65]
509 HRESULT WINAPI DoDragDrop (
510 IDataObject *pDataObject, /* [in] ptr to the data obj */
511 IDropSource* pDropSource, /* [in] ptr to the source obj */
512 DWORD dwOKEffect, /* [in] effects allowed by the source */
513 DWORD *pdwEffect) /* [out] ptr to effects of the source */
515 TrackerWindowInfo trackerInfo;
516 HWND hwndTrackWindow;
519 TRACE("(DataObject %p, DropSource %p)\n", pDataObject, pDropSource);
522 * Setup the drag n drop tracking window.
524 trackerInfo.dataObject = pDataObject;
525 trackerInfo.dropSource = pDropSource;
526 trackerInfo.dwOKEffect = dwOKEffect;
527 trackerInfo.pdwEffect = pdwEffect;
528 trackerInfo.trackingDone = FALSE;
529 trackerInfo.escPressed = FALSE;
530 trackerInfo.curDragTargetHWND = 0;
531 trackerInfo.curDragTarget = 0;
533 hwndTrackWindow = CreateWindowA(OLEDD_DRAGTRACKERCLASS,
536 CW_USEDEFAULT, CW_USEDEFAULT,
537 CW_USEDEFAULT, CW_USEDEFAULT,
541 (LPVOID)&trackerInfo);
543 if (hwndTrackWindow!=0)
546 * Capture the mouse input
548 SetCapture(hwndTrackWindow);
551 * Pump messages. All mouse input should go the the capture window.
553 while (!trackerInfo.trackingDone && GetMessageA(&msg, 0, 0, 0) )
555 if ( (msg.message >= WM_KEYFIRST) &&
556 (msg.message <= WM_KEYLAST) )
559 * When keyboard messages are sent to windows on this thread, we
560 * want to ignore notify the drop source that the state changed.
561 * in the case of the Escape key, we also notify the drop source
562 * we give it a special meaning.
564 if ( (msg.message==WM_KEYDOWN) &&
565 (msg.wParam==VK_ESCAPE) )
567 trackerInfo.escPressed = TRUE;
571 * Notify the drop source.
573 OLEDD_TrackStateChange(&trackerInfo,
575 OLEDD_GetButtonState());
580 * Dispatch the messages only when it's not a keyboard message.
582 DispatchMessageA(&msg);
587 * Destroy the temporary window.
589 DestroyWindow(hwndTrackWindow);
591 return trackerInfo.returnValue;
597 /***********************************************************************
598 * OleQueryLinkFromData [OLE32.118]
600 HRESULT WINAPI OleQueryLinkFromData(
601 IDataObject* pSrcDataObject)
603 FIXME("(%p),stub!\n", pSrcDataObject);
607 /***********************************************************************
608 * OleRegGetMiscStatus [OLE32.121]
610 HRESULT WINAPI OleRegGetMiscStatus(
622 * Initialize the out parameter.
627 * Build the key name we're looking for
629 sprintf( keyName, "CLSID\\{%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}\\",
630 clsid->Data1, clsid->Data2, clsid->Data3,
631 clsid->Data4[0], clsid->Data4[1], clsid->Data4[2], clsid->Data4[3],
632 clsid->Data4[4], clsid->Data4[5], clsid->Data4[6], clsid->Data4[7] );
634 TRACE("(%s, %ld, %p)\n", keyName, dwAspect, pdwStatus);
637 * Open the class id Key
639 result = RegOpenKeyA(HKEY_CLASSES_ROOT,
643 if (result != ERROR_SUCCESS)
644 return REGDB_E_CLASSNOTREG;
649 result = RegOpenKeyA(clsidKey,
654 if (result != ERROR_SUCCESS)
656 RegCloseKey(clsidKey);
657 return REGDB_E_READREGDB;
661 * Read the default value
663 OLEUTL_ReadRegistryDWORDValue(miscStatusKey, pdwStatus);
666 * Open the key specific to the requested aspect.
668 sprintf(keyName, "%ld", dwAspect);
670 result = RegOpenKeyA(miscStatusKey,
674 if (result == ERROR_SUCCESS)
676 OLEUTL_ReadRegistryDWORDValue(aspectKey, pdwStatus);
677 RegCloseKey(aspectKey);
683 RegCloseKey(miscStatusKey);
684 RegCloseKey(clsidKey);
689 /******************************************************************************
690 * OleSetContainedObject [OLE32.128]
692 HRESULT WINAPI OleSetContainedObject(
696 IRunnableObject* runnable = NULL;
699 TRACE("(%p,%x), stub!\n", pUnknown, fContained);
701 hres = IUnknown_QueryInterface(pUnknown,
702 &IID_IRunnableObject,
707 hres = IRunnableObject_SetContainedObject(runnable, fContained);
709 IRunnableObject_Release(runnable);
717 /******************************************************************************
718 * OleLoad [OLE32.112]
720 HRESULT WINAPI OleLoad(
723 LPOLECLIENTSITE pClientSite,
726 IPersistStorage* persistStorage = NULL;
727 IOleObject* oleObject = NULL;
731 TRACE("(%p,%p,%p,%p)\n", pStg, riid, pClientSite, ppvObj);
734 * TODO, Conversion ... OleDoAutoConvert
738 * Get the class ID for the object.
740 hres = IStorage_Stat(pStg, &storageInfo, STATFLAG_NONAME);
743 * Now, try and create the handler for the object
745 hres = CoCreateInstance(&storageInfo.clsid,
747 CLSCTX_INPROC_HANDLER,
752 * If that fails, as it will most times, load the default
757 hres = OleCreateDefaultHandler(&storageInfo.clsid,
764 * If we couldn't find a handler... this is bad. Abort the whole thing.
770 * Inform the new object of it's client site.
772 hres = IOleObject_SetClientSite(oleObject, pClientSite);
775 * Initialize the object with it's IPersistStorage interface.
777 hres = IOleObject_QueryInterface(oleObject,
778 &IID_IPersistStorage,
779 (void**)&persistStorage);
783 IPersistStorage_Load(persistStorage, pStg);
785 IPersistStorage_Release(persistStorage);
786 persistStorage = NULL;
790 * Return the requested interface to the caller.
792 hres = IOleObject_QueryInterface(oleObject, riid, ppvObj);
795 * Cleanup interfaces used internally
797 IOleObject_Release(oleObject);
802 /***********************************************************************
803 * OleSave [OLE32.124]
805 HRESULT WINAPI OleSave(
806 LPPERSISTSTORAGE pPS,
813 TRACE("(%p,%p,%x)\n", pPS, pStg, fSameAsLoad);
816 * First, we transfer the class ID (if available)
818 hres = IPersistStorage_GetClassID(pPS, &objectClass);
822 WriteClassStg(pStg, &objectClass);
826 * Then, we ask the object to save itself to the
827 * storage. If it is successful, we commit the storage.
829 hres = IPersistStorage_Save(pPS, pStg, fSameAsLoad);
833 IStorage_Commit(pStg,
841 /******************************************************************************
842 * OleLockRunning [OLE32.114]
844 HRESULT WINAPI OleLockRunning(LPUNKNOWN pUnknown, BOOL fLock, BOOL fLastUnlockCloses)
846 IRunnableObject* runnable = NULL;
849 TRACE("(%p,%x,%x)\n", pUnknown, fLock, fLastUnlockCloses);
851 hres = IUnknown_QueryInterface(pUnknown,
852 &IID_IRunnableObject,
857 hres = IRunnableObject_LockRunning(runnable, fLock, fLastUnlockCloses);
859 IRunnableObject_Release(runnable);
868 /**************************************************************************
869 * Internal methods to manage the shared OLE menu in response to the
870 * OLE***MenuDescriptor API
874 * OLEMenu_Initialize()
876 * Initializes the OLEMENU data structures.
878 static void OLEMenu_Initialize()
883 * OLEMenu_UnInitialize()
885 * Releases the OLEMENU data structures.
887 static void OLEMenu_UnInitialize()
891 /*************************************************************************
892 * OLEMenu_InstallHooks
893 * Install thread scope message hooks for WH_GETMESSAGE and WH_CALLWNDPROC
895 * RETURNS: TRUE if message hooks were succesfully installed
898 BOOL OLEMenu_InstallHooks( DWORD tid )
900 OleMenuHookItem *pHookItem = NULL;
902 /* Create an entry for the hook table */
903 if ( !(pHookItem = HeapAlloc(GetProcessHeap(), 0,
904 sizeof(OleMenuHookItem)) ) )
907 pHookItem->tid = tid;
908 pHookItem->hHeap = GetProcessHeap();
910 /* Install a thread scope message hook for WH_GETMESSAGE */
911 pHookItem->GetMsg_hHook = SetWindowsHookExA( WH_GETMESSAGE, OLEMenu_GetMsgProc,
912 0, GetCurrentThreadId() );
913 if ( !pHookItem->GetMsg_hHook )
916 /* Install a thread scope message hook for WH_CALLWNDPROC */
917 pHookItem->CallWndProc_hHook = SetWindowsHookExA( WH_CALLWNDPROC, OLEMenu_CallWndProc,
918 0, GetCurrentThreadId() );
919 if ( !pHookItem->CallWndProc_hHook )
922 /* Insert the hook table entry */
923 pHookItem->next = hook_list;
924 hook_list = pHookItem;
929 /* Unhook any hooks */
930 if ( pHookItem->GetMsg_hHook )
931 UnhookWindowsHookEx( pHookItem->GetMsg_hHook );
932 if ( pHookItem->CallWndProc_hHook )
933 UnhookWindowsHookEx( pHookItem->CallWndProc_hHook );
934 /* Release the hook table entry */
935 HeapFree(pHookItem->hHeap, 0, pHookItem );
940 /*************************************************************************
941 * OLEMenu_UnInstallHooks
942 * UnInstall thread scope message hooks for WH_GETMESSAGE and WH_CALLWNDPROC
944 * RETURNS: TRUE if message hooks were succesfully installed
947 BOOL OLEMenu_UnInstallHooks( DWORD tid )
949 OleMenuHookItem *pHookItem = NULL;
950 OleMenuHookItem **ppHook = &hook_list;
954 if ((*ppHook)->tid == tid)
957 *ppHook = pHookItem->next;
960 ppHook = &(*ppHook)->next;
962 if (!pHookItem) return FALSE;
964 /* Uninstall the hooks installed for this thread */
965 if ( !UnhookWindowsHookEx( pHookItem->GetMsg_hHook ) )
967 if ( !UnhookWindowsHookEx( pHookItem->CallWndProc_hHook ) )
970 /* Release the hook table entry */
971 HeapFree(pHookItem->hHeap, 0, pHookItem );
976 /* Release the hook table entry */
978 HeapFree(pHookItem->hHeap, 0, pHookItem );
983 /*************************************************************************
984 * OLEMenu_IsHookInstalled
985 * Tests if OLEMenu hooks have been installed for a thread
987 * RETURNS: The pointer and index of the hook table entry for the tid
988 * NULL and -1 for the index if no hooks were installed for this thread
990 OleMenuHookItem * OLEMenu_IsHookInstalled( DWORD tid )
992 OleMenuHookItem *pHookItem = NULL;
994 /* Do a simple linear search for an entry whose tid matches ours.
995 * We really need a map but efficiency is not a concern here. */
996 for (pHookItem = hook_list; pHookItem; pHookItem = pHookItem->next)
998 if ( tid == pHookItem->tid )
1005 /***********************************************************************
1006 * OLEMenu_FindMainMenuIndex
1008 * Used by OLEMenu API to find the top level group a menu item belongs to.
1009 * On success pnPos contains the index of the item in the top level menu group
1011 * RETURNS: TRUE if the ID was found, FALSE on failure
1013 static BOOL OLEMenu_FindMainMenuIndex( HMENU hMainMenu, HMENU hPopupMenu, UINT *pnPos )
1017 nItems = GetMenuItemCount( hMainMenu );
1019 for (i = 0; i < nItems; i++)
1023 /* Is the current item a submenu? */
1024 if ( (hsubmenu = GetSubMenu(hMainMenu, i)) )
1026 /* If the handle is the same we're done */
1027 if ( hsubmenu == hPopupMenu )
1033 /* Recursively search without updating pnPos */
1034 else if ( OLEMenu_FindMainMenuIndex( hsubmenu, hPopupMenu, NULL ) )
1046 /***********************************************************************
1047 * OLEMenu_SetIsServerMenu
1049 * Checks whether a popup menu belongs to a shared menu group which is
1050 * owned by the server, and sets the menu descriptor state accordingly.
1051 * All menu messages from these groups should be routed to the server.
1053 * RETURNS: TRUE if the popup menu is part of a server owned group
1054 * FASE if the popup menu is part of a container owned group
1056 BOOL OLEMenu_SetIsServerMenu( HMENU hmenu, OleMenuDescriptor *pOleMenuDescriptor )
1058 UINT nPos = 0, nWidth, i;
1060 pOleMenuDescriptor->bIsServerItem = FALSE;
1062 /* Don't bother searching if the popup is the combined menu itself */
1063 if ( hmenu == pOleMenuDescriptor->hmenuCombined )
1066 /* Find the menu item index in the shared OLE menu that this item belongs to */
1067 if ( !OLEMenu_FindMainMenuIndex( pOleMenuDescriptor->hmenuCombined, hmenu, &nPos ) )
1070 /* The group widths array has counts for the number of elements
1071 * in the groups File, Edit, Container, Object, Window, Help.
1072 * The Edit, Object & Help groups belong to the server object
1073 * and the other three belong to the container.
1074 * Loop through the group widths and locate the group we are a member of.
1076 for ( i = 0, nWidth = 0; i < 6; i++ )
1078 nWidth += pOleMenuDescriptor->mgw.width[i];
1079 if ( nPos < nWidth )
1081 /* Odd elements are server menu widths */
1082 pOleMenuDescriptor->bIsServerItem = (i%2) ? TRUE : FALSE;
1087 return pOleMenuDescriptor->bIsServerItem;
1090 /*************************************************************************
1091 * OLEMenu_CallWndProc
1092 * Thread scope WH_CALLWNDPROC hook proc filter function (callback)
1093 * This is invoked from a message hook installed in OleSetMenuDescriptor.
1095 LRESULT CALLBACK OLEMenu_CallWndProc(INT code, WPARAM wParam, LPARAM lParam)
1097 LPCWPSTRUCT pMsg = NULL;
1098 HOLEMENU hOleMenu = 0;
1099 OleMenuDescriptor *pOleMenuDescriptor = NULL;
1100 OleMenuHookItem *pHookItem = NULL;
1103 TRACE("%i, %04x, %08x\n", code, wParam, (unsigned)lParam );
1105 /* Check if we're being asked to process the message */
1106 if ( HC_ACTION != code )
1109 /* Retrieve the current message being dispatched from lParam */
1110 pMsg = (LPCWPSTRUCT)lParam;
1112 /* Check if the message is destined for a window we are interested in:
1113 * If the window has an OLEMenu property we may need to dispatch
1114 * the menu message to its active objects window instead. */
1116 hOleMenu = (HOLEMENU)GetPropA( pMsg->hwnd, "PROP_OLEMenuDescriptor" );
1120 /* Get the menu descriptor */
1121 pOleMenuDescriptor = (OleMenuDescriptor *) GlobalLock( hOleMenu );
1122 if ( !pOleMenuDescriptor ) /* Bad descriptor! */
1125 /* Process menu messages */
1126 switch( pMsg->message )
1130 /* Reset the menu descriptor state */
1131 pOleMenuDescriptor->bIsServerItem = FALSE;
1133 /* Send this message to the server as well */
1134 SendMessageA( pOleMenuDescriptor->hwndActiveObject,
1135 pMsg->message, pMsg->wParam, pMsg->lParam );
1139 case WM_INITMENUPOPUP:
1141 /* Save the state for whether this is a server owned menu */
1142 OLEMenu_SetIsServerMenu( (HMENU)pMsg->wParam, pOleMenuDescriptor );
1148 fuFlags = HIWORD(pMsg->wParam); /* Get flags */
1149 if ( fuFlags & MF_SYSMENU )
1152 /* Save the state for whether this is a server owned popup menu */
1153 else if ( fuFlags & MF_POPUP )
1154 OLEMenu_SetIsServerMenu( (HMENU)pMsg->lParam, pOleMenuDescriptor );
1161 LPDRAWITEMSTRUCT lpdis = (LPDRAWITEMSTRUCT) pMsg->lParam;
1162 if ( pMsg->wParam != 0 || lpdis->CtlType != ODT_MENU )
1163 goto NEXTHOOK; /* Not a menu message */
1172 /* If the message was for the server dispatch it accordingly */
1173 if ( pOleMenuDescriptor->bIsServerItem )
1175 SendMessageA( pOleMenuDescriptor->hwndActiveObject,
1176 pMsg->message, pMsg->wParam, pMsg->lParam );
1180 if ( pOleMenuDescriptor )
1181 GlobalUnlock( hOleMenu );
1183 /* Lookup the hook item for the current thread */
1184 if ( !( pHookItem = OLEMenu_IsHookInstalled( GetCurrentThreadId() ) ) )
1186 /* This should never fail!! */
1187 WARN("could not retrieve hHook for current thread!\n" );
1191 /* Pass on the message to the next hooker */
1192 return CallNextHookEx( pHookItem->CallWndProc_hHook, code, wParam, lParam );
1195 /*************************************************************************
1196 * OLEMenu_GetMsgProc
1197 * Thread scope WH_GETMESSAGE hook proc filter function (callback)
1198 * This is invoked from a message hook installed in OleSetMenuDescriptor.
1200 LRESULT CALLBACK OLEMenu_GetMsgProc(INT code, WPARAM wParam, LPARAM lParam)
1203 HOLEMENU hOleMenu = 0;
1204 OleMenuDescriptor *pOleMenuDescriptor = NULL;
1205 OleMenuHookItem *pHookItem = NULL;
1208 TRACE("%i, %04x, %08x\n", code, wParam, (unsigned)lParam );
1210 /* Check if we're being asked to process a messages */
1211 if ( HC_ACTION != code )
1214 /* Retrieve the current message being dispatched from lParam */
1215 pMsg = (LPMSG)lParam;
1217 /* Check if the message is destined for a window we are interested in:
1218 * If the window has an OLEMenu property we may need to dispatch
1219 * the menu message to its active objects window instead. */
1221 hOleMenu = (HOLEMENU)GetPropA( pMsg->hwnd, "PROP_OLEMenuDescriptor" );
1225 /* Process menu messages */
1226 switch( pMsg->message )
1230 wCode = HIWORD(pMsg->wParam); /* Get notification code */
1232 goto NEXTHOOK; /* Not a menu message */
1239 /* Get the menu descriptor */
1240 pOleMenuDescriptor = (OleMenuDescriptor *) GlobalLock( hOleMenu );
1241 if ( !pOleMenuDescriptor ) /* Bad descriptor! */
1244 /* If the message was for the server dispatch it accordingly */
1245 if ( pOleMenuDescriptor->bIsServerItem )
1247 /* Change the hWnd in the message to the active objects hWnd.
1248 * The message loop which reads this message will automatically
1249 * dispatch it to the embedded objects window. */
1250 pMsg->hwnd = pOleMenuDescriptor->hwndActiveObject;
1254 if ( pOleMenuDescriptor )
1255 GlobalUnlock( hOleMenu );
1257 /* Lookup the hook item for the current thread */
1258 if ( !( pHookItem = OLEMenu_IsHookInstalled( GetCurrentThreadId() ) ) )
1260 /* This should never fail!! */
1261 WARN("could not retrieve hHook for current thread!\n" );
1265 /* Pass on the message to the next hooker */
1266 return CallNextHookEx( pHookItem->GetMsg_hHook, code, wParam, lParam );
1269 /***********************************************************************
1270 * OleCreateMenuDescriptor [OLE32.97]
1271 * Creates an OLE menu descriptor for OLE to use when dispatching
1272 * menu messages and commands.
1275 * hmenuCombined - Handle to the objects combined menu
1276 * lpMenuWidths - Pointer to array of 6 LONG's indicating menus per group
1279 HOLEMENU WINAPI OleCreateMenuDescriptor(
1280 HMENU hmenuCombined,
1281 LPOLEMENUGROUPWIDTHS lpMenuWidths)
1284 OleMenuDescriptor *pOleMenuDescriptor;
1287 if ( !hmenuCombined || !lpMenuWidths )
1290 /* Create an OLE menu descriptor */
1291 if ( !(hOleMenu = GlobalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT,
1292 sizeof(OleMenuDescriptor) ) ) )
1295 pOleMenuDescriptor = (OleMenuDescriptor *) GlobalLock( hOleMenu );
1296 if ( !pOleMenuDescriptor )
1299 /* Initialize menu group widths and hmenu */
1300 for ( i = 0; i < 6; i++ )
1301 pOleMenuDescriptor->mgw.width[i] = lpMenuWidths->width[i];
1303 pOleMenuDescriptor->hmenuCombined = hmenuCombined;
1304 pOleMenuDescriptor->bIsServerItem = FALSE;
1305 GlobalUnlock( hOleMenu );
1310 /***********************************************************************
1311 * OleDestroyMenuDescriptor [OLE32.99]
1312 * Destroy the shared menu descriptor
1314 HRESULT WINAPI OleDestroyMenuDescriptor(
1315 HOLEMENU hmenuDescriptor)
1317 if ( hmenuDescriptor )
1318 GlobalFree( hmenuDescriptor );
1322 /***********************************************************************
1323 * OleSetMenuDescriptor [OLE32.129]
1324 * Installs or removes OLE dispatching code for the containers frame window
1325 * FIXME: The lpFrame and lpActiveObject parameters are currently ignored
1326 * OLE should install context sensitive help F1 filtering for the app when
1327 * these are non null.
1330 * hOleMenu Handle to composite menu descriptor
1331 * hwndFrame Handle to containers frame window
1332 * hwndActiveObject Handle to objects in-place activation window
1333 * lpFrame Pointer to IOleInPlaceFrame on containers window
1334 * lpActiveObject Pointer to IOleInPlaceActiveObject on active in-place object
1337 * S_OK - menu installed correctly
1338 * E_FAIL, E_INVALIDARG, E_UNEXPECTED - failure
1340 HRESULT WINAPI OleSetMenuDescriptor(
1343 HWND hwndActiveObject,
1344 LPOLEINPLACEFRAME lpFrame,
1345 LPOLEINPLACEACTIVEOBJECT lpActiveObject)
1347 OleMenuDescriptor *pOleMenuDescriptor = NULL;
1350 if ( !hwndFrame || (hOleMenu && !hwndActiveObject) )
1351 return E_INVALIDARG;
1353 if ( lpFrame || lpActiveObject )
1355 FIXME("(%x, %x, %x, %p, %p), Context sensitive help filtering not implemented!\n",
1356 (unsigned int)hOleMenu,
1363 /* Set up a message hook to intercept the containers frame window messages.
1364 * The message filter is responsible for dispatching menu messages from the
1365 * shared menu which are intended for the object.
1368 if ( hOleMenu ) /* Want to install dispatching code */
1370 /* If OLEMenu hooks are already installed for this thread, fail
1371 * Note: This effectively means that OleSetMenuDescriptor cannot
1372 * be called twice in succession on the same frame window
1373 * without first calling it with a null hOleMenu to uninstall */
1374 if ( OLEMenu_IsHookInstalled( GetCurrentThreadId() ) )
1377 /* Get the menu descriptor */
1378 pOleMenuDescriptor = (OleMenuDescriptor *) GlobalLock( hOleMenu );
1379 if ( !pOleMenuDescriptor )
1380 return E_UNEXPECTED;
1382 /* Update the menu descriptor */
1383 pOleMenuDescriptor->hwndFrame = hwndFrame;
1384 pOleMenuDescriptor->hwndActiveObject = hwndActiveObject;
1386 GlobalUnlock( hOleMenu );
1387 pOleMenuDescriptor = NULL;
1389 /* Add a menu descriptor windows property to the frame window */
1390 SetPropA( hwndFrame, "PROP_OLEMenuDescriptor", hOleMenu );
1392 /* Install thread scope message hooks for WH_GETMESSAGE and WH_CALLWNDPROC */
1393 if ( !OLEMenu_InstallHooks( GetCurrentThreadId() ) )
1396 else /* Want to uninstall dispatching code */
1398 /* Uninstall the hooks */
1399 if ( !OLEMenu_UnInstallHooks( GetCurrentThreadId() ) )
1402 /* Remove the menu descriptor property from the frame window */
1403 RemovePropA( hwndFrame, "PROP_OLEMenuDescriptor" );
1409 /******************************************************************************
1410 * IsAccelerator [OLE32.75]
1411 * Mostly copied from controls/menu.c TranslateAccelerator implementation
1413 BOOL WINAPI IsAccelerator(HACCEL hAccel, int cAccelEntries, LPMSG lpMsg, WORD* lpwCmd)
1416 LPACCEL16 lpAccelTbl;
1419 if(!lpMsg) return FALSE;
1420 if (!hAccel || !(lpAccelTbl = (LPACCEL16)LockResource16(hAccel)))
1422 WARN_(accel)("invalid accel handle=%04x\n", hAccel);
1425 if((lpMsg->message != WM_KEYDOWN &&
1426 lpMsg->message != WM_KEYUP &&
1427 lpMsg->message != WM_SYSKEYDOWN &&
1428 lpMsg->message != WM_SYSKEYUP &&
1429 lpMsg->message != WM_CHAR)) return FALSE;
1431 TRACE_(accel)("hAccel=%04x, cAccelEntries=%d,"
1432 "msg->hwnd=%04x, msg->message=%04x, wParam=%08x, lParam=%08lx\n",
1433 hAccel, cAccelEntries,
1434 lpMsg->hwnd, lpMsg->message, lpMsg->wParam, lpMsg->lParam);
1435 for(i = 0; i < cAccelEntries; i++)
1437 if(lpAccelTbl[i].key != lpMsg->wParam)
1440 if(lpMsg->message == WM_CHAR)
1442 if(!(lpAccelTbl[i].fVirt & FALT) && !(lpAccelTbl[i].fVirt & FVIRTKEY))
1444 TRACE_(accel)("found accel for WM_CHAR: ('%c')\n", lpMsg->wParam & 0xff);
1450 if(lpAccelTbl[i].fVirt & FVIRTKEY)
1453 TRACE_(accel)("found accel for virt_key %04x (scan %04x)\n",
1454 lpMsg->wParam, HIWORD(lpMsg->lParam) & 0xff);
1455 if(GetKeyState(VK_SHIFT) & 0x8000) mask |= FSHIFT;
1456 if(GetKeyState(VK_CONTROL) & 0x8000) mask |= FCONTROL;
1457 if(GetKeyState(VK_MENU) & 0x8000) mask |= FALT;
1458 if(mask == (lpAccelTbl[i].fVirt & (FSHIFT | FCONTROL | FALT))) goto found;
1459 TRACE_(accel)("incorrect SHIFT/CTRL/ALT-state\n");
1463 if(!(lpMsg->lParam & 0x01000000)) /* no special_key */
1465 if((lpAccelTbl[i].fVirt & FALT) && (lpMsg->lParam & 0x20000000))
1466 { /* ^^ ALT pressed */
1467 TRACE_(accel)("found accel for Alt-%c\n", lpMsg->wParam & 0xff);
1475 WARN_(accel)("couldn't translate accelerator key\n");
1479 if(lpwCmd) *lpwCmd = lpAccelTbl[i].cmd;
1483 /***********************************************************************
1484 * ReleaseStgMedium [OLE32.140]
1486 void WINAPI ReleaseStgMedium(
1489 switch (pmedium->tymed)
1493 if ( (pmedium->pUnkForRelease==0) &&
1494 (pmedium->u.hGlobal!=0) )
1495 GlobalFree(pmedium->u.hGlobal);
1497 pmedium->u.hGlobal = 0;
1502 if (pmedium->u.lpszFileName!=0)
1504 if (pmedium->pUnkForRelease==0)
1506 DeleteFileW(pmedium->u.lpszFileName);
1509 CoTaskMemFree(pmedium->u.lpszFileName);
1512 pmedium->u.lpszFileName = 0;
1517 if (pmedium->u.pstm!=0)
1519 IStream_Release(pmedium->u.pstm);
1522 pmedium->u.pstm = 0;
1525 case TYMED_ISTORAGE:
1527 if (pmedium->u.pstg!=0)
1529 IStorage_Release(pmedium->u.pstg);
1532 pmedium->u.pstg = 0;
1537 if ( (pmedium->pUnkForRelease==0) &&
1538 (pmedium->u.hGlobal!=0) )
1539 DeleteObject(pmedium->u.hGlobal);
1541 pmedium->u.hGlobal = 0;
1546 if ( (pmedium->pUnkForRelease==0) &&
1547 (pmedium->u.hMetaFilePict!=0) )
1549 LPMETAFILEPICT pMP = GlobalLock(pmedium->u.hGlobal);
1550 DeleteMetaFile(pMP->hMF);
1551 GlobalUnlock(pmedium->u.hGlobal);
1552 GlobalFree(pmedium->u.hGlobal);
1555 pmedium->u.hMetaFilePict = 0;
1560 if ( (pmedium->pUnkForRelease==0) &&
1561 (pmedium->u.hEnhMetaFile!=0) )
1563 DeleteEnhMetaFile(pmedium->u.hEnhMetaFile);
1566 pmedium->u.hEnhMetaFile = 0;
1575 * After cleaning up, the unknown is released
1577 if (pmedium->pUnkForRelease!=0)
1579 IUnknown_Release(pmedium->pUnkForRelease);
1580 pmedium->pUnkForRelease = 0;
1585 * OLEDD_Initialize()
1587 * Initializes the OLE drag and drop data structures.
1589 static void OLEDD_Initialize()
1593 ZeroMemory (&wndClass, sizeof(WNDCLASSA));
1594 wndClass.style = CS_GLOBALCLASS;
1595 wndClass.lpfnWndProc = (WNDPROC)OLEDD_DragTrackerWindowProc;
1596 wndClass.cbClsExtra = 0;
1597 wndClass.cbWndExtra = sizeof(TrackerWindowInfo*);
1598 wndClass.hCursor = 0;
1599 wndClass.hbrBackground = 0;
1600 wndClass.lpszClassName = OLEDD_DRAGTRACKERCLASS;
1602 RegisterClassA (&wndClass);
1606 * OLEDD_UnInitialize()
1608 * Releases the OLE drag and drop data structures.
1610 static void OLEDD_UnInitialize()
1613 * Simply empty the list.
1615 while (targetListHead!=NULL)
1617 RevokeDragDrop(targetListHead->hwndTarget);
1622 * OLEDD_InsertDropTarget()
1624 * Insert the target node in the tree.
1626 static void OLEDD_InsertDropTarget(DropTargetNode* nodeToAdd)
1628 DropTargetNode* curNode;
1629 DropTargetNode** parentNodeLink;
1632 * Iterate the tree to find the insertion point.
1634 curNode = targetListHead;
1635 parentNodeLink = &targetListHead;
1637 while (curNode!=NULL)
1639 if (nodeToAdd->hwndTarget<curNode->hwndTarget)
1642 * If the node we want to add has a smaller HWND, go left
1644 parentNodeLink = &curNode->prevDropTarget;
1645 curNode = curNode->prevDropTarget;
1647 else if (nodeToAdd->hwndTarget>curNode->hwndTarget)
1650 * If the node we want to add has a larger HWND, go right
1652 parentNodeLink = &curNode->nextDropTarget;
1653 curNode = curNode->nextDropTarget;
1658 * The item was found in the list. It shouldn't have been there
1666 * If we get here, we have found a spot for our item. The parentNodeLink
1667 * pointer points to the pointer that we have to modify.
1668 * The curNode should be NULL. We just have to establish the link and Voila!
1670 assert(curNode==NULL);
1671 assert(parentNodeLink!=NULL);
1672 assert(*parentNodeLink==NULL);
1674 *parentNodeLink=nodeToAdd;
1678 * OLEDD_ExtractDropTarget()
1680 * Removes the target node from the tree.
1682 static DropTargetNode* OLEDD_ExtractDropTarget(HWND hwndOfTarget)
1684 DropTargetNode* curNode;
1685 DropTargetNode** parentNodeLink;
1688 * Iterate the tree to find the insertion point.
1690 curNode = targetListHead;
1691 parentNodeLink = &targetListHead;
1693 while (curNode!=NULL)
1695 if (hwndOfTarget<curNode->hwndTarget)
1698 * If the node we want to add has a smaller HWND, go left
1700 parentNodeLink = &curNode->prevDropTarget;
1701 curNode = curNode->prevDropTarget;
1703 else if (hwndOfTarget>curNode->hwndTarget)
1706 * If the node we want to add has a larger HWND, go right
1708 parentNodeLink = &curNode->nextDropTarget;
1709 curNode = curNode->nextDropTarget;
1714 * The item was found in the list. Detach it from it's parent and
1715 * re-insert it's kids in the tree.
1717 assert(parentNodeLink!=NULL);
1718 assert(*parentNodeLink==curNode);
1721 * We arbitrately re-attach the left sub-tree to the parent.
1723 *parentNodeLink = curNode->prevDropTarget;
1726 * And we re-insert the right subtree
1728 if (curNode->nextDropTarget!=NULL)
1730 OLEDD_InsertDropTarget(curNode->nextDropTarget);
1734 * The node we found is still a valid node once we complete
1735 * the unlinking of the kids.
1737 curNode->nextDropTarget=NULL;
1738 curNode->prevDropTarget=NULL;
1745 * If we get here, the node is not in the tree
1751 * OLEDD_FindDropTarget()
1753 * Finds information about the drop target.
1755 static DropTargetNode* OLEDD_FindDropTarget(HWND hwndOfTarget)
1757 DropTargetNode* curNode;
1760 * Iterate the tree to find the HWND value.
1762 curNode = targetListHead;
1764 while (curNode!=NULL)
1766 if (hwndOfTarget<curNode->hwndTarget)
1769 * If the node we want to add has a smaller HWND, go left
1771 curNode = curNode->prevDropTarget;
1773 else if (hwndOfTarget>curNode->hwndTarget)
1776 * If the node we want to add has a larger HWND, go right
1778 curNode = curNode->nextDropTarget;
1783 * The item was found in the list.
1790 * If we get here, the item is not in the list
1796 * OLEDD_DragTrackerWindowProc()
1798 * This method is the WindowProcedure of the drag n drop tracking
1799 * window. During a drag n Drop operation, an invisible window is created
1800 * to receive the user input and act upon it. This procedure is in charge
1803 static LRESULT WINAPI OLEDD_DragTrackerWindowProc(
1813 LPCREATESTRUCTA createStruct = (LPCREATESTRUCTA)lParam;
1815 SetWindowLongA(hwnd, 0, (LONG)createStruct->lpCreateParams);
1822 TrackerWindowInfo* trackerInfo = (TrackerWindowInfo*)GetWindowLongA(hwnd, 0);
1826 * Get the current mouse position in screen coordinates.
1828 mousePos.x = LOWORD(lParam);
1829 mousePos.y = HIWORD(lParam);
1830 ClientToScreen(hwnd, &mousePos);
1833 * Track the movement of the mouse.
1835 OLEDD_TrackMouseMove(trackerInfo, mousePos, wParam);
1842 case WM_LBUTTONDOWN:
1843 case WM_MBUTTONDOWN:
1844 case WM_RBUTTONDOWN:
1846 TrackerWindowInfo* trackerInfo = (TrackerWindowInfo*)GetWindowLongA(hwnd, 0);
1850 * Get the current mouse position in screen coordinates.
1852 mousePos.x = LOWORD(lParam);
1853 mousePos.y = HIWORD(lParam);
1854 ClientToScreen(hwnd, &mousePos);
1857 * Notify everyone that the button state changed
1858 * TODO: Check if the "escape" key was pressed.
1860 OLEDD_TrackStateChange(trackerInfo, mousePos, wParam);
1867 * This is a window proc after all. Let's call the default.
1869 return DefWindowProcA (hwnd, uMsg, wParam, lParam);
1873 * OLEDD_TrackMouseMove()
1875 * This method is invoked while a drag and drop operation is in effect.
1876 * it will generate the appropriate callbacks in the drop source
1877 * and drop target. It will also provide the expected feedback to
1881 * trackerInfo - Pointer to the structure identifying the
1882 * drag & drop operation that is currently
1884 * mousePos - Current position of the mouse in screen
1886 * keyState - Contains the state of the shift keys and the
1887 * mouse buttons (MK_LBUTTON and the like)
1889 static void OLEDD_TrackMouseMove(
1890 TrackerWindowInfo* trackerInfo,
1894 HWND hwndNewTarget = 0;
1898 * Get the handle of the window under the mouse
1900 hwndNewTarget = WindowFromPoint(mousePos);
1903 * Every time, we re-initialize the effects passed to the
1904 * IDropTarget to the effects allowed by the source.
1906 *trackerInfo->pdwEffect = trackerInfo->dwOKEffect;
1909 * If we are hovering over the same target as before, send the
1910 * DragOver notification
1912 if ( (trackerInfo->curDragTarget != 0) &&
1913 (trackerInfo->curDragTargetHWND==hwndNewTarget) )
1915 POINTL mousePosParam;
1918 * The documentation tells me that the coordinate should be in the target
1919 * window's coordinate space. However, the tests I made tell me the
1920 * coordinates should be in screen coordinates.
1922 mousePosParam.x = mousePos.x;
1923 mousePosParam.y = mousePos.y;
1925 IDropTarget_DragOver(trackerInfo->curDragTarget,
1928 trackerInfo->pdwEffect);
1932 DropTargetNode* newDropTargetNode = 0;
1935 * If we changed window, we have to notify our old target and check for
1938 if (trackerInfo->curDragTarget!=0)
1940 IDropTarget_DragLeave(trackerInfo->curDragTarget);
1944 * Make sure we're hovering over a window.
1946 if (hwndNewTarget!=0)
1949 * Find-out if there is a drag target under the mouse
1951 HWND nexttar = hwndNewTarget;
1953 newDropTargetNode = OLEDD_FindDropTarget(nexttar);
1954 } while (!newDropTargetNode && (nexttar = GetParent(nexttar)) != 0);
1955 if(nexttar) hwndNewTarget = nexttar;
1957 trackerInfo->curDragTargetHWND = hwndNewTarget;
1958 trackerInfo->curDragTarget = newDropTargetNode ? newDropTargetNode->dropTarget : 0;
1961 * If there is, notify it that we just dragged-in
1963 if (trackerInfo->curDragTarget!=0)
1965 POINTL mousePosParam;
1968 * The documentation tells me that the coordinate should be in the target
1969 * window's coordinate space. However, the tests I made tell me the
1970 * coordinates should be in screen coordinates.
1972 mousePosParam.x = mousePos.x;
1973 mousePosParam.y = mousePos.y;
1975 IDropTarget_DragEnter(trackerInfo->curDragTarget,
1976 trackerInfo->dataObject,
1979 trackerInfo->pdwEffect);
1985 * The mouse is not over a window so we don't track anything.
1987 trackerInfo->curDragTargetHWND = 0;
1988 trackerInfo->curDragTarget = 0;
1993 * Now that we have done that, we have to tell the source to give
1994 * us feedback on the work being done by the target. If we don't
1995 * have a target, simulate no effect.
1997 if (trackerInfo->curDragTarget==0)
1999 *trackerInfo->pdwEffect = DROPEFFECT_NONE;
2002 hr = IDropSource_GiveFeedback(trackerInfo->dropSource,
2003 *trackerInfo->pdwEffect);
2006 * When we ask for feedback from the drop source, sometimes it will
2007 * do all the necessary work and sometimes it will not handle it
2008 * when that's the case, we must display the standard drag and drop
2011 if (hr==DRAGDROP_S_USEDEFAULTCURSORS)
2013 if (*trackerInfo->pdwEffect & DROPEFFECT_MOVE)
2015 SetCursor(LoadCursorA(OLE32_hInstance, MAKEINTRESOURCEA(1)));
2017 else if (*trackerInfo->pdwEffect & DROPEFFECT_COPY)
2019 SetCursor(LoadCursorA(OLE32_hInstance, MAKEINTRESOURCEA(2)));
2021 else if (*trackerInfo->pdwEffect & DROPEFFECT_LINK)
2023 SetCursor(LoadCursorA(OLE32_hInstance, MAKEINTRESOURCEA(3)));
2027 SetCursor(LoadCursorA(OLE32_hInstance, MAKEINTRESOURCEA(0)));
2033 * OLEDD_TrackStateChange()
2035 * This method is invoked while a drag and drop operation is in effect.
2036 * It is used to notify the drop target/drop source callbacks when
2037 * the state of the keyboard or mouse button change.
2040 * trackerInfo - Pointer to the structure identifying the
2041 * drag & drop operation that is currently
2043 * mousePos - Current position of the mouse in screen
2045 * keyState - Contains the state of the shift keys and the
2046 * mouse buttons (MK_LBUTTON and the like)
2048 static void OLEDD_TrackStateChange(
2049 TrackerWindowInfo* trackerInfo,
2054 * Ask the drop source what to do with the operation.
2056 trackerInfo->returnValue = IDropSource_QueryContinueDrag(
2057 trackerInfo->dropSource,
2058 trackerInfo->escPressed,
2062 * All the return valued will stop the operation except the S_OK
2065 if (trackerInfo->returnValue!=S_OK)
2068 * Make sure the message loop in DoDragDrop stops
2070 trackerInfo->trackingDone = TRUE;
2073 * Release the mouse in case the drop target decides to show a popup
2074 * or a menu or something.
2079 * If we end-up over a target, drop the object in the target or
2080 * inform the target that the operation was cancelled.
2082 if (trackerInfo->curDragTarget!=0)
2084 switch (trackerInfo->returnValue)
2087 * If the source wants us to complete the operation, we tell
2088 * the drop target that we just dropped the object in it.
2090 case DRAGDROP_S_DROP:
2092 POINTL mousePosParam;
2095 * The documentation tells me that the coordinate should be
2096 * in the target window's coordinate space. However, the tests
2097 * I made tell me the coordinates should be in screen coordinates.
2099 mousePosParam.x = mousePos.x;
2100 mousePosParam.y = mousePos.y;
2102 IDropTarget_Drop(trackerInfo->curDragTarget,
2103 trackerInfo->dataObject,
2106 trackerInfo->pdwEffect);
2110 * If the source told us that we should cancel, fool the drop
2111 * target by telling it that the mouse left it's window.
2112 * Also set the drop effect to "NONE" in case the application
2113 * ignores the result of DoDragDrop.
2115 case DRAGDROP_S_CANCEL:
2116 IDropTarget_DragLeave(trackerInfo->curDragTarget);
2117 *trackerInfo->pdwEffect = DROPEFFECT_NONE;
2125 * OLEDD_GetButtonState()
2127 * This method will use the current state of the keyboard to build
2128 * a button state mask equivalent to the one passed in the
2129 * WM_MOUSEMOVE wParam.
2131 static DWORD OLEDD_GetButtonState()
2133 BYTE keyboardState[256];
2136 GetKeyboardState(keyboardState);
2138 if ( (keyboardState[VK_SHIFT] & 0x80) !=0)
2139 keyMask |= MK_SHIFT;
2141 if ( (keyboardState[VK_CONTROL] & 0x80) !=0)
2142 keyMask |= MK_CONTROL;
2144 if ( (keyboardState[VK_LBUTTON] & 0x80) !=0)
2145 keyMask |= MK_LBUTTON;
2147 if ( (keyboardState[VK_RBUTTON] & 0x80) !=0)
2148 keyMask |= MK_RBUTTON;
2150 if ( (keyboardState[VK_MBUTTON] & 0x80) !=0)
2151 keyMask |= MK_MBUTTON;
2157 * OLEDD_GetButtonState()
2159 * This method will read the default value of the registry key in
2160 * parameter and extract a DWORD value from it. The registry key value
2161 * can be in a string key or a DWORD key.
2164 * regKey - Key to read the default value from
2165 * pdwValue - Pointer to the location where the DWORD
2166 * value is returned. This value is not modified
2167 * if the value is not found.
2170 static void OLEUTL_ReadRegistryDWORDValue(
2179 lres = RegQueryValueExA(regKey,
2186 if (lres==ERROR_SUCCESS)
2191 *pdwValue = *(DWORD*)buffer;
2196 *pdwValue = (DWORD)strtoul(buffer, NULL, 10);
2202 /******************************************************************************
2203 * OleMetaFilePictFromIconAndLabel (OLE2.56)
2205 * Returns a global memory handle to a metafile which contains the icon and
2207 * I guess the result of that should look somehow like desktop icons.
2208 * If no hIcon is given, we load the icon via lpszSourceFile and iIconIndex.
2209 * This code might be wrong at some places.
2211 HGLOBAL16 WINAPI OleMetaFilePictFromIconAndLabel16(
2213 LPCOLESTR16 lpszLabel,
2214 LPCOLESTR16 lpszSourceFile,
2221 FIXME("(%04x, '%s', '%s', %d): incorrect metrics, please try to correct them !\n\n\n", hIcon, lpszLabel, lpszSourceFile, iIconIndex);
2224 if (lpszSourceFile) {
2225 HINSTANCE16 hInstance = LoadLibrary16(lpszSourceFile);
2227 /* load the icon at index from lpszSourceFile */
2228 hIcon = (HICON16)LoadIconA(hInstance, (LPCSTR)(DWORD)iIconIndex);
2229 FreeLibrary16(hInstance);
2231 return (HGLOBAL)NULL;
2234 hdc = CreateMetaFile16(NULL);
2235 DrawIcon(hdc, 0, 0, hIcon); /* FIXME */
2236 TextOutA(hdc, 0, 0, lpszLabel, 1); /* FIXME */
2237 hmf = GlobalAlloc16(0, sizeof(METAFILEPICT16));
2238 mf = (METAFILEPICT16 *)GlobalLock16(hmf);
2239 mf->mm = MM_ANISOTROPIC;
2240 mf->xExt = 20; /* FIXME: bogus */
2241 mf->yExt = 20; /* dito */
2242 mf->hMF = CloseMetaFile16(hdc);
2246 /******************************************************************************
2247 * DllDebugObjectRPCHook (OLE32.62)
2248 * turns on and off internal debugging, pointer is only used on macintosh
2251 BOOL WINAPI DllDebugObjectRPCHook(BOOL b, void *dummy)