Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
TToggleGroup.cxx
Go to the documentation of this file.
1 // @(#)root/meta:$Id$
2 // Author: Piotr Golonka 31/07/97
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 /** \class TToggleGroup
13 
14 This class defines check-box facility for TToggle objects
15 It is used in context menu "selectors" for picking up a value.
16 */
17 
18 
19 #include "TToggleGroup.h"
20 
21 ClassImp(TToggleGroup);
22 
23 ////////////////////////////////////////////////////////////////////////////////
24 /// Constructor.
25 
26 TToggleGroup::TToggleGroup()
27 {
28  fToggles = new TOrdCollection();
29 }
30 
31 ////////////////////////////////////////////////////////////////////////////////
32 /// Copy constructor
33 
34 TToggleGroup::TToggleGroup(const TToggleGroup& rhs) : TNamed(rhs),fToggles(0)
35 {
36  fToggles = (TOrdCollection*)rhs.fToggles->Clone();
37 }
38 
39 ////////////////////////////////////////////////////////////////////////////////
40 /// Assignment operator.
41 
42 TToggleGroup &TToggleGroup::operator=(const TToggleGroup &rhs)
43 {
44  if (this != &rhs) {
45  delete fToggles;
46  fToggles = (TOrdCollection*)rhs.fToggles->Clone();
47  }
48  return *this;
49 }
50 
51 
52 ////////////////////////////////////////////////////////////////////////////////
53 /// Deletes togglegroup but does not disposes toggled objects!
54 
55 TToggleGroup::~TToggleGroup()
56 {
57  delete fToggles;
58 }
59 
60 ////////////////////////////////////////////////////////////////////////////////
61 /// Add a new toggle.
62 
63 Int_t TToggleGroup::Add(TToggle *t, Bool_t select)
64 {
65  if (t) {
66  fToggles->AddLast(t);
67  if (select)
68  Select(t);
69  return IndexOf(t);
70  } else
71  return (-1);
72 }
73 
74 ////////////////////////////////////////////////////////////////////////////////
75 /// Add a new toggle at a specific position.
76 
77 Int_t TToggleGroup::InsertAt(TToggle *t, Int_t pos,Bool_t select)
78 {
79  if (t) {
80  fToggles->AddAt(t,pos);
81  if (select)
82  Select(t);
83  return IndexOf(t);
84  } else
85  return (-1);
86 }
87 
88 ////////////////////////////////////////////////////////////////////////////////
89 /// Select a toggle.
90 
91 void TToggleGroup::Select(Int_t idx)
92 {
93  TToggle *sel = At(idx);
94  if (sel)
95  Select(sel);
96 }
97 
98 ////////////////////////////////////////////////////////////////////////////////
99 /// Selector a toggle.
100 
101 void TToggleGroup::Select(TToggle *t)
102 {
103  TIter next(fToggles);
104  TToggle *i = 0;
105 
106  // Untoggle toggled , and toggle this one if it's present on a list!
107 
108  while ((i = (TToggle*)next()))
109  if ( i->GetState() || (i==t) )
110  i->Toggle();
111 }
112 
113 ////////////////////////////////////////////////////////////////////////////////
114 /// Disposes of all objects and clears array
115 
116 void TToggleGroup::DeleteAll()
117 {
118  fToggles->Delete();
119 }