{- |
Copyright  : Will Thompson, Iñaki García Etxebarria and Jonas Platte
License    : LGPL-2.1
Maintainer : Iñaki García Etxebarria (garetxe@gmail.com)

A 'GI.Gdk.Objects.Cursor.Cursor' represents a cursor. Its contents are private.
-}

module GI.Gdk.Objects.Cursor
    ( 

-- * Exported types
    Cursor(..)                              ,
    IsCursor                                ,
    toCursor                                ,
    noCursor                                ,


 -- * Methods
-- ** getCursorType #method:getCursorType#
    CursorGetCursorTypeMethodInfo           ,
    cursorGetCursorType                     ,


-- ** getDisplay #method:getDisplay#
    CursorGetDisplayMethodInfo              ,
    cursorGetDisplay                        ,


-- ** getImage #method:getImage#
    CursorGetImageMethodInfo                ,
    cursorGetImage                          ,


-- ** getSurface #method:getSurface#
    CursorGetSurfaceMethodInfo              ,
    cursorGetSurface                        ,


-- ** new #method:new#
    cursorNew                               ,


-- ** newForDisplay #method:newForDisplay#
    cursorNewForDisplay                     ,


-- ** newFromName #method:newFromName#
    cursorNewFromName                       ,


-- ** newFromPixbuf #method:newFromPixbuf#
    cursorNewFromPixbuf                     ,


-- ** newFromSurface #method:newFromSurface#
    cursorNewFromSurface                    ,


-- ** ref #method:ref#
    CursorRefMethodInfo                     ,
    cursorRef                               ,


-- ** unref #method:unref#
    CursorUnrefMethodInfo                   ,
    cursorUnref                             ,




 -- * Properties
-- ** cursorType #attr:cursorType#
    CursorCursorTypePropertyInfo            ,
    constructCursorCursorType               ,
    cursorCursorType                        ,
    getCursorCursorType                     ,


-- ** display #attr:display#
    CursorDisplayPropertyInfo               ,
    constructCursorDisplay                  ,
    cursorDisplay                           ,
    getCursorDisplay                        ,




    ) 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.ManagedPtr as B.ManagedPtr
