Copyright | (c) Daan Leijen 2003 (c) Shelarcy (shelarcy@gmail.com) 2006 |
---|---|
License | wxWindows |
Maintainer | wxhaskell-devel@lists.sourceforge.net |
Stability | provisional |
Portability | portable |
Safe Haskell | None |
Language | Haskell98 |
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 filters 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 implementation
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 }]
- data Event w a
- on :: Event w a -> Attr w a
- mapEvent :: (a -> b) -> (a -> b -> a) -> Event w a -> Event w b
- propagateEvent :: IO ()
- class Selecting w where
- select :: Selecting w => Event w (IO ())
- class Commanding w where
- command :: Commanding w => Event w (IO ())
- class Updating w where
- update :: Updating w => Event w (IO ())
- class Reactive w where
- mouse :: Reactive w => Event w (EventMouse -> IO ())
- keyboard :: Reactive w => Event w (EventKey -> IO ())
- closing :: Reactive w => Event w (IO ())
- idle :: Reactive w => Event w (IO Bool)
- resize :: Reactive w => Event w (IO ())
- focus :: Reactive w => Event w (Bool -> IO ())
- activate :: Reactive w => Event w (Bool -> IO ())
- class Paint w where
- paint :: Paint w => Event w (DC () -> Rect -> IO ())
- paintRaw :: Paint w => Event w (PaintDC () -> Rect -> [Rect] -> IO ())
- paintGc :: Paint w => Event w (GCDC () -> Rect -> IO ())
- repaint :: Paint w => w -> IO ()
- 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 ())
- doubleClick :: Reactive w => Event w (Point -> IO ())
- clickRight :: Reactive w => Event w (Point -> IO ())
- unclickRight :: Reactive w => Event w (Point -> IO ())
- anyKey :: Reactive w => Event w (Key -> IO ())
- key :: Reactive w => Key -> Event w (IO ())
- charKey :: Reactive w => Char -> Event w (IO ())
- enterKey :: Reactive w => Event w (IO ())
- tabKey :: Reactive w => Event w (IO ())
- escKey :: Reactive w => Event w (IO ())
- helpKey :: Reactive w => Event w (IO ())
- delKey :: Reactive w => Event w (IO ())
- homeKey :: Reactive w => Event w (IO ())
- endKey :: Reactive w => Event w (IO ())
- pgupKey :: Reactive w => Event w (IO ())
- pgdownKey :: Reactive w => Event w (IO ())
- downKey :: Reactive w => Event w (IO ())
- upKey :: Reactive w => Event w (IO ())
- leftKey :: Reactive w => Event w (IO ())
- rightKey :: Reactive w => Event w (IO ())
- rebind :: Event w (IO ()) -> Event w (IO ())
- data Modifiers :: * = Modifiers {}
- showModifiers :: Modifiers -> String
- noneDown :: Modifiers
- justShift :: Modifiers
- justAlt :: Modifiers
- justControl :: Modifiers
- justMeta :: Modifiers
- isNoneDown :: Modifiers -> Bool
- isNoShiftAltControlDown :: Modifiers -> Bool
- data EventMouse :: *
- = MouseMotion ~Point ~Modifiers
- | MouseEnter ~Point ~Modifiers
- | MouseLeave ~Point ~Modifiers
- | MouseLeftDown ~Point ~Modifiers
- | MouseLeftUp ~Point ~Modifiers
- | MouseLeftDClick ~Point ~Modifiers
- | MouseLeftDrag ~Point ~Modifiers
- | MouseRightDown ~Point ~Modifiers
- | MouseRightUp ~Point ~Modifiers
- | MouseRightDClick ~Point ~Modifiers
- | MouseRightDrag ~Point ~Modifiers
- | MouseMiddleDown ~Point ~Modifiers
- | MouseMiddleUp ~Point ~Modifiers
- | MouseMiddleDClick ~Point ~Modifiers
- | MouseMiddleDrag ~Point ~Modifiers
- | MouseWheel ~Bool ~Point ~Modifiers
- showMouse :: EventMouse -> String
- mousePos :: EventMouse -> Point
- mouseModifiers :: EventMouse -> Modifiers
- data EventCalendar :: *
- calendarEvent :: Event (CalendarCtrl a) (EventCalendar -> IO ())
- data EventAuiNotebook :: *
- = AuiNotebookAllowDnd { }
- | AuiNotebookBeginDrag { }
- | AuiNotebookBgDclick { }
- | AuiNotebookButton { }
- | AuiNotebookDragDone { }
- | AuiNotebookDragMotion { }
- | AuiNotebookEndDrag { }
- | AuiNotebookPageChanged { }
- | AuiNotebookPageChanging { }
- | AuiNotebookPageClose { }
- | AuiNotebookPageClosed { }
- | AuiNotebookTabMiddleDown { }
- | AuiNotebookTabMiddleUp { }
- | AuiNotebookTabRightDown { }
- | AuiNotebookTabRightUp { }
- | AuiNotebookUnknown
- | AuiTabCtrlPageChanging { }
- | AuiTabCtrlUnknown
- auiNotebookOnPageCloseEvent :: Event (AuiNotebook a) (EventAuiNotebook -> IO ())
- auiNotebookOnPageClosedEvent :: Event (AuiNotebook a) (EventAuiNotebook -> IO ())
- auiNotebookOnPageChangingEvent :: Event (AuiNotebook a) (EventAuiNotebook -> IO ())
- auiNotebookOnPageChangedEvent :: Event (AuiNotebook a) (EventAuiNotebook -> IO ())
- data EventKey :: * = EventKey ~Key ~Modifiers ~Point
- data Key :: *
- = KeyChar ~Char
- | KeyOther ~KeyCode
- | KeyBack
- | KeyTab
- | KeyReturn
- | KeyEscape
- | KeySpace
- | KeyDelete
- | KeyInsert
- | KeyEnd
- | KeyHome
- | KeyLeft
- | KeyUp
- | KeyRight
- | KeyDown
- | KeyPageUp
- | KeyPageDown
- | KeyStart
- | KeyClear
- | KeyShift
- | KeyAlt
- | KeyControl
- | KeyMenu
- | KeyPause
- | KeyCapital
- | KeyHelp
- | KeySelect
- | KeyPrint
- | KeyExecute
- | KeySnapshot
- | KeyCancel
- | KeyLeftButton
- | KeyRightButton
- | KeyMiddleButton
- | KeyNum0
- | KeyNum1
- | KeyNum2
- | KeyNum3
- | KeyNum4
- | KeyNum5
- | KeyNum6
- | KeyNum7
- | KeyNum8
- | KeyNum9
- | KeyMultiply
- | KeyAdd
- | KeySeparator
- | KeySubtract
- | KeyDecimal
- | KeyDivide
- | KeyF1
- | KeyF2
- | KeyF3
- | KeyF4
- | KeyF5
- | KeyF6
- | KeyF7
- | KeyF8
- | KeyF9
- | KeyF10
- | KeyF11
- | KeyF12
- | KeyF13
- | KeyF14
- | KeyF15
- | KeyF16
- | KeyF17
- | KeyF18
- | KeyF19
- | KeyF20
- | KeyF21
- | KeyF22
- | KeyF23
- | KeyF24
- | KeyNumLock
- | KeyScroll
- keyKey :: EventKey -> Key
- keyModifiers :: EventKey -> Modifiers
- keyPos :: EventKey -> Point
- showKey :: Key -> String
- showKeyModifiers :: Key -> Modifiers -> String
- newEvent :: String -> (w -> IO a) -> (w -> a -> IO ()) -> Event w a
Event
propagateEvent :: IO () #
Pass the event on the next wxWidgets 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
Commanding
class Commanding w where Source #
Commanding
widgets fire a command
event.
Updating
Reactive
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 (PaintDC () -> 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.\
paintGc :: Event w (GCDC () -> Rect -> IO ()) Source #
Paint double buffered to a GCDC
device context, for
anti-aliased drawing. The context is always cleared before
drawing. Takes the current view rectangle (adjusted for
scrolling) as an argument.
repaint :: w -> IO () Source #
Emit a paint event to the specified widget.
paint :: Paint w => 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 :: Paint w => Event w (PaintDC () -> 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.\
paintGc :: Paint w => Event w (GCDC () -> Rect -> IO ()) Source #
Paint double buffered to a GCDC
device context, for
anti-aliased drawing. The context is always cleared before
drawing. Takes the current view rectangle (adjusted for
scrolling) as an argument.
Event filters
Mouse filters
Keyboard event filters
Types
Modifiers
showModifiers :: Modifiers -> String #
Show modifiers, for example for use in menus.
Construct a Modifiers
structure with just Ctrl 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
data EventCalendar :: * #
calendarEvent :: Event (CalendarCtrl a) (EventCalendar -> IO ()) Source #
AuiNotebook event
data EventAuiNotebook :: * #
AuiNotebook events.
auiNotebookOnPageCloseEvent :: Event (AuiNotebook a) (EventAuiNotebook -> IO ()) Source #
auiNotebookOnPageClosedEvent :: Event (AuiNotebook a) (EventAuiNotebook -> IO ()) Source #
auiNotebookOnPageChangingEvent :: Event (AuiNotebook a) (EventAuiNotebook -> IO ()) Source #
auiNotebookOnPageChangedEvent :: Event (AuiNotebook a) (EventAuiNotebook -> IO ()) Source #
Keyboard events
A keyboard event contains the key, the modifiers and the focus point.
A Key
represents a single key on a keyboard.
keyModifiers :: EventKey -> Modifiers #
Extract the modifiers from a keyboard event.
showKeyModifiers :: Key -> Modifiers -> String #
Show a key/modifiers combination, for example for use in menus.