5 * Copyright 1995 Martin von Loewis
6 * Copyright 1999 Francis Beaudet
7 * Copyright 1999 Noel Borthwick
27 #include "wine/obj_clientserver.h"
28 #include "wine/winbase16.h"
29 #include "wine/wingdi16.h"
30 #include "wine/winuser16.h"
31 #include "ole32_main.h"
33 #include "debugtools.h"
35 DEFAULT_DEBUG_CHANNEL(ole
);
36 DECLARE_DEBUG_CHANNEL(accel
);
38 /******************************************************************************
39 * These are static/global variables and internal data structures that the
40 * OLE module uses to maintain it's state.
42 typedef struct tagDropTargetNode
45 IDropTarget
* dropTarget
;
46 struct tagDropTargetNode
* prevDropTarget
;
47 struct tagDropTargetNode
* nextDropTarget
;
50 typedef struct tagTrackerWindowInfo
52 IDataObject
* dataObject
;
53 IDropSource
* dropSource
;
60 HWND curDragTargetHWND
;
61 IDropTarget
* curDragTarget
;
64 typedef struct tagOleMenuDescriptor
/* OleMenuDescriptor */
66 HWND hwndFrame
; /* The containers frame window */
67 HWND hwndActiveObject
; /* The active objects window */
68 OLEMENUGROUPWIDTHS mgw
; /* OLE menu group widths for the shared menu */
69 HMENU hmenuCombined
; /* The combined menu */
70 BOOL bIsServerItem
; /* True if the currently open popup belongs to the server */
73 typedef struct tagOleMenuHookItem
/* OleMenu hook item in per thread hook list */
75 DWORD tid
; /* Thread Id */
76 HANDLE hHeap
; /* Heap this is allocated from */
77 HHOOK GetMsg_hHook
; /* message hook for WH_GETMESSAGE */
78 HHOOK CallWndProc_hHook
; /* message hook for WH_CALLWNDPROC */
79 struct tagOleMenuHookItem
*next
;
82 static OleMenuHookItem
*hook_list
;
85 * This is the lock count on the OLE library. It is controlled by the
86 * OLEInitialize/OLEUninitialize methods.
88 static ULONG OLE_moduleLockCount
= 0;
91 * Name of our registered window class.
93 static const char OLEDD_DRAGTRACKERCLASS
[] = "WineDragDropTracker32";
96 * This is the head of the Drop target container.
98 static DropTargetNode
* targetListHead
= NULL
;
100 /******************************************************************************
101 * These are the prototypes of miscelaneous utility methods
103 static void OLEUTL_ReadRegistryDWORDValue(HKEY regKey
, DWORD
* pdwValue
);
105 /******************************************************************************
106 * These are the prototypes of the utility methods used to manage a shared menu
108 static void OLEMenu_Initialize();
109 static void OLEMenu_UnInitialize();
110 BOOL
OLEMenu_InstallHooks( DWORD tid
);
111 BOOL
OLEMenu_UnInstallHooks( DWORD tid
);
112 OleMenuHookItem
* OLEMenu_IsHookInstalled( DWORD tid
);
113 static BOOL
OLEMenu_FindMainMenuIndex( HMENU hMainMenu
, HMENU hPopupMenu
, UINT
*pnPos
);
114 BOOL
OLEMenu_SetIsServerMenu( HMENU hmenu
, OleMenuDescriptor
*pOleMenuDescriptor
);
115 LRESULT CALLBACK
OLEMenu_CallWndProc(INT code
, WPARAM wParam
, LPARAM lParam
);
116 LRESULT CALLBACK
OLEMenu_GetMsgProc(INT code
, WPARAM wParam
, LPARAM lParam
);
118 /******************************************************************************
119 * These are the prototypes of the OLE Clipboard initialization methods (in clipboard.c)
121 void OLEClipbrd_UnInitialize();
122 void OLEClipbrd_Initialize();
124 /******************************************************************************
125 * These are the prototypes of the utility methods used for OLE Drag n Drop
127 static void OLEDD_Initialize();
128 static void OLEDD_UnInitialize();
129 static void OLEDD_InsertDropTarget(
130 DropTargetNode
* nodeToAdd
);
131 static DropTargetNode
* OLEDD_ExtractDropTarget(
133 static DropTargetNode
* OLEDD_FindDropTarget(
135 static LRESULT WINAPI
OLEDD_DragTrackerWindowProc(
140 static void OLEDD_TrackMouseMove(
141 TrackerWindowInfo
* trackerInfo
,
144 static void OLEDD_TrackStateChange(
145 TrackerWindowInfo
* trackerInfo
,
148 static DWORD
OLEDD_GetButtonState();
151 /******************************************************************************
152 * OleBuildVersion [OLE2.1]
153 * OleBuildVersion [OLE32.84]
155 DWORD WINAPI
OleBuildVersion(void)
157 TRACE("Returning version %d, build %d.\n", rmm
, rup
);
158 return (rmm
<<16)+rup
;
161 /***********************************************************************
162 * OleInitialize (OLE2.2)
163 * OleInitialize (OLE32.108)
165 HRESULT WINAPI
OleInitialize(LPVOID reserved
)
169 TRACE("(%p)\n", reserved
);
172 * The first duty of the OleInitialize is to initialize the COM libraries.
174 hr
= CoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
177 * If the CoInitializeEx call failed, the OLE libraries can't be
184 * Then, it has to initialize the OLE specific modules.
188 * Object linking and Embedding
189 * In-place activation
191 if (OLE_moduleLockCount
==0)
194 * Initialize the libraries.
196 TRACE("() - Initializing the OLE libraries\n");
201 OLEClipbrd_Initialize();
211 OLEMenu_Initialize();
215 * Then, we increase the lock count on the OLE module.
217 OLE_moduleLockCount
++;
222 /******************************************************************************
223 * CoGetCurrentProcess [COMPOBJ.34]
224 * CoGetCurrentProcess [OLE32.18]
227 * Is DWORD really the correct return type for this function?
229 DWORD WINAPI
CoGetCurrentProcess(void)
231 return GetCurrentProcessId();
234 /******************************************************************************
235 * OleUninitialize [OLE2.3]
236 * OleUninitialize [OLE32.131]
238 void WINAPI
OleUninitialize(void)
243 * Decrease the lock count on the OLE module.
245 OLE_moduleLockCount
--;
248 * If we hit the bottom of the lock stack, free the libraries.
250 if (OLE_moduleLockCount
==0)
253 * Actually free the libraries.
255 TRACE("() - Freeing the last reference count\n");
260 OLEClipbrd_UnInitialize();
265 OLEDD_UnInitialize();
270 OLEMenu_UnInitialize();
274 * Then, uninitialize the COM libraries.
279 /******************************************************************************
280 * CoRegisterMessageFilter [OLE32.38]
282 HRESULT WINAPI
CoRegisterMessageFilter(
283 LPMESSAGEFILTER lpMessageFilter
, /* [in] Pointer to interface */
284 LPMESSAGEFILTER
*lplpMessageFilter
/* [out] Indirect pointer to prior instance if non-NULL */
287 if (lplpMessageFilter
) {
288 *lplpMessageFilter
= NULL
;
293 /******************************************************************************
294 * OleInitializeWOW [OLE32.109]
296 HRESULT WINAPI
OleInitializeWOW(DWORD x
) {
297 FIXME("(0x%08lx),stub!\n",x
);
301 /***********************************************************************
302 * RegisterDragDrop (OLE2.35)
304 HRESULT WINAPI
RegisterDragDrop16(
306 LPDROPTARGET pDropTarget
308 FIXME("(0x%04x,%p),stub!\n",hwnd
,pDropTarget
);
312 /***********************************************************************
313 * RegisterDragDrop (OLE32.139)
315 HRESULT WINAPI
RegisterDragDrop(
317 LPDROPTARGET pDropTarget
)
319 DropTargetNode
* dropTargetInfo
;
321 TRACE("(0x%x,%p)\n", hwnd
, pDropTarget
);
324 * First, check if the window is already registered.
326 dropTargetInfo
= OLEDD_FindDropTarget(hwnd
);
328 if (dropTargetInfo
!=NULL
)
329 return DRAGDROP_E_ALREADYREGISTERED
;
332 * If it's not there, we can add it. We first create a node for it.
334 dropTargetInfo
= HeapAlloc(GetProcessHeap(), 0, sizeof(DropTargetNode
));
336 if (dropTargetInfo
==NULL
)
337 return E_OUTOFMEMORY
;
339 dropTargetInfo
->hwndTarget
= hwnd
;
340 dropTargetInfo
->prevDropTarget
= NULL
;
341 dropTargetInfo
->nextDropTarget
= NULL
;
344 * Don't forget that this is an interface pointer, need to nail it down since
345 * we keep a copy of it.
347 dropTargetInfo
->dropTarget
= pDropTarget
;
348 IDropTarget_AddRef(dropTargetInfo
->dropTarget
);
350 OLEDD_InsertDropTarget(dropTargetInfo
);
355 /***********************************************************************
356 * RevokeDragDrop (OLE2.36)
358 HRESULT WINAPI
RevokeDragDrop16(
361 FIXME("(0x%04x),stub!\n",hwnd
);
365 /***********************************************************************
366 * RevokeDragDrop (OLE32.141)
368 HRESULT WINAPI
RevokeDragDrop(
371 DropTargetNode
* dropTargetInfo
;
373 TRACE("(0x%x)\n", hwnd
);
376 * First, check if the window is already registered.
378 dropTargetInfo
= OLEDD_ExtractDropTarget(hwnd
);
381 * If it ain't in there, it's an error.
383 if (dropTargetInfo
==NULL
)
384 return DRAGDROP_E_NOTREGISTERED
;
387 * If it's in there, clean-up it's used memory and
390 IDropTarget_Release(dropTargetInfo
->dropTarget
);
391 HeapFree(GetProcessHeap(), 0, dropTargetInfo
);
396 /***********************************************************************
397 * OleRegGetUserType (OLE32.122)
399 * This implementation of OleRegGetUserType ignores the dwFormOfType
400 * parameter and always returns the full name of the object. This is
401 * not too bad since this is the case for many objects because of the
402 * way they are registered.
404 HRESULT WINAPI
OleRegGetUserType(
407 LPOLESTR
* pszUserType
)
417 * Initialize the out parameter.
422 * Build the key name we're looking for
424 sprintf( keyName
, "CLSID\\{%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}\\",
425 clsid
->Data1
, clsid
->Data2
, clsid
->Data3
,
426 clsid
->Data4
[0], clsid
->Data4
[1], clsid
->Data4
[2], clsid
->Data4
[3],
427 clsid
->Data4
[4], clsid
->Data4
[5], clsid
->Data4
[6], clsid
->Data4
[7] );
429 TRACE("(%s, %ld, %p)\n", keyName
, dwFormOfType
, pszUserType
);
432 * Open the class id Key
434 hres
= RegOpenKeyA(HKEY_CLASSES_ROOT
,
438 if (hres
!= ERROR_SUCCESS
)
439 return REGDB_E_CLASSNOTREG
;
442 * Retrieve the size of the name string.
446 hres
= RegQueryValueExA(clsidKey
,
453 if (hres
!=ERROR_SUCCESS
)
455 RegCloseKey(clsidKey
);
456 return REGDB_E_READREGDB
;
460 * Allocate a buffer for the registry value.
462 *pszUserType
= CoTaskMemAlloc(cbData
*2);
464 if (*pszUserType
==NULL
)
466 RegCloseKey(clsidKey
);
467 return E_OUTOFMEMORY
;
470 buffer
= HeapAlloc(GetProcessHeap(), 0, cbData
);
474 RegCloseKey(clsidKey
);
475 CoTaskMemFree(*pszUserType
);
477 return E_OUTOFMEMORY
;
480 hres
= RegQueryValueExA(clsidKey
,
487 RegCloseKey(clsidKey
);
490 if (hres
!=ERROR_SUCCESS
)
492 CoTaskMemFree(*pszUserType
);
495 retVal
= REGDB_E_READREGDB
;
499 MultiByteToWideChar( CP_ACP
, 0, buffer
, -1, *pszUserType
, cbData
/*FIXME*/ );
502 HeapFree(GetProcessHeap(), 0, buffer
);
507 /***********************************************************************
508 * DoDragDrop [OLE32.65]
510 HRESULT WINAPI
DoDragDrop (
511 IDataObject
*pDataObject
, /* [in] ptr to the data obj */
512 IDropSource
* pDropSource
, /* [in] ptr to the source obj */
513 DWORD dwOKEffect
, /* [in] effects allowed by the source */
514 DWORD
*pdwEffect
) /* [out] ptr to effects of the source */
516 TrackerWindowInfo trackerInfo
;
517 HWND hwndTrackWindow
;
520 TRACE("(DataObject %p, DropSource %p)\n", pDataObject
, pDropSource
);
523 * Setup the drag n drop tracking window.
525 trackerInfo
.dataObject
= pDataObject
;
526 trackerInfo
.dropSource
= pDropSource
;
527 trackerInfo
.dwOKEffect
= dwOKEffect
;
528 trackerInfo
.pdwEffect
= pdwEffect
;
529 trackerInfo
.trackingDone
= FALSE
;
530 trackerInfo
.escPressed
= FALSE
;
531 trackerInfo
.curDragTargetHWND
= 0;
532 trackerInfo
.curDragTarget
= 0;
534 hwndTrackWindow
= CreateWindowA(OLEDD_DRAGTRACKERCLASS
,
537 CW_USEDEFAULT
, CW_USEDEFAULT
,
538 CW_USEDEFAULT
, CW_USEDEFAULT
,
542 (LPVOID
)&trackerInfo
);
544 if (hwndTrackWindow
!=0)
547 * Capture the mouse input
549 SetCapture(hwndTrackWindow
);
552 * Pump messages. All mouse input should go the the capture window.
554 while (!trackerInfo
.trackingDone
&& GetMessageA(&msg
, 0, 0, 0) )
556 if ( (msg
.message
>= WM_KEYFIRST
) &&
557 (msg
.message
<= WM_KEYLAST
) )
560 * When keyboard messages are sent to windows on this thread, we
561 * want to ignore notify the drop source that the state changed.
562 * in the case of the Escape key, we also notify the drop source
563 * we give it a special meaning.
565 if ( (msg
.message
==WM_KEYDOWN
) &&
566 (msg
.wParam
==VK_ESCAPE
) )
568 trackerInfo
.escPressed
= TRUE
;
572 * Notify the drop source.
574 OLEDD_TrackStateChange(&trackerInfo
,
576 OLEDD_GetButtonState());
581 * Dispatch the messages only when it's not a keyboard message.
583 DispatchMessageA(&msg
);
588 * Destroy the temporary window.
590 DestroyWindow(hwndTrackWindow
);
592 return trackerInfo
.returnValue
;
598 /***********************************************************************
599 * OleQueryLinkFromData [OLE32.118]
601 HRESULT WINAPI
OleQueryLinkFromData(
602 IDataObject
* pSrcDataObject
)
604 FIXME("(%p),stub!\n", pSrcDataObject
);
608 /***********************************************************************
609 * OleRegGetMiscStatus [OLE32.121]
611 HRESULT WINAPI
OleRegGetMiscStatus(
623 * Initialize the out parameter.
628 * Build the key name we're looking for
630 sprintf( keyName
, "CLSID\\{%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}\\",
631 clsid
->Data1
, clsid
->Data2
, clsid
->Data3
,
632 clsid
->Data4
[0], clsid
->Data4
[1], clsid
->Data4
[2], clsid
->Data4
[3],
633 clsid
->Data4
[4], clsid
->Data4
[5], clsid
->Data4
[6], clsid
->Data4
[7] );
635 TRACE("(%s, %ld, %p)\n", keyName
, dwAspect
, pdwStatus
);
638 * Open the class id Key
640 result
= RegOpenKeyA(HKEY_CLASSES_ROOT
,
644 if (result
!= ERROR_SUCCESS
)
645 return REGDB_E_CLASSNOTREG
;
650 result
= RegOpenKeyA(clsidKey
,
655 if (result
!= ERROR_SUCCESS
)
657 RegCloseKey(clsidKey
);
658 return REGDB_E_READREGDB
;
662 * Read the default value
664 OLEUTL_ReadRegistryDWORDValue(miscStatusKey
, pdwStatus
);
667 * Open the key specific to the requested aspect.
669 sprintf(keyName
, "%ld", dwAspect
);
671 result
= RegOpenKeyA(miscStatusKey
,
675 if (result
== ERROR_SUCCESS
)
677 OLEUTL_ReadRegistryDWORDValue(aspectKey
, pdwStatus
);
678 RegCloseKey(aspectKey
);
684 RegCloseKey(miscStatusKey
);
685 RegCloseKey(clsidKey
);
690 /******************************************************************************
691 * OleSetContainedObject [OLE32.128]
693 HRESULT WINAPI
OleSetContainedObject(
697 IRunnableObject
* runnable
= NULL
;
700 TRACE("(%p,%x), stub!\n", pUnknown
, fContained
);
702 hres
= IUnknown_QueryInterface(pUnknown
,
703 &IID_IRunnableObject
,
708 hres
= IRunnableObject_SetContainedObject(runnable
, fContained
);
710 IRunnableObject_Release(runnable
);
718 /******************************************************************************
719 * OleLoad [OLE32.112]
721 HRESULT WINAPI
OleLoad(
724 LPOLECLIENTSITE pClientSite
,
727 IPersistStorage
* persistStorage
= NULL
;
728 IOleObject
* oleObject
= NULL
;
732 TRACE("(%p,%p,%p,%p)\n", pStg
, riid
, pClientSite
, ppvObj
);
735 * TODO, Conversion ... OleDoAutoConvert
739 * Get the class ID for the object.
741 hres
= IStorage_Stat(pStg
, &storageInfo
, STATFLAG_NONAME
);
744 * Now, try and create the handler for the object
746 hres
= CoCreateInstance(&storageInfo
.clsid
,
748 CLSCTX_INPROC_HANDLER
,
753 * If that fails, as it will most times, load the default
758 hres
= OleCreateDefaultHandler(&storageInfo
.clsid
,
765 * If we couldn't find a handler... this is bad. Abort the whole thing.
771 * Inform the new object of it's client site.
773 hres
= IOleObject_SetClientSite(oleObject
, pClientSite
);
776 * Initialize the object with it's IPersistStorage interface.
778 hres
= IOleObject_QueryInterface(oleObject
,
779 &IID_IPersistStorage
,
780 (void**)&persistStorage
);
784 IPersistStorage_Load(persistStorage
, pStg
);
786 IPersistStorage_Release(persistStorage
);
787 persistStorage
= NULL
;
791 * Return the requested interface to the caller.
793 hres
= IOleObject_QueryInterface(oleObject
, riid
, ppvObj
);
796 * Cleanup interfaces used internally
798 IOleObject_Release(oleObject
);
803 /***********************************************************************
804 * OleSave [OLE32.124]
806 HRESULT WINAPI
OleSave(
807 LPPERSISTSTORAGE pPS
,
814 TRACE("(%p,%p,%x)\n", pPS
, pStg
, fSameAsLoad
);
817 * First, we transfer the class ID (if available)
819 hres
= IPersistStorage_GetClassID(pPS
, &objectClass
);
823 WriteClassStg(pStg
, &objectClass
);
827 * Then, we ask the object to save itself to the
828 * storage. If it is successful, we commit the storage.
830 hres
= IPersistStorage_Save(pPS
, pStg
, fSameAsLoad
);
834 IStorage_Commit(pStg
,
842 /******************************************************************************
843 * OleLockRunning [OLE32.114]
845 HRESULT WINAPI
OleLockRunning(LPUNKNOWN pUnknown
, BOOL fLock
, BOOL fLastUnlockCloses
)
847 IRunnableObject
* runnable
= NULL
;
850 TRACE("(%p,%x,%x)\n", pUnknown
, fLock
, fLastUnlockCloses
);
852 hres
= IUnknown_QueryInterface(pUnknown
,
853 &IID_IRunnableObject
,
858 hres
= IRunnableObject_LockRunning(runnable
, fLock
, fLastUnlockCloses
);
860 IRunnableObject_Release(runnable
);
869 /**************************************************************************
870 * Internal methods to manage the shared OLE menu in response to the
871 * OLE***MenuDescriptor API
875 * OLEMenu_Initialize()
877 * Initializes the OLEMENU data structures.
879 static void OLEMenu_Initialize()
884 * OLEMenu_UnInitialize()
886 * Releases the OLEMENU data structures.
888 static void OLEMenu_UnInitialize()
892 /*************************************************************************
893 * OLEMenu_InstallHooks
894 * Install thread scope message hooks for WH_GETMESSAGE and WH_CALLWNDPROC
896 * RETURNS: TRUE if message hooks were succesfully installed
899 BOOL
OLEMenu_InstallHooks( DWORD tid
)
901 OleMenuHookItem
*pHookItem
= NULL
;
903 /* Create an entry for the hook table */
904 if ( !(pHookItem
= HeapAlloc(GetProcessHeap(), 0,
905 sizeof(OleMenuHookItem
)) ) )
908 pHookItem
->tid
= tid
;
909 pHookItem
->hHeap
= GetProcessHeap();
911 /* Install a thread scope message hook for WH_GETMESSAGE */
912 pHookItem
->GetMsg_hHook
= SetWindowsHookExA( WH_GETMESSAGE
, OLEMenu_GetMsgProc
,
913 0, GetCurrentThreadId() );
914 if ( !pHookItem
->GetMsg_hHook
)
917 /* Install a thread scope message hook for WH_CALLWNDPROC */
918 pHookItem
->CallWndProc_hHook
= SetWindowsHookExA( WH_CALLWNDPROC
, OLEMenu_CallWndProc
,
919 0, GetCurrentThreadId() );
920 if ( !pHookItem
->CallWndProc_hHook
)
923 /* Insert the hook table entry */
924 pHookItem
->next
= hook_list
;
925 hook_list
= pHookItem
;
930 /* Unhook any hooks */
931 if ( pHookItem
->GetMsg_hHook
)
932 UnhookWindowsHookEx( pHookItem
->GetMsg_hHook
);
933 if ( pHookItem
->CallWndProc_hHook
)
934 UnhookWindowsHookEx( pHookItem
->CallWndProc_hHook
);
935 /* Release the hook table entry */
936 HeapFree(pHookItem
->hHeap
, 0, pHookItem
);
941 /*************************************************************************
942 * OLEMenu_UnInstallHooks
943 * UnInstall thread scope message hooks for WH_GETMESSAGE and WH_CALLWNDPROC
945 * RETURNS: TRUE if message hooks were succesfully installed
948 BOOL
OLEMenu_UnInstallHooks( DWORD tid
)
950 OleMenuHookItem
*pHookItem
= NULL
;
951 OleMenuHookItem
**ppHook
= &hook_list
;
955 if ((*ppHook
)->tid
== tid
)
958 *ppHook
= pHookItem
->next
;
961 ppHook
= &(*ppHook
)->next
;
963 if (!pHookItem
) return FALSE
;
965 /* Uninstall the hooks installed for this thread */
966 if ( !UnhookWindowsHookEx( pHookItem
->GetMsg_hHook
) )
968 if ( !UnhookWindowsHookEx( pHookItem
->CallWndProc_hHook
) )
971 /* Release the hook table entry */
972 HeapFree(pHookItem
->hHeap
, 0, pHookItem
);
977 /* Release the hook table entry */
979 HeapFree(pHookItem
->hHeap
, 0, pHookItem
);
984 /*************************************************************************
985 * OLEMenu_IsHookInstalled
986 * Tests if OLEMenu hooks have been installed for a thread
988 * RETURNS: The pointer and index of the hook table entry for the tid
989 * NULL and -1 for the index if no hooks were installed for this thread
991 OleMenuHookItem
* OLEMenu_IsHookInstalled( DWORD tid
)
993 OleMenuHookItem
*pHookItem
= NULL
;
995 /* Do a simple linear search for an entry whose tid matches ours.
996 * We really need a map but efficiency is not a concern here. */
997 for (pHookItem
= hook_list
; pHookItem
; pHookItem
= pHookItem
->next
)
999 if ( tid
== pHookItem
->tid
)
1006 /***********************************************************************
1007 * OLEMenu_FindMainMenuIndex
1009 * Used by OLEMenu API to find the top level group a menu item belongs to.
1010 * On success pnPos contains the index of the item in the top level menu group
1012 * RETURNS: TRUE if the ID was found, FALSE on failure
1014 static BOOL
OLEMenu_FindMainMenuIndex( HMENU hMainMenu
, HMENU hPopupMenu
, UINT
*pnPos
)
1018 nItems
= GetMenuItemCount( hMainMenu
);
1020 for (i
= 0; i
< nItems
; i
++)
1024 /* Is the current item a submenu? */
1025 if ( (hsubmenu
= GetSubMenu(hMainMenu
, i
)) )
1027 /* If the handle is the same we're done */
1028 if ( hsubmenu
== hPopupMenu
)
1034 /* Recursively search without updating pnPos */
1035 else if ( OLEMenu_FindMainMenuIndex( hsubmenu
, hPopupMenu
, NULL
) )
1047 /***********************************************************************
1048 * OLEMenu_SetIsServerMenu
1050 * Checks whether a popup menu belongs to a shared menu group which is
1051 * owned by the server, and sets the menu descriptor state accordingly.
1052 * All menu messages from these groups should be routed to the server.
1054 * RETURNS: TRUE if the popup menu is part of a server owned group
1055 * FASE if the popup menu is part of a container owned group
1057 BOOL
OLEMenu_SetIsServerMenu( HMENU hmenu
, OleMenuDescriptor
*pOleMenuDescriptor
)
1059 UINT nPos
= 0, nWidth
, i
;
1061 pOleMenuDescriptor
->bIsServerItem
= FALSE
;
1063 /* Don't bother searching if the popup is the combined menu itself */
1064 if ( hmenu
== pOleMenuDescriptor
->hmenuCombined
)
1067 /* Find the menu item index in the shared OLE menu that this item belongs to */
1068 if ( !OLEMenu_FindMainMenuIndex( pOleMenuDescriptor
->hmenuCombined
, hmenu
, &nPos
) )
1071 /* The group widths array has counts for the number of elements
1072 * in the groups File, Edit, Container, Object, Window, Help.
1073 * The Edit, Object & Help groups belong to the server object
1074 * and the other three belong to the container.
1075 * Loop through the group widths and locate the group we are a member of.
1077 for ( i
= 0, nWidth
= 0; i
< 6; i
++ )
1079 nWidth
+= pOleMenuDescriptor
->mgw
.width
[i
];
1080 if ( nPos
< nWidth
)
1082 /* Odd elements are server menu widths */
1083 pOleMenuDescriptor
->bIsServerItem
= (i
%2) ? TRUE
: FALSE
;
1088 return pOleMenuDescriptor
->bIsServerItem
;
1091 /*************************************************************************
1092 * OLEMenu_CallWndProc
1093 * Thread scope WH_CALLWNDPROC hook proc filter function (callback)
1094 * This is invoked from a message hook installed in OleSetMenuDescriptor.
1096 LRESULT CALLBACK
OLEMenu_CallWndProc(INT code
, WPARAM wParam
, LPARAM lParam
)
1098 LPCWPSTRUCT pMsg
= NULL
;
1099 HOLEMENU hOleMenu
= 0;
1100 OleMenuDescriptor
*pOleMenuDescriptor
= NULL
;
1101 OleMenuHookItem
*pHookItem
= NULL
;
1104 TRACE("%i, %04x, %08x\n", code
, wParam
, (unsigned)lParam
);
1106 /* Check if we're being asked to process the message */
1107 if ( HC_ACTION
!= code
)
1110 /* Retrieve the current message being dispatched from lParam */
1111 pMsg
= (LPCWPSTRUCT
)lParam
;
1113 /* Check if the message is destined for a window we are interested in:
1114 * If the window has an OLEMenu property we may need to dispatch
1115 * the menu message to its active objects window instead. */
1117 hOleMenu
= (HOLEMENU
)GetPropA( pMsg
->hwnd
, "PROP_OLEMenuDescriptor" );
1121 /* Get the menu descriptor */
1122 pOleMenuDescriptor
= (OleMenuDescriptor
*) GlobalLock( hOleMenu
);
1123 if ( !pOleMenuDescriptor
) /* Bad descriptor! */
1126 /* Process menu messages */
1127 switch( pMsg
->message
)
1131 /* Reset the menu descriptor state */
1132 pOleMenuDescriptor
->bIsServerItem
= FALSE
;
1134 /* Send this message to the server as well */
1135 SendMessageA( pOleMenuDescriptor
->hwndActiveObject
,
1136 pMsg
->message
, pMsg
->wParam
, pMsg
->lParam
);
1140 case WM_INITMENUPOPUP
:
1142 /* Save the state for whether this is a server owned menu */
1143 OLEMenu_SetIsServerMenu( (HMENU
)pMsg
->wParam
, pOleMenuDescriptor
);
1149 fuFlags
= HIWORD(pMsg
->wParam
); /* Get flags */
1150 if ( fuFlags
& MF_SYSMENU
)
1153 /* Save the state for whether this is a server owned popup menu */
1154 else if ( fuFlags
& MF_POPUP
)
1155 OLEMenu_SetIsServerMenu( (HMENU
)pMsg
->lParam
, pOleMenuDescriptor
);
1162 LPDRAWITEMSTRUCT lpdis
= (LPDRAWITEMSTRUCT
) pMsg
->lParam
;
1163 if ( pMsg
->wParam
!= 0 || lpdis
->CtlType
!= ODT_MENU
)
1164 goto NEXTHOOK
; /* Not a menu message */
1173 /* If the message was for the server dispatch it accordingly */
1174 if ( pOleMenuDescriptor
->bIsServerItem
)
1176 SendMessageA( pOleMenuDescriptor
->hwndActiveObject
,
1177 pMsg
->message
, pMsg
->wParam
, pMsg
->lParam
);
1181 if ( pOleMenuDescriptor
)
1182 GlobalUnlock( hOleMenu
);
1184 /* Lookup the hook item for the current thread */
1185 if ( !( pHookItem
= OLEMenu_IsHookInstalled( GetCurrentThreadId() ) ) )
1187 /* This should never fail!! */
1188 WARN("could not retrieve hHook for current thread!\n" );
1192 /* Pass on the message to the next hooker */
1193 return CallNextHookEx( pHookItem
->CallWndProc_hHook
, code
, wParam
, lParam
);
1196 /*************************************************************************
1197 * OLEMenu_GetMsgProc
1198 * Thread scope WH_GETMESSAGE hook proc filter function (callback)
1199 * This is invoked from a message hook installed in OleSetMenuDescriptor.
1201 LRESULT CALLBACK
OLEMenu_GetMsgProc(INT code
, WPARAM wParam
, LPARAM lParam
)
1204 HOLEMENU hOleMenu
= 0;
1205 OleMenuDescriptor
*pOleMenuDescriptor
= NULL
;
1206 OleMenuHookItem
*pHookItem
= NULL
;
1209 TRACE("%i, %04x, %08x\n", code
, wParam
, (unsigned)lParam
);
1211 /* Check if we're being asked to process a messages */
1212 if ( HC_ACTION
!= code
)
1215 /* Retrieve the current message being dispatched from lParam */
1216 pMsg
= (LPMSG
)lParam
;
1218 /* Check if the message is destined for a window we are interested in:
1219 * If the window has an OLEMenu property we may need to dispatch
1220 * the menu message to its active objects window instead. */
1222 hOleMenu
= (HOLEMENU
)GetPropA( pMsg
->hwnd
, "PROP_OLEMenuDescriptor" );
1226 /* Process menu messages */
1227 switch( pMsg
->message
)
1231 wCode
= HIWORD(pMsg
->wParam
); /* Get notification code */
1233 goto NEXTHOOK
; /* Not a menu message */
1240 /* Get the menu descriptor */
1241 pOleMenuDescriptor
= (OleMenuDescriptor
*) GlobalLock( hOleMenu
);
1242 if ( !pOleMenuDescriptor
) /* Bad descriptor! */
1245 /* If the message was for the server dispatch it accordingly */
1246 if ( pOleMenuDescriptor
->bIsServerItem
)
1248 /* Change the hWnd in the message to the active objects hWnd.
1249 * The message loop which reads this message will automatically
1250 * dispatch it to the embedded objects window. */
1251 pMsg
->hwnd
= pOleMenuDescriptor
->hwndActiveObject
;
1255 if ( pOleMenuDescriptor
)
1256 GlobalUnlock( hOleMenu
);
1258 /* Lookup the hook item for the current thread */
1259 if ( !( pHookItem
= OLEMenu_IsHookInstalled( GetCurrentThreadId() ) ) )
1261 /* This should never fail!! */
1262 WARN("could not retrieve hHook for current thread!\n" );
1266 /* Pass on the message to the next hooker */
1267 return CallNextHookEx( pHookItem
->GetMsg_hHook
, code
, wParam
, lParam
);
1270 /***********************************************************************
1271 * OleCreateMenuDescriptor [OLE32.97]
1272 * Creates an OLE menu descriptor for OLE to use when dispatching
1273 * menu messages and commands.
1276 * hmenuCombined - Handle to the objects combined menu
1277 * lpMenuWidths - Pointer to array of 6 LONG's indicating menus per group
1280 HOLEMENU WINAPI
OleCreateMenuDescriptor(
1281 HMENU hmenuCombined
,
1282 LPOLEMENUGROUPWIDTHS lpMenuWidths
)
1285 OleMenuDescriptor
*pOleMenuDescriptor
;
1288 if ( !hmenuCombined
|| !lpMenuWidths
)
1291 /* Create an OLE menu descriptor */
1292 if ( !(hOleMenu
= GlobalAlloc(GMEM_MOVEABLE
| GMEM_ZEROINIT
,
1293 sizeof(OleMenuDescriptor
) ) ) )
1296 pOleMenuDescriptor
= (OleMenuDescriptor
*) GlobalLock( hOleMenu
);
1297 if ( !pOleMenuDescriptor
)
1300 /* Initialize menu group widths and hmenu */
1301 for ( i
= 0; i
< 6; i
++ )
1302 pOleMenuDescriptor
->mgw
.width
[i
] = lpMenuWidths
->width
[i
];
1304 pOleMenuDescriptor
->hmenuCombined
= hmenuCombined
;
1305 pOleMenuDescriptor
->bIsServerItem
= FALSE
;
1306 GlobalUnlock( hOleMenu
);
1311 /***********************************************************************
1312 * OleDestroyMenuDescriptor [OLE32.99]
1313 * Destroy the shared menu descriptor
1315 HRESULT WINAPI
OleDestroyMenuDescriptor(
1316 HOLEMENU hmenuDescriptor
)
1318 if ( hmenuDescriptor
)
1319 GlobalFree( hmenuDescriptor
);
1323 /***********************************************************************
1324 * OleSetMenuDescriptor [OLE32.129]
1325 * Installs or removes OLE dispatching code for the containers frame window
1326 * FIXME: The lpFrame and lpActiveObject parameters are currently ignored
1327 * OLE should install context sensitive help F1 filtering for the app when
1328 * these are non null.
1331 * hOleMenu Handle to composite menu descriptor
1332 * hwndFrame Handle to containers frame window
1333 * hwndActiveObject Handle to objects in-place activation window
1334 * lpFrame Pointer to IOleInPlaceFrame on containers window
1335 * lpActiveObject Pointer to IOleInPlaceActiveObject on active in-place object
1338 * S_OK - menu installed correctly
1339 * E_FAIL, E_INVALIDARG, E_UNEXPECTED - failure
1341 HRESULT WINAPI
OleSetMenuDescriptor(
1344 HWND hwndActiveObject
,
1345 LPOLEINPLACEFRAME lpFrame
,
1346 LPOLEINPLACEACTIVEOBJECT lpActiveObject
)
1348 OleMenuDescriptor
*pOleMenuDescriptor
= NULL
;
1351 if ( !hwndFrame
|| (hOleMenu
&& !hwndActiveObject
) )
1352 return E_INVALIDARG
;
1354 if ( lpFrame
|| lpActiveObject
)
1356 FIXME("(%x, %x, %x, %p, %p), Context sensitive help filtering not implemented!\n",
1357 (unsigned int)hOleMenu
,
1364 /* Set up a message hook to intercept the containers frame window messages.
1365 * The message filter is responsible for dispatching menu messages from the
1366 * shared menu which are intended for the object.
1369 if ( hOleMenu
) /* Want to install dispatching code */
1371 /* If OLEMenu hooks are already installed for this thread, fail
1372 * Note: This effectively means that OleSetMenuDescriptor cannot
1373 * be called twice in succession on the same frame window
1374 * without first calling it with a null hOleMenu to uninstall */
1375 if ( OLEMenu_IsHookInstalled( GetCurrentThreadId() ) )
1378 /* Get the menu descriptor */
1379 pOleMenuDescriptor
= (OleMenuDescriptor
*) GlobalLock( hOleMenu
);
1380 if ( !pOleMenuDescriptor
)
1381 return E_UNEXPECTED
;
1383 /* Update the menu descriptor */
1384 pOleMenuDescriptor
->hwndFrame
= hwndFrame
;
1385 pOleMenuDescriptor
->hwndActiveObject
= hwndActiveObject
;
1387 GlobalUnlock( hOleMenu
);
1388 pOleMenuDescriptor
= NULL
;
1390 /* Add a menu descriptor windows property to the frame window */
1391 SetPropA( hwndFrame
, "PROP_OLEMenuDescriptor", hOleMenu
);
1393 /* Install thread scope message hooks for WH_GETMESSAGE and WH_CALLWNDPROC */
1394 if ( !OLEMenu_InstallHooks( GetCurrentThreadId() ) )
1397 else /* Want to uninstall dispatching code */
1399 /* Uninstall the hooks */
1400 if ( !OLEMenu_UnInstallHooks( GetCurrentThreadId() ) )
1403 /* Remove the menu descriptor property from the frame window */
1404 RemovePropA( hwndFrame
, "PROP_OLEMenuDescriptor" );
1410 /******************************************************************************
1411 * IsAccelerator [OLE32.75]
1412 * Mostly copied from controls/menu.c TranslateAccelerator implementation
1414 BOOL WINAPI
IsAccelerator(HACCEL hAccel
, int cAccelEntries
, LPMSG lpMsg
, WORD
* lpwCmd
)
1417 LPACCEL16 lpAccelTbl
;
1420 if(!lpMsg
) return FALSE
;
1421 if (!hAccel
|| !(lpAccelTbl
= (LPACCEL16
)LockResource16(hAccel
)))
1423 WARN_(accel
)("invalid accel handle=%04x\n", hAccel
);
1426 if((lpMsg
->message
!= WM_KEYDOWN
&&
1427 lpMsg
->message
!= WM_KEYUP
&&
1428 lpMsg
->message
!= WM_SYSKEYDOWN
&&
1429 lpMsg
->message
!= WM_SYSKEYUP
&&
1430 lpMsg
->message
!= WM_CHAR
)) return FALSE
;
1432 TRACE_(accel
)("hAccel=%04x, cAccelEntries=%d,"
1433 "msg->hwnd=%04x, msg->message=%04x, wParam=%08x, lParam=%08lx\n",
1434 hAccel
, cAccelEntries
,
1435 lpMsg
->hwnd
, lpMsg
->message
, lpMsg
->wParam
, lpMsg
->lParam
);
1436 for(i
= 0; i
< cAccelEntries
; i
++)
1438 if(lpAccelTbl
[i
].key
!= lpMsg
->wParam
)
1441 if(lpMsg
->message
== WM_CHAR
)
1443 if(!(lpAccelTbl
[i
].fVirt
& FALT
) && !(lpAccelTbl
[i
].fVirt
& FVIRTKEY
))
1445 TRACE_(accel
)("found accel for WM_CHAR: ('%c')\n", lpMsg
->wParam
& 0xff);
1451 if(lpAccelTbl
[i
].fVirt
& FVIRTKEY
)
1454 TRACE_(accel
)("found accel for virt_key %04x (scan %04x)\n",
1455 lpMsg
->wParam
, HIWORD(lpMsg
->lParam
) & 0xff);
1456 if(GetKeyState(VK_SHIFT
) & 0x8000) mask
|= FSHIFT
;
1457 if(GetKeyState(VK_CONTROL
) & 0x8000) mask
|= FCONTROL
;
1458 if(GetKeyState(VK_MENU
) & 0x8000) mask
|= FALT
;
1459 if(mask
== (lpAccelTbl
[i
].fVirt
& (FSHIFT
| FCONTROL
| FALT
))) goto found
;
1460 TRACE_(accel
)("incorrect SHIFT/CTRL/ALT-state\n");
1464 if(!(lpMsg
->lParam
& 0x01000000)) /* no special_key */
1466 if((lpAccelTbl
[i
].fVirt
& FALT
) && (lpMsg
->lParam
& 0x20000000))
1467 { /* ^^ ALT pressed */
1468 TRACE_(accel
)("found accel for Alt-%c\n", lpMsg
->wParam
& 0xff);
1476 WARN_(accel
)("couldn't translate accelerator key\n");
1480 if(lpwCmd
) *lpwCmd
= lpAccelTbl
[i
].cmd
;
1484 /***********************************************************************
1485 * ReleaseStgMedium [OLE32.140]
1487 void WINAPI
ReleaseStgMedium(
1490 switch (pmedium
->tymed
)
1494 if ( (pmedium
->pUnkForRelease
==0) &&
1495 (pmedium
->u
.hGlobal
!=0) )
1496 GlobalFree(pmedium
->u
.hGlobal
);
1498 pmedium
->u
.hGlobal
= 0;
1503 if (pmedium
->u
.lpszFileName
!=0)
1505 if (pmedium
->pUnkForRelease
==0)
1507 DeleteFileW(pmedium
->u
.lpszFileName
);
1510 CoTaskMemFree(pmedium
->u
.lpszFileName
);
1513 pmedium
->u
.lpszFileName
= 0;
1518 if (pmedium
->u
.pstm
!=0)
1520 IStream_Release(pmedium
->u
.pstm
);
1523 pmedium
->u
.pstm
= 0;
1526 case TYMED_ISTORAGE
:
1528 if (pmedium
->u
.pstg
!=0)
1530 IStorage_Release(pmedium
->u
.pstg
);
1533 pmedium
->u
.pstg
= 0;
1538 if ( (pmedium
->pUnkForRelease
==0) &&
1539 (pmedium
->u
.hGlobal
!=0) )
1540 DeleteObject(pmedium
->u
.hGlobal
);
1542 pmedium
->u
.hGlobal
= 0;
1547 if ( (pmedium
->pUnkForRelease
==0) &&
1548 (pmedium
->u
.hMetaFilePict
!=0) )
1550 LPMETAFILEPICT pMP
= GlobalLock(pmedium
->u
.hGlobal
);
1551 DeleteMetaFile(pMP
->hMF
);
1552 GlobalUnlock(pmedium
->u
.hGlobal
);
1553 GlobalFree(pmedium
->u
.hGlobal
);
1556 pmedium
->u
.hMetaFilePict
= 0;
1561 if ( (pmedium
->pUnkForRelease
==0) &&
1562 (pmedium
->u
.hEnhMetaFile
!=0) )
1564 DeleteEnhMetaFile(pmedium
->u
.hEnhMetaFile
);
1567 pmedium
->u
.hEnhMetaFile
= 0;
1576 * After cleaning up, the unknown is released
1578 if (pmedium
->pUnkForRelease
!=0)
1580 IUnknown_Release(pmedium
->pUnkForRelease
);
1581 pmedium
->pUnkForRelease
= 0;
1586 * OLEDD_Initialize()
1588 * Initializes the OLE drag and drop data structures.
1590 static void OLEDD_Initialize()
1594 ZeroMemory (&wndClass
, sizeof(WNDCLASSA
));
1595 wndClass
.style
= CS_GLOBALCLASS
;
1596 wndClass
.lpfnWndProc
= (WNDPROC
)OLEDD_DragTrackerWindowProc
;
1597 wndClass
.cbClsExtra
= 0;
1598 wndClass
.cbWndExtra
= sizeof(TrackerWindowInfo
*);
1599 wndClass
.hCursor
= 0;
1600 wndClass
.hbrBackground
= 0;
1601 wndClass
.lpszClassName
= OLEDD_DRAGTRACKERCLASS
;
1603 RegisterClassA (&wndClass
);
1607 * OLEDD_UnInitialize()
1609 * Releases the OLE drag and drop data structures.
1611 static void OLEDD_UnInitialize()
1614 * Simply empty the list.
1616 while (targetListHead
!=NULL
)
1618 RevokeDragDrop(targetListHead
->hwndTarget
);
1623 * OLEDD_InsertDropTarget()
1625 * Insert the target node in the tree.
1627 static void OLEDD_InsertDropTarget(DropTargetNode
* nodeToAdd
)
1629 DropTargetNode
* curNode
;
1630 DropTargetNode
** parentNodeLink
;
1633 * Iterate the tree to find the insertion point.
1635 curNode
= targetListHead
;
1636 parentNodeLink
= &targetListHead
;
1638 while (curNode
!=NULL
)
1640 if (nodeToAdd
->hwndTarget
<curNode
->hwndTarget
)
1643 * If the node we want to add has a smaller HWND, go left
1645 parentNodeLink
= &curNode
->prevDropTarget
;
1646 curNode
= curNode
->prevDropTarget
;
1648 else if (nodeToAdd
->hwndTarget
>curNode
->hwndTarget
)
1651 * If the node we want to add has a larger HWND, go right
1653 parentNodeLink
= &curNode
->nextDropTarget
;
1654 curNode
= curNode
->nextDropTarget
;
1659 * The item was found in the list. It shouldn't have been there
1667 * If we get here, we have found a spot for our item. The parentNodeLink
1668 * pointer points to the pointer that we have to modify.
1669 * The curNode should be NULL. We just have to establish the link and Voila!
1671 assert(curNode
==NULL
);
1672 assert(parentNodeLink
!=NULL
);
1673 assert(*parentNodeLink
==NULL
);
1675 *parentNodeLink
=nodeToAdd
;
1679 * OLEDD_ExtractDropTarget()
1681 * Removes the target node from the tree.
1683 static DropTargetNode
* OLEDD_ExtractDropTarget(HWND hwndOfTarget
)
1685 DropTargetNode
* curNode
;
1686 DropTargetNode
** parentNodeLink
;
1689 * Iterate the tree to find the insertion point.
1691 curNode
= targetListHead
;
1692 parentNodeLink
= &targetListHead
;
1694 while (curNode
!=NULL
)
1696 if (hwndOfTarget
<curNode
->hwndTarget
)
1699 * If the node we want to add has a smaller HWND, go left
1701 parentNodeLink
= &curNode
->prevDropTarget
;
1702 curNode
= curNode
->prevDropTarget
;
1704 else if (hwndOfTarget
>curNode
->hwndTarget
)
1707 * If the node we want to add has a larger HWND, go right
1709 parentNodeLink
= &curNode
->nextDropTarget
;
1710 curNode
= curNode
->nextDropTarget
;
1715 * The item was found in the list. Detach it from it's parent and
1716 * re-insert it's kids in the tree.
1718 assert(parentNodeLink
!=NULL
);
1719 assert(*parentNodeLink
==curNode
);
1722 * We arbitrately re-attach the left sub-tree to the parent.
1724 *parentNodeLink
= curNode
->prevDropTarget
;
1727 * And we re-insert the right subtree
1729 if (curNode
->nextDropTarget
!=NULL
)
1731 OLEDD_InsertDropTarget(curNode
->nextDropTarget
);
1735 * The node we found is still a valid node once we complete
1736 * the unlinking of the kids.
1738 curNode
->nextDropTarget
=NULL
;
1739 curNode
->prevDropTarget
=NULL
;
1746 * If we get here, the node is not in the tree
1752 * OLEDD_FindDropTarget()
1754 * Finds information about the drop target.
1756 static DropTargetNode
* OLEDD_FindDropTarget(HWND hwndOfTarget
)
1758 DropTargetNode
* curNode
;
1761 * Iterate the tree to find the HWND value.
1763 curNode
= targetListHead
;
1765 while (curNode
!=NULL
)
1767 if (hwndOfTarget
<curNode
->hwndTarget
)
1770 * If the node we want to add has a smaller HWND, go left
1772 curNode
= curNode
->prevDropTarget
;
1774 else if (hwndOfTarget
>curNode
->hwndTarget
)
1777 * If the node we want to add has a larger HWND, go right
1779 curNode
= curNode
->nextDropTarget
;
1784 * The item was found in the list.
1791 * If we get here, the item is not in the list
1797 * OLEDD_DragTrackerWindowProc()
1799 * This method is the WindowProcedure of the drag n drop tracking
1800 * window. During a drag n Drop operation, an invisible window is created
1801 * to receive the user input and act upon it. This procedure is in charge
1804 static LRESULT WINAPI
OLEDD_DragTrackerWindowProc(
1814 LPCREATESTRUCTA createStruct
= (LPCREATESTRUCTA
)lParam
;
1816 SetWindowLongA(hwnd
, 0, (LONG
)createStruct
->lpCreateParams
);
1823 TrackerWindowInfo
* trackerInfo
= (TrackerWindowInfo
*)GetWindowLongA(hwnd
, 0);
1827 * Get the current mouse position in screen coordinates.
1829 mousePos
.x
= LOWORD(lParam
);
1830 mousePos
.y
= HIWORD(lParam
);
1831 ClientToScreen(hwnd
, &mousePos
);
1834 * Track the movement of the mouse.
1836 OLEDD_TrackMouseMove(trackerInfo
, mousePos
, wParam
);
1843 case WM_LBUTTONDOWN
:
1844 case WM_MBUTTONDOWN
:
1845 case WM_RBUTTONDOWN
:
1847 TrackerWindowInfo
* trackerInfo
= (TrackerWindowInfo
*)GetWindowLongA(hwnd
, 0);
1851 * Get the current mouse position in screen coordinates.
1853 mousePos
.x
= LOWORD(lParam
);
1854 mousePos
.y
= HIWORD(lParam
);
1855 ClientToScreen(hwnd
, &mousePos
);
1858 * Notify everyone that the button state changed
1859 * TODO: Check if the "escape" key was pressed.
1861 OLEDD_TrackStateChange(trackerInfo
, mousePos
, wParam
);
1868 * This is a window proc after all. Let's call the default.
1870 return DefWindowProcA (hwnd
, uMsg
, wParam
, lParam
);
1874 * OLEDD_TrackMouseMove()
1876 * This method is invoked while a drag and drop operation is in effect.
1877 * it will generate the appropriate callbacks in the drop source
1878 * and drop target. It will also provide the expected feedback to
1882 * trackerInfo - Pointer to the structure identifying the
1883 * drag & drop operation that is currently
1885 * mousePos - Current position of the mouse in screen
1887 * keyState - Contains the state of the shift keys and the
1888 * mouse buttons (MK_LBUTTON and the like)
1890 static void OLEDD_TrackMouseMove(
1891 TrackerWindowInfo
* trackerInfo
,
1895 HWND hwndNewTarget
= 0;
1899 * Get the handle of the window under the mouse
1901 hwndNewTarget
= WindowFromPoint(mousePos
);
1904 * Every time, we re-initialize the effects passed to the
1905 * IDropTarget to the effects allowed by the source.
1907 *trackerInfo
->pdwEffect
= trackerInfo
->dwOKEffect
;
1910 * If we are hovering over the same target as before, send the
1911 * DragOver notification
1913 if ( (trackerInfo
->curDragTarget
!= 0) &&
1914 (trackerInfo
->curDragTargetHWND
==hwndNewTarget
) )
1916 POINTL mousePosParam
;
1919 * The documentation tells me that the coordinate should be in the target
1920 * window's coordinate space. However, the tests I made tell me the
1921 * coordinates should be in screen coordinates.
1923 mousePosParam
.x
= mousePos
.x
;
1924 mousePosParam
.y
= mousePos
.y
;
1926 IDropTarget_DragOver(trackerInfo
->curDragTarget
,
1929 trackerInfo
->pdwEffect
);
1933 DropTargetNode
* newDropTargetNode
= 0;
1936 * If we changed window, we have to notify our old target and check for
1939 if (trackerInfo
->curDragTarget
!=0)
1941 IDropTarget_DragLeave(trackerInfo
->curDragTarget
);
1945 * Make sure we're hovering over a window.
1947 if (hwndNewTarget
!=0)
1950 * Find-out if there is a drag target under the mouse
1952 HWND nexttar
= hwndNewTarget
;
1954 newDropTargetNode
= OLEDD_FindDropTarget(nexttar
);
1955 } while (!newDropTargetNode
&& (nexttar
= GetParent(nexttar
)) != 0);
1956 if(nexttar
) hwndNewTarget
= nexttar
;
1958 trackerInfo
->curDragTargetHWND
= hwndNewTarget
;
1959 trackerInfo
->curDragTarget
= newDropTargetNode
? newDropTargetNode
->dropTarget
: 0;
1962 * If there is, notify it that we just dragged-in
1964 if (trackerInfo
->curDragTarget
!=0)
1966 POINTL mousePosParam
;
1969 * The documentation tells me that the coordinate should be in the target
1970 * window's coordinate space. However, the tests I made tell me the
1971 * coordinates should be in screen coordinates.
1973 mousePosParam
.x
= mousePos
.x
;
1974 mousePosParam
.y
= mousePos
.y
;
1976 IDropTarget_DragEnter(trackerInfo
->curDragTarget
,
1977 trackerInfo
->dataObject
,
1980 trackerInfo
->pdwEffect
);
1986 * The mouse is not over a window so we don't track anything.
1988 trackerInfo
->curDragTargetHWND
= 0;
1989 trackerInfo
->curDragTarget
= 0;
1994 * Now that we have done that, we have to tell the source to give
1995 * us feedback on the work being done by the target. If we don't
1996 * have a target, simulate no effect.
1998 if (trackerInfo
->curDragTarget
==0)
2000 *trackerInfo
->pdwEffect
= DROPEFFECT_NONE
;
2003 hr
= IDropSource_GiveFeedback(trackerInfo
->dropSource
,
2004 *trackerInfo
->pdwEffect
);
2007 * When we ask for feedback from the drop source, sometimes it will
2008 * do all the necessary work and sometimes it will not handle it
2009 * when that's the case, we must display the standard drag and drop
2012 if (hr
==DRAGDROP_S_USEDEFAULTCURSORS
)
2014 if (*trackerInfo
->pdwEffect
& DROPEFFECT_MOVE
)
2016 SetCursor(LoadCursorA(OLE32_hInstance
, MAKEINTRESOURCEA(1)));
2018 else if (*trackerInfo
->pdwEffect
& DROPEFFECT_COPY
)
2020 SetCursor(LoadCursorA(OLE32_hInstance
, MAKEINTRESOURCEA(2)));
2022 else if (*trackerInfo
->pdwEffect
& DROPEFFECT_LINK
)
2024 SetCursor(LoadCursorA(OLE32_hInstance
, MAKEINTRESOURCEA(3)));
2028 SetCursor(LoadCursorA(OLE32_hInstance
, MAKEINTRESOURCEA(0)));
2034 * OLEDD_TrackStateChange()
2036 * This method is invoked while a drag and drop operation is in effect.
2037 * It is used to notify the drop target/drop source callbacks when
2038 * the state of the keyboard or mouse button change.
2041 * trackerInfo - Pointer to the structure identifying the
2042 * drag & drop operation that is currently
2044 * mousePos - Current position of the mouse in screen
2046 * keyState - Contains the state of the shift keys and the
2047 * mouse buttons (MK_LBUTTON and the like)
2049 static void OLEDD_TrackStateChange(
2050 TrackerWindowInfo
* trackerInfo
,
2055 * Ask the drop source what to do with the operation.
2057 trackerInfo
->returnValue
= IDropSource_QueryContinueDrag(
2058 trackerInfo
->dropSource
,
2059 trackerInfo
->escPressed
,
2063 * All the return valued will stop the operation except the S_OK
2066 if (trackerInfo
->returnValue
!=S_OK
)
2069 * Make sure the message loop in DoDragDrop stops
2071 trackerInfo
->trackingDone
= TRUE
;
2074 * Release the mouse in case the drop target decides to show a popup
2075 * or a menu or something.
2080 * If we end-up over a target, drop the object in the target or
2081 * inform the target that the operation was cancelled.
2083 if (trackerInfo
->curDragTarget
!=0)
2085 switch (trackerInfo
->returnValue
)
2088 * If the source wants us to complete the operation, we tell
2089 * the drop target that we just dropped the object in it.
2091 case DRAGDROP_S_DROP
:
2093 POINTL mousePosParam
;
2096 * The documentation tells me that the coordinate should be
2097 * in the target window's coordinate space. However, the tests
2098 * I made tell me the coordinates should be in screen coordinates.
2100 mousePosParam
.x
= mousePos
.x
;
2101 mousePosParam
.y
= mousePos
.y
;
2103 IDropTarget_Drop(trackerInfo
->curDragTarget
,
2104 trackerInfo
->dataObject
,
2107 trackerInfo
->pdwEffect
);
2111 * If the source told us that we should cancel, fool the drop
2112 * target by telling it that the mouse left it's window.
2113 * Also set the drop effect to "NONE" in case the application
2114 * ignores the result of DoDragDrop.
2116 case DRAGDROP_S_CANCEL
:
2117 IDropTarget_DragLeave(trackerInfo
->curDragTarget
);
2118 *trackerInfo
->pdwEffect
= DROPEFFECT_NONE
;
2126 * OLEDD_GetButtonState()
2128 * This method will use the current state of the keyboard to build
2129 * a button state mask equivalent to the one passed in the
2130 * WM_MOUSEMOVE wParam.
2132 static DWORD
OLEDD_GetButtonState()
2134 BYTE keyboardState
[256];
2137 GetKeyboardState(keyboardState
);
2139 if ( (keyboardState
[VK_SHIFT
] & 0x80) !=0)
2140 keyMask
|= MK_SHIFT
;
2142 if ( (keyboardState
[VK_CONTROL
] & 0x80) !=0)
2143 keyMask
|= MK_CONTROL
;
2145 if ( (keyboardState
[VK_LBUTTON
] & 0x80) !=0)
2146 keyMask
|= MK_LBUTTON
;
2148 if ( (keyboardState
[VK_RBUTTON
] & 0x80) !=0)
2149 keyMask
|= MK_RBUTTON
;
2151 if ( (keyboardState
[VK_MBUTTON
] & 0x80) !=0)
2152 keyMask
|= MK_MBUTTON
;
2158 * OLEDD_GetButtonState()
2160 * This method will read the default value of the registry key in
2161 * parameter and extract a DWORD value from it. The registry key value
2162 * can be in a string key or a DWORD key.
2165 * regKey - Key to read the default value from
2166 * pdwValue - Pointer to the location where the DWORD
2167 * value is returned. This value is not modified
2168 * if the value is not found.
2171 static void OLEUTL_ReadRegistryDWORDValue(
2180 lres
= RegQueryValueExA(regKey
,
2187 if (lres
==ERROR_SUCCESS
)
2192 *pdwValue
= *(DWORD
*)buffer
;
2197 *pdwValue
= (DWORD
)strtoul(buffer
, NULL
, 10);
2203 /******************************************************************************
2204 * OleMetaFilePictFromIconAndLabel (OLE2.56)
2206 * Returns a global memory handle to a metafile which contains the icon and
2208 * I guess the result of that should look somehow like desktop icons.
2209 * If no hIcon is given, we load the icon via lpszSourceFile and iIconIndex.
2210 * This code might be wrong at some places.
2212 HGLOBAL16 WINAPI
OleMetaFilePictFromIconAndLabel16(
2214 LPCOLESTR16 lpszLabel
,
2215 LPCOLESTR16 lpszSourceFile
,
2222 FIXME("(%04x, '%s', '%s', %d): incorrect metrics, please try to correct them !\n\n\n", hIcon
, lpszLabel
, lpszSourceFile
, iIconIndex
);
2225 if (lpszSourceFile
) {
2226 HINSTANCE16 hInstance
= LoadLibrary16(lpszSourceFile
);
2228 /* load the icon at index from lpszSourceFile */
2229 hIcon
= (HICON16
)LoadIconA(hInstance
, (LPCSTR
)(DWORD
)iIconIndex
);
2230 FreeLibrary16(hInstance
);
2232 return (HGLOBAL
)NULL
;
2235 hdc
= CreateMetaFile16(NULL
);
2236 DrawIcon(hdc
, 0, 0, hIcon
); /* FIXME */
2237 TextOutA(hdc
, 0, 0, lpszLabel
, 1); /* FIXME */
2238 hmf
= GlobalAlloc16(0, sizeof(METAFILEPICT16
));
2239 mf
= (METAFILEPICT16
*)GlobalLock16(hmf
);
2240 mf
->mm
= MM_ANISOTROPIC
;
2241 mf
->xExt
= 20; /* FIXME: bogus */
2242 mf
->yExt
= 20; /* dito */
2243 mf
->hMF
= CloseMetaFile16(hdc
);
2247 /******************************************************************************
2248 * DllDebugObjectRPCHook (OLE32.62)
2249 * turns on and off internal debugging, pointer is only used on macintosh
2252 BOOL WINAPI
DllDebugObjectRPCHook(BOOL b
, void *dummy
)