Professional UI Solutions
Site Map   /  Register
 
 

Forum

Please Log In to post a new message or reply to an existing one. If you are not registered, please register.

NOTE: Some forums may be read-only if you are not currently subscribed to our technical support services.

Forums » Prof-UIS Tech Support » Focus on an Icon-only CExtButton Collapse All
Subject Author Date
Krustys Donuts Oct 21, 2008 - 11:20 AM

Dear Support,


I have a CExtButton object that displays an icon only. That is, no text. The problem is when this button has the focus, the focus rectangle is not displayed. If text is added to this button, the focus rectangle is shown (around the text) as expected. How, when the button is icon only, can I get the focus rectangle to display? I have another bitmap that should be used when the button has the focus, but I do not know to which CExtButton member variable this icon should be assigned.


Thanks,


Gil

Technical Support Oct 21, 2008 - 1:11 PM

The following class will appear in Prof-UIS 2.84 so you can put it at the end of .../Include/ExtButton.h and .../Src/ExtButton.cpp files and use in your project(s):

/////////////////////////////////////////////////////////////////////////////
// CExtIconButton

class __PROF_UIS_API CExtIconButton : public CExtButton
{
public:
            DECLARE_DYNCREATE( CExtIconButton );
            CExtIconButton();
            virtual ~CExtIconButton();

            CRect m_rcFocusRectPadding;

            // Overrides
            //{{AFX_VIRTUAL(CExtIconButton)
            //}}AFX_VIRTUAL
            
            //{{AFX_MSG(CExtIconButton)
            //}}AFX_MSG
            
            DECLARE_MESSAGE_MAP()
protected:
            virtual void _RenderImpl( // buffered paint
                        CDC & dc,
                        bool bTransparent = false,
                        bool bCombinedContent = false
                        );
}; /// class CExtIconButton


/////////////////////////////////////////////////////////////////////////////
// CExtIconButton

IMPLEMENT_DYNCREATE( CExtIconButton, CExtButton );

CExtIconButton::CExtIconButton()
            : m_rcFocusRectPadding( 1, 1, 1, 1 )
{
}

CExtIconButton::~CExtIconButton()
{
}

BEGIN_MESSAGE_MAP( CExtIconButton, CExtButton )
//{{AFX_MSG_MAP(CExtIconButton)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

void CExtIconButton::_RenderImpl(
            CDC & dc,
            bool bTransparent, // = false
            bool bCombinedContent // = false
            )
{
            ASSERT_VALID( this );
            m_bSeparatedDropDown = false; // should never become a split button
CExtPaintManager * pPM = PmBridge_GetPM();
            ASSERT_VALID( pPM );
CRect rcClient;
            GetClientRect( &rcClient );
COLORREF clrBackground = GetBkColor();
            if(                     (! bTransparent )
//                      &&        (! (bHover || bPushed) )
                        &&        pPM->GetCb2DbTransparentMode(this)
                        &&        ( clrBackground == COLORREF(-1L) )
                        )
            {
                        CExtPaintManager::stat_ExcludeChildAreas(
                                    dc,
                                    GetSafeHwnd(),
                                    CExtPaintManager::stat_DefExcludeChildAreaCallback
                                    );
                        if( pPM->PaintDockerBkgnd( true, dc, this ) )
                                    bTransparent = true;
            }
            if( ! bTransparent )
                        dc.FillSolidRect( 
                                    &rcClient, 
                                    (clrBackground != COLORREF(-1L)) 
                                                ? clrBackground 
                                                : pPM->GetColor( CExtPaintManager::CLR_3DFACE_OUT, this ) 
                                    );
            if( ! m_icon.IsEmpty() )
            {
                        //bool bDefault = GetDefault() ? true : false;
                        bool bPushed = m_bPushed ? true : false;
                        bool bEnabled = OnQueryWindowEnabledState();
                        //bool bFlat = GetFlat() ? true : false;
                        bool bHover = ( m_bMouseOver && !CExtPopupMenuWnd::IsMenuTracking() ) ? true : false;
                        CExtCmdIcon::e_paint_type_t ePT =
                                    bEnabled
                                                ? ( bPushed
                                                                        ? CExtCmdIcon::__PAINT_PRESSED
                                                                        : ( bHover
                                                                                                ? CExtCmdIcon::__PAINT_HOVER
                                                                                                : CExtCmdIcon::__PAINT_NORMAL
                                                                                                )
                                                                        )
                                                : CExtCmdIcon::__PAINT_DISABLED
                                                ;
                        CSize _sizeClient = rcClient.Size();
                        CSize _sizeIcon = m_icon.GetSize();
                        CRect rcIcon(
                                    rcClient.left,
                                    rcClient.top,
                                    rcClient.left + _sizeIcon.cx,
                                    rcClient.top + _sizeIcon.cy
                                    );
                        if( _sizeClient != _sizeIcon )
                                    rcIcon.OffsetRect(
                                                ( _sizeClient.cx - _sizeIcon.cx ) / 2,
                                                ( _sizeClient.cy - _sizeIcon.cy ) / 2
                                                );
                        m_icon.Paint( pPM, dc.m_hDC, rcIcon, ePT );
            } // if( ! m_icon.IsEmpty() )
bool bDrawFocusRect = ( (!bCombinedContent) && GetFocus() == this && m_bDrawFocusRect ) ? true : false;
            if( GetParent()->IsKindOf(RUNTIME_CLASS(CControlBar)) )
            {
                        bDrawFocusRect = false;
                        //bFlat = true;
            }
            if( bDrawFocusRect )
            {
                        CRect rcFocus( rcClient );
                        rcFocus.DeflateRect( &m_rcFocusRectPadding );
                        dc.DrawFocusRect( &rcClient );
            }
}