Jan Engelhardt
2014-04-03 14:10:05 UTC
I am looking for a way to navigate in a ListCtrl while another widget
has focus. A TextCtrl gets CHAR events as usual. There is just a
single line in this TextCtrl, so WXK_UP/WXK_DOWN does not have much
of a meaning. In fact, GTK2 "abuses" it to jump to the next widget
like TAB normally would.
Anyhow, I would like to use WXK_UP/DOWN for moving around the
ListCtrl. It would seem that wxPostEvent and ProcessEvent are both
ignored. The code below is an example of that.
This may have to do with the fact that wxListMainWindow is separate
from wxListCtrl itself. If possible, I would rather avoid having to
copy what's in wxListMainWindow::OnChar.
#include <wx/wx.h>
#include <wx/listctrl.h>
#include <cstdio>
class M : public wxFrame {
public:
wxTextCtrl *text;
wxListCtrl *list;
public: M(void) : wxFrame(NULL, wxID_ANY, "") {
text = new wxTextCtrl(this, wxID_ANY);
text->Bind(wxEVT_CHAR, [this](wxKeyEvent &event) {
auto k = event.GetKeyCode();
if (list != NULL && (k == WXK_UP || k == WXK_DOWN)) {
wxKeyEvent copy = event;
copy.SetId(list->GetId());
copy.SetEventObject(list);
wxPostEvent(list, copy);
//list->GetEventHandler()->ProcessEvent(copy);
return;
}
event.Skip();
});
list = new wxListCtrl(this, wxID_ANY);
list->AppendColumn("head");
list->InsertItem(0, "first");
list->InsertItem(1, "second");
list->SetInitialSize(wxSize(200, 200));
auto sizer = new wxBoxSizer(wxVERTICAL);
sizer->Add(text, 0, wxEXPAND);
sizer->Add(list, 1, wxEXPAND);
SetSizer(sizer);
sizer->SetSizeHints(this);
};
};
class A : public wxApp {
public: bool OnInit(void) {
(new M)->Show();
return true;
};
int FilterEvent(wxEvent &e) {
auto t = e.GetEventType();
if (t == wxEVT_CHAR) {
auto w = dynamic_cast<wxWindow *>(e.GetEventObject());
printf("CHAR for %d\n", w->GetId());
}
return Event_Skip;
};
};
IMPLEMENT_APP(A);
has focus. A TextCtrl gets CHAR events as usual. There is just a
single line in this TextCtrl, so WXK_UP/WXK_DOWN does not have much
of a meaning. In fact, GTK2 "abuses" it to jump to the next widget
like TAB normally would.
Anyhow, I would like to use WXK_UP/DOWN for moving around the
ListCtrl. It would seem that wxPostEvent and ProcessEvent are both
ignored. The code below is an example of that.
This may have to do with the fact that wxListMainWindow is separate
from wxListCtrl itself. If possible, I would rather avoid having to
copy what's in wxListMainWindow::OnChar.
#include <wx/wx.h>
#include <wx/listctrl.h>
#include <cstdio>
class M : public wxFrame {
public:
wxTextCtrl *text;
wxListCtrl *list;
public: M(void) : wxFrame(NULL, wxID_ANY, "") {
text = new wxTextCtrl(this, wxID_ANY);
text->Bind(wxEVT_CHAR, [this](wxKeyEvent &event) {
auto k = event.GetKeyCode();
if (list != NULL && (k == WXK_UP || k == WXK_DOWN)) {
wxKeyEvent copy = event;
copy.SetId(list->GetId());
copy.SetEventObject(list);
wxPostEvent(list, copy);
//list->GetEventHandler()->ProcessEvent(copy);
return;
}
event.Skip();
});
list = new wxListCtrl(this, wxID_ANY);
list->AppendColumn("head");
list->InsertItem(0, "first");
list->InsertItem(1, "second");
list->SetInitialSize(wxSize(200, 200));
auto sizer = new wxBoxSizer(wxVERTICAL);
sizer->Add(text, 0, wxEXPAND);
sizer->Add(list, 1, wxEXPAND);
SetSizer(sizer);
sizer->SetSizeHints(this);
};
};
class A : public wxApp {
public: bool OnInit(void) {
(new M)->Show();
return true;
};
int FilterEvent(wxEvent &e) {
auto t = e.GetEventType();
if (t == wxEVT_CHAR) {
auto w = dynamic_cast<wxWindow *>(e.GetEventObject());
printf("CHAR for %d\n", w->GetId());
}
return Event_Skip;
};
};
IMPLEMENT_APP(A);
--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.
To unsubscribe, send email to wx-users+***@googlegroups.com
or visit http://groups.google.com/group/wx-users
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.
To unsubscribe, send email to wx-users+***@googlegroups.com
or visit http://groups.google.com/group/wx-users