|
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
|
2 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
3 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
5 |
|
6 #ifndef nsToolkit_h__ |
|
7 #define nsToolkit_h__ |
|
8 |
|
9 #include "nsdefs.h" |
|
10 |
|
11 #include "nsITimer.h" |
|
12 #include "nsCOMPtr.h" |
|
13 #include <windows.h> |
|
14 |
|
15 // Avoid including windowsx.h to prevent macro pollution |
|
16 #ifndef GET_X_LPARAM |
|
17 #define GET_X_LPARAM(pt) (short(LOWORD(pt))) |
|
18 #endif |
|
19 #ifndef GET_Y_LPARAM |
|
20 #define GET_Y_LPARAM(pt) (short(HIWORD(pt))) |
|
21 #endif |
|
22 |
|
23 /** |
|
24 * Makes sure exit/enter mouse messages are always dispatched. |
|
25 * In the case where the mouse has exited the outer most window the |
|
26 * only way to tell if it has exited is to set a timer and look at the |
|
27 * mouse pointer to see if it is within the outer most window. |
|
28 */ |
|
29 |
|
30 class MouseTrailer |
|
31 { |
|
32 public: |
|
33 HWND GetMouseTrailerWindow() { return mMouseTrailerWindow; } |
|
34 HWND GetCaptureWindow() { return mCaptureWindow; } |
|
35 |
|
36 void SetMouseTrailerWindow(HWND aWnd); |
|
37 void SetCaptureWindow(HWND aWnd); |
|
38 void Disable() { mEnabled = false; DestroyTimer(); } |
|
39 void Enable() { mEnabled = true; CreateTimer(); } |
|
40 void DestroyTimer(); |
|
41 |
|
42 MouseTrailer(); |
|
43 ~MouseTrailer(); |
|
44 private: |
|
45 |
|
46 nsresult CreateTimer(); |
|
47 |
|
48 static void TimerProc(nsITimer* aTimer, void* aClosure); |
|
49 |
|
50 // Information for mouse enter/exit events |
|
51 HWND mMouseTrailerWindow; |
|
52 HWND mCaptureWindow; |
|
53 bool mIsInCaptureMode; |
|
54 bool mEnabled; |
|
55 nsCOMPtr<nsITimer> mTimer; |
|
56 }; |
|
57 |
|
58 /** |
|
59 * Wrapper around the thread running the message pump. |
|
60 * The toolkit abstraction is necessary because the message pump must |
|
61 * execute within the same thread that created the widget under Win32. |
|
62 */ |
|
63 |
|
64 class nsToolkit |
|
65 { |
|
66 public: |
|
67 nsToolkit(); |
|
68 |
|
69 private: |
|
70 ~nsToolkit(); |
|
71 |
|
72 public: |
|
73 static nsToolkit* GetToolkit(); |
|
74 |
|
75 static HINSTANCE mDllInstance; |
|
76 static MouseTrailer *gMouseTrailer; |
|
77 |
|
78 static void Startup(HMODULE hModule); |
|
79 static void Shutdown(); |
|
80 static void StartAllowingD3D9(); |
|
81 |
|
82 protected: |
|
83 static nsToolkit* gToolkit; |
|
84 |
|
85 nsCOMPtr<nsITimer> mD3D9Timer; |
|
86 MouseTrailer mMouseTrailer; |
|
87 }; |
|
88 |
|
89 #endif // TOOLKIT_H |