forked from adobe/brackets-shell
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcef_host_window.cpp
More file actions
140 lines (120 loc) · 4.49 KB
/
Copy pathcef_host_window.cpp
File metadata and controls
140 lines (120 loc) · 4.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/*
* Copyright (c) 2013 Adobe Systems Incorporated. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
#include "client_handler.h"
#include "cef_host_window.h"
#include "native_menu_model.h"
// externals
extern CefRefPtr<ClientHandler> g_handler;
cef_host_window::cef_host_window(void)
{
}
cef_host_window::~cef_host_window(void)
{
}
HWND cef_host_window::SafeGetCefBrowserHwnd()
{
if (GetBrowser().get() && GetBrowser()->GetHost().get())
return GetBrowser()->GetHost()->GetWindowHandle();
return NULL;
}
// WM_INITMENUPOPUP handler
BOOL cef_host_window::HandleInitMenuPopup(HMENU hMenuPopup)
{
// Load the menu item state from the menu state cache
int count = ::GetMenuItemCount(hMenuPopup);
void* menuParent = ::getMenuParent(GetBrowser());
for (int i = 0; i < count; i++) {
UINT id = GetMenuItemID(hMenuPopup, i);
bool enabled = NativeMenuModel::getInstance(menuParent).isMenuItemEnabled(id);
UINT flagEnabled = enabled ? MF_ENABLED | MF_BYCOMMAND : MF_DISABLED | MF_BYCOMMAND;
EnableMenuItem(hMenuPopup, id, flagEnabled);
bool checked = NativeMenuModel::getInstance(menuParent).isMenuItemChecked(id);
UINT flagChecked = checked ? MF_CHECKED | MF_BYCOMMAND : MF_UNCHECKED | MF_BYCOMMAND;
CheckMenuItem(hMenuPopup, id, flagChecked);
}
return TRUE;
}
// DoCommand Impl with a command string
BOOL cef_host_window::DoCommand(const CefString& commandString, CefRefPtr<CommandCallback> callback/*=0*/)
{
if (commandString.size() > 0)
{
g_handler->SendJSCommand(GetBrowser(), commandString, callback);
return TRUE;
}
return FALSE;
}
// GetCommandString: CommandID => CommandString
CefString cef_host_window::GetCommandString(UINT commandId)
{
return NativeMenuModel::getInstance(::getMenuParent(GetBrowser())).getCommandId(commandId);
}
// DoCommand Impl with a command id
BOOL cef_host_window::DoCommand(UINT commandId, CefRefPtr<CommandCallback> callback/*=0*/)
{
CefString commandString = GetCommandString(commandId);
if (callback == NULL) {
callback = new EditCommandCallback(GetBrowser(), commandString);
}
return DoCommand(commandString, callback);
}
// WM_SIZE handler
BOOL cef_host_window::HandleSize(BOOL bMinimize)
{
#ifdef DARK_UI
// We turn off redraw during activation to minimized flicker
// which causes problems on some versions of Windows. If the app
// was minimized and was re-activated, it will restore and the client area isn't
// drawn so redraw the client area now or it will be hollow in the middle...
if (GetProp(L"WasMinimized")) {
DoRepaintClientArea();
}
SetProp(L"WasMinimized", (HANDLE)bMinimize);
#endif
return FALSE;
}
void cef_host_window::DoRepaintClientArea()
{
CefWindowHandle hwnd = SafeGetCefBrowserHwnd();
if (!hwnd)
return;
RECT rect;
GetClientRect(&rect);
::RedrawWindow(hwnd, &rect, NULL, RDW_ERASE|RDW_INTERNALPAINT|RDW_INVALIDATE|RDW_ERASENOW|RDW_UPDATENOW|RDW_ALLCHILDREN);
}
// Window Proc dispatches window messages
LRESULT cef_host_window::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_SIZE:
if (HandleSize(wParam == SIZE_MINIMIZED))
return 0L;
break;
case WM_INITMENUPOPUP:
if (HandleInitMenuPopup((HMENU)wParam))
return 0L;
break;
}
LRESULT lr = cef_host_window_base::WindowProc(message, wParam, lParam);
return lr;
}