Lines 9-21
Link Here
|
9 |
* |
9 |
* |
10 |
* Contributors: |
10 |
* Contributors: |
11 |
* IBM Corporation - initial API and implementation |
11 |
* IBM Corporation - initial API and implementation |
|
|
12 |
* Randy Hudson <hudsonr@us.ibm.com> |
13 |
* - Fix for bug 19524 - Resizing WorkbenchWindow resizes Views |
12 |
* Cagatay Kavukcuoglu <cagatayk@acm.org> |
14 |
* Cagatay Kavukcuoglu <cagatayk@acm.org> |
13 |
* - Fix for bug 10025 - Resizing views should not use height ratios |
15 |
* - Fix for bug 10025 - Resizing views should not use height ratios |
14 |
**********************************************************************/ |
16 |
**********************************************************************/ |
15 |
|
17 |
|
16 |
import java.util.ArrayList; |
18 |
import java.util.ArrayList; |
17 |
|
19 |
|
18 |
import org.eclipse.jface.util.Geometry; |
|
|
19 |
import org.eclipse.swt.graphics.Point; |
20 |
import org.eclipse.swt.graphics.Point; |
20 |
import org.eclipse.swt.graphics.Rectangle; |
21 |
import org.eclipse.swt.graphics.Rectangle; |
21 |
import org.eclipse.swt.widgets.Composite; |
22 |
import org.eclipse.swt.widgets.Composite; |
Lines 61-67
Link Here
|
61 |
|
62 |
|
62 |
Rectangle bounds = sash.getBounds(); |
63 |
Rectangle bounds = sash.getBounds(); |
63 |
|
64 |
|
64 |
int relativePos = Geometry.getRelativePosition(bounds, toFind); |
65 |
//int relativePos = Geometry.getRelativePosition(bounds, toFind); |
65 |
|
66 |
|
66 |
if(sash.isVertical()) { |
67 |
if(sash.isVertical()) { |
67 |
if (toFind.x < bounds.x + (bounds.width / 2)) { |
68 |
if (toFind.x < bounds.x + (bounds.width / 2)) { |
Lines 90-96
Link Here
|
90 |
PartSashContainer.RelationshipInfo r = new PartSashContainer.RelationshipInfo(); |
91 |
PartSashContainer.RelationshipInfo r = new PartSashContainer.RelationshipInfo(); |
91 |
r.relative = children[0].computeRelation(relations); |
92 |
r.relative = children[0].computeRelation(relations); |
92 |
r.part = children[1].computeRelation(relations); |
93 |
r.part = children[1].computeRelation(relations); |
93 |
r.ratio = getSash().getRatio(); |
94 |
r.left = getSash().getLeft(); |
|
|
95 |
r.right = getSash().getRight(); |
94 |
r.relationship = getSash().isVertical()?IPageLayout.RIGHT:IPageLayout.BOTTOM; |
96 |
r.relationship = getSash().isVertical()?IPageLayout.RIGHT:IPageLayout.BOTTOM; |
95 |
relations.add(0,r); |
97 |
relations.add(0,r); |
96 |
return r.relative; |
98 |
return r.relative; |
Lines 227-232
Link Here
|
227 |
public boolean isVisible() { |
229 |
public boolean isVisible() { |
228 |
return children[0].isVisible() || children[1].isVisible(); |
230 |
return children[0].isVisible() || children[1].isVisible(); |
229 |
} |
231 |
} |
|
|
232 |
|
230 |
/** |
233 |
/** |
231 |
* Recompute the ratios in this tree. The ratio for a node is the width |
234 |
* Recompute the ratios in this tree. The ratio for a node is the width |
232 |
* (or height if the sash is horizontal) of the left child's bounds |
235 |
* (or height if the sash is horizontal) of the left child's bounds |
Lines 307-312
Link Here
|
307 |
* Resize the parts on this tree to fit in <code>bounds</code>. |
310 |
* Resize the parts on this tree to fit in <code>bounds</code>. |
308 |
*/ |
311 |
*/ |
309 |
public void setBounds(Rectangle bounds) { |
312 |
public void setBounds(Rectangle bounds) { |
|
|
313 |
// if (bounds.isEmpty()) |
314 |
// return; |
310 |
if(!children[0].isVisible()) { |
315 |
if(!children[0].isVisible()) { |
311 |
children[1].setBounds(bounds); |
316 |
children[1].setBounds(bounds); |
312 |
return; |
317 |
return; |
Lines 321-331
Link Here
|
321 |
Rectangle sashBounds = new Rectangle(bounds.x,bounds.y,bounds.width,bounds.height); |
326 |
Rectangle sashBounds = new Rectangle(bounds.x,bounds.y,bounds.width,bounds.height); |
322 |
|
327 |
|
323 |
float ratio = getSash().getRatio(); |
328 |
float ratio = getSash().getRatio(); |
|
|
329 |
if (ratio != 0.0) { |
330 |
int length = getSash().isVertical() |
331 |
? bounds.width : bounds.height; |
332 |
getSash().setSizes((int)(length * ratio), length - (int)(length * ratio)); |
333 |
getSash().setRatio(0.0f); |
334 |
} |
335 |
int left = getSash().getLeft(); |
336 |
int right = getSash().getRight(); |
337 |
int total = left+right; |
338 |
|
339 |
//At first I was going to have a more elaborate weighting system, but all-or-non is |
340 |
// sufficient |
341 |
double wLeft = left, wRight = right; |
342 |
switch (getCompressionBias()) { |
343 |
case -1: |
344 |
wLeft = 0.0; |
345 |
break; |
346 |
case 1: |
347 |
wRight = 0.0; |
348 |
break; |
349 |
default: |
350 |
break; |
351 |
} |
352 |
double wTotal = wLeft + wRight; |
324 |
|
353 |
|
325 |
if(getSash().isVertical()) { |
354 |
if(getSash().isVertical()) { |
326 |
|
355 |
|
327 |
//Work on x and width |
356 |
//Work on x and width |
328 |
leftBounds.width = (int)(ratio * bounds.width); |
357 |
leftBounds.width = left; |
|
|
358 |
rightBounds.width = right; |
359 |
|
360 |
int redistribute = bounds.width - SASH_WIDTH - total; |
361 |
|
362 |
leftBounds.x = bounds.x; |
363 |
leftBounds.width += Math.round(redistribute * wLeft / wTotal); |
364 |
|
329 |
sashBounds.x = leftBounds.x + leftBounds.width; |
365 |
sashBounds.x = leftBounds.x + leftBounds.width; |
330 |
sashBounds.width = SASH_WIDTH; |
366 |
sashBounds.width = SASH_WIDTH; |
331 |
|
367 |
|
Lines 334-340
Link Here
|
334 |
} |
370 |
} |
335 |
|
371 |
|
336 |
rightBounds.x = sashBounds.x + sashBounds.width; |
372 |
rightBounds.x = sashBounds.x + sashBounds.width; |
337 |
rightBounds.width = bounds.width - leftBounds.width - sashBounds.width; |
373 |
rightBounds.width = bounds.x + bounds.width - rightBounds.x; |
338 |
|
374 |
|
339 |
if (children[1].fixedHeight()) { |
375 |
if (children[1].fixedHeight()) { |
340 |
rightBounds.height = children[1].getBounds().height; |
376 |
rightBounds.height = children[1].getBounds().height; |
Lines 343-357
Link Here
|
343 |
adjustWidths(bounds, leftBounds, rightBounds, sashBounds); |
379 |
adjustWidths(bounds, leftBounds, rightBounds, sashBounds); |
344 |
} else { |
380 |
} else { |
345 |
//Work on y and height |
381 |
//Work on y and height |
|
|
382 |
int redistribute = bounds.height - SASH_WIDTH - total; |
383 |
|
346 |
if (children[0].fixedHeight()) { |
384 |
if (children[0].fixedHeight()) { |
347 |
leftBounds.height = children[0].getBounds().height; |
385 |
leftBounds.height = children[0].getBounds().height; |
|
|
386 |
} else if (children[1].fixedHeight()) { |
387 |
leftBounds.height = bounds.height - children[1].getBounds().height - SASH_WIDTH; |
348 |
} else { |
388 |
} else { |
349 |
|
389 |
leftBounds.height = left + (int)Math.round(redistribute * wLeft / wTotal); |
350 |
if (children[1].fixedHeight()) { |
|
|
351 |
leftBounds.height = bounds.height - children[1].getBounds().height - SASH_WIDTH; |
352 |
} else { |
353 |
leftBounds.height = (int)(ratio * bounds.height); |
354 |
} |
355 |
} |
390 |
} |
356 |
sashBounds.y = leftBounds.y + leftBounds.height; |
391 |
sashBounds.y = leftBounds.y + leftBounds.height; |
357 |
sashBounds.height = SASH_WIDTH; |
392 |
sashBounds.height = SASH_WIDTH; |
Lines 360-366
Link Here
|
360 |
if (children[1].fixedHeight()) { |
395 |
if (children[1].fixedHeight()) { |
361 |
rightBounds.height = children[1].getBounds().height; |
396 |
rightBounds.height = children[1].getBounds().height; |
362 |
} else { |
397 |
} else { |
363 |
rightBounds.height = bounds.height - leftBounds.height - sashBounds.height; |
398 |
rightBounds.height = bounds.y + bounds.height - rightBounds.y; |
364 |
} |
399 |
} |
365 |
adjustHeights(bounds, leftBounds, rightBounds, sashBounds); |
400 |
adjustHeights(bounds, leftBounds, rightBounds, sashBounds); |
366 |
} |
401 |
} |
Lines 471-477
Link Here
|
471 |
return (part != 0 ) ? part / whole : IPageLayout.RATIO_MIN; |
506 |
return (part != 0 ) ? part / whole : IPageLayout.RATIO_MIN; |
472 |
} |
507 |
} |
473 |
|
508 |
|
474 |
// getMaximumRatioFor added by cagatayk@acm.org |
509 |
|
|
|
510 |
//Added by hudsonr@us.ibm.com - bug 19524 |
511 |
|
512 |
public boolean isCompressible() { |
513 |
return children[0].isCompressible() || children[1].isCompressible(); |
514 |
} |
515 |
|
516 |
/** |
517 |
* Returns 0 if there is no bias. Returns -1 if the first child should be of |
518 |
* fixed size, and the second child should be compressed. Returns 1 if the |
519 |
* second child should be of fixed size. |
520 |
* @return the bias |
521 |
*/ |
522 |
public int getCompressionBias() { |
523 |
boolean left = children[0].isCompressible(); |
524 |
boolean right = children[1].isCompressible(); |
525 |
if (left == right) |
526 |
return 0; |
527 |
if (right) |
528 |
return -1; |
529 |
return 1; |
530 |
}// getMaximumRatioFor added by cagatayk@acm.org |
475 |
/** |
531 |
/** |
476 |
* Obtain the maximum ratio required to display the control on the "right" |
532 |
* Obtain the maximum ratio required to display the control on the "right" |
477 |
* using its minimum dimensions. |
533 |
* using its minimum dimensions. |