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


 828 
 829     /*
 830      * The association list of children's IDs and corresponding components.
 831      * Some components like Choice or List are required their sizes while
 832      * the creations of themselfs are in progress.
 833      */
 834     class ChildListItem {
 835     public:
 836         ChildListItem(UINT id, AwtComponent* component) {
 837             m_ID = id;
 838             m_Component = component;
 839             m_next = NULL;
 840         }
 841         ~ChildListItem() {
 842             if (m_next != NULL)
 843                 delete m_next;
 844         }
 845 
 846         UINT m_ID;
 847         AwtComponent* m_Component;
 848         ChildListItem* m_next;
 849     };
 850 
 851 public:
 852     INLINE void PushChild(UINT id, AwtComponent* component) {
 853         ChildListItem* child = new ChildListItem(id, component);
 854         child->m_next = m_childList;
 855         m_childList = child;
 856     }
 857 
 858     static void SetParent(void * param);
 859 private:
 860     AwtComponent* SearchChild(UINT id);
 861     void RemoveChild(UINT id) ;
 862     static BOOL IsNavigationKey(UINT wkey);
 863     static void BuildPrimaryDynamicTable();
 864 
 865     ChildListItem* m_childList;
 866 
 867     HCURSOR m_hCursorCache; // the latest cursor which has been active within the heavyweight component
 868 public:
 869     inline void setCursorCache(HCURSOR hCursor) {
 870         m_hCursorCache = hCursor;
 871     }
 872     inline HCURSOR getCursorCache() {
 873         return m_hCursorCache;
 874     }
 875 };
 876 
 877 class CounterHelper {
 878 private:
 879     UINT *m_counter;
 880 public:
 881     explicit CounterHelper(UINT *counter) {
 882         m_counter = counter;
 883         (*m_counter)++;
 884     }
 885     ~CounterHelper() {
 886         (*m_counter)--;
 887         m_counter = NULL;
 888     }
 889 };
 890 
 891 // DC management objects; these classes are used to track the list of
 892 // DC's associated with a given Component.  Then DC's can be released
 893 // appropriately on demand or on window destruction to avoid resource
 894 // leakage.
 895 class DCItem {
 896 public:
 897     HDC             hDC;
 898     HWND            hWnd;
 899     DCItem          *next;
 900 };
 901 class DCList {
 902     DCItem          *head;
 903     CriticalSection listLock;
 904 public:
 905     DCList() { head = NULL; }
 906 
 907     void            AddDC(HDC hDC, HWND hWnd);
 908     void            AddDCItem(DCItem *newItem);
 909     DCItem          *RemoveDC(HDC hDC, HWND hWnd);
 910     DCItem          *RemoveAllDCs(HWND hWnd);
 911     void            RealizePalettes(int screen);
 912 };
 913 
 914 void ReleaseDCList(HWND hwnd, DCList &list);
 915 void MoveDCToPassiveList(HDC hDC, HWND hWnd);
 916 
 917 #include "ObjectList.h"
 918 
 919 #endif /* AWT_COMPONENT_H */
--- EOF ---