OWLNext    7.0
Borland's Object Windows Library for the modern age
Loading...
Searching...
No Matches
Mouse Events in a Gadget

You can track mouse events that happen inside and outside a gadget through a number of pseudo-event handlers in the TGadget class.

These functions look much like standard ObjectWindows event-handling functions except that the names of the functions are not prefixed with Ev.

Because gadgets are not actually windows, they do not have response tables like other ObjectWindows classes. All of a gadget's communication with the outside is handled through the gadget window. When a mouse event takes place in the gadget window, the window tries to determine which gadget is affected by the event. To find out if an event took place inside a particular gadget, you can call the TGadget::PtIn function:

virtual bool PtIn(TPoint& point);

The default behavior for this function is to return true if point is within the gadget's bounding rectangle. You could override this function if you were designing an oddly shaped gadget.

When the mouse enters the bounding rectangle of a gadget, the gadget window calls the function TGadget::MouseEnter. This function looks like this:

virtual void MouseEnter(uint modKeys, TPoint& point);

modKeys contains virtual key information identical to that passed-in in the standard ObjectWindows EvMouseMove function. It indicates whether various virtual keys are pressed. This parameter can be any combination of the following values: MK_CONTROL, MK_LBUTTON, MK_MBUTTON, MK_RBUTTON, or MK_SHIFT. point tells the gadget where the mouse entered the gadget.

After the gadget window calls the gadget's MouseEnter function to inform the gadget that the mouse has entered the gadget's area, the gadget captures mouse movements by calling the gadget window's GadgetSetCapture function to guarantee that the gadget's MouseLeave function is called.

After the mouse leaves the gadget bounds, the gadget window calls MouseLeave, which function looks like this:

virtual void MouseLeave(uint modKeys, TPoint& point);

There are also a couple of functions to detect left mouse button clicks, TGadget::LButtonDown and TGadget::LButtonUp. The default behavior for LButtonDown is to capture the mouse if the bool flag TrackMouse is set. The default behavior for LButtonUp is to release the mouse if the bool flag TrackMouse is set. By default TrackMouse is not set.

virtual void LButtonDown(uint modKeys, TPoint& point);
virtual void LButtonUp(uint modKeys, TPoint& point);

When the mouse is moved inside the bounding rectangle of a gadget while mouse movements are being captured by the gadget window, the window calls the gadget's TGadget::MouseMove function. This function looks like this:

virtual void MouseMove(uint modKeys, TPoint& point);

As with MouseEnter, modKeys contains virtual key information. point tells the gadget where the mouse stopped moving.

See Also