00001
00009 #ifndef INCLUDE_TANUKI_WND_H__
00010 #define INCLUDE_TANUKI_WND_H__
00011
00012
00013 #include <WINDOWS.H>
00014 #include <WINDOWSX.H>
00015 #include <TCHAR.H>
00016 #include <CRTDBG.H>
00017
00018
00019
00020 #ifdef TANUKI_USED_DLL_EXPORT
00021 #define TANUKI_API __declspec( dllexport )
00022 #else //TANUKI_USED_DLL_EXPORT
00023 #define TANUKI_API
00024 #endif //TANUKI_USED_DLL_EXPORT
00025
00026
00027 namespace tanuki {
00028
00029
00030 #ifndef INCLUDE_TANUKI_EXCEPTION_BASE_CL__
00031 #define INCLUDE_TANUKI_EXCEPTION_BASE_CL__
00032
00038 class TANUKI_API exc_base {
00039
00040
00041
00042 protected:
00044 exc_base(LPCTSTR msg) : m_msg(msg) {}
00046 virtual ~exc_base() {}
00047
00048
00049
00050
00051 public:
00053 LPCTSTR What() const { return m_msg; }
00054
00055
00056
00057
00058 private:
00059
00060 LPCTSTR m_msg;
00061 };
00062
00063 #endif //INCLUDE_TANUKI_EXCEPTION_BASE_CL__
00064
00065
00070 class TANUKI_API exc_window : public exc_base {
00071
00072
00073
00074 public:
00078 exc_window(LPCTSTR msg) : exc_base(msg) {}
00080 virtual ~exc_window() {}
00081 };
00082
00083
00093 class TANUKI_API cl_wnd_base {
00094
00095
00096
00097 protected:
00099 cl_wnd_base();
00101 virtual ~cl_wnd_base() = 0;
00102 private:
00103
00104 cl_wnd_base(const cl_wnd_base &);
00105 cl_wnd_base & operator =(const cl_wnd_base &);
00106
00107
00108
00109
00110 protected:
00112 HWND m_hWnd;
00113 };
00114
00115
00125 class TANUKI_API cl_process_wnd : public cl_wnd_base {
00126
00127
00128
00129 protected:
00144 typedef BOOL (* wm_handler_t) (cl_process_wnd * p_myself, WPARAM wprm,
00145 LPARAM lprm, LRESULT & result);
00155 typedef void (* cmd_handler_t) (cl_process_wnd * p_myself);
00156
00157
00158
00159
00160 protected:
00165 struct sh_wm_hash {
00167 UINT key;
00169 wm_handler_t handler;
00170 };
00175 struct sh_cmd_hash {
00177 WORD key;
00179 cmd_handler_t handler;
00180 };
00181
00182
00183
00184
00185 protected:
00186 enum {
00188 WMSG_HASH_TABLE_SIZE = 1021,
00190 CMD_HASH_TABLE_SIZE = 127,
00191 };
00192
00193
00194
00195
00196 protected:
00204 cl_process_wnd();
00206 virtual ~cl_process_wnd();
00207 private:
00208
00209 cl_process_wnd(const cl_process_wnd &);
00210 cl_process_wnd & operator =(const cl_process_wnd &);
00211
00212
00213
00214
00215 public:
00229 void EnableReplyPaint(bool is_reply = true)
00230 { m_is_reply_wm_paint = is_reply; }
00231 protected:
00243 void registerWndMessageHandler(UINT msg_id, wm_handler_t handler);
00282 bool registerCommandHandler(WORD cmd_id, cmd_handler_t handler);
00301 BOOL callWndMessageHandler(UINT msg_id,
00302 WPARAM wprm,
00303 LPARAM lprm,
00304 LRESULT & result);
00319 BOOL callCommandHandler(WORD cmd_id);
00320
00321
00322
00323
00324 private:
00325
00326 static BOOL on_wm_create(cl_process_wnd * p_myself,
00327 WPARAM,
00328 LPARAM lprm,
00329 LRESULT & result)
00330 {
00331 _ASSERT(p_myself); _ASSERT(::IsWindow(p_myself->m_hWnd));
00332 return p_myself->onCreate((LPCREATESTRUCT) lprm, result);
00333 }
00334
00335 static BOOL on_wm_destroy(cl_process_wnd * p_myself,
00336 WPARAM,
00337 LPARAM,
00338 LRESULT &)
00339 {
00340 _ASSERT(p_myself); _ASSERT(::IsWindow(p_myself->m_hWnd));
00341 ::PostQuitMessage(p_myself->onDestroy());
00342 return TRUE;
00343 }
00344
00345 static BOOL on_wm_mousemove(cl_process_wnd * p_myself,
00346 WPARAM wprm,
00347 LPARAM lprm,
00348 LRESULT &)
00349 {
00350 _ASSERT(p_myself); _ASSERT(::IsWindow(p_myself->m_hWnd));
00351 POINT pos = {
00352 GET_X_LPARAM(lprm),
00353 GET_Y_LPARAM(lprm)
00354 };
00355 return p_myself->onMouseMove(pos, wprm);
00356 }
00357
00358 static BOOL on_wm_lbuttondown(cl_process_wnd * p_myself,
00359 WPARAM wprm,
00360 LPARAM lprm,
00361 LRESULT &)
00362 {
00363 _ASSERT(p_myself); _ASSERT(::IsWindow(p_myself->m_hWnd));
00364 POINT pos = {
00365 GET_X_LPARAM(lprm),
00366 GET_Y_LPARAM(lprm)
00367 };
00368 return p_myself->onMouseLeftButtonDown(pos, wprm);
00369 }
00370
00371 static BOOL on_wm_lbuttonup(cl_process_wnd * p_myself,
00372 WPARAM wprm,
00373 LPARAM lprm,
00374 LRESULT &)
00375 {
00376 _ASSERT(p_myself); _ASSERT(::IsWindow(p_myself->m_hWnd));
00377 POINT pos = {
00378 GET_X_LPARAM(lprm),
00379 GET_Y_LPARAM(lprm)
00380 };
00381 return p_myself->onMouseLeftButtonUp(pos, wprm);
00382 }
00383
00384 static BOOL on_wm_paint(cl_process_wnd * p_myself,
00385 WPARAM,
00386 LPARAM,
00387 LRESULT &)
00388 {
00389 _ASSERT(p_myself); _ASSERT(::IsWindow(p_myself->m_hWnd));
00390
00391 if (!p_myself->m_is_reply_wm_paint)
00392 return FALSE;
00393
00394 PAINTSTRUCT paint_st;
00395 HDC h_dc = ::BeginPaint(p_myself->m_hWnd, &paint_st);
00396
00397 if (!h_dc){
00398 _ASSERT(0);
00399 return FALSE;
00400 }
00401
00402 p_myself->onPaint(h_dc, paint_st.fErase, paint_st.rcPaint);
00403
00404 (void) ::EndPaint(p_myself->m_hWnd, &paint_st);
00405 return TRUE;
00406 }
00407 protected:
00426 virtual BOOL onCreate(LPCREATESTRUCT p_create_st, LRESULT & result)
00427 { _ASSERT(result == 0); return FALSE; }
00434 virtual int onDestroy() { return 0; }
00456 virtual BOOL onMouseMove(const POINT & pos, DWORD key_indicator)
00457 { return FALSE; }
00470 virtual BOOL onMouseLeftButtonDown(const POINT & pos,
00471 DWORD key_indicator)
00472 { return FALSE; }
00485 virtual BOOL onMouseLeftButtonUp(const POINT & pos,
00486 DWORD key_indicator)
00487 { return FALSE; }
00503 virtual void onPaint(HDC h_dc, BOOL is_erase, const RECT & rect)
00504 { return; }
00505
00506
00507
00508
00509 protected:
00510
00511
00512
00513
00514 private:
00515
00516 sh_wm_hash m_wm_hash_table[WMSG_HASH_TABLE_SIZE];
00517
00518 sh_cmd_hash m_cmd_hash_table[CMD_HASH_TABLE_SIZE];
00519
00520 bool m_is_reply_wm_paint;
00521 };
00522
00523
00524 }
00525
00526
00527 #endif //INCLUDE_TANUKI_WND_H__
00528
00529
00530