widget/windows/WindowHook.h

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:1b08d2153091
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 *
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7 #ifndef __mozilla_WindowHook_h__
8 #define __mozilla_WindowHook_h__
9
10 #include <windows.h>
11
12 #include <nsHashKeys.h>
13 #include <nsClassHashtable.h>
14 #include <nsTArray.h>
15
16 #include "nsAppShell.h"
17
18 class nsWindow;
19
20 namespace mozilla {
21 namespace widget {
22
23 struct MSGResult;
24
25 class WindowHook {
26 public:
27
28 // It is expected that most callbacks will return false
29 typedef bool (*Callback)(void *aContext, HWND hWnd, UINT nMsg,
30 WPARAM wParam, LPARAM lParam, LRESULT *aResult);
31
32 nsresult AddHook(UINT nMsg, Callback callback, void *context);
33 nsresult RemoveHook(UINT nMsg, Callback callback, void *context);
34 nsresult AddMonitor(UINT nMsg, Callback callback, void *context);
35 nsresult RemoveMonitor(UINT nMsg, Callback callback, void *context);
36
37 private:
38 struct CallbackData {
39 Callback cb;
40 void *context;
41
42 CallbackData() : cb(nullptr), context(nullptr) {}
43 CallbackData(Callback cb, void *ctx) : cb(cb), context(ctx) {}
44 bool Invoke(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam,
45 LRESULT *aResult);
46 bool operator== (const CallbackData &rhs) const {
47 return cb == rhs.cb && context == rhs.context;
48 }
49 bool operator!= (const CallbackData &rhs) const {
50 return !(*this == rhs);
51 }
52 operator bool () const {
53 return !!cb;
54 }
55 };
56
57 typedef nsTArray<CallbackData> CallbackDataArray;
58 struct MessageData {
59 UINT nMsg;
60 CallbackData hook;
61 CallbackDataArray monitors;
62 };
63
64 bool Notify(HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam,
65 MSGResult& aResult);
66
67 MessageData *Lookup(UINT nMsg);
68 MessageData *LookupOrCreate(UINT nMsg);
69 void DeleteIfEmpty(MessageData *data);
70
71 typedef nsTArray<MessageData> MessageDataArray;
72 MessageDataArray mMessageData;
73
74 // For Notify
75 friend class ::nsWindow;
76 };
77
78 }
79 }
80
81 #endif // __mozilla_WindowHook_h__

mercurial