rev 60071 : 8211999: Window positioning bugs due to overlapping GraphicsDevice bounds (Windows/HiDPI)
Reviewed-by: XXX

   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_COMPONENT_H
  27 #define AWT_COMPONENT_H
  28 
  29 #include "awtmsg.h"
  30 #include "awt_Object.h"
  31 #include "awt_Font.h"
  32 #include "awt_Brush.h"
  33 #include "awt_Pen.h"
  34 #include "awt_Win32GraphicsDevice.h"
  35 #include "GDIWindowSurfaceData.h"
  36 
  37 #include "java_awt_Component.h"
  38 #include "sun_awt_windows_WComponentPeer.h"
  39 #include "java_awt_event_KeyEvent.h"
  40 #include "java_awt_event_MouseEvent.h"
  41 #include "java_awt_event_WindowEvent.h"
  42 #include "java_awt_Dimension.h"
  43 
  44 extern LPCTSTR szAwtComponentClassName;
  45 
  46 static LPCTSTR DrawingStateProp = TEXT("SunAwtDrawingStateProp");
  47 
  48 const UINT IGNORE_KEY = (UINT)-1;
  49 const UINT MAX_ACP_STR_LEN = 7; // ANSI CP identifiers are no longer than this
  50 
  51 #define LEFT_BUTTON 1
  52 #define MIDDLE_BUTTON 2
  53 #define RIGHT_BUTTON 4
  54 #define DBL_CLICK 8
  55 #define X1_BUTTON 16
  56 #define X2_BUTTON 32
  57 
  58 #ifndef MK_XBUTTON1
  59 #define MK_XBUTTON1         0x0020
  60 #endif
  61 
  62 #ifndef MK_XBUTTON2
  63 #define MK_XBUTTON2         0x0040
  64 #endif
  65 
  66 // combination of standard mouse button flags
  67 const int ALL_MK_BUTTONS = MK_LBUTTON|MK_MBUTTON|MK_RBUTTON;
  68 const int X_BUTTONS = MK_XBUTTON1|MK_XBUTTON2;
  69 
  70 // The allowable difference between coordinates of the WM_TOUCH event and the
  71 // corresponding WM_LBUTTONDOWN/WM_LBUTTONUP event letting to associate these
  72 // events, when their coordinates are slightly different.
  73 const int TOUCH_MOUSE_COORDS_DELTA = 10;
  74 
  75 // Whether to check for embedded frame and adjust location
  76 #define CHECK_EMBEDDED 0
  77 #define DONT_CHECK_EMBEDDED 1
  78 
  79 class AwtPopupMenu;
  80 
  81 class AwtDropTarget;
  82 
  83 /*
  84  * Message routing codes
  85  */
  86 enum MsgRouting {
  87     mrPassAlong,    /* pass along to next in chain */
  88     mrDoDefault,    /* skip right to underlying default behavior */
  89     mrConsume,      /* consume msg & terminate routing immediatly,
  90                      * don't pass anywhere
  91                      */
  92 };
  93 
  94 /************************************************************************
  95  * AwtComponent class
  96  */
  97 
  98 class AwtComponent : public AwtObject {
  99 public:
 100     /* java.awt.Component fields and method IDs */
 101     static jfieldID peerID;
 102     static jfieldID xID;
 103     static jfieldID yID;
 104     static jfieldID widthID;
 105     static jfieldID heightID;
 106     static jfieldID visibleID;
 107     static jfieldID backgroundID;
 108     static jfieldID foregroundID;
 109     static jfieldID enabledID;
 110     static jfieldID parentID;
 111     static jfieldID cursorID;
 112     static jfieldID graphicsConfigID;
 113     static jfieldID peerGCID;
 114     static jfieldID focusableID;
 115     static jfieldID appContextID;
 116     static jfieldID hwndID;
 117 
 118     static jmethodID getFontMID;
 119     static jmethodID getToolkitMID;
 120     static jmethodID isEnabledMID;
 121     static jmethodID getLocationOnScreenMID;
 122     static jmethodID replaceSurfaceDataMID;
 123     static jmethodID replaceSurfaceDataLaterMID;
 124     static jmethodID disposeLaterMID;
 125 
 126     static const UINT WmAwtIsComponent;
 127     static jint * masks; //InputEvent mask array
 128     AwtComponent();
 129     virtual ~AwtComponent();
 130 
 131     /*
 132      * Dynamic class registration & creation
 133      */
 134     virtual LPCTSTR GetClassName() = 0;
 135     /*
 136      * Fix for 4964237: Win XP: Changing theme changes java dialogs title icon
 137      * WNDCLASS structure has been superseded by the WNDCLASSEX in Win32
 138      */
 139     virtual void FillClassInfo(WNDCLASSEX *lpwc);
 140     virtual void RegisterClass();
 141     virtual void UnregisterClass();
 142 
 143     virtual void CreateHWnd(JNIEnv *env, LPCWSTR title,
 144                     DWORD windowStyle, DWORD windowExStyle,
 145                     int x, int y, int w, int h,
 146                     HWND hWndParent, HMENU hMenu,
 147                     COLORREF colorForeground, COLORREF colorBackground,
 148                     jobject peer);
 149     virtual void DestroyHWnd();
 150     void InitPeerGraphicsConfig(JNIEnv *env, jobject peer);
 151 
 152     virtual void Dispose();
 153 
 154     void UpdateBackground(JNIEnv *env, jobject target);
 155 
 156     virtual void SubclassHWND();
 157     virtual void UnsubclassHWND();
 158 
 159     static LRESULT CALLBACK WndProc(HWND hWnd, UINT message,
 160         WPARAM wParam, LPARAM lParam);
 161 
 162     /*
 163      * Access to the various objects of this aggregate component
 164      */
 165     INLINE HWND GetHWnd() { return m_hwnd; }
 166     INLINE void SetHWnd(HWND hwnd) { m_hwnd = hwnd; }
 167 
 168     static AwtComponent* GetComponent(HWND hWnd);
 169 
 170     /*
 171      * Access to the properties of the component
 172      */
 173     INLINE COLORREF GetColor() { return m_colorForeground; }
 174     virtual void SetColor(COLORREF c);
 175     HPEN GetForegroundPen();
 176 
 177     COLORREF GetBackgroundColor();
 178     virtual void SetBackgroundColor(COLORREF c);
 179     HBRUSH GetBackgroundBrush();
 180     INLINE BOOL IsBackgroundColorSet() { return m_backgroundColorSet; }
 181 
 182     virtual void SetFont(AwtFont *pFont);
 183 
 184     INLINE void SetText(LPCTSTR text) { ::SetWindowText(GetHWnd(), text); }
 185     INLINE int GetText(LPTSTR buffer, int size) {
 186         return ::GetWindowText(GetHWnd(), buffer, size);
 187     }
 188     INLINE int GetTextLength() { return ::GetWindowTextLength(GetHWnd()); }
 189 
 190     virtual void GetInsets(RECT* rect) {
 191         VERIFY(::SetRectEmpty(rect));
 192     }
 193 
 194     BOOL IsVisible() { return m_visible;};
 195 
 196     HDC GetDCFromComponent();
 197 
 198     /*
 199      * Enable/disable component
 200      */
 201     virtual void Enable(BOOL bEnable);
 202 
 203     /*
 204      * Validate and call handleExpose on rects of UpdateRgn
 205      */
 206     void PaintUpdateRgn(const RECT *insets);
 207 
 208     static HWND GetTopLevelParentForWindow(HWND hwndDescendant);
 209 
 210     static jobject FindHeavyweightUnderCursor(BOOL useCache);
 211 
 212     /*
 213      * Returns the parent component.  If no parent window, or the
 214      * parent window isn't an AwtComponent, returns NULL.
 215      */
 216     AwtComponent* GetParent();
 217 
 218     /* Get the component's immediate container. Note: may return NULL while
 219        the component is being reparented in full-screen mode by Direct3D */
 220     class AwtWindow* GetContainer();
 221 
 222     /* Is a component a container? Used by above method */
 223     virtual BOOL IsContainer() { return FALSE;} // Plain components can't
 224 
 225     /**
 226      * Returns TRUE if this message will trigger native focus change, FALSE otherwise.
 227      */
 228     virtual BOOL IsFocusingKeyMessage(MSG *pMsg);
 229     virtual BOOL IsFocusingMouseMessage(MSG *pMsg);
 230 
 231     BOOL IsFocusable();
 232 
 233     /*
 234      * Returns an increasing unsigned value used for child control IDs.
 235      * There is no attempt to reclaim command ID's.
 236      */
 237     INLINE UINT CreateControlID() { return m_nextControlID++; }
 238 
 239     // returns the current keyboard layout
 240     INLINE static HKL GetKeyboardLayout() {
 241         return m_hkl;
 242     }
 243 
 244     // returns the current code page that should be used in
 245     // all MultiByteToWideChar and WideCharToMultiByte calls.
 246     // This code page should also be use in IsDBCSLeadByteEx.
 247     INLINE static UINT GetCodePage()
 248     {
 249         return m_CodePage;
 250     }
 251 
 252 // Added by waleed for BIDI Support
 253     // returns the right to left status
 254     INLINE static BOOL GetRTLReadingOrder() {
 255         return sm_rtlReadingOrder;
 256     }
 257     // returns the right to left status
 258     INLINE static BOOL GetRTL() {
 259         return sm_rtl;
 260     }
 261     // returns the current sub language
 262     INLINE static LANGID GetSubLanguage() {
 263         return SUBLANGID(m_idLang);
 264     }
 265 // end waleed
 266 
 267     // returns the current input language
 268     INLINE static LANGID GetInputLanguage()
 269     {
 270         return m_idLang;
 271     }
 272     // Convert Language ID to CodePage
 273     static UINT LangToCodePage(LANGID idLang);
 274 
 275     /*
 276      * methods on this component
 277      */
 278     virtual int GetScreenImOn();
 279     virtual void Show();
 280     virtual void Hide();
 281     virtual void Reshape(int x, int y, int w, int h);
 282     void ReshapeNoScale(int x, int y, int w, int h);
 283 
 284     /*
 285      * Fix for 4046446.
 286      * Component size/position helper, for the values above the short int limit.
 287      */
 288     static BOOL SetWindowPos(HWND wnd, HWND after,
 289                              int x, int y, int w, int h, UINT flags);
 290 
 291     /*
 292      * Sets the scrollbar values.  'bar' can be either SB_VERT or
 293      * SB_HORZ.  'min', 'value', and 'max' can have the value INT_MAX
 294      * which means that the value should not be changed.
 295      */
 296     void SetScrollValues(UINT bar, int min, int value, int max);
 297 
 298     INLINE LRESULT SendMessage(UINT msg, WPARAM wParam=0, LPARAM lParam=0) {
 299         DASSERT(GetHWnd());
 300         return ::SendMessage(GetHWnd(), msg, wParam, lParam);
 301     }
 302 
 303     void PostUngrabEvent();
 304 
 305     INLINE virtual LONG GetStyle() {
 306         DASSERT(GetHWnd());
 307         return ::GetWindowLong(GetHWnd(), GWL_STYLE);
 308     }
 309     INLINE virtual void SetStyle(LONG style) {
 310         DASSERT(GetHWnd());
 311         // SetWindowLong() error handling as recommended by Win32 API doc.
 312         ::SetLastError(0);
 313         DWORD ret = ::SetWindowLong(GetHWnd(), GWL_STYLE, style);
 314         DASSERT(ret != 0 || ::GetLastError() == 0);
 315     }
 316     INLINE virtual LONG GetStyleEx() {
 317         DASSERT(GetHWnd());
 318         return ::GetWindowLong(GetHWnd(), GWL_EXSTYLE);
 319     }
 320     INLINE virtual void SetStyleEx(LONG style) {
 321         DASSERT(GetHWnd());
 322         // SetWindowLong() error handling as recommended by Win32 API doc.
 323         ::SetLastError(0);
 324         DWORD ret = ::SetWindowLong(GetHWnd(), GWL_EXSTYLE, style);
 325         DASSERT(ret != 0 || ::GetLastError() == 0);
 326     }
 327 
 328     virtual BOOL NeedDblClick() { return FALSE; }
 329 
 330     /* for multifont component */
 331     static void DrawWindowText(HDC hDC, jobject font, jstring text,
 332                                int x, int y);
 333     static void DrawGrayText(HDC hDC, jobject font, jstring text,
 334                              int x, int y);
 335 
 336     void DrawListItem(JNIEnv *env, DRAWITEMSTRUCT &drawInfo);
 337 
 338     void MeasureListItem(JNIEnv *env, MEASUREITEMSTRUCT &measureInfo);
 339 
 340     jstring GetItemString(JNIEnv *env, jobject target, jint index);
 341 
 342     jint GetFontHeight(JNIEnv *env);
 343 
 344     virtual jobject PreferredItemSize(JNIEnv *env) {DASSERT(FALSE); return NULL; }
 345 
 346     INLINE BOOL isEnabled() {
 347         JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
 348         if (env->EnsureLocalCapacity(2) < 0) {
 349             return NULL;
 350         }
 351         jobject self = GetPeer(env);
 352         jobject target = env->GetObjectField(self, AwtObject::targetID);
 353         BOOL e = env->CallBooleanMethod(target, AwtComponent::isEnabledMID);
 354         DASSERT(!safe_ExceptionOccurred(env));
 355 
 356         env->DeleteLocalRef(target);
 357 
 358         return e;
 359     }
 360 
 361     INLINE BOOL isRecursivelyEnabled() {
 362         AwtComponent* p = this;
 363         do {
 364             if (!p->isEnabled()) {
 365                 return FALSE;
 366             }
 367         } while (!p->IsTopLevel() &&
 368             (p = p->GetParent()) != NULL);
 369         return TRUE;
 370     }
 371 
 372     void SendKeyEventToFocusOwner(jint id, jlong when, jint raw, jint cooked,
 373                                   jint modifiers, jint keyLocation, jlong nativeCode,
 374                                   MSG *msg = NULL);
 375     /*
 376      * Allocate and initialize a new java.awt.event.KeyEvent, and
 377      * post it to the peer's target object.  No response is expected
 378      * from the target.
 379      */
 380     void SendKeyEvent(jint id, jlong when, jint raw, jint cooked,
 381                       jint modifiers, jint keyLocation, jlong nativeCode,
 382                       MSG *msg = NULL);
 383 
 384     /*
 385      * Allocate and initialize a new java.awt.event.MouseEvent, and
 386      * post it to the peer's target object.  No response is expected
 387      * from the target.
 388      */
 389     void SendMouseEvent(jint id, jlong when, jint x, jint y,
 390                         jint modifiers, jint clickCount,
 391                         jboolean popupTrigger, jint button = 0,
 392                         MSG *msg = NULL, BOOL causedByTouchEvent = FALSE);
 393 
 394     /*
 395      * Allocate and initialize a new java.awt.event.MouseWheelEvent, and
 396      * post it to the peer's target object.  No response is expected
 397      * from the target.
 398      */
 399     void SendMouseWheelEvent(jint id, jlong when, jint x, jint y,
 400                              jint modifiers, jint clickCount,
 401                              jboolean popupTrigger, jint scrollType,
 402                              jint scrollAmount, jint wheelRotation,
 403                              jdouble preciseWheelRotation, MSG *msg = NULL);
 404 
 405     /*
 406      * Allocate and initialize a new java.awt.event.FocusEvent, and
 407      * post it to the peer's target object.  No response is expected
 408      * from the target.
 409      */
 410     void SendFocusEvent(jint id, HWND opposite);
 411 
 412     /* Forward a filtered event directly to the subclassed window.
 413        synthetic should be TRUE iff the message was generated because
 414        of a synthetic Java event, rather than a native event. */
 415     virtual MsgRouting HandleEvent(MSG *msg, BOOL synthetic);
 416 
 417     /* Post a WM_AWT_HANDLE_EVENT message which invokes HandleEvent
 418        on the toolkit thread. This method may pre-filter the messages. */
 419     virtual BOOL PostHandleEventMessage(MSG *msg, BOOL synthetic);
 420 
 421     /* Event->message synthesizer methods. */
 422     void SynthesizeKeyMessage(JNIEnv *env, jobject keyEvent);
 423     void SynthesizeMouseMessage(JNIEnv *env, jobject mouseEvent);
 424 
 425     /* Components which inherit native mouse wheel behavior will
 426      * return TRUE.  These are TextArea, Choice, FileDialog, and
 427      * List.  All other Components return FALSE.
 428      */
 429     virtual BOOL InheritsNativeMouseWheelBehavior();
 430 
 431     /* Determines whether the component is obscured by another window */
 432     // Called on Toolkit thread
 433     static jboolean _IsObscured(void *param);
 434 
 435     /* Invalidate the specified rectangle. */
 436     virtual void Invalidate(RECT* r);
 437 
 438     /* Begin and end deferred window positioning. */
 439     virtual void BeginValidate();
 440     virtual void EndValidate();
 441 
 442     /* Keyboard conversion routines. */
 443     static void InitDynamicKeyMapTable();
 444     static void BuildDynamicKeyMapTable();
 445     static jint GetJavaModifiers();
 446     static jint GetActionModifiers();
 447     static jint GetButton(int mouseButton);
 448     static UINT GetButtonMK(int mouseButton);
 449     static UINT WindowsKeyToJavaKey(UINT windowsKey, UINT modifiers, UINT character, BOOL isDeadKey);
 450     static void JavaKeyToWindowsKey(UINT javaKey, UINT *windowsKey, UINT *modifiers, UINT originalWindowsKey);
 451     static void UpdateDynPrimaryKeymap(UINT wkey, UINT jkeyLegacy, jint keyLocation, UINT modifiers);
 452 
 453     INLINE static void JavaKeyToWindowsKey(UINT javaKey,
 454                                        UINT *windowsKey, UINT *modifiers)
 455     {
 456         JavaKeyToWindowsKey(javaKey, windowsKey, modifiers, IGNORE_KEY);
 457     }
 458 
 459     enum TransOps {NONE, LOAD, SAVE};
 460 
 461     UINT WindowsKeyToJavaChar(UINT wkey, UINT modifiers, TransOps ops, BOOL &isDeadKey);
 462 
 463     /* routines used for input method support */
 464     void SetInputMethod(jobject im, BOOL useNativeCompWindow);
 465     void SendInputMethodEvent(jint id, jstring text, int cClause,
 466                               int *rgClauseBoundary, jstring *rgClauseReading,
 467                               int cAttrBlock, int *rgAttrBoundary,
 468                               BYTE *rgAttrValue, int commitedTextLength,
 469                               int caretPos, int visiblePos);
 470     void InquireCandidatePosition();
 471     INLINE LPARAM GetCandidateType() { return m_bitsCandType; }
 472     HWND ImmGetHWnd();
 473     HIMC ImmAssociateContext(HIMC himc);
 474     HWND GetProxyFocusOwner();
 475 
 476     INLINE HWND GetProxyToplevelContainer() {
 477         HWND proxyHWnd = GetProxyFocusOwner();
 478         return ::GetAncestor(proxyHWnd, GA_ROOT); // a browser in case of EmbeddedFrame
 479     }
 480 
 481     void CallProxyDefWindowProc(UINT message,
 482                                 WPARAM wParam,
 483                                 LPARAM lParam,
 484                                 LRESULT &retVal,
 485                                 MsgRouting &mr);
 486 
 487     /*
 488      * Windows message handler functions
 489      */
 490     virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam);
 491     virtual LRESULT DefWindowProc(UINT msg, WPARAM wParam, LPARAM lParam);
 492 
 493     /* return true if msg is processed */
 494     virtual MsgRouting PreProcessMsg(MSG& msg);
 495 
 496     virtual MsgRouting WmCreate() {return mrDoDefault;}
 497     virtual MsgRouting WmClose() {return mrDoDefault;}
 498     virtual MsgRouting WmDestroy();
 499     virtual MsgRouting WmNcDestroy();
 500 
 501     virtual MsgRouting WmActivate(UINT nState, BOOL fMinimized, HWND opposite)
 502     {
 503         return mrDoDefault;
 504     }
 505 
 506     virtual MsgRouting WmEraseBkgnd(HDC hDC, BOOL& didErase)
 507     {
 508         return mrDoDefault;
 509     }
 510 
 511     virtual MsgRouting WmPaint(HDC hDC);
 512     virtual MsgRouting WmGetMinMaxInfo(LPMINMAXINFO lpmmi);
 513     virtual MsgRouting WmMove(int x, int y);
 514     virtual MsgRouting WmSize(UINT type, int w, int h);
 515     virtual MsgRouting WmSizing();
 516     virtual MsgRouting WmShowWindow(BOOL show, UINT status);
 517     virtual MsgRouting WmSetFocus(HWND hWndLost);
 518     virtual MsgRouting WmKillFocus(HWND hWndGot);
 519     virtual MsgRouting WmCtlColor(HDC hDC, HWND hCtrl,
 520                                   UINT ctlColor, HBRUSH& retBrush);
 521     virtual MsgRouting WmHScroll(UINT scrollCode, UINT pos, HWND hScrollBar);
 522     virtual MsgRouting WmVScroll(UINT scrollCode, UINT pos, HWND hScrollBar);
 523 
 524     virtual MsgRouting WmMouseEnter(UINT flags, int x, int y);
 525     virtual MsgRouting WmMouseDown(UINT flags, int x, int y, int button);
 526     virtual MsgRouting WmMouseUp(UINT flags, int x, int y, int button);
 527     virtual MsgRouting WmMouseMove(UINT flags, int x, int y);
 528     virtual MsgRouting WmMouseExit(UINT flags, int x, int y);
 529     virtual MsgRouting WmMouseWheel(UINT flags, int x, int y,
 530                                     int wheelRotation, BOOL isHorizontal);
 531     virtual MsgRouting WmNcMouseDown(WPARAM hitTest, int x, int y, int button);
 532     virtual MsgRouting WmNcMouseUp(WPARAM hitTest, int x, int y, int button);
 533     virtual MsgRouting WmWindowPosChanging(LPARAM windowPos);
 534     virtual MsgRouting WmWindowPosChanged(LPARAM windowPos);
 535     virtual void WmTouch(WPARAM wParam, LPARAM lParam);
 536 
 537     // NB: 64-bit: vkey is wParam of the message, but other API's take
 538     // vkey parameters of type UINT, so we do the cast before dispatching.
 539     virtual MsgRouting WmKeyDown(UINT vkey, UINT repCnt, UINT flags, BOOL system);
 540     virtual MsgRouting WmKeyUp(UINT vkey, UINT repCnt, UINT flags, BOOL system);
 541 
 542     virtual MsgRouting WmChar(UINT character, UINT repCnt, UINT flags, BOOL system);
 543     virtual MsgRouting WmIMEChar(UINT character, UINT repCnt, UINT flags, BOOL system);
 544     virtual MsgRouting WmInputLangChange(UINT charset, HKL hKeyBoardLayout);
 545     virtual MsgRouting WmForwardChar(WCHAR character, LPARAM lParam,
 546                                      BOOL synthethic);
 547     virtual MsgRouting WmPaste();
 548 
 549     virtual void SetCompositionWindow(RECT &r);
 550     virtual void OpenCandidateWindow(int x, int y);
 551     virtual void SetCandidateWindow(int iCandType, int x, int y);
 552     virtual MsgRouting WmImeSetContext(BOOL fSet, LPARAM *lplParam);
 553     virtual MsgRouting WmImeNotify(WPARAM subMsg, LPARAM bitsCandType);
 554     virtual MsgRouting WmImeStartComposition();
 555     virtual MsgRouting WmImeEndComposition();
 556     virtual MsgRouting WmImeComposition(WORD wChar, LPARAM flags);
 557 
 558     virtual MsgRouting WmTimer(UINT_PTR timerID) {return mrDoDefault;}
 559 
 560     virtual MsgRouting WmCommand(UINT id, HWND hWndCtrl, UINT notifyCode);
 561 
 562     /* reflected WmCommand from parent */
 563     virtual MsgRouting WmNotify(UINT notifyCode);
 564 
 565     virtual MsgRouting WmCompareItem(UINT /*ctrlId*/,
 566                                      COMPAREITEMSTRUCT &compareInfo,
 567                                      LRESULT &result);
 568     virtual MsgRouting WmDeleteItem(UINT /*ctrlId*/,
 569                                     DELETEITEMSTRUCT &deleteInfo);
 570     virtual MsgRouting WmDrawItem(UINT ctrlId,
 571                                   DRAWITEMSTRUCT &drawInfo);
 572     virtual MsgRouting WmMeasureItem(UINT ctrlId,
 573                                      MEASUREITEMSTRUCT &measureInfo);
 574     /* Fix 4181790 & 4223341 : These functions get overridden in owner-drawn
 575      * components instead of the Wm... versions.
 576      */
 577     virtual MsgRouting OwnerDrawItem(UINT ctrlId,
 578                                      DRAWITEMSTRUCT &drawInfo);
 579     virtual MsgRouting OwnerMeasureItem(UINT ctrlId,
 580                                         MEASUREITEMSTRUCT &measureInfo);
 581 
 582     virtual MsgRouting WmPrint(HDC hDC, LPARAM flags);
 583     virtual MsgRouting WmPrintClient(HDC hDC, LPARAM flags);
 584 
 585     virtual MsgRouting WmNcCalcSize(BOOL fCalcValidRects,
 586                                     LPNCCALCSIZE_PARAMS lpncsp,
 587                                     LRESULT &retVal);
 588     virtual MsgRouting WmNcPaint(HRGN hrgn);
 589     virtual MsgRouting WmNcHitTest(UINT x, UINT y, LRESULT &retVal);
 590     virtual MsgRouting WmSysCommand(UINT uCmdType, int xPos, int yPos);
 591     virtual MsgRouting WmEnterSizeMove();
 592     virtual MsgRouting WmExitSizeMove();
 593     virtual MsgRouting WmEnterMenuLoop(BOOL isTrackPopupMenu);
 594     virtual MsgRouting WmExitMenuLoop(BOOL isTrackPopupMenu);
 595 
 596     virtual MsgRouting WmQueryNewPalette(LRESULT &retVal);
 597     virtual MsgRouting WmPaletteChanged(HWND hwndPalChg);
 598     virtual MsgRouting WmPaletteIsChanging(HWND hwndPalChg);
 599     virtual MsgRouting WmStyleChanged(int wStyleType, LPSTYLESTRUCT lpss);
 600     virtual MsgRouting WmSettingChange(UINT wFlag, LPCTSTR pszSection);
 601 
 602     virtual MsgRouting WmContextMenu(HWND hCtrl, UINT xPos, UINT yPos) {
 603         return mrDoDefault;
 604     }
 605 
 606     void UpdateColorModel();
 607 
 608     jintArray CreatePrintedPixels(SIZE &loc, SIZE &size, int alpha);
 609 
 610     /*
 611      * HWND, AwtComponent and Java Peer interaction
 612      *
 613      * Link the C++, Java peer, and HWNDs together.
 614      */
 615     void LinkObjects(JNIEnv *env, jobject peer);
 616 
 617     void UnlinkObjects();
 618 
 619     static BOOL QueryNewPaletteCalled() { return m_QueryNewPaletteCalled; }
 620 
 621 #ifdef DEBUG
 622     virtual void VerifyState(); /* verify component and peer are in sync. */
 623 #else
 624     void VerifyState() {}       /* no-op */
 625 #endif
 626 
 627     virtual AwtDropTarget* CreateDropTarget(JNIEnv* env);
 628     virtual void DestroyDropTarget();
 629 
 630     INLINE virtual HWND GetDBCSEditHandle() { return NULL; }
 631     // State for native drawing API
 632     INLINE jint GetDrawState() { return GetDrawState(m_hwnd); }
 633     INLINE void SetDrawState(jint state) { SetDrawState(m_hwnd, state); }    // State for native drawing API
 634 
 635     INLINE virtual BOOL IsTopLevel() { return FALSE; }
 636     INLINE virtual BOOL IsEmbeddedFrame() { return FALSE; }
 637     INLINE virtual BOOL IsScrollbar() { return FALSE; }
 638 
 639     static INLINE BOOL IsTopLevelHWnd(HWND hwnd) {
 640         AwtComponent *comp = AwtComponent::GetComponent(hwnd);
 641         return (comp != NULL && comp->IsTopLevel());
 642     }
 643     static INLINE BOOL IsEmbeddedFrameHWnd(HWND hwnd) {
 644         AwtComponent *comp = AwtComponent::GetComponent(hwnd);
 645         return (comp != NULL && comp->IsEmbeddedFrame());
 646     }
 647 
 648     static jint GetDrawState(HWND hwnd);
 649     static void SetDrawState(HWND hwnd, jint state);
 650 
 651     static HWND GetHWnd(JNIEnv* env, jobject target);
 652 
 653     static MSG* CreateMessage(UINT message, WPARAM wParam, LPARAM lParam, int x, int y);
 654     static void InitMessage(MSG* msg, UINT message, WPARAM wParam, LPARAM lParam, int x, int y);
 655 
 656     // Some methods to be called on Toolkit thread via Toolkit.InvokeFunction()
 657     static void _Show(void *param);
 658     static void _Hide(void *param);
 659     static void _Enable(void *param);
 660     static void _Disable(void *param);
 661     static jobject _GetLocationOnScreen(void *param);
 662     static void _Reshape(void *param);
 663     static void _ReshapeNoCheck(void *param);
 664     static void _NativeHandleEvent(void *param);
 665     static void _SetForeground(void *param);
 666     static void _SetBackground(void *param);
 667     static void _SetFont(void *param);
 668     static void _Start(void *param);
 669     static void _BeginValidate(void *param);
 670     static void _EndValidate(void *param);
 671     static void _UpdateWindow(void *param);
 672     static jlong _AddNativeDropTarget(void *param);
 673     static void _RemoveNativeDropTarget(void *param);
 674     static jintArray _CreatePrintedPixels(void *param);
 675     static jboolean _NativeHandlesWheelScrolling(void *param);
 676     static void _SetParent(void * param);
 677     static void _SetRectangularShape(void *param);
 678     static void _SetZOrder(void *param);
 679 
 680     static HWND sm_focusOwner;
 681 
 682 private:
 683     static HWND sm_focusedWindow;
 684 
 685 public:
 686     static inline HWND GetFocusedWindow() { return sm_focusedWindow; }
 687     static void SetFocusedWindow(HWND window);
 688 
 689     static void _SetFocus(void *param);
 690 
 691     static void *SetNativeFocusOwner(void *self);
 692     static void *GetNativeFocusedWindow();
 693     static void *GetNativeFocusOwner();
 694 
 695     static BOOL sm_inSynthesizeFocus;
 696 
 697     // Execute on Toolkit only.
 698     INLINE static LRESULT SynthesizeWmSetFocus(HWND targetHWnd, HWND oppositeHWnd) {
 699         sm_inSynthesizeFocus = TRUE;
 700         LRESULT res = ::SendMessage(targetHWnd, WM_SETFOCUS, (WPARAM)oppositeHWnd, 0);
 701         sm_inSynthesizeFocus = FALSE;
 702         return res;
 703     }
 704     // Execute on Toolkit only.
 705     INLINE static LRESULT SynthesizeWmKillFocus(HWND targetHWnd, HWND oppositeHWnd) {
 706         sm_inSynthesizeFocus = TRUE;
 707         LRESULT res = ::SendMessage(targetHWnd, WM_KILLFOCUS, (WPARAM)oppositeHWnd, 0);
 708         sm_inSynthesizeFocus = FALSE;
 709         return res;
 710     }
 711 
 712     static BOOL sm_bMenuLoop;
 713     static INLINE BOOL isMenuLoopActive() {
 714         return sm_bMenuLoop;
 715     }
 716 
 717     // when this component is being destroyed, this method is called
 718     // to find out if there are any messages being processed, and if
 719     // there are some then disposal of this component is postponed
 720     virtual BOOL CanBeDeleted() {
 721         return m_MessagesProcessing == 0;
 722     }
 723 
 724     BOOL IsDestroyPaused() const {
 725         return m_bPauseDestroy;
 726     }
 727 
 728 protected:
 729     static AwtComponent* GetComponentImpl(HWND hWnd);
 730 
 731     static int GetClickCount();
 732 
 733     HWND     m_hwnd;
 734     UINT     m_myControlID;     /* its own ID from the view point of parent */
 735     BOOL     m_backgroundColorSet;
 736     BOOL     m_visible;         /* copy of Component.visible */
 737 
 738     static BOOL sm_suppressFocusAndActivation;
 739     static BOOL sm_restoreFocusAndActivation;
 740 
 741     /*
 742      * The function sets the focus-restore flag ON/OFF.
 743      * When the flag is ON, focus is restored immidiately after the proxy loses it.
 744      * All focus messages are suppressed. It's also assumed that sm_focusedWindow and
 745      * sm_focusOwner don't change after the flag is set ON and before it's set OFF.
 746      */
 747     static INLINE void SetRestoreFocus(BOOL doSet) {
 748         sm_suppressFocusAndActivation = doSet;
 749         sm_restoreFocusAndActivation = doSet;
 750     }
 751 
 752     virtual void SetDragCapture(UINT flags);
 753     virtual void ReleaseDragCapture(UINT flags);
 754 
 755     virtual void FillBackground(HDC hMemoryDC, SIZE &size);
 756     virtual void FillAlpha(void *bitmapBits, SIZE &size, BYTE alpha);
 757 
 758     int ScaleUpX(int x);
 759     int ScaleUpAbsX(int x);
 760     int ScaleUpY(int y);
 761     int ScaleUpAbsY(int y);
 762     int ScaleDownX(int x);
 763     int ScaleDownAbsX(int x);
 764     int ScaleDownY(int y);
 765     int ScaleDownAbsY(int y);
 766 
 767 private:
 768     /* A bitmask keeps the button's numbers as MK_LBUTTON, MK_MBUTTON, MK_RBUTTON
 769      * which are allowed to
 770      * generate the CLICK event after the RELEASE has happened.
 771      * There are conditions that must be true for that sending CLICK event:
 772      * 1) button was initially PRESSED
 773      * 2) no movement or drag has happened until RELEASE
 774     */
 775     UINT m_mouseButtonClickAllowed;
 776 
 777     BOOL m_touchDownOccurred;
 778     BOOL m_touchUpOccurred;
 779     POINT m_touchDownPoint;
 780     POINT m_touchUpPoint;
 781 
 782     BOOL m_bSubclassed;
 783     BOOL m_bPauseDestroy;
 784 
 785     COLORREF m_colorForeground;
 786     COLORREF m_colorBackground;
 787 
 788     AwtPen*  m_penForeground;
 789     AwtBrush* m_brushBackground;
 790 
 791     WNDPROC  m_DefWindowProc;
 792     // counter for messages being processed by this component
 793     UINT     m_MessagesProcessing;
 794 
 795     // provides a unique ID for child controls
 796     UINT     m_nextControlID;
 797 
 798     // DeferWindowPos handle for batched-up window positioning
 799     HDWP     m_hdwp;
 800     // Counter to handle nested calls to Begin/EndValidate
 801     UINT     m_validationNestCount;
 802 
 803     AwtDropTarget* m_dropTarget; // associated DropTarget object
 804 
 805     // When we process WM_INPUTLANGCHANGE we remember the keyboard
 806     // layout handle and associated input language and codepage.
 807     // We also invalidate VK translation table for VK_OEM_* codes
 808     static HKL    m_hkl;
 809     static UINT   m_CodePage;
 810     static LANGID m_idLang;
 811 
 812     static BOOL sm_rtl;
 813     static BOOL sm_rtlReadingOrder;
 814 
 815     static BOOL sm_PrimaryDynamicTableBuilt;
 816 
 817     jobject m_InputMethod;
 818     BOOL    m_useNativeCompWindow;
 819     LPARAM  m_bitsCandType;
 820     UINT    m_PendingLeadByte;
 821 
 822     void SetComponentInHWND();
 823 
 824     // Determines whether a given virtual key is on the numpad
 825     static BOOL IsNumPadKey(UINT vkey, BOOL extended);
 826 
 827     // Determines the keyLocation of a given key
 828     static jint GetKeyLocation(UINT wkey, UINT flags);
 829     static jint GetShiftKeyLocation(UINT wkey, UINT flags);
 830 
 831     // Cache for FindComponent
 832     static HWND sm_cursorOn;
 833 
 834     static BOOL m_QueryNewPaletteCalled;
 835 
 836     static AwtComponent* sm_getComponentCache; // a cache for the GetComponent(..) method.
 837 
 838     int windowMoveLockPosX;
 839     int windowMoveLockPosY;
 840     int windowMoveLockPosCX;
 841     int windowMoveLockPosCY;
 842 
 843     // 6524352: support finer-resolution
 844     int m_wheelRotationAmountX;
 845     int m_wheelRotationAmountY;
 846 
 847     BOOL deadKeyActive;
 848 
 849     /*
 850      * The association list of children's IDs and corresponding components.
 851      * Some components like Choice or List are required their sizes while
 852      * the creations of themselfs are in progress.
 853      */
 854     class ChildListItem {
 855     public:
 856         ChildListItem(UINT id, AwtComponent* component) {
 857             m_ID = id;
 858             m_Component = component;
 859             m_next = NULL;
 860         }
 861         ~ChildListItem() {
 862             if (m_next != NULL)
 863                 delete m_next;
 864         }
 865 
 866         UINT m_ID;
 867         AwtComponent* m_Component;
 868         ChildListItem* m_next;
 869     };
 870 
 871 public:
 872     INLINE void PushChild(UINT id, AwtComponent* component) {
 873         ChildListItem* child = new ChildListItem(id, component);
 874         child->m_next = m_childList;
 875         m_childList = child;
 876     }
 877 
 878     static void SetParent(void * param);
 879 private:
 880     AwtComponent* SearchChild(UINT id);
 881     void RemoveChild(UINT id) ;
 882     static BOOL IsNavigationKey(UINT wkey);
 883     static void BuildPrimaryDynamicTable();
 884 
 885     ChildListItem* m_childList;
 886 
 887     HCURSOR m_hCursorCache; // the latest cursor which has been active within the heavyweight component
 888 public:
 889     inline void setCursorCache(HCURSOR hCursor) {
 890         m_hCursorCache = hCursor;
 891     }
 892     inline HCURSOR getCursorCache() {
 893         return m_hCursorCache;
 894     }
 895 };
 896 
 897 class CounterHelper {
 898 private:
 899     UINT *m_counter;
 900 public:
 901     explicit CounterHelper(UINT *counter) {
 902         m_counter = counter;
 903         (*m_counter)++;
 904     }
 905     ~CounterHelper() {
 906         (*m_counter)--;
 907         m_counter = NULL;
 908     }
 909 };
 910 
 911 // DC management objects; these classes are used to track the list of
 912 // DC's associated with a given Component.  Then DC's can be released
 913 // appropriately on demand or on window destruction to avoid resource
 914 // leakage.
 915 class DCItem {
 916 public:
 917     HDC             hDC;
 918     HWND            hWnd;
 919     DCItem          *next;
 920 };
 921 class DCList {
 922     DCItem          *head;
 923     CriticalSection listLock;
 924 public:
 925     DCList() { head = NULL; }
 926 
 927     void            AddDC(HDC hDC, HWND hWnd);
 928     void            AddDCItem(DCItem *newItem);
 929     DCItem          *RemoveDC(HDC hDC, HWND hWnd);
 930     DCItem          *RemoveAllDCs(HWND hWnd);
 931     DCItem          *RemoveAllDCs();
 932     void            RealizePalettes(int screen);
 933 };
 934 
 935 void ReleaseDCList(HWND hwnd, DCList &list);
 936 void ReleaseDCList(DCList &list);
 937 void MoveDCToPassiveList(HDC hDC, HWND hWnd);
 938 
 939 #include "ObjectList.h"
 940 
 941 #endif /* AWT_COMPONENT_H */
--- EOF ---