189 env->DeleteLocalRef(dimension); 190 } 191 } catch (...) { 192 env->DeleteLocalRef(target); 193 throw; 194 } 195 196 done: 197 env->DeleteLocalRef(target); 198 199 return c; 200 } 201 202 // calculate height of drop-down list part of the combobox 203 // to show all the items up to a maximum of eight 204 int AwtChoice::GetDropDownHeight() 205 { 206 int itemHeight =(int)::SendMessage(GetHWnd(), CB_GETITEMHEIGHT, (UINT)0,0); 207 int numItemsToShow = (int)::SendMessage(GetHWnd(), CB_GETCOUNT, 0,0); 208 numItemsToShow = min(MINIMUM_NUMBER_OF_VISIBLE_ITEMS, numItemsToShow); 209 // drop-down height snaps to nearest line, so add a 210 // fudge factor of 1/2 line to ensure last line shows 211 return itemHeight*numItemsToShow + itemHeight/2; 212 } 213 214 // get the height of the field portion of the combobox 215 int AwtChoice::GetFieldHeight() 216 { 217 int fieldHeight; 218 int borderHeight; 219 fieldHeight =(int)::SendMessage(GetHWnd(), CB_GETITEMHEIGHT, (UINT)-1, 0); 220 // add top and bottom border lines; border size is different for 221 // Win 4.x (3d edge) vs 3.x (1 pixel line) 222 borderHeight = ::GetSystemMetrics(SM_CYEDGE); 223 fieldHeight += borderHeight*2; 224 return fieldHeight; 225 } 226 227 // gets the total height of the combobox, including drop down 228 int AwtChoice::GetTotalHeight() 229 { 230 int dropHeight = GetDropDownHeight(); 231 int fieldHeight = GetFieldHeight(); 232 int totalHeight; 233 234 // border on drop-down portion is always non-3d (so don't use SM_CYEDGE) 235 int borderHeight = ::GetSystemMetrics(SM_CYBORDER); 236 // total height = drop down height + field height + top+bottom drop down border lines 237 totalHeight = dropHeight + fieldHeight +borderHeight*2; 238 return totalHeight; 239 } 240 241 // Recalculate and set the drop-down height for the Choice. 242 void AwtChoice::ResetDropDownHeight() 243 { 244 RECT rcWindow; 308 ::GetWindowRect(GetHWnd(), &rc); 309 int oldW = rc.right - rc.left; 310 RECT parentRc; 311 ::GetWindowRect(awtParent->GetHWnd(), &parentRc); 312 int oldX = rc.left - parentRc.left; 313 int oldY = rc.top - parentRc.top; 314 bReshape = (x != oldX || y != oldY || w != oldW); 315 } 316 317 if (bReshape) 318 { 319 int totalHeight = GetTotalHeight(); 320 AwtComponent::Reshape(x, y, w, totalHeight); 321 } 322 323 /* Bug 4255631 Solaris: Size returned by Choice.getSize() does not match 324 * actual size 325 * Fix: Set the Choice to its actual size in the component. 326 */ 327 ::GetClientRect(GetHWnd(), &rc); 328 env->SetIntField(target, AwtComponent::widthID, (jint)rc.right); 329 env->SetIntField(target, AwtComponent::heightID, (jint)rc.bottom); 330 331 env->DeleteLocalRef(target); 332 env->DeleteLocalRef(parent); 333 } 334 335 jobject AwtChoice::PreferredItemSize(JNIEnv *env) 336 { 337 jobject dimension = JNU_CallMethodByName(env, NULL, GetPeer(env), 338 "preferredSize", 339 "()Ljava/awt/Dimension;").l; 340 DASSERT(!safe_ExceptionOccurred(env)); 341 CHECK_NULL_RETURN(dimension, NULL); 342 343 /* This size is window size of choice and it's too big for each 344 * drop down item height. 345 */ 346 env->SetIntField(dimension, AwtDimension::heightID, 347 GetFontHeight(env)); 348 return dimension; 349 } | 189 env->DeleteLocalRef(dimension); 190 } 191 } catch (...) { 192 env->DeleteLocalRef(target); 193 throw; 194 } 195 196 done: 197 env->DeleteLocalRef(target); 198 199 return c; 200 } 201 202 // calculate height of drop-down list part of the combobox 203 // to show all the items up to a maximum of eight 204 int AwtChoice::GetDropDownHeight() 205 { 206 int itemHeight =(int)::SendMessage(GetHWnd(), CB_GETITEMHEIGHT, (UINT)0,0); 207 int numItemsToShow = (int)::SendMessage(GetHWnd(), CB_GETCOUNT, 0,0); 208 numItemsToShow = min(MINIMUM_NUMBER_OF_VISIBLE_ITEMS, numItemsToShow); 209 210 // drop-down height snaps to nearest line, so add a 211 // fudge factor of 1/2 line to ensure last line shows 212 return ScaleDownY(itemHeight * numItemsToShow + itemHeight / 2); 213 } 214 215 // get the height of the field portion of the combobox 216 int AwtChoice::GetFieldHeight() 217 { 218 int fieldHeight; 219 int borderHeight; 220 fieldHeight =(int)::SendMessage(GetHWnd(), CB_GETITEMHEIGHT, (UINT)-1, 0); 221 // add top and bottom border lines; border size is different for 222 // Win 4.x (3d edge) vs 3.x (1 pixel line) 223 borderHeight = ::GetSystemMetrics(SM_CYEDGE); 224 fieldHeight += borderHeight*2; 225 return ScaleDownY(fieldHeight); 226 } 227 228 // gets the total height of the combobox, including drop down 229 int AwtChoice::GetTotalHeight() 230 { 231 int dropHeight = GetDropDownHeight(); 232 int fieldHeight = GetFieldHeight(); 233 int totalHeight; 234 235 // border on drop-down portion is always non-3d (so don't use SM_CYEDGE) 236 int borderHeight = ::GetSystemMetrics(SM_CYBORDER); 237 // total height = drop down height + field height + top+bottom drop down border lines 238 totalHeight = dropHeight + fieldHeight +borderHeight*2; 239 return totalHeight; 240 } 241 242 // Recalculate and set the drop-down height for the Choice. 243 void AwtChoice::ResetDropDownHeight() 244 { 245 RECT rcWindow; 309 ::GetWindowRect(GetHWnd(), &rc); 310 int oldW = rc.right - rc.left; 311 RECT parentRc; 312 ::GetWindowRect(awtParent->GetHWnd(), &parentRc); 313 int oldX = rc.left - parentRc.left; 314 int oldY = rc.top - parentRc.top; 315 bReshape = (x != oldX || y != oldY || w != oldW); 316 } 317 318 if (bReshape) 319 { 320 int totalHeight = GetTotalHeight(); 321 AwtComponent::Reshape(x, y, w, totalHeight); 322 } 323 324 /* Bug 4255631 Solaris: Size returned by Choice.getSize() does not match 325 * actual size 326 * Fix: Set the Choice to its actual size in the component. 327 */ 328 ::GetClientRect(GetHWnd(), &rc); 329 env->SetIntField(target, AwtComponent::widthID, ScaleDownX(rc.right)); 330 env->SetIntField(target, AwtComponent::heightID, ScaleDownY(rc.bottom)); 331 332 env->DeleteLocalRef(target); 333 env->DeleteLocalRef(parent); 334 } 335 336 jobject AwtChoice::PreferredItemSize(JNIEnv *env) 337 { 338 jobject dimension = JNU_CallMethodByName(env, NULL, GetPeer(env), 339 "preferredSize", 340 "()Ljava/awt/Dimension;").l; 341 DASSERT(!safe_ExceptionOccurred(env)); 342 CHECK_NULL_RETURN(dimension, NULL); 343 344 /* This size is window size of choice and it's too big for each 345 * drop down item height. 346 */ 347 env->SetIntField(dimension, AwtDimension::heightID, 348 GetFontHeight(env)); 349 return dimension; 350 } |