1 /*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 #include "NativeSubWindow.h"
17
18 struct SubWindowUserData {
19 SubWindowRepaintCallback repaint_callback;
20 void* repaint_callback_param;
21 };
22
subWindowProc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam)23 static LRESULT CALLBACK subWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
24 if (uMsg == WM_PAINT) {
25 auto user_data =
26 (SubWindowUserData*)GetWindowLongPtr(hwnd, GWLP_USERDATA);
27 if (user_data && user_data->repaint_callback) {
28 user_data->repaint_callback(user_data->repaint_callback_param);
29 }
30 } else if (uMsg == WM_NCDESTROY) {
31 SubWindowUserData* user_data =
32 (SubWindowUserData*)GetWindowLongPtr(hwnd, GWLP_USERDATA);
33 delete user_data;
34 }
35 return DefWindowProcA(hwnd, uMsg, wParam, lParam);
36 }
37
createSubWindow(FBNativeWindowType p_window,int x,int y,int width,int height,float dpr,SubWindowRepaintCallback repaint_callback,void * repaint_callback_param,int hideWindow)38 EGLNativeWindowType createSubWindow(FBNativeWindowType p_window,
39 int x, int y,int width, int height, float dpr,
40 SubWindowRepaintCallback repaint_callback,
41 void* repaint_callback_param, int hideWindow){
42 static const char className[] = "subWin";
43
44 WNDCLASSA wc = {};
45 if (!GetClassInfoA(GetModuleHandle(NULL), className, &wc)) {
46 wc.style = CS_OWNDC | CS_HREDRAW | CS_VREDRAW;// redraw if size changes
47 wc.lpfnWndProc = &subWindowProc; // points to window procedure
48 wc.cbWndExtra = sizeof(void*) ; // save extra window memory
49 wc.lpszClassName = className; // name of window class
50 RegisterClassA(&wc);
51 }
52
53 EGLNativeWindowType ret = CreateWindowExA(
54 WS_EX_NOPARENTNOTIFY, // do not bother our parent window
55 className,
56 "sub",
57 WS_CHILD|WS_DISABLED,
58 x,y,width,height,
59 p_window,
60 NULL,
61 NULL,
62 NULL);
63
64 auto user_data = new SubWindowUserData();
65 user_data->repaint_callback = repaint_callback;
66 user_data->repaint_callback_param = repaint_callback_param;
67
68 SetWindowLongPtr(ret, GWLP_USERDATA, (LONG_PTR)user_data);
69 if (!hideWindow)
70 ShowWindow(ret, SW_SHOW);
71 return ret;
72 }
73
destroySubWindow(EGLNativeWindowType win)74 void destroySubWindow(EGLNativeWindowType win){
75 PostMessage(win, WM_CLOSE, 0, 0);
76 }
77
moveSubWindow(FBNativeWindowType p_parent_window,EGLNativeWindowType p_sub_window,int x,int y,int width,int height)78 int moveSubWindow(FBNativeWindowType p_parent_window,
79 EGLNativeWindowType p_sub_window,
80 int x,
81 int y,
82 int width,
83 int height) {
84 BOOL ret = MoveWindow(p_sub_window,
85 x,
86 y,
87 width,
88 height,
89 TRUE);
90 return ret;
91 }
92