5 * Copyright 1995 Martin von Loewis
6 * Copyright 1999 Francis Beaudet
7 * Copyright 1999 Noel Borthwick
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
32 #define NONAMELESSUNION
33 #define NONAMELESSSTRUCT
46 #include "wine/winbase16.h"
47 #include "wine/wingdi16.h"
48 #include "wine/winuser16.h"
49 #include "ole32_main.h"
51 #include "wine/debug.h"
53 WINE_DEFAULT_DEBUG_CHANNEL(ole);
54 WINE_DECLARE_DEBUG_CHANNEL(accel);
56 #define HICON_16(h32) (LOWORD(h32))
57 #define HICON_32(h16) ((HICON)(ULONG_PTR)(h16))
58 #define HINSTANCE_32(h16) ((HINSTANCE)(ULONG_PTR)(h16))
60 /******************************************************************************
61 * These are static/global variables and internal data structures that the
62 * OLE module uses to maintain it's state.
64 typedef struct tagDropTargetNode
67 IDropTarget* dropTarget;
68 struct tagDropTargetNode* prevDropTarget;
69 struct tagDropTargetNode* nextDropTarget;
72 typedef struct tagTrackerWindowInfo
74 IDataObject* dataObject;
75 IDropSource* dropSource;
82 HWND curTargetHWND; /* window the mouse is hovering over */
83 HWND curDragTargetHWND; /* might be a ancestor of curTargetHWND */
84 IDropTarget* curDragTarget;
87 typedef struct tagOleMenuDescriptor /* OleMenuDescriptor */
89 HWND hwndFrame; /* The containers frame window */
90 HWND hwndActiveObject; /* The active objects window */
91 OLEMENUGROUPWIDTHS mgw; /* OLE menu group widths for the shared menu */
92 HMENU hmenuCombined; /* The combined menu */
93 BOOL bIsServerItem; /* True if the currently open popup belongs to the server */
96 typedef struct tagOleMenuHookItem /* OleMenu hook item in per thread hook list */
98 DWORD tid; /* Thread Id */
99 HANDLE hHeap; /* Heap this is allocated from */
100 HHOOK GetMsg_hHook; /* message hook for WH_GETMESSAGE */
101 HHOOK CallWndProc_hHook; /* message hook for WH_CALLWNDPROC */
102 struct tagOleMenuHookItem *next;
105 static OleMenuHookItem *hook_list;
108 * This is the lock count on the OLE library. It is controlled by the
109 * OLEInitialize/OLEUninitialize methods.
111 static ULONG OLE_moduleLockCount = 0;
114 * Name of our registered window class.
116 static const char OLEDD_DRAGTRACKERCLASS[] = "WineDragDropTracker32";
119 * This is the head of the Drop target container.
121 static DropTargetNode* targetListHead = NULL;
123 /******************************************************************************
124 * These are the prototypes of miscelaneous utility methods
126 static void OLEUTL_ReadRegistryDWORDValue(HKEY regKey, DWORD* pdwValue);
128 /******************************************************************************
129 * These are the prototypes of the utility methods used to manage a shared menu
131 static void OLEMenu_Initialize();
132 static void OLEMenu_UnInitialize();
133 BOOL OLEMenu_InstallHooks( DWORD tid );
134 BOOL OLEMenu_UnInstallHooks( DWORD tid );
135 OleMenuHookItem * OLEMenu_IsHookInstalled( DWORD tid );
136 static BOOL OLEMenu_FindMainMenuIndex( HMENU hMainMenu, HMENU hPopupMenu, UINT *pnPos );
137 BOOL OLEMenu_SetIsServerMenu( HMENU hmenu, OleMenuDescriptor *pOleMenuDescriptor );
138 LRESULT CALLBACK OLEMenu_CallWndProc(INT code, WPARAM wParam, LPARAM lParam);
139 LRESULT CALLBACK OLEMenu_GetMsgProc(INT code, WPARAM wParam, LPARAM lParam);
141 /******************************************************************************
142 * These are the prototypes of the OLE Clipboard initialization methods (in clipboard.c)
144 void OLEClipbrd_UnInitialize();
145 void OLEClipbrd_Initialize();
147 /******************************************************************************
148 * These are the prototypes of the utility methods used for OLE Drag n Drop
150 static void OLEDD_Initialize();
151 static void OLEDD_UnInitialize();
152 static void OLEDD_InsertDropTarget(
153 DropTargetNode* nodeToAdd);
154 static DropTargetNode* OLEDD_ExtractDropTarget(
156 static DropTargetNode* OLEDD_FindDropTarget(
158 static LRESULT WINAPI OLEDD_DragTrackerWindowProc(
163 static void OLEDD_TrackMouseMove(
164 TrackerWindowInfo* trackerInfo,
167 static void OLEDD_TrackStateChange(
168 TrackerWindowInfo* trackerInfo,
171 static DWORD OLEDD_GetButtonState();
174 /******************************************************************************
175 * OleBuildVersion [OLE2.1]
176 * OleBuildVersion [OLE32.@]
178 DWORD WINAPI OleBuildVersion(void)
180 TRACE("Returning version %d, build %d.\n", rmm, rup);
181 return (rmm<<16)+rup;
184 /***********************************************************************
185 * OleInitialize (OLE2.2)
186 * OleInitialize (OLE32.@)
188 HRESULT WINAPI OleInitialize(LPVOID reserved)
192 TRACE("(%p)\n", reserved);
195 * The first duty of the OleInitialize is to initialize the COM libraries.
197 hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
200 * If the CoInitializeEx call failed, the OLE libraries can't be
207 * Then, it has to initialize the OLE specific modules.
211 * Object linking and Embedding
212 * In-place activation
214 if (OLE_moduleLockCount==0)
217 * Initialize the libraries.
219 TRACE("() - Initializing the OLE libraries\n");
224 OLEClipbrd_Initialize();
234 OLEMenu_Initialize();
238 * Then, we increase the lock count on the OLE module.
240 OLE_moduleLockCount++;
245 /******************************************************************************
246 * CoGetCurrentProcess [COMPOBJ.34]
247 * CoGetCurrentProcess [OLE32.@]
250 * Is DWORD really the correct return type for this function?
252 DWORD WINAPI CoGetCurrentProcess(void)
254 return GetCurrentProcessId();
257 /******************************************************************************
258 * OleUninitialize [OLE2.3]
259 * OleUninitialize [OLE32.@]
261 void WINAPI OleUninitialize(void)
266 * Decrease the lock count on the OLE module.
268 OLE_moduleLockCount--;
271 * If we hit the bottom of the lock stack, free the libraries.
273 if (OLE_moduleLockCount==0)
276 * Actually free the libraries.
278 TRACE("() - Freeing the last reference count\n");
283 OLEClipbrd_UnInitialize();
288 OLEDD_UnInitialize();
293 OLEMenu_UnInitialize();
297 * Then, uninitialize the COM libraries.
302 /******************************************************************************
303 * CoRegisterMessageFilter [OLE32.@]
305 HRESULT WINAPI CoRegisterMessageFilter(
306 LPMESSAGEFILTER lpMessageFilter, /* [in] Pointer to interface */
307 LPMESSAGEFILTER *lplpMessageFilter /* [out] Indirect pointer to prior instance if non-NULL */
310 if (lplpMessageFilter) {
311 *lplpMessageFilter = NULL;
316 /******************************************************************************
317 * OleInitializeWOW [OLE32.@]
319 HRESULT WINAPI OleInitializeWOW(DWORD x) {
320 FIXME("(0x%08lx),stub!\n",x);
324 /***********************************************************************
325 * RegisterDragDrop (OLE32.@)
327 HRESULT WINAPI RegisterDragDrop(
329 LPDROPTARGET pDropTarget)
331 DropTargetNode* dropTargetInfo;
333 TRACE("(%p,%p)\n", hwnd, pDropTarget);
339 * First, check if the window is already registered.
341 dropTargetInfo = OLEDD_FindDropTarget(hwnd);
343 if (dropTargetInfo!=NULL)
344 return DRAGDROP_E_ALREADYREGISTERED;
347 * If it's not there, we can add it. We first create a node for it.
349 dropTargetInfo = HeapAlloc(GetProcessHeap(), 0, sizeof(DropTargetNode));
351 if (dropTargetInfo==NULL)
352 return E_OUTOFMEMORY;
354 dropTargetInfo->hwndTarget = hwnd;
355 dropTargetInfo->prevDropTarget = NULL;
356 dropTargetInfo->nextDropTarget = NULL;
359 * Don't forget that this is an interface pointer, need to nail it down since
360 * we keep a copy of it.
362 dropTargetInfo->dropTarget = pDropTarget;
363 IDropTarget_AddRef(dropTargetInfo->dropTarget);
365 OLEDD_InsertDropTarget(dropTargetInfo);
370 /***********************************************************************
371 * RevokeDragDrop (OLE32.@)
373 HRESULT WINAPI RevokeDragDrop(
376 DropTargetNode* dropTargetInfo;
378 TRACE("(%p)\n", hwnd);
381 * First, check if the window is already registered.
383 dropTargetInfo = OLEDD_ExtractDropTarget(hwnd);
386 * If it ain't in there, it's an error.
388 if (dropTargetInfo==NULL)
389 return DRAGDROP_E_NOTREGISTERED;
392 * If it's in there, clean-up it's used memory and
395 IDropTarget_Release(dropTargetInfo->dropTarget);
396 HeapFree(GetProcessHeap(), 0, dropTargetInfo);
401 /***********************************************************************
402 * OleRegGetUserType (OLE32.@)
404 * This implementation of OleRegGetUserType ignores the dwFormOfType
405 * parameter and always returns the full name of the object. This is
406 * not too bad since this is the case for many objects because of the
407 * way they are registered.
409 HRESULT WINAPI OleRegGetUserType(
412 LPOLESTR* pszUserType)
422 * Initialize the out parameter.
427 * Build the key name we're looking for
429 sprintf( keyName, "CLSID\\{%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}\\",
430 clsid->Data1, clsid->Data2, clsid->Data3,
431 clsid->Data4[0], clsid->Data4[1], clsid->Data4[2], clsid->Data4[3],
432 clsid->Data4[4], clsid->Data4[5], clsid->Data4[6], clsid->Data4[7] );
434 TRACE("(%s, %ld, %p)\n", keyName, dwFormOfType, pszUserType);
437 * Open the class id Key
439 hres = RegOpenKeyA(HKEY_CLASSES_ROOT,
443 if (hres != ERROR_SUCCESS)
444 return REGDB_E_CLASSNOTREG;
447 * Retrieve the size of the name string.
451 hres = RegQueryValueExA(clsidKey,
458 if (hres!=ERROR_SUCCESS)
460 RegCloseKey(clsidKey);
461 return REGDB_E_READREGDB;
465 * Allocate a buffer for the registry value.
467 *pszUserType = CoTaskMemAlloc(cbData*2);
469 if (*pszUserType==NULL)
471 RegCloseKey(clsidKey);
472 return E_OUTOFMEMORY;
475 buffer = HeapAlloc(GetProcessHeap(), 0, cbData);
479 RegCloseKey(clsidKey);
480 CoTaskMemFree(*pszUserType);
482 return E_OUTOFMEMORY;
485 hres = RegQueryValueExA(clsidKey,
492 RegCloseKey(clsidKey);
495 if (hres!=ERROR_SUCCESS)
497 CoTaskMemFree(*pszUserType);
500 retVal = REGDB_E_READREGDB;
504 MultiByteToWideChar( CP_ACP, 0, buffer, -1, *pszUserType, cbData /*FIXME*/ );
507 HeapFree(GetProcessHeap(), 0, buffer);
512 /***********************************************************************
513 * DoDragDrop [OLE32.@]
515 HRESULT WINAPI DoDragDrop (
516 IDataObject *pDataObject, /* [in] ptr to the data obj */
517 IDropSource* pDropSource, /* [in] ptr to the source obj */
518 DWORD dwOKEffect, /* [in] effects allowed by the source */
519 DWORD *pdwEffect) /* [out] ptr to effects of the source */
521 TrackerWindowInfo trackerInfo;
522 HWND hwndTrackWindow;
525 TRACE("(DataObject %p, DropSource %p)\n", pDataObject, pDropSource);
528 * Setup the drag n drop tracking window.
530 if (!IsValidInterface((LPUNKNOWN)pDropSource))
533 trackerInfo.dataObject = pDataObject;
534 trackerInfo.dropSource = pDropSource;
535 trackerInfo.dwOKEffect = dwOKEffect;
536 trackerInfo.pdwEffect = pdwEffect;
537 trackerInfo.trackingDone = FALSE;
538 trackerInfo.escPressed = FALSE;
539 trackerInfo.curDragTargetHWND = 0;
540 trackerInfo.curTargetHWND = 0;
541 trackerInfo.curDragTarget = 0;
543 hwndTrackWindow = CreateWindowA(OLEDD_DRAGTRACKERCLASS,
546 CW_USEDEFAULT, CW_USEDEFAULT,
547 CW_USEDEFAULT, CW_USEDEFAULT,
551 (LPVOID)&trackerInfo);
553 if (hwndTrackWindow!=0)
556 * Capture the mouse input
558 SetCapture(hwndTrackWindow);
561 * Pump messages. All mouse input should go the the capture window.
563 while (!trackerInfo.trackingDone && GetMessageA(&msg, 0, 0, 0) )
565 if ( (msg.message >= WM_KEYFIRST) &&
566 (msg.message <= WM_KEYLAST) )
569 * When keyboard messages are sent to windows on this thread, we
570 * want to ignore notify the drop source that the state changed.
571 * in the case of the Escape key, we also notify the drop source
572 * we give it a special meaning.
574 if ( (msg.message==WM_KEYDOWN) &&
575 (msg.wParam==VK_ESCAPE) )
577 trackerInfo.escPressed = TRUE;
581 * Notify the drop source.
583 OLEDD_TrackStateChange(&trackerInfo,
585 OLEDD_GetButtonState());
590 * Dispatch the messages only when it's not a keyboard message.
592 DispatchMessageA(&msg);
597 * Destroy the temporary window.
599 DestroyWindow(hwndTrackWindow);
601 return trackerInfo.returnValue;
607 /***********************************************************************
608 * OleQueryLinkFromData [OLE32.@]
610 HRESULT WINAPI OleQueryLinkFromData(
611 IDataObject* pSrcDataObject)
613 FIXME("(%p),stub!\n", pSrcDataObject);
617 /***********************************************************************
618 * OleRegGetMiscStatus [OLE32.@]
620 HRESULT WINAPI OleRegGetMiscStatus(
632 * Initialize the out parameter.
637 * Build the key name we're looking for
639 sprintf( keyName, "CLSID\\{%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}\\",
640 clsid->Data1, clsid->Data2, clsid->Data3,
641 clsid->Data4[0], clsid->Data4[1], clsid->Data4[2], clsid->Data4[3],
642 clsid->Data4[4], clsid->Data4[5], clsid->Data4[6], clsid->Data4[7] );
644 TRACE("(%s, %ld, %p)\n", keyName, dwAspect, pdwStatus);
647 * Open the class id Key
649 result = RegOpenKeyA(HKEY_CLASSES_ROOT,
653 if (result != ERROR_SUCCESS)
654 return REGDB_E_CLASSNOTREG;
659 result = RegOpenKeyA(clsidKey,
664 if (result != ERROR_SUCCESS)
666 RegCloseKey(clsidKey);
667 return REGDB_E_READREGDB;
671 * Read the default value
673 OLEUTL_ReadRegistryDWORDValue(miscStatusKey, pdwStatus);
676 * Open the key specific to the requested aspect.
678 sprintf(keyName, "%ld", dwAspect);
680 result = RegOpenKeyA(miscStatusKey,
684 if (result == ERROR_SUCCESS)
686 OLEUTL_ReadRegistryDWORDValue(aspectKey, pdwStatus);
687 RegCloseKey(aspectKey);
693 RegCloseKey(miscStatusKey);
694 RegCloseKey(clsidKey);
699 /******************************************************************************
700 * OleSetContainedObject [OLE32.@]
702 HRESULT WINAPI OleSetContainedObject(
706 IRunnableObject* runnable = NULL;
709 TRACE("(%p,%x), stub!\n", pUnknown, fContained);
711 hres = IUnknown_QueryInterface(pUnknown,
712 &IID_IRunnableObject,
717 hres = IRunnableObject_SetContainedObject(runnable, fContained);
719 IRunnableObject_Release(runnable);
727 /******************************************************************************
730 HRESULT WINAPI OleLoad(
733 LPOLECLIENTSITE pClientSite,
736 IPersistStorage* persistStorage = NULL;
737 IOleObject* oleObject = NULL;
741 TRACE("(%p,%p,%p,%p)\n", pStg, riid, pClientSite, ppvObj);
744 * TODO, Conversion ... OleDoAutoConvert
748 * Get the class ID for the object.
750 hres = IStorage_Stat(pStg, &storageInfo, STATFLAG_NONAME);
753 * Now, try and create the handler for the object
755 hres = CoCreateInstance(&storageInfo.clsid,
757 CLSCTX_INPROC_HANDLER,
762 * If that fails, as it will most times, load the default
767 hres = OleCreateDefaultHandler(&storageInfo.clsid,
774 * If we couldn't find a handler... this is bad. Abort the whole thing.
780 * Inform the new object of it's client site.
782 hres = IOleObject_SetClientSite(oleObject, pClientSite);
785 * Initialize the object with it's IPersistStorage interface.
787 hres = IOleObject_QueryInterface(oleObject,
788 &IID_IPersistStorage,
789 (void**)&persistStorage);
793 IPersistStorage_Load(persistStorage, pStg);
795 IPersistStorage_Release(persistStorage);
796 persistStorage = NULL;
800 * Return the requested interface to the caller.
802 hres = IOleObject_QueryInterface(oleObject, riid, ppvObj);
805 * Cleanup interfaces used internally
807 IOleObject_Release(oleObject);
812 /***********************************************************************
815 HRESULT WINAPI OleSave(
816 LPPERSISTSTORAGE pPS,
823 TRACE("(%p,%p,%x)\n", pPS, pStg, fSameAsLoad);
826 * First, we transfer the class ID (if available)
828 hres = IPersistStorage_GetClassID(pPS, &objectClass);
832 WriteClassStg(pStg, &objectClass);
836 * Then, we ask the object to save itself to the
837 * storage. If it is successful, we commit the storage.
839 hres = IPersistStorage_Save(pPS, pStg, fSameAsLoad);
843 IStorage_Commit(pStg,
851 /******************************************************************************
852 * OleLockRunning [OLE32.@]
854 HRESULT WINAPI OleLockRunning(LPUNKNOWN pUnknown, BOOL fLock, BOOL fLastUnlockCloses)
856 IRunnableObject* runnable = NULL;
859 TRACE("(%p,%x,%x)\n", pUnknown, fLock, fLastUnlockCloses);
861 hres = IUnknown_QueryInterface(pUnknown,
862 &IID_IRunnableObject,
867 hres = IRunnableObject_LockRunning(runnable, fLock, fLastUnlockCloses);
869 IRunnableObject_Release(runnable);
878 /**************************************************************************
879 * Internal methods to manage the shared OLE menu in response to the
880 * OLE***MenuDescriptor API
884 * OLEMenu_Initialize()
886 * Initializes the OLEMENU data structures.
888 static void OLEMenu_Initialize()
893 * OLEMenu_UnInitialize()
895 * Releases the OLEMENU data structures.
897 static void OLEMenu_UnInitialize()
901 /*************************************************************************
902 * OLEMenu_InstallHooks
903 * Install thread scope message hooks for WH_GETMESSAGE and WH_CALLWNDPROC
905 * RETURNS: TRUE if message hooks were successfully installed
908 BOOL OLEMenu_InstallHooks( DWORD tid )
910 OleMenuHookItem *pHookItem = NULL;
912 /* Create an entry for the hook table */
913 if ( !(pHookItem = HeapAlloc(GetProcessHeap(), 0,
914 sizeof(OleMenuHookItem)) ) )
917 pHookItem->tid = tid;
918 pHookItem->hHeap = GetProcessHeap();
920 /* Install a thread scope message hook for WH_GETMESSAGE */
921 pHookItem->GetMsg_hHook = SetWindowsHookExA( WH_GETMESSAGE, OLEMenu_GetMsgProc,
922 0, GetCurrentThreadId() );
923 if ( !pHookItem->GetMsg_hHook )
926 /* Install a thread scope message hook for WH_CALLWNDPROC */
927 pHookItem->CallWndProc_hHook = SetWindowsHookExA( WH_CALLWNDPROC, OLEMenu_CallWndProc,
928 0, GetCurrentThreadId() );
929 if ( !pHookItem->CallWndProc_hHook )
932 /* Insert the hook table entry */
933 pHookItem->next = hook_list;
934 hook_list = pHookItem;
939 /* Unhook any hooks */
940 if ( pHookItem->GetMsg_hHook )
941 UnhookWindowsHookEx( pHookItem->GetMsg_hHook );
942 if ( pHookItem->CallWndProc_hHook )
943 UnhookWindowsHookEx( pHookItem->CallWndProc_hHook );
944 /* Release the hook table entry */
945 HeapFree(pHookItem->hHeap, 0, pHookItem );
950 /*************************************************************************
951 * OLEMenu_UnInstallHooks
952 * UnInstall thread scope message hooks for WH_GETMESSAGE and WH_CALLWNDPROC
954 * RETURNS: TRUE if message hooks were successfully installed
957 BOOL OLEMenu_UnInstallHooks( DWORD tid )
959 OleMenuHookItem *pHookItem = NULL;
960 OleMenuHookItem **ppHook = &hook_list;
964 if ((*ppHook)->tid == tid)
967 *ppHook = pHookItem->next;
970 ppHook = &(*ppHook)->next;
972 if (!pHookItem) return FALSE;
974 /* Uninstall the hooks installed for this thread */
975 if ( !UnhookWindowsHookEx( pHookItem->GetMsg_hHook ) )
977 if ( !UnhookWindowsHookEx( pHookItem->CallWndProc_hHook ) )
980 /* Release the hook table entry */
981 HeapFree(pHookItem->hHeap, 0, pHookItem );
986 /* Release the hook table entry */
988 HeapFree(pHookItem->hHeap, 0, pHookItem );
993 /*************************************************************************
994 * OLEMenu_IsHookInstalled
995 * Tests if OLEMenu hooks have been installed for a thread
997 * RETURNS: The pointer and index of the hook table entry for the tid
998 * NULL and -1 for the index if no hooks were installed for this thread
1000 OleMenuHookItem * OLEMenu_IsHookInstalled( DWORD tid )
1002 OleMenuHookItem *pHookItem = NULL;
1004 /* Do a simple linear search for an entry whose tid matches ours.
1005 * We really need a map but efficiency is not a concern here. */
1006 for (pHookItem = hook_list; pHookItem; pHookItem = pHookItem->next)
1008 if ( tid == pHookItem->tid )
1015 /***********************************************************************
1016 * OLEMenu_FindMainMenuIndex
1018 * Used by OLEMenu API to find the top level group a menu item belongs to.
1019 * On success pnPos contains the index of the item in the top level menu group
1021 * RETURNS: TRUE if the ID was found, FALSE on failure
1023 static BOOL OLEMenu_FindMainMenuIndex( HMENU hMainMenu, HMENU hPopupMenu, UINT *pnPos )
1027 nItems = GetMenuItemCount( hMainMenu );
1029 for (i = 0; i < nItems; i++)
1033 /* Is the current item a submenu? */
1034 if ( (hsubmenu = GetSubMenu(hMainMenu, i)) )
1036 /* If the handle is the same we're done */
1037 if ( hsubmenu == hPopupMenu )
1043 /* Recursively search without updating pnPos */
1044 else if ( OLEMenu_FindMainMenuIndex( hsubmenu, hPopupMenu, NULL ) )
1056 /***********************************************************************
1057 * OLEMenu_SetIsServerMenu
1059 * Checks whether a popup menu belongs to a shared menu group which is
1060 * owned by the server, and sets the menu descriptor state accordingly.
1061 * All menu messages from these groups should be routed to the server.
1063 * RETURNS: TRUE if the popup menu is part of a server owned group
1064 * FASE if the popup menu is part of a container owned group
1066 BOOL OLEMenu_SetIsServerMenu( HMENU hmenu, OleMenuDescriptor *pOleMenuDescriptor )
1068 UINT nPos = 0, nWidth, i;
1070 pOleMenuDescriptor->bIsServerItem = FALSE;
1072 /* Don't bother searching if the popup is the combined menu itself */
1073 if ( hmenu == pOleMenuDescriptor->hmenuCombined )
1076 /* Find the menu item index in the shared OLE menu that this item belongs to */
1077 if ( !OLEMenu_FindMainMenuIndex( pOleMenuDescriptor->hmenuCombined, hmenu, &nPos ) )
1080 /* The group widths array has counts for the number of elements
1081 * in the groups File, Edit, Container, Object, Window, Help.
1082 * The Edit, Object & Help groups belong to the server object
1083 * and the other three belong to the container.
1084 * Loop through the group widths and locate the group we are a member of.
1086 for ( i = 0, nWidth = 0; i < 6; i++ )
1088 nWidth += pOleMenuDescriptor->mgw.width[i];
1089 if ( nPos < nWidth )
1091 /* Odd elements are server menu widths */
1092 pOleMenuDescriptor->bIsServerItem = (i%2) ? TRUE : FALSE;
1097 return pOleMenuDescriptor->bIsServerItem;
1100 /*************************************************************************
1101 * OLEMenu_CallWndProc
1102 * Thread scope WH_CALLWNDPROC hook proc filter function (callback)
1103 * This is invoked from a message hook installed in OleSetMenuDescriptor.
1105 LRESULT CALLBACK OLEMenu_CallWndProc(INT code, WPARAM wParam, LPARAM lParam)
1107 LPCWPSTRUCT pMsg = NULL;
1108 HOLEMENU hOleMenu = 0;
1109 OleMenuDescriptor *pOleMenuDescriptor = NULL;
1110 OleMenuHookItem *pHookItem = NULL;
1113 TRACE("%i, %04x, %08x\n", code, wParam, (unsigned)lParam );
1115 /* Check if we're being asked to process the message */
1116 if ( HC_ACTION != code )
1119 /* Retrieve the current message being dispatched from lParam */
1120 pMsg = (LPCWPSTRUCT)lParam;
1122 /* Check if the message is destined for a window we are interested in:
1123 * If the window has an OLEMenu property we may need to dispatch
1124 * the menu message to its active objects window instead. */
1126 hOleMenu = (HOLEMENU)GetPropA( pMsg->hwnd, "PROP_OLEMenuDescriptor" );
1130 /* Get the menu descriptor */
1131 pOleMenuDescriptor = (OleMenuDescriptor *) GlobalLock( hOleMenu );
1132 if ( !pOleMenuDescriptor ) /* Bad descriptor! */
1135 /* Process menu messages */
1136 switch( pMsg->message )
1140 /* Reset the menu descriptor state */
1141 pOleMenuDescriptor->bIsServerItem = FALSE;
1143 /* Send this message to the server as well */
1144 SendMessageA( pOleMenuDescriptor->hwndActiveObject,
1145 pMsg->message, pMsg->wParam, pMsg->lParam );
1149 case WM_INITMENUPOPUP:
1151 /* Save the state for whether this is a server owned menu */
1152 OLEMenu_SetIsServerMenu( (HMENU)pMsg->wParam, pOleMenuDescriptor );
1158 fuFlags = HIWORD(pMsg->wParam); /* Get flags */
1159 if ( fuFlags & MF_SYSMENU )
1162 /* Save the state for whether this is a server owned popup menu */
1163 else if ( fuFlags & MF_POPUP )
1164 OLEMenu_SetIsServerMenu( (HMENU)pMsg->lParam, pOleMenuDescriptor );
1171 LPDRAWITEMSTRUCT lpdis = (LPDRAWITEMSTRUCT) pMsg->lParam;
1172 if ( pMsg->wParam != 0 || lpdis->CtlType != ODT_MENU )
1173 goto NEXTHOOK; /* Not a menu message */
1182 /* If the message was for the server dispatch it accordingly */
1183 if ( pOleMenuDescriptor->bIsServerItem )
1185 SendMessageA( pOleMenuDescriptor->hwndActiveObject,
1186 pMsg->message, pMsg->wParam, pMsg->lParam );
1190 if ( pOleMenuDescriptor )
1191 GlobalUnlock( hOleMenu );
1193 /* Lookup the hook item for the current thread */
1194 if ( !( pHookItem = OLEMenu_IsHookInstalled( GetCurrentThreadId() ) ) )
1196 /* This should never fail!! */
1197 WARN("could not retrieve hHook for current thread!\n" );
1201 /* Pass on the message to the next hooker */
1202 return CallNextHookEx( pHookItem->CallWndProc_hHook, code, wParam, lParam );
1205 /*************************************************************************
1206 * OLEMenu_GetMsgProc
1207 * Thread scope WH_GETMESSAGE hook proc filter function (callback)
1208 * This is invoked from a message hook installed in OleSetMenuDescriptor.
1210 LRESULT CALLBACK OLEMenu_GetMsgProc(INT code, WPARAM wParam, LPARAM lParam)
1213 HOLEMENU hOleMenu = 0;
1214 OleMenuDescriptor *pOleMenuDescriptor = NULL;
1215 OleMenuHookItem *pHookItem = NULL;
1218 TRACE("%i, %04x, %08x\n", code, wParam, (unsigned)lParam );
1220 /* Check if we're being asked to process a messages */
1221 if ( HC_ACTION != code )
1224 /* Retrieve the current message being dispatched from lParam */
1225 pMsg = (LPMSG)lParam;
1227 /* Check if the message is destined for a window we are interested in:
1228 * If the window has an OLEMenu property we may need to dispatch
1229 * the menu message to its active objects window instead. */
1231 hOleMenu = (HOLEMENU)GetPropA( pMsg->hwnd, "PROP_OLEMenuDescriptor" );
1235 /* Process menu messages */
1236 switch( pMsg->message )
1240 wCode = HIWORD(pMsg->wParam); /* Get notification code */
1242 goto NEXTHOOK; /* Not a menu message */
1249 /* Get the menu descriptor */
1250 pOleMenuDescriptor = (OleMenuDescriptor *) GlobalLock( hOleMenu );
1251 if ( !pOleMenuDescriptor ) /* Bad descriptor! */
1254 /* If the message was for the server dispatch it accordingly */
1255 if ( pOleMenuDescriptor->bIsServerItem )
1257 /* Change the hWnd in the message to the active objects hWnd.
1258 * The message loop which reads this message will automatically
1259 * dispatch it to the embedded objects window. */
1260 pMsg->hwnd = pOleMenuDescriptor->hwndActiveObject;
1264 if ( pOleMenuDescriptor )
1265 GlobalUnlock( hOleMenu );
1267 /* Lookup the hook item for the current thread */
1268 if ( !( pHookItem = OLEMenu_IsHookInstalled( GetCurrentThreadId() ) ) )
1270 /* This should never fail!! */
1271 WARN("could not retrieve hHook for current thread!\n" );
1275 /* Pass on the message to the next hooker */
1276 return CallNextHookEx( pHookItem->GetMsg_hHook, code, wParam, lParam );
1279 /***********************************************************************
1280 * OleCreateMenuDescriptor [OLE32.@]
1281 * Creates an OLE menu descriptor for OLE to use when dispatching
1282 * menu messages and commands.
1285 * hmenuCombined - Handle to the objects combined menu
1286 * lpMenuWidths - Pointer to array of 6 LONG's indicating menus per group
1289 HOLEMENU WINAPI OleCreateMenuDescriptor(
1290 HMENU hmenuCombined,
1291 LPOLEMENUGROUPWIDTHS lpMenuWidths)
1294 OleMenuDescriptor *pOleMenuDescriptor;
1297 if ( !hmenuCombined || !lpMenuWidths )
1300 /* Create an OLE menu descriptor */
1301 if ( !(hOleMenu = GlobalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT,
1302 sizeof(OleMenuDescriptor) ) ) )
1305 pOleMenuDescriptor = (OleMenuDescriptor *) GlobalLock( hOleMenu );
1306 if ( !pOleMenuDescriptor )
1309 /* Initialize menu group widths and hmenu */
1310 for ( i = 0; i < 6; i++ )
1311 pOleMenuDescriptor->mgw.width[i] = lpMenuWidths->width[i];
1313 pOleMenuDescriptor->hmenuCombined = hmenuCombined;
1314 pOleMenuDescriptor->bIsServerItem = FALSE;
1315 GlobalUnlock( hOleMenu );
1320 /***********************************************************************
1321 * OleDestroyMenuDescriptor [OLE32.@]
1322 * Destroy the shared menu descriptor
1324 HRESULT WINAPI OleDestroyMenuDescriptor(
1325 HOLEMENU hmenuDescriptor)
1327 if ( hmenuDescriptor )
1328 GlobalFree( hmenuDescriptor );
1332 /***********************************************************************
1333 * OleSetMenuDescriptor [OLE32.@]
1334 * Installs or removes OLE dispatching code for the containers frame window
1335 * FIXME: The lpFrame and lpActiveObject parameters are currently ignored
1336 * OLE should install context sensitive help F1 filtering for the app when
1337 * these are non null.
1340 * hOleMenu Handle to composite menu descriptor
1341 * hwndFrame Handle to containers frame window
1342 * hwndActiveObject Handle to objects in-place activation window
1343 * lpFrame Pointer to IOleInPlaceFrame on containers window
1344 * lpActiveObject Pointer to IOleInPlaceActiveObject on active in-place object
1347 * S_OK - menu installed correctly
1348 * E_FAIL, E_INVALIDARG, E_UNEXPECTED - failure
1350 HRESULT WINAPI OleSetMenuDescriptor(
1353 HWND hwndActiveObject,
1354 LPOLEINPLACEFRAME lpFrame,
1355 LPOLEINPLACEACTIVEOBJECT lpActiveObject)
1357 OleMenuDescriptor *pOleMenuDescriptor = NULL;
1360 if ( !hwndFrame || (hOleMenu && !hwndActiveObject) )
1361 return E_INVALIDARG;
1363 if ( lpFrame || lpActiveObject )
1365 FIXME("(%x, %p, %p, %p, %p), Context sensitive help filtering not implemented!\n",
1366 (unsigned int)hOleMenu,
1373 /* Set up a message hook to intercept the containers frame window messages.
1374 * The message filter is responsible for dispatching menu messages from the
1375 * shared menu which are intended for the object.
1378 if ( hOleMenu ) /* Want to install dispatching code */
1380 /* If OLEMenu hooks are already installed for this thread, fail
1381 * Note: This effectively means that OleSetMenuDescriptor cannot
1382 * be called twice in succession on the same frame window
1383 * without first calling it with a null hOleMenu to uninstall */
1384 if ( OLEMenu_IsHookInstalled( GetCurrentThreadId() ) )
1387 /* Get the menu descriptor */
1388 pOleMenuDescriptor = (OleMenuDescriptor *) GlobalLock( hOleMenu );
1389 if ( !pOleMenuDescriptor )
1390 return E_UNEXPECTED;
1392 /* Update the menu descriptor */
1393 pOleMenuDescriptor->hwndFrame = hwndFrame;
1394 pOleMenuDescriptor->hwndActiveObject = hwndActiveObject;
1396 GlobalUnlock( hOleMenu );
1397 pOleMenuDescriptor = NULL;
1399 /* Add a menu descriptor windows property to the frame window */
1400 SetPropA( hwndFrame, "PROP_OLEMenuDescriptor", hOleMenu );
1402 /* Install thread scope message hooks for WH_GETMESSAGE and WH_CALLWNDPROC */
1403 if ( !OLEMenu_InstallHooks( GetCurrentThreadId() ) )
1406 else /* Want to uninstall dispatching code */
1408 /* Uninstall the hooks */
1409 if ( !OLEMenu_UnInstallHooks( GetCurrentThreadId() ) )
1412 /* Remove the menu descriptor property from the frame window */
1413 RemovePropA( hwndFrame, "PROP_OLEMenuDescriptor" );
1419 /******************************************************************************
1420 * IsAccelerator [OLE32.@]
1421 * Mostly copied from controls/menu.c TranslateAccelerator implementation
1423 BOOL WINAPI IsAccelerator(HACCEL hAccel, int cAccelEntries, LPMSG lpMsg, WORD* lpwCmd)
1428 if(!lpMsg) return FALSE;
1431 WARN_(accel)("NULL accel handle\n");
1434 if((lpMsg->message != WM_KEYDOWN &&
1435 lpMsg->message != WM_KEYUP &&
1436 lpMsg->message != WM_SYSKEYDOWN &&
1437 lpMsg->message != WM_SYSKEYUP &&
1438 lpMsg->message != WM_CHAR)) return FALSE;
1439 lpAccelTbl = HeapAlloc(GetProcessHeap(), 0, cAccelEntries * sizeof(ACCEL));
1440 if (NULL == lpAccelTbl)
1444 if (CopyAcceleratorTableW(hAccel, lpAccelTbl, cAccelEntries) != cAccelEntries)
1446 WARN_(accel)("CopyAcceleratorTableW failed\n");
1447 HeapFree(GetProcessHeap(), 0, lpAccelTbl);
1451 TRACE_(accel)("hAccel=%p, cAccelEntries=%d,"
1452 "msg->hwnd=%p, msg->message=%04x, wParam=%08x, lParam=%08lx\n",
1453 hAccel, cAccelEntries,
1454 lpMsg->hwnd, lpMsg->message, lpMsg->wParam, lpMsg->lParam);
1455 for(i = 0; i < cAccelEntries; i++)
1457 if(lpAccelTbl[i].key != lpMsg->wParam)
1460 if(lpMsg->message == WM_CHAR)
1462 if(!(lpAccelTbl[i].fVirt & FALT) && !(lpAccelTbl[i].fVirt & FVIRTKEY))
1464 TRACE_(accel)("found accel for WM_CHAR: ('%c')\n", lpMsg->wParam & 0xff);
1470 if(lpAccelTbl[i].fVirt & FVIRTKEY)
1473 TRACE_(accel)("found accel for virt_key %04x (scan %04x)\n",
1474 lpMsg->wParam, HIWORD(lpMsg->lParam) & 0xff);
1475 if(GetKeyState(VK_SHIFT) & 0x8000) mask |= FSHIFT;
1476 if(GetKeyState(VK_CONTROL) & 0x8000) mask |= FCONTROL;
1477 if(GetKeyState(VK_MENU) & 0x8000) mask |= FALT;
1478 if(mask == (lpAccelTbl[i].fVirt & (FSHIFT | FCONTROL | FALT))) goto found;
1479 TRACE_(accel)("incorrect SHIFT/CTRL/ALT-state\n");
1483 if(!(lpMsg->lParam & 0x01000000)) /* no special_key */
1485 if((lpAccelTbl[i].fVirt & FALT) && (lpMsg->lParam & 0x20000000))
1486 { /* ^^ ALT pressed */
1487 TRACE_(accel)("found accel for Alt-%c\n", lpMsg->wParam & 0xff);
1495 WARN_(accel)("couldn't translate accelerator key\n");
1496 HeapFree(GetProcessHeap(), 0, lpAccelTbl);
1500 if(lpwCmd) *lpwCmd = lpAccelTbl[i].cmd;
1501 HeapFree(GetProcessHeap(), 0, lpAccelTbl);
1505 /***********************************************************************
1506 * ReleaseStgMedium [OLE32.@]
1508 void WINAPI ReleaseStgMedium(
1511 switch (pmedium->tymed)
1515 if ( (pmedium->pUnkForRelease==0) &&
1516 (pmedium->u.hGlobal!=0) )
1517 GlobalFree(pmedium->u.hGlobal);
1522 if (pmedium->u.lpszFileName!=0)
1524 if (pmedium->pUnkForRelease==0)
1526 DeleteFileW(pmedium->u.lpszFileName);
1529 CoTaskMemFree(pmedium->u.lpszFileName);
1535 if (pmedium->u.pstm!=0)
1537 IStream_Release(pmedium->u.pstm);
1541 case TYMED_ISTORAGE:
1543 if (pmedium->u.pstg!=0)
1545 IStorage_Release(pmedium->u.pstg);
1551 if ( (pmedium->pUnkForRelease==0) &&
1552 (pmedium->u.hBitmap!=0) )
1553 DeleteObject(pmedium->u.hBitmap);
1558 if ( (pmedium->pUnkForRelease==0) &&
1559 (pmedium->u.hMetaFilePict!=0) )
1561 LPMETAFILEPICT pMP = GlobalLock(pmedium->u.hMetaFilePict);
1562 DeleteMetaFile(pMP->hMF);
1563 GlobalUnlock(pmedium->u.hMetaFilePict);
1564 GlobalFree(pmedium->u.hMetaFilePict);
1570 if ( (pmedium->pUnkForRelease==0) &&
1571 (pmedium->u.hEnhMetaFile!=0) )
1573 DeleteEnhMetaFile(pmedium->u.hEnhMetaFile);
1581 pmedium->tymed=TYMED_NULL;
1584 * After cleaning up, the unknown is released
1586 if (pmedium->pUnkForRelease!=0)
1588 IUnknown_Release(pmedium->pUnkForRelease);
1589 pmedium->pUnkForRelease = 0;
1594 * OLEDD_Initialize()
1596 * Initializes the OLE drag and drop data structures.
1598 static void OLEDD_Initialize()
1602 ZeroMemory (&wndClass, sizeof(WNDCLASSA));
1603 wndClass.style = CS_GLOBALCLASS;
1604 wndClass.lpfnWndProc = (WNDPROC)OLEDD_DragTrackerWindowProc;
1605 wndClass.cbClsExtra = 0;
1606 wndClass.cbWndExtra = sizeof(TrackerWindowInfo*);
1607 wndClass.hCursor = 0;
1608 wndClass.hbrBackground = 0;
1609 wndClass.lpszClassName = OLEDD_DRAGTRACKERCLASS;
1611 RegisterClassA (&wndClass);
1615 * OLEDD_UnInitialize()
1617 * Releases the OLE drag and drop data structures.
1619 static void OLEDD_UnInitialize()
1622 * Simply empty the list.
1624 while (targetListHead!=NULL)
1626 RevokeDragDrop(targetListHead->hwndTarget);
1631 * OLEDD_InsertDropTarget()
1633 * Insert the target node in the tree.
1635 static void OLEDD_InsertDropTarget(DropTargetNode* nodeToAdd)
1637 DropTargetNode* curNode;
1638 DropTargetNode** parentNodeLink;
1641 * Iterate the tree to find the insertion point.
1643 curNode = targetListHead;
1644 parentNodeLink = &targetListHead;
1646 while (curNode!=NULL)
1648 if (nodeToAdd->hwndTarget<curNode->hwndTarget)
1651 * If the node we want to add has a smaller HWND, go left
1653 parentNodeLink = &curNode->prevDropTarget;
1654 curNode = curNode->prevDropTarget;
1656 else if (nodeToAdd->hwndTarget>curNode->hwndTarget)
1659 * If the node we want to add has a larger HWND, go right
1661 parentNodeLink = &curNode->nextDropTarget;
1662 curNode = curNode->nextDropTarget;
1667 * The item was found in the list. It shouldn't have been there
1675 * If we get here, we have found a spot for our item. The parentNodeLink
1676 * pointer points to the pointer that we have to modify.
1677 * The curNode should be NULL. We just have to establish the link and Voila!
1679 assert(curNode==NULL);
1680 assert(parentNodeLink!=NULL);
1681 assert(*parentNodeLink==NULL);
1683 *parentNodeLink=nodeToAdd;
1687 * OLEDD_ExtractDropTarget()
1689 * Removes the target node from the tree.
1691 static DropTargetNode* OLEDD_ExtractDropTarget(HWND hwndOfTarget)
1693 DropTargetNode* curNode;
1694 DropTargetNode** parentNodeLink;
1697 * Iterate the tree to find the insertion point.
1699 curNode = targetListHead;
1700 parentNodeLink = &targetListHead;
1702 while (curNode!=NULL)
1704 if (hwndOfTarget<curNode->hwndTarget)
1707 * If the node we want to add has a smaller HWND, go left
1709 parentNodeLink = &curNode->prevDropTarget;
1710 curNode = curNode->prevDropTarget;
1712 else if (hwndOfTarget>curNode->hwndTarget)
1715 * If the node we want to add has a larger HWND, go right
1717 parentNodeLink = &curNode->nextDropTarget;
1718 curNode = curNode->nextDropTarget;
1723 * The item was found in the list. Detach it from it's parent and
1724 * re-insert it's kids in the tree.
1726 assert(parentNodeLink!=NULL);
1727 assert(*parentNodeLink==curNode);
1730 * We arbitrately re-attach the left sub-tree to the parent.
1732 *parentNodeLink = curNode->prevDropTarget;
1735 * And we re-insert the right subtree
1737 if (curNode->nextDropTarget!=NULL)
1739 OLEDD_InsertDropTarget(curNode->nextDropTarget);
1743 * The node we found is still a valid node once we complete
1744 * the unlinking of the kids.
1746 curNode->nextDropTarget=NULL;
1747 curNode->prevDropTarget=NULL;
1754 * If we get here, the node is not in the tree
1760 * OLEDD_FindDropTarget()
1762 * Finds information about the drop target.
1764 static DropTargetNode* OLEDD_FindDropTarget(HWND hwndOfTarget)
1766 DropTargetNode* curNode;
1769 * Iterate the tree to find the HWND value.
1771 curNode = targetListHead;
1773 while (curNode!=NULL)
1775 if (hwndOfTarget<curNode->hwndTarget)
1778 * If the node we want to add has a smaller HWND, go left
1780 curNode = curNode->prevDropTarget;
1782 else if (hwndOfTarget>curNode->hwndTarget)
1785 * If the node we want to add has a larger HWND, go right
1787 curNode = curNode->nextDropTarget;
1792 * The item was found in the list.
1799 * If we get here, the item is not in the list
1805 * OLEDD_DragTrackerWindowProc()
1807 * This method is the WindowProcedure of the drag n drop tracking
1808 * window. During a drag n Drop operation, an invisible window is created
1809 * to receive the user input and act upon it. This procedure is in charge
1812 static LRESULT WINAPI OLEDD_DragTrackerWindowProc(
1822 LPCREATESTRUCTA createStruct = (LPCREATESTRUCTA)lParam;
1824 SetWindowLongA(hwnd, 0, (LONG)createStruct->lpCreateParams);
1831 TrackerWindowInfo* trackerInfo = (TrackerWindowInfo*)GetWindowLongA(hwnd, 0);
1835 * Get the current mouse position in screen coordinates.
1837 mousePos.x = LOWORD(lParam);
1838 mousePos.y = HIWORD(lParam);
1839 ClientToScreen(hwnd, &mousePos);
1842 * Track the movement of the mouse.
1844 OLEDD_TrackMouseMove(trackerInfo, mousePos, wParam);
1851 case WM_LBUTTONDOWN:
1852 case WM_MBUTTONDOWN:
1853 case WM_RBUTTONDOWN:
1855 TrackerWindowInfo* trackerInfo = (TrackerWindowInfo*)GetWindowLongA(hwnd, 0);
1859 * Get the current mouse position in screen coordinates.
1861 mousePos.x = LOWORD(lParam);
1862 mousePos.y = HIWORD(lParam);
1863 ClientToScreen(hwnd, &mousePos);
1866 * Notify everyone that the button state changed
1867 * TODO: Check if the "escape" key was pressed.
1869 OLEDD_TrackStateChange(trackerInfo, mousePos, wParam);
1876 * This is a window proc after all. Let's call the default.
1878 return DefWindowProcA (hwnd, uMsg, wParam, lParam);
1882 * OLEDD_TrackMouseMove()
1884 * This method is invoked while a drag and drop operation is in effect.
1885 * it will generate the appropriate callbacks in the drop source
1886 * and drop target. It will also provide the expected feedback to
1890 * trackerInfo - Pointer to the structure identifying the
1891 * drag & drop operation that is currently
1893 * mousePos - Current position of the mouse in screen
1895 * keyState - Contains the state of the shift keys and the
1896 * mouse buttons (MK_LBUTTON and the like)
1898 static void OLEDD_TrackMouseMove(
1899 TrackerWindowInfo* trackerInfo,
1903 HWND hwndNewTarget = 0;
1907 * Get the handle of the window under the mouse
1909 hwndNewTarget = WindowFromPoint(mousePos);
1912 * Every time, we re-initialize the effects passed to the
1913 * IDropTarget to the effects allowed by the source.
1915 *trackerInfo->pdwEffect = trackerInfo->dwOKEffect;
1918 * If we are hovering over the same target as before, send the
1919 * DragOver notification
1921 if ( (trackerInfo->curDragTarget != 0) &&
1922 (trackerInfo->curTargetHWND == hwndNewTarget) )
1924 POINTL mousePosParam;
1927 * The documentation tells me that the coordinate should be in the target
1928 * window's coordinate space. However, the tests I made tell me the
1929 * coordinates should be in screen coordinates.
1931 mousePosParam.x = mousePos.x;
1932 mousePosParam.y = mousePos.y;
1934 IDropTarget_DragOver(trackerInfo->curDragTarget,
1937 trackerInfo->pdwEffect);
1941 DropTargetNode* newDropTargetNode = 0;
1944 * If we changed window, we have to notify our old target and check for
1947 if (trackerInfo->curDragTarget!=0)
1949 IDropTarget_DragLeave(trackerInfo->curDragTarget);
1953 * Make sure we're hovering over a window.
1955 if (hwndNewTarget!=0)
1958 * Find-out if there is a drag target under the mouse
1960 HWND nexttar = hwndNewTarget;
1961 trackerInfo->curTargetHWND = hwndNewTarget;
1964 newDropTargetNode = OLEDD_FindDropTarget(nexttar);
1965 } while (!newDropTargetNode && (nexttar = GetParent(nexttar)) != 0);
1966 if(nexttar) hwndNewTarget = nexttar;
1968 trackerInfo->curDragTargetHWND = hwndNewTarget;
1969 trackerInfo->curDragTarget = newDropTargetNode ? newDropTargetNode->dropTarget : 0;
1972 * If there is, notify it that we just dragged-in
1974 if (trackerInfo->curDragTarget!=0)
1976 POINTL mousePosParam;
1979 * The documentation tells me that the coordinate should be in the target
1980 * window's coordinate space. However, the tests I made tell me the
1981 * coordinates should be in screen coordinates.
1983 mousePosParam.x = mousePos.x;
1984 mousePosParam.y = mousePos.y;
1986 IDropTarget_DragEnter(trackerInfo->curDragTarget,
1987 trackerInfo->dataObject,
1990 trackerInfo->pdwEffect);
1996 * The mouse is not over a window so we don't track anything.
1998 trackerInfo->curDragTargetHWND = 0;
1999 trackerInfo->curTargetHWND = 0;
2000 trackerInfo->curDragTarget = 0;
2005 * Now that we have done that, we have to tell the source to give
2006 * us feedback on the work being done by the target. If we don't
2007 * have a target, simulate no effect.
2009 if (trackerInfo->curDragTarget==0)
2011 *trackerInfo->pdwEffect = DROPEFFECT_NONE;
2014 hr = IDropSource_GiveFeedback(trackerInfo->dropSource,
2015 *trackerInfo->pdwEffect);
2018 * When we ask for feedback from the drop source, sometimes it will
2019 * do all the necessary work and sometimes it will not handle it
2020 * when that's the case, we must display the standard drag and drop
2023 if (hr==DRAGDROP_S_USEDEFAULTCURSORS)
2025 if (*trackerInfo->pdwEffect & DROPEFFECT_MOVE)
2027 SetCursor(LoadCursorA(OLE32_hInstance, MAKEINTRESOURCEA(1)));
2029 else if (*trackerInfo->pdwEffect & DROPEFFECT_COPY)
2031 SetCursor(LoadCursorA(OLE32_hInstance, MAKEINTRESOURCEA(2)));
2033 else if (*trackerInfo->pdwEffect & DROPEFFECT_LINK)
2035 SetCursor(LoadCursorA(OLE32_hInstance, MAKEINTRESOURCEA(3)));
2039 SetCursor(LoadCursorA(OLE32_hInstance, MAKEINTRESOURCEA(0)));
2045 * OLEDD_TrackStateChange()
2047 * This method is invoked while a drag and drop operation is in effect.
2048 * It is used to notify the drop target/drop source callbacks when
2049 * the state of the keyboard or mouse button change.
2052 * trackerInfo - Pointer to the structure identifying the
2053 * drag & drop operation that is currently
2055 * mousePos - Current position of the mouse in screen
2057 * keyState - Contains the state of the shift keys and the
2058 * mouse buttons (MK_LBUTTON and the like)
2060 static void OLEDD_TrackStateChange(
2061 TrackerWindowInfo* trackerInfo,
2066 * Ask the drop source what to do with the operation.
2068 trackerInfo->returnValue = IDropSource_QueryContinueDrag(
2069 trackerInfo->dropSource,
2070 trackerInfo->escPressed,
2074 * All the return valued will stop the operation except the S_OK
2077 if (trackerInfo->returnValue!=S_OK)
2080 * Make sure the message loop in DoDragDrop stops
2082 trackerInfo->trackingDone = TRUE;
2085 * Release the mouse in case the drop target decides to show a popup
2086 * or a menu or something.
2091 * If we end-up over a target, drop the object in the target or
2092 * inform the target that the operation was cancelled.
2094 if (trackerInfo->curDragTarget!=0)
2096 switch (trackerInfo->returnValue)
2099 * If the source wants us to complete the operation, we tell
2100 * the drop target that we just dropped the object in it.
2102 case DRAGDROP_S_DROP:
2104 POINTL mousePosParam;
2107 * The documentation tells me that the coordinate should be
2108 * in the target window's coordinate space. However, the tests
2109 * I made tell me the coordinates should be in screen coordinates.
2111 mousePosParam.x = mousePos.x;
2112 mousePosParam.y = mousePos.y;
2114 IDropTarget_Drop(trackerInfo->curDragTarget,
2115 trackerInfo->dataObject,
2118 trackerInfo->pdwEffect);
2122 * If the source told us that we should cancel, fool the drop
2123 * target by telling it that the mouse left it's window.
2124 * Also set the drop effect to "NONE" in case the application
2125 * ignores the result of DoDragDrop.
2127 case DRAGDROP_S_CANCEL:
2128 IDropTarget_DragLeave(trackerInfo->curDragTarget);
2129 *trackerInfo->pdwEffect = DROPEFFECT_NONE;
2137 * OLEDD_GetButtonState()
2139 * This method will use the current state of the keyboard to build
2140 * a button state mask equivalent to the one passed in the
2141 * WM_MOUSEMOVE wParam.
2143 static DWORD OLEDD_GetButtonState()
2145 BYTE keyboardState[256];
2148 GetKeyboardState(keyboardState);
2150 if ( (keyboardState[VK_SHIFT] & 0x80) !=0)
2151 keyMask |= MK_SHIFT;
2153 if ( (keyboardState[VK_CONTROL] & 0x80) !=0)
2154 keyMask |= MK_CONTROL;
2156 if ( (keyboardState[VK_LBUTTON] & 0x80) !=0)
2157 keyMask |= MK_LBUTTON;
2159 if ( (keyboardState[VK_RBUTTON] & 0x80) !=0)
2160 keyMask |= MK_RBUTTON;
2162 if ( (keyboardState[VK_MBUTTON] & 0x80) !=0)
2163 keyMask |= MK_MBUTTON;
2169 * OLEDD_GetButtonState()
2171 * This method will read the default value of the registry key in
2172 * parameter and extract a DWORD value from it. The registry key value
2173 * can be in a string key or a DWORD key.
2176 * regKey - Key to read the default value from
2177 * pdwValue - Pointer to the location where the DWORD
2178 * value is returned. This value is not modified
2179 * if the value is not found.
2182 static void OLEUTL_ReadRegistryDWORDValue(
2191 lres = RegQueryValueExA(regKey,
2198 if (lres==ERROR_SUCCESS)
2203 *pdwValue = *(DWORD*)buffer;
2208 *pdwValue = (DWORD)strtoul(buffer, NULL, 10);
2214 /******************************************************************************
2217 * The operation of this function is documented literally in the WinAPI
2218 * documentation to involve a QueryInterface for the IViewObject interface,
2219 * followed by a call to IViewObject::Draw.
2221 HRESULT WINAPI OleDraw(
2228 IViewObject *viewobject;
2230 hres = IUnknown_QueryInterface(pUnk,
2232 (void**)&viewobject);
2234 if (SUCCEEDED(hres))
2238 rectl.left = lprcBounds->left;
2239 rectl.right = lprcBounds->right;
2240 rectl.top = lprcBounds->top;
2241 rectl.bottom = lprcBounds->bottom;
2242 hres = IViewObject_Draw(viewobject, dwAspect, -1, 0, 0, 0, hdcDraw, &rectl, 0, 0, 0);
2244 IViewObject_Release(viewobject);
2249 return DV_E_NOIVIEWOBJECT;
2253 /***********************************************************************
2254 * OleTranslateAccelerator [OLE32.@]
2256 HRESULT WINAPI OleTranslateAccelerator (LPOLEINPLACEFRAME lpFrame,
2257 LPOLEINPLACEFRAMEINFO lpFrameInfo, LPMSG lpmsg)
2261 TRACE("(%p,%p,%p)\n", lpFrame, lpFrameInfo, lpmsg);
2263 if (IsAccelerator(lpFrameInfo->haccel,lpFrameInfo->cAccelEntries,lpmsg,&wID))
2264 return IOleInPlaceFrame_TranslateAccelerator(lpFrame,lpmsg,wID);
2269 /******************************************************************************
2270 * OleCreate [OLE32.@]
2273 HRESULT WINAPI OleCreate(
2277 LPFORMATETC pFormatEtc,
2278 LPOLECLIENTSITE pClientSite,
2282 HRESULT hres, hres1;
2283 IUnknown * pUnk = NULL;
2285 FIXME("\n\t%s\n\t%s semi-stub!\n", debugstr_guid(rclsid), debugstr_guid(riid));
2287 if (SUCCEEDED((hres = CoCreateInstance(rclsid, 0, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER|CLSCTX_LOCAL_SERVER , riid, (LPVOID*)&pUnk))))
2292 IPersistStorage * pPS;
2293 if (SUCCEEDED((hres = IUnknown_QueryInterface( pUnk, &IID_IOleObject, (LPVOID*)&pOE))))
2295 TRACE("trying to set clientsite %p\n", pClientSite);
2296 hres1 = IOleObject_SetClientSite(pOE, pClientSite);
2297 TRACE("-- result 0x%08lx\n", hres1);
2298 IOleObject_Release(pOE);
2300 if (SUCCEEDED((hres = IUnknown_QueryInterface( pUnk, &IID_IPersistStorage, (LPVOID*)&pPS))))
2302 TRACE("trying to set stg %p\n", pStg);
2303 hres1 = IPersistStorage_InitNew(pPS, pStg);
2304 TRACE("-- result 0x%08lx\n", hres1);
2305 IPersistStorage_Release(pPS);
2312 TRACE("-- %p \n", pUnk);
2316 /***********************************************************************
2317 * OLE_FreeClipDataArray [internal]
2320 * frees the data associated with an array of CLIPDATAs
2322 static void OLE_FreeClipDataArray(ULONG count, CLIPDATA * pClipDataArray)
2325 for (i = 0; i < count; i++)
2326 if (pClipDataArray[i].pClipData)
2327 CoTaskMemFree(pClipDataArray[i].pClipData);
2330 HRESULT WINAPI FreePropVariantArray(ULONG,PROPVARIANT*);
2332 /***********************************************************************
2333 * PropVariantClear [OLE32.@]
2335 HRESULT WINAPI PropVariantClear(PROPVARIANT * pvar) /* [in/out] */
2337 TRACE("(%p)\n", pvar);
2345 case VT_STREAMED_OBJECT:
2347 case VT_STORED_OBJECT:
2348 IUnknown_Release((LPUNKNOWN)pvar->u.pStream);
2353 /* pick an arbitary typed pointer - we don't care about the type
2354 * as we are just freeing it */
2355 CoTaskMemFree(pvar->u.puuid);
2358 case VT_BLOB_OBJECT:
2359 CoTaskMemFree(pvar->u.blob.pBlobData);
2362 FIXME("Need to load OLEAUT32 for SysFreeString\n");
2363 /* SysFreeString(pvar->u.bstrVal); */
2366 if (pvar->u.pclipdata)
2368 OLE_FreeClipDataArray(1, pvar->u.pclipdata);
2369 CoTaskMemFree(pvar->u.pclipdata);
2373 if (pvar->vt & VT_ARRAY)
2375 FIXME("Need to call SafeArrayDestroy\n");
2376 /* SafeArrayDestroy(pvar->u.caub); */
2378 switch (pvar->vt & VT_VECTOR)
2381 FreePropVariantArray(pvar->u.capropvar.cElems, pvar->u.capropvar.pElems);
2384 OLE_FreeClipDataArray(pvar->u.caclipdata.cElems, pvar->u.caclipdata.pElems);
2389 FIXME("Freeing of vector sub-type not supported yet\n");
2391 if (pvar->vt & VT_VECTOR)
2393 /* pick an arbitary VT_VECTOR structure - they all have the same
2395 CoTaskMemFree(pvar->u.capropvar.pElems);
2399 ZeroMemory(pvar, sizeof(*pvar));
2404 /***********************************************************************
2405 * PropVariantCopy [OLE32.@]
2407 HRESULT WINAPI PropVariantCopy(PROPVARIANT *pvarDest, /* [out] */
2408 const PROPVARIANT *pvarSrc) /* [in] */
2411 TRACE("(%p, %p): stub:\n", pvarDest, pvarSrc);
2413 /* this will deal with most cases */
2414 CopyMemory(pvarDest, pvarSrc, sizeof(*pvarDest));
2419 case VT_STREAMED_OBJECT:
2421 case VT_STORED_OBJECT:
2422 IUnknown_AddRef((LPUNKNOWN)pvarDest->u.pStream);
2425 pvarDest->u.puuid = CoTaskMemAlloc(sizeof(CLSID));
2426 CopyMemory(pvarDest->u.puuid, pvarSrc->u.puuid, sizeof(CLSID));
2429 len = strlen(pvarSrc->u.pszVal);
2430 pvarDest->u.pszVal = CoTaskMemAlloc(len);
2431 CopyMemory(pvarDest->u.pszVal, pvarSrc->u.pszVal, len);
2434 len = lstrlenW(pvarSrc->u.pwszVal);
2435 pvarDest->u.pwszVal = CoTaskMemAlloc(len);
2436 CopyMemory(pvarDest->u.pwszVal, pvarSrc->u.pwszVal, len);
2439 case VT_BLOB_OBJECT:
2440 if (pvarSrc->u.blob.pBlobData)
2442 len = pvarSrc->u.blob.cbSize;
2443 pvarDest->u.blob.pBlobData = CoTaskMemAlloc(len);
2444 CopyMemory(pvarDest->u.blob.pBlobData, pvarSrc->u.blob.pBlobData, len);
2448 FIXME("Need to copy BSTR\n");
2451 if (pvarSrc->u.pclipdata)
2453 len = pvarSrc->u.pclipdata->cbSize - sizeof(pvarSrc->u.pclipdata->ulClipFmt);
2454 CoTaskMemAlloc(len);
2455 CopyMemory(pvarDest->u.pclipdata->pClipData, pvarSrc->u.pclipdata->pClipData, len);
2459 if (pvarSrc->vt & VT_ARRAY)
2461 FIXME("Need to call SafeArrayCopy\n");
2462 /* SafeArrayCopy(...); */
2464 if (pvarSrc->vt & VT_VECTOR)
2467 switch(pvarSrc->vt & VT_VECTOR)
2469 case VT_I1: elemSize = sizeof(pvarSrc->u.cVal); break;
2470 case VT_UI1: elemSize = sizeof(pvarSrc->u.bVal); break;
2471 case VT_I2: elemSize = sizeof(pvarSrc->u.iVal); break;
2472 case VT_UI2: elemSize = sizeof(pvarSrc->u.uiVal); break;
2473 case VT_BOOL: elemSize = sizeof(pvarSrc->u.boolVal); break;
2474 case VT_I4: elemSize = sizeof(pvarSrc->u.lVal); break;
2475 case VT_UI4: elemSize = sizeof(pvarSrc->u.ulVal); break;
2476 case VT_R4: elemSize = sizeof(pvarSrc->u.fltVal); break;
2477 case VT_R8: elemSize = sizeof(pvarSrc->u.dblVal); break;
2478 case VT_ERROR: elemSize = sizeof(pvarSrc->u.scode); break;
2479 case VT_I8: elemSize = sizeof(pvarSrc->u.hVal); break;
2480 case VT_UI8: elemSize = sizeof(pvarSrc->u.uhVal); break;
2481 case VT_CY: elemSize = sizeof(pvarSrc->u.cyVal); break;
2482 case VT_DATE: elemSize = sizeof(pvarSrc->u.date); break;
2483 case VT_FILETIME: elemSize = sizeof(pvarSrc->u.filetime); break;
2484 case VT_CLSID: elemSize = sizeof(*pvarSrc->u.puuid); break;
2485 case VT_CF: elemSize = sizeof(*pvarSrc->u.pclipdata); break;
2492 FIXME("Invalid element type: %ul\n", pvarSrc->vt & VT_VECTOR);
2493 return E_INVALIDARG;
2495 len = pvarSrc->u.capropvar.cElems;
2496 pvarDest->u.capropvar.pElems = CoTaskMemAlloc(len * elemSize);
2497 if (pvarSrc->vt == (VT_VECTOR | VT_VARIANT))
2500 for (i = 0; i < len; i++)
2501 PropVariantCopy(&pvarDest->u.capropvar.pElems[i], &pvarSrc->u.capropvar.pElems[i]);
2503 else if (pvarSrc->vt == (VT_VECTOR | VT_CF))
2505 FIXME("Copy clipformats\n");
2507 else if (pvarSrc->vt == (VT_VECTOR | VT_BSTR))
2509 FIXME("Copy BSTRs\n");
2511 else if (pvarSrc->vt == (VT_VECTOR | VT_LPSTR))
2513 FIXME("Copy LPSTRs\n");
2515 else if (pvarSrc->vt == (VT_VECTOR | VT_LPSTR))
2517 FIXME("Copy LPWSTRs\n");
2520 CopyMemory(pvarDest->u.capropvar.pElems, pvarSrc->u.capropvar.pElems, len * elemSize);
2527 /***********************************************************************
2528 * FreePropVariantArray [OLE32.@]
2530 HRESULT WINAPI FreePropVariantArray(ULONG cVariants, /* [in] */
2531 PROPVARIANT *rgvars) /* [in/out] */
2535 TRACE("(%lu, %p)\n", cVariants, rgvars);
2537 for(i = 0; i < cVariants; i++)
2538 PropVariantClear(&rgvars[i]);
2543 /******************************************************************************
2544 * DllDebugObjectRPCHook (OLE32.@)
2545 * turns on and off internal debugging, pointer is only used on macintosh
2548 BOOL WINAPI DllDebugObjectRPCHook(BOOL b, void *dummy)