{-# LANGUAGE TypeApplications #-}


-- | Copyright  : Will Thompson, Iñaki García Etxebarria and Jonas Platte
-- License    : LGPL-2.1
-- Maintainer : Iñaki García Etxebarria
-- 
-- t'GI.Gtk.Objects.CustomLayout.CustomLayout' is a convenience type meant to be used as a transition
-- mechanism between @/GtkWidgets/@ implementing a layout policy, and
-- t'GI.Gtk.Objects.LayoutManager.LayoutManager' classes.
-- 
-- A t'GI.Gtk.Objects.CustomLayout.CustomLayout' uses closures matching to the old t'GI.Gtk.Objects.Widget.Widget' virtual
-- functions for size negotiation, as a convenience API to ease the porting
-- towards the corresponding t'GI.Gtk.Objects.LayoutManager.LayoutManager' virtual functions.

#if (MIN_VERSION_haskell_gi_overloading(1,0,0) && !defined(__HADDOCK_VERSION__))
#define ENABLE_OVERLOADING
#endif

module GI.Gtk.Objects.CustomLayout
    ( 

-- * Exported types
    CustomLayout(..)                        ,
    IsCustomLayout                          ,
    toCustomLayout                          ,


 -- * Methods
-- ** Overloaded methods #method:Overloaded methods#

#if defined(ENABLE_OVERLOADING)
    ResolveCustomLayoutMethod               ,
#endif


-- ** new #method:new#

    customLayoutNew                         ,




    ) where

import Data.GI.Base.ShortPrelude
import qualified Data.GI.Base.ShortPrelude as SP
import qualified Data.GI.Base.Overloading as O
import qualified Prelude as P

import qualified Data.GI.Base.Attributes as GI.Attributes
import qualified Data.GI.Base.BasicTypes as B.Types
import qualified Data.GI.Base.ManagedPtr as B.ManagedPtr
import qualified Data.GI.Base.GClosure as B.GClosure
import qualified Data.GI.Base.GError as B.GError
import qualified Data.GI.Base.GVariant as B.GVariant
import qualified Data.GI.Base.GValue as B.GValue
import qualified Data.GI.Base.GParamSpec as B.GParamSpec
import qualified Data.GI.Base.CallStack as B.CallStack
import qualified Data.GI.Base.Properties as B.Properties
import qualified Data.GI.Base.Signals as B.Signals
import qualified Control.Monad.IO.Class as MIO
import qualified Data.Text as T
import qualified Data.ByteString.Char8 as B
import qualified Data.Map as Map
import qualified Foreign.Ptr as FP
import qualified GHC.OverloadedLabels as OL

import qualified GI.GObject.Objects.Object as GObject.Object
import qualified GI.Gtk.Callbacks as Gtk.Callbacks
import {-# SOURCE #-} qualified GI.Gtk.Objects.LayoutManager as Gtk.LayoutManager

-- | Memory-managed wrapper type.
newtype CustomLayout = CustomLayout (SP.ManagedPtr CustomLayout)
    deriving (CustomLayout -> CustomLayout -> Bool
(CustomLayout -> CustomLayout -> Bool)
-> (CustomLayout -> CustomLayout -> Bool) -> Eq CustomLayout
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CustomLayout -> CustomLayout -> Bool
$c/= :: CustomLayout -> CustomLayout -> Bool
== :: CustomLayout -> CustomLayout -> Bool
$c== :: CustomLayout -> CustomLayout -> Bool
Eq)

instance SP.ManagedPtrNewtype CustomLayout where
    toManagedPtr :: CustomLayout -> ManagedPtr CustomLayout
toManagedPtr (CustomLayout ManagedPtr CustomLayout
p) = ManagedPtr CustomLayout
p

foreign import ccall "gtk_custom_layout_get_type"
    c_gtk_custom_layout_get_type :: IO B.Types.GType

instance B.Types.TypedObject CustomLayout where
    glibType :: IO GType
glibType = IO GType
c_gtk_custom_layout_get_type

instance B.Types.GObject CustomLayout

-- | Convert 'CustomLayout' to and from 'Data.GI.Base.GValue.GValue' with 'Data.GI.Base.GValue.toGValue' and 'Data.GI.Base.GValue.fromGValue'.
instance B.GValue.IsGValue CustomLayout where
    toGValue :: CustomLayout -> IO GValue
toGValue CustomLayout
o = do
        GType
gtype <- IO GType
c_gtk_custom_layout_get_type
        CustomLayout -> (Ptr CustomLayout -> IO GValue) -> IO GValue
forall a c.
(HasCallStack, ManagedPtrNewtype a) =>
a -> (Ptr a -> IO c) -> IO c
B.ManagedPtr.withManagedPtr CustomLayout
o (GType
-> (GValue -> Ptr CustomLayout -> IO ())
-> Ptr CustomLayout
-> IO GValue
forall a. GType -> (GValue -> a -> IO ()) -> a -> IO GValue
B.GValue.buildGValue GType
gtype GValue -> Ptr CustomLayout -> IO ()
forall a. GObject a => GValue -> Ptr a -> IO ()
B.GValue.set_object)
        
    fromGValue :: GValue -> IO CustomLayout
fromGValue GValue
gv = do
        Ptr CustomLayout
ptr <- GValue -> IO (Ptr CustomLayout)
forall b. GObject b => GValue -> IO (Ptr b)
B.GValue.get_object GValue
gv :: IO (Ptr CustomLayout)
        (ManagedPtr CustomLayout -> CustomLayout)
-> Ptr CustomLayout -> IO CustomLayout
forall a b.
(HasCallStack, GObject a, GObject b) =>
(ManagedPtr a -> a) -> Ptr b -> IO a
B.ManagedPtr.newObject ManagedPtr CustomLayout -> CustomLayout
CustomLayout Ptr CustomLayout
ptr
        
    

-- | Type class for types which can be safely cast to `CustomLayout`, for instance with `toCustomLayout`.
class (SP.GObject o, O.IsDescendantOf CustomLayout o) => IsCustomLayout o
instance (SP.GObject o, O.IsDescendantOf CustomLayout o) => IsCustomLayout o

instance O.HasParentTypes CustomLayout
type instance O.ParentTypes CustomLayout = '[Gtk.LayoutManager.LayoutManager, GObject.Object.Object]

-- | Cast to `CustomLayout`, for types for which this is known to be safe. For general casts, use `Data.GI.Base.ManagedPtr.castTo`.
toCustomLayout :: (MonadIO m, IsCustomLayout o) => o -> m CustomLayout
toCustomLayout :: o -> m CustomLayout
toCustomLayout = IO CustomLayout -> m CustomLayout
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO CustomLayout -> m CustomLayout)
-> (o -> IO CustomLayout) -> o -> m CustomLayout
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ManagedPtr CustomLayout -> CustomLayout) -> o -> IO CustomLayout
forall o o'.
(HasCallStack, ManagedPtrNewtype o, TypedObject o,
 ManagedPtrNewtype o', TypedObject o') =>
