Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:11:37

0001 // -*- C++ -*-
0002 //
0003 // Package:     Core
0004 // Class  :     FWCustomIconsButton
0005 //
0006 // Implementation:
0007 //     <Notes on implementation>
0008 //
0009 // Original Author:  Chris Jones
0010 //         Created:  Thu Oct 23 13:05:35 EDT 2008
0011 //
0012 
0013 // system include files
0014 #include <algorithm>
0015 #include <cassert>
0016 #include "TGPicture.h"
0017 #include "TVirtualX.h"
0018 // user include files
0019 #include "Fireworks/Core/interface/FWCustomIconsButton.h"
0020 
0021 //
0022 // constants, enums and typedefs
0023 //
0024 
0025 //
0026 // static data member definitions
0027 //
0028 
0029 //
0030 // constructors and destructor
0031 //
0032 FWCustomIconsButton::FWCustomIconsButton(const TGWindow* iParent,
0033                                          const TGPicture* iUpIcon,
0034                                          const TGPicture* iDownIcon,
0035                                          const TGPicture* iDisabledIcon,
0036                                          const TGPicture* iBelowMouseIcon,
0037                                          Int_t id,
0038                                          GContext_t norm,
0039                                          UInt_t option)
0040     : TGButton(iParent, id, norm, option),
0041       m_upIcon(iUpIcon),
0042       m_downIcon(iDownIcon),
0043       m_disabledIcon(iDisabledIcon),
0044       m_belowMouseIcon(iBelowMouseIcon),
0045       m_inside(false) {
0046   assert(nullptr != iUpIcon);
0047   assert(nullptr != iDownIcon);
0048   assert(nullptr != iDisabledIcon);
0049   gVirtualX->ShapeCombineMask(GetId(), 0, 0, iUpIcon->GetMask());
0050   SetBackgroundPixmap(iUpIcon->GetPicture());
0051   Resize(iUpIcon->GetWidth(), iUpIcon->GetHeight());
0052   fTWidth = iUpIcon->GetWidth();
0053   fTHeight = iUpIcon->GetHeight();
0054 }
0055 
0056 // FWCustomIconsButton::FWCustomIconsButton(const FWCustomIconsButton& rhs)
0057 // {
0058 //    // do actual copying here;
0059 // }
0060 
0061 FWCustomIconsButton::~FWCustomIconsButton() {}
0062 
0063 //
0064 // assignment operators
0065 //
0066 // const FWCustomIconsButton& FWCustomIconsButton::operator=(const FWCustomIconsButton& rhs)
0067 // {
0068 //   //An exception safe implementation is
0069 //   FWCustomIconsButton temp(rhs);
0070 //   swap(rhs);
0071 //
0072 //   return *this;
0073 // }
0074 
0075 //
0076 // member functions
0077 //
0078 void FWCustomIconsButton::swapIcons(const TGPicture*& iUpIcon,
0079                                     const TGPicture*& iDownIcon,
0080                                     const TGPicture*& iDisabledIcon) {
0081   std::swap(iUpIcon, m_upIcon);
0082   std::swap(iDownIcon, m_downIcon);
0083   std::swap(iDisabledIcon, m_disabledIcon);
0084   gVirtualX->ShapeCombineMask(GetId(), 0, 0, m_upIcon->GetMask());
0085   fClient->NeedRedraw(this);
0086 }
0087 
0088 void FWCustomIconsButton::setIcons(const TGPicture* iUpIcon,
0089                                    const TGPicture* iDownIcon,
0090                                    const TGPicture* iDisabledIcon,
0091                                    const TGPicture* iBelowMouseIcon) {
0092   m_upIcon = iUpIcon;
0093   m_downIcon = iDownIcon;
0094   m_disabledIcon = iDisabledIcon;
0095   m_belowMouseIcon = iBelowMouseIcon;
0096 
0097   gVirtualX->ShapeCombineMask(GetId(), 0, 0, m_upIcon->GetMask());
0098   fClient->NeedRedraw(this);
0099 }
0100 
0101 //
0102 // const member functions
0103 //
0104 
0105 //______________________________________________________________________________
0106 bool FWCustomIconsButton::HandleCrossing(Event_t* event) {
0107   if (event->fType == kEnterNotify)
0108     m_inside = true;
0109   else if (event->fType == kLeaveNotify)
0110     m_inside = false;
0111 
0112   fClient->NeedRedraw(this);
0113 
0114   return TGButton::HandleCrossing(event);
0115 }
0116 
0117 void FWCustomIconsButton::DoRedraw() {
0118   //ChangeOptions(0);
0119   //TGButton::DoRedraw();
0120   //Stole this from TGPictureButton.
0121   int x = (fWidth - fTWidth) >> 1;
0122   int y = (fHeight - fTHeight) >> 1;
0123 
0124   switch (fState) {
0125     case kButtonUp:
0126       if (m_belowMouseIcon && m_inside)
0127         m_belowMouseIcon->Draw(fId, fNormGC, x, y);
0128       else
0129         m_upIcon->Draw(fId, fNormGC, x, y);
0130       break;
0131     case kButtonEngaged:
0132     case kButtonDown:
0133       m_downIcon->Draw(fId, fNormGC, x, y);
0134       break;
0135     case kButtonDisabled:
0136     default:
0137       m_disabledIcon->Draw(fId, fNormGC, x, y);
0138   }
0139 }
0140 
0141 //
0142 // static member functions
0143 //