]>
git.saurik.com Git - wxWidgets.git/blob - src/common/event.cpp
963aa42d42b5c62c378d8c683f5a60236adcf01d
   1 ///////////////////////////////////////////////////////////////////////////// 
   3 // Purpose:     Event classes 
   4 // Author:      Julian Smart 
   8 // Copyright:   (c) Julian Smart and Markus Holzem 
   9 // Licence:     wxWindows licence 
  10 ///////////////////////////////////////////////////////////////////////////// 
  13 #pragma implementation "event.h" 
  16 // For compilers that support precompilation, includes "wx.h". 
  17 #include "wx/wxprec.h" 
  25 #include "wx/control.h" 
  32 #include "wx/validate.h" 
  34 #if !USE_SHARED_LIBRARY 
  35 IMPLEMENT_DYNAMIC_CLASS(wxEvtHandler
, wxObject
) 
  36 IMPLEMENT_ABSTRACT_CLASS(wxEvent
, wxObject
) 
  37 IMPLEMENT_DYNAMIC_CLASS(wxCommandEvent
, wxEvent
) 
  38 IMPLEMENT_DYNAMIC_CLASS(wxScrollEvent
, wxCommandEvent
) 
  39 IMPLEMENT_DYNAMIC_CLASS(wxMouseEvent
, wxEvent
) 
  40 IMPLEMENT_DYNAMIC_CLASS(wxKeyEvent
, wxEvent
) 
  41 IMPLEMENT_DYNAMIC_CLASS(wxSizeEvent
, wxEvent
) 
  42 IMPLEMENT_DYNAMIC_CLASS(wxPaintEvent
, wxEvent
) 
  43 IMPLEMENT_DYNAMIC_CLASS(wxEraseEvent
, wxEvent
) 
  44 IMPLEMENT_DYNAMIC_CLASS(wxMoveEvent
, wxEvent
) 
  45 IMPLEMENT_DYNAMIC_CLASS(wxFocusEvent
, wxEvent
) 
  46 IMPLEMENT_DYNAMIC_CLASS(wxCloseEvent
, wxEvent
) 
  47 IMPLEMENT_DYNAMIC_CLASS(wxShowEvent
, wxEvent
) 
  48 IMPLEMENT_DYNAMIC_CLASS(wxMaximizeEvent
, wxEvent
) 
  49 IMPLEMENT_DYNAMIC_CLASS(wxIconizeEvent
, wxEvent
) 
  50 IMPLEMENT_DYNAMIC_CLASS(wxMenuEvent
, wxEvent
) 
  51 IMPLEMENT_DYNAMIC_CLASS(wxJoystickEvent
, wxEvent
) 
  52 IMPLEMENT_DYNAMIC_CLASS(wxDropFilesEvent
, wxEvent
) 
  53 IMPLEMENT_DYNAMIC_CLASS(wxActivateEvent
, wxEvent
) 
  54 IMPLEMENT_DYNAMIC_CLASS(wxInitDialogEvent
, wxEvent
) 
  55 IMPLEMENT_DYNAMIC_CLASS(wxSysColourChangedEvent
, wxEvent
) 
  56 IMPLEMENT_DYNAMIC_CLASS(wxIdleEvent
, wxEvent
) 
  57 IMPLEMENT_DYNAMIC_CLASS(wxUpdateUIEvent
, wxEvent
) 
  59 const wxEventTable 
*wxEvtHandler::GetEventTable() const { return &wxEvtHandler::sm_eventTable
; } 
  61 const wxEventTable 
wxEvtHandler::sm_eventTable 
= 
  62         { NULL
, &wxEvtHandler::sm_eventTableEntries
[0] }; 
  64 const wxEventTableEntry 
wxEvtHandler::sm_eventTableEntries
[] = { { 0, 0, 0, NULL 
} }; 
  69  * General wxWindows events, covering 
  70  * all interesting things that might happen (button clicking, resizing, 
  71  * setting text in widgets, etc.). 
  73  * For each completely new event type, derive a new event class. 
  77 wxEvent::wxEvent(int theId
) 
  92 wxCommandEvent::wxCommandEvent(WXTYPE commandType
, int theId
) 
  94   m_eventType 
= commandType
; 
  99   m_commandString 
= NULL
; 
 106 wxScrollEvent::wxScrollEvent(WXTYPE commandType
, int id
, int pos
, int orient
): 
 107   wxCommandEvent(commandType
, id
) 
 109   m_extraLong 