(ManagedPtr o' -> o') -> o -> IO o'
unsafeCastTo ManagedPtr CustomLayout -> CustomLayout
CustomLayout

#if defined(ENABLE_OVERLOADING)
type family ResolveCustomLayoutMethod (t :: Symbol) (o :: *) :: * where
    ResolveCustomLayoutMethod "allocate" o = Gtk.LayoutManager.LayoutManagerAllocateMethodInfo
    ResolveCustomLayoutMethod "bindProperty" o = GObject.Object.ObjectBindPropertyMethodInfo
    ResolveCustomLayoutMethod "bindPropertyFull" o = GObject.Object.ObjectBindPropertyFullMethodInfo
    ResolveCustomLayoutMethod "forceFloating" o = GObject.Object.ObjectForceFloatingMethodInfo
    ResolveCustomLayoutMethod "freezeNotify" o = GObject.Object.ObjectFreezeNotifyMethodInfo
    ResolveCustomLayoutMethod "getv" o = GObject.Object.ObjectGetvMethodInfo
    ResolveCustomLayoutMethod "isFloating" o = GObject.Object.ObjectIsFloatingMethodInfo
    ResolveCustomLayoutMethod "layoutChanged" o = Gtk.LayoutManager.LayoutManagerLayoutChangedMethodInfo
    ResolveCustomLayoutMethod "measure" o = Gtk.LayoutManager.LayoutManagerMeasureMethodInfo
    ResolveCustomLayoutMethod "notify" o = GObject.Object.ObjectNotifyMethodInfo
    ResolveCustomLayoutMethod "notifyByPspec" o = GObject.Object.ObjectNotifyByPspecMethodInfo
    ResolveCustomLayoutMethod "ref" o = GObject.Object.ObjectRefMethodInfo
    ResolveCustomLayoutMethod "refSink" o = GObject.Object.ObjectRefSinkMethodInfo
    ResolveCustomLayoutMethod "runDispose" o = GObject.Object.ObjectRunDisposeMethodInfo
    ResolveCustomLayoutMethod "stealData" o = GObject.Object.ObjectStealDataMethodInfo
    ResolveCustomLayoutMethod "stealQdata" o = GObject.Object.ObjectStealQdataMethodInfo
    ResolveCustomLayoutMethod "thawNotify" o = GObject.Object.ObjectThawNotifyMethodInfo
    ResolveCustomLayoutMethod "unref" o = GObject.Object.ObjectUnrefMethodInfo
    ResolveCustomLayoutMethod "watchClosure" o = GObject.Object.ObjectWatchClosureMethodInfo
    ResolveCustomLayoutMethod "getData" o = GObject.Object.ObjectGetDataMethodInfo
    ResolveCustomLayoutMethod "getLayoutChild" o = Gtk.LayoutManager.LayoutManagerGetLayoutChildMethodInfo
    ResolveCustomLayoutMethod "getProperty" o = GObject.Object.ObjectGetPropertyMethodInfo
    ResolveCustomLayoutMethod "getQdata" o = GObject.Object.ObjectGetQdataMethodInfo
    ResolveCustomLayoutMethod "getRequestMode" o = Gtk.LayoutManager.LayoutManagerGetRequestModeMethodInfo
    ResolveCustomLayoutMethod "getWidget" o = Gtk.LayoutManager.LayoutManagerGetWidgetMethodInfo
    ResolveCustomLayoutMethod "setData" o = GObject.Object.ObjectSetDataMethodInfo
    ResolveCustomLayoutMethod "setDataFull" o = GObject.Object.ObjectSetDataFullMethodInfo
    ResolveCustomLayoutMethod "setProperty" o = GObject.Object.ObjectSetPropertyMethodInfo
    ResolveCustomLayoutMethod l o = O.MethodResolutionFailed l o

