MTGListTree.cxx

Go to the documentation of this file.
00001 /*********************************************************************
00002 
00003   Name:         MTGListTree.cxx
00004   Created by:   Matthias Schneebeli
00005 
00006                                                                        
00007   Contents:     MIROODAS        
00008   $Log$
00009   Revision 1.4  2005/03/10 18:29:43  chuma
00010   Fixed segmentation fault problems when connected online, then having the
00011   connection broken, then re-establishing the connection and then clicking
00012   on an online item in the main window.  The problem is in TGListTree in
00013   the ROOT code, and is fixed here by including 2 routines into MTGListTree.
00014 
00015   Revision 1.3  2004/09/24 22:08:35  chuma
00016   Added TNetFolder support
00017 
00018   Revision 1.2  2004/09/20 19:39:24  chuma
00019   multiple selection of histograms with CTRL key updated
00020 
00021   Revision 1.1  2004/09/16 16:30:36  schneebeli
00022   Linking on windows and multiple selection of items
00023 
00024   
00025 *********************************************************************/
00026 
00027 #include <iostream>
00028 #include <algorithm>
00029 
00030 #include "TGToolTip.h"
00031 #include "Riostream.h"
00032 #include "MTGListTree.h"
00033 
00034 ClassImp(MTGListTree)
00035 
00036 MTGListTree::MTGListTree(TGWindow *p, UInt_t w, UInt_t h, UInt_t options, ULong_t back) : TGListTree(p,w,h,options,back) { this->AddInput(kKeyReleaseMask); };
00037 MTGListTree::MTGListTree(TGCanvas *p,UInt_t options,ULong_t back) : TGListTree(p,options,back) { this->AddInput(kKeyReleaseMask); };
00038 
00039 /*
00040   The routines MDeleteItem and MPDeleteChildren were added to fix a problem in TGListTree
00041   where fSelected is being left set to a TGListTreeItem pointer after that pointer has
00042   been deleted.
00043 */
00044 
00045 Int_t MTGListTree::MDeleteItem( TGListTreeItem *item )
00046 {
00047   // Delete item from list tree
00048   //
00049   if( item->GetFirstChild() )MPDeleteChildren( item->GetFirstChild() );
00050   TGListTreeItem *tmp = item->GetFirstChild();
00051   tmp = 0;
00052   RemoveReference( item );
00053   if( fSelected == item )fSelected = 0; // line added by JChuma
00054   delete item;
00055   return 1;
00056 }
00057 
00058 void MTGListTree::MPDeleteChildren( TGListTreeItem *item )
00059 {
00060   // Delete children of item from list.
00061   //
00062   TGListTreeItem *sibling;
00063   while (item)
00064   {
00065     if( item->GetFirstChild() )
00066     {
00067       MPDeleteChildren( item->GetFirstChild() );
00068       TGListTreeItem *tmp = item->GetFirstChild();
00069       tmp = 0;
00070     }
00071     sibling = item->GetNextSibling();
00072     if( fSelected == item )fSelected = 0;  // line added by JChuma
00073     delete item;
00074     item = sibling;
00075   }
00076 }
00077 
00078 Bool_t MTGListTree::HandleButton(Event_t *event)
00079 {
00080    // Handle button events in the list tree.
00081 
00082    TGListTreeItem *item;
00083 
00084    if (fTip) fTip->Hide();
00085 
00086    Int_t page = 0;
00087    if (event->fCode == kButton4 || event->fCode == kButton5) {
00088       if (!fCanvas) return kTRUE;
00089       if (fCanvas->GetContainer()->GetHeight())
00090          page = Int_t(Float_t(fCanvas->GetViewPort()->GetHeight() *
00091                               fCanvas->GetViewPort()->GetHeight()) /
00092                               fCanvas->GetContainer()->GetHeight());
00093    }
00094 
00095    if (event->fCode == kButton4) {
00096       //scroll up
00097       Int_t newpos = fCanvas->GetVsbPosition() - page;
00098       if (newpos < 0) newpos = 0;
00099       fCanvas->SetVsbPosition(newpos);
00100       return kTRUE;
00101    }
00102    if (event->fCode == kButton5) {
00103       // scroll down
00104       Int_t newpos = fCanvas->GetVsbPosition() + page;
00105       fCanvas->SetVsbPosition(newpos);
00106       return kTRUE;
00107    }
00108 
00109    if( event->fType == kButtonPress )
00110    {
00111      if( (item = FindItem(event->fY)) != 0 )
00112      {
00113        // if (fSelected) fSelected->fActive = kFALSE;  // changed
00114        if( !fControlPressed )
00115        {
00116          HighlightItem(fSelected, kFALSE, kTRUE);  // to this
00117          UnselectAll(kTRUE);
00118        }
00119        fLastY = event->fY;
00120        fSelected = item;
00121        //item->fActive = kTRUE; // this is done below w/redraw
00122        HighlightItem(item, kTRUE, kTRUE);
00123        SendMessage(fMsgWindow, MK_MSG(kC_LISTTREE, kCT_ITEMCLICK),
00124                    event->fCode, (event->fYRoot << 16) | event->fXRoot);
00125        Clicked(item, event->fCode);
00126        Clicked(item, event->fCode, event->fXRoot, event->fYRoot);
00127      }
00128    }
00129    if (event->fType == kButtonRelease) gVirtualX->SetInputFocus(fId);
00130    return kTRUE;
00131 }
00132 
00133 void MTGListTree::GetSelectedItems( std::vector<TGListTreeItem*> &items )
00134 {
00135   items.clear();
00136   TGListTreeItem *item = fFirst; // fFirst set in TGListTree
00137   GetSelectedItemsRecursive( item, items );
00138 }
00139 
00140 void MTGListTree::GetSelectedItemsRecursive( TGListTreeItem *item, std::vector<TGListTreeItem*> &items )
00141 {
00142   while( item )
00143   {
00144     TGListTreeItem *firstChild = item->GetFirstChild();
00145     if( firstChild )GetSelectedItemsRecursive( firstChild, items );
00146     if( item->IsActive() && find(items.begin(),items.end(),item)==items.end() )items.push_back( item );
00147     item = item->GetNextSibling();
00148   }
00149 }
00150 
00151 Bool_t MTGListTree::HandleKey(Event_t *event)
00152 {
00153    char   input[10];
00154    UInt_t keysym;
00155    if (event->fType == kGKeyPress) {
00156       gVirtualX->LookupString(event, input, sizeof(input), keysym);
00157       if (keysym==4129) {
00158          fControlPressed = true;
00159       }
00160    }
00161    if (event->fType == kKeyRelease) {
00162       gVirtualX->LookupString(event, input, sizeof(input), keysym);
00163       if (keysym==4129) {
00164          fControlPressed = false;
00165       }
00166    }
00167    return TGListTree::HandleKey(event);
00168 }

Roody DOC Version 1.0.1 ---- TRIUMF ----
Contributions: Pierre-Andre Amaudruz - Joe Chuma - Doxygen - Greg King - Konstantin Olchanski - Matthias Schneebeli