module Graphics.UI.Gtk.Embedding.Types (
Socket(Socket), SocketClass,
toSocket,
mkSocket, unSocket,
castToSocket, gTypeSocket,
Plug(Plug), PlugClass,
toPlug,
mkPlug, unPlug,
castToPlug, gTypePlug,
) where
import Foreign.ForeignPtr (ForeignPtr, castForeignPtr)
import Foreign.ForeignPtr.Unsafe (unsafeForeignPtrToPtr)
import Foreign.C.Types (CULong(..), CUInt(..), CULLong(..))
import System.Glib.GType (GType, typeInstanceIsA)
import System.Glib.GObject
import Graphics.UI.Gtk.General.Threading
import Graphics.UI.Gtk.Types
castTo :: (GObjectClass obj, GObjectClass obj') => GType -> String
-> (obj -> obj')
castTo gtype objTypeName obj =
case toGObject obj of
gobj@(GObject objFPtr)
| typeInstanceIsA ((unsafeForeignPtrToPtr.castForeignPtr) objFPtr) gtype
-> unsafeCastGObject gobj
| otherwise -> error $ "Cannot cast object to " ++ objTypeName
newtype Socket = Socket (ForeignPtr (Socket)) deriving (Eq,Ord)
mkSocket = (Socket, objectUnrefFromMainloop)
unSocket (Socket o) = o
class ContainerClass o => SocketClass o
toSocket :: SocketClass o => o -> Socket
toSocket = unsafeCastGObject . toGObject
instance SocketClass Socket
instance ContainerClass Socket
instance WidgetClass Socket
instance GObjectClass Socket where
toGObject = GObject . castForeignPtr . unSocket
unsafeCastGObject = Socket . castForeignPtr . unGObject
castToSocket :: GObjectClass obj => obj -> Socket
castToSocket = castTo gTypeSocket "Socket"
gTypeSocket :: GType
gTypeSocket =
gtk_socket_get_type
newtype Plug = Plug (ForeignPtr (Plug)) deriving (Eq,Ord)
mkPlug = (Plug, objectUnrefFromMainloop)
unPlug (Plug o) = o
class WindowClass o => PlugClass o
toPlug :: PlugClass o => o -> Plug
toPlug = unsafeCastGObject . toGObject
instance PlugClass Plug
instance WindowClass Plug
instance BinClass Plug
instance ContainerClass Plug
instance WidgetClass Plug
instance GObjectClass Plug where
toGObject = GObject . castForeignPtr . unPlug
unsafeCastGObject = Plug . castForeignPtr . unGObject
castToPlug :: GObjectClass obj => obj -> Plug
castToPlug = castTo gTypePlug "Plug"
gTypePlug :: GType
gTypePlug =
gtk_plug_get_type
foreign import ccall unsafe "gtk_socket_get_type"
gtk_socket_get_type :: CULong
foreign import ccall unsafe "gtk_plug_get_type"
gtk_plug_get_type :: CULong