00001 // @(#)root/meta:$Id: TToggleGroup.cxx 26606 2008-12-02 20:36:09Z pcanal $ 00002 // Author: Piotr Golonka 31/07/97 00003 00004 /************************************************************************* 00005 * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. * 00006 * All rights reserved. * 00007 * * 00008 * For the licensing terms see $ROOTSYS/LICENSE. * 00009 * For the list of contributors see $ROOTSYS/README/CREDITS. * 00010 *************************************************************************/ 00011 00012 ////////////////////////////////////////////////////////////////////////// 00013 // // 00014 // TToggleGroup // 00015 // // 00016 // This class defines check-box facility for TToggle objects // 00017 // It is used in context menu "selectors" for picking up a value. // 00018 // // 00019 ////////////////////////////////////////////////////////////////////////// 00020 00021 00022 #include "TMethod.h" 00023 #include "TToggleGroup.h" 00024 00025 ClassImp(TToggleGroup) 00026 00027 //______________________________________________________________________________ 00028 TToggleGroup::TToggleGroup() 00029 { 00030 // Constructor. 00031 00032 fToggles = new TOrdCollection(); 00033 } 00034 00035 //______________________________________________________________________________ 00036 TToggleGroup::TToggleGroup(const TToggleGroup& rhs) : TNamed(rhs),fToggles(0) 00037 { 00038 // Copy constructor 00039 fToggles = (TOrdCollection*)rhs.fToggles->Clone(); 00040 } 00041 00042 //______________________________________________________________________________ 00043 TToggleGroup &TToggleGroup::operator=(const TToggleGroup &rhs) 00044 { 00045 // Assignment operastor. 00046 00047 delete fToggles; 00048 fToggles = (TOrdCollection*)rhs.fToggles->Clone(); 00049 return *this; 00050 } 00051 00052 00053 //______________________________________________________________________________ 00054 TToggleGroup::~TToggleGroup() 00055 { 00056 // Deletes togglegroup but does not disposes toggled objects! 00057 00058 delete fToggles; 00059 } 00060 00061 //______________________________________________________________________________ 00062 Int_t TToggleGroup::Add(TToggle *t, Bool_t select) 00063 { 00064 // Add a new toggle. 00065 00066 if (t) { 00067 fToggles->AddLast(t); 00068 if (select) 00069 Select(t); 00070 return IndexOf(t); 00071 } else 00072 return (-1); 00073 } 00074 00075 //______________________________________________________________________________ 00076 Int_t TToggleGroup::InsertAt(TToggle *t, Int_t pos,Bool_t select) 00077 { 00078 // Add a new toggle at a specific position. 00079 00080 if (t) { 00081 fToggles->AddAt(t,pos); 00082 if (select) 00083 Select(t); 00084 return IndexOf(t); 00085 } else 00086 return (-1); 00087 } 00088 00089 //______________________________________________________________________________ 00090 void TToggleGroup::Select(Int_t idx) 00091 { 00092 // Select a toggle. 00093 00094 TToggle *sel = At(idx); 00095 if (sel) 00096 Select(sel); 00097 } 00098 00099 //______________________________________________________________________________ 00100 void TToggleGroup::Select(TToggle *t) 00101 { 00102 // Selector a toggle. 00103 00104 TIter next(fToggles); 00105 TToggle *i = 0; 00106 00107 // Untoggle toggled , and toggle this one if it's present on a list! 00108 00109 while ((i = (TToggle*)next())) 00110 if ( i->GetState() || (i==t) ) 00111 i->Toggle(); 00112 } 00113 00114 //______________________________________________________________________________ 00115 void TToggleGroup::DeleteAll() 00116 { 00117 // Disposes of all objects and clears array 00118 00119 fToggles->Delete(); 00120 }