instance (info ~ ResolveCustomLayoutMethod t CustomLayout, O.MethodInfo info CustomLayout p) => OL.IsLabel t (CustomLayout -> p) where
#if MIN_VERSION_base(4,10,0)
    fromLabel = O.overloadedMethod @info
#else
    fromLabel _ = O.overloadedMethod @info
#endif

#endif

#if defined(ENABLE_OVERLOADING)
instance O.HasAttributeList CustomLayout
type instance O.AttributeList CustomLayout = CustomLayoutAttributeList
type CustomLayoutAttributeList = ('[ ] :: [(Symbol, *)])
#endif

#if defined(ENABLE_OVERLOADING)
#endif

#if defined(ENABLE_OVERLOADING)
type instance O.SignalList CustomLayout = CustomLayoutSignalList
type CustomLayoutSignalList = ('[ '("notify", GObject.Object.ObjectNotifySignalInfo)] :: [(Symbol, *)])

#endif

-- method CustomLayout::new
-- method type : Constructor
-- Args: [ Arg
--           { argCName = "request_mode"
--           , argType =
--               TInterface
--                 Name { namespace = "Gtk" , name = "CustomRequestModeFunc" }
--           , direction = DirectionIn
--           , mayBeNull = True
--           , argDoc =
--               Documentation
--                 { rawDocText =
--                     Just
--                       "a function to retrieve\n  the #GtkSizeRequestMode of the widget using the layout; the\n  default request mode is %GTK_SIZE_REQUEST_CONSTANT_SIZE"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeCall
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "measure"
--           , argType =
--               TInterface Name { namespace = "Gtk" , name = "CustomMeasureFunc" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText =
--                     Just "a function to measure the widget using the layout manager"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeCall
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "allocate"
--           , argType =
--               TInterface Name { namespace = "Gtk" , name = "CustomAllocateFunc" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText =
--                     Just
--                       "a function to allocate the children of the widget using\n  the layout manager"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeCall
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       ]
-- Lengths: []
-- returnType: Just
--               (TInterface Name { namespace = "Gtk" , name = "CustomLayout" })
-- throws : False
-- Skip return : False

foreign import ccall "gtk_custom_layout_new" gtk_custom_layout_new :: 
    FunPtr Gtk.Callbacks.C_CustomRequestModeFunc -> -- request_mode : TInterface (Name {namespace = "Gtk", name = "CustomRequestModeFunc"})
    FunPtr Gtk.Callbacks.C_CustomMeasureFunc -> -- measure : TInterface (Name {namespace = "Gtk", name = "CustomMeasureFunc"})
    FunPtr Gtk.Callbacks.C_CustomAllocateFunc -> -- allocate : TInterface (Name {namespace = "Gtk", name = "CustomAllocateFunc"})
    IO (Ptr CustomLayout)

-- | Creates a new legacy layout manager.
-- 
-- Legacy layout managers map to the old t'GI.Gtk.Objects.Widget.Widget' size negotiation
-- virtual functions, and are meant to be used during the transition
-- from layout containers to layout manager delegates.
customLayoutNew ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    Maybe (Gtk.Callbacks.CustomRequestModeFunc)
    -- ^ /@requestMode@/: a function to retrieve
    --   the t'GI.Gtk.Enums.SizeRequestMode' of the widget using the layout; the
    --   default request mode is 'GI.Gtk.Enums.SizeRequestModeConstantSize'
    -> Gtk.Callbacks.CustomMeasureFunc
    -- ^ /@measure@/: a function to measure the widget using the layout manager
    -> Gtk.Callbacks.CustomAllocateFunc
    -- ^ /@allocate@/: a function to allocate the children of the widget using
    --   the layout manager
    -> m CustomLayout
    -- ^ __Returns:__ the newly created t'GI.Gtk.Objects.CustomLayout.CustomLayout'
customLayoutNew :: Maybe CustomRequestModeFunc
-> CustomMeasureFunc -> CustomAllocateFunc -> m CustomLayout
customLayoutNew Maybe CustomRequestModeFunc
requestMode CustomMeasureFunc
measure CustomAllocateFunc
allocate = IO CustomLayout -> m CustomLayout
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO CustomLayout -> m CustomLayout)
-> IO CustomLayout -> m CustomLayout
forall a b. (a -> b) -> a -> b
$ do
    FunPtr C_CustomRequestModeFunc
maybeRequestMode <- case Maybe CustomRequestModeFunc
requestMode of
        Maybe CustomRequestModeFunc
Nothing -> FunPtr C_CustomRequestModeFunc
-> IO (FunPtr C_CustomRequestModeFunc)
forall (m :: * -> *) a. Monad m => a -> m a
return (Ptr Any -> FunPtr C_CustomRequestModeFunc
forall a b. Ptr a -> FunPtr b
castPtrToFunPtr Ptr Any
forall a. Ptr a
nullPtr)
        Just CustomRequestModeFunc
jRequestMode -> do
            FunPtr C_CustomRequestModeFunc
jRequestMode' <- C_CustomRequestModeFunc -> IO (FunPtr C_CustomRequestModeFunc)
Gtk.Callbacks.mk_CustomRequestModeFunc (Maybe (Ptr (FunPtr C_CustomRequestModeFunc))
-> CustomRequestModeFunc -> C_CustomRequestModeFunc
Gtk.Callbacks.wrap_CustomRequestModeFunc Maybe (Ptr (FunPtr C_CustomRequestModeFunc))
forall a. Maybe a
Nothing CustomRequestModeFunc
jRequestMode)
            FunPtr C_CustomRequestModeFunc
-> IO (FunPtr C_CustomRequestModeFunc)
forall (m :: * -> *) a. Monad m => a -> m a
return FunPtr C_CustomRequestModeFunc
jRequestMode'
    FunPtr C_CustomMeasureFunc
measure' <- C_CustomMeasureFunc -> IO (FunPtr C_CustomMeasureFunc)
Gtk.Callbacks.mk_CustomMeasureFunc (Maybe (Ptr (FunPtr C_CustomMeasureFunc))
-> CustomMeasureFunc -> C_CustomMeasureFunc
Gtk.Callbacks.wrap_CustomMeasureFunc Maybe (Ptr (FunPtr C_CustomMeasureFunc))
forall a. Maybe a
Nothing CustomMeasureFunc
measure)
    FunPtr C_CustomAllocateFunc
allocate' <- C_CustomAllocateFunc -> IO (FunPtr C_CustomAllocateFunc)
Gtk.Callbacks.mk_CustomAllocateFunc (Maybe (Ptr (FunPtr C_CustomAllocateFunc))
-> CustomAllocateFunc -> C_CustomAllocateFunc
Gtk.Callbacks.wrap_CustomAllocateFunc Maybe (Ptr (FunPtr C_CustomAllocateFunc))
forall a. Maybe a
Nothing CustomAllocateFunc
allocate)
    Ptr CustomLayout
result <- FunPtr C_CustomRequestModeFunc
-> FunPtr C_CustomMeasureFunc
-> FunPtr C_CustomAllocateFunc
-> IO (Ptr CustomLayout)
gtk_custom_layout_new FunPtr C_CustomRequestModeFunc
maybeRequestMode FunPtr C_CustomMeasureFunc
measure' FunPtr C_CustomAllocateFunc
allocate'
    Text -> Ptr CustomLayout -> IO ()
forall a. HasCallStack => Text -> Ptr a -> IO ()
checkUnexpectedReturnNULL Text
"customLayoutNew" Ptr CustomLayout
result
    CustomLayout
result' <- ((ManagedPtr CustomLayout -> CustomLayout)
-> Ptr CustomLayout -> IO CustomLayout
forall a b.
(HasCallStack, GObject a, GObject b) =>
(ManagedPtr a -> a) -> Ptr b -> IO a
wrapObject ManagedPtr CustomLayout -> CustomLayout
CustomLayout) Ptr CustomLayout
result
    Ptr Any -> IO ()
forall a. Ptr a -> IO ()
safeFreeFunPtr (Ptr Any -> IO ()) -> Ptr Any -> IO ()
forall a b. (a -> b) -> a -> b
$ FunPtr C_CustomRequestModeFunc -> Ptr Any
forall a b. FunPtr a -> Ptr b
castFunPtrToPtr FunPtr C_CustomRequestModeFunc
maybeRequestMode
    Ptr Any -> IO ()
forall a. Ptr a -> IO ()
safeFreeFunPtr (Ptr Any -> IO ()) -> Ptr Any -> IO ()
forall a b. (a -> b) -> a -> b
$ FunPtr C_CustomMeasureFunc -> Ptr Any
forall a b. FunPtr a -> Ptr b
castFunPtrToPtr FunPtr C_CustomMeasureFunc
measure'
    Ptr Any -> IO ()
forall a. Ptr a -> IO ()
safeFreeFunPtr (Ptr Any -> IO ()) -> Ptr Any -> IO ()
forall a b. (a -> b) -> a -> b
$ FunPtr C_CustomAllocateFunc -> Ptr Any
forall a b. FunPtr a -> Ptr b
castFunPtrToPtr FunPtr C_CustomAllocateFunc
allocate'
    CustomLayout -> IO CustomLayout
forall (m :: * -> *) a. Monad m => a -> m a
return CustomLayout
result'

#if defined(ENABLE_OVERLOADING)
#endif