    {-# LINE 2 "./Graphics/UI/Gtk/Abstract/Object.chs" #-}
    -- -*-haskell-*-
    -- GIMP Toolkit (GTK) Object
    --
    -- Author : Axel Simon
    --
    -- Created: 9 April 2001
    --
    -- Copyright (C) 2001-2005 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.
    --
    -- |
    -- Maintainer : gtk2hs-users@lists.sourceforge.net
    -- Stability : provisional
    -- Portability : portable (depends on GHC)
    --
    -- The base class of the Gtk+ type hierarchy.
    --
    -- * Each widget is a represented as a purely abstract data type. It can only
    -- be accessed through and the special access functions that are defined
    -- in each widget file.
    --
    module Graphics.UI.Gtk.Abstract.Object (
    -- * Detail
    --
    -- | 'Object' is the base class for all widgets, and for a few non-widget
    -- objects such as 'Adjustment'. 'Object' predates 'GObject'; non-widgets that
    -- derive from 'Object' rather than 'GObject' do so for backward compatibility
    -- reasons.
    --
    -- Object has been removed in Gt3k, but this module still provides useful
    -- functions.

    -- * Class Hierarchy
    -- |
    -- @
    -- | 'GObject'
    -- | +----Object
    -- | +----'Widget'
    -- | +----'Adjustment'
    -- | +----'CellRenderer'
    -- | +----'FileFilter'
    -- | +----'ItemFactory'
    -- | +----'Tooltips'
    -- | +----'TreeViewColumn'
    -- @
    {-# LINE 64 "./Graphics/UI/Gtk/Abstract/Object.chs" #-}
    -- * Methods
      makeNewObject,

    -- * Weak references
      GWeakNotify,
      objectWeakref,
      objectWeakunref,

    -- * Signals
      objectDestroy,
      notifyProperty
      ) where
    import Control.Monad (when)

    import System.Glib.FFI
    import System.Glib.Attributes (ReadWriteAttr)
    import Graphics.UI.Gtk.Types
    {-# LINE 81 "./Graphics/UI/Gtk/Abstract/Object.chs" #-}
    import Graphics.UI.Gtk.Signals
    {-# LINE 82 "./Graphics/UI/Gtk/Abstract/Object.chs" #-}
    import Data.IORef

    {-# LINE 85 "./Graphics/UI/Gtk/Abstract/Object.chs" #-}

    --------------------
    -- Methods

    -- turn the initial floating state to sunk
    --
    -- * The floating\/sunk concept of a GTK object is not very useful to us.
    -- The following procedure circumvents the whole subject and ensures
    -- proper cleanup:
    -- on creation: objectRef, objectSink
    -- on finalization: objectUnref
    --
    -- * This function cannot be bound by c2hs because it is not possible to
    -- override the pointer hook.

    -- This is a convenience function to generate a new widget. It adds the
    -- finalizer with the method described under objectSink.
    --
    -- * The constr argument is the constructor of the specific object.
    --

    makeNewObject :: GObjectClass obj =>

      (ForeignPtr obj -> obj, FinalizerPtr obj) -> IO (Ptr obj) -> IO obj
    makeNewObject :: forall obj.
    GObjectClass obj =>
    (ForeignPtr obj -> obj, FinalizerPtr obj) -> IO (Ptr obj) -> IO obj
    makeNewObject (ForeignPtr obj -> obj
    constr, FinalizerPtr obj
    objectUnref) IO (Ptr obj)
    generator = do
      objPtr <- IO (Ptr obj)
    generator
      when (objPtr == nullPtr) (fail "makeNewObject: object is NULL")

      objectRefSink objPtr

      obj <- newForeignPtr objPtr objectUnref
      return $! constr obj

    type GWeakNotify = FunPtr (((Ptr ()) -> ((Ptr GObject) -> (IO ()))))
    {-# LINE 127 "./Graphics/UI/Gtk/Abstract/Object.chs" #-}

    foreign import ccall "wrapper" mkDestructor
      :: (Ptr () -> Ptr GObject -> IO ()) -> IO GWeakNotify

    -- | Attach a callback that will be called after the
    -- destroy hooks have been called
    --

    objectWeakref :: GObjectClass o => o -> IO () -> IO GWeakNotify

    objectWeakref :: forall o. GObjectClass o => o -> IO () -> IO GWeakNotify
    objectWeakref o
    obj IO ()
    uFun = do
      funPtrContainer <- GWeakNotify -> IO (IORef GWeakNotify)
    forall a. a -> IO (IORef a)
    newIORef GWeakNotify
    forall a. FunPtr a
    nullFunPtr
      uFunPtr <- mkDestructor $ \Ptr ()
    _ Ptr GObject
    _ -> do
        IO ()
    uFun
        funPtr <- IORef GWeakNotify -> IO GWeakNotify
    forall a. IORef a -> IO a
    readIORef IORef GWeakNotify
    funPtrContainer
        freeHaskellFunPtr funPtr
      writeIORef funPtrContainer uFunPtr
      (\(GObject ForeignPtr GObject
    arg1) GWeakNotify
    arg2 Ptr ()
    arg3 -> ForeignPtr GObject -> (Ptr GObject -> IO ()) -> IO ()
    forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
    withForeignPtr ForeignPtr GObject
    arg1 ((Ptr GObject -> IO ()) -> IO ())
    -> (Ptr GObject -> IO ()) -> IO ()
    forall a b. (a -> b) -> a -> b
    $ \Ptr GObject
    argPtr1 ->Ptr GObject -> GWeakNotify -> Ptr () -> IO ()
    g_object_weak_ref Ptr GObject
    argPtr1 GWeakNotify
    arg2 Ptr ()
    arg3) (toGObject obj) uFunPtr nullPtr
      return uFunPtr

    -- | Detach a weak destroy callback function
    --

    objectWeakunref :: GObjectClass o => o -> GWeakNotify -> IO ()

    objectWeakunref :: forall o. GObjectClass o => o -> GWeakNotify -> IO ()
    objectWeakunref o
    obj GWeakNotify
    fun =
      (\(GObject ForeignPtr GObject
    arg1) GWeakNotify
    arg2 Ptr ()
    arg3 -> ForeignPtr GObject -> (Ptr GObject -> IO ()) -> IO ()
    forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
    withForeignPtr ForeignPtr GObject
    arg1 ((Ptr GObject -> IO ()) -> IO ())
    -> (Ptr GObject -> IO ()) -> IO ()
    forall a b. (a -> b) -> a -> b
    $ \Ptr GObject
    argPtr1 ->Ptr GObject -> GWeakNotify -> Ptr () -> IO ()
    g_object_weak_unref Ptr GObject
    argPtr1 GWeakNotify
    arg2 Ptr ()
    arg3) (o -> GObject
    forall o. GObjectClass o => o -> GObject
    toGObject o
    obj) GWeakNotify
    fun Ptr ()
    forall a. Ptr a
    nullPtr

    --------------------
    -- Signals

    -- | Signals that all holders of a reference to the 'Object' should release
    -- the reference that they hold. May result in finalization of the object if
    -- all references are released.
    --

    objectDestroy :: WidgetClass self => Signal self (IO ())

    objectDestroy :: forall self. WidgetClass self => Signal self (IO ())
    objectDestroy = (Bool -> self -> IO () -> IO (ConnectId self))
    -> Signal self (IO ())
    forall object handler.
    (Bool -> object -> handler -> IO (ConnectId object))
    -> Signal object handler
    Signal (String -> Bool -> self -> IO () -> IO (ConnectId self)
    forall obj.
    GObjectClass obj =>
    String -> Bool -> obj -> IO () -> IO (ConnectId obj)
    connect_NONE__NONE String
    "destroy")

    -- | Register a notify callback that is triggered when the given property
    -- has been modified.
    --
    -- * Note that this callback is triggered even if the actual value of
    -- the property has not changed.
    -- * Not all attributes are properties. A warning will be generated at
    -- runtime if the passed-in attribute is not a property of the class
    -- with which it was registered.
    --

    notifyProperty :: GObjectClass self => ReadWriteAttr self a b -> Signal self (IO ())

    notifyProperty :: forall self a b.
    GObjectClass self =>
    ReadWriteAttr self a b -> Signal self (IO ())
    notifyProperty ReadWriteAttr self a b
    attr = (Bool -> self -> IO () -> IO (ConnectId self))
    -> Signal self (IO ())
    forall object handler.
    (Bool -> object -> handler -> IO (ConnectId object))
    -> Signal object handler
    Signal (\Bool
    on self
    obj IO ()
    cb -> String
    -> Bool
    -> self
    -> (Ptr (ZonkAny 0) -> IO ())
    -> IO (ConnectId self)
    forall obj a.
    GObjectClass obj =>
    String -> Bool -> obj -> (Ptr a -> IO ()) -> IO (ConnectId obj)
    connect_PTR__NONE (String
    "notify::"String -> String -> String
    forall a. [a] -> [a] -> [a]
    ++ReadWriteAttr self a b -> String
    forall a. Show a => a -> String
    show ReadWriteAttr self a b
    attr) Bool
    on self
    obj (IO () -> Ptr (ZonkAny 0) -> IO ()
    forall a b. a -> b -> a
    const IO ()
    cb))

    foreign import ccall unsafe "g_object_weak_ref"
      g_object_weak_ref :: ((Ptr GObject) -> ((FunPtr ((Ptr ()) -> ((Ptr GObject) -> (IO ())))) -> ((Ptr ()) -> (IO ()))))

    foreign import ccall unsafe "g_object_weak_unref"
      g_object_weak_unref :: ((Ptr GObject) -> ((FunPtr ((Ptr ()) -> ((Ptr GObject) -> (IO ())))) -> ((Ptr ()) -> (IO ()))))