File indexing completed on 2023-03-17 11:01:25
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #include <cassert>
0015 #include <stdexcept>
0016 #include <iostream>
0017
0018 #include "TSystem.h"
0019 #include "TGButton.h"
0020 #include "TEveWindow.h"
0021
0022 #include "Fireworks/Core/interface/FWGUISubviewArea.h"
0023 #include "Fireworks/Core/interface/FWGUIManager.h"
0024 #include "Fireworks/Core/interface/CmsShowMainFrame.h"
0025 #include "Fireworks/Core/src/FWCheckBoxIcon.h"
0026
0027
0028
0029
0030
0031
0032 namespace {
0033 class XXXButton : public TGPictureButton {
0034 Int_t fXState;
0035
0036 public:
0037 XXXButton(const TGWindow* p, const TGPicture* pic) : TGPictureButton(p, pic), fXState(kButtonUp) {}
0038
0039 void SetState(EButtonState state, Bool_t emit = kFALSE) override {
0040 TGPictureButton::SetState(state, kFALSE);
0041 if ((fXState == kButtonUp && fState == kButtonEngaged) || (fState == kButtonUp && fXState == kButtonEngaged)) {
0042 fXState = fState;
0043 Clicked();
0044 }
0045 }
0046 };
0047 }
0048
0049
0050
0051
0052
0053 FWGUISubviewArea::FWGUISubviewArea(TEveCompositeFrame* ef, TGCompositeFrame* parent, Int_t height)
0054 : TGHorizontalFrame(parent, 20, height),
0055 m_frame(ef),
0056 m_swapButton(nullptr),
0057 m_undockButton(nullptr),
0058 m_dockButton(nullptr),
0059 m_closeButton(nullptr),
0060 m_infoButton(nullptr) {
0061 UInt_t lh = kLHintsNormal | kLHintsExpandX | kLHintsExpandY;
0062
0063
0064 m_infoButton = new XXXButton(this, infoIcon());
0065 m_infoButton->ChangeOptions(kRaisedFrame);
0066 m_infoButton->SetDisabledPicture(infoDisabledIcon());
0067 AddFrame(m_infoButton, new TGLayoutHints(lh));
0068 m_infoButton->AllowStayDown(kTRUE);
0069 m_infoButton->Connect("Clicked()", "FWGUISubviewArea", this, "selectButtonToggle()");
0070 m_infoButton->SetToolTipText("Edit View");
0071
0072
0073 m_swapButton = new TGPictureButton(this, swapIcon());
0074 m_swapButton->SetDisabledPicture(swapDisabledIcon());
0075 m_swapButton->SetToolTipText("Swap with the first view or select window to swap with click on toolbar.");
0076 m_swapButton->ChangeOptions(kRaisedFrame);
0077 m_swapButton->SetHeight(height);
0078 AddFrame(m_swapButton, new TGLayoutHints(lh));
0079 m_swapButton->Connect("Clicked()", "FWGUISubviewArea", this, "swap()");
0080
0081
0082 if (dynamic_cast<const TGMainFrame*>(ef->GetParent())) {
0083 m_dockButton = new TGPictureButton(this, dockIcon());
0084 m_dockButton->ChangeOptions(kRaisedFrame);
0085 m_dockButton->ChangeOptions(kRaisedFrame);
0086 m_dockButton->SetToolTipText("Dock view");
0087 m_dockButton->SetHeight(height);
0088 AddFrame(m_dockButton, new TGLayoutHints(lh));
0089 m_dockButton->Connect("Clicked()", "FWGUISubviewArea", this, "dock()");
0090 } else {
0091
0092 m_undockButton = new TGPictureButton(this, undockIcon());
0093 m_undockButton->ChangeOptions(kRaisedFrame);
0094 m_undockButton->SetDisabledPicture(undockDisabledIcon());
0095 m_undockButton->SetToolTipText("Undock view to own window");
0096 m_undockButton->SetHeight(height);
0097 AddFrame(m_undockButton, new TGLayoutHints(lh));
0098 m_undockButton->Connect("Clicked()", "FWGUISubviewArea", this, "undock()");
0099 }
0100
0101 m_closeButton = new TGPictureButton(this, closeIcon());
0102 m_closeButton->ChangeOptions(kRaisedFrame);
0103 m_closeButton->SetToolTipText("Close view");
0104 m_closeButton->SetHeight(height);
0105 AddFrame(m_closeButton, new TGLayoutHints(lh));
0106 m_closeButton->Connect("Clicked()", "FWGUISubviewArea", this, "destroy()");
0107
0108 FWGUIManager::getGUIManager()->connectSubviewAreaSignals(this);
0109 }
0110
0111 FWGUISubviewArea::~FWGUISubviewArea() {
0112
0113 m_closeButton->Disconnect("Clicked()", this, "destroy()");
0114 m_infoButton->Disconnect("Clicked()", this, "selectButtonToggle()");
0115 }
0116
0117
0118
0119
0120
0121
0122 void FWGUISubviewArea::selectButtonToggle() {
0123 if (isSelected())
0124 selected_(this);
0125 else
0126 unselected_(this);
0127 }
0128
0129 void FWGUISubviewArea::unselect() { m_infoButton->SetState(kButtonUp); }
0130
0131 void FWGUISubviewArea::setSwapIcon(bool isOn) { m_swapButton->SetEnabled(isOn); }
0132
0133 void FWGUISubviewArea::swap() { swap_(this); }
0134
0135 void FWGUISubviewArea::destroy() { goingToBeDestroyed_(this); }
0136
0137 void FWGUISubviewArea::undock() {
0138 TEveWindow* ew = m_frame->GetEveWindow();
0139 ew->UndockWindow();
0140 TEveCompositeFrameInMainFrame* emf = dynamic_cast<TEveCompositeFrameInMainFrame*>(ew->GetEveFrame());
0141 if (emf) {
0142 const TGMainFrame* mf = dynamic_cast<const TGMainFrame*>(emf->GetParent());
0143 if (mf)
0144 FWGUIManager::getGUIManager()->getMainFrame()->bindCSGActionKeys(mf);
0145 }
0146 }
0147
0148 void FWGUISubviewArea::dock() {
0149 TGWindow* w = (TGWindow*)(m_frame->GetParent());
0150 w->UnmapWindow();
0151 TTimer::SingleShot(0, m_frame->ClassName(), m_frame, "MainFrameClosed()");
0152 }
0153
0154
0155
0156
0157 bool FWGUISubviewArea::isSelected() const { return m_infoButton->IsDown(); }
0158
0159
0160 TEveWindow* FWGUISubviewArea::getEveWindow() { return m_frame->GetEveWindow(); }
0161
0162
0163
0164
0165 const TGPicture* FWGUISubviewArea::swapIcon() {
0166 static const TGPicture* s_icon = nullptr;
0167 if (nullptr == s_icon) {
0168 const char* cmspath = gSystem->Getenv("CMSSW_BASE");
0169 if (nullptr == cmspath) {
0170 throw std::runtime_error("CMSSW_BASE environment variable not set");
0171 }
0172 s_icon = gClient->GetPicture(FWCheckBoxIcon::coreIcondir() + "moveup.png");
0173 }
0174 return s_icon;
0175 }
0176
0177 const TGPicture* FWGUISubviewArea::swapDisabledIcon() {
0178 static const TGPicture* s_icon = nullptr;
0179 if (nullptr == s_icon) {
0180 const char* cmspath = gSystem->Getenv("CMSSW_BASE");
0181 if (nullptr == cmspath) {
0182 throw std::runtime_error("CMSSW_BASE environment variable not set");
0183 }
0184 s_icon = gClient->GetPicture(FWCheckBoxIcon::coreIcondir() + "moveup-disabled.png");
0185 }
0186 return s_icon;
0187 }
0188
0189 const TGPicture* FWGUISubviewArea::closeIcon() {
0190 static const TGPicture* s_icon = nullptr;
0191 if (nullptr == s_icon) {
0192 const char* cmspath = gSystem->Getenv("CMSSW_BASE");
0193 if (nullptr == cmspath) {
0194 throw std::runtime_error("CMSSW_BASE environment variable not set");
0195 }
0196 s_icon = gClient->GetPicture(FWCheckBoxIcon::coreIcondir() + "delete.png");
0197 }
0198 return s_icon;
0199 }
0200
0201 const TGPicture* FWGUISubviewArea::closeDisabledIcon() {
0202 static const TGPicture* s_icon = nullptr;
0203 if (nullptr == s_icon) {
0204 const char* cmspath = gSystem->Getenv("CMSSW_BASE");
0205 if (nullptr == cmspath) {
0206 throw std::runtime_error("CMSSW_BASE environment variable not set");
0207 }
0208 s_icon = gClient->GetPicture(FWCheckBoxIcon::coreIcondir() + "delete-disabled.png");
0209 }
0210 return s_icon;
0211 }
0212
0213 const TGPicture* FWGUISubviewArea::undockIcon() {
0214 static const TGPicture* s_icon = nullptr;
0215 if (nullptr == s_icon) {
0216 const char* cmspath = gSystem->Getenv("CMSSW_BASE");
0217 if (nullptr == cmspath) {
0218 throw std::runtime_error("CMSSW_BASE environment variable not set");
0219 }
0220 s_icon = gClient->GetPicture(FWCheckBoxIcon::coreIcondir() + "expand.png");
0221 }
0222 return s_icon;
0223 }
0224
0225 const TGPicture* FWGUISubviewArea::dockIcon() {
0226 static const TGPicture* s_icon = nullptr;
0227 if (nullptr == s_icon) {
0228 const char* cmspath = gSystem->Getenv("CMSSW_BASE");
0229 if (nullptr == cmspath) {
0230 throw std::runtime_error("CMSSW_BASE environment variable not set");
0231 }
0232 s_icon = gClient->GetPicture(FWCheckBoxIcon::coreIcondir() + "dock.png");
0233 }
0234 return s_icon;
0235 }
0236
0237 const TGPicture* FWGUISubviewArea::undockDisabledIcon() {
0238 static const TGPicture* s_icon = nullptr;
0239 if (nullptr == s_icon) {
0240 const char* cmspath = gSystem->Getenv("CMSSW_BASE");
0241 if (nullptr == cmspath) {
0242 throw std::runtime_error("CMSSW_BASE environment variable not set");
0243 }
0244 s_icon = gClient->GetPicture(FWCheckBoxIcon::coreIcondir() + "expand-disabled.png");
0245 }
0246 return s_icon;
0247 }
0248
0249 const TGPicture* FWGUISubviewArea::infoIcon() {
0250 static const TGPicture* s_icon = nullptr;
0251 if (nullptr == s_icon) {
0252 const char* cmspath = gSystem->Getenv("CMSSW_BASE");
0253 if (nullptr == cmspath) {
0254 throw std::runtime_error("CMSSW_BASE environment variable not set");
0255 }
0256 s_icon = gClient->GetPicture(FWCheckBoxIcon::coreIcondir() + "info.png");
0257 }
0258 return s_icon;
0259 }
0260
0261 const TGPicture* FWGUISubviewArea::infoDisabledIcon() {
0262 static const TGPicture* s_icon = nullptr;
0263 if (nullptr == s_icon) {
0264 const char* cmspath = gSystem->Getenv("CMSSW_BASE");
0265 if (nullptr == cmspath) {
0266 throw std::runtime_error("CMSSW_BASE environment variable not set");
0267 }
0268 s_icon = gClient->GetPicture(FWCheckBoxIcon::coreIcondir() + "info-disabled.png");
0269 }
0270 return s_icon;
0271 }
0272
0273 void FWGUISubviewArea::setInfoButton(bool downp) { m_infoButton->SetState(downp ? kButtonEngaged : kButtonUp, false); }
0274
0275 FWGUISubviewArea* FWGUISubviewArea::getToolBarFromWindow(TEveWindow* w) {
0276
0277 TGFrameElement* el = (TGFrameElement*)w->GetEveFrame()->GetList()->First();
0278 TGCompositeFrame* hf = (TGCompositeFrame*)el->fFrame;
0279
0280 el = (TGFrameElement*)hf->GetList()->Last();
0281 FWGUISubviewArea* ar = dynamic_cast<FWGUISubviewArea*>(el->fFrame);
0282 return ar;
0283 }