00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include <algorithm>
00016 #include <assert.h>
00017 #include "TGPicture.h"
00018
00019
00020 #include "Fireworks/Core/interface/FWCustomIconsButton.h"
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
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
00058
00059
00060
00061
00062 FWCustomIconsButton::~FWCustomIconsButton()
00063 {
00064 }
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
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
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
00130
00131
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
00157