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/wingdi16.h"
23 #include "debugtools.h"
27 DEFAULT_DEBUG_CHANNEL(ole
)
29 /******************************************************************************
30 * These are static/global variables and internal data structures that the
31 * OLE module uses to maintain it's state.
33 typedef struct tagDropTargetNode
36 IDropTarget
* dropTarget
;
37 struct tagDropTargetNode
* prevDropTarget
;
38 struct tagDropTargetNode
* nextDropTarget
;
41 typedef struct tagTrackerWindowInfo
43 IDataObject
* dataObject
;
44 IDropSource
* dropSource
;
51 HWND curDragTargetHWND
;
52 IDropTarget
* curDragTarget
;
55 typedef struct tagOleMenuDescriptor
/* OleMenuDescriptor */
57 HWND hwndFrame
; /* The containers frame window */
58 HWND hwndActiveObject
; /* The active objects window */
59 OLEMENUGROUPWIDTHS mgw
; /* OLE menu group widths for the shared menu */
60 HMENU hmenuCombined
; /* The combined menu */
61 BOOL bIsServerItem
; /* True if the currently open popup belongs to the server */
64 typedef struct tagOleMenuHookItem
/* OleMenu hook item in per thread hook list */
66 DWORD tid
; /* Thread Id */
67 HANDLE hHeap
; /* Heap this is allocated from */
68 HHOOK GetMsg_hHook
; /* message hook for WH_GETMESSAGE */
69 HHOOK CallWndProc_hHook
; /* message hook for WH_CALLWNDPROC */
70 struct tagOleMenuHookItem
*next
;
73 static OleMenuHookItem
*hook_list
;
76 * This is the lock count on the OLE library. It is controlled by the
77 * OLEInitialize/OLEUninitialize methods.
79 static ULONG OLE_moduleLockCount
= 0;
82 * Name of our registered window class.
84 static const char OLEDD_DRAGTRACKERCLASS
[] = "WineDragDropTracker32";
87 * This is the head of the Drop target container.
89 static DropTargetNode
* targetListHead
= NULL
;
91 /******************************************************************************
92 * These are the prototypes of miscelaneous utility methods
94 static void OLEUTL_ReadRegistryDWORDValue(HKEY regKey
, DWORD
* pdwValue
);
96 /******************************************************************************
97 * These are the prototypes of the utility methods used to manage a shared menu
99 static void OLEMenu_Initialize();
100 static void OLEMenu_UnInitialize();
101 BOOL
OLEMenu_InstallHooks( DWORD tid
);
102 BOOL
OLEMenu_UnInstallHooks( DWORD tid
);
103 OleMenuHookItem
* OLEMenu_IsHookInstalled( DWORD tid
);
104 static BOOL
OLEMenu_FindMainMenuIndex( HMENU hMainMenu
, HMENU hPopupMenu
, UINT
*pnPos
);
105 BOOL
OLEMenu_SetIsServerMenu( HMENU hmenu
, OleMenuDescriptor
*pOleMenuDescriptor
);
106 LRESULT CALLBACK
OLEMenu_CallWndProc(INT code
, WPARAM wParam
, LPARAM lParam
);
107 LRESULT CALLBACK
OLEMenu_GetMsgProc(INT code
, WPARAM wParam
, LPARAM lParam
);
109 /******************************************************************************
110 * These are the prototypes of the OLE Clipboard initialization methods (in clipboard.c)
112 void OLEClipbrd_UnInitialize();
113 void OLEClipbrd_Initialize();
115 /******************************************************************************
116 * These are the prototypes of the utility methods used for OLE Drag n Drop
118 static void OLEDD_Initialize();
119 static void OLEDD_UnInitialize();
120 static void OLEDD_InsertDropTarget(
121 DropTargetNode
* nodeToAdd
);
122 static DropTargetNode
* OLEDD_ExtractDropTarget(
124 static DropTargetNode
* OLEDD_FindDropTarget(
126 static LRESULT WINAPI
OLEDD_DragTrackerWindowProc(
131 static void OLEDD_TrackMouseMove(
132 TrackerWindowInfo
* trackerInfo
,
135 static void OLEDD_TrackStateChange(
136 TrackerWindowInfo
* trackerInfo
,
139 static DWORD
OLEDD_GetButtonState();
142 /******************************************************************************
143 * OleBuildVersion [OLE2.1]
145 DWORD WINAPI
OleBuildVersion(void)
147 TRACE("Returning version %d, build %d.\n", rmm
, rup
);
148 return (rmm
<<16)+rup
;
151 /***********************************************************************
152 * OleInitialize (OLE2.2) (OLE32.108)
154 HRESULT WINAPI
OleInitialize(LPVOID reserved
)
158 TRACE("(%p)\n", reserved
);
161 * The first duty of the OleInitialize is to initialize the COM libraries.
163 hr
= CoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
166 * If the CoInitializeEx call failed, the OLE libraries can't be
173 * Then, it has to initialize the OLE specific modules.
177 * Object linking and Embedding
178 * In-place activation
180 if (OLE_moduleLockCount
==0)
183 * Initialize the libraries.
185 TRACE("() - Initializing the OLE libraries\n");
190 OLEClipbrd_Initialize();
200 OLEMenu_Initialize();
204 * Then, we increase the lock count on the OLE module.
206 OLE_moduleLockCount
++;
211 /******************************************************************************
212 * CoGetCurrentProcess [COMPOBJ.34] [OLE2.2][OLE32.108]
215 * Is DWORD really the correct return type for this function?
217 DWORD WINAPI
CoGetCurrentProcess(void) {
218 return (DWORD
)PROCESS_Current();
221 /******************************************************************************
222 * OleUninitialize [OLE2.3] [OLE32.131]
224 void WINAPI
OleUninitialize(void)
229 * Decrease the lock count on the OLE module.
231 OLE_moduleLockCount
--;
234 * If we hit the bottom of the lock stack, free the libraries.
236 if (OLE_moduleLockCount
==0)
239 * Actually free the libraries.
241 TRACE("() - Freeing the last reference count\n");
246 OLEClipbrd_UnInitialize();
251 OLEDD_UnInitialize();
256 OLEMenu_UnInitialize();
260 * Then, uninitialize the COM libraries.
265 /******************************************************************************
266 * CoRegisterMessageFilter32 [OLE32.38]
268 HRESULT WINAPI
CoRegisterMessageFilter(
269 LPMESSAGEFILTER lpMessageFilter
, /* Pointer to interface */
270 LPMESSAGEFILTER
*lplpMessageFilter
/* Indirect pointer to prior instance if non-NULL */
273 if (lplpMessageFilter
) {
274 *lplpMessageFilter
= NULL
;
279 /******************************************************************************
280 * OleInitializeWOW [OLE32.109]
282 HRESULT WINAPI
OleInitializeWOW(DWORD x
) {
283 FIXME("(0x%08lx),stub!\n",x
);
287 /***********************************************************************
288 * RegisterDragDrop16 (OLE2.35)
290 HRESULT WINAPI
RegisterDragDrop16(
292 LPDROPTARGET pDropTarget
294 FIXME("(0x%04x,%p),stub!\n",hwnd
,pDropTarget
);
298 /***********************************************************************
299 * RegisterDragDrop32 (OLE32.139)
301 HRESULT WINAPI
RegisterDragDrop(
303 LPDROPTARGET pDropTarget
)
305 DropTargetNode
* dropTargetInfo
;
307 TRACE("(0x%x,%p)\n", hwnd
, pDropTarget
);
310 * First, check if the window is already registered.
312 dropTargetInfo
= OLEDD_FindDropTarget(hwnd
);
314 if (dropTargetInfo
!=NULL
)
315 return DRAGDROP_E_ALREADYREGISTERED
;
318 * If it's not there, we can add it. We first create a node for it.
320 dropTargetInfo
= HeapAlloc(GetProcessHeap(), 0, sizeof(DropTargetNode
));
322 if (dropTargetInfo
==NULL
)
323 return E_OUTOFMEMORY
;
325 dropTargetInfo
->hwndTarget
= hwnd
;
326 dropTargetInfo
->prevDropTarget
= NULL
;
327 dropTargetInfo
->nextDropTarget
= NULL
;
330 * Don't forget that this is an interface pointer, need to nail it down since
331 * we keep a copy of it.
333 dropTargetInfo
->dropTarget
= pDropTarget
;
334 IDropTarget_AddRef(dropTargetInfo
->dropTarget
);
336 OLEDD_InsertDropTarget(dropTargetInfo
);
341 /***********************************************************************
342 * RevokeDragDrop16 (OLE2.36)
344 HRESULT WINAPI
RevokeDragDrop16(
347 FIXME("(0x%04x),stub!\n",hwnd
);
351 /***********************************************************************
352 * RevokeDragDrop32 (OLE32.141)
354 HRESULT WINAPI
RevokeDragDrop(
357 DropTargetNode
* dropTargetInfo
;
359 TRACE("(0x%x)\n", hwnd
);
362 * First, check if the window is already registered.
364 dropTargetInfo
= OLEDD_ExtractDropTarget(hwnd
);
367 * If it ain't in there, it's an error.
369 if (dropTargetInfo
==NULL
)
370 return DRAGDROP_E_NOTREGISTERED
;
373 * If it's in there, clean-up it's used memory and
376 IDropTarget_Release(dropTargetInfo
->dropTarget
);
377 HeapFree(GetProcessHeap(), 0, dropTargetInfo
);
382 /***********************************************************************
383 * OleRegGetUserType (OLE32.122)
385 * This implementation of OleRegGetUserType ignores the dwFormOfType
386 * parameter and always returns the full name of the object. This is
387 * not too bad since this is the case for many objects because of the
388 * way they are registered.
390 HRESULT WINAPI
OleRegGetUserType(
393 LPOLESTR
* pszUserType
)
403 * Initialize the out parameter.
408 * Build the key name we're looking for
410 WINE_StringFromCLSID((LPCLSID
)clsid
, xclsid
);
412 strcpy(keyName
, "CLSID\\");
413 strcat(keyName
, xclsid
);
414 strcat(keyName
, "\\");
416 TRACE("(%s, %ld, %p)\n", keyName
, dwFormOfType
, pszUserType
);
419 * Open the class id Key
421 hres
= RegOpenKeyA(HKEY_CLASSES_ROOT
,
425 if (hres
!= ERROR_SUCCESS
)
426 return REGDB_E_CLASSNOTREG
;
429 * Retrieve the size of the name string.
433 hres
= RegQueryValueExA(clsidKey
,
440 if (hres
!=ERROR_SUCCESS
)
442 RegCloseKey(clsidKey
);
443 return REGDB_E_READREGDB
;
447 * Allocate a buffer for the registry value.
449 *pszUserType
= CoTaskMemAlloc(cbData
);
451 if (*pszUserType
==NULL
)
453 RegCloseKey(clsidKey
);
454 return E_OUTOFMEMORY
;
457 hres
= RegQueryValueExA(clsidKey
,
461 (LPBYTE
)*pszUserType
,
464 RegCloseKey(clsidKey
);
466 if (hres
!=ERROR_SUCCESS
)
468 CoTaskMemFree(*pszUserType
);
471 return REGDB_E_READREGDB
;
477 /***********************************************************************
478 * DoDragDrop32 [OLE32.65]
480 HRESULT WINAPI
DoDragDrop (
481 IDataObject
*pDataObject
, /* ptr to the data obj */
482 IDropSource
* pDropSource
, /* ptr to the source obj */
483 DWORD dwOKEffect
, /* effects allowed by the source */
484 DWORD
*pdwEffect
) /* ptr to effects of the source */
486 TrackerWindowInfo trackerInfo
;
487 HWND hwndTrackWindow
;
490 TRACE("(DataObject %p, DropSource %p)\n", pDataObject
, pDropSource
);
493 * Setup the drag n drop tracking window.
495 trackerInfo
.dataObject
= pDataObject
;
496 trackerInfo
.dropSource
= pDropSource
;
497 trackerInfo
.dwOKEffect
= dwOKEffect
;
498 trackerInfo
.pdwEffect
= pdwEffect
;
499 trackerInfo
.trackingDone
= FALSE
;
500 trackerInfo
.escPressed
= FALSE
;
501 trackerInfo
.curDragTargetHWND
= 0;
502 trackerInfo
.curDragTarget
= 0;
504 hwndTrackWindow
= CreateWindowA(OLEDD_DRAGTRACKERCLASS
,
507 CW_USEDEFAULT
, CW_USEDEFAULT
,
508 CW_USEDEFAULT
, CW_USEDEFAULT
,
512 (LPVOID
)&trackerInfo
);
514 if (hwndTrackWindow
!=0)
517 * Capture the mouse input
519 SetCapture(hwndTrackWindow
);
522 * Pump messages. All mouse input should go the the capture window.
524 while (!trackerInfo
.trackingDone
&& GetMessageA(&msg
, 0, 0, 0) )
526 if ( (msg
.message
>= WM_KEYFIRST
) &&
527 (msg
.message
<= WM_KEYFIRST
) )
530 * When keyboard messages are sent to windows on this thread, we
531 * want to ignore notify the drop source that the state changed.
532 * in the case of the Escape key, we also notify the drop source
533 * we give it a special meaning.
535 if ( (msg
.message
==WM_KEYDOWN
) &&
536 (msg
.wParam
==VK_ESCAPE
) )
538 trackerInfo
.escPressed
= TRUE
;
542 * Notify the drop source.
544 OLEDD_TrackStateChange(&trackerInfo
,
546 OLEDD_GetButtonState());
551 * Dispatch the messages only when it's not a keyboard message.
553 DispatchMessageA(&msg
);
558 * Destroy the temporary window.
560 DestroyWindow(hwndTrackWindow
);
562 return trackerInfo
.returnValue
;
568 /***********************************************************************
569 * OleQueryLinkFromData32 [OLE32.118]
571 HRESULT WINAPI
OleQueryLinkFromData(
572 IDataObject
* pSrcDataObject
)
574 FIXME("(%p),stub!\n", pSrcDataObject
);
578 /***********************************************************************
579 * OleRegGetMiscStatus [OLE32.121]
581 HRESULT WINAPI
OleRegGetMiscStatus(
594 * Initialize the out parameter.
599 * Build the key name we're looking for
601 WINE_StringFromCLSID((LPCLSID
)clsid
, xclsid
);
603 strcpy(keyName
, "CLSID\\");
604 strcat(keyName
, xclsid
);
605 strcat(keyName
, "\\");
607 TRACE("(%s, %ld, %p)\n", keyName
, dwAspect
, pdwStatus
);
610 * Open the class id Key
612 result
= RegOpenKeyA(HKEY_CLASSES_ROOT
,
616 if (result
!= ERROR_SUCCESS
)
617 return REGDB_E_CLASSNOTREG
;
622 result
= RegOpenKeyA(clsidKey
,
627 if (result
!= ERROR_SUCCESS
)
629 RegCloseKey(clsidKey
);
630 return REGDB_E_READREGDB
;
634 * Read the default value
636 OLEUTL_ReadRegistryDWORDValue(miscStatusKey
, pdwStatus
);
639 * Open the key specific to the requested aspect.
641 sprintf(keyName
, "%ld", dwAspect
);
643 result
= RegOpenKeyA(miscStatusKey
,
647 if (result
== ERROR_SUCCESS
)
649 OLEUTL_ReadRegistryDWORDValue(aspectKey
, pdwStatus
);
650 RegCloseKey(aspectKey
);
656 RegCloseKey(miscStatusKey
);
657 RegCloseKey(clsidKey
);
662 /******************************************************************************
663 * OleSetContainedObject [OLE32.128]
665 HRESULT WINAPI
OleSetContainedObject(
669 IRunnableObject
* runnable
= NULL
;
672 TRACE("(%p,%x), stub!\n", pUnknown
, fContained
);
674 hres
= IUnknown_QueryInterface(pUnknown
,
675 &IID_IRunnableObject
,
680 hres
= IRunnableObject_SetContainedObject(runnable
, fContained
);
682 IRunnableObject_Release(runnable
);
690 /******************************************************************************
691 * OleLoad [OLE32.112]
693 HRESULT WINAPI
OleLoad(
696 LPOLECLIENTSITE pClientSite
,
699 IPersistStorage
* persistStorage
= NULL
;
700 IOleObject
* oleObject
= NULL
;
704 TRACE("(%p,%p,%p,%p)\n", pStg
, riid
, pClientSite
, ppvObj
);
707 * TODO, Conversion ... OleDoAutoConvert
711 * Get the class ID for the object.
713 hres
= IStorage_Stat(pStg
, &storageInfo
, STATFLAG_NONAME
);
716 * Now, try and create the handler for the object
718 hres
= CoCreateInstance(&storageInfo
.clsid
,
720 CLSCTX_INPROC_HANDLER
,
725 * If that fails, as it will most times, load the default
730 hres
= OleCreateDefaultHandler(&storageInfo
.clsid
,
737 * If we couldn't find a handler... this is bad. Abort the whole thing.
743 * Inform the new object of it's client site.
745 hres
= IOleObject_SetClientSite(oleObject
, pClientSite
);
748 * Initialize the object with it's IPersistStorage interface.
750 hres
= IOleObject_QueryInterface(oleObject
,
751 &IID_IPersistStorage
,
752 (void**)&persistStorage
);
756 IPersistStorage_Load(persistStorage
, pStg
);
758 IPersistStorage_Release(persistStorage
);
759 persistStorage
= NULL
;
763 * Return the requested interface to the caller.
765 hres
= IOleObject_QueryInterface(oleObject
, riid
, ppvObj
);
768 * Cleanup interfaces used internally
770 IOleObject_Release(oleObject
);
775 /***********************************************************************
776 * OleSave [OLE32.124]
778 HRESULT WINAPI
OleSave(
779 LPPERSISTSTORAGE pPS
,
786 TRACE("(%p,%p,%x)\n", pPS
, pStg
, fSameAsLoad
);
789 * First, we transfer the class ID (if available)
791 hres
= IPersistStorage_GetClassID(pPS
, &objectClass
);
795 WriteClassStg(pStg
, &objectClass
);
799 * Then, we ask the object to save itself to the
800 * storage. If it is successful, we commit the storage.
802 hres
= IPersistStorage_Save(pPS
, pStg
, fSameAsLoad
);
806 IStorage_Commit(pStg
,
814 /**************************************************************************
815 * Internal methods to manage the shared OLE menu in response to the
816 * OLE***MenuDescriptor API
820 * OLEMenu_Initialize()
822 * Initializes the OLEMENU data structures.
824 static void OLEMenu_Initialize()
829 * OLEMenu_UnInitialize()
831 * Releases the OLEMENU data structures.
833 static void OLEMenu_UnInitialize()
837 /*************************************************************************
838 * OLEMenu_InstallHooks
839 * Install thread scope message hooks for WH_GETMESSAGE and WH_CALLWNDPROC
841 * RETURNS: TRUE if message hooks were succesfully installed
844 BOOL
OLEMenu_InstallHooks( DWORD tid
)
846 OleMenuHookItem
*pHookItem
= NULL
;
848 /* Create an entry for the hook table */
849 if ( !(pHookItem
= HeapAlloc(GetProcessHeap(), 0,
850 sizeof(OleMenuHookItem
)) ) )
853 pHookItem
->tid
= tid
;
854 pHookItem
->hHeap
= GetProcessHeap();
856 /* Install a thread scope message hook for WH_GETMESSAGE */
857 pHookItem
->GetMsg_hHook
= SetWindowsHookExA( WH_GETMESSAGE
, OLEMenu_GetMsgProc
,
858 0, GetCurrentThreadId() );
859 if ( !pHookItem
->GetMsg_hHook
)
862 /* Install a thread scope message hook for WH_CALLWNDPROC */
863 pHookItem
->CallWndProc_hHook
= SetWindowsHookExA( WH_CALLWNDPROC
, OLEMenu_CallWndProc
,
864 0, GetCurrentThreadId() );
865 if ( !pHookItem
->CallWndProc_hHook
)
868 /* Insert the hook table entry */
869 pHookItem
->next
= hook_list
;
870 hook_list
= pHookItem
;
875 /* Unhook any hooks */
876 if ( pHookItem
->GetMsg_hHook
)
877 UnhookWindowsHookEx( pHookItem
->GetMsg_hHook
);
878 if ( pHookItem
->CallWndProc_hHook
)
879 UnhookWindowsHookEx( pHookItem
->CallWndProc_hHook
);
880 /* Release the hook table entry */
881 HeapFree(pHookItem
->hHeap
, 0, pHookItem
);
886 /*************************************************************************
887 * OLEMenu_UnInstallHooks
888 * UnInstall thread scope message hooks for WH_GETMESSAGE and WH_CALLWNDPROC
890 * RETURNS: TRUE if message hooks were succesfully installed
893 BOOL
OLEMenu_UnInstallHooks( DWORD tid
)
895 OleMenuHookItem
*pHookItem
= NULL
;
896 OleMenuHookItem
**ppHook
= &hook_list
;
900 if ((*ppHook
)->tid
== tid
)
903 *ppHook
= pHookItem
->next
;
906 ppHook
= &(*ppHook
)->next
;
908 if (!pHookItem
) return FALSE
;
910 /* Uninstall the hooks installed for this thread */
911 if ( !UnhookWindowsHookEx( pHookItem
->GetMsg_hHook
) )
913 if ( !UnhookWindowsHookEx( pHookItem
->CallWndProc_hHook
) )
916 /* Release the hook table entry */
917 HeapFree(pHookItem
->hHeap
, 0, pHookItem
);
922 /* Release the hook table entry */
924 HeapFree(pHookItem
->hHeap
, 0, pHookItem
);
929 /*************************************************************************
930 * OLEMenu_IsHookInstalled
931 * Tests if OLEMenu hooks have been installed for a thread
933 * RETURNS: The pointer and index of the hook table entry for the tid
934 * NULL and -1 for the index if no hooks were installed for this thread
936 OleMenuHookItem
* OLEMenu_IsHookInstalled( DWORD tid
)
938 OleMenuHookItem
*pHookItem
= NULL
;
940 /* Do a simple linear search for an entry whose tid matches ours.
941 * We really need a map but efficiency is not a concern here. */
942 for (pHookItem
= hook_list
; pHookItem
; pHookItem
= pHookItem
->next
)
944 if ( tid
== pHookItem
->tid
)
951 /***********************************************************************
952 * OLEMenu_FindMainMenuIndex
954 * Used by OLEMenu API to find the top level group a menu item belongs to.
955 * On success pnPos contains the index of the item in the top level menu group
957 * RETURNS: TRUE if the ID was found, FALSE on failure
959 static BOOL
OLEMenu_FindMainMenuIndex( HMENU hMainMenu
, HMENU hPopupMenu
, UINT
*pnPos
)
963 nItems
= GetMenuItemCount( hMainMenu
);
965 for (i
= 0; i
< nItems
; i
++)
969 /* Is the current item a submenu? */
970 if ( (hsubmenu
= GetSubMenu(hMainMenu
, i
)) )
972 /* If the handle is the same we're done */
973 if ( hsubmenu
== hPopupMenu
)
979 /* Recursively search without updating pnPos */
980 else if ( OLEMenu_FindMainMenuIndex( hsubmenu
, hPopupMenu
, NULL
) )
992 /***********************************************************************
993 * OLEMenu_SetIsServerMenu
995 * Checks whether a popup menu belongs to a shared menu group which is
996 * owned by the server, and sets the menu descriptor state accordingly.
997 * All menu messages from these groups should be routed to the server.
999 * RETURNS: TRUE if the popup menu is part of a server owned group
1000 * FASE if the popup menu is part of a container owned group
1002 BOOL
OLEMenu_SetIsServerMenu( HMENU hmenu
, OleMenuDescriptor
*pOleMenuDescriptor
)
1004 UINT nPos
= 0, nWidth
, i
;
1006 pOleMenuDescriptor
->bIsServerItem
= FALSE
;
1008 /* Don't bother searching if the popup is the combined menu itself */
1009 if ( hmenu
== pOleMenuDescriptor
->hmenuCombined
)
1012 /* Find the menu item index in the shared OLE menu that this item belongs to */
1013 if ( !OLEMenu_FindMainMenuIndex( pOleMenuDescriptor
->hmenuCombined
, hmenu
, &nPos
) )
1016 /* The group widths array has counts for the number of elements
1017 * in the groups File, Edit, Container, Object, Window, Help.
1018 * The Edit, Object & Help groups belong to the server object
1019 * and the other three belong to the container.
1020 * Loop thru the group widths and locate the group we are a member of.
1022 for ( i
= 0, nWidth
= 0; i
< 6; i
++ )
1024 nWidth
+= pOleMenuDescriptor
->mgw
.width
[i
];
1025 if ( nPos
< nWidth
)
1027 /* Odd elements are server menu widths */
1028 pOleMenuDescriptor
->bIsServerItem
= (i
%2) ? TRUE
: FALSE
;
1033 return pOleMenuDescriptor
->bIsServerItem
;
1036 /*************************************************************************
1037 * OLEMenu_CallWndProc
1038 * Thread scope WH_CALLWNDPROC hook proc filter function (callback)
1039 * This is invoked from a message hook installed in OleSetMenuDescriptor.
1041 LRESULT CALLBACK
OLEMenu_CallWndProc(INT code
, WPARAM wParam
, LPARAM lParam
)
1043 LPCWPSTRUCT pMsg
= NULL
;
1044 HOLEMENU hOleMenu
= 0;
1045 OleMenuDescriptor
*pOleMenuDescriptor
= NULL
;
1046 OleMenuHookItem
*pHookItem
= NULL
;
1049 TRACE("%i, %04x, %08x\n", code
, wParam
, (unsigned)lParam
);
1051 /* Check if we're being asked to process the message */
1052 if ( HC_ACTION
!= code
)
1055 /* Retrieve the current message being dispatched from lParam */
1056 pMsg
= (LPCWPSTRUCT
)lParam
;
1058 /* Check if the message is destined for a window we are interested in:
1059 * If the window has an OLEMenu property we may need to dispatch
1060 * the menu message to its active objects window instead. */
1062 hOleMenu
= (HOLEMENU
)GetPropA( pMsg
->hwnd
, "PROP_OLEMenuDescriptor" );
1066 /* Get the menu descriptor */
1067 pOleMenuDescriptor
= (OleMenuDescriptor
*) GlobalLock( hOleMenu
);
1068 if ( !pOleMenuDescriptor
) /* Bad descriptor! */
1071 /* Process menu messages */
1072 switch( pMsg
->message
)
1076 /* Reset the menu descriptor state */
1077 pOleMenuDescriptor
->bIsServerItem
= FALSE
;
1079 /* Send this message to the server as well */
1080 SendMessageA( pOleMenuDescriptor
->hwndActiveObject
,
1081 pMsg
->message
, pMsg
->wParam
, pMsg
->lParam
);
1085 case WM_INITMENUPOPUP
:
1087 /* Save the state for whether this is a server owned menu */
1088 OLEMenu_SetIsServerMenu( (HMENU
)pMsg
->wParam
, pOleMenuDescriptor
);
1094 fuFlags
= HIWORD(pMsg
->wParam
); /* Get flags */
1095 if ( fuFlags
& MF_SYSMENU
)
1098 /* Save the state for whether this is a server owned popup menu */
1099 else if ( fuFlags
& MF_POPUP
)
1100 OLEMenu_SetIsServerMenu( (HMENU
)pMsg
->lParam
, pOleMenuDescriptor
);
1107 LPDRAWITEMSTRUCT lpdis
= (LPDRAWITEMSTRUCT
) pMsg
->lParam
;
1108 if ( pMsg
->wParam
!= 0 || lpdis
->CtlType
!= ODT_MENU
)
1109 goto NEXTHOOK
; /* Not a menu message */
1118 /* If the message was for the server dispatch it accordingly */
1119 if ( pOleMenuDescriptor
->bIsServerItem
)
1121 SendMessageA( pOleMenuDescriptor
->hwndActiveObject
,
1122 pMsg
->message
, pMsg
->wParam
, pMsg
->lParam
);
1126 if ( pOleMenuDescriptor
)
1127 GlobalUnlock( hOleMenu
);
1129 /* Lookup the hook item for the current thread */
1130 if ( !( pHookItem
= OLEMenu_IsHookInstalled( GetCurrentThreadId() ) ) )
1132 /* This should never fail!! */
1133 WARN("could not retrieve hHook for current thread!\n" );
1137 /* Pass on the message to the next hooker */
1138 return CallNextHookEx( pHookItem
->CallWndProc_hHook
, code
, wParam
, lParam
);
1141 /*************************************************************************
1142 * OLEMenu_GetMsgProc
1143 * Thread scope WH_GETMESSAGE hook proc filter function (callback)
1144 * This is invoked from a message hook installed in OleSetMenuDescriptor.
1146 LRESULT CALLBACK
OLEMenu_GetMsgProc(INT code
, WPARAM wParam
, LPARAM lParam
)
1149 HOLEMENU hOleMenu
= 0;
1150 OleMenuDescriptor
*pOleMenuDescriptor
= NULL
;
1151 OleMenuHookItem
*pHookItem
= NULL
;
1154 TRACE("%i, %04x, %08x\n", code
, wParam
, (unsigned)lParam
);
1156 /* Check if we're being asked to process a messages */
1157 if ( HC_ACTION
!= code
)
1160 /* Retrieve the current message being dispatched from lParam */
1161 pMsg
= (LPMSG
)lParam
;
1163 /* Check if the message is destined for a window we are interested in:
1164 * If the window has an OLEMenu property we may need to dispatch
1165 * the menu message to its active objects window instead. */
1167 hOleMenu
= (HOLEMENU
)GetPropA( pMsg
->hwnd
, "PROP_OLEMenuDescriptor" );
1171 /* Process menu messages */
1172 switch( pMsg
->message
)
1176 wCode
= HIWORD(pMsg
->wParam
); /* Get notification code */
1178 goto NEXTHOOK
; /* Not a menu message */
1185 /* Get the menu descriptor */
1186 pOleMenuDescriptor
= (OleMenuDescriptor
*) GlobalLock( hOleMenu
);
1187 if ( !pOleMenuDescriptor
) /* Bad descriptor! */
1190 /* If the message was for the server dispatch it accordingly */
1191 if ( pOleMenuDescriptor
->bIsServerItem
)
1193 /* Change the hWnd in the message to the active objects hWnd.
1194 * The message loop which reads this message will automatically
1195 * dispatch it to the embedded objects window. */
1196 pMsg
->hwnd
= pOleMenuDescriptor
->hwndActiveObject
;
1200 if ( pOleMenuDescriptor
)
1201 GlobalUnlock( hOleMenu
);
1203 /* Lookup the hook item for the current thread */
1204 if ( !( pHookItem
= OLEMenu_IsHookInstalled( GetCurrentThreadId() ) ) )
1206 /* This should never fail!! */
1207 WARN("could not retrieve hHook for current thread!\n" );
1211 /* Pass on the message to the next hooker */
1212 return CallNextHookEx( pHookItem
->GetMsg_hHook
, code
, wParam
, lParam
);
1215 /***********************************************************************
1216 * OleCreateMenuDescriptor [OLE32.97]
1217 * Creates an OLE menu descriptor for OLE to use when dispatching
1218 * menu messages and commands.
1221 * hmenuCombined - Handle to the objects combined menu
1222 * lpMenuWidths - Pointer to array of 6 LONG's indicating menus per group
1225 HOLEMENU WINAPI
OleCreateMenuDescriptor(
1226 HMENU hmenuCombined
,
1227 LPOLEMENUGROUPWIDTHS lpMenuWidths
)
1230 OleMenuDescriptor
*pOleMenuDescriptor
;
1233 if ( !hmenuCombined
|| !lpMenuWidths
)
1236 /* Create an OLE menu descriptor */
1237 if ( !(hOleMenu
= GlobalAlloc(GMEM_MOVEABLE
| GMEM_ZEROINIT
,
1238 sizeof(OleMenuDescriptor
) ) ) )
1241 pOleMenuDescriptor
= (OleMenuDescriptor
*) GlobalLock( hOleMenu
);
1242 if ( !pOleMenuDescriptor
)
1245 /* Initialize menu group widths and hmenu */
1246 for ( i
= 0; i
< 6; i
++ )
1247 pOleMenuDescriptor
->mgw
.width
[i
] = lpMenuWidths
->width
[i
];
1249 pOleMenuDescriptor
->hmenuCombined
= hmenuCombined
;
1250 pOleMenuDescriptor
->bIsServerItem
= FALSE
;
1251 GlobalUnlock( hOleMenu
);
1256 /***********************************************************************
1257 * OleDestroyMenuDescriptor [OLE32.99]
1258 * Destroy the shared menu descriptor
1260 HRESULT WINAPI
OleDestroyMenuDescriptor(
1261 HOLEMENU hmenuDescriptor
)
1263 if ( hmenuDescriptor
)
1264 GlobalFree( hmenuDescriptor
);
1268 /***********************************************************************
1269 * OleSetMenuDescriptor [OLE32.129]
1270 * Installs or removes OLE dispatching code for the containers frame window
1271 * FIXME: The lpFrame and lpActiveObject parameters are currently ignored
1272 * OLE should install context sensitive help F1 filtering for the app when
1273 * these are non null.
1276 * hOleMenu Handle to composite menu descriptor
1277 * hwndFrame Handle to containers frame window
1278 * hwndActiveObject Handle to objects in-place activation window
1279 * lpFrame Pointer to IOleInPlaceFrame on containers window
1280 * lpActiveObject Pointer to IOleInPlaceActiveObject on active in-place object
1283 * S_OK - menu installed correctly
1284 * E_FAIL, E_INVALIDARG, E_UNEXPECTED - failure
1286 HRESULT WINAPI
OleSetMenuDescriptor(
1289 HWND hwndActiveObject
,
1290 LPOLEINPLACEFRAME lpFrame
,
1291 LPOLEINPLACEACTIVEOBJECT lpActiveObject
)
1293 OleMenuDescriptor
*pOleMenuDescriptor
= NULL
;
1296 if ( !hwndFrame
|| (hOleMenu
&& !hwndActiveObject
) )
1297 return E_INVALIDARG
;
1299 if ( lpFrame
|| lpActiveObject
)
1301 FIXME("(%x, %x, %x, %p, %p), Context sensitive help filtering not implemented!\n",
1302 (unsigned int)hOleMenu
,
1309 /* Set up a message hook to intercept the containers frame window messages.
1310 * The message filter is responsible for dispatching menu messages from the
1311 * shared menu which are intended for the object.
1314 if ( hOleMenu
) /* Want to install dispatching code */
1316 /* If OLEMenu hooks are already installed for this thread, fail
1317 * Note: This effectively means that OleSetMenuDescriptor cannot
1318 * be called twice in succession on the same frame window
1319 * without first calling it with a null hOleMenu to uninstall */
1320 if ( OLEMenu_IsHookInstalled( GetCurrentThreadId() ) )
1323 /* Get the menu descriptor */
1324 pOleMenuDescriptor
= (OleMenuDescriptor
*) GlobalLock( hOleMenu
);
1325 if ( !pOleMenuDescriptor
)
1326 return E_UNEXPECTED
;
1328 /* Update the menu descriptor */
1329 pOleMenuDescriptor
->hwndFrame
= hwndFrame
;
1330 pOleMenuDescriptor
->hwndActiveObject
= hwndActiveObject
;
1332 GlobalUnlock( hOleMenu
);
1333 pOleMenuDescriptor
= NULL
;
1335 /* Add a menu descriptor windows property to the frame window */
1336 SetPropA( hwndFrame
, "PROP_OLEMenuDescriptor", hOleMenu
);
1338 /* Install thread scope message hooks for WH_GETMESSAGE and WH_CALLWNDPROC */
1339 if ( !OLEMenu_InstallHooks( GetCurrentThreadId() ) )
1342 else /* Want to uninstall dispatching code */
1344 /* Uninstall the hooks */
1345 if ( !OLEMenu_UnInstallHooks( GetCurrentThreadId() ) )
1348 /* Remove the menu descriptor property from the frame window */
1349 RemovePropA( hwndFrame
, "PROP_OLEMenuDescriptor" );
1355 /***********************************************************************
1356 * ReleaseStgMedium [OLE32.140]
1358 void WINAPI
ReleaseStgMedium(
1361 switch (pmedium
->tymed
)
1365 if ( (pmedium
->pUnkForRelease
==0) &&
1366 (pmedium
->u
.hGlobal
!=0) )
1367 GlobalFree(pmedium
->u
.hGlobal
);
1369 pmedium
->u
.hGlobal
= 0;
1374 if (pmedium
->u
.lpszFileName
!=0)
1376 if (pmedium
->pUnkForRelease
==0)
1378 DeleteFileW(pmedium
->u
.lpszFileName
);
1381 CoTaskMemFree(pmedium
->u
.lpszFileName
);
1384 pmedium
->u
.lpszFileName
= 0;
1389 if (pmedium
->u
.pstm
!=0)
1391 IStream_Release(pmedium
->u
.pstm
);
1394 pmedium
->u
.pstm
= 0;
1397 case TYMED_ISTORAGE
:
1399 if (pmedium
->u
.pstg
!=0)
1401 IStorage_Release(pmedium
->u
.pstg
);
1404 pmedium
->u
.pstg
= 0;
1409 if ( (pmedium
->pUnkForRelease
==0) &&
1410 (pmedium
->u
.hGlobal
!=0) )
1411 DeleteObject(pmedium
->u
.hGlobal
);
1413 pmedium
->u
.hGlobal
= 0;
1418 if ( (pmedium
->pUnkForRelease
==0) &&
1419 (pmedium
->u
.hMetaFilePict
!=0) )
1421 DeleteMetaFile(pmedium
->u
.hMetaFilePict
);
1422 GlobalFree(pmedium
->u
.hMetaFilePict
);
1425 pmedium
->u
.hMetaFilePict
= 0;
1430 if ( (pmedium
->pUnkForRelease
==0) &&
1431 (pmedium
->u
.hEnhMetaFile
!=0) )
1433 DeleteEnhMetaFile(pmedium
->u
.hEnhMetaFile
);
1436 pmedium
->u
.hEnhMetaFile
= 0;
1445 * After cleaning up, the unknown is released
1447 if (pmedium
->pUnkForRelease
!=0)
1449 IUnknown_Release(pmedium
->pUnkForRelease
);
1450 pmedium
->pUnkForRelease
= 0;
1455 * OLEDD_Initialize()
1457 * Initializes the OLE drag and drop data structures.
1459 static void OLEDD_Initialize()
1463 ZeroMemory (&wndClass
, sizeof(WNDCLASSA
));
1464 wndClass
.style
= CS_GLOBALCLASS
;
1465 wndClass
.lpfnWndProc
= (WNDPROC
)OLEDD_DragTrackerWindowProc
;
1466 wndClass
.cbClsExtra
= 0;
1467 wndClass
.cbWndExtra
= sizeof(TrackerWindowInfo
*);
1468 wndClass
.hCursor
= 0;
1469 wndClass
.hbrBackground
= 0;
1470 wndClass
.lpszClassName
= OLEDD_DRAGTRACKERCLASS
;
1472 RegisterClassA (&wndClass
);
1476 * OLEDD_UnInitialize()
1478 * Releases the OLE drag and drop data structures.
1480 static void OLEDD_UnInitialize()
1483 * Simply empty the list.
1485 while (targetListHead
!=NULL
)
1487 RevokeDragDrop(targetListHead
->hwndTarget
);
1492 * OLEDD_InsertDropTarget()
1494 * Insert the target node in the tree.
1496 static void OLEDD_InsertDropTarget(DropTargetNode
* nodeToAdd
)
1498 DropTargetNode
* curNode
;
1499 DropTargetNode
** parentNodeLink
;
1502 * Iterate the tree to find the insertion point.
1504 curNode
= targetListHead
;
1505 parentNodeLink
= &targetListHead
;
1507 while (curNode
!=NULL
)
1509 if (nodeToAdd
->hwndTarget
<curNode
->hwndTarget
)
1512 * If the node we want to add has a smaller HWND, go left
1514 parentNodeLink
= &curNode
->prevDropTarget
;
1515 curNode
= curNode
->prevDropTarget
;
1517 else if (nodeToAdd
->hwndTarget
>curNode
->hwndTarget
)
1520 * If the node we want to add has a larger HWND, go right
1522 parentNodeLink
= &curNode
->nextDropTarget
;
1523 curNode
= curNode
->nextDropTarget
;
1528 * The item was found in the list. It shouldn't have been there
1536 * If we get here, we have found a spot for our item. The parentNodeLink
1537 * pointer points to the pointer that we have to modify.
1538 * The curNode should be NULL. We just have to establish the link and Voila!
1540 assert(curNode
==NULL
);
1541 assert(parentNodeLink
!=NULL
);
1542 assert(*parentNodeLink
==NULL
);
1544 *parentNodeLink
=nodeToAdd
;
1548 * OLEDD_ExtractDropTarget()
1550 * Removes the target node from the tree.
1552 static DropTargetNode
* OLEDD_ExtractDropTarget(HWND hwndOfTarget
)
1554 DropTargetNode
* curNode
;
1555 DropTargetNode
** parentNodeLink
;
1558 * Iterate the tree to find the insertion point.
1560 curNode
= targetListHead
;
1561 parentNodeLink
= &targetListHead
;
1563 while (curNode
!=NULL
)
1565 if (hwndOfTarget
<curNode
->hwndTarget
)
1568 * If the node we want to add has a smaller HWND, go left
1570 parentNodeLink
= &curNode
->prevDropTarget
;
1571 curNode
= curNode
->prevDropTarget
;
1573 else if (hwndOfTarget
>curNode
->hwndTarget
)
1576 * If the node we want to add has a larger HWND, go right
1578 parentNodeLink
= &curNode
->nextDropTarget
;
1579 curNode
= curNode
->nextDropTarget
;
1584 * The item was found in the list. Detach it from it's parent and
1585 * re-insert it's kids in the tree.
1587 assert(parentNodeLink
!=NULL
);
1588 assert(*parentNodeLink
==curNode
);
1591 * We arbitrately re-attach the left sub-tree to the parent.
1593 *parentNodeLink
= curNode
->prevDropTarget
;
1596 * And we re-insert the right subtree
1598 if (curNode
->nextDropTarget
!=NULL
)
1600 OLEDD_InsertDropTarget(curNode
->nextDropTarget
);
1604 * The node we found is still a valid node once we complete
1605 * the unlinking of the kids.
1607 curNode
->nextDropTarget
=NULL
;
1608 curNode
->prevDropTarget
=NULL
;
1615 * If we get here, the node is not in the tree
1621 * OLEDD_FindDropTarget()
1623 * Finds information about the drop target.
1625 static DropTargetNode
* OLEDD_FindDropTarget(HWND hwndOfTarget
)
1627 DropTargetNode
* curNode
;
1630 * Iterate the tree to find the HWND value.
1632 curNode
= targetListHead
;
1634 while (curNode
!=NULL
)
1636 if (hwndOfTarget
<curNode
->hwndTarget
)
1639 * If the node we want to add has a smaller HWND, go left
1641 curNode
= curNode
->prevDropTarget
;
1643 else if (hwndOfTarget
>curNode
->hwndTarget
)
1646 * If the node we want to add has a larger HWND, go right
1648 curNode
= curNode
->nextDropTarget
;
1653 * The item was found in the list.
1660 * If we get here, the item is not in the list
1666 * OLEDD_DragTrackerWindowProc()
1668 * This method is the WindowProcedure of the drag n drop tracking
1669 * window. During a drag n Drop operation, an invisible window is created
1670 * to receive the user input and act upon it. This procedure is in charge
1673 static LRESULT WINAPI
OLEDD_DragTrackerWindowProc(
1683 LPCREATESTRUCTA createStruct
= (LPCREATESTRUCTA
)lParam
;
1685 SetWindowLongA(hwnd
, 0, (LONG
)createStruct
->lpCreateParams
);
1692 TrackerWindowInfo
* trackerInfo
= (TrackerWindowInfo
*)GetWindowLongA(hwnd
, 0);
1696 * Get the current mouse position in screen coordinates.
1698 mousePos
.x
= LOWORD(lParam
);
1699 mousePos
.y
= HIWORD(lParam
);
1700 ClientToScreen(hwnd
, &mousePos
);
1703 * Track the movement of the mouse.
1705 OLEDD_TrackMouseMove(trackerInfo
, mousePos
, wParam
);
1712 case WM_LBUTTONDOWN
:
1713 case WM_MBUTTONDOWN
:
1714 case WM_RBUTTONDOWN
:
1716 TrackerWindowInfo
* trackerInfo
= (TrackerWindowInfo
*)GetWindowLongA(hwnd
, 0);
1720 * Get the current mouse position in screen coordinates.
1722 mousePos
.x
= LOWORD(lParam
);
1723 mousePos
.y
= HIWORD(lParam
);
1724 ClientToScreen(hwnd
, &mousePos
);
1727 * Notify everyone that the button state changed
1728 * TODO: Check if the "escape" key was pressed.
1730 OLEDD_TrackStateChange(trackerInfo
, mousePos
, wParam
);
1737 * This is a window proc after all. Let's call the default.
1739 return DefWindowProcA (hwnd
, uMsg
, wParam
, lParam
);
1743 * OLEDD_TrackMouseMove()
1745 * This method is invoked while a drag and drop operation is in effect.
1746 * it will generate the appropriate callbacks in the drop source
1747 * and drop target. It will also provide the expected feedback to
1751 * trackerInfo - Pointer to the structure identifying the
1752 * drag & drop operation that is currently
1754 * mousePos - Current position of the mouse in screen
1756 * keyState - Contains the state of the shift keys and the
1757 * mouse buttons (MK_LBUTTON and the like)
1759 static void OLEDD_TrackMouseMove(
1760 TrackerWindowInfo
* trackerInfo
,
1764 HWND hwndNewTarget
= 0;
1768 * Get the handle of the window under the mouse
1770 hwndNewTarget
= WindowFromPoint(mousePos
);
1773 * Every time, we re-initialize the effects passed to the
1774 * IDropTarget to the effects allowed by the source.
1776 *trackerInfo
->pdwEffect
= trackerInfo
->dwOKEffect
;
1779 * If we are hovering over the same target as before, send the
1780 * DragOver notification
1782 if ( (trackerInfo
->curDragTarget
!= 0) &&
1783 (trackerInfo
->curDragTargetHWND
==hwndNewTarget
) )
1785 POINTL mousePosParam
;
1788 * The documentation tells me that the coordinate should be in the target
1789 * window's coordinate space. However, the tests I made tell me the
1790 * coordinates should be in screen coordinates.
1792 mousePosParam
.x
= mousePos
.x
;
1793 mousePosParam
.y
= mousePos
.y
;
1795 IDropTarget_DragOver(trackerInfo
->curDragTarget
,
1798 trackerInfo
->pdwEffect
);
1802 DropTargetNode
* newDropTargetNode
= 0;
1805 * If we changed window, we have to notify our old target and check for
1808 if (trackerInfo
->curDragTarget
!=0)
1810 IDropTarget_DragLeave(trackerInfo
->curDragTarget
);
1814 * Make sure we're hovering over a window.
1816 if (hwndNewTarget
!=0)
1819 * Find-out if there is a drag target under the mouse
1821 newDropTargetNode
= OLEDD_FindDropTarget(hwndNewTarget
);
1823 trackerInfo
->curDragTargetHWND
= hwndNewTarget
;
1824 trackerInfo
->curDragTarget
= newDropTargetNode
? newDropTargetNode
->dropTarget
: 0;
1827 * If there is, notify it that we just dragged-in
1829 if (trackerInfo
->curDragTarget
!=0)
1831 POINTL mousePosParam
;
1834 * The documentation tells me that the coordinate should be in the target
1835 * window's coordinate space. However, the tests I made tell me the
1836 * coordinates should be in screen coordinates.
1838 mousePosParam
.x
= mousePos
.x
;
1839 mousePosParam
.y
= mousePos
.y
;
1841 IDropTarget_DragEnter(trackerInfo
->curDragTarget
,
1842 trackerInfo
->dataObject
,
1845 trackerInfo
->pdwEffect
);
1851 * The mouse is not over a window so we don't track anything.
1853 trackerInfo
->curDragTargetHWND
= 0;
1854 trackerInfo
->curDragTarget
= 0;
1859 * Now that we have done that, we have to tell the source to give
1860 * us feedback on the work being done by the target. If we don't
1861 * have a target, simulate no effect.
1863 if (trackerInfo
->curDragTarget
==0)
1865 *trackerInfo
->pdwEffect
= DROPEFFECT_NONE
;
1868 hr
= IDropSource_GiveFeedback(trackerInfo
->dropSource
,
1869 *trackerInfo
->pdwEffect
);
1872 * When we ask for feedback from the drop source, sometimes it will
1873 * do all the necessary work and sometimes it will not handle it
1874 * when that's the case, we must display the standard drag and drop
1877 if (hr
==DRAGDROP_S_USEDEFAULTCURSORS
)
1879 if ( (*trackerInfo
->pdwEffect
& DROPEFFECT_MOVE
) ||
1880 (*trackerInfo
->pdwEffect
& DROPEFFECT_COPY
) ||
1881 (*trackerInfo
->pdwEffect
& DROPEFFECT_LINK
) )
1883 SetCursor(LoadCursorA(0, IDC_SIZEALLA
));
1887 SetCursor(LoadCursorA(0, IDC_NOA
));
1893 * OLEDD_TrackStateChange()
1895 * This method is invoked while a drag and drop operation is in effect.
1896 * It is used to notify the drop target/drop source callbacks when
1897 * the state of the keyboard or mouse button change.
1900 * trackerInfo - Pointer to the structure identifying the
1901 * drag & drop operation that is currently
1903 * mousePos - Current position of the mouse in screen
1905 * keyState - Contains the state of the shift keys and the
1906 * mouse buttons (MK_LBUTTON and the like)
1908 static void OLEDD_TrackStateChange(
1909 TrackerWindowInfo
* trackerInfo
,
1914 * Ask the drop source what to do with the operation.
1916 trackerInfo
->returnValue
= IDropSource_QueryContinueDrag(
1917 trackerInfo
->dropSource
,
1918 trackerInfo
->escPressed
,
1922 * All the return valued will stop the operation except the S_OK
1925 if (trackerInfo
->returnValue
!=S_OK
)
1928 * Make sure the message loop in DoDragDrop stops
1930 trackerInfo
->trackingDone
= TRUE
;
1933 * Release the mouse in case the drop target decides to show a popup
1934 * or a menu or something.
1939 * If we end-up over a target, drop the object in the target or
1940 * inform the target that the operation was cancelled.
1942 if (trackerInfo
->curDragTarget
!=0)
1944 switch (trackerInfo
->returnValue
)
1947 * If the source wants us to complete the operation, we tell
1948 * the drop target that we just dropped the object in it.
1950 case DRAGDROP_S_DROP
:
1952 POINTL mousePosParam
;
1955 * The documentation tells me that the coordinate should be
1956 * in the target window's coordinate space. However, the tests
1957 * I made tell me the coordinates should be in screen coordinates.
1959 mousePosParam
.x
= mousePos
.x
;
1960 mousePosParam
.y
= mousePos
.y
;
1962 IDropTarget_Drop(trackerInfo
->curDragTarget
,
1963 trackerInfo
->dataObject
,
1966 trackerInfo
->pdwEffect
);
1970 * If the source told us that we should cancel, fool the drop
1971 * target by telling it that the mouse left it's window.
1972 * Also set the drop effect to "NONE" in case the application
1973 * ignores the result of DoDragDrop.
1975 case DRAGDROP_S_CANCEL
:
1976 IDropTarget_DragLeave(trackerInfo
->curDragTarget
);
1977 *trackerInfo
->pdwEffect
= DROPEFFECT_NONE
;
1985 * OLEDD_GetButtonState()
1987 * This method will use the current state of the keyboard to build
1988 * a button state mask equivalent to the one passed in the
1989 * WM_MOUSEMOVE wParam.
1991 static DWORD
OLEDD_GetButtonState()
1993 BYTE keyboardState
[256];
1996 GetKeyboardState(keyboardState
);
1998 if ( (keyboardState
[VK_SHIFT
] & 0x80) !=0)
1999 keyMask
|= MK_SHIFT
;
2001 if ( (keyboardState
[VK_CONTROL
] & 0x80) !=0)
2002 keyMask
|= MK_CONTROL
;
2004 if ( (keyboardState
[VK_LBUTTON
] & 0x80) !=0)
2005 keyMask
|= MK_LBUTTON
;
2007 if ( (keyboardState
[VK_RBUTTON
] & 0x80) !=0)
2008 keyMask
|= MK_RBUTTON
;
2010 if ( (keyboardState
[VK_MBUTTON
] & 0x80) !=0)
2011 keyMask
|= MK_MBUTTON
;
2017 * OLEDD_GetButtonState()
2019 * This method will read the default value of the registry key in
2020 * parameter and extract a DWORD value from it. The registry key value
2021 * can be in a string key or a DWORD key.
2024 * regKey - Key to read the default value from
2025 * pdwValue - Pointer to the location where the DWORD
2026 * value is returned. This value is not modified
2027 * if the value is not found.
2030 static void OLEUTL_ReadRegistryDWORDValue(
2039 lres
= RegQueryValueExA(regKey
,
2046 if (lres
==ERROR_SUCCESS
)
2051 *pdwValue
= *(DWORD
*)buffer
;
2056 *pdwValue
= (DWORD
)strtoul(buffer
, NULL
, 10);
2062 /******************************************************************************
2063 * OleMetaFilePictFromIconAndLabel
2065 * Returns a global memory handle to a metafile which contains the icon and
2067 * I guess the result of that should look somehow like desktop icons.
2068 * If no hIcon is given, we load the icon via lpszSourceFile and iIconIndex.
2069 * This code might be wrong at some places.
2071 HGLOBAL16 WINAPI
OleMetaFilePictFromIconAndLabel16(
2073 LPCOLESTR16 lpszLabel
,
2074 LPCOLESTR16 lpszSourceFile
,
2081 FIXME("(%04x, '%s', '%s', %d): incorrect metrics, please try to correct them !\n\n\n", hIcon
, lpszLabel
, lpszSourceFile
, iIconIndex
);
2084 if (lpszSourceFile
) {
2085 HINSTANCE16 hInstance
= LoadLibrary16(lpszSourceFile
);
2087 /* load the icon at index from lpszSourceFile */
2088 hIcon
= (HICON16
)LoadIconA(hInstance
, (LPCSTR
)(DWORD
)iIconIndex
);
2089 FreeLibrary16(hInstance
);
2091 return (HGLOBAL
)NULL
;
2094 hdc
= CreateMetaFile16(NULL
);
2095 DrawIcon(hdc
, 0, 0, hIcon
); /* FIXME */
2096 TextOut16(hdc
, 0, 0, lpszLabel
, 1); /* FIXME */
2097 hmf
= GlobalAlloc16(0, sizeof(METAFILEPICT16
));
2098 mf
= (METAFILEPICT16
*)GlobalLock16(hmf
);
2099 mf
->mm
= MM_ANISOTROPIC
;
2100 mf
->xExt
= 20; /* FIXME: bogus */
2101 mf
->yExt
= 20; /* dito */
2102 mf
->hMF
= CloseMetaFile16(hdc
);