How to use "Tab" to move the focus on GUI?

[size=134]hello, Anyone knows how can I just type “Tab” to move the focus on GUI?
I have a GUI base on ROOT and have tens of buttons. I want to use “Tab” to loop on the buttons which can help to make the slection more fast.
Thank you.[/size]

Hi,
You can do something like this :

[code]//______________________________________________________________________________
Bool_t MyDialog::ProcessMessage(Long_t msg, Long_t parm1, Long_t)
{
// Process messages coming from widgets associated with the dialog.
switch (GET_MSG(msg)) {
case kC_TEXTENTRY:
switch (GET_SUBMSG(msg)) {
case kTE_ENTER:
switch (parm1) {
case Id1:
fTxt2->SetFocus();
break;
case Id2:
fTxt3->SetFocus();
break;
case Id3:
fTxt1->SetFocus();
break;
}
break;
case kTE_TAB:
switch (parm1) {
case Id1:
fTxt2->SetFocus();
break;
case Id2:
fTxt3->SetFocus();
break;
case Id3:
fTxt1->SetFocus();
break;
}
break;
default:
break;
}
break;

  default:
     break;

}
return kTRUE;
}
[/code]
Take a look in $(ROOTSYS)/test/RootShower, there is code using this method (i.e SettingsDlg.cxx).

Cheers,
Bertrand.

Hi,
the following macro shows how to do it.

Regards. Valeriy


// Mainframe macro generated from application: /home/onuchin/flash/root/bin/root.exe
// By ROOT version 5.11/07 on 2006-06-09 21:25:08

#if !defined( __CINT__) || defined (__MAKECINT__)

#ifndef ROOT_TGDockableFrame
#include "TGDockableFrame.h"
#endif
#ifndef ROOT_TGMenu
#include "TGMenu.h"
#endif
#ifndef ROOT_TGMdiDecorFrame
#include "TGMdiDecorFrame.h"
#endif
#ifndef ROOT_TG3DLine
#include "TG3DLine.h"
#endif
#ifndef ROOT_TGMdiFrame
#include "TGMdiFrame.h"
#endif
#ifndef ROOT_TGMdiMainFrame
#include "TGMdiMainFrame.h"
#endif
#ifndef ROOT_TGuiBldHintsButton
#include "TGuiBldHintsButton.h"
#endif
#ifndef ROOT_TGMdiMenu
#include "TGMdiMenu.h"
#endif
#ifndef ROOT_TGListBox
#include "TGListBox.h"
#endif
#ifndef ROOT_TGNumberEntry
#include "TGNumberEntry.h"
#endif
#ifndef ROOT_TGScrollBar
#include "TGScrollBar.h"
#endif
#ifndef ROOT_TGuiBldHintsEditor
#include "TGuiBldHintsEditor.h"
#endif
#ifndef ROOT_TGFileDialog
#include "TGFileDialog.h"
#endif
#ifndef ROOT_TGShutter
#include "TGShutter.h"
#endif
#ifndef ROOT_TGButtonGroup
#include "TGButtonGroup.h"
#endif
#ifndef ROOT_TGCanvas
#include "TGCanvas.h"
#endif
#ifndef ROOT_TGFSContainer
#include "TGFSContainer.h"
#endif
#ifndef ROOT_TGButton
#include "TGButton.h"
#endif
#ifndef ROOT_TGuiBldEditor
#include "TGuiBldEditor.h"
#endif
#ifndef ROOT_TGSplitter
#include "TGSplitter.h"
#endif
#ifndef ROOT_TGFSComboBox
#include "TGFSComboBox.h"
#endif
#ifndef ROOT_TGLabel
#include "TGLabel.h"
#endif
#ifndef ROOT_TRootGuiBuilder
#include "TRootGuiBuilder.h"
#endif
#ifndef ROOT_TGTab
#include "TGTab.h"
#endif
#ifndef ROOT_TGListView
#include "TGListView.h"
#endif
#ifndef ROOT_TGStatusBar
#include "TGStatusBar.h"
#endif
#ifndef ROOT_TGToolTip
#include "TGToolTip.h"
#endif
#ifndef ROOT_TGToolBar
#include "TGToolBar.h"
#endif
#ifndef ROOT_TGuiBldDragManager
#include "TGuiBldDragManager.h"
#endif

#include "Riostream.h"
#include "KeySymbols.h"

#endif

TGMainFrame *fMainFrame1057;
TList *listOfButtons= new TList();

///////////// event handler ///////////////////
void handleTabs(Event_t *event)
{
   // the function to handle tab key pressing

   ///////// only key press events ////////////////////
   if (event->fType != kGKeyPress) {
      return;
   }

   static TGTextButton *cur = 0;

   if (!cur) {
      cur = (TGTextButton*)listOfButtons->First();
   } else {
      cur->SetDown(kFALSE);
      cur = (TGTextButton*)listOfButtons->After(cur);
   }

   if(!cur) {
      cur = (TGTextButton*)listOfButtons->First();
   }
   cur->SetDown(kTRUE);
}

void tst()
{

   // main frame
   fMainFrame1057 = new TGMainFrame(gClient->GetRoot(),10,10,kMainFrame | kVerticalFrame);
   fMainFrame1057->SetLayoutBroken(kTRUE);

   //////// grab key ///////////
   gVirtualX->GrabKey(fMainFrame1057->GetId(),gVirtualX->KeysymToKeycode(kKey_Tab), 0, kTRUE);

   ////// connect /// to event handler
   fMainFrame1057->Connect("ProcessedEvent(Event_t*)", 0, 0, "handleTabs(Event_t*)");

   // composite frame
   TGCompositeFrame *fCompositeFrame721 = new TGCompositeFrame(fMainFrame1057,77,108);
   fCompositeFrame721->SetLayoutManager(new TGVerticalLayout(fCompositeFrame721));

   TGTextButton *fTextButton722 = new TGTextButton(fCompositeFrame721,"fTextButton514");
   ///////// add to the list of buttons
   listOfButtons->Add(fTextButton722);

   fTextButton722->SetTextJustify(36);
   fTextButton722->Resize(73,23);
   fCompositeFrame721->AddFrame(fTextButton722, new TGLayoutHints(kLHintsLeft | kLHintsTop,2,2,2,2));

   TGTextButton *fTextButton723 = new TGTextButton(fCompositeFrame721,"fTextButton517");
   ///////// add to the list of buttons
   listOfButtons->Add(fTextButton723);

   fTextButton723->SetTextJustify(36);
   fTextButton723->Resize(73,23);
   fCompositeFrame721->AddFrame(fTextButton723, new TGLayoutHints(kLHintsLeft | kLHintsTop,2,2,2,2));

   TGTextButton *fTextButton724 = new TGTextButton(fCompositeFrame721,"fTextButton524");
   ///////// add to the list of buttons
   listOfButtons->Add(fTextButton724);

   fTextButton724->SetTextJustify(36);
   fTextButton724->Resize(73,23);
   fCompositeFrame721->AddFrame(fTextButton724, new TGLayoutHints(kLHintsLeft | kLHintsTop,2,2,2,2));

   TGTextButton *fTextButton725 = new TGTextButton(fCompositeFrame721,"fTextButton527");
   //////////// add to the list of buttons
   listOfButtons->Add(fTextButton725);

   fTextButton725->SetTextJustify(36);
   fTextButton725->Resize(73,23);
   fCompositeFrame721->AddFrame(fTextButton725, new TGLayoutHints(kLHintsLeft | kLHintsTop,2,2,2,2));

   fMainFrame1057->AddFrame(fCompositeFrame721, new TGLayoutHints(kLHintsLeft | kLHintsTop,2,2,2,2));
   fCompositeFrame721->MoveResize(176,16,77,108);

   // composite frame
   TGCompositeFrame *fCompositeFrame530 = new TGCompositeFrame(fMainFrame1057,77,108);
   fCompositeFrame530->SetLayoutManager(new TGVerticalLayout(fCompositeFrame530));

   TGTextButton *fTextButton514 = new TGTextButton(fCompositeFrame530,"fTextButton514");
   //////////// add to the list of buttons
   listOfButtons->Add(fTextButton514);

   fTextButton514->SetTextJustify(36);
   fTextButton514->Resize(73,23);
   fCompositeFrame530->AddFrame(fTextButton514, new TGLayoutHints(kLHintsLeft | kLHintsTop,2,2,2,2));

   TGTextButton *fTextButton517 = new TGTextButton(fCompositeFrame530,"fTextButton517");
   //////////// add to the list of buttons
   listOfButtons->Add(fTextButton517);

   fTextButton517->SetTextJustify(36);
   fTextButton517->Resize(73,23);
   fCompositeFrame530->AddFrame(fTextButton517, new TGLayoutHints(kLHintsLeft | kLHintsTop,2,2,2,2));

   TGTextButton *fTextButton524 = new TGTextButton(fCompositeFrame530,"fTextButton524");
   //////////// add to the list of buttons
   listOfButtons->Add(fTextButton524);

   fTextButton524->SetTextJustify(36);
   fTextButton524->Resize(73,23);
   fCompositeFrame530->AddFrame(fTextButton524, new TGLayoutHints(kLHintsLeft | kLHintsTop,2,2,2,2));

   TGTextButton *fTextButton527 = new TGTextButton(fCompositeFrame530,"fTextButton527");
   ///////// add to the list of buttons
   listOfButtons->Add(fTextButton527);

   fTextButton527->SetTextJustify(36);
   fTextButton527->Resize(73,23);
   fCompositeFrame530->AddFrame(fTextButton527, new TGLayoutHints(kLHintsLeft | kLHintsTop,2,2,2,2));

   fMainFrame1057->AddFrame(fCompositeFrame530, new TGLayoutHints(kLHintsNormal));
   fCompositeFrame530->MoveResize(40,16,77,108);

   fMainFrame1057->MapSubwindows();

   fMainFrame1057->Resize(fMainFrame1057->GetDefaultSize());
   fMainFrame1057->MapWindow();
   fMainFrame1057->Resize(269,187);
}  


That 's great. Thank you very much.