1 /*
2  * Copyright (c) 1996, 2020, Oracle and/or its affiliates. All rights reserved.
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * This code is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License version 2 only, as
7  * published by the Free Software Foundation.  Oracle designates this
8  * particular file as subject to the "Classpath" exception as provided
9  * by Oracle in the LICENSE file that accompanied this code.
10  *
11  * This code is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14  * version 2 for more details (a copy is included in the LICENSE file that
15  * accompanied this code).
16  *
17  * You should have received a copy of the GNU General Public License version
18  * 2 along with this work; if not, write to the Free Software Foundation,
19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20  *
21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22  * or visit www.oracle.com if you need additional information or have any
23  * questions.
24  */
25 
26 #ifndef AWT_FRAME_H
27 #define AWT_FRAME_H
28 
29 #include "awt_Window.h"
30 #include "awt_MenuBar.h" //add for multifont
31 #include "awt_Toolkit.h"
32 #include "Hashtable.h"
33 
34 #include "java_awt_Frame.h"
35 #include "sun_awt_windows_WFramePeer.h"
36 
37 
38 /************************************************************************
39  * AwtFrame class
40  */
41 
42 #define AWT_FRAME_WINDOW_CLASS_NAME TEXT("SunAwtFrame")
43 
44 
45 class AwtFrame : public AwtWindow {
46 public:
47     enum FrameExecIds {
48         FRAME_SETMENUBAR
49     };
50 
51     /* java.awt.Frame fields and method IDs */
52     static jfieldID undecoratedID;
53 
54     /* sun.awt.windows.WEmbeddedFrame fields and method IDs */
55     static jfieldID handleID;
56 
57     static jmethodID getExtendedStateMID;
58 
59     /* method id for WEmbeddedFrame.requestActivate() method */
60     static jmethodID activateEmbeddingTopLevelMID;
61 
62     /* field id for WEmbeddedFrame.isEmbeddedInIE */
63     static jfieldID isEmbeddedInIEID;
64 
65     AwtFrame();
66     virtual ~AwtFrame();
67 
68     virtual void Dispose();
69 
70     virtual LPCTSTR GetClassName();
71 
72     /* Create a new AwtFrame.  This must be run on the main thread. */
73     static AwtFrame* Create(jobject self, jobject parent);
74 
75     /* Returns whether this frame is embedded in an external native frame. */
IsEmbeddedFrame()76     INLINE BOOL IsEmbeddedFrame() { return m_isEmbedded; }
77     /* Returns whether this frame is lightweight. */
IsLightweightFrame()78     INLINE virtual BOOL IsLightweightFrame() { return m_isLightweight; }
79 
IsSimpleWindow()80     INLINE BOOL IsSimpleWindow() { return FALSE; }
81 
82     /* Returns whether this window is in iconified state. */
isIconic()83     INLINE BOOL isIconic() { return m_iconic; }
setIconic(BOOL b)84     INLINE void setIconic(BOOL b) { m_iconic = b; }
85 
86     /* Returns whether this window is in zoomed state. */
isZoomed()87     INLINE BOOL isZoomed() { return m_zoomed; }
setZoomed(BOOL b)88     INLINE void setZoomed(BOOL b) { m_zoomed = b; }
89 
90     void Show();
91 
DrawMenuBar()92     INLINE void DrawMenuBar() { VERIFY(::DrawMenuBar(GetHWnd())); }
93 
94     virtual void DoUpdateIcon();
95     virtual HICON GetEffectiveIcon(int iconType);
96 
97     /*for WmDrawItem and WmMeasureItem method */
98     AwtMenuBar* GetMenuBar();
99     void SetMenuBar(AwtMenuBar*);
100 
101     virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam);
102 
103     MsgRouting WmGetMinMaxInfo(LPMINMAXINFO lpmmi);
104     MsgRouting WmSize(UINT type, int w, int h);
105     MsgRouting WmActivate(UINT nState, BOOL fMinimized, HWND opposite);
106     MsgRouting WmDrawItem(UINT ctrlId, DRAWITEMSTRUCT& drawInfo);
107     MsgRouting WmMeasureItem(UINT ctrlId, MEASUREITEMSTRUCT& measureInfo);
108     MsgRouting WmEnterMenuLoop(BOOL isTrackPopupMenu);
109     MsgRouting WmExitMenuLoop(BOOL isTrackPopupMenu);
110     MsgRouting WmMouseUp(UINT flags, int x, int y, int button);
111     MsgRouting WmMouseMove(UINT flags, int x, int y);
112     MsgRouting WmNcMouseDown(WPARAM hitTest, int x, int y, int button);
113     MsgRouting WmNcMouseUp(WPARAM hitTest, int x, int y, int button);
114     MsgRouting WmGetIcon(WPARAM iconType, LRESULT& retVal);
115     MsgRouting WmShowWindow(BOOL show, UINT status);
116 
117     virtual MsgRouting WmSysCommand(UINT uCmdType, int xPos, int yPos);
118 
119     LRESULT WinThreadExecProc(ExecuteArgs * args);
120 
IsUndecorated()121     INLINE BOOL IsUndecorated() { return m_isUndecorated; }
122 
GetProxyFocusOwner()123     INLINE HWND GetProxyFocusOwner() {
124         return GetHWnd();
125     }
126 
127     void SetMaximizedBounds(int x, int y, int w, int h);
128     void ClearMaximizedBounds();
129 
130     // returns true if the frame is inputmethod window
isInputMethodWindow()131     INLINE BOOL isInputMethodWindow() { return m_isInputMethodWindow; }
132     // adjusts the IME candidate window position if needed
133     void AdjustCandidateWindowPos();
134 
135     // invoked on Toolkit thread
136     static jobject _GetBoundsPrivate(void *param);
137 
138     // some methods called on Toolkit thread
139     static void _SetState(void *param);
140     static jint _GetState(void *param);
141     static void _SetMaximizedBounds(void *param);
142     static void _ClearMaximizedBounds(void *param);
143     static void _SetMenuBar(void *param);
144     static void _SetIMMOption(void *param);
145     static void _SynthesizeWmActivate(void *param);
146     static void _NotifyModalBlocked(void *param);
147 
148     virtual void Reshape(int x, int y, int width, int height);
149 
150     virtual BOOL AwtSetActiveWindow(BOOL isMouseEventCause = FALSE, UINT hittest = HTCLIENT);
151 
152     void CheckRetainActualFocusedWindow(HWND activatedOpositeHWnd);
153     BOOL CheckActivateActualFocusedWindow(HWND deactivatedOpositeHWnd);
154 
GetImeTargetComponent()155     INLINE HWND GetImeTargetComponent() { return m_imeTargetComponent; }
SetImeTargetComponent(HWND hwnd)156     INLINE void SetImeTargetComponent(HWND hwnd) { m_imeTargetComponent = hwnd; }
157 
158 protected:
159     /* The frame is undecorated. */
160     BOOL m_isUndecorated;
161 
162 private:
163     LRESULT ProxyWindowProc(UINT message, WPARAM wParam, LPARAM lParam, MsgRouting &mr);
164 
165     /* The frame's embedding parent (if any) */
166     HWND m_parentWnd;
167 
168     /* The frame's menubar. */
169     AwtMenuBar* menuBar;
170 
171     /* The frame is an EmbeddedFrame. */
172     BOOL m_isEmbedded;
173 
174     /* Fix for JDK-8056915:
175        The embedded frame must gain focus by setting focus to its parent. */
176     BOOL m_isEmbeddedInIE;
177 
178     /* Checks whether the frame is embedded in IE */
179     static BOOL IsEmbeddedInIE(HWND hwndParent);
180 
181     /* The frame is a LightweightFrame */
182     BOOL m_isLightweight;
183 
184     /* used so that calls to ::MoveWindow in SetMenuBar don't propogate
185        because they are immediately followed by calls to Component.resize */
186     BOOL m_ignoreWmSize;
187 
188     /* tracks whether or not menu on this frame is dropped down */
189     BOOL m_isMenuDropped;
190 
191     /* The frame is an InputMethodWindow */
192     BOOL m_isInputMethodWindow;
193 
194     // retains the target component for the IME messages
195     HWND m_imeTargetComponent;
196 
197     /*
198      * Fix for 4823903.
199      * Retains a focus proxied window to set the focus correctly
200      * when its owner get activated.
201      */
202     AwtWindow *m_actualFocusedWindow;
203 
204     /* The original, default WndProc for m_proxyFocusOwner. */
205     WNDPROC m_proxyDefWindowProc;
206 
207     BOOL m_iconic;          /* are we in an iconic state */
208     BOOL m_zoomed;          /* are we in a zoomed state */
209 
210     /* whether WmSize() must unconditionally reset zoomed state */
211     BOOL m_forceResetZoomed;
212 
213     BOOL  m_maxBoundsSet;
214     POINT m_maxPos;
215     POINT m_maxSize;
216 
217     BOOL isInManualMoveOrSize;
218     WPARAM grabbedHitTest;
219     POINT savedMousePos;
220 
221     /*
222      * Hashtable<Thread, BlockedThreadStruct> - a table that contains all the
223      * information about non-toolkit threads with modal blocked embedded
224      * frames. This information includes: number of blocked embedded frames
225      * created on the the thread, and mouse and modal hooks installed for
226      * that thread. For every thread each hook is installed only once
227      */
228     static Hashtable sm_BlockedThreads;
229 };
230 
231 #endif /* AWT_FRAME_H */
232