| 1 | /* ======================================================================== *\
|
|---|
| 2 | !
|
|---|
| 3 | ! *
|
|---|
| 4 | ! * This file is part of MARS, the MAGIC Analysis and Reconstruction
|
|---|
| 5 | ! * Software. It is distributed to you in the hope that it can be a useful
|
|---|
| 6 | ! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
|
|---|
| 7 | ! * It is distributed WITHOUT ANY WARRANTY.
|
|---|
| 8 | ! *
|
|---|
| 9 | ! * Permission to use, copy, modify and distribute this software and its
|
|---|
| 10 | ! * documentation for any purpose is hereby granted without fee,
|
|---|
| 11 | ! * provided that the above copyright notice appear in all copies and
|
|---|
| 12 | ! * that both that copyright notice and this permission notice appear
|
|---|
| 13 | ! * in supporting documentation. It is provided "as is" without express
|
|---|
| 14 | ! * or implied warranty.
|
|---|
| 15 | ! *
|
|---|
| 16 | !
|
|---|
| 17 | !
|
|---|
| 18 | ! Author(s): Thomas Bretz 11/2001 <mailto:tbretz@uni-sw.gwdg.de>
|
|---|
| 19 | !
|
|---|
| 20 | ! Copyright: MAGIC Software Development, 2000-2001
|
|---|
| 21 | !
|
|---|
| 22 | !
|
|---|
| 23 | \* ======================================================================== */
|
|---|
| 24 |
|
|---|
| 25 | /////////////////////////////////////////////////////////////////////////////
|
|---|
| 26 | // //
|
|---|
| 27 | // MGList //
|
|---|
| 28 | // //
|
|---|
| 29 | // This is a TList object which has some enhancements for GUI elements. //
|
|---|
| 30 | // Use GetWidget to search for a GUI element with a given widget id. //
|
|---|
| 31 | // Add checkes for the existances of a GUI element with the same widget //
|
|---|
| 32 | // id (for IDs>=0). //
|
|---|
| 33 | // //
|
|---|
| 34 | /////////////////////////////////////////////////////////////////////////////
|
|---|
| 35 | #include "MGList.h"
|
|---|
| 36 |
|
|---|
| 37 | #include <iostream.h>
|
|---|
| 38 |
|
|---|
| 39 | #include <TClass.h>
|
|---|
| 40 | #include <TGWidget.h>
|
|---|
| 41 |
|
|---|
| 42 |
|
|---|
| 43 | ClassImp(MGList);
|
|---|
| 44 |
|
|---|
| 45 | // --------------------------------------------------------------------------
|
|---|
| 46 | //
|
|---|
| 47 | // Does a dynamic cast from a TObject to a TGWidget. This is necesary
|
|---|
| 48 | // if a class derived from TObject inherits also from TGWidget and
|
|---|
| 49 | // you have only a pointer to the TObject available.
|
|---|
| 50 | //
|
|---|
| 51 | TGWidget *MGList::GetWidget(TObject *obj) const
|
|---|
| 52 | {
|
|---|
| 53 | //
|
|---|
| 54 | // - IsA gives a pointer to the parent class entry in the dictionary
|
|---|
| 55 | // - DynamicCast tries to cast obj of class type obj->IsA to one
|
|---|
| 56 | // of its base classes TGWidget
|
|---|
| 57 | // - This method is ment for dynamic casts (multi inheritance)
|
|---|
| 58 | //
|
|---|
| 59 | // If this functions makes trouble check for the correct inheritance
|
|---|
| 60 | // first via obj->InheritsFrom(TGWidget::Class())
|
|---|
| 61 | //
|
|---|
| 62 | // The root implementation is used, because for space reasons
|
|---|
| 63 | // the C++ dynamic_cast<TGWidget*> is turned off by the option
|
|---|
| 64 | // -fno-rtti, which could be used in 'plain' C++
|
|---|
| 65 | //
|
|---|
| 66 | return (TGWidget*)obj->IsA()->DynamicCast(TGWidget::Class(), obj);
|
|---|
| 67 | }
|
|---|
| 68 |
|
|---|
| 69 | // --------------------------------------------------------------------------
|
|---|
| 70 | //
|
|---|
| 71 | // Returns kTRUE if the object is derived from TGWidget and a widget
|
|---|
| 72 | // with the TGWidget id of this object is already in the list.
|
|---|
| 73 | // If the object is not derived from TGWidget or no TGWidget object
|
|---|
| 74 | // with the same widget id is existing in the list kFALSE is returned.
|
|---|
| 75 | // If the TGWidget has an object id < 0 kFALSE is always retuned.
|
|---|
| 76 | //
|
|---|
| 77 | Bool_t MGList::IsExisting(TObject *obj) const
|
|---|
| 78 | {
|
|---|
| 79 | const TGWidget *wid = GetWidget(obj);
|
|---|
| 80 |
|
|---|
| 81 | //
|
|---|
| 82 | // check whether it is a TGWidget
|
|---|
| 83 | //
|
|---|
| 84 | if (!wid)
|
|---|
| 85 | return kFALSE;
|
|---|
| 86 |
|
|---|
| 87 | const Int_t id = wid->WidgetId();
|
|---|
| 88 |
|
|---|
| 89 | //
|
|---|
| 90 | // check whether is has a valid id
|
|---|
| 91 | // (not id=-1, which is the standard id)
|
|---|
| 92 | //
|
|---|
| 93 | if (id < 0)
|
|---|
| 94 | return kFALSE;
|
|---|
| 95 |
|
|---|
| 96 | //
|
|---|
| 97 | // check whether Widget id is already existing in the list
|
|---|
| 98 | //
|
|---|
| 99 | return (Bool_t)FindWidget(id);
|
|---|
| 100 | }
|
|---|
| 101 |
|
|---|
| 102 | // --------------------------------------------------------------------------
|
|---|
| 103 | //
|
|---|
| 104 | // If the given object obj is derived from TGWidget and a TGWidget with
|
|---|
| 105 | // the same widget id is already existing in the list the object is
|
|---|
| 106 | // ignored, otherwise it is added to the list via TList::Add(TObject *)
|
|---|
| 107 | //
|
|---|
| 108 | void MGList::Add(TObject *obj)
|
|---|
| 109 | {
|
|---|
| 110 | if (IsExisting(obj))
|
|---|
| 111 | {
|
|---|
| 112 | cout << "Widget with id #" << GetWidget(obj)->WidgetId() << " already in list... ignored." << endl;
|
|---|
| 113 | return;
|
|---|
| 114 | }
|
|---|
| 115 |
|
|---|
| 116 | TList::Add(obj);
|
|---|
| 117 | }
|
|---|
| 118 |
|
|---|
| 119 | // --------------------------------------------------------------------------
|
|---|
| 120 | //
|
|---|
| 121 | // If the given object obj is derived from TGWidget and a TGWidget with
|
|---|
| 122 | // the same widget id is already existing in the list the object is
|
|---|
| 123 | // ignored, otherwise it is added to the list via
|
|---|
| 124 | // TList::Add(TObject *, Option_t *)
|
|---|
| 125 | //
|
|---|
| 126 | void MGList::Add(TObject *obj, Option_t *opt)
|
|---|
| 127 | {
|
|---|
| 128 | if (IsExisting(obj))
|
|---|
| 129 | {
|
|---|
| 130 | cout << "Widget with id #" << GetWidget(obj)->WidgetId() << " already in list... ignored." << endl;
|
|---|
| 131 | return;
|
|---|
| 132 | }
|
|---|
| 133 |
|
|---|
| 134 | TList::Add(obj, opt);
|
|---|
| 135 | }
|
|---|
| 136 |
|
|---|
| 137 | // --------------------------------------------------------------------------
|
|---|
| 138 | //
|
|---|
| 139 | // Search the list for a object derived from TGidget which has the given
|
|---|
| 140 | // widget id. Returns a pointer to this object otherwise NULL.
|
|---|
| 141 | // For IDs < 0 the function returns always NULL.
|
|---|
| 142 | //
|
|---|
| 143 | TObject *MGList::FindWidget(Int_t id) const
|
|---|
| 144 | {
|
|---|
| 145 | if (id<0)
|
|---|
| 146 | return NULL;
|
|---|
| 147 |
|
|---|
| 148 | TObject *obj;
|
|---|
| 149 | TIter Next(this);
|
|---|
| 150 | while ((obj=Next()))
|
|---|
| 151 | {
|
|---|
| 152 | const TGWidget *wid = GetWidget(obj);
|
|---|
| 153 |
|
|---|
| 154 | if (!wid)
|
|---|
| 155 | continue;
|
|---|
| 156 |
|
|---|
| 157 | if (id == wid->WidgetId())
|
|---|
| 158 | return obj;
|
|---|
| 159 | }
|
|---|
| 160 | return NULL;
|
|---|
| 161 | }
|
|---|