widget/windows/nsToolkit.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/widget/windows/nsToolkit.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,89 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#ifndef nsToolkit_h__
    1.10 +#define nsToolkit_h__
    1.11 +
    1.12 +#include "nsdefs.h"
    1.13 +
    1.14 +#include "nsITimer.h"
    1.15 +#include "nsCOMPtr.h"
    1.16 +#include <windows.h>
    1.17 +
    1.18 +// Avoid including windowsx.h to prevent macro pollution
    1.19 +#ifndef GET_X_LPARAM
    1.20 +#define GET_X_LPARAM(pt) (short(LOWORD(pt)))
    1.21 +#endif
    1.22 +#ifndef GET_Y_LPARAM
    1.23 +#define GET_Y_LPARAM(pt) (short(HIWORD(pt)))
    1.24 +#endif
    1.25 +
    1.26 +/**
    1.27 + * Makes sure exit/enter mouse messages are always dispatched.
    1.28 + * In the case where the mouse has exited the outer most window the
    1.29 + * only way to tell if it has exited is to set a timer and look at the
    1.30 + * mouse pointer to see if it is within the outer most window.
    1.31 + */ 
    1.32 +
    1.33 +class MouseTrailer 
    1.34 +{
    1.35 +public:
    1.36 +    HWND                  GetMouseTrailerWindow() { return mMouseTrailerWindow; }
    1.37 +    HWND                  GetCaptureWindow() { return mCaptureWindow; }
    1.38 +
    1.39 +    void                  SetMouseTrailerWindow(HWND aWnd);
    1.40 +    void                  SetCaptureWindow(HWND aWnd);
    1.41 +    void                  Disable() { mEnabled = false; DestroyTimer(); }
    1.42 +    void                  Enable() { mEnabled = true; CreateTimer(); }
    1.43 +    void                  DestroyTimer();
    1.44 +
    1.45 +                          MouseTrailer();
    1.46 +                          ~MouseTrailer();
    1.47 +private:
    1.48 +
    1.49 +    nsresult              CreateTimer();
    1.50 +
    1.51 +    static void           TimerProc(nsITimer* aTimer, void* aClosure);
    1.52 +
    1.53 +    // Information for mouse enter/exit events
    1.54 +    HWND                  mMouseTrailerWindow;
    1.55 +    HWND                  mCaptureWindow;
    1.56 +    bool                  mIsInCaptureMode;
    1.57 +    bool                  mEnabled;
    1.58 +    nsCOMPtr<nsITimer>    mTimer;
    1.59 +};
    1.60 +
    1.61 +/**
    1.62 + * Wrapper around the thread running the message pump.
    1.63 + * The toolkit abstraction is necessary because the message pump must
    1.64 + * execute within the same thread that created the widget under Win32.
    1.65 + */ 
    1.66 +
    1.67 +class nsToolkit
    1.68 +{
    1.69 +public:
    1.70 +    nsToolkit();
    1.71 +
    1.72 +private:
    1.73 +    ~nsToolkit();
    1.74 +
    1.75 +public:
    1.76 +    static nsToolkit* GetToolkit();
    1.77 +
    1.78 +    static HINSTANCE mDllInstance;
    1.79 +    static MouseTrailer *gMouseTrailer;
    1.80 +
    1.81 +    static void Startup(HMODULE hModule);
    1.82 +    static void Shutdown();
    1.83 +    static void StartAllowingD3D9();
    1.84 +
    1.85 +protected:
    1.86 +    static nsToolkit* gToolkit;
    1.87 +
    1.88 +    nsCOMPtr<nsITimer> mD3D9Timer;
    1.89 +    MouseTrailer mMouseTrailer;
    1.90 +};
    1.91 +
    1.92 +#endif  // TOOLKIT_H

mercurial