| 1 |
{-# LANGUAGE CPP #-} |
| 2 |
{-# OPTIONS_HADDOCK hide #-} |
| 3 |
{-# OPTIONS_GHC -fno-warn-unused-imports #-} |
| 4 |
-- -*-haskell-*- |
| 5 |
-- -------------------- automatically generated file - do not edit ---------- |
| 6 |
-- Object hierarchy for the GIMP Toolkit (GTK) Binding for Haskell |
| 7 |
-- |
| 8 |
-- Author : Axel Simon |
| 9 |
-- |
| 10 |
-- Copyright (C) 2001-2005 Axel Simon |
| 11 |
-- |
| 12 |
-- This library is free software; you can redistribute it and/or |
| 13 |
-- modify it under the terms of the GNU Lesser General Public |
| 14 |
-- License as published by the Free Software Foundation; either |
| 15 |
-- version 2.1 of the License, or (at your option) any later version. |
| 16 |
-- |
| 17 |
-- This library is distributed in the hope that it will be useful, |
| 18 |
-- but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 19 |
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 20 |
-- Lesser General Public License for more details. |
| 21 |
-- |
| 22 |
-- #hide |
| 23 |
|
| 24 |
-- | |
| 25 |
-- Maintainer : gtk2hs-users\@lists.sourceforge.net |
| 26 |
-- Stability : provisional |
| 27 |
-- Portability : portable (depends on GHC) |
| 28 |
-- |
| 29 |
-- This file reflects the Gtk+ object hierarchy in terms of Haskell classes. |
| 30 |
-- |
| 31 |
-- Note: the mk... functions were originally meant to simply be an alias |
| 32 |
-- for the constructor. However, in order to communicate the destructor |
| 33 |
-- of an object to objectNew, the mk... functions are now a tuple containing |
| 34 |
-- Haskell constructor and the destructor function pointer. This hack avoids |
| 35 |
-- changing all modules that simply pass mk... to objectNew. |
| 36 |
-- |
| 37 |
module @MODULE_NAME@ ( |
| 38 |
@MODULE_EXPORTS@ |
| 39 |
) where |
| 40 |
|
| 41 |
import Foreign.ForeignPtr (ForeignPtr, castForeignPtr) |
| 42 |
-- TODO work around cpphs https://ghc.haskell.org/trac/ghc/ticket/13553 |
| 43 |
#if __GLASGOW_HASKELL__ >= 707 || __GLASGOW_HASKELL__ == 0 |
| 44 |
import Foreign.ForeignPtr.Unsafe (unsafeForeignPtrToPtr) |
| 45 |
#else |
| 46 |
import Foreign.ForeignPtr (unsafeForeignPtrToPtr) |
| 47 |
#endif |
| 48 |
|
| 49 |
import Foreign.C.Types (CULong(..), CUInt(..), CULLong(..)) |
| 50 |
import System.Glib.GType (GType, typeInstanceIsA) |
| 51 |
@MODULE_IMPORTS@ |
| 52 |
{# context lib="@CONTEXT_LIB@" prefix="@CONTEXT_PREFIX@" #} |
| 53 |
|
| 54 |
-- The usage of foreignPtrToPtr should be safe as the evaluation will only be |
| 55 |
-- forced if the object is used afterwards |
| 56 |
-- |
| 57 |
castTo :: (@ROOTOBJECT@Class obj, @ROOTOBJECT@Class obj') => GType -> String |
| 58 |
-> (obj -> obj') |
| 59 |
castTo gtype objTypeName obj = |
| 60 |
case to@ROOTOBJECT@ obj of |
| 61 |
gobj\@(@ROOTOBJECT@ objFPtr) |
| 62 |
| typeInstanceIsA ((unsafeForeignPtrToPtr.castForeignPtr) objFPtr) gtype |
| 63 |
-> unsafeCast@ROOTOBJECT@ gobj |
| 64 |
| otherwise -> error $ "Cannot cast object to " ++ objTypeName |
| 65 |
|
| 66 |
@DECLARATIONS@ |