TGTableContainer.cxx

Go to the documentation of this file.
00001 // Author: Roel Aaij   14/08/2007
00002 
00003 /*************************************************************************
00004  * Copyright (C) 1995-2007, Rene Brun and Fons Rademakers.               *
00005  * All rights reserved.                                                  *
00006  *                                                                       *
00007  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00008  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00009  *************************************************************************/
00010 
00011 #include "TGTableContainer.h"
00012 #include "TGTableCell.h"
00013 #include "TGLayout.h"
00014 #include "TGWindow.h"
00015 #include "TGScrollBar.h"
00016 #include "TGTable.h"
00017 
00018 ClassImp(TGTableFrame)
00019 ClassImp(TGTableHeaderFrame)
00020 
00021 //////////////////////////////////////////////////////////////////////////
00022 //                                                                      //
00023 // TGTableFrame and TGTableHeaderFrame                                  //
00024 //                                                                      //
00025 // TGTableFrame contains a composite frame that uses a TGMatrixLayout   //
00026 // to Layout the frames it contains.                                    //
00027 //                                                                      //
00028 // TGTableHeaderFrame implements a frame used to display TGTableHeaders //
00029 // in a TGTable.                                                        //
00030 //                                                                      //
00031 // Both classes are for internal use in TGTable only.                   //
00032 //                                                                      //
00033 //////////////////////////////////////////////////////////////////////////
00034 
00035 //______________________________________________________________________________
00036 TGTableFrame::TGTableFrame(const TGWindow *p, UInt_t nrows, UInt_t ncolumns) 
00037    : TQObject(), fFrame(0), fCanvas(0)
00038 {
00039    // Create the container used to view TGTableCells. p.
00040 
00041    fFrame = new TGCompositeFrame(p, 10, 10, kHorizontalFrame,
00042                                  TGFrame::GetWhitePixel());
00043    fFrame->Connect("ProcessedEvent(Event_t*)", "TGTableFrame", this,
00044                    "HandleMouseWheel(Event_t*)");
00045    fCanvas = 0;
00046    fFrame->SetLayoutManager(new TGMatrixLayout(fFrame, nrows, ncolumns));
00047 
00048    gVirtualX->GrabButton(fFrame->GetId(), kAnyButton, kAnyModifier,
00049                          kButtonPressMask | kButtonReleaseMask |
00050                          kPointerMotionMask, kNone, kNone);
00051 }
00052 
00053 //______________________________________________________________________________
00054 void TGTableFrame::HandleMouseWheel(Event_t *event)
00055 {
00056    // Handle mouse wheel to scroll.
00057 
00058    if (event->fType != kButtonPress && event->fType != kButtonRelease)
00059       return;
00060 
00061    Int_t page = 0;
00062    if (event->fCode == kButton4 || event->fCode == kButton5) {
00063       if (!fCanvas) return;
00064       if (fCanvas->GetContainer()->GetHeight())
00065          page = Int_t(Float_t(fCanvas->GetViewPort()->GetHeight() *
00066                               fCanvas->GetViewPort()->GetHeight()) /
00067                               fCanvas->GetContainer()->GetHeight());
00068    }
00069 
00070    if (event->fCode == kButton4) {
00071       //scroll up
00072       Int_t newpos = fCanvas->GetVsbPosition() - page;
00073       if (newpos < 0) newpos = 0;
00074       fCanvas->SetVsbPosition(newpos);
00075    }
00076    if (event->fCode == kButton5) {
00077       // scroll down
00078       Int_t newpos = fCanvas->GetVsbPosition() + page;
00079       fCanvas->SetVsbPosition(newpos);
00080    }
00081 }
00082 
00083 //______________________________________________________________________________
00084 void TGTableFrame::DrawRegion(Int_t x, Int_t y, UInt_t w, UInt_t h)
00085 {
00086    // Draw a region of container in viewport.
00087 
00088    TGFrameElement *el;
00089    //   Handle_t id = fId;
00090 
00091    Int_t xx = fCanvas->GetX() + fCanvas->GetHsbPosition() + x; // translate coordinates to current page position
00092    Int_t yy = fCanvas->GetY() + fCanvas->GetVsbPosition() + y;
00093 
00094    TIter next(fFrame->GetList());
00095 
00096    while ((el = (TGFrameElement *) next())) {
00097       if ((Int_t(el->fFrame->GetY()) >= yy - (Int_t)el->fFrame->GetHeight()) &&
00098           (Int_t(el->fFrame->GetX()) >= xx - (Int_t)el->fFrame->GetWidth()) &&
00099           (Int_t(el->fFrame->GetY()) <= yy + Int_t(h + el->fFrame->GetHeight())) &&
00100           (Int_t(el->fFrame->GetX()) <= xx + Int_t(w + el->fFrame->GetWidth()))) {
00101 
00102          // draw either in container window or in double-buffer
00103          //          if (!fMapSubwindows) {
00104          //             el->fFrame->DrawCopy(id, el->fFrame->GetX() - pos.fX, el->fFrame->GetY() - pos.fY);
00105          //          } else {
00106          gClient->NeedRedraw(el->fFrame);
00107          //          }
00108       }
00109    }
00110 }
00111 
00112 //_____________________________________________________________________________
00113 TGTableHeaderFrame::TGTableHeaderFrame(const TGWindow *p, TGTable *table, 
00114                                        UInt_t w, UInt_t h, EHeaderType type, 
00115                                        UInt_t options) :
00116    TGCompositeFrame(p, w, h, options), fX0(0), fY0(0), fTable(table)
00117 {
00118    // TGTableHeaderFrame constuctor.
00119 
00120    if (type == kRowHeader) {
00121       ChangeOptions(GetOptions() | kVerticalFrame);
00122       fY0 = fTable->GetTableHeader()->GetHeight();
00123    } else if (type == kColumnHeader) {
00124       ChangeOptions(GetOptions() | kHorizontalFrame);
00125       fX0 = fTable->GetTableHeader()->GetWidth();
00126    } else {
00127       Error("TGTableHeaderFrame::TGTableHeaderFrame", 
00128             "specify correct header type");
00129    }
00130 
00131 }
00132 
00133 //______________________________________________________________________________
00134 void TGTableHeaderFrame::DrawRegion(Int_t x, Int_t y, UInt_t w, UInt_t h)
00135 {
00136    // Draw a region of container in viewport.
00137 
00138    TGFrameElement *el;
00139    //   Handle_t id = fId;
00140 
00141    Int_t xx = fX0 + x; // translate coordinates to current page position
00142    Int_t yy = fY0 + y;
00143 
00144    TIter next(fList);
00145 
00146    while ((el = (TGFrameElement *) next())) {
00147       if ((Int_t(el->fFrame->GetY()) >= yy - (Int_t)el->fFrame->GetHeight()) &&
00148           (Int_t(el->fFrame->GetX()) >= xx - (Int_t)el->fFrame->GetWidth()) &&
00149           (Int_t(el->fFrame->GetY()) <= yy + Int_t(h + el->fFrame->GetHeight())) &&
00150           (Int_t(el->fFrame->GetX()) <= xx + Int_t(w + el->fFrame->GetWidth()))) {
00151          
00152          fClient->NeedRedraw(el->fFrame);
00153       }
00154    }
00155 }

Generated on Tue Jul 5 14:22:04 2011 for ROOT_528-00b_version by  doxygen 1.5.1