Main/Primary Frame/Window should not get focus if secondary Frame/Window is opened Topic is solved
Main/Primary Frame/Window should not get focus if secondary Frame/Window is opened
Is there any Flag or Managed window/frame or dialog which do not loose focus to Main window until closed?
I tried few but could not find the combination. I also tried ChildFocusEvent on main window but it do not work on grand children or crashes.
I tried few but could not find the combination. I also tried ChildFocusEvent on main window but it do not work on grand children or crashes.
Re: Main/Primary Frame/Window should not get focus if secondary Frame/Window is opened
wxDialog should work. Make sure to open it with ShowModal(), not Show().
Use the source, Luke!
Re: Main/Primary Frame/Window should not get focus if secondary Frame/Window is opened
Hi,
Can we see some code?
Thank you.
Can we see some code?
Thank you.
Re: Main/Primary Frame/Window should not get focus if secondary Frame/Window is opened
Hi,
What do you do differently?
Can you make a reproducer?
Also - you don't have to use event.Skip() everywhere. Sometimes it can be dangerous.
You absolutely have to use for all non command events, unless you know what you are doing. But wxCommandEvent-derived functions can survive without it.
Thank you.
What do you do differently?
Can you make a reproducer?
Also - you don't have to use event.Skip() everywhere. Sometimes it can be dangerous.
You absolutely have to use for all non command events, unless you know what you are doing. But wxCommandEvent-derived functions can survive without it.
Thank you.
Re: Main/Primary Frame/Window should not get focus if secondary Frame/Window is opened
I have reproducted the Issue here.
Code: Select all
#include<wx/wx.h>
class MyFrame : public wxFrame{
wxPanel *panel;
wxBoxSizer *vbox;
wxTextCtrl *txt;
wxDialog *dlg;
void OnChar(wxKeyEvent &event){
event.Skip();
if(event.GetKeyCode()==13){
std::cout<<"13";
txt=wxDynamicCast(event.GetEventObject(),wxTextCtrl);
txt->Navigate(wxNavigationKeyEvent::IsForward);
}
}
void OnFocusOut(wxFocusEvent &event){
event.Skip();
ShowInfo();
}
void ShowInfo(){
dlg=new wxDialog(wxDynamicCast(this,wxWindow),wxID_ANY,wxT("Dialog Example"));
vbox=new wxBoxSizer(wxVERTICAL);
txt=new wxTextCtrl(dlg,wxID_ANY,wxT("1234567890"),wxDefaultPosition,wxSize(200,30));
vbox->Add(txt,0,wxEXPAND,5);
dlg->SetSizer(vbox);
dlg->ShowModal();
}
public :
MyFrame():wxFrame(NULL,wxID_ANY,"Child Focus"){
panel=new wxPanel(this);
panel->Bind(wxEVT_CHAR_HOOK,&MyFrame::OnChar,this);
vbox=new wxBoxSizer(wxVERTICAL);
txt=new wxTextCtrl(panel,wxID_ANY,wxT(""),wxDefaultPosition,wxDefaultSize,wxTE_PROCESS_ENTER);
txt->Bind(wxEVT_KILL_FOCUS,&MyFrame::OnFocusOut,this);
vbox->Add(txt,0,wxEXPAND);
vbox->AddSpacer(5);
txt=new wxTextCtrl(panel,wxID_ANY,wxT(""));
vbox->Add(txt,0,wxEXPAND);
panel->SetSizer(vbox);
}
};
class MyApp: public wxApp
{
wxFrame* m_frame;
public:
bool OnInit()
{
m_frame = new MyFrame();
m_frame->Show();
return true;
}
};
IMPLEMENT_APP(MyApp);
Re: Main/Primary Frame/Window should not get focus if secondary Frame/Window is opened
Hi,
Why do you have 2 textcontrol created, but only one pointer?
Also, unrelated, you don't have to cast the pointer that you pass to the dialog constructor - just use this.
Thank you.
Why do you have 2 textcontrol created, but only one pointer?
Also, unrelated, you don't have to cast the pointer that you pass to the dialog constructor - just use this.
Thank you.
Re: Main/Primary Frame/Window should not get focus if secondary Frame/Window is opened
Please explain in words what you want to happen.
Use the source, Luke!
Re: Main/Primary Frame/Window should not get focus if secondary Frame/Window is opened
Just for the record: Displaying a modal dialog when a textcontrol loses focus, is horrible GUI design. When ever i encounter a program that's does it, it'll get uninstalled immediately
The problem is that inside a wxEVT_KILL_FOCUS handler, you're doing something that will cause more focus events. So you'll need some wx magic to delay setting the focus back to the text control.
The problem is that inside a wxEVT_KILL_FOCUS handler, you're doing something that will cause more focus events. So you'll need some wx magic to delay setting the focus back to the text control.
Code: Select all
void OnFocusOut(wxFocusEvent &event){
event.Skip();
CallAfter( [this] {
// this will get executed asynchronously after all events have been processed
ShowInfo();
});
}
void ShowInfo(){
// better: subclass wxDialog and put all the initialization in its constructor
// and create it on the stack instead of the heap
dlg=new wxDialog(this, wxID_ANY, wxT("Dialog Example"));
vbox=new wxBoxSizer(wxVERTICAL);
txt=new wxTextCtrl(dlg,wxID_ANY,wxT("1234567890"),wxDefaultPosition,wxSize(200,30));
vbox->Add(txt,0,wxEXPAND,5);
dlg->SetSizer(vbox);
dlg->ShowModal();
// if you create the dialog on the heap, you need to destroy it
dlg->Destroy();
}
Use the source, Luke!
Re: Main/Primary Frame/Window should not get focus if secondary Frame/Window is opened
I will remember it. @doublemaxJust for the record: Displaying a modal dialog when a textcontrol loses focus, is horrible GUI design. When ever i encounter a program that's does it, it'll get uninstalled immediately
Thank you..