[5601] | 1 | /* $Id: oleMenu.cpp,v 1.1 2001-04-26 19:26:14 sandervl Exp $ */
|
---|
| 2 | /*
|
---|
| 3 | *
|
---|
| 4 | * Project Odin Software License can be found in LICENSE.TXT
|
---|
| 5 | *
|
---|
| 6 | */
|
---|
| 7 | /*
|
---|
| 8 | * OLEMENU functions.
|
---|
| 9 | *
|
---|
| 10 | * 4/9/99
|
---|
| 11 | *
|
---|
| 12 | * Copyright 1999 David J. Raison
|
---|
| 13 | *
|
---|
| 14 | * Some portions from Wine Implementation (2/9/99)
|
---|
| 15 | * Copyright 1995 Martin von Loewis
|
---|
| 16 | * Copyright 1999 Francis Beaudet
|
---|
| 17 | * Copyright 1999 Noel Borthwick
|
---|
| 18 | */
|
---|
| 19 |
|
---|
| 20 | #include "ole32.h"
|
---|
| 21 | #include "commctrl.h"
|
---|
| 22 | #include "oString.h"
|
---|
| 23 | #include <assert.h>
|
---|
| 24 | #include "storage32.h"
|
---|
| 25 |
|
---|
| 26 | // ======================================================================
|
---|
| 27 | // Local Data
|
---|
| 28 | // ======================================================================
|
---|
| 29 |
|
---|
| 30 | typedef struct tagOleMenuDescriptor /* OleMenuDescriptor */
|
---|
| 31 | {
|
---|
| 32 | HWND hwndFrame; /* The containers frame window */
|
---|
| 33 | HWND hwndActiveObject; /* The active objects window */
|
---|
| 34 | OLEMENUGROUPWIDTHS mgw; /* OLE menu group widths for the shared menu */
|
---|
| 35 | HMENU hmenuCombined; /* The combined menu */
|
---|
| 36 | BOOL bIsServerItem; /* True if the currently open popup belongs to the server */
|
---|
| 37 | } OleMenuDescriptor;
|
---|
| 38 |
|
---|
| 39 | typedef struct tagOleMenuHookItem /* OleMenu hook item in per thread hook list */
|
---|
| 40 | {
|
---|
| 41 | DWORD tid; /* Thread Id */
|
---|
| 42 | HANDLE hHeap; /* Heap this is allocated from */
|
---|
| 43 | HHOOK GetMsg_hHook; /* message hook for WH_GETMESSAGE */
|
---|
| 44 | HHOOK CallWndProc_hHook; /* message hook for WH_CALLWNDPROC */
|
---|
| 45 | } OleMenuHookItem;
|
---|
| 46 |
|
---|
| 47 | /*
|
---|
| 48 | * Dynamic pointer array of per thread message hooks (maintained by OleSetMenuDescriptor)
|
---|
| 49 | */
|
---|
| 50 | static HDPA OLEMenu_MsgHookDPA = NULL;
|
---|
| 51 |
|
---|
| 52 |
|
---|
| 53 | // ======================================================================
|
---|
| 54 | // Prototypes.
|
---|
| 55 | // ======================================================================
|
---|
| 56 | static void OLEUTL_ReadRegistryDWORDValue(HKEY regKey, DWORD* pdwValue);
|
---|
| 57 |
|
---|
| 58 | // These are the prototypes of the utility methods used to manage a shared menu
|
---|
| 59 | extern void OLEMenu_Initialize();
|
---|
| 60 | extern void OLEMenu_UnInitialize();
|
---|
| 61 |
|
---|
| 62 | BOOL OLEMenu_InstallHooks( DWORD tid );
|
---|
| 63 | BOOL OLEMenu_UnInstallHooks( DWORD tid );
|
---|
| 64 | OleMenuHookItem * OLEMenu_IsHookInstalled( DWORD tid, INT *pixHook );
|
---|
| 65 | static BOOL OLEMenu_FindMainMenuIndex( HMENU hMainMenu, HMENU hPopupMenu, UINT *pnPos );
|
---|
| 66 | BOOL OLEMenu_SetIsServerMenu( HMENU hmenu, OleMenuDescriptor *pOleMenuDescriptor );
|
---|
| 67 | LRESULT CALLBACK OLEMenu_CallWndProc(INT code, WPARAM wParam, LPARAM lParam);
|
---|
| 68 | LRESULT CALLBACK OLEMenu_GetMsgProc(INT code, WPARAM wParam, LPARAM lParam);
|
---|
| 69 |
|
---|
| 70 | // ======================================================================
|
---|
| 71 | // Public API's
|
---|
| 72 | // ======================================================================
|
---|
| 73 |
|
---|
| 74 | /*
|
---|
| 75 | * OleCreateMenuDescriptor [OLE32.97]
|
---|
| 76 | * Creates an OLE menu descriptor for OLE to use when dispatching
|
---|
| 77 | * menu messages and commands.
|
---|
| 78 | *
|
---|
| 79 | * PARAMS:
|
---|
| 80 | * hmenuCombined - Handle to the objects combined menu
|
---|
| 81 | * lpMenuWidths - Pointer to array of 6 LONG's indicating menus per group
|
---|
| 82 | *
|
---|
| 83 | */
|
---|
| 84 | HOLEMENU WIN32API OleCreateMenuDescriptor(
|
---|
| 85 | HMENU hmenuCombined,
|
---|
| 86 | LPOLEMENUGROUPWIDTHS lpMenuWidths)
|
---|
| 87 | {
|
---|
| 88 | HOLEMENU hOleMenu;
|
---|
| 89 | OleMenuDescriptor *pOleMenuDescriptor;
|
---|
| 90 | int i;
|
---|
| 91 |
|
---|
| 92 | if ( !hmenuCombined || !lpMenuWidths )
|
---|
| 93 | return 0;
|
---|
| 94 |
|
---|
| 95 | /* Create an OLE menu descriptor */
|
---|
| 96 | if ( !(hOleMenu = GlobalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT,
|
---|
| 97 | sizeof(OleMenuDescriptor) ) ) )
|
---|
| 98 | return 0;
|
---|
| 99 |
|
---|
| 100 | pOleMenuDescriptor = (OleMenuDescriptor *) GlobalLock( hOleMenu );
|
---|
| 101 | if ( !pOleMenuDescriptor )
|
---|
| 102 | return 0;
|
---|
| 103 |
|
---|
| 104 | /* Initialize menu group widths and hmenu */
|
---|
| 105 | for ( i = 0; i < 6; i++ )
|
---|
| 106 | pOleMenuDescriptor->mgw.width[i] = lpMenuWidths->width[i];
|
---|
| 107 |
|
---|
| 108 | pOleMenuDescriptor->hmenuCombined = hmenuCombined;
|
---|
| 109 | pOleMenuDescriptor->bIsServerItem = FALSE;
|
---|
| 110 | GlobalUnlock( hOleMenu );
|
---|
| 111 |
|
---|
| 112 | return hOleMenu;
|
---|
| 113 | }
|
---|
| 114 |
|
---|
| 115 | /*
|
---|
| 116 | * OleDestroyMenuDescriptor [OLE32.99]
|
---|
| 117 | * Destroy the shared menu descriptor
|
---|
| 118 | */
|
---|
| 119 | HRESULT WIN32API OleDestroyMenuDescriptor(
|
---|
| 120 | HOLEMENU hmenuDescriptor)
|
---|
| 121 | {
|
---|
| 122 | if ( hmenuDescriptor )
|
---|
| 123 | GlobalFree( hmenuDescriptor );
|
---|
| 124 | return S_OK;
|
---|
| 125 | }
|
---|
| 126 |
|
---|
| 127 | /*
|
---|
| 128 | * OleSetMenuDescriptor [OLE32.129]
|
---|
| 129 | * Installs or removes OLE dispatching code for the containers frame window
|
---|
| 130 | * FIXME: The lpFrame and lpActiveObject parameters are currently ignored
|
---|
| 131 | * OLE should install context sensitive help F1 filtering for the app when
|
---|
| 132 | * these are non null.
|
---|
| 133 | *
|
---|
| 134 | * PARAMS:
|
---|
| 135 | * hOleMenu Handle to composite menu descriptor
|
---|
| 136 | * hwndFrame Handle to containers frame window
|
---|
| 137 | * hwndActiveObject Handle to objects in-place activation window
|
---|
| 138 | * lpFrame Pointer to IOleInPlaceFrame on containers window
|
---|
| 139 | * lpActiveObject Pointer to IOleInPlaceActiveObject on active in-place object
|
---|
| 140 | *
|
---|
| 141 | * RETURNS:
|
---|
| 142 | * S_OK - menu installed correctly
|
---|
| 143 | * E_FAIL, E_INVALIDARG, E_UNEXPECTED - failure
|
---|
| 144 | */
|
---|
| 145 | HRESULT WIN32API OleSetMenuDescriptor(
|
---|
| 146 | HOLEMENU hOleMenu,
|
---|
| 147 | HWND hwndFrame,
|
---|
| 148 | HWND hwndActiveObject,
|
---|
| 149 | LPOLEINPLACEFRAME lpFrame,
|
---|
| 150 | LPOLEINPLACEACTIVEOBJECT lpActiveObject)
|
---|
| 151 | {
|
---|
| 152 | OleMenuDescriptor *pOleMenuDescriptor = NULL;
|
---|
| 153 |
|
---|
| 154 | /* Check args */
|
---|
| 155 | if ( !hwndFrame || (hOleMenu && !hwndActiveObject) )
|
---|
| 156 | return E_INVALIDARG;
|
---|
| 157 |
|
---|
| 158 | if ( lpFrame || lpActiveObject )
|
---|
| 159 | {
|
---|
| 160 | dprintf(("OLE32: OleSetMenuDescriptor(%x, %x, %x, %p, %p), Context sensitive help filtering not implemented!\n",
|
---|
| 161 | (unsigned int)hOleMenu,
|
---|
| 162 | hwndFrame,
|
---|
| 163 | hwndActiveObject,
|
---|
| 164 | lpFrame,
|
---|
| 165 | lpActiveObject));
|
---|
| 166 | }
|
---|
| 167 |
|
---|
| 168 | /* Set up a message hook to intercept the containers frame window messages.
|
---|
| 169 | * The message filter is responsible for dispatching menu messages from the
|
---|
| 170 | * shared menu which are intended for the object.
|
---|
| 171 | */
|
---|
| 172 |
|
---|
| 173 | if ( hOleMenu ) /* Want to install dispatching code */
|
---|
| 174 | {
|
---|
| 175 | /* If OLEMenu hooks are already installed for this thread, fail
|
---|
| 176 | * Note: This effectively means that OleSetMenuDescriptor cannot
|
---|
| 177 | * be called twice in succession on the same frame window
|
---|
| 178 | * without first calling it with a null hOleMenu to uninstall */
|
---|
| 179 | if ( OLEMenu_IsHookInstalled( GetCurrentThreadId(), NULL ) )
|
---|
| 180 | return E_FAIL;
|
---|
| 181 |
|
---|
| 182 | /* Get the menu descriptor */
|
---|
| 183 | pOleMenuDescriptor = (OleMenuDescriptor *) GlobalLock( hOleMenu );
|
---|
| 184 | if ( !pOleMenuDescriptor )
|
---|
| 185 | return E_UNEXPECTED;
|
---|
| 186 |
|
---|
| 187 | /* Update the menu descriptor */
|
---|
| 188 | pOleMenuDescriptor->hwndFrame = hwndFrame;
|
---|
| 189 | pOleMenuDescriptor->hwndActiveObject = hwndActiveObject;
|
---|
| 190 |
|
---|
| 191 | GlobalUnlock( hOleMenu );
|
---|
| 192 | pOleMenuDescriptor = NULL;
|
---|
| 193 |
|
---|
| 194 | /* Add a menu descriptor windows property to the frame window */
|
---|
| 195 | SetPropA( hwndFrame, "PROP_OLEMenuDescriptor", hOleMenu );
|
---|
| 196 |
|
---|
| 197 | /* Install thread scope message hooks for WH_GETMESSAGE and WH_CALLWNDPROC */
|
---|
| 198 | if ( !OLEMenu_InstallHooks( GetCurrentThreadId() ) )
|
---|
| 199 | return E_FAIL;
|
---|
| 200 | }
|
---|
| 201 | else /* Want to uninstall dispatching code */
|
---|
| 202 | {
|
---|
| 203 | /* Uninstall the hooks */
|
---|
| 204 | if ( !OLEMenu_UnInstallHooks( GetCurrentThreadId() ) )
|
---|
| 205 | return E_FAIL;
|
---|
| 206 |
|
---|
| 207 | /* Remove the menu descriptor property from the frame window */
|
---|
| 208 | RemovePropA( hwndFrame, "PROP_OLEMenuDescriptor" );
|
---|
| 209 | }
|
---|
| 210 |
|
---|
| 211 | return S_OK;
|
---|
| 212 | }
|
---|
| 213 |
|
---|
| 214 | /*
|
---|
| 215 | * OLEMenu_Initialize()
|
---|
| 216 | *
|
---|
| 217 | * Initializes the OLEMENU data structures.
|
---|
| 218 | */
|
---|
| 219 | extern void OLEMenu_Initialize()
|
---|
| 220 | {
|
---|
| 221 | dprintf(("OLE32: OLEMenu_Initialize"));
|
---|
| 222 |
|
---|
| 223 | /* Create a dynamic pointer array to store the hook handles */
|
---|
| 224 | if ( !OLEMenu_MsgHookDPA )
|
---|
| 225 | OLEMenu_MsgHookDPA = DPA_CreateEx( 2, GetProcessHeap() );
|
---|
| 226 | }
|
---|
| 227 |
|
---|
| 228 | /*
|
---|
| 229 | * OLEMenu_UnInitialize()
|
---|
| 230 | *
|
---|
| 231 | * Releases the OLEMENU data structures.
|
---|
| 232 | */
|
---|
| 233 | extern void OLEMenu_UnInitialize()
|
---|
| 234 | {
|
---|
| 235 | dprintf(("OLE32: OLEMenu_UnInitialize"));
|
---|
| 236 |
|
---|
| 237 | /* Release the hook table */
|
---|
| 238 | if ( OLEMenu_MsgHookDPA )
|
---|
| 239 | DPA_Destroy( OLEMenu_MsgHookDPA );
|
---|
| 240 |
|
---|
| 241 | OLEMenu_MsgHookDPA = NULL;
|
---|
| 242 | }
|
---|
| 243 |
|
---|
| 244 | // ======================================================================
|
---|
| 245 | // Private functions.
|
---|
| 246 | // ======================================================================
|
---|
| 247 |
|
---|
| 248 | /*
|
---|
| 249 | * Internal methods to manage the shared OLE menu in response to the
|
---|
| 250 | * OLE***MenuDescriptor API
|
---|
| 251 | */
|
---|
| 252 |
|
---|
| 253 | /*
|
---|
| 254 | * OLEMenu_InstallHooks
|
---|
| 255 | * Install thread scope message hooks for WH_GETMESSAGE and WH_CALLWNDPROC
|
---|
| 256 | *
|
---|
| 257 | * RETURNS: TRUE if message hooks were succesfully installed
|
---|
| 258 | * FALSE on failure
|
---|
| 259 | */
|
---|
| 260 | BOOL OLEMenu_InstallHooks( DWORD tid )
|
---|
| 261 | {
|
---|
| 262 | OleMenuHookItem *pHookItem = NULL;
|
---|
| 263 |
|
---|
| 264 | if ( !OLEMenu_MsgHookDPA ) /* No hook table? Create one */
|
---|
| 265 | {
|
---|
| 266 | /* Create a dynamic pointer array to store the hook handles */
|
---|
| 267 | if ( !(OLEMenu_MsgHookDPA = DPA_CreateEx( 2, GetProcessHeap() )) )
|
---|
| 268 | return FALSE;
|
---|
| 269 | }
|
---|
| 270 |
|
---|
| 271 | /* Create an entry for the hook table */
|
---|
| 272 | if ( !(pHookItem = (OleMenuHookItem *)HeapAlloc(GetProcessHeap(), 0,
|
---|
| 273 | sizeof(OleMenuHookItem)) ) )
|
---|
| 274 | return FALSE;
|
---|
| 275 |
|
---|
| 276 | pHookItem->tid = tid;
|
---|
| 277 | pHookItem->hHeap = GetProcessHeap();
|
---|
| 278 |
|
---|
| 279 | /* Install a thread scope message hook for WH_GETMESSAGE */
|
---|
| 280 | pHookItem->GetMsg_hHook = SetWindowsHookExA( WH_GETMESSAGE, OLEMenu_GetMsgProc,
|
---|
| 281 | 0, GetCurrentThreadId() );
|
---|
| 282 | if ( !pHookItem->GetMsg_hHook )
|
---|
| 283 | goto CLEANUP;
|
---|
| 284 |
|
---|
| 285 | /* Install a thread scope message hook for WH_CALLWNDPROC */
|
---|
| 286 | pHookItem->CallWndProc_hHook = SetWindowsHookExA( WH_CALLWNDPROC, OLEMenu_CallWndProc,
|
---|
| 287 | 0, GetCurrentThreadId() );
|
---|
| 288 | if ( !pHookItem->CallWndProc_hHook )
|
---|
| 289 | goto CLEANUP;
|
---|
| 290 |
|
---|
| 291 | /* Insert the hook table entry */
|
---|
| 292 | if ( -1 == DPA_InsertPtr( OLEMenu_MsgHookDPA, 0, pHookItem ) )
|
---|
| 293 | goto CLEANUP;
|
---|
| 294 |
|
---|
| 295 | return TRUE;
|
---|
| 296 |
|
---|
| 297 | CLEANUP:
|
---|
| 298 | /* Unhook any hooks */
|
---|
| 299 | if ( pHookItem->GetMsg_hHook )
|
---|
| 300 | UnhookWindowsHookEx( pHookItem->GetMsg_hHook );
|
---|
| 301 | if ( pHookItem->CallWndProc_hHook )
|
---|
| 302 | UnhookWindowsHookEx( pHookItem->CallWndProc_hHook );
|
---|
| 303 | /* Release the hook table entry */
|
---|
| 304 | HeapFree(pHookItem->hHeap, 0, pHookItem );
|
---|
| 305 |
|
---|
| 306 | return FALSE;
|
---|
| 307 | }
|
---|
| 308 |
|
---|
| 309 | /*
|
---|
| 310 | * OLEMenu_UnInstallHooks
|
---|
| 311 | * UnInstall thread scope message hooks for WH_GETMESSAGE and WH_CALLWNDPROC
|
---|
| 312 | *
|
---|
| 313 | * RETURNS: TRUE if message hooks were succesfully installed
|
---|
| 314 | * FALSE on failure
|
---|
| 315 | */
|
---|
| 316 | BOOL OLEMenu_UnInstallHooks( DWORD tid )
|
---|
| 317 | {
|
---|
| 318 | INT ixHook;
|
---|
| 319 | OleMenuHookItem *pHookItem = NULL;
|
---|
| 320 |
|
---|
| 321 | if ( !OLEMenu_MsgHookDPA ) /* No hooks set */
|
---|
| 322 | return TRUE;
|
---|
| 323 |
|
---|
| 324 | /* Lookup the hHook index for this tid */
|
---|
| 325 | if ( !OLEMenu_IsHookInstalled( tid , &ixHook ) )
|
---|
| 326 | return TRUE;
|
---|
| 327 |
|
---|
| 328 | /* Remove the hook entry from the table(the pointer itself is not deleted) */
|
---|
| 329 | if ( !( pHookItem = (OleMenuHookItem *)DPA_DeletePtr(OLEMenu_MsgHookDPA, ixHook) ) )
|
---|
| 330 | return FALSE;
|
---|
| 331 |
|
---|
| 332 | /* Uninstall the hooks installed for this thread */
|
---|
| 333 | if ( !UnhookWindowsHookEx( pHookItem->GetMsg_hHook ) )
|
---|
| 334 | goto CLEANUP;
|
---|
| 335 | if ( !UnhookWindowsHookEx( pHookItem->CallWndProc_hHook ) )
|
---|
| 336 | goto CLEANUP;
|
---|
| 337 |
|
---|
| 338 | /* Release the hook table entry */
|
---|
| 339 | HeapFree(pHookItem->hHeap, 0, pHookItem );
|
---|
| 340 |
|
---|
| 341 | return TRUE;
|
---|
| 342 |
|
---|
| 343 | CLEANUP:
|
---|
| 344 | /* Release the hook table entry */
|
---|
| 345 | if (pHookItem)
|
---|
| 346 | HeapFree(pHookItem->hHeap, 0, pHookItem );
|
---|
| 347 |
|
---|
| 348 | return FALSE;
|
---|
| 349 | }
|
---|
| 350 |
|
---|
| 351 | /*
|
---|
| 352 | * OLEMenu_IsHookInstalled
|
---|
| 353 | * Tests if OLEMenu hooks have been installed for a thread
|
---|
| 354 | *
|
---|
| 355 | * RETURNS: The pointer and index of the hook table entry for the tid
|
---|
| 356 | * NULL and -1 for the index if no hooks were installed for this thread
|
---|
| 357 | */
|
---|
| 358 | OleMenuHookItem * OLEMenu_IsHookInstalled( DWORD tid, INT *pixHook )
|
---|
| 359 | {
|
---|
| 360 | INT ixHook;
|
---|
| 361 | OleMenuHookItem *pHookItem = NULL;
|
---|
| 362 |
|
---|
| 363 | if ( pixHook )
|
---|
| 364 | *pixHook = -1;
|
---|
| 365 |
|
---|
| 366 | if ( !OLEMenu_MsgHookDPA ) /* No hooks set */
|
---|
| 367 | return NULL;
|
---|
| 368 |
|
---|
| 369 | /* Do a simple linear search for an entry whose tid matches ours.
|
---|
| 370 | * We really need a map but efficiency is not a concern here. */
|
---|
| 371 | for( ixHook = 0; ; ixHook++ )
|
---|
| 372 | {
|
---|
| 373 | /* Retrieve the hook entry */
|
---|
| 374 | if ( !( pHookItem = (OleMenuHookItem *)DPA_GetPtr(OLEMenu_MsgHookDPA, ixHook) ) )
|
---|
| 375 | return NULL;
|
---|
| 376 |
|
---|
| 377 | if ( tid == pHookItem->tid )
|
---|
| 378 | {
|
---|
| 379 | if ( pixHook )
|
---|
| 380 | *pixHook = ixHook;
|
---|
| 381 | return pHookItem;
|
---|
| 382 | }
|
---|
| 383 | }
|
---|
| 384 |
|
---|
| 385 | return NULL;
|
---|
| 386 | }
|
---|
| 387 |
|
---|
| 388 | /*
|
---|
| 389 | * OLEMenu_FindMainMenuIndex
|
---|
| 390 | *
|
---|
| 391 | * Used by OLEMenu API to find the top level group a menu item belongs to.
|
---|
| 392 | * On success pnPos contains the index of the item in the top level menu group
|
---|
| 393 | *
|
---|
| 394 | * RETURNS: TRUE if the ID was found, FALSE on failure
|
---|
| 395 | */
|
---|
| 396 | static BOOL OLEMenu_FindMainMenuIndex( HMENU hMainMenu, HMENU hPopupMenu, UINT *pnPos )
|
---|
| 397 | {
|
---|
| 398 | UINT i, nItems;
|
---|
| 399 |
|
---|
| 400 | nItems = GetMenuItemCount( hMainMenu );
|
---|
| 401 |
|
---|
| 402 | for (i = 0; i < nItems; i++)
|
---|
| 403 | {
|
---|
| 404 | HMENU hsubmenu;
|
---|
| 405 |
|
---|
| 406 | /* Is the current item a submenu? */
|
---|
| 407 | if ( (hsubmenu = GetSubMenu(hMainMenu, i)) != NULL)
|
---|
| 408 | {
|
---|
| 409 | /* If the handle is the same we're done */
|
---|
| 410 | if ( hsubmenu == hPopupMenu )
|
---|
| 411 | {
|
---|
| 412 | if (pnPos)
|
---|
| 413 | *pnPos = i;
|
---|
| 414 | return TRUE;
|
---|
| 415 | }
|
---|
| 416 | /* Recursively search without updating pnPos */
|
---|
| 417 | else if ( OLEMenu_FindMainMenuIndex( hsubmenu, hPopupMenu, NULL ) )
|
---|
| 418 | {
|
---|
| 419 | if (pnPos)
|
---|
| 420 | *pnPos = i;
|
---|
| 421 | return TRUE;
|
---|
| 422 | }
|
---|
| 423 | }
|
---|
| 424 | }
|
---|
| 425 |
|
---|
| 426 | return FALSE;
|
---|
| 427 | }
|
---|
| 428 |
|
---|
| 429 | /*
|
---|
| 430 | * OLEMenu_SetIsServerMenu
|
---|
| 431 | *
|
---|
| 432 | * Checks whether a popup menu belongs to a shared menu group which is
|
---|
| 433 | * owned by the server, and sets the menu descriptor state accordingly.
|
---|
| 434 | * All menu messages from these groups should be routed to the server.
|
---|
| 435 | *
|
---|
| 436 | * RETURNS: TRUE if the popup menu is part of a server owned group
|
---|
| 437 | * FASE if the popup menu is part of a container owned group
|
---|
| 438 | */
|
---|
| 439 | BOOL OLEMenu_SetIsServerMenu( HMENU hmenu, OleMenuDescriptor *pOleMenuDescriptor )
|
---|
| 440 | {
|
---|
| 441 | UINT nPos = 0, nWidth, i;
|
---|
| 442 |
|
---|
| 443 | pOleMenuDescriptor->bIsServerItem = FALSE;
|
---|
| 444 |
|
---|
| 445 | /* Don't bother searching if the popup is the combined menu itself */
|
---|
| 446 | if ( hmenu == pOleMenuDescriptor->hmenuCombined )
|
---|
| 447 | return FALSE;
|
---|
| 448 |
|
---|
| 449 | /* Find the menu item index in the shared OLE menu that this item belongs to */
|
---|
| 450 | if ( !OLEMenu_FindMainMenuIndex( pOleMenuDescriptor->hmenuCombined, hmenu, &nPos ) )
|
---|
| 451 | return FALSE;
|
---|
| 452 |
|
---|
| 453 | /* The group widths array has counts for the number of elements
|
---|
| 454 | * in the groups File, Edit, Container, Object, Window, Help.
|
---|
| 455 | * The Edit, Object & Help groups belong to the server object
|
---|
| 456 | * and the other three belong to the container.
|
---|
| 457 | * Loop thru the group widths and locate the group we are a member of.
|
---|
| 458 | */
|
---|
| 459 | for ( i = 0, nWidth = 0; i < 6; i++ )
|
---|
| 460 | {
|
---|
| 461 | nWidth += pOleMenuDescriptor->mgw.width[i];
|
---|
| 462 | if ( nPos < nWidth )
|
---|
| 463 | {
|
---|
| 464 | /* Odd elements are server menu widths */
|
---|
| 465 | pOleMenuDescriptor->bIsServerItem = (i%2) ? TRUE : FALSE;
|
---|
| 466 | break;
|
---|
| 467 | }
|
---|
| 468 | }
|
---|
| 469 |
|
---|
| 470 | return pOleMenuDescriptor->bIsServerItem;
|
---|
| 471 | }
|
---|
| 472 |
|
---|
| 473 | /*
|
---|
| 474 | * OLEMenu_CallWndProc
|
---|
| 475 | * Thread scope WH_CALLWNDPROC hook proc filter function (callback)
|
---|
| 476 | * This is invoked from a message hook installed in OleSetMenuDescriptor.
|
---|
| 477 | */
|
---|
| 478 | LRESULT CALLBACK OLEMenu_CallWndProc(INT code, WPARAM wParam, LPARAM lParam)
|
---|
| 479 | {
|
---|
| 480 | LPCWPSTRUCT pMsg = NULL;
|
---|
| 481 | HOLEMENU hOleMenu = 0;
|
---|
| 482 | OleMenuDescriptor *pOleMenuDescriptor = NULL;
|
---|
| 483 | OleMenuHookItem *pHookItem = NULL;
|
---|
| 484 | WORD fuFlags;
|
---|
| 485 |
|
---|
| 486 | dprintf(("OLE32: OLEMenu_CallWndProc %i, %04x, %08x", code, wParam, (unsigned)lParam));
|
---|
| 487 |
|
---|
| 488 | /* Check if we're being asked to process the message */
|
---|
| 489 | if ( HC_ACTION != code )
|
---|
| 490 | goto NEXTHOOK;
|
---|
| 491 |
|
---|
| 492 | /* Retrieve the current message being dispatched from lParam */
|
---|
| 493 | pMsg = (LPCWPSTRUCT)lParam;
|
---|
| 494 |
|
---|
| 495 | /* Check if the message is destined for a window we are interested in:
|
---|
| 496 | * If the window has an OLEMenu property we may need to dispatch
|
---|
| 497 | * the menu message to its active objects window instead. */
|
---|
| 498 |
|
---|
| 499 | hOleMenu = (HOLEMENU)GetPropA( pMsg->hwnd, "PROP_OLEMenuDescriptor" );
|
---|
| 500 | if ( !hOleMenu )
|
---|
| 501 | goto NEXTHOOK;
|
---|
| 502 |
|
---|
| 503 | /* Get the menu descriptor */
|
---|
| 504 | pOleMenuDescriptor = (OleMenuDescriptor *) GlobalLock( hOleMenu );
|
---|
| 505 | if ( !pOleMenuDescriptor ) /* Bad descriptor! */
|
---|
| 506 | goto NEXTHOOK;
|
---|
| 507 |
|
---|
| 508 | /* Process menu messages */
|
---|
| 509 | switch( pMsg->message )
|
---|
| 510 | {
|
---|
| 511 | case WM_INITMENU:
|
---|
| 512 | {
|
---|
| 513 | /* Reset the menu descriptor state */
|
---|
| 514 | pOleMenuDescriptor->bIsServerItem = FALSE;
|
---|
| 515 |
|
---|
| 516 | /* Send this message to the server as well */
|
---|
| 517 | SendMessageA( pOleMenuDescriptor->hwndActiveObject,
|
---|
| 518 | pMsg->message, pMsg->wParam, pMsg->lParam );
|
---|
| 519 | goto NEXTHOOK;
|
---|
| 520 | }
|
---|
| 521 |
|
---|
| 522 | case WM_INITMENUPOPUP:
|
---|
| 523 | {
|
---|
| 524 | /* Save the state for whether this is a server owned menu */
|
---|
| 525 | OLEMenu_SetIsServerMenu( (HMENU)pMsg->wParam, pOleMenuDescriptor );
|
---|
| 526 | break;
|
---|
| 527 | }
|
---|
| 528 |
|
---|
| 529 | case WM_MENUSELECT:
|
---|
| 530 | {
|
---|
| 531 | fuFlags = HIWORD(pMsg->wParam); /* Get flags */
|
---|
| 532 | if ( fuFlags & MF_SYSMENU )
|
---|
| 533 | goto NEXTHOOK;
|
---|
| 534 |
|
---|
| 535 | /* Save the state for whether this is a server owned popup menu */
|
---|
| 536 | else if ( fuFlags & MF_POPUP )
|
---|
| 537 | OLEMenu_SetIsServerMenu( (HMENU)pMsg->lParam, pOleMenuDescriptor );
|
---|
| 538 |
|
---|
| 539 | break;
|
---|
| 540 | }
|
---|
| 541 |
|
---|
| 542 | case WM_DRAWITEM:
|
---|
| 543 | {
|
---|
| 544 | LPDRAWITEMSTRUCT lpdis = (LPDRAWITEMSTRUCT) pMsg->lParam;
|
---|
| 545 | if ( pMsg->wParam != 0 || lpdis->CtlType != ODT_MENU )
|
---|
| 546 | goto NEXTHOOK; /* Not a menu message */
|
---|
| 547 |
|
---|
| 548 | break;
|
---|
| 549 | }
|
---|
| 550 |
|
---|
| 551 | default:
|
---|
| 552 | goto NEXTHOOK;
|
---|
| 553 | }
|
---|
| 554 |
|
---|
| 555 | /* If the message was for the server dispatch it accordingly */
|
---|
| 556 | if ( pOleMenuDescriptor->bIsServerItem )
|
---|
| 557 | {
|
---|
| 558 | SendMessageA( pOleMenuDescriptor->hwndActiveObject,
|
---|
| 559 | pMsg->message, pMsg->wParam, pMsg->lParam );
|
---|
| 560 | }
|
---|
| 561 |
|
---|
| 562 | NEXTHOOK:
|
---|
| 563 | if ( pOleMenuDescriptor )
|
---|
| 564 | GlobalUnlock( hOleMenu );
|
---|
| 565 |
|
---|
| 566 | /* Lookup the hook item for the current thread */
|
---|
| 567 | if ( !( pHookItem = OLEMenu_IsHookInstalled( GetCurrentThreadId(), NULL ) ) )
|
---|
| 568 | {
|
---|
| 569 | /* This should never fail!! */
|
---|
| 570 | dprintf(("Warning: Could not retrieve hHook for current thread!"));
|
---|
| 571 | return 0;
|
---|
| 572 | }
|
---|
| 573 |
|
---|
| 574 | /* Pass on the message to the next hooker */
|
---|
| 575 | return CallNextHookEx( pHookItem->CallWndProc_hHook, code, wParam, lParam );
|
---|
| 576 | }
|
---|
| 577 |
|
---|
| 578 | /*
|
---|
| 579 | * OLEMenu_GetMsgProc
|
---|
| 580 | * Thread scope WH_GETMESSAGE hook proc filter function (callback)
|
---|
| 581 | * This is invoked from a message hook installed in OleSetMenuDescriptor.
|
---|
| 582 | */
|
---|
| 583 | LRESULT CALLBACK OLEMenu_GetMsgProc(INT code, WPARAM wParam, LPARAM lParam)
|
---|
| 584 | {
|
---|
| 585 | LPMSG pMsg = NULL;
|
---|
| 586 | HOLEMENU hOleMenu = 0;
|
---|
| 587 | OleMenuDescriptor *pOleMenuDescriptor = NULL;
|
---|
| 588 | OleMenuHookItem *pHookItem = NULL;
|
---|
| 589 | WORD wCode;
|
---|
| 590 |
|
---|
| 591 | dprintf(("OLE32: OLEMenu_GetMsgProc %i, %04x, %08x", code, wParam, (unsigned)lParam ));
|
---|
| 592 |
|
---|
| 593 | /* Check if we're being asked to process a messages */
|
---|
| 594 | if ( HC_ACTION != code )
|
---|
| 595 | goto NEXTHOOK;
|
---|
| 596 |
|
---|
| 597 | /* Retrieve the current message being dispatched from lParam */
|
---|
| 598 | pMsg = (LPMSG)lParam;
|
---|
| 599 |
|
---|
| 600 | /* Check if the message is destined for a window we are interested in:
|
---|
| 601 | * If the window has an OLEMenu property we may need to dispatch
|
---|
| 602 | * the menu message to its active objects window instead. */
|
---|
| 603 |
|
---|
| 604 | hOleMenu = (HOLEMENU)GetPropA( pMsg->hwnd, "PROP_OLEMenuDescriptor" );
|
---|
| 605 | if ( !hOleMenu )
|
---|
| 606 | goto NEXTHOOK;
|
---|
| 607 |
|
---|
| 608 | /* Process menu messages */
|
---|
| 609 | switch( pMsg->message )
|
---|
| 610 | {
|
---|
| 611 | case WM_COMMAND:
|
---|
| 612 | {
|
---|
| 613 | wCode = HIWORD(pMsg->wParam); /* Get notification code */
|
---|
| 614 | if ( wCode )
|
---|
| 615 | goto NEXTHOOK; /* Not a menu message */
|
---|
| 616 | break;
|
---|
| 617 | }
|
---|
| 618 | default:
|
---|
| 619 | goto NEXTHOOK;
|
---|
| 620 | }
|
---|
| 621 |
|
---|
| 622 | /* Get the menu descriptor */
|
---|
| 623 | pOleMenuDescriptor = (OleMenuDescriptor *) GlobalLock( hOleMenu );
|
---|
| 624 | if ( !pOleMenuDescriptor ) /* Bad descriptor! */
|
---|
| 625 | goto NEXTHOOK;
|
---|
| 626 |
|
---|
| 627 | /* If the message was for the server dispatch it accordingly */
|
---|
| 628 | if ( pOleMenuDescriptor->bIsServerItem )
|
---|
| 629 | {
|
---|
| 630 | /* Change the hWnd in the message to the active objects hWnd.
|
---|
| 631 | * The message loop which reads this message will automatically
|
---|
| 632 | * dispatch it to the embedded objects window. */
|
---|
| 633 | pMsg->hwnd = pOleMenuDescriptor->hwndActiveObject;
|
---|
| 634 | }
|
---|
| 635 |
|
---|
| 636 | NEXTHOOK:
|
---|
| 637 | if ( pOleMenuDescriptor )
|
---|
| 638 | GlobalUnlock( hOleMenu );
|
---|
| 639 |
|
---|
| 640 | /* Lookup the hook item for the current thread */
|
---|
| 641 | if ( !( pHookItem = OLEMenu_IsHookInstalled( GetCurrentThreadId(), NULL ) ) )
|
---|
| 642 | {
|
---|
| 643 | /* This should never fail!! */
|
---|
| 644 | dprintf(("Warning: Could not retrieve hHook for current thread!\n" ));
|
---|
| 645 | return FALSE;
|
---|
| 646 | }
|
---|
| 647 |
|
---|
| 648 | /* Pass on the message to the next hooker */
|
---|
| 649 | return CallNextHookEx( pHookItem->GetMsg_hHook, code, wParam, lParam );
|
---|
| 650 | }
|
---|
| 651 |
|
---|