<s> from pyjamas import DOM <EOL> from pyjamas . ui import Event <EOL> from pyjamas . EventController import Handler <EOL> def fireMouseEvent ( listeners , sender , event ) : <EOL> x = DOM . eventGetClientX ( event ) - DOM . getAbsoluteLeft ( sender . getElement ( ) ) <EOL> y = DOM . eventGetClientY ( event ) - DOM . getAbsoluteTop ( sender . getElement ( ) ) <EOL> etype = DOM . eventGetType ( event ) <EOL> if etype == "<STR_LIT>" : <EOL> for listener in listeners : <EOL> listener . onMouseDown ( sender , x , y ) <EOL> return True <EOL> elif etype == "<STR_LIT>" : <EOL> for listener in listeners : <EOL> listener . onMouseUp ( sender , x , y ) <EOL> return True <EOL> elif etype == "<STR_LIT>" : <EOL> for listener in listeners : <EOL> listener . onMouseMove ( sender , x , y ) <EOL> return True <EOL> elif etype == "<STR_LIT>" : <EOL> to_element = DOM . eventGetToElement ( event ) <EOL> if to_element and not DOM . isOrHasChild ( sender . getElement ( ) , to_element ) : <EOL> for listener in listeners : <EOL> listener . onMouseEnter ( sender ) <EOL> return True <EOL> elif etype == "<STR_LIT>" : <EOL> to_element = DOM . eventGetToElement ( event ) <EOL> if to_element and not DOM . isOrHasChild ( sender . getElement ( ) , to_element ) : <EOL> for listener in listeners : <EOL> listener . onMouseLeave ( sender ) <EOL> return True <EOL> return False <EOL> MOUSE_EVENTS = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] <EOL> class MouseHandler ( object ) : <EOL> def __init__ ( self , preventDefault = False ) : <EOL> self . _mouseListeners = [ ] <EOL> self . _mousePreventDefault = preventDefault <EOL> self . sinkEvents ( Event . MOUSEEVENTS ) <EOL> def onBrowserEvent ( self , event ) : <EOL> etype = DOM . eventGetType ( event ) <EOL> if etype in MOUSE_EVENTS : <EOL> if self . _mousePreventDefault : <EOL> DOM . eventPreventDefault ( event ) <EOL> return fireMouseEvent ( self . _mouseListeners , self , event ) <EOL> return False <EOL> def addMouseListener ( self , listener ) : <EOL> self . _mouseListeners . append ( listener ) <EOL> def removeMouseListener ( self , listener ) : <EOL> self . _mouseListeners . remove ( listener ) <EOL> def onMouseMove ( self , sender , x , y ) : <EOL> pass <EOL> def onMouseDown ( self , sender , x , y ) : <EOL> pass <EOL> def onMouseUp ( self , sender , x , y ) : <EOL> pass <EOL> def onMouseEnter ( self , sender ) : <EOL> pass <EOL> def onMouseLeave ( self , sender ) : <EOL> pass <EOL> def onMouseGlassEnter ( self , sender ) : <EOL> pass <EOL> def onMouseGlassLeave ( self , sender ) : <EOL> pass <EOL> class MouseWheelHandler ( object ) : <EOL> def __init__ ( self , preventDefault = False ) : <EOL> self . _mouseWheelListeners = [ ] <EOL> self . _mouseWheelPreventDefault = preventDefault <EOL> self . sinkEvents ( Event . ONMOUSEWHEEL ) <EOL> def onBrowserEvent ( self , event ) : <EOL> etype = DOM . eventGetType ( event ) <EOL> if etype == "<STR_LIT>" : <EOL> if self . _mouseWheelPreventDefault : <EOL> DOM . eventPreventDefault ( event ) <EOL> velocity = DOM . eventGetMouseWheelVelocityY ( event ) <EOL> for listener in self . _mouseWheelListeners : <EOL> listener . onMouseWheel ( self , velocity ) <EOL> return True <EOL> def addMouseWheelListener ( self , listener ) : <EOL> self . _mouseWheelListeners . append ( listener ) <EOL> def removeMouseWheelListener ( self , listener ) : <EOL> self . _mouseWheelListeners . remove ( listener ) <EOL> def onMouseWheel ( self , sender , velocity ) : <EOL> pass </s>
