1 /*
2  * Copyright (c) 1996, 2013, 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_DIALOG_H
27 #define AWT_DIALOG_H
28 
29 #include "awt_Frame.h"
30 
31 #include "java_awt_Dialog.h"
32 #include "sun_awt_windows_WDialogPeer.h"
33 
34 
35 /************************************************************************
36  * AwtDialog class
37  */
38 // unification with AwtComponent
39 #define AWT_DIALOG_WINDOW_CLASS_NAME TEXT("SunAwtDialog")
40 
41 class AwtDialog : public AwtFrame {
42 public:
43 
44     /* java.awt.Dialog field ids */
45     static jfieldID titleID;
46 
47     /* boolean undecorated field for java.awt.Dialog */
48     static jfieldID undecoratedID;
49 
50     AwtDialog();
51     virtual ~AwtDialog();
52 
53     virtual void Dispose();
54 
55     virtual LPCTSTR GetClassName();
56     virtual void  FillClassInfo(WNDCLASSEX *lpwc);
57     virtual void SetResizable(BOOL isResizable);
58 
59     void Show();
60 
61     virtual void DoUpdateIcon();
62     virtual HICON GetEffectiveIcon(int iconType);
63 
64     /* Create a new AwtDialog.  This must be run on the main thread. */
65     static AwtDialog* Create(jobject peer, jobject hParent);
66     virtual MsgRouting WmShowModal();
67     virtual MsgRouting WmEndModal();
68     virtual MsgRouting WmStyleChanged(int wStyleType, LPSTYLESTRUCT lpss);
69     virtual MsgRouting WmSize(UINT type, int w, int h);
70     MsgRouting WmNcMouseDown(WPARAM hitTest, int x, int y, int button);
71     virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam);
72 
73     /*
74      * The check is performed before the dialog is shown.
75      * The focused window can't be blocked at the time it's focused.
76      * Thus we don't have to perform any transitive (a blocker of a blocker) checks.
77      */
IsFocusedWindowModalBlocker()78     INLINE virtual BOOL IsFocusedWindowModalBlocker() {
79         return (AwtComponent::GetFocusedWindow() != NULL) && (GetModalBlocker(AwtComponent::GetFocusedWindow()) == GetHWnd());
80     }
81 
82     // finds and activates some window after the modal dialog is hidden
83     static void ModalActivateNextWindow(HWND dialogHWnd,
84                                         jobject dialogTarget, jobject dialogPeer);
85 
86     // some methods called on Tookit thread
87     static void _ShowModal(void *param);
88     static void _EndModal(void *param);
89     static void _SetIMMOption(void *param);
90 
91     static BOOL IsModalExcluded(HWND hwnd);
92 
93     static void CheckInstallModalHook();
94     static void CheckUninstallModalHook();
95 
96 private:
97 
98     void UpdateSystemMenu();
99 
100     HWND m_modalWnd;
101 
102     // checks if the given window can be activated after a modal dialog is hidden
ModalCanBeActivated(HWND hwnd)103     inline static BOOL ModalCanBeActivated(HWND hwnd) {
104         return ::IsWindow(hwnd) &&
105                ::IsWindowVisible(hwnd) &&
106                ::IsWindowEnabled(hwnd) &&
107               !::IsWindow(AwtWindow::GetModalBlocker(hwnd));
108     }
109     /*
110      * Activates the given window
111      * If the window is an embedded frame, it is activated from Java code.
112      *   See WEmbeddedFrame.activateEmbeddingTopLevel() for details.
113      */
114     static void ModalPerformActivation(HWND hWnd);
115 
116     static void PopupBlockers(HWND blocker, BOOL isModalHook, HWND prevFGWindow, BOOL onTaskbar);
117     static void PopupBlocker(HWND blocker, HWND nextBlocker, BOOL isModalHook, HWND prevFGWindow, BOOL onTaskbar);
118 
119 public:
120 
121     // WH_CBT hook procedure used in modality, prevents modal
122     // blocked windows from being activated
123     static LRESULT CALLBACK ModalFilterProc(int code,
124                                             WPARAM wParam, LPARAM lParam);
125     // WM_MOUSE hook procedure used in modality, filters some
126     // mouse events for blocked windows and brings blocker
127     // dialog to front
128     static LRESULT CALLBACK MouseHookProc(int code,
129                                           WPARAM wParam, LPARAM lParam);
130     // WM_MOUSE hook procedure used in modality, similar to
131     // MouseHookProc but installed on non-toolkit threads, for
132     // example on browser's thread when running in Java Plugin
133     static LRESULT CALLBACK MouseHookProc_NonTT(int code,
134                                                 WPARAM wParam, LPARAM lParam);
135 
136     static void AnimateModalBlocker(HWND window);
137 };
138 
139 #endif /* AWT_DIALOG_H */
140