Hi,
i have a big problem. I wrote my own control. It was derived from wxControl and it was initialized through wxControl::Create method.
It works great, but Windows never sets focus to this compoment. When the control is derived from wxListCtrl windows sets focus normally.
Do somebody known the solution?
Creating own control - focus issue
-
- In need of some credit
- Posts: 7
- Joined: Wed May 14, 2008 11:12 am
- Location: Czech Republic, Prag
- Contact:
This is my source example. CalendarCtrl is derived from wxPanel.
[/code]
Code: Select all
bool CalendarCtrl::Create(wxWindow *parent,
wxWindowID id,
const wxPoint& pos)
{
return wxPanel::Create(parent, id, pos,wxDefaultSize,wxBORDER_NONE|wxWANTS_CHARS);
}
void CalendarCtrl::onKeyPress(wxKeyEvent & event) {
int code = event.GetKeyCode();
if((code == WXK_EXECUTE || code == WXK_SPACE || code == WXK_RETURN)&&(movedCol != -1 && movedRow != -1)) {
if (date) {
findDate(movedRow, movedCol, date);
}
else {
date = new wxDateTime();
findDate(movedRow, movedCol, date);
}
selectPosition();
}else if (code == WXK_TAB){
Navigate((event.ShiftDown()?(wxNavigationKeyEvent::IsBackward):(wxNavigationKeyEvent::IsForward)));
} else ...
Hi jhruby,
for TAB key handling try this
How do you know that your control has no focus, you have to draw this state yourself in your OnPaint handler.
Regards,
Frank
for TAB key handling try this
Code: Select all
switch(event.GetKeyCode())
{
case WXK_TAB:
{
wxNavigationKeyEvent evt;
int dir = event.ShiftDown()?0:1;
evt.SetFlags(wxNavigationKeyEvent::FromTab|
(dir?wxNavigationKeyEvent::IsForward:
wxNavigationKeyEvent::IsBackward));
evt.SetEventObject(this);
GetParent()->GetEventHandler()->AddPendingEvent(evt);
}
break;
}
Code: Select all
if(FindFocus() == this)
DrawFocusRect(dc);
Frank