Change windows messages api to hook instead of emitter
This commit is contained in:
parent
edbebf84b9
commit
e355532d27
4 changed files with 73 additions and 9 deletions
|
@ -190,8 +190,10 @@ void Window::OnExecuteWindowsCommand(const std::string& command_name) {
|
|||
}
|
||||
|
||||
#if defined(OS_WIN)
|
||||
void Window::OnWindowMessage(UINT message, LPARAM l_param, WPARAM w_param) {
|
||||
Emit("message", message, l_param, w_param);
|
||||
void Window::OnWindowMessage(UINT message, WPARAM w_param, LPARAM l_param) {
|
||||
if (IsWindowMessageHooked(message)) {
|
||||
messages_callback_map_[message].Run(w_param, l_param);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -498,6 +500,29 @@ bool Window::IsMenuBarVisible() {
|
|||
return window_->IsMenuBarVisible();
|
||||
}
|
||||
|
||||
#if defined(OS_WIN)
|
||||
bool Window::HookWindowMessage(UINT message,
|
||||
const MessageCallback& callback) {
|
||||
messages_callback_map_[message] = callback;
|
||||
return true;
|
||||
}
|
||||
|
||||
void Window::UnhookWindowMessage(UINT message) {
|
||||
if (!ContainsKey(messages_callback_map_, message))
|
||||
return;
|
||||
|
||||
messages_callback_map_.erase(message);
|
||||
}
|
||||
|
||||
bool Window::IsWindowMessageHooked(UINT message) {
|
||||
return ContainsKey(messages_callback_map_, message);
|
||||
}
|
||||
|
||||
void Window::UnhookAllWindowMessages() {
|
||||
messages_callback_map_.clear();
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(OS_MACOSX)
|
||||
void Window::ShowDefinitionForSelection() {
|
||||
window_->ShowDefinitionForSelection();
|
||||
|
@ -596,6 +621,12 @@ void Window::BuildPrototype(v8::Isolate* isolate,
|
|||
&Window::SetVisibleOnAllWorkspaces)
|
||||
.SetMethod("isVisibleOnAllWorkspaces",
|
||||
&Window::IsVisibleOnAllWorkspaces)
|
||||
#if defined(OS_WIN)
|
||||
.SetMethod("hookWindowMessage", &Window::HookWindowMessage)
|
||||
.SetMethod("isWindowMessageHooked", &Window::IsWindowMessageHooked)
|
||||
.SetMethod("unhookWindowMessage", &Window::UnhookWindowMessage)
|
||||
.SetMethod("unhookAllWindowMessages", &Window::UnhookAllWindowMessages)
|
||||
#endif
|
||||
#if defined(OS_MACOSX)
|
||||
.SetMethod("showDefinitionForSelection",
|
||||
&Window::ShowDefinitionForSelection)
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#ifndef ATOM_BROWSER_API_ATOM_API_WINDOW_H_
|
||||
#define ATOM_BROWSER_API_ATOM_API_WINDOW_H_
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
|
@ -76,8 +77,8 @@ class Window : public mate::TrackableObject<Window>,
|
|||
void OnExecuteWindowsCommand(const std::string& command_name) override;
|
||||
|
||||
#if defined(OS_WIN)
|
||||
void OnWindowMessage(unsigned int message, LPARAM l_param,
|
||||
WPARAM w_param) override;
|
||||
void OnWindowMessage(UINT message, WPARAM w_param,
|
||||
LPARAM l_param) override;
|
||||
#endif
|
||||
|
||||
// mate::Wrappable:
|
||||
|
@ -148,6 +149,18 @@ class Window : public mate::TrackableObject<Window>,
|
|||
bool IsMenuBarVisible();
|
||||
void SetAspectRatio(double aspect_ratio, mate::Arguments* args);
|
||||
|
||||
#if defined(OS_WIN)
|
||||
typedef base::Callback<void(WPARAM, LPARAM)> MessageCallback;
|
||||
typedef std::map<UINT, MessageCallback> MessageCallbackMap;
|
||||
MessageCallbackMap messages_callback_map_;
|
||||
|
||||
bool HookWindowMessage(UINT message,
|
||||
const MessageCallback& callback);
|
||||
bool IsWindowMessageHooked(UINT message);
|
||||
void UnhookWindowMessage(UINT message);
|
||||
void UnhookAllWindowMessages();
|
||||
#endif
|
||||
|
||||
#if defined(OS_MACOSX)
|
||||
void ShowDefinitionForSelection();
|
||||
#endif
|
||||
|
|
|
@ -61,7 +61,7 @@ class NativeWindowObserver {
|
|||
|
||||
// Called when window message received
|
||||
#if defined(OS_WIN)
|
||||
virtual void OnWindowMessage(UINT message, LPARAM l_param, WPARAM w_param) {}
|
||||
virtual void OnWindowMessage(UINT message, WPARAM w_param, LPARAM l_param) {}
|
||||
#endif
|
||||
|
||||
// Called when renderer is hung.
|
||||
|
|
|
@ -232,10 +232,6 @@ Emitted when the window enters full screen state triggered by html api.
|
|||
|
||||
Emitted when the window leaves full screen state triggered by html api.
|
||||
|
||||
### Event: 'message' _WINDOWS_
|
||||
|
||||
Emitted when the window receives a message from the operating system.
|
||||
|
||||
### Event: 'app-command':
|
||||
|
||||
Emitted when an [App Command](https://msdn.microsoft.com/en-us/library/windows/desktop/ms646275(v=vs.85).aspx)
|
||||
|
@ -556,6 +552,30 @@ Enters or leaves the kiosk mode.
|
|||
|
||||
Returns whether the window is in kiosk mode.
|
||||
|
||||
### `win.hookWindowMessage(message, callback)` _WINDOWS_
|
||||
|
||||
* `message` Integer
|
||||
* `callback` Function
|
||||
|
||||
Hooks a windows message. The `callback` is called when
|
||||
the message is received in the WndProc.
|
||||
|
||||
### `win.isWindowMessageHooked(message)` _WINDOWS_
|
||||
|
||||
* `message` Integer
|
||||
|
||||
Returns `true` or `false` depending on whether the message is hooked.
|
||||
|
||||
### `win.unhookWindowMessage(message)` _WINDOWS_
|
||||
|
||||
* `message` Integer
|
||||
|
||||
Unhook the window message.
|
||||
|
||||
### `win.unhookAllWindowMessages()` _WINDOWS_
|
||||
|
||||
Unhooks all of the window messages.
|
||||
|
||||
### `win.setRepresentedFilename(filename)` _OS X_
|
||||
|
||||
* `filename` String
|
||||
|
|
Loading…
Reference in a new issue