4 * Copyright 1995 Martin von Loewis
5 * Copyright 1999 Francis Beaudet
6 * Copyright 1999 Noel Borthwick
21 #include "wine/obj_clientserver.h"
22 #include "wine/winbase16.h"
23 #include "wine/wingdi16.h"
24 #include "debugtools.h"
27 #include "ole32_main.h"
29 DEFAULT_DEBUG_CHANNEL(ole);
31 /******************************************************************************
32 * These are static/global variables and internal data structures that the
33 * OLE module uses to maintain it's state.
35 typedef struct tagDropTargetNode
38 IDropTarget* dropTarget;
39 struct tagDropTargetNode* prevDropTarget;
40 struct tagDropTargetNode* nextDropTarget;
43 typedef struct tagTrackerWindowInfo
45 IDataObject* dataObject;
46 IDropSource* dropSource;
53 HWND curDragTargetHWND;
54 IDropTarget* curDragTarget;
57 typedef struct tagOleMenuDescriptor /* OleMenuDescriptor */
59 HWND hwndFrame; /* The containers frame window */
60 HWND hwndActiveObject; /* The active objects window */
61 OLEMENUGROUPWIDTHS mgw; /* OLE menu group widths for the shared menu */
62 HMENU hmenuCombined; /* The combined menu */
63 BOOL bIsServerItem; /* True if the currently open popup belongs to the server */
66 typedef struct tagOleMenuHookItem /* OleMenu hook item in per thread hook list */
68 DWORD tid; /* Thread Id */
69 HANDLE hHeap; /* Heap this is allocated from */
70 HHOOK GetMsg_hHook; /* message hook for WH_GETMESSAGE */
71 HHOOK CallWndProc_hHook; /* message hook for WH_CALLWNDPROC */
72 struct tagOleMenuHookItem *next;
75 static OleMenuHookItem *hook_list;
78 * This is the lock count on the OLE library. It is controlled by the
79 * OLEInitialize/OLEUninitialize methods.
81 static ULONG OLE_moduleLockCount = 0;
84 * Name of our registered window class.
86 static const char OLEDD_DRAGTRACKERCLASS[] = "WineDragDropTracker32";
89 * This is the head of the Drop target container.
91 static DropTargetNode* targetListHead = NULL;
93 /******************************************************************************
94 * These are the prototypes of miscelaneous utility methods
96 static void OLEUTL_ReadRegistryDWORDValue(HKEY regKey, DWORD* pdwValue);
98 /******************************************************************************
99 * These are the prototypes of the utility methods used to manage a shared menu
101 static void OLEMenu_Initialize();
102 static void OLEMenu_UnInitialize();
103 BOOL OLEMenu_InstallHooks( DWORD tid );
104 BOOL OLEMenu_UnInstallHooks( DWORD tid );
105 OleMenuHookItem * OLEMenu_IsHookInstalled( DWORD tid );
106 static BOOL OLEMenu_FindMainMenuIndex( HMENU hMainMenu, HMENU hPopupMenu, UINT *pnPos );
107 BOOL OLEMenu_SetIsServerMenu( HMENU hmenu, OleMenuDescriptor *pOleMenuDescriptor );
108 LRESULT CALLBACK OLEMenu_CallWndProc(INT code, WPARAM wParam, LPARAM lParam);
109 LRESULT CALLBACK OLEMenu_GetMsgProc(INT code, WPARAM wParam, LPARAM lParam);
111 /******************************************************************************
112 * These are the prototypes of the OLE Clipboard initialization methods (in clipboard.c)
114 void OLEClipbrd_UnInitialize();
115 void OLEClipbrd_Initialize();
117 /******************************************************************************
118 * These are the prototypes of the utility methods used for OLE Drag n Drop
120 static void OLEDD_Initialize();
121 static void OLEDD_UnInitialize();
122 static void OLEDD_InsertDropTarget(
123 DropTargetNode* nodeToAdd);
124 static DropTargetNode* OLEDD_ExtractDropTarget(
126 static DropTargetNode* OLEDD_FindDropTarget(
128 static LRESULT WINAPI OLEDD_DragTrackerWindowProc(
133 static void OLEDD_TrackMouseMove(
134 TrackerWindowInfo* trackerInfo,
137 static void OLEDD_TrackStateChange(
138 TrackerWindowInfo* trackerInfo,
141 static DWORD OLEDD_GetButtonState();
144 /******************************************************************************
145 * OleBuildVersion [OLE2.1]
147 DWORD WINAPI OleBuildVersion(void)
149 TRACE("Returning version %d, build %d.\n", rmm, rup);
150 return (rmm<<16)+rup;
153 /***********************************************************************
154 * OleInitialize (OLE2.2) (OLE32.108)
156 HRESULT WINAPI OleInitialize(LPVOID reserved)
160 TRACE("(%p)\n", reserved);
163 * The first duty of the OleInitialize is to initialize the COM libraries.
165 hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
168 * If the CoInitializeEx call failed, the OLE libraries can't be
175 * Then, it has to initialize the OLE specific modules.
179 * Object linking and Embedding
180 * In-place activation
182 if (OLE_moduleLockCount==0)
185 * Initialize the libraries.
187 TRACE("() - Initializing the OLE libraries\n");
192 OLEClipbrd_Initialize();
202 OLEMenu_Initialize();
206 * Then, we increase the lock count on the OLE module.
208 OLE_moduleLockCount++;
213 /******************************************************************************
214 * CoGetCurrentProcess [COMPOBJ.34] [OLE2.2][OLE32.108]
217 * Is DWORD really the correct return type for this function?
219 DWORD WINAPI CoGetCurrentProcess(void)
221 return GetCurrentProcessId();
224 /******************************************************************************
225 * OleUninitialize [OLE2.3] [OLE32.131]
227 void WINAPI OleUninitialize(void)
232 * Decrease the lock count on the OLE module.
234 OLE_moduleLockCount--;
237 * If we hit the bottom of the lock stack, free the libraries.
239 if (OLE_moduleLockCount==0)
242 * Actually free the libraries.
244 TRACE("() - Freeing the last reference count\n");
249 OLEClipbrd_UnInitialize();
254 OLEDD_UnInitialize();
259 OLEMenu_UnInitialize();
263 * Then, uninitialize the COM libraries.
268 /******************************************************************************
269 * CoRegisterMessageFilter [OLE32.38]
271 HRESULT WINAPI CoRegisterMessageFilter(
272 LPMESSAGEFILTER lpMessageFilter, /* Pointer to interface */
273 LPMESSAGEFILTER *lplpMessageFilter /* Indirect pointer to prior instance if non-NULL */
276 if (lplpMessageFilter) {
277 *lplpMessageFilter = NULL;
282 /******************************************************************************
283 * OleInitializeWOW [OLE32.109]
285 HRESULT WINAPI OleInitializeWOW(DWORD x) {
286 FIXME("(0x%08lx),stub!\n",x);
290 /***********************************************************************
291 * RegisterDragDrop16 (OLE2.35)
293 HRESULT WINAPI RegisterDragDrop16(
295 LPDROPTARGET pDropTarget
297 FIXME("(0x%04x,%p),stub!\n",hwnd,pDropTarget);
301 /***********************************************************************
302 * RegisterDragDrop (OLE32.139)
304 HRESULT WINAPI RegisterDragDrop(
306 LPDROPTARGET pDropTarget)
308 DropTargetNode* dropTargetInfo;
310 TRACE("(0x%x,%p)\n", hwnd, pDropTarget);
313 * First, check if the window is already registered.
315 dropTargetInfo = OLEDD_FindDropTarget(hwnd);
317 if (dropTargetInfo!=NULL)
318 return DRAGDROP_E_ALREADYREGISTERED;
321 * If it's not there, we can add it. We first create a node for it.
323 dropTargetInfo = HeapAlloc(GetProcessHeap(), 0, sizeof(DropTargetNode));
325 if (dropTargetInfo==NULL)
326 return E_OUTOFMEMORY;
328 dropTargetInfo->hwndTarget = hwnd;
329 dropTargetInfo->prevDropTarget = NULL;
330 dropTargetInfo->nextDropTarget = NULL;
333 * Don't forget that this is an interface pointer, need to nail it down since
334 * we keep a copy of it.
336 dropTargetInfo->dropTarget = pDropTarget;
337 IDropTarget_AddRef(dropTargetInfo->dropTarget);
339 OLEDD_InsertDropTarget(dropTargetInfo);
344 /***********************************************************************
345 * RevokeDragDrop16 (OLE2.36)
347 HRESULT WINAPI RevokeDragDrop16(
350 FIXME("(0x%04x),stub!\n",hwnd);
354 /***********************************************************************
355 * RevokeDragDrop (OLE32.141)
357 HRESULT WINAPI RevokeDragDrop(
360 DropTargetNode* dropTargetInfo;
362 TRACE("(0x%x)\n", hwnd);
365 * First, check if the window is already registered.
367 dropTargetInfo = OLEDD_ExtractDropTarget(hwnd);
370 * If it ain't in there, it's an error.
372 if (dropTargetInfo==NULL)
373 return DRAGDROP_E_NOTREGISTERED;
376 * If it's in there, clean-up it's used memory and
379 IDropTarget_Release(dropTargetInfo->dropTarget);
380 HeapFree(GetProcessHeap(), 0, dropTargetInfo);
385 /***********************************************************************
386 * OleRegGetUserType (OLE32.122)
388 * This implementation of OleRegGetUserType ignores the dwFormOfType
389 * parameter and always returns the full name of the object. This is
390 * not too bad since this is the case for many objects because of the
391 * way they are registered.
393 HRESULT WINAPI OleRegGetUserType(
396 LPOLESTR* pszUserType)
406 * Initialize the out parameter.
411 * Build the key name we're looking for
413 sprintf( keyName, "CLSID\\{%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}\\",
414 clsid->Data1, clsid->Data2, clsid->Data3,
415 clsid->Data4[0], clsid->Data4[1], clsid->Data4[2], clsid->Data4[3],
416 clsid->Data4[4], clsid->Data4[5], clsid->Data4[6], clsid->Data4[7] );
418 TRACE("(%s, %ld, %p)\n", keyName, dwFormOfType, pszUserType);
421 * Open the class id Key
423 hres = RegOpenKeyA(HKEY_CLASSES_ROOT,
427 if (hres != ERROR_SUCCESS)
428 return REGDB_E_CLASSNOTREG;
431 * Retrieve the size of the name string.
435 hres = RegQueryValueExA(clsidKey,
442 if (hres!=ERROR_SUCCESS)
444 RegCloseKey(clsidKey);
445 return REGDB_E_READREGDB;
449 * Allocate a buffer for the registry value.
451 *pszUserType = CoTaskMemAlloc(cbData*2);
453 if (*pszUserType==NULL)
455 RegCloseKey(clsidKey);
456 return E_OUTOFMEMORY;
459 buffer = HeapAlloc(GetProcessHeap(), 0, cbData);
463 RegCloseKey(clsidKey);
464 CoTaskMemFree(*pszUserType);
466 return E_OUTOFMEMORY;
469 hres = RegQueryValueExA(clsidKey,
476 RegCloseKey(clsidKey);
479 if (hres!=ERROR_SUCCESS)
481 CoTaskMemFree(*pszUserType);
484 retVal = REGDB_E_READREGDB;
488 MultiByteToWideChar( CP_ACP, 0, buffer, -1, *pszUserType, cbData /*FIXME*/ );
491 HeapFree(GetProcessHeap(), 0, buffer);
496 /***********************************************************************
497 * DoDragDrop [OLE32.65]
499 HRESULT WINAPI DoDragDrop (
500 IDataObject *pDataObject, /* ptr to the data obj */
501 IDropSource* pDropSource, /* ptr to the source obj */
502 DWORD dwOKEffect, /* effects allowed by the source */
503 DWORD *pdwEffect) /* ptr to effects of the source */
505 TrackerWindowInfo trackerInfo;
506 HWND hwndTrackWindow;
509 TRACE("(DataObject %p, DropSource %p)\n", pDataObject, pDropSource);
512 * Setup the drag n drop tracking window.
514 trackerInfo.dataObject = pDataObject;
515 trackerInfo.dropSource = pDropSource;
516 trackerInfo.dwOKEffect = dwOKEffect;
517 trackerInfo.pdwEffect = pdwEffect;
518 trackerInfo.trackingDone = FALSE;
519 trackerInfo.escPressed = FALSE;
520 trackerInfo.curDragTargetHWND = 0;
521 trackerInfo.curDragTarget = 0;
523 hwndTrackWindow = CreateWindowA(OLEDD_DRAGTRACKERCLASS,
526 CW_USEDEFAULT, CW_USEDEFAULT,
527 CW_USEDEFAULT, CW_USEDEFAULT,
531 (LPVOID)&trackerInfo);
533 if (hwndTrackWindow!=0)
536 * Capture the mouse input
538 SetCapture(hwndTrackWindow);
541 * Pump messages. All mouse input should go the the capture window.
543 while (!trackerInfo.trackingDone && GetMessageA(&msg, 0, 0, 0) )
545 if ( (msg.message >= WM_KEYFIRST) &&
546 (msg.message <= WM_KEYLAST) )
549 * When keyboard messages are sent to windows on this thread, we
550 * want to ignore notify the drop source that the state changed.
551 * in the case of the Escape key, we also notify the drop source
552 * we give it a special meaning.
554 if ( (msg.message==WM_KEYDOWN) &&
555 (msg.wParam==VK_ESCAPE) )
557 trackerInfo.escPressed = TRUE;
561 * Notify the drop source.
563 OLEDD_TrackStateChange(&trackerInfo,
565 OLEDD_GetButtonState());
570 * Dispatch the messages only when it's not a keyboard message.
572 DispatchMessageA(&msg);
577 * Destroy the temporary window.
579 DestroyWindow(hwndTrackWindow);
581 return trackerInfo.returnValue;
587 /***********************************************************************
588 * OleQueryLinkFromData [OLE32.118]
590 HRESULT WINAPI OleQueryLinkFromData(
591 IDataObject* pSrcDataObject)
593 FIXME("(%p),stub!\n", pSrcDataObject);
597 /***********************************************************************
598 * OleRegGetMiscStatus [OLE32.121]
600 HRESULT WINAPI OleRegGetMiscStatus(
612 * Initialize the out parameter.
617 * Build the key name we're looking for
619 sprintf( keyName, "CLSID\\{%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}\\",
620 clsid->Data1, clsid->Data2, clsid->Data3,
621 clsid->Data4[0], clsid->Data4[1], clsid->Data4[2], clsid->Data4[3],
622 clsid->Data4[4], clsid->Data4[5], clsid->Data4[6], clsid->Data4[7] );
624 TRACE("(%s, %ld, %p)\n", keyName, dwAspect, pdwStatus);
627 * Open the class id Key
629 result = RegOpenKeyA(HKEY_CLASSES_ROOT,
633 if (result != ERROR_SUCCESS)
634 return REGDB_E_CLASSNOTREG;
639 result = RegOpenKeyA(clsidKey,
644 if (result != ERROR_SUCCESS)
646 RegCloseKey(clsidKey);
647 return REGDB_E_READREGDB;
651 * Read the default value
653 OLEUTL_ReadRegistryDWORDValue(miscStatusKey, pdwStatus);
656 * Open the key specific to the requested aspect.
658 sprintf(keyName, "%ld", dwAspect);
660 result = RegOpenKeyA(miscStatusKey,
664 if (result == ERROR_SUCCESS)
666 OLEUTL_ReadRegistryDWORDValue(aspectKey, pdwStatus);
667 RegCloseKey(aspectKey);
673 RegCloseKey(miscStatusKey);
674 RegCloseKey(clsidKey);
679 /******************************************************************************
680 * OleSetContainedObject [OLE32.128]
682 HRESULT WINAPI OleSetContainedObject(
686 IRunnableObject* runnable = NULL;
689 TRACE("(%p,%x), stub!\n", pUnknown, fContained);
691 hres = IUnknown_QueryInterface(pUnknown,
692 &IID_IRunnableObject,
697 hres = IRunnableObject_SetContainedObject(runnable, fContained);
699 IRunnableObject_Release(runnable);
707 /******************************************************************************
708 * OleLoad [OLE32.112]
710 HRESULT WINAPI OleLoad(
713 LPOLECLIENTSITE pClientSite,
716 IPersistStorage* persistStorage = NULL;
717 IOleObject* oleObject = NULL;
721 TRACE("(%p,%p,%p,%p)\n", pStg, riid, pClientSite, ppvObj);
724 * TODO, Conversion ... OleDoAutoConvert
728 * Get the class ID for the object.
730 hres = IStorage_Stat(pStg, &storageInfo, STATFLAG_NONAME);
733 * Now, try and create the handler for the object
735 hres = CoCreateInstance(&storageInfo.clsid,
737 CLSCTX_INPROC_HANDLER,
742 * If that fails, as it will most times, load the default
747 hres = OleCreateDefaultHandler(&storageInfo.clsid,
754 * If we couldn't find a handler... this is bad. Abort the whole thing.
760 * Inform the new object of it's client site.
762 hres = IOleObject_SetClientSite(oleObject, pClientSite);
765 * Initialize the object with it's IPersistStorage interface.
767 hres = IOleObject_QueryInterface(oleObject,
768 &IID_IPersistStorage,
769 (void**)&persistStorage);
773 IPersistStorage_Load(persistStorage, pStg);
775 IPersistStorage_Release(persistStorage);
776 persistStorage = NULL;
780 * Return the requested interface to the caller.
782 hres = IOleObject_QueryInterface(oleObject, riid, ppvObj);
785 * Cleanup interfaces used internally
787 IOleObject_Release(oleObject);
792 /***********************************************************************
793 * OleSave [OLE32.124]
795 HRESULT WINAPI OleSave(
796 LPPERSISTSTORAGE pPS,
803 TRACE("(%p,%p,%x)\n", pPS, pStg, fSameAsLoad);
806 * First, we transfer the class ID (if available)
808 hres = IPersistStorage_GetClassID(pPS, &objectClass);
812 WriteClassStg(pStg, &objectClass);
816 * Then, we ask the object to save itself to the
817 * storage. If it is successful, we commit the storage.
819 hres = IPersistStorage_Save(pPS, pStg, fSameAsLoad);
823 IStorage_Commit(pStg,
831 /******************************************************************************
832 * OleLockRunning [OLE32.114]
834 HRESULT WINAPI OleLockRunning(LPUNKNOWN pUnknown, BOOL fLock, BOOL fLastUnlockCloses)
836 IRunnableObject* runnable = NULL;
839 TRACE("(%p,%x,%x)\n", pUnknown, fLock, fLastUnlockCloses);
841 hres = IUnknown_QueryInterface(pUnknown,
842 &IID_IRunnableObject,
847 hres = IRunnableObject_LockRunning(runnable, fLock, fLastUnlockCloses);
849 IRunnableObject_Release(runnable);
858 /**************************************************************************
859 * Internal methods to manage the shared OLE menu in response to the
860 * OLE***MenuDescriptor API
864 * OLEMenu_Initialize()
866 * Initializes the OLEMENU data structures.
868 static void OLEMenu_Initialize()
873 * OLEMenu_UnInitialize()
875 * Releases the OLEMENU data structures.
877 static void OLEMenu_UnInitialize()
881 /*************************************************************************
882 * OLEMenu_InstallHooks
883 * Install thread scope message hooks for WH_GETMESSAGE and WH_CALLWNDPROC
885 * RETURNS: TRUE if message hooks were succesfully installed
888 BOOL OLEMenu_InstallHooks( DWORD tid )
890 OleMenuHookItem *pHookItem = NULL;
892 /* Create an entry for the hook table */
893 if ( !(pHookItem = HeapAlloc(GetProcessHeap(), 0,
894 sizeof(OleMenuHookItem)) ) )
897 pHookItem->tid = tid;
898 pHookItem->hHeap = GetProcessHeap();
900 /* Install a thread scope message hook for WH_GETMESSAGE */
901 pHookItem->GetMsg_hHook = SetWindowsHookExA( WH_GETMESSAGE, OLEMenu_GetMsgProc,
902 0, GetCurrentThreadId() );
903 if ( !pHookItem->GetMsg_hHook )
906 /* Install a thread scope message hook for WH_CALLWNDPROC */
907 pHookItem->CallWndProc_hHook = SetWindowsHookExA( WH_CALLWNDPROC, OLEMenu_CallWndProc,
908 0, GetCurrentThreadId() );
909 if ( !pHookItem->CallWndProc_hHook )
912 /* Insert the hook table entry */
913 pHookItem->next = hook_list;
914 hook_list = pHookItem;
919 /* Unhook any hooks */
920 if ( pHookItem->GetMsg_hHook )
921 UnhookWindowsHookEx( pHookItem->GetMsg_hHook );
922 if ( pHookItem->CallWndProc_hHook )
923 UnhookWindowsHookEx( pHookItem->CallWndProc_hHook );
924 /* Release the hook table entry */
925 HeapFree(pHookItem->hHeap, 0, pHookItem );
930 /*************************************************************************
931 * OLEMenu_UnInstallHooks
932 * UnInstall thread scope message hooks for WH_GETMESSAGE and WH_CALLWNDPROC
934 * RETURNS: TRUE if message hooks were succesfully installed
937 BOOL OLEMenu_UnInstallHooks( DWORD tid )
939 OleMenuHookItem *pHookItem = NULL;
940 OleMenuHookItem **ppHook = &hook_list;
944 if ((*ppHook)->tid == tid)
947 *ppHook = pHookItem->next;
950 ppHook = &(*ppHook)->next;
952 if (!pHookItem) return FALSE;
954 /* Uninstall the hooks installed for this thread */
955 if ( !UnhookWindowsHookEx( pHookItem->GetMsg_hHook ) )
957 if ( !UnhookWindowsHookEx( pHookItem->CallWndProc_hHook ) )
960 /* Release the hook table entry */
961 HeapFree(pHookItem->hHeap, 0, pHookItem );
966 /* Release the hook table entry */
968 HeapFree(pHookItem->hHeap, 0, pHookItem );
973 /*************************************************************************
974 * OLEMenu_IsHookInstalled
975 * Tests if OLEMenu hooks have been installed for a thread
977 * RETURNS: The pointer and index of the hook table entry for the tid
978 * NULL and -1 for the index if no hooks were installed for this thread
980 OleMenuHookItem * OLEMenu_IsHookInstalled( DWORD tid )
982 OleMenuHookItem *pHookItem = NULL;
984 /* Do a simple linear search for an entry whose tid matches ours.
985 * We really need a map but efficiency is not a concern here. */
986 for (pHookItem = hook_list; pHookItem; pHookItem = pHookItem->next)
988 if ( tid == pHookItem->tid )
995 /***********************************************************************
996 * OLEMenu_FindMainMenuIndex
998 * Used by OLEMenu API to find the top level group a menu item belongs to.
999 * On success pnPos contains the index of the item in the top level menu group
1001 * RETURNS: TRUE if the ID was found, FALSE on failure
1003 static BOOL OLEMenu_FindMainMenuIndex( HMENU hMainMenu, HMENU hPopupMenu, UINT *pnPos )
1007 nItems = GetMenuItemCount( hMainMenu );
1009 for (i = 0; i < nItems; i++)
1013 /* Is the current item a submenu? */
1014 if ( (hsubmenu = GetSubMenu(hMainMenu, i)) )
1016 /* If the handle is the same we're done */
1017 if ( hsubmenu == hPopupMenu )
1023 /* Recursively search without updating pnPos */
1024 else if ( OLEMenu_FindMainMenuIndex( hsubmenu, hPopupMenu, NULL ) )
1036 /***********************************************************************
1037 * OLEMenu_SetIsServerMenu
1039 * Checks whether a popup menu belongs to a shared menu group which is
1040 * owned by the server, and sets the menu descriptor state accordingly.
1041 * All menu messages from these groups should be routed to the server.
1043 * RETURNS: TRUE if the popup menu is part of a server owned group
1044 * FASE if the popup menu is part of a container owned group
1046 BOOL OLEMenu_SetIsServerMenu( HMENU hmenu, OleMenuDescriptor *pOleMenuDescriptor )
1048 UINT nPos = 0, nWidth, i;
1050 pOleMenuDescriptor->bIsServerItem = FALSE;
1052 /* Don't bother searching if the popup is the combined menu itself */
1053 if ( hmenu == pOleMenuDescriptor->hmenuCombined )
1056 /* Find the menu item index in the shared OLE menu that this item belongs to */
1057 if ( !OLEMenu_FindMainMenuIndex( pOleMenuDescriptor->hmenuCombined, hmenu, &nPos ) )
1060 /* The group widths array has counts for the number of elements
1061 * in the groups File, Edit, Container, Object, Window, Help.
1062 * The Edit, Object & Help groups belong to the server object
1063 * and the other three belong to the container.
1064 * Loop thru the group widths and locate the group we are a member of.
1066 for ( i = 0, nWidth = 0; i < 6; i++ )
1068 nWidth += pOleMenuDescriptor->mgw.width[i];
1069 if ( nPos < nWidth )
1071 /* Odd elements are server menu widths */
1072 pOleMenuDescriptor->bIsServerItem = (i%2) ? TRUE : FALSE;
1077 return pOleMenuDescriptor->bIsServerItem;
1080 /*************************************************************************
1081 * OLEMenu_CallWndProc
1082 * Thread scope WH_CALLWNDPROC hook proc filter function (callback)
1083 * This is invoked from a message hook installed in OleSetMenuDescriptor.
1085 LRESULT CALLBACK OLEMenu_CallWndProc(INT code, WPARAM wParam, LPARAM lParam)
1087 LPCWPSTRUCT pMsg = NULL;
1088 HOLEMENU hOleMenu = 0;
1089 OleMenuDescriptor *pOleMenuDescriptor = NULL;
1090 OleMenuHookItem *pHookItem = NULL;
1093 TRACE("%i, %04x, %08x\n", code, wParam, (unsigned)lParam );
1095 /* Check if we're being asked to process the message */
1096 if ( HC_ACTION != code )
1099 /* Retrieve the current message being dispatched from lParam */
1100 pMsg = (LPCWPSTRUCT)lParam;
1102 /* Check if the message is destined for a window we are interested in:
1103 * If the window has an OLEMenu property we may need to dispatch
1104 * the menu message to its active objects window instead. */
1106 hOleMenu = (HOLEMENU)GetPropA( pMsg->hwnd, "PROP_OLEMenuDescriptor" );
1110 /* Get the menu descriptor */
1111 pOleMenuDescriptor = (OleMenuDescriptor *) GlobalLock( hOleMenu );
1112 if ( !pOleMenuDescriptor ) /* Bad descriptor! */
1115 /* Process menu messages */
1116 switch( pMsg->message )
1120 /* Reset the menu descriptor state */
1121 pOleMenuDescriptor->bIsServerItem = FALSE;
1123 /* Send this message to the server as well */
1124 SendMessageA( pOleMenuDescriptor->hwndActiveObject,
1125 pMsg->message, pMsg->wParam, pMsg->lParam );
1129 case WM_INITMENUPOPUP:
1131 /* Save the state for whether this is a server owned menu */
1132 OLEMenu_SetIsServerMenu( (HMENU)pMsg->wParam, pOleMenuDescriptor );
1138 fuFlags = HIWORD(pMsg->wParam); /* Get flags */
1139 if ( fuFlags & MF_SYSMENU )
1142 /* Save the state for whether this is a server owned popup menu */
1143 else if ( fuFlags & MF_POPUP )
1144 OLEMenu_SetIsServerMenu( (HMENU)pMsg->lParam, pOleMenuDescriptor );
1151 LPDRAWITEMSTRUCT lpdis = (LPDRAWITEMSTRUCT) pMsg->lParam;
1152 if ( pMsg->wParam != 0 || lpdis->CtlType != ODT_MENU )
1153 goto NEXTHOOK; /* Not a menu message */
1162 /* If the message was for the server dispatch it accordingly */
1163 if ( pOleMenuDescriptor->bIsServerItem )
1165 SendMessageA( pOleMenuDescriptor->hwndActiveObject,
1166 pMsg->message, pMsg->wParam, pMsg->lParam );
1170 if ( pOleMenuDescriptor )
1171 GlobalUnlock( hOleMenu );
1173 /* Lookup the hook item for the current thread */
1174 if ( !( pHookItem = OLEMenu_IsHookInstalled( GetCurrentThreadId() ) ) )
1176 /* This should never fail!! */
1177 WARN("could not retrieve hHook for current thread!\n" );
1181 /* Pass on the message to the next hooker */
1182 return CallNextHookEx( pHookItem->CallWndProc_hHook, code, wParam, lParam );
1185 /*************************************************************************
1186 * OLEMenu_GetMsgProc
1187 * Thread scope WH_GETMESSAGE hook proc filter function (callback)
1188 * This is invoked from a message hook installed in OleSetMenuDescriptor.
1190 LRESULT CALLBACK OLEMenu_GetMsgProc(INT code, WPARAM wParam, LPARAM lParam)
1193 HOLEMENU hOleMenu = 0;
1194 OleMenuDescriptor *pOleMenuDescriptor = NULL;
1195 OleMenuHookItem *pHookItem = NULL;
1198 TRACE("%i, %04x, %08x\n", code, wParam, (unsigned)lParam );
1200 /* Check if we're being asked to process a messages */
1201 if ( HC_ACTION != code )
1204 /* Retrieve the current message being dispatched from lParam */
1205 pMsg = (LPMSG)lParam;
1207 /* Check if the message is destined for a window we are interested in:
1208 * If the window has an OLEMenu property we may need to dispatch
1209 * the menu message to its active objects window instead. */
1211 hOleMenu = (HOLEMENU)GetPropA( pMsg->hwnd, "PROP_OLEMenuDescriptor" );
1215 /* Process menu messages */
1216 switch( pMsg->message )
1220 wCode = HIWORD(pMsg->wParam); /* Get notification code */
1222 goto NEXTHOOK; /* Not a menu message */
1229 /* Get the menu descriptor */
1230 pOleMenuDescriptor = (OleMenuDescriptor *) GlobalLock( hOleMenu );
1231 if ( !pOleMenuDescriptor ) /* Bad descriptor! */
1234 /* If the message was for the server dispatch it accordingly */
1235 if ( pOleMenuDescriptor->bIsServerItem )
1237 /* Change the hWnd in the message to the active objects hWnd.
1238 * The message loop which reads this message will automatically
1239 * dispatch it to the embedded objects window. */
1240 pMsg->hwnd = pOleMenuDescriptor->hwndActiveObject;
1244 if ( pOleMenuDescriptor )
1245 GlobalUnlock( hOleMenu );
1247 /* Lookup the hook item for the current thread */
1248 if ( !( pHookItem = OLEMenu_IsHookInstalled( GetCurrentThreadId() ) ) )
1250 /* This should never fail!! */
1251 WARN("could not retrieve hHook for current thread!\n" );
1255 /* Pass on the message to the next hooker */
1256 return CallNextHookEx( pHookItem->GetMsg_hHook, code, wParam, lParam );
1259 /***********************************************************************
1260 * OleCreateMenuDescriptor [OLE32.97]
1261 * Creates an OLE menu descriptor for OLE to use when dispatching
1262 * menu messages and commands.
1265 * hmenuCombined - Handle to the objects combined menu
1266 * lpMenuWidths - Pointer to array of 6 LONG's indicating menus per group
1269 HOLEMENU WINAPI OleCreateMenuDescriptor(
1270 HMENU hmenuCombined,
1271 LPOLEMENUGROUPWIDTHS lpMenuWidths)
1274 OleMenuDescriptor *pOleMenuDescriptor;
1277 if ( !hmenuCombined || !lpMenuWidths )
1280 /* Create an OLE menu descriptor */
1281 if ( !(hOleMenu = GlobalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT,
1282 sizeof(OleMenuDescriptor) ) ) )
1285 pOleMenuDescriptor = (OleMenuDescriptor *) GlobalLock( hOleMenu );
1286 if ( !pOleMenuDescriptor )
1289 /* Initialize menu group widths and hmenu */
1290 for ( i = 0; i < 6; i++ )
1291 pOleMenuDescriptor->mgw.width[i] = lpMenuWidths->width[i];
1293 pOleMenuDescriptor->hmenuCombined = hmenuCombined;
1294 pOleMenuDescriptor->bIsServerItem = FALSE;
1295 GlobalUnlock( hOleMenu );
1300 /***********************************************************************
1301 * OleDestroyMenuDescriptor [OLE32.99]
1302 * Destroy the shared menu descriptor
1304 HRESULT WINAPI OleDestroyMenuDescriptor(
1305 HOLEMENU hmenuDescriptor)
1307 if ( hmenuDescriptor )
1308 GlobalFree( hmenuDescriptor );
1312 /***********************************************************************
1313 * OleSetMenuDescriptor [OLE32.129]
1314 * Installs or removes OLE dispatching code for the containers frame window
1315 * FIXME: The lpFrame and lpActiveObject parameters are currently ignored
1316 * OLE should install context sensitive help F1 filtering for the app when
1317 * these are non null.
1320 * hOleMenu Handle to composite menu descriptor
1321 * hwndFrame Handle to containers frame window
1322 * hwndActiveObject Handle to objects in-place activation window
1323 * lpFrame Pointer to IOleInPlaceFrame on containers window
1324 * lpActiveObject Pointer to IOleInPlaceActiveObject on active in-place object
1327 * S_OK - menu installed correctly
1328 * E_FAIL, E_INVALIDARG, E_UNEXPECTED - failure
1330 HRESULT WINAPI OleSetMenuDescriptor(
1333 HWND hwndActiveObject,
1334 LPOLEINPLACEFRAME lpFrame,
1335 LPOLEINPLACEACTIVEOBJECT lpActiveObject)
1337 OleMenuDescriptor *pOleMenuDescriptor = NULL;
1340 if ( !hwndFrame || (hOleMenu && !hwndActiveObject) )
1341 return E_INVALIDARG;
1343 if ( lpFrame || lpActiveObject )
1345 FIXME("(%x, %x, %x, %p, %p), Context sensitive help filtering not implemented!\n",
1346 (unsigned int)hOleMenu,
1353 /* Set up a message hook to intercept the containers frame window messages.
1354 * The message filter is responsible for dispatching menu messages from the
1355 * shared menu which are intended for the object.
1358 if ( hOleMenu ) /* Want to install dispatching code */
1360 /* If OLEMenu hooks are already installed for this thread, fail
1361 * Note: This effectively means that OleSetMenuDescriptor cannot
1362 * be called twice in succession on the same frame window
1363 * without first calling it with a null hOleMenu to uninstall */
1364 if ( OLEMenu_IsHookInstalled( GetCurrentThreadId() ) )
1367 /* Get the menu descriptor */
1368 pOleMenuDescriptor = (OleMenuDescriptor *) GlobalLock( hOleMenu );
1369 if ( !pOleMenuDescriptor )
1370 return E_UNEXPECTED;
1372 /* Update the menu descriptor */
1373 pOleMenuDescriptor->hwndFrame = hwndFrame;
1374 pOleMenuDescriptor->hwndActiveObject = hwndActiveObject;
1376 GlobalUnlock( hOleMenu );
1377 pOleMenuDescriptor = NULL;
1379 /* Add a menu descriptor windows property to the frame window */
1380 SetPropA( hwndFrame, "PROP_OLEMenuDescriptor", hOleMenu );
1382 /* Install thread scope message hooks for WH_GETMESSAGE and WH_CALLWNDPROC */
1383 if ( !OLEMenu_InstallHooks( GetCurrentThreadId() ) )
1386 else /* Want to uninstall dispatching code */
1388 /* Uninstall the hooks */
1389 if ( !OLEMenu_UnInstallHooks( GetCurrentThreadId() ) )
1392 /* Remove the menu descriptor property from the frame window */
1393 RemovePropA( hwndFrame, "PROP_OLEMenuDescriptor" );
1399 /***********************************************************************
1400 * ReleaseStgMedium [OLE32.140]
1402 void WINAPI ReleaseStgMedium(
1405 switch (pmedium->tymed)
1409 if ( (pmedium->pUnkForRelease==0) &&
1410 (pmedium->u.hGlobal!=0) )
1411 GlobalFree(pmedium->u.hGlobal);
1413 pmedium->u.hGlobal = 0;
1418 if (pmedium->u.lpszFileName!=0)
1420 if (pmedium->pUnkForRelease==0)
1422 DeleteFileW(pmedium->u.lpszFileName);
1425 CoTaskMemFree(pmedium->u.lpszFileName);
1428 pmedium->u.lpszFileName = 0;
1433 if (pmedium->u.pstm!=0)
1435 IStream_Release(pmedium->u.pstm);
1438 pmedium->u.pstm = 0;
1441 case TYMED_ISTORAGE:
1443 if (pmedium->u.pstg!=0)
1445 IStorage_Release(pmedium->u.pstg);
1448 pmedium->u.pstg = 0;
1453 if ( (pmedium->pUnkForRelease==0) &&
1454 (pmedium->u.hGlobal!=0) )
1455 DeleteObject(pmedium->u.hGlobal);
1457 pmedium->u.hGlobal = 0;
1462 if ( (pmedium->pUnkForRelease==0) &&
1463 (pmedium->u.hMetaFilePict!=0) )
1465 DeleteMetaFile(pmedium->u.hMetaFilePict);
1466 GlobalFree(pmedium->u.hMetaFilePict);
1469 pmedium->u.hMetaFilePict = 0;
1474 if ( (pmedium->pUnkForRelease==0) &&
1475 (pmedium->u.hEnhMetaFile!=0) )
1477 DeleteEnhMetaFile(pmedium->u.hEnhMetaFile);
1480 pmedium->u.hEnhMetaFile = 0;
1489 * After cleaning up, the unknown is released
1491 if (pmedium->pUnkForRelease!=0)
1493 IUnknown_Release(pmedium->pUnkForRelease);
1494 pmedium->pUnkForRelease = 0;
1499 * OLEDD_Initialize()
1501 * Initializes the OLE drag and drop data structures.
1503 static void OLEDD_Initialize()
1507 ZeroMemory (&wndClass, sizeof(WNDCLASSA));
1508 wndClass.style = CS_GLOBALCLASS;
1509 wndClass.lpfnWndProc = (WNDPROC)OLEDD_DragTrackerWindowProc;
1510 wndClass.cbClsExtra = 0;
1511 wndClass.cbWndExtra = sizeof(TrackerWindowInfo*);
1512 wndClass.hCursor = 0;
1513 wndClass.hbrBackground = 0;
1514 wndClass.lpszClassName = OLEDD_DRAGTRACKERCLASS;
1516 RegisterClassA (&wndClass);
1520 * OLEDD_UnInitialize()
1522 * Releases the OLE drag and drop data structures.
1524 static void OLEDD_UnInitialize()
1527 * Simply empty the list.
1529 while (targetListHead!=NULL)
1531 RevokeDragDrop(targetListHead->hwndTarget);
1536 * OLEDD_InsertDropTarget()
1538 * Insert the target node in the tree.
1540 static void OLEDD_InsertDropTarget(DropTargetNode* nodeToAdd)
1542 DropTargetNode* curNode;
1543 DropTargetNode** parentNodeLink;
1546 * Iterate the tree to find the insertion point.
1548 curNode = targetListHead;
1549 parentNodeLink = &targetListHead;
1551 while (curNode!=NULL)
1553 if (nodeToAdd->hwndTarget<curNode->hwndTarget)
1556 * If the node we want to add has a smaller HWND, go left
1558 parentNodeLink = &curNode->prevDropTarget;
1559 curNode = curNode->prevDropTarget;
1561 else if (nodeToAdd->hwndTarget>curNode->hwndTarget)
1564 * If the node we want to add has a larger HWND, go right
1566 parentNodeLink = &curNode->nextDropTarget;
1567 curNode = curNode->nextDropTarget;
1572 * The item was found in the list. It shouldn't have been there
1580 * If we get here, we have found a spot for our item. The parentNodeLink
1581 * pointer points to the pointer that we have to modify.
1582 * The curNode should be NULL. We just have to establish the link and Voila!
1584 assert(curNode==NULL);
1585 assert(parentNodeLink!=NULL);
1586 assert(*parentNodeLink==NULL);
1588 *parentNodeLink=nodeToAdd;
1592 * OLEDD_ExtractDropTarget()
1594 * Removes the target node from the tree.
1596 static DropTargetNode* OLEDD_ExtractDropTarget(HWND hwndOfTarget)
1598 DropTargetNode* curNode;
1599 DropTargetNode** parentNodeLink;
1602 * Iterate the tree to find the insertion point.
1604 curNode = targetListHead;
1605 parentNodeLink = &targetListHead;
1607 while (curNode!=NULL)
1609 if (hwndOfTarget<curNode->hwndTarget)
1612 * If the node we want to add has a smaller HWND, go left
1614 parentNodeLink = &curNode->prevDropTarget;
1615 curNode = curNode->prevDropTarget;
1617 else if (hwndOfTarget>curNode->hwndTarget)
1620 * If the node we want to add has a larger HWND, go right
1622 parentNodeLink = &curNode->nextDropTarget;
1623 curNode = curNode->nextDropTarget;
1628 * The item was found in the list. Detach it from it's parent and
1629 * re-insert it's kids in the tree.
1631 assert(parentNodeLink!=NULL);
1632 assert(*parentNodeLink==curNode);
1635 * We arbitrately re-attach the left sub-tree to the parent.
1637 *parentNodeLink = curNode->prevDropTarget;
1640 * And we re-insert the right subtree
1642 if (curNode->nextDropTarget!=NULL)
1644 OLEDD_InsertDropTarget(curNode->nextDropTarget);
1648 * The node we found is still a valid node once we complete
1649 * the unlinking of the kids.
1651 curNode->nextDropTarget=NULL;
1652 curNode->prevDropTarget=NULL;
1659 * If we get here, the node is not in the tree
1665 * OLEDD_FindDropTarget()
1667 * Finds information about the drop target.
1669 static DropTargetNode* OLEDD_FindDropTarget(HWND hwndOfTarget)
1671 DropTargetNode* curNode;
1674 * Iterate the tree to find the HWND value.
1676 curNode = targetListHead;
1678 while (curNode!=NULL)
1680 if (hwndOfTarget<curNode->hwndTarget)
1683 * If the node we want to add has a smaller HWND, go left
1685 curNode = curNode->prevDropTarget;
1687 else if (hwndOfTarget>curNode->hwndTarget)
1690 * If the node we want to add has a larger HWND, go right
1692 curNode = curNode->nextDropTarget;
1697 * The item was found in the list.
1704 * If we get here, the item is not in the list
1710 * OLEDD_DragTrackerWindowProc()
1712 * This method is the WindowProcedure of the drag n drop tracking
1713 * window. During a drag n Drop operation, an invisible window is created
1714 * to receive the user input and act upon it. This procedure is in charge
1717 static LRESULT WINAPI OLEDD_DragTrackerWindowProc(
1727 LPCREATESTRUCTA createStruct = (LPCREATESTRUCTA)lParam;
1729 SetWindowLongA(hwnd, 0, (LONG)createStruct->lpCreateParams);
1736 TrackerWindowInfo* trackerInfo = (TrackerWindowInfo*)GetWindowLongA(hwnd, 0);
1740 * Get the current mouse position in screen coordinates.
1742 mousePos.x = LOWORD(lParam);
1743 mousePos.y = HIWORD(lParam);
1744 ClientToScreen(hwnd, &mousePos);
1747 * Track the movement of the mouse.
1749 OLEDD_TrackMouseMove(trackerInfo, mousePos, wParam);
1756 case WM_LBUTTONDOWN:
1757 case WM_MBUTTONDOWN:
1758 case WM_RBUTTONDOWN:
1760 TrackerWindowInfo* trackerInfo = (TrackerWindowInfo*)GetWindowLongA(hwnd, 0);
1764 * Get the current mouse position in screen coordinates.
1766 mousePos.x = LOWORD(lParam);
1767 mousePos.y = HIWORD(lParam);
1768 ClientToScreen(hwnd, &mousePos);
1771 * Notify everyone that the button state changed
1772 * TODO: Check if the "escape" key was pressed.
1774 OLEDD_TrackStateChange(trackerInfo, mousePos, wParam);
1781 * This is a window proc after all. Let's call the default.
1783 return DefWindowProcA (hwnd, uMsg, wParam, lParam);
1787 * OLEDD_TrackMouseMove()
1789 * This method is invoked while a drag and drop operation is in effect.
1790 * it will generate the appropriate callbacks in the drop source
1791 * and drop target. It will also provide the expected feedback to
1795 * trackerInfo - Pointer to the structure identifying the
1796 * drag & drop operation that is currently
1798 * mousePos - Current position of the mouse in screen
1800 * keyState - Contains the state of the shift keys and the
1801 * mouse buttons (MK_LBUTTON and the like)
1803 static void OLEDD_TrackMouseMove(
1804 TrackerWindowInfo* trackerInfo,
1808 HWND hwndNewTarget = 0;
1812 * Get the handle of the window under the mouse
1814 hwndNewTarget = WindowFromPoint(mousePos);
1817 * Every time, we re-initialize the effects passed to the
1818 * IDropTarget to the effects allowed by the source.
1820 *trackerInfo->pdwEffect = trackerInfo->dwOKEffect;
1823 * If we are hovering over the same target as before, send the
1824 * DragOver notification
1826 if ( (trackerInfo->curDragTarget != 0) &&
1827 (trackerInfo->curDragTargetHWND==hwndNewTarget) )
1829 POINTL mousePosParam;
1832 * The documentation tells me that the coordinate should be in the target
1833 * window's coordinate space. However, the tests I made tell me the
1834 * coordinates should be in screen coordinates.
1836 mousePosParam.x = mousePos.x;
1837 mousePosParam.y = mousePos.y;
1839 IDropTarget_DragOver(trackerInfo->curDragTarget,
1842 trackerInfo->pdwEffect);
1846 DropTargetNode* newDropTargetNode = 0;
1849 * If we changed window, we have to notify our old target and check for
1852 if (trackerInfo->curDragTarget!=0)
1854 IDropTarget_DragLeave(trackerInfo->curDragTarget);
1858 * Make sure we're hovering over a window.
1860 if (hwndNewTarget!=0)
1863 * Find-out if there is a drag target under the mouse
1865 newDropTargetNode = OLEDD_FindDropTarget(hwndNewTarget);
1867 trackerInfo->curDragTargetHWND = hwndNewTarget;
1868 trackerInfo->curDragTarget = newDropTargetNode ? newDropTargetNode->dropTarget : 0;
1871 * If there is, notify it that we just dragged-in
1873 if (trackerInfo->curDragTarget!=0)
1875 POINTL mousePosParam;
1878 * The documentation tells me that the coordinate should be in the target
1879 * window's coordinate space. However, the tests I made tell me the
1880 * coordinates should be in screen coordinates.
1882 mousePosParam.x = mousePos.x;
1883 mousePosParam.y = mousePos.y;
1885 IDropTarget_DragEnter(trackerInfo->curDragTarget,
1886 trackerInfo->dataObject,
1889 trackerInfo->pdwEffect);
1895 * The mouse is not over a window so we don't track anything.
1897 trackerInfo->curDragTargetHWND = 0;
1898 trackerInfo->curDragTarget = 0;
1903 * Now that we have done that, we have to tell the source to give
1904 * us feedback on the work being done by the target. If we don't
1905 * have a target, simulate no effect.
1907 if (trackerInfo->curDragTarget==0)
1909 *trackerInfo->pdwEffect = DROPEFFECT_NONE;
1912 hr = IDropSource_GiveFeedback(trackerInfo->dropSource,
1913 *trackerInfo->pdwEffect);
1916 * When we ask for feedback from the drop source, sometimes it will
1917 * do all the necessary work and sometimes it will not handle it
1918 * when that's the case, we must display the standard drag and drop
1921 if (hr==DRAGDROP_S_USEDEFAULTCURSORS)
1923 if (*trackerInfo->pdwEffect & DROPEFFECT_MOVE)
1925 SetCursor(LoadCursorA(OLE32_hInstance, MAKEINTRESOURCEA(1)));
1927 else if (*trackerInfo->pdwEffect & DROPEFFECT_COPY)
1929 SetCursor(LoadCursorA(OLE32_hInstance, MAKEINTRESOURCEA(2)));
1931 else if (*trackerInfo->pdwEffect & DROPEFFECT_LINK)
1933 SetCursor(LoadCursorA(OLE32_hInstance, MAKEINTRESOURCEA(3)));
1937 SetCursor(LoadCursorA(OLE32_hInstance, MAKEINTRESOURCEA(0)));
1943 * OLEDD_TrackStateChange()
1945 * This method is invoked while a drag and drop operation is in effect.
1946 * It is used to notify the drop target/drop source callbacks when
1947 * the state of the keyboard or mouse button change.
1950 * trackerInfo - Pointer to the structure identifying the
1951 * drag & drop operation that is currently
1953 * mousePos - Current position of the mouse in screen
1955 * keyState - Contains the state of the shift keys and the
1956 * mouse buttons (MK_LBUTTON and the like)
1958 static void OLEDD_TrackStateChange(
1959 TrackerWindowInfo* trackerInfo,
1964 * Ask the drop source what to do with the operation.
1966 trackerInfo->returnValue = IDropSource_QueryContinueDrag(
1967 trackerInfo->dropSource,
1968 trackerInfo->escPressed,
1972 * All the return valued will stop the operation except the S_OK
1975 if (trackerInfo->returnValue!=S_OK)
1978 * Make sure the message loop in DoDragDrop stops
1980 trackerInfo->trackingDone = TRUE;
1983 * Release the mouse in case the drop target decides to show a popup
1984 * or a menu or something.
1989 * If we end-up over a target, drop the object in the target or
1990 * inform the target that the operation was cancelled.
1992 if (trackerInfo->curDragTarget!=0)
1994 switch (trackerInfo->returnValue)
1997 * If the source wants us to complete the operation, we tell
1998 * the drop target that we just dropped the object in it.
2000 case DRAGDROP_S_DROP:
2002 POINTL mousePosParam;
2005 * The documentation tells me that the coordinate should be
2006 * in the target window's coordinate space. However, the tests
2007 * I made tell me the coordinates should be in screen coordinates.
2009 mousePosParam.x = mousePos.x;
2010 mousePosParam.y = mousePos.y;
2012 IDropTarget_Drop(trackerInfo->curDragTarget,
2013 trackerInfo->dataObject,
2016 trackerInfo->pdwEffect);
2020 * If the source told us that we should cancel, fool the drop
2021 * target by telling it that the mouse left it's window.
2022 * Also set the drop effect to "NONE" in case the application
2023 * ignores the result of DoDragDrop.
2025 case DRAGDROP_S_CANCEL:
2026 IDropTarget_DragLeave(trackerInfo->curDragTarget);
2027 *trackerInfo->pdwEffect = DROPEFFECT_NONE;
2035 * OLEDD_GetButtonState()
2037 * This method will use the current state of the keyboard to build
2038 * a button state mask equivalent to the one passed in the
2039 * WM_MOUSEMOVE wParam.
2041 static DWORD OLEDD_GetButtonState()
2043 BYTE keyboardState[256];
2046 GetKeyboardState(keyboardState);
2048 if ( (keyboardState[VK_SHIFT] & 0x80) !=0)
2049 keyMask |= MK_SHIFT;
2051 if ( (keyboardState[VK_CONTROL] & 0x80) !=0)
2052 keyMask |= MK_CONTROL;
2054 if ( (keyboardState[VK_LBUTTON] & 0x80) !=0)
2055 keyMask |= MK_LBUTTON;
2057 if ( (keyboardState[VK_RBUTTON] & 0x80) !=0)
2058 keyMask |= MK_RBUTTON;
2060 if ( (keyboardState[VK_MBUTTON] & 0x80) !=0)
2061 keyMask |= MK_MBUTTON;
2067 * OLEDD_GetButtonState()
2069 * This method will read the default value of the registry key in
2070 * parameter and extract a DWORD value from it. The registry key value
2071 * can be in a string key or a DWORD key.
2074 * regKey - Key to read the default value from
2075 * pdwValue - Pointer to the location where the DWORD
2076 * value is returned. This value is not modified
2077 * if the value is not found.
2080 static void OLEUTL_ReadRegistryDWORDValue(
2089 lres = RegQueryValueExA(regKey,
2096 if (lres==ERROR_SUCCESS)
2101 *pdwValue = *(DWORD*)buffer;
2106 *pdwValue = (DWORD)strtoul(buffer, NULL, 10);
2112 /******************************************************************************
2113 * OleMetaFilePictFromIconAndLabel
2115 * Returns a global memory handle to a metafile which contains the icon and
2117 * I guess the result of that should look somehow like desktop icons.
2118 * If no hIcon is given, we load the icon via lpszSourceFile and iIconIndex.
2119 * This code might be wrong at some places.
2121 HGLOBAL16 WINAPI OleMetaFilePictFromIconAndLabel16(
2123 LPCOLESTR16 lpszLabel,
2124 LPCOLESTR16 lpszSourceFile,
2131 FIXME("(%04x, '%s', '%s', %d): incorrect metrics, please try to correct them !\n\n\n", hIcon, lpszLabel, lpszSourceFile, iIconIndex);
2134 if (lpszSourceFile) {
2135 HINSTANCE16 hInstance = LoadLibrary16(lpszSourceFile);
2137 /* load the icon at index from lpszSourceFile */
2138 hIcon = (HICON16)LoadIconA(hInstance, (LPCSTR)(DWORD)iIconIndex);
2139 FreeLibrary16(hInstance);
2141 return (HGLOBAL)NULL;
2144 hdc = CreateMetaFile16(NULL);
2145 DrawIcon(hdc, 0, 0, hIcon); /* FIXME */
2146 TextOutA(hdc, 0, 0, lpszLabel, 1); /* FIXME */
2147 hmf = GlobalAlloc16(0, sizeof(METAFILEPICT16));
2148 mf = (METAFILEPICT16 *)GlobalLock16(hmf);
2149 mf->mm = MM_ANISOTROPIC;
2150 mf->xExt = 20; /* FIXME: bogus */
2151 mf->yExt = 20; /* dito */
2152 mf->hMF = CloseMetaFile16(hdc);