DhEvent Class

DhEvent Class

This Package | All Packages

public class DhEvent

Carries event information from source to sink. This object is the only parameter on any HTML event callback. The information relayed in this class is rich and deep. Probably the best way to understand all the different information conveyed here is to experiment.

Start with the following code example:


   import wfc.html.*;
   import wfc.html.event.*;
   
   
   public class DumpEvent extends DhModule
   {
   	DhDocument  document;
   	DhText		text;
   	
   	public void documentLoad(Object sender, DhEvent e)
   	{
   		document = getDocument();
   		text = new DhText();
   		document.add(text,DhDocument.INSERT_BEGINNING);
   		document.addOnMouseMove( new DhEventHandler(this,"onMouseMove") );
   	}
   
   	public void onMouseMove( Object sender, DhEvent event )
   	{
   		text.setText( event.toString() );
   	}
   }

Compile that code and put the result onto your CLASSPATH. Now put the following portion of HTML code onto any page:


<object classid="java:DumpEvent"></object>

Now point Internet Explorer (4.0 or later) at that page. As you move the mouse around the page and over elements, hold down various keys (ALT, CTRL, and so on). You will see the results of all the different types of keyboard and mouse position information available to you.

You should also note the effects of the event bubbling. This is an effect caused by the fact that all event sources in HTML trigger the same events all the way up their containment hierarchy. (This is also known as bubbling, broadcasting, or multicasting.) Because the mouse move events are sinked at the document (the top of the containment hierarchy), we see all mouse move events of all elements on the screen.

Fields
Name Description
EVT_LEFTBUTTON Indicates that the left mouse button has been pressed.
EVT_MIDDLEBUTTON Indicates that the middle mouse button has been pressed.
EVT_NOBUTTON Indicates that no mouse button has been pressed.
EVT_RIGHTBUTTON Indicates that the right mouse button has been pressed.

Methods
Name Description
cancelBubble() All event sources in HTML trigger the same events all the way up their containment hierarchy Calling this method tells the HTML document to stop event bubbling.
getChar() Tests for the presence of any key and returns that keypress.
getClientPoint() Retrieves the current position of the mouse relative to the parent client area.
getDocument() Retrieves the document object on which this event was triggered.
getMouseButton() Tests for mouse button events.
getOffsetPoint() Retrieves the current position of the mouse relative to the element's client area.
getPeer() Retrieves the underlying HTML peer element for this class.
getPoint() Retrieves the current position of the mouse relative to the document client.
getReturnValue() Determines if return data has been set.
getScreenPoint() Retrieves the current position of the mouse relative to the desktop.
getSource() Retrieves the original source of the event.
isAltKey() Tests for the ALT key.
isCtrlKey() Tests for the CTRL key.
isShiftKey() Tests for the SHIFT key.
setChar( int c ) Topic under construction.
setReturnValue(boolean b) Sets return data.
setReturnValue(String s) Sets return data.
setReturnValue(int i) Sets return data.
setReturnValue( Variant v) Sets return data.
toString() Converts this event object to a string.

Fields

DhEvent.EVT_LEFTBUTTON

Syntax
public static final int EVT_LEFTBUTTON;
Description
Indicates that the left mouse button has been pressed.

DhEvent.EVT_MIDDLEBUTTON

Syntax
public static final int EVT_MIDDLEBUTTON;
Description
Indicates that the middle mouse button has been pressed.

DhEvent.EVT_NOBUTTON

Syntax
public static final int EVT_NOBUTTON;
Description
Indicates that no mouse button has been pressed.

DhEvent.EVT_RIGHTBUTTON

Syntax
public static final int EVT_RIGHTBUTTON;
Description
Indicates that the right mouse button has been pressed.

Methods

DhEvent.cancelBubble

Syntax
final public synchronized void cancelBubble();
Description

All event sources in HTML trigger the same events all the way up their containment hierarchy Calling this method tells the HTML document to stop event bubbling.

DhEvent.getChar

Syntax
final public synchronized int getChar();
Return Value

