javauis/eswt_akn/org.eclipse.ercp.swt.s60/src/org/eclipse/swt/custom/ScrolledComposite.java
branchRCL_3
changeset 19 71c436fe3ce0
parent 14 04becd199f91
equal deleted inserted replaced
18:9ac0a0a7da70 19:71c436fe3ce0
   732     {
   732     {
   733         checkWidget();
   733         checkWidget();
   734         if (control == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
   734         if (control == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
   735         if (control.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
   735         if (control.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
   736         if (!contains(control)) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
   736         if (!contains(control)) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
   737 
   737         doShowControl(control, false);
       
   738     }
       
   739 
       
   740     private void doShowControl(Control control, boolean center) {
   738         Rectangle itemRect = getDisplay().map(control.getParent(), this, control.getBounds());
   741         Rectangle itemRect = getDisplay().map(control.getParent(), this, control.getBounds());
   739         Rectangle area = getClientArea();
   742         Rectangle area = getClientArea();
   740         Point origin = getOrigin();
   743         Point origin = getOrigin();
   741         if (itemRect.x < 0)
   744         if (itemRect.x < 0)
   742         {
   745         {
   744         }
   747         }
   745         else
   748         else
   746         {
   749         {
   747             if (area.width < itemRect.x + itemRect.width) origin.x = Math.max(0, origin.x + itemRect.x + Math.min(itemRect.width, area.width) - area.width);
   750             if (area.width < itemRect.x + itemRect.width) origin.x = Math.max(0, origin.x + itemRect.x + Math.min(itemRect.width, area.width) - area.width);
   748         }
   751         }
   749         if (itemRect.y < 0)
   752         
   750         {
   753         if (center && itemRect.height <= area.height)
   751             origin.y = Math.max(0, origin.y + itemRect.y);
   754         {
       
   755             origin.y = origin.y + itemRect.y - (area.height - itemRect.height) / 2;
   752         }
   756         }
   753         else
   757         else
   754         {
   758         {
   755             if (area.height < itemRect.y + itemRect.height) origin.y = Math.max(0, origin.y + itemRect.y + Math.min(itemRect.height, area.height) - area.height);
   759             if (itemRect.y < 0)
       
   760             {
       
   761                 origin.y = Math.max(0, origin.y + itemRect.y);
       
   762             }
       
   763             else
       
   764             {
       
   765                 if (area.height < itemRect.y + itemRect.height) origin.y = Math.max(0, origin.y + itemRect.y + Math.min(itemRect.height, area.height) - area.height);
       
   766             }
   756         }
   767         }
   757         setOrigin(origin);
   768         setOrigin(origin);
   758     }
   769     }
   759 
   770 
   760     void vScroll()
   771     void vScroll()
   763         Point location = content.getLocation();
   774         Point location = content.getLocation();
   764         ScrollBar vBar = getVerticalBar();
   775         ScrollBar vBar = getVerticalBar();
   765         int vSelection = vBar.getSelection();
   776         int vSelection = vBar.getSelection();
   766         content.setLocation(location.x, -vSelection);
   777         content.setLocation(location.x, -vSelection);
   767     }
   778     }
       
   779     
       
   780     void handleShowFocusedControlEvent()
       
   781     {
       
   782         Control control = getDisplay().getFocusControl();
       
   783         if (contains(control)) doShowControl(control, true);
       
   784     }
   768 }
   785 }