File: Types.chs

package info (click to toggle)
haskell-glib 0.13.11.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 260 kB
  • sloc: haskell: 321; ansic: 224; makefile: 3
file content (67 lines) | stat: -rw-r--r-- 1,652 bytes parent folder | download | duplicates (7)
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
{-# OPTIONS_HADDOCK hide #-}
-- -*-haskell-*-
--  GIMP Toolkit (GTK) Widget GObject
--
--  Author : Axel Simon
--
--  Created: 9 April 2001
--
--  Copyright (c) 2001 Axel Simon
--
--  This library is free software; you can redistribute it and/or
--  modify it under the terms of the GNU Lesser General Public
--  License as published by the Free Software Foundation; either
--  version 2.1 of the License, or (at your option) any later version.
--
--  This library is distributed in the hope that it will be useful,
--  but WITHOUT ANY WARRANTY; without even the implied warranty of
--  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
--  Lesser General Public License for more details.
--
-- #hide

-- |
-- Maintainer  : gtk2hs-users@lists.sourceforge.net
-- Stability   : provisional
-- Portability : portable (depends on GHC)
--
-- Implements the base GObject class.
--
module System.Glib.Types (
  GObject(..),
  GObjectClass,
  mkGObject,
  unGObject,
  toGObject,
  unsafeCastGObject,
  castToGObject,
  objectUnref
  ) where

import System.Glib.FFI

{# context lib="glib" prefix="g" #}

{#pointer *GObject foreign newtype #} deriving (Eq)

mkGObject = (GObject, objectUnref)
unGObject (GObject o) = o

class GObjectClass o where
  -- | Safe upcast.
  toGObject         :: o -> GObject
  -- | Unchecked downcast.
  unsafeCastGObject :: GObject -> o

instance GObjectClass GObject where
  toGObject = id
  unsafeCastGObject = id

castToGObject :: GObjectClass obj => obj -> obj
castToGObject = id

-- | Decrease the reference counter of an object
--
foreign import ccall unsafe "&g_object_unref"
  objectUnref :: FinalizerPtr a