function over_scrollbars = isOverScrollbars(cpx,cpy,hScrollpanel)
%isOverScrollbars Returns true if over the scrollbars.
%   OVER = isOverScrollbars(X,Y,H_SCROLLPANEL) calculates whether coordinate
%   (X,Y) falls inside the scrollbars or corner frame of the scroll panel
%   H_SCROLLPANEL. 

%   Copyright 2004 The MathWorks, Inc.
%   $Revision: 1.1.8.1 $  $Date: 2004/08/10 01:50:27 $

  % Temporarily disable ResizeFcn to avoid recursion
  actualResizeFcn = get(hScrollpanel,'ResizeFcn');
  set(hScrollpanel,'ResizeFcn','')

  hSliders = findobj(hScrollpanel,'Type','Uicontrol','Style','slider');
  isVisible = @(h) strcmp( get(h,'Visible'), 'on');
  
  hScrollpanel_pos = getpixelposition(hScrollpanel);
  yoffset = hScrollpanel_pos(2);
  
  slider1_pos = getpixelposition(hSliders(1));
  slider1_pos(2) = slider1_pos(2) + yoffset;
  over_slider1 = isVisible(hSliders(1)) && isOver(cpx,cpy,slider1_pos);
      
  slider2_pos = getpixelposition(hSliders(2));
  slider2_pos(2) = slider2_pos(2) + yoffset;
  over_slider2 = isVisible(hSliders(2)) && isOver(cpx,cpy,slider2_pos);    

  hFrame = findobj(hScrollpanel,'Type','Uicontrol','Style','frame');
  frame_pos = getpixelposition(hFrame);
  frame_pos(2) = frame_pos(2) + yoffset;
  over_frame = isVisible(hFrame) && isOver(cpx,cpy,frame_pos);
      
  over_scrollbars = over_slider1 || over_slider2 || over_frame;

  % Restore ResizeFcn
  set(hScrollpanel,'ResizeFcn',actualResizeFcn)      
  
end
