|
1
|
1 #pragma once
|
|
|
2
|
|
|
3 #ifdef _WIN32
|
|
|
4 //! A message filter class. Allows you to filter incoming messages in main app loop. Use message_loop API to register/unregister, \n
|
|
|
5 //! or derive from message_filter_impl_base to have your class registered/deregistered automatically with lifetime.
|
|
|
6 //! //! Use with caution. Will not be executed during modal loops.
|
|
|
7 class NOVTABLE message_filter {
|
|
|
8 public:
|
|
|
9 //! Notifies you about incoming message. \n
|
|
|
10 //! You can alter the message (not generally recommended), let others handle it (return false) \n
|
|
|
11 //! or signal that you've handled it (return true) to suppress further processing.
|
|
|
12 virtual bool pretranslate_message(MSG * p_msg) = 0;
|
|
|
13 };
|
|
|
14
|
|
|
15 //! An idle handler class. Executed when main loop is about to enter idle state. \n
|
|
|
16 //! Use with caution. Will not be executed during modal loops.
|
|
|
17 class NOVTABLE idle_handler {
|
|
|
18 public:
|
|
|
19 virtual bool on_idle() = 0;
|
|
|
20 };
|
|
|
21
|
|
|
22 //! Entrypoint API for registering message_filter and idle_handler objects. \n
|
|
|
23 //! Usage: message_loop::get()->add_message_filter(myfilter);
|
|
|
24 class NOVTABLE message_loop : public service_base
|
|
|
25 {
|
|
|
26 public:
|
|
|
27 virtual void add_message_filter(message_filter * ptr) = 0;
|
|
|
28 virtual void remove_message_filter(message_filter * ptr) = 0;
|
|
|
29
|
|
|
30 virtual void add_idle_handler(idle_handler * ptr) = 0;
|
|
|
31 virtual void remove_idle_handler(idle_handler * ptr) = 0;
|
|
|
32
|
|
|
33 FB2K_MAKE_SERVICE_COREAPI(message_loop);
|
|
|
34 };
|
|
|
35
|
|
|
36 class NOVTABLE message_loop_v2 : public message_loop {
|
|
|
37 public:
|
|
|
38 virtual void add_message_filter_ex(message_filter * ptr, t_uint32 lowest, t_uint32 highest) = 0;
|
|
|
39
|
|
|
40 FB2K_MAKE_SERVICE_COREAPI_EXTENSION(message_loop_v2, message_loop);
|
|
|
41 };
|
|
|
42
|
|
|
43 class message_filter_impl_base : public message_filter {
|
|
|
44 public:
|
|
|
45 message_filter_impl_base();
|
|
|
46 message_filter_impl_base(t_uint32 lowest, t_uint32 highest);
|
|
|
47 ~message_filter_impl_base();
|
|
|
48
|
|
|
49 bool pretranslate_message(MSG * ) override {return false;}
|
|
|
50
|
|
|
51 PFC_CLASS_NOT_COPYABLE(message_filter_impl_base,message_filter_impl_base);
|
|
|
52 };
|
|
|
53
|
|
|
54 class message_filter_impl_accel : public message_filter_impl_base {
|
|
|
55 protected:
|
|
|
56 bool pretranslate_message(MSG * p_msg) override;
|
|
|
57 public:
|
|
|
58 message_filter_impl_accel(HINSTANCE p_instance,const TCHAR * p_accel);
|
|
|
59 void set_wnd(HWND p_wnd) {m_wnd = p_wnd;}
|
|
|
60 private:
|
|
|
61 HWND m_wnd = NULL;
|
|
|
62 win32_accelerator m_accel;
|
|
|
63
|
|
|
64 PFC_CLASS_NOT_COPYABLE(message_filter_impl_accel,message_filter_impl_accel);
|
|
|
65 };
|
|
|
66
|
|
|
67 class message_filter_remap_f1 : public message_filter_impl_base {
|
|
|
68 public:
|
|
|
69 bool pretranslate_message(MSG * p_msg) override;
|
|
|
70 void set_wnd(HWND wnd) {m_wnd = wnd;}
|
|
|
71 private:
|
|
|
72 static bool IsOurMsg(const MSG * msg) {
|
|
|
73 return msg->message == WM_KEYDOWN && msg->wParam == VK_F1;
|
|
|
74 }
|
|
|
75 HWND m_wnd = NULL;
|
|
|
76 };
|
|
|
77
|
|
|
78 class idle_handler_impl_base : public idle_handler {
|
|
|
79 public:
|
|
|
80 idle_handler_impl_base() {message_loop::get()->add_idle_handler(this);}
|
|
|
81 ~idle_handler_impl_base() { message_loop::get()->remove_idle_handler(this);}
|
|
|
82 bool on_idle() {return true;}
|
|
|
83
|
|
|
84 PFC_CLASS_NOT_COPYABLE_EX(idle_handler_impl_base)
|
|
|
85 };
|
|
|
86 #endif // _WIN32
|