00001
00002
00003
00004
00005
00006
00007 #ifndef M_EVENTHANDLER_H
00008 #define M_EVENTHANDLER_H
00009
00010 namespace MWidgets
00011 {
00012
00013 class Widget;
00015 class BaseEventHandler
00016 {
00017 public:
00020 virtual void Call(Widget* sender);
00026 virtual void Call(Widget* sender,int x,int y,DWORD buttonMask);
00033 virtual void Call(Widget* sender,int left,int top,int right,int bottom);
00034 };
00035
00037 template<class T>
00038 class EventHandler:public BaseEventHandler
00039 {
00040 public:
00042 typedef void (T::*EventCallBack)(Widget* sender);
00043 protected:
00044 T *m_pParent;
00045 EventCallBack m_pCallBack;
00046 public:
00050 EventHandler(T *parent,EventCallBack callback)
00051 {
00052 m_pParent=parent;
00053 m_pCallBack=callback;
00054 };
00057 void Call(Widget* sender)
00058 {
00059 (m_pParent->*m_pCallBack)(sender);
00060 };
00061 };
00063 template<class T>
00064 class MouseEventHandler:public BaseEventHandler
00065 {
00066 public:
00068 typedef void (T::*MouseEventCallBack)(Widget* sender,int x,int y,DWORD buttonMask);
00069
00070 protected:
00071 T *m_pParent;
00072 MouseEventCallBack m_pCallBack;
00073 public:
00077 MouseEventHandler(T *parent,MouseEventCallBack callback)
00078 {
00079 m_pParent=parent;
00080 m_pCallBack=callback;
00081 };
00087 void Call(Widget* sender,int x,int y,DWORD buttonMask)
00088 {
00089 (m_pParent->*m_pCallBack)(sender,x,y,buttonMask);
00090 };
00091 };
00092
00094 template<class T>
00095 class WindowSizeEventHandler:public BaseEventHandler
00096 {
00097 public:
00099 typedef void (T::*WindowSizeEventCallBack)(Widget* sender,int left,int top,int right,int bottom);
00100
00101 protected:
00102 T *m_pParent;
00103 WindowSizeEventCallBack m_pCallBack;
00104 public:
00108 WindowSizeEventHandler(T *parent,WindowSizeEventCallBack callback)
00109 {
00110 m_pParent=parent;
00111 m_pCallBack=callback;
00112 };
00119 void Call(Widget* sender,int left,int top,int right, int bottom)
00120 {
00121 (m_pParent->*m_pCallBack)(sender,left, top, right, bottom);
00122 };
00123 };
00124 };
00125
00126 #endif