MTGListTree.cxx

Go to the documentation of this file.
00001 /*********************************************************************
00002 
00003   Name:         MTGListTree.cxx
00004   Created by:   Matthias Schneebeli
00005   $Id$
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 void MTGListTree::init()
00037 {
00038   fControlPressed = false;
00039   AddInput(kKeyReleaseMask);
00040 }
00041 
00042 MTGListTree::MTGListTree(TGWindow *p, UInt_t w, UInt_t h, UInt_t options, ULong_t back) : TGListTree(p,w,h,options,back)
00043 {
00044   init();
00045 };
00046 
00047 MTGListTree::MTGListTree(TGCanvas *p,UInt_t options,ULong_t back) : TGListTree(p,options,back)
00048 {
00049   init();
00050 };
00051 
00052 /*
00053   The routines MDeleteItem and MPDeleteChildren were added to fix a problem in TGListTree
00054   where fSelected is being left set to a TGListTreeItem pointer after that pointer has
00055   been deleted.
00056 */
00057 
00058 Int_t MTGListTree::MDeleteItem( TGListTreeItem *item )
00059 {
00060   // Delete item from list tree
00061   //
00062   if( item->GetFirstChild() )MPDeleteChildren( item->GetFirstChild() );
00063   TGListTreeItem *tmp = item->GetFirstChild();
00064   tmp = 0;
00065   RemoveReference( item );
00066   if( fSelected == item )fSelected = 0; // line added by JChuma
00067   delete item;
00068   return 1;
00069 }
00070 
00071 void MTGListTree::MPDeleteChildren( TGListTreeItem *item )
00072 {
00073   // Delete children of item from list.
00074   //
00075   TGListTreeItem *sibling;
00076   while (item)
00077   {
00078     if( item->GetFirstChild() )
00079     {
00080       MPDeleteChildren( item->GetFirstChild() );
00081       TGListTreeItem *tmp = item->GetFirstChild();
00082       tmp = 0;
00083     }
00084     sibling = item->GetNextSibling();
00085     if( fSelected == item )fSelected = 0;  // line added by JChuma
00086     delete item;
00087     item = sibling;
00088   }
00089 }
00090 
00091 Bool_t MTGListTree::HandleButton(Event_t *event)
00092 {
00093    // Handle button events in the list tree.
00094 
00095    TGListTreeItem *item;
00096 
00097    if (fTip) fTip->Hide();
00098 
00099    Int_t page = 0;
00100    if (event->fCode == kButton4 || event->fCode == kButton5) {
00101       if (!fCanvas) return kTRUE;
00102       if (fCanvas->GetContainer()->GetHeight())
00103          page = Int_t(Float_t(fCanvas->GetViewPort()->GetHeight() *
00104                               fCanvas->GetViewPort()->GetHeight()) /
00105                               fCanvas->GetContainer()->GetHeight());
00106    }
00107 
00108    if (event->fCode == kButton4) {
00109       //scroll up
00110       Int_t newpos = fCanvas->GetVsbPosition() - page;
00111       if (newpos < 0) newpos = 0;
00112       fCanvas->SetVsbPosition(newpos);
00113       return kTRUE;
00114    }
00115    if (event->fCode == kButton5) {
00116       // scroll down
00117       Int_t newpos = fCanvas->GetVsbPosition() + page;
00118       fCanvas->SetVsbPosition(newpos);
00119       return kTRUE;
00120    }
00121 
00122    if( event->fType == kButtonPress )
00123    {
00124      if( (item = FindItem(event->fY)) != 0 )
00125      {
00126        // if (fSelected) fSelected->fActive = kFALSE;  // changed
00127        if( !fControlPressed )
00128        {
00129          HighlightItem(fSelected, kFALSE, kTRUE);  // to this
00130          UnselectAll(kTRUE);
00131        }
00132        //fLastY = event->fY;
00133        fSelected = item;
00134        //item->fActive = kTRUE; // this is done below w/redraw
00135        HighlightItem(item, kTRUE, kTRUE);
00136        SendMessage(fMsgWindow, MK_MSG(kC_LISTTREE, kCT_ITEMCLICK),
00137                    event->fCode, (event->fYRoot << 16) | event->fXRoot);
00138        Clicked(item, event->fCode);
00139        Clicked(item, event->fCode, event->fXRoot, event->fYRoot);
00140      }
00141    }
00142    if (event->fType == kButtonRelease) gVirtualX->SetInputFocus(fId);
00143    return kTRUE;
00144 }
00145 
00146 void MTGListTree::GetSelectedItems( std::vector<TGListTreeItem*> &items )
00147 {
00148   items.clear();
00149   TGListTreeItem *item = fFirst; // fFirst set in TGListTree
00150   GetSelectedItemsRecursive( item, items );
00151 }
00152 
00153 void MTGListTree::GetSelectedItemsRecursive( TGListTreeItem *item, std::vector<TGListTreeItem*> &items )
00154 {
00155   while( item )
00156   {
00157     TGListTreeItem *firstChild = item->GetFirstChild();
00158     if( firstChild )GetSelectedItemsRecursive( firstChild, items );
00159     if( item->IsActive() && find(items.begin(),items.end(),item)==items.end() )items.push_back( item );
00160     item = item->GetNextSibling();
00161   }
00162 }
00163 
00164 Bool_t MTGListTree::HandleKey(Event_t *event)
00165 {
00166    char   input[10];
00167    UInt_t keysym;
00168    if (event->fType == kGKeyPress) {
00169       gVirtualX->LookupString(event, input, sizeof(input), keysym);
00170       if (keysym==4129) {
00171          fControlPressed = true;
00172       }
00173    }
00174    if (event->fType == kKeyRelease) {
00175       gVirtualX->LookupString(event, input, sizeof(input), keysym);
00176       if (keysym==4129) {
00177          fControlPressed = false;
00178       }
00179    }
00180    return TGListTree::HandleKey(event);
00181 }
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends

Generated on 15 Nov 2016 for Roody by  doxygen 1.6.1