Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
// -*- C++ -*-
//
// Package:     Core
// Class  :     CSGContinuousAction
//
// Implementation:
//     <Notes on implementation>
//
// Original Author:  Chris Jones
//         Created:  Tue Jul 29 10:21:18 EDT 2008
//

// system include files
#include <functional>
#include "TGMenu.h"

// user include files
#include "Fireworks/Core/interface/CSGContinuousAction.h"
#include "Fireworks/Core/interface/FWCustomIconsButton.h"

//
// constants, enums and typedefs
//

//
// static data member definitions
//

//
// constructors and destructor
//
CSGContinuousAction::CSGContinuousAction(CSGActionSupervisor* iSupervisor, const char* iName)
    : CSGAction(iSupervisor, iName),
      m_upPic(nullptr),
      m_downPic(nullptr),
      m_disabledPic(nullptr),
      m_runningUpPic(nullptr),
      m_runningDownPic(nullptr),
      m_button(nullptr),
      m_isRunning(false) {
  activated.connect(std::bind(&CSGContinuousAction::switchMode, this));
}

void CSGContinuousAction::createCustomIconsButton(TGCompositeFrame* p,
                                                  const TGPicture* upPic,
                                                  const TGPicture* downPic,
                                                  const TGPicture* disabledPic,
                                                  const TGPicture* upRunningPic,
                                                  const TGPicture* downRunningPic,
                                                  TGLayoutHints* l,
                                                  Int_t id,
                                                  GContext_t norm,
                                                  UInt_t option) {
  m_upPic = upPic;
  m_downPic = downPic;
  m_disabledPic = disabledPic;
  m_runningUpPic = upRunningPic;
  m_runningDownPic = downRunningPic;
  m_button = CSGAction::createCustomIconsButton(p, upPic, downPic, disabledPic, l, id, norm, option);
}

void CSGContinuousAction::switchMode() {
  if (!m_isRunning) {
    m_isRunning = true;
    CSGAction::globalEnable();
    if (getToolBar() && !m_runningImageFileName.empty()) {
      getToolBar()->ChangeIcon(getToolBarData(), m_runningImageFileName.c_str());
    }
    if (nullptr != m_button) {
      const TGPicture* tUp = m_runningUpPic;
      const TGPicture* tDown = m_runningDownPic;
      m_button->swapIcons(tUp, tDown, m_disabledPic);
    }
    if (nullptr != getMenu()) {
      getMenu()->CheckEntry(getMenuEntry());
    }
    started_();
  } else {
    stop();
    stopped_();
  }
}

void CSGContinuousAction::stop() {
  m_isRunning = false;
  if (getToolBar() && !m_imageFileName.empty()) {
    getToolBar()->ChangeIcon(getToolBarData(), m_imageFileName.c_str());
  }
  if (nullptr != m_button) {
    const TGPicture* tUp = m_upPic;
    const TGPicture* tDown = m_downPic;

    m_button->swapIcons(tUp, tDown, m_disabledPic);
  }
  if (nullptr != getMenu()) {
    getMenu()->UnCheckEntry(getMenuEntry());
  }
}

void CSGContinuousAction::globalEnable() { CSGAction::globalEnable(); }

void CSGContinuousAction::globalDisable() {
  if (!m_isRunning) {
    CSGAction::globalDisable();
  }
}

//
// const member functions
//

//
// static member functions
//