4 * Copyright 1995 Martin von Loewis
5 * Copyright 1999 Francis Beaudet
6 * Copyright 1999 Noel Borthwick
18 #include "wine/obj_clientserver.h"
19 #include "wine/wingdi16.h"
20 #include "debugtools.h"
24 DEFAULT_DEBUG_CHANNEL(ole
)
26 /******************************************************************************
27 * These are static/global variables and internal data structures that the
28 * OLE module uses to maintain it's state.
30 typedef struct tagDropTargetNode
33 IDropTarget
* dropTarget
;
34 struct tagDropTargetNode
* prevDropTarget
;
35 struct tagDropTargetNode
* nextDropTarget
;
38 typedef struct tagTrackerWindowInfo
40 IDataObject
* dataObject
;
41 IDropSource
* dropSource
;
48 HWND curDragTargetHWND
;
49 IDropTarget
* curDragTarget
;
52 typedef struct tagOleMenuDescriptor
/* OleMenuDescriptor */
54 HWND hwndFrame
; /* The containers frame window */
55 HWND hwndActiveObject
; /* The active objects window */
56 OLEMENUGROUPWIDTHS mgw
; /* OLE menu group widths for the shared menu */
57 HMENU hmenuCombined
; /* The combined menu */
58 BOOL bIsServerItem
; /* True if the currently open popup belongs to the server */
61 typedef struct tagOleMenuHookItem
/* OleMenu hook item in per thread hook list */
63 DWORD tid
; /* Thread Id */
64 HANDLE hHeap
; /* Heap this is allocated from */
65 HHOOK GetMsg_hHook
; /* message hook for WH_GETMESSAGE */
66 HHOOK CallWndProc_hHook
; /* message hook for WH_CALLWNDPROC */
70 * Dynamic pointer array of per thread message hooks (maintained by OleSetMenuDescriptor)
72 static HDPA OLEMenu_MsgHookDPA
= NULL
;
75 * This is the lock count on the OLE library. It is controlled by the
76 * OLEInitialize/OLEUninitialize methods.
78 static ULONG OLE_moduleLockCount
= 0;
81 * Name of our registered window class.
83 static const char OLEDD_DRAGTRACKERCLASS
[] = "WineDragDropTracker32";
86 * This is the head of the Drop target container.
88 static DropTargetNode
* targetListHead
= NULL
;
90 /******************************************************************************
91 * These are the prototypes of miscelaneous utility methods
93 static void OLEUTL_ReadRegistryDWORDValue(HKEY regKey
, DWORD
* pdwValue
);
95 /******************************************************************************
96 * These are the prototypes of the utility methods used to manage a shared menu
98 static void OLEMenu_Initialize();
99 static void OLEMenu_UnInitialize();
100 BOOL
OLEMenu_InstallHooks( DWORD tid
);
101 BOOL
OLEMenu_UnInstallHooks( DWORD tid
);
102 OleMenuHookItem
* OLEMenu_IsHookInstalled( DWORD tid
, INT
*pixHook
);
103 static BOOL
OLEMenu_FindMainMenuIndex( HMENU hMainMenu
, HMENU hPopupMenu
, UINT
*pnPos
);
104 BOOL
OLEMenu_SetIsServerMenu( HMENU hmenu
, OleMenuDescriptor
*pOleMenuDescriptor
);
105 LRESULT CALLBACK
OLEMenu_CallWndProc(INT code
, WPARAM wParam
, LPARAM lParam
);
106 LRESULT CALLBACK
OLEMenu_GetMsgProc(INT code
, WPARAM wParam
, LPARAM lParam
);
108 /******************************************************************************
109 * These are the prototypes of the OLE Clipboard initialization methods (in clipboard.c)
111 void OLEClipbrd_UnInitialize();
112 void OLEClipbrd_Initialize();
114 /******************************************************************************
115 * These are the prototypes of the utility methods used for OLE Drag n Drop
117 static void OLEDD_Initialize();
118 static void OLEDD_UnInitialize();
119 static void OLEDD_InsertDropTarget(
120 DropTargetNode
* nodeToAdd
);
121 static DropTargetNode
* OLEDD_ExtractDropTarget(
123 static DropTargetNode
* OLEDD_FindDropTarget(
125 static LRESULT WINAPI
OLEDD_DragTrackerWindowProc(
130 static void OLEDD_TrackMouseMove(
131 TrackerWindowInfo
* trackerInfo
,
134 static void OLEDD_TrackStateChange(
135 TrackerWindowInfo
* trackerInfo
,
138 static DWORD
OLEDD_GetButtonState();
141 /******************************************************************************
142 * OleBuildVersion [OLE2.1]
144 DWORD WINAPI
OleBuildVersion(void)
147 return (rmm
<<16)+rup
;
150 /***********************************************************************
151 * OleInitialize (OLE2.2) (OLE32.108)
153 HRESULT WINAPI
OleInitialize(LPVOID reserved
)
157 TRACE("(%p)\n", reserved
);
160 * The first duty of the OleInitialize is to initialize the COM libraries.
162 hr
= CoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
165 * If the CoInitializeEx call failed, the OLE libraries can't be
172 * Then, it has to initialize the OLE specific modules.
176 * Object linking and Embedding
177 * In-place activation
179 if (OLE_moduleLockCount
==0)
182 * Initialize the libraries.
184 TRACE("() - Initializing the OLE libraries\n");
189 OLEClipbrd_Initialize();
199 OLEMenu_Initialize();
203 * Then, we increase the lock count on the OLE module.
205 OLE_moduleLockCount
++;
210 /******************************************************************************
211 * CoGetCurrentProcess [COMPOBJ.34] [OLE2.2][OLE32.108]
214 * Is DWORD really the correct return type for this function?
216 DWORD WINAPI
CoGetCurrentProcess(void) {
217 return (DWORD
)PROCESS_Current();
220 /******************************************************************************
221 * OleUninitialize [OLE2.3] [OLE32.131]
223 void WINAPI
OleUninitialize(void)
228 * Decrease the lock count on the OLE module.
230 OLE_moduleLockCount
--;
233 * If we hit the bottom of the lock stack, free the libraries.
235 if (OLE_moduleLockCount
==0)
238 * Actually free the libraries.
240 TRACE("() - Freeing the last reference count\n");
245 OLEClipbrd_UnInitialize();
250 OLEDD_UnInitialize();
255 OLEMenu_UnInitialize();
259 * Then, uninitialize the COM libraries.
264 /******************************************************************************
265 * CoRegisterMessageFilter32 [OLE32.38]
267 HRESULT WINAPI
CoRegisterMessageFilter(
268 LPMESSAGEFILTER lpMessageFilter
, /* Pointer to interface */
269 LPMESSAGEFILTER
*lplpMessageFilter
/* Indirect pointer to prior instance if non-NULL */
272 if (lplpMessageFilter
) {
273 *lplpMessageFilter
= NULL
;
278 /******************************************************************************
279 * OleInitializeWOW [OLE32.109]
281 HRESULT WINAPI
OleInitializeWOW(DWORD x
) {
282 FIXME("(0x%08lx),stub!\n",x
);
286 /***********************************************************************
287 * RegisterDragDrop16 (OLE2.35)
289 HRESULT WINAPI
RegisterDragDrop16(
291 LPDROPTARGET pDropTarget
293 FIXME("(0x%04x,%p),stub!\n",hwnd
,pDropTarget
);
297 /***********************************************************************
298 * RegisterDragDrop32 (OLE32.139)
300 HRESULT WINAPI
RegisterDragDrop(
302 LPDROPTARGET pDropTarget
)
304 DropTargetNode
* dropTargetInfo
;
306 TRACE("(0x%x,%p)\n", hwnd
, pDropTarget
);
309 * First, check if the window is already registered.
311 dropTargetInfo
= OLEDD_FindDropTarget(hwnd
);
313 if (dropTargetInfo
!=NULL
)
314 return DRAGDROP_E_ALREADYREGISTERED
;
317 * If it's not there, we can add it. We first create a node for it.
319 dropTargetInfo
= HeapAlloc(GetProcessHeap(), 0, sizeof(DropTargetNode
));
321 if (dropTargetInfo
==NULL
)
322 return E_OUTOFMEMORY
;
324 dropTargetInfo
->hwndTarget
= hwnd
;
325 dropTargetInfo
->prevDropTarget
= NULL
;
326 dropTargetInfo
->nextDropTarget
= NULL
;
329 * Don't forget that this is an interface pointer, need to nail it down since
330 * we keep a copy of it.
332 dropTargetInfo
->dropTarget
= pDropTarget
;
333 IDropTarget_AddRef(dropTargetInfo
->dropTarget
);
335 OLEDD_InsertDropTarget(dropTargetInfo
);
340 /***********************************************************************
341 * RevokeDragDrop16 (OLE2.36)
343 HRESULT WINAPI
RevokeDragDrop16(
346 FIXME("(0x%04x),stub!\n",hwnd
);
350 /***********************************************************************
351 * RevokeDragDrop32 (OLE32.141)
353 HRESULT WINAPI
RevokeDragDrop(
356 DropTargetNode
* dropTargetInfo
;
358 TRACE("(0x%x)\n", hwnd
);
361 * First, check if the window is already registered.
363 dropTargetInfo
= OLEDD_ExtractDropTarget(hwnd
);
366 * If it ain't in there, it's an error.
368 if (dropTargetInfo
==NULL
)
369 return DRAGDROP_E_NOTREGISTERED
;
372 * If it's in there, clean-up it's used memory and
375 IDropTarget_Release(dropTargetInfo
->dropTarget
);
376 HeapFree(GetProcessHeap(), 0, dropTargetInfo
);
381 /***********************************************************************
382 * OleRegGetUserType (OLE32.122)
384 * This implementation of OleRegGetUserType ignores the dwFormOfType
385 * parameter and always returns the full name of the object. This is
386 * not too bad since this is the case for many objects because of the
387 * way they are registered.
389 HRESULT WINAPI
OleRegGetUserType(
392 LPOLESTR
* pszUserType
)
402 * Initialize the out parameter.
407 * Build the key name we're looking for
409 WINE_StringFromCLSID((LPCLSID
)clsid
, xclsid
);
411 strcpy(keyName
, "CLSID\\");
412 strcat(keyName
, xclsid
);
413 strcat(keyName
, "\\");
415 TRACE("(%s, %ld, %p)\n", keyName
, dwFormOfType
, pszUserType
);
418 * Open the class id Key
420 hres
= RegOpenKeyA(HKEY_CLASSES_ROOT
,
424 if (hres
!= ERROR_SUCCESS
)
425 return REGDB_E_CLASSNOTREG
;
428 * Retrieve the size of the name string.
432 hres
= RegQueryValueExA(clsidKey
,
439 if (hres
!=ERROR_SUCCESS
)
441 RegCloseKey(clsidKey
);
442 return REGDB_E_READREGDB
;
446 * Allocate a buffer for the registry value.
448 *pszUserType
= CoTaskMemAlloc(cbData
);
450 if (*pszUserType
==NULL
)
452 RegCloseKey(clsidKey
);
453 return E_OUTOFMEMORY
;
456 hres
= RegQueryValueExA(HKEY_CLASSES_ROOT
,
460 (LPBYTE
)*pszUserType
,
463 RegCloseKey(clsidKey
);
465 if (hres
!=ERROR_SUCCESS
)
467 CoTaskMemFree(*pszUserType
);
470 return REGDB_E_READREGDB
;
476 /***********************************************************************
477 * DoDragDrop32 [OLE32.65]
479 HRESULT WINAPI
DoDragDrop (
480 IDataObject
*pDataObject
, /* ptr to the data obj */
481 IDropSource
* pDropSource
, /* ptr to the source obj */
482 DWORD dwOKEffect
, /* effects allowed by the source */
483 DWORD
*pdwEffect
) /* ptr to effects of the source */
485 TrackerWindowInfo trackerInfo
;
486 HWND hwndTrackWindow
;
489 TRACE("(DataObject %p, DropSource %p)\n", pDataObject
, pDropSource
);
492 * Setup the drag n drop tracking window.
494 trackerInfo
.dataObject
= pDataObject
;
495 trackerInfo
.dropSource
= pDropSource
;
496 trackerInfo
.dwOKEffect
= dwOKEffect
;
497 trackerInfo
.pdwEffect
= pdwEffect
;
498 trackerInfo
.trackingDone
= FALSE
;
499 trackerInfo
.escPressed
= FALSE
;
500 trackerInfo
.curDragTargetHWND
= 0;
501 trackerInfo
.curDragTarget
= 0;
503 hwndTrackWindow
= CreateWindowA(OLEDD_DRAGTRACKERCLASS
,
506 CW_USEDEFAULT
, CW_USEDEFAULT
,
507 CW_USEDEFAULT
, CW_USEDEFAULT
,
511 (LPVOID
)&trackerInfo
);
513 if (hwndTrackWindow
!=0)
516 * Capture the mouse input
518 SetCapture(hwndTrackWindow
);
521 * Pump messages. All mouse input should go the the capture window.
523 while (!trackerInfo
.trackingDone
&& GetMessageA(&msg
, 0, 0, 0) )
525 if ( (msg
.message
>= WM_KEYFIRST
) &&
526 (msg
.message
<= WM_KEYFIRST
) )
529 * When keyboard messages are sent to windows on this thread, we
530 * want to ignore notify the drop source that the state changed.
531 * in the case of the Escape key, we also notify the drop source
532 * we give it a special meaning.
534 if ( (msg
.message
==WM_KEYDOWN
) &&
535 (msg
.wParam
==VK_ESCAPE
) )
537 trackerInfo
.escPressed
= TRUE
;
541 * Notify the drop source.
543 OLEDD_TrackStateChange(&trackerInfo
,
545 OLEDD_GetButtonState());
550 * Dispatch the messages only when it's not a keyboard message.
552 DispatchMessageA(&msg
);
557 * Destroy the temporary window.
559 DestroyWindow(hwndTrackWindow
);
561 return trackerInfo
.returnValue
;
567 /***********************************************************************
568 * OleQueryLinkFromData32 [OLE32.118]
570 HRESULT WINAPI
OleQueryLinkFromData(
571 IDataObject
* pSrcDataObject
)
573 FIXME("(%p),stub!\n", pSrcDataObject
);
577 /***********************************************************************
578 * OleRegGetMiscStatus [OLE32.121]
580 HRESULT WINAPI
OleRegGetMiscStatus(
593 * Initialize the out parameter.
598 * Build the key name we're looking for
600 WINE_StringFromCLSID((LPCLSID
)clsid
, xclsid
);
602 strcpy(keyName
, "CLSID\\");
603 strcat(keyName
, xclsid
);
604 strcat(keyName
, "\\");
606 TRACE("(%s, %ld, %p)\n", keyName
, dwAspect
, pdwStatus
);
609 * Open the class id Key
611 result
= RegOpenKeyA(HKEY_CLASSES_ROOT
,
615 if (result
!= ERROR_SUCCESS
)
616 return REGDB_E_CLASSNOTREG
;
621 result
= RegOpenKeyA(clsidKey
,
626 if (result
!= ERROR_SUCCESS
)
628 RegCloseKey(clsidKey
);
629 return REGDB_E_READREGDB
;
633 * Read the default value
635 OLEUTL_ReadRegistryDWORDValue(miscStatusKey
, pdwStatus
);
638 * Open the key specific to the requested aspect.
640 sprintf(keyName
, "%ld", dwAspect
);
642 result
= RegOpenKeyA(miscStatusKey
,
646 if (result
== ERROR_SUCCESS
)
648 OLEUTL_ReadRegistryDWORDValue(aspectKey
, pdwStatus
);
649 RegCloseKey(aspectKey
);
655 RegCloseKey(miscStatusKey
);
656 RegCloseKey(clsidKey
);
661 /******************************************************************************
662 * OleSetContainedObject [OLE32.128]
664 HRESULT WINAPI
OleSetContainedObject(
668 IRunnableObject
* runnable
= NULL
;
671 TRACE("(%p,%x), stub!\n", pUnknown
, fContained
);
673 hres
= IUnknown_QueryInterface(pUnknown
,
674 &IID_IRunnableObject
,
679 hres
= IRunnableObject_SetContainedObject(runnable
, fContained
);
681 IRunnableObject_Release(runnable
);
689 /******************************************************************************
690 * OleLoad [OLE32.112]
692 HRESULT WINAPI
OleLoad(
695 LPOLECLIENTSITE pClientSite
,
698 IPersistStorage
* persistStorage
= NULL
;
699 IOleObject
* oleObject
= NULL
;
703 TRACE("(%p,%p,%p,%p)\n", pStg
, riid
, pClientSite
, ppvObj
);
706 * TODO, Conversion ... OleDoAutoConvert
710 * Get the class ID for the object.
712 hres
= IStorage_Stat(pStg
, &storageInfo
, STATFLAG_NONAME
);
715 * Now, try and create the handler for the object
717 hres
= CoCreateInstance(&storageInfo
.clsid
,
719 CLSCTX_INPROC_HANDLER
,
724 * If that fails, as it will most times, load the default
729 hres
= OleCreateDefaultHandler(&storageInfo
.clsid
,
736 * If we couldn't find a handler... this is bad. Abort the whole thing.
742 * Inform the new object of it's client site.
744 hres
= IOleObject_SetClientSite(oleObject
, pClientSite
);
747 * Initialize the object with it's IPersistStorage interface.
749 hres
= IOleObject_QueryInterface(oleObject
,
750 &IID_IPersistStorage
,
751 (void**)&persistStorage
);
755 IPersistStorage_Load(persistStorage
, pStg
);
757 IPersistStorage_Release(persistStorage
);
758 persistStorage
= NULL
;
762 * Return the requested interface to the caller.
764 hres
= IOleObject_QueryInterface(oleObject
, riid
, ppvObj
);
767 * Cleanup interfaces used internally
769 IOleObject_Release(oleObject
);
774 /***********************************************************************
775 * OleSave [OLE32.124]
777 HRESULT WINAPI
OleSave(
778 LPPERSISTSTORAGE pPS
,
785 TRACE("(%p,%p,%x)\n", pPS
, pStg
, fSameAsLoad
);
788 * First, we transfer the class ID (if available)
790 hres
= IPersistStorage_GetClassID(pPS
, &objectClass
);
794 WriteClassStg(pStg
, &objectClass
);
798 * Then, we ask the object to save itself to the
799 * storage. If it is successful, we commit the storage.
801 hres
= IPersistStorage_Save(pPS
, pStg
, fSameAsLoad
);
805 IStorage_Commit(pStg
,
813 /**************************************************************************
814 * Internal methods to manage the shared OLE menu in response to the
815 * OLE***MenuDescriptor API
819 * OLEMenu_Initialize()
821 * Initializes the OLEMENU data structures.
823 static void OLEMenu_Initialize()
825 /* Create a dynamic pointer array to store the hook handles */
826 if ( !OLEMenu_MsgHookDPA
)
827 OLEMenu_MsgHookDPA
= DPA_CreateEx( 2, GetProcessHeap() );
831 * OLEMenu_UnInitialize()
833 * Releases the OLEMENU data structures.
835 static void OLEMenu_UnInitialize()
837 /* Release the hook table */
838 if ( OLEMenu_MsgHookDPA
)
839 DPA_Destroy( OLEMenu_MsgHookDPA
);
841 OLEMenu_MsgHookDPA
= NULL
;
844 /*************************************************************************
845 * OLEMenu_InstallHooks
846 * Install thread scope message hooks for WH_GETMESSAGE and WH_CALLWNDPROC
848 * RETURNS: TRUE if message hooks were succesfully installed
851 BOOL
OLEMenu_InstallHooks( DWORD tid
)
853 OleMenuHookItem
*pHookItem
= NULL
;
855 if ( !OLEMenu_MsgHookDPA
) /* No hook table? Create one */
857 /* Create a dynamic pointer array to store the hook handles */
858 if ( !(OLEMenu_MsgHookDPA
= DPA_CreateEx( 2, GetProcessHeap() )) )
862 /* Create an entry for the hook table */
863 if ( !(pHookItem
= HeapAlloc(GetProcessHeap(), 0,
864 sizeof(OleMenuHookItem
)) ) )
867 pHookItem
->tid
= tid
;
868 pHookItem
->hHeap
= GetProcessHeap();
870 /* Install a thread scope message hook for WH_GETMESSAGE */
871 pHookItem
->GetMsg_hHook
= SetWindowsHookExA( WH_GETMESSAGE
, OLEMenu_GetMsgProc
,
872 0, GetCurrentThreadId() );
873 if ( !pHookItem
->GetMsg_hHook
)
876 /* Install a thread scope message hook for WH_CALLWNDPROC */
877 pHookItem
->CallWndProc_hHook
= SetWindowsHookExA( WH_CALLWNDPROC
, OLEMenu_CallWndProc
,
878 0, GetCurrentThreadId() );
879 if ( !pHookItem
->CallWndProc_hHook
)
882 /* Insert the hook table entry */
883 if ( -1 == DPA_InsertPtr( OLEMenu_MsgHookDPA
, 0, pHookItem
) )
889 /* Unhook any hooks */
890 if ( pHookItem
->GetMsg_hHook
)
891 UnhookWindowsHookEx( pHookItem
->GetMsg_hHook
);
892 if ( pHookItem
->CallWndProc_hHook
)
893 UnhookWindowsHookEx( pHookItem
->CallWndProc_hHook
);
894 /* Release the hook table entry */
895 HeapFree(pHookItem
->hHeap
, 0, pHookItem
);
900 /*************************************************************************
901 * OLEMenu_UnInstallHooks
902 * UnInstall thread scope message hooks for WH_GETMESSAGE and WH_CALLWNDPROC
904 * RETURNS: TRUE if message hooks were succesfully installed
907 BOOL
OLEMenu_UnInstallHooks( DWORD tid
)
910 OleMenuHookItem
*pHookItem
= NULL
;
912 if ( !OLEMenu_MsgHookDPA
) /* No hooks set */
915 /* Lookup the hHook index for this tid */
916 if ( !OLEMenu_IsHookInstalled( tid
, &ixHook
) )
919 /* Remove the hook entry from the table(the pointer itself is not deleted) */
920 if ( !( pHookItem
= DPA_DeletePtr(OLEMenu_MsgHookDPA
, ixHook
) ) )
923 /* Uninstall the hooks installed for this thread */
924 if ( !UnhookWindowsHookEx( pHookItem
->GetMsg_hHook
) )
926 if ( !UnhookWindowsHookEx( pHookItem
->CallWndProc_hHook
) )
929 /* Release the hook table entry */
930 HeapFree(pHookItem
->hHeap
, 0, pHookItem
);
935 /* Release the hook table entry */
937 HeapFree(pHookItem
->hHeap
, 0, pHookItem
);
942 /*************************************************************************
943 * OLEMenu_IsHookInstalled
944 * Tests if OLEMenu hooks have been installed for a thread
946 * RETURNS: The pointer and index of the hook table entry for the tid
947 * NULL and -1 for the index if no hooks were installed for this thread
949 OleMenuHookItem
* OLEMenu_IsHookInstalled( DWORD tid
, INT
*pixHook
)
952 OleMenuHookItem
*pHookItem
= NULL
;
957 if ( !OLEMenu_MsgHookDPA
) /* No hooks set */
960 /* Do a simple linear search for an entry whose tid matches ours.
961 * We really need a map but efficiency is not a concern here. */
962 for( ixHook
= 0; ; ixHook
++ )
964 /* Retrieve the hook entry */
965 if ( !( pHookItem
= DPA_GetPtr(OLEMenu_MsgHookDPA
, ixHook
) ) )
968 if ( tid
== pHookItem
->tid
)
979 /***********************************************************************
980 * OLEMenu_FindMainMenuIndex
982 * Used by OLEMenu API to find the top level group a menu item belongs to.
983 * On success pnPos contains the index of the item in the top level menu group
985 * RETURNS: TRUE if the ID was found, FALSE on failure
987 static BOOL
OLEMenu_FindMainMenuIndex( HMENU hMainMenu
, HMENU hPopupMenu
, UINT
*pnPos
)
991 nItems
= GetMenuItemCount( hMainMenu
);
993 for (i
= 0; i
< nItems
; i
++)
997 /* Is the current item a submenu? */
998 if ( (hsubmenu
= GetSubMenu(hMainMenu
, i
)) )
1000 /* If the handle is the same we're done */
1001 if ( hsubmenu
== hPopupMenu
)
1007 /* Recursively search without updating pnPos */
1008 else if ( OLEMenu_FindMainMenuIndex( hsubmenu
, hPopupMenu
, NULL
) )
1020 /***********************************************************************
1021 * OLEMenu_SetIsServerMenu
1023 * Checks whether a popup menu belongs to a shared menu group which is
1024 * owned by the server, and sets the menu descriptor state accordingly.
1025 * All menu messages from these groups should be routed to the server.
1027 * RETURNS: TRUE if the popup menu is part of a server owned group
1028 * FASE if the popup menu is part of a container owned group
1030 BOOL
OLEMenu_SetIsServerMenu( HMENU hmenu
, OleMenuDescriptor
*pOleMenuDescriptor
)
1032 UINT nPos
= 0, nWidth
, i
;
1034 pOleMenuDescriptor
->bIsServerItem
= FALSE
;
1036 /* Don't bother searching if the popup is the combined menu itself */
1037 if ( hmenu
== pOleMenuDescriptor
->hmenuCombined
)
1040 /* Find the menu item index in the shared OLE menu that this item belongs to */
1041 if ( !OLEMenu_FindMainMenuIndex( pOleMenuDescriptor
->hmenuCombined
, hmenu
, &nPos
) )
1044 /* The group widths array has counts for the number of elements
1045 * in the groups File, Edit, Container, Object, Window, Help.
1046 * The Edit, Object & Help groups belong to the server object
1047 * and the other three belong to the container.
1048 * Loop thru the group widths and locate the group we are a member of.
1050 for ( i
= 0, nWidth
= 0; i
< 6; i
++ )
1052 nWidth
+= pOleMenuDescriptor
->mgw
.width
[i
];
1053 if ( nPos
< nWidth
)
1055 /* Odd elements are server menu widths */
1056 pOleMenuDescriptor
->bIsServerItem
= (i
%2) ? TRUE
: FALSE
;
1061 return pOleMenuDescriptor
->bIsServerItem
;
1064 /*************************************************************************
1065 * OLEMenu_CallWndProc
1066 * Thread scope WH_CALLWNDPROC hook proc filter function (callback)
1067 * This is invoked from a message hook installed in OleSetMenuDescriptor.
1069 LRESULT CALLBACK
OLEMenu_CallWndProc(INT code
, WPARAM wParam
, LPARAM lParam
)
1071 LPCWPSTRUCT pMsg
= NULL
;
1072 HOLEMENU hOleMenu
= 0;
1073 OleMenuDescriptor
*pOleMenuDescriptor
= NULL
;
1074 OleMenuHookItem
*pHookItem
= NULL
;
1077 TRACE("%i, %04x, %08x\n", code
, wParam
, (unsigned)lParam
);
1079 /* Check if we're being asked to process the message */
1080 if ( HC_ACTION
!= code
)
1083 /* Retrieve the current message being dispatched from lParam */
1084 pMsg
= (LPCWPSTRUCT
)lParam
;
1086 /* Check if the message is destined for a window we are interested in:
1087 * If the window has an OLEMenu property we may need to dispatch
1088 * the menu message to its active objects window instead. */
1090 hOleMenu
= (HOLEMENU
)GetPropA( pMsg
->hwnd
, "PROP_OLEMenuDescriptor" );
1094 /* Get the menu descriptor */
1095 pOleMenuDescriptor
= (OleMenuDescriptor
*) GlobalLock( hOleMenu
);
1096 if ( !pOleMenuDescriptor
) /* Bad descriptor! */
1099 /* Process menu messages */
1100 switch( pMsg
->message
)
1104 /* Reset the menu descriptor state */
1105 pOleMenuDescriptor
->bIsServerItem
= FALSE
;
1107 /* Send this message to the server as well */
1108 SendMessageA( pOleMenuDescriptor
->hwndActiveObject
,
1109 pMsg
->message
, pMsg
->wParam
, pMsg
->lParam
);
1113 case WM_INITMENUPOPUP
:
1115 /* Save the state for whether this is a server owned menu */
1116 OLEMenu_SetIsServerMenu( (HMENU
)pMsg
->wParam
, pOleMenuDescriptor
);
1122 fuFlags
= HIWORD(pMsg
->wParam
); /* Get flags */
1123 if ( fuFlags
& MF_SYSMENU
)
1126 /* Save the state for whether this is a server owned popup menu */
1127 else if ( fuFlags
& MF_POPUP
)
1128 OLEMenu_SetIsServerMenu( (HMENU
)pMsg
->lParam
, pOleMenuDescriptor
);
1135 LPDRAWITEMSTRUCT lpdis
= (LPDRAWITEMSTRUCT
) pMsg
->lParam
;
1136 if ( pMsg
->wParam
!= 0 || lpdis
->CtlType
!= ODT_MENU
)
1137 goto NEXTHOOK
; /* Not a menu message */
1146 /* If the message was for the server dispatch it accordingly */
1147 if ( pOleMenuDescriptor
->bIsServerItem
)
1149 SendMessageA( pOleMenuDescriptor
->hwndActiveObject
,
1150 pMsg
->message
, pMsg
->wParam
, pMsg
->lParam
);
1154 if ( pOleMenuDescriptor
)
1155 GlobalUnlock( hOleMenu
);
1157 /* Lookup the hook item for the current thread */
1158 if ( !( pHookItem
= OLEMenu_IsHookInstalled( GetCurrentThreadId(), NULL
) ) )
1160 /* This should never fail!! */
1161 WARN("could not retrieve hHook for current thread!\n" );
1165 /* Pass on the message to the next hooker */
1166 return CallNextHookEx( pHookItem
->CallWndProc_hHook
, code
, wParam
, lParam
);
1169 /*************************************************************************
1170 * OLEMenu_GetMsgProc
1171 * Thread scope WH_GETMESSAGE hook proc filter function (callback)
1172 * This is invoked from a message hook installed in OleSetMenuDescriptor.
1174 LRESULT CALLBACK
OLEMenu_GetMsgProc(INT code
, WPARAM wParam
, LPARAM lParam
)
1177 HOLEMENU hOleMenu
= 0;
1178 OleMenuDescriptor
*pOleMenuDescriptor
= NULL
;
1179 OleMenuHookItem
*pHookItem
= NULL
;
1182 TRACE("%i, %04x, %08x\n", code
, wParam
, (unsigned)lParam
);
1184 /* Check if we're being asked to process a messages */
1185 if ( HC_ACTION
!= code
)
1188 /* Retrieve the current message being dispatched from lParam */
1189 pMsg
= (LPMSG
)lParam
;
1191 /* Check if the message is destined for a window we are interested in:
1192 * If the window has an OLEMenu property we may need to dispatch
1193 * the menu message to its active objects window instead. */
1195 hOleMenu
= (HOLEMENU
)GetPropA( pMsg
->hwnd
, "PROP_OLEMenuDescriptor" );
1199 /* Process menu messages */
1200 switch( pMsg
->message
)
1204 wCode
= HIWORD(pMsg
->wParam
); /* Get notification code */
1206 goto NEXTHOOK
; /* Not a menu message */
1213 /* Get the menu descriptor */
1214 pOleMenuDescriptor
= (OleMenuDescriptor
*) GlobalLock( hOleMenu
);
1215 if ( !pOleMenuDescriptor
) /* Bad descriptor! */
1218 /* If the message was for the server dispatch it accordingly */
1219 if ( pOleMenuDescriptor
->bIsServerItem
)
1221 /* Change the hWnd in the message to the active objects hWnd.
1222 * The message loop which reads this message will automatically
1223 * dispatch it to the embedded objects window. */
1224 pMsg
->hwnd
= pOleMenuDescriptor
->hwndActiveObject
;
1228 if ( pOleMenuDescriptor
)
1229 GlobalUnlock( hOleMenu
);
1231 /* Lookup the hook item for the current thread */
1232 if ( !( pHookItem
= OLEMenu_IsHookInstalled( GetCurrentThreadId(), NULL
) ) )
1234 /* This should never fail!! */
1235 WARN("could not retrieve hHook for current thread!\n" );
1239 /* Pass on the message to the next hooker */
1240 return CallNextHookEx( pHookItem
->GetMsg_hHook
, code
, wParam
, lParam
);
1243 /***********************************************************************
1244 * OleCreateMenuDescriptor [OLE32.97]
1245 * Creates an OLE menu descriptor for OLE to use when dispatching
1246 * menu messages and commands.
1249 * hmenuCombined - Handle to the objects combined menu
1250 * lpMenuWidths - Pointer to array of 6 LONG's indicating menus per group
1253 HOLEMENU WINAPI
OleCreateMenuDescriptor(
1254 HMENU hmenuCombined
,
1255 LPOLEMENUGROUPWIDTHS lpMenuWidths
)
1258 OleMenuDescriptor
*pOleMenuDescriptor
;
1261 if ( !hmenuCombined
|| !lpMenuWidths
)
1264 /* Create an OLE menu descriptor */
1265 if ( !(hOleMenu
= GlobalAlloc(GMEM_MOVEABLE
| GMEM_ZEROINIT
,
1266 sizeof(OleMenuDescriptor
) ) ) )
1269 pOleMenuDescriptor
= (OleMenuDescriptor
*) GlobalLock( hOleMenu
);
1270 if ( !pOleMenuDescriptor
)
1273 /* Initialize menu group widths and hmenu */
1274 for ( i
= 0; i
< 6; i
++ )
1275 pOleMenuDescriptor
->mgw
.width
[i
] = lpMenuWidths
->width
[i
];
1277 pOleMenuDescriptor
->hmenuCombined
= hmenuCombined
;
1278 pOleMenuDescriptor
->bIsServerItem
= FALSE
;
1279 GlobalUnlock( hOleMenu
);
1284 /***********************************************************************
1285 * OleDestroyMenuDescriptor [OLE32.99]
1286 * Destroy the shared menu descriptor
1288 HRESULT WINAPI
OleDestroyMenuDescriptor(
1289 HOLEMENU hmenuDescriptor
)
1291 if ( hmenuDescriptor
)
1292 GlobalFree( hmenuDescriptor
);
1296 /***********************************************************************
1297 * OleSetMenuDescriptor [OLE32.129]
1298 * Installs or removes OLE dispatching code for the containers frame window
1299 * FIXME: The lpFrame and lpActiveObject parameters are currently ignored
1300 * OLE should install context sensitive help F1 filtering for the app when
1301 * these are non null.
1304 * hOleMenu Handle to composite menu descriptor
1305 * hwndFrame Handle to containers frame window
1306 * hwndActiveObject Handle to objects in-place activation window
1307 * lpFrame Pointer to IOleInPlaceFrame on containers window
1308 * lpActiveObject Pointer to IOleInPlaceActiveObject on active in-place object
1311 * S_OK - menu installed correctly
1312 * E_FAIL, E_INVALIDARG, E_UNEXPECTED - failure
1314 HRESULT WINAPI
OleSetMenuDescriptor(
1317 HWND hwndActiveObject
,
1318 LPOLEINPLACEFRAME lpFrame
,
1319 LPOLEINPLACEACTIVEOBJECT lpActiveObject
)
1321 OleMenuDescriptor
*pOleMenuDescriptor
= NULL
;
1324 if ( !hwndFrame
|| (hOleMenu
&& !hwndActiveObject
) )
1325 return E_INVALIDARG
;
1327 if ( lpFrame
|| lpActiveObject
)
1329 FIXME("(%x, %x, %x, %p, %p), Context sensitive help filtering not implemented!\n",
1330 (unsigned int)hOleMenu
,
1337 /* Set up a message hook to intercept the containers frame window messages.
1338 * The message filter is responsible for dispatching menu messages from the
1339 * shared menu which are intended for the object.
1342 if ( hOleMenu
) /* Want to install dispatching code */
1344 /* If OLEMenu hooks are already installed for this thread, fail
1345 * Note: This effectively means that OleSetMenuDescriptor cannot
1346 * be called twice in succession on the same frame window
1347 * without first calling it with a null hOleMenu to uninstall */
1348 if ( OLEMenu_IsHookInstalled( GetCurrentThreadId(), NULL
) )
1351 /* Get the menu descriptor */
1352 pOleMenuDescriptor
= (OleMenuDescriptor
*) GlobalLock( hOleMenu
);
1353 if ( !pOleMenuDescriptor
)
1354 return E_UNEXPECTED
;
1356 /* Update the menu descriptor */
1357 pOleMenuDescriptor
->hwndFrame
= hwndFrame
;
1358 pOleMenuDescriptor
->hwndActiveObject
= hwndActiveObject
;
1360 GlobalUnlock( hOleMenu
);
1361 pOleMenuDescriptor
= NULL
;
1363 /* Add a menu descriptor windows property to the frame window */
1364 SetPropA( hwndFrame
, "PROP_OLEMenuDescriptor", hOleMenu
);
1366 /* Install thread scope message hooks for WH_GETMESSAGE and WH_CALLWNDPROC */
1367 if ( !OLEMenu_InstallHooks( GetCurrentThreadId() ) )
1370 else /* Want to uninstall dispatching code */
1372 /* Uninstall the hooks */
1373 if ( !OLEMenu_UnInstallHooks( GetCurrentThreadId() ) )
1376 /* Remove the menu descriptor property from the frame window */
1377 RemovePropA( hwndFrame
, "PROP_OLEMenuDescriptor" );
1383 /***********************************************************************
1384 * ReleaseStgMedium [OLE32.140]
1386 void WINAPI
ReleaseStgMedium(
1389 switch (pmedium
->tymed
)
1393 if ( (pmedium
->pUnkForRelease
==0) &&
1394 (pmedium
->u
.hGlobal
!=0) )
1395 GlobalFree(pmedium
->u
.hGlobal
);
1397 pmedium
->u
.hGlobal
= 0;
1402 if (pmedium
->u
.lpszFileName
!=0)
1404 if (pmedium
->pUnkForRelease
==0)
1406 DeleteFileW(pmedium
->u
.lpszFileName
);
1409 CoTaskMemFree(pmedium
->u
.lpszFileName
);
1412 pmedium
->u
.lpszFileName
= 0;
1417 if (pmedium
->u
.pstm
!=0)
1419 IStream_Release(pmedium
->u
.pstm
);
1422 pmedium
->u
.pstm
= 0;
1425 case TYMED_ISTORAGE
:
1427 if (pmedium
->u
.pstg
!=0)
1429 IStorage_Release(pmedium
->u
.pstg
);
1432 pmedium
->u
.pstg
= 0;
1437 if ( (pmedium
->pUnkForRelease
==0) &&
1438 (pmedium
->u
.hGlobal
!=0) )
1439 DeleteObject(pmedium
->u
.hGlobal
);
1441 pmedium
->u
.hGlobal
= 0;
1446 if ( (pmedium
->pUnkForRelease
==0) &&
1447 (pmedium
->u
.hMetaFilePict
!=0) )
1449 DeleteMetaFile(pmedium
->u
.hMetaFilePict
);
1450 GlobalFree(pmedium
->u
.hMetaFilePict
);
1453 pmedium
->u
.hMetaFilePict
= 0;
1458 if ( (pmedium
->pUnkForRelease
==0) &&
1459 (pmedium
->u
.hEnhMetaFile
!=0) )
1461 DeleteEnhMetaFile(pmedium
->u
.hEnhMetaFile
);
1464 pmedium
->u
.hEnhMetaFile
= 0;
1473 * After cleaning up, the unknown is released
1475 if (pmedium
->pUnkForRelease
!=0)
1477 IUnknown_Release(pmedium
->pUnkForRelease
);
1478 pmedium
->pUnkForRelease
= 0;
1483 * OLEDD_Initialize()
1485 * Initializes the OLE drag and drop data structures.
1487 static void OLEDD_Initialize()
1491 ZeroMemory (&wndClass
, sizeof(WNDCLASSA
));
1492 wndClass
.style
= CS_GLOBALCLASS
;
1493 wndClass
.lpfnWndProc
= (WNDPROC
)OLEDD_DragTrackerWindowProc
;
1494 wndClass
.cbClsExtra
= 0;
1495 wndClass
.cbWndExtra
= sizeof(TrackerWindowInfo
*);
1496 wndClass
.hCursor
= 0;
1497 wndClass
.hbrBackground
= 0;
1498 wndClass
.lpszClassName
= OLEDD_DRAGTRACKERCLASS
;
1500 RegisterClassA (&wndClass
);
1504 * OLEDD_UnInitialize()
1506 * Releases the OLE drag and drop data structures.
1508 static void OLEDD_UnInitialize()
1511 * Simply empty the list.
1513 while (targetListHead
!=NULL
)
1515 RevokeDragDrop(targetListHead
->hwndTarget
);
1520 * OLEDD_InsertDropTarget()
1522 * Insert the target node in the tree.
1524 static void OLEDD_InsertDropTarget(DropTargetNode
* nodeToAdd
)
1526 DropTargetNode
* curNode
;
1527 DropTargetNode
** parentNodeLink
;
1530 * Iterate the tree to find the insertion point.
1532 curNode
= targetListHead
;
1533 parentNodeLink
= &targetListHead
;
1535 while (curNode
!=NULL
)
1537 if (nodeToAdd
->hwndTarget
<curNode
->hwndTarget
)
1540 * If the node we want to add has a smaller HWND, go left
1542 parentNodeLink
= &curNode
->prevDropTarget
;
1543 curNode
= curNode
->prevDropTarget
;
1545 else if (nodeToAdd
->hwndTarget
>curNode
->hwndTarget
)
1548 * If the node we want to add has a larger HWND, go right
1550 parentNodeLink
= &curNode
->nextDropTarget
;
1551 curNode
= curNode
->nextDropTarget
;
1556 * The item was found in the list. It shouldn't have been there
1564 * If we get here, we have found a spot for our item. The parentNodeLink
1565 * pointer points to the pointer that we have to modify.
1566 * The curNode should be NULL. We just have to establish the link and Voila!
1568 assert(curNode
==NULL
);
1569 assert(parentNodeLink
!=NULL
);
1570 assert(*parentNodeLink
==NULL
);
1572 *parentNodeLink
=nodeToAdd
;
1576 * OLEDD_ExtractDropTarget()
1578 * Removes the target node from the tree.
1580 static DropTargetNode
* OLEDD_ExtractDropTarget(HWND hwndOfTarget
)
1582 DropTargetNode
* curNode
;
1583 DropTargetNode
** parentNodeLink
;
1586 * Iterate the tree to find the insertion point.
1588 curNode
= targetListHead
;
1589 parentNodeLink
= &targetListHead
;
1591 while (curNode
!=NULL
)
1593 if (hwndOfTarget
<curNode
->hwndTarget
)
1596 * If the node we want to add has a smaller HWND, go left
1598 parentNodeLink
= &curNode
->prevDropTarget
;
1599 curNode
= curNode
->prevDropTarget
;
1601 else if (hwndOfTarget
>curNode
->hwndTarget
)
1604 * If the node we want to add has a larger HWND, go right
1606 parentNodeLink
= &curNode
->nextDropTarget
;
1607 curNode
= curNode
->nextDropTarget
;
1612 * The item was found in the list. Detach it from it's parent and
1613 * re-insert it's kids in the tree.
1615 assert(parentNodeLink
!=NULL
);
1616 assert(*parentNodeLink
==curNode
);
1619 * We arbitrately re-attach the left sub-tree to the parent.
1621 *parentNodeLink
= curNode
->prevDropTarget
;
1624 * And we re-insert the right subtree
1626 if (curNode
->nextDropTarget
!=NULL
)
1628 OLEDD_InsertDropTarget(curNode
->nextDropTarget
);
1632 * The node we found is still a valid node once we complete
1633 * the unlinking of the kids.
1635 curNode
->nextDropTarget
=NULL
;
1636 curNode
->prevDropTarget
=NULL
;
1643 * If we get here, the node is not in the tree
1649 * OLEDD_FindDropTarget()
1651 * Finds information about the drop target.
1653 static DropTargetNode
* OLEDD_FindDropTarget(HWND hwndOfTarget
)
1655 DropTargetNode
* curNode
;
1658 * Iterate the tree to find the HWND value.
1660 curNode
= targetListHead
;
1662 while (curNode
!=NULL
)
1664 if (hwndOfTarget
<curNode
->hwndTarget
)
1667 * If the node we want to add has a smaller HWND, go left
1669 curNode
= curNode
->prevDropTarget
;
1671 else if (hwndOfTarget
>curNode
->hwndTarget
)
1674 * If the node we want to add has a larger HWND, go right
1676 curNode
= curNode
->nextDropTarget
;
1681 * The item was found in the list.
1688 * If we get here, the item is not in the list
1694 * OLEDD_DragTrackerWindowProc()
1696 * This method is the WindowProcedure of the drag n drop tracking
1697 * window. During a drag n Drop operation, an invisible window is created
1698 * to receive the user input and act upon it. This procedure is in charge
1701 static LRESULT WINAPI
OLEDD_DragTrackerWindowProc(
1711 LPCREATESTRUCTA createStruct
= (LPCREATESTRUCTA
)lParam
;
1713 SetWindowLongA(hwnd
, 0, (LONG
)createStruct
->lpCreateParams
);
1720 TrackerWindowInfo
* trackerInfo
= (TrackerWindowInfo
*)GetWindowLongA(hwnd
, 0);
1724 * Get the current mouse position in screen coordinates.
1726 mousePos
.x
= LOWORD(lParam
);
1727 mousePos
.y
= HIWORD(lParam
);
1728 ClientToScreen(hwnd
, &mousePos
);
1731 * Track the movement of the mouse.
1733 OLEDD_TrackMouseMove(trackerInfo
, mousePos
, wParam
);
1740 case WM_LBUTTONDOWN
:
1741 case WM_MBUTTONDOWN
:
1742 case WM_RBUTTONDOWN
:
1744 TrackerWindowInfo
* trackerInfo
= (TrackerWindowInfo
*)GetWindowLongA(hwnd
, 0);
1748 * Get the current mouse position in screen coordinates.
1750 mousePos
.x
= LOWORD(lParam
);
1751 mousePos
.y
= HIWORD(lParam
);
1752 ClientToScreen(hwnd
, &mousePos
);
1755 * Notify everyone that the button state changed
1756 * TODO: Check if the "escape" key was pressed.
1758 OLEDD_TrackStateChange(trackerInfo
, mousePos
, wParam
);
1765 * This is a window proc after all. Let's call the default.
1767 return DefWindowProcA (hwnd
, uMsg
, wParam
, lParam
);
1771 * OLEDD_TrackMouseMove()
1773 * This method is invoked while a drag and drop operation is in effect.
1774 * it will generate the appropriate callbacks in the drop source
1775 * and drop target. It will also provide the expected feedback to
1779 * trackerInfo - Pointer to the structure identifying the
1780 * drag & drop operation that is currently
1782 * mousePos - Current position of the mouse in screen
1784 * keyState - Contains the state of the shift keys and the
1785 * mouse buttons (MK_LBUTTON and the like)
1787 static void OLEDD_TrackMouseMove(
1788 TrackerWindowInfo
* trackerInfo
,
1792 HWND hwndNewTarget
= 0;
1796 * Get the handle of the window under the mouse
1798 hwndNewTarget
= WindowFromPoint(mousePos
);
1801 * Every time, we re-initialize the effects passed to the
1802 * IDropTarget to the effects allowed by the source.
1804 *trackerInfo
->pdwEffect
= trackerInfo
->dwOKEffect
;
1807 * If we are hovering over the same target as before, send the
1808 * DragOver notification
1810 if ( (trackerInfo
->curDragTarget
!= 0) &&
1811 (trackerInfo
->curDragTargetHWND
==hwndNewTarget
) )
1813 POINTL mousePosParam
;
1816 * The documentation tells me that the coordinate should be in the target
1817 * window's coordinate space. However, the tests I made tell me the
1818 * coordinates should be in screen coordinates.
1820 mousePosParam
.x
= mousePos
.x
;
1821 mousePosParam
.y
= mousePos
.y
;
1823 IDropTarget_DragOver(trackerInfo
->curDragTarget
,
1826 trackerInfo
->pdwEffect
);
1830 DropTargetNode
* newDropTargetNode
= 0;
1833 * If we changed window, we have to notify our old target and check for
1836 if (trackerInfo
->curDragTarget
!=0)
1838 IDropTarget_DragLeave(trackerInfo
->curDragTarget
);
1842 * Make sure we're hovering over a window.
1844 if (hwndNewTarget
!=0)
1847 * Find-out if there is a drag target under the mouse
1849 newDropTargetNode
= OLEDD_FindDropTarget(hwndNewTarget
);
1851 trackerInfo
->curDragTargetHWND
= hwndNewTarget
;
1852 trackerInfo
->curDragTarget
= newDropTargetNode
? newDropTargetNode
->dropTarget
: 0;
1855 * If there is, notify it that we just dragged-in
1857 if (trackerInfo
->curDragTarget
!=0)
1859 POINTL mousePosParam
;
1862 * The documentation tells me that the coordinate should be in the target
1863 * window's coordinate space. However, the tests I made tell me the
1864 * coordinates should be in screen coordinates.
1866 mousePosParam
.x
= mousePos
.x
;
1867 mousePosParam
.y
= mousePos
.y
;
1869 IDropTarget_DragEnter(trackerInfo
->curDragTarget
,
1870 trackerInfo
->dataObject
,
1873 trackerInfo
->pdwEffect
);
1879 * The mouse is not over a window so we don't track anything.
1881 trackerInfo
->curDragTargetHWND
= 0;
1882 trackerInfo
->curDragTarget
= 0;
1887 * Now that we have done that, we have to tell the source to give
1888 * us feedback on the work being done by the target. If we don't
1889 * have a target, simulate no effect.
1891 if (trackerInfo
->curDragTarget
==0)
1893 *trackerInfo
->pdwEffect
= DROPEFFECT_NONE
;
1896 hr
= IDropSource_GiveFeedback(trackerInfo
->dropSource
,
1897 *trackerInfo
->pdwEffect
);
1900 * When we ask for feedback from the drop source, sometimes it will
1901 * do all the necessary work and sometimes it will not handle it
1902 * when that's the case, we must display the standard drag and drop
1905 if (hr
==DRAGDROP_S_USEDEFAULTCURSORS
)
1907 if ( (*trackerInfo
->pdwEffect
& DROPEFFECT_MOVE
) ||
1908 (*trackerInfo
->pdwEffect
& DROPEFFECT_COPY
) ||
1909 (*trackerInfo
->pdwEffect
& DROPEFFECT_LINK
) )
1911 SetCursor(LoadCursorA(0, IDC_SIZEALLA
));
1915 SetCursor(LoadCursorA(0, IDC_NOA
));
1921 * OLEDD_TrackStateChange()
1923 * This method is invoked while a drag and drop operation is in effect.
1924 * It is used to notify the drop target/drop source callbacks when
1925 * the state of the keyboard or mouse button change.
1928 * trackerInfo - Pointer to the structure identifying the
1929 * drag & drop operation that is currently
1931 * mousePos - Current position of the mouse in screen
1933 * keyState - Contains the state of the shift keys and the
1934 * mouse buttons (MK_LBUTTON and the like)
1936 static void OLEDD_TrackStateChange(
1937 TrackerWindowInfo
* trackerInfo
,
1942 * Ask the drop source what to do with the operation.
1944 trackerInfo
->returnValue
= IDropSource_QueryContinueDrag(
1945 trackerInfo
->dropSource
,
1946 trackerInfo
->escPressed
,
1950 * All the return valued will stop the operation except the S_OK
1953 if (trackerInfo
->returnValue
!=S_OK
)
1956 * Make sure the message loop in DoDragDrop stops
1958 trackerInfo
->trackingDone
= TRUE
;
1961 * Release the mouse in case the drop target decides to show a popup
1962 * or a menu or something.
1967 * If we end-up over a target, drop the object in the target or
1968 * inform the target that the operation was cancelled.
1970 if (trackerInfo
->curDragTarget
!=0)
1972 switch (trackerInfo
->returnValue
)
1975 * If the source wants us to complete the operation, we tell
1976 * the drop target that we just dropped the object in it.
1978 case DRAGDROP_S_DROP
:
1980 POINTL mousePosParam
;
1983 * The documentation tells me that the coordinate should be
1984 * in the target window's coordinate space. However, the tests
1985 * I made tell me the coordinates should be in screen coordinates.
1987 mousePosParam
.x
= mousePos
.x
;
1988 mousePosParam
.y
= mousePos
.y
;
1990 IDropTarget_Drop(trackerInfo
->curDragTarget
,
1991 trackerInfo
->dataObject
,
1994 trackerInfo
->pdwEffect
);
1998 * If the source told us that we should cancel, fool the drop
1999 * target by telling it that the mouse left it's window.
2001 case DRAGDROP_S_CANCEL
:
2002 IDropTarget_DragLeave(trackerInfo
->curDragTarget
);
2010 * OLEDD_GetButtonState()
2012 * This method will use the current state of the keyboard to build
2013 * a button state mask equivalent to the one passed in the
2014 * WM_MOUSEMOVE wParam.
2016 static DWORD
OLEDD_GetButtonState()
2018 BYTE keyboardState
[256];
2021 GetKeyboardState(keyboardState
);
2023 if ( (keyboardState
[VK_SHIFT
] & 0x80) !=0)
2024 keyMask
|= MK_SHIFT
;
2026 if ( (keyboardState
[VK_CONTROL
] & 0x80) !=0)
2027 keyMask
|= MK_CONTROL
;
2029 if ( (keyboardState
[VK_LBUTTON
] & 0x80) !=0)
2030 keyMask
|= MK_LBUTTON
;
2032 if ( (keyboardState
[VK_RBUTTON
] & 0x80) !=0)
2033 keyMask
|= MK_RBUTTON
;
2035 if ( (keyboardState
[VK_MBUTTON
] & 0x80) !=0)
2036 keyMask
|= MK_MBUTTON
;
2042 * OLEDD_GetButtonState()
2044 * This method will read the default value of the registry key in
2045 * parameter and extract a DWORD value from it. The registry key value
2046 * can be in a string key or a DWORD key.
2049 * regKey - Key to read the default value from
2050 * pdwValue - Pointer to the location where the DWORD
2051 * value is returned. This value is not modified
2052 * if the value is not found.
2055 static void OLEUTL_ReadRegistryDWORDValue(
2064 lres
= RegQueryValueExA(regKey
,
2071 if (lres
==ERROR_SUCCESS
)
2076 *pdwValue
= *(DWORD
*)buffer
;
2081 *pdwValue
= (DWORD
)strtoul(buffer
, NULL
, 10);
2087 /******************************************************************************
2088 * OleMetaFilePictFromIconAndLabel
2090 * Returns a global memory handle to a metafile which contains the icon and
2092 * I guess the result of that should look somehow like desktop icons.
2093 * If no hIcon is given, we load the icon via lpszSourceFile and iIconIndex.
2094 * This code might be wrong at some places.
2096 HGLOBAL16 WINAPI
OleMetaFilePictFromIconAndLabel16(
2098 LPCOLESTR16 lpszLabel
,
2099 LPCOLESTR16 lpszSourceFile
,
2106 FIXME("(%04x, '%s', '%s', %d): incorrect metrics, please try to correct them !\n\n\n", hIcon
, lpszLabel
, lpszSourceFile
, iIconIndex
);
2109 if (lpszSourceFile
) {
2110 HINSTANCE16 hInstance
= LoadLibrary16(lpszSourceFile
);
2112 /* load the icon at index from lpszSourceFile */
2113 hIcon
= (HICON16
)LoadIconA(hInstance
, (LPCSTR
)(DWORD
)iIconIndex
);
2114 FreeLibrary16(hInstance
);
2116 return (HGLOBAL
)NULL
;
2119 hdc
= CreateMetaFile16(NULL
);
2120 DrawIcon(hdc
, 0, 0, hIcon
); /* FIXME */
2121 TextOut16(hdc
, 0, 0, lpszLabel
, 1); /* FIXME */
2122 hmf
= GlobalAlloc16(0, sizeof(METAFILEPICT16
));
2123 mf
= (METAFILEPICT16
*)GlobalLock16(hmf
);
2124 mf
->mm
= MM_ANISOTROPIC
;
2125 mf
->xExt
= 20; /* FIXME: bogus */
2126 mf
->yExt
= 20; /* dito */
2127 mf
->hMF
= CloseMetaFile16(hdc
);