📄 btnctrl.cpp
字号:
// BtnCtrl.cpp: implementation of the CBtnCtrl class.
//
//////////////////////////////////////////////////////////////////////
#include "BtnCtrl.h"
#include <eikenv.h> // CEikonEnv iEikonEnv and AKN_LAF_COLOR
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CBtnCtrl * CBtnCtrl::NewL(const TRect& aRect, const CCoeControl* aParent,const TDesC & aCaption )
{
CBtnCtrl * pBtnCtrl = NewLC(aRect, aParent,aCaption ) ;
CleanupStack::Pop( pBtnCtrl ) ;
return pBtnCtrl ;
}
CBtnCtrl * CBtnCtrl::NewLC(const TRect& aRect, const CCoeControl* aParent,const TDesC & aCaption )
{
CBtnCtrl * pBtnCtrl = new(ELeave)CBtnCtrl(aCaption);
CleanupStack::PushL( pBtnCtrl) ;
pBtnCtrl->ConstructL(aRect, aParent) ; //执行二阶段构建
return pBtnCtrl ;
}
void CBtnCtrl::ConstructL(const TRect& aRect , const CCoeControl* aParent)
{
if( aParent == NULL)
CreateWindowL( ) ;
else
SetContainerWindowL(*aParent) ;
SetRect(aRect) ;
ActivateL( ) ;
}
void CBtnCtrl::Draw(const TRect& aRect) const
{
TBool bIsFocus = IsFocused( ) ;
CWindowGc & gc=SystemGc( ) ;
gc.SetPenColor(KRgbBlack);
//画背景色
if(bIsFocus) //已获得焦点
{
gc.SetBrushColor(TRgb(211,200,188) ); //KRgbRed
}
else
{
gc.SetBrushColor(KRgbWhite) ;
}
gc.Clear( aRect ) ;
gc.DrawRect( aRect ) ;
const CFont* font=iEikonEnv->AnnotationFont( );
gc.UseFont(font);
gc.DrawText(iCaption,aRect,16, CGraphicsContext::ELeft,15) ;
gc.DiscardFont( );
//font = iEikonEnv->AnnotationFont( );
}
void CBtnCtrl::SetFocus(TBool aFocus,TDrawNow aDrawNow)
{
CCoeControl::SetFocus(aFocus,ENoDrawNow);
if(aDrawNow == ENoDrawNow )
return ;
this->DrawDeferred( );
}
TSize CBtnCtrl::MinimumSize( )
{
return TSize(50,20);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -