Set focus to a component in a dialogbox

Hi,

I was wondering if anybody could help me with this.
I need textEditorDesc componet to grab keyboard focus when the dialogbox(modal) is activated, please see the code below.

How can I do it?

Thank you.

void cRefTypeTable::EditTypeDialog( ULONG item)
	{
		cEditRefItem editTypeDialogPane(item, m_pConn);

		editTypeDialogPane.grabKeyboardFocus();

		int i = DialogWindow::showModalDialog(T("Edit Item!"),&editTypeDialogPane,this,Colours::azure,true);

		if(!i)
			return;

		RecordSetRefresh();
		repaint();

		return;
	}

and this is the construcrtor of cEditRefItem:

[code]
cEditRefItem::cEditRefItem (ULONG item, _ConnectionPtr& pConn)
: m_pConn(pConn),
textEditorDesc (0),
label14 (0),

{

addAndMakeVisible (textEditorDesc = new TextEditor (T("new text editor")));
textEditorDesc->setExplicitFocusOrder (1);
textEditorDesc->setMultiLine (false);
textEditorDesc->setReturnKeyStartsNewLine (false);
textEditorDesc->setReadOnly (false);
textEditorDesc->setScrollbarsShown (true);
textEditorDesc->setCaretVisible (true);
textEditorDesc->setPopupMenuEnabled (true);
textEditorDesc->setColour (TextEditor::textColourId, Colours::red);
textEditorDesc->setText (String::empty);

addAndMakeVisible (label14 = new Label (T("new label"),
                                        T("Credit/Debit")));
label14->setFont (juce::Font (15.0000f, juce::Font::plain));
label14->setJustificationType (Justification::centredLeft);
label14->setEditable (false, false, false);
label14->setColour (TextEditor::textColourId, Colours::black);
label14->setColour (TextEditor::backgroundColourId, Colour (0x0));



//[UserPreSize]

//[/UserPreSize]

setSize (660, 400);

//[Constructor] You can add your own custom stuff here..
try{
	TESTHR(m_pRstType.CreateInstance(__uuidof(Recordset)));
}
catch(_com_error &e){
	MessageComError(e);
}

textEditorDesc->grabKeyboardFocus();


//[/Constructor]

}

[/code][/code]

Maybe the Component::canModalEventBeSentToComponent method would be useful for you?

Hi,

Please help. How do I use it? I’ve already tried everything that I could think of, how do I make a componet in the dialog(i.e. all created in constructor, jucer generated code) grab input when its presented to the user?

thanks

Try making the dialog visible before you do the grabFocus call…

I’ve tried, please see the code below, is that what you mean?
One more thing, a dialog being modal is there a method that gets called (from DialogWindow::showModalDialog) right after the dialog is presented to the user? so that I could do

textEditorPassword->grabKeyboardFocus();

in it.

i.e. something like calledRightAfterDialogIsMadeVisible()

thank you for your time

void doChangePasswordProc( bool preload_password ) { cChangePasswordDlg dlg(m_pConn, cSessions::Instance().getCurrent().getLoginId(), preload_password ); //dlg.setWantsKeyboardFocus(false); dlg.setVisible(true); dlg.grabKeyboardFocus(); dlg.grabFocus(); //dlg.grabKeyboardFocus(); // dlg.toFront(true); int i = DialogWindow::showModalDialog( T("Change Password"), &dlg, this, Colours::azure, true);

[code]class cChangePasswordDlg : public Component,
public ButtonListener
{
public:
//==============================================================================
cChangePasswordDlg (_ConnectionPtr& pConn, ULONG login_id, bool preload_old_password);
~cChangePasswordDlg();

//==============================================================================
//[UserMethods]     -- You can add your own custom methods in this section.
bool canModalEventBeSentToComponent ( Component *  targetComponent  ){
	return true;
}
void grabFocus(){
	textEditorPassword->grabKeyboardFocus();
}
/* void focusGained (FocusChangeType cause){
	textEditorPassword->grabKeyboardFocus();
}*/
//[/UserMethods][/code]

I was wondering, is this normal or am I doing something wrong? when a dialog is created and presented via DialogWindow::showModalDialog and I manualy set focus to a textEditor componet in it (i.e. to enter text), if I try to drag the dialog through its title bar the componet that I’ve been working in (textEditor componet, entering text) loses focus.

Hmm, I guess that’s just the top-level dialog component grabbing focus. I should probably tweak it so that it doesn’t do that…

[quote=“appugno”]I’ve tried, please see the code below, is that what you mean?
One more thing, a dialog being modal is there a method that gets called (from DialogWindow::showModalDialog) right after the dialog is presented to the user? so that I could do

textEditorPassword->grabKeyboardFocus();

in it.

i.e. something like calledRightAfterDialogIsMadeVisible()

thank you for your time

void doChangePasswordProc( bool preload_password ) { cChangePasswordDlg dlg(m_pConn, cSessions::Instance().getCurrent().getLoginId(), preload_password ); //dlg.setWantsKeyboardFocus(false); dlg.setVisible(true); dlg.grabKeyboardFocus(); dlg.grabFocus(); //dlg.grabKeyboardFocus(); // dlg.toFront(true); int i = DialogWindow::showModalDialog( T("Change Password"), &dlg, this, Colours::azure, true);

[code]class cChangePasswordDlg : public Component,
public ButtonListener
{
public:
//==============================================================================
cChangePasswordDlg (_ConnectionPtr& pConn, ULONG login_id, bool preload_old_password);
~cChangePasswordDlg();

//==============================================================================
//[UserMethods]     -- You can add your own custom methods in this section.
bool canModalEventBeSentToComponent ( Component *  targetComponent  ){
	return true;
}
void grabFocus(){
	textEditorPassword->grabKeyboardFocus();
}
/* void focusGained (FocusChangeType cause){
	textEditorPassword->grabKeyboardFocus();
}*/
//[/UserMethods][/code][/quote]

Have you seen this post?

Hmm, I guess that’s just the top-level dialog component grabbing focus. I should probably tweak it so that it doesn’t do that…[/quote]

Thank you!