Print Page | Close Window

Shifting Focus while Tabbing in a toolbar

Printed From: Codejock Forums
Category: Codejock Products
Forum Name: Toolkit Pro
Forum Description: Topics Related to Codejock Toolkit Pro
URL: http://forum.codejock.com/forum_posts.asp?TID=2372
Printed Date: 08 November 2025 at 9:48pm
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: Shifting Focus while Tabbing in a toolbar
Posted By: mwest
Subject: Shifting Focus while Tabbing in a toolbar
Date Posted: 13 June 2005 at 5:00pm
How do you shift focus along with the selection (highlight) when tabbing through controls (like CControlComboBoxEx)?

I am having trouble getting certain notifications.

Take a look at the Custom Themes Sample.  How can you make it enter focus into the "masked" combo box when the user tabs from a previous control like the "new" box?

The user should be able to start typing without having to hit <enter> first.

Thanks.



Replies:
Posted By: Oleg
Date Posted: 14 June 2005 at 5:05am
Thank you for this good suggestion. We changed this behaviour.

-------------
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS


Posted By: mwest
Date Posted: 14 June 2005 at 9:52am
Will this change be in a future release?  If so, what did you do to move the focus?


Posted By: Oleg
Date Posted: 17 June 2005 at 7:24am
It is added for 9.70 release. Key handled in CXTPCommandBar::OnKeyDown.

-------------
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS


Posted By: mwest
Date Posted: 01 August 2005 at 5:26pm
For those out there, I came up with an ugly hack to get the tabbing to work (the cursor enters an edit box or a dropdown, regardless of whether it is inherited from CWnd or CXTPControl) without altering the Code Jock source code.  The work-around is not pleasant, but it seems to work.  If there is a better solution, I would love to hear it.

1)  Because we cannot alter CXTPCommandBar and we cannot use a custom CommandBar, we need to make a new class that inherits from CXTPToolBar.  Call it CToolBarEx or something.

2)  When adding the toolbar that needs the tabbing behavior in CMainFrame:: OnCreate, explicitly indicate what toolbar class to use:

CXTPToolBar* pToolbar = (CXTPToolBar*)pCommandBars->Add(“Toolbar”, xtpBarTop, RUNTIME_CLASS(CToolBarEx));


3)    In the CToolBar class, override the OnKeyDown(UINT nChar).  Take note this is a custom Codejock method and not the standard OnKeyDown we all know and love.

4)    The body of the OnKeyDown should be:


if( nChar == VK_TAB )
{
  int nNum = m_pControls->GetNext(m_nSelected, +1);
  CXTPControl* pCtrl = GetControl(nNum);
  DWORD tag = pCtrl->GetTag();
  if( tag == 42 )
  {
    SetSelected(nNum, TRUE);
    SetFocusedControl(pCtrl);
    return CXTPCommandBar::OnKeyDown(VK_RETURN);
  }   
}

return CXTPToolBar::OnKeyDown(nChar);


The code essentially sets the next control up for focus and calls an extra OnKeyDown, but with VK_ENTER so that all the codejock code will perform like normal.

The ‘if(tag == 42 )’ statement is noteworthy because we want to check to see if this control requested the tabbing-enter (You might not want an Enter performed on a button).

5)  When making the control set the Tag data to flag it wants to be a part of the tab-enter in CMainFrame::OnCreateControl(LPCREATECONTROLSTRUCT lpCreateControl).


// ...Next to your
lpCreateControl->pControl = m_pComboUrl;
// ...put
pCreateControl->pControl->SetTag( 42 );


6)  Test it


Posted By: g_j_a_i_n
Date Posted: 14 September 2005 at 5:23am


Fantastic !

Thank you so much for sharing. Thank you.

With your suggestion, the following statement has solved the problem:

return CXTPCommandBar::OnKeyDown(VK_RETURN);

The mistake I did was that I always returned TRUE.
I am still not sure how you got this idea.

I was having problem with removing the focus from the combo box totally. What I was not able to do.

Thanks again

Regards,
Gautam Jain




Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.04 - http://www.webwizforums.com
Copyright ©2001-2021 Web Wiz Ltd. - https://www.webwiz.net