wx- wxHaskell





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 Graphics.UI.WXCore.Events.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 }]



data Event w a Source

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

on :: Event w a -> Attr w aSource

Transform an event to an attribute.

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

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


class Selecting w whereSource

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


select :: Event w (IO ())Source

A select event is fired when an item is selected.


class Commanding w whereSource

Commanding widgets fire a command event.


command :: Event w (IO ())Source

A commanding event, for example a button press.


class Reactive w whereSource

Reactive widgets are almost all visible widgets on the screen.


class Paint w whereSource

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


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

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 ())Source

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

repaint :: w -> IO ()Source

Emit a paint event to the specified widget.


Event filters

Mouse filters

Keyboard event filters

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

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



data Modifiers

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




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.


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.


EventKey !Key !Modifiers !Point 


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.


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

Create a new event from a get and set function.