1 /* 2 * Copyright (c) 1996, 2009, 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_WINDOW_H 27 #define AWT_WINDOW_H 28 29 #include "awt_Canvas.h" 30 31 #include "java_awt_Window.h" 32 #include "sun_awt_windows_WWindowPeer.h" 33 34 // property name tagging windows disabled by modality 35 static LPCTSTR ModalBlockerProp = TEXT("SunAwtModalBlockerProp"); 36 static LPCTSTR ModalDialogPeerProp = TEXT("SunAwtModalDialogPeerProp"); 37 38 #ifndef WH_MOUSE_LL 39 #define WH_MOUSE_LL 14 40 #endif 41 42 // WS_EX_NOACTIVATE is not defined in the headers we build with 43 #define AWT_WS_EX_NOACTIVATE 0x08000000L 44 45 class AwtFrame; 46 47 /************************************************************************ 48 * AwtWindow class 49 */ 50 51 class AwtWindow : public AwtCanvas { 52 public: 53 54 /* java.awt.Window field ids */ 55 static jfieldID warningStringID; 56 static jfieldID locationByPlatformID; 57 static jfieldID screenID; /* screen number passed over from WindowPeer */ 58 static jfieldID autoRequestFocusID; 59 static jfieldID securityWarningWidthID; 60 static jfieldID securityWarningHeightID; 61 62 // The coordinates at the peer. 63 static jfieldID sysXID; 64 static jfieldID sysYID; 65 static jfieldID sysWID; 66 static jfieldID sysHID; 67 68 static jmethodID getWarningStringMID; 69 static jmethodID calculateSecurityWarningPositionMID; 70 71 AwtWindow(); 72 virtual ~AwtWindow(); 73 74 virtual void Dispose(); 75 76 virtual LPCTSTR GetClassName(); 77 virtual void FillClassInfo(WNDCLASSEX *lpwc); 78 79 static AwtWindow* Create(jobject self, jobject parent); 80 81 // Returns TRUE if this Window is equal to or one of owners of wnd 82 BOOL IsOneOfOwnersOf(AwtWindow * wnd); 83 84 /* Update the insets for this Window (container), its peer & 85 * optional other 86 */ 87 BOOL UpdateInsets(jobject insets = 0); 88 BOOL HasValidRect(); 89 90 static BOOL CALLBACK UpdateOwnedIconCallback(HWND hwnd, LPARAM param); 91 92 INLINE AwtFrame * GetOwningFrameOrDialog() { return m_owningFrameDialog; } 93 94 HWND GetTopLevelHWnd(); 95 96 /* Subtract inset values from a window origin. */ 97 INLINE void SubtractInsetPoint(int& x, int& y) { 98 x -= m_insets.left; 99 y -= m_insets.top; 100 } 101 102 virtual void GetInsets(RECT* rect) { 103 VERIFY(::CopyRect(rect, &m_insets)); 104 } 105 106 /* to make embedded frames easier */ 107 virtual BOOL IsEmbeddedFrame() { return FALSE;} 108 109 /* We can hold children */ 110 virtual BOOL IsContainer() { return TRUE;} 111 112 virtual BOOL IsUndecorated() { return TRUE; } 113 114 INLINE virtual BOOL IsSimpleWindow() { return TRUE; } 115 116 INLINE BOOL IsRetainingHierarchyZOrder() { return m_isRetainingHierarchyZOrder; } 117 118 /* WARNING: don't invoke on Toolkit thread! */ 119 INLINE BOOL IsAutoRequestFocus() { 120 JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2); 121 return env->GetBooleanField(GetTarget(env), AwtWindow::autoRequestFocusID); 122 } 123 124 INLINE virtual BOOL IsFocusedWindowModalBlocker() { 125 return FALSE; 126 } 127 128 virtual void Invalidate(RECT* r); 129 virtual void Show(); 130 virtual void SetResizable(BOOL isResizable); 131 BOOL IsResizable(); 132 virtual void RecalcNonClient(); 133 virtual void RedrawNonClient(); 134 virtual int GetScreenImOn(); 135 virtual void CheckIfOnNewScreen(); 136 virtual void Grab(); 137 virtual void Ungrab(); 138 virtual void Ungrab(BOOL doPost); 139 virtual void SetIconData(JNIEnv* env, jintArray iconData, jint w, jint h, 140 jintArray smallIconData, jint smw, jint smh); 141 virtual void DoUpdateIcon(); 142 INLINE HICON GetHIcon() {return m_hIcon;}; 143 INLINE HICON GetHIconSm() {return m_hIconSm;}; 144 INLINE BOOL IsIconInherited() {return m_iconInherited;}; 145 146 /* Post events to the EventQueue */ 147 void SendComponentEvent(jint eventId); 148 void SendWindowEvent(jint id, HWND opposite = NULL, 149 jint oldState = 0, jint newState = 0); 150 151 BOOL IsFocusableWindow(); 152 153 /* some helper methods about blocking windows by modal dialogs */ 154 INLINE static HWND GetModalBlocker(HWND window) { 155 return reinterpret_cast<HWND>(::GetProp(window, ModalBlockerProp)); 156 } 157 static void SetModalBlocker(HWND window, HWND blocker); 158 static void SetAndActivateModalBlocker(HWND window, HWND blocker); 159 160 static HWND GetTopmostModalBlocker(HWND window); 161 162 /* 163 * Windows message handler functions 164 */ 165 virtual MsgRouting WmActivate(UINT nState, BOOL fMinimized, HWND opposite); 166 static void BounceActivation(void *self); // used by WmActivate 167 virtual MsgRouting WmCreate(); 168 virtual MsgRouting WmClose(); 169 virtual MsgRouting WmDestroy(); 170 virtual MsgRouting WmShowWindow(BOOL show, UINT status); 171 virtual MsgRouting WmGetMinMaxInfo(LPMINMAXINFO lpmmi); 172 virtual MsgRouting WmMove(int x, int y); 173 virtual MsgRouting WmSize(UINT type, int w, int h); 174 virtual MsgRouting WmSizing(); 175 virtual MsgRouting WmPaint(HDC hDC); 176 virtual MsgRouting WmSettingChange(UINT wFlag, LPCTSTR pszSection); 177 virtual MsgRouting WmNcCalcSize(BOOL fCalcValidRects, 178 LPNCCALCSIZE_PARAMS lpncsp, LRESULT& retVal); 179 virtual MsgRouting WmNcHitTest(UINT x, UINT y, LRESULT& retVal); 180 virtual MsgRouting WmNcMouseDown(WPARAM hitTest, int x, int y, int button); 181 virtual MsgRouting WmGetIcon(WPARAM iconType, LRESULT& retVal); 182 virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam); 183 virtual MsgRouting WmWindowPosChanging(LPARAM windowPos); 184 virtual MsgRouting WmWindowPosChanged(LPARAM windowPos); 185 virtual MsgRouting WmTimer(UINT_PTR timerID); 186 187 virtual MsgRouting HandleEvent(MSG *msg, BOOL synthetic); 188 virtual void WindowResized(); 189 190 void moveToDefaultLocation(); /* moves Window to X,Y specified by Window Manger */ 191 192 void UpdateWindow(JNIEnv* env, jintArray data, int width, int height, 193 HBITMAP hNewBitmap = NULL); 194 195 INLINE virtual BOOL IsTopLevel() { return TRUE; } 196 static AwtWindow * GetGrabbedWindow() { return m_grabbedWindow; } 197 198 static void FlashWindowEx(HWND hWnd, UINT count, DWORD timeout, DWORD flags); 199 200 // some methods invoked on Toolkit thread 201 static void _ToFront(void *param); 202 static void _ToBack(void *param); 203 static void _Grab(void *param); 204 static void _Ungrab(void *param); 205 static void _SetAlwaysOnTop(void *param); 206 static void _SetTitle(void *param); 207 static void _SetResizable(void *param); 208 static void _UpdateInsets(void *param); 209 static void _ReshapeFrame(void *param); 210 static void _SetIconImagesData(void * param); 211 static void _SetMinSize(void* param); 212 static jint _GetScreenImOn(void *param); 213 static void _SetFocusableWindow(void *param); 214 static void _SetModalExcludedNativeProp(void *param); 215 static void _ModalDisable(void *param); 216 static void _ModalEnable(void *param); 217 static void _SetOpacity(void* param); 218 static void _SetOpaque(void* param); 219 static void _UpdateWindow(void* param); 220 static void _RepositionSecurityWarning(void* param); 221 222 inline static BOOL IsResizing() { 223 return sm_resizing; 224 } 225 226 virtual void CreateHWnd(JNIEnv *env, LPCWSTR title, 227 DWORD windowStyle, DWORD windowExStyle, 228 int x, int y, int w, int h, 229 HWND hWndParent, HMENU hMenu, 230 COLORREF colorForeground, COLORREF colorBackground, 231 jobject peer); 232 virtual void DestroyHWnd(); 233 234 static void FocusedWindowChanged(HWND from, HWND to); 235 236 private: 237 static int ms_instanceCounter; 238 static HHOOK ms_hCBTFilter; 239 static LRESULT CALLBACK CBTFilter(int nCode, WPARAM wParam, LPARAM lParam); 240 static HWND sm_retainingHierarchyZOrderInShow; // a referred window in the process of show 241 static BOOL sm_resizing; /* in the middle of a resizing operation */ 242 243 RECT m_insets; /* a cache of the insets being used */ 244 RECT m_old_insets; /* help determine if insets change */ 245 POINT m_sizePt; /* the last value of WM_SIZE */ 246 RECT m_warningRect; /* The window's warning banner area, if any. */ 247 AwtFrame *m_owningFrameDialog; /* The nearest Frame/Dialog which owns us */ 248 BOOL m_isFocusableWindow; /* a cache of Window.isFocusableWindow() return value */ 249 POINT m_minSize; /* Minimum size of the window for WM_GETMINMAXINFO message */ 250 BOOL m_grabbed; // Whether the current window is grabbed 251 BOOL m_isRetainingHierarchyZOrder; // Is this a window that shouldn't change z-order of any window 252 // from its hierarchy when shown. Currently applied to instances of 253 // javax/swing/Popup$HeavyWeightWindow class. 254 255 BYTE m_opacity; // The opacity level. == 0xff by default (when opacity mode is disabled) 256 BOOL m_opaque; // Whether the window uses the perpixel translucency (false), or not (true). 257 258 inline BYTE getOpacity() { 259 return m_opacity; 260 } 261 inline void setOpacity(BYTE opacity) { 262 m_opacity = opacity; 263 } 264 265 inline BOOL isOpaque() { 266 return m_opaque; 267 } 268 inline void setOpaque(BOOL opaque) { 269 m_opaque = opaque; 270 } 271 272 CRITICAL_SECTION contentBitmapCS; 273 HBITMAP hContentBitmap; 274 UINT contentWidth; 275 UINT contentHeight; 276 277 void SetTranslucency(BYTE opacity, BOOL opaque); 278 void UpdateWindow(int width, int height, HBITMAP hBitmap); 279 void UpdateWindowImpl(int width, int height, HBITMAP hBitmap); 280 void RedrawWindow(); 281 282 static UINT untrustedWindowsCounter; 283 284 WCHAR * warningString; 285 286 // The warning icon 287 HWND warningWindow; 288 // The tooltip that appears when hovering the icon 289 HWND securityTooltipWindow; 290 291 UINT warningWindowWidth; 292 UINT warningWindowHeight; 293 void InitSecurityWarningSize(JNIEnv *env); 294 HICON GetSecurityWarningIcon(); 295 296 void CreateWarningWindow(JNIEnv *env); 297 void DestroyWarningWindow(); 298 static LPCTSTR GetWarningWindowClassName(); 299 void FillWarningWindowClassInfo(WNDCLASS *lpwc); 300 void RegisterWarningWindowClass(); 301 void UnregisterWarningWindowClass(); 302 static LRESULT CALLBACK WarningWindowProc( 303 HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam); 304 305 static void PaintWarningWindow(HWND warningWindow); 306 static void PaintWarningWindow(HWND warningWindow, HDC hdc); 307 void RepaintWarningWindow(); 308 void CalculateWarningWindowBounds(JNIEnv *env, LPRECT rect); 309 310 void AnimateSecurityWarning(bool enable); 311 UINT securityWarningAnimationStage; 312 313 enum AnimationKind { 314 akNone, akShow, akPreHide, akHide 315 }; 316 317 AnimationKind securityAnimationKind; 318 319 void StartSecurityAnimation(AnimationKind kind); 320 void StopSecurityAnimation(); 321 322 void RepositionSecurityWarning(JNIEnv *env); 323 324 public: 325 void UpdateSecurityWarningVisibility(); 326 static bool IsWarningWindow(HWND hWnd); 327 328 protected: 329 BOOL m_isResizable; 330 static AwtWindow* m_grabbedWindow; // Current grabbing window 331 HICON m_hIcon; /* Icon for this window. It can be set explicitely or inherited from the owner */ 332 HICON m_hIconSm; /* Small icon for this window. It can be set explicitely or inherited from the owner */ 333 BOOL m_iconInherited; /* TRUE if icon is inherited from the owner */ 334 BOOL m_filterFocusAndActivation; /* Used in the WH_CBT hook */ 335 336 //These are used in AwtComponent::CreatePrintedPixels. They are overridden 337 //here to handle non-opaque windows. 338 virtual void FillBackground(HDC hMemoryDC, SIZE &size); 339 virtual void FillAlpha(void *bitmapBits, SIZE &size, BYTE alpha); 340 341 inline BOOL IsUntrusted() { 342 return warningString != NULL; 343 } 344 345 UINT currentWmSizeState; 346 347 private: 348 int m_screenNum; 349 350 void InitOwner(AwtWindow *owner); 351 }; 352 353 #endif /* AWT_WINDOW_H */