summaryrefslogtreecommitdiff
path: root/src/Gtk/Signal.dcl
blob: 85a780ca2bb7dc25781321b838b81d4253918b05 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
definition module Gtk.Signal

/**
 * This module provides functionality for Gtk signals.
 */

from System._Pointer import :: Pointer

from Gdk.Events import :: GdkEvent
from Gtk.State import :: GtkM, :: GtkState
from Gtk.Tune import class tune
from Gtk.Types import :: GtkPropagate, :: GtkTimeout
from Gtk.Widgets import class gtkWidget

/**
 * If more handlers are defined outside this module (and hence outside the
 * `GSignalHandler` type), they must instantiate this class to be able to be
 * installed on widgets.
 */
class signalHandler h
where
	//* The name of the signal, e.g. `destroy` or `key-press-event`.
	signalName :: !h -> String
	//* An internal representation of the handler.
	signalHandler :: !h -> SignalHandlerInternal

//* A number of basic signals. See the Gtk documentation for their usage.
:: GSignalHandler
	= ActivateHandler      !(GtkM ())
	| ChangedHandler       !(GtkM ())
	| ClickedHandler       !(GtkM ())
	| DeleteEventHandler   !(GdkEvent -> GtkM GtkPropagate)
	| DestroyHandler       !(GtkM ())
	| KeyPressHandler      !(GdkEvent -> GtkM GtkPropagate)
	| NextMatchHandler     !(GtkM ())
	| PreviousMatchHandler !(GtkM ())
	| SearchChangedHandler !(GtkM ())
	| StopSearchHandler    !(GtkM ())

instance signalHandler GSignalHandler

/**
 * Inner representation of the various types of signal handlers that there are.
 * This is only needed outside this module when adding more signals.
 */
:: SignalHandlerInternal
	= SHI_Void !(GtkM ())
	| SHI_Pointer_Bool !(Pointer -> GtkM Bool)
	| SHI_Int_Int_Bool !(Int Int -> GtkM Bool)
	| SHI_Int_Int_Pointer_Pointer_Bool !(Int Int Pointer Pointer -> GtkM Bool)

/**
 * Install a signal handler on a widget. Often, the `tune` instance defined
 * below leads to more readable code.
 */
installSignalHandler :: !h !w -> GtkM w | signalHandler h & gtkWidget w

//* Alternative for `installSignalHandler` for more readable code.
instance tune w GSignalHandler | gtkWidget w

/**
 * Run a function at a certain interval. The function will continue to run
 * until it returns `False`. Note that Glib timeouts cannot be used for precise
 * timing; see the documentation for more details:
 * https://developer.gnome.org/glib/stable/glib-The-Main-Event-Loop.html#g-timeout-add
 */
addTimeout :: !GtkTimeout !(GtkM Bool) -> GtkM ()

/**
 * Wrap functionality with `saveState` and `retrieveState`. This is needed if
 * it can be re-entrant, for example when it can trigger signals. See the
 * documentation on `saveState` for more details.
 */
withPossibleCallback :: !(GtkM a) -> GtkM a

/**
 * Some functions can lead to Gtk signals to be emitted. If these signals have
 * handlers set up, the function is re-entrant (may return to Clean code). For
 * this kind of functions, we need to save the `GtkM` state beforehand and
 * retrieve it afterwards, because the signal handler may rely on that state
 * and may modify it. `saveState` saves the state internally; `retrieveState`
 * restores it. `withPossibleCallback` is a convenient wrapper combining both.
 */
saveState :: GtkM ()

//* Retrieve the state saved with `saveState`.
retrieveState :: GtkM GtkState

// The functions below are only exported because they need a foreign export entry point:
handleSignal_void :: !Pointer !Int -> Int
handleSignal_pointer_bool :: !Pointer !Pointer !Int -> Int
handleSignal_int_int_bool :: !Pointer !Int !Int !Int -> Int
handleSignal_int_int_pointer_pointer_bool :: !Pointer !Int !Int !Pointer !Pointer !Int -> Int

handleTimeout :: !Int -> Int