import qualified Data.GI.Base.GError as B.GError
import qualified Data.GI.Base.GVariant as B.GVariant
import qualified Data.GI.Base.GParamSpec as B.GParamSpec
import qualified Data.GI.Base.CallStack as B.CallStack
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 GI.Cairo.Structs.Surface as Cairo.Surface
import qualified GI.GObject.Objects.Object as GObject.Object
import {-# SOURCE #-} qualified GI.Gdk.Enums as Gdk.Enums
import {-# SOURCE #-} qualified GI.Gdk.Objects.Display as Gdk.Display
import qualified GI.GdkPixbuf.Objects.Pixbuf as GdkPixbuf.Pixbuf

newtype Cursor = Cursor (ManagedPtr Cursor)
foreign import ccall "gdk_cursor_get_type"
    c_gdk_cursor_get_type :: IO GType

instance GObject Cursor where
    gobjectType _ = c_gdk_cursor_get_type
    

class GObject o => IsCursor o
#if MIN_VERSION_base(4,9,0)
instance {-# OVERLAPPABLE #-} (GObject a, O.UnknownAncestorError Cursor a) =>
    IsCursor a
#endif
instance IsCursor Cursor
instance GObject.Object.IsObject Cursor

toCursor :: IsCursor o => o -> IO Cursor
toCursor = unsafeCastTo Cursor

noCursor :: Maybe Cursor
noCursor = Nothing

type family ResolveCursorMethod (t :: Symbol) (o :: *) :: * where
    ResolveCursorMethod "bindProperty" o = GObject.Object.ObjectBindPropertyMethodInfo
    ResolveCursorMethod "bindPropertyFull" o = GObject.Object.ObjectBindPropertyFullMethodInfo
    ResolveCursorMethod "forceFloating" o = GObject.Object.ObjectForceFloatingMethodInfo
    ResolveCursorMethod "freezeNotify" o = GObject.Object.ObjectFreezeNotifyMethodInfo
    ResolveCursorMethod "isFloating" o = GObject.Object.ObjectIsFloatingMethodInfo
    ResolveCursorMethod "notify" o = GObject.Object.ObjectNotifyMethodInfo
    ResolveCursorMethod "notifyByPspec" o = GObject.Object.ObjectNotifyByPspecMethodInfo
    ResolveCursorMethod "ref" o = CursorRefMethodInfo
    ResolveCursorMethod "refSink" o = GObject.Object.ObjectRefSinkMethodInfo
    ResolveCursorMethod "replaceData" o = GObject.Object.ObjectReplaceDataMethodInfo
    ResolveCursorMethod "replaceQdata" o = GObject.Object.ObjectReplaceQdataMethodInfo
    ResolveCursorMethod "runDispose" o = GObject.Object.ObjectRunDisposeMethodInfo
    ResolveCursorMethod "stealData" o = GObject.Object.ObjectStealDataMethodInfo
    ResolveCursorMethod "stealQdata" o = GObject.Object.ObjectStealQdataMethodInfo
    ResolveCursorMethod "thawNotify" o = GObject.Object.ObjectThawNotifyMethodInfo
    ResolveCursorMethod "unref" o = CursorUnrefMethodInfo
    ResolveCursorMethod "watchClosure" o = GObject.Object.ObjectWatchClosureMethodInfo
    ResolveCursorMethod "getCursorType" o = CursorGetCursorTypeMethodInfo
    ResolveCursorMethod "getData" o = GObject.Object.ObjectGetDataMethodInfo
    ResolveCursorMethod "getDisplay" o = CursorGetDisplayMethodInfo
    ResolveCursorMethod "getImage" o = CursorGetImageMethodInfo
    ResolveCursorMethod "getProperty" o = GObject.Object.ObjectGetPropertyMethodInfo
    ResolveCursorMethod "getQdata" o = GObject.Object.ObjectGetQdataMethodInfo
    ResolveCursorMethod "getSurface" o = CursorGetSurfaceMethodInfo
    ResolveCursorMethod "setData" o = GObject.Object.ObjectSetDataMethodInfo
    ResolveCursorMethod "setProperty" o = GObject.Object.ObjectSetPropertyMethodInfo
    ResolveCursorMethod l o = O.MethodResolutionFailed l o

instance (info ~ ResolveCursorMethod t Cursor, O.MethodInfo info Cursor p) => O.IsLabelProxy t (Cursor -> p) where
    fromLabelProxy _ = O.overloadedMethod (O.MethodProxy :: O.MethodProxy info)

#if MIN_VERSION_base(4,9,0)
instance (info ~ ResolveCursorMethod t Cursor, O.MethodInfo info Cursor p) => O.IsLabel t (Cursor -> p) where
    fromLabel _ = O.overloadedMethod (O.MethodProxy :: O.MethodProxy info)
#endif

-- VVV Prop "cursor-type"
   -- Type: TInterface (Name {namespace = "Gdk", name = "CursorType"})
   -- Flags: [PropertyReadable,PropertyWritable,PropertyConstructOnly]
   -- Nullable: (Just False,Nothing)

getCursorCursorType :: (MonadIO m, IsCursor o) => o -> m Gdk.Enums.CursorType
getCursorCursorType obj = liftIO $ getObjectPropertyEnum obj "cursor-type"

constructCursorCursorType :: (IsCursor o) => Gdk.Enums.CursorType -> IO (GValueConstruct o)
constructCursorCursorType val = constructObjectPropertyEnum "cursor-type" val

data CursorCursorTypePropertyInfo
instance AttrInfo CursorCursorTypePropertyInfo where
    type AttrAllowedOps CursorCursorTypePropertyInfo = '[ 'AttrConstruct, 'AttrGet]
    type AttrSetTypeConstraint CursorCursorTypePropertyInfo = (~) Gdk.Enums.CursorType
    type AttrBaseTypeConstraint CursorCursorTypePropertyInfo = IsCursor
    type AttrGetType CursorCursorTypePropertyInfo = Gdk.Enums.CursorType
    type AttrLabel CursorCursorTypePropertyInfo = "cursor-type"
    type AttrOrigin CursorCursorTypePropertyInfo = Cursor
    attrGet _ = getCursorCursorType
    attrSet _ = undefined
    attrConstruct _ = constructCursorCursorType
    attrClear _ = undefined

-- VVV Prop "display"
   -- Type: TInterface (Name {namespace = "Gdk", name = "Display"})
   -- Flags: [PropertyReadable,PropertyWritable,PropertyConstructOnly]
   -- Nullable: (Just False,Nothing)

getCursorDisplay :: (MonadIO m, IsCursor o) => o -> m Gdk.Display.Display
getCursorDisplay obj = liftIO $ checkUnexpectedNothing "getCursorDisplay" $ getObjectPropertyObject obj "display" Gdk.Display.Display

constructCursorDisplay :: (IsCursor o, Gdk.Display.IsDisplay a) => a -> IO (GValueConstruct o)
constructCursorDisplay val = constructObjectPropertyObject "display" (Just val)

data CursorDisplayPropertyInfo
instance AttrInfo CursorDisplayPropertyInfo where
    type AttrAllowedOps CursorDisplayPropertyInfo = '[ 'AttrConstruct, 'AttrGet, 'AttrClear]
    type AttrSetTypeConstraint CursorDisplayPropertyInfo = Gdk.Display.IsDisplay
    type AttrBaseTypeConstraint CursorDisplayPropertyInfo = IsCursor
    type AttrGetType CursorDisplayPropertyInfo = Gdk.Display.Display
    type AttrLabel CursorDisplayPropertyInfo = "display"
    type AttrOrigin CursorDisplayPropertyInfo = Cursor
    attrGet _ = getCursorDisplay
    attrSet _ = undefined
    attrConstruct _ = constructCursorDisplay
    attrClear _ = undefined

instance O.HasAttributeList Cursor
type instance O.AttributeList Cursor = CursorAttributeList
type CursorAttributeList = ('[ '("cursorType", CursorCursorTypePropertyInfo), '("display", CursorDisplayPropertyInfo)] :: [(Symbol, *)])

cursorCursorType :: AttrLabelProxy "cursorType"
cursorCursorType = AttrLabelProxy

cursorDisplay :: AttrLabelProxy "display"
cursorDisplay = AttrLabelProxy

type instance O.SignalList Cursor = CursorSignalList
type CursorSignalList = ('[ '("notify", GObject.Object.ObjectNotifySignalInfo)] :: [(Symbol, *)])

-- method Cursor::new
-- method type : Constructor
-- Args : [Arg {argCName = "cursor_type", argType = TInterface (Name {namespace = "Gdk", name = "CursorType"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "cursor to create", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TInterface (Name {namespace = "Gdk", name = "Cursor"}))
-- throws : False
-- Skip return : False

foreign import ccall "gdk_cursor_new" gdk_cursor_new :: 
    CUInt ->                                -- cursor_type : TInterface (Name {namespace = "Gdk", name = "CursorType"})
    IO (Ptr Cursor)

{-# DEPRECATED cursorNew ["(Since version 3.16)","Use 'GI.Gdk.Objects.Cursor.cursorNewForDisplay' instead."] #-}
{- |
Creates a new cursor from the set of builtin cursors for the default display.
See 'GI.Gdk.Objects.Cursor.cursorNewForDisplay'.

To make the cursor invisible, use 'GI.Gdk.Enums.CursorTypeBlankCursor'.
-}
cursorNew ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    Gdk.Enums.CursorType
    {- ^ /@cursorType@/: cursor to create -}
    -> m Cursor
    {- ^ __Returns:__ a new 'GI.Gdk.Objects.Cursor.Cursor' -}
cursorNew cursorType = liftIO $ do
    let cursorType' = (fromIntegral . fromEnum) cursorType
    result <- gdk_cursor_new cursorType'
    checkUnexpectedReturnNULL "cursorNew" result
    result' <- (wrapObject Cursor) result
    return result'

-- method Cursor::new_for_display
-- method type : Constructor
-- Args : [Arg {argCName = "display", argType = TInterface (Name {namespace = "Gdk", name = "Display"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the #GdkDisplay for which the cursor will be created", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "cursor_type", argType = TInterface (Name {namespace = "Gdk", name = "CursorType"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "cursor to create", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TInterface (Name {namespace = "Gdk", name = "Cursor"}))
-- throws : False
-- Skip return : False

foreign import ccall "gdk_cursor_new_for_display" gdk_cursor_new_for_display :: 
    Ptr Gdk.Display.Display ->              -- display : TInterface (Name {namespace = "Gdk", name = "Display"})
    CUInt ->                                -- cursor_type : TInterface (Name {namespace = "Gdk", name = "CursorType"})
    IO (Ptr Cursor)

{- |
Creates a new cursor from the set of builtin cursors.

@since 2.2
-}
cursorNewForDisplay ::
    (B.CallStack.HasCallStack, MonadIO m, Gdk.Display.IsDisplay a) =>
    a
    {- ^ /@display@/: the 'GI.Gdk.Objects.Display.Display' for which the cursor will be created -}
    -> Gdk.Enums.CursorType
    {- ^ /@cursorType@/: cursor to create -}
    -> m Cursor
    {- ^ __Returns:__ a new 'GI.Gdk.Objects.Cursor.Cursor' -}
cursorNewForDisplay display cursorType = liftIO $ do
    display' <- unsafeManagedPtrCastPtr display
    let cursorType' = (fromIntegral . fromEnum) cursorType
    result <- gdk_cursor_new_for_display display' cursorType'
    checkUnexpectedReturnNULL "cursorNewForDisplay" result
    result' <- (wrapObject Cursor) result
    touchManagedPtr display
    return result'

-- method Cursor::new_from_name
-- method type : Constructor
-- Args : [Arg {argCName = "display", argType = TInterface (Name {namespace = "Gdk", name = "Display"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the #GdkDisplay for which the cursor will be created", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "name", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the name of the cursor", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TInterface (Name {namespace = "Gdk", name = "Cursor"}))
-- throws : False
-- Skip return : False

foreign import ccall "gdk_cursor_new_from_name" gdk_cursor_new_from_name :: 
    Ptr Gdk.Display.Display ->              -- display : TInterface (Name {namespace = "Gdk", name = "Display"})
    CString ->                              -- name : TBasicType TUTF8
    IO (Ptr Cursor)

{- |
Creates a new cursor by looking up /@name@/ in the current cursor
theme.

A recommended set of cursor names that will work across different
platforms can be found in the CSS specification:

* \"none\"
* <<http://developer.gnome.org/gdk/stable/default_cursor.png>> \"default\"
* <<http://developer.gnome.org/gdk/stable/help_cursor.png>> \"help\"
* <<http://developer.gnome.org/gdk/stable/pointer_cursor.png>> \"pointer\"
* <<http://developer.gnome.org/gdk/stable/context_menu_cursor.png>> \"context-menu\"
* <<http://developer.gnome.org/gdk/stable/progress_cursor.png>> \"progress\"
* <<http://developer.gnome.org/gdk/stable/wait_cursor.png>> \"wait\"
* <<http://developer.gnome.org/gdk/stable/cell_cursor.png>> \"cell\"
* <<http://developer.gnome.org/gdk/stable/crosshair_cursor.png>> \"crosshair\"
* <<http://developer.gnome.org/gdk/stable/text_cursor.png>> \"text\"
* <<http://developer.gnome.org/gdk/stable/vertical_text_cursor.png>> \"vertical-text\"
* <<http://developer.gnome.org/gdk/stable/alias_cursor.png>> \"alias\"
* <<http://developer.gnome.org/gdk/stable/copy_cursor.png>> \"copy\"
* <<http://developer.gnome.org/gdk/stable/no_drop_cursor.png>> \"no-drop\"
* <<http://developer.gnome.org/gdk/stable/move_cursor.png>> \"move\"
* <<http://developer.gnome.org/gdk/stable/not_allowed_cursor.png>> \"not-allowed\"
* <<http://developer.gnome.org/gdk/stable/grab_cursor.png>> \"grab\"
* <<http://developer.gnome.org/gdk/stable/grabbing_cursor.png>> \"grabbing\"
* <<http://developer.gnome.org/gdk/stable/all_scroll_cursor.png>> \"all-scroll\"
* <<http://developer.gnome.org/gdk/stable/col_resize_cursor.png>> \"col-resize\"
* <<http://developer.gnome.org/gdk/stable/row_resize_cursor.png>> \"row-resize\"
* <<http://developer.gnome.org/gdk/stable/n_resize_cursor.png>> \"n-resize\"
* <<http://developer.gnome.org/gdk/stable/e_resize_cursor.png>> \"e-resize\"
* <<http://developer.gnome.org/gdk/stable/s_resize_cursor.png>> \"s-resize\"
* <<http://developer.gnome.org/gdk/stable/w_resize_cursor.png>> \"w-resize\"
* <<http://developer.gnome.org/gdk/stable/ne_resize_cursor.png>> \"ne-resize\"
* <<http://developer.gnome.org/gdk/stable/nw_resize_cursor.png>> \"nw-resize\"
* <<http://developer.gnome.org/gdk/stable/sw_resize_cursor.png>> \"sw-resize\"
* <<http://developer.gnome.org/gdk/stable/se_resize_cursor.png>> \"se-resize\"
* <<http://developer.gnome.org/gdk/stable/ew_resize_cursor.png>> \"ew-resize\"
* <<http://developer.gnome.org/gdk/stable/ns_resize_cursor.png>> \"ns-resize\"
* <<http://developer.gnome.org/gdk/stable/nesw_resize_cursor.png>> \"nesw-resize\"
* <<http://developer.gnome.org/gdk/stable/nwse_resize_cursor.png>> \"nwse-resize\"
* <<http://developer.gnome.org/gdk/stable/zoom_in_cursor.png>> \"zoom-in\"
* <<http://developer.gnome.org/gdk/stable/zoom_out_cursor.png>> \"zoom-out\"

@since 2.8
-}
cursorNewFromName ::
    (B.CallStack.HasCallStack, MonadIO m, Gdk.Display.IsDisplay a) =>
    a
    {- ^ /@display@/: the 'GI.Gdk.Objects.Display.Display' for which the cursor will be created -}
    -> T.Text
    {- ^ /@name@/: the name of the cursor -}
    -> m (Maybe Cursor)
    {- ^ __Returns:__ a new 'GI.Gdk.Objects.Cursor.Cursor', or 'Nothing' if there is no
  cursor with the given name -}
cursorNewFromName display name = liftIO $ do
    display' <- unsafeManagedPtrCastPtr display
    name' <- textToCString name
    result <- gdk_cursor_new_from_name display' name'
    maybeResult <- convertIfNonNull result $ \result' -> do
        result'' <- (wrapObject Cursor) result'
        return result''
    touchManagedPtr display
    freeMem name'
    return maybeResult

-- method Cursor::new_from_pixbuf
-- method type : Constructor
-- Args : [Arg {argCName = "display", argType = TInterface (Name {namespace = "Gdk", name = "Display"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the #GdkDisplay for which the cursor will be created", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "pixbuf", argType = TInterface (Name {namespace = "GdkPixbuf", name = "Pixbuf"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the #GdkPixbuf containing the cursor image", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "x", argType = TBasicType TInt, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the horizontal offset of the \8220hotspot\8221 of the cursor.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "y", argType = TBasicType TInt, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the vertical offset of the \8220hotspot\8221 of the cursor.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TInterface (Name {namespace = "Gdk", name = "Cursor"}))
-- throws : False
-- Skip return : False

foreign import ccall "gdk_cursor_new_from_pixbuf" gdk_cursor_new_from_pixbuf :: 
    Ptr Gdk.Display.Display ->              -- display : TInterface (Name {namespace = "Gdk", name = "Display"})
    Ptr GdkPixbuf.Pixbuf.Pixbuf ->          -- pixbuf : TInterface (Name {namespace = "GdkPixbuf", name = "Pixbuf"})
    Int32 ->                                -- x : TBasicType TInt
    Int32 ->                                -- y : TBasicType TInt
    IO (Ptr Cursor)

{- |
Creates a new cursor from a pixbuf.

Not all GDK backends support RGBA cursors. If they are not
supported, a monochrome approximation will be displayed.
The functions 'GI.Gdk.Objects.Display.displaySupportsCursorAlpha' and
'GI.Gdk.Objects.Display.displaySupportsCursorColor' can be used to determine
whether RGBA cursors are supported;
'GI.Gdk.Objects.Display.displayGetDefaultCursorSize' and
'GI.Gdk.Objects.Display.displayGetMaximalCursorSize' give information about
cursor sizes.

If /@x@/ or /@y@/ are @-1@, the pixbuf must have
options named “x_hot” and “y_hot”, resp., containing
integer values between @0@ and the width resp. height of
the pixbuf. (Since: 3.0)

On the X backend, support for RGBA cursors requires a
sufficently new version of the X Render extension.

@since 2.4
-}
cursorNewFromPixbuf ::
    (B.CallStack.HasCallStack, MonadIO m, Gdk.Display.IsDisplay a, GdkPixbuf.Pixbuf.IsPixbuf b) =>
    a
    {- ^ /@display@/: the 'GI.Gdk.Objects.Display.Display' for which the cursor will be created -}
    -> b
    {- ^ /@pixbuf@/: the 'GI.GdkPixbuf.Objects.Pixbuf.Pixbuf' containing the cursor image -}
    -> Int32
    {- ^ /@x@/: the horizontal offset of the “hotspot” of the cursor. -}
    -> Int32
    {- ^ /@y@/: the vertical offset of the “hotspot” of the cursor. -}
    -> m Cursor
    {- ^ __Returns:__ a new 'GI.Gdk.Objects.Cursor.Cursor'. -}
cursorNewFromPixbuf display pixbuf x y = liftIO $ do
    display' <- unsafeManagedPtrCastPtr display
    pixbuf' <- unsafeManagedPtrCastPtr pixbuf
    result <- gdk_cursor_new_from_pixbuf display' pixbuf' x y
    checkUnexpectedReturnNULL "cursorNewFromPixbuf" result
    result' <- (wrapObject Cursor) result
    touchManagedPtr display
    touchManagedPtr pixbuf
    return result'

-- method Cursor::new_from_surface
-- method type : Constructor
-- Args : [Arg {argCName = "display", argType = TInterface (Name {namespace = "Gdk", name = "Display"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the #GdkDisplay for which the cursor will be created", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "surface", argType = TInterface (Name {namespace = "cairo", name = "Surface"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the cairo image surface containing the cursor pixel data", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "x", argType = TBasicType TDouble, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the horizontal offset of the \8220hotspot\8221 of the cursor", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "y", argType = TBasicType TDouble, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the vertical offset of the \8220hotspot\8221 of the cursor", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TInterface (Name {namespace = "Gdk", name = "Cursor"}))
-- throws : False
-- Skip return : False

foreign import ccall "gdk_cursor_new_from_surface" gdk_cursor_new_from_surface :: 
    Ptr Gdk.Display.Display ->              -- display : TInterface (Name {namespace = "Gdk", name = "Display"})
    Ptr Cairo.Surface.Surface ->            -- surface : TInterface (Name {namespace = "cairo", name = "Surface"})
    CDouble ->                              -- x : TBasicType TDouble
    CDouble ->                              -- y : TBasicType TDouble
    IO (Ptr Cursor)

{- |
Creates a new cursor from a cairo image surface.

Not all GDK backends support RGBA cursors. If they are not
supported, a monochrome approximation will be displayed.
The functions 'GI.Gdk.Objects.Display.displaySupportsCursorAlpha' and
'GI.Gdk.Objects.Display.displaySupportsCursorColor' can be used to determine
whether RGBA cursors are supported;
'GI.Gdk.Objects.Display.displayGetDefaultCursorSize' and
'GI.Gdk.Objects.Display.displayGetMaximalCursorSize' give information about
cursor sizes.

On the X backend, support for RGBA cursors requires a
sufficently new version of the X Render extension.

@since 3.10
-}
cursorNewFromSurface ::
    (B.CallStack.HasCallStack, MonadIO m, Gdk.Display.IsDisplay a) =>
    a
    {- ^ /@display@/: the 'GI.Gdk.Objects.Display.Display' for which the cursor will be created -}
    -> Cairo.Surface.Surface
    {- ^ /@surface@/: the cairo image surface containing the cursor pixel data -}
    -> Double
    {- ^ /@x@/: the horizontal offset of the “hotspot” of the cursor -}
    -> Double
    {- ^ /@y@/: the vertical offset of the “hotspot” of the cursor -}
    -> m Cursor
    {- ^ __Returns:__ a new 'GI.Gdk.Objects.Cursor.Cursor'. -}
cursorNewFromSurface display surface x y = liftIO $ do
    display' <- unsafeManagedPtrCastPtr display
    surface' <- unsafeManagedPtrGetPtr surface
    let x' = realToFrac x
    let y' = realToFrac y
    result <- gdk_cursor_new_from_surface display' surface' x' y'
    checkUnexpectedReturnNULL "cursorNewFromSurface" result
    result' <- (wrapObject Cursor) result
    touchManagedPtr display
    touchManagedPtr surface
    return result'

-- method Cursor::get_cursor_type
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "cursor", argType = TInterface (Name {namespace = "Gdk", name = "Cursor"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GdkCursor", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TInterface (Name {namespace = "Gdk", name = "CursorType"}))
-- throws : False
-- Skip return : False

foreign import ccall "gdk_cursor_get_cursor_type" gdk_cursor_get_cursor_type :: 
    Ptr Cursor ->                           -- cursor : TInterface (Name {namespace = "Gdk", name = "Cursor"})
    IO CUInt

{- |
Returns the cursor type for this cursor.

@since 2.22
-}
cursorGetCursorType ::
    (B.CallStack.HasCallStack, MonadIO m, IsCursor a) =>
    a
    {- ^ /@cursor@/: a 'GI.Gdk.Objects.Cursor.Cursor' -}
    -> m Gdk.Enums.CursorType
    {- ^ __Returns:__ a 'GI.Gdk.Enums.CursorType' -}
cursorGetCursorType cursor = liftIO $ do
    cursor' <- unsafeManagedPtrCastPtr cursor
    result <- gdk_cursor_get_cursor_type cursor'
    let result' = (toEnum . fromIntegral) result
    touchManagedPtr cursor
    return result'

data CursorGetCursorTypeMethodInfo
instance (signature ~ (m Gdk.Enums.CursorType), MonadIO m, IsCursor a) => O.MethodInfo CursorGetCursorTypeMethodInfo a signature where
    overloadedMethod _ = cursorGetCursorType

-- method Cursor::get_display
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "cursor", argType = TInterface (Name {namespace = "Gdk", name = "Cursor"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GdkCursor.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TInterface (Name {namespace = "Gdk", name = "Display"}))
-- throws : False
-- Skip return : False

foreign import ccall "gdk_cursor_get_display" gdk_cursor_get_display :: 
    Ptr Cursor ->                           -- cursor : TInterface (Name {namespace = "Gdk", name = "Cursor"})
    IO (Ptr Gdk.Display.Display)

{- |
Returns the display on which the 'GI.Gdk.Objects.Cursor.Cursor' is defined.

@since 2.2
-}
cursorGetDisplay ::
    (B.CallStack.HasCallStack, MonadIO m, IsCursor a) =>
    a
    {- ^ /@cursor@/: a 'GI.Gdk.Objects.Cursor.Cursor'. -}
    -> m Gdk.Display.Display
    {- ^ __Returns:__ the 'GI.Gdk.Objects.Display.Display' associated to /@cursor@/ -}
cursorGetDisplay cursor = liftIO $ do
    cursor' <- unsafeManagedPtrCastPtr cursor
    result <- gdk_cursor_get_display cursor'
    checkUnexpectedReturnNULL "cursorGetDisplay" result
    result' <- (newObject Gdk.Display.Display) result
    touchManagedPtr cursor
    return result'

data CursorGetDisplayMethodInfo
instance (signature ~ (m Gdk.Display.Display), MonadIO m, IsCursor a) => O.MethodInfo CursorGetDisplayMethodInfo a signature where
    overloadedMethod _ = cursorGetDisplay

-- method Cursor::get_image
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "cursor", argType = TInterface (Name {namespace = "Gdk", name = "Cursor"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GdkCursor", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TInterface (Name {namespace = "GdkPixbuf", name = "Pixbuf"}))
-- throws : False
-- Skip return : False

foreign import ccall "gdk_cursor_get_image" gdk_cursor_get_image :: 
    Ptr Cursor ->                           -- cursor : TInterface (Name {namespace = "Gdk", name = "Cursor"})
    IO (Ptr GdkPixbuf.Pixbuf.Pixbuf)

{- |
Returns a 'GI.GdkPixbuf.Objects.Pixbuf.Pixbuf' with the image used to display the cursor.

Note that depending on the capabilities of the windowing system and
on the cursor, GDK may not be able to obtain the image data. In this
case, 'Nothing' is returned.

@since 2.8
-}
cursorGetImage ::
    (B.CallStack.HasCallStack, MonadIO m, IsCursor a) =>
    a
    {- ^ /@cursor@/: a 'GI.Gdk.Objects.Cursor.Cursor' -}
    -> m (Maybe GdkPixbuf.Pixbuf.Pixbuf)
    {- ^ __Returns:__ a 'GI.GdkPixbuf.Objects.Pixbuf.Pixbuf' representing
  /@cursor@/, or 'Nothing' -}
cursorGetImage cursor = liftIO $ do
    cursor' <- unsafeManagedPtrCastPtr cursor
    result <- gdk_cursor_get_image cursor'
    maybeResult <- convertIfNonNull result $ \result' -> do
        result'' <- (wrapObject GdkPixbuf.Pixbuf.Pixbuf) result'
        return result''
    touchManagedPtr cursor
    return maybeResult

data CursorGetImageMethodInfo
instance (signature ~ (m (Maybe GdkPixbuf.Pixbuf.Pixbuf)), MonadIO m, IsCursor a) => O.MethodInfo CursorGetImageMethodInfo a signature where
    overloadedMethod _ = cursorGetImage

-- method Cursor::get_surface
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "cursor", argType = TInterface (Name {namespace = "Gdk", name = "Cursor"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GdkCursor", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "x_hot", argType = TBasicType TDouble, direction = DirectionOut, mayBeNull = False, argDoc = Documentation {rawDocText = Just "Location to store the hotspot x position,\n  or %NULL", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferEverything},Arg {argCName = "y_hot", argType = TBasicType TDouble, direction = DirectionOut, mayBeNull = False, argDoc = Documentation {rawDocText = Just "Location to store the hotspot y position,\n  or %NULL", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferEverything}]
-- Lengths : []
-- returnType : Just (TInterface (Name {namespace = "cairo", name = "Surface"}))
-- throws : False
-- Skip return : False

foreign import ccall "gdk_cursor_get_surface" gdk_cursor_get_surface :: 
    Ptr Cursor ->                           -- cursor : TInterface (Name {namespace = "Gdk", name = "Cursor"})
    Ptr CDouble ->                          -- x_hot : TBasicType TDouble
    Ptr CDouble ->                          -- y_hot : TBasicType TDouble
    IO (Ptr Cairo.Surface.Surface)

{- |
Returns a cairo image surface with the image used to display the cursor.

Note that depending on the capabilities of the windowing system and
on the cursor, GDK may not be able to obtain the image data. In this
case, 'Nothing' is returned.

@since 3.10
-}
cursorGetSurface ::
    (B.CallStack.HasCallStack, MonadIO m, IsCursor a) =>
    a
    {- ^ /@cursor@/: a 'GI.Gdk.Objects.Cursor.Cursor' -}
    -> m ((Maybe Cairo.Surface.Surface),Double,Double)
    {- ^ __Returns:__ a 'GI.Cairo.Structs.Surface.Surface'
  representing /@cursor@/, or 'Nothing' -}
cursorGetSurface cursor = liftIO $ do
    cursor' <- unsafeManagedPtrCastPtr cursor
    xHot <- allocMem :: IO (Ptr CDouble)
    yHot <- allocMem :: IO (Ptr CDouble)
    result <- gdk_cursor_get_surface cursor' xHot yHot
    maybeResult <- convertIfNonNull result $ \result' -> do
        result'' <- (wrapBoxed Cairo.Surface.Surface) result'
        return result''
    xHot' <- peek xHot
    let xHot'' = realToFrac xHot'
    yHot' <- peek yHot
    let yHot'' = realToFrac yHot'
    touchManagedPtr cursor
    freeMem xHot
    freeMem yHot
    return (maybeResult, xHot'', yHot'')

data CursorGetSurfaceMethodInfo
instance (signature ~ (m ((Maybe Cairo.Surface.Surface),Double,Double)), MonadIO m, IsCursor a) => O.MethodInfo CursorGetSurfaceMethodInfo a signature where
    overloadedMethod _ = cursorGetSurface

-- method Cursor::ref
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "cursor", argType = TInterface (Name {namespace = "Gdk", name = "Cursor"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GdkCursor", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TInterface (Name {namespace = "Gdk", name = "Cursor"}))
-- throws : False
-- Skip return : False

foreign import ccall "gdk_cursor_ref" gdk_cursor_ref :: 
    Ptr Cursor ->                           -- cursor : TInterface (Name {namespace = "Gdk", name = "Cursor"})
    IO (Ptr Cursor)

{-# DEPRECATED cursorRef ["(Since version 3.0)","Use 'GI.GObject.Objects.Object.objectRef' instead"] #-}
{- |
Adds a reference to /@cursor@/.
-}
cursorRef ::
    (B.CallStack.HasCallStack, MonadIO m, IsCursor a) =>
    a
    {- ^ /@cursor@/: a 'GI.Gdk.Objects.Cursor.Cursor' -}
    -> m Cursor
    {- ^ __Returns:__ Same /@cursor@/ that was passed in -}
cursorRef cursor = liftIO $ do
    cursor' <- unsafeManagedPtrCastPtr cursor
    result <- gdk_cursor_ref cursor'
    checkUnexpectedReturnNULL "cursorRef" result
    result' <- (wrapObject Cursor) result
    touchManagedPtr cursor
    return result'

data CursorRefMethodInfo
instance (signature ~ (m Cursor), MonadIO m, IsCursor a) => O.MethodInfo CursorRefMethodInfo a signature where
    overloadedMethod _ = cursorRef

-- method Cursor::unref
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "cursor", argType = TInterface (Name {namespace = "Gdk", name = "Cursor"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GdkCursor", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Nothing
-- throws : False
-- Skip return : False

foreign import ccall "gdk_cursor_unref" gdk_cursor_unref :: 
    Ptr Cursor ->                           -- cursor : TInterface (Name {namespace = "Gdk", name = "Cursor"})
    IO ()

{-# DEPRECATED cursorUnref ["(Since version 3.0)","Use 'GI.GObject.Objects.Object.objectUnref' instead"] #-}
{- |
Removes a reference from /@cursor@/, deallocating the cursor
if no references remain.
-}
cursorUnref ::
    (B.CallStack.HasCallStack, MonadIO m, IsCursor a) =>
    a
    {- ^ /@cursor@/: a 'GI.Gdk.Objects.Cursor.Cursor' -}
    -> m ()
cursorUnref cursor = liftIO $ do
    cursor' <- unsafeManagedPtrCastPtr cursor
    gdk_cursor_unref cursor'
    touchManagedPtr cursor
    return ()

data CursorUnrefMethodInfo
instance (signature ~ (m ()), MonadIO m, IsCursor a) => O.MethodInfo CursorUnrefMethodInfo a signature where
    overloadedMethod _ = cursorUnref