< prev index next >

src/windows/native/sun/windows/awt_Component.cpp

Print this page
rev 12527 : 8165543: Better window framing
Reviewed-by: serb


 133 struct SetRectangularShapeStruct {
 134     jobject component;
 135     jint x1, x2, y1, y2;
 136     jobject region;
 137 };
 138 // Struct for _GetInsets function
 139 struct GetInsetsStruct {
 140     jobject window;
 141     RECT *insets;
 142 };
 143 // Struct for _SetZOrder function
 144 struct SetZOrderStruct {
 145     jobject component;
 146     jlong above;
 147 };
 148 // Struct for _SetFocus function
 149 struct SetFocusStruct {
 150     jobject component;
 151     jboolean doSetFocus;
 152 };





 153 /************************************************************************/
 154 
 155 //////////////////////////////////////////////////////////////////////////
 156 
 157 /*************************************************************************
 158  * AwtComponent fields
 159  */
 160 
 161 
 162 jfieldID AwtComponent::peerID;
 163 jfieldID AwtComponent::xID;
 164 jfieldID AwtComponent::yID;
 165 jfieldID AwtComponent::widthID;
 166 jfieldID AwtComponent::heightID;
 167 jfieldID AwtComponent::visibleID;
 168 jfieldID AwtComponent::backgroundID;
 169 jfieldID AwtComponent::foregroundID;
 170 jfieldID AwtComponent::enabledID;
 171 jfieldID AwtComponent::parentID;
 172 jfieldID AwtComponent::graphicsConfigID;


 244     windowMoveLockPosCY = 0;
 245 
 246     m_hCursorCache = NULL;
 247 
 248     m_bSubclassed = FALSE;
 249     m_bPauseDestroy = FALSE;
 250 
 251     m_MessagesProcessing = 0;
 252     m_wheelRotationAmount = 0;
 253     if (!sm_PrimaryDynamicTableBuilt) {
 254         // do it once.
 255         AwtComponent::BuildPrimaryDynamicTable();
 256         sm_PrimaryDynamicTableBuilt = TRUE;
 257     }
 258 }
 259 
 260 AwtComponent::~AwtComponent()
 261 {
 262     DASSERT(AwtToolkit::IsMainThread());
 263 
 264     /* Disconnect all links. */
 265     UnlinkObjects();
 266 
 267     /*
 268      * All the messages for this component are processed, native
 269      * resources are freed, and Java object is not connected to
 270      * the native one anymore. So we can safely destroy component's
 271      * handle.
 272      */
 273     DestroyHWnd();
 274 }
 275 
 276 void AwtComponent::Dispose()
 277 {


 278     // NOTE: in case the component/toplevel was focused, Java should
 279     // have already taken care of proper transferring it or clearing.
 280 
 281     if (m_hdwp != NULL) {
 282     // end any deferred window positioning, regardless
 283     // of m_validationNestCount
 284         ::EndDeferWindowPos(m_hdwp);
 285     }
 286 
 287     // Send final message to release all DCs associated with this component
 288     SendMessage(WM_AWT_RELEASE_ALL_DCS);
 289 
 290     /* Stop message filtering. */
 291     UnsubclassHWND();
 292 
 293     /* Release global ref to input method */
 294     SetInputMethod(NULL, TRUE);
 295 
 296     if (m_childList != NULL)
 297         delete m_childList;


 298 
 299     DestroyDropTarget();
 300     ReleaseDragCapture(0);
 301 
 302     if (m_myControlID != 0) {
 303         AwtComponent* parent = GetParent();
 304         if (parent != NULL)
 305             parent->RemoveChild(m_myControlID);
 306     }
 307 
 308     ::RemoveProp(GetHWnd(), DrawingStateProp);
 309 
 310     /* Release any allocated resources. */
 311     if (m_penForeground != NULL) {
 312         m_penForeground->Release();
 313         m_penForeground = NULL;
 314     }
 315     if (m_brushBackground != NULL) {
 316         m_brushBackground->Release();
 317         m_brushBackground = NULL;
 318     }
 319 



 320     if (m_bPauseDestroy) {
 321         // AwtComponent::WmNcDestroy could be released now
 322         m_bPauseDestroy = FALSE;
 323         m_hwnd = NULL;
 324     }
 325 
 326     // The component instance is deleted using AwtObject::Dispose() method
 327     AwtObject::Dispose();
 328 }
 329 
 330 /* store component pointer in window extra bytes */
 331 void AwtComponent::SetComponentInHWND() {
 332     DASSERT(::GetWindowLongPtr(GetHWnd(), GWLP_USERDATA) == NULL);
 333     ::SetWindowLongPtr(GetHWnd(), GWLP_USERDATA, (LONG_PTR)this);
 334 }
 335 
 336 /*
 337  * static function to get AwtComponent pointer from hWnd --
 338  * you don't want to call this from inside a wndproc to avoid
 339  * infinite recursion


6106     JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
6107 
6108     jobject self = (jobject)param;
6109 
6110     jboolean result = JNI_FALSE;
6111     AwtComponent *c = NULL;
6112 
6113     PDATA pData;
6114     JNI_CHECK_PEER_GOTO(self, ret);
6115     c = (AwtComponent *)pData;
6116     if (::IsWindow(c->GetHWnd()))
6117     {
6118         result = JNI_IS_TRUE(c->InheritsNativeMouseWheelBehavior());
6119     }
6120 ret:
6121     env->DeleteGlobalRef(self);
6122 
6123     return result;
6124 }
6125 
6126 void AwtComponent::SetParent(void * param) {

6127     if (AwtToolkit::IsMainThread()) {
6128         AwtComponent** comps = (AwtComponent**)param;
6129         if ((comps[0] != NULL) && (comps[1] != NULL)) {
6130             HWND selfWnd = comps[0]->GetHWnd();
6131             HWND parentWnd = comps[1]->GetHWnd();












6132             if (::IsWindow(selfWnd) && ::IsWindow(parentWnd)) {
6133                 // Shouldn't trigger native focus change
6134                 // (only the proxy may be the native focus owner).
6135                 ::SetParent(selfWnd, parentWnd);
6136             }
6137         }
6138         delete[] comps;


6139     } else {
6140         AwtToolkit::GetInstance().InvokeFunction(AwtComponent::SetParent, param);
6141     }
6142 }
6143 
6144 void AwtComponent::_SetRectangularShape(void *param)
6145 {
6146     if (!AwtToolkit::IsMainThread()) {
6147         AwtToolkit::GetInstance().InvokeFunction(AwtComponent::_SetRectangularShape, param);
6148     } else {
6149         JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
6150 
6151         SetRectangularShapeStruct *data = (SetRectangularShapeStruct *)param;
6152         jobject self = data->component;
6153         jint x1 = data->x1;
6154         jint x2 = data->x2;
6155         jint y1 = data->y1;
6156         jint y2 = data->y2;
6157         jobject region = data->region;
6158 
6159         AwtComponent *c = NULL;
6160 


6947 JNIEXPORT jboolean JNICALL
6948 Java_sun_awt_windows_WComponentPeer_isObscured(JNIEnv* env,
6949     jobject self)
6950 {
6951     TRY;
6952 
6953     jobject selfGlobalRef = env->NewGlobalRef(self);
6954 
6955     return (jboolean)AwtToolkit::GetInstance().SyncCall(
6956         (void*(*)(void*))AwtComponent::_IsObscured,
6957         (void *)selfGlobalRef);
6958     // selfGlobalRef is deleted in _IsObscured
6959 
6960     CATCH_BAD_ALLOC_RET(NULL);
6961 }
6962 
6963 JNIEXPORT void JNICALL
6964 Java_sun_awt_windows_WComponentPeer_pSetParent(JNIEnv* env, jobject self, jobject parent) {
6965     TRY;
6966 
6967     typedef AwtComponent* PComponent;
6968     AwtComponent** comps = new PComponent[2];
6969     AwtComponent* comp = (AwtComponent*)JNI_GET_PDATA(self);
6970     AwtComponent* parentComp = (AwtComponent*)JNI_GET_PDATA(parent);
6971     comps[0] = comp;
6972     comps[1] = parentComp;
6973 
6974     AwtToolkit::GetInstance().SyncCall(AwtComponent::SetParent, comps);
6975     // comps is deleted in SetParent
6976 
6977     CATCH_BAD_ALLOC;
6978 }
6979 
6980 JNIEXPORT void JNICALL
6981 Java_sun_awt_windows_WComponentPeer_setRectangularShape(JNIEnv* env, jobject self,
6982         jint x1, jint y1, jint x2, jint y2, jobject region)
6983 {
6984     TRY;
6985 
6986     SetRectangularShapeStruct * data = new SetRectangularShapeStruct;
6987     data->component = env->NewGlobalRef(self);
6988     data->x1 = x1;
6989     data->x2 = x2;
6990     data->y1 = y1;
6991     data->y2 = y2;
6992     if (region) {
6993         data->region = env->NewGlobalRef(region);
6994     } else {
6995         data->region = NULL;




 133 struct SetRectangularShapeStruct {
 134     jobject component;
 135     jint x1, x2, y1, y2;
 136     jobject region;
 137 };
 138 // Struct for _GetInsets function
 139 struct GetInsetsStruct {
 140     jobject window;
 141     RECT *insets;
 142 };
 143 // Struct for _SetZOrder function
 144 struct SetZOrderStruct {
 145     jobject component;
 146     jlong above;
 147 };
 148 // Struct for _SetFocus function
 149 struct SetFocusStruct {
 150     jobject component;
 151     jboolean doSetFocus;
 152 };
 153 // Struct for _SetParent function
 154 struct SetParentStruct {
 155     jobject component;
 156     jobject parentComp;
 157 };
 158 /************************************************************************/
 159 
 160 //////////////////////////////////////////////////////////////////////////
 161 
 162 /*************************************************************************
 163  * AwtComponent fields
 164  */
 165 
 166 
 167 jfieldID AwtComponent::peerID;
 168 jfieldID AwtComponent::xID;
 169 jfieldID AwtComponent::yID;
 170 jfieldID AwtComponent::widthID;
 171 jfieldID AwtComponent::heightID;
 172 jfieldID AwtComponent::visibleID;
 173 jfieldID AwtComponent::backgroundID;
 174 jfieldID AwtComponent::foregroundID;
 175 jfieldID AwtComponent::enabledID;
 176 jfieldID AwtComponent::parentID;
 177 jfieldID AwtComponent::graphicsConfigID;


 249     windowMoveLockPosCY = 0;
 250 
 251     m_hCursorCache = NULL;
 252 
 253     m_bSubclassed = FALSE;
 254     m_bPauseDestroy = FALSE;
 255 
 256     m_MessagesProcessing = 0;
 257     m_wheelRotationAmount = 0;
 258     if (!sm_PrimaryDynamicTableBuilt) {
 259         // do it once.
 260         AwtComponent::BuildPrimaryDynamicTable();
 261         sm_PrimaryDynamicTableBuilt = TRUE;
 262     }
 263 }
 264 
 265 AwtComponent::~AwtComponent()
 266 {
 267     DASSERT(AwtToolkit::IsMainThread());
 268 



 269     /*
 270      * All the messages for this component are processed, native
 271      * resources are freed, and Java object is not connected to
 272      * the native one anymore. So we can safely destroy component's
 273      * handle.
 274      */
 275     DestroyHWnd();
 276 }
 277 
 278 void AwtComponent::Dispose()
 279 {
 280     DASSERT(AwtToolkit::IsMainThread());
 281 
 282     // NOTE: in case the component/toplevel was focused, Java should
 283     // have already taken care of proper transferring it or clearing.
 284 
 285     if (m_hdwp != NULL) {
 286     // end any deferred window positioning, regardless
 287     // of m_validationNestCount
 288         ::EndDeferWindowPos(m_hdwp);
 289     }
 290 
 291     // Send final message to release all DCs associated with this component
 292     SendMessage(WM_AWT_RELEASE_ALL_DCS);
 293 
 294     /* Stop message filtering. */
 295     UnsubclassHWND();
 296 
 297     /* Release global ref to input method */
 298     SetInputMethod(NULL, TRUE);
 299 
 300     if (m_childList != NULL) {
 301         delete m_childList;
 302         m_childList = NULL;
 303     }
 304 
 305     DestroyDropTarget();
 306     ReleaseDragCapture(0);
 307 
 308     if (m_myControlID != 0) {
 309         AwtComponent* parent = GetParent();
 310         if (parent != NULL)
 311             parent->RemoveChild(m_myControlID);
 312     }
 313 
 314     ::RemoveProp(GetHWnd(), DrawingStateProp);
 315 
 316     /* Release any allocated resources. */
 317     if (m_penForeground != NULL) {
 318         m_penForeground->Release();
 319         m_penForeground = NULL;
 320     }
 321     if (m_brushBackground != NULL) {
 322         m_brushBackground->Release();
 323         m_brushBackground = NULL;
 324     }
 325 
 326     /* Disconnect all links. */
 327     UnlinkObjects();
 328 
 329     if (m_bPauseDestroy) {
 330         // AwtComponent::WmNcDestroy could be released now
 331         m_bPauseDestroy = FALSE;
 332         m_hwnd = NULL;
 333     }
 334 
 335     // The component instance is deleted using AwtObject::Dispose() method
 336     AwtObject::Dispose();
 337 }
 338 
 339 /* store component pointer in window extra bytes */
 340 void AwtComponent::SetComponentInHWND() {
 341     DASSERT(::GetWindowLongPtr(GetHWnd(), GWLP_USERDATA) == NULL);
 342     ::SetWindowLongPtr(GetHWnd(), GWLP_USERDATA, (LONG_PTR)this);
 343 }
 344 
 345 /*
 346  * static function to get AwtComponent pointer from hWnd --
 347  * you don't want to call this from inside a wndproc to avoid
 348  * infinite recursion


6115     JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
6116 
6117     jobject self = (jobject)param;
6118 
6119     jboolean result = JNI_FALSE;
6120     AwtComponent *c = NULL;
6121 
6122     PDATA pData;
6123     JNI_CHECK_PEER_GOTO(self, ret);
6124     c = (AwtComponent *)pData;
6125     if (::IsWindow(c->GetHWnd()))
6126     {
6127         result = JNI_IS_TRUE(c->InheritsNativeMouseWheelBehavior());
6128     }
6129 ret:
6130     env->DeleteGlobalRef(self);
6131 
6132     return result;
6133 }
6134 
6135 void AwtComponent::_SetParent(void * param)
6136 {
6137     if (AwtToolkit::IsMainThread()) {
6138         JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
6139         SetParentStruct *data = (SetParentStruct*) param;
6140         jobject self = data->component;
6141         jobject parent = data->parentComp;
6142 
6143         AwtComponent *awtComponent = NULL;
6144         AwtComponent *awtParent = NULL;
6145 
6146         PDATA pData;
6147         JNI_CHECK_PEER_GOTO(self, ret);
6148         awtComponent = (AwtComponent *)pData;
6149         JNI_CHECK_PEER_GOTO(parent, ret);
6150         awtParent = (AwtComponent *)pData;
6151 
6152         HWND selfWnd = awtComponent->GetHWnd();
6153         HWND parentWnd = awtParent->GetHWnd();
6154         if (::IsWindow(selfWnd) && ::IsWindow(parentWnd)) {
6155             // Shouldn't trigger native focus change
6156             // (only the proxy may be the native focus owner).
6157             ::SetParent(selfWnd, parentWnd);
6158         }
6159 ret:
6160         env->DeleteGlobalRef(self);
6161         env->DeleteGlobalRef(parent);
6162         delete data;
6163     } else {
6164         AwtToolkit::GetInstance().InvokeFunction(AwtComponent::_SetParent, param);
6165     }
6166 }
6167 
6168 void AwtComponent::_SetRectangularShape(void *param)
6169 {
6170     if (!AwtToolkit::IsMainThread()) {
6171         AwtToolkit::GetInstance().InvokeFunction(AwtComponent::_SetRectangularShape, param);
6172     } else {
6173         JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
6174 
6175         SetRectangularShapeStruct *data = (SetRectangularShapeStruct *)param;
6176         jobject self = data->component;
6177         jint x1 = data->x1;
6178         jint x2 = data->x2;
6179         jint y1 = data->y1;
6180         jint y2 = data->y2;
6181         jobject region = data->region;
6182 
6183         AwtComponent *c = NULL;
6184 


6971 JNIEXPORT jboolean JNICALL
6972 Java_sun_awt_windows_WComponentPeer_isObscured(JNIEnv* env,
6973     jobject self)
6974 {
6975     TRY;
6976 
6977     jobject selfGlobalRef = env->NewGlobalRef(self);
6978 
6979     return (jboolean)AwtToolkit::GetInstance().SyncCall(
6980         (void*(*)(void*))AwtComponent::_IsObscured,
6981         (void *)selfGlobalRef);
6982     // selfGlobalRef is deleted in _IsObscured
6983 
6984     CATCH_BAD_ALLOC_RET(NULL);
6985 }
6986 
6987 JNIEXPORT void JNICALL
6988 Java_sun_awt_windows_WComponentPeer_pSetParent(JNIEnv* env, jobject self, jobject parent) {
6989     TRY;
6990 
6991     SetParentStruct * data = new SetParentStruct;
6992     data->component = env->NewGlobalRef(self);
6993     data->parentComp = env->NewGlobalRef(parent);



6994 
6995     AwtToolkit::GetInstance().SyncCall(AwtComponent::_SetParent, data);
6996     // global refs and data are deleted in SetParent
6997 
6998     CATCH_BAD_ALLOC;
6999 }
7000 
7001 JNIEXPORT void JNICALL
7002 Java_sun_awt_windows_WComponentPeer_setRectangularShape(JNIEnv* env, jobject self,
7003         jint x1, jint y1, jint x2, jint y2, jobject region)
7004 {
7005     TRY;
7006 
7007     SetRectangularShapeStruct * data = new SetRectangularShapeStruct;
7008     data->component = env->NewGlobalRef(self);
7009     data->x1 = x1;
7010     data->x2 = x2;
7011     data->y1 = y1;
7012     data->y2 = y2;
7013     if (region) {
7014         data->region = env->NewGlobalRef(region);
7015     } else {
7016         data->region = NULL;


< prev index next >