michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 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 nsToolkit_h__ michael@0: #define nsToolkit_h__ michael@0: michael@0: #include "nsdefs.h" michael@0: michael@0: #include "nsITimer.h" michael@0: #include "nsCOMPtr.h" michael@0: #include michael@0: michael@0: // Avoid including windowsx.h to prevent macro pollution michael@0: #ifndef GET_X_LPARAM michael@0: #define GET_X_LPARAM(pt) (short(LOWORD(pt))) michael@0: #endif michael@0: #ifndef GET_Y_LPARAM michael@0: #define GET_Y_LPARAM(pt) (short(HIWORD(pt))) michael@0: #endif michael@0: michael@0: /** michael@0: * Makes sure exit/enter mouse messages are always dispatched. michael@0: * In the case where the mouse has exited the outer most window the michael@0: * only way to tell if it has exited is to set a timer and look at the michael@0: * mouse pointer to see if it is within the outer most window. michael@0: */ michael@0: michael@0: class MouseTrailer michael@0: { michael@0: public: michael@0: HWND GetMouseTrailerWindow() { return mMouseTrailerWindow; } michael@0: HWND GetCaptureWindow() { return mCaptureWindow; } michael@0: michael@0: void SetMouseTrailerWindow(HWND aWnd); michael@0: void SetCaptureWindow(HWND aWnd); michael@0: void Disable() { mEnabled = false; DestroyTimer(); } michael@0: void Enable() { mEnabled = true; CreateTimer(); } michael@0: void DestroyTimer(); michael@0: michael@0: MouseTrailer(); michael@0: ~MouseTrailer(); michael@0: private: michael@0: michael@0: nsresult CreateTimer(); michael@0: michael@0: static void TimerProc(nsITimer* aTimer, void* aClosure); michael@0: michael@0: // Information for mouse enter/exit events michael@0: HWND mMouseTrailerWindow; michael@0: HWND mCaptureWindow; michael@0: bool mIsInCaptureMode; michael@0: bool mEnabled; michael@0: nsCOMPtr mTimer; michael@0: }; michael@0: michael@0: /** michael@0: * Wrapper around the thread running the message pump. michael@0: * The toolkit abstraction is necessary because the message pump must michael@0: * execute within the same thread that created the widget under Win32. michael@0: */ michael@0: michael@0: class nsToolkit michael@0: { michael@0: public: michael@0: nsToolkit(); michael@0: michael@0: private: michael@0: ~nsToolkit(); michael@0: michael@0: public: michael@0: static nsToolkit* GetToolkit(); michael@0: michael@0: static HINSTANCE mDllInstance; michael@0: static MouseTrailer *gMouseTrailer; michael@0: michael@0: static void Startup(HMODULE hModule); michael@0: static void Shutdown(); michael@0: static void StartAllowingD3D9(); michael@0: michael@0: protected: michael@0: static nsToolkit* gToolkit; michael@0: michael@0: nsCOMPtr mD3D9Timer; michael@0: MouseTrailer mMouseTrailer; michael@0: }; michael@0: michael@0: #endif // TOOLKIT_H