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 » Sub classing CExtRibbonNode and CExtBarButton Collapse All
Subject Author Date
Dominik Braendlin Apr 30, 2010 - 8:22 AM

Hi Support,

I have sub classed my own CMyRibbonNode from CExtRibbonNode and CMyBarButton from CExtBarButton as in example “http://www.prof-uis.com/prof-uis/tech-support/support-forum/about-ribbonbar-part5-58991.aspx” explained.

Everything works fine except that I am missing the small icon that came along before I have sub classed the Button that I now have replaced with my own CMyRibbonNode. What else do I need to overwrite to get back the small and if wanted the big icon?

The result should show a ribbon button with a small icon to the left and the text to the right.

Thanks

Adrian

 

Dominik Braendlin May 4, 2010 - 11:58 PM

Sorry for the confusion. The link was only intended to relate to the subclass technique of ribbon controls I am using.


Here is the source I am working on.


 


.h File:



// CMyRibbonPressButton

 

class

{

 

public

DECLARE_DYNCREATE(CMyRibbonPressButton);

 

public

CMyRibbonPressButton(

CExtToolControlBar * pBar = NULL,

UINT nCmdID = ID_SEPARATOR,

UINT nStyle = 0

);

 

public

 

 

 

public

 

 

 

 

protected

 

 

protected

CLink m_lnkLUp;

CLink m_lnkLDown;

BOOL m_bTrackingLB;

};

 

 

// CMyRibbonPressButtonNode

 

class

{

 

public

DECLARE_SERIAL(CMyRibbonPressButtonNode);

 

public

CMyRibbonPressButtonNode(

UINT nCmdIdBasic = 0L,

UINT nCmdIdEffective = 0L,

CExtRibbonNode * pParentNode = NULL,

DWORD dwFlags = 0L,

__EXT_MFC_SAFE_LPCTSTR strTextInToolbar = NULL,

__EXT_MFC_SAFE_LPCTSTR strTextInMenu = NULL,

__EXT_MFC_SAFE_LPCTSTR strTextUser = NULL,

LPARAM lParam = 0L,

CExtCmdIcon * pIconCustomized = NULL

 

#if

,

INT nTextFieldWidth = 100,

INT nDropDownWidth = -2,

 

INT nDropDownHeightMax = 250

 

#endif

 

);

 

 

public

 

 

 

public

 

 

CExtRibbonPage * pBar,

CExtBarButton * pParentTBB = NULL

);

 

protected

CLink m_lnkLUp;

CLink m_lnkLDown;

CMyRibbonPressButton* m_pTBB;

};

  CMyRibbonPressButton : public CExtBarButton : : :void SetLButtonDownHdl(const CLink& hdl);void SetLButtonUpHdl(const CLink& hdl); :virtual void OnClick(CPoint point, bool bDown);virtual void OnPressedTrackingStart();virtual void OnPressedTrackingStop(); :void CancelAction(void); :   CMyRibbonPressButtonNode : public CExtRibbonNode : :  (!defined __EXT_MFC_NO_BUILTIN_TEXTFIELD)// (-1) - auto calc, (-2) - same as button area   // (!defined __EXT_MFC_NO_BUILTIN_TEXTFIELD) virtual ~CMyRibbonPressButtonNode(); :void SetLButtonDownHdl(const CLink& hdl);void SetLButtonUpHdl(const CLink& hdl); :virtual CRuntimeClass * _OnRibbonGetButtonRTC();virtual CExtBarButton * OnRibbonCreateBarButton( :

 

 

.cpp File

// CMyRibbonPressButton

IMPLEMENT_DYNCREATE(CMyRibbonPressButton, CExtBarButton);

//---------------------------------------------------------------------------

CMyRibbonPressButton::CMyRibbonPressButton(CExtToolControlBar * pBar,

UINT nCmdID, UINT nStyle)

: CExtBarButton(pBar, nCmdID, nStyle)

, m_bTrackingLB(FALSE)

{

}

//---------------------------------------------------------------------------

void

{

m_lnkLDown = hdl;

}

CMyRibbonPressButton::SetLButtonDownHdl(const CLink& hdl)

//---------------------------------------------------------------------------

void

{

m_lnkLUp = hdl;

}

CMyRibbonPressButton::SetLButtonUpHdl(const CLink& hdl)

//---------------------------------------------------------------------------

void

{

 

 

{

m_bTrackingLB = TRUE;

m_lnkLDown.Call(

}

 

CMyRibbonPressButton::OnClick(CPoint point, bool bDown)__super::OnClick(point, bDown);if (bDown == TRUE)this);else

{

CancelAction();

}

}

//---------------------------------------------------------------------------

void

{

 

}

CMyRibbonPressButton::OnPressedTrackingStart()__super::OnPressedTrackingStart();

//---------------------------------------------------------------------------

void

{

 

CancelAction();

}

CMyRibbonPressButton::OnPressedTrackingStop()__super::OnPressedTrackingStop();

//---------------------------------------------------------------------------

void

{

 

{

m_bTrackingLB = FALSE;

m_lnkLUp.Call(

}

}

 

CMyRibbonPressButton::CancelAction(void)if (m_bTrackingLB == TRUE)this);

// CMyRibbonPressButtonNode

