annotate src/java.desktop/windows/native/libawt/windows/awt_Window.h @ 13220:a8e9ad77ac81

8073320: Windows HiDPI Graphics support Reviewed-by: flar, serb
author alexsch
date Fri, 13 Nov 2015 05:02:26 -0800
parents e66f69113b89
children 7d9ef221ddc7
rev   line source
duke@0 1 /*
lana@9330 2 * Copyright (c) 1996, 2013, Oracle and/or its affiliates. All rights reserved.
duke@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@0 4 *
duke@0 5 * This code is free software; you can redistribute it and/or modify it
duke@0 6 * under the terms of the GNU General Public License version 2 only, as
ohair@2362 7 * published by the Free Software Foundation. Oracle designates this
duke@0 8 * particular file as subject to the "Classpath" exception as provided
ohair@2362 9 * by Oracle in the LICENSE file that accompanied this code.
duke@0 10 *
duke@0 11 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@0 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@0 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@0 14 * version 2 for more details (a copy is included in the LICENSE file that
duke@0 15 * accompanied this code).
duke@0 16 *
duke@0 17 * You should have received a copy of the GNU General Public License version
duke@0 18 * 2 along with this work; if not, write to the Free Software Foundation,
duke@0 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@0 20 *
ohair@2362 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ohair@2362 22 * or visit www.oracle.com if you need additional information or have any
ohair@2362 23 * questions.
duke@0 24 */
duke@0 25
duke@0 26 #ifndef AWT_WINDOW_H
duke@0 27 #define AWT_WINDOW_H
duke@0 28
duke@0 29 #include "awt_Canvas.h"
duke@0 30
duke@0 31 #include "java_awt_Window.h"
duke@0 32 #include "sun_awt_windows_WWindowPeer.h"
duke@0 33
duke@0 34 // property name tagging windows disabled by modality
duke@0 35 static LPCTSTR ModalBlockerProp = TEXT("SunAwtModalBlockerProp");
duke@0 36 static LPCTSTR ModalDialogPeerProp = TEXT("SunAwtModalDialogPeerProp");
dcherepanov@1050 37 static LPCTSTR NativeDialogWndProcProp = TEXT("SunAwtNativeDialogWndProcProp");
duke@0 38
duke@0 39 #ifndef WH_MOUSE_LL
duke@0 40 #define WH_MOUSE_LL 14
duke@0 41 #endif
duke@0 42
duke@0 43 class AwtFrame;
duke@0 44
duke@0 45 /************************************************************************
duke@0 46 * AwtWindow class
duke@0 47 */
duke@0 48
duke@0 49 class AwtWindow : public AwtCanvas {
duke@0 50 public:
duke@0 51
duke@0 52 /* java.awt.Window field ids */
duke@0 53 static jfieldID warningStringID;
duke@0 54 static jfieldID locationByPlatformID;
duke@0 55 static jfieldID screenID; /* screen number passed over from WindowPeer */
duke@0 56 static jfieldID autoRequestFocusID;
anthony@1066 57 static jfieldID securityWarningWidthID;
anthony@1066 58 static jfieldID securityWarningHeightID;
duke@0 59
anthony@106 60 // The coordinates at the peer.
anthony@106 61 static jfieldID sysXID;
anthony@106 62 static jfieldID sysYID;
anthony@106 63 static jfieldID sysWID;
anthony@106 64 static jfieldID sysHID;
anthony@106 65
anthony@1971 66 static jfieldID windowTypeID;
anthony@1971 67
anthony@1066 68 static jmethodID getWarningStringMID;
anthony@1066 69 static jmethodID calculateSecurityWarningPositionMID;
anthony@1971 70 static jmethodID windowTypeNameMID;
anthony@1066 71
duke@0 72 AwtWindow();
duke@0 73 virtual ~AwtWindow();
duke@0 74
duke@0 75 virtual void Dispose();
duke@0 76
duke@0 77 virtual LPCTSTR GetClassName();
duke@0 78 virtual void FillClassInfo(WNDCLASSEX *lpwc);
duke@0 79
duke@0 80 static AwtWindow* Create(jobject self, jobject parent);
duke@0 81
duke@0 82 // Returns TRUE if this Window is equal to or one of owners of wnd
duke@0 83 BOOL IsOneOfOwnersOf(AwtWindow * wnd);
duke@0 84
duke@0 85 /* Update the insets for this Window (container), its peer &
duke@0 86 * optional other
duke@0 87 */
duke@0 88 BOOL UpdateInsets(jobject insets = 0);
duke@0 89 BOOL HasValidRect();
duke@0 90
duke@0 91 static BOOL CALLBACK UpdateOwnedIconCallback(HWND hwnd, LPARAM param);
duke@0 92
duke@0 93 INLINE AwtFrame * GetOwningFrameOrDialog() { return m_owningFrameDialog; }
duke@0 94
duke@0 95 HWND GetTopLevelHWnd();
duke@0 96
duke@0 97 /* Subtract inset values from a window origin. */
duke@0 98 INLINE void SubtractInsetPoint(int& x, int& y) {
duke@0 99 x -= m_insets.left;
duke@0 100 y -= m_insets.top;
duke@0 101 }
duke@0 102
duke@0 103 virtual void GetInsets(RECT* rect) {
duke@0 104 VERIFY(::CopyRect(rect, &m_insets));
duke@0 105 }
duke@0 106
duke@0 107 /* to make embedded frames easier */
duke@0 108 virtual BOOL IsEmbeddedFrame() { return FALSE;}
duke@0 109
duke@0 110 /* We can hold children */
duke@0 111 virtual BOOL IsContainer() { return TRUE;}
duke@0 112
duke@0 113 virtual BOOL IsUndecorated() { return TRUE; }
duke@0 114
duke@0 115 INLINE virtual BOOL IsSimpleWindow() { return TRUE; }
duke@0 116
duke@0 117 INLINE BOOL IsRetainingHierarchyZOrder() { return m_isRetainingHierarchyZOrder; }
duke@0 118
duke@0 119 /* WARNING: don't invoke on Toolkit thread! */
duke@0 120 INLINE BOOL IsAutoRequestFocus() {
duke@0 121 JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
duke@0 122 return env->GetBooleanField(GetTarget(env), AwtWindow::autoRequestFocusID);
duke@0 123 }
duke@0 124
duke@0 125 INLINE virtual BOOL IsFocusedWindowModalBlocker() {
duke@0 126 return FALSE;
duke@0 127 }
duke@0 128
duke@0 129 virtual void Invalidate(RECT* r);
duke@0 130 virtual void Show();
duke@0 131 virtual void SetResizable(BOOL isResizable);
duke@0 132 BOOL IsResizable();
duke@0 133 virtual void RecalcNonClient();
duke@0 134 virtual void RedrawNonClient();
duke@0 135 virtual int GetScreenImOn();
duke@0 136 virtual void CheckIfOnNewScreen();
duke@0 137 virtual void Grab();
duke@0 138 virtual void Ungrab();
duke@0 139 virtual void Ungrab(BOOL doPost);
duke@0 140 virtual void SetIconData(JNIEnv* env, jintArray iconData, jint w, jint h,
duke@0 141 jintArray smallIconData, jint smw, jint smh);
duke@0 142 virtual void DoUpdateIcon();
duke@0 143 INLINE HICON GetHIcon() {return m_hIcon;};
duke@0 144 INLINE HICON GetHIconSm() {return m_hIconSm;};
duke@0 145 INLINE BOOL IsIconInherited() {return m_iconInherited;};
ant@6621 146 INLINE virtual BOOL IsLightweightFrame() {return FALSE;}
duke@0 147
duke@0 148 /* Post events to the EventQueue */
duke@0 149 void SendComponentEvent(jint eventId);
duke@0 150 void SendWindowEvent(jint id, HWND opposite = NULL,
duke@0 151 jint oldState = 0, jint newState = 0);
duke@0 152
duke@0 153 BOOL IsFocusableWindow();
duke@0 154
duke@0 155 /* some helper methods about blocking windows by modal dialogs */
duke@0 156 INLINE static HWND GetModalBlocker(HWND window) {
duke@0 157 return reinterpret_cast<HWND>(::GetProp(window, ModalBlockerProp));
duke@0 158 }
duke@0 159 static void SetModalBlocker(HWND window, HWND blocker);
duke@0 160 static void SetAndActivateModalBlocker(HWND window, HWND blocker);
duke@0 161
anthony@1066 162 static HWND GetTopmostModalBlocker(HWND window);
anthony@1066 163
duke@0 164 /*
duke@0 165 * Windows message handler functions
duke@0 166 */
duke@0 167 virtual MsgRouting WmActivate(UINT nState, BOOL fMinimized, HWND opposite);
duke@0 168 virtual MsgRouting WmCreate();
duke@0 169 virtual MsgRouting WmClose();
duke@0 170 virtual MsgRouting WmDestroy();
duke@0 171 virtual MsgRouting WmShowWindow(BOOL show, UINT status);
duke@0 172 virtual MsgRouting WmGetMinMaxInfo(LPMINMAXINFO lpmmi);
duke@0 173 virtual MsgRouting WmMove(int x, int y);
duke@0 174 virtual MsgRouting WmSize(UINT type, int w, int h);
duke@0 175 virtual MsgRouting WmSizing();
duke@0 176 virtual MsgRouting WmPaint(HDC hDC);
duke@0 177 virtual MsgRouting WmSettingChange(UINT wFlag, LPCTSTR pszSection);
duke@0 178 virtual MsgRouting WmNcCalcSize(BOOL fCalcValidRects,
duke@0 179 LPNCCALCSIZE_PARAMS lpncsp, LRESULT& retVal);
duke@0 180 virtual MsgRouting WmNcHitTest(UINT x, UINT y, LRESULT& retVal);
duke@0 181 virtual MsgRouting WmNcMouseDown(WPARAM hitTest, int x, int y, int button);
duke@0 182 virtual MsgRouting WmGetIcon(WPARAM iconType, LRESULT& retVal);
duke@0 183 virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam);
duke@0 184 virtual MsgRouting WmWindowPosChanging(LPARAM windowPos);
duke@0 185 virtual MsgRouting WmWindowPosChanged(LPARAM windowPos);
anthony@1066 186 virtual MsgRouting WmTimer(UINT_PTR timerID);
duke@0 187
duke@0 188 virtual MsgRouting HandleEvent(MSG *msg, BOOL synthetic);
duke@0 189 virtual void WindowResized();
duke@0 190
ant@1058 191 static jboolean _RequestWindowFocus(void *param);
ant@1058 192
ant@1058 193 virtual BOOL AwtSetActiveWindow(BOOL isMouseEventCause = FALSE, UINT hittest = HTCLIENT);
ant@1058 194
ant@1058 195 // Execute on Toolkit only.
ant@1058 196 INLINE static LRESULT SynthesizeWmActivate(BOOL doActivate, HWND targetHWnd, HWND oppositeHWnd) {
ant@6621 197 AwtWindow *win = static_cast<AwtWindow*>(AwtComponent::GetComponent(targetHWnd));
ant@2698 198 if (doActivate &&
ant@6621 199 (!::IsWindowVisible(targetHWnd) || ::IsIconic(::GetAncestor(targetHWnd, GA_ROOT))) &&
ant@6621 200 (win == NULL || !win->IsLightweightFrame()))
ant@2698 201 {
ant@2698 202 // The activation is rejected if either:
ant@2698 203 // - The toplevel is not visible
ant@2698 204 // - The toplevel (or its embedder) is minimised
ant@2698 205 return 1;
ant@1058 206 }
ant@2698 207 return ::SendMessage(targetHWnd, WM_ACTIVATE,
ant@2698 208 MAKEWPARAM(doActivate ? WA_ACTIVE : WA_INACTIVE, FALSE),
ant@2698 209 (LPARAM) oppositeHWnd);
ant@1058 210 }
ant@1058 211
duke@0 212 void moveToDefaultLocation(); /* moves Window to X,Y specified by Window Manger */
duke@0 213
art@1045 214 void UpdateWindow(JNIEnv* env, jintArray data, int width, int height,
art@1045 215 HBITMAP hNewBitmap = NULL);
art@1045 216
duke@0 217 INLINE virtual BOOL IsTopLevel() { return TRUE; }
duke@0 218 static AwtWindow * GetGrabbedWindow() { return m_grabbedWindow; }
duke@0 219
duke@0 220 static void FlashWindowEx(HWND hWnd, UINT count, DWORD timeout, DWORD flags);
duke@0 221
duke@0 222 // some methods invoked on Toolkit thread
duke@0 223 static void _ToFront(void *param);
duke@0 224 static void _ToBack(void *param);
duke@0 225 static void _Grab(void *param);
duke@0 226 static void _Ungrab(void *param);
duke@0 227 static void _SetAlwaysOnTop(void *param);
duke@0 228 static void _SetTitle(void *param);
duke@0 229 static void _SetResizable(void *param);
duke@0 230 static void _UpdateInsets(void *param);
duke@0 231 static void _ReshapeFrame(void *param);
duke@0 232 static void _SetIconImagesData(void * param);
duke@0 233 static void _SetMinSize(void* param);
duke@0 234 static jint _GetScreenImOn(void *param);
duke@0 235 static void _SetFocusableWindow(void *param);
duke@0 236 static void _SetModalExcludedNativeProp(void *param);
duke@0 237 static void _ModalDisable(void *param);
duke@0 238 static void _ModalEnable(void *param);
art@1045 239 static void _SetOpacity(void* param);
art@1045 240 static void _SetOpaque(void* param);
art@1045 241 static void _UpdateWindow(void* param);
anthony@1066 242 static void _RepositionSecurityWarning(void* param);
anthony@1890 243 static void _SetFullScreenExclusiveModeState(void* param);
alexsch@13220 244 static void _GetNativeWindowSize(void* param);
duke@0 245
duke@0 246 inline static BOOL IsResizing() {
duke@0 247 return sm_resizing;
duke@0 248 }
duke@0 249
anthony@1066 250 virtual void CreateHWnd(JNIEnv *env, LPCWSTR title,
anthony@1066 251 DWORD windowStyle, DWORD windowExStyle,
anthony@1066 252 int x, int y, int w, int h,
anthony@1066 253 HWND hWndParent, HMENU hMenu,
anthony@1066 254 COLORREF colorForeground, COLORREF colorBackground,
anthony@1066 255 jobject peer);
anthony@1066 256 virtual void DestroyHWnd();
anthony@1066 257
anthony@1066 258 static void FocusedWindowChanged(HWND from, HWND to);
anthony@1066 259
duke@0 260 private:
duke@0 261 static int ms_instanceCounter;
duke@0 262 static HHOOK ms_hCBTFilter;
duke@0 263 static LRESULT CALLBACK CBTFilter(int nCode, WPARAM wParam, LPARAM lParam);
duke@0 264 static BOOL sm_resizing; /* in the middle of a resizing operation */
duke@0 265
duke@0 266 RECT m_insets; /* a cache of the insets being used */
duke@0 267 RECT m_old_insets; /* help determine if insets change */
duke@0 268 POINT m_sizePt; /* the last value of WM_SIZE */
duke@0 269 RECT m_warningRect; /* The window's warning banner area, if any. */
duke@0 270 AwtFrame *m_owningFrameDialog; /* The nearest Frame/Dialog which owns us */
duke@0 271 BOOL m_isFocusableWindow; /* a cache of Window.isFocusableWindow() return value */
duke@0 272 POINT m_minSize; /* Minimum size of the window for WM_GETMINMAXINFO message */
duke@0 273 BOOL m_grabbed; // Whether the current window is grabbed
duke@0 274 BOOL m_isRetainingHierarchyZOrder; // Is this a window that shouldn't change z-order of any window
duke@0 275 // from its hierarchy when shown. Currently applied to instances of
duke@0 276 // javax/swing/Popup$HeavyWeightWindow class.
duke@0 277
anthony@1614 278 // SetTranslucency() is the setter for the following two fields
art@1045 279 BYTE m_opacity; // The opacity level. == 0xff by default (when opacity mode is disabled)
art@1045 280 BOOL m_opaque; // Whether the window uses the perpixel translucency (false), or not (true).
art@1045 281
art@1045 282 inline BYTE getOpacity() {
art@1045 283 return m_opacity;
art@1045 284 }
art@1045 285
art@1045 286 inline BOOL isOpaque() {
art@1045 287 return m_opaque;
art@1045 288 }
art@1045 289
art@1045 290 CRITICAL_SECTION contentBitmapCS;
art@1045 291 HBITMAP hContentBitmap;
art@1045 292 UINT contentWidth;
art@1045 293 UINT contentHeight;
art@1045 294
anthony@1614 295 void SetTranslucency(BYTE opacity, BOOL opaque, BOOL setValues = TRUE,
anthony@1614 296 BOOL useDefaultForOldValues = FALSE);
anthony@1066 297 void UpdateWindow(int width, int height, HBITMAP hBitmap);
anthony@1066 298 void UpdateWindowImpl(int width, int height, HBITMAP hBitmap);
art@1045 299 void RedrawWindow();
anthony@1614 300 void DeleteContentBitmap();
anthony@1066 301
anthony@1066 302 static UINT untrustedWindowsCounter;
anthony@1066 303
anthony@1066 304 WCHAR * warningString;
anthony@1066 305
anthony@1066 306 // The warning icon
anthony@1066 307 HWND warningWindow;
anthony@1066 308 // The tooltip that appears when hovering the icon
anthony@1066 309 HWND securityTooltipWindow;
anthony@1066 310
anthony@1066 311 UINT warningWindowWidth;
anthony@1066 312 UINT warningWindowHeight;
anthony@1066 313 void InitSecurityWarningSize(JNIEnv *env);
anthony@1066 314 HICON GetSecurityWarningIcon();
anthony@1066 315
anthony@1066 316 void CreateWarningWindow(JNIEnv *env);
anthony@1066 317 void DestroyWarningWindow();
anthony@1066 318 static LPCTSTR GetWarningWindowClassName();
anthony@1066 319 void FillWarningWindowClassInfo(WNDCLASS *lpwc);
anthony@1066 320 void RegisterWarningWindowClass();
anthony@1066 321 void UnregisterWarningWindowClass();
anthony@1066 322 static LRESULT CALLBACK WarningWindowProc(
anthony@1066 323 HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
anthony@1066 324
anthony@1066 325 static void PaintWarningWindow(HWND warningWindow);
anthony@1066 326 static void PaintWarningWindow(HWND warningWindow, HDC hdc);
anthony@1066 327 void RepaintWarningWindow();
anthony@1066 328 void CalculateWarningWindowBounds(JNIEnv *env, LPRECT rect);
anthony@1066 329
anthony@1066 330 void AnimateSecurityWarning(bool enable);
anthony@1066 331 UINT securityWarningAnimationStage;
anthony@1066 332
anthony@1066 333 enum AnimationKind {
anthony@1066 334 akNone, akShow, akPreHide, akHide
anthony@1066 335 };
anthony@1066 336
anthony@1066 337 AnimationKind securityAnimationKind;
anthony@1066 338
anthony@1066 339 void StartSecurityAnimation(AnimationKind kind);
anthony@1066 340 void StopSecurityAnimation();
anthony@1066 341
anthony@1066 342 void RepositionSecurityWarning(JNIEnv *env);
anthony@1066 343
anthony@1496 344 static void SetLayered(HWND window, bool layered);
anthony@1496 345 static bool IsLayered(HWND window);
anthony@1496 346
anthony@1890 347 BOOL fullScreenExclusiveModeState;
anthony@1890 348 inline void setFullScreenExclusiveModeState(BOOL isEntered) {
anthony@1890 349 fullScreenExclusiveModeState = isEntered;
anthony@1890 350 UpdateSecurityWarningVisibility();
anthony@1890 351 }
anthony@1890 352 inline BOOL isFullScreenExclusiveMode() {
anthony@1890 353 return fullScreenExclusiveModeState;
anthony@1890 354 }
anthony@1890 355
anthony@1890 356
anthony@1066 357 public:
anthony@1066 358 void UpdateSecurityWarningVisibility();
anthony@1066 359 static bool IsWarningWindow(HWND hWnd);
art@1045 360
duke@0 361 protected:
duke@0 362 BOOL m_isResizable;
duke@0 363 static AwtWindow* m_grabbedWindow; // Current grabbing window
duke@0 364 HICON m_hIcon; /* Icon for this window. It can be set explicitely or inherited from the owner */
duke@0 365 HICON m_hIconSm; /* Small icon for this window. It can be set explicitely or inherited from the owner */
duke@0 366 BOOL m_iconInherited; /* TRUE if icon is inherited from the owner */
duke@0 367 BOOL m_filterFocusAndActivation; /* Used in the WH_CBT hook */
duke@0 368
anthony@1066 369 inline BOOL IsUntrusted() {
anthony@1066 370 return warningString != NULL;
anthony@1066 371 }
anthony@1066 372
anthony@1066 373 UINT currentWmSizeState;
anthony@1066 374
anthony@1614 375 void EnableTranslucency(BOOL enable);
anthony@1614 376
anthony@1971 377 // Native representation of the java.awt.Window.Type enum
anthony@1971 378 enum Type {
anthony@1971 379 NORMAL, UTILITY, POPUP
anthony@1971 380 };
anthony@1971 381
anthony@1971 382 inline Type GetType() { return m_windowType; }
anthony@1971 383
duke@0 384 private:
duke@0 385 int m_screenNum;
duke@0 386
duke@0 387 void InitOwner(AwtWindow *owner);
anthony@1971 388
anthony@1971 389 Type m_windowType;
anthony@1971 390 void InitType(JNIEnv *env, jobject peer);
anthony@1971 391
anthony@1971 392 // Tweak the style according to the type of the window
anthony@1971 393 void TweakStyle(DWORD & style, DWORD & exStyle);
anthony@1971 394
anthony@1980 395 // Set in _SetAlwaysOnTop()
anthony@1980 396 bool m_alwaysOnTop;
anthony@1980 397 public:
anthony@1980 398 inline bool IsAlwaysOnTop() { return m_alwaysOnTop; }
duke@0 399 };
duke@0 400
duke@0 401 #endif /* AWT_WINDOW_H */