00001
00002
00003
00004
00005
00006
00007 #ifndef M_WIDGET_H
00008 #define M_WIDGET_H
00009
00010 namespace MWidgets
00011 {
00013 enum WIDGET_TYPE
00014 {
00015 WINDOW,
00016 DOCKWINDOW,
00017 DIALOG,
00018 GROUPBOX,
00019 LABEL,
00020 TEXTBOX,
00021 BUTTON,
00022 CHECKBOX,
00023 RADIOBUTTON,
00024 COMBOBOX,
00025 STATUSBAR,
00026 GRID
00027 };
00028 class ContextMenu;
00030 class Widget
00031 {
00032 protected:
00033 HWND m_hWnd;
00034 HINSTANCE m_hInstance;
00035 WNDPROC m_prevWndProc;
00036 HMENU m_hContextMenu;
00037 std::map<std::string,UINT> m_mapHotKeyIds;
00038 std::map<UINT,BaseEventHandler*> m_mapHotKeyHendles;
00039
00040 protected:
00042 BaseEventHandler *m_pOnCreateHandler;
00044 BaseEventHandler *m_pOnLButtonDownHandler;
00046 BaseEventHandler *m_pOnRButtonDownHandler;
00048 BaseEventHandler *m_pOnSizeHandler;
00049 protected:
00050 friend class ContextMenu;
00053 virtual LRESULT OnMessage (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
00056 virtual void OnCommand( WORD code,WORD id);
00059 static Widget *GetObjectFromHwnd(HWND hWnd);
00063 static BOOL CALLBACK DestroyChildProc(HWND hwnd,LPARAM lParam);
00064
00067 void ProcessMenu(WORD id);
00070 void ProcessAccelerators(WORD id);
00073 void ProcessHotKey(WORD id);
00074 public:
00076 static LRESULT CALLBACK WindowProcedure (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
00078 Widget();
00084 void Create(int x,int y,int w,int h,string caption,string classname,DWORD styles,HWND parent,DWORD stylesex=0);
00086 virtual ~Widget();
00088 HWND GetHwnd();
00090 HINSTANCE GetHinstance();
00092 void Show();
00094 void Hide();
00097 void SetText(string text);
00099 string GetText();
00101 void DestroyChildWindows();
00104 void SetMenuBar(Menu* pMenu);
00106 void RemoveMenuBar();
00110 template<class T>
00111 void SetOnCreateHandler(T *pProcessor,void (T::*EventCallBack)(Widget* sender))
00112 {
00113 if(m_pOnCreateHandler!=NULL)
00114 delete m_pOnCreateHandler;
00115 m_pOnCreateHandler=new EventHandler<T>(pProcessor,EventCallBack);
00116 };
00118 virtual void OnCreate();
00122 template<class T>
00123 void SetLeftButtonDownHandler(T *pProcessor,void (T::*EventCallBack)(Widget* sender,int x,int y,DWORD buttonMask))
00124 {
00125 if(m_pOnLButtonDownHandler!=NULL)
00126 delete m_pOnLButtonDownHandler;
00127 m_pOnLButtonDownHandler=new MouseEventHandler<T>(pProcessor,EventCallBack);
00128 };
00132 virtual void OnLeftButtonDown(int x,int y,DWORD buttonMask);
00136 template<class T>
00137 void SetRightButtonDownHandler(T *pProcessor,void (T::*EventCallBack)(Widget* sender,int x,int y,DWORD buttonMask))
00138 {
00139 if(m_pOnRButtonDownHandler!=NULL)
00140 delete m_pOnRButtonDownHandler;
00141 m_pOnRButtonDownHandler=new MouseEventHandler<T>(pProcessor,EventCallBack);
00142 };
00146 virtual void OnRightButtonDown(int x,int y,DWORD buttonMask);
00150 template<class T>
00151 void SetOnSizeHandler(T *pProcessor,void (T::*EventCallBack)(Widget* sender))
00152 {
00153 if(m_pOnSizeHandler!=NULL)
00154 delete m_pOnSizeHandler;
00155 m_pOnSizeHandler=new WindowSizeEventHandler<T>(pProcessor,EventCallBack);
00156 };
00162 virtual void OnSize(int left,int top,int right,int bottom);
00165 void Enable(BOOL bEnable);
00167 bool IsDestroyed();
00169 void Destroy();
00174 void SetHotKey(UINT fsModifiers,UINT vk,BaseEventHandler* pEventHandler);
00180 template<class T>
00181 void SetHotKey(UINT fsModifiers,UINT vk,T *pProcessor,void (T::*EventCallBack)(Widget* sender))
00182 {
00183 BaseEventHandler *pEventHandler=new EventHandler<T>(pProcessor,EventCallBack);
00184 SetHotKey(fsModifiers, vk,pEventHandler);
00185 };
00187 virtual WIDGET_TYPE GetType()=0;
00189 HWND GetParent();
00193 void Move(int x,int y);
00197 void Size(int w,int h);
00198 };
00199 };
00200
00201 #endif