= orient
; 
 119 wxMouseEvent::wxMouseEvent(WXTYPE commandType
) 
 121   m_eventType 
= commandType
; 
 124   m_controlDown 
= FALSE
; 
 128 // True if was a button dclick event (1 = left, 2 = middle, 3 = right) 
 129 // or any button dclick event (but = -1) 
 130 bool wxMouseEvent::ButtonDClick(int but
) const 
 134       return (LeftDClick() || MiddleDClick() || RightDClick()); 
 138       return MiddleDClick(); 
 140       return RightDClick(); 
 147 // True if was a button down event (1 = left, 2 = middle, 3 = right) 
 148 // or any button down event (but = -1) 
 149 bool wxMouseEvent::ButtonDown(int but
) const 
 153       return (LeftDown() || MiddleDown() || RightDown()); 
 166 // True if was a button up event (1 = left, 2 = middle, 3 = right) 
 167 // or any button up event (but = -1) 
 168 bool wxMouseEvent::ButtonUp(int but
) const 
 172       return (LeftUp() || MiddleUp() || RightUp()); 
 185 // True if the given button is currently changing state 
 186 bool wxMouseEvent::Button(int but
) const 
 190       return (ButtonUp(-1) || ButtonDown(-1) || ButtonDClick(-1)) ; 
 192       return (LeftDown() || LeftUp() || LeftDClick()); 
 194       return (MiddleDown() || MiddleUp() || MiddleDClick()); 
 196       return (RightDown() || RightUp() || RightDClick()); 
 203 bool wxMouseEvent::ButtonIsDown(int but
) const 
 207       return (LeftIsDown() || MiddleIsDown() || RightIsDown()); 
 211       return MiddleIsDown(); 
 213       return RightIsDown(); 
 220 // Find the logical position of the event given the DC 
 221 wxPoint 
wxMouseEvent::GetLogicalPosition(const wxDC
& dc
) const 
 223         wxPoint 
pt(dc
.DeviceToLogicalX(m_x
), dc
.DeviceToLogicalY(m_y
)); 
 233 wxKeyEvent::wxKeyEvent(WXTYPE type
) 
 237   m_controlDown 
= FALSE
; 
 247 wxEvtHandler::wxEvtHandler(void) 
 250   m_nextHandler 
= NULL
; 
 251   m_previousHandler 
= NULL
; 
 255 wxEvtHandler::~wxEvtHandler(void) 
 257   // Takes itself out of the list of handlers 
 258   if (m_previousHandler
) 
 259     m_previousHandler
->m_nextHandler 
= m_nextHandler
; 
 262     m_nextHandler
->m_previousHandler 
= m_previousHandler
; 
 269 bool wxEvtHandler::ProcessEvent(wxEvent
& event
) 
 271   // An event handler can be enabled or disabled 
 272   if ( GetEvtHandlerEnabled() ) 
 274     const wxEventTable 
*table 
= GetEventTable(); 
 276     // Try the associated validator first, if this is a window. 
 277     // Problem: if the event handler of the window has been replaced, 
 278     // this wxEvtHandler may no longer be a window. 
 279     // Therefore validators won't be processed if the handler 
 280     // has been replaced with SetEventHandler. 
 281     // THIS CAN BE CURED if PushEventHandler is used instead of 
 282     // SetEventHandler, and then processing will be passed down the 
 283     // chain of event handlers. 
 284     if (IsKindOf(CLASSINFO(wxWindow
))) 
 286           wxWindow 
*win 
= (wxWindow 
*)this; 
 288           // Can only use the validator of the window which 
 289           // is receiving the event 
 290           if ( (win 
== event
.GetEventObject()) && 
 291               win
->GetValidator() && 
 292                   win
->GetValidator()->ProcessEvent(event
)) 
 296     // Search upwards through the inheritance hierarchy 
 299       if (SearchEventTable((wxEventTable
&)*table
, event
)) 
 301       table 
= table
->baseTable
; 
 305   // Try going down the event handler chain 
 306   if ( GetNextHandler() ) 
 308             if ( GetNextHandler()->ProcessEvent(event
) ) 
 312   // Carry on up the parent-child hierarchy, 
 313   // but only if event is a command event: it wouldn't 
 314   // make sense for a parent to receive a child's size event, for example 
 315   if (IsKindOf(CLASSINFO(wxWindow
)) && event
.IsKindOf(CLASSINFO(wxCommandEvent
))) 
 317     wxWindow 
