home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / macfe / central / CTargetedUpdateMenuRegistry.cp < prev    next >
Encoding:
Text File  |  1998-04-08  |  3.2 KB  |  93 lines

  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2.  *
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  *
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  *
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18.  
  19. //    CTargetedUpdateMenuRegistry.cp
  20.  
  21. //
  22. //    CTargetedUpdateMenuRegistry is used in conjunction with LEventDispatchers
  23. //    which are CTargetedUpdateMenuRegistry-aware to enable a more targeted
  24. //    update of menus.
  25. //
  26. //    One common example of this is menu items whose text should change when
  27. //    certain modifiers are held down (Close -> Close All when optionKey is
  28. //    held down, for example).
  29. //
  30. //    Usage notes for callers of UpdateMenus:
  31. //
  32. //        (1) Call SetCommands with a list of commands which should be updated.
  33. //        (2) Call UpdateMenus.
  34. //
  35. //    Usage notes for implementors of UpdateMenus:
  36. //
  37. //        (1) When looping through commands in menus, determine if the registry
  38. //            is active by calling UseRegistryToUpdateMenus.
  39. //        (2) If the registry is active, then check to see if the command is
  40. //            in the registry by calling CommandInRegistry before processing
  41. //            command status for the command.
  42. //
  43. //    Note: For the targeted update to be useful, there should generally be
  44. //    a very small number of targeted commands. In fact, command lookup will
  45. //    slow down if there are too many commands.
  46.  
  47. #include "CTargetedUpdateMenuRegistry.h"
  48.  
  49. // === Static Members ===
  50.  
  51. Boolean            CTargetedUpdateMenuRegistry::sUseRegistryToUpdateMenus = false;
  52. list<CommandT>    CTargetedUpdateMenuRegistry::sCommands;
  53.  
  54. // ---------------------------------------------------------------------------
  55. //        Ñ SetCommands
  56. // ---------------------------------------------------------------------------
  57.  
  58. void
  59. CTargetedUpdateMenuRegistry::SetCommands(
  60.     const list<CommandT>& inCommands)
  61. {
  62.     sCommands = inCommands;
  63. }    
  64.  
  65. // ---------------------------------------------------------------------------
  66. //        Ñ UpdateMenus
  67. // ---------------------------------------------------------------------------
  68.  
  69. void
  70. CTargetedUpdateMenuRegistry::UpdateMenus()
  71. {
  72.     if (LEventDispatcher::GetCurrentEventDispatcher())
  73.     {
  74.         StValueChanger<Boolean> setUseRegistryToUpdateMenus(sUseRegistryToUpdateMenus, true);
  75.     
  76.         LEventDispatcher::GetCurrentEventDispatcher()->UpdateMenus();
  77.     }
  78. }
  79.  
  80. // ---------------------------------------------------------------------------
  81. //        Ñ CommandInRegistry
  82. // ---------------------------------------------------------------------------
  83.  
  84. Boolean
  85. CTargetedUpdateMenuRegistry::CommandInRegistry(CommandT inCommand)
  86. {
  87.     list<CommandT>::const_iterator theCommand = find(
  88.                                                         sCommands.begin(),
  89.                                                         sCommands.end(),
  90.                                                         inCommand);
  91.     return (theCommand != sCommands.end());
  92. }
  93.