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