*win 
= (wxWindow 
*)this; 
 318         wxWindow 
*parent 
= win
->GetParent(); 
 319     if (parent 
&& !parent
->IsBeingDeleted()) 
 320       return win
->GetParent()->GetEventHandler()->ProcessEvent(event
); 
 323   // Last try - application object 
 324   if (wxTheApp 
&& this != wxTheApp 
&& wxTheApp
->ProcessEvent(event
)) 
 330 bool wxEvtHandler::SearchEventTable(wxEventTable
& table
, wxEvent
& event
) 
 333   int commandId 
= event
.GetId(); 
 335   while (table
.entries
[i
].m_fn 
!= NULL
) 
 337     if ((event
.GetEventType() == table
.entries
[i
].m_eventType
) && 
 338         (table
.entries
[i
].m_id 
== -1 || // Match, if event spec says any id will do (id == -1) 
 339           (table
.entries
[i
].m_lastId 
== -1 && commandId 
== table
.entries
[i
].m_id
) || 
 340           (table
.entries
[i
].m_lastId 
!= -1 && 
 341             (commandId 
>= table
.entries
[i
].m_id 
&& commandId 
<= table
.entries
[i
].m_lastId
)))) 
 345         (this->*((wxEventFunction
) (table
.entries
[i
].m_fn
)))(event
); 
 347                 if ( event
.GetSkipped() ) 
 357 #if WXWIN_COMPATIBILITY 
 358 void wxEvtHandler::OldOnMenuCommand(int cmd
) 
 360     if (GetNextHandler()) GetNextHandler()->OldOnMenuCommand(cmd
); 
 363 void wxEvtHandler::OldOnMenuSelect(int cmd
) 
 365     if (GetNextHandler()) GetNextHandler()->OldOnMenuSelect(cmd
); 
 368 void wxEvtHandler::OldOnInitMenuPopup(int pos
) 
 370     if (GetNextHandler()) GetNextHandler()->OldOnInitMenuPopup(pos
); 
 373 void wxEvtHandler::OldOnScroll(wxCommandEvent
& event
) 
 375     if (GetNextHandler()) GetNextHandler()->OldOnScroll(event
); 
 378 void wxEvtHandler::OldOnPaint(void) 
 380     if (GetNextHandler()) GetNextHandler()->OldOnPaint(); 
 382 void wxEvtHandler::OldOnSize(int width
, int height
) 
 384     if (GetNextHandler()) GetNextHandler()->OldOnSize(width
, height
); 
 387 void wxEvtHandler::OldOnMove(int x
, int y
) 
 389     if (GetNextHandler()) GetNextHandler()->OldOnMove(x
, y
); 
 392 void wxEvtHandler::OldOnMouseEvent(wxMouseEvent
& event
) 
 394     if (GetNextHandler()) GetNextHandler()->OldOnMouseEvent(event
); 
 397 void wxEvtHandler::OldOnChar(wxKeyEvent
& event
) 
 399     if (GetNextHandler()) GetNextHandler()->OldOnChar(event
); 
 402 // Under Windows, we can intercept character input per dialog or frame 
 403 bool wxEvtHandler::OldOnCharHook(wxKeyEvent
& event
) 
 405     if (GetNextHandler()) return GetNextHandler()->OldOnCharHook(event
); 
 409 void wxEvtHandler::OldOnActivate(bool active
) 
 411     if (GetNextHandler()) GetNextHandler()->OldOnActivate(active
); 
 414 void wxEvtHandler::OldOnSetFocus(void) 
 416     if (GetNextHandler()) GetNextHandler()->OldOnSetFocus(); 
 419 void wxEvtHandler::OldOnKillFocus(void) 
 421     if (GetNextHandler()) GetNextHandler()->OldOnKillFocus(); 
 424 bool wxEvtHandler::OldOnSysColourChange(void) 
 426     if (GetNextHandler()) return GetNextHandler()->OldOnSysColourChange(); 
 430 void wxEvtHandler::OldOnDropFiles(int n
, char *files
[], int x
, int y
) 
 432     if (GetNextHandler()) GetNextHandler()->OldOnDropFiles(n
, files
, x
, y
); 
 436 bool wxEvtHandler::OnClose(void) 
 438     if (GetNextHandler()) return GetNextHandler()->OnClose();