annotate src/windows/native/sun/windows/awt_Component.h @ 1095:d0b6e69791c8

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