Returns the key code of the currently pressed key (or 0 if no key is pressed).

Description

Tests for the presence of any key and returns that keypress.

DhEvent.getClientPoint

Syntax
final public synchronized Point getClientPoint();
Return Value

Returns the current position of the mouse relative to the parent client area.

Description

Retrieves the current position of the mouse relative to the parent client area.

See Also
toString

DhEvent.getDocument

Syntax
final public synchronized DhDocument getDocument();
Return Value

Returns the document object this event came from.

Description

Retrieves the document object on which this event was triggered.

DhEvent.getMouseButton

Syntax
final public synchronized int getMouseButton();
Return Value

Returns one of the mouse buttons constants (EVT_NOBUTTON, EVT_LEFTBUTTON, EVT_RIGHTBUTTON, or EVT_MIDDLEBUTTON).

Description

Tests for mouse button events.

DhEvent.getOffsetPoint

Syntax
final public synchronized Point getOffsetPoint();
Return Value

Returns the current position of the mouse.

Description

Retrieves the current position of the mouse relative to the element's client area.

See Also
toString

DhEvent.getPeer

Syntax
final public IUnknown getPeer();
Return Value

Returns the element peer underlying the HTML peer for this class.

Description

Retrieves the underlying HTML peer element for this class. This method may return null if the event is not bound to the document. Java code that is running in a trusted environment can freely cast the resulting reference to a specific element peer type (for example, wfc.html.om.IHTMLEventObj). This method always returns null if the code is running in a Web server environment.

Note Calling this method represents a very advanced usage scenario. Typically, you would never use this method.

DhEvent.getPoint

Syntax
final public synchronized Point getPoint();
Return Value

Returns the current position of the mouse.

Description

Retrieves the current position of the mouse relative to the document client.

See Also
toString

DhEvent.getReturnValue

Syntax
final public synchronized Variant getReturnValue();
Description

Determines if return data has been set. Certain kinds of events require a response value. Use this method to see if another handler has set the return data to the event source.

DhEvent.getScreenPoint

Syntax
final public synchronized Point getScreenPoint();
Return Value

Returns the current position of the mouse.

Description

Retrieves the current position of the mouse relative to the desktop.

See Also
toString

DhEvent.getSource

Syntax
final public synchronized DhElement getSource();
Return Value

Returns the element that first triggered this event.

Description

Retrieves the original source of the event. This may be the object you actually hooked the event on, or it may one of its children (because all events bubble up the containment hierarchy automatically).

DhEvent.isAltKey

Syntax
final public synchronized boolean isAltKey();
Return Value

Returns true if the ALT key is pressed.

Description

Tests for the ALT key.

DhEvent.isCtrlKey

Syntax
final public synchronized boolean isCtrlKey();
Return Value

Returns true if the CTRL key is pressed.

Description

Tests for the CTRL key.

DhEvent.isShiftKey

Syntax
final public synchronized boolean isShiftKey();
Return Value

Returns true if the SHIFT key is pressed.

Description

Tests for the SHIFT key.

DhEvent.setChar

Syntax
final public synchronized void setChar( int c );
Description

Topic under construction.

DhEvent.setReturnValue

Syntax 1
final public void setReturnValue( boolean b );
Parameters
b
The boolean value to return.
Description

Sets return data. Certain kinds of events require a response value. Use this method to return data to the event source.



Syntax 2
final public void setReturnValue( String s );
Parameters
s
The string value to return.
Description

Sets return data. Certain kinds of events require a response value. Use this method to return data to the event source.



Syntax 3
final public void setReturnValue( int i );
Parameters
i
The integer value to return.
Description

Sets return data. Certain kinds of events require a response value. Use this method to return data to the event source.



Syntax 4
final public synchronized void setReturnValue( Variant v );
Parameters
v
The variant value to return.
Description

Sets return data. Certain kinds of events require a response value. Use this method to return data to the event source.

DhEvent.toString

Syntax
public synchronized String toString();
Description

Converts this event object to a string. Use this when performing diagnostics on your code.