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 */
67 struct tagOleMenuHookItem *next;
70 static OleMenuHookItem *hook_list;
73 * This is the lock count on the OLE library. It is controlled by the
74 * OLEInitialize/OLEUninitialize methods.
76 static ULONG OLE_moduleLockCount = 0;
79 * Name of our registered window class.
81 static const char OLEDD_DRAGTRACKERCLASS[] = "WineDragDropTracker32";
84 * This is the head of the Drop target container.
86 static DropTargetNode* targetListHead = NULL;
88 /******************************************************************************
89 * These are the prototypes of miscelaneous utility methods
91 static void OLEUTL_ReadRegistryDWORDValue(HKEY regKey, DWORD* pdwValue);
93 /******************************************************************************
94 * These are the prototypes of the utility methods used to manage a shared menu
96 static void OLEMenu_Initialize();
97 static void OLEMenu_UnInitialize();
98 BOOL OLEMenu_InstallHooks( DWORD tid );
99 BOOL OLEMenu_UnInstallHooks( DWORD tid );
100 OleMenuHookItem * OLEMenu_IsHookInstalled( DWORD tid );
101 static BOOL OLEMenu_FindMainMenuIndex( HMENU hMainMenu, HMENU hPopupMenu, UINT *pnPos );
102 BOOL OLEMenu_SetIsServerMenu( HMENU hmenu, OleMenuDescriptor *pOleMenuDescriptor );
103 LRESULT CALLBACK OLEMenu_CallWndProc(INT code, WPARAM wParam, LPARAM lParam);
104 LRESULT CALLBACK OLEMenu_GetMsgProc(INT code, WPARAM wParam, LPARAM lParam);
106 /******************************************************************************
107 * These are the prototypes of the OLE Clipboard initialization methods (in clipboard.c)
109 void OLEClipbrd_UnInitialize();
110 void OLEClipbrd_Initialize();
112 /******************************************************************************
113 * These are the prototypes of the utility methods used for OLE Drag n Drop
115 static void OLEDD_Initialize();
116 static void OLEDD_UnInitialize();
117 static void OLEDD_InsertDropTarget(
118 DropTargetNode* nodeToAdd);
119 static DropTargetNode* OLEDD_ExtractDropTarget(
121 static DropTargetNode* OLEDD_FindDropTarget(
123 static LRESULT WINAPI OLEDD_DragTrackerWindowProc(
128 static void OLEDD_TrackMouseMove(
129 TrackerWindowInfo* trackerInfo,
132 static void OLEDD_TrackStateChange(
133 TrackerWindowInfo* trackerInfo,
136 static DWORD OLEDD_GetButtonState();
139 /******************************************************************************
140 * OleBuildVersion [OLE2.1]
142 DWORD WINAPI OleBuildVersion(void)
144 TRACE("Returning version %d, build %d.\n", rmm, rup);
145 return (rmm<<16)+rup;
148 /***********************************************************************
149 * OleInitialize (OLE2.2) (OLE32.108)
151 HRESULT WINAPI OleInitialize(LPVOID reserved)
155 TRACE("(%p)\n", reserved);
158 * The first duty of the OleInitialize is to initialize the COM libraries.
160 hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
163 * If the CoInitializeEx call failed, the OLE libraries can't be
170 * Then, it has to initialize the OLE specific modules.
174 * Object linking and Embedding
175 * In-place activation
177 if (OLE_moduleLockCount==0)
180 * Initialize the libraries.
182 TRACE("() - Initializing the OLE libraries\n");
187 OLEClipbrd_Initialize();
197 OLEMenu_Initialize();
201 * Then, we increase the lock count on the OLE module.
203 OLE_moduleLockCount++;
208 /******************************************************************************
209 * CoGetCurrentProcess [COMPOBJ.34] [OLE2.2][OLE32.108]
212 * Is DWORD really the correct return type for this function?
214 DWORD WINAPI CoGetCurrentProcess(void) {
215 return (DWORD)PROCESS_Current();
218 /******************************************************************************
219 * OleUninitialize [OLE2.3] [OLE32.131]
221 void WINAPI OleUninitialize(void)
226 * Decrease the lock count on the OLE module.
228 OLE_moduleLockCount--;
231 * If we hit the bottom of the lock stack, free the libraries.
233 if (OLE_moduleLockCount==0)
236 * Actually free the libraries.
238 TRACE("() - Freeing the last reference count\n");
243 OLEClipbrd_UnInitialize();
248 OLEDD_UnInitialize();
253 OLEMenu_UnInitialize();
257 * Then, uninitialize the COM libraries.
262 /******************************************************************************
263 * CoRegisterMessageFilter32 [OLE32.38]
265 HRESULT WINAPI CoRegisterMessageFilter(
266 LPMESSAGEFILTER lpMessageFilter, /* Pointer to interface */
267 LPMESSAGEFILTER *lplpMessageFilter /* Indirect pointer to prior instance if non-NULL */
270 if (lplpMessageFilter) {
271 *lplpMessageFilter = NULL;
276 /******************************************************************************
277 * OleInitializeWOW [OLE32.109]
279 HRESULT WINAPI OleInitializeWOW(DWORD x) {
280 FIXME("(0x%08lx),stub!\n",x);
284 /***********************************************************************
285 * RegisterDragDrop16 (OLE2.35)
287 HRESULT WINAPI RegisterDragDrop16(
289 LPDROPTARGET pDropTarget
291 FIXME("(0x%04x,%p),stub!\n",hwnd,pDropTarget);
295 /***********************************************************************
296 * RegisterDragDrop32 (OLE32.139)
298 HRESULT WINAPI RegisterDragDrop(
300 LPDROPTARGET pDropTarget)
302 DropTargetNode* dropTargetInfo;
304 TRACE("(0x%x,%p)\n", hwnd, pDropTarget);
307 * First, check if the window is already registered.
309 dropTargetInfo = OLEDD_FindDropTarget(hwnd);
311 if (dropTargetInfo!=NULL)
312 return DRAGDROP_E_ALREADYREGISTERED;
315 * If it's not there, we can add it. We first create a node for it.
317 dropTargetInfo = HeapAlloc(GetProcessHeap(), 0, sizeof(DropTargetNode));
319 if (dropTargetInfo==NULL)
320 return E_OUTOFMEMORY;
322 dropTargetInfo->hwndTarget = hwnd;
323 dropTargetInfo->prevDropTarget = NULL;
324 dropTargetInfo->nextDropTarget = NULL;
327 * Don't forget that this is an interface pointer, need to nail it down since
328 * we keep a copy of it.
330 dropTargetInfo->dropTarget = pDropTarget;
331 IDropTarget_AddRef(dropTargetInfo->dropTarget);
333 OLEDD_InsertDropTarget(dropTargetInfo);
338 /***********************************************************************
339 * RevokeDragDrop16 (OLE2.36)
341 HRESULT WINAPI RevokeDragDrop16(
344 FIXME("(0x%04x),stub!\n",hwnd);
348 /***********************************************************************
349 * RevokeDragDrop32 (OLE32.141)
351 HRESULT WINAPI RevokeDragDrop(
354 DropTargetNode* dropTargetInfo;
356 TRACE("(0x%x)\n", hwnd);
359 * First, check if the window is already registered.
361 dropTargetInfo = OLEDD_ExtractDropTarget(hwnd);
364 * If it ain't in there, it's an error.
366 if (dropTargetInfo==NULL)
367 return DRAGDROP_E_NOTREGISTERED;
370 * If it's in there, clean-up it's used memory and
373 IDropTarget_Release(dropTargetInfo->dropTarget);
374 HeapFree(GetProcessHeap(), 0, dropTargetInfo);
379 /***********************************************************************
380 * OleRegGetUserType (OLE32.122)
382 * This implementation of OleRegGetUserType ignores the dwFormOfType
383 * parameter and always returns the full name of the object. This is
384 * not too bad since this is the case for many objects because of the
385 * way they are registered.
387 HRESULT WINAPI OleRegGetUserType(
390 LPOLESTR* pszUserType)
400 * Initialize the out parameter.
405 * Build the key name we're looking for
407 WINE_StringFromCLSID((LPCLSID)clsid, xclsid);
409 strcpy(keyName, "CLSID\\");
410 strcat(keyName, xclsid);
411 strcat(keyName, "\\");
413 TRACE("(%s, %ld, %p)\n", keyName, dwFormOfType, pszUserType);
416 * Open the class id Key
418 hres = RegOpenKeyA(HKEY_CLASSES_ROOT,
422 if (hres != ERROR_SUCCESS)
423 return REGDB_E_CLASSNOTREG;
426 * Retrieve the size of the name string.
430 hres = RegQueryValueExA(clsidKey,
437 if (hres!=ERROR_SUCCESS)
439 RegCloseKey(clsidKey);
440 return REGDB_E_READREGDB;
444 * Allocate a buffer for the registry value.
446 *pszUserType = CoTaskMemAlloc(cbData);
448 if (*pszUserType==NULL)
450 RegCloseKey(clsidKey);
451 return E_OUTOFMEMORY;
454 hres = RegQueryValueExA(HKEY_CLASSES_ROOT,
458 (LPBYTE)*pszUserType,
461 RegCloseKey(clsidKey);
463 if (hres!=ERROR_SUCCESS)
465 CoTaskMemFree(*pszUserType);
468 return REGDB_E_READREGDB;
474 /***********************************************************************
475 * DoDragDrop32 [OLE32.65]
477 HRESULT WINAPI DoDragDrop (
478 IDataObject *pDataObject, /* ptr to the data obj */
479 IDropSource* pDropSource, /* ptr to the source obj */
480 DWORD dwOKEffect, /* effects allowed by the source */
481 DWORD *pdwEffect) /* ptr to effects of the source */
483 TrackerWindowInfo trackerInfo;
484 HWND hwndTrackWindow;
487 TRACE("(DataObject %p, DropSource %p)\n", pDataObject, pDropSource);
490 * Setup the drag n drop tracking window.
492 trackerInfo.dataObject = pDataObject;
493 trackerInfo.dropSource = pDropSource;
494 trackerInfo.dwOKEffect = dwOKEffect;
495 trackerInfo.pdwEffect = pdwEffect;
496 trackerInfo.trackingDone = FALSE;
497 trackerInfo.escPressed = FALSE;
498 trackerInfo.curDragTargetHWND = 0;
499 trackerInfo.curDragTarget = 0;
501 hwndTrackWindow = CreateWindowA(OLEDD_DRAGTRACKERCLASS,
504 CW_USEDEFAULT, CW_USEDEFAULT,
505 CW_USEDEFAULT, CW_USEDEFAULT,
509 (LPVOID)&trackerInfo);
511 if (hwndTrackWindow!=0)
514 * Capture the mouse input
516 SetCapture(hwndTrackWindow);
519 * Pump messages. All mouse input should go the the capture window.
521 while (!trackerInfo.trackingDone && GetMessageA(&msg, 0, 0, 0) )
523 if ( (msg.message >= WM_KEYFIRST) &&
524 (msg.message <= WM_KEYFIRST) )
527 * When keyboard messages are sent to windows on this thread, we
528 * want to ignore notify the drop source that the state changed.
529 * in the case of the Escape key, we also notify the drop source
530 * we give it a special meaning.
532 if ( (msg.message==WM_KEYDOWN) &&
533 (msg.wParam==VK_ESCAPE) )
535 trackerInfo.escPressed = TRUE;
539 * Notify the drop source.
541 OLEDD_TrackStateChange(&trackerInfo,
543 OLEDD_GetButtonState());
548 * Dispatch the messages only when it's not a keyboard message.
550 DispatchMessageA(&msg);
555 * Destroy the temporary window.
557 DestroyWindow(hwndTrackWindow);
559 return trackerInfo.returnValue;
565 /***********************************************************************
566 * OleQueryLinkFromData32 [OLE32.118]
568 HRESULT WINAPI OleQueryLinkFromData(
569 IDataObject* pSrcDataObject)
571 FIXME("(%p),stub!\n", pSrcDataObject);
575 /***********************************************************************
576 * OleRegGetMiscStatus [OLE32.121]
578 HRESULT WINAPI OleRegGetMiscStatus(
591 * Initialize the out parameter.
596 * Build the key name we're looking for
598 WINE_StringFromCLSID((LPCLSID)clsid, xclsid);
600 strcpy(keyName, "CLSID\\");
601 strcat(keyName, xclsid);
602 strcat(keyName, "\\");
604 TRACE("(%s, %ld, %p)\n", keyName, dwAspect, pdwStatus);
607 * Open the class id Key
609 result = RegOpenKeyA(HKEY_CLASSES_ROOT,
613 if (result != ERROR_SUCCESS)
614 return REGDB_E_CLASSNOTREG;
619 result = RegOpenKeyA(clsidKey,
624 if (result != ERROR_SUCCESS)
626 RegCloseKey(clsidKey);
627 return REGDB_E_READREGDB;
631 * Read the default value
633 OLEUTL_ReadRegistryDWORDValue(miscStatusKey, pdwStatus);
636 * Open the key specific to the requested aspect.
638 sprintf(keyName, "%ld", dwAspect);
640 result = RegOpenKeyA(miscStatusKey,
644 if (result == ERROR_SUCCESS)
646 OLEUTL_ReadRegistryDWORDValue(aspectKey, pdwStatus);
647 RegCloseKey(aspectKey);
653 RegCloseKey(miscStatusKey);
654 RegCloseKey(clsidKey);
659 /******************************************************************************
660 * OleSetContainedObject [OLE32.128]
662 HRESULT WINAPI OleSetContainedObject(
666 IRunnableObject* runnable = NULL;
669 TRACE("(%p,%x), stub!\n", pUnknown, fContained);
671 hres = IUnknown_QueryInterface(pUnknown,
672 &IID_IRunnableObject,
677 hres = IRunnableObject_SetContainedObject(runnable, fContained);
679 IRunnableObject_Release(runnable);
687 /******************************************************************************
688 * OleLoad [OLE32.112]
690 HRESULT WINAPI OleLoad(
693 LPOLECLIENTSITE pClientSite,
696 IPersistStorage* persistStorage = NULL;
697 IOleObject* oleObject = NULL;
701 TRACE("(%p,%p,%p,%p)\n", pStg, riid, pClientSite, ppvObj);
704 * TODO, Conversion ... OleDoAutoConvert
708 * Get the class ID for the object.
710 hres = IStorage_Stat(pStg, &storageInfo, STATFLAG_NONAME);
713 * Now, try and create the handler for the object
715 hres = CoCreateInstance(&storageInfo.clsid,
717 CLSCTX_INPROC_HANDLER,
722 * If that fails, as it will most times, load the default
727 hres = OleCreateDefaultHandler(&storageInfo.clsid,
734 * If we couldn't find a handler... this is bad. Abort the whole thing.
740 * Inform the new object of it's client site.
742 hres = IOleObject_SetClientSite(oleObject, pClientSite);
745 * Initialize the object with it's IPersistStorage interface.
747 hres = IOleObject_QueryInterface(oleObject,
748 &IID_IPersistStorage,
749 (void**)&persistStorage);
753 IPersistStorage_Load(persistStorage, pStg);
755 IPersistStorage_Release(persistStorage);
756 persistStorage = NULL;
760 * Return the requested interface to the caller.
762 hres = IOleObject_QueryInterface(oleObject, riid, ppvObj);
765 * Cleanup interfaces used internally
767 IOleObject_Release(oleObject);
772 /***********************************************************************
773 * OleSave [OLE32.124]
775 HRESULT WINAPI OleSave(
776 LPPERSISTSTORAGE pPS,
783 TRACE("(%p,%p,%x)\n", pPS, pStg, fSameAsLoad);
786 * First, we transfer the class ID (if available)
788 hres = IPersistStorage_GetClassID(pPS, &objectClass);
792 WriteClassStg(pStg, &objectClass);
796 * Then, we ask the object to save itself to the
797 * storage. If it is successful, we commit the storage.
799 hres = IPersistStorage_Save(pPS, pStg, fSameAsLoad);
803 IStorage_Commit(pStg,
811 /**************************************************************************
812 * Internal methods to manage the shared OLE menu in response to the
813 * OLE***MenuDescriptor API
817 * OLEMenu_Initialize()
819 * Initializes the OLEMENU data structures.
821 static void OLEMenu_Initialize()
826 * OLEMenu_UnInitialize()
828 * Releases the OLEMENU data structures.
830 static void OLEMenu_UnInitialize()
834 /*************************************************************************
835 * OLEMenu_InstallHooks
836 * Install thread scope message hooks for WH_GETMESSAGE and WH_CALLWNDPROC
838 * RETURNS: TRUE if message hooks were succesfully installed
841 BOOL OLEMenu_InstallHooks( DWORD tid )
843 OleMenuHookItem *pHookItem = NULL;
845 /* Create an entry for the hook table */
846 if ( !(pHookItem = HeapAlloc(GetProcessHeap(), 0,
847 sizeof(OleMenuHookItem)) ) )
850 pHookItem->tid = tid;
851 pHookItem->hHeap = GetProcessHeap();
853 /* Install a thread scope message hook for WH_GETMESSAGE */
854 pHookItem->GetMsg_hHook = SetWindowsHookExA( WH_GETMESSAGE, OLEMenu_GetMsgProc,
855 0, GetCurrentThreadId() );
856 if ( !pHookItem->GetMsg_hHook )
859 /* Install a thread scope message hook for WH_CALLWNDPROC */
860 pHookItem->CallWndProc_hHook = SetWindowsHookExA( WH_CALLWNDPROC, OLEMenu_CallWndProc,
861 0, GetCurrentThreadId() );
862 if ( !pHookItem->CallWndProc_hHook )
865 /* Insert the hook table entry */
866 pHookItem->next = hook_list;
867 hook_list = pHookItem;
872 /* Unhook any hooks */
873 if ( pHookItem->GetMsg_hHook )
874 UnhookWindowsHookEx( pHookItem->GetMsg_hHook );
875 if ( pHookItem->CallWndProc_hHook )
876 UnhookWindowsHookEx( pHookItem->CallWndProc_hHook );
877 /* Release the hook table entry */
878 HeapFree(pHookItem->hHeap, 0, pHookItem );
883 /*************************************************************************
884 * OLEMenu_UnInstallHooks
885 * UnInstall thread scope message hooks for WH_GETMESSAGE and WH_CALLWNDPROC
887 * RETURNS: TRUE if message hooks were succesfully installed
890 BOOL OLEMenu_UnInstallHooks( DWORD tid )
892 OleMenuHookItem *pHookItem = NULL;
893 OleMenuHookItem **ppHook = &hook_list;
897 if ((*ppHook)->tid == tid)
900 *ppHook = pHookItem->next;
903 ppHook = &(*ppHook)->next;
905 if (!pHookItem) return FALSE;
907 /* Uninstall the hooks installed for this thread */
908 if ( !UnhookWindowsHookEx( pHookItem->GetMsg_hHook ) )
910 if ( !UnhookWindowsHookEx( pHookItem->CallWndProc_hHook ) )
913 /* Release the hook table entry */
914 HeapFree(pHookItem->hHeap, 0, pHookItem );
919 /* Release the hook table entry */
921 HeapFree(pHookItem->hHeap, 0, pHookItem );
926 /*************************************************************************
927 * OLEMenu_IsHookInstalled
928 * Tests if OLEMenu hooks have been installed for a thread
930 * RETURNS: The pointer and index of the hook table entry for the tid
931 * NULL and -1 for the index if no hooks were installed for this thread
933 OleMenuHookItem * OLEMenu_IsHookInstalled( DWORD tid )
935 OleMenuHookItem *pHookItem = NULL;
937 /* Do a simple linear search for an entry whose tid matches ours.
938 * We really need a map but efficiency is not a concern here. */
939 for (pHookItem = hook_list; pHookItem; pHookItem = pHookItem->next)
941 if ( tid == pHookItem->tid )
948 /***********************************************************************
949 * OLEMenu_FindMainMenuIndex
951 * Used by OLEMenu API to find the top level group a menu item belongs to.
952 * On success pnPos contains the index of the item in the top level menu group
954 * RETURNS: TRUE if the ID was found, FALSE on failure
956 static BOOL OLEMenu_FindMainMenuIndex( HMENU hMainMenu, HMENU hPopupMenu, UINT *pnPos )
960 nItems = GetMenuItemCount( hMainMenu );
962 for (i = 0; i < nItems; i++)
966 /* Is the current item a submenu? */
967 if ( (hsubmenu = GetSubMenu(hMainMenu, i)) )
969 /* If the handle is the same we're done */
970 if ( hsubmenu == hPopupMenu )
976 /* Recursively search without updating pnPos */
977 else if ( OLEMenu_FindMainMenuIndex( hsubmenu, hPopupMenu, NULL ) )
989 /***********************************************************************
990 * OLEMenu_SetIsServerMenu
992 * Checks whether a popup menu belongs to a shared menu group which is
993 * owned by the server, and sets the menu descriptor state accordingly.
994 * All menu messages from these groups should be routed to the server.
996 * RETURNS: TRUE if the popup menu is part of a server owned group
997 * FASE if the popup menu is part of a container owned group
999 BOOL OLEMenu_SetIsServerMenu( HMENU hmenu, OleMenuDescriptor *pOleMenuDescriptor )
1001 UINT nPos = 0, nWidth, i;
1003 pOleMenuDescriptor->bIsServerItem = FALSE;
1005 /* Don't bother searching if the popup is the combined menu itself */
1006 if ( hmenu == pOleMenuDescriptor->hmenuCombined )
1009 /* Find the menu item index in the shared OLE menu that this item belongs to */
1010 if ( !OLEMenu_FindMainMenuIndex( pOleMenuDescriptor->hmenuCombined, hmenu, &nPos ) )
1013 /* The group widths array has counts for the number of elements
1014 * in the groups File, Edit, Container, Object, Window, Help.
1015 * The Edit, Object & Help groups belong to the server object
1016 * and the other three belong to the container.
1017 * Loop thru the group widths and locate the group we are a member of.
1019 for ( i = 0, nWidth = 0; i < 6; i++ )
1021 nWidth += pOleMenuDescriptor->mgw.width[i];
1022 if ( nPos < nWidth )
1024 /* Odd elements are server menu widths */
1025 pOleMenuDescriptor->bIsServerItem = (i%2) ? TRUE : FALSE;
1030 return pOleMenuDescriptor->bIsServerItem;
1033 /*************************************************************************
1034 * OLEMenu_CallWndProc
1035 * Thread scope WH_CALLWNDPROC hook proc filter function (callback)
1036 * This is invoked from a message hook installed in OleSetMenuDescriptor.
1038 LRESULT CALLBACK OLEMenu_CallWndProc(INT code, WPARAM wParam, LPARAM lParam)
1040 LPCWPSTRUCT pMsg = NULL;
1041 HOLEMENU hOleMenu = 0;
1042 OleMenuDescriptor *pOleMenuDescriptor = NULL;
1043 OleMenuHookItem *pHookItem = NULL;
1046 TRACE("%i, %04x, %08x\n", code, wParam, (unsigned)lParam );
1048 /* Check if we're being asked to process the message */
1049 if ( HC_ACTION != code )
1052 /* Retrieve the current message being dispatched from lParam */
1053 pMsg = (LPCWPSTRUCT)lParam;
1055 /* Check if the message is destined for a window we are interested in:
1056 * If the window has an OLEMenu property we may need to dispatch
1057 * the menu message to its active objects window instead. */
1059 hOleMenu = (HOLEMENU)GetPropA( pMsg->hwnd, "PROP_OLEMenuDescriptor" );
1063 /* Get the menu descriptor */
1064 pOleMenuDescriptor = (OleMenuDescriptor *) GlobalLock( hOleMenu );
1065 if ( !pOleMenuDescriptor ) /* Bad descriptor! */
1068 /* Process menu messages */
1069 switch( pMsg->message )
1073 /* Reset the menu descriptor state */
1074 pOleMenuDescriptor->bIsServerItem = FALSE;
1076 /* Send this message to the server as well */
1077 SendMessageA( pOleMenuDescriptor->hwndActiveObject,
1078 pMsg->message, pMsg->wParam, pMsg->lParam );
1082 case WM_INITMENUPOPUP:
1084 /* Save the state for whether this is a server owned menu */
1085 OLEMenu_SetIsServerMenu( (HMENU)pMsg->wParam, pOleMenuDescriptor );
1091 fuFlags = HIWORD(pMsg->wParam); /* Get flags */
1092 if ( fuFlags & MF_SYSMENU )
1095 /* Save the state for whether this is a server owned popup menu */
1096 else if ( fuFlags & MF_POPUP )
1097 OLEMenu_SetIsServerMenu( (HMENU)pMsg->lParam, pOleMenuDescriptor );
1104 LPDRAWITEMSTRUCT lpdis = (LPDRAWITEMSTRUCT) pMsg->lParam;
1105 if ( pMsg->wParam != 0 || lpdis->CtlType != ODT_MENU )
1106 goto NEXTHOOK; /* Not a menu message */
1115 /* If the message was for the server dispatch it accordingly */
1116 if ( pOleMenuDescriptor->bIsServerItem )
1118 SendMessageA( pOleMenuDescriptor->hwndActiveObject,
1119 pMsg->message, pMsg->wParam, pMsg->lParam );
1123 if ( pOleMenuDescriptor )
1124 GlobalUnlock( hOleMenu );
1126 /* Lookup the hook item for the current thread */
1127 if ( !( pHookItem = OLEMenu_IsHookInstalled( GetCurrentThreadId() ) ) )
1129 /* This should never fail!! */
1130 WARN("could not retrieve hHook for current thread!\n" );
1134 /* Pass on the message to the next hooker */
1135 return CallNextHookEx( pHookItem->CallWndProc_hHook, code, wParam, lParam );
1138 /*************************************************************************
1139 * OLEMenu_GetMsgProc
1140 * Thread scope WH_GETMESSAGE hook proc filter function (callback)
1141 * This is invoked from a message hook installed in OleSetMenuDescriptor.
1143 LRESULT CALLBACK OLEMenu_GetMsgProc(INT code, WPARAM wParam, LPARAM lParam)
1146 HOLEMENU hOleMenu = 0;
1147 OleMenuDescriptor *pOleMenuDescriptor = NULL;
1148 OleMenuHookItem *pHookItem = NULL;
1151 TRACE("%i, %04x, %08x\n", code, wParam, (unsigned)lParam );
1153 /* Check if we're being asked to process a messages */
1154 if ( HC_ACTION != code )
1157 /* Retrieve the current message being dispatched from lParam */
1158 pMsg = (LPMSG)lParam;
1160 /* Check if the message is destined for a window we are interested in:
1161 * If the window has an OLEMenu property we may need to dispatch
1162 * the menu message to its active objects window instead. */
1164 hOleMenu = (HOLEMENU)GetPropA( pMsg->hwnd, "PROP_OLEMenuDescriptor" );
1168 /* Process menu messages */
1169 switch( pMsg->message )
1173 wCode = HIWORD(pMsg->wParam); /* Get notification code */
1175 goto NEXTHOOK; /* Not a menu message */
1182 /* Get the menu descriptor */
1183 pOleMenuDescriptor = (OleMenuDescriptor *) GlobalLock( hOleMenu );
1184 if ( !pOleMenuDescriptor ) /* Bad descriptor! */
1187 /* If the message was for the server dispatch it accordingly */
1188 if ( pOleMenuDescriptor->bIsServerItem )
1190 /* Change the hWnd in the message to the active objects hWnd.
1191 * The message loop which reads this message will automatically
1192 * dispatch it to the embedded objects window. */
1193 pMsg->hwnd = pOleMenuDescriptor->hwndActiveObject;
1197 if ( pOleMenuDescriptor )
1198 GlobalUnlock( hOleMenu );
1200 /* Lookup the hook item for the current thread */
1201 if ( !( pHookItem = OLEMenu_IsHookInstalled( GetCurrentThreadId() ) ) )
1203 /* This should never fail!! */
1204 WARN("could not retrieve hHook for current thread!\n" );
1208 /* Pass on the message to the next hooker */
1209 return CallNextHookEx( pHookItem->GetMsg_hHook, code, wParam, lParam );
1212 /***********************************************************************
1213 * OleCreateMenuDescriptor [OLE32.97]
1214 * Creates an OLE menu descriptor for OLE to use when dispatching
1215 * menu messages and commands.
1218 * hmenuCombined - Handle to the objects combined menu
1219 * lpMenuWidths - Pointer to array of 6 LONG's indicating menus per group
1222 HOLEMENU WINAPI OleCreateMenuDescriptor(
1223 HMENU hmenuCombined,
1224 LPOLEMENUGROUPWIDTHS lpMenuWidths)
1227 OleMenuDescriptor *pOleMenuDescriptor;
1230 if ( !hmenuCombined || !lpMenuWidths )
1233 /* Create an OLE menu descriptor */
1234 if ( !(hOleMenu = GlobalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT,
1235 sizeof(OleMenuDescriptor) ) ) )
1238 pOleMenuDescriptor = (OleMenuDescriptor *) GlobalLock( hOleMenu );
1239 if ( !pOleMenuDescriptor )
1242 /* Initialize menu group widths and hmenu */
1243 for ( i = 0; i < 6; i++ )
1244 pOleMenuDescriptor->mgw.width[i] = lpMenuWidths->width[i];
1246 pOleMenuDescriptor->hmenuCombined = hmenuCombined;
1247 pOleMenuDescriptor->bIsServerItem = FALSE;
1248 GlobalUnlock( hOleMenu );
1253 /***********************************************************************
1254 * OleDestroyMenuDescriptor [OLE32.99]
1255 * Destroy the shared menu descriptor
1257 HRESULT WINAPI OleDestroyMenuDescriptor(
1258 HOLEMENU hmenuDescriptor)
1260 if ( hmenuDescriptor )
1261 GlobalFree( hmenuDescriptor );
1265 /***********************************************************************
1266 * OleSetMenuDescriptor [OLE32.129]
1267 * Installs or removes OLE dispatching code for the containers frame window
1268 * FIXME: The lpFrame and lpActiveObject parameters are currently ignored
1269 * OLE should install context sensitive help F1 filtering for the app when
1270 * these are non null.
1273 * hOleMenu Handle to composite menu descriptor
1274 * hwndFrame Handle to containers frame window
1275 * hwndActiveObject Handle to objects in-place activation window
1276 * lpFrame Pointer to IOleInPlaceFrame on containers window
1277 * lpActiveObject Pointer to IOleInPlaceActiveObject on active in-place object
1280 * S_OK - menu installed correctly
1281 * E_FAIL, E_INVALIDARG, E_UNEXPECTED - failure
1283 HRESULT WINAPI OleSetMenuDescriptor(
1286 HWND hwndActiveObject,
1287 LPOLEINPLACEFRAME lpFrame,
1288 LPOLEINPLACEACTIVEOBJECT lpActiveObject)
1290 OleMenuDescriptor *pOleMenuDescriptor = NULL;
1293 if ( !hwndFrame || (hOleMenu && !hwndActiveObject) )
1294 return E_INVALIDARG;
1296 if ( lpFrame || lpActiveObject )
1298 FIXME("(%x, %x, %x, %p, %p), Context sensitive help filtering not implemented!\n",
1299 (unsigned int)hOleMenu,
1306 /* Set up a message hook to intercept the containers frame window messages.
1307 * The message filter is responsible for dispatching menu messages from the
1308 * shared menu which are intended for the object.
1311 if ( hOleMenu ) /* Want to install dispatching code */
1313 /* If OLEMenu hooks are already installed for this thread, fail
1314 * Note: This effectively means that OleSetMenuDescriptor cannot
1315 * be called twice in succession on the same frame window
1316 * without first calling it with a null hOleMenu to uninstall */
1317 if ( OLEMenu_IsHookInstalled( GetCurrentThreadId() ) )
1320 /* Get the menu descriptor */
1321 pOleMenuDescriptor = (OleMenuDescriptor *) GlobalLock( hOleMenu );
1322 if ( !pOleMenuDescriptor )
1323 return E_UNEXPECTED;
1325 /* Update the menu descriptor */
1326 pOleMenuDescriptor->hwndFrame = hwndFrame;
1327 pOleMenuDescriptor->hwndActiveObject = hwndActiveObject;
1329 GlobalUnlock( hOleMenu );
1330 pOleMenuDescriptor = NULL;
1332 /* Add a menu descriptor windows property to the frame window */
1333 SetPropA( hwndFrame, "PROP_OLEMenuDescriptor", hOleMenu );
1335 /* Install thread scope message hooks for WH_GETMESSAGE and WH_CALLWNDPROC */
1336 if ( !OLEMenu_InstallHooks( GetCurrentThreadId() ) )
1339 else /* Want to uninstall dispatching code */
1341 /* Uninstall the hooks */
1342 if ( !OLEMenu_UnInstallHooks( GetCurrentThreadId() ) )
1345 /* Remove the menu descriptor property from the frame window */
1346 RemovePropA( hwndFrame, "PROP_OLEMenuDescriptor" );
1352 /***********************************************************************
1353 * ReleaseStgMedium [OLE32.140]
1355 void WINAPI ReleaseStgMedium(
1358 switch (pmedium->tymed)
1362 if ( (pmedium->pUnkForRelease==0) &&
1363 (pmedium->u.hGlobal!=0) )
1364 GlobalFree(pmedium->u.hGlobal);
1366 pmedium->u.hGlobal = 0;
1371 if (pmedium->u.lpszFileName!=0)
1373 if (pmedium->pUnkForRelease==0)
1375 DeleteFileW(pmedium->u.lpszFileName);
1378 CoTaskMemFree(pmedium->u.lpszFileName);
1381 pmedium->u.lpszFileName = 0;
1386 if (pmedium->u.pstm!=0)
1388 IStream_Release(pmedium->u.pstm);
1391 pmedium->u.pstm = 0;
1394 case TYMED_ISTORAGE:
1396 if (pmedium->u.pstg!=0)
1398 IStorage_Release(pmedium->u.pstg);
1401 pmedium->u.pstg = 0;
1406 if ( (pmedium->pUnkForRelease==0) &&
1407 (pmedium->u.hGlobal!=0) )
1408 DeleteObject(pmedium->u.hGlobal);
1410 pmedium->u.hGlobal = 0;
1415 if ( (pmedium->pUnkForRelease==0) &&
1416 (pmedium->u.hMetaFilePict!=0) )
1418 DeleteMetaFile(pmedium->u.hMetaFilePict);
1419 GlobalFree(pmedium->u.hMetaFilePict);
1422 pmedium->u.hMetaFilePict = 0;
1427 if ( (pmedium->pUnkForRelease==0) &&
1428 (pmedium->u.hEnhMetaFile!=0) )
1430 DeleteEnhMetaFile(pmedium->u.hEnhMetaFile);
1433 pmedium->u.hEnhMetaFile = 0;
1442 * After cleaning up, the unknown is released
1444 if (pmedium->pUnkForRelease!=0)
1446 IUnknown_Release(pmedium->pUnkForRelease);
1447 pmedium->pUnkForRelease = 0;
1452 * OLEDD_Initialize()
1454 * Initializes the OLE drag and drop data structures.
1456 static void OLEDD_Initialize()
1460 ZeroMemory (&wndClass, sizeof(WNDCLASSA));
1461 wndClass.style = CS_GLOBALCLASS;
1462 wndClass.lpfnWndProc = (WNDPROC)OLEDD_DragTrackerWindowProc;
1463 wndClass.cbClsExtra = 0;
1464 wndClass.cbWndExtra = sizeof(TrackerWindowInfo*);
1465 wndClass.hCursor = 0;
1466 wndClass.hbrBackground = 0;
1467 wndClass.lpszClassName = OLEDD_DRAGTRACKERCLASS;
1469 RegisterClassA (&wndClass);
1473 * OLEDD_UnInitialize()
1475 * Releases the OLE drag and drop data structures.
1477 static void OLEDD_UnInitialize()
1480 * Simply empty the list.
1482 while (targetListHead!=NULL)
1484 RevokeDragDrop(targetListHead->hwndTarget);
1489 * OLEDD_InsertDropTarget()
1491 * Insert the target node in the tree.
1493 static void OLEDD_InsertDropTarget(DropTargetNode* nodeToAdd)
1495 DropTargetNode* curNode;
1496 DropTargetNode** parentNodeLink;
1499 * Iterate the tree to find the insertion point.
1501 curNode = targetListHead;
1502 parentNodeLink = &targetListHead;
1504 while (curNode!=NULL)
1506 if (nodeToAdd->hwndTarget<curNode->hwndTarget)
1509 * If the node we want to add has a smaller HWND, go left
1511 parentNodeLink = &curNode->prevDropTarget;
1512 curNode = curNode->prevDropTarget;
1514 else if (nodeToAdd->hwndTarget>curNode->hwndTarget)
1517 * If the node we want to add has a larger HWND, go right
1519 parentNodeLink = &curNode->nextDropTarget;
1520 curNode = curNode->nextDropTarget;
1525 * The item was found in the list. It shouldn't have been there
1533 * If we get here, we have found a spot for our item. The parentNodeLink
1534 * pointer points to the pointer that we have to modify.
1535 * The curNode should be NULL. We just have to establish the link and Voila!
1537 assert(curNode==NULL);
1538 assert(parentNodeLink!=NULL);
1539 assert(*parentNodeLink==NULL);
1541 *parentNodeLink=nodeToAdd;
1545 * OLEDD_ExtractDropTarget()
1547 * Removes the target node from the tree.
1549 static DropTargetNode* OLEDD_ExtractDropTarget(HWND hwndOfTarget)
1551 DropTargetNode* curNode;
1552 DropTargetNode** parentNodeLink;
1555 * Iterate the tree to find the insertion point.
1557 curNode = targetListHead;
1558 parentNodeLink = &targetListHead;
1560 while (curNode!=NULL)
1562 if (hwndOfTarget<curNode->hwndTarget)
1565 * If the node we want to add has a smaller HWND, go left
1567 parentNodeLink = &curNode->prevDropTarget;
1568 curNode = curNode->prevDropTarget;
1570 else if (hwndOfTarget>curNode->hwndTarget)
1573 * If the node we want to add has a larger HWND, go right
1575 parentNodeLink = &curNode->nextDropTarget;
1576 curNode = curNode->nextDropTarget;
1581 * The item was found in the list. Detach it from it's parent and
1582 * re-insert it's kids in the tree.
1584 assert(parentNodeLink!=NULL);
1585 assert(*parentNodeLink==curNode);
1588 * We arbitrately re-attach the left sub-tree to the parent.
1590 *parentNodeLink = curNode->prevDropTarget;
1593 * And we re-insert the right subtree
1595 if (curNode->nextDropTarget!=NULL)
1597 OLEDD_InsertDropTarget(curNode->nextDropTarget);
1601 * The node we found is still a valid node once we complete
1602 * the unlinking of the kids.
1604 curNode->nextDropTarget=NULL;
1605 curNode->prevDropTarget=NULL;
1612 * If we get here, the node is not in the tree
1618 * OLEDD_FindDropTarget()
1620 * Finds information about the drop target.
1622 static DropTargetNode* OLEDD_FindDropTarget(HWND hwndOfTarget)
1624 DropTargetNode* curNode;
1627 * Iterate the tree to find the HWND value.
1629 curNode = targetListHead;
1631 while (curNode!=NULL)
1633 if (hwndOfTarget<curNode->hwndTarget)
1636 * If the node we want to add has a smaller HWND, go left
1638 curNode = curNode->prevDropTarget;
1640 else if (hwndOfTarget>curNode->hwndTarget)
1643 * If the node we want to add has a larger HWND, go right
1645 curNode = curNode->nextDropTarget;
1650 * The item was found in the list.
1657 * If we get here, the item is not in the list
1663 * OLEDD_DragTrackerWindowProc()
1665 * This method is the WindowProcedure of the drag n drop tracking
1666 * window. During a drag n Drop operation, an invisible window is created
1667 * to receive the user input and act upon it. This procedure is in charge
1670 static LRESULT WINAPI OLEDD_DragTrackerWindowProc(
1680 LPCREATESTRUCTA createStruct = (LPCREATESTRUCTA)lParam;
1682 SetWindowLongA(hwnd, 0, (LONG)createStruct->lpCreateParams);
1689 TrackerWindowInfo* trackerInfo = (TrackerWindowInfo*)GetWindowLongA(hwnd, 0);
1693 * Get the current mouse position in screen coordinates.
1695 mousePos.x = LOWORD(lParam);
1696 mousePos.y = HIWORD(lParam);
1697 ClientToScreen(hwnd, &mousePos);
1700 * Track the movement of the mouse.
1702 OLEDD_TrackMouseMove(trackerInfo, mousePos, wParam);
1709 case WM_LBUTTONDOWN:
1710 case WM_MBUTTONDOWN:
1711 case WM_RBUTTONDOWN:
1713 TrackerWindowInfo* trackerInfo = (TrackerWindowInfo*)GetWindowLongA(hwnd, 0);
1717 * Get the current mouse position in screen coordinates.
1719 mousePos.x = LOWORD(lParam);
1720 mousePos.y = HIWORD(lParam);
1721 ClientToScreen(hwnd, &mousePos);
1724 * Notify everyone that the button state changed
1725 * TODO: Check if the "escape" key was pressed.
1727 OLEDD_TrackStateChange(trackerInfo, mousePos, wParam);
1734 * This is a window proc after all. Let's call the default.
1736 return DefWindowProcA (hwnd, uMsg, wParam, lParam);
1740 * OLEDD_TrackMouseMove()
1742 * This method is invoked while a drag and drop operation is in effect.
1743 * it will generate the appropriate callbacks in the drop source
1744 * and drop target. It will also provide the expected feedback to
1748 * trackerInfo - Pointer to the structure identifying the
1749 * drag & drop operation that is currently
1751 * mousePos - Current position of the mouse in screen
1753 * keyState - Contains the state of the shift keys and the
1754 * mouse buttons (MK_LBUTTON and the like)
1756 static void OLEDD_TrackMouseMove(
1757 TrackerWindowInfo* trackerInfo,
1761 HWND hwndNewTarget = 0;
1765 * Get the handle of the window under the mouse
1767 hwndNewTarget = WindowFromPoint(mousePos);
1770 * Every time, we re-initialize the effects passed to the
1771 * IDropTarget to the effects allowed by the source.
1773 *trackerInfo->pdwEffect = trackerInfo->dwOKEffect;
1776 * If we are hovering over the same target as before, send the
1777 * DragOver notification
1779 if ( (trackerInfo->curDragTarget != 0) &&
1780 (trackerInfo->curDragTargetHWND==hwndNewTarget) )
1782 POINTL mousePosParam;
1785 * The documentation tells me that the coordinate should be in the target
1786 * window's coordinate space. However, the tests I made tell me the
1787 * coordinates should be in screen coordinates.
1789 mousePosParam.x = mousePos.x;
1790 mousePosParam.y = mousePos.y;
1792 IDropTarget_DragOver(trackerInfo->curDragTarget,
1795 trackerInfo->pdwEffect);
1799 DropTargetNode* newDropTargetNode = 0;
1802 * If we changed window, we have to notify our old target and check for
1805 if (trackerInfo->curDragTarget!=0)
1807 IDropTarget_DragLeave(trackerInfo->curDragTarget);
1811 * Make sure we're hovering over a window.
1813 if (hwndNewTarget!=0)
1816 * Find-out if there is a drag target under the mouse
1818 newDropTargetNode = OLEDD_FindDropTarget(hwndNewTarget);
1820 trackerInfo->curDragTargetHWND = hwndNewTarget;
1821 trackerInfo->curDragTarget = newDropTargetNode ? newDropTargetNode->dropTarget : 0;
1824 * If there is, notify it that we just dragged-in
1826 if (trackerInfo->curDragTarget!=0)
1828 POINTL mousePosParam;
1831 * The documentation tells me that the coordinate should be in the target
1832 * window's coordinate space. However, the tests I made tell me the
1833 * coordinates should be in screen coordinates.
1835 mousePosParam.x = mousePos.x;
1836 mousePosParam.y = mousePos.y;
1838 IDropTarget_DragEnter(trackerInfo->curDragTarget,
1839 trackerInfo->dataObject,
1842 trackerInfo->pdwEffect);
1848 * The mouse is not over a window so we don't track anything.
1850 trackerInfo->curDragTargetHWND = 0;
1851 trackerInfo->curDragTarget = 0;
1856 * Now that we have done that, we have to tell the source to give
1857 * us feedback on the work being done by the target. If we don't
1858 * have a target, simulate no effect.
1860 if (trackerInfo->curDragTarget==0)
1862 *trackerInfo->pdwEffect = DROPEFFECT_NONE;
1865 hr = IDropSource_GiveFeedback(trackerInfo->dropSource,
1866 *trackerInfo->pdwEffect);
1869 * When we ask for feedback from the drop source, sometimes it will
1870 * do all the necessary work and sometimes it will not handle it
1871 * when that's the case, we must display the standard drag and drop
1874 if (hr==DRAGDROP_S_USEDEFAULTCURSORS)
1876 if ( (*trackerInfo->pdwEffect & DROPEFFECT_MOVE) ||
1877 (*trackerInfo->pdwEffect & DROPEFFECT_COPY) ||
1878 (*trackerInfo->pdwEffect & DROPEFFECT_LINK) )
1880 SetCursor(LoadCursorA(0, IDC_SIZEALLA));
1884 SetCursor(LoadCursorA(0, IDC_NOA));
1890 * OLEDD_TrackStateChange()
1892 * This method is invoked while a drag and drop operation is in effect.
1893 * It is used to notify the drop target/drop source callbacks when
1894 * the state of the keyboard or mouse button change.
1897 * trackerInfo - Pointer to the structure identifying the
1898 * drag & drop operation that is currently
1900 * mousePos - Current position of the mouse in screen
1902 * keyState - Contains the state of the shift keys and the
1903 * mouse buttons (MK_LBUTTON and the like)
1905 static void OLEDD_TrackStateChange(
1906 TrackerWindowInfo* trackerInfo,
1911 * Ask the drop source what to do with the operation.
1913 trackerInfo->returnValue = IDropSource_QueryContinueDrag(
1914 trackerInfo->dropSource,
1915 trackerInfo->escPressed,
1919 * All the return valued will stop the operation except the S_OK
1922 if (trackerInfo->returnValue!=S_OK)
1925 * Make sure the message loop in DoDragDrop stops
1927 trackerInfo->trackingDone = TRUE;
1930 * Release the mouse in case the drop target decides to show a popup
1931 * or a menu or something.
1936 * If we end-up over a target, drop the object in the target or
1937 * inform the target that the operation was cancelled.
1939 if (trackerInfo->curDragTarget!=0)
1941 switch (trackerInfo->returnValue)
1944 * If the source wants us to complete the operation, we tell
1945 * the drop target that we just dropped the object in it.
1947 case DRAGDROP_S_DROP:
1949 POINTL mousePosParam;
1952 * The documentation tells me that the coordinate should be
1953 * in the target window's coordinate space. However, the tests
1954 * I made tell me the coordinates should be in screen coordinates.
1956 mousePosParam.x = mousePos.x;
1957 mousePosParam.y = mousePos.y;
1959 IDropTarget_Drop(trackerInfo->curDragTarget,
1960 trackerInfo->dataObject,
1963 trackerInfo->pdwEffect);
1967 * If the source told us that we should cancel, fool the drop
1968 * target by telling it that the mouse left it's window.
1969 * Also set the drop effect to "NONE" in case the application
1970 * ignores the result of DoDragDrop.
1972 case DRAGDROP_S_CANCEL:
1973 IDropTarget_DragLeave(trackerInfo->curDragTarget);
1974 *trackerInfo->pdwEffect = DROPEFFECT_NONE;
1982 * OLEDD_GetButtonState()
1984 * This method will use the current state of the keyboard to build
1985 * a button state mask equivalent to the one passed in the
1986 * WM_MOUSEMOVE wParam.
1988 static DWORD OLEDD_GetButtonState()
1990 BYTE keyboardState[256];
1993 GetKeyboardState(keyboardState);
1995 if ( (keyboardState[VK_SHIFT] & 0x80) !=0)
1996 keyMask |= MK_SHIFT;
1998 if ( (keyboardState[VK_CONTROL] & 0x80) !=0)
1999 keyMask |= MK_CONTROL;
2001 if ( (keyboardState[VK_LBUTTON] & 0x80) !=0)
2002 keyMask |= MK_LBUTTON;
2004 if ( (keyboardState[VK_RBUTTON] & 0x80) !=0)
2005 keyMask |= MK_RBUTTON;
2007 if ( (keyboardState[VK_MBUTTON] & 0x80) !=0)
2008 keyMask |= MK_MBUTTON;
2014 * OLEDD_GetButtonState()
2016 * This method will read the default value of the registry key in
2017 * parameter and extract a DWORD value from it. The registry key value
2018 * can be in a string key or a DWORD key.
2021 * regKey - Key to read the default value from
2022 * pdwValue - Pointer to the location where the DWORD
2023 * value is returned. This value is not modified
2024 * if the value is not found.
2027 static void OLEUTL_ReadRegistryDWORDValue(
2036 lres = RegQueryValueExA(regKey,
2043 if (lres==ERROR_SUCCESS)
2048 *pdwValue = *(DWORD*)buffer;
2053 *pdwValue = (DWORD)strtoul(buffer, NULL, 10);
2059 /******************************************************************************
2060 * OleMetaFilePictFromIconAndLabel
2062 * Returns a global memory handle to a metafile which contains the icon and
2064 * I guess the result of that should look somehow like desktop icons.
2065 * If no hIcon is given, we load the icon via lpszSourceFile and iIconIndex.
2066 * This code might be wrong at some places.
2068 HGLOBAL16 WINAPI OleMetaFilePictFromIconAndLabel16(
2070 LPCOLESTR16 lpszLabel,
2071 LPCOLESTR16 lpszSourceFile,
2078 FIXME("(%04x, '%s', '%s', %d): incorrect metrics, please try to correct them !\n\n\n", hIcon, lpszLabel, lpszSourceFile, iIconIndex);
2081 if (lpszSourceFile) {
2082 HINSTANCE16 hInstance = LoadLibrary16(lpszSourceFile);
2084 /* load the icon at index from lpszSourceFile */
2085 hIcon = (HICON16)LoadIconA(hInstance, (LPCSTR)(DWORD)iIconIndex);
2086 FreeLibrary16(hInstance);
2088 return (HGLOBAL)NULL;
2091 hdc = CreateMetaFile16(NULL);
2092 DrawIcon(hdc, 0, 0, hIcon); /* FIXME */
2093 TextOut16(hdc, 0, 0, lpszLabel, 1); /* FIXME */
2094 hmf = GlobalAlloc16(0, sizeof(METAFILEPICT16));
2095 mf = (METAFILEPICT16 *)GlobalLock16(hmf);
2096 mf->mm = MM_ANISOTROPIC;
2097 mf->xExt = 20; /* FIXME: bogus */
2098 mf->yExt = 20; /* dito */
2099 mf->hMF = CloseMetaFile16(hdc);