    {-# LINE 2 "./Graphics/UI/Gtk/Embedding/Plug.chs" #-}
    -- -*-haskell-*-
    -- GIMP Toolkit (GTK) Widget Plug
    --
    -- Author : Axel Simon, Andy Stewart
    --
    -- Created: 23 May 2001
    --
    -- Copyright (C) 1999-2005 Axel Simon
    -- Copyright (C) 2009 Andy Stewart
    --
    -- 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)
    --
    -- Toplevel for embedding into other processes
    --
    module Graphics.UI.Gtk.Embedding.Plug (
    -- * Detail
    --
    -- | Together with 'Socket', 'Plug' provides the ability to embed widgets from
    -- one process into another process in a fashion that is transparent to the
    -- user. One process creates a 'Socket' widget and, passes the ID of that
    -- widgets window to the other process, which then creates a 'Plug' with that
    -- window ID. Any widgets contained in the 'Plug' then will appear inside the
    -- first applications window.

    -- * Class Hierarchy
    -- |
    -- @
    -- | 'GObject'
    -- | +----'Object'
    -- | +----'Widget'
    -- | +----'Container'
    -- | +----'Bin'
    -- | +----'Window'
    -- | +----Plug
    -- @

    -- * Types
      Plug,
      PlugClass,
      castToPlug, gTypePlug,
      toPlug,
      NativeWindowId,

    -- * Constructors
      plugNew,

      plugNewForDisplay,

    -- * Methods
      plugGetId,

      plugGetEmbedded,
      plugGetSocketWindow,

    -- * Attributes
      plugAttrEmbedded,
      plugAttrSocketWindow,

    -- * Signals
      plugEmbedded,

      ) where

    import Control.Monad (liftM)
    import Data.Maybe (fromMaybe)

    import System.Glib.FFI
    import System.Glib.Attributes
    import System.Glib.Properties
    import Graphics.UI.Gtk.Abstract.Object (makeNewObject)
    import Graphics.UI.Gtk.Types
    {-# LINE 91 "./Graphics/UI/Gtk/Embedding/Plug.chs" #-}
    import Graphics.UI.Gtk.Embedding.Types
    {-# LINE 92 "./Graphics/UI/Gtk/Embedding/Plug.chs" #-}
    import Graphics.UI.Gtk.Signals
    {-# LINE 93 "./Graphics/UI/Gtk/Embedding/Plug.chs" #-}

    import Graphics.UI.Gtk.General.Structs

    {-# LINE 99 "./Graphics/UI/Gtk/Embedding/Plug.chs" #-}

    --------------------
    -- Constructors

    -- | Creates a new plug widget inside the 'Socket' identified by @socketId@.
    -- If @socketId@ is @Nothing@, the plug is left \"unplugged\" and can later be
    -- plugged into a 'Socket' by 'Graphics.UI.Gtk.Embedding.Socket.socketAddId'.
    --
    -- If a NativeWindowId is supplied the foreign application window will
    -- immediately appear in this 'Plug' once it is shown. If @Nothing@ is passed
    -- then a 'NativeWindowId' can be extracted from this 'Plug' using 'plugGetId'
    -- and be passed to the application which is to be embedded.
    --
    plugNew ::
      Maybe NativeWindowId -- ^ @socketId@ - the window ID of the socket, or
                           -- @Nothing@.
     -> IO Plug
    plugNew :: Maybe NativeWindowId -> IO Plug
    plugNew Maybe NativeWindowId
    socketId =
      (ForeignPtr Plug -> Plug, FinalizerPtr Plug)
    -> IO (Ptr Plug) -> IO Plug
    forall obj.
    GObjectClass obj =>
    (ForeignPtr obj -> obj, FinalizerPtr obj) -> IO (Ptr obj) -> IO obj
    makeNewObject (ForeignPtr Plug -> Plug, FinalizerPtr Plug)
    forall {a}. (ForeignPtr Plug -> Plug, FinalizerPtr a)
    mkPlug (IO (Ptr Plug) -> IO Plug) -> IO (Ptr Plug) -> IO Plug
    forall a b. (a -> b) -> a -> b
    $
      (Ptr Widget -> Ptr Plug) -> IO (Ptr Widget) -> IO (Ptr Plug)
    forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
    liftM (Ptr Widget -> Ptr Plug
    forall a b. Ptr a -> Ptr b
    castPtr :: Ptr Widget -> Ptr Plug) (IO (Ptr Widget) -> IO (Ptr Plug))
    -> IO (Ptr Widget) -> IO (Ptr Plug)
    forall a b. (a -> b) -> a -> b
    $
      CULong -> IO (Ptr Widget)
    gtk_plug_new
    {-# LINE 120 "./Graphics/UI/Gtk/Embedding/Plug.chs" #-}
        (fromNativeWindowId (fromMaybe nativeWindowIdNone socketId))

    -- | Create a new plug widget inside the 'Socket' identified by socket_id.
    --
    -- * Available since Gtk+ version 2.2
    --
    plugNewForDisplay ::
        Display -- ^ @display@ - the 'Display' on which @socketId@ is
                            -- displayed
     -> Maybe NativeWindowId -- ^ @socketId@ - the XID of the socket's window.
     -> IO Plug
    plugNewForDisplay :: Display -> Maybe NativeWindowId -> IO Plug
    plugNewForDisplay Display
    display Maybe NativeWindowId
    socketId =
      (ForeignPtr Plug -> Plug, FinalizerPtr Plug)
    -> IO (Ptr Plug) -> IO Plug
    forall obj.
    GObjectClass obj =>
    (ForeignPtr obj -> obj, FinalizerPtr obj) -> IO (Ptr obj) -> IO obj
    makeNewObject (ForeignPtr Plug -> Plug, FinalizerPtr Plug)
    forall {a}. (ForeignPtr Plug -> Plug, FinalizerPtr a)
    mkPlug (IO (Ptr Plug) -> IO Plug) -> IO (Ptr Plug) -> IO Plug
    forall a b. (a -> b) -> a -> b
    $
      (Ptr Widget -> Ptr Plug) -> IO (Ptr Widget) -> IO (Ptr Plug)
    forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
    liftM (Ptr Widget -> Ptr Plug
    forall a b. Ptr a -> Ptr b
    castPtr :: Ptr Widget -> Ptr Plug) (IO (Ptr Widget) -> IO (Ptr Plug))
    -> IO (Ptr Widget) -> IO (Ptr Plug)
    forall a b. (a -> b) -> a -> b
    $
      (\(Display ForeignPtr Display
    arg1) CULong
    arg2 -> ForeignPtr Display
    -> (Ptr Display -> IO (Ptr Widget)) -> IO (Ptr Widget)
    forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
    withForeignPtr ForeignPtr Display
    arg1 ((Ptr Display -> IO (Ptr Widget)) -> IO (Ptr Widget))
    -> (Ptr Display -> IO (Ptr Widget)) -> IO (Ptr Widget)
    forall a b. (a -> b) -> a -> b
    $ \Ptr Display
    argPtr1 ->Ptr Display -> CULong -> IO (Ptr Widget)
    gtk_plug_new_for_display Ptr Display
    argPtr1 CULong
    arg2)
    {-# LINE 136 "./Graphics/UI/Gtk/Embedding/Plug.chs" #-}
        display
        (NativeWindowId -> CULong
    forall a. Integral a => NativeWindowId -> a
    fromNativeWindowId (NativeWindowId -> Maybe NativeWindowId -> NativeWindowId
    forall a. a -> Maybe a -> a
    fromMaybe NativeWindowId
    nativeWindowIdNone Maybe NativeWindowId
    socketId))

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

    -- | Gets the window ID of a 'Plug' widget, which can then be used to embed
    -- this window inside another window, for instance with
    -- 'Graphics.UI.Gtk.Embedding.Socket.socketAddId'.
    --
    plugGetId :: PlugClass self => self
     -> IO NativeWindowId -- ^ returns the window ID for the plug
    plugGetId :: forall self. PlugClass self => self -> IO NativeWindowId
    plugGetId self
    self =
      (CULong -> NativeWindowId) -> IO CULong -> IO NativeWindowId
    forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
    liftM CULong -> NativeWindowId
    forall a. Integral a => a -> NativeWindowId
    toNativeWindowId (IO CULong -> IO NativeWindowId) -> IO CULong -> IO NativeWindowId
    forall a b. (a -> b) -> a -> b
    $
      (\(Plug ForeignPtr Plug
    arg1) -> ForeignPtr Plug -> (Ptr Plug -> IO CULong) -> IO CULong
    forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
    withForeignPtr ForeignPtr Plug
    arg1 ((Ptr Plug -> IO CULong) -> IO CULong)
    -> (Ptr Plug -> IO CULong) -> IO CULong
    forall a b. (a -> b) -> a -> b
    $ \Ptr Plug
    argPtr1 ->Ptr Plug -> IO CULong
    gtk_plug_get_id Ptr Plug
    argPtr1)
    {-# LINE 152 "./Graphics/UI/Gtk/Embedding/Plug.chs" #-}
        (toPlug self)

    -- | Determines whether the plug is embedded in a socket.
    --
    -- * Available since Gtk+ version 2.14
    --
    plugGetEmbedded :: PlugClass self => self
     -> IO Bool -- ^ returns @True@ if the plug is embedded in a socket
    plugGetEmbedded :: forall self. PlugClass self => self -> IO Bool
    plugGetEmbedded self
    self =
      (CInt -> Bool) -> IO CInt -> IO Bool
    forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
    liftM CInt -> Bool
    forall a. (Eq a, Num a) => a -> Bool
    toBool (IO CInt -> IO Bool) -> IO CInt -> IO Bool
    forall a b. (a -> b) -> a -> b
    $
      (\(Plug ForeignPtr Plug
    arg1) -> ForeignPtr Plug -> (Ptr Plug -> IO CInt) -> IO CInt
    forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
    withForeignPtr ForeignPtr Plug
    arg1 ((Ptr Plug -> IO CInt) -> IO CInt)
    -> (Ptr Plug -> IO CInt) -> IO CInt
    forall a b. (a -> b) -> a -> b
    $ \Ptr Plug
    argPtr1 ->Ptr Plug -> IO CInt
    gtk_plug_get_embedded Ptr Plug
    argPtr1)
    {-# LINE 164 "./Graphics/UI/Gtk/Embedding/Plug.chs" #-}
        (toPlug self)

    -- | Retrieves the socket the plug is embedded in.
    --
    -- * Available since Gtk+ version 2.14
    --
    plugGetSocketWindow :: PlugClass self => self
     -> IO (Maybe DrawWindow) -- ^ returns the window of the socket
    plugGetSocketWindow :: forall self. PlugClass self => self -> IO (Maybe DrawWindow)
    plugGetSocketWindow self
    self =
      (IO (Ptr DrawWindow) -> IO DrawWindow)
    -> IO (Ptr DrawWindow) -> IO (Maybe DrawWindow)
    forall a. (IO (Ptr a) -> IO a) -> IO (Ptr a) -> IO (Maybe a)
    maybeNull ((ForeignPtr DrawWindow -> DrawWindow, FinalizerPtr DrawWindow)
    -> IO (Ptr DrawWindow) -> IO DrawWindow
    forall obj.
    GObjectClass obj =>
    (ForeignPtr obj -> obj, FinalizerPtr obj) -> IO (Ptr obj) -> IO obj
    makeNewGObject (ForeignPtr DrawWindow -> DrawWindow, FinalizerPtr DrawWindow)
    forall {a}. (ForeignPtr DrawWindow -> DrawWindow, FinalizerPtr a)
    mkDrawWindow) (IO (Ptr DrawWindow) -> IO (Maybe DrawWindow))
    -> IO (Ptr DrawWindow) -> IO (Maybe DrawWindow)
    forall a b. (a -> b) -> a -> b
    $
      (\(Plug ForeignPtr Plug
    arg1) -> ForeignPtr Plug
    -> (Ptr Plug -> IO (Ptr DrawWindow)) -> IO (Ptr DrawWindow)
    forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
    withForeignPtr ForeignPtr Plug
    arg1 ((Ptr Plug -> IO (Ptr DrawWindow)) -> IO (Ptr DrawWindow))
    -> (Ptr Plug -> IO (Ptr DrawWindow)) -> IO (Ptr DrawWindow)
    forall a b. (a -> b) -> a -> b
    $ \Ptr Plug
    argPtr1 ->Ptr Plug -> IO (Ptr DrawWindow)
    gtk_plug_get_socket_window Ptr Plug
    argPtr1)
    {-# LINE 175 "./Graphics/UI/Gtk/Embedding/Plug.chs" #-}
        (toPlug self)

    --------------------
    -- Attributes

    -- | @True@ if the plug is embedded in a socket.
    --
    -- Default value: @False@
    --
    -- * Available since Gtk+ version 2.12
    --
    plugAttrEmbedded :: PlugClass self => ReadAttr self Bool
    plugAttrEmbedded :: forall self. PlugClass self => ReadAttr self Bool
    plugAttrEmbedded = String -> ReadAttr self Bool
    forall gobj. GObjectClass gobj => String -> ReadAttr gobj Bool
    readAttrFromBoolProperty String
    "embedded"

    -- | The window of the socket the plug is embedded in.
    --
    -- * Available since Gtk+ version 2.14
    --
    plugAttrSocketWindow :: PlugClass self => ReadAttr self (Maybe DrawWindow)
    plugAttrSocketWindow :: forall self. PlugClass self => ReadAttr self (Maybe DrawWindow)
    plugAttrSocketWindow = String -> CULong -> ReadAttr self (Maybe DrawWindow)
    forall gobj gobj'.
    (GObjectClass gobj, GObjectClass gobj') =>
    String -> CULong -> ReadAttr gobj (Maybe gobj')
    readAttrFromMaybeObjectProperty String
    "socket-window"

                           CULong
    gdk_window_get_type
    {-# LINE 200 "./Graphics/UI/Gtk/Embedding/Plug.chs" #-}

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

    -- | Gets emitted when the plug becomes embedded in a socket and when the
    -- embedding ends.
    --
    plugEmbedded :: PlugClass self => Signal self (IO ())
    plugEmbedded :: forall self. PlugClass self => Signal self (IO ())
    plugEmbedded = (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
    "embedded")

    foreign import ccall unsafe "gtk_plug_new"
      gtk_plug_new :: (CULong -> (IO (Ptr Widget)))

    foreign import ccall safe "gtk_plug_new_for_display"
      gtk_plug_new_for_display :: ((Ptr Display) -> (CULong -> (IO (Ptr Widget))))

    foreign import ccall unsafe "gtk_plug_get_id"
      gtk_plug_get_id :: ((Ptr Plug) -> (IO CULong))

    foreign import ccall safe "gtk_plug_get_embedded"
      gtk_plug_get_embedded :: ((Ptr Plug) -> (IO CInt))

    foreign import ccall safe "gtk_plug_get_socket_window"
      gtk_plug_get_socket_window :: ((Ptr Plug) -> (IO (Ptr DrawWindow)))

    foreign import ccall unsafe "gdk_window_get_type"
      gdk_window_get_type :: CULong