wx-0.90.0.1: wxHaskell

Portabilityportable
Stabilityprovisional
Maintainerwxhaskell-devel@lists.sourceforge.net
Safe HaskellSafe-Infered

Graphics.UI.WX.Events

Contents

Description

Define event handling. Events are parametrised by the widget that can correspond to a certain event and the type of the event handler. For example, the resize event has type:

 Reactive w => Event w (IO ())

This means that all widgets in the Reactive class can respond to resize events. (and since Window is an instance of this class, this means that basically all visible widgets are reactive).

An Event w a can be transformed into an attribute of type Attr w a using the on function.

 do f <- frame [text := "test"]
    set f [on resize := set f [text := "resizing"]]

For convenience, the mouse and keyboard have a serie of event filters: click, drag, enterKey, charKey, etc. These filters are write-only and do not overwrite any previous mouse or keyboard handler but all stay active at the same time. However, all filter will be overwritten again when mouse or keyboard is set again. For example, the following program makes sense:

 set w [on click := ..., on drag := ...]

But in the following program, only the handler for mouse will be called:

 set w [on click := ..., on mouse := ...]

If you want to set the mouse later but retain the old event filters, you can first read the current mouse handler and call it in the new handler (and the same for the keyboard of course). This implemenation technique is used to implement event filters themselves and is also very useful when setting an event handler for a closing event:

 set w [on closing :~ \previous -> do{ ...; previous }]

Note that you should call propagateEvent (or skipCurrentEvent) whenever you do not process the event yourself in an event handler. This propagates the event to the parent event handlers and give them a chance to handle the event in an appropiate way. This gives another elegant way to install a closing event handler:

 set w [on closing := do{ ...; propagateEvent }]

Synopsis

Event

data Event w a

An event for a widget w that expects an event handler of type a.

on :: Event w a -> Attr w a

Transform an event to an attribute.

mapEvent :: (a -> b) -> (a -> b -> a) -> Event w a -> Event w b

Change the event type.

propagateEvent :: IO ()

Pass the event on the next wxWindows event handler, either on this window or its parent. Always call this method when you do not process the event. (This function just call skipCurrentEvent).

Basic events

Selecting

class Selecting w where

Selecting widgets fire a select event when an item is selected.

Methods

select :: Event w (IO ())

A select event is fired when an item is selected.

Commanding

class Commanding w where

Commanding widgets fire a command event.

Methods

command :: Event w (IO ())

A commanding event, for example a button press.

Reactive

class Reactive w where

Reactive widgets are almost all visible widgets on the screen.

Methods

mouse :: Event w (EventMouse -> IO ())

keyboard :: Event w (EventKey -> IO ())

closing :: Event w (IO ())

idle :: Event w (IO Bool)

resize :: Event w (IO ())

focus :: Event w (Bool -> IO ())

activate :: Event w (Bool -> IO ())

Instances

class Paint w where

Paint widgets can serve as a canvas. Note: it is illegal to use both a paint and paintRaw event handler at the same widget.

Methods

paint :: Event w (DC () -> Rect -> IO ())

Paint double buffered to a device context. The context is always cleared before drawing. Takes the current view rectangle (adjusted for scrolling) as an argument.

paintRaw :: Event w (DC () -> Rect -> [Rect] -> IO ())

Paint directly to the on-screen device context. Takes the current view rectangle and a list of dirty rectangles as arguments.\

repaint :: w -> IO ()

Emit a paint event to the specified widget.

Instances

Event filters

Mouse filters

enter :: Reactive w => Event w (Point -> IO ())

leave :: Reactive w => Event w (Point -> IO ())

motion :: Reactive w => Event w (Point -> IO ())

drag :: Reactive w => Event w (Point -> IO ())

click :: Reactive w => Event w (Point -> IO ())

unclick :: Reactive w => Event w (Point -> IO ())

Keyboard event filters

anyKey :: Reactive w => Event w (Key -> IO ())

key :: Reactive w => Key -> Event w (IO ())

charKey :: Reactive w => Char -> Event w (IO ())

rebind :: Event w (IO ()) -> Event w (IO ())

Types

Modifiers

data Modifiers

The Modifiers indicate the meta keys that have been pressed (True) or not (False).

Constructors

Modifiers 

Fields

altDown :: !Bool

alt key down

shiftDown :: !Bool

shift key down

controlDown :: !Bool

control key down

metaDown :: !Bool

meta key down

showModifiers :: Modifiers -> String

Show modifiers, for example for use in menus.

noneDown :: Modifiers

Construct a Modifiers structure with no meta keys pressed.

justShift :: Modifiers

Construct a Modifiers structure with just Shift meta key pressed.

justAlt :: Modifiers

Construct a Modifiers structure with just Alt meta key pressed.

justControl :: Modifiers

Construct a Modifiers structure with just Ctrl meta key pressed.

justMeta :: Modifiers

Construct a Modifiers structure with just Meta meta key pressed.

isNoneDown :: Modifiers -> Bool

Test if no meta key was pressed.

isNoShiftAltControlDown :: Modifiers -> Bool

Test if no shift, alt, or control key was pressed.

Mouse events

data EventMouse

Mouse events. The Point gives the logical (unscrolled) position.

Constructors

MouseMotion !Point !Modifiers

Mouse was moved over the client area of the window

MouseEnter !Point !Modifiers

Mouse enters in the client area of the window

MouseLeave !Point !Modifiers

Mouse leaves the client area of the window

MouseLeftDown !Point !Modifiers

Mouse left button goes down

MouseLeftUp !Point !Modifiers

Mouse left button goes up

MouseLeftDClick !Point !Modifiers

Mouse left button double click

MouseLeftDrag !Point !Modifiers

Mouse left button drag

MouseRightDown !Point !Modifiers

Mouse right button goes down

MouseRightUp !Point !Modifiers

Mouse right button goes up

MouseRightDClick !Point !Modifiers

Mouse right button double click

MouseRightDrag !Point !Modifiers

Mouse right button drag (unsupported on most platforms)

MouseMiddleDown !Point !Modifiers

Mouse middle button goes down

MouseMiddleUp !Point !Modifiers

Mouse middle button goes up

MouseMiddleDClick !Point !Modifiers

Mouse middle button double click

MouseMiddleDrag !Point !Modifiers

Mouse middle button drag (unsupported on most platforms)

MouseWheel !Bool !Point !Modifiers

Mouse wheel rotation. (Bool is True for a downward rotation)

showMouse :: EventMouse -> String

Show an EventMouse in a user friendly way.

mousePos :: EventMouse -> Point

Extract the position from a MouseEvent.

mouseModifiers :: EventMouse -> Modifiers

Extract the modifiers from a MouseEvent.

Calender event

Keyboard events

data EventKey

A keyboard event contains the key, the modifiers and the focus point.

Constructors

EventKey !Key !Modifiers !Point 

Instances

keyKey :: EventKey -> Key

Extract the key from a keyboard event.

keyModifiers :: EventKey -> Modifiers

Extract the modifiers from a keyboard event.

keyPos :: EventKey -> Point

Extract the position from a keyboard event.

showKey :: Key -> String

Show a key for use in menus for example.

showKeyModifiers :: Key -> Modifiers -> String

Show a key/modifiers combination, for example for use in menus.

Internal

newEvent :: String -> (w -> IO a) -> (w -> a -> IO ()) -> Event w a

Create a new event from a get and set function.