ScrolledComposite sc = ((ScrolledComposite)composite);
if (sc.content == null) return;
Rectangle contentRect = sc.content.getBounds();
ScrollBar hBar = sc.getHorizontalBar();
ScrollBar vBar = sc.getVerticalBar();
if (hBar != null && hBar.getSize().y >= sc.getSize().y) return;
if (vBar != null && vBar.getSize().x >= sc.getSize().x) return;
// inLayout = true;
Rectangle hostRect = sc.getClientArea();
if (sc.expandHorizontal) {
contentRect.width = Math.max(sc.minWidth, hostRect.width) ;
}
if (sc.expandVertical) {
contentRect.height = Math.max(sc.minHeight, hostRect.height);
}
contentRect = new Rectangle(5, 0, contentRect.width - 10 , contentRect.height);
if (hBar != null) {
hBar.setMaximum (contentRect.width);
int ht = Math.min (contentRect.width, hostRect.width);
hBar.setThumb(ht);
int hPage = contentRect.width - hostRect.width;
if(ht == contentRect.height) hBar.setVisible(false);
else{
hBar.setVisible(true);
int hSelection = hBar.getSelection ();
if (hSelection >= hPage) {
if (hPage <= 0) {
hSelection = 0;
hBar.setSelection(0);
}
contentRect.x = -hSelection;
}
}
}
List<OutlookBarItem> items = ((OutlookBarPane)composite.getParent()).getItemList();
int increate = items.size() > 1 ? items.size()*110 : items.size()*400;
if (vBar != null) {
vBar.setMaximum (contentRect.height);
int ht = Math.min(contentRect.height , hostRect.height + increate);
if(ht == contentRect.height) {
vBar.setVisible(false);
} else{
vBar.setVisible(true);
vBar.setThumb(ht);
int vPage = contentRect.height - hostRect.height;
int vSelection = vBar.getSelection ();
if (vSelection >= vPage) {
if (vPage <= 0) {
vSelection = 0;
vBar.setSelection(0);
}
contentRect.y = -vSelection;
}
}
}