1 /* 2 * Copyright (c) 1996, 2009, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 #ifndef AWT_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_FocusEvent.h" 41 #include "java_awt_event_MouseEvent.h" 42 #include "java_awt_event_WindowEvent.h" 43 #include "java_awt_Dimension.h" 44 45 extern LPCTSTR szAwtComponentClassName; 46 47 static LPCTSTR DrawingStateProp = TEXT("SunAwtDrawingStateProp"); 48 49 const UINT IGNORE_KEY = (UINT)-1; 50 const UINT MAX_ACP_STR_LEN = 7; // ANSI CP identifiers are no longer than this 51 52 #define LEFT_BUTTON 1 53 #define MIDDLE_BUTTON 2 54 #define RIGHT_BUTTON 4 55 #define DBL_CLICK 8 56 #define X1_BUTTON 16 57 #define X2_BUTTON 32 58 59 #ifndef MK_XBUTTON1 60 #define MK_XBUTTON1 0x0020 61 #endif 62 63 #ifndef MK_XBUTTON2 64 #define MK_XBUTTON2 0x0040 65 #endif 66 67 // combination of standard mouse button flags 68 const int ALL_MK_BUTTONS = MK_LBUTTON|MK_MBUTTON|MK_RBUTTON; 69 const int X_BUTTONS = MK_XBUTTON1|MK_XBUTTON2; 70 71 72 73 // Whether to check for embedded frame and adjust location 74 #define CHECK_EMBEDDED 0 75 #define DONT_CHECK_EMBEDDED 1 76 77 class AwtPopupMenu; 78 79 class AwtDropTarget; 80 81 /* 82 * Message routing codes 83 */ 84 enum MsgRouting { 85 mrPassAlong, /* pass along to next in chain */ 86 mrDoDefault, /* skip right to underlying default behavior */ 87 mrConsume, /* consume msg & terminate routing immediatly, 88 * don't pass anywhere 89 */ 90 }; 91 92 /************************************************************************ 93 * AwtComponent class 94 */ 95 96 class AwtComponent : public AwtObject { 97 public: 98 /* java.awt.Component fields and method IDs */ 99 static jfieldID peerID; 100 static jfieldID xID; 101 static jfieldID yID; 102 static jfieldID widthID; 103 static jfieldID heightID; 104 static jfieldID visibleID; 105 static jfieldID backgroundID; 106 static jfieldID foregroundID; 107 static jfieldID enabledID; 108 static jfieldID parentID; 109 static jfieldID cursorID; 110 static jfieldID graphicsConfigID; 111 static jfieldID peerGCID; 112 static jfieldID focusableID; 113 static jfieldID appContextID; 114 static jfieldID hwndID; 115 116 static jmethodID getFontMID; 117 static jmethodID getToolkitMID; 118 static jmethodID isEnabledMID; 119 static jmethodID getLocationOnScreenMID; 120 static jmethodID replaceSurfaceDataMID; 121 static jmethodID replaceSurfaceDataLaterMID; 122 static jmethodID disposeLaterMID; 123 124 static const UINT WmAwtIsComponent; 125 static jint * masks; //InputEvent mask array 126 AwtComponent(); 127 virtual ~AwtComponent(); 128 129 /* 130 * Dynamic class registration & creation 131 */ 132 virtual LPCTSTR GetClassName() = 0; 133 /* 134 * Fix for 4964237: Win XP: Changing theme changes java dialogs title icon 135 * WNDCLASS structure has been superseded by the WNDCLASSEX in Win32 136 */ 137 virtual void FillClassInfo(WNDCLASSEX *lpwc); 138 virtual void RegisterClass(); 139 virtual void UnregisterClass(); 140 141 virtual void CreateHWnd(JNIEnv *env, LPCWSTR title, 142 DWORD windowStyle, DWORD windowExStyle, 143 int x, int y, int w, int h, 144 HWND hWndParent, HMENU hMenu, 145 COLORREF colorForeground, COLORREF colorBackground, 146 jobject peer); 147 virtual void DestroyHWnd(); 148 void InitPeerGraphicsConfig(JNIEnv *env, jobject peer); 149 150 virtual void Dispose(); 151 152 void UpdateBackground(JNIEnv *env, jobject target); 153 154 virtual void SubclassHWND(); 155 virtual void UnsubclassHWND(); 156 157 static LRESULT CALLBACK WndProc(HWND hWnd, UINT message, 158 WPARAM wParam, LPARAM lParam); 159 160 /* 161 * Access to the various objects of this aggregate component 162 */ 163 INLINE HWND GetHWnd() { return m_hwnd; } 164 INLINE void SetHWnd(HWND hwnd) { m_hwnd = hwnd; } 165 166 static AwtComponent* GetComponent(HWND hWnd); 167 168 /* 169 * Access to the properties of the component 170 */ 171 INLINE COLORREF GetColor() { return m_colorForeground; } 172 virtual void SetColor(COLORREF c); 173 HPEN GetForegroundPen(); 174 175 COLORREF GetBackgroundColor(); 176 virtual void SetBackgroundColor(COLORREF c); 177 HBRUSH GetBackgroundBrush(); 178 INLINE BOOL IsBackgroundColorSet() { return m_backgroundColorSet; } 179 180 virtual void SetFont(AwtFont *pFont); 181 182 INLINE void SetText(LPCTSTR text) { ::SetWindowText(GetHWnd(), text); } 183 INLINE int GetText(LPTSTR buffer, int size) { 184 return ::GetWindowText(GetHWnd(), buffer, size); 185 } 186 INLINE int GetTextLength() { return ::GetWindowTextLength(GetHWnd()); } 187 188 virtual void GetInsets(RECT* rect) { 189 VERIFY(::SetRectEmpty(rect)); 190 } 191 192 BOOL IsVisible() { return m_visible;}; 193 194 HDC GetDCFromComponent(); 195 196 /* 197 * Enable/disable component 198 */ 199 virtual void Enable(BOOL bEnable); 200 201 /* 202 * Validate and call handleExpose on rects of UpdateRgn 203 */ 204 void PaintUpdateRgn(const RECT *insets); 205 206 static HWND GetTopLevelParentForWindow(HWND hwndDescendant); 207 208 static jobject FindHeavyweightUnderCursor(BOOL useCache); 209 210 /* 211 * Returns the parent component. If no parent window, or the 212 * parent window isn't an AwtComponent, returns NULL. 213 */ 214 AwtComponent* GetParent(); 215 216 /* Get the component's immediate container. Note: may return NULL while 217 the component is being reparented in full-screen mode by Direct3D */ 218 class AwtWindow* GetContainer(); 219 220 /* Is a component a container? Used by above method */ 221 virtual BOOL IsContainer() { return FALSE;} // Plain components can't 222 223 /** 224 * Returns TRUE if this message will trigger native focus change, FALSE otherwise. 225 */ 226 virtual BOOL IsFocusingKeyMessage(MSG *pMsg); 227 virtual BOOL IsFocusingMouseMessage(MSG *pMsg); 228 229 BOOL IsFocusable(); 230 231 /* 232 * Returns an increasing unsigned value used for child control IDs. 233 * There is no attempt to reclaim command ID's. 234 */ 235 INLINE UINT CreateControlID() { return m_nextControlID++; } 236 237 // returns the current keyboard layout 238 INLINE static HKL GetKeyboardLayout() { 239 return m_hkl; 240 } 241 242 // returns the current code page that should be used in 243 // all MultiByteToWideChar and WideCharToMultiByte calls. 244 // This code page should also be use in IsDBCSLeadByteEx. 245 INLINE static UINT GetCodePage() 246 { 247 return m_CodePage; 248 } 249 250 // Added by waleed for BIDI Support 251 // returns the right to left status 252 INLINE static BOOL GetRTLReadingOrder() { 253 return sm_rtlReadingOrder; 254 } 255 // returns the right to left status 256 INLINE static BOOL GetRTL() { 257 return sm_rtl; 258 } 259 // returns the current sub language 260 INLINE static LANGID GetSubLanguage() { 261 return SUBLANGID(m_idLang); 262 } 263 // end waleed 264 265 // returns the current input language 266 INLINE static LANGID GetInputLanguage() 267 { 268 return m_idLang; 269 } 270 // Convert Language ID to CodePage 271 static UINT LangToCodePage(LANGID idLang); 272 273 /* 274 * methods on this component 275 */ 276 virtual void Show(); 277 virtual void Hide(); 278 virtual void Reshape(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 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 private: 751 /* A bitmask keeps the button's numbers as MK_LBUTTON, MK_MBUTTON, MK_RBUTTON 752 * which are allowed to 753 * generate the CLICK event after the RELEASE has happened. 754 * There are conditions that must be true for that sending CLICK event: 755 * 1) button was initially PRESSED 756 * 2) no movement or drag has happened until RELEASE 757 */ 758 UINT m_mouseButtonClickAllowed; 759 760 BOOL m_bSubclassed; 761 BOOL m_bPauseDestroy; 762 763 COLORREF m_colorForeground; 764 COLORREF m_colorBackground; 765 766 AwtPen* m_penForeground; 767 AwtBrush* m_brushBackground; 768 769 WNDPROC m_DefWindowProc; 770 // counter for messages being processed by this component 771 UINT m_MessagesProcessing; 772 773 // provides a unique ID for child controls 774 UINT m_nextControlID; 775 776 // DeferWindowPos handle for batched-up window positioning 777 HDWP m_hdwp; 778 // Counter to handle nested calls to Begin/EndValidate 779 UINT m_validationNestCount; 780 781 AwtDropTarget* m_dropTarget; // associated DropTarget object 782 783 // When we process WM_INPUTLANGCHANGE we remember the keyboard 784 // layout handle and associated input language and codepage. 785 // We also invalidate VK translation table for VK_OEM_* codes 786 static HKL m_hkl; 787 static UINT m_CodePage; 788 static LANGID m_idLang; 789 790 static BOOL sm_rtl; 791 static BOOL sm_rtlReadingOrder; 792 793 static BOOL sm_PrimaryDynamicTableBuilt; 794 795 jobject m_InputMethod; 796 BOOL m_useNativeCompWindow; 797 LPARAM m_bitsCandType; 798 UINT m_PendingLeadByte; 799 800 void SetComponentInHWND(); 801 802 // Determines whether a given virtual key is on the numpad 803 static BOOL IsNumPadKey(UINT vkey, BOOL extended); 804 805 // Determines the keyLocation of a given key 806 static jint GetKeyLocation(UINT wkey, UINT flags); 807 static jint GetShiftKeyLocation(UINT wkey, UINT flags); 808 809 // Cache for FindComponent 810 static HWND sm_cursorOn; 811 812 static BOOL m_QueryNewPaletteCalled; 813 814 static AwtComponent* sm_getComponentCache; // a cache for the GetComponent(..) method. 815 816 int windowMoveLockPosX; 817 int windowMoveLockPosY; 818 int windowMoveLockPosCX; 819 int windowMoveLockPosCY; 820 821 // 6524352: support finer-resolution 822 int m_wheelRotationAmount; 823 824 /* 825 * The association list of children's IDs and corresponding components. 826 * Some components like Choice or List are required their sizes while 827 * the creations of themselfs are in progress. 828 */ 829 class ChildListItem { 830 public: 831 ChildListItem(UINT id, AwtComponent* component) { 832 m_ID = id; 833 m_Component = component; 834 m_next = NULL; 835 } 836 ~ChildListItem() { 837 if (m_next != NULL) 838 delete m_next; 839 } 840 841 UINT m_ID; 842 AwtComponent* m_Component; 843 ChildListItem* m_next; 844 }; 845 846 public: 847 INLINE void PushChild(UINT id, AwtComponent* component) { 848 ChildListItem* child = new ChildListItem(id, component); 849 child->m_next = m_childList; 850 m_childList = child; 851 } 852 853 static void SetParent(void * param); 854 private: 855 AwtComponent* SearchChild(UINT id); 856 void RemoveChild(UINT id) ; 857 static BOOL IsNavigationKey(UINT wkey); 858 static void BuildPrimaryDynamicTable(); 859 860 ChildListItem* m_childList; 861 862 HCURSOR m_hCursorCache; // the latest cursor which has been active within the heavyweight component 863 public: 864 inline void setCursorCache(HCURSOR hCursor) { 865 m_hCursorCache = hCursor; 866 } 867 inline HCURSOR getCursorCache() { 868 return m_hCursorCache; 869 } 870 }; 871 872 class CounterHelper { 873 private: 874 UINT *m_counter; 875 public: 876 explicit CounterHelper(UINT *counter) { 877 m_counter = counter; 878 (*m_counter)++; 879 } 880 ~CounterHelper() { 881 (*m_counter)--; 882 m_counter = NULL; 883 } 884 }; 885 886 // DC management objects; these classes are used to track the list of 887 // DC's associated with a given Component. Then DC's can be released 888 // appropriately on demand or on window destruction to avoid resource 889 // leakage. 890 class DCItem { 891 public: 892 HDC hDC; 893 HWND hWnd; 894 DCItem *next; 895 }; 896 class DCList { 897 DCItem *head; 898 CriticalSection listLock; 899 public: 900 DCList() { head = NULL; } 901 902 void AddDC(HDC hDC, HWND hWnd); 903 void AddDCItem(DCItem *newItem); 904 DCItem *RemoveDC(HDC hDC); 905 DCItem *RemoveAllDCs(HWND hWnd); 906 void RealizePalettes(int screen); 907 }; 908 909 void ReleaseDCList(HWND hwnd, DCList &list); 910 void MoveDCToPassiveList(HDC hDC); 911 912 namespace TimeHelper{ 913 jlong getMessageTimeUTC(); 914 jlong windowsToUTC(DWORD event_offset); 915 } 916 917 #include "ObjectList.h" 918 919 #endif /* AWT_COMPONENT_H */