1 /* 2 * Copyright (c) 1996, 2016, 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 void ReshapeNoScale(int x, int y, int w, int h); 279 280 /* 281 * Fix for 4046446. 282 * Component size/position helper, for the values above the short int limit. 283 */ 284 static BOOL SetWindowPos(HWND wnd, HWND after, 285 int x, int y, int w, int h, UINT flags); 286 287 /* 288 * Sets the scrollbar values. 'bar' can be either SB_VERT or 289 * SB_HORZ. 'min', 'value', and 'max' can have the value INT_MAX 290 * which means that the value should not be changed. 291 */ 292 void SetScrollValues(UINT bar, int min, int value, int max); 293 294 INLINE LRESULT SendMessage(UINT msg, WPARAM wParam=0, LPARAM lParam=0) { 295 DASSERT(GetHWnd()); 296 return ::SendMessage(GetHWnd(), msg, wParam, lParam); 297 } 298 299 void PostUngrabEvent(); 300 301 INLINE virtual LONG GetStyle() { 302 DASSERT(GetHWnd()); 303 return ::GetWindowLong(GetHWnd(), GWL_STYLE); 304 } 305 INLINE virtual void SetStyle(LONG style) { 306 DASSERT(GetHWnd()); 307 // SetWindowLong() error handling as recommended by Win32 API doc. 308 ::SetLastError(0); 309 DWORD ret = ::SetWindowLong(GetHWnd(), GWL_STYLE, style); 310 DASSERT(ret != 0 || ::GetLastError() == 0); 311 } 312 INLINE virtual LONG GetStyleEx() { 313 DASSERT(GetHWnd()); 314 return ::GetWindowLong(GetHWnd(), GWL_EXSTYLE); 315 } 316 INLINE virtual void SetStyleEx(LONG style) { 317 DASSERT(GetHWnd()); 318 // SetWindowLong() error handling as recommended by Win32 API doc. 319 ::SetLastError(0); 320 DWORD ret = ::SetWindowLong(GetHWnd(), GWL_EXSTYLE, style); 321 DASSERT(ret != 0 || ::GetLastError() == 0); 322 } 323 324 virtual BOOL NeedDblClick() { return FALSE; } 325 326 /* for multifont component */ 327 static void DrawWindowText(HDC hDC, jobject font, jstring text, 328 int x, int y); 329 static void DrawGrayText(HDC hDC, jobject font, jstring text, 330 int x, int y); 331 332 void DrawListItem(JNIEnv *env, DRAWITEMSTRUCT &drawInfo); 333 334 void MeasureListItem(JNIEnv *env, MEASUREITEMSTRUCT &measureInfo); 335 336 jstring GetItemString(JNIEnv *env, jobject target, jint index); 337 338 jint GetFontHeight(JNIEnv *env); 339 340 virtual jobject PreferredItemSize(JNIEnv *env) {DASSERT(FALSE); return NULL; } 341 342 INLINE BOOL isEnabled() { 343 JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2); 344 if (env->EnsureLocalCapacity(2) < 0) { 345 return NULL; 346 } 347 jobject self = GetPeer(env); 348 jobject target = env->GetObjectField(self, AwtObject::targetID); 349 BOOL e = env->CallBooleanMethod(target, AwtComponent::isEnabledMID); 350 DASSERT(!safe_ExceptionOccurred(env)); 351 352 env->DeleteLocalRef(target); 353 354 return e; 355 } 356 357 INLINE BOOL isRecursivelyEnabled() { 358 AwtComponent* p = this; 359 do { 360 if (!p->isEnabled()) { 361 return FALSE; 362 } 363 } while (!p->IsTopLevel() && 364 (p = p->GetParent()) != NULL); 365 return TRUE; 366 } 367 368 void SendKeyEventToFocusOwner(jint id, jlong when, jint raw, jint cooked, 369 jint modifiers, jint keyLocation, jlong nativeCode, 370 MSG *msg = NULL); 371 /* 372 * Allocate and initialize a new java.awt.event.KeyEvent, and 373 * post it to the peer's target object. No response is expected 374 * from the target. 375 */ 376 void SendKeyEvent(jint id, jlong when, jint raw, jint cooked, 377 jint modifiers, jint keyLocation, jlong nativeCode, 378 MSG *msg = NULL); 379 380 /* 381 * Allocate and initialize a new java.awt.event.MouseEvent, and 382 * post it to the peer's target object. No response is expected 383 * from the target. 384 */ 385 void SendMouseEvent(jint id, jlong when, jint x, jint y, 386 jint modifiers, jint clickCount, 387 jboolean popupTrigger, jint button = 0, 388 MSG *msg = NULL); 389 390 /* 391 * Allocate and initialize a new java.awt.event.MouseWheelEvent, and 392 * post it to the peer's target object. No response is expected 393 * from the target. 394 */ 395 void SendMouseWheelEvent(jint id, jlong when, jint x, jint y, 396 jint modifiers, jint clickCount, 397 jboolean popupTrigger, jint scrollType, 398 jint scrollAmount, jint wheelRotation, 399 jdouble preciseWheelRotation, MSG *msg = NULL); 400 401 /* 402 * Allocate and initialize a new java.awt.event.FocusEvent, and 403 * post it to the peer's target object. No response is expected 404 * from the target. 405 */ 406 void SendFocusEvent(jint id, HWND opposite); 407 408 /* Forward a filtered event directly to the subclassed window. 409 synthetic should be TRUE iff the message was generated because 410 of a synthetic Java event, rather than a native event. */ 411 virtual MsgRouting HandleEvent(MSG *msg, BOOL synthetic); 412 413 /* Post a WM_AWT_HANDLE_EVENT message which invokes HandleEvent 414 on the toolkit thread. This method may pre-filter the messages. */ 415 virtual BOOL PostHandleEventMessage(MSG *msg, BOOL synthetic); 416 417 /* Event->message synthesizer methods. */ 418 void SynthesizeKeyMessage(JNIEnv *env, jobject keyEvent); 419 void SynthesizeMouseMessage(JNIEnv *env, jobject mouseEvent); 420 421 /* Components which inherit native mouse wheel behavior will 422 * return TRUE. These are TextArea, Choice, FileDialog, and 423 * List. All other Components return FALSE. 424 */ 425 virtual BOOL InheritsNativeMouseWheelBehavior(); 426 427 /* Determines whether the component is obscured by another window */ 428 // Called on Toolkit thread 429 static jboolean _IsObscured(void *param); 430 431 /* Invalidate the specified rectangle. */ 432 virtual void Invalidate(RECT* r); 433 434 /* Begin and end deferred window positioning. */ 435 virtual void BeginValidate(); 436 virtual void EndValidate(); 437 438 /* Keyboard conversion routines. */ 439 static void InitDynamicKeyMapTable(); 440 static void BuildDynamicKeyMapTable(); 441 static jint GetJavaModifiers(); 442 static jint GetActionModifiers(); 443 static jint GetButton(int mouseButton); 444 static UINT GetButtonMK(int mouseButton); 445 static UINT WindowsKeyToJavaKey(UINT windowsKey, UINT modifiers, UINT character, BOOL isDeadKey); 446 static void JavaKeyToWindowsKey(UINT javaKey, UINT *windowsKey, UINT *modifiers, UINT originalWindowsKey); 447 static void UpdateDynPrimaryKeymap(UINT wkey, UINT jkeyLegacy, jint keyLocation, UINT modifiers); 448 449 INLINE static void AwtComponent::JavaKeyToWindowsKey(UINT javaKey, 450 UINT *windowsKey, UINT *modifiers) 451 { 452 JavaKeyToWindowsKey(javaKey, windowsKey, modifiers, IGNORE_KEY); 453 } 454 455 enum TransOps {NONE, LOAD, SAVE}; 456 457 UINT WindowsKeyToJavaChar(UINT wkey, UINT modifiers, TransOps ops, BOOL &isDeadKey); 458 459 /* routines used for input method support */ 460 void SetInputMethod(jobject im, BOOL useNativeCompWindow); 461 void SendInputMethodEvent(jint id, jstring text, int cClause, 462 int *rgClauseBoundary, jstring *rgClauseReading, 463 int cAttrBlock, int *rgAttrBoundary, 464 BYTE *rgAttrValue, int commitedTextLength, 465 int caretPos, int visiblePos); 466 void InquireCandidatePosition(); 467 INLINE LPARAM GetCandidateType() { return m_bitsCandType; } 468 HWND ImmGetHWnd(); 469 HIMC ImmAssociateContext(HIMC himc); 470 HWND GetProxyFocusOwner(); 471 472 INLINE HWND GetProxyToplevelContainer() { 473 HWND proxyHWnd = GetProxyFocusOwner(); 474 return ::GetAncestor(proxyHWnd, GA_ROOT); // a browser in case of EmbeddedFrame 475 } 476 477 void CallProxyDefWindowProc(UINT message, 478 WPARAM wParam, 479 LPARAM lParam, 480 LRESULT &retVal, 481 MsgRouting &mr); 482 483 /* 484 * Windows message handler functions 485 */ 486 virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam); 487 virtual LRESULT DefWindowProc(UINT msg, WPARAM wParam, LPARAM lParam); 488 489 /* return true if msg is processed */ 490 virtual MsgRouting PreProcessMsg(MSG& msg); 491 492 virtual MsgRouting WmCreate() {return mrDoDefault;} 493 virtual MsgRouting WmClose() {return mrDoDefault;} 494 virtual MsgRouting WmDestroy(); 495 virtual MsgRouting WmNcDestroy(); 496 497 virtual MsgRouting WmActivate(UINT nState, BOOL fMinimized, HWND opposite) 498 { 499 return mrDoDefault; 500 } 501 502 virtual MsgRouting WmEraseBkgnd(HDC hDC, BOOL& didErase) 503 { 504 return mrDoDefault; 505 } 506 507 virtual MsgRouting WmPaint(HDC hDC); 508 virtual MsgRouting WmGetMinMaxInfo(LPMINMAXINFO lpmmi); 509 virtual MsgRouting WmMove(int x, int y); 510 virtual MsgRouting WmSize(UINT type, int w, int h); 511 virtual MsgRouting WmSizing(); 512 virtual MsgRouting WmShowWindow(BOOL show, UINT status); 513 virtual MsgRouting WmSetFocus(HWND hWndLost); 514 virtual MsgRouting WmKillFocus(HWND hWndGot); 515 virtual MsgRouting WmCtlColor(HDC hDC, HWND hCtrl, 516 UINT ctlColor, HBRUSH& retBrush); 517 virtual MsgRouting WmHScroll(UINT scrollCode, UINT pos, HWND hScrollBar); 518 virtual MsgRouting WmVScroll(UINT scrollCode, UINT pos, HWND hScrollBar); 519 520 virtual MsgRouting WmMouseEnter(UINT flags, int x, int y); 521 virtual MsgRouting WmMouseDown(UINT flags, int x, int y, int button); 522 virtual MsgRouting WmMouseUp(UINT flags, int x, int y, int button); 523 virtual MsgRouting WmMouseMove(UINT flags, int x, int y); 524 virtual MsgRouting WmMouseExit(UINT flags, int x, int y); 525 virtual MsgRouting WmMouseWheel(UINT flags, int x, int y, 526 int wheelRotation, BOOL isHorizontal); 527 virtual MsgRouting WmNcMouseDown(WPARAM hitTest, int x, int y, int button); 528 virtual MsgRouting WmNcMouseUp(WPARAM hitTest, int x, int y, int button); 529 virtual MsgRouting WmWindowPosChanging(LPARAM windowPos); 530 virtual MsgRouting WmWindowPosChanged(LPARAM windowPos); 531 532 // NB: 64-bit: vkey is wParam of the message, but other API's take 533 // vkey parameters of type UINT, so we do the cast before dispatching. 534 virtual MsgRouting WmKeyDown(UINT vkey, UINT repCnt, UINT flags, BOOL system); 535 virtual MsgRouting WmKeyUp(UINT vkey, UINT repCnt, UINT flags, BOOL system); 536 537 virtual MsgRouting WmChar(UINT character, UINT repCnt, UINT flags, BOOL system); 538 virtual MsgRouting WmIMEChar(UINT character, UINT repCnt, UINT flags, BOOL system); 539 virtual MsgRouting WmInputLangChange(UINT charset, HKL hKeyBoardLayout); 540 virtual MsgRouting WmForwardChar(WCHAR character, LPARAM lParam, 541 BOOL synthethic); 542 virtual MsgRouting WmPaste(); 543 544 virtual void SetCompositionWindow(RECT &r); 545 virtual void OpenCandidateWindow(int x, int y); 546 virtual void SetCandidateWindow(int iCandType, int x, int y); 547 virtual MsgRouting WmImeSetContext(BOOL fSet, LPARAM *lplParam); 548 virtual MsgRouting WmImeNotify(WPARAM subMsg, LPARAM bitsCandType); 549 virtual MsgRouting WmImeStartComposition(); 550 virtual MsgRouting WmImeEndComposition(); 551 virtual MsgRouting WmImeComposition(WORD wChar, LPARAM flags); 552 553 virtual MsgRouting WmTimer(UINT_PTR timerID) {return mrDoDefault;} 554 555 virtual MsgRouting WmCommand(UINT id, HWND hWndCtrl, UINT notifyCode); 556 557 /* reflected WmCommand from parent */ 558 virtual MsgRouting WmNotify(UINT notifyCode); 559 560 virtual MsgRouting WmCompareItem(UINT /*ctrlId*/, 561 COMPAREITEMSTRUCT &compareInfo, 562 LRESULT &result); 563 virtual MsgRouting WmDeleteItem(UINT /*ctrlId*/, 564 DELETEITEMSTRUCT &deleteInfo); 565 virtual MsgRouting WmDrawItem(UINT ctrlId, 566 DRAWITEMSTRUCT &drawInfo); 567 virtual MsgRouting WmMeasureItem(UINT ctrlId, 568 MEASUREITEMSTRUCT &measureInfo); 569 /* Fix 4181790 & 4223341 : These functions get overridden in owner-drawn 570 * components instead of the Wm... versions. 571 */ 572 virtual MsgRouting OwnerDrawItem(UINT ctrlId, 573 DRAWITEMSTRUCT &drawInfo); 574 virtual MsgRouting OwnerMeasureItem(UINT ctrlId, 575 MEASUREITEMSTRUCT &measureInfo); 576 577 virtual MsgRouting WmPrint(HDC hDC, LPARAM flags); 578 virtual MsgRouting WmPrintClient(HDC hDC, LPARAM flags); 579 580 virtual MsgRouting WmNcCalcSize(BOOL fCalcValidRects, 581 LPNCCALCSIZE_PARAMS lpncsp, 582 LRESULT &retVal); 583 virtual MsgRouting WmNcPaint(HRGN hrgn); 584 virtual MsgRouting WmNcHitTest(UINT x, UINT y, LRESULT &retVal); 585 virtual MsgRouting WmSysCommand(UINT uCmdType, int xPos, int yPos); 586 virtual MsgRouting WmExitSizeMove(); 587 virtual MsgRouting WmEnterMenuLoop(BOOL isTrackPopupMenu); 588 virtual MsgRouting WmExitMenuLoop(BOOL isTrackPopupMenu); 589 590 virtual MsgRouting WmQueryNewPalette(LRESULT &retVal); 591 virtual MsgRouting WmPaletteChanged(HWND hwndPalChg); 592 virtual MsgRouting WmPaletteIsChanging(HWND hwndPalChg); 593 virtual MsgRouting WmStyleChanged(int wStyleType, LPSTYLESTRUCT lpss); 594 virtual MsgRouting WmSettingChange(UINT wFlag, LPCTSTR pszSection); 595 596 virtual MsgRouting WmContextMenu(HWND hCtrl, UINT xPos, UINT yPos) { 597 return mrDoDefault; 598 } 599 600 void UpdateColorModel(); 601 602 jintArray CreatePrintedPixels(SIZE &loc, SIZE &size, int alpha); 603 604 /* 605 * HWND, AwtComponent and Java Peer interaction 606 * 607 * Link the C++, Java peer, and HWNDs together. 608 */ 609 void LinkObjects(JNIEnv *env, jobject peer); 610 611 void UnlinkObjects(); 612 613 static BOOL QueryNewPaletteCalled() { return m_QueryNewPaletteCalled; } 614 615 #ifdef DEBUG 616 virtual void VerifyState(); /* verify component and peer are in sync. */ 617 #else 618 void VerifyState() {} /* no-op */ 619 #endif 620 621 virtual AwtDropTarget* CreateDropTarget(JNIEnv* env); 622 virtual void DestroyDropTarget(); 623 624 INLINE virtual HWND GetDBCSEditHandle() { return NULL; } 625 // State for native drawing API 626 INLINE jint GetDrawState() { return GetDrawState(m_hwnd); } 627 INLINE void SetDrawState(jint state) { SetDrawState(m_hwnd, state); } // State for native drawing API 628 629 INLINE virtual BOOL IsTopLevel() { return FALSE; } 630 INLINE virtual BOOL IsEmbeddedFrame() { return FALSE; } 631 INLINE virtual BOOL IsScrollbar() { return FALSE; } 632 633 static INLINE BOOL IsTopLevelHWnd(HWND hwnd) { 634 AwtComponent *comp = AwtComponent::GetComponent(hwnd); 635 return (comp != NULL && comp->IsTopLevel()); 636 } 637 static INLINE BOOL IsEmbeddedFrameHWnd(HWND hwnd) { 638 AwtComponent *comp = AwtComponent::GetComponent(hwnd); 639 return (comp != NULL && comp->IsEmbeddedFrame()); 640 } 641 642 static jint GetDrawState(HWND hwnd); 643 static void SetDrawState(HWND hwnd, jint state); 644 645 static HWND GetHWnd(JNIEnv* env, jobject target); 646 647 static MSG* CreateMessage(UINT message, WPARAM wParam, LPARAM lParam, int x, int y); 648 static void InitMessage(MSG* msg, UINT message, WPARAM wParam, LPARAM lParam, int x, int y); 649 650 // Some methods to be called on Toolkit thread via Toolkit.InvokeFunction() 651 static void _Show(void *param); 652 static void _Hide(void *param); 653 static void _Enable(void *param); 654 static void _Disable(void *param); 655 static jobject _GetLocationOnScreen(void *param); 656 static void _Reshape(void *param); 657 static void _ReshapeNoCheck(void *param); 658 static void _NativeHandleEvent(void *param); 659 static void _SetForeground(void *param); 660 static void _SetBackground(void *param); 661 static void _SetFont(void *param); 662 static void _Start(void *param); 663 static void _BeginValidate(void *param); 664 static void _EndValidate(void *param); 665 static void _UpdateWindow(void *param); 666 static jlong _AddNativeDropTarget(void *param); 667 static void _RemoveNativeDropTarget(void *param); 668 static jintArray _CreatePrintedPixels(void *param); 669 static jboolean _NativeHandlesWheelScrolling(void *param); 670 static void _SetRectangularShape(void *param); 671 static void _SetZOrder(void *param); 672 673 static HWND sm_focusOwner; 674 675 private: 676 static HWND sm_focusedWindow; 677 678 public: 679 static inline HWND GetFocusedWindow() { return sm_focusedWindow; } 680 static void SetFocusedWindow(HWND window); 681 682 static void _SetFocus(void *param); 683 684 static void *SetNativeFocusOwner(void *self); 685 static void *GetNativeFocusedWindow(); 686 static void *GetNativeFocusOwner(); 687 688 static BOOL sm_inSynthesizeFocus; 689 690 // Execute on Toolkit only. 691 INLINE static LRESULT SynthesizeWmSetFocus(HWND targetHWnd, HWND oppositeHWnd) { 692 sm_inSynthesizeFocus = TRUE; 693 LRESULT res = ::SendMessage(targetHWnd, WM_SETFOCUS, (WPARAM)oppositeHWnd, 0); 694 sm_inSynthesizeFocus = FALSE; 695 return res; 696 } 697 // Execute on Toolkit only. 698 INLINE static LRESULT SynthesizeWmKillFocus(HWND targetHWnd, HWND oppositeHWnd) { 699 sm_inSynthesizeFocus = TRUE; 700 LRESULT res = ::SendMessage(targetHWnd, WM_KILLFOCUS, (WPARAM)oppositeHWnd, 0); 701 sm_inSynthesizeFocus = FALSE; 702 return res; 703 } 704 705 static BOOL sm_bMenuLoop; 706 static INLINE BOOL isMenuLoopActive() { 707 return sm_bMenuLoop; 708 } 709 710 // when this component is being destroyed, this method is called 711 // to find out if there are any messages being processed, and if 712 // there are some then disposal of this component is postponed 713 virtual BOOL CanBeDeleted() { 714 return m_MessagesProcessing == 0; 715 } 716 717 BOOL IsDestroyPaused() const { 718 return m_bPauseDestroy; 719 } 720 721 protected: 722 static AwtComponent* GetComponentImpl(HWND hWnd); 723 724 static int GetClickCount(); 725 726 HWND m_hwnd; 727 UINT m_myControlID; /* its own ID from the view point of parent */ 728 BOOL m_backgroundColorSet; 729 BOOL m_visible; /* copy of Component.visible */ 730 731 static BOOL sm_suppressFocusAndActivation; 732 static BOOL sm_restoreFocusAndActivation; 733 734 /* 735 * The function sets the focus-restore flag ON/OFF. 736 * When the flag is ON, focus is restored immidiately after the proxy loses it. 737 * All focus messages are suppressed. It's also assumed that sm_focusedWindow and 738 * sm_focusOwner don't change after the flag is set ON and before it's set OFF. 739 */ 740 static INLINE void SetRestoreFocus(BOOL doSet) { 741 sm_suppressFocusAndActivation = doSet; 742 sm_restoreFocusAndActivation = doSet; 743 } 744 745 virtual void SetDragCapture(UINT flags); 746 virtual void ReleaseDragCapture(UINT flags); 747 748 virtual void FillBackground(HDC hMemoryDC, SIZE &size); 749 virtual void FillAlpha(void *bitmapBits, SIZE &size, BYTE alpha); 750 751 int ScaleUpX(int x); 752 int ScaleUpY(int y); 753 int ScaleDownX(int x); 754 int ScaleDownY(int y); 755 756 private: 757 /* A bitmask keeps the button's numbers as MK_LBUTTON, MK_MBUTTON, MK_RBUTTON 758 * which are allowed to 759 * generate the CLICK event after the RELEASE has happened. 760 * There are conditions that must be true for that sending CLICK event: 761 * 1) button was initially PRESSED 762 * 2) no movement or drag has happened until RELEASE 763 */ 764 UINT m_mouseButtonClickAllowed; 765 766 BOOL m_bSubclassed; 767 BOOL m_bPauseDestroy; 768 769 COLORREF m_colorForeground; 770 COLORREF m_colorBackground; 771 772 AwtPen* m_penForeground; 773 AwtBrush* m_brushBackground; 774 775 WNDPROC m_DefWindowProc; 776 // counter for messages being processed by this component 777 UINT m_MessagesProcessing; 778 779 // provides a unique ID for child controls 780 UINT m_nextControlID; 781 782 // DeferWindowPos handle for batched-up window positioning 783 HDWP m_hdwp; 784 // Counter to handle nested calls to Begin/EndValidate 785 UINT m_validationNestCount; 786 787 AwtDropTarget* m_dropTarget; // associated DropTarget object 788 789 // When we process WM_INPUTLANGCHANGE we remember the keyboard 790 // layout handle and associated input language and codepage. 791 // We also invalidate VK translation table for VK_OEM_* codes 792 static HKL m_hkl; 793 static UINT m_CodePage; 794 static LANGID m_idLang; 795 796 static BOOL sm_rtl; 797 static BOOL sm_rtlReadingOrder; 798 799 static BOOL sm_PrimaryDynamicTableBuilt; 800 801 jobject m_InputMethod; 802 BOOL m_useNativeCompWindow; 803 LPARAM m_bitsCandType; 804 UINT m_PendingLeadByte; 805 806 void SetComponentInHWND(); 807 808 // Determines whether a given virtual key is on the numpad 809 static BOOL IsNumPadKey(UINT vkey, BOOL extended); 810 811 // Determines the keyLocation of a given key 812 static jint GetKeyLocation(UINT wkey, UINT flags); 813 static jint GetShiftKeyLocation(UINT wkey, UINT flags); 814 815 // Cache for FindComponent 816 static HWND sm_cursorOn; 817 818 static BOOL m_QueryNewPaletteCalled; 819 820 static AwtComponent* sm_getComponentCache; // a cache for the GetComponent(..) method. 821 822 int windowMoveLockPosX; 823 int windowMoveLockPosY; 824 int windowMoveLockPosCX; 825 int windowMoveLockPosCY; 826 827 // 6524352: support finer-resolution 828 int m_wheelRotationAmountX; 829 int m_wheelRotationAmountY; 830 831 BOOL deadKeyActive; 832 833 /* 834 * The association list of children's IDs and corresponding components. 835 * Some components like Choice or List are required their sizes while 836 * the creations of themselfs are in progress. 837 */ 838 class ChildListItem { 839 public: 840 ChildListItem(UINT id, AwtComponent* component) { 841 m_ID = id; 842 m_Component = component; 843 m_next = NULL; 844 } 845 ~ChildListItem() { 846 if (m_next != NULL) 847 delete m_next; 848 } 849 850 UINT m_ID; 851 AwtComponent* m_Component; 852 ChildListItem* m_next; 853 }; 854 855 public: 856 INLINE void PushChild(UINT id, AwtComponent* component) { 857 ChildListItem* child = new ChildListItem(id, component); 858 child->m_next = m_childList; 859 m_childList = child; 860 } 861 862 static void SetParent(void * param); 863 private: 864 AwtComponent* SearchChild(UINT id); 865 void RemoveChild(UINT id) ; 866 static BOOL IsNavigationKey(UINT wkey); 867 static void BuildPrimaryDynamicTable(); 868 869 ChildListItem* m_childList; 870 871 HCURSOR m_hCursorCache; // the latest cursor which has been active within the heavyweight component 872 public: 873 inline void setCursorCache(HCURSOR hCursor) { 874 m_hCursorCache = hCursor; 875 } 876 inline HCURSOR getCursorCache() { 877 return m_hCursorCache; 878 } 879 }; 880 881 class CounterHelper { 882 private: 883 UINT *m_counter; 884 public: 885 explicit CounterHelper(UINT *counter) { 886 m_counter = counter; 887 (*m_counter)++; 888 } 889 ~CounterHelper() { 890 (*m_counter)--; 891 m_counter = NULL; 892 } 893 }; 894 895 // DC management objects; these classes are used to track the list of 896 // DC's associated with a given Component. Then DC's can be released 897 // appropriately on demand or on window destruction to avoid resource 898 // leakage. 899 class DCItem { 900 public: 901 HDC hDC; 902 HWND hWnd; 903 DCItem *next; 904 }; 905 class DCList { 906 DCItem *head; 907 CriticalSection listLock; 908 public: 909 DCList() { head = NULL; } 910 911 void AddDC(HDC hDC, HWND hWnd); 912 void AddDCItem(DCItem *newItem); 913 DCItem *RemoveDC(HDC hDC, HWND hWnd); 914 DCItem *RemoveAllDCs(HWND hWnd); 915 void RealizePalettes(int screen); 916 }; 917 918 void ReleaseDCList(HWND hwnd, DCList &list); 919 void MoveDCToPassiveList(HDC hDC, HWND hWnd); 920 921 #include "ObjectList.h" 922 923 #endif /* AWT_COMPONENT_H */