4 * Copyright 1995 Martin von Loewis
5 * Copyright 1999 Francis Beaudet
6 * Copyright 1999 Noel Borthwick
21 #include "wine/obj_clientserver.h"
22 #include "wine/winbase16.h"
23 #include "wine/wingdi16.h"
24 #include "wine/winuser16.h"
25 #include "debugtools.h"
28 #include "ole32_main.h"
30 DEFAULT_DEBUG_CHANNEL(ole
);
31 DECLARE_DEBUG_CHANNEL(accel
);
33 /******************************************************************************
34 * These are static/global variables and internal data structures that the
35 * OLE module uses to maintain it's state.
37 typedef struct tagDropTargetNode
40 IDropTarget
* dropTarget
;
41 struct tagDropTargetNode
* prevDropTarget
;
42 struct tagDropTargetNode
* nextDropTarget
;
45 typedef struct tagTrackerWindowInfo
47 IDataObject
* dataObject
;
48 IDropSource
* dropSource
;
55 HWND curDragTargetHWND
;
56 IDropTarget
* curDragTarget
;
59 typedef struct tagOleMenuDescriptor
/* OleMenuDescriptor */
61 HWND hwndFrame
; /* The containers frame window */
62 HWND hwndActiveObject
; /* The active objects window */
63 OLEMENUGROUPWIDTHS mgw
; /* OLE menu group widths for the shared menu */
64 HMENU hmenuCombined
; /* The combined menu */
65 BOOL bIsServerItem
; /* True if the currently open popup belongs to the server */
68 typedef struct tagOleMenuHookItem
/* OleMenu hook item in per thread hook list */
70 DWORD tid
; /* Thread Id */
71 HANDLE hHeap
; /* Heap this is allocated from */
72 HHOOK GetMsg_hHook
; /* message hook for WH_GETMESSAGE */
73 HHOOK CallWndProc_hHook
; /* message hook for WH_CALLWNDPROC */
74 struct tagOleMenuHookItem
*next
;
77 static OleMenuHookItem
*hook_list
;
80 * This is the lock count on the OLE library. It is controlled by the
81 * OLEInitialize/OLEUninitialize methods.
83 static ULONG OLE_moduleLockCount
= 0;
86 * Name of our registered window class.
88 static const char OLEDD_DRAGTRACKERCLASS
[] = "WineDragDropTracker32";
91 * This is the head of the Drop target container.
93 static DropTargetNode
* targetListHead
= NULL
;
95 /******************************************************************************
96 * These are the prototypes of miscelaneous utility methods
98 static void OLEUTL_ReadRegistryDWORDValue(HKEY regKey
, DWORD
* pdwValue
);
100 /******************************************************************************
101 * These are the prototypes of the utility methods used to manage a shared menu
103 static void OLEMenu_Initialize();
104 static void OLEMenu_UnInitialize();
105 BOOL
OLEMenu_InstallHooks( DWORD tid
);
106 BOOL
OLEMenu_UnInstallHooks( DWORD tid
);
107 OleMenuHookItem
* OLEMenu_IsHookInstalled( DWORD tid
);
108 static BOOL
OLEMenu_FindMainMenuIndex( HMENU hMainMenu
, HMENU hPopupMenu
, UINT
*pnPos
);
109 BOOL
OLEMenu_SetIsServerMenu( HMENU hmenu
, OleMenuDescriptor
*pOleMenuDescriptor
);
110 LRESULT CALLBACK
OLEMenu_CallWndProc(INT code
, WPARAM wParam
, LPARAM lParam
);
111 LRESULT CALLBACK
OLEMenu_GetMsgProc(INT code
, WPARAM wParam
, LPARAM lParam
);
113 /******************************************************************************
114 * These are the prototypes of the OLE Clipboard initialization methods (in clipboard.c)
116 void OLEClipbrd_UnInitialize();
117 void OLEClipbrd_Initialize();
119 /******************************************************************************
120 * These are the prototypes of the utility methods used for OLE Drag n Drop
122 static void OLEDD_Initialize();
123 static void OLEDD_UnInitialize();
124 static void OLEDD_InsertDropTarget(
125 DropTargetNode
* nodeToAdd
);
126 static DropTargetNode
* OLEDD_ExtractDropTarget(
128 static DropTargetNode
* OLEDD_FindDropTarget(
130 static LRESULT WINAPI
OLEDD_DragTrackerWindowProc(
135 static void OLEDD_TrackMouseMove(
136 TrackerWindowInfo
* trackerInfo
,
139 static void OLEDD_TrackStateChange(
140 TrackerWindowInfo
* trackerInfo
,
143 static DWORD
OLEDD_GetButtonState();
146 /******************************************************************************
147 * OleBuildVersion [OLE2.1]
149 DWORD WINAPI
OleBuildVersion(void)
151 TRACE("Returning version %d, build %d.\n", rmm
, rup
);
152 return (rmm
<<16)+rup
;
155 /***********************************************************************
156 * OleInitialize (OLE2.2) (OLE32.108)
158 HRESULT WINAPI
OleInitialize(LPVOID reserved
)
162 TRACE("(%p)\n", reserved
);
165 * The first duty of the OleInitialize is to initialize the COM libraries.
167 hr
= CoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
170 * If the CoInitializeEx call failed, the OLE libraries can't be
177 * Then, it has to initialize the OLE specific modules.
181 * Object linking and Embedding
182 * In-place activation
184 if (OLE_moduleLockCount
==0)
187 * Initialize the libraries.
189 TRACE("() - Initializing the OLE libraries\n");
194 OLEClipbrd_Initialize();
204 OLEMenu_Initialize();
208 * Then, we increase the lock count on the OLE module.
210 OLE_moduleLockCount
++;
215 /******************************************************************************
216 * CoGetCurrentProcess [COMPOBJ.34] [OLE2.2][OLE32.108]
219 * Is DWORD really the correct return type for this function?
221 DWORD WINAPI
CoGetCurrentProcess(void)
223 return GetCurrentProcessId();
226 /******************************************************************************
227 * OleUninitialize [OLE2.3] [OLE32.131]
229 void WINAPI
OleUninitialize(void)
234 * Decrease the lock count on the OLE module.
236 OLE_moduleLockCount
--;
239 * If we hit the bottom of the lock stack, free the libraries.
241 if (OLE_moduleLockCount
==0)
244 * Actually free the libraries.
246 TRACE("() - Freeing the last reference count\n");
251 OLEClipbrd_UnInitialize();
256 OLEDD_UnInitialize();
261 OLEMenu_UnInitialize();
265 * Then, uninitialize the COM libraries.
270 /******************************************************************************
271 * CoRegisterMessageFilter [OLE32.38]
273 HRESULT WINAPI
CoRegisterMessageFilter(
274 LPMESSAGEFILTER lpMessageFilter
, /* [in] Pointer to interface */
275 LPMESSAGEFILTER
*lplpMessageFilter
/* [out] Indirect pointer to prior instance if non-NULL */
278 if (lplpMessageFilter
) {
279 *lplpMessageFilter
= NULL
;
284 /******************************************************************************
285 * OleInitializeWOW [OLE32.109]
287 HRESULT WINAPI
OleInitializeWOW(DWORD x
) {
288 FIXME("(0x%08lx),stub!\n",x
);
292 /***********************************************************************
293 * RegisterDragDrop16 (OLE2.35)
295 HRESULT WINAPI
RegisterDragDrop16(
297 LPDROPTARGET pDropTarget
299 FIXME("(0x%04x,%p),stub!\n",hwnd
,pDropTarget
);
303 /***********************************************************************
304 * RegisterDragDrop (OLE32.139)
306 HRESULT WINAPI
RegisterDragDrop(
308 LPDROPTARGET pDropTarget
)
310 DropTargetNode
* dropTargetInfo
;
312 TRACE("(0x%x,%p)\n", hwnd
, pDropTarget
);
315 * First, check if the window is already registered.
317 dropTargetInfo
= OLEDD_FindDropTarget(hwnd
);
319 if (dropTargetInfo
!=NULL
)
320 return DRAGDROP_E_ALREADYREGISTERED
;
323 * If it's not there, we can add it. We first create a node for it.
325 dropTargetInfo
= HeapAlloc(GetProcessHeap(), 0, sizeof(DropTargetNode
));
327 if (dropTargetInfo
==NULL
)
328 return E_OUTOFMEMORY
;
330 dropTargetInfo
->hwndTarget
= hwnd
;
331 dropTargetInfo
->prevDropTarget
= NULL
;
332 dropTargetInfo
->nextDropTarget
= NULL
;
335 * Don't forget that this is an interface pointer, need to nail it down since
336 * we keep a copy of it.
338 dropTargetInfo
->dropTarget
= pDropTarget
;
339 IDropTarget_AddRef(dropTargetInfo
->dropTarget
);
341 OLEDD_InsertDropTarget(dropTargetInfo
);
346 /***********************************************************************
347 * RevokeDragDrop16 (OLE2.36)
349 HRESULT WINAPI
RevokeDragDrop16(
352 FIXME("(0x%04x),stub!\n",hwnd
);
356 /***********************************************************************
357 * RevokeDragDrop (OLE32.141)
359 HRESULT WINAPI
RevokeDragDrop(
362 DropTargetNode
* dropTargetInfo
;
364 TRACE("(0x%x)\n", hwnd
);
367 * First, check if the window is already registered.
369 dropTargetInfo
= OLEDD_ExtractDropTarget(hwnd
);
372 * If it ain't in there, it's an error.
374 if (dropTargetInfo
==NULL
)
375 return DRAGDROP_E_NOTREGISTERED
;
378 * If it's in there, clean-up it's used memory and
381 IDropTarget_Release(dropTargetInfo
->dropTarget
);
382 HeapFree(GetProcessHeap(), 0, dropTargetInfo
);
387 /***********************************************************************
388 * OleRegGetUserType (OLE32.122)
390 * This implementation of OleRegGetUserType ignores the dwFormOfType
391 * parameter and always returns the full name of the object. This is
392 * not too bad since this is the case for many objects because of the
393 * way they are registered.
395 HRESULT WINAPI
OleRegGetUserType(
398 LPOLESTR
* pszUserType
)
408 * Initialize the out parameter.
413 * Build the key name we're looking for
415 sprintf( keyName
, "CLSID\\{%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}\\",
416 clsid
->Data1
, clsid
->Data2
, clsid
->Data3
,
417 clsid
->Data4
[0], clsid
->Data4
[1], clsid
->Data4
[2], clsid
->Data4
[3],
418 clsid
->Data4
[4], clsid
->Data4
[5], clsid
->Data4
[6], clsid
->Data4
[7] );
420 TRACE("(%s, %ld, %p)\n", keyName
, dwFormOfType
, pszUserType
);
423 * Open the class id Key
425 hres
= RegOpenKeyA(HKEY_CLASSES_ROOT
,
429 if (hres
!= ERROR_SUCCESS
)
430 return REGDB_E_CLASSNOTREG
;
433 * Retrieve the size of the name string.
437 hres
= RegQueryValueExA(clsidKey
,
444 if (hres
!=ERROR_SUCCESS
)
446 RegCloseKey(clsidKey
);
447 return REGDB_E_READREGDB
;
451 * Allocate a buffer for the registry value.
453 *pszUserType
= CoTaskMemAlloc(cbData
*2);
455 if (*pszUserType
==NULL
)
457 RegCloseKey(clsidKey
);
458 return E_OUTOFMEMORY
;
461 buffer
= HeapAlloc(GetProcessHeap(), 0, cbData
);
465 RegCloseKey(clsidKey
);
466 CoTaskMemFree(*pszUserType
);
468 return E_OUTOFMEMORY
;
471 hres
= RegQueryValueExA(clsidKey
,
478 RegCloseKey(clsidKey
);
481 if (hres
!=ERROR_SUCCESS
)
483 CoTaskMemFree(*pszUserType
);
486 retVal
= REGDB_E_READREGDB
;
490 MultiByteToWideChar( CP_ACP
, 0, buffer
, -1, *pszUserType
, cbData
/*FIXME*/ );
493 HeapFree(GetProcessHeap(), 0, buffer
);
498 /***********************************************************************
499 * DoDragDrop [OLE32.65]
501 HRESULT WINAPI
DoDragDrop (
502 IDataObject
*pDataObject
, /* [in] ptr to the data obj */
503 IDropSource
* pDropSource
, /* [in] ptr to the source obj */
504 DWORD dwOKEffect
, /* [in] effects allowed by the source */
505 DWORD
*pdwEffect
) /* [out] ptr to effects of the source */
507 TrackerWindowInfo trackerInfo
;
508 HWND hwndTrackWindow
;
511 TRACE("(DataObject %p, DropSource %p)\n", pDataObject
, pDropSource
);
514 * Setup the drag n drop tracking window.
516 trackerInfo
.dataObject
= pDataObject
;
517 trackerInfo
.dropSource
= pDropSource
;
518 trackerInfo
.dwOKEffect
= dwOKEffect
;
519 trackerInfo
.pdwEffect
= pdwEffect
;
520 trackerInfo
.trackingDone
= FALSE
;
521 trackerInfo
.escPressed
= FALSE
;
522 trackerInfo
.curDragTargetHWND
= 0;
523 trackerInfo
.curDragTarget
= 0;
525 hwndTrackWindow
= CreateWindowA(OLEDD_DRAGTRACKERCLASS
,
528 CW_USEDEFAULT
, CW_USEDEFAULT
,
529 CW_USEDEFAULT
, CW_USEDEFAULT
,
533 (LPVOID
)&trackerInfo
);
535 if (hwndTrackWindow
!=0)
538 * Capture the mouse input
540 SetCapture(hwndTrackWindow
);
543 * Pump messages. All mouse input should go the the capture window.
545 while (!trackerInfo
.trackingDone
&& GetMessageA(&msg
, 0, 0, 0) )
547 if ( (msg
.message
>= WM_KEYFIRST
) &&
548 (msg
.message
<= WM_KEYLAST
) )
551 * When keyboard messages are sent to windows on this thread, we
552 * want to ignore notify the drop source that the state changed.
553 * in the case of the Escape key, we also notify the drop source
554 * we give it a special meaning.
556 if ( (msg
.message
==WM_KEYDOWN
) &&
557 (msg
.wParam
==VK_ESCAPE
) )
559 trackerInfo
.escPressed
= TRUE
;
563 * Notify the drop source.
565 OLEDD_TrackStateChange(&trackerInfo
,
567 OLEDD_GetButtonState());
572 * Dispatch the messages only when it's not a keyboard message.
574 DispatchMessageA(&msg
);
579 * Destroy the temporary window.
581 DestroyWindow(hwndTrackWindow
);
583 return trackerInfo
.returnValue
;
589 /***********************************************************************
590 * OleQueryLinkFromData [OLE32.118]
592 HRESULT WINAPI
OleQueryLinkFromData(
593 IDataObject
* pSrcDataObject
)
595 FIXME("(%p),stub!\n", pSrcDataObject
);
599 /***********************************************************************
600 * OleRegGetMiscStatus [OLE32.121]
602 HRESULT WINAPI
OleRegGetMiscStatus(
614 * Initialize the out parameter.
619 * Build the key name we're looking for
621 sprintf( keyName
, "CLSID\\{%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}\\",
622 clsid
->Data1
, clsid
->Data2
, clsid
->Data3
,
623 clsid
->Data4
[0], clsid
->Data4
[1], clsid
->Data4
[2], clsid
->Data4
[3],
624 clsid
->Data4
[4], clsid
->Data4
[5], clsid
->Data4
[6], clsid
->Data4
[7] );
626 TRACE("(%s, %ld, %p)\n", keyName
, dwAspect
, pdwStatus
);
629 * Open the class id Key
631 result
= RegOpenKeyA(HKEY_CLASSES_ROOT
,
635 if (result
!= ERROR_SUCCESS
)
636 return REGDB_E_CLASSNOTREG
;
641 result
= RegOpenKeyA(clsidKey
,
646 if (result
!= ERROR_SUCCESS
)
648 RegCloseKey(clsidKey
);
649 return REGDB_E_READREGDB
;
653 * Read the default value
655 OLEUTL_ReadRegistryDWORDValue(miscStatusKey
, pdwStatus
);
658 * Open the key specific to the requested aspect.
660 sprintf(keyName
, "%ld", dwAspect
);
662 result
= RegOpenKeyA(miscStatusKey
,
666 if (result
== ERROR_SUCCESS
)
668 OLEUTL_ReadRegistryDWORDValue(aspectKey
, pdwStatus
);
669 RegCloseKey(aspectKey
);
675 RegCloseKey(miscStatusKey
);
676 RegCloseKey(clsidKey
);
681 /******************************************************************************
682 * OleSetContainedObject [OLE32.128]
684 HRESULT WINAPI
OleSetContainedObject(
688 IRunnableObject
* runnable
= NULL
;
691 TRACE("(%p,%x), stub!\n", pUnknown
, fContained
);
693 hres
= IUnknown_QueryInterface(pUnknown
,
694 &IID_IRunnableObject
,
699 hres
= IRunnableObject_SetContainedObject(runnable
, fContained
);
701 IRunnableObject_Release(runnable
);
709 /******************************************************************************
710 * OleLoad [OLE32.112]
712 HRESULT WINAPI
OleLoad(
715 LPOLECLIENTSITE pClientSite
,
718 IPersistStorage
* persistStorage
= NULL
;
719 IOleObject
* oleObject
= NULL
;
723 TRACE("(%p,%p,%p,%p)\n", pStg
, riid
, pClientSite
, ppvObj
);
726 * TODO, Conversion ... OleDoAutoConvert
730 * Get the class ID for the object.
732 hres
= IStorage_Stat(pStg
, &storageInfo
, STATFLAG_NONAME
);
735 * Now, try and create the handler for the object
737 hres
= CoCreateInstance(&storageInfo
.clsid
,
739 CLSCTX_INPROC_HANDLER
,
744 * If that fails, as it will most times, load the default
749 hres
= OleCreateDefaultHandler(&storageInfo
.clsid
,
756 * If we couldn't find a handler... this is bad. Abort the whole thing.
762 * Inform the new object of it's client site.
764 hres
= IOleObject_SetClientSite(oleObject
, pClientSite
);
767 * Initialize the object with it's IPersistStorage interface.
769 hres
= IOleObject_QueryInterface(oleObject
,
770 &IID_IPersistStorage
,
771 (void**)&persistStorage
);
775 IPersistStorage_Load(persistStorage
, pStg
);
777 IPersistStorage_Release(persistStorage
);
778 persistStorage
= NULL
;
782 * Return the requested interface to the caller.
784 hres
= IOleObject_QueryInterface(oleObject
, riid
, ppvObj
);
787 * Cleanup interfaces used internally
789 IOleObject_Release(oleObject
);
794 /***********************************************************************
795 * OleSave [OLE32.124]
797 HRESULT WINAPI
OleSave(
798 LPPERSISTSTORAGE pPS
,
805 TRACE("(%p,%p,%x)\n", pPS
, pStg
, fSameAsLoad
);
808 * First, we transfer the class ID (if available)
810 hres
= IPersistStorage_GetClassID(pPS
, &objectClass
);
814 WriteClassStg(pStg
, &objectClass
);
818 * Then, we ask the object to save itself to the
819 * storage. If it is successful, we commit the storage.
821 hres
= IPersistStorage_Save(pPS
, pStg
, fSameAsLoad
);
825 IStorage_Commit(pStg
,
833 /******************************************************************************
834 * OleLockRunning [OLE32.114]
836 HRESULT WINAPI
OleLockRunning(LPUNKNOWN pUnknown
, BOOL fLock
, BOOL fLastUnlockCloses
)
838 IRunnableObject
* runnable
= NULL
;
841 TRACE("(%p,%x,%x)\n", pUnknown
, fLock
, fLastUnlockCloses
);
843 hres
= IUnknown_QueryInterface(pUnknown
,
844 &IID_IRunnableObject
,
849 hres
= IRunnableObject_LockRunning(runnable
, fLock
, fLastUnlockCloses
);
851 IRunnableObject_Release(runnable
);
860 /**************************************************************************
861 * Internal methods to manage the shared OLE menu in response to the
862 * OLE***MenuDescriptor API
866 * OLEMenu_Initialize()
868 * Initializes the OLEMENU data structures.
870 static void OLEMenu_Initialize()
875 * OLEMenu_UnInitialize()
877 * Releases the OLEMENU data structures.
879 static void OLEMenu_UnInitialize()
883 /*************************************************************************
884 * OLEMenu_InstallHooks
885 * Install thread scope message hooks for WH_GETMESSAGE and WH_CALLWNDPROC
887 * RETURNS: TRUE if message hooks were succesfully installed
890 BOOL
OLEMenu_InstallHooks( DWORD tid
)
892 OleMenuHookItem
*pHookItem
= NULL
;
894 /* Create an entry for the hook table */
895 if ( !(pHookItem
= HeapAlloc(GetProcessHeap(), 0,
896 sizeof(OleMenuHookItem
)) ) )
899 pHookItem
->tid
= tid
;
900 pHookItem
->hHeap
= GetProcessHeap();
902 /* Install a thread scope message hook for WH_GETMESSAGE */
903 pHookItem
->GetMsg_hHook
= SetWindowsHookExA( WH_GETMESSAGE
, OLEMenu_GetMsgProc
,
904 0, GetCurrentThreadId() );
905 if ( !pHookItem
->GetMsg_hHook
)
908 /* Install a thread scope message hook for WH_CALLWNDPROC */
909 pHookItem
->CallWndProc_hHook
= SetWindowsHookExA( WH_CALLWNDPROC
, OLEMenu_CallWndProc
,
910 0, GetCurrentThreadId() );
911 if ( !pHookItem
->CallWndProc_hHook
)
914 /* Insert the hook table entry */
915 pHookItem
->next
= hook_list
;
916 hook_list
= pHookItem
;
921 /* Unhook any hooks */
922 if ( pHookItem
->GetMsg_hHook
)
923 UnhookWindowsHookEx( pHookItem
->GetMsg_hHook
);
924 if ( pHookItem
->CallWndProc_hHook
)
925 UnhookWindowsHookEx( pHookItem
->CallWndProc_hHook
);
926 /* Release the hook table entry */
927 HeapFree(pHookItem
->hHeap
, 0, pHookItem
);
932 /*************************************************************************
933 * OLEMenu_UnInstallHooks
934 * UnInstall thread scope message hooks for WH_GETMESSAGE and WH_CALLWNDPROC
936 * RETURNS: TRUE if message hooks were succesfully installed
939 BOOL
OLEMenu_UnInstallHooks( DWORD tid
)
941 OleMenuHookItem
*pHookItem
= NULL
;
942 OleMenuHookItem
**ppHook
= &hook_list
;
946 if ((*ppHook
)->tid
== tid
)
949 *ppHook
= pHookItem
->next
;
952 ppHook
= &(*ppHook
)->next
;
954 if (!pHookItem
) return FALSE
;
956 /* Uninstall the hooks installed for this thread */
957 if ( !UnhookWindowsHookEx( pHookItem
->GetMsg_hHook
) )
959 if ( !UnhookWindowsHookEx( pHookItem
->CallWndProc_hHook
) )
962 /* Release the hook table entry */
963 HeapFree(pHookItem
->hHeap
, 0, pHookItem
);
968 /* Release the hook table entry */
970 HeapFree(pHookItem
->hHeap
, 0, pHookItem
);
975 /*************************************************************************
976 * OLEMenu_IsHookInstalled
977 * Tests if OLEMenu hooks have been installed for a thread
979 * RETURNS: The pointer and index of the hook table entry for the tid
980 * NULL and -1 for the index if no hooks were installed for this thread
982 OleMenuHookItem
* OLEMenu_IsHookInstalled( DWORD tid
)
984 OleMenuHookItem
*pHookItem
= NULL
;
986 /* Do a simple linear search for an entry whose tid matches ours.
987 * We really need a map but efficiency is not a concern here. */
988 for (pHookItem
= hook_list
; pHookItem
; pHookItem
= pHookItem
->next
)
990 if ( tid
== pHookItem
->tid
)
997 /***********************************************************************
998 * OLEMenu_FindMainMenuIndex
1000 * Used by OLEMenu API to find the top level group a menu item belongs to.
1001 * On success pnPos contains the index of the item in the top level menu group
1003 * RETURNS: TRUE if the ID was found, FALSE on failure
1005 static BOOL
OLEMenu_FindMainMenuIndex( HMENU hMainMenu
, HMENU hPopupMenu
, UINT
*pnPos
)
1009 nItems
= GetMenuItemCount( hMainMenu
);
1011 for (i
= 0; i
< nItems
; i
++)
1015 /* Is the current item a submenu? */
1016 if ( (hsubmenu
= GetSubMenu(hMainMenu
, i
)) )
1018 /* If the handle is the same we're done */
1019 if ( hsubmenu
== hPopupMenu
)
1025 /* Recursively search without updating pnPos */
1026 else if ( OLEMenu_FindMainMenuIndex( hsubmenu
, hPopupMenu
, NULL
) )
1038 /***********************************************************************
1039 * OLEMenu_SetIsServerMenu
1041 * Checks whether a popup menu belongs to a shared menu group which is
1042 * owned by the server, and sets the menu descriptor state accordingly.
1043 * All menu messages from these groups should be routed to the server.
1045 * RETURNS: TRUE if the popup menu is part of a server owned group
1046 * FASE if the popup menu is part of a container owned group
1048 BOOL
OLEMenu_SetIsServerMenu( HMENU hmenu
, OleMenuDescriptor
*pOleMenuDescriptor
)
1050 UINT nPos
= 0, nWidth
, i
;
1052 pOleMenuDescriptor
->bIsServerItem
= FALSE
;
1054 /* Don't bother searching if the popup is the combined menu itself */
1055 if ( hmenu
== pOleMenuDescriptor
->hmenuCombined
)
1058 /* Find the menu item index in the shared OLE menu that this item belongs to */
1059 if ( !OLEMenu_FindMainMenuIndex( pOleMenuDescriptor
->hmenuCombined
, hmenu
, &nPos
) )
1062 /* The group widths array has counts for the number of elements
1063 * in the groups File, Edit, Container, Object, Window, Help.
1064 * The Edit, Object & Help groups belong to the server object
1065 * and the other three belong to the container.
1066 * Loop thru the group widths and locate the group we are a member of.
1068 for ( i
= 0, nWidth
= 0; i
< 6; i
++ )
1070 nWidth
+= pOleMenuDescriptor
->mgw
.width
[i
];
1071 if ( nPos
< nWidth
)
1073 /* Odd elements are server menu widths */
1074 pOleMenuDescriptor
->bIsServerItem
= (i
%2) ? TRUE
: FALSE
;
1079 return pOleMenuDescriptor
->bIsServerItem
;
1082 /*************************************************************************
1083 * OLEMenu_CallWndProc
1084 * Thread scope WH_CALLWNDPROC hook proc filter function (callback)
1085 * This is invoked from a message hook installed in OleSetMenuDescriptor.
1087 LRESULT CALLBACK
OLEMenu_CallWndProc(INT code
, WPARAM wParam
, LPARAM lParam
)
1089 LPCWPSTRUCT pMsg
= NULL
;
1090 HOLEMENU hOleMenu
= 0;
1091 OleMenuDescriptor
*pOleMenuDescriptor
= NULL
;
1092 OleMenuHookItem
*pHookItem
= NULL
;
1095 TRACE("%i, %04x, %08x\n", code
, wParam
, (unsigned)lParam
);
1097 /* Check if we're being asked to process the message */
1098 if ( HC_ACTION
!= code
)
1101 /* Retrieve the current message being dispatched from lParam */
1102 pMsg
= (LPCWPSTRUCT
)lParam
;
1104 /* Check if the message is destined for a window we are interested in:
1105 * If the window has an OLEMenu property we may need to dispatch
1106 * the menu message to its active objects window instead. */
1108 hOleMenu
= (HOLEMENU
)GetPropA( pMsg
->hwnd
, "PROP_OLEMenuDescriptor" );
1112 /* Get the menu descriptor */
1113 pOleMenuDescriptor
= (OleMenuDescriptor
*) GlobalLock( hOleMenu
);
1114 if ( !pOleMenuDescriptor
) /* Bad descriptor! */
1117 /* Process menu messages */
1118 switch( pMsg
->message
)
1122 /* Reset the menu descriptor state */
1123 pOleMenuDescriptor
->bIsServerItem
= FALSE
;
1125 /* Send this message to the server as well */
1126 SendMessageA( pOleMenuDescriptor
->hwndActiveObject
,
1127 pMsg
->message
, pMsg
->wParam
, pMsg
->lParam
);
1131 case WM_INITMENUPOPUP
:
1133 /* Save the state for whether this is a server owned menu */
1134 OLEMenu_SetIsServerMenu( (HMENU
)pMsg
->wParam
, pOleMenuDescriptor
);
1140 fuFlags
= HIWORD(pMsg
->wParam
); /* Get flags */
1141 if ( fuFlags
& MF_SYSMENU
)
1144 /* Save the state for whether this is a server owned popup menu */
1145 else if ( fuFlags
& MF_POPUP
)
1146 OLEMenu_SetIsServerMenu( (HMENU
)pMsg
->lParam
, pOleMenuDescriptor
);
1153 LPDRAWITEMSTRUCT lpdis
= (LPDRAWITEMSTRUCT
) pMsg
->lParam
;
1154 if ( pMsg
->wParam
!= 0 || lpdis
->CtlType
!= ODT_MENU
)
1155 goto NEXTHOOK
; /* Not a menu message */
1164 /* If the message was for the server dispatch it accordingly */
1165 if ( pOleMenuDescriptor
->bIsServerItem
)
1167 SendMessageA( pOleMenuDescriptor
->hwndActiveObject
,
1168 pMsg
->message
, pMsg
->wParam
, pMsg
->lParam
);
1172 if ( pOleMenuDescriptor
)
1173 GlobalUnlock( hOleMenu
);
1175 /* Lookup the hook item for the current thread */
1176 if ( !( pHookItem
= OLEMenu_IsHookInstalled( GetCurrentThreadId() ) ) )
1178 /* This should never fail!! */
1179 WARN("could not retrieve hHook for current thread!\n" );
1183 /* Pass on the message to the next hooker */
1184 return CallNextHookEx( pHookItem
->CallWndProc_hHook
, code
, wParam
, lParam
);
1187 /*************************************************************************
1188 * OLEMenu_GetMsgProc
1189 * Thread scope WH_GETMESSAGE hook proc filter function (callback)
1190 * This is invoked from a message hook installed in OleSetMenuDescriptor.
1192 LRESULT CALLBACK
OLEMenu_GetMsgProc(INT code
, WPARAM wParam
, LPARAM lParam
)
1195 HOLEMENU hOleMenu
= 0;
1196 OleMenuDescriptor
*pOleMenuDescriptor
= NULL
;
1197 OleMenuHookItem
*pHookItem
= NULL
;
1200 TRACE("%i, %04x, %08x\n", code
, wParam
, (unsigned)lParam
);
1202 /* Check if we're being asked to process a messages */
1203 if ( HC_ACTION
!= code
)
1206 /* Retrieve the current message being dispatched from lParam */
1207 pMsg
= (LPMSG
)lParam
;
1209 /* Check if the message is destined for a window we are interested in:
1210 * If the window has an OLEMenu property we may need to dispatch
1211 * the menu message to its active objects window instead. */
1213 hOleMenu
= (HOLEMENU
)GetPropA( pMsg
->hwnd
, "PROP_OLEMenuDescriptor" );
1217 /* Process menu messages */
1218 switch( pMsg
->message
)
1222 wCode
= HIWORD(pMsg
->wParam
); /* Get notification code */
1224 goto NEXTHOOK
; /* Not a menu message */
1231 /* Get the menu descriptor */
1232 pOleMenuDescriptor
= (OleMenuDescriptor
*) GlobalLock( hOleMenu
);
1233 if ( !pOleMenuDescriptor
) /* Bad descriptor! */
1236 /* If the message was for the server dispatch it accordingly */
1237 if ( pOleMenuDescriptor
->bIsServerItem
)
1239 /* Change the hWnd in the message to the active objects hWnd.
1240 * The message loop which reads this message will automatically
1241 * dispatch it to the embedded objects window. */
1242 pMsg
->hwnd
= pOleMenuDescriptor
->hwndActiveObject
;
1246 if ( pOleMenuDescriptor
)
1247 GlobalUnlock( hOleMenu
);
1249 /* Lookup the hook item for the current thread */
1250 if ( !( pHookItem
= OLEMenu_IsHookInstalled( GetCurrentThreadId() ) ) )
1252 /* This should never fail!! */
1253 WARN("could not retrieve hHook for current thread!\n" );
1257 /* Pass on the message to the next hooker */
1258 return CallNextHookEx( pHookItem
->GetMsg_hHook
, code
, wParam
, lParam
);
1261 /***********************************************************************
1262 * OleCreateMenuDescriptor [OLE32.97]
1263 * Creates an OLE menu descriptor for OLE to use when dispatching
1264 * menu messages and commands.
1267 * hmenuCombined - Handle to the objects combined menu
1268 * lpMenuWidths - Pointer to array of 6 LONG's indicating menus per group
1271 HOLEMENU WINAPI
OleCreateMenuDescriptor(
1272 HMENU hmenuCombined
,
1273 LPOLEMENUGROUPWIDTHS lpMenuWidths
)
1276 OleMenuDescriptor
*pOleMenuDescriptor
;
1279 if ( !hmenuCombined
|| !lpMenuWidths
)
1282 /* Create an OLE menu descriptor */
1283 if ( !(hOleMenu
= GlobalAlloc(GMEM_MOVEABLE
| GMEM_ZEROINIT
,
1284 sizeof(OleMenuDescriptor
) ) ) )
1287 pOleMenuDescriptor
= (OleMenuDescriptor
*) GlobalLock( hOleMenu
);
1288 if ( !pOleMenuDescriptor
)
1291 /* Initialize menu group widths and hmenu */
1292 for ( i
= 0; i
< 6; i
++ )
1293 pOleMenuDescriptor
->mgw
.width
[i
] = lpMenuWidths
->width
[i
];
1295 pOleMenuDescriptor
->hmenuCombined
= hmenuCombined
;
1296 pOleMenuDescriptor
->bIsServerItem
= FALSE
;
1297 GlobalUnlock( hOleMenu
);
1302 /***********************************************************************
1303 * OleDestroyMenuDescriptor [OLE32.99]
1304 * Destroy the shared menu descriptor
1306 HRESULT WINAPI
OleDestroyMenuDescriptor(
1307 HOLEMENU hmenuDescriptor
)
1309 if ( hmenuDescriptor
)
1310 GlobalFree( hmenuDescriptor
);
1314 /***********************************************************************
1315 * OleSetMenuDescriptor [OLE32.129]
1316 * Installs or removes OLE dispatching code for the containers frame window
1317 * FIXME: The lpFrame and lpActiveObject parameters are currently ignored
1318 * OLE should install context sensitive help F1 filtering for the app when
1319 * these are non null.
1322 * hOleMenu Handle to composite menu descriptor
1323 * hwndFrame Handle to containers frame window
1324 * hwndActiveObject Handle to objects in-place activation window
1325 * lpFrame Pointer to IOleInPlaceFrame on containers window
1326 * lpActiveObject Pointer to IOleInPlaceActiveObject on active in-place object
1329 * S_OK - menu installed correctly
1330 * E_FAIL, E_INVALIDARG, E_UNEXPECTED - failure
1332 HRESULT WINAPI
OleSetMenuDescriptor(
1335 HWND hwndActiveObject
,
1336 LPOLEINPLACEFRAME lpFrame
,
1337 LPOLEINPLACEACTIVEOBJECT lpActiveObject
)
1339 OleMenuDescriptor
*pOleMenuDescriptor
= NULL
;
1342 if ( !hwndFrame
|| (hOleMenu
&& !hwndActiveObject
) )
1343 return E_INVALIDARG
;
1345 if ( lpFrame
|| lpActiveObject
)
1347 FIXME("(%x, %x, %x, %p, %p), Context sensitive help filtering not implemented!\n",
1348 (unsigned int)hOleMenu
,
1355 /* Set up a message hook to intercept the containers frame window messages.
1356 * The message filter is responsible for dispatching menu messages from the
1357 * shared menu which are intended for the object.
1360 if ( hOleMenu
) /* Want to install dispatching code */
1362 /* If OLEMenu hooks are already installed for this thread, fail
1363 * Note: This effectively means that OleSetMenuDescriptor cannot
1364 * be called twice in succession on the same frame window
1365 * without first calling it with a null hOleMenu to uninstall */
1366 if ( OLEMenu_IsHookInstalled( GetCurrentThreadId() ) )
1369 /* Get the menu descriptor */
1370 pOleMenuDescriptor
= (OleMenuDescriptor
*) GlobalLock( hOleMenu
);
1371 if ( !pOleMenuDescriptor
)
1372 return E_UNEXPECTED
;
1374 /* Update the menu descriptor */
1375 pOleMenuDescriptor
->hwndFrame
= hwndFrame
;
1376 pOleMenuDescriptor
->hwndActiveObject
= hwndActiveObject
;
1378 GlobalUnlock( hOleMenu
);
1379 pOleMenuDescriptor
= NULL
;
1381 /* Add a menu descriptor windows property to the frame window */
1382 SetPropA( hwndFrame
, "PROP_OLEMenuDescriptor", hOleMenu
);
1384 /* Install thread scope message hooks for WH_GETMESSAGE and WH_CALLWNDPROC */
1385 if ( !OLEMenu_InstallHooks( GetCurrentThreadId() ) )
1388 else /* Want to uninstall dispatching code */
1390 /* Uninstall the hooks */
1391 if ( !OLEMenu_UnInstallHooks( GetCurrentThreadId() ) )
1394 /* Remove the menu descriptor property from the frame window */
1395 RemovePropA( hwndFrame
, "PROP_OLEMenuDescriptor" );
1401 /******************************************************************************
1402 * IsAccelerator [OLE32.75]
1403 * Mostly copied from controls/menu.c TranslateAccelerator implementation
1405 BOOL WINAPI
IsAccelerator(HACCEL hAccel
, int cAccelEntries
, LPMSG lpMsg
, WORD
* lpwCmd
)
1408 LPACCEL16 lpAccelTbl
;
1411 if(!lpMsg
) return FALSE
;
1412 if (!hAccel
|| !(lpAccelTbl
= (LPACCEL16
)LockResource16(hAccel
)))
1414 WARN_(accel
)("invalid accel handle=%04x\n", hAccel
);
1417 if((lpMsg
->message
!= WM_KEYDOWN
&&
1418 lpMsg
->message
!= WM_KEYUP
&&
1419 lpMsg
->message
!= WM_SYSKEYDOWN
&&
1420 lpMsg
->message
!= WM_SYSKEYUP
&&
1421 lpMsg
->message
!= WM_CHAR
)) return FALSE
;
1423 TRACE_(accel
)("hAccel=%04x, cAccelEntries=%d,"
1424 "msg->hwnd=%04x, msg->message=%04x, wParam=%08x, lParam=%08lx\n",
1425 hAccel
, cAccelEntries
,
1426 lpMsg
->hwnd
, lpMsg
->message
, lpMsg
->wParam
, lpMsg
->lParam
);
1427 for(i
= 0; i
< cAccelEntries
; i
++)
1429 if(lpAccelTbl
[i
].key
!= lpMsg
->wParam
)
1432 if(lpMsg
->message
== WM_CHAR
)
1434 if(!(lpAccelTbl
[i
].fVirt
& FALT
) && !(lpAccelTbl
[i
].fVirt
& FVIRTKEY
))
1436 TRACE_(accel
)("found accel for WM_CHAR: ('%c')\n", lpMsg
->wParam
& 0xff);
1442 if(lpAccelTbl
[i
].fVirt
& FVIRTKEY
)
1445 TRACE_(accel
)("found accel for virt_key %04x (scan %04x)\n",
1446 lpMsg
->wParam
, HIWORD(lpMsg
->lParam
) & 0xff);
1447 if(GetKeyState(VK_SHIFT
) & 0x8000) mask
|= FSHIFT
;
1448 if(GetKeyState(VK_CONTROL
) & 0x8000) mask
|= FCONTROL
;
1449 if(GetKeyState(VK_MENU
) & 0x8000) mask
|= FALT
;
1450 if(mask
== (lpAccelTbl
[i
].fVirt
& (FSHIFT
| FCONTROL
| FALT
))) goto found
;
1451 TRACE_(accel
)("incorrect SHIFT/CTRL/ALT-state\n");
1455 if(!(lpMsg
->lParam
& 0x01000000)) /* no special_key */
1457 if((lpAccelTbl
[i
].fVirt
& FALT
) && (lpMsg
->lParam
& 0x20000000))
1458 { /* ^^ ALT pressed */
1459 TRACE_(accel
)("found accel for Alt-%c\n", lpMsg
->wParam
& 0xff);
1467 WARN_(accel
)("couldn't translate accelerator key\n");
1471 if(lpwCmd
) *lpwCmd
= lpAccelTbl
[i
].cmd
;
1475 /***********************************************************************
1476 * ReleaseStgMedium [OLE32.140]
1478 void WINAPI
ReleaseStgMedium(
1481 switch (pmedium
->tymed
)
1485 if ( (pmedium
->pUnkForRelease
==0) &&
1486 (pmedium
->u
.hGlobal
!=0) )
1487 GlobalFree(pmedium
->u
.hGlobal
);
1489 pmedium
->u
.hGlobal
= 0;
1494 if (pmedium
->u
.lpszFileName
!=0)
1496 if (pmedium
->pUnkForRelease
==0)
1498 DeleteFileW(pmedium
->u
.lpszFileName
);
1501 CoTaskMemFree(pmedium
->u
.lpszFileName
);
1504 pmedium
->u
.lpszFileName
= 0;
1509 if (pmedium
->u
.pstm
!=0)
1511 IStream_Release(pmedium
->u
.pstm
);
1514 pmedium
->u
.pstm
= 0;
1517 case TYMED_ISTORAGE
:
1519 if (pmedium
->u
.pstg
!=0)
1521 IStorage_Release(pmedium
->u
.pstg
);
1524 pmedium
->u
.pstg
= 0;
1529 if ( (pmedium
->pUnkForRelease
==0) &&
1530 (pmedium
->u
.hGlobal
!=0) )
1531 DeleteObject(pmedium
->u
.hGlobal
);
1533 pmedium
->u
.hGlobal
= 0;
1538 if ( (pmedium
->pUnkForRelease
==0) &&
1539 (pmedium
->u
.hMetaFilePict
!=0) )
1541 LPMETAFILEPICT pMP
= GlobalLock(pmedium
->u
.hMetaFilePict
);
1542 DeleteMetaFile(pMP
->hMF
);
1543 GlobalUnlock(pmedium
->u
.hMetaFilePict
);
1544 GlobalFree(pmedium
->u
.hMetaFilePict
);
1547 pmedium
->u
.hMetaFilePict
= 0;
1552 if ( (pmedium
->pUnkForRelease
==0) &&
1553 (pmedium
->u
.hEnhMetaFile
!=0) )
1555 DeleteEnhMetaFile(pmedium
->u
.hEnhMetaFile
);
1558 pmedium
->u
.hEnhMetaFile
= 0;
1567 * After cleaning up, the unknown is released
1569 if (pmedium
->pUnkForRelease
!=0)
1571 IUnknown_Release(pmedium
->pUnkForRelease
);
1572 pmedium
->pUnkForRelease
= 0;
1577 * OLEDD_Initialize()
1579 * Initializes the OLE drag and drop data structures.
1581 static void OLEDD_Initialize()
1585 ZeroMemory (&wndClass
, sizeof(WNDCLASSA
));
1586 wndClass
.style
= CS_GLOBALCLASS
;
1587 wndClass
.lpfnWndProc
= (WNDPROC
)OLEDD_DragTrackerWindowProc
;
1588 wndClass
.cbClsExtra
= 0;
1589 wndClass
.cbWndExtra
= sizeof(TrackerWindowInfo
*);
1590 wndClass
.hCursor
= 0;
1591 wndClass
.hbrBackground
= 0;
1592 wndClass
.lpszClassName
= OLEDD_DRAGTRACKERCLASS
;
1594 RegisterClassA (&wndClass
);
1598 * OLEDD_UnInitialize()
1600 * Releases the OLE drag and drop data structures.
1602 static void OLEDD_UnInitialize()
1605 * Simply empty the list.
1607 while (targetListHead
!=NULL
)
1609 RevokeDragDrop(targetListHead
->hwndTarget
);
1614 * OLEDD_InsertDropTarget()
1616 * Insert the target node in the tree.
1618 static void OLEDD_InsertDropTarget(DropTargetNode
* nodeToAdd
)
1620 DropTargetNode
* curNode
;
1621 DropTargetNode
** parentNodeLink
;
1624 * Iterate the tree to find the insertion point.
1626 curNode
= targetListHead
;
1627 parentNodeLink
= &targetListHead
;
1629 while (curNode
!=NULL
)
1631 if (nodeToAdd
->hwndTarget
<curNode
->hwndTarget
)
1634 * If the node we want to add has a smaller HWND, go left
1636 parentNodeLink
= &curNode
->prevDropTarget
;
1637 curNode
= curNode
->prevDropTarget
;
1639 else if (nodeToAdd
->hwndTarget
>curNode
->hwndTarget
)
1642 * If the node we want to add has a larger HWND, go right
1644 parentNodeLink
= &curNode
->nextDropTarget
;
1645 curNode
= curNode
->nextDropTarget
;
1650 * The item was found in the list. It shouldn't have been there
1658 * If we get here, we have found a spot for our item. The parentNodeLink
1659 * pointer points to the pointer that we have to modify.
1660 * The curNode should be NULL. We just have to establish the link and Voila!
1662 assert(curNode
==NULL
);
1663 assert(parentNodeLink
!=NULL
);
1664 assert(*parentNodeLink
==NULL
);
1666 *parentNodeLink
=nodeToAdd
;
1670 * OLEDD_ExtractDropTarget()
1672 * Removes the target node from the tree.
1674 static DropTargetNode
* OLEDD_ExtractDropTarget(HWND hwndOfTarget
)
1676 DropTargetNode
* curNode
;
1677 DropTargetNode
** parentNodeLink
;
1680 * Iterate the tree to find the insertion point.
1682 curNode
= targetListHead
;
1683 parentNodeLink
= &targetListHead
;
1685 while (curNode
!=NULL
)
1687 if (hwndOfTarget
<curNode
->hwndTarget
)
1690 * If the node we want to add has a smaller HWND, go left
1692 parentNodeLink
= &curNode
->prevDropTarget
;
1693 curNode
= curNode
->prevDropTarget
;
1695 else if (hwndOfTarget
>curNode
->hwndTarget
)
1698 * If the node we want to add has a larger HWND, go right
1700 parentNodeLink
= &curNode
->nextDropTarget
;
1701 curNode
= curNode
->nextDropTarget
;
1706 * The item was found in the list. Detach it from it's parent and
1707 * re-insert it's kids in the tree.
1709 assert(parentNodeLink
!=NULL
);
1710 assert(*parentNodeLink
==curNode
);
1713 * We arbitrately re-attach the left sub-tree to the parent.
1715 *parentNodeLink
= curNode
->prevDropTarget
;
1718 * And we re-insert the right subtree
1720 if (curNode
->nextDropTarget
!=NULL
)
1722 OLEDD_InsertDropTarget(curNode
->nextDropTarget
);
1726 * The node we found is still a valid node once we complete
1727 * the unlinking of the kids.
1729 curNode
->nextDropTarget
=NULL
;
1730 curNode
->prevDropTarget
=NULL
;
1737 * If we get here, the node is not in the tree
1743 * OLEDD_FindDropTarget()
1745 * Finds information about the drop target.
1747 static DropTargetNode
* OLEDD_FindDropTarget(HWND hwndOfTarget
)
1749 DropTargetNode
* curNode
;
1752 * Iterate the tree to find the HWND value.
1754 curNode
= targetListHead
;
1756 while (curNode
!=NULL
)
1758 if (hwndOfTarget
<curNode
->hwndTarget
)
1761 * If the node we want to add has a smaller HWND, go left
1763 curNode
= curNode
->prevDropTarget
;
1765 else if (hwndOfTarget
>curNode
->hwndTarget
)
1768 * If the node we want to add has a larger HWND, go right
1770 curNode
= curNode
->nextDropTarget
;
1775 * The item was found in the list.
1782 * If we get here, the item is not in the list
1788 * OLEDD_DragTrackerWindowProc()
1790 * This method is the WindowProcedure of the drag n drop tracking
1791 * window. During a drag n Drop operation, an invisible window is created
1792 * to receive the user input and act upon it. This procedure is in charge
1795 static LRESULT WINAPI
OLEDD_DragTrackerWindowProc(
1805 LPCREATESTRUCTA createStruct
= (LPCREATESTRUCTA
)lParam
;
1807 SetWindowLongA(hwnd
, 0, (LONG
)createStruct
->lpCreateParams
);
1814 TrackerWindowInfo
* trackerInfo
= (TrackerWindowInfo
*)GetWindowLongA(hwnd
, 0);
1818 * Get the current mouse position in screen coordinates.
1820 mousePos
.x
= LOWORD(lParam
);
1821 mousePos
.y
= HIWORD(lParam
);
1822 ClientToScreen(hwnd
, &mousePos
);
1825 * Track the movement of the mouse.
1827 OLEDD_TrackMouseMove(trackerInfo
, mousePos
, wParam
);
1834 case WM_LBUTTONDOWN
:
1835 case WM_MBUTTONDOWN
:
1836 case WM_RBUTTONDOWN
:
1838 TrackerWindowInfo
* trackerInfo
= (TrackerWindowInfo
*)GetWindowLongA(hwnd
, 0);
1842 * Get the current mouse position in screen coordinates.
1844 mousePos
.x
= LOWORD(lParam
);
1845 mousePos
.y
= HIWORD(lParam
);
1846 ClientToScreen(hwnd
, &mousePos
);
1849 * Notify everyone that the button state changed
1850 * TODO: Check if the "escape" key was pressed.
1852 OLEDD_TrackStateChange(trackerInfo
, mousePos
, wParam
);
1859 * This is a window proc after all. Let's call the default.
1861 return DefWindowProcA (hwnd
, uMsg
, wParam
, lParam
);
1865 * OLEDD_TrackMouseMove()
1867 * This method is invoked while a drag and drop operation is in effect.
1868 * it will generate the appropriate callbacks in the drop source
1869 * and drop target. It will also provide the expected feedback to
1873 * trackerInfo - Pointer to the structure identifying the
1874 * drag & drop operation that is currently
1876 * mousePos - Current position of the mouse in screen
1878 * keyState - Contains the state of the shift keys and the
1879 * mouse buttons (MK_LBUTTON and the like)
1881 static void OLEDD_TrackMouseMove(
1882 TrackerWindowInfo
* trackerInfo
,
1886 HWND hwndNewTarget
= 0;
1890 * Get the handle of the window under the mouse
1892 hwndNewTarget
= WindowFromPoint(mousePos
);
1895 * Every time, we re-initialize the effects passed to the
1896 * IDropTarget to the effects allowed by the source.
1898 *trackerInfo
->pdwEffect
= trackerInfo
->dwOKEffect
;
1901 * If we are hovering over the same target as before, send the
1902 * DragOver notification
1904 if ( (trackerInfo
->curDragTarget
!= 0) &&
1905 (trackerInfo
->curDragTargetHWND
==hwndNewTarget
) )
1907 POINTL mousePosParam
;
1910 * The documentation tells me that the coordinate should be in the target
1911 * window's coordinate space. However, the tests I made tell me the
1912 * coordinates should be in screen coordinates.
1914 mousePosParam
.x
= mousePos
.x
;
1915 mousePosParam
.y
= mousePos
.y
;
1917 IDropTarget_DragOver(trackerInfo
->curDragTarget
,
1920 trackerInfo
->pdwEffect
);
1924 DropTargetNode
* newDropTargetNode
= 0;
1927 * If we changed window, we have to notify our old target and check for
1930 if (trackerInfo
->curDragTarget
!=0)
1932 IDropTarget_DragLeave(trackerInfo
->curDragTarget
);
1936 * Make sure we're hovering over a window.
1938 if (hwndNewTarget
!=0)
1941 * Find-out if there is a drag target under the mouse
1943 HWND nexttar
= hwndNewTarget
;
1945 newDropTargetNode
= OLEDD_FindDropTarget(nexttar
);
1946 } while (!newDropTargetNode
&& (nexttar
= GetParent(nexttar
)) != 0);
1947 if(nexttar
) hwndNewTarget
= nexttar
;
1949 trackerInfo
->curDragTargetHWND
= hwndNewTarget
;
1950 trackerInfo
->curDragTarget
= newDropTargetNode
? newDropTargetNode
->dropTarget
: 0;
1953 * If there is, notify it that we just dragged-in
1955 if (trackerInfo
->curDragTarget
!=0)
1957 POINTL mousePosParam
;
1960 * The documentation tells me that the coordinate should be in the target
1961 * window's coordinate space. However, the tests I made tell me the
1962 * coordinates should be in screen coordinates.
1964 mousePosParam
.x
= mousePos
.x
;
1965 mousePosParam
.y
= mousePos
.y
;
1967 IDropTarget_DragEnter(trackerInfo
->curDragTarget
,
1968 trackerInfo
->dataObject
,
1971 trackerInfo
->pdwEffect
);
1977 * The mouse is not over a window so we don't track anything.
1979 trackerInfo
->curDragTargetHWND
= 0;
1980 trackerInfo
->curDragTarget
= 0;
1985 * Now that we have done that, we have to tell the source to give
1986 * us feedback on the work being done by the target. If we don't
1987 * have a target, simulate no effect.
1989 if (trackerInfo
->curDragTarget
==0)
1991 *trackerInfo
->pdwEffect
= DROPEFFECT_NONE
;
1994 hr
= IDropSource_GiveFeedback(trackerInfo
->dropSource
,
1995 *trackerInfo
->pdwEffect
);
1998 * When we ask for feedback from the drop source, sometimes it will
1999 * do all the necessary work and sometimes it will not handle it
2000 * when that's the case, we must display the standard drag and drop
2003 if (hr
==DRAGDROP_S_USEDEFAULTCURSORS
)
2005 if (*trackerInfo
->pdwEffect
& DROPEFFECT_MOVE
)
2007 SetCursor(LoadCursorA(OLE32_hInstance
, MAKEINTRESOURCEA(1)));
2009 else if (*trackerInfo
->pdwEffect
& DROPEFFECT_COPY
)
2011 SetCursor(LoadCursorA(OLE32_hInstance
, MAKEINTRESOURCEA(2)));
2013 else if (*trackerInfo
->pdwEffect
& DROPEFFECT_LINK
)
2015 SetCursor(LoadCursorA(OLE32_hInstance
, MAKEINTRESOURCEA(3)));
2019 SetCursor(LoadCursorA(OLE32_hInstance
, MAKEINTRESOURCEA(0)));
2025 * OLEDD_TrackStateChange()
2027 * This method is invoked while a drag and drop operation is in effect.
2028 * It is used to notify the drop target/drop source callbacks when
2029 * the state of the keyboard or mouse button change.
2032 * trackerInfo - Pointer to the structure identifying the
2033 * drag & drop operation that is currently
2035 * mousePos - Current position of the mouse in screen
2037 * keyState - Contains the state of the shift keys and the
2038 * mouse buttons (MK_LBUTTON and the like)
2040 static void OLEDD_TrackStateChange(
2041 TrackerWindowInfo
* trackerInfo
,
2046 * Ask the drop source what to do with the operation.
2048 trackerInfo
->returnValue
= IDropSource_QueryContinueDrag(
2049 trackerInfo
->dropSource
,
2050 trackerInfo
->escPressed
,
2054 * All the return valued will stop the operation except the S_OK
2057 if (trackerInfo
->returnValue
!=S_OK
)
2060 * Make sure the message loop in DoDragDrop stops
2062 trackerInfo
->trackingDone
= TRUE
;
2065 * Release the mouse in case the drop target decides to show a popup
2066 * or a menu or something.
2071 * If we end-up over a target, drop the object in the target or
2072 * inform the target that the operation was cancelled.
2074 if (trackerInfo
->curDragTarget
!=0)
2076 switch (trackerInfo
->returnValue
)
2079 * If the source wants us to complete the operation, we tell
2080 * the drop target that we just dropped the object in it.
2082 case DRAGDROP_S_DROP
:
2084 POINTL mousePosParam
;
2087 * The documentation tells me that the coordinate should be
2088 * in the target window's coordinate space. However, the tests
2089 * I made tell me the coordinates should be in screen coordinates.
2091 mousePosParam
.x
= mousePos
.x
;
2092 mousePosParam
.y
= mousePos
.y
;
2094 IDropTarget_Drop(trackerInfo
->curDragTarget
,
2095 trackerInfo
->dataObject
,
2098 trackerInfo
->pdwEffect
);
2102 * If the source told us that we should cancel, fool the drop
2103 * target by telling it that the mouse left it's window.
2104 * Also set the drop effect to "NONE" in case the application
2105 * ignores the result of DoDragDrop.
2107 case DRAGDROP_S_CANCEL
:
2108 IDropTarget_DragLeave(trackerInfo
->curDragTarget
);
2109 *trackerInfo
->pdwEffect
= DROPEFFECT_NONE
;
2117 * OLEDD_GetButtonState()
2119 * This method will use the current state of the keyboard to build
2120 * a button state mask equivalent to the one passed in the
2121 * WM_MOUSEMOVE wParam.
2123 static DWORD
OLEDD_GetButtonState()
2125 BYTE keyboardState
[256];
2128 GetKeyboardState(keyboardState
);
2130 if ( (keyboardState
[VK_SHIFT
] & 0x80) !=0)
2131 keyMask
|= MK_SHIFT
;
2133 if ( (keyboardState
[VK_CONTROL
] & 0x80) !=0)
2134 keyMask
|= MK_CONTROL
;
2136 if ( (keyboardState
[VK_LBUTTON
] & 0x80) !=0)
2137 keyMask
|= MK_LBUTTON
;
2139 if ( (keyboardState
[VK_RBUTTON
] & 0x80) !=0)
2140 keyMask
|= MK_RBUTTON
;
2142 if ( (keyboardState
[VK_MBUTTON
] & 0x80) !=0)
2143 keyMask
|= MK_MBUTTON
;
2149 * OLEDD_GetButtonState()
2151 * This method will read the default value of the registry key in
2152 * parameter and extract a DWORD value from it. The registry key value
2153 * can be in a string key or a DWORD key.
2156 * regKey - Key to read the default value from
2157 * pdwValue - Pointer to the location where the DWORD
2158 * value is returned. This value is not modified
2159 * if the value is not found.
2162 static void OLEUTL_ReadRegistryDWORDValue(
2171 lres
= RegQueryValueExA(regKey
,
2178 if (lres
==ERROR_SUCCESS
)
2183 *pdwValue
= *(DWORD
*)buffer
;
2188 *pdwValue
= (DWORD
)strtoul(buffer
, NULL
, 10);
2194 /******************************************************************************
2195 * OleMetaFilePictFromIconAndLabel
2197 * Returns a global memory handle to a metafile which contains the icon and
2199 * I guess the result of that should look somehow like desktop icons.
2200 * If no hIcon is given, we load the icon via lpszSourceFile and iIconIndex.
2201 * This code might be wrong at some places.
2203 HGLOBAL16 WINAPI
OleMetaFilePictFromIconAndLabel16(
2205 LPCOLESTR16 lpszLabel
,
2206 LPCOLESTR16 lpszSourceFile
,
2213 FIXME("(%04x, '%s', '%s', %d): incorrect metrics, please try to correct them !\n\n\n", hIcon
, lpszLabel
, lpszSourceFile
, iIconIndex
);
2216 if (lpszSourceFile
) {
2217 HINSTANCE16 hInstance
= LoadLibrary16(lpszSourceFile
);
2219 /* load the icon at index from lpszSourceFile */
2220 hIcon
= (HICON16
)LoadIconA(hInstance
, (LPCSTR
)(DWORD
)iIconIndex
);
2221 FreeLibrary16(hInstance
);
2223 return (HGLOBAL
)NULL
;
2226 hdc
= CreateMetaFile16(NULL
);
2227 DrawIcon(hdc
, 0, 0, hIcon
); /* FIXME */
2228 TextOutA(hdc
, 0, 0, lpszLabel
, 1); /* FIXME */
2229 hmf
= GlobalAlloc16(0, sizeof(METAFILEPICT16
));
2230 mf
= (METAFILEPICT16
*)GlobalLock16(hmf
);
2231 mf
->mm
= MM_ANISOTROPIC
;
2232 mf
->xExt
= 20; /* FIXME: bogus */
2233 mf
->yExt
= 20; /* dito */
2234 mf
->hMF
= CloseMetaFile16(hdc
);
2238 /******************************************************************************
2239 * DllDebugObjectRPCHook
2240 * turns on and off internal debugging, pointer is only used on macintosh
2243 BOOL WINAPI
DllDebugObjectRPCHook(BOOL b
, void *dummy
)