michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- michael@0: * michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef __mozilla_WindowHook_h__ michael@0: #define __mozilla_WindowHook_h__ michael@0: michael@0: #include michael@0: michael@0: #include michael@0: #include michael@0: #include michael@0: michael@0: #include "nsAppShell.h" michael@0: michael@0: class nsWindow; michael@0: michael@0: namespace mozilla { michael@0: namespace widget { michael@0: michael@0: struct MSGResult; michael@0: michael@0: class WindowHook { michael@0: public: michael@0: michael@0: // It is expected that most callbacks will return false michael@0: typedef bool (*Callback)(void *aContext, HWND hWnd, UINT nMsg, michael@0: WPARAM wParam, LPARAM lParam, LRESULT *aResult); michael@0: michael@0: nsresult AddHook(UINT nMsg, Callback callback, void *context); michael@0: nsresult RemoveHook(UINT nMsg, Callback callback, void *context); michael@0: nsresult AddMonitor(UINT nMsg, Callback callback, void *context); michael@0: nsresult RemoveMonitor(UINT nMsg, Callback callback, void *context); michael@0: michael@0: private: michael@0: struct CallbackData { michael@0: Callback cb; michael@0: void *context; michael@0: michael@0: CallbackData() : cb(nullptr), context(nullptr) {} michael@0: CallbackData(Callback cb, void *ctx) : cb(cb), context(ctx) {} michael@0: bool Invoke(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, michael@0: LRESULT *aResult); michael@0: bool operator== (const CallbackData &rhs) const { michael@0: return cb == rhs.cb && context == rhs.context; michael@0: } michael@0: bool operator!= (const CallbackData &rhs) const { michael@0: return !(*this == rhs); michael@0: } michael@0: operator bool () const { michael@0: return !!cb; michael@0: } michael@0: }; michael@0: michael@0: typedef nsTArray CallbackDataArray; michael@0: struct MessageData { michael@0: UINT nMsg; michael@0: CallbackData hook; michael@0: CallbackDataArray monitors; michael@0: }; michael@0: michael@0: bool Notify(HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam, michael@0: MSGResult& aResult); michael@0: michael@0: MessageData *Lookup(UINT nMsg); michael@0: MessageData *LookupOrCreate(UINT nMsg); michael@0: void DeleteIfEmpty(MessageData *data); michael@0: michael@0: typedef nsTArray MessageDataArray; michael@0: MessageDataArray mMessageData; michael@0: michael@0: // For Notify michael@0: friend class ::nsWindow; michael@0: }; michael@0: michael@0: } michael@0: } michael@0: michael@0: #endif // __mozilla_WindowHook_h__