IMPLEMENT_SERIAL(CMyRibbonPressButtonNode, CExtRibbonNode, VERSIONABLE_SCHEMA|1);

// CMyRibbonPressButtonNode

//---------------------------------------------------------------------------

CMyRibbonPressButtonNode::CMyRibbonPressButtonNode(

UINT nCmdIdBasic,

UINT nCmdIdEffective,

CExtRibbonNode * pParentNode,

DWORD dwFlags,

__EXT_MFC_SAFE_LPCTSTR strTextInToolbar,

__EXT_MFC_SAFE_LPCTSTR strTextInMenu,

__EXT_MFC_SAFE_LPCTSTR strTextUser,

LPARAM lParam,

CExtCmdIcon * pIconCustomized

#if

,

INT nTextFieldWidth,

INT nDropDownWidth,

INT nDropDownHeightMax

(!defined __EXT_MFC_NO_BUILTIN_TEXTFIELD)

#endif

// (!defined __EXT_MFC_NO_BUILTIN_TEXTFIELD)

)

: CExtRibbonNode(

nCmdIdBasic,

nCmdIdEffective,

pParentNode,

dwFlags,

strTextInToolbar,

strTextInMenu,

strTextUser,

lParam,

pIconCustomized

#if

,

nTextFieldWidth,

nDropDownWidth,

nDropDownHeightMax

(!defined __EXT_MFC_NO_BUILTIN_TEXTFIELD)

#endif

// (!defined __EXT_MFC_NO_BUILTIN_TEXTFIELD)

)

, m_pTBB(NULL)

{

}

//---------------------------------------------------------------------------

CMyRibbonPressButtonNode::~CMyRibbonPressButtonNode()

{

}

//---------------------------------------------------------------------------

void

{

ASSERT_VALID(

ASSERT(m_pTBB != NULL);

ASSERT_VALID(m_pTBB);

m_lnkLDown = hdl;

 

m_pTBB->SetLButtonDownHdl(hdl);

}

}

CMyRibbonPressButtonNode::SetLButtonDownHdl(const CLink& hdl)this);if (m_pTBB != NULL) {

//---------------------------------------------------------------------------

void

{

ASSERT_VALID(

ASSERT(m_pTBB != NULL);

ASSERT_VALID(m_pTBB);

m_lnkLUp = hdl;

 

m_pTBB->SetLButtonUpHdl(hdl);

}

}

 

CMyRibbonPressButtonNode::SetLButtonUpHdl(const CLink& hdl)this);if (m_pTBB != NULL) {

//---------------------------------------------------------------------------

CRuntimeClass * CMyRibbonPressButtonNode::_OnRibbonGetButtonRTC()

{

ASSERT_VALID(

 

}

this );return ( RUNTIME_CLASS( CMyRibbonPressButton ) );

//---------------------------------------------------------------------------

CExtBarButton * CMyRibbonPressButtonNode::OnRibbonCreateBarButton(

CExtRibbonPage * pBar, CExtBarButton * pParentTBB)

{

#if

m_pTBB =

STATIC_DOWNCAST(

CMyRibbonPressButton,

CExtRibbonNode::OnRibbonCreateBarButton( pBar, pParentTBB )

);

m_pTBB->SetLButtonDownHdl(m_lnkLDown);

m_pTBB->SetLButtonUpHdl(m_lnkLUp);

 

1return m_pTBB;

#else

return CExtRibbonNode::OnRibbonCreateBarButton( pBar, pParentTBB );

#endif

}


 


As you can see I am trying to subclass a CExtBarButton. It works so far exept that my subclass CMyRibbonPressButton is missing the Icon which would show if I would use a CExtBarButton instead.


 


 


 


 


Technical Support May 5, 2010 - 12:32 PM

The source code of the ribbon button does not override the CExtBarButton::PaintCompound(), CExtBarButton::CalculateLayout() and CExtBarButton::GetIcon() methods. This means your ribbon button should have exactly the same look as other push buttons in the ribbon bar. We suspect there is something else affecting to your button and not present in the code snippets in your message. Could you please try to insert your ribbon button and node classes into the RibbonBar sample project and send it to us?

Technical Support May 4, 2010 - 1:54 PM

You provided a link to the other forum thread. That thread discusses text field buttons. That’s why we supposed some of your text field buttons need icons before or after the editable area.
But now we need your help. Please describe us which buttons exactly are you using and which icons are missing?

Dominik Braendlin May 3, 2010 - 1:33 PM

Thank you for the help.


Unfortunately I am using CExtBarButton as base class not CExtBarTextFieldButton.


This base class does not provide the two virtual methods. Should I use a different base class? I have to catch the OnClick and the OnPressedTrackingStop mehtod. Thats why I subclassed CExtBarButton in the first place. Other than that the Button should look and feel like CExtBarButton.

Technical Support May 3, 2010 - 8:38 AM

First of all, your CExtBarTextFieldButton-derived class should override the CExtBarTextFieldButton::OnInplaceControlCalcRect() virtual method which computes the text field area rectangle. Your method should return a smaller rectangle to reserve some space on the left and/or right sides of the text field area.

Second, your CExtBarTextFieldButton-derived class should override the CExtBarTextFieldButton::PaintCompound() virtual method. Your virtual method should invoke the parent method and then draw the icons near the text field area defined by the OnInplaceControlCalcRect() virtual method.