source: trunk/src/ole32/ole2.c@ 8441

Last change on this file since 8441 was 8441, checked in by sandervl, 23 years ago

Wine resync

File size: 57.9 KB
Line 
1
2/*
3 * OLE2 library
4 *
5 * Copyright 1995 Martin von Loewis
6 * Copyright 1999 Francis Beaudet
7 * Copyright 1999 Noel Borthwick
8 *
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
13 *
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 */
23
24#include "config.h"
25
26#include <assert.h>
27#include <stdlib.h>
28#include <stdio.h>
29#include <string.h>
30
31#include "commctrl.h"
32#include "ole2.h"
33#include "ole2ver.h"
34#include "windef.h"
35#include "winbase.h"
36#include "winerror.h"
37#include "winuser.h"
38#include "winreg.h"
39
40#include "wine/obj_clientserver.h"
41#include "wine/winbase16.h"
42#include "wine/wingdi16.h"
43#include "wine/winuser16.h"
44#include "ole32_main.h"
45
46#include "wine/debug.h"
47
48WINE_DEFAULT_DEBUG_CHANNEL(ole);
49WINE_DECLARE_DEBUG_CHANNEL(accel);
50
51/******************************************************************************
52 * These are static/global variables and internal data structures that the
53 * OLE module uses to maintain it's state.
54 */
55typedef struct tagDropTargetNode
56{
57 HWND hwndTarget;
58 IDropTarget* dropTarget;
59 struct tagDropTargetNode* prevDropTarget;
60 struct tagDropTargetNode* nextDropTarget;
61} DropTargetNode;
62
63typedef struct tagTrackerWindowInfo
64{
65 IDataObject* dataObject;
66 IDropSource* dropSource;
67 DWORD dwOKEffect;
68 DWORD* pdwEffect;
69 BOOL trackingDone;
70 HRESULT returnValue;
71
72 BOOL escPressed;
73 HWND curDragTargetHWND;
74 IDropTarget* curDragTarget;
75} TrackerWindowInfo;
76
77typedef struct tagOleMenuDescriptor /* OleMenuDescriptor */
78{
79 HWND hwndFrame; /* The containers frame window */
80 HWND hwndActiveObject; /* The active objects window */
81 OLEMENUGROUPWIDTHS mgw; /* OLE menu group widths for the shared menu */
82 HMENU hmenuCombined; /* The combined menu */
83 BOOL bIsServerItem; /* True if the currently open popup belongs to the server */
84} OleMenuDescriptor;
85
86typedef struct tagOleMenuHookItem /* OleMenu hook item in per thread hook list */
87{
88 DWORD tid; /* Thread Id */
89 HANDLE hHeap; /* Heap this is allocated from */
90 HHOOK GetMsg_hHook; /* message hook for WH_GETMESSAGE */
91 HHOOK CallWndProc_hHook; /* message hook for WH_CALLWNDPROC */
92 struct tagOleMenuHookItem *next;
93} OleMenuHookItem;
94
95static OleMenuHookItem *hook_list;
96
97/*
98 * This is the lock count on the OLE library. It is controlled by the
99 * OLEInitialize/OLEUninitialize methods.
100 */
101static ULONG OLE_moduleLockCount = 0;
102
103/*
104 * Name of our registered window class.
105 */
106static const char OLEDD_DRAGTRACKERCLASS[] = "WineDragDropTracker32";
107
108/*
109 * This is the head of the Drop target container.
110 */
111static DropTargetNode* targetListHead = NULL;
112
113/******************************************************************************
114 * These are the prototypes of miscelaneous utility methods
115 */
116static void OLEUTL_ReadRegistryDWORDValue(HKEY regKey, DWORD* pdwValue);
117
118/******************************************************************************
119 * These are the prototypes of the utility methods used to manage a shared menu
120 */
121static void OLEMenu_Initialize();
122static void OLEMenu_UnInitialize();
123BOOL OLEMenu_InstallHooks( DWORD tid );
124BOOL OLEMenu_UnInstallHooks( DWORD tid );
125OleMenuHookItem * OLEMenu_IsHookInstalled( DWORD tid );
126static BOOL OLEMenu_FindMainMenuIndex( HMENU hMainMenu, HMENU hPopupMenu, UINT *pnPos );
127BOOL OLEMenu_SetIsServerMenu( HMENU hmenu, OleMenuDescriptor *pOleMenuDescriptor );
128LRESULT CALLBACK OLEMenu_CallWndProc(INT code, WPARAM wParam, LPARAM lParam);
129LRESULT CALLBACK OLEMenu_GetMsgProc(INT code, WPARAM wParam, LPARAM lParam);
130
131/******************************************************************************
132 * These are the prototypes of the OLE Clipboard initialization methods (in clipboard.c)
133 */
134void OLEClipbrd_UnInitialize();
135void OLEClipbrd_Initialize();
136
137/******************************************************************************
138 * These are the prototypes of the utility methods used for OLE Drag n Drop
139 */
140static void OLEDD_Initialize();
141static void OLEDD_UnInitialize();
142static void OLEDD_InsertDropTarget(
143 DropTargetNode* nodeToAdd);
144static DropTargetNode* OLEDD_ExtractDropTarget(
145 HWND hwndOfTarget);
146static DropTargetNode* OLEDD_FindDropTarget(
147 HWND hwndOfTarget);
148static LRESULT WINAPI OLEDD_DragTrackerWindowProc(
149 HWND hwnd,
150 UINT uMsg,
151 WPARAM wParam,
152 LPARAM lParam);
153static void OLEDD_TrackMouseMove(
154 TrackerWindowInfo* trackerInfo,
155 POINT mousePos,
156 DWORD keyState);
157static void OLEDD_TrackStateChange(
158 TrackerWindowInfo* trackerInfo,
159 POINT mousePos,
160 DWORD keyState);
161static DWORD OLEDD_GetButtonState();
162
163
164/******************************************************************************
165 * OleBuildVersion [OLE2.1]
166 * OleBuildVersion [OLE32.84]
167 */
168DWORD WINAPI OleBuildVersion(void)
169{
170 TRACE("Returning version %d, build %d.\n", rmm, rup);
171 return (rmm<<16)+rup;
172}
173
174/***********************************************************************
175 * OleInitialize (OLE2.2)
176 * OleInitialize (OLE32.108)
177 */
178HRESULT WINAPI OleInitialize(LPVOID reserved)
179{
180 HRESULT hr;
181
182 TRACE("(%p)\n", reserved);
183
184 /*
185 * The first duty of the OleInitialize is to initialize the COM libraries.
186 */
187 hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
188
189 /*
190 * If the CoInitializeEx call failed, the OLE libraries can't be
191 * initialized.
192 */
193 if (FAILED(hr))
194 return hr;
195
196 /*
197 * Then, it has to initialize the OLE specific modules.
198 * This includes:
199 * Clipboard
200 * Drag and Drop
201 * Object linking and Embedding
202 * In-place activation
203 */
204 if (OLE_moduleLockCount==0)
205 {
206 /*
207 * Initialize the libraries.
208 */
209 TRACE("() - Initializing the OLE libraries\n");
210
211 /*
212 * OLE Clipboard
213 */
214 OLEClipbrd_Initialize();
215
216 /*
217 * Drag and Drop
218 */
219 OLEDD_Initialize();
220
221 /*
222 * OLE shared menu
223 */
224 OLEMenu_Initialize();
225 }
226
227 /*
228 * Then, we increase the lock count on the OLE module.
229 */
230 OLE_moduleLockCount++;
231
232 return hr;
233}
234
235/******************************************************************************
236 * CoGetCurrentProcess [COMPOBJ.34]
237 * CoGetCurrentProcess [OLE32.18]
238 *
239 * NOTES
240 * Is DWORD really the correct return type for this function?
241 */
242DWORD WINAPI CoGetCurrentProcess(void)
243{
244 return GetCurrentProcessId();
245}
246
247/******************************************************************************
248 * OleUninitialize [OLE2.3]
249 * OleUninitialize [OLE32.131]
250 */
251void WINAPI OleUninitialize(void)
252{
253 TRACE("()\n");
254
255 /*
256 * Decrease the lock count on the OLE module.
257 */
258 OLE_moduleLockCount--;
259
260 /*
261 * If we hit the bottom of the lock stack, free the libraries.
262 */
263 if (OLE_moduleLockCount==0)
264 {
265 /*
266 * Actually free the libraries.
267 */
268 TRACE("() - Freeing the last reference count\n");
269
270 /*
271 * OLE Clipboard
272 */
273 OLEClipbrd_UnInitialize();
274
275 /*
276 * Drag and Drop
277 */
278 OLEDD_UnInitialize();
279
280 /*
281 * OLE shared menu
282 */
283 OLEMenu_UnInitialize();
284 }
285
286 /*
287 * Then, uninitialize the COM libraries.
288 */
289 CoUninitialize();
290}
291
292/******************************************************************************
293 * CoRegisterMessageFilter [OLE32.38]
294 */
295HRESULT WINAPI CoRegisterMessageFilter(
296 LPMESSAGEFILTER lpMessageFilter, /* [in] Pointer to interface */
297 LPMESSAGEFILTER *lplpMessageFilter /* [out] Indirect pointer to prior instance if non-NULL */
298) {
299 FIXME("stub\n");
300 if (lplpMessageFilter) {
301 *lplpMessageFilter = NULL;
302 }
303 return S_OK;
304}
305
306/******************************************************************************
307 * OleInitializeWOW [OLE32.109]
308 */
309HRESULT WINAPI OleInitializeWOW(DWORD x) {
310 FIXME("(0x%08lx),stub!\n",x);
311 return 0;
312}
313
314/***********************************************************************
315 * RegisterDragDrop (OLE2.35)
316 */
317HRESULT WINAPI RegisterDragDrop16(
318 HWND16 hwnd,
319 LPDROPTARGET pDropTarget
320) {
321 FIXME("(0x%04x,%p),stub!\n",hwnd,pDropTarget);
322 return S_OK;
323}
324
325/***********************************************************************
326 * RegisterDragDrop (OLE32.139)
327 */
328HRESULT WINAPI RegisterDragDrop(
329 HWND hwnd,
330 LPDROPTARGET pDropTarget)
331{
332 DropTargetNode* dropTargetInfo;
333
334 TRACE("(0x%x,%p)\n", hwnd, pDropTarget);
335
336 /*
337 * First, check if the window is already registered.
338 */
339 dropTargetInfo = OLEDD_FindDropTarget(hwnd);
340
341 if (dropTargetInfo!=NULL)
342 return DRAGDROP_E_ALREADYREGISTERED;
343
344 /*
345 * If it's not there, we can add it. We first create a node for it.
346 */
347 dropTargetInfo = HeapAlloc(GetProcessHeap(), 0, sizeof(DropTargetNode));
348
349 if (dropTargetInfo==NULL)
350 return E_OUTOFMEMORY;
351
352 dropTargetInfo->hwndTarget = hwnd;
353 dropTargetInfo->prevDropTarget = NULL;
354 dropTargetInfo->nextDropTarget = NULL;
355
356 /*
357 * Don't forget that this is an interface pointer, need to nail it down since
358 * we keep a copy of it.
359 */
360 dropTargetInfo->dropTarget = pDropTarget;
361 IDropTarget_AddRef(dropTargetInfo->dropTarget);
362
363 OLEDD_InsertDropTarget(dropTargetInfo);
364
365 return S_OK;
366}
367
368/***********************************************************************
369 * RevokeDragDrop (OLE2.36)
370 */
371HRESULT WINAPI RevokeDragDrop16(
372 HWND16 hwnd
373) {
374 FIXME("(0x%04x),stub!\n",hwnd);
375 return S_OK;
376}
377
378/***********************************************************************
379 * RevokeDragDrop (OLE32.141)
380 */
381HRESULT WINAPI RevokeDragDrop(
382 HWND hwnd)
383{
384 DropTargetNode* dropTargetInfo;
385
386 TRACE("(0x%x)\n", hwnd);
387
388 /*
389 * First, check if the window is already registered.
390 */
391 dropTargetInfo = OLEDD_ExtractDropTarget(hwnd);
392
393 /*
394 * If it ain't in there, it's an error.
395 */
396 if (dropTargetInfo==NULL)
397 return DRAGDROP_E_NOTREGISTERED;
398
399 /*
400 * If it's in there, clean-up it's used memory and
401 * references
402 */
403 IDropTarget_Release(dropTargetInfo->dropTarget);
404 HeapFree(GetProcessHeap(), 0, dropTargetInfo);
405
406 return S_OK;
407}
408
409/***********************************************************************
410 * OleRegGetUserType (OLE32.122)
411 *
412 * This implementation of OleRegGetUserType ignores the dwFormOfType
413 * parameter and always returns the full name of the object. This is
414 * not too bad since this is the case for many objects because of the
415 * way they are registered.
416 */
417HRESULT WINAPI OleRegGetUserType(
418 REFCLSID clsid,
419 DWORD dwFormOfType,
420 LPOLESTR* pszUserType)
421{
422 char keyName[60];
423 DWORD dwKeyType;
424 DWORD cbData;
425 HKEY clsidKey;
426 LONG hres;
427 LPBYTE buffer;
428 HRESULT retVal;
429 /*
430 * Initialize the out parameter.
431 */
432 *pszUserType = NULL;
433
434 /*
435 * Build the key name we're looking for
436 */
437 sprintf( keyName, "CLSID\\{%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}\\",
438 clsid->Data1, clsid->Data2, clsid->Data3,
439 clsid->Data4[0], clsid->Data4[1], clsid->Data4[2], clsid->Data4[3],
440 clsid->Data4[4], clsid->Data4[5], clsid->Data4[6], clsid->Data4[7] );
441
442 TRACE("(%s, %ld, %p)\n", keyName, dwFormOfType, pszUserType);
443
444 /*
445 * Open the class id Key
446 */
447 hres = RegOpenKeyA(HKEY_CLASSES_ROOT,
448 keyName,
449 &clsidKey);
450
451 if (hres != ERROR_SUCCESS)
452 return REGDB_E_CLASSNOTREG;
453
454 /*
455 * Retrieve the size of the name string.
456 */
457 cbData = 0;
458
459 hres = RegQueryValueExA(clsidKey,
460 "",
461 NULL,
462 &dwKeyType,
463 NULL,
464 &cbData);
465
466 if (hres!=ERROR_SUCCESS)
467 {
468 RegCloseKey(clsidKey);
469 return REGDB_E_READREGDB;
470 }
471
472 /*
473 * Allocate a buffer for the registry value.
474 */
475 *pszUserType = CoTaskMemAlloc(cbData*2);
476
477 if (*pszUserType==NULL)
478 {
479 RegCloseKey(clsidKey);
480 return E_OUTOFMEMORY;
481 }
482
483 buffer = HeapAlloc(GetProcessHeap(), 0, cbData);
484
485 if (buffer == NULL)
486 {
487 RegCloseKey(clsidKey);
488 CoTaskMemFree(*pszUserType);
489 *pszUserType=NULL;
490 return E_OUTOFMEMORY;
491 }
492
493 hres = RegQueryValueExA(clsidKey,
494 "",
495 NULL,
496 &dwKeyType,
497 buffer,
498 &cbData);
499
500 RegCloseKey(clsidKey);
501
502
503 if (hres!=ERROR_SUCCESS)
504 {
505 CoTaskMemFree(*pszUserType);
506 *pszUserType=NULL;
507
508 retVal = REGDB_E_READREGDB;
509 }
510 else
511 {
512 MultiByteToWideChar( CP_ACP, 0, buffer, -1, *pszUserType, cbData /*FIXME*/ );
513 retVal = S_OK;
514 }
515 HeapFree(GetProcessHeap(), 0, buffer);
516
517 return retVal;
518}
519
520/***********************************************************************
521 * DoDragDrop [OLE32.65]
522 */
523HRESULT WINAPI DoDragDrop (
524 IDataObject *pDataObject, /* [in] ptr to the data obj */
525 IDropSource* pDropSource, /* [in] ptr to the source obj */
526 DWORD dwOKEffect, /* [in] effects allowed by the source */
527 DWORD *pdwEffect) /* [out] ptr to effects of the source */
528{
529 TrackerWindowInfo trackerInfo;
530 HWND hwndTrackWindow;
531 MSG msg;
532
533 TRACE("(DataObject %p, DropSource %p)\n", pDataObject, pDropSource);
534
535 /*
536 * Setup the drag n drop tracking window.
537 */
538 trackerInfo.dataObject = pDataObject;
539 trackerInfo.dropSource = pDropSource;
540 trackerInfo.dwOKEffect = dwOKEffect;
541 trackerInfo.pdwEffect = pdwEffect;
542 trackerInfo.trackingDone = FALSE;
543 trackerInfo.escPressed = FALSE;
544 trackerInfo.curDragTargetHWND = 0;
545 trackerInfo.curDragTarget = 0;
546
547 hwndTrackWindow = CreateWindowA(OLEDD_DRAGTRACKERCLASS,
548 "TrackerWindow",
549 WS_POPUP,
550 CW_USEDEFAULT, CW_USEDEFAULT,
551 CW_USEDEFAULT, CW_USEDEFAULT,
552 0,
553 0,
554 0,
555 (LPVOID)&trackerInfo);
556
557 if (hwndTrackWindow!=0)
558 {
559 /*
560 * Capture the mouse input
561 */
562 SetCapture(hwndTrackWindow);
563
564 /*
565 * Pump messages. All mouse input should go the the capture window.
566 */
567 while (!trackerInfo.trackingDone && GetMessageA(&msg, 0, 0, 0) )
568 {
569 if ( (msg.message >= WM_KEYFIRST) &&
570 (msg.message <= WM_KEYLAST) )
571 {
572 /*
573 * When keyboard messages are sent to windows on this thread, we
574 * want to ignore notify the drop source that the state changed.
575 * in the case of the Escape key, we also notify the drop source
576 * we give it a special meaning.
577 */
578 if ( (msg.message==WM_KEYDOWN) &&
579 (msg.wParam==VK_ESCAPE) )
580 {
581 trackerInfo.escPressed = TRUE;
582 }
583
584 /*
585 * Notify the drop source.
586 */
587 OLEDD_TrackStateChange(&trackerInfo,
588 msg.pt,
589 OLEDD_GetButtonState());
590 }
591 else
592 {
593 /*
594 * Dispatch the messages only when it's not a keyboard message.
595 */
596 DispatchMessageA(&msg);
597 }
598 }
599
600 /*
601 * Destroy the temporary window.
602 */
603 DestroyWindow(hwndTrackWindow);
604
605 return trackerInfo.returnValue;
606 }
607
608 return E_FAIL;
609}
610
611/***********************************************************************
612 * OleQueryLinkFromData [OLE32.118]
613 */
614HRESULT WINAPI OleQueryLinkFromData(
615 IDataObject* pSrcDataObject)
616{
617 FIXME("(%p),stub!\n", pSrcDataObject);
618 return S_OK;
619}
620
621/***********************************************************************
622 * OleRegGetMiscStatus [OLE32.121]
623 */
624HRESULT WINAPI OleRegGetMiscStatus(
625 REFCLSID clsid,
626 DWORD dwAspect,
627 DWORD* pdwStatus)
628{
629 char keyName[60];
630 HKEY clsidKey;
631 HKEY miscStatusKey;
632 HKEY aspectKey;
633 LONG result;
634
635 /*
636 * Initialize the out parameter.
637 */
638 *pdwStatus = 0;
639
640 /*
641 * Build the key name we're looking for
642 */
643 sprintf( keyName, "CLSID\\{%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}\\",
644 clsid->Data1, clsid->Data2, clsid->Data3,
645 clsid->Data4[0], clsid->Data4[1], clsid->Data4[2], clsid->Data4[3],
646 clsid->Data4[4], clsid->Data4[5], clsid->Data4[6], clsid->Data4[7] );
647
648 TRACE("(%s, %ld, %p)\n", keyName, dwAspect, pdwStatus);
649
650 /*
651 * Open the class id Key
652 */
653 result = RegOpenKeyA(HKEY_CLASSES_ROOT,
654 keyName,
655 &clsidKey);
656
657 if (result != ERROR_SUCCESS)
658 return REGDB_E_CLASSNOTREG;
659
660 /*
661 * Get the MiscStatus
662 */
663 result = RegOpenKeyA(clsidKey,
664 "MiscStatus",
665 &miscStatusKey);
666
667
668 if (result != ERROR_SUCCESS)
669 {
670 RegCloseKey(clsidKey);
671 return REGDB_E_READREGDB;
672 }
673
674 /*
675 * Read the default value
676 */
677 OLEUTL_ReadRegistryDWORDValue(miscStatusKey, pdwStatus);
678
679 /*
680 * Open the key specific to the requested aspect.
681 */
682 sprintf(keyName, "%ld", dwAspect);
683
684 result = RegOpenKeyA(miscStatusKey,
685 keyName,
686 &aspectKey);
687
688 if (result == ERROR_SUCCESS)
689 {
690 OLEUTL_ReadRegistryDWORDValue(aspectKey, pdwStatus);
691 RegCloseKey(aspectKey);
692 }
693
694 /*
695 * Cleanup
696 */
697 RegCloseKey(miscStatusKey);
698 RegCloseKey(clsidKey);
699
700 return S_OK;
701}
702
703/******************************************************************************
704 * OleSetContainedObject [OLE32.128]
705 */
706HRESULT WINAPI OleSetContainedObject(
707 LPUNKNOWN pUnknown,
708 BOOL fContained)
709{
710 IRunnableObject* runnable = NULL;
711 HRESULT hres;
712
713 TRACE("(%p,%x), stub!\n", pUnknown, fContained);
714
715 hres = IUnknown_QueryInterface(pUnknown,
716 &IID_IRunnableObject,
717 (void**)&runnable);
718
719 if (SUCCEEDED(hres))
720 {
721 hres = IRunnableObject_SetContainedObject(runnable, fContained);
722
723 IRunnableObject_Release(runnable);
724
725 return hres;
726 }
727
728 return S_OK;
729}
730
731/******************************************************************************
732 * OleLoad [OLE32.112]
733 */
734HRESULT WINAPI OleLoad(
735 LPSTORAGE pStg,
736 REFIID riid,
737 LPOLECLIENTSITE pClientSite,
738 LPVOID* ppvObj)
739{
740 IPersistStorage* persistStorage = NULL;
741 IOleObject* oleObject = NULL;
742 STATSTG storageInfo;
743 HRESULT hres;
744
745 TRACE("(%p,%p,%p,%p)\n", pStg, riid, pClientSite, ppvObj);
746
747 /*
748 * TODO, Conversion ... OleDoAutoConvert
749 */
750
751 /*
752 * Get the class ID for the object.
753 */
754 hres = IStorage_Stat(pStg, &storageInfo, STATFLAG_NONAME);
755
756 /*
757 * Now, try and create the handler for the object
758 */
759 hres = CoCreateInstance(&storageInfo.clsid,
760 NULL,
761 CLSCTX_INPROC_HANDLER,
762 &IID_IOleObject,
763 (void**)&oleObject);
764
765 /*
766 * If that fails, as it will most times, load the default
767 * OLE handler.
768 */
769 if (FAILED(hres))
770 {
771 hres = OleCreateDefaultHandler(&storageInfo.clsid,
772 NULL,
773 &IID_IOleObject,
774 (void**)&oleObject);
775 }
776
777 /*
778 * If we couldn't find a handler... this is bad. Abort the whole thing.
779 */
780 if (FAILED(hres))
781 return hres;
782
783 /*
784 * Inform the new object of it's client site.
785 */
786 hres = IOleObject_SetClientSite(oleObject, pClientSite);
787
788 /*
789 * Initialize the object with it's IPersistStorage interface.
790 */
791 hres = IOleObject_QueryInterface(oleObject,
792 &IID_IPersistStorage,
793 (void**)&persistStorage);
794
795 if (SUCCEEDED(hres))
796 {
797 IPersistStorage_Load(persistStorage, pStg);
798
799 IPersistStorage_Release(persistStorage);
800 persistStorage = NULL;
801 }
802
803 /*
804 * Return the requested interface to the caller.
805 */
806 hres = IOleObject_QueryInterface(oleObject, riid, ppvObj);
807
808 /*
809 * Cleanup interfaces used internally
810 */
811 IOleObject_Release(oleObject);
812
813 return hres;
814}
815
816/***********************************************************************
817 * OleSave [OLE32.124]
818 */
819HRESULT WINAPI OleSave(
820 LPPERSISTSTORAGE pPS,
821 LPSTORAGE pStg,
822 BOOL fSameAsLoad)
823{
824 HRESULT hres;
825 CLSID objectClass;
826
827 TRACE("(%p,%p,%x)\n", pPS, pStg, fSameAsLoad);
828
829 /*
830 * First, we transfer the class ID (if available)
831 */
832 hres = IPersistStorage_GetClassID(pPS, &objectClass);
833
834 if (SUCCEEDED(hres))
835 {
836 WriteClassStg(pStg, &objectClass);
837 }
838
839 /*
840 * Then, we ask the object to save itself to the
841 * storage. If it is successful, we commit the storage.
842 */
843 hres = IPersistStorage_Save(pPS, pStg, fSameAsLoad);
844
845 if (SUCCEEDED(hres))
846 {
847 IStorage_Commit(pStg,
848 STGC_DEFAULT);
849 }
850
851 return hres;
852}
853
854
855/******************************************************************************
856 * OleLockRunning [OLE32.114]
857 */
858HRESULT WINAPI OleLockRunning(LPUNKNOWN pUnknown, BOOL fLock, BOOL fLastUnlockCloses)
859{
860 IRunnableObject* runnable = NULL;
861 HRESULT hres;
862
863 TRACE("(%p,%x,%x)\n", pUnknown, fLock, fLastUnlockCloses);
864
865 hres = IUnknown_QueryInterface(pUnknown,
866 &IID_IRunnableObject,
867 (void**)&runnable);
868
869 if (SUCCEEDED(hres))
870 {
871 hres = IRunnableObject_LockRunning(runnable, fLock, fLastUnlockCloses);
872
873 IRunnableObject_Release(runnable);
874
875 return hres;
876 }
877 else
878 return E_INVALIDARG;
879}
880
881
882/**************************************************************************
883 * Internal methods to manage the shared OLE menu in response to the
884 * OLE***MenuDescriptor API
885 */
886
887/***
888 * OLEMenu_Initialize()
889 *
890 * Initializes the OLEMENU data structures.
891 */
892static void OLEMenu_Initialize()
893{
894}
895
896/***
897 * OLEMenu_UnInitialize()
898 *
899 * Releases the OLEMENU data structures.
900 */
901static void OLEMenu_UnInitialize()
902{
903}
904
905/*************************************************************************
906 * OLEMenu_InstallHooks
907 * Install thread scope message hooks for WH_GETMESSAGE and WH_CALLWNDPROC
908 *
909 * RETURNS: TRUE if message hooks were succesfully installed
910 * FALSE on failure
911 */
912BOOL OLEMenu_InstallHooks( DWORD tid )
913{
914 OleMenuHookItem *pHookItem = NULL;
915
916 /* Create an entry for the hook table */
917 if ( !(pHookItem = HeapAlloc(GetProcessHeap(), 0,
918 sizeof(OleMenuHookItem)) ) )
919 return FALSE;
920
921 pHookItem->tid = tid;
922 pHookItem->hHeap = GetProcessHeap();
923
924 /* Install a thread scope message hook for WH_GETMESSAGE */
925 pHookItem->GetMsg_hHook = SetWindowsHookExA( WH_GETMESSAGE, OLEMenu_GetMsgProc,
926 0, GetCurrentThreadId() );
927 if ( !pHookItem->GetMsg_hHook )
928 goto CLEANUP;
929
930 /* Install a thread scope message hook for WH_CALLWNDPROC */
931 pHookItem->CallWndProc_hHook = SetWindowsHookExA( WH_CALLWNDPROC, OLEMenu_CallWndProc,
932 0, GetCurrentThreadId() );
933 if ( !pHookItem->CallWndProc_hHook )
934 goto CLEANUP;
935
936 /* Insert the hook table entry */
937 pHookItem->next = hook_list;
938 hook_list = pHookItem;
939
940 return TRUE;
941
942CLEANUP:
943 /* Unhook any hooks */
944 if ( pHookItem->GetMsg_hHook )
945 UnhookWindowsHookEx( pHookItem->GetMsg_hHook );
946 if ( pHookItem->CallWndProc_hHook )
947 UnhookWindowsHookEx( pHookItem->CallWndProc_hHook );
948 /* Release the hook table entry */
949 HeapFree(pHookItem->hHeap, 0, pHookItem );
950
951 return FALSE;
952}
953
954/*************************************************************************
955 * OLEMenu_UnInstallHooks
956 * UnInstall thread scope message hooks for WH_GETMESSAGE and WH_CALLWNDPROC
957 *
958 * RETURNS: TRUE if message hooks were succesfully installed
959 * FALSE on failure
960 */
961BOOL OLEMenu_UnInstallHooks( DWORD tid )
962{
963 OleMenuHookItem *pHookItem = NULL;
964 OleMenuHookItem **ppHook = &hook_list;
965
966 while (*ppHook)
967 {
968 if ((*ppHook)->tid == tid)
969 {
970 pHookItem = *ppHook;
971 *ppHook = pHookItem->next;
972 break;
973 }
974 ppHook = &(*ppHook)->next;
975 }
976 if (!pHookItem) return FALSE;
977
978 /* Uninstall the hooks installed for this thread */
979 if ( !UnhookWindowsHookEx( pHookItem->GetMsg_hHook ) )
980 goto CLEANUP;
981 if ( !UnhookWindowsHookEx( pHookItem->CallWndProc_hHook ) )
982 goto CLEANUP;
983
984 /* Release the hook table entry */
985 HeapFree(pHookItem->hHeap, 0, pHookItem );
986
987 return TRUE;
988
989CLEANUP:
990 /* Release the hook table entry */
991 if (pHookItem)
992 HeapFree(pHookItem->hHeap, 0, pHookItem );
993
994 return FALSE;
995}
996
997/*************************************************************************
998 * OLEMenu_IsHookInstalled
999 * Tests if OLEMenu hooks have been installed for a thread
1000 *
1001 * RETURNS: The pointer and index of the hook table entry for the tid
1002 * NULL and -1 for the index if no hooks were installed for this thread
1003 */
1004OleMenuHookItem * OLEMenu_IsHookInstalled( DWORD tid )
1005{
1006 OleMenuHookItem *pHookItem = NULL;
1007
1008 /* Do a simple linear search for an entry whose tid matches ours.
1009 * We really need a map but efficiency is not a concern here. */
1010 for (pHookItem = hook_list; pHookItem; pHookItem = pHookItem->next)
1011 {
1012 if ( tid == pHookItem->tid )
1013 return pHookItem;
1014 }
1015
1016 return NULL;
1017}
1018
1019/***********************************************************************
1020 * OLEMenu_FindMainMenuIndex
1021 *
1022 * Used by OLEMenu API to find the top level group a menu item belongs to.
1023 * On success pnPos contains the index of the item in the top level menu group
1024 *
1025 * RETURNS: TRUE if the ID was found, FALSE on failure
1026 */
1027static BOOL OLEMenu_FindMainMenuIndex( HMENU hMainMenu, HMENU hPopupMenu, UINT *pnPos )
1028{
1029 UINT i, nItems;
1030
1031 nItems = GetMenuItemCount( hMainMenu );
1032
1033 for (i = 0; i < nItems; i++)
1034 {
1035 HMENU hsubmenu;
1036
1037 /* Is the current item a submenu? */
1038 if ( (hsubmenu = GetSubMenu(hMainMenu, i)) )
1039 {
1040 /* If the handle is the same we're done */
1041 if ( hsubmenu == hPopupMenu )
1042 {
1043 if (pnPos)
1044 *pnPos = i;
1045 return TRUE;
1046 }
1047 /* Recursively search without updating pnPos */
1048 else if ( OLEMenu_FindMainMenuIndex( hsubmenu, hPopupMenu, NULL ) )
1049 {
1050 if (pnPos)
1051 *pnPos = i;
1052 return TRUE;
1053 }
1054 }
1055 }
1056
1057 return FALSE;
1058}
1059
1060/***********************************************************************
1061 * OLEMenu_SetIsServerMenu
1062 *
1063 * Checks whether a popup menu belongs to a shared menu group which is
1064 * owned by the server, and sets the menu descriptor state accordingly.
1065 * All menu messages from these groups should be routed to the server.
1066 *
1067 * RETURNS: TRUE if the popup menu is part of a server owned group
1068 * FASE if the popup menu is part of a container owned group
1069 */
1070BOOL OLEMenu_SetIsServerMenu( HMENU hmenu, OleMenuDescriptor *pOleMenuDescriptor )
1071{
1072 UINT nPos = 0, nWidth, i;
1073
1074 pOleMenuDescriptor->bIsServerItem = FALSE;
1075
1076 /* Don't bother searching if the popup is the combined menu itself */
1077 if ( hmenu == pOleMenuDescriptor->hmenuCombined )
1078 return FALSE;
1079
1080 /* Find the menu item index in the shared OLE menu that this item belongs to */
1081 if ( !OLEMenu_FindMainMenuIndex( pOleMenuDescriptor->hmenuCombined, hmenu, &nPos ) )
1082 return FALSE;
1083
1084 /* The group widths array has counts for the number of elements
1085 * in the groups File, Edit, Container, Object, Window, Help.
1086 * The Edit, Object & Help groups belong to the server object
1087 * and the other three belong to the container.
1088 * Loop through the group widths and locate the group we are a member of.
1089 */
1090 for ( i = 0, nWidth = 0; i < 6; i++ )
1091 {
1092 nWidth += pOleMenuDescriptor->mgw.width[i];
1093 if ( nPos < nWidth )
1094 {
1095 /* Odd elements are server menu widths */
1096 pOleMenuDescriptor->bIsServerItem = (i%2) ? TRUE : FALSE;
1097 break;
1098 }
1099 }
1100
1101 return pOleMenuDescriptor->bIsServerItem;
1102}
1103
1104/*************************************************************************
1105 * OLEMenu_CallWndProc
1106 * Thread scope WH_CALLWNDPROC hook proc filter function (callback)
1107 * This is invoked from a message hook installed in OleSetMenuDescriptor.
1108 */
1109LRESULT CALLBACK OLEMenu_CallWndProc(INT code, WPARAM wParam, LPARAM lParam)
1110{
1111 LPCWPSTRUCT pMsg = NULL;
1112 HOLEMENU hOleMenu = 0;
1113 OleMenuDescriptor *pOleMenuDescriptor = NULL;
1114 OleMenuHookItem *pHookItem = NULL;
1115 WORD fuFlags;
1116
1117 TRACE("%i, %04x, %08x\n", code, wParam, (unsigned)lParam );
1118
1119 /* Check if we're being asked to process the message */
1120 if ( HC_ACTION != code )
1121 goto NEXTHOOK;
1122
1123 /* Retrieve the current message being dispatched from lParam */
1124 pMsg = (LPCWPSTRUCT)lParam;
1125
1126 /* Check if the message is destined for a window we are interested in:
1127 * If the window has an OLEMenu property we may need to dispatch
1128 * the menu message to its active objects window instead. */
1129
1130 hOleMenu = (HOLEMENU)GetPropA( pMsg->hwnd, "PROP_OLEMenuDescriptor" );
1131 if ( !hOleMenu )
1132 goto NEXTHOOK;
1133
1134 /* Get the menu descriptor */
1135 pOleMenuDescriptor = (OleMenuDescriptor *) GlobalLock( hOleMenu );
1136 if ( !pOleMenuDescriptor ) /* Bad descriptor! */
1137 goto NEXTHOOK;
1138
1139 /* Process menu messages */
1140 switch( pMsg->message )
1141 {
1142 case WM_INITMENU:
1143 {
1144 /* Reset the menu descriptor state */
1145 pOleMenuDescriptor->bIsServerItem = FALSE;
1146
1147 /* Send this message to the server as well */
1148 SendMessageA( pOleMenuDescriptor->hwndActiveObject,
1149 pMsg->message, pMsg->wParam, pMsg->lParam );
1150 goto NEXTHOOK;
1151 }
1152
1153 case WM_INITMENUPOPUP:
1154 {
1155 /* Save the state for whether this is a server owned menu */
1156 OLEMenu_SetIsServerMenu( (HMENU)pMsg->wParam, pOleMenuDescriptor );
1157 break;
1158 }
1159
1160 case WM_MENUSELECT:
1161 {
1162 fuFlags = HIWORD(pMsg->wParam); /* Get flags */
1163 if ( fuFlags & MF_SYSMENU )
1164 goto NEXTHOOK;
1165
1166 /* Save the state for whether this is a server owned popup menu */
1167 else if ( fuFlags & MF_POPUP )
1168 OLEMenu_SetIsServerMenu( (HMENU)pMsg->lParam, pOleMenuDescriptor );
1169
1170 break;
1171 }
1172
1173 case WM_DRAWITEM:
1174 {
1175 LPDRAWITEMSTRUCT lpdis = (LPDRAWITEMSTRUCT) pMsg->lParam;
1176 if ( pMsg->wParam != 0 || lpdis->CtlType != ODT_MENU )
1177 goto NEXTHOOK; /* Not a menu message */
1178
1179 break;
1180 }
1181
1182 default:
1183 goto NEXTHOOK;
1184 }
1185
1186 /* If the message was for the server dispatch it accordingly */
1187 if ( pOleMenuDescriptor->bIsServerItem )
1188 {
1189 SendMessageA( pOleMenuDescriptor->hwndActiveObject,
1190 pMsg->message, pMsg->wParam, pMsg->lParam );
1191 }
1192
1193NEXTHOOK:
1194 if ( pOleMenuDescriptor )
1195 GlobalUnlock( hOleMenu );
1196
1197 /* Lookup the hook item for the current thread */
1198 if ( !( pHookItem = OLEMenu_IsHookInstalled( GetCurrentThreadId() ) ) )
1199 {
1200 /* This should never fail!! */
1201 WARN("could not retrieve hHook for current thread!\n" );
1202 return 0;
1203 }
1204
1205 /* Pass on the message to the next hooker */
1206 return CallNextHookEx( pHookItem->CallWndProc_hHook, code, wParam, lParam );
1207}
1208
1209/*************************************************************************
1210 * OLEMenu_GetMsgProc
1211 * Thread scope WH_GETMESSAGE hook proc filter function (callback)
1212 * This is invoked from a message hook installed in OleSetMenuDescriptor.
1213 */
1214LRESULT CALLBACK OLEMenu_GetMsgProc(INT code, WPARAM wParam, LPARAM lParam)
1215{
1216 LPMSG pMsg = NULL;
1217 HOLEMENU hOleMenu = 0;
1218 OleMenuDescriptor *pOleMenuDescriptor = NULL;
1219 OleMenuHookItem *pHookItem = NULL;
1220 WORD wCode;
1221
1222 TRACE("%i, %04x, %08x\n", code, wParam, (unsigned)lParam );
1223
1224 /* Check if we're being asked to process a messages */
1225 if ( HC_ACTION != code )
1226 goto NEXTHOOK;
1227
1228 /* Retrieve the current message being dispatched from lParam */
1229 pMsg = (LPMSG)lParam;
1230
1231 /* Check if the message is destined for a window we are interested in:
1232 * If the window has an OLEMenu property we may need to dispatch
1233 * the menu message to its active objects window instead. */
1234
1235 hOleMenu = (HOLEMENU)GetPropA( pMsg->hwnd, "PROP_OLEMenuDescriptor" );
1236 if ( !hOleMenu )
1237 goto NEXTHOOK;
1238
1239 /* Process menu messages */
1240 switch( pMsg->message )
1241 {
1242 case WM_COMMAND:
1243 {
1244 wCode = HIWORD(pMsg->wParam); /* Get notification code */
1245 if ( wCode )
1246 goto NEXTHOOK; /* Not a menu message */
1247 break;
1248 }
1249 default:
1250 goto NEXTHOOK;
1251 }
1252
1253 /* Get the menu descriptor */
1254 pOleMenuDescriptor = (OleMenuDescriptor *) GlobalLock( hOleMenu );
1255 if ( !pOleMenuDescriptor ) /* Bad descriptor! */
1256 goto NEXTHOOK;
1257
1258 /* If the message was for the server dispatch it accordingly */
1259 if ( pOleMenuDescriptor->bIsServerItem )
1260 {
1261 /* Change the hWnd in the message to the active objects hWnd.
1262 * The message loop which reads this message will automatically
1263 * dispatch it to the embedded objects window. */
1264 pMsg->hwnd = pOleMenuDescriptor->hwndActiveObject;
1265 }
1266
1267NEXTHOOK:
1268 if ( pOleMenuDescriptor )
1269 GlobalUnlock( hOleMenu );
1270
1271 /* Lookup the hook item for the current thread */
1272 if ( !( pHookItem = OLEMenu_IsHookInstalled( GetCurrentThreadId() ) ) )
1273 {
1274 /* This should never fail!! */
1275 WARN("could not retrieve hHook for current thread!\n" );
1276 return FALSE;
1277 }
1278
1279 /* Pass on the message to the next hooker */
1280 return CallNextHookEx( pHookItem->GetMsg_hHook, code, wParam, lParam );
1281}
1282
1283/***********************************************************************
1284 * OleCreateMenuDescriptor [OLE32.97]
1285 * Creates an OLE menu descriptor for OLE to use when dispatching
1286 * menu messages and commands.
1287 *
1288 * PARAMS:
1289 * hmenuCombined - Handle to the objects combined menu
1290 * lpMenuWidths - Pointer to array of 6 LONG's indicating menus per group
1291 *
1292 */
1293HOLEMENU WINAPI OleCreateMenuDescriptor(
1294 HMENU hmenuCombined,
1295 LPOLEMENUGROUPWIDTHS lpMenuWidths)
1296{
1297 HOLEMENU hOleMenu;
1298 OleMenuDescriptor *pOleMenuDescriptor;
1299 int i;
1300
1301 if ( !hmenuCombined || !lpMenuWidths )
1302 return 0;
1303
1304 /* Create an OLE menu descriptor */
1305 if ( !(hOleMenu = GlobalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT,
1306 sizeof(OleMenuDescriptor) ) ) )
1307 return 0;
1308
1309 pOleMenuDescriptor = (OleMenuDescriptor *) GlobalLock( hOleMenu );
1310 if ( !pOleMenuDescriptor )
1311 return 0;
1312
1313 /* Initialize menu group widths and hmenu */
1314 for ( i = 0; i < 6; i++ )
1315 pOleMenuDescriptor->mgw.width[i] = lpMenuWidths->width[i];
1316
1317 pOleMenuDescriptor->hmenuCombined = hmenuCombined;
1318 pOleMenuDescriptor->bIsServerItem = FALSE;
1319 GlobalUnlock( hOleMenu );
1320
1321 return hOleMenu;
1322}
1323
1324/***********************************************************************
1325 * OleDestroyMenuDescriptor [OLE32.99]
1326 * Destroy the shared menu descriptor
1327 */
1328HRESULT WINAPI OleDestroyMenuDescriptor(
1329 HOLEMENU hmenuDescriptor)
1330{
1331 if ( hmenuDescriptor )
1332 GlobalFree( hmenuDescriptor );
1333 return S_OK;
1334}
1335
1336/***********************************************************************
1337 * OleSetMenuDescriptor [OLE32.129]
1338 * Installs or removes OLE dispatching code for the containers frame window
1339 * FIXME: The lpFrame and lpActiveObject parameters are currently ignored
1340 * OLE should install context sensitive help F1 filtering for the app when
1341 * these are non null.
1342 *
1343 * PARAMS:
1344 * hOleMenu Handle to composite menu descriptor
1345 * hwndFrame Handle to containers frame window
1346 * hwndActiveObject Handle to objects in-place activation window
1347 * lpFrame Pointer to IOleInPlaceFrame on containers window
1348 * lpActiveObject Pointer to IOleInPlaceActiveObject on active in-place object
1349 *
1350 * RETURNS:
1351 * S_OK - menu installed correctly
1352 * E_FAIL, E_INVALIDARG, E_UNEXPECTED - failure
1353 */
1354HRESULT WINAPI OleSetMenuDescriptor(
1355 HOLEMENU hOleMenu,
1356 HWND hwndFrame,
1357 HWND hwndActiveObject,
1358 LPOLEINPLACEFRAME lpFrame,
1359 LPOLEINPLACEACTIVEOBJECT lpActiveObject)
1360{
1361 OleMenuDescriptor *pOleMenuDescriptor = NULL;
1362
1363 /* Check args */
1364 if ( !hwndFrame || (hOleMenu && !hwndActiveObject) )
1365 return E_INVALIDARG;
1366
1367 if ( lpFrame || lpActiveObject )
1368 {
1369 FIXME("(%x, %x, %x, %p, %p), Context sensitive help filtering not implemented!\n",
1370 (unsigned int)hOleMenu,
1371 hwndFrame,
1372 hwndActiveObject,
1373 lpFrame,
1374 lpActiveObject);
1375 }
1376
1377 /* Set up a message hook to intercept the containers frame window messages.
1378 * The message filter is responsible for dispatching menu messages from the
1379 * shared menu which are intended for the object.
1380 */
1381
1382 if ( hOleMenu ) /* Want to install dispatching code */
1383 {
1384 /* If OLEMenu hooks are already installed for this thread, fail
1385 * Note: This effectively means that OleSetMenuDescriptor cannot
1386 * be called twice in succession on the same frame window
1387 * without first calling it with a null hOleMenu to uninstall */
1388 if ( OLEMenu_IsHookInstalled( GetCurrentThreadId() ) )
1389 return E_FAIL;
1390
1391 /* Get the menu descriptor */
1392 pOleMenuDescriptor = (OleMenuDescriptor *) GlobalLock( hOleMenu );
1393 if ( !pOleMenuDescriptor )
1394 return E_UNEXPECTED;
1395
1396 /* Update the menu descriptor */
1397 pOleMenuDescriptor->hwndFrame = hwndFrame;
1398 pOleMenuDescriptor->hwndActiveObject = hwndActiveObject;
1399
1400 GlobalUnlock( hOleMenu );
1401 pOleMenuDescriptor = NULL;
1402
1403 /* Add a menu descriptor windows property to the frame window */
1404 SetPropA( hwndFrame, "PROP_OLEMenuDescriptor", hOleMenu );
1405
1406 /* Install thread scope message hooks for WH_GETMESSAGE and WH_CALLWNDPROC */
1407 if ( !OLEMenu_InstallHooks( GetCurrentThreadId() ) )
1408 return E_FAIL;
1409 }
1410 else /* Want to uninstall dispatching code */
1411 {
1412 /* Uninstall the hooks */
1413 if ( !OLEMenu_UnInstallHooks( GetCurrentThreadId() ) )
1414 return E_FAIL;
1415
1416 /* Remove the menu descriptor property from the frame window */
1417 RemovePropA( hwndFrame, "PROP_OLEMenuDescriptor" );
1418 }
1419
1420 return S_OK;
1421}
1422
1423/******************************************************************************
1424 * IsAccelerator [OLE32.75]
1425 * Mostly copied from controls/menu.c TranslateAccelerator implementation
1426 */
1427BOOL WINAPI IsAccelerator(HACCEL hAccel, int cAccelEntries, LPMSG lpMsg, WORD* lpwCmd)
1428{
1429 /* YES, Accel16! */
1430 LPACCEL16 lpAccelTbl;
1431 int i;
1432
1433 if(!lpMsg) return FALSE;
1434
1435#ifdef __WIN32OS2__
1436 if (!hAccel || !(lpAccelTbl = (LPACCEL16)LockResource(hAccel)))
1437#else
1438 if (!hAccel || !(lpAccelTbl = (LPACCEL16)LockResource16(hAccel)))
1439#endif
1440 {
1441 WARN_(accel)("invalid accel handle=%04x\n", hAccel);
1442 return FALSE;
1443 }
1444 if((lpMsg->message != WM_KEYDOWN &&
1445 lpMsg->message != WM_KEYUP &&
1446 lpMsg->message != WM_SYSKEYDOWN &&
1447 lpMsg->message != WM_SYSKEYUP &&
1448 lpMsg->message != WM_CHAR)) return FALSE;
1449
1450 TRACE_(accel)("hAccel=%04x, cAccelEntries=%d,"
1451 "msg->hwnd=%04x, msg->message=%04x, wParam=%08x, lParam=%08lx\n",
1452 hAccel, cAccelEntries,
1453 lpMsg->hwnd, lpMsg->message, lpMsg->wParam, lpMsg->lParam);
1454 for(i = 0; i < cAccelEntries; i++)
1455 {
1456 if(lpAccelTbl[i].key != lpMsg->wParam)
1457 continue;
1458
1459 if(lpMsg->message == WM_CHAR)
1460 {
1461 if(!(lpAccelTbl[i].fVirt & FALT) && !(lpAccelTbl[i].fVirt & FVIRTKEY))
1462 {
1463 TRACE_(accel)("found accel for WM_CHAR: ('%c')\n", lpMsg->wParam & 0xff);
1464 goto found;
1465 }
1466 }
1467 else
1468 {
1469 if(lpAccelTbl[i].fVirt & FVIRTKEY)
1470 {
1471 INT mask = 0;
1472 TRACE_(accel)("found accel for virt_key %04x (scan %04x)\n",
1473 lpMsg->wParam, HIWORD(lpMsg->lParam) & 0xff);
1474 if(GetKeyState(VK_SHIFT) & 0x8000) mask |= FSHIFT;
1475 if(GetKeyState(VK_CONTROL) & 0x8000) mask |= FCONTROL;
1476 if(GetKeyState(VK_MENU) & 0x8000) mask |= FALT;
1477 if(mask == (lpAccelTbl[i].fVirt & (FSHIFT | FCONTROL | FALT))) goto found;
1478 TRACE_(accel)("incorrect SHIFT/CTRL/ALT-state\n");
1479 }
1480 else
1481 {
1482 if(!(lpMsg->lParam & 0x01000000)) /* no special_key */
1483 {
1484 if((lpAccelTbl[i].fVirt & FALT) && (lpMsg->lParam & 0x20000000))
1485 { /* ^^ ALT pressed */
1486 TRACE_(accel)("found accel for Alt-%c\n", lpMsg->wParam & 0xff);
1487 goto found;
1488 }
1489 }
1490 }
1491 }
1492 }
1493
1494 WARN_(accel)("couldn't translate accelerator key\n");
1495 return FALSE;
1496
1497found:
1498 if(lpwCmd) *lpwCmd = lpAccelTbl[i].cmd;
1499 return TRUE;
1500}
1501
1502/***********************************************************************
1503 * ReleaseStgMedium [OLE32.140]
1504 */
1505void WINAPI ReleaseStgMedium(
1506 STGMEDIUM* pmedium)
1507{
1508 switch (pmedium->tymed)
1509 {
1510 case TYMED_HGLOBAL:
1511 {
1512 if ( (pmedium->pUnkForRelease==0) &&
1513 (pmedium->u.hGlobal!=0) )
1514 GlobalFree(pmedium->u.hGlobal);
1515
1516 pmedium->u.hGlobal = 0;
1517 break;
1518 }
1519 case TYMED_FILE:
1520 {
1521 if (pmedium->u.lpszFileName!=0)
1522 {
1523 if (pmedium->pUnkForRelease==0)
1524 {
1525 DeleteFileW(pmedium->u.lpszFileName);
1526 }
1527
1528 CoTaskMemFree(pmedium->u.lpszFileName);
1529 }
1530
1531 pmedium->u.lpszFileName = 0;
1532 break;
1533 }
1534 case TYMED_ISTREAM:
1535 {
1536 if (pmedium->u.pstm!=0)
1537 {
1538 IStream_Release(pmedium->u.pstm);
1539 }
1540
1541 pmedium->u.pstm = 0;
1542 break;
1543 }
1544 case TYMED_ISTORAGE:
1545 {
1546 if (pmedium->u.pstg!=0)
1547 {
1548 IStorage_Release(pmedium->u.pstg);
1549 }
1550
1551 pmedium->u.pstg = 0;
1552 break;
1553 }
1554 case TYMED_GDI:
1555 {
1556 if ( (pmedium->pUnkForRelease==0) &&
1557 (pmedium->u.hGlobal!=0) )
1558 DeleteObject(pmedium->u.hGlobal);
1559
1560 pmedium->u.hGlobal = 0;
1561 break;
1562 }
1563 case TYMED_MFPICT:
1564 {
1565 if ( (pmedium->pUnkForRelease==0) &&
1566 (pmedium->u.hMetaFilePict!=0) )
1567 {
1568 LPMETAFILEPICT pMP = GlobalLock(pmedium->u.hGlobal);
1569 DeleteMetaFile(pMP->hMF);
1570 GlobalUnlock(pmedium->u.hGlobal);
1571 GlobalFree(pmedium->u.hGlobal);
1572 }
1573
1574 pmedium->u.hMetaFilePict = 0;
1575 break;
1576 }
1577 case TYMED_ENHMF:
1578 {
1579 if ( (pmedium->pUnkForRelease==0) &&
1580 (pmedium->u.hEnhMetaFile!=0) )
1581 {
1582 DeleteEnhMetaFile(pmedium->u.hEnhMetaFile);
1583 }
1584
1585 pmedium->u.hEnhMetaFile = 0;
1586 break;
1587 }
1588 case TYMED_NULL:
1589 default:
1590 break;
1591 }
1592
1593 /*
1594 * After cleaning up, the unknown is released
1595 */
1596 if (pmedium->pUnkForRelease!=0)
1597 {
1598 IUnknown_Release(pmedium->pUnkForRelease);
1599 pmedium->pUnkForRelease = 0;
1600 }
1601}
1602
1603/***
1604 * OLEDD_Initialize()
1605 *
1606 * Initializes the OLE drag and drop data structures.
1607 */
1608static void OLEDD_Initialize()
1609{
1610 WNDCLASSA wndClass;
1611
1612 ZeroMemory (&wndClass, sizeof(WNDCLASSA));
1613 wndClass.style = CS_GLOBALCLASS;
1614 wndClass.lpfnWndProc = (WNDPROC)OLEDD_DragTrackerWindowProc;
1615 wndClass.cbClsExtra = 0;
1616 wndClass.cbWndExtra = sizeof(TrackerWindowInfo*);
1617 wndClass.hCursor = 0;
1618 wndClass.hbrBackground = 0;
1619 wndClass.lpszClassName = OLEDD_DRAGTRACKERCLASS;
1620
1621 RegisterClassA (&wndClass);
1622}
1623
1624/***
1625 * OLEDD_UnInitialize()
1626 *
1627 * Releases the OLE drag and drop data structures.
1628 */
1629static void OLEDD_UnInitialize()
1630{
1631 /*
1632 * Simply empty the list.
1633 */
1634 while (targetListHead!=NULL)
1635 {
1636 RevokeDragDrop(targetListHead->hwndTarget);
1637 }
1638}
1639
1640/***
1641 * OLEDD_InsertDropTarget()
1642 *
1643 * Insert the target node in the tree.
1644 */
1645static void OLEDD_InsertDropTarget(DropTargetNode* nodeToAdd)
1646{
1647 DropTargetNode* curNode;
1648 DropTargetNode** parentNodeLink;
1649
1650 /*
1651 * Iterate the tree to find the insertion point.
1652 */
1653 curNode = targetListHead;
1654 parentNodeLink = &targetListHead;
1655
1656 while (curNode!=NULL)
1657 {
1658 if (nodeToAdd->hwndTarget<curNode->hwndTarget)
1659 {
1660 /*
1661 * If the node we want to add has a smaller HWND, go left
1662 */
1663 parentNodeLink = &curNode->prevDropTarget;
1664 curNode = curNode->prevDropTarget;
1665 }
1666 else if (nodeToAdd->hwndTarget>curNode->hwndTarget)
1667 {
1668 /*
1669 * If the node we want to add has a larger HWND, go right
1670 */
1671 parentNodeLink = &curNode->nextDropTarget;
1672 curNode = curNode->nextDropTarget;
1673 }
1674 else
1675 {
1676 /*
1677 * The item was found in the list. It shouldn't have been there
1678 */
1679 assert(FALSE);
1680 return;
1681 }
1682 }
1683
1684 /*
1685 * If we get here, we have found a spot for our item. The parentNodeLink
1686 * pointer points to the pointer that we have to modify.
1687 * The curNode should be NULL. We just have to establish the link and Voila!
1688 */
1689 assert(curNode==NULL);
1690 assert(parentNodeLink!=NULL);
1691 assert(*parentNodeLink==NULL);
1692
1693 *parentNodeLink=nodeToAdd;
1694}
1695
1696/***
1697 * OLEDD_ExtractDropTarget()
1698 *
1699 * Removes the target node from the tree.
1700 */
1701static DropTargetNode* OLEDD_ExtractDropTarget(HWND hwndOfTarget)
1702{
1703 DropTargetNode* curNode;
1704 DropTargetNode** parentNodeLink;
1705
1706 /*
1707 * Iterate the tree to find the insertion point.
1708 */
1709 curNode = targetListHead;
1710 parentNodeLink = &targetListHead;
1711
1712 while (curNode!=NULL)
1713 {
1714 if (hwndOfTarget<curNode->hwndTarget)
1715 {
1716 /*
1717 * If the node we want to add has a smaller HWND, go left
1718 */
1719 parentNodeLink = &curNode->prevDropTarget;
1720 curNode = curNode->prevDropTarget;
1721 }
1722 else if (hwndOfTarget>curNode->hwndTarget)
1723 {
1724 /*
1725 * If the node we want to add has a larger HWND, go right
1726 */
1727 parentNodeLink = &curNode->nextDropTarget;
1728 curNode = curNode->nextDropTarget;
1729 }
1730 else
1731 {
1732 /*
1733 * The item was found in the list. Detach it from it's parent and
1734 * re-insert it's kids in the tree.
1735 */
1736 assert(parentNodeLink!=NULL);
1737 assert(*parentNodeLink==curNode);
1738
1739 /*
1740 * We arbitrately re-attach the left sub-tree to the parent.
1741 */
1742 *parentNodeLink = curNode->prevDropTarget;
1743
1744 /*
1745 * And we re-insert the right subtree
1746 */
1747 if (curNode->nextDropTarget!=NULL)
1748 {
1749 OLEDD_InsertDropTarget(curNode->nextDropTarget);
1750 }
1751
1752 /*
1753 * The node we found is still a valid node once we complete
1754 * the unlinking of the kids.
1755 */
1756 curNode->nextDropTarget=NULL;
1757 curNode->prevDropTarget=NULL;
1758
1759 return curNode;
1760 }
1761 }
1762
1763 /*
1764 * If we get here, the node is not in the tree
1765 */
1766 return NULL;
1767}
1768
1769/***
1770 * OLEDD_FindDropTarget()
1771 *
1772 * Finds information about the drop target.
1773 */
1774static DropTargetNode* OLEDD_FindDropTarget(HWND hwndOfTarget)
1775{
1776 DropTargetNode* curNode;
1777
1778 /*
1779 * Iterate the tree to find the HWND value.
1780 */
1781 curNode = targetListHead;
1782
1783 while (curNode!=NULL)
1784 {
1785 if (hwndOfTarget<curNode->hwndTarget)
1786 {
1787 /*
1788 * If the node we want to add has a smaller HWND, go left
1789 */
1790 curNode = curNode->prevDropTarget;
1791 }
1792 else if (hwndOfTarget>curNode->hwndTarget)
1793 {
1794 /*
1795 * If the node we want to add has a larger HWND, go right
1796 */
1797 curNode = curNode->nextDropTarget;
1798 }
1799 else
1800 {
1801 /*
1802 * The item was found in the list.
1803 */
1804 return curNode;
1805 }
1806 }
1807
1808 /*
1809 * If we get here, the item is not in the list
1810 */
1811 return NULL;
1812}
1813
1814/***
1815 * OLEDD_DragTrackerWindowProc()
1816 *
1817 * This method is the WindowProcedure of the drag n drop tracking
1818 * window. During a drag n Drop operation, an invisible window is created
1819 * to receive the user input and act upon it. This procedure is in charge
1820 * of this behavior.
1821 */
1822static LRESULT WINAPI OLEDD_DragTrackerWindowProc(
1823 HWND hwnd,
1824 UINT uMsg,
1825 WPARAM wParam,
1826 LPARAM lParam)
1827{
1828 switch (uMsg)
1829 {
1830 case WM_CREATE:
1831 {
1832 LPCREATESTRUCTA createStruct = (LPCREATESTRUCTA)lParam;
1833
1834 SetWindowLongA(hwnd, 0, (LONG)createStruct->lpCreateParams);
1835
1836
1837 break;
1838 }
1839 case WM_MOUSEMOVE:
1840 {
1841 TrackerWindowInfo* trackerInfo = (TrackerWindowInfo*)GetWindowLongA(hwnd, 0);
1842 POINT mousePos;
1843
1844 /*
1845 * Get the current mouse position in screen coordinates.
1846 */
1847 mousePos.x = LOWORD(lParam);
1848 mousePos.y = HIWORD(lParam);
1849 ClientToScreen(hwnd, &mousePos);
1850
1851 /*
1852 * Track the movement of the mouse.
1853 */
1854 OLEDD_TrackMouseMove(trackerInfo, mousePos, wParam);
1855
1856 break;
1857 }
1858 case WM_LBUTTONUP:
1859 case WM_MBUTTONUP:
1860 case WM_RBUTTONUP:
1861 case WM_LBUTTONDOWN:
1862 case WM_MBUTTONDOWN:
1863 case WM_RBUTTONDOWN:
1864 {
1865 TrackerWindowInfo* trackerInfo = (TrackerWindowInfo*)GetWindowLongA(hwnd, 0);
1866 POINT mousePos;
1867
1868 /*
1869 * Get the current mouse position in screen coordinates.
1870 */
1871 mousePos.x = LOWORD(lParam);
1872 mousePos.y = HIWORD(lParam);
1873 ClientToScreen(hwnd, &mousePos);
1874
1875 /*
1876 * Notify everyone that the button state changed
1877 * TODO: Check if the "escape" key was pressed.
1878 */
1879 OLEDD_TrackStateChange(trackerInfo, mousePos, wParam);
1880
1881 break;
1882 }
1883 }
1884
1885 /*
1886 * This is a window proc after all. Let's call the default.
1887 */
1888 return DefWindowProcA (hwnd, uMsg, wParam, lParam);
1889}
1890
1891/***
1892 * OLEDD_TrackMouseMove()
1893 *
1894 * This method is invoked while a drag and drop operation is in effect.
1895 * it will generate the appropriate callbacks in the drop source
1896 * and drop target. It will also provide the expected feedback to
1897 * the user.
1898 *
1899 * params:
1900 * trackerInfo - Pointer to the structure identifying the
1901 * drag & drop operation that is currently
1902 * active.
1903 * mousePos - Current position of the mouse in screen
1904 * coordinates.
1905 * keyState - Contains the state of the shift keys and the
1906 * mouse buttons (MK_LBUTTON and the like)
1907 */
1908static void OLEDD_TrackMouseMove(
1909 TrackerWindowInfo* trackerInfo,
1910 POINT mousePos,
1911 DWORD keyState)
1912{
1913 HWND hwndNewTarget = 0;
1914 HRESULT hr = S_OK;
1915
1916 /*
1917 * Get the handle of the window under the mouse
1918 */
1919 hwndNewTarget = WindowFromPoint(mousePos);
1920
1921 /*
1922 * Every time, we re-initialize the effects passed to the
1923 * IDropTarget to the effects allowed by the source.
1924 */
1925 *trackerInfo->pdwEffect = trackerInfo->dwOKEffect;
1926
1927 /*
1928 * If we are hovering over the same target as before, send the
1929 * DragOver notification
1930 */
1931 if ( (trackerInfo->curDragTarget != 0) &&
1932 (trackerInfo->curDragTargetHWND==hwndNewTarget) )
1933 {
1934 POINTL mousePosParam;
1935
1936 /*
1937 * The documentation tells me that the coordinate should be in the target
1938 * window's coordinate space. However, the tests I made tell me the
1939 * coordinates should be in screen coordinates.
1940 */
1941 mousePosParam.x = mousePos.x;
1942 mousePosParam.y = mousePos.y;
1943
1944 IDropTarget_DragOver(trackerInfo->curDragTarget,
1945 keyState,
1946 mousePosParam,
1947 trackerInfo->pdwEffect);
1948 }
1949 else
1950 {
1951 DropTargetNode* newDropTargetNode = 0;
1952
1953 /*
1954 * If we changed window, we have to notify our old target and check for
1955 * the new one.
1956 */
1957 if (trackerInfo->curDragTarget!=0)
1958 {
1959 IDropTarget_DragLeave(trackerInfo->curDragTarget);
1960 }
1961
1962 /*
1963 * Make sure we're hovering over a window.
1964 */
1965 if (hwndNewTarget!=0)
1966 {
1967 /*
1968 * Find-out if there is a drag target under the mouse
1969 */
1970 HWND nexttar = hwndNewTarget;
1971 do {
1972 newDropTargetNode = OLEDD_FindDropTarget(nexttar);
1973 } while (!newDropTargetNode && (nexttar = GetParent(nexttar)) != 0);
1974 if(nexttar) hwndNewTarget = nexttar;
1975
1976 trackerInfo->curDragTargetHWND = hwndNewTarget;
1977 trackerInfo->curDragTarget = newDropTargetNode ? newDropTargetNode->dropTarget : 0;
1978
1979 /*
1980 * If there is, notify it that we just dragged-in
1981 */
1982 if (trackerInfo->curDragTarget!=0)
1983 {
1984 POINTL mousePosParam;
1985
1986 /*
1987 * The documentation tells me that the coordinate should be in the target
1988 * window's coordinate space. However, the tests I made tell me the
1989 * coordinates should be in screen coordinates.
1990 */
1991 mousePosParam.x = mousePos.x;
1992 mousePosParam.y = mousePos.y;
1993
1994 IDropTarget_DragEnter(trackerInfo->curDragTarget,
1995 trackerInfo->dataObject,
1996 keyState,
1997 mousePosParam,
1998 trackerInfo->pdwEffect);
1999 }
2000 }
2001 else
2002 {
2003 /*
2004 * The mouse is not over a window so we don't track anything.
2005 */
2006 trackerInfo->curDragTargetHWND = 0;
2007 trackerInfo->curDragTarget = 0;
2008 }
2009 }
2010
2011 /*
2012 * Now that we have done that, we have to tell the source to give
2013 * us feedback on the work being done by the target. If we don't
2014 * have a target, simulate no effect.
2015 */
2016 if (trackerInfo->curDragTarget==0)
2017 {
2018 *trackerInfo->pdwEffect = DROPEFFECT_NONE;
2019 }
2020
2021 hr = IDropSource_GiveFeedback(trackerInfo->dropSource,
2022 *trackerInfo->pdwEffect);
2023
2024 /*
2025 * When we ask for feedback from the drop source, sometimes it will
2026 * do all the necessary work and sometimes it will not handle it
2027 * when that's the case, we must display the standard drag and drop
2028 * cursors.
2029 */
2030 if (hr==DRAGDROP_S_USEDEFAULTCURSORS)
2031 {
2032 if (*trackerInfo->pdwEffect & DROPEFFECT_MOVE)
2033 {
2034 SetCursor(LoadCursorA(OLE32_hInstance, MAKEINTRESOURCEA(1)));
2035 }
2036 else if (*trackerInfo->pdwEffect & DROPEFFECT_COPY)
2037 {
2038 SetCursor(LoadCursorA(OLE32_hInstance, MAKEINTRESOURCEA(2)));
2039 }
2040 else if (*trackerInfo->pdwEffect & DROPEFFECT_LINK)
2041 {
2042 SetCursor(LoadCursorA(OLE32_hInstance, MAKEINTRESOURCEA(3)));
2043 }
2044 else
2045 {
2046 SetCursor(LoadCursorA(OLE32_hInstance, MAKEINTRESOURCEA(0)));
2047 }
2048 }
2049}
2050
2051/***
2052 * OLEDD_TrackStateChange()
2053 *
2054 * This method is invoked while a drag and drop operation is in effect.
2055 * It is used to notify the drop target/drop source callbacks when
2056 * the state of the keyboard or mouse button change.
2057 *
2058 * params:
2059 * trackerInfo - Pointer to the structure identifying the
2060 * drag & drop operation that is currently
2061 * active.
2062 * mousePos - Current position of the mouse in screen
2063 * coordinates.
2064 * keyState - Contains the state of the shift keys and the
2065 * mouse buttons (MK_LBUTTON and the like)
2066 */
2067static void OLEDD_TrackStateChange(
2068 TrackerWindowInfo* trackerInfo,
2069 POINT mousePos,
2070 DWORD keyState)
2071{
2072 /*
2073 * Ask the drop source what to do with the operation.
2074 */
2075 trackerInfo->returnValue = IDropSource_QueryContinueDrag(
2076 trackerInfo->dropSource,
2077 trackerInfo->escPressed,
2078 keyState);
2079
2080 /*
2081 * All the return valued will stop the operation except the S_OK
2082 * return value.
2083 */
2084 if (trackerInfo->returnValue!=S_OK)
2085 {
2086 /*
2087 * Make sure the message loop in DoDragDrop stops
2088 */
2089 trackerInfo->trackingDone = TRUE;
2090
2091 /*
2092 * Release the mouse in case the drop target decides to show a popup
2093 * or a menu or something.
2094 */
2095 ReleaseCapture();
2096
2097 /*
2098 * If we end-up over a target, drop the object in the target or
2099 * inform the target that the operation was cancelled.
2100 */
2101 if (trackerInfo->curDragTarget!=0)
2102 {
2103 switch (trackerInfo->returnValue)
2104 {
2105 /*
2106 * If the source wants us to complete the operation, we tell
2107 * the drop target that we just dropped the object in it.
2108 */
2109 case DRAGDROP_S_DROP:
2110 {
2111 POINTL mousePosParam;
2112
2113 /*
2114 * The documentation tells me that the coordinate should be
2115 * in the target window's coordinate space. However, the tests
2116 * I made tell me the coordinates should be in screen coordinates.
2117 */
2118 mousePosParam.x = mousePos.x;
2119 mousePosParam.y = mousePos.y;
2120
2121 IDropTarget_Drop(trackerInfo->curDragTarget,
2122 trackerInfo->dataObject,
2123 keyState,
2124 mousePosParam,
2125 trackerInfo->pdwEffect);
2126 break;
2127 }
2128 /*
2129 * If the source told us that we should cancel, fool the drop
2130 * target by telling it that the mouse left it's window.
2131 * Also set the drop effect to "NONE" in case the application
2132 * ignores the result of DoDragDrop.
2133 */
2134 case DRAGDROP_S_CANCEL:
2135 IDropTarget_DragLeave(trackerInfo->curDragTarget);
2136 *trackerInfo->pdwEffect = DROPEFFECT_NONE;
2137 break;
2138 }
2139 }
2140 }
2141}
2142
2143/***
2144 * OLEDD_GetButtonState()
2145 *
2146 * This method will use the current state of the keyboard to build
2147 * a button state mask equivalent to the one passed in the
2148 * WM_MOUSEMOVE wParam.
2149 */
2150static DWORD OLEDD_GetButtonState()
2151{
2152 BYTE keyboardState[256];
2153 DWORD keyMask = 0;
2154
2155 GetKeyboardState(keyboardState);
2156
2157 if ( (keyboardState[VK_SHIFT] & 0x80) !=0)
2158 keyMask |= MK_SHIFT;
2159
2160 if ( (keyboardState[VK_CONTROL] & 0x80) !=0)
2161 keyMask |= MK_CONTROL;
2162
2163 if ( (keyboardState[VK_LBUTTON] & 0x80) !=0)
2164 keyMask |= MK_LBUTTON;
2165
2166 if ( (keyboardState[VK_RBUTTON] & 0x80) !=0)
2167 keyMask |= MK_RBUTTON;
2168
2169 if ( (keyboardState[VK_MBUTTON] & 0x80) !=0)
2170 keyMask |= MK_MBUTTON;
2171
2172 return keyMask;
2173}
2174
2175/***
2176 * OLEDD_GetButtonState()
2177 *
2178 * This method will read the default value of the registry key in
2179 * parameter and extract a DWORD value from it. The registry key value
2180 * can be in a string key or a DWORD key.
2181 *
2182 * params:
2183 * regKey - Key to read the default value from
2184 * pdwValue - Pointer to the location where the DWORD
2185 * value is returned. This value is not modified
2186 * if the value is not found.
2187 */
2188
2189static void OLEUTL_ReadRegistryDWORDValue(
2190 HKEY regKey,
2191 DWORD* pdwValue)
2192{
2193 char buffer[20];
2194 DWORD dwKeyType;
2195 DWORD cbData = 20;
2196 LONG lres;
2197
2198 lres = RegQueryValueExA(regKey,
2199 "",
2200 NULL,
2201 &dwKeyType,
2202 (LPBYTE)buffer,
2203 &cbData);
2204
2205 if (lres==ERROR_SUCCESS)
2206 {
2207 switch (dwKeyType)
2208 {
2209 case REG_DWORD:
2210 *pdwValue = *(DWORD*)buffer;
2211 break;
2212 case REG_EXPAND_SZ:
2213 case REG_MULTI_SZ:
2214 case REG_SZ:
2215 *pdwValue = (DWORD)strtoul(buffer, NULL, 10);
2216 break;
2217 }
2218 }
2219}
2220#ifndef __WIN32OS2__
2221/******************************************************************************
2222 * OleMetaFilePictFromIconAndLabel (OLE2.56)
2223 *
2224 * Returns a global memory handle to a metafile which contains the icon and
2225 * label given.
2226 * I guess the result of that should look somehow like desktop icons.
2227 * If no hIcon is given, we load the icon via lpszSourceFile and iIconIndex.
2228 * This code might be wrong at some places.
2229 */
2230HGLOBAL16 WINAPI OleMetaFilePictFromIconAndLabel16(
2231 HICON16 hIcon,
2232 LPCOLESTR16 lpszLabel,
2233 LPCOLESTR16 lpszSourceFile,
2234 UINT16 iIconIndex
2235) {
2236 METAFILEPICT16 *mf;
2237 HGLOBAL16 hmf;
2238 HDC16 hdc;
2239
2240 FIXME("(%04x, '%s', '%s', %d): incorrect metrics, please try to correct them !\n\n\n", hIcon, lpszLabel, lpszSourceFile, iIconIndex);
2241
2242 if (!hIcon) {
2243 if (lpszSourceFile) {
2244 HINSTANCE16 hInstance = LoadLibrary16(lpszSourceFile);
2245
2246 /* load the icon at index from lpszSourceFile */
2247 hIcon = (HICON16)LoadIconA(hInstance, (LPCSTR)(DWORD)iIconIndex);
2248 FreeLibrary16(hInstance);
2249 } else
2250 return (HGLOBAL)NULL;
2251 }
2252
2253 hdc = CreateMetaFile16(NULL);
2254 DrawIcon(hdc, 0, 0, hIcon); /* FIXME */
2255 TextOutA(hdc, 0, 0, lpszLabel, 1); /* FIXME */
2256 hmf = GlobalAlloc16(0, sizeof(METAFILEPICT16));
2257 mf = (METAFILEPICT16 *)GlobalLock16(hmf);
2258 mf->mm = MM_ANISOTROPIC;
2259 mf->xExt = 20; /* FIXME: bogus */
2260 mf->yExt = 20; /* dito */
2261 mf->hMF = CloseMetaFile16(hdc);
2262 return hmf;
2263}
2264#endif
2265
2266/******************************************************************************
2267 * DllDebugObjectRPCHook (OLE32.62)
2268 * turns on and off internal debugging, pointer is only used on macintosh
2269 */
2270
2271BOOL WINAPI DllDebugObjectRPCHook(BOOL b, void *dummy)
2272{
2273 FIXME("stub\n");
2274 return TRUE;
2275}
2276
Note: See TracBrowser for help on using the repository browser.