179 int posBefore; 180 int posAfter; 181 182 posBefore = GetScrollPos(orient); 183 si.cbSize = sizeof(SCROLLINFO); 184 si.nMin = 0; 185 si.nMax = max; 186 si.fMask = SIF_RANGE; 187 if (disableNoScroll) { 188 si.fMask |= SIF_DISABLENOSCROLL; 189 } 190 if (page > 0) { 191 si.fMask |= SIF_PAGE; 192 si.nPage = page; 193 } 194 ::SetScrollInfo(GetHWnd(), orient, &si, TRUE); 195 // scroll position may have changed when thumb is at the end of the bar 196 // and the page size changes 197 posAfter = GetScrollPos(orient); 198 if (posBefore != posAfter) { 199 if(max==0 && posAfter==0) { 200 // Caller used nMin==nMax idiom to hide scrollbar. 201 // On the new themes (Windows XP, Vista) this would reset 202 // scroll position to zero ("just inside the range") (6404832). 203 // 204 PostScrollEvent(orient, SB_THUMBPOSITION, posBefore); 205 }else{ 206 PostScrollEvent(orient, SB_THUMBPOSITION, posAfter); 207 } 208 } 209 } 210 211 void AwtScrollPane::RecalcSizes(int parentWidth, int parentHeight, 212 int childWidth, int childHeight) 213 { 214 JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2); 215 if (env->EnsureLocalCapacity(2) < 0) { 216 return; 217 } 218 219 /* Determine border width without scrollbars. */ 220 int horzBorder = ::GetSystemMetrics(SM_CXEDGE);; 221 int vertBorder = ::GetSystemMetrics(SM_CYEDGE);; 222 223 parentWidth -= (horzBorder * 2); 224 parentHeight -= (vertBorder * 2); 225 226 /* Enable each scrollbar as needed. */ 227 jobject target = AwtObject::GetTarget(env); 228 jint policy = env->GetIntField(target, 246 * recalculate the horizontal metrics and scrollbar boolean. 247 */ 248 if (!needsHorz) { 249 needsHorz = (policy == java_awt_ScrollPane_SCROLLBARS_ALWAYS || 250 (policy == java_awt_ScrollPane_SCROLLBARS_AS_NEEDED && 251 childWidth > parentWidth)); 252 if (needsHorz) { 253 parentHeight -= ::GetSystemMetrics(SM_CYHSCROLL); 254 } 255 } 256 257 /* Now set ranges -- setting the min and max the same disables them. */ 258 if (needsHorz) { 259 jobject hAdj = 260 env->GetObjectField(target, AwtScrollPane::hAdjustableID); 261 env->SetIntField(hAdj, AwtScrollPane::blockIncrementID, parentWidth); 262 SetScrollInfo(SB_HORZ, childWidth - 1, parentWidth, 263 (policy == java_awt_ScrollPane_SCROLLBARS_ALWAYS)); 264 env->DeleteLocalRef(hAdj); 265 } else { 266 SetScrollInfo(SB_HORZ, 0, 0, 267 (policy == java_awt_ScrollPane_SCROLLBARS_ALWAYS)); 268 } 269 270 if (needsVert) { 271 jobject vAdj = 272 env->GetObjectField(target, AwtScrollPane::vAdjustableID); 273 env->SetIntField(vAdj, AwtScrollPane::blockIncrementID, parentHeight); 274 SetScrollInfo(SB_VERT, childHeight - 1, parentHeight, 275 (policy == java_awt_ScrollPane_SCROLLBARS_ALWAYS)); 276 env->DeleteLocalRef(vAdj); 277 } else { 278 SetScrollInfo(SB_VERT, 0, 0, 279 (policy == java_awt_ScrollPane_SCROLLBARS_ALWAYS)); 280 } 281 282 env->DeleteLocalRef(target); 283 } 284 285 void AwtScrollPane::Reshape(int x, int y, int w, int h) 286 { 287 AwtComponent::Reshape(x, y, w, h); 288 } 289 290 void AwtScrollPane::Show(JNIEnv *env) 291 { 292 SetInsets(env); 293 SendMessage(WM_AWT_COMPONENT_SHOW); 294 } 295 296 void AwtScrollPane::PostScrollEvent(int orient, int scrollCode, int pos) { 297 if (scrollCode == SB_ENDSCROLL) { 298 return; 299 } | 179 int posBefore; 180 int posAfter; 181 182 posBefore = GetScrollPos(orient); 183 si.cbSize = sizeof(SCROLLINFO); 184 si.nMin = 0; 185 si.nMax = max; 186 si.fMask = SIF_RANGE; 187 if (disableNoScroll) { 188 si.fMask |= SIF_DISABLENOSCROLL; 189 } 190 if (page > 0) { 191 si.fMask |= SIF_PAGE; 192 si.nPage = page; 193 } 194 ::SetScrollInfo(GetHWnd(), orient, &si, TRUE); 195 // scroll position may have changed when thumb is at the end of the bar 196 // and the page size changes 197 posAfter = GetScrollPos(orient); 198 if (posBefore != posAfter) { 199 PostScrollEvent(orient, SB_THUMBPOSITION, posAfter); 200 } 201 } 202 203 void AwtScrollPane::RecalcSizes(int parentWidth, int parentHeight, 204 int childWidth, int childHeight) 205 { 206 JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2); 207 if (env->EnsureLocalCapacity(2) < 0) { 208 return; 209 } 210 211 /* Determine border width without scrollbars. */ 212 int horzBorder = ::GetSystemMetrics(SM_CXEDGE);; 213 int vertBorder = ::GetSystemMetrics(SM_CYEDGE);; 214 215 parentWidth -= (horzBorder * 2); 216 parentHeight -= (vertBorder * 2); 217 218 /* Enable each scrollbar as needed. */ 219 jobject target = AwtObject::GetTarget(env); 220 jint policy = env->GetIntField(target, 238 * recalculate the horizontal metrics and scrollbar boolean. 239 */ 240 if (!needsHorz) { 241 needsHorz = (policy == java_awt_ScrollPane_SCROLLBARS_ALWAYS || 242 (policy == java_awt_ScrollPane_SCROLLBARS_AS_NEEDED && 243 childWidth > parentWidth)); 244 if (needsHorz) { 245 parentHeight -= ::GetSystemMetrics(SM_CYHSCROLL); 246 } 247 } 248 249 /* Now set ranges -- setting the min and max the same disables them. */ 250 if (needsHorz) { 251 jobject hAdj = 252 env->GetObjectField(target, AwtScrollPane::hAdjustableID); 253 env->SetIntField(hAdj, AwtScrollPane::blockIncrementID, parentWidth); 254 SetScrollInfo(SB_HORZ, childWidth - 1, parentWidth, 255 (policy == java_awt_ScrollPane_SCROLLBARS_ALWAYS)); 256 env->DeleteLocalRef(hAdj); 257 } else { 258 /* Set scroll info to imitate the behaviour and since we don't 259 need to display it, explicitly don't show the bar */ 260 SetScrollInfo(SB_HORZ, childWidth - 1, parentWidth, 261 (policy == java_awt_ScrollPane_SCROLLBARS_ALWAYS)); 262 ::ShowScrollBar(GetHWnd(), SB_HORZ, false); 263 } 264 265 if (needsVert) { 266 jobject vAdj = 267 env->GetObjectField(target, AwtScrollPane::vAdjustableID); 268 env->SetIntField(vAdj, AwtScrollPane::blockIncrementID, parentHeight); 269 SetScrollInfo(SB_VERT, childHeight - 1, parentHeight, 270 (policy == java_awt_ScrollPane_SCROLLBARS_ALWAYS)); 271 env->DeleteLocalRef(vAdj); 272 } else { 273 /* Set scroll info to imitate the behaviour and since we don't 274 need to display it, explicitly don't show the bar */ 275 SetScrollInfo(SB_VERT, childHeight - 1, parentHeight, 276 (policy == java_awt_ScrollPane_SCROLLBARS_ALWAYS)); 277 ::ShowScrollBar(GetHWnd(), SB_VERT, false); 278 } 279 280 env->DeleteLocalRef(target); 281 } 282 283 void AwtScrollPane::Reshape(int x, int y, int w, int h) 284 { 285 AwtComponent::Reshape(x, y, w, h); 286 } 287 288 void AwtScrollPane::Show(JNIEnv *env) 289 { 290 SetInsets(env); 291 SendMessage(WM_AWT_COMPONENT_SHOW); 292 } 293 294 void AwtScrollPane::PostScrollEvent(int orient, int scrollCode, int pos) { 295 if (scrollCode == SB_ENDSCROLL) { 296 return; 297 } |