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 "wine/winuser16.h"
25 #include "debugtools.h"
28 #include "ole32_main.h"
30 DEFAULT_DEBUG_CHANNEL(ole);
31 DECLARE_DEBUG_CHANNEL(accel);
33 /******************************************************************************
34 * These are static/global variables and internal data structures that the
35 * OLE module uses to maintain it's state.
37 typedef struct tagDropTargetNode
40 IDropTarget* dropTarget;
41 struct tagDropTargetNode* prevDropTarget;
42 struct tagDropTargetNode* nextDropTarget;
45 typedef struct tagTrackerWindowInfo
47 IDataObject* dataObject;
48 IDropSource* dropSource;
55 HWND curDragTargetHWND;
56 IDropTarget* curDragTarget;
59 typedef struct tagOleMenuDescriptor /* OleMenuDescriptor */
61 HWND hwndFrame; /* The containers frame window */
62 HWND hwndActiveObject; /* The active objects window */
63 OLEMENUGROUPWIDTHS mgw; /* OLE menu group widths for the shared menu */
64 HMENU hmenuCombined; /* The combined menu */
65 BOOL bIsServerItem; /* True if the currently open popup belongs to the server */
68 typedef struct tagOleMenuHookItem /* OleMenu hook item in per thread hook list */
70 DWORD tid; /* Thread Id */
71 HANDLE hHeap; /* Heap this is allocated from */
72 HHOOK GetMsg_hHook; /* message hook for WH_GETMESSAGE */
73 HHOOK CallWndProc_hHook; /* message hook for WH_CALLWNDPROC */
74 struct tagOleMenuHookItem *next;
77 static OleMenuHookItem *hook_list;
80 * This is the lock count on the OLE library. It is controlled by the
81 * OLEInitialize/OLEUninitialize methods.
83 static ULONG OLE_moduleLockCount = 0;
86 * Name of our registered window class.
88 static const char OLEDD_DRAGTRACKERCLASS[] = "WineDragDropTracker32";
91 * This is the head of the Drop target container.
93 static DropTargetNode* targetListHead = NULL;
95 /******************************************************************************
96 * These are the prototypes of miscelaneous utility methods
98 static void OLEUTL_ReadRegistryDWORDValue(HKEY regKey, DWORD* pdwValue);
100 /******************************************************************************
101 * These are the prototypes of the utility methods used to manage a shared menu
103 static void OLEMenu_Initialize();
104 static void OLEMenu_UnInitialize();
105 BOOL OLEMenu_InstallHooks( DWORD tid );
106 BOOL OLEMenu_UnInstallHooks( DWORD tid );
107 OleMenuHookItem * OLEMenu_IsHookInstalled( DWORD tid );
108 static BOOL OLEMenu_FindMainMenuIndex( HMENU hMainMenu, HMENU hPopupMenu, UINT *pnPos );
109 BOOL OLEMenu_SetIsServerMenu( HMENU hmenu, OleMenuDescriptor *pOleMenuDescriptor );
110 LRESULT CALLBACK OLEMenu_CallWndProc(INT code, WPARAM wParam, LPARAM lParam);
111 LRESULT CALLBACK OLEMenu_GetMsgProc(INT code, WPARAM wParam, LPARAM lParam);
113 /******************************************************************************
114 * These are the prototypes of the OLE Clipboard initialization methods (in clipboard.c)
116 void OLEClipbrd_UnInitialize();
117 void OLEClipbrd_Initialize();
119 /******************************************************************************
120 * These are the prototypes of the utility methods used for OLE Drag n Drop
122 static void OLEDD_Initialize();
123 static void OLEDD_UnInitialize();
124 static void OLEDD_InsertDropTarget(
125 DropTargetNode* nodeToAdd);
126 static DropTargetNode* OLEDD_ExtractDropTarget(
128 static DropTargetNode* OLEDD_FindDropTarget(
130 static LRESULT WINAPI OLEDD_DragTrackerWindowProc(
135 static void OLEDD_TrackMouseMove(
136 TrackerWindowInfo* trackerInfo,
139 static void OLEDD_TrackStateChange(
140 TrackerWindowInfo* trackerInfo,
143 static DWORD OLEDD_GetButtonState();
146 /******************************************************************************
147 * OleBuildVersion [OLE2.1]
148 * OleBuildVersion [OLE32.84]
150 DWORD WINAPI OleBuildVersion(void)
152 TRACE("Returning version %d, build %d.\n", rmm, rup);
153 return (rmm<<16)+rup;
156 /***********************************************************************
157 * OleInitialize (OLE2.2)
158 * OleInitialize (OLE32.108)
160 HRESULT WINAPI OleInitialize(LPVOID reserved)
164 TRACE("(%p)\n", reserved);
167 * The first duty of the OleInitialize is to initialize the COM libraries.
169 hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
172 * If the CoInitializeEx call failed, the OLE libraries can't be
179 * Then, it has to initialize the OLE specific modules.
183 * Object linking and Embedding
184 * In-place activation
186 if (OLE_moduleLockCount==0)
189 * Initialize the libraries.
191 TRACE("() - Initializing the OLE libraries\n");
196 OLEClipbrd_Initialize();
206 OLEMenu_Initialize();
210 * Then, we increase the lock count on the OLE module.
212 OLE_moduleLockCount++;
217 /******************************************************************************
218 * CoGetCurrentProcess [COMPOBJ.34]
219 * CoGetCurrentProcess [OLE32.18]
222 * Is DWORD really the correct return type for this function?
224 DWORD WINAPI CoGetCurrentProcess(void)
226 return GetCurrentProcessId();
229 /******************************************************************************
230 * OleUninitialize [OLE2.3]
231 * OleUninitialize [OLE32.131]
233 void WINAPI OleUninitialize(void)
238 * Decrease the lock count on the OLE module.
240 OLE_moduleLockCount--;
243 * If we hit the bottom of the lock stack, free the libraries.
245 if (OLE_moduleLockCount==0)
248 * Actually free the libraries.
250 TRACE("() - Freeing the last reference count\n");
255 OLEClipbrd_UnInitialize();
260 OLEDD_UnInitialize();
265 OLEMenu_UnInitialize();
269 * Then, uninitialize the COM libraries.
274 /******************************************************************************
275 * CoRegisterMessageFilter [OLE32.38]
277 HRESULT WINAPI CoRegisterMessageFilter(
278 LPMESSAGEFILTER lpMessageFilter, /* [in] Pointer to interface */
279 LPMESSAGEFILTER *lplpMessageFilter /* [out] Indirect pointer to prior instance if non-NULL */
282 if (lplpMessageFilter) {
283 *lplpMessageFilter = NULL;
288 /******************************************************************************
289 * OleInitializeWOW [OLE32.109]
291 HRESULT WINAPI OleInitializeWOW(DWORD x) {
292 FIXME("(0x%08lx),stub!\n",x);
296 /***********************************************************************
297 * RegisterDragDrop (OLE2.35)
299 HRESULT WINAPI RegisterDragDrop16(
301 LPDROPTARGET pDropTarget
303 FIXME("(0x%04x,%p),stub!\n",hwnd,pDropTarget);
307 /***********************************************************************
308 * RegisterDragDrop (OLE32.139)
310 HRESULT WINAPI RegisterDragDrop(
312 LPDROPTARGET pDropTarget)
314 DropTargetNode* dropTargetInfo;
316 TRACE("(0x%x,%p)\n", hwnd, pDropTarget);
319 * First, check if the window is already registered.
321 dropTargetInfo = OLEDD_FindDropTarget(hwnd);
323 if (dropTargetInfo!=NULL)
324 return DRAGDROP_E_ALREADYREGISTERED;
327 * If it's not there, we can add it. We first create a node for it.
329 dropTargetInfo = HeapAlloc(GetProcessHeap(), 0, sizeof(DropTargetNode));
331 if (dropTargetInfo==NULL)
332 return E_OUTOFMEMORY;
334 dropTargetInfo->hwndTarget = hwnd;
335 dropTargetInfo->prevDropTarget = NULL;
336 dropTargetInfo->nextDropTarget = NULL;
339 * Don't forget that this is an interface pointer, need to nail it down since
340 * we keep a copy of it.
342 dropTargetInfo->dropTarget = pDropTarget;
343 IDropTarget_AddRef(dropTargetInfo->dropTarget);
345 OLEDD_InsertDropTarget(dropTargetInfo);
350 /***********************************************************************
351 * RevokeDragDrop (OLE2.36)
353 HRESULT WINAPI RevokeDragDrop16(
356 FIXME("(0x%04x),stub!\n",hwnd);
360 /***********************************************************************
361 * RevokeDragDrop (OLE32.141)
363 HRESULT WINAPI RevokeDragDrop(
366 DropTargetNode* dropTargetInfo;
368 TRACE("(0x%x)\n", hwnd);
371 * First, check if the window is already registered.
373 dropTargetInfo = OLEDD_ExtractDropTarget(hwnd);
376 * If it ain't in there, it's an error.
378 if (dropTargetInfo==NULL)
379 return DRAGDROP_E_NOTREGISTERED;
382 * If it's in there, clean-up it's used memory and
385 IDropTarget_Release(dropTargetInfo->dropTarget);
386 HeapFree(GetProcessHeap(), 0, dropTargetInfo);
391 /***********************************************************************
392 * OleRegGetUserType (OLE32.122)
394 * This implementation of OleRegGetUserType ignores the dwFormOfType
395 * parameter and always returns the full name of the object. This is
396 * not too bad since this is the case for many objects because of the
397 * way they are registered.
399 HRESULT WINAPI OleRegGetUserType(
402 LPOLESTR* pszUserType)
412 * Initialize the out parameter.
417 * Build the key name we're looking for
419 sprintf( keyName, "CLSID\\{%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}\\",
420 clsid->Data1, clsid->Data2, clsid->Data3,
421 clsid->Data4[0], clsid->Data4[1], clsid->Data4[2], clsid->Data4[3],
422 clsid->Data4[4], clsid->Data4[5], clsid->Data4[6], clsid->Data4[7] );
424 TRACE("(%s, %ld, %p)\n", keyName, dwFormOfType, pszUserType);
427 * Open the class id Key
429 hres = RegOpenKeyA(HKEY_CLASSES_ROOT,
433 if (hres != ERROR_SUCCESS)
434 return REGDB_E_CLASSNOTREG;
437 * Retrieve the size of the name string.
441 hres = RegQueryValueExA(clsidKey,
448 if (hres!=ERROR_SUCCESS)
450 RegCloseKey(clsidKey);
451 return REGDB_E_READREGDB;
455 * Allocate a buffer for the registry value.
457 *pszUserType = CoTaskMemAlloc(cbData*2);
459 if (*pszUserType==NULL)
461 RegCloseKey(clsidKey);
462 return E_OUTOFMEMORY;
465 buffer = HeapAlloc(GetProcessHeap(), 0, cbData);
469 RegCloseKey(clsidKey);
470 CoTaskMemFree(*pszUserType);
472 return E_OUTOFMEMORY;
475 hres = RegQueryValueExA(clsidKey,
482 RegCloseKey(clsidKey);
485 if (hres!=ERROR_SUCCESS)
487 CoTaskMemFree(*pszUserType);
490 retVal = REGDB_E_READREGDB;
494 MultiByteToWideChar( CP_ACP, 0, buffer, -1, *pszUserType, cbData /*FIXME*/ );
497 HeapFree(GetProcessHeap(), 0, buffer);
502 /***********************************************************************
503 * DoDragDrop [OLE32.65]
505 HRESULT WINAPI DoDragDrop (
506 IDataObject *pDataObject, /* [in] ptr to the data obj */
507 IDropSource* pDropSource, /* [in] ptr to the source obj */
508 DWORD dwOKEffect, /* [in] effects allowed by the source */
509 DWORD *pdwEffect) /* [out] ptr to effects of the source */
511 TrackerWindowInfo trackerInfo;
512 HWND hwndTrackWindow;
515 TRACE("(DataObject %p, DropSource %p)\n", pDataObject, pDropSource);
518 * Setup the drag n drop tracking window.
520 trackerInfo.dataObject = pDataObject;
521 trackerInfo.dropSource = pDropSource;
522 trackerInfo.dwOKEffect = dwOKEffect;
523 trackerInfo.pdwEffect = pdwEffect;
524 trackerInfo.trackingDone = FALSE;
525 trackerInfo.escPressed = FALSE;
526 trackerInfo.curDragTargetHWND = 0;
527 trackerInfo.curDragTarget = 0;
529 hwndTrackWindow = CreateWindowA(OLEDD_DRAGTRACKERCLASS,
532 CW_USEDEFAULT, CW_USEDEFAULT,
533 CW_USEDEFAULT, CW_USEDEFAULT,
537 (LPVOID)&trackerInfo);
539 if (hwndTrackWindow!=0)
542 * Capture the mouse input
544 SetCapture(hwndTrackWindow);
547 * Pump messages. All mouse input should go the the capture window.
549 while (!trackerInfo.trackingDone && GetMessageA(&msg, 0, 0, 0) )
551 if ( (msg.message >= WM_KEYFIRST) &&
552 (msg.message <= WM_KEYLAST) )
555 * When keyboard messages are sent to windows on this thread, we
556 * want to ignore notify the drop source that the state changed.
557 * in the case of the Escape key, we also notify the drop source
558 * we give it a special meaning.
560 if ( (msg.message==WM_KEYDOWN) &&
561 (msg.wParam==VK_ESCAPE) )
563 trackerInfo.escPressed = TRUE;
567 * Notify the drop source.
569 OLEDD_TrackStateChange(&trackerInfo,
571 OLEDD_GetButtonState());
576 * Dispatch the messages only when it's not a keyboard message.
578 DispatchMessageA(&msg);
583 * Destroy the temporary window.
585 DestroyWindow(hwndTrackWindow);
587 return trackerInfo.returnValue;
593 /***********************************************************************
594 * OleQueryLinkFromData [OLE32.118]
596 HRESULT WINAPI OleQueryLinkFromData(
597 IDataObject* pSrcDataObject)
599 FIXME("(%p),stub!\n", pSrcDataObject);
603 /***********************************************************************
604 * OleRegGetMiscStatus [OLE32.121]
606 HRESULT WINAPI OleRegGetMiscStatus(
618 * Initialize the out parameter.
623 * Build the key name we're looking for
625 sprintf( keyName, "CLSID\\{%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}\\",
626 clsid->Data1, clsid->Data2, clsid->Data3,
627 clsid->Data4[0], clsid->Data4[1], clsid->Data4[2], clsid->Data4[3],
628 clsid->Data4[4], clsid->Data4[5], clsid->Data4[6], clsid->Data4[7] );
630 TRACE("(%s, %ld, %p)\n", keyName, dwAspect, pdwStatus);
633 * Open the class id Key
635 result = RegOpenKeyA(HKEY_CLASSES_ROOT,
639 if (result != ERROR_SUCCESS)
640 return REGDB_E_CLASSNOTREG;
645 result = RegOpenKeyA(clsidKey,
650 if (result != ERROR_SUCCESS)
652 RegCloseKey(clsidKey);
653 return REGDB_E_READREGDB;
657 * Read the default value
659 OLEUTL_ReadRegistryDWORDValue(miscStatusKey, pdwStatus);
662 * Open the key specific to the requested aspect.
664 sprintf(keyName, "%ld", dwAspect);
666 result = RegOpenKeyA(miscStatusKey,
670 if (result == ERROR_SUCCESS)
672 OLEUTL_ReadRegistryDWORDValue(aspectKey, pdwStatus);
673 RegCloseKey(aspectKey);
679 RegCloseKey(miscStatusKey);
680 RegCloseKey(clsidKey);
685 /******************************************************************************
686 * OleSetContainedObject [OLE32.128]
688 HRESULT WINAPI OleSetContainedObject(
692 IRunnableObject* runnable = NULL;
695 TRACE("(%p,%x), stub!\n", pUnknown, fContained);
697 hres = IUnknown_QueryInterface(pUnknown,
698 &IID_IRunnableObject,
703 hres = IRunnableObject_SetContainedObject(runnable, fContained);
705 IRunnableObject_Release(runnable);
713 /******************************************************************************
714 * OleLoad [OLE32.112]
716 HRESULT WINAPI OleLoad(
719 LPOLECLIENTSITE pClientSite,
722 IPersistStorage* persistStorage = NULL;
723 IOleObject* oleObject = NULL;
727 TRACE("(%p,%p,%p,%p)\n", pStg, riid, pClientSite, ppvObj);
730 * TODO, Conversion ... OleDoAutoConvert
734 * Get the class ID for the object.
736 hres = IStorage_Stat(pStg, &storageInfo, STATFLAG_NONAME);
739 * Now, try and create the handler for the object
741 hres = CoCreateInstance(&storageInfo.clsid,
743 CLSCTX_INPROC_HANDLER,
748 * If that fails, as it will most times, load the default
753 hres = OleCreateDefaultHandler(&storageInfo.clsid,
760 * If we couldn't find a handler... this is bad. Abort the whole thing.
766 * Inform the new object of it's client site.
768 hres = IOleObject_SetClientSite(oleObject, pClientSite);
771 * Initialize the object with it's IPersistStorage interface.
773 hres = IOleObject_QueryInterface(oleObject,
774 &IID_IPersistStorage,
775 (void**)&persistStorage);
779 IPersistStorage_Load(persistStorage, pStg);
781 IPersistStorage_Release(persistStorage);
782 persistStorage = NULL;
786 * Return the requested interface to the caller.
788 hres = IOleObject_QueryInterface(oleObject, riid, ppvObj);
791 * Cleanup interfaces used internally
793 IOleObject_Release(oleObject);
798 /***********************************************************************
799 * OleSave [OLE32.124]
801 HRESULT WINAPI OleSave(
802 LPPERSISTSTORAGE pPS,
809 TRACE("(%p,%p,%x)\n", pPS, pStg, fSameAsLoad);
812 * First, we transfer the class ID (if available)
814 hres = IPersistStorage_GetClassID(pPS, &objectClass);
818 WriteClassStg(pStg, &objectClass);
822 * Then, we ask the object to save itself to the
823 * storage. If it is successful, we commit the storage.
825 hres = IPersistStorage_Save(pPS, pStg, fSameAsLoad);
829 IStorage_Commit(pStg,
837 /******************************************************************************
838 * OleLockRunning [OLE32.114]
840 HRESULT WINAPI OleLockRunning(LPUNKNOWN pUnknown, BOOL fLock, BOOL fLastUnlockCloses)
842 IRunnableObject* runnable = NULL;
845 TRACE("(%p,%x,%x)\n", pUnknown, fLock, fLastUnlockCloses);
847 hres = IUnknown_QueryInterface(pUnknown,
848 &IID_IRunnableObject,
853 hres = IRunnableObject_LockRunning(runnable, fLock, fLastUnlockCloses);
855 IRunnableObject_Release(runnable);
864 /**************************************************************************
865 * Internal methods to manage the shared OLE menu in response to the
866 * OLE***MenuDescriptor API
870 * OLEMenu_Initialize()
872 * Initializes the OLEMENU data structures.
874 static void OLEMenu_Initialize()
879 * OLEMenu_UnInitialize()
881 * Releases the OLEMENU data structures.
883 static void OLEMenu_UnInitialize()
887 /*************************************************************************
888 * OLEMenu_InstallHooks
889 * Install thread scope message hooks for WH_GETMESSAGE and WH_CALLWNDPROC
891 * RETURNS: TRUE if message hooks were succesfully installed
894 BOOL OLEMenu_InstallHooks( DWORD tid )
896 OleMenuHookItem *pHookItem = NULL;
898 /* Create an entry for the hook table */
899 if ( !(pHookItem = HeapAlloc(GetProcessHeap(), 0,
900 sizeof(OleMenuHookItem)) ) )
903 pHookItem->tid = tid;
904 pHookItem->hHeap = GetProcessHeap();
906 /* Install a thread scope message hook for WH_GETMESSAGE */
907 pHookItem->GetMsg_hHook = SetWindowsHookExA( WH_GETMESSAGE, OLEMenu_GetMsgProc,
908 0, GetCurrentThreadId() );
909 if ( !pHookItem->GetMsg_hHook )
912 /* Install a thread scope message hook for WH_CALLWNDPROC */
913 pHookItem->CallWndProc_hHook = SetWindowsHookExA( WH_CALLWNDPROC, OLEMenu_CallWndProc,
914 0, GetCurrentThreadId() );
915 if ( !pHookItem->CallWndProc_hHook )
918 /* Insert the hook table entry */
919 pHookItem->next = hook_list;
920 hook_list = pHookItem;
925 /* Unhook any hooks */
926 if ( pHookItem->GetMsg_hHook )
927 UnhookWindowsHookEx( pHookItem->GetMsg_hHook );
928 if ( pHookItem->CallWndProc_hHook )
929 UnhookWindowsHookEx( pHookItem->CallWndProc_hHook );
930 /* Release the hook table entry */
931 HeapFree(pHookItem->hHeap, 0, pHookItem );
936 /*************************************************************************
937 * OLEMenu_UnInstallHooks
938 * UnInstall thread scope message hooks for WH_GETMESSAGE and WH_CALLWNDPROC
940 * RETURNS: TRUE if message hooks were succesfully installed
943 BOOL OLEMenu_UnInstallHooks( DWORD tid )
945 OleMenuHookItem *pHookItem = NULL;
946 OleMenuHookItem **ppHook = &hook_list;
950 if ((*ppHook)->tid == tid)
953 *ppHook = pHookItem->next;
956 ppHook = &(*ppHook)->next;
958 if (!pHookItem) return FALSE;
960 /* Uninstall the hooks installed for this thread */
961 if ( !UnhookWindowsHookEx( pHookItem->GetMsg_hHook ) )
963 if ( !UnhookWindowsHookEx( pHookItem->CallWndProc_hHook ) )
966 /* Release the hook table entry */
967 HeapFree(pHookItem->hHeap, 0, pHookItem );
972 /* Release the hook table entry */
974 HeapFree(pHookItem->hHeap, 0, pHookItem );
979 /*************************************************************************
980 * OLEMenu_IsHookInstalled
981 * Tests if OLEMenu hooks have been installed for a thread
983 * RETURNS: The pointer and index of the hook table entry for the tid
984 * NULL and -1 for the index if no hooks were installed for this thread
986 OleMenuHookItem * OLEMenu_IsHookInstalled( DWORD tid )
988 OleMenuHookItem *pHookItem = NULL;
990 /* Do a simple linear search for an entry whose tid matches ours.
991 * We really need a map but efficiency is not a concern here. */
992 for (pHookItem = hook_list; pHookItem; pHookItem = pHookItem->next)
994 if ( tid == pHookItem->tid )
1001 /***********************************************************************
1002 * OLEMenu_FindMainMenuIndex
1004 * Used by OLEMenu API to find the top level group a menu item belongs to.
1005 * On success pnPos contains the index of the item in the top level menu group
1007 * RETURNS: TRUE if the ID was found, FALSE on failure
1009 static BOOL OLEMenu_FindMainMenuIndex( HMENU hMainMenu, HMENU hPopupMenu, UINT *pnPos )
1013 nItems = GetMenuItemCount( hMainMenu );
1015 for (i = 0; i < nItems; i++)
1019 /* Is the current item a submenu? */
1020 if ( (hsubmenu = GetSubMenu(hMainMenu, i)) )
1022 /* If the handle is the same we're done */
1023 if ( hsubmenu == hPopupMenu )
1029 /* Recursively search without updating pnPos */
1030 else if ( OLEMenu_FindMainMenuIndex( hsubmenu, hPopupMenu, NULL ) )
1042 /***********************************************************************
1043 * OLEMenu_SetIsServerMenu
1045 * Checks whether a popup menu belongs to a shared menu group which is
1046 * owned by the server, and sets the menu descriptor state accordingly.
1047 * All menu messages from these groups should be routed to the server.
1049 * RETURNS: TRUE if the popup menu is part of a server owned group
1050 * FASE if the popup menu is part of a container owned group
1052 BOOL OLEMenu_SetIsServerMenu( HMENU hmenu, OleMenuDescriptor *pOleMenuDescriptor )
1054 UINT nPos = 0, nWidth, i;
1056 pOleMenuDescriptor->bIsServerItem = FALSE;
1058 /* Don't bother searching if the popup is the combined menu itself */
1059 if ( hmenu == pOleMenuDescriptor->hmenuCombined )
1062 /* Find the menu item index in the shared OLE menu that this item belongs to */
1063 if ( !OLEMenu_FindMainMenuIndex( pOleMenuDescriptor->hmenuCombined, hmenu, &nPos ) )
1066 /* The group widths array has counts for the number of elements
1067 * in the groups File, Edit, Container, Object, Window, Help.
1068 * The Edit, Object & Help groups belong to the server object
1069 * and the other three belong to the container.
1070 * Loop thru the group widths and locate the group we are a member of.
1072 for ( i = 0, nWidth = 0; i < 6; i++ )
1074 nWidth += pOleMenuDescriptor->mgw.width[i];
1075 if ( nPos < nWidth )
1077 /* Odd elements are server menu widths */
1078 pOleMenuDescriptor->bIsServerItem = (i%2) ? TRUE : FALSE;
1083 return pOleMenuDescriptor->bIsServerItem;
1086 /*************************************************************************
1087 * OLEMenu_CallWndProc
1088 * Thread scope WH_CALLWNDPROC hook proc filter function (callback)
1089 * This is invoked from a message hook installed in OleSetMenuDescriptor.
1091 LRESULT CALLBACK OLEMenu_CallWndProc(INT code, WPARAM wParam, LPARAM lParam)
1093 LPCWPSTRUCT pMsg = NULL;
1094 HOLEMENU hOleMenu = 0;
1095 OleMenuDescriptor *pOleMenuDescriptor = NULL;
1096 OleMenuHookItem *pHookItem = NULL;
1099 TRACE("%i, %04x, %08x\n", code, wParam, (unsigned)lParam );
1101 /* Check if we're being asked to process the message */
1102 if ( HC_ACTION != code )
1105 /* Retrieve the current message being dispatched from lParam */
1106 pMsg = (LPCWPSTRUCT)lParam;
1108 /* Check if the message is destined for a window we are interested in:
1109 * If the window has an OLEMenu property we may need to dispatch
1110 * the menu message to its active objects window instead. */
1112 hOleMenu = (HOLEMENU)GetPropA( pMsg->hwnd, "PROP_OLEMenuDescriptor" );
1116 /* Get the menu descriptor */
1117 pOleMenuDescriptor = (OleMenuDescriptor *) GlobalLock( hOleMenu );
1118 if ( !pOleMenuDescriptor ) /* Bad descriptor! */
1121 /* Process menu messages */
1122 switch( pMsg->message )
1126 /* Reset the menu descriptor state */
1127 pOleMenuDescriptor->bIsServerItem = FALSE;
1129 /* Send this message to the server as well */
1130 SendMessageA( pOleMenuDescriptor->hwndActiveObject,
1131 pMsg->message, pMsg->wParam, pMsg->lParam );
1135 case WM_INITMENUPOPUP:
1137 /* Save the state for whether this is a server owned menu */
1138 OLEMenu_SetIsServerMenu( (HMENU)pMsg->wParam, pOleMenuDescriptor );
1144 fuFlags = HIWORD(pMsg->wParam); /* Get flags */
1145 if ( fuFlags & MF_SYSMENU )
1148 /* Save the state for whether this is a server owned popup menu */
1149 else if ( fuFlags & MF_POPUP )
1150 OLEMenu_SetIsServerMenu( (HMENU)pMsg->lParam, pOleMenuDescriptor );
1157 LPDRAWITEMSTRUCT lpdis = (LPDRAWITEMSTRUCT) pMsg->lParam;
1158 if ( pMsg->wParam != 0 || lpdis->CtlType != ODT_MENU )
1159 goto NEXTHOOK; /* Not a menu message */
1168 /* If the message was for the server dispatch it accordingly */
1169 if ( pOleMenuDescriptor->bIsServerItem )
1171 SendMessageA( pOleMenuDescriptor->hwndActiveObject,
1172 pMsg->message, pMsg->wParam, pMsg->lParam );
1176 if ( pOleMenuDescriptor )
1177 GlobalUnlock( hOleMenu );
1179 /* Lookup the hook item for the current thread */
1180 if ( !( pHookItem = OLEMenu_IsHookInstalled( GetCurrentThreadId() ) ) )
1182 /* This should never fail!! */
1183 WARN("could not retrieve hHook for current thread!\n" );
1187 /* Pass on the message to the next hooker */
1188 return CallNextHookEx( pHookItem->CallWndProc_hHook, code, wParam, lParam );
1191 /*************************************************************************
1192 * OLEMenu_GetMsgProc
1193 * Thread scope WH_GETMESSAGE hook proc filter function (callback)
1194 * This is invoked from a message hook installed in OleSetMenuDescriptor.
1196 LRESULT CALLBACK OLEMenu_GetMsgProc(INT code, WPARAM wParam, LPARAM lParam)
1199 HOLEMENU hOleMenu = 0;
1200 OleMenuDescriptor *pOleMenuDescriptor = NULL;
1201 OleMenuHookItem *pHookItem = NULL;
1204 TRACE("%i, %04x, %08x\n", code, wParam, (unsigned)lParam );
1206 /* Check if we're being asked to process a messages */
1207 if ( HC_ACTION != code )
1210 /* Retrieve the current message being dispatched from lParam */
1211 pMsg = (LPMSG)lParam;
1213 /* Check if the message is destined for a window we are interested in:
1214 * If the window has an OLEMenu property we may need to dispatch
1215 * the menu message to its active objects window instead. */
1217 hOleMenu = (HOLEMENU)GetPropA( pMsg->hwnd, "PROP_OLEMenuDescriptor" );
1221 /* Process menu messages */
1222 switch( pMsg->message )
1226 wCode = HIWORD(pMsg->wParam); /* Get notification code */
1228 goto NEXTHOOK; /* Not a menu message */
1235 /* Get the menu descriptor */
1236 pOleMenuDescriptor = (OleMenuDescriptor *) GlobalLock( hOleMenu );
1237 if ( !pOleMenuDescriptor ) /* Bad descriptor! */
1240 /* If the message was for the server dispatch it accordingly */
1241 if ( pOleMenuDescriptor->bIsServerItem )
1243 /* Change the hWnd in the message to the active objects hWnd.
1244 * The message loop which reads this message will automatically
1245 * dispatch it to the embedded objects window. */
1246 pMsg->hwnd = pOleMenuDescriptor->hwndActiveObject;
1250 if ( pOleMenuDescriptor )
1251 GlobalUnlock( hOleMenu );
1253 /* Lookup the hook item for the current thread */
1254 if ( !( pHookItem = OLEMenu_IsHookInstalled( GetCurrentThreadId() ) ) )
1256 /* This should never fail!! */
1257 WARN("could not retrieve hHook for current thread!\n" );
1261 /* Pass on the message to the next hooker */
1262 return CallNextHookEx( pHookItem->GetMsg_hHook, code, wParam, lParam );
1265 /***********************************************************************
1266 * OleCreateMenuDescriptor [OLE32.97]
1267 * Creates an OLE menu descriptor for OLE to use when dispatching
1268 * menu messages and commands.
1271 * hmenuCombined - Handle to the objects combined menu
1272 * lpMenuWidths - Pointer to array of 6 LONG's indicating menus per group
1275 HOLEMENU WINAPI OleCreateMenuDescriptor(
1276 HMENU hmenuCombined,
1277 LPOLEMENUGROUPWIDTHS lpMenuWidths)
1280 OleMenuDescriptor *pOleMenuDescriptor;
1283 if ( !hmenuCombined || !lpMenuWidths )
1286 /* Create an OLE menu descriptor */
1287 if ( !(hOleMenu = GlobalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT,
1288 sizeof(OleMenuDescriptor) ) ) )
1291 pOleMenuDescriptor = (OleMenuDescriptor *) GlobalLock( hOleMenu );
1292 if ( !pOleMenuDescriptor )
1295 /* Initialize menu group widths and hmenu */
1296 for ( i = 0; i < 6; i++ )
1297 pOleMenuDescriptor->mgw.width[i] = lpMenuWidths->width[i];
1299 pOleMenuDescriptor->hmenuCombined = hmenuCombined;
1300 pOleMenuDescriptor->bIsServerItem = FALSE;
1301 GlobalUnlock( hOleMenu );
1306 /***********************************************************************
1307 * OleDestroyMenuDescriptor [OLE32.99]
1308 * Destroy the shared menu descriptor
1310 HRESULT WINAPI OleDestroyMenuDescriptor(
1311 HOLEMENU hmenuDescriptor)
1313 if ( hmenuDescriptor )
1314 GlobalFree( hmenuDescriptor );
1318 /***********************************************************************
1319 * OleSetMenuDescriptor [OLE32.129]
1320 * Installs or removes OLE dispatching code for the containers frame window
1321 * FIXME: The lpFrame and lpActiveObject parameters are currently ignored
1322 * OLE should install context sensitive help F1 filtering for the app when
1323 * these are non null.
1326 * hOleMenu Handle to composite menu descriptor
1327 * hwndFrame Handle to containers frame window
1328 * hwndActiveObject Handle to objects in-place activation window
1329 * lpFrame Pointer to IOleInPlaceFrame on containers window
1330 * lpActiveObject Pointer to IOleInPlaceActiveObject on active in-place object
1333 * S_OK - menu installed correctly
1334 * E_FAIL, E_INVALIDARG, E_UNEXPECTED - failure
1336 HRESULT WINAPI OleSetMenuDescriptor(
1339 HWND hwndActiveObject,
1340 LPOLEINPLACEFRAME lpFrame,
1341 LPOLEINPLACEACTIVEOBJECT lpActiveObject)
1343 OleMenuDescriptor *pOleMenuDescriptor = NULL;
1346 if ( !hwndFrame || (hOleMenu && !hwndActiveObject) )
1347 return E_INVALIDARG;
1349 if ( lpFrame || lpActiveObject )
1351 FIXME("(%x, %x, %x, %p, %p), Context sensitive help filtering not implemented!\n",
1352 (unsigned int)hOleMenu,
1359 /* Set up a message hook to intercept the containers frame window messages.
1360 * The message filter is responsible for dispatching menu messages from the
1361 * shared menu which are intended for the object.
1364 if ( hOleMenu ) /* Want to install dispatching code */
1366 /* If OLEMenu hooks are already installed for this thread, fail
1367 * Note: This effectively means that OleSetMenuDescriptor cannot
1368 * be called twice in succession on the same frame window
1369 * without first calling it with a null hOleMenu to uninstall */
1370 if ( OLEMenu_IsHookInstalled( GetCurrentThreadId() ) )
1373 /* Get the menu descriptor */
1374 pOleMenuDescriptor = (OleMenuDescriptor *) GlobalLock( hOleMenu );
1375 if ( !pOleMenuDescriptor )
1376 return E_UNEXPECTED;
1378 /* Update the menu descriptor */
1379 pOleMenuDescriptor->hwndFrame = hwndFrame;
1380 pOleMenuDescriptor->hwndActiveObject = hwndActiveObject;
1382 GlobalUnlock( hOleMenu );
1383 pOleMenuDescriptor = NULL;
1385 /* Add a menu descriptor windows property to the frame window */
1386 SetPropA( hwndFrame, "PROP_OLEMenuDescriptor", hOleMenu );
1388 /* Install thread scope message hooks for WH_GETMESSAGE and WH_CALLWNDPROC */
1389 if ( !OLEMenu_InstallHooks( GetCurrentThreadId() ) )
1392 else /* Want to uninstall dispatching code */
1394 /* Uninstall the hooks */
1395 if ( !OLEMenu_UnInstallHooks( GetCurrentThreadId() ) )
1398 /* Remove the menu descriptor property from the frame window */
1399 RemovePropA( hwndFrame, "PROP_OLEMenuDescriptor" );
1405 /******************************************************************************
1406 * IsAccelerator [OLE32.75]
1407 * Mostly copied from controls/menu.c TranslateAccelerator implementation
1409 BOOL WINAPI IsAccelerator(HACCEL hAccel, int cAccelEntries, LPMSG lpMsg, WORD* lpwCmd)
1412 LPACCEL16 lpAccelTbl;
1415 if(!lpMsg) return FALSE;
1416 if (!hAccel || !(lpAccelTbl = (LPACCEL16)LockResource16(hAccel)))
1418 WARN_(accel)("invalid accel handle=%04x\n", hAccel);
1421 if((lpMsg->message != WM_KEYDOWN &&
1422 lpMsg->message != WM_KEYUP &&
1423 lpMsg->message != WM_SYSKEYDOWN &&
1424 lpMsg->message != WM_SYSKEYUP &&
1425 lpMsg->message != WM_CHAR)) return FALSE;
1427 TRACE_(accel)("hAccel=%04x, cAccelEntries=%d,"
1428 "msg->hwnd=%04x, msg->message=%04x, wParam=%08x, lParam=%08lx\n",
1429 hAccel, cAccelEntries,
1430 lpMsg->hwnd, lpMsg->message, lpMsg->wParam, lpMsg->lParam);
1431 for(i = 0; i < cAccelEntries; i++)
1433 if(lpAccelTbl[i].key != lpMsg->wParam)
1436 if(lpMsg->message == WM_CHAR)
1438 if(!(lpAccelTbl[i].fVirt & FALT) && !(lpAccelTbl[i].fVirt & FVIRTKEY))
1440 TRACE_(accel)("found accel for WM_CHAR: ('%c')\n", lpMsg->wParam & 0xff);
1446 if(lpAccelTbl[i].fVirt & FVIRTKEY)
1449 TRACE_(accel)("found accel for virt_key %04x (scan %04x)\n",
1450 lpMsg->wParam, HIWORD(lpMsg->lParam) & 0xff);
1451 if(GetKeyState(VK_SHIFT) & 0x8000) mask |= FSHIFT;
1452 if(GetKeyState(VK_CONTROL) & 0x8000) mask |= FCONTROL;
1453 if(GetKeyState(VK_MENU) & 0x8000) mask |= FALT;
1454 if(mask == (lpAccelTbl[i].fVirt & (FSHIFT | FCONTROL | FALT))) goto found;
1455 TRACE_(accel)("incorrect SHIFT/CTRL/ALT-state\n");
1459 if(!(lpMsg->lParam & 0x01000000)) /* no special_key */
1461 if((lpAccelTbl[i].fVirt & FALT) && (lpMsg->lParam & 0x20000000))
1462 { /* ^^ ALT pressed */
1463 TRACE_(accel)("found accel for Alt-%c\n", lpMsg->wParam & 0xff);
1471 WARN_(accel)("couldn't translate accelerator key\n");
1475 if(lpwCmd) *lpwCmd = lpAccelTbl[i].cmd;
1479 /***********************************************************************
1480 * ReleaseStgMedium [OLE32.140]
1482 void WINAPI ReleaseStgMedium(
1485 switch (pmedium->tymed)
1489 if ( (pmedium->pUnkForRelease==0) &&
1490 (pmedium->u.hGlobal!=0) )
1491 GlobalFree(pmedium->u.hGlobal);
1493 pmedium->u.hGlobal = 0;
1498 if (pmedium->u.lpszFileName!=0)
1500 if (pmedium->pUnkForRelease==0)
1502 DeleteFileW(pmedium->u.lpszFileName);
1505 CoTaskMemFree(pmedium->u.lpszFileName);
1508 pmedium->u.lpszFileName = 0;
1513 if (pmedium->u.pstm!=0)
1515 IStream_Release(pmedium->u.pstm);
1518 pmedium->u.pstm = 0;
1521 case TYMED_ISTORAGE:
1523 if (pmedium->u.pstg!=0)
1525 IStorage_Release(pmedium->u.pstg);
1528 pmedium->u.pstg = 0;
1533 if ( (pmedium->pUnkForRelease==0) &&
1534 (pmedium->u.hGlobal!=0) )
1535 DeleteObject(pmedium->u.hGlobal);
1537 pmedium->u.hGlobal = 0;
1542 if ( (pmedium->pUnkForRelease==0) &&
1543 (pmedium->u.hMetaFilePict!=0) )
1545 LPMETAFILEPICT pMP = GlobalLock(pmedium->u.hMetaFilePict);
1546 DeleteMetaFile(pMP->hMF);
1547 GlobalUnlock(pmedium->u.hMetaFilePict);
1548 GlobalFree(pmedium->u.hMetaFilePict);
1551 pmedium->u.hMetaFilePict = 0;
1556 if ( (pmedium->pUnkForRelease==0) &&
1557 (pmedium->u.hEnhMetaFile!=0) )
1559 DeleteEnhMetaFile(pmedium->u.hEnhMetaFile);
1562 pmedium->u.hEnhMetaFile = 0;
1571 * After cleaning up, the unknown is released
1573 if (pmedium->pUnkForRelease!=0)
1575 IUnknown_Release(pmedium->pUnkForRelease);
1576 pmedium->pUnkForRelease = 0;
1581 * OLEDD_Initialize()
1583 * Initializes the OLE drag and drop data structures.
1585 static void OLEDD_Initialize()
1589 ZeroMemory (&wndClass, sizeof(WNDCLASSA));
1590 wndClass.style = CS_GLOBALCLASS;
1591 wndClass.lpfnWndProc = (WNDPROC)OLEDD_DragTrackerWindowProc;
1592 wndClass.cbClsExtra = 0;
1593 wndClass.cbWndExtra = sizeof(TrackerWindowInfo*);
1594 wndClass.hCursor = 0;
1595 wndClass.hbrBackground = 0;
1596 wndClass.lpszClassName = OLEDD_DRAGTRACKERCLASS;
1598 RegisterClassA (&wndClass);
1602 * OLEDD_UnInitialize()
1604 * Releases the OLE drag and drop data structures.
1606 static void OLEDD_UnInitialize()
1609 * Simply empty the list.
1611 while (targetListHead!=NULL)
1613 RevokeDragDrop(targetListHead->hwndTarget);
1618 * OLEDD_InsertDropTarget()
1620 * Insert the target node in the tree.
1622 static void OLEDD_InsertDropTarget(DropTargetNode* nodeToAdd)
1624 DropTargetNode* curNode;
1625 DropTargetNode** parentNodeLink;
1628 * Iterate the tree to find the insertion point.
1630 curNode = targetListHead;
1631 parentNodeLink = &targetListHead;
1633 while (curNode!=NULL)
1635 if (nodeToAdd->hwndTarget<curNode->hwndTarget)
1638 * If the node we want to add has a smaller HWND, go left
1640 parentNodeLink = &curNode->prevDropTarget;
1641 curNode = curNode->prevDropTarget;
1643 else if (nodeToAdd->hwndTarget>curNode->hwndTarget)
1646 * If the node we want to add has a larger HWND, go right
1648 parentNodeLink = &curNode->nextDropTarget;
1649 curNode = curNode->nextDropTarget;
1654 * The item was found in the list. It shouldn't have been there
1662 * If we get here, we have found a spot for our item. The parentNodeLink
1663 * pointer points to the pointer that we have to modify.
1664 * The curNode should be NULL. We just have to establish the link and Voila!
1666 assert(curNode==NULL);
1667 assert(parentNodeLink!=NULL);
1668 assert(*parentNodeLink==NULL);
1670 *parentNodeLink=nodeToAdd;
1674 * OLEDD_ExtractDropTarget()
1676 * Removes the target node from the tree.
1678 static DropTargetNode* OLEDD_ExtractDropTarget(HWND hwndOfTarget)
1680 DropTargetNode* curNode;
1681 DropTargetNode** parentNodeLink;
1684 * Iterate the tree to find the insertion point.
1686 curNode = targetListHead;
1687 parentNodeLink = &targetListHead;
1689 while (curNode!=NULL)
1691 if (hwndOfTarget<curNode->hwndTarget)
1694 * If the node we want to add has a smaller HWND, go left
1696 parentNodeLink = &curNode->prevDropTarget;
1697 curNode = curNode->prevDropTarget;
1699 else if (hwndOfTarget>curNode->hwndTarget)
1702 * If the node we want to add has a larger HWND, go right
1704 parentNodeLink = &curNode->nextDropTarget;
1705 curNode = curNode->nextDropTarget;
1710 * The item was found in the list. Detach it from it's parent and
1711 * re-insert it's kids in the tree.
1713 assert(parentNodeLink!=NULL);
1714 assert(*parentNodeLink==curNode);
1717 * We arbitrately re-attach the left sub-tree to the parent.
1719 *parentNodeLink = curNode->prevDropTarget;
1722 * And we re-insert the right subtree
1724 if (curNode->nextDropTarget!=NULL)
1726 OLEDD_InsertDropTarget(curNode->nextDropTarget);
1730 * The node we found is still a valid node once we complete
1731 * the unlinking of the kids.
1733 curNode->nextDropTarget=NULL;
1734 curNode->prevDropTarget=NULL;
1741 * If we get here, the node is not in the tree
1747 * OLEDD_FindDropTarget()
1749 * Finds information about the drop target.
1751 static DropTargetNode* OLEDD_FindDropTarget(HWND hwndOfTarget)
1753 DropTargetNode* curNode;
1756 * Iterate the tree to find the HWND value.
1758 curNode = targetListHead;
1760 while (curNode!=NULL)
1762 if (hwndOfTarget<curNode->hwndTarget)
1765 * If the node we want to add has a smaller HWND, go left
1767 curNode = curNode->prevDropTarget;
1769 else if (hwndOfTarget>curNode->hwndTarget)
1772 * If the node we want to add has a larger HWND, go right
1774 curNode = curNode->nextDropTarget;
1779 * The item was found in the list.
1786 * If we get here, the item is not in the list
1792 * OLEDD_DragTrackerWindowProc()
1794 * This method is the WindowProcedure of the drag n drop tracking
1795 * window. During a drag n Drop operation, an invisible window is created
1796 * to receive the user input and act upon it. This procedure is in charge
1799 static LRESULT WINAPI OLEDD_DragTrackerWindowProc(
1809 LPCREATESTRUCTA createStruct = (LPCREATESTRUCTA)lParam;
1811 SetWindowLongA(hwnd, 0, (LONG)createStruct->lpCreateParams);
1818 TrackerWindowInfo* trackerInfo = (TrackerWindowInfo*)GetWindowLongA(hwnd, 0);
1822 * Get the current mouse position in screen coordinates.
1824 mousePos.x = LOWORD(lParam);
1825 mousePos.y = HIWORD(lParam);
1826 ClientToScreen(hwnd, &mousePos);
1829 * Track the movement of the mouse.
1831 OLEDD_TrackMouseMove(trackerInfo, mousePos, wParam);
1838 case WM_LBUTTONDOWN:
1839 case WM_MBUTTONDOWN:
1840 case WM_RBUTTONDOWN:
1842 TrackerWindowInfo* trackerInfo = (TrackerWindowInfo*)GetWindowLongA(hwnd, 0);
1846 * Get the current mouse position in screen coordinates.
1848 mousePos.x = LOWORD(lParam);
1849 mousePos.y = HIWORD(lParam);
1850 ClientToScreen(hwnd, &mousePos);
1853 * Notify everyone that the button state changed
1854 * TODO: Check if the "escape" key was pressed.
1856 OLEDD_TrackStateChange(trackerInfo, mousePos, wParam);
1863 * This is a window proc after all. Let's call the default.
1865 return DefWindowProcA (hwnd, uMsg, wParam, lParam);
1869 * OLEDD_TrackMouseMove()
1871 * This method is invoked while a drag and drop operation is in effect.
1872 * it will generate the appropriate callbacks in the drop source
1873 * and drop target. It will also provide the expected feedback to
1877 * trackerInfo - Pointer to the structure identifying the
1878 * drag & drop operation that is currently
1880 * mousePos - Current position of the mouse in screen
1882 * keyState - Contains the state of the shift keys and the
1883 * mouse buttons (MK_LBUTTON and the like)
1885 static void OLEDD_TrackMouseMove(
1886 TrackerWindowInfo* trackerInfo,
1890 HWND hwndNewTarget = 0;
1894 * Get the handle of the window under the mouse
1896 hwndNewTarget = WindowFromPoint(mousePos);
1899 * Every time, we re-initialize the effects passed to the
1900 * IDropTarget to the effects allowed by the source.
1902 *trackerInfo->pdwEffect = trackerInfo->dwOKEffect;
1905 * If we are hovering over the same target as before, send the
1906 * DragOver notification
1908 if ( (trackerInfo->curDragTarget != 0) &&
1909 (trackerInfo->curDragTargetHWND==hwndNewTarget) )
1911 POINTL mousePosParam;
1914 * The documentation tells me that the coordinate should be in the target
1915 * window's coordinate space. However, the tests I made tell me the
1916 * coordinates should be in screen coordinates.
1918 mousePosParam.x = mousePos.x;
1919 mousePosParam.y = mousePos.y;
1921 IDropTarget_DragOver(trackerInfo->curDragTarget,
1924 trackerInfo->pdwEffect);
1928 DropTargetNode* newDropTargetNode = 0;
1931 * If we changed window, we have to notify our old target and check for
1934 if (trackerInfo->curDragTarget!=0)
1936 IDropTarget_DragLeave(trackerInfo->curDragTarget);
1940 * Make sure we're hovering over a window.
1942 if (hwndNewTarget!=0)
1945 * Find-out if there is a drag target under the mouse
1947 HWND nexttar = hwndNewTarget;
1949 newDropTargetNode = OLEDD_FindDropTarget(nexttar);
1950 } while (!newDropTargetNode && (nexttar = GetParent(nexttar)) != 0);
1951 if(nexttar) hwndNewTarget = nexttar;
1953 trackerInfo->curDragTargetHWND = hwndNewTarget;
1954 trackerInfo->curDragTarget = newDropTargetNode ? newDropTargetNode->dropTarget : 0;
1957 * If there is, notify it that we just dragged-in
1959 if (trackerInfo->curDragTarget!=0)
1961 POINTL mousePosParam;
1964 * The documentation tells me that the coordinate should be in the target
1965 * window's coordinate space. However, the tests I made tell me the
1966 * coordinates should be in screen coordinates.
1968 mousePosParam.x = mousePos.x;
1969 mousePosParam.y = mousePos.y;
1971 IDropTarget_DragEnter(trackerInfo->curDragTarget,
1972 trackerInfo->dataObject,
1975 trackerInfo->pdwEffect);
1981 * The mouse is not over a window so we don't track anything.
1983 trackerInfo->curDragTargetHWND = 0;
1984 trackerInfo->curDragTarget = 0;
1989 * Now that we have done that, we have to tell the source to give
1990 * us feedback on the work being done by the target. If we don't
1991 * have a target, simulate no effect.
1993 if (trackerInfo->curDragTarget==0)
1995 *trackerInfo->pdwEffect = DROPEFFECT_NONE;
1998 hr = IDropSource_GiveFeedback(trackerInfo->dropSource,
1999 *trackerInfo->pdwEffect);
2002 * When we ask for feedback from the drop source, sometimes it will
2003 * do all the necessary work and sometimes it will not handle it
2004 * when that's the case, we must display the standard drag and drop
2007 if (hr==DRAGDROP_S_USEDEFAULTCURSORS)
2009 if (*trackerInfo->pdwEffect & DROPEFFECT_MOVE)
2011 SetCursor(LoadCursorA(OLE32_hInstance, MAKEINTRESOURCEA(1)));
2013 else if (*trackerInfo->pdwEffect & DROPEFFECT_COPY)
2015 SetCursor(LoadCursorA(OLE32_hInstance, MAKEINTRESOURCEA(2)));
2017 else if (*trackerInfo->pdwEffect & DROPEFFECT_LINK)
2019 SetCursor(LoadCursorA(OLE32_hInstance, MAKEINTRESOURCEA(3)));
2023 SetCursor(LoadCursorA(OLE32_hInstance, MAKEINTRESOURCEA(0)));
2029 * OLEDD_TrackStateChange()
2031 * This method is invoked while a drag and drop operation is in effect.
2032 * It is used to notify the drop target/drop source callbacks when
2033 * the state of the keyboard or mouse button change.
2036 * trackerInfo - Pointer to the structure identifying the
2037 * drag & drop operation that is currently
2039 * mousePos - Current position of the mouse in screen
2041 * keyState - Contains the state of the shift keys and the
2042 * mouse buttons (MK_LBUTTON and the like)
2044 static void OLEDD_TrackStateChange(
2045 TrackerWindowInfo* trackerInfo,
2050 * Ask the drop source what to do with the operation.
2052 trackerInfo->returnValue = IDropSource_QueryContinueDrag(
2053 trackerInfo->dropSource,
2054 trackerInfo->escPressed,
2058 * All the return valued will stop the operation except the S_OK
2061 if (trackerInfo->returnValue!=S_OK)
2064 * Make sure the message loop in DoDragDrop stops
2066 trackerInfo->trackingDone = TRUE;
2069 * Release the mouse in case the drop target decides to show a popup
2070 * or a menu or something.
2075 * If we end-up over a target, drop the object in the target or
2076 * inform the target that the operation was cancelled.
2078 if (trackerInfo->curDragTarget!=0)
2080 switch (trackerInfo->returnValue)
2083 * If the source wants us to complete the operation, we tell
2084 * the drop target that we just dropped the object in it.
2086 case DRAGDROP_S_DROP:
2088 POINTL mousePosParam;
2091 * The documentation tells me that the coordinate should be
2092 * in the target window's coordinate space. However, the tests
2093 * I made tell me the coordinates should be in screen coordinates.
2095 mousePosParam.x = mousePos.x;
2096 mousePosParam.y = mousePos.y;
2098 IDropTarget_Drop(trackerInfo->curDragTarget,
2099 trackerInfo->dataObject,
2102 trackerInfo->pdwEffect);
2106 * If the source told us that we should cancel, fool the drop
2107 * target by telling it that the mouse left it's window.
2108 * Also set the drop effect to "NONE" in case the application
2109 * ignores the result of DoDragDrop.
2111 case DRAGDROP_S_CANCEL:
2112 IDropTarget_DragLeave(trackerInfo->curDragTarget);
2113 *trackerInfo->pdwEffect = DROPEFFECT_NONE;
2121 * OLEDD_GetButtonState()
2123 * This method will use the current state of the keyboard to build
2124 * a button state mask equivalent to the one passed in the
2125 * WM_MOUSEMOVE wParam.
2127 static DWORD OLEDD_GetButtonState()
2129 BYTE keyboardState[256];
2132 GetKeyboardState(keyboardState);
2134 if ( (keyboardState[VK_SHIFT] & 0x80) !=0)
2135 keyMask |= MK_SHIFT;
2137 if ( (keyboardState[VK_CONTROL] & 0x80) !=0)
2138 keyMask |= MK_CONTROL;
2140 if ( (keyboardState[VK_LBUTTON] & 0x80) !=0)
2141 keyMask |= MK_LBUTTON;
2143 if ( (keyboardState[VK_RBUTTON] & 0x80) !=0)
2144 keyMask |= MK_RBUTTON;
2146 if ( (keyboardState[VK_MBUTTON] & 0x80) !=0)
2147 keyMask |= MK_MBUTTON;
2153 * OLEDD_GetButtonState()
2155 * This method will read the default value of the registry key in
2156 * parameter and extract a DWORD value from it. The registry key value
2157 * can be in a string key or a DWORD key.
2160 * regKey - Key to read the default value from
2161 * pdwValue - Pointer to the location where the DWORD
2162 * value is returned. This value is not modified
2163 * if the value is not found.
2166 static void OLEUTL_ReadRegistryDWORDValue(
2175 lres = RegQueryValueExA(regKey,
2182 if (lres==ERROR_SUCCESS)
2187 *pdwValue = *(DWORD*)buffer;
2192 *pdwValue = (DWORD)strtoul(buffer, NULL, 10);
2198 /******************************************************************************
2199 * OleMetaFilePictFromIconAndLabel (OLE2.56)
2201 * Returns a global memory handle to a metafile which contains the icon and
2203 * I guess the result of that should look somehow like desktop icons.
2204 * If no hIcon is given, we load the icon via lpszSourceFile and iIconIndex.
2205 * This code might be wrong at some places.
2207 HGLOBAL16 WINAPI OleMetaFilePictFromIconAndLabel16(
2209 LPCOLESTR16 lpszLabel,
2210 LPCOLESTR16 lpszSourceFile,
2217 FIXME("(%04x, '%s', '%s', %d): incorrect metrics, please try to correct them !\n\n\n", hIcon, lpszLabel, lpszSourceFile, iIconIndex);
2220 if (lpszSourceFile) {
2221 HINSTANCE16 hInstance = LoadLibrary16(lpszSourceFile);
2223 /* load the icon at index from lpszSourceFile */
2224 hIcon = (HICON16)LoadIconA(hInstance, (LPCSTR)(DWORD)iIconIndex);
2225 FreeLibrary16(hInstance);
2227 return (HGLOBAL)NULL;
2230 hdc = CreateMetaFile16(NULL);
2231 DrawIcon(hdc, 0, 0, hIcon); /* FIXME */
2232 TextOutA(hdc, 0, 0, lpszLabel, 1); /* FIXME */
2233 hmf = GlobalAlloc16(0, sizeof(METAFILEPICT16));
2234 mf = (METAFILEPICT16 *)GlobalLock16(hmf);
2235 mf->mm = MM_ANISOTROPIC;
2236 mf->xExt = 20; /* FIXME: bogus */
2237 mf->yExt = 20; /* dito */
2238 mf->hMF = CloseMetaFile16(hdc);
2242 /******************************************************************************
2243 * DllDebugObjectRPCHook (OLE32.62)
2244 * turns on and off internal debugging, pointer is only used on macintosh
2247 BOOL WINAPI DllDebugObjectRPCHook(BOOL b, void *dummy)