widget/windows/WindowHook.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/widget/windows/WindowHook.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,81 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
     1.5 + *
     1.6 + * This Source Code Form is subject to the terms of the Mozilla Public
     1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.9 +
    1.10 +#ifndef __mozilla_WindowHook_h__
    1.11 +#define __mozilla_WindowHook_h__
    1.12 +
    1.13 +#include <windows.h>
    1.14 +
    1.15 +#include <nsHashKeys.h>
    1.16 +#include <nsClassHashtable.h>
    1.17 +#include <nsTArray.h>
    1.18 +
    1.19 +#include "nsAppShell.h"
    1.20 +
    1.21 +class nsWindow;
    1.22 +
    1.23 +namespace mozilla {
    1.24 +namespace widget {
    1.25 +
    1.26 +struct MSGResult;
    1.27 +
    1.28 +class WindowHook {
    1.29 +public:
    1.30 +
    1.31 +  // It is expected that most callbacks will return false
    1.32 +  typedef bool (*Callback)(void *aContext, HWND hWnd, UINT nMsg,
    1.33 +                             WPARAM wParam, LPARAM lParam, LRESULT *aResult);
    1.34 +
    1.35 +  nsresult AddHook(UINT nMsg, Callback callback, void *context);
    1.36 +  nsresult RemoveHook(UINT nMsg, Callback callback, void *context);
    1.37 +  nsresult AddMonitor(UINT nMsg, Callback callback, void *context);
    1.38 +  nsresult RemoveMonitor(UINT nMsg, Callback callback, void *context);
    1.39 +
    1.40 +private:
    1.41 +  struct CallbackData {
    1.42 +    Callback cb;
    1.43 +    void *context;
    1.44 +
    1.45 +    CallbackData() : cb(nullptr), context(nullptr) {}
    1.46 +    CallbackData(Callback cb, void *ctx) : cb(cb), context(ctx) {}
    1.47 +    bool Invoke(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam,
    1.48 +                  LRESULT *aResult);
    1.49 +    bool operator== (const CallbackData &rhs) const {
    1.50 +      return cb == rhs.cb && context == rhs.context;
    1.51 +    }
    1.52 +    bool operator!= (const CallbackData &rhs) const {
    1.53 +      return !(*this == rhs);
    1.54 +    }
    1.55 +    operator bool () const {
    1.56 +      return !!cb;
    1.57 +    }
    1.58 +  };
    1.59 +
    1.60 +  typedef nsTArray<CallbackData> CallbackDataArray;
    1.61 +  struct MessageData {
    1.62 +    UINT nMsg;
    1.63 +    CallbackData hook;
    1.64 +    CallbackDataArray monitors;
    1.65 +  };
    1.66 +
    1.67 +  bool Notify(HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam,
    1.68 +              MSGResult& aResult);
    1.69 +
    1.70 +  MessageData *Lookup(UINT nMsg);
    1.71 +  MessageData *LookupOrCreate(UINT nMsg);
    1.72 +  void DeleteIfEmpty(MessageData *data);
    1.73 +
    1.74 +  typedef nsTArray<MessageData> MessageDataArray;
    1.75 +  MessageDataArray mMessageData;
    1.76 +
    1.77 +  // For Notify
    1.78 +  friend class ::nsWindow;
    1.79 +};
    1.80 +
    1.81 +}
    1.82 +}
    1.83 +
    1.84 +#endif // __mozilla_WindowHook_h__

mercurial