1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 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/. */
7 #ifndef __mozilla_WindowHook_h__
8 #define __mozilla_WindowHook_h__
12 #include <nsHashKeys.h>
13 #include <nsClassHashtable.h>
16 #include "nsAppShell.h"
27 // It is expected that most callbacks will return false
28 typedef bool (*Callback
)(void* aContext
, HWND hWnd
, UINT nMsg
, WPARAM wParam
,
29 LPARAM lParam
, LRESULT
* aResult
);
31 nsresult
AddHook(UINT nMsg
, Callback callback
, void* context
);
32 nsresult
RemoveHook(UINT nMsg
, Callback callback
, void* context
);
33 nsresult
AddMonitor(UINT nMsg
, Callback callback
, void* context
);
34 nsresult
RemoveMonitor(UINT nMsg
, Callback callback
, void* context
);
41 CallbackData() : cb(nullptr), context(nullptr) {}
42 CallbackData(Callback cb
, void* ctx
) : cb(cb
), context(ctx
) {}
43 bool Invoke(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
,
45 bool operator==(const CallbackData
& rhs
) const {
46 return cb
== rhs
.cb
&& context
== rhs
.context
;
48 bool operator!=(const CallbackData
& rhs
) const { return !(*this == rhs
); }
49 explicit operator bool() const { return !!cb
; }
52 typedef nsTArray
<CallbackData
> CallbackDataArray
;
56 CallbackDataArray monitors
;
59 bool Notify(HWND hWnd
, UINT nMsg
, WPARAM wParam
, LPARAM lParam
,
62 MessageData
* Lookup(UINT nMsg
);
63 MessageData
* LookupOrCreate(UINT nMsg
);
64 void DeleteIfEmpty(MessageData
* data
);
66 typedef nsTArray
<MessageData
> MessageDataArray
;
67 MessageDataArray mMessageData
;
70 friend class ::nsWindow
;
74 } // namespace mozilla
76 #endif // __mozilla_WindowHook_h__