home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / lib / mac / UserInterface / CSelectionBroadcastingList.cp < prev    next >
Encoding:
Text File  |  1998-04-08  |  5.6 KB  |  204 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. #include "CSelectionBroadcastingList.h"
  20.  
  21. #include <LStream.h>
  22.  
  23. // ---------------------------------------------------------------------------
  24. //        Ñ CreateFromStream [static]
  25. // ---------------------------------------------------------------------------
  26.  
  27. void*
  28. CSelectionBroadcastingList::CreateFromStream(
  29.     LStream    *inStream)
  30. {
  31.     return (new CSelectionBroadcastingList(inStream));
  32. }
  33.  
  34. // ---------------------------------------------------------------------------
  35. //        Ñ CSelectionBroadcastingList
  36. // ---------------------------------------------------------------------------
  37.  
  38. CSelectionBroadcastingList::CSelectionBroadcastingList(
  39.     LStream    *inStream)
  40.     :    fAllowSelectionChange(true),
  41.     
  42.         super(inStream)
  43. {
  44.     inStream->ReadData(&fMessage, sizeof(fMessage));
  45. }
  46.  
  47. // ---------------------------------------------------------------------------
  48. //        Ñ ~CSelectionBroadcastingList
  49. // ---------------------------------------------------------------------------
  50.  
  51. CSelectionBroadcastingList::~CSelectionBroadcastingList()
  52. {
  53. }
  54.  
  55. // ---------------------------------------------------------------------------
  56. //        Ñ SetBroadcastMessage
  57. // ---------------------------------------------------------------------------
  58.  
  59. void
  60. CSelectionBroadcastingList::SetBroadcastMessage(MessageT inMessage)
  61. {
  62.     fMessage = inMessage;
  63. }
  64.  
  65. // ---------------------------------------------------------------------------
  66. //        Ñ GetBroadcastMessage
  67. // ---------------------------------------------------------------------------
  68.  
  69. MessageT
  70. CSelectionBroadcastingList::GetBroadcastMessage()
  71. {
  72.     return fMessage;
  73. }
  74.  
  75. // ---------------------------------------------------------------------------
  76. //        Ñ SetValue
  77. // ---------------------------------------------------------------------------
  78.  
  79. void
  80. CSelectionBroadcastingList::SetValue(Int32 inValue)
  81. {
  82.     if (fAllowSelectionChange)
  83.     {
  84.         super::SetValue(inValue);
  85.         
  86.         BroadcastMessage(fMessage, this);
  87.     }
  88. }
  89.  
  90. // ---------------------------------------------------------------------------
  91. //        Ñ DoNavigationKey
  92. // ---------------------------------------------------------------------------
  93.  
  94. void
  95. CSelectionBroadcastingList::DoNavigationKey(
  96.     const EventRecord    &inKeyEvent)
  97. {
  98.     int before = NumCellsSelected();
  99.     
  100.     if (fAllowSelectionChange)
  101.     {
  102.         super::DoNavigationKey(inKeyEvent);
  103.         
  104.             // if num selected hasn't changed, then don't send message
  105.         if (NumCellsSelected() != before)
  106.             BroadcastMessage(fMessage, this);
  107.     }
  108. }    
  109.  
  110. // ---------------------------------------------------------------------------
  111. //        Ñ DoTypeSelection
  112. // ---------------------------------------------------------------------------
  113.  
  114. void
  115. CSelectionBroadcastingList::DoTypeSelection(
  116.     const EventRecord& inKeyEvent)
  117. {    
  118.     if (fAllowSelectionChange)
  119.     {
  120.         super::DoTypeSelection(inKeyEvent);
  121.         
  122.         BroadcastMessage(fMessage, this);
  123.     }
  124. }
  125.  
  126. // ---------------------------------------------------------------------------
  127. //        Ñ SelectOneCell
  128. // ---------------------------------------------------------------------------
  129.  
  130. void
  131. CSelectionBroadcastingList::SelectOneCell(
  132.     Cell    inCell)
  133. {
  134.     if (fAllowSelectionChange)
  135.     {
  136.         super::SelectOneCell(inCell);
  137.         
  138.         BroadcastMessage(fMessage, this);
  139.     }
  140. }
  141.  
  142. // ---------------------------------------------------------------------------
  143. //        Ñ ClickSelf
  144. // ---------------------------------------------------------------------------
  145.  
  146. void
  147. CSelectionBroadcastingList::ClickSelf(
  148.     const SMouseDownEvent    &inMouseDown)
  149. {
  150.     int before = NumCellsSelected();
  151.  
  152.     if (fAllowSelectionChange)
  153.     {
  154.         super::ClickSelf(inMouseDown);
  155.         
  156.             // if num selected hasn't changed, then don't send message
  157.         if (NumCellsSelected() != before)
  158.             BroadcastMessage(fMessage, this);
  159.     }
  160. }
  161.  
  162. // ---------------------------------------------------------------------------
  163. //        Ñ DontAllowSelectionChange
  164. // ---------------------------------------------------------------------------
  165.  
  166. void
  167. CSelectionBroadcastingList::DontAllowSelectionChange()
  168. {
  169.     fAllowSelectionChange = false;
  170. }
  171.  
  172. // ---------------------------------------------------------------------------
  173. //        Ñ AllowSelectionChange
  174. // ---------------------------------------------------------------------------
  175.  
  176. void
  177. CSelectionBroadcastingList::AllowSelectionChange()
  178. {
  179.     fAllowSelectionChange = true;
  180. }
  181.  
  182. // ---------------------------------------------------------------------------
  183. //        Ñ NumCellsSelected
  184. // ---------------------------------------------------------------------------
  185.  
  186. int
  187. CSelectionBroadcastingList::NumCellsSelected()
  188. {
  189.     int        numSelected = 0;
  190.     Cell    currentCell = {0, 0};
  191.     Boolean    hasSelection = ::LGetSelect(true, ¤tCell, mMacListH);
  192.     
  193.     if (hasSelection)
  194.     {
  195.         do
  196.         {
  197.             if (::LGetSelect(true, ¤tCell, mMacListH))
  198.                 numSelected++;
  199.         } while (::LNextCell(true, true, ¤tCell, mMacListH));
  200.     }
  201.     
  202.     return numSelected;
  203. }
  204.