CMS 3D CMS Logo

/data/git/CMSSW_5_3_11_patch5/src/Fireworks/Core/src/FWGUISubviewArea.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:     Core
00004 // Class  :     FWGUISubviewArea
00005 //
00006 // Implementation:
00007 //     <Notes on implementation>
00008 //
00009 // Original Author:  Chris Jones
00010 //         Created:  Fri Feb 15 14:13:33 EST 2008
00011 // $Id: FWGUISubviewArea.cc,v 1.38 2011/02/22 18:37:31 amraktad Exp $
00012 //
00013 
00014 // system include files
00015 #include <assert.h>
00016 #include <stdexcept>
00017 #include <iostream>
00018 
00019 #include "TSystem.h"
00020 #include "TGButton.h"
00021 #include "TEveWindow.h"
00022 
00023 #include "Fireworks/Core/interface/FWGUISubviewArea.h"
00024 #include "Fireworks/Core/interface/FWGUIManager.h"
00025 #include "Fireworks/Core/interface/CmsShowMainFrame.h"
00026 #include "Fireworks/Core/src/FWCheckBoxIcon.h"
00027 
00028 
00029 //==============================================================================
00030 // Workaround around bloody squeaking TGPictureButton.
00031 // Want to get signal when pressed and released.
00032 // This is needed for "info" button which "stays down".
00033 //------------------------------------------------------------------------------
00034 namespace
00035 {
00036    class XXXButton : public TGPictureButton
00037    {
00038       Int_t fXState;
00039    public:
00040       XXXButton(const TGWindow* p, const TGPicture* pic) :
00041          TGPictureButton(p, pic), fXState(kButtonUp) {}
00042 
00043       virtual void SetState(EButtonState state, Bool_t emit=kFALSE)
00044       {
00045          TGPictureButton::SetState(state, kFALSE);
00046          if ((fXState == kButtonUp && fState  == kButtonEngaged) ||
00047              (fState  == kButtonUp && fXState == kButtonEngaged))
00048          {
00049             fXState = fState;
00050             Clicked();
00051          }
00052       }      
00053    };
00054 }
00055 //==============================================================================
00056 
00057 
00058 //
00059 // constructors and destructor
00060 //
00061 FWGUISubviewArea::FWGUISubviewArea(TEveCompositeFrame* ef, TGCompositeFrame* parent, Int_t height) :
00062    TGHorizontalFrame(parent, 20, height),
00063    m_frame (ef),
00064    m_swapButton(0),
00065    m_undockButton(0), m_dockButton(0),
00066    m_closeButton(0),
00067    m_infoButton(0)
00068 {
00069    UInt_t lh = kLHintsNormal | kLHintsExpandX | kLHintsExpandY;
00070 
00071    // info
00072    m_infoButton = new XXXButton(this,infoIcon());
00073    m_infoButton->ChangeOptions(kRaisedFrame);
00074    m_infoButton->SetDisabledPicture(infoDisabledIcon());
00075    AddFrame(m_infoButton, new TGLayoutHints(lh));
00076    m_infoButton->AllowStayDown(kTRUE);
00077    m_infoButton->Connect("Clicked()","FWGUISubviewArea",this,"selectButtonToggle()");
00078    m_infoButton->SetToolTipText("Edit View");
00079 
00080    //swap
00081    m_swapButton = new TGPictureButton(this, swapIcon());
00082    m_swapButton->SetDisabledPicture(swapDisabledIcon());
00083    m_swapButton->SetToolTipText("Swap with the first view or select window to swap with click on toolbar.");
00084    m_swapButton->ChangeOptions(kRaisedFrame);
00085    m_swapButton->SetHeight(height);
00086    AddFrame(m_swapButton, new TGLayoutHints(lh));
00087    m_swapButton->Connect("Clicked()","FWGUISubviewArea",this,"swap()");
00088 
00089    // dock 
00090    if (dynamic_cast<const TGMainFrame*>(ef->GetParent()))
00091    {  
00092       m_dockButton = new TGPictureButton(this, dockIcon());
00093       m_dockButton->ChangeOptions(kRaisedFrame);
00094       m_dockButton->ChangeOptions(kRaisedFrame);
00095       m_dockButton->SetToolTipText("Dock view");
00096       m_dockButton->SetHeight(height);
00097       AddFrame(m_dockButton, new TGLayoutHints(lh));
00098       m_dockButton->Connect("Clicked()", "FWGUISubviewArea",this,"dock()");
00099    }
00100    else
00101    {
00102       // undock  
00103       m_undockButton = new TGPictureButton(this, undockIcon());
00104       m_undockButton->ChangeOptions(kRaisedFrame);
00105       m_undockButton->SetDisabledPicture(undockDisabledIcon());
00106       m_undockButton->SetToolTipText("Undock view to own window");
00107       m_undockButton->SetHeight(height);
00108       AddFrame(m_undockButton, new TGLayoutHints(lh));
00109       m_undockButton->Connect("Clicked()", "FWGUISubviewArea",this,"undock()");
00110    }
00111    // destroy
00112    m_closeButton = new TGPictureButton(this,closeIcon());
00113    m_closeButton->ChangeOptions(kRaisedFrame);
00114    m_closeButton->SetToolTipText("Close view");
00115    m_closeButton->SetHeight(height);
00116    AddFrame(m_closeButton, new TGLayoutHints(lh));
00117    m_closeButton->Connect("Clicked()", "FWGUISubviewArea",this,"destroy()");
00118 
00119    FWGUIManager::getGUIManager()->connectSubviewAreaSignals(this);
00120 }
00121 
00122 FWGUISubviewArea::~FWGUISubviewArea()
00123 {
00124    //std::cout <<"IN dstr FWGUISubviewArea"<<std::endl;
00125    m_closeButton->Disconnect("Clicked()", this,"destroy()");
00126    m_infoButton->Disconnect("Clicked()",this,"selectButtonToggle()");
00127 }
00128 
00129 //______________________________________________________________________________
00130 //
00131 // actions
00132 //
00133 
00134 void
00135 FWGUISubviewArea::selectButtonToggle()
00136 {
00137    if (isSelected())
00138       selected_(this);
00139    else
00140       unselected_(this);
00141 }
00142 
00143 void
00144 FWGUISubviewArea::unselect()
00145 {
00146    m_infoButton->SetState(kButtonUp);
00147 }
00148 
00149 void
00150 FWGUISubviewArea::setSwapIcon(bool isOn)
00151 {
00152   m_swapButton->SetEnabled(isOn);
00153 }
00154 
00155 void
00156 FWGUISubviewArea::swap()
00157 {
00158    swap_(this);
00159 }
00160 
00161 void
00162 FWGUISubviewArea::destroy()
00163 {
00164    goingToBeDestroyed_(this);
00165 }
00166 
00167 void
00168 FWGUISubviewArea::undock()
00169 {
00170    TEveWindow* ew = m_frame->GetEveWindow();
00171    ew->UndockWindow();
00172    TEveCompositeFrameInMainFrame* emf = dynamic_cast<TEveCompositeFrameInMainFrame*>(ew->GetEveFrame());
00173    if (emf) {
00174       const TGMainFrame* mf =  dynamic_cast<const TGMainFrame*>(emf->GetParent());
00175       if (mf)
00176          FWGUIManager::getGUIManager()->getMainFrame()->bindCSGActionKeys(mf);
00177    }
00178 }
00179 
00180 void
00181 FWGUISubviewArea::dock()
00182 {
00183    TGWindow* w = (TGWindow*)(m_frame->GetParent());
00184    w->UnmapWindow();
00185    TTimer::SingleShot(0, m_frame->ClassName(), m_frame, "MainFrameClosed()");
00186 }
00187 
00188 //
00189 // const member functions
00190 //
00191 bool
00192 FWGUISubviewArea::isSelected() const
00193 {
00194    return m_infoButton->IsDown();
00195 }
00196 
00197 
00198 //______________________________________________________________________________
00199 TEveWindow*
00200 FWGUISubviewArea::getEveWindow()
00201 {
00202    return m_frame->GetEveWindow();
00203 }
00204 
00205 //______________________________________________________________________________
00206 // static member functions
00207 //
00208 const TGPicture *
00209 FWGUISubviewArea::swapIcon()
00210 {
00211    static const TGPicture* s_icon = 0;
00212    if(0== s_icon) {
00213       const char* cmspath = gSystem->Getenv("CMSSW_BASE");
00214       if(0 == cmspath) {
00215          throw std::runtime_error("CMSSW_BASE environment variable not set");
00216       }
00217       s_icon = gClient->GetPicture(FWCheckBoxIcon::coreIcondir()+"moveup.png");
00218    }
00219    return s_icon;
00220 }
00221 
00222 const TGPicture *
00223 FWGUISubviewArea::swapDisabledIcon()
00224 {
00225    static const TGPicture* s_icon = 0;
00226    if(0== s_icon) {
00227       const char* cmspath = gSystem->Getenv("CMSSW_BASE");
00228       if(0 == cmspath) {
00229          throw std::runtime_error("CMSSW_BASE environment variable not set");
00230       }
00231       s_icon = gClient->GetPicture(FWCheckBoxIcon::coreIcondir()+"moveup-disabled.png");
00232    }
00233    return s_icon;
00234 }
00235 
00236 const TGPicture *
00237 FWGUISubviewArea::closeIcon()
00238 {
00239    static const TGPicture* s_icon = 0;
00240    if(0== s_icon) {
00241       const char* cmspath = gSystem->Getenv("CMSSW_BASE");
00242       if(0 == cmspath) {
00243          throw std::runtime_error("CMSSW_BASE environment variable not set");
00244       }
00245       s_icon = gClient->GetPicture(FWCheckBoxIcon::coreIcondir()+"delete.png");
00246    }
00247    return s_icon;
00248 }
00249 
00250 const TGPicture *
00251 FWGUISubviewArea::closeDisabledIcon()
00252 {
00253    static const TGPicture* s_icon = 0;
00254    if(0== s_icon) {
00255       const char* cmspath = gSystem->Getenv("CMSSW_BASE");
00256       if(0 == cmspath) {
00257          throw std::runtime_error("CMSSW_BASE environment variable not set");
00258       }
00259       s_icon = gClient->GetPicture(FWCheckBoxIcon::coreIcondir()+"delete-disabled.png");
00260    }
00261    return s_icon;
00262 }
00263 
00264 
00265 const TGPicture *
00266 FWGUISubviewArea::undockIcon()
00267 {
00268    static const TGPicture* s_icon = 0;
00269    if(0== s_icon) {
00270       const char* cmspath = gSystem->Getenv("CMSSW_BASE");
00271       if(0 == cmspath) {
00272          throw std::runtime_error("CMSSW_BASE environment variable not set");
00273       }
00274       s_icon = gClient->GetPicture(FWCheckBoxIcon::coreIcondir()+"expand.png");
00275    }
00276    return s_icon;
00277 }
00278 
00279 const TGPicture *
00280 FWGUISubviewArea::dockIcon()
00281 {
00282    static const TGPicture* s_icon = 0;
00283    if(0== s_icon) {
00284       const char* cmspath = gSystem->Getenv("CMSSW_BASE");
00285       if(0 == cmspath) {
00286          throw std::runtime_error("CMSSW_BASE environment variable not set");
00287       }
00288       s_icon = gClient->GetPicture(FWCheckBoxIcon::coreIcondir()+"dock.png");
00289    }
00290    return s_icon;
00291 }
00292 
00293 const TGPicture *
00294 FWGUISubviewArea::undockDisabledIcon()
00295 {
00296    static const TGPicture* s_icon = 0;
00297    if(0== s_icon) {
00298       const char* cmspath = gSystem->Getenv("CMSSW_BASE");
00299       if(0 == cmspath) {
00300          throw std::runtime_error("CMSSW_BASE environment variable not set");
00301       }
00302       s_icon = gClient->GetPicture(FWCheckBoxIcon::coreIcondir()+"expand-disabled.png");
00303    }
00304    return s_icon;
00305 }
00306 
00307 const TGPicture *
00308 FWGUISubviewArea::infoIcon()
00309 {
00310    static const TGPicture* s_icon = 0;
00311    if(0== s_icon) {
00312       const char* cmspath = gSystem->Getenv("CMSSW_BASE");
00313       if(0 == cmspath) {
00314          throw std::runtime_error("CMSSW_BASE environment variable not set");
00315       }
00316       s_icon = gClient->GetPicture(FWCheckBoxIcon::coreIcondir()+"info.png");
00317    }
00318    return s_icon;
00319 }
00320 
00321 const TGPicture *
00322 FWGUISubviewArea::infoDisabledIcon()
00323 {
00324    static const TGPicture* s_icon = 0;
00325    if(0== s_icon) {
00326       const char* cmspath = gSystem->Getenv("CMSSW_BASE");
00327       if(0 == cmspath) {
00328          throw std::runtime_error("CMSSW_BASE environment variable not set");
00329       }
00330       s_icon = gClient->GetPicture(FWCheckBoxIcon::coreIcondir()+"info-disabled.png");
00331    }
00332    return s_icon;
00333 }
00334 
00335 void
00336 FWGUISubviewArea::setInfoButton(bool downp)
00337 {
00338    m_infoButton->SetState(downp ? kButtonEngaged : kButtonUp, false);
00339 }
00340 
00341 FWGUISubviewArea*
00342 FWGUISubviewArea::getToolBarFromWindow(TEveWindow* w)
00343 {
00344    // horizontal frame
00345    TGFrameElement *el = (TGFrameElement*) w->GetEveFrame()->GetList()->First();
00346    TGCompositeFrame* hf = (TGCompositeFrame*)el->fFrame;
00347    // subview last in the horizontal frame
00348    el = (TGFrameElement*)hf->GetList()->Last();
00349    FWGUISubviewArea* ar = dynamic_cast<FWGUISubviewArea*>(el->fFrame);
00350    return ar;
00351 }