CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC4_patch1/src/Fireworks/Core/src/FWCustomIconsButton.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:     Core
00004 // Class  :     FWCustomIconsButton
00005 //
00006 // Implementation:
00007 //     <Notes on implementation>
00008 //
00009 // Original Author:  Chris Jones
00010 //         Created:  Thu Oct 23 13:05:35 EDT 2008
00011 // $Id: FWCustomIconsButton.cc,v 1.7 2009/11/29 15:56:33 amraktad Exp $
00012 //
00013 
00014 // system include files
00015 #include <algorithm>
00016 #include <assert.h>
00017 #include "TGPicture.h"
00018 
00019 // user include files
00020 #include "Fireworks/Core/interface/FWCustomIconsButton.h"
00021 
00022 
00023 //
00024 // constants, enums and typedefs
00025 //
00026 
00027 //
00028 // static data member definitions
00029 //
00030 
00031 //
00032 // constructors and destructor
00033 //
00034 FWCustomIconsButton::FWCustomIconsButton(const TGWindow* iParent,
00035                                          const TGPicture* iUpIcon,
00036                                          const TGPicture* iDownIcon,
00037                                          const TGPicture* iDisabledIcon,
00038                                          const TGPicture* iBelowMouseIcon,
00039                                          Int_t id, GContext_t norm, UInt_t option) :
00040    TGButton(iParent,id, norm, option),
00041    m_upIcon(iUpIcon),
00042    m_downIcon(iDownIcon),
00043    m_disabledIcon(iDisabledIcon),
00044    m_belowMouseIcon(iBelowMouseIcon),
00045    m_inside(false)
00046 {
00047    assert(0!=iUpIcon);
00048    assert(0!=iDownIcon);
00049    assert(0!=iDisabledIcon);
00050    gVirtualX->ShapeCombineMask(GetId(), 0, 0, iUpIcon->GetMask());
00051    SetBackgroundPixmap(iUpIcon->GetPicture());
00052    Resize(iUpIcon->GetWidth(),iUpIcon->GetHeight());
00053    fTWidth = iUpIcon->GetWidth();
00054    fTHeight = iUpIcon->GetHeight();
00055 }
00056 
00057 // FWCustomIconsButton::FWCustomIconsButton(const FWCustomIconsButton& rhs)
00058 // {
00059 //    // do actual copying here;
00060 // }
00061 
00062 FWCustomIconsButton::~FWCustomIconsButton()
00063 {
00064 }
00065 
00066 //
00067 // assignment operators
00068 //
00069 // const FWCustomIconsButton& FWCustomIconsButton::operator=(const FWCustomIconsButton& rhs)
00070 // {
00071 //   //An exception safe implementation is
00072 //   FWCustomIconsButton temp(rhs);
00073 //   swap(rhs);
00074 //
00075 //   return *this;
00076 // }
00077 
00078 //
00079 // member functions
00080 //
00081 void
00082 FWCustomIconsButton::swapIcons(const TGPicture*& iUpIcon,
00083                                const TGPicture*& iDownIcon,
00084                                const TGPicture*& iDisabledIcon)
00085 {
00086    std::swap(iUpIcon,m_upIcon);
00087    std::swap(iDownIcon,m_downIcon);
00088    std::swap(iDisabledIcon,m_disabledIcon);
00089    gVirtualX->ShapeCombineMask(GetId(), 0, 0, m_upIcon->GetMask());
00090    fClient->NeedRedraw(this);
00091 }
00092 
00093 void
00094 FWCustomIconsButton::setIcons(const TGPicture* iUpIcon,
00095                               const TGPicture* iDownIcon,
00096                               const TGPicture* iDisabledIcon,
00097                               const TGPicture* iBelowMouseIcon)
00098 {
00099    m_upIcon       = iUpIcon;
00100    m_downIcon     = iDownIcon;
00101    m_disabledIcon = iDisabledIcon;
00102    m_belowMouseIcon = iBelowMouseIcon;
00103 
00104    gVirtualX->ShapeCombineMask(GetId(), 0, 0, m_upIcon->GetMask());
00105    fClient->NeedRedraw(this);
00106 }
00107 
00108 //
00109 // const member functions
00110 //
00111 
00112 //______________________________________________________________________________
00113 bool FWCustomIconsButton::HandleCrossing(Event_t *event)
00114 {
00115    if (event->fType == kEnterNotify)
00116       m_inside = true;      
00117    else if (event->fType == kLeaveNotify)   
00118       m_inside = false;
00119 
00120    fClient->NeedRedraw(this);
00121 
00122    return TGButton::HandleCrossing(event);
00123 }
00124 
00125 
00126 void
00127 FWCustomIconsButton::DoRedraw()
00128 {
00129    //ChangeOptions(0);
00130    //TGButton::DoRedraw();
00131    //Stole this from TGPictureButton.
00132    int x = (fWidth - fTWidth) >> 1;
00133    int y = (fHeight - fTHeight) >> 1;
00134 
00135    gVirtualX->FillRectangle(fId, fNormGC, 2,2,fWidth,fHeight);
00136    
00137    switch(fState)
00138    {
00139       case kButtonUp:
00140          if (m_belowMouseIcon && m_inside)
00141               m_belowMouseIcon->Draw(fId, fNormGC,x,y);
00142          else
00143               m_upIcon->Draw(fId, fNormGC,x,y);
00144          break;
00145       case kButtonEngaged:
00146       case kButtonDown:
00147          m_downIcon->Draw(fId, fNormGC,x,y);
00148          break;
00149       case kButtonDisabled:
00150       default:
00151          m_disabledIcon->Draw(fId, fNormGC,x,y);
00152    }
00153 }
00154 
00155 //
00156 // static member functions
00157 //