home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / macfe / gui / CToolbarModeManager.cp < prev    next >
Encoding:
Text File  |  1998-04-08  |  2.2 KB  |  80 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. // CToolbarModeManager.cp
  20.  
  21. #include "CToolbarModeManager.h"
  22.  
  23. #include <UException.h>
  24.  
  25. #include "CToolbarPrefsProxy.h"
  26.  
  27. LBroadcaster* CToolbarModeManager::sBroadcaster = NULL;
  28. CToolbarPrefsProxy* CToolbarModeManager::sPrefsProxy = NULL;
  29.  
  30. #pragma mark -- CToolbarModeManager --
  31.  
  32. int CToolbarModeManager::BroadcastToolbarModeChange(
  33.     const char* /* domain */,
  34.     void* /* instance_data */)
  35. {
  36.     Int32 toolbarStyle;
  37.     int result = GetToolbarPref(toolbarStyle);
  38.     if (result == noErr)
  39.     {
  40.         if (sBroadcaster)
  41.             sBroadcaster->BroadcastMessage(msg_ToolbarModeChange,
  42.                                            (void*)toolbarStyle);
  43.     }
  44.     return result;
  45. }
  46.  
  47. void CToolbarModeManager::AddToolbarModeListener(LListener* inListener)
  48. {
  49.     try {
  50.         if (!sBroadcaster)
  51.             sBroadcaster = new LBroadcaster;
  52.         sBroadcaster->AddListener(inListener);
  53.     } catch (...) {
  54.         sBroadcaster = NULL;
  55.     }
  56. }
  57.  
  58. int CToolbarModeManager::GetToolbarPref(Int32& ioPref)
  59. {
  60.     int result = noErr;
  61.     if (sPrefsProxy)
  62.         result = sPrefsProxy->GetToolbarPref(ioPref);
  63.     else
  64.         ioPref = defaultToolbarMode;
  65.     return result;
  66. }
  67.  
  68. #pragma mark -- CToolbarModeChangeListener --
  69.  
  70. CToolbarModeChangeListener::CToolbarModeChangeListener()
  71. {
  72.     CToolbarModeManager::AddToolbarModeListener(this);
  73. }
  74.  
  75. void CToolbarModeChangeListener::ListenToMessage(MessageT inMessage, void* ioParam)
  76. {
  77.     if (inMessage == CToolbarModeManager::msg_ToolbarModeChange)
  78.         HandleModeChange((Int8)ioParam);
  79. }
  80.